@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.
- package/README.en.md +14 -0
- package/README.md +14 -0
- package/README.zh-CN.md +14 -0
- package/dist/spreadsheet/autoRowHeight.d.ts +16 -0
- package/dist/spreadsheet/autoRowHeight.js +208 -0
- package/dist/spreadsheet/comments.d.ts +40 -0
- package/dist/spreadsheet/comments.js +388 -0
- package/dist/spreadsheet/drawingAutoHeight.d.ts +7 -0
- package/dist/spreadsheet/drawingAutoHeight.js +51 -0
- package/dist/spreadsheet/sourceRegion.d.ts +37 -0
- package/dist/spreadsheet/sourceRegion.js +54 -0
- package/dist/spreadsheet/state.d.ts +7 -1
- package/dist/spreadsheet/state.js +6 -0
- package/dist/spreadsheet/view.d.ts +9 -4
- package/dist/spreadsheet/view.js +98 -27
- package/dist/spreadsheet/worker/sheetjs/SheetJsModel.d.ts +61 -2
- package/dist/spreadsheet/worker/sheetjs/SheetJsModel.js +134 -28
- package/dist/spreadsheet/worker/sheetjs/chartParser.d.ts +3 -2
- package/dist/spreadsheet/worker/sheetjs/chartParser.js +13 -5
- package/dist/spreadsheet/worker/sheetjs/commentParser.d.ts +7 -0
- package/dist/spreadsheet/worker/sheetjs/commentParser.js +232 -0
- package/dist/spreadsheet/worker/sheetjs/drawingRowAnchor.d.ts +4 -0
- package/dist/spreadsheet/worker/sheetjs/drawingRowAnchor.js +90 -0
- package/dist/spreadsheet/worker/sheetjs/parser.d.ts +40 -3
- package/dist/spreadsheet/worker/sheetjs/parser.js +452 -54
- package/dist/spreadsheet/worker/sheetjs/richDataParser.js +5 -2
- package/dist/spreadsheet/worker/sheetjs/rowSizing.d.ts +10 -0
- package/dist/spreadsheet/worker/sheetjs/rowSizing.js +156 -0
- package/dist/spreadsheet/worker/sheetjs/sheetLayout.d.ts +2 -0
- package/dist/spreadsheet/worker/sheetjs/sourceAnchor.d.ts +10 -0
- package/dist/spreadsheet/worker/sheetjs/sourceAnchor.js +286 -0
- package/dist/spreadsheet/worker/sheetjs/textEncoding.d.ts +1 -1
- package/dist/spreadsheet/worker/sheetjs/textEncoding.js +1 -1
- package/dist/spreadsheet/worker/sheetjs/workbookFont.d.ts +4 -0
- package/dist/spreadsheet/worker/sheetjs/workbookFont.js +15 -0
- package/dist/spreadsheet/worker/sheetjs/xmlBudget.d.ts +11 -0
- package/dist/spreadsheet/worker/sheetjs/xmlBudget.js +39 -0
- package/dist/spreadsheet/worker/type.d.ts +145 -0
- package/dist/spreadsheet.js +150 -39
- package/dist/worker/sheet.worker.js +49 -65
- package/package.json +22 -2
package/dist/spreadsheet/view.js
CHANGED
|
@@ -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
|
|
264
|
-
|
|
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
|
-
|
|
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
|
|
937
|
-
const
|
|
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
|
|
946
|
-
|
|
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,
|
|
953
|
-
const mirror = !hasRenderableValue(
|
|
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
|
-
|
|
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 :
|
|
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:
|
|
991
|
-
MAX_HEIGHT:
|
|
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
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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,6 +535,7 @@ 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,
|
|
@@ -570,26 +585,45 @@ class SheetJsModel {
|
|
|
570
585
|
}
|
|
571
586
|
return fixMatrix(result, this.totalCols);
|
|
572
587
|
}
|
|
573
|
-
|
|
588
|
+
getCellMetadata(rowIndex, colIndex, cell) {
|
|
574
589
|
var _a, _b;
|
|
575
|
-
const result = {};
|
|
576
590
|
const { '!cols': cols = [], '!rows': rows = [] } = this.ws;
|
|
591
|
+
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);
|
|
592
|
+
const rawStyle = resolveTableCellStyle(this.ws, rowIndex, colIndex, inheritedStyle);
|
|
593
|
+
let displayStyle = rawStyle;
|
|
594
|
+
if (this._defaultFont && (cell || rawStyle)) {
|
|
595
|
+
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)
|
|
596
|
+
? inheritedStyle : undefined);
|
|
597
|
+
displayStyle = {
|
|
598
|
+
...rawStyle,
|
|
599
|
+
font: {
|
|
600
|
+
...(explicitFont ? {
|
|
601
|
+
name: this._defaultFont.name,
|
|
602
|
+
sz: this._defaultFont.sz,
|
|
603
|
+
...explicitFont
|
|
604
|
+
} : this._defaultFont),
|
|
605
|
+
...rawStyle === null || rawStyle === void 0 ? void 0 : rawStyle.font
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
const className = alignToClassName(rawStyle === null || rawStyle === void 0 ? void 0 : rawStyle.alignment);
|
|
610
|
+
const style = getCellStyle(displayStyle);
|
|
611
|
+
const richText = parseCellRichText(cell);
|
|
612
|
+
if (!className && !style && !(richText === null || richText === void 0 ? void 0 : richText.length))
|
|
613
|
+
return undefined;
|
|
614
|
+
return {
|
|
615
|
+
...(className ? { className } : {}),
|
|
616
|
+
style: style || {},
|
|
617
|
+
...((richText === null || richText === void 0 ? void 0 : richText.length) ? { richText } : {})
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
getCell() {
|
|
621
|
+
const result = {};
|
|
577
622
|
for (let rowIndex = this.startRow; rowIndex < this.endRow; rowIndex += 1) {
|
|
578
623
|
for (let colIndex = 0; colIndex < this.totalCols; colIndex += 1) {
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
|
|
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
|
-
};
|
|
624
|
+
const metadata = this.getCellMetadata(rowIndex, colIndex, this.getCellAt(rowIndex, colIndex));
|
|
625
|
+
if (metadata)
|
|
626
|
+
result[cellKey(rowIndex - this.startRow, colIndex)] = metadata;
|
|
593
627
|
}
|
|
594
628
|
}
|
|
595
629
|
return result;
|
|
@@ -618,7 +652,7 @@ class SheetJsModel {
|
|
|
618
652
|
}
|
|
619
653
|
}
|
|
620
654
|
}
|
|
621
|
-
if (heights.length === 1) {
|
|
655
|
+
if (heights.length === 1 && this.endRow - this.startRow === 1) {
|
|
622
656
|
return heights[0];
|
|
623
657
|
}
|
|
624
658
|
return heights.length ? heights : rowHeight;
|
|
@@ -626,15 +660,26 @@ class SheetJsModel {
|
|
|
626
660
|
getAllRowHeights() {
|
|
627
661
|
const { '!rows': rows = [] } = this.ws;
|
|
628
662
|
const heights = [];
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
663
|
+
let entries = 0, visited = 0;
|
|
664
|
+
for (const key in rows) {
|
|
665
|
+
if (!Object.prototype.hasOwnProperty.call(rows, key))
|
|
666
|
+
continue;
|
|
667
|
+
const absoluteRow = Number(key);
|
|
668
|
+
if (!Number.isSafeInteger(absoluteRow) || absoluteRow < 0 || absoluteRow >= this.totalRows)
|
|
669
|
+
continue;
|
|
670
|
+
if (visited >= ORDINARY_GRID_BUDGET.rows) {
|
|
671
|
+
throw Object.assign(new RangeError('Stored row layout exceeds the metadata budget; request a data-only window or source region.'), {
|
|
672
|
+
code: 'LAYOUT_BUDGET_EXCEEDED', limit: ORDINARY_GRID_BUDGET.rows,
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
visited++;
|
|
676
|
+
const height = getRowPixelHeight(rows[absoluteRow]);
|
|
677
|
+
if (height !== undefined) {
|
|
678
|
+
entries++;
|
|
679
|
+
heights[absoluteRow] = height;
|
|
635
680
|
}
|
|
636
681
|
}
|
|
637
|
-
return
|
|
682
|
+
return entries ? heights : undefined;
|
|
638
683
|
}
|
|
639
684
|
getAutoFitColumns() {
|
|
640
685
|
var _a, _b;
|
|
@@ -727,15 +772,76 @@ class SheetJsModel {
|
|
|
727
772
|
});
|
|
728
773
|
}
|
|
729
774
|
getStructure() {
|
|
775
|
+
var _a;
|
|
730
776
|
return {
|
|
731
777
|
merge: this.getAllMerge(),
|
|
732
778
|
colWidths: this.getColWidths(),
|
|
733
779
|
rowHeights: this.getAllRowHeights(),
|
|
780
|
+
rowSizing: (_a = this.ws['!fileViewerLayout']) === null || _a === void 0 ? void 0 : _a.rowSizing,
|
|
734
781
|
columns: this.getColumns(),
|
|
735
782
|
images: this.getImages(),
|
|
736
783
|
charts: this.getCharts()
|
|
737
784
|
};
|
|
738
785
|
}
|
|
786
|
+
toRegionObject(region) {
|
|
787
|
+
var _a, _b;
|
|
788
|
+
assertSheetRegion(region);
|
|
789
|
+
const { '!cols': sourceCols = [], '!rows': sourceRows = [] } = this.ws;
|
|
790
|
+
const layout = this.ws['!fileViewerLayout'];
|
|
791
|
+
const defaults = this.defaults;
|
|
792
|
+
const fixedRows = new Set(((_a = layout === null || layout === void 0 ? void 0 : layout.rowSizing) === null || _a === void 0 ? void 0 : _a.fixedRows) || []);
|
|
793
|
+
const data = [], cell = {};
|
|
794
|
+
const rows = Array.from({ length: region.rowCount }, (_, localRow) => {
|
|
795
|
+
const sourceRow = region.startRow + localRow;
|
|
796
|
+
const values = [];
|
|
797
|
+
for (let localCol = 0; localCol < region.colCount; localCol++) {
|
|
798
|
+
const sourceCol = region.startCol + localCol, value = this.getCellAt(sourceRow, sourceCol);
|
|
799
|
+
values.push(this._cellImageKeys.has(cellKey(sourceRow, sourceCol)) ? '' : formatCellValue(value));
|
|
800
|
+
const metadata = this.getCellMetadata(sourceRow, sourceCol, value);
|
|
801
|
+
if (metadata)
|
|
802
|
+
cell[cellKey(localRow, localCol)] = metadata;
|
|
803
|
+
}
|
|
804
|
+
data.push(values);
|
|
805
|
+
const height = getRowPixelHeight(sourceRows[sourceRow]);
|
|
806
|
+
return { sourceRow, height: height !== null && height !== void 0 ? height : defaults.rowHeight,
|
|
807
|
+
fixed: height !== undefined || fixedRows.has(sourceRow), hidden: height === 0 };
|
|
808
|
+
});
|
|
809
|
+
const columns = Array.from({ length: region.colCount }, (_, localCol) => {
|
|
810
|
+
var _a;
|
|
811
|
+
const sourceCol = region.startCol + localCol, meta = sourceCols[sourceCol];
|
|
812
|
+
return { sourceCol, title: utils.encode_col(sourceCol), hidden: !!(meta === null || meta === void 0 ? void 0 : meta.hidden),
|
|
813
|
+
width: (_a = getColumnPixelWidth(meta, layout === null || layout === void 0 ? void 0 : layout.maximumDigitWidth)) !== null && _a !== void 0 ? _a : defaults.colWidth };
|
|
814
|
+
});
|
|
815
|
+
const merges = this.getAllMerge().filter(merge => regionIntersects(region, merge)).map(source => {
|
|
816
|
+
const anchor = this.getCellAt(source.row, source.col);
|
|
817
|
+
return { source, anchorValue: formatCellValue(anchor),
|
|
818
|
+
anchorMetadata: this.getCellMetadata(source.row, source.col, anchor),
|
|
819
|
+
contained: source.row >= region.startRow && source.col >= region.startCol
|
|
820
|
+
&& source.row + source.rowspan <= region.startRow + region.rowCount
|
|
821
|
+
&& source.col + source.colspan <= region.startCol + region.colCount };
|
|
822
|
+
});
|
|
823
|
+
const drawings = this.ws['!drawings'];
|
|
824
|
+
const sourceImages = (drawings === null || drawings === void 0 ? void 0 : drawings.images) || [], rowAnchors = readImageRowAnchors(drawings === null || drawings === void 0 ? void 0 : drawings.raw, sourceImages);
|
|
825
|
+
const sourceObjects = {
|
|
826
|
+
images: sourceImages.map(image => ({ id: image.id, src: image.dataURI, anchor: image.anchor,
|
|
827
|
+
contentType: image.contentType, rowAnchor: rowAnchors.get(image) })),
|
|
828
|
+
charts: this._charts,
|
|
829
|
+
cellImages: this._cellImages,
|
|
830
|
+
};
|
|
831
|
+
const sourceGeometry = {
|
|
832
|
+
rows: Object.keys(sourceRows).flatMap(key => {
|
|
833
|
+
const index = Number(key), size = getRowPixelHeight(sourceRows[index]);
|
|
834
|
+
return Number.isSafeInteger(index) && index >= 0 && size !== undefined ? [{ index, size }] : [];
|
|
835
|
+
}),
|
|
836
|
+
columns: Object.keys(sourceCols).flatMap(key => {
|
|
837
|
+
const index = Number(key), size = getColumnPixelWidth(sourceCols[index], layout === null || layout === void 0 ? void 0 : layout.maximumDigitWidth);
|
|
838
|
+
return Number.isSafeInteger(index) && index >= 0 && size !== undefined ? [{ index, size }] : [];
|
|
839
|
+
}),
|
|
840
|
+
};
|
|
841
|
+
return { coordinateSpace: 'region-local', region: { ...region }, defaults, data, cell,
|
|
842
|
+
rows, columns, merges, sourceObjects, sourceGeometry,
|
|
843
|
+
autoHeightDisabled: !!((_b = layout === null || layout === void 0 ? void 0 : layout.rowSizing) === null || _b === void 0 ? void 0 : _b.autoHeightDisabled) };
|
|
844
|
+
}
|
|
739
845
|
toObject(options = {}) {
|
|
740
846
|
const { defaults, data, cell, merge, rowHeights, meta } = this;
|
|
741
847
|
return {
|
|
@@ -1,3 +1,4 @@
|
|
|
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
4
|
import type { WorkBook } from 'styled-exceljs';
|
|
@@ -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[]>>;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { readSourceAnchor } from './sourceAnchor.js';
|
|
2
|
+
import { createDrawingRowAnchor } from './drawingRowAnchor.js';
|
|
3
|
+
import { readStoredRowSizing } from './rowSizing.js';
|
|
4
|
+
import { readBoundedZipText } from './xmlBudget.js';
|
|
1
5
|
import { DOMParser } from '@xmldom/xmldom';
|
|
2
6
|
import JSZip from 'jszip';
|
|
3
7
|
import { readStoredSheetLayout, readWorkbookDigitWidth } from './sheetLayout.js';
|
|
@@ -118,15 +122,15 @@ const relationshipPartPath = (sourcePart) => {
|
|
|
118
122
|
const parseXml = (xml) => {
|
|
119
123
|
return new DOMParser().parseFromString(xml.replace(/^[\uFEFF\s]+/, ''), 'application/xml');
|
|
120
124
|
};
|
|
121
|
-
export const loadXml = async (zip, path) => {
|
|
125
|
+
export const loadXml = async (zip, path, budget) => {
|
|
122
126
|
const file = zip.file(path);
|
|
123
127
|
if (!file) {
|
|
124
128
|
return null;
|
|
125
129
|
}
|
|
126
|
-
return parseXml(await file.async('text'));
|
|
130
|
+
return parseXml(budget ? await readBoundedZipText(file, budget) : await file.async('text'));
|
|
127
131
|
};
|
|
128
|
-
export const loadRelationships = async (zip, sourcePart) => {
|
|
129
|
-
const document = await
|
|
132
|
+
export const loadRelationships = async (zip, sourcePart, readPart = (path) => loadXml(zip, path)) => {
|
|
133
|
+
const document = await readPart(relationshipPartPath(sourcePart));
|
|
130
134
|
if (!document) {
|
|
131
135
|
return [];
|
|
132
136
|
}
|
|
@@ -445,6 +449,7 @@ const parseDrawingCharts = async (zip, drawingPart, workbook) => {
|
|
|
445
449
|
if (!chart || !chart.series.length || chart.series.every((series) => !series.values.length)) {
|
|
446
450
|
return null;
|
|
447
451
|
}
|
|
452
|
+
const sourceAnchor = readSourceAnchor(anchor, chartReference, 'chart');
|
|
448
453
|
const from = parseMarker(firstChildByLocal(anchor, 'from')) || {
|
|
449
454
|
row: 0,
|
|
450
455
|
col: 0,
|
|
@@ -456,6 +461,8 @@ const parseDrawingCharts = async (zip, drawingPart, workbook) => {
|
|
|
456
461
|
const name = (_a = firstByLocal(anchor, 'cNvPr')) === null || _a === void 0 ? void 0 : _a.getAttribute('name');
|
|
457
462
|
return {
|
|
458
463
|
...chart,
|
|
464
|
+
sourceAnchor,
|
|
465
|
+
rowAnchor: createDrawingRowAnchor(localName(anchor), anchor.getAttribute('editAs'), from, to),
|
|
459
466
|
id: name || chartRelationship.target || `chart-${index + 1}`,
|
|
460
467
|
from,
|
|
461
468
|
to,
|
|
@@ -493,7 +500,8 @@ export const parseSpreadsheetCharts = async (data, workbook) => {
|
|
|
493
500
|
worksheet['!fileViewerLayout'] = {};
|
|
494
501
|
worksheet['!fileViewerLayout'] = {
|
|
495
502
|
...await readStoredSheetLayout(zip, worksheetRelationship.target),
|
|
496
|
-
maximumDigitWidth
|
|
503
|
+
maximumDigitWidth,
|
|
504
|
+
rowSizing: await readStoredRowSizing(zip, worksheetRelationship.target)
|
|
497
505
|
};
|
|
498
506
|
}
|
|
499
507
|
const worksheetRelationships = await loadRelationships(zip, worksheetRelationship.target);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type WorkBook } from 'styled-exceljs';
|
|
2
|
+
import type { SheetComment } from '../type.js';
|
|
3
|
+
export declare const readWorkbookNotes: (workbook: WorkBook) => Record<string, SheetComment[]>;
|
|
4
|
+
export declare const parseSpreadsheetComments: (data: ArrayBuffer, workbook: WorkBook) => Promise<{
|
|
5
|
+
comments: Record<string, SheetComment[]>;
|
|
6
|
+
hasError: boolean;
|
|
7
|
+
}>;
|