@lunalytics/ui
Version:
React based component library created to be used in Lunalytics
1,537 lines • 68 kB
JavaScript
import '../../assets/contextMenu.css';var Cn = Object.defineProperty;
var vn = (e, t, n) => t in e ? Cn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
var Pe = (e, t, n) => vn(e, typeof t != "symbol" ? t + "" : t, n);
import { jsx as H, jsxs as Ae } from "react/jsx-runtime";
import * as s from "react";
import { d as Tt, b as ne, a as ce, m as gt, e as St, f as rt, E as ht, c as Ve, i as In, T as Pt, u as He, D as On, g as kn, h as Nn, j as Tn } from "../../useTimeout-BZrhyGBQ.js";
import { A as bt, v as ae, w as je, x as Oe, y as ke, z as Dt, B as st, C as de, D as en, E as ft, F as we, G as Ke, H as Sn, I as ot, J as tn, K as yt, L as Ue, M as Lt, N as At, O as Fe, c as he, P as nn, Q as Ft, R as rn, S as on, T as Bt, U as Ut, V as Pn, W as Dn, b as qe, X as sn, Y as Ln, Z as An, i as Vt, _ as Rt, $ as Fn, a0 as un, a as Mt, a1 as Bn, a2 as Un, f as cn, p as an, q as Vn, a3 as _n, a4 as Hn, o as Kn, a5 as Wn, d as zn, e as Yn, r as Gn, h as $n, j as qn, s as Xn, k as jn, l as Jn, a6 as Qn, m as Zn, a7 as er, t as tr, n as nr } from "../../useAnchorPositioning-DkEGnORe.js";
import { N as rr } from "../../noop-D0ZWT7db.js";
function Qe(e, t, n) {
return Math.floor(e / t) !== n;
}
function Xe(e, t) {
return t < 0 || t >= e.current.length;
}
function ct(e, t) {
return fe(e, {
disabledIndices: t
});
}
function _t(e, t) {
return fe(e, {
decrement: !0,
startingIndex: e.current.length,
disabledIndices: t
});
}
function fe(e, {
startingIndex: t = -1,
decrement: n = !1,
disabledIndices: r,
amount: u = 1
} = {}) {
let o = t;
do
o += n ? -u : u;
while (o >= 0 && o <= e.current.length - 1 && nt(e, o, r));
return o;
}
function or(e, {
event: t,
orientation: n,
loop: r,
rtl: u,
cols: o,
disabledIndices: i,
minIndex: h,
maxIndex: b,
prevIndex: c,
stopEvent: a = !1
}) {
let d = c;
if (t.key === bt) {
if (a && ae(t), c === -1)
d = b;
else if (d = fe(e, {
startingIndex: d,
amount: o,
decrement: !0,
disabledIndices: i
}), r && (c - o < h || d < 0)) {
const R = c % o, l = b % o, p = b - (l - R);
l === R ? d = b : d = l > R ? p : p - o;
}
Xe(e, d) && (d = c);
}
if (t.key === je && (a && ae(t), c === -1 ? d = h : (d = fe(e, {
startingIndex: c,
amount: o,
disabledIndices: i
}), r && c + o > b && (d = fe(e, {
startingIndex: c % o - o,
amount: o,
disabledIndices: i
}))), Xe(e, d) && (d = c)), n === "both") {
const R = Dt(c / o);
t.key === (u ? Oe : ke) && (a && ae(t), c % o !== o - 1 ? (d = fe(e, {
startingIndex: c,
disabledIndices: i
}), r && Qe(d, o, R) && (d = fe(e, {
startingIndex: c - c % o - 1,
disabledIndices: i
}))) : r && (d = fe(e, {
startingIndex: c - c % o - 1,
disabledIndices: i
})), Qe(d, o, R) && (d = c)), t.key === (u ? ke : Oe) && (a && ae(t), c % o !== 0 ? (d = fe(e, {
startingIndex: c,
decrement: !0,
disabledIndices: i
}), r && Qe(d, o, R) && (d = fe(e, {
startingIndex: c + (o - c % o),
decrement: !0,
disabledIndices: i
}))) : r && (d = fe(e, {
startingIndex: c + (o - c % o),
decrement: !0,
disabledIndices: i
})), Qe(d, o, R) && (d = c));
const l = Dt(b / o) === R;
Xe(e, d) && (r && l ? d = t.key === (u ? ke : Oe) ? b : fe(e, {
startingIndex: c - c % o - 1,
disabledIndices: i
}) : d = c);
}
return d;
}
function sr(e, t, n) {
const r = [];
let u = 0;
return e.forEach(({
width: o,
height: i
}, h) => {
if (o > t && process.env.NODE_ENV !== "production")
throw new Error(`[Floating UI]: Invalid grid - item width at index ${h} is greater than grid columns`);
let b = !1;
for (n && (u = 0); !b; ) {
const c = [];
for (let a = 0; a < o; a += 1)
for (let d = 0; d < i; d += 1)
c.push(u + a + d * t);
u % t + o <= t && c.every((a) => r[a] == null) ? (c.forEach((a) => {
r[a] = h;
}), b = !0) : u += 1;
}
}), [...r];
}
function ir(e, t, n, r, u) {
if (e === -1)
return -1;
const o = n.indexOf(e), i = t[e];
switch (u) {
case "tl":
return o;
case "tr":
return i ? o + i.width - 1 : o;
case "bl":
return i ? o + (i.height - 1) * r : o;
case "br":
return n.lastIndexOf(e);
default:
return -1;
}
}
function ur(e, t) {
return t.flatMap((n, r) => e.includes(n) ? [r] : []);
}
function nt(e, t, n) {
if (typeof n == "function")
return n(t);
if (n)
return n.includes(t);
const r = e.current[t];
return r == null || r.hasAttribute("disabled") || r.getAttribute("aria-disabled") === "true";
}
const Et = /* @__PURE__ */ s.createContext({
register: () => {
},
unregister: () => {
},
subscribeMapChange: () => () => {
},
elementsRef: {
current: []
},
nextIndexRef: {
current: 0
}
});
process.env.NODE_ENV !== "production" && (Et.displayName = "CompositeListContext");
function cr() {
return s.useContext(Et);
}
function ar(e) {
const {
children: t,
elementsRef: n,
labelsRef: r,
onMapChange: u
} = e, o = s.useRef(0), i = Tt(fr).current, h = Tt(lr).current, [b, c] = s.useState(0), a = s.useRef(b), d = ne((g, E) => {
h.set(g, E ?? null), a.current += 1, c(a.current);
}), R = ne((g) => {
h.delete(g), a.current += 1, c(a.current);
}), l = s.useMemo(() => {
const g = /* @__PURE__ */ new Map();
return Array.from(h.keys()).sort(dr).forEach((f, x) => {
const N = h.get(f) ?? {};
g.set(f, {
...N,
index: x
});
}), g;
}, [h, b]);
ce(() => {
a.current === b && (n.current.length !== l.size && (n.current.length = l.size), r && r.current.length !== l.size && (r.current.length = l.size)), u == null || u(l);
}, [u, l, n, r, b, a]);
const p = ne((g) => (i.add(g), () => {
i.delete(g);
}));
ce(() => {
i.forEach((g) => g(l));
}, [i, l]);
const y = s.useMemo(() => ({
register: d,
unregister: R,
subscribeMapChange: p,
elementsRef: n,
labelsRef: r,
nextIndexRef: o
}), [d, R, p, n, r, o]);
return /* @__PURE__ */ H(Et.Provider, {
value: y,
children: t
});
}
function lr() {
return /* @__PURE__ */ new Map();
}
function fr() {
return /* @__PURE__ */ new Set();
}
function dr(e, t) {
const n = e.compareDocumentPosition(t);
return n & Node.DOCUMENT_POSITION_FOLLOWING || n & Node.DOCUMENT_POSITION_CONTAINED_BY ? -1 : n & Node.DOCUMENT_POSITION_PRECEDING || n & Node.DOCUMENT_POSITION_CONTAINS ? 1 : 0;
}
function ln(e) {
return st(e, "base-ui");
}
let pr = /* @__PURE__ */ function(e) {
return e[e.None = 0] = "None", e[e.GuessFromOrder = 1] = "GuessFromOrder", e;
}({});
function fn(e = {}) {
const {
label: t,
metadata: n,
textRef: r,
indexGuessBehavior: u
} = e, {
register: o,
unregister: i,
subscribeMapChange: h,
elementsRef: b,
labelsRef: c,
nextIndexRef: a
} = cr(), d = s.useRef(-1), [R, l] = s.useState(u === pr.GuessFromOrder ? () => {
if (d.current === -1) {
const g = a.current;
a.current += 1, d.current = g;
}
return d.current;
} : -1), p = s.useRef(null), y = s.useCallback((g) => {
var E;
if (p.current = g, R !== -1 && g !== null && (b.current[R] = g, c)) {
const f = t !== void 0;
c.current[R] = f ? t : ((E = r == null ? void 0 : r.current) == null ? void 0 : E.textContent) ?? g.textContent;
}
}, [R, b, c, t, r]);
return ce(() => {
const g = p.current;
if (g)
return o(g, n), () => {
i(g);
};
}, [o, i, n]), ce(() => h((g) => {
var f;
const E = p.current ? (f = g.get(p.current)) == null ? void 0 : f.index : null;
E != null && l(E);
}), [h, l]), s.useMemo(() => ({
ref: y,
index: R
}), [R, y]);
}
const dn = /* @__PURE__ */ s.createContext(void 0);
process.env.NODE_ENV !== "production" && (dn.displayName = "CompositeRootContext");
function mr(e = !1) {
const t = s.useContext(dn);
if (t === void 0 && !e)
throw new Error("Base UI: CompositeRootContext is missing. Composite parts must be placed within <Composite.Root>.");
return t;
}
function gr(e) {
const {
focusableWhenDisabled: t,
disabled: n,
composite: r = !1,
tabIndex: u = 0,
isNativeButton: o
} = e, i = r && t !== !1, h = r && t === !1;
return {
props: s.useMemo(() => {
const c = {
// allow Tabbing away from focusableWhenDisabled elements
onKeyDown(a) {
n && t && a.key !== "Tab" && a.preventDefault();
}
};
return r || (c.tabIndex = u, !o && n && (c.tabIndex = t ? u : -1)), (o && (t || i) || !o && n) && (c["aria-disabled"] = n), o && (!t || h) && (c.disabled = n), c;
}, [r, n, t, i, h, o, u])
};
}
function hr(e = {}) {
const {
disabled: t = !1,
focusableWhenDisabled: n,
tabIndex: r = 0,
native: u = !0
} = e, o = s.useRef(null), i = mr(!0) !== void 0, h = ne(() => {
const a = o.current;
return !!((a == null ? void 0 : a.tagName) === "A" && (a != null && a.href));
}), {
props: b
} = gr({
focusableWhenDisabled: n,
disabled: t,
composite: i,
tabIndex: r,
isNativeButton: u
});
return ce(() => {
const a = o.current;
a instanceof HTMLButtonElement && i && t && b.disabled === void 0 && a.disabled && (a.disabled = !1);
}, [t, b.disabled, i]), {
getButtonProps: s.useCallback((a = {}) => {
const {
onClick: d,
onMouseDown: R,
onKeyUp: l,
onKeyDown: p,
onPointerDown: y,
...g
} = a;
return gt({
type: u ? "button" : void 0,
onClick(f) {
if (t) {
f.preventDefault();
return;
}
d == null || d(f);
},
onMouseDown(f) {
t || R == null || R(f);
},
onKeyDown(f) {
t || (St(f), p == null || p(f)), !f.baseUIHandlerPrevented && f.target === f.currentTarget && !u && !h() && f.key === "Enter" && !t && (d == null || d(f), f.preventDefault());
},
onKeyUp(f) {
t || (St(f), l == null || l(f)), !f.baseUIHandlerPrevented && f.target === f.currentTarget && !u && !t && f.key === " " && (d == null || d(f));
},
onPointerDown(f) {
if (t) {
f.preventDefault();
return;
}
y == null || y(f);
}
}, u ? void 0 : {
role: "button"
}, b, g);
}, [t, b, u, h]),
buttonRef: o
};
}
let Ht = 0;
function De(e, t = {}) {
const {
preventScroll: n = !1,
cancelPrevious: r = !0,
sync: u = !1
} = t;
r && cancelAnimationFrame(Ht);
const o = () => e == null ? void 0 : e.focus({
preventScroll: n
});
u ? o() : Ht = requestAnimationFrame(o);
}
const _e = {
inert: /* @__PURE__ */ new WeakMap(),
"aria-hidden": /* @__PURE__ */ new WeakMap(),
none: /* @__PURE__ */ new WeakMap()
};
function Kt(e) {
return e === "inert" ? _e.inert : e === "aria-hidden" ? _e["aria-hidden"] : _e.none;
}
let Ze = /* @__PURE__ */ new WeakSet(), et = {}, at = 0;
const br = () => typeof HTMLElement < "u" && "inert" in HTMLElement.prototype, pn = (e) => e && (e.host || pn(e.parentNode)), yr = (e, t) => t.map((n) => {
if (e.contains(n))
return n;
const r = pn(n);
return e.contains(r) ? r : null;
}).filter((n) => n != null);
function Rr(e, t, n, r) {
const u = "data-base-ui-inert", o = r ? "inert" : n ? "aria-hidden" : null, i = yr(t, e), h = /* @__PURE__ */ new Set(), b = new Set(i), c = [];
et[u] || (et[u] = /* @__PURE__ */ new WeakMap());
const a = et[u];
i.forEach(d), R(t), h.clear();
function d(l) {
!l || h.has(l) || (h.add(l), l.parentNode && d(l.parentNode));
}
function R(l) {
!l || b.has(l) || [].forEach.call(l.children, (p) => {
if (en(p) !== "script")
if (h.has(p))
R(p);
else {
const y = o ? p.getAttribute(o) : null, g = y !== null && y !== "false", E = Kt(o), f = (E.get(p) || 0) + 1, x = (a.get(p) || 0) + 1;
E.set(p, f), a.set(p, x), c.push(p), f === 1 && g && Ze.add(p), x === 1 && p.setAttribute(u, ""), !g && o && p.setAttribute(o, o === "inert" ? "" : "true");
}
});
}
return at += 1, () => {
c.forEach((l) => {
const p = Kt(o), g = (p.get(l) || 0) - 1, E = (a.get(l) || 0) - 1;
p.set(l, g), a.set(l, E), g || (!Ze.has(l) && o && l.removeAttribute(o), Ze.delete(l)), E || l.removeAttribute(u);
}), at -= 1, at || (_e.inert = /* @__PURE__ */ new WeakMap(), _e["aria-hidden"] = /* @__PURE__ */ new WeakMap(), _e.none = /* @__PURE__ */ new WeakMap(), Ze = /* @__PURE__ */ new WeakSet(), et = {});
};
}
function Wt(e, t = !1, n = !1) {
const r = de(e[0]).body;
return Rr(e.concat(Array.from(r.querySelectorAll("[aria-live]"))), r, t, n);
}
const zt = 20;
let Le = [];
function Mr(e) {
Le = Le.filter((t) => t.isConnected), e && en(e) !== "body" && (Le.push(e), Le.length > zt && (Le = Le.slice(-zt)));
}
function Yt() {
return Le.slice().reverse().find((e) => e.isConnected);
}
function Er(e) {
const t = yt();
return sn(e, t) ? e : tn(e, t)[0] || e;
}
function Gt(e, t) {
var i;
if (!t.current.includes("floating") && !((i = e.getAttribute("role")) != null && i.includes("dialog")))
return;
const n = yt(), u = Ln(e, n).filter((h) => {
const b = h.getAttribute("data-tabindex") || "";
return sn(h, n) || h.hasAttribute("data-tabindex") && !b.startsWith("-");
}), o = e.getAttribute("tabindex");
t.current.includes("floating") || u.length === 0 ? o !== "0" && e.setAttribute("tabindex", "0") : (o !== "-1" || e.hasAttribute("data-tabindex") && e.getAttribute("data-tabindex") !== "-1") && (e.setAttribute("tabindex", "-1"), e.setAttribute("data-tabindex", "-1"));
}
const mn = /* @__PURE__ */ s.forwardRef(function(t, n) {
return /* @__PURE__ */ H("button", {
...t,
type: "button",
ref: n,
tabIndex: -1,
style: nn
});
});
process.env.NODE_ENV !== "production" && (mn.displayName = "VisuallyHiddenDismiss");
function xr(e) {
const {
context: t,
children: n,
disabled: r = !1,
order: u = ["content"],
guards: o = !0,
initialFocus: i = 0,
returnFocus: h = !0,
restoreFocus: b = !1,
modal: c = !0,
visuallyHiddenDismiss: a = !1,
closeOnFocusOut: d = !0,
outsideElementsInert: R = !1,
getInsideElements: l = () => []
} = e, {
open: p,
onOpenChange: y,
events: g,
dataRef: E,
elements: {
domReference: f,
floating: x
}
} = t, N = ne(() => {
var L;
return (L = E.current.floatingContext) == null ? void 0 : L.nodeId;
}), B = ne(l), F = typeof i == "number" && i < 0, I = ft(f) && F, D = br(), v = D ? o : !0, W = !v || D && R, C = we(u), Re = we(i), ie = we(h), S = Ke(), M = Sn(), j = s.useRef(null), P = s.useRef(null), z = s.useRef(!1), re = s.useRef(!1), Y = s.useRef(-1), Ee = M != null, m = ot(x), ue = ne((L = m) => L ? tn(L, yt()) : []), oe = ne((L) => {
const A = ue(L);
return C.current.map((O) => f && O === "reference" ? f : m && O === "floating" ? m : A).filter(Boolean).flat();
});
s.useEffect(() => {
if (r || !c)
return;
function L(O) {
if (O.key === "Tab") {
he(m, Fe(de(m))) && ue().length === 0 && !I && ae(O);
const T = oe(), G = qe(O);
C.current[0] === "reference" && G === f && (ae(O), O.shiftKey ? De(T[T.length - 1]) : De(T[1])), C.current[1] === "floating" && G === m && O.shiftKey && (ae(O), De(T[0]));
}
}
const A = de(m);
return A.addEventListener("keydown", L), () => {
A.removeEventListener("keydown", L);
};
}, [r, f, m, c, C, I, ue, oe]), s.useEffect(() => {
if (r || !x)
return;
function L(A) {
const O = qe(A), G = ue().indexOf(O);
G !== -1 && (Y.current = G);
}
return x.addEventListener("focusin", L), () => {
x.removeEventListener("focusin", L);
};
}, [r, x, ue]), s.useEffect(() => {
if (r || !d)
return;
function L() {
re.current = !0, setTimeout(() => {
re.current = !1;
});
}
function A(O) {
const T = O.relatedTarget, G = O.currentTarget, $ = qe(O);
queueMicrotask(() => {
const se = N(), le = !(he(f, T) || he(x, T) || he(T, x) || he(M == null ? void 0 : M.portalNode, T) || T != null && T.hasAttribute(Lt("focus-guard")) || S && (Ft(S.nodesRef.current, se).find((V) => {
var K, q;
return he((K = V.context) == null ? void 0 : K.elements.floating, T) || he((q = V.context) == null ? void 0 : q.elements.domReference, T);
}) || At(S.nodesRef.current, se).find((V) => {
var K, q, k;
return [(K = V.context) == null ? void 0 : K.elements.floating, ot((q = V.context) == null ? void 0 : q.elements.floating)].includes(T) || ((k = V.context) == null ? void 0 : k.elements.domReference) === T;
})));
if (G === f && m && Gt(m, C), b && G !== f && !($ != null && $.isConnected) && Fe(de(m)) === de(m).body) {
Ue(m) && m.focus();
const V = Y.current, K = ue(), q = K[V] || K[K.length - 1] || m;
Ue(q) && q.focus();
}
if (E.current.insideReactTree) {
E.current.insideReactTree = !1;
return;
}
(I || !c) && T && le && !re.current && // Fix React 18 Strict Mode returnFocus due to double rendering.
T !== Yt() && (z.current = !0, y(!1, O, "focus-out"));
});
}
if (x && Ue(f))
return f.addEventListener("focusout", A), f.addEventListener("pointerdown", L), x.addEventListener("focusout", A), () => {
f.removeEventListener("focusout", A), f.removeEventListener("pointerdown", L), x.removeEventListener("focusout", A);
};
}, [r, f, x, m, c, S, M, y, d, b, ue, I, N, C, E]);
const U = s.useRef(null), ee = s.useRef(null), be = rt(U, M == null ? void 0 : M.beforeInsideRef), X = rt(ee, M == null ? void 0 : M.afterInsideRef);
s.useEffect(() => {
var se, le, V;
if (r || !x)
return;
const L = Array.from(((se = M == null ? void 0 : M.portalNode) == null ? void 0 : se.querySelectorAll(`[${Lt("portal")}]`)) || []), A = S ? At(S.nodesRef.current, N()) : [], O = S && !c ? A.map((K) => {
var q;
return (q = K.context) == null ? void 0 : q.elements.floating;
}) : [], T = (V = (le = A.find((K) => {
var q;
return ft(((q = K.context) == null ? void 0 : q.elements.domReference) || null);
})) == null ? void 0 : le.context) == null ? void 0 : V.elements.domReference, G = [x, T, ...L, ...O, ...B(), j.current, P.current, U.current, ee.current, M == null ? void 0 : M.beforeOutsideRef.current, M == null ? void 0 : M.afterOutsideRef.current, C.current.includes("reference") || I ? f : null].filter((K) => K != null), $ = c || I ? Wt(G, !W, W) : Wt(G);
return () => {
$();
};
}, [r, f, x, c, C, M, I, v, W, S, N, B]), ce(() => {
if (r || !Ue(m))
return;
const L = de(m), A = Fe(L);
queueMicrotask(() => {
const O = oe(m), T = Re.current, G = (typeof T == "number" ? O[T] : T.current) || m, $ = he(m, A);
!F && !$ && p && De(G, {
preventScroll: G === m
});
});
}, [r, p, m, F, oe, Re]), ce(() => {
if (r || !m)
return;
const L = de(m), A = Fe(L);
Mr(A);
function O({
reason: $,
event: se,
nested: le
}) {
if (["hover", "safe-polygon"].includes($) && se.type === "mouseleave" && (z.current = !0), $ === "outside-press")
if (le)
z.current = !1;
else if (rn(se) || on(se))
z.current = !1;
else {
let V = !1;
document.createElement("div").focus({
get preventScroll() {
return V = !0, !1;
}
}), V ? z.current = !1 : z.current = !0;
}
}
g.on("openchange", O);
const T = L.createElement("span");
T.setAttribute("tabindex", "-1"), T.setAttribute("aria-hidden", "true"), Object.assign(T.style, nn), Ee && f && f.insertAdjacentElement("afterend", T);
function G() {
if (typeof ie.current == "boolean") {
const $ = f || Yt();
return $ && $.isConnected ? $ : T;
}
return ie.current.current || T;
}
return () => {
g.off("openchange", O);
const $ = Fe(L), se = he(x, $) || S && Ft(S.nodesRef.current, N(), !1).some((V) => {
var K;
return he((K = V.context) == null ? void 0 : K.elements.floating, $);
}), le = G();
queueMicrotask(() => {
const V = Er(le);
// eslint-disable-next-line react-hooks/exhaustive-deps
ie.current && !z.current && Ue(V) && // If the focus moved somewhere else after mount, avoid returning focus
// since it likely entered a different element which should be
// respected: https://github.com/floating-ui/floating-ui/issues/2607
(!(V !== $ && $ !== L.body) || se) && V.focus({
preventScroll: !0
}), T.remove();
});
};
}, [r, x, m, ie, E, g, S, Ee, f, N]), s.useEffect(() => {
queueMicrotask(() => {
z.current = !1;
});
}, [r]), ce(() => {
if (!r && M)
return M.setFocusManagerState({
modal: c,
closeOnFocusOut: d,
open: p,
onOpenChange: y,
domReference: f
}), () => {
M.setFocusManagerState(null);
};
}, [r, M, c, p, y, d, f]), ce(() => {
r || m && Gt(m, C);
}, [r, m, C]);
function Ce(L) {
return r || !a || !c ? null : /* @__PURE__ */ H(mn, {
ref: L === "start" ? j : P,
onClick: (A) => y(!1, A.nativeEvent),
children: typeof a == "string" ? a : "Dismiss"
});
}
const Me = !r && v && (c ? !I : !0) && (Ee || c);
return /* @__PURE__ */ Ae(s.Fragment, {
children: [Me && /* @__PURE__ */ H(Bt, {
"data-type": "inside",
ref: be,
onFocus: (L) => {
var A;
if (c) {
const O = oe();
De(u[0] === "reference" ? O[0] : O[O.length - 1]);
} else if (M != null && M.preserveTabOrder && M.portalNode)
if (z.current = !1, Ut(L, M.portalNode)) {
const O = Pn(f);
O == null || O.focus();
} else
(A = M.beforeOutsideRef.current) == null || A.focus();
}
}), !I && Ce("start"), n, Ce("end"), Me && /* @__PURE__ */ H(Bt, {
"data-type": "inside",
ref: X,
onFocus: (L) => {
var A;
if (c)
De(oe()[0]);
else if (M != null && M.preserveTabOrder && M.portalNode)
if (d && (z.current = !0), Ut(L, M.portalNode)) {
const O = Dn(f);
O == null || O.focus();
} else
(A = M.afterOutsideRef.current) == null || A.focus();
}
})]
});
}
function wr(e, t = {}) {
const {
open: n,
onOpenChange: r,
dataRef: u
} = e, {
enabled: o = !0,
event: i = "click",
toggle: h = !0,
ignoreMouse: b = !1,
stickIfOpen: c = !0
} = t, a = s.useRef(void 0), d = An(), R = s.useMemo(() => ({
onPointerDown(l) {
a.current = l.pointerType;
},
onMouseDown(l) {
const p = a.current, y = l.nativeEvent;
if (l.button !== 0 || i === "click" || Vt(p, !0) && b)
return;
const g = u.current.openEvent, E = g == null ? void 0 : g.type, f = !(n && h && (!(g && c) || E === "click" || E === "mousedown"));
d.request(() => {
r(f, y, "click");
});
},
onClick(l) {
const p = a.current;
if (i === "mousedown" && p) {
a.current = void 0;
return;
}
if (Vt(p, !0) && b)
return;
const y = u.current.openEvent, g = y == null ? void 0 : y.type;
r(!(n && h && (!(y && c) || g === "click" || g === "mousedown" || g === "keydown" || g === "keyup")), l.nativeEvent, "click");
},
onKeyDown() {
a.current = void 0;
}
}), [u, i, b, r, n, c, h, d]);
return s.useMemo(() => o ? {
reference: R
} : ht, [o, R]);
}
const Cr = "Escape";
function it(e, t, n) {
switch (e) {
case "vertical":
return t;
case "horizontal":
return n;
default:
return t || n;
}
}
function tt(e, t) {
return it(t, e === bt || e === je, e === Oe || e === ke);
}
function lt(e, t, n) {
return it(t, e === je, n ? e === Oe : e === ke) || e === "Enter" || e === " " || e === "";
}
function $t(e, t, n) {
return it(t, n ? e === Oe : e === ke, e === je);
}
function qt(e, t, n, r) {
const u = n ? e === ke : e === Oe, o = e === bt;
return t === "both" || t === "horizontal" && r && r > 1 ? e === Cr : it(t, u, o);
}
function vr(e, t) {
const {
open: n,
onOpenChange: r,
elements: u,
floatingId: o
} = e, {
listRef: i,
activeIndex: h,
onNavigate: b = () => {
},
enabled: c = !0,
selectedIndex: a = null,
allowEscape: d = !1,
loop: R = !1,
nested: l = !1,
rtl: p = !1,
virtual: y = !1,
focusItemOnOpen: g = "auto",
focusItemOnHover: E = !0,
openOnArrowKeyDown: f = !0,
disabledIndices: x = void 0,
orientation: N = "vertical",
parentOrientation: B,
cols: F = 1,
scrollItemIntoView: I = !0,
virtualItemRef: D,
itemSizes: v,
dense: W = !1
} = t;
process.env.NODE_ENV !== "production" && (d && (R || console.warn("`useListNavigation` looping must be enabled to allow escaping."), y || console.warn("`useListNavigation` must be virtual to allow escaping.")), N === "vertical" && F > 1 && console.warn("In grid list navigation mode (`cols` > 1), the `orientation` should", 'be either "horizontal" or "both".'));
const C = ot(u.floating), Re = we(C), ie = Rt(), S = Ke();
ce(() => {
e.dataRef.current.orientation = N;
}, [e, N]);
const M = ft(u.domReference), j = s.useRef(g), P = s.useRef(a ?? -1), z = s.useRef(null), re = s.useRef(!0), Y = ne(() => {
b(P.current === -1 ? null : P.current);
}), Ee = s.useRef(Y), m = s.useRef(!!u.floating), ue = s.useRef(n), oe = s.useRef(!1), U = s.useRef(!1), ee = we(x), be = we(n), X = we(I), Ce = we(a), [Me, L] = s.useState(), [A, O] = s.useState(), T = ne(() => {
function k(J) {
var te;
y ? ((te = J.id) != null && te.endsWith("-fui-option") && (J.id = `${o}-${Math.random().toString(16).slice(2, 10)}`), L(J.id), S == null || S.events.emit("virtualfocus", J), D && (D.current = J)) : De(J, {
sync: oe.current,
preventScroll: !0
});
}
const _ = i.current[P.current], w = U.current;
_ && k(_), (oe.current ? (J) => J() : requestAnimationFrame)(() => {
var ve;
const J = i.current[P.current] || _;
if (!J)
return;
_ || k(J);
const te = X.current;
// eslint-disable-next-line @typescript-eslint/no-use-before-define
te && $ && (w || !re.current) && ((ve = J.scrollIntoView) == null || ve.call(J, typeof te == "boolean" ? {
block: "nearest",
inline: "nearest"
} : te));
});
});
ce(() => {
c && (n && u.floating ? j.current && a != null && (U.current = !0, P.current = a, Y()) : m.current && (P.current = -1, Ee.current()));
}, [c, n, u.floating, a, Y]), ce(() => {
if (c && n && u.floating)
if (h == null) {
if (oe.current = !1, Ce.current != null)
return;
if (m.current && (P.current = -1, T()), (!ue.current || !m.current) && j.current && (z.current != null || j.current === !0 && z.current == null)) {
let k = 0;
const _ = () => {
i.current[0] == null ? (k < 2 && (k ? requestAnimationFrame : queueMicrotask)(_), k += 1) : (P.current = z.current == null || lt(z.current, N, p) || l ? ct(i, ee.current) : _t(i, ee.current), z.current = null, Y());
};
_();
}
} else Xe(i, h) || (P.current = h, T(), U.current = !1);
}, [c, n, u.floating, h, Ce, l, i, N, p, Y, T, ee]), ce(() => {
var J, te;
if (!c || u.floating || !S || y || !m.current)
return;
const k = S.nodesRef.current, _ = (te = (J = k.find((ye) => ye.id === ie)) == null ? void 0 : J.context) == null ? void 0 : te.elements.floating, w = Fe(de(u.floating)), Z = k.some((ye) => ye.context && he(ye.context.elements.floating, w));
_ && !Z && re.current && _.focus({
preventScroll: !0
});
}, [c, u.floating, S, ie, y]), ce(() => {
if (!c || !S || !y || ie)
return;
function k(_) {
O(_.id), D && (D.current = _);
}
return S.events.on("virtualfocus", k), () => {
S.events.off("virtualfocus", k);
};
}, [c, S, y, ie, D]), ce(() => {
Ee.current = Y, ue.current = n, m.current = !!u.floating;
}), ce(() => {
n || (z.current = null, j.current = g);
}, [n, g]);
const G = h != null, $ = s.useMemo(() => {
function k(w) {
if (!be.current)
return;
const Z = i.current.indexOf(w);
Z !== -1 && P.current !== Z && (P.current = Z, Y());
}
return {
onFocus({
currentTarget: w
}) {
oe.current = !0, k(w);
},
onClick: ({
currentTarget: w
}) => w.focus({
preventScroll: !0
}),
// Safari
onMouseMove({
currentTarget: w
}) {
oe.current = !0, U.current = !1, E && k(w);
},
onPointerLeave({
pointerType: w
}) {
var Z;
!re.current || w === "touch" || (oe.current = !0, E && (P.current = -1, Y(), y || (Z = Re.current) == null || Z.focus({
preventScroll: !0
})));
}
};
}, [be, Re, E, i, Y, y]), se = s.useCallback(() => {
var k, _, w;
return B ?? ((w = (_ = (k = S == null ? void 0 : S.nodesRef.current.find((Z) => Z.id === ie)) == null ? void 0 : k.context) == null ? void 0 : _.dataRef) == null ? void 0 : w.current.orientation);
}, [ie, S, B]), le = ne((k) => {
if (re.current = !1, oe.current = !0, k.which === 229 || !be.current && k.currentTarget === Re.current)
return;
if (l && qt(k.key, N, p, F)) {
tt(k.key, se()) || ae(k), r(!1, k.nativeEvent, "list-navigation"), Ue(u.domReference) && (y ? S == null || S.events.emit("virtualfocus", u.domReference) : u.domReference.focus());
return;
}
const _ = P.current, w = ct(i, x), Z = _t(i, x);
if (M || (k.key === "Home" && (ae(k), P.current = w, Y()), k.key === "End" && (ae(k), P.current = Z, Y())), F > 1) {
const J = v || Array.from({
length: i.current.length
}, () => ({
width: 1,
height: 1
})), te = sr(J, F, W), ye = te.findIndex((pe) => pe != null && !nt(i, pe, x)), ve = te.reduce((pe, Ie, Be) => Ie != null && !nt(i, Ie, x) ? Be : pe, -1), Ne = te[or({
current: te.map((pe) => pe != null ? i.current[pe] : null)
}, {
event: k,
orientation: N,
loop: R,
rtl: p,
cols: F,
// treat undefined (empty grid spaces) as disabled indices so we
// don't end up in them
disabledIndices: ur([...(typeof x != "function" ? x : null) || i.current.map((pe, Ie) => nt(i, Ie, x) ? Ie : void 0), void 0], te),
minIndex: ye,
maxIndex: ve,
prevIndex: ir(
P.current > Z ? w : P.current,
J,
te,
F,
// use a corner matching the edge closest to the direction
// we're moving in so we don't end up in the same item. Prefer
// top/left over bottom/right.
// eslint-disable-next-line no-nested-ternary
k.key === je ? "bl" : k.key === (p ? Oe : ke) ? "tr" : "tl"
),
stopEvent: !0
})];
if (Ne != null && (P.current = Ne, Y()), N === "both")
return;
}
if (tt(k.key, N)) {
if (ae(k), n && !y && Fe(k.currentTarget.ownerDocument) === k.currentTarget) {
P.current = lt(k.key, N, p) ? w : Z, Y();
return;
}
lt(k.key, N, p) ? R ? P.current = // eslint-disable-next-line no-nested-ternary
_ >= Z ? d && _ !== i.current.length ? -1 : w : fe(i, {
startingIndex: _,
disabledIndices: x
}) : P.current = Math.min(Z, fe(i, {
startingIndex: _,
disabledIndices: x
})) : R ? P.current = // eslint-disable-next-line no-nested-ternary
_ <= w ? d && _ !== -1 ? i.current.length : Z : fe(i, {
startingIndex: _,
decrement: !0,
disabledIndices: x
}) : P.current = Math.max(w, fe(i, {
startingIndex: _,
decrement: !0,
disabledIndices: x
})), Xe(i, P.current) && (P.current = -1), Y();
}
}), V = s.useMemo(() => y && n && G && {
"aria-activedescendant": A || Me
}, [y, n, G, A, Me]), K = s.useMemo(() => ({
"aria-orientation": N === "both" ? void 0 : N,
...M ? {} : V,
onKeyDown: le,
onPointerMove() {
re.current = !0;
}
}), [V, le, N, M]), q = s.useMemo(() => {
function k(w) {
g === "auto" && rn(w.nativeEvent) && (j.current = !0);
}
function _(w) {
j.current = g, g === "auto" && on(w.nativeEvent) && (j.current = !0);
}
return {
...V,
onKeyDown(w) {
var Be, ze, Ye;
re.current = !1;
const Z = w.key.startsWith("Arrow"), J = ["Home", "End"].includes(w.key), te = Z || J, ye = $t(w.key, N, p), ve = qt(w.key, N, p, F), Ne = $t(w.key, se(), p), pe = tt(w.key, N), Ie = (l ? Ne : pe) || w.key === "Enter" || w.key.trim() === "";
if (y && n) {
const Te = S == null ? void 0 : S.nodesRef.current.find((Se) => Se.parentId == null), xe = S && Te ? Fn(S.nodesRef.current, Te.id) : null;
if (te && xe && D) {
const Se = new KeyboardEvent("keydown", {
key: w.key,
bubbles: !0
});
if (ye || ve) {
const Je = ((Be = xe.context) == null ? void 0 : Be.elements.domReference) === w.currentTarget, Ge = (
// eslint-disable-next-line no-nested-ternary
ve && !Je ? (ze = xe.context) == null ? void 0 : ze.elements.domReference : ye ? i.current.find(($e) => ($e == null ? void 0 : $e.id) === Me) : null
);
Ge && (ae(w), Ge.dispatchEvent(Se), O(void 0));
}
if ((pe || J) && xe.context && xe.context.open && xe.parentId && w.currentTarget !== xe.context.elements.domReference) {
ae(w), (Ye = xe.context.elements.domReference) == null || Ye.dispatchEvent(Se);
return;
}
}
return le(w);
}
if (!(!n && !f && Z)) {
if (Ie) {
const Te = tt(w.key, se());
z.current = l && Te ? null : w.key;
}
if (l) {
Ne && (ae(w), n ? (P.current = ct(i, ee.current), Y()) : r(!0, w.nativeEvent, "list-navigation"));
return;
}
pe && (a != null && (P.current = a), ae(w), !n && f ? r(!0, w.nativeEvent, "list-navigation") : le(w), n && Y());
}
},
onFocus() {
n && !y && (P.current = -1, Y());
},
onPointerDown: _,
onPointerEnter: _,
onMouseDown: k,
onClick: k
};
}, [Me, V, F, le, ee, g, i, l, Y, r, n, f, N, se, p, a, S, y, D]);
return s.useMemo(() => c ? {
reference: q,
floating: K,
item: $
} : {}, [c, q, K, $]);
}
const Ir = /* @__PURE__ */ new Map([["select", "listbox"], ["combobox", "listbox"], ["label", !1]]);
function Or(e, t = {}) {
var g;
const {
open: n,
elements: r,
floatingId: u
} = e, {
enabled: o = !0,
role: i = "dialog"
} = t, h = st(), b = ((g = r.domReference) == null ? void 0 : g.id) || h, c = s.useMemo(() => {
var E;
return ((E = ot(r.floating)) == null ? void 0 : E.id) || u;
}, [r.floating, u]), a = Ir.get(i) ?? i, R = Rt() != null, l = s.useMemo(() => a === "tooltip" || i === "label" ? {
[`aria-${i === "label" ? "labelledby" : "describedby"}`]: n ? c : void 0
} : {
"aria-expanded": n ? "true" : "false",
"aria-haspopup": a === "alertdialog" ? "dialog" : a,
"aria-controls": n ? c : void 0,
...a === "listbox" && {
role: "combobox"
},
...a === "menu" && {
id: b
},
...a === "menu" && R && {
role: "menuitem"
},
...i === "select" && {
"aria-autocomplete": "none"
},
...i === "combobox" && {
"aria-autocomplete": "list"
}
}, [a, c, R, n, b, i]), p = s.useMemo(() => {
const E = {
id: c,
...a && {
role: a
}
};
return a === "tooltip" || i === "label" ? E : {
...E,
...a === "menu" && {
"aria-labelledby": b
}
};
}, [a, c, b, i]), y = s.useCallback(({
active: E,
selected: f
}) => {
const x = {
role: "option",
...E && {
id: `${c}-fui-option`
}
};
switch (i) {
case "select":
return {
...x,
"aria-selected": E && f
};
case "combobox":
return {
...x,
"aria-selected": f
};
}
return {};
}, [c, i]);
return s.useMemo(() => o ? {
reference: l,
floating: p,
item: y
} : {}, [o, l, p, y]);
}
function kr(e, t) {
const {
open: n,
dataRef: r
} = e, {
listRef: u,
activeIndex: o,
onMatch: i,
onTypingChange: h,
enabled: b = !0,
findMatch: c = null,
resetMs: a = 750,
ignoreKeys: d = [],
selectedIndex: R = null
} = t, l = Ve(), p = s.useRef(""), y = s.useRef(R ?? o ?? -1), g = s.useRef(null), E = ne(i), f = ne(h), x = we(c), N = we(d);
ce(() => {
n && (l.clear(), g.current = null, p.current = "");
}, [n, l]), ce(() => {
n && p.current === "" && (y.current = R ?? o ?? -1);
}, [n, R, o]);
const B = ne((v) => {
v ? r.current.typing || (r.current.typing = v, f(v)) : r.current.typing && (r.current.typing = v, f(v));
}), F = ne((v) => {
function W(M, j, P) {
const z = x.current ? x.current(j, P) : j.find((re) => (re == null ? void 0 : re.toLocaleLowerCase().indexOf(P.toLocaleLowerCase())) === 0);
return z ? M.indexOf(z) : -1;
}
const C = u.current;
if (p.current.length > 0 && p.current[0] !== " " && (W(C, C, p.current) === -1 ? B(!1) : v.key === " " && ae(v)), C == null || N.current.includes(v.key) || // Character key.
v.key.length !== 1 || // Modifier key.
v.ctrlKey || v.metaKey || v.altKey)
return;
n && v.key !== " " && (ae(v), B(!0)), C.every((M) => {
var j, P;
return M ? ((j = M[0]) == null ? void 0 : j.toLocaleLowerCase()) !== ((P = M[1]) == null ? void 0 : P.toLocaleLowerCase()) : !0;
}) && p.current === v.key && (p.current = "", y.current = g.current), p.current += v.key, l.start(a, () => {
p.current = "", y.current = g.current, B(!1);
});
const ie = y.current, S = W(C, [...C.slice((ie || 0) + 1), ...C.slice(0, (ie || 0) + 1)], p.current);
S !== -1 ? (E(S), g.current = S) : v.key !== " " && (p.current = "", B(!1));
}), I = s.useMemo(() => ({
onKeyDown: F
}), [F]), D = s.useMemo(() => ({
onKeyDown: F,
onKeyUp(v) {
v.key === " " && B(!1);
}
}), [F, B]);
return s.useMemo(() => b ? {
reference: I,
floating: D
} : {}, [b, I, D]);
}
const gn = /* @__PURE__ */ s.forwardRef(function(t, n) {
const {
cutout: r,
...u
} = t;
let o;
if (r) {
const i = r == null ? void 0 : r.getBoundingClientRect();
o = `polygon(
0% 0%,
100% 0%,
100% 100%,
0% 100%,
0% 0%,
${i.left}px ${i.top}px,
${i.left}px ${i.bottom}px,
${i.right}px ${i.bottom}px,
${i.right}px ${i.top}px,
${i.left}px ${i.top}px
)`;
}
return /* @__PURE__ */ H("div", {
ref: n,
role: "presentation",
"data-base-ui-inert": "",
...u,
style: {
position: "fixed",
inset: 0,
userSelect: "none",
WebkitUserSelect: "none",
clipPath: o
}
});
});
process.env.NODE_ENV !== "production" && (gn.displayName = "InternalBackdrop");
function Nr(e) {
return In(19) ? e : e ? "true" : void 0;
}
let Xt = {}, jt = {}, Jt = "";
function Tr(e) {
if (typeof document > "u")
return !1;
const t = de(e);
return Mt(t).innerWidth - t.documentElement.clientWidth > 0;
}
function Sr(e) {
const n = de(e).documentElement, r = n.style.overflow;
return n.style.overflow = "hidden", () => {
n.style.overflow = r;
};
}
function Pr(e) {
var d;
const t = de(e), n = t.documentElement, r = t.body, u = Mt(n);
let o = 0, i = 0;
const h = Un.create();
if (un && (((d = u.visualViewport) == null ? void 0 : d.scale) ?? 1) !== 1)
return () => {
};
function b() {
var I;
const R = u.getComputedStyle(n), l = u.getComputedStyle(r);
o = n.scrollTop, i = n.scrollLeft, Xt = {
scrollbarGutter: n.style.scrollbarGutter,
overflowY: n.style.overflowY,
overflowX: n.style.overflowX
}, Jt = n.style.scrollBehavior, jt = {
position: r.style.position,
height: r.style.height,
width: r.style.width,
boxSizing: r.style.boxSizing,
overflowY: r.style.overflowY,
overflowX: r.style.overflowX,
scrollBehavior: r.style.scrollBehavior
};
const p = typeof CSS < "u" && ((I = CSS.supports) == null ? void 0 : I.call(CSS, "scrollbar-gutter", "stable")), y = n.scrollHeight > n.clientHeight, g = n.scrollWidth > n.clientWidth, E = R.overflowY === "scroll" || l.overflowY === "scroll", f = R.overflowX === "scroll" || l.overflowX === "scroll", x = Math.max(0, u.innerWidth - n.clientWidth), N = Math.max(0, u.innerHeight - n.clientHeight), B = parseFloat(l.marginTop) + parseFloat(l.marginBottom), F = parseFloat(l.marginLeft) + parseFloat(l.marginRight);
Object.assign(n.style, {
scrollbarGutter: "stable",
overflowY: !p && (y || E) ? "scroll" : "hidden",
overflowX: !p && (g || f) ? "scroll" : "hidden"
}), Object.assign(r.style, {
position: "relative",
height: B || N ? `calc(100dvh - ${B + N}px)` : "100dvh",
width: F || x ? `calc(100vw - ${F + x}px)` : "100vw",
boxSizing: "border-box",
overflow: "hidden",
scrollBehavior: "unset"
}), r.scrollTop = o, r.scrollLeft = i, n.setAttribute("data-base-ui-scroll-locked", ""), n.style.scrollBehavior = "unset";
}
function c() {
Object.assign(n.style, Xt), Object.assign(r.style, jt), n.scrollTop = o, n.scrollLeft = i, n.removeAttribute("data-base-ui-scroll-locked"), n.style.scrollBehavior = Jt;
}
function a() {
c(), h.request(b);
}
return b(), u.addEventListener("resize", a), () => {
h.cancel(), c(), u.removeEventListener("resize", a);
};
}
class Dr {
constructor() {
Pe(this, "lockCount", 0);
Pe(this, "restore", null);
Pe(this, "timeoutLock", Pt.create());
Pe(this, "timeoutUnlock", Pt.create());
Pe(this, "release", () => {
this.lockCount -= 1, this.lockCount === 0 && this.restore && this.timeoutUnlock.start(0, this.unlock);
});
Pe(this, "unlock", () => {
var t;
this.lockCount === 0 && this.restore && ((t = this.restore) == null || t.call(this), this.restore = null);
});
}
acquire(t) {
return this.lockCount += 1, this.lockCount === 1 && this.restore === null && this.timeoutLock.start(0, () => this.lock(t)), this.release;
}
lock(t) {
if (this.lockCount === 0 || this.restore !== null)
return;
const r = de(t).documentElement, u = Mt(r).getComputedStyle(r).overflowY;
if (u === "hidden" || u === "clip") {
this.restore = rr;
return;
}
const o = Bn || !Tr(t);
this.restore = o ? Sr(t) : Pr(t);
}
}
const Lr = new Dr();
function Ar(e) {
const {
enabled: t = !0,
mounted: n,
open: r,
referenceElement: u = null
} = e;
ce(() => {
if (un && n && !r) {
const o = de(u), i = o.body.style.userSelect, h = o.body.style.webkitUserSelect;
return o.body.style.userSelect = "none", o.body.style.webkitUserSelect = "none", () => {
o.body.style.userSelect = i, o.body.style.webkitUserSelect = h;
};
}
}, [n, r, u]), ce(() => {
if (t)
return Lr.acquire(u);
}, [t, u]);
}
const xt = /* @__PURE__ */ s.createContext(void 0);
process.env.NODE_ENV !== "production" && (xt.displayName = "ContextMenuRootContext");
function wt(e = !0) {
const t = s.useContext(xt);
if (t === void 0 && !e)
throw new Error("Base UI: ContextMenuRootContext is missing. ContextMenu parts must be placed within <ContextMenu.Root>.");
return t;
}
const Ct = /* @__PURE__ */ s.createContext(void 0);
process.env.NODE_ENV !== "production" && (Ct.displayName = "MenuPositionerContext");
function Fr() {
const e = s.useContext(Ct);
if (e === void 0)
throw new Error("Base UI: MenuPositionerContext is missing. MenuPositioner parts must be placed within <Menu.Positioner>.");
return e;
}
const ut = /* @__PURE__ */ s.createContext(void 0);
process.env.NODE_ENV !== "production" && (ut.displayName = "MenuRootContext");
function We(e) {
const t = s.useContext(ut);
if (t === void 0 && !e)
throw new Error("Base UI: MenuRootContext is missing. Menu parts must be placed within <Menu.Root>.");
return t;
}
const Br = {
type: "regular-item"
};
function hn(e) {
const {
closeOnClick: t,
disabled: n = !1,
highlighted: r,
id: u,
menuEvents: o,
allowMouseUpTriggerRef: i,
typingRef: h,
nativeButton: b,
itemMetadata: c
} = e, a = s.useRef(null), {
getButtonProps: d,
buttonRef: R
} = hr({
disabled: n,
focusableWhenDisabled: !0,
native: b
}), l = s.useCallback((y) => gt({
id: u,
role: "menuitem",
tabIndex: r ? 0 : -1,
onMouseEnter() {
c.type === "submenu-trigger" && c.setActive();
},
onKeyUp: (g) => {
g.key === " " && h.current && g.preventBaseUIHandler();
},
onClick: (g) => {
t && o.emit("close", {
domEvent: g,
reason: "item-press"
});
},
onMouseUp: () => {
a.current && i.current && c.type === "regular-item" && a.current.click();
}
}, y, d), [u, r, d, h, t, o, i, c]), p = rt(a, R);
return s.useMemo(() => ({
getItemProps: l,
itemRef: p
}), [l, p]);
}
const bn = /* @__PURE__ */ s.memo(/* @__PURE__ */ s.forwardRef(function(t, n) {
const {
className: r,
closeOnClick: u = !0,
disabled: o = !1,
highlighted: i,
id: h,
menuEvents: b,
itemProps: c,
render: a,
allowMouseUpTriggerRef: d,
typingRef: R,
nativeButton: l,
...p
} = t, {
getItemProps: y,
itemRef: g
} = hn({
closeOnClick: u,
disabled: o,
highlighted: i,
id: h,
menuEvents: b,
allowMouseUpTriggerRef: d,
typingRef: R,
nativeButton: l,
itemMetadata: Br
}), E = s.useMemo(() => ({
disabled: o,
highlighted: i
}), [o, i]);
return He("div", t, {
state: E,
ref: [g, n],
props: [c, p, y]
});
}));
process.env.NODE_ENV !== "production" && (bn.displayName = "InnerMenuItem");
const dt = /* @__PURE__ */ s.forwardRef(function(t, n) {
const {
id: r,
label: u,
nativeButton: o = !1,
...i
} = t, h = s.useRef(null), b = fn({
label: u
}), c = rt(n, b.ref, h), {
itemProps: a,
activeIndex: d,
allowMouseUpTriggerRef: R,
typingRef: l
} = We(), p = ln(r), y = b.index === d, {
events: g
} = Ke();
return /* @__PURE__ */ H(bn, {
...i,
id: p,
ref: c,
highlighted: y,
menuEvents: g,
itemProps: a,
allowMouseUpTriggerRef: R,
typingRef: l,
nativeButton: o
});
});
process.env.NODE_ENV !== "production" && (dt.displayName = "MenuItem");
const Ur = {
...an,
...Vn
}, pt = /* @__PURE__ */ s.forwardRef(function(t, n) {
const {
render: r,
className: u,
finalFocus: o,
...i
} = t, {
open: h,
setOpen: b,
popupRef: c,
transitionStatus: a,
popupProps: d,
mounted: R,
instantType: l,
onOpenChangeComplete: p,
parent: y,
lastOpenChangeReason: g,
rootId: E
} = We(), {
side: f,
align: x,
floatingContext: N
} = Fr();
cn({
open: h,
ref: c,
onComplete() {
h && (p == null || p(!0));
}
});
const {
events: B
} = Ke();
s.useEffect(() => {
function v(W) {
b(!1, W.domEvent, W.reason);
}
return B.on("close", v), () => {
B.off("close", v);
};
}, [B, b]);
const F = s.useMemo(() => ({
transitionStatus: a,
side: f,
align: x,
open: h,
nested: y.type === "menu",
instant: l
}), [a, f, x, h, y.type, l]), I = He("div", t, {
state: F,
ref: [n, c],
customStyleHookMapping: Ur,
props: [d, a === "starting" ? On : ht, i, {
"data-rootownerid": E
}]
});
let D = y.type === void 0 || y.type === "context-menu";
return y.type === "menubar" && g !== "outside-press" && (D = !0), /* @__PURE__ */ H(xr, {
context: N,
modal: !1,
disabled: !R,
returnFocus: o || D,
initialFocus: y.type === "menu" ? -1 : 0,
restoreFocus: !0,
children: I
});
});
process.env.NODE_ENV !== "production" && (pt.displayName = "MenuPopup");
const vt = /* @__PURE__ */ s.createContext(void 0);
process.env.NODE_ENV !== "production" && (vt.displayName = "MenuPortalContext");
function Vr() {
const e = s.useContext(vt);
if (e === void 0)
throw new Error("Base UI: <Menu.Portal> is missing.");
return e;
}
function Qt(e) {
const {
children: t,
keepMounted: n = !1,
container: r
} = e, {
mounted: u
} = We();
return u || n ? /* @__PURE__ */ H(vt.Provider, {
value: n,
children: /* @__PURE__ */ H(_n, {
root: r,
children: t
})
}) : null;
}
const mt = /* @__PURE__ */ s.forwardRef(function(t, n) {
var O;
const {
anchor: r,
positionMethod: u = "absolute",
className: o,
render: i,
side: h,
align: b,
sideOffset: c = 0,
alignOffset: a = 0,
collisionBoundary: d = "clippin