@react-pdf-kit/viewer 0.0.0-legacy.0 → 0.0.0-legacy.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-04-03T08:12:50.805Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", s = {
3
+ const b = /* @__PURE__ */ new Date("2026-05-06T16:14:18.520Z"), 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,85 +1,95 @@
1
- import { useState as d, useRef as A, useEffect as k } from "react";
2
- import * as I from "pdfjs-dist";
3
- import { ErrorType as F } from "../types.js";
4
- import { getThumbnailViewport as j } from "../getThumbnailViewport.js";
5
- import { useConfigContext as z } from "../../contexts/ConfigContext.js";
6
- import { useDocumentPasswordContext as _ } from "../../contexts/DocumentPasswordContext.js";
1
+ import { useState as u, useRef as O, useEffect as h } from "react";
2
+ import * as C from "pdfjs-dist";
3
+ import { ErrorType as $ } from "../types.js";
4
+ import { getThumbnailViewport as A } from "../getThumbnailViewport.js";
5
+ import { useConfigContext as j } from "../../contexts/ConfigContext.js";
6
+ import { useDocumentPasswordContext as z } from "../../contexts/DocumentPasswordContext.js";
7
7
  import "../../de_DE-a553b162.js";
8
8
  import "react/jsx-runtime";
9
9
  import "../appConsole.js";
10
- const Y = (m, s, h = {}) => {
11
- const [n, q] = d(), { workerUrlAdded: v } = z(), [D, S] = d(/* @__PURE__ */ new Map()), a = A(), [f, g] = d(0), [P, T] = d(!1), [N, O] = d(), { password: u, passwordError: U, setPasswordError: c, passwordRequired: p, setPasswordRequired: w } = _(), { onLoadError: i, onLoaded: E, onLoadProgress: b, disableAutoFetch: x, disableStream: C, rangeChunkSize: V } = h;
12
- return k(() => {
13
- b && b(f);
14
- }, [f, b]), k(() => {
15
- if (!v || !m)
10
+ const X = (g, t, V = {}) => {
11
+ const [r, D] = u(), { workerUrlAdded: S } = j(), [I, q] = u(/* @__PURE__ */ new Map()), d = O(), [p, L] = u(0), [f, x] = u(!1), [U, F] = u(), { password: a, passwordError: N, setPasswordError: w, passwordRequired: k, setPasswordRequired: E } = z(), { onLoadError: i, onLoaded: b, onLoadProgress: v, disableAutoFetch: y, disableStream: R, rangeChunkSize: T } = V;
12
+ return h(() => {
13
+ v && v(p);
14
+ }, [p, v]), h(() => {
15
+ if (!S) {
16
+ console.log("useLoadPdf: skipping — worker URL not yet added");
16
17
  return;
17
- g(0), a.current = Date.now();
18
- const r = a.current, R = {
19
- url: m,
20
- cMapPacked: (s == null ? void 0 : s.isCompressed) ?? !0,
21
- ...(s == null ? void 0 : s.url) && { cMapUrl: s.url },
22
- ...u && { password: u },
23
- ...x !== void 0 && { disableAutoFetch: x },
24
- ...C !== void 0 && { disableStream: C },
25
- ...V !== void 0 && { rangeChunkSize: V },
26
- verbosity: I.VerbosityLevel.ERRORS
18
+ }
19
+ if (!g) {
20
+ console.log("useLoadPdf: skipping — no src provided");
21
+ return;
22
+ }
23
+ console.log("useLoadPdf: starting load", { src: g, password: !!a, disableAutoFetch: y, disableStream: R, rangeChunkSize: T }), L(0), d.current = Date.now();
24
+ const s = d.current, c = {
25
+ url: g,
26
+ cMapPacked: (t == null ? void 0 : t.isCompressed) ?? !0,
27
+ ...(t == null ? void 0 : t.url) && { cMapUrl: t.url },
28
+ ...a && { password: a },
29
+ ...y !== void 0 && { disableAutoFetch: y },
30
+ ...R !== void 0 && { disableStream: R },
31
+ ...T !== void 0 && { rangeChunkSize: T },
32
+ verbosity: C.VerbosityLevel.ERRORS
27
33
  };
28
34
  try {
29
- const e = I.getDocument(R);
35
+ const e = C.getDocument(c);
30
36
  e.onProgress = (o) => {
31
- if (r === a.current) {
32
- const { loaded: y, total: l } = o, L = l ? Math.min(100, Math.round(y / l * 100)) : 0;
33
- g(L);
37
+ if (s === d.current) {
38
+ const { loaded: P, total: l } = o, m = l ? Math.min(100, Math.round(P / l * 100)) : 0;
39
+ console.log(`useLoadPdf: progress ${m}% (${P}/${l})`), L(m);
34
40
  }
35
- }, T(!0);
36
- const t = e.promise.then((o) => (r === a.current && (q(o), g(100)), E && E(o), w(!1), c(""), o)).catch((o) => {
37
- o instanceof Error && o.name === "PasswordException" ? (w(!0), c(o.message || "Password required")) : o instanceof Error && o.name === "InvalidPDFException" && u ? (w(!0), c("Incorrect password")) : i && i(o);
41
+ }, x(!0);
42
+ const n = e.promise.then((o) => (s === d.current ? (console.log("useLoadPdf: document loaded", { numPages: o.numPages, taskId: s }), D(o), L(100)) : console.log("useLoadPdf: stale task resolved, ignoring", { taskId: s, latestTask: d.current }), b && b(o), E(!1), w(""), o)).catch((o) => {
43
+ o instanceof Error && o.name === "PasswordException" ? (console.log("useLoadPdf: password required", o.message), E(!0), w(o.message || "Password required")) : o instanceof Error && o.name === "InvalidPDFException" && a ? (console.log("useLoadPdf: invalid PDF / incorrect password", o.message), E(!0), w("Incorrect password")) : (console.log("useLoadPdf: load error", o), i && i(o));
38
44
  }).finally(() => {
39
- T(!1);
45
+ console.log("useLoadPdf: loading finished, setting loading=false"), x(!1);
40
46
  });
41
47
  return () => {
42
- t.finally(() => {
48
+ n.finally(() => {
43
49
  e.destroy();
44
50
  });
45
51
  };
46
52
  } catch (e) {
47
- O(F.NOT_SUPPORTED), i && i(e);
53
+ console.log("useLoadPdf: synchronous error in getDocument", e), F($.NOT_SUPPORTED), i && i(e);
48
54
  }
49
- }, [m, v, u, i, E]), k(() => {
50
- if (p)
55
+ }, [g, S, a, i, b]), h(() => {
56
+ if (k) {
57
+ console.log("useLoadPdf: skipping page load — password required");
51
58
  return;
52
- const r = /* @__PURE__ */ new Map();
53
- if (!n || P) {
54
- S(r);
59
+ }
60
+ const s = /* @__PURE__ */ new Map();
61
+ if (!r || f) {
62
+ console.log("useLoadPdf: skipping page load", { pdf: !!r, loading: f }), q(s);
55
63
  return;
56
64
  }
57
- const R = n.numPages, e = [];
58
- for (let t = 1; t <= R; t++) {
59
- const o = n.getPage(t);
65
+ const c = r.numPages;
66
+ console.log("useLoadPdf: loading pages", { totalPage: c });
67
+ const e = [];
68
+ for (let n = 1; n <= c; n++) {
69
+ const o = r.getPage(n);
60
70
  e.push(o);
61
71
  }
62
- Promise.all(e).then((t) => {
63
- t.map((o) => {
64
- const { thumbnailViewport: y, scale: l } = j(o), L = o.getViewport();
65
- r.set(o.pageNumber, {
72
+ Promise.all(e).then((n) => {
73
+ console.log("useLoadPdf: all pages loaded", { count: n.length }), n.map((o) => {
74
+ const { thumbnailViewport: P, scale: l } = A(o), m = o.getViewport();
75
+ s.set(o.pageNumber, {
66
76
  page: o,
67
- thumbnailViewport: y,
77
+ thumbnailViewport: P,
68
78
  thumbnailScale: l,
69
- defaultRotation: L.rotation
79
+ defaultRotation: m.rotation
70
80
  });
71
- }), S(r);
81
+ }), q(s);
72
82
  });
73
- }, [n, P, p]), {
74
- pdf: n,
75
- pages: D,
76
- loading: P,
77
- error: N,
78
- loadingProgress: f,
79
- passwordRequired: p,
80
- passwordError: U
83
+ }, [r, f, k]), {
84
+ pdf: r,
85
+ pages: I,
86
+ loading: f,
87
+ error: U,
88
+ loadingProgress: p,
89
+ passwordRequired: k,
90
+ passwordError: N
81
91
  };
82
92
  };
83
93
  export {
84
- Y as useLoadPdf
94
+ X as useLoadPdf
85
95
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf-kit/viewer",
3
- "version": "0.0.0-legacy.0",
3
+ "version": "0.0.0-legacy.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": [