@react-pdf-kit/viewer 0.0.0-experimental.3 → 0.0.0-experimental.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/RPLayout.module-7766e0b4.js +14 -0
- package/dist/assets/style.css +1 -1
- package/dist/assets/style.js +15 -15
- package/dist/components/RPController.js +24 -20
- package/dist/components/RPPages.js +322 -321
- package/dist/components/RPProvider.js +22 -19
- package/dist/components/layout/LayoutContainer.js +1 -1
- package/dist/components/layout/LayoutWrapper.js +1 -1
- package/dist/components/layout/RPDefaultLayout.js +5 -3
- package/dist/components/layout/RPLayout.js +5 -3
- package/dist/components/layout/toolbar/RPToolbar.js +4 -2
- package/dist/components/layout/toolbar/SearchResultNavigator.js +4 -2
- package/dist/components/layout/toolbar/SearchTool.js +4 -2
- package/dist/components/layout/toolbar/ToolbarDefault.js +4 -2
- package/dist/components/layout/toolbar/ToolbarLayout.js +4 -2
- package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +7 -4
- package/dist/components/layout/toolbar/tools/FirstPageTool.js +7 -4
- package/dist/components/layout/toolbar/tools/LastPageTool.js +7 -4
- package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +4 -2
- package/dist/components/page/AnnotationLayer.js +52 -52
- package/dist/components/page/DualPage.js +9 -4
- package/dist/components/page/DualPageWithCover.js +9 -4
- package/dist/components/page/RPPage.js +9 -4
- package/dist/components/page/SinglePage.js +9 -4
- package/dist/components/page/TextHighlightLayer.js +84 -177
- package/dist/components/page/TextLayer.js +124 -170
- package/dist/contexts/HighlightContext.js +8 -6
- package/dist/contexts/SearchContext.js +6 -4
- package/dist/contexts/TextSelectionContext.js +191 -0
- package/dist/main.js +114 -112
- package/dist/types/contexts/TextSelectionContext.d.ts +14 -0
- package/dist/types/utils/geometryCache.d.ts +15 -0
- package/dist/types/utils/glyphHitTest.d.ts +12 -0
- package/dist/types/utils/hooks/useTextSelection.d.ts +12 -3
- package/dist/types/utils/selectionUtils.d.ts +30 -0
- package/dist/utils/geometryCache.js +32 -0
- package/dist/utils/glyphHitTest.js +29 -0
- package/dist/utils/highlight.js +184 -158
- package/dist/utils/hooks/useCopyText.js +60 -22
- package/dist/utils/hooks/useHighlight.js +35 -33
- package/dist/utils/hooks/useLicense.js +1 -1
- package/dist/utils/hooks/useSearch.js +4 -2
- package/dist/utils/hooks/useTextSelection.js +2 -73
- package/dist/utils/selectionUtils.js +96 -0
- package/package.json +2 -2
- package/dist/RPLayout.module-b4b23e29.js +0 -14
- package/dist/types/utils/hooks/useFlickerSelectText.d.ts +0 -1
- package/dist/utils/hooks/useFlickerSelectText.js +0 -25
package/dist/utils/highlight.js
CHANGED
|
@@ -1,221 +1,247 @@
|
|
|
1
|
-
import { getCharacterType as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { getCharacterType as y } from "./charators.js";
|
|
2
|
+
import { rectsForRange as L } from "./selectionUtils.js";
|
|
3
|
+
import { geometryCache as R } from "./geometryCache.js";
|
|
4
|
+
function A(r, d, a, i) {
|
|
5
|
+
const t = [];
|
|
6
|
+
for (const s of r) {
|
|
7
|
+
const c = X(d, s, i);
|
|
8
|
+
t.push(..._(c, d, a));
|
|
7
9
|
}
|
|
8
|
-
return
|
|
10
|
+
return t;
|
|
9
11
|
}
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
let
|
|
14
|
-
return new RegExp(
|
|
12
|
+
const W = (r, d) => {
|
|
13
|
+
const a = ["g"];
|
|
14
|
+
d.matchCase || a.push("i");
|
|
15
|
+
let t = r.replace(/[.^$*+?()[{|\\]/g, (s) => `\\${s}`).trim();
|
|
16
|
+
return new RegExp(t, a.join(""));
|
|
15
17
|
};
|
|
16
|
-
function
|
|
18
|
+
function X(r, d, a) {
|
|
17
19
|
const i = [];
|
|
18
|
-
for (const
|
|
19
|
-
if (
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
i.push(
|
|
20
|
+
for (const n of r.items)
|
|
21
|
+
if (n.hasEOL)
|
|
22
|
+
if (n.str.endsWith("-")) {
|
|
23
|
+
const T = n.str.lastIndexOf("-");
|
|
24
|
+
i.push(n.str.substring(0, T));
|
|
23
25
|
} else
|
|
24
|
-
i.push(
|
|
26
|
+
i.push(n.str, `
|
|
25
27
|
`);
|
|
26
28
|
else
|
|
27
|
-
i.push(
|
|
28
|
-
const
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
const
|
|
29
|
+
i.push(n.str);
|
|
30
|
+
const t = i.join("").replace(/\n/g, " ");
|
|
31
|
+
let s;
|
|
32
|
+
d instanceof RegExp ? s = d.flags.indexOf("g") === -1 ? new RegExp(d, `${d.flags}g`) : d : s = W(d, a);
|
|
33
|
+
const c = [];
|
|
32
34
|
let e;
|
|
33
|
-
for (; (e =
|
|
34
|
-
|
|
35
|
-
return
|
|
35
|
+
for (; (e = s.exec(t)) !== null; )
|
|
36
|
+
a.wholeWords && !V(t, e.index, e[0].length) || c.push([e.index, e[0].length, e[0]]);
|
|
37
|
+
return c;
|
|
36
38
|
}
|
|
37
|
-
function
|
|
38
|
-
function i(
|
|
39
|
-
return
|
|
39
|
+
function _(r, d, a) {
|
|
40
|
+
function i(o) {
|
|
41
|
+
return o.hasEOL ? o.str.endsWith("-") ? -1 : 1 : 0;
|
|
40
42
|
}
|
|
41
|
-
let
|
|
42
|
-
const
|
|
43
|
-
for (let
|
|
44
|
-
let
|
|
45
|
-
for (;
|
|
46
|
-
const x =
|
|
47
|
-
|
|
43
|
+
let t = 0, s = 0;
|
|
44
|
+
const c = d.items, e = c.length - 1, n = [];
|
|
45
|
+
for (let o = 0; o < r.length; o++) {
|
|
46
|
+
let l = r[o][0];
|
|
47
|
+
for (; t !== e && l >= s + c[t].str.length; ) {
|
|
48
|
+
const x = c[t];
|
|
49
|
+
s += x.str.length + i(x), t++;
|
|
48
50
|
}
|
|
49
|
-
const
|
|
50
|
-
idx:
|
|
51
|
-
offset:
|
|
51
|
+
const u = {
|
|
52
|
+
idx: t,
|
|
53
|
+
offset: l - s
|
|
52
54
|
};
|
|
53
|
-
for (
|
|
54
|
-
const x =
|
|
55
|
-
|
|
55
|
+
for (l += r[o][1]; t !== e && l > s + c[t].str.length; ) {
|
|
56
|
+
const x = c[t];
|
|
57
|
+
s += x.str.length + i(x), t++;
|
|
56
58
|
}
|
|
57
|
-
const
|
|
58
|
-
idx:
|
|
59
|
-
offset:
|
|
59
|
+
const g = {
|
|
60
|
+
idx: t,
|
|
61
|
+
offset: l - s
|
|
60
62
|
};
|
|
61
|
-
|
|
62
|
-
start:
|
|
63
|
-
end:
|
|
64
|
-
str:
|
|
65
|
-
oIndex:
|
|
66
|
-
pageIndex:
|
|
63
|
+
n.push({
|
|
64
|
+
start: u,
|
|
65
|
+
end: g,
|
|
66
|
+
str: r[o][2],
|
|
67
|
+
oIndex: r[o][0],
|
|
68
|
+
pageIndex: a,
|
|
67
69
|
rect: { left: 0, bottom: 0, width: 0, height: 0 },
|
|
68
70
|
rects: []
|
|
69
71
|
});
|
|
70
72
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
const T = R.get(a);
|
|
74
|
+
for (const o of n) {
|
|
75
|
+
const l = [];
|
|
76
|
+
if (T && T.runs.length > 0) {
|
|
77
|
+
const u = D(T, o.start.idx, o.start.offset), g = D(T, o.end.idx, o.end.offset - 1);
|
|
78
|
+
if (u >= 0 && g >= 0) {
|
|
79
|
+
const x = L(T, u, g);
|
|
80
|
+
for (const h of x)
|
|
81
|
+
l.push({
|
|
82
|
+
left: h.x,
|
|
83
|
+
bottom: h.y + h.height,
|
|
84
|
+
width: h.width,
|
|
85
|
+
height: h.height
|
|
86
|
+
});
|
|
87
|
+
}
|
|
81
88
|
}
|
|
82
|
-
|
|
89
|
+
if (l.length === 0)
|
|
90
|
+
for (let u = o.start.idx; u <= o.end.idx; u++) {
|
|
91
|
+
const g = c[u], x = g.transform[4], h = g.transform[5], v = g.str.length > 0 ? g.width / g.str.length : 0, b = u === o.start.idx ? o.start.offset : 0, p = u === o.end.idx ? o.end.offset : g.str.length, E = x + b * v, f = (p - b) * v, m = (d.styles ?? {})[g.fontName], M = (m == null ? void 0 : m.ascent) ?? 1, C = (m == null ? void 0 : m.descent) != null ? Math.abs(m.descent) : 1 - M, w = h - C * g.height;
|
|
92
|
+
g.height > 0 && g.width > 0 && l.push({
|
|
93
|
+
left: E,
|
|
94
|
+
bottom: w,
|
|
95
|
+
width: f,
|
|
96
|
+
height: g.height
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
o.rect = l[0] ?? { left: 0, bottom: 0, width: 0, height: 0 }, o.rects = l;
|
|
83
100
|
}
|
|
84
|
-
return
|
|
101
|
+
return n;
|
|
85
102
|
}
|
|
86
|
-
function
|
|
87
|
-
let i =
|
|
103
|
+
function V(r, d, a) {
|
|
104
|
+
let i = r.slice(0, d).match(/([^\p{M}])\p{M}*$/u);
|
|
88
105
|
if (i) {
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
106
|
+
const t = r.charCodeAt(d), s = i[1].charCodeAt(0);
|
|
107
|
+
if (y(t) === y(s))
|
|
91
108
|
return !1;
|
|
92
109
|
}
|
|
93
|
-
if (i =
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
110
|
+
if (i = r.slice(d + a).match(/^\p{M}*([^\p{M}])/u), i) {
|
|
111
|
+
const t = r.charCodeAt(d + a - 1), s = i[1].charCodeAt(0);
|
|
112
|
+
if (y(t) === y(s))
|
|
96
113
|
return !1;
|
|
97
114
|
}
|
|
98
115
|
return !0;
|
|
99
116
|
}
|
|
100
|
-
function
|
|
117
|
+
function $(r, d, a) {
|
|
101
118
|
const i = [];
|
|
102
|
-
function s
|
|
103
|
-
const
|
|
104
|
-
let
|
|
105
|
-
if (!
|
|
119
|
+
function t(s, c, e = -1, n = -1, T = "") {
|
|
120
|
+
const o = d.items[s], l = [];
|
|
121
|
+
let u = "", g = "", x = "", h = a[s];
|
|
122
|
+
if (!h)
|
|
106
123
|
return;
|
|
107
|
-
if (
|
|
108
|
-
const
|
|
109
|
-
|
|
124
|
+
if (h.nodeType === Node.TEXT_NODE) {
|
|
125
|
+
const p = document.createElement("span");
|
|
126
|
+
h.before(p), p.append(h), a[s] = p, h = p;
|
|
110
127
|
}
|
|
111
|
-
e >= 0 &&
|
|
112
|
-
const
|
|
113
|
-
if (
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
128
|
+
e >= 0 && n >= 0 ? u = o.str.substring(e, n) : e < 0 && n < 0 ? u = o.str : e >= 0 ? u = o.str.substring(e) : n >= 0 && (u = o.str.substring(0, n));
|
|
129
|
+
const v = document.createTextNode(u), b = document.createElement("span");
|
|
130
|
+
if (b.className = "highlight appended " + T, b.setAttribute("data-match-index", `${c}`), b.append(v), l.push(b), i.push({ element: b, index: c }), e > 0)
|
|
131
|
+
if (h.childNodes.length === 1 && h.childNodes[0].nodeType === Node.TEXT_NODE) {
|
|
132
|
+
g = o.str.substring(0, e);
|
|
133
|
+
const p = document.createTextNode(g);
|
|
134
|
+
l.unshift(p);
|
|
118
135
|
} else {
|
|
119
|
-
let
|
|
136
|
+
let p = 0;
|
|
120
137
|
const E = [];
|
|
121
|
-
for (const
|
|
122
|
-
const
|
|
123
|
-
|
|
138
|
+
for (const f of h.childNodes) {
|
|
139
|
+
const N = f.nodeType === Node.TEXT_NODE ? f.nodeValue : f.firstChild.nodeValue;
|
|
140
|
+
p += N.length, p <= e ? E.push(f) : e >= p - N.length && n <= p && E.push(
|
|
124
141
|
document.createTextNode(
|
|
125
|
-
|
|
142
|
+
N.substring(0, e - (p - N.length))
|
|
126
143
|
)
|
|
127
144
|
);
|
|
128
145
|
}
|
|
129
|
-
|
|
146
|
+
l.unshift(...E);
|
|
130
147
|
}
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
148
|
+
if (n > 0) {
|
|
149
|
+
x = o.str.substring(n);
|
|
150
|
+
const p = document.createTextNode(x);
|
|
151
|
+
l.push(p);
|
|
135
152
|
}
|
|
136
|
-
|
|
153
|
+
h.replaceChildren(...l);
|
|
137
154
|
}
|
|
138
|
-
for (const [
|
|
139
|
-
if (
|
|
140
|
-
|
|
155
|
+
for (const [s, c] of r.entries())
|
|
156
|
+
if (c.start.idx === c.end.idx)
|
|
157
|
+
t(c.start.idx, s, c.start.offset, c.end.offset);
|
|
141
158
|
else
|
|
142
|
-
for (let e =
|
|
143
|
-
e ===
|
|
159
|
+
for (let e = c.start.idx, n = c.end.idx; e <= n; e++)
|
|
160
|
+
e === c.start.idx ? t(e, s, c.start.offset, -1, "begin") : e === c.end.idx ? t(e, s, -1, c.end.offset, "end") : t(e, s, -1, -1, "middle");
|
|
144
161
|
return i;
|
|
145
162
|
}
|
|
146
|
-
function
|
|
147
|
-
const
|
|
148
|
-
for (let i = 0; i <
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
151
|
-
const
|
|
152
|
-
|
|
163
|
+
function F(r, d) {
|
|
164
|
+
const a = r.items.map((i) => i.str);
|
|
165
|
+
for (let i = 0; i < d.length; i++) {
|
|
166
|
+
const t = d[i];
|
|
167
|
+
if (t && t.nodeType !== Node.TEXT_NODE) {
|
|
168
|
+
const s = document.createTextNode(a[i]);
|
|
169
|
+
t.replaceChildren(s);
|
|
153
170
|
}
|
|
154
171
|
}
|
|
155
172
|
}
|
|
156
|
-
function
|
|
157
|
-
return { matchCase: !1, wholeWords: !1, ...
|
|
173
|
+
function G(r = {}) {
|
|
174
|
+
return { matchCase: !1, wholeWords: !1, ...r };
|
|
158
175
|
}
|
|
159
|
-
function
|
|
176
|
+
function j(r, d, a) {
|
|
160
177
|
const i = [];
|
|
161
|
-
function s
|
|
162
|
-
var
|
|
163
|
-
const
|
|
164
|
-
let
|
|
165
|
-
if (!
|
|
178
|
+
function t(s, c, e = -1, n = -1, T) {
|
|
179
|
+
var p, E;
|
|
180
|
+
const o = d.items[s], l = [];
|
|
181
|
+
let u = "", g = "", x = "", h = a[s];
|
|
182
|
+
if (!h)
|
|
166
183
|
return;
|
|
167
|
-
e >= 0 &&
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
184
|
+
e >= 0 && n >= 0 ? u = o.str.substring(e, n) : e < 0 && n < 0 ? u = o.str : e >= 0 ? u = o.str.substring(e) : n >= 0 && (u = o.str.substring(0, n));
|
|
185
|
+
const v = document.createTextNode(u), b = document.createElement("span");
|
|
186
|
+
if (b.style.background = T, b.append(v), l.push(b), e > 0)
|
|
187
|
+
if (h.childNodes.length === 1 && h.childNodes[0].nodeType === Node.TEXT_NODE) {
|
|
188
|
+
g = o.str.substring(0, e);
|
|
189
|
+
const f = document.createTextNode(g);
|
|
190
|
+
l.unshift(f);
|
|
174
191
|
} else {
|
|
175
|
-
let
|
|
176
|
-
const
|
|
177
|
-
for (const
|
|
178
|
-
const
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
else if (e >=
|
|
182
|
-
const w =
|
|
183
|
-
|
|
192
|
+
let f = 0;
|
|
193
|
+
const N = [];
|
|
194
|
+
for (const m of h.childNodes) {
|
|
195
|
+
const M = m.nodeType === Node.TEXT_NODE ? m.nodeValue || "" : ((p = m.firstChild) == null ? void 0 : p.nodeValue) || "", C = M.length;
|
|
196
|
+
if (f += C, f <= e)
|
|
197
|
+
N.push(m);
|
|
198
|
+
else if (e >= f - C && n <= f) {
|
|
199
|
+
const w = M.substring(0, e - (f - C));
|
|
200
|
+
N.push(document.createTextNode(w));
|
|
184
201
|
}
|
|
185
202
|
}
|
|
186
|
-
|
|
203
|
+
l.unshift(...N);
|
|
187
204
|
}
|
|
188
|
-
if (
|
|
189
|
-
if (
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
205
|
+
if (n > 0)
|
|
206
|
+
if (h.childNodes.length === 1 && h.childNodes[0].nodeType === Node.TEXT_NODE) {
|
|
207
|
+
x = o.str.substring(n);
|
|
208
|
+
const f = document.createTextNode(x);
|
|
209
|
+
l.push(f);
|
|
193
210
|
} else {
|
|
194
|
-
let
|
|
195
|
-
const
|
|
196
|
-
for (const
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
if (
|
|
200
|
-
const w =
|
|
201
|
-
w &&
|
|
211
|
+
let f = 0;
|
|
212
|
+
const N = [];
|
|
213
|
+
for (const m of h.childNodes) {
|
|
214
|
+
f >= n && N.push(m);
|
|
215
|
+
const M = m.nodeType === Node.TEXT_NODE ? m.nodeValue || "" : ((E = m.firstChild) == null ? void 0 : E.nodeValue) || "", C = M.length;
|
|
216
|
+
if (f += C, f > n) {
|
|
217
|
+
const w = M.substring(n - (f - C));
|
|
218
|
+
w && N.push(document.createTextNode(w));
|
|
202
219
|
}
|
|
203
220
|
}
|
|
204
|
-
|
|
221
|
+
N.length > 0 && l.push(...N);
|
|
205
222
|
}
|
|
206
|
-
|
|
223
|
+
h.replaceChildren(...l), i.push({ element: b, index: c });
|
|
207
224
|
}
|
|
208
|
-
for (const [
|
|
209
|
-
const { start: e, end:
|
|
210
|
-
e.idx ===
|
|
225
|
+
for (const [s, c] of r.entries()) {
|
|
226
|
+
const { start: e, end: n, color: T } = c;
|
|
227
|
+
e.idx === n.idx && t(e.idx, s, e.offset, n.offset, T);
|
|
211
228
|
}
|
|
212
229
|
return i;
|
|
213
230
|
}
|
|
231
|
+
function D(r, d, a) {
|
|
232
|
+
let i = 0;
|
|
233
|
+
for (let t = 0; t < r.runs.length; t++) {
|
|
234
|
+
if (t === d)
|
|
235
|
+
return i + Math.min(a, r.runs[t].glyphs.length - 1);
|
|
236
|
+
i += r.runs[t].glyphs.length;
|
|
237
|
+
}
|
|
238
|
+
return Math.max(0, i - 1);
|
|
239
|
+
}
|
|
214
240
|
export {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
241
|
+
A as findMatches,
|
|
242
|
+
G as getHighlightOptionsWithDefaults,
|
|
243
|
+
$ as highlightMatches,
|
|
244
|
+
j as highlightMultipleColorMatches,
|
|
245
|
+
V as isMatchEntireWord,
|
|
246
|
+
F as resetDivs
|
|
221
247
|
};
|
|
@@ -1,36 +1,74 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { useRef as p, useEffect as x } from "react";
|
|
2
|
+
import { useTextSelectionContext as R } from "../../contexts/TextSelectionContext.js";
|
|
3
|
+
import "react/jsx-runtime";
|
|
4
|
+
import "../glyphHitTest.js";
|
|
5
|
+
import "../selectionUtils.js";
|
|
6
|
+
import "../geometryCache.js";
|
|
7
|
+
import "../../contexts/EventCallbackContext.js";
|
|
8
|
+
import "../../contexts/ZoomContext.js";
|
|
9
|
+
import "../types.js";
|
|
10
|
+
import "../../de_DE-a553b162.js";
|
|
11
|
+
import "../appConsole.js";
|
|
12
|
+
import "../../contexts/InitialStateContext.js";
|
|
13
|
+
import "../../contexts/RPDocumentContext.js";
|
|
14
|
+
import "./useLoadPdf.js";
|
|
15
|
+
import "@pdf-viewer/pdfium";
|
|
16
|
+
import "@pdf-viewer/pdfium/compat";
|
|
17
|
+
import "../getThumbnailViewport.js";
|
|
18
|
+
import "../../contexts/ConfigContext.js";
|
|
19
|
+
import "../../contexts/DocumentPasswordContext.js";
|
|
20
|
+
import "./usePdfProperties.js";
|
|
21
|
+
import "../convertPdfDate.js";
|
|
22
|
+
import "../formatFileSize.js";
|
|
23
|
+
import "../constants.js";
|
|
24
|
+
import "../getZoomLevel.js";
|
|
25
|
+
import "../../contexts/LayoutContainerContext.js";
|
|
26
|
+
import "../../contexts/ViewModeContext.js";
|
|
27
|
+
import "../../contexts/RotationContext.js";
|
|
28
|
+
import "../../contexts/GlobalCurrentPage.js";
|
|
29
|
+
import "./useDebounce.js";
|
|
30
|
+
const g = /[\x00-\x1F]/g;
|
|
31
|
+
let c = null, o = null;
|
|
32
|
+
function C(t) {
|
|
33
|
+
return c || (c = /([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu, o = /* @__PURE__ */ new Map([["ſt", "ſt"]])), t.replace(
|
|
6
34
|
c,
|
|
7
|
-
(
|
|
35
|
+
(e, r, f) => r ? r.normalize("NFKC") : (o == null ? void 0 : o.get(f)) || ""
|
|
8
36
|
);
|
|
9
37
|
}
|
|
10
|
-
function
|
|
11
|
-
return
|
|
38
|
+
function D(t, e = !1) {
|
|
39
|
+
return g.test(t) ? e ? t.replace(g, (r) => r === "\0" ? "" : " ") : t.replace(/\x00/g, "") : t;
|
|
12
40
|
}
|
|
13
|
-
const
|
|
14
|
-
const f =
|
|
15
|
-
|
|
16
|
-
|
|
41
|
+
const X = (t) => {
|
|
42
|
+
const { selectedText: e, selectionVersion: r } = R(), f = p(e), i = p(!1), n = p(null);
|
|
43
|
+
x(() => {
|
|
44
|
+
f.current = e;
|
|
45
|
+
}, [e, r]), x(() => {
|
|
46
|
+
if (!t || i.current)
|
|
17
47
|
return;
|
|
18
|
-
const
|
|
19
|
-
var
|
|
48
|
+
const a = (u) => {
|
|
49
|
+
var s, d;
|
|
50
|
+
const m = f.current;
|
|
51
|
+
if (m) {
|
|
52
|
+
(s = u.clipboardData) == null || s.setData(
|
|
53
|
+
"text/plain",
|
|
54
|
+
D(C(m))
|
|
55
|
+
), u.preventDefault(), u.stopPropagation();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
20
58
|
const b = document.getSelection();
|
|
21
59
|
if (!b)
|
|
22
60
|
return;
|
|
23
|
-
const
|
|
24
|
-
|
|
61
|
+
const l = b.toString();
|
|
62
|
+
l && ((d = u.clipboardData) == null || d.setData(
|
|
25
63
|
"text/plain",
|
|
26
|
-
|
|
27
|
-
),
|
|
64
|
+
D(C(l))
|
|
65
|
+
), u.preventDefault(), u.stopPropagation());
|
|
28
66
|
};
|
|
29
|
-
return
|
|
30
|
-
|
|
67
|
+
return t.addEventListener("copy", a), n.current = t, i.current = !0, () => {
|
|
68
|
+
n.current && (n.current.removeEventListener("copy", a), i.current = !1);
|
|
31
69
|
};
|
|
32
|
-
}, [
|
|
70
|
+
}, [t]);
|
|
33
71
|
};
|
|
34
72
|
export {
|
|
35
|
-
|
|
73
|
+
X as useCopyText
|
|
36
74
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { useState as f, useCallback as p, useEffect as w } from "react";
|
|
2
2
|
import { getHighlightOptionsWithDefaults as k, findMatches as P } from "../highlight.js";
|
|
3
3
|
import "../charators.js";
|
|
4
|
+
import "../selectionUtils.js";
|
|
5
|
+
import "../geometryCache.js";
|
|
4
6
|
const x = (n) => {
|
|
5
|
-
const e = Math.min(...n.map((s) => s.left)),
|
|
6
|
-
return { left: e, bottom: o, width:
|
|
7
|
+
const e = Math.min(...n.map((s) => s.left)), r = Math.max(...n.map((s) => s.left + s.width)), o = Math.min(...n.map((s) => s.bottom)), t = Math.max(...n.map((s) => s.height));
|
|
8
|
+
return { left: e, bottom: o, width: r - e, height: t };
|
|
7
9
|
}, N = (n) => n.flatMap((e) => e.rects ?? (e.rect ? [e.rect] : [])), O = (n) => {
|
|
8
10
|
const e = n.reduce((o, t) => {
|
|
9
11
|
const s = Math.round(t.bottom);
|
|
@@ -12,17 +14,17 @@ const x = (n) => {
|
|
|
12
14
|
return Object.entries(e).sort((o, t) => Number(t[0]) - Number(o[0])).map(([o, t]) => x(t));
|
|
13
15
|
}, L = (n) => {
|
|
14
16
|
const e = {};
|
|
15
|
-
for (const
|
|
16
|
-
const o =
|
|
17
|
-
t.push(
|
|
17
|
+
for (const r of n) {
|
|
18
|
+
const o = r.keyword, t = e[o] ?? [];
|
|
19
|
+
t.push(r), e[o] = t;
|
|
18
20
|
}
|
|
19
21
|
return e;
|
|
20
22
|
}, j = (n, e) => {
|
|
21
|
-
const
|
|
23
|
+
const r = n[0], o = N(n), t = o.length > 0 ? O(o) : r.rect ? [r.rect] : [];
|
|
22
24
|
return {
|
|
23
|
-
...
|
|
25
|
+
...r,
|
|
24
26
|
pageMatchIdx: e,
|
|
25
|
-
rect: t[0] ??
|
|
27
|
+
rect: t[0] ?? r.rect,
|
|
26
28
|
rects: t
|
|
27
29
|
};
|
|
28
30
|
}, v = (n) => {
|
|
@@ -31,53 +33,53 @@ const x = (n) => {
|
|
|
31
33
|
const s = e[t.page] ?? [];
|
|
32
34
|
s.push(t), e[t.page] = s;
|
|
33
35
|
}
|
|
34
|
-
let
|
|
36
|
+
let r = 0;
|
|
35
37
|
const o = [];
|
|
36
38
|
for (const t of Object.values(e)) {
|
|
37
39
|
const s = L(t);
|
|
38
40
|
for (const g of Object.values(s))
|
|
39
|
-
o.push(j(g,
|
|
41
|
+
o.push(j(g, r++));
|
|
40
42
|
}
|
|
41
43
|
return o;
|
|
42
|
-
},
|
|
43
|
-
const [e,
|
|
44
|
-
if (!
|
|
44
|
+
}, I = (n) => {
|
|
45
|
+
const [e, r] = f(void 0), [o, t] = f([]), s = p(async (c) => {
|
|
46
|
+
if (!c)
|
|
45
47
|
return {};
|
|
46
|
-
const
|
|
47
|
-
for (let
|
|
48
|
-
const u = await
|
|
49
|
-
h
|
|
48
|
+
const a = c.numPages, i = {};
|
|
49
|
+
for (let h = 1; h <= a; h++) {
|
|
50
|
+
const u = await c.getPage(h);
|
|
51
|
+
i[h.toString()] = await u.getTextContent();
|
|
50
52
|
}
|
|
51
|
-
return
|
|
52
|
-
}, []), g = p(async (
|
|
53
|
-
c
|
|
53
|
+
return i;
|
|
54
|
+
}, []), g = p(async (c) => {
|
|
55
|
+
r(c);
|
|
54
56
|
}, []), l = p(() => {
|
|
55
|
-
t([]),
|
|
57
|
+
t([]), r(void 0);
|
|
56
58
|
}, []);
|
|
57
59
|
return w(() => {
|
|
58
|
-
n && s(n).then((
|
|
59
|
-
let
|
|
60
|
-
for (const { keyword:
|
|
61
|
-
if (!
|
|
60
|
+
n && s(n).then((c) => {
|
|
61
|
+
let a = [];
|
|
62
|
+
for (const { keyword: i, highlightColor: h, options: u } of e) {
|
|
63
|
+
if (!i)
|
|
62
64
|
continue;
|
|
63
65
|
const b = k(u);
|
|
64
|
-
for (const m of Object.keys(
|
|
66
|
+
for (const m of Object.keys(c)) {
|
|
65
67
|
const d = P(
|
|
66
|
-
[
|
|
67
|
-
|
|
68
|
+
[i],
|
|
69
|
+
c[m],
|
|
68
70
|
Number(m) - 1,
|
|
69
71
|
b
|
|
70
72
|
).map((M, y) => ({
|
|
71
73
|
...M,
|
|
72
74
|
page: Number(m),
|
|
73
75
|
pageMatchIdx: y,
|
|
74
|
-
color:
|
|
75
|
-
keyword:
|
|
76
|
+
color: h,
|
|
77
|
+
keyword: i
|
|
76
78
|
}));
|
|
77
|
-
|
|
79
|
+
a = [...a, ...d];
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
|
-
t(v(
|
|
82
|
+
t(v(a));
|
|
81
83
|
}).catch(() => {
|
|
82
84
|
l();
|
|
83
85
|
});
|
|
@@ -89,5 +91,5 @@ const x = (n) => {
|
|
|
89
91
|
};
|
|
90
92
|
};
|
|
91
93
|
export {
|
|
92
|
-
|
|
94
|
+
I as useHighlight
|
|
93
95
|
};
|
|
@@ -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-03-
|
|
3
|
+
const b = /* @__PURE__ */ new Date("2026-03-12T03:17:42.792Z"), 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}`,
|