@react-pdf-kit/viewer 0.0.0-experimental.2 → 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 (81) hide show
  1. package/dist/{Combination-17ab8af1.js → Combination-479e39c6.js} +187 -184
  2. package/dist/RPLayout.module-7766e0b4.js +14 -0
  3. package/dist/assets/style.css +1 -1
  4. package/dist/assets/style.js +15 -15
  5. package/dist/components/RPController.js +24 -20
  6. package/dist/components/RPPages.js +322 -321
  7. package/dist/components/RPProvider.js +22 -19
  8. package/dist/components/layout/LayoutContainer.js +1 -1
  9. package/dist/components/layout/LayoutWrapper.js +1 -1
  10. package/dist/components/layout/RPDefaultLayout.js +7 -5
  11. package/dist/components/layout/RPLayout.js +7 -5
  12. package/dist/components/layout/toolbar/DocumentDialog.js +1 -1
  13. package/dist/components/layout/toolbar/DocumentProperties.js +2 -2
  14. package/dist/components/layout/toolbar/FileDownloadTool.js +2 -2
  15. package/dist/components/layout/toolbar/FileUploadTool.js +2 -2
  16. package/dist/components/layout/toolbar/FullScreenTool.js +2 -2
  17. package/dist/components/layout/toolbar/MenuItem.js +2 -2
  18. package/dist/components/layout/toolbar/MenuSeparator.js +2 -2
  19. package/dist/components/layout/toolbar/MostPageTool.js +2 -2
  20. package/dist/components/layout/toolbar/OtherTool.js +2 -2
  21. package/dist/components/layout/toolbar/PrintTool.js +2 -2
  22. package/dist/components/layout/toolbar/RPMenuItem.js +2 -2
  23. package/dist/components/layout/toolbar/RPMoreOptions.js +2 -2
  24. package/dist/components/layout/toolbar/RPToolbar.js +6 -4
  25. package/dist/components/layout/toolbar/RPToolbarEnd.js +2 -2
  26. package/dist/components/layout/toolbar/RotateTool.js +2 -2
  27. package/dist/components/layout/toolbar/ScrollModeTool.js +2 -2
  28. package/dist/components/layout/toolbar/SearchResultNavigator.js +4 -2
  29. package/dist/components/layout/toolbar/SearchTool.js +6 -4
  30. package/dist/components/layout/toolbar/SelectionModeTool.js +2 -2
  31. package/dist/components/layout/toolbar/ToolbarDefault.js +6 -4
  32. package/dist/components/layout/toolbar/ToolbarLayout.js +6 -4
  33. package/dist/components/layout/toolbar/ViewModeTool.js +2 -2
  34. package/dist/components/layout/toolbar/ZoomTool.js +2 -2
  35. package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +1 -1
  36. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +9 -6
  37. package/dist/components/layout/toolbar/tools/FirstPageTool.js +9 -6
  38. package/dist/components/layout/toolbar/tools/LastPageTool.js +9 -6
  39. package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +2 -2
  40. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +6 -4
  41. package/dist/components/layout/toolbar/tools/more-options/DocumentProperties.js +2 -2
  42. package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +2 -2
  43. package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +2 -2
  44. package/dist/components/layout/toolbar/tools/more-options/FullScreenTool.js +2 -2
  45. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +2 -2
  46. package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +2 -2
  47. package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +2 -2
  48. package/dist/components/layout/toolbar/tools/more-options/ScrollModeTool.js +2 -2
  49. package/dist/components/layout/toolbar/tools/more-options/SelectionModeTool.js +2 -2
  50. package/dist/components/layout/toolbar/tools/more-options/ViewModeTool.js +2 -2
  51. package/dist/components/page/AnnotationLayer.js +52 -52
  52. package/dist/components/page/DualPage.js +9 -4
  53. package/dist/components/page/DualPageWithCover.js +9 -4
  54. package/dist/components/page/RPPage.js +9 -4
  55. package/dist/components/page/SinglePage.js +9 -4
  56. package/dist/components/page/TextHighlightLayer.js +84 -177
  57. package/dist/components/page/TextLayer.js +124 -170
  58. package/dist/components/ui/DropDown.js +2 -2
  59. package/dist/contexts/HighlightContext.js +8 -6
  60. package/dist/contexts/SearchContext.js +6 -4
  61. package/dist/contexts/TextSelectionContext.js +191 -0
  62. package/dist/{index-11f3cd64.js → index-535ad364.js} +1 -1
  63. package/dist/main.js +116 -114
  64. package/dist/types/contexts/TextSelectionContext.d.ts +14 -0
  65. package/dist/types/utils/geometryCache.d.ts +15 -0
  66. package/dist/types/utils/glyphHitTest.d.ts +12 -0
  67. package/dist/types/utils/hooks/useTextSelection.d.ts +12 -3
  68. package/dist/types/utils/selectionUtils.d.ts +30 -0
  69. package/dist/utils/geometryCache.js +32 -0
  70. package/dist/utils/glyphHitTest.js +29 -0
  71. package/dist/utils/highlight.js +184 -158
  72. package/dist/utils/hooks/useCopyText.js +60 -22
  73. package/dist/utils/hooks/useHighlight.js +35 -33
  74. package/dist/utils/hooks/useLicense.js +1 -1
  75. package/dist/utils/hooks/useSearch.js +4 -2
  76. package/dist/utils/hooks/useTextSelection.js +2 -73
  77. package/dist/utils/selectionUtils.js +96 -0
  78. package/package.json +2 -2
  79. package/dist/RPLayout.module-b4b23e29.js +0 -14
  80. package/dist/types/utils/hooks/useFlickerSelectText.d.ts +0 -1
  81. package/dist/utils/hooks/useFlickerSelectText.js +0 -25
@@ -1,202 +1,156 @@
1
- import { jsx as I } 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 { TextLayerBuilder as J } from "@pdf-viewer/pdfium/compat";
5
- import { resetDivs as $, highlightMatches as U } from "../../utils/highlight.js";
6
- import { useSearchContext as V } from "../../contexts/SearchContext.js";
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";
7
11
  import "../../utils/hooks/useLoadPdf.js";
8
12
  import "@pdf-viewer/pdfium";
9
- import "../../utils/types.js";
10
- import "../../de_DE-a553b162.js";
13
+ import "@pdf-viewer/pdfium/compat";
11
14
  import "../../utils/getThumbnailViewport.js";
12
15
  import "../../contexts/ConfigContext.js";
13
16
  import "../../contexts/DocumentPasswordContext.js";
14
17
  import "../../utils/appConsole.js";
18
+ import "../../de_DE-a553b162.js";
15
19
  import "../../utils/hooks/usePdfProperties.js";
16
20
  import "../../utils/convertPdfDate.js";
17
21
  import "../../utils/formatFileSize.js";
18
- import "../../utils/charators.js";
19
22
  import "../../utils/hooks/useSearch.js";
23
+ import "../../utils/highlight.js";
24
+ import "../../utils/charators.js";
20
25
  import "../../contexts/VirtualScrollContext.js";
21
26
  import "../../contexts/ScrollModeContext.js";
22
27
  import "../../contexts/InitialStateContext.js";
23
- import "../../contexts/ZoomContext.js";
24
- import "../../utils/constants.js";
25
- import "../../utils/getZoomLevel.js";
26
- import "../../contexts/LayoutContainerContext.js";
27
- import "../../contexts/ViewModeContext.js";
28
- import "../../contexts/RotationContext.js";
28
+ import "../../PaginationContext-9217cab4.js";
29
29
  import "../../contexts/GlobalCurrentPage.js";
30
30
  import "../../contexts/EventCallbackContext.js";
31
- import "../../utils/hooks/useDebounce.js";
32
- import "../../PaginationContext-9217cab4.js";
31
+ import "../../contexts/ViewModeContext.js";
33
32
  import "../../contexts/VirtualGridContext.js";
34
33
  import "../../utils/smoothScrollTo.js";
35
34
  import "../../contexts/DimensionPagesContext.js";
35
+ import "../../utils/constants.js";
36
36
  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";
37
41
  import "../../contexts/SmoothScrollContext.js";
38
42
  import "../../utils/getScrollDistance.js";
39
43
  import "../../utils/calculatePage.js";
40
44
  import "../../utils/getWordPositionInPage.js";
41
- const X = "_selecting_1553j_14", z = "_markedContent_1553j_37", a = {
42
- "rp-text-layer": "_rp-text-layer_1553j_1",
43
- selecting: X,
44
- markedContent: z,
45
- "rp-text-layer-text": "_rp-text-layer-text_1553j_61"
46
- }, ke = (j) => {
47
- const { pageNumber: d } = j, { pages: R } = G(), i = g(null), { matches: O, currentMatch: v } = V(), [D, A] = H(
48
- []
49
- ), p = g(), h = g(), L = g([]), y = P(() => O.filter((r) => r.pageIndex === d - 1), [O, d]), T = _(
50
- (r, t, e = !1) => {
51
- if (e && $(r, t), !y.length) {
52
- L.current = [], A([]);
53
- return;
54
- }
55
- const n = U(y, r, t);
56
- A(n);
57
- },
58
- [y]
59
- ), x = g(), C = g(!1), E = _(() => Array.from(document.querySelectorAll('[data-rp$="-textLayer"]')), []);
60
- w(() => ((() => {
61
- if (x.current)
62
- return;
63
- x.current = new AbortController();
64
- const { signal: t } = x.current, e = () => {
65
- E().forEach((o) => {
66
- const s = o.querySelector(".endOfContent");
67
- s && (o.appendChild(s), s.style.width = "", s.style.height = "", o.classList.remove(a.selecting));
68
- });
69
- };
70
- document.addEventListener(
71
- "pointerdown",
72
- () => {
73
- C.current = !0;
74
- },
75
- { signal: t }
76
- ), document.addEventListener(
77
- "pointerup",
78
- () => {
79
- C.current = !1, e();
80
- },
81
- { signal: t }
82
- ), window.addEventListener(
83
- "blur",
84
- () => {
85
- C.current = !1, e();
86
- },
87
- { signal: t }
88
- ), document.addEventListener(
89
- "keyup",
90
- () => {
91
- C.current || e();
92
- },
93
- { signal: t }
94
- );
95
- let n = null;
96
- document.addEventListener(
97
- "selectionchange",
98
- () => {
99
- var M, k;
100
- const o = document.getSelection();
101
- if (!o)
102
- return;
103
- if (o.rangeCount === 0) {
104
- e();
105
- return;
106
- }
107
- const s = /* @__PURE__ */ new Set();
108
- for (let c = 0; c < o.rangeCount; c++) {
109
- const f = o.getRangeAt(c);
110
- E().forEach((N) => {
111
- f.intersectsNode(N) && !s.has(N) && s.add(N);
112
- });
113
- }
114
- E().forEach((c) => {
115
- if (s.has(c))
116
- c.classList.add(a.selecting);
117
- else {
118
- const f = c.querySelector(".endOfContent");
119
- f && (c.appendChild(f), f.style.width = "", f.style.height = "", c.classList.remove(a.selecting));
120
- }
121
- });
122
- const l = o.getRangeAt(0);
123
- let u = n && (l.compareBoundaryPoints(Range.END_TO_END, n) === 0 || l.compareBoundaryPoints(Range.START_TO_END, n) === 0) ? l.startContainer : l.endContainer;
124
- u.nodeType === Node.TEXT_NODE && (u = u.parentNode);
125
- const m = (M = u.parentElement) == null ? void 0 : M.closest(
126
- a["rp-text-layer"]
127
- ), S = m == null ? void 0 : m.querySelector(".endOfContent");
128
- S && m && (S.style.width = m.style.width, S.style.height = m.style.height, (k = u.parentElement) == null || k.insertBefore(S, u.nextSibling)), n = l.cloneRange();
129
- },
130
- { signal: t }
131
- );
132
- })(), () => {
133
- var t;
134
- (t = x.current) == null || t.abort(), x.current = void 0;
135
- }), [E]);
136
- const q = _(() => {
137
- i.current && i.current.classList.add(a.selecting);
138
- }, []), B = _(() => {
139
- i.current && i.current.classList.remove(a.selecting);
140
- }, []);
141
- return w(() => {
142
- if (L.current.forEach((e) => {
143
- e.classList.remove("selected");
144
- }), !D.length || !v || v.pageIndex !== d - 1)
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)
145
64
  return;
146
- const r = y.findIndex(
147
- (e) => JSON.stringify(e) === JSON.stringify(v)
148
- );
149
- if (r === -1)
150
- return;
151
- const t = D.filter((e) => e.index === r);
152
- t.length && (L.current = t.map((e) => e.element), t.forEach((e) => {
153
- e.element.classList.add("selected");
154
- }));
155
- }, [v, D, y]), w(() => {
156
- const r = R.get(d);
157
- if (!r || !i.current)
158
- return;
159
- const t = i.current;
160
- return p.current && p.current.cancel(), r.page.getTextContent().then((e) => {
161
- const n = r.page.getViewport({ scale: 1 });
162
- return p.current = new J({
163
- viewport: n,
164
- textContentSource: e,
165
- container: t
166
- }), h.current = e, t && (t.innerText = ""), p.current.render();
167
- }).then(() => {
168
- var s, l;
169
- [].slice.call(t.children).forEach((b) => {
170
- b.classList.add(a["rp-text-layer-text"]), b.setAttribute("data-rp", "rp-text-layer-text");
171
- });
172
- const n = (s = p.current) == null ? void 0 : s.textDivs;
173
- n && h.current && T(h.current, n);
174
- const o = document.createElement("div");
175
- o.className = "endOfContent", (l = i.current) == null || l.appendChild(o);
176
- }).catch(() => {
177
- }), () => {
178
- var e;
179
- (e = p.current) == null || e.cancel();
180
- };
181
- }, [R, d]), w(() => {
182
- var e;
183
- [].slice.call(i.current.children).forEach((n) => {
184
- n.classList.add(a["rp-text-layer-text"]);
185
- });
186
- const t = (e = p.current) == null ? void 0 : e.textDivs;
187
- t && h.current && T(h.current, t, !0);
188
- }, [T]), /* @__PURE__ */ I(
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);
85
+ },
86
+ [n, v, e]
87
+ ), q = y(() => {
88
+ n && M();
89
+ }, [n, M]);
90
+ return /* @__PURE__ */ T(
189
91
  "div",
190
92
  {
191
93
  "data-rp-text-layer": !0,
192
- "data-rp": `page-${d}-textLayer`,
193
- className: a["rp-text-layer"],
194
- ref: i,
195
- onMouseDown: q,
196
- onMouseUp: B
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
+ ]
197
143
  }
198
144
  );
199
145
  };
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
+ }
200
154
  export {
201
- ke as TextLayer
155
+ At as TextLayer
202
156
  };
@@ -1,11 +1,11 @@
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-11f3cd64.js";
2
+ import { R as l, T as c, P as _, C as m } from "../../index-535ad364.js";
3
3
  import { c as A } from "../../clsx-0c6e471a.js";
4
4
  import "react";
5
5
  import "../../index-113053cf.js";
6
6
  import "react-dom";
7
7
  import "../../index-23911b43.js";
8
- import "../../Combination-17ab8af1.js";
8
+ import "../../Combination-479e39c6.js";
9
9
  import "../../index-d0f0aa9a.js";
10
10
  import "../../index-ada501c4.js";
11
11
  const F = "_slideDownAndFade_1vzkq_1", w = "_slideLeftAndFade_1vzkq_1", f = "_slideUpAndFade_1vzkq_1", g = "_slideRightAndFade_1vzkq_1", h = {
@@ -16,10 +16,12 @@ import "../utils/convertPdfDate.js";
16
16
  import "../utils/formatFileSize.js";
17
17
  import "../utils/highlight.js";
18
18
  import "../utils/charators.js";
19
- const o = g(void 0), k = ({ children: t }) => {
20
- const { pdf: i } = s(), { highlight: r, highlightMatches: e, highlightKeywords: h, clear: m } = c(i);
21
- return /* @__PURE__ */ p(o.Provider, { value: { highlight: r, highlightMatches: e, highlightKeywords: h, clear: m }, children: t });
22
- }, q = () => {
19
+ import "../utils/selectionUtils.js";
20
+ import "../utils/geometryCache.js";
21
+ const o = g(void 0), z = ({ children: t }) => {
22
+ const { pdf: i } = s(), { highlight: r, highlightMatches: e, highlightKeywords: m, clear: h } = c(i);
23
+ return /* @__PURE__ */ p(o.Provider, { value: { highlight: r, highlightMatches: e, highlightKeywords: m, clear: h }, children: t });
24
+ }, A = () => {
23
25
  const t = n(o);
24
26
  if (!t)
25
27
  throw new Error("useHighlightContext must be used within a HighlightProvider");
@@ -27,6 +29,6 @@ const o = g(void 0), k = ({ children: t }) => {
27
29
  };
28
30
  export {
29
31
  o as HighlightContext,
30
- k as HighlightProvider,
31
- q as useHighlightContext
32
+ z as HighlightProvider,
33
+ A as useHighlightContext
32
34
  };
@@ -5,6 +5,8 @@ import "../utils/types.js";
5
5
  import "../de_DE-a553b162.js";
6
6
  import "../utils/highlight.js";
7
7
  import "../utils/charators.js";
8
+ import "../utils/selectionUtils.js";
9
+ import "../utils/geometryCache.js";
8
10
  import "./VirtualScrollContext.js";
9
11
  import "./ScrollModeContext.js";
10
12
  import "../utils/appConsole.js";
@@ -53,7 +55,7 @@ const o = x({
53
55
  searchOptions: {},
54
56
  setSearchOptions: (t) => t,
55
57
  setCurrentMatchPosition: (t) => t
56
- }), pt = ({
58
+ }), ct = ({
57
59
  children: t,
58
60
  initialSearch: i
59
61
  }) => {
@@ -89,9 +91,9 @@ const o = x({
89
91
  children: t
90
92
  }
91
93
  );
92
- }, mt = () => C(o);
94
+ }, at = () => C(o);
93
95
  export {
94
96
  o as SearchContext,
95
- pt as SearchProvider,
96
- mt as useSearchContext
97
+ ct as SearchProvider,
98
+ at as useSearchContext
97
99
  };
@@ -0,0 +1,191 @@
1
+ import { jsx as J } from "react/jsx-runtime";
2
+ import { createContext as K, useContext as O, useRef as l, useState as Q, useCallback as f, useEffect as _, useMemo as B } from "react";
3
+ import { glyphAt as q } from "../utils/glyphHitTest.js";
4
+ import { rectsForRange as A, textForRange as E, expandToWordBoundary as L, expandToLineBoundary as $ } from "../utils/selectionUtils.js";
5
+ import { geometryCache as k } from "../utils/geometryCache.js";
6
+ import { useEventCallbackContext as ee } from "./EventCallbackContext.js";
7
+ import { useZoomContext as te } from "./ZoomContext.js";
8
+ import "../utils/types.js";
9
+ import "../de_DE-a553b162.js";
10
+ import "../utils/appConsole.js";
11
+ import "./InitialStateContext.js";
12
+ import "./RPDocumentContext.js";
13
+ import "../utils/hooks/useLoadPdf.js";
14
+ import "@pdf-viewer/pdfium";
15
+ import "@pdf-viewer/pdfium/compat";
16
+ import "../utils/getThumbnailViewport.js";
17
+ import "./ConfigContext.js";
18
+ import "./DocumentPasswordContext.js";
19
+ import "../utils/hooks/usePdfProperties.js";
20
+ import "../utils/convertPdfDate.js";
21
+ import "../utils/formatFileSize.js";
22
+ import "../utils/constants.js";
23
+ import "../utils/getZoomLevel.js";
24
+ import "./LayoutContainerContext.js";
25
+ import "./ViewModeContext.js";
26
+ import "./RotationContext.js";
27
+ import "./GlobalCurrentPage.js";
28
+ import "../utils/hooks/useDebounce.js";
29
+ const ne = {
30
+ handlePointerDown: () => {
31
+ },
32
+ handlePointerMove: () => {
33
+ },
34
+ handlePointerUp: () => {
35
+ },
36
+ getPageSelectionRects: () => [],
37
+ isSelecting: !1,
38
+ selectedText: "",
39
+ selectionVersion: 0,
40
+ clearSelection: () => {
41
+ }
42
+ }, z = K(ne), Ve = () => O(z), Fe = ({ children: G }) => {
43
+ const { onTextSelect: C } = ee(), { currentZoom: P } = te(), h = l(null), R = l(null), g = l(!1), y = l(/* @__PURE__ */ new Map()), S = l(""), m = l(0), F = l(0), D = l({ x: 0, y: 0 }), I = l(0), w = l(0), M = l(-1), [N, V] = Q(0), T = f(
44
+ (e, n) => {
45
+ const o = n.getBoundingClientRect();
46
+ return { x: e.clientX - o.left, y: e.clientY - o.top };
47
+ },
48
+ []
49
+ ), b = f(
50
+ (e, n) => {
51
+ const o = /* @__PURE__ */ new Map();
52
+ let a = "";
53
+ if (e.pageIndex === n.pageIndex) {
54
+ const i = k.get(e.pageIndex);
55
+ if (i) {
56
+ const c = A(i, e.charIndex, n.charIndex);
57
+ c.length > 0 && o.set(e.pageIndex, c), a = E(i, e.charIndex, n.charIndex);
58
+ }
59
+ } else {
60
+ const i = e.pageIndex < n.pageIndex, c = Math.min(e.pageIndex, n.pageIndex), t = Math.max(e.pageIndex, n.pageIndex);
61
+ for (let r = c; r <= t; r++) {
62
+ const u = k.get(r);
63
+ if (!u || u.totalCharCount === 0)
64
+ continue;
65
+ const d = u.totalCharCount - 1;
66
+ let x, p;
67
+ r === e.pageIndex ? (x = e.charIndex, p = i ? d : 0) : r === n.pageIndex ? (x = i ? 0 : d, p = n.charIndex) : (x = 0, p = d);
68
+ const s = A(u, x, p);
69
+ s.length > 0 && o.set(r, s);
70
+ const j = E(u, x, p);
71
+ a && j && (a += `
72
+ `), a += j;
73
+ }
74
+ }
75
+ y.current = o, S.current = a, V((i) => i + 1);
76
+ },
77
+ []
78
+ ), X = f(
79
+ (e, n, o) => {
80
+ const { x: a, y: i } = T(n, o), c = k.get(e);
81
+ if (!c)
82
+ return;
83
+ const t = q(c, a, i);
84
+ if (!t) {
85
+ h.current = null, R.current = null, y.current = /* @__PURE__ */ new Map(), S.current = "", V((s) => s + 1);
86
+ return;
87
+ }
88
+ const r = Date.now(), u = Math.abs(n.clientX - D.current.x), d = Math.abs(n.clientY - D.current.y);
89
+ r - F.current < 500 && u < 5 && d < 5 ? m.current = m.current % 3 + 1 : m.current = 1, F.current = r, D.current = { x: n.clientX, y: n.clientY };
90
+ let x, p;
91
+ if (m.current === 2) {
92
+ const s = L(c, t.charIndex);
93
+ x = { pageIndex: e, charIndex: s.start }, p = { pageIndex: e, charIndex: s.end }, I.current = s.start, w.current = s.end, M.current = e;
94
+ } else if (m.current === 3) {
95
+ const s = $(c, t.charIndex);
96
+ x = { pageIndex: e, charIndex: s.start }, p = { pageIndex: e, charIndex: s.end }, I.current = s.start, w.current = s.end, M.current = e;
97
+ } else
98
+ x = { pageIndex: e, charIndex: t.charIndex }, p = { pageIndex: e, charIndex: t.charIndex };
99
+ h.current = x, R.current = p, g.current = !0, o.setPointerCapture(n.pointerId), b(x, p);
100
+ },
101
+ [T, b]
102
+ ), Y = f(
103
+ (e, n, o) => {
104
+ if (!g.current || !h.current)
105
+ return;
106
+ const { x: a, y: i } = T(n, o), c = k.get(e);
107
+ if (!c)
108
+ return;
109
+ const t = q(c, a, i);
110
+ if (!t)
111
+ return;
112
+ let r = t.charIndex;
113
+ const u = h.current;
114
+ if (m.current === 2 && e === M.current) {
115
+ const d = L(c, t.charIndex);
116
+ t.charIndex < I.current ? (r = d.start, h.current = { pageIndex: u.pageIndex, charIndex: w.current }) : (r = d.end, h.current = { pageIndex: u.pageIndex, charIndex: I.current });
117
+ } else if (m.current === 3 && e === M.current) {
118
+ const d = $(c, t.charIndex);
119
+ t.charIndex < I.current ? (r = d.start, h.current = { pageIndex: u.pageIndex, charIndex: w.current }) : (r = d.end, h.current = { pageIndex: u.pageIndex, charIndex: I.current });
120
+ }
121
+ R.current = { pageIndex: e, charIndex: r }, b(h.current, R.current);
122
+ },
123
+ [T, b]
124
+ ), Z = f(() => {
125
+ if (!g.current)
126
+ return;
127
+ g.current = !1;
128
+ const e = S.current;
129
+ if (e && C) {
130
+ const n = [];
131
+ for (const [o, a] of y.current.entries()) {
132
+ const i = o + 1, c = document.querySelector(`[data-rp="page-${i}"]`), t = c == null ? void 0 : c.getBoundingClientRect();
133
+ n.push({
134
+ pageNumber: i,
135
+ pageBasedBoundingRects: a.map((r) => ({
136
+ left: r.x,
137
+ bottom: r.y + r.height,
138
+ width: r.width,
139
+ height: r.height
140
+ })),
141
+ pageDimension: {
142
+ width: (t == null ? void 0 : t.width) ?? 0,
143
+ height: (t == null ? void 0 : t.height) ?? 0
144
+ },
145
+ pagePositionInWindow: {
146
+ x: (t == null ? void 0 : t.left) ?? 0,
147
+ y: (t == null ? void 0 : t.top) ?? 0
148
+ }
149
+ });
150
+ }
151
+ n.sort((o, a) => o.pageNumber - a.pageNumber), C({
152
+ text: e,
153
+ pageSelections: n
154
+ });
155
+ } else
156
+ C && !e && C(null);
157
+ }, [C]), v = f(() => {
158
+ h.current = null, R.current = null, g.current = !1, y.current = /* @__PURE__ */ new Map(), S.current = "", V((e) => e + 1);
159
+ }, []), U = l(P);
160
+ _(() => {
161
+ P !== U.current && (U.current = P, v());
162
+ }, [P, v]);
163
+ const W = f(
164
+ (e) => y.current.get(e) ?? [],
165
+ []
166
+ ), H = B(
167
+ () => ({
168
+ handlePointerDown: X,
169
+ handlePointerMove: Y,
170
+ handlePointerUp: Z,
171
+ getPageSelectionRects: W,
172
+ isSelecting: g.current,
173
+ selectedText: S.current,
174
+ selectionVersion: N,
175
+ clearSelection: v
176
+ }),
177
+ [
178
+ X,
179
+ Y,
180
+ Z,
181
+ W,
182
+ N,
183
+ v
184
+ ]
185
+ );
186
+ return /* @__PURE__ */ J(z.Provider, { value: H, children: G });
187
+ };
188
+ export {
189
+ Fe as TextSelectionProvider,
190
+ Ve as useTextSelectionContext
191
+ };
@@ -3,7 +3,7 @@ import K from "react";
3
3
  import { c as re, a as k, g as pe, f as ye, P as L, b as g, d as ae, j as Te, i as _n } from "./index-113053cf.js";
4
4
  import { jsx as s } from "react/jsx-runtime";
5
5
  import { a as ge, u as me, D as Rn } from "./index-23911b43.js";
6
- import { h as In, u as En, F as Sn, R as bn, P as Pn } from "./Combination-17ab8af1.js";
6
+ import { h as In, u as En, F as Sn, R as bn, P as Pn } from "./Combination-479e39c6.js";
7
7
  import { c as xe, A as Dn, C as yn, a as Tn, R as xn } from "./index-d0f0aa9a.js";
8
8
  function Ae(e) {
9
9
  const o = e + "CollectionProvider", [n, t] = re(o), [r, c] = n(