@react-pdf-kit/viewer 2.9.2 → 2.10.0-beta.1

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 (166) hide show
  1. package/dist/AnnotationLayer-lagF0zYo.js +116 -0
  2. package/dist/{Button-DBu3SaMk.js → Button-B_yuVBQ_.js} +1 -1
  3. package/dist/{Checkbox-CSIEUyO8.js → Checkbox-BVARFFLh.js} +2 -2
  4. package/dist/{Combination-11kyhTGt.js → Combination-ILTe_xfZ.js} +2 -2
  5. package/dist/{Container-BuamPhw4.js → Container-CY9sCoDd.js} +1 -1
  6. package/dist/{DocumentDialog-cRr9sSSH.js → DocumentDialog-CYKsfOE1.js} +4 -4
  7. package/dist/{DropDown-CM6xEwZC.js → DropDown-DEnDtOIT.js} +2 -2
  8. package/dist/{Input-Dpo1Xfxe.js → Input-CVjTHdhy.js} +1 -1
  9. package/dist/{LoaderIcon-B3ddfd0D.js → LoaderIcon-SD35XFV2.js} +1 -1
  10. package/dist/{LoadingIndicator-0E8WHnSN.js → LoadingIndicator-SLpllUQ1.js} +1 -1
  11. package/dist/{MenuItem-lItnKNd5.js → MenuItem-DEd62cAM.js} +2 -2
  12. package/dist/{MenuSeparator-CaFxd8b5.js → MenuSeparator-BVQWugN3.js} +1 -1
  13. package/dist/{PasswordModal-CxHFn0pB.js → PasswordModal-BCjtXHN4.js} +1 -1
  14. package/dist/{RPDropFileZone-Bq1bzWmO.js → RPDropFileZone-lI-AmN-1.js} +3 -3
  15. package/dist/{RPPages-BZwgKgfJ.js → RPPages-BVSFaPUT.js} +2 -2
  16. package/dist/{RPTooltip-QWwWh4HW.js → RPTooltip-KdCUxOyM.js} +3 -3
  17. package/dist/TextHighlightLayer-BMhYl-9Q.js +162 -0
  18. package/dist/{TextLayer-Bp1CDIIa.js → TextLayer-CUtANGvL.js} +2 -2
  19. package/dist/{Thumbnail-BXMk0OWF.js → Thumbnail-BDGp0xdd.js} +3 -3
  20. package/dist/{Thumbnails-BIuN8LZ8.js → Thumbnails-C6maORBh.js} +1 -1
  21. package/dist/XfaLayer.module-w4FOd2dm.js +4 -0
  22. package/dist/assets/XfaLayer.css +1 -0
  23. package/dist/assets/style.js +1 -1
  24. package/dist/components/RPController.js +1 -1
  25. package/dist/components/RPDropFileZone.js +1 -1
  26. package/dist/components/RPPages.js +1 -1
  27. package/dist/components/RPProvider.js +1 -1
  28. package/dist/components/icons/DarkPdfIcon.js +1 -1
  29. package/dist/components/icons/LightPdfIcon.js +1 -1
  30. package/dist/components/icons/LoaderIcon.js +1 -1
  31. package/dist/components/layout/Container.js +1 -1
  32. package/dist/components/layout/LayoutContainer.js +2 -2
  33. package/dist/components/layout/LayoutWrapper.js +1 -1
  34. package/dist/components/layout/RPDefaultLayout.js +5 -5
  35. package/dist/components/layout/RPLayout.js +5 -5
  36. package/dist/components/layout/SkipLink.js +1 -1
  37. package/dist/components/layout/WrapperLayout.js +1 -1
  38. package/dist/components/layout/sidebar/CustomThumbnailElement.js +1 -1
  39. package/dist/components/layout/sidebar/RPSidebar.js +4 -4
  40. package/dist/components/layout/sidebar/RPSplitter.js +1 -1
  41. package/dist/components/layout/sidebar/Thumbnail.js +1 -1
  42. package/dist/components/layout/sidebar/Thumbnails.js +1 -1
  43. package/dist/components/layout/toolbar/DarkModeTool.js +2 -2
  44. package/dist/components/layout/toolbar/DocumentDialog.js +1 -1
  45. package/dist/components/layout/toolbar/DocumentProperties.js +3 -3
  46. package/dist/components/layout/toolbar/FileDownloadTool.js +3 -3
  47. package/dist/components/layout/toolbar/FileUploadTool.js +3 -3
  48. package/dist/components/layout/toolbar/FullScreenTool.js +3 -3
  49. package/dist/components/layout/toolbar/MenuItem.js +1 -1
  50. package/dist/components/layout/toolbar/MenuSeparator.js +1 -1
  51. package/dist/components/layout/toolbar/MostPageTool.js +5 -5
  52. package/dist/components/layout/toolbar/OtherTool.js +7 -7
  53. package/dist/components/layout/toolbar/Paginate.js +4 -4
  54. package/dist/components/layout/toolbar/PrintTool.js +3 -3
  55. package/dist/components/layout/toolbar/PropertyItem.js +1 -1
  56. package/dist/components/layout/toolbar/RPMenuItem.js +3 -3
  57. package/dist/components/layout/toolbar/RPMoreOptions.js +7 -7
  58. package/dist/components/layout/toolbar/RPToolbar.js +2 -2
  59. package/dist/components/layout/toolbar/RotateTool.js +5 -5
  60. package/dist/components/layout/toolbar/ScrollModeTool.js +3 -3
  61. package/dist/components/layout/toolbar/SearchCloseButton.js +3 -3
  62. package/dist/components/layout/toolbar/SearchResultNavigator.js +3 -3
  63. package/dist/components/layout/toolbar/SearchTool.js +7 -7
  64. package/dist/components/layout/toolbar/SelectionModeTool.js +4 -4
  65. package/dist/components/layout/toolbar/ThumbnailTool.js +2 -2
  66. package/dist/components/layout/toolbar/ToolbarCustom.js +4 -4
  67. package/dist/components/layout/toolbar/ToolbarDefault.js +4 -4
  68. package/dist/components/layout/toolbar/ViewModeTool.js +4 -4
  69. package/dist/components/layout/toolbar/ZoomTool.js +8 -8
  70. package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +3 -3
  71. package/dist/components/layout/toolbar/tools/DualPageTool.js +2 -2
  72. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +1 -1
  73. package/dist/components/layout/toolbar/tools/FileDownloadTool.js +2 -2
  74. package/dist/components/layout/toolbar/tools/FileUploadTool.js +2 -2
  75. package/dist/components/layout/toolbar/tools/FirstPageTool.js +1 -1
  76. package/dist/components/layout/toolbar/tools/FullScreenTool.js +2 -2
  77. package/dist/components/layout/toolbar/tools/HorizontalScrollingTool.js +2 -2
  78. package/dist/components/layout/toolbar/tools/InputPageTool.js +3 -3
  79. package/dist/components/layout/toolbar/tools/LastPageTool.js +1 -1
  80. package/dist/components/layout/toolbar/tools/NextPageTool.js +2 -2
  81. package/dist/components/layout/toolbar/tools/PageScrollingTool.js +2 -2
  82. package/dist/components/layout/toolbar/tools/PreviousPageTool.js +2 -2
  83. package/dist/components/layout/toolbar/tools/PrintTool.js +2 -2
  84. package/dist/components/layout/toolbar/tools/RotateClockwiseTool.js +2 -2
  85. package/dist/components/layout/toolbar/tools/RotateCounterclockwiseTool.js +3 -3
  86. package/dist/components/layout/toolbar/tools/SelectionModeSwitcherTool.js +2 -2
  87. package/dist/components/layout/toolbar/tools/SinglePageTool.js +2 -2
  88. package/dist/components/layout/toolbar/tools/ThemeSwitcherTool.js +2 -2
  89. package/dist/components/layout/toolbar/tools/ThumbnailTool.js +2 -2
  90. package/dist/components/layout/toolbar/tools/VerticalScrollingTool.js +2 -2
  91. package/dist/components/layout/toolbar/tools/ZoomInTool.js +2 -2
  92. package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +7 -7
  93. package/dist/components/layout/toolbar/tools/ZoomOutTool.js +2 -2
  94. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +1 -1
  95. package/dist/components/layout/toolbar/tools/more-options/DocumentProperties.js +2 -2
  96. package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +2 -2
  97. package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +2 -2
  98. package/dist/components/layout/toolbar/tools/more-options/FullScreenTool.js +2 -2
  99. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +5 -5
  100. package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +2 -2
  101. package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +5 -5
  102. package/dist/components/layout/toolbar/tools/more-options/ScrollModeTool.js +3 -3
  103. package/dist/components/layout/toolbar/tools/more-options/SelectionModeTool.js +4 -4
  104. package/dist/components/layout/toolbar/tools/more-options/ViewModeTool.js +4 -4
  105. package/dist/components/page/AnnotationLayer.js +1 -1
  106. package/dist/components/page/CanvasLayer.js +1 -1
  107. package/dist/components/page/RPPage.js +54 -52
  108. package/dist/components/page/TextHighlightLayer.js +1 -1
  109. package/dist/components/page/TextLayer.js +1 -1
  110. package/dist/components/page/XfaLayer.js +86 -0
  111. package/dist/components/ui/Button.js +1 -1
  112. package/dist/components/ui/Checkbox.js +1 -1
  113. package/dist/components/ui/DropDown.js +1 -1
  114. package/dist/components/ui/Input.js +1 -1
  115. package/dist/components/ui/LoadingIndicator.js +1 -1
  116. package/dist/components/ui/PasswordModal.js +1 -1
  117. package/dist/components/ui/RPTooltip.js +1 -1
  118. package/dist/contexts/LoaderContext.js +1 -1
  119. package/dist/contexts/RenderQueueProvider.js +46 -43
  120. package/dist/{dist-CNbFpoT1.js → dist-BgFO-PWQ.js} +1 -1
  121. package/dist/{dist-VbpVNBs6.js → dist-CtoH1CMU.js} +4 -4
  122. package/dist/{dist-B2hwhF6G.js → dist-D6Fk7CTS.js} +3 -3
  123. package/dist/{dist-BfuBBQ14.js → dist-SBjhcXgf.js} +1 -1
  124. package/dist/icons.js +3 -3
  125. package/dist/{main-DCzVrq0G.js → main-DrddwgsH.js} +3 -3
  126. package/dist/main.js +4 -4
  127. package/dist/{style-dcYpxEeL.js → style-DW_uCDpt.js} +1 -1
  128. package/dist/types/components/page/XfaLayer.d.ts +6 -0
  129. package/dist/types/utils/pdfOperationTracker.d.ts +20 -0
  130. package/dist/utils/annotations.js +72 -71
  131. package/dist/utils/highlight.js +4 -2
  132. package/dist/utils/hooks/useFileDownload.js +10 -6
  133. package/dist/utils/hooks/useHighlight.js +43 -42
  134. package/dist/utils/hooks/useLicense.js +2 -2
  135. package/dist/utils/hooks/useLoadPdf.js +66 -64
  136. package/dist/utils/hooks/usePdfProperties.js +33 -32
  137. package/dist/utils/hooks/usePrint.js +123 -88
  138. package/dist/utils/hooks/useSearch.js +87 -83
  139. package/dist/utils/hooks/useWatermark.js +1 -1
  140. package/dist/utils/injectPrintCSS.js +1 -1
  141. package/dist/utils/link_service.js +33 -17
  142. package/dist/utils/pdfOperationTracker.js +27 -4
  143. package/package.json +1 -1
  144. package/dist/AnnotationLayer-oDu2B4X1.js +0 -114
  145. package/dist/TextHighlightLayer-3vIZbRyL.js +0 -157
  146. /package/dist/{CanvasLayer-C3gb8EXu.js → CanvasLayer-DkVH-tX2.js} +0 -0
  147. /package/dist/{CustomThumbnailElement-C2quEICO.js → CustomThumbnailElement-BxTSbzpP.js} +0 -0
  148. /package/dist/{DarkPdfIcon-B5ehd9CV.js → DarkPdfIcon-2aDGWxuA.js} +0 -0
  149. /package/dist/{LightPdfIcon-DL8MYtWQ.js → LightPdfIcon-LatCGY0T.js} +0 -0
  150. /package/dist/{MostPageTool.module-BRVv-sGz.js → MostPageTool.module-BP2BMoK8.js} +0 -0
  151. /package/dist/{OtherTool.module-BQY9Nfqz.js → OtherTool.module-CMbI70sn.js} +0 -0
  152. /package/dist/{Paginate.module-DhE7N8AA.js → Paginate.module-DxXyYoYp.js} +0 -0
  153. /package/dist/{PropertyItem-evJWWmWZ.js → PropertyItem-CmRC2e5Z.js} +0 -0
  154. /package/dist/{RPLayout.module-BH5r8dDc.js → RPLayout.module-DLX1UwA3.js} +0 -0
  155. /package/dist/{RPSplitter-C63X9M8w.js → RPSplitter-DGnDuwsT.js} +0 -0
  156. /package/dist/{RPToolbar.module-BwqWLviy.js → RPToolbar.module-ODOa9FwW.js} +0 -0
  157. /package/dist/{RotateTool.module-DH5yWbvM.js → RotateTool.module-BHFeo1yn.js} +0 -0
  158. /package/dist/{SearchTool.module-DY8Ucfb_.js → SearchTool.module-BQDBENlo.js} +0 -0
  159. /package/dist/{SkipLink-Dj83gZdk.js → SkipLink-mnqFQj0O.js} +0 -0
  160. /package/dist/{ToolbarLayout.module-Zo715dbb.js → ToolbarLayout.module-BC9eQ9LN.js} +0 -0
  161. /package/dist/{WrapperLayout-Dcd9l9xH.js → WrapperLayout-NjsBnUaz.js} +0 -0
  162. /package/dist/{ZoomTool.module-BrIPy8pO.js → ZoomTool.module-DO-r2IDy.js} +0 -0
  163. /package/dist/{clsx-DSGuh5YW.js → clsx-BD2qMUU1.js} +0 -0
  164. /package/dist/{dist-CgoP608h.js → dist-DjD1zIE0.js} +0 -0
  165. /package/dist/{lib-CSInlR9T.js → lib-DTkzWIMS.js} +0 -0
  166. /package/dist/{useWatermark-CvAAf66v.js → useWatermark-DlRNcg9p.js} +0 -0
@@ -1,125 +1,129 @@
1
1
  import { ScrollMode as e } from "../types.js";
2
- import { useDocumentContext as t } from "../../contexts/RPDocumentContext.js";
3
- import { useScrollModeContext as n } from "../../contexts/ScrollModeContext.js";
4
- import { useViewModeContext as r } from "../../contexts/ViewModeContext.js";
5
- import { useVirtualScrollContext as i } from "../../contexts/VirtualScrollContext.js";
6
- import { useLayoutContainer as a } from "../../contexts/LayoutContainerContext.js";
7
- import { useZoomContext as o } from "../../contexts/ZoomContext.js";
8
- import { usePagesRotateContext as s } from "../../contexts/PagesRotateContext.js";
9
- import { useDimensionPagesContext as c } from "../../contexts/DimensionPagesContext.js";
10
- import { useSmoothScrollContext as l } from "../../contexts/SmoothScrollContext.js";
11
- import { buildDocumentLayout as u, getPagePlacement as d } from "../documentLayout.js";
12
- import { r as f } from "../../PaginationContext-DIzsZhFd.js";
13
- import { findMatches as p } from "../highlight.js";
14
- import { getWordPositionInPage as m } from "../getWordPositionInPage.js";
15
- import { useCallback as h, useEffect as g, useMemo as _, useRef as v, useState as y } from "react";
2
+ import { runPdfOperation as t } from "../pdfOperationTracker.js";
3
+ import { useDocumentContext as n } from "../../contexts/RPDocumentContext.js";
4
+ import { useScrollModeContext as r } from "../../contexts/ScrollModeContext.js";
5
+ import { useViewModeContext as i } from "../../contexts/ViewModeContext.js";
6
+ import { useVirtualScrollContext as a } from "../../contexts/VirtualScrollContext.js";
7
+ import { useLayoutContainer as o } from "../../contexts/LayoutContainerContext.js";
8
+ import { useZoomContext as s } from "../../contexts/ZoomContext.js";
9
+ import { usePagesRotateContext as c } from "../../contexts/PagesRotateContext.js";
10
+ import { useDimensionPagesContext as l } from "../../contexts/DimensionPagesContext.js";
11
+ import { useSmoothScrollContext as u } from "../../contexts/SmoothScrollContext.js";
12
+ import { buildDocumentLayout as d, getPagePlacement as f } from "../documentLayout.js";
13
+ import { r as p } from "../../PaginationContext-DIzsZhFd.js";
14
+ import { findMatches as m } from "../highlight.js";
15
+ import { getWordPositionInPage as h } from "../getWordPositionInPage.js";
16
+ import { useCallback as g, useEffect as _, useMemo as v, useRef as y, useState as b } from "react";
16
17
  //#region lib/utils/hooks/useSearch.ts
17
- var b = (b = {}, x = "") => {
18
- let [S, C] = y(x), [w, T] = y(!1), { pdf: E, pages: D } = t(), { widths: O, heights: k } = c(), A = v(!S), { currentZoom: j } = o(), [M, N] = y([]), { setFocusedPage: P } = f(), { viewMode: F } = r(), { pageRotate: I } = s(), [L, R] = y(0), { pageScrollElementRef: z, virtualScrollableElementRef: B } = i(), { scrollMode: V } = n(), { pagesRef: H } = a(), { scrollBehavior: U } = l(), W = v({}), G = v(0), K = _(() => L === 0 ? null : M[L - 1], [L, M]), q = _(() => M.length, [M]), J = h((t) => {
18
+ var x = (x = {}, S = "") => {
19
+ let [C, w] = b(S), [T, E] = b(!1), { pdf: D, pages: O } = n(), { widths: k, heights: A } = l(), j = y(!C), { currentZoom: M } = s(), [N, P] = b([]), { setFocusedPage: F } = p(), { viewMode: I } = i(), { pageRotate: L } = c(), [R, z] = b(0), { pageScrollElementRef: B, virtualScrollableElementRef: V } = a(), { scrollMode: H } = r(), { pagesRef: U } = o(), { scrollBehavior: W } = u(), G = y({}), K = y(0), q = v(() => R === 0 ? null : N[R - 1], [R, N]), J = v(() => N.length, [N]), Y = g((t) => {
19
20
  if (t === 0) return;
20
- let n = M[t - 1];
21
- if (!n || !D) return;
22
- let r = B || z;
23
- if (!r || !H) return;
24
- let i = D.get(n.page);
25
- if (V === e.PAGE_SCROLLING && P(n.page), !i) return;
26
- let a = u({
21
+ let n = N[t - 1];
22
+ if (!n || !O) return;
23
+ let r = V || B;
24
+ if (!r || !U) return;
25
+ let i = O.get(n.page);
26
+ if (H === e.PAGE_SCROLLING && F(n.page), !i) return;
27
+ let a = d({
27
28
  pageDimensions: {
28
- widths: O,
29
- heights: k
29
+ widths: k,
30
+ heights: A
30
31
  },
31
32
  viewportWidth: r.clientWidth,
32
33
  viewportHeight: r.clientHeight,
33
- scrollMode: V,
34
- viewMode: F,
34
+ scrollMode: H,
35
+ viewMode: I,
35
36
  focusedPage: n.page
36
- }), o = d(a, n.page);
37
+ }), o = f(a, n.page);
37
38
  if (!o) return;
38
39
  let s = {
39
- height: k[n.page - 1],
40
- width: O[n.page - 1]
41
- }, c = I[n.page], { leftInPage: l, topInPage: f } = m(s, H, n.rect, j, c), p = a.offsetLeft + o.left + l, h = a.offsetTop + o.top + f, g = {
40
+ height: A[n.page - 1],
41
+ width: k[n.page - 1]
42
+ }, c = L[n.page], { leftInPage: l, topInPage: u } = i.page.isPureXfa ? {
43
+ leftInPage: 0,
44
+ topInPage: 0
45
+ } : h(s, U, n.rect, M, c), p = a.offsetLeft + o.left + l, m = a.offsetTop + o.top + u, g = {
42
46
  left: Math.max(p, 0),
43
- top: Math.max(h, 0)
47
+ top: Math.max(m, 0)
44
48
  };
45
49
  r.scrollTo({
46
50
  ...g,
47
- behavior: U
51
+ behavior: W
48
52
  });
49
53
  }, [
50
- D,
51
- P,
52
54
  O,
55
+ F,
53
56
  k,
57
+ A,
58
+ H,
59
+ I,
54
60
  V,
55
- F,
56
61
  B,
57
- z,
58
- H,
62
+ U,
63
+ N,
59
64
  M,
60
- j,
61
- I,
62
- U
65
+ L,
66
+ W
63
67
  ]);
64
- g(() => {
65
- L && J(L);
66
- }, [L]);
67
- let Y = h(() => {
68
- R((e) => {
68
+ _(() => {
69
+ R && Y(R);
70
+ }, [R]);
71
+ let X = g(() => {
72
+ z((e) => {
69
73
  let t;
70
- return t = q ? e + 1 > q ? 1 : e + 1 : 0, G.current = t, t;
71
- }), G.current === 1 && J(G.current);
72
- }, [q, J]), X = h(() => {
73
- R((e) => {
74
+ return t = J ? e + 1 > J ? 1 : e + 1 : 0, K.current = t, t;
75
+ }), K.current === 1 && Y(K.current);
76
+ }, [J, Y]), Z = g(() => {
77
+ z((e) => {
74
78
  let t;
75
- return t = q ? e - 1 <= 0 ? q : e - 1 : 0, G.current = t, t;
76
- }), G.current === 1 && J(G.current);
77
- }, [q, J]), Z = h(async (e) => {
79
+ return t = J ? e - 1 <= 0 ? J : e - 1 : 0, K.current = t, t;
80
+ }), K.current === 1 && Y(K.current);
81
+ }, [J, Y]), Q = g(async (e) => {
78
82
  if (!e) return {};
79
- let t = e.numPages, n = {};
80
- for (let r = 1; r <= t; r++) {
81
- if (A.current) throw "close pop over";
82
- let t = await e.getPage(r);
83
- n[r.toString()] = await t.getTextContent();
83
+ let n = e.numPages, r = {};
84
+ for (let i = 1; i <= n; i++) {
85
+ if (j.current) throw "close pop over";
86
+ let n = await t(e, () => e.getPage(i));
87
+ r[i.toString()] = await t(e, () => n.getTextContent());
84
88
  }
85
- return n;
89
+ return r;
86
90
  }, []);
87
- return g(() => {
88
- if (!S) {
89
- A.current = !0, N([]), R(0);
91
+ return _(() => {
92
+ if (!C) {
93
+ j.current = !0, P([]), z(0);
90
94
  return;
91
95
  }
92
- A.current = !1, T(!0), N([]), R(0), Z(E).then((e) => {
93
- W.current = e;
96
+ j.current = !1, E(!0), P([]), z(0), Q(D).then((e) => {
97
+ G.current = e;
94
98
  let t = Object.keys(e).reduce((t, n) => {
95
- let r = p([S], e[n], Number(n) - 1, b).map((e, t) => ({
99
+ let r = m([C], e[n], Number(n) - 1, x).map((e, t) => ({
96
100
  ...e,
97
101
  page: Number(n),
98
102
  pageMatchIdx: t
99
103
  }));
100
104
  return [...t, ...r];
101
105
  }, []);
102
- N(t), R(+!!t.length);
106
+ P(t), z(+!!t.length);
103
107
  }).catch(() => {
104
- N([]), R(0);
105
- }).finally(() => T(!1));
108
+ P([]), z(0);
109
+ }).finally(() => E(!1));
106
110
  }, [
107
- S,
108
- Z,
109
- E,
110
- b
111
+ C,
112
+ Q,
113
+ D,
114
+ x
111
115
  ]), {
112
- search: S,
113
- setSearch: C,
114
- loading: w,
115
- matches: M,
116
- totalMatches: q,
117
- currentMatchPosition: L,
118
- currentMatch: K,
119
- nextMatch: Y,
120
- prevMatch: X,
121
- setCurrentMatchPosition: R
116
+ search: C,
117
+ setSearch: w,
118
+ loading: T,
119
+ matches: N,
120
+ totalMatches: J,
121
+ currentMatchPosition: R,
122
+ currentMatch: q,
123
+ nextMatch: X,
124
+ prevMatch: Z,
125
+ setCurrentMatchPosition: z
122
126
  };
123
127
  };
124
128
  //#endregion
125
- export { b as useSearch };
129
+ export { x as useSearch };
@@ -1,2 +1,2 @@
1
- import { t as e } from "../../useWatermark-CvAAf66v.js";
1
+ import { t as e } from "../../useWatermark-DlRNcg9p.js";
2
2
  export { e as useWatermark };
@@ -2,7 +2,7 @@
2
2
  function e() {
3
3
  if (typeof document > "u" || document.getElementById("rp-print-style")) return;
4
4
  let e = document.createElement("style");
5
- e.id = "rp-print-style", e.textContent = "\n @page { margin: 0; }\n\n .rp-print-zone { display: none; }\n\n @media print {\n .rp-print-html-printing { height: 100%; }\n .rp-print-body-printing { background: rgb(0 0 0 / 0) none; height: 100% !important; margin: 0 !important; display: block !important; }\n .rp-print-body-printing * { display: none; }\n .rp-print-zone { display: block; height: 100%; }\n .rp-print-page { display: flex; align-items: center; flex-direction: column; justify-content: center; height: 100%; width: 100%; page-break-after: always; page-break-inside: avoid; }\n .rp-print-page:last-child { page-break-after: auto; }\n .rp-print-page img, .rp-print-page canvas { display: block; max-width: 100%; max-height: 100%; direction: ltr; }\n }\n ", document.head.appendChild(e);
5
+ e.id = "rp-print-style", e.textContent = "\n @page { margin: 0; }\n\n .rp-print-zone { display: none; }\n\n @media print {\n .rp-print-html-printing { height: 100%; }\n .rp-print-body-printing { background: rgb(0 0 0 / 0) none; height: 100% !important; margin: 0 !important; display: block !important; }\n .rp-print-body-printing > *:not(.rp-print-zone) { display: none; }\n .rp-print-zone { display: block; height: 100%; }\n .rp-print-page { display: flex; align-items: center; flex-direction: column; justify-content: center; height: 100%; width: 100%; page-break-after: always; page-break-inside: avoid; }\n .rp-print-page:last-child { page-break-after: auto; }\n .rp-print-page-content { position: relative; flex: 0 0 auto; }\n .rp-print-page:not(.rp-print-xfa-page) img, .rp-print-page canvas { display: block; max-width: 100%; max-height: 100%; direction: ltr; }\n .rp-print-page.rp-print-xfa-page { display: block; position: relative; }\n .rp-print-xfa-page .xfaPage { position: absolute; }\n }\n ", document.head.appendChild(e);
6
6
  }
7
7
  //#endregion
8
8
  export { e as injectPrintCSS };
@@ -1,5 +1,6 @@
1
+ import { isPdfDestroyed as e, isPdfDocumentDestroyedError as t, runPdfOperation as n } from "./pdfOperationTracker.js";
1
2
  //#region lib/utils/link_service.ts
2
- var e = class {
3
+ var r = class {
3
4
  externalLinkEnabled;
4
5
  pdfDocument;
5
6
  constructor(e, t) {
@@ -19,26 +20,41 @@ var e = class {
19
20
  get isInPresentationMode() {
20
21
  return !1;
21
22
  }
22
- async goToDestination(e) {
23
- let t, n;
24
- if (t = typeof e == "string" ? await this.pdfDocument?.getDestination(e) : await e, !Array.isArray(t)) {
25
- console.error(`goToDestination: "${t}" is not a valid destination array, for dest="${e}".`);
23
+ async goToDestination(r) {
24
+ let i, a;
25
+ if (typeof r == "string") {
26
+ let a = this.pdfDocument;
27
+ if (!a || e(a)) return;
28
+ try {
29
+ i = await n(a, () => a.getDestination(r));
30
+ } catch (e) {
31
+ if (t(e)) return;
32
+ throw e;
33
+ }
34
+ } else i = await r;
35
+ if (!Array.isArray(i)) {
36
+ console.error(`goToDestination: "${i}" is not a valid destination array, for dest="${r}".`);
26
37
  return;
27
38
  }
28
- let [r] = t;
29
- if (r && typeof r == "object") {
30
- if (n = this.pdfDocument?.cachedPageNumber(r), !n) try {
31
- n = (await this.pdfDocument?.getPageIndex(r) || 0) + 1;
32
- } catch {
33
- console.error(`goToDestination: "${r}" is not a valid page reference, for dest="${e}".`);
34
- return;
39
+ let [o] = i;
40
+ if (o && typeof o == "object") {
41
+ if (a = this.pdfDocument?.cachedPageNumber(o), !a) {
42
+ let i = this.pdfDocument;
43
+ if (!i || e(i)) return;
44
+ try {
45
+ a = (await n(i, () => i.getPageIndex(o)) || 0) + 1;
46
+ } catch (e) {
47
+ if (t(e)) return;
48
+ console.error(`goToDestination: "${o}" is not a valid page reference, for dest="${r}".`);
49
+ return;
50
+ }
35
51
  }
36
- } else Number.isInteger(r) && (n = r + 1);
37
- if (!n || n < 1 || n > this.pagesCount) {
38
- console.error(`goToDestination: "${n}" is not a valid page number, for dest="${e}".`);
52
+ } else Number.isInteger(o) && (a = o + 1);
53
+ if (!a || a < 1 || a > this.pagesCount) {
54
+ console.error(`goToDestination: "${a}" is not a valid page number, for dest="${r}".`);
39
55
  return;
40
56
  }
41
- this.goToPage(n);
57
+ this.goToPage(a);
42
58
  }
43
59
  goToPage(e) {}
44
60
  goToXY(e, t, n, r = {}) {}
@@ -57,4 +73,4 @@ var e = class {
57
73
  cachePageRef(e, t) {}
58
74
  };
59
75
  //#endregion
60
- export { e as SimpleLinkService };
76
+ export { r as SimpleLinkService };
@@ -1,6 +1,19 @@
1
1
  //#region lib/utils/pdfOperationTracker.ts
2
- var e = /* @__PURE__ */ new WeakMap();
3
- function t(t, n) {
2
+ var e = /* @__PURE__ */ new WeakMap(), t = /* @__PURE__ */ new WeakSet(), n = class extends Error {
3
+ constructor() {
4
+ super("PDF document has been destroyed"), this.name = "PdfDocumentDestroyedError";
5
+ }
6
+ };
7
+ function r(e) {
8
+ return e instanceof n;
9
+ }
10
+ function i(e) {
11
+ t.add(e);
12
+ }
13
+ function a(e) {
14
+ return e ? t.has(e) ? !0 : e.loadingTask?.destroyed === !0 : !1;
15
+ }
16
+ function o(t, n) {
4
17
  if (!t) return n;
5
18
  let r = e.get(t);
6
19
  r || (r = /* @__PURE__ */ new Set(), e.set(t, r));
@@ -9,9 +22,19 @@ function t(t, n) {
9
22
  r?.delete(i);
10
23
  }), n;
11
24
  }
12
- function n(t) {
25
+ function s(e, t) {
26
+ if (a(e)) return Promise.reject(new n());
27
+ let r;
28
+ try {
29
+ r = t();
30
+ } catch (e) {
31
+ return Promise.reject(e);
32
+ }
33
+ return o(e, r);
34
+ }
35
+ function c(t) {
13
36
  let n = e.get(t);
14
37
  return !n || n.size === 0 ? Promise.resolve() : Promise.allSettled(Array.from(n)).then(() => void 0);
15
38
  }
16
39
  //#endregion
17
- export { t as trackPdfOperation, n as waitForPdfOperations };
40
+ export { n as PdfDocumentDestroyedError, a as isPdfDestroyed, r as isPdfDocumentDestroyedError, i as markPdfDestroying, s as runPdfOperation, o as trackPdfOperation, c as waitForPdfOperations };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf-kit/viewer",
3
- "version": "2.9.2",
3
+ "version": "2.10.0-beta.1",
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": [
@@ -1,114 +0,0 @@
1
- import { AnnotationSubType as e } from "./utils/types.js";
2
- import { trackPdfOperation as t } from "./utils/pdfOperationTracker.js";
3
- import { useDocumentContext as n } from "./contexts/RPDocumentContext.js";
4
- import { useInitialStateContext as r } from "./contexts/InitialStateContext.js";
5
- import { useScrollModeContext as i } from "./contexts/ScrollModeContext.js";
6
- import { r as a } from "./PaginationContext-DIzsZhFd.js";
7
- import { usePrintContext as o } from "./contexts/PrintContext.js";
8
- import { SimpleLinkService as s } from "./utils/link_service.js";
9
- import { annotationEventsHandler as c, bindLayerEvents as l, enhanceLinkAccessibility as u, fixTabIndexAccessibility as d, handleAnnotationWidget as f, insertDateText as p, unbindLayerEvents as m } from "./utils/annotations.js";
10
- import { useFileDownload as h } from "./utils/hooks/useFileDownload.js";
11
- import { useCallback as g, useEffect as _, useMemo as v, useRef as y, useState as b } from "react";
12
- import { AnnotationLayer as x } from "pdfjs-dist";
13
- import { jsx as S } from "react/jsx-runtime";
14
- import './assets/AnnotationLayer.css';//#region lib/components/page/AnnotationLayer.module.css
15
- var C = { "rp-annotation-layer": "_rp-annotation-layer_foiun_1" }, w = "https://unpkg.com/pdfjs-dist@4.4.168/web/images/", T = (T) => {
16
- let { pageNumber: E } = T, D = y(null), { pages: O, pdf: k } = n(), { interactiveForm: A } = r(), j = y(), [M, N] = b(), { goToPage: P } = a(), { scrollMode: F } = i(), { print: I } = o(), { download: L } = h(), R = y(null), z = v(() => O.get(E), [O, E]), B = v(() => z?.page.getViewport(), [z]);
17
- _(() => {
18
- j.current &&= (j.current.div.replaceChildren(), void 0);
19
- }, [k]), _(() => {
20
- z && t(k, z.page.getAnnotations()).then((e) => {
21
- j.current = void 0, N(e), D.current && (D.current.innerText = "");
22
- });
23
- }, [z]);
24
- let V = g((e) => {
25
- !M || !k || (p(D.current), c(e, k, M).then((e) => {
26
- e?.data?.action === "Print" ? I() : e?.data?.action === "SaveAs" && L();
27
- }));
28
- }, [
29
- k,
30
- M,
31
- F,
32
- I,
33
- L
34
- ]);
35
- return _(() => {
36
- if (!z || !M) return;
37
- let t = z.page.getViewport();
38
- if (j.current) {
39
- j.current.update({ viewport: t.clone({ dontFlip: !0 }) });
40
- return;
41
- }
42
- let n = /* @__PURE__ */ new Map([]);
43
- for (let r of M) {
44
- let { annotationType: i } = r;
45
- switch (i) {
46
- case e.Widget:
47
- f(r, t, n);
48
- break;
49
- default: break;
50
- }
51
- }
52
- let r = new AbortController();
53
- return (async () => {
54
- j.current &&= (j.current.div.replaceChildren(), void 0), D.current && (D.current.innerText = ""), j.current = new x({
55
- div: D.current,
56
- accessibilityManager: void 0,
57
- annotationCanvasMap: void 0,
58
- annotationEditorUIManager: void 0,
59
- structTreeLayer: null,
60
- page: z.page,
61
- viewport: t.clone({ dontFlip: !0 }),
62
- commentManager: void 0,
63
- linkService: new s(k, P),
64
- annotationStorage: k?.annotationStorage
65
- }), D.current && m(D.current, V);
66
- let e = await k?.hasJSActions(), n = await k?.getFieldObjects();
67
- if (r.signal.aborted) throw "abort";
68
- return j.current?.render({
69
- annotations: M,
70
- annotationStorage: k?.annotationStorage,
71
- hasJSActions: e,
72
- fieldObjects: n,
73
- div: D.current,
74
- viewport: t.clone({ dontFlip: !0 }),
75
- page: z.page,
76
- imageResourcesPath: w,
77
- renderForms: A ?? !0,
78
- linkService: new s(k, P),
79
- downloadManager: null,
80
- enableScripting: !1
81
- });
82
- })().then(() => {
83
- D.current && (l(D.current, V), d(D.current), u(D.current), R.current && R.current.disconnect(), R.current = new MutationObserver(() => {
84
- D.current && (d(D.current), u(D.current));
85
- }), R.current.observe(D.current, {
86
- childList: !0,
87
- subtree: !0,
88
- attributes: !0,
89
- attributeFilter: ["tabindex", "href"]
90
- }));
91
- }).catch((e) => {
92
- if (e !== "abort") throw e;
93
- }).finally(() => {
94
- j.current = void 0;
95
- }), () => {
96
- r.abort("clear"), D.current && m(D.current, V), R.current &&= (R.current.disconnect(), null);
97
- };
98
- }, [
99
- k,
100
- M,
101
- V,
102
- P
103
- ]), /* @__PURE__ */ S("div", {
104
- "data-rp": `page-${E}-annotationLayer`,
105
- style: {
106
- width: `${B?.width}px`,
107
- height: `${B?.height}px`
108
- },
109
- className: C["rp-annotation-layer"],
110
- ref: D
111
- });
112
- };
113
- //#endregion
114
- export { T as t };
@@ -1,157 +0,0 @@
1
- import { useDocumentContext as e } from "./contexts/RPDocumentContext.js";
2
- import { isMatchEntireWord as t } from "./utils/highlight.js";
3
- import { useHighlightContext as n } from "./contexts/HighlightContext.js";
4
- import { normalizeSingleKeyword as r, sortHighlightPosition as i, unwrap as a } from "./components/page/searchHighlight.js";
5
- import { useEffect as o, useMemo as s, useRef as c, useState as l } from "react";
6
- import { Fragment as u, jsx as d } from "react/jsx-runtime";
7
- import './assets/TextHighlightLayer.css';//#region lib/components/page/TextHighlightLayer.module.css
8
- var f = { "rp-text-highlight": "_rp-text-highlight_jdkf8_1" }, p = ({ pageNumber: p, viewport: m }) => {
9
- let [h, g] = l(), { pages: _ } = e(), { highlightKeywords: v } = n(), y = c(null), [b, x] = l(null), [S, C] = l([]);
10
- o(() => {
11
- y.current && x(y.current.parentElement);
12
- }, [y]), o(() => {
13
- (async () => {
14
- let e = _.get(p);
15
- !e || !y.current || g(await e.page.getTextContent());
16
- })();
17
- }, [_, p]);
18
- let w = s(() => v ? v.map((e) => ({
19
- ...r(e.keyword, e.options?.matchCase, e.options?.wholeWords),
20
- color: e.highlightColor
21
- })) : [], [v]);
22
- function T(e, t) {
23
- if (!e) return;
24
- let n = `[data-rp="page-${t}-textLayer"]`;
25
- return new Promise((t) => {
26
- let r = e.querySelector(n);
27
- if (r) {
28
- t(r);
29
- return;
30
- }
31
- new MutationObserver((r, i) => {
32
- let a = e.querySelector(n);
33
- a && (t(a), i.disconnect());
34
- }).observe(e, {
35
- childList: !0,
36
- subtree: !0
37
- });
38
- });
39
- }
40
- function E(e) {
41
- return new Promise((t) => {
42
- let n = e.querySelectorAll("[data-rp=\"rp-text-layer-text\"]");
43
- if (n.length) {
44
- t(Array.from(n));
45
- return;
46
- }
47
- new MutationObserver((n, r) => {
48
- let i = e.querySelectorAll(".rp-text-layer-text");
49
- i.length && (t(Array.from(i)), r.disconnect());
50
- }).observe(e, {
51
- childList: !0,
52
- subtree: !0
53
- });
54
- });
55
- }
56
- let D = (e, t, n, r) => {
57
- let i = document.createRange(), o = n.firstChild;
58
- if (!o || o.nodeType !== Node.TEXT_NODE) return null;
59
- let s = o.textContent?.length ?? 0, c = r[0].charIdxInSpan, l = r.length === 1 ? c : r[r.length - 1].charIdxInSpan;
60
- if (c > s || l + 1 > s) return null;
61
- i.setStart(o, c), i.setEnd(o, l + 1);
62
- let u = document.createElement("span");
63
- u.style.width = "auto", i.surroundContents(u);
64
- let d = u.getBoundingClientRect(), f = e.getBoundingClientRect(), p = f.height, m = f.width, h = 100 * (d.left - f.left) / m, g = 100 * (d.top - f.top) / p, _ = 100 * d.height / p, v = 100 * d.width / m;
65
- return a(u), {
66
- keywordStr: t,
67
- left: h,
68
- top: g,
69
- height: _,
70
- width: v,
71
- pageHeight: p,
72
- pageWidth: m
73
- };
74
- };
75
- async function O(e, t) {
76
- let n = await T(b, e);
77
- if (!n) return;
78
- let r = await E(n);
79
- r.length && C(k(n, t, r, r.map((e) => e.tagName === "BR" ? " " : e.textContent).reduce((e, t, n) => e.concat(t.split("").map((e, t) => ({
80
- char: e,
81
- charIdxInSpan: t,
82
- spanIdx: n
83
- }))), [{
84
- char: "",
85
- charIdxInSpan: 0,
86
- spanIdx: 0
87
- }]).slice(1)));
88
- }
89
- let k = (e, n, r, a) => {
90
- let o = n.length;
91
- if (!a.length || !o) return [];
92
- let s = [], c = a.map((e) => e.char).join("");
93
- return w.forEach((n) => {
94
- let { keyword: i, regExp: o, wholeWords: l, color: u } = n, d = i;
95
- if (!d.trim()) return;
96
- let f = o.flags.indexOf("g") === -1 ? new RegExp(o, `${o.flags}g`) : o, p, m = [];
97
- for (; (p = f.exec(c)) !== null;) l && !t(c, p.index, p[0].length) || m.push({
98
- keyword: f,
99
- startIndex: p.index,
100
- endIndex: f.lastIndex
101
- });
102
- let h = m.map((e) => ({
103
- keyword: e.keyword,
104
- indexes: a.slice(e.startIndex, e.endIndex),
105
- color: u
106
- }));
107
- for (let t of h) {
108
- let n = t.indexes.reduce((e, t) => (e[t.spanIdx] = (e[t.spanIdx] || []).concat([t]), e), {});
109
- for (let i of Object.values(n)) if (i.length !== 1 || i[0].char.trim() !== "") {
110
- let n = i, a = r[n[0].spanIdx], o = D(e, d, a, n);
111
- if (o) {
112
- let { left: e, top: n } = o;
113
- if (s.find((t) => t.left === e && t.top === n)) continue;
114
- s.push({
115
- ...o,
116
- highlightColor: t.color
117
- });
118
- }
119
- }
120
- }
121
- }), s.sort(i), s;
122
- };
123
- return o(() => {
124
- (async () => {
125
- if (!v || v.length === 0) {
126
- C([]);
127
- return;
128
- }
129
- try {
130
- await O(p, v);
131
- } catch (e) {
132
- console.error(e);
133
- }
134
- })();
135
- }, [
136
- !0,
137
- v,
138
- p,
139
- h,
140
- m
141
- ]), /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d("div", {
142
- ref: y,
143
- "data-rp": `page-${p}-textHighlightLayer`,
144
- children: S.map((e, t) => /* @__PURE__ */ d("div", {
145
- className: f["rp-text-highlight"],
146
- style: {
147
- top: `${e.top}%`,
148
- left: `${e.left}%`,
149
- width: `${e.width}%`,
150
- height: `${e.height}%`,
151
- backgroundColor: e.highlightColor
152
- }
153
- }, t))
154
- }) });
155
- };
156
- //#endregion
157
- export { p as t };