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