@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
package/README.en.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @file-viewer/renderer-spreadsheet
|
|
2
2
|
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/spreadsheet/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/spreadsheet/README.zh-CN.md)
|
|
4
|
+
|
|
3
5
|
Standalone spreadsheet renderer package for Flyfish File Viewer. It is powered by `styled-exceljs` and `e-virt-table`, previews XLSX, XLSM, XLSB, XLS, CSV, TSV, ODS, FODS, Numbers, and compatible spreadsheet files in the browser, and resolves the optional worker URL through the File Viewer asset manifest for offline enterprise deployments.
|
|
4
6
|
|
|
5
7
|
## Usage
|
|
@@ -35,20 +37,22 @@ const options = {
|
|
|
35
37
|
- Supports multiple sheets, horizontally scrollable sheet tabs, merged cells, row and column sizing, borders, fills, alignment, text color, Office 365 and WPS in-cell images, workbook drawing images, double-click image previews, the global zoom provider, and optional header drag column resizing.
|
|
36
38
|
- TIFF drawings in XLSX files load the MIT-licensed UTIF.js decoder only when needed and are converted to PNG in the browser. Ordinary spreadsheets do not load the TIFF decoder.
|
|
37
39
|
- Uses virtual rendering for interaction. Host components usually hide full-document print for spreadsheets to avoid printing only the current viewport.
|
|
40
|
+
- XLSX uses saved default and explicit column widths and point-based row heights. CSV/TSV retains content auto-fit and supports large decoded text without creating a second UTF-8 byte array.
|
|
41
|
+
- Column units follow the workbook's Normal style. SimSun/NSimSun digit advances are converted from points before rounding; unmeasured custom fonts retain the standard fallback, so exact geometry can depend on the font.
|
|
38
42
|
|
|
39
43
|
## Fill the viewport for small Excel sheets
|
|
40
44
|
|
|
41
|
-
`options.spreadsheet.fillViewport` defaults to `
|
|
45
|
+
`options.spreadsheet.fillViewport` defaults to `true` for spreadsheet formats, including Excel and CSV / TSV. Small and empty sheets show blank column headers (A / B / …), row numbers and grid cells using the worksheet's default sizes. Padding recalculates on resize, zoom and sheet changes, stays virtual, and never stretches existing cells or changes workbook data. Set it to `false` to show only the used range.
|
|
42
46
|
|
|
43
47
|
```ts
|
|
44
48
|
const options = {
|
|
45
49
|
rendererMode: 'replace',
|
|
46
50
|
renderers: spreadsheetRenderer,
|
|
47
|
-
spreadsheet: { fillViewport:
|
|
51
|
+
spreadsheet: { fillViewport: false }, // Optional: show only the used range.
|
|
48
52
|
}
|
|
49
53
|
```
|
|
50
54
|
|
|
51
|
-
This changes only the display: workbook data, used range, original-file downloads/exports, search results and content counts remain unchanged.
|
|
55
|
+
This changes only the display: workbook data, used range, original-file downloads/exports, search results and content counts remain unchanged.
|
|
52
56
|
|
|
53
57
|
## Offline Assets
|
|
54
58
|
|
|
@@ -61,3 +65,9 @@ For private deployments, override it with `options.spreadsheet.workerUrl`. The o
|
|
|
61
65
|
## Migration Note
|
|
62
66
|
|
|
63
67
|
Spreadsheet preview has moved completely out of `@file-viewer/core`. Core now only keeps the asset manifest, shared types, and a compatibility error message, and it no longer installs `styled-exceljs`, `e-virt-table`, or `tinycolor2` by default. Install this package and pass it through `renderers`, or use `@file-viewer/preset-all` for the complete spreadsheet experience.
|
|
68
|
+
|
|
69
|
+
## Formulas without saved results
|
|
70
|
+
|
|
71
|
+
Saved formula results, including zero, remain authoritative. When an exporter omits the saved result, the preview can recover local/cross-sheet references, ranges, arithmetic/comparisons, `IF`, `ROUND`, `ROW` and `SUM` with a bounded offline evaluator. Cell number formats are retained.
|
|
72
|
+
|
|
73
|
+
This is not a full Excel calculation engine. Cyclic, external, unsupported or over-budget formulas are displayed as their original `=formula` text instead of a fabricated zero. No JavaScript or remote formula resources are evaluated. Main-thread and Worker paths use the same recovery logic.
|
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# @file-viewer/renderer-spreadsheet
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/spreadsheet/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/spreadsheet/README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Standalone spreadsheet renderer package for Flyfish File Viewer. It is powered by `styled-exceljs` and `e-virt-table`, previews XLSX, XLSM, XLSB, XLS, CSV, TSV, ODS, FODS, Numbers, and compatible spreadsheet files in the browser, and resolves the optional worker URL through the File Viewer asset manifest for offline enterprise deployments.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
6
8
|
|
|
7
9
|
```ts
|
|
8
10
|
import FileViewer from '@file-viewer/vue3'
|
|
@@ -14,7 +16,7 @@ const options = {
|
|
|
14
16
|
}
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
You can also compose it with other renderer packages:
|
|
18
20
|
|
|
19
21
|
```ts
|
|
20
22
|
import { pdfRenderer } from '@file-viewer/renderer-pdf'
|
|
@@ -26,38 +28,46 @@ const options = {
|
|
|
26
28
|
}
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
##
|
|
31
|
+
## Capabilities
|
|
30
32
|
|
|
31
|
-
-
|
|
32
|
-
- CSV / TSV
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
- XLSX
|
|
37
|
-
-
|
|
33
|
+
- Supports `.xlsx`, `.xltx`, `.xlsm`, `.xlsb`, `.xls`, `.xlt`, `.xltm`, `.csv`, `.tsv`, `.ods`, `.fods`, and `.numbers`.
|
|
34
|
+
- CSV / TSV automatically detects UTF-8 (with or without BOM) and GBK / GB18030. For known inputs, set `options.spreadsheet.textEncoding` to `utf-8`, `gbk`, or `gb18030`.
|
|
35
|
+
- Defaults to `options.spreadsheet.worker: 'auto'`: small files keep the main-thread compatibility path, while files at or above `options.spreadsheet.workerAutoThreshold` (1MB by default) automatically try the static worker.
|
|
36
|
+
- Can force the static worker with `options.spreadsheet.worker: true`, disable auto worker with `worker: false`, and override custom static paths with `options.spreadsheet.workerUrl`.
|
|
37
|
+
- Supports multiple sheets, horizontally scrollable sheet tabs, merged cells, row and column sizing, borders, fills, alignment, text color, Office 365 and WPS in-cell images, workbook drawing images, double-click image previews, the global zoom provider, and optional header drag column resizing.
|
|
38
|
+
- TIFF drawings in XLSX files load the MIT-licensed UTIF.js decoder only when needed and are converted to PNG in the browser. Ordinary spreadsheets do not load the TIFF decoder.
|
|
39
|
+
- Uses virtual rendering for interaction. Host components usually hide full-document print for spreadsheets to avoid printing only the current viewport.
|
|
40
|
+
- XLSX uses saved default and explicit column widths and point-based row heights. CSV/TSV retains content auto-fit and supports large decoded text without creating a second UTF-8 byte array.
|
|
41
|
+
- Column units follow the workbook's Normal style. SimSun/NSimSun digit advances are converted from points before rounding; unmeasured custom fonts retain the standard fallback, so exact geometry can depend on the font.
|
|
38
42
|
|
|
39
|
-
##
|
|
43
|
+
## Fill the viewport for small Excel sheets
|
|
40
44
|
|
|
41
|
-
`options.spreadsheet.fillViewport`
|
|
45
|
+
`options.spreadsheet.fillViewport` defaults to `true` for spreadsheet formats, including Excel and CSV / TSV. Small and empty sheets show blank column headers (A / B / …), row numbers and grid cells using the worksheet's default sizes. Padding recalculates on resize, zoom and sheet changes, stays virtual, and never stretches existing cells or changes workbook data. Set it to `false` to show only the used range.
|
|
42
46
|
|
|
43
47
|
```ts
|
|
44
48
|
const options = {
|
|
45
49
|
rendererMode: 'replace',
|
|
46
50
|
renderers: spreadsheetRenderer,
|
|
47
|
-
spreadsheet: { fillViewport:
|
|
51
|
+
spreadsheet: { fillViewport: false }, // Optional: show only the used range.
|
|
48
52
|
}
|
|
49
53
|
```
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
This changes only the display: workbook data, used range, original-file downloads/exports, search results and content counts remain unchanged.
|
|
52
56
|
|
|
53
|
-
##
|
|
57
|
+
## Offline Assets
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
The optional worker path is:
|
|
56
60
|
|
|
57
61
|
- `vendor/xlsx/sheet.worker.js`
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
For private deployments, override it with `options.spreadsheet.workerUrl`. The official Vite plugin and demo worker build script generate this file from this package's worker entry.
|
|
64
|
+
|
|
65
|
+
## Migration Note
|
|
66
|
+
|
|
67
|
+
Spreadsheet preview has moved completely out of `@file-viewer/core`. Core now only keeps the asset manifest, shared types, and a compatibility error message, and it no longer installs `styled-exceljs`, `e-virt-table`, or `tinycolor2` by default. Install this package and pass it through `renderers`, or use `@file-viewer/preset-all` for the complete spreadsheet experience.
|
|
68
|
+
|
|
69
|
+
## Formulas without saved results
|
|
60
70
|
|
|
61
|
-
|
|
71
|
+
Saved formula results, including zero, remain authoritative. When an exporter omits the saved result, the preview can recover local/cross-sheet references, ranges, arithmetic/comparisons, `IF`, `ROUND`, `ROW` and `SUM` with a bounded offline evaluator. Cell number formats are retained.
|
|
62
72
|
|
|
63
|
-
|
|
73
|
+
This is not a full Excel calculation engine. Cyclic, external, unsupported or over-budget formulas are displayed as their original `=formula` text instead of a fabricated zero. No JavaScript or remote formula resources are evaluated. Main-thread and Worker paths use the same recovery logic.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @file-viewer/renderer-spreadsheet
|
|
2
|
+
|
|
3
|
+
[English](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/spreadsheet/README.md) · [简体中文](https://github.com/flyfish-dev/file-viewer/blob/main/packages/renderers/spreadsheet/README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Flyfish File Viewer 的独立表格 renderer 包。它基于 `styled-exceljs` 与 `e-virt-table` 提供 XLSX、XLSM、XLSB、XLS、CSV、TSV、ODS、FODS、Numbers 等表格文件的浏览器端预览,并通过 File Viewer 统一的 asset manifest 解析可选 Worker 路径,适合企业内网和离线部署。
|
|
6
|
+
|
|
7
|
+
## 用法
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import FileViewer from '@file-viewer/vue3'
|
|
11
|
+
import { spreadsheetRenderer } from '@file-viewer/renderer-spreadsheet'
|
|
12
|
+
|
|
13
|
+
const options = {
|
|
14
|
+
rendererMode: 'replace',
|
|
15
|
+
renderers: spreadsheetRenderer,
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
也可以和其他 renderer 一起组合:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { pdfRenderer } from '@file-viewer/renderer-pdf'
|
|
23
|
+
import { spreadsheetRenderer } from '@file-viewer/renderer-spreadsheet'
|
|
24
|
+
|
|
25
|
+
const options = {
|
|
26
|
+
rendererMode: 'replace',
|
|
27
|
+
renderers: [pdfRenderer, spreadsheetRenderer],
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 能力边界
|
|
32
|
+
|
|
33
|
+
- 支持 `.xlsx`、`.xltx`、`.xlsm`、`.xlsb`、`.xls`、`.xlt`、`.xltm`、`.csv`、`.tsv`、`.ods`、`.fods`、`.numbers`。
|
|
34
|
+
- CSV / TSV 默认自动识别 UTF-8(含 BOM)与 GBK / GB18030;遇到来源编码已知的文件时,可通过 `options.spreadsheet.textEncoding` 固定为 `utf-8`、`gbk` 或 `gb18030`。
|
|
35
|
+
- 默认 `options.spreadsheet.worker: 'auto'`:小文件走主线程兼容路径,大文件达到 `options.spreadsheet.workerAutoThreshold`(默认 1MB)后自动尝试静态 Worker。
|
|
36
|
+
- 可以通过 `options.spreadsheet.worker: true` 强制启用静态 Worker,通过 `worker: false` 关闭自动启用;静态路径特殊时配置 `options.spreadsheet.workerUrl`。
|
|
37
|
+
- 支持多 sheet、横向滚动标签栏、合并单元格、列宽/行高、边框、填充、对齐、文本颜色、Office 365 / WPS 单元格内嵌图片、workbook drawing 图片、图片双击大图预览、统一缩放 provider 和可选表头拖拽调整列宽。
|
|
38
|
+
- XLSX drawing 中的 TIFF 图片会按需加载 MIT 许可的 UTIF.js,在浏览器内转换为 PNG;普通表格不会加载 TIFF 解码器。
|
|
39
|
+
- 表格使用虚拟渲染,适合交互预览;完整打印按钮通常由上层能力判断隐藏,避免只打印当前视口。
|
|
40
|
+
- XLSX 保留文件保存的默认列宽、显式列宽和以磅记录的行高;CSV/TSV 继续按内容调整列宽,大文本解析避免重复创建完整 UTF-8 字节数组。
|
|
41
|
+
- 列宽单位以工作簿 Normal 样式为基准。宋体、新宋体的数字宽度先从磅转换为像素,再进行取整;尚未测定的自定义字体沿用标准回退,实际尺寸可能受字体影响。
|
|
42
|
+
|
|
43
|
+
## 小内容 Excel 填满视口
|
|
44
|
+
|
|
45
|
+
`options.spreadsheet.fillViewport` 默认 `true`,适用于 Excel、CSV / TSV 等表格格式。按工作表默认行高、列宽补充空白列标题(A / B / …)、行号和网格,让小表或空 Sheet 填满当前预览区域。容器 resize、缩放和切 Sheet 时重新计算,补充部分沿用虚拟画布,不生成整张 Excel 空表,不拉伸已有单元格,也不改变工作簿数据。设为 `false` 可只显示已用区域。
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const options = {
|
|
49
|
+
rendererMode: 'replace',
|
|
50
|
+
renderers: spreadsheetRenderer,
|
|
51
|
+
spreadsheet: { fillViewport: false }, // 可选:只显示已用区域。
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
补充部分只用于显示,不改变工作簿数据、used-range、原文件下载/导出、搜索结果或内容统计。
|
|
56
|
+
|
|
57
|
+
## 离线资产
|
|
58
|
+
|
|
59
|
+
默认可选 Worker 路径为:
|
|
60
|
+
|
|
61
|
+
- `vendor/xlsx/sheet.worker.js`
|
|
62
|
+
|
|
63
|
+
私有化部署时可以通过 `options.spreadsheet.workerUrl` 覆盖。官方 Vite 插件和 Demo worker 构建脚本会从本包的 worker 入口生成该文件。
|
|
64
|
+
|
|
65
|
+
## 迁移说明
|
|
66
|
+
|
|
67
|
+
表格预览已经从 `@file-viewer/core` 中彻底移出,core 只保留资产 manifest、类型和兼容错误提示,不再默认安装 `styled-exceljs`、`e-virt-table` 或 `tinycolor2`。完整表格能力请安装本包并传入 `renderers`,或直接使用 `@file-viewer/preset-all`。
|
|
68
|
+
|
|
69
|
+
## 未保存计算结果的公式
|
|
70
|
+
|
|
71
|
+
优先保留文件已保存的公式结果,包括真实的零值。导出器未保存计算结果时,预览可在离线、受限的运算预算内补算本表/跨表引用、区域、算术/比较,以及 `IF`、`ROUND`、`ROW`、`SUM`,并保留单元格数字格式;主线程和 Worker 使用同一逻辑。
|
|
72
|
+
|
|
73
|
+
这不是完整的 Excel 计算引擎。循环引用、外部引用、不支持或超出预算的公式,会直接显示原始 `=公式` 文本,不再伪装成零。不会执行 JavaScript 或请求远程公式资源。
|
|
@@ -24,6 +24,9 @@ const svgText = (documentRef, value, x, y, options = {}) => {
|
|
|
24
24
|
text.textContent = value;
|
|
25
25
|
return text;
|
|
26
26
|
};
|
|
27
|
+
// The fixed plot coordinate system is letterboxed into the authored chart box.
|
|
28
|
+
// Compensate font units once for that intrinsic scale; sheet zoom is still
|
|
29
|
+
// applied by the containing renderer, so user zoom never gets cancelled out.
|
|
27
30
|
const axisFontSize = (chart, size, fallback) => {
|
|
28
31
|
const scale = Math.min(chart.width / 640, chart.height / 360);
|
|
29
32
|
return size !== undefined && Number.isFinite(size) && size > 0 && Number.isFinite(scale) && scale > 0
|
|
@@ -395,6 +398,7 @@ const polarPoint = (cx, cy, radius, angle) => {
|
|
|
395
398
|
};
|
|
396
399
|
};
|
|
397
400
|
const pieSlicePath = (cx, cy, outerRadius, innerRadius, startAngle, endAngle) => {
|
|
401
|
+
// A single SVG arc with identical endpoints is empty, not a full circle.
|
|
398
402
|
if (endAngle - startAngle >= 360 - 1e-7) {
|
|
399
403
|
const a = polarPoint(cx, cy, outerRadius, startAngle);
|
|
400
404
|
const b = polarPoint(cx, cy, outerRadius, startAngle + 180);
|
|
@@ -449,6 +453,7 @@ const drawLegend = (documentRef, svg, chart) => {
|
|
|
449
453
|
}
|
|
450
454
|
const right = chart.legendPosition === 'right';
|
|
451
455
|
const categorySeries = chart.type === 'pie' || chart.type === 'doughnut' ? chart.series[0] : undefined;
|
|
456
|
+
// Build only visible entries when a pie has a large category cache.
|
|
452
457
|
const entries = chart.type === 'pie' || chart.type === 'doughnut'
|
|
453
458
|
? ((categorySeries === null || categorySeries === void 0 ? void 0 : categorySeries.values) || []).slice(0, MAX_LEGEND_ITEMS).map((_, index) => ({
|
|
454
459
|
...categorySeries,
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export declare const MAX_TRANSFERRED_LINE_CHART_POINTS = 4096;
|
|
2
|
+
/** Keep absent points as explicit separators through both transfer and SVG
|
|
3
|
+
* sampling. Otherwise an omitted gap becomes an invented connecting segment.
|
|
4
|
+
* Reserve at most one separator per retained interval, keeping a strict budget.
|
|
5
|
+
*/
|
|
2
6
|
export declare const extremaPointIndexes: (values: number[], maxPoints: number, spanBlankIndexes?: number[]) => number[];
|
|
@@ -36,6 +36,10 @@ const sampleExtrema = (values, maxPoints) => {
|
|
|
36
36
|
result.push(values.length - 1);
|
|
37
37
|
return Array.from(new Set(result));
|
|
38
38
|
};
|
|
39
|
+
/** Keep absent points as explicit separators through both transfer and SVG
|
|
40
|
+
* sampling. Otherwise an omitted gap becomes an invented connecting segment.
|
|
41
|
+
* Reserve at most one separator per retained interval, keeping a strict budget.
|
|
42
|
+
*/
|
|
39
43
|
export const extremaPointIndexes = (values, maxPoints, spanBlankIndexes = []) => {
|
|
40
44
|
const limit = Math.max(2, Number.isFinite(maxPoints) ? Math.floor(maxPoints) : 2);
|
|
41
45
|
if (values.length <= limit)
|
|
@@ -46,6 +50,8 @@ export const extremaPointIndexes = (values, maxPoints, spanBlankIndexes = []) =>
|
|
|
46
50
|
const spanning = new Set(spanBlankIndexes);
|
|
47
51
|
const hardGap = (index) => !Number.isFinite(values[index]) && !spanning.has(index);
|
|
48
52
|
if (limit === 2) {
|
|
53
|
+
// There is no room for both endpoints and a separator. Prefer dropping one
|
|
54
|
+
// endpoint over inventing a connecting line across an absent interval.
|
|
49
55
|
const gap = values.findIndex((_, index) => hardGap(index));
|
|
50
56
|
return gap > 0 && gap < values.length - 1 ? [0, gap] : [0, values.length - 1];
|
|
51
57
|
}
|
|
@@ -10,11 +10,13 @@ type Options = {
|
|
|
10
10
|
jump: (range: FileViewerSpreadsheetRange) => void;
|
|
11
11
|
clearJump: () => void;
|
|
12
12
|
};
|
|
13
|
+
/** Own requests from registration through parsing, virtual-window loading and paint. */
|
|
13
14
|
export declare const createSpreadsheetRangeNavigation: (options: Options) => {
|
|
14
15
|
provider: FileViewerViewStateProvider;
|
|
15
16
|
cancel: (result?: "cancelled" | "failed" | "disposed") => void;
|
|
16
17
|
notify: (action: FileViewerViewStateChange["action"], source?: FileViewerViewStateChange["source"], notify?: boolean) => void;
|
|
17
18
|
isPending: () => boolean;
|
|
19
|
+
/** Called after the target virtual window loads, before drawing the highlight. */
|
|
18
20
|
prepare(totalRows: number, totalCols: number): (() => void) | null;
|
|
19
21
|
contains(sheetId: number, row: number, col: number): boolean;
|
|
20
22
|
};
|
|
@@ -14,6 +14,7 @@ const cloneState = (state) => ({
|
|
|
14
14
|
range: state.spreadsheet.range ? { ...state.spreadsheet.range } : undefined,
|
|
15
15
|
} : undefined,
|
|
16
16
|
});
|
|
17
|
+
/** Own requests from registration through parsing, virtual-window loading and paint. */
|
|
17
18
|
export const createSpreadsheetRangeNavigation = (options) => {
|
|
18
19
|
let stopped;
|
|
19
20
|
let status = 'idle';
|
|
@@ -52,6 +53,7 @@ export const createSpreadsheetRangeNavigation = (options) => {
|
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
55
|
const cancel = (result = 'cancelled') => {
|
|
56
|
+
// Disposal is terminal, including when a late parser rejection arrives.
|
|
55
57
|
if (stopped === 'disposed')
|
|
56
58
|
return;
|
|
57
59
|
const hadHighlight = !!highlighted;
|
|
@@ -66,6 +68,7 @@ export const createSpreadsheetRangeNavigation = (options) => {
|
|
|
66
68
|
if (result === 'disposed')
|
|
67
69
|
listeners.clear();
|
|
68
70
|
};
|
|
71
|
+
// Consume failure even when no API request was made before parsing failed.
|
|
69
72
|
void options.ready.catch(() => { if (!stopped)
|
|
70
73
|
cancel('failed'); });
|
|
71
74
|
const provider = {
|
|
@@ -140,6 +143,7 @@ export const createSpreadsheetRangeNavigation = (options) => {
|
|
|
140
143
|
return {
|
|
141
144
|
provider, cancel, notify: emit,
|
|
142
145
|
isPending: () => !!(pending === null || pending === void 0 ? void 0 : pending.range),
|
|
146
|
+
/** Called after the target virtual window loads, before drawing the highlight. */
|
|
143
147
|
prepare(totalRows, totalCols) {
|
|
144
148
|
const request = pending;
|
|
145
149
|
if (!(request === null || request === void 0 ? void 0 : request.range))
|
|
@@ -55,6 +55,7 @@ export interface VirtualSheetState {
|
|
|
55
55
|
mergeStartMap: Map<string, CellMerge>;
|
|
56
56
|
mergeCoveredMap: Map<string, true>;
|
|
57
57
|
rowHeightCache: Map<number, number>;
|
|
58
|
+
/** Unscaled user sizes take precedence over asynchronously loaded metrics. */
|
|
58
59
|
rowHeightOverrides: Map<number, number>;
|
|
59
60
|
windowRows: Map<number, number[]>;
|
|
60
61
|
windowCells: Map<number, string[]>;
|
|
@@ -65,6 +65,8 @@ export const getWindowStart = (row = 0, totalRows = 0) => {
|
|
|
65
65
|
const start = Math.floor(Math.max(row, 0) / WINDOW_SIZE) * WINDOW_SIZE;
|
|
66
66
|
return clampWindowStart(start, totalRows);
|
|
67
67
|
};
|
|
68
|
+
// 视口周边始终保留一小圈热窗口,滚轮滚动和拖动滚动条都可以直接命中缓存,
|
|
69
|
+
// 避免每次跳转都同步等待 worker 回包。
|
|
68
70
|
export const collectWindowStarts = ({ startRow, endRow, direction, totalRows, far = false }) => {
|
|
69
71
|
const starts = new Set();
|
|
70
72
|
const firstWindow = getWindowStart(startRow, totalRows);
|
package/dist/spreadsheet/view.js
CHANGED
|
@@ -169,7 +169,7 @@ export const buildFont = (style) => {
|
|
|
169
169
|
return [
|
|
170
170
|
style.fontStyle || 'normal',
|
|
171
171
|
normalizedWeight,
|
|
172
|
-
`${Number.
|
|
172
|
+
`${Number.parseFloat(style.fontSize) || TABLE_FONT_SIZE}px`,
|
|
173
173
|
normalizeFontFamily(style.fontFamily)
|
|
174
174
|
].join(' ');
|
|
175
175
|
};
|
|
@@ -235,9 +235,12 @@ export const getRowHeight = (heights, index, fallback) => {
|
|
|
235
235
|
}
|
|
236
236
|
return (_a = heights === null || heights === void 0 ? void 0 : heights[index]) !== null && _a !== void 0 ? _a : fallback;
|
|
237
237
|
};
|
|
238
|
+
// Excel 已经给出了行高时,预览层不再二次猜测。
|
|
239
|
+
// 只有完全缺失时才回退到默认行高,同时给极小值留一个最小可渲染下限。
|
|
238
240
|
export const normalizeRowHeight = (height, fallback) => {
|
|
239
241
|
if (typeof height === 'number' && Number.isFinite(height)) {
|
|
240
242
|
if (height <= 0) {
|
|
243
|
+
// e-virt-table 内部用 item._height || CELL_HEIGHT,0 会被误判为未设置。
|
|
241
244
|
return HIDDEN_ROW_HEIGHT;
|
|
242
245
|
}
|
|
243
246
|
return Math.max(Math.ceil(height), MIN_RENDERABLE_ROW_HEIGHT);
|
|
@@ -254,6 +257,8 @@ const isPlainTextCell = (value) => {
|
|
|
254
257
|
}
|
|
255
258
|
return !/^\d+([./:-]\d+)*$/.test(text);
|
|
256
259
|
};
|
|
260
|
+
// 普通明细表通常会把第一行当成字段表头,而报表类工作表往往需要保留原始 Excel 行号。
|
|
261
|
+
// 这里只在“首行像简单字段头且没有合并单元格”时,才给左侧序号做 1 行偏移。
|
|
257
262
|
export const detectIndexOffset = (ws) => {
|
|
258
263
|
const meta = ws.meta;
|
|
259
264
|
const rows = ws.data || [];
|
|
@@ -340,6 +345,7 @@ const scaleColumn = (column, zoomScale) => {
|
|
|
340
345
|
}
|
|
341
346
|
return nextColumn;
|
|
342
347
|
};
|
|
348
|
+
// Excel 预览优先忠实还原原始列宽,不再为了“铺满容器”二次拉伸列宽。
|
|
343
349
|
export const getDisplayColumns = (columns, zoomScale = 1) => {
|
|
344
350
|
const normalizedScale = normalizeZoomScale(zoomScale);
|
|
345
351
|
if (normalizedScale === 1) {
|
|
@@ -425,6 +431,7 @@ const shouldRenderTextInOverlay = (style, column) => {
|
|
|
425
431
|
if (!hasTextLayout(style)) {
|
|
426
432
|
return false;
|
|
427
433
|
}
|
|
434
|
+
// e-virt-table 的列级 align 可以交给 canvas;只有单元格级布局差异才用 DOM 覆盖层补齐。
|
|
428
435
|
return !!((style === null || style === void 0 ? void 0 : style.wrapText) ||
|
|
429
436
|
(style === null || style === void 0 ? void 0 : style.shrinkToFit) ||
|
|
430
437
|
((style === null || style === void 0 ? void 0 : style.horizontalAlign) && style.horizontalAlign !== ((column === null || column === void 0 ? void 0 : column.align) || 'left')) ||
|
|
@@ -547,7 +554,7 @@ const getExcelOverflowLayout = (virtualState, row, rowIndex, dataColIndex, colum
|
|
|
547
554
|
if (!ownWidth) {
|
|
548
555
|
return undefined;
|
|
549
556
|
}
|
|
550
|
-
const font = (style === null || style === void 0 ? void 0 : style.font) ||
|
|
557
|
+
const font = (style === null || style === void 0 ? void 0 : style.font) || getBodyFont(zoomScale);
|
|
551
558
|
const measuredWidth = Math.ceil(measureTextWidth(text, font, scaleNumber(CELL_PADDING, zoomScale), documentRef));
|
|
552
559
|
if (measuredWidth <= ownWidth) {
|
|
553
560
|
return undefined;
|
|
@@ -775,6 +782,8 @@ const applyOverflowLayout = (text, overflowLayout) => {
|
|
|
775
782
|
textOverflow: 'clip'
|
|
776
783
|
});
|
|
777
784
|
};
|
|
785
|
+
// e-virt-table 的普通样式接口不支持 Excel 式四边边框和单元格级换行/垂直对齐,
|
|
786
|
+
// 这里借助官方的 BODY_CELL_RENDER_METHOD,只在可视区补轻量 DOM 覆盖层。
|
|
778
787
|
const renderCellOverlay = (cellEl, borderStyle, textStyle, textValue, renderText, overflowLayout, zoomScale) => {
|
|
779
788
|
const documentRef = cellEl.ownerDocument;
|
|
780
789
|
cellEl.replaceChildren();
|
|
@@ -1036,6 +1045,8 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
|
|
|
1036
1045
|
RESIZE_ROW_LINE_COLOR: EXCEL_GREEN,
|
|
1037
1046
|
RESIZE_ROW_MIN_HEIGHT: scaleNumber(RESIZABLE_ROW_MIN_HEIGHT, normalizedScale),
|
|
1038
1047
|
ENABLE_KEYBOARD: true,
|
|
1048
|
+
// The table finder only indexes loaded rows and competes with the viewer's
|
|
1049
|
+
// workbook-wide search shortcut. Keep one search owner for all integrations.
|
|
1039
1050
|
ENABLE_FINDER: false,
|
|
1040
1051
|
ENABLE_COPY: true,
|
|
1041
1052
|
BEFORE_COPY_METHOD: copySelection
|
|
@@ -1044,6 +1055,7 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
|
|
|
1044
1055
|
return undefined;
|
|
1045
1056
|
}
|
|
1046
1057
|
: undefined,
|
|
1058
|
+
// 预览态只开放“拖动扩选”的交互,不允许真正写回单元格内容。
|
|
1047
1059
|
BEFORE_AUTOFILL_DATA_METHOD: () => [],
|
|
1048
1060
|
SPAN_METHOD: spanMethod,
|
|
1049
1061
|
HEADER_CELL_STYLE_METHOD: headerStyleMethod,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Column } from 'e-virt-table';
|
|
2
2
|
import { type VirtualRow, type VirtualSheetState } from './state.js';
|
|
3
3
|
export declare const shouldFillSpreadsheetViewport: (enabled: boolean | undefined, type?: string) => boolean;
|
|
4
|
+
/** Display-only padding. The parser's dimensions, rows and columns stay authoritative. */
|
|
4
5
|
export declare class SpreadsheetViewportFill {
|
|
5
6
|
private sourceRows?;
|
|
6
7
|
private rows;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getDataKey, ROW_KEY_FIELD, ROW_STATE_FIELD, RowState } from './state.js';
|
|
2
2
|
import { getDisplayColumns, HEADER_HEIGHT, normalizeRowHeight } from './view.js';
|
|
3
|
-
const
|
|
4
|
-
export const shouldFillSpreadsheetViewport = (enabled, type = '') => (enabled
|
|
3
|
+
const GRID_FORMATS = new Set(['xlsx', 'xltx', 'xlsm', 'xltm', 'xlsb', 'xls', 'xlt', 'xla', 'xlam', 'csv', 'tsv', 'ods', 'fods', 'numbers', 'et', 'ett', 'dbf']);
|
|
4
|
+
export const shouldFillSpreadsheetViewport = (enabled, type = '') => (enabled !== false && GRID_FORMATS.has(type.toLowerCase().replace(/^\./, '')));
|
|
5
5
|
const columnLabel = (index) => {
|
|
6
6
|
let value = index + 1;
|
|
7
7
|
let label = '';
|
|
@@ -12,6 +12,7 @@ const columnLabel = (index) => {
|
|
|
12
12
|
}
|
|
13
13
|
return label;
|
|
14
14
|
};
|
|
15
|
+
/** Display-only padding. The parser's dimensions, rows and columns stay authoritative. */
|
|
15
16
|
export class SpreadsheetViewportFill {
|
|
16
17
|
constructor() {
|
|
17
18
|
this.rows = [];
|
|
@@ -51,6 +52,7 @@ export class SpreadsheetViewportFill {
|
|
|
51
52
|
verticalAlign: 'middle',
|
|
52
53
|
}))) : state.columns;
|
|
53
54
|
}
|
|
55
|
+
// Blank rows use default metrics even when the host allows resizing data rows.
|
|
54
56
|
for (let index = state.totalRows; index < this.rows.length; index += 1)
|
|
55
57
|
this.rows[index]._height = rowHeight;
|
|
56
58
|
return { rows: this.rows, columns: this.columns };
|
|
@@ -43,10 +43,9 @@ const toFiniteNumber = (value) => {
|
|
|
43
43
|
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
44
44
|
};
|
|
45
45
|
const getDefaultColumnWidth = () => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return Math.ceil((_a = toFiniteNumber(value)) !== null && _a !== void 0 ? _a : 64);
|
|
46
|
+
// Excel's displayed default is 8.43 characters plus five pixels of padding,
|
|
47
|
+
// not an already encoded OOXML <col width> value.
|
|
48
|
+
return Math.floor(EXCEL_DEFAULT_COLUMN_WIDTH * 7 + 5);
|
|
50
49
|
};
|
|
51
50
|
const getDefaultRowHeight = () => {
|
|
52
51
|
var _a;
|
|
@@ -80,13 +79,18 @@ export const formatCellValue = (cell) => {
|
|
|
80
79
|
}
|
|
81
80
|
return `${cell.v}`;
|
|
82
81
|
};
|
|
83
|
-
const getColumnPixelWidth = (column) => {
|
|
82
|
+
const getColumnPixelWidth = (column, maximumDigitWidth = 7) => {
|
|
84
83
|
if (!column) {
|
|
85
84
|
return undefined;
|
|
86
85
|
}
|
|
87
86
|
if (column.hidden) {
|
|
88
87
|
return 0;
|
|
89
88
|
}
|
|
89
|
+
const storedWidth = toFiniteNumber(column.width);
|
|
90
|
+
if (maximumDigitWidth !== 7 && storedWidth !== undefined && storedWidth >= 0) {
|
|
91
|
+
return Math.trunc(((256 * storedWidth + Math.trunc(128 / maximumDigitWidth)) / 256) * maximumDigitWidth);
|
|
92
|
+
}
|
|
93
|
+
// styled-exceljs 在 browserPixels 模式下会优先输出 wpx,这是最接近浏览器渲染的列宽。
|
|
90
94
|
const wpx = toFiniteNumber(column.wpx);
|
|
91
95
|
if (wpx !== undefined && wpx >= 0) {
|
|
92
96
|
return Math.ceil(wpx);
|
|
@@ -141,16 +145,18 @@ const getRowPixelHeight = (rowMeta) => {
|
|
|
141
145
|
if (rowMeta.hidden) {
|
|
142
146
|
return 0;
|
|
143
147
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return Math.ceil(hpx);
|
|
147
|
-
}
|
|
148
|
+
// The parser retains OOXML points in hpt, but its legacy hpx conversion
|
|
149
|
+
// uses 96/96. Prefer the authoritative points and convert to CSS pixels once.
|
|
148
150
|
const hpt = toFiniteNumber(rowMeta.hpt);
|
|
149
151
|
if (hpt !== undefined && hpt >= 0) {
|
|
150
152
|
const converter = utils.row_height_to_px;
|
|
151
153
|
const converted = typeof converter === 'function' ? toFiniteNumber(converter(hpt)) : undefined;
|
|
152
154
|
return Math.ceil(converted !== null && converted !== void 0 ? converted : hpt * 96 / 72);
|
|
153
155
|
}
|
|
156
|
+
const hpx = toFiniteNumber(rowMeta.hpx);
|
|
157
|
+
if (hpx !== undefined && hpx >= 0) {
|
|
158
|
+
return Math.ceil(hpx);
|
|
159
|
+
}
|
|
154
160
|
return undefined;
|
|
155
161
|
};
|
|
156
162
|
const normalizeHorizontalAlign = (value) => {
|
|
@@ -229,6 +235,8 @@ const isAutomaticPaletteColor = (color) => {
|
|
|
229
235
|
return indexed === 32767;
|
|
230
236
|
};
|
|
231
237
|
const normalizeFontColor = (color) => {
|
|
238
|
+
// BIFF/XLS 会把“自动字体色”解析成 indexed 32767,部分文件还会附带
|
|
239
|
+
// FFFFFF 的 rgb 值。Excel 实际显示为默认黑色,不能当成显式白色。
|
|
232
240
|
if (isAutomaticPaletteColor(color)) {
|
|
233
241
|
return EXCEL_DEFAULT_TEXT_COLOR;
|
|
234
242
|
}
|
|
@@ -312,9 +320,10 @@ const getCellStyle = (cellStyle) => {
|
|
|
312
320
|
if (font.bold || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.bold)) {
|
|
313
321
|
style.fontWeight = 'bold';
|
|
314
322
|
}
|
|
315
|
-
const fontSize = font.sz || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.sz);
|
|
316
|
-
if (fontSize) {
|
|
317
|
-
|
|
323
|
+
const fontSize = Number(font.sz || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.sz));
|
|
324
|
+
if (Number.isFinite(fontSize) && fontSize > 0) {
|
|
325
|
+
// Excel 字号以 pt 存储;模型统一输出 CSS px,视图层再单独应用缩放。
|
|
326
|
+
style.fontSize = `${fontSize * 96 / 72}px`;
|
|
318
327
|
}
|
|
319
328
|
const fontName = font.name || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.name);
|
|
320
329
|
if (fontName) {
|
|
@@ -366,7 +375,14 @@ class SheetJsModel {
|
|
|
366
375
|
return this._ws;
|
|
367
376
|
}
|
|
368
377
|
get defaults() {
|
|
369
|
-
|
|
378
|
+
const layout = this.ws['!fileViewerLayout'];
|
|
379
|
+
if (!layout)
|
|
380
|
+
return SheetJsModel.defaults;
|
|
381
|
+
const columnWidth = layout.columnWidth === undefined ? undefined : getColumnPixelWidth({ width: layout.columnWidth }, layout.maximumDigitWidth);
|
|
382
|
+
return {
|
|
383
|
+
colWidth: columnWidth !== null && columnWidth !== void 0 ? columnWidth : SheetJsModel.defaults.colWidth,
|
|
384
|
+
rowHeight: layout.rowHeightPt === undefined ? SheetJsModel.defaults.rowHeight : Math.ceil(layout.rowHeightPt * 96 / 72)
|
|
385
|
+
};
|
|
370
386
|
}
|
|
371
387
|
get data() {
|
|
372
388
|
var _a;
|
|
@@ -615,6 +631,7 @@ class SheetJsModel {
|
|
|
615
631
|
}
|
|
616
632
|
return heights.length ? heights : rowHeight;
|
|
617
633
|
}
|
|
634
|
+
// 整表行高必须按绝对行号下发,否则拖动滚动条时隐藏行和特殊行高会造成高度跳变。
|
|
618
635
|
getAllRowHeights() {
|
|
619
636
|
const { '!rows': rows = [] } = this.ws;
|
|
620
637
|
const heights = [];
|
|
@@ -638,6 +655,8 @@ class SheetJsModel {
|
|
|
638
655
|
const sampleRanges = this.getAutoFitSampleRanges();
|
|
639
656
|
const fittedColumns = [];
|
|
640
657
|
for (const range of sampleRanges) {
|
|
658
|
+
// 自动列宽只作为缺失列宽的兜底。合并标题和 Excel 溢出文本不应该反向撑开基础列宽。
|
|
659
|
+
// 大表只抽样固定数量的单元格,避免为了首屏列宽扫描整张工作表。
|
|
641
660
|
const measuredColumns = autoFitColumns(this.ws, {
|
|
642
661
|
range,
|
|
643
662
|
set: false,
|
|
@@ -680,9 +699,13 @@ class SheetJsModel {
|
|
|
680
699
|
if (hasColumnWidth(sourceColumn)) {
|
|
681
700
|
return sourceColumn;
|
|
682
701
|
}
|
|
683
|
-
|
|
702
|
+
// A drawing anchor is measured against the workbook's stored/default
|
|
703
|
+
// column geometry. Auto-fitting blank columns to 24px changes that
|
|
704
|
+
// coordinate system and makes two-cell images visibly smaller than Excel.
|
|
705
|
+
if (this.hasAnchoredObjects || this.ws['!fileViewerLayout']) {
|
|
684
706
|
return sourceColumn;
|
|
685
707
|
}
|
|
708
|
+
// 没有显式列宽时,再使用 styled-exceljs 的内容测量兜底,避免报表类标题污染原始宽度。
|
|
686
709
|
return ((_a = this.autoFitColumns) === null || _a === void 0 ? void 0 : _a[colIndex]) || sourceColumn;
|
|
687
710
|
}
|
|
688
711
|
get hasAnchoredObjects() {
|
|
@@ -691,11 +714,12 @@ class SheetJsModel {
|
|
|
691
714
|
return !!((_a = drawings === null || drawings === void 0 ? void 0 : drawings.images) === null || _a === void 0 ? void 0 : _a.length) || !!this._charts.length || !!this._cellImages.length;
|
|
692
715
|
}
|
|
693
716
|
getColWidths() {
|
|
717
|
+
var _a;
|
|
694
718
|
const { colWidth } = this.defaults;
|
|
695
719
|
const { '!cols': sourceCols = [] } = this.ws;
|
|
696
720
|
const widths = [];
|
|
697
721
|
for (let colIndex = 0; colIndex < this.totalCols; colIndex += 1) {
|
|
698
|
-
const width = getColumnPixelWidth(this.getColumnMeta(sourceCols, colIndex));
|
|
722
|
+
const width = getColumnPixelWidth(this.getColumnMeta(sourceCols, colIndex), (_a = this.ws['!fileViewerLayout']) === null || _a === void 0 ? void 0 : _a.maximumDigitWidth);
|
|
699
723
|
if (width !== undefined) {
|
|
700
724
|
widths[colIndex] = width;
|
|
701
725
|
}
|