ooxml-core 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11700,6 +11700,7 @@ function deleteCell(sheet, row3, col) {
11700
11700
  cells3.delete(col);
11701
11701
  if (cells3.size === 0) sheet.rows.delete(row3);
11702
11702
  }
11703
+ var isEmptyCell = (cell) => !cell || cell.value === null && !cell.formula && !cell.styleId && !cell.richText;
11703
11704
  function forEachCell(sheet, visit2) {
11704
11705
  for (const row3 of [...sheet.rows.keys()].sort((a2, b) => a2 - b)) {
11705
11706
  const cells3 = sheet.rows.get(row3);
@@ -30540,6 +30541,29 @@ function pruneCell(sheet, row3, col) {
30540
30541
 
30541
30542
  // xlsx/edit/shift-preserved.ts
30542
30543
  var XM2 = "http://schemas.microsoft.com/office/excel/2006/main";
30544
+ function hasPreservedOverflow(sheet, shift2, clipped, banded) {
30545
+ const keys = banded ? ["extLst"] : [shift2.axis === "row" ? "rowBreaks" : "colBreaks", "extLst"];
30546
+ for (const key2 of keys)
30547
+ for (const xml of sheet.preserved.get(key2) ?? []) {
30548
+ if (!xml.includes(key2 === "extLst" ? "sqref" : "brk")) continue;
30549
+ let root;
30550
+ try {
30551
+ root = parseXml(xml).documentElement;
30552
+ } catch {
30553
+ continue;
30554
+ }
30555
+ if (key2 === "extLst") {
30556
+ if (descendants4(root, XM2, "sqref").some(
30557
+ (node2) => parseSqref(node2.textContent ?? "").some(clipped)
30558
+ ))
30559
+ return true;
30560
+ } else if (elements(root).some(
30561
+ (node2) => node2.localName === "brk" && shiftIndex(Number(node2.getAttribute("id") ?? "0"), shift2) === void 0
30562
+ ))
30563
+ return true;
30564
+ }
30565
+ return false;
30566
+ }
30543
30567
  function descendants4(root, ns, local) {
30544
30568
  return Array.from(root.getElementsByTagNameNS(ns, local));
30545
30569
  }
@@ -31774,6 +31798,39 @@ function setBorders(ctx, s, range2, preset, edge = { style: "thin" }) {
31774
31798
  );
31775
31799
  }
31776
31800
 
31801
+ // xlsx/edit/insert-guard.ts
31802
+ function assertInsertFits(sheet, shift2, band2) {
31803
+ if (shift2.count <= 0) return;
31804
+ const max = shift2.axis === "row" ? MAX_ROW : MAX_COL;
31805
+ if (shift2.at + shift2.count > max + 1)
31806
+ throw new RangeError("The insert area extends beyond the sheet.");
31807
+ const first3 = max - shift2.count + 1;
31808
+ const lost = shift2.axis === "row" ? cellRange(first3, band2?.lo ?? 0, MAX_ROW, band2?.hi ?? MAX_COL) : cellRange(band2?.lo ?? 0, first3, band2?.hi ?? MAX_ROW, MAX_COL);
31809
+ const other = shift2.axis === "row" ? "col" : "row";
31810
+ const clipped = (range2) => (!band2 || range2.start[other] >= band2.lo && range2.end[other] <= band2.hi) && rangesIntersect(range2, lost);
31811
+ const fail3 = () => {
31812
+ throw new Error("Cannot insert cells: non-empty cells would be pushed off the sheet.");
31813
+ };
31814
+ for (const [row3, cells3] of sheet.rows) {
31815
+ if (row3 < lost.start.row || row3 > lost.end.row) continue;
31816
+ for (const [col, cell] of cells3)
31817
+ if (col >= lost.start.col && col <= lost.end.col && (!isEmptyCell(cell) || cell.cellMetadata !== void 0 || cell.valueMetadata !== void 0))
31818
+ fail3();
31819
+ }
31820
+ 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((rule2) => rule2.ranges.some(clipped)) || sheet.conditionalFormats.some((format4) => format4.ranges.some(clipped)) || sheet.autoFilter !== void 0 && clipped(sheet.autoFilter.range) || sheet.pageSetup?.printArea !== void 0 && clipped(sheet.pageSetup.printArea) || hasPreservedOverflow(sheet, shift2, clipped, !!band2))
31821
+ fail3();
31822
+ for (const { anchor } of sheet.drawings) {
31823
+ if (band2 && (anchor.from[other] < band2.lo || anchor.from[other] > band2.hi)) continue;
31824
+ if (anchor.from[shift2.axis] >= first3 || anchor.to && anchor.to[shift2.axis] >= first3) fail3();
31825
+ }
31826
+ if (band2) return;
31827
+ if (shift2.axis === "row") {
31828
+ for (const [row3, info] of sheet.rowInfo) if (row3 >= first3 && Object.keys(info).length) fail3();
31829
+ } else {
31830
+ if (normalizeColumns(sheet.columns).some((c2) => c2.min >= first3)) fail3();
31831
+ }
31832
+ }
31833
+
31777
31834
  // xlsx/edit/shift-rule-anchors.ts
31778
31835
  function rebaseRulesForDeletion(sheet, shift2, band2) {
31779
31836
  if (shift2.count >= 0) return;
@@ -31795,6 +31852,7 @@ function rebaseRulesForDeletion(sheet, shift2, band2) {
31795
31852
 
31796
31853
  // xlsx/edit/shift-sheet.ts
31797
31854
  function shiftSheetContent(sheet, shift2, band2) {
31855
+ assertInsertFits(sheet, shift2, band2);
31798
31856
  const moveRange = (range2) => band2 ? shiftRangeInBand(range2, shift2, band2.lo, band2.hi) : shiftRange(range2, shift2);
31799
31857
  shiftCells(sheet, shift2, band2, moveRange);
31800
31858
  sheet.merges = sheet.merges.map(moveRange).filter((m) => !!m && (m.start.row !== m.end.row || m.start.col !== m.end.col));
@@ -31932,10 +31990,11 @@ function shiftFreeze(sheet, shift2) {
31932
31990
  // xlsx/edit/structure.ts
31933
31991
  function checkSpan(axis, at2, count2) {
31934
31992
  const max = axis === "row" ? MAX_ROW : MAX_COL;
31935
- if (!Number.isInteger(at2) || !Number.isInteger(count2) || at2 < 0 || at2 > max || count2 < 1)
31993
+ if (!Number.isInteger(at2) || !Number.isInteger(count2) || at2 < 0 || at2 > max || count2 < 1 || at2 + count2 > max + 1)
31936
31994
  throw new RangeError(`Invalid ${axis} span ${at2} + ${count2}`);
31937
31995
  }
31938
31996
  function applyAxisShift(ctx, sheet, shift2) {
31997
+ assertInsertFits(sheet, shift2);
31939
31998
  rebaseRulesForDeletion(sheet, shift2);
31940
31999
  const spec2 = { sheet: sheet.name, axis: shift2.axis, at: shift2.at, count: shift2.count };
31941
32000
  rewriteFormulas(
@@ -31969,6 +32028,7 @@ function shiftAxis(ctx, s, axis, at2, count2, insert) {
31969
32028
  const sheet = sheetAt(ctx.workbook, s);
31970
32029
  const noun = axis === "row" ? count2 === 1 ? "row" : "rows" : count2 === 1 ? "column" : "columns";
31971
32030
  const shift2 = { axis, at: at2, count: insert ? count2 : -count2 };
32031
+ assertInsertFits(sheet, shift2);
31972
32032
  const info = { sheet: s, structural: true };
31973
32033
  if (!sheet.autoFilter || shiftRange(sheet.autoFilter.range, shift2))
31974
32034
  info.calc = { kind: "shift", sheet: s, shift: shift2 };
@@ -32011,6 +32071,7 @@ function shiftBand(ctx, s, range2, direction) {
32011
32071
  };
32012
32072
  const band2 = vertical ? { lo: r.start.col, hi: r.end.col } : { lo: r.start.row, hi: r.end.row };
32013
32073
  assertBandIntact(sheet, shift2, band2);
32074
+ assertInsertFits(sheet, shift2, band2);
32014
32075
  ctx.run(
32015
32076
  `${insert ? "Insert" : "Delete"} cells`,
32016
32077
  "structure",
@@ -34504,6 +34565,7 @@ var byId = (sheet, id3) => {
34504
34565
  function insertBandRow(workbook, sheet, table3, row3) {
34505
34566
  const shift2 = { axis: "row", at: row3, count: 1 };
34506
34567
  const band2 = { lo: table3.range.start.col, hi: table3.range.end.col };
34568
+ assertInsertFits(sheet, shift2, band2);
34507
34569
  rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band2));
34508
34570
  shiftSheetContent(sheet, shift2, band2);
34509
34571
  }
@@ -34542,6 +34604,7 @@ function setTotalsRow(workbook, sheet, id3, on) {
34542
34604
  table3.totalsRow = false;
34543
34605
  return;
34544
34606
  }
34607
+ if (end.row === MAX_ROW) throw new RangeError("The insert area extends beyond the sheet.");
34545
34608
  if (!rowIsEmpty(sheet, end.row + 1, start.col, end.col)) {
34546
34609
  insertBandRow(workbook, sheet, table3, end.row + 1);
34547
34610
  table3 = byId(sheet, id3);
@@ -11694,6 +11694,7 @@ function deleteCell(sheet, row3, col) {
11694
11694
  cells3.delete(col);
11695
11695
  if (cells3.size === 0) sheet.rows.delete(row3);
11696
11696
  }
11697
+ var isEmptyCell = (cell) => !cell || cell.value === null && !cell.formula && !cell.styleId && !cell.richText;
11697
11698
  function forEachCell(sheet, visit2) {
11698
11699
  for (const row3 of [...sheet.rows.keys()].sort((a2, b) => a2 - b)) {
11699
11700
  const cells3 = sheet.rows.get(row3);
@@ -30534,6 +30535,29 @@ function pruneCell(sheet, row3, col) {
30534
30535
 
30535
30536
  // xlsx/edit/shift-preserved.ts
30536
30537
  var XM2 = "http://schemas.microsoft.com/office/excel/2006/main";
30538
+ function hasPreservedOverflow(sheet, shift2, clipped, banded) {
30539
+ const keys = banded ? ["extLst"] : [shift2.axis === "row" ? "rowBreaks" : "colBreaks", "extLst"];
30540
+ for (const key2 of keys)
30541
+ for (const xml of sheet.preserved.get(key2) ?? []) {
30542
+ if (!xml.includes(key2 === "extLst" ? "sqref" : "brk")) continue;
30543
+ let root;
30544
+ try {
30545
+ root = parseXml(xml).documentElement;
30546
+ } catch {
30547
+ continue;
30548
+ }
30549
+ if (key2 === "extLst") {
30550
+ if (descendants4(root, XM2, "sqref").some(
30551
+ (node2) => parseSqref(node2.textContent ?? "").some(clipped)
30552
+ ))
30553
+ return true;
30554
+ } else if (elements(root).some(
30555
+ (node2) => node2.localName === "brk" && shiftIndex(Number(node2.getAttribute("id") ?? "0"), shift2) === void 0
30556
+ ))
30557
+ return true;
30558
+ }
30559
+ return false;
30560
+ }
30537
30561
  function descendants4(root, ns, local) {
30538
30562
  return Array.from(root.getElementsByTagNameNS(ns, local));
30539
30563
  }
@@ -31768,6 +31792,39 @@ function setBorders(ctx, s, range2, preset, edge = { style: "thin" }) {
31768
31792
  );
31769
31793
  }
31770
31794
 
31795
+ // xlsx/edit/insert-guard.ts
31796
+ function assertInsertFits(sheet, shift2, band2) {
31797
+ if (shift2.count <= 0) return;
31798
+ const max = shift2.axis === "row" ? MAX_ROW : MAX_COL;
31799
+ if (shift2.at + shift2.count > max + 1)
31800
+ throw new RangeError("The insert area extends beyond the sheet.");
31801
+ const first3 = max - shift2.count + 1;
31802
+ const lost = shift2.axis === "row" ? cellRange(first3, band2?.lo ?? 0, MAX_ROW, band2?.hi ?? MAX_COL) : cellRange(band2?.lo ?? 0, first3, band2?.hi ?? MAX_ROW, MAX_COL);
31803
+ const other = shift2.axis === "row" ? "col" : "row";
31804
+ const clipped = (range2) => (!band2 || range2.start[other] >= band2.lo && range2.end[other] <= band2.hi) && rangesIntersect(range2, lost);
31805
+ const fail3 = () => {
31806
+ throw new Error("Cannot insert cells: non-empty cells would be pushed off the sheet.");
31807
+ };
31808
+ for (const [row3, cells3] of sheet.rows) {
31809
+ if (row3 < lost.start.row || row3 > lost.end.row) continue;
31810
+ for (const [col, cell] of cells3)
31811
+ if (col >= lost.start.col && col <= lost.end.col && (!isEmptyCell(cell) || cell.cellMetadata !== void 0 || cell.valueMetadata !== void 0))
31812
+ fail3();
31813
+ }
31814
+ 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((rule2) => rule2.ranges.some(clipped)) || sheet.conditionalFormats.some((format4) => format4.ranges.some(clipped)) || sheet.autoFilter !== void 0 && clipped(sheet.autoFilter.range) || sheet.pageSetup?.printArea !== void 0 && clipped(sheet.pageSetup.printArea) || hasPreservedOverflow(sheet, shift2, clipped, !!band2))
31815
+ fail3();
31816
+ for (const { anchor } of sheet.drawings) {
31817
+ if (band2 && (anchor.from[other] < band2.lo || anchor.from[other] > band2.hi)) continue;
31818
+ if (anchor.from[shift2.axis] >= first3 || anchor.to && anchor.to[shift2.axis] >= first3) fail3();
31819
+ }
31820
+ if (band2) return;
31821
+ if (shift2.axis === "row") {
31822
+ for (const [row3, info] of sheet.rowInfo) if (row3 >= first3 && Object.keys(info).length) fail3();
31823
+ } else {
31824
+ if (normalizeColumns(sheet.columns).some((c2) => c2.min >= first3)) fail3();
31825
+ }
31826
+ }
31827
+
31771
31828
  // xlsx/edit/shift-rule-anchors.ts
31772
31829
  function rebaseRulesForDeletion(sheet, shift2, band2) {
31773
31830
  if (shift2.count >= 0) return;
@@ -31789,6 +31846,7 @@ function rebaseRulesForDeletion(sheet, shift2, band2) {
31789
31846
 
31790
31847
  // xlsx/edit/shift-sheet.ts
31791
31848
  function shiftSheetContent(sheet, shift2, band2) {
31849
+ assertInsertFits(sheet, shift2, band2);
31792
31850
  const moveRange = (range2) => band2 ? shiftRangeInBand(range2, shift2, band2.lo, band2.hi) : shiftRange(range2, shift2);
31793
31851
  shiftCells(sheet, shift2, band2, moveRange);
31794
31852
  sheet.merges = sheet.merges.map(moveRange).filter((m) => !!m && (m.start.row !== m.end.row || m.start.col !== m.end.col));
@@ -31926,10 +31984,11 @@ function shiftFreeze(sheet, shift2) {
31926
31984
  // xlsx/edit/structure.ts
31927
31985
  function checkSpan(axis, at2, count2) {
31928
31986
  const max = axis === "row" ? MAX_ROW : MAX_COL;
31929
- if (!Number.isInteger(at2) || !Number.isInteger(count2) || at2 < 0 || at2 > max || count2 < 1)
31987
+ if (!Number.isInteger(at2) || !Number.isInteger(count2) || at2 < 0 || at2 > max || count2 < 1 || at2 + count2 > max + 1)
31930
31988
  throw new RangeError(`Invalid ${axis} span ${at2} + ${count2}`);
31931
31989
  }
31932
31990
  function applyAxisShift(ctx, sheet, shift2) {
31991
+ assertInsertFits(sheet, shift2);
31933
31992
  rebaseRulesForDeletion(sheet, shift2);
31934
31993
  const spec2 = { sheet: sheet.name, axis: shift2.axis, at: shift2.at, count: shift2.count };
31935
31994
  rewriteFormulas(
@@ -31963,6 +32022,7 @@ function shiftAxis(ctx, s, axis, at2, count2, insert) {
31963
32022
  const sheet = sheetAt(ctx.workbook, s);
31964
32023
  const noun = axis === "row" ? count2 === 1 ? "row" : "rows" : count2 === 1 ? "column" : "columns";
31965
32024
  const shift2 = { axis, at: at2, count: insert ? count2 : -count2 };
32025
+ assertInsertFits(sheet, shift2);
31966
32026
  const info = { sheet: s, structural: true };
31967
32027
  if (!sheet.autoFilter || shiftRange(sheet.autoFilter.range, shift2))
31968
32028
  info.calc = { kind: "shift", sheet: s, shift: shift2 };
@@ -32005,6 +32065,7 @@ function shiftBand(ctx, s, range2, direction) {
32005
32065
  };
32006
32066
  const band2 = vertical ? { lo: r.start.col, hi: r.end.col } : { lo: r.start.row, hi: r.end.row };
32007
32067
  assertBandIntact(sheet, shift2, band2);
32068
+ assertInsertFits(sheet, shift2, band2);
32008
32069
  ctx.run(
32009
32070
  `${insert ? "Insert" : "Delete"} cells`,
32010
32071
  "structure",
@@ -34498,6 +34559,7 @@ var byId = (sheet, id3) => {
34498
34559
  function insertBandRow(workbook, sheet, table3, row3) {
34499
34560
  const shift2 = { axis: "row", at: row3, count: 1 };
34500
34561
  const band2 = { lo: table3.range.start.col, hi: table3.range.end.col };
34562
+ assertInsertFits(sheet, shift2, band2);
34501
34563
  rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band2));
34502
34564
  shiftSheetContent(sheet, shift2, band2);
34503
34565
  }
@@ -34536,6 +34598,7 @@ function setTotalsRow(workbook, sheet, id3, on) {
34536
34598
  table3.totalsRow = false;
34537
34599
  return;
34538
34600
  }
34601
+ if (end.row === MAX_ROW) throw new RangeError("The insert area extends beyond the sheet.");
34539
34602
  if (!rowIsEmpty(sheet, end.row + 1, start.col, end.col)) {
34540
34603
  insertBandRow(workbook, sheet, table3, end.row + 1);
34541
34604
  table3 = byId(sheet, id3);
@@ -1 +1 @@
1
- {"version":3,"file":"cell-shift.d.ts","sourceRoot":"","sources":["../../../xlsx/edit/cell-shift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAqD,MAAM,YAAY,CAAC;AAG/F,OAAO,EAAE,KAAK,WAAW,EAAwC,MAAM,WAAW,CAAC;AA2DnF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,WAAW,EAChB,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,GAAG,OAAO,GACzB,IAAI,CAON;AAED,kFAAkF;AAClF,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,WAAW,EAChB,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,IAAI,GAAG,MAAM,GACtB,IAAI,CAON"}
1
+ {"version":3,"file":"cell-shift.d.ts","sourceRoot":"","sources":["../../../xlsx/edit/cell-shift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAqD,MAAM,YAAY,CAAC;AAI/F,OAAO,EAAE,KAAK,WAAW,EAAwC,MAAM,WAAW,CAAC;AA4DnF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,WAAW,EAChB,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,GAAG,OAAO,GACzB,IAAI,CAON;AAED,kFAAkF;AAClF,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,WAAW,EAChB,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,IAAI,GAAG,MAAM,GACtB,IAAI,CAON"}
@@ -0,0 +1,6 @@
1
+ import type { Worksheet } from '../model.js';
2
+ import type { AxisShift } from './range-math.js';
3
+ import type { Band } from './shift-sheet.js';
4
+ /** Refuses an insertion that would discard cells or clip positioned metadata at the grid edge. */
5
+ export declare function assertInsertFits(sheet: Worksheet, shift: AxisShift, band?: Band): void;
6
+ //# sourceMappingURL=insert-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insert-guard.d.ts","sourceRoot":"","sources":["../../../xlsx/edit/insert-guard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAG1C,kGAAkG;AAClG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAqDtF"}
@@ -1,6 +1,8 @@
1
1
  import type { CellRange } from '../address.js';
2
2
  import type { Worksheet } from '../model.js';
3
3
  import { type AxisShift } from './range-math.js';
4
+ /** Reports page breaks and extension ranges that an insertion would push beyond the grid. */
5
+ export declare function hasPreservedOverflow(sheet: Worksheet, shift: AxisShift, clipped: (range: CellRange) => boolean, banded: boolean): boolean;
4
6
  /** Rewrites one formula; `formulaSheet` is the sheet unqualified references point at. */
5
7
  type Rewrite = (formula: string, formulaSheet: string) => string;
6
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"shift-preserved.d.ts","sourceRoot":"","sources":["../../../xlsx/edit/shift-preserved.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG1C,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,cAAc,CAAC;AAI1D,yFAAyF;AACzF,KAAK,OAAO,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;AA2GjE;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,SAAS,GAAG,SAAS,EACtD,MAAM,EAAE,OAAO,GACb,IAAI,CAcN;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAsBjF"}
1
+ {"version":3,"file":"shift-preserved.d.ts","sourceRoot":"","sources":["../../../xlsx/edit/shift-preserved.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG1C,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,cAAc,CAAC;AAI1D,6FAA6F;AAC7F,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,EACtC,MAAM,EAAE,OAAO,GACb,OAAO,CA6BT;AAED,yFAAyF;AACzF,KAAK,OAAO,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;AA2GjE;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,SAAS,GAAG,SAAS,EACtD,MAAM,EAAE,OAAO,GACb,IAAI,CAcN;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAsBjF"}
@@ -1 +1 @@
1
- {"version":3,"file":"shift-sheet.d.ts","sourceRoot":"","sources":["../../../xlsx/edit/shift-sheet.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA2C,SAAS,EAAE,MAAM,UAAU,CAAC;AAGnF,OAAO,EACN,KAAK,SAAS,EAMd,MAAM,cAAc,CAAC;AAEtB,iGAAiG;AACjG,MAAM,WAAW,IAAI;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACX;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAgDvF"}
1
+ {"version":3,"file":"shift-sheet.d.ts","sourceRoot":"","sources":["../../../xlsx/edit/shift-sheet.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA2C,SAAS,EAAE,MAAM,UAAU,CAAC;AAInF,OAAO,EACN,KAAK,SAAS,EAMd,MAAM,cAAc,CAAC;AAEtB,iGAAiG;AACjG,MAAM,WAAW,IAAI;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACX;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAiDvF"}
@@ -1 +1 @@
1
- {"version":3,"file":"structure.d.ts","sourceRoot":"","sources":["../../../xlsx/edit/structure.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,KAAK,WAAW,EAAyB,MAAM,WAAW,CAAC;AAEpE,OAAO,EAAa,KAAK,SAAS,EAAc,MAAM,cAAc,CAAC;AAWrE,yFAAyF;AACzF,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAOzF;AAoDD,eAAO,MAAM,UAAU,QAAS,WAAW,KAAK,MAAM,MAAM,MAAM,SAAS,MAAM,KAAG,IAC1C,CAAC;AAC3C,eAAO,MAAM,UAAU,QAAS,WAAW,KAAK,MAAM,MAAM,MAAM,SAAS,MAAM,KAAG,IACzC,CAAC;AAC5C,eAAO,MAAM,aAAa,QAAS,WAAW,KAAK,MAAM,MAAM,MAAM,SAAS,MAAM,KAAG,IAC7C,CAAC;AAC3C,eAAO,MAAM,aAAa,QAAS,WAAW,KAAK,MAAM,MAAM,MAAM,SAAS,MAAM,KAAG,IAC5C,CAAC"}
1
+ {"version":3,"file":"structure.d.ts","sourceRoot":"","sources":["../../../xlsx/edit/structure.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,KAAK,WAAW,EAAyB,MAAM,WAAW,CAAC;AAGpE,OAAO,EAAa,KAAK,SAAS,EAAc,MAAM,cAAc,CAAC;AAmBrE,yFAAyF;AACzF,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAQzF;AAsDD,eAAO,MAAM,UAAU,QAAS,WAAW,KAAK,MAAM,MAAM,MAAM,SAAS,MAAM,KAAG,IAC1C,CAAC;AAC3C,eAAO,MAAM,UAAU,QAAS,WAAW,KAAK,MAAM,MAAM,MAAM,SAAS,MAAM,KAAG,IACzC,CAAC;AAC5C,eAAO,MAAM,aAAa,QAAS,WAAW,KAAK,MAAM,MAAM,MAAM,SAAS,MAAM,KAAG,IAC7C,CAAC;AAC3C,eAAO,MAAM,aAAa,QAAS,WAAW,KAAK,MAAM,MAAM,MAAM,SAAS,MAAM,KAAG,IAC5C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"table-edits.d.ts","sourceRoot":"","sources":["../../../xlsx/edit/table-edits.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAmC,MAAM,YAAY,CAAC;AAI7E,OAAO,KAAK,EAAE,KAAK,EAAe,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGxE,OAAO,EAAE,KAAK,WAAW,EAAwB,MAAM,WAAW,CAAC;AAOnE,wEAAwE;AACxE,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC,qCAAqC;AACrC,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC;AAEjE,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CAOlE;AAID,uFAAuF;AACvF,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,KAAK,GACV,MAAM,GAAG,SAAS,CAWpB;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAYlF;AAwHD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CA4C/F;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAU9F;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,GAAG,IAAI,CAyCpF"}
1
+ {"version":3,"file":"table-edits.d.ts","sourceRoot":"","sources":["../../../xlsx/edit/table-edits.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAA4C,MAAM,YAAY,CAAC;AAItF,OAAO,KAAK,EAAE,KAAK,EAAe,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAIxE,OAAO,EAAE,KAAK,WAAW,EAAwB,MAAM,WAAW,CAAC;AAOnE,wEAAwE;AACxE,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC,qCAAqC;AACrC,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC;AAEjE,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CAOlE;AAID,uFAAuF;AACvF,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,KAAK,GACV,MAAM,GAAG,SAAS,CAWpB;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAYlF;AA2HD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CA4C/F;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAU9F;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,GAAG,IAAI,CAyCpF"}
@@ -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);
@@ -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);
@@ -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);
@@ -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",
@@ -163,6 +163,7 @@ function deleteCell(sheet, row2, col) {
163
163
  cells.delete(col);
164
164
  if (cells.size === 0) sheet.rows.delete(row2);
165
165
  }
166
+ var isEmptyCell = (cell) => !cell || cell.value === null && !cell.formula && !cell.styleId && !cell.richText;
166
167
  function forEachCell(sheet, visit2) {
167
168
  for (const row2 of [...sheet.rows.keys()].sort((a, b) => a - b)) {
168
169
  const cells = sheet.rows.get(row2);
@@ -14391,6 +14392,29 @@ function pruneCell(sheet, row2, col) {
14391
14392
 
14392
14393
  // xlsx/edit/shift-preserved.ts
14393
14394
  var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
14395
+ function hasPreservedOverflow(sheet, shift2, clipped, banded) {
14396
+ const keys = banded ? ["extLst"] : [shift2.axis === "row" ? "rowBreaks" : "colBreaks", "extLst"];
14397
+ for (const key of keys)
14398
+ for (const xml of sheet.preserved.get(key) ?? []) {
14399
+ if (!xml.includes(key === "extLst" ? "sqref" : "brk")) continue;
14400
+ let root;
14401
+ try {
14402
+ root = parseXml(xml).documentElement;
14403
+ } catch {
14404
+ continue;
14405
+ }
14406
+ if (key === "extLst") {
14407
+ if (descendants2(root, XM3, "sqref").some(
14408
+ (node) => parseSqref(node.textContent ?? "").some(clipped)
14409
+ ))
14410
+ return true;
14411
+ } else if (elements(root).some(
14412
+ (node) => node.localName === "brk" && shiftIndex(Number(node.getAttribute("id") ?? "0"), shift2) === void 0
14413
+ ))
14414
+ return true;
14415
+ }
14416
+ return false;
14417
+ }
14394
14418
  function descendants2(root, ns, local) {
14395
14419
  return Array.from(root.getElementsByTagNameNS(ns, local));
14396
14420
  }
@@ -15625,6 +15649,39 @@ function setBorders(ctx, s, range2, preset, edge = { style: "thin" }) {
15625
15649
  );
15626
15650
  }
15627
15651
 
15652
+ // xlsx/edit/insert-guard.ts
15653
+ function assertInsertFits(sheet, shift2, band) {
15654
+ if (shift2.count <= 0) return;
15655
+ const max = shift2.axis === "row" ? MAX_ROW : MAX_COL;
15656
+ if (shift2.at + shift2.count > max + 1)
15657
+ throw new RangeError("The insert area extends beyond the sheet.");
15658
+ const first2 = max - shift2.count + 1;
15659
+ 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);
15660
+ const other = shift2.axis === "row" ? "col" : "row";
15661
+ const clipped = (range2) => (!band || range2.start[other] >= band.lo && range2.end[other] <= band.hi) && rangesIntersect(range2, lost);
15662
+ const fail2 = () => {
15663
+ throw new Error("Cannot insert cells: non-empty cells would be pushed off the sheet.");
15664
+ };
15665
+ for (const [row2, cells] of sheet.rows) {
15666
+ if (row2 < lost.start.row || row2 > lost.end.row) continue;
15667
+ for (const [col, cell] of cells)
15668
+ if (col >= lost.start.col && col <= lost.end.col && (!isEmptyCell(cell) || cell.cellMetadata !== void 0 || cell.valueMetadata !== void 0))
15669
+ fail2();
15670
+ }
15671
+ 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))
15672
+ fail2();
15673
+ for (const { anchor } of sheet.drawings) {
15674
+ if (band && (anchor.from[other] < band.lo || anchor.from[other] > band.hi)) continue;
15675
+ if (anchor.from[shift2.axis] >= first2 || anchor.to && anchor.to[shift2.axis] >= first2) fail2();
15676
+ }
15677
+ if (band) return;
15678
+ if (shift2.axis === "row") {
15679
+ for (const [row2, info] of sheet.rowInfo) if (row2 >= first2 && Object.keys(info).length) fail2();
15680
+ } else {
15681
+ if (normalizeColumns(sheet.columns).some((c) => c.min >= first2)) fail2();
15682
+ }
15683
+ }
15684
+
15628
15685
  // xlsx/edit/shift-rule-anchors.ts
15629
15686
  function rebaseRulesForDeletion(sheet, shift2, band) {
15630
15687
  if (shift2.count >= 0) return;
@@ -15646,6 +15703,7 @@ function rebaseRulesForDeletion(sheet, shift2, band) {
15646
15703
 
15647
15704
  // xlsx/edit/shift-sheet.ts
15648
15705
  function shiftSheetContent(sheet, shift2, band) {
15706
+ assertInsertFits(sheet, shift2, band);
15649
15707
  const moveRange = (range2) => band ? shiftRangeInBand(range2, shift2, band.lo, band.hi) : shiftRange(range2, shift2);
15650
15708
  shiftCells(sheet, shift2, band, moveRange);
15651
15709
  sheet.merges = sheet.merges.map(moveRange).filter((m) => !!m && (m.start.row !== m.end.row || m.start.col !== m.end.col));
@@ -15783,10 +15841,11 @@ function shiftFreeze(sheet, shift2) {
15783
15841
  // xlsx/edit/structure.ts
15784
15842
  function checkSpan(axis, at, count2) {
15785
15843
  const max = axis === "row" ? MAX_ROW : MAX_COL;
15786
- if (!Number.isInteger(at) || !Number.isInteger(count2) || at < 0 || at > max || count2 < 1)
15844
+ if (!Number.isInteger(at) || !Number.isInteger(count2) || at < 0 || at > max || count2 < 1 || at + count2 > max + 1)
15787
15845
  throw new RangeError(`Invalid ${axis} span ${at} + ${count2}`);
15788
15846
  }
15789
15847
  function applyAxisShift(ctx, sheet, shift2) {
15848
+ assertInsertFits(sheet, shift2);
15790
15849
  rebaseRulesForDeletion(sheet, shift2);
15791
15850
  const spec2 = { sheet: sheet.name, axis: shift2.axis, at: shift2.at, count: shift2.count };
15792
15851
  rewriteFormulas(
@@ -15820,6 +15879,7 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
15820
15879
  const sheet = sheetAt(ctx.workbook, s);
15821
15880
  const noun = axis === "row" ? count2 === 1 ? "row" : "rows" : count2 === 1 ? "column" : "columns";
15822
15881
  const shift2 = { axis, at, count: insert ? count2 : -count2 };
15882
+ assertInsertFits(sheet, shift2);
15823
15883
  const info = { sheet: s, structural: true };
15824
15884
  if (!sheet.autoFilter || shiftRange(sheet.autoFilter.range, shift2))
15825
15885
  info.calc = { kind: "shift", sheet: s, shift: shift2 };
@@ -15862,6 +15922,7 @@ function shiftBand(ctx, s, range2, direction) {
15862
15922
  };
15863
15923
  const band = vertical2 ? { lo: r.start.col, hi: r.end.col } : { lo: r.start.row, hi: r.end.row };
15864
15924
  assertBandIntact(sheet, shift2, band);
15925
+ assertInsertFits(sheet, shift2, band);
15865
15926
  ctx.run(
15866
15927
  `${insert ? "Insert" : "Delete"} cells`,
15867
15928
  "structure",
@@ -18133,6 +18194,7 @@ var byId = (sheet, id) => {
18133
18194
  function insertBandRow(workbook, sheet, table2, row2) {
18134
18195
  const shift2 = { axis: "row", at: row2, count: 1 };
18135
18196
  const band = { lo: table2.range.start.col, hi: table2.range.end.col };
18197
+ assertInsertFits(sheet, shift2, band);
18136
18198
  rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
18137
18199
  shiftSheetContent(sheet, shift2, band);
18138
18200
  }
@@ -18171,6 +18233,7 @@ function setTotalsRow(workbook, sheet, id, on) {
18171
18233
  table2.totalsRow = false;
18172
18234
  return;
18173
18235
  }
18236
+ if (end.row === MAX_ROW) throw new RangeError("The insert area extends beyond the sheet.");
18174
18237
  if (!rowIsEmpty(sheet, end.row + 1, start.col, end.col)) {
18175
18238
  insertBandRow(workbook, sheet, table2, end.row + 1);
18176
18239
  table2 = byId(sheet, id);
@@ -27059,6 +27122,7 @@ var grid = {
27059
27122
  "A sheet name cannot be blank.": "Ein Blattname darf nicht leer sein.",
27060
27123
  "A sheet name cannot contain \\ / ? * [ ] or :": "Ein Blattname darf \\ / ? * [ ] oder : nicht enthalten",
27061
27124
  "A sheet name cannot start or end with an apostrophe.": "Ein Blattname darf nicht mit einem Apostroph beginnen oder enden.",
27125
+ "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.",
27062
27126
  Cancel: "Abbrechen",
27063
27127
  "Cell editor": "Zelleneditor",
27064
27128
  Chart: "Diagramm",
@@ -27124,6 +27188,7 @@ var grid = {
27124
27188
  "Tab Color": "Registerfarbe",
27125
27189
  "That name is already taken.": "Dieser Name ist bereits vergeben.",
27126
27190
  "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.",
27191
+ "The insert area extends beyond the sheet.": "Der einzuf\xFCgende Bereich reicht \xFCber das Blatt hinaus.",
27127
27192
  "The paste area extends beyond the sheet.": "Der Einf\xFCgebereich reicht \xFCber das Blatt hinaus.",
27128
27193
  "This action won't work on multiple selections.": "Diese Aktion funktioniert nicht bei Mehrfachauswahlen.",
27129
27194
  "This chart could not be displayed.": "Dieses Diagramm konnte nicht angezeigt werden.",
@@ -27445,6 +27510,7 @@ var grid2 = {
27445
27510
  "A sheet name cannot be blank.": "A sheet name cannot be blank.",
27446
27511
  "A sheet name cannot contain \\ / ? * [ ] or :": "A sheet name cannot contain \\ / ? * [ ] or :",
27447
27512
  "A sheet name cannot start or end with an apostrophe.": "A sheet name cannot start or end with an apostrophe.",
27513
+ "Cannot insert cells: non-empty cells would be pushed off the sheet.": "Cannot insert cells: non-empty cells would be pushed off the sheet.",
27448
27514
  Cancel: "Cancel",
27449
27515
  "Cell editor": "Cell editor",
27450
27516
  Chart: "Chart",
@@ -27510,6 +27576,7 @@ var grid2 = {
27510
27576
  "Tab Color": "Tab Color",
27511
27577
  "That name is already taken.": "That name is already taken.",
27512
27578
  "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.",
27579
+ "The insert area extends beyond the sheet.": "The insert area extends beyond the sheet.",
27513
27580
  "The paste area extends beyond the sheet.": "The paste area extends beyond the sheet.",
27514
27581
  "This action won't work on multiple selections.": "This action won't work on multiple selections.",
27515
27582
  "This chart could not be displayed.": "This chart could not be displayed.",
@@ -27831,6 +27898,7 @@ var grid3 = {
27831
27898
  "A sheet name cannot be blank.": "El nombre de una hoja no puede estar en blanco.",
27832
27899
  "A sheet name cannot contain \\ / ? * [ ] or :": "El nombre de una hoja no puede contener \\ / ? * [ ] ni :",
27833
27900
  "A sheet name cannot start or end with an apostrophe.": "El nombre de una hoja no puede empezar ni terminar con un ap\xF3strofo.",
27901
+ "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.",
27834
27902
  Cancel: "Cancelar",
27835
27903
  "Cell editor": "Editor de celdas",
27836
27904
  Chart: "Gr\xE1fico",
@@ -27896,6 +27964,7 @@ var grid3 = {
27896
27964
  "Tab Color": "Color de pesta\xF1a",
27897
27965
  "That name is already taken.": "Ese nombre ya est\xE1 en uso.",
27898
27966
  "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.",
27967
+ "The insert area extends beyond the sheet.": "El \xE1rea de inserci\xF3n se extiende m\xE1s all\xE1 de la hoja.",
27899
27968
  "The paste area extends beyond the sheet.": "El \xE1rea de pegado se extiende m\xE1s all\xE1 de la hoja.",
27900
27969
  "This action won't work on multiple selections.": "Esta acci\xF3n no funciona en selecciones m\xFAltiples.",
27901
27970
  "This chart could not be displayed.": "No se pudo mostrar este gr\xE1fico.",
@@ -28217,6 +28286,7 @@ var grid4 = {
28217
28286
  "A sheet name cannot be blank.": "Un nom de feuille ne peut pas \xEAtre vide.",
28218
28287
  "A sheet name cannot contain \\ / ? * [ ] or :": "Un nom de feuille ne peut pas contenir \\ / ? * [ ] ou :",
28219
28288
  "A sheet name cannot start or end with an apostrophe.": "Un nom de feuille ne peut pas commencer ou se terminer par une apostrophe.",
28289
+ "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.",
28220
28290
  Cancel: "Annuler",
28221
28291
  "Cell editor": "\xC9diteur de cellule",
28222
28292
  Chart: "Graphique",
@@ -28282,6 +28352,7 @@ var grid4 = {
28282
28352
  "Tab Color": "Couleur d\u2019onglet",
28283
28353
  "That name is already taken.": "Ce nom est d\xE9j\xE0 utilis\xE9.",
28284
28354
  "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.",
28355
+ "The insert area extends beyond the sheet.": "La zone d\u2019insertion d\xE9passe les limites de la feuille.",
28285
28356
  "The paste area extends beyond the sheet.": "La zone de collage d\xE9passe les limites de la feuille.",
28286
28357
  "This action won't work on multiple selections.": "Cette action ne fonctionne pas sur des s\xE9lections multiples.",
28287
28358
  "This chart could not be displayed.": "Ce graphique n'a pas pu \xEAtre affich\xE9.",
@@ -28603,6 +28674,7 @@ var grid5 = {
28603
28674
  "A sheet name cannot be blank.": "\u5DE5\u4F5C\u8868\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A\u3002",
28604
28675
  "A sheet name cannot contain \\ / ? * [ ] or :": "\u5DE5\u4F5C\u8868\u540D\u79F0\u4E0D\u80FD\u5305\u542B \\ / ? * [ ] \u6216 :",
28605
28676
  "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",
28677
+ "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",
28606
28678
  Cancel: "\u53D6\u6D88",
28607
28679
  "Cell editor": "\u5355\u5143\u683C\u7F16\u8F91\u5668",
28608
28680
  Chart: "\u56FE\u8868",
@@ -28668,6 +28740,7 @@ var grid5 = {
28668
28740
  "Tab Color": "\u5DE5\u4F5C\u8868\u6807\u7B7E\u989C\u8272",
28669
28741
  "That name is already taken.": "\u8BE5\u540D\u79F0\u5DF2\u88AB\u4F7F\u7528\u3002",
28670
28742
  "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",
28743
+ "The insert area extends beyond the sheet.": "\u63D2\u5165\u533A\u57DF\u8D85\u51FA\u4E86\u5DE5\u4F5C\u8868\u8303\u56F4\u3002",
28671
28744
  "The paste area extends beyond the sheet.": "\u7C98\u8D34\u533A\u57DF\u8D85\u51FA\u4E86\u5DE5\u4F5C\u8868\u8303\u56F4\u3002",
28672
28745
  "This action won't work on multiple selections.": "\u6B64\u64CD\u4F5C\u4E0D\u9002\u7528\u4E8E\u591A\u91CD\u9009\u62E9\u3002",
28673
28746
  "This chart could not be displayed.": "\u65E0\u6CD5\u663E\u793A\u6B64\u56FE\u8868\u3002",
@@ -1 +1 @@
1
- {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../../../xlsx/ui/locales/de/grid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA4FvC,CAAC"}
1
+ {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../../../xlsx/ui/locales/de/grid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAgGvC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../../../xlsx/ui/locales/en/grid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA0FvC,CAAC"}
1
+ {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../../../xlsx/ui/locales/en/grid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA6FvC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../../../xlsx/ui/locales/es/grid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA4FvC,CAAC"}
1
+ {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../../../xlsx/ui/locales/es/grid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAgGvC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../../../xlsx/ui/locales/fr/grid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA6FvC,CAAC"}
1
+ {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../../../xlsx/ui/locales/fr/grid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAiGvC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../../../xlsx/ui/locales/zh-CN/grid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAwFvC,CAAC"}
1
+ {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../../../xlsx/ui/locales/zh-CN/grid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA2FvC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ooxml-core",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Shared OOXML logic for the Word, PowerPoint and Excel viewers: everything except the UI",
5
5
  "keywords": [
6
6
  "charts",