pdf-tsx 1.1.0 → 1.2.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 (59) hide show
  1. package/README.md +46 -2
  2. package/dist/cjs/components/features/PDFOutline.cjs +1 -1
  3. package/dist/cjs/hooks/useAnnotationLayer.cjs +1 -1
  4. package/dist/cjs/hooks/useOverlayRects.cjs +1 -1
  5. package/dist/cjs/hooks/usePDFLoader.cjs +1 -1
  6. package/dist/cjs/hooks/usePDFRenderer.cjs +1 -1
  7. package/dist/cjs/hooks/useTextLayer.cjs +1 -1
  8. package/dist/cjs/hooks/useThumbnails.cjs +1 -1
  9. package/dist/cjs/utils/pdfFit.cjs +1 -1
  10. package/dist/cjs/utils/rotation.cjs +1 -0
  11. package/dist/cjs/vendor/pdfjs-wasm/jbig2.cjs +1 -0
  12. package/dist/cjs/vendor/pdfjs-wasm/openjpeg.cjs +1 -0
  13. package/dist/cjs/vendor/pdfjs-wasm/qcms_bg.cjs +1 -0
  14. package/dist/components/PDFSidebar.d.ts +1 -1
  15. package/dist/components/PDFViewer.d.ts +2 -2
  16. package/dist/components/features/PDFAnnotations.d.ts +2 -2
  17. package/dist/components/features/PDFAttachments.d.ts +2 -2
  18. package/dist/components/features/PDFChangeFile.d.ts +1 -1
  19. package/dist/components/features/PDFDownloadButton.d.ts +1 -1
  20. package/dist/components/features/PDFNavigation.d.ts +1 -1
  21. package/dist/components/features/PDFOutline.d.ts +1 -1
  22. package/dist/components/features/PDFPageFit.d.ts +1 -1
  23. package/dist/components/features/PDFPrintButton.d.ts +1 -1
  24. package/dist/components/features/PDFRotationControl.d.ts +1 -1
  25. package/dist/components/features/PDFSearch.d.ts +1 -1
  26. package/dist/components/features/PDFSidebarToggle.d.ts +1 -1
  27. package/dist/components/features/PDFSignatures.d.ts +2 -2
  28. package/dist/components/features/PDFThemeToggle.d.ts +1 -1
  29. package/dist/components/features/PDFThumbnails.d.ts +1 -1
  30. package/dist/components/features/PDFViewModeToggle.d.ts +11 -0
  31. package/dist/components/features/PDFZoomControls.d.ts +1 -1
  32. package/dist/components/ui/PDFToolbar.d.ts +1 -1
  33. package/dist/components/ui/PDFToolbarItem.d.ts +1 -1
  34. package/dist/components/ui/PDFToolbarSeparator.d.ts +1 -1
  35. package/dist/components/ui/ToolbarButton.d.ts +1 -1
  36. package/dist/components/ui/icons.d.ts +3 -2
  37. package/dist/context/LabelsContext.d.ts +1 -1
  38. package/dist/context/PDFViewerContext.d.ts +2 -0
  39. package/dist/context/ThemeContext.d.ts +1 -1
  40. package/dist/es/components/features/PDFOutline.js +47 -46
  41. package/dist/es/hooks/useAnnotationLayer.js +39 -38
  42. package/dist/es/hooks/useOverlayRects.js +44 -43
  43. package/dist/es/hooks/usePDFLoader.js +36 -16
  44. package/dist/es/hooks/usePDFRenderer.js +65 -64
  45. package/dist/es/hooks/useTextLayer.js +34 -33
  46. package/dist/es/hooks/useThumbnails.js +33 -32
  47. package/dist/es/utils/pdfFit.js +13 -12
  48. package/dist/es/utils/rotation.js +6 -0
  49. package/dist/es/vendor/pdfjs-wasm/jbig2.js +4 -0
  50. package/dist/es/vendor/pdfjs-wasm/openjpeg.js +4 -0
  51. package/dist/es/vendor/pdfjs-wasm/qcms_bg.js +4 -0
  52. package/dist/hooks/usePDFLoader.d.ts +1 -1
  53. package/dist/hooks/usePinchZoom.d.ts +1 -0
  54. package/dist/index.d.ts +1 -0
  55. package/dist/labels.d.ts +4 -0
  56. package/dist/utils/pdfjsPolyfill.d.ts +2 -0
  57. package/dist/utils/rotation.d.ts +7 -0
  58. package/dist/utils/zoom.d.ts +4 -0
  59. package/package.json +3 -2
@@ -1,12 +1,13 @@
1
1
  import { usePDFViewer as e } from "../../context/PDFViewerContext.js";
2
- import { useLabels as t } from "../../hooks/useLabels.js";
3
- import { useOutline as n } from "../../hooks/useOutline.js";
4
- import { IconChevronDown as r, IconChevronRight as i } from "../ui/icons.js";
5
- import a from "./PDFOutline.module.js";
6
- import { memo as o, useCallback as s, useMemo as c, useState as l } from "react";
7
- import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
2
+ import { getEffectiveRotation as t } from "../../utils/rotation.js";
3
+ import { useLabels as n } from "../../hooks/useLabels.js";
4
+ import { useOutline as r } from "../../hooks/useOutline.js";
5
+ import { IconChevronDown as i, IconChevronRight as a } from "../ui/icons.js";
6
+ import o from "./PDFOutline.module.js";
7
+ import { memo as s, useCallback as c, useMemo as l, useState as u } from "react";
8
+ import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
8
9
  //#region src/components/features/PDFOutline.tsx
9
- async function p(e, t) {
10
+ async function m(e, t) {
10
11
  if (!e || !t) return null;
11
12
  try {
12
13
  let n = typeof t == "string" ? await e.getDestination(t) : t;
@@ -20,10 +21,10 @@ async function p(e, t) {
20
21
  return null;
21
22
  }
22
23
  }
23
- var m = o(function e({ node: t, depth: n, onNavigate: o }) {
24
- let [p, m] = l(n === 0), h = t.items.length > 0, g = s((e) => {
24
+ var h = s(function e({ node: t, depth: n, onNavigate: r }) {
25
+ let [s, m] = u(n === 0), h = t.items.length > 0, g = c((e) => {
25
26
  e.stopPropagation(), m((e) => !e);
26
- }, []), _ = s(() => o(t.dest), [o, t.dest]), v = c(() => ({
27
+ }, []), _ = c(() => r(t.dest), [r, t.dest]), v = l(() => ({
27
28
  paddingLeft: 12 + n * 14,
28
29
  fontWeight: t.bold ? 600 : 400,
29
30
  fontStyle: t.italic ? "italic" : "normal"
@@ -32,66 +33,66 @@ var m = o(function e({ node: t, depth: n, onNavigate: o }) {
32
33
  t.bold,
33
34
  t.italic
34
35
  ]);
35
- return /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ f("div", {
36
- className: a.row,
36
+ return /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ p("div", {
37
+ className: o.row,
37
38
  style: v,
38
39
  onClick: _,
39
- children: [h ? /* @__PURE__ */ d("button", {
40
- className: a.chevronBtn,
40
+ children: [h ? /* @__PURE__ */ f("button", {
41
+ className: o.chevronBtn,
41
42
  onClick: g,
42
- children: d(p ? r : i, { size: 12 })
43
- }) : /* @__PURE__ */ d("span", { style: {
43
+ children: f(s ? i : a, { size: 12 })
44
+ }) : /* @__PURE__ */ f("span", { style: {
44
45
  width: 16,
45
46
  flexShrink: 0
46
- } }), /* @__PURE__ */ d("span", {
47
- className: a.title,
47
+ } }), /* @__PURE__ */ f("span", {
48
+ className: o.title,
48
49
  title: t.title,
49
50
  children: t.title
50
51
  })]
51
- }), p && t.items.map((t, r) => /* @__PURE__ */ d(e, {
52
+ }), s && t.items.map((t, i) => /* @__PURE__ */ f(e, {
52
53
  node: t,
53
54
  depth: n + 1,
54
- onNavigate: o
55
- }, r))] });
55
+ onNavigate: r
56
+ }, i))] });
56
57
  });
57
- function h() {
58
- let { pdf: r, zoom: i, rotation: o, goToPage: c } = e(), l = t(), { outline: u, loading: h } = n({ pdf: r }), g = s(async (e) => {
59
- let t = await p(r, e);
60
- if (t) {
61
- if (t.pdfTop !== null) try {
62
- let [, e] = (await r.getPage(t.page)).getViewport({
63
- scale: i,
64
- rotation: o
65
- }).convertToViewportPoint(0, t.pdfTop);
66
- c(t.page, e);
58
+ function g() {
59
+ let { pdf: i, zoom: a, rotation: s, goToPage: l } = e(), u = n(), { outline: d, loading: g } = r({ pdf: i }), _ = c(async (e) => {
60
+ let n = await m(i, e);
61
+ if (n) {
62
+ if (n.pdfTop !== null) try {
63
+ let e = await i.getPage(n.page), [, r] = e.getViewport({
64
+ scale: a,
65
+ rotation: t(e, s)
66
+ }).convertToViewportPoint(0, n.pdfTop);
67
+ l(n.page, r);
67
68
  return;
68
69
  } catch {}
69
- c(t.page);
70
+ l(n.page);
70
71
  }
71
72
  }, [
72
- r,
73
73
  i,
74
- o,
75
- c
74
+ a,
75
+ s,
76
+ l
76
77
  ]);
77
- return /* @__PURE__ */ f("div", {
78
- className: a.tree,
78
+ return /* @__PURE__ */ p("div", {
79
+ className: o.tree,
79
80
  children: [
80
- h && /* @__PURE__ */ d("div", {
81
- className: a.emptyState,
82
- children: l.outlineLoading
81
+ g && /* @__PURE__ */ f("div", {
82
+ className: o.emptyState,
83
+ children: u.outlineLoading
83
84
  }),
84
- !h && u.length === 0 && /* @__PURE__ */ d("div", {
85
- className: a.emptyState,
86
- children: l.outlineEmpty
85
+ !g && d.length === 0 && /* @__PURE__ */ f("div", {
86
+ className: o.emptyState,
87
+ children: u.outlineEmpty
87
88
  }),
88
- !h && u.map((e, t) => /* @__PURE__ */ d(m, {
89
+ !g && d.map((e, t) => /* @__PURE__ */ f(h, {
89
90
  node: e,
90
91
  depth: 0,
91
- onNavigate: g
92
+ onNavigate: _
92
93
  }, t))
93
94
  ]
94
95
  });
95
96
  }
96
97
  //#endregion
97
- export { h as PDFOutline };
98
+ export { g as PDFOutline };
@@ -1,25 +1,26 @@
1
- import { isSafeUrl as e } from "../utils/url.js";
2
- import { useEffect as t, useState as n } from "react";
1
+ import { getEffectiveRotation as e } from "../utils/rotation.js";
2
+ import { isSafeUrl as t } from "../utils/url.js";
3
+ import { useEffect as n, useState as r } from "react";
3
4
  import "pdfjs-dist";
4
5
  //#region src/hooks/useAnnotationLayer.ts
5
- function r({ pdf: r, zoom: i, rotation: a, mountedPages: o, goToPage: s }) {
6
- let [c, l] = n([]), [u, d] = n([]);
7
- t(() => {
8
- if (!r) return;
9
- let e = !1;
6
+ function i({ pdf: i, zoom: a, rotation: o, mountedPages: s, goToPage: c }) {
7
+ let [l, u] = r([]), [d, f] = r([]);
8
+ n(() => {
9
+ if (!i) return;
10
+ let t = !1;
10
11
  return (async () => {
11
- let t = [], n = [];
12
- for (let s of o) {
13
- if (e) break;
14
- let o = await r.getPage(s), c = o.getViewport({
15
- scale: i,
16
- rotation: a
17
- }), l = await o.getAnnotations();
18
- for (let e of l) {
12
+ let n = [], r = [];
13
+ for (let c of s) {
14
+ if (t) break;
15
+ let s = await i.getPage(c), l = s.getViewport({
16
+ scale: a,
17
+ rotation: e(s, o)
18
+ }), u = await s.getAnnotations();
19
+ for (let e of u) {
19
20
  if (!e.rect) continue;
20
- let r = e.rect, [i, a, o, l] = c.convertToViewportRectangle(r), u = Math.min(i, o), d = Math.min(a, l), f = Math.abs(o - i), p = Math.abs(l - a);
21
- if (e.subtype === "Link") t.push({
22
- page: s,
21
+ let t = e.rect, [i, a, o, s] = l.convertToViewportRectangle(t), u = Math.min(i, o), d = Math.min(a, s), f = Math.abs(o - i), p = Math.abs(s - a);
22
+ if (e.subtype === "Link") n.push({
23
+ page: c,
23
24
  x: u,
24
25
  y: d,
25
26
  width: f,
@@ -29,9 +30,9 @@ function r({ pdf: r, zoom: i, rotation: a, mountedPages: o, goToPage: s }) {
29
30
  newWindow: e.newWindow
30
31
  });
31
32
  else {
32
- let t = e.contentsObj, i = e.titleObj, a = t?.str ?? e.contents ?? "", o = i?.str ?? e.title;
33
- a && n.push({
34
- page: s,
33
+ let n = e.contentsObj, i = e.titleObj, a = n?.str ?? e.contents ?? "", o = i?.str ?? e.title;
34
+ a && r.push({
35
+ page: c,
35
36
  x: u,
36
37
  y: d,
37
38
  width: f,
@@ -39,40 +40,40 @@ function r({ pdf: r, zoom: i, rotation: a, mountedPages: o, goToPage: s }) {
39
40
  contents: a,
40
41
  title: o || void 0,
41
42
  subtype: e.subtype,
42
- pdfRect: r
43
+ pdfRect: t
43
44
  });
44
45
  }
45
46
  }
46
47
  }
47
- e || (l(t), d(n));
48
+ t || (u(n), f(r));
48
49
  })(), () => {
49
- e = !0;
50
+ t = !0;
50
51
  };
51
52
  }, [
52
- r,
53
53
  i,
54
54
  a,
55
- o
55
+ o,
56
+ s
56
57
  ]);
57
- let f = async (t) => {
58
- if (t.url) {
59
- if (!e(t.url)) return;
60
- window.open(t.url, "_blank", "noopener,noreferrer");
58
+ let p = async (e) => {
59
+ if (e.url) {
60
+ if (!t(e.url)) return;
61
+ window.open(e.url, "_blank", "noopener,noreferrer");
61
62
  return;
62
63
  }
63
- if (t.dest && r) {
64
- let e = null;
65
- if (typeof t.dest == "string" ? e = await r.getDestination(t.dest) : Array.isArray(t.dest) && (e = t.dest), !e) return;
66
- s(await r.getPageIndex(e[0]) + 1);
64
+ if (e.dest && i) {
65
+ let t = null;
66
+ if (typeof e.dest == "string" ? t = await i.getDestination(e.dest) : Array.isArray(e.dest) && (t = e.dest), !t) return;
67
+ c(await i.getPageIndex(t[0]) + 1);
67
68
  }
68
69
  };
69
70
  return {
70
- linkOverlays: c.map((e) => ({
71
+ linkOverlays: l.map((e) => ({
71
72
  ...e,
72
- _handleClick: f.bind(null, e)
73
+ _handleClick: p.bind(null, e)
73
74
  })),
74
- noteOverlays: u
75
+ noteOverlays: d
75
76
  };
76
77
  }
77
78
  //#endregion
78
- export { r as useAnnotationLayer };
79
+ export { i as useAnnotationLayer };
@@ -1,63 +1,64 @@
1
- import { useEffect as e, useState as t } from "react";
1
+ import { getEffectiveRotation as e } from "../utils/rotation.js";
2
+ import { useEffect as t, useState as n } from "react";
2
3
  import "pdfjs-dist";
3
4
  //#region src/hooks/useOverlayRects.ts
4
- function n({ pdf: n, highlight: r, searchMatches: i, zoom: a, rotation: o }) {
5
- let [s, c] = t(null), [l, u] = t([]);
6
- return e(() => {
7
- if (!n || i.length === 0) return;
8
- let e = !1;
5
+ function r({ pdf: r, highlight: i, searchMatches: a, zoom: o, rotation: s }) {
6
+ let [c, l] = n(null), [u, d] = n([]);
7
+ return t(() => {
8
+ if (!r || a.length === 0) return;
9
+ let t = !1;
9
10
  return (async () => {
10
- let t = [];
11
- for (let r of i) {
12
- if (e) break;
13
- let [i, s, c, l] = (await n.getPage(r.page)).getViewport({
14
- scale: a,
15
- rotation: o
16
- }).convertToViewportRectangle(r.pdfRect);
17
- t.push({
18
- page: r.page,
19
- x: Math.min(i, c),
20
- y: Math.min(s, l),
21
- width: Math.abs(c - i),
22
- height: Math.abs(l - s)
11
+ let n = [];
12
+ for (let i of a) {
13
+ if (t) break;
14
+ let a = await r.getPage(i.page), [c, l, u, d] = a.getViewport({
15
+ scale: o,
16
+ rotation: e(a, s)
17
+ }).convertToViewportRectangle(i.pdfRect);
18
+ n.push({
19
+ page: i.page,
20
+ x: Math.min(c, u),
21
+ y: Math.min(l, d),
22
+ width: Math.abs(u - c),
23
+ height: Math.abs(d - l)
23
24
  });
24
25
  }
25
- e || u(t);
26
+ t || d(n);
26
27
  })(), () => {
27
- e = !0;
28
+ t = !0;
28
29
  };
29
30
  }, [
30
- i,
31
31
  a,
32
32
  o,
33
- n
34
- ]), e(() => {
35
- if (!r || !n) return;
36
- let e = !1;
33
+ s,
34
+ r
35
+ ]), t(() => {
36
+ if (!i || !r) return;
37
+ let t = !1;
37
38
  return (async () => {
38
- let [t, i, s, l] = (await n.getPage(r.page)).getViewport({
39
- scale: a,
40
- rotation: o
41
- }).convertToViewportRectangle(r.pdfRect);
42
- e || c({
43
- page: r.page,
44
- x: Math.min(t, s),
45
- y: Math.min(i, l),
46
- width: Math.abs(s - t),
47
- height: Math.abs(l - i)
39
+ let n = await r.getPage(i.page), [a, c, u, d] = n.getViewport({
40
+ scale: o,
41
+ rotation: e(n, s)
42
+ }).convertToViewportRectangle(i.pdfRect);
43
+ t || l({
44
+ page: i.page,
45
+ x: Math.min(a, u),
46
+ y: Math.min(c, d),
47
+ width: Math.abs(u - a),
48
+ height: Math.abs(d - c)
48
49
  });
49
50
  })(), () => {
50
- e = !0;
51
+ t = !0;
51
52
  };
52
53
  }, [
53
- r,
54
- a,
54
+ i,
55
55
  o,
56
- n
56
+ s,
57
+ r
57
58
  ]), {
58
- overlayRect: !r || !n ? null : s,
59
- searchOverlays: !n || i.length === 0 ? [] : l
59
+ overlayRect: !i || !r ? null : c,
60
+ searchOverlays: !r || a.length === 0 ? [] : u
60
61
  };
61
62
  }
62
63
  //#endregion
63
- export { n as useOverlayRects };
64
+ export { r as useOverlayRects };
@@ -1,27 +1,47 @@
1
- import { useEffect as e, useState as t } from "react";
2
- import * as n from "pdfjs-dist";
1
+ import e from "../vendor/pdfjs-wasm/openjpeg.js";
2
+ import t from "../vendor/pdfjs-wasm/jbig2.js";
3
+ import n from "../vendor/pdfjs-wasm/qcms_bg.js";
4
+ import { useEffect as r, useState as i } from "react";
5
+ import * as a from "pdfjs-dist";
3
6
  //#region src/hooks/usePDFLoader.ts
4
- function r(r) {
5
- let [i, a] = t(null), [o, s] = t(0), [c, l] = t(!0);
6
- return e(() => {
7
- l(!0), a(null), s(0);
8
- let e = new FileReader();
9
- e.onload = async (e) => {
7
+ var o = {
8
+ "openjpeg.wasm": e,
9
+ "jbig2.wasm": t,
10
+ "qcms_bg.wasm": n
11
+ }, s = class {
12
+ async fetch({ kind: e, filename: t }) {
13
+ let n = e === "wasmUrl" ? o[t] : void 0;
14
+ if (!n) throw Error(`Unable to load ${e} data at: ${t}`);
15
+ let r = await fetch(n);
16
+ return new Uint8Array(await r.arrayBuffer());
17
+ }
18
+ };
19
+ function c(e) {
20
+ let [t, n] = i(null), [o, c] = i(0), [l, u] = i(!0);
21
+ return r(() => {
22
+ u(!0), n(null), c(0);
23
+ let t = new FileReader();
24
+ t.onload = async (e) => {
10
25
  let t = new Uint8Array(e.target?.result);
11
26
  try {
12
- let e = await n.getDocument(t).promise;
13
- a(e), s(e.numPages);
27
+ let e = await a.getDocument({
28
+ data: t,
29
+ wasmUrl: "wasm/",
30
+ useWorkerFetch: !1,
31
+ BinaryDataFactory: s
32
+ }).promise;
33
+ n(e), c(e.numPages);
14
34
  } catch (e) {
15
35
  console.error("Errore caricamento:", e);
16
36
  } finally {
17
- l(!1);
37
+ u(!1);
18
38
  }
19
- }, e.readAsArrayBuffer(r);
20
- }, [r]), {
21
- pdf: i,
39
+ }, t.readAsArrayBuffer(e);
40
+ }, [e]), {
41
+ pdf: t,
22
42
  numPages: o,
23
- loading: c
43
+ loading: l
24
44
  };
25
45
  }
26
46
  //#endregion
27
- export { r as usePDFLoader };
47
+ export { c as usePDFLoader };
@@ -1,78 +1,79 @@
1
- import { useEffect as e, useRef as t, useState as n } from "react";
1
+ import { getEffectiveRotation as e } from "../utils/rotation.js";
2
+ import { useEffect as t, useRef as n, useState as r } from "react";
2
3
  import "pdfjs-dist";
3
4
  //#region src/hooks/usePDFRenderer.ts
4
- function r(e, t, n, r) {
5
- let i = e.getContext("2d");
6
- if (!i) return null;
7
- let a = t.getViewport({
8
- scale: n,
9
- rotation: r
10
- }), o = window.devicePixelRatio || 1, s = Math.min(1, 4096 / Math.max(a.width, a.height)), c = Math.sqrt(Math.min(1, 16777216 / (a.width * a.height))), l = Math.max(.1, Math.min(o, s, c));
11
- l < o && console.warn(`[pdf-tsx] canvas clamped to avoid blank render: page=${t.pageNumber} zoom=${n} dpr=${o} requested=${Math.round(a.width * o)}x${Math.round(a.height * o)}px clamped=${Math.round(a.width * l)}x${Math.round(a.height * l)}px`);
12
- let u = t.getViewport({
13
- scale: n * l,
14
- rotation: r
5
+ function i(t, n, r, i) {
6
+ let a = t.getContext("2d");
7
+ if (!a) return null;
8
+ let o = e(n, i), s = n.getViewport({
9
+ scale: r,
10
+ rotation: o
11
+ }), c = window.devicePixelRatio || 1, l = Math.min(1, 4096 / Math.max(s.width, s.height)), u = Math.sqrt(Math.min(1, 16777216 / (s.width * s.height))), d = Math.max(.1, Math.min(c, l, u));
12
+ d < c && console.warn(`[pdf-tsx] canvas clamped to avoid blank render: page=${n.pageNumber} zoom=${r} dpr=${c} requested=${Math.round(s.width * c)}x${Math.round(s.height * c)}px clamped=${Math.round(s.width * d)}x${Math.round(s.height * d)}px`);
13
+ let f = n.getViewport({
14
+ scale: r * d,
15
+ rotation: o
15
16
  });
16
- return e.width = u.width, e.height = u.height, e.style.width = `${a.width}px`, e.style.height = `${a.height}px`, t.render({
17
- canvasContext: i,
18
- viewport: u,
19
- canvas: e
17
+ return t.width = f.width, t.height = f.height, t.style.width = `${s.width}px`, t.style.height = `${s.height}px`, n.render({
18
+ canvasContext: a,
19
+ viewport: f,
20
+ canvas: t
20
21
  });
21
22
  }
22
- function i({ pdf: i, zoom: a, rotation: o, visiblePages: s, canvasRefs: c }) {
23
- let [l, u] = n([]), [d, f] = n(/* @__PURE__ */ new Set()), p = t([]), m = t(/* @__PURE__ */ new Set()), h = t(!1);
24
- return e(() => {
25
- if (!i) return;
26
- h.current = !1, m.current = /* @__PURE__ */ new Set(), f(/* @__PURE__ */ new Set());
27
- let e = !1;
23
+ function a({ pdf: a, zoom: o, rotation: s, visiblePages: c, canvasRefs: l }) {
24
+ let [u, d] = r([]), [f, p] = r(/* @__PURE__ */ new Set()), m = n([]), h = n(/* @__PURE__ */ new Set()), g = n(!1);
25
+ return t(() => {
26
+ if (!a) return;
27
+ g.current = !1, h.current = /* @__PURE__ */ new Set(), p(/* @__PURE__ */ new Set());
28
+ let t = !1;
28
29
  return (async () => {
29
- let t = p.current.map((e) => e ? (e.cancel(), e.promise.catch(() => {})) : Promise.resolve());
30
- if (await Promise.all(t), p.current = Array(i.numPages).fill(null), e) return;
31
- let n = await i.getPage(1);
32
- if (e) return;
33
- let r = n.getViewport({
34
- scale: a,
35
- rotation: o
36
- }), s = {
37
- width: r.width,
38
- height: r.height
30
+ let n = m.current.map((e) => e ? (e.cancel(), e.promise.catch(() => {})) : Promise.resolve());
31
+ if (await Promise.all(n), m.current = Array(a.numPages).fill(null), t) return;
32
+ let r = await a.getPage(1);
33
+ if (t) return;
34
+ let i = r.getViewport({
35
+ scale: o,
36
+ rotation: e(r, s)
37
+ }), c = {
38
+ width: i.width,
39
+ height: i.height
39
40
  };
40
- u(Array(i.numPages).fill(s));
41
- let c = await Promise.all(Array.from({ length: i.numPages }, async (e, t) => {
42
- let r = (t === 0 ? n : await i.getPage(t + 1)).getViewport({
43
- scale: a,
44
- rotation: o
41
+ d(Array(a.numPages).fill(c));
42
+ let l = await Promise.all(Array.from({ length: a.numPages }, async (t, n) => {
43
+ let i = n === 0 ? r : await a.getPage(n + 1), c = i.getViewport({
44
+ scale: o,
45
+ rotation: e(i, s)
45
46
  });
46
47
  return {
47
- width: r.width,
48
- height: r.height
48
+ width: c.width,
49
+ height: c.height
49
50
  };
50
51
  }));
51
- e || (h.current = !0, u(c));
52
+ t || (g.current = !0, d(l));
52
53
  })(), () => {
53
- e = !0, p.current.forEach((e) => e?.cancel());
54
+ t = !0, m.current.forEach((e) => e?.cancel());
54
55
  };
55
56
  }, [
56
- i,
57
57
  a,
58
- o
59
- ]), e(() => {
60
- if (!i || l.length !== i.numPages || !h.current) return;
58
+ o,
59
+ s
60
+ ]), t(() => {
61
+ if (!a || u.length !== a.numPages || !g.current) return;
61
62
  let e = !1;
62
63
  return (async () => {
63
- for (let t of s) {
64
- if (e || m.current.has(t)) continue;
65
- let n = await i.getPage(t);
64
+ for (let t of c) {
65
+ if (e || h.current.has(t)) continue;
66
+ let n = await a.getPage(t);
66
67
  if (e) return;
67
- let s = c.current[t - 1];
68
- if (!s) continue;
69
- let l = p.current[t - 1];
70
- if (l && (l.cancel(), await l.promise.catch(() => {}), e)) return;
71
- let u = r(s, n, a, o);
68
+ let r = l.current[t - 1];
69
+ if (!r) continue;
70
+ let c = m.current[t - 1];
71
+ if (c && (c.cancel(), await c.promise.catch(() => {}), e)) return;
72
+ let u = i(r, n, o, s);
72
73
  if (u) {
73
- p.current[t - 1] = u;
74
+ m.current[t - 1] = u;
74
75
  try {
75
- await u.promise, e || (m.current = new Set(m.current).add(t), f((e) => {
76
+ await u.promise, e || (h.current = new Set(h.current).add(t), p((e) => {
76
77
  if (e.has(t)) return e;
77
78
  let n = new Set(e);
78
79
  return n.add(t), n;
@@ -80,7 +81,7 @@ function i({ pdf: i, zoom: a, rotation: o, visiblePages: s, canvasRefs: c }) {
80
81
  } catch (e) {
81
82
  e && typeof e == "object" && "name" in e && e.name !== "RenderingCancelledException" && console.error("Render error:", e);
82
83
  } finally {
83
- p.current[t - 1] === u && (p.current[t - 1] = null);
84
+ m.current[t - 1] === u && (m.current[t - 1] = null);
84
85
  }
85
86
  }
86
87
  }
@@ -88,16 +89,16 @@ function i({ pdf: i, zoom: a, rotation: o, visiblePages: s, canvasRefs: c }) {
88
89
  e = !0;
89
90
  };
90
91
  }, [
91
- i,
92
- l,
93
- o,
94
- s,
95
92
  a,
96
- c
93
+ u,
94
+ s,
95
+ c,
96
+ o,
97
+ l
97
98
  ]), {
98
- pageSizes: l,
99
- renderedPages: d
99
+ pageSizes: u,
100
+ renderedPages: f
100
101
  };
101
102
  }
102
103
  //#endregion
103
- export { i as usePDFRenderer };
104
+ export { a as usePDFRenderer };