@file-viewer/renderer-spreadsheet 3.3.4 → 3.3.6

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.
@@ -4,6 +4,7 @@ import { readStoredRowSizing } from './rowSizing.js';
4
4
  import { readBoundedZipText } from './xmlBudget.js';
5
5
  import { DOMParser } from '@xmldom/xmldom';
6
6
  import JSZip from 'jszip';
7
+ import { SSF } from 'styled-exceljs';
7
8
  import { readStoredSheetLayout, readWorkbookDigitWidth } from './sheetLayout.js';
8
9
  import { extremaPointIndexes, MAX_TRANSFERRED_LINE_CHART_POINTS } from '../../chartSampling.js';
9
10
  const CHART_RELATIONSHIP_SUFFIX = '/chart';
@@ -331,7 +332,47 @@ const parseSeriesMarker = (series) => {
331
332
  size: Number.isFinite(sizeValue) && sizeValue > 0 ? sizeValue : undefined
332
333
  };
333
334
  };
334
- const parseSeries = (chartNode, workbook, blankMode = 'gap') => {
335
+ const xmlBoolean = (value) => value === '1' || value === 'true';
336
+ const excelNumericText = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
337
+ const categoryDateFormatter = (format, date1904) => {
338
+ if (!format || format.length > 255)
339
+ return undefined;
340
+ try {
341
+ if (!SSF.is_date(format))
342
+ return undefined;
343
+ return (value) => {
344
+ if (!excelNumericText.test(value.trim()))
345
+ return value;
346
+ const serial = Number(value);
347
+ try {
348
+ return serial >= 0 && serial < 2958466 ? SSF.format(format, serial, { date1904 }) || value : value;
349
+ }
350
+ catch {
351
+ return value;
352
+ }
353
+ };
354
+ }
355
+ catch {
356
+ return undefined;
357
+ }
358
+ };
359
+ const categoryFormat = (category, axis) => {
360
+ const numFmt = firstChildByLocal(axis, 'numFmt');
361
+ const axisFormat = (numFmt === null || numFmt === void 0 ? void 0 : numFmt.getAttribute('formatCode')) || undefined;
362
+ const sourceLinked = numFmt === null || numFmt === void 0 ? void 0 : numFmt.getAttribute('sourceLinked');
363
+ const cache = firstChildByLocal(category, 'numLit') ||
364
+ firstChildByLocal(firstChildByLocal(category, 'numRef'), 'numCache');
365
+ const cacheFormat = textContent(firstChildByLocal(cache, 'formatCode'));
366
+ if (axisFormat && (sourceLinked === '0' || sourceLinked === 'false'))
367
+ return axisFormat;
368
+ if (cacheFormat && cacheFormat !== 'General')
369
+ return cacheFormat;
370
+ if (cache || !category) {
371
+ return axisFormat || (axis && localName(axis) === 'dateAx' ? 'm/d/yyyy' : undefined);
372
+ }
373
+ return undefined;
374
+ };
375
+ const parseSeries = (chartNode, workbook, blankMode, categoryAxis, date1904, seriesOffset) => {
335
376
  const chartType = CHART_TYPE_MAP[localName(chartNode)];
336
377
  const compactLineSeries = chartType === 'line'
337
378
  || chartType === 'area'
@@ -341,7 +382,12 @@ const parseSeries = (chartNode, workbook, blankMode = 'gap') => {
341
382
  const tx = firstChildByLocal(series, 'tx');
342
383
  const category = firstChildByLocal(series, 'cat') || firstChildByLocal(series, 'xVal');
343
384
  const value = firstChildByLocal(series, 'val') || firstChildByLocal(series, 'yVal');
344
- const categories = parsePointValues(category, workbook);
385
+ const format = categoryFormat(category, categoryAxis);
386
+ const textCategories = firstChildByLocal(category, 'strRef') ||
387
+ firstChildByLocal(category, 'strLit') || firstChildByLocal(category, 'multiLvlStrRef');
388
+ const formatDate = textCategories ? undefined : categoryDateFormatter(format, date1904);
389
+ const rawCategories = parsePointValues(category, workbook, !format || !!textCategories);
390
+ const categories = formatDate ? rawCategories.map(formatDate) : rawCategories;
345
391
  const rawValues = parsePointValues(value, workbook, false);
346
392
  const count = Math.max(categories.length, rawValues.length);
347
393
  const spanBlankIndexes = [];
@@ -353,14 +399,17 @@ const parseSeries = (chartNode, workbook, blankMode = 'gap') => {
353
399
  spanBlankIndexes.push(pointIndex);
354
400
  return blankMode === 'zero' ? 0 : Number.NaN;
355
401
  }
356
- const number = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(raw) ? Number(raw) : NaN;
402
+ const number = excelNumericText.test(raw) ? Number(raw) : NaN;
357
403
  return Number.isFinite(number) ? number : Number.NaN;
358
404
  });
359
405
  const result = {
360
- name: chartText(tx, workbook) || `Series ${index + 1}`,
406
+ name: chartText(tx, workbook) || `Series ${seriesOffset + index + 1}`,
361
407
  categories: categories.length
362
408
  ? Array.from({ length: count }, (_, i) => { var _a; return (_a = categories[i]) !== null && _a !== void 0 ? _a : ''; })
363
- : values.map((_, valueIndex) => `${valueIndex + 1}`),
409
+ : values.map((_, valueIndex) => {
410
+ const label = `${valueIndex + 1}`;
411
+ return !category && formatDate ? formatDate(label) : label;
412
+ }),
364
413
  values,
365
414
  ...(spanBlankIndexes.length ? { spanBlankIndexes } : {}),
366
415
  color: parseSeriesColor(series),
@@ -396,39 +445,95 @@ const parseAxisFontSize = (axis, chartSpace) => {
396
445
  };
397
446
  return (_a = size(axis)) !== null && _a !== void 0 ? _a : size(chartSpace);
398
447
  };
399
- const parseChart = (document, workbook) => {
400
- var _a, _b, _c, _d, _e;
448
+ const axisId = (axis) => { var _a; return ((_a = firstChildByLocal(axis, 'axId')) === null || _a === void 0 ? void 0 : _a.getAttribute('val')) || undefined; };
449
+ const isCategoryAxis = (axis) => ['catAx', 'dateAx'].includes(localName(axis));
450
+ const legendPosition = (legend) => {
451
+ var _a, _b, _c, _d;
452
+ if (!legend)
453
+ return undefined;
454
+ const position = ((_a = firstChildByLocal(legend, 'legendPos')) === null || _a === void 0 ? void 0 : _a.getAttribute('val')) || '';
455
+ const manual = firstByLocal(firstChildByLocal(legend, 'layout'), 'manualLayout');
456
+ const y = Number((_c = (_b = firstChildByLocal(manual, 'y')) === null || _b === void 0 ? void 0 : _b.getAttribute('val')) !== null && _c !== void 0 ? _c : NaN);
457
+ if (position === 'b' && ((_d = firstChildByLocal(manual, 'yMode')) === null || _d === void 0 ? void 0 : _d.getAttribute('val')) === 'edge' && y >= 0 && y < 0.15) {
458
+ return 'top';
459
+ }
460
+ return LEGEND_POSITION_MAP[position] || 'bottom';
461
+ };
462
+ const parseChart = (document, workbook, workbookDate1904) => {
463
+ var _a, _b, _c, _d;
401
464
  const root = document.documentElement;
402
465
  const chart = firstByLocal(root, 'chart');
403
466
  const plotArea = firstChildByLocal(chart, 'plotArea') || firstByLocal(chart, 'plotArea');
404
- const chartEntry = childElements(plotArea)
467
+ const chartEntries = childElements(plotArea)
405
468
  .map((element) => ({ element, type: CHART_TYPE_MAP[localName(element)] }))
406
- .find((entry) => entry.type);
469
+ .filter((entry) => entry.type);
470
+ const chartEntry = chartEntries[0];
407
471
  if (!chartEntry) {
408
472
  return null;
409
473
  }
410
- const legend = firstChildByLocal(chart, 'legend');
411
- const legendPositionValue = ((_a = firstChildByLocal(legend, 'legendPos')) === null || _a === void 0 ? void 0 : _a.getAttribute('val')) || '';
412
- const categoryAxis = firstChildByLocal(plotArea, 'catAx');
413
- const valueAxis = firstChildByLocal(plotArea, 'valAx');
414
- const barDirection = ((_b = firstChildByLocal(chartEntry.element, 'barDir')) === null || _b === void 0 ? void 0 : _b.getAttribute('val')) === 'bar'
415
- ? 'bar'
416
- : 'column';
474
+ const direction = (element) => { var _a; return ((_a = firstChildByLocal(element, 'barDir')) === null || _a === void 0 ? void 0 : _a.getAttribute('val')) === 'bar' ? 'bar' : 'column'; };
475
+ const supportsCombination = chartEntries.every(({ element, type }) => type === 'line' || (type === 'bar' && direction(element) === 'column'))
476
+ && chartEntries.some(entry => entry.type === 'line') && chartEntries.some(entry => entry.type === 'bar');
477
+ const axes = childElements(plotArea);
478
+ const categoryAxes = axes.filter(isCategoryAxis);
479
+ const valueAxisElements = axes.filter(axis => localName(axis) === 'valAx');
480
+ const boundAxes = (element) => {
481
+ const ids = childrenByLocal(element, 'axId').map(id => id.getAttribute('val'));
482
+ return {
483
+ category: categoryAxes.find(axis => ids.includes(axisId(axis) || '')),
484
+ value: valueAxisElements.find(axis => ids.includes(axisId(axis) || '')),
485
+ };
486
+ };
487
+ const primaryAxes = boundAxes(chartEntry.element);
488
+ const categoryAxis = primaryAxes.category || categoryAxes[0];
489
+ const valueAxis = primaryAxes.value || valueAxisElements[0];
490
+ const dateEpoch = firstChildByLocal(root, 'date1904');
491
+ const date1904 = dateEpoch ? xmlBoolean((_a = dateEpoch.getAttribute('val')) !== null && _a !== void 0 ? _a : '1') : workbookDate1904;
492
+ const blankMode = ((_b = firstChildByLocal(chart, 'dispBlanksAs')) === null || _b === void 0 ? void 0 : _b.getAttribute('val')) || 'gap';
493
+ const series = [];
494
+ for (const entry of supportsCombination ? chartEntries : [chartEntry]) {
495
+ const binding = boundAxes(entry.element);
496
+ const entries = parseSeries(entry.element, workbook, blankMode, binding.category || categoryAxis, date1904, series.length);
497
+ for (const item of entries) {
498
+ if (supportsCombination) {
499
+ item.type = entry.type;
500
+ item.categoryAxisId = axisId(binding.category);
501
+ item.valueAxisId = axisId(binding.value || valueAxis);
502
+ }
503
+ series.push(item);
504
+ }
505
+ }
506
+ const valueAxes = supportsCombination ? valueAxisElements.flatMap((axis) => {
507
+ var _a, _b;
508
+ const id = axisId(axis);
509
+ if (!id || !series.some(item => item.valueAxisId === id))
510
+ return [];
511
+ return [{
512
+ id,
513
+ position: ((_a = firstChildByLocal(axis, 'axPos')) === null || _a === void 0 ? void 0 : _a.getAttribute('val')) === 'r' ? 'right' : 'left',
514
+ hidden: xmlBoolean((_b = firstChildByLocal(axis, 'delete')) === null || _b === void 0 ? void 0 : _b.getAttribute('val')),
515
+ fontSize: parseAxisFontSize(axis, root),
516
+ title: chartText(firstChildByLocal(axis, 'title'), workbook) || undefined
517
+ }];
518
+ }) : undefined;
417
519
  return {
418
520
  type: chartEntry.type,
419
521
  title: chartText(firstChildByLocal(chart, 'title'), workbook) || undefined,
420
522
  categoryAxisTitle: chartText(firstChildByLocal(categoryAxis, 'title'), workbook) || undefined,
523
+ categoryAxisId: supportsCombination ? axisId(categoryAxis) : undefined,
524
+ categoryAxisDate: categoryAxis && localName(categoryAxis) === 'dateAx' ? true : undefined,
421
525
  valueAxisTitle: chartText(firstChildByLocal(valueAxis, 'title'), workbook) || undefined,
422
- barDirection,
526
+ valueAxes,
527
+ barDirection: direction(chartEntry.element),
423
528
  categoryAxisFontSize: parseAxisFontSize(categoryAxis, root),
424
529
  valueAxisFontSize: parseAxisFontSize(valueAxis, root),
425
530
  grouping: ((_c = firstChildByLocal(chartEntry.element, 'grouping')) === null || _c === void 0 ? void 0 : _c.getAttribute('val')) || undefined,
426
531
  scatterStyle: ((_d = firstChildByLocal(chartEntry.element, 'scatterStyle')) === null || _d === void 0 ? void 0 : _d.getAttribute('val')) || undefined,
427
- legendPosition: legend ? LEGEND_POSITION_MAP[legendPositionValue] || 'bottom' : undefined,
428
- series: parseSeries(chartEntry.element, workbook, ((_e = firstChildByLocal(chart, 'dispBlanksAs')) === null || _e === void 0 ? void 0 : _e.getAttribute('val')) || 'gap')
532
+ legendPosition: legendPosition(firstChildByLocal(chart, 'legend')),
533
+ series
429
534
  };
430
535
  };
431
- const parseDrawingCharts = async (zip, drawingPart, workbook) => {
536
+ const parseDrawingCharts = async (zip, drawingPart, workbook, date1904) => {
432
537
  const [document, relationships] = await Promise.all([
433
538
  loadXml(zip, drawingPart),
434
539
  loadRelationships(zip, drawingPart)
@@ -445,7 +550,7 @@ const parseDrawingCharts = async (zip, drawingPart, workbook) => {
445
550
  return null;
446
551
  }
447
552
  const chartDocument = await loadXml(zip, chartRelationship.target);
448
- const chart = chartDocument ? parseChart(chartDocument, workbook) : null;
553
+ const chart = chartDocument ? parseChart(chartDocument, workbook, date1904) : null;
449
554
  if (!chart || !chart.series.length || chart.series.every((series) => !series.values.length)) {
450
555
  return null;
451
556
  }
@@ -477,7 +582,7 @@ const parseDrawingCharts = async (zip, drawingPart, workbook) => {
477
582
  return charts.filter((chart) => chart !== null);
478
583
  };
479
584
  export const parseSpreadsheetCharts = async (data, workbook) => {
480
- var _a;
585
+ var _a, _b;
481
586
  const zip = await JSZip.loadAsync(data);
482
587
  const workbookPart = 'xl/workbook.xml';
483
588
  const [workbookDocument, workbookRelationships] = await Promise.all([
@@ -489,13 +594,14 @@ export const parseSpreadsheetCharts = async (data, workbook) => {
489
594
  return result;
490
595
  }
491
596
  const maximumDigitWidth = readWorkbookDigitWidth(workbook);
597
+ const date1904 = xmlBoolean((_a = firstChildByLocal(workbookDocument.documentElement, 'workbookPr')) === null || _a === void 0 ? void 0 : _a.getAttribute('date1904'));
492
598
  for (const sheet of elementsByLocal(workbookDocument.documentElement, 'sheet')) {
493
599
  const name = sheet.getAttribute('name') || '';
494
600
  const worksheetRelationship = relationById(workbookRelationships, relationshipId(sheet));
495
601
  if (!name || !(worksheetRelationship === null || worksheetRelationship === void 0 ? void 0 : worksheetRelationship.type.endsWith(WORKSHEET_RELATIONSHIP_SUFFIX))) {
496
602
  continue;
497
603
  }
498
- const worksheet = (_a = workbook === null || workbook === void 0 ? void 0 : workbook.Sheets) === null || _a === void 0 ? void 0 : _a[name];
604
+ const worksheet = (_b = workbook === null || workbook === void 0 ? void 0 : workbook.Sheets) === null || _b === void 0 ? void 0 : _b[name];
499
605
  if (worksheet) {
500
606
  worksheet['!fileViewerLayout'] = {};
501
607
  worksheet['!fileViewerLayout'] = {
@@ -508,7 +614,7 @@ export const parseSpreadsheetCharts = async (data, workbook) => {
508
614
  const drawingParts = Array.from(new Set(worksheetRelationships
509
615
  .filter((relationship) => relationship.type.endsWith(DRAWING_RELATIONSHIP_SUFFIX))
510
616
  .map((relationship) => relationship.target)));
511
- const charts = (await Promise.all(drawingParts.map((part) => parseDrawingCharts(zip, part, workbook)))).flat();
617
+ const charts = (await Promise.all(drawingParts.map((part) => parseDrawingCharts(zip, part, workbook, date1904)))).flat();
512
618
  if (charts.length) {
513
619
  result[name] = charts;
514
620
  }
@@ -55,6 +55,9 @@ export interface SheetDrawingMarker {
55
55
  }
56
56
  export interface SheetChartSeries {
57
57
  name: string;
58
+ type?: SheetChartType;
59
+ categoryAxisId?: string;
60
+ valueAxisId?: string;
58
61
  categories: string[];
59
62
  values: number[];
60
63
  spanBlankIndexes?: number[];
@@ -69,6 +72,13 @@ export interface SheetChartSeries {
69
72
  size?: number;
70
73
  };
71
74
  }
75
+ export interface SheetChartValueAxis {
76
+ id: string;
77
+ position: 'left' | 'right';
78
+ hidden: boolean;
79
+ fontSize?: number;
80
+ title?: string;
81
+ }
72
82
  export interface SheetSourceAnchor {
73
83
  status: 'valid' | 'unknown';
74
84
  reason?: string;
@@ -89,9 +99,12 @@ export interface SheetChartDefinition {
89
99
  type: SheetChartType;
90
100
  title?: string;
91
101
  categoryAxisTitle?: string;
102
+ categoryAxisId?: string;
103
+ categoryAxisDate?: boolean;
92
104
  categoryAxisFontSize?: number;
93
105
  valueAxisFontSize?: number;
94
106
  valueAxisTitle?: string;
107
+ valueAxes?: SheetChartValueAxis[];
95
108
  barDirection?: 'column' | 'bar';
96
109
  grouping?: string;
97
110
  scatterStyle?: string;
@@ -6,7 +6,7 @@ import { createFileViewerWorkerController, createFileViewerTranslator, normalize
6
6
  import { renderSpreadsheetChart } from './spreadsheet/chartRenderer.js';
7
7
  import { createSpreadsheetImageSourceResolver } from './spreadsheet/imageSource.js';
8
8
  import { shouldFillSpreadsheetViewport, SpreadsheetViewportFill } from './spreadsheet/viewport.js';
9
- import { buildRows, clampWindowStart, collectWindowStarts, createEmptyVirtualState, DEFAULT_SHEET_DEFAULTS, displayCellKey, getDataKey, getWindowStart, INDEX_COLUMN_KEY, markWindowState, ROW_STATE_FIELD, RowState, WINDOW_SIZE, } from './spreadsheet/state.js';
9
+ import { buildRows, clampWindowStart, collectWindowStarts, createEmptyVirtualState, DEFAULT_SHEET_DEFAULTS, displayCellKey, getDataKey, getOrdinaryWindowSize, getWindowStart, INDEX_COLUMN_KEY, markWindowState, ROW_STATE_FIELD, RowState, } from './spreadsheet/state.js';
10
10
  import { buildColumns, createTableConfig, detectIndexOffset, getDisplayColumns, getSearchColumnLeft, getRowHeight, HEADER_HEIGHT, INDEX_COLUMN_WIDTH, normalizeCellStyle, normalizeRowHeight, RESIZABLE_COLUMN_MIN_WIDTH, RESIZABLE_ROW_MIN_HEIGHT, SPREADSHEET_MAX_ZOOM, SPREADSHEET_MIN_ZOOM, } from './spreadsheet/view.js';
11
11
  const EXCEL_IMAGE_SCROLLBAR_GUARD = 18;
12
12
  const DEFAULT_SPREADSHEET_WORKER_AUTO_THRESHOLD = 1 * 1024 * 1024;
@@ -638,7 +638,6 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
638
638
  let sheetDefaults = { ...DEFAULT_SHEET_DEFAULTS };
639
639
  let sheetInitializing = true;
640
640
  let hasInitialWindow = false;
641
- let loadedWindowCount = 0;
642
641
  let loadingWindowCount = 0;
643
642
  let sheetImages = [];
644
643
  let sheetCharts = [];
@@ -890,7 +889,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
890
889
  if (!totalRows) {
891
890
  return '';
892
891
  }
893
- const cachedRows = Math.min(loadedWindowCount * WINDOW_SIZE, totalRows);
892
+ const cachedRows = Array.from(virtualState.windowRows.values()).reduce((count, rows) => count + rows.length, 0);
894
893
  return t('spreadsheet.state.cachedRows', {
895
894
  cached: cachedRows,
896
895
  total: totalRows,
@@ -1219,7 +1218,6 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1219
1218
  subscribe: zoomEmitter.subscribe,
1220
1219
  });
1221
1220
  const syncWindowStats = () => {
1222
- loadedWindowCount = virtualState.loadedWindows.size;
1223
1221
  loadingWindowCount = virtualState.loadingWindows.size;
1224
1222
  renderChrome();
1225
1223
  };
@@ -1296,6 +1294,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1296
1294
  endRow,
1297
1295
  direction: scrollDirection,
1298
1296
  totalRows: virtualState.totalRows,
1297
+ windowSize: virtualState.windowSize,
1299
1298
  }).forEach(windowStart => requestWindow(windowStart, true));
1300
1299
  };
1301
1300
  const scheduleViewportLoad = () => {
@@ -1533,21 +1532,21 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1533
1532
  if (sheetId === undefined) {
1534
1533
  return;
1535
1534
  }
1536
- const windowStart = clampWindowStart(startRow, virtualState.totalRows);
1535
+ const windowStart = clampWindowStart(startRow, virtualState.totalRows, virtualState.windowSize);
1537
1536
  if (virtualState.loadedWindows.has(windowStart) || virtualState.loadingWindows.has(windowStart)) {
1538
1537
  return;
1539
1538
  }
1540
1539
  virtualState.loadingWindows.add(windowStart);
1541
1540
  syncWindowStats();
1542
1541
  if (virtualState.active) {
1543
- markWindowState(virtualState.rows, virtualState.totalRows, windowStart, RowState.Loading);
1542
+ markWindowState(virtualState.rows, virtualState.totalRows, windowStart, RowState.Loading, virtualState.windowSize);
1544
1543
  table === null || table === void 0 ? void 0 : table.draw();
1545
1544
  }
1546
1545
  errorMessage = '';
1547
1546
  emitWorker('parseSheet', {
1548
1547
  sheet: sheetId,
1549
1548
  startRow: windowStart,
1550
- pageSize: WINDOW_SIZE,
1549
+ pageSize: virtualState.windowSize,
1551
1550
  sessionId: sheetSessionId,
1552
1551
  });
1553
1552
  if (silent) {
@@ -1562,7 +1561,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1562
1561
  }
1563
1562
  const { columns, dataKeys } = buildColumns(ws, rowNumberMode);
1564
1563
  virtualState = {
1565
- ...createEmptyVirtualState(),
1564
+ ...createEmptyVirtualState(virtualState.windowSize),
1566
1565
  active: true,
1567
1566
  totalRows: meta.totalRows,
1568
1567
  totalCols: meta.totalCols,
@@ -1759,11 +1758,10 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1759
1758
  flushPendingViewRestore();
1760
1759
  requestPendingSearchWindow();
1761
1760
  flushPendingSearchJump();
1762
- const start = viewportRange.start || meta.startRow;
1763
- const end = Math.max(viewportRange.end, meta.endRow - 1, meta.startRow);
1764
- ensureViewportWindows(start, end);
1761
+ ensureViewportWindows(viewportRange.start, viewportRange.end);
1765
1762
  };
1766
1763
  const resetViewState = () => {
1764
+ var _a, _b;
1767
1765
  autoRowHeight.cancel();
1768
1766
  errorMessage = '';
1769
1767
  totalRows = 0;
@@ -1771,7 +1769,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1771
1769
  sheetDefaults = { ...DEFAULT_SHEET_DEFAULTS };
1772
1770
  sheetImages = [];
1773
1771
  sheetCharts = [];
1774
- virtualState = createEmptyVirtualState();
1772
+ virtualState = createEmptyVirtualState(getOrdinaryWindowSize((_b = (_a = getActiveSheet()) === null || _a === void 0 ? void 0 : _a.colCount) !== null && _b !== void 0 ? _b : 0));
1775
1773
  hasInitialWindow = false;
1776
1774
  resetViewportTracking();
1777
1775
  syncWindowStats();
@@ -1916,7 +1914,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1916
1914
  const pending = pendingSearchJump;
1917
1915
  if (!pending ||
1918
1916
  pending.sheetId !== getActiveSheetId() ||
1919
- !virtualState.loadedWindows.has(getWindowStart(pending.row, virtualState.totalRows)) ||
1917
+ !virtualState.loadedWindows.has(getWindowStart(pending.row, virtualState.totalRows, virtualState.windowSize)) ||
1920
1918
  !table) {
1921
1919
  return;
1922
1920
  }
@@ -1947,7 +1945,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1947
1945
  if (!pending || pending.sheetId !== getActiveSheetId() || !virtualState.totalRows) {
1948
1946
  return;
1949
1947
  }
1950
- const windowStart = getWindowStart(pending.row, virtualState.totalRows);
1948
+ const windowStart = getWindowStart(pending.row, virtualState.totalRows, virtualState.windowSize);
1951
1949
  if (virtualState.loadedWindows.has(windowStart)) {
1952
1950
  flushPendingSearchJump();
1953
1951
  return;
@@ -2112,7 +2110,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
2112
2110
  virtualState.loadingWindows.delete(startRow);
2113
2111
  syncWindowStats();
2114
2112
  if (virtualState.active) {
2115
- markWindowState(virtualState.rows, virtualState.totalRows, startRow, RowState.Placeholder);
2113
+ markWindowState(virtualState.rows, virtualState.totalRows, startRow, RowState.Placeholder, virtualState.windowSize);
2116
2114
  table === null || table === void 0 ? void 0 : table.draw();
2117
2115
  }
2118
2116
  }