@file-viewer/renderer-spreadsheet 3.3.1 → 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 (52) 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/chartRenderer.js +0 -5
  7. package/dist/spreadsheet/chartSampling.d.ts +0 -4
  8. package/dist/spreadsheet/chartSampling.js +0 -6
  9. package/dist/spreadsheet/comments.d.ts +40 -0
  10. package/dist/spreadsheet/comments.js +388 -0
  11. package/dist/spreadsheet/drawingAutoHeight.d.ts +7 -0
  12. package/dist/spreadsheet/drawingAutoHeight.js +51 -0
  13. package/dist/spreadsheet/rangeNavigation.d.ts +0 -2
  14. package/dist/spreadsheet/rangeNavigation.js +0 -4
  15. package/dist/spreadsheet/sourceRegion.d.ts +37 -0
  16. package/dist/spreadsheet/sourceRegion.js +54 -0
  17. package/dist/spreadsheet/state.d.ts +7 -2
  18. package/dist/spreadsheet/state.js +6 -2
  19. package/dist/spreadsheet/view.d.ts +9 -4
  20. package/dist/spreadsheet/view.js +98 -39
  21. package/dist/spreadsheet/viewport.d.ts +0 -1
  22. package/dist/spreadsheet/viewport.js +0 -2
  23. package/dist/spreadsheet/worker/sheetjs/SheetJsModel.d.ts +61 -2
  24. package/dist/spreadsheet/worker/sheetjs/SheetJsModel.js +134 -43
  25. package/dist/spreadsheet/worker/sheetjs/chartParser.d.ts +3 -2
  26. package/dist/spreadsheet/worker/sheetjs/chartParser.js +13 -24
  27. package/dist/spreadsheet/worker/sheetjs/color.js +8 -10
  28. package/dist/spreadsheet/worker/sheetjs/commentParser.d.ts +7 -0
  29. package/dist/spreadsheet/worker/sheetjs/commentParser.js +232 -0
  30. package/dist/spreadsheet/worker/sheetjs/drawingRowAnchor.d.ts +4 -0
  31. package/dist/spreadsheet/worker/sheetjs/drawingRowAnchor.js +90 -0
  32. package/dist/spreadsheet/worker/sheetjs/formulaValues.js +0 -9
  33. package/dist/spreadsheet/worker/sheetjs/parser.d.ts +40 -4
  34. package/dist/spreadsheet/worker/sheetjs/parser.js +453 -78
  35. package/dist/spreadsheet/worker/sheetjs/richDataParser.js +5 -4
  36. package/dist/spreadsheet/worker/sheetjs/richText.js +0 -1
  37. package/dist/spreadsheet/worker/sheetjs/rowSizing.d.ts +10 -0
  38. package/dist/spreadsheet/worker/sheetjs/rowSizing.js +156 -0
  39. package/dist/spreadsheet/worker/sheetjs/sheetLayout.d.ts +2 -4
  40. package/dist/spreadsheet/worker/sheetjs/sheetLayout.js +0 -8
  41. package/dist/spreadsheet/worker/sheetjs/sourceAnchor.d.ts +10 -0
  42. package/dist/spreadsheet/worker/sheetjs/sourceAnchor.js +286 -0
  43. package/dist/spreadsheet/worker/sheetjs/textEncoding.d.ts +1 -1
  44. package/dist/spreadsheet/worker/sheetjs/textEncoding.js +1 -8
  45. package/dist/spreadsheet/worker/sheetjs/workbookFont.d.ts +4 -0
  46. package/dist/spreadsheet/worker/sheetjs/workbookFont.js +15 -0
  47. package/dist/spreadsheet/worker/sheetjs/xmlBudget.d.ts +11 -0
  48. package/dist/spreadsheet/worker/sheetjs/xmlBudget.js +39 -0
  49. package/dist/spreadsheet/worker/type.d.ts +145 -3
  50. package/dist/spreadsheet.js +150 -63
  51. package/dist/worker/sheet.worker.js +49 -65
  52. package/package.json +23 -3
@@ -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
  };
@@ -129,12 +132,6 @@ const collectEVirtTableStyleDocuments = (documentRef) => [
129
132
  ].filter((value, index, values) => (!!value && values.indexOf(value) === index));
130
133
  const collectStyleElements = (documents) => documents.flatMap(candidateDocument => { var _a; return Array.from(((_a = candidateDocument.head) === null || _a === void 0 ? void 0 : _a.querySelectorAll('style')) || []); });
131
134
  let loadedEVirtTableStyleText = '';
132
- // e-virt-table bundles its complete stylesheet into the ESM entry and injects
133
- // unscoped :root, .dark, and table selectors into document.head. Capture that
134
- // exact version-matched CSS, remove only the node created by our import, and
135
- // install a scoped copy beside the renderer for both light and shadow DOM.
136
- // Independent layout, overlay, editor, and menu markers avoid mistaking an
137
- // app's partial compatibility overrides for the complete vendor sheet.
138
135
  export const resolveEVirtTableStyleText = (documentRef) => {
139
136
  var _a;
140
137
  const styles = collectStyleElements(collectEVirtTableStyleDocuments(documentRef));
@@ -158,9 +155,6 @@ const loadEVirtTable = async (documentRef) => {
158
155
  injectedStyles.forEach(style => style.remove());
159
156
  return {
160
157
  constructor: resolveEVirtTableConstructor(module),
161
- // The vendor entry injects CSS while its dynamic import is evaluated.
162
- // Prefer that newly-created node so an app's independently loaded table
163
- // version cannot be mistaken for the renderer-owned dependency.
164
158
  styleText: loadedEVirtTableStyleText || resolveEVirtTableStyleText(documentRef),
165
159
  };
166
160
  };
@@ -546,11 +540,11 @@ const writeSpreadsheetClipboard = async (documentRef, text) => {
546
540
  return copyTextWithTextareaFallback(documentRef, text);
547
541
  };
548
542
  const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
549
- 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;
550
544
  const documentRef = target.ownerDocument;
551
545
  const loadedEVirtTable = await loadEVirtTable(documentRef);
552
546
  const EVirtTable = loadedEVirtTable.constructor;
553
- 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));
554
548
  const zoomEmitter = createZoomChangeEmitter();
555
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;
556
550
  const darkMode = resolveFileViewerColorScheme((_d = context === null || context === void 0 ? void 0 : context.options) === null || _d === void 0 ? void 0 : _d.theme, systemDark) === 'dark';
@@ -571,12 +565,12 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
571
565
  loadingCopy.className = 'loading-copy';
572
566
  const loadingKicker = documentRef.createElement('span');
573
567
  loadingKicker.className = 'loading-kicker';
574
- loadingKicker.textContent = t('spreadsheet.loading.kicker');
568
+ t.text(loadingKicker, 'spreadsheet.loading.kicker');
575
569
  const loadingTitle = documentRef.createElement('strong');
576
570
  loadingTitle.dataset.loadingTitle = 'true';
577
- loadingTitle.textContent = t('spreadsheet.loading.title');
571
+ t.text(loadingTitle, 'spreadsheet.loading.title');
578
572
  const loadingHint = documentRef.createElement('p');
579
- loadingHint.textContent = t('spreadsheet.loading.hint');
573
+ t.text(loadingHint, 'spreadsheet.loading.hint');
580
574
  loadingCopy.append(loadingKicker, loadingTitle, loadingHint);
581
575
  const loadingSpinner = documentRef.createElement('span');
582
576
  loadingSpinner.className = 'loading-spinner';
@@ -591,7 +585,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
591
585
  const sheetLoadingDot = documentRef.createElement('span');
592
586
  sheetLoadingDot.className = 'sheet-loading-dot';
593
587
  const sheetLoadingText = documentRef.createElement('span');
594
- sheetLoadingText.textContent = t('spreadsheet.loading.streaming');
588
+ t.text(sheetLoadingText, 'spreadsheet.loading.streaming');
595
589
  const sheetLoadingSummary = documentRef.createElement('span');
596
590
  sheetLoadingSummary.className = 'sheet-loading-summary';
597
591
  sheetLoading.append(sheetLoadingDot, sheetLoadingText, sheetLoadingSummary);
@@ -613,26 +607,32 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
613
607
  imageLightbox.setAttribute('aria-modal', 'true');
614
608
  imageLightbox.setAttribute('aria-hidden', 'true');
615
609
  const lightboxImage = documentRef.createElement('img');
616
- lightboxImage.alt = t('image.lightbox.alt');
610
+ t.attr(lightboxImage, 'alt', 'image.lightbox.alt');
617
611
  lightboxImage.draggable = false;
618
612
  const lightboxCloseButton = documentRef.createElement('button');
619
613
  lightboxCloseButton.type = 'button';
620
- lightboxCloseButton.setAttribute('aria-label', t('image.lightbox.close'));
614
+ t.attr(lightboxCloseButton, 'aria-label', 'image.lightbox.close');
621
615
  lightboxCloseButton.textContent = '×';
622
616
  imageLightbox.append(lightboxImage, lightboxCloseButton);
623
617
  const toolbar = documentRef.createElement('div');
624
618
  toolbar.className = 'toolbar';
625
619
  const sheetTabsBar = documentRef.createElement('div');
626
620
  sheetTabsBar.className = 'btn-group';
627
- sheetTabsBar.setAttribute('aria-label', t('spreadsheet.tabs.ariaLabel'));
621
+ t.attr(sheetTabsBar, 'aria-label', 'spreadsheet.tabs.ariaLabel');
628
622
  const summary = documentRef.createElement('div');
629
623
  summary.className = 'summary';
630
624
  toolbar.append(sheetTabsBar, summary);
631
- 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);
632
629
  target.replaceChildren(createEVirtTableStyle(documentRef, target, loadedEVirtTable.styleText), createStyle(documentRef), root);
633
630
  let sheets = [];
631
+ let commentsError = false;
632
+ let commentViewport = null;
634
633
  let sheetIndex = 0;
635
634
  let errorMessage = '';
635
+ let loadError;
636
636
  let totalRows = 0;
637
637
  let totalCols = 0;
638
638
  let sheetDefaults = { ...DEFAULT_SHEET_DEFAULTS };
@@ -685,7 +685,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
685
685
  });
686
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;
687
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;
688
- 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()));
689
691
  const viewportFill = new SpreadsheetViewportFill();
690
692
  let renderedRows = [];
691
693
  const controller = createFileViewerWorkerController(createSpreadsheetWorkerFactory(target, buffer.byteLength, context), { logErrors: false });
@@ -717,6 +719,27 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
717
719
  table === null || table === void 0 ? void 0 : table.draw();
718
720
  },
719
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 });
720
743
  const getColumnLabel = (column) => {
721
744
  let value = Math.max(0, column) + 1;
722
745
  let label = '';
@@ -824,12 +847,10 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
824
847
  if (x < 0 || y < 0 || x > viewportRect.width || y > viewportRect.height) {
825
848
  return undefined;
826
849
  }
827
- // Charts are appended after images and therefore paint above them. Do not
828
- // open an image hidden under a chart when their saved bounds overlap.
829
- if ([...sheetCharts].reverse().some(chart => containsViewportPoint(chart, x, y))) {
850
+ if (sheetCharts.map(chart => applyAutoRowDrawingGeometry(chart, virtualState)).reverse().some(chart => containsViewportPoint(chart, x, y))) {
830
851
  return undefined;
831
852
  }
832
- return [...sheetImages].reverse().find(image => containsViewportPoint(image, x, y));
853
+ return sheetImages.map(image => applyAutoRowDrawingGeometry(image, virtualState)).reverse().find(image => containsViewportPoint(image, x, y));
833
854
  };
834
855
  const handleImageDoubleClick = (event) => {
835
856
  const image = findImageAtViewportPoint(event.clientX, event.clientY);
@@ -871,8 +892,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
871
892
  }
872
893
  const cachedRows = Math.min(loadedWindowCount * WINDOW_SIZE, totalRows);
873
894
  return t('spreadsheet.state.cachedRows', {
874
- cached: cachedRows.toLocaleString(),
875
- total: totalRows.toLocaleString(),
895
+ cached: cachedRows,
896
+ total: totalRows,
876
897
  });
877
898
  };
878
899
  const getStatusSummary = () => {
@@ -883,11 +904,11 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
883
904
  return '';
884
905
  }
885
906
  if (!cols) {
886
- return t('spreadsheet.state.rows', { rows: rows.toLocaleString() });
907
+ return t('spreadsheet.state.rows', { rows });
887
908
  }
888
909
  return t('spreadsheet.state.rowsAndColumns', {
889
- rows: rows.toLocaleString(),
890
- cols: cols.toLocaleString(),
910
+ rows,
911
+ cols,
891
912
  });
892
913
  };
893
914
  const getZoomState = () => ({
@@ -907,8 +928,6 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
907
928
  const horizontal = tableContainer
908
929
  ? Math.max(tableContainer.offsetHeight - tableContainer.clientHeight, 0)
909
930
  : 0;
910
- // e-virt-table may draw overlay scrollbars, so keep a small reserved lane
911
- // even when native scrollbar metrics report zero.
912
931
  return {
913
932
  vertical: vertical || EXCEL_IMAGE_SCROLLBAR_GUARD,
914
933
  horizontal: horizontal || EXCEL_IMAGE_SCROLLBAR_GUARD,
@@ -919,7 +938,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
919
938
  const guard = getImageViewportScrollbarGuard();
920
939
  const width = Math.max(imageViewportState.width - scalePx(INDEX_COLUMN_WIDTH) - guard.vertical, 0);
921
940
  const height = Math.max(imageViewportState.height - scalePx(HEADER_HEIGHT) - guard.horizontal, 0);
922
- const visibleImages = sheetImages.filter((image) => {
941
+ const visibleImages = sheetImages.map(image => applyAutoRowDrawingGeometry(image, virtualState)).filter((image) => {
923
942
  const x = scalePx(image.left) - imageViewportState.scrollX;
924
943
  const y = scalePx(image.top) - imageViewportState.scrollY;
925
944
  return x + scalePx(image.width) >= -margin &&
@@ -927,7 +946,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
927
946
  y + scalePx(image.height) >= -margin &&
928
947
  y <= height + margin;
929
948
  });
930
- const visibleCharts = sheetCharts.filter((chart) => {
949
+ const visibleCharts = sheetCharts.map(chart => applyAutoRowDrawingGeometry(chart, virtualState)).filter((chart) => {
931
950
  const x = scalePx(chart.left) - imageViewportState.scrollX;
932
951
  const y = scalePx(chart.top) - imageViewportState.scrollY;
933
952
  return x + scalePx(chart.width) >= -margin &&
@@ -989,19 +1008,20 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
989
1008
  });
990
1009
  };
991
1010
  const renderChrome = () => {
1011
+ commentsView.update(sheets, commentsError);
992
1012
  setHidden(loading, !showBlockingLoading());
993
1013
  const loadingTitle = loading.querySelector('[data-loading-title]');
994
1014
  if (loadingTitle) {
995
- loadingTitle.textContent = getSheetLoadingText();
1015
+ t.bind(loadingTitle, node => { node.textContent = getSheetLoadingText(); });
996
1016
  }
997
- error.textContent = errorMessage;
1017
+ t.bind(error, node => { node.textContent = errorMessage ? normalizeFileViewerErrorMessage(loadError || errorMessage, context === null || context === void 0 ? void 0 : context.options) : ''; });
998
1018
  setHidden(error, !errorMessage);
999
1019
  setHidden(sheetLoading, !showStreamingLoading());
1000
1020
  const cacheText = sheetLoading.querySelector('.sheet-loading-summary');
1001
1021
  if (cacheText) {
1002
- cacheText.textContent = getCachedSummary();
1022
+ t.bind(cacheText, node => { node.textContent = getCachedSummary(); });
1003
1023
  }
1004
- summary.textContent = getStatusSummary();
1024
+ t.bind(summary, node => { node.textContent = getStatusSummary(); });
1005
1025
  sheetTabsBar.replaceChildren(...getSheetTabs().map(sheet => {
1006
1026
  const button = documentRef.createElement('button');
1007
1027
  button.type = 'button';
@@ -1037,6 +1057,38 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1037
1057
  row.__baseHeight = baseHeight;
1038
1058
  row._height = scaleRowHeight(baseHeight);
1039
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
+ });
1040
1092
  const syncScaledRowHeights = () => {
1041
1093
  virtualState.rowHeightCache.forEach((height, rowIndex) => {
1042
1094
  const row = virtualState.rows[rowIndex];
@@ -1046,8 +1098,10 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1046
1098
  });
1047
1099
  };
1048
1100
  const setZoom = (scale) => {
1101
+ commentsView.hide();
1049
1102
  zoom = clampZoom(scale);
1050
1103
  syncScaledRowHeights();
1104
+ autoRowHeight.invalidate();
1051
1105
  syncTableLayout();
1052
1106
  zoomEmitter.emit();
1053
1107
  renderChrome();
@@ -1215,6 +1269,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1215
1269
  darkMode,
1216
1270
  resizableColumns,
1217
1271
  resizableRows,
1272
+ comments: activeComments(),
1273
+ showComment,
1274
+ commentLabel,
1218
1275
  copySelection: copySpreadsheetSelection,
1219
1276
  searchCell: getSearchCell,
1220
1277
  sheetDefaults,
@@ -1253,6 +1310,11 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1253
1310
  if (!table || !virtualState.active || !virtualState.totalRows || disposed) {
1254
1311
  return;
1255
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
+ }
1256
1318
  const head = Math.max(table.ctx.body.headIndex || 0, 0);
1257
1319
  const tail = Math.max(table.ctx.body.tailIndex || head, head);
1258
1320
  const scrollY = table.ctx.scrollY || 0;
@@ -1281,6 +1343,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1281
1343
  darkMode,
1282
1344
  resizableColumns,
1283
1345
  resizableRows,
1346
+ comments: activeComments(),
1347
+ showComment,
1348
+ commentLabel,
1284
1349
  copySelection: copySpreadsheetSelection,
1285
1350
  searchCell: getSearchCell,
1286
1351
  sheetDefaults,
@@ -1289,6 +1354,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1289
1354
  }),
1290
1355
  });
1291
1356
  enableEVirtTableShadowEventTargeting(table.ctx);
1357
+ table.on('overlayerChange', () => commentsView.restoreCellFocus());
1292
1358
  table.on('onScrollX', scheduleViewportLoad);
1293
1359
  table.on('onScrollY', scheduleViewportLoad);
1294
1360
  table.on('resize', scheduleViewportLoad);
@@ -1350,6 +1416,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1350
1416
  return;
1351
1417
  }
1352
1418
  applyDefaultInitialFit();
1419
+ autoRowHeight.enqueue(virtualState.autoHeightCells.keys());
1353
1420
  syncTableLayout();
1354
1421
  };
1355
1422
  const scheduleStableFirstPaintRefresh = () => {
@@ -1382,7 +1449,6 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1382
1449
  }
1383
1450
  refreshTableLayoutWhenVisible();
1384
1451
  }).catch(() => {
1385
- // Font readiness is only a paint stabilizer; rendering already has a fallback.
1386
1452
  }));
1387
1453
  };
1388
1454
  function setColumnWidthByKey(columns, key, width) {
@@ -1403,7 +1469,6 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1403
1469
  (_a = table === null || table === void 0 ? void 0 : table.setCustomHeader) === null || _a === void 0 ? void 0 : _a.call(table, { resizableData: {} }, true);
1404
1470
  }
1405
1471
  catch {
1406
- // 某些旧版 e-virt-table 类型没有公开 setCustomHeader,忽略即可,下一次 loadColumns 仍会使用 core 状态。
1407
1472
  }
1408
1473
  }
1409
1474
  function handleColumnResizeChange(event) {
@@ -1424,12 +1489,11 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1424
1489
  if (activeSheetId !== undefined) {
1425
1490
  sheetStateCache.set(activeSheetId, virtualState);
1426
1491
  }
1427
- // e-virt-table writes its pixel-width cache after emitting the resize event.
1428
- // Clear it after that write so our unscaled, per-sheet widths remain authoritative.
1429
1492
  queueMicrotask(() => {
1430
1493
  if (disposed || !table)
1431
1494
  return;
1432
1495
  clearTableResizableHeaderCache();
1496
+ autoRowHeight.invalidate();
1433
1497
  syncTableLayout();
1434
1498
  });
1435
1499
  }
@@ -1455,6 +1519,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1455
1519
  const baseHeight = normalizeRowHeight(Math.max(RESIZABLE_ROW_MIN_HEIGHT, Math.round(displayHeight / Math.max(zoom, 0.01))), virtualState.defaults.rowHeight);
1456
1520
  applyRowHeight(row, baseHeight);
1457
1521
  virtualState.rowHeightOverrides.set(rowIndex, baseHeight);
1522
+ virtualState.autoRowHeights.delete(rowIndex);
1523
+ virtualState.autoHeightRevision++;
1458
1524
  virtualState.rowHeightCache.set(rowIndex, baseHeight);
1459
1525
  const activeSheetId = getActiveSheetId();
1460
1526
  if (activeSheetId !== undefined) {
@@ -1494,13 +1560,13 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1494
1560
  if (!meta) {
1495
1561
  return;
1496
1562
  }
1497
- const { columns, dataKeys } = buildColumns(ws);
1563
+ const { columns, dataKeys } = buildColumns(ws, rowNumberMode);
1498
1564
  virtualState = {
1499
1565
  ...createEmptyVirtualState(),
1500
1566
  active: true,
1501
1567
  totalRows: meta.totalRows,
1502
1568
  totalCols: meta.totalCols,
1503
- indexOffset: detectIndexOffset(ws),
1569
+ indexOffset: detectIndexOffset(ws, rowNumberMode),
1504
1570
  defaults: ws.defaults,
1505
1571
  dataKeys,
1506
1572
  rows: buildRows(meta.totalRows),
@@ -1529,13 +1595,16 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1529
1595
  if (!row) {
1530
1596
  return;
1531
1597
  }
1532
- 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;
1533
1602
  applyRowHeight(row, height);
1534
1603
  virtualState.rowHeightCache.set(absoluteRow, height);
1535
1604
  });
1536
1605
  };
1537
1606
  const applyWindowRows = (ws) => {
1538
- var _a, _b, _c;
1607
+ var _a, _b, _c, _d;
1539
1608
  const meta = ws.meta;
1540
1609
  if (!meta) {
1541
1610
  return;
@@ -1557,7 +1626,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1557
1626
  row[getDataKey(colIndex)] = value;
1558
1627
  });
1559
1628
  const windowHeight = getRowHeight(ws.rowHeights, relativeRow, virtualState.defaults.rowHeight);
1560
- 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);
1561
1632
  applyRowHeight(row, height);
1562
1633
  row[ROW_STATE_FIELD] = RowState.Loaded;
1563
1634
  virtualState.rowHeightCache.set(absoluteRow, height);
@@ -1571,6 +1642,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1571
1642
  return;
1572
1643
  }
1573
1644
  const keys = [];
1645
+ for (let row = meta.startRow; row < meta.endRow; row++)
1646
+ virtualState.autoHeightCells.delete(row);
1574
1647
  Object.entries(ws.cell || {}).forEach(([key, value]) => {
1575
1648
  const [row, col] = key.split('-').map(Number);
1576
1649
  const absoluteKey = displayCellKey(meta.startRow + row, col + 1);
@@ -1579,6 +1652,12 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1579
1652
  return;
1580
1653
  }
1581
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
+ }
1582
1661
  keys.push(absoluteKey);
1583
1662
  });
1584
1663
  virtualState.windowCells.set(meta.startRow, keys);
@@ -1598,7 +1677,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1598
1677
  continue;
1599
1678
  }
1600
1679
  const coveredKey = displayCellKey(merge.row + rowOffset, merge.col + colOffset + 1);
1601
- virtualState.mergeCoveredMap.set(coveredKey, true);
1680
+ virtualState.mergeCoveredMap.set(coveredKey, startKey);
1602
1681
  }
1603
1682
  }
1604
1683
  });
@@ -1618,6 +1697,10 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1618
1697
  })));
1619
1698
  }
1620
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
+ }
1621
1704
  applyStructureRowHeights(structure === null || structure === void 0 ? void 0 : structure.rowHeights);
1622
1705
  if (structure === null || structure === void 0 ? void 0 : structure.images) {
1623
1706
  sheetImages = structure.images;
@@ -1648,6 +1731,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1648
1731
  applyWindowRows(ws);
1649
1732
  applyWindowCells(ws);
1650
1733
  applyDefaultInitialFit();
1734
+ autoRowHeight.enqueue(virtualState.windowRows.get(meta.startRow) || []);
1651
1735
  virtualState.loadedWindows.add(meta.startRow);
1652
1736
  virtualState.loadingWindows.delete(meta.startRow);
1653
1737
  syncWindowStats();
@@ -1680,6 +1764,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1680
1764
  ensureViewportWindows(start, end);
1681
1765
  };
1682
1766
  const resetViewState = () => {
1767
+ autoRowHeight.cancel();
1683
1768
  errorMessage = '';
1684
1769
  totalRows = 0;
1685
1770
  totalCols = 0;
@@ -1714,8 +1799,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1714
1799
  }
1715
1800
  cached.loadingWindows.clear();
1716
1801
  virtualState = cached;
1717
- // Cached rows store display heights from their last active zoom. Rebuild
1718
- // those heights from unscaled state before loading them into the table.
1802
+ autoRowHeight.invalidate();
1719
1803
  syncScaledRowHeights();
1720
1804
  errorMessage = '';
1721
1805
  totalRows = cached.totalRows;
@@ -1787,7 +1871,6 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1787
1871
  const scale = Number((_a = state.scale) !== null && _a !== void 0 ? _a : (_b = state.zoom) === null || _b === void 0 ? void 0 : _b.scale);
1788
1872
  if (Number.isFinite(scale) && scale > 0)
1789
1873
  setZoom(scale);
1790
- // Coordinate navigation supplies its own final scroll after the target loads.
1791
1874
  if (((_c = state.spreadsheet) === null || _c === void 0 ? void 0 : _c.range) || !sheets.length)
1792
1875
  return;
1793
1876
  const nextSheet = (_e = (_d = state.spreadsheet) === null || _d === void 0 ? void 0 : _d.sheetId) !== null && _e !== void 0 ? _e : getActiveSheetId();
@@ -1809,8 +1892,6 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1809
1892
  const restore = pendingViewRestore;
1810
1893
  if (!restore || !table || !virtualState.active || restore.sheetId !== getActiveSheetId())
1811
1894
  return;
1812
- // Cached sheet installation runs in a microtask and the table draws in RAF.
1813
- // Wait through that draw before its scroll bounds can clamp restored values.
1814
1895
  requestAnimationFrame(() => requestAnimationFrame(() => {
1815
1896
  if (pendingViewRestore !== restore || !restore.isCurrent() || !table || disposed)
1816
1897
  return;
@@ -1849,8 +1930,6 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1849
1930
  if (navigatingRange && !finishRange)
1850
1931
  return;
1851
1932
  const targetTop = Math.max(0, getSearchRowTop(pending.row) - Math.max(0, (tableHost.clientHeight || 0) * 0.35));
1852
- // The vendor's rendered header index can still be empty before its first
1853
- // draw. Source column geometry is ready as soon as the window is loaded.
1854
1933
  const columnLeft = getSearchColumnLeft(getDisplayColumns(virtualState.columns, zoom), virtualState.dataKeys[pending.col] || getDataKey(pending.col));
1855
1934
  const targetLeft = columnLeft === undefined
1856
1935
  ? table.ctx.scrollX || 0
@@ -1882,6 +1961,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1882
1961
  }
1883
1962
  function jumpToSpreadsheetCell(spreadsheet) {
1884
1963
  var _a;
1964
+ commentsView.hide();
1885
1965
  pendingSearchJump = spreadsheet;
1886
1966
  if (!spreadsheet) {
1887
1967
  return;
@@ -1899,6 +1979,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1899
1979
  requestPendingSearchWindow();
1900
1980
  }
1901
1981
  function handleSheet(index) {
1982
+ commentsView.hide();
1902
1983
  latestSearchRequest += 1;
1903
1984
  rangeNavigation.cancel();
1904
1985
  if (sheetIndex === index) {
@@ -1995,8 +2076,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1995
2076
  includeEmptySheets: fillViewport,
1996
2077
  });
1997
2078
  };
1998
- controller.onWorkerEvent('sheets', ({ sheets: list }) => {
2079
+ controller.onWorkerEvent('sheets', ({ sheets: list, commentsError: error }) => {
1999
2080
  sheets = list;
2081
+ commentsError = !!error;
2000
2082
  resolveWorkbookReady === null || resolveWorkbookReady === void 0 ? void 0 : resolveWorkbookReady();
2001
2083
  resolveWorkbookReady = null;
2002
2084
  const firstSheet = list.find((sheet) => !sheet.hidden) || list[0];
@@ -2038,7 +2120,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
2038
2120
  virtualState.loadingWindows.clear();
2039
2121
  syncWindowStats();
2040
2122
  }
2041
- errorMessage = message || t('spreadsheet.error.parseFailed');
2123
+ loadError = message ? new Error(message) : t.error('spreadsheet.error.parseFailed');
2124
+ errorMessage = loadError.message;
2042
2125
  renderChrome();
2043
2126
  });
2044
2127
  controller.onWorkerError((event) => {
@@ -2047,14 +2130,15 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
2047
2130
  resolveWorkbookReady = null;
2048
2131
  sheetInitializing = false;
2049
2132
  loadingState = false;
2050
- errorMessage = event.message || t('spreadsheet.error.workerFailed');
2133
+ loadError = event.message ? new Error(event.message) : t.error('spreadsheet.error.workerFailed');
2134
+ errorMessage = loadError.message;
2051
2135
  renderChrome();
2052
2136
  });
2053
- (_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, {
2054
2138
  print: false,
2055
2139
  exportHtml: false,
2056
2140
  });
2057
- (_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, {
2058
2142
  beforeCapture: async ({ signal }) => {
2059
2143
  while (!hasInitialWindow && !errorMessage && !disposed) {
2060
2144
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
@@ -2069,13 +2153,13 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
2069
2153
  });
2070
2154
  }
2071
2155
  if (errorMessage) {
2072
- throw new Error(errorMessage);
2156
+ throw loadError || new Error(errorMessage);
2073
2157
  }
2074
2158
  },
2075
2159
  getTarget: () => tableWrapper,
2076
2160
  });
2077
2161
  ensureTable();
2078
- 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) ||
2079
2163
  (typeof ResizeObserver !== 'undefined' ? ResizeObserver : undefined);
2080
2164
  if (ResizeObserverCtor) {
2081
2165
  resizeObserver = new ResizeObserverCtor(() => {
@@ -2084,6 +2168,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
2084
2168
  }
2085
2169
  resizeFrame = requestAnimationFrame(() => {
2086
2170
  resizeFrame = 0;
2171
+ autoRowHeight.enqueue(virtualState.autoHeightCells.keys());
2087
2172
  syncTableLayout();
2088
2173
  });
2089
2174
  });
@@ -2096,6 +2181,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
2096
2181
  unmount() {
2097
2182
  var _a, _b;
2098
2183
  disposed = true;
2184
+ autoRowHeight.destroy();
2185
+ commentsView.destroy();
2099
2186
  rangeNavigation.cancel('disposed');
2100
2187
  unsubscribeViewStateZoom();
2101
2188
  unregisterFileViewerViewStateProvider(root);