UNPKG

@undp/design-system-react

Version:

React based design system for UNDP

98 lines (97 loc) 3.54 kB
import { t as e } from "./dist-BKfyhBSH.js"; import * as t from "react"; //#region node_modules/@radix-ui/react-presence/dist/index.mjs var n = Object.defineProperty, r = (e, t) => n(e, "name", { value: t, configurable: !0 }); function i(e, n) { return t.useReducer((e, t) => n[e][t] ?? e, e); } r(i, "useStateMachine"); var a = /* @__PURE__ */ r((e) => { let { present: n, children: r } = e, i = o(n), a = typeof r == "function" ? r({ present: i.isPresent }) : t.Children.only(r), s = c(i.ref, u(a)); return typeof r == "function" || i.isPresent ? t.cloneElement(a, { ref: s }) : null; }, "Presence"); function o(n) { let [a, o] = t.useState(), s = t.useRef(null), c = t.useRef(n), u = t.useRef("none"), d = t.useRef(void 0), [f, p] = i(n ? "mounted" : "unmounted", { mounted: { UNMOUNT: "unmounted", ANIMATION_OUT: "unmountSuspended" }, unmountSuspended: { MOUNT: "mounted", ANIMATION_END: "unmounted" }, unmounted: { MOUNT: "mounted" } }); return t.useEffect(() => { f === "mounted" ? (u.current = d.current ?? l(s.current), d.current = void 0) : u.current = "none"; }, [f]), e(() => { let e = s.current, t = c.current; if (t !== n) { let r = u.current, i = l(e); n ? (d.current = i, p("MOUNT")) : i === "none" || e?.display === "none" ? p("UNMOUNT") : p(t && r !== i ? "ANIMATION_OUT" : "UNMOUNT"), c.current = n; } }, [n, p]), e(() => { if (a) { let e, t = a.ownerDocument.defaultView ?? window, n = /* @__PURE__ */ r((n) => { let r = l(s.current).includes(CSS.escape(n.animationName)); if (n.target === a && r && (p("ANIMATION_END"), !c.current)) { let n = a.style.animationFillMode; a.style.animationFillMode = "forwards", e = t.setTimeout(() => { a.style.animationFillMode === "forwards" && (a.style.animationFillMode = n); }); } }, "handleAnimationEnd"), i = /* @__PURE__ */ r((e) => { e.target === a && (u.current = l(s.current)); }, "handleAnimationStart"); return a.addEventListener("animationstart", i), a.addEventListener("animationcancel", n), a.addEventListener("animationend", n), () => { t.clearTimeout(e), a.removeEventListener("animationstart", i), a.removeEventListener("animationcancel", n), a.removeEventListener("animationend", n); }; } else p("ANIMATION_END"); }, [a, p]), { isPresent: ["mounted", "unmountSuspended"].includes(f), ref: t.useCallback((e) => { if (e) { let t = getComputedStyle(e); s.current = t, d.current = l(t); } else s.current = null; o(e); }, []) }; } r(o, "usePresence"); function s(e, t) { if (typeof e == "function") return e(t); e != null && (e.current = t); } r(s, "setRef"); function c(...e) { let n = t.useRef(e); return n.current = e, t.useCallback((e) => { let t = n.current, r = !1, i = t.map((t) => { let n = s(t, e); return !r && typeof n == "function" && (r = !0), n; }); if (r) return () => { for (let e = 0; e < i.length; e++) { let n = i[e]; typeof n == "function" ? n() : s(t[e], null); } }; }, []); } r(c, "useStableComposedRefs"); function l(e) { return e?.animationName || "none"; } r(l, "getAnimationName"); function u(e) { let t = Object.getOwnPropertyDescriptor(e.props, "ref")?.get, n = t && "isReactWarning" in t && t.isReactWarning; return n ? e.ref : (t = Object.getOwnPropertyDescriptor(e, "ref")?.get, n = t && "isReactWarning" in t && t.isReactWarning, n ? e.props.ref : e.props.ref || e.ref); } r(u, "getElementRef"); //#endregion export { a as t }; //# sourceMappingURL=dist-CnnnGPaT.js.map