@react-pdf-kit/viewer 0.0.0-experimental.8 → 0.0.0-experimental.9

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 (130) hide show
  1. package/dist/RPLayout.module-7766e0b4.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 +11 -12
  5. package/dist/components/RPController.js +26 -21
  6. package/dist/components/RPDropFileZone.js +8 -7
  7. package/dist/components/RPPages.js +360 -351
  8. package/dist/components/RPProvider.js +24 -20
  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 +7 -4
  12. package/dist/components/layout/RPLayout.js +7 -4
  13. package/dist/components/layout/WrapperLayout.js +4 -3
  14. package/dist/components/layout/sidebar/RPSidebar.js +4 -3
  15. package/dist/components/layout/sidebar/Thumbnail.js +4 -3
  16. package/dist/components/layout/sidebar/Thumbnails.js +4 -3
  17. package/dist/components/layout/toolbar/DocumentDialog.js +6 -5
  18. package/dist/components/layout/toolbar/FileDownloadTool.js +4 -3
  19. package/dist/components/layout/toolbar/FileUploadTool.js +4 -3
  20. package/dist/components/layout/toolbar/MostPageTool.js +4 -3
  21. package/dist/components/layout/toolbar/OtherTool.js +4 -3
  22. package/dist/components/layout/toolbar/Paginate.js +4 -3
  23. package/dist/components/layout/toolbar/PrintTool.js +4 -3
  24. package/dist/components/layout/toolbar/RPMoreOptions.js +4 -3
  25. package/dist/components/layout/toolbar/RPToolbar.js +6 -3
  26. package/dist/components/layout/toolbar/RPToolbarEnd.js +4 -3
  27. package/dist/components/layout/toolbar/RotateTool.js +4 -3
  28. package/dist/components/layout/toolbar/SearchResultNavigator.js +6 -3
  29. package/dist/components/layout/toolbar/SearchTool.js +6 -3
  30. package/dist/components/layout/toolbar/ThumbnailTool.js +4 -3
  31. package/dist/components/layout/toolbar/ToolbarCustom.js +4 -3
  32. package/dist/components/layout/toolbar/ToolbarDefault.js +6 -3
  33. package/dist/components/layout/toolbar/ToolbarLayout.js +6 -3
  34. package/dist/components/layout/toolbar/ZoomTool.js +4 -3
  35. package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +4 -3
  36. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +9 -5
  37. package/dist/components/layout/toolbar/tools/FileDownloadTool.js +4 -3
  38. package/dist/components/layout/toolbar/tools/FileUploadTool.js +4 -3
  39. package/dist/components/layout/toolbar/tools/FirstPageTool.js +9 -5
  40. package/dist/components/layout/toolbar/tools/InputPageTool.js +4 -3
  41. package/dist/components/layout/toolbar/tools/LastPageTool.js +9 -5
  42. package/dist/components/layout/toolbar/tools/NextPageTool.js +4 -3
  43. package/dist/components/layout/toolbar/tools/PreviousPageTool.js +4 -3
  44. package/dist/components/layout/toolbar/tools/PrintTool.js +4 -3
  45. package/dist/components/layout/toolbar/tools/RotateClockwiseTool.js +4 -3
  46. package/dist/components/layout/toolbar/tools/RotateCounterclockwiseTool.js +4 -3
  47. package/dist/components/layout/toolbar/tools/ThumbnailTool.js +4 -3
  48. package/dist/components/layout/toolbar/tools/ZoomInTool.js +4 -3
  49. package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +14 -13
  50. package/dist/components/layout/toolbar/tools/ZoomOutTool.js +4 -3
  51. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +6 -3
  52. package/dist/components/layout/toolbar/tools/defaults/RPVerticalBar.js +4 -3
  53. package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +4 -3
  54. package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +4 -3
  55. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +4 -3
  56. package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +4 -3
  57. package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +4 -3
  58. package/dist/components/page/AnnotationLayer.js +69 -72
  59. package/dist/components/page/CanvasLayer.js +4 -3
  60. package/dist/components/page/CustomElement.js +4 -3
  61. package/dist/components/page/DualPage.js +11 -5
  62. package/dist/components/page/DualPageWithCover.js +11 -5
  63. package/dist/components/page/RPPage.js +12 -6
  64. package/dist/components/page/SinglePage.js +11 -5
  65. package/dist/components/page/TextHighlightLayer.js +86 -178
  66. package/dist/components/page/TextLayer.js +125 -170
  67. package/dist/components/ui/LoadingIndicator.js +8 -7
  68. package/dist/contexts/DimensionPagesContext.js +6 -5
  69. package/dist/contexts/DropFileZoneContext.js +5 -4
  70. package/dist/contexts/ElementPageContext.js +6 -5
  71. package/dist/contexts/FileInputContext.js +6 -5
  72. package/dist/contexts/HighlightContext.js +10 -7
  73. package/dist/contexts/PagesRotateContext.js +6 -5
  74. package/dist/contexts/PaginationContext.js +6 -5
  75. package/dist/contexts/PrintContext.js +17 -16
  76. package/dist/contexts/RPDocumentContext.js +14 -13
  77. package/dist/contexts/RenderQueueProvider.js +6 -5
  78. package/dist/contexts/RotationContext.js +9 -8
  79. package/dist/contexts/SearchContext.js +8 -5
  80. package/dist/contexts/TextSelectionContext.js +191 -0
  81. package/dist/contexts/ThumbnailsContext.js +5 -4
  82. package/dist/contexts/ZoomContext.js +6 -5
  83. package/dist/main.js +116 -113
  84. package/dist/types/components/layout/sidebar/Thumbnail.d.ts +2 -2
  85. package/dist/types/contexts/RPDocumentContext.d.ts +1 -1
  86. package/dist/types/contexts/RenderQueueProvider.d.ts +1 -1
  87. package/dist/types/contexts/RenderedPagesCache.d.ts +2 -2
  88. package/dist/types/contexts/TextSelectionContext.d.ts +14 -0
  89. package/dist/types/main.d.ts +1 -1
  90. package/dist/types/utils/annotations.d.ts +2 -2
  91. package/dist/types/utils/geometryCache.d.ts +15 -0
  92. package/dist/types/utils/getThumbnailViewport.d.ts +2 -2
  93. package/dist/types/utils/glyphHitTest.d.ts +12 -0
  94. package/dist/types/utils/highlight.d.ts +5 -5
  95. package/dist/types/utils/hooks/useHighlight.d.ts +1 -1
  96. package/dist/types/utils/hooks/useLoadPdf.d.ts +2 -2
  97. package/dist/types/utils/hooks/useLoadWorker.d.ts +5 -1
  98. package/dist/types/utils/hooks/usePdfProperties.d.ts +1 -1
  99. package/dist/types/utils/hooks/useTextSelection.d.ts +12 -3
  100. package/dist/types/utils/link_service.d.ts +2 -3
  101. package/dist/types/utils/renderPage.d.ts +2 -2
  102. package/dist/types/utils/selectionUtils.d.ts +30 -0
  103. package/dist/types/utils/types.d.ts +5 -7
  104. package/dist/utils/geometryCache.js +32 -0
  105. package/dist/utils/glyphHitTest.js +29 -0
  106. package/dist/utils/highlight.js +184 -158
  107. package/dist/utils/hooks/useCopyText.js +60 -22
  108. package/dist/utils/hooks/useFileDownload.js +6 -5
  109. package/dist/utils/hooks/useHighlight.js +35 -33
  110. package/dist/utils/hooks/useLicense.js +62 -62
  111. package/dist/utils/hooks/useLoadPdf.js +102 -70
  112. package/dist/utils/hooks/useLoadWorker.js +4 -14
  113. package/dist/utils/hooks/usePageRotateContext.js +8 -7
  114. package/dist/utils/hooks/usePaginate.js +4 -3
  115. package/dist/utils/hooks/usePinch.js +11 -10
  116. package/dist/utils/hooks/usePresentPage.js +4 -3
  117. package/dist/utils/hooks/usePrint.js +74 -78
  118. package/dist/utils/hooks/useRotate.js +4 -3
  119. package/dist/utils/hooks/useScrollToPage.js +4 -3
  120. package/dist/utils/hooks/useSearch.js +18 -15
  121. package/dist/utils/hooks/useTextSelection.js +2 -73
  122. package/dist/utils/hooks/useThumbnail.js +18 -17
  123. package/dist/utils/hooks/useVirtualReactWindow.js +4 -3
  124. package/dist/utils/link_service.js +18 -19
  125. package/dist/utils/renderPage.js +1 -1
  126. package/dist/utils/selectionUtils.js +96 -0
  127. package/package.json +2 -3
  128. package/dist/RPLayout.module-b4b23e29.js +0 -14
  129. package/dist/types/utils/hooks/useFlickerSelectText.d.ts +0 -1
  130. package/dist/utils/hooks/useFlickerSelectText.js +0 -25
@@ -1,9 +1,11 @@
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";
4
6
  const x = (n) => {
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 };
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 };
7
9
  }, N = (n) => n.flatMap((e) => e.rects ?? (e.rect ? [e.rect] : [])), O = (n) => {
8
10
  const e = n.reduce((o, t) => {
9
11
  const s = Math.round(t.bottom);
@@ -12,17 +14,17 @@ const x = (n) => {
12
14
  return Object.entries(e).sort((o, t) => Number(t[0]) - Number(o[0])).map(([o, t]) => x(t));
13
15
  }, L = (n) => {
14
16
  const e = {};
15
- for (const c of n) {
16
- const o = c.keyword, t = e[o] ?? [];
17
- t.push(c), e[o] = t;
17
+ for (const r of n) {
18
+ const o = r.keyword, t = e[o] ?? [];
19
+ t.push(r), e[o] = t;
18
20
  }
19
21
  return e;
20
22
  }, j = (n, e) => {
21
- const c = n[0], o = N(n), t = o.length > 0 ? O(o) : c.rect ? [c.rect] : [];
23
+ const r = n[0], o = N(n), t = o.length > 0 ? O(o) : r.rect ? [r.rect] : [];
22
24
  return {
23
- ...c,
25
+ ...r,
24
26
  pageMatchIdx: e,
25
- rect: t[0] ?? c.rect,
27
+ rect: t[0] ?? r.rect,
26
28
  rects: t
27
29
  };
28
30
  }, v = (n) => {
@@ -31,53 +33,53 @@ const x = (n) => {
31
33
  const s = e[t.page] ?? [];
32
34
  s.push(t), e[t.page] = s;
33
35
  }
34
- let c = 0;
36
+ let r = 0;
35
37
  const o = [];
36
38
  for (const t of Object.values(e)) {
37
39
  const s = L(t);
38
40
  for (const g of Object.values(s))
39
- o.push(j(g, c++));
41
+ o.push(j(g, r++));
40
42
  }
41
43
  return o;
42
- }, K = (n) => {
43
- const [e, c] = f(void 0), [o, t] = f([]), s = p(async (r) => {
44
- if (!r)
44
+ }, I = (n) => {
45
+ const [e, r] = f(void 0), [o, t] = f([]), s = p(async (c) => {
46
+ if (!c)
45
47
  return {};
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();
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();
50
52
  }
51
- return h;
52
- }, []), g = p(async (r) => {
53
- c(r);
53
+ return i;
54
+ }, []), g = p(async (c) => {
55
+ r(c);
54
56
  }, []), l = p(() => {
55
- t([]), c(void 0);
57
+ t([]), r(void 0);
56
58
  }, []);
57
59
  return w(() => {
58
- n && s(n).then((r) => {
59
- let i = [];
60
- for (const { keyword: h, highlightColor: a, options: u } of e) {
61
- if (!h)
60
+ n && s(n).then((c) => {
61
+ let a = [];
62
+ for (const { keyword: i, highlightColor: h, options: u } of e) {
63
+ if (!i)
62
64
  continue;
63
65
  const b = k(u);
64
- for (const m of Object.keys(r)) {
66
+ for (const m of Object.keys(c)) {
65
67
  const d = P(
66
- [h],
67
- r[m],
68
+ [i],
69
+ c[m],
68
70
  Number(m) - 1,
69
71
  b
70
72
  ).map((M, y) => ({
71
73
  ...M,
72
74
  page: Number(m),
73
75
  pageMatchIdx: y,
74
- color: a,
75
- keyword: h
76
+ color: h,
77
+ keyword: i
76
78
  }));
77
- i = [...i, ...d];
79
+ a = [...a, ...d];
78
80
  }
79
81
  }
80
- t(v(i));
82
+ t(v(a));
81
83
  }).catch(() => {
82
84
  l();
83
85
  });
@@ -89,5 +91,5 @@ const x = (n) => {
89
91
  };
90
92
  };
91
93
  export {
92
- K as useHighlight
94
+ I as useHighlight
93
95
  };
@@ -1,59 +1,59 @@
1
- import { useState as v, useCallback as E, useEffect as b } from "react";
2
- import { LicenseType as y } from "../types.js";
3
- import { appConsole as c } from "../appConsole.js";
1
+ import { useState as h, useCallback as E, useEffect as A } from "react";
2
+ import { LicenseType as b } from "../types.js";
3
+ import { appConsole as l } from "../appConsole.js";
4
4
  import "../../de_DE-a553b162.js";
5
- const A = /* @__PURE__ */ new Date("2026-03-23T03:03:12.500Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", o = {
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 = {
6
6
  invalidLicense: `You are currently using without a valid license. ${d}`,
7
7
  mismatchedDomain: `Your license key is not valid for the current domain / IP. ${d}`,
8
8
  expired: `Your license key has expired. ${d}`,
9
9
  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
10
  invalidSignature: "Invalid license key: Signature mismatch"
11
11
  };
12
- function I(r) {
13
- const t = r.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s+/g, ""), e = atob(t), n = new Uint8Array(e.length);
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);
14
14
  for (let i = 0; i < e.length; i++)
15
- n[i] = e.charCodeAt(i);
16
- return n.buffer;
15
+ r[i] = e.charCodeAt(i);
16
+ return r.buffer;
17
17
  }
18
- function L(r) {
19
- const t = atob(r), e = new Uint8Array(t.length);
20
- for (let n = 0; n < t.length; n++)
21
- e[n] = t.charCodeAt(n);
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);
22
22
  return e.buffer;
23
23
  }
24
- async function S(r, t = "SHA-256") {
24
+ async function I(n, t = "SHA-256") {
25
25
  try {
26
- const { data: e, signature: n } = JSON.parse(atob(r)), i = I(`-----BEGIN PUBLIC KEY-----
27
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyrIi83Zr5AKaWO6zbZmX
28
- qv3McVhtnPOnWCiFgf5xeaglLzEwMiXo3gALaPoBp5Q0WPOSBE9GTqwOyQUgpDNS
29
- BuQ0cjOzQdFM3GPnKSqQThZJfjUmD9egMZDmfhcpFGPybUoicoIEFQOdX2vMFUfn
30
- 6yjRsyvbK6UPTombYl785V8dXNnnIHa4tQC1JSaSe/bhG3e/6kbQCy9VJ23242q9
31
- WJpx9c2sZ+bmyI0r9Zx0PfqcDJzDfKn45v96EtxGhV16OZhqkbj4ljiJ/mfqfCkx
32
- ybkm9nvxz0hAwcEftQaxl/0cZ1RxtsRcL+V3msLsmGcs9nPqAuXecbfg9QVCi/+m
33
- iwIDAQAB
34
- -----END PUBLIC KEY-----`), s = await window.crypto.subtle.importKey(
26
+ const { data: e, signature: r } = JSON.parse(atob(n)), i = S(`-----BEGIN PUBLIC KEY-----
27
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIokvErJ0Fctu0jduSAx
28
+ gr+5Har/VSuZLlOunS28hnlqqA+OF1apHL7RYkjBosS15yvviYdLrVWYHpHnoY4b
29
+ HLQ9I6YX6FMB9T/VbB4xLdVdKvfi8r49aTScl5EKuSpgpPgz2VSJTfvVGcRuth/Y
30
+ Bm7PPGYdL2l2gvKDxchmmsHFPukGki9L4JOUeIVX0GXAxabENckaEH/iC1NZhX+W
31
+ vXnpHeHuIIKlZ16LSivXNgo6BH2Z3GFdg4G3cAaXr6qNP8fsacYNqv2SpTW1viFD
32
+ vzcGRabN25gpJAp9/syeScefWH3OiJY1lmw88oTiJbjIoiq6AkPhfn3G9mF54nvR
33
+ kwIDAQAB
34
+ -----END PUBLIC KEY-----`), a = await window.crypto.subtle.importKey(
35
35
  "spki",
36
36
  // str2ab(publicKeyContent), // Convert PEM string to ArrayBuffer
37
37
  i,
38
38
  { name: "RSA-PSS", hash: t },
39
39
  !0,
40
40
  ["verify"]
41
- ), a = await window.crypto.subtle.verify(
41
+ );
42
+ if (!await window.crypto.subtle.verify(
42
43
  { name: "RSA-PSS", saltLength: 32 },
43
- s,
44
- L(n),
44
+ a,
45
+ y(r),
45
46
  // Convert signature to ArrayBuffer
46
47
  new TextEncoder().encode(atob(e))
47
- );
48
- if (c.debug(">>> Verified license key validity", a), !a)
49
- throw new Error(o.invalidSignature);
48
+ ))
49
+ throw new Error(s.invalidSignature);
50
50
  return JSON.parse(atob(e));
51
51
  } catch {
52
- throw new Error(o.invalidLicense);
52
+ throw new Error(s.invalidLicense);
53
53
  }
54
54
  }
55
- const x = (r, t) => {
56
- switch (r) {
55
+ const T = (n, t) => {
56
+ switch (n) {
57
57
  case "specific":
58
58
  return t === window.location.host;
59
59
  case "wildcard":
@@ -61,48 +61,48 @@ const x = (r, t) => {
61
61
  }
62
62
  }, u = {
63
63
  isValid: !0,
64
- invalidatedMessage: o.invalidLicense,
64
+ invalidatedMessage: s.invalidLicense,
65
65
  type: void 0
66
- }, N = (r) => {
67
- const [t, e] = v(u), n = E(async () => {
68
- if (e((l) => ({ ...l, validating: !0 })), !r)
69
- throw e({ ...u, validating: !1 }), new Error(o.invalidLicense);
66
+ }, Y = (n) => {
67
+ const [t, e] = h(u), r = E(async () => {
68
+ if (e((c) => ({ ...c, validating: !0 })), !n)
69
+ throw e({ ...u, validating: !1 }), new Error(s.invalidLicense);
70
70
  let i;
71
71
  try {
72
- i = await S(r);
73
- } catch (l) {
74
- throw c.warn(l.message), new Error(l.message);
72
+ i = await I(n);
73
+ } catch (c) {
74
+ throw l.warn(c.message), new Error(c.message);
75
75
  }
76
- c.debug(">>> validatedLicense", i);
77
- const { avu: s, exp: a, dmt: w, dm: p, t: f } = i;
78
- if (!a)
76
+ l.debug(">>> validatedLicense", i);
77
+ const { avu: a, exp: o, dmt: w, dm: p, t: m } = i;
78
+ if (!o)
79
79
  throw new Error("License is missing expiration timestamp");
80
- if (a > Number.MAX_SAFE_INTEGER / 1e3)
80
+ if (o > Number.MAX_SAFE_INTEGER / 1e3)
81
81
  throw new Error("Invalid expiration timestamp: value too large");
82
- const g = new Date(a * 1e3), h = (/* @__PURE__ */ new Date()).getTime();
83
- if (g.getTime() < h)
84
- throw new Error(o.expired);
85
- if (!s)
82
+ const v = new Date(o * 1e3), g = (/* @__PURE__ */ new Date()).getTime();
83
+ if (v.getTime() < g)
84
+ throw new Error(s.expired);
85
+ if (!a)
86
86
  throw new Error("License is missing available until version timestamp");
87
- if (s > Number.MAX_SAFE_INTEGER / 1e3)
87
+ if (a > Number.MAX_SAFE_INTEGER / 1e3)
88
88
  throw new Error("Invalid available until version timestamp: value too large");
89
- const m = new Date(s * 1e3);
90
- if (c.debug("availableUntilTimestamp", m), m.getTime() < A.getTime())
91
- throw new Error(o.exceededVersion);
92
- if (f !== y.Custom && !x(w, p))
93
- throw new Error(o.mismatchedDomain);
89
+ const f = new Date(a * 1e3);
90
+ if (l.debug("availableUntilTimestamp", f), f.getTime() < L.getTime())
91
+ throw new Error(s.exceededVersion);
92
+ if (m !== b.Custom && !T(w, p))
93
+ throw new Error(s.mismatchedDomain);
94
94
  return {
95
95
  isValid: !0,
96
- type: f,
96
+ type: m,
97
97
  invalidatedMessage: void 0
98
98
  };
99
- }, [r]);
100
- return b(() => {
101
- n().then(({ isValid: i, type: s, invalidatedMessage: a }) => {
99
+ }, [n]);
100
+ return A(() => {
101
+ r().then(({ isValid: i, type: a, invalidatedMessage: o }) => {
102
102
  e({
103
103
  isValid: i,
104
- type: s,
105
- invalidatedMessage: a,
104
+ type: a,
105
+ invalidatedMessage: o,
106
106
  validating: !1
107
107
  });
108
108
  }).catch((i) => {
@@ -110,10 +110,10 @@ const x = (r, t) => {
110
110
  ...u,
111
111
  isValid: !1,
112
112
  validating: !1
113
- }), c.warn(i.message);
113
+ }), l.warn(i.message);
114
114
  });
115
- }, [n]), t;
115
+ }, [r]), t;
116
116
  };
117
117
  export {
118
- N as useLicense
118
+ Y as useLicense
119
119
  };
@@ -1,86 +1,118 @@
1
- import { useState as a, useRef as F, useEffect as v } from "react";
2
- import * as U from "pdfjs-dist";
3
- import { ErrorType as j } from "../types.js";
4
- import { getThumbnailViewport as z } from "../getThumbnailViewport.js";
5
- import { useConfigContext as _ } from "../../contexts/ConfigContext.js";
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";
6
7
  import { useDocumentPasswordContext as B } from "../../contexts/DocumentPasswordContext.js";
7
8
  import "../../de_DE-a553b162.js";
8
9
  import "react/jsx-runtime";
9
10
  import "../appConsole.js";
10
- const Z = (m, s, h = {}) => {
11
- const [n, q] = a(), { workerUrlAdded: S, wasmUrl: f } = _(), [D, T] = a(/* @__PURE__ */ new Map()), d = F(), [g, P] = a(0), [c, x] = a(!1), [N, O] = a(), { password: u, passwordError: A, setPasswordError: p, passwordRequired: w, setPasswordRequired: E } = B(), { onLoadError: i, onLoaded: b, onLoadProgress: R, disableAutoFetch: C, disableStream: V, rangeChunkSize: I } = h;
12
- return v(() => {
13
- R && R(g);
14
- }, [g, R]), v(() => {
15
- if (!S || !m)
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)
16
47
  return;
17
- P(0), d.current = Date.now();
18
- const r = d.current, y = {
19
- url: m,
20
- cMapPacked: (s == null ? void 0 : s.isCompressed) ?? !0,
21
- ...(s == null ? void 0 : s.url) && { cMapUrl: s.url },
22
- ...u && { password: u },
23
- ...C !== void 0 && { disableAutoFetch: C },
24
- ...V !== void 0 && { disableStream: V },
25
- ...I !== void 0 && { rangeChunkSize: I },
26
- ...f && { wasmUrl: f },
27
- verbosity: U.VerbosityLevel.ERRORS
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;
28
79
  };
29
- try {
30
- const e = U.getDocument(y);
31
- e.onProgress = (o) => {
32
- if (r === d.current) {
33
- const { loaded: L, total: l } = o, k = l ? Math.min(100, Math.round(L / l * 100)) : 0;
34
- P(k);
35
- }
36
- }, x(!0);
37
- const t = e.promise.then((o) => (r === d.current && (q(o), P(100)), b && b(o), E(!1), p(""), o)).catch((o) => {
38
- o instanceof Error && o.name === "PasswordException" ? (E(!0), p(o.message || "Password required")) : o instanceof Error && o.name === "InvalidPDFException" && u ? (E(!0), p("Incorrect password")) : i && i(o);
39
- }).finally(() => {
40
- x(!1);
41
- });
42
- return () => {
43
- t.finally(() => {
44
- e.destroy();
45
- });
46
- };
47
- } catch (e) {
48
- O(j.NOT_SUPPORTED), i && i(e);
49
- }
50
- }, [m, S, f, u, i, b]), v(() => {
51
- if (w)
80
+ }, [t, y, p, x, A, L]), P(() => {
81
+ if (E)
52
82
  return;
53
- const r = /* @__PURE__ */ new Map();
54
- if (!n || c) {
55
- T(r);
83
+ const f = /* @__PURE__ */ new Map();
84
+ if (!o || D) {
85
+ w(f);
56
86
  return;
57
87
  }
58
- const y = n.numPages, e = [];
59
- for (let t = 1; t <= y; t++) {
60
- const o = n.getPage(t);
61
- e.push(o);
88
+ const d = o.numPages, k = [];
89
+ for (let e = 1; e <= d; e++) {
90
+ const r = o.getPage(e);
91
+ k.push(r);
62
92
  }
63
- Promise.all(e).then((t) => {
64
- t.map((o) => {
65
- const { thumbnailViewport: L, scale: l } = z(o), k = o.getViewport();
66
- r.set(o.pageNumber, {
67
- page: o,
68
- thumbnailViewport: L,
69
- thumbnailScale: l,
70
- defaultRotation: k.rotation
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
71
101
  });
72
- }), T(r);
102
+ }), w(f);
73
103
  });
74
- }, [n, c, w]), {
75
- pdf: n,
76
- pages: D,
77
- loading: c,
78
- error: N,
79
- loadingProgress: g,
80
- passwordRequired: w,
81
- passwordError: A
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
82
114
  };
83
115
  };
84
116
  export {
85
- Z as useLoadPdf
117
+ re as useLoadPdf
86
118
  };