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.
@@ -23738,6 +23738,264 @@ function sheetDataXml(ctx, sheet) {
23738
23738
  return out ? `<sheetData>${out}</sheetData>` : "<sheetData/>";
23739
23739
  }
23740
23740
 
23741
+ // xlsx/layout/sparkline-view.ts
23742
+ var DEFAULTS = {
23743
+ colorSeries: "#376092",
23744
+ colorNegative: "#D00000",
23745
+ colorAxis: "#000000",
23746
+ colorMarkers: "#D00000",
23747
+ colorFirst: "#D00000",
23748
+ colorLast: "#D00000",
23749
+ colorHigh: "#D00000",
23750
+ colorLow: "#D00000"
23751
+ };
23752
+ var COLUMN_GAP = 0.2;
23753
+ function extent(values2) {
23754
+ let min = Infinity;
23755
+ let max = -Infinity;
23756
+ for (const v of values2) {
23757
+ if (v === null) continue;
23758
+ if (v < min) min = v;
23759
+ if (v > max) max = v;
23760
+ }
23761
+ return min <= max ? { min, max } : void 0;
23762
+ }
23763
+ function sparklineValues(group, values2) {
23764
+ return group.displayEmptyCellsAs === "zero" ? values2.map((v) => v ?? 0) : [...values2];
23765
+ }
23766
+ function sparklineScale(group, all2, index2) {
23767
+ const own = extent(sparklineValues(group, all2[index2]?.values ?? []));
23768
+ const needsGroup = group.minAxisType === "group" || group.maxAxisType === "group";
23769
+ const shared = needsGroup ? extent(all2.flatMap((data) => sparklineValues(group, data.values))) : void 0;
23770
+ const end = (type, manual, key) => {
23771
+ if (type === "custom" && manual !== void 0) return manual;
23772
+ if (type === "group" && shared) return shared[key];
23773
+ return own?.[key];
23774
+ };
23775
+ const min = end(group.minAxisType, group.manualMin, "min");
23776
+ const max = end(group.maxAxisType, group.manualMax, "max");
23777
+ return min === void 0 || max === void 0 ? void 0 : { min, max };
23778
+ }
23779
+ function positions(group, data, n2) {
23780
+ const dates = data.dates;
23781
+ if (group.dateAxis && dates && dates.length === n2) {
23782
+ const span3 = extent(dates);
23783
+ if (span3) {
23784
+ const width = span3.max - span3.min;
23785
+ return dates.map((d) => d === null ? null : width ? (d - span3.min) / width : 0.5);
23786
+ }
23787
+ }
23788
+ return Array.from({ length: n2 }, (_, i2) => n2 === 1 ? 0.5 : i2 / (n2 - 1));
23789
+ }
23790
+ function pointFacts(values2) {
23791
+ const numbers3 = values2.filter((x) => x !== null);
23792
+ let last = values2.length - 1;
23793
+ while (last >= 0 && values2[last] === null) last--;
23794
+ return {
23795
+ high: Math.max(...numbers3),
23796
+ low: Math.min(...numbers3),
23797
+ first: values2.findIndex((x) => x !== null),
23798
+ last
23799
+ };
23800
+ }
23801
+ function pointColor(group, v, i2, facts, colors, markers) {
23802
+ let color = markers && group.markers ? colors.colorMarkers : void 0;
23803
+ if (group.negative && v < 0) color = colors.colorNegative;
23804
+ if (group.high && v === facts.high) color = colors.colorHigh;
23805
+ if (group.low && v === facts.low) color = colors.colorLow;
23806
+ if (group.first && i2 === facts.first) color = colors.colorFirst;
23807
+ if (group.last && i2 === facts.last) color = colors.colorLast;
23808
+ return color;
23809
+ }
23810
+ function resolveColors(group, theme2) {
23811
+ const out = { ...DEFAULTS };
23812
+ for (const key of Object.keys(DEFAULTS)) {
23813
+ const color = group[key];
23814
+ out[key] = resolveColor(color, theme2, DEFAULTS[key]) ?? DEFAULTS[key];
23815
+ }
23816
+ return out;
23817
+ }
23818
+ function sparklineView(group, data, scale2, theme2) {
23819
+ const colors = resolveColors(group, theme2);
23820
+ const view = {
23821
+ type: group.type,
23822
+ color: colors.colorSeries,
23823
+ lineWeightPt: group.lineWeight,
23824
+ lines: [],
23825
+ markers: [],
23826
+ columns: []
23827
+ };
23828
+ const values2 = sparklineValues(group, data.values);
23829
+ const n2 = values2.length;
23830
+ if (!n2 || !scale2) return view;
23831
+ const facts = pointFacts(values2);
23832
+ const xs = positions(group, data, n2);
23833
+ const flip = (x) => group.rightToLeft ? 1 - x : x;
23834
+ const range = scale2.max - scale2.min;
23835
+ const yOf = (v) => range ? Math.max(0, Math.min(1, (scale2.max - v) / range)) : 0.5;
23836
+ if (group.type === "line") {
23837
+ let segment = [];
23838
+ values2.forEach((v, i2) => {
23839
+ const x = xs[i2];
23840
+ if (v === null || x === null || x === void 0) {
23841
+ if (group.displayEmptyCellsAs === "gap" && segment.length) {
23842
+ view.lines.push(segment);
23843
+ segment = [];
23844
+ }
23845
+ return;
23846
+ }
23847
+ const point = { x: flip(x), y: yOf(v) };
23848
+ segment.push(point);
23849
+ const color = pointColor(group, v, i2, facts, colors, true);
23850
+ if (color) view.markers.push({ ...point, color });
23851
+ });
23852
+ if (segment.length) view.lines.push(segment);
23853
+ } else {
23854
+ const slot2 = 1 / n2;
23855
+ const w = slot2 * (1 - COLUMN_GAP);
23856
+ const base = yOf(Math.max(scale2.min, Math.min(scale2.max, 0)));
23857
+ values2.forEach((v, i2) => {
23858
+ const position = xs[i2];
23859
+ if (v === null || position === null || position === void 0) return;
23860
+ if (v === 0) return;
23861
+ let top;
23862
+ let bottom;
23863
+ if (group.type === "stacked") [top, bottom] = v > 0 ? [0, 0.5] : [0.5, 1];
23864
+ else if (!range) [top, bottom] = [0, 1];
23865
+ else [top, bottom] = [Math.min(base, yOf(v)), Math.max(base, yOf(v))];
23866
+ const centre = flip(slot2 / 2 + position * (1 - slot2));
23867
+ const color = pointColor(group, v, i2, facts, colors, false) ?? view.color;
23868
+ view.columns.push({ x: centre - w / 2, y: top, w, h: bottom - top, color });
23869
+ });
23870
+ }
23871
+ if (group.type === "stacked") {
23872
+ if (group.displayXAxis) view.axis = { y: 0.5, color: colors.colorAxis };
23873
+ } else if (group.displayXAxis && range && scale2.min <= 0 && scale2.max >= 0)
23874
+ view.axis = { y: yOf(0), color: colors.colorAxis };
23875
+ return view;
23876
+ }
23877
+
23878
+ // xlsx/layout/sparkline-data.ts
23879
+ var MAX_POINTS = 1e4;
23880
+ var hostIndex = /* @__PURE__ */ new WeakMap();
23881
+ function hosts(sheet) {
23882
+ const groups = sheetSparklineGroups(sheet);
23883
+ let index2 = hostIndex.get(groups);
23884
+ if (!index2) {
23885
+ index2 = /* @__PURE__ */ new Map();
23886
+ for (const group of groups)
23887
+ group.sparklines.forEach((line3, i2) => {
23888
+ const key = cellKey(line3.host.start.row, line3.host.start.col);
23889
+ if (!index2.has(key)) index2.set(key, { group, index: i2 });
23890
+ });
23891
+ hostIndex.set(groups, index2);
23892
+ }
23893
+ return index2;
23894
+ }
23895
+ function hasSparklineAt(sheet, row2, col) {
23896
+ return hosts(sheet).has(cellKey(row2, col));
23897
+ }
23898
+ function resolveSparklineRange(workbook, sheet, formula) {
23899
+ const ref = formula.trim().replace(/^=/, "");
23900
+ const bang = ref.lastIndexOf("!");
23901
+ let target = sheet;
23902
+ if (bang >= 0) {
23903
+ const raw2 = ref.slice(0, bang);
23904
+ const name = /^'.*'$/.test(raw2) ? raw2.slice(1, -1).replace(/''/g, "'") : raw2;
23905
+ target = sheetByName(workbook, name);
23906
+ }
23907
+ const range = parseRange(ref.slice(bang + 1).replace(/\$/g, ""));
23908
+ return target && range ? { sheet: target, range: normalizeRange(range) } : void 0;
23909
+ }
23910
+ var rowHidden = (sheet, row2) => sheet.rowInfo.get(row2)?.hidden === true;
23911
+ var colHidden = (sheet, col) => sheet.columns.some((c2) => c2.hidden === true && col >= c2.min && col <= c2.max);
23912
+ function readSparklineValues(sheet, range, displayHidden) {
23913
+ let endRow = range.end.row;
23914
+ if (endRow - range.start.row >= MAX_POINTS) {
23915
+ let lastRow = range.start.row;
23916
+ for (const row2 of sheet.rows.keys()) if (row2 > lastRow) lastRow = row2;
23917
+ endRow = Math.min(endRow, lastRow);
23918
+ }
23919
+ const out = [];
23920
+ for (let row2 = range.start.row; row2 <= endRow && out.length < MAX_POINTS; row2++) {
23921
+ if (!displayHidden && rowHidden(sheet, row2)) continue;
23922
+ for (let col = range.start.col; col <= range.end.col && out.length < MAX_POINTS; col++) {
23923
+ if (!displayHidden && colHidden(sheet, col)) continue;
23924
+ const value = getCell(sheet, row2, col)?.value;
23925
+ out.push(typeof value === "number" && Number.isFinite(value) ? value : null);
23926
+ }
23927
+ }
23928
+ return out;
23929
+ }
23930
+ function groupData(workbook, sheet, group) {
23931
+ const dateRange = group.dateAxis && group.dateFormula;
23932
+ const dates = dateRange ? resolveSparklineRange(workbook, sheet, dateRange) : void 0;
23933
+ const dateValues = dates ? readSparklineValues(dates.sheet, dates.range, group.displayHidden) : void 0;
23934
+ return group.sparklines.map((line3) => {
23935
+ const source2 = line3.formula ? resolveSparklineRange(workbook, sheet, line3.formula) : void 0;
23936
+ const values2 = source2 ? readSparklineValues(source2.sheet, source2.range, group.displayHidden) : [];
23937
+ return dateValues ? { values: values2, dates: dateValues } : { values: values2 };
23938
+ });
23939
+ }
23940
+ function sparklineViewAt(workbook, sheetIndex2, row2, col) {
23941
+ const sheet = workbook.sheets[sheetIndex2];
23942
+ if (!sheet) return void 0;
23943
+ const entry3 = hosts(sheet).get(cellKey(row2, col));
23944
+ if (!entry3) return void 0;
23945
+ const { group, index: index2 } = entry3;
23946
+ const needsGroup = group.minAxisType === "group" || group.maxAxisType === "group";
23947
+ const data = needsGroup ? groupData(workbook, sheet, group) : groupData(workbook, sheet, { ...group, sparklines: [group.sparklines[index2]] });
23948
+ const at = needsGroup ? index2 : 0;
23949
+ return sparklineView(
23950
+ group,
23951
+ data[at] ?? { values: [] },
23952
+ sparklineScale(group, data, at),
23953
+ workbook.theme
23954
+ );
23955
+ }
23956
+
23957
+ // xlsx/write/chart-cache.ts
23958
+ var MAX_CHART_CACHE_CELLS = 1e4;
23959
+ function referenceValues(workbook, sheet, ref, maxCells = MAX_CHART_CACHE_CELLS) {
23960
+ if (!ref) return void 0;
23961
+ const target = resolveSparklineRange(workbook, sheet, ref);
23962
+ if (!target) return void 0;
23963
+ const { range } = target;
23964
+ const count2 = rangeSize(range);
23965
+ if (!Number.isSafeInteger(count2) || count2 < 1 || count2 > maxCells || range.end.row > MAX_ROW || range.end.col > MAX_COL)
23966
+ return void 0;
23967
+ const values2 = [];
23968
+ for (let row2 = range.start.row; row2 <= range.end.row; row2++)
23969
+ for (let col = range.start.col; col <= range.end.col; col++)
23970
+ values2.push(getValue(target.sheet, row2, col));
23971
+ return values2;
23972
+ }
23973
+ function categoryValue(value) {
23974
+ if (value === null) return "";
23975
+ if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
23976
+ if (typeof value === "object") return value.error;
23977
+ if (typeof value === "number" && !Number.isFinite(value)) return "";
23978
+ return value;
23979
+ }
23980
+ function chartWithCurrentCaches(workbook, sheet, chart) {
23981
+ return {
23982
+ ...chart,
23983
+ series: chart.series.map((series) => {
23984
+ const values2 = referenceValues(workbook, sheet, series.valuesRef);
23985
+ const categories = referenceValues(workbook, sheet, series.categoriesRef);
23986
+ const name = referenceValues(workbook, sheet, series.nameRef, 1);
23987
+ return {
23988
+ ...series,
23989
+ ...name === void 0 ? {} : { name: String(categoryValue(name[0] ?? null)) },
23990
+ values: values2?.map(
23991
+ (value) => typeof value === "number" && Number.isFinite(value) ? value : null
23992
+ ) ?? series.values,
23993
+ categories: categories?.map(categoryValue) ?? series.categories
23994
+ };
23995
+ })
23996
+ };
23997
+ }
23998
+
23741
23999
  // xlsx/write/vml-ids.ts
23742
24000
  var IDS_PER_BLOCK = 1024;
23743
24001
  function vmlIdmapBlocks(xml) {
@@ -24206,7 +24464,10 @@ function writeSheetDrawing(ctx, sheet, partName, rels, sourceDrawing) {
24206
24464
  }
24207
24465
  }
24208
24466
  const target = sourceDrawing && !writer.has(sourceDrawing) ? sourceDrawing : writer.uniqueName((n2) => `xl/drawings/drawing${n2}.xml`, ctx.reserved);
24209
- if (!writeDrawing(writer, target, sheet.drawings, sourceDrawing)) return "";
24467
+ const drawings = sheet.drawings.map(
24468
+ (object) => object.kind === "chart" && (!object.partName || !source2?.has(object.partName)) ? chartWithCurrentCaches(ctx.workbook, sheet, object) : object
24469
+ );
24470
+ if (!writeDrawing(writer, target, drawings, sourceDrawing)) return "";
24210
24471
  return `<drawing r:id="${rels.add(RELATIONSHIP_TYPES.drawing, relativeTarget(partName, target))}"/>`;
24211
24472
  }
24212
24473
 
@@ -27397,6 +27658,7 @@ function sortRows2(sheet, range, keys, hasHeader) {
27397
27658
  const sortKeys2 = keys.length ? keys : [{ col: r.start.col }];
27398
27659
  const rows = [];
27399
27660
  for (let row2 = firstRow; row2 <= lastRow; row2++) {
27661
+ if (sheet.rowInfo.get(row2)?.hidden) continue;
27400
27662
  const cells = /* @__PURE__ */ new Map();
27401
27663
  for (const [col, cell] of sheet.rows.get(row2) ?? [])
27402
27664
  if (col >= r.start.col && col <= r.end.col) cells.set(col, cell);
@@ -27414,9 +27676,9 @@ function sortRows2(sheet, range, keys, hasHeader) {
27414
27676
  return 0;
27415
27677
  });
27416
27678
  for (const { row: row2, cells } of rows) for (const col of cells.keys()) deleteCell(sheet, row2, col);
27417
- moveAnnotations(sheet, dataArea, new Map(sorted2.map((source2, i2) => [source2.row, firstRow + i2])));
27679
+ moveAnnotations(sheet, dataArea, new Map(sorted2.map((source2, i2) => [source2.row, rows[i2].row])));
27418
27680
  sorted2.forEach((source2, i2) => {
27419
- const row2 = firstRow + i2;
27681
+ const row2 = rows[i2].row;
27420
27682
  const dRow = row2 - source2.row;
27421
27683
  for (const [col, cell] of source2.cells) {
27422
27684
  if (cell.formula !== void 0 && dRow) {
@@ -31174,222 +31436,6 @@ function bordersView(border, theme2) {
31174
31436
  return out;
31175
31437
  }
31176
31438
 
31177
- // xlsx/layout/sparkline-view.ts
31178
- var DEFAULTS = {
31179
- colorSeries: "#376092",
31180
- colorNegative: "#D00000",
31181
- colorAxis: "#000000",
31182
- colorMarkers: "#D00000",
31183
- colorFirst: "#D00000",
31184
- colorLast: "#D00000",
31185
- colorHigh: "#D00000",
31186
- colorLow: "#D00000"
31187
- };
31188
- var COLUMN_GAP = 0.2;
31189
- function extent(values2) {
31190
- let min = Infinity;
31191
- let max = -Infinity;
31192
- for (const v of values2) {
31193
- if (v === null) continue;
31194
- if (v < min) min = v;
31195
- if (v > max) max = v;
31196
- }
31197
- return min <= max ? { min, max } : void 0;
31198
- }
31199
- function sparklineValues(group, values2) {
31200
- return group.displayEmptyCellsAs === "zero" ? values2.map((v) => v ?? 0) : [...values2];
31201
- }
31202
- function sparklineScale(group, all2, index2) {
31203
- const own = extent(sparklineValues(group, all2[index2]?.values ?? []));
31204
- const needsGroup = group.minAxisType === "group" || group.maxAxisType === "group";
31205
- const shared = needsGroup ? extent(all2.flatMap((data) => sparklineValues(group, data.values))) : void 0;
31206
- const end = (type, manual, key) => {
31207
- if (type === "custom" && manual !== void 0) return manual;
31208
- if (type === "group" && shared) return shared[key];
31209
- return own?.[key];
31210
- };
31211
- const min = end(group.minAxisType, group.manualMin, "min");
31212
- const max = end(group.maxAxisType, group.manualMax, "max");
31213
- return min === void 0 || max === void 0 ? void 0 : { min, max };
31214
- }
31215
- function positions(group, data, n2) {
31216
- const dates = data.dates;
31217
- if (group.dateAxis && dates && dates.length === n2) {
31218
- const span3 = extent(dates);
31219
- if (span3) {
31220
- const width = span3.max - span3.min;
31221
- return dates.map((d) => d === null ? null : width ? (d - span3.min) / width : 0.5);
31222
- }
31223
- }
31224
- return Array.from({ length: n2 }, (_, i2) => n2 === 1 ? 0.5 : i2 / (n2 - 1));
31225
- }
31226
- function pointFacts(values2) {
31227
- const numbers3 = values2.filter((x) => x !== null);
31228
- let last = values2.length - 1;
31229
- while (last >= 0 && values2[last] === null) last--;
31230
- return {
31231
- high: Math.max(...numbers3),
31232
- low: Math.min(...numbers3),
31233
- first: values2.findIndex((x) => x !== null),
31234
- last
31235
- };
31236
- }
31237
- function pointColor(group, v, i2, facts, colors, markers) {
31238
- let color = markers && group.markers ? colors.colorMarkers : void 0;
31239
- if (group.negative && v < 0) color = colors.colorNegative;
31240
- if (group.high && v === facts.high) color = colors.colorHigh;
31241
- if (group.low && v === facts.low) color = colors.colorLow;
31242
- if (group.first && i2 === facts.first) color = colors.colorFirst;
31243
- if (group.last && i2 === facts.last) color = colors.colorLast;
31244
- return color;
31245
- }
31246
- function resolveColors(group, theme2) {
31247
- const out = { ...DEFAULTS };
31248
- for (const key of Object.keys(DEFAULTS)) {
31249
- const color = group[key];
31250
- out[key] = resolveColor(color, theme2, DEFAULTS[key]) ?? DEFAULTS[key];
31251
- }
31252
- return out;
31253
- }
31254
- function sparklineView(group, data, scale2, theme2) {
31255
- const colors = resolveColors(group, theme2);
31256
- const view = {
31257
- type: group.type,
31258
- color: colors.colorSeries,
31259
- lineWeightPt: group.lineWeight,
31260
- lines: [],
31261
- markers: [],
31262
- columns: []
31263
- };
31264
- const values2 = sparklineValues(group, data.values);
31265
- const n2 = values2.length;
31266
- if (!n2 || !scale2) return view;
31267
- const facts = pointFacts(values2);
31268
- const xs = positions(group, data, n2);
31269
- const flip = (x) => group.rightToLeft ? 1 - x : x;
31270
- const range = scale2.max - scale2.min;
31271
- const yOf = (v) => range ? Math.max(0, Math.min(1, (scale2.max - v) / range)) : 0.5;
31272
- if (group.type === "line") {
31273
- let segment = [];
31274
- values2.forEach((v, i2) => {
31275
- const x = xs[i2];
31276
- if (v === null || x === null || x === void 0) {
31277
- if (group.displayEmptyCellsAs === "gap" && segment.length) {
31278
- view.lines.push(segment);
31279
- segment = [];
31280
- }
31281
- return;
31282
- }
31283
- const point = { x: flip(x), y: yOf(v) };
31284
- segment.push(point);
31285
- const color = pointColor(group, v, i2, facts, colors, true);
31286
- if (color) view.markers.push({ ...point, color });
31287
- });
31288
- if (segment.length) view.lines.push(segment);
31289
- } else {
31290
- const slot2 = 1 / n2;
31291
- const w = slot2 * (1 - COLUMN_GAP);
31292
- const base = yOf(Math.max(scale2.min, Math.min(scale2.max, 0)));
31293
- values2.forEach((v, i2) => {
31294
- const position = xs[i2];
31295
- if (v === null || position === null || position === void 0) return;
31296
- if (v === 0) return;
31297
- let top;
31298
- let bottom;
31299
- if (group.type === "stacked") [top, bottom] = v > 0 ? [0, 0.5] : [0.5, 1];
31300
- else if (!range) [top, bottom] = [0, 1];
31301
- else [top, bottom] = [Math.min(base, yOf(v)), Math.max(base, yOf(v))];
31302
- const centre = flip(slot2 / 2 + position * (1 - slot2));
31303
- const color = pointColor(group, v, i2, facts, colors, false) ?? view.color;
31304
- view.columns.push({ x: centre - w / 2, y: top, w, h: bottom - top, color });
31305
- });
31306
- }
31307
- if (group.type === "stacked") {
31308
- if (group.displayXAxis) view.axis = { y: 0.5, color: colors.colorAxis };
31309
- } else if (group.displayXAxis && range && scale2.min <= 0 && scale2.max >= 0)
31310
- view.axis = { y: yOf(0), color: colors.colorAxis };
31311
- return view;
31312
- }
31313
-
31314
- // xlsx/layout/sparkline-data.ts
31315
- var MAX_POINTS = 1e4;
31316
- var hostIndex = /* @__PURE__ */ new WeakMap();
31317
- function hosts(sheet) {
31318
- const groups = sheetSparklineGroups(sheet);
31319
- let index2 = hostIndex.get(groups);
31320
- if (!index2) {
31321
- index2 = /* @__PURE__ */ new Map();
31322
- for (const group of groups)
31323
- group.sparklines.forEach((line3, i2) => {
31324
- const key = cellKey(line3.host.start.row, line3.host.start.col);
31325
- if (!index2.has(key)) index2.set(key, { group, index: i2 });
31326
- });
31327
- hostIndex.set(groups, index2);
31328
- }
31329
- return index2;
31330
- }
31331
- function hasSparklineAt(sheet, row2, col) {
31332
- return hosts(sheet).has(cellKey(row2, col));
31333
- }
31334
- function resolveSparklineRange(workbook, sheet, formula) {
31335
- const ref = formula.trim().replace(/^=/, "");
31336
- const bang = ref.lastIndexOf("!");
31337
- let target = sheet;
31338
- if (bang >= 0) {
31339
- const raw2 = ref.slice(0, bang);
31340
- const name = /^'.*'$/.test(raw2) ? raw2.slice(1, -1).replace(/''/g, "'") : raw2;
31341
- target = sheetByName(workbook, name);
31342
- }
31343
- const range = parseRange(ref.slice(bang + 1).replace(/\$/g, ""));
31344
- return target && range ? { sheet: target, range: normalizeRange(range) } : void 0;
31345
- }
31346
- var rowHidden = (sheet, row2) => sheet.rowInfo.get(row2)?.hidden === true;
31347
- var colHidden = (sheet, col) => sheet.columns.some((c2) => c2.hidden === true && col >= c2.min && col <= c2.max);
31348
- function readSparklineValues(sheet, range, displayHidden) {
31349
- let endRow = range.end.row;
31350
- if (endRow - range.start.row >= MAX_POINTS) {
31351
- let lastRow = range.start.row;
31352
- for (const row2 of sheet.rows.keys()) if (row2 > lastRow) lastRow = row2;
31353
- endRow = Math.min(endRow, lastRow);
31354
- }
31355
- const out = [];
31356
- for (let row2 = range.start.row; row2 <= endRow && out.length < MAX_POINTS; row2++) {
31357
- if (!displayHidden && rowHidden(sheet, row2)) continue;
31358
- for (let col = range.start.col; col <= range.end.col && out.length < MAX_POINTS; col++) {
31359
- if (!displayHidden && colHidden(sheet, col)) continue;
31360
- const value = getCell(sheet, row2, col)?.value;
31361
- out.push(typeof value === "number" && Number.isFinite(value) ? value : null);
31362
- }
31363
- }
31364
- return out;
31365
- }
31366
- function groupData(workbook, sheet, group) {
31367
- const dateRange = group.dateAxis && group.dateFormula;
31368
- const dates = dateRange ? resolveSparklineRange(workbook, sheet, dateRange) : void 0;
31369
- const dateValues = dates ? readSparklineValues(dates.sheet, dates.range, group.displayHidden) : void 0;
31370
- return group.sparklines.map((line3) => {
31371
- const source2 = line3.formula ? resolveSparklineRange(workbook, sheet, line3.formula) : void 0;
31372
- const values2 = source2 ? readSparklineValues(source2.sheet, source2.range, group.displayHidden) : [];
31373
- return dateValues ? { values: values2, dates: dateValues } : { values: values2 };
31374
- });
31375
- }
31376
- function sparklineViewAt(workbook, sheetIndex2, row2, col) {
31377
- const sheet = workbook.sheets[sheetIndex2];
31378
- if (!sheet) return void 0;
31379
- const entry3 = hosts(sheet).get(cellKey(row2, col));
31380
- if (!entry3) return void 0;
31381
- const { group, index: index2 } = entry3;
31382
- const needsGroup = group.minAxisType === "group" || group.maxAxisType === "group";
31383
- const data = needsGroup ? groupData(workbook, sheet, group) : groupData(workbook, sheet, { ...group, sparklines: [group.sparklines[index2]] });
31384
- const at = needsGroup ? index2 : 0;
31385
- return sparklineView(
31386
- group,
31387
- data[at] ?? { values: [] },
31388
- sparklineScale(group, data, at),
31389
- workbook.theme
31390
- );
31391
- }
31392
-
31393
31439
  // xlsx/layout/units.ts
31394
31440
  var DEFAULT_MAX_DIGIT_WIDTH = 7;
31395
31441
  var DEFAULT_BASE_COL_WIDTH = 8;
@@ -31974,13 +32020,14 @@ function duplicateSheet(ctx, index2) {
31974
32020
  delete next.partName;
31975
32021
  return next;
31976
32022
  });
31977
- if (renames.length)
31978
- rewriteSheetFormulas(
31979
- copy,
31980
- (formula) => renames.reduce((f6, [from, to]) => renameTableInFormula(f6, from, to), formula)
31981
- );
32023
+ const rewrite2 = (formula) => renames.reduce(
32024
+ (f6, [from, to]) => renameTableInFormula(f6, from, to),
32025
+ renameSheetInFormula(formula, sheet.name, copy.name)
32026
+ );
32027
+ rewriteSheetFormulas(copy, rewrite2);
31982
32028
  for (const drawing of copy.drawings) if (drawing.kind === "chart") delete drawing.partName;
31983
32029
  const copiedNames = namesForCopy(workbook, index2, sheet.name, copy.name);
32030
+ for (const name of copiedNames) name.formula = rewrite2(name.formula);
31984
32031
  workbook.sheets.splice(at, 0, copy);
31985
32032
  remapSheets(workbook, (i2) => i2 >= at ? i2 + 1 : i2);
31986
32033
  for (const n2 of copiedNames) workbook.definedNames.push({ ...n2, localSheet: at });