UNPKG

dgz-ui

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript

222 lines (221 loc) 7.6 kB
import * as i from "react"; import { jsx as h } from "react/jsx-runtime"; import * as g from "react-dom"; import { c as x, u as A } from "./index-DLcqcWxM.es.js"; import { u as P } from "./index-Dt3MSLsk.es.js"; function F(n, e) { const r = i.createContext(e), o = (s) => { const { children: u, ...c } = s, a = i.useMemo(() => c, Object.values(c)); return /* @__PURE__ */ h(r.Provider, { value: a, children: u }); }; o.displayName = n + "Provider"; function t(s) { const u = i.useContext(r); if (u) return u; if (e !== void 0) return e; throw new Error(`\`${s}\` must be used within \`${n}\``); } return [o, t]; } function V(n, e = []) { let r = []; function o(s, u) { const c = i.createContext(u), a = r.length; r = [...r, u]; const l = (f) => { var v; const { scope: m, children: d, ...N } = f, S = ((v = m == null ? void 0 : m[n]) == null ? void 0 : v[a]) || c, C = i.useMemo(() => N, Object.values(N)); return /* @__PURE__ */ h(S.Provider, { value: C, children: d }); }; l.displayName = s + "Provider"; function p(f, m) { var S; const d = ((S = m == null ? void 0 : m[n]) == null ? void 0 : S[a]) || c, N = i.useContext(d); if (N) return N; if (u !== void 0) return u; throw new Error(`\`${f}\` must be used within \`${s}\``); } return [l, p]; } const t = () => { const s = r.map((u) => i.createContext(u)); return function(c) { const a = (c == null ? void 0 : c[n]) || s; return i.useMemo( () => ({ [`__scope${n}`]: { ...c, [n]: a } }), [c, a] ); }; }; return t.scopeName = n, [o, O(t, ...e)]; } function O(...n) { const e = n[0]; if (n.length === 1) return e; const r = () => { const o = n.map((t) => ({ useScope: t(), scopeName: t.scopeName })); return function(s) { const u = o.reduce((c, { useScope: a, scopeName: l }) => { const f = a(s)[`__scope${l}`]; return { ...c, ...f }; }, {}); return i.useMemo(() => ({ [`__scope${e.scopeName}`]: u }), [u]); }; }; return r.scopeName = e.scopeName, r; } function B(n, e, { checkForDefaultPrevented: r = !0 } = {}) { return function(t) { if (n == null || n(t), r === !1 || !t.defaultPrevented) return e == null ? void 0 : e(t); }; } // @__NO_SIDE_EFFECTS__ function w(n) { const e = /* @__PURE__ */ E(n), r = i.forwardRef((o, t) => { const { children: s, ...u } = o, c = i.Children.toArray(s), a = c.find(R); if (a) { const l = a.props.children, p = c.map((f) => f === a ? i.Children.count(l) > 1 ? i.Children.only(null) : i.isValidElement(l) ? l.props.children : null : f); return /* @__PURE__ */ h(e, { ...u, ref: t, children: i.isValidElement(l) ? i.cloneElement(l, void 0, p) : null }); } return /* @__PURE__ */ h(e, { ...u, ref: t, children: s }); }); return r.displayName = `${n}.Slot`, r; } // @__NO_SIDE_EFFECTS__ function E(n) { const e = i.forwardRef((r, o) => { const { children: t, ...s } = r; if (i.isValidElement(t)) { const u = T(t), c = b(s, t.props); return t.type !== i.Fragment && (c.ref = o ? x(o, u) : u), i.cloneElement(t, c); } return i.Children.count(t) > 1 ? i.Children.only(null) : null; }); return e.displayName = `${n}.SlotClone`, e; } var M = Symbol("radix.slottable"); function R(n) { return i.isValidElement(n) && typeof n.type == "function" && "__radixId" in n.type && n.type.__radixId === M; } function b(n, e) { const r = { ...e }; for (const o in e) { const t = n[o], s = e[o]; /^on[A-Z]/.test(o) ? t && s ? r[o] = (...c) => { const a = s(...c); return t(...c), a; } : t && (r[o] = t) : o === "style" ? r[o] = { ...t, ...s } : o === "className" && (r[o] = [t, s].filter(Boolean).join(" ")); } return { ...n, ...r }; } function T(n) { var o, t; let e = (o = Object.getOwnPropertyDescriptor(n.props, "ref")) == null ? void 0 : o.get, r = e && "isReactWarning" in e && e.isReactWarning; return r ? n.ref : (e = (t = Object.getOwnPropertyDescriptor(n, "ref")) == null ? void 0 : t.get, r = e && "isReactWarning" in e && e.isReactWarning, r ? n.props.ref : n.props.ref || n.ref); } var I = [ "a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "select", "span", "svg", "ul" ], k = I.reduce((n, e) => { const r = /* @__PURE__ */ w(`Primitive.${e}`), o = i.forwardRef((t, s) => { const { asChild: u, ...c } = t, a = u ? r : e; return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ h(a, { ...c, ref: s }); }); return o.displayName = `Primitive.${e}`, { ...n, [e]: o }; }, {}); function Z(n, e) { n && g.flushSync(() => n.dispatchEvent(e)); } function _(n, e) { return i.useReducer((r, o) => e[r][o] ?? r, n); } var D = (n) => { const { present: e, children: r } = n, o = $(e), t = typeof r == "function" ? r({ present: o.isPresent }) : i.Children.only(r), s = A(o.ref, U(t)); return typeof r == "function" || o.isPresent ? i.cloneElement(t, { ref: s }) : null; }; D.displayName = "Presence"; function $(n) { const [e, r] = i.useState(), o = i.useRef(null), t = i.useRef(n), s = i.useRef("none"), u = n ? "mounted" : "unmounted", [c, a] = _(u, { mounted: { UNMOUNT: "unmounted", ANIMATION_OUT: "unmountSuspended" }, unmountSuspended: { MOUNT: "mounted", ANIMATION_END: "unmounted" }, unmounted: { MOUNT: "mounted" } }); return i.useEffect(() => { const l = y(o.current); s.current = c === "mounted" ? l : "none"; }, [c]), P(() => { const l = o.current, p = t.current; if (p !== n) { const m = s.current, d = y(l); n ? a("MOUNT") : d === "none" || (l == null ? void 0 : l.display) === "none" ? a("UNMOUNT") : a(p && m !== d ? "ANIMATION_OUT" : "UNMOUNT"), t.current = n; } }, [n, a]), P(() => { if (e) { let l; const p = e.ownerDocument.defaultView ?? window, f = (d) => { const S = y(o.current).includes(CSS.escape(d.animationName)); if (d.target === e && S && (a("ANIMATION_END"), !t.current)) { const C = e.style.animationFillMode; e.style.animationFillMode = "forwards", l = p.setTimeout(() => { e.style.animationFillMode === "forwards" && (e.style.animationFillMode = C); }); } }, m = (d) => { d.target === e && (s.current = y(o.current)); }; return e.addEventListener("animationstart", m), e.addEventListener("animationcancel", f), e.addEventListener("animationend", f), () => { p.clearTimeout(l), e.removeEventListener("animationstart", m), e.removeEventListener("animationcancel", f), e.removeEventListener("animationend", f); }; } else a("ANIMATION_END"); }, [e, a]), { isPresent: ["mounted", "unmountSuspended"].includes(c), ref: i.useCallback((l) => { o.current = l ? getComputedStyle(l) : null, r(l); }, []) }; } function y(n) { return (n == null ? void 0 : n.animationName) || "none"; } function U(n) { var o, t; let e = (o = Object.getOwnPropertyDescriptor(n.props, "ref")) == null ? void 0 : o.get, r = e && "isReactWarning" in e && e.isReactWarning; return r ? n.ref : (e = (t = Object.getOwnPropertyDescriptor(n, "ref")) == null ? void 0 : t.get, r = e && "isReactWarning" in e && e.isReactWarning, r ? n.props.ref : n.props.ref || n.ref); } export { k as P, D as a, V as b, B as c, F as d, Z as e }; //# sourceMappingURL=index-BVqmUhu5.es.js.map