pdf-tsx 1.1.0 → 1.2.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 +46 -2
- package/dist/cjs/components/features/PDFOutline.cjs +1 -1
- package/dist/cjs/hooks/useAnnotationLayer.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/useTextLayer.cjs +1 -1
- package/dist/cjs/hooks/useThumbnails.cjs +1 -1
- package/dist/cjs/utils/pdfFit.cjs +1 -1
- package/dist/cjs/utils/rotation.cjs +1 -0
- package/dist/cjs/vendor/pdfjs-wasm/jbig2.cjs +1 -0
- package/dist/cjs/vendor/pdfjs-wasm/openjpeg.cjs +1 -0
- package/dist/cjs/vendor/pdfjs-wasm/qcms_bg.cjs +1 -0
- package/dist/components/PDFSidebar.d.ts +1 -1
- package/dist/components/PDFViewer.d.ts +2 -2
- package/dist/components/features/PDFAnnotations.d.ts +2 -2
- package/dist/components/features/PDFAttachments.d.ts +2 -2
- package/dist/components/features/PDFChangeFile.d.ts +1 -1
- package/dist/components/features/PDFDownloadButton.d.ts +1 -1
- package/dist/components/features/PDFNavigation.d.ts +1 -1
- package/dist/components/features/PDFOutline.d.ts +1 -1
- package/dist/components/features/PDFPageFit.d.ts +1 -1
- package/dist/components/features/PDFPrintButton.d.ts +1 -1
- package/dist/components/features/PDFRotationControl.d.ts +1 -1
- package/dist/components/features/PDFSearch.d.ts +1 -1
- package/dist/components/features/PDFSidebarToggle.d.ts +1 -1
- package/dist/components/features/PDFSignatures.d.ts +2 -2
- package/dist/components/features/PDFThemeToggle.d.ts +1 -1
- package/dist/components/features/PDFThumbnails.d.ts +1 -1
- package/dist/components/features/PDFViewModeToggle.d.ts +11 -0
- package/dist/components/features/PDFZoomControls.d.ts +1 -1
- package/dist/components/ui/PDFToolbar.d.ts +1 -1
- package/dist/components/ui/PDFToolbarItem.d.ts +1 -1
- package/dist/components/ui/PDFToolbarSeparator.d.ts +1 -1
- package/dist/components/ui/ToolbarButton.d.ts +1 -1
- package/dist/components/ui/icons.d.ts +3 -2
- package/dist/context/LabelsContext.d.ts +1 -1
- package/dist/context/PDFViewerContext.d.ts +2 -0
- package/dist/context/ThemeContext.d.ts +1 -1
- package/dist/es/components/features/PDFOutline.js +47 -46
- package/dist/es/hooks/useAnnotationLayer.js +39 -38
- package/dist/es/hooks/useOverlayRects.js +44 -43
- package/dist/es/hooks/usePDFLoader.js +36 -16
- package/dist/es/hooks/usePDFRenderer.js +65 -64
- package/dist/es/hooks/useTextLayer.js +34 -33
- package/dist/es/hooks/useThumbnails.js +33 -32
- package/dist/es/utils/pdfFit.js +13 -12
- package/dist/es/utils/rotation.js +6 -0
- package/dist/es/vendor/pdfjs-wasm/jbig2.js +4 -0
- package/dist/es/vendor/pdfjs-wasm/openjpeg.js +4 -0
- package/dist/es/vendor/pdfjs-wasm/qcms_bg.js +4 -0
- package/dist/hooks/usePDFLoader.d.ts +1 -1
- package/dist/hooks/usePinchZoom.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/labels.d.ts +4 -0
- package/dist/utils/pdfjsPolyfill.d.ts +2 -0
- package/dist/utils/rotation.d.ts +7 -0
- package/dist/utils/zoom.d.ts +4 -0
- package/package.json +3 -2
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { usePDFViewer as e } from "../../context/PDFViewerContext.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import a from "
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
2
|
+
import { getEffectiveRotation as t } from "../../utils/rotation.js";
|
|
3
|
+
import { useLabels as n } from "../../hooks/useLabels.js";
|
|
4
|
+
import { useOutline as r } from "../../hooks/useOutline.js";
|
|
5
|
+
import { IconChevronDown as i, IconChevronRight as a } from "../ui/icons.js";
|
|
6
|
+
import o from "./PDFOutline.module.js";
|
|
7
|
+
import { memo as s, useCallback as c, useMemo as l, useState as u } from "react";
|
|
8
|
+
import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
8
9
|
//#region src/components/features/PDFOutline.tsx
|
|
9
|
-
async function
|
|
10
|
+
async function m(e, t) {
|
|
10
11
|
if (!e || !t) return null;
|
|
11
12
|
try {
|
|
12
13
|
let n = typeof t == "string" ? await e.getDestination(t) : t;
|
|
@@ -20,10 +21,10 @@ async function p(e, t) {
|
|
|
20
21
|
return null;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
|
-
var
|
|
24
|
-
let [
|
|
24
|
+
var h = s(function e({ node: t, depth: n, onNavigate: r }) {
|
|
25
|
+
let [s, m] = u(n === 0), h = t.items.length > 0, g = c((e) => {
|
|
25
26
|
e.stopPropagation(), m((e) => !e);
|
|
26
|
-
}, []), _ =
|
|
27
|
+
}, []), _ = c(() => r(t.dest), [r, t.dest]), v = l(() => ({
|
|
27
28
|
paddingLeft: 12 + n * 14,
|
|
28
29
|
fontWeight: t.bold ? 600 : 400,
|
|
29
30
|
fontStyle: t.italic ? "italic" : "normal"
|
|
@@ -32,66 +33,66 @@ var m = o(function e({ node: t, depth: n, onNavigate: o }) {
|
|
|
32
33
|
t.bold,
|
|
33
34
|
t.italic
|
|
34
35
|
]);
|
|
35
|
-
return /* @__PURE__ */
|
|
36
|
-
className:
|
|
36
|
+
return /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ p("div", {
|
|
37
|
+
className: o.row,
|
|
37
38
|
style: v,
|
|
38
39
|
onClick: _,
|
|
39
|
-
children: [h ? /* @__PURE__ */
|
|
40
|
-
className:
|
|
40
|
+
children: [h ? /* @__PURE__ */ f("button", {
|
|
41
|
+
className: o.chevronBtn,
|
|
41
42
|
onClick: g,
|
|
42
|
-
children:
|
|
43
|
-
}) : /* @__PURE__ */
|
|
43
|
+
children: f(s ? i : a, { size: 12 })
|
|
44
|
+
}) : /* @__PURE__ */ f("span", { style: {
|
|
44
45
|
width: 16,
|
|
45
46
|
flexShrink: 0
|
|
46
|
-
} }), /* @__PURE__ */
|
|
47
|
-
className:
|
|
47
|
+
} }), /* @__PURE__ */ f("span", {
|
|
48
|
+
className: o.title,
|
|
48
49
|
title: t.title,
|
|
49
50
|
children: t.title
|
|
50
51
|
})]
|
|
51
|
-
}),
|
|
52
|
+
}), s && t.items.map((t, i) => /* @__PURE__ */ f(e, {
|
|
52
53
|
node: t,
|
|
53
54
|
depth: n + 1,
|
|
54
|
-
onNavigate:
|
|
55
|
-
},
|
|
55
|
+
onNavigate: r
|
|
56
|
+
}, i))] });
|
|
56
57
|
});
|
|
57
|
-
function
|
|
58
|
-
let { pdf:
|
|
59
|
-
let
|
|
60
|
-
if (
|
|
61
|
-
if (
|
|
62
|
-
let
|
|
63
|
-
scale:
|
|
64
|
-
rotation:
|
|
65
|
-
}).convertToViewportPoint(0,
|
|
66
|
-
|
|
58
|
+
function g() {
|
|
59
|
+
let { pdf: i, zoom: a, rotation: s, goToPage: l } = e(), u = n(), { outline: d, loading: g } = r({ pdf: i }), _ = c(async (e) => {
|
|
60
|
+
let n = await m(i, e);
|
|
61
|
+
if (n) {
|
|
62
|
+
if (n.pdfTop !== null) try {
|
|
63
|
+
let e = await i.getPage(n.page), [, r] = e.getViewport({
|
|
64
|
+
scale: a,
|
|
65
|
+
rotation: t(e, s)
|
|
66
|
+
}).convertToViewportPoint(0, n.pdfTop);
|
|
67
|
+
l(n.page, r);
|
|
67
68
|
return;
|
|
68
69
|
} catch {}
|
|
69
|
-
|
|
70
|
+
l(n.page);
|
|
70
71
|
}
|
|
71
72
|
}, [
|
|
72
|
-
r,
|
|
73
73
|
i,
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
a,
|
|
75
|
+
s,
|
|
76
|
+
l
|
|
76
77
|
]);
|
|
77
|
-
return /* @__PURE__ */
|
|
78
|
-
className:
|
|
78
|
+
return /* @__PURE__ */ p("div", {
|
|
79
|
+
className: o.tree,
|
|
79
80
|
children: [
|
|
80
|
-
|
|
81
|
-
className:
|
|
82
|
-
children:
|
|
81
|
+
g && /* @__PURE__ */ f("div", {
|
|
82
|
+
className: o.emptyState,
|
|
83
|
+
children: u.outlineLoading
|
|
83
84
|
}),
|
|
84
|
-
!
|
|
85
|
-
className:
|
|
86
|
-
children:
|
|
85
|
+
!g && d.length === 0 && /* @__PURE__ */ f("div", {
|
|
86
|
+
className: o.emptyState,
|
|
87
|
+
children: u.outlineEmpty
|
|
87
88
|
}),
|
|
88
|
-
!
|
|
89
|
+
!g && d.map((e, t) => /* @__PURE__ */ f(h, {
|
|
89
90
|
node: e,
|
|
90
91
|
depth: 0,
|
|
91
|
-
onNavigate:
|
|
92
|
+
onNavigate: _
|
|
92
93
|
}, t))
|
|
93
94
|
]
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
//#endregion
|
|
97
|
-
export {
|
|
98
|
+
export { g as PDFOutline };
|
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getEffectiveRotation as e } from "../utils/rotation.js";
|
|
2
|
+
import { isSafeUrl as t } from "../utils/url.js";
|
|
3
|
+
import { useEffect as n, useState as r } from "react";
|
|
3
4
|
import "pdfjs-dist";
|
|
4
5
|
//#region src/hooks/useAnnotationLayer.ts
|
|
5
|
-
function
|
|
6
|
-
let [
|
|
7
|
-
|
|
8
|
-
if (!
|
|
9
|
-
let
|
|
6
|
+
function i({ pdf: i, zoom: a, rotation: o, mountedPages: s, goToPage: c }) {
|
|
7
|
+
let [l, u] = r([]), [d, f] = r([]);
|
|
8
|
+
n(() => {
|
|
9
|
+
if (!i) return;
|
|
10
|
+
let t = !1;
|
|
10
11
|
return (async () => {
|
|
11
|
-
let
|
|
12
|
-
for (let
|
|
13
|
-
if (
|
|
14
|
-
let
|
|
15
|
-
scale:
|
|
16
|
-
rotation:
|
|
17
|
-
}),
|
|
18
|
-
for (let e of
|
|
12
|
+
let n = [], r = [];
|
|
13
|
+
for (let c of s) {
|
|
14
|
+
if (t) break;
|
|
15
|
+
let s = await i.getPage(c), l = s.getViewport({
|
|
16
|
+
scale: a,
|
|
17
|
+
rotation: e(s, o)
|
|
18
|
+
}), u = await s.getAnnotations();
|
|
19
|
+
for (let e of u) {
|
|
19
20
|
if (!e.rect) continue;
|
|
20
|
-
let
|
|
21
|
-
if (e.subtype === "Link")
|
|
22
|
-
page:
|
|
21
|
+
let t = e.rect, [i, a, o, s] = l.convertToViewportRectangle(t), u = Math.min(i, o), d = Math.min(a, s), f = Math.abs(o - i), p = Math.abs(s - a);
|
|
22
|
+
if (e.subtype === "Link") n.push({
|
|
23
|
+
page: c,
|
|
23
24
|
x: u,
|
|
24
25
|
y: d,
|
|
25
26
|
width: f,
|
|
@@ -29,9 +30,9 @@ function r({ pdf: r, zoom: i, rotation: a, mountedPages: o, goToPage: s }) {
|
|
|
29
30
|
newWindow: e.newWindow
|
|
30
31
|
});
|
|
31
32
|
else {
|
|
32
|
-
let
|
|
33
|
-
a &&
|
|
34
|
-
page:
|
|
33
|
+
let n = e.contentsObj, i = e.titleObj, a = n?.str ?? e.contents ?? "", o = i?.str ?? e.title;
|
|
34
|
+
a && r.push({
|
|
35
|
+
page: c,
|
|
35
36
|
x: u,
|
|
36
37
|
y: d,
|
|
37
38
|
width: f,
|
|
@@ -39,40 +40,40 @@ function r({ pdf: r, zoom: i, rotation: a, mountedPages: o, goToPage: s }) {
|
|
|
39
40
|
contents: a,
|
|
40
41
|
title: o || void 0,
|
|
41
42
|
subtype: e.subtype,
|
|
42
|
-
pdfRect:
|
|
43
|
+
pdfRect: t
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
+
t || (u(n), f(r));
|
|
48
49
|
})(), () => {
|
|
49
|
-
|
|
50
|
+
t = !0;
|
|
50
51
|
};
|
|
51
52
|
}, [
|
|
52
|
-
r,
|
|
53
53
|
i,
|
|
54
54
|
a,
|
|
55
|
-
o
|
|
55
|
+
o,
|
|
56
|
+
s
|
|
56
57
|
]);
|
|
57
|
-
let
|
|
58
|
-
if (
|
|
59
|
-
if (!e
|
|
60
|
-
window.open(
|
|
58
|
+
let p = async (e) => {
|
|
59
|
+
if (e.url) {
|
|
60
|
+
if (!t(e.url)) return;
|
|
61
|
+
window.open(e.url, "_blank", "noopener,noreferrer");
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
|
-
if (
|
|
64
|
-
let
|
|
65
|
-
if (typeof
|
|
66
|
-
|
|
64
|
+
if (e.dest && i) {
|
|
65
|
+
let t = null;
|
|
66
|
+
if (typeof e.dest == "string" ? t = await i.getDestination(e.dest) : Array.isArray(e.dest) && (t = e.dest), !t) return;
|
|
67
|
+
c(await i.getPageIndex(t[0]) + 1);
|
|
67
68
|
}
|
|
68
69
|
};
|
|
69
70
|
return {
|
|
70
|
-
linkOverlays:
|
|
71
|
+
linkOverlays: l.map((e) => ({
|
|
71
72
|
...e,
|
|
72
|
-
_handleClick:
|
|
73
|
+
_handleClick: p.bind(null, e)
|
|
73
74
|
})),
|
|
74
|
-
noteOverlays:
|
|
75
|
+
noteOverlays: d
|
|
75
76
|
};
|
|
76
77
|
}
|
|
77
78
|
//#endregion
|
|
78
|
-
export {
|
|
79
|
+
export { i as useAnnotationLayer };
|
|
@@ -1,63 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getEffectiveRotation as e } from "../utils/rotation.js";
|
|
2
|
+
import { useEffect as t, useState as n } from "react";
|
|
2
3
|
import "pdfjs-dist";
|
|
3
4
|
//#region src/hooks/useOverlayRects.ts
|
|
4
|
-
function
|
|
5
|
-
let [
|
|
6
|
-
return
|
|
7
|
-
if (!
|
|
8
|
-
let
|
|
5
|
+
function r({ pdf: r, highlight: i, searchMatches: a, zoom: o, rotation: s }) {
|
|
6
|
+
let [c, l] = n(null), [u, d] = n([]);
|
|
7
|
+
return t(() => {
|
|
8
|
+
if (!r || a.length === 0) return;
|
|
9
|
+
let t = !1;
|
|
9
10
|
return (async () => {
|
|
10
|
-
let
|
|
11
|
-
for (let
|
|
12
|
-
if (
|
|
13
|
-
let
|
|
14
|
-
scale:
|
|
15
|
-
rotation:
|
|
16
|
-
}).convertToViewportRectangle(
|
|
17
|
-
|
|
18
|
-
page:
|
|
19
|
-
x: Math.min(
|
|
20
|
-
y: Math.min(
|
|
21
|
-
width: Math.abs(
|
|
22
|
-
height: Math.abs(
|
|
11
|
+
let n = [];
|
|
12
|
+
for (let i of a) {
|
|
13
|
+
if (t) break;
|
|
14
|
+
let a = await r.getPage(i.page), [c, l, u, d] = a.getViewport({
|
|
15
|
+
scale: o,
|
|
16
|
+
rotation: e(a, s)
|
|
17
|
+
}).convertToViewportRectangle(i.pdfRect);
|
|
18
|
+
n.push({
|
|
19
|
+
page: i.page,
|
|
20
|
+
x: Math.min(c, u),
|
|
21
|
+
y: Math.min(l, d),
|
|
22
|
+
width: Math.abs(u - c),
|
|
23
|
+
height: Math.abs(d - l)
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
t || d(n);
|
|
26
27
|
})(), () => {
|
|
27
|
-
|
|
28
|
+
t = !0;
|
|
28
29
|
};
|
|
29
30
|
}, [
|
|
30
|
-
i,
|
|
31
31
|
a,
|
|
32
32
|
o,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
s,
|
|
34
|
+
r
|
|
35
|
+
]), t(() => {
|
|
36
|
+
if (!i || !r) return;
|
|
37
|
+
let t = !1;
|
|
37
38
|
return (async () => {
|
|
38
|
-
let [
|
|
39
|
-
scale:
|
|
40
|
-
rotation:
|
|
41
|
-
}).convertToViewportRectangle(
|
|
42
|
-
|
|
43
|
-
page:
|
|
44
|
-
x: Math.min(
|
|
45
|
-
y: Math.min(
|
|
46
|
-
width: Math.abs(
|
|
47
|
-
height: Math.abs(
|
|
39
|
+
let n = await r.getPage(i.page), [a, c, u, d] = n.getViewport({
|
|
40
|
+
scale: o,
|
|
41
|
+
rotation: e(n, s)
|
|
42
|
+
}).convertToViewportRectangle(i.pdfRect);
|
|
43
|
+
t || l({
|
|
44
|
+
page: i.page,
|
|
45
|
+
x: Math.min(a, u),
|
|
46
|
+
y: Math.min(c, d),
|
|
47
|
+
width: Math.abs(u - a),
|
|
48
|
+
height: Math.abs(d - c)
|
|
48
49
|
});
|
|
49
50
|
})(), () => {
|
|
50
|
-
|
|
51
|
+
t = !0;
|
|
51
52
|
};
|
|
52
53
|
}, [
|
|
53
|
-
|
|
54
|
-
a,
|
|
54
|
+
i,
|
|
55
55
|
o,
|
|
56
|
-
|
|
56
|
+
s,
|
|
57
|
+
r
|
|
57
58
|
]), {
|
|
58
|
-
overlayRect: !
|
|
59
|
-
searchOverlays: !
|
|
59
|
+
overlayRect: !i || !r ? null : c,
|
|
60
|
+
searchOverlays: !r || a.length === 0 ? [] : u
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
//#endregion
|
|
63
|
-
export {
|
|
64
|
+
export { r as useOverlayRects };
|
|
@@ -1,27 +1,47 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import e from "../vendor/pdfjs-wasm/openjpeg.js";
|
|
2
|
+
import t from "../vendor/pdfjs-wasm/jbig2.js";
|
|
3
|
+
import n from "../vendor/pdfjs-wasm/qcms_bg.js";
|
|
4
|
+
import { useEffect as r, useState as i } from "react";
|
|
5
|
+
import * as a from "pdfjs-dist";
|
|
3
6
|
//#region src/hooks/usePDFLoader.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
var o = {
|
|
8
|
+
"openjpeg.wasm": e,
|
|
9
|
+
"jbig2.wasm": t,
|
|
10
|
+
"qcms_bg.wasm": n
|
|
11
|
+
}, s = class {
|
|
12
|
+
async fetch({ kind: e, filename: t }) {
|
|
13
|
+
let n = e === "wasmUrl" ? o[t] : void 0;
|
|
14
|
+
if (!n) throw Error(`Unable to load ${e} data at: ${t}`);
|
|
15
|
+
let r = await fetch(n);
|
|
16
|
+
return new Uint8Array(await r.arrayBuffer());
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
function c(e) {
|
|
20
|
+
let [t, n] = i(null), [o, c] = i(0), [l, u] = i(!0);
|
|
21
|
+
return r(() => {
|
|
22
|
+
u(!0), n(null), c(0);
|
|
23
|
+
let t = new FileReader();
|
|
24
|
+
t.onload = async (e) => {
|
|
10
25
|
let t = new Uint8Array(e.target?.result);
|
|
11
26
|
try {
|
|
12
|
-
let e = await
|
|
13
|
-
|
|
27
|
+
let e = await a.getDocument({
|
|
28
|
+
data: t,
|
|
29
|
+
wasmUrl: "wasm/",
|
|
30
|
+
useWorkerFetch: !1,
|
|
31
|
+
BinaryDataFactory: s
|
|
32
|
+
}).promise;
|
|
33
|
+
n(e), c(e.numPages);
|
|
14
34
|
} catch (e) {
|
|
15
35
|
console.error("Errore caricamento:", e);
|
|
16
36
|
} finally {
|
|
17
|
-
|
|
37
|
+
u(!1);
|
|
18
38
|
}
|
|
19
|
-
},
|
|
20
|
-
}, [
|
|
21
|
-
pdf:
|
|
39
|
+
}, t.readAsArrayBuffer(e);
|
|
40
|
+
}, [e]), {
|
|
41
|
+
pdf: t,
|
|
22
42
|
numPages: o,
|
|
23
|
-
loading:
|
|
43
|
+
loading: l
|
|
24
44
|
};
|
|
25
45
|
}
|
|
26
46
|
//#endregion
|
|
27
|
-
export {
|
|
47
|
+
export { c as usePDFLoader };
|
|
@@ -1,78 +1,79 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getEffectiveRotation as e } from "../utils/rotation.js";
|
|
2
|
+
import { useEffect as t, useRef as n, useState as r } from "react";
|
|
2
3
|
import "pdfjs-dist";
|
|
3
4
|
//#region src/hooks/usePDFRenderer.ts
|
|
4
|
-
function
|
|
5
|
-
let
|
|
6
|
-
if (!
|
|
7
|
-
let
|
|
8
|
-
scale:
|
|
9
|
-
rotation:
|
|
10
|
-
}),
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
scale:
|
|
14
|
-
rotation:
|
|
5
|
+
function i(t, n, r, i) {
|
|
6
|
+
let a = t.getContext("2d");
|
|
7
|
+
if (!a) return null;
|
|
8
|
+
let o = e(n, i), s = n.getViewport({
|
|
9
|
+
scale: r,
|
|
10
|
+
rotation: o
|
|
11
|
+
}), c = window.devicePixelRatio || 1, l = Math.min(1, 4096 / Math.max(s.width, s.height)), u = Math.sqrt(Math.min(1, 16777216 / (s.width * s.height))), d = Math.max(.1, Math.min(c, l, u));
|
|
12
|
+
d < c && console.warn(`[pdf-tsx] canvas clamped to avoid blank render: page=${n.pageNumber} zoom=${r} dpr=${c} requested=${Math.round(s.width * c)}x${Math.round(s.height * c)}px clamped=${Math.round(s.width * d)}x${Math.round(s.height * d)}px`);
|
|
13
|
+
let f = n.getViewport({
|
|
14
|
+
scale: r * d,
|
|
15
|
+
rotation: o
|
|
15
16
|
});
|
|
16
|
-
return
|
|
17
|
-
canvasContext:
|
|
18
|
-
viewport:
|
|
19
|
-
canvas:
|
|
17
|
+
return t.width = f.width, t.height = f.height, t.style.width = `${s.width}px`, t.style.height = `${s.height}px`, n.render({
|
|
18
|
+
canvasContext: a,
|
|
19
|
+
viewport: f,
|
|
20
|
+
canvas: t
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
-
let [
|
|
24
|
-
return
|
|
25
|
-
if (!
|
|
26
|
-
|
|
27
|
-
let
|
|
23
|
+
function a({ pdf: a, zoom: o, rotation: s, visiblePages: c, canvasRefs: l }) {
|
|
24
|
+
let [u, d] = r([]), [f, p] = r(/* @__PURE__ */ new Set()), m = n([]), h = n(/* @__PURE__ */ new Set()), g = n(!1);
|
|
25
|
+
return t(() => {
|
|
26
|
+
if (!a) return;
|
|
27
|
+
g.current = !1, h.current = /* @__PURE__ */ new Set(), p(/* @__PURE__ */ new Set());
|
|
28
|
+
let t = !1;
|
|
28
29
|
return (async () => {
|
|
29
|
-
let
|
|
30
|
-
if (await Promise.all(
|
|
31
|
-
let
|
|
32
|
-
if (
|
|
33
|
-
let
|
|
34
|
-
scale:
|
|
35
|
-
rotation:
|
|
36
|
-
}),
|
|
37
|
-
width:
|
|
38
|
-
height:
|
|
30
|
+
let n = m.current.map((e) => e ? (e.cancel(), e.promise.catch(() => {})) : Promise.resolve());
|
|
31
|
+
if (await Promise.all(n), m.current = Array(a.numPages).fill(null), t) return;
|
|
32
|
+
let r = await a.getPage(1);
|
|
33
|
+
if (t) return;
|
|
34
|
+
let i = r.getViewport({
|
|
35
|
+
scale: o,
|
|
36
|
+
rotation: e(r, s)
|
|
37
|
+
}), c = {
|
|
38
|
+
width: i.width,
|
|
39
|
+
height: i.height
|
|
39
40
|
};
|
|
40
|
-
|
|
41
|
-
let
|
|
42
|
-
let
|
|
43
|
-
scale:
|
|
44
|
-
rotation:
|
|
41
|
+
d(Array(a.numPages).fill(c));
|
|
42
|
+
let l = await Promise.all(Array.from({ length: a.numPages }, async (t, n) => {
|
|
43
|
+
let i = n === 0 ? r : await a.getPage(n + 1), c = i.getViewport({
|
|
44
|
+
scale: o,
|
|
45
|
+
rotation: e(i, s)
|
|
45
46
|
});
|
|
46
47
|
return {
|
|
47
|
-
width:
|
|
48
|
-
height:
|
|
48
|
+
width: c.width,
|
|
49
|
+
height: c.height
|
|
49
50
|
};
|
|
50
51
|
}));
|
|
51
|
-
|
|
52
|
+
t || (g.current = !0, d(l));
|
|
52
53
|
})(), () => {
|
|
53
|
-
|
|
54
|
+
t = !0, m.current.forEach((e) => e?.cancel());
|
|
54
55
|
};
|
|
55
56
|
}, [
|
|
56
|
-
i,
|
|
57
57
|
a,
|
|
58
|
-
o
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
o,
|
|
59
|
+
s
|
|
60
|
+
]), t(() => {
|
|
61
|
+
if (!a || u.length !== a.numPages || !g.current) return;
|
|
61
62
|
let e = !1;
|
|
62
63
|
return (async () => {
|
|
63
|
-
for (let t of
|
|
64
|
-
if (e ||
|
|
65
|
-
let n = await
|
|
64
|
+
for (let t of c) {
|
|
65
|
+
if (e || h.current.has(t)) continue;
|
|
66
|
+
let n = await a.getPage(t);
|
|
66
67
|
if (e) return;
|
|
67
|
-
let
|
|
68
|
-
if (!
|
|
69
|
-
let
|
|
70
|
-
if (
|
|
71
|
-
let u = r
|
|
68
|
+
let r = l.current[t - 1];
|
|
69
|
+
if (!r) continue;
|
|
70
|
+
let c = m.current[t - 1];
|
|
71
|
+
if (c && (c.cancel(), await c.promise.catch(() => {}), e)) return;
|
|
72
|
+
let u = i(r, n, o, s);
|
|
72
73
|
if (u) {
|
|
73
|
-
|
|
74
|
+
m.current[t - 1] = u;
|
|
74
75
|
try {
|
|
75
|
-
await u.promise, e || (
|
|
76
|
+
await u.promise, e || (h.current = new Set(h.current).add(t), p((e) => {
|
|
76
77
|
if (e.has(t)) return e;
|
|
77
78
|
let n = new Set(e);
|
|
78
79
|
return n.add(t), n;
|
|
@@ -80,7 +81,7 @@ function i({ pdf: i, zoom: a, rotation: o, visiblePages: s, canvasRefs: c }) {
|
|
|
80
81
|
} catch (e) {
|
|
81
82
|
e && typeof e == "object" && "name" in e && e.name !== "RenderingCancelledException" && console.error("Render error:", e);
|
|
82
83
|
} finally {
|
|
83
|
-
|
|
84
|
+
m.current[t - 1] === u && (m.current[t - 1] = null);
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
}
|
|
@@ -88,16 +89,16 @@ function i({ pdf: i, zoom: a, rotation: o, visiblePages: s, canvasRefs: c }) {
|
|
|
88
89
|
e = !0;
|
|
89
90
|
};
|
|
90
91
|
}, [
|
|
91
|
-
i,
|
|
92
|
-
l,
|
|
93
|
-
o,
|
|
94
|
-
s,
|
|
95
92
|
a,
|
|
96
|
-
|
|
93
|
+
u,
|
|
94
|
+
s,
|
|
95
|
+
c,
|
|
96
|
+
o,
|
|
97
|
+
l
|
|
97
98
|
]), {
|
|
98
|
-
pageSizes:
|
|
99
|
-
renderedPages:
|
|
99
|
+
pageSizes: u,
|
|
100
|
+
renderedPages: f
|
|
100
101
|
};
|
|
101
102
|
}
|
|
102
103
|
//#endregion
|
|
103
|
-
export {
|
|
104
|
+
export { a as usePDFRenderer };
|