ooxml-core 1.15.0 → 1.16.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 (102) hide show
  1. package/dist/PptxHandler-3A7VEXVK.cjs +13 -0
  2. package/dist/PptxHandler-7POULDRL.mjs +4 -0
  3. package/dist/{PptxHandler-R5BVKEBW.mjs → PptxHandler-M35YFCUC.mjs} +2 -2
  4. package/dist/PresentationBuilder-C7NPM7OQ.mjs +4 -0
  5. package/dist/{PresentationBuilder-4AF3PZHG.cjs → PresentationBuilder-XVRTITYR.cjs} +6 -5
  6. package/dist/{PresentationBuilder-W67DIJBV.mjs → PresentationBuilder-Y6DJK6H2.mjs} +2 -2
  7. package/dist/automation/index.cjs +935 -535
  8. package/dist/automation/index.mjs +935 -535
  9. package/dist/chunk-5W2QL4SB.cjs +244 -0
  10. package/dist/{chunk-ZWI7MTLF.cjs → chunk-AHRFBMLK.cjs} +2846 -1546
  11. package/dist/{chunk-NWAQEXBK.mjs → chunk-B37EVUMG.mjs} +1 -1
  12. package/dist/{chunk-HU36GIYM.mjs → chunk-C2Y6SZDN.mjs} +421 -129
  13. package/dist/chunk-CA7KCNL3.mjs +236 -0
  14. package/dist/{chunk-BSUIDT6K.cjs → chunk-DWRJ62KP.cjs} +1 -0
  15. package/dist/{chunk-OPBZBSJF.mjs → chunk-KOX5Y5E5.mjs} +1 -1
  16. package/dist/{chunk-JFMIPOPV.mjs → chunk-LM6VBPQJ.mjs} +416 -15
  17. package/dist/{chunk-PC4MTLG4.cjs → chunk-OA5V3JJC.cjs} +8 -8
  18. package/dist/{chunk-7ZIZFJXT.mjs → chunk-OKGQ2X7D.mjs} +1848 -548
  19. package/dist/{chunk-X7MGZQ6C.cjs → chunk-UGWY72WC.cjs} +396 -254
  20. package/dist/{chunk-EMZIHAOH.mjs → chunk-WBCV52YV.mjs} +1846 -565
  21. package/dist/{chunk-2EBMHIGJ.mjs → chunk-WEFFRYXN.mjs} +379 -242
  22. package/dist/{chunk-AXF2FC4D.mjs → chunk-WSRCLCMB.mjs} +1 -0
  23. package/dist/{chunk-LMMP67YN.mjs → chunk-XCJRUBGJ.mjs} +1 -1
  24. package/dist/pptx/automation/index.cjs +2662 -884
  25. package/dist/pptx/automation/index.d.ts +4 -4
  26. package/dist/pptx/automation/index.mjs +5 -5
  27. package/dist/pptx/chunks/{elements-Cadkqht8.d.ts → elements-iUzpAeqR.d.ts} +114 -25
  28. package/dist/pptx/chunks/elements-iUzpAeqR.d.ts.map +1 -0
  29. package/dist/pptx/chunks/{index-CJI2EugA.d.ts → index-BWHNCVNC.d.ts} +1671 -1534
  30. package/dist/pptx/chunks/index-BWHNCVNC.d.ts.map +1 -0
  31. package/dist/pptx/chunks/{index-CozqpSPL.d.ts → index-CiyTR6mm.d.ts} +99 -10
  32. package/dist/pptx/chunks/index-CiyTR6mm.d.ts.map +1 -0
  33. package/dist/pptx/chunks/{text-operations-C3L9xrqx.d.ts → text-operations-CfLVZ7DK.d.ts} +81 -3
  34. package/dist/pptx/chunks/text-operations-CfLVZ7DK.d.ts.map +1 -0
  35. package/dist/pptx/cli/index.cjs +2652 -874
  36. package/dist/pptx/cli/index.d.ts +1 -1
  37. package/dist/pptx/cli/index.mjs +4 -4
  38. package/dist/pptx/converter/index.cjs +45 -1
  39. package/dist/pptx/converter/index.d.ts +1 -1
  40. package/dist/pptx/converter/index.mjs +2 -2
  41. package/dist/pptx/editor/render/collaboration-live-patch-target.cjs +4 -4
  42. package/dist/pptx/editor/render/collaboration-live-patch-target.mjs +2 -2
  43. package/dist/pptx/editor/render/collaboration-reconcile.cjs +7 -7
  44. package/dist/pptx/editor/render/collaboration-reconcile.mjs +2 -2
  45. package/dist/pptx/editor/render/collaboration-sync.cjs +14 -14
  46. package/dist/pptx/editor/render/collaboration-sync.d.ts.map +1 -1
  47. package/dist/pptx/editor/render/collaboration-sync.mjs +1 -1
  48. package/dist/pptx/editor/render/find-replace.cjs +15 -14
  49. package/dist/pptx/editor/render/find-replace.d.ts +2 -2
  50. package/dist/pptx/editor/render/find-replace.mjs +2 -1
  51. package/dist/pptx/editor/render/slide-operations.cjs +9 -8
  52. package/dist/pptx/editor/render/slide-operations.mjs +3 -2
  53. package/dist/pptx/editor/render/slide-size-rescale.cjs +3 -3
  54. package/dist/pptx/editor/render/slide-size-rescale.d.ts +1 -1
  55. package/dist/pptx/editor/render/slide-size-rescale.d.ts.map +1 -1
  56. package/dist/pptx/editor/render/slide-size-rescale.mjs +3 -3
  57. package/dist/pptx/editor/render/text-runs-style-patch.d.ts +1 -1
  58. package/dist/pptx/editor/render/text-style-scope.d.ts +1 -1
  59. package/dist/pptx/index.cjs +3208 -1106
  60. package/dist/pptx/index.d.ts +5 -5
  61. package/dist/pptx/index.mjs +5 -5
  62. package/dist/teams/index.cjs +156 -65
  63. package/dist/teams/index.mjs +156 -65
  64. package/dist/xlsx/edit/pivots.d.ts.map +1 -1
  65. package/dist/xlsx/index.cjs +867 -467
  66. package/dist/xlsx/index.mjs +867 -467
  67. package/dist/xlsx/load/index.cjs +345 -99
  68. package/dist/xlsx/load/index.mjs +345 -99
  69. package/dist/xlsx/model-pivots.d.ts +47 -0
  70. package/dist/xlsx/model-pivots.d.ts.map +1 -1
  71. package/dist/xlsx/pivot/captions-locales.d.ts +3 -0
  72. package/dist/xlsx/pivot/captions-locales.d.ts.map +1 -0
  73. package/dist/xlsx/pivot/captions-read.d.ts +14 -0
  74. package/dist/xlsx/pivot/captions-read.d.ts.map +1 -0
  75. package/dist/xlsx/pivot/captions.d.ts +26 -0
  76. package/dist/xlsx/pivot/captions.d.ts.map +1 -0
  77. package/dist/xlsx/pivot/columns.d.ts.map +1 -1
  78. package/dist/xlsx/pivot/data.d.ts +3 -2
  79. package/dist/xlsx/pivot/data.d.ts.map +1 -1
  80. package/dist/xlsx/pivot/item-labels.d.ts +12 -0
  81. package/dist/xlsx/pivot/item-labels.d.ts.map +1 -0
  82. package/dist/xlsx/pivot/item-names-read.d.ts +8 -0
  83. package/dist/xlsx/pivot/item-names-read.d.ts.map +1 -0
  84. package/dist/xlsx/pivot/measures.d.ts +2 -1
  85. package/dist/xlsx/pivot/measures.d.ts.map +1 -1
  86. package/dist/xlsx/pivot/nested.d.ts.map +1 -1
  87. package/dist/xlsx/pivot/page-filter-admission.d.ts.map +1 -1
  88. package/dist/xlsx/pivot/page-filter.d.ts +1 -1
  89. package/dist/xlsx/pivot/page-filter.d.ts.map +1 -1
  90. package/dist/xlsx/pivot/read.d.ts.map +1 -1
  91. package/dist/xlsx/pivot/table-xml.d.ts.map +1 -1
  92. package/dist/xlsx/ui/commands/i18n/navigation.d.ts.map +1 -1
  93. package/dist/xlsx/ui/index.cjs +800 -621
  94. package/dist/xlsx/ui/index.mjs +800 -621
  95. package/package.json +1 -1
  96. package/dist/PptxHandler-OGLITB3F.cjs +0 -12
  97. package/dist/PptxHandler-UKAA5T5U.mjs +0 -3
  98. package/dist/PresentationBuilder-54QGEZ2F.mjs +0 -3
  99. package/dist/pptx/chunks/elements-Cadkqht8.d.ts.map +0 -1
  100. package/dist/pptx/chunks/index-CJI2EugA.d.ts.map +0 -1
  101. package/dist/pptx/chunks/index-CozqpSPL.d.ts.map +0 -1
  102. package/dist/pptx/chunks/text-operations-C3L9xrqx.d.ts.map +0 -1
@@ -75,7 +75,7 @@ var DEFAULT_XML_LIMITS = {
75
75
  maxNodes: 5e6
76
76
  };
77
77
  var MARKUP_RE = /<!--[\s\S]*?-->|<!\[CDATA\[[\s\S]*?\]\]>|<\?[\s\S]*?\?>|<(\/?)([^\s\/>]+)(?:\s+[^\s=\/>]+\s*=\s*(?:"[^"]*"|'[^']*'))*\s*(\/?)>/g;
78
- function checkXmlLimits(xml, label4, limits = {}) {
78
+ function checkXmlLimits(xml, label2, limits = {}) {
79
79
  const maxDepth = limits.maxDepth ?? DEFAULT_XML_LIMITS.maxDepth;
80
80
  const maxNodes = limits.maxNodes ?? DEFAULT_XML_LIMITS.maxNodes;
81
81
  let depth = 0;
@@ -88,16 +88,16 @@ function checkXmlLimits(xml, label4, limits = {}) {
88
88
  continue;
89
89
  }
90
90
  nodes++;
91
- if (nodes > maxNodes) throw new Error(`${label4} XML exceeds the limit of ${maxNodes} elements`);
91
+ if (nodes > maxNodes) throw new Error(`${label2} XML exceeds the limit of ${maxNodes} elements`);
92
92
  if (!selfClosing && ++depth > maxDepth)
93
- throw new Error(`${label4} XML exceeds the nesting depth limit of ${maxDepth}`);
93
+ throw new Error(`${label2} XML exceeds the nesting depth limit of ${maxDepth}`);
94
94
  }
95
95
  }
96
96
  function parseXml(xml, options = {}) {
97
- const label4 = options.label ?? "OOXML";
97
+ const label2 = options.label ?? "OOXML";
98
98
  if (/<!DOCTYPE|<!ENTITY/i.test(xml))
99
- throw new Error(`${label4} XML with DTD or entity declarations is not supported`);
100
- checkXmlLimits(xml, label4, options.limits);
99
+ throw new Error(`${label2} XML with DTD or entity declarations is not supported`);
100
+ checkXmlLimits(xml, label2, options.limits);
101
101
  let parseError = "";
102
102
  let parsed;
103
103
  try {
@@ -108,12 +108,12 @@ function parseXml(xml, options = {}) {
108
108
  }).parseFromString(xml, "application/xml");
109
109
  } catch (error) {
110
110
  throw new Error(
111
- `Invalid ${label4} XML: ${error instanceof Error ? error.message : String(error)}`,
111
+ `Invalid ${label2} XML: ${error instanceof Error ? error.message : String(error)}`,
112
112
  { cause: error }
113
113
  );
114
114
  }
115
115
  if (parseError || !parsed.documentElement)
116
- throw new Error(`Invalid ${label4} XML: ${parseError || "missing root element"}`);
116
+ throw new Error(`Invalid ${label2} XML: ${parseError || "missing root element"}`);
117
117
  return parsed;
118
118
  }
119
119
  var buildXml = (node3) => new XMLSerializer().serializeToString(node3);
@@ -400,10 +400,10 @@ function withParseWarnings(warnings, fn) {
400
400
  function reportParseWarning(message) {
401
401
  if (sink && !sink.includes(message)) sink.push(message);
402
402
  }
403
- function enumValue(guard2, raw2, label4) {
403
+ function enumValue(guard2, raw2, label2) {
404
404
  if (raw2 === null || raw2 === void 0 || raw2 === "") return void 0;
405
405
  if (guard2(raw2)) return raw2;
406
- reportParseWarning(`Ignored invalid ${label4} value \u201C${raw2}\u201D; it is not allowed by the schema.`);
406
+ reportParseWarning(`Ignored invalid ${label2} value \u201C${raw2}\u201D; it is not allowed by the schema.`);
407
407
  return void 0;
408
408
  }
409
409
 
@@ -2292,7 +2292,7 @@ function flatChildren(parent, names, level = "block", enclosing, controls3 = /*
2292
2292
  return found;
2293
2293
  }
2294
2294
  var flatBlocks = (container) => flatChildren(container, ["p", "tbl"]);
2295
- var flatRows = (table3) => flatChildren(table3, ["tr"], "row");
2295
+ var flatRows = (table4) => flatChildren(table4, ["tr"], "row");
2296
2296
  var flatCells = (row3) => flatChildren(row3, ["tc"], "cell");
2297
2297
  var flatCellParagraphs = (cell) => flatChildren(cell, ["p"]);
2298
2298
 
@@ -3005,42 +3005,42 @@ function buildMargins(doc, margins, tag) {
3005
3005
  }
3006
3006
  return element2.childNodes.length ? element2 : void 0;
3007
3007
  }
3008
- function tableJustification(table3) {
3009
- const { alignment, justification } = table3;
3008
+ function tableJustification(table4) {
3009
+ const { alignment, justification } = table4;
3010
3010
  const implied = justification === "start" ? "left" : justification === "end" ? "right" : justification;
3011
3011
  return justification && implied === alignment ? justification : alignment;
3012
3012
  }
3013
- function tableColumnCount(table3) {
3013
+ function tableColumnCount(table4) {
3014
3014
  return Math.max(
3015
3015
  1,
3016
- ...table3.rows.map((row3) => row3.reduce((sum3, cell) => sum3 + (cell.gridSpan ?? 1), 0))
3016
+ ...table4.rows.map((row3) => row3.reduce((sum3, cell) => sum3 + (cell.gridSpan ?? 1), 0))
3017
3017
  );
3018
3018
  }
3019
- function buildNewTableProperties(doc, table3, contentWidthTwips) {
3019
+ function buildNewTableProperties(doc, table4, contentWidthTwips) {
3020
3020
  const tblPr = makeW(doc, "tblPr");
3021
- if (table3.style) {
3021
+ if (table4.style) {
3022
3022
  const style3 = makeW(doc, "tblStyle");
3023
- setW2(style3, "val", table3.style);
3023
+ setW2(style3, "val", table4.style);
3024
3024
  tblPr.appendChild(style3);
3025
3025
  }
3026
3026
  const width = makeW(doc, "tblW");
3027
- setW2(width, "w", String(table3.widthTwips ?? 0));
3028
- setW2(width, "type", table3.widthTwips ? "dxa" : "auto");
3027
+ setW2(width, "w", String(table4.widthTwips ?? 0));
3028
+ setW2(width, "type", table4.widthTwips ? "dxa" : "auto");
3029
3029
  tblPr.appendChild(width);
3030
- const jcValue = tableJustification(table3);
3030
+ const jcValue = tableJustification(table4);
3031
3031
  if (jcValue) {
3032
3032
  const jc = makeW(doc, "jc");
3033
3033
  setW2(jc, "val", jcValue);
3034
3034
  tblPr.appendChild(jc);
3035
3035
  }
3036
- if (table3.indentTwips !== void 0) {
3036
+ if (table4.indentTwips !== void 0) {
3037
3037
  const indent = makeW(doc, "tblInd");
3038
- setW2(indent, "w", String(table3.indentTwips));
3038
+ setW2(indent, "w", String(table4.indentTwips));
3039
3039
  setW2(indent, "type", "dxa");
3040
3040
  tblPr.appendChild(indent);
3041
3041
  }
3042
- if (table3.borders) tblPr.appendChild(buildBorders(doc, table3.borders, "tblBorders"));
3043
- const margins = table3.cellMargins && buildMargins(doc, table3.cellMargins, "tblCellMar");
3042
+ if (table4.borders) tblPr.appendChild(buildBorders(doc, table4.borders, "tblBorders"));
3043
+ const margins = table4.cellMargins && buildMargins(doc, table4.cellMargins, "tblCellMar");
3044
3044
  if (margins) tblPr.appendChild(margins);
3045
3045
  const look = makeW(doc, "tblLook");
3046
3046
  const lookAttributes = [
@@ -3055,8 +3055,8 @@ function buildNewTableProperties(doc, table3, contentWidthTwips) {
3055
3055
  for (const [name3, value2] of lookAttributes) setW2(look, name3, value2);
3056
3056
  tblPr.appendChild(look);
3057
3057
  const tblGrid = makeW(doc, "tblGrid");
3058
- const columns = tableColumnCount(table3);
3059
- const widths = table3.grid?.length === columns ? table3.grid : Array.from({ length: columns }, () => Math.max(1, Math.floor(contentWidthTwips / columns)));
3058
+ const columns = tableColumnCount(table4);
3059
+ const widths = table4.grid?.length === columns ? table4.grid : Array.from({ length: columns }, () => Math.max(1, Math.floor(contentWidthTwips / columns)));
3060
3060
  for (const value2 of widths) {
3061
3061
  const column2 = makeW(doc, "gridCol");
3062
3062
  setW2(column2, "w", String(value2));
@@ -3304,14 +3304,14 @@ function patchRowProperties(doc, tr, next, base2) {
3304
3304
  }
3305
3305
  orderChildren(props, ROW_ORDER);
3306
3306
  }
3307
- function patchTableMargins(doc, table3, node3, base2) {
3307
+ function patchTableMargins(doc, table4, node3, base2) {
3308
3308
  patchMarginProperties(
3309
3309
  doc,
3310
3310
  node3,
3311
3311
  "tblPr",
3312
3312
  "tblCellMar",
3313
3313
  TABLE_ORDER,
3314
- table3.cellMargins,
3314
+ table4.cellMargins,
3315
3315
  base2?.cellMargins
3316
3316
  );
3317
3317
  }
@@ -3406,12 +3406,12 @@ function patchCellShading(doc, tc, next, base2) {
3406
3406
  }
3407
3407
 
3408
3408
  // docx/write-table.ts
3409
- function canEditTableStructure(table3) {
3409
+ function canEditTableStructure(table4) {
3410
3410
  const only = (parent, allowed) => Array.from(parent.childNodes).filter(isElement).every((node3) => allowed.some((name3) => named2(node3, name3)));
3411
- if (!only(table3, ["tblPr", "tblGrid", "tr"])) return false;
3412
- const grid = first2(table3, "tblGrid");
3411
+ if (!only(table4, ["tblPr", "tblGrid", "tr"])) return false;
3412
+ const grid = first2(table4, "tblGrid");
3413
3413
  if (grid && !only(grid, ["gridCol"])) return false;
3414
- const rows = children2(table3, "tr");
3414
+ const rows = children2(table4, "tr");
3415
3415
  if (!rows.length) return false;
3416
3416
  const [firstRow] = rows;
3417
3417
  if (!firstRow) return false;
@@ -3437,7 +3437,7 @@ function canEditTableStructure(table3) {
3437
3437
  }
3438
3438
  return true;
3439
3439
  }
3440
- var layout = (table3) => table3.rows.map((row3) => row3.map((cell) => cell.paragraphs.map((p) => p.id)));
3440
+ var layout = (table4) => table4.rows.map((row3) => row3.map((cell) => cell.paragraphs.map((p) => p.id)));
3441
3441
  var TABLE_DESCRIPTOR_KEYS = [
3442
3442
  "grid",
3443
3443
  "widthTwips",
@@ -3454,9 +3454,9 @@ function pick(source2, keys) {
3454
3454
  for (const key2 of keys) if (record2[key2] !== void 0) result2[key2] = record2[key2];
3455
3455
  return result2;
3456
3456
  }
3457
- function assertNoDescriptorEdits(table3, base2) {
3457
+ function assertNoDescriptorEdits(table4, base2) {
3458
3458
  if (!base2) return;
3459
- if (JSON.stringify(pick(table3, TABLE_DESCRIPTOR_KEYS)) !== JSON.stringify(pick(base2, TABLE_DESCRIPTOR_KEYS)))
3459
+ if (JSON.stringify(pick(table4, TABLE_DESCRIPTOR_KEYS)) !== JSON.stringify(pick(base2, TABLE_DESCRIPTOR_KEYS)))
3460
3460
  throw new Error(
3461
3461
  "Cannot edit table grid widths, width, alignment, indent, borders, or style; only cell text and row/column structure changes are supported. The original DOCX package remains unchanged."
3462
3462
  );
@@ -3466,7 +3466,7 @@ function assertNoDescriptorEdits(table3, base2) {
3466
3466
  const id3 = cell.paragraphs[0]?.id;
3467
3467
  if (id3) baseCellById.set(id3, cell);
3468
3468
  }
3469
- for (const row3 of table3.rows)
3469
+ for (const row3 of table4.rows)
3470
3470
  for (const cell of row3) {
3471
3471
  const id3 = cell.paragraphs[0]?.id;
3472
3472
  const source2 = id3 ? baseCellById.get(id3) : void 0;
@@ -3482,23 +3482,23 @@ function writeNestedTables(doc, tc, cell, base2, writeParagraph, replaceSlots2)
3482
3482
  const next = tables(cell.sourceBlocks);
3483
3483
  const before = tables(base2?.sourceBlocks);
3484
3484
  const nodes = children2(tc, "tbl");
3485
- next.forEach((table3, index3) => {
3485
+ next.forEach((table4, index3) => {
3486
3486
  const node3 = nodes[index3];
3487
3487
  if (node3 && before[index3])
3488
- writeTable(doc, table3, node3, before[index3], writeParagraph, replaceSlots2);
3488
+ writeTable(doc, table4, node3, before[index3], writeParagraph, replaceSlots2);
3489
3489
  });
3490
3490
  }
3491
- function writeTable(doc, table3, node3, base2, writeParagraph, replaceSlots2) {
3492
- if (base2 && JSON.stringify(table3) === JSON.stringify(base2)) return node3;
3493
- assertNoDescriptorEdits(table3, base2);
3494
- patchTableMargins(doc, table3, node3, base2);
3495
- const structural = base2 && JSON.stringify(layout(table3)) !== JSON.stringify(layout(base2));
3491
+ function writeTable(doc, table4, node3, base2, writeParagraph, replaceSlots2) {
3492
+ if (base2 && JSON.stringify(table4) === JSON.stringify(base2)) return node3;
3493
+ assertNoDescriptorEdits(table4, base2);
3494
+ patchTableMargins(doc, table4, node3, base2);
3495
+ const structural = base2 && JSON.stringify(layout(table4)) !== JSON.stringify(layout(base2));
3496
3496
  if (structural && !canEditTableStructure(node3))
3497
3497
  throw new Error(
3498
3498
  "Cannot change the structure of a merged, nested, or complex table. The original DOCX package remains unchanged."
3499
3499
  );
3500
- const width = table3.rows[0]?.length ?? 0;
3501
- if (!width || table3.rows.some((row3) => row3.length !== width || row3.some((cell) => !cell.paragraphs.length)))
3500
+ const width = table4.rows[0]?.length ?? 0;
3501
+ if (!width || table4.rows.some((row3) => row3.length !== width || row3.some((cell) => !cell.paragraphs.length)))
3502
3502
  throw new Error("Tables must contain rectangular rows and at least one paragraph per cell.");
3503
3503
  const oldRows = flatRows(node3).map((entry3) => entry3.element);
3504
3504
  const sourceById = /* @__PURE__ */ new Map();
@@ -3519,7 +3519,7 @@ function writeTable(doc, table3, node3, base2, writeParagraph, replaceSlots2) {
3519
3519
  const usedCells = /* @__PURE__ */ new Set();
3520
3520
  const usedRows = /* @__PURE__ */ new Set();
3521
3521
  const columns = /* @__PURE__ */ new Map();
3522
- const nextRows = table3.rows.map((row3, rowIndex2) => {
3522
+ const nextRows = table4.rows.map((row3, rowIndex2) => {
3523
3523
  const sources = row3.map(
3524
3524
  (cell) => cell.paragraphs.map((p) => sourceById.get(p.id)).find(Boolean)
3525
3525
  );
@@ -3534,7 +3534,7 @@ function writeTable(doc, table3, node3, base2, writeParagraph, replaceSlots2) {
3534
3534
  patchRowProperties(
3535
3535
  doc,
3536
3536
  tr,
3537
- table3.rowProperties?.[rowIndex2],
3537
+ table4.rowProperties?.[rowIndex2],
3538
3538
  sourceRow === void 0 ? void 0 : base2?.rowProperties?.[sourceRow]
3539
3539
  );
3540
3540
  const nextCells = row3.map((cell, ci) => {
@@ -11560,8 +11560,8 @@ function gd14(name3, formula) {
11560
11560
  const parts = formula.trim().split(/\s+/);
11561
11561
  return { name: name3, formula, args: parts.slice(1) };
11562
11562
  }
11563
- function parseGdTable(table3) {
11564
- return table3.trim().split(/[\n;]/).filter((entry3) => entry3.length > 0).map((entry3) => {
11563
+ function parseGdTable(table4) {
11564
+ return table4.trim().split(/[\n;]/).filter((entry3) => entry3.length > 0).map((entry3) => {
11565
11565
  const sep = entry3.indexOf("|");
11566
11566
  return gd14(entry3.slice(0, sep), entry3.slice(sep + 1));
11567
11567
  });
@@ -13454,8 +13454,8 @@ function parseDiagramDataModel(source2, part) {
13454
13454
  "CONNECTION_ENDPOINT_MISSING",
13455
13455
  `dgm:cxn ${attribute4} references missing point: ${id3}.`
13456
13456
  );
13457
- const label4 = connectionLabel(connection, transitionText);
13458
- connections2.push(label4 ? { ...connection, label: label4 } : connection);
13457
+ const label2 = connectionLabel(connection, transitionText);
13458
+ connections2.push(label2 ? { ...connection, label: label2 } : connection);
13459
13459
  if ((!connection.type || connection.type === "parOf") && !parentById.has(connection.destId))
13460
13460
  parentById.set(connection.destId, connection.sourceId);
13461
13461
  }
@@ -13494,14 +13494,14 @@ function colorList(container) {
13494
13494
  }
13495
13495
  function parseDiagramColors(source2) {
13496
13496
  const root = rootOf2(source2);
13497
- const labels = children(root, "styleLbl", NS.dgm).map((label4) => ({
13498
- name: stringAttribute(label4, "name") ?? "",
13499
- fill: colorList(first(label4, "fillClrLst", NS.dgm)),
13500
- line: colorList(first(label4, "linClrLst", NS.dgm)),
13501
- effect: colorList(first(label4, "effectClrLst", NS.dgm)),
13502
- textLine: colorList(first(label4, "txLinClrLst", NS.dgm)),
13503
- textFill: colorList(first(label4, "txFillClrLst", NS.dgm)),
13504
- textEffect: colorList(first(label4, "txEffectClrLst", NS.dgm))
13497
+ const labels = children(root, "styleLbl", NS.dgm).map((label2) => ({
13498
+ name: stringAttribute(label2, "name") ?? "",
13499
+ fill: colorList(first(label2, "fillClrLst", NS.dgm)),
13500
+ line: colorList(first(label2, "linClrLst", NS.dgm)),
13501
+ effect: colorList(first(label2, "effectClrLst", NS.dgm)),
13502
+ textLine: colorList(first(label2, "txLinClrLst", NS.dgm)),
13503
+ textFill: colorList(first(label2, "txFillClrLst", NS.dgm)),
13504
+ textEffect: colorList(first(label2, "txEffectClrLst", NS.dgm))
13505
13505
  }));
13506
13506
  return { ...parseDefinitionHeader(root), labels };
13507
13507
  }
@@ -13534,16 +13534,16 @@ function parseStyleReferences(style3) {
13534
13534
  var hasContent = (element2) => Boolean(element2 && (element2.attributes.length > 0 || elements(element2).length > 0));
13535
13535
  function parseDiagramQuickStyle(source2) {
13536
13536
  const root = rootOf2(source2);
13537
- const labels = children(root, "styleLbl", NS.dgm).map((label4) => ({
13538
- name: stringAttribute(label4, "name") ?? "",
13539
- ...parseStyleReferences(first(label4, "style", NS.dgm)),
13540
- hasScene3d: Boolean(first(label4, "scene3d", NS.dgm)),
13541
- hasShape3d: hasContent(first(label4, "sp3d", NS.dgm))
13537
+ const labels = children(root, "styleLbl", NS.dgm).map((label2) => ({
13538
+ name: stringAttribute(label2, "name") ?? "",
13539
+ ...parseStyleReferences(first(label2, "style", NS.dgm)),
13540
+ hasScene3d: Boolean(first(label2, "scene3d", NS.dgm)),
13541
+ hasShape3d: hasContent(first(label2, "sp3d", NS.dgm))
13542
13542
  }));
13543
13543
  return {
13544
13544
  ...parseDefinitionHeader(root),
13545
13545
  labels,
13546
- has3d: labels.some((label4) => label4.hasShape3d)
13546
+ has3d: labels.some((label2) => label2.hasShape3d)
13547
13547
  };
13548
13548
  }
13549
13549
  function parseDiagramLayoutSummary(source2) {
@@ -14713,10 +14713,10 @@ function parseDisplayUnits(context, element2) {
14713
14713
  if (!element2) return void 0;
14714
14714
  reportUnmodelled(context, element2, DISPLAY_UNITS);
14715
14715
  const labelElement = cChild(element2, "dispUnitsLbl");
14716
- let label4;
14716
+ let label2;
14717
14717
  if (labelElement) {
14718
14718
  reportUnmodelled(context, labelElement, DISPLAY_UNITS_LABEL);
14719
- label4 = assignDefined(
14719
+ label2 = assignDefined(
14720
14720
  {},
14721
14721
  {
14722
14722
  layout: manualLayout(labelElement),
@@ -14731,7 +14731,7 @@ function parseDisplayUnits(context, element2) {
14731
14731
  {
14732
14732
  builtInUnit: cVal(element2, "builtInUnit"),
14733
14733
  customUnit: cNumber(context, element2, "custUnit"),
14734
- label: label4,
14734
+ label: label2,
14735
14735
  extLst: extensionList2(element2)
14736
14736
  }
14737
14737
  );
@@ -15585,10 +15585,10 @@ function titleXml(context, title) {
15585
15585
  function labelOptionsXml(context, options) {
15586
15586
  return numberFormatXml(options.numberFormat) + shapePropertiesXml(context, options.spPr) + textBodyXml(context, options.txPr) + valXml("dLblPos", options.position) + valXml("showLegendKey", options.showLegendKey) + valXml("showVal", options.showValue) + valXml("showCatName", options.showCategoryName) + valXml("showSerName", options.showSeriesName) + valXml("showPercent", options.showPercent) + valXml("showBubbleSize", options.showBubbleSize) + (options.separator === void 0 ? "" : textElement("separator", options.separator));
15587
15587
  }
15588
- function labelXml(context, label4) {
15588
+ function labelXml(context, label2) {
15589
15589
  return elementXml(
15590
15590
  "dLbl",
15591
- valXml("idx", label4.index) + valXml("delete", label4.deleted) + layoutXml(context, label4.layout) + chartTextXml(context, label4.tx, false) + labelOptionsXml(context, label4) + raw(context, label4.extLst)
15591
+ valXml("idx", label2.index) + valXml("delete", label2.deleted) + layoutXml(context, label2.layout) + chartTextXml(context, label2.tx, false) + labelOptionsXml(context, label2) + raw(context, label2.extLst)
15592
15592
  );
15593
15593
  }
15594
15594
  function dataLabelsXml(context, labels) {
@@ -15596,7 +15596,7 @@ function dataLabelsXml(context, labels) {
15596
15596
  const leaderLines = labels.leaderLines ? elementXml("leaderLines", shapePropertiesXml(context, labels.leaderLines.spPr)) : "";
15597
15597
  return elementXml(
15598
15598
  "dLbls",
15599
- labels.labels.map((label4) => labelXml(context, label4)).join("") + valXml("delete", labels.deleted) + labelOptionsXml(context, labels) + valXml("showLeaderLines", labels.showLeaderLines) + leaderLines + raw(context, labels.extLst)
15599
+ labels.labels.map((label2) => labelXml(context, label2)).join("") + valXml("delete", labels.deleted) + labelOptionsXml(context, labels) + valXml("showLeaderLines", labels.showLeaderLines) + leaderLines + raw(context, labels.extLst)
15600
15600
  );
15601
15601
  }
15602
15602
 
@@ -15608,21 +15608,21 @@ function surfaceXml(context, local, surface) {
15608
15608
  valXml("thickness", surface.thickness) + shapePropertiesXml(context, surface.spPr) + raw(context, surface.pictureOptionsXml) + raw(context, surface.extLst)
15609
15609
  );
15610
15610
  }
15611
- function dataTableXml(context, table3) {
15612
- if (!table3) return "";
15611
+ function dataTableXml(context, table4) {
15612
+ if (!table4) return "";
15613
15613
  return elementXml(
15614
15614
  "dTable",
15615
- valXml("showHorzBorder", table3.showHorizontalBorder) + valXml("showVertBorder", table3.showVerticalBorder) + valXml("showOutline", table3.showOutline) + valXml("showKeys", table3.showKeys) + shapePropertiesXml(context, table3.spPr) + textBodyXml(context, table3.txPr) + raw(context, table3.extLst)
15615
+ valXml("showHorzBorder", table4.showHorizontalBorder) + valXml("showVertBorder", table4.showVerticalBorder) + valXml("showOutline", table4.showOutline) + valXml("showKeys", table4.showKeys) + shapePropertiesXml(context, table4.spPr) + textBodyXml(context, table4.txPr) + raw(context, table4.extLst)
15616
15616
  );
15617
15617
  }
15618
15618
  function displayUnitsXml(context, units2) {
15619
15619
  if (!units2) return "";
15620
- const label4 = units2.label;
15620
+ const label2 = units2.label;
15621
15621
  return elementXml(
15622
15622
  "dispUnits",
15623
- valXml("custUnit", units2.customUnit) + (units2.customUnit === void 0 ? valXml("builtInUnit", units2.builtInUnit) : "") + (label4 ? elementXml(
15623
+ valXml("custUnit", units2.customUnit) + (units2.customUnit === void 0 ? valXml("builtInUnit", units2.builtInUnit) : "") + (label2 ? elementXml(
15624
15624
  "dispUnitsLbl",
15625
- layoutXml(context, label4.layout) + chartTextXml(context, label4.tx, false) + shapePropertiesXml(context, label4.spPr) + textBodyXml(context, label4.txPr)
15625
+ layoutXml(context, label2.layout) + chartTextXml(context, label2.tx, false) + shapePropertiesXml(context, label2.spPr) + textBodyXml(context, label2.txPr)
15626
15626
  ) : "") + raw(context, units2.extLst)
15627
15627
  );
15628
15628
  }
@@ -15647,11 +15647,11 @@ function axisXml(context, axis) {
15647
15647
  }
15648
15648
 
15649
15649
  // chart/write-analysis.ts
15650
- function trendlineLabelXml(context, label4) {
15651
- if (!label4) return "";
15650
+ function trendlineLabelXml(context, label2) {
15651
+ if (!label2) return "";
15652
15652
  return elementXml(
15653
15653
  "trendlineLbl",
15654
- layoutXml(context, label4.layout) + chartTextXml(context, label4.tx, false) + numberFormatXml(label4.numberFormat) + shapePropertiesXml(context, label4.spPr) + textBodyXml(context, label4.txPr) + raw(context, label4.extLst)
15654
+ layoutXml(context, label2.layout) + chartTextXml(context, label2.tx, false) + numberFormatXml(label2.numberFormat) + shapePropertiesXml(context, label2.spPr) + textBodyXml(context, label2.txPr) + raw(context, label2.extLst)
15655
15655
  );
15656
15656
  }
15657
15657
  function trendlineXml(context, trendline) {
@@ -17902,16 +17902,16 @@ var RelationshipAllocator = class {
17902
17902
 
17903
17903
  // docx/write.ts
17904
17904
  var twips2 = (pixels) => String(Math.round(pixels * 15));
17905
- function createTable(doc, table3, allocator, contentWidthTwips, spans2) {
17905
+ function createTable(doc, table4, allocator, contentWidthTwips, spans2) {
17906
17906
  const node3 = makeW(doc, "tbl");
17907
- const { tblPr, tblGrid } = buildNewTableProperties(doc, table3, contentWidthTwips);
17907
+ const { tblPr, tblGrid } = buildNewTableProperties(doc, table4, contentWidthTwips);
17908
17908
  node3.appendChild(tblPr);
17909
17909
  node3.appendChild(tblGrid);
17910
- const columns = tableColumnCount(table3);
17911
- table3.rows.forEach((row3, rowIndex2) => {
17910
+ const columns = tableColumnCount(table4);
17911
+ table4.rows.forEach((row3, rowIndex2) => {
17912
17912
  const tr = makeW(doc, "tr");
17913
17913
  const spanned = row3.reduce((sum3, cell) => sum3 + (cell.gridSpan ?? 1), 0);
17914
- const trPr = buildRowProperties(doc, table3.rowProperties?.[rowIndex2], columns - spanned);
17914
+ const trPr = buildRowProperties(doc, table4.rowProperties?.[rowIndex2], columns - spanned);
17915
17915
  if (trPr) tr.appendChild(trPr);
17916
17916
  for (const cell of row3) {
17917
17917
  const tc = makeW(doc, "tc");
@@ -18314,28 +18314,28 @@ function validateCell(c2, cell) {
18314
18314
  for (const side2 of ["top", "bottom", "left", "right"])
18315
18315
  c2.at(".margins").signed(side2, cell.margins[side2], "ST_SignedTwipsMeasure");
18316
18316
  }
18317
- function validateTable(c2, table3) {
18318
- c2.unsigned("widthTwips", table3.widthTwips, "ST_TwipsMeasure");
18319
- c2.signed("indentTwips", table3.indentTwips, "ST_SignedTwipsMeasure");
18317
+ function validateTable(c2, table4) {
18318
+ c2.unsigned("widthTwips", table4.widthTwips, "ST_TwipsMeasure");
18319
+ c2.signed("indentTwips", table4.indentTwips, "ST_SignedTwipsMeasure");
18320
18320
  c2.check(
18321
18321
  "alignment",
18322
- table3.alignment,
18322
+ table4.alignment,
18323
18323
  (v) => v === "left" || v === "center" || v === "right",
18324
18324
  'must be "left", "center" or "right"'
18325
18325
  );
18326
- c2.enum("justification", table3.justification, isStJcTable, "ST_JcTable");
18327
- table3.grid?.forEach(
18326
+ c2.enum("justification", table4.justification, isStJcTable, "ST_JcTable");
18327
+ table4.grid?.forEach(
18328
18328
  (width, index3) => c2.at(`.grid[${index3}]`).unsigned("width", width, "ST_TwipsMeasure")
18329
18329
  );
18330
- validateBorders(c2.at(".borders"), table3.borders);
18331
- if (table3.cellMargins)
18330
+ validateBorders(c2.at(".borders"), table4.borders);
18331
+ if (table4.cellMargins)
18332
18332
  for (const side2 of ["top", "bottom", "left", "right"])
18333
- c2.at(".cellMargins").signed(side2, table3.cellMargins[side2], "ST_SignedTwipsMeasure");
18334
- table3.rowProperties?.forEach((row3, index3) => {
18333
+ c2.at(".cellMargins").signed(side2, table4.cellMargins[side2], "ST_SignedTwipsMeasure");
18334
+ table4.rowProperties?.forEach((row3, index3) => {
18335
18335
  if (row3)
18336
18336
  c2.at(`.rowProperties[${index3}]`).unsigned("heightTwips", row3.heightTwips, "ST_TwipsMeasure");
18337
18337
  });
18338
- table3.rows.forEach(
18338
+ table4.rows.forEach(
18339
18339
  (row3, r) => row3.forEach((cell, k) => validateCell(c2.at(`.rows[${r}][${k}]`), cell))
18340
18340
  );
18341
18341
  }
@@ -19767,40 +19767,40 @@ function parseTable(node3, id3, parseParagraph3) {
19767
19767
  (cell, ci) => parseCell(cell.element, parseParagraph3, `${id3}-r${ri}c${ci}`, cell.control)
19768
19768
  )
19769
19769
  );
19770
- const table3 = { type: "table", id: id3, rows, structureEditable: canEditTableStructure(node3) };
19770
+ const table4 = { type: "table", id: id3, rows, structureEditable: canEditTableStructure(node3) };
19771
19771
  const gridElement = first2(node3, "tblGrid");
19772
19772
  const grid = gridElement ? children2(gridElement, "gridCol").flatMap((column2) => {
19773
19773
  const width2 = dxa(getW(column2, "w"));
19774
19774
  return width2 === void 0 ? [] : [width2];
19775
19775
  }) : [];
19776
- if (grid.length) table3.grid = grid;
19776
+ if (grid.length) table4.grid = grid;
19777
19777
  const tblPr = first2(node3, "tblPr");
19778
19778
  const tableWidth = first2(tblPr, "tblW");
19779
19779
  const width = (getW(tableWidth, "type") ?? "dxa") === "dxa" ? dxa(getW(tableWidth, "w")) : void 0;
19780
- if (width !== void 0) table3.widthTwips = width;
19780
+ if (width !== void 0) table4.widthTwips = width;
19781
19781
  const justification = enumValue(isStJcTable, getW(first2(tblPr, "jc"), "val"), "w:tblPr/w:jc");
19782
19782
  if (justification) {
19783
- table3.justification = justification;
19783
+ table4.justification = justification;
19784
19784
  const rtl = onOffElement(first2(tblPr, "bidiVisual")) === true;
19785
- table3.alignment = justification === "start" ? rtl ? "right" : "left" : justification === "end" ? rtl ? "left" : "right" : justification;
19785
+ table4.alignment = justification === "start" ? rtl ? "right" : "left" : justification === "end" ? rtl ? "left" : "right" : justification;
19786
19786
  }
19787
19787
  const indent = parseSignedTwips(getW(first2(tblPr, "tblInd"), "w"));
19788
- if (indent !== void 0) table3.indentTwips = indent;
19788
+ if (indent !== void 0) table4.indentTwips = indent;
19789
19789
  const borders = parseTableBorders(first2(tblPr, "tblBorders"));
19790
- if (borders) table3.borders = borders;
19790
+ if (borders) table4.borders = borders;
19791
19791
  const styleId = getW(first2(tblPr, "tblStyle"), "val");
19792
- if (styleId) table3.style = styleId;
19792
+ if (styleId) table4.style = styleId;
19793
19793
  const look = parseLook(first2(tblPr, "tblLook"));
19794
- if (look) table3.look = look;
19794
+ if (look) table4.look = look;
19795
19795
  const cellMargins = parseMargins(first2(tblPr, "tblCellMar"));
19796
- if (cellMargins) table3.cellMargins = cellMargins;
19796
+ if (cellMargins) table4.cellMargins = cellMargins;
19797
19797
  const rowProperties = rowEntries.map(({ element: element2, control }) => {
19798
19798
  const properties = parseRowProperties(element2);
19799
19799
  if (control) properties.contentControl = control;
19800
19800
  return properties;
19801
19801
  });
19802
- if (rowProperties.some((row3) => Object.keys(row3).length)) table3.rowProperties = rowProperties;
19803
- return table3;
19802
+ if (rowProperties.some((row3) => Object.keys(row3).length)) table4.rowProperties = rowProperties;
19803
+ return table4;
19804
19804
  }
19805
19805
 
19806
19806
  // docx/hyperlink.ts
@@ -20854,19 +20854,19 @@ var nextSheetId = (workbook) => workbook.sheets.reduce((max, sheet) => Math.max(
20854
20854
  var MAX_ROW = 1048575;
20855
20855
  var MAX_COL = 16383;
20856
20856
  function columnLabel(col) {
20857
- let label4 = "";
20857
+ let label2 = "";
20858
20858
  let n = col + 1;
20859
20859
  while (n > 0) {
20860
20860
  const rem = (n - 1) % 26;
20861
- label4 = String.fromCharCode(65 + rem) + label4;
20861
+ label2 = String.fromCharCode(65 + rem) + label2;
20862
20862
  n = Math.floor((n - 1) / 26);
20863
20863
  }
20864
- return label4;
20864
+ return label2;
20865
20865
  }
20866
- function columnIndex(label4) {
20867
- if (!/^[A-Za-z]{1,3}$/.test(label4)) return -1;
20866
+ function columnIndex(label2) {
20867
+ if (!/^[A-Za-z]{1,3}$/.test(label2)) return -1;
20868
20868
  let n = 0;
20869
- for (const ch of label4.toUpperCase()) n = n * 26 + (ch.charCodeAt(0) - 64);
20869
+ for (const ch of label2.toUpperCase()) n = n * 26 + (ch.charCodeAt(0) - 64);
20870
20870
  return n - 1;
20871
20871
  }
20872
20872
  var formatAddress = (address2) => `${columnLabel(address2.col)}${address2.row + 1}`;
@@ -23237,6 +23237,223 @@ var pivotColumnFields = (pivot) => [
23237
23237
  ...pivot.columnField ? pivot.moreColumnFields ?? [] : []
23238
23238
  ];
23239
23239
 
23240
+ // i18n/locale.ts
23241
+ var SUPPORTED_OFFICE_LOCALES = ["en", "fr", "de", "es", "zh-CN"];
23242
+ var DEFAULT_REJECTED_SUBTAGS = ["hant", "tw", "hk", "mo"];
23243
+ function normalizeLocale(input, supported2, fallback, options = {}) {
23244
+ const parts = (input ?? "").trim().toLowerCase().split(/[-_]/).filter(Boolean);
23245
+ const language = parts[0];
23246
+ if (!language) return fallback;
23247
+ const find3 = (tag) => supported2.find((item) => item.toLowerCase() === tag);
23248
+ const exact = find3(parts.join("-"));
23249
+ if (exact) return exact;
23250
+ const base2 = find3(language);
23251
+ if (base2) return base2;
23252
+ const rejected = options.rejectedSubtags ?? DEFAULT_REJECTED_SUBTAGS;
23253
+ if (parts.slice(1).some((part) => rejected.includes(part))) return fallback;
23254
+ return supported2.find((item) => item.toLowerCase().split("-")[0] === language && item.includes("-")) ?? fallback;
23255
+ }
23256
+ function normalizeOfficeLocale(input) {
23257
+ return normalizeLocale(input, SUPPORTED_OFFICE_LOCALES, "en");
23258
+ }
23259
+
23260
+ // xlsx/pivot/captions-locales.ts
23261
+ var table = (words2, prefix3, rest, functions) => ({
23262
+ ...rest,
23263
+ functions,
23264
+ aggregates: Object.fromEntries(
23265
+ Object.keys(words2).map((fn) => [fn, prefix3(words2[fn])])
23266
+ )
23267
+ });
23268
+ var GERMAN = {
23269
+ sum: "Summe",
23270
+ count: "Anzahl",
23271
+ average: "Mittelwert",
23272
+ max: "Max",
23273
+ min: "Min",
23274
+ product: "Produkt",
23275
+ countNums: "Anzahl (Zahlen)",
23276
+ stdDev: "Standardabweichung",
23277
+ stdDevp: "Standardabweichung (Grundgesamtheit)",
23278
+ var: "Varianz",
23279
+ varp: "Varianz (Grundgesamtheit)"
23280
+ };
23281
+ var SPANISH = {
23282
+ sum: "Suma",
23283
+ count: "Cuenta",
23284
+ average: "Promedio",
23285
+ max: "M\xE1x",
23286
+ min: "M\xEDn",
23287
+ product: "Producto",
23288
+ countNums: "Cuenta de n\xFAmeros",
23289
+ stdDev: "Desvest",
23290
+ stdDevp: "Desvestp",
23291
+ var: "Var",
23292
+ varp: "Varp"
23293
+ };
23294
+ var FRENCH = {
23295
+ sum: "Somme",
23296
+ count: "Nombre",
23297
+ average: "Moyenne",
23298
+ max: "Max",
23299
+ min: "Min",
23300
+ product: "Produit",
23301
+ countNums: "Nombre (nombres)",
23302
+ stdDev: "\xC9cartype",
23303
+ stdDevp: "\xC9cartypep",
23304
+ var: "Var",
23305
+ varp: "Varp"
23306
+ };
23307
+ var CHINESE = {
23308
+ sum: "\u6C42\u548C",
23309
+ count: "\u8BA1\u6570",
23310
+ average: "\u5E73\u5747\u503C",
23311
+ max: "\u6700\u5927\u503C",
23312
+ min: "\u6700\u5C0F\u503C",
23313
+ product: "\u4E58\u79EF",
23314
+ countNums: "\u6570\u503C\u8BA1\u6570",
23315
+ stdDev: "\u6807\u51C6\u504F\u5DEE",
23316
+ stdDevp: "\u603B\u4F53\u6807\u51C6\u504F\u5DEE",
23317
+ var: "\u65B9\u5DEE",
23318
+ varp: "\u603B\u4F53\u65B9\u5DEE"
23319
+ };
23320
+ var LOCALIZED_PIVOT_CAPTIONS = {
23321
+ de: table(
23322
+ GERMAN,
23323
+ (word) => `${word} von {0}`,
23324
+ {
23325
+ rowLabels: "Zeilenbeschriftungen",
23326
+ columnLabels: "Spaltenbeschriftungen",
23327
+ grandTotal: "Gesamtergebnis",
23328
+ values: "Werte",
23329
+ all: "(Alle)",
23330
+ blank: "(leer)",
23331
+ subtotal: "{0} Ergebnis",
23332
+ measureTotal: "Gesamt {0}"
23333
+ },
23334
+ GERMAN
23335
+ ),
23336
+ es: table(
23337
+ SPANISH,
23338
+ (word) => `${word} de {0}`,
23339
+ {
23340
+ rowLabels: "Etiquetas de fila",
23341
+ columnLabels: "Etiquetas de columna",
23342
+ grandTotal: "Total general",
23343
+ values: "Valores",
23344
+ all: "(Todas)",
23345
+ blank: "(en blanco)",
23346
+ subtotal: "{0} Total",
23347
+ measureTotal: "Total {0}"
23348
+ },
23349
+ SPANISH
23350
+ ),
23351
+ fr: table(
23352
+ FRENCH,
23353
+ (word) => `${word} de {0}`,
23354
+ {
23355
+ rowLabels: "\xC9tiquettes de lignes",
23356
+ columnLabels: "\xC9tiquettes de colonnes",
23357
+ grandTotal: "Total g\xE9n\xE9ral",
23358
+ values: "Valeurs",
23359
+ all: "(Tous)",
23360
+ blank: "(vide)",
23361
+ subtotal: "{0} Total",
23362
+ measureTotal: "Total {0}"
23363
+ },
23364
+ FRENCH
23365
+ ),
23366
+ "zh-CN": table(
23367
+ CHINESE,
23368
+ (word) => `${word}\u9879:{0}`,
23369
+ {
23370
+ rowLabels: "\u884C\u6807\u7B7E",
23371
+ columnLabels: "\u5217\u6807\u7B7E",
23372
+ grandTotal: "\u603B\u8BA1",
23373
+ values: "\u6570\u503C",
23374
+ all: "(\u5168\u90E8)",
23375
+ blank: "(\u7A7A\u767D)",
23376
+ subtotal: "{0} \u6C47\u603B",
23377
+ measureTotal: "\u603B\u8BA1 {0}"
23378
+ },
23379
+ CHINESE
23380
+ )
23381
+ };
23382
+
23383
+ // xlsx/pivot/captions.ts
23384
+ var FUNCTIONS = {
23385
+ sum: "Sum",
23386
+ count: "Count",
23387
+ average: "Average",
23388
+ max: "Max",
23389
+ min: "Min",
23390
+ product: "Product",
23391
+ countNums: "Count",
23392
+ stdDev: "StdDev",
23393
+ stdDevp: "StdDevp",
23394
+ var: "Var",
23395
+ varp: "Varp"
23396
+ };
23397
+ var aggregateNames = () => Object.fromEntries(
23398
+ Object.keys(FUNCTIONS).map((fn) => [
23399
+ fn,
23400
+ `${fn[0].toUpperCase()}${fn.slice(1)} of {0}`
23401
+ ])
23402
+ );
23403
+ var ENGLISH_PIVOT_CAPTIONS = {
23404
+ rowLabels: "Row Labels",
23405
+ columnLabels: "Column Labels",
23406
+ grandTotal: "Grand Total",
23407
+ values: "Values",
23408
+ all: "(All)",
23409
+ blank: "(blank)",
23410
+ subtotal: "{0} Total",
23411
+ measureTotal: "Total {0}",
23412
+ functions: FUNCTIONS,
23413
+ aggregates: aggregateNames()
23414
+ };
23415
+ var fillCaption = (template, ...args) => template.replace(/\{(\d)\}/g, (_match, at2) => args[Number(at2)] ?? "");
23416
+ function pivotCaptions(pivot) {
23417
+ const own2 = pivot.captions;
23418
+ if (!own2) return ENGLISH_PIVOT_CAPTIONS;
23419
+ return {
23420
+ ...ENGLISH_PIVOT_CAPTIONS,
23421
+ ...Object.fromEntries(Object.entries(own2).filter(([, value2]) => typeof value2 === "string")),
23422
+ functions: { ...ENGLISH_PIVOT_CAPTIONS.functions, ...own2.functions },
23423
+ aggregates: { ...ENGLISH_PIVOT_CAPTIONS.aggregates, ...own2.aggregates }
23424
+ };
23425
+ }
23426
+ var pivotMeasureName = (aggregate2, field2, pivot = {}) => fillCaption(pivotCaptions(pivot).aggregates[aggregate2], field2);
23427
+ function localizedPivotCaptions(locale) {
23428
+ const caps = LOCALIZED_PIVOT_CAPTIONS[normalizeOfficeLocale(locale)];
23429
+ return caps ? structuredClone(caps) : void 0;
23430
+ }
23431
+ function trimmedCaptions(caps) {
23432
+ const out = {};
23433
+ for (const key2 of [
23434
+ "rowLabels",
23435
+ "columnLabels",
23436
+ "grandTotal",
23437
+ "values",
23438
+ "all",
23439
+ "blank",
23440
+ "subtotal",
23441
+ "measureTotal"
23442
+ ])
23443
+ if (caps[key2] !== ENGLISH_PIVOT_CAPTIONS[key2]) out[key2] = caps[key2];
23444
+ for (const key2 of ["functions", "aggregates"]) {
23445
+ const changed = Object.keys(caps[key2]).filter(
23446
+ (fn) => caps[key2][fn] !== ENGLISH_PIVOT_CAPTIONS[key2][fn]
23447
+ );
23448
+ if (changed.length) out[key2] = Object.fromEntries(changed.map((fn) => [fn, caps[key2][fn]]));
23449
+ }
23450
+ return Object.keys(out).length ? out : void 0;
23451
+ }
23452
+ function authoredCaptions(options) {
23453
+ const own2 = options.captions ?? localizedPivotCaptions(options.locale);
23454
+ return own2 && Object.keys(own2).length ? structuredClone(own2) : void 0;
23455
+ }
23456
+
23240
23457
  // xlsx/formula/date-serial.ts
23241
23458
  var DAY_MS = 864e5;
23242
23459
  var EPOCH_19002 = Date.UTC(1899, 11, 30);
@@ -23495,9 +23712,9 @@ function expandDateGroups(pivot) {
23495
23712
  fields: [...pivot.fields, ...derived.map((entry3) => entry3.name)],
23496
23713
  records: pivot.records.map((record2) => [
23497
23714
  ...record2,
23498
- ...tables.map((table3) => {
23499
- const value2 = record2[table3.base];
23500
- return typeof value2 === "number" ? table3.labels[table3.index(value2)] : null;
23715
+ ...tables.map((table4) => {
23716
+ const value2 = record2[table4.base];
23717
+ return typeof value2 === "number" ? table4.labels[table4.index(value2)] : null;
23501
23718
  })
23502
23719
  ])
23503
23720
  };
@@ -23701,6 +23918,17 @@ function pruneItemFilters(pivot) {
23701
23918
  return next.length ? next : void 0;
23702
23919
  }
23703
23920
 
23921
+ // xlsx/pivot/item-labels.ts
23922
+ var keyOf = (field2, item) => `${field2}\0${pivotValueKey(item)}`;
23923
+ function pivotItemLabeler(pivot) {
23924
+ const blank = pivotCaptions(pivot).blank;
23925
+ const names = pivot.itemNames?.length ? new Map(pivot.itemNames.map((entry3) => [keyOf(entry3.field, entry3.item), entry3.name])) : void 0;
23926
+ return (field2, value2) => names?.get(keyOf(field2, value2)) ?? (value2 === null || value2 === "" ? blank : pivotItemLabel(value2));
23927
+ }
23928
+ var pivotItemName = (pivot, field2, item) => pivot.itemNames?.find(
23929
+ (entry3) => entry3.field === field2 && pivotValueKey(entry3.item) === pivotValueKey(item)
23930
+ )?.name;
23931
+
23704
23932
  // xlsx/pivot/page-filter.ts
23705
23933
  function validatePivotPageFilter(pivot) {
23706
23934
  const filter2 = pivot.pageFilter;
@@ -23712,8 +23940,8 @@ function validatePivotPageFilter(pivot) {
23712
23940
  pivot.columnField,
23713
23941
  pivot.valueField,
23714
23942
  ...extras.map((v) => v?.field)
23715
- ].includes(filter2.field) || pivot.valuesAxis === "rows")
23716
- throw new Error("Report filters require Values on columns and a separate source field.");
23943
+ ].includes(filter2.field))
23944
+ throw new Error("Report filters require a separate source field.");
23717
23945
  if (filter2.item !== void 0 && !(filter2.item === null || typeof filter2.item === "string" || typeof filter2.item === "boolean" || typeof filter2.item === "number" && Number.isFinite(filter2.item) || isCellError(filter2.item) && isErrorCode(filter2.item.error) && Object.keys(filter2.item).length === 1))
23718
23946
  throw new Error("Choose a cached literal report filter item.");
23719
23947
  }
@@ -23726,10 +23954,10 @@ function pagedProjection(pivot) {
23726
23954
  if (!filter2) return pivot;
23727
23955
  const labels = /* @__PURE__ */ new Map();
23728
23956
  for (const item of pivotItems(pivot, filter2.field)) {
23729
- const label4 = String(pivotItemLabel(item)).toLowerCase(), key3 = pivotValueKey(item);
23730
- if (label4 === "(all)" || labels.has(label4) && labels.get(label4) !== key3)
23957
+ const label2 = String(pivotItemLabel(item)).toLowerCase(), key3 = pivotValueKey(item);
23958
+ if (label2 === "(all)" || labels.has(label2) && labels.get(label2) !== key3)
23731
23959
  throw new Error("Ambiguous report filter item captions are preserved.");
23732
- labels.set(label4, key3);
23960
+ labels.set(label2, key3);
23733
23961
  }
23734
23962
  if (filter2.item === void 0) return pivot;
23735
23963
  const index3 = pivot.fields.indexOf(filter2.field), key2 = pivotValueKey(filter2.item);
@@ -23747,7 +23975,7 @@ function prependPivotPage(grid, pivot) {
23747
23975
  values: [
23748
23976
  [
23749
23977
  pivot.pageFilter.field,
23750
- pivot.pageFilter.item === void 0 ? "(All)" : pivotItemLabel(pivot.pageFilter.item),
23978
+ pivot.pageFilter.item === void 0 ? pivotCaptions(pivot).all : pivotItemLabeler(pivot)(pivot.pageFilter.field, pivot.pageFilter.item),
23751
23979
  ...Array(width - 2).fill(null)
23752
23980
  ],
23753
23981
  Array(width).fill(null),
@@ -23886,7 +24114,7 @@ function validatePivotFields(pivot) {
23886
24114
  throw new Error("Values before or between fields require two row fields and Values on rows.");
23887
24115
  if (pivot.valuesAxis === "rows" && (!Array.isArray(extras) || !extras.length))
23888
24116
  throw new Error("Values on rows require multiple measures.");
23889
- if (extras.length > 0 && pivot.sourceXml && parseXml(pivot.sourceXml).documentElement.getAttribute("dataCaption") !== "Values")
24117
+ if (extras.length > 0 && pivot.sourceXml && parseXml(pivot.sourceXml).documentElement.getAttribute("dataCaption") !== pivotCaptions(pivot).values)
23890
24118
  throw new Error("This PivotTable uses unsupported Values header captions.");
23891
24119
  if (!Array.isArray(extras) || extras.length > 15 || extras.some(
23892
24120
  (measure2) => !measure2 || !pivot.fields.includes(measure2.field) || !PIVOT_AGGREGATES.includes(measure2.aggregate) || typeof measure2.caption !== "string" || !measure2.caption.trim() || measure2.caption.length > 255 || pivot.fields.some((field2) => field2.toLowerCase() === measure2.caption.toLowerCase())
@@ -23899,8 +24127,8 @@ function validatePivotFields(pivot) {
23899
24127
  if (pivot.layout !== void 0 && !["tabular", "compact", "outline"].includes(pivot.layout) || pivot.subtotalPosition !== void 0 && !["top", "bottom"].includes(pivot.subtotalPosition) || !PIVOT_AGGREGATES.includes(pivot.aggregate) || !pivot.fields.includes(pivot.valueField) || [...rows, ...columns].some((field2) => !axisNames.includes(field2)) || (/* @__PURE__ */ new Set([...rows, ...columns])).size !== rows.length + columns.length || pivot.subtotals !== void 0 && typeof pivot.subtotals !== "boolean" || pivot.repeatLabels !== void 0 && typeof pivot.repeatLabels !== "boolean")
23900
24128
  throw new Error("Choose valid PivotTable fields; row and column fields must differ.");
23901
24129
  }
23902
- function pivotCaption(aggregate2, field2) {
23903
- return `${aggregate2[0].toUpperCase()}${aggregate2.slice(1)} of ${field2}`;
24130
+ function pivotCaption(aggregate2, field2, pivot) {
24131
+ return pivotMeasureName(aggregate2, field2, pivot);
23904
24132
  }
23905
24133
 
23906
24134
  // xlsx/write/xml-out.ts
@@ -23947,7 +24175,7 @@ var pivotMeasures = (pivot) => [
23947
24175
  { field: pivot.valueField, aggregate: pivot.aggregate, caption: pivot.valueCaption },
23948
24176
  ...pivot.additionalValues ?? []
23949
24177
  ];
23950
- function normalizedPivotMeasures(values2) {
24178
+ function normalizedPivotMeasures(values2, pivot) {
23951
24179
  if (!Array.isArray(values2) || values2.length > 15)
23952
24180
  throw new Error("Choose between one and sixteen PivotTable value fields.");
23953
24181
  return values2.map((value2) => {
@@ -23959,7 +24187,7 @@ function normalizedPivotMeasures(values2) {
23959
24187
  return {
23960
24188
  field: value2.field,
23961
24189
  aggregate: aggregate2,
23962
- caption: value2.caption ?? `${aggregate2[0].toUpperCase()}${aggregate2.slice(1)} of ${value2.field}`
24190
+ caption: value2.caption ?? pivotMeasureName(aggregate2, value2.field, pivot)
23963
24191
  };
23964
24192
  });
23965
24193
  }
@@ -23994,7 +24222,6 @@ var pivotMeasureNumber = (pivot, records, measure2) => aggregateValues(records,
23994
24222
 
23995
24223
  // xlsx/pivot/columns.ts
23996
24224
  var SEPARATOR = "";
23997
- var label = pivotItemLabel;
23998
24225
  var columnKey = (keys, depth) => keys.slice(0, depth).join(SEPARATOR);
23999
24226
  var recordColumnKeys = (record2, indices) => indices.map((index3) => pivotValueKey(record2[index3] ?? null));
24000
24227
  function pivotColumnEntries(pivot) {
@@ -24069,7 +24296,9 @@ function pivotColumnHeaders(pivot, columns, rowLabels, valuesOnRows = false) {
24069
24296
  const rows = levels + 1 + Number(count2 > 1);
24070
24297
  const grid = Array.from({ length: rows }, () => Array(width).fill(null));
24071
24298
  if (count2 === 1 && !valuesOnRows) grid[0][0] = pivot.valueCaption;
24072
- const titles = compact3 ? ["Column Labels"] : [...columns.names, ...count2 > 1 ? ["Values"] : []];
24299
+ const caps = pivotCaptions(pivot);
24300
+ const labelOf = pivotItemLabeler(pivot);
24301
+ const titles = compact3 ? [caps.columnLabels] : [...columns.names, ...count2 > 1 ? [caps.values] : []];
24073
24302
  titles.forEach((title, i2) => {
24074
24303
  grid[0][labelColumns + i2] = title;
24075
24304
  });
@@ -24082,17 +24311,17 @@ function pivotColumnHeaders(pivot, columns, rowLabels, valuesOnRows = false) {
24082
24311
  if (entry3.kind === "leaf") {
24083
24312
  entry3.path.forEach((_index, level) => {
24084
24313
  const continued = entry3.path.slice(0, level + 1).every((p, i2) => p === previous[i2]);
24085
- if (!continued) grid[1 + level][at2] = label(entry3.values[level]);
24314
+ if (!continued) grid[1 + level][at2] = labelOf(columns.names[level], entry3.values[level]);
24086
24315
  });
24087
24316
  previous = entry3.path;
24088
24317
  if (count2 > 1) measures2.forEach((measure2, m) => grid[rows - 1][at2 + m] = measure2.caption);
24089
24318
  return;
24090
24319
  }
24091
24320
  const row3 = entry3.kind === "grand" ? 1 : entry3.path.length;
24092
- const name3 = entry3.kind === "grand" ? "" : String(label(entry3.values.at(-1)));
24321
+ const name3 = entry3.kind === "grand" ? "" : String(labelOf(columns.names[entry3.path.length - 1], entry3.values.at(-1)));
24093
24322
  measures2.forEach((measure2, m) => {
24094
- const custom = entry3.fn ? PIVOT_SUBTOTALS[entry3.fn].label : void 0;
24095
- grid[row3][at2 + m] = custom ? count2 === 1 ? `${name3} ${custom}` : `${name3} ${custom} of ${measure2.field}` : count2 === 1 ? entry3.kind === "grand" ? "Grand Total" : `${name3} Total` : entry3.kind === "grand" ? `Total ${measure2.caption}` : `${name3} ${measure2.caption}`;
24323
+ const custom = entry3.fn ? caps.functions[entry3.fn] : void 0;
24324
+ grid[row3][at2 + m] = custom ? count2 === 1 ? `${name3} ${custom}` : `${name3} ${custom} of ${measure2.field}` : count2 === 1 ? entry3.kind === "grand" ? caps.grandTotal : fillCaption(caps.subtotal, name3) : entry3.kind === "grand" ? fillCaption(caps.measureTotal, measure2.caption) : `${name3} ${measure2.caption}`;
24096
24325
  });
24097
24326
  });
24098
24327
  return grid;
@@ -24125,7 +24354,6 @@ function pivotColumnItemsXml(entries, measures2, remap) {
24125
24354
  }
24126
24355
 
24127
24356
  // xlsx/pivot/nested.ts
24128
- var label2 = pivotItemLabel;
24129
24357
  var MAX_CELLS = 1e6;
24130
24358
  var node = (index3, value2) => ({
24131
24359
  index: index3,
@@ -24155,6 +24383,8 @@ function nestedPivotGrid(pivot) {
24155
24383
  const labelColumns = compact3 ? 1 : levels;
24156
24384
  const measures2 = pivotMeasures(pivot);
24157
24385
  const functions = names.map((name3) => fieldSubtotalFunctions(pivot, name3));
24386
+ const caps = pivotCaptions(pivot);
24387
+ const labelOf = pivotItemLabeler(pivot);
24158
24388
  const root = node(0, null);
24159
24389
  for (const record2 of pivot.records) {
24160
24390
  const keys = recordColumnKeys(record2, columnFields);
@@ -24181,7 +24411,7 @@ function nestedPivotGrid(pivot) {
24181
24411
  }
24182
24412
  const dimensions3 = pivotColumnDimensions(pivot, columns, labelColumns, onRows);
24183
24413
  const rowTitles = names.map((name3) => name3);
24184
- if (onRows) rowTitles.splice(valuesAt, 0, "Values");
24414
+ if (onRows) rowTitles.splice(valuesAt, 0, caps.values);
24185
24415
  let values2 = [];
24186
24416
  let indents = [];
24187
24417
  const rowEntries = [];
@@ -24260,11 +24490,11 @@ function nestedPivotGrid(pivot) {
24260
24490
  const children4 = [...group.children.values()].sort((a2, b) => a2.index - b.index);
24261
24491
  children4.forEach((child7, position2) => {
24262
24492
  const here = {
24263
- labels: [...path2.labels, label2(child7.value)],
24493
+ labels: [...path2.labels, labelOf(names[field2], child7.value)],
24264
24494
  indices: [...path2.indices, child7.index],
24265
24495
  firsts: [...path2.firsts, position2 === 0]
24266
24496
  };
24267
- const text8 = label2(child7.value);
24497
+ const text8 = labelOf(names[field2], child7.value);
24268
24498
  if (last)
24269
24499
  return push3(level, () => [
24270
24500
  labelCells(path2, leafShown(here.firsts), level, text8),
@@ -24287,14 +24517,14 @@ function nestedPivotGrid(pivot) {
24287
24517
  ]);
24288
24518
  if (own2 === "auto") {
24289
24519
  if (showsValue) return;
24290
- if (valuesAbove) subtotal(`${caption} Total`, void 0, measure2);
24520
+ if (valuesAbove) subtotal(fillCaption(caps.subtotal, caption), void 0, measure2);
24291
24521
  else measures2.forEach((one2, m) => subtotal(`${caption} ${one2.caption}`, void 0, m));
24292
24522
  } else
24293
24523
  for (const fn of own2)
24294
- if (valuesAbove) subtotal(`${caption} ${PIVOT_SUBTOTALS[fn].label}`, fn, measure2);
24524
+ if (valuesAbove) subtotal(`${caption} ${caps.functions[fn]}`, fn, measure2);
24295
24525
  else
24296
24526
  measures2.forEach(
24297
- (one2, m) => subtotal(`${caption} ${PIVOT_SUBTOTALS[fn].label} of ${one2.field}`, fn, m)
24527
+ (one2, m) => subtotal(`${caption} ${caps.functions[fn]} of ${one2.field}`, fn, m)
24298
24528
  );
24299
24529
  });
24300
24530
  };
@@ -24305,12 +24535,12 @@ function nestedPivotGrid(pivot) {
24305
24535
  ]);
24306
24536
  const build2 = () => {
24307
24537
  walk2(0, root, void 0, { labels: [], indices: [], firsts: [] });
24308
- if (onRows) measures2.forEach((one2, m) => grand(`Total ${one2.caption}`, m));
24309
- else grand("Grand Total");
24538
+ if (onRows) measures2.forEach((one2, m) => grand(fillCaption(caps.measureTotal, one2.caption), m));
24539
+ else grand(caps.grandTotal);
24310
24540
  };
24311
24541
  build2();
24312
24542
  counting = false;
24313
- values2 = pivotColumnHeaders(pivot, columns, compact3 ? ["Row Labels"] : rowTitles, onRows);
24543
+ values2 = pivotColumnHeaders(pivot, columns, compact3 ? [caps.rowLabels] : rowTitles, onRows);
24314
24544
  const firstDataRow = values2.length;
24315
24545
  indents = values2.map(() => 0);
24316
24546
  build2();
@@ -24343,14 +24573,14 @@ function pivotTableAt(sheet, at2) {
24343
24573
  var X14 = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main";
24344
24574
  var LAYOUT = "http://schemas.microsoft.com/office/spreadsheetml/2016/pivotdefaultlayout";
24345
24575
  var TABLE = {
24346
- pivotTableDefinition: "name cacheId dataCaption dataOnRows dataPosition updatedVersion minRefreshableVersion createdVersion applyNumberFormats applyBorderFormats applyFontFormats applyPatternFormats applyAlignmentFormats applyWidthHeightFormats useAutoFormatting itemPrintTitles indent compact compactData outline outlineData multipleFieldFilters rowGrandTotals colGrandTotals",
24576
+ pivotTableDefinition: "name cacheId dataCaption grandTotalCaption rowHeaderCaption colHeaderCaption dataOnRows dataPosition updatedVersion minRefreshableVersion createdVersion applyNumberFormats applyBorderFormats applyFontFormats applyPatternFormats applyAlignmentFormats applyWidthHeightFormats useAutoFormatting itemPrintTitles indent compact compactData outline outlineData multipleFieldFilters rowGrandTotals colGrandTotals",
24347
24577
  location: "ref firstHeaderRow firstDataRow firstDataCol rowPageCount colPageCount",
24348
24578
  pageFields: "count",
24349
24579
  pageField: "fld item hier",
24350
24580
  pivotFields: "count",
24351
24581
  pivotField: "axis dataField compact outline showAll subtotalTop defaultSubtotal numFmtId sumSubtotal countASubtotal avgSubtotal maxSubtotal minSubtotal productSubtotal countSubtotal stdDevSubtotal stdDevPSubtotal varSubtotal varPSubtotal",
24352
24582
  items: "count",
24353
- item: "x t h",
24583
+ item: "x t h n",
24354
24584
  rowFields: "count",
24355
24585
  colFields: "count",
24356
24586
  field: "x",
@@ -24451,8 +24681,8 @@ function inspect(node3, profile, cache3) {
24451
24681
  }
24452
24682
  for (const child7 of elements(node3)) inspect(child7, profile, cache3);
24453
24683
  }
24454
- function assertPivotAdmission(table3, cache3) {
24455
- inspect(table3, TABLE, false);
24684
+ function assertPivotAdmission(table4, cache3) {
24685
+ inspect(table4, TABLE, false);
24456
24686
  inspect(cache3, CACHE, true);
24457
24687
  }
24458
24688
  function assertPivotRecords(records) {
@@ -24463,6 +24693,121 @@ function assertPivotRecords(records) {
24463
24693
  );
24464
24694
  }
24465
24695
 
24696
+ // xlsx/pivot/captions-read.ts
24697
+ var ATTRIBUTES2 = {
24698
+ rowHeaderCaption: "rowLabels",
24699
+ colHeaderCaption: "columnLabels",
24700
+ grandTotalCaption: "grandTotal",
24701
+ dataCaption: "values"
24702
+ };
24703
+ function readPivotCaptionAttributes(root) {
24704
+ const out = {};
24705
+ for (const [attribute4, key2] of Object.entries(ATTRIBUTES2)) {
24706
+ const text8 = att(root, attribute4);
24707
+ if (text8 !== void 0)
24708
+ out[key2] = decodeEscapes(text8);
24709
+ }
24710
+ return out;
24711
+ }
24712
+ function aggregateCaptionsOf(pivot) {
24713
+ const out = {};
24714
+ for (const measure2 of [
24715
+ { field: pivot.valueField, aggregate: pivot.aggregate, caption: pivot.valueCaption },
24716
+ ...pivot.additionalValues ?? []
24717
+ ]) {
24718
+ const at2 = measure2.caption.indexOf(measure2.field);
24719
+ if (at2 < 0 || measure2.caption === measure2.field) continue;
24720
+ const template = `${measure2.caption.slice(0, at2)}{0}${measure2.caption.slice(at2 + measure2.field.length)}`;
24721
+ if (template !== ENGLISH_PIVOT_CAPTIONS.aggregates[measure2.aggregate])
24722
+ out[measure2.aggregate] = template;
24723
+ }
24724
+ return Object.keys(out).length ? out : void 0;
24725
+ }
24726
+ var MARK = "";
24727
+ var SENTINELS = {
24728
+ rowLabels: `${MARK}R`,
24729
+ columnLabels: `${MARK}C`,
24730
+ grandTotal: `${MARK}G`,
24731
+ values: `${MARK}V`,
24732
+ all: `${MARK}A`,
24733
+ blank: `${MARK}B`,
24734
+ subtotal: `{0}${MARK}S`,
24735
+ measureTotal: `${MARK}M{0}`,
24736
+ functions: Object.fromEntries(
24737
+ Object.keys(ENGLISH_PIVOT_CAPTIONS.functions).map((fn) => [fn, `${MARK}F${fn}`])
24738
+ ),
24739
+ aggregates: ENGLISH_PIVOT_CAPTIONS.aggregates
24740
+ };
24741
+ function templateOf(cached6, arg) {
24742
+ if (!arg || !cached6.includes(arg)) return void 0;
24743
+ if (cached6.startsWith(arg)) return `{0}${cached6.slice(arg.length)}`;
24744
+ if (cached6.endsWith(arg)) return `${cached6.slice(0, -arg.length)}{0}`;
24745
+ const at2 = cached6.indexOf(arg);
24746
+ return `${cached6.slice(0, at2)}{0}${cached6.slice(at2 + arg.length)}`;
24747
+ }
24748
+ function inferPivotCaptions(pivot, sheet, named3) {
24749
+ const known = pivotCaptions({ captions: named3 });
24750
+ const probe = { ...SENTINELS };
24751
+ for (const key2 of Object.keys(named3))
24752
+ if (typeof named3[key2] === "string")
24753
+ probe[key2] = known[key2];
24754
+ const grid = pivotGrid({ ...pivot, captions: probe });
24755
+ const found = /* @__PURE__ */ new Map();
24756
+ const set = (key2, value2) => {
24757
+ if (value2 === void 0) return;
24758
+ const before = found.get(key2);
24759
+ found.set(key2, before === void 0 || before === value2 ? value2 : null);
24760
+ };
24761
+ grid.values.forEach(
24762
+ (line3, r) => line3.forEach((expected, c2) => {
24763
+ if (typeof expected !== "string" || !expected.includes(MARK)) return;
24764
+ const cached6 = getCell(
24765
+ sheet,
24766
+ pivot.location.start.row + r,
24767
+ pivot.location.start.col + c2
24768
+ )?.value;
24769
+ if (typeof cached6 !== "string") return;
24770
+ const kind = /\u0001([RCGVASMFB])(\w*)/.exec(expected);
24771
+ if (!kind) return;
24772
+ const at2 = kind.index;
24773
+ switch (kind[1]) {
24774
+ case "R":
24775
+ return set("rowLabels", cached6);
24776
+ case "C":
24777
+ return set("columnLabels", cached6);
24778
+ case "G":
24779
+ return set("grandTotal", cached6);
24780
+ case "V":
24781
+ return set("values", cached6);
24782
+ case "A":
24783
+ return set("all", cached6);
24784
+ case "B":
24785
+ return set("blank", cached6);
24786
+ case "S":
24787
+ return set("subtotal", templateOf(cached6, expected.slice(0, at2)));
24788
+ case "M":
24789
+ return set("measureTotal", templateOf(cached6, expected.slice(at2 + 2)));
24790
+ case "F": {
24791
+ const item = expected.slice(0, at2 - 1);
24792
+ const of = / of (.*)$/.exec(expected.slice(at2));
24793
+ const word = cached6.slice(item.length + 1, of ? cached6.length - of[0].length : void 0);
24794
+ if (cached6.startsWith(`${item} `) && (!of || cached6.endsWith(of[0])))
24795
+ set(`function:${kind[2]}`, word);
24796
+ }
24797
+ }
24798
+ })
24799
+ );
24800
+ const out = pivotCaptions({ captions: named3 });
24801
+ const functions = { ...out.functions };
24802
+ for (const [key2, value2] of found) {
24803
+ if (value2 === null) continue;
24804
+ if (key2.startsWith("function:")) functions[key2.slice(9)] = value2;
24805
+ else out[key2] = value2;
24806
+ }
24807
+ out.functions = functions;
24808
+ return trimmedCaptions(out);
24809
+ }
24810
+
24466
24811
  // xlsx/slicer/read-slicers.ts
24467
24812
  var TABLE_SLICER_URI = "{2F2917AC-EB37-4324-AD4E-5DD8C200BD13}";
24468
24813
  var X152 = "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main";
@@ -24538,12 +24883,12 @@ function parseSlicerCache(xml, partName) {
24538
24883
  if (data) return void 0;
24539
24884
  const list2 = byLocal(root, "extLst");
24540
24885
  const ext = list2 ? elements(list2).find((node3) => node3.getAttribute("uri") === TABLE_SLICER_URI) : void 0;
24541
- const table3 = ext ? first(ext, "tableSlicerCache", X152) : void 0;
24542
- const tableId = numAttr(table3, "tableId");
24543
- const column2 = numAttr(table3, "column");
24544
- if (!table3 || tableId === void 0 || column2 === void 0) return void 0;
24886
+ const table4 = ext ? first(ext, "tableSlicerCache", X152) : void 0;
24887
+ const tableId = numAttr(table4, "tableId");
24888
+ const column2 = numAttr(table4, "column");
24889
+ if (!table4 || tableId === void 0 || column2 === void 0) return void 0;
24545
24890
  const cache3 = { ...common, source: { kind: "table", tableId, column: column2 } };
24546
- if (att(table3, "sortOrder") === "descending") cache3.sortOrder = "descending";
24891
+ if (att(table4, "sortOrder") === "descending") cache3.sortOrder = "descending";
24547
24892
  if (elements(root).some((node3) => node3.localName === "pivotTables")) return void 0;
24548
24893
  return cache3;
24549
24894
  }
@@ -24628,14 +24973,14 @@ function parseTimelineCache(xml, partName) {
24628
24973
  }
24629
24974
 
24630
24975
  // xlsx/slicer/table-filter.ts
24631
- function tableFilterBounds(table3) {
24976
+ function tableFilterBounds(table4) {
24632
24977
  return {
24633
- start: table3.range.start,
24634
- end: { ...table3.range.end, row: table3.range.end.row - (table3.totalsRow ? 1 : 0) }
24978
+ start: table4.range.start,
24979
+ end: { ...table4.range.end, row: table4.range.end.row - (table4.totalsRow ? 1 : 0) }
24635
24980
  };
24636
24981
  }
24637
- function tableAutoFilter(table3) {
24638
- const columns = table3.columns.flatMap(
24982
+ function tableAutoFilter(table4) {
24983
+ const columns = table4.columns.flatMap(
24639
24984
  (column2, offset2) => column2.filter ? [
24640
24985
  {
24641
24986
  offset: offset2,
@@ -24645,12 +24990,12 @@ function tableAutoFilter(table3) {
24645
24990
  ] : []
24646
24991
  );
24647
24992
  if (!columns.length) return void 0;
24648
- return { range: tableFilterBounds(table3), columns };
24993
+ return { range: tableFilterBounds(table4), columns };
24649
24994
  }
24650
- function applyTableFilter(workbook, sheet, table3) {
24651
- if (!table3.headerRow) return;
24652
- const bounds2 = tableFilterBounds(table3);
24653
- const filter2 = tableAutoFilter(table3);
24995
+ function applyTableFilter(workbook, sheet, table4) {
24996
+ if (!table4.headerRow) return;
24997
+ const bounds2 = tableFilterBounds(table4);
24998
+ const filter2 = tableAutoFilter(table4);
24654
24999
  for (let row3 = bounds2.start.row + 1; row3 <= bounds2.end.row; row3++) {
24655
25000
  const visible = !filter2 || rowMatchesFilter(workbook, sheet, row3, filter2);
24656
25001
  setRowFiltered(sheet, row3, !visible, !!filter2);
@@ -24658,8 +25003,8 @@ function applyTableFilter(workbook, sheet, table3) {
24658
25003
  }
24659
25004
  function readTableFilteredRows(workbook) {
24660
25005
  for (const sheet of workbook.sheets)
24661
- for (const table3 of sheet.tables) {
24662
- const filter2 = tableAutoFilter(table3);
25006
+ for (const table4 of sheet.tables) {
25007
+ const filter2 = tableAutoFilter(table4);
24663
25008
  if (!filter2) continue;
24664
25009
  for (let row3 = filter2.range.start.row + 1; row3 <= filter2.range.end.row; row3++) {
24665
25010
  const info = sheet.rowInfo.get(row3);
@@ -24778,9 +25123,9 @@ function settleSlicers(workbook, warn) {
24778
25123
  if (cache3.source.kind === "table") {
24779
25124
  const { tableId, column: column2 } = cache3.source;
24780
25125
  for (const sheet of workbook.sheets) {
24781
- const table3 = sheet.tables.find((entry3) => entry3.id === tableId);
24782
- if (table3)
24783
- return table3.headerRow && !table3.filterNotModeled && table3.columns.some((entry3) => entry3.sourceId === column2);
25126
+ const table4 = sheet.tables.find((entry3) => entry3.id === tableId);
25127
+ if (table4)
25128
+ return table4.headerRow && !table4.filterNotModeled && table4.columns.some((entry3) => entry3.sourceId === column2);
24784
25129
  }
24785
25130
  return false;
24786
25131
  }
@@ -24958,7 +25303,7 @@ function readFieldGroups(fields, names) {
24958
25303
  throw new Error("Unsupported pivot field group");
24959
25304
  const labels = children(list2, "s", NS.x).map((node3) => decodeEscapes(att(node3, "v") ?? ""));
24960
25305
  const expected = numberGroupLabels({ start, end, by });
24961
- if (elements(list2).length !== labels.length || labels.length !== expected.length || labels.some((label4, i2) => label4 !== expected[i2]))
25306
+ if (elements(list2).length !== labels.length || labels.length !== expected.length || labels.some((label2, i2) => label2 !== expected[i2]))
24962
25307
  throw new Error("Unsupported pivot group items");
24963
25308
  groups.push({ field: names[index3] ?? "", start, end, by });
24964
25309
  });
@@ -25042,7 +25387,7 @@ function readDateGroups(fields, count2, names, dateFields, records, date1904) {
25042
25387
  const node3 = first(first(entry3.node, "fieldGroup", NS.x), "groupItems", NS.x);
25043
25388
  const actual = children(node3, "s", NS.x).map((item) => decodeEscapes(att(item, "v") ?? ""));
25044
25389
  const name3 = decodeEscapes(att(entry3.node, "name") ?? "");
25045
- if (!name3 || elements(node3).length !== actual.length || actual.length !== labels.length || actual.some((label4) => !label4) || new Set(actual).size !== actual.length)
25390
+ if (!name3 || elements(node3).length !== actual.length || actual.length !== labels.length || actual.some((label2) => !label2) || new Set(actual).size !== actual.length)
25046
25391
  throw unsupported("group items");
25047
25392
  if (name3 !== dateGroupFieldName(entry3.unit, field2) || actual.some((l, i2) => l !== labels[i2]))
25048
25393
  localized[entry3.unit] = { name: name3, labels: actual };
@@ -25100,6 +25445,25 @@ function readItemFilters(fields, names, shared) {
25100
25445
  return filters.length ? filters : void 0;
25101
25446
  }
25102
25447
 
25448
+ // xlsx/pivot/item-names-read.ts
25449
+ function readItemNames(tableFields, names, shared) {
25450
+ const out = [];
25451
+ tableFields.forEach((field2, index3) => {
25452
+ const list2 = first(field2, "items", NS.x);
25453
+ if (!list2 || index3 >= names.length) return;
25454
+ for (const item of children(list2, "item", NS.x)) {
25455
+ const name3 = att(item, "n");
25456
+ if (name3 === void 0) continue;
25457
+ const at2 = Number(att(item, "x"));
25458
+ const value2 = shared[index3]?.[at2];
25459
+ if (att(item, "t") !== void 0 || !Number.isInteger(at2) || value2 === void 0)
25460
+ throw new Error("Unsupported pivot item name");
25461
+ out.push({ field: names[index3], item: value2, name: decodeEscapes(name3) });
25462
+ }
25463
+ });
25464
+ return out;
25465
+ }
25466
+
25103
25467
  // xlsx/pivot/values-axis.ts
25104
25468
  function remapPivotRowEntries(entries, axes2) {
25105
25469
  return entries.map(
@@ -25222,7 +25586,10 @@ function assertPageAxisItems(root, pivot, shared, cache3, recordRoot) {
25222
25586
  };
25223
25587
  const rowAxes = pivotRowFields(pivot).map((name3) => axisValues(name3, "axisRow")), rowItems = read("rowItems");
25224
25588
  const grid = pivotGrid(pivot);
25225
- const entries = grid.rowEntries ? remapPivotRowEntries(grid.rowEntries, rowAxes) : [
25589
+ const valuesAt = pivotValuesIndex(pivot);
25590
+ const levelAxes = [...rowAxes];
25591
+ if (valuesAt >= 0) levelAxes.splice(valuesAt, 0, null);
25592
+ const entries = grid.rowEntries ? remapPivotRowEntries(grid.rowEntries, levelAxes) : [
25226
25593
  ...rowAxes[0].map((index3) => ({ indices: [index3] })),
25227
25594
  { indices: [0], type: "grand" }
25228
25595
  ];
@@ -25232,11 +25599,11 @@ function assertPageAxisItems(root, pivot, shared, cache3, recordRoot) {
25232
25599
  const expected2 = entries[i2];
25233
25600
  const xs = children(item, "x", NS.x).map((x) => integer3(x.getAttribute("v"), 0)), prefix3 = integer3(item.getAttribute("r"), 0);
25234
25601
  const type = expected2.type === void 0 || expected2.type === "default" || expected2.type === "grand" ? expected2.type : PIVOT_SUBTOTALS[expected2.type].item;
25235
- if (item.getAttribute("t") !== (type ?? null) || !Number.isInteger(prefix3) || prefix3 < 0 || prefix3 > previousRow.length || prefix3 >= expected2.indices.length || expected2.type === "grand" && prefix3 !== 0 || integer3(item.getAttribute("i"), 0) !== 0 || JSON.stringify([...previousRow.slice(0, prefix3), ...xs]) !== JSON.stringify(expected2.indices))
25602
+ if (item.getAttribute("t") !== (type ?? null) || !Number.isInteger(prefix3) || prefix3 < 0 || prefix3 > previousRow.length || prefix3 >= expected2.indices.length || expected2.type === "grand" && prefix3 !== 0 || integer3(item.getAttribute("i"), 0) !== (expected2.measure ?? 0) || JSON.stringify([...previousRow.slice(0, prefix3), ...xs]) !== JSON.stringify(expected2.indices))
25236
25603
  throw new Error("Unmodeled page row item");
25237
25604
  previousRow = expected2.type === "grand" ? [] : expected2.indices;
25238
25605
  });
25239
- const measures2 = 1 + (pivot.additionalValues?.length ?? 0), columns = pivot.columnField ? axisValues(pivot.columnField, "axisCol") : void 0, expected = [];
25606
+ const measures2 = valuesAt >= 0 ? 1 : 1 + (pivot.additionalValues?.length ?? 0), columns = pivot.columnField ? axisValues(pivot.columnField, "axisCol") : void 0, expected = [];
25240
25607
  if (columns)
25241
25608
  for (const col of columns)
25242
25609
  for (let m = 0; m < measures2; m++) expected.push(measures2 > 1 ? [col, m] : [col]);
@@ -25278,6 +25645,10 @@ function value(node3, date1904 = false) {
25278
25645
  if (node3.localName === "e" && isErrorCode(v)) return { error: v };
25279
25646
  throw new Error("Unsupported pivot cache item");
25280
25647
  }
25648
+ var namedAggregates = (pivot) => {
25649
+ const aggregates = aggregateCaptionsOf(pivot);
25650
+ return aggregates ? { aggregates } : {};
25651
+ };
25281
25652
  function readOne(workbook, source2, part) {
25282
25653
  const xml = source2.text(part);
25283
25654
  const root = parseXml(xml).documentElement;
@@ -25424,6 +25795,7 @@ function readOne(workbook, source2, part) {
25424
25795
  location.start.row -= 2;
25425
25796
  }
25426
25797
  const itemFilters = readItemFilters(tableFields, names, shared);
25798
+ const itemNames = readItemNames(tableFields, names, shared);
25427
25799
  const slicerCacheId = readSlicerCacheId(cache3);
25428
25800
  const fieldGroups = readFieldGroups(fields, names);
25429
25801
  const dateFields = readDateFields(fields, names);
@@ -25462,6 +25834,7 @@ function readOne(workbook, source2, part) {
25462
25834
  const pivot = {
25463
25835
  ...pageFilter ? { pageFilter } : {},
25464
25836
  ...itemFilters ? { itemFilters } : {},
25837
+ ...itemNames.length ? { itemNames } : {},
25465
25838
  ...fieldGroups.length ? { fieldGroups } : {},
25466
25839
  ...dateFields.length ? { dateFields } : {},
25467
25840
  ...dateGroups.length ? { dateGroups } : {},
@@ -25504,6 +25877,12 @@ function readOne(workbook, source2, part) {
25504
25877
  ...col ? { columnField: col } : {},
25505
25878
  ...moreColumns.length ? { moreColumnFields: moreColumns } : {}
25506
25879
  };
25880
+ const captions = trimmedCaptions(
25881
+ pivotCaptions({
25882
+ captions: { ...readPivotCaptionAttributes(root), ...namedAggregates(pivot) }
25883
+ })
25884
+ );
25885
+ if (captions) pivot.captions = captions;
25507
25886
  if (pageFilter && moreColumns.length) throw new Error("Report filters support one column field");
25508
25887
  assertPageAxisItems(root, pivot, shared, cache3, recordRoot);
25509
25888
  return pivot;
@@ -25531,6 +25910,12 @@ function readPivotTables(workbook, source2, warn, slicers) {
25531
25910
  if (slicers.blocked.has(pivotKey(sheet.sheetId, name3)) || cache3 && (caches2.get(cache3) ?? 0) > 1)
25532
25911
  throw new Error("Shared pivot cache or unsupported slicer connection");
25533
25912
  const pivot = readOne(workbook, source2, part);
25913
+ const inferred = inferPivotCaptions(pivot, sheet, {
25914
+ ...readPivotCaptionAttributes(parseXml(pivot.sourceXml).documentElement),
25915
+ ...namedAggregates(pivot)
25916
+ });
25917
+ if (inferred) pivot.captions = inferred;
25918
+ else delete pivot.captions;
25534
25919
  const grid = pivotGrid(pivot);
25535
25920
  if (grid.values.length !== pivot.location.end.row - pivot.location.start.row + 1 || grid.values[0].length !== pivot.location.end.col - pivot.location.start.col + 1 || grid.values.some(
25536
25921
  (line3, r) => line3.some(
@@ -26170,7 +26555,7 @@ function mergeSpacedAreas(tokens3) {
26170
26555
  }
26171
26556
  return out;
26172
26557
  }
26173
- function templateOf(formula) {
26558
+ function templateOf2(formula) {
26174
26559
  const cached6 = templates.get(formula);
26175
26560
  if (cached6 !== void 0) return cached6;
26176
26561
  const raw2 = safeTokens(formula);
@@ -26200,7 +26585,7 @@ function templateOf(formula) {
26200
26585
  return template;
26201
26586
  }
26202
26587
  function rewriteTemplate(formula, rewrite2) {
26203
- const template = templateOf(formula);
26588
+ const template = templateOf2(formula);
26204
26589
  if (!template) return formula;
26205
26590
  let next;
26206
26591
  for (let i2 = 0; i2 < template.length; i2++) {
@@ -27501,14 +27886,14 @@ function readDataTable(f6) {
27501
27886
  const ref = parseRange(att(f6, "ref") ?? "");
27502
27887
  const r1 = att(f6, "r1");
27503
27888
  if (!ref || !r1) return void 0;
27504
- const table3 = { ref, r1 };
27889
+ const table4 = { ref, r1 };
27505
27890
  const r2 = att(f6, "r2");
27506
- if (r2) table3.r2 = r2;
27507
- if (boolAttr(f6, "dt2D")) table3.dt2D = true;
27508
- if (boolAttr(f6, "dtr")) table3.dtr = true;
27509
- if (boolAttr(f6, "del1")) table3.del1 = true;
27510
- if (boolAttr(f6, "del2")) table3.del2 = true;
27511
- return table3;
27891
+ if (r2) table4.r2 = r2;
27892
+ if (boolAttr(f6, "dt2D")) table4.dt2D = true;
27893
+ if (boolAttr(f6, "dtr")) table4.dtr = true;
27894
+ if (boolAttr(f6, "del1")) table4.del1 = true;
27895
+ if (boolAttr(f6, "del2")) table4.del2 = true;
27896
+ return table4;
27512
27897
  }
27513
27898
  function readFormula(ctx, f6, row3, col, cell, masters, dynamic2, anchors, sheet) {
27514
27899
  const kind = att(f6, "t") ?? "normal";
@@ -27532,8 +27917,8 @@ function readFormula(ctx, f6, row3, col, cell, masters, dynamic2, anchors, sheet
27532
27917
  }
27533
27918
  if (kind === "dataTable") {
27534
27919
  delete cell.legacyFormula;
27535
- const table3 = readDataTable(f6);
27536
- if (table3) (sheet.dataTables ??= []).push(table3);
27920
+ const table4 = readDataTable(f6);
27921
+ if (table4) (sheet.dataTables ??= []).push(table4);
27537
27922
  else ctx.warn("A what-if data table formula could not be read; its cached values were kept.");
27538
27923
  return;
27539
27924
  }
@@ -27725,14 +28110,14 @@ function parseTable3(xml, partName) {
27725
28110
  if (id3 !== void 0 && Number.isInteger(id3) && id3 >= 0) column2.sourceId = id3;
27726
28111
  const fn = att(node3, "totalsRowFunction");
27727
28112
  if (fn && fn !== "none") column2.totalsRowFunction = fn;
27728
- const label4 = att(node3, "totalsRowLabel");
27729
- if (label4 !== void 0) column2.totalsRowLabel = label4;
28113
+ const label2 = att(node3, "totalsRowLabel");
28114
+ if (label2 !== void 0) column2.totalsRowLabel = label2;
27730
28115
  const calculated = xFirst(node3, "calculatedColumnFormula");
27731
28116
  if (calculated) column2.calculatedColumnFormula = stripFuturePrefixes(xText(calculated));
27732
28117
  return column2;
27733
28118
  }
27734
28119
  );
27735
- const table3 = {
28120
+ const table4 = {
27736
28121
  id: numAttr(root, "id") ?? 1,
27737
28122
  name: name3,
27738
28123
  displayName: att(root, "displayName") ?? name3,
@@ -27742,26 +28127,26 @@ function parseTable3(xml, partName) {
27742
28127
  columns,
27743
28128
  partName
27744
28129
  };
27745
- readColumnFilters(root, table3);
28130
+ readColumnFilters(root, table4);
27746
28131
  const info = xFirst(root, "tableStyleInfo");
27747
28132
  if (info) {
27748
28133
  const style3 = att(info, "name");
27749
- if (style3) table3.styleName = style3;
27750
- table3.showRowStripes = boolAttr(info, "showRowStripes", false);
27751
- table3.showColumnStripes = boolAttr(info, "showColumnStripes", false);
27752
- table3.showFirstColumn = boolAttr(info, "showFirstColumn", false);
27753
- table3.showLastColumn = boolAttr(info, "showLastColumn", false);
28134
+ if (style3) table4.styleName = style3;
28135
+ table4.showRowStripes = boolAttr(info, "showRowStripes", false);
28136
+ table4.showColumnStripes = boolAttr(info, "showColumnStripes", false);
28137
+ table4.showFirstColumn = boolAttr(info, "showFirstColumn", false);
28138
+ table4.showLastColumn = boolAttr(info, "showLastColumn", false);
27754
28139
  }
27755
- return table3;
28140
+ return table4;
27756
28141
  }
27757
- function readColumnFilters(root, table3) {
28142
+ function readColumnFilters(root, table4) {
27758
28143
  const filter2 = xFirst(root, "autoFilter");
27759
28144
  for (const node3 of filter2 ? xChildren(filter2, "filterColumn") : []) {
27760
- const column2 = table3.columns[numAttr(node3, "colId") ?? -1];
28145
+ const column2 = table4.columns[numAttr(node3, "colId") ?? -1];
27761
28146
  const filters = xChildren(node3, "filters");
27762
28147
  const simple = column2 && isValueListFilterColumn(node3);
27763
28148
  if (!simple) {
27764
- table3.filterNotModeled = true;
28149
+ table4.filterNotModeled = true;
27765
28150
  continue;
27766
28151
  }
27767
28152
  const values2 = xChildren(filters[0], "filter").map((child7) => att(child7, "val") ?? "");
@@ -27840,8 +28225,8 @@ function readTables(ctx, partName, node3, sheet) {
27840
28225
  const rel = rels.get(relAttr(part, "id") ?? "");
27841
28226
  const target2 = rel ? ctx.source.target(partName, rel) : void 0;
27842
28227
  const xml = target2 ? ctx.source.text(target2) : void 0;
27843
- const table3 = target2 && xml ? parseTable3(xml, target2) : void 0;
27844
- if (table3) sheet.tables.push(table3);
28228
+ const table4 = target2 && xml ? parseTable3(xml, target2) : void 0;
28229
+ if (table4) sheet.tables.push(table4);
27845
28230
  else ctx.warn("A table part could not be read and was dropped.");
27846
28231
  }
27847
28232
  }
@@ -30311,14 +30696,14 @@ function unique(args, ctx) {
30311
30696
  const byCol = args.length > 1 && args[1] !== null && toBool(ctx.toScalar(args[1] ?? null));
30312
30697
  const once = args.length > 2 && args[2] !== null && toBool(ctx.toScalar(args[2] ?? null));
30313
30698
  if (byCol) m = transpose(m);
30314
- const keyOf2 = (row3) => JSON.stringify(
30699
+ const keyOf3 = (row3) => JSON.stringify(
30315
30700
  row3.map(
30316
30701
  (v) => isError(v) ? `#${v.error}` : typeof v === "string" ? `s${v.toLowerCase()}` : v
30317
30702
  )
30318
30703
  );
30319
30704
  const counts = /* @__PURE__ */ new Map();
30320
30705
  for (const row3 of m.data) {
30321
- const key2 = keyOf2(row3);
30706
+ const key2 = keyOf3(row3);
30322
30707
  const entry3 = counts.get(key2);
30323
30708
  if (entry3) entry3.count++;
30324
30709
  else counts.set(key2, { row: row3, count: 1 });
@@ -30603,30 +30988,30 @@ function gammaLn(z) {
30603
30988
 
30604
30989
  // xlsx/formula/functions/database.ts
30605
30990
  var C3 = "Database";
30606
- var label3 = (value2) => value2 === null ? "" : typeof value2 === "string" ? value2 : String(value2);
30991
+ var label = (value2) => value2 === null ? "" : typeof value2 === "string" ? value2 : String(value2);
30607
30992
  function tableOf(ctx, value2) {
30608
30993
  const [head, ...records] = ctx.toMatrix(value2 ?? null).data;
30609
30994
  if (!head || records.length === 0) fail(ERR.VALUE);
30610
- return { headers: head.map((v) => label3(v).toLowerCase()), records };
30995
+ return { headers: head.map((v) => label(v).toLowerCase()), records };
30611
30996
  }
30612
- function fieldIndex(table3, field2) {
30997
+ function fieldIndex(table4, field2) {
30613
30998
  const value2 = scalar2(field2);
30614
30999
  if (isError(value2)) fail(value2);
30615
31000
  if (typeof value2 === "number") {
30616
31001
  const index4 = Math.trunc(value2) - 1;
30617
- if (index4 < 0 || index4 >= table3.headers.length) fail(ERR.VALUE);
31002
+ if (index4 < 0 || index4 >= table4.headers.length) fail(ERR.VALUE);
30618
31003
  return index4;
30619
31004
  }
30620
- const index3 = table3.headers.indexOf(label3(value2).toLowerCase());
31005
+ const index3 = table4.headers.indexOf(label(value2).toLowerCase());
30621
31006
  if (index3 < 0) fail(ERR.VALUE);
30622
31007
  return index3;
30623
31008
  }
30624
- function recordFilter(table3, criteria) {
31009
+ function recordFilter(table4, criteria) {
30625
31010
  const [head, ...rows] = criteria;
30626
31011
  if (!head || rows.length === 0) fail(ERR.VALUE);
30627
31012
  const columns = head.map((name3) => {
30628
31013
  if (name3 === null || name3 === "") return -1;
30629
- return table3.headers.indexOf(label3(name3).toLowerCase());
31014
+ return table4.headers.indexOf(label(name3).toLowerCase());
30630
31015
  });
30631
31016
  const alternatives = rows.map(
30632
31017
  (row3) => row3.flatMap((cell, c2) => {
@@ -30640,10 +31025,10 @@ function recordFilter(table3, criteria) {
30640
31025
  return (record2) => alternatives.some((tests) => tests.every((test) => test(record2)));
30641
31026
  }
30642
31027
  function selected(ctx, args) {
30643
- const table3 = tableOf(ctx, args[0]);
30644
- const column2 = fieldIndex(table3, args[1]);
30645
- const matches2 = recordFilter(table3, ctx.toMatrix(args[2] ?? null).data);
30646
- return table3.records.filter(matches2).map((record2) => record2[column2] ?? null);
31028
+ const table4 = tableOf(ctx, args[0]);
31029
+ const column2 = fieldIndex(table4, args[1]);
31030
+ const matches2 = recordFilter(table4, ctx.toMatrix(args[2] ?? null).data);
31031
+ return table4.records.filter(matches2).map((record2) => record2[column2] ?? null);
30647
31032
  }
30648
31033
  var numbers = (values2) => {
30649
31034
  for (const v of values2) if (isError(v)) fail(v);
@@ -31471,9 +31856,9 @@ var BESSEL_FUNCTIONS = [
31471
31856
  ];
31472
31857
 
31473
31858
  // xlsx/formula/functions/convert.ts
31474
- var table = /* @__PURE__ */ new Map();
31859
+ var table2 = /* @__PURE__ */ new Map();
31475
31860
  var add3 = (dimension3, names, factor, extra = {}) => {
31476
- for (const name3 of names) table.set(name3, { dimension: dimension3, factor, ...extra });
31861
+ for (const name3 of names) table2.set(name3, { dimension: dimension3, factor, ...extra });
31477
31862
  };
31478
31863
  add3("mass", ["g"], 1, { prefix: "metric" });
31479
31864
  add3("mass", ["sg"], 14593.9029372064);
@@ -31604,10 +31989,10 @@ var BINARY2 = {
31604
31989
  ki: 2 ** 10
31605
31990
  };
31606
31991
  function resolve(name3) {
31607
- const direct = table.get(name3);
31992
+ const direct = table2.get(name3);
31608
31993
  if (direct) return { dimension: direct.dimension, factor: direct.factor };
31609
31994
  for (const length of [2, 1]) {
31610
- const unit3 = table.get(name3.slice(length));
31995
+ const unit3 = table2.get(name3.slice(length));
31611
31996
  const prefix3 = name3.slice(0, length);
31612
31997
  if (!unit3?.prefix) continue;
31613
31998
  const scale2 = (unit3.prefix === "binary" ? BINARY2[prefix3] : void 0) ?? METRIC[prefix3];
@@ -32942,30 +33327,30 @@ function findTable(host, name3, sheet, row3, col) {
32942
33327
  if (name3) {
32943
33328
  const lower3 = name3.toLowerCase();
32944
33329
  for (let s = 0; s < sheets.length; s++) {
32945
- const table4 = sheets[s]?.tables.find(
33330
+ const table5 = sheets[s]?.tables.find(
32946
33331
  (t) => t.displayName.toLowerCase() === lower3 || t.name.toLowerCase() === lower3
32947
33332
  );
32948
- if (table4) return { table: table4, sheet: s };
33333
+ if (table5) return { table: table5, sheet: s };
32949
33334
  }
32950
33335
  return void 0;
32951
33336
  }
32952
- const table3 = sheets[sheet]?.tables.find(
33337
+ const table4 = sheets[sheet]?.tables.find(
32953
33338
  (t) => row3 >= t.range.start.row && row3 <= t.range.end.row && col >= t.range.start.col && col <= t.range.end.col
32954
33339
  );
32955
- return table3 ? { table: table3, sheet } : void 0;
33340
+ return table4 ? { table: table4, sheet } : void 0;
32956
33341
  }
32957
33342
  function resolveStructured(ref, frame2) {
32958
33343
  const found = findTable(frame2.host, ref.table, frame2.sheet, frame2.row, frame2.col);
32959
33344
  if (!found) return ref.table ? ERR.NAME : ERR.REF;
32960
- const { table: table3, sheet } = found;
32961
- const range2 = normalizeRange(table3.range);
32962
- const headerRow = table3.headerRow ? range2.start.row : -1;
32963
- const dataStart = range2.start.row + (table3.headerRow ? 1 : 0);
32964
- const dataEnd = range2.end.row - (table3.totalsRow ? 1 : 0);
32965
- const totalsRow = table3.totalsRow ? range2.end.row : -1;
33345
+ const { table: table4, sheet } = found;
33346
+ const range2 = normalizeRange(table4.range);
33347
+ const headerRow = table4.headerRow ? range2.start.row : -1;
33348
+ const dataStart = range2.start.row + (table4.headerRow ? 1 : 0);
33349
+ const dataEnd = range2.end.row - (table4.totalsRow ? 1 : 0);
33350
+ const totalsRow = table4.totalsRow ? range2.end.row : -1;
32966
33351
  const columnOf = (name3) => {
32967
33352
  const lower3 = name3.toLowerCase();
32968
- const index3 = table3.columns.findIndex((c3) => c3.name.toLowerCase() === lower3);
33353
+ const index3 = table4.columns.findIndex((c3) => c3.name.toLowerCase() === lower3);
32969
33354
  return index3 < 0 ? -1 : range2.start.col + index3;
32970
33355
  };
32971
33356
  let c1 = range2.start.col;
@@ -34277,16 +34662,16 @@ function lookupArray(value2) {
34277
34662
  }
34278
34663
  function vhlookup(args, ctx, vertical2) {
34279
34664
  const lookup2 = blankAsZero(args);
34280
- const table3 = lookupArray(args[1] ?? null);
34665
+ const table4 = lookupArray(args[1] ?? null);
34281
34666
  const index3 = int3(args[2]);
34282
34667
  const approximate2 = args.length < 4 ? true : bool(args[3]);
34283
- const { rows, cols } = shape(table3);
34668
+ const { rows, cols } = shape(table4);
34284
34669
  if (index3 < 1) fail(ERR.VALUE);
34285
34670
  if (index3 > (vertical2 ? cols : rows)) fail(ERR.REF);
34286
- const keys = line2(ctx, table3, vertical2 ? "col" : "row", 0);
34671
+ const keys = line2(ctx, table4, vertical2 ? "col" : "row", 0);
34287
34672
  const at2 = approximate2 ? findAscending(keys, lookup2) : findExact(keys, lookup2, true);
34288
34673
  if (at2 < 0) fail(ERR.NA);
34289
- return vertical2 ? cellOf(table3, at2, index3 - 1) : cellOf(table3, index3 - 1, at2);
34674
+ return vertical2 ? cellOf(table4, at2, index3 - 1) : cellOf(table4, index3 - 1, at2);
34290
34675
  }
34291
34676
  function match(args, ctx) {
34292
34677
  const lookup2 = blankAsZero(args);
@@ -35730,10 +36115,10 @@ var REGRESSION_FUNCTIONS = [
35730
36115
  const lay = logs(layout2(ctx, args));
35731
36116
  const fit3 = fitLeastSquares(lay.x, lay.y, withConst(args, 2));
35732
36117
  const stats = !omitted(args, 3) && bool(args[3]);
35733
- const table3 = coefficientTable(fit3, stats, Math.exp);
35734
- if (!stats) return table3;
36118
+ const table4 = coefficientTable(fit3, stats, Math.exp);
36119
+ if (!stats) return table4;
35735
36120
  const plain5 = coefficientTable(fit3, true, (v) => v).data;
35736
- return new Matrix([table3.data[0] ?? [], ...plain5.slice(1)]);
36121
+ return new Matrix([table4.data[0] ?? [], ...plain5.slice(1)]);
35737
36122
  },
35738
36123
  ARGS
35739
36124
  ),
@@ -38119,7 +38504,7 @@ function headerMode(args, i2, ctx, firstRow) {
38119
38504
  if (mode === 1 || mode === 3) return true;
38120
38505
  return fail(ERR.VALUE);
38121
38506
  }
38122
- var keyOf = (values2) => JSON.stringify(values2);
38507
+ var keyOf2 = (values2) => JSON.stringify(values2);
38123
38508
  var plain2 = (v) => v === void 0 || isError(v) ? null : v;
38124
38509
  function compareBy(keys, rows) {
38125
38510
  return (a2, b) => {
@@ -38159,12 +38544,12 @@ function groupby(args, ctx) {
38159
38544
  if (rows.length === 0) fail(ERR.CALC);
38160
38545
  const groups = /* @__PURE__ */ new Map();
38161
38546
  for (const r of rows) {
38162
- const key2 = keyOf(keysM.data[r]);
38547
+ const key2 = keyOf2(keysM.data[r]);
38163
38548
  const found = groups.get(key2);
38164
38549
  if (found) found.push(r);
38165
38550
  else groups.set(key2, [r]);
38166
38551
  }
38167
- const table3 = [...groups.values()].map((members3) => {
38552
+ const table4 = [...groups.values()].map((members3) => {
38168
38553
  const key2 = keysM.data[members3[0]];
38169
38554
  const cells3 = Array.from(
38170
38555
  { length: vCols },
@@ -38176,8 +38561,8 @@ function groupby(args, ctx) {
38176
38561
  return [...key2, ...cells3];
38177
38562
  });
38178
38563
  for (const key2 of sort2) if (Math.abs(key2) > kCols + vCols) fail(ERR.VALUE);
38179
- const order = table3.map((_, i2) => i2).sort(compareBy(sort2, table3));
38180
- const out = order.map((i2) => table3[i2]);
38564
+ const order = table4.map((_, i2) => i2).sort(compareBy(sort2, table4));
38565
+ const out = order.map((i2) => table4[i2]);
38181
38566
  if (depth !== 0) {
38182
38567
  const total2 = [
38183
38568
  "Total",
@@ -38226,8 +38611,8 @@ function pivotby(args, ctx) {
38226
38611
  const colKeys = /* @__PURE__ */ new Map();
38227
38612
  for (const r of used) {
38228
38613
  for (const [map, key2] of [
38229
- [rowKeys, keyOf(rowsM.data[r])],
38230
- [colKeys, keyOf(colsM.data[r])]
38614
+ [rowKeys, keyOf2(rowsM.data[r])],
38615
+ [colKeys, keyOf2(colsM.data[r])]
38231
38616
  ]) {
38232
38617
  const found = map.get(key2);
38233
38618
  if (found) found.push(r);
@@ -38960,8 +39345,8 @@ function resolveName(node3, frame2) {
38960
39345
  const value2 = evaluateDefinedName(node3.name, sheet, node3.prefix !== void 0, frame2);
38961
39346
  if (value2 !== void 0) return value2;
38962
39347
  if (!node3.prefix) {
38963
- const table3 = resolveStructured({ table: node3.name, specials: [] }, frame2);
38964
- if (!(isError(table3) && table3.error === "#NAME?")) return table3;
39348
+ const table4 = resolveStructured({ table: node3.name, specials: [] }, frame2);
39349
+ if (!(isError(table4) && table4.error === "#NAME?")) return table4;
38965
39350
  }
38966
39351
  return ERR.NAME;
38967
39352
  }
@@ -40611,8 +40996,8 @@ function deleteSheetInFormula(formula, sheetName, tableNames = []) {
40611
40996
  for (const token of tokens3) {
40612
40997
  const prefix3 = token.prefix;
40613
40998
  const onSheet = prefix3 !== void 0 && prefix3.book === void 0 && prefix3.sheet2 === void 0 && same5(prefix3.sheet, sheetName);
40614
- const table3 = typeof token.value === "string" && tables.has(token.value.toLowerCase()) && (token.kind === "structured" || token.kind === "name" && !prefix3);
40615
- if ((token.kind === "ref" || token.kind === "name") && onSheet || table3) {
40999
+ const table4 = typeof token.value === "string" && tables.has(token.value.toLowerCase()) && (token.kind === "structured" || token.kind === "name" && !prefix3);
41000
+ if ((token.kind === "ref" || token.kind === "name") && onSheet || table4) {
40616
41001
  token.text = "#REF!";
40617
41002
  changed = true;
40618
41003
  }
@@ -40675,11 +41060,11 @@ function renameTableColumnInFormula(formula, tableName, oldName, newName, inside
40675
41060
  // xlsx/formula/structured-to-a1.ts
40676
41061
  var abs = (row3, col, rowAbs = true) => `$${columnLabel(col)}${rowAbs ? "$" : ""}${row3 + 1}`;
40677
41062
  function a1For(ref, t) {
40678
- const { table: table3 } = t;
40679
- const { start, end } = table3.range;
41063
+ const { table: table4 } = t;
41064
+ const { start, end } = table4.range;
40680
41065
  const index3 = (name3) => {
40681
41066
  if (name3 === void 0) return void 0;
40682
- const i2 = table3.columns.findIndex((c3) => c3.name.toLowerCase() === name3.toLowerCase());
41067
+ const i2 = table4.columns.findIndex((c3) => c3.name.toLowerCase() === name3.toLowerCase());
40683
41068
  return i2 < 0 ? -1 : start.col + i2;
40684
41069
  };
40685
41070
  const c1 = index3(ref.column);
@@ -40687,10 +41072,10 @@ function a1For(ref, t) {
40687
41072
  if (c1 === -1 || c2 === -1) return "#REF!";
40688
41073
  const colLo = c1 ?? start.col;
40689
41074
  const colHi = c2 ?? end.col;
40690
- const headerRow = table3.headerRow ? start.row : void 0;
40691
- const totalsRow = table3.totalsRow ? end.row : void 0;
40692
- const dataLo = start.row + (table3.headerRow ? 1 : 0);
40693
- const dataHi = end.row - (table3.totalsRow ? 1 : 0);
41075
+ const headerRow = table4.headerRow ? start.row : void 0;
41076
+ const totalsRow = table4.totalsRow ? end.row : void 0;
41077
+ const dataLo = start.row + (table4.headerRow ? 1 : 0);
41078
+ const dataHi = end.row - (table4.totalsRow ? 1 : 0);
40694
41079
  const specials = new Set(ref.specials);
40695
41080
  let rowLo;
40696
41081
  let rowHi;
@@ -42123,8 +42508,8 @@ function sheetDataXml(ctx, sheet) {
42123
42508
  ].sort((a2, b) => a2 - b);
42124
42509
  const spills = new SpillPlan(sheet);
42125
42510
  const tables = /* @__PURE__ */ new Map();
42126
- for (const table3 of sheet.dataTables ?? [])
42127
- tables.set(`${table3.ref.start.row}:${table3.ref.start.col}`, table3);
42511
+ for (const table4 of sheet.dataTables ?? [])
42512
+ tables.set(`${table4.ref.start.row}:${table4.ref.start.col}`, table4);
42128
42513
  let out = "";
42129
42514
  for (const row3 of rows) {
42130
42515
  const cells3 = sheet.rows.get(row3);
@@ -42606,29 +42991,29 @@ function setChildText(doc, parent, local, text8, before) {
42606
42991
  node3.textContent = text8;
42607
42992
  if (!existing) insertBefore(parent, node3, before);
42608
42993
  }
42609
- function tableFilterRange(table3) {
42994
+ function tableFilterRange(table4) {
42610
42995
  return {
42611
- start: table3.range.start,
42612
- end: { ...table3.range.end, row: table3.range.end.row - (table3.totalsRow ? 1 : 0) }
42996
+ start: table4.range.start,
42997
+ end: { ...table4.range.end, row: table4.range.end.row - (table4.totalsRow ? 1 : 0) }
42613
42998
  };
42614
42999
  }
42615
- function sourceColumnsForPatch(root, table3, names) {
43000
+ function sourceColumnsForPatch(root, table4, names) {
42616
43001
  const list2 = xKid(root, "tableColumns");
42617
43002
  const source2 = list2 ? xKids(list2, "tableColumn") : [];
42618
43003
  const byId2 = new Map(source2.map((c2) => [Number(c2.getAttribute("id")), c2]));
42619
43004
  const byName2 = new Map(source2.map((c2) => [(c2.getAttribute("name") ?? "").toLowerCase(), c2]));
42620
- const tracked = table3.partName !== void 0 || table3.columns.some((c2) => c2.sourceId !== void 0);
43005
+ const tracked = table4.partName !== void 0 || table4.columns.some((c2) => c2.sourceId !== void 0);
42621
43006
  const used = /* @__PURE__ */ new Set();
42622
43007
  return names.map((name3, index3) => {
42623
- const id3 = table3.columns[index3]?.sourceId;
43008
+ const id3 = table4.columns[index3]?.sourceId;
42624
43009
  const match2 = id3 !== void 0 ? byId2.get(id3) : tracked ? void 0 : source2.length === names.length ? source2[index3] : byName2.get(name3.toLowerCase());
42625
43010
  if (!match2 || used.has(match2)) return void 0;
42626
43011
  used.add(match2);
42627
43012
  return match2;
42628
43013
  });
42629
43014
  }
42630
- function syncColumnFilters(doc, filter2, table3) {
42631
- table3.columns.forEach((column2, index3) => {
43015
+ function syncColumnFilters(doc, filter2, table4) {
43016
+ table4.columns.forEach((column2, index3) => {
42632
43017
  const node3 = xKids(filter2, "filterColumn").find(
42633
43018
  (n) => Number(n.getAttribute("colId")) === index3
42634
43019
  );
@@ -42650,29 +43035,29 @@ function syncColumnFilters(doc, filter2, table3) {
42650
43035
  }
42651
43036
  });
42652
43037
  }
42653
- function patchAutoFilter(doc, root, table3, before, names) {
43038
+ function patchAutoFilter(doc, root, table4, before, names) {
42654
43039
  const existing = xKid(root, "autoFilter");
42655
- if (!table3.headerRow) {
43040
+ if (!table4.headerRow) {
42656
43041
  if (existing) root.removeChild(existing);
42657
43042
  return;
42658
43043
  }
42659
43044
  const filter2 = existing ?? doc.createElementNS(NS.x, "autoFilter");
42660
- const range2 = tableFilterRange(table3);
43045
+ const range2 = tableFilterRange(table4);
42661
43046
  filter2.setAttribute("ref", formatRange(range2));
42662
43047
  const list2 = xKid(root, "tableColumns");
42663
43048
  const original = list2 ? xKids(list2, "tableColumn") : [];
42664
- const current = new Map(sourceColumnsForPatch(root, table3, names).map((c2, index3) => [c2, index3]));
43049
+ const current = new Map(sourceColumnsForPatch(root, table4, names).map((c2, index3) => [c2, index3]));
42665
43050
  for (const column2 of xKids(filter2, "filterColumn")) {
42666
43051
  const old = original[Number(column2.getAttribute("colId") ?? "0")];
42667
43052
  const index3 = old ? current.get(old) : void 0;
42668
43053
  if (index3 === void 0) filter2.removeChild(column2);
42669
43054
  else column2.setAttribute("colId", num(index3));
42670
43055
  }
42671
- syncColumnFilters(doc, filter2, table3);
43056
+ syncColumnFilters(doc, filter2, table4);
42672
43057
  if (!existing) insertBefore(root, filter2, ["sortState", "tableColumns"]);
42673
43058
  const sort2 = xKid(filter2, "sortState") ?? xKid(root, "sortState");
42674
43059
  if (!sort2) return;
42675
- const moved = before.start.row !== table3.range.start.row || before.start.col !== table3.range.start.col || before.end.col !== table3.range.end.col;
43060
+ const moved = before.start.row !== table4.range.start.row || before.start.col !== table4.range.start.col || before.end.col !== table4.range.end.col;
42676
43061
  if (moved) {
42677
43062
  sort2.parentNode?.removeChild(sort2);
42678
43063
  return;
@@ -42694,7 +43079,7 @@ function patchAutoFilter(doc, root, table3, before, names) {
42694
43079
  }
42695
43080
  }
42696
43081
  var COLUMN_CHILD_ORDER = ["calculatedColumnFormula", "totalsRowFormula", "xmlColumnPr", "extLst"];
42697
- function patchColumns(doc, root, sheet, table3, names) {
43082
+ function patchColumns(doc, root, sheet, table4, names) {
42698
43083
  let list2 = xKid(root, "tableColumns");
42699
43084
  if (!list2) {
42700
43085
  list2 = doc.createElementNS(NS.x, "tableColumns");
@@ -42702,7 +43087,7 @@ function patchColumns(doc, root, sheet, table3, names) {
42702
43087
  }
42703
43088
  const sourceColumns = xKids(list2, "tableColumn");
42704
43089
  const ids = /* @__PURE__ */ new Set();
42705
- const picked = sourceColumnsForPatch(root, table3, names).map((match2) => {
43090
+ const picked = sourceColumnsForPatch(root, table4, names).map((match2) => {
42706
43091
  if (!match2) return void 0;
42707
43092
  const id3 = Number(match2.getAttribute("id"));
42708
43093
  if (Number.isInteger(id3) && id3 >= 0 && !ids.has(id3)) ids.add(id3);
@@ -42711,15 +43096,15 @@ function patchColumns(doc, root, sheet, table3, names) {
42711
43096
  });
42712
43097
  for (const column2 of sourceColumns) list2.removeChild(column2);
42713
43098
  let nextId3 = Math.max(0, ...ids) + 1;
42714
- const totalsRow = table3.range.end.row;
43099
+ const totalsRow = table4.range.end.row;
42715
43100
  names.forEach((name3, index3) => {
42716
43101
  const column2 = picked[index3] ?? doc.createElementNS(NS.x, "tableColumn");
42717
43102
  if (!column2.getAttribute("id")) column2.setAttribute("id", num(nextId3++));
42718
43103
  column2.setAttribute("name", name3);
42719
- const model = table3.columns[index3];
42720
- const fn = table3.totalsRow ? model?.totalsRowFunction : void 0;
43104
+ const model = table4.columns[index3];
43105
+ const fn = table4.totalsRow ? model?.totalsRowFunction : void 0;
42721
43106
  setOrRemove(column2, "totalsRowFunction", fn);
42722
- setOrRemove(column2, "totalsRowLabel", table3.totalsRow ? model?.totalsRowLabel : void 0);
43107
+ setOrRemove(column2, "totalsRowLabel", table4.totalsRow ? model?.totalsRowLabel : void 0);
42723
43108
  const calculated = model?.calculatedColumnFormula;
42724
43109
  setChildText(
42725
43110
  doc,
@@ -42730,7 +43115,7 @@ function patchColumns(doc, root, sheet, table3, names) {
42730
43115
  );
42731
43116
  if (fn !== "custom") setChildText(doc, column2, "totalsRowFormula", void 0, []);
42732
43117
  else {
42733
- const cellFormula = sheet.rows.get(totalsRow)?.get(table3.range.start.col + index3)?.formula;
43118
+ const cellFormula = sheet.rows.get(totalsRow)?.get(table4.range.start.col + index3)?.formula;
42734
43119
  if (cellFormula)
42735
43120
  setChildText(
42736
43121
  doc,
@@ -42744,19 +43129,19 @@ function patchColumns(doc, root, sheet, table3, names) {
42744
43129
  });
42745
43130
  list2.setAttribute("count", num(names.length));
42746
43131
  }
42747
- function patchStyleInfo(doc, root, table3) {
43132
+ function patchStyleInfo(doc, root, table4) {
42748
43133
  let info = xKid(root, "tableStyleInfo");
42749
43134
  if (!info) {
42750
43135
  info = doc.createElementNS(NS.x, "tableStyleInfo");
42751
43136
  insertBefore(root, info, ["extLst"]);
42752
43137
  }
42753
- setOrRemove(info, "name", table3.styleName);
42754
- info.setAttribute("showFirstColumn", flag2(table3.showFirstColumn, false));
42755
- info.setAttribute("showLastColumn", flag2(table3.showLastColumn, false));
42756
- info.setAttribute("showRowStripes", flag2(table3.showRowStripes, true));
42757
- info.setAttribute("showColumnStripes", flag2(table3.showColumnStripes, false));
43138
+ setOrRemove(info, "name", table4.styleName);
43139
+ info.setAttribute("showFirstColumn", flag2(table4.showFirstColumn, false));
43140
+ info.setAttribute("showLastColumn", flag2(table4.showLastColumn, false));
43141
+ info.setAttribute("showRowStripes", flag2(table4.showRowStripes, true));
43142
+ info.setAttribute("showColumnStripes", flag2(table4.showColumnStripes, false));
42758
43143
  }
42759
- function patchTableXml(sourceXml, sheet, table3, id3, names) {
43144
+ function patchTableXml(sourceXml, sheet, table4, id3, names) {
42760
43145
  let doc;
42761
43146
  try {
42762
43147
  doc = parseXml(sourceXml, { label: "XLSX table" });
@@ -42765,80 +43150,80 @@ function patchTableXml(sourceXml, sheet, table3, id3, names) {
42765
43150
  }
42766
43151
  const root = doc.documentElement;
42767
43152
  if (root.localName !== "table") return void 0;
42768
- const before = parseRange(root.getAttribute("ref") ?? "") ?? table3.range;
43153
+ const before = parseRange(root.getAttribute("ref") ?? "") ?? table4.range;
42769
43154
  root.setAttribute("id", num(id3));
42770
- root.setAttribute("name", table3.name);
42771
- root.setAttribute("displayName", table3.displayName || table3.name);
42772
- root.setAttribute("ref", formatRange(table3.range));
42773
- setOrRemove(root, "headerRowCount", table3.headerRow ? void 0 : "0");
42774
- if (table3.totalsRow) {
43155
+ root.setAttribute("name", table4.name);
43156
+ root.setAttribute("displayName", table4.displayName || table4.name);
43157
+ root.setAttribute("ref", formatRange(table4.range));
43158
+ setOrRemove(root, "headerRowCount", table4.headerRow ? void 0 : "0");
43159
+ if (table4.totalsRow) {
42775
43160
  root.setAttribute("totalsRowCount", "1");
42776
43161
  root.removeAttribute("totalsRowShown");
42777
43162
  } else {
42778
43163
  root.removeAttribute("totalsRowCount");
42779
43164
  if (!root.hasAttribute("totalsRowShown")) root.setAttribute("totalsRowShown", "0");
42780
43165
  }
42781
- patchAutoFilter(doc, root, table3, before, names);
42782
- patchColumns(doc, root, sheet, table3, names);
42783
- patchStyleInfo(doc, root, table3);
43166
+ patchAutoFilter(doc, root, table4, before, names);
43167
+ patchColumns(doc, root, sheet, table4, names);
43168
+ patchStyleInfo(doc, root, table4);
42784
43169
  return buildXml(doc);
42785
43170
  }
42786
43171
 
42787
43172
  // xlsx/write/tables.ts
42788
43173
  var headerTextOf = (value2) => typeof value2 === "string" ? value2 : typeof value2 === "number" || typeof value2 === "boolean" ? String(value2).toUpperCase() : void 0;
42789
- function resolveTableColumns(sheet, table3) {
43174
+ function resolveTableColumns(sheet, table4) {
42790
43175
  const headerText = /* @__PURE__ */ new Map();
42791
43176
  const used = /* @__PURE__ */ new Set();
42792
- const width = table3.range.end.col - table3.range.start.col + 1;
43177
+ const width = table4.range.end.col - table4.range.start.col + 1;
42793
43178
  const names = [];
42794
43179
  for (let i2 = 0; i2 < width; i2++) {
42795
- const col = table3.range.start.col + i2;
42796
- const row3 = table3.range.start.row;
42797
- const fromCell = table3.headerRow ? headerTextOf(sheet.rows.get(row3)?.get(col)?.value) : void 0;
42798
- let name3 = (fromCell?.trim() ? fromCell : void 0) ?? table3.columns[i2]?.name ?? `Column${i2 + 1}`;
43180
+ const col = table4.range.start.col + i2;
43181
+ const row3 = table4.range.start.row;
43182
+ const fromCell = table4.headerRow ? headerTextOf(sheet.rows.get(row3)?.get(col)?.value) : void 0;
43183
+ let name3 = (fromCell?.trim() ? fromCell : void 0) ?? table4.columns[i2]?.name ?? `Column${i2 + 1}`;
42799
43184
  if (!name3.trim()) name3 = `Column${i2 + 1}`;
42800
43185
  let unique4 = name3;
42801
43186
  for (let n = 2; used.has(unique4.toLowerCase()); n++) unique4 = `${name3}${n}`;
42802
43187
  used.add(unique4.toLowerCase());
42803
43188
  names.push(unique4);
42804
43189
  const cell = sheet.rows.get(row3)?.get(col);
42805
- if (table3.headerRow && (typeof cell?.value !== "string" || cell.value !== unique4))
43190
+ if (table4.headerRow && (typeof cell?.value !== "string" || cell.value !== unique4))
42806
43191
  headerText.set(`${row3}:${col}`, unique4);
42807
43192
  }
42808
43193
  return { names, headerText };
42809
43194
  }
42810
- function tableXml(table3, id3, names) {
42811
- const range2 = formatRange(table3.range);
42812
- const filterEnd = { ...table3.range.end, row: table3.range.end.row - (table3.totalsRow ? 1 : 0) };
42813
- const criteria = table3.columns.map((column2, index3) => column2.filter ? filterColumnXml(index3, column2.filter) : "").join("");
42814
- const filterRef = formatRange({ start: table3.range.start, end: filterEnd });
42815
- const filter2 = table3.headerRow ? criteria ? `<autoFilter ref="${filterRef}">${criteria}</autoFilter>` : `<autoFilter ref="${filterRef}"/>` : "";
43195
+ function tableXml(table4, id3, names) {
43196
+ const range2 = formatRange(table4.range);
43197
+ const filterEnd = { ...table4.range.end, row: table4.range.end.row - (table4.totalsRow ? 1 : 0) };
43198
+ const criteria = table4.columns.map((column2, index3) => column2.filter ? filterColumnXml(index3, column2.filter) : "").join("");
43199
+ const filterRef = formatRange({ start: table4.range.start, end: filterEnd });
43200
+ const filter2 = table4.headerRow ? criteria ? `<autoFilter ref="${filterRef}">${criteria}</autoFilter>` : `<autoFilter ref="${filterRef}"/>` : "";
42816
43201
  const columns = names.map((name3, index3) => {
42817
- const column2 = table3.columns[index3];
43202
+ const column2 = table4.columns[index3];
42818
43203
  const calculated = column2?.calculatedColumnFormula ? `<calculatedColumnFormula>${escapeText3(addFuturePrefixes(column2.calculatedColumnFormula))}</calculatedColumnFormula>` : "";
42819
43204
  const values2 = attrs2({
42820
43205
  id: index3 + 1,
42821
43206
  name: name3,
42822
- totalsRowFunction: table3.totalsRow ? column2?.totalsRowFunction : void 0,
42823
- totalsRowLabel: table3.totalsRow ? column2?.totalsRowLabel : void 0
43207
+ totalsRowFunction: table4.totalsRow ? column2?.totalsRowFunction : void 0,
43208
+ totalsRowLabel: table4.totalsRow ? column2?.totalsRowLabel : void 0
42824
43209
  });
42825
43210
  return calculated ? `<tableColumn${values2}>${calculated}</tableColumn>` : `<tableColumn${values2}/>`;
42826
43211
  }).join("");
42827
43212
  const style3 = attrs2({
42828
- name: table3.styleName,
42829
- showFirstColumn: table3.showFirstColumn ?? false,
42830
- showLastColumn: table3.showLastColumn ?? false,
42831
- showRowStripes: table3.showRowStripes ?? true,
42832
- showColumnStripes: table3.showColumnStripes ?? false
43213
+ name: table4.styleName,
43214
+ showFirstColumn: table4.showFirstColumn ?? false,
43215
+ showLastColumn: table4.showLastColumn ?? false,
43216
+ showRowStripes: table4.showRowStripes ?? true,
43217
+ showColumnStripes: table4.showColumnStripes ?? false
42833
43218
  });
42834
43219
  const head = attrs2({
42835
43220
  id: id3,
42836
- name: table3.name,
42837
- displayName: table3.displayName || table3.name,
43221
+ name: table4.name,
43222
+ displayName: table4.displayName || table4.name,
42838
43223
  ref: range2,
42839
- headerRowCount: table3.headerRow ? void 0 : 0,
42840
- totalsRowCount: table3.totalsRow ? 1 : void 0,
42841
- totalsRowShown: table3.totalsRow ? void 0 : false
43224
+ headerRowCount: table4.headerRow ? void 0 : 0,
43225
+ totalsRowCount: table4.totalsRow ? 1 : void 0,
43226
+ totalsRowShown: table4.totalsRow ? void 0 : false
42842
43227
  });
42843
43228
  return `${XML_HEADER}<table xmlns="${NS.x}"${head}>${filter2}<tableColumns count="${names.length}">${columns}</tableColumns><tableStyleInfo${style3}/></table>`;
42844
43229
  }
@@ -42852,24 +43237,24 @@ var SUBTOTAL_CODES = {
42852
43237
  sum: 109,
42853
43238
  var: 110
42854
43239
  };
42855
- function totalsRowFormulas(sheet, table3, names) {
43240
+ function totalsRowFormulas(sheet, table4, names) {
42856
43241
  const out = /* @__PURE__ */ new Map();
42857
- if (!table3.totalsRow) return out;
42858
- const row3 = table3.range.end.row;
43242
+ if (!table4.totalsRow) return out;
43243
+ const row3 = table4.range.end.row;
42859
43244
  names.forEach((name3, index3) => {
42860
- const code = SUBTOTAL_CODES[table3.columns[index3]?.totalsRowFunction ?? ""];
43245
+ const code = SUBTOTAL_CODES[table4.columns[index3]?.totalsRowFunction ?? ""];
42861
43246
  if (code === void 0) return;
42862
- const col = table3.range.start.col + index3;
43247
+ const col = table4.range.start.col + index3;
42863
43248
  const escaped = name3.replace(/['#[\]]/g, "'$&");
42864
- const formula = `SUBTOTAL(${code},${table3.displayName || table3.name}[${escaped}])`;
43249
+ const formula = `SUBTOTAL(${code},${table4.displayName || table4.name}[${escaped}])`;
42865
43250
  if (sheet.rows.get(row3)?.get(col)?.formula !== formula) out.set(`${row3}:${col}`, formula);
42866
43251
  });
42867
43252
  return out;
42868
43253
  }
42869
- function resolveTableNames(table3, before, index3) {
42870
- const display = table3.displayName || table3.name;
43254
+ function resolveTableNames(table4, before, index3) {
43255
+ const display = table4.displayName || table4.name;
42871
43256
  const displayName = before && before.displayName === display ? display : safeTableName(display, index3);
42872
- const name3 = before && before.name === table3.name ? table3.name : table3.name === display ? displayName : safeTableName(table3.name, index3);
43257
+ const name3 = before && before.name === table4.name ? table4.name : table4.name === display ? displayName : safeTableName(table4.name, index3);
42873
43258
  return { name: name3, displayName };
42874
43259
  }
42875
43260
  function safeTableName(name3, index3) {
@@ -42962,21 +43347,21 @@ function writeTables(ctx, sheet, partName, rels, headerText, formulas) {
42962
43347
  const sourceXml = original.partName ? source2?.text(original.partName) : void 0;
42963
43348
  const before = sourceXml && original.partName ? parseTable3(sourceXml, original.partName) : void 0;
42964
43349
  const { name: name3, displayName } = resolveTableNames(original, before, index3 + 1);
42965
- const table3 = name3 === original.name && displayName === original.displayName ? original : { ...original, name: name3, displayName };
42966
- const { names, headerText: forced } = resolveTableColumns(sheet, table3);
43350
+ const table4 = name3 === original.name && displayName === original.displayName ? original : { ...original, name: name3, displayName };
43351
+ const { names, headerText: forced } = resolveTableColumns(sheet, table4);
42967
43352
  for (const [key2, text8] of forced) headerText.set(key2, text8);
42968
- const totals = totalsRowFormulas(sheet, table3, names);
43353
+ const totals = totalsRowFormulas(sheet, table4, names);
42969
43354
  for (const [key2, formula] of totals) formulas.set(key2, formula);
42970
- let id3 = table3.id;
42971
- const unchanged = table3.partName && sourceXml && !writer.has(table3.partName) && !ctx.tableIds.has(id3) && forced.size === 0 && totals.size === 0 && table3 === original && sameModel(before, table3);
43355
+ let id3 = table4.id;
43356
+ const unchanged = table4.partName && sourceXml && !writer.has(table4.partName) && !ctx.tableIds.has(id3) && forced.size === 0 && totals.size === 0 && table4 === original && sameModel(before, table4);
42972
43357
  let part;
42973
- if (unchanged && table3.partName) {
42974
- part = table3.partName;
43358
+ if (unchanged && table4.partName) {
43359
+ part = table4.partName;
42975
43360
  writer.carry(part);
42976
43361
  } else {
42977
43362
  while (ctx.tableIds.has(id3) || id3 < 1) id3++;
42978
- part = table3.partName && !writer.has(table3.partName) ? table3.partName : writer.uniqueName((n) => `xl/tables/table${n}.xml`, ctx.reserved);
42979
- const xml = (sourceXml && patchTableXml(sourceXml, sheet, table3, id3, names)) ?? tableXml(table3, id3, names);
43363
+ part = table4.partName && !writer.has(table4.partName) ? table4.partName : writer.uniqueName((n) => `xl/tables/table${n}.xml`, ctx.reserved);
43364
+ const xml = (sourceXml && patchTableXml(sourceXml, sheet, table4, id3, names)) ?? tableXml(table4, id3, names);
42980
43365
  writer.add(part, xml, CONTENT_TYPES.table);
42981
43366
  }
42982
43367
  ctx.tableIds.add(id3);
@@ -43421,13 +43806,13 @@ function derivedFieldXml(pivot, entry3, date1904) {
43421
43806
  const days = dateGroupDays(entry3.group);
43422
43807
  const labels = dateUnitLabels(entry3.unit, range2, days, date1904, entry3.group);
43423
43808
  const base2 = pivot.fields.indexOf(entry3.group.field);
43424
- return `<cacheField${attrs2({ name: encodeEscapes(entry3.name), numFmtId: 0, databaseField: false })}><fieldGroup base="${base2}"><rangePr${attrs2({ autoStart: entry3.autoStart ? void 0 : false, autoEnd: entry3.autoEnd ? void 0 : false, groupBy: entry3.unit, startDate: serialToIso(range2.start, date1904), endDate: serialToIso(range2.end, date1904), groupInterval: days > 1 ? days : void 0 })}/><groupItems count="${labels.length}">${labels.map((label4) => `<s v="${escapeAttr3(label4)}"/>`).join("")}</groupItems></fieldGroup></cacheField>`;
43809
+ return `<cacheField${attrs2({ name: encodeEscapes(entry3.name), numFmtId: 0, databaseField: false })}><fieldGroup base="${base2}"><rangePr${attrs2({ autoStart: entry3.autoStart ? void 0 : false, autoEnd: entry3.autoEnd ? void 0 : false, groupBy: entry3.unit, startDate: serialToIso(range2.start, date1904), endDate: serialToIso(range2.end, date1904), groupInterval: days > 1 ? days : void 0 })}/><groupItems count="${labels.length}">${labels.map((label2) => `<s v="${escapeAttr3(label2)}"/>`).join("")}</groupItems></fieldGroup></cacheField>`;
43425
43810
  }
43426
43811
  function groupXml2(pivot, name3, index3) {
43427
43812
  const group = groupOf(pivot, name3);
43428
43813
  if (!group) return "";
43429
43814
  const labels = numberGroupLabels(group);
43430
- return `<fieldGroup base="${index3}"><rangePr autoStart="0" autoEnd="0" startNum="${group.start}" endNum="${group.end}" groupInterval="${group.by}"/><groupItems count="${labels.length}">${labels.map((label4) => `<s v="${escapeAttr3(label4)}"/>`).join("")}</groupItems></fieldGroup>`;
43815
+ return `<fieldGroup base="${index3}"><rangePr autoStart="0" autoEnd="0" startNum="${group.start}" endNum="${group.end}" groupInterval="${group.by}"/><groupItems count="${labels.length}">${labels.map((label2) => `<s v="${escapeAttr3(label2)}"/>`).join("")}</groupItems></fieldGroup>`;
43431
43816
  }
43432
43817
  function slicerExt(pivot) {
43433
43818
  if (pivot.slicerCacheId === void 0) return "";
@@ -43487,6 +43872,10 @@ function pivotTableXml(source2, cacheId, cache3) {
43487
43872
  const compact3 = pivot.layout === "compact";
43488
43873
  const outline2 = pivot.layout === "compact" || pivot.layout === "outline";
43489
43874
  const top = (pivot.subtotalPosition ?? (outline2 ? "top" : "bottom")) === "top";
43875
+ const named3 = (field2, item) => {
43876
+ const text8 = pivotItemName(pivot, field2, item);
43877
+ return text8 === void 0 ? "" : attrs2({ n: encodeEscapes(text8) });
43878
+ };
43490
43879
  const fields = pivot.fields.map((name3, index3) => {
43491
43880
  const isDate = pivot.dateFields?.includes(name3) ?? false;
43492
43881
  const at2 = rowIdx.indexOf(index3);
@@ -43501,7 +43890,7 @@ function pivotTableXml(source2, cacheId, cache3) {
43501
43890
  custom.map((fn) => [PIVOT_SUBTOTALS[fn].attr, true])
43502
43891
  );
43503
43892
  const entries = automatic ? '<item t="default"/>' : custom.map((fn) => `<item t="${PIVOT_SUBTOTALS[fn].item}"/>`).join("");
43504
- return `<pivotField${attrs2({ axis: index3 === page ? "axisPage" : at2 >= 0 ? "axisRow" : colAt >= 0 ? "axisCol" : void 0, dataField: measures2.some((measure2) => pivot.fields.indexOf(measure2.field) === index3) ? true : void 0, compact: compact3, outline: outline2, showAll: false, subtotalTop: at2 >= 0 ? top : void 0, numFmtId: isDate ? 14 : void 0, defaultSubtotal: automatic ? void 0 : false, ...flags })}>${items2 ? `<items count="${items2.length + (automatic ? 1 : custom.length)}">${items2.map((item) => `<item${hidden.has(pivotValueKey(item)) ? ' h="1"' : ""} x="${itemX(index3, item)}"/>`).join("")}${entries}</items>` : ""}${repeated}</pivotField>`;
43893
+ return `<pivotField${attrs2({ axis: index3 === page ? "axisPage" : at2 >= 0 ? "axisRow" : colAt >= 0 ? "axisCol" : void 0, dataField: measures2.some((measure2) => pivot.fields.indexOf(measure2.field) === index3) ? true : void 0, compact: compact3, outline: outline2, showAll: false, subtotalTop: at2 >= 0 ? top : void 0, numFmtId: isDate ? 14 : void 0, defaultSubtotal: automatic ? void 0 : false, ...flags })}>${items2 ? `<items count="${items2.length + (automatic ? 1 : custom.length)}">${items2.map((item) => `<item${hidden.has(pivotValueKey(item)) ? ' h="1"' : ""}${named3(name3, item)} x="${itemX(index3, item)}"/>`).join("")}${entries}</items>` : ""}${repeated}</pivotField>`;
43505
43894
  }).join("");
43506
43895
  const items = (count2, indices) => Array.from({ length: count2 }, (_v, i2) => `<i><x v="${indices?.[i2] ?? i2}"/></i>`).join("") + '<i t="grand"><x/></i>';
43507
43896
  const header = grid.firstHeaderRow !== void 0 ? grid.firstHeaderRow - pageOffset : col >= 0 ? 1 : grid.firstDataRow - pageOffset - 1;
@@ -43531,6 +43920,15 @@ function pivotTableXml(source2, cacheId, cache3) {
43531
43920
  const root = doc.documentElement;
43532
43921
  root.setAttribute("name", pivot.name);
43533
43922
  root.setAttribute("cacheId", String(cacheId));
43923
+ const caps = pivotCaptions(pivot);
43924
+ root.setAttribute("dataCaption", caps.values);
43925
+ for (const [attribute4, key2] of [
43926
+ ["rowHeaderCaption", "rowLabels"],
43927
+ ["colHeaderCaption", "columnLabels"],
43928
+ ["grandTotalCaption", "grandTotal"]
43929
+ ])
43930
+ if (caps[key2] !== ENGLISH_PIVOT_CAPTIONS[key2] || root.hasAttribute(attribute4))
43931
+ root.setAttribute(attribute4, caps[key2]);
43534
43932
  root.setAttribute("dataOnRows", rowsAxis ? "1" : "0");
43535
43933
  if (rowsAxis && valuesAt < rowIdx.length) root.setAttribute("dataPosition", String(valuesAt));
43536
43934
  else root.removeAttribute("dataPosition");
@@ -43654,7 +44052,7 @@ var PivotWritePlan = class {
43654
44052
  this.tableParts.set(pivot, pivot.partName);
43655
44053
  continue;
43656
44054
  }
43657
- const table3 = pivot.partName ?? writer.uniqueName((n) => `xl/pivotTables/pivotTable${n}.xml`, reserved);
44055
+ const table4 = pivot.partName ?? writer.uniqueName((n) => `xl/pivotTables/pivotTable${n}.xml`, reserved);
43658
44056
  const definition = writer.uniqueName(
43659
44057
  (n) => `xl/pivotCache/pivotCacheDefinition${n}.xml`,
43660
44058
  reserved
@@ -43676,24 +44074,24 @@ var PivotWritePlan = class {
43676
44074
  TYPES2.definition
43677
44075
  );
43678
44076
  writer.rels(definition, cacheRels);
43679
- writer.add(table3, pivotTableXml(pivot, cacheId, cache3), TYPES2.table);
44077
+ writer.add(table4, pivotTableXml(pivot, cacheId, cache3), TYPES2.table);
43680
44078
  const tableRels = new RelationshipSet();
43681
- tableRels.add(RELATIONSHIP_TYPES.pivotCacheDefinition, relativeTarget(table3, definition));
43682
- writer.rels(table3, tableRels);
44079
+ tableRels.add(RELATIONSHIP_TYPES.pivotCacheDefinition, relativeTarget(table4, definition));
44080
+ writer.rels(table4, tableRels);
43683
44081
  const rid2 = bookRels.add(
43684
44082
  RELATIONSHIP_TYPES.pivotCacheDefinition,
43685
44083
  relativeTarget(bookPart, definition)
43686
44084
  );
43687
44085
  entries.push(`<pivotCache cacheId="${cacheId++}" r:id="${rid2}"/>`);
43688
- this.tableParts.set(pivot, table3);
44086
+ this.tableParts.set(pivot, table4);
43689
44087
  }
43690
44088
  this.cachesXml = owns ? entries.length ? `<pivotCaches>${entries.join("")}</pivotCaches>` : "" : void 0;
43691
44089
  }
43692
44090
  writeSheet(writer, sheet, part, rels) {
43693
44091
  for (const pivot of sheet.pivotTables ?? []) {
43694
- const table3 = this.tableParts.get(pivot);
43695
- writer.carry(table3);
43696
- rels.add(RELATIONSHIP_TYPES.pivotTable, relativeTarget(part, table3));
44092
+ const table4 = this.tableParts.get(pivot);
44093
+ writer.carry(table4);
44094
+ rels.add(RELATIONSHIP_TYPES.pivotTable, relativeTarget(part, table4));
43697
44095
  }
43698
44096
  }
43699
44097
  };
@@ -43863,9 +44261,9 @@ function slicerTarget(workbook, cache3) {
43863
44261
  const source2 = cache3.source;
43864
44262
  for (const [sheetIndex2, sheet] of workbook.sheets.entries()) {
43865
44263
  if (source2.kind === "table") {
43866
- const table3 = sheet.tables.find((entry3) => entry3.id === source2.tableId);
43867
- const offset2 = table3?.columns.findIndex((column2) => column2.sourceId === source2.column) ?? -1;
43868
- if (table3 && offset2 >= 0) return { kind: "table", sheet, sheetIndex: sheetIndex2, table: table3, offset: offset2 };
44264
+ const table4 = sheet.tables.find((entry3) => entry3.id === source2.tableId);
44265
+ const offset2 = table4?.columns.findIndex((column2) => column2.sourceId === source2.column) ?? -1;
44266
+ if (table4 && offset2 >= 0) return { kind: "table", sheet, sheetIndex: sheetIndex2, table: table4, offset: offset2 };
43869
44267
  } else {
43870
44268
  const first3 = source2.pivots[0];
43871
44269
  const pivot = first3 && sheet.sheetId === first3.tabId ? sheet.pivotTables?.find((entry3) => entry3.name === first3.name) : void 0;
@@ -44054,12 +44452,12 @@ function slicerCacheXml(cache3, facts) {
44054
44452
  ext.setAttribute("xmlns:x15", X153);
44055
44453
  list2.appendChild(ext);
44056
44454
  }
44057
- let table3 = first(ext, "tableSlicerCache", X153);
44058
- if (!table3) table3 = ext.appendChild(make2(X153, "x15:tableSlicerCache"));
44059
- table3.setAttribute("tableId", String(source2.tableId));
44060
- table3.setAttribute("column", String(source2.column));
44061
- if (cache3.sortOrder === "descending") table3.setAttribute("sortOrder", "descending");
44062
- else table3.removeAttribute("sortOrder");
44455
+ let table4 = first(ext, "tableSlicerCache", X153);
44456
+ if (!table4) table4 = ext.appendChild(make2(X153, "x15:tableSlicerCache"));
44457
+ table4.setAttribute("tableId", String(source2.tableId));
44458
+ table4.setAttribute("column", String(source2.column));
44459
+ if (cache3.sortOrder === "descending") table4.setAttribute("sortOrder", "descending");
44460
+ else table4.removeAttribute("sortOrder");
44063
44461
  return XML_HEADER + buildXml(root);
44064
44462
  }
44065
44463
 
@@ -44612,12 +45010,12 @@ function rewriteSheetFormulas(sheet, rewrite2, formulaCells) {
44612
45010
  }
44613
45011
  {
44614
45012
  const name3 = sheet.name;
44615
- for (const table3 of sheet.tables)
44616
- for (const [index3, column2] of table3.columns.entries())
45013
+ for (const table4 of sheet.tables)
45014
+ for (const [index3, column2] of table4.columns.entries())
44617
45015
  if (column2.calculatedColumnFormula !== void 0)
44618
45016
  column2.calculatedColumnFormula = safe(rewrite2, column2.calculatedColumnFormula, name3, {
44619
- row: table3.range.start.row + (table3.headerRow ? 1 : 0),
44620
- col: table3.range.start.col + index3
45017
+ row: table4.range.start.row + (table4.headerRow ? 1 : 0),
45018
+ col: table4.range.start.col + index3
44621
45019
  });
44622
45020
  if (formulaCells) {
44623
45021
  for (const at2 of formulaCells) {
@@ -44682,14 +45080,14 @@ function tableHeaderAt(sheet, row3, col) {
44682
45080
  );
44683
45081
  }
44684
45082
  function syncTableHeader(ctx, sheet, row3, col, formulaCells) {
44685
- const table3 = tableHeaderAt(sheet, row3, col);
44686
- if (!table3) return;
44687
- const column2 = table3.columns[col - table3.range.start.col];
45083
+ const table4 = tableHeaderAt(sheet, row3, col);
45084
+ if (!table4) return;
45085
+ const column2 = table4.columns[col - table4.range.start.col];
44688
45086
  if (!column2) return;
44689
45087
  const text8 = displayText(ctx.workbook, getCell(sheet, row3, col)).trim();
44690
45088
  if (!text8 || column2.name === text8) return;
44691
45089
  const oldName = column2.name;
44692
- const others = table3.columns.filter((entry3) => entry3 !== column2).map((entry3) => entry3.name);
45090
+ const others = table4.columns.filter((entry3) => entry3 !== column2).map((entry3) => entry3.name);
44693
45091
  const newName = uniqueHeaders([...others, text8]).at(-1);
44694
45092
  column2.name = newName;
44695
45093
  if (newName !== text8) writeValue(sheet, row3, col, newName);
@@ -44699,10 +45097,10 @@ function syncTableHeader(ctx, sheet, row3, col, formulaCells) {
44699
45097
  ctx.workbook,
44700
45098
  (formula, formulaSheet, at2) => renameTableColumnInFormula(
44701
45099
  formula,
44702
- table3.name,
45100
+ table4.name,
44703
45101
  oldName,
44704
45102
  newName,
44705
- formulaSheet === sheet.name && !!at2 && rangeContains(table3.range, at2)
45103
+ formulaSheet === sheet.name && !!at2 && rangeContains(table4.range, at2)
44706
45104
  ),
44707
45105
  cells3
44708
45106
  );
@@ -45826,11 +46224,11 @@ function uniqueColumnName(columns) {
45826
46224
  const taken = new Set(columns.map((c2) => c2.name.toLowerCase()));
45827
46225
  for (let n = 1; ; n++) if (!taken.has(`column${n}`)) return `Column${n}`;
45828
46226
  }
45829
- function shiftTable(sheet, table3, shift2, moveRange) {
45830
- const old = table3.range;
46227
+ function shiftTable(sheet, table4, shift2, moveRange) {
46228
+ const old = table4.range;
45831
46229
  const range2 = moveRange(old);
45832
46230
  if (!range2) return [];
45833
- const next = { ...table3, range: range2, columns: [...table3.columns] };
46231
+ const next = { ...table4, range: range2, columns: [...table4.columns] };
45834
46232
  const widened = range2.end.col - range2.start.col !== old.end.col - old.start.col;
45835
46233
  if (shift2.axis === "col" && widened) {
45836
46234
  if (shift2.count > 0) {
@@ -46306,8 +46704,8 @@ function cellText(inner2) {
46306
46704
  ).replace(/ /g, " ").trim();
46307
46705
  }
46308
46706
  function parseHtmlTable(html, base2) {
46309
- const table3 = /<table\b[^>]*>([\s\S]*?)<\/table>/i.exec(html)?.[1];
46310
- if (table3 === void 0) return void 0;
46707
+ const table4 = /<table\b[^>]*>([\s\S]*?)<\/table>/i.exec(html)?.[1];
46708
+ if (table4 === void 0) return void 0;
46311
46709
  const classes = /* @__PURE__ */ new Map();
46312
46710
  for (const block of html.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi))
46313
46711
  for (const rule2 of removeAll(block[1] ?? "", ["<!--", "-->"]).matchAll(
@@ -46320,7 +46718,7 @@ function parseHtmlTable(html, base2) {
46320
46718
  const hyperlinks = [];
46321
46719
  let r = 0;
46322
46720
  let spanned = 0;
46323
- for (const tr of table3.matchAll(/<tr\b[^>]*>([\s\S]*?)(?=<tr\b|<\/tbody|<\/table|$)/gi)) {
46721
+ for (const tr of table4.matchAll(/<tr\b[^>]*>([\s\S]*?)(?=<tr\b|<\/tbody|<\/table|$)/gi)) {
46324
46722
  const row3 = grid[r] ??= [];
46325
46723
  let c2 = 0;
46326
46724
  for (const td of (tr[1] ?? "").matchAll(
@@ -47172,9 +47570,9 @@ function filterColumn(ctx, s, col, values2) {
47172
47570
  }
47173
47571
  function sortByColumn(ctx, s, col, descending) {
47174
47572
  const sheet = sheetAt(ctx.workbook, s);
47175
- const table3 = sheet.tables.find((t) => col >= t.range.start.col && col <= t.range.end.col);
47573
+ const table4 = sheet.tables.find((t) => col >= t.range.start.col && col <= t.range.end.col);
47176
47574
  const filter2 = sheet.autoFilter;
47177
- const target2 = table3 ? { range: table3.range, header: table3.headerRow, totals: table3.totalsRow } : filter2 && rangeContains(filter2.range, { row: filter2.range.start.row, col }) ? { range: filter2.range, header: true, totals: false } : void 0;
47575
+ const target2 = table4 ? { range: table4.range, header: table4.headerRow, totals: table4.totalsRow } : filter2 && rangeContains(filter2.range, { row: filter2.range.start.row, col }) ? { range: filter2.range, header: true, totals: false } : void 0;
47178
47576
  if (!target2) throw new Error("The column is not inside a table or an auto-filter range.");
47179
47577
  const range2 = target2.totals ? { start: target2.range.start, end: { ...target2.range.end, row: target2.range.end.row - 1 } } : target2.range;
47180
47578
  ctx.run(
@@ -47234,12 +47632,12 @@ function restore(sheet, saved) {
47234
47632
  Object.assign(cell, saved.fields);
47235
47633
  }
47236
47634
  var valueAt = (sheet, row3, col) => getCell(sheet, row3, col)?.value ?? null;
47237
- function computeDataTable(workbook, calc, sheetIndex2, table3) {
47635
+ function computeDataTable(workbook, calc, sheetIndex2, table4) {
47238
47636
  const sheet = sheetAt(workbook, sheetIndex2);
47239
- const { ref } = table3;
47240
- const first3 = parseInputCell(sheet, table3.r1);
47241
- const second = table3.dt2D && table3.r2 ? parseInputCell(sheet, table3.r2) : void 0;
47242
- if (!first3 || table3.dt2D && !second || table3.del1 || table3.del2) return [];
47637
+ const { ref } = table4;
47638
+ const first3 = parseInputCell(sheet, table4.r1);
47639
+ const second = table4.dt2D && table4.r2 ? parseInputCell(sheet, table4.r2) : void 0;
47640
+ if (!first3 || table4.dt2D && !second || table4.del1 || table4.del2) return [];
47243
47641
  const inputs = [first3, ...second ? [second] : []];
47244
47642
  const saved = inputs.map((p) => save(sheet, p.row, p.col));
47245
47643
  const top = ref.start.row - 1;
@@ -47258,11 +47656,11 @@ function computeDataTable(workbook, calc, sheetIndex2, table3) {
47258
47656
  for (let row3 = ref.start.row; row3 <= ref.end.row; row3++) {
47259
47657
  for (let col = ref.start.col; col <= ref.end.col; col++) {
47260
47658
  let formulaAt;
47261
- if (table3.dt2D) {
47659
+ if (table4.dt2D) {
47262
47660
  set(first3, valueAt(sheet, top, col));
47263
47661
  if (second) set(second, valueAt(sheet, row3, left2));
47264
47662
  formulaAt = { row: top, col: left2 };
47265
- } else if (table3.dtr) {
47663
+ } else if (table4.dtr) {
47266
47664
  set(first3, valueAt(sheet, top, col));
47267
47665
  formulaAt = { row: row3, col: left2 };
47268
47666
  } else {
@@ -47287,8 +47685,8 @@ function computeDataTable(workbook, calc, sheetIndex2, table3) {
47287
47685
  function refreshDataTables(workbook, calc) {
47288
47686
  const changed = [];
47289
47687
  workbook.sheets.forEach((sheet, index3) => {
47290
- for (const table3 of sheet.dataTables ?? [])
47291
- changed.push(...computeDataTable(workbook, calc, index3, table3));
47688
+ for (const table4 of sheet.dataTables ?? [])
47689
+ changed.push(...computeDataTable(workbook, calc, index3, table4));
47292
47690
  });
47293
47691
  if (changed.length) calc.recalculateFrom(changed);
47294
47692
  }
@@ -47311,23 +47709,23 @@ function resolve2(sheet, request) {
47311
47709
  const ref = cellRange(range2.start.row + 1, range2.start.col + 1, range2.end.row, range2.end.col);
47312
47710
  if ([row3, col].some((p) => p && rangeContains(ref, p))) return { problem: "input-inside" };
47313
47711
  const name3 = (p) => formatAddress(p);
47314
- const table3 = { ref, r1: "" };
47712
+ const table4 = { ref, r1: "" };
47315
47713
  if (row3 && col) {
47316
- table3.dt2D = true;
47317
- table3.dtr = true;
47318
- table3.r1 = name3(row3);
47319
- table3.r2 = name3(col);
47714
+ table4.dt2D = true;
47715
+ table4.dtr = true;
47716
+ table4.r1 = name3(row3);
47717
+ table4.r2 = name3(col);
47320
47718
  } else if (row3) {
47321
- table3.dtr = true;
47322
- table3.r1 = name3(row3);
47323
- } else if (col) table3.r1 = name3(col);
47324
- return { table: table3 };
47719
+ table4.dtr = true;
47720
+ table4.r1 = name3(row3);
47721
+ } else if (col) table4.r1 = name3(col);
47722
+ return { table: table4 };
47325
47723
  }
47326
47724
  function createDataTable(ctx, s, request) {
47327
47725
  const sheet = sheetAt(ctx.workbook, s);
47328
47726
  const result2 = resolve2(sheet, request);
47329
47727
  if ("problem" in result2) throw new Error(MESSAGES[result2.problem]);
47330
- const { table: table3 } = result2;
47728
+ const { table: table4 } = result2;
47331
47729
  const range2 = normalizeRange(request.range);
47332
47730
  ctx.run(
47333
47731
  "Data Table",
@@ -47338,16 +47736,16 @@ function createDataTable(ctx, s, request) {
47338
47736
  ],
47339
47737
  () => {
47340
47738
  sheet.dataTables = (sheet.dataTables ?? []).filter((t) => !rangesIntersect(t.ref, range2));
47341
- sheet.dataTables.push(table3);
47342
- for (let row3 = table3.ref.start.row; row3 <= table3.ref.end.row; row3++)
47343
- for (let col = table3.ref.start.col; col <= table3.ref.end.col; col++) {
47739
+ sheet.dataTables.push(table4);
47740
+ for (let row3 = table4.ref.start.row; row3 <= table4.ref.end.row; row3++)
47741
+ for (let col = table4.ref.start.col; col <= table4.ref.end.col; col++) {
47344
47742
  const cell = ensureCell(sheet, row3, col);
47345
47743
  delete cell.formula;
47346
47744
  delete cell.arrayRange;
47347
47745
  delete cell.legacyFormula;
47348
47746
  delete cell.dynamicArray;
47349
47747
  }
47350
- computeDataTable(ctx.workbook, ctx.calc, s, table3);
47748
+ computeDataTable(ctx.workbook, ctx.calc, s, table4);
47351
47749
  },
47352
47750
  { sheet: s, ranges: [range2] }
47353
47751
  );
@@ -48664,7 +49062,7 @@ function plan(ctx, s, pivot, old) {
48664
49062
  if (![start.row, start.col].every(Number.isInteger) || start.row < 0 || start.col < 0 || location.end.row > MAX_ROW || location.end.col > MAX_COL)
48665
49063
  throw new Error("The PivotTable result does not fit on the worksheet.");
48666
49064
  const source2 = sparklineDataRange(ctx.workbook, s, pivot.source);
48667
- if (source2.sheet === s && rangesIntersect(source2.range, location) || sheet.merges.some((range2) => rangesIntersect(range2, location)) || sheet.tables.some((table3) => rangesIntersect(table3.range, location)) || sheet.pivotTables?.some((other) => other !== old && rangesIntersect(other.location, location)))
49065
+ if (source2.sheet === s && rangesIntersect(source2.range, location) || sheet.merges.some((range2) => rangesIntersect(range2, location)) || sheet.tables.some((table4) => rangesIntersect(table4.range, location)) || sheet.pivotTables?.some((other) => other !== old && rangesIntersect(other.location, location)))
48668
49066
  throw new Error("The PivotTable would overlap source data, another table or merged cells.");
48669
49067
  let occupied = false;
48670
49068
  forEachCellInRange(sheet, location, (cell, row3, col) => {
@@ -48674,12 +49072,12 @@ function plan(ctx, s, pivot, old) {
48674
49072
  if (occupied) throw new Error("The PivotTable would overwrite existing cell content.");
48675
49073
  return { grid, location };
48676
49074
  }
48677
- function writePivot(ctx, s, pivot, old, label4, inside2) {
49075
+ function writePivot(ctx, s, pivot, old, label2, inside2) {
48678
49076
  const sheet = sheetAt(ctx.workbook, s);
48679
49077
  const { grid, location } = plan(ctx, s, pivot, old);
48680
49078
  const ranges = [...old ? [old.location] : [], location];
48681
49079
  ctx.run(
48682
- label4 ?? (old ? "Refresh PivotTable" : "Create PivotTable"),
49080
+ label2 ?? (old ? "Refresh PivotTable" : "Create PivotTable"),
48683
49081
  "annotations",
48684
49082
  [
48685
49083
  { kind: "parts", sheet: s, parts: ["pivotTables"] },
@@ -48736,8 +49134,10 @@ function createPivotTable(ctx, s, destination, options) {
48736
49134
  const name3 = options.name ?? uniqueName(ctx);
48737
49135
  checkName2(ctx, name3);
48738
49136
  const aggregate2 = options.aggregate ?? "sum";
49137
+ const captions = authoredCaptions(options);
48739
49138
  const pivot = {
48740
49139
  ...data,
49140
+ ...captions ? { captions } : {},
48741
49141
  name: name3,
48742
49142
  rowField: options.rowField,
48743
49143
  layout: options.layout ?? "tabular",
@@ -48751,12 +49151,12 @@ function createPivotTable(ctx, s, destination, options) {
48751
49151
  ...options.repeatLabels !== void 0 ? { repeatLabels: options.repeatLabels } : {},
48752
49152
  valueField: options.valueField,
48753
49153
  aggregate: aggregate2,
48754
- valueCaption: pivotCaption(aggregate2, options.valueField),
49154
+ valueCaption: pivotCaption(aggregate2, options.valueField, { captions }),
48755
49155
  ...options.pageFilter !== void 0 ? { pageFilter: structuredClone(options.pageFilter) } : {},
48756
49156
  ...options.fieldGroups?.length ? { fieldGroups: structuredClone(options.fieldGroups) } : {},
48757
49157
  ...options.valuesAxis !== void 0 ? { valuesAxis: options.valuesAxis } : {},
48758
49158
  ...options.valuesPosition !== void 0 ? { valuesPosition: options.valuesPosition } : {},
48759
- ...options.additionalValues ? { additionalValues: normalizedPivotMeasures(options.additionalValues) } : {},
49159
+ ...options.additionalValues ? { additionalValues: normalizedPivotMeasures(options.additionalValues, { captions }) } : {},
48760
49160
  location: { start: { ...destination }, end: { ...destination } },
48761
49161
  ...options.columnField ? { columnField: options.columnField } : {},
48762
49162
  ...options.columnField && options.moreColumnFields?.length ? { moreColumnFields: [...options.moreColumnFields] } : {}
@@ -48779,7 +49179,7 @@ function refreshPivotTable(ctx, s, name3, patch2 = {}) {
48779
49179
  rowField: patch2.rowField ?? old.rowField,
48780
49180
  valueField,
48781
49181
  aggregate: aggregate2,
48782
- valueCaption: aggregate2 === old.aggregate && valueField === old.valueField ? old.valueCaption : pivotCaption(aggregate2, valueField)
49182
+ valueCaption: aggregate2 === old.aggregate && valueField === old.valueField ? old.valueCaption : pivotCaption(aggregate2, valueField, old)
48783
49183
  };
48784
49184
  if (patch2.columnField !== void 0) {
48785
49185
  if (patch2.columnField) next.columnField = patch2.columnField;
@@ -48829,7 +49229,7 @@ function refreshPivotTable(ctx, s, name3, patch2 = {}) {
48829
49229
  else if (patch2.valuesAxis === "columns" || patch2.secondRowField === "")
48830
49230
  delete next.valuesPosition;
48831
49231
  if (patch2.additionalValues !== void 0) {
48832
- const measures2 = normalizedPivotMeasures(patch2.additionalValues);
49232
+ const measures2 = normalizedPivotMeasures(patch2.additionalValues, old);
48833
49233
  if (measures2.length) next.additionalValues = measures2;
48834
49234
  else delete next.additionalValues;
48835
49235
  }
@@ -49299,10 +49699,10 @@ function validatePatch(group, patch2) {
49299
49699
  delete next.manualMax;
49300
49700
  validateSettings(next);
49301
49701
  }
49302
- function save2(ctx, s, next, label4, ranges) {
49702
+ function save2(ctx, s, next, label2, ranges) {
49303
49703
  const sheet = sheetAt(ctx.workbook, s);
49304
49704
  ctx.run(
49305
- label4,
49705
+ label2,
49306
49706
  "annotations",
49307
49707
  [{ kind: "parts", sheet: s, parts: ["preserved"] }],
49308
49708
  () => sheet.preserved.set("extLst", next),
@@ -49420,20 +49820,20 @@ function setSlicerSelection(ctx, cacheName, keys) {
49420
49820
  const target2 = slicerTarget(ctx.workbook, cache3);
49421
49821
  if (!target2) throw new Error("The slicer has no data source.");
49422
49822
  if (target2.kind === "table") {
49423
- const { sheet, table: table3, offset: offset2 } = target2;
49823
+ const { sheet, table: table4, offset: offset2 } = target2;
49424
49824
  ctx.run(
49425
49825
  keys === null ? "Clear slicer filter" : "Filter slicer",
49426
49826
  "view",
49427
49827
  [{ kind: "sheet", sheet: target2.sheetIndex }],
49428
49828
  () => {
49429
- const column2 = table3.columns[offset2];
49829
+ const column2 = table4.columns[offset2];
49430
49830
  if (keys === null) delete column2.filter;
49431
49831
  else
49432
49832
  column2.filter = {
49433
49833
  values: keys.filter((key2) => key2 !== ""),
49434
49834
  ...keys.includes("") ? { blank: true } : {}
49435
49835
  };
49436
- applyTableFilter(ctx.workbook, sheet, table3);
49836
+ applyTableFilter(ctx.workbook, sheet, table4);
49437
49837
  },
49438
49838
  { sheet: target2.sheetIndex, structural: true }
49439
49839
  );
@@ -49504,17 +49904,17 @@ function unique2(base2, taken) {
49504
49904
  function insertSlicer(ctx, s, ref) {
49505
49905
  const { workbook } = ctx;
49506
49906
  const sheet = sheetAt(workbook, s);
49507
- let table3;
49907
+ let table4;
49508
49908
  let pivot;
49509
49909
  let field2;
49510
49910
  if (ref.kind === "table") {
49511
- table3 = sheet.tables.find(
49911
+ table4 = sheet.tables.find(
49512
49912
  (entry3) => entry3.name === ref.table || entry3.displayName === ref.table
49513
49913
  );
49514
- if (!table3?.headerRow || table3.filterNotModeled)
49914
+ if (!table4?.headerRow || table4.filterNotModeled)
49515
49915
  throw new Error("Choose a table with a header row and value filters.");
49516
49916
  field2 = ref.column;
49517
- if (!table3.columns.some((column2) => column2.name === field2))
49917
+ if (!table4.columns.some((column2) => column2.name === field2))
49518
49918
  throw new Error("Choose a column of the table.");
49519
49919
  } else {
49520
49920
  pivot = sheet.pivotTables?.find((entry3) => entry3.name === ref.pivot);
@@ -49534,7 +49934,7 @@ function insertSlicer(ctx, s, ref) {
49534
49934
  (c2) => names.has(c2.toLowerCase())
49535
49935
  ).replace(/ /g, "_");
49536
49936
  const metrics = createGridMetrics(sheet, { zoom: 100 });
49537
- const anchorCell = table3 ? { row: table3.range.start.row, col: table3.range.end.col + 2 } : { row: pivot.location.start.row, col: pivot.location.end.col + 2 };
49937
+ const anchorCell = table4 ? { row: table4.range.start.row, col: table4.range.end.col + 2 } : { row: pivot.location.start.row, col: pivot.location.end.col + 2 };
49538
49938
  const x = Math.max(metrics.colLeft(anchorCell.col), frameBounds(sheet) + 10);
49539
49939
  const box5 = { x, y: metrics.rowTop(anchorCell.row), ...SLICER_BOX };
49540
49940
  const anchor = pixelBoxToAnchor(sheet, box5, metrics, "twoCell");
@@ -49551,13 +49951,13 @@ function insertSlicer(ctx, s, ref) {
49551
49951
  () => {
49552
49952
  const book = cloneBook(workbook);
49553
49953
  let source2;
49554
- if (table3) {
49555
- if (table3.columns.some((column2) => column2.sourceId === void 0))
49556
- table3.columns.forEach((column2, index3) => column2.sourceId ??= index3 + 1);
49954
+ if (table4) {
49955
+ if (table4.columns.some((column2) => column2.sourceId === void 0))
49956
+ table4.columns.forEach((column2, index3) => column2.sourceId ??= index3 + 1);
49557
49957
  source2 = {
49558
49958
  kind: "table",
49559
- tableId: table3.id,
49560
- column: table3.columns.find((column2) => column2.name === field2).sourceId
49959
+ tableId: table4.id,
49960
+ column: table4.columns.find((column2) => column2.name === field2).sourceId
49561
49961
  };
49562
49962
  } else {
49563
49963
  const target2 = pivot;
@@ -50043,9 +50443,9 @@ var SUBTOTAL = {
50043
50443
  var: 110
50044
50444
  };
50045
50445
  var escapeColumn = (name3) => name3.replace(/['#[\]]/g, "'$&");
50046
- function applyTotalsRow(sheet, table3) {
50047
- const row3 = table3.range.end.row;
50048
- const { columns } = table3;
50446
+ function applyTotalsRow(sheet, table4) {
50447
+ const row3 = table4.range.end.row;
50448
+ const { columns } = table4;
50049
50449
  if (!columns.some((c2) => c2.totalsRowFunction || c2.totalsRowLabel)) {
50050
50450
  const first3 = columns[0];
50051
50451
  const last = columns[columns.length - 1];
@@ -50053,12 +50453,12 @@ function applyTotalsRow(sheet, table3) {
50053
50453
  if (last) last.totalsRowFunction = "sum";
50054
50454
  }
50055
50455
  columns.forEach((column2, i2) => {
50056
- const col = table3.range.start.col + i2;
50456
+ const col = table4.range.start.col + i2;
50057
50457
  const code = SUBTOTAL[column2.totalsRowFunction ?? ""];
50058
50458
  if (code !== void 0) {
50059
50459
  const cell = ensureCell(sheet, row3, col);
50060
50460
  clearContents(cell);
50061
- cell.formula = `SUBTOTAL(${code},${table3.name}[${escapeColumn(column2.name)}])`;
50461
+ cell.formula = `SUBTOTAL(${code},${table4.name}[${escapeColumn(column2.name)}])`;
50062
50462
  } else if (column2.totalsRowLabel && column2.totalsRowFunction !== "custom")
50063
50463
  writeValue(sheet, row3, col, column2.totalsRowLabel);
50064
50464
  });
@@ -50082,8 +50482,8 @@ function validateTableName(workbook, name3, self) {
50082
50482
  ) || workbook.definedNames.some((n) => n.name.toLowerCase() === lower3);
50083
50483
  return taken ? "That name is already used by another table or name." : void 0;
50084
50484
  }
50085
- function renameTableIn(workbook, table3, name3) {
50086
- const old = table3.name;
50485
+ function renameTableIn(workbook, table4, name3) {
50486
+ const old = table4.name;
50087
50487
  if (old === name3) return;
50088
50488
  const rename = (f6) => renameTableInFormula(f6, old, name3);
50089
50489
  rewriteFormulas(workbook, rename);
@@ -50092,73 +50492,73 @@ function renameTableIn(workbook, table3, name3) {
50092
50492
  for (const column2 of t.columns)
50093
50493
  if (column2.calculatedColumnFormula)
50094
50494
  column2.calculatedColumnFormula = rename(column2.calculatedColumnFormula);
50095
- table3.name = name3;
50096
- table3.displayName = name3;
50495
+ table4.name = name3;
50496
+ table4.displayName = name3;
50097
50497
  }
50098
50498
  var byId = (sheet, id3) => {
50099
- const table3 = sheet.tables.find((t) => t.id === id3);
50100
- if (!table3) throw new Error("The table disappeared during the edit.");
50101
- return table3;
50499
+ const table4 = sheet.tables.find((t) => t.id === id3);
50500
+ if (!table4) throw new Error("The table disappeared during the edit.");
50501
+ return table4;
50102
50502
  };
50103
- function insertBandRow(workbook, sheet, table3, row3) {
50503
+ function insertBandRow(workbook, sheet, table4, row3) {
50104
50504
  const shift2 = { axis: "row", at: row3, count: 1 };
50105
- const band2 = { lo: table3.range.start.col, hi: table3.range.end.col };
50505
+ const band2 = { lo: table4.range.start.col, hi: table4.range.end.col };
50106
50506
  assertInsertFits(sheet, shift2, band2);
50107
50507
  rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band2));
50108
50508
  shiftSheetContent(sheet, shift2, band2);
50109
50509
  }
50110
50510
  function setHeaderRow(workbook, sheet, id3, on) {
50111
- let table3 = byId(sheet, id3);
50112
- if (table3.headerRow === on) return;
50113
- const { start, end } = table3.range;
50511
+ let table4 = byId(sheet, id3);
50512
+ if (table4.headerRow === on) return;
50513
+ const { start, end } = table4.range;
50114
50514
  if (!on) {
50115
50515
  if (start.row === end.row) throw new Error("A table needs at least one row.");
50116
50516
  clearRow(sheet, start.row, start.col, end.col);
50117
- table3.range = { start: { row: start.row + 1, col: start.col }, end };
50118
- table3.headerRow = false;
50517
+ table4.range = { start: { row: start.row + 1, col: start.col }, end };
50518
+ table4.headerRow = false;
50119
50519
  return;
50120
50520
  }
50121
50521
  if (start.row === 0 || !rowIsEmpty(sheet, start.row - 1, start.col, end.col)) {
50122
- insertBandRow(workbook, sheet, table3, start.row);
50123
- table3 = byId(sheet, id3);
50124
- }
50125
- const top = table3.range.start.row - 1;
50126
- const left2 = table3.range.start.col;
50127
- table3.range = { start: { row: top, col: left2 }, end: table3.range.end };
50128
- table3.headerRow = true;
50129
- uniqueHeaders(table3.columns.map((c2) => c2.name)).forEach((name3, i2) => {
50130
- const column2 = table3.columns[i2];
50522
+ insertBandRow(workbook, sheet, table4, start.row);
50523
+ table4 = byId(sheet, id3);
50524
+ }
50525
+ const top = table4.range.start.row - 1;
50526
+ const left2 = table4.range.start.col;
50527
+ table4.range = { start: { row: top, col: left2 }, end: table4.range.end };
50528
+ table4.headerRow = true;
50529
+ uniqueHeaders(table4.columns.map((c2) => c2.name)).forEach((name3, i2) => {
50530
+ const column2 = table4.columns[i2];
50131
50531
  if (column2) column2.name = name3;
50132
50532
  writeValue(sheet, top, left2 + i2, name3);
50133
50533
  });
50134
50534
  }
50135
50535
  function setTotalsRow(workbook, sheet, id3, on) {
50136
- let table3 = byId(sheet, id3);
50137
- if (table3.totalsRow === on) return;
50138
- const { start, end } = table3.range;
50536
+ let table4 = byId(sheet, id3);
50537
+ if (table4.totalsRow === on) return;
50538
+ const { start, end } = table4.range;
50139
50539
  if (!on) {
50140
50540
  clearRow(sheet, end.row, start.col, end.col);
50141
- table3.range = { start, end: { row: end.row - 1, col: end.col } };
50142
- table3.totalsRow = false;
50541
+ table4.range = { start, end: { row: end.row - 1, col: end.col } };
50542
+ table4.totalsRow = false;
50143
50543
  return;
50144
50544
  }
50145
50545
  if (end.row === MAX_ROW) throw new RangeError("The insert area extends beyond the sheet.");
50146
50546
  if (!rowIsEmpty(sheet, end.row + 1, start.col, end.col)) {
50147
- insertBandRow(workbook, sheet, table3, end.row + 1);
50148
- table3 = byId(sheet, id3);
50547
+ insertBandRow(workbook, sheet, table4, end.row + 1);
50548
+ table4 = byId(sheet, id3);
50149
50549
  }
50150
- table3.range = { start: table3.range.start, end: { row: table3.range.end.row + 1, col: end.col } };
50151
- table3.totalsRow = true;
50152
- applyTotalsRow(sheet, table3);
50550
+ table4.range = { start: table4.range.start, end: { row: table4.range.end.row + 1, col: end.col } };
50551
+ table4.totalsRow = true;
50552
+ applyTotalsRow(sheet, table4);
50153
50553
  }
50154
- function resizedColumns(workbook, sheet, table3, range2) {
50554
+ function resizedColumns(workbook, sheet, table4, range2) {
50155
50555
  const width = range2.end.col - range2.start.col + 1;
50156
- const oldAt = (col) => col >= table3.range.start.col && col <= table3.range.end.col ? table3.columns[col - table3.range.start.col] : void 0;
50556
+ const oldAt = (col) => col >= table4.range.start.col && col <= table4.range.end.col ? table4.columns[col - table4.range.start.col] : void 0;
50157
50557
  const texts = Array.from({ length: width }, (_v, i2) => {
50158
50558
  const col = range2.start.col + i2;
50159
50559
  const old = oldAt(col);
50160
50560
  if (old) return old.name;
50161
- return table3.headerRow ? displayText(workbook, getCell(sheet, range2.start.row, col)) : "";
50561
+ return table4.headerRow ? displayText(workbook, getCell(sheet, range2.start.row, col)) : "";
50162
50562
  });
50163
50563
  return uniqueHeaders(texts).map((name3, i2) => {
50164
50564
  const old = oldAt(range2.start.col + i2);
@@ -50166,30 +50566,30 @@ function resizedColumns(workbook, sheet, table3, range2) {
50166
50566
  });
50167
50567
  }
50168
50568
  function resizeTableIn(workbook, sheet, id3, range2) {
50169
- const table3 = byId(sheet, id3);
50569
+ const table4 = byId(sheet, id3);
50170
50570
  const r = normalizeRange(range2);
50171
- if (table3.headerRow && r.start.row !== table3.range.start.row)
50571
+ if (table4.headerRow && r.start.row !== table4.range.start.row)
50172
50572
  throw new Error("The table headers must remain in the same row.");
50173
- if (!rangesIntersect(r, table3.range)) throw new Error("The new range must overlap the table.");
50174
- if (r.end.row - r.start.row + 1 < (table3.headerRow ? 2 : 1) + (table3.totalsRow ? 1 : 0))
50573
+ if (!rangesIntersect(r, table4.range)) throw new Error("The new range must overlap the table.");
50574
+ if (r.end.row - r.start.row + 1 < (table4.headerRow ? 2 : 1) + (table4.totalsRow ? 1 : 0))
50175
50575
  throw new Error("The table range is too small.");
50176
- if (sheet.tables.some((t) => t !== table3 && rangesIntersect(t.range, r)))
50576
+ if (sheet.tables.some((t) => t !== table4 && rangesIntersect(t.range, r)))
50177
50577
  throw new Error("A table cannot overlap another table.");
50178
50578
  if (sheet.pivotTables?.some((pivot) => rangesIntersect(pivot.location, r)))
50179
50579
  throw new Error("A table cannot overlap a PivotTable.");
50180
50580
  if (sheet.merges.some((m) => rangesIntersect(m, r)))
50181
50581
  throw new Error("A table cannot contain merged cells.");
50182
- const oldEnd = table3.range.end.row;
50183
- table3.columns = resizedColumns(workbook, sheet, table3, r);
50184
- table3.range = r;
50185
- if (table3.headerRow)
50186
- table3.columns.forEach((column2, i2) => {
50582
+ const oldEnd = table4.range.end.row;
50583
+ table4.columns = resizedColumns(workbook, sheet, table4, r);
50584
+ table4.range = r;
50585
+ if (table4.headerRow)
50586
+ table4.columns.forEach((column2, i2) => {
50187
50587
  const cell = getCell(sheet, r.start.row, r.start.col + i2);
50188
50588
  if (cell?.value !== column2.name) writeValue(sheet, r.start.row, r.start.col + i2, column2.name);
50189
50589
  });
50190
- if (table3.totalsRow) {
50590
+ if (table4.totalsRow) {
50191
50591
  if (oldEnd !== r.end.row) clearRow(sheet, oldEnd, r.start.col, r.end.col);
50192
- applyTotalsRow(sheet, table3);
50592
+ applyTotalsRow(sheet, table4);
50193
50593
  }
50194
50594
  }
50195
50595
  var STYLE_KEYS = [
@@ -50217,20 +50617,20 @@ function updateTable(ctx, s, ref, patch2) {
50217
50617
  "structure",
50218
50618
  [scope],
50219
50619
  () => {
50220
- const table3 = byId(sheet, id3);
50221
- if (renaming) renameTableIn(workbook, table3, name3);
50620
+ const table4 = byId(sheet, id3);
50621
+ if (renaming) renameTableIn(workbook, table4, name3);
50222
50622
  for (const key2 of STYLE_KEYS) {
50223
50623
  if (!(key2 in patch2)) continue;
50224
50624
  const value2 = patch2[key2];
50225
- if (value2 === void 0) delete table3[key2];
50226
- else table3[key2] = value2;
50625
+ if (value2 === void 0) delete table4[key2];
50626
+ else table4[key2] = value2;
50227
50627
  }
50228
50628
  if (patch2.columns) {
50229
- const width = table3.range.end.col - table3.range.start.col + 1;
50629
+ const width = table4.range.end.col - table4.range.start.col + 1;
50230
50630
  if (patch2.columns.length !== width) throw new Error("Give one column per table column.");
50231
- const before = table3.columns;
50232
- table3.columns = structuredClone(patch2.columns);
50233
- for (const [index3, column2] of table3.columns.entries()) {
50631
+ const before = table4.columns;
50632
+ table4.columns = structuredClone(patch2.columns);
50633
+ for (const [index3, column2] of table4.columns.entries()) {
50234
50634
  const sourceId = before[index3]?.sourceId;
50235
50635
  if (column2.sourceId === void 0 && sourceId !== void 0) column2.sourceId = sourceId;
50236
50636
  const filter2 = before[index3]?.filter;
@@ -50239,7 +50639,7 @@ function updateTable(ctx, s, ref, patch2) {
50239
50639
  }
50240
50640
  if (patch2.headerRow !== void 0) setHeaderRow(workbook, sheet, id3, patch2.headerRow);
50241
50641
  if (patch2.totalsRow !== void 0) setTotalsRow(workbook, sheet, id3, patch2.totalsRow);
50242
- else if (patch2.columns && table3.totalsRow) applyTotalsRow(sheet, byId(sheet, id3));
50642
+ else if (patch2.columns && table4.totalsRow) applyTotalsRow(sheet, byId(sheet, id3));
50243
50643
  if (patch2.range) resizeTableIn(workbook, sheet, id3, patch2.range);
50244
50644
  },
50245
50645
  { sheet: s, ranges: [current.range], structural: true }
@@ -50259,13 +50659,13 @@ function resizeTable(ctx, s, ref, range2) {
50259
50659
  function convertTableToRange(ctx, s, ref) {
50260
50660
  const { workbook } = ctx;
50261
50661
  const sheet = sheetAt(workbook, s);
50262
- const table3 = sheet.tables[tableIndex(sheet, ref)];
50662
+ const table4 = sheet.tables[tableIndex(sheet, ref)];
50263
50663
  ctx.run(
50264
50664
  "Convert to range",
50265
50665
  "structure",
50266
50666
  [{ kind: "workbook" }],
50267
50667
  () => {
50268
- const live2 = byId(sheet, table3.id);
50668
+ const live2 = byId(sheet, table4.id);
50269
50669
  const base2 = { table: live2, tableSheet: sheet.name };
50270
50670
  const { start, end } = live2.range;
50271
50671
  for (const ws of workbook.sheets)
@@ -50290,7 +50690,7 @@ function convertTableToRange(ctx, s, ref) {
50290
50690
  });
50291
50691
  sheet.tables = sheet.tables.filter((t) => t.id !== live2.id);
50292
50692
  },
50293
- { sheet: s, ranges: [table3.range], structural: true }
50693
+ { sheet: s, ranges: [table4.range], structural: true }
50294
50694
  );
50295
50695
  }
50296
50696
 
@@ -53196,7 +53596,7 @@ function createTable2(ctx, s, range2, hasHeader, styleName = "TableStyleMedium2"
53196
53596
  });
53197
53597
  const name3 = nextTableName(workbook);
53198
53598
  const id3 = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
53199
- const table3 = {
53599
+ const table4 = {
53200
53600
  id: id3,
53201
53601
  name: name3,
53202
53602
  displayName: name3,
@@ -53210,8 +53610,8 @@ function createTable2(ctx, s, range2, hasHeader, styleName = "TableStyleMedium2"
53210
53610
  showFirstColumn: false,
53211
53611
  showLastColumn: false
53212
53612
  };
53213
- sheet.tables.push(table3);
53214
- return table3;
53613
+ sheet.tables.push(table4);
53614
+ return table4;
53215
53615
  },
53216
53616
  { sheet: s, ranges: [r], structural: !hasHeader }
53217
53617
  );
@@ -53415,8 +53815,8 @@ function createEditSession(workbook, options = {}) {
53415
53815
  if (!workbook.warnings.includes(message)) workbook.warnings.push(message);
53416
53816
  }
53417
53817
  };
53418
- const begin = (label4, kind, info) => {
53419
- const step2 = { label: label4, entries: [], structural: info.structural ?? false };
53818
+ const begin = (label2, kind, info) => {
53819
+ const step2 = { label: label2, entries: [], structural: info.structural ?? false };
53420
53820
  if (info.calc) step2.calc = info.calc;
53421
53821
  return { step: step2, kind, sheet: info.sheet, ranges: [...info.ranges ?? []] };
53422
53822
  };
@@ -53440,7 +53840,7 @@ function createEditSession(workbook, options = {}) {
53440
53840
  }
53441
53841
  current.step.entries.length = from;
53442
53842
  };
53443
- const run2 = (label4, kind, scopes, fn, info = {}) => {
53843
+ const run2 = (label2, kind, scopes, fn, info = {}) => {
53444
53844
  if (kind === "cells") {
53445
53845
  for (const scope of scopes)
53446
53846
  if (scope.kind === "cells" && workbook.sheets[scope.sheet]?.pivotTables?.some(
@@ -53457,7 +53857,7 @@ function createEditSession(workbook, options = {}) {
53457
53857
  }))
53458
53858
  throw new Error(DATA_TABLE_PART_ERROR);
53459
53859
  const outer = !open;
53460
- const current = open ?? begin(label4, kind, info);
53860
+ const current = open ?? begin(label2, kind, info);
53461
53861
  if (!outer) {
53462
53862
  delete current.step.calc;
53463
53863
  if (info.structural) current.step.structural = true;
@@ -53588,9 +53988,9 @@ function createEditSession(workbook, options = {}) {
53588
53988
  removeConditionalFormat: (s, index3) => removeConditionalFormat(ctx, s, index3),
53589
53989
  setConditionalRulePriority: (s, f6, r, priority) => setConditionalRulePriority(ctx, s, f6, r, priority),
53590
53990
  moveConditionalRule: (s, f6, r, direction) => moveConditionalRule(ctx, s, f6, r, direction),
53591
- updateTable: (s, table3, patch2) => updateTable(ctx, s, table3, patch2),
53592
- resizeTable: (s, table3, range2) => resizeTable(ctx, s, table3, range2),
53593
- convertTableToRange: (s, table3) => convertTableToRange(ctx, s, table3),
53991
+ updateTable: (s, table4, patch2) => updateTable(ctx, s, table4, patch2),
53992
+ resizeTable: (s, table4, range2) => resizeTable(ctx, s, table4, range2),
53993
+ convertTableToRange: (s, table4) => convertTableToRange(ctx, s, table4),
53594
53994
  applyCellStyle: (s, ranges, name3) => applyCellStyle(ctx, s, ranges, name3),
53595
53995
  setPageSetup: (s, patch2) => setPageSetup(ctx, s, patch2),
53596
53996
  setPageBreak: (s, axis, before, present) => setPageBreak(ctx, s, axis, before, present),
@@ -53627,12 +54027,12 @@ function createEditSession(workbook, options = {}) {
53627
54027
  validate: (s, r, c2, value2) => validateCellInput(workbook, s, r, c2, value2, {
53628
54028
  evaluate: (formula, at2) => calc.evaluate(formula, at2)
53629
54029
  }),
53630
- batch(label4, fn) {
54030
+ batch(label2, fn) {
53631
54031
  if (open) {
53632
54032
  fn();
53633
54033
  return;
53634
54034
  }
53635
- const current = begin(label4, "batch", {});
54035
+ const current = begin(label2, "batch", {});
53636
54036
  open = current;
53637
54037
  try {
53638
54038
  fn();
@@ -54312,9 +54712,9 @@ var VisioPackage = class _VisioPackage {
54312
54712
  };
54313
54713
 
54314
54714
  // visio/metadata.ts
54315
- function metadata(value2, max, label4) {
54715
+ function metadata(value2, max, label2) {
54316
54716
  if (value2.length > max)
54317
- throw new VisioPackageError("METADATA_LIMIT", `${label4} exceeds its metadata length limit.`);
54717
+ throw new VisioPackageError("METADATA_LIMIT", `${label2} exceeds its metadata length limit.`);
54318
54718
  return value2;
54319
54719
  }
54320
54720
  function metadataAttributes(node3) {
@@ -58266,15 +58666,15 @@ function legacyFillGradient(cells3, width, height, resolve3) {
58266
58666
 
58267
58667
  // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/utils/png-encoder.js
58268
58668
  var CRC_TABLE = (() => {
58269
- const table3 = new Uint32Array(256);
58669
+ const table4 = new Uint32Array(256);
58270
58670
  for (let n = 0; n < 256; n++) {
58271
58671
  let c2 = n;
58272
58672
  for (let k = 0; k < 8; k++) {
58273
58673
  c2 = c2 & 1 ? 3988292384 ^ c2 >>> 1 : c2 >>> 1;
58274
58674
  }
58275
- table3[n] = c2 >>> 0;
58675
+ table4[n] = c2 >>> 0;
58276
58676
  }
58277
- return table3;
58677
+ return table4;
58278
58678
  })();
58279
58679
  function crc322(bytes) {
58280
58680
  let crc = 4294967295;
@@ -60948,7 +61348,7 @@ function property(row3, budget, report) {
60948
61348
  "Shape data has no supported current cached typed value; original cached text is retained."
60949
61349
  );
60950
61350
  }
60951
- const label4 = get("Label"), format5 = get("Format"), prompt = get("Prompt"), sortKey = get("SortKey");
61351
+ const label2 = get("Label"), format5 = get("Format"), prompt = get("Prompt"), sortKey = get("SortKey");
60952
61352
  const invisible = boolean(row3.cells, "Invisible", budget, report);
60953
61353
  const dataLinked = row3.cells.has("DataLinked") ? boolean(row3.cells, "DataLinked", budget, report) : void 0;
60954
61354
  const unit3 = row3.cells.get("Value")?.unit, error = row3.cells.get("Value")?.error;
@@ -60960,7 +61360,7 @@ function property(row3, budget, report) {
60960
61360
  ...rawType === void 0 ? {} : { rawType },
60961
61361
  ...rawValue === void 0 ? {} : { rawValue },
60962
61362
  ...value2 === void 0 ? {} : { value: value2 },
60963
- ...label4 === void 0 ? {} : { label: label4 },
61363
+ ...label2 === void 0 ? {} : { label: label2 },
60964
61364
  ...format5 === void 0 ? {} : { format: format5 },
60965
61365
  ...prompt === void 0 ? {} : { prompt },
60966
61366
  ...sortKey === void 0 ? {} : { sortKey },
@@ -61193,9 +61593,9 @@ async function readDataRecordsets(pkg, documentPart, check3) {
61193
61593
  const declared = children3(children3(set, "DataColumns")[0], "DataColumn");
61194
61594
  const columns = (declared.length ? declared : []).map((node3) => {
61195
61595
  const name4 = attribute3(node3, "ColumnNameID") ?? attribute3(node3, "Name") ?? "";
61196
- const label4 = attribute3(node3, "Label") ?? attribute3(node3, "Name") ?? name4;
61197
- if (!name4 || name4.length > 255 || label4.length > 255) invalid2("Invalid data column.");
61198
- return { name: name4, label: label4, type: typeFromCode(attribute3(node3, "DataType")) };
61596
+ const label2 = attribute3(node3, "Label") ?? attribute3(node3, "Name") ?? name4;
61597
+ if (!name4 || name4.length > 255 || label2.length > 255) invalid2("Invalid data column.");
61598
+ return { name: name4, label: label2, type: typeFromCode(attribute3(node3, "DataType")) };
61199
61599
  });
61200
61600
  if (!columns.length)
61201
61601
  for (const column2 of ado.columns)
@@ -67858,18 +68258,18 @@ function advances(family, bold) {
67858
68258
  const key2 = `${name3}|${bold ? "b" : "r"}`;
67859
68259
  const known = decoded.get(key2);
67860
68260
  if (known) return known;
67861
- const table3 = Object.hasOwn(DESIGN_ADVANCES, name3) ? DESIGN_ADVANCES[name3] : void 0;
67862
- if (!table3) return void 0;
67863
- const values2 = (bold ? table3.bold : table3.regular).split(" ").map(Number);
68261
+ const table4 = Object.hasOwn(DESIGN_ADVANCES, name3) ? DESIGN_ADVANCES[name3] : void 0;
68262
+ if (!table4) return void 0;
68263
+ const values2 = (bold ? table4.bold : table4.regular).split(" ").map(Number);
67864
68264
  decoded.set(key2, values2);
67865
68265
  return values2;
67866
68266
  }
67867
68267
  function designTextWidthEm(text8, family, bold = false) {
67868
- const table3 = advances(family, bold);
67869
- if (!table3) return void 0;
68268
+ const table4 = advances(family, bold);
68269
+ if (!table4) return void 0;
67870
68270
  let units2 = 0;
67871
68271
  for (let index3 = 0; index3 < text8.length; ++index3) {
67872
- const advance = table3[text8.charCodeAt(index3) - FIRST];
68272
+ const advance = table4[text8.charCodeAt(index3) - FIRST];
67873
68273
  if (advance === void 0 || Number.isNaN(advance)) return void 0;
67874
68274
  units2 += advance;
67875
68275
  }
@@ -71080,9 +71480,9 @@ function visioBorderShapes(style3, width, height, title = VISIO_DEFAULT_TITLE) {
71080
71480
  // visio/edit-page-setup-commands.ts
71081
71481
  var VISIO_SCALE_UNITS = Object.freeze(["IN", "FT", "MM", "CM", "M"]);
71082
71482
  var isVisioPageSetupEdit = (edit) => edit.type === "set-page-alt-text" || edit.type === "set-page-setup" || edit.type === "set-page-properties" || edit.type === "set-page-decoration" || edit.type === "set-page-layout" || edit.type === "set-snap-glue";
71083
- var pageId = (value2, label4) => {
71483
+ var pageId = (value2, label2) => {
71084
71484
  if (typeof value2 !== "string" || !value2 || value2.length > 256)
71085
- fail2("INVALID_EDIT", `Invalid ${label4}.`);
71485
+ fail2("INVALID_EDIT", `Invalid ${label2}.`);
71086
71486
  return value2;
71087
71487
  };
71088
71488
  var newPageId = (value2) => {
@@ -71189,11 +71589,11 @@ var VISIO_SHAPE_DATA_TYPES = [
71189
71589
  "date"
71190
71590
  ];
71191
71591
  var invalidText2 = /[\u0000-\u0008\u000b\u000c\u000e-\u001f￾￿]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/u;
71192
- function shapeDataText(value2, label4) {
71592
+ function shapeDataText(value2, label2) {
71193
71593
  if (typeof value2 !== "string" || value2.length > VISIO_METADATA_TEXT_LIMIT)
71194
- fail2("INVALID_EDIT", `${label4} must be a string within the length limit.`);
71594
+ fail2("INVALID_EDIT", `${label2} must be a string within the length limit.`);
71195
71595
  if (invalidText2.test(value2) || /[\r\n\t]/.test(value2))
71196
- fail2("INVALID_EDIT_TEXT", `${label4} contains invalid characters.`);
71596
+ fail2("INVALID_EDIT_TEXT", `${label2} contains invalid characters.`);
71197
71597
  return value2;
71198
71598
  }
71199
71599
  function shapeDataRowName(value2) {
@@ -71201,9 +71601,9 @@ function shapeDataRowName(value2) {
71201
71601
  fail2("INVALID_EDIT", "Shape Data row names use letters, digits and underscores.");
71202
71602
  return value2;
71203
71603
  }
71204
- function visioShapeDataRowName(label4, taken = []) {
71604
+ function visioShapeDataRowName(label2, taken = []) {
71205
71605
  const used = new Set([...taken].map((name4) => name4.toLowerCase()));
71206
- let base2 = label4.normalize("NFKD").replace(/[^\w]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 48);
71606
+ let base2 = label2.normalize("NFKD").replace(/[^\w]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 48);
71207
71607
  if (!base2) base2 = "Property";
71208
71608
  if (/^\d/.test(base2)) base2 = `_${base2}`;
71209
71609
  let name3 = base2;
@@ -71275,18 +71675,18 @@ var TYPES3 = [
71275
71675
  "unlink-data-rows"
71276
71676
  ];
71277
71677
  var isVisioDataEdit = (edit) => TYPES3.includes(edit.type);
71278
- var id = (value2, label4) => {
71678
+ var id = (value2, label2) => {
71279
71679
  if (typeof value2 !== "string" || !/^(0|[1-9]\d{0,9})$/.test(value2) || Number(value2) > 4294967295)
71280
- fail2("INVALID_EDIT", `Invalid ${label4}.`);
71680
+ fail2("INVALID_EDIT", `Invalid ${label2}.`);
71281
71681
  return value2;
71282
71682
  };
71283
- var name = (value2, label4) => {
71284
- const text8 = shapeDataText(value2, label4);
71683
+ var name = (value2, label2) => {
71684
+ const text8 = shapeDataText(value2, label2);
71285
71685
  if (!text8.trim() || text8.length > 255)
71286
- fail2("INVALID_EDIT", `${label4} must be 1 to 255 characters.`);
71686
+ fail2("INVALID_EDIT", `${label2} must be 1 to 255 characters.`);
71287
71687
  return text8;
71288
71688
  };
71289
- function table2(columns, rows) {
71689
+ function table3(columns, rows) {
71290
71690
  if (!Array.isArray(columns) || !columns.length || columns.length > VISIO_DATA_LIMITS.maxColumns)
71291
71691
  fail2("INVALID_EDIT", `A recordset needs 1 to ${VISIO_DATA_LIMITS.maxColumns} columns.`);
71292
71692
  if (!Array.isArray(rows) || rows.length > VISIO_DATA_LIMITS.maxRows)
@@ -71332,14 +71732,14 @@ function snapshotDataEdit(edit) {
71332
71732
  type: edit.type,
71333
71733
  pageId: pageId2,
71334
71734
  name: name(edit.name, "The recordset name"),
71335
- ...table2(edit.columns, edit.rows)
71735
+ ...table3(edit.columns, edit.rows)
71336
71736
  };
71337
71737
  case "refresh-data-recordset":
71338
71738
  return {
71339
71739
  type: edit.type,
71340
71740
  pageId: pageId2,
71341
71741
  recordsetId: id(edit.recordsetId, "recordset"),
71342
- ...table2(edit.columns, edit.rows)
71742
+ ...table3(edit.columns, edit.rows)
71343
71743
  };
71344
71744
  case "delete-data-recordset":
71345
71745
  return { type: edit.type, pageId: pageId2, recordsetId: id(edit.recordsetId, "recordset") };
@@ -71398,16 +71798,16 @@ function snapshotPageTheme(edit) {
71398
71798
  var isVisioCommentEdit = (edit) => edit.type === "add-comment" || edit.type === "edit-comment" || edit.type === "delete-comment";
71399
71799
  var invalidText3 = /[\u0000-\u0008\u000b\u000c\u000e-\u001f￾￿]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/u;
71400
71800
  var dateTime = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,7})?(?:Z|[+-]\d{2}:\d{2})?$/;
71401
- function string(value2, limit3, label4, required = true) {
71801
+ function string(value2, limit3, label2, required = true) {
71402
71802
  if (typeof value2 !== "string" || value2.length > limit3 || required && !value2.trim())
71403
- fail2("INVALID_EDIT", `${label4} must be a non-empty string within its length limit.`);
71803
+ fail2("INVALID_EDIT", `${label2} must be a non-empty string within its length limit.`);
71404
71804
  if (invalidText3.test(value2))
71405
- fail2("INVALID_EDIT_TEXT", `${label4} contains invalid XML characters.`);
71805
+ fail2("INVALID_EDIT_TEXT", `${label2} contains invalid XML characters.`);
71406
71806
  return value2;
71407
71807
  }
71408
- var id2 = (value2, label4) => {
71808
+ var id2 = (value2, label2) => {
71409
71809
  if (typeof value2 !== "string" || !/^(0|[1-9]\d{0,9})$/.test(value2) || Number(value2) > 4294967295)
71410
- fail2("INVALID_EDIT", `${label4} must be a canonical unsigned integer.`);
71810
+ fail2("INVALID_EDIT", `${label2} must be a canonical unsigned integer.`);
71411
71811
  return value2;
71412
71812
  };
71413
71813
  var date = (value2) => {
@@ -71930,7 +72330,7 @@ async function editVsdxMasterInstance(pkg, parts, pages, edit, limits, maxOutput
71930
72330
 
71931
72331
  // visio/paper-sizes.ts
71932
72332
  var mm = (value2) => value2 / 25.4;
71933
- var size = (id3, label4, width, height, paperKind) => Object.freeze({ id: id3, label: label4, width, height, ...paperKind === void 0 ? {} : { paperKind } });
72333
+ var size = (id3, label2, width, height, paperKind) => Object.freeze({ id: id3, label: label2, width, height, ...paperKind === void 0 ? {} : { paperKind } });
71934
72334
  var VISIO_PAPER_SIZES = Object.freeze([
71935
72335
  size("letter", "Letter", 8.5, 11, 1),
71936
72336
  size("tabloid", "Tabloid", 11, 17, 3),
@@ -73300,7 +73700,7 @@ function snapshotFormatting(edit) {
73300
73700
  if (!Number.isInteger(value2)) fail2("INVALID_EDIT", "Paint patterns require integers.");
73301
73701
  result2[name3] = value2;
73302
73702
  }
73303
- for (const [name3, maximum, label4] of [
73703
+ for (const [name3, maximum, label2] of [
73304
73704
  ["beginArrow", 45, "Arrowheads are numbered 0 to 45."],
73305
73705
  ["endArrow", 45, "Arrowheads are numbered 0 to 45."],
73306
73706
  ["beginArrowSize", 6, "Arrowhead sizes are numbered 0 to 6."],
@@ -73314,7 +73714,7 @@ function snapshotFormatting(edit) {
73314
73714
  const value2 = edit[name3];
73315
73715
  if (value2 === void 0) continue;
73316
73716
  if (typeof value2 !== "number" || !Number.isInteger(value2) || value2 < 0 || value2 > maximum)
73317
- fail2("INVALID_EDIT", label4);
73717
+ fail2("INVALID_EDIT", label2);
73318
73718
  result2[name3] = value2;
73319
73719
  }
73320
73720
  if (edit.rounding !== void 0) result2.rounding = points(edit.rounding, 0, 720);