@extend-ai/react-xlsx 0.6.0 → 0.7.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.
@@ -16,6 +16,9 @@ var SERIES_COLORS = [
16
16
  "#636363",
17
17
  "#997300"
18
18
  ];
19
+ function normalizeWorksheetVisibility(value) {
20
+ return value === "hidden" || value === "veryHidden" ? value : "visible";
21
+ }
19
22
  var EMU_PER_PIXEL = 9525;
20
23
  var THEME_COLOR_INDEX_BY_NAME = {
21
24
  accent1: 4,
@@ -950,7 +953,7 @@ function applyChartSeriesStyleFromXml(chart, chartTypeNode, themePalette) {
950
953
  const invertNegativeStyle = parseInvertNegativeStyle(seriesNode, themePalette);
951
954
  const invertIfNegative = readChartBooleanAttribute(seriesNode, "invertIfNegative");
952
955
  const isScatterChart = chart.chartType === "Scatter" || chart.chartType === "ScatterLines" || chart.chartType === "ScatterSmooth" || chart.chartType === "Bubble";
953
- const cachedCategories = isScatterChart ? parseChartCacheValues(getFirstLocalChild(seriesNode, "xVal"), "numCache", "value") ?? parseChartMultiLevelCacheValues(getFirstLocalChild(seriesNode, "xVal"), "category") : parseChartCacheValues(getFirstLocalChild(seriesNode, "cat"), "strCache", "category");
956
+ const cachedCategories = isScatterChart ? parseChartCacheValues(getFirstLocalChild(seriesNode, "xVal"), "numCache", "value") ?? parseChartMultiLevelCacheValues(getFirstLocalChild(seriesNode, "xVal"), "category") : parseChartCacheValues(getFirstLocalChild(seriesNode, "cat"), "strCache", "category") ?? parseChartCacheValues(getFirstLocalChild(seriesNode, "cat"), "numCache", "category") ?? parseChartMultiLevelCacheValues(getFirstLocalChild(seriesNode, "cat"), "category");
954
957
  const cachedValues = isScatterChart ? parseChartCacheValues(getFirstLocalChild(seriesNode, "yVal"), "numCache", "value") : parseChartCacheValues(getFirstLocalChild(seriesNode, "val"), "numCache", "value");
955
958
  const cachedBubbleSizes = chart.chartType === "Bubble" ? parseChartCacheValues(getFirstLocalChild(seriesNode, "bubbleSize"), "numCache", "value") : null;
956
959
  const existingShapeProperties = series.shapeProperties && typeof series.shapeProperties === "object" ? series.shapeProperties : null;
@@ -2691,17 +2694,25 @@ function normalizeChartsheet(raw, index) {
2691
2694
  workbookSheetIndex: typeof chartsheet.workbookSheetIndex === "number" ? chartsheet.workbookSheetIndex : void 0
2692
2695
  };
2693
2696
  }
2694
- function buildTabs(workbook2, chartsheets2, visibleSheetIndexByWorkbookSheetIndex) {
2697
+ function buildTabs(workbook2, chartsheets2, visibleSheetIndexByWorkbookSheetIndex, showHiddenSheets = false) {
2695
2698
  const rawOrder = Array.isArray(workbook2.sheetOrder) ? workbook2.sheetOrder : [];
2696
2699
  if (rawOrder.length === 0) {
2697
- return workbook2.sheetNames.map((name, index) => ({
2698
- id: `sheet-${index}`,
2699
- index,
2700
- kind: "sheet",
2701
- name,
2702
- sheetIndex: visibleSheetIndexByWorkbookSheetIndex.get(index) ?? index,
2703
- workbookSheetIndex: index
2704
- }));
2700
+ return workbook2.sheetNames.flatMap((name, index) => {
2701
+ const worksheet = workbook2.getSheet(index);
2702
+ const visibility = normalizeWorksheetVisibility(worksheet.visibility);
2703
+ if (!showHiddenSheets && visibility !== "visible") {
2704
+ return [];
2705
+ }
2706
+ return [{
2707
+ id: `sheet-${index}`,
2708
+ index,
2709
+ kind: "sheet",
2710
+ name,
2711
+ sheetIndex: visibleSheetIndexByWorkbookSheetIndex.get(index) ?? index,
2712
+ visibility,
2713
+ workbookSheetIndex: index
2714
+ }];
2715
+ });
2705
2716
  }
2706
2717
  return rawOrder.flatMap((entry, index) => {
2707
2718
  const slotType = typeof entry.slotType === "string" ? entry.slotType : "worksheet";
@@ -2717,7 +2728,8 @@ function buildTabs(workbook2, chartsheets2, visibleSheetIndexByWorkbookSheetInde
2717
2728
  }] : [];
2718
2729
  }
2719
2730
  const worksheet = workbook2.getSheet(slotIndex);
2720
- if (worksheet.visibility !== "visible") {
2731
+ const visibility = normalizeWorksheetVisibility(worksheet.visibility);
2732
+ if (!showHiddenSheets && visibility !== "visible") {
2721
2733
  return [];
2722
2734
  }
2723
2735
  return [{
@@ -2726,6 +2738,7 @@ function buildTabs(workbook2, chartsheets2, visibleSheetIndexByWorkbookSheetInde
2726
2738
  kind: "sheet",
2727
2739
  name: worksheet.name,
2728
2740
  sheetIndex: visibleSheetIndexByWorkbookSheetIndex.get(slotIndex) ?? slotIndex,
2741
+ visibility,
2729
2742
  workbookSheetIndex: slotIndex
2730
2743
  }];
2731
2744
  });
@@ -2815,7 +2828,7 @@ function applyChartOrigins(chartsByWorkbookSheetIndex2, chartOriginsById, archiv
2815
2828
  });
2816
2829
  }
2817
2830
  }
2818
- function loadWorkbookChartAssets(workbook2, imageAssets, visibleSheetIndexByWorkbookSheetIndex) {
2831
+ function loadWorkbookChartAssets(workbook2, imageAssets, visibleSheetIndexByWorkbookSheetIndex, showHiddenSheets = false) {
2819
2832
  const chartsByWorkbookSheetIndex2 = Array.from({ length: workbook2.sheetCount }, (_, workbookSheetIndex) => {
2820
2833
  const worksheet = workbook2.getSheet(workbookSheetIndex);
2821
2834
  const rawCharts = Array.isArray(worksheet.charts) ? worksheet.charts : [];
@@ -2903,7 +2916,7 @@ function loadWorkbookChartAssets(workbook2, imageAssets, visibleSheetIndexByWork
2903
2916
  return [...classicCharts, ...modernCharts];
2904
2917
  });
2905
2918
  const chartsheets2 = Array.isArray(workbook2.chartsheets) ? workbook2.chartsheets.map((entry, index) => normalizeChartsheet(entry, index)) : [];
2906
- const tabs2 = buildTabs(workbook2, chartsheets2, visibleSheetIndexByWorkbookSheetIndex);
2919
+ const tabs2 = buildTabs(workbook2, chartsheets2, visibleSheetIndexByWorkbookSheetIndex, showHiddenSheets);
2907
2920
  const chartOriginsById = /* @__PURE__ */ new Map();
2908
2921
  if (imageAssets) {
2909
2922
  applyChartOrigins(chartsByWorkbookSheetIndex2, chartOriginsById, imageAssets.archive, imageAssets.sheetOrigins);
@@ -3605,6 +3618,8 @@ function parseSpreadsheetAlignment(node) {
3605
3618
  const vertical = node.getAttribute("vertical");
3606
3619
  const wrapText = node.getAttribute("wrapText");
3607
3620
  const indent = node.getAttribute("indent");
3621
+ const shrinkToFit = node.getAttribute("shrinkToFit");
3622
+ const textRotation = node.getAttribute("textRotation");
3608
3623
  if (horizontal) {
3609
3624
  alignment.horizontal = horizontal;
3610
3625
  }
@@ -3614,9 +3629,18 @@ function parseSpreadsheetAlignment(node) {
3614
3629
  if (wrapText !== null) {
3615
3630
  alignment.wrapText = wrapText === "1";
3616
3631
  }
3632
+ if (shrinkToFit !== null) {
3633
+ alignment.shrinkToFit = shrinkToFit === "1";
3634
+ }
3617
3635
  if (indent !== null) {
3618
3636
  alignment.indent = Number(indent);
3619
3637
  }
3638
+ if (textRotation !== null) {
3639
+ const parsedRotation = Number(textRotation);
3640
+ if (Number.isFinite(parsedRotation)) {
3641
+ alignment.textRotation = parsedRotation;
3642
+ }
3643
+ }
3620
3644
  return Object.keys(alignment).length > 0 ? alignment : void 0;
3621
3645
  }
3622
3646
  function parseDifferentialStyle(node) {
@@ -4290,18 +4314,22 @@ function isLegacyXlsWorkbook(bytes) {
4290
4314
  function shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing = false) {
4291
4315
  return skipXmlParsing || isLegacyXlsWorkbook(bytes);
4292
4316
  }
4317
+ function normalizeWorksheetVisibility2(value) {
4318
+ return value === "hidden" || value === "veryHidden" ? value : "visible";
4319
+ }
4293
4320
  var workbook = null;
4294
4321
  var chartsByWorkbookSheetIndex = [];
4295
4322
  var chartsheets = [];
4296
4323
  var sheets = [];
4297
4324
  var tablesByWorkbookSheetIndex = [];
4298
4325
  var tabs = [];
4299
- function buildVisibleSheetIndexByWorkbookSheetIndex(nextWorkbook) {
4326
+ function buildVisibleSheetIndexByWorkbookSheetIndex(nextWorkbook, showHiddenSheets = false) {
4300
4327
  const mapping = /* @__PURE__ */ new Map();
4301
4328
  let visibleIndex = 0;
4302
4329
  for (let workbookSheetIndex = 0; workbookSheetIndex < nextWorkbook.sheetCount; workbookSheetIndex += 1) {
4303
4330
  const worksheet = nextWorkbook.getSheet(workbookSheetIndex);
4304
- if (worksheet.visibility !== "visible") {
4331
+ const visibility = normalizeWorksheetVisibility2(worksheet.visibility);
4332
+ if (!showHiddenSheets && visibility !== "visible") {
4305
4333
  continue;
4306
4334
  }
4307
4335
  mapping.set(workbookSheetIndex, visibleIndex);
@@ -4397,12 +4425,13 @@ function resolveWorksheetZoomScale(worksheet, sheetState) {
4397
4425
  const value = candidates.find((entry) => typeof entry === "number" && Number.isFinite(entry) && entry > 0);
4398
4426
  return value ?? DEFAULT_ZOOM_SCALE;
4399
4427
  }
4400
- function buildSheetList(nextWorkbook, structureAssets) {
4428
+ function buildSheetList(nextWorkbook, structureAssets, showHiddenSheets = false) {
4401
4429
  const sheetsByWorkbookSheetIndex = [];
4402
4430
  for (let index = 0; index < nextWorkbook.sheetCount; index += 1) {
4403
4431
  const worksheet = nextWorkbook.getSheet(index);
4404
4432
  const sheetState = structureAssets?.sheetStatesByWorkbookSheetIndex[index] ?? null;
4405
- if (worksheet.visibility !== "visible") {
4433
+ const visibility = normalizeWorksheetVisibility2(worksheet.visibility);
4434
+ if (!showHiddenSheets && visibility !== "visible") {
4406
4435
  continue;
4407
4436
  }
4408
4437
  const resolveColumnWidthPx = (col) => {
@@ -4439,9 +4468,12 @@ function buildSheetList(nextWorkbook, structureAssets) {
4439
4468
  maxVerticalMergeEndRow: sheetState?.maxVerticalMergeEndRow ?? -1,
4440
4469
  hiddenCols: sheetState?.hiddenCols ?? [],
4441
4470
  hiddenRows: sheetState?.hiddenRows ?? [],
4471
+ minUsedCol: -1,
4472
+ minUsedRow: -1,
4442
4473
  maxUsedCol: -1,
4443
4474
  maxUsedRow: -1,
4444
4475
  name: worksheet.name,
4476
+ visibility,
4445
4477
  namedCellStyleByName: structureAssets?.namedCellStyleByName ?? {},
4446
4478
  rowCount: 0,
4447
4479
  rowHeightOverridesPx: sheetState?.rowHeightOverridesPx ?? {},
@@ -4459,7 +4491,7 @@ function buildSheetList(nextWorkbook, structureAssets) {
4459
4491
  });
4460
4492
  continue;
4461
4493
  }
4462
- const [, , maxRow, maxCol] = usedRange;
4494
+ const [minRow, minCol, maxRow, maxCol] = usedRange;
4463
4495
  const hiddenRows = (sheetState?.hiddenRows ?? []).filter((row) => row >= 0 && row <= maxRow);
4464
4496
  const hiddenCols = (sheetState?.hiddenCols ?? []).filter((col) => col >= 0 && col <= maxCol);
4465
4497
  sheetsByWorkbookSheetIndex.push({
@@ -4480,9 +4512,12 @@ function buildSheetList(nextWorkbook, structureAssets) {
4480
4512
  maxVerticalMergeEndRow: sheetState?.maxVerticalMergeEndRow ?? -1,
4481
4513
  hiddenCols,
4482
4514
  hiddenRows,
4515
+ minUsedCol: minCol,
4516
+ minUsedRow: minRow,
4483
4517
  maxUsedCol: maxCol,
4484
4518
  maxUsedRow: maxRow,
4485
4519
  name: worksheet.name,
4520
+ visibility,
4486
4521
  namedCellStyleByName: structureAssets?.namedCellStyleByName ?? {},
4487
4522
  rowCount: Math.max(0, maxRow + 1 - hiddenRows.length),
4488
4523
  rowHeightOverridesPx: sheetState?.rowHeightOverridesPx ?? {},
@@ -4566,7 +4601,7 @@ function cellAddressToA1(cell) {
4566
4601
  }
4567
4602
  return `${label}${cell.row + 1}`;
4568
4603
  }
4569
- async function loadWorkbook(buffer, skipXmlParsing = false) {
4604
+ async function loadWorkbook(buffer, skipXmlParsing = false, showHiddenSheets = false) {
4570
4605
  const wasmModule = await getSheetsWasmModule();
4571
4606
  const bytes = new Uint8Array(buffer);
4572
4607
  const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing);
@@ -4583,7 +4618,7 @@ async function loadWorkbook(buffer, skipXmlParsing = false) {
4583
4618
  includeCachedFormulaValues: true
4584
4619
  });
4585
4620
  workbook = nextWorkbook;
4586
- sheets = buildSheetList(nextWorkbook, structureAssets);
4621
+ sheets = buildSheetList(nextWorkbook, structureAssets, showHiddenSheets);
4587
4622
  tablesByWorkbookSheetIndex = Array.from(
4588
4623
  { length: nextWorkbook.sheetCount },
4589
4624
  (_, workbookSheetIndex) => mapWorksheetTables(
@@ -4599,7 +4634,12 @@ async function loadWorkbook(buffer, skipXmlParsing = false) {
4599
4634
  return hasClassicCharts || hasModernCharts;
4600
4635
  }).some(Boolean);
4601
4636
  const chartStyleAssets = effectiveSkipXmlParsing || !hasCharts ? null : parseWorkbookChartStyleAssets(bytes);
4602
- const chartAssets = loadWorkbookChartAssets(nextWorkbook, chartStyleAssets, visibleSheetIndexByWorkbookSheetIndex);
4637
+ const chartAssets = loadWorkbookChartAssets(
4638
+ nextWorkbook,
4639
+ chartStyleAssets,
4640
+ visibleSheetIndexByWorkbookSheetIndex,
4641
+ showHiddenSheets
4642
+ );
4603
4643
  chartsByWorkbookSheetIndex = chartAssets.chartsByWorkbookSheetIndex;
4604
4644
  chartsheets = chartAssets.chartsheets;
4605
4645
  tabs = chartAssets.tabs;
@@ -4611,7 +4651,7 @@ async function loadWorkbook(buffer, skipXmlParsing = false) {
4611
4651
  tabs
4612
4652
  };
4613
4653
  }
4614
- async function parseCharts(buffer, skipXmlParsing = false) {
4654
+ async function parseCharts(buffer, skipXmlParsing = false, showHiddenSheets = false) {
4615
4655
  const wasmModule = await getSheetsWasmModule();
4616
4656
  const bytes = new Uint8Array(buffer);
4617
4657
  const effectiveSkipXmlParsing = shouldSkipXmlParsingForWorkbook(bytes, skipXmlParsing);
@@ -4623,9 +4663,14 @@ async function parseCharts(buffer, skipXmlParsing = false) {
4623
4663
  if (totalFormulas <= FORMULA_COUNT_THRESHOLD) {
4624
4664
  nextWorkbook.calculate();
4625
4665
  }
4626
- const visibleSheetIndexByWorkbookSheetIndex = buildVisibleSheetIndexByWorkbookSheetIndex(nextWorkbook);
4666
+ const visibleSheetIndexByWorkbookSheetIndex = buildVisibleSheetIndexByWorkbookSheetIndex(nextWorkbook, showHiddenSheets);
4627
4667
  const chartStyleAssets = effectiveSkipXmlParsing ? null : parseWorkbookChartStyleAssets(bytes);
4628
- const chartAssets = loadWorkbookChartAssets(nextWorkbook, chartStyleAssets, visibleSheetIndexByWorkbookSheetIndex);
4668
+ const chartAssets = loadWorkbookChartAssets(
4669
+ nextWorkbook,
4670
+ chartStyleAssets,
4671
+ visibleSheetIndexByWorkbookSheetIndex,
4672
+ showHiddenSheets
4673
+ );
4629
4674
  return {
4630
4675
  chartsByWorkbookSheetIndex: chartAssets.chartsByWorkbookSheetIndex,
4631
4676
  chartsheets: chartAssets.chartsheets,
@@ -4638,10 +4683,10 @@ function respond(message) {
4638
4683
  async function handleMessage(message) {
4639
4684
  switch (message.type) {
4640
4685
  case "load": {
4641
- return loadWorkbook(message.payload.buffer, message.payload.skipXmlParsing);
4686
+ return loadWorkbook(message.payload.buffer, message.payload.skipXmlParsing, message.payload.showHiddenSheets);
4642
4687
  }
4643
4688
  case "parseCharts": {
4644
- return parseCharts(message.payload.buffer, message.payload.skipXmlParsing);
4689
+ return parseCharts(message.payload.buffer, message.payload.skipXmlParsing, message.payload.showHiddenSheets);
4645
4690
  }
4646
4691
  case "getCellSnapshot": {
4647
4692
  if (!workbook) {