@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.
Files changed (48) hide show
  1. package/dist/RPLayout.module-7766e0b4.js +14 -0
  2. package/dist/assets/style.css +1 -1
  3. package/dist/assets/style.js +15 -15
  4. package/dist/components/RPController.js +24 -20
  5. package/dist/components/RPPages.js +322 -321
  6. package/dist/components/RPProvider.js +22 -19
  7. package/dist/components/layout/LayoutContainer.js +1 -1
  8. package/dist/components/layout/LayoutWrapper.js +1 -1
  9. package/dist/components/layout/RPDefaultLayout.js +5 -3
  10. package/dist/components/layout/RPLayout.js +5 -3
  11. package/dist/components/layout/toolbar/RPToolbar.js +4 -2
  12. package/dist/components/layout/toolbar/SearchResultNavigator.js +4 -2
  13. package/dist/components/layout/toolbar/SearchTool.js +4 -2
  14. package/dist/components/layout/toolbar/ToolbarDefault.js +4 -2
  15. package/dist/components/layout/toolbar/ToolbarLayout.js +4 -2
  16. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +7 -4
  17. package/dist/components/layout/toolbar/tools/FirstPageTool.js +7 -4
  18. package/dist/components/layout/toolbar/tools/LastPageTool.js +7 -4
  19. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +4 -2
  20. package/dist/components/page/AnnotationLayer.js +52 -52
  21. package/dist/components/page/DualPage.js +9 -4
  22. package/dist/components/page/DualPageWithCover.js +9 -4
  23. package/dist/components/page/RPPage.js +9 -4
  24. package/dist/components/page/SinglePage.js +9 -4
  25. package/dist/components/page/TextHighlightLayer.js +84 -177
  26. package/dist/components/page/TextLayer.js +124 -170
  27. package/dist/contexts/HighlightContext.js +8 -6
  28. package/dist/contexts/SearchContext.js +6 -4
  29. package/dist/contexts/TextSelectionContext.js +191 -0
  30. package/dist/main.js +114 -112
  31. package/dist/types/contexts/TextSelectionContext.d.ts +14 -0
  32. package/dist/types/utils/geometryCache.d.ts +15 -0
  33. package/dist/types/utils/glyphHitTest.d.ts +12 -0
  34. package/dist/types/utils/hooks/useTextSelection.d.ts +12 -3
  35. package/dist/types/utils/selectionUtils.d.ts +30 -0
  36. package/dist/utils/geometryCache.js +32 -0
  37. package/dist/utils/glyphHitTest.js +29 -0
  38. package/dist/utils/highlight.js +184 -158
  39. package/dist/utils/hooks/useCopyText.js +60 -22
  40. package/dist/utils/hooks/useHighlight.js +35 -33
  41. package/dist/utils/hooks/useLicense.js +1 -1
  42. package/dist/utils/hooks/useSearch.js +4 -2
  43. package/dist/utils/hooks/useTextSelection.js +2 -73
  44. package/dist/utils/selectionUtils.js +96 -0
  45. package/package.json +2 -2
  46. package/dist/RPLayout.module-b4b23e29.js +0 -14
  47. package/dist/types/utils/hooks/useFlickerSelectText.d.ts +0 -1
  48. package/dist/utils/hooks/useFlickerSelectText.js +0 -25
@@ -1,221 +1,247 @@
1
- import { getCharacterType as D } from "./charators.js";
2
- function _(l, c, m, i) {
3
- const s = [];
4
- for (const n of l) {
5
- const o = y(c, n, i);
6
- s.push(...R(o, c, m));
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 s;
10
+ return t;
9
11
  }
10
- const L = (l, c) => {
11
- const m = ["g"];
12
- c.matchCase || m.push("i");
13
- let s = l.replace(/[.^$*+?()[{|\\]/g, (n) => `\\${n}`).trim();
14
- return new RegExp(s, m.join(""));
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 y(l, c, m) {
18
+ function X(r, d, a) {
17
19
  const i = [];
18
- for (const t of l.items)
19
- if (t.hasEOL)
20
- if (t.str.endsWith("-")) {
21
- const d = t.str.lastIndexOf("-");
22
- i.push(t.str.substring(0, d));
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(t.str, `
26
+ i.push(n.str, `
25
27
  `);
26
28
  else
27
- i.push(t.str);
28
- const s = i.join("").replace(/\n/g, " ");
29
- let n;
30
- c instanceof RegExp ? n = c.flags.indexOf("g") === -1 ? new RegExp(c, `${c.flags}g`) : c : n = L(c, m);
31
- const o = [];
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 = n.exec(s)) !== null; )
34
- m.wholeWords && !W(s, e.index, e[0].length) || o.push([e.index, e[0].length, e[0]]);
35
- return o;
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 R(l, c, m) {
38
- function i(d) {
39
- return d.hasEOL ? d.str.endsWith("-") ? -1 : 1 : 0;
39
+ function _(r, d, a) {
40
+ function i(o) {
41
+ return o.hasEOL ? o.str.endsWith("-") ? -1 : 1 : 0;
40
42
  }
41
- let s = 0, n = 0;
42
- const o = c.items, e = o.length - 1, t = [];
43
- for (let d = 0; d < l.length; d++) {
44
- let h = l[d][0];
45
- for (; s !== e && h >= n + o[s].str.length; ) {
46
- const x = o[s];
47
- n += x.str.length + i(x), s++;
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 g = {
50
- idx: s,
51
- offset: h - n
51
+ const u = {
52
+ idx: t,
53
+ offset: l - s
52
54
  };
53
- for (h += l[d][1]; s !== e && h > n + o[s].str.length; ) {
54
- const x = o[s];
55
- n += x.str.length + i(x), s++;
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 r = {
58
- idx: s,
59
- offset: h - n
59
+ const g = {
60
+ idx: t,
61
+ offset: l - s
60
62
  };
61
- t.push({
62
- start: g,
63
- end: r,
64
- str: l[d][2],
65
- oIndex: l[d][0],
66
- pageIndex: m,
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
- for (const d of t) {
72
- const h = [];
73
- for (let g = d.start.idx; g <= d.end.idx; g++) {
74
- const r = o[g], x = r.transform[4], C = r.transform[5], a = r.str.length > 0 ? r.width / r.str.length : 0, M = g === d.start.idx ? d.start.offset : 0, N = g === d.end.idx ? d.end.offset : r.str.length, f = x + M * a, E = (N - M) * a, u = (c.styles ?? {})[r.fontName], T = (u == null ? void 0 : u.ascent) ?? 1, v = (u == null ? void 0 : u.descent) != null ? Math.abs(u.descent) : 1 - T, b = C - v * r.height;
75
- r.height > 0 && r.width > 0 && h.push({
76
- left: f,
77
- bottom: b,
78
- width: E,
79
- height: r.height
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
- d.rect = h[0], d.rects = h;
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 t;
101
+ return n;
85
102
  }
86
- function W(l, c, m) {
87
- let i = l.slice(0, c).match(/([^\p{M}])\p{M}*$/u);
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 s = l.charCodeAt(c), n = i[1].charCodeAt(0);
90
- if (D(s) === D(n))
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 = l.slice(c + m).match(/^\p{M}*([^\p{M}])/u), i) {
94
- const s = l.charCodeAt(c + m - 1), n = i[1].charCodeAt(0);
95
- if (D(s) === D(n))
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 I(l, c, m) {
117
+ function $(r, d, a) {
101
118
  const i = [];
102
- function s(n, o, e = -1, t = -1, d = "") {
103
- const h = c.items[n], g = [];
104
- let r = "", x = "", C = "", a = m[n];
105
- if (!a)
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 (a.nodeType === Node.TEXT_NODE) {
108
- const f = document.createElement("span");
109
- a.before(f), f.append(a), m[n] = f, a = f;
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 && t >= 0 ? r = h.str.substring(e, t) : e < 0 && t < 0 ? r = h.str : e >= 0 ? r = h.str.substring(e) : t >= 0 && (r = h.str.substring(0, t));
112
- const M = document.createTextNode(r), N = document.createElement("span");
113
- if (N.className = "highlight appended " + d, N.setAttribute("data-match-index", `${o}`), N.append(M), g.push(N), i.push({ element: N, index: o }), e > 0)
114
- if (a.childNodes.length === 1 && a.childNodes[0].nodeType === Node.TEXT_NODE) {
115
- x = h.str.substring(0, e);
116
- const f = document.createTextNode(x);
117
- g.unshift(f);
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 f = 0;
136
+ let p = 0;
120
137
  const E = [];
121
- for (const p of a.childNodes) {
122
- const u = p.nodeType === Node.TEXT_NODE ? p.nodeValue : p.firstChild.nodeValue;
123
- f += u.length, f <= e ? E.push(p) : e >= f - u.length && t <= f && E.push(
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
- u.substring(0, e - (f - u.length))
142
+ N.substring(0, e - (p - N.length))
126
143
  )
127
144
  );
128
145
  }
129
- g.unshift(...E);
146
+ l.unshift(...E);
130
147
  }
131
- if (t > 0) {
132
- C = h.str.substring(t);
133
- const f = document.createTextNode(C);
134
- g.push(f);
148
+ if (n > 0) {
149
+ x = o.str.substring(n);
150
+ const p = document.createTextNode(x);
151
+ l.push(p);
135
152
  }
136
- a.replaceChildren(...g);
153
+ h.replaceChildren(...l);
137
154
  }
138
- for (const [n, o] of l.entries())
139
- if (o.start.idx === o.end.idx)
140
- s(o.start.idx, n, o.start.offset, o.end.offset);
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 = o.start.idx, t = o.end.idx; e <= t; e++)
143
- e === o.start.idx ? s(e, n, o.start.offset, -1, "begin") : e === o.end.idx ? s(e, n, -1, o.end.offset, "end") : s(e, n, -1, -1, "middle");
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 V(l, c) {
147
- const m = l.items.map((i) => i.str);
148
- for (let i = 0; i < c.length; i++) {
149
- const s = c[i];
150
- if (s && s.nodeType !== Node.TEXT_NODE) {
151
- const n = document.createTextNode(m[i]);
152
- s.replaceChildren(n);
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 H(l = {}) {
157
- return { matchCase: !1, wholeWords: !1, ...l };
173
+ function G(r = {}) {
174
+ return { matchCase: !1, wholeWords: !1, ...r };
158
175
  }
159
- function S(l, c, m) {
176
+ function j(r, d, a) {
160
177
  const i = [];
161
- function s(n, o, e = -1, t = -1, d) {
162
- var f, E;
163
- const h = c.items[n], g = [];
164
- let r = "", x = "", C = "", a = m[n];
165
- if (!a)
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 && t >= 0 ? r = h.str.substring(e, t) : e < 0 && t < 0 ? r = h.str : e >= 0 ? r = h.str.substring(e) : t >= 0 && (r = h.str.substring(0, t));
168
- const M = document.createTextNode(r), N = document.createElement("span");
169
- if (N.style.background = d, N.append(M), g.push(N), e > 0)
170
- if (a.childNodes.length === 1 && a.childNodes[0].nodeType === Node.TEXT_NODE) {
171
- x = h.str.substring(0, e);
172
- const p = document.createTextNode(x);
173
- g.unshift(p);
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 p = 0;
176
- const u = [];
177
- for (const T of a.childNodes) {
178
- const v = T.nodeType === Node.TEXT_NODE ? T.nodeValue || "" : ((f = T.firstChild) == null ? void 0 : f.nodeValue) || "", b = v.length;
179
- if (p += b, p <= e)
180
- u.push(T);
181
- else if (e >= p - b && t <= p) {
182
- const w = v.substring(0, e - (p - b));
183
- u.push(document.createTextNode(w));
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
- g.unshift(...u);
203
+ l.unshift(...N);
187
204
  }
188
- if (t > 0)
189
- if (a.childNodes.length === 1 && a.childNodes[0].nodeType === Node.TEXT_NODE) {
190
- C = h.str.substring(t);
191
- const p = document.createTextNode(C);
192
- g.push(p);
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 p = 0;
195
- const u = [];
196
- for (const T of a.childNodes) {
197
- p >= t && u.push(T);
198
- const v = T.nodeType === Node.TEXT_NODE ? T.nodeValue || "" : ((E = T.firstChild) == null ? void 0 : E.nodeValue) || "", b = v.length;
199
- if (p += b, p > t) {
200
- const w = v.substring(t - (p - b));
201
- w && u.push(document.createTextNode(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
- u.length > 0 && g.push(...u);
221
+ N.length > 0 && l.push(...N);
205
222
  }
206
- a.replaceChildren(...g), i.push({ element: N, index: o });
223
+ h.replaceChildren(...l), i.push({ element: b, index: c });
207
224
  }
208
- for (const [n, o] of l.entries()) {
209
- const { start: e, end: t, color: d } = o;
210
- e.idx === t.idx && s(e.idx, n, e.offset, t.offset, d);
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
- _ as findMatches,
216
- H as getHighlightOptionsWithDefaults,
217
- I as highlightMatches,
218
- S as highlightMultipleColorMatches,
219
- W as isMatchEntireWord,
220
- V as resetDivs
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 o, useEffect as i } from "react";
2
- const s = /[\x00-\x1F]/g;
3
- let c = null, r = null;
4
- function d(e) {
5
- 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, r = /* @__PURE__ */ new Map([["", "ſt"]])), e.replace(
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
- (f, u, t) => u ? u.normalize("NFKC") : (r == null ? void 0 : r.get(t)) || ""
35
+ (e, r, f) => r ? r.normalize("NFKC") : (o == null ? void 0 : o.get(f)) || ""
8
36
  );
9
37
  }
10
- function p(e, f = !1) {
11
- return s.test(e) ? f ? e.replace(s, (u) => u === "\0" ? "" : " ") : e.replace(/\x00/g, "") : e;
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 x = (e) => {
14
- const f = o(!1), u = o(null);
15
- i(() => {
16
- if (!e || f.current)
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 t = (n) => {
19
- var l;
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 a = b.toString();
24
- a && ((l = n.clipboardData) == null || l.setData(
61
+ const l = b.toString();
62
+ l && ((d = u.clipboardData) == null || d.setData(
25
63
  "text/plain",
26
- p(d(a))
27
- ), n.preventDefault(), n.stopPropagation());
64
+ D(C(l))
65
+ ), u.preventDefault(), u.stopPropagation());
28
66
  };
29
- return e.addEventListener("copy", t), u.current = e, f.current = !0, () => {
30
- u.current && (u.current.removeEventListener("copy", t), f.current = !1);
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
- }, [e]);
70
+ }, [t]);
33
71
  };
34
72
  export {
35
- x as useCopyText
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)), c = 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));
6
- return { left: e, bottom: o, width: c - e, height: t };
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 c of n) {
16
- const o = c.keyword, t = e[o] ?? [];
17
- t.push(c), e[o] = t;
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 c = n[0], o = N(n), t = o.length > 0 ? O(o) : c.rect ? [c.rect] : [];
23
+ const r = n[0], o = N(n), t = o.length > 0 ? O(o) : r.rect ? [r.rect] : [];
22
24
  return {
23
- ...c,
25
+ ...r,
24
26
  pageMatchIdx: e,
25
- rect: t[0] ?? c.rect,
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 c = 0;
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, c++));
41
+ o.push(j(g, r++));
40
42
  }
41
43
  return o;
42
- }, K = (n) => {
43
- const [e, c] = f(void 0), [o, t] = f([]), s = p(async (r) => {
44
- if (!r)
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 i = r.numPages, h = {};
47
- for (let a = 1; a <= i; a++) {
48
- const u = await r.getPage(a);
49
- h[a.toString()] = await u.getTextContent();
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 h;
52
- }, []), g = p(async (r) => {
53
- c(r);
53
+ return i;
54
+ }, []), g = p(async (c) => {
55
+ r(c);
54
56
  }, []), l = p(() => {
55
- t([]), c(void 0);
57
+ t([]), r(void 0);
56
58
  }, []);
57
59
  return w(() => {
58
- n && s(n).then((r) => {
59
- let i = [];
60
- for (const { keyword: h, highlightColor: a, options: u } of e) {
61
- if (!h)
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(r)) {
66
+ for (const m of Object.keys(c)) {
65
67
  const d = P(
66
- [h],
67
- r[m],
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: a,
75
- keyword: h
76
+ color: h,
77
+ keyword: i
76
78
  }));
77
- i = [...i, ...d];
79
+ a = [...a, ...d];
78
80
  }
79
81
  }
80
- t(v(i));
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
- K as useHighlight
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-10T05:15:21.036Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", s = {
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}`,