pdf-tsx 0.4.0 → 0.5.0

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 (106) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +350 -337
  3. package/dist/cjs/components/PDFSidebar.cjs +1 -1
  4. package/dist/cjs/components/PDFSidebar.module.cjs +1 -1
  5. package/dist/cjs/components/PDFViewer.cjs +1 -1
  6. package/dist/cjs/components/PDFViewer.module.cjs +1 -1
  7. package/dist/cjs/components/features/PDFAnnotations.cjs +1 -1
  8. package/dist/cjs/components/features/PDFAnnotations.module.cjs +1 -1
  9. package/dist/cjs/components/features/PDFChangeFile.cjs +1 -1
  10. package/dist/cjs/components/features/PDFDownloadButton.cjs +1 -1
  11. package/dist/cjs/components/features/PDFNavigation.cjs +1 -1
  12. package/dist/cjs/components/features/PDFNavigation.module.cjs +1 -1
  13. package/dist/cjs/components/features/PDFOutline.cjs +1 -1
  14. package/dist/cjs/components/features/PDFOutline.module.cjs +1 -1
  15. package/dist/cjs/components/features/PDFPageFit.cjs +1 -1
  16. package/dist/cjs/components/features/PDFPrintButton.cjs +1 -1
  17. package/dist/cjs/components/features/PDFRotationControl.cjs +1 -1
  18. package/dist/cjs/components/features/PDFSearch.cjs +1 -1
  19. package/dist/cjs/components/features/PDFSearch.module.cjs +1 -1
  20. package/dist/cjs/components/features/PDFSidebarToggle.cjs +1 -1
  21. package/dist/cjs/components/features/PDFSignatures.cjs +1 -1
  22. package/dist/cjs/components/features/PDFSignatures.module.cjs +1 -1
  23. package/dist/cjs/components/features/PDFThemeToggle.cjs +1 -1
  24. package/dist/cjs/components/features/PDFThumbnails.cjs +1 -1
  25. package/dist/cjs/components/features/PDFThumbnails.module.cjs +1 -1
  26. package/dist/cjs/components/features/PDFZoomControls.cjs +1 -1
  27. package/dist/cjs/components/features/PDFZoomControls.module.cjs +1 -1
  28. package/dist/cjs/components/ui/ToolbarButton.module.cjs +1 -1
  29. package/dist/cjs/components/ui/icons.cjs +1 -1
  30. package/dist/cjs/context/ThemeContext.cjs +1 -1
  31. package/dist/cjs/context/themeContextValue.cjs +1 -0
  32. package/dist/cjs/hooks/useAnnotationLayer.cjs +1 -1
  33. package/dist/cjs/hooks/useAnnotations.cjs +1 -1
  34. package/dist/cjs/hooks/useKeyboardShortcuts.cjs +1 -1
  35. package/dist/cjs/hooks/useOutline.cjs +1 -1
  36. package/dist/cjs/hooks/useOverlayRects.cjs +1 -0
  37. package/dist/cjs/hooks/usePDFLoader.cjs +1 -0
  38. package/dist/cjs/hooks/usePDFRenderer.cjs +1 -0
  39. package/dist/cjs/hooks/useScrollTracking.cjs +1 -1
  40. package/dist/cjs/hooks/useTextLayer.cjs +1 -1
  41. package/dist/cjs/hooks/useTextSearch.cjs +1 -1
  42. package/dist/cjs/hooks/useTheme.cjs +1 -0
  43. package/dist/cjs/hooks/useThumbnails.cjs +1 -1
  44. package/dist/cjs/pdf-tsx.css +1 -1
  45. package/dist/components/PDFSidebar.d.ts +1 -2
  46. package/dist/components/features/PDFSidebarToggle.d.ts +1 -1
  47. package/dist/components/ui/icons.d.ts +0 -14
  48. package/dist/context/ThemeContext.d.ts +0 -6
  49. package/dist/context/themeContextValue.d.ts +7 -0
  50. package/dist/es/components/PDFSidebar.js +26 -33
  51. package/dist/es/components/PDFSidebar.module.js +9 -9
  52. package/dist/es/components/PDFViewer.js +240 -269
  53. package/dist/es/components/PDFViewer.module.js +15 -15
  54. package/dist/es/components/features/PDFAnnotations.js +57 -64
  55. package/dist/es/components/features/PDFAnnotations.module.js +12 -12
  56. package/dist/es/components/features/PDFChangeFile.js +3 -3
  57. package/dist/es/components/features/PDFDownloadButton.js +2 -2
  58. package/dist/es/components/features/PDFNavigation.js +3 -3
  59. package/dist/es/components/features/PDFNavigation.module.js +3 -3
  60. package/dist/es/components/features/PDFOutline.js +7 -7
  61. package/dist/es/components/features/PDFOutline.module.js +5 -5
  62. package/dist/es/components/features/PDFPageFit.js +1 -1
  63. package/dist/es/components/features/PDFPrintButton.js +5 -4
  64. package/dist/es/components/features/PDFRotationControl.js +1 -1
  65. package/dist/es/components/features/PDFSearch.js +4 -4
  66. package/dist/es/components/features/PDFSearch.module.js +5 -5
  67. package/dist/es/components/features/PDFSidebarToggle.js +11 -10
  68. package/dist/es/components/features/PDFSignatures.js +158 -116
  69. package/dist/es/components/features/PDFSignatures.module.js +16 -16
  70. package/dist/es/components/features/PDFThemeToggle.js +5 -5
  71. package/dist/es/components/features/PDFThumbnails.js +54 -30
  72. package/dist/es/components/features/PDFThumbnails.module.js +9 -7
  73. package/dist/es/components/features/PDFZoomControls.js +1 -1
  74. package/dist/es/components/features/PDFZoomControls.module.js +1 -1
  75. package/dist/es/components/ui/ToolbarButton.module.js +2 -2
  76. package/dist/es/components/ui/icons.js +1 -1
  77. package/dist/es/context/ThemeContext.js +20 -25
  78. package/dist/es/context/themeContextValue.js +5 -0
  79. package/dist/es/hooks/useAnnotationLayer.js +11 -11
  80. package/dist/es/hooks/useAnnotations.js +0 -1
  81. package/dist/es/hooks/useKeyboardShortcuts.js +12 -15
  82. package/dist/es/hooks/useOutline.js +31 -12
  83. package/dist/es/hooks/useOverlayRects.js +72 -0
  84. package/dist/es/hooks/usePDFLoader.js +26 -0
  85. package/dist/es/hooks/usePDFRenderer.js +83 -0
  86. package/dist/es/hooks/useScrollTracking.js +21 -20
  87. package/dist/es/hooks/useTextLayer.js +13 -12
  88. package/dist/es/hooks/useTextSearch.js +30 -18
  89. package/dist/es/hooks/useTheme.js +10 -0
  90. package/dist/es/hooks/useThumbnails.js +86 -24
  91. package/dist/es/pdf-tsx.css +1 -1
  92. package/dist/hooks/useAnnotationLayer.d.ts +2 -2
  93. package/dist/hooks/useAnnotations.d.ts +0 -5
  94. package/dist/hooks/useKeyboardShortcuts.d.ts +1 -2
  95. package/dist/hooks/useOverlayRects.d.ts +21 -0
  96. package/dist/hooks/usePDFLoader.d.ts +4 -0
  97. package/dist/hooks/usePDFRenderer.d.ts +16 -0
  98. package/dist/hooks/useScrollTracking.d.ts +2 -1
  99. package/dist/hooks/useTextLayer.d.ts +2 -2
  100. package/dist/hooks/useTheme.d.ts +2 -0
  101. package/dist/hooks/useThumbnails.d.ts +3 -2
  102. package/dist/pdf-tsx.cjs.js +5 -0
  103. package/dist/pdf-tsx.css +2 -0
  104. package/dist/pdf-tsx.es.js +2637 -0
  105. package/dist/vite.svg +1 -0
  106. package/package.json +61 -61
@@ -23,7 +23,6 @@ function r({ pdf: r }) {
23
23
  subtype: i,
24
24
  contents: r.contents,
25
25
  title: r.title,
26
- color: r.color,
27
26
  rect: r.rect
28
27
  });
29
28
  }
@@ -1,44 +1,41 @@
1
- import { useEffect as e } from "react";
1
+ import { c as e } from "react/compiler-runtime";
2
+ import { useEffect as t } from "react";
2
3
  import "pdfjs-dist";
3
- import { c as t } from "react/compiler-runtime";
4
4
  //#region src/hooks/useKeyboardShortcuts.ts
5
5
  function n(n) {
6
- let o = t(13), { pdf: s, currentPage: c, numPages: l, goToPage: u, setZoom: d, setRotation: f } = n, p;
7
- o[0] !== c || o[1] !== u || o[2] !== s || o[3] !== f || o[4] !== d ? (p = () => {
6
+ let o = e(7), { pdf: s, currentPage: c, goToPage: l, setZoom: u, setRotation: d } = n, f, p;
7
+ o[0] !== c || o[1] !== l || o[2] !== s || o[3] !== d || o[4] !== u ? (f = () => {
8
8
  if (!s) return;
9
9
  let e = (e) => {
10
10
  let t = e.target.tagName;
11
11
  if (!(t === "INPUT" || t === "TEXTAREA")) bb13: switch (e.key) {
12
12
  case "ArrowLeft":
13
13
  case "ArrowUp":
14
- e.preventDefault(), u(c - 1);
14
+ e.preventDefault(), l(c - 1);
15
15
  break bb13;
16
16
  case "ArrowRight":
17
17
  case "ArrowDown":
18
- e.preventDefault(), u(c + 1);
18
+ e.preventDefault(), l(c + 1);
19
19
  break bb13;
20
20
  case "+":
21
21
  case "=":
22
- e.preventDefault(), d(a);
22
+ e.preventDefault(), u(a);
23
23
  break bb13;
24
24
  case "-":
25
- e.preventDefault(), d(i);
25
+ e.preventDefault(), u(i);
26
26
  break bb13;
27
27
  case "r":
28
- case "R": e.preventDefault(), f(r);
28
+ case "R": e.preventDefault(), d(r);
29
29
  }
30
30
  };
31
31
  return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
32
- }, o[0] = c, o[1] = u, o[2] = s, o[3] = f, o[4] = d, o[5] = p) : p = o[5];
33
- let m;
34
- o[6] !== c || o[7] !== u || o[8] !== l || o[9] !== s || o[10] !== f || o[11] !== d ? (m = [
32
+ }, p = [
35
33
  s,
36
34
  c,
37
35
  l,
38
36
  u,
39
- d,
40
- f
41
- ], o[6] = c, o[7] = u, o[8] = l, o[9] = s, o[10] = f, o[11] = d, o[12] = m) : m = o[12], e(p, m);
37
+ d
38
+ ], o[0] = c, o[1] = l, o[2] = s, o[3] = d, o[4] = u, o[5] = f, o[6] = p) : (f = o[5], p = o[6]), t(f, p);
42
39
  }
43
40
  function r(e) {
44
41
  return (e + 90) % 360;
@@ -1,19 +1,38 @@
1
- import { useEffect as e, useState as t } from "react";
1
+ import { c as e } from "react/compiler-runtime";
2
+ import { useEffect as t, useState as n } from "react";
2
3
  import "pdfjs-dist";
3
- import { c as n } from "react/compiler-runtime";
4
4
  //#region src/hooks/useOutline.ts
5
5
  function r(r) {
6
- let i = n(7), { pdf: a } = r, o;
7
- i[0] === Symbol.for("react.memo_cache_sentinel") ? (o = [], i[0] = o) : o = i[0];
8
- let [s, c] = t(o), [l, u] = t(!1), d, f;
9
- i[1] === a ? (d = i[2], f = i[3]) : (d = () => {
10
- a && (u(!0), a.getOutline().then((e) => c(e ?? [])).catch(() => c([])).finally(() => u(!1)));
11
- }, f = [a], i[1] = a, i[2] = d, i[3] = f), e(d, f);
6
+ let i = e(10), { pdf: a } = r, o;
7
+ i[0] === Symbol.for("react.memo_cache_sentinel") ? (o = {
8
+ pdf: null,
9
+ outline: []
10
+ }, i[0] = o) : o = i[0];
11
+ let [s, c] = n(o), l, u;
12
+ i[1] === a ? (l = i[2], u = i[3]) : (l = () => {
13
+ if (!a) return;
14
+ let e = !1;
15
+ return a.getOutline().then((t) => {
16
+ e || c({
17
+ pdf: a,
18
+ outline: t ?? []
19
+ });
20
+ }).catch(() => {
21
+ e || c({
22
+ pdf: a,
23
+ outline: []
24
+ });
25
+ }), () => {
26
+ e = !0;
27
+ };
28
+ }, u = [a], i[1] = a, i[2] = l, i[3] = u), t(l, u);
29
+ let d = a !== null && s.pdf !== a, f;
30
+ i[4] !== d || i[5] !== s ? (f = d ? [] : s.outline, i[4] = d, i[5] = s, i[6] = f) : f = i[6];
12
31
  let p;
13
- return i[4] !== l || i[5] !== s ? (p = {
14
- outline: s,
15
- loading: l
16
- }, i[4] = l, i[5] = s, i[6] = p) : p = i[6], p;
32
+ return i[7] !== d || i[8] !== f ? (p = {
33
+ outline: f,
34
+ loading: d
35
+ }, i[7] = d, i[8] = f, i[9] = p) : p = i[9], p;
17
36
  }
18
37
  //#endregion
19
38
  export { r as useOutline };
@@ -0,0 +1,72 @@
1
+ import { c as e } from "react/compiler-runtime";
2
+ import { useEffect as t, useState as n } from "react";
3
+ import "pdfjs-dist";
4
+ //#region src/hooks/useOverlayRects.ts
5
+ function r(r) {
6
+ let i = e(20), { pdf: a, highlight: o, searchMatches: s, zoom: c, rotation: l } = r, [u, d] = n(null), f;
7
+ i[0] === Symbol.for("react.memo_cache_sentinel") ? (f = [], i[0] = f) : f = i[0];
8
+ let [p, m] = n(f), h, g;
9
+ i[1] !== a || i[2] !== l || i[3] !== s || i[4] !== c ? (h = () => {
10
+ if (!a || s.length === 0) return;
11
+ let e = !1;
12
+ return (async () => {
13
+ let t = [];
14
+ for (let n of s) {
15
+ if (e) break;
16
+ let [r, i, o, s] = (await a.getPage(n.page)).getViewport({
17
+ scale: c,
18
+ rotation: l
19
+ }).convertToViewportRectangle(n.pdfRect);
20
+ t.push({
21
+ page: n.page,
22
+ x: Math.min(r, o),
23
+ y: Math.min(i, s),
24
+ width: Math.abs(o - r),
25
+ height: Math.abs(s - i)
26
+ });
27
+ }
28
+ e || m(t);
29
+ })(), () => {
30
+ e = !0;
31
+ };
32
+ }, g = [
33
+ s,
34
+ c,
35
+ l,
36
+ a
37
+ ], i[1] = a, i[2] = l, i[3] = s, i[4] = c, i[5] = h, i[6] = g) : (h = i[5], g = i[6]), t(h, g);
38
+ let _, v;
39
+ i[7] !== o || i[8] !== a || i[9] !== l || i[10] !== c ? (_ = () => {
40
+ if (!o || !a) return;
41
+ let e = !1;
42
+ return (async () => {
43
+ let [t, n, r, i] = (await a.getPage(o.page)).getViewport({
44
+ scale: c,
45
+ rotation: l
46
+ }).convertToViewportRectangle(o.pdfRect);
47
+ e || d({
48
+ page: o.page,
49
+ x: Math.min(t, r),
50
+ y: Math.min(n, i),
51
+ width: Math.abs(r - t),
52
+ height: Math.abs(i - n)
53
+ });
54
+ })(), () => {
55
+ e = !0;
56
+ };
57
+ }, v = [
58
+ o,
59
+ c,
60
+ l,
61
+ a
62
+ ], i[7] = o, i[8] = a, i[9] = l, i[10] = c, i[11] = _, i[12] = v) : (_ = i[11], v = i[12]), t(_, v);
63
+ let y = !o || !a ? null : u, b;
64
+ i[13] !== a || i[14] !== s || i[15] !== p ? (b = !a || s.length === 0 ? [] : p, i[13] = a, i[14] = s, i[15] = p, i[16] = b) : b = i[16];
65
+ let x;
66
+ return i[17] !== y || i[18] !== b ? (x = {
67
+ overlayRect: y,
68
+ searchOverlays: b
69
+ }, i[17] = y, i[18] = b, i[19] = x) : x = i[19], x;
70
+ }
71
+ //#endregion
72
+ export { r as useOverlayRects };
@@ -0,0 +1,26 @@
1
+ import { c as e } from "react/compiler-runtime";
2
+ import { useEffect as t, useState as n } from "react";
3
+ import * as r from "pdfjs-dist";
4
+ //#region src/hooks/usePDFLoader.ts
5
+ function i(i) {
6
+ let a = e(6), [o, s] = n(null), [c, l] = n(0), u, d;
7
+ a[0] === i ? (u = a[1], d = a[2]) : (u = () => {
8
+ let e = new FileReader();
9
+ e.onload = async (e) => {
10
+ let t = new Uint8Array(e.target?.result);
11
+ try {
12
+ let e = await r.getDocument(t).promise;
13
+ s(e), l(e.numPages);
14
+ } catch (e) {
15
+ console.error("Errore caricamento:", e);
16
+ }
17
+ }, e.readAsArrayBuffer(i);
18
+ }, d = [i], a[0] = i, a[1] = u, a[2] = d), t(u, d);
19
+ let f;
20
+ return a[3] !== c || a[4] !== o ? (f = {
21
+ pdf: o,
22
+ numPages: c
23
+ }, a[3] = c, a[4] = o, a[5] = f) : f = a[5], f;
24
+ }
25
+ //#endregion
26
+ export { i as usePDFLoader };
@@ -0,0 +1,83 @@
1
+ import { useEffect as e, useRef as t, useState as n } from "react";
2
+ import "pdfjs-dist";
3
+ //#region src/hooks/usePDFRenderer.ts
4
+ function r({ pdf: r, zoom: i, rotation: a, visiblePages: o, canvasRefs: s }) {
5
+ let [c, l] = n([]), [u, d] = n(/* @__PURE__ */ new Set()), f = t([]), p = t(/* @__PURE__ */ new Set()), m = t(!1);
6
+ return e(() => {
7
+ if (!r) return;
8
+ m.current = !1, p.current = /* @__PURE__ */ new Set(), d(/* @__PURE__ */ new Set());
9
+ let e = !1;
10
+ return (async () => {
11
+ let t = f.current.map((e) => e ? (e.cancel(), e.promise.catch(() => {})) : Promise.resolve());
12
+ if (await Promise.all(t), f.current = Array(r.numPages).fill(null), e) return;
13
+ let n = [];
14
+ for (let e = 1; e <= r.numPages; e++) {
15
+ let t = (await r.getPage(e)).getViewport({
16
+ scale: i,
17
+ rotation: a
18
+ });
19
+ n.push({
20
+ width: t.width,
21
+ height: t.height
22
+ });
23
+ }
24
+ e || (m.current = !0, l(n));
25
+ })(), () => {
26
+ e = !0, f.current.forEach((e) => e?.cancel());
27
+ };
28
+ }, [
29
+ r,
30
+ i,
31
+ a
32
+ ]), e(() => {
33
+ if (!r || c.length !== r.numPages || !m.current) return;
34
+ let e = !1;
35
+ return (async () => {
36
+ for (let t of o) {
37
+ if (e || p.current.has(t)) continue;
38
+ let n = await r.getPage(t);
39
+ if (e) return;
40
+ let o = n.getViewport({
41
+ scale: i,
42
+ rotation: a
43
+ }), c = s.current[t - 1];
44
+ if (!c) continue;
45
+ let l = c.getContext("2d");
46
+ if (!l) continue;
47
+ let u = f.current[t - 1];
48
+ if (u && (u.cancel(), await u.promise.catch(() => {}), e)) return;
49
+ c.height = o.height, c.width = o.width;
50
+ let m = n.render({
51
+ canvasContext: l,
52
+ viewport: o,
53
+ canvas: c
54
+ });
55
+ f.current[t - 1] = m;
56
+ try {
57
+ await m.promise, e || (p.current = new Set(p.current).add(t), d((e) => {
58
+ if (e.has(t)) return e;
59
+ let n = new Set(e);
60
+ return n.add(t), n;
61
+ }));
62
+ } catch (e) {
63
+ e && typeof e == "object" && "name" in e && e.name !== "RenderingCancelledException" && console.error("Render error:", e);
64
+ } finally {
65
+ f.current[t - 1] === m && (f.current[t - 1] = null);
66
+ }
67
+ }
68
+ })(), () => {
69
+ e = !0;
70
+ };
71
+ }, [
72
+ r,
73
+ c,
74
+ a,
75
+ o,
76
+ i
77
+ ]), {
78
+ pageSizes: c,
79
+ renderedPages: u
80
+ };
81
+ }
82
+ //#endregion
83
+ export { r as usePDFRenderer };
@@ -1,46 +1,47 @@
1
- import { useEffect as e, useState as t } from "react";
1
+ import { c as e } from "react/compiler-runtime";
2
+ import { useEffect as t, useState as n } from "react";
2
3
  import "pdfjs-dist";
3
- import { c as n } from "react/compiler-runtime";
4
4
  //#region src/hooks/useScrollTracking.ts
5
5
  var r = 10;
6
6
  function i(i) {
7
- let a = n(16), { pdf: o, numPages: s, zoom: c, rotation: l, containerRef: u, canvasRefs: d } = i, [f, p] = t(1), m;
8
- a[0] !== d || a[1] !== u ? (m = () => {
7
+ let a = e(17), { pdf: o, numPages: s, zoom: c, rotation: l, containerRef: u, pageRefs: d, canvasRefs: f } = i, [p, m] = n(1), h;
8
+ a[0] !== u || a[1] !== d ? (h = () => {
9
9
  let e = u.current;
10
10
  if (!e) return;
11
11
  let t = () => {
12
12
  let t = e.getBoundingClientRect().top, n = d.current;
13
13
  for (let e = 0; e < n.length; e++) {
14
14
  let r = n[e];
15
- r && (r.parentElement ?? r).getBoundingClientRect().top - t <= 150 && p(e + 1);
15
+ r && r.getBoundingClientRect().top - t <= 150 && m(e + 1);
16
16
  }
17
17
  };
18
18
  return e.addEventListener("scroll", t), () => e.removeEventListener("scroll", t);
19
- }, a[0] = d, a[1] = u, a[2] = m) : m = a[2];
20
- let h;
21
- a[3] !== d || a[4] !== u || a[5] !== o || a[6] !== l || a[7] !== c ? (h = [
19
+ }, a[0] = u, a[1] = d, a[2] = h) : h = a[2];
20
+ let g;
21
+ a[3] !== f || a[4] !== u || a[5] !== d || a[6] !== o || a[7] !== l || a[8] !== c ? (g = [
22
22
  o,
23
23
  c,
24
24
  l,
25
25
  u,
26
- d
27
- ], a[3] = d, a[4] = u, a[5] = o, a[6] = l, a[7] = c, a[8] = h) : h = a[8], e(m, h);
28
- let g;
29
- a[9] !== d || a[10] !== u || a[11] !== s ? (g = (e) => {
26
+ d,
27
+ f
28
+ ], a[3] = f, a[4] = u, a[5] = d, a[6] = o, a[7] = l, a[8] = c, a[9] = g) : g = a[9], t(h, g);
29
+ let _;
30
+ a[10] !== u || a[11] !== s || a[12] !== d ? (_ = (e) => {
30
31
  let t = Math.min(Math.max(e, 1), s), n = d.current[t - 1], i = u.current;
31
32
  if (n && i) {
32
- let e = (n.parentElement ?? n).getBoundingClientRect().top, a = i.getBoundingClientRect().top, o = i.scrollTop + (e - a) - r;
33
+ let e = n.getBoundingClientRect().top, a = i.getBoundingClientRect().top, o = i.scrollTop + (e - a) - r;
33
34
  i.scrollTo({
34
35
  top: o,
35
36
  behavior: "smooth"
36
- }), p(t);
37
+ }), m(t);
37
38
  }
38
- }, a[9] = d, a[10] = u, a[11] = s, a[12] = g) : g = a[12];
39
- let _ = g, v;
40
- return a[13] !== f || a[14] !== _ ? (v = {
41
- currentPage: f,
42
- goToPage: _
43
- }, a[13] = f, a[14] = _, a[15] = v) : v = a[15], v;
39
+ }, a[10] = u, a[11] = s, a[12] = d, a[13] = _) : _ = a[13];
40
+ let v = _, y;
41
+ return a[14] !== p || a[15] !== v ? (y = {
42
+ currentPage: p,
43
+ goToPage: v
44
+ }, a[14] = p, a[15] = v, a[16] = y) : y = a[16], y;
44
45
  }
45
46
  //#endregion
46
47
  export { i as useScrollTracking };
@@ -1,27 +1,28 @@
1
- import { useEffect as e, useRef as t } from "react";
2
- import * as n from "pdfjs-dist";
3
- import { c as r } from "react/compiler-runtime";
1
+ import { c as e } from "react/compiler-runtime";
2
+ import { useEffect as t, useRef as n } from "react";
3
+ import * as r from "pdfjs-dist";
4
4
  //#region src/hooks/useTextLayer.ts
5
5
  function i(i) {
6
- let a = r(8), { pdf: o, zoom: s, rotation: c, numPages: l, canvasRefs: u } = i, d;
6
+ let a = e(8), { pdf: o, zoom: s, rotation: c, mountedPages: l, canvasRefs: u } = i, d;
7
7
  a[0] === Symbol.for("react.memo_cache_sentinel") ? (d = [], a[0] = d) : d = a[0];
8
- let f = t(d), p, m;
8
+ let f = n(d), p, m;
9
9
  return a[1] !== u || a[2] !== l || a[3] !== o || a[4] !== c || a[5] !== s ? (p = () => {
10
10
  if (!o) return;
11
11
  let e = !1;
12
12
  return (async () => {
13
- for (let t = 1; t <= l && !e; t++) {
14
- let r = f.current[t - 1], i = u.current[t - 1];
15
- if (!r || !i) continue;
16
- r.replaceChildren();
13
+ for (let t of l) {
14
+ if (e) break;
15
+ let n = f.current[t - 1], i = u.current[t - 1];
16
+ if (!n || !i) continue;
17
+ n.replaceChildren();
17
18
  let a = await o.getPage(t), l = a.getViewport({
18
19
  scale: s,
19
20
  rotation: c
20
21
  }), d = await a.getTextContent();
21
22
  if (e) break;
22
- r.style.width = `${l.width}px`, r.style.height = `${l.height}px`, await new n.TextLayer({
23
+ n.style.width = `${l.width}px`, n.style.height = `${l.height}px`, await new r.TextLayer({
23
24
  textContentSource: d,
24
- container: r,
25
+ container: n,
25
26
  viewport: l
26
27
  }).render();
27
28
  }
@@ -34,7 +35,7 @@ function i(i) {
34
35
  c,
35
36
  l,
36
37
  u
37
- ], a[1] = u, a[2] = l, a[3] = o, a[4] = c, a[5] = s, a[6] = p, a[7] = m) : (p = a[6], m = a[7]), e(p, m), f;
38
+ ], a[1] = u, a[2] = l, a[3] = o, a[4] = c, a[5] = s, a[6] = p, a[7] = m) : (p = a[6], m = a[7]), t(p, m), f;
38
39
  }
39
40
  //#endregion
40
41
  export { i as useTextLayer };
@@ -1,20 +1,19 @@
1
- import { useEffect as e, useState as t } from "react";
1
+ import { c as e } from "react/compiler-runtime";
2
+ import { useEffect as t, useState as n } from "react";
2
3
  import "pdfjs-dist";
3
- import { c as n } from "react/compiler-runtime";
4
4
  //#region src/hooks/useTextSearch.ts
5
5
  function r(r) {
6
- let i = n(8), { pdf: a, query: o } = r, s;
7
- i[0] === Symbol.for("react.memo_cache_sentinel") ? (s = [], i[0] = s) : s = i[0];
8
- let [c, l] = t(s), [u, d] = t(!1), f, p;
9
- i[1] !== a || i[2] !== o ? (f = () => {
6
+ let i = e(12), { pdf: a, query: o } = r, s;
7
+ i[0] === Symbol.for("react.memo_cache_sentinel") ? (s = {
8
+ query: "",
9
+ matches: []
10
+ }, i[0] = s) : s = i[0];
11
+ let [c, l] = n(s), u, d;
12
+ i[1] !== a || i[2] !== o ? (u = () => {
10
13
  let e = o.trim().toLowerCase();
11
- if (!a || !e) {
12
- l([]);
13
- return;
14
- }
14
+ if (!a || !e) return;
15
15
  let t = !1;
16
16
  return (async () => {
17
- d(!0);
18
17
  let n = [];
19
18
  for (let r = 1; r <= a.numPages && !t; r++) {
20
19
  let t = await (await a.getPage(r)).getTextContent();
@@ -37,16 +36,29 @@ function r(r) {
37
36
  }
38
37
  }
39
38
  }
40
- t || (l(n), d(!1));
39
+ t || l({
40
+ query: o,
41
+ matches: n
42
+ });
41
43
  })(), () => {
42
44
  t = !0;
43
45
  };
44
- }, p = [a, o], i[1] = a, i[2] = o, i[3] = f, i[4] = p) : (f = i[3], p = i[4]), e(f, p);
45
- let m;
46
- return i[5] !== c || i[6] !== u ? (m = {
47
- matches: c,
48
- searching: u
49
- }, i[5] = c, i[6] = u, i[7] = m) : m = i[7], m;
46
+ }, d = [a, o], i[1] = a, i[2] = o, i[3] = u, i[4] = d) : (u = i[3], d = i[4]), t(u, d);
47
+ let f = o.trim();
48
+ if (!a || !f) {
49
+ let e;
50
+ return i[5] === Symbol.for("react.memo_cache_sentinel") ? (e = {
51
+ matches: [],
52
+ searching: !1
53
+ }, i[5] = e) : e = i[5], e;
54
+ }
55
+ let p = c.query !== o, m;
56
+ i[6] !== p || i[7] !== c.matches ? (m = p ? [] : c.matches, i[6] = p, i[7] = c.matches, i[8] = m) : m = i[8];
57
+ let h;
58
+ return i[9] !== p || i[10] !== m ? (h = {
59
+ matches: m,
60
+ searching: p
61
+ }, i[9] = p, i[10] = m, i[11] = h) : h = i[11], h;
50
62
  }
51
63
  //#endregion
52
64
  export { r as useTextSearch };
@@ -0,0 +1,10 @@
1
+ import { ThemeContext as e } from "../context/themeContextValue.js";
2
+ import { useContext as t } from "react";
3
+ //#region src/hooks/useTheme.ts
4
+ function n() {
5
+ let n = t(e);
6
+ if (!n) throw Error("useTheme must be used inside <ThemeProvider>");
7
+ return n;
8
+ }
9
+ //#endregion
10
+ export { n as useTheme };
@@ -1,30 +1,92 @@
1
- import { useEffect as e, useState as t } from "react";
1
+ import { c as e } from "react/compiler-runtime";
2
+ import { useEffect as t, useReducer as n, useRef as r } from "react";
2
3
  import "pdfjs-dist";
3
- import { c as n } from "react/compiler-runtime";
4
4
  //#region src/hooks/useThumbnails.ts
5
- function r(r) {
6
- let i = n(7), { pdf: a, rotation: o } = r, s;
7
- i[0] === Symbol.for("react.memo_cache_sentinel") ? (s = [], i[0] = s) : s = i[0];
8
- let [c, l] = t(s), u, d;
9
- i[1] !== a || i[2] !== o ? (u = () => {
10
- a && (async () => {
11
- let e = [];
12
- for (let t = 1; t <= a.numPages; t++) {
13
- let n = await a.getPage(t), r = n.getViewport({
5
+ function i(e, t) {
6
+ if (t.type === "reset") return {
7
+ thumbnails: Array(t.numPages).fill(null),
8
+ version: e.version + 1
9
+ };
10
+ if (t.type === "set") {
11
+ let n = [...e.thumbnails];
12
+ return n[t.pageNum - 1] = t.dataUrl, {
13
+ thumbnails: n,
14
+ version: e.version
15
+ };
16
+ }
17
+ return e;
18
+ }
19
+ function a(a) {
20
+ let o = e(14), { pdf: s, rotation: c, visiblePages: l } = a, u;
21
+ o[0] === Symbol.for("react.memo_cache_sentinel") ? (u = {
22
+ thumbnails: [],
23
+ version: 0
24
+ }, o[0] = u) : u = o[0];
25
+ let [d, f] = n(i, u), { thumbnails: p, version: m } = d, h;
26
+ o[1] === Symbol.for("react.memo_cache_sentinel") ? (h = /* @__PURE__ */ new Set(), o[1] = h) : h = o[1];
27
+ let g = r(h), _;
28
+ o[2] === Symbol.for("react.memo_cache_sentinel") ? (_ = {
29
+ pdf: null,
30
+ rotation: 0
31
+ }, o[2] = _) : _ = o[2];
32
+ let v = r(_), y;
33
+ o[3] !== s || o[4] !== c || o[5] !== l ? (y = () => {
34
+ if (!s) {
35
+ f({
36
+ type: "reset",
37
+ numPages: 0
38
+ }), g.current.clear(), v.current = {
39
+ pdf: null,
40
+ rotation: 0
41
+ };
42
+ return;
43
+ }
44
+ if (v.current.pdf !== s || v.current.rotation !== c) {
45
+ v.current = {
46
+ pdf: s,
47
+ rotation: c
48
+ }, g.current.clear(), f({
49
+ type: "reset",
50
+ numPages: s.numPages
51
+ });
52
+ return;
53
+ }
54
+ let e = l.filter((e) => !g.current.has(e));
55
+ if (e.length === 0) return;
56
+ let t = !1;
57
+ return (async () => {
58
+ for (let n of e) {
59
+ if (t) break;
60
+ let e = await s.getPage(n), r = e.getViewport({
14
61
  scale: .2,
15
- rotation: o
16
- }), i = document.createElement("canvas"), s = i.getContext("2d");
17
- s && (i.height = r.height, i.width = r.width, await n.render({
18
- canvasContext: s,
19
- viewport: r,
20
- canvas: i
21
- }).promise, e.push(i.toDataURL()));
62
+ rotation: c
63
+ }), i = document.createElement("canvas"), a = i.getContext("2d");
64
+ if (a) {
65
+ if (i.height = r.height, i.width = r.width, await e.render({
66
+ canvasContext: a,
67
+ viewport: r,
68
+ canvas: i
69
+ }).promise, t) break;
70
+ g.current.add(n), f({
71
+ type: "set",
72
+ pageNum: n,
73
+ dataUrl: i.toDataURL()
74
+ });
75
+ }
22
76
  }
23
- l(e);
24
- })();
25
- }, d = [a, o], i[1] = a, i[2] = o, i[3] = u, i[4] = d) : (u = i[3], d = i[4]), e(u, d);
26
- let f;
27
- return i[5] === c ? f = i[6] : (f = { thumbnails: c }, i[5] = c, i[6] = f), f;
77
+ })(), () => {
78
+ t = !0;
79
+ };
80
+ }, o[3] = s, o[4] = c, o[5] = l, o[6] = y) : y = o[6];
81
+ let b;
82
+ o[7] !== s || o[8] !== c || o[9] !== m || o[10] !== l ? (b = [
83
+ s,
84
+ c,
85
+ l,
86
+ m
87
+ ], o[7] = s, o[8] = c, o[9] = m, o[10] = l, o[11] = b) : b = o[11], t(y, b);
88
+ let x;
89
+ return o[12] === p ? x = o[13] : (x = { thumbnails: p }, o[12] = p, o[13] = x), x;
28
90
  }
29
91
  //#endregion
30
- export { r as useThumbnails };
92
+ export { a as useThumbnails };