@cannymindstech/file-viewers 0.27.11 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/package.json +2 -2
  2. package/dist/chunk-2BLHLWNN.js +0 -299
  3. package/dist/chunk-2BLHLWNN.js.map +0 -1
  4. package/dist/chunk-6BRYDA3B.js +0 -329
  5. package/dist/chunk-6BRYDA3B.js.map +0 -1
  6. package/dist/chunk-7JPF5AYR.mjs +0 -488
  7. package/dist/chunk-7JPF5AYR.mjs.map +0 -1
  8. package/dist/chunk-7P6WEBHN.js +0 -2299
  9. package/dist/chunk-7P6WEBHN.js.map +0 -1
  10. package/dist/chunk-7PMZ4GN5.mjs +0 -290
  11. package/dist/chunk-7PMZ4GN5.mjs.map +0 -1
  12. package/dist/chunk-B5NNB4KD.mjs +0 -268
  13. package/dist/chunk-B5NNB4KD.mjs.map +0 -1
  14. package/dist/chunk-CIWCHSAA.js +0 -309
  15. package/dist/chunk-CIWCHSAA.js.map +0 -1
  16. package/dist/chunk-D7SDEVDM.js +0 -268
  17. package/dist/chunk-D7SDEVDM.js.map +0 -1
  18. package/dist/chunk-ECZ6IBOS.js +0 -424
  19. package/dist/chunk-ECZ6IBOS.js.map +0 -1
  20. package/dist/chunk-EI3EP65I.mjs +0 -868
  21. package/dist/chunk-EI3EP65I.mjs.map +0 -1
  22. package/dist/chunk-EKNP342T.mjs +0 -299
  23. package/dist/chunk-EKNP342T.mjs.map +0 -1
  24. package/dist/chunk-EM63H4SA.js +0 -290
  25. package/dist/chunk-EM63H4SA.js.map +0 -1
  26. package/dist/chunk-IJMNPAXX.mjs +0 -309
  27. package/dist/chunk-IJMNPAXX.mjs.map +0 -1
  28. package/dist/chunk-KJNOBIUZ.mjs +0 -36
  29. package/dist/chunk-KJNOBIUZ.mjs.map +0 -1
  30. package/dist/chunk-KQCU7XW2.mjs +0 -424
  31. package/dist/chunk-KQCU7XW2.mjs.map +0 -1
  32. package/dist/chunk-MPTCXAXO.js +0 -868
  33. package/dist/chunk-MPTCXAXO.js.map +0 -1
  34. package/dist/chunk-OPJOCUSL.js +0 -36
  35. package/dist/chunk-OPJOCUSL.js.map +0 -1
  36. package/dist/chunk-PZGUVU6N.mjs +0 -2299
  37. package/dist/chunk-PZGUVU6N.mjs.map +0 -1
  38. package/dist/chunk-QV63FULE.js +0 -488
  39. package/dist/chunk-QV63FULE.js.map +0 -1
  40. package/dist/chunk-XJQ5J2UF.mjs +0 -329
  41. package/dist/chunk-XJQ5J2UF.mjs.map +0 -1
  42. package/dist/components/viewers/AudioViewer.d.mts +0 -6
  43. package/dist/components/viewers/AudioViewer.d.ts +0 -6
  44. package/dist/components/viewers/AudioViewer.js +0 -10
  45. package/dist/components/viewers/AudioViewer.js.map +0 -1
  46. package/dist/components/viewers/AudioViewer.mjs +0 -10
  47. package/dist/components/viewers/AudioViewer.mjs.map +0 -1
  48. package/dist/components/viewers/DefaultViewer.d.mts +0 -6
  49. package/dist/components/viewers/DefaultViewer.d.ts +0 -6
  50. package/dist/components/viewers/DefaultViewer.js +0 -10
  51. package/dist/components/viewers/DefaultViewer.js.map +0 -1
  52. package/dist/components/viewers/DefaultViewer.mjs +0 -10
  53. package/dist/components/viewers/DefaultViewer.mjs.map +0 -1
  54. package/dist/components/viewers/ImageViewer.d.mts +0 -6
  55. package/dist/components/viewers/ImageViewer.d.ts +0 -6
  56. package/dist/components/viewers/ImageViewer.js +0 -10
  57. package/dist/components/viewers/ImageViewer.js.map +0 -1
  58. package/dist/components/viewers/ImageViewer.mjs +0 -10
  59. package/dist/components/viewers/ImageViewer.mjs.map +0 -1
  60. package/dist/components/viewers/PDFViewer.d.mts +0 -51
  61. package/dist/components/viewers/PDFViewer.d.ts +0 -51
  62. package/dist/components/viewers/PDFViewer.js +0 -11
  63. package/dist/components/viewers/PDFViewer.js.map +0 -1
  64. package/dist/components/viewers/PDFViewer.mjs +0 -11
  65. package/dist/components/viewers/PDFViewer.mjs.map +0 -1
  66. package/dist/components/viewers/TIFFViewer.d.mts +0 -6
  67. package/dist/components/viewers/TIFFViewer.d.ts +0 -6
  68. package/dist/components/viewers/TIFFViewer.js +0 -10
  69. package/dist/components/viewers/TIFFViewer.js.map +0 -1
  70. package/dist/components/viewers/TIFFViewer.mjs +0 -10
  71. package/dist/components/viewers/TIFFViewer.mjs.map +0 -1
  72. package/dist/components/viewers/TextViewer.d.mts +0 -6
  73. package/dist/components/viewers/TextViewer.d.ts +0 -6
  74. package/dist/components/viewers/TextViewer.js +0 -10
  75. package/dist/components/viewers/TextViewer.js.map +0 -1
  76. package/dist/components/viewers/TextViewer.mjs +0 -10
  77. package/dist/components/viewers/TextViewer.mjs.map +0 -1
  78. package/dist/components/viewers/VideoViewer.d.mts +0 -6
  79. package/dist/components/viewers/VideoViewer.d.ts +0 -6
  80. package/dist/components/viewers/VideoViewer.js +0 -10
  81. package/dist/components/viewers/VideoViewer.js.map +0 -1
  82. package/dist/components/viewers/VideoViewer.mjs +0 -10
  83. package/dist/components/viewers/VideoViewer.mjs.map +0 -1
  84. package/dist/index.d.mts +0 -75
  85. package/dist/index.d.ts +0 -75
  86. package/dist/index.js +0 -305
  87. package/dist/index.js.map +0 -1
  88. package/dist/index.mjs +0 -305
  89. package/dist/index.mjs.map +0 -1
  90. package/dist/types-BYTxtKEc.d.mts +0 -100
  91. package/dist/types-BYTxtKEc.d.ts +0 -100
@@ -1,868 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
2
-
3
-
4
- var _chunkOPJOCUSLjs = require('./chunk-OPJOCUSL.js');
5
-
6
-
7
-
8
- var _chunkEM63H4SAjs = require('./chunk-EM63H4SA.js');
9
-
10
- // src/components/viewers/TIFFViewer.tsx
11
-
12
-
13
-
14
-
15
-
16
-
17
- var _react = require('react');
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
- var _material = require('@mui/material');
29
- var _Download = require('@mui/icons-material/Download'); var _Download2 = _interopRequireDefault(_Download);
30
- var _Print = require('@mui/icons-material/Print'); var _Print2 = _interopRequireDefault(_Print);
31
- var _Fullscreen = require('@mui/icons-material/Fullscreen'); var _Fullscreen2 = _interopRequireDefault(_Fullscreen);
32
- var _FirstPage = require('@mui/icons-material/FirstPage'); var _FirstPage2 = _interopRequireDefault(_FirstPage);
33
- var _LastPage = require('@mui/icons-material/LastPage'); var _LastPage2 = _interopRequireDefault(_LastPage);
34
- var _ChevronLeft = require('@mui/icons-material/ChevronLeft'); var _ChevronLeft2 = _interopRequireDefault(_ChevronLeft);
35
- var _ChevronRight = require('@mui/icons-material/ChevronRight'); var _ChevronRight2 = _interopRequireDefault(_ChevronRight);
36
- var _ZoomIn = require('@mui/icons-material/ZoomIn'); var _ZoomIn2 = _interopRequireDefault(_ZoomIn);
37
- var _ZoomOut = require('@mui/icons-material/ZoomOut'); var _ZoomOut2 = _interopRequireDefault(_ZoomOut);
38
- var _FitScreen = require('@mui/icons-material/FitScreen'); var _FitScreen2 = _interopRequireDefault(_FitScreen);
39
- var _AspectRatio = require('@mui/icons-material/AspectRatio'); var _AspectRatio2 = _interopRequireDefault(_AspectRatio);
40
- var _Info = require('@mui/icons-material/Info'); var _Info2 = _interopRequireDefault(_Info);
41
- var _Description = require('@mui/icons-material/Description'); var _Description2 = _interopRequireDefault(_Description);
42
- var _History = require('@mui/icons-material/History'); var _History2 = _interopRequireDefault(_History);
43
- var _iconsmaterial = require('@mui/icons-material');
44
- var _utif = require('utif'); var UTIF = _interopRequireWildcard(_utif);
45
- var _jsxruntime = require('react/jsx-runtime');
46
- var resolveDocumentName = (file, fileName, url) => {
47
- if (_optionalChain([file, 'optionalAccess', _ => _.name])) {
48
- return file.name;
49
- }
50
- if (fileName) {
51
- return fileName;
52
- }
53
- if (url) {
54
- const parts = _nullishCoalesce(_optionalChain([url, 'access', _2 => _2.split, 'call', _3 => _3("?"), 'access', _4 => _4[0], 'optionalAccess', _5 => _5.split, 'call', _6 => _6("#"), 'access', _7 => _7[0], 'optionalAccess', _8 => _8.split, 'call', _9 => _9("/")]), () => ( []));
55
- return parts[parts.length - 1] || "document.tiff";
56
- }
57
- return "document.tiff";
58
- };
59
- var TIFFViewerContent = ({
60
- sourceDescription,
61
- file,
62
- url,
63
- fileName,
64
- totalPages = 1,
65
- className = "",
66
- style = {},
67
- width = "100%",
68
- height = "100%",
69
- onLoad,
70
- onError,
71
- onDownloadClick,
72
- onPrintClick,
73
- onTagsClick,
74
- onMetadataClick,
75
- onPropertiesClick,
76
- onHistoryClick,
77
- pageLoader,
78
- showDownload = true,
79
- showPrint = true,
80
- showMetadata = false,
81
- showTags = true,
82
- showProperties = false,
83
- showHistory = true,
84
- // Extract props that shouldn't be passed to DOM elements
85
- mimeType,
86
- fileSize,
87
- showPageCount,
88
- showPageNavigation,
89
- showZoomControls,
90
- showSearch,
91
- customRegistry,
92
- initialSearchText,
93
- initialSearchPages,
94
- autoOpenSearch,
95
- autoExecuteSearch,
96
- onSearchComplete,
97
- toolbarActions,
98
- // Annotation-related FileViewerProps (PDF only) — extract so they don't
99
- // leak onto the DOM via {...props} on <Box>.
100
- showAnnotations,
101
- userDetails,
102
- annotationSelectionMenu,
103
- isHighlighterActive,
104
- isStampActive,
105
- isNoteActive,
106
- onHighlighterClick,
107
- onStampClick,
108
- onSignatureClick,
109
- onNoteClick,
110
- permissions,
111
- isAnnotationForeign,
112
- onAnnotationNoteClick,
113
- isAnnotationInteractive,
114
- hasUnsavedAnnotations,
115
- isSavingAnnotations,
116
- canSaveAnnotations,
117
- onSaveAnnotations,
118
- onDownloadWithAnnotations,
119
- onDownloadWithoutAnnotations,
120
- onPrintWithAnnotations,
121
- onPrintWithoutAnnotations,
122
- showDownloadOriginal,
123
- showDownloadWithAnnotations,
124
- showPrintOriginal,
125
- showPrintWithAnnotations,
126
- showAnnotate,
127
- disabledAnnotate,
128
- showRotation,
129
- defaultFitToPage,
130
- loading,
131
- onPasswordRequest,
132
- ...props
133
- }) => {
134
- const [currentPage, setCurrentPage] = _react.useState.call(void 0, 1);
135
- const [isLoading, setIsLoading] = _react.useState.call(void 0, false);
136
- const [error, setError] = _react.useState.call(void 0, null);
137
- const [fitMode, setFitMode] = _react.useState.call(void 0,
138
- "fit-page"
139
- );
140
- const [zoom, setZoom] = _react.useState.call(void 0, 100);
141
- const [viewportWidth, setViewportWidth] = _react.useState.call(void 0, 0);
142
- const [viewportHeight, setViewportHeight] = _react.useState.call(void 0, 0);
143
- const [, setIsFullScreen] = _react.useState.call(void 0, false);
144
- const [imageUrl, setImageUrl] = _react.useState.call(void 0, null);
145
- const [pageImages, setPageImages] = _react.useState.call(void 0, /* @__PURE__ */ new Map());
146
- const [internalLoading, setInternalLoading] = _react.useState.call(void 0, false);
147
- const [imageSize, setImageSize] = _react.useState.call(void 0, null);
148
- const viewportRef = _react.useRef.call(void 0, null);
149
- const containerRef = _react.useRef.call(void 0, null);
150
- const imgRef = _react.useRef.call(void 0, null);
151
- const pageLoaderRef = _react.useRef.call(void 0, pageLoader);
152
- _react.useEffect.call(void 0, () => {
153
- pageLoaderRef.current = pageLoader;
154
- }, [pageLoader]);
155
- const [localTotalPages, setLocalTotalPages] = _react.useState.call(void 0, 0);
156
- const tiffSourceRef = _react.useRef.call(void 0, null);
157
- const effectiveTotalPages = localTotalPages || totalPages;
158
- const updatePageImage = _react.useCallback.call(void 0,
159
- (pageData, pageNumber) => {
160
- const blob = new Blob([pageData]);
161
- const imageUrl2 = URL.createObjectURL(blob);
162
- setPageImages((prev) => {
163
- const oldUrl = prev.get(pageNumber);
164
- if (oldUrl && oldUrl !== imageUrl2) {
165
- URL.revokeObjectURL(oldUrl);
166
- }
167
- return new Map(prev).set(pageNumber, imageUrl2);
168
- });
169
- setCurrentPage(pageNumber);
170
- setImageUrl(imageUrl2);
171
- },
172
- []
173
- );
174
- const decodeLocalPage = _react.useCallback.call(void 0,
175
- async (pageIndex) => {
176
- const source = tiffSourceRef.current;
177
- if (!source) return null;
178
- const image = source.ifds[pageIndex];
179
- if (!image) return null;
180
- UTIF.decodeImage(source.buffer, image);
181
- const rgba = UTIF.toRGBA8(image);
182
- const width2 = Number(image.width) || 0;
183
- const height2 = Number(image.height) || 0;
184
- if (!width2 || !height2) return null;
185
- const canvas = document.createElement("canvas");
186
- canvas.width = width2;
187
- canvas.height = height2;
188
- const ctx = canvas.getContext("2d");
189
- if (!ctx) return null;
190
- ctx.putImageData(
191
- new ImageData(new Uint8ClampedArray(rgba), width2, height2),
192
- 0,
193
- 0
194
- );
195
- return await new Promise((resolve) => {
196
- canvas.toBlob(async (blob) => {
197
- if (!blob) {
198
- resolve(null);
199
- return;
200
- }
201
- resolve(await blob.arrayBuffer());
202
- }, "image/png");
203
- });
204
- },
205
- []
206
- );
207
- _react.useEffect.call(void 0, () => {
208
- const loadInitialPage = async () => {
209
- if (pageLoaderRef.current && !pageImages.has(1) && currentPage === 1) {
210
- setInternalLoading(true);
211
- setError(null);
212
- try {
213
- const pageData = await pageLoaderRef.current(1);
214
- if (pageData) {
215
- updatePageImage(pageData, 1);
216
- } else {
217
- setError("Failed to load page 1");
218
- }
219
- } catch (err) {
220
- const message = err instanceof Error ? err.message : "Unable to load page 1";
221
- setError(message);
222
- _optionalChain([onError, 'optionalCall', _10 => _10(new Error(message))]);
223
- } finally {
224
- setInternalLoading(false);
225
- }
226
- }
227
- };
228
- loadInitialPage();
229
- }, [pageImages, currentPage, updatePageImage, onError]);
230
- _react.useEffect.call(void 0, () => {
231
- if (!file && !url) {
232
- tiffSourceRef.current = null;
233
- setLocalTotalPages(0);
234
- return;
235
- }
236
- let cancelled = false;
237
- (async () => {
238
- try {
239
- let buffer = null;
240
- if (file) {
241
- buffer = await file.arrayBuffer();
242
- } else if (url && !pageLoader) {
243
- buffer = await (await fetch(url)).arrayBuffer();
244
- }
245
- if (cancelled || !buffer) return;
246
- const ifds = UTIF.decode(buffer);
247
- if (!ifds.length) {
248
- throw new Error("No pages found in TIFF");
249
- }
250
- tiffSourceRef.current = { buffer, ifds };
251
- setLocalTotalPages(ifds.length);
252
- if (pageLoader) return;
253
- setInternalLoading(true);
254
- setError(null);
255
- setImageUrl(null);
256
- setImageSize(null);
257
- setPageImages((prev) => {
258
- prev.forEach((u) => URL.revokeObjectURL(u));
259
- return /* @__PURE__ */ new Map();
260
- });
261
- const firstPage = await decodeLocalPage(0);
262
- if (cancelled) return;
263
- if (!firstPage) {
264
- throw new Error("Failed to decode TIFF page 1");
265
- }
266
- updatePageImage(firstPage, 1);
267
- _optionalChain([onLoad, 'optionalCall', _11 => _11()]);
268
- } catch (err) {
269
- if (cancelled) return;
270
- const message = err instanceof Error ? err.message : "Failed to decode TIFF";
271
- if (!pageLoader) {
272
- setError(message);
273
- _optionalChain([onError, 'optionalCall', _12 => _12(new Error(message))]);
274
- } else {
275
- console.warn(`[TIFFViewer] Local IFD count failed: ${message}`);
276
- }
277
- } finally {
278
- if (!cancelled && !pageLoader) setInternalLoading(false);
279
- }
280
- })();
281
- return () => {
282
- cancelled = true;
283
- };
284
- }, [file, url, pageLoader, decodeLocalPage, updatePageImage, onLoad, onError]);
285
- const handlePageChange = _react.useCallback.call(void 0,
286
- async (newPageNumber) => {
287
- const hasExternalLoader = !!pageLoaderRef.current;
288
- const hasLocalSource = !!tiffSourceRef.current;
289
- if (!hasExternalLoader && !hasLocalSource) {
290
- console.warn("pageLoader not provided - page navigation disabled");
291
- return;
292
- }
293
- const cachedUrl = pageImages.get(newPageNumber);
294
- if (cachedUrl) {
295
- setCurrentPage(newPageNumber);
296
- setImageUrl(cachedUrl);
297
- return;
298
- }
299
- setError(null);
300
- try {
301
- const pageData = hasExternalLoader ? await pageLoaderRef.current(newPageNumber) : await decodeLocalPage(newPageNumber - 1);
302
- if (pageData) {
303
- updatePageImage(pageData, newPageNumber);
304
- } else {
305
- setError(`Failed to load page ${newPageNumber}`);
306
- }
307
- } catch (err) {
308
- const message = err instanceof Error ? err.message : `Unable to load page ${newPageNumber}`;
309
- setError(message);
310
- _optionalChain([onError, 'optionalCall', _13 => _13(new Error(message))]);
311
- }
312
- },
313
- [pageImages, onError, updatePageImage, decodeLocalPage]
314
- );
315
- const resolvedFileName = _react.useMemo.call(void 0,
316
- () => fileName || sourceDescription,
317
- [fileName, sourceDescription]
318
- );
319
- const fileExtension = _react.useMemo.call(void 0,
320
- () => _chunkOPJOCUSLjs.getFileExtension.call(void 0, resolvedFileName || ""),
321
- [resolvedFileName]
322
- );
323
- const loadImage = _react.useCallback.call(void 0,
324
- async (resetPage = false) => {
325
- if (!file && !url) {
326
- setImageUrl(null);
327
- if (resetPage) setCurrentPage(1);
328
- setError(null);
329
- return;
330
- }
331
- setIsLoading(true);
332
- setError(null);
333
- if (resetPage) {
334
- setCurrentPage(1);
335
- setFitMode("fit-page");
336
- setZoom(100);
337
- }
338
- setIsLoading(false);
339
- },
340
- [file, url]
341
- );
342
- const [previousFileSource, setPreviousFileSource] = _react.useState.call(void 0, {});
343
- _react.useEffect.call(void 0, () => {
344
- const currentFileSource = { file, url };
345
- const isNewFile = previousFileSource.file !== file || previousFileSource.url !== url;
346
- if (isNewFile) {
347
- setPreviousFileSource(currentFileSource);
348
- void loadImage(true);
349
- } else {
350
- void loadImage(false);
351
- }
352
- }, [file, url, loadImage, previousFileSource.file, previousFileSource.url]);
353
- _react.useEffect.call(void 0, () => {
354
- return () => {
355
- pageImages.forEach((url2) => {
356
- URL.revokeObjectURL(url2);
357
- });
358
- if (imageUrl && file && !pageImages.has(currentPage)) {
359
- URL.revokeObjectURL(imageUrl);
360
- }
361
- };
362
- }, []);
363
- const hasImage = !!imageUrl;
364
- const hasMultiplePages = effectiveTotalPages > 1;
365
- const MARGIN = 40;
366
- const MIN_ZOOM = 25;
367
- const MAX_ZOOM = 400;
368
- const ZOOM_LEVELS = [25, 50, 75, 100, 125, 150, 200, 300, 400];
369
- const calculateFitZoom = _react.useCallback.call(void 0,
370
- (mode) => {
371
- if (!imageSize || viewportWidth <= 0) return null;
372
- const availableWidth = viewportWidth - MARGIN;
373
- if (mode === "fit-width") {
374
- const calculatedZoom = Math.round(
375
- availableWidth / imageSize.width * 100
376
- );
377
- return Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, calculatedZoom));
378
- }
379
- if (mode === "fit-page" && viewportHeight > 0) {
380
- const availableHeight = viewportHeight - MARGIN;
381
- const scaleW = availableWidth / imageSize.width;
382
- const scaleH = availableHeight / imageSize.height;
383
- const calculatedZoom = Math.round(Math.min(scaleW, scaleH) * 100);
384
- return Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, calculatedZoom));
385
- }
386
- return null;
387
- },
388
- [imageSize, viewportWidth, viewportHeight]
389
- );
390
- _react.useEffect.call(void 0, () => {
391
- if (!hasImage || !imageSize) return;
392
- const newZoom = calculateFitZoom(fitMode);
393
- if (newZoom !== null) {
394
- setZoom(newZoom);
395
- }
396
- }, [currentPage, hasImage, imageSize, fitMode, calculateFitZoom]);
397
- _react.useEffect.call(void 0, () => {
398
- if (typeof window === "undefined" || typeof ResizeObserver === "undefined") {
399
- return void 0;
400
- }
401
- if (!viewportRef.current) {
402
- return void 0;
403
- }
404
- const updateSize = () => {
405
- const bounds = _optionalChain([viewportRef, 'access', _14 => _14.current, 'optionalAccess', _15 => _15.getBoundingClientRect, 'call', _16 => _16()]);
406
- if (bounds) {
407
- setViewportWidth(bounds.width);
408
- setViewportHeight(bounds.height);
409
- }
410
- };
411
- updateSize();
412
- const observer = new ResizeObserver(updateSize);
413
- observer.observe(viewportRef.current);
414
- return () => {
415
- observer.disconnect();
416
- };
417
- }, []);
418
- const handleZoomIn = _react.useCallback.call(void 0, () => {
419
- setFitMode("zoom");
420
- setZoom((value) => {
421
- const nextLevel = ZOOM_LEVELS.find((level) => level > value);
422
- return nextLevel || MAX_ZOOM;
423
- });
424
- }, []);
425
- const handleZoomOut = _react.useCallback.call(void 0, () => {
426
- setFitMode("zoom");
427
- setZoom((value) => {
428
- const prevLevel = [...ZOOM_LEVELS].reverse().find((level) => level < value);
429
- return prevLevel || MIN_ZOOM;
430
- });
431
- }, []);
432
- const handleFitWidth = _react.useCallback.call(void 0, () => {
433
- setFitMode("fit-width");
434
- const newZoom = calculateFitZoom("fit-width");
435
- if (newZoom !== null) {
436
- setZoom(newZoom);
437
- }
438
- }, [calculateFitZoom]);
439
- const handleFitPage = _react.useCallback.call(void 0, () => {
440
- setFitMode("fit-page");
441
- const newZoom = calculateFitZoom("fit-page");
442
- if (newZoom !== null) {
443
- setZoom(newZoom);
444
- }
445
- }, [calculateFitZoom]);
446
- const handleFirstPage = _react.useCallback.call(void 0, () => {
447
- handlePageChange(1);
448
- }, [handlePageChange]);
449
- const handleLastPage = _react.useCallback.call(void 0, () => {
450
- handlePageChange(effectiveTotalPages);
451
- }, [handlePageChange, effectiveTotalPages]);
452
- const handlePreviousPage = _react.useCallback.call(void 0, () => {
453
- const newPage = Math.max(currentPage - 1, 1);
454
- if (newPage !== currentPage) {
455
- handlePageChange(newPage);
456
- }
457
- }, [currentPage, handlePageChange]);
458
- const handleNextPage = _react.useCallback.call(void 0, () => {
459
- const newPage = Math.min(currentPage + 1, effectiveTotalPages);
460
- if (newPage !== currentPage) {
461
- handlePageChange(newPage);
462
- }
463
- }, [currentPage, effectiveTotalPages, handlePageChange]);
464
- const handleToggleFullScreen = _react.useCallback.call(void 0, () => {
465
- if (!document.fullscreenElement && _optionalChain([containerRef, 'access', _17 => _17.current, 'optionalAccess', _18 => _18.requestFullscreen])) {
466
- containerRef.current.requestFullscreen();
467
- } else if (document.fullscreenElement && document.exitFullscreen) {
468
- document.exitFullscreen();
469
- }
470
- }, []);
471
- _react.useEffect.call(void 0, () => {
472
- const onFullscreenChange = () => {
473
- setIsFullScreen(!!document.fullscreenElement);
474
- };
475
- document.addEventListener("fullscreenchange", onFullscreenChange);
476
- return () => {
477
- document.removeEventListener("fullscreenchange", onFullscreenChange);
478
- };
479
- }, []);
480
- const handlePrint = _react.useCallback.call(void 0, () => {
481
- if (!imageUrl) return;
482
- const printWindow = window.open("", "_blank", "width=900,height=1200");
483
- if (!printWindow) return;
484
- const doc = printWindow.document;
485
- doc.title = resolvedFileName || "Document";
486
- const style2 = doc.createElement("style");
487
- style2.textContent = "@page { margin: 0.5cm; }html, body { margin: 0; padding: 0; }img { display: block; width: 100%; height: auto; page-break-after: always; }";
488
- doc.head.appendChild(style2);
489
- const img = doc.createElement("img");
490
- img.alt = resolvedFileName || "Document";
491
- img.onload = () => {
492
- window.setTimeout(() => printWindow.print(), 100);
493
- };
494
- img.src = imageUrl;
495
- doc.body.appendChild(img);
496
- }, [imageUrl, resolvedFileName]);
497
- const toolbar = _chunkEM63H4SAjs.mergeToolbarConfig.call(void 0, {
498
- showDownload,
499
- showPrint,
500
- showMetadata,
501
- showTags,
502
- showProperties,
503
- showHistory,
504
- onDownloadClick,
505
- onPrintClick,
506
- onTagsClick,
507
- onMetadataClick,
508
- onPropertiesClick,
509
- onHistoryClick,
510
- toolbarActions
511
- });
512
- const displayScale = zoom;
513
- const handleImageLoad = _react.useCallback.call(void 0,
514
- (e) => {
515
- const img = e.currentTarget;
516
- setImageSize({ width: img.naturalWidth, height: img.naturalHeight });
517
- if (!hasImage) {
518
- _optionalChain([onLoad, 'optionalCall', _19 => _19()]);
519
- }
520
- },
521
- [hasImage, onLoad]
522
- );
523
- const renderImage = () => {
524
- if (!imageUrl) {
525
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, { variant: "body2", color: "text.secondary", children: "No image available." });
526
- }
527
- let imgStyle = {
528
- display: "block",
529
- borderRadius: "4px"
530
- };
531
- if (imageSize) {
532
- const zoomFactor = zoom / 100;
533
- const scaledWidth = imageSize.width * zoomFactor;
534
- const scaledHeight = imageSize.height * zoomFactor;
535
- imgStyle = {
536
- ...imgStyle,
537
- width: `${scaledWidth}px`,
538
- height: `${scaledHeight}px`,
539
- maxWidth: "none",
540
- maxHeight: "none"
541
- };
542
- }
543
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
544
- _material.Box,
545
- {
546
- component: "img",
547
- ref: imgRef,
548
- src: imageUrl,
549
- alt: `${resolvedFileName} page ${currentPage}`,
550
- onLoad: handleImageLoad,
551
- onError: () => {
552
- setError("Failed to load image");
553
- _optionalChain([onError, 'optionalCall', _20 => _20(new Error("Failed to load image"))]);
554
- },
555
- sx: {
556
- ...imgStyle,
557
- boxShadow: 1,
558
- backgroundColor: "#fff",
559
- margin: "20px"
560
- }
561
- }
562
- );
563
- };
564
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
565
- _material.Box,
566
- {
567
- ref: containerRef,
568
- className: `tiff-viewer ${className}`,
569
- sx: {
570
- width,
571
- height,
572
- display: "flex",
573
- flexDirection: "column",
574
- overflow: "hidden",
575
- ...style
576
- },
577
- ...props,
578
- children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
579
- _material.Card,
580
- {
581
- sx: {
582
- height: "100%",
583
- width: "100%",
584
- display: "flex",
585
- flexDirection: "column",
586
- overflow: "hidden"
587
- },
588
- elevation: 1,
589
- children: [
590
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
591
- _material.CardHeader,
592
- {
593
- avatar: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkEM63H4SAjs.FileIcon_default, { ext: fileExtension, size: 32 }),
594
- title: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, { variant: "subtitle1", fontWeight: 500, children: resolvedFileName }),
595
- sx: { pb: 1 }
596
- }
597
- ),
598
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, { sx: { px: 2, pb: 1, display: "flex", justifyContent: "center" }, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
599
- _material.Stack,
600
- {
601
- direction: "row",
602
- spacing: 1,
603
- alignItems: "center",
604
- flexWrap: "wrap",
605
- gap: 1,
606
- children: [
607
- hasMultiplePages && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
608
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
609
- _material.IconButton,
610
- {
611
- size: "small",
612
- onClick: handleFirstPage,
613
- disabled: currentPage === 1,
614
- title: "First Page",
615
- "aria-label": "Go to first page",
616
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _FirstPage2.default, { fontSize: "small" })
617
- }
618
- ),
619
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
620
- _material.IconButton,
621
- {
622
- size: "small",
623
- onClick: handlePreviousPage,
624
- disabled: currentPage === 1,
625
- title: "Previous Page",
626
- "aria-label": "Go to previous page",
627
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _ChevronLeft2.default, { fontSize: "small" })
628
- }
629
- ),
630
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
631
- _material.Typography,
632
- {
633
- variant: "body2",
634
- color: "text.secondary",
635
- sx: { minWidth: 100, textAlign: "center" },
636
- children: [
637
- "Page ",
638
- currentPage,
639
- " of ",
640
- effectiveTotalPages
641
- ]
642
- }
643
- ),
644
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
645
- _material.IconButton,
646
- {
647
- size: "small",
648
- onClick: handleNextPage,
649
- disabled: currentPage === effectiveTotalPages,
650
- title: "Next Page",
651
- "aria-label": "Go to next page",
652
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _ChevronRight2.default, { fontSize: "small" })
653
- }
654
- ),
655
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
656
- _material.IconButton,
657
- {
658
- size: "small",
659
- onClick: handleLastPage,
660
- disabled: currentPage === effectiveTotalPages,
661
- title: "Last Page",
662
- "aria-label": "Go to last page",
663
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _LastPage2.default, { fontSize: "small" })
664
- }
665
- ),
666
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Divider, { orientation: "vertical", flexItem: true, sx: { mx: 1 } })
667
- ] }),
668
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
669
- _material.IconButton,
670
- {
671
- size: "small",
672
- onClick: handleZoomOut,
673
- disabled: !hasImage || zoom <= 25,
674
- title: "Zoom Out",
675
- "aria-label": "Zoom out",
676
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _ZoomOut2.default, { fontSize: "small" })
677
- }
678
- ),
679
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
680
- _material.Typography,
681
- {
682
- variant: "body2",
683
- color: "text.secondary",
684
- sx: { minWidth: 64, textAlign: "center" },
685
- children: hasImage ? `${displayScale}%` : "\u2014"
686
- }
687
- ),
688
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
689
- _material.IconButton,
690
- {
691
- size: "small",
692
- onClick: handleZoomIn,
693
- disabled: !hasImage || zoom >= 400,
694
- title: "Zoom In",
695
- "aria-label": "Zoom in",
696
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _ZoomIn2.default, { fontSize: "small" })
697
- }
698
- ),
699
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
700
- _material.IconButton,
701
- {
702
- size: "small",
703
- onClick: handleFitWidth,
704
- disabled: !hasImage,
705
- title: "Fit to Width",
706
- "aria-label": "Fit to width",
707
- color: fitMode === "fit-width" ? "primary" : "default",
708
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _AspectRatio2.default, { fontSize: "small" })
709
- }
710
- ),
711
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
712
- _material.IconButton,
713
- {
714
- size: "small",
715
- onClick: handleFitPage,
716
- disabled: !hasImage,
717
- title: "Fit to Page",
718
- "aria-label": "Fit to page",
719
- color: fitMode === "fit-page" ? "primary" : "default",
720
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _FitScreen2.default, { fontSize: "small" })
721
- }
722
- ),
723
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Divider, { orientation: "vertical", flexItem: true, sx: { mx: 1 } }),
724
- !toolbar.isHidden("download") && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
725
- _material.IconButton,
726
- {
727
- size: "small",
728
- onClick: toolbar.getHandler("download", onDownloadClick),
729
- disabled: toolbar.isDisabled("download"),
730
- title: toolbar.getLabel("download") || "Download",
731
- "aria-label": "Download TIFF",
732
- children: toolbar.getIcon("download") || /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Download2.default, { fontSize: "small" })
733
- }
734
- ),
735
- !toolbar.isHidden("print") && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
736
- _material.IconButton,
737
- {
738
- size: "small",
739
- onClick: toolbar.getHandler("print", onPrintClick || handlePrint),
740
- disabled: toolbar.isDisabled("print"),
741
- title: toolbar.getLabel("print") || "Print",
742
- "aria-label": "Print TIFF",
743
- children: toolbar.getIcon("print") || /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Print2.default, { fontSize: "small" })
744
- }
745
- ),
746
- !toolbar.isHidden("fullscreen") && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
747
- _material.IconButton,
748
- {
749
- size: "small",
750
- onClick: toolbar.getHandler(
751
- "fullscreen",
752
- handleToggleFullScreen
753
- ),
754
- disabled: toolbar.isDisabled("fullscreen"),
755
- title: toolbar.getLabel("fullscreen") || "Fullscreen",
756
- "aria-label": "Toggle fullscreen",
757
- children: toolbar.getIcon("fullscreen") || /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Fullscreen2.default, { fontSize: "small" })
758
- }
759
- ),
760
- !toolbar.isHidden("metadata") && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
761
- _material.IconButton,
762
- {
763
- size: "small",
764
- onClick: toolbar.getHandler("metadata", onMetadataClick),
765
- disabled: toolbar.isDisabled("metadata"),
766
- title: toolbar.getLabel("metadata") || "Document Metadata",
767
- "aria-label": "View document metadata",
768
- children: toolbar.getIcon("metadata") || /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Description2.default, { fontSize: "small" })
769
- }
770
- ),
771
- !toolbar.isHidden("properties") && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
772
- _material.IconButton,
773
- {
774
- size: "small",
775
- onClick: toolbar.getHandler("properties", onPropertiesClick),
776
- disabled: toolbar.isDisabled("properties"),
777
- title: toolbar.getLabel("properties") || "Document Properties",
778
- "aria-label": "View document properties",
779
- children: toolbar.getIcon("properties") || /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Info2.default, { fontSize: "small" })
780
- }
781
- ),
782
- !toolbar.isHidden("tags") && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
783
- _material.IconButton,
784
- {
785
- size: "small",
786
- onClick: toolbar.getHandler("tags", onTagsClick),
787
- disabled: toolbar.isDisabled("tags"),
788
- title: toolbar.getLabel("tags") || "Document Tags",
789
- "aria-label": "View document tags",
790
- children: toolbar.getIcon("tags") || /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _iconsmaterial.LocalOffer, { fontSize: "small" })
791
- }
792
- ),
793
- !toolbar.isHidden("history") && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
794
- _material.IconButton,
795
- {
796
- size: "small",
797
- onClick: toolbar.getHandler("history", onHistoryClick),
798
- disabled: toolbar.isDisabled("history"),
799
- title: toolbar.getLabel("history") || "Document History",
800
- "aria-label": "View document history",
801
- children: toolbar.getIcon("history") || /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _History2.default, { fontSize: "small" })
802
- }
803
- )
804
- ]
805
- }
806
- ) }),
807
- (isLoading || internalLoading) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.LinearProgress, { sx: { mx: 3, mb: 1 } }),
808
- error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, { color: "error", variant: "body2", sx: { px: 3, pb: 1 }, children: error }),
809
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Divider, {}),
810
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
811
- _material.CardContent,
812
- {
813
- sx: {
814
- flexGrow: 1,
815
- flexShrink: 1,
816
- minHeight: 0,
817
- p: 0,
818
- overflow: "hidden",
819
- backgroundColor: "#f6f8fa",
820
- position: "relative"
821
- },
822
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
823
- _material.Box,
824
- {
825
- ref: viewportRef,
826
- sx: {
827
- position: "absolute",
828
- top: 0,
829
- left: 0,
830
- right: 0,
831
- bottom: 0,
832
- overflow: "auto"
833
- },
834
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
835
- _material.Box,
836
- {
837
- sx: {
838
- minWidth: "100%",
839
- minHeight: "100%",
840
- display: "flex",
841
- alignItems: "center",
842
- justifyContent: "center"
843
- },
844
- children: renderImage()
845
- }
846
- )
847
- }
848
- )
849
- }
850
- )
851
- ]
852
- }
853
- )
854
- }
855
- );
856
- };
857
- var TIFFViewer = (props) => {
858
- const sourceDescription = _react.useMemo.call(void 0,
859
- () => resolveDocumentName(props.file, props.fileName, props.url),
860
- [props.file, props.fileName, props.url]
861
- );
862
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TIFFViewerContent, { ...props, sourceDescription });
863
- };
864
-
865
-
866
-
867
- exports.TIFFViewer = TIFFViewer;
868
- //# sourceMappingURL=chunk-MPTCXAXO.js.map