@react-pdf-kit/viewer 0.0.0-legacy.0 → 0.0.0-legacy.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,6 @@
|
|
|
1
1
|
import { useState as E, useCallback as h, useEffect as A } from "react";
|
|
2
2
|
import { appConsole as l } from "../appConsole.js";
|
|
3
|
-
const b = /* @__PURE__ */ new Date("2026-
|
|
3
|
+
const b = /* @__PURE__ */ new Date("2026-05-06T16:14:18.520Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", s = {
|
|
4
4
|
invalidLicense: `You are currently using without a valid license. ${d}`,
|
|
5
5
|
mismatchedDomain: `Your license key is not valid for the current domain / IP. ${d}`,
|
|
6
6
|
expired: `Your license key has expired. ${d}`,
|
|
@@ -1,85 +1,95 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import * as
|
|
3
|
-
import { ErrorType as
|
|
4
|
-
import { getThumbnailViewport as
|
|
5
|
-
import { useConfigContext as
|
|
6
|
-
import { useDocumentPasswordContext as
|
|
1
|
+
import { useState as u, useRef as O, useEffect as h } from "react";
|
|
2
|
+
import * as C from "pdfjs-dist";
|
|
3
|
+
import { ErrorType as $ } from "../types.js";
|
|
4
|
+
import { getThumbnailViewport as A } from "../getThumbnailViewport.js";
|
|
5
|
+
import { useConfigContext as j } from "../../contexts/ConfigContext.js";
|
|
6
|
+
import { useDocumentPasswordContext as z } from "../../contexts/DocumentPasswordContext.js";
|
|
7
7
|
import "../../de_DE-a553b162.js";
|
|
8
8
|
import "react/jsx-runtime";
|
|
9
9
|
import "../appConsole.js";
|
|
10
|
-
const
|
|
11
|
-
const [
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
}, [
|
|
15
|
-
if (!
|
|
10
|
+
const X = (g, t, V = {}) => {
|
|
11
|
+
const [r, D] = u(), { workerUrlAdded: S } = j(), [I, q] = u(/* @__PURE__ */ new Map()), d = O(), [p, L] = u(0), [f, x] = u(!1), [U, F] = u(), { password: a, passwordError: N, setPasswordError: w, passwordRequired: k, setPasswordRequired: E } = z(), { onLoadError: i, onLoaded: b, onLoadProgress: v, disableAutoFetch: y, disableStream: R, rangeChunkSize: T } = V;
|
|
12
|
+
return h(() => {
|
|
13
|
+
v && v(p);
|
|
14
|
+
}, [p, v]), h(() => {
|
|
15
|
+
if (!S) {
|
|
16
|
+
console.log("useLoadPdf: skipping — worker URL not yet added");
|
|
16
17
|
return;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
}
|
|
19
|
+
if (!g) {
|
|
20
|
+
console.log("useLoadPdf: skipping — no src provided");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
console.log("useLoadPdf: starting load", { src: g, password: !!a, disableAutoFetch: y, disableStream: R, rangeChunkSize: T }), L(0), d.current = Date.now();
|
|
24
|
+
const s = d.current, c = {
|
|
25
|
+
url: g,
|
|
26
|
+
cMapPacked: (t == null ? void 0 : t.isCompressed) ?? !0,
|
|
27
|
+
...(t == null ? void 0 : t.url) && { cMapUrl: t.url },
|
|
28
|
+
...a && { password: a },
|
|
29
|
+
...y !== void 0 && { disableAutoFetch: y },
|
|
30
|
+
...R !== void 0 && { disableStream: R },
|
|
31
|
+
...T !== void 0 && { rangeChunkSize: T },
|
|
32
|
+
verbosity: C.VerbosityLevel.ERRORS
|
|
27
33
|
};
|
|
28
34
|
try {
|
|
29
|
-
const e =
|
|
35
|
+
const e = C.getDocument(c);
|
|
30
36
|
e.onProgress = (o) => {
|
|
31
|
-
if (
|
|
32
|
-
const { loaded:
|
|
33
|
-
|
|
37
|
+
if (s === d.current) {
|
|
38
|
+
const { loaded: P, total: l } = o, m = l ? Math.min(100, Math.round(P / l * 100)) : 0;
|
|
39
|
+
console.log(`useLoadPdf: progress ${m}% (${P}/${l})`), L(m);
|
|
34
40
|
}
|
|
35
|
-
},
|
|
36
|
-
const
|
|
37
|
-
o instanceof Error && o.name === "PasswordException" ? (
|
|
41
|
+
}, x(!0);
|
|
42
|
+
const n = e.promise.then((o) => (s === d.current ? (console.log("useLoadPdf: document loaded", { numPages: o.numPages, taskId: s }), D(o), L(100)) : console.log("useLoadPdf: stale task resolved, ignoring", { taskId: s, latestTask: d.current }), b && b(o), E(!1), w(""), o)).catch((o) => {
|
|
43
|
+
o instanceof Error && o.name === "PasswordException" ? (console.log("useLoadPdf: password required", o.message), E(!0), w(o.message || "Password required")) : o instanceof Error && o.name === "InvalidPDFException" && a ? (console.log("useLoadPdf: invalid PDF / incorrect password", o.message), E(!0), w("Incorrect password")) : (console.log("useLoadPdf: load error", o), i && i(o));
|
|
38
44
|
}).finally(() => {
|
|
39
|
-
|
|
45
|
+
console.log("useLoadPdf: loading finished, setting loading=false"), x(!1);
|
|
40
46
|
});
|
|
41
47
|
return () => {
|
|
42
|
-
|
|
48
|
+
n.finally(() => {
|
|
43
49
|
e.destroy();
|
|
44
50
|
});
|
|
45
51
|
};
|
|
46
52
|
} catch (e) {
|
|
47
|
-
|
|
53
|
+
console.log("useLoadPdf: synchronous error in getDocument", e), F($.NOT_SUPPORTED), i && i(e);
|
|
48
54
|
}
|
|
49
|
-
}, [
|
|
50
|
-
if (
|
|
55
|
+
}, [g, S, a, i, b]), h(() => {
|
|
56
|
+
if (k) {
|
|
57
|
+
console.log("useLoadPdf: skipping page load — password required");
|
|
51
58
|
return;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
}
|
|
60
|
+
const s = /* @__PURE__ */ new Map();
|
|
61
|
+
if (!r || f) {
|
|
62
|
+
console.log("useLoadPdf: skipping page load", { pdf: !!r, loading: f }), q(s);
|
|
55
63
|
return;
|
|
56
64
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
65
|
+
const c = r.numPages;
|
|
66
|
+
console.log("useLoadPdf: loading pages", { totalPage: c });
|
|
67
|
+
const e = [];
|
|
68
|
+
for (let n = 1; n <= c; n++) {
|
|
69
|
+
const o = r.getPage(n);
|
|
60
70
|
e.push(o);
|
|
61
71
|
}
|
|
62
|
-
Promise.all(e).then((
|
|
63
|
-
|
|
64
|
-
const { thumbnailViewport:
|
|
65
|
-
|
|
72
|
+
Promise.all(e).then((n) => {
|
|
73
|
+
console.log("useLoadPdf: all pages loaded", { count: n.length }), n.map((o) => {
|
|
74
|
+
const { thumbnailViewport: P, scale: l } = A(o), m = o.getViewport();
|
|
75
|
+
s.set(o.pageNumber, {
|
|
66
76
|
page: o,
|
|
67
|
-
thumbnailViewport:
|
|
77
|
+
thumbnailViewport: P,
|
|
68
78
|
thumbnailScale: l,
|
|
69
|
-
defaultRotation:
|
|
79
|
+
defaultRotation: m.rotation
|
|
70
80
|
});
|
|
71
|
-
}),
|
|
81
|
+
}), q(s);
|
|
72
82
|
});
|
|
73
|
-
}, [
|
|
74
|
-
pdf:
|
|
75
|
-
pages:
|
|
76
|
-
loading:
|
|
77
|
-
error:
|
|
78
|
-
loadingProgress:
|
|
79
|
-
passwordRequired:
|
|
80
|
-
passwordError:
|
|
83
|
+
}, [r, f, k]), {
|
|
84
|
+
pdf: r,
|
|
85
|
+
pages: I,
|
|
86
|
+
loading: f,
|
|
87
|
+
error: U,
|
|
88
|
+
loadingProgress: p,
|
|
89
|
+
passwordRequired: k,
|
|
90
|
+
passwordError: N
|
|
81
91
|
};
|
|
82
92
|
};
|
|
83
93
|
export {
|
|
84
|
-
|
|
94
|
+
X as useLoadPdf
|
|
85
95
|
};
|
package/package.json
CHANGED