@react-pdf-kit/viewer 0.0.0-experimental.4 → 0.0.0-experimental.5

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 (170) hide show
  1. package/dist/{Combination-479e39c6.js → Combination-136ff99c.js} +184 -187
  2. package/dist/RPLayout.module-b4b23e29.js +14 -0
  3. package/dist/assets/style.css +1 -1
  4. package/dist/assets/style.js +15 -15
  5. package/dist/components/RPConfig.js +16 -6
  6. package/dist/components/RPController.js +21 -26
  7. package/dist/components/RPDropFileZone.js +35 -29
  8. package/dist/components/RPPages.js +351 -360
  9. package/dist/components/RPProvider.js +20 -24
  10. package/dist/components/layout/LayoutContainer.js +1 -1
  11. package/dist/components/layout/LayoutWrapper.js +1 -1
  12. package/dist/components/layout/RPDefaultLayout.js +12 -13
  13. package/dist/components/layout/RPLayout.js +28 -28
  14. package/dist/components/layout/WrapperLayout.js +10 -11
  15. package/dist/components/layout/sidebar/RPSidebar.js +7 -8
  16. package/dist/components/layout/sidebar/Thumbnail.js +3 -4
  17. package/dist/components/layout/sidebar/Thumbnails.js +3 -4
  18. package/dist/components/layout/toolbar/DarkModeTool.js +4 -4
  19. package/dist/components/layout/toolbar/DocumentDialog.js +8 -9
  20. package/dist/components/layout/toolbar/DocumentProperties.js +6 -6
  21. package/dist/components/layout/toolbar/FileDownloadTool.js +9 -10
  22. package/dist/components/layout/toolbar/FileUploadTool.js +9 -10
  23. package/dist/components/layout/toolbar/FullScreenTool.js +6 -6
  24. package/dist/components/layout/toolbar/MenuItem.js +6 -6
  25. package/dist/components/layout/toolbar/MenuSeparator.js +6 -6
  26. package/dist/components/layout/toolbar/MostPageTool.js +9 -10
  27. package/dist/components/layout/toolbar/OtherTool.js +9 -10
  28. package/dist/components/layout/toolbar/Paginate.js +7 -8
  29. package/dist/components/layout/toolbar/PrintTool.js +9 -10
  30. package/dist/components/layout/toolbar/RPMenuItem.js +6 -6
  31. package/dist/components/layout/toolbar/RPMoreOptions.js +9 -10
  32. package/dist/components/layout/toolbar/RPToolbar.js +9 -12
  33. package/dist/components/layout/toolbar/RPToolbarEnd.js +9 -10
  34. package/dist/components/layout/toolbar/RotateTool.js +9 -10
  35. package/dist/components/layout/toolbar/ScrollModeTool.js +6 -6
  36. package/dist/components/layout/toolbar/SearchCloseButton.js +4 -4
  37. package/dist/components/layout/toolbar/SearchResultNavigator.js +7 -10
  38. package/dist/components/layout/toolbar/SearchTool.js +11 -14
  39. package/dist/components/layout/toolbar/SelectionModeTool.js +6 -6
  40. package/dist/components/layout/toolbar/ThumbnailTool.js +7 -8
  41. package/dist/components/layout/toolbar/ToolbarCustom.js +3 -4
  42. package/dist/components/layout/toolbar/ToolbarDefault.js +9 -12
  43. package/dist/components/layout/toolbar/ToolbarLayout.js +9 -12
  44. package/dist/components/layout/toolbar/ViewModeTool.js +6 -6
  45. package/dist/components/layout/toolbar/ZoomTool.js +9 -10
  46. package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +8 -9
  47. package/dist/components/layout/toolbar/tools/DualPageTool.js +4 -4
  48. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +13 -15
  49. package/dist/components/layout/toolbar/tools/FileDownloadTool.js +7 -8
  50. package/dist/components/layout/toolbar/tools/FileUploadTool.js +7 -8
  51. package/dist/components/layout/toolbar/tools/FirstPageTool.js +13 -15
  52. package/dist/components/layout/toolbar/tools/FullScreenTool.js +4 -4
  53. package/dist/components/layout/toolbar/tools/HorizontalScrollingTool.js +4 -4
  54. package/dist/components/layout/toolbar/tools/InputPageTool.js +7 -8
  55. package/dist/components/layout/toolbar/tools/LastPageTool.js +13 -15
  56. package/dist/components/layout/toolbar/tools/NextPageTool.js +7 -8
  57. package/dist/components/layout/toolbar/tools/PageScrollingTool.js +4 -4
  58. package/dist/components/layout/toolbar/tools/PreviousPageTool.js +7 -8
  59. package/dist/components/layout/toolbar/tools/PrintTool.js +7 -8
  60. package/dist/components/layout/toolbar/tools/RotateClockwiseTool.js +7 -8
  61. package/dist/components/layout/toolbar/tools/RotateCounterclockwiseTool.js +7 -8
  62. package/dist/components/layout/toolbar/tools/SelectionModeSwitcherTool.js +4 -4
  63. package/dist/components/layout/toolbar/tools/SinglePageTool.js +4 -4
  64. package/dist/components/layout/toolbar/tools/ThemeSwitcherTool.js +4 -4
  65. package/dist/components/layout/toolbar/tools/ThumbnailTool.js +7 -8
  66. package/dist/components/layout/toolbar/tools/VerticalScrollingTool.js +4 -4
  67. package/dist/components/layout/toolbar/tools/ZoomInTool.js +7 -8
  68. package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +19 -20
  69. package/dist/components/layout/toolbar/tools/ZoomOutTool.js +7 -8
  70. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +9 -12
  71. package/dist/components/layout/toolbar/tools/defaults/RPVerticalBar.js +7 -8
  72. package/dist/components/layout/toolbar/tools/more-options/DocumentProperties.js +6 -6
  73. package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +9 -10
  74. package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +9 -10
  75. package/dist/components/layout/toolbar/tools/more-options/FullScreenTool.js +6 -6
  76. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +9 -10
  77. package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +9 -10
  78. package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +9 -10
  79. package/dist/components/layout/toolbar/tools/more-options/ScrollModeTool.js +6 -6
  80. package/dist/components/layout/toolbar/tools/more-options/SelectionModeTool.js +6 -6
  81. package/dist/components/layout/toolbar/tools/more-options/ViewModeTool.js +6 -6
  82. package/dist/components/page/AnnotationLayer.js +65 -66
  83. package/dist/components/page/CanvasLayer.js +3 -4
  84. package/dist/components/page/CustomElement.js +3 -4
  85. package/dist/components/page/DualPage.js +5 -11
  86. package/dist/components/page/DualPageWithCover.js +5 -11
  87. package/dist/components/page/RPPage.js +6 -12
  88. package/dist/components/page/SinglePage.js +5 -11
  89. package/dist/components/page/TextHighlightLayer.js +178 -86
  90. package/dist/components/page/TextLayer.js +170 -125
  91. package/dist/components/ui/Checkbox.js +2 -2
  92. package/dist/components/ui/DropDown.js +6 -6
  93. package/dist/components/ui/LoadingIndicator.js +7 -8
  94. package/dist/components/ui/RPTooltip.js +411 -197
  95. package/dist/contexts/ConfigContext.js +5 -4
  96. package/dist/contexts/DimensionPagesContext.js +5 -6
  97. package/dist/contexts/DropFileZoneContext.js +4 -5
  98. package/dist/contexts/ElementPageContext.js +5 -6
  99. package/dist/contexts/FileInputContext.js +5 -6
  100. package/dist/contexts/HighlightContext.js +7 -10
  101. package/dist/contexts/LayoutDropFileZoneContext.js +11 -0
  102. package/dist/contexts/PagesRotateContext.js +5 -6
  103. package/dist/contexts/PaginationContext.js +5 -6
  104. package/dist/contexts/PrintContext.js +16 -17
  105. package/dist/contexts/RPDocumentContext.js +13 -14
  106. package/dist/contexts/RenderQueueProvider.js +5 -6
  107. package/dist/contexts/RotationContext.js +8 -9
  108. package/dist/contexts/SearchContext.js +5 -8
  109. package/dist/contexts/ThumbnailsContext.js +4 -5
  110. package/dist/contexts/ZoomContext.js +5 -6
  111. package/dist/floating-ui.react-dom-5ec29bd6.js +1327 -0
  112. package/dist/index-61f59539.js +1198 -0
  113. package/dist/{index-ada501c4.js → index-655864a7.js} +1 -1
  114. package/dist/{index-113053cf.js → index-c0faa594.js} +2 -2
  115. package/dist/{index-23911b43.js → index-e3ee9457.js} +6 -6
  116. package/dist/main.js +15 -15
  117. package/dist/polyfills.js +8055 -0
  118. package/dist/types/components/layout/sidebar/Thumbnail.d.ts +2 -2
  119. package/dist/types/contexts/LayoutDropFileZoneContext.d.ts +9 -0
  120. package/dist/types/contexts/RPDocumentContext.d.ts +1 -1
  121. package/dist/types/contexts/RenderQueueProvider.d.ts +1 -1
  122. package/dist/types/contexts/RenderedPagesCache.d.ts +2 -2
  123. package/dist/types/main.d.ts +1 -1
  124. package/dist/types/utils/annotations.d.ts +2 -2
  125. package/dist/types/utils/getThumbnailViewport.d.ts +2 -2
  126. package/dist/types/utils/highlight.d.ts +5 -5
  127. package/dist/types/utils/hooks/useDropFileZone.d.ts +5 -0
  128. package/dist/types/utils/hooks/useFlickerSelectText.d.ts +1 -0
  129. package/dist/types/utils/hooks/useHighlight.d.ts +1 -1
  130. package/dist/types/utils/hooks/useLoadPdf.d.ts +2 -2
  131. package/dist/types/utils/hooks/useLoadWorker.d.ts +1 -5
  132. package/dist/types/utils/hooks/usePdfProperties.d.ts +1 -1
  133. package/dist/types/utils/hooks/useTextSelection.d.ts +3 -12
  134. package/dist/types/utils/link_service.d.ts +3 -2
  135. package/dist/types/utils/renderPage.d.ts +2 -2
  136. package/dist/types/utils/types.d.ts +8 -5
  137. package/dist/utils/highlight.js +158 -184
  138. package/dist/utils/hooks/useCopyText.js +22 -60
  139. package/dist/utils/hooks/useDropFileZone.js +12 -0
  140. package/dist/utils/hooks/useFileDownload.js +5 -6
  141. package/dist/utils/hooks/useFlickerSelectText.js +25 -0
  142. package/dist/utils/hooks/useHighlight.js +33 -35
  143. package/dist/utils/hooks/useLicense.js +1 -1
  144. package/dist/utils/hooks/useLoadPdf.js +70 -95
  145. package/dist/utils/hooks/useLoadWorker.js +14 -4
  146. package/dist/utils/hooks/usePageRotateContext.js +7 -8
  147. package/dist/utils/hooks/usePaginate.js +3 -4
  148. package/dist/utils/hooks/usePinch.js +10 -11
  149. package/dist/utils/hooks/usePresentPage.js +3 -4
  150. package/dist/utils/hooks/usePrint.js +55 -54
  151. package/dist/utils/hooks/useRotate.js +3 -4
  152. package/dist/utils/hooks/useScrollToPage.js +3 -4
  153. package/dist/utils/hooks/useSearch.js +15 -18
  154. package/dist/utils/hooks/useTextSelection.js +73 -2
  155. package/dist/utils/hooks/useThumbnail.js +17 -18
  156. package/dist/utils/hooks/useVirtualReactWindow.js +3 -4
  157. package/dist/utils/link_service.js +19 -18
  158. package/dist/utils/renderPage.js +1 -1
  159. package/package.json +13 -4
  160. package/dist/RPLayout.module-7766e0b4.js +0 -14
  161. package/dist/contexts/TextSelectionContext.js +0 -191
  162. package/dist/index-535ad364.js +0 -983
  163. package/dist/index-d0f0aa9a.js +0 -1542
  164. package/dist/types/contexts/TextSelectionContext.d.ts +0 -14
  165. package/dist/types/utils/geometryCache.d.ts +0 -15
  166. package/dist/types/utils/glyphHitTest.d.ts +0 -12
  167. package/dist/types/utils/selectionUtils.d.ts +0 -30
  168. package/dist/utils/geometryCache.js +0 -32
  169. package/dist/utils/glyphHitTest.js +0 -29
  170. package/dist/utils/selectionUtils.js +0 -96
@@ -1,14 +1,11 @@
1
- import { jsx as d } from "react/jsx-runtime";
2
- import { useState as $, useEffect as k, useMemo as y } from "react";
3
- import { useDocumentContext as _ } from "../../contexts/RPDocumentContext.js";
4
- import { useHighlightContext as L } from "../../contexts/HighlightContext.js";
5
- import { normalizeSingleKeyword as M } from "./searchHighlight.js";
6
- import { isMatchEntireWord as T } from "../../utils/highlight.js";
7
- import { geometryCache as w } from "../../utils/geometryCache.js";
8
- import { rectsForRange as G } from "../../utils/selectionUtils.js";
1
+ import { jsx as k, Fragment as J } from "react/jsx-runtime";
2
+ import { useState as A, useRef as N, useEffect as H, useMemo as Q } from "react";
3
+ import { useDocumentContext as U } from "../../contexts/RPDocumentContext.js";
4
+ import { useHighlightContext as V } from "../../contexts/HighlightContext.js";
5
+ import { normalizeSingleKeyword as Y, sortHighlightPosition as Z, unwrap as tt } from "./searchHighlight.js";
6
+ import { isMatchEntireWord as et } from "../../utils/highlight.js";
9
7
  import "../../utils/hooks/useLoadPdf.js";
10
- import "@pdf-viewer/pdfium";
11
- import "@pdf-viewer/pdfium/compat";
8
+ import "pdfjs-dist";
12
9
  import "../../utils/types.js";
13
10
  import "../../de_DE-a553b162.js";
14
11
  import "../../utils/getThumbnailViewport.js";
@@ -21,86 +18,181 @@ import "../../utils/formatFileSize.js";
21
18
  import "../../utils/hooks/useHighlight.js";
22
19
  import "../../utils/charators.js";
23
20
  import "../../utils/const.js";
24
- const C = {
25
- "rp-text-highlight-layer": "_rp-text-highlight-layer_1gqf0_1",
26
- "rp-text-highlight": "_rp-text-highlight_1gqf0_1"
27
- }, Z = ({ pageNumber: n, viewport: p }) => {
28
- const i = n - 1, { pages: h } = _(), { highlightKeywords: s } = L(), [r, m] = $(null);
29
- k(() => {
30
- const e = w.get(i);
31
- if (e) {
32
- m(e);
33
- return;
34
- }
35
- const o = h.get(n);
36
- if (!o)
37
- return;
38
- const t = o.page.getViewport({ scale: (p.width > 0, 1) }), g = o.page.getPageGeometry(t);
39
- w.set(i, g), m(g);
40
- }, [h, n, i, p]);
41
- const c = y(() => s ? s.map((e) => {
42
- var o, t;
21
+ const nt = {
22
+ "rp-text-highlight": "_rp-text-highlight_jdkf8_1"
23
+ }, Tt = ({ pageNumber: w, viewport: O }) => {
24
+ const [$, v] = A(), { pages: R } = U(), { highlightKeywords: d } = V(), M = !0, C = N(null), [P, q] = A(null), [_, b] = A([]);
25
+ H(() => {
26
+ C.current && q(C.current.parentElement);
27
+ }, [C]), H(() => {
28
+ (async () => {
29
+ const e = R.get(w);
30
+ if (!e || !C.current)
31
+ return;
32
+ const n = await e.page.getTextContent();
33
+ v(n);
34
+ })();
35
+ }, [R, w]);
36
+ const j = Q(() => d ? d.map((t) => {
37
+ var e, n;
43
38
  return {
44
- ...M(e.keyword, (o = e.options) == null ? void 0 : o.matchCase, (t = e.options) == null ? void 0 : t.wholeWords),
45
- color: e.highlightColor
39
+ ...Y(t.keyword, (e = t.options) == null ? void 0 : e.matchCase, (n = t.options) == null ? void 0 : n.wholeWords),
40
+ color: t.highlightColor
46
41
  };
47
- }) : [], [s]), a = y(() => {
48
- if (!r || !c.length)
49
- return [];
50
- if (r.totalCharCount === 0)
51
- return [];
52
- const e = r.runs.map((t) => t.text).join(""), o = [];
53
- for (const t of c) {
54
- if (!t.keyword.trim())
55
- continue;
56
- const g = t.regExp.flags.indexOf("g") === -1 ? new RegExp(t.regExp, `${t.regExp.flags}g`) : t.regExp;
57
- let l;
58
- for (; (l = g.exec(e)) !== null; ) {
59
- if (t.wholeWords && !T(e, l.index, l[0].length))
60
- continue;
61
- const x = E(r, l.index), f = E(r, l.index + l[0].length - 1);
62
- if (x >= 0 && f >= 0) {
63
- const u = G(r, x, f);
64
- u.length > 0 && o.push({
65
- rects: u,
66
- color: t.color ?? "rgba(255, 235, 59, 0.4)",
67
- keyword: t.keyword
68
- });
69
- }
42
+ }) : [], [d]);
43
+ function D(t, e) {
44
+ if (!t)
45
+ return;
46
+ const n = `[data-rp="page-${e}-textLayer"]`;
47
+ return new Promise((r) => {
48
+ const s = t.querySelector(n);
49
+ if (s) {
50
+ r(s);
51
+ return;
70
52
  }
53
+ new MutationObserver((i, c) => {
54
+ const l = t.querySelector(n);
55
+ l && (r(l), c.disconnect());
56
+ }).observe(t, { childList: !0, subtree: !0 });
57
+ });
58
+ }
59
+ function K(t) {
60
+ return new Promise((e) => {
61
+ const n = t.querySelectorAll(
62
+ '[data-rp="rp-text-layer-text"]'
63
+ );
64
+ if (n.length) {
65
+ e(Array.from(n));
66
+ return;
67
+ }
68
+ new MutationObserver((s, o) => {
69
+ const i = t.querySelectorAll(
70
+ ".rp-text-layer-text"
71
+ );
72
+ i.length && (e(Array.from(i)), o.disconnect());
73
+ }).observe(t, { childList: !0, subtree: !0 });
74
+ });
75
+ }
76
+ const W = (t, e, n, r) => {
77
+ var I;
78
+ const s = document.createRange(), o = n.firstChild;
79
+ if (!o || o.nodeType !== Node.TEXT_NODE)
80
+ return null;
81
+ const i = ((I = o.textContent) == null ? void 0 : I.length) ?? 0, c = r[0].charIdxInSpan, l = r.length === 1 ? c : r[r.length - 1].charIdxInSpan;
82
+ if (c > i || l + 1 > i)
83
+ return null;
84
+ s.setStart(o, c), s.setEnd(o, l + 1);
85
+ const h = document.createElement("span");
86
+ h.style.width = "auto", s.surroundContents(h);
87
+ const a = h.getBoundingClientRect(), f = t.getBoundingClientRect(), m = f.height, p = f.width, x = 100 * (a.left - f.left) / p, E = 100 * (a.top - f.top) / m, S = 100 * a.height / m, g = 100 * a.width / p;
88
+ return tt(h), {
89
+ keywordStr: e,
90
+ left: x,
91
+ top: E,
92
+ height: S,
93
+ width: g,
94
+ pageHeight: m,
95
+ pageWidth: p
96
+ };
97
+ };
98
+ async function z(t, e) {
99
+ const n = await D(P, t);
100
+ if (!n)
101
+ return;
102
+ const r = await K(n);
103
+ if (r.length) {
104
+ const s = r.map((i) => i.tagName === "BR" ? " " : i.textContent).reduce(
105
+ (i, c, l) => i.concat(
106
+ c.split("").map((h, a) => ({
107
+ char: h,
108
+ charIdxInSpan: a,
109
+ spanIdx: l
110
+ }))
111
+ ),
112
+ [
113
+ {
114
+ char: "",
115
+ charIdxInSpan: 0,
116
+ spanIdx: 0
117
+ }
118
+ ]
119
+ ).slice(1), o = B(n, e, r, s);
120
+ b(o);
71
121
  }
72
- return o;
73
- }, [r, c]);
74
- return a.length === 0 ? null : /* @__PURE__ */ d("div", { "data-rp": `page-${n}-textHighlightLayer`, className: C["rp-text-highlight-layer"], children: a.map(
75
- (e, o) => e.rects.map((t, g) => /* @__PURE__ */ d(
76
- "div",
77
- {
78
- className: C["rp-text-highlight"],
79
- style: {
80
- position: "absolute",
81
- left: `${t.x}px`,
82
- top: `${t.y}px`,
83
- width: `${t.width}px`,
84
- height: `${t.height}px`,
85
- backgroundColor: e.color
86
- }
87
- },
88
- `${o}-${g}`
89
- ))
90
- ) });
91
- };
92
- function E(n, p) {
93
- let i = 0, h = 0;
94
- for (const s of n.runs) {
95
- const r = s.text.length, m = s.glyphs.length;
96
- if (p < i + r) {
97
- const c = p - i;
98
- return h + Math.min(c, m - 1);
99
- }
100
- i += r, h += m;
101
122
  }
102
- return Math.max(0, h - 1);
103
- }
123
+ const B = (t, e, n, r) => {
124
+ const s = e.length;
125
+ if (!r.length || !s)
126
+ return [];
127
+ const o = [], i = r.map((c) => c.char).join("");
128
+ return j.forEach((c) => {
129
+ const { keyword: l, regExp: h, wholeWords: a, color: f } = c, m = l;
130
+ if (!m.trim())
131
+ return;
132
+ const p = h.flags.indexOf("g") === -1 ? new RegExp(h, `${h.flags}g`) : h;
133
+ let x;
134
+ const E = [];
135
+ for (; (x = p.exec(i)) !== null; )
136
+ a && !et(i, x.index, x[0].length) || E.push({
137
+ keyword: p,
138
+ startIndex: x.index,
139
+ endIndex: p.lastIndex
140
+ });
141
+ const S = E.map((g) => ({
142
+ keyword: g.keyword,
143
+ indexes: r.slice(g.startIndex, g.endIndex),
144
+ color: f
145
+ }));
146
+ for (const g of S) {
147
+ const I = g.indexes.reduce(
148
+ (u, y) => (u[y.spanIdx] = (u[y.spanIdx] || []).concat([y]), u),
149
+ {}
150
+ );
151
+ for (const u of Object.values(I))
152
+ if (u.length !== 1 || u[0].char.trim() !== "") {
153
+ const y = u, F = n[y[0].spanIdx], T = W(
154
+ t,
155
+ m,
156
+ F,
157
+ y
158
+ );
159
+ if (T) {
160
+ const { left: X, top: G } = T;
161
+ if (o.find((L) => L.left === X && L.top === G))
162
+ continue;
163
+ o.push({ ...T, highlightColor: g.color });
164
+ }
165
+ }
166
+ }
167
+ }), o.sort(Z), o;
168
+ };
169
+ return H(() => {
170
+ (async () => {
171
+ if (!d || d.length === 0) {
172
+ b([]);
173
+ return;
174
+ }
175
+ try {
176
+ await z(w, d);
177
+ } catch (e) {
178
+ console.error(e);
179
+ }
180
+ })();
181
+ }, [M, d, w, $, O]), /* @__PURE__ */ k(J, { children: /* @__PURE__ */ k("div", { ref: C, "data-rp": `page-${w}-textHighlightLayer`, children: _.map((t, e) => /* @__PURE__ */ k(
182
+ "div",
183
+ {
184
+ className: nt["rp-text-highlight"],
185
+ style: {
186
+ top: `${t.top}%`,
187
+ left: `${t.left}%`,
188
+ width: `${t.width}%`,
189
+ height: `${t.height}%`,
190
+ backgroundColor: t.highlightColor
191
+ }
192
+ },
193
+ e
194
+ )) }) });
195
+ };
104
196
  export {
105
- Z as TextHighlightLayer
197
+ Tt as TextHighlightLayer
106
198
  };
@@ -1,156 +1,201 @@
1
- import { jsxs as T, jsx as f } from "react/jsx-runtime";
2
- import { useRef as D, useState as E, useEffect as L, useMemo as d, useCallback as y } from "react";
3
- import { useDocumentContext as j } from "../../contexts/RPDocumentContext.js";
4
- import { useSearchContext as A } from "../../contexts/SearchContext.js";
5
- import { useTextSelectionContext as G } from "../../contexts/TextSelectionContext.js";
6
- import { useSelectionModeContext as U } from "../../contexts/SelectionModeContext.js";
7
- import { useZoomContext as V } from "../../contexts/ZoomContext.js";
8
- import { geometryCache as Z } from "../../utils/geometryCache.js";
9
- import { rectsForRange as k } from "../../utils/selectionUtils.js";
10
- import { SelectionMode as F } from "../../utils/types.js";
1
+ import { jsx as B } from "react/jsx-runtime";
2
+ import { useRef as g, useState as H, useMemo as P, useCallback as _, useEffect as w } from "react";
3
+ import { useDocumentContext as G } from "../../contexts/RPDocumentContext.js";
4
+ import * as J from "pdfjs-dist";
5
+ import { resetDivs as $, highlightMatches as U } from "../../utils/highlight.js";
6
+ import { useSearchContext as V } from "../../contexts/SearchContext.js";
11
7
  import "../../utils/hooks/useLoadPdf.js";
12
- import "@pdf-viewer/pdfium";
13
- import "@pdf-viewer/pdfium/compat";
8
+ import "../../utils/types.js";
9
+ import "../../de_DE-a553b162.js";
14
10
  import "../../utils/getThumbnailViewport.js";
15
11
  import "../../contexts/ConfigContext.js";
16
12
  import "../../contexts/DocumentPasswordContext.js";
17
13
  import "../../utils/appConsole.js";
18
- import "../../de_DE-a553b162.js";
19
14
  import "../../utils/hooks/usePdfProperties.js";
20
15
  import "../../utils/convertPdfDate.js";
21
16
  import "../../utils/formatFileSize.js";
22
- import "../../utils/hooks/useSearch.js";
23
- import "../../utils/highlight.js";
24
17
  import "../../utils/charators.js";
18
+ import "../../utils/hooks/useSearch.js";
25
19
  import "../../contexts/VirtualScrollContext.js";
26
20
  import "../../contexts/ScrollModeContext.js";
27
21
  import "../../contexts/InitialStateContext.js";
28
- import "../../PaginationContext-9217cab4.js";
22
+ import "../../contexts/ZoomContext.js";
23
+ import "../../utils/constants.js";
24
+ import "../../utils/getZoomLevel.js";
25
+ import "../../contexts/LayoutContainerContext.js";
26
+ import "../../contexts/ViewModeContext.js";
27
+ import "../../contexts/RotationContext.js";
29
28
  import "../../contexts/GlobalCurrentPage.js";
30
29
  import "../../contexts/EventCallbackContext.js";
31
- import "../../contexts/ViewModeContext.js";
30
+ import "../../utils/hooks/useDebounce.js";
31
+ import "../../PaginationContext-9217cab4.js";
32
32
  import "../../contexts/VirtualGridContext.js";
33
33
  import "../../utils/smoothScrollTo.js";
34
34
  import "../../contexts/DimensionPagesContext.js";
35
- import "../../utils/constants.js";
36
35
  import "../../contexts/PagesRotateContext.js";
37
- import "../../contexts/RotationContext.js";
38
- import "../../utils/getZoomLevel.js";
39
- import "../../contexts/LayoutContainerContext.js";
40
- import "../../utils/hooks/useDebounce.js";
41
36
  import "../../contexts/SmoothScrollContext.js";
42
37
  import "../../utils/getScrollDistance.js";
43
38
  import "../../utils/calculatePage.js";
44
39
  import "../../utils/getWordPositionInPage.js";
45
- import "../../utils/glyphHitTest.js";
46
- const O = "_selecting_tl66q_12", h = {
47
- "rp-text-layer": "_rp-text-layer_tl66q_1",
48
- selecting: O,
49
- "rp-selection-highlight": "_rp-selection-highlight_tl66q_17",
50
- "rp-search-highlight": "_rp-search-highlight_tl66q_24",
51
- "rp-search-highlight-active": "_rp-search-highlight-active_tl66q_32",
52
- "rp-text-interaction-overlay": "_rp-text-interaction-overlay_tl66q_40"
53
- }, At = (a) => {
54
- const { pageNumber: o } = a, e = o - 1, { pages: p } = j(), { currentZoom: c } = V(), { matches: i, currentMatch: l } = A(), { selectionMode: g } = U(), {
55
- handlePointerDown: _,
56
- handlePointerMove: v,
57
- handlePointerUp: M,
58
- getPageSelectionRects: $,
59
- selectionVersion: w
60
- } = G(), m = D(null), [u, P] = E(null), n = g === F.TEXT;
61
- L(() => {
62
- const t = p.get(o);
63
- if (!t)
64
- return;
65
- const r = t.page.getViewport({ scale: c }), s = t.page.getPageGeometry(r);
66
- Z.set(e, s), P(s);
67
- }, [p, o, e, c]);
68
- const R = d(() => $(e), [$, e, w]), x = d(() => i.filter((t) => t.pageIndex === e), [i, e]), b = d(() => {
69
- if (!x.length || !u)
70
- return [];
71
- const t = [];
72
- for (const [r, s] of x.entries()) {
73
- const C = X(u, s), N = l !== null && l.pageIndex === e && l.pageMatchIdx === s.pageMatchIdx;
74
- C.length > 0 && t.push({ rects: C, isActive: N, matchIndex: r });
75
- }
76
- return t;
77
- }, [x, u, l, e]), I = y(
78
- (t) => {
79
- !n || !m.current || _(e, t, m.current);
80
- },
81
- [n, _, e]
82
- ), S = y(
83
- (t) => {
84
- !n || !m.current || v(e, t, m.current);
40
+ const X = "_selecting_1553j_14", z = "_markedContent_1553j_37", a = {
41
+ "rp-text-layer": "_rp-text-layer_1553j_1",
42
+ selecting: X,
43
+ markedContent: z,
44
+ "rp-text-layer-text": "_rp-text-layer-text_1553j_61"
45
+ }, Ae = (k) => {
46
+ const { pageNumber: d } = k, { pages: R } = G(), i = g(null), { matches: O, currentMatch: v } = V(), [D, A] = H(
47
+ []
48
+ ), p = g(), h = g(), L = g([]), y = P(() => O.filter((r) => r.pageIndex === d - 1), [O, d]), T = _(
49
+ (r, t, e = !1) => {
50
+ if (e && $(r, t), !y.length) {
51
+ L.current = [], A([]);
52
+ return;
53
+ }
54
+ const n = U(y, r, t);
55
+ A(n);
85
56
  },
86
- [n, v, e]
87
- ), q = y(() => {
88
- n && M();
89
- }, [n, M]);
90
- return /* @__PURE__ */ T(
57
+ [y]
58
+ ), x = g(), C = g(!1), E = _(() => Array.from(document.querySelectorAll('[data-rp$="-textLayer"]')), []);
59
+ w(() => ((() => {
60
+ if (x.current)
61
+ return;
62
+ x.current = new AbortController();
63
+ const { signal: t } = x.current, e = () => {
64
+ E().forEach((o) => {
65
+ const s = o.querySelector(".endOfContent");
66
+ s && (o.appendChild(s), s.style.width = "", s.style.height = "", o.classList.remove(a.selecting));
67
+ });
68
+ };
69
+ document.addEventListener(
70
+ "pointerdown",
71
+ () => {
72
+ C.current = !0;
73
+ },
74
+ { signal: t }
75
+ ), document.addEventListener(
76
+ "pointerup",
77
+ () => {
78
+ C.current = !1, e();
79
+ },
80
+ { signal: t }
81
+ ), window.addEventListener(
82
+ "blur",
83
+ () => {
84
+ C.current = !1, e();
85
+ },
86
+ { signal: t }
87
+ ), document.addEventListener(
88
+ "keyup",
89
+ () => {
90
+ C.current || e();
91
+ },
92
+ { signal: t }
93
+ );
94
+ let n = null;
95
+ document.addEventListener(
96
+ "selectionchange",
97
+ () => {
98
+ var M, j;
99
+ const o = document.getSelection();
100
+ if (!o)
101
+ return;
102
+ if (o.rangeCount === 0) {
103
+ e();
104
+ return;
105
+ }
106
+ const s = /* @__PURE__ */ new Set();
107
+ for (let c = 0; c < o.rangeCount; c++) {
108
+ const f = o.getRangeAt(c);
109
+ E().forEach((N) => {
110
+ f.intersectsNode(N) && !s.has(N) && s.add(N);
111
+ });
112
+ }
113
+ E().forEach((c) => {
114
+ if (s.has(c))
115
+ c.classList.add(a.selecting);
116
+ else {
117
+ const f = c.querySelector(".endOfContent");
118
+ f && (c.appendChild(f), f.style.width = "", f.style.height = "", c.classList.remove(a.selecting));
119
+ }
120
+ });
121
+ const l = o.getRangeAt(0);
122
+ let u = n && (l.compareBoundaryPoints(Range.END_TO_END, n) === 0 || l.compareBoundaryPoints(Range.START_TO_END, n) === 0) ? l.startContainer : l.endContainer;
123
+ u.nodeType === Node.TEXT_NODE && (u = u.parentNode);
124
+ const m = (M = u.parentElement) == null ? void 0 : M.closest(
125
+ a["rp-text-layer"]
126
+ ), S = m == null ? void 0 : m.querySelector(".endOfContent");
127
+ S && m && (S.style.width = m.style.width, S.style.height = m.style.height, (j = u.parentElement) == null || j.insertBefore(S, u.nextSibling)), n = l.cloneRange();
128
+ },
129
+ { signal: t }
130
+ );
131
+ })(), () => {
132
+ var t;
133
+ (t = x.current) == null || t.abort(), x.current = void 0;
134
+ }), [E]);
135
+ const q = _(() => {
136
+ i.current && i.current.classList.add(a.selecting);
137
+ }, []), I = _(() => {
138
+ i.current && i.current.classList.remove(a.selecting);
139
+ }, []);
140
+ return w(() => {
141
+ if (L.current.forEach((e) => {
142
+ e.classList.remove("selected");
143
+ }), !D.length || !v || v.pageIndex !== d - 1)
144
+ return;
145
+ const r = y.findIndex(
146
+ (e) => JSON.stringify(e) === JSON.stringify(v)
147
+ );
148
+ if (r === -1)
149
+ return;
150
+ const t = D.filter((e) => e.index === r);
151
+ t.length && (L.current = t.map((e) => e.element), t.forEach((e) => {
152
+ e.element.classList.add("selected");
153
+ }));
154
+ }, [v, D, y]), w(() => {
155
+ const r = R.get(d);
156
+ if (!r || !i.current)
157
+ return;
158
+ const t = i.current;
159
+ return p.current && p.current.cancel(), r.page.getTextContent().then((e) => {
160
+ const n = r.page.getViewport({ scale: 1 });
161
+ return p.current = new J.TextLayer({
162
+ viewport: n,
163
+ textContentSource: e,
164
+ container: t
165
+ }), h.current = e, t && (t.innerText = ""), p.current.render();
166
+ }).then(() => {
167
+ var s, l;
168
+ [].slice.call(t.children).forEach((b) => {
169
+ b.classList.add(a["rp-text-layer-text"]), b.setAttribute("data-rp", "rp-text-layer-text");
170
+ });
171
+ const n = (s = p.current) == null ? void 0 : s.textDivs;
172
+ n && h.current && T(h.current, n);
173
+ const o = document.createElement("div");
174
+ o.className = "endOfContent", (l = i.current) == null || l.appendChild(o);
175
+ }).catch(() => {
176
+ }), () => {
177
+ var e;
178
+ (e = p.current) == null || e.cancel();
179
+ };
180
+ }, [R, d]), w(() => {
181
+ var e;
182
+ [].slice.call(i.current.children).forEach((n) => {
183
+ n.classList.add(a["rp-text-layer-text"]);
184
+ });
185
+ const t = (e = p.current) == null ? void 0 : e.textDivs;
186
+ t && h.current && T(h.current, t, !0);
187
+ }, [T]), /* @__PURE__ */ B(
91
188
  "div",
92
189
  {
93
190
  "data-rp-text-layer": !0,
94
- "data-rp": `page-${o}-textLayer`,
95
- className: h["rp-text-layer"],
96
- children: [
97
- R.map((t, r) => /* @__PURE__ */ f(
98
- "div",
99
- {
100
- className: h["rp-selection-highlight"],
101
- style: {
102
- position: "absolute",
103
- left: `${t.x}px`,
104
- top: `${t.y}px`,
105
- width: `${t.width}px`,
106
- height: `${t.height}px`
107
- }
108
- },
109
- `sel-${r}`
110
- )),
111
- b.map(
112
- (t) => t.rects.map((r, s) => /* @__PURE__ */ f(
113
- "div",
114
- {
115
- className: t.isActive ? h["rp-search-highlight-active"] : h["rp-search-highlight"],
116
- style: {
117
- position: "absolute",
118
- left: `${r.x}px`,
119
- top: `${r.y}px`,
120
- width: `${r.width}px`,
121
- height: `${r.height}px`
122
- }
123
- },
124
- `search-${t.matchIndex}-${s}`
125
- ))
126
- ),
127
- /* @__PURE__ */ f(
128
- "div",
129
- {
130
- ref: m,
131
- className: h["rp-text-interaction-overlay"],
132
- style: {
133
- position: "absolute",
134
- inset: 0,
135
- cursor: n ? "text" : "default"
136
- },
137
- onPointerDown: I,
138
- onPointerMove: S,
139
- onPointerUp: q
140
- }
141
- )
142
- ]
191
+ "data-rp": `page-${d}-textLayer`,
192
+ className: a["rp-text-layer"],
193
+ ref: i,
194
+ onMouseDown: q,
195
+ onMouseUp: I
143
196
  }
144
197
  );
145
198
  };
146
- function X(a, o) {
147
- let e = 0, p = 0, c = 0;
148
- for (let i = 0; i < a.runs.length; i++) {
149
- const g = a.runs[i].glyphs.length;
150
- o.start.idx === i && (e = c + o.start.offset), o.end.idx === i && (p = c + o.end.offset - 1), c += g;
151
- }
152
- return p < e ? [] : k(a, e, p);
153
- }
154
199
  export {
155
- At as TextLayer
200
+ Ae as TextLayer
156
201
  };
@@ -1,7 +1,7 @@
1
1
  import { jsx as i, jsxs as w, Fragment as U } from "react/jsx-runtime";
2
2
  import * as s from "react";
3
- import { c as z, a as B, P as y, b as S, d as G, f as K } from "../../index-113053cf.js";
4
- import { u as X } from "../../index-ada501c4.js";
3
+ import { c as z, a as B, P as y, b as S, d as G, f as K } from "../../index-c0faa594.js";
4
+ import { u as X } from "../../index-655864a7.js";
5
5
  import { CheckIcon as J } from "../icons/CheckIcon.js";
6
6
  import "react-dom";
7
7
  function Q(e) {
@@ -1,13 +1,13 @@
1
1
  import { jsxs as p, jsx as d } from "react/jsx-runtime";
2
- import { R as l, T as c, P as _, C as m } from "../../index-535ad364.js";
2
+ import { R as l, T as c, P as _, C as m } from "../../index-61f59539.js";
3
3
  import { c as A } from "../../clsx-0c6e471a.js";
4
4
  import "react";
5
- import "../../index-113053cf.js";
5
+ import "../../index-c0faa594.js";
6
6
  import "react-dom";
7
- import "../../index-23911b43.js";
8
- import "../../Combination-479e39c6.js";
9
- import "../../index-d0f0aa9a.js";
10
- import "../../index-ada501c4.js";
7
+ import "../../index-e3ee9457.js";
8
+ import "../../Combination-136ff99c.js";
9
+ import "../../floating-ui.react-dom-5ec29bd6.js";
10
+ import "../../index-655864a7.js";
11
11
  const F = "_slideDownAndFade_1vzkq_1", w = "_slideLeftAndFade_1vzkq_1", f = "_slideUpAndFade_1vzkq_1", g = "_slideRightAndFade_1vzkq_1", h = {
12
12
  "rp-dropdown-content": "_rp-dropdown-content_1vzkq_1",
13
13
  slideDownAndFade: F,