@pdf-viewer/react
Version:
A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.
333 lines (332 loc) • 10.3 kB
JavaScript
import * as s from "react";
import { jsx as v, Fragment as A } from "react/jsx-runtime";
import * as E from "react-dom";
function k(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 C(e, t) {
if (typeof e == "function")
return e(t);
e != null && (e.current = t);
}
function P(...e) {
return (t) => {
let n = !1;
const o = e.map((r) => {
const i = C(r, t);
return !n && typeof i == "function" && (n = !0), i;
});
if (n)
return () => {
for (let r = 0; r < o.length; r++) {
const i = o[r];
typeof i == "function" ? i() : C(e[r], null);
}
};
};
}
function x(...e) {
return s.useCallback(P(...e), e);
}
function B(e, t) {
const n = s.createContext(t), o = (i) => {
const { children: u, ...c } = i, a = s.useMemo(() => c, Object.values(c));
return /* @__PURE__ */ v(n.Provider, { value: a, children: u });
};
o.displayName = e + "Provider";
function r(i) {
const u = s.useContext(n);
if (u)
return u;
if (t !== void 0)
return t;
throw new Error(`\`${i}\` must be used within \`${e}\``);
}
return [o, r];
}
function Z(e, t = []) {
let n = [];
function o(i, u) {
const c = s.createContext(u), a = n.length;
n = [...n, u];
const l = (f) => {
var g;
const { scope: m, children: p, ...h } = f, S = ((g = m == null ? void 0 : m[e]) == null ? void 0 : g[a]) || c, b = s.useMemo(() => h, Object.values(h));
return /* @__PURE__ */ v(S.Provider, { value: b, children: p });
};
l.displayName = i + "Provider";
function d(f, m) {
var S;
const p = ((S = m == null ? void 0 : m[e]) == null ? void 0 : S[a]) || c, h = s.useContext(p);
if (h)
return h;
if (u !== void 0)
return u;
throw new Error(`\`${f}\` must be used within \`${i}\``);
}
return [l, d];
}
const r = () => {
const i = n.map((u) => s.createContext(u));
return function(c) {
const a = (c == null ? void 0 : c[e]) || i;
return s.useMemo(
() => ({ [`__scope${e}`]: { ...c, [e]: a } }),
[c, a]
);
};
};
return r.scopeName = e, [o, R(r, ...t)];
}
function R(...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(i) {
const u = o.reduce((c, { useScope: a, scopeName: l }) => {
const f = a(i)[`__scope${l}`];
return { ...c, ...f };
}, {});
return s.useMemo(() => ({ [`__scope${t.scopeName}`]: u }), [u]);
};
};
return n.scopeName = t.scopeName, n;
}
// @__NO_SIDE_EFFECTS__
function O(e) {
const t = /* @__PURE__ */ M(e), n = s.forwardRef((o, r) => {
const { children: i, ...u } = o, c = s.Children.toArray(i), a = c.find(I);
if (a) {
const l = a.props.children, d = c.map((f) => f === a ? s.Children.count(l) > 1 ? s.Children.only(null) : s.isValidElement(l) ? l.props.children : null : f);
return /* @__PURE__ */ v(t, { ...u, ref: r, children: s.isValidElement(l) ? s.cloneElement(l, void 0, d) : null });
}
return /* @__PURE__ */ v(t, { ...u, ref: r, children: i });
});
return n.displayName = `${e}.Slot`, n;
}
// @__NO_SIDE_EFFECTS__
function M(e) {
const t = s.forwardRef((n, o) => {
const { children: r, ...i } = n;
if (s.isValidElement(r)) {
const u = _(r), c = T(i, r.props);
return r.type !== s.Fragment && (c.ref = o ? P(o, u) : u), s.cloneElement(r, c);
}
return s.Children.count(r) > 1 ? s.Children.only(null) : null;
});
return t.displayName = `${e}.SlotClone`, t;
}
var w = Symbol("radix.slottable");
// @__NO_SIDE_EFFECTS__
function q(e) {
const t = ({ children: n }) => /* @__PURE__ */ v(A, { children: n });
return t.displayName = `${e}.Slottable`, t.__radixId = w, t;
}
function I(e) {
return s.isValidElement(e) && typeof e.type == "function" && "__radixId" in e.type && e.type.__radixId === w;
}
function T(e, t) {
const n = { ...t };
for (const o in t) {
const r = e[o], i = t[o];
/^on[A-Z]/.test(o) ? r && i ? n[o] = (...c) => {
const a = i(...c);
return r(...c), a;
} : r && (n[o] = r) : o === "style" ? n[o] = { ...r, ...i } : o === "className" && (n[o] = [r, i].filter(Boolean).join(" "));
}
return { ...e, ...n };
}
function _(e) {
var o, r;
let t = (o = Object.getOwnPropertyDescriptor(e.props, "ref")) == null ? void 0 : o.get, n = t && "isReactWarning" in t && t.isReactWarning;
return n ? e.ref : (t = (r = Object.getOwnPropertyDescriptor(e, "ref")) == null ? void 0 : r.get, n = t && "isReactWarning" in t && t.isReactWarning, n ? e.props.ref : e.props.ref || e.ref);
}
var $ = [
"a",
"button",
"div",
"form",
"h2",
"h3",
"img",
"input",
"label",
"li",
"nav",
"ol",
"p",
"select",
"span",
"svg",
"ul"
], G = $.reduce((e, t) => {
const n = /* @__PURE__ */ O(`Primitive.${t}`), o = s.forwardRef((r, i) => {
const { asChild: u, ...c } = r, a = u ? n : t;
return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ v(a, { ...c, ref: i });
});
return o.displayName = `Primitive.${t}`, { ...e, [t]: o };
}, {});
function J(e, t) {
e && E.flushSync(() => e.dispatchEvent(t));
}
var N = globalThis != null && globalThis.document ? s.useLayoutEffect : () => {
};
function K(e) {
const [t, n] = s.useState(void 0);
return N(() => {
if (e) {
n({ width: e.offsetWidth, height: e.offsetHeight });
const o = new ResizeObserver((r) => {
if (!Array.isArray(r) || !r.length)
return;
const i = r[0];
let u, c;
if ("borderBoxSize" in i) {
const a = i.borderBoxSize, l = Array.isArray(a) ? a[0] : a;
u = l.inlineSize, c = l.blockSize;
} else
u = e.offsetWidth, c = e.offsetHeight;
n({ width: u, height: c });
});
return o.observe(e, { box: "border-box" }), () => o.unobserve(e);
} else
n(void 0);
}, [e]), t;
}
function D(e, t) {
return s.useReducer((n, o) => t[n][o] ?? n, e);
}
var U = (e) => {
const { present: t, children: n } = e, o = W(t), r = typeof n == "function" ? n({ present: o.isPresent }) : s.Children.only(n), i = x(o.ref, z(r));
return typeof n == "function" || o.isPresent ? s.cloneElement(r, { ref: i }) : null;
};
U.displayName = "Presence";
function W(e) {
const [t, n] = s.useState(), o = s.useRef(null), r = s.useRef(e), i = s.useRef("none"), u = e ? "mounted" : "unmounted", [c, a] = D(u, {
mounted: {
UNMOUNT: "unmounted",
ANIMATION_OUT: "unmountSuspended"
},
unmountSuspended: {
MOUNT: "mounted",
ANIMATION_END: "unmounted"
},
unmounted: {
MOUNT: "mounted"
}
});
return s.useEffect(() => {
const l = y(o.current);
i.current = c === "mounted" ? l : "none";
}, [c]), N(() => {
const l = o.current, d = r.current;
if (d !== e) {
const m = i.current, p = y(l);
e ? a("MOUNT") : p === "none" || (l == null ? void 0 : l.display) === "none" ? a("UNMOUNT") : a(d && m !== p ? "ANIMATION_OUT" : "UNMOUNT"), r.current = e;
}
}, [e, a]), N(() => {
if (t) {
let l;
const d = t.ownerDocument.defaultView ?? window, f = (p) => {
const S = y(o.current).includes(p.animationName);
if (p.target === t && S && (a("ANIMATION_END"), !r.current)) {
const b = t.style.animationFillMode;
t.style.animationFillMode = "forwards", l = d.setTimeout(() => {
t.style.animationFillMode === "forwards" && (t.style.animationFillMode = b);
});
}
}, m = (p) => {
p.target === t && (i.current = y(o.current));
};
return t.addEventListener("animationstart", m), t.addEventListener("animationcancel", f), t.addEventListener("animationend", f), () => {
d.clearTimeout(l), t.removeEventListener("animationstart", m), t.removeEventListener("animationcancel", f), t.removeEventListener("animationend", f);
};
} else
a("ANIMATION_END");
}, [t, a]), {
isPresent: ["mounted", "unmountSuspended"].includes(c),
ref: s.useCallback((l) => {
o.current = l ? getComputedStyle(l) : null, n(l);
}, [])
};
}
function y(e) {
return (e == null ? void 0 : e.animationName) || "none";
}
function z(e) {
var o, r;
let t = (o = Object.getOwnPropertyDescriptor(e.props, "ref")) == null ? void 0 : o.get, n = t && "isReactWarning" in t && t.isReactWarning;
return n ? e.ref : (t = (r = Object.getOwnPropertyDescriptor(e, "ref")) == null ? void 0 : r.get, n = t && "isReactWarning" in t && t.isReactWarning, n ? e.props.ref : e.props.ref || e.ref);
}
var L = s[" useInsertionEffect ".trim().toString()] || N;
function Q({
prop: e,
defaultProp: t,
onChange: n = () => {
},
caller: o
}) {
const [r, i, u] = j({
defaultProp: t,
onChange: n
}), c = e !== void 0, a = c ? e : r;
{
const d = s.useRef(e !== void 0);
s.useEffect(() => {
const f = d.current;
f !== c && console.warn(
`${o} is changing from ${f ? "controlled" : "uncontrolled"} to ${c ? "controlled" : "uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`
), d.current = c;
}, [c, o]);
}
const l = s.useCallback(
(d) => {
var f;
if (c) {
const m = F(d) ? d(e) : d;
m !== e && ((f = u.current) == null || f.call(u, m));
} else
i(d);
},
[c, e, i, u]
);
return [a, l];
}
function j({
defaultProp: e,
onChange: t
}) {
const [n, o] = s.useState(e), r = s.useRef(n), i = s.useRef(t);
return L(() => {
i.current = t;
}, [t]), s.useEffect(() => {
var u;
r.current !== n && ((u = i.current) == null || u.call(i, n), r.current = n);
}, [n, r]), [n, o, i];
}
function F(e) {
return typeof e == "function";
}
export {
G as P,
k as a,
U as b,
Z as c,
K as d,
Q as e,
J as f,
N as g,
q as h,
O as i,
P as j,
B as k,
x as u
};