ooxml-core 1.14.0 → 1.15.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 (104) hide show
  1. package/dist/{PptxHandler-5YP75BPO.cjs → PptxHandler-OGLITB3F.cjs} +2 -2
  2. package/dist/{PptxHandler-KNBFECUE.mjs → PptxHandler-R5BVKEBW.mjs} +2 -2
  3. package/dist/{PptxHandler-GT5Q66TG.mjs → PptxHandler-UKAA5T5U.mjs} +1 -1
  4. package/dist/{PresentationBuilder-II7C4A3R.cjs → PresentationBuilder-4AF3PZHG.cjs} +4 -4
  5. package/dist/{PresentationBuilder-CVM6LJ7L.mjs → PresentationBuilder-54QGEZ2F.mjs} +1 -1
  6. package/dist/{PresentationBuilder-5DCCFHWJ.mjs → PresentationBuilder-W67DIJBV.mjs} +2 -2
  7. package/dist/automation/index.cjs +372 -669
  8. package/dist/automation/index.mjs +372 -669
  9. package/dist/{chunk-ORH32TO3.mjs → chunk-7ZIZFJXT.mjs} +1509 -754
  10. package/dist/{chunk-XGXIS4PN.mjs → chunk-EMZIHAOH.mjs} +1508 -739
  11. package/dist/{chunk-4WZLFUUA.mjs → chunk-HU36GIYM.mjs} +642 -200
  12. package/dist/{chunk-54ASP65T.mjs → chunk-JFMIPOPV.mjs} +1 -1
  13. package/dist/{chunk-2D4IFQ5M.mjs → chunk-NWAQEXBK.mjs} +1 -1
  14. package/dist/{chunk-TNNXOW2O.mjs → chunk-OPBZBSJF.mjs} +1 -1
  15. package/dist/{chunk-TQE7FFNT.cjs → chunk-ZWI7MTLF.cjs} +1509 -754
  16. package/dist/geometry/index.cjs +259 -0
  17. package/dist/geometry/index.d.ts +1 -0
  18. package/dist/geometry/index.d.ts.map +1 -1
  19. package/dist/geometry/index.mjs +255 -1
  20. package/dist/geometry/shape-gallery-catalog.d.ts +32 -0
  21. package/dist/geometry/shape-gallery-catalog.d.ts.map +1 -0
  22. package/dist/index.cjs +371 -112
  23. package/dist/index.mjs +371 -112
  24. package/dist/pptx/automation/index.cjs +2203 -1415
  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-tK7xnWeS.d.ts → elements-Cadkqht8.d.ts} +143 -2
  28. package/dist/pptx/chunks/elements-Cadkqht8.d.ts.map +1 -0
  29. package/dist/pptx/chunks/{index-DS9Y4Ne3.d.ts → index-CJI2EugA.d.ts} +5 -3
  30. package/dist/pptx/chunks/{index-DS9Y4Ne3.d.ts.map → index-CJI2EugA.d.ts.map} +1 -1
  31. package/dist/pptx/chunks/{index-BSpNQuvz.d.ts → index-CozqpSPL.d.ts} +112 -5
  32. package/dist/pptx/chunks/index-CozqpSPL.d.ts.map +1 -0
  33. package/dist/pptx/chunks/{text-operations-BdD_UQ11.d.ts → text-operations-C3L9xrqx.d.ts} +2 -2
  34. package/dist/pptx/chunks/{text-operations-BdD_UQ11.d.ts.map → text-operations-C3L9xrqx.d.ts.map} +1 -1
  35. package/dist/pptx/cli/index.cjs +2151 -1363
  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 +7 -0
  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/find-replace.d.ts +2 -2
  42. package/dist/pptx/editor/render/slide-operations.cjs +1 -1
  43. package/dist/pptx/editor/render/slide-operations.mjs +1 -1
  44. package/dist/pptx/editor/render/text-runs-style-patch.d.ts +1 -1
  45. package/dist/pptx/editor/render/text-style-scope.d.ts +1 -1
  46. package/dist/pptx/index.cjs +2990 -1726
  47. package/dist/pptx/index.d.ts +5 -5
  48. package/dist/pptx/index.mjs +5 -5
  49. package/dist/teams/ics.d.ts.map +1 -1
  50. package/dist/teams/index.cjs +527 -622
  51. package/dist/teams/index.d.ts +1 -0
  52. package/dist/teams/index.d.ts.map +1 -1
  53. package/dist/teams/index.mjs +512 -623
  54. package/dist/teams/meetings.d.ts +11 -1
  55. package/dist/teams/meetings.d.ts.map +1 -1
  56. package/dist/teams/recurrence-calendar.d.ts +41 -0
  57. package/dist/teams/recurrence-calendar.d.ts.map +1 -0
  58. package/dist/teams/recurrence.d.ts +1 -1
  59. package/dist/teams/recurrence.d.ts.map +1 -1
  60. package/dist/teams/server-session.d.ts +19 -0
  61. package/dist/teams/server-session.d.ts.map +1 -1
  62. package/dist/xlsx/edit/pivots.d.ts.map +1 -1
  63. package/dist/xlsx/index.cjs +386 -676
  64. package/dist/xlsx/index.mjs +385 -677
  65. package/dist/xlsx/load/index.cjs +328 -633
  66. package/dist/xlsx/load/index.mjs +328 -633
  67. package/dist/xlsx/model-pivots.d.ts +17 -4
  68. package/dist/xlsx/model-pivots.d.ts.map +1 -1
  69. package/dist/xlsx/pivot/aggregate.d.ts +6 -3
  70. package/dist/xlsx/pivot/aggregate.d.ts.map +1 -1
  71. package/dist/xlsx/pivot/axes.d.ts +5 -0
  72. package/dist/xlsx/pivot/axes.d.ts.map +1 -1
  73. package/dist/xlsx/pivot/columns.d.ts +9 -3
  74. package/dist/xlsx/pivot/columns.d.ts.map +1 -1
  75. package/dist/xlsx/pivot/data.d.ts.map +1 -1
  76. package/dist/xlsx/pivot/date-axes.d.ts +1 -1
  77. package/dist/xlsx/pivot/date-axes.d.ts.map +1 -1
  78. package/dist/xlsx/pivot/date-group-read.d.ts.map +1 -1
  79. package/dist/xlsx/pivot/date-groups.d.ts +8 -3
  80. package/dist/xlsx/pivot/date-groups.d.ts.map +1 -1
  81. package/dist/xlsx/pivot/index.d.ts +2 -1
  82. package/dist/xlsx/pivot/index.d.ts.map +1 -1
  83. package/dist/xlsx/pivot/measures.d.ts +0 -7
  84. package/dist/xlsx/pivot/measures.d.ts.map +1 -1
  85. package/dist/xlsx/pivot/nested.d.ts +4 -2
  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.map +1 -1
  89. package/dist/xlsx/pivot/read.d.ts.map +1 -1
  90. package/dist/xlsx/pivot/subtotals.d.ts +6 -1
  91. package/dist/xlsx/pivot/subtotals.d.ts.map +1 -1
  92. package/dist/xlsx/pivot/table-xml.d.ts.map +1 -1
  93. package/dist/xlsx/pivot/values-axis.d.ts +7 -4
  94. package/dist/xlsx/pivot/values-axis.d.ts.map +1 -1
  95. package/dist/xlsx/ui/commands/i18n/pivots.d.ts.map +1 -1
  96. package/dist/xlsx/ui/index.cjs +271 -584
  97. package/dist/xlsx/ui/index.mjs +271 -584
  98. package/package.json +1 -1
  99. package/dist/pptx/chunks/elements-tK7xnWeS.d.ts.map +0 -1
  100. package/dist/pptx/chunks/index-BSpNQuvz.d.ts.map +0 -1
  101. package/dist/xlsx/pivot/hierarchy-first.d.ts +0 -21
  102. package/dist/xlsx/pivot/hierarchy-first.d.ts.map +0 -1
  103. package/dist/xlsx/pivot/hierarchy.d.ts +0 -8
  104. package/dist/xlsx/pivot/hierarchy.d.ts.map +0 -1
@@ -81,7 +81,7 @@ var DEFAULT_XML_LIMITS = {
81
81
  maxNodes: 5e6
82
82
  };
83
83
  var MARKUP_RE = /<!--[\s\S]*?-->|<!\[CDATA\[[\s\S]*?\]\]>|<\?[\s\S]*?\?>|<(\/?)([^\s\/>]+)(?:\s+[^\s=\/>]+\s*=\s*(?:"[^"]*"|'[^']*'))*\s*(\/?)>/g;
84
- function checkXmlLimits(xml, label5, limits = {}) {
84
+ function checkXmlLimits(xml, label4, limits = {}) {
85
85
  const maxDepth = limits.maxDepth ?? DEFAULT_XML_LIMITS.maxDepth;
86
86
  const maxNodes = limits.maxNodes ?? DEFAULT_XML_LIMITS.maxNodes;
87
87
  let depth = 0;
@@ -94,16 +94,16 @@ function checkXmlLimits(xml, label5, limits = {}) {
94
94
  continue;
95
95
  }
96
96
  nodes++;
97
- if (nodes > maxNodes) throw new Error(`${label5} XML exceeds the limit of ${maxNodes} elements`);
97
+ if (nodes > maxNodes) throw new Error(`${label4} XML exceeds the limit of ${maxNodes} elements`);
98
98
  if (!selfClosing && ++depth > maxDepth)
99
- throw new Error(`${label5} XML exceeds the nesting depth limit of ${maxDepth}`);
99
+ throw new Error(`${label4} XML exceeds the nesting depth limit of ${maxDepth}`);
100
100
  }
101
101
  }
102
102
  function parseXml(xml, options = {}) {
103
- const label5 = options.label ?? "OOXML";
103
+ const label4 = options.label ?? "OOXML";
104
104
  if (/<!DOCTYPE|<!ENTITY/i.test(xml))
105
- throw new Error(`${label5} XML with DTD or entity declarations is not supported`);
106
- checkXmlLimits(xml, label5, options.limits);
105
+ throw new Error(`${label4} XML with DTD or entity declarations is not supported`);
106
+ checkXmlLimits(xml, label4, options.limits);
107
107
  let parseError = "";
108
108
  let parsed;
109
109
  try {
@@ -114,12 +114,12 @@ function parseXml(xml, options = {}) {
114
114
  }).parseFromString(xml, "application/xml");
115
115
  } catch (error) {
116
116
  throw new Error(
117
- `Invalid ${label5} XML: ${error instanceof Error ? error.message : String(error)}`,
117
+ `Invalid ${label4} XML: ${error instanceof Error ? error.message : String(error)}`,
118
118
  { cause: error }
119
119
  );
120
120
  }
121
121
  if (parseError || !parsed.documentElement)
122
- throw new Error(`Invalid ${label5} XML: ${parseError || "missing root element"}`);
122
+ throw new Error(`Invalid ${label4} XML: ${parseError || "missing root element"}`);
123
123
  return parsed;
124
124
  }
125
125
  var buildXml = (node3) => new xmldom.XMLSerializer().serializeToString(node3);
@@ -406,10 +406,10 @@ function withParseWarnings(warnings, fn) {
406
406
  function reportParseWarning(message) {
407
407
  if (sink && !sink.includes(message)) sink.push(message);
408
408
  }
409
- function enumValue(guard2, raw2, label5) {
409
+ function enumValue(guard2, raw2, label4) {
410
410
  if (raw2 === null || raw2 === void 0 || raw2 === "") return void 0;
411
411
  if (guard2(raw2)) return raw2;
412
- reportParseWarning(`Ignored invalid ${label5} value \u201C${raw2}\u201D; it is not allowed by the schema.`);
412
+ reportParseWarning(`Ignored invalid ${label4} value \u201C${raw2}\u201D; it is not allowed by the schema.`);
413
413
  return void 0;
414
414
  }
415
415
 
@@ -13460,8 +13460,8 @@ function parseDiagramDataModel(source2, part) {
13460
13460
  "CONNECTION_ENDPOINT_MISSING",
13461
13461
  `dgm:cxn ${attribute4} references missing point: ${id3}.`
13462
13462
  );
13463
- const label5 = connectionLabel(connection, transitionText);
13464
- connections2.push(label5 ? { ...connection, label: label5 } : connection);
13463
+ const label4 = connectionLabel(connection, transitionText);
13464
+ connections2.push(label4 ? { ...connection, label: label4 } : connection);
13465
13465
  if ((!connection.type || connection.type === "parOf") && !parentById.has(connection.destId))
13466
13466
  parentById.set(connection.destId, connection.sourceId);
13467
13467
  }
@@ -13500,14 +13500,14 @@ function colorList(container) {
13500
13500
  }
13501
13501
  function parseDiagramColors(source2) {
13502
13502
  const root = rootOf2(source2);
13503
- const labels = children(root, "styleLbl", NS.dgm).map((label5) => ({
13504
- name: stringAttribute(label5, "name") ?? "",
13505
- fill: colorList(first(label5, "fillClrLst", NS.dgm)),
13506
- line: colorList(first(label5, "linClrLst", NS.dgm)),
13507
- effect: colorList(first(label5, "effectClrLst", NS.dgm)),
13508
- textLine: colorList(first(label5, "txLinClrLst", NS.dgm)),
13509
- textFill: colorList(first(label5, "txFillClrLst", NS.dgm)),
13510
- textEffect: colorList(first(label5, "txEffectClrLst", NS.dgm))
13503
+ const labels = children(root, "styleLbl", NS.dgm).map((label4) => ({
13504
+ name: stringAttribute(label4, "name") ?? "",
13505
+ fill: colorList(first(label4, "fillClrLst", NS.dgm)),
13506
+ line: colorList(first(label4, "linClrLst", NS.dgm)),
13507
+ effect: colorList(first(label4, "effectClrLst", NS.dgm)),
13508
+ textLine: colorList(first(label4, "txLinClrLst", NS.dgm)),
13509
+ textFill: colorList(first(label4, "txFillClrLst", NS.dgm)),
13510
+ textEffect: colorList(first(label4, "txEffectClrLst", NS.dgm))
13511
13511
  }));
13512
13512
  return { ...parseDefinitionHeader(root), labels };
13513
13513
  }
@@ -13540,16 +13540,16 @@ function parseStyleReferences(style3) {
13540
13540
  var hasContent = (element2) => Boolean(element2 && (element2.attributes.length > 0 || elements(element2).length > 0));
13541
13541
  function parseDiagramQuickStyle(source2) {
13542
13542
  const root = rootOf2(source2);
13543
- const labels = children(root, "styleLbl", NS.dgm).map((label5) => ({
13544
- name: stringAttribute(label5, "name") ?? "",
13545
- ...parseStyleReferences(first(label5, "style", NS.dgm)),
13546
- hasScene3d: Boolean(first(label5, "scene3d", NS.dgm)),
13547
- hasShape3d: hasContent(first(label5, "sp3d", NS.dgm))
13543
+ const labels = children(root, "styleLbl", NS.dgm).map((label4) => ({
13544
+ name: stringAttribute(label4, "name") ?? "",
13545
+ ...parseStyleReferences(first(label4, "style", NS.dgm)),
13546
+ hasScene3d: Boolean(first(label4, "scene3d", NS.dgm)),
13547
+ hasShape3d: hasContent(first(label4, "sp3d", NS.dgm))
13548
13548
  }));
13549
13549
  return {
13550
13550
  ...parseDefinitionHeader(root),
13551
13551
  labels,
13552
- has3d: labels.some((label5) => label5.hasShape3d)
13552
+ has3d: labels.some((label4) => label4.hasShape3d)
13553
13553
  };
13554
13554
  }
13555
13555
  function parseDiagramLayoutSummary(source2) {
@@ -14719,10 +14719,10 @@ function parseDisplayUnits(context, element2) {
14719
14719
  if (!element2) return void 0;
14720
14720
  reportUnmodelled(context, element2, DISPLAY_UNITS);
14721
14721
  const labelElement = cChild(element2, "dispUnitsLbl");
14722
- let label5;
14722
+ let label4;
14723
14723
  if (labelElement) {
14724
14724
  reportUnmodelled(context, labelElement, DISPLAY_UNITS_LABEL);
14725
- label5 = assignDefined(
14725
+ label4 = assignDefined(
14726
14726
  {},
14727
14727
  {
14728
14728
  layout: manualLayout(labelElement),
@@ -14737,7 +14737,7 @@ function parseDisplayUnits(context, element2) {
14737
14737
  {
14738
14738
  builtInUnit: cVal(element2, "builtInUnit"),
14739
14739
  customUnit: cNumber(context, element2, "custUnit"),
14740
- label: label5,
14740
+ label: label4,
14741
14741
  extLst: extensionList2(element2)
14742
14742
  }
14743
14743
  );
@@ -15591,10 +15591,10 @@ function titleXml(context, title) {
15591
15591
  function labelOptionsXml(context, options) {
15592
15592
  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));
15593
15593
  }
15594
- function labelXml(context, label5) {
15594
+ function labelXml(context, label4) {
15595
15595
  return elementXml(
15596
15596
  "dLbl",
15597
- valXml("idx", label5.index) + valXml("delete", label5.deleted) + layoutXml(context, label5.layout) + chartTextXml(context, label5.tx, false) + labelOptionsXml(context, label5) + raw(context, label5.extLst)
15597
+ valXml("idx", label4.index) + valXml("delete", label4.deleted) + layoutXml(context, label4.layout) + chartTextXml(context, label4.tx, false) + labelOptionsXml(context, label4) + raw(context, label4.extLst)
15598
15598
  );
15599
15599
  }
15600
15600
  function dataLabelsXml(context, labels) {
@@ -15602,7 +15602,7 @@ function dataLabelsXml(context, labels) {
15602
15602
  const leaderLines = labels.leaderLines ? elementXml("leaderLines", shapePropertiesXml(context, labels.leaderLines.spPr)) : "";
15603
15603
  return elementXml(
15604
15604
  "dLbls",
15605
- labels.labels.map((label5) => labelXml(context, label5)).join("") + valXml("delete", labels.deleted) + labelOptionsXml(context, labels) + valXml("showLeaderLines", labels.showLeaderLines) + leaderLines + raw(context, labels.extLst)
15605
+ labels.labels.map((label4) => labelXml(context, label4)).join("") + valXml("delete", labels.deleted) + labelOptionsXml(context, labels) + valXml("showLeaderLines", labels.showLeaderLines) + leaderLines + raw(context, labels.extLst)
15606
15606
  );
15607
15607
  }
15608
15608
 
@@ -15623,12 +15623,12 @@ function dataTableXml(context, table3) {
15623
15623
  }
15624
15624
  function displayUnitsXml(context, units2) {
15625
15625
  if (!units2) return "";
15626
- const label5 = units2.label;
15626
+ const label4 = units2.label;
15627
15627
  return elementXml(
15628
15628
  "dispUnits",
15629
- valXml("custUnit", units2.customUnit) + (units2.customUnit === void 0 ? valXml("builtInUnit", units2.builtInUnit) : "") + (label5 ? elementXml(
15629
+ valXml("custUnit", units2.customUnit) + (units2.customUnit === void 0 ? valXml("builtInUnit", units2.builtInUnit) : "") + (label4 ? elementXml(
15630
15630
  "dispUnitsLbl",
15631
- layoutXml(context, label5.layout) + chartTextXml(context, label5.tx, false) + shapePropertiesXml(context, label5.spPr) + textBodyXml(context, label5.txPr)
15631
+ layoutXml(context, label4.layout) + chartTextXml(context, label4.tx, false) + shapePropertiesXml(context, label4.spPr) + textBodyXml(context, label4.txPr)
15632
15632
  ) : "") + raw(context, units2.extLst)
15633
15633
  );
15634
15634
  }
@@ -15653,11 +15653,11 @@ function axisXml(context, axis) {
15653
15653
  }
15654
15654
 
15655
15655
  // chart/write-analysis.ts
15656
- function trendlineLabelXml(context, label5) {
15657
- if (!label5) return "";
15656
+ function trendlineLabelXml(context, label4) {
15657
+ if (!label4) return "";
15658
15658
  return elementXml(
15659
15659
  "trendlineLbl",
15660
- layoutXml(context, label5.layout) + chartTextXml(context, label5.tx, false) + numberFormatXml(label5.numberFormat) + shapePropertiesXml(context, label5.spPr) + textBodyXml(context, label5.txPr) + raw(context, label5.extLst)
15660
+ layoutXml(context, label4.layout) + chartTextXml(context, label4.tx, false) + numberFormatXml(label4.numberFormat) + shapePropertiesXml(context, label4.spPr) + textBodyXml(context, label4.txPr) + raw(context, label4.extLst)
15661
15661
  );
15662
15662
  }
15663
15663
  function trendlineXml(context, trendline) {
@@ -20860,19 +20860,19 @@ var nextSheetId = (workbook) => workbook.sheets.reduce((max, sheet) => Math.max(
20860
20860
  var MAX_ROW = 1048575;
20861
20861
  var MAX_COL = 16383;
20862
20862
  function columnLabel(col) {
20863
- let label5 = "";
20863
+ let label4 = "";
20864
20864
  let n = col + 1;
20865
20865
  while (n > 0) {
20866
20866
  const rem = (n - 1) % 26;
20867
- label5 = String.fromCharCode(65 + rem) + label5;
20867
+ label4 = String.fromCharCode(65 + rem) + label4;
20868
20868
  n = Math.floor((n - 1) / 26);
20869
20869
  }
20870
- return label5;
20870
+ return label4;
20871
20871
  }
20872
- function columnIndex(label5) {
20873
- if (!/^[A-Za-z]{1,3}$/.test(label5)) return -1;
20872
+ function columnIndex(label4) {
20873
+ if (!/^[A-Za-z]{1,3}$/.test(label4)) return -1;
20874
20874
  let n = 0;
20875
- for (const ch of label5.toUpperCase()) n = n * 26 + (ch.charCodeAt(0) - 64);
20875
+ for (const ch of label4.toUpperCase()) n = n * 26 + (ch.charCodeAt(0) - 64);
20876
20876
  return n - 1;
20877
20877
  }
20878
20878
  var formatAddress = (address2) => `${columnLabel(address2.col)}${address2.row + 1}`;
@@ -23231,6 +23231,13 @@ var pivotRowFields = (pivot) => [
23231
23231
  ...pivot.secondRowField ? [pivot.secondRowField] : [],
23232
23232
  ...pivot.secondRowField ? pivot.moreRowFields ?? [] : []
23233
23233
  ];
23234
+ function pivotValuesIndex(pivot) {
23235
+ if (pivot.valuesAxis !== "rows") return -1;
23236
+ const count2 = pivotRowFields(pivot).length;
23237
+ const at2 = pivot.valuesPosition;
23238
+ if (typeof at2 === "number") return Math.min(Math.max(Math.trunc(at2), 0), count2);
23239
+ return at2 === "first" ? 0 : at2 === "between" ? Math.min(1, count2) : count2;
23240
+ }
23234
23241
  var pivotColumnFields = (pivot) => [
23235
23242
  ...pivot.columnField ? [pivot.columnField] : [],
23236
23243
  ...pivot.columnField ? pivot.moreColumnFields ?? [] : []
@@ -23332,7 +23339,7 @@ var LEAP_MONTHS = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
23332
23339
  var MAX_ITEMS = 1e4;
23333
23340
  var pad3 = (value2, width = 2) => String(value2).padStart(width, "0");
23334
23341
  var dateGroupUnits = (group) => PIVOT_DATE_UNITS.filter((unit3) => group.by.includes(unit3));
23335
- var dateGroupFieldName = (unit3, field2) => `${UNIT_TITLES[unit3]} (${field2})`;
23342
+ var dateGroupFieldName = (unit3, field2, group) => group?.localized?.[unit3]?.name ?? `${UNIT_TITLES[unit3]} (${field2})`;
23336
23343
  var dateGroupDays = (group) => group.by.length === 1 && group.by[0] === "days" ? group.days ?? 1 : 1;
23337
23344
  function dateGroupRange(group, serials) {
23338
23345
  let min = Infinity;
@@ -23355,7 +23362,7 @@ var secondsOfDay = (serial) => Math.round((serial - Math.floor(serial)) * 86400)
23355
23362
  function dayBuckets(range2, days) {
23356
23363
  return Math.max(1, Math.ceil((Math.floor(range2.end) - Math.floor(range2.start) + 1) / days));
23357
23364
  }
23358
- function dateUnitLabels(unit3, range2, days, date1904) {
23365
+ function englishDateUnitLabels(unit3, range2, days, date1904) {
23359
23366
  const labels = [`<${isoDay(range2.start, date1904)}`];
23360
23367
  if (unit3 === "seconds" || unit3 === "minutes")
23361
23368
  for (let i2 = 0; i2 < 60; i2++) labels.push(`:${pad3(i2)}`);
@@ -23384,6 +23391,11 @@ function dateUnitLabels(unit3, range2, days, date1904) {
23384
23391
  labels.push(`>${isoDay(range2.end, date1904)}`);
23385
23392
  return labels;
23386
23393
  }
23394
+ function dateUnitLabels(unit3, range2, days, date1904, group) {
23395
+ const english = englishDateUnitLabels(unit3, range2, days, date1904);
23396
+ const localized = group?.localized?.[unit3]?.labels;
23397
+ return localized?.length === english.length ? localized : english;
23398
+ }
23387
23399
  function dateUnitIndex(unit3, range2, days, date1904, serial, count2) {
23388
23400
  if (serial < range2.start) return 0;
23389
23401
  if (serial > range2.end) return count2 - 1;
@@ -23407,7 +23419,7 @@ function derivedDateFields(pivot) {
23407
23419
  for (const group of pivot.dateGroups ?? [])
23408
23420
  for (const unit3 of dateGroupUnits(group))
23409
23421
  derived.push({
23410
- name: dateGroupFieldName(unit3, group.field),
23422
+ name: dateGroupFieldName(unit3, group.field, group),
23411
23423
  unit: unit3,
23412
23424
  group,
23413
23425
  index: databaseFields + derived.length
@@ -23418,7 +23430,7 @@ function countDerived(pivot) {
23418
23430
  let count2 = 0;
23419
23431
  for (const group of pivot.dateGroups ?? [])
23420
23432
  for (const unit3 of dateGroupUnits(group))
23421
- if (pivot.fields.includes(dateGroupFieldName(unit3, group.field))) count2++;
23433
+ if (pivot.fields.includes(dateGroupFieldName(unit3, group.field, group))) count2++;
23422
23434
  return count2;
23423
23435
  }
23424
23436
  var pivotAxisFieldNames = (pivot) => [
@@ -23438,7 +23450,7 @@ function derivedDateLabels(pivot, name3) {
23438
23450
  if (!entry3) return void 0;
23439
23451
  const [group] = resolveDateGroups({ ...pivot, dateGroups: [entry3.group] });
23440
23452
  const range2 = { start: group.start, end: group.end };
23441
- return dateUnitLabels(entry3.unit, range2, dateGroupDays(group), pivot.date1904 ?? false);
23453
+ return dateUnitLabels(entry3.unit, range2, dateGroupDays(group), pivot.date1904 ?? false, group);
23442
23454
  }
23443
23455
  function validateDateGroups(pivot) {
23444
23456
  const groups = pivot.dateGroups;
@@ -23454,18 +23466,16 @@ function validateDateGroups(pivot) {
23454
23466
  seen.add(group.field);
23455
23467
  if (!(pivot.dateFields ?? []).includes(group.field))
23456
23468
  throw new Error("Only fields that contain dates can be grouped by date.");
23457
- if (pivot.pageFilter || pivot.dateFilter)
23458
- throw new Error("Date groups cannot be combined with report filters or timelines.");
23459
23469
  const serials = pivot.records.map((record2) => record2[index3]);
23460
23470
  if (!serials.length || serials.some((v) => typeof v !== "number" || !Number.isFinite(v)))
23461
23471
  throw new Error("Only fields that contain dates can be grouped by date.");
23462
23472
  const range2 = dateGroupRange(group, serials);
23463
23473
  if (range2.start >= range2.end) throw new Error("The date group must end after it starts.");
23464
23474
  for (const unit3 of dateGroupUnits(group)) {
23465
- const name3 = dateGroupFieldName(unit3, group.field);
23475
+ const name3 = dateGroupFieldName(unit3, group.field, group);
23466
23476
  if (pivot.fields.includes(name3))
23467
23477
  throw new Error("A source field already has the name of a date group field.");
23468
- if (dateUnitLabels(unit3, range2, dateGroupDays(group), pivot.date1904 ?? false).length > MAX_ITEMS)
23478
+ if (dateUnitLabels(unit3, range2, dateGroupDays(group), pivot.date1904 ?? false, group).length > MAX_ITEMS)
23469
23479
  throw new Error("The date group has too many items.");
23470
23480
  }
23471
23481
  }
@@ -23479,7 +23489,7 @@ function expandDateGroups(pivot) {
23479
23489
  const tables = derived.map((entry3) => {
23480
23490
  const range2 = { start: entry3.group.start, end: entry3.group.end };
23481
23491
  const days = dateGroupDays(entry3.group);
23482
- const labels = dateUnitLabels(entry3.unit, range2, days, date1904);
23492
+ const labels = dateUnitLabels(entry3.unit, range2, days, date1904, entry3.group);
23483
23493
  return {
23484
23494
  base: pivot.fields.indexOf(entry3.group.field),
23485
23495
  labels,
@@ -23612,15 +23622,13 @@ function normalizedFieldSubtotals(entries) {
23612
23622
  };
23613
23623
  });
23614
23624
  }
23615
- function validateFieldSubtotals(pivot, rowFields) {
23625
+ function validateFieldSubtotals(pivot, axisFields) {
23616
23626
  const entries = pivot.fieldSubtotals;
23617
23627
  if (entries === void 0) return;
23618
23628
  if (!Array.isArray(entries)) throw new Error("Choose valid field subtotals.");
23619
- if (entries.length && pivot.valuesAxis === "rows")
23620
- throw new Error("Field subtotals require Values on columns.");
23621
23629
  const seen = /* @__PURE__ */ new Set();
23622
23630
  for (const entry3 of entries) {
23623
- if (!entry3 || typeof entry3 !== "object" || !rowFields.includes(entry3.field) || seen.has(entry3.field) || !Array.isArray(entry3.functions) || entry3.functions.some((fn) => !PIVOT_AGGREGATES.includes(fn)) || new Set(entry3.functions).size !== entry3.functions.length)
23631
+ if (!entry3 || typeof entry3 !== "object" || !axisFields.includes(entry3.field) || seen.has(entry3.field) || !Array.isArray(entry3.functions) || entry3.functions.some((fn) => !PIVOT_AGGREGATES.includes(fn)) || new Set(entry3.functions).size !== entry3.functions.length)
23624
23632
  throw new Error("Choose valid field subtotals.");
23625
23633
  seen.add(entry3.field);
23626
23634
  }
@@ -23716,17 +23724,18 @@ function validatePivotPageFilter(pivot) {
23716
23724
  throw new Error("Choose a cached literal report filter item.");
23717
23725
  }
23718
23726
  function pivotPageProjection(pivot) {
23719
- return applyPivotGroups(applyPivotItemFilters(pagedProjection(pivot)));
23727
+ const groups = pivot.dateGroups?.length ? { ...pivot, dateGroups: resolveDateGroups(pivot) } : pivot;
23728
+ return applyPivotGroups(applyPivotItemFilters(pagedProjection(groups)));
23720
23729
  }
23721
23730
  function pagedProjection(pivot) {
23722
23731
  const filter2 = pivot.pageFilter;
23723
23732
  if (!filter2) return pivot;
23724
23733
  const labels = /* @__PURE__ */ new Map();
23725
23734
  for (const item of pivotItems(pivot, filter2.field)) {
23726
- const label5 = String(pivotItemLabel(item)).toLowerCase(), key3 = pivotValueKey(item);
23727
- if (label5 === "(all)" || labels.has(label5) && labels.get(label5) !== key3)
23735
+ const label4 = String(pivotItemLabel(item)).toLowerCase(), key3 = pivotValueKey(item);
23736
+ if (label4 === "(all)" || labels.has(label4) && labels.get(label4) !== key3)
23728
23737
  throw new Error("Ambiguous report filter item captions are preserved.");
23729
- labels.set(label5, key3);
23738
+ labels.set(label4, key3);
23730
23739
  }
23731
23740
  if (filter2.item === void 0) return pivot;
23732
23741
  const index3 = pivot.fields.indexOf(filter2.field), key2 = pivotValueKey(filter2.item);
@@ -23865,13 +23874,9 @@ function validatePivotFields(pivot) {
23865
23874
  const columns = pivotColumnFields(pivot);
23866
23875
  if (pivot.moreColumnFields !== void 0 && (!Array.isArray(pivot.moreColumnFields) || pivot.moreColumnFields.length > 0 && !pivot.columnField || pivot.moreColumnFields.length > 62 || pivot.moreColumnFields.some((name3) => typeof name3 !== "string")))
23867
23876
  throw new Error("Choose valid PivotTable column fields.");
23868
- if (pivot.valuesAxis === "rows" && rows.length > 2)
23869
- throw new Error("Values on rows support at most two row fields.");
23870
- if (pivot.valuesAxis === "rows" && columns.length > 1)
23871
- throw new Error("Values on rows support one column field.");
23872
23877
  if (pivot.pageFilter && columns.length > 1)
23873
23878
  throw new Error("Report filters support one column field.");
23874
- validateFieldSubtotals(pivot, rows);
23879
+ validateFieldSubtotals(pivot, [...rows, ...columns]);
23875
23880
  const axisNames = pivotAxisFieldNames(pivot);
23876
23881
  if ((pivot.dateGroups ?? []).some(
23877
23882
  (group) => [...rows, ...columns].some((name3) => name3 === group.field)
@@ -23880,9 +23885,10 @@ function validatePivotFields(pivot) {
23880
23885
  const extras = pivot.additionalValues ?? [];
23881
23886
  if (pivot.valuesAxis !== void 0 && !["columns", "rows"].includes(pivot.valuesAxis))
23882
23887
  throw new Error("Choose a valid Values axis.");
23883
- if (pivot.valuesPosition !== void 0 && !["last", "between", "first"].includes(pivot.valuesPosition))
23888
+ const position2 = pivot.valuesPosition;
23889
+ if (position2 !== void 0 && !["last", "between", "first"].includes(position2) && !(typeof position2 === "number" && Number.isInteger(position2) && position2 >= 0))
23884
23890
  throw new Error("Choose a valid Values position.");
23885
- if ((pivot.valuesPosition === "between" || pivot.valuesPosition === "first") && (pivot.valuesAxis !== "rows" || !pivot.secondRowField))
23891
+ if (position2 !== void 0 && position2 !== "last" && (pivot.valuesAxis !== "rows" || position2 === "between" && !pivot.secondRowField || typeof position2 === "number" && position2 > rows.length))
23886
23892
  throw new Error("Values before or between fields require two row fields and Values on rows.");
23887
23893
  if (pivot.valuesAxis === "rows" && (!Array.isArray(extras) || !extras.length))
23888
23894
  throw new Error("Values on rows require multiple measures.");
@@ -23903,6 +23909,45 @@ function pivotCaption(aggregate2, field2) {
23903
23909
  return `${aggregate2[0].toUpperCase()}${aggregate2.slice(1)} of ${field2}`;
23904
23910
  }
23905
23911
 
23912
+ // xlsx/write/xml-out.ts
23913
+ var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
23914
+ var CONTROL2 = "\0-\b\v\f-" + String.fromCharCode(65534, 65535);
23915
+ var NEEDS_ESCAPE = new RegExp(`[${CONTROL2}\r]|_x[0-9A-Fa-f]{4}_`);
23916
+ var ESCAPABLE = new RegExp(`[${CONTROL2}\r]|_(?=x[0-9A-Fa-f]{4}_)`, "g");
23917
+ function encodeEscapes(text8) {
23918
+ if (!NEEDS_ESCAPE.test(text8)) return text8;
23919
+ return text8.replace(
23920
+ ESCAPABLE,
23921
+ (ch) => `_x${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}_`
23922
+ );
23923
+ }
23924
+ var INVALID_XML2 = new RegExp(`[${CONTROL2}]`, "g");
23925
+ var escapeText3 = (text8) => text8.replace(INVALID_XML2, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
23926
+ var escapeAttr3 = (text8) => text8.replace(INVALID_XML2, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;").replace(/\t/g, "&#9;");
23927
+ function attrs2(values2) {
23928
+ let out = "";
23929
+ for (const [name3, value2] of Object.entries(values2)) {
23930
+ if (value2 === void 0) continue;
23931
+ const text8 = typeof value2 === "boolean" ? value2 ? "1" : "0" : typeof value2 === "number" ? num(value2) : value2;
23932
+ out += ` ${name3}="${escapeAttr3(text8)}"`;
23933
+ }
23934
+ return out;
23935
+ }
23936
+ var el4 = (name3, values2 = {}, content2 = "") => content2 ? `<${name3}${attrs2(values2)}>${content2}</${name3}>` : `<${name3}${attrs2(values2)}/>`;
23937
+ var num = (value2) => Object.is(value2, -0) ? "0" : String(value2);
23938
+ function tElement(text8, name3 = "t") {
23939
+ const encoded = escapeText3(encodeEscapes(text8));
23940
+ const preserve = /^\s|\s$|\n|\t/.test(text8) ? ' xml:space="preserve"' : "";
23941
+ return `<${name3}${preserve}>${encoded}</${name3}>`;
23942
+ }
23943
+ var MAIN_NS = ' xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"';
23944
+ function inlineFragment(xml) {
23945
+ const end = xml.indexOf(">");
23946
+ if (end < 0) return xml;
23947
+ const head = xml.slice(0, end);
23948
+ return head.includes(MAIN_NS) ? head.replace(MAIN_NS, "") + xml.slice(end) : xml;
23949
+ }
23950
+
23906
23951
  // xlsx/pivot/measures.ts
23907
23952
  var pivotMeasures = (pivot) => [
23908
23953
  { field: pivot.valueField, aggregate: pivot.aggregate, caption: pivot.valueCaption },
@@ -23952,329 +23997,17 @@ function aggregateValues(records, field2, type) {
23952
23997
  return type === "average" ? sum3 / numbers3.length : sum3;
23953
23998
  }
23954
23999
  var pivotMeasureNumber = (pivot, records, measure2) => aggregateValues(records, pivot.fields.indexOf(measure2.field), measure2.aggregate);
23955
- var pivotNumbers = (pivot, records) => pivotMeasures(pivot).map((measure2) => pivotMeasureNumber(pivot, records, measure2));
23956
- function pivotHeaderDimensions(pivot, columnItems, rowLabels) {
23957
- return {
23958
- rows: (pivot.columnField ? 2 : 1) + (pivot.pageFilter ? 2 : 0),
23959
- width: rowLabels + (pivot.columnField ? columnItems + 1 : 1)
23960
- };
23961
- }
23962
- function pivotHeaders(pivot, columns, labels, label5) {
23963
- const rowLabels = pivot.layout === "compact" ? ["Row Labels"] : pivot.valuesPosition === "first" ? ["Values", ...labels] : pivot.valuesPosition === "between" ? [labels[0], "Values", labels[1]] : [...labels, "Values"];
23964
- return pivot.columnField ? [
23965
- [
23966
- ...rowLabels.map(() => null),
23967
- pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
23968
- ...columns.map(() => null)
23969
- ],
23970
- [...rowLabels, ...columns.map(label5), "Grand Total"]
23971
- ] : [[...rowLabels, null]];
23972
- }
23973
-
23974
- // xlsx/pivot/hierarchy-first.ts
23975
- function appendFirstPivotValues(pivot, context) {
23976
- const {
23977
- rowItems,
23978
- secondRowItems,
23979
- columnItems,
23980
- children: children4,
23981
- innerIndices,
23982
- groups,
23983
- details,
23984
- buckets,
23985
- width,
23986
- rowLabels,
23987
- top,
23988
- bottom,
23989
- append
23990
- } = context;
23991
- const compact3 = pivot.layout === "compact";
23992
- const tabular = !pivot.layout || pivot.layout === "tabular";
23993
- const blank = () => Array(width - rowLabels).fill(null);
23994
- pivotMeasures(pivot).forEach((measure2, m) => {
23995
- const numbers3 = (keys, records) => [
23996
- ...columnItems.map(
23997
- (column2) => pivotMeasureNumber(
23998
- pivot,
23999
- buckets.get(JSON.stringify([...keys, pivotValueKey(column2)])) ?? [],
24000
- measure2
24001
- )
24002
- ),
24003
- pivotMeasureNumber(pivot, records, measure2)
24004
- ];
24005
- if (!tabular)
24006
- append([measure2.caption, ...Array(rowLabels - 1).fill(null)], blank(), {
24007
- indices: [m],
24008
- measure: m
24009
- });
24010
- let first3 = true;
24011
- rowItems.forEach((outer, outerIndex) => {
24012
- const key2 = pivotValueKey(outer);
24013
- const group = groups.get(key2) ?? [];
24014
- if (!tabular)
24015
- append(
24016
- compact3 ? [pivotItemLabel(outer)] : [null, pivotItemLabel(outer), null],
24017
- top ? numbers3([key2], group) : blank(),
24018
- { indices: [m, outerIndex], measure: m },
24019
- compact3 ? 1 : 0
24020
- );
24021
- const innerKeys = [...children4.get(key2)].sort(
24022
- (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
24023
- );
24024
- innerKeys.forEach((innerKey, child7) => {
24025
- const innerIndex = innerIndices.get(innerKey);
24026
- append(
24027
- compact3 ? [pivotItemLabel(secondRowItems[innerIndex])] : [
24028
- tabular && first3 ? measure2.caption : null,
24029
- pivot.repeatLabels || tabular && child7 === 0 ? pivotItemLabel(outer) : null,
24030
- pivotItemLabel(secondRowItems[innerIndex])
24031
- ],
24032
- numbers3([key2, innerKey], details.get(JSON.stringify([key2, innerKey]))),
24033
- { indices: [m, outerIndex, innerIndex], measure: m },
24034
- compact3 ? 2 : 0
24035
- );
24036
- first3 = false;
24037
- });
24038
- if (bottom)
24039
- append(
24040
- compact3 ? [`${String(pivotItemLabel(outer))} Total`] : [null, `${String(pivotItemLabel(outer))} Total`, null],
24041
- numbers3([key2], group),
24042
- { indices: [m, outerIndex], measure: m, type: "default" },
24043
- compact3 ? 1 : 0
24044
- );
24045
- });
24046
- });
24047
- }
24048
-
24049
- // xlsx/pivot/hierarchy.ts
24050
- var label = pivotItemLabel;
24051
- function hierarchicalPivotGrid(pivot) {
24052
- const rowItems = pivotItems(pivot, pivot.rowField);
24053
- const secondRowItems = pivotItems(pivot, pivot.secondRowField);
24054
- const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
24055
- const outerField = pivot.fields.indexOf(pivot.rowField);
24056
- const innerField = pivot.fields.indexOf(pivot.secondRowField);
24057
- const columnField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
24058
- const layout3 = pivot.layout ?? "tabular";
24059
- const compact3 = layout3 === "compact";
24060
- const firstValues = pivot.valuesPosition === "first";
24061
- const between = pivot.valuesPosition === "between";
24062
- const measures2 = pivotMeasures(pivot);
24063
- const top = firstValues && layout3 !== "tabular" && pivot.subtotals !== false && (pivot.subtotalPosition ?? "top") === "top";
24064
- const bottom = pivot.subtotals !== false && !top;
24065
- const rowLabelColumns = compact3 ? 1 : 3;
24066
- const groups = /* @__PURE__ */ new Map();
24067
- const details = /* @__PURE__ */ new Map();
24068
- const children4 = /* @__PURE__ */ new Map();
24069
- const innerIndices = new Map(secondRowItems.map((item, index3) => [pivotValueKey(item), index3]));
24070
- const buckets = /* @__PURE__ */ new Map();
24071
- const collect = (map, key2, record2) => {
24072
- const list2 = map.get(key2);
24073
- if (list2) list2.push(record2);
24074
- else map.set(key2, [record2]);
24075
- };
24076
- for (const record2 of pivot.records) {
24077
- const outer = pivotValueKey(record2[outerField] ?? null);
24078
- const inner2 = pivotValueKey(record2[innerField] ?? null);
24079
- collect(groups, outer, record2);
24080
- collect(details, JSON.stringify([outer, inner2]), record2);
24081
- if (!children4.has(outer)) children4.set(outer, /* @__PURE__ */ new Set());
24082
- children4.get(outer).add(inner2);
24083
- if (pivot.columnField) {
24084
- const column2 = pivotValueKey(record2[columnField] ?? null);
24085
- for (const key2 of [[], [outer], [outer, inner2]])
24086
- collect(buckets, JSON.stringify([...key2, column2]), record2);
24087
- }
24088
- }
24089
- const dimensions3 = pivotHeaderDimensions(pivot, columnItems.length, rowLabelColumns);
24090
- const rows = (details.size + rowItems.length * Number(bottom) + 1) * measures2.length + rowItems.length * Number(layout3 !== "tabular") * (firstValues ? measures2.length : 1) + (firstValues ? measures2.length : between ? rowItems.length * measures2.length : details.size) * Number(layout3 !== "tabular") + dimensions3.rows;
24091
- if (rows * dimensions3.width > 1e6) throw new Error("The PivotTable result is too large.");
24092
- const labels = compact3 ? ["Row Labels"] : [pivot.rowField, pivot.secondRowField];
24093
- const values2 = pivotHeaders(pivot, columnItems, labels, label);
24094
- const firstDataRow = values2.length;
24095
- const indents = values2.map(() => 0);
24096
- const rowEntries = [];
24097
- const append = (labels2, numbers4, entry3, indent = 0) => {
24098
- values2.push([...labels2, ...numbers4]);
24099
- rowEntries.push(entry3);
24100
- indents.push(indent);
24101
- };
24102
- const bands = (keys, records) => [
24103
- ...columnItems.map(
24104
- (column2) => pivotNumbers(pivot, buckets.get(JSON.stringify([...keys, pivotValueKey(column2)])) ?? [])
24105
- ),
24106
- pivotNumbers(pivot, records)
24107
- ];
24108
- const numbers3 = (keys, records) => bands(keys, records).flat();
24109
- const appendMeasures = (labels2, keys, records, indices, type) => {
24110
- const values3 = bands(keys, records);
24111
- measures2.forEach(
24112
- (measure2, m) => append(
24113
- type ? [
24114
- `${type === "grand" ? "Total" : String(labels2[0])} ${measure2.caption}`,
24115
- ...Array(rowLabelColumns - 1).fill(null)
24116
- ] : compact3 ? [measure2.caption] : [
24117
- ...labels2.map(
24118
- (label5) => layout3 === "tabular" && m === 0 || pivot.repeatLabels ? label5 : null
24119
- ),
24120
- measure2.caption
24121
- ],
24122
- values3.map((band2) => band2[m] ?? null),
24123
- { indices: type ? indices : [...indices, m], measure: m, ...type ? { type } : {} },
24124
- compact3 && !type ? 2 : 0
24125
- )
24126
- );
24127
- };
24128
- if (firstValues)
24129
- appendFirstPivotValues(pivot, {
24130
- rowItems,
24131
- secondRowItems,
24132
- columnItems,
24133
- children: children4,
24134
- innerIndices,
24135
- groups,
24136
- details,
24137
- buckets,
24138
- width: dimensions3.width,
24139
- rowLabels: rowLabelColumns,
24140
- top,
24141
- bottom,
24142
- append
24143
- });
24144
- else
24145
- rowItems.forEach((outer, outerIndex) => {
24146
- const key2 = pivotValueKey(outer);
24147
- if (layout3 !== "tabular")
24148
- append(
24149
- [label(outer), ...Array(rowLabelColumns - 1).fill(null)],
24150
- top ? numbers3([key2], groups.get(key2) ?? []) : Array(dimensions3.width - rowLabelColumns).fill(null),
24151
- { indices: [outerIndex] }
24152
- );
24153
- let first3 = true;
24154
- const innerKeys = [...children4.get(key2)].sort(
24155
- (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
24156
- );
24157
- if (between)
24158
- measures2.forEach((measure2, m) => {
24159
- if (layout3 !== "tabular")
24160
- append(
24161
- compact3 ? [measure2.caption] : [pivot.repeatLabels ? label(outer) : null, measure2.caption, null],
24162
- Array(dimensions3.width - rowLabelColumns).fill(null),
24163
- { indices: [outerIndex, m], measure: m },
24164
- compact3 ? 1 : 0
24165
- );
24166
- innerKeys.forEach((innerKey, child7) => {
24167
- const innerIndex = innerIndices.get(innerKey);
24168
- const keys = [key2, innerKey];
24169
- const records = details.get(JSON.stringify(keys));
24170
- append(
24171
- compact3 ? [label(secondRowItems[innerIndex])] : [
24172
- pivot.repeatLabels || layout3 === "tabular" && m === 0 && child7 === 0 ? label(outer) : null,
24173
- layout3 === "tabular" && child7 === 0 ? measure2.caption : null,
24174
- label(secondRowItems[innerIndex])
24175
- ],
24176
- [
24177
- ...columnItems.map(
24178
- (column2) => pivotMeasureNumber(
24179
- pivot,
24180
- buckets.get(JSON.stringify([...keys, pivotValueKey(column2)])) ?? [],
24181
- measure2
24182
- )
24183
- ),
24184
- pivotMeasureNumber(pivot, records, measure2)
24185
- ],
24186
- { indices: [outerIndex, m, innerIndex], measure: m },
24187
- compact3 ? 2 : 0
24188
- );
24189
- });
24190
- });
24191
- else
24192
- innerKeys.forEach((innerKey) => {
24193
- const innerIndex = innerIndices.get(innerKey);
24194
- const inner2 = secondRowItems[innerIndex];
24195
- const keys = [key2, innerKey];
24196
- const records = details.get(JSON.stringify(keys));
24197
- if (!records) return;
24198
- if (layout3 !== "tabular")
24199
- append(
24200
- compact3 ? [label(inner2)] : [pivot.repeatLabels ? label(outer) : null, label(inner2), null],
24201
- Array(dimensions3.width - rowLabelColumns).fill(null),
24202
- { indices: [outerIndex, innerIndex] },
24203
- compact3 ? 1 : 0
24204
- );
24205
- appendMeasures(
24206
- [pivot.repeatLabels || first3 ? label(outer) : null, label(inner2)],
24207
- keys,
24208
- records,
24209
- [outerIndex, innerIndex]
24210
- );
24211
- first3 = false;
24212
- });
24213
- if (bottom)
24214
- appendMeasures([label(outer)], [key2], groups.get(key2) ?? [], [outerIndex], "default");
24215
- });
24216
- appendMeasures([], [], pivot.records, [0], "grand");
24217
- return {
24218
- values: values2,
24219
- rowItems,
24220
- secondRowItems,
24221
- columnItems,
24222
- rowEntries,
24223
- firstDataRow,
24224
- rowLabelColumns,
24225
- indents,
24226
- firstHeaderRow: 1
24227
- };
24228
- }
24229
-
24230
- // xlsx/write/xml-out.ts
24231
- var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
24232
- var CONTROL2 = "\0-\b\v\f-" + String.fromCharCode(65534, 65535);
24233
- var NEEDS_ESCAPE = new RegExp(`[${CONTROL2}\r]|_x[0-9A-Fa-f]{4}_`);
24234
- var ESCAPABLE = new RegExp(`[${CONTROL2}\r]|_(?=x[0-9A-Fa-f]{4}_)`, "g");
24235
- function encodeEscapes(text8) {
24236
- if (!NEEDS_ESCAPE.test(text8)) return text8;
24237
- return text8.replace(
24238
- ESCAPABLE,
24239
- (ch) => `_x${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}_`
24240
- );
24241
- }
24242
- var INVALID_XML2 = new RegExp(`[${CONTROL2}]`, "g");
24243
- var escapeText3 = (text8) => text8.replace(INVALID_XML2, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
24244
- var escapeAttr3 = (text8) => text8.replace(INVALID_XML2, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;").replace(/\t/g, "&#9;");
24245
- function attrs2(values2) {
24246
- let out = "";
24247
- for (const [name3, value2] of Object.entries(values2)) {
24248
- if (value2 === void 0) continue;
24249
- const text8 = typeof value2 === "boolean" ? value2 ? "1" : "0" : typeof value2 === "number" ? num(value2) : value2;
24250
- out += ` ${name3}="${escapeAttr3(text8)}"`;
24251
- }
24252
- return out;
24253
- }
24254
- var el4 = (name3, values2 = {}, content2 = "") => content2 ? `<${name3}${attrs2(values2)}>${content2}</${name3}>` : `<${name3}${attrs2(values2)}/>`;
24255
- var num = (value2) => Object.is(value2, -0) ? "0" : String(value2);
24256
- function tElement(text8, name3 = "t") {
24257
- const encoded = escapeText3(encodeEscapes(text8));
24258
- const preserve = /^\s|\s$|\n|\t/.test(text8) ? ' xml:space="preserve"' : "";
24259
- return `<${name3}${preserve}>${encoded}</${name3}>`;
24260
- }
24261
- var MAIN_NS = ' xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"';
24262
- function inlineFragment(xml) {
24263
- const end = xml.indexOf(">");
24264
- if (end < 0) return xml;
24265
- const head = xml.slice(0, end);
24266
- return head.includes(MAIN_NS) ? head.replace(MAIN_NS, "") + xml.slice(end) : xml;
24267
- }
24268
24000
 
24269
24001
  // xlsx/pivot/columns.ts
24270
24002
  var SEPARATOR = "";
24271
- var label2 = pivotItemLabel;
24003
+ var label = pivotItemLabel;
24272
24004
  var columnKey = (keys, depth) => keys.slice(0, depth).join(SEPARATOR);
24273
24005
  var recordColumnKeys = (record2, indices) => indices.map((index3) => pivotValueKey(record2[index3] ?? null));
24274
24006
  function pivotColumnEntries(pivot) {
24275
24007
  const names = pivotColumnFields(pivot);
24276
24008
  const items = names.map((name3) => pivotItems(pivot, name3));
24277
24009
  const entries = [];
24010
+ const functions = names.map((name3) => fieldSubtotalFunctions(pivot, name3));
24278
24011
  if (names.length) {
24279
24012
  const order = items.map(
24280
24013
  (list2) => new Map(list2.map((item, index3) => [pivotValueKey(item), index3]))
@@ -24309,7 +24042,9 @@ function pivotColumnEntries(pivot) {
24309
24042
  if (level === names.length - 1) entries.push({ kind: "leaf", ...entry3 });
24310
24043
  else {
24311
24044
  visit2(child7[1], level + 1, here.path, here.values, here.keys);
24312
- entries.push({ kind: "subtotal", ...entry3 });
24045
+ const own2 = functions[level];
24046
+ if (own2 === "auto") entries.push({ kind: "subtotal", ...entry3 });
24047
+ else for (const fn of own2) entries.push({ kind: "subtotal", ...entry3, fn });
24313
24048
  }
24314
24049
  }
24315
24050
  };
@@ -24318,25 +24053,28 @@ function pivotColumnEntries(pivot) {
24318
24053
  entries.push({ kind: "grand", path: [], key: "", values: [] });
24319
24054
  return { names, items, entries };
24320
24055
  }
24321
- function pivotColumnDimensions(pivot, columns, labelColumns) {
24322
- const measures2 = 1 + (pivot.additionalValues?.length ?? 0);
24056
+ function pivotColumnDimensions(pivot, columns, labelColumns, valuesOnRows = false) {
24057
+ const measures2 = valuesOnRows ? 1 : 1 + (pivot.additionalValues?.length ?? 0);
24323
24058
  const levels = columns.names.length;
24324
24059
  return {
24325
24060
  rows: (levels ? levels + 1 + Number(measures2 > 1) : 1) + (pivot.pageFilter ? 2 : 0),
24326
24061
  width: labelColumns + (levels ? columns.entries.length : 1) * measures2
24327
24062
  };
24328
24063
  }
24329
- function pivotColumnHeaders(pivot, columns, rowLabels) {
24330
- const measures2 = pivotMeasures(pivot);
24064
+ function pivotColumnHeaders(pivot, columns, rowLabels, valuesOnRows = false) {
24065
+ const measures2 = valuesOnRows ? pivotMeasures(pivot).slice(0, 1) : pivotMeasures(pivot);
24331
24066
  const count2 = measures2.length;
24332
24067
  const levels = columns.names.length;
24333
- if (!levels) return [[...rowLabels, ...measures2.map((measure2) => measure2.caption)]];
24068
+ if (!levels)
24069
+ return [
24070
+ [...rowLabels, ...valuesOnRows ? [null] : measures2.map((measure2) => measure2.caption)]
24071
+ ];
24334
24072
  const compact3 = pivot.layout === "compact";
24335
24073
  const labelColumns = rowLabels.length;
24336
24074
  const width = labelColumns + columns.entries.length * count2;
24337
24075
  const rows = levels + 1 + Number(count2 > 1);
24338
24076
  const grid = Array.from({ length: rows }, () => Array(width).fill(null));
24339
- if (count2 === 1) grid[0][0] = pivot.valueCaption;
24077
+ if (count2 === 1 && !valuesOnRows) grid[0][0] = pivot.valueCaption;
24340
24078
  const titles = compact3 ? ["Column Labels"] : [...columns.names, ...count2 > 1 ? ["Values"] : []];
24341
24079
  titles.forEach((title, i2) => {
24342
24080
  grid[0][labelColumns + i2] = title;
@@ -24350,16 +24088,17 @@ function pivotColumnHeaders(pivot, columns, rowLabels) {
24350
24088
  if (entry3.kind === "leaf") {
24351
24089
  entry3.path.forEach((_index, level) => {
24352
24090
  const continued = entry3.path.slice(0, level + 1).every((p, i2) => p === previous[i2]);
24353
- if (!continued) grid[1 + level][at2] = label2(entry3.values[level]);
24091
+ if (!continued) grid[1 + level][at2] = label(entry3.values[level]);
24354
24092
  });
24355
24093
  previous = entry3.path;
24356
24094
  if (count2 > 1) measures2.forEach((measure2, m) => grid[rows - 1][at2 + m] = measure2.caption);
24357
24095
  return;
24358
24096
  }
24359
24097
  const row3 = entry3.kind === "grand" ? 1 : entry3.path.length;
24360
- const name3 = entry3.kind === "grand" ? "" : String(label2(entry3.values.at(-1)));
24098
+ const name3 = entry3.kind === "grand" ? "" : String(label(entry3.values.at(-1)));
24361
24099
  measures2.forEach((measure2, m) => {
24362
- grid[row3][at2 + m] = count2 === 1 ? entry3.kind === "grand" ? "Grand Total" : `${name3} Total` : entry3.kind === "grand" ? `Total ${measure2.caption}` : `${name3} ${measure2.caption}`;
24100
+ const custom = entry3.fn ? PIVOT_SUBTOTALS[entry3.fn].label : void 0;
24101
+ 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}`;
24363
24102
  });
24364
24103
  });
24365
24104
  return grid;
@@ -24384,7 +24123,7 @@ function pivotColumnItemsXml(entries, measures2, remap) {
24384
24123
  const prefix3 = sharedPrefix(path2, previous);
24385
24124
  const xs = path2.slice(prefix3).map((index3) => `<x${attrs2({ v: index3 || void 0 })}/>`);
24386
24125
  out.push(
24387
- `<i${attrs2({ t: entry3.kind === "subtotal" ? "default" : void 0, r: prefix3 || void 0, i: m || void 0 })}>${xs.join("")}</i>`
24126
+ `<i${attrs2({ t: entry3.kind === "subtotal" ? entry3.fn ? PIVOT_SUBTOTALS[entry3.fn].item : "default" : void 0, r: prefix3 || void 0, i: m || void 0 })}>${xs.join("")}</i>`
24388
24127
  );
24389
24128
  previous = path2;
24390
24129
  }
@@ -24392,7 +24131,7 @@ function pivotColumnItemsXml(entries, measures2, remap) {
24392
24131
  }
24393
24132
 
24394
24133
  // xlsx/pivot/nested.ts
24395
- var label3 = pivotItemLabel;
24134
+ var label2 = pivotItemLabel;
24396
24135
  var MAX_CELLS = 1e6;
24397
24136
  var node = (index3, value2) => ({
24398
24137
  index: index3,
@@ -24404,6 +24143,10 @@ var node = (index3, value2) => ({
24404
24143
  function nestedPivotGrid(pivot) {
24405
24144
  const names = pivotRowFields(pivot);
24406
24145
  const depth = names.length;
24146
+ const valuesAt = pivotValuesIndex(pivot);
24147
+ const onRows = valuesAt >= 0;
24148
+ const levels = depth + (onRows ? 1 : 0);
24149
+ const fieldOf = (level) => !onRows || level < valuesAt ? level : level === valuesAt ? -1 : level - 1;
24407
24150
  const axisItems = names.map((name3) => pivotItems(pivot, name3));
24408
24151
  const itemIndices = axisItems.map(
24409
24152
  (items) => new Map(items.map((item, index3) => [pivotValueKey(item), index3]))
@@ -24415,125 +24158,168 @@ function nestedPivotGrid(pivot) {
24415
24158
  const compact3 = layout3 === "compact";
24416
24159
  const tabular = layout3 === "tabular";
24417
24160
  const above = !tabular && (pivot.subtotalPosition ?? "top") === "top";
24418
- const labelColumns = compact3 ? 1 : depth;
24161
+ const labelColumns = compact3 ? 1 : levels;
24419
24162
  const measures2 = pivotMeasures(pivot);
24163
+ const functions = names.map((name3) => fieldSubtotalFunctions(pivot, name3));
24420
24164
  const root = node(0, null);
24421
24165
  for (const record2 of pivot.records) {
24422
24166
  const keys = recordColumnKeys(record2, columnFields);
24423
24167
  let current = root;
24424
- for (let level = -1; level < depth; level++) {
24425
- if (level >= 0) {
24426
- const value2 = record2[fieldIndices[level]] ?? null;
24168
+ for (let field2 = -1; field2 < depth; field2++) {
24169
+ if (field2 >= 0) {
24170
+ const value2 = record2[fieldIndices[field2]] ?? null;
24427
24171
  const key2 = pivotValueKey(value2);
24428
24172
  let child7 = current.children.get(key2);
24429
24173
  if (!child7) {
24430
- child7 = node(itemIndices[level].get(key2), value2);
24174
+ child7 = node(itemIndices[field2].get(key2), value2);
24431
24175
  current.children.set(key2, child7);
24432
24176
  }
24433
24177
  current = child7;
24434
24178
  }
24435
24179
  current.records.push(record2);
24436
- for (let width = 1; width <= keys.length; width++) {
24437
- const key2 = columnKey(keys, width);
24180
+ for (let width2 = 1; width2 <= keys.length; width2++) {
24181
+ const key2 = columnKey(keys, width2);
24438
24182
  const list2 = current.columns.get(key2);
24439
24183
  if (list2) list2.push(record2);
24440
24184
  else current.columns.set(key2, [record2]);
24441
24185
  }
24442
24186
  }
24443
24187
  }
24444
- const dimensions3 = pivotColumnDimensions(pivot, columns, labelColumns);
24445
- const functions = names.map((name3) => fieldSubtotalFunctions(pivot, name3));
24446
- let rows = 1;
24447
- const count2 = (parent, level) => {
24448
- for (const child7 of parent.children.values()) {
24449
- rows++;
24450
- if (level < depth - 1) {
24451
- const f6 = functions[level];
24452
- rows += f6 === "auto" ? 1 : f6.length;
24453
- count2(child7, level + 1);
24454
- }
24455
- }
24456
- };
24457
- count2(root, 0);
24458
- if ((rows + dimensions3.rows) * dimensions3.width > MAX_CELLS)
24459
- throw new Error("The PivotTable result is too large.");
24460
- const values2 = pivotColumnHeaders(pivot, columns, compact3 ? ["Row Labels"] : names);
24461
- const firstDataRow = values2.length;
24462
- const indents = values2.map(() => 0);
24188
+ const dimensions3 = pivotColumnDimensions(pivot, columns, labelColumns, onRows);
24189
+ const rowTitles = names.map((name3) => name3);
24190
+ if (onRows) rowTitles.splice(valuesAt, 0, "Values");
24191
+ let values2 = [];
24192
+ let indents = [];
24463
24193
  const rowEntries = [];
24464
- const blanks = () => Array(dimensions3.width - labelColumns).fill(null);
24465
- const bands = (group, run2) => columns.entries.flatMap(
24466
- (entry3) => run2(entry3.kind === "grand" ? group.records : group.columns.get(entry3.key) ?? [])
24467
- );
24468
- const numbers3 = (group) => bands(group, (records) => pivotNumbers(pivot, records));
24469
- const subtotalNumbers = (group, fn) => bands(
24470
- group,
24471
- (records) => measures2.map((measure2) => aggregateValues(records, pivot.fields.indexOf(measure2.field), fn))
24472
- );
24473
- const labelCells = (path2, shown, text8) => {
24194
+ let counting = true;
24195
+ let rowCount = 0;
24196
+ const width = dimensions3.width - labelColumns;
24197
+ const blanks = () => Array(width).fill(null);
24198
+ const cells3 = (group, rowFn, measure2) => columns.entries.flatMap((entry3) => {
24199
+ const records = entry3.kind === "grand" ? group.records : group.columns.get(entry3.key) ?? [];
24200
+ const picked = measure2 === void 0 ? measures2 : [measures2[measure2]];
24201
+ if (rowFn && entry3.fn && rowFn !== entry3.fn) return picked.map(() => null);
24202
+ const fn = rowFn ?? entry3.fn;
24203
+ return picked.map(
24204
+ (one2) => fn ? aggregateValues(records, pivot.fields.indexOf(one2.field), fn) : pivotMeasureNumber(pivot, records, one2)
24205
+ );
24206
+ });
24207
+ const labelCells = (path2, shown, level, text8) => {
24474
24208
  if (compact3) return [text8];
24475
- const cells3 = Array(depth).fill(null);
24476
- path2.forEach((value2, level) => {
24477
- if (shown[level]) cells3[level] = label3(value2);
24209
+ const row3 = Array(levels).fill(null);
24210
+ path2.labels.forEach((value2, at2) => {
24211
+ if (shown[at2]) row3[at2] = value2;
24478
24212
  });
24479
- cells3[path2.length] = text8;
24480
- return cells3;
24213
+ row3[level] = text8;
24214
+ return row3;
24481
24215
  };
24482
- const push3 = (cells3, numbersOnRow, entry3, indent) => {
24483
- values2.push([...cells3, ...numbersOnRow]);
24216
+ const push3 = (indent, build3) => {
24217
+ if (counting) {
24218
+ if ((++rowCount + dimensions3.rows) * dimensions3.width > MAX_CELLS)
24219
+ throw new Error("The PivotTable result is too large.");
24220
+ return;
24221
+ }
24222
+ const [cells4, numbers3, entry3] = build3();
24223
+ values2.push([...cells4, ...numbers3]);
24484
24224
  rowEntries.push(entry3);
24485
24225
  indents.push(compact3 ? indent : 0);
24486
24226
  };
24487
- const emit = (parent, level, path2, indices, firsts) => {
24488
- const last = level === depth - 1;
24489
- const own2 = functions[level];
24490
- const children4 = [...parent.children.values()].sort((a2, b) => a2.index - b.index);
24227
+ const entryOf = (indices, measure2, type) => ({
24228
+ indices,
24229
+ ...measure2 !== void 0 ? { measure: measure2 } : {},
24230
+ ...type ? { type } : {}
24231
+ });
24232
+ const walk2 = (level, group, measure2, path2) => {
24233
+ const field2 = fieldOf(level);
24234
+ const last = level === levels - 1;
24235
+ const repeated = Array.from(
24236
+ { length: level },
24237
+ (_v, k) => !!pivot.repeatLabels && fieldOf(k) >= 0
24238
+ );
24239
+ const leafShown = (firsts) => repeated.map((repeat, k) => repeat || tabular && firsts.slice(k + 1).every(Boolean));
24240
+ if (field2 < 0) {
24241
+ measures2.forEach((one2, m) => {
24242
+ const here = {
24243
+ labels: [...path2.labels, one2.caption],
24244
+ indices: [...path2.indices, m],
24245
+ firsts: [...path2.firsts, m === 0]
24246
+ };
24247
+ if (last)
24248
+ return push3(level, () => [
24249
+ labelCells(path2, leafShown(here.firsts), level, one2.caption),
24250
+ cells3(group, void 0, m),
24251
+ entryOf(here.indices, m)
24252
+ ]);
24253
+ if (!tabular)
24254
+ push3(level, () => [
24255
+ labelCells(path2, repeated, level, one2.caption),
24256
+ blanks(),
24257
+ entryOf(here.indices, m)
24258
+ ]);
24259
+ walk2(level + 1, group, m, here);
24260
+ });
24261
+ return;
24262
+ }
24263
+ const own2 = functions[field2];
24264
+ const valuesAbove = !onRows || valuesAt < level;
24265
+ const showsValue = above && own2 === "auto" && valuesAbove;
24266
+ const children4 = [...group.children.values()].sort((a2, b) => a2.index - b.index);
24491
24267
  children4.forEach((child7, position2) => {
24492
- const here = [...path2, child7.value];
24493
- const at2 = [...indices, child7.index];
24494
- const firstHere = [...firsts, position2 === 0];
24495
- const repeated = Array(level).fill(!!pivot.repeatLabels);
24496
- if (last) {
24497
- const shown = repeated.map(
24498
- (repeat, k) => repeat || tabular && firstHere.slice(k + 1).every(Boolean)
24499
- );
24500
- push3(labelCells(path2, shown, label3(child7.value)), numbers3(child7), { indices: at2 }, level);
24501
- return;
24502
- }
24268
+ const here = {
24269
+ labels: [...path2.labels, label2(child7.value)],
24270
+ indices: [...path2.indices, child7.index],
24271
+ firsts: [...path2.firsts, position2 === 0]
24272
+ };
24273
+ const text8 = label2(child7.value);
24274
+ if (last)
24275
+ return push3(level, () => [
24276
+ labelCells(path2, leafShown(here.firsts), level, text8),
24277
+ cells3(child7, void 0, measure2),
24278
+ entryOf(here.indices, measure2)
24279
+ ]);
24503
24280
  if (!tabular)
24504
- push3(
24505
- labelCells(path2, repeated, label3(child7.value)),
24506
- own2 === "auto" && above ? numbers3(child7) : blanks(),
24507
- { indices: at2 },
24508
- level
24509
- );
24510
- emit(child7, level + 1, here, at2, firstHere);
24511
- const caption = String(label3(child7.value));
24281
+ push3(level, () => [
24282
+ labelCells(path2, repeated, level, text8),
24283
+ showsValue ? cells3(child7, void 0, measure2) : blanks(),
24284
+ entryOf(here.indices, measure2)
24285
+ ]);
24286
+ walk2(level + 1, child7, measure2, here);
24287
+ if (field2 === depth - 1) return;
24288
+ const caption = String(text8);
24289
+ const subtotal = (title, fn, one2) => push3(level, () => [
24290
+ labelCells(path2, repeated, level, title),
24291
+ cells3(child7, fn, one2),
24292
+ entryOf(here.indices, one2, fn ?? "default")
24293
+ ]);
24512
24294
  if (own2 === "auto") {
24513
- if (!above)
24514
- push3(
24515
- labelCells(path2, repeated, `${caption} Total`),
24516
- numbers3(child7),
24517
- { indices: at2, type: "default" },
24518
- level
24519
- );
24295
+ if (showsValue) return;
24296
+ if (valuesAbove) subtotal(`${caption} Total`, void 0, measure2);
24297
+ else measures2.forEach((one2, m) => subtotal(`${caption} ${one2.caption}`, void 0, m));
24520
24298
  } else
24521
24299
  for (const fn of own2)
24522
- push3(
24523
- labelCells(path2, repeated, `${caption} ${PIVOT_SUBTOTALS[fn].label}`),
24524
- subtotalNumbers(child7, fn),
24525
- { indices: at2, type: fn },
24526
- level
24527
- );
24300
+ if (valuesAbove) subtotal(`${caption} ${PIVOT_SUBTOTALS[fn].label}`, fn, measure2);
24301
+ else
24302
+ measures2.forEach(
24303
+ (one2, m) => subtotal(`${caption} ${PIVOT_SUBTOTALS[fn].label} of ${one2.field}`, fn, m)
24304
+ );
24528
24305
  });
24529
24306
  };
24530
- emit(root, 0, [], [], []);
24531
- push3(
24532
- compact3 ? ["Grand Total"] : ["Grand Total", ...Array(depth - 1).fill(null)],
24533
- numbers3(root),
24534
- { indices: [0], type: "grand" },
24535
- 0
24536
- );
24307
+ const grand = (text8, measure2) => push3(0, () => [
24308
+ compact3 ? [text8] : [text8, ...Array(levels - 1).fill(null)],
24309
+ cells3(root, void 0, measure2),
24310
+ entryOf([0], measure2, "grand")
24311
+ ]);
24312
+ const build2 = () => {
24313
+ walk2(0, root, void 0, { labels: [], indices: [], firsts: [] });
24314
+ if (onRows) measures2.forEach((one2, m) => grand(`Total ${one2.caption}`, m));
24315
+ else grand("Grand Total");
24316
+ };
24317
+ build2();
24318
+ counting = false;
24319
+ values2 = pivotColumnHeaders(pivot, columns, compact3 ? ["Row Labels"] : rowTitles, onRows);
24320
+ const firstDataRow = values2.length;
24321
+ indents = values2.map(() => 0);
24322
+ build2();
24537
24323
  return {
24538
24324
  values: values2,
24539
24325
  rowItems: axisItems[0],
@@ -24545,105 +24331,15 @@ function nestedPivotGrid(pivot) {
24545
24331
  rowEntries,
24546
24332
  firstDataRow,
24547
24333
  rowLabelColumns: labelColumns,
24548
- indents
24334
+ indents,
24335
+ ...onRows ? { firstHeaderRow: 1 } : {}
24549
24336
  };
24550
24337
  }
24551
24338
 
24552
24339
  // xlsx/pivot/aggregate.ts
24553
24340
  function pivotGrid(pivot) {
24554
24341
  validatePivotFields(pivot);
24555
- return prependPivotPage(pivotDataGrid(pivotPageProjection(pivot)), pivot);
24556
- }
24557
- function pivotDataGrid(pivot) {
24558
- if (pivot.valuesAxis !== "rows") return nestedPivotGrid(pivot);
24559
- if (pivot.secondRowField) return hierarchicalPivotGrid(pivot);
24560
- const rowItems = pivotItems(pivot, pivot.rowField);
24561
- const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
24562
- const compact3 = pivot.layout === "compact";
24563
- const headings = pivot.layout !== void 0 && pivot.layout !== "tabular";
24564
- const dimensions3 = pivotHeaderDimensions(pivot, columnItems.length, compact3 ? 1 : 2);
24565
- const dataRows = (rowItems.length + 1) * (1 + (pivot.additionalValues?.length ?? 0)) + (headings ? rowItems.length : 0);
24566
- if ((dataRows + dimensions3.rows) * dimensions3.width > 1e6)
24567
- throw new Error("The PivotTable result is too large.");
24568
- const label5 = pivotItemLabel;
24569
- const values2 = pivotHeaders(pivot, columnItems, [compact3 ? "Row Labels" : pivot.rowField], label5);
24570
- const rowField = pivot.fields.indexOf(pivot.rowField);
24571
- const colField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
24572
- const groups = /* @__PURE__ */ new Map();
24573
- const cells3 = /* @__PURE__ */ new Map();
24574
- const columns = /* @__PURE__ */ new Map();
24575
- const collect = (map, key2, record2) => {
24576
- const found = map.get(key2);
24577
- if (found) found.push(record2);
24578
- else map.set(key2, [record2]);
24579
- };
24580
- for (const record2 of pivot.records) {
24581
- const key2 = pivotValueKey(record2[rowField] ?? null);
24582
- collect(groups, key2, record2);
24583
- if (pivot.columnField) {
24584
- const col = pivotValueKey(record2[colField] ?? null);
24585
- collect(columns, col, record2);
24586
- collect(cells3, JSON.stringify([key2, col]), record2);
24587
- }
24588
- }
24589
- const firstDataRow = values2.length;
24590
- const measures2 = pivotMeasures(pivot);
24591
- const rowEntries = [];
24592
- const indents = values2.map(() => 0);
24593
- const append = (caption, bands, index3, grand = false) => {
24594
- measures2.forEach((measure2, m) => {
24595
- values2.push([
24596
- ...compact3 ? [grand ? `Total ${measure2.caption}` : measure2.caption] : [
24597
- grand ? `Total ${measure2.caption}` : pivot.repeatLabels || !headings && m === 0 ? caption : null,
24598
- grand ? null : measure2.caption
24599
- ],
24600
- ...bands.map((band2) => band2[m] ?? null)
24601
- ]);
24602
- indents.push(compact3 && !grand ? 1 : 0);
24603
- rowEntries.push({
24604
- indices: grand ? [0] : [index3, m],
24605
- measure: m,
24606
- ...grand ? { type: "grand" } : {}
24607
- });
24608
- });
24609
- };
24610
- rowItems.forEach((item, index3) => {
24611
- const key2 = pivotValueKey(item);
24612
- if (headings) {
24613
- values2.push([label5(item), ...Array(dimensions3.width - 1).fill(null)]);
24614
- rowEntries.push({ indices: [index3] });
24615
- indents.push(0);
24616
- }
24617
- append(
24618
- label5(item),
24619
- [
24620
- ...columnItems.map(
24621
- (col) => pivotNumbers(pivot, cells3.get(JSON.stringify([key2, pivotValueKey(col)])) ?? [])
24622
- ),
24623
- pivotNumbers(pivot, groups.get(key2) ?? [])
24624
- ],
24625
- index3
24626
- );
24627
- });
24628
- append(
24629
- "Grand Total",
24630
- [
24631
- ...columnItems.map((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
24632
- pivotNumbers(pivot, pivot.records)
24633
- ],
24634
- 0,
24635
- true
24636
- );
24637
- return {
24638
- values: values2,
24639
- rowItems,
24640
- columnItems,
24641
- firstDataRow,
24642
- rowLabelColumns: compact3 ? 1 : 2,
24643
- indents,
24644
- firstHeaderRow: 1,
24645
- rowEntries
24646
- };
24342
+ return prependPivotPage(nestedPivotGrid(pivotPageProjection(pivot)), pivot);
24647
24343
  }
24648
24344
  function pivotTableAt(sheet, at2) {
24649
24345
  return sheet.pivotTables?.find((pivot) => rangeContains(pivot.location, at2));
@@ -25268,7 +24964,7 @@ function readFieldGroups(fields, names) {
25268
24964
  throw new Error("Unsupported pivot field group");
25269
24965
  const labels = children(list2, "s", NS.x).map((node3) => decodeEscapes(att(node3, "v") ?? ""));
25270
24966
  const expected = numberGroupLabels({ start, end, by });
25271
- if (elements(list2).length !== labels.length || labels.length !== expected.length || labels.some((label5, i2) => label5 !== expected[i2]))
24967
+ if (elements(list2).length !== labels.length || labels.length !== expected.length || labels.some((label4, i2) => label4 !== expected[i2]))
25272
24968
  throw new Error("Unsupported pivot group items");
25273
24969
  groups.push({ field: names[index3] ?? "", start, end, by });
25274
24970
  });
@@ -25346,14 +25042,18 @@ function readDateGroups(fields, count2, names, dateFields, records, date1904) {
25346
25042
  const expected = dateGroupRange(group, serials);
25347
25043
  if (!close(expected.start, start) || !close(expected.end, end))
25348
25044
  throw unsupported("stale range");
25045
+ const localized = {};
25349
25046
  for (const entry3 of list2) {
25350
- const labels = dateUnitLabels(entry3.unit, expected, dateGroupDays(group), date1904);
25047
+ const labels = englishDateUnitLabels(entry3.unit, expected, dateGroupDays(group), date1904);
25351
25048
  const node3 = first(first(entry3.node, "fieldGroup", NS.x), "groupItems", NS.x);
25352
25049
  const actual = children(node3, "s", NS.x).map((item) => decodeEscapes(att(item, "v") ?? ""));
25353
- if (att(entry3.node, "name") === void 0 || decodeEscapes(att(entry3.node, "name")) !== dateGroupFieldName(entry3.unit, field2) || elements(node3).length !== actual.length || actual.length !== labels.length || actual.some((label5, i2) => label5 !== labels[i2]))
25050
+ const name3 = decodeEscapes(att(entry3.node, "name") ?? "");
25051
+ if (!name3 || elements(node3).length !== actual.length || actual.length !== labels.length || actual.some((label4) => !label4) || new Set(actual).size !== actual.length)
25354
25052
  throw unsupported("group items");
25053
+ if (name3 !== dateGroupFieldName(entry3.unit, field2) || actual.some((l, i2) => l !== labels[i2]))
25054
+ localized[entry3.unit] = { name: name3, labels: actual };
25355
25055
  }
25356
- groups.push(group);
25056
+ groups.push(Object.keys(localized).length ? { ...group, localized } : group);
25357
25057
  }
25358
25058
  return groups;
25359
25059
  }
@@ -25412,6 +25112,7 @@ function remapPivotRowEntries(entries, axes2) {
25412
25112
  (entry3) => entry3.type === "grand" ? entry3 : {
25413
25113
  ...entry3,
25414
25114
  indices: entry3.indices.map((item, axis) => {
25115
+ if (axes2[axis] === null) return item;
25415
25116
  const index3 = axes2[axis]?.[item];
25416
25117
  if (index3 === void 0) throw new Error("Invalid report row axis item");
25417
25118
  return index3;
@@ -25430,7 +25131,7 @@ function pivotValueIndex(root, axis) {
25430
25131
  const position2 = root.getAttribute("dataPosition");
25431
25132
  if (position2 !== null && (!/^\d+$/.test(position2.trim()) || Number(position2) !== index3))
25432
25133
  throw new Error("Inconsistent Values axis position");
25433
- if (axis.length === 3 && index3 >= 0 && index3 < 2 && position2 === null)
25134
+ if (index3 >= 0 && index3 < axis.length - 1 && position2 === null)
25434
25135
  throw new Error("Missing leading or between-field Values position");
25435
25136
  return index3;
25436
25137
  }
@@ -25445,7 +25146,7 @@ function pivotValueAxisItems(measures2) {
25445
25146
  function supportedPivotAxes(rows, columns, measures2, valuesOnRows) {
25446
25147
  const index3 = pivotFieldIndex;
25447
25148
  if (valuesOnRows)
25448
- return measures2 > 1 && (rows.length === 2 || rows.length === 3) && (index3(rows[0]) >= 0 || rows.length === 3) && rows.filter((field2) => index3(field2) === -2).length === 1 && rows.filter((field2) => index3(field2) !== -2).every((field2) => index3(field2) >= 0) && columns.length <= 1 && (!columns.length || index3(columns[0]) >= 0);
25149
+ return measures2 > 1 && rows.length > 1 && rows.filter((field2) => index3(field2) === -2).length === 1 && rows.filter((field2) => index3(field2) !== -2).every((field2) => index3(field2) >= 0) && columns.every((field2) => index3(field2) >= 0);
25449
25150
  if (rows.some((field2) => !Number.isInteger(index3(field2)) || index3(field2) < 0)) return false;
25450
25151
  if (measures2 > 1 && (!columns.length || index3(columns.at(-1)) !== -2)) return false;
25451
25152
  return (measures2 > 1 ? columns.slice(0, -1) : columns).every(
@@ -25466,6 +25167,9 @@ function assertPageAxisItems(root, pivot, shared, cache3, recordRoot) {
25466
25167
  literals(cache3);
25467
25168
  literals(recordRoot);
25468
25169
  const cacheFields = children(first(cache3, "cacheFields", NS.x), "cacheField", NS.x);
25170
+ const all2 = expandDateGroups(pivot).fields;
25171
+ const derived = all2.slice(pivot.fields.length).map((name3) => groupLabelsOf(pivot, name3) ?? []);
25172
+ const sharedAll = [...shared, ...derived];
25469
25173
  if (pivot.columnField) {
25470
25174
  const column2 = children(first(root, "pivotFields", NS.x), "pivotField", NS.x)[pivot.fields.indexOf(pivot.columnField)];
25471
25175
  const list2 = first(column2, "extLst", NS.x);
@@ -25484,13 +25188,13 @@ function assertPageAxisItems(root, pivot, shared, cache3, recordRoot) {
25484
25188
  ))
25485
25189
  throw new Error("Repeated report column labels are preserved");
25486
25190
  }
25487
- if (integer3(first(cache3, "cacheFields", NS.x)?.getAttribute("count") ?? null) !== pivot.fields.length || integer3(cache3.getAttribute("recordCount")) !== pivot.records.length || integer3(recordRoot.getAttribute("count")) !== pivot.records.length)
25191
+ if (integer3(first(cache3, "cacheFields", NS.x)?.getAttribute("count") ?? null) !== all2.length || integer3(cache3.getAttribute("recordCount")) !== pivot.records.length || integer3(recordRoot.getAttribute("count")) !== pivot.records.length)
25488
25192
  throw new Error("Inconsistent report cache counts");
25489
25193
  for (const name3 of [...pivotRowFields(pivot), pivot.columnField, pivot.pageFilter.field].filter(
25490
25194
  Boolean
25491
25195
  )) {
25492
- const field2 = pivot.fields.indexOf(name3);
25493
- if (integer3(first(cacheFields[field2], "sharedItems", NS.x)?.getAttribute("count") ?? null) !== shared[field2].length)
25196
+ const field2 = all2.indexOf(name3);
25197
+ if (field2 < pivot.fields.length && integer3(first(cacheFields[field2], "sharedItems", NS.x)?.getAttribute("count") ?? null) !== shared[field2].length)
25494
25198
  throw new Error("Inconsistent report shared-item counts");
25495
25199
  }
25496
25200
  for (const name3 of ["rowFields", "colFields"]) {
@@ -25500,7 +25204,7 @@ function assertPageAxisItems(root, pivot, shared, cache3, recordRoot) {
25500
25204
  }
25501
25205
  const projected = pivotPageProjection(pivot), fields = children(first(root, "pivotFields", NS.x), "pivotField", NS.x);
25502
25206
  const axisValues = (name3, axis) => {
25503
- const f6 = pivot.fields.indexOf(name3), node3 = fields[f6], list2 = first(node3, "items", NS.x), items = children(list2, "item", NS.x), count2 = shared[f6].length;
25207
+ const f6 = all2.indexOf(name3), node3 = fields[f6], list2 = first(node3, "items", NS.x), items = children(list2, "item", NS.x), count2 = sharedAll[f6].length;
25504
25208
  if (node3.getAttribute("axis") !== axis) throw new Error("Inconsistent report axis field");
25505
25209
  const defaults = node3.getAttribute("defaultSubtotal") !== "0";
25506
25210
  if (!list2 || integer3(list2.getAttribute("count")) !== items.length || items.length !== count2 + Number(defaults))
@@ -25509,7 +25213,7 @@ function assertPageAxisItems(root, pivot, shared, cache3, recordRoot) {
25509
25213
  const i2 = integer3(item.getAttribute("x"));
25510
25214
  if (item.hasAttribute("t") || !Number.isInteger(i2) || i2 >= count2)
25511
25215
  throw new Error("Invalid page-axis cache item");
25512
- return shared[f6][i2];
25216
+ return sharedAll[f6][i2];
25513
25217
  });
25514
25218
  if (new Set(data.map(pivotValueKey)).size !== count2 || defaults && (items.at(-1)?.getAttribute("t") !== "default" || items.at(-1)?.hasAttribute("x")))
25515
25219
  throw new Error("Invalid page-axis default item");
@@ -25645,7 +25349,7 @@ function readOne(workbook, source2, part) {
25645
25349
  "dataField",
25646
25350
  NS.x
25647
25351
  );
25648
- if (rowFields.length < 1 || rowsAxis && rowFields.length > 3 || dataFields.length < 1 || dataFields.length > 16 || !supportedPivotAxes(rowFields, colFields, dataFields.length, rowsAxis) || root.getAttribute("rowGrandTotals") === "0" || root.getAttribute("colGrandTotals") === "0")
25352
+ if (rowFields.length < 1 || dataFields.length < 1 || dataFields.length > 16 || !supportedPivotAxes(rowFields, colFields, dataFields.length, rowsAxis) || root.getAttribute("rowGrandTotals") === "0" || root.getAttribute("colGrandTotals") === "0")
25649
25353
  throw new Error("Unsupported pivot layout");
25650
25354
  const valueIndex = pivotValueIndex(root, rowsAxis ? rowFields : colFields);
25651
25355
  const measure2 = dataFields[0];
@@ -25715,8 +25419,8 @@ function readOne(workbook, source2, part) {
25715
25419
  const col = columnNames[0];
25716
25420
  const moreColumns = columnNames.slice(1);
25717
25421
  const columnDefinitions = columnDefs.map((field2) => tableFields[Number(att(field2, "x"))]);
25718
- if (fieldSubtotalsOf(columnDefinitions.slice(0, -1), columnNames.slice(0, -1)).length || columnNames.some((name3) => !name3))
25719
- throw new Error("Column subtotal settings are preserved");
25422
+ if (columnNames.some((name3) => !name3)) throw new Error("Invalid pivot column fields");
25423
+ const columnSubtotals = fieldSubtotalsOf(columnDefinitions, columnNames);
25720
25424
  const data = names[Number(att(measure2, "fld"))];
25721
25425
  const location = parseRange(att(first(root, "location", NS.x), "ref") ?? "");
25722
25426
  if (!row3 || !data || !location || hasColumn && !col || realRows.length === 2 && !second)
@@ -25757,8 +25461,10 @@ function readOne(workbook, source2, part) {
25757
25461
  ]);
25758
25462
  if (dateFields.some((field2) => onAxis.has(field2)))
25759
25463
  throw new Error("Date fields used as rows, columns or values are preserved");
25760
- if ([...realRows, ...columnDefs].some((field2) => pivotFieldIndex(field2) >= databaseCount) && (pageFilter || dateFilter || itemFilters || slicerCacheId !== void 0))
25761
- throw new Error("Date groups with filters are preserved");
25464
+ const fieldSubtotals = [
25465
+ ...subtotalSettings.filter((entry4) => entry4.field !== row3 || entry4.functions.length),
25466
+ ...columnSubtotals
25467
+ ];
25762
25468
  const pivot = {
25763
25469
  ...pageFilter ? { pageFilter } : {},
25764
25470
  ...itemFilters ? { itemFilters } : {},
@@ -25773,13 +25479,11 @@ function readOne(workbook, source2, part) {
25773
25479
  rowField: row3,
25774
25480
  layout: layout3,
25775
25481
  ...rowsAxis ? { valuesAxis: "rows" } : {},
25776
- ...rowsAxis && realRows.length === 2 && valueIndex < 2 ? { valuesPosition: valueIndex === 0 ? "first" : "between" } : {},
25777
- subtotalPosition: att(outer, "subtotalTop") === "0" ? "bottom" : "top",
25778
- ...subtotalSettings.some((entry4) => entry4.field !== row3 || entry4.functions.length) ? {
25779
- fieldSubtotals: subtotalSettings.filter(
25780
- (entry4) => entry4.field !== row3 || entry4.functions.length
25781
- )
25482
+ ...rowsAxis && valueIndex < realRows.length ? {
25483
+ valuesPosition: valueIndex === 0 ? "first" : valueIndex === 1 && realRows.length === 2 ? "between" : valueIndex
25782
25484
  } : {},
25485
+ subtotalPosition: att(outer, "subtotalTop") === "0" ? "bottom" : "top",
25486
+ ...fieldSubtotals.length ? { fieldSubtotals } : {},
25783
25487
  ...more.length ? { moreRowFields: more } : {},
25784
25488
  ...second ? { secondRowField: second, subtotals: subtotal, repeatLabels: repeat[0] ?? false } : {
25785
25489
  ...subtotal ? {} : { subtotals: false },
@@ -28027,8 +27731,8 @@ function parseTable3(xml, partName) {
28027
27731
  if (id3 !== void 0 && Number.isInteger(id3) && id3 >= 0) column2.sourceId = id3;
28028
27732
  const fn = att(node3, "totalsRowFunction");
28029
27733
  if (fn && fn !== "none") column2.totalsRowFunction = fn;
28030
- const label5 = att(node3, "totalsRowLabel");
28031
- if (label5 !== void 0) column2.totalsRowLabel = label5;
27734
+ const label4 = att(node3, "totalsRowLabel");
27735
+ if (label4 !== void 0) column2.totalsRowLabel = label4;
28032
27736
  const calculated = xFirst(node3, "calculatedColumnFormula");
28033
27737
  if (calculated) column2.calculatedColumnFormula = stripFuturePrefixes(xText(calculated));
28034
27738
  return column2;
@@ -30905,11 +30609,11 @@ function gammaLn(z) {
30905
30609
 
30906
30610
  // xlsx/formula/functions/database.ts
30907
30611
  var C3 = "Database";
30908
- var label4 = (value2) => value2 === null ? "" : typeof value2 === "string" ? value2 : String(value2);
30612
+ var label3 = (value2) => value2 === null ? "" : typeof value2 === "string" ? value2 : String(value2);
30909
30613
  function tableOf(ctx, value2) {
30910
30614
  const [head, ...records] = ctx.toMatrix(value2 ?? null).data;
30911
30615
  if (!head || records.length === 0) fail(ERR.VALUE);
30912
- return { headers: head.map((v) => label4(v).toLowerCase()), records };
30616
+ return { headers: head.map((v) => label3(v).toLowerCase()), records };
30913
30617
  }
30914
30618
  function fieldIndex(table3, field2) {
30915
30619
  const value2 = scalar2(field2);
@@ -30919,7 +30623,7 @@ function fieldIndex(table3, field2) {
30919
30623
  if (index4 < 0 || index4 >= table3.headers.length) fail(ERR.VALUE);
30920
30624
  return index4;
30921
30625
  }
30922
- const index3 = table3.headers.indexOf(label4(value2).toLowerCase());
30626
+ const index3 = table3.headers.indexOf(label3(value2).toLowerCase());
30923
30627
  if (index3 < 0) fail(ERR.VALUE);
30924
30628
  return index3;
30925
30629
  }
@@ -30928,7 +30632,7 @@ function recordFilter(table3, criteria) {
30928
30632
  if (!head || rows.length === 0) fail(ERR.VALUE);
30929
30633
  const columns = head.map((name3) => {
30930
30634
  if (name3 === null || name3 === "") return -1;
30931
- return table3.headers.indexOf(label4(name3).toLowerCase());
30635
+ return table3.headers.indexOf(label3(name3).toLowerCase());
30932
30636
  });
30933
30637
  const alternatives = rows.map(
30934
30638
  (row3) => row3.flatMap((cell, c2) => {
@@ -43721,15 +43425,15 @@ function derivedFields(pivot, date1904) {
43721
43425
  function derivedFieldXml(pivot, entry3, date1904) {
43722
43426
  const range2 = { start: entry3.group.start, end: entry3.group.end };
43723
43427
  const days = dateGroupDays(entry3.group);
43724
- const labels = dateUnitLabels(entry3.unit, range2, days, date1904);
43428
+ const labels = dateUnitLabels(entry3.unit, range2, days, date1904, entry3.group);
43725
43429
  const base2 = pivot.fields.indexOf(entry3.group.field);
43726
- 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((label5) => `<s v="${escapeAttr3(label5)}"/>`).join("")}</groupItems></fieldGroup></cacheField>`;
43430
+ 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>`;
43727
43431
  }
43728
43432
  function groupXml2(pivot, name3, index3) {
43729
43433
  const group = groupOf(pivot, name3);
43730
43434
  if (!group) return "";
43731
43435
  const labels = numberGroupLabels(group);
43732
- return `<fieldGroup base="${index3}"><rangePr autoStart="0" autoEnd="0" startNum="${group.start}" endNum="${group.end}" groupInterval="${group.by}"/><groupItems count="${labels.length}">${labels.map((label5) => `<s v="${escapeAttr3(label5)}"/>`).join("")}</groupItems></fieldGroup>`;
43436
+ 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>`;
43733
43437
  }
43734
43438
  function slicerExt(pivot) {
43735
43439
  if (pivot.slicerCacheId === void 0) return "";
@@ -43750,8 +43454,6 @@ function pivotTableXml(source2, cacheId, cache3) {
43750
43454
  const pivot = expandDateGroups(source2);
43751
43455
  const rowNames = pivotRowFields(pivot);
43752
43456
  const rowIdx = rowNames.map((name3) => pivot.fields.indexOf(name3));
43753
- const row3 = rowIdx[0];
43754
- const second = rowIdx[1] ?? -1;
43755
43457
  const page = pivot.pageFilter ? pivot.fields.indexOf(pivot.pageFilter.field) : -1;
43756
43458
  const pageItems = page >= 0 ? pivotItems(pivot, pivot.pageFilter.field) : [];
43757
43459
  const filtered2 = filteredFields(pivot);
@@ -43779,7 +43481,10 @@ function pivotTableXml(source2, cacheId, cache3) {
43779
43481
  const columnIndicesFull = columnNames.map(
43780
43482
  (_name, k) => itemIndices(visibleColumns[k], columnItemsFull[k])
43781
43483
  );
43782
- const rowEntries = anyFull && grid.rowEntries ? remapPivotRowEntries(grid.rowEntries, rowIndicesFull) : grid.rowEntries;
43484
+ const valuesAt = pivotValuesIndex(pivot);
43485
+ const levelAxes = [...rowIndicesFull];
43486
+ if (valuesAt >= 0) levelAxes.splice(valuesAt, 0, null);
43487
+ const rowEntries = anyFull && grid.rowEntries ? remapPivotRowEntries(grid.rowEntries, levelAxes) : grid.rowEntries;
43783
43488
  const pageOffset = page >= 0 ? 2 : 0;
43784
43489
  const col = columnIdx[0] ?? -1;
43785
43490
  const measures2 = pivotMeasures(pivot);
@@ -43794,7 +43499,7 @@ function pivotTableXml(source2, cacheId, cache3) {
43794
43499
  const colAt = columnIdx.indexOf(index3);
43795
43500
  const items2 = index3 === page ? pageItems : at2 >= 0 ? rowItemsFull[at2] : colAt >= 0 ? columnItemsFull[colAt] : groupLabelsOf(pivot, name3) ?? (filtered2.has(name3) || isDate ? pivotItems(pivot, name3) : void 0);
43796
43501
  const hidden = hiddenItemKeys(pivot, name3);
43797
- const functions = at2 >= 0 ? fieldSubtotalFunctions(pivot, name3) : "auto";
43502
+ const functions = at2 >= 0 || colAt >= 0 ? fieldSubtotalFunctions(pivot, name3) : "auto";
43798
43503
  const automatic = functions === "auto";
43799
43504
  const custom = automatic ? [] : functions;
43800
43505
  const repeated = pivot.repeatLabels && at2 >= 0 ? `<extLst><ext uri="{2946ED86-A175-432a-8AC1-64E0C546D7DE}"><x14:pivotField xmlns:x14="${X143}" fillDownLabels="1"/></ext></extLst>` : "";
@@ -43806,33 +43511,23 @@ function pivotTableXml(source2, cacheId, cache3) {
43806
43511
  }).join("");
43807
43512
  const items = (count2, indices) => Array.from({ length: count2 }, (_v, i2) => `<i><x v="${indices?.[i2] ?? i2}"/></i>`).join("") + '<i t="grand"><x/></i>';
43808
43513
  const header = grid.firstHeaderRow !== void 0 ? grid.firstHeaderRow - pageOffset : col >= 0 ? 1 : grid.firstDataRow - pageOffset - 1;
43809
- const rowIndices = rowsAxis && pivot.valuesPosition === "first" ? [-2, row3, second] : rowsAxis && pivot.valuesPosition === "between" ? [row3, -2, second] : [...rowIdx, ...rowsAxis ? [-2] : []];
43514
+ const rowIndices = [...rowIdx];
43515
+ if (valuesAt >= 0) rowIndices.splice(valuesAt, 0, -2);
43810
43516
  let previous = [];
43811
43517
  const rowItems = rowEntries?.map((entry3) => {
43812
43518
  let prefix3 = 0;
43813
43519
  const type = entry3.type === void 0 || entry3.type === "default" || entry3.type === "grand" ? entry3.type : PIVOT_SUBTOTALS[entry3.type].item;
43814
- if (rowsAxis) {
43815
- if (entry3.type === "default" && pivot.valuesPosition === "first") prefix3 = 1;
43816
- else if (!entry3.type)
43817
- while (prefix3 < entry3.indices.length - 1 && entry3.indices[prefix3] === previous[prefix3])
43818
- prefix3++;
43819
- previous = entry3.type && !(entry3.type === "default" && pivot.valuesPosition === "first") ? [] : entry3.indices;
43820
- } else {
43821
- if (entry3.type !== "grand") prefix3 = sharedPrefix(entry3.indices, previous);
43822
- previous = entry3.type === "grand" ? [] : entry3.indices;
43823
- }
43520
+ if (entry3.type !== "grand") prefix3 = sharedPrefix(entry3.indices, previous);
43521
+ previous = entry3.type === "grand" ? [] : entry3.indices;
43824
43522
  return `<i${attrs2({ t: type, r: prefix3 || void 0, i: entry3.measure || void 0 })}>${entry3.indices.slice(prefix3).map((index3) => `<x${attrs2({ v: index3 || void 0 })}/>`).join("")}</i>`;
43825
43523
  }).join("") ?? items(grid.rowItems.length, rowIndicesFull[0]);
43826
43524
  let body = `<location${attrs2({ ref: formatRange({ ...pivot.location, start: { ...pivot.location.start, row: pivot.location.start.row + pageOffset } }), firstHeaderRow: header, firstDataRow: grid.firstDataRow - pageOffset, rowPageCount: page >= 0 ? 1 : void 0, colPageCount: page >= 0 ? 1 : void 0, firstDataCol: grid.rowLabelColumns ?? 1 })}/><pivotFields count="${pivot.fields.length}">${fields}</pivotFields><rowFields count="${rowIndices.length}">${rowIndices.map((index3) => `<field x="${index3}"/>`).join("")}</rowFields><rowItems count="${grid.rowEntries?.length ?? grid.rowItems.length + 1}">${rowItems}</rowItems>`;
43827
- if (!rowsAxis && col >= 0 && grid.columnEntries) {
43828
- const fieldsOnColumns = [...columnIdx, ...multiple ? [-2] : []];
43829
- body += `<colFields count="${fieldsOnColumns.length}">${fieldsOnColumns.map((index3) => `<field x="${index3}"/>`).join("")}</colFields>${pivotColumnItemsXml(grid.columnEntries, measures2.length, (level, index3) => columnIndicesFull[level][index3])}`;
43525
+ if (col >= 0 && grid.columnEntries) {
43526
+ const fieldsOnColumns = [...columnIdx, ...multiple && !rowsAxis ? [-2] : []];
43527
+ body += `<colFields count="${fieldsOnColumns.length}">${fieldsOnColumns.map((index3) => `<field x="${index3}"/>`).join("")}</colFields>${pivotColumnItemsXml(grid.columnEntries, rowsAxis ? 1 : measures2.length, (level, index3) => columnIndicesFull[level][index3])}`;
43830
43528
  } else if (multiple && !rowsAxis)
43831
43529
  body += `<colFields count="1"><field x="-2"/></colFields>${pivotValueAxisItems(measures2.length)}`;
43832
- else if (col >= 0)
43833
- body += `<colFields count="1"><field x="${col}"/></colFields><colItems count="${grid.columnItems.length + 1}">${items(grid.columnItems.length, columnIndicesFull[0])}</colItems>`;
43834
- else
43835
- body += rowsAxis ? '<colItems count="1"><i/></colItems>' : page >= 0 ? '<colItems count="1"><i/></colItems>' : '<colItems count="1"><i><x/></i></colItems>';
43530
+ else body += '<colItems count="1"><i/></colItems>';
43836
43531
  if (page >= 0)
43837
43532
  body += `<pageFields count="1"><pageField${attrs2({ fld: page, hier: -1, item: pivot.pageFilter.item !== void 0 ? pageItems.findIndex((item) => pivotValueKey(item) === pivotValueKey(pivot.pageFilter.item)) : void 0 })}/></pageFields>`;
43838
43533
  body += `<dataFields count="${measures2.length}">${measures2.map((measure2) => `<dataField${attrs2({ name: encodeEscapes(measure2.caption), fld: pivot.fields.indexOf(measure2.field), subtotal: measure2.aggregate, baseField: 0, baseItem: 0 })}/>`).join("")}</dataFields>`;
@@ -43843,8 +43538,7 @@ function pivotTableXml(source2, cacheId, cache3) {
43843
43538
  root.setAttribute("name", pivot.name);
43844
43539
  root.setAttribute("cacheId", String(cacheId));
43845
43540
  root.setAttribute("dataOnRows", rowsAxis ? "1" : "0");
43846
- if (rowsAxis && (pivot.valuesPosition === "between" || pivot.valuesPosition === "first"))
43847
- root.setAttribute("dataPosition", pivot.valuesPosition === "first" ? "0" : "1");
43541
+ if (rowsAxis && valuesAt < rowIdx.length) root.setAttribute("dataPosition", String(valuesAt));
43848
43542
  else root.removeAttribute("dataPosition");
43849
43543
  root.setAttribute("compact", compact3 ? "1" : "0");
43850
43544
  root.setAttribute("compactData", compact3 ? "1" : "0");
@@ -43910,7 +43604,8 @@ function pivotTableXml(source2, cacheId, cache3) {
43910
43604
  }
43911
43605
  function dateFilterXml(pivot, filter2) {
43912
43606
  const x15 = "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main";
43913
- return `<filters count="1"><filter${attrs2({ fld: pivot.fields.indexOf(filter2.field), type: "dateBetween", evalOrder: -1, id: 1, name: filter2.field })}><autoFilter ref="A1"><filterColumn colId="0"><customFilters and="1"><customFilter operator="greaterThanOrEqual" val="${Math.floor(filter2.start)}"/><customFilter operator="lessThanOrEqual" val="${Math.floor(filter2.end)}"/></customFilters></filterColumn></autoFilter><extLst><ext uri="{0605FD5F-26C8-4aeb-8148-2DB25E43C511}" xmlns:x15="${x15}"><x15:pivotFilter useWholeDay="1"/></ext></extLst></filter></filters>`;
43607
+ const id3 = Number(/<filter [^>]*\bid="(\d+)"/.exec(pivot.sourceXml ?? "")?.[1] ?? 1);
43608
+ return `<filters count="1"><filter${attrs2({ fld: pivot.fields.indexOf(filter2.field), type: "dateBetween", evalOrder: -1, id: id3, name: filter2.field })}><autoFilter ref="A1"><filterColumn colId="0"><customFilters and="1"><customFilter operator="greaterThanOrEqual" val="${Math.floor(filter2.start)}"/><customFilter operator="lessThanOrEqual" val="${Math.floor(filter2.end)}"/></customFilters></filterColumn></autoFilter><extLst><ext uri="{0605FD5F-26C8-4aeb-8148-2DB25E43C511}" xmlns:x15="${x15}"><x15:pivotFilter useWholeDay="1"/></ext></extLst></filter></filters>`;
43914
43609
  }
43915
43610
 
43916
43611
  // xlsx/pivot/write.ts
@@ -48895,7 +48590,7 @@ function pixelSizeToExtent(width, height) {
48895
48590
  }
48896
48591
 
48897
48592
  // xlsx/pivot/date-axes.ts
48898
- var dateGroupAxisNames = (group) => dateGroupUnits(group).reverse().map((unit3) => dateGroupFieldName(unit3, group.field));
48593
+ var dateGroupAxisNames = (group) => dateGroupUnits(group).reverse().map((unit3) => dateGroupFieldName(unit3, group.field, group));
48899
48594
  function replace(list2, names, replacement) {
48900
48595
  const at2 = list2.findIndex((name3) => names.includes(name3));
48901
48596
  if (at2 < 0) return list2;
@@ -48931,7 +48626,9 @@ function reconcileDateAxes(next, previous) {
48931
48626
  if (columns.length > 1) next.moreColumnFields = columns.slice(1);
48932
48627
  else delete next.moreColumnFields;
48933
48628
  if (next.fieldSubtotals) {
48934
- const kept = next.fieldSubtotals.filter((entry3) => rows.includes(entry3.field));
48629
+ const kept = next.fieldSubtotals.filter(
48630
+ (entry3) => rows.includes(entry3.field) || columns.includes(entry3.field)
48631
+ );
48935
48632
  if (kept.length) next.fieldSubtotals = kept;
48936
48633
  else delete next.fieldSubtotals;
48937
48634
  }
@@ -48983,12 +48680,12 @@ function plan(ctx, s, pivot, old) {
48983
48680
  if (occupied) throw new Error("The PivotTable would overwrite existing cell content.");
48984
48681
  return { grid, location };
48985
48682
  }
48986
- function writePivot(ctx, s, pivot, old, label5, inside2) {
48683
+ function writePivot(ctx, s, pivot, old, label4, inside2) {
48987
48684
  const sheet = sheetAt(ctx.workbook, s);
48988
48685
  const { grid, location } = plan(ctx, s, pivot, old);
48989
48686
  const ranges = [...old ? [old.location] : [], location];
48990
48687
  ctx.run(
48991
- label5 ?? (old ? "Refresh PivotTable" : "Create PivotTable"),
48688
+ label4 ?? (old ? "Refresh PivotTable" : "Create PivotTable"),
48992
48689
  "annotations",
48993
48690
  [
48994
48691
  { kind: "parts", sheet: s, parts: ["pivotTables"] },
@@ -49147,6 +48844,12 @@ function refreshPivotTable(ctx, s, name3, patch2 = {}) {
49147
48844
  else delete next.dateFields;
49148
48845
  roundDateRecords(next, dates, ctx.workbook.date1904);
49149
48846
  if (next.dateFilter && !dates.includes(next.dateFilter.field)) delete next.dateFilter;
48847
+ if (patch2.fieldSubtotals === void 0 && next.fieldSubtotals) {
48848
+ const onAxes = [...pivotRowFields(next), ...pivotColumnFields(next)];
48849
+ const left2 = next.fieldSubtotals.filter((entry3) => onAxes.includes(entry3.field));
48850
+ if (left2.length) next.fieldSubtotals = left2;
48851
+ else delete next.fieldSubtotals;
48852
+ }
49150
48853
  const kept = pruneItemFilters(next);
49151
48854
  if (kept) next.itemFilters = kept;
49152
48855
  else delete next.itemFilters;
@@ -49602,10 +49305,10 @@ function validatePatch(group, patch2) {
49602
49305
  delete next.manualMax;
49603
49306
  validateSettings(next);
49604
49307
  }
49605
- function save2(ctx, s, next, label5, ranges) {
49308
+ function save2(ctx, s, next, label4, ranges) {
49606
49309
  const sheet = sheetAt(ctx.workbook, s);
49607
49310
  ctx.run(
49608
- label5,
49311
+ label4,
49609
49312
  "annotations",
49610
49313
  [{ kind: "parts", sheet: s, parts: ["preserved"] }],
49611
49314
  () => sheet.preserved.set("extLst", next),
@@ -53718,8 +53421,8 @@ function createEditSession(workbook, options = {}) {
53718
53421
  if (!workbook.warnings.includes(message)) workbook.warnings.push(message);
53719
53422
  }
53720
53423
  };
53721
- const begin = (label5, kind, info) => {
53722
- const step2 = { label: label5, entries: [], structural: info.structural ?? false };
53424
+ const begin = (label4, kind, info) => {
53425
+ const step2 = { label: label4, entries: [], structural: info.structural ?? false };
53723
53426
  if (info.calc) step2.calc = info.calc;
53724
53427
  return { step: step2, kind, sheet: info.sheet, ranges: [...info.ranges ?? []] };
53725
53428
  };
@@ -53743,7 +53446,7 @@ function createEditSession(workbook, options = {}) {
53743
53446
  }
53744
53447
  current.step.entries.length = from;
53745
53448
  };
53746
- const run2 = (label5, kind, scopes, fn, info = {}) => {
53449
+ const run2 = (label4, kind, scopes, fn, info = {}) => {
53747
53450
  if (kind === "cells") {
53748
53451
  for (const scope of scopes)
53749
53452
  if (scope.kind === "cells" && workbook.sheets[scope.sheet]?.pivotTables?.some(
@@ -53760,7 +53463,7 @@ function createEditSession(workbook, options = {}) {
53760
53463
  }))
53761
53464
  throw new Error(DATA_TABLE_PART_ERROR);
53762
53465
  const outer = !open;
53763
- const current = open ?? begin(label5, kind, info);
53466
+ const current = open ?? begin(label4, kind, info);
53764
53467
  if (!outer) {
53765
53468
  delete current.step.calc;
53766
53469
  if (info.structural) current.step.structural = true;
@@ -53930,12 +53633,12 @@ function createEditSession(workbook, options = {}) {
53930
53633
  validate: (s, r, c2, value2) => validateCellInput(workbook, s, r, c2, value2, {
53931
53634
  evaluate: (formula, at2) => calc.evaluate(formula, at2)
53932
53635
  }),
53933
- batch(label5, fn) {
53636
+ batch(label4, fn) {
53934
53637
  if (open) {
53935
53638
  fn();
53936
53639
  return;
53937
53640
  }
53938
- const current = begin(label5, "batch", {});
53641
+ const current = begin(label4, "batch", {});
53939
53642
  open = current;
53940
53643
  try {
53941
53644
  fn();
@@ -54615,9 +54318,9 @@ var VisioPackage = class _VisioPackage {
54615
54318
  };
54616
54319
 
54617
54320
  // visio/metadata.ts
54618
- function metadata(value2, max, label5) {
54321
+ function metadata(value2, max, label4) {
54619
54322
  if (value2.length > max)
54620
- throw new VisioPackageError("METADATA_LIMIT", `${label5} exceeds its metadata length limit.`);
54323
+ throw new VisioPackageError("METADATA_LIMIT", `${label4} exceeds its metadata length limit.`);
54621
54324
  return value2;
54622
54325
  }
54623
54326
  function metadataAttributes(node3) {
@@ -61251,7 +60954,7 @@ function property(row3, budget, report) {
61251
60954
  "Shape data has no supported current cached typed value; original cached text is retained."
61252
60955
  );
61253
60956
  }
61254
- const label5 = get("Label"), format5 = get("Format"), prompt = get("Prompt"), sortKey = get("SortKey");
60957
+ const label4 = get("Label"), format5 = get("Format"), prompt = get("Prompt"), sortKey = get("SortKey");
61255
60958
  const invisible = boolean(row3.cells, "Invisible", budget, report);
61256
60959
  const dataLinked = row3.cells.has("DataLinked") ? boolean(row3.cells, "DataLinked", budget, report) : void 0;
61257
60960
  const unit3 = row3.cells.get("Value")?.unit, error = row3.cells.get("Value")?.error;
@@ -61263,7 +60966,7 @@ function property(row3, budget, report) {
61263
60966
  ...rawType === void 0 ? {} : { rawType },
61264
60967
  ...rawValue === void 0 ? {} : { rawValue },
61265
60968
  ...value2 === void 0 ? {} : { value: value2 },
61266
- ...label5 === void 0 ? {} : { label: label5 },
60969
+ ...label4 === void 0 ? {} : { label: label4 },
61267
60970
  ...format5 === void 0 ? {} : { format: format5 },
61268
60971
  ...prompt === void 0 ? {} : { prompt },
61269
60972
  ...sortKey === void 0 ? {} : { sortKey },
@@ -61496,9 +61199,9 @@ async function readDataRecordsets(pkg, documentPart, check3) {
61496
61199
  const declared = children3(children3(set, "DataColumns")[0], "DataColumn");
61497
61200
  const columns = (declared.length ? declared : []).map((node3) => {
61498
61201
  const name4 = attribute3(node3, "ColumnNameID") ?? attribute3(node3, "Name") ?? "";
61499
- const label5 = attribute3(node3, "Label") ?? attribute3(node3, "Name") ?? name4;
61500
- if (!name4 || name4.length > 255 || label5.length > 255) invalid2("Invalid data column.");
61501
- return { name: name4, label: label5, type: typeFromCode(attribute3(node3, "DataType")) };
61202
+ const label4 = attribute3(node3, "Label") ?? attribute3(node3, "Name") ?? name4;
61203
+ if (!name4 || name4.length > 255 || label4.length > 255) invalid2("Invalid data column.");
61204
+ return { name: name4, label: label4, type: typeFromCode(attribute3(node3, "DataType")) };
61502
61205
  });
61503
61206
  if (!columns.length)
61504
61207
  for (const column2 of ado.columns)
@@ -71383,9 +71086,9 @@ function visioBorderShapes(style3, width, height, title = VISIO_DEFAULT_TITLE) {
71383
71086
  // visio/edit-page-setup-commands.ts
71384
71087
  var VISIO_SCALE_UNITS = Object.freeze(["IN", "FT", "MM", "CM", "M"]);
71385
71088
  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";
71386
- var pageId = (value2, label5) => {
71089
+ var pageId = (value2, label4) => {
71387
71090
  if (typeof value2 !== "string" || !value2 || value2.length > 256)
71388
- fail2("INVALID_EDIT", `Invalid ${label5}.`);
71091
+ fail2("INVALID_EDIT", `Invalid ${label4}.`);
71389
71092
  return value2;
71390
71093
  };
71391
71094
  var newPageId = (value2) => {
@@ -71492,11 +71195,11 @@ var VISIO_SHAPE_DATA_TYPES = [
71492
71195
  "date"
71493
71196
  ];
71494
71197
  var invalidText2 = /[\u0000-\u0008\u000b\u000c\u000e-\u001f￾￿]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/u;
71495
- function shapeDataText(value2, label5) {
71198
+ function shapeDataText(value2, label4) {
71496
71199
  if (typeof value2 !== "string" || value2.length > VISIO_METADATA_TEXT_LIMIT)
71497
- fail2("INVALID_EDIT", `${label5} must be a string within the length limit.`);
71200
+ fail2("INVALID_EDIT", `${label4} must be a string within the length limit.`);
71498
71201
  if (invalidText2.test(value2) || /[\r\n\t]/.test(value2))
71499
- fail2("INVALID_EDIT_TEXT", `${label5} contains invalid characters.`);
71202
+ fail2("INVALID_EDIT_TEXT", `${label4} contains invalid characters.`);
71500
71203
  return value2;
71501
71204
  }
71502
71205
  function shapeDataRowName(value2) {
@@ -71504,9 +71207,9 @@ function shapeDataRowName(value2) {
71504
71207
  fail2("INVALID_EDIT", "Shape Data row names use letters, digits and underscores.");
71505
71208
  return value2;
71506
71209
  }
71507
- function visioShapeDataRowName(label5, taken = []) {
71210
+ function visioShapeDataRowName(label4, taken = []) {
71508
71211
  const used = new Set([...taken].map((name4) => name4.toLowerCase()));
71509
- let base2 = label5.normalize("NFKD").replace(/[^\w]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 48);
71212
+ let base2 = label4.normalize("NFKD").replace(/[^\w]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 48);
71510
71213
  if (!base2) base2 = "Property";
71511
71214
  if (/^\d/.test(base2)) base2 = `_${base2}`;
71512
71215
  let name3 = base2;
@@ -71578,15 +71281,15 @@ var TYPES3 = [
71578
71281
  "unlink-data-rows"
71579
71282
  ];
71580
71283
  var isVisioDataEdit = (edit) => TYPES3.includes(edit.type);
71581
- var id = (value2, label5) => {
71284
+ var id = (value2, label4) => {
71582
71285
  if (typeof value2 !== "string" || !/^(0|[1-9]\d{0,9})$/.test(value2) || Number(value2) > 4294967295)
71583
- fail2("INVALID_EDIT", `Invalid ${label5}.`);
71286
+ fail2("INVALID_EDIT", `Invalid ${label4}.`);
71584
71287
  return value2;
71585
71288
  };
71586
- var name = (value2, label5) => {
71587
- const text8 = shapeDataText(value2, label5);
71289
+ var name = (value2, label4) => {
71290
+ const text8 = shapeDataText(value2, label4);
71588
71291
  if (!text8.trim() || text8.length > 255)
71589
- fail2("INVALID_EDIT", `${label5} must be 1 to 255 characters.`);
71292
+ fail2("INVALID_EDIT", `${label4} must be 1 to 255 characters.`);
71590
71293
  return text8;
71591
71294
  };
71592
71295
  function table2(columns, rows) {
@@ -71701,16 +71404,16 @@ function snapshotPageTheme(edit) {
71701
71404
  var isVisioCommentEdit = (edit) => edit.type === "add-comment" || edit.type === "edit-comment" || edit.type === "delete-comment";
71702
71405
  var invalidText3 = /[\u0000-\u0008\u000b\u000c\u000e-\u001f￾￿]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/u;
71703
71406
  var dateTime = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,7})?(?:Z|[+-]\d{2}:\d{2})?$/;
71704
- function string(value2, limit3, label5, required = true) {
71407
+ function string(value2, limit3, label4, required = true) {
71705
71408
  if (typeof value2 !== "string" || value2.length > limit3 || required && !value2.trim())
71706
- fail2("INVALID_EDIT", `${label5} must be a non-empty string within its length limit.`);
71409
+ fail2("INVALID_EDIT", `${label4} must be a non-empty string within its length limit.`);
71707
71410
  if (invalidText3.test(value2))
71708
- fail2("INVALID_EDIT_TEXT", `${label5} contains invalid XML characters.`);
71411
+ fail2("INVALID_EDIT_TEXT", `${label4} contains invalid XML characters.`);
71709
71412
  return value2;
71710
71413
  }
71711
- var id2 = (value2, label5) => {
71414
+ var id2 = (value2, label4) => {
71712
71415
  if (typeof value2 !== "string" || !/^(0|[1-9]\d{0,9})$/.test(value2) || Number(value2) > 4294967295)
71713
- fail2("INVALID_EDIT", `${label5} must be a canonical unsigned integer.`);
71416
+ fail2("INVALID_EDIT", `${label4} must be a canonical unsigned integer.`);
71714
71417
  return value2;
71715
71418
  };
71716
71419
  var date = (value2) => {
@@ -72233,7 +71936,7 @@ async function editVsdxMasterInstance(pkg, parts, pages, edit, limits, maxOutput
72233
71936
 
72234
71937
  // visio/paper-sizes.ts
72235
71938
  var mm = (value2) => value2 / 25.4;
72236
- var size = (id3, label5, width, height, paperKind) => Object.freeze({ id: id3, label: label5, width, height, ...paperKind === void 0 ? {} : { paperKind } });
71939
+ var size = (id3, label4, width, height, paperKind) => Object.freeze({ id: id3, label: label4, width, height, ...paperKind === void 0 ? {} : { paperKind } });
72237
71940
  var VISIO_PAPER_SIZES = Object.freeze([
72238
71941
  size("letter", "Letter", 8.5, 11, 1),
72239
71942
  size("tabloid", "Tabloid", 11, 17, 3),
@@ -73603,7 +73306,7 @@ function snapshotFormatting(edit) {
73603
73306
  if (!Number.isInteger(value2)) fail2("INVALID_EDIT", "Paint patterns require integers.");
73604
73307
  result2[name3] = value2;
73605
73308
  }
73606
- for (const [name3, maximum, label5] of [
73309
+ for (const [name3, maximum, label4] of [
73607
73310
  ["beginArrow", 45, "Arrowheads are numbered 0 to 45."],
73608
73311
  ["endArrow", 45, "Arrowheads are numbered 0 to 45."],
73609
73312
  ["beginArrowSize", 6, "Arrowhead sizes are numbered 0 to 6."],
@@ -73617,7 +73320,7 @@ function snapshotFormatting(edit) {
73617
73320
  const value2 = edit[name3];
73618
73321
  if (value2 === void 0) continue;
73619
73322
  if (typeof value2 !== "number" || !Number.isInteger(value2) || value2 < 0 || value2 > maximum)
73620
- fail2("INVALID_EDIT", label5);
73323
+ fail2("INVALID_EDIT", label4);
73621
73324
  result2[name3] = value2;
73622
73325
  }
73623
73326
  if (edit.rounding !== void 0) result2.rounding = points(edit.rounding, 0, 720);