@cannyminds/dms-file-viewers 0.5.0 → 0.7.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 (101) hide show
  1. package/dist/{chunk-DOOYIHGW.js → chunk-56PP5GHZ.js} +70 -18
  2. package/dist/chunk-56PP5GHZ.js.map +1 -0
  3. package/dist/chunk-57BAESSV.mjs +341 -0
  4. package/dist/chunk-57BAESSV.mjs.map +1 -0
  5. package/dist/{chunk-7BLEPGZ4.mjs → chunk-7AUCINV2.mjs} +70 -18
  6. package/dist/chunk-7AUCINV2.mjs.map +1 -0
  7. package/dist/chunk-A2MSWOEM.js +159 -0
  8. package/dist/chunk-A2MSWOEM.js.map +1 -0
  9. package/dist/{chunk-SBEFC7HP.js → chunk-CQ3HSM5S.js} +70 -18
  10. package/dist/chunk-CQ3HSM5S.js.map +1 -0
  11. package/dist/{chunk-SNEIVT4R.js → chunk-ETHSDRF5.js} +70 -18
  12. package/dist/chunk-ETHSDRF5.js.map +1 -0
  13. package/dist/{chunk-RE4XRGSV.js → chunk-FA5L62Y5.js} +52 -32
  14. package/dist/chunk-FA5L62Y5.js.map +1 -0
  15. package/dist/chunk-GMDRDOWP.mjs +159 -0
  16. package/dist/chunk-GMDRDOWP.mjs.map +1 -0
  17. package/dist/{chunk-K5SKH4SD.mjs → chunk-HLDLNHNY.mjs} +226 -282
  18. package/dist/chunk-HLDLNHNY.mjs.map +1 -0
  19. package/dist/{chunk-QELOFQEB.js → chunk-HQJPMN53.js} +283 -339
  20. package/dist/chunk-HQJPMN53.js.map +1 -0
  21. package/dist/{chunk-4DJJINTB.mjs → chunk-KBST5Z5H.mjs} +69 -17
  22. package/dist/chunk-KBST5Z5H.mjs.map +1 -0
  23. package/dist/{chunk-WP55NYFS.js → chunk-LQVHD4FS.js} +71 -19
  24. package/dist/chunk-LQVHD4FS.js.map +1 -0
  25. package/dist/chunk-M57PSU4O.mjs +36 -0
  26. package/dist/chunk-M57PSU4O.mjs.map +1 -0
  27. package/dist/{chunk-YHMHDPLQ.mjs → chunk-PFJKVNUA.mjs} +69 -17
  28. package/dist/chunk-PFJKVNUA.mjs.map +1 -0
  29. package/dist/chunk-QGM5J3SP.js +341 -0
  30. package/dist/chunk-QGM5J3SP.js.map +1 -0
  31. package/dist/{chunk-677DWENS.mjs → chunk-THFHTTQX.mjs} +64 -17
  32. package/dist/chunk-THFHTTQX.mjs.map +1 -0
  33. package/dist/{chunk-77UARJVQ.js → chunk-UUM656JE.js} +66 -19
  34. package/dist/chunk-UUM656JE.js.map +1 -0
  35. package/dist/{chunk-QQDQJ7TS.mjs → chunk-VJFXCN5Z.mjs} +50 -30
  36. package/dist/chunk-VJFXCN5Z.mjs.map +1 -0
  37. package/dist/{chunk-BHMFZTZ7.mjs → chunk-WNZHGFNC.mjs} +69 -17
  38. package/dist/chunk-WNZHGFNC.mjs.map +1 -0
  39. package/dist/chunk-YEPEMLM3.js +36 -0
  40. package/dist/chunk-YEPEMLM3.js.map +1 -0
  41. package/dist/components/viewers/AudioViewer.d.mts +1 -1
  42. package/dist/components/viewers/AudioViewer.d.ts +1 -1
  43. package/dist/components/viewers/AudioViewer.js +4 -3
  44. package/dist/components/viewers/AudioViewer.js.map +1 -1
  45. package/dist/components/viewers/AudioViewer.mjs +3 -2
  46. package/dist/components/viewers/DefaultViewer.d.mts +1 -1
  47. package/dist/components/viewers/DefaultViewer.d.ts +1 -1
  48. package/dist/components/viewers/DefaultViewer.js +4 -3
  49. package/dist/components/viewers/DefaultViewer.js.map +1 -1
  50. package/dist/components/viewers/DefaultViewer.mjs +3 -2
  51. package/dist/components/viewers/ImageViewer.d.mts +1 -1
  52. package/dist/components/viewers/ImageViewer.d.ts +1 -1
  53. package/dist/components/viewers/ImageViewer.js +4 -4
  54. package/dist/components/viewers/ImageViewer.mjs +3 -3
  55. package/dist/components/viewers/PDFViewer.d.mts +1 -1
  56. package/dist/components/viewers/PDFViewer.d.ts +1 -1
  57. package/dist/components/viewers/PDFViewer.js +5 -3
  58. package/dist/components/viewers/PDFViewer.js.map +1 -1
  59. package/dist/components/viewers/PDFViewer.mjs +4 -2
  60. package/dist/components/viewers/TIFFViewer.d.mts +1 -1
  61. package/dist/components/viewers/TIFFViewer.d.ts +1 -1
  62. package/dist/components/viewers/TIFFViewer.js +4 -3
  63. package/dist/components/viewers/TIFFViewer.js.map +1 -1
  64. package/dist/components/viewers/TIFFViewer.mjs +3 -2
  65. package/dist/components/viewers/TextViewer.d.mts +1 -1
  66. package/dist/components/viewers/TextViewer.d.ts +1 -1
  67. package/dist/components/viewers/TextViewer.js +4 -3
  68. package/dist/components/viewers/TextViewer.js.map +1 -1
  69. package/dist/components/viewers/TextViewer.mjs +3 -2
  70. package/dist/components/viewers/VideoViewer.d.mts +1 -1
  71. package/dist/components/viewers/VideoViewer.d.ts +1 -1
  72. package/dist/components/viewers/VideoViewer.js +4 -3
  73. package/dist/components/viewers/VideoViewer.js.map +1 -1
  74. package/dist/components/viewers/VideoViewer.mjs +3 -2
  75. package/dist/index.d.mts +2 -2
  76. package/dist/index.d.ts +2 -2
  77. package/dist/index.js +14 -11
  78. package/dist/index.js.map +1 -1
  79. package/dist/index.mjs +12 -9
  80. package/dist/index.mjs.map +1 -1
  81. package/dist/{types-C6IEfcTM.d.mts → types-BmZB9kkJ.d.mts} +13 -1
  82. package/dist/{types-C6IEfcTM.d.ts → types-BmZB9kkJ.d.ts} +13 -1
  83. package/package.json +1 -1
  84. package/dist/chunk-4DJJINTB.mjs.map +0 -1
  85. package/dist/chunk-677DWENS.mjs.map +0 -1
  86. package/dist/chunk-6ZBHO5SP.js +0 -294
  87. package/dist/chunk-6ZBHO5SP.js.map +0 -1
  88. package/dist/chunk-77UARJVQ.js.map +0 -1
  89. package/dist/chunk-7BLEPGZ4.mjs.map +0 -1
  90. package/dist/chunk-BHMFZTZ7.mjs.map +0 -1
  91. package/dist/chunk-DOOYIHGW.js.map +0 -1
  92. package/dist/chunk-K5SKH4SD.mjs.map +0 -1
  93. package/dist/chunk-QELOFQEB.js.map +0 -1
  94. package/dist/chunk-QQDQJ7TS.mjs.map +0 -1
  95. package/dist/chunk-RE4XRGSV.js.map +0 -1
  96. package/dist/chunk-SBEFC7HP.js.map +0 -1
  97. package/dist/chunk-SNEIVT4R.js.map +0 -1
  98. package/dist/chunk-UX6U3H7J.mjs +0 -294
  99. package/dist/chunk-UX6U3H7J.mjs.map +0 -1
  100. package/dist/chunk-WP55NYFS.js.map +0 -1
  101. package/dist/chunk-YHMHDPLQ.mjs.map +0 -1
@@ -1,8 +1,14 @@
1
1
  "use client";
2
2
  import {
3
- FileIcon_default,
3
+ toolbarStyles
4
+ } from "./chunk-GMDRDOWP.mjs";
5
+ import {
4
6
  getFileExtension
5
- } from "./chunk-QQDQJ7TS.mjs";
7
+ } from "./chunk-M57PSU4O.mjs";
8
+ import {
9
+ FileIcon_default,
10
+ mergeToolbarConfig
11
+ } from "./chunk-VJFXCN5Z.mjs";
6
12
 
7
13
  // src/components/viewers/PDFViewer.tsx
8
14
  import { useCallback, useEffect as useEffect3, useMemo, useRef as useRef2, useState as useState3, forwardRef, useImperativeHandle } from "react";
@@ -39,6 +45,7 @@ import ZoomOutIcon from "@mui/icons-material/ZoomOut";
39
45
  import FitScreenIcon from "@mui/icons-material/FitScreen";
40
46
  import AspectRatioIcon from "@mui/icons-material/AspectRatio";
41
47
  import SearchIcon from "@mui/icons-material/Search";
48
+ import FullscreenIcon from "@mui/icons-material/Fullscreen";
42
49
  import DownloadIcon from "@mui/icons-material/Download";
43
50
  import PrintIcon from "@mui/icons-material/Print";
44
51
  import InfoIcon from "@mui/icons-material/Info";
@@ -57,6 +64,10 @@ var PDFToolbar = React2.memo(({
57
64
  showProperties,
58
65
  showDownload,
59
66
  showPrint,
67
+ disabledMetadata,
68
+ disabledProperties,
69
+ disabledDownload,
70
+ disabledPrint,
60
71
  onFirstPage,
61
72
  onPreviousPage,
62
73
  onNextPage,
@@ -68,6 +79,7 @@ var PDFToolbar = React2.memo(({
68
79
  onFitToWidth,
69
80
  onFitToPage,
70
81
  onToggleSidebar,
82
+ onToggleFullScreen,
71
83
  onDownloadClick,
72
84
  onPrintClick,
73
85
  onMetadataClick,
@@ -196,6 +208,16 @@ var PDFToolbar = React2.memo(({
196
208
  }
197
209
  ) })
198
210
  ] }),
211
+ /* @__PURE__ */ jsx2("div", { className: "toolbar-separator" }),
212
+ /* @__PURE__ */ jsx2("div", { className: "toolbar-section", children: /* @__PURE__ */ jsx2(
213
+ "button",
214
+ {
215
+ className: "toolbar-button",
216
+ onClick: onToggleFullScreen,
217
+ title: "Fullscreen",
218
+ children: /* @__PURE__ */ jsx2(FullscreenIcon, { fontSize: "small" })
219
+ }
220
+ ) }),
199
221
  (showMetadata || showProperties || showDownload || showPrint) && /* @__PURE__ */ jsxs(Fragment, { children: [
200
222
  /* @__PURE__ */ jsx2("div", { className: "toolbar-separator" }),
201
223
  /* @__PURE__ */ jsxs("div", { className: "toolbar-section", children: [
@@ -204,6 +226,7 @@ var PDFToolbar = React2.memo(({
204
226
  {
205
227
  className: "toolbar-button",
206
228
  onClick: onDownloadClick,
229
+ disabled: disabledDownload,
207
230
  title: "Download PDF",
208
231
  children: /* @__PURE__ */ jsx2(DownloadIcon, { fontSize: "small" })
209
232
  }
@@ -213,6 +236,7 @@ var PDFToolbar = React2.memo(({
213
236
  {
214
237
  className: "toolbar-button",
215
238
  onClick: onPrintClick,
239
+ disabled: disabledPrint,
216
240
  title: "Print PDF",
217
241
  children: /* @__PURE__ */ jsx2(PrintIcon, { fontSize: "small" })
218
242
  }
@@ -222,8 +246,9 @@ var PDFToolbar = React2.memo(({
222
246
  {
223
247
  className: "toolbar-button",
224
248
  onClick: onMetadataClick,
249
+ disabled: disabledMetadata,
225
250
  title: "Document Metadata",
226
- children: /* @__PURE__ */ jsx2(InfoIcon, { fontSize: "small" })
251
+ children: /* @__PURE__ */ jsx2(DescriptionIcon, { fontSize: "small" })
227
252
  }
228
253
  ),
229
254
  showProperties && /* @__PURE__ */ jsx2(
@@ -231,8 +256,9 @@ var PDFToolbar = React2.memo(({
231
256
  {
232
257
  className: "toolbar-button",
233
258
  onClick: onPropertiesClick,
259
+ disabled: disabledProperties,
234
260
  title: "Document Properties",
235
- children: /* @__PURE__ */ jsx2(DescriptionIcon, { fontSize: "small" })
261
+ children: /* @__PURE__ */ jsx2(InfoIcon, { fontSize: "small" })
236
262
  }
237
263
  )
238
264
  ] })
@@ -260,7 +286,8 @@ import {
260
286
  TextField,
261
287
  IconButton,
262
288
  InputAdornment,
263
- Divider
289
+ Divider,
290
+ CircularProgress
264
291
  } from "@mui/material";
265
292
  import SearchIcon2 from "@mui/icons-material/Search";
266
293
  import CloseIcon from "@mui/icons-material/Close";
@@ -363,10 +390,10 @@ var SearchSidebar = ({
363
390
  }, []);
364
391
  useLayoutEffect(() => {
365
392
  setSearchTerm(searchKeyword || "");
366
- if (searchKeyword) {
393
+ if (searchKeyword || searchResults.length > 0) {
367
394
  setHasSearched(true);
368
395
  }
369
- }, [searchKeyword]);
396
+ }, [searchKeyword, searchResults]);
370
397
  const handleSearchSubmit = (e) => {
371
398
  if (e) e.preventDefault();
372
399
  if (searchTerm.trim()) {
@@ -582,7 +609,7 @@ var SearchSidebar = ({
582
609
  /* @__PURE__ */ jsx4(Typography, { variant: "body1", sx: { color: "text.primary", fontWeight: 500, mb: 1 }, children: "Search in Document" }),
583
610
  /* @__PURE__ */ jsx4(Typography, { variant: "body2", sx: { color: "text.secondary", lineHeight: 1.6 }, children: "Enter keywords to find text within the PDF document" })
584
611
  ] }),
585
- searchTerm && !hasSearched && /* @__PURE__ */ jsxs3(Box, { sx: { p: 4, textAlign: "center", mt: 6 }, children: [
612
+ searchTerm && !hasSearched && !isSearching && /* @__PURE__ */ jsxs3(Box, { sx: { p: 4, textAlign: "center", mt: 6 }, children: [
586
613
  /* @__PURE__ */ jsx4(
587
614
  Box,
588
615
  {
@@ -624,6 +651,27 @@ var SearchSidebar = ({
624
651
  }
625
652
  )
626
653
  ] }),
654
+ isSearching && /* @__PURE__ */ jsxs3(Box, { sx: { p: 4, textAlign: "center", mt: 6 }, children: [
655
+ /* @__PURE__ */ jsx4(
656
+ Box,
657
+ {
658
+ sx: {
659
+ display: "flex",
660
+ alignItems: "center",
661
+ justifyContent: "center",
662
+ margin: "0 auto",
663
+ mb: 3
664
+ },
665
+ children: /* @__PURE__ */ jsx4(CircularProgress, { size: 60, thickness: 4 })
666
+ }
667
+ ),
668
+ /* @__PURE__ */ jsx4(Typography, { variant: "body1", sx: { color: "text.primary", fontWeight: 500, mb: 1 }, children: "Searching..." }),
669
+ /* @__PURE__ */ jsxs3(Typography, { variant: "body2", sx: { color: "text.secondary", lineHeight: 1.6 }, children: [
670
+ 'Finding matches for "',
671
+ searchTerm,
672
+ '"'
673
+ ] })
674
+ ] }),
627
675
  hasSearched && totalResults === 0 && !isSearching && /* @__PURE__ */ jsxs3(Box, { sx: { p: 4, textAlign: "center", mt: 6 }, children: [
628
676
  /* @__PURE__ */ jsx4(
629
677
  Box,
@@ -892,159 +940,6 @@ var PasswordDialog = ({
892
940
  );
893
941
  };
894
942
 
895
- // src/components/viewers/pdf/PDFStyles.tsx
896
- var toolbarStyles = `
897
- @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');
898
-
899
- * {
900
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
901
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
902
- 'Noto Sans Tamil', 'Noto Sans Devanagari', 'Lohit Tamil', 'Tamil MN',
903
- 'Arial Unicode MS', sans-serif !important;
904
- }
905
-
906
- /* Target PDF.js text layer */
907
- .textLayer,
908
- .textLayer span,
909
- .textLayer div,
910
- [class*="pdf"],
911
- [class*="page"],
912
- canvas + div,
913
- .embedpdf-viewport *,
914
- [data-pdf-viewer] *,
915
- [role="document"] * {
916
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
917
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
918
- 'Noto Sans Tamil', 'Noto Sans Devanagari', 'Lohit Tamil', 'Tamil MN',
919
- 'Arial Unicode MS', sans-serif !important;
920
- }
921
-
922
- .pdf-viewer-header {
923
- display: flex;
924
- align-items: center;
925
- justify-content: flex-start;
926
- gap: 8px;
927
- padding: 3px 16px 0 16px;
928
- background: #fff;
929
- min-height: 36px;
930
- }
931
- .header-file-name {
932
- font-size: 12px;
933
- font-weight: 500;
934
- color: #424242;
935
- white-space: nowrap;
936
- overflow: hidden;
937
- text-overflow: ellipsis;
938
- max-width: 400px;
939
- }
940
- .pdf-viewer-toolbar {
941
- display: flex;
942
- align-items: center;
943
- justify-content: center;
944
- padding: 0 16px 6px 16px;
945
- background: #fff;
946
- gap: 12px;
947
- flex-wrap: wrap;
948
- min-height: 44px;
949
- }
950
- .toolbar-section {
951
- display: flex;
952
- align-items: center;
953
- gap: 8px;
954
- }
955
- .toolbar-separator {
956
- width: 1px;
957
- height: 24px;
958
- background: #e0e0e0;
959
- margin: 0 4px;
960
- }
961
- .toolbar-button {
962
- padding: 8px;
963
- border: none;
964
- background: transparent;
965
- cursor: pointer;
966
- border-radius: 4px;
967
- display: flex;
968
- align-items: center;
969
- justify-content: center;
970
- transition: background 0.2s;
971
- }
972
- .toolbar-button:hover:not(:disabled) {
973
- background: #f5f5f5;
974
- }
975
- .toolbar-button:disabled {
976
- opacity: 0.4;
977
- cursor: not-allowed;
978
- }
979
- .toolbar-button svg {
980
- width: 20px;
981
- height: 20px;
982
- display: block;
983
- }
984
- .page-input {
985
- width: 60px;
986
- padding: 4px 8px;
987
- border: 1px solid #e0e0e0;
988
- border-radius: 4px;
989
- text-align: center;
990
- font-size: 14px;
991
- }
992
- .page-info {
993
- font-size: 14px;
994
- color: #666;
995
- white-space: nowrap;
996
- }
997
- .zoom-display {
998
- min-width: 60px;
999
- text-align: center;
1000
- font-size: 14px;
1001
- color: #666;
1002
- }
1003
- .search-input {
1004
- padding: 4px 8px;
1005
- border: 1px solid #e0e0e0;
1006
- border-radius: 4px;
1007
- font-size: 14px;
1008
- min-width: 200px;
1009
- }
1010
- .pdf-viewer-content {
1011
- flex: 1;
1012
- overflow: hidden;
1013
- position: relative;
1014
- user-select: text;
1015
- -webkit-user-select: text;
1016
- -moz-user-select: text;
1017
- -ms-user-select: text;
1018
- }
1019
- .pdf-viewer-container {
1020
- display: flex;
1021
- flex-direction: column;
1022
- height: 100%;
1023
- width: 100%;
1024
- }
1025
- .pdf-viewer-main {
1026
- display: flex;
1027
- flex: 1;
1028
- overflow: hidden;
1029
- position: relative;
1030
- }
1031
- .pdf-viewer-viewer-area {
1032
- flex: 1;
1033
- overflow: hidden;
1034
- position: relative;
1035
- user-select: text;
1036
- -webkit-user-select: text;
1037
- -moz-user-select: text;
1038
- -ms-user-select: text;
1039
- }
1040
- .pdf-viewer-viewer-area * {
1041
- user-select: text !important;
1042
- -webkit-user-select: text !important;
1043
- -moz-user-select: text !important;
1044
- -ms-user-select: text !important;
1045
- }
1046
- `;
1047
-
1048
943
  // src/components/viewers/PDFViewer.tsx
1049
944
  import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
1050
945
  var PDFViewerContent = forwardRef((props, ref) => {
@@ -1096,10 +991,40 @@ var PDFViewerContent = forwardRef((props, ref) => {
1096
991
  const [currentSearchResultIndex, setCurrentSearchResultIndex] = useState3(0);
1097
992
  const [totalSearchResults, setTotalSearchResults] = useState3(0);
1098
993
  const [autoExecuteSearch, setAutoExecuteSearch] = useState3(!!initialSearchText);
994
+ const [isFullScreen, setIsFullScreen] = useState3(false);
995
+ const containerRef = useRef2(null);
1099
996
  const [isPasswordDialogOpen, setIsPasswordDialogOpen] = useState3(false);
1100
997
  const [passwordError, setPasswordError] = useState3("");
1101
998
  const [passwordResolve, setPasswordResolve] = useState3(null);
1102
999
  const hasExecutedInitialSearch = useRef2(false);
1000
+ const handleToggleFullScreen = useCallback(() => {
1001
+ if (!isFullScreen && containerRef.current?.requestFullscreen) {
1002
+ containerRef.current.requestFullscreen();
1003
+ setIsFullScreen(true);
1004
+ } else if (isFullScreen && document.exitFullscreen) {
1005
+ document.exitFullscreen();
1006
+ setIsFullScreen(false);
1007
+ }
1008
+ }, [isFullScreen]);
1009
+ const handleSidebarClose = useCallback(() => {
1010
+ setIsSidebarOpen(false);
1011
+ setSearchQuery("");
1012
+ setSearchResults([]);
1013
+ setTotalSearchResults(0);
1014
+ setCurrentSearchResultIndex(0);
1015
+ pdfViewerRef.current?.search.stopSearch();
1016
+ }, []);
1017
+ const toolbar = mergeToolbarConfig({
1018
+ showDownload,
1019
+ showPrint,
1020
+ showMetadata,
1021
+ showProperties,
1022
+ onDownloadClick,
1023
+ onPrintClick,
1024
+ onMetadataClick,
1025
+ onPropertiesClick,
1026
+ toolbarActions: props.toolbarActions
1027
+ });
1103
1028
  const toolbarHandlers = useMemo(() => ({
1104
1029
  handleZoomIn: () => {
1105
1030
  pdfViewerRef.current?.zoom.zoomIn();
@@ -1165,7 +1090,13 @@ var PDFViewerContent = forwardRef((props, ref) => {
1165
1090
  setCurrentPage(current);
1166
1091
  });
1167
1092
  },
1168
- toggleSidebar: () => setIsSidebarOpen(!isSidebarOpen),
1093
+ toggleSidebar: () => {
1094
+ if (isSidebarOpen) {
1095
+ handleSidebarClose();
1096
+ } else {
1097
+ setIsSidebarOpen(true);
1098
+ }
1099
+ },
1169
1100
  handlePageInput: (e) => {
1170
1101
  const value = e.target.value;
1171
1102
  if (/^\d*$/.test(value)) {
@@ -1186,24 +1117,35 @@ var PDFViewerContent = forwardRef((props, ref) => {
1186
1117
  setCurrentPage(page);
1187
1118
  }
1188
1119
  }
1189
- }
1190
- }), [isSidebarOpen, totalPages]);
1120
+ },
1121
+ handleToggleFullScreen
1122
+ }), [isSidebarOpen, totalPages, handleToggleFullScreen]);
1191
1123
  useEffect3(() => {
1192
- console.log("came", initialSearchText, pdfViewerRef.current, hasExecutedInitialSearch.current);
1193
- if (pdfViewerRef.current && !hasExecutedInitialSearch.current && initialSearchText) {
1194
- hasExecutedInitialSearch.current = true;
1195
- setIsSidebarOpen(true);
1196
- setSearchQuery(initialSearchText);
1197
- handleSidebarSearch(initialSearchText, initialSearchPages);
1198
- setAutoExecuteSearch(false);
1199
- pdfViewerRef.current.search.searchText(initialSearchText).then((results) => {
1200
- console.log("results", results);
1201
- if (results?.results?.length > 0) {
1202
- pdfViewerRef.current?.navigation.goToPage(results.results[0].pageIndex + 1);
1203
- }
1124
+ console.log("came", initialSearchText, pdfViewerRef.current, hasExecutedInitialSearch.current, "state:", state, "totalPages:", totalPages);
1125
+ if (!initialSearchText || hasExecutedInitialSearch.current) return;
1126
+ const isPDFReady = state === "ready";
1127
+ const isPagesInitialized = totalPages > 0;
1128
+ const isViewerAvailable = !!pdfViewerRef.current;
1129
+ const isSearchAPIReady = !!pdfViewerRef.current?.search?.searchText;
1130
+ const canExecuteSearch = isPDFReady && isPagesInitialized && isViewerAvailable && isSearchAPIReady;
1131
+ if (!canExecuteSearch) return;
1132
+ hasExecutedInitialSearch.current = true;
1133
+ const SEARCH_INITIALIZATION_DELAY = 10;
1134
+ setTimeout(() => {
1135
+ if (!pdfViewerRef.current?.search?.searchText) {
1136
+ console.warn("Search API became unavailable, skipping initial search");
1137
+ hasExecutedInitialSearch.current = false;
1138
+ return;
1139
+ }
1140
+ requestAnimationFrame(() => {
1141
+ requestAnimationFrame(() => {
1142
+ setIsSidebarOpen(true);
1143
+ handleSidebarSearch(initialSearchText, initialSearchPages);
1144
+ setAutoExecuteSearch(false);
1145
+ });
1204
1146
  });
1205
- }
1206
- }, [pdfViewerRef.current, initialSearchText]);
1147
+ }, SEARCH_INITIALIZATION_DELAY);
1148
+ }, [state, totalPages, pdfViewerRef.current, initialSearchText, initialSearchPages]);
1207
1149
  useEffect3(() => {
1208
1150
  setSearchQuery("");
1209
1151
  setSearchResults([]);
@@ -1211,6 +1153,7 @@ var PDFViewerContent = forwardRef((props, ref) => {
1211
1153
  setTotalSearchResults(0);
1212
1154
  setIsSearching(false);
1213
1155
  setIsSidebarOpen(false);
1156
+ hasExecutedInitialSearch.current = false;
1214
1157
  setCurrentPage(1);
1215
1158
  setTotalPages(0);
1216
1159
  setZoom(100);
@@ -1393,45 +1336,15 @@ var PDFViewerContent = forwardRef((props, ref) => {
1393
1336
  });
1394
1337
  };
1395
1338
  const handleSearch = async () => {
1396
- if (searchQuery.trim()) {
1397
- setIsSearching(true);
1398
- const results = await pdfViewerRef.current?.search.searchText(searchQuery);
1399
- setIsSearching(false);
1400
- if (results && results.results) {
1401
- const formattedResults = results.results.map((result, index) => {
1402
- let textContent = "";
1403
- let contextContent = "";
1404
- if (typeof result === "string") {
1405
- textContent = result;
1406
- contextContent = result;
1407
- } else if (result.text) {
1408
- textContent = String(result.text);
1409
- contextContent = result.context ? String(result.context) : String(result.text);
1410
- } else if (result.str) {
1411
- textContent = String(result.str);
1412
- contextContent = String(result.str);
1413
- } else if (result.match) {
1414
- textContent = String(result.match);
1415
- contextContent = String(result.match);
1416
- } else {
1417
- textContent = JSON.stringify(result);
1418
- contextContent = textContent;
1419
- }
1420
- return {
1421
- pageNumber: (result.pageIndex ?? result.pageNumber ?? 0) + 1,
1422
- text: textContent,
1423
- context: contextContent,
1424
- index
1425
- };
1426
- });
1427
- setSearchResults(formattedResults);
1428
- setTotalSearchResults(formattedResults.length);
1429
- setCurrentSearchResultIndex(0);
1430
- } else {
1431
- setSearchResults([]);
1432
- setTotalSearchResults(0);
1433
- setCurrentSearchResultIndex(0);
1434
- }
1339
+ if (!searchQuery.trim()) return;
1340
+ setIsSearching(true);
1341
+ const results = await pdfViewerRef.current?.search.searchText(searchQuery);
1342
+ setIsSearching(false);
1343
+ if (results?.results && Array.isArray(results.results) && results.results.length > 0) {
1344
+ const formattedResults = formatSearchResults(results.results);
1345
+ updateSearchState(formattedResults);
1346
+ } else {
1347
+ clearSearchResults();
1435
1348
  }
1436
1349
  };
1437
1350
  const handleSearchKeyPress = (e) => {
@@ -1441,66 +1354,92 @@ var PDFViewerContent = forwardRef((props, ref) => {
1441
1354
  };
1442
1355
  const handleSidebarSearch = async (keyword, pageNumbers) => {
1443
1356
  setSearchQuery(keyword);
1444
- if (keyword.trim()) {
1445
- setIsSearching(true);
1446
- const results = await pdfViewerRef.current?.search.searchText(keyword);
1357
+ if (!keyword.trim()) {
1358
+ setSearchResults([]);
1359
+ setTotalSearchResults(0);
1360
+ setCurrentSearchResultIndex(0);
1361
+ pdfViewerRef.current?.search.stopSearch();
1362
+ return;
1363
+ }
1364
+ if (!pdfViewerRef.current?.search?.searchText) {
1365
+ console.warn("Search functionality not yet available");
1366
+ return;
1367
+ }
1368
+ setIsSearching(true);
1369
+ try {
1370
+ const results = await pdfViewerRef.current.search.searchText(keyword);
1371
+ console.log("Search completed:", results);
1447
1372
  setIsSearching(false);
1448
- if (results && results.results && results.results.length > 0) {
1449
- const formattedResults = results.results.map((result, index) => {
1450
- let textContent = "";
1451
- let contextContent = "";
1452
- if (result.context && typeof result.context === "object") {
1453
- const before = result.context.before || "";
1454
- const match = result.context.match || "";
1455
- const after = result.context.after || "";
1456
- textContent = match;
1457
- contextContent = `${before}${match}${after}`;
1458
- } else if (typeof result === "string") {
1459
- textContent = result;
1460
- contextContent = result;
1461
- } else {
1462
- textContent = String(result.match || result.text || "");
1463
- contextContent = textContent;
1464
- }
1465
- return {
1466
- pageNumber: (result.pageIndex ?? result.pageNumber ?? 0) + 1,
1467
- text: textContent,
1468
- context: contextContent,
1469
- index
1470
- };
1471
- });
1472
- setSearchResults(formattedResults);
1473
- setTotalSearchResults(formattedResults.length);
1474
- setCurrentSearchResultIndex(0);
1475
- if (formattedResults.length > 0) {
1476
- const firstPageNumber = formattedResults[0].pageNumber;
1477
- pdfViewerRef.current?.navigation.goToPage(firstPageNumber);
1478
- setCurrentPage(firstPageNumber);
1479
- }
1373
+ const hasValidResults = results?.results && Array.isArray(results.results) && results.results.length > 0;
1374
+ if (hasValidResults) {
1375
+ const formattedResults = formatSearchResults(results.results);
1376
+ updateSearchState(formattedResults);
1377
+ navigateToFirstResult(formattedResults);
1480
1378
  } else if (pageNumbers && pageNumbers.length > 0) {
1481
- const fallbackResults = pageNumbers.map((pageNum, index) => ({
1482
- pageNumber: pageNum,
1483
- text: keyword,
1484
- context: `"${keyword}" found on this page ${pageNum}`,
1485
- index
1486
- }));
1487
- setSearchResults(fallbackResults);
1488
- setTotalSearchResults(fallbackResults.length);
1489
- setCurrentSearchResultIndex(0);
1490
- pdfViewerRef.current?.navigation.goToPage(pageNumbers[0]);
1491
- setCurrentPage(pageNumbers[0]);
1379
+ const fallbackResults = createFallbackResults(pageNumbers, keyword);
1380
+ updateSearchState(fallbackResults);
1381
+ navigateToPage(pageNumbers[0]);
1492
1382
  } else {
1493
- setSearchResults([]);
1494
- setTotalSearchResults(0);
1495
- setCurrentSearchResultIndex(0);
1383
+ clearSearchResults();
1496
1384
  }
1497
- } else {
1498
- setSearchResults([]);
1499
- pdfViewerRef.current?.search.stopSearch();
1500
- setTotalSearchResults(0);
1501
- setCurrentSearchResultIndex(0);
1385
+ } catch (error2) {
1386
+ console.error("Search failed:", error2);
1387
+ setIsSearching(false);
1388
+ clearSearchResults();
1502
1389
  }
1503
1390
  };
1391
+ const formatSearchResults = (results) => {
1392
+ return results.map((result, index) => {
1393
+ let textContent = "";
1394
+ let contextContent = "";
1395
+ if (result.context && typeof result.context === "object") {
1396
+ const { before = "", match = "", after = "" } = result.context;
1397
+ textContent = match;
1398
+ contextContent = `${before}${match}${after}`;
1399
+ } else if (typeof result === "string") {
1400
+ textContent = result;
1401
+ contextContent = result;
1402
+ } else {
1403
+ textContent = String(result.match || result.text || "");
1404
+ contextContent = textContent;
1405
+ }
1406
+ return {
1407
+ pageNumber: (result.pageIndex ?? result.pageNumber ?? 0) + 1,
1408
+ text: textContent,
1409
+ context: contextContent,
1410
+ index
1411
+ };
1412
+ });
1413
+ };
1414
+ const createFallbackResults = (pageNumbers, keyword) => {
1415
+ return pageNumbers.map((pageNum, index) => ({
1416
+ pageNumber: pageNum,
1417
+ text: keyword,
1418
+ context: `"${keyword}" found on this page ${pageNum}`,
1419
+ index
1420
+ }));
1421
+ };
1422
+ const updateSearchState = (results) => {
1423
+ setSearchResults(results);
1424
+ setTotalSearchResults(results.length);
1425
+ setCurrentSearchResultIndex(0);
1426
+ };
1427
+ const clearSearchResults = () => {
1428
+ setSearchResults([]);
1429
+ setTotalSearchResults(0);
1430
+ setCurrentSearchResultIndex(0);
1431
+ };
1432
+ const navigateToFirstResult = (results) => {
1433
+ if (results.length > 0) {
1434
+ navigateToPage(results[0].pageNumber);
1435
+ }
1436
+ };
1437
+ const navigateToPage = (pageNumber) => {
1438
+ requestAnimationFrame(() => {
1439
+ pdfViewerRef.current?.navigation.goToPage(pageNumber);
1440
+ setCurrentPage(pageNumber);
1441
+ });
1442
+ };
1504
1443
  const handleSearchResultClick = (pageNumber, resultIndex) => {
1505
1444
  pdfViewerRef.current?.navigation.goToPage(pageNumber);
1506
1445
  setCurrentSearchResultIndex(resultIndex);
@@ -1643,7 +1582,7 @@ var PDFViewerContent = forwardRef((props, ref) => {
1643
1582
  height: "100%"
1644
1583
  }, children: /* @__PURE__ */ jsx6("p", { children: "Preparing PDF..." }) });
1645
1584
  }
1646
- return /* @__PURE__ */ jsxs5("div", { className: "pdf-viewer-container", children: [
1585
+ return /* @__PURE__ */ jsxs5("div", { ref: containerRef, className: "pdf-viewer-container", children: [
1647
1586
  /* @__PURE__ */ jsx6("style", { children: toolbarStyles }),
1648
1587
  /* @__PURE__ */ jsx6(
1649
1588
  PDFHeader,
@@ -1663,10 +1602,14 @@ var PDFViewerContent = forwardRef((props, ref) => {
1663
1602
  showPageCount,
1664
1603
  showZoomControls,
1665
1604
  showSearch,
1666
- showMetadata,
1667
- showProperties,
1668
- showDownload,
1669
- showPrint,
1605
+ showMetadata: !toolbar.isHidden("metadata"),
1606
+ showProperties: !toolbar.isHidden("properties"),
1607
+ showDownload: !toolbar.isHidden("download"),
1608
+ showPrint: !toolbar.isHidden("print"),
1609
+ disabledMetadata: toolbar.isDisabled("metadata"),
1610
+ disabledProperties: toolbar.isDisabled("properties"),
1611
+ disabledDownload: toolbar.isDisabled("download"),
1612
+ disabledPrint: toolbar.isDisabled("print"),
1670
1613
  onFirstPage: toolbarHandlers.handleFirstPage,
1671
1614
  onPreviousPage: toolbarHandlers.handlePreviousPage,
1672
1615
  onNextPage: toolbarHandlers.handleNextPage,
@@ -1678,10 +1621,11 @@ var PDFViewerContent = forwardRef((props, ref) => {
1678
1621
  onFitToWidth: toolbarHandlers.handleFitToWidth,
1679
1622
  onFitToPage: toolbarHandlers.handleFitToPage,
1680
1623
  onToggleSidebar: toolbarHandlers.toggleSidebar,
1681
- onDownloadClick,
1682
- onPrintClick,
1683
- onMetadataClick,
1684
- onPropertiesClick
1624
+ onToggleFullScreen: toolbarHandlers.handleToggleFullScreen,
1625
+ onDownloadClick: toolbar.getHandler("download", onDownloadClick),
1626
+ onPrintClick: toolbar.getHandler("print", onPrintClick),
1627
+ onMetadataClick: toolbar.getHandler("metadata", onMetadataClick),
1628
+ onPropertiesClick: toolbar.getHandler("properties", onPropertiesClick)
1685
1629
  }
1686
1630
  ),
1687
1631
  /* @__PURE__ */ jsxs5("div", { className: "pdf-viewer-main", children: [
@@ -1697,7 +1641,7 @@ var PDFViewerContent = forwardRef((props, ref) => {
1697
1641
  SearchSidebar,
1698
1642
  {
1699
1643
  isOpen: isSidebarOpen,
1700
- onClose: () => setIsSidebarOpen(false),
1644
+ onClose: handleSidebarClose,
1701
1645
  onSearch: handleSidebarSearch,
1702
1646
  onSearchResultClick: handleSearchResultClick,
1703
1647
  onNextResult: handleNextSearchResult,
@@ -1731,4 +1675,4 @@ PDFViewer.displayName = "PDFViewer";
1731
1675
  export {
1732
1676
  PDFViewer
1733
1677
  };
1734
- //# sourceMappingURL=chunk-K5SKH4SD.mjs.map
1678
+ //# sourceMappingURL=chunk-HLDLNHNY.mjs.map