@react-pdf-kit/viewer 0.0.0-experimental.9 → 0.0.0-legacy.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 (155) hide show
  1. package/dist/{Combination-479e39c6.js → Combination-17ab8af1.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 +7 -16
  6. package/dist/components/RPController.js +21 -26
  7. package/dist/components/RPDropFileZone.js +27 -35
  8. package/dist/components/RPPages.js +352 -361
  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 +6 -11
  13. package/dist/components/layout/RPLayout.js +21 -27
  14. package/dist/components/layout/WrapperLayout.js +9 -10
  15. package/dist/components/layout/sidebar/RPSidebar.js +3 -4
  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/DocumentDialog.js +6 -7
  19. package/dist/components/layout/toolbar/DocumentProperties.js +2 -2
  20. package/dist/components/layout/toolbar/FileDownloadTool.js +5 -6
  21. package/dist/components/layout/toolbar/FileUploadTool.js +5 -6
  22. package/dist/components/layout/toolbar/FullScreenTool.js +2 -2
  23. package/dist/components/layout/toolbar/MenuItem.js +2 -2
  24. package/dist/components/layout/toolbar/MenuSeparator.js +2 -2
  25. package/dist/components/layout/toolbar/MostPageTool.js +5 -6
  26. package/dist/components/layout/toolbar/OtherTool.js +5 -6
  27. package/dist/components/layout/toolbar/Paginate.js +3 -4
  28. package/dist/components/layout/toolbar/PrintTool.js +5 -6
  29. package/dist/components/layout/toolbar/RPMenuItem.js +2 -2
  30. package/dist/components/layout/toolbar/RPMoreOptions.js +5 -6
  31. package/dist/components/layout/toolbar/RPToolbar.js +5 -8
  32. package/dist/components/layout/toolbar/RPToolbarEnd.js +5 -6
  33. package/dist/components/layout/toolbar/RotateTool.js +5 -6
  34. package/dist/components/layout/toolbar/ScrollModeTool.js +2 -2
  35. package/dist/components/layout/toolbar/SearchResultNavigator.js +3 -6
  36. package/dist/components/layout/toolbar/SearchTool.js +5 -8
  37. package/dist/components/layout/toolbar/SelectionModeTool.js +2 -2
  38. package/dist/components/layout/toolbar/ThumbnailTool.js +3 -4
  39. package/dist/components/layout/toolbar/ToolbarCustom.js +3 -4
  40. package/dist/components/layout/toolbar/ToolbarDefault.js +5 -8
  41. package/dist/components/layout/toolbar/ToolbarLayout.js +5 -8
  42. package/dist/components/layout/toolbar/ViewModeTool.js +2 -2
  43. package/dist/components/layout/toolbar/ZoomTool.js +5 -6
  44. package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +4 -5
  45. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +7 -13
  46. package/dist/components/layout/toolbar/tools/FileDownloadTool.js +3 -4
  47. package/dist/components/layout/toolbar/tools/FileUploadTool.js +3 -4
  48. package/dist/components/layout/toolbar/tools/FirstPageTool.js +7 -13
  49. package/dist/components/layout/toolbar/tools/InputPageTool.js +3 -4
  50. package/dist/components/layout/toolbar/tools/LastPageTool.js +7 -13
  51. package/dist/components/layout/toolbar/tools/NextPageTool.js +3 -4
  52. package/dist/components/layout/toolbar/tools/PreviousPageTool.js +3 -4
  53. package/dist/components/layout/toolbar/tools/PrintTool.js +3 -4
  54. package/dist/components/layout/toolbar/tools/RotateClockwiseTool.js +3 -4
  55. package/dist/components/layout/toolbar/tools/RotateCounterclockwiseTool.js +3 -4
  56. package/dist/components/layout/toolbar/tools/ThumbnailTool.js +3 -4
  57. package/dist/components/layout/toolbar/tools/ZoomInTool.js +3 -4
  58. package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +15 -16
  59. package/dist/components/layout/toolbar/tools/ZoomOutTool.js +3 -4
  60. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +5 -8
  61. package/dist/components/layout/toolbar/tools/defaults/RPVerticalBar.js +3 -4
  62. package/dist/components/layout/toolbar/tools/more-options/DocumentProperties.js +2 -2
  63. package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +5 -6
  64. package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +5 -6
  65. package/dist/components/layout/toolbar/tools/more-options/FullScreenTool.js +2 -2
  66. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +5 -6
  67. package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +5 -6
  68. package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +5 -6
  69. package/dist/components/layout/toolbar/tools/more-options/ScrollModeTool.js +2 -2
  70. package/dist/components/layout/toolbar/tools/more-options/SelectionModeTool.js +2 -2
  71. package/dist/components/layout/toolbar/tools/more-options/ViewModeTool.js +2 -2
  72. package/dist/components/page/AnnotationLayer.js +72 -69
  73. package/dist/components/page/CanvasLayer.js +3 -4
  74. package/dist/components/page/CustomElement.js +3 -4
  75. package/dist/components/page/DualPage.js +5 -11
  76. package/dist/components/page/DualPageWithCover.js +5 -11
  77. package/dist/components/page/RPPage.js +6 -12
  78. package/dist/components/page/SinglePage.js +5 -11
  79. package/dist/components/page/TextHighlightLayer.js +178 -86
  80. package/dist/components/page/TextLayer.js +170 -125
  81. package/dist/components/ui/DropDown.js +2 -2
  82. package/dist/components/ui/LoadingIndicator.js +7 -8
  83. package/dist/contexts/ConfigContext.js +4 -5
  84. package/dist/contexts/DimensionPagesContext.js +5 -6
  85. package/dist/contexts/DropFileZoneContext.js +4 -5
  86. package/dist/contexts/ElementPageContext.js +5 -6
  87. package/dist/contexts/FileInputContext.js +5 -6
  88. package/dist/contexts/HighlightContext.js +7 -10
  89. package/dist/contexts/LicenseContext.js +6 -8
  90. package/dist/contexts/PagesRotateContext.js +5 -6
  91. package/dist/contexts/PaginationContext.js +5 -6
  92. package/dist/contexts/PrintContext.js +16 -17
  93. package/dist/contexts/RPDocumentContext.js +13 -14
  94. package/dist/contexts/RenderQueueProvider.js +5 -6
  95. package/dist/contexts/RotationContext.js +8 -9
  96. package/dist/contexts/SearchContext.js +5 -8
  97. package/dist/contexts/ThumbnailsContext.js +4 -5
  98. package/dist/contexts/ZoomContext.js +5 -6
  99. package/dist/{index-535ad364.js → index-11f3cd64.js} +1 -1
  100. package/dist/main.js +115 -120
  101. package/dist/polyfills.js +8166 -0
  102. package/dist/types/components/layout/sidebar/Thumbnail.d.ts +2 -2
  103. package/dist/types/contexts/RPDocumentContext.d.ts +1 -1
  104. package/dist/types/contexts/RenderQueueProvider.d.ts +1 -1
  105. package/dist/types/contexts/RenderedPagesCache.d.ts +2 -2
  106. package/dist/types/main.d.ts +1 -1
  107. package/dist/types/utils/annotations.d.ts +2 -2
  108. package/dist/types/utils/getThumbnailViewport.d.ts +2 -2
  109. package/dist/types/utils/highlight.d.ts +5 -5
  110. package/dist/types/utils/hooks/useFlickerSelectText.d.ts +1 -0
  111. package/dist/types/utils/hooks/useHighlight.d.ts +1 -1
  112. package/dist/types/utils/hooks/useLoadPdf.d.ts +2 -2
  113. package/dist/types/utils/hooks/useLoadWorker.d.ts +1 -5
  114. package/dist/types/utils/hooks/usePdfProperties.d.ts +1 -1
  115. package/dist/types/utils/hooks/useTextSelection.d.ts +3 -12
  116. package/dist/types/utils/link_service.d.ts +3 -2
  117. package/dist/types/utils/renderPage.d.ts +2 -2
  118. package/dist/types/utils/types.d.ts +8 -9
  119. package/dist/utils/highlight.js +158 -184
  120. package/dist/utils/hooks/useCopyText.js +22 -60
  121. package/dist/utils/hooks/useFileDownload.js +5 -6
  122. package/dist/utils/hooks/useFlickerSelectText.js +25 -0
  123. package/dist/utils/hooks/useHighlight.js +33 -35
  124. package/dist/utils/hooks/useLicense.js +29 -38
  125. package/dist/utils/hooks/useLoadPdf.js +80 -103
  126. package/dist/utils/hooks/useLoadWorker.js +14 -4
  127. package/dist/utils/hooks/usePageRotateContext.js +7 -8
  128. package/dist/utils/hooks/usePaginate.js +3 -4
  129. package/dist/utils/hooks/usePinch.js +10 -11
  130. package/dist/utils/hooks/usePresentPage.js +3 -4
  131. package/dist/utils/hooks/usePrint.js +78 -74
  132. package/dist/utils/hooks/useRotate.js +3 -4
  133. package/dist/utils/hooks/useScrollToPage.js +3 -4
  134. package/dist/utils/hooks/useSearch.js +15 -18
  135. package/dist/utils/hooks/useTextSelection.js +73 -2
  136. package/dist/utils/hooks/useThumbnail.js +17 -18
  137. package/dist/utils/hooks/useVirtualReactWindow.js +3 -4
  138. package/dist/utils/hooks/useWatermark.js +6 -8
  139. package/dist/utils/link_service.js +19 -18
  140. package/dist/utils/renderPage.js +1 -1
  141. package/dist/utils/types.js +3 -3
  142. package/package.json +14 -3
  143. package/dist/RPLayout.module-7766e0b4.js +0 -14
  144. package/dist/contexts/LayoutDropFileZoneContext.js +0 -11
  145. package/dist/contexts/TextSelectionContext.js +0 -191
  146. package/dist/types/contexts/LayoutDropFileZoneContext.d.ts +0 -9
  147. package/dist/types/contexts/TextSelectionContext.d.ts +0 -14
  148. package/dist/types/utils/geometryCache.d.ts +0 -15
  149. package/dist/types/utils/glyphHitTest.d.ts +0 -12
  150. package/dist/types/utils/hooks/useDropFileZone.d.ts +0 -5
  151. package/dist/types/utils/selectionUtils.d.ts +0 -30
  152. package/dist/utils/geometryCache.js +0 -32
  153. package/dist/utils/glyphHitTest.js +0 -29
  154. package/dist/utils/hooks/useDropFileZone.js +0 -12
  155. package/dist/utils/selectionUtils.js +0 -96
@@ -1,11 +1,9 @@
1
1
  import { useState as f, useCallback as p, useEffect as w } from "react";
2
2
  import { getHighlightOptionsWithDefaults as k, findMatches as P } from "../highlight.js";
3
3
  import "../charators.js";
4
- import "../selectionUtils.js";
5
- import "../geometryCache.js";
6
4
  const x = (n) => {
7
- const e = Math.min(...n.map((s) => s.left)), r = Math.max(...n.map((s) => s.left + s.width)), o = Math.min(...n.map((s) => s.bottom)), t = Math.max(...n.map((s) => s.height));
8
- return { left: e, bottom: o, width: r - e, height: t };
5
+ const e = Math.min(...n.map((s) => s.left)), c = Math.max(...n.map((s) => s.left + s.width)), o = Math.min(...n.map((s) => s.bottom)), t = Math.max(...n.map((s) => s.height));
6
+ return { left: e, bottom: o, width: c - e, height: t };
9
7
  }, N = (n) => n.flatMap((e) => e.rects ?? (e.rect ? [e.rect] : [])), O = (n) => {
10
8
  const e = n.reduce((o, t) => {
11
9
  const s = Math.round(t.bottom);
@@ -14,17 +12,17 @@ const x = (n) => {
14
12
  return Object.entries(e).sort((o, t) => Number(t[0]) - Number(o[0])).map(([o, t]) => x(t));
15
13
  }, L = (n) => {
16
14
  const e = {};
17
- for (const r of n) {
18
- const o = r.keyword, t = e[o] ?? [];
19
- t.push(r), e[o] = t;
15
+ for (const c of n) {
16
+ const o = c.keyword, t = e[o] ?? [];
17
+ t.push(c), e[o] = t;
20
18
  }
21
19
  return e;
22
20
  }, j = (n, e) => {
23
- const r = n[0], o = N(n), t = o.length > 0 ? O(o) : r.rect ? [r.rect] : [];
21
+ const c = n[0], o = N(n), t = o.length > 0 ? O(o) : c.rect ? [c.rect] : [];
24
22
  return {
25
- ...r,
23
+ ...c,
26
24
  pageMatchIdx: e,
27
- rect: t[0] ?? r.rect,
25
+ rect: t[0] ?? c.rect,
28
26
  rects: t
29
27
  };
30
28
  }, v = (n) => {
@@ -33,53 +31,53 @@ const x = (n) => {
33
31
  const s = e[t.page] ?? [];
34
32
  s.push(t), e[t.page] = s;
35
33
  }
36
- let r = 0;
34
+ let c = 0;
37
35
  const o = [];
38
36
  for (const t of Object.values(e)) {
39
37
  const s = L(t);
40
38
  for (const g of Object.values(s))
41
- o.push(j(g, r++));
39
+ o.push(j(g, c++));
42
40
  }
43
41
  return o;
44
- }, I = (n) => {
45
- const [e, r] = f(void 0), [o, t] = f([]), s = p(async (c) => {
46
- if (!c)
42
+ }, K = (n) => {
43
+ const [e, c] = f(void 0), [o, t] = f([]), s = p(async (r) => {
44
+ if (!r)
47
45
  return {};
48
- const a = c.numPages, i = {};
49
- for (let h = 1; h <= a; h++) {
50
- const u = await c.getPage(h);
51
- i[h.toString()] = await u.getTextContent();
46
+ const i = r.numPages, h = {};
47
+ for (let a = 1; a <= i; a++) {
48
+ const u = await r.getPage(a);
49
+ h[a.toString()] = await u.getTextContent();
52
50
  }
53
- return i;
54
- }, []), g = p(async (c) => {
55
- r(c);
51
+ return h;
52
+ }, []), g = p(async (r) => {
53
+ c(r);
56
54
  }, []), l = p(() => {
57
- t([]), r(void 0);
55
+ t([]), c(void 0);
58
56
  }, []);
59
57
  return w(() => {
60
- n && s(n).then((c) => {
61
- let a = [];
62
- for (const { keyword: i, highlightColor: h, options: u } of e) {
63
- if (!i)
58
+ n && s(n).then((r) => {
59
+ let i = [];
60
+ for (const { keyword: h, highlightColor: a, options: u } of e) {
61
+ if (!h)
64
62
  continue;
65
63
  const b = k(u);
66
- for (const m of Object.keys(c)) {
64
+ for (const m of Object.keys(r)) {
67
65
  const d = P(
68
- [i],
69
- c[m],
66
+ [h],
67
+ r[m],
70
68
  Number(m) - 1,
71
69
  b
72
70
  ).map((M, y) => ({
73
71
  ...M,
74
72
  page: Number(m),
75
73
  pageMatchIdx: y,
76
- color: h,
77
- keyword: i
74
+ color: a,
75
+ keyword: h
78
76
  }));
79
- a = [...a, ...d];
77
+ i = [...i, ...d];
80
78
  }
81
79
  }
82
- t(v(a));
80
+ t(v(i));
83
81
  }).catch(() => {
84
82
  l();
85
83
  });
@@ -91,5 +89,5 @@ const x = (n) => {
91
89
  };
92
90
  };
93
91
  export {
94
- I as useHighlight
92
+ K as useHighlight
95
93
  };
@@ -1,29 +1,27 @@
1
- import { useState as h, useCallback as E, useEffect as A } from "react";
2
- import { LicenseType as b } from "../types.js";
1
+ import { useState as E, useCallback as h, useEffect as A } from "react";
3
2
  import { appConsole as l } from "../appConsole.js";
4
- import "../../de_DE-a553b162.js";
5
- const L = /* @__PURE__ */ new Date("2026-03-26T05:34:18.450Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", s = {
3
+ const b = /* @__PURE__ */ new Date("2026-05-06T16:14:18.520Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", s = {
6
4
  invalidLicense: `You are currently using without a valid license. ${d}`,
7
5
  mismatchedDomain: `Your license key is not valid for the current domain / IP. ${d}`,
8
6
  expired: `Your license key has expired. ${d}`,
9
7
  exceededVersion: "Your license does not support the current version of React PDF. The library version you are using exceeds the supported range of your license.",
10
8
  invalidSignature: "Invalid license key: Signature mismatch"
11
9
  };
12
- function S(n) {
13
- const t = n.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s+/g, ""), e = atob(t), r = new Uint8Array(e.length);
10
+ function L(r) {
11
+ const t = r.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s+/g, ""), e = atob(t), n = new Uint8Array(e.length);
14
12
  for (let i = 0; i < e.length; i++)
15
- r[i] = e.charCodeAt(i);
16
- return r.buffer;
13
+ n[i] = e.charCodeAt(i);
14
+ return n.buffer;
17
15
  }
18
- function y(n) {
19
- const t = atob(n), e = new Uint8Array(t.length);
20
- for (let r = 0; r < t.length; r++)
21
- e[r] = t.charCodeAt(r);
16
+ function S(r) {
17
+ const t = atob(r), e = new Uint8Array(t.length);
18
+ for (let n = 0; n < t.length; n++)
19
+ e[n] = t.charCodeAt(n);
22
20
  return e.buffer;
23
21
  }
24
- async function I(n, t = "SHA-256") {
22
+ async function I(r, t = "SHA-256") {
25
23
  try {
26
- const { data: e, signature: r } = JSON.parse(atob(n)), i = S(`-----BEGIN PUBLIC KEY-----
24
+ const { data: e, signature: n } = JSON.parse(atob(r)), i = L(`-----BEGIN PUBLIC KEY-----
27
25
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIokvErJ0Fctu0jduSAx
28
26
  gr+5Har/VSuZLlOunS28hnlqqA+OF1apHL7RYkjBosS15yvviYdLrVWYHpHnoY4b
29
27
  HLQ9I6YX6FMB9T/VbB4xLdVdKvfi8r49aTScl5EKuSpgpPgz2VSJTfvVGcRuth/Y
@@ -42,7 +40,7 @@ kwIDAQAB
42
40
  if (!await window.crypto.subtle.verify(
43
41
  { name: "RSA-PSS", saltLength: 32 },
44
42
  a,
45
- y(r),
43
+ S(n),
46
44
  // Convert signature to ArrayBuffer
47
45
  new TextEncoder().encode(atob(e))
48
46
  ))
@@ -52,53 +50,46 @@ kwIDAQAB
52
50
  throw new Error(s.invalidLicense);
53
51
  }
54
52
  }
55
- const T = (n, t) => {
56
- switch (n) {
57
- case "specific":
58
- return t === window.location.host;
59
- case "wildcard":
60
- return t ? window.location.host.includes(t) : !1;
61
- }
62
- }, u = {
53
+ const y = (r, t) => r === "specific" ? t === window.location.host : window.location.host.includes(t), u = {
63
54
  isValid: !0,
64
55
  invalidatedMessage: s.invalidLicense,
65
56
  type: void 0
66
- }, Y = (n) => {
67
- const [t, e] = h(u), r = E(async () => {
68
- if (e((c) => ({ ...c, validating: !0 })), !n)
57
+ }, x = (r) => {
58
+ const [t, e] = E(u), n = h(async () => {
59
+ if (e((c) => ({ ...c, validating: !0 })), !r)
69
60
  throw e({ ...u, validating: !1 }), new Error(s.invalidLicense);
70
61
  let i;
71
62
  try {
72
- i = await I(n);
63
+ i = await I(r);
73
64
  } catch (c) {
74
65
  throw l.warn(c.message), new Error(c.message);
75
66
  }
76
67
  l.debug(">>> validatedLicense", i);
77
- const { avu: a, exp: o, dmt: w, dm: p, t: m } = i;
68
+ const { avu: a, exp: o, dmt: m, dm: w, t: f } = i;
78
69
  if (!o)
79
70
  throw new Error("License is missing expiration timestamp");
80
71
  if (o > Number.MAX_SAFE_INTEGER / 1e3)
81
72
  throw new Error("Invalid expiration timestamp: value too large");
82
- const v = new Date(o * 1e3), g = (/* @__PURE__ */ new Date()).getTime();
83
- if (v.getTime() < g)
73
+ const p = new Date(o * 1e3), g = (/* @__PURE__ */ new Date()).getTime();
74
+ if (p.getTime() < g)
84
75
  throw new Error(s.expired);
85
76
  if (!a)
86
77
  throw new Error("License is missing available until version timestamp");
87
78
  if (a > Number.MAX_SAFE_INTEGER / 1e3)
88
79
  throw new Error("Invalid available until version timestamp: value too large");
89
- const f = new Date(a * 1e3);
90
- if (l.debug("availableUntilTimestamp", f), f.getTime() < L.getTime())
80
+ const v = new Date(a * 1e3);
81
+ if (l.debug("availableUntilTimestamp", v), v.getTime() < b.getTime())
91
82
  throw new Error(s.exceededVersion);
92
- if (m !== b.Custom && !T(w, p))
83
+ if (!y(m, w))
93
84
  throw new Error(s.mismatchedDomain);
94
85
  return {
95
86
  isValid: !0,
96
- type: m,
87
+ type: f,
97
88
  invalidatedMessage: void 0
98
89
  };
99
- }, [n]);
90
+ }, [r]);
100
91
  return A(() => {
101
- r().then(({ isValid: i, type: a, invalidatedMessage: o }) => {
92
+ n().then(({ isValid: i, type: a, invalidatedMessage: o }) => {
102
93
  e({
103
94
  isValid: i,
104
95
  type: a,
@@ -112,8 +103,8 @@ const T = (n, t) => {
112
103
  validating: !1
113
104
  }), l.warn(i.message);
114
105
  });
115
- }, [r]), t;
106
+ }, [n]), t;
116
107
  };
117
108
  export {
118
- Y as useLicense
109
+ x as useLicense
119
110
  };
@@ -1,118 +1,95 @@
1
- import { useState as h, useRef as I, useEffect as P } from "react";
2
- import { init as F } from "@pdf-viewer/pdfium";
3
- import { createDocumentProxy as N } from "@pdf-viewer/pdfium/compat";
4
- import { ErrorType as O } from "../types.js";
5
- import { getThumbnailViewport as q } from "../getThumbnailViewport.js";
6
- import { useConfigContext as v } from "../../contexts/ConfigContext.js";
7
- import { useDocumentPasswordContext as B } from "../../contexts/DocumentPasswordContext.js";
1
+ import { useState as u, useRef as O, useEffect as h } from "react";
2
+ import * as C from "pdfjs-dist";
3
+ import { ErrorType as $ } from "../types.js";
4
+ import { getThumbnailViewport as A } from "../getThumbnailViewport.js";
5
+ import { useConfigContext as j } from "../../contexts/ConfigContext.js";
6
+ import { useDocumentPasswordContext as z } from "../../contexts/DocumentPasswordContext.js";
8
7
  import "../../de_DE-a553b162.js";
9
8
  import "react/jsx-runtime";
10
9
  import "../appConsole.js";
11
- async function W(t, c) {
12
- const a = await fetch(typeof t == "string" ? t : t.href);
13
- if (!a.ok)
14
- throw new Error(`Failed to fetch PDF: ${a.status} ${a.statusText}`);
15
- const o = a.headers.get("content-length"), l = o ? parseInt(o, 10) : 0;
16
- if (!a.body || !l) {
17
- const n = await a.arrayBuffer();
18
- return c == null || c(100), n;
19
- }
20
- const y = a.body.getReader(), p = [];
21
- let m = 0;
22
- for (; ; ) {
23
- const { done: n, value: i } = await y.read();
24
- if (n)
25
- break;
26
- p.push(i), m += i.length, l && (c == null || c(Math.min(100, Math.round(m / l * 100))));
27
- }
28
- const w = new Uint8Array(m);
29
- let s = 0;
30
- for (const n of p)
31
- w.set(n, s), s += n.length;
32
- return w.buffer;
33
- }
34
- const re = (t, c, a = {}) => {
35
- const [o, l] = h(), { workerUrlAdded: y, wasmUrl: p } = v(), [m, w] = h(/* @__PURE__ */ new Map()), s = I(), [n, i] = h(0), [D, _] = h(!1), [T, M] = h(), { password: x, passwordError: V, setPasswordError: b, passwordRequired: E, setPasswordRequired: R } = B(), {
36
- onLoadError: A,
37
- onLoaded: L,
38
- onLoadProgress: S,
39
- disableAutoFetch: $,
40
- disableStream: z,
41
- rangeChunkSize: Q
42
- } = a, u = I();
43
- return P(() => {
44
- S && S(n);
45
- }, [n, S]), P(() => {
46
- if (!y || !t)
10
+ const X = (g, t, V = {}) => {
11
+ const [r, D] = u(), { workerUrlAdded: S } = j(), [I, q] = u(/* @__PURE__ */ new Map()), d = O(), [p, L] = u(0), [f, x] = u(!1), [U, F] = u(), { password: a, passwordError: N, setPasswordError: w, passwordRequired: k, setPasswordRequired: E } = z(), { onLoadError: i, onLoaded: b, onLoadProgress: v, disableAutoFetch: y, disableStream: R, rangeChunkSize: T } = V;
12
+ return h(() => {
13
+ v && v(p);
14
+ }, [p, v]), h(() => {
15
+ if (!S) {
16
+ console.log("useLoadPdf: skipping worker URL not yet added");
47
17
  return;
48
- i(0), s.current = Date.now();
49
- const f = s.current;
50
- let d = !1;
51
- return (async () => {
52
- try {
53
- _(!0);
54
- let e;
55
- if (t instanceof ArrayBuffer)
56
- e = t, i(100);
57
- else if (t instanceof Uint8Array)
58
- e = t.buffer, i(100);
59
- else if (typeof t == "string" || t instanceof URL)
60
- e = await W(t, (U) => {
61
- f === s.current && i(U);
62
- });
63
- else
64
- throw new Error("Unsupported PDF source type");
65
- if (d || f !== s.current || ((!u.current || u.current.isDestroyed) && (u.current = await F({ wasmUrl: p })), d || f !== s.current))
66
- return;
67
- const r = u.current.openDocument(e, x || void 0), g = N(r, e);
68
- f === s.current && (l(g), i(100)), L && L(g), R(!1), b("");
69
- } catch (e) {
70
- if (d)
71
- return;
72
- const r = e;
73
- r.code === "PASSWORD_REQUIRED" ? (R(!0), b(r.message || "Password required")) : r.code === "INVALID_PASSWORD" ? (R(!0), b("Incorrect password")) : (M(O.NOT_SUPPORTED), A && A(e));
74
- } finally {
75
- d || _(!1);
76
- }
77
- })(), () => {
78
- d = !0;
18
+ }
19
+ if (!g) {
20
+ console.log("useLoadPdf: skipping no src provided");
21
+ return;
22
+ }
23
+ console.log("useLoadPdf: starting load", { src: g, password: !!a, disableAutoFetch: y, disableStream: R, rangeChunkSize: T }), L(0), d.current = Date.now();
24
+ const s = d.current, c = {
25
+ url: g,
26
+ cMapPacked: (t == null ? void 0 : t.isCompressed) ?? !0,
27
+ ...(t == null ? void 0 : t.url) && { cMapUrl: t.url },
28
+ ...a && { password: a },
29
+ ...y !== void 0 && { disableAutoFetch: y },
30
+ ...R !== void 0 && { disableStream: R },
31
+ ...T !== void 0 && { rangeChunkSize: T },
32
+ verbosity: C.VerbosityLevel.ERRORS
79
33
  };
80
- }, [t, y, p, x, A, L]), P(() => {
81
- if (E)
34
+ try {
35
+ const e = C.getDocument(c);
36
+ e.onProgress = (o) => {
37
+ if (s === d.current) {
38
+ const { loaded: P, total: l } = o, m = l ? Math.min(100, Math.round(P / l * 100)) : 0;
39
+ console.log(`useLoadPdf: progress ${m}% (${P}/${l})`), L(m);
40
+ }
41
+ }, x(!0);
42
+ const n = e.promise.then((o) => (s === d.current ? (console.log("useLoadPdf: document loaded", { numPages: o.numPages, taskId: s }), D(o), L(100)) : console.log("useLoadPdf: stale task resolved, ignoring", { taskId: s, latestTask: d.current }), b && b(o), E(!1), w(""), o)).catch((o) => {
43
+ o instanceof Error && o.name === "PasswordException" ? (console.log("useLoadPdf: password required", o.message), E(!0), w(o.message || "Password required")) : o instanceof Error && o.name === "InvalidPDFException" && a ? (console.log("useLoadPdf: invalid PDF / incorrect password", o.message), E(!0), w("Incorrect password")) : (console.log("useLoadPdf: load error", o), i && i(o));
44
+ }).finally(() => {
45
+ console.log("useLoadPdf: loading finished, setting loading=false"), x(!1);
46
+ });
47
+ return () => {
48
+ n.finally(() => {
49
+ e.destroy();
50
+ });
51
+ };
52
+ } catch (e) {
53
+ console.log("useLoadPdf: synchronous error in getDocument", e), F($.NOT_SUPPORTED), i && i(e);
54
+ }
55
+ }, [g, S, a, i, b]), h(() => {
56
+ if (k) {
57
+ console.log("useLoadPdf: skipping page load — password required");
82
58
  return;
83
- const f = /* @__PURE__ */ new Map();
84
- if (!o || D) {
85
- w(f);
59
+ }
60
+ const s = /* @__PURE__ */ new Map();
61
+ if (!r || f) {
62
+ console.log("useLoadPdf: skipping page load", { pdf: !!r, loading: f }), q(s);
86
63
  return;
87
64
  }
88
- const d = o.numPages, k = [];
89
- for (let e = 1; e <= d; e++) {
90
- const r = o.getPage(e);
91
- k.push(r);
65
+ const c = r.numPages;
66
+ console.log("useLoadPdf: loading pages", { totalPage: c });
67
+ const e = [];
68
+ for (let n = 1; n <= c; n++) {
69
+ const o = r.getPage(n);
70
+ e.push(o);
92
71
  }
93
- Promise.all(k).then((e) => {
94
- e.map((r) => {
95
- const { thumbnailViewport: g, scale: U } = q(r), C = r.getViewport();
96
- f.set(r.pageNumber, {
97
- page: r,
98
- thumbnailViewport: g,
99
- thumbnailScale: U,
100
- defaultRotation: C.rotation
72
+ Promise.all(e).then((n) => {
73
+ console.log("useLoadPdf: all pages loaded", { count: n.length }), n.map((o) => {
74
+ const { thumbnailViewport: P, scale: l } = A(o), m = o.getViewport();
75
+ s.set(o.pageNumber, {
76
+ page: o,
77
+ thumbnailViewport: P,
78
+ thumbnailScale: l,
79
+ defaultRotation: m.rotation
101
80
  });
102
- }), w(f);
81
+ }), q(s);
103
82
  });
104
- }, [o, D, E]), P(() => () => {
105
- o && o.destroy(), u.current && !u.current.isDestroyed && u.current.destroy();
106
- }, []), {
107
- pdf: o,
108
- pages: m,
109
- loading: D,
110
- error: T,
111
- loadingProgress: n,
112
- passwordRequired: E,
113
- passwordError: V
83
+ }, [r, f, k]), {
84
+ pdf: r,
85
+ pages: I,
86
+ loading: f,
87
+ error: U,
88
+ loadingProgress: p,
89
+ passwordRequired: k,
90
+ passwordError: N
114
91
  };
115
92
  };
116
93
  export {
117
- re as useLoadPdf
94
+ X as useLoadPdf
118
95
  };