pdf-tsx 0.16.1 → 0.16.2

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.
@@ -3,262 +3,262 @@ import { useScrollTracking as t } from "../hooks/useScrollTracking.js";
3
3
  import { useKeyboardShortcuts as n } from "../hooks/useKeyboardShortcuts.js";
4
4
  import { useTextLayer as r } from "../hooks/useTextLayer.js";
5
5
  import { isSafeUrl as i } from "../utils/url.js";
6
- import { useAnnotationLayer as ee } from "../hooks/useAnnotationLayer.js";
7
- import { usePDFLoader as te } from "../hooks/usePDFLoader.js";
8
- import { usePDFRenderer as ne } from "../hooks/usePDFRenderer.js";
9
- import { useOverlayRects as re } from "../hooks/useOverlayRects.js";
10
- import { computeFit as a } from "../utils/pdfFit.js";
11
- import { ThemeProvider as ie } from "../context/ThemeContext.js";
12
- import { LabelsProvider as ae } from "../context/LabelsContext.js";
13
- import { useLabels as o } from "../hooks/useLabels.js";
14
- import s from "./PDFViewer.module.js";
15
- import { useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
16
- import * as oe from "pdfjs-dist";
17
- import { Fragment as se, jsx as p, jsxs as m } from "react/jsx-runtime";
6
+ import { useAnnotationLayer as a } from "../hooks/useAnnotationLayer.js";
7
+ import { usePDFLoader as ee } from "../hooks/usePDFLoader.js";
8
+ import { usePDFRenderer as te } from "../hooks/usePDFRenderer.js";
9
+ import { useOverlayRects as ne } from "../hooks/useOverlayRects.js";
10
+ import { computeFit as o } from "../utils/pdfFit.js";
11
+ import { ThemeProvider as re } from "../context/ThemeContext.js";
12
+ import { LabelsProvider as ie } from "../context/LabelsContext.js";
13
+ import { useLabels as s } from "../hooks/useLabels.js";
14
+ import c from "./PDFViewer.module.js";
15
+ import { useCallback as l, useEffect as u, useMemo as d, useRef as f, useState as p } from "react";
16
+ import * as ae from "pdfjs-dist";
17
+ import { Fragment as oe, jsx as m, jsxs as h } from "react/jsx-runtime";
18
18
  //#region src/components/PDFViewer.tsx
19
- var h = 2;
20
- function ce({ hasRead: e }) {
21
- let t = o();
22
- return /* @__PURE__ */ m("div", {
23
- className: `${s.requireReadBanner} ${e ? s.requireReadDone : ""}`,
24
- children: [e ? /* @__PURE__ */ p("svg", {
19
+ var g = 2;
20
+ function se({ hasRead: e }) {
21
+ let t = s();
22
+ return /* @__PURE__ */ h("div", {
23
+ className: `${c.requireReadBanner} ${e ? c.requireReadDone : ""}`,
24
+ children: [e ? /* @__PURE__ */ m("svg", {
25
25
  width: "16",
26
26
  height: "16",
27
27
  viewBox: "0 0 16 16",
28
28
  fill: "none",
29
29
  "aria-hidden": "true",
30
- children: /* @__PURE__ */ p("path", {
30
+ children: /* @__PURE__ */ m("path", {
31
31
  d: "M3 8l3.5 3.5L13 4.5",
32
32
  stroke: "currentColor",
33
33
  strokeWidth: "2",
34
34
  strokeLinecap: "round",
35
35
  strokeLinejoin: "round"
36
36
  })
37
- }) : /* @__PURE__ */ p("svg", {
37
+ }) : /* @__PURE__ */ m("svg", {
38
38
  width: "16",
39
39
  height: "16",
40
40
  viewBox: "0 0 16 16",
41
41
  fill: "none",
42
42
  "aria-hidden": "true",
43
- children: /* @__PURE__ */ p("path", {
43
+ children: /* @__PURE__ */ m("path", {
44
44
  d: "M8 3v10M4 9l4 4 4-4",
45
45
  stroke: "currentColor",
46
46
  strokeWidth: "2",
47
47
  strokeLinecap: "round",
48
48
  strokeLinejoin: "round"
49
49
  })
50
- }), /* @__PURE__ */ p("span", { children: e ? t.requireReadDone : t.requireReadPending })]
50
+ }), /* @__PURE__ */ m("span", { children: e ? t.requireReadDone : t.requireReadPending })]
51
51
  });
52
52
  }
53
- var g = ({ file: o, workerSrc: g, sidebar: le, toolbar: _, onChangeFile: v, themeOverrides: ue, defaultTheme: de, defaultFit: y, language: fe, className: b, style: pe, requireRead: x, onDocumentRead: S }) => {
54
- l(() => {
55
- oe.GlobalWorkerOptions.workerSrc = g;
56
- }, [g]);
57
- let [C, w] = f(1), [T, E] = f(0), [D, O] = f(null), [k, me] = f([]), [A, he] = f(!1), [j, ge] = f(y ?? null), [M, N] = f(null), [P, F] = f(!1), I = d(!1), L = d(null), R = d([]), z = d([]), B = d(T);
58
- l(() => {
59
- B.current = T;
60
- }, [T]);
61
- let [_e, ve] = f(null);
62
- _e !== o && (ve(o), O(null), F(!1)), l(() => {
63
- I.current = !1;
64
- }, [o]);
65
- let { pdf: V, numPages: H, loading: ye } = te(o);
66
- l(() => {
67
- V && (R.current = Array(V.numPages).fill(null), z.current = Array(V.numPages).fill(null));
68
- }, [V]), l(() => {
69
- !V || !y || !L.current || a(y, V, L.current, B.current).then(w);
70
- }, [V, y]);
71
- let U = d(j);
72
- l(() => {
73
- U.current = j;
74
- }, [j]), l(() => {
75
- if (!V || !L.current) return;
76
- let e = L.current, t = new ResizeObserver(() => {
77
- U.current && a(U.current, V, e, B.current).then(w);
53
+ var _ = ({ file: s, workerSrc: _, sidebar: ce, toolbar: v, onChangeFile: y, themeOverrides: le, defaultTheme: ue, defaultFit: b, language: de, className: x, style: fe, requireRead: S, onDocumentRead: C, wasmUrl: pe }) => {
54
+ u(() => {
55
+ ae.GlobalWorkerOptions.workerSrc = _;
56
+ }, [_]);
57
+ let [w, T] = p(1), [E, D] = p(0), [O, k] = p(null), [A, me] = p([]), [j, he] = p(!1), [M, ge] = p(b ?? null), [N, P] = p(null), [F, I] = p(!1), L = f(!1), R = f(null), z = f([]), B = f([]), V = f(E);
58
+ u(() => {
59
+ V.current = E;
60
+ }, [E]);
61
+ let [_e, ve] = p(null);
62
+ _e !== s && (ve(s), k(null), I(!1)), u(() => {
63
+ L.current = !1;
64
+ }, [s]);
65
+ let { pdf: H, numPages: U, loading: ye } = ee(s, pe);
66
+ u(() => {
67
+ H && (z.current = Array(H.numPages).fill(null), B.current = Array(H.numPages).fill(null));
68
+ }, [H]), u(() => {
69
+ !H || !b || !R.current || o(b, H, R.current, V.current).then(T);
70
+ }, [H, b]);
71
+ let W = f(M);
72
+ u(() => {
73
+ W.current = M;
74
+ }, [M]), u(() => {
75
+ if (!H || !R.current) return;
76
+ let e = R.current, t = new ResizeObserver(() => {
77
+ W.current && o(W.current, H, e, V.current).then(T);
78
78
  });
79
79
  return t.observe(e), () => t.disconnect();
80
- }, [V]);
81
- let { currentPage: W, goToPage: G } = t({
82
- numPages: H,
83
- containerRef: L,
84
- pageRefs: R
80
+ }, [H]);
81
+ let { currentPage: G, goToPage: K } = t({
82
+ numPages: U,
83
+ containerRef: R,
84
+ pageRefs: z
85
85
  });
86
- l(() => {
87
- H === 0 || W < H || (x && !P && F(!0), I.current || (I.current = !0, S?.()));
86
+ u(() => {
87
+ U === 0 || G < U || (S && !F && I(!0), L.current || (L.current = !0, C?.()));
88
88
  }, [
89
- W,
90
- H,
91
- x,
92
- P,
93
- S
89
+ G,
90
+ U,
91
+ S,
92
+ F,
93
+ C
94
94
  ]);
95
- let K = u(() => {
96
- if (H === 0) return [];
97
- let e = /* @__PURE__ */ new Set(), t = Math.max(W - h, 1), n = Math.min(W + h, H);
95
+ let q = d(() => {
96
+ if (U === 0) return [];
97
+ let e = /* @__PURE__ */ new Set(), t = Math.max(G - g, 1), n = Math.min(G + g, U);
98
98
  for (let r = t; r <= n; r++) e.add(r);
99
- D && e.add(D.page);
100
- for (let t of k) e.add(t.page);
99
+ O && e.add(O.page);
100
+ for (let t of A) e.add(t.page);
101
101
  return Array.from(e).sort((e, t) => e - t);
102
102
  }, [
103
- W,
104
- H,
105
- D,
106
- k
107
- ]), { pageSizes: be, renderedPages: q } = ne({
108
- pdf: V,
109
- zoom: C,
110
- rotation: T,
111
- visiblePages: K,
112
- canvasRefs: z
113
- }), J = u(() => {
114
- let e = new Set(K);
115
- for (let t of q) e.add(t);
103
+ G,
104
+ U,
105
+ O,
106
+ A
107
+ ]), { pageSizes: be, renderedPages: J } = te({
108
+ pdf: H,
109
+ zoom: w,
110
+ rotation: E,
111
+ visiblePages: q,
112
+ canvasRefs: B
113
+ }), Y = d(() => {
114
+ let e = new Set(q);
115
+ for (let t of J) e.add(t);
116
116
  return Array.from(e).sort((e, t) => e - t);
117
- }, [K, q]);
117
+ }, [q, J]);
118
118
  n({
119
- pdf: V,
120
- currentPage: W,
121
- goToPage: G,
122
- setRotation: E
119
+ pdf: H,
120
+ currentPage: G,
121
+ goToPage: K,
122
+ setRotation: D
123
123
  });
124
124
  let xe = r({
125
- pdf: V,
126
- zoom: C,
127
- rotation: T,
128
- mountedPages: J,
129
- canvasRefs: z
130
- }), { linkOverlays: Se, noteOverlays: Ce } = ee({
131
- pdf: V,
132
- zoom: C,
133
- rotation: T,
134
- mountedPages: J,
135
- goToPage: G
125
+ pdf: H,
126
+ zoom: w,
127
+ rotation: E,
128
+ mountedPages: Y,
129
+ canvasRefs: B
130
+ }), { linkOverlays: Se, noteOverlays: Ce } = a({
131
+ pdf: H,
132
+ zoom: w,
133
+ rotation: E,
134
+ mountedPages: Y,
135
+ goToPage: K
136
136
  });
137
- l(() => {
138
- if (!M) return;
139
- let e = () => N(null), t = (e) => {
140
- e.key === "Escape" && N(null);
137
+ u(() => {
138
+ if (!N) return;
139
+ let e = () => P(null), t = (e) => {
140
+ e.key === "Escape" && P(null);
141
141
  };
142
142
  return document.addEventListener("click", e), document.addEventListener("keydown", t), () => {
143
143
  document.removeEventListener("click", e), document.removeEventListener("keydown", t);
144
144
  };
145
- }, [M]);
146
- let { overlayRect: Y, searchOverlays: we } = re({
147
- pdf: V,
148
- highlight: D,
149
- searchMatches: k,
150
- zoom: C,
151
- rotation: T
152
- }), Te = c((e, t) => {
145
+ }, [N]);
146
+ let { overlayRect: X, searchOverlays: we } = ne({
147
+ pdf: H,
148
+ highlight: O,
149
+ searchMatches: A,
150
+ zoom: w,
151
+ rotation: E
152
+ }), Te = l((e, t) => {
153
153
  (!e.url || !i(e.url)) && (t.preventDefault(), e.url || e._handleClick());
154
- }, []), X = d(null), Z = c((e, t) => {
155
- X.current && clearTimeout(X.current);
154
+ }, []), Z = f(null), Q = l((e, t) => {
155
+ Z.current && clearTimeout(Z.current);
156
156
  let n = t.clientY > window.innerHeight * .6;
157
- N({
157
+ P({
158
158
  x: Math.min(t.clientX, window.innerWidth - 304),
159
159
  y: n ? window.innerHeight - t.clientY + 8 : t.clientY + 12,
160
160
  above: n,
161
161
  contents: e.contents,
162
162
  title: e.title
163
163
  });
164
- }, []), Q = c(() => {
165
- X.current = setTimeout(() => N(null), 200);
166
- }, []), $ = c((e) => {
167
- O({
164
+ }, []), $ = l(() => {
165
+ Z.current = setTimeout(() => P(null), 200);
166
+ }, []), Ee = l((e) => {
167
+ k({
168
168
  page: e.page,
169
169
  pdfRect: e.pdfRect
170
- }), G(e.page);
171
- }, [O, G]), Ee = u(() => ({
172
- pdf: V,
173
- numPages: H,
174
- zoom: C,
175
- setZoom: w,
176
- rotation: T,
177
- setRotation: E,
178
- currentPage: W,
179
- goToPage: G,
180
- containerRef: L,
181
- canvasRefs: z,
182
- file: o,
183
- highlight: D,
184
- setHighlight: O,
185
- searchMatches: k,
170
+ }), K(e.page);
171
+ }, [k, K]), De = d(() => ({
172
+ pdf: H,
173
+ numPages: U,
174
+ zoom: w,
175
+ setZoom: T,
176
+ rotation: E,
177
+ setRotation: D,
178
+ currentPage: G,
179
+ goToPage: K,
180
+ containerRef: R,
181
+ canvasRefs: B,
182
+ file: s,
183
+ highlight: O,
184
+ setHighlight: k,
185
+ searchMatches: A,
186
186
  setSearchMatches: me,
187
- onChangeFile: v,
188
- sidebarCollapsed: A,
187
+ onChangeFile: y,
188
+ sidebarCollapsed: j,
189
189
  setSidebarCollapsed: he,
190
- fitMode: j,
190
+ fitMode: M,
191
191
  setFitMode: ge,
192
- navigationLocked: !!x && !P
192
+ navigationLocked: !!S && !F
193
193
  }), [
194
- V,
195
194
  H,
196
- C,
197
- T,
198
- W,
195
+ U,
196
+ w,
197
+ E,
199
198
  G,
200
- o,
201
- D,
202
- k,
203
- v,
199
+ K,
200
+ s,
201
+ O,
204
202
  A,
203
+ y,
205
204
  j,
206
- x,
207
- P
205
+ M,
206
+ S,
207
+ F
208
208
  ]);
209
- return /* @__PURE__ */ p(ie, {
210
- themeOverrides: ue,
211
- defaultTheme: de,
212
- children: /* @__PURE__ */ p(ae, {
213
- language: fe,
214
- children: /* @__PURE__ */ m(e.Provider, {
215
- value: Ee,
216
- children: [/* @__PURE__ */ m("div", {
217
- className: `${s.appLayout}${b ? ` ${b}` : ""}`,
218
- style: pe,
219
- children: [_ && /* @__PURE__ */ p("div", {
220
- className: s.toolbar,
221
- children: _
222
- }), /* @__PURE__ */ m("div", {
223
- className: s.body,
224
- children: [le, /* @__PURE__ */ m("div", {
225
- className: s.scrollContainer,
226
- ref: L,
209
+ return /* @__PURE__ */ m(re, {
210
+ themeOverrides: le,
211
+ defaultTheme: ue,
212
+ children: /* @__PURE__ */ m(ie, {
213
+ language: de,
214
+ children: /* @__PURE__ */ h(e.Provider, {
215
+ value: De,
216
+ children: [/* @__PURE__ */ h("div", {
217
+ className: `${c.appLayout}${x ? ` ${x}` : ""}`,
218
+ style: fe,
219
+ children: [v && /* @__PURE__ */ m("div", {
220
+ className: c.toolbar,
221
+ children: v
222
+ }), /* @__PURE__ */ h("div", {
223
+ className: c.body,
224
+ children: [ce, /* @__PURE__ */ h("div", {
225
+ className: c.scrollContainer,
226
+ ref: R,
227
227
  children: [
228
- ye && /* @__PURE__ */ p("div", { className: s.documentLoading }),
229
- Array.from({ length: H }, (e, t) => {
230
- let n = q.has(t + 1), r = be[t], ee = J.includes(t + 1);
231
- return /* @__PURE__ */ m("div", {
232
- className: s.pageWrapper,
228
+ ye && /* @__PURE__ */ m("div", { className: c.documentLoading }),
229
+ Array.from({ length: U }, (e, t) => {
230
+ let n = J.has(t + 1), r = be[t], a = Y.includes(t + 1);
231
+ return /* @__PURE__ */ h("div", {
232
+ className: c.pageWrapper,
233
233
  ref: (e) => {
234
- R.current[t] = e;
234
+ z.current[t] = e;
235
235
  },
236
236
  style: r ? {
237
237
  width: r.width,
238
238
  height: r.height
239
239
  } : void 0,
240
240
  children: [
241
- r && !n && /* @__PURE__ */ p("div", {
242
- className: s.pageSkeleton,
241
+ r && !n && /* @__PURE__ */ m("div", {
242
+ className: c.pageSkeleton,
243
243
  style: {
244
244
  width: r.width,
245
245
  height: r.height
246
246
  }
247
247
  }),
248
- ee && /* @__PURE__ */ m(se, { children: [/* @__PURE__ */ p("canvas", {
249
- className: s.pageCanvas,
248
+ a && /* @__PURE__ */ h(oe, { children: [/* @__PURE__ */ m("canvas", {
249
+ className: c.pageCanvas,
250
250
  ref: (e) => {
251
- z.current[t] = e;
251
+ B.current[t] = e;
252
252
  },
253
253
  style: { display: n ? "block" : "none" }
254
- }), /* @__PURE__ */ p("div", {
255
- className: `textLayer ${s.textLayer}`,
254
+ }), /* @__PURE__ */ m("div", {
255
+ className: `textLayer ${c.textLayer}`,
256
256
  ref: (e) => {
257
257
  xe.current[t] = e;
258
258
  }
259
259
  })] }),
260
- Se.filter((e) => e.page === t + 1).map((e, t) => /* @__PURE__ */ p("a", {
261
- className: s.linkOverlay,
260
+ Se.filter((e) => e.page === t + 1).map((e, t) => /* @__PURE__ */ m("a", {
261
+ className: c.linkOverlay,
262
262
  href: e.url && i(e.url) ? e.url : "#",
263
263
  target: "_blank",
264
264
  rel: "noopener noreferrer",
@@ -270,25 +270,25 @@ var g = ({ file: o, workerSrc: g, sidebar: le, toolbar: _, onChangeFile: v, them
270
270
  },
271
271
  onClick: (t) => Te(e, t)
272
272
  }, t)),
273
- Ce.filter((e) => e.page === t + 1).map((e, t) => e.subtype === "Text" ? /* @__PURE__ */ p("div", {
274
- className: s.noteIconOverlay,
273
+ Ce.filter((e) => e.page === t + 1).map((e, t) => e.subtype === "Text" ? /* @__PURE__ */ m("div", {
274
+ className: c.noteIconOverlay,
275
275
  style: {
276
276
  left: e.x,
277
277
  top: e.y,
278
278
  width: Math.max(e.width, 26),
279
279
  height: Math.max(e.height, 26)
280
280
  },
281
- onMouseEnter: (t) => Z(e, t),
282
- onMouseLeave: Q,
283
- onClick: () => $(e),
284
- children: /* @__PURE__ */ m("svg", {
281
+ onMouseEnter: (t) => Q(e, t),
282
+ onMouseLeave: $,
283
+ onClick: () => Ee(e),
284
+ children: /* @__PURE__ */ h("svg", {
285
285
  width: "22",
286
286
  height: "22",
287
287
  viewBox: "0 0 12 12",
288
288
  fill: "none",
289
289
  "aria-hidden": "true",
290
290
  children: [
291
- /* @__PURE__ */ p("rect", {
291
+ /* @__PURE__ */ m("rect", {
292
292
  x: "0.5",
293
293
  y: "0.5",
294
294
  width: "9",
@@ -298,13 +298,13 @@ var g = ({ file: o, workerSrc: g, sidebar: le, toolbar: _, onChangeFile: v, them
298
298
  stroke: "rgba(160,120,0,0.7)",
299
299
  strokeWidth: "1"
300
300
  }),
301
- /* @__PURE__ */ p("path", {
301
+ /* @__PURE__ */ m("path", {
302
302
  d: "M9.5 5.5v3l2.5-3z",
303
303
  fill: "rgba(255,210,0,0.9)",
304
304
  stroke: "rgba(160,120,0,0.7)",
305
305
  strokeWidth: "1"
306
306
  }),
307
- /* @__PURE__ */ p("line", {
307
+ /* @__PURE__ */ m("line", {
308
308
  x1: "2",
309
309
  y1: "3",
310
310
  x2: "8",
@@ -313,7 +313,7 @@ var g = ({ file: o, workerSrc: g, sidebar: le, toolbar: _, onChangeFile: v, them
313
313
  strokeWidth: "1",
314
314
  strokeLinecap: "round"
315
315
  }),
316
- /* @__PURE__ */ p("line", {
316
+ /* @__PURE__ */ m("line", {
317
317
  x1: "2",
318
318
  y1: "5.5",
319
319
  x2: "7",
@@ -324,20 +324,20 @@ var g = ({ file: o, workerSrc: g, sidebar: le, toolbar: _, onChangeFile: v, them
324
324
  })
325
325
  ]
326
326
  })
327
- }, t) : /* @__PURE__ */ p("div", {
328
- className: s.noteOverlay,
327
+ }, t) : /* @__PURE__ */ m("div", {
328
+ className: c.noteOverlay,
329
329
  style: {
330
330
  left: e.x,
331
331
  top: e.y,
332
332
  width: e.width,
333
333
  height: e.height
334
334
  },
335
- onMouseEnter: (t) => Z(e, t),
336
- onMouseLeave: Q,
337
- onClick: () => $(e)
335
+ onMouseEnter: (t) => Q(e, t),
336
+ onMouseLeave: $,
337
+ onClick: () => Ee(e)
338
338
  }, t)),
339
- we.filter((e) => e.page === t + 1).map((e, t) => /* @__PURE__ */ p("div", {
340
- className: s.searchMatchOverlay,
339
+ we.filter((e) => e.page === t + 1).map((e, t) => /* @__PURE__ */ m("div", {
340
+ className: c.searchMatchOverlay,
341
341
  style: {
342
342
  left: e.x,
343
343
  top: e.y,
@@ -345,42 +345,42 @@ var g = ({ file: o, workerSrc: g, sidebar: le, toolbar: _, onChangeFile: v, them
345
345
  height: e.height
346
346
  }
347
347
  }, t)),
348
- D && Y?.page === t + 1 && /* @__PURE__ */ p("div", {
349
- className: s.highlightOverlay,
348
+ O && X?.page === t + 1 && /* @__PURE__ */ m("div", {
349
+ className: c.highlightOverlay,
350
350
  style: {
351
- left: Y.x,
352
- top: Y.y,
353
- width: Y.width,
354
- height: Y.height
351
+ left: X.x,
352
+ top: X.y,
353
+ width: X.width,
354
+ height: X.height
355
355
  }
356
356
  })
357
357
  ]
358
- }, `${t}-${T}`);
358
+ }, `${t}-${E}`);
359
359
  }),
360
- x && /* @__PURE__ */ p(ce, { hasRead: P })
360
+ S && /* @__PURE__ */ m(se, { hasRead: F })
361
361
  ]
362
362
  })]
363
363
  })]
364
- }), M && /* @__PURE__ */ m("div", {
365
- className: s.notePopover,
366
- style: M.above ? {
367
- left: M.x,
368
- bottom: M.y
364
+ }), N && /* @__PURE__ */ h("div", {
365
+ className: c.notePopover,
366
+ style: N.above ? {
367
+ left: N.x,
368
+ bottom: N.y
369
369
  } : {
370
- left: M.x,
371
- top: M.y
370
+ left: N.x,
371
+ top: N.y
372
372
  },
373
373
  onMouseEnter: () => {
374
- X.current && clearTimeout(X.current);
374
+ Z.current && clearTimeout(Z.current);
375
375
  },
376
- onMouseLeave: Q,
376
+ onMouseLeave: $,
377
377
  onClick: (e) => e.stopPropagation(),
378
- children: [M.title && /* @__PURE__ */ p("div", {
379
- className: s.notePopoverTitle,
380
- children: M.title
381
- }), /* @__PURE__ */ p("p", {
382
- className: s.notePopoverContent,
383
- children: M.contents
378
+ children: [N.title && /* @__PURE__ */ m("div", {
379
+ className: c.notePopoverTitle,
380
+ children: N.title
381
+ }), /* @__PURE__ */ m("p", {
382
+ className: c.notePopoverContent,
383
+ children: N.contents
384
384
  })]
385
385
  })]
386
386
  })
@@ -388,4 +388,4 @@ var g = ({ file: o, workerSrc: g, sidebar: le, toolbar: _, onChangeFile: v, them
388
388
  });
389
389
  };
390
390
  //#endregion
391
- export { g as default };
391
+ export { _ as default };
@@ -1,22 +1,17 @@
1
- import e from "../node_modules/pdfjs-dist/wasm/jbig2.js";
2
- import "../node_modules/pdfjs-dist/wasm/openjpeg.js";
3
- import "../node_modules/pdfjs-dist/wasm/qcms_bg.js";
4
- import "../node_modules/pdfjs-dist/wasm/quickjs-eval.js";
5
- import { useEffect as t, useState as n } from "react";
6
- import * as r from "pdfjs-dist";
1
+ import { useEffect as e, useState as t } from "react";
2
+ import * as n from "pdfjs-dist";
7
3
  //#region src/hooks/usePDFLoader.ts
8
- var i = e.replace(/[^/]+$/, "");
9
- function a(e) {
10
- let [a, o] = n(null), [s, c] = n(0), [l, u] = n(!0);
11
- return t(() => {
4
+ function r(r, i) {
5
+ let [a, o] = t(null), [s, c] = t(0), [l, u] = t(!0);
6
+ return e(() => {
12
7
  u(!0), o(null), c(0);
13
- let t = new FileReader();
14
- t.onload = async (e) => {
8
+ let e = new FileReader();
9
+ e.onload = async (e) => {
15
10
  let t = new Uint8Array(e.target?.result);
16
11
  try {
17
- let e = await r.getDocument({
12
+ let e = await n.getDocument({
18
13
  data: t,
19
- wasmUrl: i
14
+ ...i ? { wasmUrl: i } : {}
20
15
  }).promise;
21
16
  o(e), c(e.numPages);
22
17
  } catch (e) {
@@ -24,12 +19,12 @@ function a(e) {
24
19
  } finally {
25
20
  u(!1);
26
21
  }
27
- }, t.readAsArrayBuffer(e);
28
- }, [e]), {
22
+ }, e.readAsArrayBuffer(r);
23
+ }, [r, i]), {
29
24
  pdf: a,
30
25
  numPages: s,
31
26
  loading: l
32
27
  };
33
28
  }
34
29
  //#endregion
35
- export { a as usePDFLoader };
30
+ export { r as usePDFLoader };
@@ -1,4 +1,4 @@
1
- export declare function usePDFLoader(file: File): {
1
+ export declare function usePDFLoader(file: File, wasmUrl?: string): {
2
2
  pdf: import('pdfjs-dist/types/src/display/api').PDFDocumentProxy | null;
3
3
  numPages: number;
4
4
  loading: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-tsx",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "A fully-featured, composable PDF viewer component for React",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.cjs",