@pdf-viewer/react 1.4.0-beta.4 → 1.4.0-beta.6

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,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
  };
@@ -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,
@@ -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,6 +1,6 @@
1
1
  import { useState as g, useCallback as h, useEffect as E } from "react";
2
2
  import { appConsole as l } from "../appConsole.js";
3
- const A = /* @__PURE__ */ new Date("2025-04-16T03:06:57.051Z"), d = "Please visit https://www.react-pdf.dev/license-management/ to generate a new license key.", o = {
3
+ const A = /* @__PURE__ */ new Date("2025-04-18T03:13:50.431Z"), d = "Please visit https://www.react-pdf.dev/license-management/ to generate a new license key.", o = {
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,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
  };
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.4",
5
+ "version": "1.4.0-beta.6",
6
6
  "keywords": [
7
7
  "component",
8
8
  "frontend",