@konstructio/ui
Version:
A set of reusable and customizable React components built for konstruct.io
923 lines (922 loc) • 29.5 kB
JavaScript
import { Body as Mr } from "./components/Modal/components/Body/Body.js";
import { Footer as _r } from "./components/Modal/components/Footer/Footer.js";
import { Header as kr } from "./components/Modal/components/Header/Header.js";
import { jsx as k, jsxs as ee } from "react/jsx-runtime";
import S, { createContext as Lr, forwardRef as Ue, useState as re, useRef as ne, useCallback as W, useEffect as Ge, useMemo as Rr, Fragment as Cr, PureComponent as Wr, Children as K, isValidElement as X } from "react";
import { r as Br } from "./index-D7QNmo_D.js";
import { R as Ur } from "./index-CbTU3cnP.js";
import { p as v } from "./index-C5psggHV.js";
import { c as le, a as Gr, u as Hr, R as jr } from "./Combination-b348x__d.js";
import { cn as Me } from "./utils/index.js";
import { buttonCloseVariants as Vr, modalVariants as qr } from "./components/Modal/components/Wrapper/Wrapper.variants.js";
import { X as $r } from "./x-DU-Zw-L_.js";
import { useTheme as Kr } from "./contexts/theme.hook.js";
function Xr(e, r) {
if (e == null) return {};
var n = {};
for (var t in e) if ({}.hasOwnProperty.call(e, t)) {
if (r.indexOf(t) !== -1) continue;
n[t] = e[t];
}
return n;
}
function U() {
return U = Object.assign ? Object.assign.bind() : function(e) {
for (var r = 1; r < arguments.length; r++) {
var n = arguments[r];
for (var t in n) ({}).hasOwnProperty.call(n, t) && (e[t] = n[t]);
}
return e;
}, U.apply(null, arguments);
}
var ie = "data-focus-lock", He = "data-focus-lock-disabled", Yr = "data-no-focus-lock", zr = "data-autofocus-inside", Jr = "data-no-autofocus", te = {
width: "1px",
height: "0px",
padding: 0,
overflow: "hidden",
position: "fixed",
top: "1px",
left: "1px"
}, je = le({}, function(e) {
var r = e.target, n = e.currentTarget;
return {
target: r,
currentTarget: n
};
}), Ve = le(), Qr = le(), Zr = Gr({
async: !0,
ssr: typeof document < "u"
}), en = /* @__PURE__ */ Lr(void 0), rn = [], ve = /* @__PURE__ */ Ue(function(r, n) {
var t, o = re(), u = o[0], a = o[1], i = ne(), m = ne(!1), c = ne(null), d = re({}), s = d[1], f = r.children, p = r.disabled, l = p === void 0 ? !1 : p, b = r.noFocusGuards, g = b === void 0 ? !1 : b, x = r.persistentFocus, y = x === void 0 ? !1 : x, h = r.crossFrame, E = h === void 0 ? !0 : h, w = r.autoFocus, D = w === void 0 ? !0 : w, q = r.allowTextSelection, z = r.group, mr = r.className, br = r.whiteList, pr = r.hasPositiveIndices, Ie = r.shards, J = Ie === void 0 ? rn : Ie, Se = r.as, Ne = Se === void 0 ? "div" : Se, Te = r.lockProps, yr = Te === void 0 ? {} : Te, hr = r.sideCar, Pe = r.returnFocus, $ = Pe === void 0 ? !1 : Pe, gr = r.focusOptions, Q = r.onActivation, Z = r.onDeactivation, Fr = re({}), xr = Fr[0], Er = W(function(I) {
var M = I.captureFocusRestore;
if (!c.current) {
var _, T = (_ = document) == null ? void 0 : _.activeElement;
c.current = T, T !== document.body && (c.current = M(T));
}
i.current && Q && Q(i.current), m.current = !0, s();
}, [Q]), Or = W(function() {
m.current = !1, Z && Z(i.current), s();
}, [Z]), wr = W(function(I) {
var M = c.current;
if (M) {
var _ = (typeof M == "function" ? M() : M) || document.body, T = typeof $ == "function" ? $(_) : $;
if (T) {
var De = typeof T == "object" ? T : void 0;
c.current = null, I ? Promise.resolve().then(function() {
return _.focus(De);
}) : _.focus(De);
}
}
}, [$]), Ir = W(function(I) {
m.current && je.useMedium(I);
}, []), Sr = Ve.useMedium, Nr = W(function(I) {
i.current !== I && (i.current = I, a(I));
}, []);
process.env.NODE_ENV !== "production" && (typeof q < "u" && console.warn("React-Focus-Lock: allowTextSelection is deprecated and enabled by default"), Ge(function() {
!i.current && typeof Ne != "string" && console.error("FocusLock: could not obtain ref to internal node");
}, []));
var Tr = U((t = {}, t[He] = l && "disabled", t[ie] = z, t), yr), Ae = g !== !0, Pr = Ae && g !== "tail", Ar = Hr([n, Nr]), Dr = Rr(function() {
return {
observed: i,
shards: J,
enabled: !l,
active: m.current
};
}, [l, m.current, J, u]);
return /* @__PURE__ */ S.createElement(Cr, null, Ae && [
/* @__PURE__ */ S.createElement("div", {
key: "guard-first",
"data-focus-guard": !0,
tabIndex: l ? -1 : 0,
style: te
}),
pr ? /* @__PURE__ */ S.createElement("div", {
key: "guard-nearest",
"data-focus-guard": !0,
tabIndex: l ? -1 : 1,
style: te
}) : null
], !l && /* @__PURE__ */ S.createElement(hr, {
id: xr,
sideCar: Zr,
observed: u,
disabled: l,
persistentFocus: y,
crossFrame: E,
autoFocus: D,
whiteList: br,
shards: J,
onActivation: Er,
onDeactivation: Or,
returnFocus: wr,
focusOptions: gr,
noFocusGuards: g
}), /* @__PURE__ */ S.createElement(Ne, U({
ref: Ar
}, Tr, {
className: mr,
onBlur: Sr,
onFocus: Ir
}), /* @__PURE__ */ S.createElement(en.Provider, {
value: Dr
}, f)), Pr && /* @__PURE__ */ S.createElement("div", {
"data-focus-guard": !0,
tabIndex: l ? -1 : 0,
style: te
}));
});
ve.propTypes = process.env.NODE_ENV !== "production" ? {
children: v.node,
disabled: v.bool,
returnFocus: v.oneOfType([v.bool, v.object, v.func]),
focusOptions: v.object,
noFocusGuards: v.bool,
hasPositiveIndices: v.bool,
allowTextSelection: v.bool,
autoFocus: v.bool,
persistentFocus: v.bool,
crossFrame: v.bool,
group: v.string,
className: v.string,
whiteList: v.func,
shards: v.arrayOf(v.any),
as: v.oneOfType([v.string, v.func, v.object]),
lockProps: v.object,
onActivation: v.func,
onDeactivation: v.func,
sideCar: v.any.isRequired
} : {};
function ce(e, r) {
return ce = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(n, t) {
return n.__proto__ = t, n;
}, ce(e, r);
}
function nn(e, r) {
e.prototype = Object.create(r.prototype), e.prototype.constructor = e, ce(e, r);
}
function G(e) {
"@babel/helpers - typeof";
return G = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(r) {
return typeof r;
} : function(r) {
return r && typeof Symbol == "function" && r.constructor === Symbol && r !== Symbol.prototype ? "symbol" : typeof r;
}, G(e);
}
function tn(e, r) {
if (G(e) != "object" || !e) return e;
var n = e[Symbol.toPrimitive];
if (n !== void 0) {
var t = n.call(e, r);
if (G(t) != "object") return t;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (r === "string" ? String : Number)(e);
}
function on(e) {
var r = tn(e, "string");
return G(r) == "symbol" ? r : r + "";
}
function un(e, r, n) {
return (r = on(r)) in e ? Object.defineProperty(e, r, {
value: n,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = n, e;
}
function an(e, r) {
if (process.env.NODE_ENV !== "production") {
if (typeof e != "function")
throw new Error("Expected reducePropsToState to be a function.");
if (typeof r != "function")
throw new Error("Expected handleStateChangeOnClient to be a function.");
}
function n(t) {
return t.displayName || t.name || "Component";
}
return function(o) {
if (process.env.NODE_ENV !== "production" && typeof o != "function")
throw new Error("Expected WrappedComponent to be a React component.");
var u = [], a;
function i() {
a = e(u.map(function(c) {
return c.props;
})), r(a);
}
var m = /* @__PURE__ */ function(c) {
nn(d, c);
function d() {
return c.apply(this, arguments) || this;
}
d.peek = function() {
return a;
};
var s = d.prototype;
return s.componentDidMount = function() {
u.push(this), i();
}, s.componentDidUpdate = function() {
i();
}, s.componentWillUnmount = function() {
var p = u.indexOf(this);
u.splice(p, 1), i();
}, s.render = function() {
return /* @__PURE__ */ S.createElement(o, this.props);
}, d;
}(Wr);
return un(m, "displayName", "SideEffect(" + n(o) + ")"), m;
};
}
var O = function(e) {
for (var r = Array(e.length), n = 0; n < e.length; ++n)
r[n] = e[n];
return r;
}, A = function(e) {
return Array.isArray(e) ? e : [e];
}, qe = function(e) {
return Array.isArray(e) ? e[0] : e;
}, cn = function(e) {
if (e.nodeType !== Node.ELEMENT_NODE)
return !1;
var r = window.getComputedStyle(e, null);
return !r || !r.getPropertyValue ? !1 : r.getPropertyValue("display") === "none" || r.getPropertyValue("visibility") === "hidden";
}, $e = function(e) {
return e.parentNode && e.parentNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE ? (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
e.parentNode.host
) : e.parentNode;
}, Ke = function(e) {
return e === document || e && e.nodeType === Node.DOCUMENT_NODE;
}, fn = function(e) {
return e.hasAttribute("inert");
}, sn = function(e, r) {
return !e || Ke(e) || !cn(e) && !fn(e) && r($e(e));
}, Xe = function(e, r) {
var n = e.get(r);
if (n !== void 0)
return n;
var t = sn(r, Xe.bind(void 0, e));
return e.set(r, t), t;
}, dn = function(e, r) {
return e && !Ke(e) ? mn(e) ? r($e(e)) : !1 : !0;
}, Ye = function(e, r) {
var n = e.get(r);
if (n !== void 0)
return n;
var t = dn(r, Ye.bind(void 0, e));
return e.set(r, t), t;
}, ze = function(e) {
return e.dataset;
}, ln = function(e) {
return e.tagName === "BUTTON";
}, Je = function(e) {
return e.tagName === "INPUT";
}, Qe = function(e) {
return Je(e) && e.type === "radio";
}, vn = function(e) {
return !((Je(e) || ln(e)) && (e.type === "hidden" || e.disabled));
}, mn = function(e) {
var r = e.getAttribute(Jr);
return ![!0, "true", ""].includes(r);
}, me = function(e) {
var r;
return !!(e && (!((r = ze(e)) === null || r === void 0) && r.focusGuard));
}, fe = function(e) {
return !me(e);
}, bn = function(e) {
return !!e;
}, pn = function(e, r) {
var n = Math.max(0, e.tabIndex), t = Math.max(0, r.tabIndex), o = n - t, u = e.index - r.index;
if (o) {
if (!n)
return 1;
if (!t)
return -1;
}
return o || u;
}, yn = function(e) {
return e.tabIndex < 0 && !e.hasAttribute("tabindex") ? 0 : e.tabIndex;
}, be = function(e, r, n) {
return O(e).map(function(t, o) {
var u = yn(t);
return {
node: t,
index: o,
tabIndex: n && u === -1 ? (t.dataset || {}).focusGuard ? 0 : -1 : u
};
}).filter(function(t) {
return !r || t.tabIndex >= 0;
}).sort(pn);
}, hn = [
"button:enabled",
"select:enabled",
"textarea:enabled",
"input:enabled",
// elements with explicit roles will also use explicit tabindex
// '[role="button"]',
"a[href]",
"area[href]",
"summary",
"iframe",
"object",
"embed",
"audio[controls]",
"video[controls]",
"[tabindex]",
"[contenteditable]",
"[autofocus]"
], pe = hn.join(","), gn = "".concat(pe, ", [data-focus-guard]"), Ze = function(e, r) {
return O((e.shadowRoot || e).children).reduce(function(n, t) {
return n.concat(t.matches(r ? gn : pe) ? [t] : [], Ze(t));
}, []);
}, Fn = function(e, r) {
var n;
return e instanceof HTMLIFrameElement && (!((n = e.contentDocument) === null || n === void 0) && n.body) ? C([e.contentDocument.body], r) : [e];
}, C = function(e, r) {
return e.reduce(function(n, t) {
var o, u = Ze(t, r), a = (o = []).concat.apply(o, u.map(function(i) {
return Fn(i, r);
}));
return n.concat(
// add all tabbables inside and within shadow DOMs in DOM order
a,
// add if node is tabbable itself
t.parentNode ? O(t.parentNode.querySelectorAll(pe)).filter(function(i) {
return i === t;
}) : []
);
}, []);
}, xn = function(e) {
var r = e.querySelectorAll("[".concat(zr, "]"));
return O(r).map(function(n) {
return C([n]);
}).reduce(function(n, t) {
return n.concat(t);
}, []);
}, ye = function(e, r) {
return O(e).filter(function(n) {
return Xe(r, n);
}).filter(function(n) {
return vn(n);
});
}, _e = function(e, r) {
return r === void 0 && (r = /* @__PURE__ */ new Map()), O(e).filter(function(n) {
return Ye(r, n);
});
}, he = function(e, r, n) {
return be(ye(C(e, n), r), !0, n);
}, H = function(e, r) {
return be(ye(C(e), r), !1);
}, En = function(e, r) {
return ye(xn(e), r);
}, P = function(e, r) {
return e.shadowRoot ? P(e.shadowRoot, r) : Object.getPrototypeOf(e).contains !== void 0 && Object.getPrototypeOf(e).contains.call(e, r) ? !0 : O(e.children).some(function(n) {
var t;
if (n instanceof HTMLIFrameElement) {
var o = (t = n.contentDocument) === null || t === void 0 ? void 0 : t.body;
return o ? P(o, r) : !1;
}
return P(n, r);
});
}, On = function(e) {
for (var r = /* @__PURE__ */ new Set(), n = e.length, t = 0; t < n; t += 1)
for (var o = t + 1; o < n; o += 1) {
var u = e[t].compareDocumentPosition(e[o]);
(u & Node.DOCUMENT_POSITION_CONTAINED_BY) > 0 && r.add(o), (u & Node.DOCUMENT_POSITION_CONTAINS) > 0 && r.add(t);
}
return e.filter(function(a, i) {
return !r.has(i);
});
}, er = function(e) {
return e.parentNode ? er(e.parentNode) : e;
}, ge = function(e) {
var r = A(e);
return r.filter(Boolean).reduce(function(n, t) {
var o = t.getAttribute(ie);
return n.push.apply(n, o ? On(O(er(t).querySelectorAll("[".concat(ie, '="').concat(o, '"]:not([').concat(He, '="disabled"])')))) : [t]), n;
}, []);
}, wn = function(e) {
try {
return e();
} catch {
return;
}
}, j = function(e) {
if (e === void 0 && (e = document), !(!e || !e.activeElement)) {
var r = e.activeElement;
return r.shadowRoot ? j(r.shadowRoot) : r instanceof HTMLIFrameElement && wn(function() {
return r.contentWindow.document;
}) ? j(r.contentWindow.document) : r;
}
}, In = function(e, r) {
return e === r;
}, Sn = function(e, r) {
return !!O(e.querySelectorAll("iframe")).some(function(n) {
return In(n, r);
});
}, rr = function(e, r) {
return r === void 0 && (r = j(qe(e).ownerDocument)), !r || r.dataset && r.dataset.focusGuard ? !1 : ge(e).some(function(n) {
return P(n, r) || Sn(n, r);
});
}, Nn = function(e) {
e === void 0 && (e = document);
var r = j(e);
return r ? O(e.querySelectorAll("[".concat(Yr, "]"))).some(function(n) {
return P(n, r);
}) : !1;
}, Tn = function(e, r) {
return r.filter(Qe).filter(function(n) {
return n.name === e.name;
}).filter(function(n) {
return n.checked;
})[0] || e;
}, Fe = function(e, r) {
return Qe(e) && e.name ? Tn(e, r) : e;
}, Pn = function(e) {
var r = /* @__PURE__ */ new Set();
return e.forEach(function(n) {
return r.add(Fe(n, e));
}), e.filter(function(n) {
return r.has(n);
});
}, ke = function(e) {
return e[0] && e.length > 1 ? Fe(e[0], e) : e[0];
}, Le = function(e, r) {
return e.indexOf(Fe(r, e));
}, se = "NEW_FOCUS", An = function(e, r, n, t, o) {
var u = e.length, a = e[0], i = e[u - 1], m = me(t);
if (!(t && e.indexOf(t) >= 0)) {
var c = t !== void 0 ? n.indexOf(t) : -1, d = o ? n.indexOf(o) : c, s = o ? e.indexOf(o) : -1;
if (c === -1)
return s !== -1 ? s : se;
if (s === -1)
return se;
var f = c - d, p = n.indexOf(a), l = n.indexOf(i), b = Pn(n), g = t !== void 0 ? b.indexOf(t) : -1, x = o ? b.indexOf(o) : g, y = b.filter(function(z) {
return z.tabIndex >= 0;
}), h = t !== void 0 ? y.indexOf(t) : -1, E = o ? y.indexOf(o) : h, w = h >= 0 && E >= 0 ? (
// old/new are tabbables, measure distance in tabbable space
E - h
) : (
// or else measure in focusable space
x - g
);
if (!f && s >= 0 || r.length === 0)
return s;
var D = Le(e, r[0]), q = Le(e, r[r.length - 1]);
if (c <= p && m && Math.abs(f) > 1)
return q;
if (c >= l && m && Math.abs(f) > 1)
return D;
if (f && Math.abs(w) > 1)
return s;
if (c <= p)
return q;
if (c > l)
return D;
if (f)
return Math.abs(f) > 1 ? s : (u + s + f) % u;
}
}, Dn = function(e) {
return function(r) {
var n, t = (n = ze(r)) === null || n === void 0 ? void 0 : n.autofocus;
return (
// @ts-expect-error
r.autofocus || //
t !== void 0 && t !== "false" || //
e.indexOf(r) >= 0
);
};
}, Re = function(e, r, n) {
var t = e.map(function(u) {
var a = u.node;
return a;
}), o = _e(t.filter(Dn(n)));
return o && o.length ? ke(o) : ke(_e(r));
}, de = function(e, r) {
return r === void 0 && (r = []), r.push(e), e.parentNode && de(e.parentNode.host || e.parentNode, r), r;
}, oe = function(e, r) {
for (var n = de(e), t = de(r), o = 0; o < n.length; o += 1) {
var u = n[o];
if (t.indexOf(u) >= 0)
return u;
}
return !1;
}, nr = function(e, r, n) {
var t = A(e), o = A(r), u = t[0], a = !1;
return o.filter(Boolean).forEach(function(i) {
a = oe(a || i, i) || a, n.filter(Boolean).forEach(function(m) {
var c = oe(u, m);
c && (!a || P(c, a) ? a = c : a = oe(c, a));
});
}), a;
}, Ce = function(e, r) {
return e.reduce(function(n, t) {
return n.concat(En(t, r));
}, []);
}, Mn = function(e, r) {
var n = /* @__PURE__ */ new Map();
return r.forEach(function(t) {
return n.set(t.node, t);
}), e.map(function(t) {
return n.get(t);
}).filter(bn);
}, _n = function(e, r) {
var n = j(A(e).length > 0 ? document : qe(e).ownerDocument), t = ge(e).filter(fe), o = nr(n || e, e, t), u = /* @__PURE__ */ new Map(), a = H(t, u), i = a.filter(function(l) {
var b = l.node;
return fe(b);
});
if (i[0]) {
var m = H([o], u).map(function(l) {
var b = l.node;
return b;
}), c = Mn(m, i), d = c.map(function(l) {
var b = l.node;
return b;
}), s = c.filter(function(l) {
var b = l.tabIndex;
return b >= 0;
}).map(function(l) {
var b = l.node;
return b;
}), f = An(d, s, m, n, r);
if (f === se) {
var p = (
// first try only tabbable, and the fallback to all focusable, as long as at least one element should be picked for focus
Re(a, s, Ce(t, u)) || Re(a, d, Ce(t, u))
);
if (p)
return { node: p };
console.warn("focus-lock: cannot find any node to move focus into");
return;
}
return f === void 0 ? f : c[f];
}
}, kn = function(e) {
var r = ge(e).filter(fe), n = nr(e, e, r), t = be(C([n], !0), !0, !0), o = C(r, !1);
return t.map(function(u) {
var a = u.node, i = u.index;
return {
node: a,
index: i,
lockItem: o.indexOf(a) >= 0,
guard: me(a)
};
});
}, xe = function(e, r) {
e && ("focus" in e && e.focus(r), "contentWindow" in e && e.contentWindow && e.contentWindow.focus());
}, ue = 0, ae = !1, tr = function(e, r, n) {
n === void 0 && (n = {});
var t = _n(e, r);
if (!ae && t) {
if (ue > 2) {
console.error("FocusLock: focus-fighting detected. Only one focus management system could be active. See https://github.com/theKashey/focus-lock/#focus-fighting"), ae = !0, setTimeout(function() {
ae = !1;
}, 1);
return;
}
ue++, xe(t.node, n.focusOptions), ue--;
}
};
function B(e) {
if (!e)
return null;
if (typeof WeakRef > "u")
return function() {
return e || null;
};
var r = e ? new WeakRef(e) : null;
return function() {
return (r == null ? void 0 : r.deref()) || null;
};
}
var Ln = function(e) {
if (!e)
return null;
for (var r = [], n = e; n && n !== document.body; )
r.push({
current: B(n),
parent: B(n.parentElement),
left: B(n.previousElementSibling),
right: B(n.nextElementSibling)
}), n = n.parentElement;
return {
element: B(e),
stack: r,
ownerDocument: e.ownerDocument
};
}, Rn = function(e) {
var r, n, t, o, u;
if (e)
for (var a = e.stack, i = e.ownerDocument, m = /* @__PURE__ */ new Map(), c = 0, d = a; c < d.length; c++) {
var s = d[c], f = (r = s.parent) === null || r === void 0 ? void 0 : r.call(s);
if (f && i.contains(f)) {
for (var p = (n = s.left) === null || n === void 0 ? void 0 : n.call(s), l = s.current(), b = f.contains(l) ? l : void 0, g = (t = s.right) === null || t === void 0 ? void 0 : t.call(s), x = he([f], m), y = (
// that is element itself
(u = (o = b ?? // or something in it's place
(p == null ? void 0 : p.nextElementSibling)) !== null && o !== void 0 ? o : (
// or somebody to the right, still close enough
g
)) !== null && u !== void 0 ? u : (
// or somebody to the left, something?
p
)
); y; ) {
for (var h = 0, E = x; h < E.length; h++) {
var w = E[h];
if (y != null && y.contains(w.node))
return w.node;
}
y = y.nextElementSibling;
}
if (x.length)
return x[0].node;
}
}
}, or = function(e) {
var r = Ln(e);
return function() {
return Rn(r);
};
}, Cn = function(e, r, n) {
if (!e || !r)
return console.error("no element or scope given"), {};
var t = A(r);
if (t.every(function(a) {
return !P(a, e);
}))
return console.error("Active element is not contained in the scope"), {};
var o = n ? he(t, /* @__PURE__ */ new Map()) : H(t, /* @__PURE__ */ new Map()), u = o.findIndex(function(a) {
var i = a.node;
return i === e;
});
if (u !== -1)
return {
prev: o[u - 1],
next: o[u + 1],
first: o[0],
last: o[o.length - 1]
};
}, Wn = function(e, r) {
var n = r ? he(A(e), /* @__PURE__ */ new Map()) : H(A(e), /* @__PURE__ */ new Map());
return {
first: n[0],
last: n[n.length - 1]
};
}, Bn = function(e) {
return Object.assign({
scope: document.body,
cycle: !0,
onlyTabbable: !0
}, e);
}, ur = function(e, r, n) {
r === void 0 && (r = {});
var t = Bn(r), o = Cn(e, t.scope, t.onlyTabbable);
if (o) {
var u = n(o, t.cycle);
u && xe(u.node, t.focusOptions);
}
}, Un = function(e, r) {
r === void 0 && (r = {}), ur(e, r, function(n, t) {
var o = n.next, u = n.first;
return o || t && u;
});
}, Gn = function(e, r) {
r === void 0 && (r = {}), ur(e, r, function(n, t) {
var o = n.prev, u = n.last;
return o || t && u;
});
}, ar = function(e, r, n) {
var t, o = Wn(e, (t = r.onlyTabbable) !== null && t !== void 0 ? t : !0), u = o[n];
u && xe(u.node, r.focusOptions);
}, Hn = function(e, r) {
r === void 0 && (r = {}), ar(e, r, "first");
}, jn = function(e, r) {
r === void 0 && (r = {}), ar(e, r, "last");
};
function Ee(e) {
setTimeout(e, 1);
}
var Vn = function(r) {
return r && "current" in r ? r.current : r;
}, ir = function() {
return document && document.activeElement === document.body;
}, qn = function() {
return ir() || Nn();
}, L = null, F = null, We = function() {
return null;
}, R = null, V = !1, Oe = !1, $n = function() {
return !0;
}, Kn = function(r) {
return (L.whiteList || $n)(r);
}, Xn = function(r, n) {
R = {
observerNode: r,
portaledElement: n
};
}, Yn = function(r) {
return R && R.portaledElement === r;
};
function Be(e, r, n, t) {
var o = null, u = e;
do {
var a = t[u];
if (a.guard)
a.node.dataset.focusAutoGuard && (o = a);
else if (a.lockItem) {
if (u !== e)
return;
o = null;
} else
break;
} while ((u += n) !== r);
o && (o.node.tabIndex = 0);
}
var zn = function(r) {
return r ? !!V : V === "meanwhile";
}, Jn = function e(r, n, t) {
return n && (n.host === r && (!n.activeElement || t.contains(n.activeElement)) || n.parentNode && e(r, n.parentNode, t));
}, Qn = function(r, n) {
return n.some(function(t) {
return Jn(r, t, t);
});
}, cr = function(r) {
return H(r, /* @__PURE__ */ new Map());
}, Zn = function(r) {
return !cr([r.parentNode]).some(function(n) {
return n.node === r;
});
}, Y = function() {
var r = !1;
if (L) {
var n = L, t = n.observed, o = n.persistentFocus, u = n.autoFocus, a = n.shards, i = n.crossFrame, m = n.focusOptions, c = n.noFocusGuards, d = t || R && R.portaledElement;
if (ir() && F && F !== document.body && (!document.body.contains(F) || Zn(F))) {
var s = We();
s && s.focus();
}
var f = document && document.activeElement;
if (d) {
var p = [d].concat(a.map(Vn).filter(Boolean)), l = function() {
if (!zn(i) || !c || !F || Oe)
return !1;
var h = cr(p), E = h.findIndex(function(w) {
var D = w.node;
return D === F;
});
return E === 0 || E === h.length - 1;
};
if ((!f || Kn(f)) && (o || l() || !qn() || !F && u) && (d && !(rr(p) || f && Qn(f, p) || Yn(f)) && (document && !F && f && !u ? (f.blur && f.blur(), document.body.focus()) : (r = tr(p, F, {
focusOptions: m
}), R = {})), F = document && document.activeElement, F !== document.body && (We = or(F)), V = !1), document && f !== document.activeElement && document.querySelector("[data-focus-auto-guard]")) {
var b = document && document.activeElement, g = kn(p), x = g.map(function(y) {
var h = y.node;
return h;
}).indexOf(b);
x > -1 && (g.filter(function(y) {
var h = y.guard, E = y.node;
return h && E.dataset.focusAutoGuard;
}).forEach(function(y) {
var h = y.node;
return h.removeAttribute("tabIndex");
}), Be(x, g.length, 1, g), Be(x, -1, -1, g));
}
}
}
return r;
}, fr = function(r) {
Y() && r && (r.stopPropagation(), r.preventDefault());
}, we = function() {
return Ee(Y);
}, et = function(r) {
var n = r.target, t = r.currentTarget;
t.contains(n) || Xn(t, n);
}, rt = function() {
return null;
}, sr = function() {
Oe = !0;
}, dr = function() {
Oe = !1, V = "just", Ee(function() {
V = "meanwhile";
});
}, nt = function() {
document.addEventListener("focusin", fr), document.addEventListener("focusout", we), window.addEventListener("focus", sr), window.addEventListener("blur", dr);
}, tt = function() {
document.removeEventListener("focusin", fr), document.removeEventListener("focusout", we), window.removeEventListener("focus", sr), window.removeEventListener("blur", dr);
};
function ot(e) {
return e.filter(function(r) {
var n = r.disabled;
return !n;
});
}
var lr = {
moveFocusInside: tr,
focusInside: rr,
focusNextElement: Un,
focusPrevElement: Gn,
focusFirstElement: Hn,
focusLastElement: jn,
captureFocusRestore: or
};
function ut(e) {
var r = e.slice(-1)[0];
r && !L && nt();
var n = L, t = n && r && r.id === n.id;
L = r, n && !t && (n.onDeactivation(), e.filter(function(o) {
var u = o.id;
return u === n.id;
}).length || n.returnFocus(!r)), r ? (F = null, (!t || n.observed !== r.observed) && r.onActivation(lr), Y(), Ee(Y)) : (tt(), F = null);
}
je.assignSyncMedium(et);
Ve.assignMedium(we);
Qr.assignMedium(function(e) {
return e(lr);
});
const at = an(ot, ut)(rt);
var vr = /* @__PURE__ */ Ue(function(r, n) {
return /* @__PURE__ */ S.createElement(ve, U({
sideCar: at,
ref: n
}, r));
}), it = ve.propTypes || {}, ct = Xr(it, ["sideCar"]);
vr.propTypes = process.env.NODE_ENV !== "production" ? ct : {};
const ft = ({
children: e,
theme: r,
className: n,
buttonCloseClassName: t,
onClose: o
}) => {
const { theme: u } = Kr(), a = K.toArray(e).find(
(d) => X(d) && d.type === N.Header
), i = K.toArray(e).find(
(d) => X(d) && d.type === N.Body
), m = K.toArray(e).find(
(d) => X(d) && d.type === N.Footer
), c = K.toArray(e).filter(
(d) => !X(d) || ![N.Header, N.Body, N.Footer].includes(
d.type
)
);
return /* @__PURE__ */ k(vr, { returnFocus: !0, children: /* @__PURE__ */ k(jr, { children: /* @__PURE__ */ ee("div", { className: "fixed inset-0 grid place-content-center", children: [
/* @__PURE__ */ k(
"div",
{
className: "absolute inset-0 bg-black opacity-75",
onClick: o,
role: "presentation"
}
),
/* @__PURE__ */ ee(
"div",
{
className: Me(
qr({
className: n,
theme: r ?? u
})
),
role: "dialog",
"aria-modal": "true",
children: [
a,
/* @__PURE__ */ ee(
"button",
{
className: Me(
Vr({
className: t,
theme: r ?? u
})
),
onClick: o,
children: [
/* @__PURE__ */ k($r, {}),
/* @__PURE__ */ k(Ur, { children: "Dismiss modal" })
]
}
),
i ?? c,
m
]
}
)
] }) }) });
}, N = ({ isOpen: e, onClose: r, ...n }) => (Ge(() => {
const t = new AbortController(), o = (u) => {
u.code === "Escape" && (r == null || r());
};
return window.addEventListener("keydown", o, {
signal: t.signal
}), () => {
t.abort();
};
}, [r]), e ? Br.createPortal(
/* @__PURE__ */ k(ft, { ...n, onClose: r }),
document.body
) : null);
N.Header = kr;
N.Body = Mr;
N.Footer = _r;
export {
N as M,
ft as W
};