@file-viewer/renderer-spreadsheet 3.1.2 → 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.
@@ -5,6 +5,7 @@ const CHART_RELATIONSHIP_SUFFIX = '/chart';
5
5
  const DRAWING_RELATIONSHIP_SUFFIX = '/drawing';
6
6
  const WORKSHEET_RELATIONSHIP_SUFFIX = '/worksheet';
7
7
  const EMUS_PER_CSS_PIXEL = 9525;
8
+ const MAX_CHART_POINTS = 1048576;
8
9
  const CHART_TYPE_MAP = {
9
10
  areaChart: 'area',
10
11
  area3DChart: 'area',
@@ -114,9 +115,6 @@ const relationshipPartPath = (sourcePart) => {
114
115
  return `${directory ? `${directory}/` : ''}_rels/${filename}.rels`;
115
116
  };
116
117
  const parseXml = (xml) => {
117
- // Some valid Office producers prefix relationship parts with a UTF-8 BOM.
118
- // XML declarations must otherwise be the first character, and xmldom reports
119
- // the BOM as content outside the root element before aborting chart parsing.
120
118
  return new DOMParser().parseFromString(xml.replace(/^[\uFEFF\s]+/, ''), 'application/xml');
121
119
  };
122
120
  export const loadXml = async (zip, path) => {
@@ -201,10 +199,17 @@ const parseFormulaRange = (formula) => {
201
199
  const sheetName = sheetToken.startsWith("'") && sheetToken.endsWith("'")
202
200
  ? sheetToken.slice(1, -1).replace(/''/g, "'")
203
201
  : sheetToken;
204
- const [startToken, endToken = startToken] = rangeToken.split(':');
202
+ const tokens = rangeToken.split(':');
203
+ if (tokens.length > 2)
204
+ return null;
205
+ const [startToken, endToken = startToken] = tokens;
205
206
  const start = parseCellAddress(startToken);
206
207
  const end = parseCellAddress(endToken);
207
- if (!sheetName || !start || !end) {
208
+ if (!sheetName || !start || !end ||
209
+ start.row < 0 || end.row < 0 ||
210
+ Math.max(start.row, end.row) >= MAX_CHART_POINTS ||
211
+ Math.max(start.col, end.col) >= 16384 ||
212
+ (Math.abs(end.row - start.row) + 1) * (Math.abs(end.col - start.col) + 1) > MAX_CHART_POINTS) {
208
213
  return null;
209
214
  }
210
215
  return {
@@ -237,18 +242,37 @@ const resolveFormulaValues = (formula, workbook, formatted) => {
237
242
  return values;
238
243
  };
239
244
  const parsePointValues = (element, workbook, formatted = true) => {
245
+ var _a;
240
246
  if (!element) {
241
247
  return [];
242
248
  }
243
- const cachedValues = elementsByLocal(element, 'pt')
244
- .map((point) => ({
245
- index: Number(point.getAttribute('idx')) || 0,
246
- value: textContent(firstChildByLocal(point, 'v')) || textContent(firstByLocal(point, 'v'))
247
- }))
248
- .sort((left, right) => left.index - right.index)
249
- .map((point) => point.value);
250
- if (cachedValues.length) {
251
- return cachedValues;
249
+ const literal = firstChildByLocal(element, 'strLit') || firstChildByLocal(element, 'numLit');
250
+ const reference = firstChildByLocal(element, 'strRef') || firstChildByLocal(element, 'numRef');
251
+ const multiLevel = firstChildByLocal(firstChildByLocal(element, 'multiLvlStrRef'), 'multiLvlStrCache');
252
+ const cache = literal || firstChildByLocal(reference, 'strCache') ||
253
+ firstChildByLocal(reference, 'numCache') || multiLevel;
254
+ if (cache) {
255
+ const unsigned = (token) => {
256
+ const text = (token === null || token === void 0 ? void 0 : token.trim()) || '';
257
+ if (!/^\+?\d+$/.test(text))
258
+ return undefined;
259
+ const value = Number(text);
260
+ return Number.isSafeInteger(value) && value >= 0 && value <= MAX_CHART_POINTS
261
+ ? value : undefined;
262
+ };
263
+ const entries = childrenByLocal(multiLevel ? firstChildByLocal(cache, 'lvl') : cache, 'pt')
264
+ .flatMap(point => {
265
+ var _a;
266
+ const index = unsigned(point.getAttribute('idx'));
267
+ return index !== undefined && index < MAX_CHART_POINTS
268
+ ? [{ index, value: ((_a = firstChildByLocal(point, 'v')) === null || _a === void 0 ? void 0 : _a.textContent) || '' }] : [];
269
+ });
270
+ const count = entries.reduce((length, point) => Math.max(length, point.index + 1), unsigned((_a = firstChildByLocal(cache, 'ptCount')) === null || _a === void 0 ? void 0 : _a.getAttribute('val')) || 0);
271
+ const values = Array(count).fill('');
272
+ for (const point of entries)
273
+ values[point.index] = point.value;
274
+ if (count || literal || !reference)
275
+ return values;
252
276
  }
253
277
  const formula = textContent(firstByLocal(element, 'f'));
254
278
  return formula ? resolveFormulaValues(formula, workbook, formatted) : [];
@@ -302,7 +326,7 @@ const parseSeriesMarker = (series) => {
302
326
  size: Number.isFinite(sizeValue) && sizeValue > 0 ? sizeValue : undefined
303
327
  };
304
328
  };
305
- const parseSeries = (chartNode, workbook) => {
329
+ const parseSeries = (chartNode, workbook, blankMode = 'gap') => {
306
330
  const chartType = CHART_TYPE_MAP[localName(chartNode)];
307
331
  const compactLineSeries = chartType === 'line'
308
332
  || chartType === 'area'
@@ -313,13 +337,27 @@ const parseSeries = (chartNode, workbook) => {
313
337
  const category = firstChildByLocal(series, 'cat') || firstChildByLocal(series, 'xVal');
314
338
  const value = firstChildByLocal(series, 'val') || firstChildByLocal(series, 'yVal');
315
339
  const categories = parsePointValues(category, workbook);
316
- const values = parsePointValues(value, workbook, false).map(Number).filter(Number.isFinite);
340
+ const rawValues = parsePointValues(value, workbook, false);
341
+ const count = Math.max(categories.length, rawValues.length);
342
+ const spanBlankIndexes = [];
343
+ const values = Array.from({ length: count }, (_, pointIndex) => {
344
+ var _a;
345
+ const raw = ((_a = rawValues[pointIndex]) === null || _a === void 0 ? void 0 : _a.trim()) || '';
346
+ if (!raw) {
347
+ if (blankMode === 'span')
348
+ spanBlankIndexes.push(pointIndex);
349
+ return blankMode === 'zero' ? 0 : Number.NaN;
350
+ }
351
+ const number = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(raw) ? Number(raw) : NaN;
352
+ return Number.isFinite(number) ? number : Number.NaN;
353
+ });
317
354
  const result = {
318
355
  name: chartText(tx, workbook) || `Series ${index + 1}`,
319
356
  categories: categories.length
320
- ? categories
357
+ ? Array.from({ length: count }, (_, i) => { var _a; return (_a = categories[i]) !== null && _a !== void 0 ? _a : ''; })
321
358
  : values.map((_, valueIndex) => `${valueIndex + 1}`),
322
359
  values,
360
+ ...(spanBlankIndexes.length ? { spanBlankIndexes } : {}),
323
361
  color: parseSeriesColor(series),
324
362
  ...parseSeriesLine(series),
325
363
  marker: parseSeriesMarker(series)
@@ -327,7 +365,8 @@ const parseSeries = (chartNode, workbook) => {
327
365
  if (!compactLineSeries || values.length <= MAX_TRANSFERRED_LINE_CHART_POINTS) {
328
366
  return result;
329
367
  }
330
- const sourcePointIndexes = extremaPointIndexes(values, MAX_TRANSFERRED_LINE_CHART_POINTS);
368
+ const sourcePointIndexes = extremaPointIndexes(values, MAX_TRANSFERRED_LINE_CHART_POINTS, spanBlankIndexes);
369
+ const spanning = new Set(spanBlankIndexes);
331
370
  return {
332
371
  ...result,
333
372
  categories: sourcePointIndexes.map((sourceIndex) => {
@@ -335,13 +374,25 @@ const parseSeries = (chartNode, workbook) => {
335
374
  return ((_a = result.categories[sourceIndex]) !== null && _a !== void 0 ? _a : `${sourceIndex + 1}`);
336
375
  }),
337
376
  values: sourcePointIndexes.map((sourceIndex) => values[sourceIndex]),
377
+ ...(spanBlankIndexes.length ? { spanBlankIndexes: sourcePointIndexes.flatMap((sourceIndex, i) => spanning.has(sourceIndex) ? [i] : []) } : {}),
338
378
  sourcePointCount: values.length,
339
379
  sourcePointIndexes
340
380
  };
341
381
  });
342
382
  };
383
+ const parseAxisFontSize = (axis, chartSpace) => {
384
+ var _a;
385
+ const size = (node) => {
386
+ var _a;
387
+ const props = firstByLocal(firstChildByLocal(node, 'txPr'), 'defRPr');
388
+ const raw = ((_a = props === null || props === void 0 ? void 0 : props.getAttribute('sz')) === null || _a === void 0 ? void 0 : _a.trim()) || '';
389
+ const value = /^\d+$/.test(raw) ? Number(raw) : NaN;
390
+ return Number.isFinite(value) && value >= 100 && value <= 400000 ? value / 75 : undefined;
391
+ };
392
+ return (_a = size(axis)) !== null && _a !== void 0 ? _a : size(chartSpace);
393
+ };
343
394
  const parseChart = (document, workbook) => {
344
- var _a, _b, _c, _d;
395
+ var _a, _b, _c, _d, _e;
345
396
  const root = document.documentElement;
346
397
  const chart = firstByLocal(root, 'chart');
347
398
  const plotArea = firstChildByLocal(chart, 'plotArea') || firstByLocal(chart, 'plotArea');
@@ -364,10 +415,12 @@ const parseChart = (document, workbook) => {
364
415
  categoryAxisTitle: chartText(firstChildByLocal(categoryAxis, 'title'), workbook) || undefined,
365
416
  valueAxisTitle: chartText(firstChildByLocal(valueAxis, 'title'), workbook) || undefined,
366
417
  barDirection,
418
+ categoryAxisFontSize: parseAxisFontSize(categoryAxis, root),
419
+ valueAxisFontSize: parseAxisFontSize(valueAxis, root),
367
420
  grouping: ((_c = firstChildByLocal(chartEntry.element, 'grouping')) === null || _c === void 0 ? void 0 : _c.getAttribute('val')) || undefined,
368
421
  scatterStyle: ((_d = firstChildByLocal(chartEntry.element, 'scatterStyle')) === null || _d === void 0 ? void 0 : _d.getAttribute('val')) || undefined,
369
422
  legendPosition: legend ? LEGEND_POSITION_MAP[legendPositionValue] || 'bottom' : undefined,
370
- series: parseSeries(chartEntry.element, workbook)
423
+ series: parseSeries(chartEntry.element, workbook, ((_e = firstChildByLocal(chart, 'dispBlanksAs')) === null || _e === void 0 ? void 0 : _e.getAttribute('val')) || 'gap')
371
424
  };
372
425
  };
373
426
  const parseDrawingCharts = async (zip, drawingPart, workbook) => {
@@ -432,11 +485,6 @@ export const parseSpreadsheetCharts = async (data, workbook) => {
432
485
  if (!name || !(worksheetRelationship === null || worksheetRelationship === void 0 ? void 0 : worksheetRelationship.type.endsWith(WORKSHEET_RELATIONSHIP_SUFFIX))) {
433
486
  continue;
434
487
  }
435
- // A worksheet can expand to hundreds of megabytes even when the drawing
436
- // relationship part is only a few hundred bytes. Loading sheetN.xml as a
437
- // string here duplicates the cell parser's work and can exceed V8's string
438
- // limit before chart parsing starts. Drawing relationships already carry
439
- // the typed targets needed by the chart parser, so discover them directly.
440
488
  const worksheetRelationships = await loadRelationships(zip, worksheetRelationship.target);
441
489
  const drawingParts = Array.from(new Set(worksheetRelationships
442
490
  .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;
@@ -22,6 +22,9 @@ export interface SpreadsheetParserContext {
22
22
  charts: Record<string, SheetChartDefinition[]>;
23
23
  cellImages: Record<string, SheetCellImage[]>;
24
24
  }
25
+ export interface SpreadsheetWorkbookSource extends SpreadsheetTextSource {
26
+ includeEmptySheets?: boolean;
27
+ }
25
28
  export interface SpreadsheetWorkerRequest {
26
29
  type: string;
27
30
  payload?: Record<string, any>;
@@ -62,7 +65,7 @@ export interface WorksheetDisplayBounds {
62
65
  trimmed: boolean;
63
66
  }
64
67
  export declare const getWorksheetDisplayBounds: (worksheet: WorksheetRangeLike | undefined, charts: SheetChartDefinition[] | undefined) => WorksheetDisplayBounds;
65
- export declare const parseSpreadsheetWorkbook: (context: SpreadsheetParserContext, data: ArrayBuffer, source?: SpreadsheetTextSource) => Promise<SpreadsheetWorkerResponse[]>;
68
+ export declare const parseSpreadsheetWorkbook: (context: SpreadsheetParserContext, data: ArrayBuffer, source?: SpreadsheetWorkbookSource) => Promise<SpreadsheetWorkerResponse[]>;
66
69
  export declare const parseSpreadsheetSheet: (context: SpreadsheetParserContext, payload?: Record<string, any>) => SpreadsheetWorkerResponse[];
67
70
  export declare const searchSpreadsheetWorkbook: (context: SpreadsheetParserContext, query: string, options?: SpreadsheetSearchOptions) => SpreadsheetSearchMatch[];
68
71
  export declare const handleSpreadsheetWorkerRequest: (context: SpreadsheetParserContext, request: SpreadsheetWorkerRequest) => SpreadsheetWorkerResponse[] | Promise<SpreadsheetWorkerResponse[]>;
@@ -179,7 +179,6 @@ const getCellBounds = (worksheet) => {
179
179
  bounds.colCount = Math.max(bounds.colCount, cell.c + 1);
180
180
  }
181
181
  catch {
182
- // Ignore non-cell extension keys exposed by third-party workbook producers.
183
182
  }
184
183
  }
185
184
  return bounds;
@@ -215,7 +214,6 @@ export const getWorksheetDisplayBounds = (worksheet, charts) => {
215
214
  declaredColCount = range.e.c + 1;
216
215
  }
217
216
  catch {
218
- // Invalid producer dimensions must not block content-based recovery.
219
217
  }
220
218
  }
221
219
  const cellBounds = getCellBounds(worksheet);
@@ -236,7 +234,7 @@ export const getWorksheetDisplayBounds = (worksheet, charts) => {
236
234
  trimmed: rowCount < declaredRowCount || colCount < declaredColCount,
237
235
  };
238
236
  };
239
- const parseSheets = (context) => {
237
+ const parseSheets = (context, includeEmptySheets = false) => {
240
238
  var _a;
241
239
  const workbook = context.workbook;
242
240
  if (!(workbook === null || workbook === void 0 ? void 0 : workbook.SheetNames)) {
@@ -247,7 +245,8 @@ const parseSheets = (context) => {
247
245
  var _a;
248
246
  const worksheet = workbook.Sheets[name];
249
247
  const bounds = getWorksheetDisplayBounds(worksheet, context.charts[name]);
250
- if (!(worksheet === null || worksheet === void 0 ? void 0 : worksheet['!ref']) && !bounds.observedRowCount && !bounds.observedColCount) {
248
+ const empty = !(worksheet === null || worksheet === void 0 ? void 0 : worksheet['!ref']) && !bounds.observedRowCount && !bounds.observedColCount;
249
+ if (!worksheet || (empty && !includeEmptySheets)) {
251
250
  return result;
252
251
  }
253
252
  if (bounds.trimmed) {
@@ -258,8 +257,8 @@ const parseSheets = (context) => {
258
257
  id: result.length,
259
258
  name,
260
259
  hidden: !!((_a = workbookSheets[sourceIndex]) === null || _a === void 0 ? void 0 : _a.Hidden),
261
- rowCount: bounds.rowCount,
262
- colCount: bounds.colCount,
260
+ rowCount: empty ? 0 : bounds.rowCount,
261
+ colCount: empty ? 0 : bounds.colCount,
263
262
  });
264
263
  return result;
265
264
  }, []);
@@ -288,7 +287,7 @@ export const parseSpreadsheetWorkbook = async (context, data, source = {}) => {
288
287
  context.charts = {};
289
288
  context.cellImages = {};
290
289
  }
291
- return parseSheets(context);
290
+ return parseSheets(context, source.includeEmptySheets);
292
291
  }
293
292
  catch (error) {
294
293
  return [toErrorResponse(error)];
@@ -316,8 +315,6 @@ export const parseSpreadsheetSheet = (context, payload = {}) => {
316
315
  charts: context.charts[sheetName],
317
316
  cellImages: context.cellImages[sheetName],
318
317
  });
319
- // Keep the first response backward-compatible; later virtual windows only need rows and cells.
320
- // Avoid recalculating auto-fit column widths for every 500-row request.
321
318
  const windowData = sheetModel.toObject({ includeLayout: startRow === 0 });
322
319
  const structure = startRow === 0 ? sheetModel.structure : undefined;
323
320
  return [{
@@ -433,13 +430,14 @@ export const searchSpreadsheetWorkbook = (context, query, options = {}) => {
433
430
  return matches;
434
431
  };
435
432
  export const handleSpreadsheetWorkerRequest = (context, request) => {
436
- var _a, _b, _c, _d, _e, _f, _g;
433
+ var _a, _b, _c, _d, _e, _f, _g, _h;
437
434
  switch (request.type) {
438
435
  case 'parseWorkbook':
439
436
  return parseSpreadsheetWorkbook(context, (_a = request.payload) === null || _a === void 0 ? void 0 : _a.workbook, {
440
437
  fileType: (_b = request.payload) === null || _b === void 0 ? void 0 : _b.fileType,
441
438
  filename: (_c = request.payload) === null || _c === void 0 ? void 0 : _c.filename,
442
439
  textEncoding: (_d = request.payload) === null || _d === void 0 ? void 0 : _d.textEncoding,
440
+ includeEmptySheets: (_e = request.payload) === null || _e === void 0 ? void 0 : _e.includeEmptySheets,
443
441
  });
444
442
  case 'parseSheet':
445
443
  return parseSpreadsheetSheet(context, request.payload);
@@ -447,9 +445,9 @@ export const handleSpreadsheetWorkerRequest = (context, request) => {
447
445
  return [{
448
446
  type: 'searchWorkbook',
449
447
  payload: {
450
- requestId: (_e = request.payload) === null || _e === void 0 ? void 0 : _e.requestId,
451
- query: ((_f = request.payload) === null || _f === void 0 ? void 0 : _f.query) || '',
452
- matches: searchSpreadsheetWorkbook(context, ((_g = request.payload) === null || _g === void 0 ? void 0 : _g.query) || '', request.payload),
448
+ requestId: (_f = request.payload) === null || _f === void 0 ? void 0 : _f.requestId,
449
+ query: ((_g = request.payload) === null || _g === void 0 ? void 0 : _g.query) || '',
450
+ matches: searchSpreadsheetWorkbook(context, ((_h = request.payload) === null || _h === void 0 ? void 0 : _h.query) || '', request.payload),
453
451
  },
454
452
  }];
455
453
  default:
@@ -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;
@@ -1,4 +1,4 @@
1
- import { decodeFileViewerTextBuffer, isValidFileViewerUtf8, } from '@file-viewer/core';
1
+ import { decodeFileViewerTextBuffer, isValidFileViewerUtf8, resolveFileViewerTextEncoding, } from '@file-viewer/core';
2
2
  const TEXT_SPREADSHEET_EXTENSIONS = new Set(['csv', 'tsv']);
3
3
  const TEXT_SPREADSHEET_MIME_TYPES = new Set([
4
4
  'text/csv',
@@ -27,8 +27,40 @@ export const isTextSpreadsheetSource = ({ fileType, filename, }) => {
27
27
  };
28
28
  export const isValidUtf8 = isValidFileViewerUtf8;
29
29
  export const decodeSpreadsheetText = (data, encoding = 'auto') => decodeFileViewerTextBuffer(data, encoding);
30
+ const LEGACY_SPREADSHEET_TYPES = new Set([
31
+ 'xls', 'xlt', 'xla', 'application/vnd.ms-excel',
32
+ ]);
33
+ const OLE_SIGNATURE = [0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1];
34
+ const TEXT_PROBE_BYTES = 65536;
35
+ const isTextBackedLegacySpreadsheet = (data, source) => {
36
+ const type = normalizeFileType(source.fileType) || getFilenameExtension(source.filename);
37
+ if (!LEGACY_SPREADSHEET_TYPES.has(type) || !data.byteLength)
38
+ return false;
39
+ const bytes = new Uint8Array(data, 0, Math.min(data.byteLength, TEXT_PROBE_BYTES));
40
+ if (OLE_SIGNATURE.every((byte, index) => bytes[index] === byte))
41
+ return false;
42
+ if (bytes[0] === 0x50 && bytes[1] === 0x4b)
43
+ return false;
44
+ if (bytes[0] === 0x09 && [0x00, 0x02, 0x04, 0x08].includes(bytes[1]))
45
+ return false;
46
+ const encoding = resolveFileViewerTextEncoding(bytes).encoding;
47
+ if (encoding.startsWith('utf-16') && data.byteLength % 2 !== 0)
48
+ return false;
49
+ try {
50
+ const text = decodeSpreadsheetText(data.slice(0, bytes.length), source.textEncoding).text;
51
+ if (/^[\s\uFEFF]*(?:%PDF-|%!PS|\{\\rtf)/i.test(text))
52
+ return false;
53
+ if (/[\u0000-\u0008\u000b\u000e-\u001f\u007f]/.test(text))
54
+ return false;
55
+ const replacements = (text.match(/\uFFFD/g) || []).length;
56
+ return replacements <= Math.max(1, text.length * 0.01);
57
+ }
58
+ catch {
59
+ return false;
60
+ }
61
+ };
30
62
  export const prepareSpreadsheetReadInput = (data, source = {}) => {
31
- if (!isTextSpreadsheetSource(source)) {
63
+ if (!isTextSpreadsheetSource(source) && !isTextBackedLegacySpreadsheet(data, source)) {
32
64
  return { kind: 'binary', data };
33
65
  }
34
66
  const decoded = decodeSpreadsheetText(data, source.textEncoding);
@@ -49,6 +49,7 @@ export interface SheetChartSeries {
49
49
  name: string;
50
50
  categories: string[];
51
51
  values: number[];
52
+ spanBlankIndexes?: number[];
52
53
  sourcePointCount?: number;
53
54
  sourcePointIndexes?: number[];
54
55
  color?: string;
@@ -65,6 +66,8 @@ export interface SheetChartDefinition {
65
66
  type: SheetChartType;
66
67
  title?: string;
67
68
  categoryAxisTitle?: string;
69
+ categoryAxisFontSize?: number;
70
+ valueAxisFontSize?: number;
68
71
  valueAxisTitle?: string;
69
72
  barDirection?: 'column' | 'bar';
70
73
  grouping?: string;