@extend-ai/react-xlsx 0.17.0 → 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.
package/dist/index.cjs CHANGED
@@ -3632,7 +3632,7 @@ function resolveWorkbookColor(color, themePalette) {
3632
3632
  if (directHex) {
3633
3633
  return normalizeHexColor2(directHex);
3634
3634
  }
3635
- const themeValue = color.theme;
3635
+ const themeValue = color.theme ?? color.themeIndex;
3636
3636
  const numericTheme = typeof themeValue === "number" ? themeValue : typeof themeValue === "string" && themeValue.trim().length > 0 ? Number(themeValue) : Number.NaN;
3637
3637
  const themeColor = Number.isFinite(numericTheme) ? themePalette?.colorsByIndex[numericTheme] ?? null : null;
3638
3638
  if (!themeColor) {
@@ -4260,6 +4260,12 @@ function parseSpreadsheetFont(node) {
4260
4260
  return void 0;
4261
4261
  }
4262
4262
  const font = {};
4263
+ for (const [tag, property] of [["b", "bold"], ["i", "italic"], ["strike", "strikethrough"]]) {
4264
+ const flag = getFirstChild(node, tag);
4265
+ if (flag) {
4266
+ font[property] = hasEnabledSpreadsheetFlag(flag);
4267
+ }
4268
+ }
4263
4269
  const size = getFirstChild(node, "sz")?.getAttribute("val");
4264
4270
  const name = getFirstChild(node, "name")?.getAttribute("val");
4265
4271
  const family = getFirstChild(node, "family")?.getAttribute("val");
@@ -4267,15 +4273,6 @@ function parseSpreadsheetFont(node) {
4267
4273
  const charset = getFirstChild(node, "charset")?.getAttribute("val");
4268
4274
  const verticalAlign = getFirstChild(node, "vertAlign")?.getAttribute("val");
4269
4275
  const color = parseSpreadsheetColor(getFirstChild(node, "color"));
4270
- if (hasEnabledSpreadsheetFlag(getFirstChild(node, "b"))) {
4271
- font.bold = true;
4272
- }
4273
- if (hasEnabledSpreadsheetFlag(getFirstChild(node, "i"))) {
4274
- font.italic = true;
4275
- }
4276
- if (hasEnabledSpreadsheetFlag(getFirstChild(node, "strike"))) {
4277
- font.strikethrough = true;
4278
- }
4279
4276
  if (getFirstChild(node, "u")) {
4280
4277
  font.underline = getFirstChild(node, "u")?.getAttribute("val") ?? "single";
4281
4278
  }
@@ -4524,7 +4521,14 @@ function parseWorkbookStyles(archive) {
4524
4521
  const styleById = {};
4525
4522
  const tableStyleByName = {};
4526
4523
  getChildElements(cellXfsNode, "xf").forEach((xfNode, index) => {
4527
- styleById[index] = parseResolvedXfStyle(xfNode, fonts, fills, borders, checkboxComplementIndices);
4524
+ const style = parseResolvedXfStyle(xfNode, fonts, fills, borders, checkboxComplementIndices);
4525
+ const overrides = {};
4526
+ for (const component of ["font", "fill", "border"]) {
4527
+ if (Number(xfNode.getAttribute(`${component}Id`) ?? 0) > 0 && xfNode.getAttribute(`apply${component[0].toUpperCase()}${component.slice(1)}`) !== "0") {
4528
+ Object.assign(overrides, { [component]: style[component] });
4529
+ }
4530
+ }
4531
+ styleById[index] = { ...style, tableStyleOverrides: overrides };
4528
4532
  });
4529
4533
  getChildElements(cellStylesNode ?? document2.documentElement, "cellStyle").forEach((cellStyleNode) => {
4530
4534
  const name = cellStyleNode.getAttribute("name");
@@ -4868,6 +4872,7 @@ function parseSheetState(archive, path, options) {
4868
4872
  const rowHeightOverridesPx = {};
4869
4873
  const colWidthOverridesPx = {};
4870
4874
  const rowStyleIds = {};
4875
+ const cellStyleIds = {};
4871
4876
  const colStyleIds = {};
4872
4877
  let minContentCol = Number.POSITIVE_INFINITY;
4873
4878
  let minContentRow = Number.POSITIVE_INFINITY;
@@ -4917,6 +4922,10 @@ function parseSheetState(archive, path, options) {
4917
4922
  }
4918
4923
  getChildElements(rowNode, "c").forEach((cellNode) => {
4919
4924
  const cellRef = cellNode.getAttribute("r");
4925
+ const cellStyleId = Number(cellNode.getAttribute("s") ?? Number.NaN);
4926
+ if (cellRef && Number.isFinite(cellStyleId)) {
4927
+ cellStyleIds[cellRef] = cellStyleId;
4928
+ }
4920
4929
  if (isMeaningfulCellNode(cellNode)) {
4921
4930
  trackContentCell(cellRef);
4922
4931
  }
@@ -4955,6 +4964,7 @@ function parseSheetState(archive, path, options) {
4955
4964
  return {
4956
4965
  autoFilterRanges,
4957
4966
  cachedFormulaValues,
4967
+ cellStyleIds,
4958
4968
  columnWidthCharacterWidthPx,
4959
4969
  colWidthOverridesPx,
4960
4970
  colStyleIds,
@@ -7458,6 +7468,7 @@ function buildSheetList(workbook, sheetStatesByWorkbookSheetIndex, themePalette,
7458
7468
  colCount: 0,
7459
7469
  rowHeightOverridesPx: sheetState?.rowHeightOverridesPx ?? {},
7460
7470
  rowStyleIds: sheetState?.rowStyleIds ?? {},
7471
+ cellStyleIds: sheetState?.cellStyleIds ?? {},
7461
7472
  styleById: styleById ?? {},
7462
7473
  sparklines: sheetState?.sparklines ?? [],
7463
7474
  tableStyleByName: tableStyleByName ?? {},
@@ -7544,6 +7555,7 @@ function buildSheetList(workbook, sheetStatesByWorkbookSheetIndex, themePalette,
7544
7555
  namedCellStyleByName: namedCellStyleByName ?? {},
7545
7556
  rowHeightOverridesPx: sheetState?.rowHeightOverridesPx ?? {},
7546
7557
  rowStyleIds: sheetState?.rowStyleIds ?? {},
7558
+ cellStyleIds: sheetState?.cellStyleIds ?? {},
7547
7559
  showGridLines: sheetState?.showGridLines ?? true,
7548
7560
  styleById: styleById ?? {},
7549
7561
  sparklines: sheetState?.sparklines ?? [],
@@ -10007,7 +10019,7 @@ function useXlsxViewerController(options) {
10007
10019
  return;
10008
10020
  }
10009
10021
  const dataStartRow = targetTable.start.row + Math.max(targetTable.headerRowCount, 1);
10010
- const totalsRowOffset = targetTable.totalsRowShown ? Math.max(targetTable.totalsRowCount, 1) : 0;
10022
+ const totalsRowOffset = targetTable.totalsRowCount;
10011
10023
  const dataEndRow = targetTable.end.row - totalsRowOffset;
10012
10024
  const startCol = targetTable.start.col;
10013
10025
  const endCol = targetTable.end.col;
@@ -19171,7 +19183,8 @@ function applyCanvasBorderDash(context, style, width) {
19171
19183
  context.setLineDash([]);
19172
19184
  }
19173
19185
  function strokeCanvasBorderSide(context, side, rect, border) {
19174
- const halfWidth = border.width / 2;
19186
+ const strokeWidth = border.style === "double" ? border.width / 3 : border.width;
19187
+ const halfWidth = strokeWidth / 2;
19175
19188
  const left = rect.left;
19176
19189
  const right = rect.left + rect.width;
19177
19190
  const top = rect.top;
@@ -19197,8 +19210,8 @@ function strokeCanvasBorderSide(context, side, rect, border) {
19197
19210
  context.stroke();
19198
19211
  };
19199
19212
  if (border.style === "double") {
19200
- const inset = Math.max(1, border.width);
19201
- context.lineWidth = Math.max(1, border.width / 3);
19213
+ const inset = border.width - strokeWidth;
19214
+ context.lineWidth = strokeWidth;
19202
19215
  context.setLineDash([]);
19203
19216
  strokeLine(0);
19204
19217
  strokeLine(inset);
@@ -22111,6 +22124,43 @@ function mergeResolvedCellStyle(base, overlay, options) {
22111
22124
  }
22112
22125
  return nextStyle;
22113
22126
  }
22127
+ function resolveCellTableOverrides(rawStyle, sheet, row, col) {
22128
+ const styleId = sheet?.cellStyleIds?.[cellAddressToA12({ row, col })] ?? sheet?.rowStyleIds[row] ?? sheet?.colStyleIds[col];
22129
+ const declared = styleId === void 0 ? void 0 : sheet?.styleById[styleId]?.tableStyleOverrides;
22130
+ const overrides = {};
22131
+ const font = asRecord(rawStyle?.font);
22132
+ if (font) {
22133
+ const explicitFont = {};
22134
+ const fontDefaults = {
22135
+ name: "Calibri",
22136
+ size: 11,
22137
+ bold: false,
22138
+ italic: false,
22139
+ underline: "none",
22140
+ strikethrough: false,
22141
+ verticalAlign: "baseline"
22142
+ };
22143
+ for (const [key, value] of Object.entries(font)) {
22144
+ const isExplicit = declared ? Object.hasOwn(declared.font ?? {}, key) : key === "color" ? asRecord(value)?.colorType !== "auto" : value !== fontDefaults[key];
22145
+ if (isExplicit) {
22146
+ explicitFont[key] = value;
22147
+ }
22148
+ }
22149
+ overrides.font = explicitFont;
22150
+ }
22151
+ const fill = asRecord(rawStyle?.fill);
22152
+ if (fill && fill.fillType !== "none") {
22153
+ overrides.fill = fill;
22154
+ }
22155
+ const border = asRecord(rawStyle?.border);
22156
+ if (border) {
22157
+ overrides.border = Object.fromEntries(Object.entries(border).filter(([, edge]) => {
22158
+ const style = asRecord(edge)?.style;
22159
+ return typeof style === "string" && style !== "none";
22160
+ }));
22161
+ }
22162
+ return overrides;
22163
+ }
22114
22164
  function resolveBorderEdgePriority(edge) {
22115
22165
  const style = typeof edge?.style === "string" ? edge.style : "none";
22116
22166
  const stylePriority = {
@@ -22239,7 +22289,7 @@ function resolveTableCellStyle(table, row, col, activeSheet) {
22239
22289
  return null;
22240
22290
  }
22241
22291
  const headerRowCount = Math.max(table.headerRowCount, 1);
22242
- const totalsRowCount = table.totalsRowShown ? Math.max(table.totalsRowCount, 1) : 0;
22292
+ const totalsRowCount = table.totalsRowCount;
22243
22293
  const headerEndRow = table.start.row + headerRowCount - 1;
22244
22294
  const totalsStartRow = table.end.row - totalsRowCount + 1;
22245
22295
  const bodyStartRow = headerEndRow + 1;
@@ -26563,7 +26613,10 @@ function XlsxGrid({
26563
26613
  });
26564
26614
  const targetTable = getTableAtCell(effectiveTables, targetRow, targetCol);
26565
26615
  const targetTableStyle = resolveTableCellStyle(targetTable, targetRow, targetCol, activeSheet);
26566
- const resolvedStyle = mergeResolvedCellStyle(targetRawStyle, targetTableStyle);
26616
+ const resolvedStyle = targetTableStyle ? mergeResolvedCellStyle(
26617
+ mergeResolvedCellStyle(targetRawStyle, targetTableStyle),
26618
+ resolveCellTableOverrides(targetRawStyle, activeSheet, targetRow, targetCol)
26619
+ ) : targetRawStyle;
26567
26620
  cellBaseRawStyleCacheRef.current.set(targetCacheKey, resolvedStyle);
26568
26621
  return resolvedStyle;
26569
26622
  };
@@ -28934,6 +28987,14 @@ function XlsxGrid({
28934
28987
  hasPendingGridlinePath = false;
28935
28988
  };
28936
28989
  const drawnMergedAnchorKeys = /* @__PURE__ */ new Set();
28990
+ const deferredDoubleBorders = [];
28991
+ const drawCellBorder = (side, rect, border) => {
28992
+ if (border.style === "double") {
28993
+ deferredDoubleBorders.push({ side, rect, border });
28994
+ } else {
28995
+ strokeCanvasBorderSide(paneContext, side, rect, border);
28996
+ }
28997
+ };
28937
28998
  for (const rowItem of paneAxisItems.rows) {
28938
28999
  for (const colItem of paneAxisItems.cols) {
28939
29000
  const cell = { row: rowItem.actualRow, col: colItem.actualCol };
@@ -29080,16 +29141,24 @@ function XlsxGrid({
29080
29141
  flushPendingGridlines();
29081
29142
  }
29082
29143
  if (topBorder && drawRowIndex === 0) {
29083
- strokeCanvasBorderSide(paneContext, "top", localRect, topBorder);
29144
+ drawCellBorder("top", localRect, topBorder);
29084
29145
  }
29085
29146
  if (resolvedRightBorder) {
29086
- strokeCanvasBorderSide(paneContext, "right", localRect, resolvedRightBorder);
29147
+ if (resolvedRightBorder.style === "double" && resolvedRightBorder === rightNeighborLeftBorder) {
29148
+ drawCellBorder("left", { ...localRect, left: localRect.left + localRect.width }, resolvedRightBorder);
29149
+ } else {
29150
+ drawCellBorder("right", localRect, resolvedRightBorder);
29151
+ }
29087
29152
  }
29088
29153
  if (resolvedBottomBorder) {
29089
- strokeCanvasBorderSide(paneContext, "bottom", localRect, resolvedBottomBorder);
29154
+ if (resolvedBottomBorder.style === "double" && resolvedBottomBorder === bottomNeighborTopBorder) {
29155
+ drawCellBorder("top", { ...localRect, top: localRect.top + localRect.height }, resolvedBottomBorder);
29156
+ } else {
29157
+ drawCellBorder("bottom", localRect, resolvedBottomBorder);
29158
+ }
29090
29159
  }
29091
29160
  if (leftBorder && drawColIndex === 0) {
29092
- strokeCanvasBorderSide(paneContext, "left", localRect, leftBorder);
29161
+ drawCellBorder("left", localRect, leftBorder);
29093
29162
  }
29094
29163
  if (cellData.chartHighlight) {
29095
29164
  const highlightBorder = {
@@ -29362,6 +29431,9 @@ function XlsxGrid({
29362
29431
  }
29363
29432
  }
29364
29433
  flushPendingGridlines();
29434
+ for (const { side, rect, border } of deferredDoubleBorders) {
29435
+ strokeCanvasBorderSide(paneContext, side, rect, border);
29436
+ }
29365
29437
  }
29366
29438
  for (const pane of cellPaneOrder) {
29367
29439
  const paneContext = bodyContexts[pane];