UNPKG

@pdf-viewer/react

Version:

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

1,448 lines (1,447 loc) 39.1 kB
import * as R from "react"; import { useLayoutEffect as Zt, useEffect as te } from "react"; import { f as vt, u as $t, P as Ht, b as mt, h as ee, g as ne } from "./index-48ca3f30.js"; import { jsx as _t } from "react/jsx-runtime"; import * as ie from "react-dom"; function oe(t, e = globalThis == null ? void 0 : globalThis.document) { const n = vt(t); R.useEffect(() => { const i = (o) => { o.key === "Escape" && n(o); }; return e.addEventListener("keydown", i, { capture: !0 }), () => e.removeEventListener("keydown", i, { capture: !0 }); }, [n, e]); } var se = "DismissableLayer", pt = "dismissableLayer.update", re = "dismissableLayer.pointerDownOutside", ce = "dismissableLayer.focusOutside", Dt, Vt = R.createContext({ layers: /* @__PURE__ */ new Set(), layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(), branches: /* @__PURE__ */ new Set() }), le = R.forwardRef( (t, e) => { const { disableOutsidePointerEvents: n = !1, onEscapeKeyDown: i, onPointerDownOutside: o, onFocusOutside: s, onInteractOutside: r, onDismiss: c, ...a } = t, l = R.useContext(Vt), [f, u] = R.useState(null), m = (f == null ? void 0 : f.ownerDocument) ?? (globalThis == null ? void 0 : globalThis.document), [, d] = R.useState({}), h = $t(e, (w) => u(w)), g = Array.from(l.layers), [p] = [...l.layersWithOutsidePointerEventsDisabled].slice(-1), y = g.indexOf(p), v = f ? g.indexOf(f) : -1, b = l.layersWithOutsidePointerEventsDisabled.size > 0, E = v >= y, x = ue((w) => { const C = w.target, S = [...l.branches].some((P) => P.contains(C)); !E || S || (o == null || o(w), r == null || r(w), w.defaultPrevented || c == null || c()); }, m), O = de((w) => { const C = w.target; [...l.branches].some((P) => P.contains(C)) || (s == null || s(w), r == null || r(w), w.defaultPrevented || c == null || c()); }, m); return oe((w) => { v === l.layers.size - 1 && (i == null || i(w), !w.defaultPrevented && c && (w.preventDefault(), c())); }, m), R.useEffect(() => { if (f) return n && (l.layersWithOutsidePointerEventsDisabled.size === 0 && (Dt = m.body.style.pointerEvents, m.body.style.pointerEvents = "none"), l.layersWithOutsidePointerEventsDisabled.add(f)), l.layers.add(f), Lt(), () => { n && l.layersWithOutsidePointerEventsDisabled.size === 1 && (m.body.style.pointerEvents = Dt); }; }, [f, m, n, l]), R.useEffect(() => () => { f && (l.layers.delete(f), l.layersWithOutsidePointerEventsDisabled.delete(f), Lt()); }, [f, l]), R.useEffect(() => { const w = () => d({}); return document.addEventListener(pt, w), () => document.removeEventListener(pt, w); }, []), /* @__PURE__ */ _t( Ht.div, { ...a, ref: h, style: { pointerEvents: b ? E ? "auto" : "none" : void 0, ...t.style }, onFocusCapture: mt(t.onFocusCapture, O.onFocusCapture), onBlurCapture: mt(t.onBlurCapture, O.onBlurCapture), onPointerDownCapture: mt( t.onPointerDownCapture, x.onPointerDownCapture ) } ); } ); le.displayName = se; var fe = "DismissableLayerBranch", ae = R.forwardRef((t, e) => { const n = R.useContext(Vt), i = R.useRef(null), o = $t(e, i); return R.useEffect(() => { const s = i.current; if (s) return n.branches.add(s), () => { n.branches.delete(s); }; }, [n.branches]), /* @__PURE__ */ _t(Ht.div, { ...t, ref: o }); }); ae.displayName = fe; function ue(t, e = globalThis == null ? void 0 : globalThis.document) { const n = vt(t), i = R.useRef(!1), o = R.useRef(() => { }); return R.useEffect(() => { const s = (c) => { if (c.target && !i.current) { let a = function() { zt( re, n, l, { discrete: !0 } ); }; const l = { originalEvent: c }; c.pointerType === "touch" ? (e.removeEventListener("click", o.current), o.current = a, e.addEventListener("click", o.current, { once: !0 })) : a(); } else e.removeEventListener("click", o.current); i.current = !1; }, r = window.setTimeout(() => { e.addEventListener("pointerdown", s); }, 0); return () => { window.clearTimeout(r), e.removeEventListener("pointerdown", s), e.removeEventListener("click", o.current); }; }, [e, n]), { // ensures we check React component tree (not just DOM tree) onPointerDownCapture: () => i.current = !0 }; } function de(t, e = globalThis == null ? void 0 : globalThis.document) { const n = vt(t), i = R.useRef(!1); return R.useEffect(() => { const o = (s) => { s.target && !i.current && zt(ce, n, { originalEvent: s }, { discrete: !1 }); }; return e.addEventListener("focusin", o), () => e.removeEventListener("focusin", o); }, [e, n]), { onFocusCapture: () => i.current = !0, onBlurCapture: () => i.current = !1 }; } function Lt() { const t = new CustomEvent(pt); document.dispatchEvent(t); } function zt(t, e, n, { discrete: i }) { const o = n.originalEvent.target, s = new CustomEvent(t, { bubbles: !1, cancelable: !0, detail: n }); e && o.addEventListener(t, e, { once: !0 }), i ? ee(o, s) : o.dispatchEvent(s); } var me = R["useId".toString()] || (() => { }), he = 0; function cn(t) { const [e, n] = R.useState(me()); return ne(() => { t || n((i) => i ?? String(he++)); }, [t]), t || (e ? `radix-${e}` : ""); } const ge = ["top", "right", "bottom", "left"], q = Math.min, B = Math.max, rt = Math.round, ot = Math.floor, _ = (t) => ({ x: t, y: t }), pe = { left: "right", right: "left", bottom: "top", top: "bottom" }, ye = { start: "end", end: "start" }; function yt(t, e, n) { return B(t, q(e, n)); } function j(t, e) { return typeof t == "function" ? t(e) : t; } function U(t) { return t.split("-")[0]; } function Z(t) { return t.split("-")[1]; } function bt(t) { return t === "x" ? "y" : "x"; } function Et(t) { return t === "y" ? "height" : "width"; } function X(t) { return ["top", "bottom"].includes(U(t)) ? "y" : "x"; } function Rt(t) { return bt(X(t)); } function we(t, e, n) { n === void 0 && (n = !1); const i = Z(t), o = Rt(t), s = Et(o); let r = o === "x" ? i === (n ? "end" : "start") ? "right" : "left" : i === "start" ? "bottom" : "top"; return e.reference[s] > e.floating[s] && (r = ct(r)), [r, ct(r)]; } function xe(t) { const e = ct(t); return [wt(t), e, wt(e)]; } function wt(t) { return t.replace(/start|end/g, (e) => ye[e]); } function ve(t, e, n) { const i = ["left", "right"], o = ["right", "left"], s = ["top", "bottom"], r = ["bottom", "top"]; switch (t) { case "top": case "bottom": return n ? e ? o : i : e ? i : o; case "left": case "right": return e ? s : r; default: return []; } } function be(t, e, n, i) { const o = Z(t); let s = ve(U(t), n === "start", i); return o && (s = s.map((r) => r + "-" + o), e && (s = s.concat(s.map(wt)))), s; } function ct(t) { return t.replace(/left|right|bottom|top/g, (e) => pe[e]); } function Ee(t) { return { top: 0, right: 0, bottom: 0, left: 0, ...t }; } function It(t) { return typeof t != "number" ? Ee(t) : { top: t, right: t, bottom: t, left: t }; } function lt(t) { const { x: e, y: n, width: i, height: o } = t; return { width: i, height: o, top: n, left: e, right: e + i, bottom: n + o, x: e, y: n }; } function St(t, e, n) { let { reference: i, floating: o } = t; const s = X(e), r = Rt(e), c = Et(r), a = U(e), l = s === "y", f = i.x + i.width / 2 - o.width / 2, u = i.y + i.height / 2 - o.height / 2, m = i[c] / 2 - o[c] / 2; let d; switch (a) { case "top": d = { x: f, y: i.y - o.height }; break; case "bottom": d = { x: f, y: i.y + i.height }; break; case "right": d = { x: i.x + i.width, y: u }; break; case "left": d = { x: i.x - o.width, y: u }; break; default: d = { x: i.x, y: i.y }; } switch (Z(e)) { case "start": d[r] -= m * (n && l ? -1 : 1); break; case "end": d[r] += m * (n && l ? -1 : 1); break; } return d; } const Re = async (t, e, n) => { const { placement: i = "bottom", strategy: o = "absolute", middleware: s = [], platform: r } = n, c = s.filter(Boolean), a = await (r.isRTL == null ? void 0 : r.isRTL(e)); let l = await r.getElementRects({ reference: t, floating: e, strategy: o }), { x: f, y: u } = St(l, i, a), m = i, d = {}, h = 0; for (let g = 0; g < c.length; g++) { const { name: p, fn: y } = c[g], { x: v, y: b, data: E, reset: x } = await y({ x: f, y: u, initialPlacement: i, placement: m, strategy: o, middlewareData: d, rects: l, platform: r, elements: { reference: t, floating: e } }); f = v ?? f, u = b ?? u, d = { ...d, [p]: { ...d[p], ...E } }, x && h <= 50 && (h++, typeof x == "object" && (x.placement && (m = x.placement), x.rects && (l = x.rects === !0 ? await r.getElementRects({ reference: t, floating: e, strategy: o }) : x.rects), { x: f, y: u } = St(l, m, a)), g = -1); } return { x: f, y: u, placement: m, strategy: o, middlewareData: d }; }; async function et(t, e) { var n; e === void 0 && (e = {}); const { x: i, y: o, platform: s, rects: r, elements: c, strategy: a } = t, { boundary: l = "clippingAncestors", rootBoundary: f = "viewport", elementContext: u = "floating", altBoundary: m = !1, padding: d = 0 } = j(e, t), h = It(d), p = c[m ? u === "floating" ? "reference" : "floating" : u], y = lt(await s.getClippingRect({ element: (n = await (s.isElement == null ? void 0 : s.isElement(p))) == null || n ? p : p.contextElement || await (s.getDocumentElement == null ? void 0 : s.getDocumentElement(c.floating)), boundary: l, rootBoundary: f, strategy: a })), v = u === "floating" ? { x: i, y: o, width: r.floating.width, height: r.floating.height } : r.reference, b = await (s.getOffsetParent == null ? void 0 : s.getOffsetParent(c.floating)), E = await (s.isElement == null ? void 0 : s.isElement(b)) ? await (s.getScale == null ? void 0 : s.getScale(b)) || { x: 1, y: 1 } : { x: 1, y: 1 }, x = lt(s.convertOffsetParentRelativeRectToViewportRelativeRect ? await s.convertOffsetParentRelativeRectToViewportRelativeRect({ elements: c, rect: v, offsetParent: b, strategy: a }) : v); return { top: (y.top - x.top + h.top) / E.y, bottom: (x.bottom - y.bottom + h.bottom) / E.y, left: (y.left - x.left + h.left) / E.x, right: (x.right - y.right + h.right) / E.x }; } const Oe = (t) => ({ name: "arrow", options: t, async fn(e) { const { x: n, y: i, placement: o, rects: s, platform: r, elements: c, middlewareData: a } = e, { element: l, padding: f = 0 } = j(t, e) || {}; if (l == null) return {}; const u = It(f), m = { x: n, y: i }, d = Rt(o), h = Et(d), g = await r.getDimensions(l), p = d === "y", y = p ? "top" : "left", v = p ? "bottom" : "right", b = p ? "clientHeight" : "clientWidth", E = s.reference[h] + s.reference[d] - m[d] - s.floating[h], x = m[d] - s.reference[d], O = await (r.getOffsetParent == null ? void 0 : r.getOffsetParent(l)); let w = O ? O[b] : 0; (!w || !await (r.isElement == null ? void 0 : r.isElement(O))) && (w = c.floating[b] || s.floating[h]); const C = E / 2 - x / 2, S = w / 2 - g[h] / 2 - 1, P = q(u[y], S), N = q(u[v], S), M = P, T = w - g[h] - N, D = w / 2 - g[h] / 2 + C, I = yt(M, D, T), L = !a.arrow && Z(o) != null && D !== I && s.reference[h] / 2 - (D < M ? P : N) - g[h] / 2 < 0, k = L ? D < M ? D - M : D - T : 0; return { [d]: m[d] + k, data: { [d]: I, centerOffset: D - I - k, ...L && { alignmentOffset: k } }, reset: L }; } }), Ae = function(t) { return t === void 0 && (t = {}), { name: "flip", options: t, async fn(e) { var n, i; const { placement: o, middlewareData: s, rects: r, initialPlacement: c, platform: a, elements: l } = e, { mainAxis: f = !0, crossAxis: u = !0, fallbackPlacements: m, fallbackStrategy: d = "bestFit", fallbackAxisSideDirection: h = "none", flipAlignment: g = !0, ...p } = j(t, e); if ((n = s.arrow) != null && n.alignmentOffset) return {}; const y = U(o), v = X(c), b = U(c) === c, E = await (a.isRTL == null ? void 0 : a.isRTL(l.floating)), x = m || (b || !g ? [ct(c)] : xe(c)), O = h !== "none"; !m && O && x.push(...be(c, g, h, E)); const w = [c, ...x], C = await et(e, p), S = []; let P = ((i = s.flip) == null ? void 0 : i.overflows) || []; if (f && S.push(C[y]), u) { const D = we(o, r, E); S.push(C[D[0]], C[D[1]]); } if (P = [...P, { placement: o, overflows: S }], !S.every((D) => D <= 0)) { var N, M; const D = (((N = s.flip) == null ? void 0 : N.index) || 0) + 1, I = w[D]; if (I) return { data: { index: D, overflows: P }, reset: { placement: I } }; let L = (M = P.filter((k) => k.overflows[0] <= 0).sort((k, A) => k.overflows[1] - A.overflows[1])[0]) == null ? void 0 : M.placement; if (!L) switch (d) { case "bestFit": { var T; const k = (T = P.filter((A) => { if (O) { const F = X(A.placement); return F === v || // Create a bias to the `y` side axis due to horizontal // reading directions favoring greater width. F === "y"; } return !0; }).map((A) => [A.placement, A.overflows.filter((F) => F > 0).reduce((F, Y) => F + Y, 0)]).sort((A, F) => A[1] - F[1])[0]) == null ? void 0 : T[0]; k && (L = k); break; } case "initialPlacement": L = c; break; } if (o !== L) return { reset: { placement: L } }; } return {}; } }; }; function Tt(t, e) { return { top: t.top - e.height, right: t.right - e.width, bottom: t.bottom - e.height, left: t.left - e.width }; } function Mt(t) { return ge.some((e) => t[e] >= 0); } const Ce = function(t) { return t === void 0 && (t = {}), { name: "hide", options: t, async fn(e) { const { rects: n } = e, { strategy: i = "referenceHidden", ...o } = j(t, e); switch (i) { case "referenceHidden": { const s = await et(e, { ...o, elementContext: "reference" }), r = Tt(s, n.reference); return { data: { referenceHiddenOffsets: r, referenceHidden: Mt(r) } }; } case "escaped": { const s = await et(e, { ...o, altBoundary: !0 }), r = Tt(s, n.floating); return { data: { escapedOffsets: r, escaped: Mt(r) } }; } default: return {}; } } }; }; async function Pe(t, e) { const { placement: n, platform: i, elements: o } = t, s = await (i.isRTL == null ? void 0 : i.isRTL(o.floating)), r = U(n), c = Z(n), a = X(n) === "y", l = ["left", "top"].includes(r) ? -1 : 1, f = s && a ? -1 : 1, u = j(e, t); let { mainAxis: m, crossAxis: d, alignmentAxis: h } = typeof u == "number" ? { mainAxis: u, crossAxis: 0, alignmentAxis: null } : { mainAxis: u.mainAxis || 0, crossAxis: u.crossAxis || 0, alignmentAxis: u.alignmentAxis }; return c && typeof h == "number" && (d = c === "end" ? h * -1 : h), a ? { x: d * f, y: m * l } : { x: m * l, y: d * f }; } const De = function(t) { return t === void 0 && (t = 0), { name: "offset", options: t, async fn(e) { var n, i; const { x: o, y: s, placement: r, middlewareData: c } = e, a = await Pe(e, t); return r === ((n = c.offset) == null ? void 0 : n.placement) && (i = c.arrow) != null && i.alignmentOffset ? {} : { x: o + a.x, y: s + a.y, data: { ...a, placement: r } }; } }; }, Le = function(t) { return t === void 0 && (t = {}), { name: "shift", options: t, async fn(e) { const { x: n, y: i, placement: o } = e, { mainAxis: s = !0, crossAxis: r = !1, limiter: c = { fn: (p) => { let { x: y, y: v } = p; return { x: y, y: v }; } }, ...a } = j(t, e), l = { x: n, y: i }, f = await et(e, a), u = X(U(o)), m = bt(u); let d = l[m], h = l[u]; if (s) { const p = m === "y" ? "top" : "left", y = m === "y" ? "bottom" : "right", v = d + f[p], b = d - f[y]; d = yt(v, d, b); } if (r) { const p = u === "y" ? "top" : "left", y = u === "y" ? "bottom" : "right", v = h + f[p], b = h - f[y]; h = yt(v, h, b); } const g = c.fn({ ...e, [m]: d, [u]: h }); return { ...g, data: { x: g.x - n, y: g.y - i, enabled: { [m]: s, [u]: r } } }; } }; }, Se = function(t) { return t === void 0 && (t = {}), { options: t, fn(e) { const { x: n, y: i, placement: o, rects: s, middlewareData: r } = e, { offset: c = 0, mainAxis: a = !0, crossAxis: l = !0 } = j(t, e), f = { x: n, y: i }, u = X(o), m = bt(u); let d = f[m], h = f[u]; const g = j(c, e), p = typeof g == "number" ? { mainAxis: g, crossAxis: 0 } : { mainAxis: 0, crossAxis: 0, ...g }; if (a) { const b = m === "y" ? "height" : "width", E = s.reference[m] - s.floating[b] + p.mainAxis, x = s.reference[m] + s.reference[b] - p.mainAxis; d < E ? d = E : d > x && (d = x); } if (l) { var y, v; const b = m === "y" ? "width" : "height", E = ["top", "left"].includes(U(o)), x = s.reference[u] - s.floating[b] + (E && ((y = r.offset) == null ? void 0 : y[u]) || 0) + (E ? 0 : p.crossAxis), O = s.reference[u] + s.reference[b] + (E ? 0 : ((v = r.offset) == null ? void 0 : v[u]) || 0) - (E ? p.crossAxis : 0); h < x ? h = x : h > O && (h = O); } return { [m]: d, [u]: h }; } }; }, Te = function(t) { return t === void 0 && (t = {}), { name: "size", options: t, async fn(e) { var n, i; const { placement: o, rects: s, platform: r, elements: c } = e, { apply: a = () => { }, ...l } = j(t, e), f = await et(e, l), u = U(o), m = Z(o), d = X(o) === "y", { width: h, height: g } = s.floating; let p, y; u === "top" || u === "bottom" ? (p = u, y = m === (await (r.isRTL == null ? void 0 : r.isRTL(c.floating)) ? "start" : "end") ? "left" : "right") : (y = u, p = m === "end" ? "top" : "bottom"); const v = g - f.top - f.bottom, b = h - f.left - f.right, E = q(g - f[p], v), x = q(h - f[y], b), O = !e.middlewareData.shift; let w = E, C = x; if ((n = e.middlewareData.shift) != null && n.enabled.x && (C = b), (i = e.middlewareData.shift) != null && i.enabled.y && (w = v), O && !m) { const P = B(f.left, 0), N = B(f.right, 0), M = B(f.top, 0), T = B(f.bottom, 0); d ? C = h - 2 * (P !== 0 || N !== 0 ? P + N : B(f.left, f.right)) : w = g - 2 * (M !== 0 || T !== 0 ? M + T : B(f.top, f.bottom)); } await a({ ...e, availableWidth: C, availableHeight: w }); const S = await r.getDimensions(c.floating); return h !== S.width || g !== S.height ? { reset: { rects: !0 } } : {}; } }; }; function at() { return typeof window < "u"; } function tt(t) { return jt(t) ? (t.nodeName || "").toLowerCase() : "#document"; } function W(t) { var e; return (t == null || (e = t.ownerDocument) == null ? void 0 : e.defaultView) || window; } function z(t) { var e; return (e = (jt(t) ? t.ownerDocument : t.document) || window.document) == null ? void 0 : e.documentElement; } function jt(t) { return at() ? t instanceof Node || t instanceof W(t).Node : !1; } function $(t) { return at() ? t instanceof Element || t instanceof W(t).Element : !1; } function V(t) { return at() ? t instanceof HTMLElement || t instanceof W(t).HTMLElement : !1; } function kt(t) { return !at() || typeof ShadowRoot > "u" ? !1 : t instanceof ShadowRoot || t instanceof W(t).ShadowRoot; } function it(t) { const { overflow: e, overflowX: n, overflowY: i, display: o } = H(t); return /auto|scroll|overlay|hidden|clip/.test(e + i + n) && !["inline", "contents"].includes(o); } function Me(t) { return ["table", "td", "th"].includes(tt(t)); } function ut(t) { return [":popover-open", ":modal"].some((e) => { try { return t.matches(e); } catch { return !1; } }); } function Ot(t) { const e = At(), n = $(t) ? H(t) : t; return ["transform", "translate", "scale", "rotate", "perspective"].some((i) => n[i] ? n[i] !== "none" : !1) || (n.containerType ? n.containerType !== "normal" : !1) || !e && (n.backdropFilter ? n.backdropFilter !== "none" : !1) || !e && (n.filter ? n.filter !== "none" : !1) || ["transform", "translate", "scale", "rotate", "perspective", "filter"].some((i) => (n.willChange || "").includes(i)) || ["paint", "layout", "strict", "content"].some((i) => (n.contain || "").includes(i)); } function ke(t) { let e = K(t); for (; V(e) && !Q(e); ) { if (Ot(e)) return e; if (ut(e)) return null; e = K(e); } return null; } function At() { return typeof CSS > "u" || !CSS.supports ? !1 : CSS.supports("-webkit-backdrop-filter", "none"); } function Q(t) { return ["html", "body", "#document"].includes(tt(t)); } function H(t) { return W(t).getComputedStyle(t); } function dt(t) { return $(t) ? { scrollLeft: t.scrollLeft, scrollTop: t.scrollTop } : { scrollLeft: t.scrollX, scrollTop: t.scrollY }; } function K(t) { if (tt(t) === "html") return t; const e = ( // Step into the shadow DOM of the parent of a slotted node. t.assignedSlot || // DOM Element detected. t.parentNode || // ShadowRoot detected. kt(t) && t.host || // Fallback. z(t) ); return kt(e) ? e.host : e; } function Ut(t) { const e = K(t); return Q(e) ? t.ownerDocument ? t.ownerDocument.body : t.body : V(e) && it(e) ? e : Ut(e); } function nt(t, e, n) { var i; e === void 0 && (e = []), n === void 0 && (n = !0); const o = Ut(t), s = o === ((i = t.ownerDocument) == null ? void 0 : i.body), r = W(o); if (s) { const c = xt(r); return e.concat(r, r.visualViewport || [], it(o) ? o : [], c && n ? nt(c) : []); } return e.concat(o, nt(o, [], n)); } function xt(t) { return t.parent && Object.getPrototypeOf(t.parent) ? t.frameElement : null; } function Yt(t) { const e = H(t); let n = parseFloat(e.width) || 0, i = parseFloat(e.height) || 0; const o = V(t), s = o ? t.offsetWidth : n, r = o ? t.offsetHeight : i, c = rt(n) !== s || rt(i) !== r; return c && (n = s, i = r), { width: n, height: i, $: c }; } function Ct(t) { return $(t) ? t : t.contextElement; } function J(t) { const e = Ct(t); if (!V(e)) return _(1); const n = e.getBoundingClientRect(), { width: i, height: o, $: s } = Yt(e); let r = (s ? rt(n.width) : n.width) / i, c = (s ? rt(n.height) : n.height) / o; return (!r || !Number.isFinite(r)) && (r = 1), (!c || !Number.isFinite(c)) && (c = 1), { x: r, y: c }; } const Fe = /* @__PURE__ */ _(0); function qt(t) { const e = W(t); return !At() || !e.visualViewport ? Fe : { x: e.visualViewport.offsetLeft, y: e.visualViewport.offsetTop }; } function Be(t, e, n) { return e === void 0 && (e = !1), !n || e && n !== W(t) ? !1 : e; } function G(t, e, n, i) { e === void 0 && (e = !1), n === void 0 && (n = !1); const o = t.getBoundingClientRect(), s = Ct(t); let r = _(1); e && (i ? $(i) && (r = J(i)) : r = J(t)); const c = Be(s, n, i) ? qt(s) : _(0); let a = (o.left + c.x) / r.x, l = (o.top + c.y) / r.y, f = o.width / r.x, u = o.height / r.y; if (s) { const m = W(s), d = i && $(i) ? W(i) : i; let h = m, g = xt(h); for (; g && i && d !== h; ) { const p = J(g), y = g.getBoundingClientRect(), v = H(g), b = y.left + (g.clientLeft + parseFloat(v.paddingLeft)) * p.x, E = y.top + (g.clientTop + parseFloat(v.paddingTop)) * p.y; a *= p.x, l *= p.y, f *= p.x, u *= p.y, a += b, l += E, h = W(g), g = xt(h); } } return lt({ width: f, height: u, x: a, y: l }); } function Pt(t, e) { const n = dt(t).scrollLeft; return e ? e.left + n : G(z(t)).left + n; } function Xt(t, e, n) { n === void 0 && (n = !1); const i = t.getBoundingClientRect(), o = i.left + e.scrollLeft - (n ? 0 : ( // RTL <body> scrollbar. Pt(t, i) )), s = i.top + e.scrollTop; return { x: o, y: s }; } function We(t) { let { elements: e, rect: n, offsetParent: i, strategy: o } = t; const s = o === "fixed", r = z(i), c = e ? ut(e.floating) : !1; if (i === r || c && s) return n; let a = { scrollLeft: 0, scrollTop: 0 }, l = _(1); const f = _(0), u = V(i); if ((u || !u && !s) && ((tt(i) !== "body" || it(r)) && (a = dt(i)), V(i))) { const d = G(i); l = J(i), f.x = d.x + i.clientLeft, f.y = d.y + i.clientTop; } const m = r && !u && !s ? Xt(r, a, !0) : _(0); return { width: n.width * l.x, height: n.height * l.y, x: n.x * l.x - a.scrollLeft * l.x + f.x + m.x, y: n.y * l.y - a.scrollTop * l.y + f.y + m.y }; } function Ne(t) { return Array.from(t.getClientRects()); } function $e(t) { const e = z(t), n = dt(t), i = t.ownerDocument.body, o = B(e.scrollWidth, e.clientWidth, i.scrollWidth, i.clientWidth), s = B(e.scrollHeight, e.clientHeight, i.scrollHeight, i.clientHeight); let r = -n.scrollLeft + Pt(t); const c = -n.scrollTop; return H(i).direction === "rtl" && (r += B(e.clientWidth, i.clientWidth) - o), { width: o, height: s, x: r, y: c }; } function He(t, e) { const n = W(t), i = z(t), o = n.visualViewport; let s = i.clientWidth, r = i.clientHeight, c = 0, a = 0; if (o) { s = o.width, r = o.height; const l = At(); (!l || l && e === "fixed") && (c = o.offsetLeft, a = o.offsetTop); } return { width: s, height: r, x: c, y: a }; } function _e(t, e) { const n = G(t, !0, e === "fixed"), i = n.top + t.clientTop, o = n.left + t.clientLeft, s = V(t) ? J(t) : _(1), r = t.clientWidth * s.x, c = t.clientHeight * s.y, a = o * s.x, l = i * s.y; return { width: r, height: c, x: a, y: l }; } function Ft(t, e, n) { let i; if (e === "viewport") i = He(t, n); else if (e === "document") i = $e(z(t)); else if ($(e)) i = _e(e, n); else { const o = qt(t); i = { x: e.x - o.x, y: e.y - o.y, width: e.width, height: e.height }; } return lt(i); } function Kt(t, e) { const n = K(t); return n === e || !$(n) || Q(n) ? !1 : H(n).position === "fixed" || Kt(n, e); } function Ve(t, e) { const n = e.get(t); if (n) return n; let i = nt(t, [], !1).filter((c) => $(c) && tt(c) !== "body"), o = null; const s = H(t).position === "fixed"; let r = s ? K(t) : t; for (; $(r) && !Q(r); ) { const c = H(r), a = Ot(r); !a && c.position === "fixed" && (o = null), (s ? !a && !o : !a && c.position === "static" && !!o && ["absolute", "fixed"].includes(o.position) || it(r) && !a && Kt(t, r)) ? i = i.filter((f) => f !== r) : o = c, r = K(r); } return e.set(t, i), i; } function ze(t) { let { element: e, boundary: n, rootBoundary: i, strategy: o } = t; const r = [...n === "clippingAncestors" ? ut(e) ? [] : Ve(e, this._c) : [].concat(n), i], c = r[0], a = r.reduce((l, f) => { const u = Ft(e, f, o); return l.top = B(u.top, l.top), l.right = q(u.right, l.right), l.bottom = q(u.bottom, l.bottom), l.left = B(u.left, l.left), l; }, Ft(e, c, o)); return { width: a.right - a.left, height: a.bottom - a.top, x: a.left, y: a.top }; } function Ie(t) { const { width: e, height: n } = Yt(t); return { width: e, height: n }; } function je(t, e, n) { const i = V(e), o = z(e), s = n === "fixed", r = G(t, !0, s, e); let c = { scrollLeft: 0, scrollTop: 0 }; const a = _(0); if (i || !i && !s) if ((tt(e) !== "body" || it(o)) && (c = dt(e)), i) { const m = G(e, !0, s, e); a.x = m.x + e.clientLeft, a.y = m.y + e.clientTop; } else o && (a.x = Pt(o)); const l = o && !i && !s ? Xt(o, c) : _(0), f = r.left + c.scrollLeft - a.x - l.x, u = r.top + c.scrollTop - a.y - l.y; return { x: f, y: u, width: r.width, height: r.height }; } function ht(t) { return H(t).position === "static"; } function Bt(t, e) { if (!V(t) || H(t).position === "fixed") return null; if (e) return e(t); let n = t.offsetParent; return z(t) === n && (n = n.ownerDocument.body), n; } function Gt(t, e) { const n = W(t); if (ut(t)) return n; if (!V(t)) { let o = K(t); for (; o && !Q(o); ) { if ($(o) && !ht(o)) return o; o = K(o); } return n; } let i = Bt(t, e); for (; i && Me(i) && ht(i); ) i = Bt(i, e); return i && Q(i) && ht(i) && !Ot(i) ? n : i || ke(t) || n; } const Ue = async function(t) { const e = this.getOffsetParent || Gt, n = this.getDimensions, i = await n(t.floating); return { reference: je(t.reference, await e(t.floating), t.strategy), floating: { x: 0, y: 0, width: i.width, height: i.height } }; }; function Ye(t) { return H(t).direction === "rtl"; } const qe = { convertOffsetParentRelativeRectToViewportRelativeRect: We, getDocumentElement: z, getClippingRect: ze, getOffsetParent: Gt, getElementRects: Ue, getClientRects: Ne, getDimensions: Ie, getScale: J, isElement: $, isRTL: Ye }; function Jt(t, e) { return t.x === e.x && t.y === e.y && t.width === e.width && t.height === e.height; } function Xe(t, e) { let n = null, i; const o = z(t); function s() { var c; clearTimeout(i), (c = n) == null || c.disconnect(), n = null; } function r(c, a) { c === void 0 && (c = !1), a === void 0 && (a = 1), s(); const l = t.getBoundingClientRect(), { left: f, top: u, width: m, height: d } = l; if (c || e(), !m || !d) return; const h = ot(u), g = ot(o.clientWidth - (f + m)), p = ot(o.clientHeight - (u + d)), y = ot(f), b = { rootMargin: -h + "px " + -g + "px " + -p + "px " + -y + "px", threshold: B(0, q(1, a)) || 1 }; let E = !0; function x(O) { const w = O[0].intersectionRatio; if (w !== a) { if (!E) return r(); w ? r(!1, w) : i = setTimeout(() => { r(!1, 1e-7); }, 1e3); } w === 1 && !Jt(l, t.getBoundingClientRect()) && r(), E = !1; } try { n = new IntersectionObserver(x, { ...b, // Handle <iframe>s root: o.ownerDocument }); } catch { n = new IntersectionObserver(x, b); } n.observe(t); } return r(!0), s; } function ln(t, e, n, i) { i === void 0 && (i = {}); const { ancestorScroll: o = !0, ancestorResize: s = !0, elementResize: r = typeof ResizeObserver == "function", layoutShift: c = typeof IntersectionObserver == "function", animationFrame: a = !1 } = i, l = Ct(t), f = o || s ? [...l ? nt(l) : [], ...nt(e)] : []; f.forEach((y) => { o && y.addEventListener("scroll", n, { passive: !0 }), s && y.addEventListener("resize", n); }); const u = l && c ? Xe(l, n) : null; let m = -1, d = null; r && (d = new ResizeObserver((y) => { let [v] = y; v && v.target === l && d && (d.unobserve(e), cancelAnimationFrame(m), m = requestAnimationFrame(() => { var b; (b = d) == null || b.observe(e); })), n(); }), l && !a && d.observe(l), d.observe(e)); let h, g = a ? G(t) : null; a && p(); function p() { const y = G(t); g && !Jt(g, y) && n(), g = y, h = requestAnimationFrame(p); } return n(), () => { var y; f.forEach((v) => { o && v.removeEventListener("scroll", n), s && v.removeEventListener("resize", n); }), u == null || u(), (y = d) == null || y.disconnect(), d = null, a && cancelAnimationFrame(h); }; } const Ke = De, Ge = Le, Je = Ae, Qe = Te, Ze = Ce, Wt = Oe, tn = Se, en = (t, e, n) => { const i = /* @__PURE__ */ new Map(), o = { platform: qe, ...n }, s = { ...o.platform, _c: i }; return Re(t, e, { ...o, platform: s }); }; var st = typeof document < "u" ? Zt : te; function ft(t, e) { if (t === e) return !0; if (typeof t != typeof e) return !1; if (typeof t == "function" && t.toString() === e.toString()) return !0; let n, i, o; if (t && e && typeof t == "object") { if (Array.isArray(t)) { if (n = t.length, n !== e.length) return !1; for (i = n; i-- !== 0; ) if (!ft(t[i], e[i])) return !1; return !0; } if (o = Object.keys(t), n = o.length, n !== Object.keys(e).length) return !1; for (i = n; i-- !== 0; ) if (!{}.hasOwnProperty.call(e, o[i])) return !1; for (i = n; i-- !== 0; ) { const s = o[i]; if (!(s === "_owner" && t.$$typeof) && !ft(t[s], e[s])) return !1; } return !0; } return t !== t && e !== e; } function Qt(t) { return typeof window > "u" ? 1 : (t.ownerDocument.defaultView || window).devicePixelRatio || 1; } function Nt(t, e) { const n = Qt(t); return Math.round(e * n) / n; } function gt(t) { const e = R.useRef(t); return st(() => { e.current = t; }), e; } function fn(t) { t === void 0 && (t = {}); const { placement: e = "bottom", strategy: n = "absolute", middleware: i = [], platform: o, elements: { reference: s, floating: r } = {}, transform: c = !0, whileElementsMounted: a, open: l } = t, [f, u] = R.useState({ x: 0, y: 0, strategy: n, placement: e, middlewareData: {}, isPositioned: !1 }), [m, d] = R.useState(i); ft(m, i) || d(i); const [h, g] = R.useState(null), [p, y] = R.useState(null), v = R.useCallback((A) => { A !== O.current && (O.current = A, g(A)); }, []), b = R.useCallback((A) => { A !== w.current && (w.current = A, y(A)); }, []), E = s || h, x = r || p, O = R.useRef(null), w = R.useRef(null), C = R.useRef(f), S = a != null, P = gt(a), N = gt(o), M = gt(l), T = R.useCallback(() => { if (!O.current || !w.current) return; const A = { placement: e, strategy: n, middleware: m }; N.current && (A.platform = N.current), en(O.current, w.current, A).then((F) => { const Y = { ...F, // The floating element's position may be recomputed while it's closed // but still mounted (such as when transitioning out). To ensure // `isPositioned` will be `false` initially on the next open, avoid // setting it to `true` when `open === false` (must be specified). isPositioned: M.current !== !1 }; D.current && !ft(C.current, Y) && (C.current = Y, ie.flushSync(() => { u(Y); })); }); }, [m, e, n, N, M]); st(() => { l === !1 && C.current.isPositioned && (C.current.isPositioned = !1, u((A) => ({ ...A, isPositioned: !1 }))); }, [l]); const D = R.useRef(!1); st(() => (D.current = !0, () => { D.current = !1; }), []), st(() => { if (E && (O.current = E), x && (w.current = x), E && x) { if (P.current) return P.current(E, x, T); T(); } }, [E, x, T, P, S]); const I = R.useMemo(() => ({ reference: O, floating: w, setReference: v, setFloating: b }), [v, b]), L = R.useMemo(() => ({ reference: E, floating: x }), [E, x]), k = R.useMemo(() => { const A = { position: n, left: 0, top: 0 }; if (!L.floating) return A; const F = Nt(L.floating, f.x), Y = Nt(L.floating, f.y); return c ? { ...A, transform: "translate(" + F + "px, " + Y + "px)", ...Qt(L.floating) >= 1.5 && { willChange: "transform" } } : { position: n, left: F, top: Y }; }, [n, c, L.floating, f.x, f.y]); return R.useMemo(() => ({ ...f, update: T, refs: I, elements: L, floatingStyles: k }), [f, T, I, L, k]); } const nn = (t) => { function e(n) { return {}.hasOwnProperty.call(n, "current"); } return { name: "arrow", options: t, fn(n) { const { element: i, padding: o } = typeof t == "function" ? t(n) : t; return i && e(i) ? i.current != null ? Wt({ element: i.current, padding: o }).fn(n) : {} : i ? Wt({ element: i, padding: o }).fn(n) : {}; } }; }, an = (t, e) => ({ ...Ke(t), options: [t, e] }), un = (t, e) => ({ ...Ge(t), options: [t, e] }), dn = (t, e) => ({ ...tn(t), options: [t, e] }), mn = (t, e) => ({ ...Je(t), options: [t, e] }), hn = (t, e) => ({ ...Qe(t), options: [t, e] }), gn = (t, e) => ({ ...Ze(t), options: [t, e] }), pn = (t, e) => ({ ...nn(t), options: [t, e] }); export { le as D, ln as a, hn as b, pn as c, cn as d, mn as f, gn as h, dn as l, an as o, un as s, fn as u };