@pdf-viewer/react 1.4.0-beta.9 → 1.4.0-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,7 +1,7 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
2
  import { LoaderImage } from '../utils/types';
3
3
  interface LoaderContextType {
4
- LoaderImageComponent?: () => JSX.Element | undefined;
4
+ LoaderImageComponent?: FC;
5
5
  }
6
6
  export declare const LoaderContext: import('react').Context<LoaderContextType>;
7
7
  interface Props extends PropsWithChildren {
@@ -584,7 +584,7 @@ export interface SelectionModeContextType {
584
584
  export interface SelectionModeProps {
585
585
  initialSelectionMode?: SelectionMode;
586
586
  }
587
- export type LoaderImage = JSX.Element;
587
+ export type LoaderImage = JSX.Element | string;
588
588
  export interface LoadPDFOptions {
589
589
  onLoadError?: (error: any) => void;
590
590
  onLoaded?: (pdfDocument: PDFDocumentProxy) => void;
@@ -1,27 +1,27 @@
1
- import { useState as g, useCallback as h, useEffect as E } from "react";
2
- import { appConsole as l } from "../appConsole.js";
3
- const A = /* @__PURE__ */ new Date("2025-04-22T07:39:29.952Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", o = {
4
- invalidLicense: `You are currently using without a valid license. ${d}`,
5
- mismatchedDomain: `Your license key is not valid for the current domain / IP. ${d}`,
6
- expired: `Your license key has expired. ${d}`,
1
+ import { useState as E, useCallback as h, useEffect as A } from "react";
2
+ import { appConsole as c } from "../appConsole.js";
3
+ const b = /* @__PURE__ */ new Date("2025-04-24T02:37:04.255Z"), l = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", o = {
4
+ invalidLicense: `You are currently using without a valid license. ${l}`,
5
+ mismatchedDomain: `Your license key is not valid for the current domain / IP. ${l}`,
6
+ expired: `Your license key has expired. ${l}`,
7
7
  exceededVersion: "Your license does not support the current version of React PDF. The library version you are using exceeds the supported range of your license.",
8
8
  invalidSignature: "Invalid license key: Signature mismatch"
9
9
  };
10
- function b(r) {
11
- const t = r.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s+/g, ""), i = atob(t), n = new Uint8Array(i.length);
12
- for (let e = 0; e < i.length; e++)
13
- n[e] = i.charCodeAt(e);
10
+ function L(r) {
11
+ const t = r.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s+/g, ""), e = atob(t), n = new Uint8Array(e.length);
12
+ for (let i = 0; i < e.length; i++)
13
+ n[i] = e.charCodeAt(i);
14
14
  return n.buffer;
15
15
  }
16
- function L(r) {
17
- const t = atob(r), i = new Uint8Array(t.length);
16
+ function S(r) {
17
+ const t = atob(r), e = new Uint8Array(t.length);
18
18
  for (let n = 0; n < t.length; n++)
19
- i[n] = t.charCodeAt(n);
20
- return i.buffer;
19
+ e[n] = t.charCodeAt(n);
20
+ return e.buffer;
21
21
  }
22
- async function S(r, t = "SHA-256") {
22
+ async function I(r, t = "SHA-256") {
23
23
  try {
24
- const { data: i, signature: n } = JSON.parse(atob(r)), e = b(`-----BEGIN PUBLIC KEY-----
24
+ const { data: e, signature: n } = JSON.parse(atob(r)), i = L(`-----BEGIN PUBLIC KEY-----
25
25
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIokvErJ0Fctu0jduSAx
26
26
  gr+5Har/VSuZLlOunS28hnlqqA+OF1apHL7RYkjBosS15yvviYdLrVWYHpHnoY4b
27
27
  HLQ9I6YX6FMB9T/VbB4xLdVdKvfi8r49aTScl5EKuSpgpPgz2VSJTfvVGcRuth/Y
@@ -32,7 +32,7 @@ kwIDAQAB
32
32
  -----END PUBLIC KEY-----`), a = await window.crypto.subtle.importKey(
33
33
  "spki",
34
34
  // str2ab(publicKeyContent), // Convert PEM string to ArrayBuffer
35
- e,
35
+ i,
36
36
  { name: "RSA-PSS", hash: t },
37
37
  !0,
38
38
  ["verify"]
@@ -40,68 +40,69 @@ kwIDAQAB
40
40
  if (!await window.crypto.subtle.verify(
41
41
  { name: "RSA-PSS", saltLength: 32 },
42
42
  a,
43
- L(n),
43
+ S(n),
44
44
  // Convert signature to ArrayBuffer
45
- new TextEncoder().encode(atob(i))
45
+ new TextEncoder().encode(atob(e))
46
46
  ))
47
47
  throw new Error(o.invalidSignature);
48
- return JSON.parse(atob(i));
48
+ return JSON.parse(atob(e));
49
49
  } catch {
50
50
  throw new Error(o.invalidLicense);
51
51
  }
52
52
  }
53
- const I = (r, t) => r === "specific" ? t === window.location.host : window.location.host.includes(t), c = {
53
+ const y = (r, t) => r === "specific" ? t === window.location.host : window.location.host.includes(t), d = {
54
54
  isValid: !0,
55
55
  invalidatedMessage: o.invalidLicense,
56
56
  type: void 0
57
- }, N = (r) => {
58
- const [t, i] = g(c), n = h(async () => {
57
+ }, x = (r) => {
58
+ const [t, e] = E(d), n = h(async () => {
59
59
  if (!r)
60
- throw i(c), new Error("License is missing");
60
+ throw e(d), new Error("License is missing");
61
+ let i;
61
62
  try {
62
- const e = await S(r);
63
- l.debug(">>> validatedLicense", e);
64
- const { avu: a, exp: s, dmt: m, dm: p, t: w } = e;
65
- if (!s)
66
- throw new Error("License is missing expiration timestamp");
67
- if (s > Number.MAX_SAFE_INTEGER / 1e3)
68
- throw new Error("Invalid expiration timestamp: value too large");
69
- const v = new Date(s * 1e3), f = (/* @__PURE__ */ new Date()).getTime();
70
- if (v.getTime() < f)
71
- throw new Error(o.expired);
72
- if (!a)
73
- throw new Error("License is missing available until version timestamp");
74
- if (a > Number.MAX_SAFE_INTEGER / 1e3)
75
- throw new Error("Invalid available until version timestamp: value too large");
76
- const u = new Date(a * 1e3);
77
- if (l.debug("availableUntilTimestamp", u), u.getTime() < A.getTime())
78
- throw new Error(o.exceededVersion);
79
- if (!I(m, p))
80
- throw new Error(o.mismatchedDomain);
81
- return {
82
- isValid: !0,
83
- type: w,
84
- invalidatedMessage: void 0
85
- };
86
- } catch (e) {
87
- return l.warn(e.message), { ...c, invalidatedMessage: e.message };
63
+ i = await I(r);
64
+ } catch (m) {
65
+ throw c.warn(m.message), new Error(m.message);
88
66
  }
67
+ c.debug(">>> validatedLicense", i);
68
+ const { avu: a, exp: s, dmt: w, dm: p, t: f } = i;
69
+ if (!s)
70
+ throw new Error("License is missing expiration timestamp");
71
+ if (s > Number.MAX_SAFE_INTEGER / 1e3)
72
+ throw new Error("Invalid expiration timestamp: value too large");
73
+ const v = new Date(s * 1e3), g = (/* @__PURE__ */ new Date()).getTime();
74
+ if (v.getTime() < g)
75
+ throw new Error(o.expired);
76
+ if (!a)
77
+ throw new Error("License is missing available until version timestamp");
78
+ if (a > Number.MAX_SAFE_INTEGER / 1e3)
79
+ throw new Error("Invalid available until version timestamp: value too large");
80
+ const u = new Date(a * 1e3);
81
+ if (c.debug("availableUntilTimestamp", u), u.getTime() < b.getTime())
82
+ throw new Error(o.exceededVersion);
83
+ if (!y(w, p))
84
+ throw new Error(o.mismatchedDomain);
85
+ return {
86
+ isValid: !0,
87
+ type: f,
88
+ invalidatedMessage: void 0
89
+ };
89
90
  }, [r]);
90
- return E(() => {
91
- n().then(({ isValid: e, type: a, invalidatedMessage: s }) => {
92
- i({
93
- isValid: e,
91
+ return A(() => {
92
+ n().then(({ isValid: i, type: a, invalidatedMessage: s }) => {
93
+ e({
94
+ isValid: i,
94
95
  type: a,
95
96
  invalidatedMessage: s
96
97
  });
97
- }).catch((e) => {
98
- throw i({
99
- ...c,
98
+ }).catch((i) => {
99
+ e({
100
+ ...d,
100
101
  isValid: !1
101
- }), e;
102
+ }), c.warn(i.message);
102
103
  });
103
104
  }, [n]), t;
104
105
  };
105
106
  export {
106
- N as useLicense
107
+ x as useLicense
107
108
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@pdf-viewer/react",
3
3
  "private": false,
4
4
  "description": "The PDF Viewer component for React and Next.js",
5
- "version": "1.4.0-beta.9",
5
+ "version": "1.4.0-rc.0",
6
6
  "keywords": [
7
7
  "component",
8
8
  "frontend",