@react-pdf-kit/viewer 0.0.0-experimental.0 → 0.0.0-experimental.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-02-
|
|
3
|
+
const b = /* @__PURE__ */ new Date("2026-02-24T03:31:41.685Z"), 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,6 +1,6 @@
|
|
|
1
|
-
import { useState as g, useRef as
|
|
2
|
-
import { useDocumentContext as
|
|
3
|
-
import { PixelsPerInch as
|
|
1
|
+
import { useState as g, useRef as k, useEffect as D, useCallback as P } from "react";
|
|
2
|
+
import { useDocumentContext as q } from "../../contexts/RPDocumentContext.js";
|
|
3
|
+
import { PixelsPerInch as O, AnnotationMode as U, RenderingCancelledException as V } from "pdfjs-dist";
|
|
4
4
|
import "react/jsx-runtime";
|
|
5
5
|
import "./useLoadPdf.js";
|
|
6
6
|
import "../types.js";
|
|
@@ -13,49 +13,49 @@ import "./usePdfProperties.js";
|
|
|
13
13
|
import "../convertPdfDate.js";
|
|
14
14
|
import "../formatFileSize.js";
|
|
15
15
|
const re = () => {
|
|
16
|
-
const { pdf: l, pages: f } =
|
|
16
|
+
const { pdf: l, pages: f } = q(), [R, E] = g({
|
|
17
17
|
loadedPages: 0,
|
|
18
18
|
totalPages: 0,
|
|
19
19
|
percentage: 0
|
|
20
|
-
}), [T,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}, [
|
|
24
|
-
const
|
|
20
|
+
}), [T, y] = g(!1), [A, b] = g(!1), [Z, C] = g(null), [M, h] = g(void 0), i = k(!1);
|
|
21
|
+
D(() => {
|
|
22
|
+
i.current;
|
|
23
|
+
}, [i]);
|
|
24
|
+
const S = P(() => {
|
|
25
25
|
document.documentElement.classList.remove("rp-print-html-printing"), document.body.classList.remove("rp-print-body-printing");
|
|
26
26
|
const e = document.querySelector(".rp-print-zone");
|
|
27
27
|
e && e.remove();
|
|
28
|
-
}, []),
|
|
29
|
-
|
|
28
|
+
}, []), s = P(() => {
|
|
29
|
+
i.current = !1, y(!1), b(!1), C(null), h(void 0), E({
|
|
30
30
|
loadedPages: 0,
|
|
31
31
|
totalPages: 0,
|
|
32
32
|
percentage: 0
|
|
33
33
|
});
|
|
34
|
-
}, []),
|
|
35
|
-
|
|
34
|
+
}, []), F = () => {
|
|
35
|
+
i.current = !0;
|
|
36
36
|
}, I = async ({
|
|
37
37
|
scratchCanvas: e,
|
|
38
38
|
pdfDocument: n,
|
|
39
39
|
pageNumber: t,
|
|
40
40
|
viewerPdfPage: o,
|
|
41
41
|
printResolution: r,
|
|
42
|
-
optionalContentConfigPromise:
|
|
42
|
+
optionalContentConfigPromise: a,
|
|
43
43
|
printAnnotationStoragePromise: u
|
|
44
44
|
}) => {
|
|
45
|
-
if (
|
|
46
|
-
|
|
45
|
+
if (i.current) {
|
|
46
|
+
s();
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
const c = r /
|
|
49
|
+
const c = r / O.PDF;
|
|
50
50
|
e.width = Math.floor(o.width * c), e.height = Math.floor(o.height * c);
|
|
51
51
|
const p = e.getContext("2d");
|
|
52
52
|
p.save(), p.fillStyle = "rgb(255, 255, 255)", p.fillRect(0, 0, e.width, e.height), p.restore();
|
|
53
|
-
const [m,
|
|
53
|
+
const [m, w] = await Promise.all([
|
|
54
54
|
n.getPage(t),
|
|
55
55
|
u
|
|
56
56
|
]);
|
|
57
|
-
if (
|
|
58
|
-
|
|
57
|
+
if (i.current) {
|
|
58
|
+
s();
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
const v = {
|
|
@@ -64,21 +64,21 @@ const re = () => {
|
|
|
64
64
|
transform: [c, 0, 0, c, 0, 0],
|
|
65
65
|
viewport: m.getViewport({ scale: 1, rotation: o.rotation }),
|
|
66
66
|
intent: "print",
|
|
67
|
-
annotationMode:
|
|
68
|
-
optionalContentConfigPromise:
|
|
69
|
-
printAnnotationStorage:
|
|
67
|
+
annotationMode: U.ENABLE_STORAGE,
|
|
68
|
+
optionalContentConfigPromise: a,
|
|
69
|
+
printAnnotationStorage: w
|
|
70
70
|
};
|
|
71
71
|
try {
|
|
72
72
|
return m.render(v).promise;
|
|
73
73
|
} catch (d) {
|
|
74
|
-
throw d instanceof
|
|
74
|
+
throw d instanceof V || console.error(d), d;
|
|
75
75
|
}
|
|
76
|
-
},
|
|
76
|
+
}, L = P(() => {
|
|
77
77
|
const e = window.print;
|
|
78
78
|
return new Promise((n) => {
|
|
79
|
-
const t = (
|
|
79
|
+
const t = (a) => {
|
|
80
80
|
setTimeout(() => {
|
|
81
|
-
e.call(window), setTimeout(() =>
|
|
81
|
+
e.call(window), setTimeout(() => a(), 20);
|
|
82
82
|
}, 0);
|
|
83
83
|
};
|
|
84
84
|
if (document.querySelector(".rp-print-zone")) {
|
|
@@ -90,94 +90,87 @@ const re = () => {
|
|
|
90
90
|
});
|
|
91
91
|
r.observe(document.body, { childList: !0, subtree: !0 });
|
|
92
92
|
});
|
|
93
|
-
}, []),
|
|
93
|
+
}, []), z = (e) => {
|
|
94
94
|
const n = document.createElement("img"), t = document.createElement("div");
|
|
95
|
-
return t.classList.add("rp-print-page"),
|
|
96
|
-
e.toBlob((i) => {
|
|
97
|
-
i ? (n.src = URL.createObjectURL(i), n.onload = () => {
|
|
98
|
-
URL.revokeObjectURL(n.src), o();
|
|
99
|
-
}, n.onerror = r) : r(new Error("Failed to create blob"));
|
|
100
|
-
});
|
|
101
|
-
}).catch(() => {
|
|
102
|
-
}), t.appendChild(n), t;
|
|
95
|
+
return t.classList.add("rp-print-page"), n.src = e.toDataURL(), t.appendChild(n), t;
|
|
103
96
|
}, x = (e, n) => {
|
|
104
97
|
const t = document.createElement("div");
|
|
105
98
|
t.classList.add("rp-print-zone");
|
|
106
99
|
const o = document.createElement("style"), r = n.get(1);
|
|
107
100
|
if (r) {
|
|
108
|
-
const { width:
|
|
109
|
-
o.innerHTML = `@page { size: ${
|
|
101
|
+
const { width: a, height: u } = r == null ? void 0 : r.page.getViewport({ scale: 1 });
|
|
102
|
+
o.innerHTML = `@page { size: ${a}px ${u}px }`;
|
|
110
103
|
}
|
|
111
104
|
return t.appendChild(o), t.append(...e), t;
|
|
112
|
-
},
|
|
105
|
+
}, N = P(
|
|
113
106
|
async (e) => {
|
|
114
107
|
if (!l)
|
|
115
108
|
return;
|
|
116
|
-
|
|
109
|
+
s();
|
|
117
110
|
const n = e && "visibleDefaultProgress" in e ? e : void 0;
|
|
118
|
-
(n == null ? void 0 : n.visibleDefaultProgress) !== void 0 ?
|
|
111
|
+
(n == null ? void 0 : n.visibleDefaultProgress) !== void 0 ? h(n.visibleDefaultProgress) : h(!0);
|
|
119
112
|
const t = document.createElement("canvas"), o = [];
|
|
120
113
|
try {
|
|
121
114
|
l.isPureXfa && console.warn("[rp] XFA Form is not supported at the moment.");
|
|
122
|
-
const
|
|
115
|
+
const a = l.getOptionalContentConfig({ intent: "print" }), u = Promise.resolve(
|
|
123
116
|
l.annotationStorage.print ?? void 0
|
|
124
117
|
), c = f.size;
|
|
125
|
-
for (const [m,
|
|
126
|
-
if (
|
|
127
|
-
|
|
118
|
+
for (const [m, w] of f) {
|
|
119
|
+
if (i.current) {
|
|
120
|
+
s();
|
|
128
121
|
return;
|
|
129
122
|
}
|
|
130
|
-
const v =
|
|
123
|
+
const v = w.page.getViewport({ scale: 1 });
|
|
131
124
|
if (await I({
|
|
132
125
|
scratchCanvas: t,
|
|
133
126
|
pdfDocument: l,
|
|
134
127
|
pageNumber: m,
|
|
135
128
|
viewerPdfPage: v,
|
|
136
129
|
printResolution: 150,
|
|
137
|
-
optionalContentConfigPromise:
|
|
130
|
+
optionalContentConfigPromise: a,
|
|
138
131
|
printAnnotationStoragePromise: u
|
|
139
|
-
}),
|
|
140
|
-
|
|
132
|
+
}), i.current) {
|
|
133
|
+
s();
|
|
141
134
|
return;
|
|
142
135
|
}
|
|
143
|
-
const d =
|
|
136
|
+
const d = z(t);
|
|
144
137
|
o.push(d);
|
|
145
|
-
const
|
|
138
|
+
const X = parseFloat((o.length / c * 100).toFixed(2));
|
|
146
139
|
E({
|
|
147
140
|
loadedPages: m,
|
|
148
141
|
totalPages: c,
|
|
149
|
-
percentage:
|
|
142
|
+
percentage: X
|
|
150
143
|
});
|
|
151
144
|
}
|
|
152
|
-
if (
|
|
153
|
-
|
|
145
|
+
if (i.current) {
|
|
146
|
+
s();
|
|
154
147
|
return;
|
|
155
148
|
}
|
|
156
149
|
const p = x(o, f);
|
|
157
|
-
document.body.appendChild(p), document.documentElement.classList.add("rp-print-html-printing"), document.body.classList.add("rp-print-body-printing"),
|
|
150
|
+
document.body.appendChild(p), document.documentElement.classList.add("rp-print-html-printing"), document.body.classList.add("rp-print-body-printing"), y(!0), await L();
|
|
158
151
|
} catch (r) {
|
|
159
|
-
|
|
152
|
+
b(!0), r instanceof Error && C(r);
|
|
160
153
|
} finally {
|
|
161
154
|
t.height = 0, t.width = 0;
|
|
162
155
|
}
|
|
163
156
|
},
|
|
164
|
-
[l, f,
|
|
157
|
+
[l, f, i, s, x, L]
|
|
165
158
|
);
|
|
166
|
-
return
|
|
159
|
+
return D(() => {
|
|
167
160
|
const e = () => {
|
|
168
|
-
|
|
161
|
+
s(), S();
|
|
169
162
|
};
|
|
170
163
|
return window.addEventListener("afterprint", e, !0), () => {
|
|
171
164
|
window.removeEventListener("afterprint", e, !0);
|
|
172
165
|
};
|
|
173
|
-
}, [
|
|
174
|
-
print:
|
|
175
|
-
cancel:
|
|
176
|
-
progress:
|
|
166
|
+
}, [S, s]), {
|
|
167
|
+
print: N,
|
|
168
|
+
cancel: F,
|
|
169
|
+
progress: R,
|
|
177
170
|
isComplete: T,
|
|
178
171
|
isError: A,
|
|
179
172
|
error: Z,
|
|
180
|
-
showDefaultProgress:
|
|
173
|
+
showDefaultProgress: M
|
|
181
174
|
};
|
|
182
175
|
};
|
|
183
176
|
export {
|
package/package.json
CHANGED