welcome-ui
Version:
Customizable design system with react, typescript, tailwindcss and ariakit.
946 lines (945 loc) • 24.9 kB
JavaScript
"use client";
import { createContext as yt, useRef as R, useContext as Pt, useState as q, useEffect as w, useCallback as at, useMemo as ge, isValidElement as ve } from "react";
import { c as J, f as O, a as j, q as zt, k as N, Z as It, g as P, h as z, _ as U, $ as ft, a0 as Ot, a1 as he, a2 as me, a3 as be, a4 as xt, Q as I, t as A, u as Gt, a5 as Ee, a6 as pe, Y as ye, J as Jt, a7 as Pe, a8 as xe, R as dt, a9 as De, aa as we, j as Se, ab as Kt, M as Fe, m as gt, ac as Ae, ad as Z, X as Te, V as Ce, ae as Le, af as Re } from "./U6HHPQDW-CzxyP5H7.js";
import { createPortal as kt, flushSync as Ne } from "react-dom";
import { jsx as E, jsxs as it, Fragment as st } from "react/jsx-runtime";
import { b as _, d as Me, u as Ve } from "./Q5W46E73-5xQblshY.js";
import { u as He, d as Qt, e as $e, f as _e, b as Dt, i as Ie, g as Oe, h as ke, j as Be } from "./WLZ6H5FH-CuTcX7sR.js";
var Bt = yt(null), qe = "span", Ut = J(
function(e) {
return e = {
...e,
style: {
border: 0,
clip: "rect(0 0 0 0)",
height: "1px",
margin: "-1px",
overflow: "hidden",
padding: 0,
position: "absolute",
whiteSpace: "nowrap",
width: "1px",
...e.style
}
}, e;
}
);
O(function(e) {
const n = Ut(e);
return j(qe, n);
});
var We = "span", je = J(
function(e) {
return e = {
"data-focus-trap": "",
tabIndex: 0,
"aria-hidden": !0,
...e,
style: {
// Prevents unintended scroll jumps.
position: "fixed",
top: 0,
left: 0,
...e.style
}
}, e = Ut(e), e;
}
), ut = O(function(e) {
const n = je(e);
return j(We, n);
}), Ye = "div";
function Xe(t) {
return P(t).body;
}
function ze(t, e) {
return e ? typeof e == "function" ? e(t) : e : P(t).createElement("div");
}
function Ge(t = "id") {
return `${t ? `${t}-` : ""}${Math.random().toString(36).slice(2, 8)}`;
}
function $(t) {
queueMicrotask(() => {
t == null || t.focus();
});
}
var Zt = J(function({
preserveTabOrder: e,
preserveTabOrderAnchor: n,
portalElement: r,
portalRef: i,
portal: o = !0,
...u
}) {
const c = R(null), f = zt(c, u.ref), b = Pt(Bt), [l, T] = q(null), [p, H] = q(
null
), k = R(null), M = R(null), Y = R(null), V = R(null);
return N(() => {
const a = c.current;
if (!a || !o) {
T(null);
return;
}
const v = ze(a, r);
if (!v) {
T(null);
return;
}
const m = v.isConnected;
if (m || (b || Xe(a)).appendChild(v), v.id || (v.id = a.id ? `portal/${a.id}` : Ge()), T(v), It(i, v), !m)
return () => {
v.remove(), It(i, null);
};
}, [o, r, b, i]), N(() => {
if (!o || !e || !n) return;
const v = P(n).createElement("span");
return v.style.position = "fixed", n.insertAdjacentElement("afterend", v), H(v), () => {
v.remove(), H(null);
};
}, [o, e, n]), w(() => {
if (!l || !e) return;
let a = 0;
const v = (m) => {
if (!U(m)) return;
const d = m.type === "focusin";
if (cancelAnimationFrame(a), d)
return he(l);
a = requestAnimationFrame(() => {
me(l, !0);
});
};
return l.addEventListener("focusin", v, !0), l.addEventListener("focusout", v, !0), () => {
cancelAnimationFrame(a), l.removeEventListener("focusin", v, !0), l.removeEventListener("focusout", v, !0);
};
}, [l, e]), u = z(
u,
(a) => {
if (a = // While the portal node is not in the DOM, we need to pass the
// current context to the portal context, otherwise it's going to
// reset to the body element on nested portals.
/* @__PURE__ */ E(Bt.Provider, { value: l || b, children: a }), !o) return a;
if (!l)
return /* @__PURE__ */ E(
"span",
{
ref: f,
id: u.id,
style: { position: "fixed" },
hidden: !0
}
);
a = /* @__PURE__ */ it(st, { children: [
e && l && /* @__PURE__ */ E(
ut,
{
ref: M,
"data-focus-trap": u.id,
className: "__focus-trap-inner-before",
onFocus: (m) => {
U(m, l) ? $(ft()) : $(k.current);
}
}
),
a,
e && l && /* @__PURE__ */ E(
ut,
{
ref: Y,
"data-focus-trap": u.id,
className: "__focus-trap-inner-after",
onFocus: (m) => {
U(m, l) ? $(Ot()) : $(V.current);
}
}
)
] }), l && (a = kt(a, l));
let v = /* @__PURE__ */ it(st, { children: [
e && l && /* @__PURE__ */ E(
ut,
{
ref: k,
"data-focus-trap": u.id,
className: "__focus-trap-outer-before",
onFocus: (m) => {
!(m.relatedTarget === V.current) && U(m, l) ? $(M.current) : $(Ot());
}
}
),
e && // We're using position: fixed here so that the browser doesn't
// add margin to the element when setting gap on a parent element.
/* @__PURE__ */ E("span", { "aria-owns": l == null ? void 0 : l.id, style: { position: "fixed" } }),
e && l && /* @__PURE__ */ E(
ut,
{
ref: V,
"data-focus-trap": u.id,
className: "__focus-trap-outer-after",
onFocus: (m) => {
if (U(m, l))
$(Y.current);
else {
const d = ft();
if (d === M.current) {
requestAnimationFrame(() => {
var X;
return (X = ft()) == null ? void 0 : X.focus();
});
return;
}
$(d);
}
}
}
)
] });
return p && e && (v = kt(
v,
p
)), /* @__PURE__ */ it(st, { children: [
v,
a
] });
},
[l, b, o, u.id, e, p]
), u = {
...u,
ref: f
}, u;
});
O(function(e) {
const n = Zt(e);
return j(Ye, n);
});
var qt = yt(0);
function Je({ level: t, children: e }) {
const n = Pt(qt), r = Math.max(
Math.min(t || n + 1, 6),
1
);
return /* @__PURE__ */ E(qt.Provider, { value: r, children: e });
}
var Ke = "div", te = J(function({ autoFocusOnShow: e = !0, ...n }) {
return n = z(
n,
(r) => /* @__PURE__ */ E(be.Provider, { value: e, children: r }),
[e]
), n;
});
O(function(e) {
const n = te(e);
return j(Ke, n);
});
function Qe(t, e) {
const r = P(t).createElement("button");
return r.type = "button", r.tabIndex = -1, r.textContent = "Dismiss popup", Object.assign(r.style, {
border: "0px",
clip: "rect(0 0 0 0)",
height: "1px",
margin: "-1px",
overflow: "hidden",
padding: "0px",
position: "absolute",
whiteSpace: "nowrap",
width: "1px"
}), r.addEventListener("click", e), t.prepend(r), () => {
r.removeEventListener("click", e), r.remove();
};
}
function Ue(t) {
const e = R(null);
return w(() => {
if (!t) {
e.current = null;
return;
}
return xt("mousedown", (r) => {
e.current = r.target;
}, !0);
}, [t]), e;
}
var vt = /* @__PURE__ */ new WeakMap();
function tt(t, e, n) {
vt.has(t) || vt.set(t, /* @__PURE__ */ new Map());
const r = vt.get(t), i = r.get(e);
if (!i)
return r.set(e, n()), () => {
var c;
(c = r.get(e)) == null || c(), r.delete(e);
};
const o = n(), u = () => {
o(), i(), r.delete(e);
};
return r.set(e, u), () => {
r.get(e) === u && (o(), r.set(e, i));
};
}
function wt(t, e, n) {
return tt(t, e, () => {
const i = t.getAttribute(e);
return t.setAttribute(e, n), () => {
i == null ? t.removeAttribute(e) : t.setAttribute(e, i);
};
});
}
function W(t, e, n) {
return tt(t, e, () => {
const i = e in t, o = t[e];
return t[e] = n, () => {
i ? t[e] = o : delete t[e];
};
});
}
function bt(t, e) {
return t ? tt(t, "style", () => {
const r = t.style.cssText;
return Object.assign(t.style, e), () => {
t.style.cssText = r;
};
}) : () => {
};
}
function Ze(t, e, n) {
return t ? tt(t, e, () => {
const i = t.style.getPropertyValue(e);
return t.style.setProperty(e, n), () => {
i ? t.style.setProperty(e, i) : t.style.removeProperty(e);
};
}) : () => {
};
}
var tn = ["SCRIPT", "STYLE"];
function Et(t) {
return `__ariakit-dialog-snapshot-${t}`;
}
function en(t, e) {
const n = P(e), r = Et(t);
if (!n.body[r]) return !0;
do {
if (e === n.body) return !1;
if (e[r]) return !0;
if (!e.parentElement) return !1;
e = e.parentElement;
} while (!0);
}
function nn(t, e, n) {
return tn.includes(e.tagName) || !en(t, e) ? !1 : !n.some(
(r) => r && A(e, r)
);
}
function St(t, e, n, r) {
for (let i of e) {
if (!(i != null && i.isConnected)) continue;
const o = e.some((f) => !f || f === i ? !1 : f.contains(i)), u = P(i), c = i;
for (; i.parentElement && i !== u.body; ) {
if (r == null || r(i.parentElement, c), !o)
for (const f of i.parentElement.children)
nn(t, f, e) && n(f, c);
i = i.parentElement;
}
}
}
function rn(t, e) {
const { body: n } = P(e[0]), r = [];
return St(t, e, (o) => {
r.push(W(o, Et(t), !0));
}), I(W(n, Et(t), !0), () => {
for (const o of r)
o();
});
}
function ee(t, ...e) {
if (!t) return !1;
const n = t.getAttribute("data-backdrop");
return n == null ? !1 : n === "" || n === "true" || !e.length ? !0 : e.some((r) => n === r);
}
function G(t = "", e = !1) {
return `__ariakit-dialog-${e ? "ancestor" : "outside"}${t ? `-${t}` : ""}`;
}
function on(t, e = "") {
return I(
W(t, G(), !0),
W(t, G(e), !0)
);
}
function ne(t, e = "") {
return I(
W(t, G("", !0), !0),
W(t, G(e, !0), !0)
);
}
function Ft(t, e) {
const n = G(e, !0);
if (t[n]) return !0;
const r = G(e);
do {
if (t[r]) return !0;
if (!t.parentElement) return !1;
t = t.parentElement;
} while (!0);
}
function Wt(t, e) {
const n = [], r = e.map((o) => o == null ? void 0 : o.id);
return St(
t,
e,
(o) => {
ee(o, ...r) || n.unshift(on(o, t));
},
(o, u) => {
u.hasAttribute("data-dialog") && u.id !== t || n.unshift(ne(o, t));
}
), () => {
for (const o of n)
o();
};
}
function un(t) {
return t.tagName === "HTML" ? !0 : A(P(t).body, t);
}
function sn(t, e) {
if (!t) return !1;
if (A(t, e)) return !0;
const n = e.getAttribute("aria-activedescendant");
if (n) {
const r = P(t).getElementById(n);
if (r)
return A(t, r);
}
return !1;
}
function an(t, e) {
if (!("clientY" in t)) return !1;
const n = e.getBoundingClientRect();
return n.width === 0 || n.height === 0 ? !1 : n.top <= t.clientY && t.clientY <= n.top + n.height && n.left <= t.clientX && t.clientX <= n.left + n.width;
}
function ht({
store: t,
type: e,
listener: n,
capture: r,
domReady: i
}) {
const o = Gt(n), u = _(t, "open"), c = R(!1);
N(() => {
if (!u || !i) return;
const { contentElement: f } = t.getState();
if (!f) return;
const b = () => {
c.current = !0;
};
return f.addEventListener("focusin", b, !0), () => f.removeEventListener("focusin", b, !0);
}, [t, u, i]), w(() => u ? xt(e, (b) => {
const { contentElement: l, disclosureElement: T } = t.getState(), p = b.target;
!l || !p || !un(p) || A(l, p) || sn(T, p) || p.hasAttribute("data-focus-trap") || an(b, l) || c.current && !Ft(p, l.id) || Ee(p) || o(b);
}, r) : void 0, [u, r]);
}
function mt(t, e) {
return typeof t == "function" ? t(e) : !!t;
}
function cn(t, e, n) {
const r = _(t, "open"), i = Ue(r), o = { store: t, domReady: n, capture: !0 };
ht({
...o,
type: "click",
listener: (u) => {
const { contentElement: c } = t.getState(), f = i.current;
f && pe(f) && Ft(f, c == null ? void 0 : c.id) && mt(e, u) && t.hide();
}
}), ht({
...o,
type: "focusin",
listener: (u) => {
const { contentElement: c } = t.getState();
c && u.target !== P(c) && mt(e, u) && t.hide();
}
}), ht({
...o,
type: "contextmenu",
listener: (u) => {
mt(e, u) && t.hide();
}
});
}
var jt = yt({});
function ln(t) {
const e = Pt(jt), [n, r] = q([]), i = at(
(c) => {
var f;
return r((b) => [...b, c]), I((f = e.add) == null ? void 0 : f.call(e, c), () => {
r((b) => b.filter((l) => l !== c));
});
},
[e]
);
N(() => Me(t, ["open", "contentElement"], (c) => {
var f;
if (c.open && c.contentElement)
return (f = e.add) == null ? void 0 : f.call(e, t);
}), [t, e]);
const o = ge(() => ({ store: t, add: i }), [t, i]);
return { wrapElement: at(
(c) => /* @__PURE__ */ E(jt.Provider, { value: o, children: c }),
[o]
), nestedDialogs: n };
}
function fn({
attribute: t,
contentId: e,
contentElement: n,
enabled: r
}) {
const [i, o] = ye(), u = at(() => {
if (!r || !n) return !1;
const { body: c } = P(n), f = c.getAttribute(t);
return !f || f === e;
}, [i, r, n, t, e]);
return w(() => {
if (!r || !e || !n) return;
const { body: c } = P(n);
if (u())
return c.setAttribute(t, e), () => c.removeAttribute(t);
const f = new MutationObserver(() => Ne(o));
return f.observe(c, { attributeFilter: [t] }), () => f.disconnect();
}, [i, r, e, n, u, t]), u;
}
function dn(t) {
const e = t.getBoundingClientRect().left;
return Math.round(e) + t.scrollLeft ? "paddingLeft" : "paddingRight";
}
function gn(t, e, n) {
const r = fn({
attribute: "data-dialog-prevent-body-scroll",
contentElement: t,
contentId: e,
enabled: n
});
w(() => {
if (!r() || !t) return;
const i = P(t), o = Jt(t), { documentElement: u, body: c } = i, f = u.style.getPropertyValue("--scrollbar-width"), b = f ? Number.parseInt(f, 10) : o.innerWidth - u.clientWidth, l = () => Ze(
u,
"--scrollbar-width",
`${b}px`
), T = dn(u), p = () => bt(c, {
overflow: "hidden",
[T]: `${b}px`
}), H = () => {
var M, Y;
const { scrollX: V, scrollY: a, visualViewport: v } = o, m = (M = v == null ? void 0 : v.offsetLeft) != null ? M : 0, d = (Y = v == null ? void 0 : v.offsetTop) != null ? Y : 0, X = bt(c, {
position: "fixed",
overflow: "hidden",
top: `${-(a - Math.floor(d))}px`,
left: `${-(V - Math.floor(m))}px`,
right: "0",
[T]: `${b}px`
});
return () => {
X(), process.env.NODE_ENV !== "test" && o.scrollTo({ left: V, top: a, behavior: "instant" });
};
}, k = Pe() && !xe();
return I(
l(),
k ? H() : p()
);
}, [r, t]);
}
function vn(t, ...e) {
if (!t) return !1;
const n = t.getAttribute("data-focus-trap");
return n == null ? !1 : e.length ? n === "" ? !1 : e.some((r) => n === r) : !0;
}
function re() {
return "inert" in HTMLElement.prototype;
}
function hn(t) {
return wt(t, "aria-hidden", "true");
}
function oe(t, e) {
if (!("style" in t)) return dt;
if (re())
return W(t, "inert", !0);
const r = De(t, !0).map((i) => {
if (e != null && e.some((u) => u && A(u, i))) return dt;
const o = tt(i, "focus", () => (i.focus = dt, () => {
delete i.focus;
}));
return I(wt(i, "tabindex", "-1"), o);
});
return I(
...r,
hn(t),
bt(t, {
pointerEvents: "none",
userSelect: "none",
cursor: "default"
})
);
}
function mn(t, e) {
const n = [], r = e.map((o) => o == null ? void 0 : o.id);
return St(
t,
e,
(o) => {
ee(o, ...r) || vn(o, ...r) || n.unshift(oe(o, e));
},
(o) => {
o.hasAttribute("role") && (e.some((u) => u && A(u, o)) || n.unshift(wt(o, "role", "none")));
}
), () => {
for (const o of n)
o();
};
}
var bn = "div", En = [
"a",
"button",
"details",
"dialog",
"div",
"form",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"header",
"img",
"input",
"label",
"li",
"nav",
"ol",
"p",
"section",
"select",
"span",
"summary",
"textarea",
"ul",
"svg"
];
J(
function(e) {
return e;
}
);
var pt = O(
// @ts-expect-error
function(e) {
return j(bn, e);
}
);
Object.assign(
pt,
En.reduce((t, e) => (t[e] = O(function(r) {
return j(e, r);
}), t), {})
);
function pn({
store: t,
backdrop: e,
alwaysVisible: n,
hidden: r
}) {
const i = R(null), o = He({ disclosure: t }), u = _(t, "contentElement");
w(() => {
const b = i.current, l = u;
b && l && (b.style.zIndex = getComputedStyle(l).zIndex);
}, [u]), N(() => {
const b = u == null ? void 0 : u.id;
if (!b) return;
const l = i.current;
if (l)
return ne(l, b);
}, [u]);
const c = Qt({
ref: i,
store: o,
role: "presentation",
"data-backdrop": (u == null ? void 0 : u.id) || "",
alwaysVisible: n,
hidden: r ?? void 0,
style: {
position: "fixed",
top: 0,
right: 0,
bottom: 0,
left: 0
}
});
return e ? ve(e) ? /* @__PURE__ */ E(pt, { ...c, render: e }) : /* @__PURE__ */ E(pt, { ...c, render: /* @__PURE__ */ E(typeof e != "boolean" ? e : "div", {}) }) : null;
}
function yn(t = {}) {
return $e(t);
}
function Pn(t, e, n) {
return _e(t, e, n);
}
function xn(t = {}) {
const [e, n] = Ve(yn, t);
return Pn(e, n, t);
}
var Dn = "div", Yt = Re();
function wn(t) {
const e = Kt();
return !e || t && A(t, e) ? !1 : !!Z(e);
}
function Xt(t, e = !1) {
if (!t) return null;
const n = "current" in t ? t.current : t;
return n ? e ? Z(n) ? n : null : n : null;
}
var Sn = J(function({
store: e,
open: n,
onClose: r,
focusable: i = !0,
modal: o = !0,
portal: u = !!o,
backdrop: c = !!o,
hideOnEscape: f = !0,
hideOnInteractOutside: b = !0,
getPersistentElements: l,
preventBodyScroll: T = !!o,
autoFocusOnShow: p = !0,
autoFocusOnHide: H = !0,
initialFocus: k,
finalFocus: M,
unmountOnHide: Y,
unstable_treeSnapshotKey: V,
...a
}) {
const v = Dt(), m = R(null), d = xn({
store: e || v,
open: n,
setOpen(s) {
if (s) return;
const h = m.current;
if (!h) return;
const y = new Event("close", { bubbles: !1, cancelable: !0 });
r && h.addEventListener("close", r, { once: !0 }), h.dispatchEvent(y), y.defaultPrevented && d.setOpen(!0);
}
}), { portalRef: X, domReady: x } = we(u, a.portalRef), ue = a.preserveTabOrder, ct = _(
d,
(s) => ue && !o && s.mounted
), C = Se(a.id), S = _(d, "open"), F = _(d, "mounted"), B = _(d, "contentElement"), ie = Ie(F, a.hidden, a.alwaysVisible);
gn(B, C, T && !ie), cn(d, b, x);
const { wrapElement: At, nestedDialogs: Tt } = ln(d);
a = z(a, At, [At]), N(() => {
if (!S) return;
const s = m.current, h = Kt(s, !0);
h && h.tagName !== "BODY" && (s && A(s, h) || d.setDisclosureElement(h));
}, [d, S]), Yt && w(() => {
if (!F) return;
const { disclosureElement: s } = d.getState();
if (!s || !Fe(s)) return;
const h = () => {
let y = !1;
const g = () => {
y = !0;
}, D = { capture: !0, once: !0 };
s.addEventListener("focusin", g, D), Ce(s, "mouseup", () => {
s.removeEventListener("focusin", g, !0), !y && Le(s);
});
};
return s.addEventListener("mousedown", h), () => {
s.removeEventListener("mousedown", h);
};
}, [d, F]), w(() => {
if (!F || !x) return;
const s = m.current;
if (!s) return;
const h = Jt(s), y = h.visualViewport || h, g = () => {
var D, L;
const Q = (L = (D = h.visualViewport) == null ? void 0 : D.height) != null ? L : h.innerHeight;
s.style.setProperty("--dialog-viewport-height", `${Q}px`);
};
return g(), y.addEventListener("resize", g), () => {
y.removeEventListener("resize", g);
};
}, [F, x]), w(() => {
if (!o || !F || !x) return;
const s = m.current;
if (!(!s || s.querySelector("[data-dialog-dismiss]")))
return Qe(s, d.hide);
}, [d, o, F, x]), N(() => {
if (!re() || S || !F || !x) return;
const s = m.current;
if (s)
return oe(s);
}, [S, F, x]);
const et = S && x;
N(() => {
if (!C || !et) return;
const s = m.current;
return rn(C, [s]);
}, [C, et, V]);
const Ct = Gt(l);
N(() => {
if (!C || !et) return;
const { disclosureElement: s } = d.getState(), h = m.current, y = Ct() || [], g = [
h,
...y,
...Tt.map((D) => D.getState().contentElement)
];
return o ? I(
Wt(C, g),
mn(C, g)
) : Wt(C, [s, ...g]);
}, [
C,
d,
et,
Ct,
Tt,
o,
V
]);
const Lt = !!p, Rt = gt(p), [se, ae] = q(!1);
w(() => {
if (!S || !Lt || !x || !(B != null && B.isConnected)) return;
const s = Xt(k, !0) || // If no initial focus is specified, we try to focus the first element
// with the autofocus attribute. If it's an Ariakit component, the
// Focusable component will consume the autoFocus prop and add the
// data-autofocus attribute to the element instead.
B.querySelector(
"[data-autofocus=true],[autofocus]"
) || // We have to fallback to the first focusable element otherwise portaled
// dialogs with preserveTabOrder set to true will not receive focus
// properly because the elements aren't tabbable until the dialog receives
// focus.
Ae(B, !0, u && ct) || // Finally, we fallback to the dialog element itself.
B, h = Z(s);
Rt(h ? s : null) && (ae(!0), queueMicrotask(() => {
s.focus(), Yt && h && s.scrollIntoView({ block: "nearest", inline: "nearest" });
}));
}, [
S,
Lt,
x,
B,
k,
u,
ct,
Rt
]);
const nt = !!H, Nt = gt(H), [rt, Mt] = q(!1);
w(() => {
if (S)
return Mt(!0), () => Mt(!1);
}, [S]);
const K = at(
(s, h = !0) => {
const { disclosureElement: y } = d.getState();
if (wn(s)) return;
let g = Xt(M) || y;
if (g != null && g.id) {
const L = P(g), Q = `[aria-activedescendant="${g.id}"]`, ot = L.querySelector(Q);
ot && (g = ot);
}
if (g && !Z(g)) {
const L = g.closest("[data-dialog]");
if (L != null && L.id) {
const Q = P(L), ot = `[aria-controls~="${L.id}"]`, _t = Q.querySelector(ot);
_t && (g = _t);
}
}
const D = g && Z(g);
if (!D && h) {
requestAnimationFrame(() => K(s, !1));
return;
}
Nt(D ? g : null) && D && (g == null || g.focus({ preventScroll: !0 }));
},
[d, M, Nt]
), lt = R(!1);
N(() => {
if (S || !rt || !nt) return;
const s = m.current;
lt.current = !0, K(s);
}, [S, rt, x, nt, K]), w(() => {
if (!rt || !nt) return;
const s = m.current;
return () => {
if (lt.current) {
lt.current = !1;
return;
}
K(s);
};
}, [rt, nt, K]);
const Vt = gt(f);
w(() => !x || !F ? void 0 : xt("keydown", (h) => {
if (h.key !== "Escape" || h.defaultPrevented) return;
const y = m.current;
if (!y || Ft(y)) return;
const g = h.target;
if (!g) return;
const { disclosureElement: D } = d.getState();
!!(g.tagName === "BODY" || A(y, g) || !D || A(D, g)) && Vt(h) && d.hide();
}, !0), [d, x, F, Vt]), a = z(
a,
(s) => /* @__PURE__ */ E(Je, { level: o ? 1 : void 0, children: s }),
[o]
);
const Ht = a.hidden, $t = a.alwaysVisible;
a = z(
a,
(s) => c ? /* @__PURE__ */ it(st, { children: [
/* @__PURE__ */ E(
pn,
{
store: d,
backdrop: c,
hidden: Ht,
alwaysVisible: $t
}
),
s
] }) : s,
[d, c, Ht, $t]
);
const [ce, le] = q(), [fe, de] = q();
return a = z(
a,
(s) => /* @__PURE__ */ E(Oe, { value: d, children: /* @__PURE__ */ E(ke.Provider, { value: le, children: /* @__PURE__ */ E(Be.Provider, { value: de, children: s }) }) }),
[d]
), a = {
id: C,
"data-dialog": "",
role: "dialog",
tabIndex: i ? -1 : void 0,
"aria-labelledby": ce,
"aria-describedby": fe,
...a,
ref: zt(m, a.ref)
}, a = te({
...a,
autoFocusOnShow: se
}), a = Qt({ store: d, ...a }), a = Te({ ...a, focusable: i }), a = Zt({ portal: u, ...a, portalRef: X, preserveTabOrder: ct }), a;
});
function Fn(t, e = Dt) {
return O(function(r) {
const i = e(), o = r.store || i;
return _(
o,
(c) => !r.unmountOnHide || (c == null ? void 0 : c.mounted) || !!r.open
) ? /* @__PURE__ */ E(t, { ...r }) : null;
});
}
var Mn = Fn(
O(function(e) {
const n = Sn(e);
return j(Dn, n);
}),
Dt
);
export {
Mn as D,
pt as R,
Sn as a,
yn as b,
Fn as c,
Pn as d,
xn as u
};