@file-viewer/renderer-spreadsheet 3.1.1 → 3.2.0

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 CHANGED
@@ -1,49 +1,7 @@
1
1
  # @file-viewer/renderer-spreadsheet
2
2
 
3
- 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.
3
+ Runtime package version 3.2.0.
4
4
 
5
- ## Usage
5
+ Usage and API documentation: https://doc.file-viewer.app/guide/on-demand-renderers
6
6
 
7
- ```ts
8
- import FileViewer from '@file-viewer/vue3'
9
- import { spreadsheetRenderer } from '@file-viewer/renderer-spreadsheet'
10
-
11
- const options = {
12
- rendererMode: 'replace',
13
- renderers: spreadsheetRenderer,
14
- }
15
- ```
16
-
17
- You can also compose it with other renderer packages:
18
-
19
- ```ts
20
- import { pdfRenderer } from '@file-viewer/renderer-pdf'
21
- import { spreadsheetRenderer } from '@file-viewer/renderer-spreadsheet'
22
-
23
- const options = {
24
- rendererMode: 'replace',
25
- renderers: [pdfRenderer, spreadsheetRenderer],
26
- }
27
- ```
28
-
29
- ## Capabilities
30
-
31
- - Supports `.xlsx`, `.xltx`, `.xlsm`, `.xlsb`, `.xls`, `.xlt`, `.xltm`, `.csv`, `.tsv`, `.ods`, `.fods`, and `.numbers`.
32
- - 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`.
33
- - 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.
34
- - 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`.
35
- - 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
- - 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
- - Uses virtual rendering for interaction. Host components usually hide full-document print for spreadsheets to avoid printing only the current viewport.
38
-
39
- ## Offline Assets
40
-
41
- The optional worker path is:
42
-
43
- - `vendor/xlsx/sheet.worker.js`
44
-
45
- 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.
46
-
47
- ## Migration Note
48
-
49
- 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.
7
+ The package's own license is Apache-2.0. Included third-party notices apply to their respective components.
package/README.md CHANGED
@@ -1,49 +1,7 @@
1
1
  # @file-viewer/renderer-spreadsheet
2
2
 
3
- Flyfish File Viewer 的独立表格 renderer 包。它基于 `styled-exceljs` 与 `e-virt-table` 提供 XLSX、XLSM、XLSB、XLS、CSV、TSV、ODS、FODS、Numbers 等表格文件的浏览器端预览,并通过 File Viewer 统一的 asset manifest 解析可选 Worker 路径,适合企业内网和离线部署。
3
+ Runtime package version 3.2.0.
4
4
 
5
- ## 用法
5
+ Usage and API documentation: https://doc.file-viewer.app/guide/on-demand-renderers
6
6
 
7
- ```ts
8
- import FileViewer from '@file-viewer/vue3'
9
- import { spreadsheetRenderer } from '@file-viewer/renderer-spreadsheet'
10
-
11
- const options = {
12
- rendererMode: 'replace',
13
- renderers: spreadsheetRenderer,
14
- }
15
- ```
16
-
17
- 也可以和其他 renderer 一起组合:
18
-
19
- ```ts
20
- import { pdfRenderer } from '@file-viewer/renderer-pdf'
21
- import { spreadsheetRenderer } from '@file-viewer/renderer-spreadsheet'
22
-
23
- const options = {
24
- rendererMode: 'replace',
25
- renderers: [pdfRenderer, spreadsheetRenderer],
26
- }
27
- ```
28
-
29
- ## 能力边界
30
-
31
- - 支持 `.xlsx`、`.xltx`、`.xlsm`、`.xlsb`、`.xls`、`.xlt`、`.xltm`、`.csv`、`.tsv`、`.ods`、`.fods`、`.numbers`。
32
- - CSV / TSV 默认自动识别 UTF-8(含 BOM)与 GBK / GB18030;遇到来源编码已知的文件时,可通过 `options.spreadsheet.textEncoding` 固定为 `utf-8`、`gbk` 或 `gb18030`。
33
- - 默认 `options.spreadsheet.worker: 'auto'`:小文件走主线程兼容路径,大文件达到 `options.spreadsheet.workerAutoThreshold`(默认 1MB)后自动尝试静态 Worker。
34
- - 可以通过 `options.spreadsheet.worker: true` 强制启用静态 Worker,通过 `worker: false` 关闭自动启用;静态路径特殊时配置 `options.spreadsheet.workerUrl`。
35
- - 支持多 sheet、横向滚动标签栏、合并单元格、列宽/行高、边框、填充、对齐、文本颜色、Office 365 / WPS 单元格内嵌图片、workbook drawing 图片、图片双击大图预览、统一缩放 provider 和可选表头拖拽调整列宽。
36
- - XLSX drawing 中的 TIFF 图片会按需加载 MIT 许可的 UTIF.js,在浏览器内转换为 PNG;普通表格不会加载 TIFF 解码器。
37
- - 表格使用虚拟渲染,适合交互预览;完整打印按钮通常由上层能力判断隐藏,避免只打印当前视口。
38
-
39
- ## 离线资产
40
-
41
- 默认可选 Worker 路径为:
42
-
43
- - `vendor/xlsx/sheet.worker.js`
44
-
45
- 私有化部署时可以通过 `options.spreadsheet.workerUrl` 覆盖。官方 Vite 插件和 Demo worker 构建脚本会从本包的 worker 入口生成该文件。
46
-
47
- ## 迁移说明
48
-
49
- 表格预览已经从 `@file-viewer/core` 中彻底移出,core 只保留资产 manifest、类型和兼容错误提示,不再默认安装 `styled-exceljs`、`e-virt-table` 或 `tinycolor2`。完整表格能力请安装本包并传入 `renderers`,或直接使用 `@file-viewer/preset-all`。
7
+ The package's own license is Apache-2.0. Included third-party notices apply to their respective components.
@@ -23,6 +23,11 @@ const svgText = (documentRef, value, x, y, options = {}) => {
23
23
  text.textContent = value;
24
24
  return text;
25
25
  };
26
+ const axisFontSize = (chart, size, fallback) => {
27
+ const scale = Math.min(chart.width / 640, chart.height / 360);
28
+ return size !== undefined && Number.isFinite(size) && size > 0 && Number.isFinite(scale) && scale > 0
29
+ ? size / scale : fallback;
30
+ };
26
31
  const seriesColor = (series, index) => {
27
32
  return series.color || DEFAULT_COLORS[index % DEFAULT_COLORS.length];
28
33
  };
@@ -151,8 +156,7 @@ const drawSeriesMarker = (documentRef, svg, series, color, x, y) => {
151
156
  }
152
157
  };
153
158
  const categoryLabels = (chart) => {
154
- var _a;
155
- const labels = ((_a = chart.series.find((series) => series.categories.length)) === null || _a === void 0 ? void 0 : _a.categories) || [];
159
+ const labels = chart.series.reduce((longest, series) => series.categories.length > longest.length ? series.categories : longest, []);
156
160
  const valueCount = chart.series.reduce((count, series) => Math.max(count, series.values.length), 0);
157
161
  return labels.length ? labels : Array.from({ length: valueCount }, (_, index) => `${index + 1}`);
158
162
  };
@@ -189,7 +193,7 @@ const createPlot = (chart) => {
189
193
  bottom
190
194
  };
191
195
  };
192
- const drawValueGrid = (documentRef, svg, plot, domain) => {
196
+ const drawValueGrid = (documentRef, svg, plot, domain, fontSize = 10) => {
193
197
  const tickCount = 5;
194
198
  for (let index = 0; index <= tickCount; index += 1) {
195
199
  const ratio = index / tickCount;
@@ -203,9 +207,9 @@ const drawValueGrid = (documentRef, svg, plot, domain) => {
203
207
  stroke: index === 0 ? '#9ca3af' : '#e5e7eb',
204
208
  'stroke-width': 1
205
209
  }));
206
- svg.appendChild(svgText(documentRef, Number.isInteger(value) ? `${value}` : value.toFixed(1), plot.left - 8, y + 4, {
210
+ svg.appendChild(svgText(documentRef, Number.isInteger(value) ? `${value}` : value.toFixed(1), plot.left - 8, y + fontSize / 3, {
207
211
  anchor: 'end',
208
- size: 10
212
+ size: fontSize
209
213
  }));
210
214
  }
211
215
  };
@@ -214,11 +218,13 @@ const drawCategoryLabels = (documentRef, svg, chart, plot, pointAxis = false) =>
214
218
  if (!categories.length) {
215
219
  return;
216
220
  }
217
- const categorySeries = chart.series.find((series) => series.categories.length);
218
- const sourcePointCount = Math.max((categorySeries === null || categorySeries === void 0 ? void 0 : categorySeries.sourcePointCount) || categories.length, categories.length);
221
+ const categorySeries = chart.series.find(series => series.categories === categories);
222
+ const sourcePointCount = Math.max(...chart.series.map(series => series.sourcePointCount || Math.max(series.values.length, series.categories.length)), categories.length);
219
223
  const step = plot.width / categories.length;
220
- categoryLabelIndexes(categories.length, plot.width).forEach((index) => {
224
+ const visible = categories.flatMap((label, i) => label ? [i] : []);
225
+ categoryLabelIndexes(visible.length, plot.width).forEach((visibleIndex) => {
221
226
  var _a, _b;
227
+ const index = visible[visibleIndex];
222
228
  const category = categories[index];
223
229
  const maxLength = categories.length > 8 ? 8 : 14;
224
230
  const label = category.length > maxLength ? `${category.slice(0, maxLength - 1)}…` : category;
@@ -228,7 +234,7 @@ const drawCategoryLabels = (documentRef, svg, chart, plot, pointAxis = false) =>
228
234
  : plot.left + (index + 0.5) * step;
229
235
  const labelElement = svgText(documentRef, label, x, plot.bottom + 17, {
230
236
  anchor: 'middle',
231
- size: 10
237
+ size: axisFontSize(chart, chart.categoryAxisFontSize, 10)
232
238
  });
233
239
  labelElement.classList.add('excel-chart-category-label');
234
240
  labelElement.dataset.categoryIndex = `${sourceIndex}`;
@@ -243,9 +249,11 @@ const drawColumnChart = (documentRef, svg, chart, plot) => {
243
249
  const seriesCount = Math.max(chart.series.length, 1);
244
250
  const slotWidth = (groupWidth * 0.76) / seriesCount;
245
251
  const zeroY = plot.bottom - ((0 - domain.min) / domain.span) * plot.height;
246
- drawValueGrid(documentRef, svg, plot, domain);
252
+ drawValueGrid(documentRef, svg, plot, domain, axisFontSize(chart, chart.valueAxisFontSize, 10));
247
253
  chart.series.forEach((series, seriesIndex) => {
248
254
  series.values.forEach((value, valueIndex) => {
255
+ if (!Number.isFinite(value))
256
+ return;
249
257
  const valueY = plot.bottom - ((value - domain.min) / domain.span) * plot.height;
250
258
  const x = plot.left + valueIndex * groupWidth + groupWidth * 0.12 + seriesIndex * slotWidth;
251
259
  const y = Math.min(zeroY, valueY);
@@ -287,6 +295,8 @@ const drawHorizontalBarChart = (documentRef, svg, chart, plot) => {
287
295
  }
288
296
  chart.series.forEach((series, seriesIndex) => {
289
297
  series.values.forEach((value, valueIndex) => {
298
+ if (!Number.isFinite(value))
299
+ return;
290
300
  const valueX = plot.left + ((value - domain.min) / domain.span) * plot.width;
291
301
  const y = plot.top + valueIndex * groupHeight + groupHeight * 0.12 + seriesIndex * slotHeight;
292
302
  svg.appendChild(svgElement(documentRef, 'rect', {
@@ -302,7 +312,7 @@ const drawHorizontalBarChart = (documentRef, svg, chart, plot) => {
302
312
  categories.forEach((category, index) => {
303
313
  svg.appendChild(svgText(documentRef, category, plot.left - 8, plot.top + (index + 0.5) * groupHeight + 4, {
304
314
  anchor: 'end',
305
- size: 10
315
+ size: axisFontSize(chart, chart.categoryAxisFontSize, 10)
306
316
  }));
307
317
  });
308
318
  };
@@ -310,30 +320,48 @@ const drawLineChart = (documentRef, svg, chart, plot, fillArea) => {
310
320
  const domain = valueDomain(chart);
311
321
  const count = Math.max(chart.series.reduce((pointCount, series) => Math.max(pointCount, series.sourcePointCount || series.values.length), 0), 1);
312
322
  const step = count > 1 ? plot.width / (count - 1) : plot.width;
313
- drawValueGrid(documentRef, svg, plot, domain);
323
+ drawValueGrid(documentRef, svg, plot, domain, axisFontSize(chart, chart.valueAxisFontSize, 10));
314
324
  chart.series.forEach((series, seriesIndex) => {
315
- const pointIndexes = extremaPointIndexes(series.values, Math.max(64, Math.floor(plot.width * MAX_LINE_POINTS_PER_PIXEL)));
316
- const points = pointIndexes.map((index) => {
317
- var _a, _b;
325
+ var _a, _b;
326
+ const pointIndexes = extremaPointIndexes(series.values, Math.max(64, Math.floor(plot.width * MAX_LINE_POINTS_PER_PIXEL)), series.spanBlankIndexes);
327
+ const spanning = new Set(series.spanBlankIndexes || []);
328
+ const segments = [];
329
+ let segment = [];
330
+ for (const index of pointIndexes) {
318
331
  const value = series.values[index];
332
+ if (!Number.isFinite(value)) {
333
+ if (spanning.has(index))
334
+ continue;
335
+ if (segment.length)
336
+ segments.push(segment);
337
+ segment = [];
338
+ continue;
339
+ }
319
340
  const sourceIndex = (_b = (_a = series.sourcePointIndexes) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : index;
320
- return {
341
+ segment.push({
321
342
  x: plot.left + (count > 1 ? sourceIndex * step : plot.width / 2),
322
343
  y: plot.bottom - ((value - domain.min) / domain.span) * plot.height
323
- };
324
- });
325
- if (!points.length) {
326
- return;
344
+ });
327
345
  }
328
- const pathData = points
329
- .map((point, index) => `${index ? 'L' : 'M'}${point.x},${point.y}`)
330
- .join(' ');
331
- if (fillArea && points.length > 1) {
332
- svg.appendChild(svgElement(documentRef, 'path', {
333
- d: `${pathData} L${points[points.length - 1].x},${plot.bottom} L${points[0].x},${plot.bottom} Z`,
334
- fill: seriesColor(series, seriesIndex),
335
- opacity: 0.2
336
- }));
346
+ if (segment.length)
347
+ segments.push(segment);
348
+ const points = segments.flat();
349
+ if (!points.length)
350
+ return;
351
+ const pathFor = (points) => points
352
+ .map((point, index) => `${index ? 'L' : 'M'}${point.x},${point.y}`).join(' ');
353
+ const pathData = segments.map(pathFor).join(' ');
354
+ if (fillArea) {
355
+ const zeroY = plot.bottom - ((0 - domain.min) / domain.span) * plot.height;
356
+ for (const points of segments) {
357
+ if (points.length < 2)
358
+ continue;
359
+ svg.appendChild(svgElement(documentRef, 'path', {
360
+ class: 'excel-chart-area',
361
+ d: `${pathFor(points)} L${points[points.length - 1].x},${zeroY} L${points[0].x},${zeroY} Z`,
362
+ fill: seriesColor(series, seriesIndex), opacity: 0.2
363
+ }));
364
+ }
337
365
  }
338
366
  const color = seriesColor(series, seriesIndex);
339
367
  const dashArray = seriesDashArray(series);
@@ -366,6 +394,16 @@ const polarPoint = (cx, cy, radius, angle) => {
366
394
  };
367
395
  };
368
396
  const pieSlicePath = (cx, cy, outerRadius, innerRadius, startAngle, endAngle) => {
397
+ if (endAngle - startAngle >= 360 - 1e-7) {
398
+ const a = polarPoint(cx, cy, outerRadius, startAngle);
399
+ const b = polarPoint(cx, cy, outerRadius, startAngle + 180);
400
+ const outer = `M${a.x},${a.y} A${outerRadius},${outerRadius} 0 1,0 ${b.x},${b.y} A${outerRadius},${outerRadius} 0 1,0 ${a.x},${a.y} Z`;
401
+ if (!innerRadius)
402
+ return outer;
403
+ const c = polarPoint(cx, cy, innerRadius, startAngle);
404
+ const d = polarPoint(cx, cy, innerRadius, startAngle + 180);
405
+ return `${outer} M${c.x},${c.y} A${innerRadius},${innerRadius} 0 1,1 ${d.x},${d.y} A${innerRadius},${innerRadius} 0 1,1 ${c.x},${c.y} Z`;
406
+ }
369
407
  const outerStart = polarPoint(cx, cy, outerRadius, endAngle);
370
408
  const outerEnd = polarPoint(cx, cy, outerRadius, startAngle);
371
409
  const largeArc = endAngle - startAngle > 180 ? 1 : 0;
@@ -380,13 +418,16 @@ const drawPieChart = (documentRef, svg, chart, doughnut) => {
380
418
  const series = chart.series[0];
381
419
  const values = (series === null || series === void 0 ? void 0 : series.values) || [];
382
420
  const categories = (series === null || series === void 0 ? void 0 : series.categories) || [];
383
- const total = values.reduce((sum, value) => sum + Math.max(0, value), 0) || 1;
421
+ const max = values.reduce((m, v) => Number.isFinite(v) ? Math.max(m, v) : m, 0) || 1;
422
+ const total = values.reduce((sum, value) => sum + (Number.isFinite(value) ? Math.max(0, value) / max : 0), 0) || 1;
384
423
  const cx = chart.legendPosition === 'right' ? 260 : 320;
385
424
  const cy = chart.title ? 180 : 170;
386
425
  const radius = 120;
387
426
  let angle = 0;
388
427
  values.forEach((value, index) => {
389
- const nextAngle = angle + (Math.max(0, value) / total) * 360;
428
+ if (!Number.isFinite(value) || value <= 0)
429
+ return;
430
+ const nextAngle = angle + (value / max / total) * 360;
390
431
  const color = DEFAULT_COLORS[index % DEFAULT_COLORS.length];
391
432
  const path = svgElement(documentRef, 'path', {
392
433
  d: pieSlicePath(cx, cy, radius, doughnut ? 62 : 0, angle, nextAngle),
@@ -1,2 +1,2 @@
1
1
  export declare const MAX_TRANSFERRED_LINE_CHART_POINTS = 4096;
2
- export declare const extremaPointIndexes: (values: number[], maxPoints: number) => number[];
2
+ export declare const extremaPointIndexes: (values: number[], maxPoints: number, spanBlankIndexes?: number[]) => number[];
@@ -1,25 +1,31 @@
1
1
  export const MAX_TRANSFERRED_LINE_CHART_POINTS = 4096;
2
- export const extremaPointIndexes = (values, maxPoints) => {
2
+ const sampleExtrema = (values, maxPoints) => {
3
3
  const pointLimit = Math.max(2, Math.floor(maxPoints));
4
4
  if (values.length <= pointLimit) {
5
5
  return values.map((_, index) => index);
6
6
  }
7
+ if (pointLimit < 4)
8
+ return [0, values.length - 1];
7
9
  const bucketCount = Math.max(1, Math.floor((pointLimit - 2) / 2));
8
10
  const bucketSize = (values.length - 2) / bucketCount;
9
11
  const result = [0];
10
12
  for (let bucket = 0; bucket < bucketCount; bucket += 1) {
11
13
  const start = Math.max(1, Math.floor(1 + bucket * bucketSize));
12
14
  const end = Math.min(values.length - 1, Math.ceil(1 + (bucket + 1) * bucketSize));
13
- let minIndex = start;
14
- let maxIndex = start;
15
- for (let index = start + 1; index < end; index += 1) {
16
- if (values[index] < values[minIndex]) {
15
+ let minIndex = -1;
16
+ let maxIndex = -1;
17
+ for (let index = start; index < end; index += 1) {
18
+ if (!Number.isFinite(values[index]))
19
+ continue;
20
+ if (minIndex < 0 || values[index] < values[minIndex]) {
17
21
  minIndex = index;
18
22
  }
19
- if (values[index] > values[maxIndex]) {
23
+ if (maxIndex < 0 || values[index] > values[maxIndex]) {
20
24
  maxIndex = index;
21
25
  }
22
26
  }
27
+ if (minIndex < 0)
28
+ continue;
23
29
  if (minIndex <= maxIndex) {
24
30
  result.push(minIndex, maxIndex);
25
31
  }
@@ -30,3 +36,37 @@ export const extremaPointIndexes = (values, maxPoints) => {
30
36
  result.push(values.length - 1);
31
37
  return Array.from(new Set(result));
32
38
  };
39
+ export const extremaPointIndexes = (values, maxPoints, spanBlankIndexes = []) => {
40
+ const limit = Math.max(2, Number.isFinite(maxPoints) ? Math.floor(maxPoints) : 2);
41
+ if (values.length <= limit)
42
+ return Array.from({ length: values.length }, (_, i) => i);
43
+ const hasGaps = values.some(value => !Number.isFinite(value));
44
+ if (!hasGaps)
45
+ return sampleExtrema(values, limit);
46
+ const spanning = new Set(spanBlankIndexes);
47
+ const hardGap = (index) => !Number.isFinite(values[index]) && !spanning.has(index);
48
+ if (limit === 2) {
49
+ const gap = values.findIndex((_, index) => hardGap(index));
50
+ return gap > 0 && gap < values.length - 1 ? [0, gap] : [0, values.length - 1];
51
+ }
52
+ const anchors = sampleExtrema(values, Math.max(2, Math.floor((limit + 1) / 2)));
53
+ const result = [anchors[0]];
54
+ for (let i = 1; i < anchors.length; i++) {
55
+ const left = anchors[i - 1], right = anchors[i];
56
+ if (!hardGap(left) && !hardGap(right)) {
57
+ let blank = -1;
58
+ for (let j = left + 1; j < right; j++) {
59
+ if (hardGap(j)) {
60
+ blank = j;
61
+ break;
62
+ }
63
+ if (blank < 0 && !Number.isFinite(values[j]))
64
+ blank = j;
65
+ }
66
+ if (blank >= 0)
67
+ result.push(blank);
68
+ }
69
+ result.push(right);
70
+ }
71
+ return result;
72
+ };
@@ -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
+ rowHeightOverrides: Map<number, number>;
58
59
  windowRows: Map<number, number[]>;
59
60
  windowCells: Map<number, string[]>;
60
61
  loadedWindows: Set<number>;
@@ -26,6 +26,7 @@ export const createEmptyVirtualState = () => ({
26
26
  mergeStartMap: new Map(),
27
27
  mergeCoveredMap: new Map(),
28
28
  rowHeightCache: new Map(),
29
+ rowHeightOverrides: new Map(),
29
30
  windowRows: new Map(),
30
31
  windowCells: new Map(),
31
32
  loadedWindows: new Set(),
@@ -64,8 +65,6 @@ export const getWindowStart = (row = 0, totalRows = 0) => {
64
65
  const start = Math.floor(Math.max(row, 0) / WINDOW_SIZE) * WINDOW_SIZE;
65
66
  return clampWindowStart(start, totalRows);
66
67
  };
67
- // 视口周边始终保留一小圈热窗口,滚轮滚动和拖动滚动条都可以直接命中缓存,
68
- // 避免每次跳转都同步等待 worker 回包。
69
68
  export const collectWindowStarts = ({ startRow, endRow, direction, totalRows, far = false }) => {
70
69
  const starts = new Set();
71
70
  const firstWindow = getWindowStart(startRow, totalRows);
@@ -235,12 +235,9 @@ 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
- // 只有完全缺失时才回退到默认行高,同时给极小值留一个最小可渲染下限。
240
238
  export const normalizeRowHeight = (height, fallback) => {
241
239
  if (typeof height === 'number' && Number.isFinite(height)) {
242
240
  if (height <= 0) {
243
- // e-virt-table 内部用 item._height || CELL_HEIGHT,0 会被误判为未设置。
244
241
  return HIDDEN_ROW_HEIGHT;
245
242
  }
246
243
  return Math.max(Math.ceil(height), MIN_RENDERABLE_ROW_HEIGHT);
@@ -257,8 +254,6 @@ const isPlainTextCell = (value) => {
257
254
  }
258
255
  return !/^\d+([./:-]\d+)*$/.test(text);
259
256
  };
260
- // 普通明细表通常会把第一行当成字段表头,而报表类工作表往往需要保留原始 Excel 行号。
261
- // 这里只在“首行像简单字段头且没有合并单元格”时,才给左侧序号做 1 行偏移。
262
257
  export const detectIndexOffset = (ws) => {
263
258
  const meta = ws.meta;
264
259
  const rows = ws.data || [];
@@ -345,7 +340,6 @@ const scaleColumn = (column, zoomScale) => {
345
340
  }
346
341
  return nextColumn;
347
342
  };
348
- // Excel 预览优先忠实还原原始列宽,不再为了“铺满容器”二次拉伸列宽。
349
343
  export const getDisplayColumns = (columns, zoomScale = 1) => {
350
344
  const normalizedScale = normalizeZoomScale(zoomScale);
351
345
  if (normalizedScale === 1) {
@@ -431,7 +425,6 @@ const shouldRenderTextInOverlay = (style, column) => {
431
425
  if (!hasTextLayout(style)) {
432
426
  return false;
433
427
  }
434
- // e-virt-table 的列级 align 可以交给 canvas;只有单元格级布局差异才用 DOM 覆盖层补齐。
435
428
  return !!((style === null || style === void 0 ? void 0 : style.wrapText) ||
436
429
  (style === null || style === void 0 ? void 0 : style.shrinkToFit) ||
437
430
  ((style === null || style === void 0 ? void 0 : style.horizontalAlign) && style.horizontalAlign !== ((column === null || column === void 0 ? void 0 : column.align) || 'left')) ||
@@ -782,8 +775,6 @@ const applyOverflowLayout = (text, overflowLayout) => {
782
775
  textOverflow: 'clip'
783
776
  });
784
777
  };
785
- // e-virt-table 的普通样式接口不支持 Excel 式四边边框和单元格级换行/垂直对齐,
786
- // 这里借助官方的 BODY_CELL_RENDER_METHOD,只在可视区补轻量 DOM 覆盖层。
787
778
  const renderCellOverlay = (cellEl, borderStyle, textStyle, textValue, renderText, overflowLayout, zoomScale) => {
788
779
  const documentRef = cellEl.ownerDocument;
789
780
  cellEl.replaceChildren();
@@ -1045,8 +1036,6 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
1045
1036
  RESIZE_ROW_LINE_COLOR: EXCEL_GREEN,
1046
1037
  RESIZE_ROW_MIN_HEIGHT: scaleNumber(RESIZABLE_ROW_MIN_HEIGHT, normalizedScale),
1047
1038
  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.
1050
1039
  ENABLE_FINDER: false,
1051
1040
  ENABLE_COPY: true,
1052
1041
  BEFORE_COPY_METHOD: copySelection
@@ -1055,7 +1044,6 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
1055
1044
  return undefined;
1056
1045
  }
1057
1046
  : undefined,
1058
- // 预览态只开放“拖动扩选”的交互,不允许真正写回单元格内容。
1059
1047
  BEFORE_AUTOFILL_DATA_METHOD: () => [],
1060
1048
  SPAN_METHOD: spanMethod,
1061
1049
  HEADER_CELL_STYLE_METHOD: headerStyleMethod,
@@ -0,0 +1,13 @@
1
+ import type { Column } from 'e-virt-table';
2
+ import { type VirtualRow, type VirtualSheetState } from './state.js';
3
+ export declare const shouldFillSpreadsheetViewport: (enabled: boolean | undefined, type?: string) => boolean;
4
+ export declare class SpreadsheetViewportFill {
5
+ private sourceRows?;
6
+ private rows;
7
+ private sourceColumns?;
8
+ private columns;
9
+ build(state: VirtualSheetState, width: number, height: number, zoom: number): {
10
+ rows: VirtualRow[];
11
+ columns: Column[];
12
+ };
13
+ }
@@ -0,0 +1,58 @@
1
+ import { getDataKey, ROW_KEY_FIELD, ROW_STATE_FIELD, RowState } from './state.js';
2
+ import { getDisplayColumns, HEADER_HEIGHT, normalizeRowHeight } from './view.js';
3
+ const EXCEL_FORMATS = new Set(['xlsx', 'xltx', 'xlsm', 'xltm', 'xlsb', 'xls', 'xlt']);
4
+ export const shouldFillSpreadsheetViewport = (enabled, type = '') => (enabled === true && EXCEL_FORMATS.has(type.toLowerCase().replace(/^\./, '')));
5
+ const columnLabel = (index) => {
6
+ let value = index + 1;
7
+ let label = '';
8
+ while (value > 0) {
9
+ value -= 1;
10
+ label = String.fromCharCode(65 + value % 26) + label;
11
+ value = Math.floor(value / 26);
12
+ }
13
+ return label;
14
+ };
15
+ export class SpreadsheetViewportFill {
16
+ constructor() {
17
+ this.rows = [];
18
+ this.columns = [];
19
+ }
20
+ build(state, width, height, zoom) {
21
+ const scale = (value) => Math.max(1, Math.round(value * zoom));
22
+ const rowHeight = scale(normalizeRowHeight(state.defaults.rowHeight, state.defaults.rowHeight));
23
+ const columnWidth = Math.max(1, Math.ceil(state.defaults.colWidth));
24
+ let contentHeight = scale(HEADER_HEIGHT) + state.totalRows * rowHeight;
25
+ state.rowHeightCache.forEach((value, index) => {
26
+ if (index < state.totalRows)
27
+ contentHeight += Math.max(0.1, Math.round(value * zoom)) - rowHeight;
28
+ });
29
+ const contentWidth = getDisplayColumns(state.columns, zoom).reduce((sum, column) => (sum + (column.hide ? 0 : Number(column.width) || 0)), 0);
30
+ const extraRows = Math.min(Math.max(0, 1048576 - state.totalRows), Math.max(0, Math.ceil((height - contentHeight) / rowHeight)));
31
+ const extraColumns = Math.min(Math.max(0, 16384 - state.totalCols), Math.max(0, Math.ceil((width - contentWidth) / scale(columnWidth))));
32
+ if (this.sourceRows !== state.rows || this.rows.length !== state.rows.length + extraRows) {
33
+ this.sourceRows = state.rows;
34
+ this.rows = extraRows ? state.rows.concat(Array.from({ length: extraRows }, (_, offset) => ({
35
+ [ROW_KEY_FIELD]: `viewport-${state.totalRows + offset}`,
36
+ [ROW_STATE_FIELD]: RowState.Loaded,
37
+ }))) : state.rows;
38
+ }
39
+ if (this.sourceColumns !== state.columns || this.columns.length !== state.columns.length + extraColumns) {
40
+ this.sourceColumns = state.columns;
41
+ this.columns = extraColumns ? state.columns.concat(Array.from({ length: extraColumns }, (_, offset) => ({
42
+ key: getDataKey(state.totalCols + offset),
43
+ title: columnLabel(state.totalCols + offset),
44
+ width: columnWidth,
45
+ minWidth: columnWidth,
46
+ maxWidth: columnWidth,
47
+ widthFillDisable: true,
48
+ headerAlign: 'center',
49
+ headerVerticalAlign: 'middle',
50
+ align: 'left',
51
+ verticalAlign: 'middle',
52
+ }))) : state.columns;
53
+ }
54
+ for (let index = state.totalRows; index < this.rows.length; index += 1)
55
+ this.rows[index]._height = rowHeight;
56
+ return { rows: this.rows, columns: this.columns };
57
+ }
58
+ }
@@ -87,7 +87,6 @@ const getColumnPixelWidth = (column) => {
87
87
  if (column.hidden) {
88
88
  return 0;
89
89
  }
90
- // styled-exceljs 在 browserPixels 模式下会优先输出 wpx,这是最接近浏览器渲染的列宽。
91
90
  const wpx = toFiniteNumber(column.wpx);
92
91
  if (wpx !== undefined && wpx >= 0) {
93
92
  return Math.ceil(wpx);
@@ -230,8 +229,6 @@ const isAutomaticPaletteColor = (color) => {
230
229
  return indexed === 32767;
231
230
  };
232
231
  const normalizeFontColor = (color) => {
233
- // BIFF/XLS 会把“自动字体色”解析成 indexed 32767,部分文件还会附带
234
- // FFFFFF 的 rgb 值。Excel 实际显示为默认黑色,不能当成显式白色。
235
232
  if (isAutomaticPaletteColor(color)) {
236
233
  return EXCEL_DEFAULT_TEXT_COLOR;
237
234
  }
@@ -520,6 +517,8 @@ class SheetJsModel {
520
517
  title: chart.title,
521
518
  categoryAxisTitle: chart.categoryAxisTitle,
522
519
  valueAxisTitle: chart.valueAxisTitle,
520
+ categoryAxisFontSize: chart.categoryAxisFontSize,
521
+ valueAxisFontSize: chart.valueAxisFontSize,
523
522
  barDirection: chart.barDirection,
524
523
  grouping: chart.grouping,
525
524
  scatterStyle: chart.scatterStyle,
@@ -616,7 +615,6 @@ class SheetJsModel {
616
615
  }
617
616
  return heights.length ? heights : rowHeight;
618
617
  }
619
- // 整表行高必须按绝对行号下发,否则拖动滚动条时隐藏行和特殊行高会造成高度跳变。
620
618
  getAllRowHeights() {
621
619
  const { '!rows': rows = [] } = this.ws;
622
620
  const heights = [];
@@ -640,8 +638,6 @@ class SheetJsModel {
640
638
  const sampleRanges = this.getAutoFitSampleRanges();
641
639
  const fittedColumns = [];
642
640
  for (const range of sampleRanges) {
643
- // 自动列宽只作为缺失列宽的兜底。合并标题和 Excel 溢出文本不应该反向撑开基础列宽。
644
- // 大表只抽样固定数量的单元格,避免为了首屏列宽扫描整张工作表。
645
641
  const measuredColumns = autoFitColumns(this.ws, {
646
642
  range,
647
643
  set: false,
@@ -684,13 +680,9 @@ class SheetJsModel {
684
680
  if (hasColumnWidth(sourceColumn)) {
685
681
  return sourceColumn;
686
682
  }
687
- // A drawing anchor is measured against the workbook's stored/default
688
- // column geometry. Auto-fitting blank columns to 24px changes that
689
- // coordinate system and makes two-cell images visibly smaller than Excel.
690
683
  if (this.hasAnchoredObjects) {
691
684
  return sourceColumn;
692
685
  }
693
- // 没有显式列宽时,再使用 styled-exceljs 的内容测量兜底,避免报表类标题污染原始宽度。
694
686
  return ((_a = this.autoFitColumns) === null || _a === void 0 ? void 0 : _a[colIndex]) || sourceColumn;
695
687
  }
696
688
  get hasAnchoredObjects() {