ooxml-core 1.8.0 → 1.8.2

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.
@@ -3561,7 +3561,7 @@ function stack(ctx, args, vertical) {
3561
3561
  function flatten(ctx, args) {
3562
3562
  const m = ctx.toMatrix(args[0] ?? null);
3563
3563
  const ignore = intAt(ctx, args, 1) ?? 0;
3564
- const byCol = intAt(ctx, args, 2) ? true : false;
3564
+ const byCol = Boolean(intAt(ctx, args, 2));
3565
3565
  const values2 = [];
3566
3566
  const rows = byCol ? m.cols : m.rows;
3567
3567
  const cols = byCol ? m.rows : m.cols;
@@ -6795,7 +6795,7 @@ function ifFn(args, ctx) {
6795
6795
  const branch = (truthy) => {
6796
6796
  const arg = args[truthy ? 1 : 2];
6797
6797
  if (arg) return arg.get();
6798
- return truthy ? true : false;
6798
+ return truthy;
6799
6799
  };
6800
6800
  if (cond instanceof Matrix) return elementwise(cond, branch, ctx);
6801
6801
  if (isError(cond)) return cond;
@@ -21950,10 +21950,10 @@ function patchChartColors(doc, chartNode, model, before) {
21950
21950
  const xml = fill ? drawingFillXml(fill) : color ? `<a:solidFill>${drawingColorXml(color)}</a:solidFill>` : void 0;
21951
21951
  let spPr = first(point, "spPr", NS.c);
21952
21952
  if (!xml) {
21953
- let paint = fillElementOf(spPr);
21954
- while (paint && spPr) {
21955
- spPr.removeChild(paint);
21956
- paint = fillElementOf(spPr);
21953
+ if (spPr) {
21954
+ for (let paint = fillElementOf(spPr); paint; paint = fillElementOf(spPr)) {
21955
+ spPr.removeChild(paint);
21956
+ }
21957
21957
  }
21958
21958
  continue;
21959
21959
  }
@@ -24347,8 +24347,8 @@ function protectionXml2(sheet) {
24347
24347
  values2["sheet"] = protection.sheet || void 0;
24348
24348
  const allow = new Set(protection.allow ?? []);
24349
24349
  if (protection.sheet) {
24350
- values2["objects"] = allow.has("objects") ? false : true;
24351
- values2["scenarios"] = allow.has("scenarios") ? false : true;
24350
+ values2["objects"] = !allow.has("objects");
24351
+ values2["scenarios"] = !allow.has("scenarios");
24352
24352
  }
24353
24353
  for (const name of allow) values2[name] = false;
24354
24354
  return el("sheetProtection", values2);
@@ -24742,6 +24742,29 @@ function pruneCell(sheet, row2, col) {
24742
24742
 
24743
24743
  // xlsx/edit/shift-preserved.ts
24744
24744
  var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
24745
+ function hasPreservedOverflow(sheet, shift2, clipped, banded) {
24746
+ const keys = banded ? ["extLst"] : [shift2.axis === "row" ? "rowBreaks" : "colBreaks", "extLst"];
24747
+ for (const key of keys)
24748
+ for (const xml of sheet.preserved.get(key) ?? []) {
24749
+ if (!xml.includes(key === "extLst" ? "sqref" : "brk")) continue;
24750
+ let root;
24751
+ try {
24752
+ root = parseXml(xml).documentElement;
24753
+ } catch {
24754
+ continue;
24755
+ }
24756
+ if (key === "extLst") {
24757
+ if (descendants3(root, XM3, "sqref").some(
24758
+ (node) => parseSqref(node.textContent ?? "").some(clipped)
24759
+ ))
24760
+ return true;
24761
+ } else if (elements(root).some(
24762
+ (node) => node.localName === "brk" && shiftIndex(Number(node.getAttribute("id") ?? "0"), shift2) === void 0
24763
+ ))
24764
+ return true;
24765
+ }
24766
+ return false;
24767
+ }
24745
24768
  function descendants3(root, ns, local) {
24746
24769
  return Array.from(root.getElementsByTagNameNS(ns, local));
24747
24770
  }
@@ -25976,6 +25999,39 @@ function setBorders(ctx, s, range, preset, edge2 = { style: "thin" }) {
25976
25999
  );
25977
26000
  }
25978
26001
 
26002
+ // xlsx/edit/insert-guard.ts
26003
+ function assertInsertFits(sheet, shift2, band) {
26004
+ if (shift2.count <= 0) return;
26005
+ const max = shift2.axis === "row" ? MAX_ROW : MAX_COL;
26006
+ if (shift2.at + shift2.count > max + 1)
26007
+ throw new RangeError("The insert area extends beyond the sheet.");
26008
+ const first2 = max - shift2.count + 1;
26009
+ const lost = shift2.axis === "row" ? cellRange(first2, band?.lo ?? 0, MAX_ROW, band?.hi ?? MAX_COL) : cellRange(band?.lo ?? 0, first2, band?.hi ?? MAX_ROW, MAX_COL);
26010
+ const other = shift2.axis === "row" ? "col" : "row";
26011
+ const clipped = (range) => (!band || range.start[other] >= band.lo && range.end[other] <= band.hi) && rangesIntersect(range, lost);
26012
+ const fail2 = () => {
26013
+ throw new Error("Cannot insert cells: non-empty cells would be pushed off the sheet.");
26014
+ };
26015
+ for (const [row2, cells] of sheet.rows) {
26016
+ if (row2 < lost.start.row || row2 > lost.end.row) continue;
26017
+ for (const [col, cell] of cells)
26018
+ if (col >= lost.start.col && col <= lost.end.col && (!isEmptyCell(cell) || cell.cellMetadata !== void 0 || cell.valueMetadata !== void 0))
26019
+ fail2();
26020
+ }
26021
+ if (sheet.comments.some((c2) => rangesIntersect(cellRange(c2.address.row, c2.address.col), lost)) || sheet.hyperlinks.some((h2) => rangesIntersect(h2.range, lost)) || sheet.merges.some((m) => rangesIntersect(m, lost)) || sheet.tables.some((t) => rangesIntersect(t.range, lost)) || sheet.dataValidations.some((rule) => rule.ranges.some(clipped)) || sheet.conditionalFormats.some((format) => format.ranges.some(clipped)) || sheet.autoFilter !== void 0 && clipped(sheet.autoFilter.range) || sheet.pageSetup?.printArea !== void 0 && clipped(sheet.pageSetup.printArea) || hasPreservedOverflow(sheet, shift2, clipped, !!band))
26022
+ fail2();
26023
+ for (const { anchor } of sheet.drawings) {
26024
+ if (band && (anchor.from[other] < band.lo || anchor.from[other] > band.hi)) continue;
26025
+ if (anchor.from[shift2.axis] >= first2 || anchor.to && anchor.to[shift2.axis] >= first2) fail2();
26026
+ }
26027
+ if (band) return;
26028
+ if (shift2.axis === "row") {
26029
+ for (const [row2, info] of sheet.rowInfo) if (row2 >= first2 && Object.keys(info).length) fail2();
26030
+ } else {
26031
+ if (normalizeColumns(sheet.columns).some((c2) => c2.min >= first2)) fail2();
26032
+ }
26033
+ }
26034
+
25979
26035
  // xlsx/edit/shift-rule-anchors.ts
25980
26036
  function rebaseRulesForDeletion(sheet, shift2, band) {
25981
26037
  if (shift2.count >= 0) return;
@@ -25997,6 +26053,7 @@ function rebaseRulesForDeletion(sheet, shift2, band) {
25997
26053
 
25998
26054
  // xlsx/edit/shift-sheet.ts
25999
26055
  function shiftSheetContent(sheet, shift2, band) {
26056
+ assertInsertFits(sheet, shift2, band);
26000
26057
  const moveRange = (range) => band ? shiftRangeInBand(range, shift2, band.lo, band.hi) : shiftRange(range, shift2);
26001
26058
  shiftCells(sheet, shift2, band, moveRange);
26002
26059
  sheet.merges = sheet.merges.map(moveRange).filter((m) => !!m && (m.start.row !== m.end.row || m.start.col !== m.end.col));
@@ -26134,10 +26191,11 @@ function shiftFreeze(sheet, shift2) {
26134
26191
  // xlsx/edit/structure.ts
26135
26192
  function checkSpan(axis, at, count2) {
26136
26193
  const max = axis === "row" ? MAX_ROW : MAX_COL;
26137
- if (!Number.isInteger(at) || !Number.isInteger(count2) || at < 0 || at > max || count2 < 1)
26194
+ if (!Number.isInteger(at) || !Number.isInteger(count2) || at < 0 || at > max || count2 < 1 || at + count2 > max + 1)
26138
26195
  throw new RangeError(`Invalid ${axis} span ${at} + ${count2}`);
26139
26196
  }
26140
26197
  function applyAxisShift(ctx, sheet, shift2) {
26198
+ assertInsertFits(sheet, shift2);
26141
26199
  rebaseRulesForDeletion(sheet, shift2);
26142
26200
  const spec2 = { sheet: sheet.name, axis: shift2.axis, at: shift2.at, count: shift2.count };
26143
26201
  rewriteFormulas(
@@ -26171,6 +26229,7 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
26171
26229
  const sheet = sheetAt(ctx.workbook, s);
26172
26230
  const noun = axis === "row" ? count2 === 1 ? "row" : "rows" : count2 === 1 ? "column" : "columns";
26173
26231
  const shift2 = { axis, at, count: insert ? count2 : -count2 };
26232
+ assertInsertFits(sheet, shift2);
26174
26233
  const info = { sheet: s, structural: true };
26175
26234
  if (!sheet.autoFilter || shiftRange(sheet.autoFilter.range, shift2))
26176
26235
  info.calc = { kind: "shift", sheet: s, shift: shift2 };
@@ -26213,6 +26272,7 @@ function shiftBand(ctx, s, range, direction) {
26213
26272
  };
26214
26273
  const band = vertical ? { lo: r.start.col, hi: r.end.col } : { lo: r.start.row, hi: r.end.row };
26215
26274
  assertBandIntact(sheet, shift2, band);
26275
+ assertInsertFits(sheet, shift2, band);
26216
26276
  ctx.run(
26217
26277
  `${insert ? "Insert" : "Delete"} cells`,
26218
26278
  "structure",
@@ -28711,6 +28771,7 @@ var byId = (sheet, id) => {
28711
28771
  function insertBandRow(workbook, sheet, table2, row2) {
28712
28772
  const shift2 = { axis: "row", at: row2, count: 1 };
28713
28773
  const band = { lo: table2.range.start.col, hi: table2.range.end.col };
28774
+ assertInsertFits(sheet, shift2, band);
28714
28775
  rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
28715
28776
  shiftSheetContent(sheet, shift2, band);
28716
28777
  }
@@ -28749,6 +28810,7 @@ function setTotalsRow(workbook, sheet, id, on) {
28749
28810
  table2.totalsRow = false;
28750
28811
  return;
28751
28812
  }
28813
+ if (end.row === MAX_ROW) throw new RangeError("The insert area extends beyond the sheet.");
28752
28814
  if (!rowIsEmpty(sheet, end.row + 1, start.col, end.col)) {
28753
28815
  insertBandRow(workbook, sheet, table2, end.row + 1);
28754
28816
  table2 = byId(sheet, id);
@@ -3555,7 +3555,7 @@ function stack(ctx, args, vertical) {
3555
3555
  function flatten(ctx, args) {
3556
3556
  const m = ctx.toMatrix(args[0] ?? null);
3557
3557
  const ignore = intAt(ctx, args, 1) ?? 0;
3558
- const byCol = intAt(ctx, args, 2) ? true : false;
3558
+ const byCol = Boolean(intAt(ctx, args, 2));
3559
3559
  const values2 = [];
3560
3560
  const rows = byCol ? m.cols : m.rows;
3561
3561
  const cols = byCol ? m.rows : m.cols;
@@ -6789,7 +6789,7 @@ function ifFn(args, ctx) {
6789
6789
  const branch = (truthy) => {
6790
6790
  const arg = args[truthy ? 1 : 2];
6791
6791
  if (arg) return arg.get();
6792
- return truthy ? true : false;
6792
+ return truthy;
6793
6793
  };
6794
6794
  if (cond instanceof Matrix) return elementwise(cond, branch, ctx);
6795
6795
  if (isError(cond)) return cond;
@@ -21944,10 +21944,10 @@ function patchChartColors(doc, chartNode, model, before) {
21944
21944
  const xml = fill ? drawingFillXml(fill) : color ? `<a:solidFill>${drawingColorXml(color)}</a:solidFill>` : void 0;
21945
21945
  let spPr = first(point, "spPr", NS.c);
21946
21946
  if (!xml) {
21947
- let paint = fillElementOf(spPr);
21948
- while (paint && spPr) {
21949
- spPr.removeChild(paint);
21950
- paint = fillElementOf(spPr);
21947
+ if (spPr) {
21948
+ for (let paint = fillElementOf(spPr); paint; paint = fillElementOf(spPr)) {
21949
+ spPr.removeChild(paint);
21950
+ }
21951
21951
  }
21952
21952
  continue;
21953
21953
  }
@@ -24341,8 +24341,8 @@ function protectionXml2(sheet) {
24341
24341
  values2["sheet"] = protection.sheet || void 0;
24342
24342
  const allow = new Set(protection.allow ?? []);
24343
24343
  if (protection.sheet) {
24344
- values2["objects"] = allow.has("objects") ? false : true;
24345
- values2["scenarios"] = allow.has("scenarios") ? false : true;
24344
+ values2["objects"] = !allow.has("objects");
24345
+ values2["scenarios"] = !allow.has("scenarios");
24346
24346
  }
24347
24347
  for (const name of allow) values2[name] = false;
24348
24348
  return el("sheetProtection", values2);
@@ -24736,6 +24736,29 @@ function pruneCell(sheet, row2, col) {
24736
24736
 
24737
24737
  // xlsx/edit/shift-preserved.ts
24738
24738
  var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
24739
+ function hasPreservedOverflow(sheet, shift2, clipped, banded) {
24740
+ const keys = banded ? ["extLst"] : [shift2.axis === "row" ? "rowBreaks" : "colBreaks", "extLst"];
24741
+ for (const key of keys)
24742
+ for (const xml of sheet.preserved.get(key) ?? []) {
24743
+ if (!xml.includes(key === "extLst" ? "sqref" : "brk")) continue;
24744
+ let root;
24745
+ try {
24746
+ root = parseXml(xml).documentElement;
24747
+ } catch {
24748
+ continue;
24749
+ }
24750
+ if (key === "extLst") {
24751
+ if (descendants3(root, XM3, "sqref").some(
24752
+ (node) => parseSqref(node.textContent ?? "").some(clipped)
24753
+ ))
24754
+ return true;
24755
+ } else if (elements(root).some(
24756
+ (node) => node.localName === "brk" && shiftIndex(Number(node.getAttribute("id") ?? "0"), shift2) === void 0
24757
+ ))
24758
+ return true;
24759
+ }
24760
+ return false;
24761
+ }
24739
24762
  function descendants3(root, ns, local) {
24740
24763
  return Array.from(root.getElementsByTagNameNS(ns, local));
24741
24764
  }
@@ -25970,6 +25993,39 @@ function setBorders(ctx, s, range, preset, edge2 = { style: "thin" }) {
25970
25993
  );
25971
25994
  }
25972
25995
 
25996
+ // xlsx/edit/insert-guard.ts
25997
+ function assertInsertFits(sheet, shift2, band) {
25998
+ if (shift2.count <= 0) return;
25999
+ const max = shift2.axis === "row" ? MAX_ROW : MAX_COL;
26000
+ if (shift2.at + shift2.count > max + 1)
26001
+ throw new RangeError("The insert area extends beyond the sheet.");
26002
+ const first2 = max - shift2.count + 1;
26003
+ const lost = shift2.axis === "row" ? cellRange(first2, band?.lo ?? 0, MAX_ROW, band?.hi ?? MAX_COL) : cellRange(band?.lo ?? 0, first2, band?.hi ?? MAX_ROW, MAX_COL);
26004
+ const other = shift2.axis === "row" ? "col" : "row";
26005
+ const clipped = (range) => (!band || range.start[other] >= band.lo && range.end[other] <= band.hi) && rangesIntersect(range, lost);
26006
+ const fail2 = () => {
26007
+ throw new Error("Cannot insert cells: non-empty cells would be pushed off the sheet.");
26008
+ };
26009
+ for (const [row2, cells] of sheet.rows) {
26010
+ if (row2 < lost.start.row || row2 > lost.end.row) continue;
26011
+ for (const [col, cell] of cells)
26012
+ if (col >= lost.start.col && col <= lost.end.col && (!isEmptyCell(cell) || cell.cellMetadata !== void 0 || cell.valueMetadata !== void 0))
26013
+ fail2();
26014
+ }
26015
+ if (sheet.comments.some((c2) => rangesIntersect(cellRange(c2.address.row, c2.address.col), lost)) || sheet.hyperlinks.some((h2) => rangesIntersect(h2.range, lost)) || sheet.merges.some((m) => rangesIntersect(m, lost)) || sheet.tables.some((t) => rangesIntersect(t.range, lost)) || sheet.dataValidations.some((rule) => rule.ranges.some(clipped)) || sheet.conditionalFormats.some((format) => format.ranges.some(clipped)) || sheet.autoFilter !== void 0 && clipped(sheet.autoFilter.range) || sheet.pageSetup?.printArea !== void 0 && clipped(sheet.pageSetup.printArea) || hasPreservedOverflow(sheet, shift2, clipped, !!band))
26016
+ fail2();
26017
+ for (const { anchor } of sheet.drawings) {
26018
+ if (band && (anchor.from[other] < band.lo || anchor.from[other] > band.hi)) continue;
26019
+ if (anchor.from[shift2.axis] >= first2 || anchor.to && anchor.to[shift2.axis] >= first2) fail2();
26020
+ }
26021
+ if (band) return;
26022
+ if (shift2.axis === "row") {
26023
+ for (const [row2, info] of sheet.rowInfo) if (row2 >= first2 && Object.keys(info).length) fail2();
26024
+ } else {
26025
+ if (normalizeColumns(sheet.columns).some((c2) => c2.min >= first2)) fail2();
26026
+ }
26027
+ }
26028
+
25973
26029
  // xlsx/edit/shift-rule-anchors.ts
25974
26030
  function rebaseRulesForDeletion(sheet, shift2, band) {
25975
26031
  if (shift2.count >= 0) return;
@@ -25991,6 +26047,7 @@ function rebaseRulesForDeletion(sheet, shift2, band) {
25991
26047
 
25992
26048
  // xlsx/edit/shift-sheet.ts
25993
26049
  function shiftSheetContent(sheet, shift2, band) {
26050
+ assertInsertFits(sheet, shift2, band);
25994
26051
  const moveRange = (range) => band ? shiftRangeInBand(range, shift2, band.lo, band.hi) : shiftRange(range, shift2);
25995
26052
  shiftCells(sheet, shift2, band, moveRange);
25996
26053
  sheet.merges = sheet.merges.map(moveRange).filter((m) => !!m && (m.start.row !== m.end.row || m.start.col !== m.end.col));
@@ -26128,10 +26185,11 @@ function shiftFreeze(sheet, shift2) {
26128
26185
  // xlsx/edit/structure.ts
26129
26186
  function checkSpan(axis, at, count2) {
26130
26187
  const max = axis === "row" ? MAX_ROW : MAX_COL;
26131
- if (!Number.isInteger(at) || !Number.isInteger(count2) || at < 0 || at > max || count2 < 1)
26188
+ if (!Number.isInteger(at) || !Number.isInteger(count2) || at < 0 || at > max || count2 < 1 || at + count2 > max + 1)
26132
26189
  throw new RangeError(`Invalid ${axis} span ${at} + ${count2}`);
26133
26190
  }
26134
26191
  function applyAxisShift(ctx, sheet, shift2) {
26192
+ assertInsertFits(sheet, shift2);
26135
26193
  rebaseRulesForDeletion(sheet, shift2);
26136
26194
  const spec2 = { sheet: sheet.name, axis: shift2.axis, at: shift2.at, count: shift2.count };
26137
26195
  rewriteFormulas(
@@ -26165,6 +26223,7 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
26165
26223
  const sheet = sheetAt(ctx.workbook, s);
26166
26224
  const noun = axis === "row" ? count2 === 1 ? "row" : "rows" : count2 === 1 ? "column" : "columns";
26167
26225
  const shift2 = { axis, at, count: insert ? count2 : -count2 };
26226
+ assertInsertFits(sheet, shift2);
26168
26227
  const info = { sheet: s, structural: true };
26169
26228
  if (!sheet.autoFilter || shiftRange(sheet.autoFilter.range, shift2))
26170
26229
  info.calc = { kind: "shift", sheet: s, shift: shift2 };
@@ -26207,6 +26266,7 @@ function shiftBand(ctx, s, range, direction) {
26207
26266
  };
26208
26267
  const band = vertical ? { lo: r.start.col, hi: r.end.col } : { lo: r.start.row, hi: r.end.row };
26209
26268
  assertBandIntact(sheet, shift2, band);
26269
+ assertInsertFits(sheet, shift2, band);
26210
26270
  ctx.run(
26211
26271
  `${insert ? "Insert" : "Delete"} cells`,
26212
26272
  "structure",
@@ -28705,6 +28765,7 @@ var byId = (sheet, id) => {
28705
28765
  function insertBandRow(workbook, sheet, table2, row2) {
28706
28766
  const shift2 = { axis: "row", at: row2, count: 1 };
28707
28767
  const band = { lo: table2.range.start.col, hi: table2.range.end.col };
28768
+ assertInsertFits(sheet, shift2, band);
28708
28769
  rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
28709
28770
  shiftSheetContent(sheet, shift2, band);
28710
28771
  }
@@ -28743,6 +28804,7 @@ function setTotalsRow(workbook, sheet, id, on) {
28743
28804
  table2.totalsRow = false;
28744
28805
  return;
28745
28806
  }
28807
+ if (end.row === MAX_ROW) throw new RangeError("The insert area extends beyond the sheet.");
28746
28808
  if (!rowIsEmpty(sheet, end.row + 1, start.col, end.col)) {
28747
28809
  insertBandRow(workbook, sheet, table2, end.row + 1);
28748
28810
  table2 = byId(sheet, id);
@@ -11827,10 +11827,10 @@ function patchChartColors(doc, chartNode, model, before) {
11827
11827
  const xml = fill ? drawingFillXml(fill) : color ? `<a:solidFill>${drawingColorXml(color)}</a:solidFill>` : void 0;
11828
11828
  let spPr = first(point, "spPr", NS.c);
11829
11829
  if (!xml) {
11830
- let paint = fillElementOf(spPr);
11831
- while (paint && spPr) {
11832
- spPr.removeChild(paint);
11833
- paint = fillElementOf(spPr);
11830
+ if (spPr) {
11831
+ for (let paint = fillElementOf(spPr); paint; paint = fillElementOf(spPr)) {
11832
+ spPr.removeChild(paint);
11833
+ }
11834
11834
  }
11835
11835
  continue;
11836
11836
  }
@@ -13344,7 +13344,7 @@ function stack(ctx, args, vertical) {
13344
13344
  function flatten(ctx, args) {
13345
13345
  const m = ctx.toMatrix(args[0] ?? null);
13346
13346
  const ignore = intAt(ctx, args, 1) ?? 0;
13347
- const byCol = intAt(ctx, args, 2) ? true : false;
13347
+ const byCol = Boolean(intAt(ctx, args, 2));
13348
13348
  const values2 = [];
13349
13349
  const rows = byCol ? m.cols : m.rows;
13350
13350
  const cols = byCol ? m.rows : m.cols;
@@ -16300,7 +16300,7 @@ function ifFn(args, ctx) {
16300
16300
  const branch = (truthy) => {
16301
16301
  const arg = args[truthy ? 1 : 2];
16302
16302
  if (arg) return arg.get();
16303
- return truthy ? true : false;
16303
+ return truthy;
16304
16304
  };
16305
16305
  if (cond instanceof Matrix) return elementwise(cond, branch, ctx);
16306
16306
  if (isError(cond)) return cond;
@@ -22840,8 +22840,8 @@ function protectionXml2(sheet) {
22840
22840
  values2["sheet"] = protection.sheet || void 0;
22841
22841
  const allow = new Set(protection.allow ?? []);
22842
22842
  if (protection.sheet) {
22843
- values2["objects"] = allow.has("objects") ? false : true;
22844
- values2["scenarios"] = allow.has("scenarios") ? false : true;
22843
+ values2["objects"] = !allow.has("objects");
22844
+ values2["scenarios"] = !allow.has("scenarios");
22845
22845
  }
22846
22846
  for (const name of allow) values2[name] = false;
22847
22847
  return el("sheetProtection", values2);
@@ -11821,10 +11821,10 @@ function patchChartColors(doc, chartNode, model, before) {
11821
11821
  const xml = fill ? drawingFillXml(fill) : color ? `<a:solidFill>${drawingColorXml(color)}</a:solidFill>` : void 0;
11822
11822
  let spPr = first(point, "spPr", NS.c);
11823
11823
  if (!xml) {
11824
- let paint = fillElementOf(spPr);
11825
- while (paint && spPr) {
11826
- spPr.removeChild(paint);
11827
- paint = fillElementOf(spPr);
11824
+ if (spPr) {
11825
+ for (let paint = fillElementOf(spPr); paint; paint = fillElementOf(spPr)) {
11826
+ spPr.removeChild(paint);
11827
+ }
11828
11828
  }
11829
11829
  continue;
11830
11830
  }
@@ -13338,7 +13338,7 @@ function stack(ctx, args, vertical) {
13338
13338
  function flatten(ctx, args) {
13339
13339
  const m = ctx.toMatrix(args[0] ?? null);
13340
13340
  const ignore = intAt(ctx, args, 1) ?? 0;
13341
- const byCol = intAt(ctx, args, 2) ? true : false;
13341
+ const byCol = Boolean(intAt(ctx, args, 2));
13342
13342
  const values2 = [];
13343
13343
  const rows = byCol ? m.cols : m.rows;
13344
13344
  const cols = byCol ? m.rows : m.cols;
@@ -16294,7 +16294,7 @@ function ifFn(args, ctx) {
16294
16294
  const branch = (truthy) => {
16295
16295
  const arg = args[truthy ? 1 : 2];
16296
16296
  if (arg) return arg.get();
16297
- return truthy ? true : false;
16297
+ return truthy;
16298
16298
  };
16299
16299
  if (cond instanceof Matrix) return elementwise(cond, branch, ctx);
16300
16300
  if (isError(cond)) return cond;
@@ -22834,8 +22834,8 @@ function protectionXml2(sheet) {
22834
22834
  values2["sheet"] = protection.sheet || void 0;
22835
22835
  const allow = new Set(protection.allow ?? []);
22836
22836
  if (protection.sheet) {
22837
- values2["objects"] = allow.has("objects") ? false : true;
22838
- values2["scenarios"] = allow.has("scenarios") ? false : true;
22837
+ values2["objects"] = !allow.has("objects");
22838
+ values2["scenarios"] = !allow.has("scenarios");
22839
22839
  }
22840
22840
  for (const name of allow) values2[name] = false;
22841
22841
  return el("sheetProtection", values2);
@@ -165,6 +165,7 @@ function deleteCell(sheet, row2, col) {
165
165
  cells.delete(col);
166
166
  if (cells.size === 0) sheet.rows.delete(row2);
167
167
  }
168
+ var isEmptyCell = (cell) => !cell || cell.value === null && !cell.formula && !cell.styleId && !cell.richText;
168
169
  function forEachCell(sheet, visit2) {
169
170
  for (const row2 of [...sheet.rows.keys()].sort((a, b) => a - b)) {
170
171
  const cells = sheet.rows.get(row2);
@@ -3495,7 +3496,7 @@ function stack(ctx, args, vertical2) {
3495
3496
  function flatten(ctx, args) {
3496
3497
  const m = ctx.toMatrix(args[0] ?? null);
3497
3498
  const ignore = intAt(ctx, args, 1) ?? 0;
3498
- const byCol = intAt(ctx, args, 2) ? true : false;
3499
+ const byCol = Boolean(intAt(ctx, args, 2));
3499
3500
  const values2 = [];
3500
3501
  const rows2 = byCol ? m.cols : m.rows;
3501
3502
  const cols = byCol ? m.rows : m.cols;
@@ -6729,7 +6730,7 @@ function ifFn(args, ctx) {
6729
6730
  const branch = (truthy) => {
6730
6731
  const arg = args[truthy ? 1 : 2];
6731
6732
  if (arg) return arg.get();
6732
- return truthy ? true : false;
6733
+ return truthy;
6733
6734
  };
6734
6735
  if (cond instanceof Matrix) return elementwise(cond, branch, ctx);
6735
6736
  if (isError(cond)) return cond;
@@ -14393,6 +14394,29 @@ function pruneCell(sheet, row2, col) {
14393
14394
 
14394
14395
  // xlsx/edit/shift-preserved.ts
14395
14396
  var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
14397
+ function hasPreservedOverflow(sheet, shift2, clipped, banded) {
14398
+ const keys = banded ? ["extLst"] : [shift2.axis === "row" ? "rowBreaks" : "colBreaks", "extLst"];
14399
+ for (const key of keys)
14400
+ for (const xml of sheet.preserved.get(key) ?? []) {
14401
+ if (!xml.includes(key === "extLst" ? "sqref" : "brk")) continue;
14402
+ let root;
14403
+ try {
14404
+ root = parseXml(xml).documentElement;
14405
+ } catch {
14406
+ continue;
14407
+ }
14408
+ if (key === "extLst") {
14409
+ if (descendants2(root, XM3, "sqref").some(
14410
+ (node) => parseSqref(node.textContent ?? "").some(clipped)
14411
+ ))
14412
+ return true;
14413
+ } else if (elements(root).some(
14414
+ (node) => node.localName === "brk" && shiftIndex(Number(node.getAttribute("id") ?? "0"), shift2) === void 0
14415
+ ))
14416
+ return true;
14417
+ }
14418
+ return false;
14419
+ }
14396
14420
  function descendants2(root, ns, local) {
14397
14421
  return Array.from(root.getElementsByTagNameNS(ns, local));
14398
14422
  }
@@ -15627,6 +15651,39 @@ function setBorders(ctx, s, range2, preset, edge = { style: "thin" }) {
15627
15651
  );
15628
15652
  }
15629
15653
 
15654
+ // xlsx/edit/insert-guard.ts
15655
+ function assertInsertFits(sheet, shift2, band) {
15656
+ if (shift2.count <= 0) return;
15657
+ const max = shift2.axis === "row" ? MAX_ROW : MAX_COL;
15658
+ if (shift2.at + shift2.count > max + 1)
15659
+ throw new RangeError("The insert area extends beyond the sheet.");
15660
+ const first2 = max - shift2.count + 1;
15661
+ const lost = shift2.axis === "row" ? cellRange(first2, band?.lo ?? 0, MAX_ROW, band?.hi ?? MAX_COL) : cellRange(band?.lo ?? 0, first2, band?.hi ?? MAX_ROW, MAX_COL);
15662
+ const other = shift2.axis === "row" ? "col" : "row";
15663
+ const clipped = (range2) => (!band || range2.start[other] >= band.lo && range2.end[other] <= band.hi) && rangesIntersect(range2, lost);
15664
+ const fail2 = () => {
15665
+ throw new Error("Cannot insert cells: non-empty cells would be pushed off the sheet.");
15666
+ };
15667
+ for (const [row2, cells] of sheet.rows) {
15668
+ if (row2 < lost.start.row || row2 > lost.end.row) continue;
15669
+ for (const [col, cell] of cells)
15670
+ if (col >= lost.start.col && col <= lost.end.col && (!isEmptyCell(cell) || cell.cellMetadata !== void 0 || cell.valueMetadata !== void 0))
15671
+ fail2();
15672
+ }
15673
+ if (sheet.comments.some((c) => rangesIntersect(cellRange(c.address.row, c.address.col), lost)) || sheet.hyperlinks.some((h2) => rangesIntersect(h2.range, lost)) || sheet.merges.some((m) => rangesIntersect(m, lost)) || sheet.tables.some((t) => rangesIntersect(t.range, lost)) || sheet.dataValidations.some((rule) => rule.ranges.some(clipped)) || sheet.conditionalFormats.some((format) => format.ranges.some(clipped)) || sheet.autoFilter !== void 0 && clipped(sheet.autoFilter.range) || sheet.pageSetup?.printArea !== void 0 && clipped(sheet.pageSetup.printArea) || hasPreservedOverflow(sheet, shift2, clipped, !!band))
15674
+ fail2();
15675
+ for (const { anchor } of sheet.drawings) {
15676
+ if (band && (anchor.from[other] < band.lo || anchor.from[other] > band.hi)) continue;
15677
+ if (anchor.from[shift2.axis] >= first2 || anchor.to && anchor.to[shift2.axis] >= first2) fail2();
15678
+ }
15679
+ if (band) return;
15680
+ if (shift2.axis === "row") {
15681
+ for (const [row2, info] of sheet.rowInfo) if (row2 >= first2 && Object.keys(info).length) fail2();
15682
+ } else {
15683
+ if (normalizeColumns(sheet.columns).some((c) => c.min >= first2)) fail2();
15684
+ }
15685
+ }
15686
+
15630
15687
  // xlsx/edit/shift-rule-anchors.ts
15631
15688
  function rebaseRulesForDeletion(sheet, shift2, band) {
15632
15689
  if (shift2.count >= 0) return;
@@ -15648,6 +15705,7 @@ function rebaseRulesForDeletion(sheet, shift2, band) {
15648
15705
 
15649
15706
  // xlsx/edit/shift-sheet.ts
15650
15707
  function shiftSheetContent(sheet, shift2, band) {
15708
+ assertInsertFits(sheet, shift2, band);
15651
15709
  const moveRange = (range2) => band ? shiftRangeInBand(range2, shift2, band.lo, band.hi) : shiftRange(range2, shift2);
15652
15710
  shiftCells(sheet, shift2, band, moveRange);
15653
15711
  sheet.merges = sheet.merges.map(moveRange).filter((m) => !!m && (m.start.row !== m.end.row || m.start.col !== m.end.col));
@@ -15785,10 +15843,11 @@ function shiftFreeze(sheet, shift2) {
15785
15843
  // xlsx/edit/structure.ts
15786
15844
  function checkSpan(axis, at, count2) {
15787
15845
  const max = axis === "row" ? MAX_ROW : MAX_COL;
15788
- if (!Number.isInteger(at) || !Number.isInteger(count2) || at < 0 || at > max || count2 < 1)
15846
+ if (!Number.isInteger(at) || !Number.isInteger(count2) || at < 0 || at > max || count2 < 1 || at + count2 > max + 1)
15789
15847
  throw new RangeError(`Invalid ${axis} span ${at} + ${count2}`);
15790
15848
  }
15791
15849
  function applyAxisShift(ctx, sheet, shift2) {
15850
+ assertInsertFits(sheet, shift2);
15792
15851
  rebaseRulesForDeletion(sheet, shift2);
15793
15852
  const spec2 = { sheet: sheet.name, axis: shift2.axis, at: shift2.at, count: shift2.count };
15794
15853
  rewriteFormulas(
@@ -15822,6 +15881,7 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
15822
15881
  const sheet = sheetAt(ctx.workbook, s);
15823
15882
  const noun = axis === "row" ? count2 === 1 ? "row" : "rows" : count2 === 1 ? "column" : "columns";
15824
15883
  const shift2 = { axis, at, count: insert ? count2 : -count2 };
15884
+ assertInsertFits(sheet, shift2);
15825
15885
  const info = { sheet: s, structural: true };
15826
15886
  if (!sheet.autoFilter || shiftRange(sheet.autoFilter.range, shift2))
15827
15887
  info.calc = { kind: "shift", sheet: s, shift: shift2 };
@@ -15864,6 +15924,7 @@ function shiftBand(ctx, s, range2, direction) {
15864
15924
  };
15865
15925
  const band = vertical2 ? { lo: r.start.col, hi: r.end.col } : { lo: r.start.row, hi: r.end.row };
15866
15926
  assertBandIntact(sheet, shift2, band);
15927
+ assertInsertFits(sheet, shift2, band);
15867
15928
  ctx.run(
15868
15929
  `${insert ? "Insert" : "Delete"} cells`,
15869
15930
  "structure",
@@ -18135,6 +18196,7 @@ var byId = (sheet, id) => {
18135
18196
  function insertBandRow(workbook, sheet, table2, row2) {
18136
18197
  const shift2 = { axis: "row", at: row2, count: 1 };
18137
18198
  const band = { lo: table2.range.start.col, hi: table2.range.end.col };
18199
+ assertInsertFits(sheet, shift2, band);
18138
18200
  rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
18139
18201
  shiftSheetContent(sheet, shift2, band);
18140
18202
  }
@@ -18173,6 +18235,7 @@ function setTotalsRow(workbook, sheet, id, on) {
18173
18235
  table2.totalsRow = false;
18174
18236
  return;
18175
18237
  }
18238
+ if (end.row === MAX_ROW) throw new RangeError("The insert area extends beyond the sheet.");
18176
18239
  if (!rowIsEmpty(sheet, end.row + 1, start.col, end.col)) {
18177
18240
  insertBandRow(workbook, sheet, table2, end.row + 1);
18178
18241
  table2 = byId(sheet, id);
@@ -27061,6 +27124,7 @@ var grid = {
27061
27124
  "A sheet name cannot be blank.": "Ein Blattname darf nicht leer sein.",
27062
27125
  "A sheet name cannot contain \\ / ? * [ ] or :": "Ein Blattname darf \\ / ? * [ ] oder : nicht enthalten",
27063
27126
  "A sheet name cannot start or end with an apostrophe.": "Ein Blattname darf nicht mit einem Apostroph beginnen oder enden.",
27127
+ "Cannot insert cells: non-empty cells would be pushed off the sheet.": "Zellen k\xF6nnen nicht eingef\xFCgt werden: Nicht leere Zellen w\xFCrden \xFCber den Blattrand hinaus verschoben.",
27064
27128
  Cancel: "Abbrechen",
27065
27129
  "Cell editor": "Zelleneditor",
27066
27130
  Chart: "Diagramm",
@@ -27126,6 +27190,7 @@ var grid = {
27126
27190
  "Tab Color": "Registerfarbe",
27127
27191
  "That name is already taken.": "Dieser Name ist bereits vergeben.",
27128
27192
  "The browser didn't allow access to the clipboard. Use Ctrl+V to paste.": "Der Browser hat den Zugriff auf die Zwischenablage nicht erlaubt. Verwenden Sie Strg+V zum Einf\xFCgen.",
27193
+ "The insert area extends beyond the sheet.": "Der einzuf\xFCgende Bereich reicht \xFCber das Blatt hinaus.",
27129
27194
  "The paste area extends beyond the sheet.": "Der Einf\xFCgebereich reicht \xFCber das Blatt hinaus.",
27130
27195
  "This action won't work on multiple selections.": "Diese Aktion funktioniert nicht bei Mehrfachauswahlen.",
27131
27196
  "This chart could not be displayed.": "Dieses Diagramm konnte nicht angezeigt werden.",
@@ -27447,6 +27512,7 @@ var grid2 = {
27447
27512
  "A sheet name cannot be blank.": "A sheet name cannot be blank.",
27448
27513
  "A sheet name cannot contain \\ / ? * [ ] or :": "A sheet name cannot contain \\ / ? * [ ] or :",
27449
27514
  "A sheet name cannot start or end with an apostrophe.": "A sheet name cannot start or end with an apostrophe.",
27515
+ "Cannot insert cells: non-empty cells would be pushed off the sheet.": "Cannot insert cells: non-empty cells would be pushed off the sheet.",
27450
27516
  Cancel: "Cancel",
27451
27517
  "Cell editor": "Cell editor",
27452
27518
  Chart: "Chart",
@@ -27512,6 +27578,7 @@ var grid2 = {
27512
27578
  "Tab Color": "Tab Color",
27513
27579
  "That name is already taken.": "That name is already taken.",
27514
27580
  "The browser didn't allow access to the clipboard. Use Ctrl+V to paste.": "The browser didn't allow access to the clipboard. Use Ctrl+V to paste.",
27581
+ "The insert area extends beyond the sheet.": "The insert area extends beyond the sheet.",
27515
27582
  "The paste area extends beyond the sheet.": "The paste area extends beyond the sheet.",
27516
27583
  "This action won't work on multiple selections.": "This action won't work on multiple selections.",
27517
27584
  "This chart could not be displayed.": "This chart could not be displayed.",
@@ -27833,6 +27900,7 @@ var grid3 = {
27833
27900
  "A sheet name cannot be blank.": "El nombre de una hoja no puede estar en blanco.",
27834
27901
  "A sheet name cannot contain \\ / ? * [ ] or :": "El nombre de una hoja no puede contener \\ / ? * [ ] ni :",
27835
27902
  "A sheet name cannot start or end with an apostrophe.": "El nombre de una hoja no puede empezar ni terminar con un ap\xF3strofo.",
27903
+ "Cannot insert cells: non-empty cells would be pushed off the sheet.": "No se pueden insertar celdas: las celdas no vac\xEDas se desplazar\xEDan fuera de la hoja.",
27836
27904
  Cancel: "Cancelar",
27837
27905
  "Cell editor": "Editor de celdas",
27838
27906
  Chart: "Gr\xE1fico",
@@ -27898,6 +27966,7 @@ var grid3 = {
27898
27966
  "Tab Color": "Color de pesta\xF1a",
27899
27967
  "That name is already taken.": "Ese nombre ya est\xE1 en uso.",
27900
27968
  "The browser didn't allow access to the clipboard. Use Ctrl+V to paste.": "El explorador no permiti\xF3 el acceso al portapapeles. Use Ctrl+V para pegar.",
27969
+ "The insert area extends beyond the sheet.": "El \xE1rea de inserci\xF3n se extiende m\xE1s all\xE1 de la hoja.",
27901
27970
  "The paste area extends beyond the sheet.": "El \xE1rea de pegado se extiende m\xE1s all\xE1 de la hoja.",
27902
27971
  "This action won't work on multiple selections.": "Esta acci\xF3n no funciona en selecciones m\xFAltiples.",
27903
27972
  "This chart could not be displayed.": "No se pudo mostrar este gr\xE1fico.",
@@ -28219,6 +28288,7 @@ var grid4 = {
28219
28288
  "A sheet name cannot be blank.": "Un nom de feuille ne peut pas \xEAtre vide.",
28220
28289
  "A sheet name cannot contain \\ / ? * [ ] or :": "Un nom de feuille ne peut pas contenir \\ / ? * [ ] ou :",
28221
28290
  "A sheet name cannot start or end with an apostrophe.": "Un nom de feuille ne peut pas commencer ou se terminer par une apostrophe.",
28291
+ "Cannot insert cells: non-empty cells would be pushed off the sheet.": "Impossible d\u2019ins\xE9rer des cellules : des cellules non vides seraient d\xE9plac\xE9es hors de la feuille.",
28222
28292
  Cancel: "Annuler",
28223
28293
  "Cell editor": "\xC9diteur de cellule",
28224
28294
  Chart: "Graphique",
@@ -28284,6 +28354,7 @@ var grid4 = {
28284
28354
  "Tab Color": "Couleur d\u2019onglet",
28285
28355
  "That name is already taken.": "Ce nom est d\xE9j\xE0 utilis\xE9.",
28286
28356
  "The browser didn't allow access to the clipboard. Use Ctrl+V to paste.": "Le navigateur n'a pas autoris\xE9 l'acc\xE8s au Presse-papiers. Utilisez Ctrl+V pour coller.",
28357
+ "The insert area extends beyond the sheet.": "La zone d\u2019insertion d\xE9passe les limites de la feuille.",
28287
28358
  "The paste area extends beyond the sheet.": "La zone de collage d\xE9passe les limites de la feuille.",
28288
28359
  "This action won't work on multiple selections.": "Cette action ne fonctionne pas sur des s\xE9lections multiples.",
28289
28360
  "This chart could not be displayed.": "Ce graphique n'a pas pu \xEAtre affich\xE9.",
@@ -28605,6 +28676,7 @@ var grid5 = {
28605
28676
  "A sheet name cannot be blank.": "\u5DE5\u4F5C\u8868\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A\u3002",
28606
28677
  "A sheet name cannot contain \\ / ? * [ ] or :": "\u5DE5\u4F5C\u8868\u540D\u79F0\u4E0D\u80FD\u5305\u542B \\ / ? * [ ] \u6216 :",
28607
28678
  "A sheet name cannot start or end with an apostrophe.": "\u5DE5\u4F5C\u8868\u540D\u79F0\u4E0D\u80FD\u4EE5\u6487\u53F7\u5F00\u5934\u6216\u7ED3\u5C3E\u3002",
28679
+ "Cannot insert cells: non-empty cells would be pushed off the sheet.": "\u65E0\u6CD5\u63D2\u5165\u5355\u5143\u683C\uFF1A\u975E\u7A7A\u5355\u5143\u683C\u4F1A\u88AB\u79FB\u51FA\u5DE5\u4F5C\u8868\u3002",
28608
28680
  Cancel: "\u53D6\u6D88",
28609
28681
  "Cell editor": "\u5355\u5143\u683C\u7F16\u8F91\u5668",
28610
28682
  Chart: "\u56FE\u8868",
@@ -28670,6 +28742,7 @@ var grid5 = {
28670
28742
  "Tab Color": "\u5DE5\u4F5C\u8868\u6807\u7B7E\u989C\u8272",
28671
28743
  "That name is already taken.": "\u8BE5\u540D\u79F0\u5DF2\u88AB\u4F7F\u7528\u3002",
28672
28744
  "The browser didn't allow access to the clipboard. Use Ctrl+V to paste.": "\u6D4F\u89C8\u5668\u4E0D\u5141\u8BB8\u8BBF\u95EE\u526A\u8D34\u677F\u3002\u8BF7\u4F7F\u7528 Ctrl+V \u7C98\u8D34\u3002",
28745
+ "The insert area extends beyond the sheet.": "\u63D2\u5165\u533A\u57DF\u8D85\u51FA\u4E86\u5DE5\u4F5C\u8868\u8303\u56F4\u3002",
28673
28746
  "The paste area extends beyond the sheet.": "\u7C98\u8D34\u533A\u57DF\u8D85\u51FA\u4E86\u5DE5\u4F5C\u8868\u8303\u56F4\u3002",
28674
28747
  "This action won't work on multiple selections.": "\u6B64\u64CD\u4F5C\u4E0D\u9002\u7528\u4E8E\u591A\u91CD\u9009\u62E9\u3002",
28675
28748
  "This chart could not be displayed.": "\u65E0\u6CD5\u663E\u793A\u6B64\u56FE\u8868\u3002",