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

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 (138) hide show
  1. package/dist/RPLayout.module-b4b23e29.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 +18 -6
  5. package/dist/components/RPController.js +21 -26
  6. package/dist/components/RPDropFileZone.js +34 -28
  7. package/dist/components/RPPages.js +352 -361
  8. package/dist/components/RPProvider.js +20 -24
  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 +6 -7
  12. package/dist/components/layout/RPLayout.js +22 -22
  13. package/dist/components/layout/WrapperLayout.js +10 -11
  14. package/dist/components/layout/sidebar/RPSidebar.js +3 -4
  15. package/dist/components/layout/sidebar/Thumbnail.js +3 -4
  16. package/dist/components/layout/sidebar/Thumbnails.js +3 -4
  17. package/dist/components/layout/toolbar/DocumentDialog.js +5 -6
  18. package/dist/components/layout/toolbar/FileDownloadTool.js +3 -4
  19. package/dist/components/layout/toolbar/FileUploadTool.js +3 -4
  20. package/dist/components/layout/toolbar/MostPageTool.js +3 -4
  21. package/dist/components/layout/toolbar/OtherTool.js +3 -4
  22. package/dist/components/layout/toolbar/Paginate.js +3 -4
  23. package/dist/components/layout/toolbar/PrintTool.js +3 -4
  24. package/dist/components/layout/toolbar/RPMoreOptions.js +3 -4
  25. package/dist/components/layout/toolbar/RPToolbar.js +3 -6
  26. package/dist/components/layout/toolbar/RPToolbarEnd.js +3 -4
  27. package/dist/components/layout/toolbar/RotateTool.js +3 -4
  28. package/dist/components/layout/toolbar/SearchResultNavigator.js +3 -6
  29. package/dist/components/layout/toolbar/SearchTool.js +5 -8
  30. package/dist/components/layout/toolbar/ThumbnailTool.js +3 -4
  31. package/dist/components/layout/toolbar/ToolbarCustom.js +3 -4
  32. package/dist/components/layout/toolbar/ToolbarDefault.js +3 -6
  33. package/dist/components/layout/toolbar/ToolbarLayout.js +3 -6
  34. package/dist/components/layout/toolbar/ZoomTool.js +3 -4
  35. package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +3 -4
  36. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +7 -9
  37. package/dist/components/layout/toolbar/tools/FileDownloadTool.js +3 -4
  38. package/dist/components/layout/toolbar/tools/FileUploadTool.js +3 -4
  39. package/dist/components/layout/toolbar/tools/FirstPageTool.js +7 -9
  40. package/dist/components/layout/toolbar/tools/InputPageTool.js +3 -4
  41. package/dist/components/layout/toolbar/tools/LastPageTool.js +7 -9
  42. package/dist/components/layout/toolbar/tools/NextPageTool.js +3 -4
  43. package/dist/components/layout/toolbar/tools/PreviousPageTool.js +3 -4
  44. package/dist/components/layout/toolbar/tools/PrintTool.js +3 -4
  45. package/dist/components/layout/toolbar/tools/RotateClockwiseTool.js +3 -4
  46. package/dist/components/layout/toolbar/tools/RotateCounterclockwiseTool.js +3 -4
  47. package/dist/components/layout/toolbar/tools/ThumbnailTool.js +3 -4
  48. package/dist/components/layout/toolbar/tools/ZoomInTool.js +3 -4
  49. package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +13 -14
  50. package/dist/components/layout/toolbar/tools/ZoomOutTool.js +3 -4
  51. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +3 -6
  52. package/dist/components/layout/toolbar/tools/defaults/RPVerticalBar.js +3 -4
  53. package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +3 -4
  54. package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +3 -4
  55. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +3 -4
  56. package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +3 -4
  57. package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +3 -4
  58. package/dist/components/page/AnnotationLayer.js +65 -66
  59. package/dist/components/page/CanvasLayer.js +3 -4
  60. package/dist/components/page/CustomElement.js +3 -4
  61. package/dist/components/page/DualPage.js +5 -11
  62. package/dist/components/page/DualPageWithCover.js +5 -11
  63. package/dist/components/page/RPPage.js +6 -12
  64. package/dist/components/page/SinglePage.js +5 -11
  65. package/dist/components/page/TextHighlightLayer.js +178 -86
  66. package/dist/components/page/TextLayer.js +170 -125
  67. package/dist/components/ui/LoadingIndicator.js +7 -8
  68. package/dist/contexts/ConfigContext.js +5 -4
  69. package/dist/contexts/DimensionPagesContext.js +5 -6
  70. package/dist/contexts/DropFileZoneContext.js +4 -5
  71. package/dist/contexts/ElementPageContext.js +5 -6
  72. package/dist/contexts/FileInputContext.js +5 -6
  73. package/dist/contexts/HighlightContext.js +7 -10
  74. package/dist/contexts/LayoutDropFileZoneContext.js +11 -0
  75. package/dist/contexts/LicenseContext.js +8 -6
  76. package/dist/contexts/PagesRotateContext.js +5 -6
  77. package/dist/contexts/PaginationContext.js +5 -6
  78. package/dist/contexts/PrintContext.js +16 -17
  79. package/dist/contexts/RPDocumentContext.js +13 -14
  80. package/dist/contexts/RenderQueueProvider.js +5 -6
  81. package/dist/contexts/RotationContext.js +8 -9
  82. package/dist/contexts/SearchContext.js +5 -8
  83. package/dist/contexts/ThumbnailsContext.js +4 -5
  84. package/dist/contexts/ZoomContext.js +5 -6
  85. package/dist/main.js +9 -9
  86. package/dist/types/components/layout/sidebar/Thumbnail.d.ts +2 -2
  87. package/dist/types/contexts/LayoutDropFileZoneContext.d.ts +9 -0
  88. package/dist/types/contexts/RPDocumentContext.d.ts +1 -1
  89. package/dist/types/contexts/RenderQueueProvider.d.ts +1 -1
  90. package/dist/types/contexts/RenderedPagesCache.d.ts +2 -2
  91. package/dist/types/main.d.ts +1 -1
  92. package/dist/types/utils/annotations.d.ts +2 -2
  93. package/dist/types/utils/getThumbnailViewport.d.ts +2 -2
  94. package/dist/types/utils/highlight.d.ts +5 -5
  95. package/dist/types/utils/hooks/useDropFileZone.d.ts +5 -0
  96. package/dist/types/utils/hooks/useFlickerSelectText.d.ts +1 -0
  97. package/dist/types/utils/hooks/useHighlight.d.ts +1 -1
  98. package/dist/types/utils/hooks/useLoadPdf.d.ts +2 -2
  99. package/dist/types/utils/hooks/useLoadWorker.d.ts +1 -5
  100. package/dist/types/utils/hooks/usePdfProperties.d.ts +1 -1
  101. package/dist/types/utils/hooks/useTextSelection.d.ts +3 -12
  102. package/dist/types/utils/link_service.d.ts +3 -2
  103. package/dist/types/utils/renderPage.d.ts +2 -2
  104. package/dist/types/utils/types.d.ts +10 -6
  105. package/dist/utils/highlight.js +158 -184
  106. package/dist/utils/hooks/useCopyText.js +22 -60
  107. package/dist/utils/hooks/useDropFileZone.js +12 -0
  108. package/dist/utils/hooks/useFileDownload.js +5 -6
  109. package/dist/utils/hooks/useFlickerSelectText.js +25 -0
  110. package/dist/utils/hooks/useHighlight.js +33 -35
  111. package/dist/utils/hooks/useLicense.js +22 -28
  112. package/dist/utils/hooks/useLoadPdf.js +70 -95
  113. package/dist/utils/hooks/useLoadWorker.js +14 -4
  114. package/dist/utils/hooks/usePageRotateContext.js +7 -8
  115. package/dist/utils/hooks/usePaginate.js +3 -4
  116. package/dist/utils/hooks/usePinch.js +10 -11
  117. package/dist/utils/hooks/usePresentPage.js +3 -4
  118. package/dist/utils/hooks/usePrint.js +55 -54
  119. package/dist/utils/hooks/useRotate.js +3 -4
  120. package/dist/utils/hooks/useScrollToPage.js +3 -4
  121. package/dist/utils/hooks/useSearch.js +15 -18
  122. package/dist/utils/hooks/useTextSelection.js +73 -2
  123. package/dist/utils/hooks/useThumbnail.js +17 -18
  124. package/dist/utils/hooks/useVirtualReactWindow.js +3 -4
  125. package/dist/utils/hooks/useWatermark.js +8 -6
  126. package/dist/utils/link_service.js +19 -18
  127. package/dist/utils/renderPage.js +1 -1
  128. package/dist/utils/types.js +3 -3
  129. package/package.json +6 -7
  130. package/dist/RPLayout.module-7766e0b4.js +0 -14
  131. package/dist/contexts/TextSelectionContext.js +0 -191
  132. package/dist/types/contexts/TextSelectionContext.d.ts +0 -14
  133. package/dist/types/utils/geometryCache.d.ts +0 -15
  134. package/dist/types/utils/glyphHitTest.d.ts +0 -12
  135. package/dist/types/utils/selectionUtils.d.ts +0 -30
  136. package/dist/utils/geometryCache.js +0 -32
  137. package/dist/utils/glyphHitTest.js +0 -29
  138. package/dist/utils/selectionUtils.js +0 -96
@@ -6,8 +6,7 @@ import { ORGANIZATION_ALLOWED_FEATURES_MESSAGE as R } from "../const.js";
6
6
  import "react/jsx-runtime";
7
7
  import "../../contexts/RPDocumentContext.js";
8
8
  import "./useLoadPdf.js";
9
- import "@pdf-viewer/pdfium";
10
- import "@pdf-viewer/pdfium/compat";
9
+ import "pdfjs-dist";
11
10
  import "../getThumbnailViewport.js";
12
11
  import "../../contexts/ConfigContext.js";
13
12
  import "../../contexts/DocumentPasswordContext.js";
@@ -20,8 +19,8 @@ import "../../contexts/RotationContext.js";
20
19
  import "../../contexts/InitialStateContext.js";
21
20
  import "../../contexts/EventCallbackContext.js";
22
21
  import "./useLicense.js";
23
- const W = () => {
24
- const { setSinglePageRotate: r } = c(), { type: i, validating: m } = u(), n = a(() => i !== f.Developer, [i]), p = l(
22
+ const U = () => {
23
+ const { setSinglePageRotate: r } = c(), { type: i, validating: n } = u(), m = a(() => i !== f.Developer, [i]), p = l(
25
24
  (s, t) => {
26
25
  r((o) => {
27
26
  const e = typeof t == "function" ? t(o[s] || 0) : t;
@@ -33,11 +32,11 @@ const W = () => {
33
32
  },
34
33
  [r]
35
34
  );
36
- return { rotate: a(() => m !== !1 ? () => {
37
- } : n ? p : () => {
35
+ return { rotate: a(() => n !== !1 ? () => {
36
+ } : m ? p : () => {
38
37
  console.error(R);
39
- }, [m, n, p]) };
38
+ }, [n, m, p]) };
40
39
  };
41
40
  export {
42
- W as usePageRotateContext
41
+ U as usePageRotateContext
43
42
  };
@@ -1,6 +1,6 @@
1
1
  import "react";
2
2
  import "../types.js";
3
- import { b as J } from "../../PaginationContext-9217cab4.js";
3
+ import { b as I } from "../../PaginationContext-9217cab4.js";
4
4
  import "../../contexts/ViewModeContext.js";
5
5
  import "../../contexts/ScrollModeContext.js";
6
6
  import "./useDebounce.js";
@@ -10,8 +10,7 @@ import "../../de_DE-a553b162.js";
10
10
  import "react/jsx-runtime";
11
11
  import "../../contexts/RPDocumentContext.js";
12
12
  import "./useLoadPdf.js";
13
- import "@pdf-viewer/pdfium";
14
- import "@pdf-viewer/pdfium/compat";
13
+ import "pdfjs-dist";
15
14
  import "../getThumbnailViewport.js";
16
15
  import "../../contexts/ConfigContext.js";
17
16
  import "../../contexts/DocumentPasswordContext.js";
@@ -34,5 +33,5 @@ import "../getZoomLevel.js";
34
33
  import "../../contexts/RotationContext.js";
35
34
  import "../../contexts/PagesRotateContext.js";
36
35
  export {
37
- J as usePaginate
36
+ I as usePaginate
38
37
  };
@@ -8,8 +8,7 @@ import "../appConsole.js";
8
8
  import "../../contexts/InitialStateContext.js";
9
9
  import "../../contexts/RPDocumentContext.js";
10
10
  import "./useLoadPdf.js";
11
- import "@pdf-viewer/pdfium";
12
- import "@pdf-viewer/pdfium/compat";
11
+ import "pdfjs-dist";
13
12
  import "../getThumbnailViewport.js";
14
13
  import "../../contexts/ConfigContext.js";
15
14
  import "../../contexts/DocumentPasswordContext.js";
@@ -23,7 +22,7 @@ import "../../contexts/ViewModeContext.js";
23
22
  import "../../contexts/RotationContext.js";
24
23
  import "../../contexts/GlobalCurrentPage.js";
25
24
  import "../../contexts/EventCallbackContext.js";
26
- const _ = (o) => {
25
+ const V = (o) => {
27
26
  const { currentZoom: L, setZoomLevel: w } = A(), [D, m] = E(0), d = g(D, 100), [s, b] = E(!1), r = T(null), u = c((e) => {
28
27
  m(e ? (t) => t + 3 : (t) => t - 3);
29
28
  }, []), a = c(
@@ -42,24 +41,24 @@ const _ = (o) => {
42
41
  m(0), w(e > 25 ? e : 25);
43
42
  }
44
43
  }, [d]);
45
- const v = (e, t) => {
44
+ const p = (e, t) => {
46
45
  const n = e.clientX - t.clientX, l = e.clientY - t.clientY;
47
46
  return Math.sqrt(n * n + l * l);
48
47
  }, f = c(
49
48
  (e) => {
50
49
  if (!s || e.touches.length !== 2)
51
50
  return;
52
- const t = v(e.touches[0], e.touches[1]);
51
+ const t = p(e.touches[0], e.touches[1]);
53
52
  r.current = t, e.preventDefault();
54
53
  },
55
54
  [s]
56
55
  ), h = c(() => {
57
56
  r.current = null;
58
- }, []), p = c(
57
+ }, []), v = c(
59
58
  (e) => {
60
59
  if (!s || e.touches.length !== 2 || r.current === null)
61
60
  return;
62
- const t = v(e.touches[0], e.touches[1]), n = t - r.current, l = Math.abs(n) > 5, S = n > 0;
61
+ const t = p(e.touches[0], e.touches[1]), n = t - r.current, l = Math.abs(n) > 5, S = n > 0;
63
62
  l && (u(S), r.current = t, e.preventDefault());
64
63
  },
65
64
  [u, s]
@@ -91,11 +90,11 @@ const _ = (o) => {
91
90
  };
92
91
  }, [o]), i(() => {
93
92
  if (o)
94
- return o.addEventListener("wheel", a, { passive: !1 }), o.addEventListener("touchstart", f, { passive: !1 }), o.addEventListener("touchmove", p, { passive: !1 }), o.addEventListener("touchend", h, { passive: !1 }), () => {
95
- o.removeEventListener("wheel", a), o.removeEventListener("touchstart", f), o.removeEventListener("touchmove", p), o.removeEventListener("touchend", h);
93
+ return o.addEventListener("wheel", a, { passive: !1 }), o.addEventListener("touchstart", f, { passive: !1 }), o.addEventListener("touchmove", v, { passive: !1 }), o.addEventListener("touchend", h, { passive: !1 }), () => {
94
+ o.removeEventListener("wheel", a), o.removeEventListener("touchstart", f), o.removeEventListener("touchmove", v), o.removeEventListener("touchend", h);
96
95
  };
97
- }, [o, a, f, p, h]);
96
+ }, [o, a, f, v, h]);
98
97
  };
99
98
  export {
100
- _ as usePinch
99
+ V as usePinch
101
100
  };
@@ -10,8 +10,7 @@ import "react/jsx-runtime";
10
10
  import "../appConsole.js";
11
11
  import "../../contexts/RPDocumentContext.js";
12
12
  import "./useLoadPdf.js";
13
- import "@pdf-viewer/pdfium";
14
- import "@pdf-viewer/pdfium/compat";
13
+ import "pdfjs-dist";
15
14
  import "../getThumbnailViewport.js";
16
15
  import "../../contexts/ConfigContext.js";
17
16
  import "../../contexts/DocumentPasswordContext.js";
@@ -33,7 +32,7 @@ import "../../contexts/VirtualScrollContext.js";
33
32
  import "../../contexts/VirtualGridContext.js";
34
33
  import "../smoothScrollTo.js";
35
34
  import "../getScrollDistance.js";
36
- const bt = (f, Y, n, W) => {
35
+ const Wt = (f, Y, n, W) => {
37
36
  const P = x(), { contentRef: E } = N(), { heights: h, widths: l } = v(), { setFocusedPage: b } = _(), [S, R] = C([]), { targetScrollPage: L } = G(), i = q(S, 0, 500), I = D(() => {
38
37
  const c = W === M.DUAL_PAGE_WITH_COVER, { rowsHeight: r, columnsWidth: o } = A({ heights: h, widths: l }, f, c);
39
38
  return h.map((m, t) => {
@@ -87,5 +86,5 @@ const bt = (f, Y, n, W) => {
87
86
  }, [n, g]);
88
87
  };
89
88
  export {
90
- bt as usePresentPage
89
+ Wt as usePresentPage
91
90
  };
@@ -1,9 +1,8 @@
1
- import { useState as g, useRef as k, useEffect as x, useCallback as P } from "react";
1
+ import { useState as g, useRef as k, useEffect as D, useCallback as P } from "react";
2
2
  import { useDocumentContext as q } from "../../contexts/RPDocumentContext.js";
3
- import { PixelsPerInch as V, AnnotationMode as O } from "@pdf-viewer/pdfium/compat";
3
+ import { PixelsPerInch as V, AnnotationMode as O, RenderingCancelledException as U } from "pdfjs-dist";
4
4
  import "react/jsx-runtime";
5
5
  import "./useLoadPdf.js";
6
- import "@pdf-viewer/pdfium";
7
6
  import "../types.js";
8
7
  import "../../de_DE-a553b162.js";
9
8
  import "../getThumbnailViewport.js";
@@ -13,19 +12,21 @@ import "../appConsole.js";
13
12
  import "./usePdfProperties.js";
14
13
  import "../convertPdfDate.js";
15
14
  import "../formatFileSize.js";
16
- const ne = () => {
17
- const { pdf: l, pages: f } = q(), [T, E] = g({
15
+ const re = () => {
16
+ const { pdf: l, pages: f } = q(), [R, E] = g({
18
17
  loadedPages: 0,
19
18
  totalPages: 0,
20
19
  percentage: 0
21
- }), [A, y] = g(!1), [R, b] = g(!1), [M, S] = g(null), [Z, w] = g(void 0), i = k(!1);
22
- x(() => {
20
+ }), [T, y] = g(!1), [A, b] = g(!1), [Z, C] = g(null), [M, w] = g(void 0), i = k(!1);
21
+ D(() => {
23
22
  i.current;
24
23
  }, [i]);
25
- const C = P(() => {
26
- document.documentElement.classList.remove("rp-print-html-printing"), document.body.classList.remove("rp-print-body-printing"), document.querySelector(".rp-print-zone");
24
+ const S = P(() => {
25
+ document.documentElement.classList.remove("rp-print-html-printing"), document.body.classList.remove("rp-print-body-printing");
26
+ const e = document.querySelector(".rp-print-zone");
27
+ e && e.remove();
27
28
  }, []), s = P(() => {
28
- i.current = !1, y(!1), b(!1), S(null), w(void 0), E({
29
+ i.current = !1, y(!1), b(!1), C(null), w(void 0), E({
29
30
  loadedPages: 0,
30
31
  totalPages: 0,
31
32
  percentage: 0
@@ -34,24 +35,24 @@ const ne = () => {
34
35
  i.current = !0;
35
36
  }, I = async ({
36
37
  scratchCanvas: e,
37
- pdfDocument: r,
38
+ pdfDocument: n,
38
39
  pageNumber: t,
39
- viewerPdfPage: n,
40
+ viewerPdfPage: r,
40
41
  printResolution: o,
41
42
  optionalContentConfigPromise: c,
42
- printAnnotationStoragePromise: d
43
+ printAnnotationStoragePromise: u
43
44
  }) => {
44
45
  if (i.current) {
45
46
  s();
46
47
  return;
47
48
  }
48
49
  const a = o / V.PDF;
49
- e.width = Math.floor(n.width * a), e.height = Math.floor(n.height * a);
50
+ e.width = Math.floor(r.width * a), e.height = Math.floor(r.height * a);
50
51
  const p = e.getContext("2d");
51
52
  p.save(), p.fillStyle = "rgb(255, 255, 255)", p.fillRect(0, 0, e.width, e.height), p.restore();
52
- const [u, h] = await Promise.all([
53
- r.getPage(t),
54
- d
53
+ const [m, h] = await Promise.all([
54
+ n.getPage(t),
55
+ u
55
56
  ]);
56
57
  if (i.current) {
57
58
  s();
@@ -61,60 +62,60 @@ const ne = () => {
61
62
  canvas: e,
62
63
  canvasContext: p,
63
64
  transform: [a, 0, 0, a, 0, 0],
64
- viewport: u.getViewport({ scale: 1, rotation: n.rotation }),
65
+ viewport: m.getViewport({ scale: 1, rotation: r.rotation }),
65
66
  intent: "print",
66
67
  annotationMode: O.ENABLE_STORAGE,
67
68
  optionalContentConfigPromise: c,
68
69
  printAnnotationStorage: h
69
70
  };
70
71
  try {
71
- return u.render(v).promise;
72
- } catch (m) {
73
- throw console.error(m), m;
72
+ return m.render(v).promise;
73
+ } catch (d) {
74
+ throw d instanceof U || console.error(d), d;
74
75
  }
75
76
  }, L = P(() => {
76
77
  const e = window.print;
77
- return new Promise((r) => {
78
+ return new Promise((n) => {
78
79
  const t = (c) => {
79
80
  setTimeout(() => {
80
81
  e.call(window), setTimeout(() => c(), 20);
81
82
  }, 0);
82
83
  };
83
84
  if (document.querySelector(".rp-print-zone")) {
84
- t(r);
85
+ t(n);
85
86
  return;
86
87
  }
87
88
  const o = new MutationObserver(() => {
88
- document.querySelector(".rp-print-zone") && (t(r), o.disconnect());
89
+ document.querySelector(".rp-print-zone") && (t(n), o.disconnect());
89
90
  });
90
91
  o.observe(document.body, { childList: !0, subtree: !0 });
91
92
  });
92
93
  }, []), z = (e) => {
93
- const r = document.createElement("img"), t = document.createElement("div");
94
- return t.classList.add("rp-print-page"), r.src = e.toDataURL(), t.appendChild(r), t;
95
- }, D = (e, r) => {
94
+ const n = document.createElement("img"), t = document.createElement("div");
95
+ return t.classList.add("rp-print-page"), n.src = e.toDataURL(), t.appendChild(n), t;
96
+ }, x = (e, n) => {
96
97
  const t = document.createElement("div");
97
98
  t.classList.add("rp-print-zone");
98
- const n = document.createElement("style"), o = r.get(1);
99
+ const r = document.createElement("style"), o = n.get(1);
99
100
  if (o) {
100
- const c = o.page.getViewport({ scale: 1 }), { width: d, height: a } = c;
101
- n.innerHTML = `@page { size: ${d}pt ${a}pt; margin: 0; }`;
101
+ const c = o.page.getViewport({ scale: 1 }), { width: u, height: a } = c;
102
+ r.innerHTML = `@page { size: ${u}pt ${a}pt; margin: 0; }`;
102
103
  }
103
- return t.appendChild(n), t.append(...e), t;
104
+ return t.appendChild(r), t.append(...e), t;
104
105
  }, N = P(
105
106
  async (e) => {
106
107
  if (!l)
107
108
  return;
108
109
  s();
109
- const r = e && "visibleDefaultProgress" in e ? e : void 0;
110
- (r == null ? void 0 : r.visibleDefaultProgress) !== void 0 ? w(r.visibleDefaultProgress) : w(!0);
111
- const t = document.createElement("canvas"), n = [];
110
+ const n = e && "visibleDefaultProgress" in e ? e : void 0;
111
+ (n == null ? void 0 : n.visibleDefaultProgress) !== void 0 ? w(n.visibleDefaultProgress) : w(!0);
112
+ const t = document.createElement("canvas"), r = [];
112
113
  try {
113
114
  l.isPureXfa && console.warn("[rp] XFA Form is not supported at the moment.");
114
- const c = l.getOptionalContentConfig({ intent: "print" }), d = Promise.resolve(
115
+ const c = l.getOptionalContentConfig({ intent: "print" }), u = Promise.resolve(
115
116
  l.annotationStorage.print ?? void 0
116
117
  ), a = f.size;
117
- for (const [u, h] of f) {
118
+ for (const [m, h] of f) {
118
119
  if (i.current) {
119
120
  s();
120
121
  return;
@@ -123,20 +124,20 @@ const ne = () => {
123
124
  if (await I({
124
125
  scratchCanvas: t,
125
126
  pdfDocument: l,
126
- pageNumber: u,
127
+ pageNumber: m,
127
128
  viewerPdfPage: v,
128
129
  printResolution: 150,
129
130
  optionalContentConfigPromise: c,
130
- printAnnotationStoragePromise: d
131
+ printAnnotationStoragePromise: u
131
132
  }), i.current) {
132
133
  s();
133
134
  return;
134
135
  }
135
- const m = z(t);
136
- n.push(m);
137
- const X = parseFloat((n.length / a * 100).toFixed(2));
136
+ const d = z(t);
137
+ r.push(d);
138
+ const X = parseFloat((r.length / a * 100).toFixed(2));
138
139
  E({
139
- loadedPages: u,
140
+ loadedPages: m,
140
141
  totalPages: a,
141
142
  percentage: X
142
143
  });
@@ -145,33 +146,33 @@ const ne = () => {
145
146
  s();
146
147
  return;
147
148
  }
148
- const p = D(n, f);
149
+ const p = x(r, f);
149
150
  document.body.appendChild(p), document.documentElement.classList.add("rp-print-html-printing"), document.body.classList.add("rp-print-body-printing"), y(!0), await L();
150
151
  } catch (o) {
151
- b(!0), o instanceof Error && S(o);
152
+ b(!0), o instanceof Error && C(o);
152
153
  } finally {
153
154
  t.height = 0, t.width = 0;
154
155
  }
155
156
  },
156
- [l, f, i, s, D, L]
157
+ [l, f, i, s, x, L]
157
158
  );
158
- return x(() => {
159
+ return D(() => {
159
160
  const e = () => {
160
- s(), C();
161
+ s(), S();
161
162
  };
162
163
  return window.addEventListener("afterprint", e, !0), () => {
163
164
  window.removeEventListener("afterprint", e, !0);
164
165
  };
165
- }, [C, s]), {
166
+ }, [S, s]), {
166
167
  print: N,
167
168
  cancel: F,
168
- progress: T,
169
- isComplete: A,
170
- isError: R,
171
- error: M,
172
- showDefaultProgress: Z
169
+ progress: R,
170
+ isComplete: T,
171
+ isError: A,
172
+ error: Z,
173
+ showDefaultProgress: M
173
174
  };
174
175
  };
175
176
  export {
176
- ne as usePrint
177
+ re as usePrint
177
178
  };
@@ -5,8 +5,7 @@ import "../appConsole.js";
5
5
  import "../../contexts/InitialStateContext.js";
6
6
  import "../../contexts/RPDocumentContext.js";
7
7
  import "./useLoadPdf.js";
8
- import "@pdf-viewer/pdfium";
9
- import "@pdf-viewer/pdfium/compat";
8
+ import "pdfjs-dist";
10
9
  import "../types.js";
11
10
  import "../../de_DE-a553b162.js";
12
11
  import "../getThumbnailViewport.js";
@@ -15,7 +14,7 @@ import "../../contexts/DocumentPasswordContext.js";
15
14
  import "./usePdfProperties.js";
16
15
  import "../convertPdfDate.js";
17
16
  import "../formatFileSize.js";
18
- const j = () => {
17
+ const g = () => {
19
18
  const { setRotate: t } = p(), i = r(() => {
20
19
  t((o) => (o + 90) % 360);
21
20
  }, [t]), m = r(() => {
@@ -24,5 +23,5 @@ const j = () => {
24
23
  return { handleRotateClockwise: i, handleRotateCounterclockwise: m };
25
24
  };
26
25
  export {
27
- j as useRotate
26
+ g as useRotate
28
27
  };
@@ -1,6 +1,6 @@
1
1
  import "react";
2
2
  import "../../contexts/ScrollModeContext.js";
3
- import { a as H } from "../../PaginationContext-9217cab4.js";
3
+ import { a as G } from "../../PaginationContext-9217cab4.js";
4
4
  import "../../contexts/ViewModeContext.js";
5
5
  import "../types.js";
6
6
  import "../../contexts/VirtualScrollContext.js";
@@ -16,8 +16,7 @@ import "../../contexts/InitialStateContext.js";
16
16
  import "../../de_DE-a553b162.js";
17
17
  import "../../contexts/RPDocumentContext.js";
18
18
  import "./useLoadPdf.js";
19
- import "@pdf-viewer/pdfium";
20
- import "@pdf-viewer/pdfium/compat";
19
+ import "pdfjs-dist";
21
20
  import "../getThumbnailViewport.js";
22
21
  import "../../contexts/ConfigContext.js";
23
22
  import "../../contexts/DocumentPasswordContext.js";
@@ -34,5 +33,5 @@ import "../getZoomLevel.js";
34
33
  import "../../contexts/RotationContext.js";
35
34
  import "../../contexts/PagesRotateContext.js";
36
35
  export {
37
- H as useScrollToPage
36
+ G as useScrollToPage
38
37
  };
@@ -6,22 +6,19 @@ import { useScrollModeContext as ct } from "../../contexts/ScrollModeContext.js"
6
6
  import { useDocumentContext as it } from "../../contexts/RPDocumentContext.js";
7
7
  import { useZoomContext as at } from "../../contexts/ZoomContext.js";
8
8
  import { u as mt } from "../../PaginationContext-9217cab4.js";
9
- import { useViewModeContext as pt } from "../../contexts/ViewModeContext.js";
10
- import { useDimensionPagesContext as ut } from "../../contexts/DimensionPagesContext.js";
9
+ import { useViewModeContext as ut } from "../../contexts/ViewModeContext.js";
10
+ import { useDimensionPagesContext as pt } from "../../contexts/DimensionPagesContext.js";
11
11
  import { useLayoutContainer as lt } from "../../contexts/LayoutContainerContext.js";
12
12
  import { getScrollDistance as F } from "../getScrollDistance.js";
13
13
  import { getWordPositionInPage as ft } from "../getWordPositionInPage.js";
14
14
  import { usePagesRotateContext as gt } from "../../contexts/PagesRotateContext.js";
15
15
  import "../../de_DE-a553b162.js";
16
16
  import "../charators.js";
17
- import "../selectionUtils.js";
18
- import "../geometryCache.js";
19
17
  import "react/jsx-runtime";
20
18
  import "../appConsole.js";
21
19
  import "../../contexts/InitialStateContext.js";
22
20
  import "./useLoadPdf.js";
23
- import "@pdf-viewer/pdfium";
24
- import "@pdf-viewer/pdfium/compat";
21
+ import "pdfjs-dist";
25
22
  import "../getThumbnailViewport.js";
26
23
  import "../../contexts/ConfigContext.js";
27
24
  import "../../contexts/DocumentPasswordContext.js";
@@ -38,8 +35,8 @@ import "../../contexts/VirtualGridContext.js";
38
35
  import "../smoothScrollTo.js";
39
36
  import "../../contexts/SmoothScrollContext.js";
40
37
  import "../calculatePage.js";
41
- const ee = (O = {}, U = "") => {
42
- const [p, q] = C(U), [B, y] = C(!1), { pdf: _, pages: S } = it(), { widths: f, heights: R } = ut(), w = b(!p), { currentZoom: A } = at(), [s, g] = C([]), { setFocusedPage: D } = mt(), { columnCount: G, viewMode: V } = pt(), { pageRotate: v } = gt(), [c, i] = C(0), { pageScrollElementRef: W, virtualScrollableElementRef: Z } = st(), { scrollMode: h } = ct(), { pagesRef: L } = lt(), J = b({}), m = b(0), K = H(() => c === 0 ? null : s[c - 1], [c, s]), a = H(() => s.length, [s]), u = I(
38
+ const Yt = (O = {}, U = "") => {
39
+ const [u, q] = C(U), [B, y] = C(!1), { pdf: _, pages: S } = it(), { widths: f, heights: R } = pt(), w = b(!u), { currentZoom: A } = at(), [s, g] = C([]), { setFocusedPage: D } = mt(), { columnCount: G, viewMode: V } = ut(), { pageRotate: v } = gt(), [c, i] = C(0), { pageScrollElementRef: W, virtualScrollableElementRef: Z } = st(), { scrollMode: h } = ct(), { pagesRef: L } = lt(), J = b({}), m = b(0), K = H(() => c === 0 ? null : s[c - 1], [c, s]), a = H(() => s.length, [s]), p = I(
43
40
  (e) => {
44
41
  if (e === 0)
45
42
  return;
@@ -103,19 +100,19 @@ const ee = (O = {}, U = "") => {
103
100
  ]
104
101
  );
105
102
  z(() => {
106
- c && u(c);
103
+ c && p(c);
107
104
  }, [c]);
108
105
  const Q = I(() => {
109
106
  i((e) => {
110
107
  let t;
111
108
  return a ? e + 1 > a ? t = 1 : t = e + 1 : t = 0, m.current = t, t;
112
- }), m.current === 1 && u(m.current);
113
- }, [a, u]), X = I(() => {
109
+ }), m.current === 1 && p(m.current);
110
+ }, [a, p]), X = I(() => {
114
111
  i((e) => {
115
112
  let t;
116
113
  return a ? e - 1 <= 0 ? t = a : t = e - 1 : t = 0, m.current = t, t;
117
- }), m.current === 1 && u(m.current);
118
- }, [a, u]), j = I(async (e) => {
114
+ }), m.current === 1 && p(m.current);
115
+ }, [a, p]), j = I(async (e) => {
119
116
  if (!e)
120
117
  return {};
121
118
  const t = e.numPages, o = {};
@@ -128,7 +125,7 @@ const ee = (O = {}, U = "") => {
128
125
  return o;
129
126
  }, []);
130
127
  return z(() => {
131
- if (!p) {
128
+ if (!u) {
132
129
  w.current = !0, g([]), i(0);
133
130
  return;
134
131
  }
@@ -136,7 +133,7 @@ const ee = (O = {}, U = "") => {
136
133
  J.current = e;
137
134
  const o = Object.keys(e).reduce((r, n) => {
138
135
  const l = nt(
139
- [p],
136
+ [u],
140
137
  e[n],
141
138
  Number(n) - 1,
142
139
  O
@@ -147,8 +144,8 @@ const ee = (O = {}, U = "") => {
147
144
  }).catch(() => {
148
145
  g([]), i(0);
149
146
  }).finally(() => y(!1));
150
- }, [p, j, _, O]), {
151
- search: p,
147
+ }, [u, j, _, O]), {
148
+ search: u,
152
149
  setSearch: q,
153
150
  loading: B,
154
151
  matches: s,
@@ -161,5 +158,5 @@ const ee = (O = {}, U = "") => {
161
158
  };
162
159
  };
163
160
  export {
164
- ee as useSearch
161
+ Yt as useSearch
165
162
  };
@@ -1,5 +1,76 @@
1
- const o = (e) => {
1
+ import { useCallback as p, useEffect as b } from "react";
2
+ const D = ({ onTextSelect: s, pagesRef: n }) => {
3
+ const f = p(() => {
4
+ const e = n == null ? void 0 : n.querySelectorAll('[data-rp$="-textLayer"]');
5
+ return e ? Array.from(e) : [];
6
+ }, [n]), N = p(() => {
7
+ const e = document.getSelection();
8
+ if (!e || e.rangeCount === 0 || e.toString().trim() === "")
9
+ return null;
10
+ const E = e.toString(), a = /* @__PURE__ */ new Map(), O = f();
11
+ for (let i = 0; i < e.rangeCount; i++) {
12
+ const t = e.getRangeAt(i);
13
+ O.forEach((d) => {
14
+ if (t.intersectsNode(d)) {
15
+ const g = d.getAttribute("data-rp"), T = g == null ? void 0 : g.match(/page-(\d+)-textLayer/);
16
+ if (T) {
17
+ const h = parseInt(T[1]), C = d.closest('[data-rp*="page-"]');
18
+ if (!C)
19
+ return;
20
+ const c = C.getBoundingClientRect();
21
+ a.has(h) || a.set(h, {
22
+ rects: [],
23
+ pageRect: c
24
+ });
25
+ const y = a.get(h), _ = document.createTreeWalker(d, NodeFilter.SHOW_TEXT, null);
26
+ let u;
27
+ for (; u = _.nextNode(); )
28
+ if (t.intersectsNode(u) && u.parentElement) {
29
+ const o = document.createRange();
30
+ o.selectNodeContents(u);
31
+ const A = t.compareBoundaryPoints(Range.START_TO_START, o) > 0 ? t.startContainer : o.startContainer, B = t.compareBoundaryPoints(Range.START_TO_START, o) > 0 ? t.startOffset : o.startOffset, R = t.compareBoundaryPoints(Range.END_TO_END, o) < 0 ? t.endContainer : o.endContainer, S = t.compareBoundaryPoints(Range.END_TO_END, o) < 0 ? t.endOffset : o.endOffset, m = document.createRange();
32
+ m.setStart(A, B), m.setEnd(R, S);
33
+ const r = m.getBoundingClientRect();
34
+ if (r.width === 0 || r.height === 0)
35
+ continue;
36
+ const P = {
37
+ left: r.left - c.left,
38
+ top: r.top - c.top,
39
+ right: r.right - c.left,
40
+ bottom: r.bottom - c.top,
41
+ width: r.width,
42
+ height: r.height
43
+ };
44
+ y.rects.push(P);
45
+ }
46
+ }
47
+ }
48
+ });
49
+ }
50
+ const w = Array.from(a.entries()).sort(([i], [t]) => i - t).map(([i, t]) => ({
51
+ pageNumber: i,
52
+ pageBasedBoundingRects: t.rects,
53
+ pageDimension: {
54
+ width: t.pageRect.width,
55
+ height: t.pageRect.height
56
+ },
57
+ pagePositionInWindow: {
58
+ x: t.pageRect.left,
59
+ y: t.pageRect.top
60
+ }
61
+ }));
62
+ return {
63
+ text: E,
64
+ pageSelections: w
65
+ };
66
+ }, [f]), l = p(() => {
67
+ const e = N();
68
+ e && (s == null || s(e));
69
+ }, [N, s]);
70
+ b(() => (n == null || n.addEventListener("pointerup", l), () => {
71
+ n == null || n.removeEventListener("pointerup", l);
72
+ }), [n, l]);
2
73
  };
3
74
  export {
4
- o as useTextSelection
75
+ D as useTextSelection
5
76
  };