@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,10 +1,9 @@
1
- import { useState as f, useMemo as d, useCallback as u, useEffect as b } from "react";
1
+ import { useState as f, useMemo as d, useCallback as m, useEffect as b } from "react";
2
2
  import { useDocumentContext as h } from "../../contexts/RPDocumentContext.js";
3
3
  import { getThumbnailViewport as P } from "../getThumbnailViewport.js";
4
4
  import "react/jsx-runtime";
5
5
  import "./useLoadPdf.js";
6
- import "@pdf-viewer/pdfium";
7
- import "@pdf-viewer/pdfium/compat";
6
+ import "pdfjs-dist";
8
7
  import "../types.js";
9
8
  import "../../de_DE-a553b162.js";
10
9
  import "../../contexts/ConfigContext.js";
@@ -13,21 +12,21 @@ import "../appConsole.js";
13
12
  import "./usePdfProperties.js";
14
13
  import "../convertPdfDate.js";
15
14
  import "../formatFileSize.js";
16
- const E = () => {
17
- const [a, s] = f({}), { pages: t } = h(), p = d(() => Object.keys(a).length, [a]), n = u(
18
- (i) => {
15
+ const D = () => {
16
+ const [r, s] = f({}), { pages: t } = h(), p = d(() => Object.keys(r).length, [r]), n = m(
17
+ (a) => {
19
18
  if (!t.size)
20
19
  return;
21
- const e = i > t.size ? t.size : i, c = Array.from(t.values()).slice(0, e).map((o) => {
22
- const { thumbnailViewport: r, scale: g } = P(o.page, o.defaultRotation);
20
+ const e = a > t.size ? t.size : a, c = Array.from(t.values()).slice(0, e).map((o) => {
21
+ const { thumbnailViewport: i, scale: g } = P(o.page, o.defaultRotation);
23
22
  return {
24
23
  scale: g,
25
24
  page: o.page,
26
25
  loading: !0,
27
- viewport: r,
26
+ viewport: i,
28
27
  defaultRotation: o.defaultRotation
29
28
  };
30
- }).reduce((o, r) => (o[r.page.pageNumber] = r, o), {});
29
+ }).reduce((o, i) => (o[i.page.pageNumber] = i, o), {});
31
30
  s(c);
32
31
  },
33
32
  [t]
@@ -35,14 +34,14 @@ const E = () => {
35
34
  b(() => {
36
35
  n(10);
37
36
  }, [n]);
38
- const l = u(
39
- (i) => {
37
+ const l = m(
38
+ (a) => {
40
39
  if (!t)
41
40
  return;
42
- const e = t.get(i);
43
- e && s((m) => ({
44
- ...m,
45
- [i]: {
41
+ const e = t.get(a);
42
+ e && s((u) => ({
43
+ ...u,
44
+ [a]: {
46
45
  loading: !0,
47
46
  page: e.page,
48
47
  viewport: e.thumbnailViewport,
@@ -53,8 +52,8 @@ const E = () => {
53
52
  },
54
53
  [t]
55
54
  );
56
- return { thumbnailPages: a, addPage: l, addToPage: n, thumbnailLength: p };
55
+ return { thumbnailPages: r, addPage: l, addToPage: n, thumbnailLength: p };
57
56
  };
58
57
  export {
59
- E as useThumbnail
58
+ D as useThumbnail
60
59
  };
@@ -12,8 +12,7 @@ import "../appConsole.js";
12
12
  import "../../contexts/InitialStateContext.js";
13
13
  import "../../contexts/RPDocumentContext.js";
14
14
  import "./useLoadPdf.js";
15
- import "@pdf-viewer/pdfium";
16
- import "@pdf-viewer/pdfium/compat";
15
+ import "pdfjs-dist";
17
16
  import "../getThumbnailViewport.js";
18
17
  import "../../contexts/ConfigContext.js";
19
18
  import "../../contexts/DocumentPasswordContext.js";
@@ -29,7 +28,7 @@ import "../../contexts/GlobalCurrentPage.js";
29
28
  import "../../contexts/EventCallbackContext.js";
30
29
  import "./useDebounce.js";
31
30
  import "../../contexts/PagesRotateContext.js";
32
- const lt = () => {
31
+ const ct = () => {
33
32
  const { viewMode: n } = G(), { scrollMode: c } = x(), { setColumnCount: f } = H(), { virtualScrollableElementRef: w } = M(), t = O(), l = m(() => t.heights.length, [t.heights]), o = m(() => c === C.HORIZONTAL_SCROLLING ? l : n === g.DUAL_PAGE || n === g.DUAL_PAGE_WITH_COVER ? 2 : 1, [n, c, c, l, w]), d = m(() => {
34
33
  if (n === g.DUAL_PAGE_WITH_COVER && t.widths.length > 0) {
35
34
  const i = [0, 0];
@@ -93,5 +92,5 @@ const lt = () => {
93
92
  };
94
93
  };
95
94
  export {
96
- lt as useVirtualReactWindow
95
+ ct as useVirtualReactWindow
97
96
  };
@@ -1,10 +1,10 @@
1
- var g = Object.defineProperty;
2
- var u = (n, e, t) => e in n ? g(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var a = (n, e, t) => (u(n, typeof e != "symbol" ? e + "" : e, t), t);
4
- class f {
1
+ var u = Object.defineProperty;
2
+ var c = (a, e, t) => e in a ? u(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
+ var n = (a, e, t) => (c(a, typeof e != "symbol" ? e + "" : e, t), t);
4
+ class p {
5
5
  constructor(e, t) {
6
- a(this, "externalLinkEnabled");
7
- a(this, "pdfDocument");
6
+ n(this, "externalLinkEnabled");
7
+ n(this, "pdfDocument");
8
8
  this.externalLinkEnabled = !0, this.pdfDocument = e, this.goToPage = t;
9
9
  }
10
10
  /**
@@ -46,7 +46,7 @@ class f {
46
46
  * @param {string|Array} _dest - The named, or explicit, PDF destination.
47
47
  */
48
48
  async goToDestination(e) {
49
- var i, s;
49
+ var i, s, g;
50
50
  let t, r;
51
51
  if (typeof e == "string" ? t = await ((i = this.pdfDocument) == null ? void 0 : i.getDestination(e)) : t = await e, !Array.isArray(t)) {
52
52
  console.error(
@@ -55,16 +55,17 @@ class f {
55
55
  return;
56
56
  }
57
57
  const [o] = t;
58
- if (o && typeof o == "object")
59
- try {
60
- r = (await ((s = this.pdfDocument) == null ? void 0 : s.getPageIndex(o)) || 0) + 1;
61
- } catch {
62
- console.error(
63
- `goToDestination: "${o}" is not a valid page reference, for dest="${e}".`
64
- );
65
- return;
66
- }
67
- else
58
+ if (o && typeof o == "object") {
59
+ if (r = (s = this.pdfDocument) == null ? void 0 : s.cachedPageNumber(o), !r)
60
+ try {
61
+ r = (await ((g = this.pdfDocument) == null ? void 0 : g.getPageIndex(o)) || 0) + 1;
62
+ } catch {
63
+ console.error(
64
+ `goToDestination: "${o}" is not a valid page reference, for dest="${e}".`
65
+ );
66
+ return;
67
+ }
68
+ } else
68
69
  Number.isInteger(o) && (r = o + 1);
69
70
  if (!r || r < 1 || r > this.pagesCount) {
70
71
  console.error(
@@ -133,5 +134,5 @@ class f {
133
134
  }
134
135
  }
135
136
  export {
136
- f as SimpleLinkService
137
+ p as SimpleLinkService
137
138
  };
@@ -1,4 +1,4 @@
1
- import { AnnotationMode as h } from "@pdf-viewer/pdfium/compat";
1
+ import { AnnotationMode as h } from "pdfjs-dist";
2
2
  const x = (e, t, s = {}) => {
3
3
  const { scale: i = 1, rotate: r = 0, renderForms: w = !1, interactiveForm: a = !0 } = s, c = t.getContext("2d", {
4
4
  desynchronized: !1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf-kit/viewer",
3
- "version": "0.0.0-experimental.4",
3
+ "version": "0.0.0-experimental.5",
4
4
  "private": false,
5
5
  "description": "A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.",
6
6
  "keywords": [
@@ -15,15 +15,22 @@
15
15
  "react-pdf-kit-viewer",
16
16
  "pdf-viewer-kit"
17
17
  ],
18
- "homepage": "https://www.react-pdf.dev",
18
+ "homepage": "https://www.react-pdf-kit.dev",
19
19
  "license": "See license section",
20
20
  "bugs": {
21
21
  "url": "https://github.com/react-pdf-kit/react-pdf-viewer/issues/new"
22
22
  },
23
- "author": "React PDF Viewer <david@react-pdf.dev>",
23
+ "author": "React PDF Viewer <support@react-pdf-kit.dev>",
24
24
  "type": "module",
25
25
  "main": "dist/main.js",
26
26
  "types": "dist/types/main.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "import": "./dist/main.js",
30
+ "types": "./dist/types/main.d.ts"
31
+ },
32
+ "./polyfills": "./dist/polyfills.js"
33
+ },
27
34
  "directories": {
28
35
  "lib": "lib"
29
36
  },
@@ -39,10 +46,10 @@
39
46
  "prepare": "husky"
40
47
  },
41
48
  "dependencies": {
42
- "@pdf-viewer/pdfium": "0.0.0-experimental.4",
43
49
  "@radix-ui/react-checkbox": "^1.3.3",
44
50
  "@radix-ui/react-popover": "^1.1.15",
45
51
  "@radix-ui/react-tooltip": "^1.2.8",
52
+ "pdfjs-dist": "5.4.530",
46
53
  "react-virtualized-auto-sizer": "^1.0.24",
47
54
  "react-window": "^1.8.10"
48
55
  },
@@ -60,6 +67,7 @@
60
67
  "@vitejs/plugin-react-swc": "^3.3.2",
61
68
  "ajv": "^8.17.1",
62
69
  "clsx": "^2.1.1",
70
+ "core-js": "^3.48.0",
63
71
  "eslint": "^8.44.0",
64
72
  "eslint-plugin-react-hooks": "^4.6.0",
65
73
  "eslint-plugin-react-refresh": "^0.4.1",
@@ -77,6 +85,7 @@
77
85
  "vite-plugin-lib-inject-css": "^2.1.1"
78
86
  },
79
87
  "peerDependencies": {
88
+ "pdfjs-dist": "5.4.530",
80
89
  "react": "^18.2.0 || ^19.0.0",
81
90
  "react-dom": "^18.2.0 || ^19.0.0"
82
91
  },
@@ -1,14 +0,0 @@
1
- const r = {
2
- "rp-layout": "_rp-layout_1o2z7_1",
3
- "rp-layout-wrapper": "_rp-layout-wrapper_1o2z7_5",
4
- "rp-content": "_rp-content_1o2z7_11",
5
- "rp-sidebar": "_rp-sidebar_1o2z7_18",
6
- "rp-pages": "_rp-pages_1o2z7_23",
7
- "rp-container": "_rp-container_1o2z7_29",
8
- "rp-loader": "_rp-loader_1o2z7_33",
9
- "rp-theme-variables": "_rp-theme-variables_1o2z7_37",
10
- "rp-dark-mode": "_rp-dark-mode_1o2z7_153"
11
- };
12
- export {
13
- r as c
14
- };
@@ -1,191 +0,0 @@
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
- };