function a(t, r, d) {
  if (t.length === 0)
    return null;
  const i = t.find((n) => n.start < d && n.end > r);
  if (i)
    return i;
  const e = t.find((n) => r >= n.start && r < n.end);
  return e || (t.find((n) => n.start >= r) ?? [...t].reverse().find((n) => n.end <= r) ?? null);
}
function c(t, r, d) {
  const i = t.findIndex((n) => n.section === r.section);
  if (i === -1)
    return d > 0 ? t[0] : t[t.length - 1];
  const e = i + d;
  return e < 0 ? t[0] : e >= t.length ? t[t.length - 1] : t[e];
}
function p(t, r) {
  return r === "start" ? t[0] : t[t.length - 1];
}
function h(t, r, d) {
  const i = t.flatMap((e) => d(e)).filter((e) => e >= r);
  return i.length > 0 ? i[0] : null;
}
function k(t, r, d, i, e = {}) {
  if (d > r)
    return t.filter((u) => u.start < d && u.end > r).map((u) => u.section);
  const n = i === "Backspace" ? Math.max(0, r - 1) : r, f = t.find((u) => n >= u.start && n < u.end);
  if (f)
    return [f.section];
  if (!e.includeAdjacentWhenNoDirectHit)
    return [];
  if (i === "Delete") {
    const u = t.find((o) => o.start > n);
    return u ? [u.section] : [];
  }
  const l = [...t].reverse().find((u) => u.end <= n);
  return l ? [l.section] : [];
}
function x(t, r) {
  return t.key.length !== 1 || t.altKey || t.ctrlKey || t.metaKey || r.test(t.key) ? !1 : (t.preventDefault(), !0);
}
export {
  c as getAdjacentMaskedFieldSectionRange,
  p as getMaskedFieldBoundarySectionRange,
  h as getMaskedFieldNextEditablePosition,
  a as getMaskedFieldSectionRangeFromSelection,
  k as getMaskedFieldSectionsFromSelection,
  x as preventInvalidMaskedPrintableKey
};
