@file-viewer/renderer-spreadsheet 3.2.2 → 3.3.1
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 +13 -3
- package/README.md +30 -20
- package/README.zh-CN.md +73 -0
- package/dist/spreadsheet/chartRenderer.js +5 -0
- package/dist/spreadsheet/chartSampling.d.ts +4 -0
- package/dist/spreadsheet/chartSampling.js +6 -0
- package/dist/spreadsheet/rangeNavigation.d.ts +2 -0
- package/dist/spreadsheet/rangeNavigation.js +4 -0
- package/dist/spreadsheet/state.d.ts +1 -0
- package/dist/spreadsheet/state.js +2 -0
- package/dist/spreadsheet/view.js +14 -2
- package/dist/spreadsheet/viewport.d.ts +1 -0
- package/dist/spreadsheet/viewport.js +4 -2
- package/dist/spreadsheet/worker/sheetjs/SheetJsModel.js +39 -15
- package/dist/spreadsheet/worker/sheetjs/chartParser.js +30 -0
- package/dist/spreadsheet/worker/sheetjs/color.js +10 -8
- package/dist/spreadsheet/worker/sheetjs/formulaValues.d.ts +5 -0
- package/dist/spreadsheet/worker/sheetjs/formulaValues.js +421 -0
- package/dist/spreadsheet/worker/sheetjs/parser.d.ts +1 -0
- package/dist/spreadsheet/worker/sheetjs/parser.js +89 -17
- package/dist/spreadsheet/worker/sheetjs/richDataParser.js +2 -0
- package/dist/spreadsheet/worker/sheetjs/richText.js +2 -1
- package/dist/spreadsheet/worker/sheetjs/sheetLayout.d.ts +13 -0
- package/dist/spreadsheet/worker/sheetjs/sheetLayout.js +68 -0
- package/dist/spreadsheet/worker/sheetjs/textEncoding.js +7 -0
- package/dist/spreadsheet/worker/type.d.ts +3 -0
- package/dist/spreadsheet.js +24 -0
- package/dist/worker/sheet.worker.js +48 -48
- package/dist/worker.THIRD_PARTY_LICENSES.txt +1 -1
- package/package.json +7 -2
|
@@ -3,6 +3,7 @@ import SheetJsModel, { formatCellValue } from './SheetJsModel.js';
|
|
|
3
3
|
import { parseSpreadsheetCharts } from './chartParser.js';
|
|
4
4
|
import { prepareSpreadsheetReadInput, } from './textEncoding.js';
|
|
5
5
|
import { parseSpreadsheetCellImages } from './richDataParser.js';
|
|
6
|
+
import { recoverUncachedFormulaValues } from './formulaValues.js';
|
|
6
7
|
const readOptions = {
|
|
7
8
|
type: 'array',
|
|
8
9
|
dense: true,
|
|
@@ -11,6 +12,8 @@ const readOptions = {
|
|
|
11
12
|
browserPixels: true,
|
|
12
13
|
drawings: true,
|
|
13
14
|
};
|
|
15
|
+
// HTML/XML 文件必须传入 type: 'string' 保持原有的 HTML 单元格解析结果
|
|
16
|
+
const prefersSheetJsTextSniff = (text) => /^[\s\uFEFF]*</.test(text);
|
|
14
17
|
const isMergeValidationError = (error) => (error instanceof Error
|
|
15
18
|
&& typeof error.code === 'string'
|
|
16
19
|
&& /^E_MERGE_/.test(error.code));
|
|
@@ -76,8 +79,15 @@ const sanitizeToleratedMerges = (workbook) => {
|
|
|
76
79
|
});
|
|
77
80
|
}
|
|
78
81
|
};
|
|
79
|
-
const readPreparedWorkbook = (input, validateMerges) => (
|
|
80
|
-
|
|
82
|
+
const readPreparedWorkbook = (input, validateMerges) => (
|
|
83
|
+
/***
|
|
84
|
+
* 对于二进制格式,直接透传 ArrayBuffer
|
|
85
|
+
* 对于文本格式用 prefersSheetJsTextSniff 选 type:
|
|
86
|
+
* - 普通文本 -> 'binary',绕过 SheetJS 内部 utf8write 的大数组崩溃
|
|
87
|
+
* - HTML/XML -> 'string',保持原有的 HTML 单元格解析结果
|
|
88
|
+
*/
|
|
89
|
+
input.kind === 'text'
|
|
90
|
+
? read(input.data, { ...readOptions, type: prefersSheetJsTextSniff(input.data) ? 'string' : 'binary', validateMerges })
|
|
81
91
|
: read(input.data, { ...readOptions, validateMerges }));
|
|
82
92
|
const readWorkbookWithMergeRecovery = (input) => {
|
|
83
93
|
try {
|
|
@@ -147,10 +157,60 @@ const EMPTY_RANGE_COLUMN_LIMIT = 256;
|
|
|
147
157
|
const RANGE_ROW_SLACK = 256;
|
|
148
158
|
const RANGE_COLUMN_SLACK = 64;
|
|
149
159
|
const RANGE_GROWTH_FACTOR = 4;
|
|
160
|
+
/** Drop sparse far outliers once the gap dwarfs the dense cluster near A1. */
|
|
161
|
+
const CONTENT_GAP_ROW_MULTIPLIER = 4;
|
|
162
|
+
const CONTENT_GAP_COL_MULTIPLIER = 4;
|
|
163
|
+
/**
|
|
164
|
+
* Keep the dense cell cluster that starts nearest A1.
|
|
165
|
+
* Nearby style-only stubs still count (needed for formatted empty tables, see #175),
|
|
166
|
+
* but a huge gap before far ghost cells near Excel max is treated as an outlier (#405).
|
|
167
|
+
*/
|
|
168
|
+
const compactSparseExtent = (indices, slack, gapMultiplier, contentExtent) => {
|
|
169
|
+
if (indices.length === 0)
|
|
170
|
+
return 0;
|
|
171
|
+
const sorted = [...new Set(indices)].sort((a, b) => a - b);
|
|
172
|
+
const originThreshold = Math.max(slack * gapMultiplier, RANGE_GROWTH_FACTOR);
|
|
173
|
+
// A workbook whose only sheet entries sit absurdly far from A1 has no usable near cluster.
|
|
174
|
+
if (!contentExtent && sorted[0] > originThreshold)
|
|
175
|
+
return 0;
|
|
176
|
+
// All meaningful cells are mandatory, even across gaps or far from A1.
|
|
177
|
+
// Only blank formatting beyond the last content cell may be compacted.
|
|
178
|
+
let end = Math.max(sorted[0], contentExtent - 1);
|
|
179
|
+
for (let i = 1; i < sorted.length; i += 1) {
|
|
180
|
+
const current = sorted[i];
|
|
181
|
+
if (current <= end)
|
|
182
|
+
continue;
|
|
183
|
+
const currentExtent = end + 1;
|
|
184
|
+
const gap = current - end;
|
|
185
|
+
const threshold = Math.max(slack * gapMultiplier, currentExtent * RANGE_GROWTH_FACTOR);
|
|
186
|
+
if (gap > threshold)
|
|
187
|
+
break;
|
|
188
|
+
end = current;
|
|
189
|
+
}
|
|
190
|
+
return end + 1;
|
|
191
|
+
};
|
|
150
192
|
const getCellBounds = (worksheet) => {
|
|
151
193
|
const bounds = { rowCount: 0, colCount: 0 };
|
|
152
194
|
if (!worksheet)
|
|
153
195
|
return bounds;
|
|
196
|
+
const rowIndices = [];
|
|
197
|
+
const colIndices = [];
|
|
198
|
+
let contentRows = 0;
|
|
199
|
+
let contentCols = 0;
|
|
200
|
+
const observe = (row, col, value) => {
|
|
201
|
+
rowIndices.push(row);
|
|
202
|
+
colIndices.push(col);
|
|
203
|
+
const cell = value;
|
|
204
|
+
// Do not test truthiness: zero, false and an explicitly stored empty string
|
|
205
|
+
// are content too. Uncached formulas have no v but must remain reachable.
|
|
206
|
+
const meaningful = typeof value !== 'object' || cell.v != null || cell.f != null
|
|
207
|
+
|| cell.F != null || !!cell.w || !!cell.r || !!cell.h || !!cell.l
|
|
208
|
+
|| (Array.isArray(cell.c) && cell.c.length > 0);
|
|
209
|
+
if (meaningful) {
|
|
210
|
+
contentRows = Math.max(contentRows, row + 1);
|
|
211
|
+
contentCols = Math.max(contentCols, col + 1);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
154
214
|
const denseRows = Array.isArray(worksheet)
|
|
155
215
|
? worksheet
|
|
156
216
|
: worksheet['!data'];
|
|
@@ -164,23 +224,25 @@ const getCellBounds = (worksheet) => {
|
|
|
164
224
|
const colIndex = Number(colKey);
|
|
165
225
|
if (!Number.isInteger(colIndex) || colIndex < 0 || row[colIndex] == null)
|
|
166
226
|
continue;
|
|
167
|
-
|
|
168
|
-
bounds.colCount = Math.max(bounds.colCount, colIndex + 1);
|
|
227
|
+
observe(rowIndex, colIndex, row[colIndex]);
|
|
169
228
|
}
|
|
170
229
|
}
|
|
171
|
-
return bounds;
|
|
172
230
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
231
|
+
else {
|
|
232
|
+
for (const key of Object.keys(worksheet)) {
|
|
233
|
+
if (key.startsWith('!') || !/^[A-Z]+[1-9][0-9]*$/i.test(key) || worksheet[key] == null)
|
|
234
|
+
continue;
|
|
235
|
+
try {
|
|
236
|
+
const cell = utils.decode_cell(key);
|
|
237
|
+
observe(cell.r, cell.c, worksheet[key]);
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
// Ignore non-cell extension keys exposed by third-party workbook producers.
|
|
241
|
+
}
|
|
182
242
|
}
|
|
183
243
|
}
|
|
244
|
+
bounds.rowCount = compactSparseExtent(rowIndices, RANGE_ROW_SLACK, CONTENT_GAP_ROW_MULTIPLIER, contentRows);
|
|
245
|
+
bounds.colCount = compactSparseExtent(colIndices, RANGE_COLUMN_SLACK, CONTENT_GAP_COL_MULTIPLIER, contentCols);
|
|
184
246
|
return bounds;
|
|
185
247
|
};
|
|
186
248
|
const getMergeBounds = (worksheet) => {
|
|
@@ -214,6 +276,7 @@ export const getWorksheetDisplayBounds = (worksheet, charts) => {
|
|
|
214
276
|
declaredColCount = range.e.c + 1;
|
|
215
277
|
}
|
|
216
278
|
catch {
|
|
279
|
+
// Invalid producer dimensions must not block content-based recovery.
|
|
217
280
|
}
|
|
218
281
|
}
|
|
219
282
|
const cellBounds = getCellBounds(worksheet);
|
|
@@ -222,8 +285,14 @@ export const getWorksheetDisplayBounds = (worksheet, charts) => {
|
|
|
222
285
|
const chartBounds = getChartBounds(charts);
|
|
223
286
|
const observedRowCount = Math.max(cellBounds.rowCount, mergeBounds.rowCount, drawingBounds.rowCount, chartBounds.rowCount);
|
|
224
287
|
const observedColCount = Math.max(cellBounds.colCount, mergeBounds.colCount, drawingBounds.colCount, chartBounds.colCount);
|
|
225
|
-
const
|
|
226
|
-
const
|
|
288
|
+
const reconciledRowCount = reconcileDeclaredRange(declaredRowCount, observedRowCount, RANGE_ROW_SLACK, EMPTY_RANGE_ROW_LIMIT);
|
|
289
|
+
const reconciledColCount = reconcileDeclaredRange(declaredColCount, observedColCount, RANGE_COLUMN_SLACK, EMPTY_RANGE_COLUMN_LIMIT);
|
|
290
|
+
const rowCount = reconciledRowCount;
|
|
291
|
+
const colCount = reconciledColCount;
|
|
292
|
+
const trimmed = (rowCount < declaredRowCount
|
|
293
|
+
|| colCount < declaredColCount
|
|
294
|
+
|| rowCount < reconciledRowCount
|
|
295
|
+
|| colCount < reconciledColCount);
|
|
227
296
|
return {
|
|
228
297
|
rowCount,
|
|
229
298
|
colCount,
|
|
@@ -231,7 +300,7 @@ export const getWorksheetDisplayBounds = (worksheet, charts) => {
|
|
|
231
300
|
declaredColCount,
|
|
232
301
|
observedRowCount,
|
|
233
302
|
observedColCount,
|
|
234
|
-
trimmed
|
|
303
|
+
trimmed,
|
|
235
304
|
};
|
|
236
305
|
};
|
|
237
306
|
const parseSheets = (context, includeEmptySheets = false) => {
|
|
@@ -268,6 +337,7 @@ export const parseSpreadsheetWorkbook = async (context, data, source = {}) => {
|
|
|
268
337
|
try {
|
|
269
338
|
const input = prepareSpreadsheetReadInput(data, source);
|
|
270
339
|
context.workbook = readWorkbookWithMergeRecovery(input);
|
|
340
|
+
recoverUncachedFormulaValues(context.workbook);
|
|
271
341
|
const signature = data.byteLength >= 2 ? new DataView(data).getUint16(0, false) : 0;
|
|
272
342
|
if (signature === 0x504b) {
|
|
273
343
|
const [charts, cellImages] = await Promise.all([
|
|
@@ -315,6 +385,8 @@ export const parseSpreadsheetSheet = (context, payload = {}) => {
|
|
|
315
385
|
charts: context.charts[sheetName],
|
|
316
386
|
cellImages: context.cellImages[sheetName],
|
|
317
387
|
});
|
|
388
|
+
// Keep the first response backward-compatible; later virtual windows only need rows and cells.
|
|
389
|
+
// Avoid recalculating auto-fit column widths for every 500-row request.
|
|
318
390
|
const windowData = sheetModel.toObject({ includeLayout: startRow === 0 });
|
|
319
391
|
const structure = startRow === 0 ? sheetModel.structure : undefined;
|
|
320
392
|
return [{
|
|
@@ -135,6 +135,8 @@ const parseWorksheetCellMetadata = (xml) => {
|
|
|
135
135
|
if (!ref || !metadataText || !Number.isInteger(metadataValue) || metadataValue < 0) {
|
|
136
136
|
continue;
|
|
137
137
|
}
|
|
138
|
+
// Cell metadata indexes are one-based in OOXML. Accept zero as a
|
|
139
|
+
// producer-tolerance fallback without shifting it below zero.
|
|
138
140
|
result.push({ ref, metadataIndex: metadataValue > 0 ? metadataValue - 1 : 0 });
|
|
139
141
|
}
|
|
140
142
|
return result;
|
|
@@ -49,7 +49,8 @@ const parseColor = (element) => {
|
|
|
49
49
|
};
|
|
50
50
|
const parseFontSize = (element) => {
|
|
51
51
|
const value = Number(element === null || element === void 0 ? void 0 : element.getAttribute('val'));
|
|
52
|
-
|
|
52
|
+
// 富文本的 <sz> 同样使用 pt,段字号与普通单元格都以 CSS px 传给视图。
|
|
53
|
+
return Number.isFinite(value) && value > 0 ? value * 96 / 72 : undefined;
|
|
53
54
|
};
|
|
54
55
|
const normalizeSymbolText = (text, fontFamily) => {
|
|
55
56
|
if ((fontFamily === null || fontFamily === void 0 ? void 0 : fontFamily.trim().toLowerCase()) !== 'wingdings 2') {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type JSZip from 'jszip';
|
|
2
|
+
import type { WorkBook } from 'styled-exceljs';
|
|
3
|
+
export interface StoredSheetLayout {
|
|
4
|
+
columnWidth?: number;
|
|
5
|
+
rowHeightPt?: number;
|
|
6
|
+
maximumDigitWidth?: number;
|
|
7
|
+
}
|
|
8
|
+
/** OOXML column units refer to the workbook's Normal style, which need not
|
|
9
|
+
* use fonts[0]. Preserve the established fallback for unmeasured fonts. */
|
|
10
|
+
export declare const readWorkbookDigitWidth: (workbook?: WorkBook | null) => number;
|
|
11
|
+
/** Read only the worksheet header; never materialize a large sheet's cells a
|
|
12
|
+
* second time merely to recover sheetFormatPr. */
|
|
13
|
+
export declare const readStoredSheetLayout: (zip: JSZip, part: string) => Promise<StoredSheetLayout>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DOMParser } from '@xmldom/xmldom';
|
|
2
|
+
/** OOXML column units refer to the workbook's Normal style, which need not
|
|
3
|
+
* use fonts[0]. Preserve the established fallback for unmeasured fonts. */
|
|
4
|
+
export const readWorkbookDigitWidth = (workbook) => {
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
6
|
+
const styles = workbook === null || workbook === void 0 ? void 0 : workbook.Styles;
|
|
7
|
+
const normal = (_b = (_a = styles === null || styles === void 0 ? void 0 : styles.CellStyles) === null || _a === void 0 ? void 0 : _a.find(style => style.builtinId === 0)) !== null && _b !== void 0 ? _b : (_c = styles === null || styles === void 0 ? void 0 : styles.CellStyles) === null || _c === void 0 ? void 0 : _c.find(style => { var _a; return ((_a = style.name) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'normal'; });
|
|
8
|
+
const fontId = (normal === null || normal === void 0 ? void 0 : normal.xfId) === undefined ? 0 : (_f = (_e = (_d = styles === null || styles === void 0 ? void 0 : styles.CellStyleXf) === null || _d === void 0 ? void 0 : _d[normal.xfId]) === null || _e === void 0 ? void 0 : _e.fontId) !== null && _f !== void 0 ? _f : 0;
|
|
9
|
+
const font = (_g = styles === null || styles === void 0 ? void 0 : styles.Fonts) === null || _g === void 0 ? void 0 : _g[fontId];
|
|
10
|
+
const size = Number(font === null || font === void 0 ? void 0 : font.sz);
|
|
11
|
+
// SimSun/NSimSun digits advance half an em. Convert font points to CSS
|
|
12
|
+
// pixels before rounding; scaling an already rounded 11pt grid widens
|
|
13
|
+
// 10.5pt and 12pt templates. Other CJK families can have different metrics.
|
|
14
|
+
if (/^(?:宋体|新宋体|simsun|nsimsun)$/i.test(((_h = font === null || font === void 0 ? void 0 : font.name) === null || _h === void 0 ? void 0 : _h.trim()) || '')
|
|
15
|
+
&& Number.isFinite(size) && size >= 1 && size <= 409) {
|
|
16
|
+
return Math.max(1, Math.ceil(size * 96 / 72 / 2));
|
|
17
|
+
}
|
|
18
|
+
return 7;
|
|
19
|
+
};
|
|
20
|
+
/** Read only the worksheet header; never materialize a large sheet's cells a
|
|
21
|
+
* second time merely to recover sheetFormatPr. */
|
|
22
|
+
export const readStoredSheetLayout = async (zip, part) => {
|
|
23
|
+
var _a, _b, _c, _d;
|
|
24
|
+
const file = zip.file(part);
|
|
25
|
+
if (!file)
|
|
26
|
+
return {};
|
|
27
|
+
const limit = 128 * 1024;
|
|
28
|
+
const header = await new Promise((resolve, reject) => {
|
|
29
|
+
let prefix = '';
|
|
30
|
+
let done = false;
|
|
31
|
+
// JSZip exposes this streaming API at runtime but omits it from JSZipObject's declaration.
|
|
32
|
+
const stream = file.internalStream('string');
|
|
33
|
+
const finish = () => {
|
|
34
|
+
if (done)
|
|
35
|
+
return;
|
|
36
|
+
done = true;
|
|
37
|
+
stream.pause();
|
|
38
|
+
resolve(prefix);
|
|
39
|
+
};
|
|
40
|
+
stream.on('data', chunk => {
|
|
41
|
+
if (done)
|
|
42
|
+
return;
|
|
43
|
+
prefix += chunk.slice(0, limit - prefix.length);
|
|
44
|
+
if (/<(?:[\w.-]+:)?(?:sheetFormatPr\b[^>]*>|sheetData\b)/.test(prefix) || prefix.length >= limit)
|
|
45
|
+
finish();
|
|
46
|
+
});
|
|
47
|
+
stream.on('end', finish);
|
|
48
|
+
stream.on('error', error => { if (!done) {
|
|
49
|
+
done = true;
|
|
50
|
+
reject(error);
|
|
51
|
+
} });
|
|
52
|
+
stream.resume();
|
|
53
|
+
});
|
|
54
|
+
const tag = (_a = /<(?:[\w.-]+:)?sheetFormatPr\b[^>]*>/.exec(header)) === null || _a === void 0 ? void 0 : _a[0];
|
|
55
|
+
if (!tag)
|
|
56
|
+
return {};
|
|
57
|
+
const root = ((_b = /<(?:[\w.-]+:)?worksheet\b[^>]*>/.exec(header)) === null || _b === void 0 ? void 0 : _b[0]) || '';
|
|
58
|
+
const namespaces = ((_c = root.match(/\sxmlns(?::[\w.-]+)?\s*=\s*(?:"[^"]*"|'[^']*')/g)) === null || _c === void 0 ? void 0 : _c.join('')) || '';
|
|
59
|
+
const element = (_d = new DOMParser().parseFromString(`<layout${namespaces}>${tag.replace(/\/?>(?:\s*)$/, '/>')}</layout>`, 'application/xml').documentElement) === null || _d === void 0 ? void 0 : _d.getElementsByTagName('*')[0];
|
|
60
|
+
const bounded = (name, max) => {
|
|
61
|
+
const raw = element === null || element === void 0 ? void 0 : element.getAttribute(name);
|
|
62
|
+
if (raw == null || raw.trim() === '')
|
|
63
|
+
return undefined;
|
|
64
|
+
const value = Number(raw);
|
|
65
|
+
return Number.isFinite(value) && value > 0 && value <= max ? value : undefined;
|
|
66
|
+
};
|
|
67
|
+
return { columnWidth: bounded('defaultColWidth', 255), rowHeightPt: bounded('defaultRowHeight', 409.5) };
|
|
68
|
+
};
|
|
@@ -32,6 +32,12 @@ const LEGACY_SPREADSHEET_TYPES = new Set([
|
|
|
32
32
|
]);
|
|
33
33
|
const OLE_SIGNATURE = [0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1];
|
|
34
34
|
const TEXT_PROBE_BYTES = 65536;
|
|
35
|
+
/**
|
|
36
|
+
* Legacy Excel exports can contain delimited text or HTML rather than BIFF.
|
|
37
|
+
* Passing those bytes directly to the workbook reader selects its single-byte
|
|
38
|
+
* fallback and corrupts UTF-8/GBK values. Sniff only legacy spreadsheet inputs;
|
|
39
|
+
* preserve real binary signatures and let the shared decoder select encoding.
|
|
40
|
+
*/
|
|
35
41
|
const isTextBackedLegacySpreadsheet = (data, source) => {
|
|
36
42
|
const type = normalizeFileType(source.fileType) || getFilenameExtension(source.filename);
|
|
37
43
|
if (!LEGACY_SPREADSHEET_TYPES.has(type) || !data.byteLength)
|
|
@@ -41,6 +47,7 @@ const isTextBackedLegacySpreadsheet = (data, source) => {
|
|
|
41
47
|
return false;
|
|
42
48
|
if (bytes[0] === 0x50 && bytes[1] === 0x4b)
|
|
43
49
|
return false;
|
|
50
|
+
// Raw BIFF2/3/4/5/8 BOF records need not be wrapped in an OLE container.
|
|
44
51
|
if (bytes[0] === 0x09 && [0x00, 0x02, 0x04, 0x08].includes(bytes[1]))
|
|
45
52
|
return false;
|
|
46
53
|
const encoding = resolveFileViewerTextEncoding(bytes).encoding;
|
|
@@ -48,7 +48,9 @@ export interface SheetDrawingMarker {
|
|
|
48
48
|
export interface SheetChartSeries {
|
|
49
49
|
name: string;
|
|
50
50
|
categories: string[];
|
|
51
|
+
/** Non-finite entries are gaps; structured clone preserves their positions. */
|
|
51
52
|
values: number[];
|
|
53
|
+
/** Transferred-array blank positions to span, excluding numeric errors. */
|
|
52
54
|
spanBlankIndexes?: number[];
|
|
53
55
|
sourcePointCount?: number;
|
|
54
56
|
sourcePointIndexes?: number[];
|
|
@@ -66,6 +68,7 @@ export interface SheetChartDefinition {
|
|
|
66
68
|
type: SheetChartType;
|
|
67
69
|
title?: string;
|
|
68
70
|
categoryAxisTitle?: string;
|
|
71
|
+
/** Unscaled CSS pixels from DrawingML hundredth-point text properties. */
|
|
69
72
|
categoryAxisFontSize?: number;
|
|
70
73
|
valueAxisFontSize?: number;
|
|
71
74
|
valueAxisTitle?: string;
|
package/dist/spreadsheet.js
CHANGED
|
@@ -129,6 +129,12 @@ const collectEVirtTableStyleDocuments = (documentRef) => [
|
|
|
129
129
|
].filter((value, index, values) => (!!value && values.indexOf(value) === index));
|
|
130
130
|
const collectStyleElements = (documents) => documents.flatMap(candidateDocument => { var _a; return Array.from(((_a = candidateDocument.head) === null || _a === void 0 ? void 0 : _a.querySelectorAll('style')) || []); });
|
|
131
131
|
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.
|
|
132
138
|
export const resolveEVirtTableStyleText = (documentRef) => {
|
|
133
139
|
var _a;
|
|
134
140
|
const styles = collectStyleElements(collectEVirtTableStyleDocuments(documentRef));
|
|
@@ -152,6 +158,9 @@ const loadEVirtTable = async (documentRef) => {
|
|
|
152
158
|
injectedStyles.forEach(style => style.remove());
|
|
153
159
|
return {
|
|
154
160
|
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.
|
|
155
164
|
styleText: loadedEVirtTableStyleText || resolveEVirtTableStyleText(documentRef),
|
|
156
165
|
};
|
|
157
166
|
};
|
|
@@ -815,6 +824,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
815
824
|
if (x < 0 || y < 0 || x > viewportRect.width || y > viewportRect.height) {
|
|
816
825
|
return undefined;
|
|
817
826
|
}
|
|
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.
|
|
818
829
|
if ([...sheetCharts].reverse().some(chart => containsViewportPoint(chart, x, y))) {
|
|
819
830
|
return undefined;
|
|
820
831
|
}
|
|
@@ -896,6 +907,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
896
907
|
const horizontal = tableContainer
|
|
897
908
|
? Math.max(tableContainer.offsetHeight - tableContainer.clientHeight, 0)
|
|
898
909
|
: 0;
|
|
910
|
+
// e-virt-table may draw overlay scrollbars, so keep a small reserved lane
|
|
911
|
+
// even when native scrollbar metrics report zero.
|
|
899
912
|
return {
|
|
900
913
|
vertical: vertical || EXCEL_IMAGE_SCROLLBAR_GUARD,
|
|
901
914
|
horizontal: horizontal || EXCEL_IMAGE_SCROLLBAR_GUARD,
|
|
@@ -1369,6 +1382,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1369
1382
|
}
|
|
1370
1383
|
refreshTableLayoutWhenVisible();
|
|
1371
1384
|
}).catch(() => {
|
|
1385
|
+
// Font readiness is only a paint stabilizer; rendering already has a fallback.
|
|
1372
1386
|
}));
|
|
1373
1387
|
};
|
|
1374
1388
|
function setColumnWidthByKey(columns, key, width) {
|
|
@@ -1389,6 +1403,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1389
1403
|
(_a = table === null || table === void 0 ? void 0 : table.setCustomHeader) === null || _a === void 0 ? void 0 : _a.call(table, { resizableData: {} }, true);
|
|
1390
1404
|
}
|
|
1391
1405
|
catch {
|
|
1406
|
+
// 某些旧版 e-virt-table 类型没有公开 setCustomHeader,忽略即可,下一次 loadColumns 仍会使用 core 状态。
|
|
1392
1407
|
}
|
|
1393
1408
|
}
|
|
1394
1409
|
function handleColumnResizeChange(event) {
|
|
@@ -1409,6 +1424,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1409
1424
|
if (activeSheetId !== undefined) {
|
|
1410
1425
|
sheetStateCache.set(activeSheetId, virtualState);
|
|
1411
1426
|
}
|
|
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.
|
|
1412
1429
|
queueMicrotask(() => {
|
|
1413
1430
|
if (disposed || !table)
|
|
1414
1431
|
return;
|
|
@@ -1697,6 +1714,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1697
1714
|
}
|
|
1698
1715
|
cached.loadingWindows.clear();
|
|
1699
1716
|
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.
|
|
1700
1719
|
syncScaledRowHeights();
|
|
1701
1720
|
errorMessage = '';
|
|
1702
1721
|
totalRows = cached.totalRows;
|
|
@@ -1768,6 +1787,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1768
1787
|
const scale = Number((_a = state.scale) !== null && _a !== void 0 ? _a : (_b = state.zoom) === null || _b === void 0 ? void 0 : _b.scale);
|
|
1769
1788
|
if (Number.isFinite(scale) && scale > 0)
|
|
1770
1789
|
setZoom(scale);
|
|
1790
|
+
// Coordinate navigation supplies its own final scroll after the target loads.
|
|
1771
1791
|
if (((_c = state.spreadsheet) === null || _c === void 0 ? void 0 : _c.range) || !sheets.length)
|
|
1772
1792
|
return;
|
|
1773
1793
|
const nextSheet = (_e = (_d = state.spreadsheet) === null || _d === void 0 ? void 0 : _d.sheetId) !== null && _e !== void 0 ? _e : getActiveSheetId();
|
|
@@ -1789,6 +1809,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1789
1809
|
const restore = pendingViewRestore;
|
|
1790
1810
|
if (!restore || !table || !virtualState.active || restore.sheetId !== getActiveSheetId())
|
|
1791
1811
|
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.
|
|
1792
1814
|
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
1793
1815
|
if (pendingViewRestore !== restore || !restore.isCurrent() || !table || disposed)
|
|
1794
1816
|
return;
|
|
@@ -1827,6 +1849,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1827
1849
|
if (navigatingRange && !finishRange)
|
|
1828
1850
|
return;
|
|
1829
1851
|
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.
|
|
1830
1854
|
const columnLeft = getSearchColumnLeft(getDisplayColumns(virtualState.columns, zoom), virtualState.dataKeys[pending.col] || getDataKey(pending.col));
|
|
1831
1855
|
const targetLeft = columnLeft === undefined
|
|
1832
1856
|
? table.ctx.scrollX || 0
|