@file-viewer/renderer-spreadsheet 3.3.3 → 3.3.4

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 (41) hide show
  1. package/README.en.md +14 -0
  2. package/README.md +14 -0
  3. package/README.zh-CN.md +14 -0
  4. package/dist/spreadsheet/autoRowHeight.d.ts +16 -0
  5. package/dist/spreadsheet/autoRowHeight.js +208 -0
  6. package/dist/spreadsheet/comments.d.ts +40 -0
  7. package/dist/spreadsheet/comments.js +388 -0
  8. package/dist/spreadsheet/drawingAutoHeight.d.ts +7 -0
  9. package/dist/spreadsheet/drawingAutoHeight.js +51 -0
  10. package/dist/spreadsheet/sourceRegion.d.ts +37 -0
  11. package/dist/spreadsheet/sourceRegion.js +54 -0
  12. package/dist/spreadsheet/state.d.ts +7 -1
  13. package/dist/spreadsheet/state.js +6 -0
  14. package/dist/spreadsheet/view.d.ts +9 -4
  15. package/dist/spreadsheet/view.js +98 -27
  16. package/dist/spreadsheet/worker/sheetjs/SheetJsModel.d.ts +61 -2
  17. package/dist/spreadsheet/worker/sheetjs/SheetJsModel.js +134 -28
  18. package/dist/spreadsheet/worker/sheetjs/chartParser.d.ts +3 -2
  19. package/dist/spreadsheet/worker/sheetjs/chartParser.js +13 -5
  20. package/dist/spreadsheet/worker/sheetjs/commentParser.d.ts +7 -0
  21. package/dist/spreadsheet/worker/sheetjs/commentParser.js +232 -0
  22. package/dist/spreadsheet/worker/sheetjs/drawingRowAnchor.d.ts +4 -0
  23. package/dist/spreadsheet/worker/sheetjs/drawingRowAnchor.js +90 -0
  24. package/dist/spreadsheet/worker/sheetjs/parser.d.ts +40 -3
  25. package/dist/spreadsheet/worker/sheetjs/parser.js +452 -54
  26. package/dist/spreadsheet/worker/sheetjs/richDataParser.js +5 -2
  27. package/dist/spreadsheet/worker/sheetjs/rowSizing.d.ts +10 -0
  28. package/dist/spreadsheet/worker/sheetjs/rowSizing.js +156 -0
  29. package/dist/spreadsheet/worker/sheetjs/sheetLayout.d.ts +2 -0
  30. package/dist/spreadsheet/worker/sheetjs/sourceAnchor.d.ts +10 -0
  31. package/dist/spreadsheet/worker/sheetjs/sourceAnchor.js +286 -0
  32. package/dist/spreadsheet/worker/sheetjs/textEncoding.d.ts +1 -1
  33. package/dist/spreadsheet/worker/sheetjs/textEncoding.js +1 -1
  34. package/dist/spreadsheet/worker/sheetjs/workbookFont.d.ts +4 -0
  35. package/dist/spreadsheet/worker/sheetjs/workbookFont.js +15 -0
  36. package/dist/spreadsheet/worker/sheetjs/xmlBudget.d.ts +11 -0
  37. package/dist/spreadsheet/worker/sheetjs/xmlBudget.js +39 -0
  38. package/dist/spreadsheet/worker/type.d.ts +145 -0
  39. package/dist/spreadsheet.js +150 -39
  40. package/dist/worker/sheet.worker.js +49 -65
  41. package/package.json +22 -2
@@ -1,5 +1,8 @@
1
+ import { applyAutoRowDrawingGeometry } from './spreadsheet/drawingAutoHeight.js';
2
+ import { createAutoRowHeight } from './spreadsheet/autoRowHeight.js';
3
+ import { createSpreadsheetComments, spreadsheetCommentsStyle } from './spreadsheet/comments.js';
1
4
  import { createSpreadsheetRangeNavigation } from './spreadsheet/rangeNavigation.js';
2
- import { createFileViewerWorkerController, createFileViewerTranslator, createFileViewerZoomChangeEmitter as createZoomChangeEmitter, createEmptyFileViewerSearchState, registerFileViewerSearchProvider, registerFileViewerViewStateProvider, registerFileViewerZoomProvider, resolveFileViewerColorScheme, resolveFileViewerFitScale, resolveFileViewerRuntimeAssetBaseUrl, resolveFileViewerSpreadsheetWorkerUrl, unregisterFileViewerSearchProvider, unregisterFileViewerViewStateProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
5
+ import { createFileViewerWorkerController, createFileViewerTranslator, normalizeFileViewerErrorMessage, createFileViewerZoomChangeEmitter as createZoomChangeEmitter, createEmptyFileViewerSearchState, registerFileViewerSearchProvider, registerFileViewerViewStateProvider, registerFileViewerZoomProvider, resolveFileViewerColorScheme, resolveFileViewerFitScale, resolveFileViewerRuntimeAssetBaseUrl, resolveFileViewerSpreadsheetWorkerUrl, unregisterFileViewerSearchProvider, unregisterFileViewerViewStateProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
3
6
  import { renderSpreadsheetChart } from './spreadsheet/chartRenderer.js';
4
7
  import { createSpreadsheetImageSourceResolver } from './spreadsheet/imageSource.js';
5
8
  import { shouldFillSpreadsheetViewport, SpreadsheetViewportFill } from './spreadsheet/viewport.js';
@@ -82,7 +85,7 @@ const spreadsheetStyle = `
82
85
  @media (max-width:720px){.excel-wrapper .toolbar{align-items:stretch;flex-direction:column}.excel-wrapper .btn-group{flex:0 0 auto}.excel-wrapper .summary{max-width:none;white-space:normal}.excel-wrapper .sheet-loading{left:12px;right:12px;bottom:58px;justify-content:center}.excel-wrapper .loading-card{margin:18px;flex-direction:column;text-align:center}.excel-wrapper .excel-image-lightbox button{top:12px;right:12px}}
83
86
  @media (prefers-reduced-motion:reduce){.excel-wrapper .excel-image-lightbox,.excel-wrapper .excel-image-lightbox img,.excel-wrapper .excel-image-lightbox button{transition:none}}
84
87
  `;
85
- const scopedSpreadsheetStyle = spreadsheetStyle.replace(/\.excel-wrapper/g, SPREADSHEET_STYLE_SCOPE);
88
+ const scopedSpreadsheetStyle = (spreadsheetStyle + spreadsheetCommentsStyle).replace(/\.excel-wrapper/g, SPREADSHEET_STYLE_SCOPE);
86
89
  const isEVirtTableConstructor = (value) => {
87
90
  return typeof value === 'function';
88
91
  };
@@ -537,11 +540,11 @@ const writeSpreadsheetClipboard = async (documentRef, text) => {
537
540
  return copyTextWithTextareaFallback(documentRef, text);
538
541
  };
539
542
  const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
540
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
543
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
541
544
  const documentRef = target.ownerDocument;
542
545
  const loadedEVirtTable = await loadEVirtTable(documentRef);
543
546
  const EVirtTable = loadedEVirtTable.constructor;
544
- const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
547
+ const t = createFileViewerTranslator((context === null || context === void 0 ? void 0 : context.i18n) || (context === null || context === void 0 ? void 0 : context.options));
545
548
  const zoomEmitter = createZoomChangeEmitter();
546
549
  const systemDark = (_c = (_b = (_a = documentRef.defaultView) === null || _a === void 0 ? void 0 : _a.matchMedia) === null || _b === void 0 ? void 0 : _b.call(_a, '(prefers-color-scheme: dark)').matches) !== null && _c !== void 0 ? _c : false;
547
550
  const darkMode = resolveFileViewerColorScheme((_d = context === null || context === void 0 ? void 0 : context.options) === null || _d === void 0 ? void 0 : _d.theme, systemDark) === 'dark';
@@ -562,12 +565,12 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
562
565
  loadingCopy.className = 'loading-copy';
563
566
  const loadingKicker = documentRef.createElement('span');
564
567
  loadingKicker.className = 'loading-kicker';
565
- loadingKicker.textContent = t('spreadsheet.loading.kicker');
568
+ t.text(loadingKicker, 'spreadsheet.loading.kicker');
566
569
  const loadingTitle = documentRef.createElement('strong');
567
570
  loadingTitle.dataset.loadingTitle = 'true';
568
- loadingTitle.textContent = t('spreadsheet.loading.title');
571
+ t.text(loadingTitle, 'spreadsheet.loading.title');
569
572
  const loadingHint = documentRef.createElement('p');
570
- loadingHint.textContent = t('spreadsheet.loading.hint');
573
+ t.text(loadingHint, 'spreadsheet.loading.hint');
571
574
  loadingCopy.append(loadingKicker, loadingTitle, loadingHint);
572
575
  const loadingSpinner = documentRef.createElement('span');
573
576
  loadingSpinner.className = 'loading-spinner';
@@ -582,7 +585,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
582
585
  const sheetLoadingDot = documentRef.createElement('span');
583
586
  sheetLoadingDot.className = 'sheet-loading-dot';
584
587
  const sheetLoadingText = documentRef.createElement('span');
585
- sheetLoadingText.textContent = t('spreadsheet.loading.streaming');
588
+ t.text(sheetLoadingText, 'spreadsheet.loading.streaming');
586
589
  const sheetLoadingSummary = documentRef.createElement('span');
587
590
  sheetLoadingSummary.className = 'sheet-loading-summary';
588
591
  sheetLoading.append(sheetLoadingDot, sheetLoadingText, sheetLoadingSummary);
@@ -604,26 +607,32 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
604
607
  imageLightbox.setAttribute('aria-modal', 'true');
605
608
  imageLightbox.setAttribute('aria-hidden', 'true');
606
609
  const lightboxImage = documentRef.createElement('img');
607
- lightboxImage.alt = t('image.lightbox.alt');
610
+ t.attr(lightboxImage, 'alt', 'image.lightbox.alt');
608
611
  lightboxImage.draggable = false;
609
612
  const lightboxCloseButton = documentRef.createElement('button');
610
613
  lightboxCloseButton.type = 'button';
611
- lightboxCloseButton.setAttribute('aria-label', t('image.lightbox.close'));
614
+ t.attr(lightboxCloseButton, 'aria-label', 'image.lightbox.close');
612
615
  lightboxCloseButton.textContent = '×';
613
616
  imageLightbox.append(lightboxImage, lightboxCloseButton);
614
617
  const toolbar = documentRef.createElement('div');
615
618
  toolbar.className = 'toolbar';
616
619
  const sheetTabsBar = documentRef.createElement('div');
617
620
  sheetTabsBar.className = 'btn-group';
618
- sheetTabsBar.setAttribute('aria-label', t('spreadsheet.tabs.ariaLabel'));
621
+ t.attr(sheetTabsBar, 'aria-label', 'spreadsheet.tabs.ariaLabel');
619
622
  const summary = documentRef.createElement('div');
620
623
  summary.className = 'summary';
621
624
  toolbar.append(sheetTabsBar, summary);
622
- root.append(loading, error, tableWrapper, toolbar, imageLightbox);
625
+ const workbookBody = documentRef.createElement('div');
626
+ workbookBody.className = 'excel-body';
627
+ workbookBody.append(tableWrapper);
628
+ root.append(loading, error, workbookBody, toolbar, imageLightbox);
623
629
  target.replaceChildren(createEVirtTableStyle(documentRef, target, loadedEVirtTable.styleText), createStyle(documentRef), root);
624
630
  let sheets = [];
631
+ let commentsError = false;
632
+ let commentViewport = null;
625
633
  let sheetIndex = 0;
626
634
  let errorMessage = '';
635
+ let loadError;
627
636
  let totalRows = 0;
628
637
  let totalCols = 0;
629
638
  let sheetDefaults = { ...DEFAULT_SHEET_DEFAULTS };
@@ -676,7 +685,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
676
685
  });
677
686
  const resizableColumns = ((_f = (_e = context === null || context === void 0 ? void 0 : context.options) === null || _e === void 0 ? void 0 : _e.spreadsheet) === null || _f === void 0 ? void 0 : _f.resizableColumns) === true;
678
687
  const resizableRows = ((_h = (_g = context === null || context === void 0 ? void 0 : context.options) === null || _g === void 0 ? void 0 : _g.spreadsheet) === null || _h === void 0 ? void 0 : _h.resizableRows) === true;
679
- const fillViewport = shouldFillSpreadsheetViewport((_k = (_j = context === null || context === void 0 ? void 0 : context.options) === null || _j === void 0 ? void 0 : _j.spreadsheet) === null || _k === void 0 ? void 0 : _k.fillViewport, type || ((_l = context === null || context === void 0 ? void 0 : context.filename) === null || _l === void 0 ? void 0 : _l.split('.').pop()));
688
+ const rowNumberMode = ((_k = (_j = context === null || context === void 0 ? void 0 : context.options) === null || _j === void 0 ? void 0 : _j.spreadsheet) === null || _k === void 0 ? void 0 : _k.rowNumberMode) === 'legacy-records'
689
+ ? 'legacy-records' : 'source';
690
+ const fillViewport = shouldFillSpreadsheetViewport((_m = (_l = context === null || context === void 0 ? void 0 : context.options) === null || _l === void 0 ? void 0 : _l.spreadsheet) === null || _m === void 0 ? void 0 : _m.fillViewport, type || ((_o = context === null || context === void 0 ? void 0 : context.filename) === null || _o === void 0 ? void 0 : _o.split('.').pop()));
680
691
  const viewportFill = new SpreadsheetViewportFill();
681
692
  let renderedRows = [];
682
693
  const controller = createFileViewerWorkerController(createSpreadsheetWorkerFactory(target, buffer.byteLength, context), { logErrors: false });
@@ -708,6 +719,27 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
708
719
  table === null || table === void 0 ? void 0 : table.draw();
709
720
  },
710
721
  });
722
+ const commentsView = createSpreadsheetComments({
723
+ root, toolbar, body: workbookBody, options: context === null || context === void 0 ? void 0 : context.options, i18n: context === null || context === void 0 ? void 0 : context.i18n,
724
+ getSheetId: () => sheetIndex,
725
+ navigate: entry => {
726
+ var _a, _b;
727
+ commentsView.hide();
728
+ void ((_b = (_a = rangeNavigation.provider).applyState) === null || _b === void 0 ? void 0 : _b.call(_a, { spreadsheet: { range: {
729
+ sheetId: entry.sheetId, startRow: entry.row, endRow: entry.row,
730
+ startCol: entry.col, endCol: entry.col,
731
+ } } }));
732
+ },
733
+ });
734
+ const activeComments = () => { var _a; return ((_a = getActiveSheet()) === null || _a === void 0 ? void 0 : _a.comments) || []; };
735
+ const showComment = (comment, anchor, focus = true) => {
736
+ const sheet = getActiveSheet();
737
+ if (!sheet)
738
+ return;
739
+ commentViewport = [(table === null || table === void 0 ? void 0 : table.ctx.scrollX) || 0, (table === null || table === void 0 ? void 0 : table.ctx.scrollY) || 0, tableHost.clientWidth, tableHost.clientHeight];
740
+ commentsView.show(comment, sheet, anchor, focus);
741
+ };
742
+ const commentLabel = (comment) => t('spreadsheet.comments.open', { cell: comment.address });
711
743
  const getColumnLabel = (column) => {
712
744
  let value = Math.max(0, column) + 1;
713
745
  let label = '';
@@ -815,10 +847,10 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
815
847
  if (x < 0 || y < 0 || x > viewportRect.width || y > viewportRect.height) {
816
848
  return undefined;
817
849
  }
818
- if ([...sheetCharts].reverse().some(chart => containsViewportPoint(chart, x, y))) {
850
+ if (sheetCharts.map(chart => applyAutoRowDrawingGeometry(chart, virtualState)).reverse().some(chart => containsViewportPoint(chart, x, y))) {
819
851
  return undefined;
820
852
  }
821
- return [...sheetImages].reverse().find(image => containsViewportPoint(image, x, y));
853
+ return sheetImages.map(image => applyAutoRowDrawingGeometry(image, virtualState)).reverse().find(image => containsViewportPoint(image, x, y));
822
854
  };
823
855
  const handleImageDoubleClick = (event) => {
824
856
  const image = findImageAtViewportPoint(event.clientX, event.clientY);
@@ -860,8 +892,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
860
892
  }
861
893
  const cachedRows = Math.min(loadedWindowCount * WINDOW_SIZE, totalRows);
862
894
  return t('spreadsheet.state.cachedRows', {
863
- cached: cachedRows.toLocaleString(),
864
- total: totalRows.toLocaleString(),
895
+ cached: cachedRows,
896
+ total: totalRows,
865
897
  });
866
898
  };
867
899
  const getStatusSummary = () => {
@@ -872,11 +904,11 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
872
904
  return '';
873
905
  }
874
906
  if (!cols) {
875
- return t('spreadsheet.state.rows', { rows: rows.toLocaleString() });
907
+ return t('spreadsheet.state.rows', { rows });
876
908
  }
877
909
  return t('spreadsheet.state.rowsAndColumns', {
878
- rows: rows.toLocaleString(),
879
- cols: cols.toLocaleString(),
910
+ rows,
911
+ cols,
880
912
  });
881
913
  };
882
914
  const getZoomState = () => ({
@@ -906,7 +938,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
906
938
  const guard = getImageViewportScrollbarGuard();
907
939
  const width = Math.max(imageViewportState.width - scalePx(INDEX_COLUMN_WIDTH) - guard.vertical, 0);
908
940
  const height = Math.max(imageViewportState.height - scalePx(HEADER_HEIGHT) - guard.horizontal, 0);
909
- const visibleImages = sheetImages.filter((image) => {
941
+ const visibleImages = sheetImages.map(image => applyAutoRowDrawingGeometry(image, virtualState)).filter((image) => {
910
942
  const x = scalePx(image.left) - imageViewportState.scrollX;
911
943
  const y = scalePx(image.top) - imageViewportState.scrollY;
912
944
  return x + scalePx(image.width) >= -margin &&
@@ -914,7 +946,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
914
946
  y + scalePx(image.height) >= -margin &&
915
947
  y <= height + margin;
916
948
  });
917
- const visibleCharts = sheetCharts.filter((chart) => {
949
+ const visibleCharts = sheetCharts.map(chart => applyAutoRowDrawingGeometry(chart, virtualState)).filter((chart) => {
918
950
  const x = scalePx(chart.left) - imageViewportState.scrollX;
919
951
  const y = scalePx(chart.top) - imageViewportState.scrollY;
920
952
  return x + scalePx(chart.width) >= -margin &&
@@ -976,19 +1008,20 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
976
1008
  });
977
1009
  };
978
1010
  const renderChrome = () => {
1011
+ commentsView.update(sheets, commentsError);
979
1012
  setHidden(loading, !showBlockingLoading());
980
1013
  const loadingTitle = loading.querySelector('[data-loading-title]');
981
1014
  if (loadingTitle) {
982
- loadingTitle.textContent = getSheetLoadingText();
1015
+ t.bind(loadingTitle, node => { node.textContent = getSheetLoadingText(); });
983
1016
  }
984
- error.textContent = errorMessage;
1017
+ t.bind(error, node => { node.textContent = errorMessage ? normalizeFileViewerErrorMessage(loadError || errorMessage, context === null || context === void 0 ? void 0 : context.options) : ''; });
985
1018
  setHidden(error, !errorMessage);
986
1019
  setHidden(sheetLoading, !showStreamingLoading());
987
1020
  const cacheText = sheetLoading.querySelector('.sheet-loading-summary');
988
1021
  if (cacheText) {
989
- cacheText.textContent = getCachedSummary();
1022
+ t.bind(cacheText, node => { node.textContent = getCachedSummary(); });
990
1023
  }
991
- summary.textContent = getStatusSummary();
1024
+ t.bind(summary, node => { node.textContent = getStatusSummary(); });
992
1025
  sheetTabsBar.replaceChildren(...getSheetTabs().map(sheet => {
993
1026
  const button = documentRef.createElement('button');
994
1027
  button.type = 'button';
@@ -1024,6 +1057,38 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1024
1057
  row.__baseHeight = baseHeight;
1025
1058
  row._height = scaleRowHeight(baseHeight);
1026
1059
  };
1060
+ const autoRowHeight = createAutoRowHeight({
1061
+ host: root,
1062
+ getState: () => virtualState,
1063
+ getZoom: () => zoom,
1064
+ getFirstVisibleRow: () => (table === null || table === void 0 ? void 0 : table.ctx.body.headIndex) || 0,
1065
+ commit: changes => {
1066
+ var _a;
1067
+ if (disposed || !virtualState.active)
1068
+ return;
1069
+ const firstRow = (table === null || table === void 0 ? void 0 : table.ctx.body.headIndex) || 0;
1070
+ const beforeTop = getSearchRowTop(firstRow);
1071
+ const scrollY = (table === null || table === void 0 ? void 0 : table.ctx.scrollY) || 0, scrollX = (table === null || table === void 0 ? void 0 : table.ctx.scrollX) || 0;
1072
+ let changed = false;
1073
+ for (const [rowIndex, height] of changes) {
1074
+ const row = virtualState.rows[rowIndex];
1075
+ if (!row || Math.abs(((_a = virtualState.rowHeightCache.get(rowIndex)) !== null && _a !== void 0 ? _a : virtualState.defaults.rowHeight) - height) < 0.001)
1076
+ continue;
1077
+ virtualState.autoRowHeights.set(rowIndex, height);
1078
+ virtualState.rowHeightCache.set(rowIndex, height);
1079
+ applyRowHeight(row, height);
1080
+ changed = true;
1081
+ }
1082
+ if (!changed)
1083
+ return;
1084
+ virtualState.autoHeightRevision++;
1085
+ syncTableLayout();
1086
+ const delta = getSearchRowTop(firstRow) - beforeTop;
1087
+ if (delta && table)
1088
+ table.scrollTo(scrollX, Math.max(0, scrollY + delta));
1089
+ flushPendingSearchJump();
1090
+ },
1091
+ });
1027
1092
  const syncScaledRowHeights = () => {
1028
1093
  virtualState.rowHeightCache.forEach((height, rowIndex) => {
1029
1094
  const row = virtualState.rows[rowIndex];
@@ -1033,8 +1098,10 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1033
1098
  });
1034
1099
  };
1035
1100
  const setZoom = (scale) => {
1101
+ commentsView.hide();
1036
1102
  zoom = clampZoom(scale);
1037
1103
  syncScaledRowHeights();
1104
+ autoRowHeight.invalidate();
1038
1105
  syncTableLayout();
1039
1106
  zoomEmitter.emit();
1040
1107
  renderChrome();
@@ -1202,6 +1269,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1202
1269
  darkMode,
1203
1270
  resizableColumns,
1204
1271
  resizableRows,
1272
+ comments: activeComments(),
1273
+ showComment,
1274
+ commentLabel,
1205
1275
  copySelection: copySpreadsheetSelection,
1206
1276
  searchCell: getSearchCell,
1207
1277
  sheetDefaults,
@@ -1240,6 +1310,11 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1240
1310
  if (!table || !virtualState.active || !virtualState.totalRows || disposed) {
1241
1311
  return;
1242
1312
  }
1313
+ const viewport = [table.ctx.scrollX || 0, table.ctx.scrollY || 0, tableHost.clientWidth, tableHost.clientHeight];
1314
+ if (commentViewport && viewport.some((value, index) => value !== (commentViewport === null || commentViewport === void 0 ? void 0 : commentViewport[index]))) {
1315
+ commentsView.hide();
1316
+ commentViewport = null;
1317
+ }
1243
1318
  const head = Math.max(table.ctx.body.headIndex || 0, 0);
1244
1319
  const tail = Math.max(table.ctx.body.tailIndex || head, head);
1245
1320
  const scrollY = table.ctx.scrollY || 0;
@@ -1268,6 +1343,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1268
1343
  darkMode,
1269
1344
  resizableColumns,
1270
1345
  resizableRows,
1346
+ comments: activeComments(),
1347
+ showComment,
1348
+ commentLabel,
1271
1349
  copySelection: copySpreadsheetSelection,
1272
1350
  searchCell: getSearchCell,
1273
1351
  sheetDefaults,
@@ -1276,6 +1354,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1276
1354
  }),
1277
1355
  });
1278
1356
  enableEVirtTableShadowEventTargeting(table.ctx);
1357
+ table.on('overlayerChange', () => commentsView.restoreCellFocus());
1279
1358
  table.on('onScrollX', scheduleViewportLoad);
1280
1359
  table.on('onScrollY', scheduleViewportLoad);
1281
1360
  table.on('resize', scheduleViewportLoad);
@@ -1337,6 +1416,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1337
1416
  return;
1338
1417
  }
1339
1418
  applyDefaultInitialFit();
1419
+ autoRowHeight.enqueue(virtualState.autoHeightCells.keys());
1340
1420
  syncTableLayout();
1341
1421
  };
1342
1422
  const scheduleStableFirstPaintRefresh = () => {
@@ -1413,6 +1493,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1413
1493
  if (disposed || !table)
1414
1494
  return;
1415
1495
  clearTableResizableHeaderCache();
1496
+ autoRowHeight.invalidate();
1416
1497
  syncTableLayout();
1417
1498
  });
1418
1499
  }
@@ -1438,6 +1519,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1438
1519
  const baseHeight = normalizeRowHeight(Math.max(RESIZABLE_ROW_MIN_HEIGHT, Math.round(displayHeight / Math.max(zoom, 0.01))), virtualState.defaults.rowHeight);
1439
1520
  applyRowHeight(row, baseHeight);
1440
1521
  virtualState.rowHeightOverrides.set(rowIndex, baseHeight);
1522
+ virtualState.autoRowHeights.delete(rowIndex);
1523
+ virtualState.autoHeightRevision++;
1441
1524
  virtualState.rowHeightCache.set(rowIndex, baseHeight);
1442
1525
  const activeSheetId = getActiveSheetId();
1443
1526
  if (activeSheetId !== undefined) {
@@ -1477,13 +1560,13 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1477
1560
  if (!meta) {
1478
1561
  return;
1479
1562
  }
1480
- const { columns, dataKeys } = buildColumns(ws);
1563
+ const { columns, dataKeys } = buildColumns(ws, rowNumberMode);
1481
1564
  virtualState = {
1482
1565
  ...createEmptyVirtualState(),
1483
1566
  active: true,
1484
1567
  totalRows: meta.totalRows,
1485
1568
  totalCols: meta.totalCols,
1486
- indexOffset: detectIndexOffset(ws),
1569
+ indexOffset: detectIndexOffset(ws, rowNumberMode),
1487
1570
  defaults: ws.defaults,
1488
1571
  dataKeys,
1489
1572
  rows: buildRows(meta.totalRows),
@@ -1512,13 +1595,16 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1512
1595
  if (!row) {
1513
1596
  return;
1514
1597
  }
1515
- const height = (_a = virtualState.rowHeightOverrides.get(absoluteRow)) !== null && _a !== void 0 ? _a : normalizeRowHeight(rawHeight, virtualState.defaults.rowHeight);
1598
+ virtualState.fixedHeightRows.add(absoluteRow);
1599
+ const sourceHeight = normalizeRowHeight(rawHeight, virtualState.defaults.rowHeight);
1600
+ virtualState.sourceRowHeights.set(absoluteRow, sourceHeight);
1601
+ const height = sourceHeight <= 0.1 ? sourceHeight : (_a = virtualState.rowHeightOverrides.get(absoluteRow)) !== null && _a !== void 0 ? _a : sourceHeight;
1516
1602
  applyRowHeight(row, height);
1517
1603
  virtualState.rowHeightCache.set(absoluteRow, height);
1518
1604
  });
1519
1605
  };
1520
1606
  const applyWindowRows = (ws) => {
1521
- var _a, _b, _c;
1607
+ var _a, _b, _c, _d;
1522
1608
  const meta = ws.meta;
1523
1609
  if (!meta) {
1524
1610
  return;
@@ -1540,7 +1626,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1540
1626
  row[getDataKey(colIndex)] = value;
1541
1627
  });
1542
1628
  const windowHeight = getRowHeight(ws.rowHeights, relativeRow, virtualState.defaults.rowHeight);
1543
- const height = (_b = virtualState.rowHeightOverrides.get(absoluteRow)) !== null && _b !== void 0 ? _b : normalizeRowHeight(getRowHeight((_c = ws.structure) === null || _c === void 0 ? void 0 : _c.rowHeights, absoluteRow, windowHeight), virtualState.defaults.rowHeight);
1629
+ const sourceHeight = normalizeRowHeight(getRowHeight((_b = ws.structure) === null || _b === void 0 ? void 0 : _b.rowHeights, absoluteRow, windowHeight), virtualState.defaults.rowHeight);
1630
+ virtualState.sourceRowHeights.set(absoluteRow, sourceHeight);
1631
+ const height = sourceHeight <= 0.1 ? sourceHeight : (_c = virtualState.rowHeightOverrides.get(absoluteRow)) !== null && _c !== void 0 ? _c : (virtualState.fixedHeightRows.has(absoluteRow) ? sourceHeight : (_d = virtualState.autoRowHeights.get(absoluteRow)) !== null && _d !== void 0 ? _d : sourceHeight);
1544
1632
  applyRowHeight(row, height);
1545
1633
  row[ROW_STATE_FIELD] = RowState.Loaded;
1546
1634
  virtualState.rowHeightCache.set(absoluteRow, height);
@@ -1554,6 +1642,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1554
1642
  return;
1555
1643
  }
1556
1644
  const keys = [];
1645
+ for (let row = meta.startRow; row < meta.endRow; row++)
1646
+ virtualState.autoHeightCells.delete(row);
1557
1647
  Object.entries(ws.cell || {}).forEach(([key, value]) => {
1558
1648
  const [row, col] = key.split('-').map(Number);
1559
1649
  const absoluteKey = displayCellKey(meta.startRow + row, col + 1);
@@ -1562,6 +1652,12 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1562
1652
  return;
1563
1653
  }
1564
1654
  virtualState.cellCache.set(absoluteKey, style);
1655
+ if (style.wrapText) {
1656
+ const absoluteRow = meta.startRow + row;
1657
+ const columns = virtualState.autoHeightCells.get(absoluteRow) || new Set();
1658
+ columns.add(col);
1659
+ virtualState.autoHeightCells.set(absoluteRow, columns);
1660
+ }
1565
1661
  keys.push(absoluteKey);
1566
1662
  });
1567
1663
  virtualState.windowCells.set(meta.startRow, keys);
@@ -1581,7 +1677,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1581
1677
  continue;
1582
1678
  }
1583
1679
  const coveredKey = displayCellKey(merge.row + rowOffset, merge.col + colOffset + 1);
1584
- virtualState.mergeCoveredMap.set(coveredKey, true);
1680
+ virtualState.mergeCoveredMap.set(coveredKey, startKey);
1585
1681
  }
1586
1682
  }
1587
1683
  });
@@ -1601,6 +1697,10 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1601
1697
  })));
1602
1698
  }
1603
1699
  }
1700
+ if (structure === null || structure === void 0 ? void 0 : structure.rowSizing) {
1701
+ virtualState.autoHeightDisabled = structure.rowSizing.autoHeightDisabled === true;
1702
+ structure.rowSizing.fixedRows.forEach(row => virtualState.fixedHeightRows.add(row));
1703
+ }
1604
1704
  applyStructureRowHeights(structure === null || structure === void 0 ? void 0 : structure.rowHeights);
1605
1705
  if (structure === null || structure === void 0 ? void 0 : structure.images) {
1606
1706
  sheetImages = structure.images;
@@ -1631,6 +1731,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1631
1731
  applyWindowRows(ws);
1632
1732
  applyWindowCells(ws);
1633
1733
  applyDefaultInitialFit();
1734
+ autoRowHeight.enqueue(virtualState.windowRows.get(meta.startRow) || []);
1634
1735
  virtualState.loadedWindows.add(meta.startRow);
1635
1736
  virtualState.loadingWindows.delete(meta.startRow);
1636
1737
  syncWindowStats();
@@ -1663,6 +1764,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1663
1764
  ensureViewportWindows(start, end);
1664
1765
  };
1665
1766
  const resetViewState = () => {
1767
+ autoRowHeight.cancel();
1666
1768
  errorMessage = '';
1667
1769
  totalRows = 0;
1668
1770
  totalCols = 0;
@@ -1697,6 +1799,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1697
1799
  }
1698
1800
  cached.loadingWindows.clear();
1699
1801
  virtualState = cached;
1802
+ autoRowHeight.invalidate();
1700
1803
  syncScaledRowHeights();
1701
1804
  errorMessage = '';
1702
1805
  totalRows = cached.totalRows;
@@ -1858,6 +1961,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1858
1961
  }
1859
1962
  function jumpToSpreadsheetCell(spreadsheet) {
1860
1963
  var _a;
1964
+ commentsView.hide();
1861
1965
  pendingSearchJump = spreadsheet;
1862
1966
  if (!spreadsheet) {
1863
1967
  return;
@@ -1875,6 +1979,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1875
1979
  requestPendingSearchWindow();
1876
1980
  }
1877
1981
  function handleSheet(index) {
1982
+ commentsView.hide();
1878
1983
  latestSearchRequest += 1;
1879
1984
  rangeNavigation.cancel();
1880
1985
  if (sheetIndex === index) {
@@ -1971,8 +2076,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1971
2076
  includeEmptySheets: fillViewport,
1972
2077
  });
1973
2078
  };
1974
- controller.onWorkerEvent('sheets', ({ sheets: list }) => {
2079
+ controller.onWorkerEvent('sheets', ({ sheets: list, commentsError: error }) => {
1975
2080
  sheets = list;
2081
+ commentsError = !!error;
1976
2082
  resolveWorkbookReady === null || resolveWorkbookReady === void 0 ? void 0 : resolveWorkbookReady();
1977
2083
  resolveWorkbookReady = null;
1978
2084
  const firstSheet = list.find((sheet) => !sheet.hidden) || list[0];
@@ -2014,7 +2120,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
2014
2120
  virtualState.loadingWindows.clear();
2015
2121
  syncWindowStats();
2016
2122
  }
2017
- errorMessage = message || t('spreadsheet.error.parseFailed');
2123
+ loadError = message ? new Error(message) : t.error('spreadsheet.error.parseFailed');
2124
+ errorMessage = loadError.message;
2018
2125
  renderChrome();
2019
2126
  });
2020
2127
  controller.onWorkerError((event) => {
@@ -2023,14 +2130,15 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
2023
2130
  resolveWorkbookReady = null;
2024
2131
  sheetInitializing = false;
2025
2132
  loadingState = false;
2026
- errorMessage = event.message || t('spreadsheet.error.workerFailed');
2133
+ loadError = event.message ? new Error(event.message) : t.error('spreadsheet.error.workerFailed');
2134
+ errorMessage = loadError.message;
2027
2135
  renderChrome();
2028
2136
  });
2029
- (_m = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _m === void 0 ? void 0 : _m.call(context, {
2137
+ (_p = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _p === void 0 ? void 0 : _p.call(context, {
2030
2138
  print: false,
2031
2139
  exportHtml: false,
2032
2140
  });
2033
- (_o = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _o === void 0 ? void 0 : _o.call(context, {
2141
+ (_q = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _q === void 0 ? void 0 : _q.call(context, {
2034
2142
  beforeCapture: async ({ signal }) => {
2035
2143
  while (!hasInitialWindow && !errorMessage && !disposed) {
2036
2144
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
@@ -2045,13 +2153,13 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
2045
2153
  });
2046
2154
  }
2047
2155
  if (errorMessage) {
2048
- throw new Error(errorMessage);
2156
+ throw loadError || new Error(errorMessage);
2049
2157
  }
2050
2158
  },
2051
2159
  getTarget: () => tableWrapper,
2052
2160
  });
2053
2161
  ensureTable();
2054
- const ResizeObserverCtor = ((_p = getTargetWindow(target)) === null || _p === void 0 ? void 0 : _p.ResizeObserver) ||
2162
+ const ResizeObserverCtor = ((_r = getTargetWindow(target)) === null || _r === void 0 ? void 0 : _r.ResizeObserver) ||
2055
2163
  (typeof ResizeObserver !== 'undefined' ? ResizeObserver : undefined);
2056
2164
  if (ResizeObserverCtor) {
2057
2165
  resizeObserver = new ResizeObserverCtor(() => {
@@ -2060,6 +2168,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
2060
2168
  }
2061
2169
  resizeFrame = requestAnimationFrame(() => {
2062
2170
  resizeFrame = 0;
2171
+ autoRowHeight.enqueue(virtualState.autoHeightCells.keys());
2063
2172
  syncTableLayout();
2064
2173
  });
2065
2174
  });
@@ -2072,6 +2181,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
2072
2181
  unmount() {
2073
2182
  var _a, _b;
2074
2183
  disposed = true;
2184
+ autoRowHeight.destroy();
2185
+ commentsView.destroy();
2075
2186
  rangeNavigation.cancel('disposed');
2076
2187
  unsubscribeViewStateZoom();
2077
2188
  unregisterFileViewerViewStateProvider(root);