UNPKG

@pdf-viewer/react

Version:

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

308 lines (307 loc) 9.32 kB
import * as s from "react"; import { jsx as S, Fragment as O } from "react/jsx-runtime"; import * as x from "react-dom"; function V(e, t, { checkForDefaultPrevented: n = !0 } = {}) { return function(o) { if (e == null || e(o), n === !1 || !o.defaultPrevented) return t == null ? void 0 : t(o); }; } function P(e, t) { if (typeof e == "function") return e(t); e != null && (e.current = t); } function w(...e) { return (t) => { let n = !1; const r = e.map((o) => { const i = P(o, t); return !n && typeof i == "function" && (n = !0), i; }); if (n) return () => { for (let o = 0; o < r.length; o++) { const i = r[o]; typeof i == "function" ? i() : P(e[o], null); } }; }; } function E(...e) { return s.useCallback(w(...e), e); } function k(e, t) { const n = s.createContext(t), r = (i) => { const { children: c, ...u } = i, a = s.useMemo(() => u, Object.values(u)); return /* @__PURE__ */ S(n.Provider, { value: a, children: c }); }; r.displayName = e + "Provider"; function o(i) { const c = s.useContext(n); if (c) return c; if (t !== void 0) return t; throw new Error(`\`${i}\` must be used within \`${e}\``); } return [r, o]; } function B(e, t = []) { let n = []; function r(i, c) { const u = s.createContext(c), a = n.length; n = [...n, c]; const f = (l) => { var b; const { scope: d, children: m, ...h } = l, v = ((b = d == null ? void 0 : d[e]) == null ? void 0 : b[a]) || u, y = s.useMemo(() => h, Object.values(h)); return /* @__PURE__ */ S(v.Provider, { value: y, children: m }); }; f.displayName = i + "Provider"; function p(l, d) { var v; const m = ((v = d == null ? void 0 : d[e]) == null ? void 0 : v[a]) || u, h = s.useContext(m); if (h) return h; if (c !== void 0) return c; throw new Error(`\`${l}\` must be used within \`${i}\``); } return [f, p]; } const o = () => { const i = n.map((c) => s.createContext(c)); return function(u) { const a = (u == null ? void 0 : u[e]) || i; return s.useMemo( () => ({ [`__scope${e}`]: { ...u, [e]: a } }), [u, a] ); }; }; return o.scopeName = e, [r, M(o, ...t)]; } function M(...e) { const t = e[0]; if (e.length === 1) return t; const n = () => { const r = e.map((o) => ({ useScope: o(), scopeName: o.scopeName })); return function(i) { const c = r.reduce((u, { useScope: a, scopeName: f }) => { const l = a(i)[`__scope${f}`]; return { ...u, ...l }; }, {}); return s.useMemo(() => ({ [`__scope${t.scopeName}`]: c }), [c]); }; }; return n.scopeName = t.scopeName, n; } var A = s.forwardRef((e, t) => { const { children: n, ...r } = e, o = s.Children.toArray(n), i = o.find(U); if (i) { const c = i.props.children, u = o.map((a) => a === i ? s.Children.count(c) > 1 ? s.Children.only(null) : s.isValidElement(c) ? c.props.children : null : a); return /* @__PURE__ */ S(g, { ...r, ref: t, children: s.isValidElement(c) ? s.cloneElement(c, void 0, u) : null }); } return /* @__PURE__ */ S(g, { ...r, ref: t, children: n }); }); A.displayName = "Slot"; var g = s.forwardRef((e, t) => { const { children: n, ...r } = e; if (s.isValidElement(n)) { const o = z(n), i = W(r, n.props); return n.type !== s.Fragment && (i.ref = t ? w(t, o) : o), s.cloneElement(n, i); } return s.Children.count(n) > 1 ? s.Children.only(null) : null; }); g.displayName = "SlotClone"; var T = ({ children: e }) => /* @__PURE__ */ S(O, { children: e }); function U(e) { return s.isValidElement(e) && e.type === T; } function W(e, t) { const n = { ...t }; for (const r in t) { const o = e[r], i = t[r]; /^on[A-Z]/.test(r) ? o && i ? n[r] = (...u) => { i(...u), o(...u); } : o && (n[r] = o) : r === "style" ? n[r] = { ...o, ...i } : r === "className" && (n[r] = [o, i].filter(Boolean).join(" ")); } return { ...e, ...n }; } function z(e) { var r, o; let t = (r = Object.getOwnPropertyDescriptor(e.props, "ref")) == null ? void 0 : r.get, n = t && "isReactWarning" in t && t.isReactWarning; return n ? e.ref : (t = (o = Object.getOwnPropertyDescriptor(e, "ref")) == null ? void 0 : o.get, n = t && "isReactWarning" in t && t.isReactWarning, n ? e.props.ref : e.props.ref || e.ref); } var D = [ "a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "span", "svg", "ul" ], Z = D.reduce((e, t) => { const n = s.forwardRef((r, o) => { const { asChild: i, ...c } = r, u = i ? A : t; return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ S(u, { ...c, ref: o }); }); return n.displayName = `Primitive.${t}`, { ...e, [t]: n }; }, {}); function q(e, t) { e && x.flushSync(() => e.dispatchEvent(t)); } function R(e) { const t = s.useRef(e); return s.useEffect(() => { t.current = e; }), s.useMemo(() => (...n) => { var r; return (r = t.current) == null ? void 0 : r.call(t, ...n); }, []); } var C = globalThis != null && globalThis.document ? s.useLayoutEffect : () => { }; function G(e) { const [t, n] = s.useState(void 0); return C(() => { if (e) { n({ width: e.offsetWidth, height: e.offsetHeight }); const r = new ResizeObserver((o) => { if (!Array.isArray(o) || !o.length) return; const i = o[0]; let c, u; if ("borderBoxSize" in i) { const a = i.borderBoxSize, f = Array.isArray(a) ? a[0] : a; c = f.inlineSize, u = f.blockSize; } else c = e.offsetWidth, u = e.offsetHeight; n({ width: c, height: u }); }); return r.observe(e, { box: "border-box" }), () => r.unobserve(e); } else n(void 0); }, [e]), t; } function I(e, t) { return s.useReducer((n, r) => t[n][r] ?? n, e); } var _ = (e) => { const { present: t, children: n } = e, r = j(t), o = typeof n == "function" ? n({ present: r.isPresent }) : s.Children.only(n), i = E(r.ref, $(o)); return typeof n == "function" || r.isPresent ? s.cloneElement(o, { ref: i }) : null; }; _.displayName = "Presence"; function j(e) { const [t, n] = s.useState(), r = s.useRef({}), o = s.useRef(e), i = s.useRef("none"), c = e ? "mounted" : "unmounted", [u, a] = I(c, { mounted: { UNMOUNT: "unmounted", ANIMATION_OUT: "unmountSuspended" }, unmountSuspended: { MOUNT: "mounted", ANIMATION_END: "unmounted" }, unmounted: { MOUNT: "mounted" } }); return s.useEffect(() => { const f = N(r.current); i.current = u === "mounted" ? f : "none"; }, [u]), C(() => { const f = r.current, p = o.current; if (p !== e) { const d = i.current, m = N(f); e ? a("MOUNT") : m === "none" || (f == null ? void 0 : f.display) === "none" ? a("UNMOUNT") : a(p && d !== m ? "ANIMATION_OUT" : "UNMOUNT"), o.current = e; } }, [e, a]), C(() => { if (t) { let f; const p = t.ownerDocument.defaultView ?? window, l = (m) => { const v = N(r.current).includes(m.animationName); if (m.target === t && v && (a("ANIMATION_END"), !o.current)) { const y = t.style.animationFillMode; t.style.animationFillMode = "forwards", f = p.setTimeout(() => { t.style.animationFillMode === "forwards" && (t.style.animationFillMode = y); }); } }, d = (m) => { m.target === t && (i.current = N(r.current)); }; return t.addEventListener("animationstart", d), t.addEventListener("animationcancel", l), t.addEventListener("animationend", l), () => { p.clearTimeout(f), t.removeEventListener("animationstart", d), t.removeEventListener("animationcancel", l), t.removeEventListener("animationend", l); }; } else a("ANIMATION_END"); }, [t, a]), { isPresent: ["mounted", "unmountSuspended"].includes(u), ref: s.useCallback((f) => { f && (r.current = getComputedStyle(f)), n(f); }, []) }; } function N(e) { return (e == null ? void 0 : e.animationName) || "none"; } function $(e) { var r, o; let t = (r = Object.getOwnPropertyDescriptor(e.props, "ref")) == null ? void 0 : r.get, n = t && "isReactWarning" in t && t.isReactWarning; return n ? e.ref : (t = (o = Object.getOwnPropertyDescriptor(e, "ref")) == null ? void 0 : o.get, n = t && "isReactWarning" in t && t.isReactWarning, n ? e.props.ref : e.props.ref || e.ref); } function J({ prop: e, defaultProp: t, onChange: n = () => { } }) { const [r, o] = L({ defaultProp: t, onChange: n }), i = e !== void 0, c = i ? e : r, u = R(n), a = s.useCallback( (f) => { if (i) { const l = typeof f == "function" ? f(e) : f; l !== e && u(l); } else o(f); }, [i, e, o, u] ); return [c, a]; } function L({ defaultProp: e, onChange: t }) { const n = s.useState(e), [r] = n, o = s.useRef(r), i = R(t); return s.useEffect(() => { o.current !== r && (i(r), o.current = r); }, [r, o, i]), n; } export { Z as P, T as S, J as a, V as b, B as c, _ as d, G as e, R as f, q as g, C as h, A as i, w as j, k, E as u };