@react-pdf-kit/viewer 2.7.3 → 2.7.4-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.
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 +1 -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 +66 -57
  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
@@ -3,53 +3,60 @@ 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
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";
6
+ import { BROWSER_NOT_SUPPORTED_MESSAGE as i, INVALID_OR_CORRUPTED_PDF_MESSAGE as a, WASM_URL_REQUIRED_MESSAGE as o } from "../const.js";
7
+ import { useEffect as s, useRef as c, useState as l } from "react";
8
+ import * as u from "pdfjs-dist";
9
9
  //#region lib/utils/hooks/useLoadPdf.ts
10
- function u(e) {
10
+ var d = new TextEncoder().encode("/JPXDecode");
11
+ function f(e) {
12
+ return e.some((t, n) => t === d[0] ? d.every((t, r) => e[n + r] === t) : !1);
13
+ }
14
+ function p(e) {
11
15
  let t = Error(a);
12
16
  return t.cause = e, t;
13
17
  }
14
- function d(e) {
18
+ function m() {
19
+ return Error(o);
20
+ }
21
+ function h(e) {
15
22
  let t = Error(i);
16
23
  return t.cause = e, t;
17
24
  }
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 = {
25
+ var g = (i, a, o = {}) => {
26
+ let [d, g] = l(), { workerUrlAdded: _, wasmUrl: v } = n(), [y, b] = l(/* @__PURE__ */ new Map()), x = c(), [S, C] = l(0), [w, T] = l(!1), [E, D] = l(), { password: O, passwordError: k, setPasswordError: A, passwordRequired: j, setPasswordRequired: M } = r(), { onLoadError: N, onLoaded: P, onLoadProgress: F, disableAutoFetch: I, disableStream: L, rangeChunkSize: R, withCredentials: z, httpHeaders: B } = o;
27
+ return s(() => {
28
+ F && F(S);
29
+ }, [S, F]), s(() => {
30
+ if (!_ || !i) return;
31
+ C(0), D(void 0), x.current = Date.now();
32
+ let t = x.current, n = {
26
33
  url: i,
27
34
  cMapPacked: a?.isCompressed ?? !0,
28
35
  ...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
36
+ ...O && { password: O },
37
+ ...I !== void 0 && { disableAutoFetch: I },
38
+ ...L !== void 0 && { disableStream: L },
39
+ ...R !== void 0 && { rangeChunkSize: R },
40
+ ...z !== void 0 && { withCredentials: z },
41
+ ...B !== void 0 && { httpHeaders: B },
42
+ ...v && { wasmUrl: v },
43
+ verbosity: u.VerbosityLevel.ERRORS
37
44
  };
38
45
  try {
39
- let r = l.getDocument(n);
46
+ let r = u.getDocument(n);
40
47
  r.onProgress = (e) => {
41
- if (t === y.current) {
48
+ if (t === x.current) {
42
49
  let { loaded: t, total: n } = e;
43
- x(n ? Math.min(100, Math.round(t / n * 100)) : 0);
50
+ C(n ? Math.min(100, Math.round(t / n * 100)) : 0);
44
51
  }
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) => {
52
+ }, T(!0), g(void 0);
53
+ let i = r.promise.then(async (n) => !v && f(await n.getData()) ? (t === x.current && (g(void 0), D(e.WASM_URL_REQUIRED)), N?.(m()), n) : (t === x.current && (g(n), C(100)), P && P(n), M(!1), A(""), n)).catch((t) => {
47
54
  if (t instanceof Error && t.name === "PasswordException") {
48
55
  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);
56
+ M(!0), e === u.PasswordResponses.INCORRECT_PASSWORD ? A("Incorrect password") : A(void 0);
57
+ } else t instanceof Error && t.name === "InvalidPDFException" && O ? (M(!0), A("Incorrect password")) : t instanceof Error && t.name === "InvalidPDFException" ? (D(e.INVALID_OR_CORRUPTED_PDF), N?.(p(t))) : N && N(t);
51
58
  }).finally(() => {
52
- C(!1);
59
+ T(!1);
53
60
  });
54
61
  return () => {
55
62
  i.finally(() => {
@@ -57,29 +64,31 @@ var f = (i, a, f = {}) => {
57
64
  });
58
65
  };
59
66
  } catch (t) {
60
- T(e.NOT_SUPPORTED), j?.(d(t));
67
+ D(e.NOT_SUPPORTED), N?.(h(t));
61
68
  }
62
69
  }, [
63
70
  i,
64
- h,
65
- g,
66
- E,
67
- j,
68
- M
69
- ]), o(() => {
70
- if (k) return;
71
+ _,
72
+ v,
73
+ O,
74
+ N,
75
+ P
76
+ ]), s(() => {
77
+ if (j) return;
71
78
  let n = /* @__PURE__ */ new Map();
72
- if (!p || S) {
73
- v(n);
79
+ if (!d || w) {
80
+ b(n);
74
81
  return;
75
82
  }
76
- let r = p.numPages, i = [];
83
+ let r = d.numPages, i = [];
77
84
  for (let e = 1; e <= r; e++) {
78
- let t = p.getPage(e);
85
+ let t = d.getPage(e);
79
86
  i.push(t);
80
87
  }
81
- Promise.all(i).then((e) => {
82
- e.map((e) => {
88
+ Promise.allSettled(i).then((e) => {
89
+ let r = e.filter((e) => e.status === "fulfilled").map((e) => e.value);
90
+ if (!r.length) throw e.find((e) => e.status === "rejected")?.reason;
91
+ r.map((e) => {
83
92
  let { thumbnailViewport: r, scale: i } = t(e), a = e.getViewport();
84
93
  n.set(e.pageNumber, {
85
94
  page: e,
@@ -87,24 +96,24 @@ var f = (i, a, f = {}) => {
87
96
  thumbnailScale: i,
88
97
  defaultRotation: a.rotation
89
98
  });
90
- }), v(n);
99
+ }), b(n);
91
100
  }).catch((t) => {
92
- m(void 0), T(e.INVALID_OR_CORRUPTED_PDF), j?.(u(t));
101
+ g(void 0), D(e.INVALID_OR_CORRUPTED_PDF), N?.(p(t));
93
102
  });
94
103
  }, [
95
- p,
96
- S,
97
- k,
98
- j
104
+ d,
105
+ w,
106
+ j,
107
+ N
99
108
  ]), {
100
- pdf: p,
101
- pages: _,
102
- loading: S,
103
- error: w,
104
- loadingProgress: b,
105
- passwordRequired: k,
106
- passwordError: D
109
+ pdf: d,
110
+ pages: y,
111
+ loading: w,
112
+ error: E,
113
+ loadingProgress: S,
114
+ passwordRequired: j,
115
+ passwordError: k
107
116
  };
108
117
  };
109
118
  //#endregion
110
- export { f as useLoadPdf };
119
+ export { g 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.0",
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": [