pdf-tsx 0.3.0 → 0.5.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/LICENSE +21 -21
- package/README.md +350 -296
- package/dist/cjs/components/PDFSidebar.cjs +1 -1
- package/dist/cjs/components/PDFSidebar.module.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/PDFAnnotations.module.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/PDFNavigation.module.cjs +1 -1
- package/dist/cjs/components/features/PDFOutline.cjs +1 -1
- package/dist/cjs/components/features/PDFOutline.module.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/PDFSearch.module.cjs +1 -1
- package/dist/cjs/components/features/PDFSidebarToggle.cjs +1 -0
- package/dist/cjs/components/features/PDFSignatures.cjs +1 -1
- package/dist/cjs/components/features/PDFSignatures.module.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/PDFThumbnails.module.cjs +1 -1
- package/dist/cjs/components/features/PDFZoomControls.cjs +1 -1
- package/dist/cjs/components/features/PDFZoomControls.module.cjs +1 -1
- package/dist/cjs/components/ui/ToolbarButton.module.cjs +1 -1
- package/dist/cjs/components/ui/icons.cjs +1 -1
- package/dist/cjs/context/ThemeContext.cjs +1 -1
- package/dist/cjs/context/themeContextValue.cjs +1 -0
- package/dist/cjs/hooks/useAnnotationLayer.cjs +1 -1
- package/dist/cjs/hooks/useAnnotations.cjs +1 -1
- package/dist/cjs/hooks/useKeyboardShortcuts.cjs +1 -1
- package/dist/cjs/hooks/useOutline.cjs +1 -1
- package/dist/cjs/hooks/useOverlayRects.cjs +1 -0
- package/dist/cjs/hooks/usePDFLoader.cjs +1 -0
- package/dist/cjs/hooks/usePDFRenderer.cjs +1 -0
- package/dist/cjs/hooks/useScrollTracking.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 -0
- 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/PDFSidebar.d.ts +1 -1
- package/dist/components/PDFViewer.d.ts +2 -0
- package/dist/components/features/PDFSidebarToggle.d.ts +7 -0
- package/dist/components/ui/icons.d.ts +0 -14
- package/dist/context/PDFViewerContext.d.ts +2 -0
- package/dist/context/ThemeContext.d.ts +0 -6
- package/dist/context/themeContextValue.d.ts +7 -0
- package/dist/es/components/PDFSidebar.js +39 -36
- package/dist/es/components/PDFSidebar.module.js +9 -7
- package/dist/es/components/PDFViewer.js +240 -266
- package/dist/es/components/PDFViewer.module.js +15 -15
- package/dist/es/components/features/PDFAnnotations.js +57 -64
- package/dist/es/components/features/PDFAnnotations.module.js +12 -12
- package/dist/es/components/features/PDFChangeFile.js +3 -3
- package/dist/es/components/features/PDFDownloadButton.js +2 -2
- package/dist/es/components/features/PDFNavigation.js +3 -3
- package/dist/es/components/features/PDFNavigation.module.js +3 -3
- package/dist/es/components/features/PDFOutline.js +7 -7
- package/dist/es/components/features/PDFOutline.module.js +5 -5
- package/dist/es/components/features/PDFPageFit.js +1 -1
- package/dist/es/components/features/PDFPrintButton.js +5 -4
- package/dist/es/components/features/PDFRotationControl.js +1 -1
- package/dist/es/components/features/PDFSearch.js +19 -14
- package/dist/es/components/features/PDFSearch.module.js +5 -4
- package/dist/es/components/features/PDFSidebarToggle.js +21 -0
- package/dist/es/components/features/PDFSignatures.js +158 -116
- package/dist/es/components/features/PDFSignatures.module.js +16 -16
- package/dist/es/components/features/PDFThemeToggle.js +5 -5
- package/dist/es/components/features/PDFThumbnails.js +54 -30
- package/dist/es/components/features/PDFThumbnails.module.js +9 -7
- package/dist/es/components/features/PDFZoomControls.js +1 -1
- package/dist/es/components/features/PDFZoomControls.module.js +1 -1
- package/dist/es/components/ui/ToolbarButton.module.js +2 -2
- package/dist/es/components/ui/icons.js +1 -1
- package/dist/es/context/ThemeContext.js +20 -25
- package/dist/es/context/themeContextValue.js +5 -0
- package/dist/es/hooks/useAnnotationLayer.js +11 -11
- package/dist/es/hooks/useAnnotations.js +0 -1
- package/dist/es/hooks/useKeyboardShortcuts.js +12 -15
- package/dist/es/hooks/useOutline.js +31 -12
- package/dist/es/hooks/useOverlayRects.js +72 -0
- package/dist/es/hooks/usePDFLoader.js +26 -0
- package/dist/es/hooks/usePDFRenderer.js +83 -0
- package/dist/es/hooks/useScrollTracking.js +21 -20
- package/dist/es/hooks/useTextLayer.js +13 -12
- package/dist/es/hooks/useTextSearch.js +30 -18
- package/dist/es/hooks/useTheme.js +10 -0
- package/dist/es/hooks/useThumbnails.js +86 -24
- package/dist/es/index.js +2 -1
- package/dist/es/pdf-tsx.css +1 -1
- package/dist/hooks/useAnnotationLayer.d.ts +2 -2
- package/dist/hooks/useAnnotations.d.ts +0 -5
- package/dist/hooks/useKeyboardShortcuts.d.ts +1 -2
- package/dist/hooks/useOverlayRects.d.ts +21 -0
- package/dist/hooks/usePDFLoader.d.ts +4 -0
- package/dist/hooks/usePDFRenderer.d.ts +16 -0
- package/dist/hooks/useScrollTracking.d.ts +2 -1
- package/dist/hooks/useTextLayer.d.ts +2 -2
- package/dist/hooks/useTheme.d.ts +2 -0
- package/dist/hooks/useThumbnails.d.ts +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/pdf-tsx.cjs.js +5 -0
- package/dist/pdf-tsx.css +2 -0
- package/dist/pdf-tsx.es.js +2637 -0
- package/dist/vite.svg +1 -0
- package/package.json +61 -61
|
@@ -1,44 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as e } from "react/compiler-runtime";
|
|
2
|
+
import { useEffect as t } from "react";
|
|
2
3
|
import "pdfjs-dist";
|
|
3
|
-
import { c as t } from "react/compiler-runtime";
|
|
4
4
|
//#region src/hooks/useKeyboardShortcuts.ts
|
|
5
5
|
function n(n) {
|
|
6
|
-
let o =
|
|
7
|
-
o[0] !== c || o[1] !==
|
|
6
|
+
let o = e(7), { pdf: s, currentPage: c, goToPage: l, setZoom: u, setRotation: d } = n, f, p;
|
|
7
|
+
o[0] !== c || o[1] !== l || o[2] !== s || o[3] !== d || o[4] !== u ? (f = () => {
|
|
8
8
|
if (!s) return;
|
|
9
9
|
let e = (e) => {
|
|
10
10
|
let t = e.target.tagName;
|
|
11
11
|
if (!(t === "INPUT" || t === "TEXTAREA")) bb13: switch (e.key) {
|
|
12
12
|
case "ArrowLeft":
|
|
13
13
|
case "ArrowUp":
|
|
14
|
-
e.preventDefault(),
|
|
14
|
+
e.preventDefault(), l(c - 1);
|
|
15
15
|
break bb13;
|
|
16
16
|
case "ArrowRight":
|
|
17
17
|
case "ArrowDown":
|
|
18
|
-
e.preventDefault(),
|
|
18
|
+
e.preventDefault(), l(c + 1);
|
|
19
19
|
break bb13;
|
|
20
20
|
case "+":
|
|
21
21
|
case "=":
|
|
22
|
-
e.preventDefault(),
|
|
22
|
+
e.preventDefault(), u(a);
|
|
23
23
|
break bb13;
|
|
24
24
|
case "-":
|
|
25
|
-
e.preventDefault(),
|
|
25
|
+
e.preventDefault(), u(i);
|
|
26
26
|
break bb13;
|
|
27
27
|
case "r":
|
|
28
|
-
case "R": e.preventDefault(),
|
|
28
|
+
case "R": e.preventDefault(), d(r);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
|
|
32
|
-
},
|
|
33
|
-
let m;
|
|
34
|
-
o[6] !== c || o[7] !== u || o[8] !== l || o[9] !== s || o[10] !== f || o[11] !== d ? (m = [
|
|
32
|
+
}, p = [
|
|
35
33
|
s,
|
|
36
34
|
c,
|
|
37
35
|
l,
|
|
38
36
|
u,
|
|
39
|
-
d
|
|
40
|
-
|
|
41
|
-
], o[6] = c, o[7] = u, o[8] = l, o[9] = s, o[10] = f, o[11] = d, o[12] = m) : m = o[12], e(p, m);
|
|
37
|
+
d
|
|
38
|
+
], o[0] = c, o[1] = l, o[2] = s, o[3] = d, o[4] = u, o[5] = f, o[6] = p) : (f = o[5], p = o[6]), t(f, p);
|
|
42
39
|
}
|
|
43
40
|
function r(e) {
|
|
44
41
|
return (e + 90) % 360;
|
|
@@ -1,19 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as e } from "react/compiler-runtime";
|
|
2
|
+
import { useEffect as t, useState as n } from "react";
|
|
2
3
|
import "pdfjs-dist";
|
|
3
|
-
import { c as n } from "react/compiler-runtime";
|
|
4
4
|
//#region src/hooks/useOutline.ts
|
|
5
5
|
function r(r) {
|
|
6
|
-
let i =
|
|
7
|
-
i[0] === Symbol.for("react.memo_cache_sentinel") ? (o =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
let i = e(10), { pdf: a } = r, o;
|
|
7
|
+
i[0] === Symbol.for("react.memo_cache_sentinel") ? (o = {
|
|
8
|
+
pdf: null,
|
|
9
|
+
outline: []
|
|
10
|
+
}, i[0] = o) : o = i[0];
|
|
11
|
+
let [s, c] = n(o), l, u;
|
|
12
|
+
i[1] === a ? (l = i[2], u = i[3]) : (l = () => {
|
|
13
|
+
if (!a) return;
|
|
14
|
+
let e = !1;
|
|
15
|
+
return a.getOutline().then((t) => {
|
|
16
|
+
e || c({
|
|
17
|
+
pdf: a,
|
|
18
|
+
outline: t ?? []
|
|
19
|
+
});
|
|
20
|
+
}).catch(() => {
|
|
21
|
+
e || c({
|
|
22
|
+
pdf: a,
|
|
23
|
+
outline: []
|
|
24
|
+
});
|
|
25
|
+
}), () => {
|
|
26
|
+
e = !0;
|
|
27
|
+
};
|
|
28
|
+
}, u = [a], i[1] = a, i[2] = l, i[3] = u), t(l, u);
|
|
29
|
+
let d = a !== null && s.pdf !== a, f;
|
|
30
|
+
i[4] !== d || i[5] !== s ? (f = d ? [] : s.outline, i[4] = d, i[5] = s, i[6] = f) : f = i[6];
|
|
12
31
|
let p;
|
|
13
|
-
return i[
|
|
14
|
-
outline:
|
|
15
|
-
loading:
|
|
16
|
-
}, i[
|
|
32
|
+
return i[7] !== d || i[8] !== f ? (p = {
|
|
33
|
+
outline: f,
|
|
34
|
+
loading: d
|
|
35
|
+
}, i[7] = d, i[8] = f, i[9] = p) : p = i[9], p;
|
|
17
36
|
}
|
|
18
37
|
//#endregion
|
|
19
38
|
export { r as useOutline };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { c as e } from "react/compiler-runtime";
|
|
2
|
+
import { useEffect as t, useState as n } from "react";
|
|
3
|
+
import "pdfjs-dist";
|
|
4
|
+
//#region src/hooks/useOverlayRects.ts
|
|
5
|
+
function r(r) {
|
|
6
|
+
let i = e(20), { pdf: a, highlight: o, searchMatches: s, zoom: c, rotation: l } = r, [u, d] = n(null), f;
|
|
7
|
+
i[0] === Symbol.for("react.memo_cache_sentinel") ? (f = [], i[0] = f) : f = i[0];
|
|
8
|
+
let [p, m] = n(f), h, g;
|
|
9
|
+
i[1] !== a || i[2] !== l || i[3] !== s || i[4] !== c ? (h = () => {
|
|
10
|
+
if (!a || s.length === 0) return;
|
|
11
|
+
let e = !1;
|
|
12
|
+
return (async () => {
|
|
13
|
+
let t = [];
|
|
14
|
+
for (let n of s) {
|
|
15
|
+
if (e) break;
|
|
16
|
+
let [r, i, o, s] = (await a.getPage(n.page)).getViewport({
|
|
17
|
+
scale: c,
|
|
18
|
+
rotation: l
|
|
19
|
+
}).convertToViewportRectangle(n.pdfRect);
|
|
20
|
+
t.push({
|
|
21
|
+
page: n.page,
|
|
22
|
+
x: Math.min(r, o),
|
|
23
|
+
y: Math.min(i, s),
|
|
24
|
+
width: Math.abs(o - r),
|
|
25
|
+
height: Math.abs(s - i)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
e || m(t);
|
|
29
|
+
})(), () => {
|
|
30
|
+
e = !0;
|
|
31
|
+
};
|
|
32
|
+
}, g = [
|
|
33
|
+
s,
|
|
34
|
+
c,
|
|
35
|
+
l,
|
|
36
|
+
a
|
|
37
|
+
], i[1] = a, i[2] = l, i[3] = s, i[4] = c, i[5] = h, i[6] = g) : (h = i[5], g = i[6]), t(h, g);
|
|
38
|
+
let _, v;
|
|
39
|
+
i[7] !== o || i[8] !== a || i[9] !== l || i[10] !== c ? (_ = () => {
|
|
40
|
+
if (!o || !a) return;
|
|
41
|
+
let e = !1;
|
|
42
|
+
return (async () => {
|
|
43
|
+
let [t, n, r, i] = (await a.getPage(o.page)).getViewport({
|
|
44
|
+
scale: c,
|
|
45
|
+
rotation: l
|
|
46
|
+
}).convertToViewportRectangle(o.pdfRect);
|
|
47
|
+
e || d({
|
|
48
|
+
page: o.page,
|
|
49
|
+
x: Math.min(t, r),
|
|
50
|
+
y: Math.min(n, i),
|
|
51
|
+
width: Math.abs(r - t),
|
|
52
|
+
height: Math.abs(i - n)
|
|
53
|
+
});
|
|
54
|
+
})(), () => {
|
|
55
|
+
e = !0;
|
|
56
|
+
};
|
|
57
|
+
}, v = [
|
|
58
|
+
o,
|
|
59
|
+
c,
|
|
60
|
+
l,
|
|
61
|
+
a
|
|
62
|
+
], i[7] = o, i[8] = a, i[9] = l, i[10] = c, i[11] = _, i[12] = v) : (_ = i[11], v = i[12]), t(_, v);
|
|
63
|
+
let y = !o || !a ? null : u, b;
|
|
64
|
+
i[13] !== a || i[14] !== s || i[15] !== p ? (b = !a || s.length === 0 ? [] : p, i[13] = a, i[14] = s, i[15] = p, i[16] = b) : b = i[16];
|
|
65
|
+
let x;
|
|
66
|
+
return i[17] !== y || i[18] !== b ? (x = {
|
|
67
|
+
overlayRect: y,
|
|
68
|
+
searchOverlays: b
|
|
69
|
+
}, i[17] = y, i[18] = b, i[19] = x) : x = i[19], x;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { r as useOverlayRects };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { c as e } from "react/compiler-runtime";
|
|
2
|
+
import { useEffect as t, useState as n } from "react";
|
|
3
|
+
import * as r from "pdfjs-dist";
|
|
4
|
+
//#region src/hooks/usePDFLoader.ts
|
|
5
|
+
function i(i) {
|
|
6
|
+
let a = e(6), [o, s] = n(null), [c, l] = n(0), u, d;
|
|
7
|
+
a[0] === i ? (u = a[1], d = a[2]) : (u = () => {
|
|
8
|
+
let e = new FileReader();
|
|
9
|
+
e.onload = async (e) => {
|
|
10
|
+
let t = new Uint8Array(e.target?.result);
|
|
11
|
+
try {
|
|
12
|
+
let e = await r.getDocument(t).promise;
|
|
13
|
+
s(e), l(e.numPages);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
console.error("Errore caricamento:", e);
|
|
16
|
+
}
|
|
17
|
+
}, e.readAsArrayBuffer(i);
|
|
18
|
+
}, d = [i], a[0] = i, a[1] = u, a[2] = d), t(u, d);
|
|
19
|
+
let f;
|
|
20
|
+
return a[3] !== c || a[4] !== o ? (f = {
|
|
21
|
+
pdf: o,
|
|
22
|
+
numPages: c
|
|
23
|
+
}, a[3] = c, a[4] = o, a[5] = f) : f = a[5], f;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { i as usePDFLoader };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useEffect as e, useRef as t, useState as n } from "react";
|
|
2
|
+
import "pdfjs-dist";
|
|
3
|
+
//#region src/hooks/usePDFRenderer.ts
|
|
4
|
+
function r({ pdf: r, zoom: i, rotation: a, visiblePages: o, canvasRefs: s }) {
|
|
5
|
+
let [c, l] = n([]), [u, d] = n(/* @__PURE__ */ new Set()), f = t([]), p = t(/* @__PURE__ */ new Set()), m = t(!1);
|
|
6
|
+
return e(() => {
|
|
7
|
+
if (!r) return;
|
|
8
|
+
m.current = !1, p.current = /* @__PURE__ */ new Set(), d(/* @__PURE__ */ new Set());
|
|
9
|
+
let e = !1;
|
|
10
|
+
return (async () => {
|
|
11
|
+
let t = f.current.map((e) => e ? (e.cancel(), e.promise.catch(() => {})) : Promise.resolve());
|
|
12
|
+
if (await Promise.all(t), f.current = Array(r.numPages).fill(null), e) return;
|
|
13
|
+
let n = [];
|
|
14
|
+
for (let e = 1; e <= r.numPages; e++) {
|
|
15
|
+
let t = (await r.getPage(e)).getViewport({
|
|
16
|
+
scale: i,
|
|
17
|
+
rotation: a
|
|
18
|
+
});
|
|
19
|
+
n.push({
|
|
20
|
+
width: t.width,
|
|
21
|
+
height: t.height
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
e || (m.current = !0, l(n));
|
|
25
|
+
})(), () => {
|
|
26
|
+
e = !0, f.current.forEach((e) => e?.cancel());
|
|
27
|
+
};
|
|
28
|
+
}, [
|
|
29
|
+
r,
|
|
30
|
+
i,
|
|
31
|
+
a
|
|
32
|
+
]), e(() => {
|
|
33
|
+
if (!r || c.length !== r.numPages || !m.current) return;
|
|
34
|
+
let e = !1;
|
|
35
|
+
return (async () => {
|
|
36
|
+
for (let t of o) {
|
|
37
|
+
if (e || p.current.has(t)) continue;
|
|
38
|
+
let n = await r.getPage(t);
|
|
39
|
+
if (e) return;
|
|
40
|
+
let o = n.getViewport({
|
|
41
|
+
scale: i,
|
|
42
|
+
rotation: a
|
|
43
|
+
}), c = s.current[t - 1];
|
|
44
|
+
if (!c) continue;
|
|
45
|
+
let l = c.getContext("2d");
|
|
46
|
+
if (!l) continue;
|
|
47
|
+
let u = f.current[t - 1];
|
|
48
|
+
if (u && (u.cancel(), await u.promise.catch(() => {}), e)) return;
|
|
49
|
+
c.height = o.height, c.width = o.width;
|
|
50
|
+
let m = n.render({
|
|
51
|
+
canvasContext: l,
|
|
52
|
+
viewport: o,
|
|
53
|
+
canvas: c
|
|
54
|
+
});
|
|
55
|
+
f.current[t - 1] = m;
|
|
56
|
+
try {
|
|
57
|
+
await m.promise, e || (p.current = new Set(p.current).add(t), d((e) => {
|
|
58
|
+
if (e.has(t)) return e;
|
|
59
|
+
let n = new Set(e);
|
|
60
|
+
return n.add(t), n;
|
|
61
|
+
}));
|
|
62
|
+
} catch (e) {
|
|
63
|
+
e && typeof e == "object" && "name" in e && e.name !== "RenderingCancelledException" && console.error("Render error:", e);
|
|
64
|
+
} finally {
|
|
65
|
+
f.current[t - 1] === m && (f.current[t - 1] = null);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
})(), () => {
|
|
69
|
+
e = !0;
|
|
70
|
+
};
|
|
71
|
+
}, [
|
|
72
|
+
r,
|
|
73
|
+
c,
|
|
74
|
+
a,
|
|
75
|
+
o,
|
|
76
|
+
i
|
|
77
|
+
]), {
|
|
78
|
+
pageSizes: c,
|
|
79
|
+
renderedPages: u
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { r as usePDFRenderer };
|
|
@@ -1,46 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as e } from "react/compiler-runtime";
|
|
2
|
+
import { useEffect as t, useState as n } from "react";
|
|
2
3
|
import "pdfjs-dist";
|
|
3
|
-
import { c as n } from "react/compiler-runtime";
|
|
4
4
|
//#region src/hooks/useScrollTracking.ts
|
|
5
5
|
var r = 10;
|
|
6
6
|
function i(i) {
|
|
7
|
-
let a =
|
|
8
|
-
a[0] !==
|
|
7
|
+
let a = e(17), { pdf: o, numPages: s, zoom: c, rotation: l, containerRef: u, pageRefs: d, canvasRefs: f } = i, [p, m] = n(1), h;
|
|
8
|
+
a[0] !== u || a[1] !== d ? (h = () => {
|
|
9
9
|
let e = u.current;
|
|
10
10
|
if (!e) return;
|
|
11
11
|
let t = () => {
|
|
12
12
|
let t = e.getBoundingClientRect().top, n = d.current;
|
|
13
13
|
for (let e = 0; e < n.length; e++) {
|
|
14
14
|
let r = n[e];
|
|
15
|
-
r &&
|
|
15
|
+
r && r.getBoundingClientRect().top - t <= 150 && m(e + 1);
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
return e.addEventListener("scroll", t), () => e.removeEventListener("scroll", t);
|
|
19
|
-
}, a[0] =
|
|
20
|
-
let
|
|
21
|
-
a[3] !==
|
|
19
|
+
}, a[0] = u, a[1] = d, a[2] = h) : h = a[2];
|
|
20
|
+
let g;
|
|
21
|
+
a[3] !== f || a[4] !== u || a[5] !== d || a[6] !== o || a[7] !== l || a[8] !== c ? (g = [
|
|
22
22
|
o,
|
|
23
23
|
c,
|
|
24
24
|
l,
|
|
25
25
|
u,
|
|
26
|
-
d
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
d,
|
|
27
|
+
f
|
|
28
|
+
], a[3] = f, a[4] = u, a[5] = d, a[6] = o, a[7] = l, a[8] = c, a[9] = g) : g = a[9], t(h, g);
|
|
29
|
+
let _;
|
|
30
|
+
a[10] !== u || a[11] !== s || a[12] !== d ? (_ = (e) => {
|
|
30
31
|
let t = Math.min(Math.max(e, 1), s), n = d.current[t - 1], i = u.current;
|
|
31
32
|
if (n && i) {
|
|
32
|
-
let e =
|
|
33
|
+
let e = n.getBoundingClientRect().top, a = i.getBoundingClientRect().top, o = i.scrollTop + (e - a) - r;
|
|
33
34
|
i.scrollTo({
|
|
34
35
|
top: o,
|
|
35
36
|
behavior: "smooth"
|
|
36
|
-
}),
|
|
37
|
+
}), m(t);
|
|
37
38
|
}
|
|
38
|
-
}, a[
|
|
39
|
-
let
|
|
40
|
-
return a[
|
|
41
|
-
currentPage:
|
|
42
|
-
goToPage:
|
|
43
|
-
}, a[
|
|
39
|
+
}, a[10] = u, a[11] = s, a[12] = d, a[13] = _) : _ = a[13];
|
|
40
|
+
let v = _, y;
|
|
41
|
+
return a[14] !== p || a[15] !== v ? (y = {
|
|
42
|
+
currentPage: p,
|
|
43
|
+
goToPage: v
|
|
44
|
+
}, a[14] = p, a[15] = v, a[16] = y) : y = a[16], y;
|
|
44
45
|
}
|
|
45
46
|
//#endregion
|
|
46
47
|
export { i as useScrollTracking };
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { c as e } from "react/compiler-runtime";
|
|
2
|
+
import { useEffect as t, useRef as n } from "react";
|
|
3
|
+
import * as r from "pdfjs-dist";
|
|
4
4
|
//#region src/hooks/useTextLayer.ts
|
|
5
5
|
function i(i) {
|
|
6
|
-
let a =
|
|
6
|
+
let a = e(8), { pdf: o, zoom: s, rotation: c, mountedPages: l, canvasRefs: u } = i, d;
|
|
7
7
|
a[0] === Symbol.for("react.memo_cache_sentinel") ? (d = [], a[0] = d) : d = a[0];
|
|
8
|
-
let f =
|
|
8
|
+
let f = n(d), p, m;
|
|
9
9
|
return a[1] !== u || a[2] !== l || a[3] !== o || a[4] !== c || a[5] !== s ? (p = () => {
|
|
10
10
|
if (!o) return;
|
|
11
11
|
let e = !1;
|
|
12
12
|
return (async () => {
|
|
13
|
-
for (let t
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
for (let t of l) {
|
|
14
|
+
if (e) break;
|
|
15
|
+
let n = f.current[t - 1], i = u.current[t - 1];
|
|
16
|
+
if (!n || !i) continue;
|
|
17
|
+
n.replaceChildren();
|
|
17
18
|
let a = await o.getPage(t), l = a.getViewport({
|
|
18
19
|
scale: s,
|
|
19
20
|
rotation: c
|
|
20
21
|
}), d = await a.getTextContent();
|
|
21
22
|
if (e) break;
|
|
22
|
-
|
|
23
|
+
n.style.width = `${l.width}px`, n.style.height = `${l.height}px`, await new r.TextLayer({
|
|
23
24
|
textContentSource: d,
|
|
24
|
-
container:
|
|
25
|
+
container: n,
|
|
25
26
|
viewport: l
|
|
26
27
|
}).render();
|
|
27
28
|
}
|
|
@@ -34,7 +35,7 @@ function i(i) {
|
|
|
34
35
|
c,
|
|
35
36
|
l,
|
|
36
37
|
u
|
|
37
|
-
], a[1] = u, a[2] = l, a[3] = o, a[4] = c, a[5] = s, a[6] = p, a[7] = m) : (p = a[6], m = a[7]),
|
|
38
|
+
], a[1] = u, a[2] = l, a[3] = o, a[4] = c, a[5] = s, a[6] = p, a[7] = m) : (p = a[6], m = a[7]), t(p, m), f;
|
|
38
39
|
}
|
|
39
40
|
//#endregion
|
|
40
41
|
export { i as useTextLayer };
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as e } from "react/compiler-runtime";
|
|
2
|
+
import { useEffect as t, useState as n } from "react";
|
|
2
3
|
import "pdfjs-dist";
|
|
3
|
-
import { c as n } from "react/compiler-runtime";
|
|
4
4
|
//#region src/hooks/useTextSearch.ts
|
|
5
5
|
function r(r) {
|
|
6
|
-
let i =
|
|
7
|
-
i[0] === Symbol.for("react.memo_cache_sentinel") ? (s =
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
let i = e(12), { pdf: a, query: o } = r, s;
|
|
7
|
+
i[0] === Symbol.for("react.memo_cache_sentinel") ? (s = {
|
|
8
|
+
query: "",
|
|
9
|
+
matches: []
|
|
10
|
+
}, i[0] = s) : s = i[0];
|
|
11
|
+
let [c, l] = n(s), u, d;
|
|
12
|
+
i[1] !== a || i[2] !== o ? (u = () => {
|
|
10
13
|
let e = o.trim().toLowerCase();
|
|
11
|
-
if (!a || !e)
|
|
12
|
-
l([]);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
14
|
+
if (!a || !e) return;
|
|
15
15
|
let t = !1;
|
|
16
16
|
return (async () => {
|
|
17
|
-
d(!0);
|
|
18
17
|
let n = [];
|
|
19
18
|
for (let r = 1; r <= a.numPages && !t; r++) {
|
|
20
19
|
let t = await (await a.getPage(r)).getTextContent();
|
|
@@ -37,16 +36,29 @@ function r(r) {
|
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
|
-
t ||
|
|
39
|
+
t || l({
|
|
40
|
+
query: o,
|
|
41
|
+
matches: n
|
|
42
|
+
});
|
|
41
43
|
})(), () => {
|
|
42
44
|
t = !0;
|
|
43
45
|
};
|
|
44
|
-
},
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
}, d = [a, o], i[1] = a, i[2] = o, i[3] = u, i[4] = d) : (u = i[3], d = i[4]), t(u, d);
|
|
47
|
+
let f = o.trim();
|
|
48
|
+
if (!a || !f) {
|
|
49
|
+
let e;
|
|
50
|
+
return i[5] === Symbol.for("react.memo_cache_sentinel") ? (e = {
|
|
51
|
+
matches: [],
|
|
52
|
+
searching: !1
|
|
53
|
+
}, i[5] = e) : e = i[5], e;
|
|
54
|
+
}
|
|
55
|
+
let p = c.query !== o, m;
|
|
56
|
+
i[6] !== p || i[7] !== c.matches ? (m = p ? [] : c.matches, i[6] = p, i[7] = c.matches, i[8] = m) : m = i[8];
|
|
57
|
+
let h;
|
|
58
|
+
return i[9] !== p || i[10] !== m ? (h = {
|
|
59
|
+
matches: m,
|
|
60
|
+
searching: p
|
|
61
|
+
}, i[9] = p, i[10] = m, i[11] = h) : h = i[11], h;
|
|
50
62
|
}
|
|
51
63
|
//#endregion
|
|
52
64
|
export { r as useTextSearch };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ThemeContext as e } from "../context/themeContextValue.js";
|
|
2
|
+
import { useContext as t } from "react";
|
|
3
|
+
//#region src/hooks/useTheme.ts
|
|
4
|
+
function n() {
|
|
5
|
+
let n = t(e);
|
|
6
|
+
if (!n) throw Error("useTheme must be used inside <ThemeProvider>");
|
|
7
|
+
return n;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { n as useTheme };
|
|
@@ -1,30 +1,92 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as e } from "react/compiler-runtime";
|
|
2
|
+
import { useEffect as t, useReducer as n, useRef as r } from "react";
|
|
2
3
|
import "pdfjs-dist";
|
|
3
|
-
import { c as n } from "react/compiler-runtime";
|
|
4
4
|
//#region src/hooks/useThumbnails.ts
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
function i(e, t) {
|
|
6
|
+
if (t.type === "reset") return {
|
|
7
|
+
thumbnails: Array(t.numPages).fill(null),
|
|
8
|
+
version: e.version + 1
|
|
9
|
+
};
|
|
10
|
+
if (t.type === "set") {
|
|
11
|
+
let n = [...e.thumbnails];
|
|
12
|
+
return n[t.pageNum - 1] = t.dataUrl, {
|
|
13
|
+
thumbnails: n,
|
|
14
|
+
version: e.version
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return e;
|
|
18
|
+
}
|
|
19
|
+
function a(a) {
|
|
20
|
+
let o = e(14), { pdf: s, rotation: c, visiblePages: l } = a, u;
|
|
21
|
+
o[0] === Symbol.for("react.memo_cache_sentinel") ? (u = {
|
|
22
|
+
thumbnails: [],
|
|
23
|
+
version: 0
|
|
24
|
+
}, o[0] = u) : u = o[0];
|
|
25
|
+
let [d, f] = n(i, u), { thumbnails: p, version: m } = d, h;
|
|
26
|
+
o[1] === Symbol.for("react.memo_cache_sentinel") ? (h = /* @__PURE__ */ new Set(), o[1] = h) : h = o[1];
|
|
27
|
+
let g = r(h), _;
|
|
28
|
+
o[2] === Symbol.for("react.memo_cache_sentinel") ? (_ = {
|
|
29
|
+
pdf: null,
|
|
30
|
+
rotation: 0
|
|
31
|
+
}, o[2] = _) : _ = o[2];
|
|
32
|
+
let v = r(_), y;
|
|
33
|
+
o[3] !== s || o[4] !== c || o[5] !== l ? (y = () => {
|
|
34
|
+
if (!s) {
|
|
35
|
+
f({
|
|
36
|
+
type: "reset",
|
|
37
|
+
numPages: 0
|
|
38
|
+
}), g.current.clear(), v.current = {
|
|
39
|
+
pdf: null,
|
|
40
|
+
rotation: 0
|
|
41
|
+
};
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (v.current.pdf !== s || v.current.rotation !== c) {
|
|
45
|
+
v.current = {
|
|
46
|
+
pdf: s,
|
|
47
|
+
rotation: c
|
|
48
|
+
}, g.current.clear(), f({
|
|
49
|
+
type: "reset",
|
|
50
|
+
numPages: s.numPages
|
|
51
|
+
});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
let e = l.filter((e) => !g.current.has(e));
|
|
55
|
+
if (e.length === 0) return;
|
|
56
|
+
let t = !1;
|
|
57
|
+
return (async () => {
|
|
58
|
+
for (let n of e) {
|
|
59
|
+
if (t) break;
|
|
60
|
+
let e = await s.getPage(n), r = e.getViewport({
|
|
14
61
|
scale: .2,
|
|
15
|
-
rotation:
|
|
16
|
-
}), i = document.createElement("canvas"),
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
62
|
+
rotation: c
|
|
63
|
+
}), i = document.createElement("canvas"), a = i.getContext("2d");
|
|
64
|
+
if (a) {
|
|
65
|
+
if (i.height = r.height, i.width = r.width, await e.render({
|
|
66
|
+
canvasContext: a,
|
|
67
|
+
viewport: r,
|
|
68
|
+
canvas: i
|
|
69
|
+
}).promise, t) break;
|
|
70
|
+
g.current.add(n), f({
|
|
71
|
+
type: "set",
|
|
72
|
+
pageNum: n,
|
|
73
|
+
dataUrl: i.toDataURL()
|
|
74
|
+
});
|
|
75
|
+
}
|
|
22
76
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
77
|
+
})(), () => {
|
|
78
|
+
t = !0;
|
|
79
|
+
};
|
|
80
|
+
}, o[3] = s, o[4] = c, o[5] = l, o[6] = y) : y = o[6];
|
|
81
|
+
let b;
|
|
82
|
+
o[7] !== s || o[8] !== c || o[9] !== m || o[10] !== l ? (b = [
|
|
83
|
+
s,
|
|
84
|
+
c,
|
|
85
|
+
l,
|
|
86
|
+
m
|
|
87
|
+
], o[7] = s, o[8] = c, o[9] = m, o[10] = l, o[11] = b) : b = o[11], t(y, b);
|
|
88
|
+
let x;
|
|
89
|
+
return o[12] === p ? x = o[13] : (x = { thumbnails: p }, o[12] = p, o[13] = x), x;
|
|
28
90
|
}
|
|
29
91
|
//#endregion
|
|
30
|
-
export {
|
|
92
|
+
export { a as useThumbnails };
|
package/dist/es/index.js
CHANGED
|
@@ -14,4 +14,5 @@ import { PDFThumbnails as h } from "./components/features/PDFThumbnails.js";
|
|
|
14
14
|
import { PDFZoomControls as g } from "./components/features/PDFZoomControls.js";
|
|
15
15
|
import { PDFThemeToggle as _ } from "./components/features/PDFThemeToggle.js";
|
|
16
16
|
import { PDFPrintButton as v } from "./components/features/PDFPrintButton.js";
|
|
17
|
-
|
|
17
|
+
import { PDFSidebarToggle as y } from "./components/features/PDFSidebarToggle.js";
|
|
18
|
+
export { i as PDFAnnotations, a as PDFAnnotationsIcon, o as PDFChangeFile, s as PDFDownloadButton, c as PDFNavigation, l as PDFOutline, u as PDFPageFit, v as PDFPrintButton, d as PDFRotationControl, f as PDFSearch, r as PDFSidebar, y as PDFSidebarToggle, p as PDFSignatures, m as PDFSignaturesIcon, _ as PDFThemeToggle, h as PDFThumbnails, n as PDFViewer, g as PDFZoomControls, e as darkTheme, t as lightTheme };
|