@kingtech/react-pdf-viewer 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/NOTICE +14 -0
- package/README.md +67 -2
- package/dist/PdfViewer.d.ts +23 -0
- package/dist/components/ContinuousPages.d.ts +23 -0
- package/dist/components/ErrorView.d.ts +10 -0
- package/dist/components/LoadingView.d.ts +6 -0
- package/dist/components/PageInput.d.ts +11 -0
- package/dist/components/PasswordPrompt.d.ts +10 -0
- package/dist/components/PdfPageCanvas.d.ts +53 -0
- package/dist/components/SearchBar.d.ts +18 -0
- package/dist/components/Thumbnails.d.ts +16 -0
- package/dist/components/Toolbar.d.ts +30 -0
- package/dist/components/ToolbarButton.d.ts +15 -0
- package/dist/components/ToolbarMenu.d.ts +25 -0
- package/dist/components/icons.d.ts +60 -0
- package/dist/core/download.d.ts +4 -0
- package/dist/core/env.d.ts +2 -0
- package/dist/core/errors.d.ts +19 -0
- package/dist/core/fileName.d.ts +10 -0
- package/dist/core/geometry.d.ts +25 -0
- package/dist/core/linkService.d.ts +29 -0
- package/dist/core/loadSource.d.ts +22 -0
- package/dist/core/pdfjs.d.ts +80 -0
- package/dist/core/print.d.ts +16 -0
- package/dist/core/scale.d.ts +26 -0
- package/dist/core/search.d.ts +36 -0
- package/dist/hooks/useControllableState.d.ts +19 -0
- package/dist/hooks/useDevicePixelRatio.d.ts +2 -0
- package/dist/hooks/useDocumentSearch.d.ts +13 -0
- package/dist/hooks/useElementSize.d.ts +13 -0
- package/dist/hooks/useFullscreen.d.ts +18 -0
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts +3 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts +18 -0
- package/dist/hooks/useMediaQuery.d.ts +2 -0
- package/dist/hooks/usePageRenderer.d.ts +74 -0
- package/dist/hooks/usePdfDocument.d.ts +31 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +2290 -0
- package/dist/index.js.map +1 -0
- package/dist/labels.d.ts +64 -0
- package/dist/styles.css +2 -0
- package/dist/types.d.ts +324 -0
- package/package.json +95 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,2290 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { forwardRef as e, memo as t, useCallback as n, useEffect as r, useId as i, useImperativeHandle as a, useLayoutEffect as o, useMemo as s, useRef as c, useState as l, useSyncExternalStore as u } from "react";
|
|
3
|
+
import { createPortal as d } from "react-dom";
|
|
4
|
+
import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
5
|
+
//#region src/core/geometry.ts
|
|
6
|
+
var h = 16777216, g = 32767;
|
|
7
|
+
function _(e, t) {
|
|
8
|
+
return Math.min(Math.max(Number.isFinite(e) ? Math.round(e) : 1, 1), Math.max(t, 1));
|
|
9
|
+
}
|
|
10
|
+
function v(e) {
|
|
11
|
+
return (Math.round(e / 90) % 4 + 4) % 4 * 90;
|
|
12
|
+
}
|
|
13
|
+
function y(e, t) {
|
|
14
|
+
return v(e + t);
|
|
15
|
+
}
|
|
16
|
+
function b(e, t, n, r) {
|
|
17
|
+
let i = Number.isFinite(n) && n > 0 ? n : 1, a = e * t;
|
|
18
|
+
return a <= 0 ? i : (r > 0 && (i = Math.min(i, Math.sqrt(r / a))), Math.min(i, g / Math.max(e, t)));
|
|
19
|
+
}
|
|
20
|
+
function x(e, t, n, r) {
|
|
21
|
+
if (!r) return e;
|
|
22
|
+
let i = [];
|
|
23
|
+
if (r.width !== void 0 && r.width > 0 && t > 0 && i.push(r.width / t), r.height !== void 0 && r.height > 0 && n > 0 && i.push(r.height / n), i.length === 0) return e;
|
|
24
|
+
let a = Math.min(...i);
|
|
25
|
+
return r.upscale ? a : Math.min(e, a);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/components/ContinuousPages.tsx
|
|
29
|
+
var S = 2, C = {
|
|
30
|
+
width: 612,
|
|
31
|
+
height: 792
|
|
32
|
+
};
|
|
33
|
+
function w(e, t) {
|
|
34
|
+
let n = Number.parseFloat(getComputedStyle(e).paddingTop) || 0;
|
|
35
|
+
e.scrollTop = t.offsetTop - n;
|
|
36
|
+
}
|
|
37
|
+
function T(e, t, n) {
|
|
38
|
+
let [i, a] = l({
|
|
39
|
+
key: e,
|
|
40
|
+
sizes: []
|
|
41
|
+
});
|
|
42
|
+
return r(() => {
|
|
43
|
+
let r = !1, i = [];
|
|
44
|
+
return (async () => {
|
|
45
|
+
for (let o = 0; o < t && !r; o++) {
|
|
46
|
+
try {
|
|
47
|
+
let t = await e.getPage(o + 1), r = t.getViewport({
|
|
48
|
+
scale: 1,
|
|
49
|
+
rotation: y(t.rotate, n)
|
|
50
|
+
});
|
|
51
|
+
i[o] = {
|
|
52
|
+
width: r.width,
|
|
53
|
+
height: r.height
|
|
54
|
+
};
|
|
55
|
+
} catch {
|
|
56
|
+
i[o] = void 0;
|
|
57
|
+
}
|
|
58
|
+
!r && (o === 0 || o % 16 == 15 || o === t - 1) && a({
|
|
59
|
+
key: e,
|
|
60
|
+
sizes: [...i]
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
})(), () => {
|
|
64
|
+
r = !0;
|
|
65
|
+
};
|
|
66
|
+
}, [
|
|
67
|
+
e,
|
|
68
|
+
t,
|
|
69
|
+
n
|
|
70
|
+
]), i.key === e ? i.sizes : [];
|
|
71
|
+
}
|
|
72
|
+
function E({ document: e, numPages: t, page: n, onVisiblePageChange: i, scale: a, rotation: s, fit: u, scroller: d, renderPage: f }) {
|
|
73
|
+
let m = T(e, t, s), h = m.find(Boolean) ?? C, g = c(/* @__PURE__ */ new Map()), [_, v] = l([n]), y = c(n), b = c(!1), E = c(i);
|
|
74
|
+
o(() => {
|
|
75
|
+
E.current = i;
|
|
76
|
+
}), r(() => {
|
|
77
|
+
if (!d || typeof IntersectionObserver > "u") return;
|
|
78
|
+
let e = /* @__PURE__ */ new Map(), t = new IntersectionObserver((t) => {
|
|
79
|
+
for (let n of t) {
|
|
80
|
+
let t = Number(n.target.dataset.page);
|
|
81
|
+
n.isIntersecting ? e.set(t, n.intersectionRatio) : e.delete(t);
|
|
82
|
+
}
|
|
83
|
+
let n = [...e.keys()].sort((e, t) => e - t);
|
|
84
|
+
if (n.length === 0) return;
|
|
85
|
+
v((e) => e.length === n.length && e.every((e, t) => e === n[t]) ? e : n);
|
|
86
|
+
let r = n[0] ?? 1;
|
|
87
|
+
for (let t of n) (e.get(t) ?? 0) > (e.get(r) ?? 0) && (r = t);
|
|
88
|
+
r !== y.current && (y.current = r, E.current(r));
|
|
89
|
+
}, {
|
|
90
|
+
root: d,
|
|
91
|
+
threshold: [
|
|
92
|
+
0,
|
|
93
|
+
.1,
|
|
94
|
+
.25,
|
|
95
|
+
.5,
|
|
96
|
+
.75,
|
|
97
|
+
1
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
for (let e of g.current.values()) t.observe(e);
|
|
101
|
+
return () => t.disconnect();
|
|
102
|
+
}, [d, t]), o(() => {
|
|
103
|
+
let e = g.current.get(n);
|
|
104
|
+
d && e && (b.current && n === y.current || (b.current = !0, y.current = n, w(d, e)));
|
|
105
|
+
}, [n, d]);
|
|
106
|
+
let D = /* @__PURE__ */ new Set();
|
|
107
|
+
if (typeof IntersectionObserver > "u") for (let e = Math.max(1, n - 1); e <= Math.min(t, n + 1); e++) D.add(e);
|
|
108
|
+
else {
|
|
109
|
+
let e = Math.min(..._), n = Math.max(..._);
|
|
110
|
+
for (let r = Math.max(1, e - 1); r <= Math.min(t, n + 1); r++) D.add(r);
|
|
111
|
+
}
|
|
112
|
+
let O = u === void 0 ? void 0 : {
|
|
113
|
+
width: u.width === void 0 ? void 0 : u.width - S,
|
|
114
|
+
height: u.height === void 0 ? void 0 : u.height - S,
|
|
115
|
+
upscale: u.upscale
|
|
116
|
+
};
|
|
117
|
+
return /* @__PURE__ */ p("div", {
|
|
118
|
+
className: "rpv-pages",
|
|
119
|
+
children: Array.from({ length: t }, (e, t) => {
|
|
120
|
+
let n = t + 1, r = m[t] ?? h, i = x(a, r.width, r.height, O);
|
|
121
|
+
return /* @__PURE__ */ p("div", {
|
|
122
|
+
ref: (e) => {
|
|
123
|
+
e ? g.current.set(n, e) : g.current.delete(n);
|
|
124
|
+
},
|
|
125
|
+
className: "rpv-page-slot",
|
|
126
|
+
"data-page": n,
|
|
127
|
+
style: {
|
|
128
|
+
width: `${r.width * i + S}px`,
|
|
129
|
+
height: `${r.height * i + S}px`
|
|
130
|
+
},
|
|
131
|
+
children: D.has(n) ? f(n, i) : null
|
|
132
|
+
}, n);
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
var D = t(E);
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/components/icons.tsx
|
|
139
|
+
function O(e, t) {
|
|
140
|
+
function n() {
|
|
141
|
+
return /* @__PURE__ */ p("svg", {
|
|
142
|
+
className: "rpv-icon",
|
|
143
|
+
viewBox: "0 0 24 24",
|
|
144
|
+
"aria-hidden": "true",
|
|
145
|
+
focusable: "false",
|
|
146
|
+
children: /* @__PURE__ */ p("path", { d: e })
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return n.displayName = t, n;
|
|
150
|
+
}
|
|
151
|
+
var k = "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z", A = O(`${k}M7 9h5v1H7z`, "ZoomOutIcon"), j = O(`${k}m2.5-4h-2v2H9v-2H7V9h2V7h1v2h2v1z`, "ZoomInIcon"), ee = O("M15.41 7.41 14 6l-6 6 6 6 1.41-1.41L10.83 12z", "NavigateBeforeIcon"), te = O("M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z", "NavigateNextIcon"), ne = O("M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z", "FullscreenIcon"), re = O("M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z", "FullscreenExitIcon"), ie = O("M15.55 5.55 11 1v3.07C7.06 4.56 4 7.92 4 12s3.05 7.44 7 7.93v-2.02c-2.84-.48-5-2.94-5-5.91s2.16-5.43 5-5.91V10l4.55-4.45zM19.93 11c-.17-1.39-.72-2.73-1.62-3.89l-1.42 1.42c.54.75.88 1.6 1.02 2.47h2.02zM13 17.9v2.02c1.39-.17 2.74-.71 3.9-1.61l-1.44-1.44c-.75.54-1.59.89-2.46 1.03zm3.89-2.42 1.42 1.41c.9-1.16 1.45-2.5 1.62-3.89h-2.02c-.14.87-.48 1.72-1.02 2.48z", "RotateRightIcon"), ae = O("M5 20h14v-2H5v2zM19 9h-4V3H9v6H5l7 7 7-7z", "DownloadIcon"), oe = O("M19 8H5c-1.66 0-3 1.34-3 3v6h4v4h12v-4h4v-6c0-1.66-1.34-3-3-3zm-3 11H8v-5h8v5zm3-7c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm-1-9H6v4h12V3z", "PrintIcon"), se = O("M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z", "ErrorOutlineIcon"), ce = O(k, "SearchIcon"), M = O("m12 8-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14z", "ExpandLessIcon"), le = O("M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z", "ExpandMoreIcon"), ue = O("M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z", "MoreVertIcon"), de = O("M12 5V2L8 6l4 4V7c3.31 0 6 2.69 6 6 0 2.97-2.17 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93 0-4.42-3.58-8-8-8zm-6 8c0-1.65.67-3.15 1.76-4.24L6.34 7.34C4.9 8.79 4 10.79 4 13c0 4.08 3.05 7.44 7 7.93v-2.02c-2.83-.48-5-2.94-5-5.91z", "RestartIcon");
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/components/ErrorView.tsx
|
|
154
|
+
function fe({ message: e, retryLabel: t, onRetry: n, variant: r = "document" }) {
|
|
155
|
+
return /* @__PURE__ */ m("div", {
|
|
156
|
+
className: r === "page" ? "rpv-error rpv-error--page" : "rpv-error",
|
|
157
|
+
children: [/* @__PURE__ */ m("div", {
|
|
158
|
+
className: "rpv-alert",
|
|
159
|
+
role: "alert",
|
|
160
|
+
children: [/* @__PURE__ */ p("span", {
|
|
161
|
+
className: "rpv-alert__icon",
|
|
162
|
+
children: /* @__PURE__ */ p(se, {})
|
|
163
|
+
}), /* @__PURE__ */ p("div", {
|
|
164
|
+
className: "rpv-alert__message",
|
|
165
|
+
children: e
|
|
166
|
+
})]
|
|
167
|
+
}), n && /* @__PURE__ */ p("button", {
|
|
168
|
+
type: "button",
|
|
169
|
+
className: "rpv-text-button",
|
|
170
|
+
onClick: n,
|
|
171
|
+
children: t
|
|
172
|
+
})]
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/components/LoadingView.tsx
|
|
177
|
+
function pe() {
|
|
178
|
+
return /* @__PURE__ */ p("span", {
|
|
179
|
+
className: "rpv-spinner",
|
|
180
|
+
"aria-hidden": "true",
|
|
181
|
+
children: /* @__PURE__ */ p("svg", {
|
|
182
|
+
viewBox: "22 22 44 44",
|
|
183
|
+
focusable: "false",
|
|
184
|
+
children: /* @__PURE__ */ p("circle", {
|
|
185
|
+
cx: "44",
|
|
186
|
+
cy: "44",
|
|
187
|
+
r: "20.2",
|
|
188
|
+
fill: "none",
|
|
189
|
+
strokeWidth: "3.6"
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function me({ label: e }) {
|
|
195
|
+
return /* @__PURE__ */ m("div", {
|
|
196
|
+
className: "rpv-loading",
|
|
197
|
+
role: "status",
|
|
198
|
+
children: [/* @__PURE__ */ p(pe, {}), /* @__PURE__ */ p("p", {
|
|
199
|
+
className: "rpv-loading__text",
|
|
200
|
+
children: e
|
|
201
|
+
})]
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/components/PageInput.tsx
|
|
206
|
+
function he({ page: e, numPages: t, label: n, context: r, onCommit: i }) {
|
|
207
|
+
let [a, o] = l(null), s = () => {
|
|
208
|
+
if (a === null) return;
|
|
209
|
+
let e = Number.parseInt(a, 10);
|
|
210
|
+
o(null), Number.isFinite(e) && i(e);
|
|
211
|
+
};
|
|
212
|
+
return /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("input", {
|
|
213
|
+
className: "rpv-page-input",
|
|
214
|
+
type: "text",
|
|
215
|
+
inputMode: "numeric",
|
|
216
|
+
autoComplete: "off",
|
|
217
|
+
"aria-label": n,
|
|
218
|
+
size: Math.max(2, String(t).length),
|
|
219
|
+
style: { "--rpv-page-input-chars": Math.max(2, String(t).length) },
|
|
220
|
+
disabled: t === 0,
|
|
221
|
+
value: a ?? (t > 0 ? r.formatNumber(e) : "0"),
|
|
222
|
+
onChange: (e) => o(e.target.value),
|
|
223
|
+
onFocus: (e) => e.target.select(),
|
|
224
|
+
onBlur: s,
|
|
225
|
+
onKeyDown: (e) => {
|
|
226
|
+
e.key === "Enter" ? (e.preventDefault(), s()) : e.key === "Escape" && o(null);
|
|
227
|
+
}
|
|
228
|
+
}), /* @__PURE__ */ m("span", {
|
|
229
|
+
"aria-hidden": "true",
|
|
230
|
+
children: ["/ ", r.formatNumber(t)]
|
|
231
|
+
})] });
|
|
232
|
+
}
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/components/PasswordPrompt.tsx
|
|
235
|
+
function ge({ labels: e, incorrect: t, onSubmit: n }) {
|
|
236
|
+
let a = i(), o = i(), s = i(), u = c(null), [d, f] = l("");
|
|
237
|
+
return r(() => {
|
|
238
|
+
u.current?.focus();
|
|
239
|
+
}, [t]), /* @__PURE__ */ m("form", {
|
|
240
|
+
className: "rpv-password",
|
|
241
|
+
"aria-labelledby": o,
|
|
242
|
+
onSubmit: (e) => {
|
|
243
|
+
e.preventDefault(), n(d), f("");
|
|
244
|
+
},
|
|
245
|
+
children: [
|
|
246
|
+
/* @__PURE__ */ p("p", {
|
|
247
|
+
id: o,
|
|
248
|
+
className: "rpv-password__title",
|
|
249
|
+
children: e.passwordPrompt
|
|
250
|
+
}),
|
|
251
|
+
t && /* @__PURE__ */ p("p", {
|
|
252
|
+
id: s,
|
|
253
|
+
className: "rpv-password__error",
|
|
254
|
+
role: "alert",
|
|
255
|
+
children: e.passwordIncorrect
|
|
256
|
+
}),
|
|
257
|
+
/* @__PURE__ */ p("label", {
|
|
258
|
+
htmlFor: a,
|
|
259
|
+
children: e.passwordLabel
|
|
260
|
+
}),
|
|
261
|
+
/* @__PURE__ */ p("input", {
|
|
262
|
+
ref: u,
|
|
263
|
+
id: a,
|
|
264
|
+
type: "password",
|
|
265
|
+
autoComplete: "current-password",
|
|
266
|
+
value: d,
|
|
267
|
+
"aria-invalid": t || void 0,
|
|
268
|
+
"aria-describedby": t ? s : void 0,
|
|
269
|
+
onChange: (e) => f(e.target.value)
|
|
270
|
+
}),
|
|
271
|
+
/* @__PURE__ */ p("button", {
|
|
272
|
+
type: "submit",
|
|
273
|
+
className: "rpv-text-button",
|
|
274
|
+
children: e.passwordSubmit
|
|
275
|
+
})
|
|
276
|
+
]
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/core/errors.ts
|
|
281
|
+
var _e = {
|
|
282
|
+
PDFJS_LOAD_FAILED: "Failed to load the PDF.js library",
|
|
283
|
+
NETWORK_ERROR: "Could not load the PDF. Check your connection and try again.",
|
|
284
|
+
HTTP_ERROR: "Failed to fetch PDF document",
|
|
285
|
+
INVALID_PDF: "Invalid or corrupted PDF file",
|
|
286
|
+
PASSWORD_REQUIRED: "This document is password protected",
|
|
287
|
+
INCORRECT_PASSWORD: "Incorrect password",
|
|
288
|
+
RENDER_FAILED: "Failed to render PDF page",
|
|
289
|
+
DOWNLOAD_FAILED: "Failed to download PDF",
|
|
290
|
+
PRINT_FAILED: "Failed to print PDF",
|
|
291
|
+
UNKNOWN: "Failed to load PDF document"
|
|
292
|
+
}, ve = 2, ye = class extends Error {
|
|
293
|
+
constructor(e, t, n) {
|
|
294
|
+
super(t, n.cause === void 0 ? void 0 : { cause: n.cause }), this.name = "PdfViewerError", this.code = e, n.status !== void 0 && (this.status = n.status);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
function be(e, t, n = {}) {
|
|
298
|
+
return new ye(e, t || _e[e], n);
|
|
299
|
+
}
|
|
300
|
+
function xe(e) {
|
|
301
|
+
return e instanceof ye;
|
|
302
|
+
}
|
|
303
|
+
function Se(e, t) {
|
|
304
|
+
return typeof e == "object" && e ? e[t] : void 0;
|
|
305
|
+
}
|
|
306
|
+
function Ce(e) {
|
|
307
|
+
let t = Se(e, "name");
|
|
308
|
+
return t === "AbortError" || t === "AbortException";
|
|
309
|
+
}
|
|
310
|
+
function N(e) {
|
|
311
|
+
return Se(e, "name") === "RenderingCancelledException";
|
|
312
|
+
}
|
|
313
|
+
function we(e, t) {
|
|
314
|
+
if (xe(e)) return e;
|
|
315
|
+
let n = t, r;
|
|
316
|
+
switch (Se(e, "name")) {
|
|
317
|
+
case "PasswordException":
|
|
318
|
+
n = Se(e, "code") === ve ? "INCORRECT_PASSWORD" : "PASSWORD_REQUIRED";
|
|
319
|
+
break;
|
|
320
|
+
case "InvalidPDFException":
|
|
321
|
+
n = "INVALID_PDF";
|
|
322
|
+
break;
|
|
323
|
+
case "ResponseException": {
|
|
324
|
+
n = "HTTP_ERROR";
|
|
325
|
+
let t = Se(e, "status");
|
|
326
|
+
r = typeof t == "number" ? t : void 0;
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
let i = Se(e, "message");
|
|
331
|
+
return be(n, typeof i == "string" && i ? i : typeof e == "string" ? e : void 0, {
|
|
332
|
+
status: r,
|
|
333
|
+
cause: e
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/core/linkService.ts
|
|
338
|
+
function Te(e, t) {
|
|
339
|
+
let n = async (t) => {
|
|
340
|
+
let n = typeof t == "string" ? await e.getDestination(t) : t;
|
|
341
|
+
if (!Array.isArray(n) || n.length === 0) return null;
|
|
342
|
+
let [r] = n;
|
|
343
|
+
if (typeof r == "object" && r) try {
|
|
344
|
+
return await e.getPageIndex(r) + 1;
|
|
345
|
+
} catch {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
return typeof r == "number" && Number.isInteger(r) ? r + 1 : null;
|
|
349
|
+
};
|
|
350
|
+
return {
|
|
351
|
+
externalLinkEnabled: !0,
|
|
352
|
+
isInPresentationMode: !1,
|
|
353
|
+
eventBus: {
|
|
354
|
+
on: () => void 0,
|
|
355
|
+
off: () => void 0,
|
|
356
|
+
dispatch: () => void 0
|
|
357
|
+
},
|
|
358
|
+
addLinkAttributes(e, t) {
|
|
359
|
+
e.href = t, e.target = "_blank", e.rel = "noopener noreferrer nofollow", e.title = t;
|
|
360
|
+
},
|
|
361
|
+
getDestinationHash: () => "#",
|
|
362
|
+
getAnchorUrl: () => "#",
|
|
363
|
+
goToDestination(e) {
|
|
364
|
+
n(e).then((e) => {
|
|
365
|
+
e !== null && t.goToPage(e);
|
|
366
|
+
}, () => void 0);
|
|
367
|
+
},
|
|
368
|
+
goToPage(e) {
|
|
369
|
+
t.goToPage(e);
|
|
370
|
+
},
|
|
371
|
+
executeNamedAction(n) {
|
|
372
|
+
let r = t.getPage(), i = {
|
|
373
|
+
FirstPage: 1,
|
|
374
|
+
LastPage: e.numPages,
|
|
375
|
+
NextPage: r + 1,
|
|
376
|
+
PrevPage: r - 1
|
|
377
|
+
}[n];
|
|
378
|
+
i !== void 0 && t.goToPage(i);
|
|
379
|
+
},
|
|
380
|
+
executeSetOCGState: () => void 0
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
//#endregion
|
|
384
|
+
//#region src/core/env.ts
|
|
385
|
+
function Ee() {
|
|
386
|
+
try {
|
|
387
|
+
return process.env.NODE_ENV !== "production";
|
|
388
|
+
} catch {
|
|
389
|
+
return !1;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
//#endregion
|
|
393
|
+
//#region src/core/pdfjs.ts
|
|
394
|
+
var P = {}, F = null, De = !1, Oe = () => import("pdfjs-dist"), ke = (e) => `https://cdn.jsdelivr.net/npm/pdfjs-dist@${e}/`;
|
|
395
|
+
function Ae() {
|
|
396
|
+
!De && Ee() && (De = !0, console.info("[react-pdf-viewer] Loading PDF.js worker/assets from cdn.jsdelivr.net. Self-host them with configurePdfJs() for production (see the package README)."));
|
|
397
|
+
}
|
|
398
|
+
function je(e) {
|
|
399
|
+
let t = e.GlobalWorkerOptions;
|
|
400
|
+
P.workerPort ? t.workerPort = P.workerPort : P.workerSrc ? t.workerSrc = P.workerSrc : !t.workerSrc && !t.workerPort && (t.workerSrc = `${ke(e.version)}build/pdf.worker.min.mjs`, Ae());
|
|
401
|
+
}
|
|
402
|
+
function Me(e) {
|
|
403
|
+
let t = e.loader !== void 0 && e.loader !== P.loader;
|
|
404
|
+
P = {
|
|
405
|
+
...P,
|
|
406
|
+
...e
|
|
407
|
+
}, t ? F = null : F && (e.workerSrc !== void 0 || e.workerPort !== void 0) && F.then(je).catch(() => void 0);
|
|
408
|
+
}
|
|
409
|
+
function Ne() {
|
|
410
|
+
if (F) return F;
|
|
411
|
+
let e = P.loader ?? Oe, t = Promise.resolve().then(e).then((e) => (je(e), e), (e) => {
|
|
412
|
+
throw F === t && (F = null), be("PDFJS_LOAD_FAILED", void 0, { cause: e });
|
|
413
|
+
});
|
|
414
|
+
return F = t, t;
|
|
415
|
+
}
|
|
416
|
+
function Pe(e) {
|
|
417
|
+
let t = ke(e.version);
|
|
418
|
+
return (!P.cMapUrl || !P.standardFontDataUrl || !P.wasmUrl || !P.iccUrl) && Ae(), {
|
|
419
|
+
cMapUrl: P.cMapUrl ?? `${t}cmaps/`,
|
|
420
|
+
cMapPacked: P.cMapPacked ?? !0,
|
|
421
|
+
standardFontDataUrl: P.standardFontDataUrl ?? `${t}standard_fonts/`,
|
|
422
|
+
wasmUrl: P.wasmUrl ?? `${t}wasm/`,
|
|
423
|
+
iccUrl: P.iccUrl ?? `${t}iccs/`,
|
|
424
|
+
isEvalSupported: P.isEvalSupported ?? !1
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/core/search.ts
|
|
429
|
+
function Fe(e) {
|
|
430
|
+
return typeof e == "object" && !!e && typeof e.str == "string";
|
|
431
|
+
}
|
|
432
|
+
function Ie(e) {
|
|
433
|
+
let t = e.toLowerCase();
|
|
434
|
+
return t.length === e.length ? t : e;
|
|
435
|
+
}
|
|
436
|
+
function Le(e) {
|
|
437
|
+
let t = [], n = [], r = "";
|
|
438
|
+
for (let i of e) t.push(r.length), n.push(i.str), r += i.str, i.hasEOL && (r += " ");
|
|
439
|
+
return {
|
|
440
|
+
text: r,
|
|
441
|
+
folded: Ie(r),
|
|
442
|
+
offsets: t,
|
|
443
|
+
items: n
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
function Re(e) {
|
|
447
|
+
return e.trim().replace(/\s+/g, " ").toLowerCase();
|
|
448
|
+
}
|
|
449
|
+
function ze(e, t) {
|
|
450
|
+
let n = Re(t);
|
|
451
|
+
if (!n) return [];
|
|
452
|
+
let r = [], i = 0;
|
|
453
|
+
for (;;) {
|
|
454
|
+
let t = e.folded.indexOf(n, i);
|
|
455
|
+
if (t === -1) break;
|
|
456
|
+
r.push({
|
|
457
|
+
start: t,
|
|
458
|
+
end: t + n.length
|
|
459
|
+
}), i = t + n.length;
|
|
460
|
+
}
|
|
461
|
+
return r;
|
|
462
|
+
}
|
|
463
|
+
function Be(e, t) {
|
|
464
|
+
let n = [];
|
|
465
|
+
return e.items.forEach((r, i) => {
|
|
466
|
+
let a = e.offsets[i] ?? 0, o = Math.max(t.start, a) - a, s = Math.min(t.end, a + r.length) - a;
|
|
467
|
+
s > o && n.push({
|
|
468
|
+
item: i,
|
|
469
|
+
start: o,
|
|
470
|
+
end: s
|
|
471
|
+
});
|
|
472
|
+
}), n;
|
|
473
|
+
}
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/hooks/useDevicePixelRatio.ts
|
|
476
|
+
function Ve(e) {
|
|
477
|
+
if (typeof window > "u" || typeof window.matchMedia != "function") return () => void 0;
|
|
478
|
+
let t = null, n = () => {
|
|
479
|
+
t?.removeEventListener("change", r), t = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`), t.addEventListener("change", r);
|
|
480
|
+
}, r = () => {
|
|
481
|
+
n(), e();
|
|
482
|
+
};
|
|
483
|
+
return n(), () => t?.removeEventListener("change", r);
|
|
484
|
+
}
|
|
485
|
+
var He = () => window.devicePixelRatio || 1, I = () => 1;
|
|
486
|
+
function Ue() {
|
|
487
|
+
return u(Ve, He, I);
|
|
488
|
+
}
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region src/hooks/useIsomorphicLayoutEffect.ts
|
|
491
|
+
var L = typeof window > "u" ? r : o;
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region src/hooks/usePageRenderer.ts
|
|
494
|
+
function R(e) {
|
|
495
|
+
e instanceof HTMLCanvasElement && (e.width = 0, e.height = 0);
|
|
496
|
+
}
|
|
497
|
+
function We(e) {
|
|
498
|
+
let t = e.ownerDocument.defaultView?.getComputedStyle(e), n = (e) => Number.parseFloat(e ?? "") || 0;
|
|
499
|
+
return {
|
|
500
|
+
x: e.offsetWidth - e.clientWidth + n(t?.paddingLeft) + n(t?.paddingRight),
|
|
501
|
+
y: e.offsetHeight - e.clientHeight + n(t?.paddingTop) + n(t?.paddingBottom)
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
async function Ge(e, t, n, r, i) {
|
|
505
|
+
let a = await t.getTextContent(), o = r.createElement("div");
|
|
506
|
+
o.className = "textLayer";
|
|
507
|
+
let s = new e.TextLayer({
|
|
508
|
+
textContentSource: a,
|
|
509
|
+
container: o,
|
|
510
|
+
viewport: n
|
|
511
|
+
});
|
|
512
|
+
i(s), await s.render();
|
|
513
|
+
let c = r.createElement("div");
|
|
514
|
+
return c.className = "endOfContent", o.append(c), o.addEventListener("mousedown", () => {
|
|
515
|
+
o.classList.add("selecting"), r.addEventListener("mouseup", () => o.classList.remove("selecting"), { once: !0 });
|
|
516
|
+
}), {
|
|
517
|
+
container: o,
|
|
518
|
+
state: {
|
|
519
|
+
divs: s.textDivs,
|
|
520
|
+
pageText: Le(a.items.filter(Fe)),
|
|
521
|
+
highlighted: /* @__PURE__ */ new Set()
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
async function Ke(e, t, n, r, i, a) {
|
|
526
|
+
let o = await n.getAnnotations({ intent: "display" }), s = a.createElement("div");
|
|
527
|
+
if (s.className = "annotationLayer", o.length === 0) return s;
|
|
528
|
+
let c = r.clone({ dontFlip: !0 }), l = i;
|
|
529
|
+
return await new e.AnnotationLayer({
|
|
530
|
+
div: s,
|
|
531
|
+
accessibilityManager: null,
|
|
532
|
+
annotationCanvasMap: null,
|
|
533
|
+
annotationEditorUIManager: null,
|
|
534
|
+
page: n,
|
|
535
|
+
viewport: c,
|
|
536
|
+
structTreeLayer: null,
|
|
537
|
+
commentManager: null,
|
|
538
|
+
linkService: l,
|
|
539
|
+
annotationStorage: t.annotationStorage
|
|
540
|
+
}).render({
|
|
541
|
+
viewport: c,
|
|
542
|
+
div: s,
|
|
543
|
+
annotations: o,
|
|
544
|
+
page: n,
|
|
545
|
+
linkService: l,
|
|
546
|
+
renderForms: !1,
|
|
547
|
+
annotationStorage: t.annotationStorage
|
|
548
|
+
}), s;
|
|
549
|
+
}
|
|
550
|
+
function z(e, t) {
|
|
551
|
+
let { divs: n, pageText: r, highlighted: i } = e;
|
|
552
|
+
for (let e of i) {
|
|
553
|
+
let t = n[e];
|
|
554
|
+
t && (t.textContent = r.items[e] ?? "");
|
|
555
|
+
}
|
|
556
|
+
if (i.clear(), !t?.query.trim()) return null;
|
|
557
|
+
let a = /* @__PURE__ */ new Map();
|
|
558
|
+
ze(r, t.query).forEach((e, n) => {
|
|
559
|
+
for (let i of Be(r, e)) {
|
|
560
|
+
let e = a.get(i.item) ?? [];
|
|
561
|
+
e.push({
|
|
562
|
+
start: i.start,
|
|
563
|
+
end: i.end,
|
|
564
|
+
selected: n === t.selected
|
|
565
|
+
}), a.set(i.item, e);
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
let o = null;
|
|
569
|
+
for (let [e, t] of a) {
|
|
570
|
+
let a = n[e], s = r.items[e];
|
|
571
|
+
if (!a || s === void 0) continue;
|
|
572
|
+
i.add(e), a.textContent = "";
|
|
573
|
+
let c = 0;
|
|
574
|
+
for (let e of t.sort((e, t) => e.start - t.start)) {
|
|
575
|
+
e.start > c && a.append(s.slice(c, e.start));
|
|
576
|
+
let t = a.ownerDocument.createElement("span");
|
|
577
|
+
t.className = e.selected ? "highlight selected appended" : "highlight appended", t.textContent = s.slice(e.start, e.end), a.append(t), e.selected && (o ??= t), c = e.end;
|
|
578
|
+
}
|
|
579
|
+
c < s.length && a.append(s.slice(c));
|
|
580
|
+
}
|
|
581
|
+
return o;
|
|
582
|
+
}
|
|
583
|
+
function B({ document: e, page: t, scale: i, rotation: a, fit: o, maxCanvasPixels: s = h, textLayer: u = !1, annotationLayer: d = !1, highlight: f, onLinkNavigate: p, onHighlight: m, onRender: g, onError: v }) {
|
|
584
|
+
let S = c(null), C = c(null), w = c(null), T = c(null), E = c(null), [D, O] = l(null), [k, A] = l(0), [j, ee] = l(0), te = Ue(), ne = c({
|
|
585
|
+
onRender: g,
|
|
586
|
+
onError: v,
|
|
587
|
+
onLinkNavigate: p,
|
|
588
|
+
onHighlight: m,
|
|
589
|
+
page: t
|
|
590
|
+
});
|
|
591
|
+
L(() => {
|
|
592
|
+
ne.current = {
|
|
593
|
+
onRender: g,
|
|
594
|
+
onError: v,
|
|
595
|
+
onLinkNavigate: p,
|
|
596
|
+
onHighlight: m,
|
|
597
|
+
page: t
|
|
598
|
+
};
|
|
599
|
+
});
|
|
600
|
+
let re = o?.width, ie = o?.height, ae = o?.upscale ?? !1;
|
|
601
|
+
r(() => {
|
|
602
|
+
let n = S.current, r = C.current, o = w.current;
|
|
603
|
+
if (!e || !n || !r || !o) return;
|
|
604
|
+
let c = !1, l = null, f = null, p = performance.now(), m = n.ownerDocument, h = Te(e, {
|
|
605
|
+
goToPage: (e) => ne.current.onLinkNavigate?.(e),
|
|
606
|
+
getPage: () => ne.current.page
|
|
607
|
+
});
|
|
608
|
+
return (async () => {
|
|
609
|
+
let g = await e.getPage(_(t, e.numPages));
|
|
610
|
+
if (c) return;
|
|
611
|
+
let v = y(g.rotate, a), S = g.getViewport({
|
|
612
|
+
scale: 1,
|
|
613
|
+
rotation: v
|
|
614
|
+
}), C = We(n), w = x(i, S.width, S.height, {
|
|
615
|
+
width: re === void 0 ? void 0 : re - C.x,
|
|
616
|
+
height: ie === void 0 ? void 0 : ie - C.y,
|
|
617
|
+
upscale: ae
|
|
618
|
+
}), D = g.getViewport({
|
|
619
|
+
scale: w,
|
|
620
|
+
rotation: v
|
|
621
|
+
}), k = u || d ? Ne().then((t) => Promise.all([u ? Ge(t, g, D, m, (e) => {
|
|
622
|
+
f = e;
|
|
623
|
+
}) : null, d ? Ke(t, e, g, D, h, m) : null])).catch(() => [null, null]) : Promise.resolve([null, null]), A = b(D.width, D.height, te, s), j = m.createElement("canvas");
|
|
624
|
+
j.className = "rpv-page__canvas", j.width = Math.max(1, Math.floor(D.width * A)), j.height = Math.max(1, Math.floor(D.height * A)), Object.assign(j.style, {
|
|
625
|
+
display: "block",
|
|
626
|
+
width: "100%",
|
|
627
|
+
height: "100%"
|
|
628
|
+
}), l = g.render({
|
|
629
|
+
canvas: j,
|
|
630
|
+
viewport: D,
|
|
631
|
+
...A === 1 ? {} : { transform: [
|
|
632
|
+
A,
|
|
633
|
+
0,
|
|
634
|
+
0,
|
|
635
|
+
A,
|
|
636
|
+
0,
|
|
637
|
+
0
|
|
638
|
+
] }
|
|
639
|
+
});
|
|
640
|
+
try {
|
|
641
|
+
await l.promise;
|
|
642
|
+
} catch (e) {
|
|
643
|
+
throw R(j), e;
|
|
644
|
+
}
|
|
645
|
+
let [oe, se] = await k;
|
|
646
|
+
if (c) {
|
|
647
|
+
R(j);
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
let ce = r.firstElementChild;
|
|
651
|
+
r.replaceChildren(j), R(ce), o.replaceChildren(...[oe?.container, se].filter((e) => !!e)), n.style.width = `${D.width}px`, n.style.height = `${D.height}px`, n.style.setProperty("--total-scale-factor", String(w * g.userUnit));
|
|
652
|
+
let M = T.current;
|
|
653
|
+
T.current = g, M && M !== g && M.cleanup(), E.current = oe?.state ?? null, oe && ee((e) => e + 1), O((e) => e === null ? e : null), ne.current.onRender?.({
|
|
654
|
+
page: g.pageNumber,
|
|
655
|
+
scale: w,
|
|
656
|
+
width: D.width,
|
|
657
|
+
height: D.height,
|
|
658
|
+
durationMs: performance.now() - p
|
|
659
|
+
});
|
|
660
|
+
})().catch((e) => {
|
|
661
|
+
if (c || N(e)) return;
|
|
662
|
+
let t = we(e, "RENDER_FAILED");
|
|
663
|
+
O(t), ne.current.onError?.(t);
|
|
664
|
+
}), () => {
|
|
665
|
+
c = !0, l?.cancel(), f?.cancel();
|
|
666
|
+
};
|
|
667
|
+
}, [
|
|
668
|
+
e,
|
|
669
|
+
t,
|
|
670
|
+
i,
|
|
671
|
+
a,
|
|
672
|
+
re,
|
|
673
|
+
ie,
|
|
674
|
+
ae,
|
|
675
|
+
te,
|
|
676
|
+
s,
|
|
677
|
+
u,
|
|
678
|
+
d,
|
|
679
|
+
k
|
|
680
|
+
]);
|
|
681
|
+
let oe = f?.query ?? "", se = f?.selected ?? null;
|
|
682
|
+
return r(() => {
|
|
683
|
+
let e = E.current;
|
|
684
|
+
if (!e) return;
|
|
685
|
+
let t = z(e, oe ? {
|
|
686
|
+
query: oe,
|
|
687
|
+
selected: se
|
|
688
|
+
} : void 0);
|
|
689
|
+
t && ne.current.onHighlight?.(t);
|
|
690
|
+
}, [
|
|
691
|
+
oe,
|
|
692
|
+
se,
|
|
693
|
+
j
|
|
694
|
+
]), r(() => {
|
|
695
|
+
let e = C.current, t = w.current;
|
|
696
|
+
return () => {
|
|
697
|
+
R(e?.firstElementChild), e?.replaceChildren(), t?.replaceChildren(), T.current?.cleanup(), T.current = null, E.current = null;
|
|
698
|
+
};
|
|
699
|
+
}, [e]), {
|
|
700
|
+
pageRef: S,
|
|
701
|
+
canvasHostRef: C,
|
|
702
|
+
layersRef: w,
|
|
703
|
+
error: D,
|
|
704
|
+
retry: n(() => {
|
|
705
|
+
O(null), A((e) => e + 1);
|
|
706
|
+
}, [])
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
//#endregion
|
|
710
|
+
//#region src/components/PdfPageCanvas.tsx
|
|
711
|
+
function V({ document: e, page: t, scale: n = 1, rotation: r = 0, fit: i, maxCanvasPixels: a, textLayer: o = !1, annotationLayer: s = !1, highlight: c, onLinkNavigate: l, onHighlight: u, "aria-label": d, className: f, style: h, renderError: g, onRender: _, onError: v }) {
|
|
712
|
+
let { pageRef: y, canvasHostRef: b, layersRef: x, error: S, retry: C } = B({
|
|
713
|
+
document: e,
|
|
714
|
+
page: t,
|
|
715
|
+
scale: n,
|
|
716
|
+
rotation: r,
|
|
717
|
+
fit: i,
|
|
718
|
+
maxCanvasPixels: a,
|
|
719
|
+
textLayer: o,
|
|
720
|
+
annotationLayer: s,
|
|
721
|
+
highlight: c,
|
|
722
|
+
onLinkNavigate: l,
|
|
723
|
+
onHighlight: u,
|
|
724
|
+
onRender: _,
|
|
725
|
+
onError: v
|
|
726
|
+
}), w = d !== void 0 && !S;
|
|
727
|
+
return /* @__PURE__ */ m("div", {
|
|
728
|
+
ref: y,
|
|
729
|
+
className: f ? `rpv-page ${f}` : "rpv-page",
|
|
730
|
+
style: h,
|
|
731
|
+
role: w ? o || s ? "group" : "img" : void 0,
|
|
732
|
+
"aria-label": w ? d : void 0,
|
|
733
|
+
"data-state": S ? "error" : void 0,
|
|
734
|
+
children: [
|
|
735
|
+
/* @__PURE__ */ p("div", {
|
|
736
|
+
ref: b,
|
|
737
|
+
className: "rpv-page__canvas-host"
|
|
738
|
+
}),
|
|
739
|
+
/* @__PURE__ */ p("div", {
|
|
740
|
+
ref: x,
|
|
741
|
+
className: "rpv-page__layers"
|
|
742
|
+
}),
|
|
743
|
+
S && (g ? g(S, { retry: C }) : /* @__PURE__ */ p("div", {
|
|
744
|
+
className: "rpv-page__error",
|
|
745
|
+
role: "alert",
|
|
746
|
+
children: S.message
|
|
747
|
+
}))
|
|
748
|
+
]
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
var qe = t(V);
|
|
752
|
+
//#endregion
|
|
753
|
+
//#region src/components/SearchBar.tsx
|
|
754
|
+
function Je({ inputRef: e, query: t, onQueryChange: n, total: r, current: i, searching: a, onNext: o, onPrevious: s, labels: c, context: l }) {
|
|
755
|
+
let u = (e) => {
|
|
756
|
+
e.key === "Enter" ? (e.preventDefault(), e.shiftKey ? s() : o()) : e.key === "Escape" && t && (e.preventDefault(), e.stopPropagation(), n(""));
|
|
757
|
+
}, d = t.trim() ? r > 0 ? c.searchResults(i + 1, r, l) : a ? "…" : c.searchNoResults : "";
|
|
758
|
+
return /* @__PURE__ */ m("div", {
|
|
759
|
+
className: "rpv-search",
|
|
760
|
+
children: [
|
|
761
|
+
/* @__PURE__ */ p("span", {
|
|
762
|
+
className: "rpv-search__icon",
|
|
763
|
+
"aria-hidden": "true",
|
|
764
|
+
children: /* @__PURE__ */ p(ce, {})
|
|
765
|
+
}),
|
|
766
|
+
/* @__PURE__ */ p("input", {
|
|
767
|
+
ref: e,
|
|
768
|
+
className: "rpv-search__input",
|
|
769
|
+
type: "search",
|
|
770
|
+
"aria-label": c.search,
|
|
771
|
+
placeholder: c.search,
|
|
772
|
+
value: t,
|
|
773
|
+
onChange: (e) => n(e.target.value),
|
|
774
|
+
onKeyDown: u
|
|
775
|
+
}),
|
|
776
|
+
/* @__PURE__ */ p("output", {
|
|
777
|
+
className: "rpv-search__status",
|
|
778
|
+
"aria-live": "polite",
|
|
779
|
+
children: d
|
|
780
|
+
}),
|
|
781
|
+
/* @__PURE__ */ p("button", {
|
|
782
|
+
type: "button",
|
|
783
|
+
className: "rpv-button",
|
|
784
|
+
"aria-label": c.searchPrevious,
|
|
785
|
+
disabled: r === 0,
|
|
786
|
+
onClick: s,
|
|
787
|
+
children: /* @__PURE__ */ p(M, {})
|
|
788
|
+
}),
|
|
789
|
+
/* @__PURE__ */ p("button", {
|
|
790
|
+
type: "button",
|
|
791
|
+
className: "rpv-button",
|
|
792
|
+
"aria-label": c.searchNext,
|
|
793
|
+
disabled: r === 0,
|
|
794
|
+
onClick: o,
|
|
795
|
+
children: /* @__PURE__ */ p(le, {})
|
|
796
|
+
})
|
|
797
|
+
]
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
//#endregion
|
|
801
|
+
//#region src/components/Thumbnails.tsx
|
|
802
|
+
var H = 8, Ye = "400px 0px", Xe = /* @__PURE__ */ new Map();
|
|
803
|
+
function Ze({ document: e, numPages: t, page: i, rotation: a, onSelect: o, labels: s, context: u }) {
|
|
804
|
+
let d = c(null), f = c(/* @__PURE__ */ new Map()), [h, g] = l(() => new Set(Array.from({ length: Math.min(t, H) }, (e, t) => t + 1))), [_, v] = l(() => ({
|
|
805
|
+
document: e,
|
|
806
|
+
rotation: a,
|
|
807
|
+
sizes: /* @__PURE__ */ new Map(),
|
|
808
|
+
latest: void 0
|
|
809
|
+
})), y = _.document === e && _.rotation === a, b = y ? _.sizes : Xe, x = y ? _.latest : void 0, S = n((t) => {
|
|
810
|
+
let n = f.current.get(t.page)?.querySelector(".rpv-page");
|
|
811
|
+
if (!n || n.offsetWidth === 0 || n.offsetHeight === 0) return;
|
|
812
|
+
let r = {
|
|
813
|
+
width: n.offsetWidth,
|
|
814
|
+
height: n.offsetHeight
|
|
815
|
+
};
|
|
816
|
+
v((n) => {
|
|
817
|
+
let i = n.document === e && n.rotation === a, o = i ? n.sizes.get(t.page) : void 0;
|
|
818
|
+
return o?.width === r.width && o.height === r.height ? n : {
|
|
819
|
+
document: e,
|
|
820
|
+
rotation: a,
|
|
821
|
+
sizes: new Map([...i ? n.sizes : [], [t.page, r]]),
|
|
822
|
+
latest: r
|
|
823
|
+
};
|
|
824
|
+
});
|
|
825
|
+
}, [e, a]);
|
|
826
|
+
return r(() => {
|
|
827
|
+
let e = d.current;
|
|
828
|
+
if (!e || typeof IntersectionObserver > "u") return;
|
|
829
|
+
let t = /* @__PURE__ */ new Set(), n = new IntersectionObserver((e) => {
|
|
830
|
+
for (let n of e) {
|
|
831
|
+
let e = Number(n.target.dataset.page);
|
|
832
|
+
n.isIntersecting ? t.add(e) : t.delete(e);
|
|
833
|
+
}
|
|
834
|
+
g((e) => e.size === t.size && [...t].every((t) => e.has(t)) ? e : new Set(t));
|
|
835
|
+
}, {
|
|
836
|
+
root: e,
|
|
837
|
+
rootMargin: Ye
|
|
838
|
+
});
|
|
839
|
+
for (let e of f.current.values()) n.observe(e);
|
|
840
|
+
return () => n.disconnect();
|
|
841
|
+
}, [t]), r(() => {
|
|
842
|
+
let e = d.current, t = f.current.get(i);
|
|
843
|
+
if (!e || !t) return;
|
|
844
|
+
let n = t.offsetTop - e.offsetTop;
|
|
845
|
+
(n < e.scrollTop || n + t.offsetHeight > e.scrollTop + e.clientHeight) && (e.scrollTop = n - (e.clientHeight - t.offsetHeight) / 2);
|
|
846
|
+
}, [i]), /* @__PURE__ */ p("nav", {
|
|
847
|
+
ref: d,
|
|
848
|
+
className: "rpv-thumbnails",
|
|
849
|
+
"aria-label": s.thumbnails,
|
|
850
|
+
children: /* @__PURE__ */ p("ol", {
|
|
851
|
+
className: "rpv-thumbnails__list",
|
|
852
|
+
children: Array.from({ length: t }, (n, r) => {
|
|
853
|
+
let c = r + 1;
|
|
854
|
+
return /* @__PURE__ */ p("li", {
|
|
855
|
+
ref: (e) => {
|
|
856
|
+
e ? f.current.set(c, e) : f.current.delete(c);
|
|
857
|
+
},
|
|
858
|
+
"data-page": c,
|
|
859
|
+
children: /* @__PURE__ */ m("button", {
|
|
860
|
+
type: "button",
|
|
861
|
+
className: "rpv-thumbnail",
|
|
862
|
+
"aria-label": s.pageAriaLabel(c, t, u),
|
|
863
|
+
"aria-current": c === i ? "page" : void 0,
|
|
864
|
+
onClick: () => o(c),
|
|
865
|
+
children: [h.has(c) ? /* @__PURE__ */ p(qe, {
|
|
866
|
+
document: e,
|
|
867
|
+
page: c,
|
|
868
|
+
rotation: a,
|
|
869
|
+
fit: {
|
|
870
|
+
width: 114,
|
|
871
|
+
upscale: !0
|
|
872
|
+
},
|
|
873
|
+
maxCanvasPixels: 1e6,
|
|
874
|
+
onRender: S
|
|
875
|
+
}) : /* @__PURE__ */ p("span", {
|
|
876
|
+
className: "rpv-thumbnail__placeholder",
|
|
877
|
+
style: b.get(c) ?? x
|
|
878
|
+
}), /* @__PURE__ */ p("span", {
|
|
879
|
+
className: "rpv-thumbnail__number",
|
|
880
|
+
"aria-hidden": "true",
|
|
881
|
+
children: u.formatNumber(c)
|
|
882
|
+
})]
|
|
883
|
+
})
|
|
884
|
+
}, c);
|
|
885
|
+
})
|
|
886
|
+
})
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
var Qe = t(Ze), $e = .25, et = .05, tt = 1e-6;
|
|
890
|
+
function U(e) {
|
|
891
|
+
return Math.round(e * 1e4) / 1e4;
|
|
892
|
+
}
|
|
893
|
+
function nt(e, t) {
|
|
894
|
+
return Math.abs(e - t) < tt;
|
|
895
|
+
}
|
|
896
|
+
function W(e, t, n) {
|
|
897
|
+
return Math.min(Math.max(e, t), n);
|
|
898
|
+
}
|
|
899
|
+
function rt({ zoomLevels: e, minScale: t, maxScale: n }) {
|
|
900
|
+
let r = (e ?? []).filter((e) => Number.isFinite(e) && e > 0).map((e) => U(W(e, t, n)));
|
|
901
|
+
return [...new Set(r)].sort((e, t) => e - t);
|
|
902
|
+
}
|
|
903
|
+
function it(e, t, n) {
|
|
904
|
+
let r = rt(n), i;
|
|
905
|
+
return i = r.length > 0 ? t > 0 ? r.find((t) => t > e + tt) : r.findLast((t) => t < e - tt) : U(W(e + t * n.scaleStep, n.minScale, n.maxScale)), i === void 0 || nt(i, e) ? null : i;
|
|
906
|
+
}
|
|
907
|
+
function at(e, t) {
|
|
908
|
+
return U(W(e, t.minScale, t.maxScale));
|
|
909
|
+
}
|
|
910
|
+
function ot(e) {
|
|
911
|
+
return Math.round(e * 100);
|
|
912
|
+
}
|
|
913
|
+
//#endregion
|
|
914
|
+
//#region src/labels.ts
|
|
915
|
+
var st = {
|
|
916
|
+
viewer: "PDF viewer",
|
|
917
|
+
toolbar: "PDF controls",
|
|
918
|
+
document: "Document",
|
|
919
|
+
zoomOut: "Zoom out",
|
|
920
|
+
zoomIn: "Zoom in",
|
|
921
|
+
zoomLevel: (e, { formatNumber: t }) => `${t(e)}%`,
|
|
922
|
+
resetZoom: "Reset zoom",
|
|
923
|
+
previousPage: "Previous page",
|
|
924
|
+
nextPage: "Next page",
|
|
925
|
+
pageIndicator: (e, t, { formatNumber: n }) => `${n(e)} / ${n(t)}`,
|
|
926
|
+
pageAriaLabel: (e, t, { formatNumber: n }) => `Page ${n(e)} of ${n(t)}`,
|
|
927
|
+
pageInput: "Page number",
|
|
928
|
+
enterFullscreen: "Enter fullscreen",
|
|
929
|
+
exitFullscreen: "Exit fullscreen",
|
|
930
|
+
rotate: "Rotate PDF",
|
|
931
|
+
download: "Download PDF",
|
|
932
|
+
print: "Print PDF",
|
|
933
|
+
moreActions: "More actions",
|
|
934
|
+
loading: "Loading PDF...",
|
|
935
|
+
retry: "Retry",
|
|
936
|
+
empty: "No document",
|
|
937
|
+
printProgress: (e, t, { formatNumber: n }) => `Preparing document for printing… ${n(e)} / ${n(t)}`,
|
|
938
|
+
cancel: "Cancel",
|
|
939
|
+
passwordPrompt: "This document is password protected",
|
|
940
|
+
passwordLabel: "Password",
|
|
941
|
+
passwordSubmit: "Open",
|
|
942
|
+
passwordIncorrect: "Incorrect password. Please try again.",
|
|
943
|
+
thumbnails: "Pages",
|
|
944
|
+
search: "Search in document",
|
|
945
|
+
searchResults: (e, t, { formatNumber: n }) => `${n(e)} of ${n(t)}`,
|
|
946
|
+
searchPrevious: "Previous match",
|
|
947
|
+
searchNext: "Next match",
|
|
948
|
+
searchNoResults: "No matches"
|
|
949
|
+
};
|
|
950
|
+
function ct(e) {
|
|
951
|
+
let t;
|
|
952
|
+
try {
|
|
953
|
+
t = new Intl.NumberFormat(e, {
|
|
954
|
+
useGrouping: !1,
|
|
955
|
+
maximumFractionDigits: 0
|
|
956
|
+
});
|
|
957
|
+
} catch {
|
|
958
|
+
t = new Intl.NumberFormat(void 0, {
|
|
959
|
+
useGrouping: !1,
|
|
960
|
+
maximumFractionDigits: 0
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
return (e) => t.format(e);
|
|
964
|
+
}
|
|
965
|
+
function lt(e) {
|
|
966
|
+
return s(() => ({ formatNumber: ct(e) }), [e]);
|
|
967
|
+
}
|
|
968
|
+
function ut(e) {
|
|
969
|
+
return s(() => ({
|
|
970
|
+
...st,
|
|
971
|
+
...e
|
|
972
|
+
}), [e]);
|
|
973
|
+
}
|
|
974
|
+
//#endregion
|
|
975
|
+
//#region src/components/ToolbarButton.tsx
|
|
976
|
+
function dt({ action: e, label: t, icon: n, onClick: r, disabled: i, tabIndex: a, onFocus: o }) {
|
|
977
|
+
return /* @__PURE__ */ p("button", {
|
|
978
|
+
type: "button",
|
|
979
|
+
className: "rpv-button",
|
|
980
|
+
"aria-label": t,
|
|
981
|
+
"data-action": e,
|
|
982
|
+
disabled: i,
|
|
983
|
+
tabIndex: a,
|
|
984
|
+
onClick: r,
|
|
985
|
+
onFocus: () => o(e),
|
|
986
|
+
children: n
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
var G = t(dt), K = "[role=\"menuitem\"]:not([aria-disabled=\"true\"])";
|
|
990
|
+
function q({ label: e, items: t, placement: n, tabIndex: a, onFocus: o }) {
|
|
991
|
+
let s = i(), u = c(null), d = c(null), [f, h] = l(!1), g = () => [...d.current?.querySelectorAll(K) ?? []];
|
|
992
|
+
r(() => {
|
|
993
|
+
if (!f) return;
|
|
994
|
+
let e = g();
|
|
995
|
+
(f === "last" ? e.at(-1) : e[0])?.focus();
|
|
996
|
+
let t = (e) => {
|
|
997
|
+
let t = e.target;
|
|
998
|
+
!d.current?.contains(t) && !u.current?.contains(t) && h(!1);
|
|
999
|
+
};
|
|
1000
|
+
return document.addEventListener("pointerdown", t), () => document.removeEventListener("pointerdown", t);
|
|
1001
|
+
}, [f]);
|
|
1002
|
+
let _ = (e) => {
|
|
1003
|
+
h(!1), e && u.current?.focus();
|
|
1004
|
+
};
|
|
1005
|
+
return /* @__PURE__ */ m("div", {
|
|
1006
|
+
className: "rpv-menu-anchor",
|
|
1007
|
+
children: [/* @__PURE__ */ p("button", {
|
|
1008
|
+
ref: u,
|
|
1009
|
+
type: "button",
|
|
1010
|
+
className: "rpv-button",
|
|
1011
|
+
"aria-label": e,
|
|
1012
|
+
"aria-haspopup": "menu",
|
|
1013
|
+
"aria-expanded": !!f,
|
|
1014
|
+
"aria-controls": f ? s : void 0,
|
|
1015
|
+
"data-action": "more",
|
|
1016
|
+
tabIndex: a,
|
|
1017
|
+
onFocus: o,
|
|
1018
|
+
onClick: () => h((e) => !e && "first"),
|
|
1019
|
+
onKeyDown: (e) => {
|
|
1020
|
+
(e.key === "ArrowDown" || e.key === "ArrowUp") && (e.preventDefault(), h(e.key === "ArrowUp" ? "last" : "first"));
|
|
1021
|
+
},
|
|
1022
|
+
children: /* @__PURE__ */ p(ue, {})
|
|
1023
|
+
}), f && /* @__PURE__ */ p("div", {
|
|
1024
|
+
ref: d,
|
|
1025
|
+
id: s,
|
|
1026
|
+
role: "menu",
|
|
1027
|
+
"aria-label": e,
|
|
1028
|
+
tabIndex: -1,
|
|
1029
|
+
className: "rpv-menu",
|
|
1030
|
+
"data-placement": n,
|
|
1031
|
+
onKeyDown: (e) => {
|
|
1032
|
+
let t = g(), n = t.indexOf(e.target), r = t.length - 1, i;
|
|
1033
|
+
switch (e.key) {
|
|
1034
|
+
case "ArrowDown":
|
|
1035
|
+
i = t[n >= r ? 0 : n + 1];
|
|
1036
|
+
break;
|
|
1037
|
+
case "ArrowUp":
|
|
1038
|
+
i = t[n <= 0 ? r : n - 1];
|
|
1039
|
+
break;
|
|
1040
|
+
case "Home":
|
|
1041
|
+
i = t[0];
|
|
1042
|
+
break;
|
|
1043
|
+
case "End":
|
|
1044
|
+
i = t[r];
|
|
1045
|
+
break;
|
|
1046
|
+
case "Escape":
|
|
1047
|
+
e.preventDefault(), e.stopPropagation(), _(!0);
|
|
1048
|
+
return;
|
|
1049
|
+
case "Tab":
|
|
1050
|
+
_(!1);
|
|
1051
|
+
return;
|
|
1052
|
+
default: return;
|
|
1053
|
+
}
|
|
1054
|
+
e.preventDefault(), e.stopPropagation(), i?.focus();
|
|
1055
|
+
},
|
|
1056
|
+
children: t.map((e) => /* @__PURE__ */ m("button", {
|
|
1057
|
+
type: "button",
|
|
1058
|
+
role: "menuitem",
|
|
1059
|
+
className: "rpv-menu__item",
|
|
1060
|
+
tabIndex: -1,
|
|
1061
|
+
"aria-disabled": e.disabled || void 0,
|
|
1062
|
+
onClick: () => {
|
|
1063
|
+
e.disabled || (_(!0), e.onSelect());
|
|
1064
|
+
},
|
|
1065
|
+
children: [/* @__PURE__ */ p("span", {
|
|
1066
|
+
className: "rpv-menu__icon",
|
|
1067
|
+
"aria-hidden": "true",
|
|
1068
|
+
children: e.icon
|
|
1069
|
+
}), /* @__PURE__ */ p("span", {
|
|
1070
|
+
className: "rpv-menu__label",
|
|
1071
|
+
children: e.label
|
|
1072
|
+
})]
|
|
1073
|
+
}, e.key))
|
|
1074
|
+
})]
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region src/components/Toolbar.tsx
|
|
1079
|
+
var ft = [
|
|
1080
|
+
"zoomOut",
|
|
1081
|
+
"zoomLevel",
|
|
1082
|
+
"zoomIn",
|
|
1083
|
+
"previousPage",
|
|
1084
|
+
"pageIndicator",
|
|
1085
|
+
"nextPage",
|
|
1086
|
+
"fullscreen",
|
|
1087
|
+
"rotate",
|
|
1088
|
+
"download",
|
|
1089
|
+
"print"
|
|
1090
|
+
], pt = ["rotate", "print"], mt = [
|
|
1091
|
+
[
|
|
1092
|
+
"zoomOut",
|
|
1093
|
+
"zoomLevel",
|
|
1094
|
+
"zoomIn"
|
|
1095
|
+
],
|
|
1096
|
+
[
|
|
1097
|
+
"previousPage",
|
|
1098
|
+
"pageIndicator",
|
|
1099
|
+
"nextPage"
|
|
1100
|
+
],
|
|
1101
|
+
[
|
|
1102
|
+
"fullscreen",
|
|
1103
|
+
"rotate",
|
|
1104
|
+
"download",
|
|
1105
|
+
"print"
|
|
1106
|
+
]
|
|
1107
|
+
], J = [
|
|
1108
|
+
"zoom",
|
|
1109
|
+
"pages",
|
|
1110
|
+
"actions"
|
|
1111
|
+
], ht = [
|
|
1112
|
+
[],
|
|
1113
|
+
[
|
|
1114
|
+
"fullscreen",
|
|
1115
|
+
"rotate",
|
|
1116
|
+
"download",
|
|
1117
|
+
"print"
|
|
1118
|
+
],
|
|
1119
|
+
[
|
|
1120
|
+
"zoomOut",
|
|
1121
|
+
"zoomLevel",
|
|
1122
|
+
"zoomIn",
|
|
1123
|
+
"fullscreen",
|
|
1124
|
+
"rotate",
|
|
1125
|
+
"download",
|
|
1126
|
+
"print"
|
|
1127
|
+
]
|
|
1128
|
+
], gt = ht.length - 1, Y = (e) => Number.parseFloat(e) || 0;
|
|
1129
|
+
function _t(e) {
|
|
1130
|
+
let t = getComputedStyle(e), n = [...e.children];
|
|
1131
|
+
return n.reduce((e, t) => e + t.offsetWidth, 0) + Y(t.columnGap) * Math.max(0, n.length - 1) + Y(t.paddingLeft) + Y(t.paddingRight);
|
|
1132
|
+
}
|
|
1133
|
+
function vt(e) {
|
|
1134
|
+
let t = e.parentElement;
|
|
1135
|
+
return t?.classList.contains("rpv-toolbar-wrapper") ? t.parentElement : t;
|
|
1136
|
+
}
|
|
1137
|
+
function yt(e) {
|
|
1138
|
+
let t = vt(e);
|
|
1139
|
+
if (!t) return 0;
|
|
1140
|
+
let n = getComputedStyle(t), r = t.clientWidth - Y(n.paddingLeft) - Y(n.paddingRight);
|
|
1141
|
+
if (r <= 0) return 0;
|
|
1142
|
+
let i = getComputedStyle(e), a = Y(i.paddingLeft) + Y(i.paddingRight), o = e.ownerDocument.documentElement.clientWidth || Infinity;
|
|
1143
|
+
return Math.min(r + a, o);
|
|
1144
|
+
}
|
|
1145
|
+
function bt({ api: e, labels: t, config: n, compact: i = !1, locale: a, zoomReset: o = !1, pageIndicator: s, menuPlacement: u = "top" }) {
|
|
1146
|
+
let d = ut(t), f = lt(a), h = c(null), [g, _] = l(null), v = n?.hiddenWhenCompact ?? pt, y = new Set((n?.actions ?? ft).filter((t) => !(i && !e.fullscreen && v.includes(t)))), b = e.status === "ready", x = d.zoomLevel(ot(e.scale), f), S = o || s !== void 0, C = `${[...y].join(",")}|${S ? "x" : ""}`, [w, T] = l({
|
|
1147
|
+
key: C,
|
|
1148
|
+
level: 0
|
|
1149
|
+
});
|
|
1150
|
+
w.key !== C && T({
|
|
1151
|
+
key: C,
|
|
1152
|
+
level: 0
|
|
1153
|
+
});
|
|
1154
|
+
let E = w.key === C ? w.level : 0, D = c(/* @__PURE__ */ new Map()), O = c(() => void 0);
|
|
1155
|
+
L(() => {
|
|
1156
|
+
O.current = () => {
|
|
1157
|
+
let e = h.current;
|
|
1158
|
+
if (!e) return;
|
|
1159
|
+
let t = yt(e);
|
|
1160
|
+
if (t <= 0) return;
|
|
1161
|
+
let n = D.current.get(C);
|
|
1162
|
+
n || (n = [], D.current.set(C, n)), n[E] = _t(e);
|
|
1163
|
+
let r = E;
|
|
1164
|
+
for (; r > 0 && (n[r - 1] ?? Infinity) <= t;) --r;
|
|
1165
|
+
r === E && (n[E] ?? 0) > t + .5 && E < gt && (r = E + 1), r !== E && T({
|
|
1166
|
+
key: C,
|
|
1167
|
+
level: r
|
|
1168
|
+
});
|
|
1169
|
+
}, O.current();
|
|
1170
|
+
}), r(() => {
|
|
1171
|
+
let e = h.current, t = e ? vt(e) : null;
|
|
1172
|
+
if (!t || typeof ResizeObserver > "u") return;
|
|
1173
|
+
let n = new ResizeObserver(() => O.current());
|
|
1174
|
+
return n.observe(t), () => n.disconnect();
|
|
1175
|
+
}, []);
|
|
1176
|
+
let k = {
|
|
1177
|
+
zoomOut: {
|
|
1178
|
+
label: d.zoomOut,
|
|
1179
|
+
icon: /* @__PURE__ */ p(A, {}),
|
|
1180
|
+
onClick: e.zoomOut,
|
|
1181
|
+
disabled: !e.canZoomOut
|
|
1182
|
+
},
|
|
1183
|
+
zoomIn: {
|
|
1184
|
+
label: d.zoomIn,
|
|
1185
|
+
icon: /* @__PURE__ */ p(j, {}),
|
|
1186
|
+
onClick: e.zoomIn,
|
|
1187
|
+
disabled: !e.canZoomIn
|
|
1188
|
+
},
|
|
1189
|
+
previousPage: {
|
|
1190
|
+
label: d.previousPage,
|
|
1191
|
+
icon: /* @__PURE__ */ p(ee, {}),
|
|
1192
|
+
onClick: e.previousPage,
|
|
1193
|
+
disabled: !b || e.page <= 1
|
|
1194
|
+
},
|
|
1195
|
+
nextPage: {
|
|
1196
|
+
label: d.nextPage,
|
|
1197
|
+
icon: /* @__PURE__ */ p(te, {}),
|
|
1198
|
+
onClick: e.nextPage,
|
|
1199
|
+
disabled: !b || e.page >= e.numPages
|
|
1200
|
+
},
|
|
1201
|
+
fullscreen: {
|
|
1202
|
+
label: e.fullscreen ? d.exitFullscreen : d.enterFullscreen,
|
|
1203
|
+
icon: e.fullscreen ? /* @__PURE__ */ p(re, {}) : /* @__PURE__ */ p(ne, {}),
|
|
1204
|
+
onClick: e.toggleFullscreen,
|
|
1205
|
+
disabled: !1
|
|
1206
|
+
},
|
|
1207
|
+
rotate: {
|
|
1208
|
+
label: d.rotate,
|
|
1209
|
+
icon: /* @__PURE__ */ p(ie, {}),
|
|
1210
|
+
onClick: () => e.rotate("cw"),
|
|
1211
|
+
disabled: !1
|
|
1212
|
+
},
|
|
1213
|
+
download: {
|
|
1214
|
+
label: d.download,
|
|
1215
|
+
icon: /* @__PURE__ */ p(ae, {}),
|
|
1216
|
+
onClick: () => void e.download(),
|
|
1217
|
+
disabled: !b
|
|
1218
|
+
},
|
|
1219
|
+
print: {
|
|
1220
|
+
label: d.print,
|
|
1221
|
+
icon: /* @__PURE__ */ p(oe, {}),
|
|
1222
|
+
onClick: () => void e.print(),
|
|
1223
|
+
disabled: !b
|
|
1224
|
+
}
|
|
1225
|
+
}, se = (ht[E] ?? []).filter((e) => y.has(e)), ce = (e) => y.has(e) && !se.includes(e), M = se.flatMap((t) => {
|
|
1226
|
+
if (t === "zoomLevel") return [{
|
|
1227
|
+
key: t,
|
|
1228
|
+
label: `${d.resetZoom} (${x})`,
|
|
1229
|
+
icon: /* @__PURE__ */ p(de, {}),
|
|
1230
|
+
onSelect: e.resetZoom
|
|
1231
|
+
}];
|
|
1232
|
+
let n = k[t];
|
|
1233
|
+
return n ? [{
|
|
1234
|
+
key: t,
|
|
1235
|
+
label: n.label,
|
|
1236
|
+
icon: n.icon,
|
|
1237
|
+
onSelect: n.onClick,
|
|
1238
|
+
disabled: n.disabled
|
|
1239
|
+
}] : [];
|
|
1240
|
+
}), le = ft.filter((e) => {
|
|
1241
|
+
if (!ce(e) || e === "pageIndicator") return !1;
|
|
1242
|
+
if (e === "zoomLevel") return o;
|
|
1243
|
+
let t = k[e];
|
|
1244
|
+
return t !== void 0 && !t.disabled;
|
|
1245
|
+
});
|
|
1246
|
+
M.length > 0 && le.push("more");
|
|
1247
|
+
let ue = g !== null && le.includes(g) ? g : le[0], fe = (e) => {
|
|
1248
|
+
if (![
|
|
1249
|
+
"ArrowLeft",
|
|
1250
|
+
"ArrowRight",
|
|
1251
|
+
"Home",
|
|
1252
|
+
"End"
|
|
1253
|
+
].includes(e.key) || !h.current) return;
|
|
1254
|
+
let t = [...h.current.querySelectorAll("[data-action]:not(:disabled)")], n = t.indexOf(e.target);
|
|
1255
|
+
if (n === -1) return;
|
|
1256
|
+
e.preventDefault(), e.stopPropagation();
|
|
1257
|
+
let r = t.length - 1;
|
|
1258
|
+
t[e.key === "Home" ? 0 : e.key === "End" ? r : e.key === "ArrowRight" ? n === r ? 0 : n + 1 : n === 0 ? r : n - 1]?.focus();
|
|
1259
|
+
}, pe = (t) => {
|
|
1260
|
+
if (t === "zoomLevel") return o ? /* @__PURE__ */ p("button", {
|
|
1261
|
+
type: "button",
|
|
1262
|
+
className: "rpv-toolbar__label rpv-toolbar__zoom rpv-zoom-reset",
|
|
1263
|
+
"aria-label": `${d.resetZoom} (${x})`,
|
|
1264
|
+
title: d.resetZoom,
|
|
1265
|
+
"data-action": t,
|
|
1266
|
+
tabIndex: t === ue ? 0 : -1,
|
|
1267
|
+
onFocus: () => _(t),
|
|
1268
|
+
onClick: e.resetZoom,
|
|
1269
|
+
children: x
|
|
1270
|
+
}, t) : /* @__PURE__ */ p("span", {
|
|
1271
|
+
className: "rpv-toolbar__label rpv-toolbar__zoom",
|
|
1272
|
+
children: x
|
|
1273
|
+
}, t);
|
|
1274
|
+
if (t === "pageIndicator") return s ? /* @__PURE__ */ p("span", {
|
|
1275
|
+
className: "rpv-toolbar__label rpv-toolbar__pages rpv-toolbar__pages--input",
|
|
1276
|
+
children: s
|
|
1277
|
+
}, t) : /* @__PURE__ */ p("span", {
|
|
1278
|
+
className: "rpv-toolbar__label rpv-toolbar__pages",
|
|
1279
|
+
"aria-live": "polite",
|
|
1280
|
+
"aria-atomic": "true",
|
|
1281
|
+
children: e.numPages > 0 ? d.pageIndicator(e.page, e.numPages, f) : d.pageIndicator(0, 0, f)
|
|
1282
|
+
}, t);
|
|
1283
|
+
let n = k[t];
|
|
1284
|
+
return n ? /* @__PURE__ */ p(G, {
|
|
1285
|
+
action: t,
|
|
1286
|
+
label: n.label,
|
|
1287
|
+
icon: n.icon,
|
|
1288
|
+
onClick: n.onClick,
|
|
1289
|
+
disabled: n.disabled,
|
|
1290
|
+
tabIndex: t === ue ? 0 : -1,
|
|
1291
|
+
onFocus: _
|
|
1292
|
+
}, t) : null;
|
|
1293
|
+
};
|
|
1294
|
+
return /* @__PURE__ */ p("div", {
|
|
1295
|
+
ref: h,
|
|
1296
|
+
role: "toolbar",
|
|
1297
|
+
"aria-label": d.toolbar,
|
|
1298
|
+
"aria-orientation": "horizontal",
|
|
1299
|
+
className: "rpv-toolbar",
|
|
1300
|
+
"data-extended": S ? "" : void 0,
|
|
1301
|
+
"data-level": E,
|
|
1302
|
+
onKeyDown: fe,
|
|
1303
|
+
children: mt.map((e, t) => {
|
|
1304
|
+
let n = e.filter(ce), r = t === mt.length - 1 && M.length > 0;
|
|
1305
|
+
return n.length === 0 && !r ? null : /* @__PURE__ */ m("div", {
|
|
1306
|
+
className: "rpv-toolbar__group",
|
|
1307
|
+
"data-group": J[t],
|
|
1308
|
+
children: [n.map(pe), r && /* @__PURE__ */ p(q, {
|
|
1309
|
+
label: d.moreActions,
|
|
1310
|
+
items: M,
|
|
1311
|
+
placement: u,
|
|
1312
|
+
tabIndex: ue === "more" ? 0 : -1,
|
|
1313
|
+
onFocus: () => _("more")
|
|
1314
|
+
})]
|
|
1315
|
+
}, J[t]);
|
|
1316
|
+
})
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
var xt = t(bt);
|
|
1320
|
+
//#endregion
|
|
1321
|
+
//#region src/core/download.ts
|
|
1322
|
+
function X(e) {
|
|
1323
|
+
return new Blob([new Uint8Array(e)], { type: "application/pdf" });
|
|
1324
|
+
}
|
|
1325
|
+
function St(e, t) {
|
|
1326
|
+
let n = URL.createObjectURL(X(e)), r = document.createElement("a");
|
|
1327
|
+
r.href = n, r.download = t, r.rel = "noopener", r.style.display = "none", document.body.append(r), r.click(), r.remove(), setTimeout(() => URL.revokeObjectURL(n), 1e4);
|
|
1328
|
+
}
|
|
1329
|
+
//#endregion
|
|
1330
|
+
//#region src/core/fileName.ts
|
|
1331
|
+
var Ct = "document.pdf";
|
|
1332
|
+
function wt(e) {
|
|
1333
|
+
let t;
|
|
1334
|
+
try {
|
|
1335
|
+
t = new URL(e, "https://base.invalid/").pathname;
|
|
1336
|
+
} catch {
|
|
1337
|
+
return null;
|
|
1338
|
+
}
|
|
1339
|
+
let n = t.split("/").pop() ?? "", r = n;
|
|
1340
|
+
try {
|
|
1341
|
+
r = decodeURIComponent(n);
|
|
1342
|
+
} catch {}
|
|
1343
|
+
return /\.pdf$/i.test(r) ? r : null;
|
|
1344
|
+
}
|
|
1345
|
+
function Tt(e, t) {
|
|
1346
|
+
if (e) return e;
|
|
1347
|
+
if (typeof Blob < "u" && t instanceof Blob && "name" in t) {
|
|
1348
|
+
let e = t.name;
|
|
1349
|
+
if (e) return e;
|
|
1350
|
+
}
|
|
1351
|
+
if (typeof t == "string" || t instanceof URL) {
|
|
1352
|
+
let e = wt(t.toString());
|
|
1353
|
+
if (e) return e;
|
|
1354
|
+
}
|
|
1355
|
+
return Ct;
|
|
1356
|
+
}
|
|
1357
|
+
//#endregion
|
|
1358
|
+
//#region src/core/print.ts
|
|
1359
|
+
var Et = 150 / 72, Dt = 6e4, Ot = "\nhtml, body { margin: 0; padding: 0; height: 100%; }\n.page {\n display: flex; align-items: center; justify-content: center;\n width: 100%; height: 100%;\n break-after: page; page-break-after: always; break-inside: avoid; page-break-inside: avoid;\n}\n.page:last-child { break-after: auto; page-break-after: auto; }\nimg { display: block; max-width: 100%; max-height: 100%; }\n";
|
|
1360
|
+
function Z(e) {
|
|
1361
|
+
return new Promise((t, n) => {
|
|
1362
|
+
e.toBlob((e) => e ? t(e) : n(/* @__PURE__ */ Error("Failed to encode a page for printing")));
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
async function kt(e, { signal: t, onProgress: n, scale: r = Et } = {}) {
|
|
1366
|
+
let i = window.document, a = i.createElement("iframe");
|
|
1367
|
+
a.className = "rpv-print-frame", a.title = "Print", a.tabIndex = -1, a.setAttribute("aria-hidden", "true"), Object.assign(a.style, {
|
|
1368
|
+
position: "fixed",
|
|
1369
|
+
right: "0",
|
|
1370
|
+
bottom: "0",
|
|
1371
|
+
width: "0",
|
|
1372
|
+
height: "0",
|
|
1373
|
+
border: "0"
|
|
1374
|
+
}), i.body.append(a);
|
|
1375
|
+
let o = [];
|
|
1376
|
+
try {
|
|
1377
|
+
let s = a.contentWindow, c = a.contentDocument;
|
|
1378
|
+
if (!s || !c) throw Error("The print frame is unavailable");
|
|
1379
|
+
let l = e.numPages, u = (await e.getPage(1)).getViewport({ scale: 1 }), d = c.createElement("style");
|
|
1380
|
+
d.textContent = `@page { size: ${u.width}pt ${u.height}pt; margin: 0; }${Ot}`, c.head.append(d), n?.(0, l);
|
|
1381
|
+
let f = /* @__PURE__ */ new Map(), p = (e, t) => {
|
|
1382
|
+
let n = `${Math.round(e)}x${Math.round(t)}`, r = f.get(n);
|
|
1383
|
+
return r || (r = `rpv-sheet-${f.size}`, f.set(n, r), d.textContent += `@page ${r} { size: ${e}pt ${t}pt; margin: 0; }.${r} { page: ${r}; }`), r;
|
|
1384
|
+
};
|
|
1385
|
+
for (let a = 1; a <= l; a++) {
|
|
1386
|
+
t?.throwIfAborted();
|
|
1387
|
+
let s = await e.getPage(a), u = s.getViewport({ scale: 1 }), d = p(u.width, u.height), f = s.getViewport({ scale: r }), m = i.createElement("canvas");
|
|
1388
|
+
m.width = Math.floor(f.width), m.height = Math.floor(f.height), await s.render({
|
|
1389
|
+
canvas: m,
|
|
1390
|
+
viewport: f,
|
|
1391
|
+
intent: "print"
|
|
1392
|
+
}).promise;
|
|
1393
|
+
let h = await Z(m);
|
|
1394
|
+
m.width = 0, m.height = 0, s.cleanup();
|
|
1395
|
+
let g = URL.createObjectURL(h);
|
|
1396
|
+
o.push(g);
|
|
1397
|
+
let _ = c.createElement("div");
|
|
1398
|
+
_.className = `page ${d}`;
|
|
1399
|
+
let v = c.createElement("img");
|
|
1400
|
+
v.alt = "", v.src = g, _.append(v), c.body.append(_), n?.(a, l);
|
|
1401
|
+
}
|
|
1402
|
+
await Promise.all([...c.images].map((e) => typeof e.decode == "function" ? e.decode().catch(() => void 0) : void 0)), t?.throwIfAborted(), await new Promise((e) => {
|
|
1403
|
+
let t = setTimeout(e, Dt);
|
|
1404
|
+
s.addEventListener("afterprint", () => {
|
|
1405
|
+
clearTimeout(t), e();
|
|
1406
|
+
}, { once: !0 }), s.focus(), s.print();
|
|
1407
|
+
});
|
|
1408
|
+
} finally {
|
|
1409
|
+
a.remove(), o.forEach((e) => URL.revokeObjectURL(e));
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
//#endregion
|
|
1413
|
+
//#region src/hooks/useControllableState.ts
|
|
1414
|
+
function At({ value: e, defaultValue: t, onChange: i, name: a = "value" }) {
|
|
1415
|
+
let [o, s] = l(t), u = e !== void 0, d = u ? e : o, f = c({
|
|
1416
|
+
current: d,
|
|
1417
|
+
isControlled: u,
|
|
1418
|
+
onChange: i
|
|
1419
|
+
});
|
|
1420
|
+
L(() => {
|
|
1421
|
+
f.current = {
|
|
1422
|
+
current: d,
|
|
1423
|
+
isControlled: u,
|
|
1424
|
+
onChange: i
|
|
1425
|
+
};
|
|
1426
|
+
});
|
|
1427
|
+
let p = c(u);
|
|
1428
|
+
return r(() => {
|
|
1429
|
+
if (p.current !== u && Ee()) {
|
|
1430
|
+
let e = p.current ? "controlled" : "uncontrolled";
|
|
1431
|
+
console.error(`[react-pdf-viewer] \`${a}\` changed from ${e} to ${u ? "controlled" : "uncontrolled"}. Decide between a controlled and an uncontrolled value for the lifetime of the component.`);
|
|
1432
|
+
}
|
|
1433
|
+
p.current = u;
|
|
1434
|
+
}, [u, a]), [d, n((e) => {
|
|
1435
|
+
let t = f.current, n = typeof e == "function" ? e(t.current) : e;
|
|
1436
|
+
Object.is(n, t.current) || (t.current = n, t.isControlled || s(n), t.onChange?.(n));
|
|
1437
|
+
}, [])];
|
|
1438
|
+
}
|
|
1439
|
+
//#endregion
|
|
1440
|
+
//#region src/hooks/useDocumentSearch.ts
|
|
1441
|
+
var jt = 200;
|
|
1442
|
+
async function Mt(e, t, n) {
|
|
1443
|
+
let r = n.get(t);
|
|
1444
|
+
return r || (r = e.getPage(t).then((e) => e.getTextContent()).then((e) => Le(e.items.filter(Fe))), n.set(t, r)), r;
|
|
1445
|
+
}
|
|
1446
|
+
function Nt(e, t) {
|
|
1447
|
+
let n = Re(t), i = s(() => /* @__PURE__ */ new Map(), [e]), [a, o] = l({
|
|
1448
|
+
document: null,
|
|
1449
|
+
query: "",
|
|
1450
|
+
matches: [],
|
|
1451
|
+
done: !0
|
|
1452
|
+
});
|
|
1453
|
+
r(() => {
|
|
1454
|
+
if (!e || !n) return;
|
|
1455
|
+
let t = !1, r = setTimeout(() => {
|
|
1456
|
+
(async () => {
|
|
1457
|
+
let r = [];
|
|
1458
|
+
for (let a = 1; a <= e.numPages; a++) {
|
|
1459
|
+
let s = await Mt(e, a, i).catch(() => null);
|
|
1460
|
+
if (t) return;
|
|
1461
|
+
s && ze(s, n).forEach((e, t) => r.push({
|
|
1462
|
+
page: a,
|
|
1463
|
+
index: t
|
|
1464
|
+
})), (a % 8 == 0 || a === e.numPages) && o({
|
|
1465
|
+
document: e,
|
|
1466
|
+
query: n,
|
|
1467
|
+
matches: [...r],
|
|
1468
|
+
done: a === e.numPages
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
})();
|
|
1472
|
+
}, jt);
|
|
1473
|
+
return () => {
|
|
1474
|
+
t = !0, clearTimeout(r);
|
|
1475
|
+
};
|
|
1476
|
+
}, [
|
|
1477
|
+
e,
|
|
1478
|
+
n,
|
|
1479
|
+
i
|
|
1480
|
+
]);
|
|
1481
|
+
let c = a.document === e && a.query === n;
|
|
1482
|
+
return {
|
|
1483
|
+
matches: c && n ? a.matches : [],
|
|
1484
|
+
searching: !!n && (!c || !a.done)
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
//#endregion
|
|
1488
|
+
//#region src/hooks/useElementSize.ts
|
|
1489
|
+
function Pt() {
|
|
1490
|
+
let [e, t] = l(null), [n, i] = l(null);
|
|
1491
|
+
return r(() => {
|
|
1492
|
+
if (!e || typeof ResizeObserver > "u") return;
|
|
1493
|
+
let t = new ResizeObserver(([e]) => {
|
|
1494
|
+
if (!e) return;
|
|
1495
|
+
let t = e.contentBoxSize[0], n = t ? t.inlineSize : e.contentRect.width, r = t ? t.blockSize : e.contentRect.height;
|
|
1496
|
+
i((e) => e && e.width === n && e.height === r ? e : {
|
|
1497
|
+
width: n,
|
|
1498
|
+
height: r
|
|
1499
|
+
});
|
|
1500
|
+
});
|
|
1501
|
+
return t.observe(e), () => t.disconnect();
|
|
1502
|
+
}, [e]), [t, n];
|
|
1503
|
+
}
|
|
1504
|
+
//#endregion
|
|
1505
|
+
//#region src/hooks/useFullscreen.ts
|
|
1506
|
+
var Ft = () => () => void 0;
|
|
1507
|
+
function It() {
|
|
1508
|
+
return typeof document < "u" && document.fullscreenEnabled === !0 && typeof HTMLElement.prototype.requestFullscreen == "function";
|
|
1509
|
+
}
|
|
1510
|
+
var Lt = "a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])";
|
|
1511
|
+
function Rt(e, t) {
|
|
1512
|
+
let n = [...t.querySelectorAll(Lt)].filter((e) => e.tabIndex >= 0 && e.getClientRects().length > 0), r = n[0], i = n.at(-1), a = t.ownerDocument.activeElement;
|
|
1513
|
+
if (!r || !i) {
|
|
1514
|
+
e.preventDefault();
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
e.shiftKey && (a === r || !t.contains(a)) ? (e.preventDefault(), i.focus()) : !e.shiftKey && (a === i || !t.contains(a)) && (e.preventDefault(), r.focus());
|
|
1518
|
+
}
|
|
1519
|
+
function zt({ mode: e, active: t, setActive: n, element: i }) {
|
|
1520
|
+
let a = u(Ft, It, () => !1), [o, s] = l(!1), d = c(n);
|
|
1521
|
+
L(() => {
|
|
1522
|
+
d.current = n;
|
|
1523
|
+
});
|
|
1524
|
+
let f = t ? e === "controlled" ? "layout" : e === "native" && a && !o ? "native" : "overlay" : "none";
|
|
1525
|
+
return r(() => {
|
|
1526
|
+
if (f !== "native" || !i) return;
|
|
1527
|
+
let e = i.ownerDocument;
|
|
1528
|
+
e.fullscreenElement !== i && i.requestFullscreen().catch(() => s(!0));
|
|
1529
|
+
let t = () => {
|
|
1530
|
+
e.fullscreenElement !== i && d.current(!1);
|
|
1531
|
+
};
|
|
1532
|
+
return e.addEventListener("fullscreenchange", t), () => {
|
|
1533
|
+
e.removeEventListener("fullscreenchange", t), e.fullscreenElement === i && e.exitFullscreen().catch(() => void 0);
|
|
1534
|
+
};
|
|
1535
|
+
}, [f, i]), !t && o && s(!1), r(() => {
|
|
1536
|
+
if (f !== "overlay" || !i) return;
|
|
1537
|
+
let e = window.document, t = e.activeElement instanceof HTMLElement ? e.activeElement : null, n = e.body.style.overflow;
|
|
1538
|
+
e.body.style.overflow = "hidden", i.focus({ preventScroll: !0 });
|
|
1539
|
+
let r = (e) => {
|
|
1540
|
+
e.key === "Escape" ? (e.preventDefault(), d.current(!1)) : e.key === "Tab" && Rt(e, i);
|
|
1541
|
+
};
|
|
1542
|
+
return e.addEventListener("keydown", r), () => {
|
|
1543
|
+
e.removeEventListener("keydown", r), e.body.style.overflow = n, t?.focus({ preventScroll: !0 });
|
|
1544
|
+
};
|
|
1545
|
+
}, [f, i]), f;
|
|
1546
|
+
}
|
|
1547
|
+
//#endregion
|
|
1548
|
+
//#region src/hooks/useKeyboardShortcuts.ts
|
|
1549
|
+
function Bt(e) {
|
|
1550
|
+
return e instanceof HTMLElement && (e.isContentEditable || [
|
|
1551
|
+
"INPUT",
|
|
1552
|
+
"TEXTAREA",
|
|
1553
|
+
"SELECT"
|
|
1554
|
+
].includes(e.tagName));
|
|
1555
|
+
}
|
|
1556
|
+
function Vt(e, t) {
|
|
1557
|
+
return !e || e.scrollWidth <= e.clientWidth ? !1 : t < 0 ? e.scrollLeft > 0 : e.scrollLeft + e.clientWidth < e.scrollWidth - 1;
|
|
1558
|
+
}
|
|
1559
|
+
function Ht(e, t) {
|
|
1560
|
+
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey || Bt(e.target) || e.shiftKey && /^(Arrow|Page|Home|End)/.test(e.key) || e.target instanceof Element && e.target.closest("[role=\"toolbar\"]") !== null && [
|
|
1561
|
+
"ArrowLeft",
|
|
1562
|
+
"ArrowRight",
|
|
1563
|
+
"Home",
|
|
1564
|
+
"End"
|
|
1565
|
+
].includes(e.key)) return null;
|
|
1566
|
+
switch (e.key) {
|
|
1567
|
+
case "PageUp": return "previousPage";
|
|
1568
|
+
case "PageDown": return "nextPage";
|
|
1569
|
+
case "ArrowLeft": return Vt(t, -1) ? null : "previousPage";
|
|
1570
|
+
case "ArrowRight": return Vt(t, 1) ? null : "nextPage";
|
|
1571
|
+
case "Home": return "firstPage";
|
|
1572
|
+
case "End": return "lastPage";
|
|
1573
|
+
case "+":
|
|
1574
|
+
case "=": return "zoomIn";
|
|
1575
|
+
case "-":
|
|
1576
|
+
case "_": return "zoomOut";
|
|
1577
|
+
case "0": return "resetZoom";
|
|
1578
|
+
case "r": return "rotateCw";
|
|
1579
|
+
case "R": return "rotateCcw";
|
|
1580
|
+
case "f":
|
|
1581
|
+
case "F": return "toggleFullscreen";
|
|
1582
|
+
default: return null;
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
function Ut({ enabled: e, element: t, viewport: n, api: i }) {
|
|
1586
|
+
let a = c({
|
|
1587
|
+
api: i,
|
|
1588
|
+
viewport: n
|
|
1589
|
+
});
|
|
1590
|
+
L(() => {
|
|
1591
|
+
a.current = {
|
|
1592
|
+
api: i,
|
|
1593
|
+
viewport: n
|
|
1594
|
+
};
|
|
1595
|
+
}), r(() => {
|
|
1596
|
+
if (!e || !t) return;
|
|
1597
|
+
let n = (e) => {
|
|
1598
|
+
let { api: t, viewport: n } = a.current, r = Ht(e, n);
|
|
1599
|
+
if (r) switch (e.preventDefault(), r) {
|
|
1600
|
+
case "previousPage":
|
|
1601
|
+
t.previousPage();
|
|
1602
|
+
break;
|
|
1603
|
+
case "nextPage":
|
|
1604
|
+
t.nextPage();
|
|
1605
|
+
break;
|
|
1606
|
+
case "firstPage":
|
|
1607
|
+
t.goToPage(1);
|
|
1608
|
+
break;
|
|
1609
|
+
case "lastPage":
|
|
1610
|
+
t.goToPage(t.numPages);
|
|
1611
|
+
break;
|
|
1612
|
+
case "zoomIn":
|
|
1613
|
+
t.zoomIn();
|
|
1614
|
+
break;
|
|
1615
|
+
case "zoomOut":
|
|
1616
|
+
t.zoomOut();
|
|
1617
|
+
break;
|
|
1618
|
+
case "resetZoom":
|
|
1619
|
+
t.resetZoom();
|
|
1620
|
+
break;
|
|
1621
|
+
case "rotateCw":
|
|
1622
|
+
t.rotate("cw");
|
|
1623
|
+
break;
|
|
1624
|
+
case "rotateCcw":
|
|
1625
|
+
t.rotate("ccw");
|
|
1626
|
+
break;
|
|
1627
|
+
case "toggleFullscreen": t.toggleFullscreen();
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
return t.addEventListener("keydown", n), () => t.removeEventListener("keydown", n);
|
|
1631
|
+
}, [e, t]);
|
|
1632
|
+
}
|
|
1633
|
+
//#endregion
|
|
1634
|
+
//#region src/hooks/useMediaQuery.ts
|
|
1635
|
+
var Wt = () => typeof window < "u" && typeof window.matchMedia == "function";
|
|
1636
|
+
function Gt(e) {
|
|
1637
|
+
let t = n((t) => {
|
|
1638
|
+
if (!Wt()) return () => void 0;
|
|
1639
|
+
let n = window.matchMedia(e);
|
|
1640
|
+
return n.addEventListener("change", t), () => n.removeEventListener("change", t);
|
|
1641
|
+
}, [e]);
|
|
1642
|
+
return u(t, () => Wt() && window.matchMedia(e).matches, () => !1);
|
|
1643
|
+
}
|
|
1644
|
+
//#endregion
|
|
1645
|
+
//#region src/core/loadSource.ts
|
|
1646
|
+
function Kt(e) {
|
|
1647
|
+
return e == null || e === "";
|
|
1648
|
+
}
|
|
1649
|
+
function qt(e) {
|
|
1650
|
+
return typeof e == "object" && !!e && typeof e.arrayBuffer == "function" && typeof e.size == "number";
|
|
1651
|
+
}
|
|
1652
|
+
function Jt(e) {
|
|
1653
|
+
return typeof e == "object" && !!e;
|
|
1654
|
+
}
|
|
1655
|
+
async function Yt(e) {
|
|
1656
|
+
let t = `Failed to fetch PDF: ${e.status} ${e.statusText}`;
|
|
1657
|
+
try {
|
|
1658
|
+
let n = await e.clone().json();
|
|
1659
|
+
Jt(n) && n.detail ? t = String(n.detail) : Jt(n) && n.title ? t = String(n.title) : typeof n == "string" && (t = n);
|
|
1660
|
+
} catch {}
|
|
1661
|
+
return t;
|
|
1662
|
+
}
|
|
1663
|
+
function Xt(e, t) {
|
|
1664
|
+
if (!t) return e;
|
|
1665
|
+
if (typeof AbortSignal.any == "function") return AbortSignal.any([e, t]);
|
|
1666
|
+
let n = new AbortController(), r = (e) => () => n.abort(e.reason);
|
|
1667
|
+
for (let i of [e, t]) {
|
|
1668
|
+
if (i.aborted) return n.abort(i.reason), n.signal;
|
|
1669
|
+
i.addEventListener("abort", r(i), { once: !0 });
|
|
1670
|
+
}
|
|
1671
|
+
return n.signal;
|
|
1672
|
+
}
|
|
1673
|
+
async function Zt(e, t, n) {
|
|
1674
|
+
let r = {
|
|
1675
|
+
...n.requestInit,
|
|
1676
|
+
signal: Xt(t, n.requestInit?.signal)
|
|
1677
|
+
}, i;
|
|
1678
|
+
try {
|
|
1679
|
+
i = n.fetcher ? await n.fetcher(e, r) : await fetch(e, r);
|
|
1680
|
+
} catch (e) {
|
|
1681
|
+
throw t.aborted || Ce(e) ? e : be("NETWORK_ERROR", e instanceof Error && !(e instanceof TypeError) && e.message ? e.message : void 0, { cause: e });
|
|
1682
|
+
}
|
|
1683
|
+
if (!i.ok) {
|
|
1684
|
+
let e = n.onHttpError ? await n.onHttpError(i) : void 0;
|
|
1685
|
+
if (t.throwIfAborted(), e === !0) return { kind: "handled" };
|
|
1686
|
+
throw be("HTTP_ERROR", await n.getHttpErrorMessage?.(i) ?? await Yt(i), { status: i.status });
|
|
1687
|
+
}
|
|
1688
|
+
let a = await i.arrayBuffer();
|
|
1689
|
+
return t.throwIfAborted(), {
|
|
1690
|
+
kind: "bytes",
|
|
1691
|
+
data: new Uint8Array(a)
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
async function Q(e, t, n = {}) {
|
|
1695
|
+
if (t.throwIfAborted(), typeof e == "string" || e instanceof URL) return Zt(e.toString(), t, n);
|
|
1696
|
+
if (qt(e)) {
|
|
1697
|
+
let n = await e.arrayBuffer();
|
|
1698
|
+
return t.throwIfAborted(), {
|
|
1699
|
+
kind: "bytes",
|
|
1700
|
+
data: new Uint8Array(n)
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
if (ArrayBuffer.isView(e)) {
|
|
1704
|
+
let { buffer: t, byteOffset: n, byteLength: r } = e;
|
|
1705
|
+
return {
|
|
1706
|
+
kind: "bytes",
|
|
1707
|
+
data: new Uint8Array(t.slice(n, n + r))
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
return {
|
|
1711
|
+
kind: "bytes",
|
|
1712
|
+
data: new Uint8Array(e.slice(0))
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
//#endregion
|
|
1716
|
+
//#region src/hooks/usePdfDocument.ts
|
|
1717
|
+
function Qt(e, t = {}) {
|
|
1718
|
+
let { password: i } = t, [a, o] = l(0), [s, u] = l(null), d = c(t);
|
|
1719
|
+
L(() => {
|
|
1720
|
+
d.current = t;
|
|
1721
|
+
}), r(() => {
|
|
1722
|
+
if (Kt(e)) return;
|
|
1723
|
+
let t = !1, n = null, r = new AbortController(), o = (n) => {
|
|
1724
|
+
t || u({
|
|
1725
|
+
source: e,
|
|
1726
|
+
password: i,
|
|
1727
|
+
attempt: a,
|
|
1728
|
+
...n
|
|
1729
|
+
});
|
|
1730
|
+
};
|
|
1731
|
+
return (async () => {
|
|
1732
|
+
let a = await Ne(), s = await Q(e, r.signal, d.current);
|
|
1733
|
+
if (t) return;
|
|
1734
|
+
if (s.kind === "handled") {
|
|
1735
|
+
o({
|
|
1736
|
+
status: "idle",
|
|
1737
|
+
document: null,
|
|
1738
|
+
error: null
|
|
1739
|
+
});
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
n = a.getDocument({
|
|
1743
|
+
...Pe(a),
|
|
1744
|
+
...d.current.pdfjsOptions,
|
|
1745
|
+
data: s.data,
|
|
1746
|
+
...i === void 0 ? {} : { password: i }
|
|
1747
|
+
});
|
|
1748
|
+
let c = await n.promise;
|
|
1749
|
+
t || (o({
|
|
1750
|
+
status: "ready",
|
|
1751
|
+
document: c,
|
|
1752
|
+
error: null
|
|
1753
|
+
}), d.current.onLoad?.(c));
|
|
1754
|
+
})().catch((e) => {
|
|
1755
|
+
if (t || Ce(e)) return;
|
|
1756
|
+
let n = we(e, "UNKNOWN");
|
|
1757
|
+
o({
|
|
1758
|
+
status: "error",
|
|
1759
|
+
document: null,
|
|
1760
|
+
error: n
|
|
1761
|
+
}), d.current.onError?.(n);
|
|
1762
|
+
}), () => {
|
|
1763
|
+
t = !0, r.abort(), n?.destroy();
|
|
1764
|
+
};
|
|
1765
|
+
}, [
|
|
1766
|
+
e,
|
|
1767
|
+
i,
|
|
1768
|
+
a
|
|
1769
|
+
]);
|
|
1770
|
+
let f = n(() => o((e) => e + 1), []), p = s !== null && Object.is(s.source, e) && s.password === i && s.attempt === a ? s : null, m = p ? p.status : Kt(e) ? "idle" : "loading", h = p?.document ?? null;
|
|
1771
|
+
return {
|
|
1772
|
+
status: m,
|
|
1773
|
+
document: h,
|
|
1774
|
+
numPages: h?.numPages ?? 0,
|
|
1775
|
+
error: p?.error ?? null,
|
|
1776
|
+
reload: f
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
//#endregion
|
|
1780
|
+
//#region src/PdfViewer.tsx
|
|
1781
|
+
var $t = () => () => void 0;
|
|
1782
|
+
function en(e) {
|
|
1783
|
+
if (typeof e != "string" && !(e instanceof URL)) return null;
|
|
1784
|
+
try {
|
|
1785
|
+
let t = new URL(e.toString(), window.location.href);
|
|
1786
|
+
return t.protocol === "http:" || t.protocol === "https:" ? t.href : null;
|
|
1787
|
+
} catch {
|
|
1788
|
+
return null;
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
async function tn(e, t, n) {
|
|
1792
|
+
let r = n ? en(t) : null;
|
|
1793
|
+
if (r) {
|
|
1794
|
+
window.open(r, "_blank", "noopener,noreferrer");
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
let i = URL.createObjectURL(X(await e.getData()));
|
|
1798
|
+
window.open(i, "_blank", "noopener,noreferrer"), setTimeout(() => URL.revokeObjectURL(i), 6e4);
|
|
1799
|
+
}
|
|
1800
|
+
function nn(e, t) {
|
|
1801
|
+
let n = t.getBoundingClientRect(), r = e.getBoundingClientRect();
|
|
1802
|
+
(n.top < r.top || n.bottom > r.bottom) && (e.scrollTop += n.top - r.top - (r.height - n.height) / 2), (n.left < r.left || n.right > r.right) && (e.scrollLeft += n.left - r.left - (r.width - n.width) / 2);
|
|
1803
|
+
}
|
|
1804
|
+
var rn = e(function(e, t) {
|
|
1805
|
+
let { source: i, fileName: o, page: f, defaultPage: h = 1, onPageChange: g, scale: y, defaultScale: b = 1, onScaleChange: x, rotation: S, defaultRotation: C = 0, onRotationChange: w, fullscreen: T, defaultFullscreen: E = !1, onFullscreenChange: O, fullscreenMode: k, minScale: A = $e, maxScale: j = 5, scaleStep: ee = et, zoomLevels: te, fitWidthAtDefaultScale: ne = !0, fitMode: re = "none", requestInit: ie, fetcher: ae, onHttpError: oe, getHttpErrorMessage: se, password: ce, pdfjsOptions: M, layout: le = "single", textLayer: ue = !1, annotationLayer: de = !1, pageInput: _e = !1, zoomReset: ve = !1, wheelZoom: ye = !1, passwordPrompt: be = !1, renderPasswordPrompt: xe, thumbnails: Se = !1, search: N = !1, toolbar: Te = !0, compactBreakpoint: Ee = 960, keyboardShortcuts: P = !0, printMode: F = "render", maxCanvasPixels: De, labels: Oe, locale: ke, renderLoading: Ae, renderError: je, renderToolbar: Me, renderEmpty: Ne, onDocumentLoad: Pe, onPageRender: Fe, onError: Ie, onDownload: Le, onPrint: Re, className: ze, style: Be, id: Ve, "aria-label": He } = e, I = ut(Oe), Ue = lt(ke), R = s(() => ({
|
|
1806
|
+
minScale: A,
|
|
1807
|
+
maxScale: j,
|
|
1808
|
+
scaleStep: ee,
|
|
1809
|
+
zoomLevels: te
|
|
1810
|
+
}), [
|
|
1811
|
+
A,
|
|
1812
|
+
j,
|
|
1813
|
+
ee,
|
|
1814
|
+
te
|
|
1815
|
+
]), We = le === "continuous", Ge = ue || N, [Ke, z] = At({
|
|
1816
|
+
value: f,
|
|
1817
|
+
defaultValue: h,
|
|
1818
|
+
onChange: g,
|
|
1819
|
+
name: "page"
|
|
1820
|
+
}), [B, V] = At({
|
|
1821
|
+
value: y,
|
|
1822
|
+
defaultValue: b,
|
|
1823
|
+
onChange: x,
|
|
1824
|
+
name: "scale"
|
|
1825
|
+
}), [H, Ye] = At({
|
|
1826
|
+
value: S,
|
|
1827
|
+
defaultValue: C,
|
|
1828
|
+
onChange: w,
|
|
1829
|
+
name: "rotation"
|
|
1830
|
+
}), [Xe, Ze] = At({
|
|
1831
|
+
value: T,
|
|
1832
|
+
defaultValue: E,
|
|
1833
|
+
onChange: O,
|
|
1834
|
+
name: "fullscreen"
|
|
1835
|
+
}), tt = k ?? (T === void 0 ? "native" : "controlled"), U = c({
|
|
1836
|
+
onDownload: Le,
|
|
1837
|
+
onPrint: Re,
|
|
1838
|
+
onError: Ie,
|
|
1839
|
+
onDocumentLoad: Pe,
|
|
1840
|
+
onPageRender: Fe
|
|
1841
|
+
});
|
|
1842
|
+
L(() => {
|
|
1843
|
+
U.current = {
|
|
1844
|
+
onDownload: Le,
|
|
1845
|
+
onPrint: Re,
|
|
1846
|
+
onError: Ie,
|
|
1847
|
+
onDocumentLoad: Pe,
|
|
1848
|
+
onPageRender: Fe
|
|
1849
|
+
};
|
|
1850
|
+
});
|
|
1851
|
+
let [W, rt] = l(null), ot = ce ?? (W && Object.is(W.source, i) ? W.password : void 0), st = n((e) => {
|
|
1852
|
+
U.current.onDocumentLoad?.({
|
|
1853
|
+
numPages: e.numPages,
|
|
1854
|
+
fingerprint: e.fingerprints[0] ?? ""
|
|
1855
|
+
});
|
|
1856
|
+
}, []), ct = n((e) => {
|
|
1857
|
+
U.current.onError?.(e);
|
|
1858
|
+
}, []), { status: dt, document: G, numPages: K, error: q, reload: ft } = Qt(i, {
|
|
1859
|
+
requestInit: ie,
|
|
1860
|
+
fetcher: ae,
|
|
1861
|
+
onHttpError: oe,
|
|
1862
|
+
getHttpErrorMessage: se,
|
|
1863
|
+
password: ot,
|
|
1864
|
+
pdfjsOptions: M,
|
|
1865
|
+
onLoad: st,
|
|
1866
|
+
onError: ct
|
|
1867
|
+
}), pt = f !== void 0, mt = c(null);
|
|
1868
|
+
L(() => {
|
|
1869
|
+
if (!G) return;
|
|
1870
|
+
let e = mt.current;
|
|
1871
|
+
if (e?.document !== G && (mt.current = {
|
|
1872
|
+
document: G,
|
|
1873
|
+
source: i
|
|
1874
|
+
}, e && !Object.is(e.source, i) && !pt)) {
|
|
1875
|
+
z(_(h, G.numPages));
|
|
1876
|
+
return;
|
|
1877
|
+
}
|
|
1878
|
+
let t = _(Ke, G.numPages);
|
|
1879
|
+
t !== Ke && z(t);
|
|
1880
|
+
}, [
|
|
1881
|
+
G,
|
|
1882
|
+
i,
|
|
1883
|
+
Ke,
|
|
1884
|
+
h,
|
|
1885
|
+
pt,
|
|
1886
|
+
z
|
|
1887
|
+
]);
|
|
1888
|
+
let J = G ? _(Ke, K) : Ke, ht = it(B, 1, R) !== null, gt = it(B, -1, R) !== null, Y = Gt(`(max-width: ${Ee - .05}px)`), [_t, vt] = l(null), [yt, bt] = Pt(), [X, Ct] = l(null), wt = n((e) => {
|
|
1889
|
+
yt(e), Ct(e);
|
|
1890
|
+
}, [yt]), Et = zt({
|
|
1891
|
+
mode: tt,
|
|
1892
|
+
active: Xe,
|
|
1893
|
+
setActive: Ze,
|
|
1894
|
+
element: _t
|
|
1895
|
+
}), Dt = u($t, () => !0, () => !1), Ot;
|
|
1896
|
+
bt && nt(B, b) && (re === "width" ? Ot = {
|
|
1897
|
+
width: bt.width,
|
|
1898
|
+
upscale: !0
|
|
1899
|
+
} : re === "page" ? Ot = {
|
|
1900
|
+
width: bt.width,
|
|
1901
|
+
height: bt.height,
|
|
1902
|
+
upscale: !0
|
|
1903
|
+
} : ne && (Ot = { width: bt.width }));
|
|
1904
|
+
let Z = n((e) => {
|
|
1905
|
+
K > 0 && z(_(e, K));
|
|
1906
|
+
}, [K, z]), jt = n(() => z((e) => K > 0 ? _(e + 1, K) : e), [K, z]), Mt = n(() => z((e) => K > 0 ? _(e - 1, K) : e), [K, z]), Ft = n(() => V((e) => it(e, 1, R) ?? e), [R, V]), It = n(() => V((e) => it(e, -1, R) ?? e), [R, V]), Lt = n((e) => {
|
|
1907
|
+
Number.isFinite(e) && V(at(e, R));
|
|
1908
|
+
}, [R, V]), Rt = n(() => V(b), [b, V]), Bt = n((e = "cw") => Ye((t) => v(t + (e === "ccw" ? -90 : 90))), [Ye]), Vt = n(() => Ze((e) => !e), [Ze]), Ht = n(async () => {
|
|
1909
|
+
if (G) try {
|
|
1910
|
+
let e = await G.getData(), t = Tt(o, i);
|
|
1911
|
+
if (U.current.onDownload?.({
|
|
1912
|
+
fileName: t,
|
|
1913
|
+
data: e
|
|
1914
|
+
}) === !1) return;
|
|
1915
|
+
St(e, t);
|
|
1916
|
+
} catch (e) {
|
|
1917
|
+
U.current.onError?.(we(e, "DOWNLOAD_FAILED"));
|
|
1918
|
+
}
|
|
1919
|
+
}, [
|
|
1920
|
+
G,
|
|
1921
|
+
o,
|
|
1922
|
+
i
|
|
1923
|
+
]), [Wt, Kt] = l(null), qt = c(null), Jt = n(async () => {
|
|
1924
|
+
if (G && !qt.current && U.current.onPrint?.() !== !1) try {
|
|
1925
|
+
if (F === "open-url") {
|
|
1926
|
+
await tn(G, i, !ae && !ie);
|
|
1927
|
+
return;
|
|
1928
|
+
}
|
|
1929
|
+
let e = new AbortController();
|
|
1930
|
+
qt.current = e, Kt({
|
|
1931
|
+
done: 0,
|
|
1932
|
+
total: G.numPages
|
|
1933
|
+
}), await kt(G, {
|
|
1934
|
+
signal: e.signal,
|
|
1935
|
+
onProgress: (e, t) => Kt({
|
|
1936
|
+
done: e,
|
|
1937
|
+
total: t
|
|
1938
|
+
})
|
|
1939
|
+
});
|
|
1940
|
+
} catch (e) {
|
|
1941
|
+
Ce(e) || U.current.onError?.(we(e, "PRINT_FAILED"));
|
|
1942
|
+
} finally {
|
|
1943
|
+
qt.current = null, Kt(null);
|
|
1944
|
+
}
|
|
1945
|
+
}, [
|
|
1946
|
+
G,
|
|
1947
|
+
F,
|
|
1948
|
+
i,
|
|
1949
|
+
ae,
|
|
1950
|
+
ie
|
|
1951
|
+
]), Yt = n(() => qt.current?.abort(), []);
|
|
1952
|
+
r(() => () => qt.current?.abort(), []);
|
|
1953
|
+
let Xt = s(() => ({
|
|
1954
|
+
status: dt,
|
|
1955
|
+
numPages: K,
|
|
1956
|
+
page: J,
|
|
1957
|
+
scale: B,
|
|
1958
|
+
rotation: H,
|
|
1959
|
+
fullscreen: Xe,
|
|
1960
|
+
canZoomIn: ht,
|
|
1961
|
+
canZoomOut: gt,
|
|
1962
|
+
goToPage: Z,
|
|
1963
|
+
nextPage: jt,
|
|
1964
|
+
previousPage: Mt,
|
|
1965
|
+
zoomIn: Ft,
|
|
1966
|
+
zoomOut: It,
|
|
1967
|
+
setScale: Lt,
|
|
1968
|
+
resetZoom: Rt,
|
|
1969
|
+
rotate: Bt,
|
|
1970
|
+
toggleFullscreen: Vt,
|
|
1971
|
+
download: Ht,
|
|
1972
|
+
print: Jt,
|
|
1973
|
+
reload: ft,
|
|
1974
|
+
getDocument: () => G
|
|
1975
|
+
}), [
|
|
1976
|
+
dt,
|
|
1977
|
+
K,
|
|
1978
|
+
J,
|
|
1979
|
+
B,
|
|
1980
|
+
H,
|
|
1981
|
+
Xe,
|
|
1982
|
+
ht,
|
|
1983
|
+
gt,
|
|
1984
|
+
Z,
|
|
1985
|
+
jt,
|
|
1986
|
+
Mt,
|
|
1987
|
+
Ft,
|
|
1988
|
+
It,
|
|
1989
|
+
Lt,
|
|
1990
|
+
Rt,
|
|
1991
|
+
Bt,
|
|
1992
|
+
Vt,
|
|
1993
|
+
Ht,
|
|
1994
|
+
Jt,
|
|
1995
|
+
ft,
|
|
1996
|
+
G
|
|
1997
|
+
]);
|
|
1998
|
+
a(t, () => Xt, [Xt]), Ut({
|
|
1999
|
+
enabled: P,
|
|
2000
|
+
element: _t,
|
|
2001
|
+
viewport: X,
|
|
2002
|
+
api: Xt
|
|
2003
|
+
});
|
|
2004
|
+
let Zt = c(null), [Q, en] = l(""), [rn, an] = l({
|
|
2005
|
+
query: "",
|
|
2006
|
+
index: null,
|
|
2007
|
+
fromPage: 1
|
|
2008
|
+
});
|
|
2009
|
+
rn.query !== Q && an({
|
|
2010
|
+
query: Q,
|
|
2011
|
+
index: null,
|
|
2012
|
+
fromPage: J
|
|
2013
|
+
});
|
|
2014
|
+
let { matches: $, searching: on } = Nt(N ? G : null, Q), sn = Math.max(0, $.findIndex((e) => e.page >= rn.fromPage)), cn = $.length === 0 ? 0 : Math.min(rn.index ?? sn, $.length - 1), ln = $[cn], un = n((e) => {
|
|
2015
|
+
$.length !== 0 && an((t) => ({
|
|
2016
|
+
...t,
|
|
2017
|
+
index: (cn + e + $.length) % $.length
|
|
2018
|
+
}));
|
|
2019
|
+
}, [$.length, cn]), dn = ln?.page;
|
|
2020
|
+
r(() => {
|
|
2021
|
+
dn !== void 0 && Z(dn);
|
|
2022
|
+
}, [
|
|
2023
|
+
dn,
|
|
2024
|
+
cn,
|
|
2025
|
+
Q,
|
|
2026
|
+
Z
|
|
2027
|
+
]);
|
|
2028
|
+
let fn = n((e) => N && Q.trim() ? {
|
|
2029
|
+
query: Q,
|
|
2030
|
+
selected: ln?.page === e ? ln.index : null
|
|
2031
|
+
} : void 0, [
|
|
2032
|
+
N,
|
|
2033
|
+
Q,
|
|
2034
|
+
ln
|
|
2035
|
+
]), pn = n((e) => {
|
|
2036
|
+
X && nn(X, e);
|
|
2037
|
+
}, [X]);
|
|
2038
|
+
r(() => {
|
|
2039
|
+
if (!N || !_t) return;
|
|
2040
|
+
let e = (e) => {
|
|
2041
|
+
(e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "f" && (e.preventDefault(), Zt.current?.focus(), Zt.current?.select());
|
|
2042
|
+
};
|
|
2043
|
+
return _t.addEventListener("keydown", e), () => _t.removeEventListener("keydown", e);
|
|
2044
|
+
}, [N, _t]);
|
|
2045
|
+
let mn = c(null), hn = c({
|
|
2046
|
+
scale: B,
|
|
2047
|
+
zoom: R,
|
|
2048
|
+
displayPage: J
|
|
2049
|
+
});
|
|
2050
|
+
L(() => {
|
|
2051
|
+
hn.current = {
|
|
2052
|
+
scale: B,
|
|
2053
|
+
zoom: R,
|
|
2054
|
+
displayPage: J
|
|
2055
|
+
};
|
|
2056
|
+
}), r(() => {
|
|
2057
|
+
if (!ye || !X) return;
|
|
2058
|
+
let e, t = 1, n = (t, n, r) => {
|
|
2059
|
+
let i = (t instanceof Element ? t.closest(".rpv-page") : null) ?? X.querySelector(".rpv-page");
|
|
2060
|
+
if (!i) {
|
|
2061
|
+
mn.current = null;
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
let a = i.getBoundingClientRect(), o = i.closest(".rpv-page-slot");
|
|
2065
|
+
mn.current = {
|
|
2066
|
+
page: o ? Number(o.dataset.page) : hn.current.displayPage,
|
|
2067
|
+
fx: a.width ? (n - a.left) / a.width : 0,
|
|
2068
|
+
fy: a.height ? (r - a.top) / a.height : 0,
|
|
2069
|
+
clientX: n,
|
|
2070
|
+
clientY: r
|
|
2071
|
+
}, clearTimeout(e), e = setTimeout(() => {
|
|
2072
|
+
mn.current = null;
|
|
2073
|
+
}, 1500);
|
|
2074
|
+
}, r = (e) => {
|
|
2075
|
+
if (!(e.ctrlKey || e.metaKey)) return;
|
|
2076
|
+
e.preventDefault(), n(e.target, e.clientX, e.clientY);
|
|
2077
|
+
let t = Math.exp(-e.deltaY * (e.deltaMode === 1 ? .05 : .002));
|
|
2078
|
+
V((e) => at(e * t, hn.current.zoom));
|
|
2079
|
+
}, i = (e) => {
|
|
2080
|
+
e.preventDefault(), t = hn.current.scale;
|
|
2081
|
+
}, a = (e) => {
|
|
2082
|
+
e.preventDefault();
|
|
2083
|
+
let r = e;
|
|
2084
|
+
n(e.target, r.clientX ?? 0, r.clientY ?? 0), V(at(t * (r.scale ?? 1), hn.current.zoom));
|
|
2085
|
+
};
|
|
2086
|
+
return X.addEventListener("wheel", r, { passive: !1 }), X.addEventListener("gesturestart", i), X.addEventListener("gesturechange", a), () => {
|
|
2087
|
+
clearTimeout(e), X.removeEventListener("wheel", r), X.removeEventListener("gesturestart", i), X.removeEventListener("gesturechange", a);
|
|
2088
|
+
};
|
|
2089
|
+
}, [
|
|
2090
|
+
ye,
|
|
2091
|
+
X,
|
|
2092
|
+
V
|
|
2093
|
+
]);
|
|
2094
|
+
let gn = n((e) => {
|
|
2095
|
+
U.current.onPageRender?.(e);
|
|
2096
|
+
let t = mn.current;
|
|
2097
|
+
if (!t || t.page !== e.page || !X) return;
|
|
2098
|
+
let n = We ? X.querySelector(`.rpv-page-slot[data-page="${e.page}"] > .rpv-page`) : X.querySelector(".rpv-page");
|
|
2099
|
+
if (!(n instanceof HTMLElement)) return;
|
|
2100
|
+
let r = n.getBoundingClientRect();
|
|
2101
|
+
X.scrollLeft += r.left + t.fx * r.width - t.clientX, X.scrollTop += r.top + t.fy * r.height - t.clientY;
|
|
2102
|
+
}, [We, X]), _n = typeof Te == "object" ? Te : void 0, vn = _n?.position ?? "bottom", yn = Te === !1 ? null : /* @__PURE__ */ p("div", {
|
|
2103
|
+
className: "rpv-toolbar-wrapper",
|
|
2104
|
+
children: Me ? Me(Xt) : /* @__PURE__ */ p(xt, {
|
|
2105
|
+
api: Xt,
|
|
2106
|
+
labels: I,
|
|
2107
|
+
config: _n,
|
|
2108
|
+
compact: Y,
|
|
2109
|
+
locale: ke,
|
|
2110
|
+
zoomReset: ve,
|
|
2111
|
+
menuPlacement: vn === "top" ? "bottom" : "top",
|
|
2112
|
+
pageIndicator: _e ? /* @__PURE__ */ p(he, {
|
|
2113
|
+
page: J,
|
|
2114
|
+
numPages: K,
|
|
2115
|
+
label: I.pageInput,
|
|
2116
|
+
context: Ue,
|
|
2117
|
+
onCommit: Z
|
|
2118
|
+
}) : void 0
|
|
2119
|
+
})
|
|
2120
|
+
}), bn = n((e, t) => je ? je(e, t) : /* @__PURE__ */ p(fe, {
|
|
2121
|
+
variant: "page",
|
|
2122
|
+
message: e.message,
|
|
2123
|
+
retryLabel: I.retry,
|
|
2124
|
+
onRetry: t.retry
|
|
2125
|
+
}), [je, I.retry]), xn = n((e, t) => G ? /* @__PURE__ */ p(qe, {
|
|
2126
|
+
document: G,
|
|
2127
|
+
page: e,
|
|
2128
|
+
scale: t,
|
|
2129
|
+
rotation: H,
|
|
2130
|
+
maxCanvasPixels: De,
|
|
2131
|
+
textLayer: Ge,
|
|
2132
|
+
annotationLayer: de,
|
|
2133
|
+
highlight: fn(e),
|
|
2134
|
+
"aria-label": I.pageAriaLabel(e, K, Ue),
|
|
2135
|
+
renderError: bn,
|
|
2136
|
+
onRender: gn,
|
|
2137
|
+
onError: ct,
|
|
2138
|
+
onLinkNavigate: Z,
|
|
2139
|
+
onHighlight: pn
|
|
2140
|
+
}) : null, [
|
|
2141
|
+
G,
|
|
2142
|
+
H,
|
|
2143
|
+
De,
|
|
2144
|
+
Ge,
|
|
2145
|
+
de,
|
|
2146
|
+
fn,
|
|
2147
|
+
I,
|
|
2148
|
+
K,
|
|
2149
|
+
Ue,
|
|
2150
|
+
bn,
|
|
2151
|
+
gn,
|
|
2152
|
+
ct,
|
|
2153
|
+
Z,
|
|
2154
|
+
pn
|
|
2155
|
+
]), Sn = be && (q?.code === "PASSWORD_REQUIRED" || q?.code === "INCORRECT_PASSWORD"), Cn = n((e) => {
|
|
2156
|
+
W && Object.is(W.source, i) && W.password === e ? ft() : rt({
|
|
2157
|
+
source: i,
|
|
2158
|
+
password: e
|
|
2159
|
+
});
|
|
2160
|
+
}, [
|
|
2161
|
+
W,
|
|
2162
|
+
i,
|
|
2163
|
+
ft
|
|
2164
|
+
]), wn;
|
|
2165
|
+
wn = dt === "error" && q ? /* @__PURE__ */ p("div", {
|
|
2166
|
+
className: "rpv-error-area",
|
|
2167
|
+
children: Sn ? xe ? xe({
|
|
2168
|
+
incorrect: q.code === "INCORRECT_PASSWORD",
|
|
2169
|
+
submit: Cn
|
|
2170
|
+
}) : /* @__PURE__ */ p("div", {
|
|
2171
|
+
className: "rpv-password-area",
|
|
2172
|
+
children: /* @__PURE__ */ p(ge, {
|
|
2173
|
+
labels: I,
|
|
2174
|
+
incorrect: q.code === "INCORRECT_PASSWORD",
|
|
2175
|
+
onSubmit: Cn
|
|
2176
|
+
})
|
|
2177
|
+
}) : je ? je(q, { retry: ft }) : /* @__PURE__ */ p(fe, {
|
|
2178
|
+
message: q.message,
|
|
2179
|
+
retryLabel: I.retry,
|
|
2180
|
+
onRetry: ft
|
|
2181
|
+
})
|
|
2182
|
+
}) : /* @__PURE__ */ m("div", {
|
|
2183
|
+
ref: wt,
|
|
2184
|
+
className: "rpv-viewport",
|
|
2185
|
+
role: "group",
|
|
2186
|
+
"aria-label": I.document,
|
|
2187
|
+
tabIndex: 0,
|
|
2188
|
+
children: [
|
|
2189
|
+
dt === "loading" && (Ae ? Ae() : /* @__PURE__ */ p(me, { label: I.loading })),
|
|
2190
|
+
dt === "idle" && (Ne ? Ne() : /* @__PURE__ */ p("p", {
|
|
2191
|
+
className: "rpv-sr-only",
|
|
2192
|
+
children: I.empty
|
|
2193
|
+
})),
|
|
2194
|
+
G && (We ? /* @__PURE__ */ p(D, {
|
|
2195
|
+
document: G,
|
|
2196
|
+
numPages: K,
|
|
2197
|
+
page: J,
|
|
2198
|
+
onVisiblePageChange: Z,
|
|
2199
|
+
scale: B,
|
|
2200
|
+
rotation: H,
|
|
2201
|
+
fit: Ot,
|
|
2202
|
+
scroller: X,
|
|
2203
|
+
renderPage: xn
|
|
2204
|
+
}) : /* @__PURE__ */ p(qe, {
|
|
2205
|
+
document: G,
|
|
2206
|
+
page: J,
|
|
2207
|
+
scale: B,
|
|
2208
|
+
rotation: H,
|
|
2209
|
+
fit: Ot,
|
|
2210
|
+
maxCanvasPixels: De,
|
|
2211
|
+
textLayer: Ge,
|
|
2212
|
+
annotationLayer: de,
|
|
2213
|
+
highlight: fn(J),
|
|
2214
|
+
"aria-label": I.pageAriaLabel(J, K, Ue),
|
|
2215
|
+
renderError: bn,
|
|
2216
|
+
onRender: gn,
|
|
2217
|
+
onError: ct,
|
|
2218
|
+
onLinkNavigate: Z,
|
|
2219
|
+
onHighlight: pn
|
|
2220
|
+
}))
|
|
2221
|
+
]
|
|
2222
|
+
});
|
|
2223
|
+
let Tn = Se && G !== null && !(Y && Et === "none") ? /* @__PURE__ */ m("div", {
|
|
2224
|
+
className: "rpv-body",
|
|
2225
|
+
children: [/* @__PURE__ */ p(Qe, {
|
|
2226
|
+
document: G,
|
|
2227
|
+
numPages: K,
|
|
2228
|
+
page: J,
|
|
2229
|
+
rotation: H,
|
|
2230
|
+
onSelect: Z,
|
|
2231
|
+
labels: I,
|
|
2232
|
+
context: Ue
|
|
2233
|
+
}), wn]
|
|
2234
|
+
}) : wn, En = Et === "overlay", Dn = /* @__PURE__ */ m("section", {
|
|
2235
|
+
ref: vt,
|
|
2236
|
+
id: Ve,
|
|
2237
|
+
className: ze ? `rpv-root ${ze}` : "rpv-root",
|
|
2238
|
+
style: Be,
|
|
2239
|
+
"aria-label": He ?? I.viewer,
|
|
2240
|
+
role: En ? "dialog" : void 0,
|
|
2241
|
+
"aria-modal": En ? !0 : void 0,
|
|
2242
|
+
tabIndex: -1,
|
|
2243
|
+
"data-status": dt,
|
|
2244
|
+
"data-layout": le,
|
|
2245
|
+
"data-compact": Y ? "" : void 0,
|
|
2246
|
+
"data-fullscreen": Et === "none" ? void 0 : "",
|
|
2247
|
+
"data-presentation": Et === "none" ? void 0 : Et,
|
|
2248
|
+
"data-zoomed": B > b && !nt(B, b) ? "" : void 0,
|
|
2249
|
+
"data-toolbar-position": vn,
|
|
2250
|
+
children: [
|
|
2251
|
+
vn === "top" && yn,
|
|
2252
|
+
N && /* @__PURE__ */ p(Je, {
|
|
2253
|
+
inputRef: Zt,
|
|
2254
|
+
query: Q,
|
|
2255
|
+
onQueryChange: en,
|
|
2256
|
+
total: $.length,
|
|
2257
|
+
current: cn,
|
|
2258
|
+
searching: on,
|
|
2259
|
+
onNext: () => un(1),
|
|
2260
|
+
onPrevious: () => un(-1),
|
|
2261
|
+
labels: I,
|
|
2262
|
+
context: Ue
|
|
2263
|
+
}),
|
|
2264
|
+
Tn,
|
|
2265
|
+
vn === "bottom" && yn,
|
|
2266
|
+
Wt && /* @__PURE__ */ m("div", {
|
|
2267
|
+
className: "rpv-print-status",
|
|
2268
|
+
role: "status",
|
|
2269
|
+
children: [
|
|
2270
|
+
/* @__PURE__ */ p(pe, {}),
|
|
2271
|
+
/* @__PURE__ */ p("p", {
|
|
2272
|
+
className: "rpv-print-status__text",
|
|
2273
|
+
children: I.printProgress(Wt.done, Wt.total, Ue)
|
|
2274
|
+
}),
|
|
2275
|
+
/* @__PURE__ */ p("button", {
|
|
2276
|
+
type: "button",
|
|
2277
|
+
className: "rpv-text-button",
|
|
2278
|
+
onClick: Yt,
|
|
2279
|
+
children: I.cancel
|
|
2280
|
+
})
|
|
2281
|
+
]
|
|
2282
|
+
})
|
|
2283
|
+
]
|
|
2284
|
+
});
|
|
2285
|
+
return En && Dt ? d(Dn, window.document.body) : Dn;
|
|
2286
|
+
});
|
|
2287
|
+
//#endregion
|
|
2288
|
+
export { qe as PdfPageCanvas, xt as PdfToolbar, rn as PdfViewer, Me as configurePdfJs, st as defaultLabels, At as useControllableState, Qt as usePdfDocument };
|
|
2289
|
+
|
|
2290
|
+
//# sourceMappingURL=index.js.map
|