@pdf-viewer/react 1.6.0-beta.1 → 1.6.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 (77) hide show
  1. package/dist/RPDefaultLayout-4518b3d3.js +3059 -0
  2. package/dist/{SearchCloseButton-d6135e7c.js → SearchCloseButton-959cc1ed.js} +11 -11
  3. package/dist/assets/Container.css +1 -1
  4. package/dist/assets/PasswordModal.css +1 -0
  5. package/dist/assets/RPDefaultLayout.css +1 -1
  6. package/dist/assets/SearchCloseButton.css +1 -1
  7. package/dist/components/RPController.js +1 -1
  8. package/dist/components/RPPages.js +4 -2
  9. package/dist/components/RPProvider.js +13 -12
  10. package/dist/components/layout/Container.js +7 -6
  11. package/dist/components/layout/LayoutContainer.js +3 -2
  12. package/dist/components/layout/RPDefaultLayout.js +1 -1
  13. package/dist/components/layout/sidebar/RPSidebar.js +1 -1
  14. package/dist/components/layout/sidebar/Thumbnail.js +1 -1
  15. package/dist/components/layout/sidebar/Thumbnails.js +1 -1
  16. package/dist/components/layout/toolbar/DocumentDialog.js +3 -2
  17. package/dist/components/layout/toolbar/FileDownloadTool.js +1 -1
  18. package/dist/components/layout/toolbar/MostPageTool.js +3 -2
  19. package/dist/components/layout/toolbar/OtherTool.js +1 -1
  20. package/dist/components/layout/toolbar/Paginate.js +1 -1
  21. package/dist/components/layout/toolbar/PrintTool.js +1 -1
  22. package/dist/components/layout/toolbar/RPToolbar.js +1 -1
  23. package/dist/components/layout/toolbar/RPToolbarEnd.js +1 -1
  24. package/dist/components/layout/toolbar/SearchCloseButton.js +1 -1
  25. package/dist/components/layout/toolbar/SearchResultNavigator.js +2 -2
  26. package/dist/components/layout/toolbar/SearchTool.js +4 -3
  27. package/dist/components/layout/toolbar/ViewModeTool.js +18 -19
  28. package/dist/components/layout/toolbar/ZoomTool.js +7 -26
  29. package/dist/components/page/AnnotationLayer.js +3 -2
  30. package/dist/components/page/CanvasLayer.js +3 -2
  31. package/dist/components/page/DualPage.js +1 -1
  32. package/dist/components/page/RPPage.js +3 -2
  33. package/dist/components/page/SinglePage.js +1 -1
  34. package/dist/components/page/TextHighlightLayer.js +3 -2
  35. package/dist/components/page/TextLayer.js +3 -2
  36. package/dist/components/ui/LoadingIndicator.js +1 -1
  37. package/dist/components/ui/PasswordModal.js +58 -0
  38. package/dist/contexts/DocumentPasswordContext.js +40 -0
  39. package/dist/contexts/PaginationContext.js +1 -1
  40. package/dist/contexts/PrintContext.js +1 -1
  41. package/dist/contexts/RPDocumentContext.js +11 -8
  42. package/dist/contexts/SearchContext.js +1 -1
  43. package/dist/contexts/SmoothScrollContext.js +8 -9
  44. package/dist/contexts/ThumbnailsContext.js +1 -1
  45. package/dist/contexts/ToolbarComponentContext.js +2 -2
  46. package/dist/contexts/ViewModeContext.js +16 -17
  47. package/dist/contexts/ZoomContext.js +17 -16
  48. package/dist/main.js +1 -1
  49. package/dist/types/components/layout/toolbar/ViewModeTool.d.ts +1 -1
  50. package/dist/types/components/ui/PasswordModal.d.ts +3 -0
  51. package/dist/types/contexts/DocumentPasswordContext.d.ts +14 -0
  52. package/dist/types/contexts/SmoothScrollContext.d.ts +1 -3
  53. package/dist/types/utils/constants.d.ts +1 -0
  54. package/dist/types/utils/getScrollDistance.d.ts +1 -0
  55. package/dist/types/utils/getWordPositionInPage.d.ts +11 -0
  56. package/dist/types/utils/getZoomLevel.d.ts +2 -2
  57. package/dist/types/utils/hooks/useLoadPdf.d.ts +2 -0
  58. package/dist/types/utils/types.d.ts +20 -3
  59. package/dist/utils/constants.js +3 -2
  60. package/dist/utils/getScrollDistance.js +4 -0
  61. package/dist/utils/getWordPositionInPage.js +19 -0
  62. package/dist/utils/getZoomLevel.js +13 -9
  63. package/dist/utils/highlight.js +141 -126
  64. package/dist/utils/hooks/useFileDownload.js +3 -2
  65. package/dist/utils/hooks/useLicense.js +18 -18
  66. package/dist/utils/hooks/useLoadPdf.js +52 -40
  67. package/dist/utils/hooks/usePaginate.js +4 -2
  68. package/dist/utils/hooks/usePinch.js +68 -17
  69. package/dist/utils/hooks/usePresentPage.js +3 -2
  70. package/dist/utils/hooks/usePrint.js +3 -2
  71. package/dist/utils/hooks/useScrollToPage.js +4 -2
  72. package/dist/utils/hooks/useSearch.js +5 -3
  73. package/dist/utils/hooks/useThumbnail.js +3 -2
  74. package/dist/utils/hooks/useVirtualReactWindow.js +3 -2
  75. package/dist/utils/types.js +4 -4
  76. package/package.json +1 -1
  77. package/dist/RPDefaultLayout-3a892bb5.js +0 -3041
@@ -1,205 +1,220 @@
1
- import { getCharacterType as D } from "./charators.js";
2
- function H(d, c, l, s) {
1
+ import { getCharacterType as X } from "./charators.js";
2
+ function V(r, c, a, i) {
3
3
  const o = [];
4
- for (const n of d) {
5
- const i = X(c, n, s);
6
- o.push(..._(i, c, l));
4
+ for (const n of r) {
5
+ const s = y(c, n, i);
6
+ o.push(...I(s, c, a));
7
7
  }
8
8
  return o;
9
9
  }
10
- const L = (d, c) => {
11
- const l = ["g"];
12
- c.matchCase || l.push("i");
13
- let o = d.replace(/[.^$*+?()[{|\\]/g, (n) => `\\${n}`).trim();
14
- return new RegExp(o, l.join(""));
10
+ const D = (r, c) => {
11
+ const a = ["g"];
12
+ c.matchCase || a.push("i");
13
+ let o = r.replace(/[.^$*+?()[{|\\]/g, (n) => `\\${n}`).trim();
14
+ return new RegExp(o, a.join(""));
15
15
  };
16
- function X(d, c, l) {
17
- const s = [];
18
- for (const t of d.items)
16
+ function y(r, c, a) {
17
+ const i = [];
18
+ for (const t of r.items)
19
19
  if (t.hasEOL)
20
20
  if (t.str.endsWith("-")) {
21
- const a = t.str.lastIndexOf("-");
22
- s.push(t.str.substring(0, a));
21
+ const l = t.str.lastIndexOf("-");
22
+ i.push(t.str.substring(0, l));
23
23
  } else
24
- s.push(t.str, `
24
+ i.push(t.str, `
25
25
  `);
26
26
  else
27
- s.push(t.str);
28
- const o = s.join("").replace(/\n/g, " ");
27
+ i.push(t.str);
28
+ const o = i.join("").replace(/\n/g, " ");
29
29
  let n;
30
- c instanceof RegExp ? n = c.flags.indexOf("g") === -1 ? new RegExp(c, `${c.flags}g`) : c : n = L(c, l);
31
- const i = [];
30
+ c instanceof RegExp ? n = c.flags.indexOf("g") === -1 ? new RegExp(c, `${c.flags}g`) : c : n = D(c, a);
31
+ const s = [];
32
32
  let e;
33
33
  for (; (e = n.exec(o)) !== null; )
34
- l.wholeWords && !w(o, e.index, e[0].length) || i.push([e.index, e[0].length, e[0]]);
35
- return i;
34
+ a.wholeWords && !L(o, e.index, e[0].length) || s.push([e.index, e[0].length, e[0]]);
35
+ return s;
36
36
  }
37
- function _(d, c, l) {
38
- function s(a) {
39
- return a.hasEOL ? a.str.endsWith("-") ? -1 : 1 : 0;
37
+ function I(r, c, a) {
38
+ function i(l) {
39
+ return l.hasEOL ? l.str.endsWith("-") ? -1 : 1 : 0;
40
40
  }
41
41
  let o = 0, n = 0;
42
- const i = c.items, e = i.length - 1, t = [];
43
- for (let a = 0; a < d.length; a++) {
44
- let r = d[a][0];
45
- for (; o !== e && r >= n + i[o].str.length; ) {
46
- const f = i[o];
47
- n += f.str.length + s(f), o++;
42
+ const s = c.items, e = s.length - 1, t = [];
43
+ for (let l = 0; l < r.length; l++) {
44
+ let d = r[l][0];
45
+ for (; o !== e && d >= n + s[o].str.length; ) {
46
+ const f = s[o];
47
+ n += f.str.length + i(f), o++;
48
48
  }
49
49
  const p = {
50
50
  idx: o,
51
- offset: r - n
51
+ offset: d - n
52
52
  };
53
- for (r += d[a][1]; o !== e && r > n + i[o].str.length; ) {
54
- const f = i[o];
55
- n += f.str.length + s(f), o++;
53
+ for (d += r[l][1]; o !== e && d > n + s[o].str.length; ) {
54
+ const f = s[o];
55
+ n += f.str.length + i(f), o++;
56
56
  }
57
57
  const m = {
58
58
  idx: o,
59
- offset: r - n
59
+ offset: d - n
60
60
  };
61
61
  t.push({
62
62
  start: p,
63
63
  end: m,
64
- str: d[a][2],
65
- oIndex: d[a][0],
66
- pageIndex: l
64
+ str: r[l][2],
65
+ oIndex: r[l][0],
66
+ pageIndex: a,
67
+ rect: {
68
+ left: 0,
69
+ top: 0,
70
+ width: 0,
71
+ height: 0
72
+ }
67
73
  });
68
74
  }
75
+ for (const l of t) {
76
+ const d = s[l.start.idx], p = s[l.end.idx], m = d.transform[4], f = d.transform[5], E = m + d.width * l.start.offset / d.str.length, h = f, b = m + p.width * l.end.offset / p.str.length, N = f, u = {
77
+ left: Math.min(E, b),
78
+ top: Math.min(h, N),
79
+ width: Math.abs(b - E),
80
+ height: Math.max(d.height, p.height)
81
+ };
82
+ l.rect = u;
83
+ }
69
84
  return t;
70
85
  }
71
- function w(d, c, l) {
72
- let s = d.slice(0, c).match(/([^\p{M}])\p{M}*$/u);
73
- if (s) {
74
- const o = d.charCodeAt(c), n = s[1].charCodeAt(0);
75
- if (D(o) === D(n))
86
+ function L(r, c, a) {
87
+ let i = r.slice(0, c).match(/([^\p{M}])\p{M}*$/u);
88
+ if (i) {
89
+ const o = r.charCodeAt(c), n = i[1].charCodeAt(0);
90
+ if (X(o) === X(n))
76
91
  return !1;
77
92
  }
78
- if (s = d.slice(c + l).match(/^\p{M}*([^\p{M}])/u), s) {
79
- const o = d.charCodeAt(c + l - 1), n = s[1].charCodeAt(0);
80
- if (D(o) === D(n))
93
+ if (i = r.slice(c + a).match(/^\p{M}*([^\p{M}])/u), i) {
94
+ const o = r.charCodeAt(c + a - 1), n = i[1].charCodeAt(0);
95
+ if (X(o) === X(n))
81
96
  return !1;
82
97
  }
83
98
  return !0;
84
99
  }
85
- function I(d, c, l) {
86
- const s = [];
87
- function o(n, i, e = -1, t = -1, a = "") {
88
- const r = c.items[n], p = [];
89
- let m = "", f = "", b = "", u = l[n];
90
- if (!u)
100
+ function H(r, c, a) {
101
+ const i = [];
102
+ function o(n, s, e = -1, t = -1, l = "") {
103
+ const d = c.items[n], p = [];
104
+ let m = "", f = "", E = "", h = a[n];
105
+ if (!h)
91
106
  return;
92
- if (u.nodeType === Node.TEXT_NODE) {
93
- const g = document.createElement("span");
94
- u.before(g), g.append(u), l[n] = g, u = g;
107
+ if (h.nodeType === Node.TEXT_NODE) {
108
+ const u = document.createElement("span");
109
+ h.before(u), u.append(h), a[n] = u, h = u;
95
110
  }
96
- e >= 0 && t >= 0 ? m = r.str.substring(e, t) : e < 0 && t < 0 ? m = r.str : e >= 0 ? m = r.str.substring(e) : t >= 0 && (m = r.str.substring(0, t));
97
- const y = document.createTextNode(m), N = document.createElement("span");
98
- if (N.className = "highlight appended " + a, N.setAttribute("data-match-index", `${i}`), N.append(y), p.push(N), s.push({ element: N, index: i }), e > 0)
99
- if (u.childNodes.length === 1 && u.childNodes[0].nodeType === Node.TEXT_NODE) {
100
- f = r.str.substring(0, e);
101
- const g = document.createTextNode(f);
102
- p.unshift(g);
111
+ e >= 0 && t >= 0 ? m = d.str.substring(e, t) : e < 0 && t < 0 ? m = d.str : e >= 0 ? m = d.str.substring(e) : t >= 0 && (m = d.str.substring(0, t));
112
+ const b = document.createTextNode(m), N = document.createElement("span");
113
+ if (N.className = "highlight appended " + l, N.setAttribute("data-match-index", `${s}`), N.append(b), p.push(N), i.push({ element: N, index: s }), e > 0)
114
+ if (h.childNodes.length === 1 && h.childNodes[0].nodeType === Node.TEXT_NODE) {
115
+ f = d.str.substring(0, e);
116
+ const u = document.createTextNode(f);
117
+ p.unshift(u);
103
118
  } else {
104
- let g = 0;
105
- const E = [];
106
- for (const h of u.childNodes) {
107
- const x = h.nodeType === Node.TEXT_NODE ? h.nodeValue : h.firstChild.nodeValue;
108
- g += x.length, g <= e ? E.push(h) : e >= g - x.length && t <= g && E.push(
119
+ let u = 0;
120
+ const C = [];
121
+ for (const g of h.childNodes) {
122
+ const x = g.nodeType === Node.TEXT_NODE ? g.nodeValue : g.firstChild.nodeValue;
123
+ u += x.length, u <= e ? C.push(g) : e >= u - x.length && t <= u && C.push(
109
124
  document.createTextNode(
110
- x.substring(0, e - (g - x.length))
125
+ x.substring(0, e - (u - x.length))
111
126
  )
112
127
  );
113
128
  }
114
- p.unshift(...E);
129
+ p.unshift(...C);
115
130
  }
116
131
  if (t > 0) {
117
- b = r.str.substring(t);
118
- const g = document.createTextNode(b);
119
- p.push(g);
132
+ E = d.str.substring(t);
133
+ const u = document.createTextNode(E);
134
+ p.push(u);
120
135
  }
121
- u.replaceChildren(...p);
136
+ h.replaceChildren(...p);
122
137
  }
123
- for (const [n, i] of d.entries())
124
- if (i.start.idx === i.end.idx)
125
- o(i.start.idx, n, i.start.offset, i.end.offset);
138
+ for (const [n, s] of r.entries())
139
+ if (s.start.idx === s.end.idx)
140
+ o(s.start.idx, n, s.start.offset, s.end.offset);
126
141
  else
127
- for (let e = i.start.idx, t = i.end.idx; e <= t; e++)
128
- e === i.start.idx ? o(e, n, i.start.offset, -1, "begin") : e === i.end.idx ? o(e, n, -1, i.end.offset, "end") : o(e, n, -1, -1, "middle");
129
- return s;
142
+ for (let e = s.start.idx, t = s.end.idx; e <= t; e++)
143
+ e === s.start.idx ? o(e, n, s.start.offset, -1, "begin") : e === s.end.idx ? o(e, n, -1, s.end.offset, "end") : o(e, n, -1, -1, "middle");
144
+ return i;
130
145
  }
131
- function R(d, c) {
132
- const l = d.items.map((s) => s.str);
133
- for (let s = 0; s < c.length; s++) {
134
- const o = c[s];
146
+ function R(r, c) {
147
+ const a = r.items.map((i) => i.str);
148
+ for (let i = 0; i < c.length; i++) {
149
+ const o = c[i];
135
150
  if (o && o.nodeType !== Node.TEXT_NODE) {
136
- const n = document.createTextNode(l[s]);
151
+ const n = document.createTextNode(a[i]);
137
152
  o.replaceChildren(n);
138
153
  }
139
154
  }
140
155
  }
141
- function W(d = {}) {
142
- return { matchCase: !1, wholeWords: !1, ...d };
156
+ function W(r = {}) {
157
+ return { matchCase: !1, wholeWords: !1, ...r };
143
158
  }
144
- function A(d, c, l) {
145
- const s = [];
146
- function o(n, i, e = -1, t = -1, a) {
147
- var g, E;
148
- const r = c.items[n], p = [];
149
- let m = "", f = "", b = "", u = l[n];
150
- if (!u)
159
+ function A(r, c, a) {
160
+ const i = [];
161
+ function o(n, s, e = -1, t = -1, l) {
162
+ var u, C;
163
+ const d = c.items[n], p = [];
164
+ let m = "", f = "", E = "", h = a[n];
165
+ if (!h)
151
166
  return;
152
- e >= 0 && t >= 0 ? m = r.str.substring(e, t) : e < 0 && t < 0 ? m = r.str : e >= 0 ? m = r.str.substring(e) : t >= 0 && (m = r.str.substring(0, t));
153
- const y = document.createTextNode(m), N = document.createElement("span");
154
- if (N.style.background = a, N.append(y), p.push(N), e > 0)
155
- if (u.childNodes.length === 1 && u.childNodes[0].nodeType === Node.TEXT_NODE) {
156
- f = r.str.substring(0, e);
157
- const h = document.createTextNode(f);
158
- p.unshift(h);
167
+ e >= 0 && t >= 0 ? m = d.str.substring(e, t) : e < 0 && t < 0 ? m = d.str : e >= 0 ? m = d.str.substring(e) : t >= 0 && (m = d.str.substring(0, t));
168
+ const b = document.createTextNode(m), N = document.createElement("span");
169
+ if (N.style.background = l, N.append(b), p.push(N), e > 0)
170
+ if (h.childNodes.length === 1 && h.childNodes[0].nodeType === Node.TEXT_NODE) {
171
+ f = d.str.substring(0, e);
172
+ const g = document.createTextNode(f);
173
+ p.unshift(g);
159
174
  } else {
160
- let h = 0;
175
+ let g = 0;
161
176
  const x = [];
162
- for (const T of u.childNodes) {
163
- const v = T.nodeType === Node.TEXT_NODE ? T.nodeValue || "" : ((g = T.firstChild) == null ? void 0 : g.nodeValue) || "", C = v.length;
164
- if (h += C, h <= e)
177
+ for (const T of h.childNodes) {
178
+ const v = T.nodeType === Node.TEXT_NODE ? T.nodeValue || "" : ((u = T.firstChild) == null ? void 0 : u.nodeValue) || "", M = v.length;
179
+ if (g += M, g <= e)
165
180
  x.push(T);
166
- else if (e >= h - C && t <= h) {
167
- const M = v.substring(0, e - (h - C));
168
- x.push(document.createTextNode(M));
181
+ else if (e >= g - M && t <= g) {
182
+ const w = v.substring(0, e - (g - M));
183
+ x.push(document.createTextNode(w));
169
184
  }
170
185
  }
171
186
  p.unshift(...x);
172
187
  }
173
188
  if (t > 0)
174
- if (u.childNodes.length === 1 && u.childNodes[0].nodeType === Node.TEXT_NODE) {
175
- b = r.str.substring(t);
176
- const h = document.createTextNode(b);
177
- p.push(h);
189
+ if (h.childNodes.length === 1 && h.childNodes[0].nodeType === Node.TEXT_NODE) {
190
+ E = d.str.substring(t);
191
+ const g = document.createTextNode(E);
192
+ p.push(g);
178
193
  } else {
179
- let h = 0;
194
+ let g = 0;
180
195
  const x = [];
181
- for (const T of u.childNodes) {
182
- h >= t && x.push(T);
183
- const v = T.nodeType === Node.TEXT_NODE ? T.nodeValue || "" : ((E = T.firstChild) == null ? void 0 : E.nodeValue) || "", C = v.length;
184
- if (h += C, h > t) {
185
- const M = v.substring(t - (h - C));
186
- M && x.push(document.createTextNode(M));
196
+ for (const T of h.childNodes) {
197
+ g >= t && x.push(T);
198
+ const v = T.nodeType === Node.TEXT_NODE ? T.nodeValue || "" : ((C = T.firstChild) == null ? void 0 : C.nodeValue) || "", M = v.length;
199
+ if (g += M, g > t) {
200
+ const w = v.substring(t - (g - M));
201
+ w && x.push(document.createTextNode(w));
187
202
  }
188
203
  }
189
204
  x.length > 0 && p.push(...x);
190
205
  }
191
- u.replaceChildren(...p), s.push({ element: N, index: i });
206
+ h.replaceChildren(...p), i.push({ element: N, index: s });
192
207
  }
193
- for (const [n, i] of d.entries()) {
194
- const { start: e, end: t, color: a } = i;
195
- e.idx === t.idx && o(e.idx, n, e.offset, t.offset, a);
208
+ for (const [n, s] of r.entries()) {
209
+ const { start: e, end: t, color: l } = s;
210
+ e.idx === t.idx && o(e.idx, n, e.offset, t.offset, l);
196
211
  }
197
- return s;
212
+ return i;
198
213
  }
199
214
  export {
200
- H as findMatches,
215
+ V as findMatches,
201
216
  W as getHighlightOptionsWithDefaults,
202
- I as highlightMatches,
217
+ H as highlightMatches,
203
218
  A as highlightMultipleColorMatches,
204
219
  R as resetDivs
205
220
  };
@@ -1,7 +1,8 @@
1
1
  import "react/jsx-runtime";
2
2
  import "react";
3
3
  import "../../contexts/RPDocumentContext.js";
4
- import { c as C } from "../../RPDefaultLayout-3a892bb5.js";
4
+ import "../../contexts/DocumentPasswordContext.js";
5
+ import { c as E } from "../../RPDefaultLayout-4518b3d3.js";
5
6
  import "../../contexts/DarkModeContext.js";
6
7
  import "../../contexts/RotationContext.js";
7
8
  import "../../contexts/LayerContext.js";
@@ -28,5 +29,5 @@ import "../../contexts/ThemeContext.js";
28
29
  import "../../components/RPDropFileZone.js";
29
30
  import "../../contexts/ToolbarComponentContext.js";
30
31
  export {
31
- C as useFileDownload
32
+ E as useFileDownload
32
33
  };
@@ -1,6 +1,6 @@
1
- import { useState as E, useCallback as h, useEffect as A } from "react";
1
+ import { useState as g, useCallback as h, useEffect as A } from "react";
2
2
  import { appConsole as c } from "../appConsole.js";
3
- const b = /* @__PURE__ */ new Date("2025-05-15T03:02:24.859Z"), l = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", o = {
3
+ const b = /* @__PURE__ */ new Date("2025-05-21T03:38:50.505Z"), l = "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. ${l}`,
5
5
  mismatchedDomain: `Your license key is not valid for the current domain / IP. ${l}`,
6
6
  expired: `Your license key has expired. ${l}`,
@@ -44,20 +44,20 @@ kwIDAQAB
44
44
  // Convert signature to ArrayBuffer
45
45
  new TextEncoder().encode(atob(e))
46
46
  ))
47
- throw new Error(o.invalidSignature);
47
+ throw new Error(s.invalidSignature);
48
48
  return JSON.parse(atob(e));
49
49
  } catch {
50
- throw new Error(o.invalidLicense);
50
+ throw new Error(s.invalidLicense);
51
51
  }
52
52
  }
53
53
  const y = (r, t) => r === "specific" ? t === window.location.host : window.location.host.includes(t), d = {
54
54
  isValid: !0,
55
- invalidatedMessage: o.invalidLicense,
55
+ invalidatedMessage: s.invalidLicense,
56
56
  type: void 0
57
57
  }, x = (r) => {
58
- const [t, e] = E(d), n = h(async () => {
58
+ const [t, e] = g(d), n = h(async () => {
59
59
  if (!r)
60
- throw e(d), new Error("License is missing");
60
+ throw e(d), new Error(s.invalidLicense);
61
61
  let i;
62
62
  try {
63
63
  i = await I(r);
@@ -65,35 +65,35 @@ const y = (r, t) => r === "specific" ? t === window.location.host : window.locat
65
65
  throw c.warn(m.message), new Error(m.message);
66
66
  }
67
67
  c.debug(">>> validatedLicense", i);
68
- const { avu: a, exp: s, dmt: w, dm: p, t: f } = i;
69
- if (!s)
68
+ const { avu: a, exp: o, dmt: w, dm: p, t: v } = i;
69
+ if (!o)
70
70
  throw new Error("License is missing expiration timestamp");
71
- if (s > Number.MAX_SAFE_INTEGER / 1e3)
71
+ if (o > Number.MAX_SAFE_INTEGER / 1e3)
72
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);
73
+ const f = new Date(o * 1e3), E = (/* @__PURE__ */ new Date()).getTime();
74
+ if (f.getTime() < E)
75
+ throw new Error(s.expired);
76
76
  if (!a)
77
77
  throw new Error("License is missing available until version timestamp");
78
78
  if (a > Number.MAX_SAFE_INTEGER / 1e3)
79
79
  throw new Error("Invalid available until version timestamp: value too large");
80
80
  const u = new Date(a * 1e3);
81
81
  if (c.debug("availableUntilTimestamp", u), u.getTime() < b.getTime())
82
- throw new Error(o.exceededVersion);
82
+ throw new Error(s.exceededVersion);
83
83
  if (!y(w, p))
84
- throw new Error(o.mismatchedDomain);
84
+ throw new Error(s.mismatchedDomain);
85
85
  return {
86
86
  isValid: !0,
87
- type: f,
87
+ type: v,
88
88
  invalidatedMessage: void 0
89
89
  };
90
90
  }, [r]);
91
91
  return A(() => {
92
- n().then(({ isValid: i, type: a, invalidatedMessage: s }) => {
92
+ n().then(({ isValid: i, type: a, invalidatedMessage: o }) => {
93
93
  e({
94
94
  isValid: i,
95
95
  type: a,
96
- invalidatedMessage: s
96
+ invalidatedMessage: o
97
97
  });
98
98
  }).catch((i) => {
99
99
  e({
@@ -1,58 +1,70 @@
1
- import { useState as u, useRef as x, useEffect as L } from "react";
2
- import * as p from "pdfjs-dist";
3
- import { getThumbnailViewport as E } from "../getThumbnailViewport.js";
4
- import { useConfigContext as I } from "../../contexts/ConfigContext.js";
5
- const V = (d, e, y = {}) => {
6
- const [r, C] = u(), { workerUrlAdded: w } = I(), [T, b] = u(/* @__PURE__ */ new Map()), i = x(), [j, f] = u(0), [g, k] = u(!1), { onLoadError: m, onLoaded: a } = y;
7
- return L(() => {
8
- if (!w || !d)
1
+ import { useState as f, useRef as D, useEffect as C } from "react";
2
+ import * as k from "pdfjs-dist";
3
+ import { getThumbnailViewport as N } from "../getThumbnailViewport.js";
4
+ import { useConfigContext as S } from "../../contexts/ConfigContext.js";
5
+ import { useDocumentPasswordContext as U } from "../../contexts/DocumentPasswordContext.js";
6
+ const z = (m, o, I = {}) => {
7
+ const [r, q] = f(), { workerUrlAdded: x } = S(), [v, L] = f(/* @__PURE__ */ new Map()), i = D(), [R, g] = f(0), [P, y] = f(!1), {
8
+ password: d,
9
+ passwordError: T,
10
+ setPasswordError: u,
11
+ passwordRequired: c,
12
+ setPasswordRequired: a
13
+ } = U(), { onLoadError: p, onLoaded: w } = I;
14
+ return C(() => {
15
+ if (!x || !m)
9
16
  return;
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 }
17
+ g(0), a(!1), u(""), i.current = Date.now();
18
+ const t = i.current, E = {
19
+ url: m,
20
+ cMapPacked: (o == null ? void 0 : o.isCompressed) ?? !0,
21
+ ...(o == null ? void 0 : o.url) && { cMapUrl: o.url },
22
+ ...d && { password: d }
15
23
  };
16
- console.log("currently pdfjs version", p.version, p);
17
- const n = p.getDocument(P);
18
- n.onProgress = (o) => {
24
+ console.log("currently pdfjs version", k.version, k);
25
+ const n = k.getDocument(E);
26
+ n.onProgress = (s) => {
19
27
  if (t === i.current) {
20
- const { loaded: c, total: l } = o, v = l ? Math.min(100, Math.round(c / l * 100)) : 0;
21
- f(v);
28
+ const { loaded: b, total: l } = s, j = l ? Math.min(100, Math.round(b / l * 100)) : 0;
29
+ g(j);
22
30
  }
23
- }, k(!0), f(0);
24
- const s = n.promise.then((o) => (t === i.current && (C(o), f(100)), a && a(o), o)).catch((o) => {
25
- m && m(o);
26
- }).finally(() => k(!1));
31
+ }, y(!0);
32
+ const e = n.promise.then((s) => (t === i.current && (q(s), g(100)), w && w(s), a(!1), u(""), s)).catch((s) => {
33
+ s instanceof Error && s.name === "PasswordException" ? (a(!0), u(s.message || "Password required")) : s instanceof Error && s.name === "InvalidPDFException" && d ? (a(!0), u("Incorrect password")) : p && p(s);
34
+ }).finally(() => y(!1));
27
35
  return () => {
28
- s.finally(() => {
36
+ e.finally(() => {
29
37
  n.destroy();
30
38
  });
31
39
  };
32
- }, [d, w, m, a]), L(() => {
40
+ }, [m, x, d, p, w]), C(() => {
41
+ if (c)
42
+ return;
33
43
  const t = /* @__PURE__ */ new Map();
34
- if (!r || g) {
35
- b(t);
44
+ if (!r || P) {
45
+ L(t);
36
46
  return;
37
47
  }
38
- const P = r.numPages, n = [];
39
- for (let s = 1; s <= P; s++) {
40
- const o = r.getPage(s);
41
- n.push(o);
48
+ const E = r.numPages, n = [];
49
+ for (let e = 1; e <= E; e++) {
50
+ const s = r.getPage(e);
51
+ n.push(s);
42
52
  }
43
- Promise.all(n).then((s) => {
44
- s.map((o) => {
45
- const { thumbnailViewport: c, scale: l } = E(o);
46
- t.set(o.pageNumber, { page: o, thumbnailViewport: c, thumbnailScale: l });
47
- }), b(t);
53
+ Promise.all(n).then((e) => {
54
+ e.map((s) => {
55
+ const { thumbnailViewport: b, scale: l } = N(s);
56
+ t.set(s.pageNumber, { page: s, thumbnailViewport: b, thumbnailScale: l });
57
+ }), L(t);
48
58
  });
49
- }, [r, g]), {
59
+ }, [r, P, c]), {
50
60
  pdf: r,
51
- pages: T,
52
- loading: g,
53
- loadingProgress: j
61
+ pages: v,
62
+ loading: P,
63
+ loadingProgress: R,
64
+ passwordRequired: c,
65
+ passwordError: T
54
66
  };
55
67
  };
56
68
  export {
57
- V as useLoadPdf
69
+ z as useLoadPdf
58
70
  };
@@ -1,7 +1,9 @@
1
1
  import "react";
2
- import { g as E } from "../../RPDefaultLayout-3a892bb5.js";
2
+ import "../types.js";
3
+ import { g as G } from "../../RPDefaultLayout-4518b3d3.js";
3
4
  import "react/jsx-runtime";
4
5
  import "../../contexts/RPDocumentContext.js";
6
+ import "../../contexts/DocumentPasswordContext.js";
5
7
  import "../../contexts/DarkModeContext.js";
6
8
  import "../../contexts/RotationContext.js";
7
9
  import "../../contexts/LayerContext.js";
@@ -29,5 +31,5 @@ import "../../components/RPDropFileZone.js";
29
31
  import "../../contexts/ToolbarComponentContext.js";
30
32
  import "./useDebounce.js";
31
33
  export {
32
- E as usePaginate
34
+ G as usePaginate
33
35
  };