@pdf-viewer/react 1.15.0-beta.3 → 1.15.0-beta.4
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/utils/annotations.js +116 -108
- package/dist/utils/hooks/useLicense.js +1 -1
- package/package.json +1 -1
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { sanitizeExternalUrl as
|
|
2
|
-
import { AnnotationSubType as
|
|
1
|
+
import { sanitizeExternalUrl as _ } from "./sanitizeExternalUrl.js";
|
|
2
|
+
import { AnnotationSubType as E, AnnotationType as u } from "./types.js";
|
|
3
3
|
import { dateFormatter as I } from "./dateFormatter.js";
|
|
4
4
|
import "../th_TH-d627cd51.js";
|
|
5
|
-
const v = ["click", "dblclick", "input", "change"],
|
|
5
|
+
const v = ["click", "dblclick", "input", "change"], b = /* @__PURE__ */ new Map(), L = (e, t) => `${e.loadingTask.docId}___${t.num}R${t.gen === 0 ? "" : t.gen}`;
|
|
6
6
|
function x(e, t) {
|
|
7
|
-
const n =
|
|
8
|
-
return
|
|
7
|
+
const n = L(e, t);
|
|
8
|
+
return b.has(n) ? b.get(n) ?? null : null;
|
|
9
9
|
}
|
|
10
10
|
const B = (e, t, n) => {
|
|
11
|
-
|
|
11
|
+
b.set(L(e, t), n);
|
|
12
12
|
}, O = (e, t) => {
|
|
13
13
|
switch (t[1].name) {
|
|
14
14
|
case "XYZ":
|
|
15
15
|
return {
|
|
16
|
-
bottomOffset: (n,
|
|
17
|
-
leftOffset: (n,
|
|
16
|
+
bottomOffset: (n, s) => t[3] === null ? s : t[3],
|
|
17
|
+
leftOffset: (n, s) => t[2] === null ? 0 : t[2],
|
|
18
18
|
pageIndex: e,
|
|
19
19
|
scaleTo: t[4]
|
|
20
20
|
};
|
|
@@ -43,15 +43,15 @@ const B = (e, t, n) => {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
-
async function
|
|
46
|
+
async function h(e, t) {
|
|
47
47
|
let n;
|
|
48
48
|
if (typeof t == "string" ? n = await e.getDestination(t) : n = t, n && typeof n[0] == "object" && n[0] !== null) {
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
const r = await e.getPageIndex(
|
|
52
|
-
return B(e,
|
|
49
|
+
const s = n[0], a = x(e, s);
|
|
50
|
+
if (a === null) {
|
|
51
|
+
const r = await e.getPageIndex(s);
|
|
52
|
+
return B(e, s, r), await h(e, n);
|
|
53
53
|
} else
|
|
54
|
-
return O(
|
|
54
|
+
return O(a, n);
|
|
55
55
|
} else
|
|
56
56
|
return O(n[0], n);
|
|
57
57
|
}
|
|
@@ -59,40 +59,40 @@ const M = (e) => {
|
|
|
59
59
|
const n = e.target.parentNode;
|
|
60
60
|
if (!n)
|
|
61
61
|
return;
|
|
62
|
-
const
|
|
63
|
-
|
|
62
|
+
const s = new MutationObserver((a) => {
|
|
63
|
+
a.forEach(() => {
|
|
64
64
|
n.querySelectorAll(
|
|
65
65
|
'[data-l10n-id="pdfjs-annotation-date-time-string"]'
|
|
66
66
|
).forEach((o) => {
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
67
|
+
const i = o.getAttribute("data-l10n-args");
|
|
68
|
+
if (i) {
|
|
69
69
|
try {
|
|
70
|
-
const { dateObj:
|
|
71
|
-
|
|
70
|
+
const { dateObj: c } = JSON.parse(i);
|
|
71
|
+
c && (o.textContent = I(c));
|
|
72
72
|
} catch {
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
s.disconnect();
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
|
-
return
|
|
79
|
+
return s.observe(n, {
|
|
80
80
|
childList: !0,
|
|
81
81
|
// Watch for changes to child elements
|
|
82
82
|
subtree: !0,
|
|
83
83
|
// Watch all descendants, not just direct children
|
|
84
84
|
attributes: !0
|
|
85
85
|
// Watch for changes to attributes
|
|
86
|
-
}), () =>
|
|
87
|
-
}, P = (e, t, n,
|
|
86
|
+
}), () => s.disconnect();
|
|
87
|
+
}, P = (e, t, n, s) => {
|
|
88
88
|
if (e.type !== "click")
|
|
89
89
|
return;
|
|
90
|
-
const
|
|
90
|
+
const a = e.target, r = a.getAttribute("data-element-id"), o = a.getAttribute("href");
|
|
91
91
|
if (o && o !== "#")
|
|
92
92
|
return;
|
|
93
|
-
const
|
|
94
|
-
!
|
|
95
|
-
|
|
93
|
+
const i = t.find((c) => c.id === r);
|
|
94
|
+
!i || i.annotationType !== E.Link || i.dest && h(n, i.dest).then((c) => {
|
|
95
|
+
s(c);
|
|
96
96
|
});
|
|
97
97
|
};
|
|
98
98
|
function U(e, t) {
|
|
@@ -104,36 +104,44 @@ function V(e, t) {
|
|
|
104
104
|
e.removeEventListener(n, t);
|
|
105
105
|
}
|
|
106
106
|
function $(e) {
|
|
107
|
-
const { id: t, url: n, unsafeUrl: a } = e;
|
|
108
|
-
new MutationObserver((
|
|
107
|
+
const { id: t, url: n, unsafeUrl: s, dest: a } = e;
|
|
108
|
+
new MutationObserver((o, i) => {
|
|
109
109
|
const c = document.querySelector(`[data-annotation-id="${t}"]`);
|
|
110
110
|
if (c) {
|
|
111
|
-
const
|
|
112
|
-
|
|
111
|
+
const l = c.querySelector("a");
|
|
112
|
+
if (l)
|
|
113
|
+
if (a && !n && !s)
|
|
114
|
+
l == null || l.setAttribute("href", "#");
|
|
115
|
+
else if (n || s) {
|
|
116
|
+
const g = _((n || s) ?? "", "");
|
|
117
|
+
l == null || l.setAttribute("target", "_blank"), l == null || l.setAttribute("href", g), l == null || l.setAttribute("rel", "noopener noreferrer");
|
|
118
|
+
} else
|
|
119
|
+
l == null || l.setAttribute("href", "");
|
|
120
|
+
i.disconnect();
|
|
113
121
|
}
|
|
114
122
|
}).observe(document.body, { childList: !0, subtree: !0 });
|
|
115
123
|
}
|
|
116
124
|
function D(e, t, n) {
|
|
117
|
-
const { rotation:
|
|
125
|
+
const { rotation: s, scale: a } = t, r = s % 180 === 0;
|
|
118
126
|
if (e.fieldType === "Btn" && e.pushButton) {
|
|
119
|
-
const o = e.rect[2] - e.rect[0],
|
|
120
|
-
|
|
127
|
+
const o = e.rect[2] - e.rect[0], i = e.rect[3] - e.rect[1], c = document.createElement("canvas");
|
|
128
|
+
c.setAttribute("width", ((r ? o : i) * a).toString()), c.setAttribute("height", ((r ? i : o) * a).toString()), n.set(e.id, c);
|
|
121
129
|
}
|
|
122
130
|
}
|
|
123
|
-
function
|
|
131
|
+
function S(e) {
|
|
124
132
|
var r;
|
|
125
133
|
let t = e;
|
|
126
134
|
for (; t.tagName !== "SECTION"; )
|
|
127
135
|
t = t.parentElement;
|
|
128
|
-
const n = t.getAttribute("aria-haspopup") === "dialog",
|
|
129
|
-
if (!n && !
|
|
136
|
+
const n = t.getAttribute("aria-haspopup") === "dialog", s = t.classList.contains("popupAnnotation");
|
|
137
|
+
if (!n && !s)
|
|
130
138
|
return;
|
|
131
|
-
let
|
|
132
|
-
if (
|
|
133
|
-
const o = t.parentElement.querySelector(`[aria-controls="${
|
|
134
|
-
o && new MutationObserver((
|
|
135
|
-
const
|
|
136
|
-
|
|
139
|
+
let a = t.id || t.getAttribute("aria-controls");
|
|
140
|
+
if (a || (a = (r = t.firstChild) == null ? void 0 : r.id), a && t.parentElement) {
|
|
141
|
+
const o = t.parentElement.querySelector(`[aria-controls="${a}"]`);
|
|
142
|
+
o && new MutationObserver((c, l) => {
|
|
143
|
+
const g = document.querySelectorAll(".popupDate");
|
|
144
|
+
g.length > 0 && (g.forEach((m) => {
|
|
137
145
|
if (m.innerHTML)
|
|
138
146
|
return !1;
|
|
139
147
|
const N = m.getAttribute("data-l10n-args");
|
|
@@ -141,31 +149,31 @@ function k(e) {
|
|
|
141
149
|
const { date: y, time: A } = JSON.parse(N);
|
|
142
150
|
y && A && (m.textContent = `${y}, ${A}`);
|
|
143
151
|
}
|
|
144
|
-
}),
|
|
152
|
+
}), l.disconnect());
|
|
145
153
|
}).observe(o, { childList: !0, subtree: !0 });
|
|
146
154
|
}
|
|
147
155
|
}
|
|
148
|
-
function
|
|
149
|
-
const
|
|
156
|
+
function p(e, t, n) {
|
|
157
|
+
const s = [];
|
|
150
158
|
if (n)
|
|
151
|
-
for (const
|
|
152
|
-
|
|
153
|
-
return
|
|
159
|
+
for (const a of n)
|
|
160
|
+
a[e] === t && s.push(a);
|
|
161
|
+
return s;
|
|
154
162
|
}
|
|
155
|
-
function
|
|
163
|
+
function f(e, t) {
|
|
156
164
|
return { type: e, data: t };
|
|
157
165
|
}
|
|
158
|
-
async function
|
|
166
|
+
async function w(e, t) {
|
|
159
167
|
if (e.dest)
|
|
160
168
|
if (typeof e.dest == "string") {
|
|
161
|
-
const n = await
|
|
162
|
-
return u
|
|
169
|
+
const n = await h(t, e.dest);
|
|
170
|
+
return f(u.INTERNAL_LINK, {
|
|
163
171
|
referencedPage: n.pageIndex,
|
|
164
172
|
offset: null
|
|
165
173
|
});
|
|
166
174
|
} else {
|
|
167
175
|
const n = await t.getPageIndex(e.dest[0]);
|
|
168
|
-
return u
|
|
176
|
+
return f(u.INTERNAL_LINK, {
|
|
169
177
|
referencedPage: n,
|
|
170
178
|
offset: {
|
|
171
179
|
left: e.dest[2],
|
|
@@ -174,7 +182,7 @@ async function S(e, t) {
|
|
|
174
182
|
});
|
|
175
183
|
}
|
|
176
184
|
else if (e.url)
|
|
177
|
-
return u
|
|
185
|
+
return f(u.LINK, {
|
|
178
186
|
url: e.url,
|
|
179
187
|
unsafeUrl: e.unsafeUrl
|
|
180
188
|
});
|
|
@@ -182,113 +190,113 @@ async function S(e, t) {
|
|
|
182
190
|
function T(e) {
|
|
183
191
|
for (const t of e.getElementsByTagName("span")) {
|
|
184
192
|
let n = t.textContent;
|
|
185
|
-
const
|
|
193
|
+
const s = JSON.parse(t.dataset.l10nArgs ?? "{}");
|
|
186
194
|
if (n)
|
|
187
|
-
for (const
|
|
188
|
-
n = n.replace(`{{${
|
|
195
|
+
for (const a in s)
|
|
196
|
+
n = n.replace(`{{${a}}}`, s[a]);
|
|
189
197
|
t.textContent = n;
|
|
190
198
|
}
|
|
191
199
|
}
|
|
192
|
-
function
|
|
193
|
-
return u
|
|
200
|
+
function C(e) {
|
|
201
|
+
return f(u.FILE_ATTACHMENT, e.file);
|
|
194
202
|
}
|
|
195
|
-
function
|
|
203
|
+
function d(e, t) {
|
|
196
204
|
switch (e.type) {
|
|
197
205
|
case "textarea":
|
|
198
206
|
case "text":
|
|
199
|
-
return u
|
|
207
|
+
return f(u.FORM_TEXT, {
|
|
200
208
|
fieldName: e.name,
|
|
201
209
|
value: e.value
|
|
202
210
|
});
|
|
203
211
|
case "select-one":
|
|
204
212
|
case "select-multiple":
|
|
205
213
|
const n = [];
|
|
206
|
-
for (const
|
|
214
|
+
for (const a of e.options)
|
|
207
215
|
n.push({
|
|
208
|
-
value:
|
|
209
|
-
label:
|
|
216
|
+
value: a.value,
|
|
217
|
+
label: a.label
|
|
210
218
|
});
|
|
211
|
-
const
|
|
212
|
-
for (const
|
|
213
|
-
|
|
214
|
-
value:
|
|
215
|
-
label:
|
|
219
|
+
const s = [];
|
|
220
|
+
for (const a of e.selectedOptions)
|
|
221
|
+
s.push({
|
|
222
|
+
value: a.value,
|
|
223
|
+
label: a.label
|
|
216
224
|
});
|
|
217
|
-
return u
|
|
225
|
+
return f(u.FORM_SELECT, {
|
|
218
226
|
fieldName: e.name,
|
|
219
|
-
value:
|
|
227
|
+
value: s,
|
|
220
228
|
options: n
|
|
221
229
|
});
|
|
222
230
|
case "checkbox":
|
|
223
|
-
return u
|
|
231
|
+
return f(u.FORM_CHECKBOX, {
|
|
224
232
|
fieldName: e.name,
|
|
225
233
|
checked: e.checked
|
|
226
234
|
});
|
|
227
235
|
case "radio":
|
|
228
|
-
return u
|
|
236
|
+
return f(u.FORM_RADIO, {
|
|
229
237
|
fieldName: e.name,
|
|
230
238
|
...t
|
|
231
239
|
});
|
|
232
240
|
case "button":
|
|
233
|
-
return u
|
|
241
|
+
return f(u.FORM_BUTTON, {
|
|
234
242
|
fieldName: e.name,
|
|
235
243
|
...t
|
|
236
244
|
});
|
|
237
245
|
}
|
|
238
246
|
}
|
|
239
247
|
async function W(e, t, n) {
|
|
240
|
-
var
|
|
241
|
-
let
|
|
242
|
-
if (
|
|
243
|
-
if (
|
|
244
|
-
const r = (
|
|
248
|
+
var a;
|
|
249
|
+
let s = e.target.parentNode;
|
|
250
|
+
if (s.tagName === "DIV" && (s = s.firstChild), S(s), typeof s.className != "object")
|
|
251
|
+
if (s.className === "linkAnnotation" && e.type === "click") {
|
|
252
|
+
const r = (a = s.dataset) == null ? void 0 : a.annotationId;
|
|
245
253
|
if (r) {
|
|
246
|
-
const o =
|
|
254
|
+
const o = p("id", r, n);
|
|
247
255
|
if (o.length)
|
|
248
|
-
return await
|
|
256
|
+
return await w(o[0], t);
|
|
249
257
|
}
|
|
250
258
|
} else if (
|
|
251
259
|
/* annotation.className.includes('popupAnnotation') || */
|
|
252
|
-
|
|
260
|
+
s.className.includes("textAnnotation")
|
|
253
261
|
)
|
|
254
|
-
T(
|
|
255
|
-
else if (
|
|
256
|
-
T(
|
|
257
|
-
const r =
|
|
262
|
+
T(s);
|
|
263
|
+
else if (s.className.includes("fileAttachmentAnnotation")) {
|
|
264
|
+
T(s);
|
|
265
|
+
const r = s.dataset.annotationId;
|
|
258
266
|
if (r && e.type === "dblclick")
|
|
259
|
-
return
|
|
260
|
-
} else if (
|
|
261
|
-
let r =
|
|
262
|
-
return r || (r =
|
|
267
|
+
return C(p("id", r, n)[0]);
|
|
268
|
+
} else if (s.className.includes("textWidgetAnnotation") && e.type === "input") {
|
|
269
|
+
let r = s.getElementsByTagName("input")[0];
|
|
270
|
+
return r || (r = s.getElementsByTagName("textarea")[0]), d(r);
|
|
263
271
|
} else {
|
|
264
|
-
if (
|
|
265
|
-
return
|
|
266
|
-
if (
|
|
267
|
-
return
|
|
268
|
-
if (
|
|
269
|
-
const r =
|
|
272
|
+
if (s.className.includes("choiceWidgetAnnotation") && e.type === "input")
|
|
273
|
+
return d(s.getElementsByTagName("select")[0]);
|
|
274
|
+
if (s.className.includes("buttonWidgetAnnotation checkBox") && e.type === "change")
|
|
275
|
+
return d(s.getElementsByTagName("input")[0]);
|
|
276
|
+
if (s.className.includes("buttonWidgetAnnotation radioButton") && e.type === "change") {
|
|
277
|
+
const r = s.dataset.annotationId;
|
|
270
278
|
if (r) {
|
|
271
|
-
const o =
|
|
272
|
-
for (const
|
|
279
|
+
const o = p("id", r, n)[0], i = [];
|
|
280
|
+
for (const c of p(
|
|
273
281
|
"fieldName",
|
|
274
282
|
o.fieldName,
|
|
275
283
|
n
|
|
276
284
|
))
|
|
277
|
-
|
|
278
|
-
return
|
|
285
|
+
c.buttonValue && i.push(c.buttonValue);
|
|
286
|
+
return d(s.getElementsByTagName("input")[0], {
|
|
279
287
|
value: o.buttonValue,
|
|
280
288
|
defaultValue: o.fieldValue,
|
|
281
|
-
options:
|
|
289
|
+
options: i
|
|
282
290
|
});
|
|
283
291
|
}
|
|
284
|
-
} else if (
|
|
285
|
-
const r =
|
|
292
|
+
} else if (s.className.includes("buttonWidgetAnnotation pushButton") && e.type === "click") {
|
|
293
|
+
const r = s.dataset.annotationId;
|
|
286
294
|
if (r) {
|
|
287
|
-
const o =
|
|
288
|
-
return
|
|
295
|
+
const o = p("id", r, n)[0], { action: i } = o;
|
|
296
|
+
return i && ["Print", "SaveAs"].includes(i) ? { type: u.BUTTON, data: o } : o.resetForm ? d(
|
|
289
297
|
{ name: o.fieldName, type: "button" },
|
|
290
298
|
{ actions: o.actions, reset: !0 }
|
|
291
|
-
) :
|
|
299
|
+
) : d(
|
|
292
300
|
{ name: o.fieldName, type: "button" },
|
|
293
301
|
{ actions: o.actions, reset: !1 }
|
|
294
302
|
);
|
|
@@ -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("2025-12-
|
|
3
|
+
const b = /* @__PURE__ */ new Date("2025-12-16T03:06:14.614Z"), 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}`,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@pdf-viewer/react",
|
|
3
3
|
"private": false,
|
|
4
4
|
"description": "A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.",
|
|
5
|
-
"version": "1.15.0-beta.
|
|
5
|
+
"version": "1.15.0-beta.4",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"react-pdf",
|
|
8
8
|
"react-pdf-viewer",
|