@extend-ai/react-xlsx 0.16.6 → 0.17.1

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.
@@ -3003,9 +3003,6 @@ function loadWorkbookChartAssets(workbook2, imageAssets, visibleSheetIndexByWork
3003
3003
  };
3004
3004
  }
3005
3005
 
3006
- // src/images.ts
3007
- import { strFromU8 as strFromU82, strToU8 as strToU82, unzipSync, zipSync } from "fflate";
3008
-
3009
3006
  // src/colors.ts
3010
3007
  function normalizeHexColor2(value) {
3011
3008
  const hex = value.replace(/^#/, "");
@@ -3101,6 +3098,16 @@ function applyExcelTint(baseColor, tint) {
3101
3098
  const [nextRed, nextGreen, nextBlue] = hslToRgb2(hue, saturation, Math.max(0, Math.min(1, nextLightness)));
3102
3099
  return rgbToHex2(nextRed, nextGreen, nextBlue);
3103
3100
  }
3101
+ function buildThemePaletteFromHex(hexColors) {
3102
+ const colorsByIndex = {};
3103
+ hexColors.forEach((hex, index) => {
3104
+ const color = normalizeHexColor2(hex);
3105
+ if (color) {
3106
+ colorsByIndex[index] = color;
3107
+ }
3108
+ });
3109
+ return { colorsByIndex };
3110
+ }
3104
3111
  function resolveWorkbookColor(color, themePalette) {
3105
3112
  if (!color) {
3106
3113
  return null;
@@ -3109,7 +3116,7 @@ function resolveWorkbookColor(color, themePalette) {
3109
3116
  if (directHex) {
3110
3117
  return normalizeHexColor2(directHex);
3111
3118
  }
3112
- const themeValue = color.theme;
3119
+ const themeValue = color.theme ?? color.themeIndex;
3113
3120
  const numericTheme = typeof themeValue === "number" ? themeValue : typeof themeValue === "string" && themeValue.trim().length > 0 ? Number(themeValue) : Number.NaN;
3114
3121
  const themeColor = Number.isFinite(numericTheme) ? themePalette?.colorsByIndex[numericTheme] ?? null : null;
3115
3122
  if (!themeColor) {
@@ -3121,6 +3128,7 @@ function resolveWorkbookColor(color, themePalette) {
3121
3128
  }
3122
3129
 
3123
3130
  // src/images.ts
3131
+ import { strFromU8 as strFromU82, strToU8 as strToU82, unzipSync, zipSync } from "fflate";
3124
3132
  var REL_NS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
3125
3133
  var SPREADSHEET_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
3126
3134
  var DRAWING_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing";
@@ -3175,7 +3183,8 @@ function resolveWorksheetMergeMetadata(worksheet) {
3175
3183
  hasHorizontalMerges: false,
3176
3184
  hasVerticalMerges: false,
3177
3185
  maxHorizontalMergeEndCol: -1,
3178
- maxVerticalMergeEndRow: -1
3186
+ maxVerticalMergeEndRow: -1,
3187
+ mergedRanges: []
3179
3188
  };
3180
3189
  const mergedRegions = Array.isArray(worksheet.mergedRegions) ? worksheet.mergedRegions : [];
3181
3190
  for (const rawRegion of mergedRegions) {
@@ -3206,6 +3215,7 @@ function resolveWorksheetMergeMetadata(worksheet) {
3206
3215
  if (!range) {
3207
3216
  continue;
3208
3217
  }
3218
+ mergeMetadata.mergedRanges.push(range);
3209
3219
  if (range.end.col > range.start.col) {
3210
3220
  mergeMetadata.hasHorizontalMerges = true;
3211
3221
  mergeMetadata.maxHorizontalMergeEndCol = Math.max(mergeMetadata.maxHorizontalMergeEndCol, range.end.col);
@@ -3594,6 +3604,12 @@ function parseSpreadsheetFont(node) {
3594
3604
  return void 0;
3595
3605
  }
3596
3606
  const font = {};
3607
+ for (const [tag, property] of [["b", "bold"], ["i", "italic"], ["strike", "strikethrough"]]) {
3608
+ const flag = getFirstChild(node, tag);
3609
+ if (flag) {
3610
+ font[property] = hasEnabledSpreadsheetFlag(flag);
3611
+ }
3612
+ }
3597
3613
  const size = getFirstChild(node, "sz")?.getAttribute("val");
3598
3614
  const name = getFirstChild(node, "name")?.getAttribute("val");
3599
3615
  const family = getFirstChild(node, "family")?.getAttribute("val");
@@ -3601,15 +3617,6 @@ function parseSpreadsheetFont(node) {
3601
3617
  const charset = getFirstChild(node, "charset")?.getAttribute("val");
3602
3618
  const verticalAlign = getFirstChild(node, "vertAlign")?.getAttribute("val");
3603
3619
  const color = parseSpreadsheetColor(getFirstChild(node, "color"));
3604
- if (hasEnabledSpreadsheetFlag(getFirstChild(node, "b"))) {
3605
- font.bold = true;
3606
- }
3607
- if (hasEnabledSpreadsheetFlag(getFirstChild(node, "i"))) {
3608
- font.italic = true;
3609
- }
3610
- if (hasEnabledSpreadsheetFlag(getFirstChild(node, "strike"))) {
3611
- font.strikethrough = true;
3612
- }
3613
3620
  if (getFirstChild(node, "u")) {
3614
3621
  font.underline = getFirstChild(node, "u")?.getAttribute("val") ?? "single";
3615
3622
  }
@@ -3858,7 +3865,14 @@ function parseWorkbookStyles(archive) {
3858
3865
  const styleById = {};
3859
3866
  const tableStyleByName = {};
3860
3867
  getChildElements(cellXfsNode, "xf").forEach((xfNode, index) => {
3861
- styleById[index] = parseResolvedXfStyle(xfNode, fonts, fills, borders, checkboxComplementIndices);
3868
+ const style = parseResolvedXfStyle(xfNode, fonts, fills, borders, checkboxComplementIndices);
3869
+ const overrides = {};
3870
+ for (const component of ["font", "fill", "border"]) {
3871
+ if (Number(xfNode.getAttribute(`${component}Id`) ?? 0) > 0 && xfNode.getAttribute(`apply${component[0].toUpperCase()}${component.slice(1)}`) !== "0") {
3872
+ Object.assign(overrides, { [component]: style[component] });
3873
+ }
3874
+ }
3875
+ styleById[index] = { ...style, tableStyleOverrides: overrides };
3862
3876
  });
3863
3877
  getChildElements(cellStylesNode ?? document2.documentElement, "cellStyle").forEach((cellStyleNode) => {
3864
3878
  const name = cellStyleNode.getAttribute("name");
@@ -4202,6 +4216,7 @@ function parseSheetState(archive, path, options) {
4202
4216
  const rowHeightOverridesPx = {};
4203
4217
  const colWidthOverridesPx = {};
4204
4218
  const rowStyleIds = {};
4219
+ const cellStyleIds = {};
4205
4220
  const colStyleIds = {};
4206
4221
  let minContentCol = Number.POSITIVE_INFINITY;
4207
4222
  let minContentRow = Number.POSITIVE_INFINITY;
@@ -4251,6 +4266,10 @@ function parseSheetState(archive, path, options) {
4251
4266
  }
4252
4267
  getChildElements(rowNode, "c").forEach((cellNode) => {
4253
4268
  const cellRef = cellNode.getAttribute("r");
4269
+ const cellStyleId = Number(cellNode.getAttribute("s") ?? Number.NaN);
4270
+ if (cellRef && Number.isFinite(cellStyleId)) {
4271
+ cellStyleIds[cellRef] = cellStyleId;
4272
+ }
4254
4273
  if (isMeaningfulCellNode(cellNode)) {
4255
4274
  trackContentCell(cellRef);
4256
4275
  }
@@ -4289,6 +4308,7 @@ function parseSheetState(archive, path, options) {
4289
4308
  return {
4290
4309
  autoFilterRanges,
4291
4310
  cachedFormulaValues,
4311
+ cellStyleIds,
4292
4312
  columnWidthCharacterWidthPx,
4293
4313
  colWidthOverridesPx,
4294
4314
  colStyleIds,
@@ -5010,7 +5030,7 @@ function resolveSheetDisplayUsedRange(usedRange, sheetState) {
5010
5030
  maxMeaningfulCol >= 0 ? maxContentCol >= 0 ? Math.min(maxCol, maxMeaningfulCol) : Math.max(maxCol, maxMeaningfulCol) : maxCol
5011
5031
  ];
5012
5032
  }
5013
- function buildSheetList(nextWorkbook, structureAssets, sheetLayoutStates, showHiddenSheets = false) {
5033
+ function buildSheetList(nextWorkbook, themePalette, structureAssets, sheetLayoutStates, showHiddenSheets = false) {
5014
5034
  const sheetsByWorkbookSheetIndex = [];
5015
5035
  for (let index = 0; index < nextWorkbook.sheetCount; index += 1) {
5016
5036
  const worksheet = nextWorkbook.getSheet(index);
@@ -5066,6 +5086,7 @@ function buildSheetList(nextWorkbook, structureAssets, sheetLayoutStates, showHi
5066
5086
  hasVerticalMerges: mergeMetadata.hasVerticalMerges,
5067
5087
  maxHorizontalMergeEndCol: mergeMetadata.maxHorizontalMergeEndCol,
5068
5088
  maxVerticalMergeEndRow: mergeMetadata.maxVerticalMergeEndRow,
5089
+ mergedRanges: mergeMetadata.mergedRanges,
5069
5090
  hiddenCols: sheetState?.hiddenCols ?? [],
5070
5091
  hiddenRows: sheetState?.hiddenRows ?? [],
5071
5092
  minUsedCol: -1,
@@ -5079,11 +5100,12 @@ function buildSheetList(nextWorkbook, structureAssets, sheetLayoutStates, showHi
5079
5100
  rowHeightOverridesPx: sheetState?.rowHeightOverridesPx ?? {},
5080
5101
  rowHeights: [],
5081
5102
  rowStyleIds: sheetState?.rowStyleIds ?? {},
5103
+ cellStyleIds: sheetState?.cellStyleIds ?? {},
5082
5104
  showGridLines: sheetState?.showGridLines ?? true,
5083
5105
  sparklines: sheetState?.sparklines ?? [],
5084
5106
  styleById: structureAssets?.styleById ?? {},
5085
5107
  tableStyleByName: structureAssets?.tableStyleByName ?? {},
5086
- themePalette: structureAssets?.themePalette ?? { colorsByIndex: {} },
5108
+ themePalette,
5087
5109
  visibleCols: [],
5088
5110
  visibleRows: [],
5089
5111
  workbookSheetIndex: index,
@@ -5127,6 +5149,7 @@ function buildSheetList(nextWorkbook, structureAssets, sheetLayoutStates, showHi
5127
5149
  hasVerticalMerges: mergeMetadata.hasVerticalMerges,
5128
5150
  maxHorizontalMergeEndCol: mergeMetadata.maxHorizontalMergeEndCol,
5129
5151
  maxVerticalMergeEndRow: mergeMetadata.maxVerticalMergeEndRow,
5152
+ mergedRanges: mergeMetadata.mergedRanges,
5130
5153
  hiddenCols,
5131
5154
  hiddenRows,
5132
5155
  minUsedCol: minCol,
@@ -5140,11 +5163,12 @@ function buildSheetList(nextWorkbook, structureAssets, sheetLayoutStates, showHi
5140
5163
  rowHeightOverridesPx: sheetState?.rowHeightOverridesPx ?? {},
5141
5164
  rowHeights: visibleRows.map(resolveRowHeightPx),
5142
5165
  rowStyleIds: sheetState?.rowStyleIds ?? {},
5166
+ cellStyleIds: sheetState?.cellStyleIds ?? {},
5143
5167
  showGridLines: sheetState?.showGridLines ?? true,
5144
5168
  sparklines: sheetState?.sparklines ?? [],
5145
5169
  styleById: structureAssets?.styleById ?? {},
5146
5170
  tableStyleByName: structureAssets?.tableStyleByName ?? {},
5147
- themePalette: structureAssets?.themePalette ?? { colorsByIndex: {} },
5171
+ themePalette,
5148
5172
  visibleCols,
5149
5173
  visibleRows,
5150
5174
  workbookSheetIndex: index,
@@ -5294,9 +5318,10 @@ async function loadWorkbook(buffer, skipXmlParsing = false, showHiddenSheets = f
5294
5318
  const structureAssets = effectiveSkipXmlParsing || shouldUseFastStructureParse || !canParseXmlInWorker() ? null : parseWorkbookStructureAssets(bytes, {
5295
5319
  includeCachedFormulaValues: true
5296
5320
  });
5321
+ const themePalette = structureAssets?.themePalette ?? buildThemePaletteFromHex(nextWorkbook.themePalette);
5297
5322
  formControlsByWorkbookSheetIndex = collectWorkbookFormControls(
5298
5323
  nextWorkbook,
5299
- structureAssets?.themePalette
5324
+ themePalette
5300
5325
  ).map(
5301
5326
  (controls, workbookSheetIndex) => controls.map((control) => ({
5302
5327
  ...control,
@@ -5305,7 +5330,7 @@ async function loadWorkbook(buffer, skipXmlParsing = false, showHiddenSheets = f
5305
5330
  );
5306
5331
  const sheetLayoutStates = structureAssets ? void 0 : parseWorkerSheetLayoutAssets(bytes, nextWorkbook.sheetCount);
5307
5332
  workbook = nextWorkbook;
5308
- sheets = buildSheetList(nextWorkbook, structureAssets, sheetLayoutStates, showHiddenSheets);
5333
+ sheets = buildSheetList(nextWorkbook, themePalette, structureAssets, sheetLayoutStates, showHiddenSheets);
5309
5334
  tablesByWorkbookSheetIndex = Array.from(
5310
5335
  { length: nextWorkbook.sheetCount },
5311
5336
  (_, workbookSheetIndex) => mapWorksheetTables(