@file-viewer/renderer-spreadsheet 3.3.1 → 3.3.3

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.
@@ -24,9 +24,6 @@ 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.
30
27
  const axisFontSize = (chart, size, fallback) => {
31
28
  const scale = Math.min(chart.width / 640, chart.height / 360);
32
29
  return size !== undefined && Number.isFinite(size) && size > 0 && Number.isFinite(scale) && scale > 0
@@ -398,7 +395,6 @@ const polarPoint = (cx, cy, radius, angle) => {
398
395
  };
399
396
  };
400
397
  const pieSlicePath = (cx, cy, outerRadius, innerRadius, startAngle, endAngle) => {
401
- // A single SVG arc with identical endpoints is empty, not a full circle.
402
398
  if (endAngle - startAngle >= 360 - 1e-7) {
403
399
  const a = polarPoint(cx, cy, outerRadius, startAngle);
404
400
  const b = polarPoint(cx, cy, outerRadius, startAngle + 180);
@@ -453,7 +449,6 @@ const drawLegend = (documentRef, svg, chart) => {
453
449
  }
454
450
  const right = chart.legendPosition === 'right';
455
451
  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.
457
452
  const entries = chart.type === 'pie' || chart.type === 'doughnut'
458
453
  ? ((categorySeries === null || categorySeries === void 0 ? void 0 : categorySeries.values) || []).slice(0, MAX_LEGEND_ITEMS).map((_, index) => ({
459
454
  ...categorySeries,
@@ -1,6 +1,2 @@
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
- */
6
2
  export declare const extremaPointIndexes: (values: number[], maxPoints: number, spanBlankIndexes?: number[]) => number[];
@@ -36,10 +36,6 @@ 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
- */
43
39
  export const extremaPointIndexes = (values, maxPoints, spanBlankIndexes = []) => {
44
40
  const limit = Math.max(2, Number.isFinite(maxPoints) ? Math.floor(maxPoints) : 2);
45
41
  if (values.length <= limit)
@@ -50,8 +46,6 @@ export const extremaPointIndexes = (values, maxPoints, spanBlankIndexes = []) =>
50
46
  const spanning = new Set(spanBlankIndexes);
51
47
  const hardGap = (index) => !Number.isFinite(values[index]) && !spanning.has(index);
52
48
  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.
55
49
  const gap = values.findIndex((_, index) => hardGap(index));
56
50
  return gap > 0 && gap < values.length - 1 ? [0, gap] : [0, values.length - 1];
57
51
  }
@@ -10,13 +10,11 @@ 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. */
14
13
  export declare const createSpreadsheetRangeNavigation: (options: Options) => {
15
14
  provider: FileViewerViewStateProvider;
16
15
  cancel: (result?: "cancelled" | "failed" | "disposed") => void;
17
16
  notify: (action: FileViewerViewStateChange["action"], source?: FileViewerViewStateChange["source"], notify?: boolean) => void;
18
17
  isPending: () => boolean;
19
- /** Called after the target virtual window loads, before drawing the highlight. */
20
18
  prepare(totalRows: number, totalCols: number): (() => void) | null;
21
19
  contains(sheetId: number, row: number, col: number): boolean;
22
20
  };
@@ -14,7 +14,6 @@ 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. */
18
17
  export const createSpreadsheetRangeNavigation = (options) => {
19
18
  let stopped;
20
19
  let status = 'idle';
@@ -53,7 +52,6 @@ export const createSpreadsheetRangeNavigation = (options) => {
53
52
  }
54
53
  };
55
54
  const cancel = (result = 'cancelled') => {
56
- // Disposal is terminal, including when a late parser rejection arrives.
57
55
  if (stopped === 'disposed')
58
56
  return;
59
57
  const hadHighlight = !!highlighted;
@@ -68,7 +66,6 @@ export const createSpreadsheetRangeNavigation = (options) => {
68
66
  if (result === 'disposed')
69
67
  listeners.clear();
70
68
  };
71
- // Consume failure even when no API request was made before parsing failed.
72
69
  void options.ready.catch(() => { if (!stopped)
73
70
  cancel('failed'); });
74
71
  const provider = {
@@ -143,7 +140,6 @@ export const createSpreadsheetRangeNavigation = (options) => {
143
140
  return {
144
141
  provider, cancel, notify: emit,
145
142
  isPending: () => !!(pending === null || pending === void 0 ? void 0 : pending.range),
146
- /** Called after the target virtual window loads, before drawing the highlight. */
147
143
  prepare(totalRows, totalCols) {
148
144
  const request = pending;
149
145
  if (!(request === null || request === void 0 ? void 0 : request.range))
@@ -55,7 +55,6 @@ 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. */
59
58
  rowHeightOverrides: Map<number, number>;
60
59
  windowRows: Map<number, number[]>;
61
60
  windowCells: Map<number, string[]>;
@@ -65,8 +65,6 @@ 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 回包。
70
68
  export const collectWindowStarts = ({ startRow, endRow, direction, totalRows, far = false }) => {
71
69
  const starts = new Set();
72
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,
@@ -1,7 +1,6 @@
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. */
5
4
  export declare class SpreadsheetViewportFill {
6
5
  private sourceRows?;
7
6
  private rows;
@@ -12,7 +12,6 @@ const columnLabel = (index) => {
12
12
  }
13
13
  return label;
14
14
  };
15
- /** Display-only padding. The parser's dimensions, rows and columns stay authoritative. */
16
15
  export class SpreadsheetViewportFill {
17
16
  constructor() {
18
17
  this.rows = [];
@@ -52,7 +51,6 @@ export class SpreadsheetViewportFill {
52
51
  verticalAlign: 'middle',
53
52
  }))) : state.columns;
54
53
  }
55
- // Blank rows use default metrics even when the host allows resizing data rows.
56
54
  for (let index = state.totalRows; index < this.rows.length; index += 1)
57
55
  this.rows[index]._height = rowHeight;
58
56
  return { rows: this.rows, columns: this.columns };
@@ -43,8 +43,6 @@ const toFiniteNumber = (value) => {
43
43
  return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
44
44
  };
45
45
  const getDefaultColumnWidth = () => {
46
- // Excel's displayed default is 8.43 characters plus five pixels of padding,
47
- // not an already encoded OOXML <col width> value.
48
46
  return Math.floor(EXCEL_DEFAULT_COLUMN_WIDTH * 7 + 5);
49
47
  };
50
48
  const getDefaultRowHeight = () => {
@@ -90,7 +88,6 @@ const getColumnPixelWidth = (column, maximumDigitWidth = 7) => {
90
88
  if (maximumDigitWidth !== 7 && storedWidth !== undefined && storedWidth >= 0) {
91
89
  return Math.trunc(((256 * storedWidth + Math.trunc(128 / maximumDigitWidth)) / 256) * maximumDigitWidth);
92
90
  }
93
- // styled-exceljs 在 browserPixels 模式下会优先输出 wpx,这是最接近浏览器渲染的列宽。
94
91
  const wpx = toFiniteNumber(column.wpx);
95
92
  if (wpx !== undefined && wpx >= 0) {
96
93
  return Math.ceil(wpx);
@@ -145,8 +142,6 @@ const getRowPixelHeight = (rowMeta) => {
145
142
  if (rowMeta.hidden) {
146
143
  return 0;
147
144
  }
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.
150
145
  const hpt = toFiniteNumber(rowMeta.hpt);
151
146
  if (hpt !== undefined && hpt >= 0) {
152
147
  const converter = utils.row_height_to_px;
@@ -235,8 +230,6 @@ const isAutomaticPaletteColor = (color) => {
235
230
  return indexed === 32767;
236
231
  };
237
232
  const normalizeFontColor = (color) => {
238
- // BIFF/XLS 会把“自动字体色”解析成 indexed 32767,部分文件还会附带
239
- // FFFFFF 的 rgb 值。Excel 实际显示为默认黑色,不能当成显式白色。
240
233
  if (isAutomaticPaletteColor(color)) {
241
234
  return EXCEL_DEFAULT_TEXT_COLOR;
242
235
  }
@@ -322,7 +315,6 @@ const getCellStyle = (cellStyle) => {
322
315
  }
323
316
  const fontSize = Number(font.sz || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.sz));
324
317
  if (Number.isFinite(fontSize) && fontSize > 0) {
325
- // Excel 字号以 pt 存储;模型统一输出 CSS px,视图层再单独应用缩放。
326
318
  style.fontSize = `${fontSize * 96 / 72}px`;
327
319
  }
328
320
  const fontName = font.name || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.name);
@@ -631,7 +623,6 @@ class SheetJsModel {
631
623
  }
632
624
  return heights.length ? heights : rowHeight;
633
625
  }
634
- // 整表行高必须按绝对行号下发,否则拖动滚动条时隐藏行和特殊行高会造成高度跳变。
635
626
  getAllRowHeights() {
636
627
  const { '!rows': rows = [] } = this.ws;
637
628
  const heights = [];
@@ -655,8 +646,6 @@ class SheetJsModel {
655
646
  const sampleRanges = this.getAutoFitSampleRanges();
656
647
  const fittedColumns = [];
657
648
  for (const range of sampleRanges) {
658
- // 自动列宽只作为缺失列宽的兜底。合并标题和 Excel 溢出文本不应该反向撑开基础列宽。
659
- // 大表只抽样固定数量的单元格,避免为了首屏列宽扫描整张工作表。
660
649
  const measuredColumns = autoFitColumns(this.ws, {
661
650
  range,
662
651
  set: false,
@@ -699,13 +688,9 @@ class SheetJsModel {
699
688
  if (hasColumnWidth(sourceColumn)) {
700
689
  return sourceColumn;
701
690
  }
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
691
  if (this.hasAnchoredObjects || this.ws['!fileViewerLayout']) {
706
692
  return sourceColumn;
707
693
  }
708
- // 没有显式列宽时,再使用 styled-exceljs 的内容测量兜底,避免报表类标题污染原始宽度。
709
694
  return ((_a = this.autoFitColumns) === null || _a === void 0 ? void 0 : _a[colIndex]) || sourceColumn;
710
695
  }
711
696
  get hasAnchoredObjects() {
@@ -6,7 +6,6 @@ const CHART_RELATIONSHIP_SUFFIX = '/chart';
6
6
  const DRAWING_RELATIONSHIP_SUFFIX = '/drawing';
7
7
  const WORKSHEET_RELATIONSHIP_SUFFIX = '/worksheet';
8
8
  const EMUS_PER_CSS_PIXEL = 9525;
9
- // Bound cache indices and formula expansion before allocating producer-controlled arrays.
10
9
  const MAX_CHART_POINTS = 1048576;
11
10
  const CHART_TYPE_MAP = {
12
11
  areaChart: 'area',
@@ -117,9 +116,6 @@ const relationshipPartPath = (sourcePart) => {
117
116
  return `${directory ? `${directory}/` : ''}_rels/${filename}.rels`;
118
117
  };
119
118
  const parseXml = (xml) => {
120
- // Some valid Office producers prefix relationship parts with a UTF-8 BOM.
121
- // XML declarations must otherwise be the first character, and xmldom reports
122
- // the BOM as content outside the root element before aborting chart parsing.
123
119
  return new DOMParser().parseFromString(xml.replace(/^[\uFEFF\s]+/, ''), 'application/xml');
124
120
  };
125
121
  export const loadXml = async (zip, path) => {
@@ -251,8 +247,6 @@ const parsePointValues = (element, workbook, formatted = true) => {
251
247
  if (!element) {
252
248
  return [];
253
249
  }
254
- // Cache point idx is a logical source position, not the point's XML order.
255
- // Select one cache/level; flattening nested caches mixes category hierarchies.
256
250
  const literal = firstChildByLocal(element, 'strLit') || firstChildByLocal(element, 'numLit');
257
251
  const reference = firstChildByLocal(element, 'strRef') || firstChildByLocal(element, 'numRef');
258
252
  const multiLevel = firstChildByLocal(firstChildByLocal(element, 'multiLvlStrRef'), 'multiLvlStrCache');
@@ -278,9 +272,6 @@ const parsePointValues = (element, workbook, formatted = true) => {
278
272
  const values = Array(count).fill('');
279
273
  for (const point of entries)
280
274
  values[point.index] = point.value;
281
- // A declared domain with missing points is an intentional sparse cache.
282
- // A zero-length reference cache supplies no domain; Office producers use
283
- // it as a placeholder until Excel recalculates the worksheet formula.
284
275
  if (count || literal || !reference)
285
276
  return values;
286
277
  }
@@ -358,8 +349,6 @@ const parseSeries = (chartNode, workbook, blankMode = 'gap') => {
358
349
  spanBlankIndexes.push(pointIndex);
359
350
  return blankMode === 'zero' ? 0 : Number.NaN;
360
351
  }
361
- // Empty cells and error values are not zero. Keep an error as a hard gap,
362
- // even when blank cells are explicitly spanned or plotted as zero.
363
352
  const number = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(raw) ? Number(raw) : NaN;
364
353
  return Number.isFinite(number) ? number : Number.NaN;
365
354
  });
@@ -392,7 +381,6 @@ const parseSeries = (chartNode, workbook, blankMode = 'gap') => {
392
381
  };
393
382
  });
394
383
  };
395
- /** DrawingML font sizes are hundredths of a point, not SVG viewport units. */
396
384
  const parseAxisFontSize = (axis, chartSpace) => {
397
385
  var _a;
398
386
  const size = (node) => {
@@ -500,8 +488,6 @@ export const parseSpreadsheetCharts = async (data, workbook) => {
500
488
  if (!name || !(worksheetRelationship === null || worksheetRelationship === void 0 ? void 0 : worksheetRelationship.type.endsWith(WORKSHEET_RELATIONSHIP_SUFFIX))) {
501
489
  continue;
502
490
  }
503
- // A missing <col> uses the worksheet's stored/default geometry, rather
504
- // than content auto-fit. Keep this metadata even when there are no charts.
505
491
  const worksheet = (_a = workbook === null || workbook === void 0 ? void 0 : workbook.Sheets) === null || _a === void 0 ? void 0 : _a[name];
506
492
  if (worksheet) {
507
493
  worksheet['!fileViewerLayout'] = {};
@@ -510,11 +496,6 @@ export const parseSpreadsheetCharts = async (data, workbook) => {
510
496
  maximumDigitWidth
511
497
  };
512
498
  }
513
- // A worksheet can expand to hundreds of megabytes even when the drawing
514
- // relationship part is only a few hundred bytes. Loading sheetN.xml as a
515
- // string here duplicates the cell parser's work and can exceed V8's string
516
- // limit before chart parsing starts. Drawing relationships already carry
517
- // the typed targets needed by the chart parser, so discover them directly.
518
499
  const worksheetRelationships = await loadRelationships(zip, worksheetRelationship.target);
519
500
  const drawingParts = Array.from(new Set(worksheetRelationships
520
501
  .filter((relationship) => relationship.type.endsWith(DRAWING_RELATIONSHIP_SUFFIX))
@@ -1,17 +1,16 @@
1
1
  import tinycolor from 'tinycolor2';
2
2
  export const indexedColors = [
3
- 'FF000000', 'FFFFFFFF', 'FFFF0000', 'FF00FF00', 'FF0000FF', 'FFFFFF00', 'FFFF00FF', 'FF00FFFF', // 0-7
4
- 'FF000000', 'FFFFFFFF', 'FFFF0000', 'FF00FF00', 'FF0000FF', 'FFFFFF00', 'FFFF00FF', 'FF00FFFF', // 8-15
5
- 'FF800000', 'FF008000', 'FF000080', 'FF808000', 'FF800080', 'FF008080', 'FFC0C0C0', 'FF808080', // 16-23
6
- 'FF9999FF', 'FF993366', 'FFFFFFCC', 'FFCCFFFF', 'FF660066', 'FFFF8080', 'FF0066CC', 'FFCCCCFF', // 24-31
7
- 'FF000080', 'FFFF00FF', 'FFFFFF00', 'FF00FFFF', 'FF800080', 'FF800000', 'FF008080', 'FF0000FF', // 32-39
8
- 'FF00CCFF', 'FFCCFFFF', 'FFCCFFCC', 'FFFFFF99', 'FF99CCFF', 'FFFF99CC', 'FFCC99FF', 'FFFFCC99', // 40-47
9
- 'FF3366FF', 'FF33CCCC', 'FF99CC00', 'FFFFCC00', 'FFFF9900', 'FFFF6600', 'FF666699', 'FF969696', // 48-55
10
- 'FF003366', 'FF339966', 'FF003300', 'FF333300', 'FF993300', 'FF993366', 'FF333399', 'FF333333' // 56-63
3
+ 'FF000000', 'FFFFFFFF', 'FFFF0000', 'FF00FF00', 'FF0000FF', 'FFFFFF00', 'FFFF00FF', 'FF00FFFF',
4
+ 'FF000000', 'FFFFFFFF', 'FFFF0000', 'FF00FF00', 'FF0000FF', 'FFFFFF00', 'FFFF00FF', 'FF00FFFF',
5
+ 'FF800000', 'FF008000', 'FF000080', 'FF808000', 'FF800080', 'FF008080', 'FFC0C0C0', 'FF808080',
6
+ 'FF9999FF', 'FF993366', 'FFFFFFCC', 'FFCCFFFF', 'FF660066', 'FFFF8080', 'FF0066CC', 'FFCCCCFF',
7
+ 'FF000080', 'FFFF00FF', 'FFFFFF00', 'FF00FFFF', 'FF800080', 'FF800000', 'FF008080', 'FF0000FF',
8
+ 'FF00CCFF', 'FFCCFFFF', 'FFCCFFCC', 'FFFFFF99', 'FF99CCFF', 'FFFF99CC', 'FFCC99FF', 'FFFFCC99',
9
+ 'FF3366FF', 'FF33CCCC', 'FF99CC00', 'FFFFCC00', 'FFFF9900', 'FFFF6600', 'FF666699', 'FF969696',
10
+ 'FF003366', 'FF339966', 'FF003300', 'FF333300', 'FF993300', 'FF993366', 'FF333399', 'FF333333'
11
11
  ];
12
12
  const HLSMAX = 240;
13
13
  const RGBMAX = 0xFF;
14
- // Excel 主题色的 tint 计算使用微软 HLS 取值范围,和浏览器 HSL 不是同一套刻度。
15
14
  function rgb2hls(r, g, b) {
16
15
  const maxc = Math.max(r, g, b);
17
16
  const minc = Math.min(r, g, b);
@@ -63,7 +62,6 @@ function tintLuminance(tint, lum) {
63
62
  }
64
63
  return Math.round(lum * (1.0 - tint) + (HLSMAX - HLSMAX * (1.0 - tint)));
65
64
  }
66
- // 根据主题原始色和 tint 还原 Excel 实际显示色。
67
65
  export function getTintColor(hex, tint) {
68
66
  if (!hex) {
69
67
  return hex;
@@ -79,7 +79,6 @@ class FormulaParser {
79
79
  };
80
80
  while (((_a = precedence[this.current().kind]) !== null && _a !== void 0 ? _a : -1) >= minimum) {
81
81
  const op = this.tokens[this.index++].kind;
82
- // Excel exponentiation is left associative.
83
82
  left = { kind: 'binary', op, left, right: this.expression(precedence[op] + 1) };
84
83
  }
85
84
  this.depth--;
@@ -163,8 +162,6 @@ const numeric = (value) => {
163
162
  return 0;
164
163
  if (typeof value === 'boolean')
165
164
  return value ? 1 : 0;
166
- // Blank cells use null. Empty strings and JavaScript-only hexadecimal text
167
- // are not Excel arithmetic numbers and must not silently become 0 or 16.
168
165
  if (typeof value === 'string' &&
169
166
  !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?$/.test(value.trim()))
170
167
  return unavailable();
@@ -292,8 +289,6 @@ export function recoverUncachedFormulaValues(workbook) {
292
289
  if (node.op === '&')
293
290
  return textValue(left) + textValue(right);
294
291
  if (['=', '<>', '<', '>', '<=', '>='].includes(node.op)) {
295
- // Excel compares text without case sensitivity. Different value types
296
- // are ordered number < text < logical; empty cells take the other type.
297
292
  const normalize = (value, other) => value === null
298
293
  ? typeof other === 'string'
299
294
  ? ''
@@ -321,7 +316,6 @@ export function recoverUncachedFormulaValues(workbook) {
321
316
  const a = numeric(left), b = numeric(right);
322
317
  if (node.op === '/' && b === 0)
323
318
  return unavailable();
324
- // Office POWER(0,0) is an error, unlike JavaScript's finite result1.
325
319
  if (node.op === '^' && a === 0 && b === 0)
326
320
  return unavailable();
327
321
  const value = node.op === '+'
@@ -391,7 +385,6 @@ export function recoverUncachedFormulaValues(workbook) {
391
385
  readCell(name, row, col, 0);
392
386
  }
393
387
  catch {
394
- /* keep the original formula visible */
395
388
  }
396
389
  }
397
390
  for (const { cells } of sheets.values())
@@ -402,13 +395,11 @@ export function recoverUncachedFormulaValues(workbook) {
402
395
  const value = (_a = results.get(cell)) !== null && _a !== void 0 ? _a : 0;
403
396
  cell.v = value;
404
397
  cell.t = typeof value === 'boolean' ? 'b' : typeof value === 'string' ? 's' : 'n';
405
- // The parser may have produced w="0" for an empty cached value.
406
398
  delete cell.w;
407
399
  try {
408
400
  cell.w = utils.format_cell(cell);
409
401
  }
410
402
  catch {
411
- /* plain value is still available */
412
403
  }
413
404
  calculated++;
414
405
  }
@@ -23,7 +23,6 @@ export interface SpreadsheetParserContext {
23
23
  cellImages: Record<string, SheetCellImage[]>;
24
24
  }
25
25
  export interface SpreadsheetWorkbookSource extends SpreadsheetTextSource {
26
- /** Retain truly empty sheets only for the opt-in Excel viewport grid. */
27
26
  includeEmptySheets?: boolean;
28
27
  }
29
28
  export interface SpreadsheetWorkerRequest {
@@ -12,7 +12,6 @@ const readOptions = {
12
12
  browserPixels: true,
13
13
  drawings: true,
14
14
  };
15
- // HTML/XML 文件必须传入 type: 'string' 保持原有的 HTML 单元格解析结果
16
15
  const prefersSheetJsTextSniff = (text) => /^[\s\uFEFF]*</.test(text);
17
16
  const isMergeValidationError = (error) => (error instanceof Error
18
17
  && typeof error.code === 'string'
@@ -79,14 +78,7 @@ const sanitizeToleratedMerges = (workbook) => {
79
78
  });
80
79
  }
81
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'
81
+ const readPreparedWorkbook = (input, validateMerges) => (input.kind === 'text'
90
82
  ? read(input.data, { ...readOptions, type: prefersSheetJsTextSniff(input.data) ? 'string' : 'binary', validateMerges })
91
83
  : read(input.data, { ...readOptions, validateMerges }));
92
84
  const readWorkbookWithMergeRecovery = (input) => {
@@ -157,24 +149,15 @@ const EMPTY_RANGE_COLUMN_LIMIT = 256;
157
149
  const RANGE_ROW_SLACK = 256;
158
150
  const RANGE_COLUMN_SLACK = 64;
159
151
  const RANGE_GROWTH_FACTOR = 4;
160
- /** Drop sparse far outliers once the gap dwarfs the dense cluster near A1. */
161
152
  const CONTENT_GAP_ROW_MULTIPLIER = 4;
162
153
  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
154
  const compactSparseExtent = (indices, slack, gapMultiplier, contentExtent) => {
169
155
  if (indices.length === 0)
170
156
  return 0;
171
157
  const sorted = [...new Set(indices)].sort((a, b) => a - b);
172
158
  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
159
  if (!contentExtent && sorted[0] > originThreshold)
175
160
  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
161
  let end = Math.max(sorted[0], contentExtent - 1);
179
162
  for (let i = 1; i < sorted.length; i += 1) {
180
163
  const current = sorted[i];
@@ -201,8 +184,6 @@ const getCellBounds = (worksheet) => {
201
184
  rowIndices.push(row);
202
185
  colIndices.push(col);
203
186
  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
187
  const meaningful = typeof value !== 'object' || cell.v != null || cell.f != null
207
188
  || cell.F != null || !!cell.w || !!cell.r || !!cell.h || !!cell.l
208
189
  || (Array.isArray(cell.c) && cell.c.length > 0);
@@ -237,7 +218,6 @@ const getCellBounds = (worksheet) => {
237
218
  observe(cell.r, cell.c, worksheet[key]);
238
219
  }
239
220
  catch {
240
- // Ignore non-cell extension keys exposed by third-party workbook producers.
241
221
  }
242
222
  }
243
223
  }
@@ -276,7 +256,6 @@ export const getWorksheetDisplayBounds = (worksheet, charts) => {
276
256
  declaredColCount = range.e.c + 1;
277
257
  }
278
258
  catch {
279
- // Invalid producer dimensions must not block content-based recovery.
280
259
  }
281
260
  }
282
261
  const cellBounds = getCellBounds(worksheet);
@@ -385,8 +364,6 @@ export const parseSpreadsheetSheet = (context, payload = {}) => {
385
364
  charts: context.charts[sheetName],
386
365
  cellImages: context.cellImages[sheetName],
387
366
  });
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.
390
367
  const windowData = sheetModel.toObject({ includeLayout: startRow === 0 });
391
368
  const structure = startRow === 0 ? sheetModel.structure : undefined;
392
369
  return [{
@@ -135,8 +135,6 @@ 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.
140
138
  result.push({ ref, metadataIndex: metadataValue > 0 ? metadataValue - 1 : 0 });
141
139
  }
142
140
  return result;
@@ -49,7 +49,6 @@ 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
- // 富文本的 <sz> 同样使用 pt,段字号与普通单元格都以 CSS px 传给视图。
53
52
  return Number.isFinite(value) && value > 0 ? value * 96 / 72 : undefined;
54
53
  };
55
54
  const normalizeSymbolText = (text, fontFamily) => {
@@ -5,9 +5,5 @@ export interface StoredSheetLayout {
5
5
  rowHeightPt?: number;
6
6
  maximumDigitWidth?: number;
7
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
8
  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
9
  export declare const readStoredSheetLayout: (zip: JSZip, part: string) => Promise<StoredSheetLayout>;
@@ -1,6 +1,4 @@
1
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
2
  export const readWorkbookDigitWidth = (workbook) => {
5
3
  var _a, _b, _c, _d, _e, _f, _g, _h;
6
4
  const styles = workbook === null || workbook === void 0 ? void 0 : workbook.Styles;
@@ -8,17 +6,12 @@ export const readWorkbookDigitWidth = (workbook) => {
8
6
  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
7
  const font = (_g = styles === null || styles === void 0 ? void 0 : styles.Fonts) === null || _g === void 0 ? void 0 : _g[fontId];
10
8
  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
9
  if (/^(?:宋体|新宋体|simsun|nsimsun)$/i.test(((_h = font === null || font === void 0 ? void 0 : font.name) === null || _h === void 0 ? void 0 : _h.trim()) || '')
15
10
  && Number.isFinite(size) && size >= 1 && size <= 409) {
16
11
  return Math.max(1, Math.ceil(size * 96 / 72 / 2));
17
12
  }
18
13
  return 7;
19
14
  };
20
- /** Read only the worksheet header; never materialize a large sheet's cells a
21
- * second time merely to recover sheetFormatPr. */
22
15
  export const readStoredSheetLayout = async (zip, part) => {
23
16
  var _a, _b, _c, _d;
24
17
  const file = zip.file(part);
@@ -28,7 +21,6 @@ export const readStoredSheetLayout = async (zip, part) => {
28
21
  const header = await new Promise((resolve, reject) => {
29
22
  let prefix = '';
30
23
  let done = false;
31
- // JSZip exposes this streaming API at runtime but omits it from JSZipObject's declaration.
32
24
  const stream = file.internalStream('string');
33
25
  const finish = () => {
34
26
  if (done)
@@ -32,12 +32,6 @@ 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
- */
41
35
  const isTextBackedLegacySpreadsheet = (data, source) => {
42
36
  const type = normalizeFileType(source.fileType) || getFilenameExtension(source.filename);
43
37
  if (!LEGACY_SPREADSHEET_TYPES.has(type) || !data.byteLength)
@@ -47,7 +41,6 @@ const isTextBackedLegacySpreadsheet = (data, source) => {
47
41
  return false;
48
42
  if (bytes[0] === 0x50 && bytes[1] === 0x4b)
49
43
  return false;
50
- // Raw BIFF2/3/4/5/8 BOF records need not be wrapped in an OLE container.
51
44
  if (bytes[0] === 0x09 && [0x00, 0x02, 0x04, 0x08].includes(bytes[1]))
52
45
  return false;
53
46
  const encoding = resolveFileViewerTextEncoding(bytes).encoding;
@@ -48,9 +48,7 @@ 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. */
52
51
  values: number[];
53
- /** Transferred-array blank positions to span, excluding numeric errors. */
54
52
  spanBlankIndexes?: number[];
55
53
  sourcePointCount?: number;
56
54
  sourcePointIndexes?: number[];
@@ -68,7 +66,6 @@ export interface SheetChartDefinition {
68
66
  type: SheetChartType;
69
67
  title?: string;
70
68
  categoryAxisTitle?: string;
71
- /** Unscaled CSS pixels from DrawingML hundredth-point text properties. */
72
69
  categoryAxisFontSize?: number;
73
70
  valueAxisFontSize?: number;
74
71
  valueAxisTitle?: string;