@extend-ai/react-xlsx 0.14.1 → 0.15.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.
@@ -1758,7 +1758,7 @@ function normalizeChartExLegend(raw) {
1758
1758
  return null;
1759
1759
  }
1760
1760
  const legend = raw;
1761
- const position = typeof legend.pos === "string" ? normalizeLegendPosition(String(legend.pos)) : void 0;
1761
+ const position = typeof legend.position === "string" ? normalizeLegendPosition(String(legend.position)) : void 0;
1762
1762
  return {
1763
1763
  overlay: typeof legend.overlay === "boolean" ? legend.overlay : void 0,
1764
1764
  position,
@@ -1879,11 +1879,11 @@ function buildChartExHistogramBins(values, rawSeries, sortByFrequency) {
1879
1879
  return [];
1880
1880
  }
1881
1881
  const rawRecord = rawSeries && typeof rawSeries === "object" ? rawSeries : null;
1882
- const layoutProperties = rawRecord?.layoutPr && typeof rawRecord.layoutPr === "object" ? rawRecord.layoutPr : null;
1882
+ const layoutProperties = rawRecord?.layoutProperties && typeof rawRecord.layoutProperties === "object" ? rawRecord.layoutProperties : null;
1883
1883
  const rawBinning = layoutProperties?.binning && typeof layoutProperties.binning === "object" ? layoutProperties.binning : null;
1884
1884
  const minValue = Math.min(...values);
1885
1885
  const maxValue = Math.max(...values);
1886
- const explicitWidth = typeof rawBinning?.binWidth === "number" && Number.isFinite(rawBinning.binWidth) && rawBinning.binWidth > 0 ? rawBinning.binWidth : typeof rawBinning?.width === "number" && Number.isFinite(rawBinning.width) && rawBinning.width > 0 ? rawBinning.width : void 0;
1886
+ const explicitWidth = typeof rawBinning?.binSize === "number" && Number.isFinite(rawBinning.binSize) && rawBinning.binSize > 0 ? rawBinning.binSize : void 0;
1887
1887
  const explicitCount = typeof rawBinning?.binCount === "number" && Number.isFinite(rawBinning.binCount) && rawBinning.binCount > 0 ? rawBinning.binCount : typeof rawBinning?.count === "number" && Number.isFinite(rawBinning.count) && rawBinning.count > 0 ? rawBinning.count : void 0;
1888
1888
  const closedRight = rawBinning?.intervalClosed === "r" || rawBinning?.intervalClosed === "right";
1889
1889
  const mean = values.reduce((sum, value) => sum + value, 0) / values.length;
@@ -1936,7 +1936,7 @@ function buildChartExHistogramSeries(series, rawSeries, sortByFrequency) {
1936
1936
  const layout = resolveChartExSeriesLayout(rawSeries);
1937
1937
  const rawRecord = rawSeries && typeof rawSeries === "object" ? rawSeries : null;
1938
1938
  const hasBinning = Boolean(
1939
- layout === "clusteredColumn" && rawRecord?.layoutPr && typeof rawRecord.layoutPr === "object" && rawRecord.layoutPr.binning != null
1939
+ layout === "clusteredColumn" && rawRecord?.layoutProperties && typeof rawRecord.layoutProperties === "object" && rawRecord.layoutProperties.binning != null
1940
1940
  );
1941
1941
  if (!hasBinning) {
1942
1942
  return series;
@@ -2148,7 +2148,8 @@ function collapseChartExPointSeries(chartType, series) {
2148
2148
  ];
2149
2149
  }
2150
2150
  function normalizeChartExChart(workbook2, workbookSheetIndex, visibleSheetIndex, raw, index, themePalette) {
2151
- const chart = raw && typeof raw === "object" ? raw : {};
2151
+ const drawing = raw && typeof raw === "object" ? raw : {};
2152
+ const chart = drawing.chartEx && typeof drawing.chartEx === "object" ? drawing.chartEx : {};
2152
2153
  const plotArea = chart.plotArea && typeof chart.plotArea === "object" ? chart.plotArea : {};
2153
2154
  const rawSeries = Array.isArray(plotArea.series) ? plotArea.series : [];
2154
2155
  const seriesLayouts = rawSeries.map(resolveChartExSeriesLayout);
@@ -2203,7 +2204,7 @@ function normalizeChartExChart(workbook2, workbookSheetIndex, visibleSheetIndex,
2203
2204
  }
2204
2205
  ] : [];
2205
2206
  const normalizedChart = {
2206
- anchor: normalizeChartAnchor(chart.anchor),
2207
+ anchor: normalizeChartAnchor(drawing.anchor),
2207
2208
  autoTitleDeleted: void 0,
2208
2209
  axes,
2209
2210
  axisLabelColor: void 0,
@@ -2227,7 +2228,7 @@ function normalizeChartExChart(workbook2, workbookSheetIndex, visibleSheetIndex,
2227
2228
  id: `chart-ex-${workbookSheetIndex}-${index}`,
2228
2229
  is3d: void 0,
2229
2230
  legend: normalizeChartExLegend(chart.legend),
2230
- name: chartTitle,
2231
+ name: typeof drawing.name === "string" ? drawing.name : chartTitle,
2231
2232
  overlap: void 0,
2232
2233
  plotVisibleOnly: void 0,
2233
2234
  raw: chart,
@@ -2255,7 +2256,7 @@ function normalizeChartExChart(workbook2, workbookSheetIndex, visibleSheetIndex,
2255
2256
  view3d: void 0,
2256
2257
  wireframe: void 0,
2257
2258
  workbookSheetIndex,
2258
- zIndex: index
2259
+ zIndex: Array.isArray(drawing.drawingPath) && typeof drawing.drawingPath[0] === "number" ? drawing.drawingPath[0] + 1 : index + 1
2259
2260
  };
2260
2261
  applyBuiltinChartDefaults(normalizedChart, themePalette);
2261
2262
  return normalizedChart;
@@ -2376,10 +2377,11 @@ function normalizeChartReference(raw) {
2376
2377
  return null;
2377
2378
  }
2378
2379
  const record = raw;
2380
+ const values = Array.isArray(record.numbers) ? record.numbers : Array.isArray(record.strings) ? record.strings : void 0;
2379
2381
  return {
2380
2382
  formula: typeof record.formula === "string" ? record.formula : void 0,
2381
2383
  refType: typeof record.refType === "string" ? record.refType : void 0,
2382
- values: Array.isArray(record.values) ? record.values : void 0
2384
+ values
2383
2385
  };
2384
2386
  }
2385
2387
  function normalizeChartAxis(raw) {
@@ -2399,8 +2401,8 @@ function normalizeChartAxis(raw) {
2399
2401
  logBase: typeof axis.logBase === "number" ? axis.logBase : void 0,
2400
2402
  orientation: typeof axis.orientation === "string" ? axis.orientation : void 0,
2401
2403
  majorUnit: typeof axis.majorUnit === "number" ? axis.majorUnit : void 0,
2402
- max: typeof axis.max === "number" ? axis.max : void 0,
2403
- min: typeof axis.min === "number" ? axis.min : void 0,
2404
+ max: typeof axis.maximum === "number" ? axis.maximum : void 0,
2405
+ min: typeof axis.minimum === "number" ? axis.minimum : void 0,
2404
2406
  majorGridlines: typeof axis.majorGridlines === "boolean" ? axis.majorGridlines : void 0,
2405
2407
  majorTickMark: typeof axis.majorTickMark === "string" ? axis.majorTickMark : void 0,
2406
2408
  minorUnit: typeof axis.minorUnit === "number" ? axis.minorUnit : void 0,
@@ -2523,11 +2525,11 @@ function normalizeChartDataLabels(raw) {
2523
2525
  pointLabels: pointLabels && pointLabels.length > 0 ? pointLabels : void 0,
2524
2526
  raw: labels,
2525
2527
  showBubbleSize: typeof labels.showBubbleSize === "boolean" ? labels.showBubbleSize : void 0,
2526
- showCategoryName: typeof labels.showCategoryName === "boolean" ? labels.showCategoryName : void 0,
2528
+ showCategoryName: typeof (labels.showCategoryName ?? labels.visibilityCategoryName) === "boolean" ? Boolean(labels.showCategoryName ?? labels.visibilityCategoryName) : void 0,
2527
2529
  showLegendKey: typeof labels.showLegendKey === "boolean" ? labels.showLegendKey : void 0,
2528
2530
  showPercent: typeof labels.showPercent === "boolean" ? labels.showPercent : void 0,
2529
- showSeriesName: typeof labels.showSeriesName === "boolean" ? labels.showSeriesName : void 0,
2530
- showValue: typeof labels.showValue === "boolean" ? labels.showValue : void 0
2531
+ showSeriesName: typeof (labels.showSeriesName ?? labels.visibilitySeriesName) === "boolean" ? Boolean(labels.showSeriesName ?? labels.visibilitySeriesName) : void 0,
2532
+ showValue: typeof (labels.showValue ?? labels.visibilityValue) === "boolean" ? Boolean(labels.showValue ?? labels.visibilityValue) : void 0
2531
2533
  };
2532
2534
  }
2533
2535
  function normalizeChartAnchor(raw) {
@@ -2539,19 +2541,52 @@ function normalizeChartAnchor(raw) {
2539
2541
  };
2540
2542
  }
2541
2543
  const anchor = raw;
2542
- const fromCol = typeof anchor.fromCol === "number" ? anchor.fromCol : 0;
2543
- const fromColOffsetEmu = typeof anchor.fromColOffset === "number" ? anchor.fromColOffset : 0;
2544
- const fromRow = typeof anchor.fromRow === "number" ? anchor.fromRow : 0;
2545
- const fromRowOffsetEmu = typeof anchor.fromRowOffset === "number" ? anchor.fromRowOffset : 0;
2546
- const rawToCol = typeof anchor.toCol === "number" ? anchor.toCol : null;
2547
- const rawToColOffsetEmu = typeof anchor.toColOffset === "number" ? anchor.toColOffset : 0;
2548
- const rawToRow = typeof anchor.toRow === "number" ? anchor.toRow : null;
2549
- const rawToRowOffsetEmu = typeof anchor.toRowOffset === "number" ? anchor.toRowOffset : 0;
2550
- const hasExplicitTo = rawToCol !== null && rawToRow !== null;
2551
- const collapsedWidth = hasExplicitTo && (rawToCol < fromCol || rawToCol === fromCol && rawToColOffsetEmu <= fromColOffsetEmu);
2552
- const collapsedHeight = hasExplicitTo && (rawToRow < fromRow || rawToRow === fromRow && rawToRowOffsetEmu <= fromRowOffsetEmu);
2553
- const fallbackToCol = Math.max(fromCol + 8, 8);
2554
- const fallbackToRow = Math.max(fromRow + 15, 15);
2544
+ const from = anchor.from && typeof anchor.from === "object" ? anchor.from : null;
2545
+ if (anchor.type === "oneCell") {
2546
+ return {
2547
+ from: {
2548
+ col: typeof from?.col === "number" ? from.col : 0,
2549
+ colOffsetEmu: typeof from?.colOffsetEmu === "number" ? from.colOffsetEmu : 0,
2550
+ row: typeof from?.row === "number" ? from.row : 0,
2551
+ rowOffsetEmu: typeof from?.rowOffsetEmu === "number" ? from.rowOffsetEmu : 0
2552
+ },
2553
+ kind: "one-cell",
2554
+ sizeEmu: {
2555
+ cx: typeof anchor.widthEmu === "number" ? anchor.widthEmu : 0,
2556
+ cy: typeof anchor.heightEmu === "number" ? anchor.heightEmu : 0
2557
+ }
2558
+ };
2559
+ }
2560
+ if (anchor.type === "absolute") {
2561
+ return {
2562
+ kind: "absolute",
2563
+ positionEmu: {
2564
+ x: typeof anchor.xEmu === "number" ? anchor.xEmu : 0,
2565
+ y: typeof anchor.yEmu === "number" ? anchor.yEmu : 0
2566
+ },
2567
+ sizeEmu: {
2568
+ cx: typeof anchor.widthEmu === "number" ? anchor.widthEmu : 0,
2569
+ cy: typeof anchor.heightEmu === "number" ? anchor.heightEmu : 0
2570
+ }
2571
+ };
2572
+ }
2573
+ const to = anchor.to && typeof anchor.to === "object" ? anchor.to : null;
2574
+ const fromColValue = from?.col;
2575
+ const fromColOffsetValue = from?.colOffsetEmu;
2576
+ const fromRowValue = from?.row;
2577
+ const fromRowOffsetValue = from?.rowOffsetEmu;
2578
+ const toColValue = to?.col;
2579
+ const toColOffsetValue = to?.colOffsetEmu;
2580
+ const toRowValue = to?.row;
2581
+ const toRowOffsetValue = to?.rowOffsetEmu;
2582
+ const fromCol = typeof fromColValue === "number" ? fromColValue : 0;
2583
+ const fromColOffsetEmu = typeof fromColOffsetValue === "number" ? fromColOffsetValue : 0;
2584
+ const fromRow = typeof fromRowValue === "number" ? fromRowValue : 0;
2585
+ const fromRowOffsetEmu = typeof fromRowOffsetValue === "number" ? fromRowOffsetValue : 0;
2586
+ const rawToCol = typeof toColValue === "number" ? toColValue : 0;
2587
+ const rawToColOffsetEmu = typeof toColOffsetValue === "number" ? toColOffsetValue : 0;
2588
+ const rawToRow = typeof toRowValue === "number" ? toRowValue : 0;
2589
+ const rawToRowOffsetEmu = typeof toRowOffsetValue === "number" ? toRowOffsetValue : 0;
2555
2590
  return {
2556
2591
  kind: "two-cell",
2557
2592
  from: {
@@ -2561,10 +2596,10 @@ function normalizeChartAnchor(raw) {
2561
2596
  rowOffsetEmu: fromRowOffsetEmu
2562
2597
  },
2563
2598
  to: {
2564
- col: !hasExplicitTo || collapsedWidth ? fallbackToCol : rawToCol,
2565
- colOffsetEmu: !hasExplicitTo || collapsedWidth ? 0 : rawToColOffsetEmu,
2566
- row: !hasExplicitTo || collapsedHeight ? fallbackToRow : rawToRow,
2567
- rowOffsetEmu: !hasExplicitTo || collapsedHeight ? 0 : rawToRowOffsetEmu
2599
+ col: rawToCol,
2600
+ colOffsetEmu: rawToColOffsetEmu,
2601
+ row: rawToRow,
2602
+ rowOffsetEmu: rawToRowOffsetEmu
2568
2603
  }
2569
2604
  };
2570
2605
  }
@@ -2678,7 +2713,7 @@ function normalizeChartTypeGroup(workbook2, workbookSheetIndex, chartId, raw, in
2678
2713
  chartType: typeof group.chartType === "string" ? group.chartType : "ColumnClustered",
2679
2714
  dataLabels: normalizeChartDataLabels(group.dataLabels),
2680
2715
  gapWidth: typeof group.gapWidth === "number" && Number.isFinite(group.gapWidth) ? group.gapWidth : void 0,
2681
- is3d: typeof group.is3d === "boolean" ? group.is3d : void 0,
2716
+ is3d: typeof group.is3D === "boolean" ? group.is3D : void 0,
2682
2717
  overlap: typeof group.overlap === "number" && Number.isFinite(group.overlap) ? group.overlap : void 0,
2683
2718
  raw: group,
2684
2719
  series: rawSeries.map((entry, seriesIndex) => normalizeChartSeries(workbook2, workbookSheetIndex, `${chartId}-group-${index}`, entry, seriesIndex)),
@@ -2832,20 +2867,25 @@ function applyChartOrigins(chartsByWorkbookSheetIndex2, chartOriginsById, archiv
2832
2867
  }
2833
2868
  }
2834
2869
  function loadWorkbookChartAssets(workbook2, imageAssets, visibleSheetIndexByWorkbookSheetIndex, showHiddenSheets = false) {
2870
+ const excludedChartIds = /* @__PURE__ */ new Set();
2835
2871
  const chartsByWorkbookSheetIndex2 = Array.from({ length: workbook2.sheetCount }, (_, workbookSheetIndex) => {
2836
2872
  const worksheet = workbook2.getSheet(workbookSheetIndex);
2837
- const rawCharts = Array.isArray(worksheet.charts) ? worksheet.charts : [];
2838
- const rawChartsEx = Array.isArray(worksheet.chartsEx) ? worksheet.chartsEx : [];
2873
+ const rawCharts = worksheet.charts;
2874
+ const rawChartsEx = worksheet.chartsEx;
2839
2875
  const visibleSheetIndex = visibleSheetIndexByWorkbookSheetIndex.get(workbookSheetIndex) ?? workbookSheetIndex;
2840
2876
  const classicCharts = rawCharts.map((rawChart, chartIndex) => {
2841
2877
  const chartId = `chart-${workbookSheetIndex}-${chartIndex}`;
2842
- const chart = rawChart && typeof rawChart === "object" ? rawChart : {};
2843
- const rawView3d = chart.view3d && typeof chart.view3d === "object" ? chart.view3d : null;
2878
+ if (rawChart.hidden || !rawChart.anchor) {
2879
+ excludedChartIds.add(chartId);
2880
+ }
2881
+ const drawing = rawChart && typeof rawChart === "object" ? rawChart : {};
2882
+ const chart = drawing.chart && typeof drawing.chart === "object" ? drawing.chart : {};
2883
+ const rawView3d = chart.view3D && typeof chart.view3D === "object" ? chart.view3D : null;
2844
2884
  const rawSeries = Array.isArray(chart.series) ? chart.series : [];
2845
2885
  const chartLevelDataLabels = normalizeChartDataLabels(chart.dataLabels);
2846
2886
  const firstSeriesDataLabels = rawSeries.length > 0 && rawSeries[0] && typeof rawSeries[0] === "object" ? normalizeChartDataLabels(rawSeries[0].dataLabels) : null;
2847
2887
  return {
2848
- anchor: normalizeChartAnchor(chart.anchor),
2888
+ anchor: normalizeChartAnchor(drawing.anchor),
2849
2889
  autoTitleDeleted: typeof chart.autoTitleDeleted === "boolean" ? chart.autoTitleDeleted : void 0,
2850
2890
  axes: Array.isArray(chart.axes) ? chart.axes.map(normalizeChartAxis).filter((value) => Boolean(value)) : [],
2851
2891
  axisLabelColor: void 0,
@@ -2866,12 +2906,12 @@ function loadWorkbookChartAssets(workbook2, imageAssets, visibleSheetIndexByWork
2866
2906
  gapWidth: typeof chart.gapWidth === "number" ? chart.gapWidth : void 0,
2867
2907
  holeSize: typeof chart.holeSize === "number" ? chart.holeSize : void 0,
2868
2908
  id: chartId,
2869
- is3d: typeof chart.is3d === "boolean" ? chart.is3d : void 0,
2909
+ is3d: typeof chart.is3D === "boolean" ? chart.is3D : void 0,
2870
2910
  legend: normalizeLegend(chart.legend) ? {
2871
2911
  ...normalizeLegend(chart.legend),
2872
2912
  position: normalizeLegendPosition(normalizeLegend(chart.legend)?.position)
2873
2913
  } : null,
2874
- name: typeof chart.name === "string" ? chart.name : void 0,
2914
+ name: typeof drawing.name === "string" ? drawing.name : void 0,
2875
2915
  overlap: typeof chart.overlap === "number" ? chart.overlap : void 0,
2876
2916
  plotVisibleOnly: typeof chart.plotVisibleOnly === "boolean" ? chart.plotVisibleOnly : void 0,
2877
2917
  raw: chart,
@@ -2905,17 +2945,23 @@ function loadWorkbookChartAssets(workbook2, imageAssets, visibleSheetIndexByWork
2905
2945
  } : void 0,
2906
2946
  wireframe: typeof chart.wireframe === "boolean" ? chart.wireframe : void 0,
2907
2947
  workbookSheetIndex,
2908
- zIndex: 200 + chartIndex
2948
+ zIndex: Array.isArray(drawing.drawingPath) && typeof drawing.drawingPath[0] === "number" ? drawing.drawingPath[0] + 1 : chartIndex + 1
2909
2949
  };
2910
2950
  });
2911
- const modernCharts = rawChartsEx.map((rawChartEx, chartExIndex) => normalizeChartExChart(
2912
- workbook2,
2913
- workbookSheetIndex,
2914
- visibleSheetIndex,
2915
- rawChartEx,
2916
- chartExIndex,
2917
- imageAssets?.themePalette ?? null
2918
- ));
2951
+ const modernCharts = rawChartsEx.map((rawChartEx, chartExIndex) => {
2952
+ const chartId = `chart-ex-${workbookSheetIndex}-${chartExIndex}`;
2953
+ if (rawChartEx.hidden || !rawChartEx.anchor) {
2954
+ excludedChartIds.add(chartId);
2955
+ }
2956
+ return normalizeChartExChart(
2957
+ workbook2,
2958
+ workbookSheetIndex,
2959
+ visibleSheetIndex,
2960
+ rawChartEx,
2961
+ chartExIndex,
2962
+ imageAssets?.themePalette ?? null
2963
+ );
2964
+ });
2919
2965
  return [...classicCharts, ...modernCharts];
2920
2966
  });
2921
2967
  const chartsheets2 = Array.isArray(workbook2.chartsheets) ? workbook2.chartsheets.map((entry, index) => normalizeChartsheet(entry, index)) : [];
@@ -2923,6 +2969,12 @@ function loadWorkbookChartAssets(workbook2, imageAssets, visibleSheetIndexByWork
2923
2969
  const chartOriginsById = /* @__PURE__ */ new Map();
2924
2970
  if (imageAssets) {
2925
2971
  applyChartOrigins(chartsByWorkbookSheetIndex2, chartOriginsById, imageAssets.archive, imageAssets.sheetOrigins);
2972
+ for (let index = 0; index < chartsByWorkbookSheetIndex2.length; index += 1) {
2973
+ chartsByWorkbookSheetIndex2[index] = (chartsByWorkbookSheetIndex2[index] ?? []).filter((chart) => !excludedChartIds.has(chart.id));
2974
+ }
2975
+ for (const id of excludedChartIds) {
2976
+ chartOriginsById.delete(id);
2977
+ }
2926
2978
  for (const charts of chartsByWorkbookSheetIndex2) {
2927
2979
  for (const chart of charts) {
2928
2980
  applyChartStyleFromXml(chart, chart.chartPath, imageAssets.archive, imageAssets.themePalette);
@@ -2930,6 +2982,9 @@ function loadWorkbookChartAssets(workbook2, imageAssets, visibleSheetIndexByWork
2930
2982
  }
2931
2983
  }
2932
2984
  } else {
2985
+ for (let index = 0; index < chartsByWorkbookSheetIndex2.length; index += 1) {
2986
+ chartsByWorkbookSheetIndex2[index] = (chartsByWorkbookSheetIndex2[index] ?? []).filter((chart) => !excludedChartIds.has(chart.id));
2987
+ }
2933
2988
  for (const charts of chartsByWorkbookSheetIndex2) {
2934
2989
  for (const chart of charts) {
2935
2990
  applyBuiltinChartDefaults(chart, null);
@@ -4229,55 +4284,138 @@ function normalizeHexColor3(value) {
4229
4284
  }
4230
4285
  return "#000000";
4231
4286
  }
4232
- function mapDukeFormControlAnchor(anchor) {
4287
+ function dukeDrawingAnchorToXlsxAnchor(anchor) {
4288
+ if (anchor.type === "absolute") {
4289
+ return {
4290
+ kind: "absolute",
4291
+ positionEmu: { x: anchor.xEmu, y: anchor.yEmu },
4292
+ sizeEmu: { cx: anchor.widthEmu, cy: anchor.heightEmu }
4293
+ };
4294
+ }
4295
+ const from = {
4296
+ col: anchor.from.col,
4297
+ colOffsetEmu: anchor.from.colOffsetEmu ?? 0,
4298
+ row: anchor.from.row,
4299
+ rowOffsetEmu: anchor.from.rowOffsetEmu ?? 0
4300
+ };
4301
+ if (anchor.type === "oneCell") {
4302
+ return {
4303
+ from,
4304
+ kind: "one-cell",
4305
+ sizeEmu: { cx: anchor.widthEmu, cy: anchor.heightEmu }
4306
+ };
4307
+ }
4233
4308
  return {
4234
- from: {
4235
- col: anchor.fromCol,
4236
- colOffsetEmu: anchor.fromColOffset,
4237
- row: anchor.fromRow,
4238
- rowOffsetEmu: anchor.fromRowOffset
4239
- },
4309
+ from,
4240
4310
  kind: "two-cell",
4241
4311
  to: {
4242
- col: anchor.toCol,
4243
- colOffsetEmu: anchor.toColOffset,
4244
- row: anchor.toRow,
4245
- rowOffsetEmu: anchor.toRowOffset
4312
+ col: anchor.to.col,
4313
+ colOffsetEmu: anchor.to.colOffsetEmu ?? 0,
4314
+ row: anchor.to.row,
4315
+ rowOffsetEmu: anchor.to.rowOffsetEmu ?? 0
4246
4316
  }
4247
4317
  };
4248
4318
  }
4249
- function mapDukeFormControlKind(kind) {
4319
+ function mapDukeDrawingColor(color) {
4320
+ if (!color) {
4321
+ return void 0;
4322
+ }
4323
+ switch (color.colorType) {
4324
+ case "auto":
4325
+ return { colorType: "auto" };
4326
+ case "rgb":
4327
+ return { b: color.b, colorType: "rgb", g: color.g, r: color.r };
4328
+ case "argb":
4329
+ return { a: color.a, b: color.b, colorType: "argb", g: color.g, r: color.r };
4330
+ case "theme":
4331
+ return { colorType: "theme", themeIndex: color.index, tint: color.tint };
4332
+ case "indexed":
4333
+ return { colorType: "indexed", paletteIndex: color.index };
4334
+ }
4335
+ }
4336
+ function mapDukeDrawingFont(font) {
4337
+ if (!font) {
4338
+ return void 0;
4339
+ }
4340
+ return {
4341
+ bold: font.bold,
4342
+ charset: font.charset,
4343
+ color: mapDukeDrawingColor(font.color),
4344
+ family: font.family,
4345
+ italic: font.italic,
4346
+ name: font.name,
4347
+ scheme: font.scheme,
4348
+ size: font.size,
4349
+ strikethrough: font.strikethrough,
4350
+ underline: font.underline,
4351
+ verticalAlign: font.verticalAlign
4352
+ };
4353
+ }
4354
+ function mapDukeDrawingText(text) {
4355
+ return {
4356
+ horizontalAlignment: text.horizontalAlignment,
4357
+ runs: text.runs.map((run) => ({ font: mapDukeDrawingFont(run.font), text: run.text })),
4358
+ verticalAlignment: text.verticalAlignment
4359
+ };
4360
+ }
4361
+ function resolveDukeDrawingColor(color, themePalette) {
4362
+ if (!color) {
4363
+ return void 0;
4364
+ }
4365
+ switch (color.colorType) {
4366
+ case "rgb":
4367
+ return resolveWorkbookColor({ rgb: [color.r, color.g, color.b].map((value) => value.toString(16).padStart(2, "0")).join("") }) ?? void 0;
4368
+ case "argb":
4369
+ return resolveWorkbookColor({ argb: [color.a, color.r, color.g, color.b].map((value) => value.toString(16).padStart(2, "0")).join("") }) ?? void 0;
4370
+ case "theme":
4371
+ return resolveWorkbookColor({ theme: color.index, tint: color.tint }, themePalette) ?? void 0;
4372
+ default:
4373
+ return void 0;
4374
+ }
4375
+ }
4376
+ function resolveDukeDrawingText(text, themePalette) {
4377
+ const caption = mapDukeDrawingText(text);
4378
+ const label = normalizeControlLabel(text.runs.map((run) => run.text).join(""));
4379
+ const firstStyledRun = text.runs.find((run) => run.font)?.font;
4380
+ const horizontalAlignment = text.horizontalAlignment;
4381
+ return {
4382
+ caption,
4383
+ fontFamily: firstStyledRun?.name,
4384
+ fontSizePt: firstStyledRun?.size,
4385
+ label,
4386
+ textAlign: horizontalAlignment === "left" || horizontalAlignment === "center" || horizontalAlignment === "right" ? horizontalAlignment : void 0,
4387
+ textColor: resolveDukeDrawingColor(firstStyledRun?.color, themePalette)
4388
+ };
4389
+ }
4390
+ function mapDukeFormControlKind(kind, themePalette) {
4250
4391
  switch (kind.kind) {
4251
4392
  case "button":
4252
- return { caption: kind.caption, kind: "button", label: normalizeControlLabel(kind.caption) };
4393
+ return { ...resolveDukeDrawingText(kind.caption, themePalette), kind: "button" };
4253
4394
  case "checkbox":
4254
4395
  return {
4255
- caption: kind.caption,
4396
+ ...resolveDukeDrawingText(kind.caption, themePalette),
4256
4397
  checked: kind.state === "checked",
4257
4398
  kind: "checkbox",
4258
- label: normalizeControlLabel(kind.caption),
4259
4399
  linkedCell: kind.cellLink,
4260
4400
  no3D: kind.no3D,
4261
4401
  state: kind.state
4262
4402
  };
4263
4403
  case "optionButton":
4264
4404
  return {
4265
- caption: kind.caption,
4405
+ ...resolveDukeDrawingText(kind.caption, themePalette),
4266
4406
  checked: kind.state === "checked",
4267
4407
  firstInGroup: kind.firstInGroup,
4268
4408
  kind: "radio",
4269
- label: normalizeControlLabel(kind.caption),
4270
4409
  linkedCell: kind.cellLink,
4271
4410
  no3D: kind.no3D,
4272
4411
  state: kind.state
4273
4412
  };
4274
4413
  case "label":
4275
- return { caption: kind.caption, kind: "label", label: normalizeControlLabel(kind.caption) };
4414
+ return { ...resolveDukeDrawingText(kind.caption, themePalette), kind: "label" };
4276
4415
  case "groupBox":
4277
4416
  return {
4278
- caption: kind.caption,
4417
+ ...resolveDukeDrawingText(kind.caption, themePalette),
4279
4418
  kind: "group-box",
4280
- label: normalizeControlLabel(kind.caption),
4281
4419
  no3D: kind.no3D
4282
4420
  };
4283
4421
  case "listBox":
@@ -4318,30 +4456,42 @@ function mapDukeFormControlKind(kind) {
4318
4456
  min: kind.min,
4319
4457
  value: kind.value
4320
4458
  };
4459
+ case "unknown":
4460
+ return {
4461
+ ...resolveDukeDrawingText(kind.caption, themePalette),
4462
+ kind: kind.objectType.toLowerCase() === "editbox" ? "editbox" : "unknown",
4463
+ legacyObjectType: kind.legacyObjectType,
4464
+ objectType: kind.objectType,
4465
+ rawObj: kind.rawObj,
4466
+ rawProperties: kind.rawProperties
4467
+ };
4321
4468
  }
4322
4469
  }
4323
- function mapDukeFormControl(control, controlIndex, workbookSheetIndex) {
4470
+ function mapDukeFormControl(control, controlIndex, workbookSheetIndex, themePalette) {
4324
4471
  return {
4325
- anchor: mapDukeFormControlAnchor(control.anchor),
4472
+ altText: control.altText,
4473
+ anchor: dukeDrawingAnchorToXlsxAnchor(control.anchor),
4326
4474
  controlIndex,
4327
- dukeAnchor: { ...control.anchor },
4328
- editAs: control.anchor.editAs,
4329
- hidden: false,
4475
+ editAs: control.anchor.type === "twoCell" ? control.anchor.editAs : void 0,
4476
+ hidden: control.hidden,
4330
4477
  id: `form-control-${workbookSheetIndex}-${controlIndex}`,
4331
4478
  locked: control.locked,
4479
+ macroName: control.formControl.macroName,
4332
4480
  name: control.name,
4333
4481
  printable: control.printable,
4482
+ rawClientData: control.formControl.rawClientData,
4334
4483
  sheetIndex: workbookSheetIndex,
4484
+ title: control.title,
4335
4485
  workbookSheetIndex,
4336
- zIndex: controlIndex + 1,
4337
- ...mapDukeFormControlKind(control.kind)
4486
+ zIndex: (control.drawingPath[0] ?? controlIndex) + 1,
4487
+ ...mapDukeFormControlKind(control.formControl.kind, themePalette)
4338
4488
  };
4339
4489
  }
4340
- function collectWorkbookFormControls(workbook2) {
4490
+ function collectWorkbookFormControls(workbook2, themePalette) {
4341
4491
  return Array.from({ length: workbook2.sheetCount }, (_, workbookSheetIndex) => {
4342
4492
  try {
4343
4493
  const controls = workbook2.getSheet(workbookSheetIndex).formControls;
4344
- return Array.isArray(controls) ? controls.map((control, controlIndex) => mapDukeFormControl(control, controlIndex, workbookSheetIndex)) : [];
4494
+ return Array.isArray(controls) ? controls.flatMap((control, controlIndex) => control.anchor ? [mapDukeFormControl(control, controlIndex, workbookSheetIndex, themePalette)] : []) : [];
4345
4495
  } catch {
4346
4496
  return [];
4347
4497
  }
@@ -5071,16 +5221,19 @@ async function loadWorkbook(buffer, skipXmlParsing = false, showHiddenSheets = f
5071
5221
  activeWorkbook = result.workbook;
5072
5222
  }
5073
5223
  const nextWorkbook = activeWorkbook;
5074
- formControlsByWorkbookSheetIndex = collectWorkbookFormControls(nextWorkbook).map(
5224
+ const shouldUseFastStructureParse = bytes.byteLength >= FAST_STRUCTURE_PARSE_THRESHOLD_BYTES && totalFormulas <= FORMULA_COUNT_THRESHOLD;
5225
+ const structureAssets = effectiveSkipXmlParsing || shouldUseFastStructureParse || !canParseXmlInWorker() ? null : parseWorkbookStructureAssets(bytes, {
5226
+ includeCachedFormulaValues: true
5227
+ });
5228
+ formControlsByWorkbookSheetIndex = collectWorkbookFormControls(
5229
+ nextWorkbook,
5230
+ structureAssets?.themePalette
5231
+ ).map(
5075
5232
  (controls, workbookSheetIndex) => controls.map((control) => ({
5076
5233
  ...control,
5077
5234
  items: resolveFormControlItems(nextWorkbook, workbookSheetIndex, control)
5078
5235
  }))
5079
5236
  );
5080
- const shouldUseFastStructureParse = bytes.byteLength >= FAST_STRUCTURE_PARSE_THRESHOLD_BYTES && totalFormulas <= FORMULA_COUNT_THRESHOLD;
5081
- const structureAssets = effectiveSkipXmlParsing || shouldUseFastStructureParse || !canParseXmlInWorker() ? null : parseWorkbookStructureAssets(bytes, {
5082
- includeCachedFormulaValues: true
5083
- });
5084
5237
  const sheetLayoutStates = structureAssets ? void 0 : parseWorkerSheetLayoutAssets(bytes, nextWorkbook.sheetCount);
5085
5238
  workbook = nextWorkbook;
5086
5239
  sheets = buildSheetList(nextWorkbook, structureAssets, sheetLayoutStates, showHiddenSheets);