@react-pdf-kit/viewer 2.0.0 → 2.0.1-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.
Files changed (48) hide show
  1. package/dist/{Combination-136ff99c.js → Combination-54a77a7a.js} +187 -184
  2. package/dist/components/layout/RPDefaultLayout.js +2 -2
  3. package/dist/components/layout/RPLayout.js +2 -2
  4. package/dist/components/layout/toolbar/DocumentDialog.js +1 -1
  5. package/dist/components/layout/toolbar/DocumentProperties.js +2 -2
  6. package/dist/components/layout/toolbar/FileDownloadTool.js +2 -2
  7. package/dist/components/layout/toolbar/FileUploadTool.js +2 -2
  8. package/dist/components/layout/toolbar/FullScreenTool.js +2 -2
  9. package/dist/components/layout/toolbar/MenuItem.js +2 -2
  10. package/dist/components/layout/toolbar/MenuSeparator.js +2 -2
  11. package/dist/components/layout/toolbar/MostPageTool.js +2 -2
  12. package/dist/components/layout/toolbar/OtherTool.js +2 -2
  13. package/dist/components/layout/toolbar/PrintTool.js +2 -2
  14. package/dist/components/layout/toolbar/RPMenuItem.js +2 -2
  15. package/dist/components/layout/toolbar/RPMoreOptions.js +2 -2
  16. package/dist/components/layout/toolbar/RPToolbar.js +2 -2
  17. package/dist/components/layout/toolbar/RPToolbarEnd.js +2 -2
  18. package/dist/components/layout/toolbar/RotateTool.js +2 -2
  19. package/dist/components/layout/toolbar/ScrollModeTool.js +2 -2
  20. package/dist/components/layout/toolbar/SearchTool.js +2 -2
  21. package/dist/components/layout/toolbar/SelectionModeTool.js +2 -2
  22. package/dist/components/layout/toolbar/ToolbarDefault.js +2 -2
  23. package/dist/components/layout/toolbar/ToolbarLayout.js +2 -2
  24. package/dist/components/layout/toolbar/ViewModeTool.js +2 -2
  25. package/dist/components/layout/toolbar/ZoomTool.js +2 -2
  26. package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +1 -1
  27. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +2 -2
  28. package/dist/components/layout/toolbar/tools/FirstPageTool.js +2 -2
  29. package/dist/components/layout/toolbar/tools/LastPageTool.js +2 -2
  30. package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +2 -2
  31. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +2 -2
  32. package/dist/components/layout/toolbar/tools/more-options/DocumentProperties.js +2 -2
  33. package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +2 -2
  34. package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +2 -2
  35. package/dist/components/layout/toolbar/tools/more-options/FullScreenTool.js +2 -2
  36. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +2 -2
  37. package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +2 -2
  38. package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +2 -2
  39. package/dist/components/layout/toolbar/tools/more-options/ScrollModeTool.js +2 -2
  40. package/dist/components/layout/toolbar/tools/more-options/SelectionModeTool.js +2 -2
  41. package/dist/components/layout/toolbar/tools/more-options/ViewModeTool.js +2 -2
  42. package/dist/components/ui/DropDown.js +2 -2
  43. package/dist/{index-61f59539.js → index-4baea9b5.js} +1 -1
  44. package/dist/main.js +2 -2
  45. package/dist/utils/hooks/useLicense.js +1 -1
  46. package/dist/utils/hooks/usePrint.js +82 -93
  47. package/dist/utils/injectPrintCSS.js +1 -2
  48. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { jsx as r, Fragment as g, jsxs as e } from "react/jsx-runtime";
2
2
  import { useMemo as L } from "react";
3
3
  import m from "../../../../ui/RPTooltip.js";
4
- import { G } from "../../../../../index-61f59539.js";
4
+ import { G } from "../../../../../index-4baea9b5.js";
5
5
  import { MenuSeparator as T } from "../../MenuSeparator.js";
6
6
  import { MenuItem as n } from "../../MenuItem.js";
7
7
  import { DualPageIcon as b } from "../../../../icons/DualPageIcon.js";
@@ -18,7 +18,7 @@ import "../../../../../index-e3ee9457.js";
18
18
  import "../../../../../floating-ui.react-dom-5ec29bd6.js";
19
19
  import "../../../../../index-655864a7.js";
20
20
  import "../../../../../utils/withRef.js";
21
- import "../../../../../Combination-136ff99c.js";
21
+ import "../../../../../Combination-54a77a7a.js";
22
22
  import "../../../../../clsx-0c6e471a.js";
23
23
  import "../../../../../utils/appConsole.js";
24
24
  import "../../../../../contexts/InitialStateContext.js";
@@ -1,11 +1,11 @@
1
1
  import { jsxs as p, jsx as d } from "react/jsx-runtime";
2
- import { R as l, T as c, P as _, C as m } from "../../index-61f59539.js";
2
+ import { R as l, T as c, P as _, C as m } from "../../index-4baea9b5.js";
3
3
  import { c as A } from "../../clsx-0c6e471a.js";
4
4
  import "react";
5
5
  import "../../index-c0faa594.js";
6
6
  import "react-dom";
7
7
  import "../../index-e3ee9457.js";
8
- import "../../Combination-136ff99c.js";
8
+ import "../../Combination-54a77a7a.js";
9
9
  import "../../floating-ui.react-dom-5ec29bd6.js";
10
10
  import "../../index-655864a7.js";
11
11
  const F = "_slideDownAndFade_1vzkq_1", w = "_slideLeftAndFade_1vzkq_1", f = "_slideUpAndFade_1vzkq_1", g = "_slideRightAndFade_1vzkq_1", h = {
@@ -3,7 +3,7 @@ import X from "react";
3
3
  import { c as ce, a as G, g as Ce, P as F, u as ke, f as Ge, b as M, d as me, j as Ke, h as Bt } from "./index-c0faa594.js";
4
4
  import { jsx as s } from "react/jsx-runtime";
5
5
  import { a as ve, u as _e, D as Yt } from "./index-e3ee9457.js";
6
- import { h as Ht, u as Vt, F as Xt, R as Wt, P as jt } from "./Combination-136ff99c.js";
6
+ import { h as Ht, u as Vt, F as Xt, R as Wt, P as jt } from "./Combination-54a77a7a.js";
7
7
  import { u as zt, a as Zt, o as qt, s as Jt, l as Qt, f as eo, b as to, c as oo, h as no } from "./floating-ui.react-dom-5ec29bd6.js";
8
8
  import { u as ro } from "./index-655864a7.js";
9
9
  function $e(e) {
package/dist/main.js CHANGED
@@ -144,8 +144,8 @@ import "./components/layout/toolbar/RPToolbarEnd.js";
144
144
  import "./components/layout/toolbar/FileUploadTool.js";
145
145
  import "./components/icons/FileUploadDefaultIcon.js";
146
146
  import "./components/layout/toolbar/MenuItem.js";
147
- import "./index-61f59539.js";
148
- import "./Combination-136ff99c.js";
147
+ import "./index-4baea9b5.js";
148
+ import "./Combination-54a77a7a.js";
149
149
  import "./components/layout/toolbar/DarkModeTool.js";
150
150
  import "./components/icons/MoonIcon.js";
151
151
  import "./components/icons/SunIcon.js";
@@ -1,6 +1,6 @@
1
1
  import { useState as E, useCallback as h, useEffect as A } from "react";
2
2
  import { appConsole as l } from "../appConsole.js";
3
- const b = /* @__PURE__ */ new Date("2026-02-20T05:08:30.511Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", s = {
3
+ const b = /* @__PURE__ */ new Date("2026-02-24T04:09:54.598Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", s = {
4
4
  invalidLicense: `You are currently using without a valid license. ${d}`,
5
5
  mismatchedDomain: `Your license key is not valid for the current domain / IP. ${d}`,
6
6
  expired: `Your license key has expired. ${d}`,
@@ -1,6 +1,6 @@
1
- import { useState as g, useRef as N, useEffect as R, useCallback as P } from "react";
2
- import { useDocumentContext as O } from "../../contexts/RPDocumentContext.js";
3
- import { PixelsPerInch as X, AnnotationMode as q, RenderingCancelledException as B } from "pdfjs-dist";
1
+ import { useState as m, useRef as X, useEffect as D, useCallback as g } from "react";
2
+ import { useDocumentContext as k } from "../../contexts/RPDocumentContext.js";
3
+ import { PixelsPerInch as q, AnnotationMode as O, RenderingCancelledException as U } from "pdfjs-dist";
4
4
  import "react/jsx-runtime";
5
5
  import "./useLoadPdf.js";
6
6
  import "../types.js";
@@ -13,171 +13,160 @@ import "./usePdfProperties.js";
13
13
  import "../convertPdfDate.js";
14
14
  import "../formatFileSize.js";
15
15
  const re = () => {
16
- const { pdf: l, pages: f } = O(), [D, E] = g({
16
+ const { pdf: p, pages: f } = k(), [R, E] = m({
17
17
  loadedPages: 0,
18
18
  totalPages: 0,
19
19
  percentage: 0
20
- }), [T, b] = g(!1), [A, y] = g(!1), [Z, L] = g(null), [F, w] = g(void 0), s = N(!1);
21
- R(() => {
22
- s.current;
23
- }, [s]);
24
- const C = P(() => {
20
+ }), [T, y] = m(!1), [A, b] = m(!1), [Z, C] = m(null), [M, P] = m(void 0), o = X(!1);
21
+ D(() => {
22
+ o.current;
23
+ }, [o]);
24
+ const S = g(() => {
25
25
  document.documentElement.classList.remove("rp-print-html-printing"), document.body.classList.remove("rp-print-body-printing");
26
26
  const e = document.querySelector(".rp-print-zone");
27
27
  e && e.remove();
28
- }, []), a = P(() => {
29
- s.current = !1, b(!1), y(!1), L(null), w(void 0), E({
28
+ }, []), i = g(() => {
29
+ o.current = !1, y(!1), b(!1), C(null), P(void 0), E({
30
30
  loadedPages: 0,
31
31
  totalPages: 0,
32
32
  percentage: 0
33
33
  });
34
- }, []), M = () => {
35
- s.current = !0;
34
+ }, []), F = () => {
35
+ o.current = !0;
36
36
  }, I = async ({
37
37
  scratchCanvas: e,
38
38
  pdfDocument: n,
39
39
  pageNumber: t,
40
- viewerPdfPage: o,
41
- printResolution: r,
42
- optionalContentConfigPromise: i,
43
- printAnnotationStoragePromise: u
40
+ viewerPdfPage: r,
41
+ printResolution: s,
42
+ optionalContentConfigPromise: l,
43
+ printAnnotationStoragePromise: w
44
44
  }) => {
45
- if (s.current) {
46
- a();
45
+ if (o.current) {
46
+ i();
47
47
  return;
48
48
  }
49
- const c = r / X.PDF;
50
- e.width = Math.floor(o.width * c), e.height = Math.floor(o.height * c);
51
- const p = e.getContext("2d");
52
- p.save(), p.fillStyle = "rgb(255, 255, 255)", p.fillRect(0, 0, e.width, e.height), p.restore();
53
- const [m, h] = await Promise.all([
49
+ const a = s / q.PDF;
50
+ e.width = Math.floor(r.width * a), e.height = Math.floor(r.height * a);
51
+ const c = e.getContext("2d");
52
+ c.save(), c.fillStyle = "rgb(255, 255, 255)", c.fillRect(0, 0, e.width, e.height), c.restore();
53
+ const [u, h] = await Promise.all([
54
54
  n.getPage(t),
55
- u
55
+ w
56
56
  ]);
57
- if (s.current) {
58
- a();
57
+ if (o.current) {
58
+ i();
59
59
  return;
60
60
  }
61
61
  const v = {
62
62
  canvas: e,
63
- canvasContext: p,
64
- transform: [c, 0, 0, c, 0, 0],
65
- viewport: m.getViewport({ scale: 1, rotation: o.rotation }),
63
+ canvasContext: c,
64
+ transform: [a, 0, 0, a, 0, 0],
65
+ viewport: u.getViewport({ scale: 1, rotation: r.rotation }),
66
66
  intent: "print",
67
- annotationMode: q.ENABLE_STORAGE,
68
- optionalContentConfigPromise: i,
67
+ annotationMode: O.ENABLE_STORAGE,
68
+ optionalContentConfigPromise: l,
69
69
  printAnnotationStorage: h
70
70
  };
71
71
  try {
72
- return m.render(v).promise;
72
+ return u.render(v).promise;
73
73
  } catch (d) {
74
- throw d instanceof B || console.error(d), d;
74
+ throw d instanceof U || console.error(d), d;
75
75
  }
76
- }, S = P(() => {
76
+ }, L = g(() => {
77
77
  const e = window.print;
78
78
  return new Promise((n) => {
79
- const t = (i) => {
79
+ const t = (l) => {
80
80
  setTimeout(() => {
81
- e.call(window), setTimeout(() => i(), 20);
81
+ e.call(window), setTimeout(() => l(), 20);
82
82
  }, 0);
83
83
  };
84
84
  if (document.querySelector(".rp-print-zone")) {
85
85
  t(n);
86
86
  return;
87
87
  }
88
- const r = new MutationObserver(() => {
89
- document.querySelector(".rp-print-zone") && (t(n), r.disconnect());
88
+ const s = new MutationObserver(() => {
89
+ document.querySelector(".rp-print-zone") && (t(n), s.disconnect());
90
90
  });
91
- r.observe(document.body, { childList: !0, subtree: !0 });
91
+ s.observe(document.body, { childList: !0, subtree: !0 });
92
92
  });
93
- }, []), U = async (e) => {
93
+ }, []), z = (e) => {
94
94
  const n = document.createElement("img"), t = document.createElement("div");
95
- return t.classList.add("rp-print-page"), await new Promise((o, r) => {
96
- e.toBlob((i) => {
97
- i ? (n.src = URL.createObjectURL(i), n.onload = () => {
98
- URL.revokeObjectURL(n.src), o();
99
- }, n.onerror = r) : r(new Error("Failed to create blob"));
100
- });
101
- }).catch(() => {
102
- }), t.appendChild(n), t;
95
+ return t.classList.add("rp-print-page"), n.src = e.toDataURL(), t.appendChild(n), t;
103
96
  }, x = (e, n) => {
104
97
  const t = document.createElement("div");
105
98
  t.classList.add("rp-print-zone");
106
- const o = document.createElement("style"), r = n.get(1);
107
- if (r) {
108
- const { width: i, height: u } = r == null ? void 0 : r.page.getViewport({ scale: 1 });
109
- o.innerHTML = `@page { size: ${i}px ${u}px }`;
110
- }
111
- return t.appendChild(o), t.append(...e), t;
112
- }, k = P(
99
+ const r = document.createElement("style");
100
+ return n.get(1) && (r.innerHTML = "@page { size: 100% 100%; margin: 0; }"), t.appendChild(r), t.append(...e), t;
101
+ }, N = g(
113
102
  async (e) => {
114
- if (!l)
103
+ if (!p)
115
104
  return;
116
- a();
105
+ i();
117
106
  const n = e && "visibleDefaultProgress" in e ? e : void 0;
118
- (n == null ? void 0 : n.visibleDefaultProgress) !== void 0 ? w(n.visibleDefaultProgress) : w(!0);
119
- const t = document.createElement("canvas"), o = [];
107
+ (n == null ? void 0 : n.visibleDefaultProgress) !== void 0 ? P(n.visibleDefaultProgress) : P(!0);
108
+ const t = document.createElement("canvas"), r = [];
120
109
  try {
121
- l.isPureXfa && console.warn("[rp] XFA Form is not supported at the moment.");
122
- const i = l.getOptionalContentConfig({ intent: "print" }), u = Promise.resolve(
123
- l.annotationStorage.print ?? void 0
124
- ), c = f.size;
125
- for (const [m, h] of f) {
126
- if (s.current) {
127
- a();
110
+ p.isPureXfa && console.warn("[rp] XFA Form is not supported at the moment.");
111
+ const l = p.getOptionalContentConfig({ intent: "print" }), w = Promise.resolve(
112
+ p.annotationStorage.print ?? void 0
113
+ ), a = f.size;
114
+ for (const [u, h] of f) {
115
+ if (o.current) {
116
+ i();
128
117
  return;
129
118
  }
130
119
  const v = h.page.getViewport({ scale: 1 });
131
120
  if (await I({
132
121
  scratchCanvas: t,
133
- pdfDocument: l,
134
- pageNumber: m,
122
+ pdfDocument: p,
123
+ pageNumber: u,
135
124
  viewerPdfPage: v,
136
125
  printResolution: 150,
137
- optionalContentConfigPromise: i,
138
- printAnnotationStoragePromise: u
139
- }), s.current) {
140
- a();
126
+ optionalContentConfigPromise: l,
127
+ printAnnotationStoragePromise: w
128
+ }), o.current) {
129
+ i();
141
130
  return;
142
131
  }
143
- const d = await U(t);
144
- o.push(d);
145
- const z = parseFloat((o.length / c * 100).toFixed(2));
132
+ const d = z(t);
133
+ r.push(d);
134
+ const V = parseFloat((r.length / a * 100).toFixed(2));
146
135
  E({
147
- loadedPages: m,
148
- totalPages: c,
149
- percentage: z
136
+ loadedPages: u,
137
+ totalPages: a,
138
+ percentage: V
150
139
  });
151
140
  }
152
- if (s.current) {
153
- a();
141
+ if (o.current) {
142
+ i();
154
143
  return;
155
144
  }
156
- const p = x(o, f);
157
- document.body.appendChild(p), document.documentElement.classList.add("rp-print-html-printing"), document.body.classList.add("rp-print-body-printing"), b(!0), await S();
158
- } catch (r) {
159
- y(!0), r instanceof Error && L(r);
145
+ const c = x(r, f);
146
+ document.body.appendChild(c), document.documentElement.classList.add("rp-print-html-printing"), document.body.classList.add("rp-print-body-printing"), y(!0), await L();
147
+ } catch (s) {
148
+ b(!0), s instanceof Error && C(s);
160
149
  } finally {
161
150
  t.height = 0, t.width = 0;
162
151
  }
163
152
  },
164
- [l, f, s, a, x, S]
153
+ [p, f, o, i, x, L]
165
154
  );
166
- return R(() => {
155
+ return D(() => {
167
156
  const e = () => {
168
- a(), C();
157
+ i(), S();
169
158
  };
170
159
  return window.addEventListener("afterprint", e, !0), () => {
171
160
  window.removeEventListener("afterprint", e, !0);
172
161
  };
173
- }, [C, a]), {
174
- print: k,
175
- cancel: M,
176
- progress: D,
162
+ }, [S, i]), {
163
+ print: N,
164
+ cancel: F,
165
+ progress: R,
177
166
  isComplete: T,
178
167
  isError: A,
179
168
  error: Z,
180
- showDefaultProgress: F
169
+ showDefaultProgress: M
181
170
  };
182
171
  };
183
172
  export {
@@ -6,14 +6,13 @@ function e() {
6
6
  .rp-print-zone { display: none; }
7
7
 
8
8
  @media print {
9
- @page { margin: 0; }
10
9
  .rp-print-html-printing { height: 100%; }
11
10
  .rp-print-body-printing { background: transparent; height: 100%; margin: 0; display: block; }
12
11
  .rp-print-body-printing * { display: none; }
13
12
  .rp-print-zone { display: block; height: 100%; }
14
13
  .rp-print-page { display: flex; align-items: center; flex-direction: column; justify-content: center; height: 100%; width: 100%; page-break-after: always; page-break-inside: avoid; }
15
14
  .rp-print-page:last-child { page-break-after: auto; }
16
- .rp-print-page img, .rp-print-page canvas { display: block; max-height: 100%; max-width: 100%; direction: ltr; }
15
+ .rp-print-page img, .rp-print-page canvas { display: block; height: 100%; width: 100%; direction: ltr; }
17
16
  }
18
17
  `, document.head.appendChild(t);
19
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf-kit/viewer",
3
- "version": "2.0.0",
3
+ "version": "2.0.1-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": [