UNPKG

@ndriadev/react-tools

Version:

A React library of hooks, components, utils and types ready to use

1,404 lines 113 kB
var ie = (e) => { throw TypeError(e); }; var oe = (e, r, t) => r.has(e) || ie("Cannot " + t); var z = (e, r, t) => (oe(e, r, "read from private field"), t ? t.call(e) : r.get(e)), ae = (e, r, t) => r.has(e) ? ie("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(e) : r.set(e, t), le = (e, r, t, n) => (oe(e, r, "write to private field"), n ? n.call(e, t) : r.set(e, t), t); import { useRef as d, useEffect as x, useLayoutEffect as j, useReducer as B, useCallback as m, useState as C, useMemo as L, createElement as ze } from "react"; import { createPortal as Ve } from "react-dom"; import { a as U, h as We, c as de, b as He, i as je, d as fe } from "./detectBrowser-Pkdp-XRY.js"; import { j as qe } from "./jsx-runtime-Dy-MutAm.js"; var O; class De { constructor() { ae(this, O); le(this, O, /* @__PURE__ */ new Map()); } subscribe(r, t) { z(this, O).has(r) || z(this, O).set(r, []); const n = z(this, O).get(r); n.push(t), z(this, O).set(r, n); } unsubscribe(r, t) { if (!z(this, O).has(r)) return !1; const n = z(this, O).get(r).filter((c) => c !== t); return z(this, O).set(r, n), !0; } publish(r, t) { (z(this, O).get(r) ?? []).forEach((c) => c(t)); } async publishAsync(r, t) { const n = z(this, O).get(r) ?? [], c = []; n.forEach((s) => c.push(s(t))), await Promise.allSettled(c); } } O = new WeakMap(); class Ue extends EventTarget { constructor() { super(); } dispatch(r) { this.dispatchEvent(r); } listen(r, t, n) { return this.addEventListener(r, t, n), () => { this.removeEventListener(r, t, n); }; } } const ee = new De(), Er = (e) => { const r = d(async (c) => await ee.publish(e, c)), t = d(/* @__PURE__ */ new Set()), n = d((c) => { ee.subscribe(e, c); const s = () => ee.unsubscribe(e, c); return t.current.add(s), () => { t.current.delete(s), ee.unsubscribe(e, c); }; }); return x(() => () => { t.current.forEach((c) => c()); }, [e]), [ n.current, r.current ]; }, br = (e, r) => { x(() => { const t = new AbortController(), n = e(t.signal); return () => { t.abort(), n instanceof Promise ? n.then((c) => { typeof c == "function" && c(); }) : typeof n == "function" && n(); }; }, r); }, Rr = (e, r, t) => { const n = d(); (!n.current || !t || t(n.current, r)) && (n.current = r), x(e, n.current); }, Pr = (e, r) => { const t = d(); (!t.current || !U(t.current, r)) && (t.current = r), x(e, t.current); }, M = (e) => { const r = d(!1), t = d(), n = d(!1); x(() => (r.current || (t.current = e(), r.current = !0, setTimeout(() => n.current = !0, 1)), () => { n.current && (t.current && t.current(), r.current = !1); }), []); }, Lr = (e, r) => { j(() => { const t = new AbortController(), n = e(t.signal); return () => { t.abort(), n instanceof Promise ? n.then((c) => { typeof c == "function" && c(); }) : typeof n == "function" && n(); }; }, r); }, Tr = (e, r, t) => { const n = d(); (!n.current || !t || t(n.current, r)) && (n.current = r), j(e, n.current); }, kr = (e, r) => { const t = d(); (!t.current || !U(t.current, r)) && (t.current = r), j(e, t.current); }; function Ie(e) { const r = B((t) => t + 1e-11, 0); return e ? r : r[1]; } const Dr = (e) => { const r = Ie(), t = d(e), n = d(), c = d(!1), s = d(!1); c.current && (s.current = !0), j(() => (c.current || (n.current = t.current(), c.current = !0, r()), () => { s.current && (n.current && n.current(), c.current = !1); }), []); }, Ir = () => { const e = d(!1); return M(() => (e.current = !0, () => { e.current = !1; })), m(() => e.current, []); }; let ce; (async () => { try { const e = await import("react"); ce = e == null ? void 0 : e.useDeferredValue; } catch { ce = void 0; } })(); function Ge(e) { const [r, t] = C(e), n = d(); return e !== r && (n.current !== null && clearTimeout(n.current), n.current = setTimeout(() => t(e))), r; } const $e = ce ?? Ge, xr = (e, r) => { const t = d(); x(() => { if (!t.current) t.current = r; else { const n = Reflect.ownKeys(r); for (const c of n) Reflect.get(r, c) !== Reflect.get(t.current, c) && console.log(e + " component updated", t, r); } }, [e, r]), x(() => (console.log(e + " component mounted"), () => { console.log(e + " component unmounted"); }), []); }, Cr = (e) => { const r = d(), t = d(!0), n = d(e), c = m((s) => t.current = s, []); return x(() => { t.current ? r.current = e : n.current = e; }, [e]), t.current && n.current && (r.current = n.current, n.current = null), [r.current, c]; }, Ar = (e, r, t) => { const n = d(); return (!n.current || !t || t(n.current, r)) && (n.current = r), m(e, n.current); }, Mr = (e, r) => { const t = d(); return (!t.current || !U(t.current, r)) && (t.current = r), m(e, t.current); }, F = (e) => { const r = d(e), t = m((...n) => r.current(...n), []); return j(() => { r.current = e; }), t; }, Or = (e, r, t) => { const n = d(); return (!n.current || !t || t(n.current, r)) && (n.current = r), L(e, n.current); }, Nr = (e, r) => { const t = d(); return (!t.current || !U(t.current, r)) && (t.current = r), L(e, t.current); }, Be = (...e) => { const r = d(null); return L(() => Object.defineProperty({}, "current", { get() { return r.current; }, set(t) { r.current = t, e.forEach((n) => typeof n == "function" ? n(r.current) : n.current = r.current); }, enumerable: !1, configurable: !1 }), [e]); }, ve = Symbol("useLazyRef.noValue"), xe = (e) => { const r = d(ve); return r.current === ve && (r.current = e()), r; }; let ue; (async () => { try { const e = await import("react"); ue = e == null ? void 0 : e.useId; } catch { ue = void 0; } })(); let Je = 0; const Ye = () => `:${(Je++).toString(32)}:`; function Xe() { return xe(Ye).current; } const _e = ue ?? Xe; function Fr(e) { const [r, t] = C(e), n = F(() => r), c = F(() => t(e)); return [ r, t, n, c ]; } const Ke = (e, r = "no-limit") => { const [t, n] = C(e), [, c] = C(0), s = d([t]), u = d(r === "no-limit" ? 1 / 0 : r), i = d(0), o = d(!0), a = m((h) => o.current = h, []), f = m((h) => { const E = h instanceof Function ? h(s.current[i.current]) : h; s.current = s.current.slice(0, i.current + 1), !o.current && s.current.pop(), s.current.push(E), s.current.length > u.current ? s.current.shift() : o.current && i.current++, n(E), c((S) => S + 1); }, [u]), v = m(() => { i.current !== 0 && (i.current--, n(s.current[i.current]), c((h) => h + 1)); }, []), g = m(() => { i.current !== s.current.length - 1 && (i.current++, n(s.current[i.current]), c((h) => h + 1)); }, []), p = m((h) => { h < 0 || h > s.current.length - 1 || (i.current = h, n(s.current[i.current]), c((E) => E + 1)); }, []), y = m((h) => { const E = h || s.current[i.current]; s.current = [E], i.current = 0, n(s.current[i.current]), c((S) => S + 1); }, []), l = i.current > 0, w = i.current < s.current.length - 1; return [ t, f, { history: Object.seal([...s.current]), presentPointer: i.current, trackUpdate: a, canUndo: l, canRedo: w, undo: v, redo: g, go: p, clear: y } ]; }, zr = (e, r = "no-limit") => { const [t, n, c] = Ke(e, r), s = F(() => t); return [ t, n, s, c ]; }, Vr = (e, r, t) => { const [n, c] = B(e, r, t), s = F(() => n), u = d(void 0), i = F(() => c(u.current)); return u.current === void 0 && (u.current = n), [ n, c, s, i ]; }, Qe = (e, r, t, n = "no-limit") => { const [c, s] = C(() => t ? t(r) : r), [, u] = C(0), i = d([c]), o = d(n === "no-limit" ? 1 / 0 : n), a = d(0), f = d(!0), v = m((S) => f.current = S, []), g = m((S) => { const R = e(i.current[a.current], S); i.current = i.current.slice(0, a.current + 1), !f.current && i.current.pop(), i.current.push(R), i.current.length > o.current ? i.current.shift() : f.current && a.current++, s(S), u((k) => k + 1); }, [o, e]), p = m(() => { a.current !== 0 && (a.current--, s(i.current[a.current]), u((S) => S + 1)); }, []), y = m(() => { a.current !== i.current.length - 1 && (a.current++, s(i.current[a.current]), u((S) => S + 1)); }, []), l = m((S) => { S < 0 || S > i.current.length - 1 || (a.current = S, s(i.current[a.current]), u((R) => R + 1)); }, []), w = m((S) => { const R = S ? e(i.current[a.current], S) : i.current[a.current]; i.current = [R], a.current = 0, s(i.current[a.current]), u((k) => k + 1); }, [e]), h = a.current > 0, E = a.current < i.current.length - 1; return [ c, g, { history: Object.seal([...i.current]), presentPointer: a.current, trackUpdate: v, canUndo: h, canRedo: E, undo: p, redo: y, go: l, clear: w } ]; }, Wr = (e, r, t, n = "no-limit") => { const [c, s, u] = Qe(e, r, t, n), i = F(() => c); return [ c, s, i, u ]; }, me = new Ue(), Ce = () => { const e = d([]), r = d((n, c, s) => { const u = me.listen(n, c, s); return e.current.push(u), u; }), t = d((n) => { me.dispatch(n); }); return x(() => () => { e.current.forEach((n) => n()); }, []), [r.current, t.current]; }; function A({ type: e, listener: r, element: t = window, listenerOpts: n, effectType: c = "normal" }) { const s = d(n), u = d(), i = c === "layout" ? j : x, o = d(Array.isArray(e) ? e : [e]); return i(() => { const f = s.current; return u.current = Reflect.has(t, "current") ? (t == null ? void 0 : t.current) !== null ? t.current : null : t, u.current && o.current.forEach((v) => u.current.addEventListener(v, r, f)), () => { u.current && o.current.forEach((v) => u.current.removeEventListener(v, r, f)); }; }, [t, r]), F(() => { u.current && o.current.forEach((f) => u.current.removeEventListener(f, r, s.current)); }); } const Hr = (e = window) => F((t) => { (Reflect.has(e, "current") ? e.current : e).dispatchEvent(t); }), jr = (e) => { const [r, t] = B((i) => i + 1e-4, 0), n = $e(r), c = d(e), s = d(); return x(() => { n !== 0 && (s.current ? c.current(...s.current) : c.current()); }, [n]), m((...i) => { s.current = i, t(); }, []); }, qr = () => T( m((e) => (document.addEventListener("visibilitychange", e, { passive: !0 }), () => { document.removeEventListener("visibilitychange", e); }), []), m(() => document.visibilityState, []) ); function Ur(e, r) { const t = d({ current: !1, previous: !1 }), n = L(() => r == null ? void 0 : r.onEnter, [r == null ? void 0 : r.onEnter]), c = L(() => r == null ? void 0 : r.onLeave, [r == null ? void 0 : r.onLeave]), s = L(() => r == null ? void 0 : r.onChange, [r == null ? void 0 : r.onChange]), u = T( m((i) => { const o = e != null && e.current ? e.current : e, a = (v) => { t.current.current = !0, n && n(v), s && s(!0), i(); }, f = (v) => { t.current.current = !1, c && c(v), s && s(!1), i(); }; return o == null || o.addEventListener("pointerenter", a, { passive: !0 }), o == null || o.addEventListener("pointerleave", f, { passive: !0 }), () => { o == null || o.removeEventListener("pointerenter", a), o == null || o.removeEventListener("pointerleave", f); }; }, [s, n, c, e]), m(() => (t.current.current !== t.current.previous && (t.current.previous = t.current.current), t.current.previous), []) ); if (!r || r.returnValue === !0) return u; } const _ = /* @__PURE__ */ new Set(), he = () => _.forEach((e) => e()), Ae = { xs: { value: 576, condition: "<" }, sm: { value: 576, condition: ">=" }, md: { value: 768, condition: ">=" }, lg: { value: 992, condition: ">=" }, xl: { value: 1200, condition: ">=" } }; function ge(e) { const r = window.innerWidth, t = {}, n = e ?? Ae, c = Object.keys(n); for (const s of c) if (Reflect.get(n, s)) { const u = Reflect.get(n, s), { value: i, condition: o } = typeof u == "number" ? { value: u, condition: ">" } : u; Reflect.set(t, s, Function(`return ${r}${o}${i}`)()); } return t; } function Gr(e) { const r = d(() => ge(e === void 0 ? Ae : e)); return T( m((t) => (_.size === 0 && window.addEventListener("resize", he, { passive: !0 }), _.add(t), () => { _.delete(t), _.size === 0 && window.removeEventListener("resize", he); }), []), L(() => { let t = r.current(); return () => { const n = r.current(), c = Object.keys(n); for (const s of c) if (Reflect.get(t, s) !== Reflect.get(n, s)) { t = n; break; } return t; }; }, []) ); } const Me = (e, r) => { if (!e || !r) return !1; if (e.contains(r)) return !0; if (e.children.length > 0) { for (let t = 0, n = e.children.length; t < n; t++) if (Me(e.children[t], r)) return !0; } return !1; }, $r = (e, r) => { const t = m((n) => { const c = e != null && e.current ? e.current : e; Me(c, n.target) || r(n); }, [e, r]); A({ type: "pointerdown", listener: t }); }, K = /* @__PURE__ */ new Set(), q = () => K.forEach((e) => e()), pe = () => { const e = Reflect.get(navigator, "connection"), r = { isSupported: !!e, isOnline: navigator.onLine }; return e && (r.isSupported = !0, r.downlink = e.downlink, r.downlinkMax = e.downlinkMax, r.effectiveType = e.effectiveType, r.rtt = e.rtt, r.saveData = e.saveData, r.type = e.type), r; }; function Ze(e) { const r = d(e ?? ["isSupported", "isOnline", "since", "downlink", "downlinkMax", "effectiveType", "rtt", "saveData", "type"]); return T( m((t) => { const n = Reflect.get(navigator, "connection"); return K.size === 0 && (window.addEventListener("online", q, { passive: !0 }), window.addEventListener("offline", q, { passive: !0 }), n && n.addEventListener("change", q)), K.add(t), () => { K.delete(q), K.size === 0 && (window.removeEventListener("online", q), window.removeEventListener("offline", q), n && n.removeEventListener("change", q)); }; }, []), L(() => { let t = pe(); return () => { const n = pe(); for (const c of r.current) if (n[c] !== t[c]) { t = { ...n, ...t.isOnline !== n.isOnline && { since: (/* @__PURE__ */ new Date()).getTime() } }; break; } return t; }; }, []) ); } const Br = () => Ze(["isOnline"]).isOnline, er = (e, r) => { const t = d(), n = d(!0), c = d(), s = d(e); return M(() => () => { var u; c.current = void 0, (u = t.current) == null || u.disconnect(), t.current = void 0; }), [ m((u) => { var i; !n.current || !u || (u && (!c.current || c.current !== u) && (c.current = u, t.current = new ResizeObserver(e), t.current.observe(u, r)), s.current !== e && t.current && u && (s.current = e, (i = t.current) == null || i.disconnect(), t.current = void 0, t.current = new ResizeObserver(e), t.current.observe(u, r))); }, [e, r]), m(() => { n.current && (n.current = !1, t.current && c.current && t.current.unobserve(c.current)); }, []), m(() => { var u; n.current || (n.current = !0, t.current && c.current && ((u = t.current) == null || u.observe(c.current, r))); }, [r]) ]; }, Jr = (e, r) => { const t = d(), n = d(!0), c = d(), s = d(e); return M(() => () => { var u; c.current = void 0, (u = t.current) == null || u.disconnect(), t.current = void 0; }), [ m((u) => { var i; !n.current || !u || (u && (!c.current || c.current !== u) && (c.current = u, t.current = new IntersectionObserver(e, r), t.current.observe(u)), s.current !== e && t.current && u && (s.current = e, (i = t.current) == null || i.disconnect(), t.current = void 0, t.current = new IntersectionObserver(e, r), t.current.observe(u))); }, [e, r]), m(() => { n.current && (n.current = !1, t.current && c.current && t.current.unobserve(c.current)); }, []), m(() => { var u; n.current || (n.current = !0, t.current && c.current && ((u = t.current) == null || u.observe(c.current))); }, []) ]; }, Yr = (e, r) => { const t = d(), n = d(!0), c = d(); return M(() => () => { var s; c.current = void 0, (s = t.current) == null || s.disconnect(), t.current = void 0; }), [ m((s) => { !n.current || !s || s && (!c.current || c.current !== s) && (c.current = s, t.current = new MutationObserver(e), t.current.observe(s, r)); }, [e, r]), m(() => { n.current && (n.current = !1, t.current && c.current && t.current.disconnect()); }, []), m(() => { n.current || (n.current = !0, t.current && c.current && t.current.observe(c.current, r)); }, [r]), m(() => { var s; return (s = t.current) == null ? void 0 : s.takeRecords(); }, []) ]; }, Xr = () => { const [e, r] = C(() => new DOMRect()), [t] = er(m((n) => { r((c) => { const s = n[0].target.getBoundingClientRect(); return s.top !== c.top || s.left !== c.left || s.right !== (c == null ? void 0 : c.right) || s.bottom !== c.bottom ? s : c; }); }, [])); return [ t, e ]; }; function _r(e) { const r = d(), t = d(), n = d(), c = d({ isVisible: !1, ratio: 0 }), s = d({ isVisible: !1, ratio: 0 }); M(() => () => { var o; r.current = void 0, (o = t.current) == null || o.disconnect(), t.current = void 0; }); const u = m((o) => { o && o && (!r.current || r.current !== o) && (r.current = o, t.current = new IntersectionObserver((a) => { const { isIntersecting: f, intersectionRatio: v } = a[0]; s.current = { isVisible: f, ratio: v }, (f !== c.current.isVisible || v !== c.current.ratio) && n.current && n.current(); }, { root: e == null ? void 0 : e.root, rootMargin: e == null ? void 0 : e.rootMargin, threshold: e == null ? void 0 : e.threshold }), t.current.observe(o)); }, [e == null ? void 0 : e.root, e == null ? void 0 : e.rootMargin, e == null ? void 0 : e.threshold]), i = T( m((o) => (n.current = o, () => { n.current = void 0; }), []), m(() => ((s.current.isVisible !== c.current.isVisible || s.current.ratio !== c.current.ratio) && (c.current = s.current), e != null && e.withRatio ? c.current : c.current.isVisible), [e == null ? void 0 : e.withRatio]) ); return e != null && e.withRatio ? [ u, i.isVisible, i.ratio ] : [ u, i ]; } const rr = (e, r) => { const t = d(L(() => { const { media: n, matches: c } = window.matchMedia(e); return { matches: c, media: n }; }, [])); return T( m((n) => { const c = window.matchMedia(e), s = (u) => { r && r(u), n(); }; return c.addEventListener("change", s, { passive: !0 }), () => { c.removeEventListener("change", s); }; }, [e, r]), m(() => { const { media: n, matches: c } = window.matchMedia(e); return c !== t.current.matches && (t.current = { matches: c, media: n }), t.current; }, [e]) ); }, tr = () => rr("(prefers-reduced-motion: reduce)").matches; function nr(e) { return -(Math.cos(Math.PI * e) - 1) / 2; } function cr(e, r) { const t = r === "x" ? "scrollLeft" : "scrollTop"; return (e ? e[t] : document.body[t] + document.documentElement[t]) ?? 0; } function ur(e, r, t, n, c) { if (!r) return 0; const u = (t || document.body).getBoundingClientRect(), i = r.getBoundingClientRect(), o = (a) => i[a] - u[a]; if (e === "y") { const a = o("top"); if (a === 0) return 0; if (n === "start") return a - c; const f = t ? u.height : window.innerHeight; return n === "end" ? a + c - f + i.height : n === "center" ? a - f / 2 + i.height / 2 : 0; } else { const a = o("left"); if (a === 0) return 0; if (n === "start") return a - c; const f = t ? u.width : window.innerWidth; return n === "end" ? a + c - f + i.width : n === "center" ? a - f / 2 + i.width / 2 : 0; } } const Kr = ({ duration: e = 1e3, axis: r = "y", animation: t = nr, offset: n = 0, cancelable: c = !1, onFinish: s, scrollableElement: u }) => { const i = d(), o = d(0), a = d(!1), f = d(null), v = tr(), g = m(() => i.current && cancelAnimationFrame(i.current), []), p = m(() => c && (a.current = !0), [c]); A({ type: "wheel", listener: p, listenerOpts: { passive: !0 } }), A({ type: "touchmove", listener: p, listenerOpts: { passive: !0 } }); const y = m((l = "start") => { a.current = !1, g(); const w = typeof u == "function" ? u() : u != null && u.current ? u.current : u, h = cr(w, r), E = ur(r, f.current, w, l, n); function S() { o.current === 0 && (o.current = performance.now()); const k = performance.now() - o.current, D = v || e === 0 ? 1 : k / e, b = h + E * t(D), P = r === "x" ? "scrollLeft" : "scrollTop"; w ? w[P] = b : (document.body[P] = b, document.documentElement[P] = b), !a.current && D < 1 ? i.current = requestAnimationFrame(S) : (s && s(), o.current = 0, i.current = void 0, g()); } S(); }, [t, r, g, e, n, s, v, u]); return { targetRef: f, scroll: y, cancel: g }; }, J = /* @__PURE__ */ new Set(); function Qr(e = { type: "client" }) { const r = d({ x: null, y: null }), t = d({ x: null, y: null }); return T( m((n) => { const c = (s) => { var l; const { screenX: u, screenY: i, clientX: o, clientY: a, pageX: f, pageY: v } = s; let g = null, p = null, y; e.type === "client" ? (g = o, p = a) : e.type === "page" ? (g = f, p = v) : (g = u, p = i), (e.relativeElement && "current" in e.relativeElement ? e.relativeElement.current : e.relativeElement) && (y = ((l = e.relativeElement) != null && l.current ? e.relativeElement.current : e.relativeElement).getBoundingClientRect(), g = f - (y.left + window.scrollX), p = v - (y.top + window.scrollY)), t.current = { x: g, y: p, relativeElementDim: y }, J.forEach((w) => w()); }; return J.size === 0 && (window.addEventListener("pointerdown", c), window.addEventListener("pointermove", c), window.addEventListener("pointerup", c)), J.add(n), () => { J.delete(n), J.size === 0 && (window.removeEventListener("pointerdown", c), window.removeEventListener("pointermove", c), window.removeEventListener("pointerup", c)); }; }, [e.relativeElement, e.type]), m(() => ((r.current.x !== t.current.x || r.current.y !== t.current.y) && (r.current = t.current), r.current), []) ); } const Zr = (e, { duration: r = 1e3, normalPress: t, onStart: n, onFinish: c }) => { const s = d(), u = d(), i = d(!1), o = d(), a = m(() => { clearTimeout(u.current), c && c(s.current), !i.current && t && t(s.current); }, [t, c]), f = m((v) => { i.current = !1, s.current = v, n && n(v), u.current = setTimeout(async () => { i.current = !0, await e(v); }, r); }, [e, r, n]); return m((v) => { var g, p; v ? (v.addEventListener("pointerdown", f), v.addEventListener("pointerup", a), o.current = v) : ((g = o.current) == null || g.removeEventListener("pointerdown", f), (p = o.current) == null || p.removeEventListener("pointerup", a), o.current = void 0); }, [f, a]); }, et = (e) => { const r = d(0), t = d("tolerance" in e ? e.tolerance : 300), n = d(); return m((c) => { "persist" in c && c.persist(), n.current && clearTimeout(n.current), r.current++, r.current === 1 && "singleClick" in e && e.singleClick && (n.current = setTimeout(() => { e.singleClick(c), r.current = 0; }, t.current)), r.current === 2 && ("doubleClick" in e ? e.doubleClick(c) : e(c), r.current = 0); }, [e]); }, rt = ({ element: e, listener: r, opts: t }) => A({ type: "beforeunload", element: e, listener: r, listenerOpts: t }), Y = /* @__PURE__ */ new Set(), tt = (e) => { const r = d(), t = d(!1), n = T( m((u) => { const i = () => { console.log("orientation"), t.current = !0, Y.forEach((a) => a()); }; Y.add(u); let o = !1; return Y.size === 1 && (screen.orientation.onchange = i, window && "getScreenDetails" in window && (o = !0, window.getScreenDetails().then((a) => { o && (a.addEventListener("currentscreenchange", i), e && a.addEventListener("screenschange", i), r.current = a, u()); }).catch(() => { }))), () => { Y.delete(u), Y.size === 0 && (r.current && (r.current.removeEventListener("currentscreenchange", i), e && r.current.removeEventListener("screenschange", i)), o = !1, screen.orientation.onchange = null); }; }, [e]), L(() => { let u = { currentScreen: { availHeight: screen.availWidth, availWidth: screen.availWidth, height: screen.height, width: screen.width, colorDepth: screen.colorDepth, pixelDepth: screen.pixelDepth, orientation: { angle: screen.orientation.angle, type: screen.orientation.type }, availLeft: void 0, availTop: void 0, left: void 0, top: void 0, devicePixelRatio: void 0, isInternal: void 0, isPrimary: void 0, label: void 0 }, screens: void 0 }; return () => { var a, f; const i = Reflect.ownKeys(u.currentScreen); u.currentScreen.isPrimary === void 0 && r.current && (u = { currentScreen: { ...u.currentScreen, availLeft: r.current.currentScreen.availLeft, availTop: r.current.currentScreen.availTop, left: r.current.currentScreen.left, top: r.current.currentScreen.top, devicePixelRatio: r.current.currentScreen.devicePixelRatio, isInternal: r.current.currentScreen.isInternal, isPrimary: r.current.currentScreen.isPrimary, label: r.current.currentScreen.label }, screens: e && ((a = r.current) != null && a.screens) ? r.current.screens : void 0 }); let o = !1; if (t.current) { t.current = !1; for (let v = 0, g = i.length; v < g; v++) if (i[v] === "orientation" ? (u.currentScreen.orientation.angle !== screen.orientation.angle || u.currentScreen.orientation.type !== screen.orientation.type) && (o = !0) : i[v] in screen && u.currentScreen[i[v]] !== screen[i[v]] && (o = !0), o) { u = { currentScreen: { availHeight: screen.availWidth, availWidth: screen.availWidth, height: screen.height, width: screen.width, colorDepth: screen.colorDepth, pixelDepth: screen.pixelDepth, orientation: { angle: screen.orientation.angle, type: screen.orientation.type }, availLeft: r.current ? r.current.currentScreen.availLeft : void 0, availTop: r.current ? r.current.currentScreen.availTop : void 0, left: r.current ? r.current.currentScreen.left : void 0, top: r.current ? r.current.currentScreen.top : void 0, devicePixelRatio: r.current ? r.current.currentScreen.devicePixelRatio : void 0, isInternal: r.current ? r.current.currentScreen.isInternal : void 0, isPrimary: r.current ? r.current.currentScreen.isPrimary : void 0, label: r.current ? r.current.currentScreen.label : void 0 }, screens: e && ((f = r.current) != null && f.screens) ? r.current.screens : void 0 }; break; } } return u; }; }, [e]) ), c = d((u) => screen.orientation.lock(u)), s = d(() => screen.orientation.unlock()); return [ n, c.current, s.current ]; }, nt = ({ hotKey: e, type: r = "keydown", target: t = window, listener: n, listenerOpts: c }) => { const s = L(() => We(e, n), [e, n]); return A({ type: r, listener: s, listenerOpts: c, element: t, effectType: "normal" }); }, ct = ({ target: e = window, listener: r }) => { const t = d([]), n = d(-1), c = d([]), s = d((o) => { t.current.push(o); }), u = d((o) => { const a = t.current.findIndex( (f) => f.pointerId === o.pointerId ); t.current.splice(a, 1), t.current.length < 2 && (n.current = -1); }), i = m((o) => { const a = t.current.findIndex( (f) => f.pointerId === o.pointerId ); if (t.current[a] = o, t.current.length === 2) { const f = Math.abs(t.current[0].clientX - t.current[1].clientX); n.current > 0 && (f > n.current && r(o, "zoomIn"), f < n.current && r(o, "zoomOut")), n.current = f; } }, [r]); return c.current[0] = A({ type: "pointerdown", listener: s.current, effectType: "normal", element: e }), c.current[1] = A({ type: "pointermove", listener: i, effectType: "normal", element: e }), c.current[2] = A({ type: "pointerup", listener: u.current, effectType: "normal", element: e }), c.current[3] = A({ type: "pointercancel", listener: u.current, effectType: "normal", element: e }), c.current[4] = A({ type: "pointerout", listener: u.current, effectType: "normal", element: e }), c.current[5] = A({ type: "pointerleave", listener: u.current, effectType: "normal", element: e }), m(() => { c.current.forEach((o) => o()); }, []); }, ut = ({ target: e, unadjustedMovement: r, onLock: t, onUnlock: n, onError: c }) => { const s = d(!1), u = m(() => { document.pointerLockElement ? t && t(document.pointerLockElement) : (s.current = !1, document.removeEventListener("pointerlockerror", c, !1), document.removeEventListener("pointerlockchange", u), n && n(e != null && e.current ? e.current : e)); }, [c, t, n, e]), i = m(async () => { s.current = !1, await document.exitPointerLock(), n && n(e != null && e.current ? e.current : e); }, [e, n]); return { lock: m(() => { const a = e != null && e.current ? e.current : e; return new Promise((f) => !a || s.current ? f() : (document.addEventListener("pointerlockerror", c, !1), document.addEventListener("pointerlockchange", u), a.requestPointerLock({ unadjustedMovement: !!r }).then(() => { s.current = !0; }).catch((v) => { c(v); }).finally(() => { f(); }))); }, [e, c, r, u]), unlock: i }; }, st = ({ element: e, listener: r, effectType: t, listenerOpts: n }) => { A({ type: "contextmenu", listener: r, effectType: t, listenerOpts: n, element: e }); }, it = ({ target: e, onSwipeStart: r, onSwipe: t, onSwipeEnd: n, options: c }) => { const s = d((y, l) => Math.max(Math.abs(y), Math.abs(l)) >= ((c == null ? void 0 : c.threshold) ?? 0)), u = d(), i = d((y, l) => s.current(y, l) ? Math.abs(y) > Math.abs(l) ? y > 0 ? "right" : "left" : l > 0 ? "down" : "up" : "none"), o = d(!1), a = d({ target: { x: 0, y: 0 }, start: { x: 0, y: 0 }, end: { x: 0, y: 0 } }), f = A({ type: ["mousedown", "touchstart"], element: e, listener: m((y) => { var S; o.current = !0, u.current = y.target, y.target && y.target.style.setProperty("touch-action", "none"), y.target && y.target.style.setProperty("-webkit-user-select", "none"), y.target && y.target.style.setProperty("-ms-user-select", "none"), y.target && y.target.style.setProperty("user-select", "none"); const { x: l, y: w } = ((S = y.target) == null ? void 0 : S.getBoundingClientRect()) ?? { x: 0, y: 0 }, { clientX: h, clientY: E } = de(y) ? y.touches[0] : y; a.current = { target: { x: l, y: w }, start: { x: h, y: E }, end: { x: h, y: E } }, r && r(y); }, [r]), listenerOpts: { capture: !0, passive: (c == null ? void 0 : c.passive) !== void 0 ? c.passive : !0 } }), v = A({ type: ["mousemove", "touchmove"], element: window, listener: m((y) => { const { clientX: l, clientY: w } = de(y) ? y.touches[0] : y; a.current.end = { x: l, y: w }; const h = a.current.end.x - a.current.start.x, E = a.current.end.y - a.current.start.y; o.current && s.current(h, E) && t && t(y, i.current(h, E), { x: h, y: E }); }, [t]), listenerOpts: { capture: !0, passive: (c == null ? void 0 : c.passive) !== void 0 ? c.passive : !0 } }), g = A({ type: ["mouseup", "mouseleave", "touchend", "touchcancel"], element: window, listener: m((y) => { const l = a.current.end.x - a.current.start.x, w = a.current.end.y - a.current.start.y; o.current && n && n(y, i.current(l, w), { x: l, y: w }), o.current = !1, u.current && u.current.style.removeProperty("touch-action"), u.current && u.current.style.removeProperty("-webkit-user-select"), u.current && u.current.style.removeProperty("-ms-user-select"), u.current && u.current.style.removeProperty("user-select"), u.current = null; }, [n]), listenerOpts: { capture: !0, passive: (c == null ? void 0 : c.passive) !== void 0 ? c.passive : !0 } }); return m(() => { f(), v(), g(); }, [f, v, g]); }, ot = ({ request: e, ref: r, hasMoreData: t, threshold: n, onBefore: c, onError: s, onSuccess: u }) => { const i = d(), o = d({ data: void 0, loading: !0, fullData: !t() }), a = m(() => o.current.loading ? Promise.resolve() : (o.current.loading = !0, i.current && i.current(), c && c(), e(o.current.data).then((p) => { o.current.data = p, o.current.loading = !1, o.current.fullData = !t(p), i.current && i.current(), u && u(); }).catch((p) => { o.current.loading = !1, i.current && i.current(), s && s(p); })), [c, u, s, e, t]), f = m((p) => { if (o.current.loading || o.current.fullData) return; const y = p === document.documentElement ? Math.max( window.scrollY, document.documentElement.scrollTop, document.body.scrollTop ) : p.scrollTop, l = p.scrollHeight || Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), w = p.clientHeight || Math.max(document.documentElement.clientHeight, document.body.clientHeight); l - y <= w + (n ?? 0) && a(); }, [a, n]), v = m((p) => { o.current.data = p instanceof Function ? p(o.current.data) : p, i.current && i.current(); }, []), g = T( m((p) => { i.current = p; const y = r.current, l = () => f(y); return y && y.addEventListener("scroll", l, { passive: !0 }), () => { i.current = void 0, y && y.removeEventListener("scroll", l); }; }, [f, r]), L(() => { let p = { loading: !0, fullData: o.current.fullData }; return () => (p.data !== o.current.data && (p.data = o.current.data === void 0 ? void 0 : Array.isArray(o.current.data) ? [...o.current.data] : typeof o.current.data == "object" ? { ...o.current.data } : o.current.data, p = { ...o.current }), (p.loading !== o.current.loading || p.fullData !== o.current.fullData) && (p = { ...o.current }), p); }, []) ); return x(() => { c && c(), o.current.loading = !0, e().then((p) => { o.current.data = p, o.current.loading = !1, o.current.fullData = !t(p), i.current && i.current(), u && u(); }).catch((p) => { o.current.loading = !1, i.current && i.current(), s && s(p); }); }, [e, s, c, u, t]), { data: g.data, loading: g.loading, fullData: g.fullData, updateData: v, loadData: a }; }; let se; (async () => { try { const e = await import("react"); se = e == null ? void 0 : e.useSyncExternalStore; } catch { se = void 0; } })(); function sr(e, r) { const [t, n] = C(r()), c = m(() => { n(r()); }, [r]); return x(() => (c(), e(c)), [c, e]), t; } const T = se ?? sr; function at({ key: e, initialState: r, opts: t }) { const [n, c] = Ce(), s = d((t == null ? void 0 : t.serializer) || JSON.stringify), u = d((t == null ? void 0 : t.deserializer) || JSON.parse), i = d((t == null ? void 0 : t.mode) || "read/write"), o = d(L(() => { if (i.current === "write") return null; const l = localStorage.getItem(e); if (l != null) return u.current(l); if (r) { const w = r instanceof Function ? r() : r; return localStorage.setItem(e, s.current(w)), w; } else return null; }, [])), a = d((l) => { const w = (E) => { E.type === "storage" && E.storageArea !== localStorage || i.current === "write" || (E instanceof CustomEvent ? E.detail.key === e && l() : E.key === e && l()); }; window.addEventListener("storage", w, { passive: !0 }); const h = n("local-strg", w); return () => { window.removeEventListener("storage", w), h(); }; }), f = d(() => { const l = localStorage.getItem(e) ?? "null", w = s.current(o.current); return l !== w && (o.current = l !== null ? u.current(l) : null), o.current; }), v = T( a.current, f.current ), g = d((l) => { const w = s.current(l instanceof Function ? l(o.current) : l); localStorage.setItem(e, w), c(new CustomEvent( "local-strg", { detail: { key: e } } )); }), p = F(() => o.current), y = d(() => { localStorage.removeItem(e), c(new CustomEvent( "local-strg", { detail: { key: e } } )); }); return i.current === "read" ? [ v, p, y.current ] : i.current === "write" ? [ g.current, p, y.current ] : [ v, g.current, p, y.current ]; } function lt({ key: e, initialState: r, opts: t }) { const [n, c] = Ce(), s = d((t == null ? void 0 : t.serializer) || JSON.stringify), u = d((t == null ? void 0 : t.deserializer) || JSON.parse), i = d((t == null ? void 0 : t.mode) || "read/write"), o = d(L(() => { if (i.current === "write") return null; const l = sessionStorage.getItem(e); if (l != null) return u.current(l); if (r) { const w = r instanceof Function ? r() : r; return sessionStorage.setItem(e, s.current(w)), w; } else return null; }, [])), a = d((l) => { const w = (E) => { E.type === "storage" && E.storageArea !== sessionStorage || i.current === "write" || (E instanceof CustomEvent ? E.detail.key === e && l() : E.key === e && l()); }; window.addEventListener("storage", w, { passive: !0 }); const h = n("ssn-strg", w); return () => { window.removeEventListener("storage", w), h(); }; }), f = d(() => { const l = sessionStorage.getItem(e) ?? "null", w = s.current(o.current); return l !== w && (o.current = l !== null ? u.current(l) : null), o.current; }), v = T( a.current, f.current ), g = d((l) => { const w = s.current(l instanceof Function ? l(o.current) : l); sessionStorage.setItem(e, w), c(new CustomEvent( "ssn-strg", { detail: { key: e } } )); }), p = d(() => { sessionStorage.removeItem(e), c(new CustomEvent( "ssn-strg", { detail: { key: e } } )); }), y = F(() => o.current); return i.current === "read" ? [ v, y, p.current ] : i.current === "write" ? [ g.current, y, p.current ] : [ v, g.current, y, p.current ]; } const dt = (e) => { const [r, t] = C(() => new Map(e instanceof Function ? e() : e)); return r.set = (n, c) => { const s = new Map(r); return s.set(n, c), t(s), s; }, r.clear = () => { t((n) => { const c = new Map(n); return c.clear(), c; }); }, r.delete = (n) => { const c = r.has(n); return t((s) => { const u = new Map(s); return u.delete(n), u; }), c; }, r; }, ft = (e) => { const [r, t] = C(() => new Set(e instanceof Function ? e() : e)); return r.add = (n) => { const c = new Set(r); return c.add(n), t(c), c; }, r.clear = () => { t((n) => { const c = new Set(n); return c.clear(), c; }); }, r.delete = (n) => { const c = r.has(n); return t((s) => { const u = new Set(s); return u.delete(n), u; }), c; }, r; }, vt = (e) => { const [r, t] = C(() => e instanceof Function ? e() : e || new Array()); return r.copyWithin = (n, c, s) => { const u = [...r].copyWithin(n, c, s); return t(u), u; }, r.fill = (n, c, s) => { const u = [...r].fill(n, c, s); return t(u), u; }, r.pop = () => { const n = [...r], c = n.pop(); return t(n), c; }, r.push = (...n) => { const c = [...r], s = c.push(...n); return t(c), s; }, r.reverse = () => { const n = [...r].reverse(); return t(n), n; }, r.shift = () => { const n = [...r], c = n.shift(); return t(n), c; }, r.sort = (n) => { const c = [...r].sort(n); return t(c), c; }, r.splice = (n, c, ...s) => { const u = [...r].splice(n, c, ...s); return t(u), u; }, r.unshift = (...n) => { const c = [...r], s = c.unshift(...n); return t(c), s; }, r; }, mt = (e, r = !1) => { const t = d(e instanceof Function ? e() : e), [, n] = B((u) => u + 1, 0), c = d((u) => { let i = {}; if (!r) i = u; else { const o = Reflect.ownKeys(u); for (const a of o) i[a] = t.current[a] instanceof Date || t.current[a] instanceof RegExp || Array.isArray(t.current[a]) || typeof t.current[a] != "object" ? t.current[a] : c.current(t.current[a]); } return new Proxy(i, { set(o, a, f, v) { return Reflect.set(o, a, f, v), n(), !0; } }); }); return d(c.current(t.current)).current; }, ht = (e, r, t) => { const [, n] = B((i) => i + 1e-6, 0), c = d({ localState: typeof e == "function" ? e() : e, deps: r }); let s; He(c.current.deps, r) ? s = c.current.localState : (s = typeof e == "function" ? e() : e, c.current = { localState: s, deps: r }, n()); const u = m((i) => { const o = typeof i == "function" ? i(c.current.localState) : i; c.current.localState = o, n(); }, []); return x(() => { let i; return t && (i = t()), () => i && i(); }, [t]), [s, u]; }, gt = (e, r) => { const t = d(), [n, c] = C(() => { let u; e instanceof Function ? u = e() : u = e; let i = {}; return !Array.isArray(u) && !(u instanceof Date) && !(u instanceof RegExp) && typeof u == "object" ? Reflect.ownKeys(u).forEach((a) => { Reflect.set(i, a, { invalid: !1 }); }) : i = { invalid: !1 }, t.current = i, { state: u, validation: i }; }), s = F((u) => { const i = u instanceof Function ? u(n.state) : u, o = r(i, JSON.parse(JSON.stringify(t.current))); c({ state: i, validation: o }); }); return [n.state, s, n.validation]; }; let we = 0; function Oe(e) { return { get(r, t) { e.push(t); const n = Reflect.get(r, t); return n == null || n instanceof Blob || n instanceof Date || n instanceof RegExp || n instanceof Map || n instanceof Set || typeof n != "object" ? n : new Proxy(n, Oe(e)); } }; } function Ne(e, r, t, n) { if (e === r) { e[t] = n; return; } for (const c in e) if (e[c] === r) { Array.isArray(e[c]) ? e[c] = [...e[c]] : e[c] = { ...e[c] }, e[c][t] = n; return; } else if (Array.isArray(e[c]) || typeof e[c] == "object") return Ne(e[c], r, t, n); } const pt = (e, r, t) => { const n = new De(), c = "pub_Sub_str-" + we; we++; let s; const u = {}, i = t === "localStorage" ? localStorage : sessionStorage; if (t) { const v = i.getItem(c); v ? s = JSON.parse(v) : (s = { ...e }, i.setItem(c, JSON.stringify(s))); } else s = { ...e }; if (r) for (const v in r) u[v] = (...g) => { const p = o(); r[v](p, ...g), t && i.setItem(c, JSON.stringify(p)), n.publish(c, p); }; n.subscribe(c, (v) => { s = v; }); function o() { return s; } function a(v) { const g = o(); v(g), t && i.setItem(c, JSON.stringify(g)), n.publish(c, g); } function f(v) { const g = d([]), p = xe(() => { if (v) { let h = new Proxy(o(), Oe(g.current)); return v(h), h = null, v(o()); } else return o(); }), y = T( m((h) => { const E = (S) => { const R = v ? v(S) : S; U(p.current, R) || (p.current = R, h()); }; return n.subscribe(c, E), () => { n.unsubscribe(c, E); }; }, [v, p]), m(() => p.current, [p]) ), l = d(() => p.current), w = d((h) => { if (v) { const E = h instanceof Function ? h(p.current) : h; let S = o(); for (let R = 0; R < g.current.length - 1; R++) !(g.current[R] in S) && (S[g.current[R]] = o()[g.current[R]]), S = S[g.current[R]]; if (Array.isArray(E) || typeof E == "object") S[g.current[g.current.length - 1]] = E, t && i.setItem(c, JSON.stringify(o())), n.publish(c, o()); else { const R = o(); Ne(R, S, g.current[g.current.length - 1], E), S = R, t && i.setItem(c, JSON.stringify(S)), n.publish(c, S); } } else { const E = h instanceof Function ? h(p.current) : h; t && i.setItem(c, JSON.stringify(E)), n.publish(c, E); } }); return [y, w.current, l.current, u]; } return { getStore: o, mutateStore: a, mutators: u, usePubSubStore: f }; }, X = (e) => { let r = "script"; for (const [t, n] of Object.entries(e)) n && (r += `[${t}${typeof n == "boolean" ? "" : `="${n}"`}]`); return document.querySelector(r); }, ir = (e) => { const r = document.createElement("script"); return e.src && (r.src = e.src), e.async && (r.async = !0), e.defer && (r.defer = !0), e.type && r.setAttribute("type", e.type), e.crossorigin && r.setAttribute("crossorigin", e.crossorigin), e.fetchpriority && r.setAttribute("fetchpriority", e.fetchpriority), e.integrity && r.setAttribute("integrity", e.integrity), e.nonce && r.setAttribute("nonce", e.nonce), e.nomodule && r.setAttribute("nomodule", e.nomodule.toString()), e.referrerpolicy && r.setAttribute("referrerpolicy", e.referrerpolicy), r.setAttribute("data-status", "loading"), r; }, wt = function(e, r) { const t = d(r), n = d(e), [c, s] = C(t.current.handleAppending ? 1 : 0), u = m((a, f) => { a && (n.current = a), f && (t.current.iframe = f), s((v) => v + 1); }, []), i = m(() => { var f; const a = X(n.current); (f = a == null ? void 0 : a.parentElement) == null || f.removeChild(a); }, []); return M(() => () => { t.current.removeOnUnmount && i(); }), [ T( m((a) => { var f, v; if (c % 2 === 0) { let g, p = !0; g = X(n.current), g || (p = !1, g = ir(n.current)); const y = (l) => { const w = X(n.current); w == null || w.setAttribute("data-status", l.type === "load" ? "ready" : "error"), a(); }; return g.addEventListener("load", y, { passive: !0 }), g.addEventListener("error", y, { passive: !0 }), !p && (((v = (f = t.current.iframe) == null ? void 0 : f.contentWindow) == null ? void 0 : v.document) || document).body.appendChild(g), () => { const l = X(n.current); l == null || l.removeEventListener("load", y), l == null || l.removeEventListener("error", y); }; } else return () => { }; }, [c]), m(() => { var f; return ((f = X(n.current)) == null ? void 0 : f.getAttribute("data-status")) ?? (t.current.handleAppending ? "idle" : "loading"); }, []) ), u, i ]; }, or = (e, r, t = !1) => { if (!t || typeof requestAnimationFrame > "u") return { id: setTimeout(e, r) }; const n = { id: 0 }, c = (/* @__PURE__ */ new Date()).getTime(), s = () => { const u = (/* @__PURE__ */ new Date()).getTime(); console.log(((u - c) / 1e3).toFixed(0)), u - c >= r ? e() : n.id = requestAnimationFrame(s); }; return n.id = requestAnimationFrame(s), n; }, re = (e, r = !1) => { if (!r || typeof cancelAnimationFrame > "u") return clearTimeout(e.id); cancelAnimationFrame(e.id); }, yt = (e, r) => { const t = d({ id: 0 }), n = d(r), c = m((...i) => { re(t.current, n.current.focusedWindow), t.current = or(() => e(...i), n.current.delay, n.current.focusedWindow); }, [e]), s = m(() => { re(t.current, n.current.focusedWindow); }, []), u = m((...i) => { re(t.current, n.current.focusedWindow), e(...i); }, [e]); return [ c, s, u ]; }, St = (e, r) => { const t = d(r), n = d(!1), c = d(), s = m((...o) => { if (!n.current) if (n.current = !0, t.current.delay) e(...o), c.current = setTimeout(() => n.current = !1, t.current.delay); else if (t.current.waitFn) { const a = e(...o); je(a) ? a.finally(() => n.current = !1) : n.current = !1; } else throw Error("useThrottled: options aren't setted correctly."); }, [e]), u = m(() => { n.current = !1; }, []), i = m((...o) => { n.current = !1, e(...o); }, [e]); return [ s, u, i ]; }, Et = () => { const e = d(null); return T( m((r) => { e.current = document.activeElement; const t = { id: 0 }, n = (c) => { c.type === "focusout" ? t.id = setTimeout(() => { r(); }, 0) : (clearTimeout(t.id), r()); }; if (typeof addEventListener > "u") t