ooxml-core 1.8.2 → 1.8.4
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/automation/index.cjs +7237 -7188
- package/dist/automation/index.mjs +7237 -7188
- package/dist/teams/index.cjs +79 -3
- package/dist/teams/index.mjs +79 -3
- package/dist/xlsx/edit/sheets.d.ts.map +1 -1
- package/dist/xlsx/edit/sort.d.ts +1 -1
- package/dist/xlsx/edit/sort.d.ts.map +1 -1
- package/dist/xlsx/index.cjs +271 -224
- package/dist/xlsx/index.mjs +271 -224
- package/dist/xlsx/load/index.cjs +63 -1
- package/dist/xlsx/load/index.mjs +63 -1
- package/dist/xlsx/ui/index.cjs +225 -223
- package/dist/xlsx/ui/index.mjs +225 -223
- package/dist/xlsx/write/chart-cache.d.ts +8 -0
- package/dist/xlsx/write/chart-cache.d.ts.map +1 -0
- package/dist/xlsx/write/sheet-parts.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/xlsx/index.mjs
CHANGED
|
@@ -23732,6 +23732,264 @@ function sheetDataXml(ctx, sheet) {
|
|
|
23732
23732
|
return out ? `<sheetData>${out}</sheetData>` : "<sheetData/>";
|
|
23733
23733
|
}
|
|
23734
23734
|
|
|
23735
|
+
// xlsx/layout/sparkline-view.ts
|
|
23736
|
+
var DEFAULTS = {
|
|
23737
|
+
colorSeries: "#376092",
|
|
23738
|
+
colorNegative: "#D00000",
|
|
23739
|
+
colorAxis: "#000000",
|
|
23740
|
+
colorMarkers: "#D00000",
|
|
23741
|
+
colorFirst: "#D00000",
|
|
23742
|
+
colorLast: "#D00000",
|
|
23743
|
+
colorHigh: "#D00000",
|
|
23744
|
+
colorLow: "#D00000"
|
|
23745
|
+
};
|
|
23746
|
+
var COLUMN_GAP = 0.2;
|
|
23747
|
+
function extent(values2) {
|
|
23748
|
+
let min = Infinity;
|
|
23749
|
+
let max = -Infinity;
|
|
23750
|
+
for (const v of values2) {
|
|
23751
|
+
if (v === null) continue;
|
|
23752
|
+
if (v < min) min = v;
|
|
23753
|
+
if (v > max) max = v;
|
|
23754
|
+
}
|
|
23755
|
+
return min <= max ? { min, max } : void 0;
|
|
23756
|
+
}
|
|
23757
|
+
function sparklineValues(group, values2) {
|
|
23758
|
+
return group.displayEmptyCellsAs === "zero" ? values2.map((v) => v ?? 0) : [...values2];
|
|
23759
|
+
}
|
|
23760
|
+
function sparklineScale(group, all2, index2) {
|
|
23761
|
+
const own = extent(sparklineValues(group, all2[index2]?.values ?? []));
|
|
23762
|
+
const needsGroup = group.minAxisType === "group" || group.maxAxisType === "group";
|
|
23763
|
+
const shared = needsGroup ? extent(all2.flatMap((data) => sparklineValues(group, data.values))) : void 0;
|
|
23764
|
+
const end = (type, manual, key) => {
|
|
23765
|
+
if (type === "custom" && manual !== void 0) return manual;
|
|
23766
|
+
if (type === "group" && shared) return shared[key];
|
|
23767
|
+
return own?.[key];
|
|
23768
|
+
};
|
|
23769
|
+
const min = end(group.minAxisType, group.manualMin, "min");
|
|
23770
|
+
const max = end(group.maxAxisType, group.manualMax, "max");
|
|
23771
|
+
return min === void 0 || max === void 0 ? void 0 : { min, max };
|
|
23772
|
+
}
|
|
23773
|
+
function positions(group, data, n2) {
|
|
23774
|
+
const dates = data.dates;
|
|
23775
|
+
if (group.dateAxis && dates && dates.length === n2) {
|
|
23776
|
+
const span3 = extent(dates);
|
|
23777
|
+
if (span3) {
|
|
23778
|
+
const width = span3.max - span3.min;
|
|
23779
|
+
return dates.map((d) => d === null ? null : width ? (d - span3.min) / width : 0.5);
|
|
23780
|
+
}
|
|
23781
|
+
}
|
|
23782
|
+
return Array.from({ length: n2 }, (_, i2) => n2 === 1 ? 0.5 : i2 / (n2 - 1));
|
|
23783
|
+
}
|
|
23784
|
+
function pointFacts(values2) {
|
|
23785
|
+
const numbers3 = values2.filter((x) => x !== null);
|
|
23786
|
+
let last = values2.length - 1;
|
|
23787
|
+
while (last >= 0 && values2[last] === null) last--;
|
|
23788
|
+
return {
|
|
23789
|
+
high: Math.max(...numbers3),
|
|
23790
|
+
low: Math.min(...numbers3),
|
|
23791
|
+
first: values2.findIndex((x) => x !== null),
|
|
23792
|
+
last
|
|
23793
|
+
};
|
|
23794
|
+
}
|
|
23795
|
+
function pointColor(group, v, i2, facts, colors, markers) {
|
|
23796
|
+
let color = markers && group.markers ? colors.colorMarkers : void 0;
|
|
23797
|
+
if (group.negative && v < 0) color = colors.colorNegative;
|
|
23798
|
+
if (group.high && v === facts.high) color = colors.colorHigh;
|
|
23799
|
+
if (group.low && v === facts.low) color = colors.colorLow;
|
|
23800
|
+
if (group.first && i2 === facts.first) color = colors.colorFirst;
|
|
23801
|
+
if (group.last && i2 === facts.last) color = colors.colorLast;
|
|
23802
|
+
return color;
|
|
23803
|
+
}
|
|
23804
|
+
function resolveColors(group, theme2) {
|
|
23805
|
+
const out = { ...DEFAULTS };
|
|
23806
|
+
for (const key of Object.keys(DEFAULTS)) {
|
|
23807
|
+
const color = group[key];
|
|
23808
|
+
out[key] = resolveColor(color, theme2, DEFAULTS[key]) ?? DEFAULTS[key];
|
|
23809
|
+
}
|
|
23810
|
+
return out;
|
|
23811
|
+
}
|
|
23812
|
+
function sparklineView(group, data, scale2, theme2) {
|
|
23813
|
+
const colors = resolveColors(group, theme2);
|
|
23814
|
+
const view = {
|
|
23815
|
+
type: group.type,
|
|
23816
|
+
color: colors.colorSeries,
|
|
23817
|
+
lineWeightPt: group.lineWeight,
|
|
23818
|
+
lines: [],
|
|
23819
|
+
markers: [],
|
|
23820
|
+
columns: []
|
|
23821
|
+
};
|
|
23822
|
+
const values2 = sparklineValues(group, data.values);
|
|
23823
|
+
const n2 = values2.length;
|
|
23824
|
+
if (!n2 || !scale2) return view;
|
|
23825
|
+
const facts = pointFacts(values2);
|
|
23826
|
+
const xs = positions(group, data, n2);
|
|
23827
|
+
const flip = (x) => group.rightToLeft ? 1 - x : x;
|
|
23828
|
+
const range = scale2.max - scale2.min;
|
|
23829
|
+
const yOf = (v) => range ? Math.max(0, Math.min(1, (scale2.max - v) / range)) : 0.5;
|
|
23830
|
+
if (group.type === "line") {
|
|
23831
|
+
let segment = [];
|
|
23832
|
+
values2.forEach((v, i2) => {
|
|
23833
|
+
const x = xs[i2];
|
|
23834
|
+
if (v === null || x === null || x === void 0) {
|
|
23835
|
+
if (group.displayEmptyCellsAs === "gap" && segment.length) {
|
|
23836
|
+
view.lines.push(segment);
|
|
23837
|
+
segment = [];
|
|
23838
|
+
}
|
|
23839
|
+
return;
|
|
23840
|
+
}
|
|
23841
|
+
const point = { x: flip(x), y: yOf(v) };
|
|
23842
|
+
segment.push(point);
|
|
23843
|
+
const color = pointColor(group, v, i2, facts, colors, true);
|
|
23844
|
+
if (color) view.markers.push({ ...point, color });
|
|
23845
|
+
});
|
|
23846
|
+
if (segment.length) view.lines.push(segment);
|
|
23847
|
+
} else {
|
|
23848
|
+
const slot2 = 1 / n2;
|
|
23849
|
+
const w = slot2 * (1 - COLUMN_GAP);
|
|
23850
|
+
const base = yOf(Math.max(scale2.min, Math.min(scale2.max, 0)));
|
|
23851
|
+
values2.forEach((v, i2) => {
|
|
23852
|
+
const position = xs[i2];
|
|
23853
|
+
if (v === null || position === null || position === void 0) return;
|
|
23854
|
+
if (v === 0) return;
|
|
23855
|
+
let top;
|
|
23856
|
+
let bottom;
|
|
23857
|
+
if (group.type === "stacked") [top, bottom] = v > 0 ? [0, 0.5] : [0.5, 1];
|
|
23858
|
+
else if (!range) [top, bottom] = [0, 1];
|
|
23859
|
+
else [top, bottom] = [Math.min(base, yOf(v)), Math.max(base, yOf(v))];
|
|
23860
|
+
const centre = flip(slot2 / 2 + position * (1 - slot2));
|
|
23861
|
+
const color = pointColor(group, v, i2, facts, colors, false) ?? view.color;
|
|
23862
|
+
view.columns.push({ x: centre - w / 2, y: top, w, h: bottom - top, color });
|
|
23863
|
+
});
|
|
23864
|
+
}
|
|
23865
|
+
if (group.type === "stacked") {
|
|
23866
|
+
if (group.displayXAxis) view.axis = { y: 0.5, color: colors.colorAxis };
|
|
23867
|
+
} else if (group.displayXAxis && range && scale2.min <= 0 && scale2.max >= 0)
|
|
23868
|
+
view.axis = { y: yOf(0), color: colors.colorAxis };
|
|
23869
|
+
return view;
|
|
23870
|
+
}
|
|
23871
|
+
|
|
23872
|
+
// xlsx/layout/sparkline-data.ts
|
|
23873
|
+
var MAX_POINTS = 1e4;
|
|
23874
|
+
var hostIndex = /* @__PURE__ */ new WeakMap();
|
|
23875
|
+
function hosts(sheet) {
|
|
23876
|
+
const groups = sheetSparklineGroups(sheet);
|
|
23877
|
+
let index2 = hostIndex.get(groups);
|
|
23878
|
+
if (!index2) {
|
|
23879
|
+
index2 = /* @__PURE__ */ new Map();
|
|
23880
|
+
for (const group of groups)
|
|
23881
|
+
group.sparklines.forEach((line3, i2) => {
|
|
23882
|
+
const key = cellKey(line3.host.start.row, line3.host.start.col);
|
|
23883
|
+
if (!index2.has(key)) index2.set(key, { group, index: i2 });
|
|
23884
|
+
});
|
|
23885
|
+
hostIndex.set(groups, index2);
|
|
23886
|
+
}
|
|
23887
|
+
return index2;
|
|
23888
|
+
}
|
|
23889
|
+
function hasSparklineAt(sheet, row2, col) {
|
|
23890
|
+
return hosts(sheet).has(cellKey(row2, col));
|
|
23891
|
+
}
|
|
23892
|
+
function resolveSparklineRange(workbook, sheet, formula) {
|
|
23893
|
+
const ref = formula.trim().replace(/^=/, "");
|
|
23894
|
+
const bang = ref.lastIndexOf("!");
|
|
23895
|
+
let target = sheet;
|
|
23896
|
+
if (bang >= 0) {
|
|
23897
|
+
const raw2 = ref.slice(0, bang);
|
|
23898
|
+
const name = /^'.*'$/.test(raw2) ? raw2.slice(1, -1).replace(/''/g, "'") : raw2;
|
|
23899
|
+
target = sheetByName(workbook, name);
|
|
23900
|
+
}
|
|
23901
|
+
const range = parseRange(ref.slice(bang + 1).replace(/\$/g, ""));
|
|
23902
|
+
return target && range ? { sheet: target, range: normalizeRange(range) } : void 0;
|
|
23903
|
+
}
|
|
23904
|
+
var rowHidden = (sheet, row2) => sheet.rowInfo.get(row2)?.hidden === true;
|
|
23905
|
+
var colHidden = (sheet, col) => sheet.columns.some((c2) => c2.hidden === true && col >= c2.min && col <= c2.max);
|
|
23906
|
+
function readSparklineValues(sheet, range, displayHidden) {
|
|
23907
|
+
let endRow = range.end.row;
|
|
23908
|
+
if (endRow - range.start.row >= MAX_POINTS) {
|
|
23909
|
+
let lastRow = range.start.row;
|
|
23910
|
+
for (const row2 of sheet.rows.keys()) if (row2 > lastRow) lastRow = row2;
|
|
23911
|
+
endRow = Math.min(endRow, lastRow);
|
|
23912
|
+
}
|
|
23913
|
+
const out = [];
|
|
23914
|
+
for (let row2 = range.start.row; row2 <= endRow && out.length < MAX_POINTS; row2++) {
|
|
23915
|
+
if (!displayHidden && rowHidden(sheet, row2)) continue;
|
|
23916
|
+
for (let col = range.start.col; col <= range.end.col && out.length < MAX_POINTS; col++) {
|
|
23917
|
+
if (!displayHidden && colHidden(sheet, col)) continue;
|
|
23918
|
+
const value = getCell(sheet, row2, col)?.value;
|
|
23919
|
+
out.push(typeof value === "number" && Number.isFinite(value) ? value : null);
|
|
23920
|
+
}
|
|
23921
|
+
}
|
|
23922
|
+
return out;
|
|
23923
|
+
}
|
|
23924
|
+
function groupData(workbook, sheet, group) {
|
|
23925
|
+
const dateRange = group.dateAxis && group.dateFormula;
|
|
23926
|
+
const dates = dateRange ? resolveSparklineRange(workbook, sheet, dateRange) : void 0;
|
|
23927
|
+
const dateValues = dates ? readSparklineValues(dates.sheet, dates.range, group.displayHidden) : void 0;
|
|
23928
|
+
return group.sparklines.map((line3) => {
|
|
23929
|
+
const source2 = line3.formula ? resolveSparklineRange(workbook, sheet, line3.formula) : void 0;
|
|
23930
|
+
const values2 = source2 ? readSparklineValues(source2.sheet, source2.range, group.displayHidden) : [];
|
|
23931
|
+
return dateValues ? { values: values2, dates: dateValues } : { values: values2 };
|
|
23932
|
+
});
|
|
23933
|
+
}
|
|
23934
|
+
function sparklineViewAt(workbook, sheetIndex2, row2, col) {
|
|
23935
|
+
const sheet = workbook.sheets[sheetIndex2];
|
|
23936
|
+
if (!sheet) return void 0;
|
|
23937
|
+
const entry3 = hosts(sheet).get(cellKey(row2, col));
|
|
23938
|
+
if (!entry3) return void 0;
|
|
23939
|
+
const { group, index: index2 } = entry3;
|
|
23940
|
+
const needsGroup = group.minAxisType === "group" || group.maxAxisType === "group";
|
|
23941
|
+
const data = needsGroup ? groupData(workbook, sheet, group) : groupData(workbook, sheet, { ...group, sparklines: [group.sparklines[index2]] });
|
|
23942
|
+
const at = needsGroup ? index2 : 0;
|
|
23943
|
+
return sparklineView(
|
|
23944
|
+
group,
|
|
23945
|
+
data[at] ?? { values: [] },
|
|
23946
|
+
sparklineScale(group, data, at),
|
|
23947
|
+
workbook.theme
|
|
23948
|
+
);
|
|
23949
|
+
}
|
|
23950
|
+
|
|
23951
|
+
// xlsx/write/chart-cache.ts
|
|
23952
|
+
var MAX_CHART_CACHE_CELLS = 1e4;
|
|
23953
|
+
function referenceValues(workbook, sheet, ref, maxCells = MAX_CHART_CACHE_CELLS) {
|
|
23954
|
+
if (!ref) return void 0;
|
|
23955
|
+
const target = resolveSparklineRange(workbook, sheet, ref);
|
|
23956
|
+
if (!target) return void 0;
|
|
23957
|
+
const { range } = target;
|
|
23958
|
+
const count2 = rangeSize(range);
|
|
23959
|
+
if (!Number.isSafeInteger(count2) || count2 < 1 || count2 > maxCells || range.end.row > MAX_ROW || range.end.col > MAX_COL)
|
|
23960
|
+
return void 0;
|
|
23961
|
+
const values2 = [];
|
|
23962
|
+
for (let row2 = range.start.row; row2 <= range.end.row; row2++)
|
|
23963
|
+
for (let col = range.start.col; col <= range.end.col; col++)
|
|
23964
|
+
values2.push(getValue(target.sheet, row2, col));
|
|
23965
|
+
return values2;
|
|
23966
|
+
}
|
|
23967
|
+
function categoryValue(value) {
|
|
23968
|
+
if (value === null) return "";
|
|
23969
|
+
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
23970
|
+
if (typeof value === "object") return value.error;
|
|
23971
|
+
if (typeof value === "number" && !Number.isFinite(value)) return "";
|
|
23972
|
+
return value;
|
|
23973
|
+
}
|
|
23974
|
+
function chartWithCurrentCaches(workbook, sheet, chart) {
|
|
23975
|
+
return {
|
|
23976
|
+
...chart,
|
|
23977
|
+
series: chart.series.map((series) => {
|
|
23978
|
+
const values2 = referenceValues(workbook, sheet, series.valuesRef);
|
|
23979
|
+
const categories = referenceValues(workbook, sheet, series.categoriesRef);
|
|
23980
|
+
const name = referenceValues(workbook, sheet, series.nameRef, 1);
|
|
23981
|
+
return {
|
|
23982
|
+
...series,
|
|
23983
|
+
...name === void 0 ? {} : { name: String(categoryValue(name[0] ?? null)) },
|
|
23984
|
+
values: values2?.map(
|
|
23985
|
+
(value) => typeof value === "number" && Number.isFinite(value) ? value : null
|
|
23986
|
+
) ?? series.values,
|
|
23987
|
+
categories: categories?.map(categoryValue) ?? series.categories
|
|
23988
|
+
};
|
|
23989
|
+
})
|
|
23990
|
+
};
|
|
23991
|
+
}
|
|
23992
|
+
|
|
23735
23993
|
// xlsx/write/vml-ids.ts
|
|
23736
23994
|
var IDS_PER_BLOCK = 1024;
|
|
23737
23995
|
function vmlIdmapBlocks(xml) {
|
|
@@ -24200,7 +24458,10 @@ function writeSheetDrawing(ctx, sheet, partName, rels, sourceDrawing) {
|
|
|
24200
24458
|
}
|
|
24201
24459
|
}
|
|
24202
24460
|
const target = sourceDrawing && !writer.has(sourceDrawing) ? sourceDrawing : writer.uniqueName((n2) => `xl/drawings/drawing${n2}.xml`, ctx.reserved);
|
|
24203
|
-
|
|
24461
|
+
const drawings = sheet.drawings.map(
|
|
24462
|
+
(object) => object.kind === "chart" && (!object.partName || !source2?.has(object.partName)) ? chartWithCurrentCaches(ctx.workbook, sheet, object) : object
|
|
24463
|
+
);
|
|
24464
|
+
if (!writeDrawing(writer, target, drawings, sourceDrawing)) return "";
|
|
24204
24465
|
return `<drawing r:id="${rels.add(RELATIONSHIP_TYPES.drawing, relativeTarget(partName, target))}"/>`;
|
|
24205
24466
|
}
|
|
24206
24467
|
|
|
@@ -27391,6 +27652,7 @@ function sortRows2(sheet, range, keys, hasHeader) {
|
|
|
27391
27652
|
const sortKeys2 = keys.length ? keys : [{ col: r.start.col }];
|
|
27392
27653
|
const rows = [];
|
|
27393
27654
|
for (let row2 = firstRow; row2 <= lastRow; row2++) {
|
|
27655
|
+
if (sheet.rowInfo.get(row2)?.hidden) continue;
|
|
27394
27656
|
const cells = /* @__PURE__ */ new Map();
|
|
27395
27657
|
for (const [col, cell] of sheet.rows.get(row2) ?? [])
|
|
27396
27658
|
if (col >= r.start.col && col <= r.end.col) cells.set(col, cell);
|
|
@@ -27408,9 +27670,9 @@ function sortRows2(sheet, range, keys, hasHeader) {
|
|
|
27408
27670
|
return 0;
|
|
27409
27671
|
});
|
|
27410
27672
|
for (const { row: row2, cells } of rows) for (const col of cells.keys()) deleteCell(sheet, row2, col);
|
|
27411
|
-
moveAnnotations(sheet, dataArea, new Map(sorted2.map((source2, i2) => [source2.row,
|
|
27673
|
+
moveAnnotations(sheet, dataArea, new Map(sorted2.map((source2, i2) => [source2.row, rows[i2].row])));
|
|
27412
27674
|
sorted2.forEach((source2, i2) => {
|
|
27413
|
-
const row2 =
|
|
27675
|
+
const row2 = rows[i2].row;
|
|
27414
27676
|
const dRow = row2 - source2.row;
|
|
27415
27677
|
for (const [col, cell] of source2.cells) {
|
|
27416
27678
|
if (cell.formula !== void 0 && dRow) {
|
|
@@ -31168,222 +31430,6 @@ function bordersView(border, theme2) {
|
|
|
31168
31430
|
return out;
|
|
31169
31431
|
}
|
|
31170
31432
|
|
|
31171
|
-
// xlsx/layout/sparkline-view.ts
|
|
31172
|
-
var DEFAULTS = {
|
|
31173
|
-
colorSeries: "#376092",
|
|
31174
|
-
colorNegative: "#D00000",
|
|
31175
|
-
colorAxis: "#000000",
|
|
31176
|
-
colorMarkers: "#D00000",
|
|
31177
|
-
colorFirst: "#D00000",
|
|
31178
|
-
colorLast: "#D00000",
|
|
31179
|
-
colorHigh: "#D00000",
|
|
31180
|
-
colorLow: "#D00000"
|
|
31181
|
-
};
|
|
31182
|
-
var COLUMN_GAP = 0.2;
|
|
31183
|
-
function extent(values2) {
|
|
31184
|
-
let min = Infinity;
|
|
31185
|
-
let max = -Infinity;
|
|
31186
|
-
for (const v of values2) {
|
|
31187
|
-
if (v === null) continue;
|
|
31188
|
-
if (v < min) min = v;
|
|
31189
|
-
if (v > max) max = v;
|
|
31190
|
-
}
|
|
31191
|
-
return min <= max ? { min, max } : void 0;
|
|
31192
|
-
}
|
|
31193
|
-
function sparklineValues(group, values2) {
|
|
31194
|
-
return group.displayEmptyCellsAs === "zero" ? values2.map((v) => v ?? 0) : [...values2];
|
|
31195
|
-
}
|
|
31196
|
-
function sparklineScale(group, all2, index2) {
|
|
31197
|
-
const own = extent(sparklineValues(group, all2[index2]?.values ?? []));
|
|
31198
|
-
const needsGroup = group.minAxisType === "group" || group.maxAxisType === "group";
|
|
31199
|
-
const shared = needsGroup ? extent(all2.flatMap((data) => sparklineValues(group, data.values))) : void 0;
|
|
31200
|
-
const end = (type, manual, key) => {
|
|
31201
|
-
if (type === "custom" && manual !== void 0) return manual;
|
|
31202
|
-
if (type === "group" && shared) return shared[key];
|
|
31203
|
-
return own?.[key];
|
|
31204
|
-
};
|
|
31205
|
-
const min = end(group.minAxisType, group.manualMin, "min");
|
|
31206
|
-
const max = end(group.maxAxisType, group.manualMax, "max");
|
|
31207
|
-
return min === void 0 || max === void 0 ? void 0 : { min, max };
|
|
31208
|
-
}
|
|
31209
|
-
function positions(group, data, n2) {
|
|
31210
|
-
const dates = data.dates;
|
|
31211
|
-
if (group.dateAxis && dates && dates.length === n2) {
|
|
31212
|
-
const span3 = extent(dates);
|
|
31213
|
-
if (span3) {
|
|
31214
|
-
const width = span3.max - span3.min;
|
|
31215
|
-
return dates.map((d) => d === null ? null : width ? (d - span3.min) / width : 0.5);
|
|
31216
|
-
}
|
|
31217
|
-
}
|
|
31218
|
-
return Array.from({ length: n2 }, (_, i2) => n2 === 1 ? 0.5 : i2 / (n2 - 1));
|
|
31219
|
-
}
|
|
31220
|
-
function pointFacts(values2) {
|
|
31221
|
-
const numbers3 = values2.filter((x) => x !== null);
|
|
31222
|
-
let last = values2.length - 1;
|
|
31223
|
-
while (last >= 0 && values2[last] === null) last--;
|
|
31224
|
-
return {
|
|
31225
|
-
high: Math.max(...numbers3),
|
|
31226
|
-
low: Math.min(...numbers3),
|
|
31227
|
-
first: values2.findIndex((x) => x !== null),
|
|
31228
|
-
last
|
|
31229
|
-
};
|
|
31230
|
-
}
|
|
31231
|
-
function pointColor(group, v, i2, facts, colors, markers) {
|
|
31232
|
-
let color = markers && group.markers ? colors.colorMarkers : void 0;
|
|
31233
|
-
if (group.negative && v < 0) color = colors.colorNegative;
|
|
31234
|
-
if (group.high && v === facts.high) color = colors.colorHigh;
|
|
31235
|
-
if (group.low && v === facts.low) color = colors.colorLow;
|
|
31236
|
-
if (group.first && i2 === facts.first) color = colors.colorFirst;
|
|
31237
|
-
if (group.last && i2 === facts.last) color = colors.colorLast;
|
|
31238
|
-
return color;
|
|
31239
|
-
}
|
|
31240
|
-
function resolveColors(group, theme2) {
|
|
31241
|
-
const out = { ...DEFAULTS };
|
|
31242
|
-
for (const key of Object.keys(DEFAULTS)) {
|
|
31243
|
-
const color = group[key];
|
|
31244
|
-
out[key] = resolveColor(color, theme2, DEFAULTS[key]) ?? DEFAULTS[key];
|
|
31245
|
-
}
|
|
31246
|
-
return out;
|
|
31247
|
-
}
|
|
31248
|
-
function sparklineView(group, data, scale2, theme2) {
|
|
31249
|
-
const colors = resolveColors(group, theme2);
|
|
31250
|
-
const view = {
|
|
31251
|
-
type: group.type,
|
|
31252
|
-
color: colors.colorSeries,
|
|
31253
|
-
lineWeightPt: group.lineWeight,
|
|
31254
|
-
lines: [],
|
|
31255
|
-
markers: [],
|
|
31256
|
-
columns: []
|
|
31257
|
-
};
|
|
31258
|
-
const values2 = sparklineValues(group, data.values);
|
|
31259
|
-
const n2 = values2.length;
|
|
31260
|
-
if (!n2 || !scale2) return view;
|
|
31261
|
-
const facts = pointFacts(values2);
|
|
31262
|
-
const xs = positions(group, data, n2);
|
|
31263
|
-
const flip = (x) => group.rightToLeft ? 1 - x : x;
|
|
31264
|
-
const range = scale2.max - scale2.min;
|
|
31265
|
-
const yOf = (v) => range ? Math.max(0, Math.min(1, (scale2.max - v) / range)) : 0.5;
|
|
31266
|
-
if (group.type === "line") {
|
|
31267
|
-
let segment = [];
|
|
31268
|
-
values2.forEach((v, i2) => {
|
|
31269
|
-
const x = xs[i2];
|
|
31270
|
-
if (v === null || x === null || x === void 0) {
|
|
31271
|
-
if (group.displayEmptyCellsAs === "gap" && segment.length) {
|
|
31272
|
-
view.lines.push(segment);
|
|
31273
|
-
segment = [];
|
|
31274
|
-
}
|
|
31275
|
-
return;
|
|
31276
|
-
}
|
|
31277
|
-
const point = { x: flip(x), y: yOf(v) };
|
|
31278
|
-
segment.push(point);
|
|
31279
|
-
const color = pointColor(group, v, i2, facts, colors, true);
|
|
31280
|
-
if (color) view.markers.push({ ...point, color });
|
|
31281
|
-
});
|
|
31282
|
-
if (segment.length) view.lines.push(segment);
|
|
31283
|
-
} else {
|
|
31284
|
-
const slot2 = 1 / n2;
|
|
31285
|
-
const w = slot2 * (1 - COLUMN_GAP);
|
|
31286
|
-
const base = yOf(Math.max(scale2.min, Math.min(scale2.max, 0)));
|
|
31287
|
-
values2.forEach((v, i2) => {
|
|
31288
|
-
const position = xs[i2];
|
|
31289
|
-
if (v === null || position === null || position === void 0) return;
|
|
31290
|
-
if (v === 0) return;
|
|
31291
|
-
let top;
|
|
31292
|
-
let bottom;
|
|
31293
|
-
if (group.type === "stacked") [top, bottom] = v > 0 ? [0, 0.5] : [0.5, 1];
|
|
31294
|
-
else if (!range) [top, bottom] = [0, 1];
|
|
31295
|
-
else [top, bottom] = [Math.min(base, yOf(v)), Math.max(base, yOf(v))];
|
|
31296
|
-
const centre = flip(slot2 / 2 + position * (1 - slot2));
|
|
31297
|
-
const color = pointColor(group, v, i2, facts, colors, false) ?? view.color;
|
|
31298
|
-
view.columns.push({ x: centre - w / 2, y: top, w, h: bottom - top, color });
|
|
31299
|
-
});
|
|
31300
|
-
}
|
|
31301
|
-
if (group.type === "stacked") {
|
|
31302
|
-
if (group.displayXAxis) view.axis = { y: 0.5, color: colors.colorAxis };
|
|
31303
|
-
} else if (group.displayXAxis && range && scale2.min <= 0 && scale2.max >= 0)
|
|
31304
|
-
view.axis = { y: yOf(0), color: colors.colorAxis };
|
|
31305
|
-
return view;
|
|
31306
|
-
}
|
|
31307
|
-
|
|
31308
|
-
// xlsx/layout/sparkline-data.ts
|
|
31309
|
-
var MAX_POINTS = 1e4;
|
|
31310
|
-
var hostIndex = /* @__PURE__ */ new WeakMap();
|
|
31311
|
-
function hosts(sheet) {
|
|
31312
|
-
const groups = sheetSparklineGroups(sheet);
|
|
31313
|
-
let index2 = hostIndex.get(groups);
|
|
31314
|
-
if (!index2) {
|
|
31315
|
-
index2 = /* @__PURE__ */ new Map();
|
|
31316
|
-
for (const group of groups)
|
|
31317
|
-
group.sparklines.forEach((line3, i2) => {
|
|
31318
|
-
const key = cellKey(line3.host.start.row, line3.host.start.col);
|
|
31319
|
-
if (!index2.has(key)) index2.set(key, { group, index: i2 });
|
|
31320
|
-
});
|
|
31321
|
-
hostIndex.set(groups, index2);
|
|
31322
|
-
}
|
|
31323
|
-
return index2;
|
|
31324
|
-
}
|
|
31325
|
-
function hasSparklineAt(sheet, row2, col) {
|
|
31326
|
-
return hosts(sheet).has(cellKey(row2, col));
|
|
31327
|
-
}
|
|
31328
|
-
function resolveSparklineRange(workbook, sheet, formula) {
|
|
31329
|
-
const ref = formula.trim().replace(/^=/, "");
|
|
31330
|
-
const bang = ref.lastIndexOf("!");
|
|
31331
|
-
let target = sheet;
|
|
31332
|
-
if (bang >= 0) {
|
|
31333
|
-
const raw2 = ref.slice(0, bang);
|
|
31334
|
-
const name = /^'.*'$/.test(raw2) ? raw2.slice(1, -1).replace(/''/g, "'") : raw2;
|
|
31335
|
-
target = sheetByName(workbook, name);
|
|
31336
|
-
}
|
|
31337
|
-
const range = parseRange(ref.slice(bang + 1).replace(/\$/g, ""));
|
|
31338
|
-
return target && range ? { sheet: target, range: normalizeRange(range) } : void 0;
|
|
31339
|
-
}
|
|
31340
|
-
var rowHidden = (sheet, row2) => sheet.rowInfo.get(row2)?.hidden === true;
|
|
31341
|
-
var colHidden = (sheet, col) => sheet.columns.some((c2) => c2.hidden === true && col >= c2.min && col <= c2.max);
|
|
31342
|
-
function readSparklineValues(sheet, range, displayHidden) {
|
|
31343
|
-
let endRow = range.end.row;
|
|
31344
|
-
if (endRow - range.start.row >= MAX_POINTS) {
|
|
31345
|
-
let lastRow = range.start.row;
|
|
31346
|
-
for (const row2 of sheet.rows.keys()) if (row2 > lastRow) lastRow = row2;
|
|
31347
|
-
endRow = Math.min(endRow, lastRow);
|
|
31348
|
-
}
|
|
31349
|
-
const out = [];
|
|
31350
|
-
for (let row2 = range.start.row; row2 <= endRow && out.length < MAX_POINTS; row2++) {
|
|
31351
|
-
if (!displayHidden && rowHidden(sheet, row2)) continue;
|
|
31352
|
-
for (let col = range.start.col; col <= range.end.col && out.length < MAX_POINTS; col++) {
|
|
31353
|
-
if (!displayHidden && colHidden(sheet, col)) continue;
|
|
31354
|
-
const value = getCell(sheet, row2, col)?.value;
|
|
31355
|
-
out.push(typeof value === "number" && Number.isFinite(value) ? value : null);
|
|
31356
|
-
}
|
|
31357
|
-
}
|
|
31358
|
-
return out;
|
|
31359
|
-
}
|
|
31360
|
-
function groupData(workbook, sheet, group) {
|
|
31361
|
-
const dateRange = group.dateAxis && group.dateFormula;
|
|
31362
|
-
const dates = dateRange ? resolveSparklineRange(workbook, sheet, dateRange) : void 0;
|
|
31363
|
-
const dateValues = dates ? readSparklineValues(dates.sheet, dates.range, group.displayHidden) : void 0;
|
|
31364
|
-
return group.sparklines.map((line3) => {
|
|
31365
|
-
const source2 = line3.formula ? resolveSparklineRange(workbook, sheet, line3.formula) : void 0;
|
|
31366
|
-
const values2 = source2 ? readSparklineValues(source2.sheet, source2.range, group.displayHidden) : [];
|
|
31367
|
-
return dateValues ? { values: values2, dates: dateValues } : { values: values2 };
|
|
31368
|
-
});
|
|
31369
|
-
}
|
|
31370
|
-
function sparklineViewAt(workbook, sheetIndex2, row2, col) {
|
|
31371
|
-
const sheet = workbook.sheets[sheetIndex2];
|
|
31372
|
-
if (!sheet) return void 0;
|
|
31373
|
-
const entry3 = hosts(sheet).get(cellKey(row2, col));
|
|
31374
|
-
if (!entry3) return void 0;
|
|
31375
|
-
const { group, index: index2 } = entry3;
|
|
31376
|
-
const needsGroup = group.minAxisType === "group" || group.maxAxisType === "group";
|
|
31377
|
-
const data = needsGroup ? groupData(workbook, sheet, group) : groupData(workbook, sheet, { ...group, sparklines: [group.sparklines[index2]] });
|
|
31378
|
-
const at = needsGroup ? index2 : 0;
|
|
31379
|
-
return sparklineView(
|
|
31380
|
-
group,
|
|
31381
|
-
data[at] ?? { values: [] },
|
|
31382
|
-
sparklineScale(group, data, at),
|
|
31383
|
-
workbook.theme
|
|
31384
|
-
);
|
|
31385
|
-
}
|
|
31386
|
-
|
|
31387
31433
|
// xlsx/layout/units.ts
|
|
31388
31434
|
var DEFAULT_MAX_DIGIT_WIDTH = 7;
|
|
31389
31435
|
var DEFAULT_BASE_COL_WIDTH = 8;
|
|
@@ -31968,13 +32014,14 @@ function duplicateSheet(ctx, index2) {
|
|
|
31968
32014
|
delete next.partName;
|
|
31969
32015
|
return next;
|
|
31970
32016
|
});
|
|
31971
|
-
|
|
31972
|
-
|
|
31973
|
-
|
|
31974
|
-
|
|
31975
|
-
|
|
32017
|
+
const rewrite2 = (formula) => renames.reduce(
|
|
32018
|
+
(f6, [from, to]) => renameTableInFormula(f6, from, to),
|
|
32019
|
+
renameSheetInFormula(formula, sheet.name, copy.name)
|
|
32020
|
+
);
|
|
32021
|
+
rewriteSheetFormulas(copy, rewrite2);
|
|
31976
32022
|
for (const drawing of copy.drawings) if (drawing.kind === "chart") delete drawing.partName;
|
|
31977
32023
|
const copiedNames = namesForCopy(workbook, index2, sheet.name, copy.name);
|
|
32024
|
+
for (const name of copiedNames) name.formula = rewrite2(name.formula);
|
|
31978
32025
|
workbook.sheets.splice(at, 0, copy);
|
|
31979
32026
|
remapSheets(workbook, (i2) => i2 >= at ? i2 + 1 : i2);
|
|
31980
32027
|
for (const n2 of copiedNames) workbook.definedNames.push({ ...n2, localSheet: at });
|
package/dist/xlsx/load/index.cjs
CHANGED
|
@@ -4151,6 +4151,7 @@ function formatRange(range) {
|
|
|
4151
4151
|
const a2 = formatAddress(start);
|
|
4152
4152
|
return start.row === end.row && start.col === end.col ? a2 : `${a2}:${formatAddress(end)}`;
|
|
4153
4153
|
}
|
|
4154
|
+
var rangeSize = (range) => (range.end.row - range.start.row + 1) * (range.end.col - range.start.col + 1);
|
|
4154
4155
|
var cellKey = (row2, col) => row2 * (MAX_COL + 1) + col;
|
|
4155
4156
|
function quoteSheetName(name) {
|
|
4156
4157
|
return /^[A-Za-z_][A-Za-z0-9_.]*$/.test(name) && !parseAddress(name) ? name : `'${name.replace(/'/g, "''")}'`;
|
|
@@ -4158,6 +4159,7 @@ function quoteSheetName(name) {
|
|
|
4158
4159
|
|
|
4159
4160
|
// xlsx/cells.ts
|
|
4160
4161
|
var getCell = (sheet, row2, col) => sheet.rows.get(row2)?.get(col);
|
|
4162
|
+
var getValue = (sheet, row2, col) => getCell(sheet, row2, col)?.value ?? null;
|
|
4161
4163
|
function usedRange(sheet) {
|
|
4162
4164
|
let minRow = Infinity;
|
|
4163
4165
|
let maxRow = -1;
|
|
@@ -5632,6 +5634,7 @@ function createWorkbook(options = {}) {
|
|
|
5632
5634
|
warnings: []
|
|
5633
5635
|
};
|
|
5634
5636
|
}
|
|
5637
|
+
var sheetByName = (workbook, name) => workbook.sheets.find((sheet) => sheet.name.toLowerCase() === name.toLowerCase());
|
|
5635
5638
|
var xChildren = (parent, local) => children(parent, local, NS.x);
|
|
5636
5639
|
var xFirst = (parent, local) => first(parent, local, NS.x);
|
|
5637
5640
|
var att = (element2, name) => {
|
|
@@ -22231,6 +22234,62 @@ function sheetDataXml(ctx, sheet) {
|
|
|
22231
22234
|
return out ? `<sheetData>${out}</sheetData>` : "<sheetData/>";
|
|
22232
22235
|
}
|
|
22233
22236
|
|
|
22237
|
+
// xlsx/layout/sparkline-data.ts
|
|
22238
|
+
function resolveSparklineRange(workbook, sheet, formula) {
|
|
22239
|
+
const ref = formula.trim().replace(/^=/, "");
|
|
22240
|
+
const bang = ref.lastIndexOf("!");
|
|
22241
|
+
let target = sheet;
|
|
22242
|
+
if (bang >= 0) {
|
|
22243
|
+
const raw2 = ref.slice(0, bang);
|
|
22244
|
+
const name = /^'.*'$/.test(raw2) ? raw2.slice(1, -1).replace(/''/g, "'") : raw2;
|
|
22245
|
+
target = sheetByName(workbook, name);
|
|
22246
|
+
}
|
|
22247
|
+
const range = parseRange(ref.slice(bang + 1).replace(/\$/g, ""));
|
|
22248
|
+
return target && range ? { sheet: target, range: normalizeRange(range) } : void 0;
|
|
22249
|
+
}
|
|
22250
|
+
|
|
22251
|
+
// xlsx/write/chart-cache.ts
|
|
22252
|
+
var MAX_CHART_CACHE_CELLS = 1e4;
|
|
22253
|
+
function referenceValues(workbook, sheet, ref, maxCells = MAX_CHART_CACHE_CELLS) {
|
|
22254
|
+
if (!ref) return void 0;
|
|
22255
|
+
const target = resolveSparklineRange(workbook, sheet, ref);
|
|
22256
|
+
if (!target) return void 0;
|
|
22257
|
+
const { range } = target;
|
|
22258
|
+
const count2 = rangeSize(range);
|
|
22259
|
+
if (!Number.isSafeInteger(count2) || count2 < 1 || count2 > maxCells || range.end.row > MAX_ROW || range.end.col > MAX_COL)
|
|
22260
|
+
return void 0;
|
|
22261
|
+
const values2 = [];
|
|
22262
|
+
for (let row2 = range.start.row; row2 <= range.end.row; row2++)
|
|
22263
|
+
for (let col = range.start.col; col <= range.end.col; col++)
|
|
22264
|
+
values2.push(getValue(target.sheet, row2, col));
|
|
22265
|
+
return values2;
|
|
22266
|
+
}
|
|
22267
|
+
function categoryValue(value) {
|
|
22268
|
+
if (value === null) return "";
|
|
22269
|
+
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
22270
|
+
if (typeof value === "object") return value.error;
|
|
22271
|
+
if (typeof value === "number" && !Number.isFinite(value)) return "";
|
|
22272
|
+
return value;
|
|
22273
|
+
}
|
|
22274
|
+
function chartWithCurrentCaches(workbook, sheet, chart) {
|
|
22275
|
+
return {
|
|
22276
|
+
...chart,
|
|
22277
|
+
series: chart.series.map((series) => {
|
|
22278
|
+
const values2 = referenceValues(workbook, sheet, series.valuesRef);
|
|
22279
|
+
const categories = referenceValues(workbook, sheet, series.categoriesRef);
|
|
22280
|
+
const name = referenceValues(workbook, sheet, series.nameRef, 1);
|
|
22281
|
+
return {
|
|
22282
|
+
...series,
|
|
22283
|
+
...name === void 0 ? {} : { name: String(categoryValue(name[0] ?? null)) },
|
|
22284
|
+
values: values2?.map(
|
|
22285
|
+
(value) => typeof value === "number" && Number.isFinite(value) ? value : null
|
|
22286
|
+
) ?? series.values,
|
|
22287
|
+
categories: categories?.map(categoryValue) ?? series.categories
|
|
22288
|
+
};
|
|
22289
|
+
})
|
|
22290
|
+
};
|
|
22291
|
+
}
|
|
22292
|
+
|
|
22234
22293
|
// xlsx/write/vml-ids.ts
|
|
22235
22294
|
var IDS_PER_BLOCK = 1024;
|
|
22236
22295
|
function vmlIdmapBlocks(xml) {
|
|
@@ -22699,7 +22758,10 @@ function writeSheetDrawing(ctx, sheet, partName, rels, sourceDrawing) {
|
|
|
22699
22758
|
}
|
|
22700
22759
|
}
|
|
22701
22760
|
const target = sourceDrawing && !writer.has(sourceDrawing) ? sourceDrawing : writer.uniqueName((n) => `xl/drawings/drawing${n}.xml`, ctx.reserved);
|
|
22702
|
-
|
|
22761
|
+
const drawings = sheet.drawings.map(
|
|
22762
|
+
(object) => object.kind === "chart" && (!object.partName || !source2?.has(object.partName)) ? chartWithCurrentCaches(ctx.workbook, sheet, object) : object
|
|
22763
|
+
);
|
|
22764
|
+
if (!writeDrawing(writer, target, drawings, sourceDrawing)) return "";
|
|
22703
22765
|
return `<drawing r:id="${rels.add(RELATIONSHIP_TYPES.drawing, relativeTarget(partName, target))}"/>`;
|
|
22704
22766
|
}
|
|
22705
22767
|
|