ooxml-core 1.2.1 → 1.4.0

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.
Files changed (201) hide show
  1. package/README.md +2 -0
  2. package/dist/{PptxHandler-VQQS4VS6.mjs → PptxHandler-ZPJNHEZZ.mjs} +2 -2
  3. package/dist/automation/index.cjs +7972 -5580
  4. package/dist/automation/index.mjs +7972 -5580
  5. package/dist/{chunk-5U27IVB7.mjs → chunk-BB55ASTX.mjs} +3 -3
  6. package/dist/{chunk-V2BIGIH4.mjs → chunk-H4TPDZV4.mjs} +1 -1
  7. package/dist/{chunk-5VLNF4OX.mjs → chunk-IVDC75E5.mjs} +1 -1
  8. package/dist/{chunk-XBNSBDNT.mjs → chunk-QPQDLSJQ.mjs} +1 -1
  9. package/dist/{chunk-XSFHGZFH.mjs → chunk-XGLKW3JJ.mjs} +5 -3
  10. package/dist/pptx/automation/index.cjs +4 -2
  11. package/dist/pptx/automation/index.mjs +5 -5
  12. package/dist/pptx/cli/index.cjs +4 -2
  13. package/dist/pptx/cli/index.mjs +4 -4
  14. package/dist/pptx/converter/index.mjs +2 -2
  15. package/dist/pptx/index.cjs +4 -2
  16. package/dist/pptx/index.mjs +5 -5
  17. package/dist/teams/index.cjs +91 -33
  18. package/dist/teams/index.mjs +91 -33
  19. package/dist/visio/clipboard-resources.d.ts +11 -0
  20. package/dist/visio/clipboard-resources.d.ts.map +1 -0
  21. package/dist/visio/clipboard-types.d.ts +26 -0
  22. package/dist/visio/clipboard-types.d.ts.map +1 -0
  23. package/dist/visio/clipboard-xml.d.ts +8 -0
  24. package/dist/visio/clipboard-xml.d.ts.map +1 -0
  25. package/dist/visio/clipboard.d.ts +7 -0
  26. package/dist/visio/clipboard.d.ts.map +1 -0
  27. package/dist/visio/create-document.d.ts +8 -0
  28. package/dist/visio/create-document.d.ts.map +1 -0
  29. package/dist/visio/edit-commands.d.ts +29 -3
  30. package/dist/visio/edit-commands.d.ts.map +1 -1
  31. package/dist/visio/edit-delete.d.ts +9 -0
  32. package/dist/visio/edit-delete.d.ts.map +1 -0
  33. package/dist/visio/edit-duplicate-commands.d.ts +14 -0
  34. package/dist/visio/edit-duplicate-commands.d.ts.map +1 -0
  35. package/dist/visio/edit-duplicate-scope.d.ts +4 -0
  36. package/dist/visio/edit-duplicate-scope.d.ts.map +1 -0
  37. package/dist/visio/edit-duplicate.d.ts +10 -0
  38. package/dist/visio/edit-duplicate.d.ts.map +1 -0
  39. package/dist/visio/edit-formatting-cell-admission.d.ts +3 -0
  40. package/dist/visio/edit-formatting-cell-admission.d.ts.map +1 -0
  41. package/dist/visio/edit-formatting-commands.d.ts +46 -0
  42. package/dist/visio/edit-formatting-commands.d.ts.map +1 -0
  43. package/dist/visio/edit-formatting-font.d.ts +6 -0
  44. package/dist/visio/edit-formatting-font.d.ts.map +1 -0
  45. package/dist/visio/edit-formatting-paint-scope.d.ts +6 -0
  46. package/dist/visio/edit-formatting-paint-scope.d.ts.map +1 -0
  47. package/dist/visio/edit-formatting-paint.d.ts +6 -0
  48. package/dist/visio/edit-formatting-paint.d.ts.map +1 -0
  49. package/dist/visio/edit-formatting-rows.d.ts +14 -0
  50. package/dist/visio/edit-formatting-rows.d.ts.map +1 -0
  51. package/dist/visio/edit-formatting-scope.d.ts +6 -0
  52. package/dist/visio/edit-formatting-scope.d.ts.map +1 -0
  53. package/dist/visio/edit-formatting-text.d.ts +8 -0
  54. package/dist/visio/edit-formatting-text.d.ts.map +1 -0
  55. package/dist/visio/edit-formatting.d.ts +12 -0
  56. package/dist/visio/edit-formatting.d.ts.map +1 -0
  57. package/dist/visio/edit-geometry.d.ts.map +1 -1
  58. package/dist/visio/edit-page-size.d.ts +5 -0
  59. package/dist/visio/edit-page-size.d.ts.map +1 -0
  60. package/dist/visio/edit-pages.d.ts.map +1 -1
  61. package/dist/visio/edit-paste-commands.d.ts +15 -0
  62. package/dist/visio/edit-paste-commands.d.ts.map +1 -0
  63. package/dist/visio/edit-paste.d.ts +5 -0
  64. package/dist/visio/edit-paste.d.ts.map +1 -0
  65. package/dist/visio/edit-recalculate.d.ts +3 -1
  66. package/dist/visio/edit-recalculate.d.ts.map +1 -1
  67. package/dist/visio/edit-resize-anchor.d.ts +8 -0
  68. package/dist/visio/edit-resize-anchor.d.ts.map +1 -0
  69. package/dist/visio/edit-scope.d.ts.map +1 -1
  70. package/dist/visio/edit-shape-create.d.ts +1 -1
  71. package/dist/visio/edit-shape-create.d.ts.map +1 -1
  72. package/dist/visio/edit-shape-order.d.ts +7 -0
  73. package/dist/visio/edit-shape-order.d.ts.map +1 -0
  74. package/dist/visio/edit-style-admission.d.ts +17 -0
  75. package/dist/visio/edit-style-admission.d.ts.map +1 -0
  76. package/dist/visio/edit-text-range-commands.d.ts +21 -0
  77. package/dist/visio/edit-text-range-commands.d.ts.map +1 -0
  78. package/dist/visio/edit-text-range-plan.d.ts +7 -0
  79. package/dist/visio/edit-text-range-plan.d.ts.map +1 -0
  80. package/dist/visio/edit-text-ranges.d.ts +4 -0
  81. package/dist/visio/edit-text-ranges.d.ts.map +1 -0
  82. package/dist/visio/edit-text-scope.d.ts +7 -0
  83. package/dist/visio/edit-text-scope.d.ts.map +1 -0
  84. package/dist/visio/edit-text-target.d.ts +3 -0
  85. package/dist/visio/edit-text-target.d.ts.map +1 -0
  86. package/dist/visio/edit-text.d.ts +1 -1
  87. package/dist/visio/edit-text.d.ts.map +1 -1
  88. package/dist/visio/edit.d.ts +1 -1
  89. package/dist/visio/edit.d.ts.map +1 -1
  90. package/dist/visio/index.cjs +3612 -1076
  91. package/dist/visio/index.d.ts +3 -1
  92. package/dist/visio/index.d.ts.map +1 -1
  93. package/dist/visio/index.mjs +3608 -1078
  94. package/dist/visio/line-pattern.d.ts +1 -1
  95. package/dist/visio/line-pattern.d.ts.map +1 -1
  96. package/dist/visio/line-style.d.ts.map +1 -1
  97. package/dist/visio/model.d.ts +26 -3
  98. package/dist/visio/model.d.ts.map +1 -1
  99. package/dist/visio/parser.d.ts.map +1 -1
  100. package/dist/visio/plain-text.d.ts +5 -0
  101. package/dist/visio/plain-text.d.ts.map +1 -0
  102. package/dist/visio/resize-anchor.d.ts +27 -0
  103. package/dist/visio/resize-anchor.d.ts.map +1 -0
  104. package/dist/visio/source-paint.d.ts +5 -0
  105. package/dist/visio/source-paint.d.ts.map +1 -0
  106. package/dist/visio/style.d.ts.map +1 -1
  107. package/dist/visio/theme-root.d.ts.map +1 -1
  108. package/dist/visio/ui/contract.d.ts +10 -6
  109. package/dist/visio/ui/contract.d.ts.map +1 -1
  110. package/dist/visio/ui/draw-plan.d.ts +32 -0
  111. package/dist/visio/ui/draw-plan.d.ts.map +1 -0
  112. package/dist/visio/ui/edit-commands.d.ts.map +1 -1
  113. package/dist/visio/ui/formatting.d.ts +28 -0
  114. package/dist/visio/ui/formatting.d.ts.map +1 -0
  115. package/dist/visio/ui/index.cjs +1429 -16
  116. package/dist/visio/ui/index.d.ts +16 -0
  117. package/dist/visio/ui/index.d.ts.map +1 -1
  118. package/dist/visio/ui/index.mjs +1380 -17
  119. package/dist/visio/ui/line-dash.d.ts +4 -0
  120. package/dist/visio/ui/line-dash.d.ts.map +1 -0
  121. package/dist/visio/ui/marquee.d.ts +15 -0
  122. package/dist/visio/ui/marquee.d.ts.map +1 -0
  123. package/dist/visio/ui/page-edit.d.ts.map +1 -1
  124. package/dist/visio/ui/page-size.d.ts +31 -0
  125. package/dist/visio/ui/page-size.d.ts.map +1 -0
  126. package/dist/visio/ui/scene-validation.d.ts.map +1 -1
  127. package/dist/visio/ui/selection.d.ts +12 -0
  128. package/dist/visio/ui/selection.d.ts.map +1 -0
  129. package/dist/visio/ui/shape-arrange.d.ts +17 -0
  130. package/dist/visio/ui/shape-arrange.d.ts.map +1 -0
  131. package/dist/visio/ui/shape-clipboard.d.ts +10 -0
  132. package/dist/visio/ui/shape-clipboard.d.ts.map +1 -0
  133. package/dist/visio/ui/shape-duplicate.d.ts +5 -0
  134. package/dist/visio/ui/shape-duplicate.d.ts.map +1 -0
  135. package/dist/visio/ui/shape-formatting.d.ts +14 -0
  136. package/dist/visio/ui/shape-formatting.d.ts.map +1 -0
  137. package/dist/visio/ui/shape-move.d.ts +14 -0
  138. package/dist/visio/ui/shape-move.d.ts.map +1 -0
  139. package/dist/visio/ui/shape-order.d.ts +4 -0
  140. package/dist/visio/ui/shape-order.d.ts.map +1 -0
  141. package/dist/visio/ui/shape-resize.d.ts +61 -0
  142. package/dist/visio/ui/shape-resize.d.ts.map +1 -0
  143. package/dist/visio/ui/size-position.d.ts +19 -0
  144. package/dist/visio/ui/size-position.d.ts.map +1 -0
  145. package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
  146. package/dist/visio/ui/svg-stroke.d.ts +8 -0
  147. package/dist/visio/ui/svg-stroke.d.ts.map +1 -0
  148. package/dist/visio/ui/text-replace-selection.d.ts +9 -0
  149. package/dist/visio/ui/text-replace-selection.d.ts.map +1 -0
  150. package/dist/visio/ui/text-replace-snapshot.d.ts +14 -0
  151. package/dist/visio/ui/text-replace-snapshot.d.ts.map +1 -0
  152. package/dist/visio/ui/text-replace-types.d.ts +52 -0
  153. package/dist/visio/ui/text-replace-types.d.ts.map +1 -0
  154. package/dist/visio/ui/text-replace.d.ts +17 -0
  155. package/dist/visio/ui/text-replace.d.ts.map +1 -0
  156. package/dist/visio/xml-validation.d.ts.map +1 -1
  157. package/dist/xlsx/collab/codec.d.ts +2 -0
  158. package/dist/xlsx/collab/codec.d.ts.map +1 -1
  159. package/dist/xlsx/collab/index.cjs +5 -0
  160. package/dist/xlsx/collab/index.mjs +5 -0
  161. package/dist/xlsx/display-text.d.ts +4 -0
  162. package/dist/xlsx/display-text.d.ts.map +1 -0
  163. package/dist/xlsx/edit/cell-values.d.ts +4 -3
  164. package/dist/xlsx/edit/cell-values.d.ts.map +1 -1
  165. package/dist/xlsx/edit/clipboard.d.ts.map +1 -1
  166. package/dist/xlsx/edit/context.d.ts +7 -5
  167. package/dist/xlsx/edit/context.d.ts.map +1 -1
  168. package/dist/xlsx/edit/deps.d.ts +1 -1
  169. package/dist/xlsx/edit/deps.d.ts.map +1 -1
  170. package/dist/xlsx/edit/dimensions.d.ts.map +1 -1
  171. package/dist/xlsx/edit/fill.d.ts.map +1 -1
  172. package/dist/xlsx/edit/filter.d.ts.map +1 -1
  173. package/dist/xlsx/edit/find.d.ts.map +1 -1
  174. package/dist/xlsx/edit/paste-selection.d.ts.map +1 -1
  175. package/dist/xlsx/edit/shift-formulas.d.ts +10 -4
  176. package/dist/xlsx/edit/shift-formulas.d.ts.map +1 -1
  177. package/dist/xlsx/edit/table-header-names.d.ts +3 -0
  178. package/dist/xlsx/edit/table-header-names.d.ts.map +1 -0
  179. package/dist/xlsx/edit/tables.d.ts +1 -2
  180. package/dist/xlsx/edit/tables.d.ts.map +1 -1
  181. package/dist/xlsx/filter-rows.d.ts +8 -0
  182. package/dist/xlsx/filter-rows.d.ts.map +1 -0
  183. package/dist/xlsx/formula/functions/math-sum.d.ts.map +1 -1
  184. package/dist/xlsx/formula/lexemes.d.ts.map +1 -1
  185. package/dist/xlsx/formula/table-refs.d.ts +2 -0
  186. package/dist/xlsx/formula/table-refs.d.ts.map +1 -1
  187. package/dist/xlsx/index.cjs +463 -332
  188. package/dist/xlsx/index.mjs +463 -332
  189. package/dist/xlsx/load/index.cjs +7628 -7583
  190. package/dist/xlsx/load/index.mjs +7628 -7583
  191. package/dist/xlsx/model.d.ts +4 -0
  192. package/dist/xlsx/model.d.ts.map +1 -1
  193. package/dist/xlsx/read/load.d.ts.map +1 -1
  194. package/dist/xlsx/ui/index.cjs +461 -332
  195. package/dist/xlsx/ui/index.mjs +461 -332
  196. package/dist/xlsx/ui/locales/de/shell.d.ts.map +1 -1
  197. package/dist/xlsx/ui/locales/en/shell.d.ts.map +1 -1
  198. package/dist/xlsx/ui/locales/es/shell.d.ts.map +1 -1
  199. package/dist/xlsx/ui/locales/fr/shell.d.ts.map +1 -1
  200. package/dist/xlsx/ui/locales/zh-CN/shell.d.ts.map +1 -1
  201. package/package.json +1 -1
@@ -2262,14 +2262,13 @@ function splitSheets(text3) {
2262
2262
  if (book !== void 0) out.book = book;
2263
2263
  return out;
2264
2264
  }
2265
- var PREFIX_AT = /(\[\d+\])?([A-Za-z0-9_.\u00A1-\uFFFF]+)(?::([A-Za-z0-9_.\u00A1-\uFFFF]+))?!/y;
2266
2265
  function readPrefix(source2, at) {
2267
2266
  const ch = source2[at];
2268
2267
  if (ch === "'") {
2269
2268
  const quoted = readQuoted(source2, at);
2270
2269
  if (source2[at + quoted.length] !== "!") return void 0;
2271
- const length = quoted.length + 1;
2272
- return { prefix: { text: source2.slice(at, at + length), ...splitSheets(quoted.name) }, length };
2270
+ const length2 = quoted.length + 1;
2271
+ return { prefix: { text: source2.slice(at, at + length2), ...splitSheets(quoted.name) }, length: length2 };
2273
2272
  }
2274
2273
  let i2 = at;
2275
2274
  if (ch === "[") {
@@ -2278,13 +2277,23 @@ function readPrefix(source2, at) {
2278
2277
  if (i2 === at + 1 || source2[i2] !== "]") return void 0;
2279
2278
  i2++;
2280
2279
  }
2280
+ const sheetFrom = i2;
2281
2281
  while (i2 < source2.length && isSheetCharCode(source2.charCodeAt(i2))) i2++;
2282
- if (source2[i2] !== "!" && source2[i2] !== ":") return void 0;
2283
- const m = matchAt(PREFIX_AT, source2, at);
2284
- if (!m) return void 0;
2285
- if (!m[1] && /^\d/.test(m[2] ?? "") && !m[3]) return void 0;
2286
- const raw2 = m[0].slice(0, -1);
2287
- return { prefix: { text: m[0], ...splitSheets(raw2) }, length: m[0].length };
2282
+ if (i2 === sheetFrom) return void 0;
2283
+ let lastFrom = -1;
2284
+ if (source2[i2] === ":") {
2285
+ lastFrom = i2 + 1;
2286
+ i2 = lastFrom;
2287
+ while (i2 < source2.length && isSheetCharCode(source2.charCodeAt(i2))) i2++;
2288
+ if (i2 === lastFrom) return void 0;
2289
+ }
2290
+ if (source2[i2] !== "!") return void 0;
2291
+ if (ch !== "[" && lastFrom < 0 && isDigitCode(source2.charCodeAt(sheetFrom))) return void 0;
2292
+ const length = i2 + 1 - at;
2293
+ return {
2294
+ prefix: { text: source2.slice(at, at + length), ...splitSheets(source2.slice(at, i2)) },
2295
+ length
2296
+ };
2288
2297
  }
2289
2298
  function numberLiteral(text3) {
2290
2299
  if (text3.length <= 15) return Number(text3);
@@ -7800,6 +7809,39 @@ function liftCriteria(ctx, pairs, fn) {
7800
7809
  });
7801
7810
  }
7802
7811
 
7812
+ // xlsx/display-text.ts
7813
+ function displayText(workbook, cell) {
7814
+ if (!cell || cell.value === null) return "";
7815
+ const value = cell.value;
7816
+ if (isCellError(value)) return value.error;
7817
+ if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
7818
+ if (cell.richText && typeof value === "string") return value;
7819
+ return formatValue(value, styleAt(workbook, cell.styleId).numFmt, {
7820
+ date1904: workbook.date1904
7821
+ }).text;
7822
+ }
7823
+
7824
+ // xlsx/filter-rows.ts
7825
+ function rowMatchesFilter(workbook, sheet, row2, filter2) {
7826
+ return (filter2.columns ?? []).every((column) => {
7827
+ if (!column.values && !column.blank) return true;
7828
+ const text3 = displayText(workbook, getCell(sheet, row2, filter2.range.start.col + column.offset));
7829
+ return text3 === "" ? !!column.blank : (column.values ?? []).includes(text3);
7830
+ });
7831
+ }
7832
+ function isFilteredRow(workbook, sheet, row2) {
7833
+ const info = sheet.rowInfo.get(row2);
7834
+ if (info?.filteredOut !== void 0) return info.filteredOut;
7835
+ const filter2 = sheet.autoFilter;
7836
+ return !!info?.hidden && !!filter2 && row2 > filter2.range.start.row && row2 <= filter2.range.end.row && !rowMatchesFilter(workbook, sheet, row2, filter2);
7837
+ }
7838
+ function readFilteredRows(workbook) {
7839
+ for (const sheet of workbook.sheets)
7840
+ for (const [row2, info] of sheet.rowInfo)
7841
+ if (sheet.autoFilter && row2 > sheet.autoFilter.range.start.row && row2 <= sheet.autoFilter.range.end.row && info.hidden)
7842
+ info.filteredOut = isFilteredRow(workbook, sheet, row2);
7843
+ }
7844
+
7803
7845
  // xlsx/formula/functions/math-sum.ts
7804
7846
  var C18 = "Math & Trig";
7805
7847
  var numbersOf = (values2) => values2.filter((v) => typeof v === "number");
@@ -7837,7 +7879,7 @@ function pairwise(ctx, args, fn) {
7837
7879
  return total2;
7838
7880
  }
7839
7881
  var SUBTOTAL_RE = /\b(?:_xlfn\.)?(?:SUBTOTAL|AGGREGATE)\s*\(/i;
7840
- function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
7882
+ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true, skipFiltered = false) {
7841
7883
  const out = [];
7842
7884
  const host = ctx.frame.host;
7843
7885
  for (const arg of args) {
@@ -7850,6 +7892,7 @@ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
7850
7892
  for (const area of arg.areas) {
7851
7893
  const sheet = ctx.workbook.sheets[area.sheet];
7852
7894
  host.forEachStored(area.sheet, area.range, (value, row2, col) => {
7895
+ if (skipFiltered && sheet && isFilteredRow(ctx.workbook, sheet, row2)) return;
7853
7896
  if (skipHidden && sheet?.rowInfo.get(row2)?.hidden) return;
7854
7897
  if (skipNested && SUBTOTAL_RE.test(host.cellFormula(area.sheet, row2, col) ?? "")) return;
7855
7898
  if (skipErrors && isError(value)) return;
@@ -8015,7 +8058,7 @@ var SUM_FUNCTIONS = [
8015
8058
  const code = int(args[0]);
8016
8059
  const base = code > 100 ? code - 100 : code;
8017
8060
  if (base < 1 || base > 11) fail(ERR.VALUE);
8018
- return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false));
8061
+ return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false, true, true));
8019
8062
  },
8020
8063
  ["value", "any"]
8021
8064
  ),
@@ -13553,6 +13596,31 @@ function renameTableInFormula(formula, oldName, newName) {
13553
13596
  }
13554
13597
  return changed ? joinTokens(tokens2) : formula;
13555
13598
  }
13599
+ function renameTableColumnInFormula(formula, tableName, oldName, newName, insideTable = false) {
13600
+ const tokens2 = safeTokens2(formula);
13601
+ if (!tokens2) return formula;
13602
+ const escaped = newName.replace(/['#@[\]]/g, "'$&");
13603
+ let changed = false;
13604
+ for (const [index2, token] of tokens2.entries()) {
13605
+ if (token.kind !== "structured" || token.prefix) continue;
13606
+ if (token.value === "" && tokens2[index2 - 1]?.prefix) continue;
13607
+ if (token.value === "" ? !insideTable : String(token.value).toLowerCase() !== tableName.toLowerCase())
13608
+ continue;
13609
+ const next = token.text.replace(
13610
+ /\[(@?)((?:[^\[\]']|'[\s\S])*)\]/g,
13611
+ (original, at, name) => {
13612
+ if (name.startsWith("#") || name.replace(/'(.)/g, "$1").toLowerCase() !== oldName.toLowerCase())
13613
+ return original;
13614
+ return `[${at}${escaped}]`;
13615
+ }
13616
+ );
13617
+ if (next !== token.text) {
13618
+ token.text = next;
13619
+ changed = true;
13620
+ }
13621
+ }
13622
+ return changed ? joinTokens(tokens2) : formula;
13623
+ }
13556
13624
 
13557
13625
  // xlsx/formula/structured-to-a1.ts
13558
13626
  var abs = (row2, col, rowAbs = true) => `$${columnLabel(col)}${rowAbs ? "$" : ""}${row2 + 1}`;
@@ -20309,6 +20377,7 @@ async function loadXlsx(input) {
20309
20377
  if (!sheets.length) throw new Error("XLSX workbook has no sheets");
20310
20378
  await resolveSmartArt(sheets, source2, warn);
20311
20379
  liftPrintAreas(workbook);
20380
+ readFilteredRows(workbook);
20312
20381
  return workbook;
20313
20382
  }
20314
20383
  function readProperties(core, app, custom, warn) {
@@ -24611,16 +24680,6 @@ function forEachPosition(sheet, range, visit2) {
24611
24680
  for (let row2 = r.start.row; row2 <= r.end.row; row2++)
24612
24681
  for (let col = r.start.col; col <= r.end.col; col++) visit2(row2, col);
24613
24682
  }
24614
- function displayText(workbook, cell) {
24615
- if (!cell) return "";
24616
- const value = cell.value;
24617
- if (value === null) return "";
24618
- if (isCellError(value)) return value.error;
24619
- if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
24620
- if (cell.richText && typeof value === "string") return value;
24621
- const format = styleAt(workbook, cell.styleId).numFmt;
24622
- return formatValue(value, format, { date1904: workbook.date1904 }).text;
24623
- }
24624
24683
  function rawText(value) {
24625
24684
  if (value === null) return "";
24626
24685
  if (isCellError(value)) return value.error;
@@ -24637,19 +24696,266 @@ function pruneCell(sheet, row2, col) {
24637
24696
  }
24638
24697
  }
24639
24698
 
24699
+ // xlsx/edit/shift-preserved.ts
24700
+ var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
24701
+ function descendants3(root, ns, local) {
24702
+ return Array.from(root.getElementsByTagNameNS(ns, local));
24703
+ }
24704
+ function editEntries(sheet, key, edit, quick) {
24705
+ const list = sheet.preserved.get(key);
24706
+ if (!list) return;
24707
+ const next = [];
24708
+ for (const xml of list) {
24709
+ if (!quick(xml)) {
24710
+ next.push(xml);
24711
+ continue;
24712
+ }
24713
+ let doc;
24714
+ try {
24715
+ doc = parseXml(xml);
24716
+ } catch {
24717
+ next.push(xml);
24718
+ continue;
24719
+ }
24720
+ const outcome = edit(doc.documentElement);
24721
+ if (outcome === "same") next.push(xml);
24722
+ else if (outcome === "changed") next.push(buildXml(doc));
24723
+ }
24724
+ if (next.length) sheet.preserved.set(key, next);
24725
+ else sheet.preserved.delete(key);
24726
+ }
24727
+ function shiftBreaks(root, shift2) {
24728
+ let changed = false;
24729
+ for (const brk of elements(root).filter((e) => e.localName === "brk")) {
24730
+ const id = Number(brk.getAttribute("id") ?? "0");
24731
+ const moved = shiftIndex(id, shift2);
24732
+ if (moved === id) continue;
24733
+ changed = true;
24734
+ if (moved === void 0 || moved === 0) root.removeChild(brk);
24735
+ else brk.setAttribute("id", String(moved));
24736
+ }
24737
+ if (!changed) return "same";
24738
+ const left2 = elements(root).filter((e) => e.localName === "brk");
24739
+ if (!left2.length) return "drop";
24740
+ if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
24741
+ if (root.hasAttribute("manualBreakCount")) {
24742
+ const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
24743
+ root.setAttribute("manualBreakCount", String(manual));
24744
+ }
24745
+ return "changed";
24746
+ }
24747
+ function removeUpwards(node, root) {
24748
+ let current = node;
24749
+ while (current && current !== root) {
24750
+ const parent = current.parentNode;
24751
+ parent?.removeChild(current);
24752
+ if (!parent) break;
24753
+ const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
24754
+ if (!emptied) break;
24755
+ current = parent;
24756
+ }
24757
+ }
24758
+ function shiftSqrefs(root, moveRange) {
24759
+ let changed = false;
24760
+ for (const sqref2 of descendants3(root, XM3, "sqref")) {
24761
+ const old = sqref2.textContent ?? "";
24762
+ const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
24763
+ const text3 = ranges.map(formatRange).join(" ");
24764
+ if (text3 === old.trim()) continue;
24765
+ changed = true;
24766
+ const owner = sqref2.parentNode;
24767
+ if (ranges.length) sqref2.textContent = text3;
24768
+ else if (owner) removeUpwards(owner, root);
24769
+ }
24770
+ if (!changed) return "same";
24771
+ for (const list of elements(root).flatMap((ext) => elements(ext)))
24772
+ if (list.localName === "dataValidations" && list.hasAttribute("count"))
24773
+ list.setAttribute("count", String(elements(list).length));
24774
+ return elements(root).length > 0 ? "changed" : "drop";
24775
+ }
24776
+ function shiftPreservedXml(sheet, shift2, moveRange, banded) {
24777
+ if (!banded)
24778
+ editEntries(
24779
+ sheet,
24780
+ shift2.axis === "row" ? "rowBreaks" : "colBreaks",
24781
+ (root) => shiftBreaks(root, shift2),
24782
+ (xml) => xml.includes("brk")
24783
+ );
24784
+ editEntries(
24785
+ sheet,
24786
+ "extLst",
24787
+ (root) => shiftSqrefs(root, moveRange),
24788
+ (xml) => xml.includes("sqref")
24789
+ );
24790
+ }
24791
+ function rewritePreservedFormulas(sheet, rewrite2) {
24792
+ editEntries(
24793
+ sheet,
24794
+ "extLst",
24795
+ (root) => {
24796
+ let changed = false;
24797
+ for (const f6 of descendants3(root, XM3, "f")) {
24798
+ const text3 = f6.textContent ?? "";
24799
+ let next = text3;
24800
+ try {
24801
+ next = rewrite2(text3, sheet.name);
24802
+ } catch {
24803
+ next = text3;
24804
+ }
24805
+ if (next === text3) continue;
24806
+ f6.textContent = next;
24807
+ changed = true;
24808
+ }
24809
+ return changed ? "changed" : "same";
24810
+ },
24811
+ (xml) => xml.includes(":f>")
24812
+ );
24813
+ }
24814
+
24815
+ // xlsx/edit/conditional-formulas.ts
24816
+ function rewriteConditionalRule(rule, rewrite2) {
24817
+ const safe2 = (formula) => {
24818
+ try {
24819
+ return rewrite2(formula);
24820
+ } catch {
24821
+ return formula;
24822
+ }
24823
+ };
24824
+ if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
24825
+ else if (rule.type === "expression") rule.formula = safe2(rule.formula);
24826
+ if (rule.type === "colorScale" || rule.type === "iconSet") {
24827
+ for (const threshold of rule.thresholds)
24828
+ if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
24829
+ }
24830
+ if (rule.type === "dataBar") {
24831
+ for (const threshold of [rule.min, rule.max])
24832
+ if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
24833
+ }
24834
+ if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
24835
+ }
24836
+
24837
+ // xlsx/edit/shift-formulas.ts
24838
+ function safe(rewrite2, formula, formulaSheet, at) {
24839
+ try {
24840
+ return rewrite2(formula, formulaSheet, at);
24841
+ } catch {
24842
+ return formula;
24843
+ }
24844
+ }
24845
+ function rewriteFormulas(workbook, rewrite2, formulaCells) {
24846
+ const bySheet = formulaCells && /* @__PURE__ */ new Map();
24847
+ if (bySheet)
24848
+ for (const cell of formulaCells ?? []) {
24849
+ const positions2 = bySheet.get(cell.sheet);
24850
+ if (positions2) positions2.push(cell);
24851
+ else bySheet.set(cell.sheet, [cell]);
24852
+ }
24853
+ workbook.sheets.forEach(
24854
+ (sheet, index2) => rewriteSheetFormulas(sheet, rewrite2, bySheet ? bySheet.get(index2) ?? [] : void 0)
24855
+ );
24856
+ for (const definedName of workbook.definedNames) {
24857
+ const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
24858
+ definedName.formula = safe(rewrite2, definedName.formula, local?.name ?? "");
24859
+ }
24860
+ }
24861
+ function rewriteSheetFormulas(sheet, rewrite2, formulaCells) {
24862
+ rewritePreservedFormulas(sheet, rewrite2);
24863
+ {
24864
+ const name = sheet.name;
24865
+ for (const table2 of sheet.tables)
24866
+ for (const [index2, column] of table2.columns.entries())
24867
+ if (column.calculatedColumnFormula !== void 0)
24868
+ column.calculatedColumnFormula = safe(rewrite2, column.calculatedColumnFormula, name, {
24869
+ row: table2.range.start.row + (table2.headerRow ? 1 : 0),
24870
+ col: table2.range.start.col + index2
24871
+ });
24872
+ if (formulaCells) {
24873
+ for (const at of formulaCells) {
24874
+ const cell = getCell(sheet, at.row, at.col);
24875
+ if (cell?.formula !== void 0) cell.formula = safe(rewrite2, cell.formula, name, at);
24876
+ }
24877
+ } else {
24878
+ sheet.rows.forEach(
24879
+ (cells, row2) => cells.forEach((cell, col) => {
24880
+ if (cell.formula !== void 0)
24881
+ cell.formula = safe(rewrite2, cell.formula, name, { row: row2, col });
24882
+ })
24883
+ );
24884
+ }
24885
+ for (const cf of sheet.conditionalFormats)
24886
+ for (const rule of cf.rules)
24887
+ rewriteConditionalRule(rule, (f6) => rewrite2(f6, name, cf.ranges[0]?.start));
24888
+ for (const dv of sheet.dataValidations) {
24889
+ if (dv.formula1 !== void 0)
24890
+ dv.formula1 = safe(rewrite2, dv.formula1, name, dv.ranges[0]?.start);
24891
+ if (dv.formula2 !== void 0)
24892
+ dv.formula2 = safe(rewrite2, dv.formula2, name, dv.ranges[0]?.start);
24893
+ }
24894
+ for (const link of sheet.hyperlinks)
24895
+ if (link.location && /![A-Za-z$]/.test(link.location))
24896
+ link.location = safe(rewrite2, link.location, name);
24897
+ for (const drawing of sheet.drawings) {
24898
+ if (drawing.kind !== "chart") continue;
24899
+ for (const series of drawing.series) {
24900
+ if (series.nameRef) series.nameRef = safe(rewrite2, series.nameRef, name);
24901
+ if (series.categoriesRef) series.categoriesRef = safe(rewrite2, series.categoriesRef, name);
24902
+ if (series.valuesRef) series.valuesRef = safe(rewrite2, series.valuesRef, name);
24903
+ }
24904
+ }
24905
+ }
24906
+ }
24907
+
24908
+ // xlsx/edit/table-header-names.ts
24909
+ function uniqueHeaders(texts) {
24910
+ const used = /* @__PURE__ */ new Set();
24911
+ return texts.map((text3, i2) => {
24912
+ let base = text3.trim() || `Column${i2 + 1}`;
24913
+ if (!used.has(base.toLowerCase())) {
24914
+ used.add(base.toLowerCase());
24915
+ return base;
24916
+ }
24917
+ for (let n2 = 2; ; n2++) {
24918
+ const candidate = `${base}${n2}`;
24919
+ if (!used.has(candidate.toLowerCase())) {
24920
+ used.add(candidate.toLowerCase());
24921
+ base = candidate;
24922
+ return base;
24923
+ }
24924
+ }
24925
+ });
24926
+ }
24927
+
24640
24928
  // xlsx/edit/cell-values.ts
24641
24929
  function tableHeaderAt(sheet, row2, col) {
24642
24930
  return sheet.tables.find(
24643
24931
  (t) => t.headerRow && t.range.start.row === row2 && col >= t.range.start.col && col <= t.range.end.col
24644
24932
  );
24645
24933
  }
24646
- function syncTableHeader(ctx, sheet, row2, col) {
24934
+ function syncTableHeader(ctx, sheet, row2, col, formulaCells) {
24647
24935
  const table2 = tableHeaderAt(sheet, row2, col);
24648
24936
  if (!table2) return;
24649
24937
  const column = table2.columns[col - table2.range.start.col];
24650
24938
  if (!column) return;
24651
24939
  const text3 = displayText(ctx.workbook, getCell(sheet, row2, col)).trim();
24652
- if (text3) column.name = text3;
24940
+ if (!text3 || column.name === text3) return;
24941
+ const oldName = column.name;
24942
+ const others = table2.columns.filter((entry3) => entry3 !== column).map((entry3) => entry3.name);
24943
+ const newName = uniqueHeaders([...others, text3]).at(-1);
24944
+ column.name = newName;
24945
+ if (newName !== text3) writeValue(sheet, row2, col, newName);
24946
+ const index2 = ctx.workbook.sheets.indexOf(sheet);
24947
+ const cells = formulaCells && (formulaCells.some((cell) => cell.sheet === index2 && cell.row === row2 && cell.col === col) ? formulaCells : [...formulaCells, { sheet: index2, row: row2, col }]);
24948
+ rewriteFormulas(
24949
+ ctx.workbook,
24950
+ (formula, formulaSheet, at) => renameTableColumnInFormula(
24951
+ formula,
24952
+ table2.name,
24953
+ oldName,
24954
+ newName,
24955
+ formulaSheet === sheet.name && !!at && rangeContains(table2.range, at)
24956
+ ),
24957
+ cells
24958
+ );
24653
24959
  }
24654
24960
  function writeScopes(sheet, index2, range, parts = []) {
24655
24961
  const r = normalizeRange(range);
@@ -24659,9 +24965,9 @@ function writeScopes(sheet, index2, range, parts = []) {
24659
24965
  cellRange(t.range.start.row, t.range.start.col, t.range.start.row, t.range.end.col)
24660
24966
  )
24661
24967
  );
24662
- const all2 = touchesHeader && !parts.includes("tables") ? [...parts, "tables"] : parts;
24968
+ if (touchesHeader) return [{ kind: "refs" }, { kind: "cells", sheet: index2, ranges: [r] }];
24663
24969
  const scopes = [{ kind: "cells", sheet: index2, ranges: [r] }];
24664
- if (all2.length) scopes.push({ kind: "parts", sheet: index2, parts: all2 });
24970
+ if (parts.length) scopes.push({ kind: "parts", sheet: index2, parts });
24665
24971
  return scopes;
24666
24972
  }
24667
24973
  function writeInput(ctx, sheet, row2, col, text3) {
@@ -24712,9 +25018,9 @@ function setCellInput(ctx, s, row2, col, text3) {
24712
25018
  `Typing in ${formatAddress({ row: row2, col })}`,
24713
25019
  "cells",
24714
25020
  writeScopes(sheet, s, range),
24715
- () => {
25021
+ (formulaCells) => {
24716
25022
  writeInput(ctx, sheet, row2, col, text3);
24717
- syncTableHeader(ctx, sheet, row2, col);
25023
+ syncTableHeader(ctx, sheet, row2, col, formulaCells);
24718
25024
  },
24719
25025
  { sheet: s, ranges: [range] }
24720
25026
  );
@@ -24726,9 +25032,9 @@ function setCellValue(ctx, s, row2, col, value) {
24726
25032
  `Edit ${formatAddress({ row: row2, col })}`,
24727
25033
  "cells",
24728
25034
  writeScopes(sheet, s, range),
24729
- () => {
25035
+ (formulaCells) => {
24730
25036
  writeValue(sheet, row2, col, value);
24731
- syncTableHeader(ctx, sheet, row2, col);
25037
+ syncTableHeader(ctx, sheet, row2, col, formulaCells);
24732
25038
  },
24733
25039
  { sheet: s, ranges: [range] }
24734
25040
  );
@@ -25155,7 +25461,7 @@ function fillRange(ctx, s, source2, target, mode = "auto") {
25155
25461
  ctx.run(
25156
25462
  "Fill",
25157
25463
  "cells",
25158
- [{ kind: "cells", sheet: s, ranges: [all2] }],
25464
+ writeScopes(sheet, s, all2),
25159
25465
  () => {
25160
25466
  const laneCount = vertical ? src.end.col - src.start.col + 1 : src.end.row - src.start.row + 1;
25161
25467
  const length = vertical ? src.end.row - src.start.row + 1 : src.end.col - src.start.col + 1;
@@ -25178,6 +25484,7 @@ function fillRange(ctx, s, source2, target, mode = "auto") {
25178
25484
  const step2 = series?.(k);
25179
25485
  const cell = !step2 || step2.kind === "copy" ? copyCell(origin, row2 - srcRow, col - srcCol) : { value: step2.value, ...origin.styleId ? { styleId: origin.styleId } : {} };
25180
25486
  putCell(sheet, row2, col, cell);
25487
+ syncTableHeader(ctx, sheet, row2, col);
25181
25488
  }
25182
25489
  }
25183
25490
  },
@@ -25216,28 +25523,6 @@ function removeValidationArea(rules, area) {
25216
25523
  });
25217
25524
  }
25218
25525
 
25219
- // xlsx/edit/conditional-formulas.ts
25220
- function rewriteConditionalRule(rule, rewrite2) {
25221
- const safe2 = (formula) => {
25222
- try {
25223
- return rewrite2(formula);
25224
- } catch {
25225
- return formula;
25226
- }
25227
- };
25228
- if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
25229
- else if (rule.type === "expression") rule.formula = safe2(rule.formula);
25230
- if (rule.type === "colorScale" || rule.type === "iconSet") {
25231
- for (const threshold of rule.thresholds)
25232
- if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
25233
- }
25234
- if (rule.type === "dataBar") {
25235
- for (const threshold of [rule.min, rule.max])
25236
- if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
25237
- }
25238
- if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
25239
- }
25240
-
25241
25526
  // xlsx/edit/conditional-formats.ts
25242
25527
  function formatAt(sheet, index2) {
25243
25528
  const format = sheet.conditionalFormats[index2];
@@ -25647,168 +25932,6 @@ function setBorders(ctx, s, range, preset, edge2 = { style: "thin" }) {
25647
25932
  );
25648
25933
  }
25649
25934
 
25650
- // xlsx/edit/shift-preserved.ts
25651
- var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
25652
- function descendants3(root, ns, local) {
25653
- return Array.from(root.getElementsByTagNameNS(ns, local));
25654
- }
25655
- function editEntries(sheet, key, edit, quick) {
25656
- const list = sheet.preserved.get(key);
25657
- if (!list) return;
25658
- const next = [];
25659
- for (const xml of list) {
25660
- if (!quick(xml)) {
25661
- next.push(xml);
25662
- continue;
25663
- }
25664
- let doc;
25665
- try {
25666
- doc = parseXml(xml);
25667
- } catch {
25668
- next.push(xml);
25669
- continue;
25670
- }
25671
- const outcome = edit(doc.documentElement);
25672
- if (outcome === "same") next.push(xml);
25673
- else if (outcome === "changed") next.push(buildXml(doc));
25674
- }
25675
- if (next.length) sheet.preserved.set(key, next);
25676
- else sheet.preserved.delete(key);
25677
- }
25678
- function shiftBreaks(root, shift2) {
25679
- let changed = false;
25680
- for (const brk of elements(root).filter((e) => e.localName === "brk")) {
25681
- const id = Number(brk.getAttribute("id") ?? "0");
25682
- const moved = shiftIndex(id, shift2);
25683
- if (moved === id) continue;
25684
- changed = true;
25685
- if (moved === void 0 || moved === 0) root.removeChild(brk);
25686
- else brk.setAttribute("id", String(moved));
25687
- }
25688
- if (!changed) return "same";
25689
- const left2 = elements(root).filter((e) => e.localName === "brk");
25690
- if (!left2.length) return "drop";
25691
- if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
25692
- if (root.hasAttribute("manualBreakCount")) {
25693
- const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
25694
- root.setAttribute("manualBreakCount", String(manual));
25695
- }
25696
- return "changed";
25697
- }
25698
- function removeUpwards(node, root) {
25699
- let current = node;
25700
- while (current && current !== root) {
25701
- const parent = current.parentNode;
25702
- parent?.removeChild(current);
25703
- if (!parent) break;
25704
- const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
25705
- if (!emptied) break;
25706
- current = parent;
25707
- }
25708
- }
25709
- function shiftSqrefs(root, moveRange) {
25710
- let changed = false;
25711
- for (const sqref2 of descendants3(root, XM3, "sqref")) {
25712
- const old = sqref2.textContent ?? "";
25713
- const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
25714
- const text3 = ranges.map(formatRange).join(" ");
25715
- if (text3 === old.trim()) continue;
25716
- changed = true;
25717
- const owner = sqref2.parentNode;
25718
- if (ranges.length) sqref2.textContent = text3;
25719
- else if (owner) removeUpwards(owner, root);
25720
- }
25721
- if (!changed) return "same";
25722
- for (const list of elements(root).flatMap((ext) => elements(ext)))
25723
- if (list.localName === "dataValidations" && list.hasAttribute("count"))
25724
- list.setAttribute("count", String(elements(list).length));
25725
- return elements(root).length > 0 ? "changed" : "drop";
25726
- }
25727
- function shiftPreservedXml(sheet, shift2, moveRange, banded) {
25728
- if (!banded)
25729
- editEntries(
25730
- sheet,
25731
- shift2.axis === "row" ? "rowBreaks" : "colBreaks",
25732
- (root) => shiftBreaks(root, shift2),
25733
- (xml) => xml.includes("brk")
25734
- );
25735
- editEntries(
25736
- sheet,
25737
- "extLst",
25738
- (root) => shiftSqrefs(root, moveRange),
25739
- (xml) => xml.includes("sqref")
25740
- );
25741
- }
25742
- function rewritePreservedFormulas(sheet, rewrite2) {
25743
- editEntries(
25744
- sheet,
25745
- "extLst",
25746
- (root) => {
25747
- let changed = false;
25748
- for (const f6 of descendants3(root, XM3, "f")) {
25749
- const text3 = f6.textContent ?? "";
25750
- let next = text3;
25751
- try {
25752
- next = rewrite2(text3, sheet.name);
25753
- } catch {
25754
- next = text3;
25755
- }
25756
- if (next === text3) continue;
25757
- f6.textContent = next;
25758
- changed = true;
25759
- }
25760
- return changed ? "changed" : "same";
25761
- },
25762
- (xml) => xml.includes(":f>")
25763
- );
25764
- }
25765
-
25766
- // xlsx/edit/shift-formulas.ts
25767
- function safe(rewrite2, formula, formulaSheet) {
25768
- try {
25769
- return rewrite2(formula, formulaSheet);
25770
- } catch {
25771
- return formula;
25772
- }
25773
- }
25774
- function rewriteFormulas(workbook, rewrite2) {
25775
- for (const sheet of workbook.sheets) rewriteSheetFormulas(sheet, rewrite2);
25776
- for (const definedName of workbook.definedNames) {
25777
- const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
25778
- definedName.formula = safe(rewrite2, definedName.formula, local?.name ?? "");
25779
- }
25780
- }
25781
- function rewriteSheetFormulas(sheet, rewrite2) {
25782
- rewritePreservedFormulas(sheet, rewrite2);
25783
- {
25784
- const name = sheet.name;
25785
- for (const table2 of sheet.tables)
25786
- for (const column of table2.columns)
25787
- if (column.calculatedColumnFormula !== void 0)
25788
- column.calculatedColumnFormula = safe(rewrite2, column.calculatedColumnFormula, name);
25789
- for (const cells of sheet.rows.values())
25790
- for (const cell of cells.values())
25791
- if (cell.formula !== void 0) cell.formula = safe(rewrite2, cell.formula, name);
25792
- for (const cf of sheet.conditionalFormats)
25793
- for (const rule of cf.rules) rewriteConditionalRule(rule, (f6) => rewrite2(f6, name));
25794
- for (const dv of sheet.dataValidations) {
25795
- if (dv.formula1 !== void 0) dv.formula1 = safe(rewrite2, dv.formula1, name);
25796
- if (dv.formula2 !== void 0) dv.formula2 = safe(rewrite2, dv.formula2, name);
25797
- }
25798
- for (const link of sheet.hyperlinks)
25799
- if (link.location && /![A-Za-z$]/.test(link.location))
25800
- link.location = safe(rewrite2, link.location, name);
25801
- for (const drawing of sheet.drawings) {
25802
- if (drawing.kind !== "chart") continue;
25803
- for (const series of drawing.series) {
25804
- if (series.nameRef) series.nameRef = safe(rewrite2, series.nameRef, name);
25805
- if (series.categoriesRef) series.categoriesRef = safe(rewrite2, series.categoriesRef, name);
25806
- if (series.valuesRef) series.valuesRef = safe(rewrite2, series.valuesRef, name);
25807
- }
25808
- }
25809
- }
25810
- }
25811
-
25812
25935
  // xlsx/edit/shift-sheet.ts
25813
25936
  function shiftSheetContent(sheet, shift2, band) {
25814
25937
  const moveRange = (range) => band ? shiftRangeInBand(range, shift2, band.lo, band.hi) : shiftRange(range, shift2);
@@ -26798,14 +26921,13 @@ function pasteAt(ctx, s, at, payload, request) {
26798
26921
  if (cut && operation !== "none")
26799
26922
  throw new RangeError("Paste operations are not available for cut cells.");
26800
26923
  const destCells = { kind: "cells", sheet: s, ranges: [dest] };
26801
- const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : [
26802
- destCells,
26803
- {
26804
- kind: "parts",
26805
- sheet: s,
26806
- parts: ["merges", "comments", "dataValidations", "hyperlinks", "conditionalFormats"]
26807
- }
26808
- ];
26924
+ const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : writeScopes(sheet, s, dest, [
26925
+ "merges",
26926
+ "comments",
26927
+ "dataValidations",
26928
+ "hyperlinks",
26929
+ "conditionalFormats"
26930
+ ]);
26809
26931
  const move = cut && {
26810
26932
  fromSheet: sheetAt(workbook, cut.sheet).name,
26811
26933
  range: cut.range,
@@ -26878,6 +27000,8 @@ function pasteAt(ctx, s, at, payload, request) {
26878
27000
  const origin = cells.source?.range.start;
26879
27001
  const formula = clip?.formula === void 0 ? void 0 : move ? moveReferencesInFormula(clip.formula, move.fromSheet, move, move.toSheet) : !origin ? clip.formula : moveFormula(clip.formula, at.row - origin.row, at.col - origin.col);
26880
27002
  writeClip(workbook, sheet, row2, col, clip, mode, formula, styleOf2, operation);
27003
+ if (mode !== "formats" && mode !== "comments" && mode !== "validation")
27004
+ syncTableHeader(ctx, sheet, row2, col);
26881
27005
  }
26882
27006
  if (mode === "all" || mode === "mergeFormats" || mode === "noBorders" || mode === "formats") {
26883
27007
  sheet.merges = sheet.merges.filter((m) => !rangesIntersect(m, dest));
@@ -26921,14 +27045,13 @@ function pasteSelection(ctx, sheet, selection, payload, request) {
26921
27045
  return ctx.run(
26922
27046
  "Paste",
26923
27047
  "cells",
26924
- [
26925
- { kind: "cells", sheet, ranges: [dest] },
26926
- {
26927
- kind: "parts",
26928
- sheet,
26929
- parts: ["merges", "comments", "dataValidations", "hyperlinks", "conditionalFormats"]
26930
- }
26931
- ],
27048
+ writeScopes(sheetAt(ctx.workbook, sheet), sheet, dest, [
27049
+ "merges",
27050
+ "comments",
27051
+ "dataValidations",
27052
+ "hyperlinks",
27053
+ "conditionalFormats"
27054
+ ]),
26932
27055
  () => {
26933
27056
  for (let row2 = dest.start.row; row2 <= dest.end.row; row2 += height)
26934
27057
  for (let col = dest.start.col; col <= dest.end.col; col += width)
@@ -27080,6 +27203,15 @@ function setHidden(ctx, s, axis, indices, hidden) {
27080
27203
  }
27081
27204
  for (const row2 of indices) {
27082
27205
  const info = { ...sheet.rowInfo.get(row2) };
27206
+ if (info.filteredOut) {
27207
+ if (hidden) info.manuallyHidden = true;
27208
+ else delete info.manuallyHidden;
27209
+ sheet.rowInfo.set(row2, info);
27210
+ continue;
27211
+ }
27212
+ const filter2 = sheet.autoFilter;
27213
+ if (filter2?.columns?.length && row2 > filter2.range.start.row && row2 <= filter2.range.end.row)
27214
+ info.filteredOut = false;
27083
27215
  if (hidden) info.hidden = true;
27084
27216
  else {
27085
27217
  delete info.hidden;
@@ -27234,14 +27366,21 @@ function currentRegion(sheet, at) {
27234
27366
  function applyFilter(ctx, sheet, filter2) {
27235
27367
  const { range } = filter2;
27236
27368
  for (let row2 = range.start.row + 1; row2 <= range.end.row; row2++) {
27237
- const visible = (filter2.columns ?? []).every((fc) => {
27238
- if (!fc.values && !fc.blank) return true;
27239
- const text3 = displayText(ctx.workbook, getCell(sheet, row2, range.start.col + fc.offset));
27240
- return text3 === "" ? !!fc.blank : (fc.values ?? []).includes(text3);
27241
- });
27369
+ const visible = rowMatchesFilter(ctx.workbook, sheet, row2, filter2);
27242
27370
  const info = { ...sheet.rowInfo.get(row2) };
27243
- if (visible) delete info.hidden;
27244
- else info.hidden = true;
27371
+ const manual = info.manuallyHidden || info.hidden && !info.filteredOut;
27372
+ if (visible) {
27373
+ delete info.filteredOut;
27374
+ delete info.manuallyHidden;
27375
+ if (manual) {
27376
+ info.hidden = true;
27377
+ if (filter2.columns?.length) info.filteredOut = false;
27378
+ } else delete info.hidden;
27379
+ } else {
27380
+ info.hidden = true;
27381
+ info.filteredOut = true;
27382
+ if (manual) info.manuallyHidden = true;
27383
+ }
27245
27384
  if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
27246
27385
  else sheet.rowInfo.delete(row2);
27247
27386
  }
@@ -27405,16 +27544,16 @@ var isSpilledAt = (workbook, at) => {
27405
27544
  return !!sheet && isSpilledCell(getCell(sheet, at.row, at.col));
27406
27545
  };
27407
27546
  var replaceQuery = (query) => query.lookIn === "comments" ? query : { ...query, lookIn: "formulas" };
27408
- function replaceScopes(query, sheet, matches2) {
27547
+ function replaceScopes(ctx, query, sheet, matches2) {
27409
27548
  if (query.lookIn === "comments") return [{ kind: "parts", sheet, parts: ["comments"] }];
27410
27549
  const ranges = matches2.map((m) => ({
27411
27550
  start: { row: m.row, col: m.col },
27412
27551
  end: { row: m.row, col: m.col }
27413
27552
  }));
27414
- return [
27415
- { kind: "cells", sheet, ranges },
27416
- { kind: "parts", sheet, parts: ["tables"] }
27417
- ];
27553
+ const header = ranges.some(
27554
+ (range) => writeScopes(sheetAt(ctx.workbook, sheet), sheet, range).some((scope) => scope.kind === "refs")
27555
+ );
27556
+ return [...header ? [{ kind: "refs" }] : [], { kind: "cells", sheet, ranges }];
27418
27557
  }
27419
27558
  function applyReplace(ctx, query, replacement, matches2) {
27420
27559
  let changed = 0;
@@ -27444,14 +27583,24 @@ function replaceAll(ctx, query, replacement) {
27444
27583
  const sheets = [...new Set(matches2.map((m) => m.sheet))];
27445
27584
  const scopes = sheets.flatMap(
27446
27585
  (sheet) => replaceScopes(
27586
+ ctx,
27447
27587
  q,
27448
27588
  sheet,
27449
27589
  matches2.filter((m) => m.sheet === sheet)
27450
27590
  )
27451
27591
  );
27452
- return ctx.run("Replace", "cells", scopes, () => applyReplace(ctx, q, replacement, matches2), {
27453
- ...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
27454
- });
27592
+ const uniqueScopes = scopes.filter(
27593
+ (scope, index2) => scope.kind !== "refs" || scopes.findIndex((entry3) => entry3.kind === "refs") === index2
27594
+ );
27595
+ return ctx.run(
27596
+ "Replace",
27597
+ "cells",
27598
+ uniqueScopes,
27599
+ () => applyReplace(ctx, q, replacement, matches2),
27600
+ {
27601
+ ...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
27602
+ }
27603
+ );
27455
27604
  }
27456
27605
  function replaceOne(ctx, query, replacement, at) {
27457
27606
  const q = replaceQuery(query);
@@ -27464,7 +27613,7 @@ function replaceOne(ctx, query, replacement, at) {
27464
27613
  ctx.run(
27465
27614
  "Replace",
27466
27615
  "cells",
27467
- replaceScopes(q, at.sheet, [match2]),
27616
+ replaceScopes(ctx, q, at.sheet, [match2]),
27468
27617
  () => applyReplace(ctx, q, replacement, [match2]),
27469
27618
  { sheet: at.sheet }
27470
27619
  );
@@ -28467,90 +28616,6 @@ function applyTotalsRow(sheet, table2) {
28467
28616
  });
28468
28617
  }
28469
28618
 
28470
- // xlsx/edit/tables.ts
28471
- function nextTableName(workbook) {
28472
- const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
28473
- const names = new Set(workbook.definedNames.map((n2) => n2.name.toLowerCase()));
28474
- for (let n2 = 1; ; n2++) if (!taken.has(`table${n2}`) && !names.has(`table${n2}`)) return `Table${n2}`;
28475
- }
28476
- function uniqueHeaders(texts) {
28477
- const used = /* @__PURE__ */ new Set();
28478
- return texts.map((text3, i2) => {
28479
- let base = text3.trim() || `Column${i2 + 1}`;
28480
- if (!used.has(base.toLowerCase())) {
28481
- used.add(base.toLowerCase());
28482
- return base;
28483
- }
28484
- for (let n2 = 2; ; n2++) {
28485
- const candidate = `${base}${n2}`;
28486
- if (!used.has(candidate.toLowerCase())) {
28487
- used.add(candidate.toLowerCase());
28488
- base = candidate;
28489
- return base;
28490
- }
28491
- }
28492
- });
28493
- }
28494
- function createTable(ctx, s, range, hasHeader, styleName = "TableStyleMedium2") {
28495
- const { workbook } = ctx;
28496
- const sheet = sheetAt(workbook, s);
28497
- let r = normalizeRange(range);
28498
- if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
28499
- if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
28500
- throw new Error("A table cannot overlap another table.");
28501
- if (sheet.merges.some((m) => rangesIntersect(m, r)))
28502
- throw new Error("A table cannot contain merged cells.");
28503
- return ctx.run(
28504
- "Create table",
28505
- "structure",
28506
- [hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
28507
- () => {
28508
- if (!hasHeader) {
28509
- const shift2 = { axis: "row", at: r.start.row, count: 1 };
28510
- const band = { lo: r.start.col, hi: r.end.col };
28511
- rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
28512
- shiftSheetContent(sheet, shift2, band);
28513
- r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
28514
- }
28515
- const width = r.end.col - r.start.col + 1;
28516
- const texts = Array.from(
28517
- { length: width },
28518
- (_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
28519
- );
28520
- const headers = uniqueHeaders(texts);
28521
- const columns = headers.map((name2, i2) => {
28522
- const cell = getCell(sheet, r.start.row, r.start.col + i2);
28523
- if (cell?.value !== name2) {
28524
- const styleId = cell?.styleId;
28525
- writeValue(sheet, r.start.row, r.start.col + i2, name2);
28526
- const written = getCell(sheet, r.start.row, r.start.col + i2);
28527
- if (written && styleId) written.styleId = styleId;
28528
- }
28529
- return { name: name2 };
28530
- });
28531
- const name = nextTableName(workbook);
28532
- const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
28533
- const table2 = {
28534
- id,
28535
- name,
28536
- displayName: name,
28537
- range: r,
28538
- headerRow: true,
28539
- totalsRow: false,
28540
- columns,
28541
- styleName,
28542
- showRowStripes: true,
28543
- showColumnStripes: false,
28544
- showFirstColumn: false,
28545
- showLastColumn: false
28546
- };
28547
- sheet.tables.push(table2);
28548
- return table2;
28549
- },
28550
- { sheet: s, ranges: [r], structural: !hasHeader }
28551
- );
28552
- }
28553
-
28554
28619
  // xlsx/edit/table-edits.ts
28555
28620
  function tableIndex(sheet, ref) {
28556
28621
  const index2 = typeof ref === "number" ? ref : sheet.tables.findIndex((t) => t.name.toLowerCase() === ref.toLowerCase());
@@ -31806,8 +31871,8 @@ function setSheetState(ctx, index2, state) {
31806
31871
  const { workbook } = ctx;
31807
31872
  const sheet = sheetAt(workbook, index2);
31808
31873
  if (sheet.state === state) return;
31874
+ assertUnlocked(workbook);
31809
31875
  if (state !== "visible") {
31810
- assertUnlocked(workbook);
31811
31876
  if (sheet.state === "visible" && visibleCount(workbook) <= 1)
31812
31877
  throw new Error("A workbook must contain at least one visible sheet.");
31813
31878
  }
@@ -31837,6 +31902,72 @@ function setTabColor(ctx, index2, color) {
31837
31902
  );
31838
31903
  }
31839
31904
 
31905
+ // xlsx/edit/tables.ts
31906
+ function nextTableName(workbook) {
31907
+ const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
31908
+ const names = new Set(workbook.definedNames.map((n2) => n2.name.toLowerCase()));
31909
+ for (let n2 = 1; ; n2++) if (!taken.has(`table${n2}`) && !names.has(`table${n2}`)) return `Table${n2}`;
31910
+ }
31911
+ function createTable(ctx, s, range, hasHeader, styleName = "TableStyleMedium2") {
31912
+ const { workbook } = ctx;
31913
+ const sheet = sheetAt(workbook, s);
31914
+ let r = normalizeRange(range);
31915
+ if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
31916
+ if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
31917
+ throw new Error("A table cannot overlap another table.");
31918
+ if (sheet.merges.some((m) => rangesIntersect(m, r)))
31919
+ throw new Error("A table cannot contain merged cells.");
31920
+ return ctx.run(
31921
+ "Create table",
31922
+ "structure",
31923
+ [hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
31924
+ () => {
31925
+ if (!hasHeader) {
31926
+ const shift2 = { axis: "row", at: r.start.row, count: 1 };
31927
+ const band = { lo: r.start.col, hi: r.end.col };
31928
+ rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
31929
+ shiftSheetContent(sheet, shift2, band);
31930
+ r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
31931
+ }
31932
+ const width = r.end.col - r.start.col + 1;
31933
+ const texts = Array.from(
31934
+ { length: width },
31935
+ (_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
31936
+ );
31937
+ const headers = uniqueHeaders(texts);
31938
+ const columns = headers.map((name2, i2) => {
31939
+ const cell = getCell(sheet, r.start.row, r.start.col + i2);
31940
+ if (cell?.value !== name2) {
31941
+ const styleId = cell?.styleId;
31942
+ writeValue(sheet, r.start.row, r.start.col + i2, name2);
31943
+ const written = getCell(sheet, r.start.row, r.start.col + i2);
31944
+ if (written && styleId) written.styleId = styleId;
31945
+ }
31946
+ return { name: name2 };
31947
+ });
31948
+ const name = nextTableName(workbook);
31949
+ const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
31950
+ const table2 = {
31951
+ id,
31952
+ name,
31953
+ displayName: name,
31954
+ range: r,
31955
+ headerRow: true,
31956
+ totalsRow: false,
31957
+ columns,
31958
+ styleName,
31959
+ showRowStripes: true,
31960
+ showColumnStripes: false,
31961
+ showFirstColumn: false,
31962
+ showLastColumn: false
31963
+ };
31964
+ sheet.tables.push(table2);
31965
+ return table2;
31966
+ },
31967
+ { sheet: s, ranges: [r], structural: !hasHeader }
31968
+ );
31969
+ }
31970
+
31840
31971
  // xlsx/edit/validation-list.ts
31841
31972
  function listSource(workbook, sheet, formula, evaluate, at, depth = 0) {
31842
31973
  const text3 = formula.replace(/^=/, "").trim();
@@ -32138,7 +32269,7 @@ function createEditSession(workbook, options = {}) {
32138
32269
  const befores = scopes.map((scope) => captureScope(workbook, scope));
32139
32270
  let result2;
32140
32271
  try {
32141
- result2 = fn();
32272
+ result2 = fn(befores.find((snapshot) => snapshot.kind === "refs")?.data.formulas);
32142
32273
  } catch (error) {
32143
32274
  for (let i2 = befores.length - 1; i2 >= 0; i2--) {
32144
32275
  const snapshot = befores[i2];