@react-pdf-kit/viewer 0.0.0-experimental.7 → 0.0.0-experimental.9

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 (130) 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/RPConfig.js +11 -12
  5. package/dist/components/RPController.js +26 -21
  6. package/dist/components/RPDropFileZone.js +8 -7
  7. package/dist/components/RPPages.js +360 -351
  8. package/dist/components/RPProvider.js +24 -20
  9. package/dist/components/layout/LayoutContainer.js +1 -1
  10. package/dist/components/layout/LayoutWrapper.js +1 -1
  11. package/dist/components/layout/RPDefaultLayout.js +7 -4
  12. package/dist/components/layout/RPLayout.js +7 -4
  13. package/dist/components/layout/WrapperLayout.js +4 -3
  14. package/dist/components/layout/sidebar/RPSidebar.js +4 -3
  15. package/dist/components/layout/sidebar/Thumbnail.js +4 -3
  16. package/dist/components/layout/sidebar/Thumbnails.js +4 -3
  17. package/dist/components/layout/toolbar/DocumentDialog.js +6 -5
  18. package/dist/components/layout/toolbar/FileDownloadTool.js +4 -3
  19. package/dist/components/layout/toolbar/FileUploadTool.js +4 -3
  20. package/dist/components/layout/toolbar/MostPageTool.js +4 -3
  21. package/dist/components/layout/toolbar/OtherTool.js +4 -3
  22. package/dist/components/layout/toolbar/Paginate.js +4 -3
  23. package/dist/components/layout/toolbar/PrintTool.js +4 -3
  24. package/dist/components/layout/toolbar/RPMoreOptions.js +4 -3
  25. package/dist/components/layout/toolbar/RPToolbar.js +6 -3
  26. package/dist/components/layout/toolbar/RPToolbarEnd.js +4 -3
  27. package/dist/components/layout/toolbar/RotateTool.js +4 -3
  28. package/dist/components/layout/toolbar/SearchResultNavigator.js +6 -3
  29. package/dist/components/layout/toolbar/SearchTool.js +6 -3
  30. package/dist/components/layout/toolbar/ThumbnailTool.js +4 -3
  31. package/dist/components/layout/toolbar/ToolbarCustom.js +4 -3
  32. package/dist/components/layout/toolbar/ToolbarDefault.js +6 -3
  33. package/dist/components/layout/toolbar/ToolbarLayout.js +6 -3
  34. package/dist/components/layout/toolbar/ZoomTool.js +4 -3
  35. package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +4 -3
  36. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +9 -5
  37. package/dist/components/layout/toolbar/tools/FileDownloadTool.js +4 -3
  38. package/dist/components/layout/toolbar/tools/FileUploadTool.js +4 -3
  39. package/dist/components/layout/toolbar/tools/FirstPageTool.js +9 -5
  40. package/dist/components/layout/toolbar/tools/InputPageTool.js +4 -3
  41. package/dist/components/layout/toolbar/tools/LastPageTool.js +9 -5
  42. package/dist/components/layout/toolbar/tools/NextPageTool.js +4 -3
  43. package/dist/components/layout/toolbar/tools/PreviousPageTool.js +4 -3
  44. package/dist/components/layout/toolbar/tools/PrintTool.js +4 -3
  45. package/dist/components/layout/toolbar/tools/RotateClockwiseTool.js +4 -3
  46. package/dist/components/layout/toolbar/tools/RotateCounterclockwiseTool.js +4 -3
  47. package/dist/components/layout/toolbar/tools/ThumbnailTool.js +4 -3
  48. package/dist/components/layout/toolbar/tools/ZoomInTool.js +4 -3
  49. package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +14 -13
  50. package/dist/components/layout/toolbar/tools/ZoomOutTool.js +4 -3
  51. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +6 -3
  52. package/dist/components/layout/toolbar/tools/defaults/RPVerticalBar.js +4 -3
  53. package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +4 -3
  54. package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +4 -3
  55. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +4 -3
  56. package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +4 -3
  57. package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +4 -3
  58. package/dist/components/page/AnnotationLayer.js +69 -72
  59. package/dist/components/page/CanvasLayer.js +4 -3
  60. package/dist/components/page/CustomElement.js +4 -3
  61. package/dist/components/page/DualPage.js +11 -5
  62. package/dist/components/page/DualPageWithCover.js +11 -5
  63. package/dist/components/page/RPPage.js +12 -6
  64. package/dist/components/page/SinglePage.js +11 -5
  65. package/dist/components/page/TextHighlightLayer.js +86 -178
  66. package/dist/components/page/TextLayer.js +125 -170
  67. package/dist/components/ui/LoadingIndicator.js +8 -7
  68. package/dist/contexts/DimensionPagesContext.js +6 -5
  69. package/dist/contexts/DropFileZoneContext.js +5 -4
  70. package/dist/contexts/ElementPageContext.js +6 -5
  71. package/dist/contexts/FileInputContext.js +6 -5
  72. package/dist/contexts/HighlightContext.js +10 -7
  73. package/dist/contexts/PagesRotateContext.js +6 -5
  74. package/dist/contexts/PaginationContext.js +6 -5
  75. package/dist/contexts/PrintContext.js +17 -16
  76. package/dist/contexts/RPDocumentContext.js +14 -13
  77. package/dist/contexts/RenderQueueProvider.js +6 -5
  78. package/dist/contexts/RotationContext.js +9 -8
  79. package/dist/contexts/SearchContext.js +8 -5
  80. package/dist/contexts/TextSelectionContext.js +191 -0
  81. package/dist/contexts/ThumbnailsContext.js +5 -4
  82. package/dist/contexts/ZoomContext.js +6 -5
  83. package/dist/main.js +116 -113
  84. package/dist/types/components/layout/sidebar/Thumbnail.d.ts +2 -2
  85. package/dist/types/contexts/RPDocumentContext.d.ts +1 -1
  86. package/dist/types/contexts/RenderQueueProvider.d.ts +1 -1
  87. package/dist/types/contexts/RenderedPagesCache.d.ts +2 -2
  88. package/dist/types/contexts/TextSelectionContext.d.ts +14 -0
  89. package/dist/types/main.d.ts +1 -1
  90. package/dist/types/utils/annotations.d.ts +2 -2
  91. package/dist/types/utils/geometryCache.d.ts +15 -0
  92. package/dist/types/utils/getThumbnailViewport.d.ts +2 -2
  93. package/dist/types/utils/glyphHitTest.d.ts +12 -0
  94. package/dist/types/utils/highlight.d.ts +5 -5
  95. package/dist/types/utils/hooks/useHighlight.d.ts +1 -1
  96. package/dist/types/utils/hooks/useLoadPdf.d.ts +2 -2
  97. package/dist/types/utils/hooks/useLoadWorker.d.ts +5 -1
  98. package/dist/types/utils/hooks/usePdfProperties.d.ts +1 -1
  99. package/dist/types/utils/hooks/useTextSelection.d.ts +12 -3
  100. package/dist/types/utils/link_service.d.ts +2 -3
  101. package/dist/types/utils/renderPage.d.ts +2 -2
  102. package/dist/types/utils/selectionUtils.d.ts +30 -0
  103. package/dist/types/utils/types.d.ts +5 -7
  104. package/dist/utils/geometryCache.js +32 -0
  105. package/dist/utils/glyphHitTest.js +29 -0
  106. package/dist/utils/highlight.js +184 -158
  107. package/dist/utils/hooks/useCopyText.js +60 -22
  108. package/dist/utils/hooks/useFileDownload.js +6 -5
  109. package/dist/utils/hooks/useHighlight.js +35 -33
  110. package/dist/utils/hooks/useLicense.js +26 -18
  111. package/dist/utils/hooks/useLoadPdf.js +102 -70
  112. package/dist/utils/hooks/useLoadWorker.js +4 -14
  113. package/dist/utils/hooks/usePageRotateContext.js +8 -7
  114. package/dist/utils/hooks/usePaginate.js +4 -3
  115. package/dist/utils/hooks/usePinch.js +11 -10
  116. package/dist/utils/hooks/usePresentPage.js +4 -3
  117. package/dist/utils/hooks/usePrint.js +74 -78
  118. package/dist/utils/hooks/useRotate.js +4 -3
  119. package/dist/utils/hooks/useScrollToPage.js +4 -3
  120. package/dist/utils/hooks/useSearch.js +18 -15
  121. package/dist/utils/hooks/useTextSelection.js +2 -73
  122. package/dist/utils/hooks/useThumbnail.js +18 -17
  123. package/dist/utils/hooks/useVirtualReactWindow.js +4 -3
  124. package/dist/utils/link_service.js +18 -19
  125. package/dist/utils/renderPage.js +1 -1
  126. package/dist/utils/selectionUtils.js +96 -0
  127. package/package.json +2 -3
  128. package/dist/RPLayout.module-b4b23e29.js +0 -14
  129. package/dist/types/utils/hooks/useFlickerSelectText.d.ts +0 -1
  130. package/dist/utils/hooks/useFlickerSelectText.js +0 -25
@@ -0,0 +1,29 @@
1
+ function x(g, s, i, u = 4) {
2
+ let e = 0;
3
+ for (let h = 0; h < g.runs.length; h++) {
4
+ const l = g.runs[h];
5
+ for (let n = 0; n < l.glyphs.length; n++) {
6
+ const t = l.glyphs[n];
7
+ if (s >= t.tightX && s <= t.tightX + t.tightWidth && i >= t.tightY && i <= t.tightY + t.tightHeight)
8
+ return { runIndex: h, glyphIndex: n, charIndex: e + n };
9
+ }
10
+ e += l.glyphs.length;
11
+ }
12
+ let c = 1 / 0, o = null;
13
+ e = 0;
14
+ for (let h = 0; h < g.runs.length; h++) {
15
+ const l = g.runs[h];
16
+ for (let n = 0; n < l.glyphs.length; n++) {
17
+ const t = l.glyphs[n];
18
+ if (t.flags === 2)
19
+ continue;
20
+ const f = t.x + t.width / 2, p = t.y + t.height / 2, d = Math.abs(s - f) + Math.abs(i - p), r = u / 2;
21
+ s >= t.x - r && s <= t.x + t.width + r && i >= t.y - r && i <= t.y + t.height + r && d < c && (c = d, o = { runIndex: h, glyphIndex: n, charIndex: e + n });
22
+ }
23
+ e += l.glyphs.length;
24
+ }
25
+ return o;
26
+ }
27
+ export {
28
+ x as glyphAt
29
+ };
@@ -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
  };
@@ -3,7 +3,8 @@ import { useCallback as a } from "react";
3
3
  import { useDownloadContext as s } from "../../contexts/DownloadContext.js";
4
4
  import "react/jsx-runtime";
5
5
  import "./useLoadPdf.js";
6
- import "pdfjs-dist";
6
+ import "@pdf-viewer/pdfium";
7
+ import "@pdf-viewer/pdfium/compat";
7
8
  import "../types.js";
8
9
  import "../../de_DE-a553b162.js";
9
10
  import "../getThumbnailViewport.js";
@@ -13,10 +14,10 @@ import "../appConsole.js";
13
14
  import "./usePdfProperties.js";
14
15
  import "../convertPdfDate.js";
15
16
  import "../formatFileSize.js";
16
- const i = ".pdf", d = (o) => URL.createObjectURL(o), l = async (o) => {
17
+ const i = ".pdf", d = (o) => URL.createObjectURL(o), p = async (o) => {
17
18
  const r = await (await fetch(o)).blob();
18
19
  return d(r);
19
- }, k = () => {
20
+ }, B = () => {
20
21
  const { filename: o, pdfSrc: e } = c(), { downloadFilename: r } = s(), m = (t) => {
21
22
  const n = r || t;
22
23
  return n.endsWith(i) ? n : `${n}${i}`;
@@ -25,9 +26,9 @@ const i = ".pdf", d = (o) => URL.createObjectURL(o), l = async (o) => {
25
26
  if (!o || !e)
26
27
  throw new Error("There is no PDF source to download");
27
28
  const t = document.createElement("a");
28
- t.href = await l(e), t.download = m(o), document.body.appendChild(t), t.click(), document.body.removeChild(t);
29
+ t.href = await p(e), t.download = m(o), document.body.appendChild(t), t.click(), document.body.removeChild(t);
29
30
  }, [o, e]) };
30
31
  };
31
32
  export {
32
- k as useFileDownload
33
+ B as useFileDownload
33
34
  };