@cannyminds/dms-file-viewers 0.2.0 → 0.4.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 (81) hide show
  1. package/dist/{chunk-FZYMVHF6.mjs → chunk-4DJJINTB.mjs} +54 -55
  2. package/dist/chunk-4DJJINTB.mjs.map +1 -0
  3. package/dist/chunk-677DWENS.mjs +133 -0
  4. package/dist/chunk-677DWENS.mjs.map +1 -0
  5. package/dist/chunk-77UARJVQ.js +133 -0
  6. package/dist/chunk-77UARJVQ.js.map +1 -0
  7. package/dist/{chunk-LKBM4O47.mjs → chunk-7BLEPGZ4.mjs} +67 -61
  8. package/dist/chunk-7BLEPGZ4.mjs.map +1 -0
  9. package/dist/{chunk-QRYIHDRT.mjs → chunk-BHMFZTZ7.mjs} +54 -55
  10. package/dist/chunk-BHMFZTZ7.mjs.map +1 -0
  11. package/dist/{chunk-XQBXRMB7.mjs → chunk-BONT4K3R.mjs} +14 -8
  12. package/dist/chunk-BONT4K3R.mjs.map +1 -0
  13. package/dist/{chunk-3STHCDAC.js → chunk-DDT3GC3C.js} +425 -164
  14. package/dist/chunk-DDT3GC3C.js.map +1 -0
  15. package/dist/{chunk-EMP7RZM2.js → chunk-DOOYIHGW.js} +52 -53
  16. package/dist/chunk-DOOYIHGW.js.map +1 -0
  17. package/dist/{chunk-73ZIFR3P.mjs → chunk-J2YW5DHC.mjs} +457 -196
  18. package/dist/chunk-J2YW5DHC.mjs.map +1 -0
  19. package/dist/{chunk-BNHQYEZ7.js → chunk-SBEFC7HP.js} +203 -158
  20. package/dist/chunk-SBEFC7HP.js.map +1 -0
  21. package/dist/{chunk-4RL77HKO.js → chunk-SNEIVT4R.js} +52 -53
  22. package/dist/chunk-SNEIVT4R.js.map +1 -0
  23. package/dist/{chunk-7JTIG6OU.js → chunk-WP55NYFS.js} +67 -61
  24. package/dist/chunk-WP55NYFS.js.map +1 -0
  25. package/dist/{chunk-NOLXOOIP.mjs → chunk-YHMHDPLQ.mjs} +200 -155
  26. package/dist/chunk-YHMHDPLQ.mjs.map +1 -0
  27. package/dist/{chunk-GNWU6XHH.js → chunk-Z3IUTTJQ.js} +15 -9
  28. package/dist/{chunk-GNWU6XHH.js.map → chunk-Z3IUTTJQ.js.map} +1 -1
  29. package/dist/components/viewers/AudioViewer.d.mts +1 -1
  30. package/dist/components/viewers/AudioViewer.d.ts +1 -1
  31. package/dist/components/viewers/AudioViewer.js +2 -2
  32. package/dist/components/viewers/AudioViewer.mjs +1 -1
  33. package/dist/components/viewers/DefaultViewer.d.mts +1 -1
  34. package/dist/components/viewers/DefaultViewer.d.ts +1 -1
  35. package/dist/components/viewers/DefaultViewer.js +3 -2
  36. package/dist/components/viewers/DefaultViewer.js.map +1 -1
  37. package/dist/components/viewers/DefaultViewer.mjs +2 -1
  38. package/dist/components/viewers/ImageViewer.d.mts +1 -1
  39. package/dist/components/viewers/ImageViewer.d.ts +1 -1
  40. package/dist/components/viewers/ImageViewer.js +3 -3
  41. package/dist/components/viewers/ImageViewer.mjs +2 -2
  42. package/dist/components/viewers/PDFViewer.d.mts +1 -1
  43. package/dist/components/viewers/PDFViewer.d.ts +1 -1
  44. package/dist/components/viewers/PDFViewer.js +2 -2
  45. package/dist/components/viewers/PDFViewer.mjs +1 -1
  46. package/dist/components/viewers/TIFFViewer.d.mts +1 -1
  47. package/dist/components/viewers/TIFFViewer.d.ts +1 -1
  48. package/dist/components/viewers/TIFFViewer.js +2 -2
  49. package/dist/components/viewers/TIFFViewer.mjs +1 -1
  50. package/dist/components/viewers/TextViewer.d.mts +1 -1
  51. package/dist/components/viewers/TextViewer.d.ts +1 -1
  52. package/dist/components/viewers/TextViewer.js +2 -2
  53. package/dist/components/viewers/TextViewer.mjs +1 -1
  54. package/dist/components/viewers/VideoViewer.d.mts +1 -1
  55. package/dist/components/viewers/VideoViewer.d.ts +1 -1
  56. package/dist/components/viewers/VideoViewer.js +2 -2
  57. package/dist/components/viewers/VideoViewer.mjs +1 -1
  58. package/dist/index.d.mts +2 -2
  59. package/dist/index.d.ts +2 -2
  60. package/dist/index.js +30 -19
  61. package/dist/index.js.map +1 -1
  62. package/dist/index.mjs +29 -18
  63. package/dist/index.mjs.map +1 -1
  64. package/dist/{types-CquKzJLE.d.mts → types-C6IEfcTM.d.mts} +13 -1
  65. package/dist/{types-CquKzJLE.d.ts → types-C6IEfcTM.d.ts} +13 -1
  66. package/package.json +1 -1
  67. package/dist/chunk-3STHCDAC.js.map +0 -1
  68. package/dist/chunk-4RL77HKO.js.map +0 -1
  69. package/dist/chunk-73ZIFR3P.mjs.map +0 -1
  70. package/dist/chunk-7JTIG6OU.js.map +0 -1
  71. package/dist/chunk-BNHQYEZ7.js.map +0 -1
  72. package/dist/chunk-EMP7RZM2.js.map +0 -1
  73. package/dist/chunk-FZYMVHF6.mjs.map +0 -1
  74. package/dist/chunk-LKBM4O47.mjs.map +0 -1
  75. package/dist/chunk-NOLXOOIP.mjs.map +0 -1
  76. package/dist/chunk-QLJKOQTP.mjs +0 -78
  77. package/dist/chunk-QLJKOQTP.mjs.map +0 -1
  78. package/dist/chunk-QRYIHDRT.mjs.map +0 -1
  79. package/dist/chunk-XQBXRMB7.mjs.map +0 -1
  80. package/dist/chunk-Z7FUO5RX.js +0 -78
  81. package/dist/chunk-Z7FUO5RX.js.map +0 -1
@@ -5,7 +5,7 @@
5
5
  var _chunkRE4XRGSVjs = require('./chunk-RE4XRGSV.js');
6
6
 
7
7
  // src/components/viewers/PDFViewer.tsx
8
- var _react = require('react'); var _react2 = _interopRequireDefault(_react);
8
+ var _react = require('react');
9
9
  var _pdfviewer = require('@cannyminds/pdf-viewer');
10
10
  var _FirstPage = require('@mui/icons-material/FirstPage'); var _FirstPage2 = _interopRequireDefault(_FirstPage);
11
11
  var _LastPage = require('@mui/icons-material/LastPage'); var _LastPage2 = _interopRequireDefault(_LastPage);
@@ -49,11 +49,17 @@ var SearchSidebar = ({
49
49
  totalResults,
50
50
  searchKeyword,
51
51
  searchResults = [],
52
- isSearching = false
52
+ isSearching = false,
53
+ isSyntheticResults = false
53
54
  }) => {
54
55
  const [searchTerm, setSearchTerm] = _react.useState.call(void 0, searchKeyword || "");
55
56
  const [hasSearched, setHasSearched] = _react.useState.call(void 0, false);
56
57
  const contentRef = _react.useRef.call(void 0, null);
58
+ _react.useEffect.call(void 0, () => {
59
+ if (searchKeyword && searchKeyword !== searchTerm) {
60
+ setSearchTerm(searchKeyword);
61
+ }
62
+ }, [searchKeyword]);
57
63
  _react.useLayoutEffect.call(void 0, () => {
58
64
  const element = contentRef.current;
59
65
  if (!element) return;
@@ -89,20 +95,29 @@ var SearchSidebar = ({
89
95
  background-color: transparent;
90
96
  }
91
97
  .search-sidebar-content::-webkit-scrollbar-thumb {
92
- background-color: rgba(0, 0, 0, 0.25);
98
+ background-color: rgba(128, 128, 128, 0.3);
93
99
  border-radius: 8px;
94
100
  border: 4px solid transparent;
95
101
  background-clip: padding-box;
96
102
  transition: all 0.15s ease;
97
103
  }
98
104
  .search-sidebar-content.scrollbar-hover::-webkit-scrollbar-thumb {
99
- background-color: rgba(0, 0, 0, 0.4);
105
+ background-color: rgba(128, 128, 128, 0.5);
100
106
  border: 2px solid transparent;
101
107
  }
102
108
  .search-sidebar-content::-webkit-scrollbar-thumb:active {
103
- background-color: rgba(25, 118, 210, 0.85);
109
+ background-color: rgba(25, 118, 210, 0.8);
104
110
  border: 1px solid transparent;
105
111
  }
112
+
113
+ @media (prefers-color-scheme: dark) {
114
+ .search-sidebar-content::-webkit-scrollbar-thumb {
115
+ background-color: rgba(255, 255, 255, 0.2);
116
+ }
117
+ .search-sidebar-content.scrollbar-hover::-webkit-scrollbar-thumb {
118
+ background-color: rgba(255, 255, 255, 0.35);
119
+ }
120
+ }
106
121
 
107
122
  /* Tamil font support for search results */
108
123
  .search-result-text {
@@ -344,12 +359,13 @@ var SearchSidebar = ({
344
359
  width: 80,
345
360
  height: 80,
346
361
  borderRadius: "50%",
347
- backgroundColor: "#e3f2fd",
362
+ backgroundColor: "primary.light",
348
363
  display: "flex",
349
364
  alignItems: "center",
350
365
  justifyContent: "center",
351
366
  margin: "0 auto",
352
- mb: 3
367
+ mb: 3,
368
+ opacity: 0.2
353
369
  },
354
370
  children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _FindInPage2.default, { sx: { fontSize: 40, color: "primary.main" } })
355
371
  }
@@ -361,12 +377,13 @@ var SearchSidebar = ({
361
377
  {
362
378
  variant: "body2",
363
379
  sx: {
364
- color: "primary.main",
380
+ color: "white",
365
381
  fontWeight: 600,
366
- backgroundColor: "#e3f2fd",
382
+ backgroundColor: (theme) => theme.palette.mode === "dark" ? "rgba(144, 202, 249, 0.16)" : "primary.light",
367
383
  padding: "6px 16px",
368
384
  borderRadius: "16px",
369
- display: "inline-block"
385
+ display: "inline-block",
386
+ opacity: 0.9
370
387
  },
371
388
  children: [
372
389
  '"',
@@ -384,14 +401,15 @@ var SearchSidebar = ({
384
401
  width: 80,
385
402
  height: 80,
386
403
  borderRadius: "50%",
387
- backgroundColor: "#fff3e0",
404
+ backgroundColor: (theme) => theme.palette.mode === "dark" ? "rgba(255, 152, 0, 0.12)" : "warning.light",
388
405
  display: "flex",
389
406
  alignItems: "center",
390
407
  justifyContent: "center",
391
408
  margin: "0 auto",
392
- mb: 3
409
+ mb: 3,
410
+ opacity: 0.6
393
411
  },
394
- children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Search2.default, { sx: { fontSize: 40, color: "#ff9800" } })
412
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Search2.default, { sx: { fontSize: 40, color: "warning.main" } })
395
413
  }
396
414
  ),
397
415
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, { variant: "body1", sx: { color: "text.primary", fontWeight: 500, mb: 1 }, children: "No Results Found" }),
@@ -404,8 +422,9 @@ var SearchSidebar = ({
404
422
  ] })
405
423
  ] })
406
424
  ] }),
407
- totalResults > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, { sx: { p: 2 }, children: Object.entries(resultsByPage).sort(([a, _], [b, __]) => parseInt(a) - parseInt(b)).map(([pageNum, pageResults]) => {
425
+ totalResults > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, { sx: { p: 2 }, children: Object.keys(resultsByPage).sort((a, b) => parseInt(a) - parseInt(b)).map((pageNum) => {
408
426
  const pageNumber = parseInt(pageNum);
427
+ const pageResults = resultsByPage[pageNumber];
409
428
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, { sx: { mb: 3 }, children: [
410
429
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
411
430
  _material.Typography,
@@ -435,15 +454,15 @@ var SearchSidebar = ({
435
454
  mx: 1,
436
455
  mb: 1.5,
437
456
  borderRadius: "8px",
438
- border: "1px solid",
457
+ border: "2px solid",
439
458
  borderColor: result.index === currentResultIndex ? "primary.main" : "divider",
440
- backgroundColor: result.index === currentResultIndex ? "#e3f2fd" : "background.paper",
459
+ backgroundColor: "background.paper",
441
460
  cursor: "pointer",
442
461
  transition: "all 0.2s ease",
443
- boxShadow: result.index === currentResultIndex ? "0 2px 8px rgba(25, 118, 210, 0.15)" : "0 1px 3px rgba(0, 0, 0, 0.05)",
462
+ boxShadow: (theme) => theme.palette.mode === "dark" ? "0 1px 3px rgba(0, 0, 0, 0.3)" : "0 1px 3px rgba(0, 0, 0, 0.05)",
444
463
  "&:hover": {
445
464
  borderColor: "primary.main",
446
- boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
465
+ boxShadow: (theme) => theme.palette.mode === "dark" ? "0 2px 8px rgba(255, 255, 255, 0.15)" : "0 2px 8px rgba(0, 0, 0, 0.1)",
447
466
  transform: "translateY(-1px)"
448
467
  }
449
468
  },
@@ -471,8 +490,180 @@ var SearchSidebar = ({
471
490
  );
472
491
  };
473
492
 
493
+ // src/components/viewers/pdf/PasswordDialog.tsx
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+ var _Lock = require('@mui/icons-material/Lock'); var _Lock2 = _interopRequireDefault(_Lock);
510
+ var _Visibility = require('@mui/icons-material/Visibility'); var _Visibility2 = _interopRequireDefault(_Visibility);
511
+ var _VisibilityOff = require('@mui/icons-material/VisibilityOff'); var _VisibilityOff2 = _interopRequireDefault(_VisibilityOff);
512
+
513
+ var PasswordDialog = ({
514
+ open,
515
+ fileName,
516
+ onSubmit,
517
+ onCancel,
518
+ error
519
+ }) => {
520
+ const [password, setPassword] = _react.useState.call(void 0, "");
521
+ const [showPassword, setShowPassword] = _react.useState.call(void 0, false);
522
+ _react.useEffect.call(void 0, () => {
523
+ if (open) {
524
+ setPassword("");
525
+ setShowPassword(false);
526
+ }
527
+ }, [open]);
528
+ const handleSubmit = (e) => {
529
+ e.preventDefault();
530
+ if (password.trim()) {
531
+ onSubmit(password);
532
+ }
533
+ };
534
+ const handleTogglePasswordVisibility = () => {
535
+ setShowPassword(!showPassword);
536
+ };
537
+ const handleKeyPress = (e) => {
538
+ if (e.key === "Enter" && password.trim()) {
539
+ handleSubmit(e);
540
+ }
541
+ };
542
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
543
+ _material.Dialog,
544
+ {
545
+ open,
546
+ onClose: onCancel,
547
+ maxWidth: "sm",
548
+ fullWidth: true,
549
+ PaperProps: {
550
+ sx: {
551
+ borderRadius: 2
552
+ }
553
+ },
554
+ children: [
555
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.DialogTitle, { sx: { pb: 1 }, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, { sx: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
556
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, { sx: { display: "flex", alignItems: "center", gap: 1.5 }, children: [
557
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
558
+ _material.Box,
559
+ {
560
+ sx: {
561
+ width: 40,
562
+ height: 40,
563
+ borderRadius: "50%",
564
+ backgroundColor: "primary.light",
565
+ display: "flex",
566
+ alignItems: "center",
567
+ justifyContent: "center",
568
+ opacity: 0.9
569
+ },
570
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Lock2.default, { sx: { color: "white", fontSize: 20 } })
571
+ }
572
+ ),
573
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, { variant: "h6", component: "div", sx: { fontWeight: 600 }, children: "Password Protected" })
574
+ ] }),
575
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
576
+ _material.IconButton,
577
+ {
578
+ size: "small",
579
+ onClick: onCancel,
580
+ sx: { color: "text.secondary" },
581
+ "aria-label": "Close dialog",
582
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Close2.default, { fontSize: "small" })
583
+ }
584
+ )
585
+ ] }) }),
586
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.DialogContent, { sx: { pt: 2 }, children: [
587
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Typography, { variant: "body2", sx: { color: "text.secondary", mb: 3 }, children: [
588
+ "This PDF is password protected. Please enter the password to view",
589
+ " ",
590
+ fileName && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "strong", { children: [
591
+ '"',
592
+ fileName,
593
+ '"'
594
+ ] })
595
+ ] }),
596
+ error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Alert, { severity: "error", sx: { mb: 2 }, children: error }),
597
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "form", { onSubmit: handleSubmit, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
598
+ _material.TextField,
599
+ {
600
+ fullWidth: true,
601
+ autoFocus: true,
602
+ type: showPassword ? "text" : "password",
603
+ label: "Password",
604
+ placeholder: "Enter password",
605
+ value: password,
606
+ onChange: (e) => setPassword(e.target.value),
607
+ onKeyPress: handleKeyPress,
608
+ error: Boolean(error),
609
+ InputProps: {
610
+ endAdornment: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.InputAdornment, { position: "end", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
611
+ _material.IconButton,
612
+ {
613
+ onClick: handleTogglePasswordVisibility,
614
+ edge: "end",
615
+ size: "small",
616
+ "aria-label": showPassword ? "Hide password" : "Show password",
617
+ children: showPassword ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _VisibilityOff2.default, {}) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Visibility2.default, {})
618
+ }
619
+ ) })
620
+ },
621
+ sx: {
622
+ "& .MuiOutlinedInput-root": {
623
+ borderRadius: 2
624
+ }
625
+ }
626
+ }
627
+ ) })
628
+ ] }),
629
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.DialogActions, { sx: { px: 3, pb: 3, pt: 2 }, children: [
630
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
631
+ _material.Button,
632
+ {
633
+ onClick: onCancel,
634
+ variant: "outlined",
635
+ sx: {
636
+ borderRadius: 2,
637
+ textTransform: "none",
638
+ px: 3
639
+ },
640
+ children: "Cancel"
641
+ }
642
+ ),
643
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
644
+ _material.Button,
645
+ {
646
+ onClick: handleSubmit,
647
+ variant: "contained",
648
+ disabled: !password.trim(),
649
+ sx: {
650
+ borderRadius: 2,
651
+ textTransform: "none",
652
+ px: 3,
653
+ boxShadow: 2
654
+ },
655
+ children: "Unlock PDF"
656
+ }
657
+ )
658
+ ] })
659
+ ]
660
+ }
661
+ );
662
+ };
663
+
474
664
  // src/components/viewers/PDFViewer.tsx
475
665
 
666
+ var HeadlessPDFViewer = _pdfviewer.PDFViewer;
476
667
  var toolbarStyles = `
477
668
  @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Tamil:wght@400;500;600;700&family=Noto+Sans+Devanagari:wght@400;500;600;700&display=swap');
478
669
 
@@ -502,7 +693,7 @@ var toolbarStyles = `
502
693
  .pdf-viewer-header {
503
694
  display: flex;
504
695
  align-items: center;
505
- justify-content: center;
696
+ justify-content: flex-start;
506
697
  gap: 8px;
507
698
  padding: 3px 16px 0 16px;
508
699
  background: #fff;
@@ -641,7 +832,9 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
641
832
  onMetadataClick,
642
833
  onPropertiesClick,
643
834
  onDownloadClick,
644
- onPrintClick
835
+ onPrintClick,
836
+ initialSearchText,
837
+ initialSearchPages
645
838
  } = props;
646
839
  const [pdfBuffer, setPdfBuffer] = _react.useState.call(void 0, null);
647
840
  const [state, setState] = _react.useState.call(void 0, "idle");
@@ -670,6 +863,10 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
670
863
  const [searchResults, setSearchResults] = _react.useState.call(void 0, []);
671
864
  const [currentSearchResultIndex, setCurrentSearchResultIndex] = _react.useState.call(void 0, 0);
672
865
  const [totalSearchResults, setTotalSearchResults] = _react.useState.call(void 0, 0);
866
+ const [autoExecuteSearch, setAutoExecuteSearch] = _react.useState.call(void 0, !!initialSearchText);
867
+ const [isPasswordDialogOpen, setIsPasswordDialogOpen] = _react.useState.call(void 0, false);
868
+ const [passwordError, setPasswordError] = _react.useState.call(void 0, "");
869
+ const [passwordResolve, setPasswordResolve] = _react.useState.call(void 0, null);
673
870
  _react.useEffect.call(void 0, () => {
674
871
  setSearchQuery("");
675
872
  setSearchResults([]);
@@ -685,79 +882,102 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
685
882
  setPdfBuffer(null);
686
883
  }, [file]);
687
884
  _react.useEffect.call(void 0, () => {
688
- if (state === "ready") {
689
- setTimeout(() => {
690
- const container = document.querySelector('[data-pdf-viewer], .embedpdf-viewport, [role="document"]');
691
- if (container) {
692
- setPdfContainer(container);
693
- }
694
- }, 500);
885
+ if (state !== "ready") return;
886
+ const container = document.querySelector('[data-pdf-viewer], .embedpdf-viewport, [role="document"]');
887
+ if (container) {
888
+ setPdfContainer(container);
889
+ return;
695
890
  }
891
+ const observer = new MutationObserver(() => {
892
+ const foundContainer = document.querySelector('[data-pdf-viewer], .embedpdf-viewport, [role="document"]');
893
+ if (foundContainer) {
894
+ setPdfContainer(foundContainer);
895
+ observer.disconnect();
896
+ }
897
+ });
898
+ observer.observe(document.body, { childList: true, subtree: true });
899
+ return () => observer.disconnect();
696
900
  }, [state]);
697
901
  _react.useEffect.call(void 0, () => {
698
- if (state === "ready" && totalPages === 0) {
699
- const initializePageCount = async () => {
700
- let viewer = pdfViewerRef.current;
701
- let retries = 0;
702
- while (!viewer && retries < 10) {
703
- await new Promise((resolve) => setTimeout(resolve, 500));
704
- viewer = pdfViewerRef.current;
705
- retries++;
902
+ if (state !== "ready" || totalPages > 0) return;
903
+ const initializePageCount = async () => {
904
+ const waitForViewer = async (maxAttempts = 10) => {
905
+ for (let i = 0; i < maxAttempts; i++) {
906
+ if (pdfViewerRef.current) return pdfViewerRef.current;
907
+ await new Promise((resolve) => requestAnimationFrame(
908
+ () => setTimeout(resolve, Math.min(100 * Math.pow(2, i), 1e3))
909
+ ));
706
910
  }
707
- if (!viewer) return;
708
- await new Promise((resolve) => setTimeout(resolve, 1500));
709
- try {
710
- let count = _optionalChain([viewer, 'access', _2 => _2.navigation, 'optionalAccess', _3 => _3.getTotalPages, 'optionalCall', _4 => _4()]);
711
- if (count && count > 1) {
712
- setTotalPages(count);
713
- return;
714
- }
715
- } catch (e) {
911
+ return null;
912
+ };
913
+ const viewer = await waitForViewer();
914
+ if (!viewer) return;
915
+ await new Promise((resolve) => requestAnimationFrame(resolve));
916
+ try {
917
+ const count = _optionalChain([viewer, 'access', _ => _.navigation, 'optionalAccess', _2 => _2.getTotalPages, 'optionalCall', _3 => _3()]);
918
+ if (count && count > 1) {
919
+ setTotalPages(count);
920
+ return;
716
921
  }
717
- try {
718
- const results = await _optionalChain([viewer, 'access', _5 => _5.search, 'optionalAccess', _6 => _6.searchText, 'optionalCall', _7 => _7("e")]);
719
- if (_optionalChain([results, 'optionalAccess', _8 => _8.results]) && results.results.length > 0) {
720
- const pageIndices = results.results.map((m) => m.pageIndex).filter((idx) => typeof idx === "number");
721
- const count = Math.max(...pageIndices) + 1;
722
- _optionalChain([viewer, 'access', _9 => _9.search, 'optionalAccess', _10 => _10.stopSearch, 'optionalCall', _11 => _11()]);
723
- setTotalPages(count);
724
- return;
725
- }
726
- } catch (error2) {
922
+ } catch (e) {
923
+ }
924
+ try {
925
+ const results = await _optionalChain([viewer, 'access', _4 => _4.search, 'optionalAccess', _5 => _5.searchText, 'optionalCall', _6 => _6("e")]);
926
+ if (_optionalChain([results, 'optionalAccess', _7 => _7.results]) && results.results.length > 0) {
927
+ const pageIndices = results.results.map((m) => m.pageIndex).filter((idx) => typeof idx === "number");
928
+ const count = Math.max(...pageIndices) + 1;
929
+ _optionalChain([viewer, 'access', _8 => _8.search, 'optionalAccess', _9 => _9.stopSearch, 'optionalCall', _10 => _10()]);
930
+ setTotalPages(count);
931
+ return;
727
932
  }
728
- try {
729
- await new Promise((resolve) => setTimeout(resolve, 1e3));
730
- const selectors = [
731
- "[data-page-index]",
732
- "[data-page-number]",
733
- ".embedpdf-page",
734
- '[role="article"]',
735
- "canvas[data-page]",
736
- ".react-pdf__Page"
737
- ];
738
- let pages = null;
739
- for (const selector of selectors) {
740
- pages = document.querySelectorAll(selector);
741
- if (pages.length > 0) break;
742
- }
743
- if (pages && pages.length > 0) {
933
+ } catch (error2) {
934
+ }
935
+ try {
936
+ const selectors = [
937
+ "[data-page-index]",
938
+ "[data-page-number]",
939
+ ".embedpdf-page",
940
+ '[role="article"]',
941
+ "canvas[data-page]",
942
+ ".react-pdf__Page"
943
+ ];
944
+ for (const selector of selectors) {
945
+ const pages = document.querySelectorAll(selector);
946
+ if (pages.length > 0) {
744
947
  setTotalPages(pages.length);
745
948
  return;
746
949
  }
747
- } catch (error2) {
748
950
  }
749
- setTotalPages(1);
750
- };
751
- initializePageCount();
752
- }
951
+ } catch (error2) {
952
+ }
953
+ setTotalPages(1);
954
+ };
955
+ initializePageCount();
753
956
  }, [state, totalPages]);
957
+ _react.useEffect.call(void 0, () => {
958
+ if (state !== "ready" || !autoExecuteSearch || !initialSearchText) return;
959
+ const scheduleSearch = (callback) => {
960
+ if ("requestIdleCallback" in window) {
961
+ requestIdleCallback(callback, { timeout: 2e3 });
962
+ } else {
963
+ requestAnimationFrame(() => setTimeout(callback, 0));
964
+ }
965
+ };
966
+ scheduleSearch(() => {
967
+ if (!pdfViewerRef.current) return;
968
+ setIsSidebarOpen(true);
969
+ setSearchQuery(initialSearchText);
970
+ handleSidebarSearch(initialSearchText, initialSearchPages);
971
+ setAutoExecuteSearch(false);
972
+ });
973
+ }, [state, autoExecuteSearch, initialSearchText, initialSearchPages]);
754
974
  _react.useEffect.call(void 0, () => {
755
975
  if (state === "ready" && pdfViewerRef.current) {
756
976
  const updateInfo = () => {
757
- const current = _optionalChain([pdfViewerRef, 'access', _12 => _12.current, 'optionalAccess', _13 => _13.navigation, 'access', _14 => _14.getCurrentPage, 'call', _15 => _15()]) || 1;
758
- const total = _optionalChain([pdfViewerRef, 'access', _16 => _16.current, 'optionalAccess', _17 => _17.navigation, 'access', _18 => _18.getTotalPages, 'call', _19 => _19()]) || 0;
759
- const zoomValue = _optionalChain([pdfViewerRef, 'access', _20 => _20.current, 'optionalAccess', _21 => _21.zoom, 'access', _22 => _22.getZoom, 'call', _23 => _23()]);
760
- const currentSearchState = _optionalChain([pdfViewerRef, 'access', _24 => _24.current, 'optionalAccess', _25 => _25.search, 'access', _26 => _26.getSearchState, 'call', _27 => _27()]);
977
+ const current = _optionalChain([pdfViewerRef, 'access', _11 => _11.current, 'optionalAccess', _12 => _12.navigation, 'access', _13 => _13.getCurrentPage, 'call', _14 => _14()]) || 1;
978
+ const total = _optionalChain([pdfViewerRef, 'access', _15 => _15.current, 'optionalAccess', _16 => _16.navigation, 'access', _17 => _17.getTotalPages, 'call', _18 => _18()]) || 0;
979
+ const zoomValue = _optionalChain([pdfViewerRef, 'access', _19 => _19.current, 'optionalAccess', _20 => _20.zoom, 'access', _21 => _21.getZoom, 'call', _22 => _22()]);
980
+ const currentSearchState = _optionalChain([pdfViewerRef, 'access', _23 => _23.current, 'optionalAccess', _24 => _24.search, 'access', _25 => _25.getSearchState, 'call', _26 => _26()]);
761
981
  setCurrentPage(current);
762
982
  if (total > 0 && total !== totalPages) {
763
983
  setTotalPages(total);
@@ -773,115 +993,115 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
773
993
  }, [state, totalPages]);
774
994
  _react.useImperativeHandle.call(void 0, ref, () => ({
775
995
  zoomIn: () => {
776
- _optionalChain([pdfViewerRef, 'access', _28 => _28.current, 'optionalAccess', _29 => _29.zoom, 'access', _30 => _30.zoomIn, 'call', _31 => _31()]);
996
+ _optionalChain([pdfViewerRef, 'access', _27 => _27.current, 'optionalAccess', _28 => _28.zoom, 'access', _29 => _29.zoomIn, 'call', _30 => _30()]);
777
997
  updateZoomDisplay();
778
998
  },
779
999
  zoomOut: () => {
780
- _optionalChain([pdfViewerRef, 'access', _32 => _32.current, 'optionalAccess', _33 => _33.zoom, 'access', _34 => _34.zoomOut, 'call', _35 => _35()]);
1000
+ _optionalChain([pdfViewerRef, 'access', _31 => _31.current, 'optionalAccess', _32 => _32.zoom, 'access', _33 => _33.zoomOut, 'call', _34 => _34()]);
781
1001
  updateZoomDisplay();
782
1002
  },
783
1003
  setZoom: (level) => {
784
- _optionalChain([pdfViewerRef, 'access', _36 => _36.current, 'optionalAccess', _37 => _37.zoom, 'access', _38 => _38.setZoom, 'call', _39 => _39(level)]);
1004
+ _optionalChain([pdfViewerRef, 'access', _35 => _35.current, 'optionalAccess', _36 => _36.zoom, 'access', _37 => _37.setZoom, 'call', _38 => _38(level)]);
785
1005
  updateZoomDisplay();
786
1006
  },
787
1007
  resetZoom: () => {
788
- _optionalChain([pdfViewerRef, 'access', _40 => _40.current, 'optionalAccess', _41 => _41.zoom, 'access', _42 => _42.resetZoom, 'call', _43 => _43()]);
1008
+ _optionalChain([pdfViewerRef, 'access', _39 => _39.current, 'optionalAccess', _40 => _40.zoom, 'access', _41 => _41.resetZoom, 'call', _42 => _42()]);
789
1009
  updateZoomDisplay();
790
1010
  },
791
1011
  getZoom: () => {
792
- const zoom2 = _optionalChain([pdfViewerRef, 'access', _44 => _44.current, 'optionalAccess', _45 => _45.zoom, 'access', _46 => _46.getZoom, 'call', _47 => _47()]);
1012
+ const zoom2 = _optionalChain([pdfViewerRef, 'access', _43 => _43.current, 'optionalAccess', _44 => _44.zoom, 'access', _45 => _45.getZoom, 'call', _46 => _46()]);
793
1013
  return typeof zoom2 === "number" ? zoom2 : 1;
794
1014
  },
795
1015
  goToPage: (page) => {
796
- _optionalChain([pdfViewerRef, 'access', _48 => _48.current, 'optionalAccess', _49 => _49.navigation, 'access', _50 => _50.goToPage, 'call', _51 => _51(page)]);
1016
+ _optionalChain([pdfViewerRef, 'access', _47 => _47.current, 'optionalAccess', _48 => _48.navigation, 'access', _49 => _49.goToPage, 'call', _50 => _50(page)]);
797
1017
  setCurrentPage(page);
798
1018
  },
799
- getCurrentPage: () => _optionalChain([pdfViewerRef, 'access', _52 => _52.current, 'optionalAccess', _53 => _53.navigation, 'access', _54 => _54.getCurrentPage, 'call', _55 => _55()]) || 1,
800
- getTotalPages: () => _optionalChain([pdfViewerRef, 'access', _56 => _56.current, 'optionalAccess', _57 => _57.navigation, 'access', _58 => _58.getTotalPages, 'call', _59 => _59()]) || 0,
1019
+ getCurrentPage: () => _optionalChain([pdfViewerRef, 'access', _51 => _51.current, 'optionalAccess', _52 => _52.navigation, 'access', _53 => _53.getCurrentPage, 'call', _54 => _54()]) || 1,
1020
+ getTotalPages: () => _optionalChain([pdfViewerRef, 'access', _55 => _55.current, 'optionalAccess', _56 => _56.navigation, 'access', _57 => _57.getTotalPages, 'call', _58 => _58()]) || 0,
801
1021
  nextPage: () => {
802
- _optionalChain([pdfViewerRef, 'access', _60 => _60.current, 'optionalAccess', _61 => _61.navigation, 'access', _62 => _62.nextPage, 'call', _63 => _63()]);
1022
+ _optionalChain([pdfViewerRef, 'access', _59 => _59.current, 'optionalAccess', _60 => _60.navigation, 'access', _61 => _61.nextPage, 'call', _62 => _62()]);
803
1023
  updatePageDisplay();
804
1024
  },
805
1025
  previousPage: () => {
806
- _optionalChain([pdfViewerRef, 'access', _64 => _64.current, 'optionalAccess', _65 => _65.navigation, 'access', _66 => _66.previousPage, 'call', _67 => _67()]);
1026
+ _optionalChain([pdfViewerRef, 'access', _63 => _63.current, 'optionalAccess', _64 => _64.navigation, 'access', _65 => _65.previousPage, 'call', _66 => _66()]);
807
1027
  updatePageDisplay();
808
1028
  },
809
1029
  goToFirstPage: () => {
810
- _optionalChain([pdfViewerRef, 'access', _68 => _68.current, 'optionalAccess', _69 => _69.navigation, 'access', _70 => _70.goToFirstPage, 'call', _71 => _71()]);
1030
+ _optionalChain([pdfViewerRef, 'access', _67 => _67.current, 'optionalAccess', _68 => _68.navigation, 'access', _69 => _69.goToFirstPage, 'call', _70 => _70()]);
811
1031
  updatePageDisplay();
812
1032
  },
813
1033
  goToLastPage: () => {
814
- _optionalChain([pdfViewerRef, 'access', _72 => _72.current, 'optionalAccess', _73 => _73.navigation, 'access', _74 => _74.goToLastPage, 'call', _75 => _75()]);
1034
+ _optionalChain([pdfViewerRef, 'access', _71 => _71.current, 'optionalAccess', _72 => _72.navigation, 'access', _73 => _73.goToLastPage, 'call', _74 => _74()]);
815
1035
  updatePageDisplay();
816
1036
  },
817
1037
  searchText: async (keyword) => {
818
1038
  setIsSearching(true);
819
- const results = await _optionalChain([pdfViewerRef, 'access', _76 => _76.current, 'optionalAccess', _77 => _77.search, 'access', _78 => _78.searchText, 'call', _79 => _79(keyword)]);
1039
+ const results = await _optionalChain([pdfViewerRef, 'access', _75 => _75.current, 'optionalAccess', _76 => _76.search, 'access', _77 => _77.searchText, 'call', _78 => _78(keyword)]);
820
1040
  setIsSearching(false);
821
1041
  setSearchQuery(keyword);
822
1042
  return results;
823
1043
  },
824
1044
  nextResult: () => {
825
- const index = _optionalChain([pdfViewerRef, 'access', _80 => _80.current, 'optionalAccess', _81 => _81.search, 'access', _82 => _82.nextResult, 'call', _83 => _83()]) || -1;
1045
+ const index = _optionalChain([pdfViewerRef, 'access', _79 => _79.current, 'optionalAccess', _80 => _80.search, 'access', _81 => _81.nextResult, 'call', _82 => _82()]) || -1;
826
1046
  return index;
827
1047
  },
828
1048
  previousResult: () => {
829
- const index = _optionalChain([pdfViewerRef, 'access', _84 => _84.current, 'optionalAccess', _85 => _85.search, 'access', _86 => _86.previousResult, 'call', _87 => _87()]) || -1;
1049
+ const index = _optionalChain([pdfViewerRef, 'access', _83 => _83.current, 'optionalAccess', _84 => _84.search, 'access', _85 => _85.previousResult, 'call', _86 => _86()]) || -1;
830
1050
  return index;
831
1051
  },
832
- goToResult: (index) => _optionalChain([pdfViewerRef, 'access', _88 => _88.current, 'optionalAccess', _89 => _89.search, 'access', _90 => _90.goToResult, 'call', _91 => _91(index)]) || -1,
1052
+ goToResult: (index) => _optionalChain([pdfViewerRef, 'access', _87 => _87.current, 'optionalAccess', _88 => _88.search, 'access', _89 => _89.goToResult, 'call', _90 => _90(index)]) || -1,
833
1053
  stopSearch: () => {
834
- _optionalChain([pdfViewerRef, 'access', _92 => _92.current, 'optionalAccess', _93 => _93.search, 'access', _94 => _94.stopSearch, 'call', _95 => _95()]);
1054
+ _optionalChain([pdfViewerRef, 'access', _91 => _91.current, 'optionalAccess', _92 => _92.search, 'access', _93 => _93.stopSearch, 'call', _94 => _94()]);
835
1055
  setSearchQuery("");
836
1056
  },
837
- getSearchState: () => _optionalChain([pdfViewerRef, 'access', _96 => _96.current, 'optionalAccess', _97 => _97.search, 'access', _98 => _98.getSearchState, 'call', _99 => _99()]) || null,
838
- getSelectedText: () => _optionalChain([pdfViewerRef, 'access', _100 => _100.current, 'optionalAccess', _101 => _101.selection, 'access', _102 => _102.getSelectedText, 'call', _103 => _103()]) || "",
839
- clearSelection: () => _optionalChain([pdfViewerRef, 'access', _104 => _104.current, 'optionalAccess', _105 => _105.selection, 'access', _106 => _106.clearSelection, 'call', _107 => _107()])
1057
+ getSearchState: () => _optionalChain([pdfViewerRef, 'access', _95 => _95.current, 'optionalAccess', _96 => _96.search, 'access', _97 => _97.getSearchState, 'call', _98 => _98()]) || null,
1058
+ getSelectedText: () => _optionalChain([pdfViewerRef, 'access', _99 => _99.current, 'optionalAccess', _100 => _100.selection, 'access', _101 => _101.getSelectedText, 'call', _102 => _102()]) || "",
1059
+ clearSelection: () => _optionalChain([pdfViewerRef, 'access', _103 => _103.current, 'optionalAccess', _104 => _104.selection, 'access', _105 => _105.clearSelection, 'call', _106 => _106()])
840
1060
  }), []);
841
1061
  const updatePageDisplay = () => {
842
- setTimeout(() => {
843
- const current = _optionalChain([pdfViewerRef, 'access', _108 => _108.current, 'optionalAccess', _109 => _109.navigation, 'access', _110 => _110.getCurrentPage, 'call', _111 => _111()]) || 1;
1062
+ requestAnimationFrame(() => {
1063
+ const current = _optionalChain([pdfViewerRef, 'access', _107 => _107.current, 'optionalAccess', _108 => _108.navigation, 'access', _109 => _109.getCurrentPage, 'call', _110 => _110()]) || 1;
844
1064
  setCurrentPage(current);
845
- }, 100);
1065
+ });
846
1066
  };
847
1067
  const updateZoomDisplay = () => {
848
- setTimeout(() => {
849
- const zoomValue = _optionalChain([pdfViewerRef, 'access', _112 => _112.current, 'optionalAccess', _113 => _113.zoom, 'access', _114 => _114.getZoom, 'call', _115 => _115()]);
1068
+ requestAnimationFrame(() => {
1069
+ const zoomValue = _optionalChain([pdfViewerRef, 'access', _111 => _111.current, 'optionalAccess', _112 => _112.zoom, 'access', _113 => _113.getZoom, 'call', _114 => _114()]);
850
1070
  if (typeof zoomValue === "number") {
851
1071
  setZoom(Math.round(zoomValue * 100));
852
1072
  }
853
- }, 100);
1073
+ });
854
1074
  };
855
1075
  const handleZoomIn = () => {
856
- _optionalChain([pdfViewerRef, 'access', _116 => _116.current, 'optionalAccess', _117 => _117.zoom, 'access', _118 => _118.zoomIn, 'call', _119 => _119()]);
1076
+ _optionalChain([pdfViewerRef, 'access', _115 => _115.current, 'optionalAccess', _116 => _116.zoom, 'access', _117 => _117.zoomIn, 'call', _118 => _118()]);
857
1077
  updateZoomDisplay();
858
1078
  };
859
1079
  const handleZoomOut = () => {
860
- _optionalChain([pdfViewerRef, 'access', _120 => _120.current, 'optionalAccess', _121 => _121.zoom, 'access', _122 => _122.zoomOut, 'call', _123 => _123()]);
1080
+ _optionalChain([pdfViewerRef, 'access', _119 => _119.current, 'optionalAccess', _120 => _120.zoom, 'access', _121 => _121.zoomOut, 'call', _122 => _122()]);
861
1081
  updateZoomDisplay();
862
1082
  };
863
1083
  const handleFitToWidth = () => {
864
- _optionalChain([pdfViewerRef, 'access', _124 => _124.current, 'optionalAccess', _125 => _125.zoom, 'access', _126 => _126.fitToWidth, 'call', _127 => _127()]);
1084
+ _optionalChain([pdfViewerRef, 'access', _123 => _123.current, 'optionalAccess', _124 => _124.zoom, 'access', _125 => _125.fitToWidth, 'call', _126 => _126()]);
865
1085
  updateZoomDisplay();
866
1086
  };
867
1087
  const handleFitToPage = () => {
868
- _optionalChain([pdfViewerRef, 'access', _128 => _128.current, 'optionalAccess', _129 => _129.zoom, 'access', _130 => _130.fitToPage, 'call', _131 => _131()]);
1088
+ _optionalChain([pdfViewerRef, 'access', _127 => _127.current, 'optionalAccess', _128 => _128.zoom, 'access', _129 => _129.fitToPage, 'call', _130 => _130()]);
869
1089
  updateZoomDisplay();
870
1090
  };
871
1091
  const handlePreviousPage = () => {
872
- _optionalChain([pdfViewerRef, 'access', _132 => _132.current, 'optionalAccess', _133 => _133.navigation, 'access', _134 => _134.previousPage, 'call', _135 => _135()]);
1092
+ _optionalChain([pdfViewerRef, 'access', _131 => _131.current, 'optionalAccess', _132 => _132.navigation, 'access', _133 => _133.previousPage, 'call', _134 => _134()]);
873
1093
  updatePageDisplay();
874
1094
  };
875
1095
  const handleNextPage = () => {
876
- _optionalChain([pdfViewerRef, 'access', _136 => _136.current, 'optionalAccess', _137 => _137.navigation, 'access', _138 => _138.nextPage, 'call', _139 => _139()]);
1096
+ _optionalChain([pdfViewerRef, 'access', _135 => _135.current, 'optionalAccess', _136 => _136.navigation, 'access', _137 => _137.nextPage, 'call', _138 => _138()]);
877
1097
  updatePageDisplay();
878
1098
  };
879
1099
  const handleFirstPage = () => {
880
- _optionalChain([pdfViewerRef, 'access', _140 => _140.current, 'optionalAccess', _141 => _141.navigation, 'access', _142 => _142.goToFirstPage, 'call', _143 => _143()]);
1100
+ _optionalChain([pdfViewerRef, 'access', _139 => _139.current, 'optionalAccess', _140 => _140.navigation, 'access', _141 => _141.goToFirstPage, 'call', _142 => _142()]);
881
1101
  updatePageDisplay();
882
1102
  };
883
1103
  const handleLastPage = () => {
884
- _optionalChain([pdfViewerRef, 'access', _144 => _144.current, 'optionalAccess', _145 => _145.navigation, 'access', _146 => _146.goToLastPage, 'call', _147 => _147()]);
1104
+ _optionalChain([pdfViewerRef, 'access', _143 => _143.current, 'optionalAccess', _144 => _144.navigation, 'access', _145 => _145.goToLastPage, 'call', _146 => _146()]);
885
1105
  updatePageDisplay();
886
1106
  };
887
1107
  const handlePageInput = (e) => {
@@ -891,7 +1111,7 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
891
1111
  return;
892
1112
  }
893
1113
  if (!isNaN(page) && page >= 1 && (totalPages === 0 || page <= totalPages)) {
894
- _optionalChain([pdfViewerRef, 'access', _148 => _148.current, 'optionalAccess', _149 => _149.navigation, 'access', _150 => _150.goToPage, 'call', _151 => _151(page)]);
1114
+ _optionalChain([pdfViewerRef, 'access', _147 => _147.current, 'optionalAccess', _148 => _148.navigation, 'access', _149 => _149.goToPage, 'call', _150 => _150(page)]);
895
1115
  setCurrentPage(page);
896
1116
  }
897
1117
  };
@@ -900,7 +1120,7 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
900
1120
  const value = e.target.value;
901
1121
  const page = parseInt(value, 10);
902
1122
  if (!isNaN(page) && page >= 1 && (totalPages === 0 || page <= totalPages)) {
903
- _optionalChain([pdfViewerRef, 'access', _152 => _152.current, 'optionalAccess', _153 => _153.navigation, 'access', _154 => _154.goToPage, 'call', _155 => _155(page)]);
1123
+ _optionalChain([pdfViewerRef, 'access', _151 => _151.current, 'optionalAccess', _152 => _152.navigation, 'access', _153 => _153.goToPage, 'call', _154 => _154(page)]);
904
1124
  setCurrentPage(page);
905
1125
  }
906
1126
  }
@@ -908,7 +1128,7 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
908
1128
  const handleSearch = async () => {
909
1129
  if (searchQuery.trim()) {
910
1130
  setIsSearching(true);
911
- const results = await _optionalChain([pdfViewerRef, 'access', _156 => _156.current, 'optionalAccess', _157 => _157.search, 'access', _158 => _158.searchText, 'call', _159 => _159(searchQuery)]);
1131
+ const results = await _optionalChain([pdfViewerRef, 'access', _155 => _155.current, 'optionalAccess', _156 => _156.search, 'access', _157 => _157.searchText, 'call', _158 => _158(searchQuery)]);
912
1132
  setIsSearching(false);
913
1133
  if (results && results.results) {
914
1134
  const formattedResults = results.results.map((result, index) => {
@@ -952,13 +1172,13 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
952
1172
  handleSearch();
953
1173
  }
954
1174
  };
955
- const handleSidebarSearch = async (keyword) => {
1175
+ const handleSidebarSearch = async (keyword, pageNumbers) => {
956
1176
  setSearchQuery(keyword);
957
1177
  if (keyword.trim()) {
958
1178
  setIsSearching(true);
959
- const results = await _optionalChain([pdfViewerRef, 'access', _160 => _160.current, 'optionalAccess', _161 => _161.search, 'access', _162 => _162.searchText, 'call', _163 => _163(keyword)]);
1179
+ const results = await _optionalChain([pdfViewerRef, 'access', _159 => _159.current, 'optionalAccess', _160 => _160.search, 'access', _161 => _161.searchText, 'call', _162 => _162(keyword)]);
960
1180
  setIsSearching(false);
961
- if (results && results.results) {
1181
+ if (results && results.results && results.results.length > 0) {
962
1182
  const formattedResults = results.results.map((result, index) => {
963
1183
  let textContent = "";
964
1184
  let contextContent = "";
@@ -987,9 +1207,21 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
987
1207
  setCurrentSearchResultIndex(0);
988
1208
  if (formattedResults.length > 0) {
989
1209
  const firstPageNumber = formattedResults[0].pageNumber;
990
- _optionalChain([pdfViewerRef, 'access', _164 => _164.current, 'optionalAccess', _165 => _165.navigation, 'access', _166 => _166.goToPage, 'call', _167 => _167(firstPageNumber)]);
1210
+ _optionalChain([pdfViewerRef, 'access', _163 => _163.current, 'optionalAccess', _164 => _164.navigation, 'access', _165 => _165.goToPage, 'call', _166 => _166(firstPageNumber)]);
991
1211
  setCurrentPage(firstPageNumber);
992
1212
  }
1213
+ } else if (pageNumbers && pageNumbers.length > 0) {
1214
+ const fallbackResults = pageNumbers.map((pageNum, index) => ({
1215
+ pageNumber: pageNum,
1216
+ text: keyword,
1217
+ context: `"${keyword}" found on this page ${pageNum}`,
1218
+ index
1219
+ }));
1220
+ setSearchResults(fallbackResults);
1221
+ setTotalSearchResults(fallbackResults.length);
1222
+ setCurrentSearchResultIndex(0);
1223
+ _optionalChain([pdfViewerRef, 'access', _167 => _167.current, 'optionalAccess', _168 => _168.navigation, 'access', _169 => _169.goToPage, 'call', _170 => _170(pageNumbers[0])]);
1224
+ setCurrentPage(pageNumbers[0]);
993
1225
  } else {
994
1226
  setSearchResults([]);
995
1227
  setTotalSearchResults(0);
@@ -997,16 +1229,16 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
997
1229
  }
998
1230
  } else {
999
1231
  setSearchResults([]);
1000
- _optionalChain([pdfViewerRef, 'access', _168 => _168.current, 'optionalAccess', _169 => _169.search, 'access', _170 => _170.stopSearch, 'call', _171 => _171()]);
1232
+ _optionalChain([pdfViewerRef, 'access', _171 => _171.current, 'optionalAccess', _172 => _172.search, 'access', _173 => _173.stopSearch, 'call', _174 => _174()]);
1001
1233
  setTotalSearchResults(0);
1002
1234
  setCurrentSearchResultIndex(0);
1003
1235
  }
1004
1236
  };
1005
1237
  const handleSearchResultClick = (pageNumber, resultIndex) => {
1006
- _optionalChain([pdfViewerRef, 'access', _172 => _172.current, 'optionalAccess', _173 => _173.navigation, 'access', _174 => _174.goToPage, 'call', _175 => _175(pageNumber)]);
1238
+ _optionalChain([pdfViewerRef, 'access', _175 => _175.current, 'optionalAccess', _176 => _176.navigation, 'access', _177 => _177.goToPage, 'call', _178 => _178(pageNumber)]);
1007
1239
  setCurrentSearchResultIndex(resultIndex);
1008
1240
  setCurrentPage(pageNumber);
1009
- _optionalChain([pdfViewerRef, 'access', _176 => _176.current, 'optionalAccess', _177 => _177.search, 'access', _178 => _178.goToResult, 'call', _179 => _179(resultIndex)]);
1241
+ _optionalChain([pdfViewerRef, 'access', _179 => _179.current, 'optionalAccess', _180 => _180.search, 'access', _181 => _181.goToResult, 'call', _182 => _182(resultIndex)]);
1010
1242
  };
1011
1243
  const toggleSidebar = () => {
1012
1244
  setIsSidebarOpen(!isSidebarOpen);
@@ -1015,10 +1247,10 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
1015
1247
  if (currentSearchResultIndex < totalSearchResults - 1) {
1016
1248
  const nextIndex = currentSearchResultIndex + 1;
1017
1249
  setCurrentSearchResultIndex(nextIndex);
1018
- _optionalChain([pdfViewerRef, 'access', _180 => _180.current, 'optionalAccess', _181 => _181.search, 'access', _182 => _182.nextResult, 'call', _183 => _183()]);
1250
+ _optionalChain([pdfViewerRef, 'access', _183 => _183.current, 'optionalAccess', _184 => _184.search, 'access', _185 => _185.nextResult, 'call', _186 => _186()]);
1019
1251
  if (searchResults[nextIndex]) {
1020
1252
  const pageNumber = searchResults[nextIndex].pageNumber;
1021
- _optionalChain([pdfViewerRef, 'access', _184 => _184.current, 'optionalAccess', _185 => _185.navigation, 'access', _186 => _186.goToPage, 'call', _187 => _187(pageNumber)]);
1253
+ _optionalChain([pdfViewerRef, 'access', _187 => _187.current, 'optionalAccess', _188 => _188.navigation, 'access', _189 => _189.goToPage, 'call', _190 => _190(pageNumber)]);
1022
1254
  setCurrentPage(pageNumber);
1023
1255
  }
1024
1256
  }
@@ -1027,30 +1259,14 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
1027
1259
  if (currentSearchResultIndex > 0) {
1028
1260
  const prevIndex = currentSearchResultIndex - 1;
1029
1261
  setCurrentSearchResultIndex(prevIndex);
1030
- _optionalChain([pdfViewerRef, 'access', _188 => _188.current, 'optionalAccess', _189 => _189.search, 'access', _190 => _190.previousResult, 'call', _191 => _191()]);
1262
+ _optionalChain([pdfViewerRef, 'access', _191 => _191.current, 'optionalAccess', _192 => _192.search, 'access', _193 => _193.previousResult, 'call', _194 => _194()]);
1031
1263
  if (searchResults[prevIndex]) {
1032
1264
  const pageNumber = searchResults[prevIndex].pageNumber;
1033
- _optionalChain([pdfViewerRef, 'access', _192 => _192.current, 'optionalAccess', _193 => _193.navigation, 'access', _194 => _194.goToPage, 'call', _195 => _195(pageNumber)]);
1265
+ _optionalChain([pdfViewerRef, 'access', _195 => _195.current, 'optionalAccess', _196 => _196.navigation, 'access', _197 => _197.goToPage, 'call', _198 => _198(pageNumber)]);
1034
1266
  setCurrentPage(pageNumber);
1035
1267
  }
1036
1268
  }
1037
1269
  };
1038
- const handleDownload = () => {
1039
- if (onDownloadClick) {
1040
- onDownloadClick();
1041
- return;
1042
- }
1043
- if (!pdfBuffer) return;
1044
- const blob = new Blob([pdfBuffer], { type: "application/pdf" });
1045
- const url = URL.createObjectURL(blob);
1046
- const link = document.createElement("a");
1047
- link.href = url;
1048
- link.download = resolvedFileName;
1049
- document.body.appendChild(link);
1050
- link.click();
1051
- document.body.removeChild(link);
1052
- URL.revokeObjectURL(url);
1053
- };
1054
1270
  const handlePrint = () => {
1055
1271
  if (onPrintClick) {
1056
1272
  onPrintClick();
@@ -1069,28 +1285,42 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
1069
1285
  document.body.appendChild(iframe);
1070
1286
  iframe.onload = () => {
1071
1287
  try {
1072
- setTimeout(() => {
1288
+ requestAnimationFrame(() => {
1073
1289
  const iframeWindow = iframe.contentWindow;
1074
1290
  if (!iframeWindow) return;
1075
1291
  iframeWindow.focus();
1076
1292
  iframeWindow.print();
1077
- const checkPrintComplete = () => {
1078
- setTimeout(() => {
1293
+ const cleanup = () => {
1294
+ requestAnimationFrame(() => {
1079
1295
  try {
1080
- document.body.removeChild(iframe);
1296
+ if (document.body.contains(iframe)) {
1297
+ document.body.removeChild(iframe);
1298
+ }
1081
1299
  URL.revokeObjectURL(blobUrl);
1082
1300
  } catch (e) {
1083
1301
  }
1084
- }, 500);
1302
+ });
1085
1303
  };
1086
1304
  if ("onafterprint" in iframeWindow) {
1087
- iframeWindow.onafterprint = checkPrintComplete;
1305
+ iframeWindow.onafterprint = cleanup;
1088
1306
  } else {
1089
- setTimeout(checkPrintComplete, 3e3);
1307
+ const visibilityHandler = () => {
1308
+ if (!document.hidden) {
1309
+ cleanup();
1310
+ document.removeEventListener("visibilitychange", visibilityHandler);
1311
+ }
1312
+ };
1313
+ document.addEventListener("visibilitychange", visibilityHandler);
1314
+ setTimeout(() => {
1315
+ cleanup();
1316
+ document.removeEventListener("visibilitychange", visibilityHandler);
1317
+ }, 5e3);
1090
1318
  }
1091
- }, 500);
1319
+ });
1092
1320
  } catch (error2) {
1093
- document.body.removeChild(iframe);
1321
+ if (document.body.contains(iframe)) {
1322
+ document.body.removeChild(iframe);
1323
+ }
1094
1324
  URL.revokeObjectURL(blobUrl);
1095
1325
  }
1096
1326
  };
@@ -1126,21 +1356,39 @@ var PDFViewerContent = _react.forwardRef.call(void 0, (props, ref) => {
1126
1356
  }
1127
1357
  setPdfBuffer(arrayBuffer);
1128
1358
  setState("ready");
1129
- _optionalChain([onLoad, 'optionalCall', _196 => _196()]);
1359
+ _optionalChain([onLoad, 'optionalCall', _199 => _199()]);
1130
1360
  } catch (err) {
1131
1361
  const errorMessage = err.message || "Failed to load PDF";
1132
1362
  setState("error");
1133
1363
  setError(errorMessage);
1134
- _optionalChain([onError, 'optionalCall', _197 => _197(err)]);
1364
+ _optionalChain([onError, 'optionalCall', _200 => _200(err)]);
1135
1365
  }
1136
1366
  };
1137
1367
  loadPDF();
1138
1368
  }, [file, onLoad, onError]);
1139
1369
  const handlePasswordRequest = _react.useCallback.call(void 0, async (fileName2) => {
1140
- const password = prompt(`This PDF is password protected.
1141
- Enter password for ${fileName2 || "document"}:`);
1142
- return password;
1370
+ return new Promise((resolve) => {
1371
+ setPasswordResolve(() => resolve);
1372
+ setPasswordError("");
1373
+ setIsPasswordDialogOpen(true);
1374
+ });
1143
1375
  }, []);
1376
+ const handlePasswordSubmit = _react.useCallback.call(void 0, (password) => {
1377
+ if (passwordResolve) {
1378
+ passwordResolve(password);
1379
+ setPasswordResolve(null);
1380
+ setIsPasswordDialogOpen(false);
1381
+ setPasswordError("");
1382
+ }
1383
+ }, [passwordResolve]);
1384
+ const handlePasswordCancel = _react.useCallback.call(void 0, () => {
1385
+ if (passwordResolve) {
1386
+ passwordResolve(null);
1387
+ setPasswordResolve(null);
1388
+ setIsPasswordDialogOpen(false);
1389
+ setPasswordError("");
1390
+ }
1391
+ }, [passwordResolve]);
1144
1392
  if (state === "loading") {
1145
1393
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { style: {
1146
1394
  display: "flex",
@@ -1366,11 +1614,14 @@ Enter password for ${fileName2 || "document"}:`);
1366
1614
  ] })
1367
1615
  ] }),
1368
1616
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "pdf-viewer-main", children: [
1369
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "pdf-viewer-viewer-area", children: _react2.default.createElement(_pdfviewer.PDFViewer, {
1370
- ref: pdfViewerRef,
1371
- pdfBuffer,
1372
- onPasswordRequest: handlePasswordRequest
1373
- }) }),
1617
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "pdf-viewer-viewer-area", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1618
+ HeadlessPDFViewer,
1619
+ {
1620
+ ref: pdfViewerRef,
1621
+ pdfBuffer,
1622
+ onPasswordRequest: handlePasswordRequest
1623
+ }
1624
+ ) }),
1374
1625
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1375
1626
  SearchSidebar,
1376
1627
  {
@@ -1387,7 +1638,17 @@ Enter password for ${fileName2 || "document"}:`);
1387
1638
  isSearching
1388
1639
  }
1389
1640
  )
1390
- ] })
1641
+ ] }),
1642
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1643
+ PasswordDialog,
1644
+ {
1645
+ open: isPasswordDialogOpen,
1646
+ fileName: resolvedFileName,
1647
+ onSubmit: handlePasswordSubmit,
1648
+ onCancel: handlePasswordCancel,
1649
+ error: passwordError
1650
+ }
1651
+ )
1391
1652
  ] });
1392
1653
  });
1393
1654
  PDFViewerContent.displayName = "PDFViewerContent";
@@ -1399,4 +1660,4 @@ PDFViewer.displayName = "PDFViewer";
1399
1660
 
1400
1661
 
1401
1662
  exports.PDFViewer = PDFViewer;
1402
- //# sourceMappingURL=chunk-3STHCDAC.js.map
1663
+ //# sourceMappingURL=chunk-DDT3GC3C.js.map