UNPKG

@pdf-viewer/react

Version:

A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.

1,446 lines (1,445 loc) 42.1 kB
import { jsxs as _t, jsx as ie } from "react/jsx-runtime"; import * as P from "react"; import { useCallback as L, createContext as Y, useMemo as D, createElement as h, useContext as be, forwardRef as A, Children as _, isValidElement as k, cloneElement as V, Fragment as Be, useEffect as S, useRef as O, useState as N, useLayoutEffect as me, useReducer as Nt } from "react"; import Tt, { flushSync as Ue } from "react-dom"; import { u as Dt, a as Ft, o as Rt, s as It, l as Lt, f as kt, b as Mt, c as Bt, h as Ut } from "./floating-ui.react-dom-4b1e2e46.js"; import { c as Wt, _ as zt, u as Ht, a as K, f as Kt, z as Xt, s as Yt, b as jt, R as Vt, e as Zt, h as Gt } from "./component-2aa6e53b.js"; import { c as qt } from "./clsx-0c6e471a.js"; import './assets/Popover.css';function x() { return x = Object.assign ? Object.assign.bind() : function(e) { for (var t = 1; t < arguments.length; t++) { var n = arguments[t]; for (var o in n) ({}).hasOwnProperty.call(n, o) && (e[o] = n[o]); } return e; }, x.apply(null, arguments); } function B(e, t, { checkForDefaultPrevented: n = !0 } = {}) { return function(r) { if (e == null || e(r), n === !1 || !r.defaultPrevented) return t == null ? void 0 : t(r); }; } function Qt(e, t) { typeof e == "function" ? e(t) : e != null && (e.current = t); } function We(...e) { return (t) => e.forEach( (n) => Qt(n, t) ); } function Z(...e) { return L(We(...e), e); } function Jt(e, t = []) { let n = []; function o(a, i) { const c = /* @__PURE__ */ Y(i), s = n.length; n = [ ...n, i ]; function u(d) { const { scope: $, children: f, ...y } = d, l = ($ == null ? void 0 : $[e][s]) || c, p = D( () => y, Object.values(y) ); return /* @__PURE__ */ h(l.Provider, { value: p }, f); } function v(d, $) { const f = ($ == null ? void 0 : $[e][s]) || c, y = be(f); if (y) return y; if (i !== void 0) return i; throw new Error(`\`${d}\` must be used within \`${a}\``); } return u.displayName = a + "Provider", [ u, v ]; } const r = () => { const a = n.map((i) => /* @__PURE__ */ Y(i)); return function(c) { const s = (c == null ? void 0 : c[e]) || a; return D( () => ({ [`__scope${e}`]: { ...c, [e]: s } }), [ c, s ] ); }; }; return r.scopeName = e, [ o, en(r, ...t) ]; } function en(...e) { const t = e[0]; if (e.length === 1) return t; const n = () => { const o = e.map( (r) => ({ useScope: r(), scopeName: r.scopeName }) ); return function(a) { const i = o.reduce((c, { useScope: s, scopeName: u }) => { const d = s(a)[`__scope${u}`]; return { ...c, ...d }; }, {}); return D( () => ({ [`__scope${t.scopeName}`]: i }), [ i ] ); }; }; return n.scopeName = t.scopeName, n; } const ge = /* @__PURE__ */ A((e, t) => { const { children: n, ...o } = e, r = _.toArray(n), a = r.find(nn); if (a) { const i = a.props.children, c = r.map((s) => s === a ? _.count(i) > 1 ? _.only(null) : /* @__PURE__ */ k(i) ? i.props.children : null : s); return /* @__PURE__ */ h(fe, x({}, o, { ref: t }), /* @__PURE__ */ k(i) ? /* @__PURE__ */ V(i, void 0, c) : null); } return /* @__PURE__ */ h(fe, x({}, o, { ref: t }), n); }); ge.displayName = "Slot"; const fe = /* @__PURE__ */ A((e, t) => { const { children: n, ...o } = e; return /* @__PURE__ */ k(n) ? /* @__PURE__ */ V(n, { ...on(o, n.props), ref: t ? We(t, n.ref) : n.ref }) : _.count(n) > 1 ? _.only(null) : null; }); fe.displayName = "SlotClone"; const tn = ({ children: e }) => /* @__PURE__ */ h(Be, null, e); function nn(e) { return /* @__PURE__ */ k(e) && e.type === tn; } function on(e, t) { const n = { ...t }; for (const o in t) { const r = e[o], a = t[o]; /^on[A-Z]/.test(o) ? r && a ? n[o] = (...c) => { a(...c), r(...c); } : r && (n[o] = r) : o === "style" ? n[o] = { ...r, ...a } : o === "className" && (n[o] = [ r, a ].filter(Boolean).join(" ")); } return { ...e, ...n }; } const rn = [ "a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "span", "svg", "ul" ], oe = rn.reduce((e, t) => { const n = /* @__PURE__ */ A((o, r) => { const { asChild: a, ...i } = o, c = a ? ge : t; return S(() => { window[Symbol.for("radix-ui")] = !0; }, []), /* @__PURE__ */ h(c, x({}, i, { ref: r })); }); return n.displayName = `Primitive.${t}`, { ...e, [t]: n }; }, {}); function cn(e, t) { e && Ue( () => e.dispatchEvent(t) ); } function Pe(e) { const t = O(e); return S(() => { t.current = e; }), D( () => (...n) => { var o; return (o = t.current) === null || o === void 0 ? void 0 : o.call(t, ...n); }, [] ); } function an(e, t = globalThis == null ? void 0 : globalThis.document) { const n = Pe(e); S(() => { const o = (r) => { r.key === "Escape" && n(r); }; return t.addEventListener("keydown", o), () => t.removeEventListener("keydown", o); }, [ n, t ]); } const ve = "dismissableLayer.update", sn = "dismissableLayer.pointerDownOutside", ln = "dismissableLayer.focusOutside"; let Oe; const un = /* @__PURE__ */ Y({ layers: /* @__PURE__ */ new Set(), layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(), branches: /* @__PURE__ */ new Set() }), dn = /* @__PURE__ */ A((e, t) => { var n; const { disableOutsidePointerEvents: o = !1, onEscapeKeyDown: r, onPointerDownOutside: a, onFocusOutside: i, onInteractOutside: c, onDismiss: s, ...u } = e, v = be(un), [d, $] = N(null), f = (n = d == null ? void 0 : d.ownerDocument) !== null && n !== void 0 ? n : globalThis == null ? void 0 : globalThis.document, [, y] = N({}), l = Z( t, (w) => $(w) ), p = Array.from(v.layers), [b] = [ ...v.layersWithOutsidePointerEventsDisabled ].slice(-1), E = p.indexOf(b), g = d ? p.indexOf(d) : -1, m = v.layersWithOutsidePointerEventsDisabled.size > 0, C = g >= E, R = fn((w) => { const F = w.target, G = [ ...v.branches ].some( (M) => M.contains(F) ); !C || G || (a == null || a(w), c == null || c(w), w.defaultPrevented || s == null || s()); }, f), T = vn((w) => { const F = w.target; [ ...v.branches ].some( (M) => M.contains(F) ) || (i == null || i(w), c == null || c(w), w.defaultPrevented || s == null || s()); }, f); return an((w) => { g === v.layers.size - 1 && (r == null || r(w), !w.defaultPrevented && s && (w.preventDefault(), s())); }, f), S(() => { if (d) return o && (v.layersWithOutsidePointerEventsDisabled.size === 0 && (Oe = f.body.style.pointerEvents, f.body.style.pointerEvents = "none"), v.layersWithOutsidePointerEventsDisabled.add(d)), v.layers.add(d), Ae(), () => { o && v.layersWithOutsidePointerEventsDisabled.size === 1 && (f.body.style.pointerEvents = Oe); }; }, [ d, f, o, v ]), S(() => () => { d && (v.layers.delete(d), v.layersWithOutsidePointerEventsDisabled.delete(d), Ae()); }, [ d, v ]), S(() => { const w = () => y({}); return document.addEventListener(ve, w), () => document.removeEventListener(ve, w); }, []), /* @__PURE__ */ h(oe.div, x({}, u, { ref: l, style: { pointerEvents: m ? C ? "auto" : "none" : void 0, ...e.style }, onFocusCapture: B(e.onFocusCapture, T.onFocusCapture), onBlurCapture: B(e.onBlurCapture, T.onBlurCapture), onPointerDownCapture: B(e.onPointerDownCapture, R.onPointerDownCapture) })); }); function fn(e, t = globalThis == null ? void 0 : globalThis.document) { const n = Pe(e), o = O(!1), r = O(() => { }); return S(() => { const a = (c) => { if (c.target && !o.current) { let u = function() { ze(sn, n, s, { discrete: !0 }); }; const s = { originalEvent: c }; c.pointerType === "touch" ? (t.removeEventListener("click", r.current), r.current = u, t.addEventListener("click", r.current, { once: !0 })) : u(); } o.current = !1; }, i = window.setTimeout(() => { t.addEventListener("pointerdown", a); }, 0); return () => { window.clearTimeout(i), t.removeEventListener("pointerdown", a), t.removeEventListener("click", r.current); }; }, [ t, n ]), { // ensures we check React component tree (not just DOM tree) onPointerDownCapture: () => o.current = !0 }; } function vn(e, t = globalThis == null ? void 0 : globalThis.document) { const n = Pe(e), o = O(!1); return S(() => { const r = (a) => { a.target && !o.current && ze(ln, n, { originalEvent: a }, { discrete: !1 }); }; return t.addEventListener("focusin", r), () => t.removeEventListener("focusin", r); }, [ t, n ]), { onFocusCapture: () => o.current = !0, onBlurCapture: () => o.current = !1 }; } function Ae() { const e = new CustomEvent(ve); document.dispatchEvent(e); } function ze(e, t, n, { discrete: o }) { const r = n.originalEvent.target, a = new CustomEvent(e, { bubbles: !1, cancelable: !0, detail: n }); t && r.addEventListener(e, t, { once: !0 }), o ? cn(r, a) : r.dispatchEvent(a); } let se = 0; function pn() { S(() => { var e, t; const n = document.querySelectorAll("[data-radix-focus-guard]"); return document.body.insertAdjacentElement("afterbegin", (e = n[0]) !== null && e !== void 0 ? e : _e()), document.body.insertAdjacentElement("beforeend", (t = n[1]) !== null && t !== void 0 ? t : _e()), se++, () => { se === 1 && document.querySelectorAll("[data-radix-focus-guard]").forEach( (o) => o.remove() ), se--; }; }, []); } function _e() { const e = document.createElement("span"); return e.setAttribute("data-radix-focus-guard", ""), e.tabIndex = 0, e.style.cssText = "outline: none; opacity: 0; position: fixed; pointer-events: none", e; } function Ne(e) { const t = O(e); return S(() => { t.current = e; }), D( () => (...n) => { var o; return (o = t.current) === null || o === void 0 ? void 0 : o.call(t, ...n); }, [] ); } const le = "focusScope.autoFocusOnMount", ue = "focusScope.autoFocusOnUnmount", Te = { bubbles: !1, cancelable: !0 }, $n = /* @__PURE__ */ A((e, t) => { const { loop: n = !1, trapped: o = !1, onMountAutoFocus: r, onUnmountAutoFocus: a, ...i } = e, [c, s] = N(null), u = Ne(r), v = Ne(a), d = O(null), $ = Z( t, (l) => s(l) ), f = O({ paused: !1, pause() { this.paused = !0; }, resume() { this.paused = !1; } }).current; S(() => { if (o) { let l = function(g) { if (f.paused || !c) return; const m = g.target; c.contains(m) ? d.current = m : I(d.current, { select: !0 }); }, p = function(g) { if (f.paused || !c) return; const m = g.relatedTarget; m !== null && (c.contains(m) || I(d.current, { select: !0 })); }, b = function(g) { const m = document.activeElement; for (const C of g) C.removedNodes.length > 0 && (c != null && c.contains(m) || I(c)); }; document.addEventListener("focusin", l), document.addEventListener("focusout", p); const E = new MutationObserver(b); return c && E.observe(c, { childList: !0, subtree: !0 }), () => { document.removeEventListener("focusin", l), document.removeEventListener("focusout", p), E.disconnect(); }; } }, [ o, c, f.paused ]), S(() => { if (c) { Fe.add(f); const l = document.activeElement; if (!c.contains(l)) { const b = new CustomEvent(le, Te); c.addEventListener(le, u), c.dispatchEvent(b), b.defaultPrevented || (hn(yn(He(c)), { select: !0 }), document.activeElement === l && I(c)); } return () => { c.removeEventListener(le, u), setTimeout(() => { const b = new CustomEvent(ue, Te); c.addEventListener(ue, v), c.dispatchEvent(b), b.defaultPrevented || I(l ?? document.body, { select: !0 }), c.removeEventListener(ue, v), Fe.remove(f); }, 0); }; } }, [ c, u, v, f ]); const y = L((l) => { if (!n && !o || f.paused) return; const p = l.key === "Tab" && !l.altKey && !l.ctrlKey && !l.metaKey, b = document.activeElement; if (p && b) { const E = l.currentTarget, [g, m] = bn(E); g && m ? !l.shiftKey && b === m ? (l.preventDefault(), n && I(g, { select: !0 })) : l.shiftKey && b === g && (l.preventDefault(), n && I(m, { select: !0 })) : b === E && l.preventDefault(); } }, [ n, o, f.paused ]); return /* @__PURE__ */ h(oe.div, x({ tabIndex: -1 }, i, { ref: $, onKeyDown: y })); }); function hn(e, { select: t = !1 } = {}) { const n = document.activeElement; for (const o of e) if (I(o, { select: t }), document.activeElement !== n) return; } function bn(e) { const t = He(e), n = De(t, e), o = De(t.reverse(), e); return [ n, o ]; } function He(e) { const t = [], n = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT, { acceptNode: (o) => { const r = o.tagName === "INPUT" && o.type === "hidden"; return o.disabled || o.hidden || r ? NodeFilter.FILTER_SKIP : o.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP; } }); for (; n.nextNode(); ) t.push(n.currentNode); return t; } function De(e, t) { for (const n of e) if (!mn(n, { upTo: t })) return n; } function mn(e, { upTo: t }) { if (getComputedStyle(e).visibility === "hidden") return !0; for (; e; ) { if (t !== void 0 && e === t) return !1; if (getComputedStyle(e).display === "none") return !0; e = e.parentElement; } return !1; } function gn(e) { return e instanceof HTMLInputElement && "select" in e; } function I(e, { select: t = !1 } = {}) { if (e && e.focus) { const n = document.activeElement; e.focus({ preventScroll: !0 }), e !== n && gn(e) && t && e.select(); } } const Fe = Pn(); function Pn() { let e = []; return { add(t) { const n = e[0]; t !== n && (n == null || n.pause()), e = Re(e, t), e.unshift(t); }, remove(t) { var n; e = Re(e, t), (n = e[0]) === null || n === void 0 || n.resume(); } }; } function Re(e, t) { const n = [ ...e ], o = n.indexOf(t); return o !== -1 && n.splice(o, 1), n; } function yn(e) { return e.filter( (t) => t.tagName !== "A" ); } const wn = globalThis != null && globalThis.document ? me : () => { }, En = P["useId".toString()] || (() => { }); let Cn = 0; function xn(e) { const [t, n] = P.useState(En()); return wn(() => { e || n( (o) => o ?? String(Cn++) ); }, [ e ]), e || (t ? `radix-${t}` : ""); } function Sn(e, t) { typeof e == "function" ? e(t) : e != null && (e.current = t); } function Ke(...e) { return (t) => e.forEach( (n) => Sn(n, t) ); } function Xe(...e) { return L(Ke(...e), e); } function On(e, t = []) { let n = []; function o(a, i) { const c = /* @__PURE__ */ Y(i), s = n.length; n = [ ...n, i ]; function u(d) { const { scope: $, children: f, ...y } = d, l = ($ == null ? void 0 : $[e][s]) || c, p = D( () => y, Object.values(y) ); return /* @__PURE__ */ h(l.Provider, { value: p }, f); } function v(d, $) { const f = ($ == null ? void 0 : $[e][s]) || c, y = be(f); if (y) return y; if (i !== void 0) return i; throw new Error(`\`${d}\` must be used within \`${a}\``); } return u.displayName = a + "Provider", [ u, v ]; } const r = () => { const a = n.map((i) => /* @__PURE__ */ Y(i)); return function(c) { const s = (c == null ? void 0 : c[e]) || a; return D( () => ({ [`__scope${e}`]: { ...c, [e]: s } }), [ c, s ] ); }; }; return r.scopeName = e, [ o, An(r, ...t) ]; } function An(...e) { const t = e[0]; if (e.length === 1) return t; const n = () => { const o = e.map( (r) => ({ useScope: r(), scopeName: r.scopeName }) ); return function(a) { const i = o.reduce((c, { useScope: s, scopeName: u }) => { const d = s(a)[`__scope${u}`]; return { ...c, ...d }; }, {}); return D( () => ({ [`__scope${t.scopeName}`]: i }), [ i ] ); }; }; return n.scopeName = t.scopeName, n; } const Ye = /* @__PURE__ */ A((e, t) => { const { children: n, ...o } = e, r = _.toArray(n), a = r.find(Nn); if (a) { const i = a.props.children, c = r.map((s) => s === a ? _.count(i) > 1 ? _.only(null) : /* @__PURE__ */ k(i) ? i.props.children : null : s); return /* @__PURE__ */ h(pe, x({}, o, { ref: t }), /* @__PURE__ */ k(i) ? /* @__PURE__ */ V(i, void 0, c) : null); } return /* @__PURE__ */ h(pe, x({}, o, { ref: t }), n); }); Ye.displayName = "Slot"; const pe = /* @__PURE__ */ A((e, t) => { const { children: n, ...o } = e; return /* @__PURE__ */ k(n) ? /* @__PURE__ */ V(n, { ...Tn(o, n.props), ref: t ? Ke(t, n.ref) : n.ref }) : _.count(n) > 1 ? _.only(null) : null; }); pe.displayName = "SlotClone"; const _n = ({ children: e }) => /* @__PURE__ */ h(Be, null, e); function Nn(e) { return /* @__PURE__ */ k(e) && e.type === _n; } function Tn(e, t) { const n = { ...t }; for (const o in t) { const r = e[o], a = t[o]; /^on[A-Z]/.test(o) ? r && a ? n[o] = (...c) => { a(...c), r(...c); } : r && (n[o] = r) : o === "style" ? n[o] = { ...r, ...a } : o === "className" && (n[o] = [ r, a ].filter(Boolean).join(" ")); } return { ...e, ...n }; } const Dn = [ "a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "span", "svg", "ul" ], je = Dn.reduce((e, t) => { const n = /* @__PURE__ */ A((o, r) => { const { asChild: a, ...i } = o, c = a ? Ye : t; return S(() => { window[Symbol.for("radix-ui")] = !0; }, []), /* @__PURE__ */ h(c, x({}, i, { ref: r })); }); return n.displayName = `Primitive.${t}`, { ...e, [t]: n }; }, {}); function Fn(e) { const t = O(e); return S(() => { t.current = e; }), D( () => (...n) => { var o; return (o = t.current) === null || o === void 0 ? void 0 : o.call(t, ...n); }, [] ); } const $e = globalThis != null && globalThis.document ? me : () => { }; function Rn(e) { const [t, n] = N(void 0); return $e(() => { if (e) { n({ width: e.offsetWidth, height: e.offsetHeight }); const o = new ResizeObserver((r) => { if (!Array.isArray(r) || !r.length) return; const a = r[0]; let i, c; if ("borderBoxSize" in a) { const s = a.borderBoxSize, u = Array.isArray(s) ? s[0] : s; i = u.inlineSize, c = u.blockSize; } else i = e.offsetWidth, c = e.offsetHeight; n({ width: i, height: c }); }); return o.observe(e, { box: "border-box" }), () => o.unobserve(e); } else n(void 0); }, [ e ]), t; } const Ve = "Popper", [Ze, Ge] = On(Ve), [In, qe] = Ze(Ve), Ln = (e) => { const { __scopePopper: t, children: n } = e, [o, r] = N(null); return /* @__PURE__ */ h(In, { scope: t, anchor: o, onAnchorChange: r }, n); }, kn = "PopperAnchor", Mn = /* @__PURE__ */ A((e, t) => { const { __scopePopper: n, virtualRef: o, ...r } = e, a = qe(kn, n), i = O(null), c = Xe(t, i); return S(() => { a.onAnchorChange((o == null ? void 0 : o.current) || i.current); }), o ? null : /* @__PURE__ */ h(je.div, x({}, r, { ref: c })); }), Qe = "PopperContent", [Bn, Lo] = Ze(Qe), Un = /* @__PURE__ */ A((e, t) => { var n, o, r, a, i, c, s, u; const { __scopePopper: v, side: d = "bottom", sideOffset: $ = 0, align: f = "center", alignOffset: y = 0, arrowPadding: l = 0, collisionBoundary: p = [], collisionPadding: b = 0, sticky: E = "partial", hideWhenDetached: g = !1, avoidCollisions: m = !0, onPlaced: C, ...R } = e, T = qe(Qe, v), [w, F] = N(null), G = Xe( t, (ae) => F(ae) ), [M, dt] = N(null), U = Rn(M), ft = (n = U == null ? void 0 : U.width) !== null && n !== void 0 ? n : 0, Ee = (o = U == null ? void 0 : U.height) !== null && o !== void 0 ? o : 0, vt = d + (f !== "center" ? "-" + f : ""), pt = typeof b == "number" ? b : { top: 0, right: 0, bottom: 0, left: 0, ...b }, Ce = Array.isArray(p) ? p : [ p ], $t = Ce.length > 0, ce = { padding: pt, boundary: Ce.filter(Wn), // with `strategy: 'fixed'`, this is the only way to get it to respect boundaries altBoundary: $t }, { refs: ht, floatingStyles: xe, placement: bt, isPositioned: q, middlewareData: W } = Dt({ // default to `fixed` strategy so users don't have to pick and we also avoid focus scroll issues strategy: "fixed", placement: vt, whileElementsMounted: Ft, elements: { reference: T.anchor }, middleware: [ Rt({ mainAxis: $ + Ee, alignmentAxis: y }), m && It({ mainAxis: !0, crossAxis: !1, limiter: E === "partial" ? Lt() : void 0, ...ce }), m && kt({ ...ce }), Mt({ ...ce, apply: ({ elements: ae, rects: Ct, availableWidth: xt, availableHeight: St }) => { const { width: Ot, height: At } = Ct.reference, J = ae.floating.style; J.setProperty("--radix-popper-available-width", `${xt}px`), J.setProperty("--radix-popper-available-height", `${St}px`), J.setProperty("--radix-popper-anchor-width", `${Ot}px`), J.setProperty("--radix-popper-anchor-height", `${At}px`); } }), M && Bt({ element: M, padding: l }), zn({ arrowWidth: ft, arrowHeight: Ee }), g && Ut({ strategy: "referenceHidden" }) ] }), [Se, mt] = Je(bt), Q = Fn(C); $e(() => { q && (Q == null || Q()); }, [ q, Q ]); const gt = (r = W.arrow) === null || r === void 0 ? void 0 : r.x, Pt = (a = W.arrow) === null || a === void 0 ? void 0 : a.y, yt = ((i = W.arrow) === null || i === void 0 ? void 0 : i.centerOffset) !== 0, [wt, Et] = N(); return $e(() => { w && Et(window.getComputedStyle(w).zIndex); }, [ w ]), /* @__PURE__ */ h("div", { ref: ht.setFloating, "data-radix-popper-content-wrapper": "", style: { ...xe, transform: q ? xe.transform : "translate(0, -200%)", // keep off the page when measuring minWidth: "max-content", zIndex: wt, "--radix-popper-transform-origin": [ (c = W.transformOrigin) === null || c === void 0 ? void 0 : c.x, (s = W.transformOrigin) === null || s === void 0 ? void 0 : s.y ].join(" ") }, dir: e.dir }, /* @__PURE__ */ h(Bn, { scope: v, placedSide: Se, onArrowChange: dt, arrowX: gt, arrowY: Pt, shouldHideArrow: yt }, /* @__PURE__ */ h(je.div, x({ "data-side": Se, "data-align": mt }, R, { ref: G, style: { ...R.style, // if the PopperContent hasn't been placed yet (not all measurements done) // we prevent animations so that users's animation don't kick in too early referring wrong sides animation: q ? void 0 : "none", // hide the content if using the hide middleware and should be hidden opacity: (u = W.hide) !== null && u !== void 0 && u.referenceHidden ? 0 : void 0 } })))); }); function Wn(e) { return e !== null; } const zn = (e) => ({ name: "transformOrigin", options: e, fn(t) { var n, o, r, a, i; const { placement: c, rects: s, middlewareData: u } = t, d = ((n = u.arrow) === null || n === void 0 ? void 0 : n.centerOffset) !== 0, $ = d ? 0 : e.arrowWidth, f = d ? 0 : e.arrowHeight, [y, l] = Je(c), p = { start: "0%", center: "50%", end: "100%" }[l], b = ((o = (r = u.arrow) === null || r === void 0 ? void 0 : r.x) !== null && o !== void 0 ? o : 0) + $ / 2, E = ((a = (i = u.arrow) === null || i === void 0 ? void 0 : i.y) !== null && a !== void 0 ? a : 0) + f / 2; let g = "", m = ""; return y === "bottom" ? (g = d ? p : `${b}px`, m = `${-f}px`) : y === "top" ? (g = d ? p : `${b}px`, m = `${s.floating.height + f}px`) : y === "right" ? (g = `${-f}px`, m = d ? p : `${E}px`) : y === "left" && (g = `${s.floating.width + f}px`, m = d ? p : `${E}px`), { data: { x: g, y: m } }; } }); function Je(e) { const [t, n = "center"] = e.split("-"); return [ t, n ]; } const Hn = Ln, Kn = Mn, Xn = Un, Yn = /* @__PURE__ */ A((e, t) => { var n; const { container: o = globalThis == null || (n = globalThis.document) === null || n === void 0 ? void 0 : n.body, ...r } = e; return o ? /* @__PURE__ */ Tt.createPortal(/* @__PURE__ */ h(oe.div, x({}, r, { ref: t })), o) : null; }), Ie = globalThis != null && globalThis.document ? me : () => { }; function jn(e, t) { return Nt((n, o) => { const r = t[n][o]; return r ?? n; }, e); } const ye = (e) => { const { present: t, children: n } = e, o = Vn(t), r = typeof n == "function" ? n({ present: o.isPresent }) : _.only(n), a = Z(o.ref, r.ref); return typeof n == "function" || o.isPresent ? /* @__PURE__ */ V(r, { ref: a }) : null; }; ye.displayName = "Presence"; function Vn(e) { const [t, n] = N(), o = O({}), r = O(e), a = O("none"), i = e ? "mounted" : "unmounted", [c, s] = jn(i, { mounted: { UNMOUNT: "unmounted", ANIMATION_OUT: "unmountSuspended" }, unmountSuspended: { MOUNT: "mounted", ANIMATION_END: "unmounted" }, unmounted: { MOUNT: "mounted" } }); return S(() => { const u = ee(o.current); a.current = c === "mounted" ? u : "none"; }, [ c ]), Ie(() => { const u = o.current, v = r.current; if (v !== e) { const $ = a.current, f = ee(u); e ? s("MOUNT") : f === "none" || (u == null ? void 0 : u.display) === "none" ? s("UNMOUNT") : s(v && $ !== f ? "ANIMATION_OUT" : "UNMOUNT"), r.current = e; } }, [ e, s ]), Ie(() => { if (t) { const u = (d) => { const f = ee(o.current).includes(d.animationName); d.target === t && f && Ue( () => s("ANIMATION_END") ); }, v = (d) => { d.target === t && (a.current = ee(o.current)); }; return t.addEventListener("animationstart", v), t.addEventListener("animationcancel", u), t.addEventListener("animationend", u), () => { t.removeEventListener("animationstart", v), t.removeEventListener("animationcancel", u), t.removeEventListener("animationend", u); }; } else s("ANIMATION_END"); }, [ t, s ]), { isPresent: [ "mounted", "unmountSuspended" ].includes(c), ref: L((u) => { u && (o.current = getComputedStyle(u)), n(u); }, []) }; } function ee(e) { return (e == null ? void 0 : e.animationName) || "none"; } function et(e) { const t = O(e); return S(() => { t.current = e; }), D( () => (...n) => { var o; return (o = t.current) === null || o === void 0 ? void 0 : o.call(t, ...n); }, [] ); } function Zn({ prop: e, defaultProp: t, onChange: n = () => { } }) { const [o, r] = Gn({ defaultProp: t, onChange: n }), a = e !== void 0, i = a ? e : o, c = et(n), s = L((u) => { if (a) { const d = typeof u == "function" ? u(e) : u; d !== e && c(d); } else r(u); }, [ a, e, r, c ]); return [ i, s ]; } function Gn({ defaultProp: e, onChange: t }) { const n = N(e), [o] = n, r = O(o), a = et(t); return S(() => { r.current !== o && (a(o), r.current = o); }, [ o, r, a ]), n; } var tt = Wt(), de = function() { }, re = P.forwardRef(function(e, t) { var n = P.useRef(null), o = P.useState({ onScrollCapture: de, onWheelCapture: de, onTouchMoveCapture: de }), r = o[0], a = o[1], i = e.forwardProps, c = e.children, s = e.className, u = e.removeScrollBar, v = e.enabled, d = e.shards, $ = e.sideCar, f = e.noIsolation, y = e.inert, l = e.allowPinchZoom, p = e.as, b = p === void 0 ? "div" : p, E = zt(e, ["forwardProps", "children", "className", "removeScrollBar", "enabled", "shards", "sideCar", "noIsolation", "inert", "allowPinchZoom", "as"]), g = $, m = Ht([n, t]), C = K(K({}, E), r); return P.createElement( P.Fragment, null, v && P.createElement(g, { sideCar: tt, removeScrollBar: u, shards: d, noIsolation: f, inert: y, setCallbacks: a, allowPinchZoom: !!l, lockRef: n }), i ? P.cloneElement(P.Children.only(c), K(K({}, C), { ref: m })) : P.createElement(b, K({}, C, { className: s, ref: m }), c) ); }); re.defaultProps = { enabled: !0, removeScrollBar: !0, inert: !1 }; re.classNames = { fullWidth: Kt, zeroRight: Xt }; var he = !1; if (typeof window < "u") try { var te = Object.defineProperty({}, "passive", { get: function() { return he = !0, !0; } }); window.addEventListener("test", te, te), window.removeEventListener("test", te, te); } catch { he = !1; } var z = he ? { passive: !1 } : !1, qn = function(e) { return e.tagName === "TEXTAREA"; }, nt = function(e, t) { var n = window.getComputedStyle(e); return ( // not-not-scrollable n[t] !== "hidden" && // contains scroll inside self !(n.overflowY === n.overflowX && !qn(e) && n[t] === "visible") ); }, Qn = function(e) { return nt(e, "overflowY"); }, Jn = function(e) { return nt(e, "overflowX"); }, Le = function(e, t) { var n = t; do { typeof ShadowRoot < "u" && n instanceof ShadowRoot && (n = n.host); var o = ot(e, n); if (o) { var r = rt(e, n), a = r[1], i = r[2]; if (a > i) return !0; } n = n.parentNode; } while (n && n !== document.body); return !1; }, eo = function(e) { var t = e.scrollTop, n = e.scrollHeight, o = e.clientHeight; return [ t, n, o ]; }, to = function(e) { var t = e.scrollLeft, n = e.scrollWidth, o = e.clientWidth; return [ t, n, o ]; }, ot = function(e, t) { return e === "v" ? Qn(t) : Jn(t); }, rt = function(e, t) { return e === "v" ? eo(t) : to(t); }, no = function(e, t) { return e === "h" && t === "rtl" ? -1 : 1; }, oo = function(e, t, n, o, r) { var a = no(e, window.getComputedStyle(t).direction), i = a * o, c = n.target, s = t.contains(c), u = !1, v = i > 0, d = 0, $ = 0; do { var f = rt(e, c), y = f[0], l = f[1], p = f[2], b = l - p - a * y; (y || b) && ot(e, c) && (d += b, $ += y), c = c.parentNode; } while ( // portaled content !s && c !== document.body || // self content s && (t.contains(c) || t === c) ); return (v && (r && d === 0 || !r && i > d) || !v && (r && $ === 0 || !r && -i > $)) && (u = !0), u; }, ne = function(e) { return "changedTouches" in e ? [e.changedTouches[0].clientX, e.changedTouches[0].clientY] : [0, 0]; }, ke = function(e) { return [e.deltaX, e.deltaY]; }, Me = function(e) { return e && "current" in e ? e.current : e; }, ro = function(e, t) { return e[0] === t[0] && e[1] === t[1]; }, co = function(e) { return ` .block-interactivity-`.concat(e, ` {pointer-events: none;} .allow-interactivity-`).concat(e, ` {pointer-events: all;} `); }, ao = 0, H = []; function io(e) { var t = P.useRef([]), n = P.useRef([0, 0]), o = P.useRef(), r = P.useState(ao++)[0], a = P.useState(function() { return Yt(); })[0], i = P.useRef(e); P.useEffect(function() { i.current = e; }, [e]), P.useEffect(function() { if (e.inert) { document.body.classList.add("block-interactivity-".concat(r)); var l = jt([e.lockRef.current], (e.shards || []).map(Me), !0).filter(Boolean); return l.forEach(function(p) { return p.classList.add("allow-interactivity-".concat(r)); }), function() { document.body.classList.remove("block-interactivity-".concat(r)), l.forEach(function(p) { return p.classList.remove("allow-interactivity-".concat(r)); }); }; } }, [e.inert, e.lockRef.current, e.shards]); var c = P.useCallback(function(l, p) { if ("touches" in l && l.touches.length === 2) return !i.current.allowPinchZoom; var b = ne(l), E = n.current, g = "deltaX" in l ? l.deltaX : E[0] - b[0], m = "deltaY" in l ? l.deltaY : E[1] - b[1], C, R = l.target, T = Math.abs(g) > Math.abs(m) ? "h" : "v"; if ("touches" in l && T === "h" && R.type === "range") return !1; var w = Le(T, R); if (!w) return !0; if (w ? C = T : (C = T === "v" ? "h" : "v", w = Le(T, R)), !w) return !1; if (!o.current && "changedTouches" in l && (g || m) && (o.current = C), !C) return !0; var F = o.current || C; return oo(F, p, l, F === "h" ? g : m, !0); }, []), s = P.useCallback(function(l) { var p = l; if (!(!H.length || H[H.length - 1] !== a)) { var b = "deltaY" in p ? ke(p) : ne(p), E = t.current.filter(function(C) { return C.name === p.type && C.target === p.target && ro(C.delta, b); })[0]; if (E && E.should) { p.cancelable && p.preventDefault(); return; } if (!E) { var g = (i.current.shards || []).map(Me).filter(Boolean).filter(function(C) { return C.contains(p.target); }), m = g.length > 0 ? c(p, g[0]) : !i.current.noIsolation; m && p.cancelable && p.preventDefault(); } } }, []), u = P.useCallback(function(l, p, b, E) { var g = { name: l, delta: p, target: b, should: E }; t.current.push(g), setTimeout(function() { t.current = t.current.filter(function(m) { return m !== g; }); }, 1); }, []), v = P.useCallback(function(l) { n.current = ne(l), o.current = void 0; }, []), d = P.useCallback(function(l) { u(l.type, ke(l), l.target, c(l, e.lockRef.current)); }, []), $ = P.useCallback(function(l) { u(l.type, ne(l), l.target, c(l, e.lockRef.current)); }, []); P.useEffect(function() { return H.push(a), e.setCallbacks({ onScrollCapture: d, onWheelCapture: d, onTouchMoveCapture: $ }), document.addEventListener("wheel", s, z), document.addEventListener("touchmove", s, z), document.addEventListener("touchstart", v, z), function() { H = H.filter(function(l) { return l !== a; }), document.removeEventListener("wheel", s, z), document.removeEventListener("touchmove", s, z), document.removeEventListener("touchstart", v, z); }; }, []); var f = e.removeScrollBar, y = e.inert; return P.createElement( P.Fragment, null, y ? P.createElement(a, { styles: co(r) }) : null, f ? P.createElement(Vt, { gapMode: "margin" }) : null ); } const so = Zt(tt, io); var ct = P.forwardRef(function(e, t) { return P.createElement(re, K({}, e, { ref: t, sideCar: so })); }); ct.classNames = re.classNames; const lo = ct, at = "Popover", [it, ko] = Jt(at, [ Ge ]), we = Ge(), [uo, X] = it(at), fo = (e) => { const { __scopePopover: t, children: n, open: o, defaultOpen: r, onOpenChange: a, modal: i = !1 } = e, c = we(t), s = O(null), [u, v] = N(!1), [d = !1, $] = Zn({ prop: o, defaultProp: r, onChange: a }); return /* @__PURE__ */ h(Hn, c, /* @__PURE__ */ h(uo, { scope: t, contentId: xn(), triggerRef: s, open: d, onOpenChange: $, onOpenToggle: L( () => $( (f) => !f ), [ $ ] ), hasCustomAnchor: u, onCustomAnchorAdd: L( () => v(!0), [] ), onCustomAnchorRemove: L( () => v(!1), [] ), modal: i }, n)); }, vo = "PopoverTrigger", po = /* @__PURE__ */ A((e, t) => { const { __scopePopover: n, ...o } = e, r = X(vo, n), a = we(n), i = Z(t, r.triggerRef), c = /* @__PURE__ */ h(oe.button, x({ type: "button", "aria-haspopup": "dialog", "aria-expanded": r.open, "aria-controls": r.contentId, "data-state": ut(r.open) }, o, { ref: i, onClick: B(e.onClick, r.onOpenToggle) })); return r.hasCustomAnchor ? c : /* @__PURE__ */ h(Kn, x({ asChild: !0 }, a), c); }), st = "PopoverPortal", [$o, ho] = it(st, { forceMount: void 0 }), bo = (e) => { const { __scopePopover: t, forceMount: n, children: o, container: r } = e, a = X(st, t); return /* @__PURE__ */ h($o, { scope: t, forceMount: n }, /* @__PURE__ */ h(ye, { present: n || a.open }, /* @__PURE__ */ h(Yn, { asChild: !0, container: r }, o))); }, j = "PopoverContent", mo = /* @__PURE__ */ A((e, t) => { const n = ho(j, e.__scopePopover), { forceMount: o = n.forceMount, ...r } = e, a = X(j, e.__scopePopover); return /* @__PURE__ */ h(ye, { present: o || a.open }, a.modal ? /* @__PURE__ */ h(go, x({}, r, { ref: t })) : /* @__PURE__ */ h(Po, x({}, r, { ref: t }))); }), go = /* @__PURE__ */ A((e, t) => { const n = X(j, e.__scopePopover), o = O(null), r = Z(t, o), a = O(!1); return S(() => { const i = o.current; if (i) return Gt(i); }, []), /* @__PURE__ */ h(lo, { as: ge, allowPinchZoom: !0 }, /* @__PURE__ */ h(lt, x({}, e, { ref: r, trapFocus: n.open, disableOutsidePointerEvents: !0, onCloseAutoFocus: B(e.onCloseAutoFocus, (i) => { var c; i.preventDefault(), a.current || (c = n.triggerRef.current) === null || c === void 0 || c.focus(); }), onPointerDownOutside: B(e.onPointerDownOutside, (i) => { const c = i.detail.originalEvent, s = c.button === 0 && c.ctrlKey === !0, u = c.button === 2 || s; a.current = u; }, { checkForDefaultPrevented: !1 }), onFocusOutside: B( e.onFocusOutside, (i) => i.preventDefault(), { checkForDefaultPrevented: !1 } ) }))); }), Po = /* @__PURE__ */ A((e, t) => { const n = X(j, e.__scopePopover), o = O(!1), r = O(!1); return /* @__PURE__ */ h(lt, x({}, e, { ref: t, trapFocus: !1, disableOutsidePointerEvents: !1, onCloseAutoFocus: (a) => { var i; if ((i = e.onCloseAutoFocus) === null || i === void 0 || i.call(e, a), !a.defaultPrevented) { var c; o.current || (c = n.triggerRef.current) === null || c === void 0 || c.focus(), a.preventDefault(); } o.current = !1, r.current = !1; }, onInteractOutside: (a) => { var i, c; (i = e.onInteractOutside) === null || i === void 0 || i.call(e, a), a.defaultPrevented || (o.current = !0, a.detail.originalEvent.type === "pointerdown" && (r.current = !0)); const s = a.target; ((c = n.triggerRef.current) === null || c === void 0 ? void 0 : c.contains(s)) && a.preventDefault(), a.detail.originalEvent.type === "focusin" && r.current && a.preventDefault(); } })); }), lt = /* @__PURE__ */ A((e, t) => { const { __scopePopover: n, trapFocus: o, onOpenAutoFocus: r, onCloseAutoFocus: a, disableOutsidePointerEvents: i, onEscapeKeyDown: c, onPointerDownOutside: s, onFocusOutside: u, onInteractOutside: v, ...d } = e, $ = X(j, n), f = we(n); return pn(), /* @__PURE__ */ h($n, { asChild: !0, loop: !0, trapped: o, onMountAutoFocus: r, onUnmountAutoFocus: a }, /* @__PURE__ */ h(dn, { asChild: !0, disableOutsidePointerEvents: i, onInteractOutside: v, onEscapeKeyDown: c, onPointerDownOutside: s, onFocusOutside: u, onDismiss: () => $.onOpenChange(!1) }, /* @__PURE__ */ h(Xn, x({ "data-state": ut($.open), role: "dialog", id: $.contentId }, f, d, { ref: t, style: { ...d.style, "--radix-popover-content-transform-origin": "var(--radix-popper-transform-origin)", "--radix-popover-content-available-width": "var(--radix-popper-available-width)", "--radix-popover-content-available-height": "var(--radix-popper-available-height)", "--radix-popover-trigger-width": "var(--radix-popper-anchor-width)", "--radix-popover-trigger-height": "var(--radix-popper-anchor-height)" } })))); }); function ut(e) { return e ? "open" : "closed"; } const yo = fo, wo = po, Eo = bo, Co = mo, xo = "_slideDownAndFade_v492z_1", So = "_slideLeftAndFade_v492z_1", Oo = "_slideUpAndFade_v492z_1", Ao = "_slideRightAndFade_v492z_1", _o = { "rp-popover-content": "_rp-popover-content_v492z_1", slideDownAndFade: xo, slideLeftAndFade: So, slideUpAndFade: Oo, slideRightAndFade: Ao, "rp-popover-arrow": "_rp-popover-arrow_v492z_31" }, Mo = (e) => { const { triggerComponent: t, children: n, container: o, className: r, open: a, ...i } = e; return /* @__PURE__ */ _t(yo, { modal: !1, open: a, children: [ /* @__PURE__ */ ie(wo, { asChild: !0, children: t }), /* @__PURE__ */ ie(Eo, { container: o, children: /* @__PURE__ */ ie( Co, { tabIndex: 0, sideOffset: 8, align: "start", ...i, className: qt(_o["rp-popover-content"], r), children: n } ) }) ] }); }; export { Mo as U, x as _ };