@pdf-viewer/react
Version:
A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.
570 lines (569 loc) • 19.9 kB
JavaScript
import { jsx as d, jsxs as Y } from "react/jsx-runtime";
import * as a from "react";
import { forwardRef as Fe } from "react";
import { P as N, c as ae, u as k, d as We, g as re, e as Be, a as E, b as Ge, h as Xe } from "../../index-6e0e48fa.js";
import { u as Ve, a as Ue, D as ze } from "../../index-e3a67935.js";
import { u as qe, a as Ze, o as Ke, s as Je, f as Qe, b as et, c as tt, h as ot, l as rt } from "../../floating-ui.react-dom-4b1e2e46.js";
import '../../assets/RPTooltip.css';var nt = "Arrow", se = a.forwardRef((e, o) => {
const { children: t, width: r = 10, height: n = 5, ...s } = e;
return /* @__PURE__ */ d(
N.svg,
{
...s,
ref: o,
width: r,
height: n,
viewBox: "0 0 30 10",
preserveAspectRatio: "none",
children: e.asChild ? t : /* @__PURE__ */ d("polygon", { points: "0,0 30,0 15,10" })
}
);
});
se.displayName = nt;
var at = se, B = "Popper", [ie, le] = ae(B), [st, ce] = ie(B), de = (e) => {
const { __scopePopper: o, children: t } = e, [r, n] = a.useState(null);
return /* @__PURE__ */ d(st, { scope: o, anchor: r, onAnchorChange: n, children: t });
};
de.displayName = B;
var pe = "PopperAnchor", ue = a.forwardRef(
(e, o) => {
const { __scopePopper: t, virtualRef: r, ...n } = e, s = ce(pe, t), i = a.useRef(null), h = k(o, i);
return a.useEffect(() => {
s.onAnchorChange((r == null ? void 0 : r.current) || i.current);
}), r ? null : /* @__PURE__ */ d(N.div, { ...n, ref: h });
}
);
ue.displayName = pe;
var G = "PopperContent", [it, lt] = ie(G), fe = a.forwardRef(
(e, o) => {
var Z, K, J, Q, ee, te;
const {
__scopePopper: t,
side: r = "bottom",
sideOffset: n = 0,
align: s = "center",
alignOffset: i = 0,
arrowPadding: h = 0,
avoidCollisions: l = !0,
collisionBoundary: p = [],
collisionPadding: c = 0,
sticky: f = "partial",
hideWhenDetached: g = !1,
updatePositionStrategy: u = "optimized",
onPlaced: v,
...y
} = e, m = ce(G, t), [w, x] = a.useState(null), T = k(o, (_) => x(_)), [C, b] = a.useState(null), P = We(C), S = (P == null ? void 0 : P.width) ?? 0, V = (P == null ? void 0 : P.height) ?? 0, Ee = r + (s !== "center" ? "-" + s : ""), Re = typeof c == "number" ? c : { top: 0, right: 0, bottom: 0, left: 0, ...c }, U = Array.isArray(p) ? p : [p], _e = U.length > 0, D = {
padding: Re,
boundary: U.filter(dt),
// with `strategy: 'fixed'`, this is the only way to get it to respect boundaries
altBoundary: _e
}, { refs: Oe, floatingStyles: z, placement: Ne, isPositioned: H, middlewareData: A } = qe({
// default to `fixed` strategy so users don't have to pick and we also avoid focus scroll issues
strategy: "fixed",
placement: Ee,
whileElementsMounted: (..._) => Ze(..._, {
animationFrame: u === "always"
}),
elements: {
reference: m.anchor
},
middleware: [
Ke({ mainAxis: n + V, alignmentAxis: i }),
l && Je({
mainAxis: !0,
crossAxis: !1,
limiter: f === "partial" ? rt() : void 0,
...D
}),
l && Qe({ ...D }),
et({
...D,
apply: ({ elements: _, rects: oe, availableWidth: Me, availableHeight: $e }) => {
const { width: je, height: Ye } = oe.reference, L = _.floating.style;
L.setProperty("--radix-popper-available-width", `${Me}px`), L.setProperty("--radix-popper-available-height", `${$e}px`), L.setProperty("--radix-popper-anchor-width", `${je}px`), L.setProperty("--radix-popper-anchor-height", `${Ye}px`);
}
}),
C && tt({ element: C, padding: h }),
pt({ arrowWidth: S, arrowHeight: V }),
g && ot({ strategy: "referenceHidden", ...D })
]
}), [q, Se] = ge(Ne), I = Ve(v);
re(() => {
H && (I == null || I());
}, [H, I]);
const De = (Z = A.arrow) == null ? void 0 : Z.x, He = (K = A.arrow) == null ? void 0 : K.y, Ie = ((J = A.arrow) == null ? void 0 : J.centerOffset) !== 0, [Le, ke] = a.useState();
return re(() => {
w && ke(window.getComputedStyle(w).zIndex);
}, [w]), /* @__PURE__ */ d(
"div",
{
ref: Oe.setFloating,
"data-radix-popper-content-wrapper": "",
style: {
...z,
transform: H ? z.transform : "translate(0, -200%)",
// keep off the page when measuring
minWidth: "max-content",
zIndex: Le,
"--radix-popper-transform-origin": [
(Q = A.transformOrigin) == null ? void 0 : Q.x,
(ee = A.transformOrigin) == null ? void 0 : ee.y
].join(" "),
// hide the content if using the hide middleware and should be hidden
// set visibility to hidden and disable pointer events so the UI behaves
// as if the PopperContent isn't there at all
...((te = A.hide) == null ? void 0 : te.referenceHidden) && {
visibility: "hidden",
pointerEvents: "none"
}
},
dir: e.dir,
children: /* @__PURE__ */ d(
it,
{
scope: t,
placedSide: q,
onArrowChange: b,
arrowX: De,
arrowY: He,
shouldHideArrow: Ie,
children: /* @__PURE__ */ d(
N.div,
{
"data-side": q,
"data-align": Se,
...y,
ref: T,
style: {
...y.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: H ? void 0 : "none"
}
}
)
}
)
}
);
}
);
fe.displayName = G;
var he = "PopperArrow", ct = {
top: "bottom",
right: "left",
bottom: "top",
left: "right"
}, ve = a.forwardRef(function(o, t) {
const { __scopePopper: r, ...n } = o, s = lt(he, r), i = ct[s.placedSide];
return (
// we have to use an extra wrapper because `ResizeObserver` (used by `useSize`)
// doesn't report size as we'd expect on SVG elements.
// it reports their bounding box which is effectively the largest path inside the SVG.
/* @__PURE__ */ d(
"span",
{
ref: s.onArrowChange,
style: {
position: "absolute",
left: s.arrowX,
top: s.arrowY,
[i]: 0,
transformOrigin: {
top: "",
right: "0 0",
bottom: "center 0",
left: "100% 0"
}[s.placedSide],
transform: {
top: "translateY(100%)",
right: "translateY(50%) rotate(90deg) translateX(-50%)",
bottom: "rotate(180deg)",
left: "translateY(50%) rotate(-90deg) translateX(50%)"
}[s.placedSide],
visibility: s.shouldHideArrow ? "hidden" : void 0
},
children: /* @__PURE__ */ d(
at,
{
...n,
ref: t,
style: {
...n.style,
// ensures the element can be measured correctly (mostly for if SVG)
display: "block"
}
}
)
}
)
);
});
ve.displayName = he;
function dt(e) {
return e !== null;
}
var pt = (e) => ({
name: "transformOrigin",
options: e,
fn(o) {
var m, w, x;
const { placement: t, rects: r, middlewareData: n } = o, i = ((m = n.arrow) == null ? void 0 : m.centerOffset) !== 0, h = i ? 0 : e.arrowWidth, l = i ? 0 : e.arrowHeight, [p, c] = ge(t), f = { start: "0%", center: "50%", end: "100%" }[c], g = (((w = n.arrow) == null ? void 0 : w.x) ?? 0) + h / 2, u = (((x = n.arrow) == null ? void 0 : x.y) ?? 0) + l / 2;
let v = "", y = "";
return p === "bottom" ? (v = i ? f : `${g}px`, y = `${-l}px`) : p === "top" ? (v = i ? f : `${g}px`, y = `${r.floating.height + l}px`) : p === "right" ? (v = `${-l}px`, y = i ? f : `${u}px`) : p === "left" && (v = `${r.floating.width + l}px`, y = i ? f : `${u}px`), { data: { x: v, y } };
}
});
function ge(e) {
const [o, t = "center"] = e.split("-");
return [o, t];
}
var ut = de, ft = ue, ht = fe, vt = ve, gt = Object.freeze({
// See: https://github.com/twbs/bootstrap/blob/main/scss/mixins/_visually-hidden.scss
position: "absolute",
border: 0,
width: 1,
height: 1,
padding: 0,
margin: -1,
overflow: "hidden",
clip: "rect(0, 0, 0, 0)",
whiteSpace: "nowrap",
wordWrap: "normal"
}), yt = "VisuallyHidden", ye = a.forwardRef(
(e, o) => /* @__PURE__ */ d(
N.span,
{
...e,
ref: o,
style: { ...gt, ...e.style }
}
)
);
ye.displayName = yt;
var mt = ye, [M, Bt] = ae("Tooltip", [
le
]), $ = le(), me = "TooltipProvider", wt = 700, F = "tooltip.open", [xt, X] = M(me), we = (e) => {
const {
__scopeTooltip: o,
delayDuration: t = wt,
skipDelayDuration: r = 300,
disableHoverableContent: n = !1,
children: s
} = e, i = a.useRef(!0), h = a.useRef(!1), l = a.useRef(0);
return a.useEffect(() => {
const p = l.current;
return () => window.clearTimeout(p);
}, []), /* @__PURE__ */ d(
xt,
{
scope: o,
isOpenDelayedRef: i,
delayDuration: t,
onOpen: a.useCallback(() => {
window.clearTimeout(l.current), i.current = !1;
}, []),
onClose: a.useCallback(() => {
window.clearTimeout(l.current), l.current = window.setTimeout(
() => i.current = !0,
r
);
}, [r]),
isPointerInTransitRef: h,
onPointerInTransitChange: a.useCallback((p) => {
h.current = p;
}, []),
disableHoverableContent: n,
children: s
}
);
};
we.displayName = me;
var O = "Tooltip", [Ct, j] = M(O), xe = (e) => {
const {
__scopeTooltip: o,
children: t,
open: r,
defaultOpen: n,
onOpenChange: s,
disableHoverableContent: i,
delayDuration: h
} = e, l = X(O, e.__scopeTooltip), p = $(o), [c, f] = a.useState(null), g = Ue(), u = a.useRef(0), v = i ?? l.disableHoverableContent, y = h ?? l.delayDuration, m = a.useRef(!1), [w, x] = Be({
prop: r,
defaultProp: n ?? !1,
onChange: (S) => {
S ? (l.onOpen(), document.dispatchEvent(new CustomEvent(F))) : l.onClose(), s == null || s(S);
},
caller: O
}), T = a.useMemo(() => w ? m.current ? "delayed-open" : "instant-open" : "closed", [w]), C = a.useCallback(() => {
window.clearTimeout(u.current), u.current = 0, m.current = !1, x(!0);
}, [x]), b = a.useCallback(() => {
window.clearTimeout(u.current), u.current = 0, x(!1);
}, [x]), P = a.useCallback(() => {
window.clearTimeout(u.current), u.current = window.setTimeout(() => {
m.current = !0, x(!0), u.current = 0;
}, y);
}, [y, x]);
return a.useEffect(() => () => {
u.current && (window.clearTimeout(u.current), u.current = 0);
}, []), /* @__PURE__ */ d(ut, { ...p, children: /* @__PURE__ */ d(
Ct,
{
scope: o,
contentId: g,
open: w,
stateAttribute: T,
trigger: c,
onTriggerChange: f,
onTriggerEnter: a.useCallback(() => {
l.isOpenDelayedRef.current ? P() : C();
}, [l.isOpenDelayedRef, P, C]),
onTriggerLeave: a.useCallback(() => {
v ? b() : (window.clearTimeout(u.current), u.current = 0);
}, [b, v]),
onOpen: C,
onClose: b,
disableHoverableContent: v,
children: t
}
) });
};
xe.displayName = O;
var W = "TooltipTrigger", Ce = a.forwardRef(
(e, o) => {
const { __scopeTooltip: t, ...r } = e, n = j(W, t), s = X(W, t), i = $(t), h = a.useRef(null), l = k(o, h, n.onTriggerChange), p = a.useRef(!1), c = a.useRef(!1), f = a.useCallback(() => p.current = !1, []);
return a.useEffect(() => () => document.removeEventListener("pointerup", f), [f]), /* @__PURE__ */ d(ft, { asChild: !0, ...i, children: /* @__PURE__ */ d(
N.button,
{
"aria-describedby": n.open ? n.contentId : void 0,
"data-state": n.stateAttribute,
...r,
ref: l,
onPointerMove: E(e.onPointerMove, (g) => {
g.pointerType !== "touch" && !c.current && !s.isPointerInTransitRef.current && (n.onTriggerEnter(), c.current = !0);
}),
onPointerLeave: E(e.onPointerLeave, () => {
n.onTriggerLeave(), c.current = !1;
}),
onPointerDown: E(e.onPointerDown, () => {
n.open && n.onClose(), p.current = !0, document.addEventListener("pointerup", f, { once: !0 });
}),
onFocus: E(e.onFocus, () => {
p.current || n.onOpen();
}),
onBlur: E(e.onBlur, n.onClose),
onClick: E(e.onClick, n.onClose)
}
) });
}
);
Ce.displayName = W;
var Pt = "TooltipPortal", [Gt, Tt] = M(Pt, {
forceMount: void 0
}), R = "TooltipContent", Pe = a.forwardRef(
(e, o) => {
const t = Tt(R, e.__scopeTooltip), { forceMount: r = t.forceMount, side: n = "top", ...s } = e, i = j(R, e.__scopeTooltip);
return /* @__PURE__ */ d(Ge, { present: r || i.open, children: i.disableHoverableContent ? /* @__PURE__ */ d(Te, { side: n, ...s, ref: o }) : /* @__PURE__ */ d(bt, { side: n, ...s, ref: o }) });
}
), bt = a.forwardRef((e, o) => {
const t = j(R, e.__scopeTooltip), r = X(R, e.__scopeTooltip), n = a.useRef(null), s = k(o, n), [i, h] = a.useState(null), { trigger: l, onClose: p } = t, c = n.current, { onPointerInTransitChange: f } = r, g = a.useCallback(() => {
h(null), f(!1);
}, [f]), u = a.useCallback(
(v, y) => {
const m = v.currentTarget, w = { x: v.clientX, y: v.clientY }, x = _t(w, m.getBoundingClientRect()), T = Ot(w, x), C = Nt(y.getBoundingClientRect()), b = Dt([...T, ...C]);
h(b), f(!0);
},
[f]
);
return a.useEffect(() => () => g(), [g]), a.useEffect(() => {
if (l && c) {
const v = (m) => u(m, c), y = (m) => u(m, l);
return l.addEventListener("pointerleave", v), c.addEventListener("pointerleave", y), () => {
l.removeEventListener("pointerleave", v), c.removeEventListener("pointerleave", y);
};
}
}, [l, c, u, g]), a.useEffect(() => {
if (i) {
const v = (y) => {
const m = y.target, w = { x: y.clientX, y: y.clientY }, x = (l == null ? void 0 : l.contains(m)) || (c == null ? void 0 : c.contains(m)), T = !St(w, i);
x ? g() : T && (g(), p());
};
return document.addEventListener("pointermove", v), () => document.removeEventListener("pointermove", v);
}
}, [l, c, i, p, g]), /* @__PURE__ */ d(Te, { ...e, ref: s });
}), [At, Et] = M(O, { isInside: !1 }), Rt = Xe("TooltipContent"), Te = a.forwardRef(
(e, o) => {
const {
__scopeTooltip: t,
children: r,
"aria-label": n,
onEscapeKeyDown: s,
onPointerDownOutside: i,
...h
} = e, l = j(R, t), p = $(t), { onClose: c } = l;
return a.useEffect(() => (document.addEventListener(F, c), () => document.removeEventListener(F, c)), [c]), a.useEffect(() => {
if (l.trigger) {
const f = (g) => {
const u = g.target;
u != null && u.contains(l.trigger) && c();
};
return window.addEventListener("scroll", f, { capture: !0 }), () => window.removeEventListener("scroll", f, { capture: !0 });
}
}, [l.trigger, c]), /* @__PURE__ */ d(
ze,
{
asChild: !0,
disableOutsidePointerEvents: !1,
onEscapeKeyDown: s,
onPointerDownOutside: i,
onFocusOutside: (f) => f.preventDefault(),
onDismiss: c,
children: /* @__PURE__ */ Y(
ht,
{
"data-state": l.stateAttribute,
...p,
...h,
ref: o,
style: {
...h.style,
"--radix-tooltip-content-transform-origin": "var(--radix-popper-transform-origin)",
"--radix-tooltip-content-available-width": "var(--radix-popper-available-width)",
"--radix-tooltip-content-available-height": "var(--radix-popper-available-height)",
"--radix-tooltip-trigger-width": "var(--radix-popper-anchor-width)",
"--radix-tooltip-trigger-height": "var(--radix-popper-anchor-height)"
},
children: [
/* @__PURE__ */ d(Rt, { children: r }),
/* @__PURE__ */ d(At, { scope: t, isInside: !0, children: /* @__PURE__ */ d(mt, { id: l.contentId, role: "tooltip", children: n || r }) })
]
}
)
}
);
}
);
Pe.displayName = R;
var be = "TooltipArrow", Ae = a.forwardRef(
(e, o) => {
const { __scopeTooltip: t, ...r } = e, n = $(t);
return Et(
be,
t
).isInside ? null : /* @__PURE__ */ d(vt, { ...n, ...r, ref: o });
}
);
Ae.displayName = be;
function _t(e, o) {
const t = Math.abs(o.top - e.y), r = Math.abs(o.bottom - e.y), n = Math.abs(o.right - e.x), s = Math.abs(o.left - e.x);
switch (Math.min(t, r, n, s)) {
case s:
return "left";
case n:
return "right";
case t:
return "top";
case r:
return "bottom";
default:
throw new Error("unreachable");
}
}
function Ot(e, o, t = 5) {
const r = [];
switch (o) {
case "top":
r.push(
{ x: e.x - t, y: e.y + t },
{ x: e.x + t, y: e.y + t }
);
break;
case "bottom":
r.push(
{ x: e.x - t, y: e.y - t },
{ x: e.x + t, y: e.y - t }
);
break;
case "left":
r.push(
{ x: e.x + t, y: e.y - t },
{ x: e.x + t, y: e.y + t }
);
break;
case "right":
r.push(
{ x: e.x - t, y: e.y - t },
{ x: e.x - t, y: e.y + t }
);
break;
}
return r;
}
function Nt(e) {
const { top: o, right: t, bottom: r, left: n } = e;
return [
{ x: n, y: o },
{ x: t, y: o },
{ x: t, y: r },
{ x: n, y: r }
];
}
function St(e, o) {
const { x: t, y: r } = e;
let n = !1;
for (let s = 0, i = o.length - 1; s < o.length; i = s++) {
const h = o[s], l = o[i], p = h.x, c = h.y, f = l.x, g = l.y;
c > r != g > r && t < (f - p) * (r - c) / (g - c) + p && (n = !n);
}
return n;
}
function Dt(e) {
const o = e.slice();
return o.sort((t, r) => t.x < r.x ? -1 : t.x > r.x ? 1 : t.y < r.y ? -1 : t.y > r.y ? 1 : 0), Ht(o);
}
function Ht(e) {
if (e.length <= 1)
return e.slice();
const o = [];
for (let r = 0; r < e.length; r++) {
const n = e[r];
for (; o.length >= 2; ) {
const s = o[o.length - 1], i = o[o.length - 2];
if ((s.x - i.x) * (n.y - i.y) >= (s.y - i.y) * (n.x - i.x))
o.pop();
else
break;
}
o.push(n);
}
o.pop();
const t = [];
for (let r = e.length - 1; r >= 0; r--) {
const n = e[r];
for (; t.length >= 2; ) {
const s = t[t.length - 1], i = t[t.length - 2];
if ((s.x - i.x) * (n.y - i.y) >= (s.y - i.y) * (n.x - i.x))
t.pop();
else
break;
}
t.push(n);
}
return t.pop(), o.length === 1 && t.length === 1 && o[0].x === t[0].x && o[0].y === t[0].y ? o : o.concat(t);
}
const It = "_tooltipContent_12gjy_1", Lt = "_tooltipArrow_12gjy_8", kt = "_fadeIn_12gjy_1", ne = {
tooltipContent: It,
tooltipArrow: Lt,
fadeIn: kt
}, Mt = Fe(
({ children: e, content: o, className: t, style: r }, n) => /* @__PURE__ */ d(we, { children: /* @__PURE__ */ Y(xe, { delayDuration: 1e3, children: [
/* @__PURE__ */ d(Ce, { asChild: !0, children: /* @__PURE__ */ d("div", { ref: n, className: t, style: r, children: e }) }),
/* @__PURE__ */ Y(Pe, { className: ne.tooltipContent, sideOffset: 5, children: [
/* @__PURE__ */ d(Ae, { className: ne.tooltipArrow }),
/* @__PURE__ */ d("span", { children: o })
] })
] }) })
);
Mt.displayName = "RPTooltip";
export {
Mt as default
};