@react-pdf-kit/viewer 0.0.0-experimental.0 → 0.0.0-experimental.1

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,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-23T11:18:40.284Z"), 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-24T03:31:41.685Z"), 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 g, useRef as k, useEffect as D, useCallback as P } from "react";
2
+ import { useDocumentContext as q } from "../../contexts/RPDocumentContext.js";
3
+ import { PixelsPerInch as O, AnnotationMode as U, RenderingCancelledException as V } from "pdfjs-dist";
4
4
  import "react/jsx-runtime";
5
5
  import "./useLoadPdf.js";
6
6
  import "../types.js";
@@ -13,49 +13,49 @@ 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: l, pages: f } = q(), [R, E] = g({
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] = g(!1), [A, b] = g(!1), [Z, C] = g(null), [M, h] = g(void 0), i = k(!1);
21
+ D(() => {
22
+ i.current;
23
+ }, [i]);
24
+ const S = P(() => {
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
+ }, []), s = P(() => {
29
+ i.current = !1, y(!1), b(!1), C(null), h(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
+ i.current = !0;
36
36
  }, I = async ({
37
37
  scratchCanvas: e,
38
38
  pdfDocument: n,
39
39
  pageNumber: t,
40
40
  viewerPdfPage: o,
41
41
  printResolution: r,
42
- optionalContentConfigPromise: i,
42
+ optionalContentConfigPromise: a,
43
43
  printAnnotationStoragePromise: u
44
44
  }) => {
45
- if (s.current) {
46
- a();
45
+ if (i.current) {
46
+ s();
47
47
  return;
48
48
  }
49
- const c = r / X.PDF;
49
+ const c = r / O.PDF;
50
50
  e.width = Math.floor(o.width * c), e.height = Math.floor(o.height * c);
51
51
  const p = e.getContext("2d");
52
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([
53
+ const [m, w] = await Promise.all([
54
54
  n.getPage(t),
55
55
  u
56
56
  ]);
57
- if (s.current) {
58
- a();
57
+ if (i.current) {
58
+ s();
59
59
  return;
60
60
  }
61
61
  const v = {
@@ -64,21 +64,21 @@ const re = () => {
64
64
  transform: [c, 0, 0, c, 0, 0],
65
65
  viewport: m.getViewport({ scale: 1, rotation: o.rotation }),
66
66
  intent: "print",
67
- annotationMode: q.ENABLE_STORAGE,
68
- optionalContentConfigPromise: i,
69
- printAnnotationStorage: h
67
+ annotationMode: U.ENABLE_STORAGE,
68
+ optionalContentConfigPromise: a,
69
+ printAnnotationStorage: w
70
70
  };
71
71
  try {
72
72
  return m.render(v).promise;
73
73
  } catch (d) {
74
- throw d instanceof B || console.error(d), d;
74
+ throw d instanceof V || console.error(d), d;
75
75
  }
76
- }, S = P(() => {
76
+ }, L = P(() => {
77
77
  const e = window.print;
78
78
  return new Promise((n) => {
79
- const t = (i) => {
79
+ const t = (a) => {
80
80
  setTimeout(() => {
81
- e.call(window), setTimeout(() => i(), 20);
81
+ e.call(window), setTimeout(() => a(), 20);
82
82
  }, 0);
83
83
  };
84
84
  if (document.querySelector(".rp-print-zone")) {
@@ -90,94 +90,87 @@ const re = () => {
90
90
  });
91
91
  r.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
99
  const o = document.createElement("style"), r = n.get(1);
107
100
  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 }`;
101
+ const { width: a, height: u } = r == null ? void 0 : r.page.getViewport({ scale: 1 });
102
+ o.innerHTML = `@page { size: ${a}px ${u}px }`;
110
103
  }
111
104
  return t.appendChild(o), t.append(...e), t;
112
- }, k = P(
105
+ }, N = P(
113
106
  async (e) => {
114
107
  if (!l)
115
108
  return;
116
- a();
109
+ s();
117
110
  const n = e && "visibleDefaultProgress" in e ? e : void 0;
118
- (n == null ? void 0 : n.visibleDefaultProgress) !== void 0 ? w(n.visibleDefaultProgress) : w(!0);
111
+ (n == null ? void 0 : n.visibleDefaultProgress) !== void 0 ? h(n.visibleDefaultProgress) : h(!0);
119
112
  const t = document.createElement("canvas"), o = [];
120
113
  try {
121
114
  l.isPureXfa && console.warn("[rp] XFA Form is not supported at the moment.");
122
- const i = l.getOptionalContentConfig({ intent: "print" }), u = Promise.resolve(
115
+ const a = l.getOptionalContentConfig({ intent: "print" }), u = Promise.resolve(
123
116
  l.annotationStorage.print ?? void 0
124
117
  ), c = f.size;
125
- for (const [m, h] of f) {
126
- if (s.current) {
127
- a();
118
+ for (const [m, w] of f) {
119
+ if (i.current) {
120
+ s();
128
121
  return;
129
122
  }
130
- const v = h.page.getViewport({ scale: 1 });
123
+ const v = w.page.getViewport({ scale: 1 });
131
124
  if (await I({
132
125
  scratchCanvas: t,
133
126
  pdfDocument: l,
134
127
  pageNumber: m,
135
128
  viewerPdfPage: v,
136
129
  printResolution: 150,
137
- optionalContentConfigPromise: i,
130
+ optionalContentConfigPromise: a,
138
131
  printAnnotationStoragePromise: u
139
- }), s.current) {
140
- a();
132
+ }), i.current) {
133
+ s();
141
134
  return;
142
135
  }
143
- const d = await U(t);
136
+ const d = z(t);
144
137
  o.push(d);
145
- const z = parseFloat((o.length / c * 100).toFixed(2));
138
+ const X = parseFloat((o.length / c * 100).toFixed(2));
146
139
  E({
147
140
  loadedPages: m,
148
141
  totalPages: c,
149
- percentage: z
142
+ percentage: X
150
143
  });
151
144
  }
152
- if (s.current) {
153
- a();
145
+ if (i.current) {
146
+ s();
154
147
  return;
155
148
  }
156
149
  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();
150
+ document.body.appendChild(p), document.documentElement.classList.add("rp-print-html-printing"), document.body.classList.add("rp-print-body-printing"), y(!0), await L();
158
151
  } catch (r) {
159
- y(!0), r instanceof Error && L(r);
152
+ b(!0), r instanceof Error && C(r);
160
153
  } finally {
161
154
  t.height = 0, t.width = 0;
162
155
  }
163
156
  },
164
- [l, f, s, a, x, S]
157
+ [l, f, i, s, x, L]
165
158
  );
166
- return R(() => {
159
+ return D(() => {
167
160
  const e = () => {
168
- a(), C();
161
+ s(), S();
169
162
  };
170
163
  return window.addEventListener("afterprint", e, !0), () => {
171
164
  window.removeEventListener("afterprint", e, !0);
172
165
  };
173
- }, [C, a]), {
174
- print: k,
175
- cancel: M,
176
- progress: D,
166
+ }, [S, s]), {
167
+ print: N,
168
+ cancel: F,
169
+ progress: R,
177
170
  isComplete: T,
178
171
  isError: A,
179
172
  error: Z,
180
- showDefaultProgress: F
173
+ showDefaultProgress: M
181
174
  };
182
175
  };
183
176
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf-kit/viewer",
3
- "version": "0.0.0-experimental.0",
3
+ "version": "0.0.0-experimental.1",
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": [