UNPKG

dgz-ui

Version:

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

79 lines (78 loc) 3.01 kB
import * as s from "react"; import { u as g } from "./index-DLcqcWxM.js"; import { u as A } from "./index-ljY4mZHt.js"; function y(n, e, { checkForDefaultPrevented: t = !0 } = {}) { return function(o) { if (n == null || n(o), t === !1 || !o.defaultPrevented) return e == null ? void 0 : e(o); }; } function P(n, e) { return s.useReducer((t, r) => e[t][r] ?? t, n); } var R = (n) => { const { present: e, children: t } = n, r = h(e), o = typeof t == "function" ? t({ present: r.isPresent }) : s.Children.only(t), c = g(r.ref, w(o)); return typeof t == "function" || r.isPresent ? s.cloneElement(o, { ref: c }) : null; }; R.displayName = "Presence"; function h(n) { const [e, t] = s.useState(), r = s.useRef(null), o = s.useRef(n), c = s.useRef("none"), p = n ? "mounted" : "unmounted", [l, a] = P(p, { mounted: { UNMOUNT: "unmounted", ANIMATION_OUT: "unmountSuspended" }, unmountSuspended: { MOUNT: "mounted", ANIMATION_END: "unmounted" }, unmounted: { MOUNT: "mounted" } }); return s.useEffect(() => { const i = N(r.current); c.current = l === "mounted" ? i : "none"; }, [l]), A(() => { const i = r.current, m = o.current; if (m !== n) { const d = c.current, u = N(i); n ? a("MOUNT") : u === "none" || (i == null ? void 0 : i.display) === "none" ? a("UNMOUNT") : a(m && d !== u ? "ANIMATION_OUT" : "UNMOUNT"), o.current = n; } }, [n, a]), A(() => { if (e) { let i; const m = e.ownerDocument.defaultView ?? window, f = (u) => { const O = N(r.current).includes(u.animationName); if (u.target === e && O && (a("ANIMATION_END"), !o.current)) { const T = e.style.animationFillMode; e.style.animationFillMode = "forwards", i = m.setTimeout(() => { e.style.animationFillMode === "forwards" && (e.style.animationFillMode = T); }); } }, d = (u) => { u.target === e && (c.current = N(r.current)); }; return e.addEventListener("animationstart", d), e.addEventListener("animationcancel", f), e.addEventListener("animationend", f), () => { m.clearTimeout(i), e.removeEventListener("animationstart", d), e.removeEventListener("animationcancel", f), e.removeEventListener("animationend", f); }; } else a("ANIMATION_END"); }, [e, a]), { isPresent: ["mounted", "unmountSuspended"].includes(l), ref: s.useCallback((i) => { r.current = i ? getComputedStyle(i) : null, t(i); }, []) }; } function N(n) { return (n == null ? void 0 : n.animationName) || "none"; } function w(n) { var r, o; let e = (r = Object.getOwnPropertyDescriptor(n.props, "ref")) == null ? void 0 : r.get, t = e && "isReactWarning" in e && e.isReactWarning; return t ? n.ref : (e = (o = Object.getOwnPropertyDescriptor(n, "ref")) == null ? void 0 : o.get, t = e && "isReactWarning" in e && e.isReactWarning, t ? n.props.ref : n.props.ref || n.ref); } export { R as P, y as c };