@react-pdf-kit/viewer 2.7.4-rc.0 → 2.7.4-rc.1
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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { NormalizedKeyword } from './types';
|
|
2
2
|
export declare const EMPTY_KEYWORD_REGEXP: NormalizedKeyword;
|
|
3
|
+
export declare const DOCS_URL = "https://www.react-pdf-kit.dev/docs";
|
|
3
4
|
export declare const ORGANIZATION_ALLOWED_FEATURES_MESSAGE = "This feature is only available for the Organization license";
|
|
4
5
|
export declare const INVALID_OR_CORRUPTED_PDF_MESSAGE = "Invalid or corrupted PDF file.";
|
|
5
6
|
export declare const BROWSER_NOT_SUPPORTED_MESSAGE = "React PDF Kit is unable to render on this browser.";
|
|
6
7
|
export declare const WASM_URL_REQUIRED_MESSAGE = "This PDF uses JPEG 2000 images and requires pdf.js WASM assets. Please set wasmUrl in RPConfig.";
|
|
8
|
+
export declare const WASM_URL_REQUIRED_CONSOLE_MESSAGE = "This PDF uses JPEG 2000 images and requires pdf.js WASM assets. Please set wasmUrl in RPConfig. Learn more: https://www.react-pdf-kit.dev/docs/components/rp-config";
|
package/dist/utils/const.js
CHANGED
|
@@ -3,6 +3,6 @@ var e = {
|
|
|
3
3
|
keyword: "",
|
|
4
4
|
regExp: /* @__PURE__ */ RegExp(" "),
|
|
5
5
|
wholeWords: !1
|
|
6
|
-
}, t = "This feature is only available for the Organization license",
|
|
6
|
+
}, t = "https://www.react-pdf-kit.dev/docs", n = "This feature is only available for the Organization license", r = "Invalid or corrupted PDF file.", i = "React PDF Kit is unable to render on this browser.", a = "This PDF uses JPEG 2000 images and requires pdf.js WASM assets. Please set wasmUrl in RPConfig.", o = `${a} Learn more: ${t}/components/rp-config`;
|
|
7
7
|
//#endregion
|
|
8
|
-
export {
|
|
8
|
+
export { i as BROWSER_NOT_SUPPORTED_MESSAGE, t as DOCS_URL, e as EMPTY_KEYWORD_REGEXP, r as INVALID_OR_CORRUPTED_PDF_MESSAGE, n as ORGANIZATION_ALLOWED_FEATURES_MESSAGE, o as WASM_URL_REQUIRED_CONSOLE_MESSAGE, a as WASM_URL_REQUIRED_MESSAGE };
|
|
@@ -3,7 +3,7 @@ import { LicenseType as t } from "../types.js";
|
|
|
3
3
|
import { appConsole as n } from "../appConsole.js";
|
|
4
4
|
import { useCallback as r, useEffect as i, useState as a } from "react";
|
|
5
5
|
//#region lib/utils/hooks/useLicense.ts
|
|
6
|
-
var o = /* @__PURE__ */ new Date("2026-07-
|
|
6
|
+
var o = /* @__PURE__ */ new Date("2026-07-22T07:13:36.943Z"), s = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIokvErJ0Fctu0jduSAx\ngr+5Har/VSuZLlOunS28hnlqqA+OF1apHL7RYkjBosS15yvviYdLrVWYHpHnoY4b\nHLQ9I6YX6FMB9T/VbB4xLdVdKvfi8r49aTScl5EKuSpgpPgz2VSJTfvVGcRuth/Y\nBm7PPGYdL2l2gvKDxchmmsHFPukGki9L4JOUeIVX0GXAxabENckaEH/iC1NZhX+W\nvXnpHeHuIIKlZ16LSivXNgo6BH2Z3GFdg4G3cAaXr6qNP8fsacYNqv2SpTW1viFD\nvzcGRabN25gpJAp9/syeScefWH3OiJY1lmw88oTiJbjIoiq6AkPhfn3G9mF54nvR\nkwIDAQAB\n-----END PUBLIC KEY-----", c = "Please visit https://app.react-pdf-kit.dev to generate a new license key.", l = {
|
|
7
7
|
invalidLicense: `You are currently using without a valid license. ${c}`,
|
|
8
8
|
mismatchedDomain: `Your license key is not valid for the current domain / IP. ${c}`,
|
|
9
9
|
expired: `Your license key has expired. ${c}`,
|
|
@@ -2,87 +2,88 @@
|
|
|
2
2
|
import { ErrorType as e } from "../types.js";
|
|
3
3
|
import { getThumbnailViewport as t } from "../getThumbnailViewport.js";
|
|
4
4
|
import { useConfigContext as n } from "../../contexts/ConfigContext.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
5
|
+
import { appConsole as r } from "../appConsole.js";
|
|
6
|
+
import { useDocumentPasswordContext as i } from "../../contexts/DocumentPasswordContext.js";
|
|
7
|
+
import { BROWSER_NOT_SUPPORTED_MESSAGE as a, INVALID_OR_CORRUPTED_PDF_MESSAGE as o, WASM_URL_REQUIRED_CONSOLE_MESSAGE as s, WASM_URL_REQUIRED_MESSAGE as c } from "../const.js";
|
|
8
|
+
import { useEffect as l, useRef as u, useState as d } from "react";
|
|
9
|
+
import * as f from "pdfjs-dist";
|
|
9
10
|
//#region lib/utils/hooks/useLoadPdf.ts
|
|
10
|
-
var
|
|
11
|
-
function
|
|
12
|
-
return e.some((t, n) => t ===
|
|
11
|
+
var p = new TextEncoder().encode("/JPXDecode");
|
|
12
|
+
function m(e) {
|
|
13
|
+
return e.some((t, n) => t === p[0] ? p.every((t, r) => e[n + r] === t) : !1);
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
let t = Error(
|
|
15
|
+
function h(e) {
|
|
16
|
+
let t = Error(o);
|
|
16
17
|
return t.cause = e, t;
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
-
return Error(
|
|
19
|
+
function g() {
|
|
20
|
+
return Error(c);
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
-
let t = Error(
|
|
22
|
+
function _(e) {
|
|
23
|
+
let t = Error(a);
|
|
23
24
|
return t.cause = e, t;
|
|
24
25
|
}
|
|
25
|
-
var
|
|
26
|
-
let [
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
}, [
|
|
30
|
-
if (!
|
|
31
|
-
|
|
32
|
-
let t =
|
|
33
|
-
url:
|
|
34
|
-
cMapPacked:
|
|
35
|
-
...
|
|
36
|
-
...
|
|
37
|
-
...
|
|
38
|
-
...
|
|
39
|
-
...
|
|
40
|
-
...
|
|
41
|
-
...
|
|
42
|
-
...
|
|
43
|
-
verbosity:
|
|
26
|
+
var v = (a, o, c = {}) => {
|
|
27
|
+
let [p, v] = d(), { workerUrlAdded: y, wasmUrl: b } = n(), [x, S] = d(/* @__PURE__ */ new Map()), C = u(), [w, T] = d(0), [E, D] = d(!1), [O, k] = d(), { password: A, passwordError: j, setPasswordError: M, passwordRequired: N, setPasswordRequired: P } = i(), { onLoadError: F, onLoaded: I, onLoadProgress: L, disableAutoFetch: R, disableStream: z, rangeChunkSize: B, withCredentials: V, httpHeaders: H } = c;
|
|
28
|
+
return l(() => {
|
|
29
|
+
L && L(w);
|
|
30
|
+
}, [w, L]), l(() => {
|
|
31
|
+
if (!y || !a) return;
|
|
32
|
+
T(0), k(void 0), C.current = Date.now();
|
|
33
|
+
let t = C.current, n = {
|
|
34
|
+
url: a,
|
|
35
|
+
cMapPacked: o?.isCompressed ?? !0,
|
|
36
|
+
...o?.url && { cMapUrl: o.url },
|
|
37
|
+
...A && { password: A },
|
|
38
|
+
...R !== void 0 && { disableAutoFetch: R },
|
|
39
|
+
...z !== void 0 && { disableStream: z },
|
|
40
|
+
...B !== void 0 && { rangeChunkSize: B },
|
|
41
|
+
...V !== void 0 && { withCredentials: V },
|
|
42
|
+
...H !== void 0 && { httpHeaders: H },
|
|
43
|
+
...b && { wasmUrl: b },
|
|
44
|
+
verbosity: f.VerbosityLevel.ERRORS
|
|
44
45
|
};
|
|
45
46
|
try {
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
if (t ===
|
|
47
|
+
let i = f.getDocument(n);
|
|
48
|
+
i.onProgress = (e) => {
|
|
49
|
+
if (t === C.current) {
|
|
49
50
|
let { loaded: t, total: n } = e;
|
|
50
|
-
|
|
51
|
+
T(n ? Math.min(100, Math.round(t / n * 100)) : 0);
|
|
51
52
|
}
|
|
52
|
-
},
|
|
53
|
-
let
|
|
53
|
+
}, D(!0), v(void 0);
|
|
54
|
+
let a = i.promise.then(async (n) => !b && m(await n.getData()) ? (t === C.current && (v(void 0), k(e.WASM_URL_REQUIRED)), r.error(s), F?.(g()), n) : (t === C.current && (v(n), T(100)), I && I(n), P(!1), M(""), n)).catch((t) => {
|
|
54
55
|
if (t instanceof Error && t.name === "PasswordException") {
|
|
55
56
|
let e = t.code;
|
|
56
|
-
|
|
57
|
-
} else t instanceof Error && t.name === "InvalidPDFException" &&
|
|
57
|
+
P(!0), e === f.PasswordResponses.INCORRECT_PASSWORD ? M("Incorrect password") : M(void 0);
|
|
58
|
+
} else t instanceof Error && t.name === "InvalidPDFException" && A ? (P(!0), M("Incorrect password")) : t instanceof Error && t.name === "InvalidPDFException" ? (k(e.INVALID_OR_CORRUPTED_PDF), F?.(h(t))) : F && F(t);
|
|
58
59
|
}).finally(() => {
|
|
59
|
-
|
|
60
|
+
D(!1);
|
|
60
61
|
});
|
|
61
62
|
return () => {
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
a.finally(() => {
|
|
64
|
+
i.destroy();
|
|
64
65
|
});
|
|
65
66
|
};
|
|
66
67
|
} catch (t) {
|
|
67
|
-
|
|
68
|
+
k(e.NOT_SUPPORTED), F?.(_(t));
|
|
68
69
|
}
|
|
69
70
|
}, [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
]),
|
|
77
|
-
if (
|
|
71
|
+
a,
|
|
72
|
+
y,
|
|
73
|
+
b,
|
|
74
|
+
A,
|
|
75
|
+
F,
|
|
76
|
+
I
|
|
77
|
+
]), l(() => {
|
|
78
|
+
if (N) return;
|
|
78
79
|
let n = /* @__PURE__ */ new Map();
|
|
79
|
-
if (!
|
|
80
|
-
|
|
80
|
+
if (!p || E) {
|
|
81
|
+
S(n);
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
83
|
-
let r =
|
|
84
|
+
let r = p.numPages, i = [];
|
|
84
85
|
for (let e = 1; e <= r; e++) {
|
|
85
|
-
let t =
|
|
86
|
+
let t = p.getPage(e);
|
|
86
87
|
i.push(t);
|
|
87
88
|
}
|
|
88
89
|
Promise.allSettled(i).then((e) => {
|
|
@@ -96,24 +97,24 @@ var g = (i, a, o = {}) => {
|
|
|
96
97
|
thumbnailScale: i,
|
|
97
98
|
defaultRotation: a.rotation
|
|
98
99
|
});
|
|
99
|
-
}),
|
|
100
|
+
}), S(n);
|
|
100
101
|
}).catch((t) => {
|
|
101
|
-
|
|
102
|
+
v(void 0), k(e.INVALID_OR_CORRUPTED_PDF), F?.(h(t));
|
|
102
103
|
});
|
|
103
104
|
}, [
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
p,
|
|
106
|
+
E,
|
|
107
|
+
N,
|
|
108
|
+
F
|
|
108
109
|
]), {
|
|
109
|
-
pdf:
|
|
110
|
-
pages:
|
|
111
|
-
loading:
|
|
112
|
-
error:
|
|
113
|
-
loadingProgress:
|
|
114
|
-
passwordRequired:
|
|
115
|
-
passwordError:
|
|
110
|
+
pdf: p,
|
|
111
|
+
pages: x,
|
|
112
|
+
loading: E,
|
|
113
|
+
error: O,
|
|
114
|
+
loadingProgress: w,
|
|
115
|
+
passwordRequired: N,
|
|
116
|
+
passwordError: j
|
|
116
117
|
};
|
|
117
118
|
};
|
|
118
119
|
//#endregion
|
|
119
|
-
export {
|
|
120
|
+
export { v as useLoadPdf };
|