@react-pdf-kit/viewer 2.10.0-beta.0 → 2.10.0-beta.2
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/components/page/RPPage.js +1 -1
- package/dist/components/page/XfaLayer.js +76 -39
- package/dist/utils/highlight.js +4 -2
- package/dist/utils/hooks/useLicense.js +1 -1
- package/dist/utils/hooks/usePrint.js +30 -13
- package/dist/utils/hooks/useSearch.js +4 -1
- package/dist/utils/injectPrintCSS.js +1 -1
- package/package.json +1 -1
|
@@ -73,7 +73,7 @@ var b = a((a, b) => {
|
|
|
73
73
|
children: /* @__PURE__ */ v(k, {})
|
|
74
74
|
}),
|
|
75
75
|
/* @__PURE__ */ v(d, { pageNumber: x }),
|
|
76
|
-
E && /* @__PURE__ */ v(c, { pageNumber: x }),
|
|
76
|
+
E && !A?.page.isPureXfa && /* @__PURE__ */ v(c, { pageNumber: x }),
|
|
77
77
|
/* @__PURE__ */ v(u, {
|
|
78
78
|
pageNumber: x,
|
|
79
79
|
viewport: F
|
|
@@ -1,49 +1,86 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { r } from "../../
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
2
|
+
import { runPdfOperation as e } from "../../utils/pdfOperationTracker.js";
|
|
3
|
+
import { useDocumentContext as t } from "../../contexts/RPDocumentContext.js";
|
|
4
|
+
import { useZoomContext as n } from "../../contexts/ZoomContext.js";
|
|
5
|
+
import { usePagesRotateContext as r } from "../../contexts/PagesRotateContext.js";
|
|
6
|
+
import { useSmoothScrollContext as i } from "../../contexts/SmoothScrollContext.js";
|
|
7
|
+
import { r as a } from "../../PaginationContext-DIzsZhFd.js";
|
|
8
|
+
import { SimpleLinkService as o } from "../../utils/link_service.js";
|
|
9
|
+
import { t as s } from "../../XfaLayer.module-w4FOd2dm.js";
|
|
10
|
+
import { highlightMatches as c, resetDivs as l } from "../../utils/highlight.js";
|
|
11
|
+
import { useSearchContext as u } from "../../contexts/SearchContext.js";
|
|
12
|
+
import { useEffect as d, useRef as f, useState as p } from "react";
|
|
13
|
+
import { XfaLayer as m } from "pdfjs-dist";
|
|
14
|
+
import { jsx as h } from "react/jsx-runtime";
|
|
11
15
|
//#region lib/components/page/XfaLayer.tsx
|
|
12
|
-
var
|
|
13
|
-
let
|
|
14
|
-
if (
|
|
15
|
-
if (!
|
|
16
|
-
let
|
|
16
|
+
var g = ({ pageNumber: g }) => {
|
|
17
|
+
let _ = f(null), v = f(null), [y, b] = p(0), [x, S] = p([]), { pages: C, pdf: w } = t(), { matches: T, currentMatch: E } = u(), { scrollBehavior: D } = i(), { currentZoom: O, targetZoom: k } = n(), { pageRotate: A } = r(), { goToPage: j } = a(), M = C.get(g), N = M ? A[g] ?? M.defaultRotation ?? 0 : 0;
|
|
18
|
+
if (d(() => {
|
|
19
|
+
if (!M || !w || !M.page.isPureXfa || !_.current || !O) return;
|
|
20
|
+
let t = new AbortController();
|
|
17
21
|
return (async () => {
|
|
18
|
-
let
|
|
19
|
-
if (
|
|
20
|
-
let
|
|
21
|
-
scale:
|
|
22
|
-
rotation:
|
|
23
|
-
}),
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
let [n, r] = await Promise.all([M.page.getXfa(), e(w, () => M.page.getTextContent())]);
|
|
23
|
+
if (t.signal.aborted || !n || !_.current) return;
|
|
24
|
+
let i = M.page.getViewport({
|
|
25
|
+
scale: O,
|
|
26
|
+
rotation: N
|
|
27
|
+
}), a = document.createElement("div");
|
|
28
|
+
_.current.replaceChildren(a);
|
|
29
|
+
let { textDivs: s } = m.render({
|
|
30
|
+
div: a,
|
|
31
|
+
viewport: i.clone({ dontFlip: !0 }),
|
|
32
|
+
xfaHtml: n,
|
|
33
|
+
annotationStorage: w.annotationStorage,
|
|
34
|
+
linkService: new o(w, j)
|
|
30
35
|
});
|
|
36
|
+
v.current = {
|
|
37
|
+
content: r,
|
|
38
|
+
divs: s
|
|
39
|
+
}, b((e) => e + 1);
|
|
31
40
|
})(), () => {
|
|
32
|
-
|
|
41
|
+
t.abort(), v.current = null;
|
|
33
42
|
};
|
|
34
43
|
}, [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
]),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
O,
|
|
45
|
+
j,
|
|
46
|
+
M,
|
|
47
|
+
w,
|
|
48
|
+
N
|
|
49
|
+
]), d(() => {
|
|
50
|
+
let e = v.current;
|
|
51
|
+
if (!e) return;
|
|
52
|
+
l(e.content, e.divs);
|
|
53
|
+
let t = T.filter((e) => e.pageIndex === g - 1);
|
|
54
|
+
S(t.length ? c(t, e.content, e.divs) : []);
|
|
55
|
+
}, [
|
|
56
|
+
T,
|
|
57
|
+
g,
|
|
58
|
+
y
|
|
59
|
+
]), d(() => {
|
|
60
|
+
if (x.forEach(({ element: e }) => e.classList.remove("selected")), E?.pageIndex !== g - 1) return;
|
|
61
|
+
let e = x.find(({ index: e }) => e === E.pageMatchIdx)?.element;
|
|
62
|
+
if (!e) return;
|
|
63
|
+
e.classList.add("selected");
|
|
64
|
+
let t = requestAnimationFrame(() => {
|
|
65
|
+
e.scrollIntoView({
|
|
66
|
+
block: "center",
|
|
67
|
+
inline: "nearest",
|
|
68
|
+
behavior: D
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
return () => cancelAnimationFrame(t);
|
|
72
|
+
}, [
|
|
73
|
+
E,
|
|
74
|
+
x,
|
|
75
|
+
g,
|
|
76
|
+
D
|
|
77
|
+
]), !M?.page.isPureXfa) return null;
|
|
78
|
+
let P = O && k ? k / O : 1;
|
|
79
|
+
return /* @__PURE__ */ h("div", {
|
|
80
|
+
ref: _,
|
|
81
|
+
className: s["rp-xfa-layer"],
|
|
82
|
+
style: { "--rp-xfa-visual-scale": P }
|
|
46
83
|
});
|
|
47
84
|
};
|
|
48
85
|
//#endregion
|
|
49
|
-
export {
|
|
86
|
+
export { g as XfaLayer };
|
package/dist/utils/highlight.js
CHANGED
|
@@ -72,7 +72,9 @@ function i(e, t, n) {
|
|
|
72
72
|
for (let e of c) {
|
|
73
73
|
let n = [];
|
|
74
74
|
for (let r = e.start.idx; r <= e.end.idx; r++) {
|
|
75
|
-
let i = o[r]
|
|
75
|
+
let i = o[r];
|
|
76
|
+
if (!i.transform) continue;
|
|
77
|
+
let a = i.transform[4], s = i.transform[5], c = i.str.length > 0 ? i.width / i.str.length : 0, l = r === e.start.idx ? e.start.offset : 0, u = r === e.end.idx ? e.end.offset : i.str.length, d = a + l * c, f = (u - l) * c, p = (t.styles ?? {})[i.fontName], m = p?.ascent ?? 1, h = s - (p?.descent == null ? 1 - m : Math.abs(p.descent)) * i.height;
|
|
76
78
|
i.height > 0 && i.width > 0 && n.push({
|
|
77
79
|
left: d,
|
|
78
80
|
bottom: h,
|
|
@@ -80,7 +82,7 @@ function i(e, t, n) {
|
|
|
80
82
|
height: i.height
|
|
81
83
|
});
|
|
82
84
|
}
|
|
83
|
-
e.rect = n[0], e.rects = n;
|
|
85
|
+
e.rect = n[0] ?? e.rect, e.rects = n;
|
|
84
86
|
}
|
|
85
87
|
return c;
|
|
86
88
|
}
|
|
@@ -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-09-
|
|
6
|
+
var o = /* @__PURE__ */ new Date("2026-09-24T09:32:41.962Z"), 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}`,
|
|
@@ -86,10 +86,26 @@ var p = () => {
|
|
|
86
86
|
subtree: !0
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
|
-
}, []), j = (e
|
|
89
|
+
}, []), j = async (e) => {
|
|
90
|
+
let t = document.createElement("iframe");
|
|
91
|
+
t.title = "PDF print document", t.style.cssText = "position:fixed;width:0;height:0;border:0;", document.body.appendChild(t);
|
|
92
|
+
try {
|
|
93
|
+
let n = t.contentWindow, r = t.contentDocument;
|
|
94
|
+
if (!n || !r) throw Error("Unable to create PDF print document");
|
|
95
|
+
for (let e of ["rp-viewer-styles", "rp-print-style"]) {
|
|
96
|
+
let t = document.getElementById(e);
|
|
97
|
+
t && r.head.appendChild(t.cloneNode(!0));
|
|
98
|
+
}
|
|
99
|
+
r.documentElement.classList.add("rp-print-html-printing"), r.body.classList.add("rp-print-xfa-printing"), r.body.appendChild(e), n.addEventListener("afterprint", () => {
|
|
100
|
+
D(), t.remove();
|
|
101
|
+
}, { once: !0 }), await new Promise((e) => setTimeout(e, 0)), n.focus(), n.print();
|
|
102
|
+
} catch (e) {
|
|
103
|
+
throw t.remove(), e;
|
|
104
|
+
}
|
|
105
|
+
}, M = (e, t) => {
|
|
90
106
|
let n = document.createElement("img"), r = document.createElement("div"), i = document.createElement("div");
|
|
91
107
|
return r.classList.add("rp-print-page"), i.classList.add("rp-print-page-content"), i.style.width = `${t.width}pt`, i.style.height = `${t.height}pt`, n.src = e.toDataURL(), i.appendChild(n), r.appendChild(i), r;
|
|
92
|
-
},
|
|
108
|
+
}, N = (e) => {
|
|
93
109
|
let t = e.allXfaHtml;
|
|
94
110
|
if (!t?.children?.length) return [];
|
|
95
111
|
let i = new n(e, () => {}), a = Math.round(l.PDF_TO_CSS_UNITS * 100) / 100;
|
|
@@ -108,7 +124,7 @@ var p = () => {
|
|
|
108
124
|
intent: "print"
|
|
109
125
|
}), n;
|
|
110
126
|
});
|
|
111
|
-
},
|
|
127
|
+
}, P = (e, t) => {
|
|
112
128
|
let n = document.createElement("div");
|
|
113
129
|
n.classList.add("rp-print-zone");
|
|
114
130
|
let r = document.createElement("style"), i = t.get(1);
|
|
@@ -117,7 +133,7 @@ var p = () => {
|
|
|
117
133
|
r.innerHTML = `@page { size: ${e}pt ${t}pt; margin: 0; }`;
|
|
118
134
|
}
|
|
119
135
|
return n.appendChild(r), n.append(...e), n;
|
|
120
|
-
},
|
|
136
|
+
}, F = i(async (t) => {
|
|
121
137
|
if (!p) return;
|
|
122
138
|
D();
|
|
123
139
|
let n = t && "visibleDefaultProgress" in t ? t : void 0;
|
|
@@ -125,16 +141,16 @@ var p = () => {
|
|
|
125
141
|
let r = document.createElement("canvas"), i = [];
|
|
126
142
|
try {
|
|
127
143
|
if (p.isPureXfa) {
|
|
128
|
-
if (i.push(...
|
|
144
|
+
if (i.push(...N(p)), T.current) {
|
|
129
145
|
D();
|
|
130
146
|
return;
|
|
131
147
|
}
|
|
132
|
-
let e =
|
|
133
|
-
|
|
148
|
+
let e = P(i, m);
|
|
149
|
+
g({
|
|
134
150
|
loadedPages: i.length,
|
|
135
151
|
totalPages: i.length,
|
|
136
152
|
percentage: 100
|
|
137
|
-
}), v(!0), await
|
|
153
|
+
}), v(!0), await j(e);
|
|
138
154
|
return;
|
|
139
155
|
}
|
|
140
156
|
let t = e(p, () => p.getOptionalContentConfig({ intent: "print" })), n = Promise.resolve(p.annotationStorage.print ?? void 0), a = m.size;
|
|
@@ -156,7 +172,7 @@ var p = () => {
|
|
|
156
172
|
D();
|
|
157
173
|
return;
|
|
158
174
|
}
|
|
159
|
-
let c =
|
|
175
|
+
let c = M(r, s);
|
|
160
176
|
i.push(c), g({
|
|
161
177
|
loadedPages: e,
|
|
162
178
|
totalPages: a,
|
|
@@ -167,7 +183,7 @@ var p = () => {
|
|
|
167
183
|
D();
|
|
168
184
|
return;
|
|
169
185
|
}
|
|
170
|
-
let o =
|
|
186
|
+
let o = P(i, m);
|
|
171
187
|
document.body.appendChild(o), document.documentElement.classList.add("rp-print-html-printing"), document.body.classList.add("rp-print-body-printing"), v(!0), await A();
|
|
172
188
|
} catch (e) {
|
|
173
189
|
b(!0), e instanceof Error && S(e);
|
|
@@ -179,8 +195,9 @@ var p = () => {
|
|
|
179
195
|
m,
|
|
180
196
|
T,
|
|
181
197
|
D,
|
|
182
|
-
|
|
183
|
-
A
|
|
198
|
+
P,
|
|
199
|
+
A,
|
|
200
|
+
j
|
|
184
201
|
]);
|
|
185
202
|
return a(() => {
|
|
186
203
|
let e = () => {
|
|
@@ -190,7 +207,7 @@ var p = () => {
|
|
|
190
207
|
window.removeEventListener("afterprint", e, !0);
|
|
191
208
|
};
|
|
192
209
|
}, [E, D]), {
|
|
193
|
-
print:
|
|
210
|
+
print: F,
|
|
194
211
|
cancel: O,
|
|
195
212
|
progress: h,
|
|
196
213
|
isComplete: _,
|
|
@@ -39,7 +39,10 @@ var x = (x = {}, S = "") => {
|
|
|
39
39
|
let s = {
|
|
40
40
|
height: A[n.page - 1],
|
|
41
41
|
width: k[n.page - 1]
|
|
42
|
-
}, c = L[n.page], { leftInPage: l, topInPage: u } =
|
|
42
|
+
}, c = L[n.page], { leftInPage: l, topInPage: u } = i.page.isPureXfa ? {
|
|
43
|
+
leftInPage: 0,
|
|
44
|
+
topInPage: 0
|
|
45
|
+
} : h(s, U, n.rect, M, c), p = a.offsetLeft + o.left + l, m = a.offsetTop + o.top + u, g = {
|
|
43
46
|
left: Math.max(p, 0),
|
|
44
47
|
top: Math.max(m, 0)
|
|
45
48
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
function e() {
|
|
3
3
|
if (typeof document > "u" || document.getElementById("rp-print-style")) return;
|
|
4
4
|
let e = document.createElement("style");
|
|
5
|
-
e.id = "rp-print-style", e.textContent = "\n @page { margin: 0; }\n\n .rp-print-zone { display: none; }\n\n @media print {\n .rp-print-html-printing { height: 100%; }\n .rp-print-body-printing { background: rgb(0 0 0 / 0) none; height: 100% !important; margin: 0 !important; display: block !important; }\n .rp-print-body-printing > *:not(.rp-print-zone) { display: none; }\n .rp-print-zone { display: block; height: 100%; }\n .rp-print-page { display: flex; align-items: center; flex-direction: column; justify-content: center; height: 100%; width: 100%; page-break-after: always; page-break-inside: avoid; }\n .rp-print-page:last-child { page-break-after: auto; }\n .rp-print-page-content { position: relative; flex: 0 0 auto; }\n .rp-print-page:not(.rp-print-xfa-page) img, .rp-print-page canvas { display: block; max-width: 100%; max-height: 100%; direction: ltr; }\n .rp-print-page.rp-print-xfa-page { display: block; position: relative; }\n .rp-print-xfa-page .xfaPage { position: absolute; }\n }\n ", document.head.appendChild(e);
|
|
5
|
+
e.id = "rp-print-style", e.textContent = "\n @page { margin: 0; }\n\n .rp-print-zone { display: none; }\n\n @media print {\n .rp-print-html-printing { height: 100%; }\n .rp-print-body-printing, .rp-print-xfa-printing { background: rgb(0 0 0 / 0) none; height: 100% !important; margin: 0 !important; display: block !important; }\n .rp-print-body-printing * { display: none; }\n .rp-print-xfa-printing > *:not(.rp-print-zone) { display: none; }\n .rp-print-zone { display: block; height: 100%; }\n .rp-print-page { display: flex; align-items: center; flex-direction: column; justify-content: center; height: 100%; width: 100%; page-break-after: always; page-break-inside: avoid; }\n .rp-print-page:last-child { page-break-after: auto; }\n .rp-print-page-content { display: block; position: relative; flex: 0 0 auto; }\n .rp-print-page:not(.rp-print-xfa-page) img, .rp-print-page canvas { display: block; max-width: 100%; max-height: 100%; direction: ltr; }\n .rp-print-page.rp-print-xfa-page { display: block; position: relative; }\n .rp-print-xfa-page .xfaPage { position: absolute; }\n }\n ", document.head.appendChild(e);
|
|
6
6
|
}
|
|
7
7
|
//#endregion
|
|
8
8
|
export { e as injectPrintCSS };
|