@pdf-viewer/react 1.4.0-beta.1 → 1.4.0-beta.10

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 (56) hide show
  1. package/dist/Popover-5281103c.js +3061 -0
  2. package/dist/RPDefaultLayout-ec67ce59.js +2911 -0
  3. package/dist/assets/RPDefaultLayout.css +1 -1
  4. package/dist/components/RPController.js +13 -12
  5. package/dist/components/RPPages.js +3 -2
  6. package/dist/components/RPProvider.js +1 -1
  7. package/dist/components/layout/RPDefaultLayout.js +1 -1
  8. package/dist/components/layout/sidebar/RPSidebar.js +1 -1
  9. package/dist/components/layout/sidebar/Thumbnail.js +1 -1
  10. package/dist/components/layout/sidebar/Thumbnails.js +1 -1
  11. package/dist/components/layout/toolbar/DocumentDialog.js +3 -2
  12. package/dist/components/layout/toolbar/FileDownloadTool.js +1 -1
  13. package/dist/components/layout/toolbar/MostPageTool.js +3 -2
  14. package/dist/components/layout/toolbar/OtherTool.js +1 -1
  15. package/dist/components/layout/toolbar/Paginate.js +1 -1
  16. package/dist/components/layout/toolbar/PrintTool.js +1 -1
  17. package/dist/components/layout/toolbar/RPToolbar.js +1 -1
  18. package/dist/components/layout/toolbar/RPToolbarEnd.js +1 -1
  19. package/dist/components/layout/toolbar/SearchTool.js +4 -3
  20. package/dist/components/layout/toolbar/ZoomTool.js +3 -2
  21. package/dist/components/page/AnnotationLayer.js +3 -2
  22. package/dist/components/page/CanvasLayer.js +3 -2
  23. package/dist/components/page/DualPage.js +1 -1
  24. package/dist/components/page/RPPage.js +3 -2
  25. package/dist/components/page/SinglePage.js +1 -1
  26. package/dist/components/page/TextHighlightLayer.js +3 -2
  27. package/dist/components/page/TextLayer.js +3 -2
  28. package/dist/components/ui/LoadingIndicator.js +1 -1
  29. package/dist/components/ui/Popover.js +4 -3058
  30. package/dist/contexts/LoaderContext.js +16 -20
  31. package/dist/contexts/PaginationContext.js +1 -1
  32. package/dist/contexts/PrintContext.js +1 -1
  33. package/dist/contexts/RPDocumentContext.js +27 -25
  34. package/dist/contexts/SearchContext.js +1 -1
  35. package/dist/contexts/SmoothScrollContext.js +13 -0
  36. package/dist/contexts/ThumbnailsContext.js +1 -1
  37. package/dist/contexts/ToolbarComponentContext.js +10 -8
  38. package/dist/contexts/ViewportContext.js +1 -1
  39. package/dist/main.js +1 -1
  40. package/dist/types/contexts/LoaderContext.d.ts +5 -2
  41. package/dist/types/contexts/SmoothScrollContext.d.ts +10 -0
  42. package/dist/types/utils/hooks/useLoadPdf.d.ts +1 -0
  43. package/dist/types/utils/types.d.ts +6 -3
  44. package/dist/utils/hooks/useFileDownload.js +3 -2
  45. package/dist/utils/hooks/useHighlight.js +13 -13
  46. package/dist/utils/hooks/useLicense.js +60 -59
  47. package/dist/utils/hooks/useLoadPdf.js +44 -38
  48. package/dist/utils/hooks/usePaginate.js +3 -2
  49. package/dist/utils/hooks/usePrint.js +3 -2
  50. package/dist/utils/hooks/useScrollToPage.js +3 -2
  51. package/dist/utils/hooks/useSearch.js +3 -2
  52. package/dist/utils/hooks/useThumbnail.js +3 -2
  53. package/dist/utils/hooks/useVirtualReactWindow.js +3 -2
  54. package/dist/utils/smoothScrollTo.js +3 -15
  55. package/package.json +1 -1
  56. package/dist/RPDefaultLayout-838ad8e8.js +0 -2907
@@ -1,30 +1,26 @@
1
- import { jsx as t } from "react/jsx-runtime";
2
- import { createContext as a, useContext as d, useState as m, useEffect as c } from "react";
3
- import { appConsole as f } from "../utils/appConsole.js";
4
- import { LoaderIcon as p } from "../components/icons/LoaderIcon.js";
5
- const n = a({
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import { createContext as d, useContext as i } from "react";
3
+ import { appConsole as m } from "../utils/appConsole.js";
4
+ import { LoaderIcon as s } from "../components/icons/LoaderIcon.js";
5
+ const t = d({
6
6
  LoaderImageComponent: void 0
7
- }), g = () => {
8
- const o = d(n);
9
- return typeof o.LoaderImageComponent > "u" && f.error("Please use this hooks inside children component of RPProvider"), o;
10
- }, l = ({ children: o, loaderImage: r }) => {
11
- const [e, s] = m("");
12
- c(() => {
13
- r && s(r);
14
- }, [r]);
15
- const i = () => e ? (e == null ? void 0 : e.trim().startsWith("<svg")) ? /* @__PURE__ */ t("span", { dangerouslySetInnerHTML: { __html: e } }) : /* @__PURE__ */ t("img", { src: e, alt: "react-pdf-viewer-loader" }) : /* @__PURE__ */ t(p, {});
16
- return /* @__PURE__ */ t(
17
- n.Provider,
7
+ }), u = () => {
8
+ const o = i(t);
9
+ return typeof o.LoaderImageComponent > "u" && m.error("Please use this hooks inside children component of RPProvider"), o;
10
+ }, C = ({ children: o, loaderImage: e }) => {
11
+ const n = () => e || /* @__PURE__ */ r(s, {});
12
+ return /* @__PURE__ */ r(
13
+ t.Provider,
18
14
  {
19
15
  value: {
20
- LoaderImageComponent: i
16
+ LoaderImageComponent: n
21
17
  },
22
18
  children: o
23
19
  }
24
20
  );
25
21
  };
26
22
  export {
27
- n as LoaderContext,
28
- l as LoaderProvider,
29
- g as useLoaderContext
23
+ t as LoaderContext,
24
+ C as LoaderProvider,
25
+ u as useLoaderContext
30
26
  };
@@ -1,6 +1,6 @@
1
1
  import "react/jsx-runtime";
2
2
  import "react";
3
- import { h as e, P as m, u as p } from "../RPDefaultLayout-838ad8e8.js";
3
+ import { h as e, P as m, u as p } from "../RPDefaultLayout-ec67ce59.js";
4
4
  import "./RPDocumentContext.js";
5
5
  import "../utils/appConsole.js";
6
6
  export {
@@ -1,6 +1,6 @@
1
1
  import "react/jsx-runtime";
2
2
  import "react";
3
- import { j as e, a as n, d as a } from "../RPDefaultLayout-838ad8e8.js";
3
+ import { j as e, a as n, d as a } from "../RPDefaultLayout-ec67ce59.js";
4
4
  export {
5
5
  e as PrintContext,
6
6
  n as PrintProvider,
@@ -1,44 +1,46 @@
1
1
  import { jsx as x } from "react/jsx-runtime";
2
- import { createContext as C, useState as m, useEffect as h, useMemo as S, useContext as g } from "react";
3
- import { useLoadPdf as v } from "../utils/hooks/useLoadPdf.js";
4
- import { usePdfProperties as D } from "../utils/hooks/usePdfProperties.js";
5
- import { appConsole as F } from "../utils/appConsole.js";
6
- const u = C({
2
+ import { createContext as C, useState as l, useEffect as h, useMemo as S, useContext as v } from "react";
3
+ import { useLoadPdf as D } from "../utils/hooks/useLoadPdf.js";
4
+ import { usePdfProperties as F } from "../utils/hooks/usePdfProperties.js";
5
+ import { appConsole as M } from "../utils/appConsole.js";
6
+ const m = C({
7
7
  pdf: void 0,
8
8
  pages: /* @__PURE__ */ new Map(),
9
9
  setPdfSrc: () => {
10
10
  },
11
11
  setFilename: () => {
12
12
  },
13
- loading: !1
14
- }), L = ({
13
+ loading: !1,
14
+ loaderProgress: 0
15
+ }), R = ({
15
16
  children: t,
16
17
  src: e,
17
- characterMap: a,
18
+ characterMap: u,
18
19
  onLoadError: c,
19
- onLoaded: l
20
+ onLoaded: P
20
21
  }) => {
21
- const [o, r] = m(e), { pdf: n, pages: s, loading: i } = v(o, a, { onLoadError: c, onLoaded: l }), [p, f] = m(), d = D(o, n, p);
22
+ const [o, n] = l(e), { pdf: r, pages: s, loading: i, loadingProgress: p } = D(o, u, { onLoadError: c, onLoaded: P }), [d, f] = l(), a = F(o, r, d);
22
23
  h(() => {
23
- f(e == null ? void 0 : e.split("/").pop()), r(e);
24
+ f(e == null ? void 0 : e.split("/").pop()), n(e);
24
25
  }, [e]);
25
- const P = S(() => ({
26
- pdf: n,
26
+ const g = S(() => ({
27
+ pdf: r,
27
28
  pages: s,
28
29
  pdfSrc: o,
29
- setPdfSrc: r,
30
- pdfProperties: d,
30
+ setPdfSrc: n,
31
+ pdfProperties: a,
31
32
  setFilename: f,
32
- filename: p,
33
- loading: i
34
- }), [n, s, o, d, i]);
35
- return /* @__PURE__ */ x(u.Provider, { value: P, children: o ? t : null });
36
- }, R = () => {
37
- const t = g(u);
38
- return t.pdfSrc || F.error("Please use this hooks inside children component of RPDocument"), t;
33
+ filename: d,
34
+ loading: i,
35
+ loaderProgress: p
36
+ }), [r, s, o, a, i, p]);
37
+ return /* @__PURE__ */ x(m.Provider, { value: g, children: o ? t : null });
38
+ }, b = () => {
39
+ const t = v(m);
40
+ return t.pdfSrc || M.error("Please use this hooks inside children component of RPDocument"), t;
39
41
  };
40
42
  export {
41
- L as DocumentProvider,
42
- u as default,
43
- R as useDocumentContext
43
+ R as DocumentProvider,
44
+ m as default,
45
+ b as useDocumentContext
44
46
  };
@@ -1,6 +1,6 @@
1
1
  import "react/jsx-runtime";
2
2
  import "react";
3
- import { o as a, S as s, e as S } from "../RPDefaultLayout-838ad8e8.js";
3
+ import { o as a, S as s, e as S } from "../RPDefaultLayout-ec67ce59.js";
4
4
  export {
5
5
  a as SearchContext,
6
6
  s as SearchProvider,
@@ -0,0 +1,13 @@
1
+ import { jsx as n } from "react/jsx-runtime";
2
+ import { createContext as c, useRef as o, useContext as s } from "react";
3
+ const t = c({
4
+ smoothScrolling: { current: !1 },
5
+ targetScrollPosition: { current: { left: 0, top: 0 } }
6
+ }), m = ({ children: r }) => {
7
+ const e = o(!1), l = o({ left: 0, top: 0 });
8
+ return /* @__PURE__ */ n(t.Provider, { value: { smoothScrolling: e, targetScrollPosition: l }, children: r });
9
+ }, u = () => s(t);
10
+ export {
11
+ m as SmoothScrollProvider,
12
+ u as useSmoothScrollContext
13
+ };
@@ -1,6 +1,6 @@
1
1
  import "react/jsx-runtime";
2
2
  import "react";
3
- import { l as i, T as r, m as e } from "../RPDefaultLayout-838ad8e8.js";
3
+ import { l as i, T as r, m as e } from "../RPDefaultLayout-ec67ce59.js";
4
4
  export {
5
5
  i as ThumbnailContext,
6
6
  r as ThumbnailProvider,
@@ -13,8 +13,9 @@ const e = l({
13
13
  printTool: !0,
14
14
  showPrintProgress: !0,
15
15
  selectionModeTool: !0,
16
- jumpNavigationTool: !0
17
- }), a = () => n(e), T = {
16
+ jumpNavigationTool: !0,
17
+ sidebarEnable: !0
18
+ }), d = () => n(e), s = {
18
19
  themeSwitcher: !0,
19
20
  documentProperties: !0,
20
21
  rotateTool: !0,
@@ -28,16 +29,17 @@ const e = l({
28
29
  thumbnailTool: !0,
29
30
  showPrintProgress: !0,
30
31
  selectionModeTool: !0,
31
- jumpNavigationTool: !0
32
- }, c = ({ children: t, slots: o }) => {
33
- const r = i(() => ({
34
- ...T,
32
+ jumpNavigationTool: !0,
33
+ sidebarEnable: !0
34
+ }, c = ({ children: r, slots: o }) => {
35
+ const t = i(() => ({
36
+ ...s,
35
37
  ...o
36
38
  }), [o]);
37
- return /* @__PURE__ */ u(e.Provider, { value: r, children: t });
39
+ return /* @__PURE__ */ u(e.Provider, { value: t, children: r });
38
40
  };
39
41
  export {
40
42
  e as ToolbarComponentContext,
41
43
  c as ToolbarComponentProvider,
42
- a as useToolbarComponentContext
44
+ d as useToolbarComponentContext
43
45
  };
@@ -21,7 +21,7 @@ const k = {
21
21
  }), s = {
22
22
  ...k,
23
23
  md: d
24
- }, l = () => r.width < s.md, u = (t) => {
24
+ }, l = () => r.width <= s.md, u = (t) => {
25
25
  const o = Object.entries(s);
26
26
  for (let i = o.length - 1; i >= 0; i--)
27
27
  if (t >= o[i][1])
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RPProvider as t } from "./components/RPProvider.js";
2
- import { b as x, R as n, c as s, u as m, d as p, e as f } from "./RPDefaultLayout-838ad8e8.js";
2
+ import { b as x, R as n, c as s, u as m, d as p, e as f } from "./RPDefaultLayout-ec67ce59.js";
3
3
  import { RPConfig as a } from "./components/RPConfig.js";
4
4
  import { RPController as l } from "./components/RPController.js";
5
5
  import { RPTheme as P } from "./components/RPTheme.js";
@@ -1,8 +1,11 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
- import { LoaderContextType } from '../utils/types';
2
+ import { LoaderImage } from '../utils/types';
3
+ interface LoaderContextType {
4
+ LoaderImageComponent?: FC;
5
+ }
3
6
  export declare const LoaderContext: import('react').Context<LoaderContextType>;
4
7
  interface Props extends PropsWithChildren {
5
- loaderImage?: string;
8
+ loaderImage?: LoaderImage;
6
9
  }
7
10
  export declare const useLoaderContext: () => LoaderContextType;
8
11
  export declare const LoaderProvider: FC<PropsWithChildren<Props>>;
@@ -0,0 +1,10 @@
1
+ import { ScrollPosition } from '../utils/types';
2
+ interface SmoothScrollContextType {
3
+ smoothScrolling: React.MutableRefObject<boolean>;
4
+ targetScrollPosition: React.MutableRefObject<ScrollPosition>;
5
+ }
6
+ export declare const SmoothScrollProvider: ({ children }: {
7
+ children: React.ReactNode;
8
+ }) => import("react/jsx-runtime").JSX.Element;
9
+ export declare const useSmoothScrollContext: () => SmoothScrollContextType;
10
+ export {};
@@ -4,4 +4,5 @@ export declare const useLoadPdf: (src?: RPSrc, characterMap?: CharacterMap, opti
4
4
  pdf: PDFDocumentProxy | undefined;
5
5
  pages: Map<number, PdfPage>;
6
6
  loading: boolean;
7
+ loadingProgress: number;
7
8
  };
@@ -11,6 +11,7 @@ export interface DocumentContextType {
11
11
  setFilename: React.Dispatch<React.SetStateAction<string | undefined>>;
12
12
  filename?: string | null;
13
13
  loading: boolean;
14
+ loaderProgress: number;
14
15
  }
15
16
  export declare enum AnnotationSubType {
16
17
  Text = 1,
@@ -243,7 +244,7 @@ export interface SetPageResult {
243
244
  export interface PageControl {
244
245
  focusedPage: number;
245
246
  setFocusedPage: (page: number | string) => void;
246
- goToPage: (page: number | string) => Promise<SetPageResult>;
247
+ goToPage: (page: number | string) => SetPageResult;
247
248
  totalPages: number;
248
249
  setTotalPages: (page: number) => void;
249
250
  nextPage: () => void;
@@ -295,7 +296,7 @@ export interface PageNavigationToolProps {
295
296
  nextPage: () => void;
296
297
  prevPage: () => void;
297
298
  changePage: (page: number) => void;
298
- goToPage: (page: number) => Promise<SetPageResult>;
299
+ goToPage: (page: number) => SetPageResult;
299
300
  }
300
301
  export interface PreparePrintProgress {
301
302
  loadedPages: number;
@@ -333,6 +334,7 @@ export interface RPSlots {
333
334
  selectionModeTool?: boolean;
334
335
  searchTool?: boolean;
335
336
  jumpNavigationTool?: boolean;
337
+ sidebarEnable?: boolean;
336
338
  }
337
339
  export interface RPIcons {
338
340
  goToFirstPageIcon?: React.ReactNode;
@@ -582,10 +584,11 @@ export interface SelectionModeContextType {
582
584
  export interface SelectionModeProps {
583
585
  initialSelectionMode?: SelectionMode;
584
586
  }
587
+ export type LoaderImage = JSX.Element | string;
585
588
  export interface LoadPDFOptions {
586
589
  onLoadError?: (error: any) => void;
587
590
  onLoaded?: (pdfDocument: PDFDocumentProxy) => void;
588
- loaderImage?: string;
591
+ loaderImage?: LoaderImage;
589
592
  }
590
593
  export interface ScrollPosition {
591
594
  left: number;
@@ -1,7 +1,7 @@
1
1
  import "react/jsx-runtime";
2
2
  import "../../contexts/RPDocumentContext.js";
3
3
  import "react";
4
- import { c as A } from "../../RPDefaultLayout-838ad8e8.js";
4
+ import { c as B } from "../../RPDefaultLayout-ec67ce59.js";
5
5
  import "../../contexts/DarkModeContext.js";
6
6
  import "../../contexts/RotationContext.js";
7
7
  import "../../contexts/LayerContext.js";
@@ -20,11 +20,12 @@ import "../../contexts/LayoutContainerContext.js";
20
20
  import "../../contexts/DimensionPagesContext.js";
21
21
  import "../../contexts/LocalizationContext.js";
22
22
  import "../../contexts/HighlightContext.js";
23
+ import "../../contexts/SmoothScrollContext.js";
23
24
  import "../../contexts/LoaderContext.js";
24
25
  import "../../components/RPConfig.js";
25
26
  import "../../contexts/ThemeContext.js";
26
27
  import "../../components/RPDropFileZone.js";
27
28
  import "../../contexts/ToolbarComponentContext.js";
28
29
  export {
29
- A as useFileDownload
30
+ B as useFileDownload
30
31
  };
@@ -1,7 +1,7 @@
1
- import { useState as c, useCallback as x, useEffect as C } from "react";
1
+ import { useState as l, useCallback as x, useEffect as C } from "react";
2
2
  import { getHighlightOptionsWithDefaults as H, findMatches as M } from "../highlight.js";
3
3
  const d = (i) => {
4
- const [g, r] = c(void 0), [l, a] = c([]), u = x(async (t) => {
4
+ const [g, a] = l(void 0), [u, r] = l([]), m = x(async (t) => {
5
5
  if (!t)
6
6
  return {};
7
7
  const o = t.numPages, s = {};
@@ -10,13 +10,13 @@ const d = (i) => {
10
10
  s[e.toString()] = await h.getTextContent();
11
11
  }
12
12
  return s;
13
- }, []), m = async (t) => {
14
- r(t);
15
- }, f = () => {
16
- a([]), r(void 0);
13
+ }, []), f = async (t) => {
14
+ a(t);
15
+ }, c = () => {
16
+ r([]), a(void 0);
17
17
  };
18
18
  return C(() => {
19
- i && u(i).then((t) => {
19
+ i && m(i).then((t) => {
20
20
  let o = [];
21
21
  for (const { keyword: s, highlightColor: e, options: h } of g) {
22
22
  const p = H(h);
@@ -36,14 +36,14 @@ const d = (i) => {
36
36
  o = [...o, ...y];
37
37
  }
38
38
  }
39
- a(o);
40
- }).catch((t) => {
41
- console.error(t);
39
+ r(o);
40
+ }).catch(() => {
41
+ c();
42
42
  });
43
43
  }, [g, i]), {
44
- highlight: m,
45
- clear: f,
46
- highlightMatches: l,
44
+ highlight: f,
45
+ clear: c,
46
+ highlightMatches: u,
47
47
  highlightKeywords: g
48
48
  };
49
49
  };
@@ -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-10T06:17:44.612Z"), d = "Please visit https://www.react-pdf.dev/license-management/ 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-23T03:32:21.513Z"), 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
  };
@@ -1,50 +1,56 @@
1
- import { useState as g, useRef as C, useEffect as c } from "react";
2
- import * as T from "pdfjs-dist";
3
- import { getThumbnailViewport as x } from "../getThumbnailViewport.js";
4
- import { useConfigContext as E } from "../../contexts/ConfigContext.js";
5
- const U = (i, o, w = {}) => {
6
- const [s, b] = g(), { workerUrlAdded: a } = E(), [k, P] = g(/* @__PURE__ */ new Map()), u = C(), [l, p] = g(!1), { onLoadError: m, onLoaded: f } = w;
7
- return c(() => {
8
- if (!a || !i)
1
+ import { useState as l, useRef as E, useEffect as k } from "react";
2
+ import * as I from "pdfjs-dist";
3
+ import { getThumbnailViewport as N } from "../getThumbnailViewport.js";
4
+ import { useConfigContext as S } from "../../contexts/ConfigContext.js";
5
+ const A = (d, e, L = {}) => {
6
+ const [r, y] = l(), { workerUrlAdded: p } = S(), [C, w] = l(/* @__PURE__ */ new Map()), i = E(), [T, m] = l(0), [f, b] = l(!1), { onLoadError: g, onLoaded: a } = L;
7
+ return k(() => {
8
+ if (!p || !d)
9
9
  return;
10
- u.current = Date.now();
11
- const n = u.current, d = {
12
- url: i,
13
- cMapPacked: (o == null ? void 0 : o.isCompressed) ?? !0,
14
- ...(o == null ? void 0 : o.url) && { cMapUrl: o.url }
15
- }, r = T.getDocument(d);
16
- p(!0);
17
- const t = r.promise.then((e) => (n === u.current && b(e), f && f(e), e)).catch((e) => {
18
- m && m(e);
19
- }).finally(() => p(!1));
10
+ i.current = Date.now();
11
+ const t = i.current, P = {
12
+ url: d,
13
+ cMapPacked: (e == null ? void 0 : e.isCompressed) ?? !0,
14
+ ...(e == null ? void 0 : e.url) && { cMapUrl: e.url }
15
+ }, n = I.getDocument(P);
16
+ n.onProgress = (o) => {
17
+ if (t === i.current) {
18
+ const { loaded: c, total: u } = o, x = u ? Math.min(100, Math.round(c / u * 100)) : 0;
19
+ m(x);
20
+ }
21
+ }, b(!0), m(0);
22
+ const s = n.promise.then((o) => (t === i.current && (y(o), m(100)), a && a(o), o)).catch((o) => {
23
+ g && g(o);
24
+ }).finally(() => b(!1));
20
25
  return () => {
21
- t.finally(() => {
22
- r.destroy();
26
+ s.finally(() => {
27
+ n.destroy();
23
28
  });
24
29
  };
25
- }, [i, a, m, f]), c(() => {
26
- const n = /* @__PURE__ */ new Map();
27
- if (!s || l) {
28
- P(n);
30
+ }, [d, p, g, a]), k(() => {
31
+ const t = /* @__PURE__ */ new Map();
32
+ if (!r || f) {
33
+ w(t);
29
34
  return;
30
35
  }
31
- const d = s.numPages, r = [];
32
- for (let t = 1; t <= d; t++) {
33
- const e = s.getPage(t);
34
- r.push(e);
36
+ const P = r.numPages, n = [];
37
+ for (let s = 1; s <= P; s++) {
38
+ const o = r.getPage(s);
39
+ n.push(o);
35
40
  }
36
- Promise.all(r).then((t) => {
37
- t.map((e) => {
38
- const { thumbnailViewport: L, scale: y } = x(e);
39
- n.set(e.pageNumber, { page: e, thumbnailViewport: L, thumbnailScale: y });
40
- }), P(n);
41
+ Promise.all(n).then((s) => {
42
+ s.map((o) => {
43
+ const { thumbnailViewport: c, scale: u } = N(o);
44
+ t.set(o.pageNumber, { page: o, thumbnailViewport: c, thumbnailScale: u });
45
+ }), w(t);
41
46
  });
42
- }, [s, l]), {
43
- pdf: s,
44
- pages: k,
45
- loading: l
47
+ }, [r, f]), {
48
+ pdf: r,
49
+ pages: C,
50
+ loading: f,
51
+ loadingProgress: T
46
52
  };
47
53
  };
48
54
  export {
49
- U as useLoadPdf
55
+ A as useLoadPdf
50
56
  };