@arbidocs/react 0.5.109 → 0.5.111

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 (85) hide show
  1. package/dist/PdfViewerImpl-QUSDLNNM.cjs +380 -0
  2. package/dist/PdfViewerImpl-QUSDLNNM.cjs.map +1 -0
  3. package/dist/PdfViewerImpl-TEBYF2QI.js +378 -0
  4. package/dist/PdfViewerImpl-TEBYF2QI.js.map +1 -0
  5. package/dist/{PdfViewer.d-bQH9yxFg.d.cts → PdfViewerImpl.d-B28hLEuj.d.cts} +8 -1
  6. package/dist/{PdfViewer.d-bQH9yxFg.d.ts → PdfViewerImpl.d-B28hLEuj.d.ts} +8 -1
  7. package/dist/annotations/freeze/index.d.cts +1 -1
  8. package/dist/annotations/freeze/index.d.ts +1 -1
  9. package/dist/artifacts/index.cjs +13 -13
  10. package/dist/artifacts/index.js +3 -3
  11. package/dist/calls/livekit/index.cjs +48 -48
  12. package/dist/calls/livekit/index.js +3 -3
  13. package/dist/{chunk-W2FATOTX.cjs → chunk-3JAEX57E.cjs} +4 -4
  14. package/dist/{chunk-W2FATOTX.cjs.map → chunk-3JAEX57E.cjs.map} +1 -1
  15. package/dist/{chunk-H5M7FXLB.js → chunk-4FL3X3LA.js} +3 -3
  16. package/dist/{chunk-H5M7FXLB.js.map → chunk-4FL3X3LA.js.map} +1 -1
  17. package/dist/{chunk-HD5H2PPP.cjs → chunk-5TRUFWKT.cjs} +66 -66
  18. package/dist/{chunk-HD5H2PPP.cjs.map → chunk-5TRUFWKT.cjs.map} +1 -1
  19. package/dist/chunk-6QNBSXCE.js +271 -0
  20. package/dist/chunk-6QNBSXCE.js.map +1 -0
  21. package/dist/{chunk-QF2BW6HZ.cjs → chunk-DI5KSVKY.cjs} +38 -38
  22. package/dist/{chunk-QF2BW6HZ.cjs.map → chunk-DI5KSVKY.cjs.map} +1 -1
  23. package/dist/{chunk-DQALOQPI.js → chunk-DZKRL5H3.js} +4 -4
  24. package/dist/{chunk-DQALOQPI.js.map → chunk-DZKRL5H3.js.map} +1 -1
  25. package/dist/{chunk-RVUGSM65.cjs → chunk-GKGAPU6T.cjs} +44 -44
  26. package/dist/{chunk-RVUGSM65.cjs.map → chunk-GKGAPU6T.cjs.map} +1 -1
  27. package/dist/chunk-L2IPPTVC.js +20 -0
  28. package/dist/chunk-L2IPPTVC.js.map +1 -0
  29. package/dist/{chunk-FZJMA32S.js → chunk-LSU4UPS5.js} +4 -4
  30. package/dist/{chunk-FZJMA32S.js.map → chunk-LSU4UPS5.js.map} +1 -1
  31. package/dist/{chunk-7LIMHY56.cjs → chunk-O32T7XRD.cjs} +3 -3
  32. package/dist/{chunk-7LIMHY56.cjs.map → chunk-O32T7XRD.cjs.map} +1 -1
  33. package/dist/chunk-PWGSIM3F.cjs +291 -0
  34. package/dist/chunk-PWGSIM3F.cjs.map +1 -0
  35. package/dist/{chunk-CPQ3CU4B.js → chunk-QMY2JKBI.js} +3 -3
  36. package/dist/{chunk-CPQ3CU4B.js.map → chunk-QMY2JKBI.js.map} +1 -1
  37. package/dist/chunk-QP3WQSAA.cjs +23 -0
  38. package/dist/chunk-QP3WQSAA.cjs.map +1 -0
  39. package/dist/chunk-SSXFVWCT.js +46 -0
  40. package/dist/chunk-SSXFVWCT.js.map +1 -0
  41. package/dist/chunk-T5FZICXN.cjs +50 -0
  42. package/dist/chunk-T5FZICXN.cjs.map +1 -0
  43. package/dist/{chunk-P6WLV5UY.js → chunk-XWPLOFDN.js} +3 -3
  44. package/dist/{chunk-P6WLV5UY.js.map → chunk-XWPLOFDN.js.map} +1 -1
  45. package/dist/{chunk-5HDKL6XB.cjs → chunk-YMB6XUR2.cjs} +57 -57
  46. package/dist/{chunk-5HDKL6XB.cjs.map → chunk-YMB6XUR2.cjs.map} +1 -1
  47. package/dist/{chunk-6H3O63TQ.js → chunk-ZM6N7YZH.js} +3 -3
  48. package/dist/{chunk-6H3O63TQ.js.map → chunk-ZM6N7YZH.js.map} +1 -1
  49. package/dist/document-tools/core.cjs +98 -98
  50. package/dist/document-tools/core.d.cts +2 -2
  51. package/dist/document-tools/core.d.ts +2 -2
  52. package/dist/document-tools/core.js +3 -3
  53. package/dist/document-tools/index.cjs +100 -100
  54. package/dist/document-tools/index.d.cts +1 -1
  55. package/dist/document-tools/index.d.ts +1 -1
  56. package/dist/document-tools/index.js +4 -4
  57. package/dist/index.cjs +1426 -1341
  58. package/dist/index.cjs.map +1 -1
  59. package/dist/{index.d-BMhTH98a.d.ts → index.d-CYXcTKYt.d.ts} +1 -0
  60. package/dist/{index.d-BMhTH98a.d.cts → index.d-LArLnpI8.d.cts} +1 -0
  61. package/dist/index.d.cts +39 -8
  62. package/dist/index.d.ts +39 -8
  63. package/dist/index.js +104 -33
  64. package/dist/index.js.map +1 -1
  65. package/dist/lazy-chunk.d-B6YDLMKI.d.cts +31 -0
  66. package/dist/lazy-chunk.d-B6YDLMKI.d.ts +31 -0
  67. package/dist/{query-keys.d-ChgpJLPF.d.cts → query-keys.d-B1Am9tIF.d.cts} +1 -1
  68. package/dist/{query-keys.d-ChgpJLPF.d.ts → query-keys.d-B1Am9tIF.d.ts} +1 -1
  69. package/dist/ui/index.cjs +13 -0
  70. package/dist/ui/index.d.cts +2 -1
  71. package/dist/ui/index.d.ts +2 -1
  72. package/dist/ui/index.js +1 -0
  73. package/dist/viewers/PdfViewer.cjs +17 -0
  74. package/dist/viewers/PdfViewer.cjs.map +1 -0
  75. package/dist/viewers/PdfViewer.d.cts +9 -0
  76. package/dist/viewers/PdfViewer.d.ts +9 -0
  77. package/dist/viewers/PdfViewer.js +4 -0
  78. package/dist/viewers/PdfViewer.js.map +1 -0
  79. package/dist/viewers/index.cjs +79 -653
  80. package/dist/viewers/index.cjs.map +1 -1
  81. package/dist/viewers/index.d.cts +3 -1
  82. package/dist/viewers/index.d.ts +3 -1
  83. package/dist/viewers/index.js +6 -639
  84. package/dist/viewers/index.js.map +1 -1
  85. package/package.json +11 -3
@@ -0,0 +1,378 @@
1
+ import { INITIAL_LAZY_LOAD_BUFFER, contentBoxWidth, LAZY_LOAD_BUFFER_AFTER, usePageIntersectionObserver, useScrollAnchor, usePinchZoom, renderDpr, fitPageWidth, LAZY_LOAD_BUFFER_BEFORE } from './chunk-6QNBSXCE.js';
2
+ import { installPdfjsPolyfills } from './chunk-PTOP7OHG.js';
3
+ import { useState, useMemo, useEffect, useRef, useCallback } from 'react';
4
+ import { Document, Page, pdfjs } from 'react-pdf';
5
+ import 'react-pdf/dist/Page/AnnotationLayer.css';
6
+ import 'react-pdf/dist/Page/TextLayer.css';
7
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
+
9
+ var DEFAULT_ASSETS = {
10
+ workerSrc: "/pdf.worker.min.mjs",
11
+ cMapUrl: "/cmaps/",
12
+ standardFontDataUrl: "/standard_fonts/",
13
+ wasmUrl: "/wasm/"
14
+ };
15
+ function ensurePdfWorker(workerSrc) {
16
+ installPdfjsPolyfills();
17
+ if (pdfjs.GlobalWorkerOptions.workerSrc !== workerSrc) {
18
+ pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
19
+ }
20
+ }
21
+ var DEFAULT_PAGE_ASPECT_RATIO = 1.414;
22
+ var PAGE_BORDER_PX = 2;
23
+ var RERENDER_DEBOUNCE_MS = 250;
24
+ var ZOOMED_BUFFER_THRESHOLD = 1.5;
25
+ function sameSet(a, b) {
26
+ if (a.size !== b.size) return false;
27
+ for (const v of a) if (!b.has(v)) return false;
28
+ return true;
29
+ }
30
+ var TEXT_LAYER_BUFFER = 1;
31
+ var ratioOf = (page) => {
32
+ const { width, height } = page.getViewport({ scale: 1 });
33
+ return width > 0 && height > 0 ? height / width : DEFAULT_PAGE_ASPECT_RATIO;
34
+ };
35
+ function PdfViewer({
36
+ file,
37
+ currentPage,
38
+ onLoadSuccess,
39
+ scrollTrigger,
40
+ zoom = 1,
41
+ onZoomChange,
42
+ onPageChange,
43
+ disableFontFace = false,
44
+ assets,
45
+ renderPageOverlay
46
+ }) {
47
+ const workerSrc = assets?.workerSrc ?? DEFAULT_ASSETS.workerSrc;
48
+ const cMapUrl = assets?.cMapUrl ?? DEFAULT_ASSETS.cMapUrl;
49
+ const standardFontDataUrl = assets?.standardFontDataUrl ?? DEFAULT_ASSETS.standardFontDataUrl;
50
+ const wasmUrl = assets?.wasmUrl ?? DEFAULT_ASSETS.wasmUrl;
51
+ ensurePdfWorker(workerSrc);
52
+ const [numPages, setNumPages] = useState(0);
53
+ const [containerWidth, setContainerWidth] = useState(0);
54
+ const [defaultRatio, setDefaultRatio] = useState(DEFAULT_PAGE_ASPECT_RATIO);
55
+ const [pageRatios, setPageRatios] = useState(/* @__PURE__ */ new Map());
56
+ const [pageWidthsPt, setPageWidthsPt] = useState(/* @__PURE__ */ new Map());
57
+ const [loadError, setLoadError] = useState(null);
58
+ const [documentKey, setDocumentKey] = useState(() => `pdf-${Date.now()}`);
59
+ const initialPage = currentPage || 1;
60
+ const [renderedPages, setRenderedPages] = useState(
61
+ /* @__PURE__ */ new Set([
62
+ Math.max(1, initialPage - INITIAL_LAZY_LOAD_BUFFER.before),
63
+ initialPage,
64
+ initialPage + INITIAL_LAZY_LOAD_BUFFER.after
65
+ ])
66
+ );
67
+ const [visiblePages, setVisiblePages] = useState(/* @__PURE__ */ new Set([initialPage]));
68
+ const loadLifetime = useMemo(() => ({ file, active: true }), [file]);
69
+ useEffect(() => {
70
+ loadLifetime.active = true;
71
+ return () => {
72
+ loadLifetime.active = false;
73
+ };
74
+ }, [loadLifetime]);
75
+ useEffect(() => {
76
+ setDocumentKey(`pdf-${Date.now()}`);
77
+ setNumPages(0);
78
+ setLoadError(null);
79
+ }, [file]);
80
+ const containerRef = useRef(null);
81
+ const pageRefs = useRef(/* @__PURE__ */ new Map());
82
+ const onDocumentLoadSuccess = useCallback(
83
+ (pdf) => {
84
+ if (!loadLifetime.active) return;
85
+ const n = pdf.numPages;
86
+ void pdf.getPage?.(1).then((page) => {
87
+ if (loadLifetime.active) setDefaultRatio(ratioOf(page));
88
+ }).catch(() => {
89
+ });
90
+ setNumPages(n);
91
+ setLoadError(null);
92
+ try {
93
+ onLoadSuccess?.(n);
94
+ } catch (error) {
95
+ console.error("Error in onLoadSuccess callback:", error);
96
+ }
97
+ },
98
+ [onLoadSuccess, loadLifetime]
99
+ );
100
+ useEffect(() => {
101
+ if (numPages === 0) return;
102
+ let cancelled = false;
103
+ const expand = () => {
104
+ if (cancelled || !loadLifetime.active) return;
105
+ setRenderedPages((prev) => {
106
+ if (prev.size === 0) return prev;
107
+ const newSet = new Set(prev);
108
+ const anchor = currentPage || 1;
109
+ for (let i = Math.max(1, anchor - LAZY_LOAD_BUFFER_BEFORE); i <= Math.min(numPages, anchor + LAZY_LOAD_BUFFER_AFTER); i++) {
110
+ newSet.add(i);
111
+ }
112
+ return newSet;
113
+ });
114
+ };
115
+ if (typeof requestIdleCallback !== "undefined") {
116
+ const handle2 = requestIdleCallback(expand, { timeout: 500 });
117
+ return () => {
118
+ cancelled = true;
119
+ if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(handle2);
120
+ };
121
+ }
122
+ const handle = setTimeout(expand, 500);
123
+ return () => {
124
+ cancelled = true;
125
+ clearTimeout(handle);
126
+ };
127
+ }, [numPages, currentPage, loadLifetime]);
128
+ const onDocumentLoadError = useCallback((error) => {
129
+ console.error("PDF loading error:", error);
130
+ setLoadError(error);
131
+ setNumPages(0);
132
+ }, []);
133
+ const onPassword = useCallback((updatePassword, reason) => {
134
+ const message = reason === 2 ? "Incorrect password. Enter the password to unlock this PDF:" : "This PDF is password-protected. Enter the password to view it:";
135
+ const password = window.prompt(message);
136
+ if (password === null) {
137
+ setLoadError(new Error("Password required to open this PDF"));
138
+ setNumPages(0);
139
+ return;
140
+ }
141
+ updatePassword(password);
142
+ }, []);
143
+ useEffect(() => {
144
+ const container = containerRef.current;
145
+ if (!container) return;
146
+ const setFromContentWidth = (contentWidth) => setContainerWidth(fitPageWidth(contentWidth, PAGE_BORDER_PX));
147
+ setFromContentWidth(contentBoxWidth(container));
148
+ const resizeObserver = new ResizeObserver((entries) => {
149
+ const entry = entries[entries.length - 1];
150
+ const box = entry?.contentBoxSize?.[0];
151
+ setFromContentWidth(box ? box.inlineSize : entry?.contentRect.width ?? 0);
152
+ });
153
+ resizeObserver.observe(container);
154
+ return () => {
155
+ resizeObserver.disconnect();
156
+ };
157
+ }, []);
158
+ const scrollCompleteRef = useRef(false);
159
+ useEffect(() => {
160
+ if (numPages === 0) return;
161
+ if (scrollCompleteRef.current) return;
162
+ if (currentPage) {
163
+ setRenderedPages((prev) => {
164
+ const newSet = new Set(prev);
165
+ for (let i = Math.max(1, currentPage - LAZY_LOAD_BUFFER_BEFORE); i <= Math.min(numPages, currentPage + LAZY_LOAD_BUFFER_AFTER); i++) {
166
+ newSet.add(i);
167
+ }
168
+ return newSet;
169
+ });
170
+ requestAnimationFrame(() => {
171
+ const pageElement = pageRefs.current.get(currentPage);
172
+ if (pageElement) {
173
+ pageElement.scrollIntoView({ behavior: "auto", block: "start" });
174
+ }
175
+ setTimeout(() => {
176
+ scrollCompleteRef.current = true;
177
+ }, 100);
178
+ });
179
+ }
180
+ }, [numPages]);
181
+ const currentPageRef = useRef(currentPage);
182
+ currentPageRef.current = currentPage;
183
+ useEffect(() => {
184
+ const currentPage2 = currentPageRef.current;
185
+ if (!scrollTrigger || numPages === 0 || !currentPage2) return;
186
+ scrollCompleteRef.current = false;
187
+ setRenderedPages((prev) => {
188
+ const newSet = new Set(prev);
189
+ for (let i = Math.max(1, currentPage2 - LAZY_LOAD_BUFFER_BEFORE); i <= Math.min(numPages, currentPage2 + LAZY_LOAD_BUFFER_AFTER); i++) {
190
+ newSet.add(i);
191
+ }
192
+ return newSet;
193
+ });
194
+ requestAnimationFrame(() => {
195
+ requestAnimationFrame(() => {
196
+ const pageElement = pageRefs.current.get(currentPage2);
197
+ if (pageElement) {
198
+ pageElement.scrollIntoView({ behavior: "instant", block: "start" });
199
+ }
200
+ scrollCompleteRef.current = true;
201
+ });
202
+ });
203
+ }, [scrollTrigger, numPages]);
204
+ const handleVisibilityUpdate = useCallback(
205
+ (visibilityMap) => {
206
+ const visiblePageNums = Array.from(visibilityMap.entries()).filter(([, ratio]) => ratio > 0).map(([pageNum]) => pageNum);
207
+ if (visiblePageNums.length > 0) {
208
+ const minVisible = Math.min(...visiblePageNums);
209
+ const maxVisible = Math.max(...visiblePageNums);
210
+ const zoomed = zoom > ZOOMED_BUFFER_THRESHOLD;
211
+ const before = zoomed ? 1 : LAZY_LOAD_BUFFER_BEFORE;
212
+ const after = zoomed ? 2 : LAZY_LOAD_BUFFER_AFTER;
213
+ const pagesToRender = /* @__PURE__ */ new Set();
214
+ for (let i = Math.max(1, minVisible - before); i <= Math.min(numPages, maxVisible + after); i++) {
215
+ pagesToRender.add(i);
216
+ }
217
+ setRenderedPages((prev) => sameSet(prev, pagesToRender) ? prev : pagesToRender);
218
+ const nearViewport = /* @__PURE__ */ new Set();
219
+ for (let i = Math.max(1, minVisible - TEXT_LAYER_BUFFER); i <= Math.min(numPages, maxVisible + TEXT_LAYER_BUFFER); i++) {
220
+ nearViewport.add(i);
221
+ }
222
+ setVisiblePages((prev) => sameSet(prev, nearViewport) ? prev : nearViewport);
223
+ }
224
+ },
225
+ [numPages, zoom]
226
+ );
227
+ const documentOptions = useMemo(
228
+ () => ({
229
+ standardFontDataUrl,
230
+ cMapUrl,
231
+ cMapPacked: true,
232
+ wasmUrl,
233
+ ...disableFontFace && { disableFontFace: true }
234
+ }),
235
+ [standardFontDataUrl, cMapUrl, wasmUrl, disableFontFace]
236
+ );
237
+ const handlePageChange = useCallback(
238
+ (pageNumber) => onPageChange?.(pageNumber),
239
+ [onPageChange]
240
+ );
241
+ usePageIntersectionObserver({
242
+ containerRef,
243
+ scrollCompleteRef,
244
+ isEnabled: numPages > 0,
245
+ getPageElements: () => Array.from(pageRefs.current.values()),
246
+ getPageNumber: (element) => parseInt(element.getAttribute("data-page-number") ?? "0"),
247
+ onPageChange: handlePageChange,
248
+ onVisibilityUpdate: handleVisibilityUpdate,
249
+ observeKey: `${numPages}:${containerWidth > 0}`
250
+ });
251
+ useScrollAnchor(containerRef, `${numPages}:${containerWidth > 0}`);
252
+ usePinchZoom({ containerRef, zoom, onZoomChange });
253
+ const [renderZoom, setRenderZoom] = useState(zoom);
254
+ useEffect(() => {
255
+ if (zoom === renderZoom) return;
256
+ const timer = setTimeout(() => setRenderZoom(zoom), RERENDER_DEBOUNCE_MS);
257
+ return () => clearTimeout(timer);
258
+ }, [zoom, renderZoom]);
259
+ return /* @__PURE__ */ jsx(
260
+ "div",
261
+ {
262
+ ref: containerRef,
263
+ className: "w-full h-full overflow-auto bg-muted flex flex-col items-start p-4 pb-20",
264
+ style: { touchAction: "pan-x pan-y", scrollbarGutter: "stable" },
265
+ role: "region",
266
+ "aria-label": "PDF document viewer",
267
+ "data-testid": "pdf-viewer",
268
+ children: /* @__PURE__ */ jsx(
269
+ Document,
270
+ {
271
+ className: "flex w-max min-w-full flex-col",
272
+ suspense: false,
273
+ file,
274
+ onLoadSuccess: onDocumentLoadSuccess,
275
+ onLoadError: onDocumentLoadError,
276
+ onPassword,
277
+ options: documentOptions,
278
+ loading: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground", children: "Loading PDF..." }) }),
279
+ error: /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center justify-center h-full gap-4 p-8", children: /* @__PURE__ */ jsx("div", { className: "text-destructive text-center", children: loadError?.message === "Cannot read properties of null (reading 'sendWithPromise')" ? /* @__PURE__ */ jsxs(Fragment, { children: [
280
+ /* @__PURE__ */ jsx("p", { className: "font-semibold mb-2", children: "PDF viewer initialization failed" }),
281
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Please refresh the page to retry" })
282
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
283
+ /* @__PURE__ */ jsx("p", { className: "font-semibold mb-2", children: "Failed to load PDF" }),
284
+ loadError && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: loadError.message })
285
+ ] }) }) }),
286
+ children: containerWidth > 0 && Array.from(new Array(numPages), (_, index) => {
287
+ const pageNumber = index + 1;
288
+ const shouldRender = renderedPages.has(pageNumber);
289
+ const ratio = pageRatios.get(pageNumber) ?? defaultRatio;
290
+ const pageWidth = containerWidth * zoom;
291
+ const pageHeight = pageWidth * ratio;
292
+ const renderWidth = containerWidth * renderZoom;
293
+ const scale = zoom / renderZoom;
294
+ const shouldRenderTextLayer = visiblePages.has(pageNumber);
295
+ return /* @__PURE__ */ jsxs(
296
+ "div",
297
+ {
298
+ ref: (el) => {
299
+ if (el) {
300
+ pageRefs.current.set(pageNumber, el);
301
+ } else {
302
+ pageRefs.current.delete(pageNumber);
303
+ }
304
+ },
305
+ "data-page-number": pageNumber,
306
+ className: "relative mx-auto mb-6 shrink-0 shadow-xl bg-white border border-border",
307
+ style: { width: pageWidth + PAGE_BORDER_PX, height: pageHeight + PAGE_BORDER_PX },
308
+ role: "article",
309
+ "aria-label": `Page ${pageNumber} of ${numPages}`,
310
+ children: [
311
+ shouldRender ? /* @__PURE__ */ jsx(
312
+ "div",
313
+ {
314
+ "data-testid": `pdf-page-scaler-${pageNumber}`,
315
+ style: scale === 1 ? void 0 : { transform: `scale(${scale})`, transformOrigin: "0 0" },
316
+ children: /* @__PURE__ */ jsx(
317
+ Page,
318
+ {
319
+ pageNumber,
320
+ width: renderWidth,
321
+ renderTextLayer: shouldRenderTextLayer,
322
+ renderAnnotationLayer: false,
323
+ onLoadSuccess: (page) => {
324
+ setPageWidthsPt(
325
+ (prev) => prev.get(pageNumber) === page.originalWidth ? prev : new Map(prev).set(pageNumber, page.originalWidth)
326
+ );
327
+ const ratio2 = page.originalHeight / page.originalWidth;
328
+ setPageRatios(
329
+ (prev) => Math.abs((prev.get(pageNumber) ?? defaultRatio) - ratio2) < 1e-3 ? prev : new Map(prev).set(pageNumber, ratio2)
330
+ );
331
+ },
332
+ devicePixelRatio: renderDpr(
333
+ renderWidth,
334
+ renderWidth * ratio,
335
+ window.devicePixelRatio || 1
336
+ ),
337
+ loading: /* @__PURE__ */ jsx(
338
+ "div",
339
+ {
340
+ className: "flex items-center justify-center bg-muted",
341
+ style: { width: renderWidth, height: renderWidth * ratio },
342
+ children: /* @__PURE__ */ jsxs("div", { className: "text-sm text-muted-foreground", children: [
343
+ "Loading page ",
344
+ pageNumber,
345
+ "..."
346
+ ] })
347
+ }
348
+ )
349
+ }
350
+ )
351
+ }
352
+ ) : /* @__PURE__ */ jsx(
353
+ "div",
354
+ {
355
+ className: "flex items-center justify-center bg-muted",
356
+ style: { width: pageWidth, height: pageHeight },
357
+ children: /* @__PURE__ */ jsxs("div", { className: "text-sm text-muted-foreground", children: [
358
+ "Page ",
359
+ pageNumber
360
+ ] })
361
+ }
362
+ ),
363
+ renderPageOverlay?.({ pageNumber, pageWidthPt: pageWidthsPt.get(pageNumber) })
364
+ ]
365
+ },
366
+ `page_${pageNumber}`
367
+ );
368
+ })
369
+ },
370
+ documentKey
371
+ )
372
+ }
373
+ );
374
+ }
375
+
376
+ export { PdfViewer };
377
+ //# sourceMappingURL=PdfViewerImpl-TEBYF2QI.js.map
378
+ //# sourceMappingURL=PdfViewerImpl-TEBYF2QI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/viewers/PdfViewerImpl.tsx"],"names":["handle","currentPage","ratio"],"mappings":";;;;;;;;AAiDA,IAAM,cAAA,GAA4C;AAAA,EAChD,SAAA,EAAW,qBAAA;AAAA,EACX,OAAA,EAAS,SAAA;AAAA,EACT,mBAAA,EAAqB,kBAAA;AAAA,EACrB,OAAA,EAAS;AACX,CAAA;AAMA,SAAS,gBAAgB,SAAA,EAAmB;AAC1C,EAAA,qBAAA,EAAsB;AACtB,EAAA,IAAI,KAAA,CAAM,mBAAA,CAAoB,SAAA,KAAc,SAAA,EAAW;AACrD,IAAA,KAAA,CAAM,oBAAoB,SAAA,GAA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*\n * Uses IntersectionObserver to track the visible page and to drive two separate\n * lazy-load windows: a wide canvas buffer (so a page image is ready before the\n * user scrolls to it) and a narrow text-layer window (text spans are expensive\n * DOM, so they only exist for the active reading area).\n *\n * DECOUPLED FOR REUSE: page changes are reported through `onPageChange` rather\n * than written to an app store, and the pdf.js asset URLs are props rather than\n * hardcoded paths, because a consuming app decides where it serves the worker,\n * cmaps and standard fonts from.\n *\n * `react-pdf` and `pdfjs-dist` are OPTIONAL peer dependencies — install them\n * only if you render PDFs. The consuming app must also serve the pdf.js worker\n * (see `assets.workerSrc`).\n */\n\nimport { useState, useEffect, useRef, useCallback, useMemo, type ReactNode } from 'react'\nimport { Document, Page, pdfjs } from 'react-pdf'\nimport 'react-pdf/dist/Page/AnnotationLayer.css'\nimport 'react-pdf/dist/Page/TextLayer.css'\nimport { installPdfjsPolyfills } from './pdfjs-polyfills'\nimport { usePageIntersectionObserver } from './usePageIntersectionObserver'\nimport { useScrollAnchor } from './page-scroll'\nimport { contentBoxWidth, fitPageWidth, renderDpr, usePinchZoom } from './viewer-zoom'\nimport {\n LAZY_LOAD_BUFFER_BEFORE,\n LAZY_LOAD_BUFFER_AFTER,\n INITIAL_LAZY_LOAD_BUFFER,\n} from './pdf-viewer-constants'\n\n/** Where the app serves the pdf.js runtime assets from. */\nexport interface PdfViewerAssets {\n /** pdf.js worker bundle. Default `/pdf.worker.min.mjs`. */\n workerSrc?: string\n /** Directory of pdf.js character maps. Default `/cmaps/`. */\n cMapUrl?: string\n /** Directory of pdf.js standard font data. Default `/standard_fonts/`. */\n standardFontDataUrl?: string\n /**\n * Directory of the pdf.js wasm decoders (openjpeg for JPEG 2000, jbig2,\n * qcms). Scanned PDFs routinely embed JPX/JBIG2-compressed page images;\n * without these modules pdf.js fails image decoding with only a console\n * warning and renders blank white pages. Default `/wasm/`.\n */\n wasmUrl?: string\n}\n\nconst DEFAULT_ASSETS: Required<PdfViewerAssets> = {\n workerSrc: '/pdf.worker.min.mjs',\n cMapUrl: '/cmaps/',\n standardFontDataUrl: '/standard_fonts/',\n wasmUrl: '/wasm/',\n}\n\n/**\n * Ready pdf.js before any Document mounts: the built-ins it needs on this thread (older browsers\n * lack them and every page render would throw), and the worker, re-set only if it changed.\n */\nfunction ensurePdfWorker(workerSrc: string) {\n installPdfjsPolyfills()\n if (pdfjs.GlobalWorkerOptions.workerSrc !== workerSrc) {\n pdfjs.GlobalWorkerOptions.workerSrc = workerSrc\n }\n}\n\n// Page rendering constants\n// Height / width used for a page until its real size is known (the first page is read as soon as\n// the document opens, every other page as it renders). A placeholder that differs from the real\n// page shifts everything below it when the page renders.\nconst DEFAULT_PAGE_ASPECT_RATIO = 1.414 // A4 (√2)\n/** The page wrapper's own border (border, top + bottom), included in its fixed height. */\nconst PAGE_BORDER_PX = 2\n/** Wait for the zoom to settle before re-rasterising every visible page. */\nconst RERENDER_DEBOUNCE_MS = 250\n/** Above this zoom a page canvas is large enough that the render window shrinks. */\nconst ZOOMED_BUFFER_THRESHOLD = 1.5\n\n/** Same set contents: lets a state setter bail out instead of re-rendering on every scroll tick. */\nfunction sameSet(a: ReadonlySet<number>, b: ReadonlySet<number>): boolean {\n if (a.size !== b.size) return false\n for (const v of a) if (!b.has(v)) return false\n return true\n}\n\n// Text layer is enabled for pages within 1 page of the visible set — enough for smooth\n// scrolling while keeping DOM node count low on large documents.\nconst TEXT_LAYER_BUFFER = 1\n\ninterface PdfPageSize {\n getViewport: (options: { scale: number }) => { width: number; height: number }\n}\nconst ratioOf = (page: PdfPageSize): number => {\n const { width, height } = page.getViewport({ scale: 1 })\n return width > 0 && height > 0 ? height / width : DEFAULT_PAGE_ASPECT_RATIO\n}\n\nexport interface PdfViewerProps {\n file: string | Blob\n currentPage?: number\n onLoadSuccess?: (numPages: number) => void\n /** Incremented to trigger scroll to currentPage */\n scrollTrigger?: number\n /** Zoom as a multiplier of the fit-width size (1 = fit width). Default 1. */\n zoom?: number\n /** Called by pinch and double-tap; the host owns the value (its buttons change it too). */\n onZoomChange?: (zoom: number) => void\n /**\n * Called as the user scrolls, with the page occupying most of the viewport.\n * This is the reusable form of the monolith's `setViewingDocumentPage`.\n */\n onPageChange?: (pageNumber: number) => void\n /**\n * Force pdf.js to rasterise fonts onto the canvas instead of using @font-face.\n * Required when rendering into a different document (e.g. a popped-out window),\n * where @font-face rules from the opener do not apply.\n */\n disableFontFace?: boolean\n /** Where the app serves the pdf.js worker, cmaps and standard fonts from. */\n assets?: PdfViewerAssets\n /**\n * Content drawn over every page, inside its border box (e.g. the annotation layer). It fills the\n * page area and moves and scales with it. `pageWidthPt` is the page's width in PDF points once\n * known, so overlays can size strokes and text to match what a later export draws.\n */\n renderPageOverlay?: (page: { pageNumber: number; pageWidthPt: number | undefined }) => ReactNode\n}\n\nexport function PdfViewer({\n file,\n currentPage,\n onLoadSuccess,\n scrollTrigger,\n zoom = 1,\n onZoomChange,\n onPageChange,\n disableFontFace = false,\n assets,\n renderPageOverlay,\n}: PdfViewerProps) {\n const workerSrc = assets?.workerSrc ?? DEFAULT_ASSETS.workerSrc\n const cMapUrl = assets?.cMapUrl ?? DEFAULT_ASSETS.cMapUrl\n const standardFontDataUrl = assets?.standardFontDataUrl ?? DEFAULT_ASSETS.standardFontDataUrl\n const wasmUrl = assets?.wasmUrl ?? DEFAULT_ASSETS.wasmUrl\n\n // Ensure the pdf.js worker is configured before any Document mounts\n ensurePdfWorker(workerSrc)\n\n const [numPages, setNumPages] = useState<number>(0)\n const [containerWidth, setContainerWidth] = useState<number>(0)\n // Real height/width of the document's pages: the first page's, then each page as it loads.\n const [defaultRatio, setDefaultRatio] = useState<number>(DEFAULT_PAGE_ASPECT_RATIO)\n const [pageRatios, setPageRatios] = useState<ReadonlyMap<number, number>>(new Map())\n // Each page's width in PDF points, for overlays that must size strokes and text like an export.\n const [pageWidthsPt, setPageWidthsPt] = useState<ReadonlyMap<number, number>>(new Map())\n const [loadError, setLoadError] = useState<Error | null>(null)\n const [documentKey, setDocumentKey] = useState<string>(() => `pdf-${Date.now()}`)\n\n // Initialize with pages around the current page (or first 3 pages if no current page).\n // Start with a small initial buffer so the first paint is cheap; expand to the full\n // buffer lazily via requestIdleCallback after the first render settles.\n const initialPage = currentPage || 1\n const [renderedPages, setRenderedPages] = useState<Set<number>>(\n new Set([\n Math.max(1, initialPage - INITIAL_LAZY_LOAD_BUFFER.before),\n initialPage,\n initialPage + INITIAL_LAZY_LOAD_BUFFER.after,\n ])\n )\n\n // Pages currently in/near the viewport — used to gate the text layer.\n // Keeping this separate from renderedPages lets the canvas still render on buffer pages\n // while text DOM nodes are only created for the user's active reading area.\n const [visiblePages, setVisiblePages] = useState<Set<number>>(new Set([initialPage]))\n\n // A late PDF.js completion belongs only to the file that started it.\n const loadLifetime = useMemo(() => ({ file, active: true }), [file])\n useEffect(() => {\n loadLifetime.active = true\n return () => {\n loadLifetime.active = false\n }\n }, [loadLifetime])\n\n // Reset document key when file changes to force remount\n useEffect(() => {\n setDocumentKey(`pdf-${Date.now()}`)\n setNumPages(0)\n setLoadError(null)\n }, [file])\n\n const containerRef = useRef<HTMLDivElement>(null)\n const pageRefs = useRef<Map<number, HTMLDivElement>>(new Map())\n\n // Handle document load success\n const onDocumentLoadSuccess = useCallback(\n (pdf: { numPages: number; getPage?: (n: number) => Promise<PdfPageSize> }) => {\n if (!loadLifetime.active) return\n const n = pdf.numPages\n void pdf\n .getPage?.(1)\n .then((page) => {\n if (loadLifetime.active) setDefaultRatio(ratioOf(page))\n })\n .catch(() => {})\n setNumPages(n)\n setLoadError(null) // Clear any previous errors\n\n try {\n onLoadSuccess?.(n)\n } catch (error) {\n console.error('Error in onLoadSuccess callback:', error)\n }\n },\n [onLoadSuccess, loadLifetime]\n )\n\n // Expand only while this file is mounted. Cancellation also guards callbacks\n // that were already queued when the idle/timer handle was cancelled.\n useEffect(() => {\n if (numPages === 0) return\n let cancelled = false\n const expand = () => {\n if (cancelled || !loadLifetime.active) return\n setRenderedPages((prev) => {\n if (prev.size === 0) return prev\n const newSet = new Set(prev)\n const anchor = currentPage || 1\n for (\n let i = Math.max(1, anchor - LAZY_LOAD_BUFFER_BEFORE);\n i <= Math.min(numPages, anchor + LAZY_LOAD_BUFFER_AFTER);\n i++\n ) {\n newSet.add(i)\n }\n return newSet\n })\n }\n if (typeof requestIdleCallback !== 'undefined') {\n const handle = requestIdleCallback(expand, { timeout: 500 })\n return () => {\n cancelled = true\n if (typeof cancelIdleCallback !== 'undefined') cancelIdleCallback(handle)\n }\n }\n const handle = setTimeout(expand, 500)\n return () => {\n cancelled = true\n clearTimeout(handle)\n }\n }, [numPages, currentPage, loadLifetime])\n\n // Handle document load error\n const onDocumentLoadError = useCallback((error: Error) => {\n console.error('PDF loading error:', error)\n setLoadError(error)\n setNumPages(0)\n }, [])\n\n // react-pdf calls this when the PDF is encrypted (reason === 1) or the\n // supplied password was wrong (reason === 2). Default behaviour is a\n // window.prompt() that, when cancelled, never resolves the password\n // callback — pdf.js then leaves the document load Promise pending forever\n // and the viewer is stuck on \"Loading PDF...\".\n //\n // Always call updatePassword exactly once. On cancel we surface a\n // synthetic load error so onLoadError → setLoadError fires the standard\n // error UI instead of the indefinite spinner.\n const onPassword = useCallback((updatePassword: (password: string) => void, reason: number) => {\n const message =\n reason === 2\n ? 'Incorrect password. Enter the password to unlock this PDF:'\n : 'This PDF is password-protected. Enter the password to view it:'\n const password = window.prompt(message)\n if (password === null) {\n // Cancelled. Synthesise a load error so the error UI takes over.\n setLoadError(new Error('Password required to open this PDF'))\n setNumPages(0)\n return\n }\n updatePassword(password)\n }, [])\n\n // Fit width: the scroller's content box (inside its padding AND its vertical scrollbar) less the\n // page's own border. `offsetWidth` would count the scrollbar and overflow sideways by its width.\n useEffect(() => {\n const container = containerRef.current\n if (!container) return\n const setFromContentWidth = (contentWidth: number) =>\n setContainerWidth(fitPageWidth(contentWidth, PAGE_BORDER_PX))\n\n setFromContentWidth(contentBoxWidth(container))\n\n // Re-measure on any change of the content box: a panel resize, or the vertical scrollbar\n // appearing once the pages are taller than the scroller.\n const resizeObserver = new ResizeObserver((entries) => {\n const entry = entries[entries.length - 1]\n const box = entry?.contentBoxSize?.[0]\n setFromContentWidth(box ? box.inlineSize : (entry?.contentRect.width ?? 0))\n })\n resizeObserver.observe(container)\n\n return () => {\n resizeObserver.disconnect()\n }\n }, [])\n\n // Track whether initial scroll has completed to prevent feedback loop\n const scrollCompleteRef = useRef(false)\n\n // Scroll to page ONLY when PDF loads - not when page number updates from scrolling\n useEffect(() => {\n if (numPages === 0) return\n\n // If we already scrolled, don't scroll again\n if (scrollCompleteRef.current) return\n\n // Ensure the target page and surrounding pages are rendered\n if (currentPage) {\n setRenderedPages((prev) => {\n const newSet = new Set(prev)\n for (\n let i = Math.max(1, currentPage - LAZY_LOAD_BUFFER_BEFORE);\n i <= Math.min(numPages, currentPage + LAZY_LOAD_BUFFER_AFTER);\n i++\n ) {\n newSet.add(i)\n }\n return newSet\n })\n\n // Wait for DOM update, then scroll\n requestAnimationFrame(() => {\n const pageElement = pageRefs.current.get(currentPage)\n if (pageElement) {\n pageElement.scrollIntoView({ behavior: 'auto', block: 'start' })\n }\n // Wait for scroll to complete before allowing page number updates\n setTimeout(() => {\n scrollCompleteRef.current = true\n }, 100)\n })\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [numPages]) // Note: currentPage is intentionally NOT a dependency to prevent feedback loop\n\n // The page the last explicit request (overlay arrows, typed number) asked for. Read when the\n // trigger fires; scrolling itself changes `currentPage` and must NOT re-run the scroll below,\n // or every page the user scrolls past would pull the view back to that page's top.\n const currentPageRef = useRef(currentPage)\n currentPageRef.current = currentPage\n\n // Scroll to page when scrollTrigger changes (user entered a page number)\n useEffect(() => {\n const currentPage = currentPageRef.current\n if (!scrollTrigger || numPages === 0 || !currentPage) return\n\n // Temporarily disable observer updates during manual scroll\n scrollCompleteRef.current = false\n\n // Ensure the target page and surrounding pages are rendered\n setRenderedPages((prev) => {\n const newSet = new Set(prev)\n for (\n let i = Math.max(1, currentPage - LAZY_LOAD_BUFFER_BEFORE);\n i <= Math.min(numPages, currentPage + LAZY_LOAD_BUFFER_AFTER);\n i++\n ) {\n newSet.add(i)\n }\n return newSet\n })\n\n // Double-rAF: first frame lets React commit the setRenderedPages update so\n // pages before the target are in the DOM at their correct heights; second\n // frame scrolls after layout has settled. Instant scroll avoids a race\n // where smooth-scroll animation is still running when the observer\n // re-enables and reports the wrong page.\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n const pageElement = pageRefs.current.get(currentPage)\n if (pageElement) {\n pageElement.scrollIntoView({ behavior: 'instant', block: 'start' })\n }\n scrollCompleteRef.current = true\n })\n })\n }, [scrollTrigger, numPages])\n\n // Handle lazy loading based on visible pages\n const handleVisibilityUpdate = useCallback(\n (visibilityMap: Map<number, number>) => {\n const visiblePageNums = Array.from(visibilityMap.entries())\n .filter(([, ratio]) => ratio > 0)\n .map(([pageNum]) => pageNum)\n\n if (visiblePageNums.length > 0) {\n const minVisible = Math.min(...visiblePageNums)\n const maxVisible = Math.max(...visiblePageNums)\n\n // Update canvas render buffer (wider window for smooth pre-loading). Zoomed pages are\n // big canvases: keep fewer of them alive so far pages release their memory.\n const zoomed = zoom > ZOOMED_BUFFER_THRESHOLD\n const before = zoomed ? 1 : LAZY_LOAD_BUFFER_BEFORE\n const after = zoomed ? 2 : LAZY_LOAD_BUFFER_AFTER\n const pagesToRender = new Set<number>()\n for (\n let i = Math.max(1, minVisible - before);\n i <= Math.min(numPages, maxVisible + after);\n i++\n ) {\n pagesToRender.add(i)\n }\n setRenderedPages((prev) => (sameSet(prev, pagesToRender) ? prev : pagesToRender))\n\n // Update text-layer set (narrow window — text layer is expensive DOM)\n const nearViewport = new Set<number>()\n for (\n let i = Math.max(1, minVisible - TEXT_LAYER_BUFFER);\n i <= Math.min(numPages, maxVisible + TEXT_LAYER_BUFFER);\n i++\n ) {\n nearViewport.add(i)\n }\n setVisiblePages((prev) => (sameSet(prev, nearViewport) ? prev : nearViewport))\n }\n },\n [numPages, zoom]\n )\n\n // Memoize options to prevent unnecessary Document reloads.\n // When the options object changes reference, react-pdf reloads the document,\n // which fails if the source Blob's ArrayBuffer was already transferred to the worker.\n const documentOptions = useMemo(\n () => ({\n standardFontDataUrl,\n cMapUrl,\n cMapPacked: true,\n wasmUrl,\n ...(disableFontFace && { disableFontFace: true }),\n }),\n [standardFontDataUrl, cMapUrl, wasmUrl, disableFontFace]\n )\n\n // Observer callback is optional for consumers that don't track the page.\n const handlePageChange = useCallback(\n (pageNumber: number) => onPageChange?.(pageNumber),\n [onPageChange]\n )\n\n // Use IntersectionObserver to track visible pages and update page number\n usePageIntersectionObserver({\n containerRef,\n scrollCompleteRef,\n isEnabled: numPages > 0,\n getPageElements: () => Array.from(pageRefs.current.values()),\n getPageNumber: (element) => parseInt(element.getAttribute('data-page-number') ?? '0'),\n onPageChange: handlePageChange,\n onVisibilityUpdate: handleVisibilityUpdate,\n observeKey: `${numPages}:${containerWidth > 0}`,\n })\n\n // Pages above the reading position change height as they load their real size.\n useScrollAnchor(containerRef, `${numPages}:${containerWidth > 0}`)\n\n // Pinch / double-tap, and the focal point kept still for every zoom change.\n usePinchZoom({ containerRef, zoom, onZoomChange })\n\n // Layout follows `zoom` at once (a CSS scale of the already rendered canvas, so the gesture is\n // smooth); the canvases are re-rendered at the new resolution once the zoom has settled. Without\n // this the bitmap is only magnified and stays blurry.\n const [renderZoom, setRenderZoom] = useState(zoom)\n useEffect(() => {\n if (zoom === renderZoom) return\n const timer = setTimeout(() => setRenderZoom(zoom), RERENDER_DEBOUNCE_MS)\n return () => clearTimeout(timer)\n }, [zoom, renderZoom])\n\n return (\n <div\n ref={containerRef}\n className=\"w-full h-full overflow-auto bg-muted flex flex-col items-start p-4 pb-20\"\n // Two-finger gestures belong to the viewer (real zoom), not to the browser (bitmap zoom).\n // The scrollbar's gutter is always reserved, so the fit width does not change (and every page\n // re-rasterise) when the scrollbar appears, and cannot flip back and forth at the threshold.\n style={{ touchAction: 'pan-x pan-y', scrollbarGutter: 'stable' }}\n role=\"region\"\n aria-label=\"PDF document viewer\"\n data-testid=\"pdf-viewer\"\n >\n <Document\n // Wider than the scroller when zoomed in: the scroller pans horizontally over it.\n className=\"flex w-max min-w-full flex-col\"\n key={documentKey}\n // react-pdf 11 suspends while loading and sends failures to an error boundary. This viewer\n // owns its loading and error UI (and the password flow), so keep the callback behaviour.\n suspense={false}\n file={file}\n onLoadSuccess={onDocumentLoadSuccess}\n onLoadError={onDocumentLoadError}\n onPassword={onPassword}\n options={documentOptions}\n loading={\n <div className=\"flex items-center justify-center h-full\">\n <div className=\"text-sm text-muted-foreground\">Loading PDF...</div>\n </div>\n }\n error={\n <div className=\"flex flex-col items-center justify-center h-full gap-4 p-8\">\n <div className=\"text-destructive text-center\">\n {loadError?.message ===\n \"Cannot read properties of null (reading 'sendWithPromise')\" ? (\n <>\n <p className=\"font-semibold mb-2\">PDF viewer initialization failed</p>\n <p className=\"text-sm text-muted-foreground\">Please refresh the page to retry</p>\n </>\n ) : (\n <>\n <p className=\"font-semibold mb-2\">Failed to load PDF</p>\n {loadError && (\n <p className=\"text-sm text-muted-foreground\">{loadError.message}</p>\n )}\n </>\n )}\n </div>\n </div>\n }\n >\n {containerWidth > 0 &&\n Array.from(new Array(numPages), (_, index) => {\n const pageNumber = index + 1\n const shouldRender = renderedPages.has(pageNumber)\n const ratio = pageRatios.get(pageNumber) ?? defaultRatio\n const pageWidth = containerWidth * zoom\n const pageHeight = pageWidth * ratio\n // Resolution the canvas is (re-)rendered at, and how far it is CSS-scaled meanwhile.\n const renderWidth = containerWidth * renderZoom\n const scale = zoom / renderZoom\n // Only enable the text layer for pages in/near the viewport.\n // Pages in the wider render buffer get a canvas (so the image is ready when\n // the user scrolls to them) but no text spans until they're nearby — this\n // avoids committing thousands of DOM nodes synchronously on large documents.\n const shouldRenderTextLayer = visiblePages.has(pageNumber)\n\n return (\n <div\n key={`page_${pageNumber}`}\n ref={(el) => {\n if (el) {\n pageRefs.current.set(pageNumber, el)\n } else {\n pageRefs.current.delete(pageNumber)\n }\n }}\n data-page-number={pageNumber}\n // Fixed height in every state: a flex item would otherwise shrink (it is a\n // scroller itself via blocks.css) and a placeholder/real mismatch would shift the\n // pages below.\n className=\"relative mx-auto mb-6 shrink-0 shadow-xl bg-white border border-border\"\n style={{ width: pageWidth + PAGE_BORDER_PX, height: pageHeight + PAGE_BORDER_PX }}\n role=\"article\"\n aria-label={`Page ${pageNumber} of ${numPages}`}\n >\n {shouldRender ? (\n <div\n data-testid={`pdf-page-scaler-${pageNumber}`}\n style={\n scale === 1\n ? undefined\n : { transform: `scale(${scale})`, transformOrigin: '0 0' }\n }\n >\n <Page\n pageNumber={pageNumber}\n width={renderWidth}\n renderTextLayer={shouldRenderTextLayer}\n renderAnnotationLayer={false}\n onLoadSuccess={(page: { originalWidth: number; originalHeight: number }) => {\n setPageWidthsPt((prev) =>\n prev.get(pageNumber) === page.originalWidth\n ? prev\n : new Map(prev).set(pageNumber, page.originalWidth)\n )\n const ratio = page.originalHeight / page.originalWidth\n setPageRatios((prev) =>\n Math.abs((prev.get(pageNumber) ?? defaultRatio) - ratio) < 0.001\n ? prev\n : new Map(prev).set(pageNumber, ratio)\n )\n }}\n // DPR capped at 2x and lowered further when the page would exceed the canvas\n // pixel budget (zoomed pages are big; iOS Safari fails above ~16.7M pixels).\n devicePixelRatio={renderDpr(\n renderWidth,\n renderWidth * ratio,\n window.devicePixelRatio || 1\n )}\n loading={\n <div\n className=\"flex items-center justify-center bg-muted\"\n style={{ width: renderWidth, height: renderWidth * ratio }}\n >\n <div className=\"text-sm text-muted-foreground\">\n Loading page {pageNumber}...\n </div>\n </div>\n }\n />\n </div>\n ) : (\n <div\n className=\"flex items-center justify-center bg-muted\"\n style={{ width: pageWidth, height: pageHeight }}\n >\n <div className=\"text-sm text-muted-foreground\">Page {pageNumber}</div>\n </div>\n )}\n {renderPageOverlay?.({ pageNumber, pageWidthPt: pageWidthsPt.get(pageNumber) })}\n </div>\n )\n })}\n </Document>\n </div>\n )\n}\n"]}
@@ -52,4 +52,11 @@ interface PdfViewerProps {
52
52
  }
53
53
  declare function PdfViewer({ file, currentPage, onLoadSuccess, scrollTrigger, zoom, onZoomChange, onPageChange, disableFontFace, assets, renderPageOverlay, }: PdfViewerProps): React.JSX.Element;
54
54
 
55
- export { PdfViewer as P, type PdfViewerAssets as a, type PdfViewerProps as b };
55
+ declare const __PdfViewerImpl_PdfViewer: typeof PdfViewer;
56
+ type __PdfViewerImpl_PdfViewerAssets = PdfViewerAssets;
57
+ type __PdfViewerImpl_PdfViewerProps = PdfViewerProps;
58
+ declare namespace __PdfViewerImpl {
59
+ export { __PdfViewerImpl_PdfViewer as PdfViewer, type __PdfViewerImpl_PdfViewerAssets as PdfViewerAssets, type __PdfViewerImpl_PdfViewerProps as PdfViewerProps };
60
+ }
61
+
62
+ export { type PdfViewerAssets as P, __PdfViewerImpl as _, type PdfViewerProps as a };
@@ -52,4 +52,11 @@ interface PdfViewerProps {
52
52
  }
53
53
  declare function PdfViewer({ file, currentPage, onLoadSuccess, scrollTrigger, zoom, onZoomChange, onPageChange, disableFontFace, assets, renderPageOverlay, }: PdfViewerProps): React.JSX.Element;
54
54
 
55
- export { PdfViewer as P, type PdfViewerAssets as a, type PdfViewerProps as b };
55
+ declare const __PdfViewerImpl_PdfViewer: typeof PdfViewer;
56
+ type __PdfViewerImpl_PdfViewerAssets = PdfViewerAssets;
57
+ type __PdfViewerImpl_PdfViewerProps = PdfViewerProps;
58
+ declare namespace __PdfViewerImpl {
59
+ export { __PdfViewerImpl_PdfViewer as PdfViewer, type __PdfViewerImpl_PdfViewerAssets as PdfViewerAssets, type __PdfViewerImpl_PdfViewerProps as PdfViewerProps };
60
+ }
61
+
62
+ export { type PdfViewerAssets as P, __PdfViewerImpl as _, type PdfViewerProps as a };
@@ -1,5 +1,5 @@
1
1
  import { a as AnnotationKind, b as AnnotationLayer, A as Annotation } from '../../model.d-CNtRWKVK.cjs';
2
- import { a as PdfViewerAssets } from '../../PdfViewer.d-bQH9yxFg.cjs';
2
+ import { P as PdfViewerAssets } from '../../PdfViewerImpl.d-B28hLEuj.cjs';
3
3
  export { B as BatesOptions, a as BundleFile, b as BundleIndexEntry, c as BundleItem, d as BundleLayout, e as BundleOptions, f as BundleResult, S as StampCorner, g as batesLabel, h as buildBundle } from '../../bundle.d-BnCSbHy2.cjs';
4
4
  import 'react';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { a as AnnotationKind, b as AnnotationLayer, A as Annotation } from '../../model.d-CNtRWKVK.js';
2
- import { a as PdfViewerAssets } from '../../PdfViewer.d-bQH9yxFg.js';
2
+ import { P as PdfViewerAssets } from '../../PdfViewerImpl.d-B28hLEuj.js';
3
3
  export { B as BatesOptions, a as BundleFile, b as BundleIndexEntry, c as BundleItem, d as BundleLayout, e as BundleOptions, f as BundleResult, S as StampCorner, g as batesLabel, h as buildBundle } from '../../bundle.d-BnCSbHy2.js';
4
4
  import 'react';
5
5
 
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunkRVUGSM65_cjs = require('../chunk-RVUGSM65.cjs');
4
- var chunk5HDKL6XB_cjs = require('../chunk-5HDKL6XB.cjs');
3
+ var chunkGKGAPU6T_cjs = require('../chunk-GKGAPU6T.cjs');
4
+ var chunkYMB6XUR2_cjs = require('../chunk-YMB6XUR2.cjs');
5
5
  var chunk3AADNIOK_cjs = require('../chunk-3AADNIOK.cjs');
6
- var chunk7LIMHY56_cjs = require('../chunk-7LIMHY56.cjs');
6
+ var chunkO32T7XRD_cjs = require('../chunk-O32T7XRD.cjs');
7
7
  require('../chunk-N73IMVFF.cjs');
8
8
  var chunkNDIKMOBJ_cjs = require('../chunk-NDIKMOBJ.cjs');
9
9
  var chunkVOFNX4P6_cjs = require('../chunk-VOFNX4P6.cjs');
@@ -270,7 +270,7 @@ var isRefusal = (error) => {
270
270
  return code === 401 || code === 403;
271
271
  };
272
272
  function useArtifactText(docId, options) {
273
- const arbi = chunk7LIMHY56_cjs.useArbi();
273
+ const arbi = chunkO32T7XRD_cjs.useArbi();
274
274
  const { attempts, baseDelayMs, maxDelayMs } = {
275
275
  ...DEFAULT_ARTIFACT_TEXT_RETRY,
276
276
  ...options?.retry
@@ -278,7 +278,7 @@ function useArtifactText(docId, options) {
278
278
  const enabled = (options?.enabled ?? true) && chunkNDIKMOBJ_cjs.isDocumentId(docId) && arbi.hasWorkspace;
279
279
  const query = reactQuery.useQuery({
280
280
  // Under the shared `parsedDoc` key, so a document's invalidation reaches it too.
281
- queryKey: [...chunk7LIMHY56_cjs.arbiQueryKeys.parsedDoc(docId ?? "", "marker"), "artifact-text"],
281
+ queryKey: [...chunkO32T7XRD_cjs.arbiQueryKeys.parsedDoc(docId ?? "", "marker"), "artifact-text"],
282
282
  queryFn: async () => {
283
283
  const { docId: plainId, version } = chunkNDIKMOBJ_cjs.parseVersionRef(docId);
284
284
  const parsed = await arbi.documents.getParsedContent(
@@ -326,12 +326,12 @@ function useArtifactText(docId, options) {
326
326
  // src/artifacts/useArtifactSession.ts
327
327
  function useArtifactVersions(workspaceId, docId) {
328
328
  const plainId = docId ? chunkNDIKMOBJ_cjs.parseVersionRef(docId).docId : null;
329
- const { data: documents } = chunkRVUGSM65_cjs.useDocuments(workspaceId);
329
+ const { data: documents } = chunkGKGAPU6T_cjs.useDocuments(workspaceId);
330
330
  const listed = react.useMemo(
331
331
  () => (documents ?? []).find((d) => d.external_id === plainId),
332
332
  [documents, plainId]
333
333
  );
334
- const { data: history } = chunk5HDKL6XB_cjs.useDocumentVersionList(plainId, {
334
+ const { data: history } = chunkYMB6XUR2_cjs.useDocumentVersionList(plainId, {
335
335
  enabled: !!plainId && documents !== void 0 && !listed
336
336
  });
337
337
  return react.useMemo(
@@ -340,7 +340,7 @@ function useArtifactVersions(workspaceId, docId) {
340
340
  );
341
341
  }
342
342
  function useSaveArtifactVersion() {
343
- const arbi = chunk7LIMHY56_cjs.useArbi();
343
+ const arbi = chunkO32T7XRD_cjs.useArbi();
344
344
  const queryClient = reactQuery.useQueryClient();
345
345
  return reactQuery.useMutation({
346
346
  mutationFn: async ({ title, content, versionOf, configId, wpType }) => {
@@ -355,10 +355,10 @@ function useSaveArtifactVersion() {
355
355
  }
356
356
  );
357
357
  const docId = result.doc_ext_ids?.[0];
358
- if (docId) await chunkRVUGSM65_cjs.refreshDocuments(queryClient, arbi, [docId]);
359
- await queryClient.invalidateQueries({ queryKey: chunk7LIMHY56_cjs.arbiQueryKeys.allDocumentVersions() });
358
+ if (docId) await chunkGKGAPU6T_cjs.refreshDocuments(queryClient, arbi, [docId]);
359
+ await queryClient.invalidateQueries({ queryKey: chunkO32T7XRD_cjs.arbiQueryKeys.allDocumentVersions() });
360
360
  if (docId)
361
- await queryClient.invalidateQueries({ queryKey: chunk7LIMHY56_cjs.arbiQueryKeys.parsedDocument(docId) });
361
+ await queryClient.invalidateQueries({ queryKey: chunkO32T7XRD_cjs.arbiQueryKeys.parsedDocument(docId) });
362
362
  return { docId, version: result.version ?? void 0 };
363
363
  }
364
364
  });
@@ -475,9 +475,9 @@ function useArtifactSession(options) {
475
475
  );
476
476
  }
477
477
  function useArtifactSource(documentId, enabled = true) {
478
- const arbi = chunk7LIMHY56_cjs.useArbi();
478
+ const arbi = chunkO32T7XRD_cjs.useArbi();
479
479
  return reactQuery.useQuery({
480
- queryKey: chunk7LIMHY56_cjs.arbiQueryKeys.artifactSource(documentId ?? ""),
480
+ queryKey: chunkO32T7XRD_cjs.arbiQueryKeys.artifactSource(documentId ?? ""),
481
481
  queryFn: async () => (await arbi.documents.download(documentId)).text(),
482
482
  enabled: enabled && !!documentId && arbi.isLoggedIn,
483
483
  staleTime: 5 * 60 * 1e3
@@ -1,8 +1,8 @@
1
- import { useDocuments, refreshDocuments } from '../chunk-P6WLV5UY.js';
2
- import { useDocumentVersionList } from '../chunk-H5M7FXLB.js';
1
+ import { useDocuments, refreshDocuments } from '../chunk-XWPLOFDN.js';
2
+ import { useDocumentVersionList } from '../chunk-4FL3X3LA.js';
3
3
  import { revertRedlineRegion, buildHybridRedlineWithRegions, buildHybridRedlineMarkdown } from '../chunk-74N436VK.js';
4
4
  export { buildHybridRedlineMarkdown, buildHybridRedlineWithRegions, revertRedlineRegion } from '../chunk-74N436VK.js';
5
- import { useArbi, arbiQueryKeys } from '../chunk-6H3O63TQ.js';
5
+ import { useArbi, arbiQueryKeys } from '../chunk-ZM6N7YZH.js';
6
6
  import '../chunk-DPYBZDJB.js';
7
7
  import { isDocumentId, parseVersionRef, flattenChunks, documentVersions, toArtifactVersions, findVersion, versionLabel, cleanDraftWithReport } from '../chunk-UW2SGTI5.js';
8
8
  export { cleanDraftMarkdown, cleanDraftWithReport, documentVersions, findVersion, flattenChunks, isDocumentId, parseVersionRef, promoteBoldTitle, repairParsedStructure, repairParsedTitle, savedFromId, stripAgentPreamble, toArtifactVersions, unescapeMarkdown, unwrapCitationLinks, versionLabel, versionRef } from '../chunk-UW2SGTI5.js';