pdf-tsx 0.16.2 → 0.17.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/README.md +14 -0
- package/dist/cjs/components/PDFSidebar.cjs +1 -1
- package/dist/cjs/components/PDFViewer.cjs +1 -1
- package/dist/cjs/components/PDFViewer.module.cjs +1 -1
- package/dist/cjs/components/features/PDFAnnotations.cjs +1 -1
- package/dist/cjs/components/features/PDFAttachments.cjs +1 -1
- package/dist/cjs/components/features/PDFChangeFile.cjs +1 -1
- package/dist/cjs/components/features/PDFDownloadButton.cjs +1 -1
- package/dist/cjs/components/features/PDFNavigation.cjs +1 -1
- package/dist/cjs/components/features/PDFOutline.cjs +1 -1
- package/dist/cjs/components/features/PDFPageFit.cjs +1 -1
- package/dist/cjs/components/features/PDFPrintButton.cjs +1 -1
- package/dist/cjs/components/features/PDFRotationControl.cjs +1 -1
- package/dist/cjs/components/features/PDFSearch.cjs +1 -1
- package/dist/cjs/components/features/PDFSidebarToggle.cjs +1 -1
- package/dist/cjs/components/features/PDFSignatures.cjs +1 -1
- package/dist/cjs/components/features/PDFThemeToggle.cjs +1 -1
- package/dist/cjs/components/features/PDFThumbnails.cjs +1 -1
- package/dist/cjs/components/features/PDFZoomControls.cjs +1 -1
- package/dist/cjs/components/ui/PDFToolbar.cjs +1 -1
- package/dist/cjs/components/ui/PDFToolbarDropdownContext.cjs +1 -1
- package/dist/cjs/components/ui/PDFToolbarItem.cjs +1 -1
- package/dist/cjs/components/ui/PDFToolbarSeparator.cjs +1 -1
- package/dist/cjs/components/ui/ToolbarButton.cjs +1 -1
- package/dist/cjs/components/ui/icons.cjs +1 -1
- package/dist/cjs/context/LabelsContext.cjs +1 -1
- package/dist/cjs/context/PDFViewerContext.cjs +1 -1
- package/dist/cjs/context/ThemeContext.cjs +1 -1
- package/dist/cjs/context/labelsContextValue.cjs +1 -1
- package/dist/cjs/context/themeContextValue.cjs +1 -1
- package/dist/cjs/hooks/useAnnotationLayer.cjs +1 -1
- package/dist/cjs/hooks/useAnnotations.cjs +1 -1
- package/dist/cjs/hooks/useAttachments.cjs +1 -1
- package/dist/cjs/hooks/useKeyboardShortcuts.cjs +1 -1
- package/dist/cjs/hooks/useLabels.cjs +1 -1
- package/dist/cjs/hooks/useOutline.cjs +1 -1
- package/dist/cjs/hooks/useOverlayRects.cjs +1 -1
- package/dist/cjs/hooks/usePDFLoader.cjs +1 -1
- package/dist/cjs/hooks/usePDFRenderer.cjs +1 -1
- package/dist/cjs/hooks/usePinchZoom.cjs +1 -0
- package/dist/cjs/hooks/useScrollTracking.cjs +1 -1
- package/dist/cjs/hooks/useSignatures.cjs +1 -1
- package/dist/cjs/hooks/useTextLayer.cjs +1 -1
- package/dist/cjs/hooks/useTextSearch.cjs +1 -1
- package/dist/cjs/hooks/useTheme.cjs +1 -1
- package/dist/cjs/hooks/useThumbnails.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/pdf-tsx.css +1 -1
- package/dist/components/PDFViewer.d.ts +2 -2
- package/dist/es/components/PDFViewer.js +118 -117
- package/dist/es/components/PDFViewer.module.js +23 -23
- package/dist/es/hooks/usePDFLoader.js +10 -13
- package/dist/es/hooks/usePDFRenderer.js +18 -15
- package/dist/es/hooks/usePinchZoom.js +58 -0
- package/dist/es/pdf-tsx.css +1 -1
- package/dist/src/components/PDFSidebar.d.ts +11 -0
- package/dist/src/components/PDFViewer.d.ts +22 -0
- package/dist/src/components/features/PDFAnnotations.d.ts +5 -0
- package/dist/src/components/features/PDFAttachments.d.ts +5 -0
- package/dist/src/components/features/PDFChangeFile.d.ts +9 -0
- package/dist/src/components/features/PDFDownloadButton.d.ts +9 -0
- package/dist/src/components/features/PDFNavigation.d.ts +10 -0
- package/dist/src/components/features/PDFOutline.d.ts +1 -0
- package/dist/src/components/features/PDFPageFit.d.ts +10 -0
- package/dist/src/components/features/PDFPrintButton.d.ts +9 -0
- package/dist/src/components/features/PDFRotationControl.d.ts +9 -0
- package/dist/src/components/features/PDFSearch.d.ts +13 -0
- package/dist/src/components/features/PDFSidebarToggle.d.ts +10 -0
- package/dist/src/components/features/PDFSignatures.d.ts +5 -0
- package/dist/src/components/features/PDFThemeToggle.d.ts +10 -0
- package/dist/src/components/features/PDFThumbnails.d.ts +1 -0
- package/dist/src/components/features/PDFZoomControls.d.ts +10 -0
- package/dist/src/components/ui/PDFToolbar.d.ts +8 -0
- package/dist/src/components/ui/PDFToolbarDropdownContext.d.ts +1 -0
- package/dist/src/components/ui/PDFToolbarItem.d.ts +7 -0
- package/dist/src/components/ui/PDFToolbarSeparator.d.ts +4 -0
- package/dist/src/components/ui/ToolbarButton.d.ts +6 -0
- package/dist/src/components/ui/icons.d.ts +7 -0
- package/dist/src/context/LabelsContext.d.ts +7 -0
- package/dist/src/context/PDFViewerContext.d.ts +30 -0
- package/dist/src/context/ThemeContext.d.ts +12 -0
- package/dist/src/context/labelsContextValue.d.ts +2 -0
- package/dist/src/context/themeContextValue.d.ts +7 -0
- package/dist/src/hooks/useAnnotationLayer.d.ts +34 -0
- package/dist/src/hooks/useAnnotations.d.ts +15 -0
- package/dist/src/hooks/useAttachments.d.ts +11 -0
- package/dist/src/hooks/useKeyboardShortcuts.d.ts +9 -0
- package/dist/src/hooks/useLabels.d.ts +2 -0
- package/dist/src/hooks/useOutline.d.ts +14 -0
- package/dist/src/hooks/useOverlayRects.d.ts +21 -0
- package/dist/src/hooks/usePDFLoader.d.ts +5 -0
- package/dist/src/hooks/usePDFRenderer.d.ts +16 -0
- package/dist/src/hooks/usePinchZoom.d.ts +1 -0
- package/dist/src/hooks/useScrollTracking.d.ts +10 -0
- package/dist/src/hooks/useSignatures.d.ts +17 -0
- package/dist/src/hooks/useTextLayer.d.ts +10 -0
- package/dist/src/hooks/useTextSearch.d.ts +12 -0
- package/dist/src/hooks/useTheme.d.ts +2 -0
- package/dist/src/hooks/useThumbnails.d.ts +10 -0
- package/dist/src/index.d.ts +24 -0
- package/dist/src/labels.d.ts +53 -0
- package/dist/src/theme.d.ts +27 -0
- package/dist/src/utils/pdfFit.d.ts +2 -0
- package/dist/src/utils/url.d.ts +1 -0
- package/dist/wasm/LICENSE_JBIG2 +196 -0
- package/dist/wasm/LICENSE_OPENJPEG +39 -0
- package/dist/wasm/LICENSE_PDFJS_JBIG2 +13 -0
- package/dist/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
- package/dist/wasm/LICENSE_PDFJS_QCMS +22 -0
- package/dist/wasm/LICENSE_QCMS +21 -0
- package/dist/wasm/jbig2.wasm +0 -0
- package/dist/wasm/jbig2_nowasm_fallback.js +15 -0
- package/dist/wasm/openjpeg.wasm +0 -0
- package/dist/wasm/openjpeg_nowasm_fallback.js +17 -0
- package/dist/wasm/qcms_bg.wasm +0 -0
- package/dist/wasm/quickjs-eval.js +16 -0
- package/dist/wasm/quickjs-eval.wasm +0 -0
- package/package.json +17 -17
|
@@ -2,7 +2,8 @@ import { default as React } from 'react';
|
|
|
2
2
|
import { Theme } from '../theme';
|
|
3
3
|
interface PDFViewerProps {
|
|
4
4
|
file: File;
|
|
5
|
-
workerSrc
|
|
5
|
+
workerSrc?: string;
|
|
6
|
+
wasmUrl?: string;
|
|
6
7
|
sidebar?: React.ReactNode;
|
|
7
8
|
toolbar?: React.ReactNode;
|
|
8
9
|
onChangeFile?: (file: File) => void;
|
|
@@ -17,7 +18,6 @@ interface PDFViewerProps {
|
|
|
17
18
|
style?: React.CSSProperties;
|
|
18
19
|
requireRead?: boolean;
|
|
19
20
|
onDocumentRead?: () => void;
|
|
20
|
-
wasmUrl?: string;
|
|
21
21
|
}
|
|
22
22
|
declare const PDFViewer: React.FC<PDFViewerProps>;
|
|
23
23
|
export default PDFViewer;
|
|
@@ -7,17 +7,18 @@ import { useAnnotationLayer as a } from "../hooks/useAnnotationLayer.js";
|
|
|
7
7
|
import { usePDFLoader as ee } from "../hooks/usePDFLoader.js";
|
|
8
8
|
import { usePDFRenderer as te } from "../hooks/usePDFRenderer.js";
|
|
9
9
|
import { useOverlayRects as ne } from "../hooks/useOverlayRects.js";
|
|
10
|
+
import { usePinchZoom as re } from "../hooks/usePinchZoom.js";
|
|
10
11
|
import { computeFit as o } from "../utils/pdfFit.js";
|
|
11
|
-
import { ThemeProvider as
|
|
12
|
-
import { LabelsProvider as
|
|
12
|
+
import { ThemeProvider as ie } from "../context/ThemeContext.js";
|
|
13
|
+
import { LabelsProvider as ae } from "../context/LabelsContext.js";
|
|
13
14
|
import { useLabels as s } from "../hooks/useLabels.js";
|
|
14
15
|
import c from "./PDFViewer.module.js";
|
|
15
16
|
import { useCallback as l, useEffect as u, useMemo as d, useRef as f, useState as p } from "react";
|
|
16
|
-
import * as
|
|
17
|
-
import { Fragment as
|
|
17
|
+
import * as oe from "pdfjs-dist";
|
|
18
|
+
import { Fragment as se, jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
18
19
|
//#region src/components/PDFViewer.tsx
|
|
19
20
|
var g = 2;
|
|
20
|
-
function
|
|
21
|
+
function ce({ hasRead: e }) {
|
|
21
22
|
let t = s();
|
|
22
23
|
return /* @__PURE__ */ h("div", {
|
|
23
24
|
className: `${c.requireReadBanner} ${e ? c.requireReadDone : ""}`,
|
|
@@ -50,111 +51,111 @@ function se({ hasRead: e }) {
|
|
|
50
51
|
}), /* @__PURE__ */ m("span", { children: e ? t.requireReadDone : t.requireReadPending })]
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
|
-
var _ = ({ file: s, workerSrc: _, sidebar:
|
|
54
|
+
var _ = ({ file: s, workerSrc: _, sidebar: le, toolbar: v, onChangeFile: y, themeOverrides: ue, defaultTheme: de, defaultFit: b, language: fe, className: x, style: pe, requireRead: S, onDocumentRead: C }) => {
|
|
54
55
|
u(() => {
|
|
55
|
-
|
|
56
|
+
oe.GlobalWorkerOptions.workerSrc = _;
|
|
56
57
|
}, [_]);
|
|
57
|
-
let [w, T] = p(1), [E, D] = p(0), [O, k] = p(null), [A, me] = p([]), [j, he] = p(!1), [M,
|
|
58
|
+
let [w, T] = p(1), [E, D] = p(0), [O, k] = p(null), [A, me] = p([]), [j, he] = p(!1), [M, N] = p(b ?? null), [P, F] = p(null), [I, L] = p(!1), R = f(!1), z = f(null), B = f([]), V = f([]), H = f(E);
|
|
58
59
|
u(() => {
|
|
59
|
-
|
|
60
|
+
H.current = E;
|
|
60
61
|
}, [E]);
|
|
61
|
-
let [
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
let [ge, _e] = p(null);
|
|
63
|
+
ge !== s && (_e(s), k(null), L(!1)), u(() => {
|
|
64
|
+
R.current = !1;
|
|
64
65
|
}, [s]);
|
|
65
|
-
let { pdf:
|
|
66
|
+
let { pdf: U, numPages: W, loading: ve } = ee(s);
|
|
66
67
|
u(() => {
|
|
67
|
-
|
|
68
|
-
}, [
|
|
69
|
-
!
|
|
70
|
-
}, [
|
|
71
|
-
let
|
|
68
|
+
U && (B.current = Array(U.numPages).fill(null), V.current = Array(U.numPages).fill(null));
|
|
69
|
+
}, [U]), u(() => {
|
|
70
|
+
!U || !b || !z.current || o(b, U, z.current, H.current).then(T);
|
|
71
|
+
}, [U, b]);
|
|
72
|
+
let G = f(M);
|
|
72
73
|
u(() => {
|
|
73
|
-
|
|
74
|
+
G.current = M;
|
|
74
75
|
}, [M]), u(() => {
|
|
75
|
-
if (!
|
|
76
|
-
let e =
|
|
77
|
-
|
|
76
|
+
if (!U || !z.current) return;
|
|
77
|
+
let e = z.current, t = new ResizeObserver(() => {
|
|
78
|
+
G.current && o(G.current, U, e, H.current).then(T);
|
|
78
79
|
});
|
|
79
80
|
return t.observe(e), () => t.disconnect();
|
|
80
|
-
}, [
|
|
81
|
-
let { currentPage:
|
|
82
|
-
numPages:
|
|
83
|
-
containerRef:
|
|
84
|
-
pageRefs:
|
|
81
|
+
}, [U]);
|
|
82
|
+
let { currentPage: K, goToPage: q } = t({
|
|
83
|
+
numPages: W,
|
|
84
|
+
containerRef: z,
|
|
85
|
+
pageRefs: B
|
|
85
86
|
});
|
|
86
87
|
u(() => {
|
|
87
|
-
|
|
88
|
+
W === 0 || K < W || (S && !I && L(!0), R.current || (R.current = !0, C?.()));
|
|
88
89
|
}, [
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
K,
|
|
91
|
+
W,
|
|
91
92
|
S,
|
|
92
|
-
|
|
93
|
+
I,
|
|
93
94
|
C
|
|
94
95
|
]);
|
|
95
|
-
let
|
|
96
|
-
if (
|
|
97
|
-
let e = /* @__PURE__ */ new Set(), t = Math.max(
|
|
96
|
+
let J = d(() => {
|
|
97
|
+
if (W === 0) return [];
|
|
98
|
+
let e = /* @__PURE__ */ new Set(), t = Math.max(K - g, 1), n = Math.min(K + g, W);
|
|
98
99
|
for (let r = t; r <= n; r++) e.add(r);
|
|
99
100
|
O && e.add(O.page);
|
|
100
101
|
for (let t of A) e.add(t.page);
|
|
101
102
|
return Array.from(e).sort((e, t) => e - t);
|
|
102
103
|
}, [
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
K,
|
|
105
|
+
W,
|
|
105
106
|
O,
|
|
106
107
|
A
|
|
107
|
-
]), { pageSizes:
|
|
108
|
-
pdf:
|
|
108
|
+
]), { pageSizes: ye, renderedPages: Y } = te({
|
|
109
|
+
pdf: U,
|
|
109
110
|
zoom: w,
|
|
110
111
|
rotation: E,
|
|
111
|
-
visiblePages:
|
|
112
|
-
canvasRefs:
|
|
113
|
-
}),
|
|
114
|
-
let e = new Set(
|
|
115
|
-
for (let t of
|
|
112
|
+
visiblePages: J,
|
|
113
|
+
canvasRefs: V
|
|
114
|
+
}), X = d(() => {
|
|
115
|
+
let e = new Set(J);
|
|
116
|
+
for (let t of Y) e.add(t);
|
|
116
117
|
return Array.from(e).sort((e, t) => e - t);
|
|
117
|
-
}, [
|
|
118
|
+
}, [J, Y]);
|
|
118
119
|
n({
|
|
119
|
-
pdf:
|
|
120
|
-
currentPage:
|
|
121
|
-
goToPage:
|
|
120
|
+
pdf: U,
|
|
121
|
+
currentPage: K,
|
|
122
|
+
goToPage: q,
|
|
122
123
|
setRotation: D
|
|
123
|
-
});
|
|
124
|
-
let
|
|
125
|
-
pdf:
|
|
124
|
+
}), re(z, w, T, N);
|
|
125
|
+
let be = r({
|
|
126
|
+
pdf: U,
|
|
126
127
|
zoom: w,
|
|
127
128
|
rotation: E,
|
|
128
|
-
mountedPages:
|
|
129
|
-
canvasRefs:
|
|
130
|
-
}), { linkOverlays:
|
|
131
|
-
pdf:
|
|
129
|
+
mountedPages: X,
|
|
130
|
+
canvasRefs: V
|
|
131
|
+
}), { linkOverlays: xe, noteOverlays: Se } = a({
|
|
132
|
+
pdf: U,
|
|
132
133
|
zoom: w,
|
|
133
134
|
rotation: E,
|
|
134
|
-
mountedPages:
|
|
135
|
-
goToPage:
|
|
135
|
+
mountedPages: X,
|
|
136
|
+
goToPage: q
|
|
136
137
|
});
|
|
137
138
|
u(() => {
|
|
138
|
-
if (!
|
|
139
|
-
let e = () =>
|
|
140
|
-
e.key === "Escape" &&
|
|
139
|
+
if (!P) return;
|
|
140
|
+
let e = () => F(null), t = (e) => {
|
|
141
|
+
e.key === "Escape" && F(null);
|
|
141
142
|
};
|
|
142
143
|
return document.addEventListener("click", e), document.addEventListener("keydown", t), () => {
|
|
143
144
|
document.removeEventListener("click", e), document.removeEventListener("keydown", t);
|
|
144
145
|
};
|
|
145
|
-
}, [
|
|
146
|
-
let { overlayRect:
|
|
147
|
-
pdf:
|
|
146
|
+
}, [P]);
|
|
147
|
+
let { overlayRect: Z, searchOverlays: Ce } = ne({
|
|
148
|
+
pdf: U,
|
|
148
149
|
highlight: O,
|
|
149
150
|
searchMatches: A,
|
|
150
151
|
zoom: w,
|
|
151
152
|
rotation: E
|
|
152
|
-
}),
|
|
153
|
+
}), we = l((e, t) => {
|
|
153
154
|
(!e.url || !i(e.url)) && (t.preventDefault(), e.url || e._handleClick());
|
|
154
|
-
}, []),
|
|
155
|
-
|
|
155
|
+
}, []), Q = f(null), Te = l((e, t) => {
|
|
156
|
+
Q.current && clearTimeout(Q.current);
|
|
156
157
|
let n = t.clientY > window.innerHeight * .6;
|
|
157
|
-
|
|
158
|
+
F({
|
|
158
159
|
x: Math.min(t.clientX, window.innerWidth - 304),
|
|
159
160
|
y: n ? window.innerHeight - t.clientY + 8 : t.clientY + 12,
|
|
160
161
|
above: n,
|
|
@@ -162,23 +163,23 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
162
163
|
title: e.title
|
|
163
164
|
});
|
|
164
165
|
}, []), $ = l(() => {
|
|
165
|
-
|
|
166
|
+
Q.current = setTimeout(() => F(null), 200);
|
|
166
167
|
}, []), Ee = l((e) => {
|
|
167
168
|
k({
|
|
168
169
|
page: e.page,
|
|
169
170
|
pdfRect: e.pdfRect
|
|
170
|
-
}),
|
|
171
|
-
}, [k,
|
|
172
|
-
pdf:
|
|
173
|
-
numPages:
|
|
171
|
+
}), q(e.page);
|
|
172
|
+
}, [k, q]), De = d(() => ({
|
|
173
|
+
pdf: U,
|
|
174
|
+
numPages: W,
|
|
174
175
|
zoom: w,
|
|
175
176
|
setZoom: T,
|
|
176
177
|
rotation: E,
|
|
177
178
|
setRotation: D,
|
|
178
|
-
currentPage:
|
|
179
|
-
goToPage:
|
|
180
|
-
containerRef:
|
|
181
|
-
canvasRefs:
|
|
179
|
+
currentPage: K,
|
|
180
|
+
goToPage: q,
|
|
181
|
+
containerRef: z,
|
|
182
|
+
canvasRefs: V,
|
|
182
183
|
file: s,
|
|
183
184
|
highlight: O,
|
|
184
185
|
setHighlight: k,
|
|
@@ -188,15 +189,15 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
188
189
|
sidebarCollapsed: j,
|
|
189
190
|
setSidebarCollapsed: he,
|
|
190
191
|
fitMode: M,
|
|
191
|
-
setFitMode:
|
|
192
|
-
navigationLocked: !!S && !
|
|
192
|
+
setFitMode: N,
|
|
193
|
+
navigationLocked: !!S && !I
|
|
193
194
|
}), [
|
|
194
|
-
H,
|
|
195
195
|
U,
|
|
196
|
+
W,
|
|
196
197
|
w,
|
|
197
198
|
E,
|
|
198
|
-
G,
|
|
199
199
|
K,
|
|
200
|
+
q,
|
|
200
201
|
s,
|
|
201
202
|
O,
|
|
202
203
|
A,
|
|
@@ -204,34 +205,34 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
204
205
|
j,
|
|
205
206
|
M,
|
|
206
207
|
S,
|
|
207
|
-
|
|
208
|
+
I
|
|
208
209
|
]);
|
|
209
|
-
return /* @__PURE__ */ m(
|
|
210
|
-
themeOverrides:
|
|
211
|
-
defaultTheme:
|
|
212
|
-
children: /* @__PURE__ */ m(
|
|
213
|
-
language:
|
|
210
|
+
return /* @__PURE__ */ m(ie, {
|
|
211
|
+
themeOverrides: ue,
|
|
212
|
+
defaultTheme: de,
|
|
213
|
+
children: /* @__PURE__ */ m(ae, {
|
|
214
|
+
language: fe,
|
|
214
215
|
children: /* @__PURE__ */ h(e.Provider, {
|
|
215
216
|
value: De,
|
|
216
217
|
children: [/* @__PURE__ */ h("div", {
|
|
217
218
|
className: `${c.appLayout}${x ? ` ${x}` : ""}`,
|
|
218
|
-
style:
|
|
219
|
+
style: pe,
|
|
219
220
|
children: [v && /* @__PURE__ */ m("div", {
|
|
220
221
|
className: c.toolbar,
|
|
221
222
|
children: v
|
|
222
223
|
}), /* @__PURE__ */ h("div", {
|
|
223
224
|
className: c.body,
|
|
224
|
-
children: [
|
|
225
|
+
children: [le, /* @__PURE__ */ h("div", {
|
|
225
226
|
className: c.scrollContainer,
|
|
226
|
-
ref:
|
|
227
|
+
ref: z,
|
|
227
228
|
children: [
|
|
228
|
-
|
|
229
|
-
Array.from({ length:
|
|
230
|
-
let n =
|
|
229
|
+
ve && /* @__PURE__ */ m("div", { className: c.documentLoading }),
|
|
230
|
+
Array.from({ length: W }, (e, t) => {
|
|
231
|
+
let n = Y.has(t + 1), r = ye[t], a = X.includes(t + 1);
|
|
231
232
|
return /* @__PURE__ */ h("div", {
|
|
232
233
|
className: c.pageWrapper,
|
|
233
234
|
ref: (e) => {
|
|
234
|
-
|
|
235
|
+
B.current[t] = e;
|
|
235
236
|
},
|
|
236
237
|
style: r ? {
|
|
237
238
|
width: r.width,
|
|
@@ -245,19 +246,19 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
245
246
|
height: r.height
|
|
246
247
|
}
|
|
247
248
|
}),
|
|
248
|
-
a && /* @__PURE__ */ h(
|
|
249
|
+
a && /* @__PURE__ */ h(se, { children: [/* @__PURE__ */ m("canvas", {
|
|
249
250
|
className: c.pageCanvas,
|
|
250
251
|
ref: (e) => {
|
|
251
|
-
|
|
252
|
+
V.current[t] = e;
|
|
252
253
|
},
|
|
253
254
|
style: { display: n ? "block" : "none" }
|
|
254
255
|
}), /* @__PURE__ */ m("div", {
|
|
255
256
|
className: `textLayer ${c.textLayer}`,
|
|
256
257
|
ref: (e) => {
|
|
257
|
-
|
|
258
|
+
be.current[t] = e;
|
|
258
259
|
}
|
|
259
260
|
})] }),
|
|
260
|
-
|
|
261
|
+
xe.filter((e) => e.page === t + 1).map((e, t) => /* @__PURE__ */ m("a", {
|
|
261
262
|
className: c.linkOverlay,
|
|
262
263
|
href: e.url && i(e.url) ? e.url : "#",
|
|
263
264
|
target: "_blank",
|
|
@@ -268,9 +269,9 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
268
269
|
width: e.width,
|
|
269
270
|
height: e.height
|
|
270
271
|
},
|
|
271
|
-
onClick: (t) =>
|
|
272
|
+
onClick: (t) => we(e, t)
|
|
272
273
|
}, t)),
|
|
273
|
-
|
|
274
|
+
Se.filter((e) => e.page === t + 1).map((e, t) => e.subtype === "Text" ? /* @__PURE__ */ m("div", {
|
|
274
275
|
className: c.noteIconOverlay,
|
|
275
276
|
style: {
|
|
276
277
|
left: e.x,
|
|
@@ -278,7 +279,7 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
278
279
|
width: Math.max(e.width, 26),
|
|
279
280
|
height: Math.max(e.height, 26)
|
|
280
281
|
},
|
|
281
|
-
onMouseEnter: (t) =>
|
|
282
|
+
onMouseEnter: (t) => Te(e, t),
|
|
282
283
|
onMouseLeave: $,
|
|
283
284
|
onClick: () => Ee(e),
|
|
284
285
|
children: /* @__PURE__ */ h("svg", {
|
|
@@ -332,11 +333,11 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
332
333
|
width: e.width,
|
|
333
334
|
height: e.height
|
|
334
335
|
},
|
|
335
|
-
onMouseEnter: (t) =>
|
|
336
|
+
onMouseEnter: (t) => Te(e, t),
|
|
336
337
|
onMouseLeave: $,
|
|
337
338
|
onClick: () => Ee(e)
|
|
338
339
|
}, t)),
|
|
339
|
-
|
|
340
|
+
Ce.filter((e) => e.page === t + 1).map((e, t) => /* @__PURE__ */ m("div", {
|
|
340
341
|
className: c.searchMatchOverlay,
|
|
341
342
|
style: {
|
|
342
343
|
left: e.x,
|
|
@@ -345,42 +346,42 @@ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, them
|
|
|
345
346
|
height: e.height
|
|
346
347
|
}
|
|
347
348
|
}, t)),
|
|
348
|
-
O &&
|
|
349
|
+
O && Z?.page === t + 1 && /* @__PURE__ */ m("div", {
|
|
349
350
|
className: c.highlightOverlay,
|
|
350
351
|
style: {
|
|
351
|
-
left:
|
|
352
|
-
top:
|
|
353
|
-
width:
|
|
354
|
-
height:
|
|
352
|
+
left: Z.x,
|
|
353
|
+
top: Z.y,
|
|
354
|
+
width: Z.width,
|
|
355
|
+
height: Z.height
|
|
355
356
|
}
|
|
356
357
|
})
|
|
357
358
|
]
|
|
358
359
|
}, `${t}-${E}`);
|
|
359
360
|
}),
|
|
360
|
-
S && /* @__PURE__ */ m(
|
|
361
|
+
S && /* @__PURE__ */ m(ce, { hasRead: I })
|
|
361
362
|
]
|
|
362
363
|
})]
|
|
363
364
|
})]
|
|
364
|
-
}),
|
|
365
|
+
}), P && /* @__PURE__ */ h("div", {
|
|
365
366
|
className: c.notePopover,
|
|
366
|
-
style:
|
|
367
|
-
left:
|
|
368
|
-
bottom:
|
|
367
|
+
style: P.above ? {
|
|
368
|
+
left: P.x,
|
|
369
|
+
bottom: P.y
|
|
369
370
|
} : {
|
|
370
|
-
left:
|
|
371
|
-
top:
|
|
371
|
+
left: P.x,
|
|
372
|
+
top: P.y
|
|
372
373
|
},
|
|
373
374
|
onMouseEnter: () => {
|
|
374
|
-
|
|
375
|
+
Q.current && clearTimeout(Q.current);
|
|
375
376
|
},
|
|
376
377
|
onMouseLeave: $,
|
|
377
378
|
onClick: (e) => e.stopPropagation(),
|
|
378
|
-
children: [
|
|
379
|
+
children: [P.title && /* @__PURE__ */ m("div", {
|
|
379
380
|
className: c.notePopoverTitle,
|
|
380
|
-
children:
|
|
381
|
+
children: P.title
|
|
381
382
|
}), /* @__PURE__ */ m("p", {
|
|
382
383
|
className: c.notePopoverContent,
|
|
383
|
-
children:
|
|
384
|
+
children: P.contents
|
|
384
385
|
})]
|
|
385
386
|
})]
|
|
386
387
|
})
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
var e = {
|
|
2
|
-
appLayout: "
|
|
3
|
-
body: "
|
|
4
|
-
toolbar: "
|
|
5
|
-
scrollContainer: "
|
|
6
|
-
pageWrapper: "
|
|
7
|
-
pageCanvas: "
|
|
8
|
-
textLayer: "
|
|
9
|
-
markedContent: "
|
|
10
|
-
endOfContent: "
|
|
11
|
-
selecting: "
|
|
12
|
-
documentLoading: "
|
|
13
|
-
spin: "
|
|
14
|
-
pageSkeleton: "
|
|
15
|
-
highlightOverlay: "
|
|
16
|
-
linkOverlay: "
|
|
17
|
-
searchMatchOverlay: "
|
|
18
|
-
noteOverlay: "
|
|
19
|
-
noteIconOverlay: "
|
|
20
|
-
requireReadBanner: "
|
|
21
|
-
requireReadDone: "
|
|
22
|
-
notePopover: "
|
|
23
|
-
notePopoverTitle: "
|
|
24
|
-
notePopoverContent: "
|
|
2
|
+
appLayout: "_appLayout_dknw2_1",
|
|
3
|
+
body: "_body_dknw2_9",
|
|
4
|
+
toolbar: "_toolbar_dknw2_17",
|
|
5
|
+
scrollContainer: "_scrollContainer_dknw2_29",
|
|
6
|
+
pageWrapper: "_pageWrapper_dknw2_41",
|
|
7
|
+
pageCanvas: "_pageCanvas_dknw2_46",
|
|
8
|
+
textLayer: "_textLayer_dknw2_55",
|
|
9
|
+
markedContent: "_markedContent_dknw2_81",
|
|
10
|
+
endOfContent: "_endOfContent_dknw2_96",
|
|
11
|
+
selecting: "_selecting_dknw2_105",
|
|
12
|
+
documentLoading: "_documentLoading_dknw2_125",
|
|
13
|
+
spin: "_spin_dknw2_1",
|
|
14
|
+
pageSkeleton: "_pageSkeleton_dknw2_145",
|
|
15
|
+
highlightOverlay: "_highlightOverlay_dknw2_174",
|
|
16
|
+
linkOverlay: "_linkOverlay_dknw2_183",
|
|
17
|
+
searchMatchOverlay: "_searchMatchOverlay_dknw2_190",
|
|
18
|
+
noteOverlay: "_noteOverlay_dknw2_198",
|
|
19
|
+
noteIconOverlay: "_noteIconOverlay_dknw2_205",
|
|
20
|
+
requireReadBanner: "_requireReadBanner_dknw2_222",
|
|
21
|
+
requireReadDone: "_requireReadDone_dknw2_246",
|
|
22
|
+
notePopover: "_notePopover_dknw2_250",
|
|
23
|
+
notePopoverTitle: "_notePopoverTitle_dknw2_263",
|
|
24
|
+
notePopoverContent: "_notePopoverContent_dknw2_270"
|
|
25
25
|
};
|
|
26
26
|
//#endregion
|
|
27
27
|
export { e as default };
|
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
import { useEffect as e, useState as t } from "react";
|
|
2
2
|
import * as n from "pdfjs-dist";
|
|
3
3
|
//#region src/hooks/usePDFLoader.ts
|
|
4
|
-
function r(r
|
|
5
|
-
let [
|
|
4
|
+
function r(r) {
|
|
5
|
+
let [i, a] = t(null), [o, s] = t(0), [c, l] = t(!0);
|
|
6
6
|
return e(() => {
|
|
7
|
-
|
|
7
|
+
l(!0), a(null), s(0);
|
|
8
8
|
let e = new FileReader();
|
|
9
9
|
e.onload = async (e) => {
|
|
10
10
|
let t = new Uint8Array(e.target?.result);
|
|
11
11
|
try {
|
|
12
|
-
let e = await n.getDocument(
|
|
13
|
-
|
|
14
|
-
...i ? { wasmUrl: i } : {}
|
|
15
|
-
}).promise;
|
|
16
|
-
o(e), c(e.numPages);
|
|
12
|
+
let e = await n.getDocument(t).promise;
|
|
13
|
+
a(e), s(e.numPages);
|
|
17
14
|
} catch (e) {
|
|
18
15
|
console.error("Errore caricamento:", e);
|
|
19
16
|
} finally {
|
|
20
|
-
|
|
17
|
+
l(!1);
|
|
21
18
|
}
|
|
22
19
|
}, e.readAsArrayBuffer(r);
|
|
23
|
-
}, [r
|
|
24
|
-
pdf:
|
|
25
|
-
numPages:
|
|
26
|
-
loading:
|
|
20
|
+
}, [r]), {
|
|
21
|
+
pdf: i,
|
|
22
|
+
numPages: o,
|
|
23
|
+
loading: c
|
|
27
24
|
};
|
|
28
25
|
}
|
|
29
26
|
//#endregion
|
|
@@ -46,24 +46,27 @@ function r({ pdf: r, zoom: i, rotation: a, visiblePages: o, canvasRefs: s }) {
|
|
|
46
46
|
if (e || p.current.has(t)) continue;
|
|
47
47
|
let n = await r.getPage(t);
|
|
48
48
|
if (e) return;
|
|
49
|
-
let o = n.getViewport({
|
|
49
|
+
let o = window.devicePixelRatio || 1, c = n.getViewport({
|
|
50
50
|
scale: i,
|
|
51
51
|
rotation: a
|
|
52
|
-
}),
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
}), l = n.getViewport({
|
|
53
|
+
scale: i * o,
|
|
54
|
+
rotation: a
|
|
55
|
+
}), u = s.current[t - 1];
|
|
56
|
+
if (!u) continue;
|
|
57
|
+
let m = u.getContext("2d");
|
|
58
|
+
if (!m) continue;
|
|
59
|
+
let h = f.current[t - 1];
|
|
60
|
+
if (h && (h.cancel(), await h.promise.catch(() => {}), e)) return;
|
|
61
|
+
u.width = l.width, u.height = l.height, u.style.width = `${c.width}px`, u.style.height = `${c.height}px`;
|
|
62
|
+
let g = n.render({
|
|
63
|
+
canvasContext: m,
|
|
64
|
+
viewport: l,
|
|
65
|
+
canvas: u
|
|
63
66
|
});
|
|
64
|
-
f.current[t - 1] =
|
|
67
|
+
f.current[t - 1] = g;
|
|
65
68
|
try {
|
|
66
|
-
await
|
|
69
|
+
await g.promise, e || (p.current = new Set(p.current).add(t), d((e) => {
|
|
67
70
|
if (e.has(t)) return e;
|
|
68
71
|
let n = new Set(e);
|
|
69
72
|
return n.add(t), n;
|
|
@@ -71,7 +74,7 @@ function r({ pdf: r, zoom: i, rotation: a, visiblePages: o, canvasRefs: s }) {
|
|
|
71
74
|
} catch (e) {
|
|
72
75
|
e && typeof e == "object" && "name" in e && e.name !== "RenderingCancelledException" && console.error("Render error:", e);
|
|
73
76
|
} finally {
|
|
74
|
-
f.current[t - 1] ===
|
|
77
|
+
f.current[t - 1] === g && (f.current[t - 1] = null);
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
})(), () => {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useEffect as e, useRef as t } from "react";
|
|
2
|
+
//#region src/hooks/usePinchZoom.ts
|
|
3
|
+
function n(e) {
|
|
4
|
+
let t = e[0].clientX - e[1].clientX, n = e[0].clientY - e[1].clientY;
|
|
5
|
+
return Math.sqrt(t * t + n * n);
|
|
6
|
+
}
|
|
7
|
+
function r(r, i, a, o) {
|
|
8
|
+
let s = t(i);
|
|
9
|
+
e(() => {
|
|
10
|
+
s.current = i;
|
|
11
|
+
}, [i]);
|
|
12
|
+
let c = t(null), l = t(1), u = t(null), d = t(!1);
|
|
13
|
+
e(() => {
|
|
14
|
+
let e = r.current;
|
|
15
|
+
if (!e) return;
|
|
16
|
+
let t = (e) => {
|
|
17
|
+
e.touches.length === 2 && (d.current = !0, u.current = null, c.current = n(e.touches), l.current = s.current);
|
|
18
|
+
}, i = (e) => {
|
|
19
|
+
if (e.touches.length !== 2 || c.current === null) return;
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
let t = n(e.touches) / c.current;
|
|
22
|
+
a(Math.max(.2, Math.min(3, l.current * t))), o(null);
|
|
23
|
+
}, f = (e) => {
|
|
24
|
+
if (e.touches.length === 0 && c.current !== null) {
|
|
25
|
+
d.current = !1, c.current = null;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (c.current = null, d.current || e.changedTouches.length !== 1) return;
|
|
29
|
+
let t = e.changedTouches[0], n = Date.now(), r = u.current;
|
|
30
|
+
if (r && n - r.time < 300) {
|
|
31
|
+
let e = t.clientX - r.x, n = t.clientY - r.y;
|
|
32
|
+
if (Math.sqrt(e * e + n * n) < 40) {
|
|
33
|
+
u.current = null, a(s.current > 1.2 ? 1 : 2), o(null);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
u.current = {
|
|
38
|
+
time: n,
|
|
39
|
+
x: t.clientX,
|
|
40
|
+
y: t.clientY
|
|
41
|
+
};
|
|
42
|
+
}, p = (e) => {
|
|
43
|
+
if (!e.ctrlKey && !e.metaKey) return;
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
let t = -(e.deltaMode === 1 ? e.deltaY * 30 : e.deltaMode === 2 ? e.deltaY * 300 : e.deltaY) * .02;
|
|
46
|
+
a(Math.max(.2, Math.min(3, s.current + t))), o(null);
|
|
47
|
+
};
|
|
48
|
+
return e.addEventListener("touchstart", t, { passive: !0 }), e.addEventListener("touchmove", i, { passive: !1 }), e.addEventListener("touchend", f, { passive: !0 }), e.addEventListener("wheel", p, { passive: !1 }), () => {
|
|
49
|
+
e.removeEventListener("touchstart", t), e.removeEventListener("touchmove", i), e.removeEventListener("touchend", f), e.removeEventListener("wheel", p);
|
|
50
|
+
};
|
|
51
|
+
}, [
|
|
52
|
+
r,
|
|
53
|
+
a,
|
|
54
|
+
o
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { r as usePinchZoom };
|