UNPKG

alinea

Version:

[![npm](https://img.shields.io/npm/v/alinea.svg)](https://npmjs.org/package/alinea) [![install size](https://packagephobia.com/badge?p=alinea)](https://packagephobia.com/result?p=alinea)

116 lines (112 loc) 4.22 kB
import { o, s, u } from "./chunk-QEHUZJO2.js"; // node_modules/@headlessui/react/dist/utils/owner.js function e(r) { return s.isServer ? null : r instanceof Node ? r.ownerDocument : r != null && r.hasOwnProperty("current") && r.current instanceof Node ? r.current.ownerDocument : document; } // node_modules/@headlessui/react/dist/utils/focus-management.js var c = ["[contentEditable=true]", "[tabindex]", "a[href]", "area[href]", "button:not([disabled])", "iframe", "input:not([disabled])", "select:not([disabled])", "textarea:not([disabled])"].map((e2) => `${e2}:not([tabindex='-1'])`).join(","); var M = ((n) => (n[n.First = 1] = "First", n[n.Previous = 2] = "Previous", n[n.Next = 4] = "Next", n[n.Last = 8] = "Last", n[n.WrapAround = 16] = "WrapAround", n[n.NoScroll = 32] = "NoScroll", n))(M || {}); var N = ((o2) => (o2[o2.Error = 0] = "Error", o2[o2.Overflow = 1] = "Overflow", o2[o2.Success = 2] = "Success", o2[o2.Underflow = 3] = "Underflow", o2))(N || {}); var F = ((t) => (t[t.Previous = -1] = "Previous", t[t.Next = 1] = "Next", t))(F || {}); function f(e2 = document.body) { return e2 == null ? [] : Array.from(e2.querySelectorAll(c)).sort((r, t) => Math.sign((r.tabIndex || Number.MAX_SAFE_INTEGER) - (t.tabIndex || Number.MAX_SAFE_INTEGER))); } var T = ((t) => (t[t.Strict = 0] = "Strict", t[t.Loose = 1] = "Loose", t))(T || {}); function h(e2, r = 0) { var t; return e2 === ((t = e(e2)) == null ? void 0 : t.body) ? false : u(r, { [0]() { return e2.matches(c); }, [1]() { let l = e2; for (; l !== null; ) { if (l.matches(c)) return true; l = l.parentElement; } return false; } }); } function D(e2) { let r = e(e2); o().nextFrame(() => { r && !h(r.activeElement, 0) && y(e2); }); } var w = ((t) => (t[t.Keyboard = 0] = "Keyboard", t[t.Mouse = 1] = "Mouse", t))(w || {}); typeof window != "undefined" && typeof document != "undefined" && (document.addEventListener("keydown", (e2) => { e2.metaKey || e2.altKey || e2.ctrlKey || (document.documentElement.dataset.headlessuiFocusVisible = ""); }, true), document.addEventListener("click", (e2) => { e2.detail === 1 ? delete document.documentElement.dataset.headlessuiFocusVisible : e2.detail === 0 && (document.documentElement.dataset.headlessuiFocusVisible = ""); }, true)); function y(e2) { e2 == null || e2.focus({ preventScroll: true }); } var S = ["textarea", "input"].join(","); function H(e2) { var r, t; return (t = (r = e2 == null ? void 0 : e2.matches) == null ? void 0 : r.call(e2, S)) != null ? t : false; } function I(e2, r = (t) => t) { return e2.slice().sort((t, l) => { let o2 = r(t), i = r(l); if (o2 === null || i === null) return 0; let n = o2.compareDocumentPosition(i); return n & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : n & Node.DOCUMENT_POSITION_PRECEDING ? 1 : 0; }); } function _(e2, r) { return O(f(), r, { relativeTo: e2 }); } function O(e2, r, { sorted: t = true, relativeTo: l = null, skipElements: o2 = [] } = {}) { let i = Array.isArray(e2) ? e2.length > 0 ? e2[0].ownerDocument : document : e2.ownerDocument, n = Array.isArray(e2) ? t ? I(e2) : e2 : f(e2); o2.length > 0 && n.length > 1 && (n = n.filter((s2) => !o2.includes(s2))), l = l != null ? l : i.activeElement; let E = (() => { if (r & 5) return 1; if (r & 10) return -1; throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last"); })(), x = (() => { if (r & 1) return 0; if (r & 2) return Math.max(0, n.indexOf(l)) - 1; if (r & 4) return Math.max(0, n.indexOf(l)) + 1; if (r & 8) return n.length - 1; throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last"); })(), p = r & 32 ? { preventScroll: true } : {}, d = 0, a = n.length, u2; do { if (d >= a || d + a <= 0) return 0; let s2 = x + d; if (r & 16) s2 = (s2 + a) % a; else { if (s2 < 0) return 3; if (s2 >= a) return 1; } u2 = n[s2], u2 == null || u2.focus(p), d += E; } while (u2 !== i.activeElement); return r & 6 && H(u2) && u2.select(), 2; } export { e, M, N, f, T, h, D, I, _, O };