@react-pdf-kit/viewer 2.6.0-beta.0 → 2.6.0-beta.2

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,8 +1,8 @@
1
1
  import { jsx as o, jsxs as t } from "react/jsx-runtime";
2
- import { useState as u } from "react";
2
+ import { useState as _ } from "react";
3
3
  import { c as a } from "../../clsx-0c6e471a.js";
4
- import { useLocalizationContext as _ } from "../../contexts/LocalizationContext.js";
5
- import { useDocumentPasswordContext as c } from "../../contexts/DocumentPasswordContext.js";
4
+ import { useLocalizationContext as c } from "../../contexts/LocalizationContext.js";
5
+ import { useDocumentPasswordContext as v } from "../../contexts/DocumentPasswordContext.js";
6
6
  import "../../utils/appConsole.js";
7
7
  import "../../utils/hooks/useLocalization.js";
8
8
  import "../../de_DE-8145915f.js";
@@ -16,12 +16,12 @@ const s = {
16
16
  "rp-password-input-invalid": "_rp-password-input-invalid_18s56_62",
17
17
  "rp-password-message-invalid": "_rp-password-message-invalid_18s56_66",
18
18
  "rp-password-submit-button": "_rp-password-submit-button_18s56_72"
19
- }, x = () => {
20
- const [d, e] = u(""), { localeMessages: r } = _(), { setPassword: l, invalidPassword: p } = c(), m = (i) => {
21
- e(i.target.value);
19
+ }, S = () => {
20
+ const [d, e] = _(""), { localeMessages: r } = c(), { setPassword: l, setPasswordError: m, invalidPassword: p } = v(), w = (i) => {
21
+ e(i.target.value), p && m(void 0);
22
22
  }, n = (i) => {
23
23
  i.preventDefault(), d && d.trim() && l(d);
24
- }, w = !d.trim();
24
+ }, u = !d.trim();
25
25
  return /* @__PURE__ */ o("div", { className: a(s["rp-password-overlay"]), role: "dialog", "aria-modal": "true", "aria-labelledby": "password-modal-title", children: /* @__PURE__ */ t("div", { className: a(s["rp-password-modal"]), children: [
26
26
  /* @__PURE__ */ o("div", { id: "password-modal-title", className: a(s["rp-password-title"]), children: r == null ? void 0 : r.passwordModalTitle }),
27
27
  /* @__PURE__ */ o("div", { className: a(s["rp-password-content"]), children: r == null ? void 0 : r.passwordModalMessage }),
@@ -32,7 +32,7 @@ const s = {
32
32
  {
33
33
  type: "password",
34
34
  value: d,
35
- onChange: m,
35
+ onChange: w,
36
36
  className: a(
37
37
  s["rp-password-input"],
38
38
  p && s["rp-password-input-invalid"]
@@ -60,7 +60,7 @@ const s = {
60
60
  "button",
61
61
  {
62
62
  type: "submit",
63
- disabled: w,
63
+ disabled: u,
64
64
  className: a(s["rp-password-submit-button"]),
65
65
  onClick: n,
66
66
  "aria-label": r == null ? void 0 : r.passwordConfirmLabel,
@@ -71,5 +71,5 @@ const s = {
71
71
  ] }) });
72
72
  };
73
73
  export {
74
- x as default
74
+ S as default
75
75
  };
@@ -1,7 +1,7 @@
1
- import { jsx as P } from "react/jsx-runtime";
2
- import { createContext as l, useState as r, useEffect as p, useMemo as m, useContext as f } from "react";
3
- import { appConsole as v } from "../utils/appConsole.js";
4
- const a = l({
1
+ import { jsx as w } from "react/jsx-runtime";
2
+ import { createContext as P, useState as r, useMemo as p, useContext as m } from "react";
3
+ import { appConsole as l } from "../utils/appConsole.js";
4
+ const n = P({
5
5
  password: void 0,
6
6
  setPassword: () => {
7
7
  },
@@ -12,29 +12,25 @@ const a = l({
12
12
  setPasswordRequired: () => {
13
13
  },
14
14
  invalidPassword: !1
15
- }), q = ({
15
+ }), C = ({
16
16
  children: s
17
17
  }) => {
18
- const [e, n] = r(), [o, i] = r(), [t, c] = r(!1), [d, w] = r(!1);
19
- p(() => {
20
- w(o === "Incorrect Password");
21
- }, [o]);
22
- const u = m(() => ({
18
+ const [e, a] = r(), [o, i] = r(), [t, c] = r(!1), d = !!o, u = p(() => ({
23
19
  password: e,
24
- setPassword: n,
20
+ setPassword: a,
25
21
  passwordError: o,
26
22
  setPasswordError: i,
27
23
  passwordRequired: t,
28
24
  setPasswordRequired: c,
29
25
  invalidPassword: d
30
26
  }), [e, o, t, d]);
31
- return /* @__PURE__ */ P(a.Provider, { value: u, children: s });
32
- }, D = () => {
33
- const s = f(a);
34
- return s || v.error("Please use this hooks inside children component of DocumentPasswordContext"), s;
27
+ return /* @__PURE__ */ w(n.Provider, { value: u, children: s });
28
+ }, h = () => {
29
+ const s = m(n);
30
+ return s || l.error("Please use this hooks inside children component of DocumentPasswordContext"), s;
35
31
  };
36
32
  export {
37
- q as DocumentPasswordProvider,
38
- a as default,
39
- D as useDocumentPasswordContext
33
+ C as DocumentPasswordProvider,
34
+ n as default,
35
+ h as useDocumentPasswordContext
40
36
  };
@@ -2,7 +2,7 @@ import { useState as E, useCallback as y, useEffect as b } from "react";
2
2
  import { LicenseType as L } from "../types.js";
3
3
  import { appConsole as c } from "../appConsole.js";
4
4
  import "../../de_DE-8145915f.js";
5
- const A = /* @__PURE__ */ new Date("2026-05-07T03:30:28.270Z"), v = `-----BEGIN PUBLIC KEY-----
5
+ const A = /* @__PURE__ */ new Date("2026-05-11T06:37:10.798Z"), v = `-----BEGIN PUBLIC KEY-----
6
6
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIokvErJ0Fctu0jduSAx
7
7
  gr+5Har/VSuZLlOunS28hnlqqA+OF1apHL7RYkjBosS15yvviYdLrVWYHpHnoY4b
8
8
  HLQ9I6YX6FMB9T/VbB4xLdVdKvfi8r49aTScl5EKuSpgpPgz2VSJTfvVGcRuth/Y
@@ -1,52 +1,56 @@
1
- import { useState as a, useRef as j, useEffect as T } from "react";
2
- import * as x from "pdfjs-dist";
3
- import { ErrorType as C } from "../types.js";
4
- import { getThumbnailViewport as z } from "../getThumbnailViewport.js";
5
- import { useConfigContext as H } from "../../contexts/ConfigContext.js";
6
- import { useDocumentPasswordContext as W } from "../../contexts/DocumentPasswordContext.js";
1
+ import { useState as u, useRef as W, useEffect as C } from "react";
2
+ import * as T from "pdfjs-dist";
3
+ import { ErrorType as b } from "../types.js";
4
+ import { getThumbnailViewport as j } from "../getThumbnailViewport.js";
5
+ import { useConfigContext as z } from "../../contexts/ConfigContext.js";
6
+ import { useDocumentPasswordContext as H } from "../../contexts/DocumentPasswordContext.js";
7
7
  import { INVALID_OR_CORRUPTED_PDF_MESSAGE as J, BROWSER_NOT_SUPPORTED_MESSAGE as K } from "../const.js";
8
8
  import "../../de_DE-8145915f.js";
9
9
  import "react/jsx-runtime";
10
10
  import "../appConsole.js";
11
11
  function F(n) {
12
- const t = new Error(J);
13
- return t.cause = n, t;
12
+ const o = new Error(J);
13
+ return o.cause = n, o;
14
14
  }
15
15
  function Q(n) {
16
- const t = new Error(K);
17
- return t.cause = n, t;
16
+ const o = new Error(K);
17
+ return o.cause = n, o;
18
18
  }
19
- const re = (n, t, L = {}) => {
20
- const [d, c] = a(), { workerUrlAdded: b, wasmUrl: P } = H(), [q, N] = a(/* @__PURE__ */ new Map()), u = j(), [p, g] = a(0), [w, U] = a(!1), [B, l] = a(), { password: f, passwordError: G, setPasswordError: E, passwordRequired: R, setPasswordRequired: D } = W(), { onLoadError: o, onLoaded: _, onLoadProgress: v, disableAutoFetch: V, disableStream: y, rangeChunkSize: A, withCredentials: h, httpHeaders: k } = L;
21
- return T(() => {
22
- v && v(p);
23
- }, [p, v]), T(() => {
24
- if (!b || !n)
19
+ const re = (n, o, L = {}) => {
20
+ const [d, p] = u(), { workerUrlAdded: N, wasmUrl: g } = z(), [q, A] = u(/* @__PURE__ */ new Map()), l = W(), [w, R] = u(0), [E, U] = u(!1), [B, c] = u(), { password: f, passwordError: G, setPasswordError: m, passwordRequired: D, setPasswordRequired: O } = H(), { onLoadError: t, onLoaded: S, onLoadProgress: _, disableAutoFetch: V, disableStream: x, rangeChunkSize: y, withCredentials: h, httpHeaders: k } = L;
21
+ return C(() => {
22
+ _ && _(w);
23
+ }, [w, _]), C(() => {
24
+ if (!N || !n)
25
25
  return;
26
- g(0), l(void 0), u.current = Date.now();
27
- const i = u.current, O = {
26
+ R(0), c(void 0), l.current = Date.now();
27
+ const i = l.current, v = {
28
28
  url: n,
29
- cMapPacked: (t == null ? void 0 : t.isCompressed) ?? !0,
30
- ...(t == null ? void 0 : t.url) && { cMapUrl: t.url },
29
+ cMapPacked: (o == null ? void 0 : o.isCompressed) ?? !0,
30
+ ...(o == null ? void 0 : o.url) && { cMapUrl: o.url },
31
31
  ...f && { password: f },
32
32
  ...V !== void 0 && { disableAutoFetch: V },
33
- ...y !== void 0 && { disableStream: y },
34
- ...A !== void 0 && { rangeChunkSize: A },
33
+ ...x !== void 0 && { disableStream: x },
34
+ ...y !== void 0 && { rangeChunkSize: y },
35
35
  ...h !== void 0 && { withCredentials: h },
36
36
  ...k !== void 0 && { httpHeaders: k },
37
- ...P && { wasmUrl: P },
38
- verbosity: x.VerbosityLevel.ERRORS
37
+ ...g && { wasmUrl: g },
38
+ verbosity: T.VerbosityLevel.ERRORS
39
39
  };
40
40
  try {
41
- const r = x.getDocument(O);
41
+ const r = T.getDocument(v);
42
42
  r.onProgress = (e) => {
43
- if (i === u.current) {
44
- const { loaded: S, total: m } = e, I = m ? Math.min(100, Math.round(S / m * 100)) : 0;
45
- g(I);
43
+ if (i === l.current) {
44
+ const { loaded: a, total: P } = e, I = P ? Math.min(100, Math.round(a / P * 100)) : 0;
45
+ R(I);
46
46
  }
47
- }, U(!0), c(void 0);
48
- const s = r.promise.then((e) => (i === u.current && (c(e), g(100)), _ && _(e), D(!1), E(""), e)).catch((e) => {
49
- e instanceof Error && e.name === "PasswordException" ? (D(!0), E(e.message || "Password required")) : e instanceof Error && e.name === "InvalidPDFException" && f ? (D(!0), E("Incorrect password")) : e instanceof Error && e.name === "InvalidPDFException" ? (l(C.INVALID_OR_CORRUPTED_PDF), o == null || o(F(e))) : o && o(e);
47
+ }, U(!0), p(void 0);
48
+ const s = r.promise.then((e) => (i === l.current && (p(e), R(100)), S && S(e), O(!1), m(""), e)).catch((e) => {
49
+ if (e instanceof Error && e.name === "PasswordException") {
50
+ const a = e.code;
51
+ O(!0), a === T.PasswordResponses.INCORRECT_PASSWORD ? m("Incorrect password") : m(void 0);
52
+ } else
53
+ e instanceof Error && e.name === "InvalidPDFException" && f ? (O(!0), m("Incorrect password")) : e instanceof Error && e.name === "InvalidPDFException" ? (c(b.INVALID_OR_CORRUPTED_PDF), t == null || t(F(e))) : t && t(e);
50
54
  }).finally(() => {
51
55
  U(!1);
52
56
  });
@@ -56,41 +60,41 @@ const re = (n, t, L = {}) => {
56
60
  });
57
61
  };
58
62
  } catch (r) {
59
- l(C.NOT_SUPPORTED), o == null || o(Q(r));
63
+ c(b.NOT_SUPPORTED), t == null || t(Q(r));
60
64
  }
61
- }, [n, b, P, f, o, _]), T(() => {
62
- if (R)
65
+ }, [n, N, g, f, t, S]), C(() => {
66
+ if (D)
63
67
  return;
64
68
  const i = /* @__PURE__ */ new Map();
65
- if (!d || w) {
66
- N(i);
69
+ if (!d || E) {
70
+ A(i);
67
71
  return;
68
72
  }
69
- const O = d.numPages, r = [];
70
- for (let s = 1; s <= O; s++) {
73
+ const v = d.numPages, r = [];
74
+ for (let s = 1; s <= v; s++) {
71
75
  const e = d.getPage(s);
72
76
  r.push(e);
73
77
  }
74
78
  Promise.all(r).then((s) => {
75
79
  s.map((e) => {
76
- const { thumbnailViewport: S, scale: m } = z(e), I = e.getViewport();
80
+ const { thumbnailViewport: a, scale: P } = j(e), I = e.getViewport();
77
81
  i.set(e.pageNumber, {
78
82
  page: e,
79
- thumbnailViewport: S,
80
- thumbnailScale: m,
83
+ thumbnailViewport: a,
84
+ thumbnailScale: P,
81
85
  defaultRotation: I.rotation
82
86
  });
83
- }), N(i);
87
+ }), A(i);
84
88
  }).catch((s) => {
85
- c(void 0), l(C.INVALID_OR_CORRUPTED_PDF), o == null || o(F(s));
89
+ p(void 0), c(b.INVALID_OR_CORRUPTED_PDF), t == null || t(F(s));
86
90
  });
87
- }, [d, w, R, o]), {
91
+ }, [d, E, D, t]), {
88
92
  pdf: d,
89
93
  pages: q,
90
- loading: w,
94
+ loading: E,
91
95
  error: B,
92
- loadingProgress: p,
93
- passwordRequired: R,
96
+ loadingProgress: w,
97
+ passwordRequired: D,
94
98
  passwordError: G
95
99
  };
96
100
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf-kit/viewer",
3
- "version": "2.6.0-beta.0",
3
+ "version": "2.6.0-beta.2",
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": [