@react-pdf-kit/viewer 2.7.3 → 2.7.4-rc.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.
Files changed (54) hide show
  1. package/dist/{AnnotationLayer-SQbmx6wX.js → AnnotationLayer-C_Sk3ZMg.js} +1 -1
  2. package/dist/{PaginationContext-B3qzCYJu.js → PaginationContext-BmPajxlU.js} +24 -16
  3. package/dist/{RPPage-BdoE0RrK.js → RPPage-B1UMGNSI.js} +1 -1
  4. package/dist/{RPPages-Dw7lGXzM.js → RPPages-Dh4RWlPS.js} +346 -341
  5. package/dist/{Thumbnail-BVjnCNxv.js → Thumbnail-BOvkeGXM.js} +1 -1
  6. package/dist/{Thumbnails-CrKLESh3.js → Thumbnails-jteSWSw9.js} +2 -2
  7. package/dist/components/RPController.js +1 -1
  8. package/dist/components/RPPages.js +1 -1
  9. package/dist/components/layout/sidebar/RPSidebar.js +1 -1
  10. package/dist/components/layout/sidebar/Thumbnail.js +1 -1
  11. package/dist/components/layout/sidebar/Thumbnails.js +1 -1
  12. package/dist/components/layout/toolbar/MostPageTool.js +1 -1
  13. package/dist/components/layout/toolbar/Paginate.js +1 -1
  14. package/dist/components/layout/toolbar/ScrollModeTool.js +4 -4
  15. package/dist/components/layout/toolbar/ToolbarCustom.js +1 -1
  16. package/dist/components/layout/toolbar/ToolbarDefault.js +1 -1
  17. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +1 -1
  18. package/dist/components/layout/toolbar/tools/FirstPageTool.js +1 -1
  19. package/dist/components/layout/toolbar/tools/HorizontalScrollingTool.js +2 -2
  20. package/dist/components/layout/toolbar/tools/InputPageTool.js +1 -1
  21. package/dist/components/layout/toolbar/tools/LastPageTool.js +1 -1
  22. package/dist/components/layout/toolbar/tools/NextPageTool.js +1 -1
  23. package/dist/components/layout/toolbar/tools/PreviousPageTool.js +1 -1
  24. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +1 -1
  25. package/dist/components/layout/toolbar/tools/more-options/ScrollModeTool.js +5 -5
  26. package/dist/components/page/AnnotationLayer.js +1 -1
  27. package/dist/components/page/DualPage.js +2 -2
  28. package/dist/components/page/DualPageWithCover.js +2 -2
  29. package/dist/components/page/RPPage.js +1 -1
  30. package/dist/components/page/SinglePage.js +2 -2
  31. package/dist/contexts/ElementThumbnailContext.js +1 -1
  32. package/dist/contexts/PaginationContext.js +1 -1
  33. package/dist/contexts/RenderQueueProvider.js +1 -1
  34. package/dist/{de_DE-C1OrwQKj.js → de_DE-x4Z-jQrz.js} +12 -0
  35. package/dist/{main-CdlJS0xf.js → main-ByQlDC9E.js} +1 -1
  36. package/dist/main.js +3 -3
  37. package/dist/types/locales/de_DE.json.d.ts +2 -0
  38. package/dist/types/locales/en_US.json.d.ts +2 -0
  39. package/dist/types/locales/it_IT.json.d.ts +2 -0
  40. package/dist/types/locales/pt_PT.json.d.ts +2 -0
  41. package/dist/types/locales/th_TH.json.d.ts +2 -0
  42. package/dist/types/locales/zh_CN.json.d.ts +2 -0
  43. package/dist/types/utils/const.d.ts +3 -0
  44. package/dist/types/utils/types.d.ts +4 -1
  45. package/dist/utils/const.js +2 -2
  46. package/dist/utils/hooks/useLicense.js +1 -1
  47. package/dist/utils/hooks/useLoadPdf.js +73 -63
  48. package/dist/utils/hooks/useLocalization.js +1 -1
  49. package/dist/utils/hooks/usePaginate.js +1 -1
  50. package/dist/utils/hooks/usePresentPage.js +1 -1
  51. package/dist/utils/hooks/useScrollToPage.js +1 -1
  52. package/dist/utils/hooks/useSearch.js +1 -1
  53. package/dist/utils/types.js +2 -2
  54. package/package.json +1 -1
@@ -2,75 +2,83 @@
2
2
  import { ErrorType as e } from "../types.js";
3
3
  import { getThumbnailViewport as t } from "../getThumbnailViewport.js";
4
4
  import { useConfigContext as n } from "../../contexts/ConfigContext.js";
5
- import { useDocumentPasswordContext as r } from "../../contexts/DocumentPasswordContext.js";
6
- import { BROWSER_NOT_SUPPORTED_MESSAGE as i, INVALID_OR_CORRUPTED_PDF_MESSAGE as a } from "../const.js";
7
- import { useEffect as o, useRef as s, useState as c } from "react";
8
- import * as l from "pdfjs-dist";
5
+ import { appConsole as r } from "../appConsole.js";
6
+ import { useDocumentPasswordContext as i } from "../../contexts/DocumentPasswordContext.js";
7
+ import { BROWSER_NOT_SUPPORTED_MESSAGE as a, INVALID_OR_CORRUPTED_PDF_MESSAGE as o, WASM_URL_REQUIRED_CONSOLE_MESSAGE as s, WASM_URL_REQUIRED_MESSAGE as c } from "../const.js";
8
+ import { useEffect as l, useRef as u, useState as d } from "react";
9
+ import * as f from "pdfjs-dist";
9
10
  //#region lib/utils/hooks/useLoadPdf.ts
10
- function u(e) {
11
- let t = Error(a);
11
+ var p = new TextEncoder().encode("/JPXDecode");
12
+ function m(e) {
13
+ return e.some((t, n) => t === p[0] ? p.every((t, r) => e[n + r] === t) : !1);
14
+ }
15
+ function h(e) {
16
+ let t = Error(o);
12
17
  return t.cause = e, t;
13
18
  }
14
- function d(e) {
15
- let t = Error(i);
19
+ function g() {
20
+ return Error(c);
21
+ }
22
+ function _(e) {
23
+ let t = Error(a);
16
24
  return t.cause = e, t;
17
25
  }
18
- var f = (i, a, f = {}) => {
19
- let [p, m] = c(), { workerUrlAdded: h, wasmUrl: g } = n(), [_, v] = c(/* @__PURE__ */ new Map()), y = s(), [b, x] = c(0), [S, C] = c(!1), [w, T] = c(), { password: E, passwordError: D, setPasswordError: O, passwordRequired: k, setPasswordRequired: A } = r(), { onLoadError: j, onLoaded: M, onLoadProgress: N, disableAutoFetch: P, disableStream: F, rangeChunkSize: I, withCredentials: L, httpHeaders: R } = f;
20
- return o(() => {
21
- N && N(b);
22
- }, [b, N]), o(() => {
23
- if (!h || !i) return;
24
- x(0), T(void 0), y.current = Date.now();
25
- let t = y.current, n = {
26
- url: i,
27
- cMapPacked: a?.isCompressed ?? !0,
28
- ...a?.url && { cMapUrl: a.url },
29
- ...E && { password: E },
30
- ...P !== void 0 && { disableAutoFetch: P },
31
- ...F !== void 0 && { disableStream: F },
32
- ...I !== void 0 && { rangeChunkSize: I },
33
- ...L !== void 0 && { withCredentials: L },
34
- ...R !== void 0 && { httpHeaders: R },
35
- ...g && { wasmUrl: g },
36
- verbosity: l.VerbosityLevel.ERRORS
26
+ var v = (a, o, c = {}) => {
27
+ let [p, v] = d(), { workerUrlAdded: y, wasmUrl: b } = n(), [x, S] = d(/* @__PURE__ */ new Map()), C = u(), [w, T] = d(0), [E, D] = d(!1), [O, k] = d(), { password: A, passwordError: j, setPasswordError: M, passwordRequired: N, setPasswordRequired: P } = i(), { onLoadError: F, onLoaded: I, onLoadProgress: L, disableAutoFetch: R, disableStream: z, rangeChunkSize: B, withCredentials: V, httpHeaders: H } = c;
28
+ return l(() => {
29
+ L && L(w);
30
+ }, [w, L]), l(() => {
31
+ if (!y || !a) return;
32
+ T(0), k(void 0), C.current = Date.now();
33
+ let t = C.current, n = {
34
+ url: a,
35
+ cMapPacked: o?.isCompressed ?? !0,
36
+ ...o?.url && { cMapUrl: o.url },
37
+ ...A && { password: A },
38
+ ...R !== void 0 && { disableAutoFetch: R },
39
+ ...z !== void 0 && { disableStream: z },
40
+ ...B !== void 0 && { rangeChunkSize: B },
41
+ ...V !== void 0 && { withCredentials: V },
42
+ ...H !== void 0 && { httpHeaders: H },
43
+ ...b && { wasmUrl: b },
44
+ verbosity: f.VerbosityLevel.ERRORS
37
45
  };
38
46
  try {
39
- let r = l.getDocument(n);
40
- r.onProgress = (e) => {
41
- if (t === y.current) {
47
+ let i = f.getDocument(n);
48
+ i.onProgress = (e) => {
49
+ if (t === C.current) {
42
50
  let { loaded: t, total: n } = e;
43
- x(n ? Math.min(100, Math.round(t / n * 100)) : 0);
51
+ T(n ? Math.min(100, Math.round(t / n * 100)) : 0);
44
52
  }
45
- }, C(!0), m(void 0);
46
- let i = r.promise.then((e) => (t === y.current && (m(e), x(100)), M && M(e), A(!1), O(""), e)).catch((t) => {
53
+ }, D(!0), v(void 0);
54
+ let a = i.promise.then(async (n) => !b && m(await n.getData()) ? (t === C.current && (v(void 0), k(e.WASM_URL_REQUIRED)), r.error(s), F?.(g()), n) : (t === C.current && (v(n), T(100)), I && I(n), P(!1), M(""), n)).catch((t) => {
47
55
  if (t instanceof Error && t.name === "PasswordException") {
48
56
  let e = t.code;
49
- A(!0), e === l.PasswordResponses.INCORRECT_PASSWORD ? O("Incorrect password") : O(void 0);
50
- } else t instanceof Error && t.name === "InvalidPDFException" && E ? (A(!0), O("Incorrect password")) : t instanceof Error && t.name === "InvalidPDFException" ? (T(e.INVALID_OR_CORRUPTED_PDF), j?.(u(t))) : j && j(t);
57
+ P(!0), e === f.PasswordResponses.INCORRECT_PASSWORD ? M("Incorrect password") : M(void 0);
58
+ } else t instanceof Error && t.name === "InvalidPDFException" && A ? (P(!0), M("Incorrect password")) : t instanceof Error && t.name === "InvalidPDFException" ? (k(e.INVALID_OR_CORRUPTED_PDF), F?.(h(t))) : F && F(t);
51
59
  }).finally(() => {
52
- C(!1);
60
+ D(!1);
53
61
  });
54
62
  return () => {
55
- i.finally(() => {
56
- r.destroy();
63
+ a.finally(() => {
64
+ i.destroy();
57
65
  });
58
66
  };
59
67
  } catch (t) {
60
- T(e.NOT_SUPPORTED), j?.(d(t));
68
+ k(e.NOT_SUPPORTED), F?.(_(t));
61
69
  }
62
70
  }, [
63
- i,
64
- h,
65
- g,
66
- E,
67
- j,
68
- M
69
- ]), o(() => {
70
- if (k) return;
71
+ a,
72
+ y,
73
+ b,
74
+ A,
75
+ F,
76
+ I
77
+ ]), l(() => {
78
+ if (N) return;
71
79
  let n = /* @__PURE__ */ new Map();
72
- if (!p || S) {
73
- v(n);
80
+ if (!p || E) {
81
+ S(n);
74
82
  return;
75
83
  }
76
84
  let r = p.numPages, i = [];
@@ -78,8 +86,10 @@ var f = (i, a, f = {}) => {
78
86
  let t = p.getPage(e);
79
87
  i.push(t);
80
88
  }
81
- Promise.all(i).then((e) => {
82
- e.map((e) => {
89
+ Promise.allSettled(i).then((e) => {
90
+ let r = e.filter((e) => e.status === "fulfilled").map((e) => e.value);
91
+ if (!r.length) throw e.find((e) => e.status === "rejected")?.reason;
92
+ r.map((e) => {
83
93
  let { thumbnailViewport: r, scale: i } = t(e), a = e.getViewport();
84
94
  n.set(e.pageNumber, {
85
95
  page: e,
@@ -87,24 +97,24 @@ var f = (i, a, f = {}) => {
87
97
  thumbnailScale: i,
88
98
  defaultRotation: a.rotation
89
99
  });
90
- }), v(n);
100
+ }), S(n);
91
101
  }).catch((t) => {
92
- m(void 0), T(e.INVALID_OR_CORRUPTED_PDF), j?.(u(t));
102
+ v(void 0), k(e.INVALID_OR_CORRUPTED_PDF), F?.(h(t));
93
103
  });
94
104
  }, [
95
105
  p,
96
- S,
97
- k,
98
- j
106
+ E,
107
+ N,
108
+ F
99
109
  ]), {
100
110
  pdf: p,
101
- pages: _,
102
- loading: S,
103
- error: w,
104
- loadingProgress: b,
105
- passwordRequired: k,
106
- passwordError: D
111
+ pages: x,
112
+ loading: E,
113
+ error: O,
114
+ loadingProgress: w,
115
+ passwordRequired: N,
116
+ passwordError: j
107
117
  };
108
118
  };
109
119
  //#endregion
110
- export { f as useLoadPdf };
120
+ export { v as useLoadPdf };
@@ -1,4 +1,4 @@
1
- import { a as e, i as t, n, o as r, r as i, t as a } from "../../de_DE-C1OrwQKj.js";
1
+ import { a as e, i as t, n, o as r, r as i, t as a } from "../../de_DE-x4Z-jQrz.js";
2
2
  import { useCallback as o, useMemo as s, useState as c } from "react";
3
3
  //#region lib/utils/hooks/useLocalization.ts
4
4
  var l = (l) => {
@@ -1,2 +1,2 @@
1
- import { i as e } from "../../PaginationContext-B3qzCYJu.js";
1
+ import { i as e } from "../../PaginationContext-BmPajxlU.js";
2
2
  export { e as usePaginate };
@@ -4,7 +4,7 @@ import { useDebounce as n } from "./useDebounce.js";
4
4
  import { useDimensionPagesContext as r } from "../../contexts/DimensionPagesContext.js";
5
5
  import { useSmoothScrollContext as i } from "../../contexts/SmoothScrollContext.js";
6
6
  import { getGridDimension as a, getPositionFromPage as o } from "../calculatePage.js";
7
- import { r as s } from "../../PaginationContext-B3qzCYJu.js";
7
+ import { r as s } from "../../PaginationContext-BmPajxlU.js";
8
8
  import { useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
9
9
  //#region lib/utils/hooks/usePresentPage.ts
10
10
  var p = (p, m, h, g) => {
@@ -1,2 +1,2 @@
1
- import { a as e } from "../../PaginationContext-B3qzCYJu.js";
1
+ import { a as e } from "../../PaginationContext-BmPajxlU.js";
2
2
  export { e as useScrollToPage };
@@ -9,7 +9,7 @@ import { usePagesRotateContext as c } from "../../contexts/PagesRotateContext.js
9
9
  import { useDimensionPagesContext as l } from "../../contexts/DimensionPagesContext.js";
10
10
  import { useSmoothScrollContext as u } from "../../contexts/SmoothScrollContext.js";
11
11
  import { getScrollDistance as d } from "../getScrollDistance.js";
12
- import { r as f } from "../../PaginationContext-B3qzCYJu.js";
12
+ import { r as f } from "../../PaginationContext-BmPajxlU.js";
13
13
  import { findMatches as p } from "../highlight.js";
14
14
  import { getWordPositionInPage as m } from "../getWordPositionInPage.js";
15
15
  import { useCallback as h, useEffect as g, useMemo as _, useRef as v, useState as y } from "react";
@@ -1,11 +1,11 @@
1
- import { a as e, i as t, n, o as r, r as i, t as a } from "../de_DE-C1OrwQKj.js";
1
+ import { a as e, i as t, n, o as r, r as i, t as a } from "../de_DE-x4Z-jQrz.js";
2
2
  //#region lib/utils/types.ts
3
3
  var o = /* @__PURE__ */ function(e) {
4
4
  return e[e.Text = 1] = "Text", e[e.Link = 2] = "Link", e[e.FreeText = 3] = "FreeText", e[e.Line = 4] = "Line", e[e.Square = 5] = "Square", e[e.Circle = 6] = "Circle", e[e.Polygon = 7] = "Polygon", e[e.Polyline = 8] = "Polyline", e[e.Highlight = 9] = "Highlight", e[e.Underline = 10] = "Underline", e[e.Squiggly = 11] = "Squiggly", e[e.StrikeOut = 12] = "StrikeOut", e[e.Stamp = 13] = "Stamp", e[e.Caret = 14] = "Caret", e[e.Ink = 15] = "Ink", e[e.Popup = 16] = "Popup", e[e.FileAttachment = 17] = "FileAttachment", e[e.Widget = 20] = "Widget", e;
5
5
  }({}), s = /* @__PURE__ */ function(e) {
6
6
  return e.INTERNAL_LINK = "internal-link", e.LINK = "link", e.FILE_ATTACHMENT = "file-attachment", e.FORM_TEXT = "form-text", e.FORM_SELECT = "form-select", e.FORM_CHECKBOX = "form-checkbox", e.FORM_RADIO = "form-radio", e.FORM_BUTTON = "form-button", e.BUTTON = "button", e;
7
7
  }({}), c = /* @__PURE__ */ function(e) {
8
- return e.NOT_SUPPORTED = "not-supported", e.INVALID_OR_CORRUPTED_PDF = "invalid-or-corrupted-pdf", e;
8
+ return e.NOT_SUPPORTED = "not-supported", e.INVALID_OR_CORRUPTED_PDF = "invalid-or-corrupted-pdf", e.WASM_URL_REQUIRED = "wasm-url-required", e;
9
9
  }({}), l = /* @__PURE__ */ function(e) {
10
10
  return e.ACTUAL = "Actual Size", e.PAGE_FIT = "Page Fit", e.PAGE_WIDTH = "Page Width", e;
11
11
  }({}), u = /* @__PURE__ */ function(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf-kit/viewer",
3
- "version": "2.7.3",
3
+ "version": "2.7.4-rc.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": [