@react-pdf-kit/viewer 0.0.0-experimental.4 → 0.0.0-experimental.6
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/dist/RPLayout.module-b4b23e29.js +14 -0
- package/dist/assets/style.css +1 -1
- package/dist/assets/style.js +15 -15
- package/dist/components/RPConfig.js +18 -6
- package/dist/components/RPController.js +21 -26
- package/dist/components/RPDropFileZone.js +34 -28
- package/dist/components/RPPages.js +352 -361
- package/dist/components/RPProvider.js +20 -24
- package/dist/components/layout/LayoutContainer.js +1 -1
- package/dist/components/layout/LayoutWrapper.js +1 -1
- package/dist/components/layout/RPDefaultLayout.js +6 -7
- package/dist/components/layout/RPLayout.js +22 -22
- package/dist/components/layout/WrapperLayout.js +10 -11
- package/dist/components/layout/sidebar/RPSidebar.js +3 -4
- package/dist/components/layout/sidebar/Thumbnail.js +3 -4
- package/dist/components/layout/sidebar/Thumbnails.js +3 -4
- package/dist/components/layout/toolbar/DocumentDialog.js +5 -6
- package/dist/components/layout/toolbar/FileDownloadTool.js +3 -4
- package/dist/components/layout/toolbar/FileUploadTool.js +3 -4
- package/dist/components/layout/toolbar/MostPageTool.js +3 -4
- package/dist/components/layout/toolbar/OtherTool.js +3 -4
- package/dist/components/layout/toolbar/Paginate.js +3 -4
- package/dist/components/layout/toolbar/PrintTool.js +3 -4
- package/dist/components/layout/toolbar/RPMoreOptions.js +3 -4
- package/dist/components/layout/toolbar/RPToolbar.js +3 -6
- package/dist/components/layout/toolbar/RPToolbarEnd.js +3 -4
- package/dist/components/layout/toolbar/RotateTool.js +3 -4
- package/dist/components/layout/toolbar/SearchResultNavigator.js +3 -6
- package/dist/components/layout/toolbar/SearchTool.js +5 -8
- package/dist/components/layout/toolbar/ThumbnailTool.js +3 -4
- package/dist/components/layout/toolbar/ToolbarCustom.js +3 -4
- package/dist/components/layout/toolbar/ToolbarDefault.js +3 -6
- package/dist/components/layout/toolbar/ToolbarLayout.js +3 -6
- package/dist/components/layout/toolbar/ZoomTool.js +3 -4
- package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +3 -4
- package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +7 -9
- package/dist/components/layout/toolbar/tools/FileDownloadTool.js +3 -4
- package/dist/components/layout/toolbar/tools/FileUploadTool.js +3 -4
- package/dist/components/layout/toolbar/tools/FirstPageTool.js +7 -9
- package/dist/components/layout/toolbar/tools/InputPageTool.js +3 -4
- package/dist/components/layout/toolbar/tools/LastPageTool.js +7 -9
- package/dist/components/layout/toolbar/tools/NextPageTool.js +3 -4
- package/dist/components/layout/toolbar/tools/PreviousPageTool.js +3 -4
- package/dist/components/layout/toolbar/tools/PrintTool.js +3 -4
- package/dist/components/layout/toolbar/tools/RotateClockwiseTool.js +3 -4
- package/dist/components/layout/toolbar/tools/RotateCounterclockwiseTool.js +3 -4
- package/dist/components/layout/toolbar/tools/ThumbnailTool.js +3 -4
- package/dist/components/layout/toolbar/tools/ZoomInTool.js +3 -4
- package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +13 -14
- package/dist/components/layout/toolbar/tools/ZoomOutTool.js +3 -4
- package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +3 -6
- package/dist/components/layout/toolbar/tools/defaults/RPVerticalBar.js +3 -4
- package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +3 -4
- package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +3 -4
- package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +3 -4
- package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +3 -4
- package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +3 -4
- package/dist/components/page/AnnotationLayer.js +65 -66
- package/dist/components/page/CanvasLayer.js +3 -4
- package/dist/components/page/CustomElement.js +3 -4
- package/dist/components/page/DualPage.js +5 -11
- package/dist/components/page/DualPageWithCover.js +5 -11
- package/dist/components/page/RPPage.js +6 -12
- package/dist/components/page/SinglePage.js +5 -11
- package/dist/components/page/TextHighlightLayer.js +178 -86
- package/dist/components/page/TextLayer.js +170 -125
- package/dist/components/ui/LoadingIndicator.js +7 -8
- package/dist/contexts/ConfigContext.js +5 -4
- package/dist/contexts/DimensionPagesContext.js +5 -6
- package/dist/contexts/DropFileZoneContext.js +4 -5
- package/dist/contexts/ElementPageContext.js +5 -6
- package/dist/contexts/FileInputContext.js +5 -6
- package/dist/contexts/HighlightContext.js +7 -10
- package/dist/contexts/LayoutDropFileZoneContext.js +11 -0
- package/dist/contexts/LicenseContext.js +8 -6
- package/dist/contexts/PagesRotateContext.js +5 -6
- package/dist/contexts/PaginationContext.js +5 -6
- package/dist/contexts/PrintContext.js +16 -17
- package/dist/contexts/RPDocumentContext.js +13 -14
- package/dist/contexts/RenderQueueProvider.js +5 -6
- package/dist/contexts/RotationContext.js +8 -9
- package/dist/contexts/SearchContext.js +5 -8
- package/dist/contexts/ThumbnailsContext.js +4 -5
- package/dist/contexts/ZoomContext.js +5 -6
- package/dist/main.js +9 -9
- package/dist/types/components/layout/sidebar/Thumbnail.d.ts +2 -2
- package/dist/types/contexts/LayoutDropFileZoneContext.d.ts +9 -0
- package/dist/types/contexts/RPDocumentContext.d.ts +1 -1
- package/dist/types/contexts/RenderQueueProvider.d.ts +1 -1
- package/dist/types/contexts/RenderedPagesCache.d.ts +2 -2
- package/dist/types/main.d.ts +1 -1
- package/dist/types/utils/annotations.d.ts +2 -2
- package/dist/types/utils/getThumbnailViewport.d.ts +2 -2
- package/dist/types/utils/highlight.d.ts +5 -5
- package/dist/types/utils/hooks/useDropFileZone.d.ts +5 -0
- package/dist/types/utils/hooks/useFlickerSelectText.d.ts +1 -0
- package/dist/types/utils/hooks/useHighlight.d.ts +1 -1
- package/dist/types/utils/hooks/useLoadPdf.d.ts +2 -2
- package/dist/types/utils/hooks/useLoadWorker.d.ts +1 -5
- package/dist/types/utils/hooks/usePdfProperties.d.ts +1 -1
- package/dist/types/utils/hooks/useTextSelection.d.ts +3 -12
- package/dist/types/utils/link_service.d.ts +3 -2
- package/dist/types/utils/renderPage.d.ts +2 -2
- package/dist/types/utils/types.d.ts +10 -6
- package/dist/utils/highlight.js +158 -184
- package/dist/utils/hooks/useCopyText.js +22 -60
- package/dist/utils/hooks/useDropFileZone.js +12 -0
- package/dist/utils/hooks/useFileDownload.js +5 -6
- package/dist/utils/hooks/useFlickerSelectText.js +25 -0
- package/dist/utils/hooks/useHighlight.js +33 -35
- package/dist/utils/hooks/useLicense.js +22 -28
- package/dist/utils/hooks/useLoadPdf.js +70 -95
- package/dist/utils/hooks/useLoadWorker.js +14 -4
- package/dist/utils/hooks/usePageRotateContext.js +7 -8
- package/dist/utils/hooks/usePaginate.js +3 -4
- package/dist/utils/hooks/usePinch.js +10 -11
- package/dist/utils/hooks/usePresentPage.js +3 -4
- package/dist/utils/hooks/usePrint.js +55 -54
- package/dist/utils/hooks/useRotate.js +3 -4
- package/dist/utils/hooks/useScrollToPage.js +3 -4
- package/dist/utils/hooks/useSearch.js +15 -18
- package/dist/utils/hooks/useTextSelection.js +73 -2
- package/dist/utils/hooks/useThumbnail.js +17 -18
- package/dist/utils/hooks/useVirtualReactWindow.js +3 -4
- package/dist/utils/hooks/useWatermark.js +8 -6
- package/dist/utils/link_service.js +19 -18
- package/dist/utils/renderPage.js +1 -1
- package/dist/utils/types.js +3 -3
- package/package.json +6 -7
- package/dist/RPLayout.module-7766e0b4.js +0 -14
- package/dist/contexts/TextSelectionContext.js +0 -191
- package/dist/types/contexts/TextSelectionContext.d.ts +0 -14
- package/dist/types/utils/geometryCache.d.ts +0 -15
- package/dist/types/utils/glyphHitTest.d.ts +0 -12
- package/dist/types/utils/selectionUtils.d.ts +0 -30
- package/dist/utils/geometryCache.js +0 -32
- package/dist/utils/glyphHitTest.js +0 -29
- package/dist/utils/selectionUtils.js +0 -96
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { useState as f, useCallback as p, useEffect as w } from "react";
|
|
2
2
|
import { getHighlightOptionsWithDefaults as k, findMatches as P } from "../highlight.js";
|
|
3
3
|
import "../charators.js";
|
|
4
|
-
import "../selectionUtils.js";
|
|
5
|
-
import "../geometryCache.js";
|
|
6
4
|
const x = (n) => {
|
|
7
|
-
const e = Math.min(...n.map((s) => s.left)),
|
|
8
|
-
return { left: e, bottom: o, width:
|
|
5
|
+
const e = Math.min(...n.map((s) => s.left)), c = Math.max(...n.map((s) => s.left + s.width)), o = Math.min(...n.map((s) => s.bottom)), t = Math.max(...n.map((s) => s.height));
|
|
6
|
+
return { left: e, bottom: o, width: c - e, height: t };
|
|
9
7
|
}, N = (n) => n.flatMap((e) => e.rects ?? (e.rect ? [e.rect] : [])), O = (n) => {
|
|
10
8
|
const e = n.reduce((o, t) => {
|
|
11
9
|
const s = Math.round(t.bottom);
|
|
@@ -14,17 +12,17 @@ const x = (n) => {
|
|
|
14
12
|
return Object.entries(e).sort((o, t) => Number(t[0]) - Number(o[0])).map(([o, t]) => x(t));
|
|
15
13
|
}, L = (n) => {
|
|
16
14
|
const e = {};
|
|
17
|
-
for (const
|
|
18
|
-
const o =
|
|
19
|
-
t.push(
|
|
15
|
+
for (const c of n) {
|
|
16
|
+
const o = c.keyword, t = e[o] ?? [];
|
|
17
|
+
t.push(c), e[o] = t;
|
|
20
18
|
}
|
|
21
19
|
return e;
|
|
22
20
|
}, j = (n, e) => {
|
|
23
|
-
const
|
|
21
|
+
const c = n[0], o = N(n), t = o.length > 0 ? O(o) : c.rect ? [c.rect] : [];
|
|
24
22
|
return {
|
|
25
|
-
...
|
|
23
|
+
...c,
|
|
26
24
|
pageMatchIdx: e,
|
|
27
|
-
rect: t[0] ??
|
|
25
|
+
rect: t[0] ?? c.rect,
|
|
28
26
|
rects: t
|
|
29
27
|
};
|
|
30
28
|
}, v = (n) => {
|
|
@@ -33,53 +31,53 @@ const x = (n) => {
|
|
|
33
31
|
const s = e[t.page] ?? [];
|
|
34
32
|
s.push(t), e[t.page] = s;
|
|
35
33
|
}
|
|
36
|
-
let
|
|
34
|
+
let c = 0;
|
|
37
35
|
const o = [];
|
|
38
36
|
for (const t of Object.values(e)) {
|
|
39
37
|
const s = L(t);
|
|
40
38
|
for (const g of Object.values(s))
|
|
41
|
-
o.push(j(g,
|
|
39
|
+
o.push(j(g, c++));
|
|
42
40
|
}
|
|
43
41
|
return o;
|
|
44
|
-
},
|
|
45
|
-
const [e,
|
|
46
|
-
if (!
|
|
42
|
+
}, K = (n) => {
|
|
43
|
+
const [e, c] = f(void 0), [o, t] = f([]), s = p(async (r) => {
|
|
44
|
+
if (!r)
|
|
47
45
|
return {};
|
|
48
|
-
const
|
|
49
|
-
for (let
|
|
50
|
-
const u = await
|
|
51
|
-
|
|
46
|
+
const i = r.numPages, h = {};
|
|
47
|
+
for (let a = 1; a <= i; a++) {
|
|
48
|
+
const u = await r.getPage(a);
|
|
49
|
+
h[a.toString()] = await u.getTextContent();
|
|
52
50
|
}
|
|
53
|
-
return
|
|
54
|
-
}, []), g = p(async (
|
|
55
|
-
r
|
|
51
|
+
return h;
|
|
52
|
+
}, []), g = p(async (r) => {
|
|
53
|
+
c(r);
|
|
56
54
|
}, []), l = p(() => {
|
|
57
|
-
t([]),
|
|
55
|
+
t([]), c(void 0);
|
|
58
56
|
}, []);
|
|
59
57
|
return w(() => {
|
|
60
|
-
n && s(n).then((
|
|
61
|
-
let
|
|
62
|
-
for (const { keyword:
|
|
63
|
-
if (!
|
|
58
|
+
n && s(n).then((r) => {
|
|
59
|
+
let i = [];
|
|
60
|
+
for (const { keyword: h, highlightColor: a, options: u } of e) {
|
|
61
|
+
if (!h)
|
|
64
62
|
continue;
|
|
65
63
|
const b = k(u);
|
|
66
|
-
for (const m of Object.keys(
|
|
64
|
+
for (const m of Object.keys(r)) {
|
|
67
65
|
const d = P(
|
|
68
|
-
[
|
|
69
|
-
|
|
66
|
+
[h],
|
|
67
|
+
r[m],
|
|
70
68
|
Number(m) - 1,
|
|
71
69
|
b
|
|
72
70
|
).map((M, y) => ({
|
|
73
71
|
...M,
|
|
74
72
|
page: Number(m),
|
|
75
73
|
pageMatchIdx: y,
|
|
76
|
-
color:
|
|
77
|
-
keyword:
|
|
74
|
+
color: a,
|
|
75
|
+
keyword: h
|
|
78
76
|
}));
|
|
79
|
-
|
|
77
|
+
i = [...i, ...d];
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
|
-
t(v(
|
|
80
|
+
t(v(i));
|
|
83
81
|
}).catch(() => {
|
|
84
82
|
l();
|
|
85
83
|
});
|
|
@@ -91,5 +89,5 @@ const x = (n) => {
|
|
|
91
89
|
};
|
|
92
90
|
};
|
|
93
91
|
export {
|
|
94
|
-
|
|
92
|
+
K as useHighlight
|
|
95
93
|
};
|
|
@@ -1,35 +1,29 @@
|
|
|
1
|
-
import { useState as E, useCallback as
|
|
1
|
+
import { useState as E, useCallback as v, useEffect as b } from "react";
|
|
2
|
+
import { LicenseType as y } from "../types.js";
|
|
2
3
|
import { appConsole as l } from "../appConsole.js";
|
|
3
|
-
|
|
4
|
+
import "../../de_DE-a553b162.js";
|
|
5
|
+
const A = /* @__PURE__ */ new Date("2026-03-19T04:24:51.186Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", s = {
|
|
4
6
|
invalidLicense: `You are currently using without a valid license. ${d}`,
|
|
5
7
|
mismatchedDomain: `Your license key is not valid for the current domain / IP. ${d}`,
|
|
6
8
|
expired: `Your license key has expired. ${d}`,
|
|
7
9
|
exceededVersion: "Your license does not support the current version of React PDF. The library version you are using exceeds the supported range of your license.",
|
|
8
10
|
invalidSignature: "Invalid license key: Signature mismatch"
|
|
9
11
|
};
|
|
10
|
-
function
|
|
12
|
+
function I(r) {
|
|
11
13
|
const t = r.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s+/g, ""), e = atob(t), n = new Uint8Array(e.length);
|
|
12
14
|
for (let i = 0; i < e.length; i++)
|
|
13
15
|
n[i] = e.charCodeAt(i);
|
|
14
16
|
return n.buffer;
|
|
15
17
|
}
|
|
16
|
-
function
|
|
18
|
+
function L(r) {
|
|
17
19
|
const t = atob(r), e = new Uint8Array(t.length);
|
|
18
20
|
for (let n = 0; n < t.length; n++)
|
|
19
21
|
e[n] = t.charCodeAt(n);
|
|
20
22
|
return e.buffer;
|
|
21
23
|
}
|
|
22
|
-
async function
|
|
24
|
+
async function S(r, t = "SHA-256") {
|
|
23
25
|
try {
|
|
24
|
-
const { data: e, signature: n } = JSON.parse(atob(r)), i =
|
|
25
|
-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIokvErJ0Fctu0jduSAx
|
|
26
|
-
gr+5Har/VSuZLlOunS28hnlqqA+OF1apHL7RYkjBosS15yvviYdLrVWYHpHnoY4b
|
|
27
|
-
HLQ9I6YX6FMB9T/VbB4xLdVdKvfi8r49aTScl5EKuSpgpPgz2VSJTfvVGcRuth/Y
|
|
28
|
-
Bm7PPGYdL2l2gvKDxchmmsHFPukGki9L4JOUeIVX0GXAxabENckaEH/iC1NZhX+W
|
|
29
|
-
vXnpHeHuIIKlZ16LSivXNgo6BH2Z3GFdg4G3cAaXr6qNP8fsacYNqv2SpTW1viFD
|
|
30
|
-
vzcGRabN25gpJAp9/syeScefWH3OiJY1lmw88oTiJbjIoiq6AkPhfn3G9mF54nvR
|
|
31
|
-
kwIDAQAB
|
|
32
|
-
-----END PUBLIC KEY-----`), a = await window.crypto.subtle.importKey(
|
|
26
|
+
const { data: e, signature: n } = JSON.parse(atob(r)), i = I("-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyrIi83Zr5AKaWO6zbZmXqv3McVhtnPOnWCiFgf5xeaglLzEwMiXo3gALaPoBp5Q0WPOSBE9GTqwOyQUgpDNSBuQ0cjOzQdFM3GPnKSqQThZJfjUmD9egMZDmfhcpFGPybUoicoIEFQOdX2vMFUfn6yjRsyvbK6UPTombYl785V8dXNnnIHa4tQC1JSaSe/bhG3e/6kbQCy9VJ23242q9WJpx9c2sZ+bmyI0r9Zx0PfqcDJzDfKn45v96EtxGhV16OZhqkbj4ljiJ/mfqfCkxybkm9nvxz0hAwcEftQaxl/0cZ1RxtsRcL+V3msLsmGcs9nPqAuXecbfg9QVCi/+miwIDAQAB-----END PUBLIC KEY-----"), a = await window.crypto.subtle.importKey(
|
|
33
27
|
"spki",
|
|
34
28
|
// str2ab(publicKeyContent), // Convert PEM string to ArrayBuffer
|
|
35
29
|
i,
|
|
@@ -40,7 +34,7 @@ kwIDAQAB
|
|
|
40
34
|
if (!await window.crypto.subtle.verify(
|
|
41
35
|
{ name: "RSA-PSS", saltLength: 32 },
|
|
42
36
|
a,
|
|
43
|
-
|
|
37
|
+
L(n),
|
|
44
38
|
// Convert signature to ArrayBuffer
|
|
45
39
|
new TextEncoder().encode(atob(e))
|
|
46
40
|
))
|
|
@@ -50,45 +44,45 @@ kwIDAQAB
|
|
|
50
44
|
throw new Error(s.invalidLicense);
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
|
-
const
|
|
47
|
+
const x = (r, t) => r === "specific" ? t === window.location.host : window.location.host.includes(t), u = {
|
|
54
48
|
isValid: !0,
|
|
55
49
|
invalidatedMessage: s.invalidLicense,
|
|
56
50
|
type: void 0
|
|
57
|
-
},
|
|
58
|
-
const [t, e] = E(u), n =
|
|
51
|
+
}, N = (r) => {
|
|
52
|
+
const [t, e] = E(u), n = v(async () => {
|
|
59
53
|
if (e((c) => ({ ...c, validating: !0 })), !r)
|
|
60
54
|
throw e({ ...u, validating: !1 }), new Error(s.invalidLicense);
|
|
61
55
|
let i;
|
|
62
56
|
try {
|
|
63
|
-
i = await
|
|
57
|
+
i = await S(r);
|
|
64
58
|
} catch (c) {
|
|
65
59
|
throw l.warn(c.message), new Error(c.message);
|
|
66
60
|
}
|
|
67
61
|
l.debug(">>> validatedLicense", i);
|
|
68
|
-
const { avu: a, exp: o, dmt:
|
|
62
|
+
const { avu: a, exp: o, dmt: w, dm: p, t: m } = i;
|
|
69
63
|
if (!o)
|
|
70
64
|
throw new Error("License is missing expiration timestamp");
|
|
71
65
|
if (o > Number.MAX_SAFE_INTEGER / 1e3)
|
|
72
66
|
throw new Error("Invalid expiration timestamp: value too large");
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
67
|
+
const g = new Date(o * 1e3), h = (/* @__PURE__ */ new Date()).getTime();
|
|
68
|
+
if (g.getTime() < h)
|
|
75
69
|
throw new Error(s.expired);
|
|
76
70
|
if (!a)
|
|
77
71
|
throw new Error("License is missing available until version timestamp");
|
|
78
72
|
if (a > Number.MAX_SAFE_INTEGER / 1e3)
|
|
79
73
|
throw new Error("Invalid available until version timestamp: value too large");
|
|
80
|
-
const
|
|
81
|
-
if (l.debug("availableUntilTimestamp",
|
|
74
|
+
const f = new Date(a * 1e3);
|
|
75
|
+
if (l.debug("availableUntilTimestamp", f), f.getTime() < A.getTime())
|
|
82
76
|
throw new Error(s.exceededVersion);
|
|
83
|
-
if (!
|
|
77
|
+
if (m !== y.Custom && !x(w, p))
|
|
84
78
|
throw new Error(s.mismatchedDomain);
|
|
85
79
|
return {
|
|
86
80
|
isValid: !0,
|
|
87
|
-
type:
|
|
81
|
+
type: m,
|
|
88
82
|
invalidatedMessage: void 0
|
|
89
83
|
};
|
|
90
84
|
}, [r]);
|
|
91
|
-
return
|
|
85
|
+
return b(() => {
|
|
92
86
|
n().then(({ isValid: i, type: a, invalidatedMessage: o }) => {
|
|
93
87
|
e({
|
|
94
88
|
isValid: i,
|
|
@@ -106,5 +100,5 @@ const y = (r, t) => r === "specific" ? t === window.location.host : window.locat
|
|
|
106
100
|
}, [n]), t;
|
|
107
101
|
};
|
|
108
102
|
export {
|
|
109
|
-
|
|
103
|
+
N as useLicense
|
|
110
104
|
};
|
|
@@ -1,111 +1,86 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { useConfigContext as v } from "../../contexts/ConfigContext.js";
|
|
1
|
+
import { useState as a, useRef as F, useEffect as v } from "react";
|
|
2
|
+
import * as U from "pdfjs-dist";
|
|
3
|
+
import { ErrorType as j } from "../types.js";
|
|
4
|
+
import { getThumbnailViewport as z } from "../getThumbnailViewport.js";
|
|
5
|
+
import { useConfigContext as _ } from "../../contexts/ConfigContext.js";
|
|
7
6
|
import { useDocumentPasswordContext as B } from "../../contexts/DocumentPasswordContext.js";
|
|
8
7
|
import "../../de_DE-a553b162.js";
|
|
9
8
|
import "react/jsx-runtime";
|
|
10
9
|
import "../appConsole.js";
|
|
11
|
-
|
|
12
|
-
const a =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const n = await a.arrayBuffer();
|
|
18
|
-
return c == null || c(100), n;
|
|
19
|
-
}
|
|
20
|
-
const y = a.body.getReader(), p = [];
|
|
21
|
-
let m = 0;
|
|
22
|
-
for (; ; ) {
|
|
23
|
-
const { done: n, value: i } = await y.read();
|
|
24
|
-
if (n)
|
|
25
|
-
break;
|
|
26
|
-
p.push(i), m += i.length, l && (c == null || c(Math.min(100, Math.round(m / l * 100))));
|
|
27
|
-
}
|
|
28
|
-
const w = new Uint8Array(m);
|
|
29
|
-
let s = 0;
|
|
30
|
-
for (const n of p)
|
|
31
|
-
w.set(n, s), s += n.length;
|
|
32
|
-
return w.buffer;
|
|
33
|
-
}
|
|
34
|
-
const re = (t, c, a = {}) => {
|
|
35
|
-
const [o, l] = h(), { workerUrlAdded: y, wasmUrl: p } = v(), [m, w] = h(/* @__PURE__ */ new Map()), s = I(), [n, i] = h(0), [D, _] = h(!1), [T, M] = h(), { password: x, passwordError: V, setPasswordError: b, passwordRequired: E, setPasswordRequired: R } = B(), { onLoadError: A, onLoaded: L, onLoadProgress: S, disableAutoFetch: $, disableStream: z, rangeChunkSize: Q } = a, u = I();
|
|
36
|
-
return P(() => {
|
|
37
|
-
S && S(n);
|
|
38
|
-
}, [n, S]), P(() => {
|
|
39
|
-
if (!y || !t)
|
|
10
|
+
const Z = (m, s, h = {}) => {
|
|
11
|
+
const [n, q] = a(), { workerUrlAdded: S, wasmUrl: f } = _(), [D, T] = a(/* @__PURE__ */ new Map()), d = F(), [g, P] = a(0), [c, x] = a(!1), [N, O] = a(), { password: u, passwordError: A, setPasswordError: p, passwordRequired: w, setPasswordRequired: E } = B(), { onLoadError: i, onLoaded: b, onLoadProgress: R, disableAutoFetch: C, disableStream: V, rangeChunkSize: I } = h;
|
|
12
|
+
return v(() => {
|
|
13
|
+
R && R(g);
|
|
14
|
+
}, [g, R]), v(() => {
|
|
15
|
+
if (!S || !m)
|
|
40
16
|
return;
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
else if (typeof t == "string" || t instanceof URL)
|
|
53
|
-
e = await W(t, (U) => {
|
|
54
|
-
f === s.current && i(U);
|
|
55
|
-
});
|
|
56
|
-
else
|
|
57
|
-
throw new Error("Unsupported PDF source type");
|
|
58
|
-
if (d || f !== s.current || ((!u.current || u.current.isDestroyed) && (u.current = await F({ wasmUrl: p })), d || f !== s.current))
|
|
59
|
-
return;
|
|
60
|
-
const r = u.current.openDocument(e, x || void 0), g = N(r, e);
|
|
61
|
-
f === s.current && (l(g), i(100)), L && L(g), R(!1), b("");
|
|
62
|
-
} catch (e) {
|
|
63
|
-
if (d)
|
|
64
|
-
return;
|
|
65
|
-
const r = e;
|
|
66
|
-
r.code === "PASSWORD_REQUIRED" ? (R(!0), b(r.message || "Password required")) : r.code === "INVALID_PASSWORD" ? (R(!0), b("Incorrect password")) : (M(O.NOT_SUPPORTED), A && A(e));
|
|
67
|
-
} finally {
|
|
68
|
-
d || _(!1);
|
|
69
|
-
}
|
|
70
|
-
})(), () => {
|
|
71
|
-
d = !0;
|
|
17
|
+
P(0), d.current = Date.now();
|
|
18
|
+
const r = d.current, y = {
|
|
19
|
+
url: m,
|
|
20
|
+
cMapPacked: (s == null ? void 0 : s.isCompressed) ?? !0,
|
|
21
|
+
...(s == null ? void 0 : s.url) && { cMapUrl: s.url },
|
|
22
|
+
...u && { password: u },
|
|
23
|
+
...C !== void 0 && { disableAutoFetch: C },
|
|
24
|
+
...V !== void 0 && { disableStream: V },
|
|
25
|
+
...I !== void 0 && { rangeChunkSize: I },
|
|
26
|
+
...f && { wasmUrl: f },
|
|
27
|
+
verbosity: U.VerbosityLevel.ERRORS
|
|
72
28
|
};
|
|
73
|
-
|
|
74
|
-
|
|
29
|
+
try {
|
|
30
|
+
const e = U.getDocument(y);
|
|
31
|
+
e.onProgress = (o) => {
|
|
32
|
+
if (r === d.current) {
|
|
33
|
+
const { loaded: L, total: l } = o, k = l ? Math.min(100, Math.round(L / l * 100)) : 0;
|
|
34
|
+
P(k);
|
|
35
|
+
}
|
|
36
|
+
}, x(!0);
|
|
37
|
+
const t = e.promise.then((o) => (r === d.current && (q(o), P(100)), b && b(o), E(!1), p(""), o)).catch((o) => {
|
|
38
|
+
o instanceof Error && o.name === "PasswordException" ? (E(!0), p(o.message || "Password required")) : o instanceof Error && o.name === "InvalidPDFException" && u ? (E(!0), p("Incorrect password")) : i && i(o);
|
|
39
|
+
}).finally(() => {
|
|
40
|
+
x(!1);
|
|
41
|
+
});
|
|
42
|
+
return () => {
|
|
43
|
+
t.finally(() => {
|
|
44
|
+
e.destroy();
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
} catch (e) {
|
|
48
|
+
O(j.NOT_SUPPORTED), i && i(e);
|
|
49
|
+
}
|
|
50
|
+
}, [m, S, f, u, i, b]), v(() => {
|
|
51
|
+
if (w)
|
|
75
52
|
return;
|
|
76
|
-
const
|
|
77
|
-
if (!
|
|
78
|
-
|
|
53
|
+
const r = /* @__PURE__ */ new Map();
|
|
54
|
+
if (!n || c) {
|
|
55
|
+
T(r);
|
|
79
56
|
return;
|
|
80
57
|
}
|
|
81
|
-
const
|
|
82
|
-
for (let
|
|
83
|
-
const
|
|
84
|
-
|
|
58
|
+
const y = n.numPages, e = [];
|
|
59
|
+
for (let t = 1; t <= y; t++) {
|
|
60
|
+
const o = n.getPage(t);
|
|
61
|
+
e.push(o);
|
|
85
62
|
}
|
|
86
|
-
Promise.all(
|
|
87
|
-
|
|
88
|
-
const { thumbnailViewport:
|
|
89
|
-
|
|
90
|
-
page:
|
|
91
|
-
thumbnailViewport:
|
|
92
|
-
thumbnailScale:
|
|
93
|
-
defaultRotation:
|
|
63
|
+
Promise.all(e).then((t) => {
|
|
64
|
+
t.map((o) => {
|
|
65
|
+
const { thumbnailViewport: L, scale: l } = z(o), k = o.getViewport();
|
|
66
|
+
r.set(o.pageNumber, {
|
|
67
|
+
page: o,
|
|
68
|
+
thumbnailViewport: L,
|
|
69
|
+
thumbnailScale: l,
|
|
70
|
+
defaultRotation: k.rotation
|
|
94
71
|
});
|
|
95
|
-
}),
|
|
72
|
+
}), T(r);
|
|
96
73
|
});
|
|
97
|
-
}, [
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
passwordRequired: E,
|
|
106
|
-
passwordError: V
|
|
74
|
+
}, [n, c, w]), {
|
|
75
|
+
pdf: n,
|
|
76
|
+
pages: D,
|
|
77
|
+
loading: c,
|
|
78
|
+
error: N,
|
|
79
|
+
loadingProgress: g,
|
|
80
|
+
passwordRequired: w,
|
|
81
|
+
passwordError: A
|
|
107
82
|
};
|
|
108
83
|
};
|
|
109
84
|
export {
|
|
110
|
-
|
|
85
|
+
Z as useLoadPdf
|
|
111
86
|
};
|