@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 +93 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +93 -21
- package/dist/index.js.map +1 -1
- package/dist/xlsx-worker.js +40 -19
- package/dist/xlsx-worker.js.map +1 -1
- package/package.json +2 -2
package/dist/xlsx-worker.js
CHANGED
|
@@ -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";
|
|
@@ -3596,6 +3604,12 @@ function parseSpreadsheetFont(node) {
|
|
|
3596
3604
|
return void 0;
|
|
3597
3605
|
}
|
|
3598
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
|
+
}
|
|
3599
3613
|
const size = getFirstChild(node, "sz")?.getAttribute("val");
|
|
3600
3614
|
const name = getFirstChild(node, "name")?.getAttribute("val");
|
|
3601
3615
|
const family = getFirstChild(node, "family")?.getAttribute("val");
|
|
@@ -3603,15 +3617,6 @@ function parseSpreadsheetFont(node) {
|
|
|
3603
3617
|
const charset = getFirstChild(node, "charset")?.getAttribute("val");
|
|
3604
3618
|
const verticalAlign = getFirstChild(node, "vertAlign")?.getAttribute("val");
|
|
3605
3619
|
const color = parseSpreadsheetColor(getFirstChild(node, "color"));
|
|
3606
|
-
if (hasEnabledSpreadsheetFlag(getFirstChild(node, "b"))) {
|
|
3607
|
-
font.bold = true;
|
|
3608
|
-
}
|
|
3609
|
-
if (hasEnabledSpreadsheetFlag(getFirstChild(node, "i"))) {
|
|
3610
|
-
font.italic = true;
|
|
3611
|
-
}
|
|
3612
|
-
if (hasEnabledSpreadsheetFlag(getFirstChild(node, "strike"))) {
|
|
3613
|
-
font.strikethrough = true;
|
|
3614
|
-
}
|
|
3615
3620
|
if (getFirstChild(node, "u")) {
|
|
3616
3621
|
font.underline = getFirstChild(node, "u")?.getAttribute("val") ?? "single";
|
|
3617
3622
|
}
|
|
@@ -3860,7 +3865,14 @@ function parseWorkbookStyles(archive) {
|
|
|
3860
3865
|
const styleById = {};
|
|
3861
3866
|
const tableStyleByName = {};
|
|
3862
3867
|
getChildElements(cellXfsNode, "xf").forEach((xfNode, index) => {
|
|
3863
|
-
|
|
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 };
|
|
3864
3876
|
});
|
|
3865
3877
|
getChildElements(cellStylesNode ?? document2.documentElement, "cellStyle").forEach((cellStyleNode) => {
|
|
3866
3878
|
const name = cellStyleNode.getAttribute("name");
|
|
@@ -4204,6 +4216,7 @@ function parseSheetState(archive, path, options) {
|
|
|
4204
4216
|
const rowHeightOverridesPx = {};
|
|
4205
4217
|
const colWidthOverridesPx = {};
|
|
4206
4218
|
const rowStyleIds = {};
|
|
4219
|
+
const cellStyleIds = {};
|
|
4207
4220
|
const colStyleIds = {};
|
|
4208
4221
|
let minContentCol = Number.POSITIVE_INFINITY;
|
|
4209
4222
|
let minContentRow = Number.POSITIVE_INFINITY;
|
|
@@ -4253,6 +4266,10 @@ function parseSheetState(archive, path, options) {
|
|
|
4253
4266
|
}
|
|
4254
4267
|
getChildElements(rowNode, "c").forEach((cellNode) => {
|
|
4255
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
|
+
}
|
|
4256
4273
|
if (isMeaningfulCellNode(cellNode)) {
|
|
4257
4274
|
trackContentCell(cellRef);
|
|
4258
4275
|
}
|
|
@@ -4291,6 +4308,7 @@ function parseSheetState(archive, path, options) {
|
|
|
4291
4308
|
return {
|
|
4292
4309
|
autoFilterRanges,
|
|
4293
4310
|
cachedFormulaValues,
|
|
4311
|
+
cellStyleIds,
|
|
4294
4312
|
columnWidthCharacterWidthPx,
|
|
4295
4313
|
colWidthOverridesPx,
|
|
4296
4314
|
colStyleIds,
|
|
@@ -5012,7 +5030,7 @@ function resolveSheetDisplayUsedRange(usedRange, sheetState) {
|
|
|
5012
5030
|
maxMeaningfulCol >= 0 ? maxContentCol >= 0 ? Math.min(maxCol, maxMeaningfulCol) : Math.max(maxCol, maxMeaningfulCol) : maxCol
|
|
5013
5031
|
];
|
|
5014
5032
|
}
|
|
5015
|
-
function buildSheetList(nextWorkbook, structureAssets, sheetLayoutStates, showHiddenSheets = false) {
|
|
5033
|
+
function buildSheetList(nextWorkbook, themePalette, structureAssets, sheetLayoutStates, showHiddenSheets = false) {
|
|
5016
5034
|
const sheetsByWorkbookSheetIndex = [];
|
|
5017
5035
|
for (let index = 0; index < nextWorkbook.sheetCount; index += 1) {
|
|
5018
5036
|
const worksheet = nextWorkbook.getSheet(index);
|
|
@@ -5082,11 +5100,12 @@ function buildSheetList(nextWorkbook, structureAssets, sheetLayoutStates, showHi
|
|
|
5082
5100
|
rowHeightOverridesPx: sheetState?.rowHeightOverridesPx ?? {},
|
|
5083
5101
|
rowHeights: [],
|
|
5084
5102
|
rowStyleIds: sheetState?.rowStyleIds ?? {},
|
|
5103
|
+
cellStyleIds: sheetState?.cellStyleIds ?? {},
|
|
5085
5104
|
showGridLines: sheetState?.showGridLines ?? true,
|
|
5086
5105
|
sparklines: sheetState?.sparklines ?? [],
|
|
5087
5106
|
styleById: structureAssets?.styleById ?? {},
|
|
5088
5107
|
tableStyleByName: structureAssets?.tableStyleByName ?? {},
|
|
5089
|
-
themePalette
|
|
5108
|
+
themePalette,
|
|
5090
5109
|
visibleCols: [],
|
|
5091
5110
|
visibleRows: [],
|
|
5092
5111
|
workbookSheetIndex: index,
|
|
@@ -5144,11 +5163,12 @@ function buildSheetList(nextWorkbook, structureAssets, sheetLayoutStates, showHi
|
|
|
5144
5163
|
rowHeightOverridesPx: sheetState?.rowHeightOverridesPx ?? {},
|
|
5145
5164
|
rowHeights: visibleRows.map(resolveRowHeightPx),
|
|
5146
5165
|
rowStyleIds: sheetState?.rowStyleIds ?? {},
|
|
5166
|
+
cellStyleIds: sheetState?.cellStyleIds ?? {},
|
|
5147
5167
|
showGridLines: sheetState?.showGridLines ?? true,
|
|
5148
5168
|
sparklines: sheetState?.sparklines ?? [],
|
|
5149
5169
|
styleById: structureAssets?.styleById ?? {},
|
|
5150
5170
|
tableStyleByName: structureAssets?.tableStyleByName ?? {},
|
|
5151
|
-
themePalette
|
|
5171
|
+
themePalette,
|
|
5152
5172
|
visibleCols,
|
|
5153
5173
|
visibleRows,
|
|
5154
5174
|
workbookSheetIndex: index,
|
|
@@ -5298,9 +5318,10 @@ async function loadWorkbook(buffer, skipXmlParsing = false, showHiddenSheets = f
|
|
|
5298
5318
|
const structureAssets = effectiveSkipXmlParsing || shouldUseFastStructureParse || !canParseXmlInWorker() ? null : parseWorkbookStructureAssets(bytes, {
|
|
5299
5319
|
includeCachedFormulaValues: true
|
|
5300
5320
|
});
|
|
5321
|
+
const themePalette = structureAssets?.themePalette ?? buildThemePaletteFromHex(nextWorkbook.themePalette);
|
|
5301
5322
|
formControlsByWorkbookSheetIndex = collectWorkbookFormControls(
|
|
5302
5323
|
nextWorkbook,
|
|
5303
|
-
|
|
5324
|
+
themePalette
|
|
5304
5325
|
).map(
|
|
5305
5326
|
(controls, workbookSheetIndex) => controls.map((control) => ({
|
|
5306
5327
|
...control,
|
|
@@ -5309,7 +5330,7 @@ async function loadWorkbook(buffer, skipXmlParsing = false, showHiddenSheets = f
|
|
|
5309
5330
|
);
|
|
5310
5331
|
const sheetLayoutStates = structureAssets ? void 0 : parseWorkerSheetLayoutAssets(bytes, nextWorkbook.sheetCount);
|
|
5311
5332
|
workbook = nextWorkbook;
|
|
5312
|
-
sheets = buildSheetList(nextWorkbook, structureAssets, sheetLayoutStates, showHiddenSheets);
|
|
5333
|
+
sheets = buildSheetList(nextWorkbook, themePalette, structureAssets, sheetLayoutStates, showHiddenSheets);
|
|
5313
5334
|
tablesByWorkbookSheetIndex = Array.from(
|
|
5314
5335
|
{ length: nextWorkbook.sheetCount },
|
|
5315
5336
|
(_, workbookSheetIndex) => mapWorksheetTables(
|