@file-viewer/renderer-spreadsheet 3.3.3 → 3.3.5

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 (42) 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 +203 -132
  7. package/dist/spreadsheet/comments.d.ts +40 -0
  8. package/dist/spreadsheet/comments.js +388 -0
  9. package/dist/spreadsheet/drawingAutoHeight.d.ts +7 -0
  10. package/dist/spreadsheet/drawingAutoHeight.js +51 -0
  11. package/dist/spreadsheet/sourceRegion.d.ts +37 -0
  12. package/dist/spreadsheet/sourceRegion.js +54 -0
  13. package/dist/spreadsheet/state.d.ts +7 -1
  14. package/dist/spreadsheet/state.js +6 -0
  15. package/dist/spreadsheet/view.d.ts +9 -4
  16. package/dist/spreadsheet/view.js +98 -27
  17. package/dist/spreadsheet/worker/sheetjs/SheetJsModel.d.ts +61 -2
  18. package/dist/spreadsheet/worker/sheetjs/SheetJsModel.js +137 -28
  19. package/dist/spreadsheet/worker/sheetjs/chartParser.d.ts +4 -3
  20. package/dist/spreadsheet/worker/sheetjs/chartParser.js +143 -29
  21. package/dist/spreadsheet/worker/sheetjs/commentParser.d.ts +7 -0
  22. package/dist/spreadsheet/worker/sheetjs/commentParser.js +232 -0
  23. package/dist/spreadsheet/worker/sheetjs/drawingRowAnchor.d.ts +4 -0
  24. package/dist/spreadsheet/worker/sheetjs/drawingRowAnchor.js +90 -0
  25. package/dist/spreadsheet/worker/sheetjs/parser.d.ts +40 -3
  26. package/dist/spreadsheet/worker/sheetjs/parser.js +452 -54
  27. package/dist/spreadsheet/worker/sheetjs/richDataParser.js +5 -2
  28. package/dist/spreadsheet/worker/sheetjs/rowSizing.d.ts +10 -0
  29. package/dist/spreadsheet/worker/sheetjs/rowSizing.js +156 -0
  30. package/dist/spreadsheet/worker/sheetjs/sheetLayout.d.ts +2 -0
  31. package/dist/spreadsheet/worker/sheetjs/sourceAnchor.d.ts +10 -0
  32. package/dist/spreadsheet/worker/sheetjs/sourceAnchor.js +286 -0
  33. package/dist/spreadsheet/worker/sheetjs/textEncoding.d.ts +1 -1
  34. package/dist/spreadsheet/worker/sheetjs/textEncoding.js +1 -1
  35. package/dist/spreadsheet/worker/sheetjs/workbookFont.d.ts +4 -0
  36. package/dist/spreadsheet/worker/sheetjs/workbookFont.js +15 -0
  37. package/dist/spreadsheet/worker/sheetjs/xmlBudget.d.ts +11 -0
  38. package/dist/spreadsheet/worker/sheetjs/xmlBudget.js +39 -0
  39. package/dist/spreadsheet/worker/type.d.ts +158 -0
  40. package/dist/spreadsheet.js +150 -39
  41. package/dist/worker/sheet.worker.js +43 -59
  42. package/package.json +23 -3
@@ -4,7 +4,7 @@ export const INDEX_COLUMN_WIDTH = 68;
4
4
  export const SPREADSHEET_MIN_ZOOM = 0.25;
5
5
  export const SPREADSHEET_MAX_ZOOM = 2.5;
6
6
  const TABLE_FONT_FAMILY = 'Aptos, Calibri, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif';
7
- const TABLE_FONT_SIZE = 11;
7
+ const TABLE_FONT_SIZE = 11 * 96 / 72;
8
8
  const MIN_RENDERABLE_ROW_HEIGHT = 8;
9
9
  const HIDDEN_ROW_HEIGHT = 0.1;
10
10
  const CELL_PADDING = 2;
@@ -254,31 +254,28 @@ const isPlainTextCell = (value) => {
254
254
  }
255
255
  return !/^\d+([./:-]\d+)*$/.test(text);
256
256
  };
257
- export const detectIndexOffset = (ws) => {
257
+ export const detectIndexOffset = (ws, mode = 'source') => {
258
+ if (mode !== 'legacy-records')
259
+ return 0;
258
260
  const meta = ws.meta;
259
261
  const rows = ws.data || [];
260
- if (!meta || rows.length < 2 || (ws.merge || []).length) {
262
+ if (!meta || rows.length < 2 || (ws.merge || []).length)
261
263
  return 0;
262
- }
263
- const firstRow = rows[0] || [];
264
- const secondRow = rows[1] || [];
265
- const firstRowValues = firstRow.filter(value => `${value !== null && value !== void 0 ? value : ''}`.trim() !== '');
266
- const secondRowValues = secondRow.filter(value => `${value !== null && value !== void 0 ? value : ''}`.trim() !== '');
267
- if (firstRowValues.length < Math.min(Math.max(Math.floor(meta.totalCols / 2), 3), 6)) {
264
+ const firstRowValues = (rows[0] || []).filter(value => `${value !== null && value !== void 0 ? value : ''}`.trim() !== '');
265
+ const secondRowValues = (rows[1] || []).filter(value => `${value !== null && value !== void 0 ? value : ''}`.trim() !== '');
266
+ if (firstRowValues.length < Math.min(Math.max(Math.floor(meta.totalCols / 2), 3), 6))
268
267
  return 0;
269
- }
270
- if (!firstRowValues.every(isPlainTextCell) || secondRowValues.length < 2) {
268
+ if (!firstRowValues.every(isPlainTextCell) || secondRowValues.length < 2)
271
269
  return 0;
272
- }
273
270
  return 1;
274
271
  };
275
- export const buildColumns = (ws) => {
272
+ export const buildColumns = (ws, mode = 'source') => {
276
273
  var _a;
277
274
  const columnsMeta = getSheetColumnsMeta(ws);
278
275
  const colWidths = getSheetColWidths(ws);
279
276
  const columns = [{
280
277
  key: INDEX_COLUMN_KEY,
281
- title: '',
278
+ title: mode === 'legacy-records' ? '#' : '',
282
279
  type: 'index',
283
280
  fixed: 'left',
284
281
  width: INDEX_COLUMN_WIDTH,
@@ -762,6 +759,12 @@ export const createTextLayer = (documentRef, value, style, padding) => {
762
759
  }
763
760
  return text;
764
761
  };
762
+ export const createAutoHeightProbe = (documentRef, value, style, width, zoom) => {
763
+ const scaled = scaleCellStyle(style, zoom) || {};
764
+ const probe = createTextLayer(documentRef, value, { ...scaled, font: scaled.font || getBodyFont(zoom) }, scaleNumber(CELL_PADDING, zoom));
765
+ Object.assign(probe.style, { width: `${width}px`, height: 'auto', minHeight: '0', overflow: 'visible', alignItems: 'flex-start', transform: 'none' });
766
+ return probe;
767
+ };
765
768
  const applyOverflowLayout = (text, overflowLayout) => {
766
769
  if (!overflowLayout) {
767
770
  return;
@@ -896,7 +899,8 @@ export const normalizeCellStyle = (meta) => {
896
899
  }
897
900
  return nextStyle;
898
901
  };
899
- export const createTableConfig = ({ hostHeight, darkMode = false, resizableColumns = false, resizableRows = false, copySelection, searchCell, sheetDefaults, virtualState, zoomScale = 1 }) => {
902
+ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColumns = false, resizableRows = false, comments = [], showComment, commentLabel, copySelection, searchCell, sheetDefaults, virtualState, zoomScale = 1 }) => {
903
+ const commentsByCell = new Map(comments.map(comment => [displayCellKey(comment.row, comment.col + 1), comment]));
900
904
  const normalizedScale = normalizeZoomScale(zoomScale);
901
905
  const scaledPadding = scaleNumber(CELL_PADDING, normalizedScale);
902
906
  const scaledHeaderHeight = scaleNumber(HEADER_HEIGHT, normalizedScale);
@@ -904,11 +908,42 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
904
908
  const scaledCellWidth = scaleNumber(sheetDefaults.colWidth, normalizedScale);
905
909
  const headerStyle = getIndexCellStyle(normalizedScale, darkMode);
906
910
  const loadingStyle = getLoadingCellStyle(normalizedScale, darkMode);
907
- const spanMethod = ({ rowIndex, colIndex, column }) => {
911
+ let firstVisibleColumn = 1;
912
+ const getProjectedMerge = (rowIndex, colIndex, column) => {
913
+ const cellKey = getCellCacheKey(rowIndex, colIndex, column);
914
+ const anchorKey = virtualState.mergeCoveredMap.get(cellKey);
915
+ const merge = anchorKey ? virtualState.mergeStartMap.get(anchorKey) : undefined;
916
+ const displayCol = getDataColumnIndex(column, colIndex) + 1;
917
+ if (!merge || merge.row !== rowIndex || displayCol !== firstVisibleColumn ||
918
+ merge.col >= displayCol || displayCol >= merge.col + merge.colspan) {
919
+ return undefined;
920
+ }
921
+ let width = 0;
922
+ let offsetLeft = 0;
923
+ for (let col = merge.col; col < merge.col + merge.colspan; col += 1) {
924
+ const sourceWidth = getRenderColumnWidth(virtualState.columns[col]);
925
+ const scaledWidth = sourceWidth > 0 ? scaleNumber(sourceWidth, normalizedScale) : 0;
926
+ width += scaledWidth;
927
+ if (col < displayCol)
928
+ offsetLeft += scaledWidth;
929
+ }
930
+ return { merge, anchorKey: anchorKey, width, offsetLeft, colspan: merge.col + merge.colspan - displayCol };
931
+ };
932
+ const spanMethod = ({ rowIndex, colIndex, column, visibleLeafColumns }) => {
933
+ if (visibleLeafColumns === null || visibleLeafColumns === void 0 ? void 0 : visibleLeafColumns.length) {
934
+ const visibleDataColumns = visibleLeafColumns.filter(item => item.key !== INDEX_COLUMN_KEY && isVisibleDataColumn(item));
935
+ if (visibleDataColumns.length) {
936
+ firstVisibleColumn = Math.min(...visibleDataColumns.map(item => getDataColumnIndex(item, 1) + 1));
937
+ }
938
+ }
908
939
  if (colIndex === 0) {
909
940
  return;
910
941
  }
911
942
  const key = getCellCacheKey(rowIndex, colIndex, column);
943
+ const projected = getProjectedMerge(rowIndex, colIndex, column);
944
+ if (projected) {
945
+ return { rowspan: projected.merge.rowspan, colspan: projected.colspan };
946
+ }
912
947
  if (virtualState.mergeCoveredMap.has(key)) {
913
948
  return { rowspan: 0, colspan: 0 };
914
949
  }
@@ -933,8 +968,9 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
933
968
  if (getRowState(currentRow) !== RowState.Loaded) {
934
969
  return loadingStyle;
935
970
  }
936
- const style = scaleCellStyle(virtualState.cellCache.get(getCellCacheKey(rowIndex, colIndex, column)), normalizedScale);
937
- const match = searchCell === null || searchCell === void 0 ? void 0 : searchCell(rowIndex, getDataColumnIndex(column, colIndex));
971
+ const projected = getProjectedMerge(rowIndex, colIndex, column);
972
+ const style = scaleCellStyle(virtualState.cellCache.get((projected === null || projected === void 0 ? void 0 : projected.anchorKey) || getCellCacheKey(rowIndex, colIndex, column)), normalizedScale);
973
+ const match = searchCell === null || searchCell === void 0 ? void 0 : searchCell(rowIndex, projected ? projected.merge.col - 1 : getDataColumnIndex(column, colIndex));
938
974
  return match ? { ...style, backgroundColor: match === 'active' ? '#ffbf47' : '#fff1a8', color: '#202124' } : style;
939
975
  };
940
976
  const renderMethod = ({ row, rowIndex, colIndex, column, value }) => {
@@ -942,20 +978,24 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
942
978
  if (colIndex === 0 || isHiddenVirtualRow(currentRow) || getRowState(currentRow) !== RowState.Loaded) {
943
979
  return undefined;
944
980
  }
945
- const cellKey = getCellCacheKey(rowIndex, colIndex, column);
946
- if (virtualState.mergeCoveredMap.has(cellKey)) {
981
+ const ownCellKey = getCellCacheKey(rowIndex, colIndex, column);
982
+ const projected = getProjectedMerge(rowIndex, colIndex, column);
983
+ if (virtualState.mergeCoveredMap.has(ownCellKey) && !projected) {
947
984
  return undefined;
948
985
  }
986
+ const cellKey = (projected === null || projected === void 0 ? void 0 : projected.anchorKey) || ownCellKey;
949
987
  const style = scaleCellStyle(virtualState.cellCache.get(cellKey), normalizedScale);
950
- const dataColIndex = getDataColumnIndex(column, colIndex);
988
+ const dataColIndex = projected ? projected.merge.col - 1 : getDataColumnIndex(column, colIndex);
989
+ const renderValue = projected ? currentRow[getDataKey(dataColIndex)] : value;
951
990
  const measureDocument = typeof document === 'undefined' ? undefined : document;
952
- const overflowLayout = getExcelOverflowLayout(virtualState, currentRow, rowIndex, dataColIndex, column, style, value, normalizedScale, measureDocument);
953
- const mirror = !hasRenderableValue(value)
991
+ const overflowLayout = projected ? { left: -projected.offsetLeft, width: projected.width } : getExcelOverflowLayout(virtualState, currentRow, rowIndex, dataColIndex, column, style, renderValue, normalizedScale, measureDocument);
992
+ const mirror = !projected && !hasRenderableValue(renderValue)
954
993
  ? getLeftOverflowMirror(virtualState, currentRow, rowIndex, dataColIndex, normalizedScale, measureDocument)
955
994
  : undefined;
956
995
  const match = searchCell === null || searchCell === void 0 ? void 0 : searchCell(rowIndex, dataColIndex);
957
996
  const renderText = shouldRenderTextInOverlay(style, column) || !!overflowLayout || !!mirror || !!match;
958
- if (!hasBorder(style) && !renderText) {
997
+ const comment = commentsByCell.get(cellKey);
998
+ if (!hasBorder(style) && !renderText && !comment) {
959
999
  return undefined;
960
1000
  }
961
1001
  return ((cellEl) => {
@@ -969,7 +1009,35 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
969
1009
  const collapsedStyle = hasBorder(style)
970
1010
  ? getCollapsedBorderStyle(virtualState, rowIndex, dataColIndex, baseStyle, normalizedScale)
971
1011
  : baseStyle;
972
- renderCellOverlay(cellEl, collapsedStyle, (mirror === null || mirror === void 0 ? void 0 : mirror.style) || collapsedStyle, mirror ? mirror.value : value, renderText, (mirror === null || mirror === void 0 ? void 0 : mirror.overflowLayout) || overflowLayout, normalizedScale);
1012
+ renderCellOverlay(cellEl, projected ? { ...collapsedStyle, borderLeft: undefined } : collapsedStyle, (mirror === null || mirror === void 0 ? void 0 : mirror.style) || collapsedStyle, mirror ? mirror.value : renderValue, renderText, (mirror === null || mirror === void 0 ? void 0 : mirror.overflowLayout) || overflowLayout, normalizedScale);
1013
+ if (comment) {
1014
+ cellEl.style.pointerEvents = 'auto';
1015
+ const indicator = cellEl.ownerDocument.createElement('button');
1016
+ indicator.type = 'button';
1017
+ indicator.className = 'excel-comment-indicator';
1018
+ indicator.dataset.cell = comment.address;
1019
+ indicator.dataset.kind = comment.kind;
1020
+ indicator.dataset.resolved = String(comment.resolved);
1021
+ indicator.setAttribute('aria-label', (commentLabel === null || commentLabel === void 0 ? void 0 : commentLabel(comment)) || comment.address);
1022
+ const open = (event) => { event.stopPropagation(); showComment === null || showComment === void 0 ? void 0 : showComment(comment, indicator); };
1023
+ indicator.addEventListener('pointerdown', event => event.stopPropagation());
1024
+ indicator.addEventListener('click', open);
1025
+ indicator.addEventListener('keydown', event => {
1026
+ if (event.key === 'Enter' || event.key === ' ') {
1027
+ event.preventDefault();
1028
+ open(event);
1029
+ }
1030
+ });
1031
+ let hoverTimer;
1032
+ indicator.addEventListener('pointerenter', () => {
1033
+ hoverTimer = setTimeout(() => {
1034
+ if (indicator.isConnected)
1035
+ showComment === null || showComment === void 0 ? void 0 : showComment(comment, indicator, false);
1036
+ }, 250);
1037
+ });
1038
+ indicator.addEventListener('pointerleave', () => clearTimeout(hoverTimer));
1039
+ cellEl.append(indicator);
1040
+ }
973
1041
  cellEl.style.boxShadow = match === 'active' ? 'inset 0 0 0 2px #9a5700' : '';
974
1042
  if (match) {
975
1043
  cellEl.dataset.spreadsheetSearch = match;
@@ -987,8 +1055,8 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
987
1055
  return {
988
1056
  ROW_KEY: ROW_KEY_FIELD,
989
1057
  DISABLED: true,
990
- HEIGHT: Math.max(hostHeight, 240),
991
- MAX_HEIGHT: Math.max(hostHeight, 240),
1058
+ HEIGHT: hostHeight > 0 ? hostHeight : 240,
1059
+ MAX_HEIGHT: hostHeight > 0 ? hostHeight : 240,
992
1060
  HEADER_HEIGHT: scaledHeaderHeight,
993
1061
  CELL_HEIGHT: scaledCellHeight,
994
1062
  CELL_WIDTH: scaledCellWidth,
@@ -1060,6 +1128,9 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
1060
1128
  if (getRowState(row) !== RowState.Loaded) {
1061
1129
  return '';
1062
1130
  }
1131
+ if (getProjectedMerge(rowIndex, colIndex, column)) {
1132
+ return '';
1133
+ }
1063
1134
  const currentRow = row;
1064
1135
  const style = scaleCellStyle(virtualState.cellCache.get(getCellCacheKey(rowIndex, colIndex, column)), normalizedScale);
1065
1136
  const dataColIndex = getDataColumnIndex(column, colIndex);
@@ -1,5 +1,5 @@
1
- import type { CellObject, Range, WorkSheet } from 'styled-exceljs';
2
- import type { CellMerge, SheetChartDefinition, SheetCellImage, SheetCellMetadata, SheetColumn, SheetModel, SheetStructure, SheetWindow } from '../type.js';
1
+ import type { CellObject, CellStyle, Range, WorkSheet } from 'styled-exceljs';
2
+ import type { CellMerge, SheetChartDefinition, SheetCellImage, SheetCellMetadata, SheetColumn, SheetModel, SheetStructure, SheetWindow, SheetRegion } from '../type.js';
3
3
  export declare const createAutoFitSampleRanges: (totalRowCount: number, totalColCount: number) => Range[];
4
4
  export declare const defaults: {
5
5
  rowHeight: number;
@@ -12,6 +12,7 @@ interface SheetSliceOptions {
12
12
  totalCols?: number;
13
13
  charts?: SheetChartDefinition[];
14
14
  cellImages?: SheetCellImage[];
15
+ defaultFont?: CellStyle['font'];
15
16
  }
16
17
  interface SheetObjectOptions {
17
18
  includeLayout?: boolean;
@@ -19,6 +20,7 @@ interface SheetObjectOptions {
19
20
  export declare const formatCellValue: (cell?: CellObject) => string;
20
21
  export default class SheetJsModel implements SheetModel {
21
22
  private readonly _ws;
23
+ private readonly _defaultFont?;
22
24
  private readonly _startRow;
23
25
  private readonly _pageSize;
24
26
  private readonly _totalRows?;
@@ -65,6 +67,7 @@ export default class SheetJsModel implements SheetModel {
65
67
  private getCharts;
66
68
  private getAllMerge;
67
69
  private getData;
70
+ private getCellMetadata;
68
71
  private getCell;
69
72
  private getMerge;
70
73
  private getRowHeights;
@@ -77,6 +80,62 @@ export default class SheetJsModel implements SheetModel {
77
80
  private getColWidths;
78
81
  private getColumns;
79
82
  private getStructure;
83
+ toRegionObject(region: SheetRegion): {
84
+ coordinateSpace: "region-local";
85
+ region: {
86
+ id: number;
87
+ startRow: number;
88
+ startCol: number;
89
+ rowCount: number;
90
+ colCount: number;
91
+ };
92
+ defaults: {
93
+ rowHeight: number;
94
+ colWidth: number;
95
+ };
96
+ data: string[][];
97
+ cell: Record<string, SheetCellMetadata>;
98
+ rows: {
99
+ sourceRow: number;
100
+ height: number;
101
+ fixed: boolean;
102
+ hidden: boolean;
103
+ }[];
104
+ columns: {
105
+ sourceCol: number;
106
+ title: string;
107
+ hidden: boolean;
108
+ width: number;
109
+ }[];
110
+ merges: {
111
+ source: CellMerge;
112
+ anchorValue: string;
113
+ anchorMetadata: SheetCellMetadata | undefined;
114
+ contained: boolean;
115
+ }[];
116
+ sourceObjects: {
117
+ images: {
118
+ id: string | undefined;
119
+ src: string | undefined;
120
+ anchor: import("styled-exceljs").DrawingAnchor | undefined;
121
+ contentType: string | undefined;
122
+ rowAnchor: import("../type.js").SheetRowAnchor | undefined;
123
+ }[];
124
+ charts: SheetChartDefinition[];
125
+ cellImages: SheetCellImage[];
126
+ };
127
+ sourceGeometry: {
128
+ rows: {
129
+ index: number;
130
+ size: number;
131
+ }[];
132
+ columns: {
133
+ index: number;
134
+ size: number;
135
+ }[];
136
+ };
137
+ autoHeightDisabled: boolean;
138
+ };
80
139
  toObject(options?: SheetObjectOptions): object;
81
140
  }
82
141
  export {};
@@ -1,3 +1,5 @@
1
+ import { assertSheetRegion, regionIntersects, ORDINARY_GRID_BUDGET } from '../../sourceRegion.js';
2
+ import { readImageRowAnchors } from './drawingRowAnchor.js';
1
3
  import { utils } from 'styled-exceljs';
2
4
  import { getTintColor, indexedColors } from './color.js';
3
5
  import { parseCellRichText, richTextToPlainText } from './richText.js';
@@ -353,6 +355,7 @@ class SheetJsModel {
353
355
  }
354
356
  constructor(ws, options) {
355
357
  this._ws = ws;
358
+ this._defaultFont = options.defaultFont;
356
359
  this._startRow = Math.max(options.startRow || 0, 0);
357
360
  this._pageSize = Math.max(options.pageSize || 500, 1);
358
361
  this._totalRows = options.totalRows;
@@ -444,10 +447,18 @@ class SheetJsModel {
444
447
  return this.ws[utils.encode_cell({ r: row, c: col })];
445
448
  }
446
449
  getAxisOffset(index, sizes, fallback) {
447
- let offset = 0;
448
- for (let current = 0; current < index; current += 1) {
449
- offset += getVectorSize(sizes, current, fallback);
450
- }
450
+ if (typeof sizes === 'number')
451
+ return index * sizes;
452
+ let offset = index * fallback;
453
+ if (sizes)
454
+ for (const key in sizes) {
455
+ if (!Object.prototype.hasOwnProperty.call(sizes, key))
456
+ continue;
457
+ const current = Number(key);
458
+ if (Number.isSafeInteger(current) && current >= 0 && current < index && sizes[current] !== undefined) {
459
+ offset += sizes[current] - fallback;
460
+ }
461
+ }
451
462
  return offset;
452
463
  }
453
464
  getMarkerLeft(marker) {
@@ -468,6 +479,7 @@ class SheetJsModel {
468
479
  if (!images.length && !this._cellImages.length) {
469
480
  return undefined;
470
481
  }
482
+ const rowAnchors = readImageRowAnchors(drawings === null || drawings === void 0 ? void 0 : drawings.raw, images);
471
483
  const drawingImages = images.flatMap((image, index) => {
472
484
  var _a, _b, _c, _d, _e;
473
485
  const anchor = image.anchor;
@@ -482,6 +494,7 @@ class SheetJsModel {
482
494
  return [{
483
495
  id: image.id || ((_e = image.objectId) === null || _e === void 0 ? void 0 : _e.toString()) || image.target || `image-${index + 1}`,
484
496
  src: image.dataURI,
497
+ ...(rowAnchors.has(image) ? { rowAnchor: rowAnchors.get(image) } : {}),
485
498
  contentType: image.contentType,
486
499
  left: Math.max(0, left),
487
500
  top: Math.max(0, top),
@@ -499,6 +512,7 @@ class SheetJsModel {
499
512
  }
500
513
  return [{
501
514
  ...image,
515
+ rowAnchor: { mode: 'cell', fromRow: image.row, fromOffset: 0 },
502
516
  left: this.getAxisOffset(image.col, this.getColWidths(), this.defaults.colWidth),
503
517
  top: this.getAxisOffset(image.row, this.getAllRowHeights(), this.defaults.rowHeight),
504
518
  width,
@@ -521,10 +535,14 @@ class SheetJsModel {
521
535
  : top + emuToPixels((_b = chart.ext) === null || _b === void 0 ? void 0 : _b.height);
522
536
  return {
523
537
  id: chart.id,
538
+ ...(chart.rowAnchor ? { rowAnchor: chart.rowAnchor } : {}),
524
539
  type: chart.type,
525
540
  title: chart.title,
526
541
  categoryAxisTitle: chart.categoryAxisTitle,
542
+ categoryAxisId: chart.categoryAxisId,
543
+ categoryAxisDate: chart.categoryAxisDate,
527
544
  valueAxisTitle: chart.valueAxisTitle,
545
+ valueAxes: chart.valueAxes,
528
546
  categoryAxisFontSize: chart.categoryAxisFontSize,
529
547
  valueAxisFontSize: chart.valueAxisFontSize,
530
548
  barDirection: chart.barDirection,
@@ -570,26 +588,45 @@ class SheetJsModel {
570
588
  }
571
589
  return fixMatrix(result, this.totalCols);
572
590
  }
573
- getCell() {
591
+ getCellMetadata(rowIndex, colIndex, cell) {
574
592
  var _a, _b;
575
- const result = {};
576
593
  const { '!cols': cols = [], '!rows': rows = [] } = this.ws;
594
+ const inheritedStyle = mergeStyle((_a = cols[colIndex]) === null || _a === void 0 ? void 0 : _a.s, (_b = rows[rowIndex]) === null || _b === void 0 ? void 0 : _b.s, cell === null || cell === void 0 ? void 0 : cell.s);
595
+ const rawStyle = resolveTableCellStyle(this.ws, rowIndex, colIndex, inheritedStyle);
596
+ let displayStyle = rawStyle;
597
+ if (this._defaultFont && (cell || rawStyle)) {
598
+ const explicitFont = (inheritedStyle === null || inheritedStyle === void 0 ? void 0 : inheritedStyle.font) || (['name', 'sz', 'bold', 'italic', 'color'].some(key => (inheritedStyle === null || inheritedStyle === void 0 ? void 0 : inheritedStyle[key]) !== undefined)
599
+ ? inheritedStyle : undefined);
600
+ displayStyle = {
601
+ ...rawStyle,
602
+ font: {
603
+ ...(explicitFont ? {
604
+ name: this._defaultFont.name,
605
+ sz: this._defaultFont.sz,
606
+ ...explicitFont
607
+ } : this._defaultFont),
608
+ ...rawStyle === null || rawStyle === void 0 ? void 0 : rawStyle.font
609
+ }
610
+ };
611
+ }
612
+ const className = alignToClassName(rawStyle === null || rawStyle === void 0 ? void 0 : rawStyle.alignment);
613
+ const style = getCellStyle(displayStyle);
614
+ const richText = parseCellRichText(cell);
615
+ if (!className && !style && !(richText === null || richText === void 0 ? void 0 : richText.length))
616
+ return undefined;
617
+ return {
618
+ ...(className ? { className } : {}),
619
+ style: style || {},
620
+ ...((richText === null || richText === void 0 ? void 0 : richText.length) ? { richText } : {})
621
+ };
622
+ }
623
+ getCell() {
624
+ const result = {};
577
625
  for (let rowIndex = this.startRow; rowIndex < this.endRow; rowIndex += 1) {
578
626
  for (let colIndex = 0; colIndex < this.totalCols; colIndex += 1) {
579
- const cell = this.getCellAt(rowIndex, colIndex);
580
- const inheritedStyle = mergeStyle((_a = cols[colIndex]) === null || _a === void 0 ? void 0 : _a.s, (_b = rows[rowIndex]) === null || _b === void 0 ? void 0 : _b.s, cell === null || cell === void 0 ? void 0 : cell.s);
581
- const rawStyle = resolveTableCellStyle(this.ws, rowIndex, colIndex, inheritedStyle);
582
- const className = alignToClassName(rawStyle === null || rawStyle === void 0 ? void 0 : rawStyle.alignment);
583
- const style = getCellStyle(rawStyle);
584
- const richText = parseCellRichText(cell);
585
- if (!className && !style && !(richText === null || richText === void 0 ? void 0 : richText.length)) {
586
- continue;
587
- }
588
- result[cellKey(rowIndex - this.startRow, colIndex)] = {
589
- ...(className ? { className } : {}),
590
- style: style || {},
591
- ...((richText === null || richText === void 0 ? void 0 : richText.length) ? { richText } : {})
592
- };
627
+ const metadata = this.getCellMetadata(rowIndex, colIndex, this.getCellAt(rowIndex, colIndex));
628
+ if (metadata)
629
+ result[cellKey(rowIndex - this.startRow, colIndex)] = metadata;
593
630
  }
594
631
  }
595
632
  return result;
@@ -618,7 +655,7 @@ class SheetJsModel {
618
655
  }
619
656
  }
620
657
  }
621
- if (heights.length === 1) {
658
+ if (heights.length === 1 && this.endRow - this.startRow === 1) {
622
659
  return heights[0];
623
660
  }
624
661
  return heights.length ? heights : rowHeight;
@@ -626,15 +663,26 @@ class SheetJsModel {
626
663
  getAllRowHeights() {
627
664
  const { '!rows': rows = [] } = this.ws;
628
665
  const heights = [];
629
- if (rows.length) {
630
- for (let absoluteRow = 0; absoluteRow < this.totalRows; absoluteRow += 1) {
631
- const height = getRowPixelHeight(rows[absoluteRow]);
632
- if (height !== undefined) {
633
- heights[absoluteRow] = height;
634
- }
666
+ let entries = 0, visited = 0;
667
+ for (const key in rows) {
668
+ if (!Object.prototype.hasOwnProperty.call(rows, key))
669
+ continue;
670
+ const absoluteRow = Number(key);
671
+ if (!Number.isSafeInteger(absoluteRow) || absoluteRow < 0 || absoluteRow >= this.totalRows)
672
+ continue;
673
+ if (visited >= ORDINARY_GRID_BUDGET.rows) {
674
+ throw Object.assign(new RangeError('Stored row layout exceeds the metadata budget; request a data-only window or source region.'), {
675
+ code: 'LAYOUT_BUDGET_EXCEEDED', limit: ORDINARY_GRID_BUDGET.rows,
676
+ });
677
+ }
678
+ visited++;
679
+ const height = getRowPixelHeight(rows[absoluteRow]);
680
+ if (height !== undefined) {
681
+ entries++;
682
+ heights[absoluteRow] = height;
635
683
  }
636
684
  }
637
- return heights.length ? heights : undefined;
685
+ return entries ? heights : undefined;
638
686
  }
639
687
  getAutoFitColumns() {
640
688
  var _a, _b;
@@ -727,15 +775,76 @@ class SheetJsModel {
727
775
  });
728
776
  }
729
777
  getStructure() {
778
+ var _a;
730
779
  return {
731
780
  merge: this.getAllMerge(),
732
781
  colWidths: this.getColWidths(),
733
782
  rowHeights: this.getAllRowHeights(),
783
+ rowSizing: (_a = this.ws['!fileViewerLayout']) === null || _a === void 0 ? void 0 : _a.rowSizing,
734
784
  columns: this.getColumns(),
735
785
  images: this.getImages(),
736
786
  charts: this.getCharts()
737
787
  };
738
788
  }
789
+ toRegionObject(region) {
790
+ var _a, _b;
791
+ assertSheetRegion(region);
792
+ const { '!cols': sourceCols = [], '!rows': sourceRows = [] } = this.ws;
793
+ const layout = this.ws['!fileViewerLayout'];
794
+ const defaults = this.defaults;
795
+ const fixedRows = new Set(((_a = layout === null || layout === void 0 ? void 0 : layout.rowSizing) === null || _a === void 0 ? void 0 : _a.fixedRows) || []);
796
+ const data = [], cell = {};
797
+ const rows = Array.from({ length: region.rowCount }, (_, localRow) => {
798
+ const sourceRow = region.startRow + localRow;
799
+ const values = [];
800
+ for (let localCol = 0; localCol < region.colCount; localCol++) {
801
+ const sourceCol = region.startCol + localCol, value = this.getCellAt(sourceRow, sourceCol);
802
+ values.push(this._cellImageKeys.has(cellKey(sourceRow, sourceCol)) ? '' : formatCellValue(value));
803
+ const metadata = this.getCellMetadata(sourceRow, sourceCol, value);
804
+ if (metadata)
805
+ cell[cellKey(localRow, localCol)] = metadata;
806
+ }
807
+ data.push(values);
808
+ const height = getRowPixelHeight(sourceRows[sourceRow]);
809
+ return { sourceRow, height: height !== null && height !== void 0 ? height : defaults.rowHeight,
810
+ fixed: height !== undefined || fixedRows.has(sourceRow), hidden: height === 0 };
811
+ });
812
+ const columns = Array.from({ length: region.colCount }, (_, localCol) => {
813
+ var _a;
814
+ const sourceCol = region.startCol + localCol, meta = sourceCols[sourceCol];
815
+ return { sourceCol, title: utils.encode_col(sourceCol), hidden: !!(meta === null || meta === void 0 ? void 0 : meta.hidden),
816
+ width: (_a = getColumnPixelWidth(meta, layout === null || layout === void 0 ? void 0 : layout.maximumDigitWidth)) !== null && _a !== void 0 ? _a : defaults.colWidth };
817
+ });
818
+ const merges = this.getAllMerge().filter(merge => regionIntersects(region, merge)).map(source => {
819
+ const anchor = this.getCellAt(source.row, source.col);
820
+ return { source, anchorValue: formatCellValue(anchor),
821
+ anchorMetadata: this.getCellMetadata(source.row, source.col, anchor),
822
+ contained: source.row >= region.startRow && source.col >= region.startCol
823
+ && source.row + source.rowspan <= region.startRow + region.rowCount
824
+ && source.col + source.colspan <= region.startCol + region.colCount };
825
+ });
826
+ const drawings = this.ws['!drawings'];
827
+ const sourceImages = (drawings === null || drawings === void 0 ? void 0 : drawings.images) || [], rowAnchors = readImageRowAnchors(drawings === null || drawings === void 0 ? void 0 : drawings.raw, sourceImages);
828
+ const sourceObjects = {
829
+ images: sourceImages.map(image => ({ id: image.id, src: image.dataURI, anchor: image.anchor,
830
+ contentType: image.contentType, rowAnchor: rowAnchors.get(image) })),
831
+ charts: this._charts,
832
+ cellImages: this._cellImages,
833
+ };
834
+ const sourceGeometry = {
835
+ rows: Object.keys(sourceRows).flatMap(key => {
836
+ const index = Number(key), size = getRowPixelHeight(sourceRows[index]);
837
+ return Number.isSafeInteger(index) && index >= 0 && size !== undefined ? [{ index, size }] : [];
838
+ }),
839
+ columns: Object.keys(sourceCols).flatMap(key => {
840
+ const index = Number(key), size = getColumnPixelWidth(sourceCols[index], layout === null || layout === void 0 ? void 0 : layout.maximumDigitWidth);
841
+ return Number.isSafeInteger(index) && index >= 0 && size !== undefined ? [{ index, size }] : [];
842
+ }),
843
+ };
844
+ return { coordinateSpace: 'region-local', region: { ...region }, defaults, data, cell,
845
+ rows, columns, merges, sourceObjects, sourceGeometry,
846
+ autoHeightDisabled: !!((_b = layout === null || layout === void 0 ? void 0 : layout.rowSizing) === null || _b === void 0 ? void 0 : _b.autoHeightDisabled) };
847
+ }
739
848
  toObject(options = {}) {
740
849
  const { defaults, data, cell, merge, rowHeights, meta } = this;
741
850
  return {
@@ -1,6 +1,7 @@
1
+ import { type XmlReadBudget } from './xmlBudget.js';
1
2
  import { type Document as XmlDocument, type Element as XmlElement, type Node as XmlNode } from '@xmldom/xmldom';
2
3
  import JSZip from 'jszip';
3
- import type { WorkBook } from 'styled-exceljs';
4
+ import { type WorkBook } from 'styled-exceljs';
4
5
  import type { SheetChartDefinition } from '../type.js';
5
6
  export type Relationship = {
6
7
  id: string;
@@ -11,7 +12,7 @@ export declare const localName: (node: XmlNode) => string;
11
12
  export declare const childElements: (node: XmlNode | null | undefined) => XmlElement[];
12
13
  export declare const elementsByLocal: (node: XmlNode | null | undefined, name: string) => XmlElement[];
13
14
  export declare const relationshipId: (element: XmlElement | undefined) => string;
14
- export declare const loadXml: (zip: JSZip, path: string) => Promise<XmlDocument | null>;
15
- export declare const loadRelationships: (zip: JSZip, sourcePart: string) => Promise<Relationship[]>;
15
+ export declare const loadXml: (zip: JSZip, path: string, budget?: XmlReadBudget) => Promise<XmlDocument | null>;
16
+ export declare const loadRelationships: (zip: JSZip, sourcePart: string, readPart?: (path: string) => Promise<XmlDocument | null>) => Promise<Relationship[]>;
16
17
  export declare const relationById: (relationships: Relationship[], id: string) => Relationship | undefined;
17
18
  export declare const parseSpreadsheetCharts: (data: ArrayBuffer, workbook?: WorkBook | null) => Promise<Record<string, SheetChartDefinition[]>>;