@react-pdf-kit/viewer 2.9.1-rc.2 → 2.9.2-rc.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.
@@ -1,15 +1,15 @@
1
1
  import { ScrollMode as e, ViewMode as t } from "./types.js";
2
2
  //#region lib/utils/documentLayout.ts
3
- var n = (e, t) => Math.max(0, (e - t) / 2), r = .5, i = (e, t, i) => {
4
- let a = n(e, i), o = Math.max(0, e - t);
5
- return Math.max(0, a - o * r);
6
- }, a = (e) => e.reduce((e, t) => e + t, 0), o = (e) => Math.min(e.widths.length, e.heights.length), s = (e) => e === "WRAPPED", c = (e, t) => {
3
+ var n = (e, t) => Math.max(0, (e - t) / 2), r = 0, i = .5, a = (e, t, r) => {
4
+ let a = n(e, r), o = Math.max(0, e - t);
5
+ return Math.max(0, a - o * i);
6
+ }, o = (e) => e.reduce((e, t) => e + t, 0), s = (e) => Math.min(e.widths.length, e.heights.length), c = (e) => e === "WRAPPED", l = (e, t) => {
7
7
  let n = t - 1;
8
8
  return {
9
9
  width: e.widths[n] || 0,
10
10
  height: e.heights[n] || 0
11
11
  };
12
- }, l = (e, n, r) => {
12
+ }, u = (e, n, r) => {
13
13
  if (!r) return [];
14
14
  let i = Math.max(1, Math.min(e, r));
15
15
  if (n === t.DUAL_PAGE) {
@@ -22,77 +22,77 @@ var n = (e, t) => Math.max(0, (e - t) / 2), r = .5, i = (e, t, i) => {
22
22
  return [e, e + 1].filter((e) => e <= r);
23
23
  }
24
24
  return [i];
25
- }, u = (e, t) => {
26
- let n = t.map((t) => c(e, t));
25
+ }, d = (e, t) => {
26
+ let n = t.map((t) => l(e, t));
27
27
  return {
28
28
  pageNumbers: t,
29
- width: a(n.map((e) => e.width)),
29
+ width: o(n.map((e) => e.width)),
30
30
  height: Math.max(...n.map((e) => e.height), 0)
31
31
  };
32
- }, d = (e, n) => {
33
- let r = o(e), i = [];
32
+ }, f = (e, n) => {
33
+ let r = s(e), i = [];
34
34
  if (n === t.DUAL_PAGE) {
35
- for (let t = 1; t <= r; t += 2) i.push(u(e, [t, t + 1].filter((e) => e <= r)));
35
+ for (let t = 1; t <= r; t += 2) i.push(d(e, [t, t + 1].filter((e) => e <= r)));
36
36
  return i;
37
37
  }
38
38
  if (n === t.DUAL_PAGE_WITH_COVER) {
39
- r >= 1 && i.push(u(e, [1]));
40
- for (let t = 2; t <= r; t += 2) i.push(u(e, [t, t + 1].filter((e) => e <= r)));
39
+ r >= 1 && i.push(d(e, [1]));
40
+ for (let t = 2; t <= r; t += 2) i.push(d(e, [t, t + 1].filter((e) => e <= r)));
41
41
  return i;
42
42
  }
43
- for (let t = 1; t <= r; t += 1) i.push(u(e, [t]));
43
+ for (let t = 1; t <= r; t += 1) i.push(d(e, [t]));
44
44
  return i;
45
- }, f = (e, t) => {
46
- let n = o(e), r = Math.max(t, 1), i = [], a = [], s = 0;
45
+ }, p = (e, t) => {
46
+ let n = s(e), r = Math.max(t, 1), i = [], a = [], o = 0;
47
47
  for (let t = 1; t <= n; t += 1) {
48
- let { width: n } = c(e, t);
49
- a.length > 0 && s + n > r && (i.push(u(e, a)), a = [], s = 0), a.push(t), s += n;
48
+ let { width: n } = l(e, t);
49
+ a.length > 0 && o + n > r && (i.push(d(e, a)), a = [], o = 0), a.push(t), o += n;
50
50
  }
51
- return a.length && i.push(u(e, a)), i;
52
- }, p = ({ pageDimensions: t, viewportWidth: n, scrollMode: r, viewMode: i, focusedPage: a }) => {
53
- let c = o(t);
54
- return c ? r === e.PAGE_SCROLLING ? [u(t, l(a || 1, i, c))] : r === e.HORIZONTAL_SCROLLING ? [u(t, Array.from({ length: c }, (e, t) => t + 1))] : s(r) ? f(t, n) : d(t, i) : [];
55
- }, m = (t) => {
56
- let { pageDimensions: r, viewportWidth: a, viewportHeight: o, scrollMode: l, viewMode: u } = t, d = p(t), f = s(l) ? Math.max(a, ...d.map((e) => e.width), 0) : Math.max(...d.map((e) => e.width), 0), m = [], h = [], g = 0;
51
+ return a.length && i.push(d(e, a)), i;
52
+ }, m = ({ pageDimensions: t, viewportWidth: n, scrollMode: r, viewMode: i, focusedPage: a }) => {
53
+ let o = s(t);
54
+ return o ? r === e.PAGE_SCROLLING ? [d(t, u(a || 1, i, o))] : r === e.HORIZONTAL_SCROLLING ? [d(t, Array.from({ length: o }, (e, t) => t + 1))] : c(r) ? p(t, n) : f(t, i) : [];
55
+ }, h = (t) => {
56
+ let { pageDimensions: r, viewportWidth: i, viewportHeight: o, scrollMode: s, viewMode: u } = t, d = m(t), f = c(s) ? Math.max(i, ...d.map((e) => e.width), 0) : Math.max(...d.map((e) => e.width), 0), p = [], h = [], g = 0;
57
57
  d.forEach((t, o) => {
58
- let u = s(l) ? Math.max(f, t.width) : t.width, d = {
58
+ let u = c(s) ? Math.max(f, t.width) : t.width, d = {
59
59
  index: o,
60
60
  top: g,
61
61
  width: u,
62
62
  height: t.height,
63
63
  pageNumbers: t.pageNumbers
64
- }, p = l !== e.HORIZONTAL_SCROLLING && !s(l) && t.width < f ? i(f, a, t.width) : n(f, t.width);
64
+ }, m = s !== e.HORIZONTAL_SCROLLING && !c(s) && t.width < f ? a(f, i, t.width) : n(f, t.width);
65
65
  t.pageNumbers.forEach((e) => {
66
- let { width: t, height: n } = c(r, e);
66
+ let { width: t, height: n } = l(r, e);
67
67
  h.push({
68
68
  pageNumber: e,
69
69
  rowIndex: o,
70
- left: p,
70
+ left: m,
71
71
  top: g,
72
72
  width: t,
73
73
  height: n
74
- }), p += t;
75
- }), m.push(d), g += t.height;
74
+ }), m += t;
75
+ }), p.push(d), g += t.height;
76
76
  });
77
- let _ = g, v = l === e.HORIZONTAL_SCROLLING ? 0 : n(a, f), y = l === e.PAGE_SCROLLING || l === e.HORIZONTAL_SCROLLING ? n(o, _) : 0;
77
+ let _ = g, v = s === e.HORIZONTAL_SCROLLING ? 0 : n(i, f), y = s === e.PAGE_SCROLLING || s === e.HORIZONTAL_SCROLLING ? n(o, _) : 0;
78
78
  return {
79
- rows: m,
79
+ rows: p,
80
80
  pages: h,
81
81
  documentWidth: f,
82
82
  documentHeight: _,
83
83
  offsetLeft: v,
84
84
  offsetTop: y,
85
- scrollWidth: Math.max(a, v + f),
85
+ scrollWidth: Math.max(i, v + f),
86
86
  scrollHeight: Math.max(o, y + _),
87
- viewportWidth: a,
87
+ viewportWidth: i,
88
88
  viewportHeight: o,
89
- scrollMode: l,
89
+ scrollMode: s,
90
90
  viewMode: u
91
91
  };
92
- }, h = (e, t) => e.pages.find((e) => e.pageNumber === t) ?? null, g = (e, t, r, i) => ({
93
- x: n(e, r),
94
- y: n(t, i)
95
- }), _ = (e, t, n) => {
92
+ }, g = (e, t) => e.pages.find((e) => e.pageNumber === t) ?? null, _ = (e, t, i, a) => ({
93
+ x: n(e, i),
94
+ y: r
95
+ }), v = (e, t, n) => {
96
96
  let r = e.rows.find((e) => n >= e.top && n <= e.top + e.height) ?? e.rows.reduce((e, t) => {
97
97
  if (!e) return t;
98
98
  let r = e.top + e.height / 2, i = t.top + t.height / 2;
@@ -105,7 +105,7 @@ var n = (e, t) => Math.max(0, (e - t) / 2), r = .5, i = (e, t, i) => {
105
105
  let r = e.left + e.width / 2, i = n.left + n.width / 2;
106
106
  return Math.abs(t - i) < Math.abs(t - r) ? n : e;
107
107
  }, null);
108
- }, v = (e, t, n, r, i, a = 1) => {
108
+ }, y = (e, t, n, r, i, a = 1) => {
109
109
  let o = t - e.offsetTop, s = o + i, c = n - e.offsetLeft, l = c + r, u = e.rows.filter((e) => e.top + e.height >= o && e.top <= s), d = u[0]?.index ?? 0, f = u[u.length - 1]?.index ?? d, p = Math.max(0, d - a), m = Math.min(e.rows.length - 1, f + a), h = r * Math.max(1, a), g = e.pages.reduce((e, t) => {
110
110
  let n = e.get(t.rowIndex);
111
111
  return n ? n.push(t) : e.set(t.rowIndex, [t]), e;
@@ -117,7 +117,7 @@ var n = (e, t) => Math.max(0, (e - t) / 2), r = .5, i = (e, t, i) => {
117
117
  return t >= c - h && e.left <= l + h && n >= o && e.top <= s;
118
118
  })
119
119
  }));
120
- }, y = (e, t, n) => {
120
+ }, b = (e, t, n) => {
121
121
  let r = new Set(t), i = n ? new Set(n) : null, a = e.pages.reduce((e, t) => {
122
122
  if (i && !i.has(t.pageNumber)) return e;
123
123
  let n = e.get(t.rowIndex);
@@ -127,8 +127,8 @@ var n = (e, t) => Math.max(0, (e - t) / 2), r = .5, i = (e, t, i) => {
127
127
  ...e,
128
128
  pages: a.get(e.index) ?? []
129
129
  }));
130
- }, b = (t, n) => {
131
- let r = h(t, n);
130
+ }, x = (t, n) => {
131
+ let r = g(t, n);
132
132
  return r ? t.scrollMode === e.HORIZONTAL_SCROLLING ? {
133
133
  left: t.offsetLeft + r.left,
134
134
  top: 0
@@ -138,4 +138,4 @@ var n = (e, t) => Math.max(0, (e - t) / 2), r = .5, i = (e, t, i) => {
138
138
  }) : null;
139
139
  };
140
140
  //#endregion
141
- export { m as buildDocumentLayout, g as getPageContentOffset, _ as getPageFromDocumentPoint, l as getPageGroupForPage, h as getPagePlacement, y as getRowsByIndexes, b as getScrollTargetForPage, v as getVisibleRows };
141
+ export { h as buildDocumentLayout, _ as getPageContentOffset, v as getPageFromDocumentPoint, u as getPageGroupForPage, g as getPagePlacement, b as getRowsByIndexes, x as getScrollTargetForPage, y as getVisibleRows };
@@ -3,7 +3,7 @@ import { LicenseType as t } from "../types.js";
3
3
  import { appConsole as n } from "../appConsole.js";
4
4
  import { useCallback as r, useEffect as i, useState as a } from "react";
5
5
  //#region lib/utils/hooks/useLicense.ts
6
- var o = /* @__PURE__ */ new Date("2026-08-25T06:35:46.374Z"), s = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIokvErJ0Fctu0jduSAx\ngr+5Har/VSuZLlOunS28hnlqqA+OF1apHL7RYkjBosS15yvviYdLrVWYHpHnoY4b\nHLQ9I6YX6FMB9T/VbB4xLdVdKvfi8r49aTScl5EKuSpgpPgz2VSJTfvVGcRuth/Y\nBm7PPGYdL2l2gvKDxchmmsHFPukGki9L4JOUeIVX0GXAxabENckaEH/iC1NZhX+W\nvXnpHeHuIIKlZ16LSivXNgo6BH2Z3GFdg4G3cAaXr6qNP8fsacYNqv2SpTW1viFD\nvzcGRabN25gpJAp9/syeScefWH3OiJY1lmw88oTiJbjIoiq6AkPhfn3G9mF54nvR\nkwIDAQAB\n-----END PUBLIC KEY-----", c = "Please visit https://app.react-pdf-kit.dev to generate a new license key.", l = {
6
+ var o = /* @__PURE__ */ new Date("2026-09-02T03:23:29.730Z"), s = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIokvErJ0Fctu0jduSAx\ngr+5Har/VSuZLlOunS28hnlqqA+OF1apHL7RYkjBosS15yvviYdLrVWYHpHnoY4b\nHLQ9I6YX6FMB9T/VbB4xLdVdKvfi8r49aTScl5EKuSpgpPgz2VSJTfvVGcRuth/Y\nBm7PPGYdL2l2gvKDxchmmsHFPukGki9L4JOUeIVX0GXAxabENckaEH/iC1NZhX+W\nvXnpHeHuIIKlZ16LSivXNgo6BH2Z3GFdg4G3cAaXr6qNP8fsacYNqv2SpTW1viFD\nvzcGRabN25gpJAp9/syeScefWH3OiJY1lmw88oTiJbjIoiq6AkPhfn3G9mF54nvR\nkwIDAQAB\n-----END PUBLIC KEY-----", c = "Please visit https://app.react-pdf-kit.dev to generate a new license key.", l = {
7
7
  invalidLicense: `You are currently using without a valid license. ${c}`,
8
8
  mismatchedDomain: `Your license key is not valid for the current domain / IP. ${c}`,
9
9
  expired: `Your license key has expired. ${c}`,
@@ -8,11 +8,15 @@ var s = (s, c) => {
8
8
  f.current = d;
9
9
  let [p, m] = o([]), { targetScrollPage: h } = t(), g = e(p, 0, 500);
10
10
  i(() => {
11
- g.length > 0 && !h.current && f.current(g[0].pageNumber);
12
- let e = g[0]?.ratio, t = h.current;
13
- e && g.some((e) => e.pageNumber === t) && (clearTimeout(u.current), u.current = setTimeout(() => {
14
- h.current === t && (h.current = void 0);
15
- }, 500));
11
+ let e = h.current;
12
+ if (e) {
13
+ if (!g.some((t) => t.pageNumber === e)) return;
14
+ f.current(e), clearTimeout(u.current), u.current = setTimeout(() => {
15
+ h.current === e && (h.current = void 0);
16
+ }, 500);
17
+ return;
18
+ }
19
+ g.length > 0 && f.current(g[0].pageNumber);
16
20
  }, [g, h]), i(() => () => {
17
21
  clearTimeout(u.current), l.current && cancelAnimationFrame(l.current);
18
22
  }, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf-kit/viewer",
3
- "version": "2.9.1-rc.2",
3
+ "version": "2.9.2-rc.0",
4
4
  "private": false,
5
5
  "description": "A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.",
6
6
  "keywords": [
@@ -1,111 +0,0 @@
1
- import { useDocumentContext as e } from "./contexts/RPDocumentContext.js";
2
- import { useInitialStateContext as t } from "./contexts/InitialStateContext.js";
3
- import { useZoomContext as n } from "./contexts/ZoomContext.js";
4
- import { usePagesRotateContext as r } from "./contexts/PagesRotateContext.js";
5
- import { useRenderQueue as i } from "./contexts/RenderQueueProvider.js";
6
- import { useRenderedPagesCache as a } from "./contexts/RenderedPagesCache.js";
7
- import { useCallback as o, useEffect as s, useRef as c } from "react";
8
- import { jsx as l } from "react/jsx-runtime";
9
- import './assets/CanvasLayer.css';//#region lib/components/page/RPPage.module.css
10
- var u = {
11
- "rp-page-wrapper": "_rp-page-wrapper_1iuev_1",
12
- "rp-page": "_rp-page_1iuev_1",
13
- "rp-canvas-layer": "_rp-canvas-layer_1iuev_17",
14
- "rp-loader-wrapper": "_rp-loader-wrapper_1iuev_40"
15
- }, d = (d) => {
16
- let { pageNumber: f, onLoaded: p, onLoading: m } = d, h = c(null), g = c(null), _ = c(null), { pages: v } = e(), { pageRotate: y } = r(), { currentZoom: b, targetZoom: x, isZooming: S } = n(), { interactiveForm: C } = t(), { hasRenderedPage: w, markRenderedPage: T } = a(), E = i(), D = c(`page-${f}`), O = c(0), k = c(""), A = c(null), j = c(0), M = c(!1), N = o((e, t = !1) => {
17
- e && (e.width = 0, e.height = 0, t && e.parentNode && e.parentNode.removeChild(e));
18
- }, []), P = o((e = g.current) => {
19
- if (!e) return;
20
- let t = j.current, n = t ? (x || b || t || 1) / t : 1;
21
- e.style.setProperty("--rp-canvas-scale-ratio", String(n));
22
- }, [b, x]), F = o(() => {
23
- let e = document.createElement("canvas");
24
- return e.dataset.rp = `page-${f}-canvas`, e.style.opacity = "0", e.style.position = "absolute", e.style.inset = "0", P(e), e;
25
- }, [f, P]), I = o(() => {
26
- E.removeQueue(D.current), A.current &&= (A.current.cancel(), null);
27
- }, [E]), L = o(() => {
28
- _.current && !_.current.parentNode && (N(_.current), _.current = null);
29
- }, [N]), R = o((e) => {
30
- if (!M.current) return N(e), !1;
31
- let t = h.current;
32
- if (!t) return N(e), !1;
33
- let n = g.current;
34
- return n?.parentNode ? n.replaceWith(e) : t.appendChild(e), e.style.opacity = "1", g.current = e, N(n), !0;
35
- }, [N]);
36
- return s(() => (M.current = !0, () => {
37
- M.current = !1, I(), N(_.current), N(g.current), _.current = null, g.current = null;
38
- }), [I, N]), s(() => {
39
- P();
40
- }, [P]), s(() => {
41
- D.current = `page-${f}`, k.current = "", j.current = 0, N(_.current, !0), N(g.current, !0), _.current = null, g.current = null;
42
- }, [N, f]), s(() => {
43
- S && (I(), L());
44
- }, [
45
- I,
46
- L,
47
- S
48
- ]), s(() => {
49
- if (!v || b === 0 || S) return;
50
- let e = v.get(f), t = h.current;
51
- if (!e || !t) return;
52
- let n = y[f] ?? e.defaultRotation ?? 0, r = `${f}:${b}:${n}:${C ? "forms" : "static"}`;
53
- if (k.current === r) return;
54
- let i = g.current, a = !!i && i.width > 0 && i.height > 0, o = O.current + 1;
55
- O.current = o, I(), L(), m && !a && m({
56
- renderKey: r,
57
- hasRenderedBefore: w(r)
58
- });
59
- let s = F();
60
- return _.current = s, E.enqueue(D.current, {
61
- page: e.page,
62
- canvasElem: s,
63
- options: {
64
- scale: b,
65
- rotate: n,
66
- renderForms: !0,
67
- interactiveForm: C
68
- },
69
- onLoaded: () => {
70
- if (O.current !== o || _.current !== s) {
71
- N(s);
72
- return;
73
- }
74
- if (j.current = b, P(s), !R(s)) {
75
- _.current = null;
76
- return;
77
- }
78
- _.current = null, k.current = r, T(r), A.current = null, p?.();
79
- },
80
- onRenderTask: (e) => {
81
- O.current === o && (A.current = e);
82
- }
83
- }, 3), () => {
84
- I(), _.current === s && (N(s), _.current = null);
85
- };
86
- }, [
87
- I,
88
- N,
89
- L,
90
- F,
91
- b,
92
- w,
93
- C,
94
- S,
95
- T,
96
- p,
97
- m,
98
- f,
99
- y,
100
- v,
101
- E,
102
- R,
103
- P
104
- ]), /* @__PURE__ */ l("div", {
105
- className: u["rp-canvas-layer"],
106
- "data-rp": `page-${f}-canvasLayer`,
107
- ref: h
108
- });
109
- };
110
- //#endregion
111
- export { u as n, d as t };