viewdoc 0.1.1 → 0.2.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 (44) hide show
  1. package/README.md +6 -3
  2. package/dist/DocxViewer-VQN3BESX.js +8 -0
  3. package/dist/DocxViewer-VQN3BESX.js.map +1 -0
  4. package/dist/PdfViewer-NVAQBI2Y.js +8 -0
  5. package/dist/PdfViewer-NVAQBI2Y.js.map +1 -0
  6. package/dist/XlsxViewer-SQMAF5UA.js +8 -0
  7. package/dist/XlsxViewer-SQMAF5UA.js.map +1 -0
  8. package/dist/chunk-4VVVAGYE.js +110 -0
  9. package/dist/chunk-4VVVAGYE.js.map +1 -0
  10. package/dist/chunk-KRN2POC4.js +174 -0
  11. package/dist/chunk-KRN2POC4.js.map +1 -0
  12. package/dist/chunk-LE4YTMPN.js +135 -0
  13. package/dist/chunk-LE4YTMPN.js.map +1 -0
  14. package/dist/chunk-OA35SYM6.js +432 -0
  15. package/dist/chunk-OA35SYM6.js.map +1 -0
  16. package/dist/docx.cjs +566 -0
  17. package/dist/docx.cjs.map +1 -0
  18. package/dist/docx.d.cts +43 -0
  19. package/dist/docx.d.ts +43 -0
  20. package/dist/docx.js +8 -0
  21. package/dist/docx.js.map +1 -0
  22. package/dist/index.cjs +235 -116
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +9 -150
  25. package/dist/index.d.ts +9 -150
  26. package/dist/index.js +21 -828
  27. package/dist/index.js.map +1 -1
  28. package/dist/pdf.cjs +631 -0
  29. package/dist/pdf.cjs.map +1 -0
  30. package/dist/pdf.d.cts +45 -0
  31. package/dist/pdf.d.ts +45 -0
  32. package/dist/pdf.js +8 -0
  33. package/dist/pdf.js.map +1 -0
  34. package/dist/useDraggable-QvFR-4DD.d.cts +33 -0
  35. package/dist/useDraggable-QvFR-4DD.d.ts +33 -0
  36. package/dist/xlsx.cjs +591 -0
  37. package/dist/xlsx.cjs.map +1 -0
  38. package/dist/xlsx.d.cts +43 -0
  39. package/dist/xlsx.d.ts +43 -0
  40. package/dist/xlsx.js +8 -0
  41. package/dist/xlsx.js.map +1 -0
  42. package/package.json +16 -1
  43. package/dist/styles.d.cts +0 -2
  44. package/dist/styles.d.ts +0 -2
@@ -0,0 +1,43 @@
1
+ import * as react from 'react';
2
+ import { CSSProperties } from 'react';
3
+ import { V as ViewerTheme, P as Position } from './useDraggable-QvFR-4DD.cjs';
4
+
5
+ interface DocxViewerProps {
6
+ /** URL of the .docx file to display. */
7
+ uri: string;
8
+ /** Used as the suggested filename on download. */
9
+ fileName?: string;
10
+ className?: string;
11
+ style?: CSSProperties;
12
+ /** Width of the viewer. Accepts any CSS size (e.g. 1200, '1200px', '100%'). Default: 1200. */
13
+ width?: number | string;
14
+ /** Height of the viewer. Accepts any CSS size (e.g. 700, '700px', '100vh'). Default: 700. */
15
+ height?: number | string;
16
+ /** Minimum zoom scale. Default: 0.5 */
17
+ minScale?: number;
18
+ /** Maximum zoom scale. Default: 3 */
19
+ maxScale?: number;
20
+ /** Zoom increment per step (buttons / Ctrl+scroll). Default: 0.25 */
21
+ zoomStep?: number;
22
+ /** Show zoom in/out and reset-to-100% controls. Default: true. */
23
+ enableZoomControls?: boolean;
24
+ /** Allow Ctrl/Cmd + scroll wheel to zoom. Default: true. */
25
+ enableWheelZoom?: boolean;
26
+ /** Show the fullscreen toggle button. Default: true. */
27
+ enableFullscreen?: boolean;
28
+ /** Show the download button. Default: true. */
29
+ enableDownload?: boolean;
30
+ /** Called when the download button is clicked. If omitted, downloads `uri` directly. */
31
+ onDownload?: () => void;
32
+ /** Colors/radii to override the default look (toolbar background, text color, etc). */
33
+ theme?: ViewerTheme;
34
+ /** Render as a floating window (position: fixed) that can be dragged, instead of filling the parent. Default: true. */
35
+ floating?: boolean;
36
+ /** When floating, allow dragging the window by its toolbar. Default: true. */
37
+ windowDraggable?: boolean;
38
+ /** Initial position when floating. Default: centered in the viewport. */
39
+ defaultPosition?: Position;
40
+ }
41
+ declare function DocxViewer({ uri, fileName, className, style, width, height, minScale, maxScale, zoomStep, enableZoomControls, enableWheelZoom, enableFullscreen, enableDownload, onDownload, theme, floating, windowDraggable, defaultPosition, }: DocxViewerProps): react.JSX.Element;
42
+
43
+ export { DocxViewer, type DocxViewerProps };
package/dist/docx.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import * as react from 'react';
2
+ import { CSSProperties } from 'react';
3
+ import { V as ViewerTheme, P as Position } from './useDraggable-QvFR-4DD.js';
4
+
5
+ interface DocxViewerProps {
6
+ /** URL of the .docx file to display. */
7
+ uri: string;
8
+ /** Used as the suggested filename on download. */
9
+ fileName?: string;
10
+ className?: string;
11
+ style?: CSSProperties;
12
+ /** Width of the viewer. Accepts any CSS size (e.g. 1200, '1200px', '100%'). Default: 1200. */
13
+ width?: number | string;
14
+ /** Height of the viewer. Accepts any CSS size (e.g. 700, '700px', '100vh'). Default: 700. */
15
+ height?: number | string;
16
+ /** Minimum zoom scale. Default: 0.5 */
17
+ minScale?: number;
18
+ /** Maximum zoom scale. Default: 3 */
19
+ maxScale?: number;
20
+ /** Zoom increment per step (buttons / Ctrl+scroll). Default: 0.25 */
21
+ zoomStep?: number;
22
+ /** Show zoom in/out and reset-to-100% controls. Default: true. */
23
+ enableZoomControls?: boolean;
24
+ /** Allow Ctrl/Cmd + scroll wheel to zoom. Default: true. */
25
+ enableWheelZoom?: boolean;
26
+ /** Show the fullscreen toggle button. Default: true. */
27
+ enableFullscreen?: boolean;
28
+ /** Show the download button. Default: true. */
29
+ enableDownload?: boolean;
30
+ /** Called when the download button is clicked. If omitted, downloads `uri` directly. */
31
+ onDownload?: () => void;
32
+ /** Colors/radii to override the default look (toolbar background, text color, etc). */
33
+ theme?: ViewerTheme;
34
+ /** Render as a floating window (position: fixed) that can be dragged, instead of filling the parent. Default: true. */
35
+ floating?: boolean;
36
+ /** When floating, allow dragging the window by its toolbar. Default: true. */
37
+ windowDraggable?: boolean;
38
+ /** Initial position when floating. Default: centered in the viewport. */
39
+ defaultPosition?: Position;
40
+ }
41
+ declare function DocxViewer({ uri, fileName, className, style, width, height, minScale, maxScale, zoomStep, enableZoomControls, enableWheelZoom, enableFullscreen, enableDownload, onDownload, theme, floating, windowDraggable, defaultPosition, }: DocxViewerProps): react.JSX.Element;
42
+
43
+ export { DocxViewer, type DocxViewerProps };
package/dist/docx.js ADDED
@@ -0,0 +1,8 @@
1
+ import {
2
+ DocxViewer
3
+ } from "./chunk-4VVVAGYE.js";
4
+ import "./chunk-OA35SYM6.js";
5
+ export {
6
+ DocxViewer
7
+ };
8
+ //# sourceMappingURL=docx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/index.cjs CHANGED
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
8
11
  var __export = (target, all) => {
9
12
  for (var name in all)
10
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -27,28 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  ));
28
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
32
 
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- DocViewer: () => DocViewer,
34
- DocxViewer: () => DocxViewer,
35
- ImageViewer: () => ImageViewer,
36
- PdfViewer: () => PdfViewer,
37
- Toolbar: () => Toolbar,
38
- ViewerShell: () => ViewerShell,
39
- XlsxViewer: () => XlsxViewer,
40
- detectFileType: () => detectFileType,
41
- getUrlExtension: () => getUrlExtension,
42
- useDraggable: () => useDraggable,
43
- useZoomPan: () => useZoomPan
44
- });
45
- module.exports = __toCommonJS(index_exports);
46
-
47
- // src/core/ViewerShell.tsx
48
- var import_react2 = require("react");
49
-
50
33
  // src/core/useDraggable.ts
51
- var import_react = require("react");
52
34
  function useDraggable(options = {}) {
53
35
  const { defaultPosition = { x: 80, y: 80 }, draggable = true } = options;
54
36
  const [position, setPosition] = (0, import_react.useState)(defaultPosition);
@@ -77,9 +59,15 @@ function useDraggable(options = {}) {
77
59
  );
78
60
  return { position, onDragHandlePointerDown };
79
61
  }
62
+ var import_react;
63
+ var init_useDraggable = __esm({
64
+ "src/core/useDraggable.ts"() {
65
+ "use strict";
66
+ import_react = require("react");
67
+ }
68
+ });
80
69
 
81
70
  // src/core/icons.tsx
82
- var import_jsx_runtime = require("react/jsx-runtime");
83
71
  function Svg(props) {
84
72
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
85
73
  "svg",
@@ -152,9 +140,15 @@ function FullscreenExitIcon() {
152
140
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "15", y1: "15", x2: "21", y2: "21" })
153
141
  ] });
154
142
  }
143
+ var import_jsx_runtime;
144
+ var init_icons = __esm({
145
+ "src/core/icons.tsx"() {
146
+ "use strict";
147
+ import_jsx_runtime = require("react/jsx-runtime");
148
+ }
149
+ });
155
150
 
156
151
  // src/core/Toolbar.tsx
157
- var import_jsx_runtime2 = require("react/jsx-runtime");
158
152
  function Toolbar({
159
153
  scale,
160
154
  onZoomIn,
@@ -234,17 +228,16 @@ function Toolbar({
234
228
  )
235
229
  ] });
236
230
  }
231
+ var import_jsx_runtime2;
232
+ var init_Toolbar = __esm({
233
+ "src/core/Toolbar.tsx"() {
234
+ "use strict";
235
+ init_icons();
236
+ import_jsx_runtime2 = require("react/jsx-runtime");
237
+ }
238
+ });
237
239
 
238
240
  // src/core/theme.ts
239
- var THEME_VAR_MAP = {
240
- background: "--vd-bg",
241
- toolbarBackground: "--vd-toolbar-bg",
242
- toolbarBorderColor: "--vd-toolbar-border-color",
243
- toolbarButtonHoverBackground: "--vd-toolbar-btn-hover-bg",
244
- textColor: "--vd-text-color",
245
- borderRadius: "--vd-border-radius",
246
- toolbarButtonRadius: "--vd-toolbar-btn-radius"
247
- };
248
241
  function themeToStyle(theme) {
249
242
  if (!theme) return void 0;
250
243
  const style = {};
@@ -254,9 +247,23 @@ function themeToStyle(theme) {
254
247
  }
255
248
  return style;
256
249
  }
250
+ var THEME_VAR_MAP;
251
+ var init_theme = __esm({
252
+ "src/core/theme.ts"() {
253
+ "use strict";
254
+ THEME_VAR_MAP = {
255
+ background: "--vd-bg",
256
+ toolbarBackground: "--vd-toolbar-bg",
257
+ toolbarBorderColor: "--vd-toolbar-border-color",
258
+ toolbarButtonHoverBackground: "--vd-toolbar-btn-hover-bg",
259
+ textColor: "--vd-text-color",
260
+ borderRadius: "--vd-border-radius",
261
+ toolbarButtonRadius: "--vd-toolbar-btn-radius"
262
+ };
263
+ }
264
+ });
257
265
 
258
266
  // src/core/ViewerShell.tsx
259
- var import_jsx_runtime3 = require("react/jsx-runtime");
260
267
  function ViewerShell({
261
268
  zoomPan,
262
269
  onDownload,
@@ -353,12 +360,20 @@ function ViewerShell({
353
360
  }
354
361
  );
355
362
  }
363
+ var import_react2, import_jsx_runtime3;
364
+ var init_ViewerShell = __esm({
365
+ "src/core/ViewerShell.tsx"() {
366
+ "use strict";
367
+ import_react2 = require("react");
368
+ init_useDraggable();
369
+ init_icons();
370
+ init_Toolbar();
371
+ init_theme();
372
+ import_jsx_runtime3 = require("react/jsx-runtime");
373
+ }
374
+ });
356
375
 
357
376
  // src/core/useZoomPan.ts
358
- var import_react3 = require("react");
359
- var DEFAULT_MIN = 0.1;
360
- var DEFAULT_MAX = 8;
361
- var DEFAULT_STEP = 0.25;
362
377
  function useZoomPan(options = {}) {
363
378
  const {
364
379
  minScale = DEFAULT_MIN,
@@ -468,64 +483,18 @@ function useZoomPan(options = {}) {
468
483
  handlers: { onWheel, onPointerDown, onPointerMove, onPointerUp }
469
484
  };
470
485
  }
471
-
472
- // src/viewers/ImageViewer.tsx
473
- var import_jsx_runtime4 = require("react/jsx-runtime");
474
- function defaultDownload(uri, fileName) {
475
- const link = document.createElement("a");
476
- link.href = uri;
477
- link.download = fileName ?? "";
478
- link.rel = "noopener";
479
- document.body.appendChild(link);
480
- link.click();
481
- document.body.removeChild(link);
482
- }
483
- function ImageViewer({
484
- uri,
485
- fileName,
486
- className,
487
- style,
488
- width,
489
- height,
490
- minScale,
491
- maxScale,
492
- zoomStep,
493
- enableZoomControls = true,
494
- enableWheelZoom = true,
495
- enablePan = true,
496
- enableFullscreen = true,
497
- enableDownload = true,
498
- onDownload,
499
- theme,
500
- floating = true,
501
- windowDraggable = true,
502
- defaultPosition
503
- }) {
504
- const zoomPan = useZoomPan({ minScale, maxScale, zoomStep, enablePan, enableWheelZoom });
505
- const handleDownload = enableDownload ? onDownload ?? (() => defaultDownload(uri, fileName)) : void 0;
506
- const wrapperStyle = floating ? { ...style } : { display: "flex", alignItems: "center", justifyContent: "center", width: "100%", height: "100%", ...style };
507
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className, style: wrapperStyle, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
508
- ViewerShell,
509
- {
510
- zoomPan,
511
- onDownload: handleDownload,
512
- enableZoomControls,
513
- enableFullscreen,
514
- enablePan,
515
- theme,
516
- width,
517
- height,
518
- floating,
519
- draggable: windowDraggable,
520
- defaultPosition,
521
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("img", { className: "vd-image", src: uri, alt: fileName ?? "document image", draggable: false })
522
- }
523
- ) });
524
- }
486
+ var import_react3, DEFAULT_MIN, DEFAULT_MAX, DEFAULT_STEP;
487
+ var init_useZoomPan = __esm({
488
+ "src/core/useZoomPan.ts"() {
489
+ "use strict";
490
+ import_react3 = require("react");
491
+ DEFAULT_MIN = 0.1;
492
+ DEFAULT_MAX = 8;
493
+ DEFAULT_STEP = 0.25;
494
+ }
495
+ });
525
496
 
526
497
  // src/viewers/PdfPage.tsx
527
- var import_react4 = require("react");
528
- var import_jsx_runtime5 = require("react/jsx-runtime");
529
498
  function PdfPage({ doc, pageNumber, renderScale = 1.5 }) {
530
499
  const canvasRef = (0, import_react4.useRef)(null);
531
500
  const renderTaskRef = (0, import_react4.useRef)(null);
@@ -554,12 +523,16 @@ function PdfPage({ doc, pageNumber, renderScale = 1.5 }) {
554
523
  }, [doc, pageNumber, renderScale]);
555
524
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("canvas", { ref: canvasRef, className: "vd-pdf-page", "data-page-number": pageNumber });
556
525
  }
526
+ var import_react4, import_jsx_runtime5;
527
+ var init_PdfPage = __esm({
528
+ "src/viewers/PdfPage.tsx"() {
529
+ "use strict";
530
+ import_react4 = require("react");
531
+ import_jsx_runtime5 = require("react/jsx-runtime");
532
+ }
533
+ });
557
534
 
558
535
  // src/viewers/usePdfDocument.ts
559
- var import_react5 = require("react");
560
- var pdfjsLib = __toESM(require("pdfjs-dist"), 1);
561
- var import_meta = {};
562
- pdfjsLib.GlobalWorkerOptions.workerSrc = new URL("pdfjs-dist/build/pdf.worker.min.mjs", import_meta.url).toString();
563
536
  function usePdfDocument(uri) {
564
537
  const [doc, setDoc] = (0, import_react5.useState)(null);
565
538
  const [error, setError] = (0, import_react5.useState)(null);
@@ -587,9 +560,18 @@ function usePdfDocument(uri) {
587
560
  }, [uri]);
588
561
  return { doc, numPages: doc?.numPages ?? 0, error, loading };
589
562
  }
563
+ var import_react5, pdfjsLib, import_meta;
564
+ var init_usePdfDocument = __esm({
565
+ "src/viewers/usePdfDocument.ts"() {
566
+ "use strict";
567
+ import_react5 = require("react");
568
+ pdfjsLib = __toESM(require("pdfjs-dist"), 1);
569
+ import_meta = {};
570
+ pdfjsLib.GlobalWorkerOptions.workerSrc = new URL("pdfjs-dist/build/pdf.worker.min.mjs", import_meta.url).toString();
571
+ }
572
+ });
590
573
 
591
574
  // src/viewers/useVisiblePage.ts
592
- var import_react6 = require("react");
593
575
  function useVisiblePage(containerRef, numPages) {
594
576
  const [currentPage, setCurrentPage] = (0, import_react6.useState)(1);
595
577
  (0, import_react6.useEffect)(() => {
@@ -611,9 +593,19 @@ function useVisiblePage(containerRef, numPages) {
611
593
  }, [containerRef, numPages]);
612
594
  return currentPage;
613
595
  }
596
+ var import_react6;
597
+ var init_useVisiblePage = __esm({
598
+ "src/viewers/useVisiblePage.ts"() {
599
+ "use strict";
600
+ import_react6 = require("react");
601
+ }
602
+ });
614
603
 
615
604
  // src/viewers/PdfViewer.tsx
616
- var import_jsx_runtime6 = require("react/jsx-runtime");
605
+ var PdfViewer_exports = {};
606
+ __export(PdfViewer_exports, {
607
+ PdfViewer: () => PdfViewer
608
+ });
617
609
  function defaultDownload2(uri, fileName) {
618
610
  const link = document.createElement("a");
619
611
  link.href = uri;
@@ -688,10 +680,20 @@ function PdfViewer({
688
680
  }
689
681
  ) });
690
682
  }
683
+ var import_jsx_runtime6;
684
+ var init_PdfViewer = __esm({
685
+ "src/viewers/PdfViewer.tsx"() {
686
+ "use strict";
687
+ init_ViewerShell();
688
+ init_useZoomPan();
689
+ init_PdfPage();
690
+ init_usePdfDocument();
691
+ init_useVisiblePage();
692
+ import_jsx_runtime6 = require("react/jsx-runtime");
693
+ }
694
+ });
691
695
 
692
696
  // src/viewers/useDocxHtml.ts
693
- var import_react7 = require("react");
694
- var import_mammoth = __toESM(require("mammoth"), 1);
695
697
  function useDocxHtml(uri) {
696
698
  const [html, setHtml] = (0, import_react7.useState)(null);
697
699
  const [error, setError] = (0, import_react7.useState)(null);
@@ -720,9 +722,20 @@ function useDocxHtml(uri) {
720
722
  }, [uri]);
721
723
  return { html, error, loading };
722
724
  }
725
+ var import_react7, import_mammoth;
726
+ var init_useDocxHtml = __esm({
727
+ "src/viewers/useDocxHtml.ts"() {
728
+ "use strict";
729
+ import_react7 = require("react");
730
+ import_mammoth = __toESM(require("mammoth"), 1);
731
+ }
732
+ });
723
733
 
724
734
  // src/viewers/DocxViewer.tsx
725
- var import_jsx_runtime7 = require("react/jsx-runtime");
735
+ var DocxViewer_exports = {};
736
+ __export(DocxViewer_exports, {
737
+ DocxViewer: () => DocxViewer
738
+ });
726
739
  function defaultDownload3(uri, fileName) {
727
740
  const link = document.createElement("a");
728
741
  link.href = uri;
@@ -789,14 +802,18 @@ function DocxViewer({
789
802
  }
790
803
  ) });
791
804
  }
792
-
793
- // src/viewers/XlsxViewer.tsx
794
- var import_react9 = require("react");
795
- var XLSX2 = __toESM(require("xlsx"), 1);
805
+ var import_jsx_runtime7;
806
+ var init_DocxViewer = __esm({
807
+ "src/viewers/DocxViewer.tsx"() {
808
+ "use strict";
809
+ init_ViewerShell();
810
+ init_useZoomPan();
811
+ init_useDocxHtml();
812
+ import_jsx_runtime7 = require("react/jsx-runtime");
813
+ }
814
+ });
796
815
 
797
816
  // src/viewers/useXlsxWorkbook.ts
798
- var import_react8 = require("react");
799
- var XLSX = __toESM(require("xlsx"), 1);
800
817
  function useXlsxWorkbook(uri) {
801
818
  const [workbook, setWorkbook] = (0, import_react8.useState)(null);
802
819
  const [error, setError] = (0, import_react8.useState)(null);
@@ -826,9 +843,20 @@ function useXlsxWorkbook(uri) {
826
843
  }, [uri]);
827
844
  return { workbook, error, loading };
828
845
  }
846
+ var import_react8, XLSX;
847
+ var init_useXlsxWorkbook = __esm({
848
+ "src/viewers/useXlsxWorkbook.ts"() {
849
+ "use strict";
850
+ import_react8 = require("react");
851
+ XLSX = __toESM(require("xlsx"), 1);
852
+ }
853
+ });
829
854
 
830
855
  // src/viewers/XlsxViewer.tsx
831
- var import_jsx_runtime8 = require("react/jsx-runtime");
856
+ var XlsxViewer_exports = {};
857
+ __export(XlsxViewer_exports, {
858
+ XlsxViewer: () => XlsxViewer
859
+ });
832
860
  function defaultDownload4(uri, fileName) {
833
861
  const link = document.createElement("a");
834
862
  link.href = uri;
@@ -915,6 +943,91 @@ function XlsxViewer({
915
943
  }
916
944
  ) });
917
945
  }
946
+ var import_react9, XLSX2, import_jsx_runtime8;
947
+ var init_XlsxViewer = __esm({
948
+ "src/viewers/XlsxViewer.tsx"() {
949
+ "use strict";
950
+ import_react9 = require("react");
951
+ XLSX2 = __toESM(require("xlsx"), 1);
952
+ init_ViewerShell();
953
+ init_useZoomPan();
954
+ init_useXlsxWorkbook();
955
+ import_jsx_runtime8 = require("react/jsx-runtime");
956
+ }
957
+ });
958
+
959
+ // src/index.ts
960
+ var src_exports = {};
961
+ __export(src_exports, {
962
+ DocViewer: () => DocViewer,
963
+ ImageViewer: () => ImageViewer,
964
+ Toolbar: () => Toolbar,
965
+ ViewerShell: () => ViewerShell,
966
+ detectFileType: () => detectFileType,
967
+ getUrlExtension: () => getUrlExtension,
968
+ useDraggable: () => useDraggable,
969
+ useZoomPan: () => useZoomPan
970
+ });
971
+ module.exports = __toCommonJS(src_exports);
972
+
973
+ // src/DocViewer.tsx
974
+ var import_react10 = require("react");
975
+
976
+ // src/viewers/ImageViewer.tsx
977
+ init_ViewerShell();
978
+ init_useZoomPan();
979
+ var import_jsx_runtime4 = require("react/jsx-runtime");
980
+ function defaultDownload(uri, fileName) {
981
+ const link = document.createElement("a");
982
+ link.href = uri;
983
+ link.download = fileName ?? "";
984
+ link.rel = "noopener";
985
+ document.body.appendChild(link);
986
+ link.click();
987
+ document.body.removeChild(link);
988
+ }
989
+ function ImageViewer({
990
+ uri,
991
+ fileName,
992
+ className,
993
+ style,
994
+ width,
995
+ height,
996
+ minScale,
997
+ maxScale,
998
+ zoomStep,
999
+ enableZoomControls = true,
1000
+ enableWheelZoom = true,
1001
+ enablePan = true,
1002
+ enableFullscreen = true,
1003
+ enableDownload = true,
1004
+ onDownload,
1005
+ theme,
1006
+ floating = true,
1007
+ windowDraggable = true,
1008
+ defaultPosition
1009
+ }) {
1010
+ const zoomPan = useZoomPan({ minScale, maxScale, zoomStep, enablePan, enableWheelZoom });
1011
+ const handleDownload = enableDownload ? onDownload ?? (() => defaultDownload(uri, fileName)) : void 0;
1012
+ const wrapperStyle = floating ? { ...style } : { display: "flex", alignItems: "center", justifyContent: "center", width: "100%", height: "100%", ...style };
1013
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className, style: wrapperStyle, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1014
+ ViewerShell,
1015
+ {
1016
+ zoomPan,
1017
+ onDownload: handleDownload,
1018
+ enableZoomControls,
1019
+ enableFullscreen,
1020
+ enablePan,
1021
+ theme,
1022
+ width,
1023
+ height,
1024
+ floating,
1025
+ draggable: windowDraggable,
1026
+ defaultPosition,
1027
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("img", { className: "vd-image", src: uri, alt: fileName ?? "document image", draggable: false })
1028
+ }
1029
+ ) });
1030
+ }
918
1031
 
919
1032
  // src/detectFileType.ts
920
1033
  var EXTENSION_MAP = {
@@ -958,17 +1071,20 @@ function detectFileType(uri, hint) {
958
1071
 
959
1072
  // src/DocViewer.tsx
960
1073
  var import_jsx_runtime9 = require("react/jsx-runtime");
961
- function DocViewer({ uri, fileName, type, fallback, ...rest }) {
1074
+ var PdfViewer2 = (0, import_react10.lazy)(() => Promise.resolve().then(() => (init_PdfViewer(), PdfViewer_exports)).then((m) => ({ default: m.PdfViewer })));
1075
+ var DocxViewer2 = (0, import_react10.lazy)(() => Promise.resolve().then(() => (init_DocxViewer(), DocxViewer_exports)).then((m) => ({ default: m.DocxViewer })));
1076
+ var XlsxViewer2 = (0, import_react10.lazy)(() => Promise.resolve().then(() => (init_XlsxViewer(), XlsxViewer_exports)).then((m) => ({ default: m.XlsxViewer })));
1077
+ function DocViewer({ uri, fileName, type, fallback, loadingFallback, ...rest }) {
962
1078
  const detected = detectFileType(uri, type ?? fileName?.split(".").pop());
963
1079
  switch (detected) {
964
1080
  case "image":
965
1081
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ImageViewer, { uri, fileName, ...rest });
966
1082
  case "pdf":
967
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PdfViewer, { uri, fileName, ...rest });
1083
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react10.Suspense, { fallback: loadingFallback ?? null, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PdfViewer2, { uri, fileName, ...rest }) });
968
1084
  case "docx":
969
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DocxViewer, { uri, fileName, ...rest });
1085
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react10.Suspense, { fallback: loadingFallback ?? null, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DocxViewer2, { uri, fileName, ...rest }) });
970
1086
  case "xlsx":
971
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(XlsxViewer, { uri, fileName, ...rest });
1087
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react10.Suspense, { fallback: loadingFallback ?? null, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(XlsxViewer2, { uri, fileName, ...rest }) });
972
1088
  default:
973
1089
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: fallback ?? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "vd-doc-status", children: [
974
1090
  'Unable to detect file type for "',
@@ -977,15 +1093,18 @@ function DocViewer({ uri, fileName, type, fallback, ...rest }) {
977
1093
  ] }) });
978
1094
  }
979
1095
  }
1096
+
1097
+ // src/index.ts
1098
+ init_ViewerShell();
1099
+ init_Toolbar();
1100
+ init_useZoomPan();
1101
+ init_useDraggable();
980
1102
  // Annotate the CommonJS export names for ESM import in node:
981
1103
  0 && (module.exports = {
982
1104
  DocViewer,
983
- DocxViewer,
984
1105
  ImageViewer,
985
- PdfViewer,
986
1106
  Toolbar,
987
1107
  ViewerShell,
988
- XlsxViewer,
989
1108
  detectFileType,
990
1109
  getUrlExtension,
991
1110
  useDraggable,