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
@@ -75,7 +75,7 @@ var DEFAULT_XML_LIMITS = {
75
75
  maxNodes: 5e6
76
76
  };
77
77
  var MARKUP_RE = /<!--[\s\S]*?-->|<!\[CDATA\[[\s\S]*?\]\]>|<\?[\s\S]*?\?>|<(\/?)([^\s\/>]+)(?:\s+[^\s=\/>]+\s*=\s*(?:"[^"]*"|'[^']*'))*\s*(\/?)>/g;
78
- function checkXmlLimits(xml, label5, limits = {}) {
78
+ function checkXmlLimits(xml, label4, limits = {}) {
79
79
  const maxDepth = limits.maxDepth ?? DEFAULT_XML_LIMITS.maxDepth;
80
80
  const maxNodes = limits.maxNodes ?? DEFAULT_XML_LIMITS.maxNodes;
81
81
  let depth = 0;
@@ -88,16 +88,16 @@ function checkXmlLimits(xml, label5, limits = {}) {
88
88
  continue;
89
89
  }
90
90
  nodes++;
91
- if (nodes > maxNodes) throw new Error(`${label5} XML exceeds the limit of ${maxNodes} elements`);
91
+ if (nodes > maxNodes) throw new Error(`${label4} XML exceeds the limit of ${maxNodes} elements`);
92
92
  if (!selfClosing && ++depth > maxDepth)
93
- throw new Error(`${label5} XML exceeds the nesting depth limit of ${maxDepth}`);
93
+ throw new Error(`${label4} XML exceeds the nesting depth limit of ${maxDepth}`);
94
94
  }
95
95
  }
96
96
  function parseXml(xml, options = {}) {
97
- const label5 = options.label ?? "OOXML";
97
+ const label4 = options.label ?? "OOXML";
98
98
  if (/<!DOCTYPE|<!ENTITY/i.test(xml))
99
- throw new Error(`${label5} XML with DTD or entity declarations is not supported`);
100
- checkXmlLimits(xml, label5, options.limits);
99
+ throw new Error(`${label4} XML with DTD or entity declarations is not supported`);
100
+ checkXmlLimits(xml, label4, options.limits);
101
101
  let parseError = "";
102
102
  let parsed;
103
103
  try {
@@ -108,12 +108,12 @@ function parseXml(xml, options = {}) {
108
108
  }).parseFromString(xml, "application/xml");
109
109
  } catch (error) {
110
110
  throw new Error(
111
- `Invalid ${label5} XML: ${error instanceof Error ? error.message : String(error)}`,
111
+ `Invalid ${label4} XML: ${error instanceof Error ? error.message : String(error)}`,
112
112
  { cause: error }
113
113
  );
114
114
  }
115
115
  if (parseError || !parsed.documentElement)
116
- throw new Error(`Invalid ${label5} XML: ${parseError || "missing root element"}`);
116
+ throw new Error(`Invalid ${label4} XML: ${parseError || "missing root element"}`);
117
117
  return parsed;
118
118
  }
119
119
  var buildXml = (node3) => new XMLSerializer().serializeToString(node3);
@@ -400,10 +400,10 @@ function withParseWarnings(warnings, fn) {
400
400
  function reportParseWarning(message) {
401
401
  if (sink && !sink.includes(message)) sink.push(message);
402
402
  }
403
- function enumValue(guard2, raw2, label5) {
403
+ function enumValue(guard2, raw2, label4) {
404
404
  if (raw2 === null || raw2 === void 0 || raw2 === "") return void 0;
405
405
  if (guard2(raw2)) return raw2;
406
- reportParseWarning(`Ignored invalid ${label5} value \u201C${raw2}\u201D; it is not allowed by the schema.`);
406
+ reportParseWarning(`Ignored invalid ${label4} value \u201C${raw2}\u201D; it is not allowed by the schema.`);
407
407
  return void 0;
408
408
  }
409
409
 
@@ -13454,8 +13454,8 @@ function parseDiagramDataModel(source2, part) {
13454
13454
  "CONNECTION_ENDPOINT_MISSING",
13455
13455
  `dgm:cxn ${attribute4} references missing point: ${id3}.`
13456
13456
  );
13457
- const label5 = connectionLabel(connection, transitionText);
13458
- connections2.push(label5 ? { ...connection, label: label5 } : connection);
13457
+ const label4 = connectionLabel(connection, transitionText);
13458
+ connections2.push(label4 ? { ...connection, label: label4 } : connection);
13459
13459
  if ((!connection.type || connection.type === "parOf") && !parentById.has(connection.destId))
13460
13460
  parentById.set(connection.destId, connection.sourceId);
13461
13461
  }
@@ -13494,14 +13494,14 @@ function colorList(container) {
13494
13494
  }
13495
13495
  function parseDiagramColors(source2) {
13496
13496
  const root = rootOf2(source2);
13497
- const labels = children(root, "styleLbl", NS.dgm).map((label5) => ({
13498
- name: stringAttribute(label5, "name") ?? "",
13499
- fill: colorList(first(label5, "fillClrLst", NS.dgm)),
13500
- line: colorList(first(label5, "linClrLst", NS.dgm)),
13501
- effect: colorList(first(label5, "effectClrLst", NS.dgm)),
13502
- textLine: colorList(first(label5, "txLinClrLst", NS.dgm)),
13503
- textFill: colorList(first(label5, "txFillClrLst", NS.dgm)),
13504
- textEffect: colorList(first(label5, "txEffectClrLst", NS.dgm))
13497
+ const labels = children(root, "styleLbl", NS.dgm).map((label4) => ({
13498
+ name: stringAttribute(label4, "name") ?? "",
13499
+ fill: colorList(first(label4, "fillClrLst", NS.dgm)),
13500
+ line: colorList(first(label4, "linClrLst", NS.dgm)),
13501
+ effect: colorList(first(label4, "effectClrLst", NS.dgm)),
13502
+ textLine: colorList(first(label4, "txLinClrLst", NS.dgm)),
13503
+ textFill: colorList(first(label4, "txFillClrLst", NS.dgm)),
13504
+ textEffect: colorList(first(label4, "txEffectClrLst", NS.dgm))
13505
13505
  }));
13506
13506
  return { ...parseDefinitionHeader(root), labels };
13507
13507
  }
@@ -13534,16 +13534,16 @@ function parseStyleReferences(style3) {
13534
13534
  var hasContent = (element2) => Boolean(element2 && (element2.attributes.length > 0 || elements(element2).length > 0));
13535
13535
  function parseDiagramQuickStyle(source2) {
13536
13536
  const root = rootOf2(source2);
13537
- const labels = children(root, "styleLbl", NS.dgm).map((label5) => ({
13538
- name: stringAttribute(label5, "name") ?? "",
13539
- ...parseStyleReferences(first(label5, "style", NS.dgm)),
13540
- hasScene3d: Boolean(first(label5, "scene3d", NS.dgm)),
13541
- hasShape3d: hasContent(first(label5, "sp3d", NS.dgm))
13537
+ const labels = children(root, "styleLbl", NS.dgm).map((label4) => ({
13538
+ name: stringAttribute(label4, "name") ?? "",
13539
+ ...parseStyleReferences(first(label4, "style", NS.dgm)),
13540
+ hasScene3d: Boolean(first(label4, "scene3d", NS.dgm)),
13541
+ hasShape3d: hasContent(first(label4, "sp3d", NS.dgm))
13542
13542
  }));
13543
13543
  return {
13544
13544
  ...parseDefinitionHeader(root),
13545
13545
  labels,
13546
- has3d: labels.some((label5) => label5.hasShape3d)
13546
+ has3d: labels.some((label4) => label4.hasShape3d)
13547
13547
  };
13548
13548
  }
13549
13549
  function parseDiagramLayoutSummary(source2) {
@@ -14713,10 +14713,10 @@ function parseDisplayUnits(context, element2) {
14713
14713
  if (!element2) return void 0;
14714
14714
  reportUnmodelled(context, element2, DISPLAY_UNITS);
14715
14715
  const labelElement = cChild(element2, "dispUnitsLbl");
14716
- let label5;
14716
+ let label4;
14717
14717
  if (labelElement) {
14718
14718
  reportUnmodelled(context, labelElement, DISPLAY_UNITS_LABEL);
14719
- label5 = assignDefined(
14719
+ label4 = assignDefined(
14720
14720
  {},
14721
14721
  {
14722
14722
  layout: manualLayout(labelElement),
@@ -14731,7 +14731,7 @@ function parseDisplayUnits(context, element2) {
14731
14731
  {
14732
14732
  builtInUnit: cVal(element2, "builtInUnit"),
14733
14733
  customUnit: cNumber(context, element2, "custUnit"),
14734
- label: label5,
14734
+ label: label4,
14735
14735
  extLst: extensionList2(element2)
14736
14736
  }
14737
14737
  );
@@ -15585,10 +15585,10 @@ function titleXml(context, title) {
15585
15585
  function labelOptionsXml(context, options) {
15586
15586
  return numberFormatXml(options.numberFormat) + shapePropertiesXml(context, options.spPr) + textBodyXml(context, options.txPr) + valXml("dLblPos", options.position) + valXml("showLegendKey", options.showLegendKey) + valXml("showVal", options.showValue) + valXml("showCatName", options.showCategoryName) + valXml("showSerName", options.showSeriesName) + valXml("showPercent", options.showPercent) + valXml("showBubbleSize", options.showBubbleSize) + (options.separator === void 0 ? "" : textElement("separator", options.separator));
15587
15587
  }
15588
- function labelXml(context, label5) {
15588
+ function labelXml(context, label4) {
15589
15589
  return elementXml(
15590
15590
  "dLbl",
15591
- valXml("idx", label5.index) + valXml("delete", label5.deleted) + layoutXml(context, label5.layout) + chartTextXml(context, label5.tx, false) + labelOptionsXml(context, label5) + raw(context, label5.extLst)
15591
+ valXml("idx", label4.index) + valXml("delete", label4.deleted) + layoutXml(context, label4.layout) + chartTextXml(context, label4.tx, false) + labelOptionsXml(context, label4) + raw(context, label4.extLst)
15592
15592
  );
15593
15593
  }
15594
15594
  function dataLabelsXml(context, labels) {
@@ -15596,7 +15596,7 @@ function dataLabelsXml(context, labels) {
15596
15596
  const leaderLines = labels.leaderLines ? elementXml("leaderLines", shapePropertiesXml(context, labels.leaderLines.spPr)) : "";
15597
15597
  return elementXml(
15598
15598
  "dLbls",
15599
- labels.labels.map((label5) => labelXml(context, label5)).join("") + valXml("delete", labels.deleted) + labelOptionsXml(context, labels) + valXml("showLeaderLines", labels.showLeaderLines) + leaderLines + raw(context, labels.extLst)
15599
+ labels.labels.map((label4) => labelXml(context, label4)).join("") + valXml("delete", labels.deleted) + labelOptionsXml(context, labels) + valXml("showLeaderLines", labels.showLeaderLines) + leaderLines + raw(context, labels.extLst)
15600
15600
  );
15601
15601
  }
15602
15602
 
@@ -15617,12 +15617,12 @@ function dataTableXml(context, table3) {
15617
15617
  }
15618
15618
  function displayUnitsXml(context, units2) {
15619
15619
  if (!units2) return "";
15620
- const label5 = units2.label;
15620
+ const label4 = units2.label;
15621
15621
  return elementXml(
15622
15622
  "dispUnits",
15623
- valXml("custUnit", units2.customUnit) + (units2.customUnit === void 0 ? valXml("builtInUnit", units2.builtInUnit) : "") + (label5 ? elementXml(
15623
+ valXml("custUnit", units2.customUnit) + (units2.customUnit === void 0 ? valXml("builtInUnit", units2.builtInUnit) : "") + (label4 ? elementXml(
15624
15624
  "dispUnitsLbl",
15625
- layoutXml(context, label5.layout) + chartTextXml(context, label5.tx, false) + shapePropertiesXml(context, label5.spPr) + textBodyXml(context, label5.txPr)
15625
+ layoutXml(context, label4.layout) + chartTextXml(context, label4.tx, false) + shapePropertiesXml(context, label4.spPr) + textBodyXml(context, label4.txPr)
15626
15626
  ) : "") + raw(context, units2.extLst)
15627
15627
  );
15628
15628
  }
@@ -15647,11 +15647,11 @@ function axisXml(context, axis) {
15647
15647
  }
15648
15648
 
15649
15649
  // chart/write-analysis.ts
15650
- function trendlineLabelXml(context, label5) {
15651
- if (!label5) return "";
15650
+ function trendlineLabelXml(context, label4) {
15651
+ if (!label4) return "";
15652
15652
  return elementXml(
15653
15653
  "trendlineLbl",
15654
- layoutXml(context, label5.layout) + chartTextXml(context, label5.tx, false) + numberFormatXml(label5.numberFormat) + shapePropertiesXml(context, label5.spPr) + textBodyXml(context, label5.txPr) + raw(context, label5.extLst)
15654
+ layoutXml(context, label4.layout) + chartTextXml(context, label4.tx, false) + numberFormatXml(label4.numberFormat) + shapePropertiesXml(context, label4.spPr) + textBodyXml(context, label4.txPr) + raw(context, label4.extLst)
15655
15655
  );
15656
15656
  }
15657
15657
  function trendlineXml(context, trendline) {
@@ -20854,19 +20854,19 @@ var nextSheetId = (workbook) => workbook.sheets.reduce((max, sheet) => Math.max(
20854
20854
  var MAX_ROW = 1048575;
20855
20855
  var MAX_COL = 16383;
20856
20856
  function columnLabel(col) {
20857
- let label5 = "";
20857
+ let label4 = "";
20858
20858
  let n = col + 1;
20859
20859
  while (n > 0) {
20860
20860
  const rem = (n - 1) % 26;
20861
- label5 = String.fromCharCode(65 + rem) + label5;
20861
+ label4 = String.fromCharCode(65 + rem) + label4;
20862
20862
  n = Math.floor((n - 1) / 26);
20863
20863
  }
20864
- return label5;
20864
+ return label4;
20865
20865
  }
20866
- function columnIndex(label5) {
20867
- if (!/^[A-Za-z]{1,3}$/.test(label5)) return -1;
20866
+ function columnIndex(label4) {
20867
+ if (!/^[A-Za-z]{1,3}$/.test(label4)) return -1;
20868
20868
  let n = 0;
20869
- for (const ch of label5.toUpperCase()) n = n * 26 + (ch.charCodeAt(0) - 64);
20869
+ for (const ch of label4.toUpperCase()) n = n * 26 + (ch.charCodeAt(0) - 64);
20870
20870
  return n - 1;
20871
20871
  }
20872
20872
  var formatAddress = (address2) => `${columnLabel(address2.col)}${address2.row + 1}`;
@@ -23225,6 +23225,13 @@ var pivotRowFields = (pivot) => [
23225
23225
  ...pivot.secondRowField ? [pivot.secondRowField] : [],
23226
23226
  ...pivot.secondRowField ? pivot.moreRowFields ?? [] : []
23227
23227
  ];
23228
+ function pivotValuesIndex(pivot) {
23229
+ if (pivot.valuesAxis !== "rows") return -1;
23230
+ const count2 = pivotRowFields(pivot).length;
23231
+ const at2 = pivot.valuesPosition;
23232
+ if (typeof at2 === "number") return Math.min(Math.max(Math.trunc(at2), 0), count2);
23233
+ return at2 === "first" ? 0 : at2 === "between" ? Math.min(1, count2) : count2;
23234
+ }
23228
23235
  var pivotColumnFields = (pivot) => [
23229
23236
  ...pivot.columnField ? [pivot.columnField] : [],
23230
23237
  ...pivot.columnField ? pivot.moreColumnFields ?? [] : []
@@ -23326,7 +23333,7 @@ var LEAP_MONTHS = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
23326
23333
  var MAX_ITEMS = 1e4;
23327
23334
  var pad3 = (value2, width = 2) => String(value2).padStart(width, "0");
23328
23335
  var dateGroupUnits = (group) => PIVOT_DATE_UNITS.filter((unit3) => group.by.includes(unit3));
23329
- var dateGroupFieldName = (unit3, field2) => `${UNIT_TITLES[unit3]} (${field2})`;
23336
+ var dateGroupFieldName = (unit3, field2, group) => group?.localized?.[unit3]?.name ?? `${UNIT_TITLES[unit3]} (${field2})`;
23330
23337
  var dateGroupDays = (group) => group.by.length === 1 && group.by[0] === "days" ? group.days ?? 1 : 1;
23331
23338
  function dateGroupRange(group, serials) {
23332
23339
  let min = Infinity;
@@ -23349,7 +23356,7 @@ var secondsOfDay = (serial) => Math.round((serial - Math.floor(serial)) * 86400)
23349
23356
  function dayBuckets(range2, days) {
23350
23357
  return Math.max(1, Math.ceil((Math.floor(range2.end) - Math.floor(range2.start) + 1) / days));
23351
23358
  }
23352
- function dateUnitLabels(unit3, range2, days, date1904) {
23359
+ function englishDateUnitLabels(unit3, range2, days, date1904) {
23353
23360
  const labels = [`<${isoDay(range2.start, date1904)}`];
23354
23361
  if (unit3 === "seconds" || unit3 === "minutes")
23355
23362
  for (let i2 = 0; i2 < 60; i2++) labels.push(`:${pad3(i2)}`);
@@ -23378,6 +23385,11 @@ function dateUnitLabels(unit3, range2, days, date1904) {
23378
23385
  labels.push(`>${isoDay(range2.end, date1904)}`);
23379
23386
  return labels;
23380
23387
  }
23388
+ function dateUnitLabels(unit3, range2, days, date1904, group) {
23389
+ const english = englishDateUnitLabels(unit3, range2, days, date1904);
23390
+ const localized = group?.localized?.[unit3]?.labels;
23391
+ return localized?.length === english.length ? localized : english;
23392
+ }
23381
23393
  function dateUnitIndex(unit3, range2, days, date1904, serial, count2) {
23382
23394
  if (serial < range2.start) return 0;
23383
23395
  if (serial > range2.end) return count2 - 1;
@@ -23401,7 +23413,7 @@ function derivedDateFields(pivot) {
23401
23413
  for (const group of pivot.dateGroups ?? [])
23402
23414
  for (const unit3 of dateGroupUnits(group))
23403
23415
  derived.push({
23404
- name: dateGroupFieldName(unit3, group.field),
23416
+ name: dateGroupFieldName(unit3, group.field, group),
23405
23417
  unit: unit3,
23406
23418
  group,
23407
23419
  index: databaseFields + derived.length
@@ -23412,7 +23424,7 @@ function countDerived(pivot) {
23412
23424
  let count2 = 0;
23413
23425
  for (const group of pivot.dateGroups ?? [])
23414
23426
  for (const unit3 of dateGroupUnits(group))
23415
- if (pivot.fields.includes(dateGroupFieldName(unit3, group.field))) count2++;
23427
+ if (pivot.fields.includes(dateGroupFieldName(unit3, group.field, group))) count2++;
23416
23428
  return count2;
23417
23429
  }
23418
23430
  var pivotAxisFieldNames = (pivot) => [
@@ -23432,7 +23444,7 @@ function derivedDateLabels(pivot, name3) {
23432
23444
  if (!entry3) return void 0;
23433
23445
  const [group] = resolveDateGroups({ ...pivot, dateGroups: [entry3.group] });
23434
23446
  const range2 = { start: group.start, end: group.end };
23435
- return dateUnitLabels(entry3.unit, range2, dateGroupDays(group), pivot.date1904 ?? false);
23447
+ return dateUnitLabels(entry3.unit, range2, dateGroupDays(group), pivot.date1904 ?? false, group);
23436
23448
  }
23437
23449
  function validateDateGroups(pivot) {
23438
23450
  const groups = pivot.dateGroups;
@@ -23448,18 +23460,16 @@ function validateDateGroups(pivot) {
23448
23460
  seen.add(group.field);
23449
23461
  if (!(pivot.dateFields ?? []).includes(group.field))
23450
23462
  throw new Error("Only fields that contain dates can be grouped by date.");
23451
- if (pivot.pageFilter || pivot.dateFilter)
23452
- throw new Error("Date groups cannot be combined with report filters or timelines.");
23453
23463
  const serials = pivot.records.map((record2) => record2[index3]);
23454
23464
  if (!serials.length || serials.some((v) => typeof v !== "number" || !Number.isFinite(v)))
23455
23465
  throw new Error("Only fields that contain dates can be grouped by date.");
23456
23466
  const range2 = dateGroupRange(group, serials);
23457
23467
  if (range2.start >= range2.end) throw new Error("The date group must end after it starts.");
23458
23468
  for (const unit3 of dateGroupUnits(group)) {
23459
- const name3 = dateGroupFieldName(unit3, group.field);
23469
+ const name3 = dateGroupFieldName(unit3, group.field, group);
23460
23470
  if (pivot.fields.includes(name3))
23461
23471
  throw new Error("A source field already has the name of a date group field.");
23462
- if (dateUnitLabels(unit3, range2, dateGroupDays(group), pivot.date1904 ?? false).length > MAX_ITEMS)
23472
+ if (dateUnitLabels(unit3, range2, dateGroupDays(group), pivot.date1904 ?? false, group).length > MAX_ITEMS)
23463
23473
  throw new Error("The date group has too many items.");
23464
23474
  }
23465
23475
  }
@@ -23473,7 +23483,7 @@ function expandDateGroups(pivot) {
23473
23483
  const tables = derived.map((entry3) => {
23474
23484
  const range2 = { start: entry3.group.start, end: entry3.group.end };
23475
23485
  const days = dateGroupDays(entry3.group);
23476
- const labels = dateUnitLabels(entry3.unit, range2, days, date1904);
23486
+ const labels = dateUnitLabels(entry3.unit, range2, days, date1904, entry3.group);
23477
23487
  return {
23478
23488
  base: pivot.fields.indexOf(entry3.group.field),
23479
23489
  labels,
@@ -23606,15 +23616,13 @@ function normalizedFieldSubtotals(entries) {
23606
23616
  };
23607
23617
  });
23608
23618
  }
23609
- function validateFieldSubtotals(pivot, rowFields) {
23619
+ function validateFieldSubtotals(pivot, axisFields) {
23610
23620
  const entries = pivot.fieldSubtotals;
23611
23621
  if (entries === void 0) return;
23612
23622
  if (!Array.isArray(entries)) throw new Error("Choose valid field subtotals.");
23613
- if (entries.length && pivot.valuesAxis === "rows")
23614
- throw new Error("Field subtotals require Values on columns.");
23615
23623
  const seen = /* @__PURE__ */ new Set();
23616
23624
  for (const entry3 of entries) {
23617
- 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)
23625
+ 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)
23618
23626
  throw new Error("Choose valid field subtotals.");
23619
23627
  seen.add(entry3.field);
23620
23628
  }
@@ -23710,17 +23718,18 @@ function validatePivotPageFilter(pivot) {
23710
23718
  throw new Error("Choose a cached literal report filter item.");
23711
23719
  }
23712
23720
  function pivotPageProjection(pivot) {
23713
- return applyPivotGroups(applyPivotItemFilters(pagedProjection(pivot)));
23721
+ const groups = pivot.dateGroups?.length ? { ...pivot, dateGroups: resolveDateGroups(pivot) } : pivot;
23722
+ return applyPivotGroups(applyPivotItemFilters(pagedProjection(groups)));
23714
23723
  }
23715
23724
  function pagedProjection(pivot) {
23716
23725
  const filter2 = pivot.pageFilter;
23717
23726
  if (!filter2) return pivot;
23718
23727
  const labels = /* @__PURE__ */ new Map();
23719
23728
  for (const item of pivotItems(pivot, filter2.field)) {
23720
- const label5 = String(pivotItemLabel(item)).toLowerCase(), key3 = pivotValueKey(item);
23721
- if (label5 === "(all)" || labels.has(label5) && labels.get(label5) !== key3)
23729
+ const label4 = String(pivotItemLabel(item)).toLowerCase(), key3 = pivotValueKey(item);
23730
+ if (label4 === "(all)" || labels.has(label4) && labels.get(label4) !== key3)
23722
23731
  throw new Error("Ambiguous report filter item captions are preserved.");
23723
- labels.set(label5, key3);
23732
+ labels.set(label4, key3);
23724
23733
  }
23725
23734
  if (filter2.item === void 0) return pivot;
23726
23735
  const index3 = pivot.fields.indexOf(filter2.field), key2 = pivotValueKey(filter2.item);
@@ -23859,13 +23868,9 @@ function validatePivotFields(pivot) {
23859
23868
  const columns = pivotColumnFields(pivot);
23860
23869
  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")))
23861
23870
  throw new Error("Choose valid PivotTable column fields.");
23862
- if (pivot.valuesAxis === "rows" && rows.length > 2)
23863
- throw new Error("Values on rows support at most two row fields.");
23864
- if (pivot.valuesAxis === "rows" && columns.length > 1)
23865
- throw new Error("Values on rows support one column field.");
23866
23871
  if (pivot.pageFilter && columns.length > 1)
23867
23872
  throw new Error("Report filters support one column field.");
23868
- validateFieldSubtotals(pivot, rows);
23873
+ validateFieldSubtotals(pivot, [...rows, ...columns]);
23869
23874
  const axisNames = pivotAxisFieldNames(pivot);
23870
23875
  if ((pivot.dateGroups ?? []).some(
23871
23876
  (group) => [...rows, ...columns].some((name3) => name3 === group.field)
@@ -23874,9 +23879,10 @@ function validatePivotFields(pivot) {
23874
23879
  const extras = pivot.additionalValues ?? [];
23875
23880
  if (pivot.valuesAxis !== void 0 && !["columns", "rows"].includes(pivot.valuesAxis))
23876
23881
  throw new Error("Choose a valid Values axis.");
23877
- if (pivot.valuesPosition !== void 0 && !["last", "between", "first"].includes(pivot.valuesPosition))
23882
+ const position2 = pivot.valuesPosition;
23883
+ if (position2 !== void 0 && !["last", "between", "first"].includes(position2) && !(typeof position2 === "number" && Number.isInteger(position2) && position2 >= 0))
23878
23884
  throw new Error("Choose a valid Values position.");
23879
- if ((pivot.valuesPosition === "between" || pivot.valuesPosition === "first") && (pivot.valuesAxis !== "rows" || !pivot.secondRowField))
23885
+ if (position2 !== void 0 && position2 !== "last" && (pivot.valuesAxis !== "rows" || position2 === "between" && !pivot.secondRowField || typeof position2 === "number" && position2 > rows.length))
23880
23886
  throw new Error("Values before or between fields require two row fields and Values on rows.");
23881
23887
  if (pivot.valuesAxis === "rows" && (!Array.isArray(extras) || !extras.length))
23882
23888
  throw new Error("Values on rows require multiple measures.");
@@ -23897,6 +23903,45 @@ function pivotCaption(aggregate2, field2) {
23897
23903
  return `${aggregate2[0].toUpperCase()}${aggregate2.slice(1)} of ${field2}`;
23898
23904
  }
23899
23905
 
23906
+ // xlsx/write/xml-out.ts
23907
+ var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
23908
+ var CONTROL2 = "\0-\b\v\f-" + String.fromCharCode(65534, 65535);
23909
+ var NEEDS_ESCAPE = new RegExp(`[${CONTROL2}\r]|_x[0-9A-Fa-f]{4}_`);
23910
+ var ESCAPABLE = new RegExp(`[${CONTROL2}\r]|_(?=x[0-9A-Fa-f]{4}_)`, "g");
23911
+ function encodeEscapes(text8) {
23912
+ if (!NEEDS_ESCAPE.test(text8)) return text8;
23913
+ return text8.replace(
23914
+ ESCAPABLE,
23915
+ (ch) => `_x${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}_`
23916
+ );
23917
+ }
23918
+ var INVALID_XML2 = new RegExp(`[${CONTROL2}]`, "g");
23919
+ var escapeText3 = (text8) => text8.replace(INVALID_XML2, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
23920
+ 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;");
23921
+ function attrs2(values2) {
23922
+ let out = "";
23923
+ for (const [name3, value2] of Object.entries(values2)) {
23924
+ if (value2 === void 0) continue;
23925
+ const text8 = typeof value2 === "boolean" ? value2 ? "1" : "0" : typeof value2 === "number" ? num(value2) : value2;
23926
+ out += ` ${name3}="${escapeAttr3(text8)}"`;
23927
+ }
23928
+ return out;
23929
+ }
23930
+ var el4 = (name3, values2 = {}, content2 = "") => content2 ? `<${name3}${attrs2(values2)}>${content2}</${name3}>` : `<${name3}${attrs2(values2)}/>`;
23931
+ var num = (value2) => Object.is(value2, -0) ? "0" : String(value2);
23932
+ function tElement(text8, name3 = "t") {
23933
+ const encoded = escapeText3(encodeEscapes(text8));
23934
+ const preserve = /^\s|\s$|\n|\t/.test(text8) ? ' xml:space="preserve"' : "";
23935
+ return `<${name3}${preserve}>${encoded}</${name3}>`;
23936
+ }
23937
+ var MAIN_NS = ' xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"';
23938
+ function inlineFragment(xml) {
23939
+ const end = xml.indexOf(">");
23940
+ if (end < 0) return xml;
23941
+ const head = xml.slice(0, end);
23942
+ return head.includes(MAIN_NS) ? head.replace(MAIN_NS, "") + xml.slice(end) : xml;
23943
+ }
23944
+
23900
23945
  // xlsx/pivot/measures.ts
23901
23946
  var pivotMeasures = (pivot) => [
23902
23947
  { field: pivot.valueField, aggregate: pivot.aggregate, caption: pivot.valueCaption },
@@ -23946,329 +23991,17 @@ function aggregateValues(records, field2, type) {
23946
23991
  return type === "average" ? sum3 / numbers3.length : sum3;
23947
23992
  }
23948
23993
  var pivotMeasureNumber = (pivot, records, measure2) => aggregateValues(records, pivot.fields.indexOf(measure2.field), measure2.aggregate);
23949
- var pivotNumbers = (pivot, records) => pivotMeasures(pivot).map((measure2) => pivotMeasureNumber(pivot, records, measure2));
23950
- function pivotHeaderDimensions(pivot, columnItems, rowLabels) {
23951
- return {
23952
- rows: (pivot.columnField ? 2 : 1) + (pivot.pageFilter ? 2 : 0),
23953
- width: rowLabels + (pivot.columnField ? columnItems + 1 : 1)
23954
- };
23955
- }
23956
- function pivotHeaders(pivot, columns, labels, label5) {
23957
- const rowLabels = pivot.layout === "compact" ? ["Row Labels"] : pivot.valuesPosition === "first" ? ["Values", ...labels] : pivot.valuesPosition === "between" ? [labels[0], "Values", labels[1]] : [...labels, "Values"];
23958
- return pivot.columnField ? [
23959
- [
23960
- ...rowLabels.map(() => null),
23961
- pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
23962
- ...columns.map(() => null)
23963
- ],
23964
- [...rowLabels, ...columns.map(label5), "Grand Total"]
23965
- ] : [[...rowLabels, null]];
23966
- }
23967
-
23968
- // xlsx/pivot/hierarchy-first.ts
23969
- function appendFirstPivotValues(pivot, context) {
23970
- const {
23971
- rowItems,
23972
- secondRowItems,
23973
- columnItems,
23974
- children: children4,
23975
- innerIndices,
23976
- groups,
23977
- details,
23978
- buckets,
23979
- width,
23980
- rowLabels,
23981
- top,
23982
- bottom,
23983
- append
23984
- } = context;
23985
- const compact3 = pivot.layout === "compact";
23986
- const tabular = !pivot.layout || pivot.layout === "tabular";
23987
- const blank = () => Array(width - rowLabels).fill(null);
23988
- pivotMeasures(pivot).forEach((measure2, m) => {
23989
- const numbers3 = (keys, records) => [
23990
- ...columnItems.map(
23991
- (column2) => pivotMeasureNumber(
23992
- pivot,
23993
- buckets.get(JSON.stringify([...keys, pivotValueKey(column2)])) ?? [],
23994
- measure2
23995
- )
23996
- ),
23997
- pivotMeasureNumber(pivot, records, measure2)
23998
- ];
23999
- if (!tabular)
24000
- append([measure2.caption, ...Array(rowLabels - 1).fill(null)], blank(), {
24001
- indices: [m],
24002
- measure: m
24003
- });
24004
- let first3 = true;
24005
- rowItems.forEach((outer, outerIndex) => {
24006
- const key2 = pivotValueKey(outer);
24007
- const group = groups.get(key2) ?? [];
24008
- if (!tabular)
24009
- append(
24010
- compact3 ? [pivotItemLabel(outer)] : [null, pivotItemLabel(outer), null],
24011
- top ? numbers3([key2], group) : blank(),
24012
- { indices: [m, outerIndex], measure: m },
24013
- compact3 ? 1 : 0
24014
- );
24015
- const innerKeys = [...children4.get(key2)].sort(
24016
- (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
24017
- );
24018
- innerKeys.forEach((innerKey, child7) => {
24019
- const innerIndex = innerIndices.get(innerKey);
24020
- append(
24021
- compact3 ? [pivotItemLabel(secondRowItems[innerIndex])] : [
24022
- tabular && first3 ? measure2.caption : null,
24023
- pivot.repeatLabels || tabular && child7 === 0 ? pivotItemLabel(outer) : null,
24024
- pivotItemLabel(secondRowItems[innerIndex])
24025
- ],
24026
- numbers3([key2, innerKey], details.get(JSON.stringify([key2, innerKey]))),
24027
- { indices: [m, outerIndex, innerIndex], measure: m },
24028
- compact3 ? 2 : 0
24029
- );
24030
- first3 = false;
24031
- });
24032
- if (bottom)
24033
- append(
24034
- compact3 ? [`${String(pivotItemLabel(outer))} Total`] : [null, `${String(pivotItemLabel(outer))} Total`, null],
24035
- numbers3([key2], group),
24036
- { indices: [m, outerIndex], measure: m, type: "default" },
24037
- compact3 ? 1 : 0
24038
- );
24039
- });
24040
- });
24041
- }
24042
-
24043
- // xlsx/pivot/hierarchy.ts
24044
- var label = pivotItemLabel;
24045
- function hierarchicalPivotGrid(pivot) {
24046
- const rowItems = pivotItems(pivot, pivot.rowField);
24047
- const secondRowItems = pivotItems(pivot, pivot.secondRowField);
24048
- const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
24049
- const outerField = pivot.fields.indexOf(pivot.rowField);
24050
- const innerField = pivot.fields.indexOf(pivot.secondRowField);
24051
- const columnField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
24052
- const layout3 = pivot.layout ?? "tabular";
24053
- const compact3 = layout3 === "compact";
24054
- const firstValues = pivot.valuesPosition === "first";
24055
- const between = pivot.valuesPosition === "between";
24056
- const measures2 = pivotMeasures(pivot);
24057
- const top = firstValues && layout3 !== "tabular" && pivot.subtotals !== false && (pivot.subtotalPosition ?? "top") === "top";
24058
- const bottom = pivot.subtotals !== false && !top;
24059
- const rowLabelColumns = compact3 ? 1 : 3;
24060
- const groups = /* @__PURE__ */ new Map();
24061
- const details = /* @__PURE__ */ new Map();
24062
- const children4 = /* @__PURE__ */ new Map();
24063
- const innerIndices = new Map(secondRowItems.map((item, index3) => [pivotValueKey(item), index3]));
24064
- const buckets = /* @__PURE__ */ new Map();
24065
- const collect = (map, key2, record2) => {
24066
- const list2 = map.get(key2);
24067
- if (list2) list2.push(record2);
24068
- else map.set(key2, [record2]);
24069
- };
24070
- for (const record2 of pivot.records) {
24071
- const outer = pivotValueKey(record2[outerField] ?? null);
24072
- const inner2 = pivotValueKey(record2[innerField] ?? null);
24073
- collect(groups, outer, record2);
24074
- collect(details, JSON.stringify([outer, inner2]), record2);
24075
- if (!children4.has(outer)) children4.set(outer, /* @__PURE__ */ new Set());
24076
- children4.get(outer).add(inner2);
24077
- if (pivot.columnField) {
24078
- const column2 = pivotValueKey(record2[columnField] ?? null);
24079
- for (const key2 of [[], [outer], [outer, inner2]])
24080
- collect(buckets, JSON.stringify([...key2, column2]), record2);
24081
- }
24082
- }
24083
- const dimensions3 = pivotHeaderDimensions(pivot, columnItems.length, rowLabelColumns);
24084
- 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;
24085
- if (rows * dimensions3.width > 1e6) throw new Error("The PivotTable result is too large.");
24086
- const labels = compact3 ? ["Row Labels"] : [pivot.rowField, pivot.secondRowField];
24087
- const values2 = pivotHeaders(pivot, columnItems, labels, label);
24088
- const firstDataRow = values2.length;
24089
- const indents = values2.map(() => 0);
24090
- const rowEntries = [];
24091
- const append = (labels2, numbers4, entry3, indent = 0) => {
24092
- values2.push([...labels2, ...numbers4]);
24093
- rowEntries.push(entry3);
24094
- indents.push(indent);
24095
- };
24096
- const bands = (keys, records) => [
24097
- ...columnItems.map(
24098
- (column2) => pivotNumbers(pivot, buckets.get(JSON.stringify([...keys, pivotValueKey(column2)])) ?? [])
24099
- ),
24100
- pivotNumbers(pivot, records)
24101
- ];
24102
- const numbers3 = (keys, records) => bands(keys, records).flat();
24103
- const appendMeasures = (labels2, keys, records, indices, type) => {
24104
- const values3 = bands(keys, records);
24105
- measures2.forEach(
24106
- (measure2, m) => append(
24107
- type ? [
24108
- `${type === "grand" ? "Total" : String(labels2[0])} ${measure2.caption}`,
24109
- ...Array(rowLabelColumns - 1).fill(null)
24110
- ] : compact3 ? [measure2.caption] : [
24111
- ...labels2.map(
24112
- (label5) => layout3 === "tabular" && m === 0 || pivot.repeatLabels ? label5 : null
24113
- ),
24114
- measure2.caption
24115
- ],
24116
- values3.map((band2) => band2[m] ?? null),
24117
- { indices: type ? indices : [...indices, m], measure: m, ...type ? { type } : {} },
24118
- compact3 && !type ? 2 : 0
24119
- )
24120
- );
24121
- };
24122
- if (firstValues)
24123
- appendFirstPivotValues(pivot, {
24124
- rowItems,
24125
- secondRowItems,
24126
- columnItems,
24127
- children: children4,
24128
- innerIndices,
24129
- groups,
24130
- details,
24131
- buckets,
24132
- width: dimensions3.width,
24133
- rowLabels: rowLabelColumns,
24134
- top,
24135
- bottom,
24136
- append
24137
- });
24138
- else
24139
- rowItems.forEach((outer, outerIndex) => {
24140
- const key2 = pivotValueKey(outer);
24141
- if (layout3 !== "tabular")
24142
- append(
24143
- [label(outer), ...Array(rowLabelColumns - 1).fill(null)],
24144
- top ? numbers3([key2], groups.get(key2) ?? []) : Array(dimensions3.width - rowLabelColumns).fill(null),
24145
- { indices: [outerIndex] }
24146
- );
24147
- let first3 = true;
24148
- const innerKeys = [...children4.get(key2)].sort(
24149
- (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
24150
- );
24151
- if (between)
24152
- measures2.forEach((measure2, m) => {
24153
- if (layout3 !== "tabular")
24154
- append(
24155
- compact3 ? [measure2.caption] : [pivot.repeatLabels ? label(outer) : null, measure2.caption, null],
24156
- Array(dimensions3.width - rowLabelColumns).fill(null),
24157
- { indices: [outerIndex, m], measure: m },
24158
- compact3 ? 1 : 0
24159
- );
24160
- innerKeys.forEach((innerKey, child7) => {
24161
- const innerIndex = innerIndices.get(innerKey);
24162
- const keys = [key2, innerKey];
24163
- const records = details.get(JSON.stringify(keys));
24164
- append(
24165
- compact3 ? [label(secondRowItems[innerIndex])] : [
24166
- pivot.repeatLabels || layout3 === "tabular" && m === 0 && child7 === 0 ? label(outer) : null,
24167
- layout3 === "tabular" && child7 === 0 ? measure2.caption : null,
24168
- label(secondRowItems[innerIndex])
24169
- ],
24170
- [
24171
- ...columnItems.map(
24172
- (column2) => pivotMeasureNumber(
24173
- pivot,
24174
- buckets.get(JSON.stringify([...keys, pivotValueKey(column2)])) ?? [],
24175
- measure2
24176
- )
24177
- ),
24178
- pivotMeasureNumber(pivot, records, measure2)
24179
- ],
24180
- { indices: [outerIndex, m, innerIndex], measure: m },
24181
- compact3 ? 2 : 0
24182
- );
24183
- });
24184
- });
24185
- else
24186
- innerKeys.forEach((innerKey) => {
24187
- const innerIndex = innerIndices.get(innerKey);
24188
- const inner2 = secondRowItems[innerIndex];
24189
- const keys = [key2, innerKey];
24190
- const records = details.get(JSON.stringify(keys));
24191
- if (!records) return;
24192
- if (layout3 !== "tabular")
24193
- append(
24194
- compact3 ? [label(inner2)] : [pivot.repeatLabels ? label(outer) : null, label(inner2), null],
24195
- Array(dimensions3.width - rowLabelColumns).fill(null),
24196
- { indices: [outerIndex, innerIndex] },
24197
- compact3 ? 1 : 0
24198
- );
24199
- appendMeasures(
24200
- [pivot.repeatLabels || first3 ? label(outer) : null, label(inner2)],
24201
- keys,
24202
- records,
24203
- [outerIndex, innerIndex]
24204
- );
24205
- first3 = false;
24206
- });
24207
- if (bottom)
24208
- appendMeasures([label(outer)], [key2], groups.get(key2) ?? [], [outerIndex], "default");
24209
- });
24210
- appendMeasures([], [], pivot.records, [0], "grand");
24211
- return {
24212
- values: values2,
24213
- rowItems,
24214
- secondRowItems,
24215
- columnItems,
24216
- rowEntries,
24217
- firstDataRow,
24218
- rowLabelColumns,
24219
- indents,
24220
- firstHeaderRow: 1
24221
- };
24222
- }
24223
-
24224
- // xlsx/write/xml-out.ts
24225
- var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
24226
- var CONTROL2 = "\0-\b\v\f-" + String.fromCharCode(65534, 65535);
24227
- var NEEDS_ESCAPE = new RegExp(`[${CONTROL2}\r]|_x[0-9A-Fa-f]{4}_`);
24228
- var ESCAPABLE = new RegExp(`[${CONTROL2}\r]|_(?=x[0-9A-Fa-f]{4}_)`, "g");
24229
- function encodeEscapes(text8) {
24230
- if (!NEEDS_ESCAPE.test(text8)) return text8;
24231
- return text8.replace(
24232
- ESCAPABLE,
24233
- (ch) => `_x${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}_`
24234
- );
24235
- }
24236
- var INVALID_XML2 = new RegExp(`[${CONTROL2}]`, "g");
24237
- var escapeText3 = (text8) => text8.replace(INVALID_XML2, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
24238
- 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;");
24239
- function attrs2(values2) {
24240
- let out = "";
24241
- for (const [name3, value2] of Object.entries(values2)) {
24242
- if (value2 === void 0) continue;
24243
- const text8 = typeof value2 === "boolean" ? value2 ? "1" : "0" : typeof value2 === "number" ? num(value2) : value2;
24244
- out += ` ${name3}="${escapeAttr3(text8)}"`;
24245
- }
24246
- return out;
24247
- }
24248
- var el4 = (name3, values2 = {}, content2 = "") => content2 ? `<${name3}${attrs2(values2)}>${content2}</${name3}>` : `<${name3}${attrs2(values2)}/>`;
24249
- var num = (value2) => Object.is(value2, -0) ? "0" : String(value2);
24250
- function tElement(text8, name3 = "t") {
24251
- const encoded = escapeText3(encodeEscapes(text8));
24252
- const preserve = /^\s|\s$|\n|\t/.test(text8) ? ' xml:space="preserve"' : "";
24253
- return `<${name3}${preserve}>${encoded}</${name3}>`;
24254
- }
24255
- var MAIN_NS = ' xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"';
24256
- function inlineFragment(xml) {
24257
- const end = xml.indexOf(">");
24258
- if (end < 0) return xml;
24259
- const head = xml.slice(0, end);
24260
- return head.includes(MAIN_NS) ? head.replace(MAIN_NS, "") + xml.slice(end) : xml;
24261
- }
24262
23994
 
24263
23995
  // xlsx/pivot/columns.ts
24264
23996
  var SEPARATOR = "";
24265
- var label2 = pivotItemLabel;
23997
+ var label = pivotItemLabel;
24266
23998
  var columnKey = (keys, depth) => keys.slice(0, depth).join(SEPARATOR);
24267
23999
  var recordColumnKeys = (record2, indices) => indices.map((index3) => pivotValueKey(record2[index3] ?? null));
24268
24000
  function pivotColumnEntries(pivot) {
24269
24001
  const names = pivotColumnFields(pivot);
24270
24002
  const items = names.map((name3) => pivotItems(pivot, name3));
24271
24003
  const entries = [];
24004
+ const functions = names.map((name3) => fieldSubtotalFunctions(pivot, name3));
24272
24005
  if (names.length) {
24273
24006
  const order = items.map(
24274
24007
  (list2) => new Map(list2.map((item, index3) => [pivotValueKey(item), index3]))
@@ -24303,7 +24036,9 @@ function pivotColumnEntries(pivot) {
24303
24036
  if (level === names.length - 1) entries.push({ kind: "leaf", ...entry3 });
24304
24037
  else {
24305
24038
  visit2(child7[1], level + 1, here.path, here.values, here.keys);
24306
- entries.push({ kind: "subtotal", ...entry3 });
24039
+ const own2 = functions[level];
24040
+ if (own2 === "auto") entries.push({ kind: "subtotal", ...entry3 });
24041
+ else for (const fn of own2) entries.push({ kind: "subtotal", ...entry3, fn });
24307
24042
  }
24308
24043
  }
24309
24044
  };
@@ -24312,25 +24047,28 @@ function pivotColumnEntries(pivot) {
24312
24047
  entries.push({ kind: "grand", path: [], key: "", values: [] });
24313
24048
  return { names, items, entries };
24314
24049
  }
24315
- function pivotColumnDimensions(pivot, columns, labelColumns) {
24316
- const measures2 = 1 + (pivot.additionalValues?.length ?? 0);
24050
+ function pivotColumnDimensions(pivot, columns, labelColumns, valuesOnRows = false) {
24051
+ const measures2 = valuesOnRows ? 1 : 1 + (pivot.additionalValues?.length ?? 0);
24317
24052
  const levels = columns.names.length;
24318
24053
  return {
24319
24054
  rows: (levels ? levels + 1 + Number(measures2 > 1) : 1) + (pivot.pageFilter ? 2 : 0),
24320
24055
  width: labelColumns + (levels ? columns.entries.length : 1) * measures2
24321
24056
  };
24322
24057
  }
24323
- function pivotColumnHeaders(pivot, columns, rowLabels) {
24324
- const measures2 = pivotMeasures(pivot);
24058
+ function pivotColumnHeaders(pivot, columns, rowLabels, valuesOnRows = false) {
24059
+ const measures2 = valuesOnRows ? pivotMeasures(pivot).slice(0, 1) : pivotMeasures(pivot);
24325
24060
  const count2 = measures2.length;
24326
24061
  const levels = columns.names.length;
24327
- if (!levels) return [[...rowLabels, ...measures2.map((measure2) => measure2.caption)]];
24062
+ if (!levels)
24063
+ return [
24064
+ [...rowLabels, ...valuesOnRows ? [null] : measures2.map((measure2) => measure2.caption)]
24065
+ ];
24328
24066
  const compact3 = pivot.layout === "compact";
24329
24067
  const labelColumns = rowLabels.length;
24330
24068
  const width = labelColumns + columns.entries.length * count2;
24331
24069
  const rows = levels + 1 + Number(count2 > 1);
24332
24070
  const grid = Array.from({ length: rows }, () => Array(width).fill(null));
24333
- if (count2 === 1) grid[0][0] = pivot.valueCaption;
24071
+ if (count2 === 1 && !valuesOnRows) grid[0][0] = pivot.valueCaption;
24334
24072
  const titles = compact3 ? ["Column Labels"] : [...columns.names, ...count2 > 1 ? ["Values"] : []];
24335
24073
  titles.forEach((title, i2) => {
24336
24074
  grid[0][labelColumns + i2] = title;
@@ -24344,16 +24082,17 @@ function pivotColumnHeaders(pivot, columns, rowLabels) {
24344
24082
  if (entry3.kind === "leaf") {
24345
24083
  entry3.path.forEach((_index, level) => {
24346
24084
  const continued = entry3.path.slice(0, level + 1).every((p, i2) => p === previous[i2]);
24347
- if (!continued) grid[1 + level][at2] = label2(entry3.values[level]);
24085
+ if (!continued) grid[1 + level][at2] = label(entry3.values[level]);
24348
24086
  });
24349
24087
  previous = entry3.path;
24350
24088
  if (count2 > 1) measures2.forEach((measure2, m) => grid[rows - 1][at2 + m] = measure2.caption);
24351
24089
  return;
24352
24090
  }
24353
24091
  const row3 = entry3.kind === "grand" ? 1 : entry3.path.length;
24354
- const name3 = entry3.kind === "grand" ? "" : String(label2(entry3.values.at(-1)));
24092
+ const name3 = entry3.kind === "grand" ? "" : String(label(entry3.values.at(-1)));
24355
24093
  measures2.forEach((measure2, m) => {
24356
- grid[row3][at2 + m] = count2 === 1 ? entry3.kind === "grand" ? "Grand Total" : `${name3} Total` : entry3.kind === "grand" ? `Total ${measure2.caption}` : `${name3} ${measure2.caption}`;
24094
+ const custom = entry3.fn ? PIVOT_SUBTOTALS[entry3.fn].label : void 0;
24095
+ grid[row3][at2 + m] = custom ? count2 === 1 ? `${name3} ${custom}` : `${name3} ${custom} of ${measure2.field}` : count2 === 1 ? entry3.kind === "grand" ? "Grand Total" : `${name3} Total` : entry3.kind === "grand" ? `Total ${measure2.caption}` : `${name3} ${measure2.caption}`;
24357
24096
  });
24358
24097
  });
24359
24098
  return grid;
@@ -24378,7 +24117,7 @@ function pivotColumnItemsXml(entries, measures2, remap) {
24378
24117
  const prefix3 = sharedPrefix(path2, previous);
24379
24118
  const xs = path2.slice(prefix3).map((index3) => `<x${attrs2({ v: index3 || void 0 })}/>`);
24380
24119
  out.push(
24381
- `<i${attrs2({ t: entry3.kind === "subtotal" ? "default" : void 0, r: prefix3 || void 0, i: m || void 0 })}>${xs.join("")}</i>`
24120
+ `<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>`
24382
24121
  );
24383
24122
  previous = path2;
24384
24123
  }
@@ -24386,7 +24125,7 @@ function pivotColumnItemsXml(entries, measures2, remap) {
24386
24125
  }
24387
24126
 
24388
24127
  // xlsx/pivot/nested.ts
24389
- var label3 = pivotItemLabel;
24128
+ var label2 = pivotItemLabel;
24390
24129
  var MAX_CELLS = 1e6;
24391
24130
  var node = (index3, value2) => ({
24392
24131
  index: index3,
@@ -24398,6 +24137,10 @@ var node = (index3, value2) => ({
24398
24137
  function nestedPivotGrid(pivot) {
24399
24138
  const names = pivotRowFields(pivot);
24400
24139
  const depth = names.length;
24140
+ const valuesAt = pivotValuesIndex(pivot);
24141
+ const onRows = valuesAt >= 0;
24142
+ const levels = depth + (onRows ? 1 : 0);
24143
+ const fieldOf = (level) => !onRows || level < valuesAt ? level : level === valuesAt ? -1 : level - 1;
24401
24144
  const axisItems = names.map((name3) => pivotItems(pivot, name3));
24402
24145
  const itemIndices = axisItems.map(
24403
24146
  (items) => new Map(items.map((item, index3) => [pivotValueKey(item), index3]))
@@ -24409,125 +24152,168 @@ function nestedPivotGrid(pivot) {
24409
24152
  const compact3 = layout3 === "compact";
24410
24153
  const tabular = layout3 === "tabular";
24411
24154
  const above = !tabular && (pivot.subtotalPosition ?? "top") === "top";
24412
- const labelColumns = compact3 ? 1 : depth;
24155
+ const labelColumns = compact3 ? 1 : levels;
24413
24156
  const measures2 = pivotMeasures(pivot);
24157
+ const functions = names.map((name3) => fieldSubtotalFunctions(pivot, name3));
24414
24158
  const root = node(0, null);
24415
24159
  for (const record2 of pivot.records) {
24416
24160
  const keys = recordColumnKeys(record2, columnFields);
24417
24161
  let current = root;
24418
- for (let level = -1; level < depth; level++) {
24419
- if (level >= 0) {
24420
- const value2 = record2[fieldIndices[level]] ?? null;
24162
+ for (let field2 = -1; field2 < depth; field2++) {
24163
+ if (field2 >= 0) {
24164
+ const value2 = record2[fieldIndices[field2]] ?? null;
24421
24165
  const key2 = pivotValueKey(value2);
24422
24166
  let child7 = current.children.get(key2);
24423
24167
  if (!child7) {
24424
- child7 = node(itemIndices[level].get(key2), value2);
24168
+ child7 = node(itemIndices[field2].get(key2), value2);
24425
24169
  current.children.set(key2, child7);
24426
24170
  }
24427
24171
  current = child7;
24428
24172
  }
24429
24173
  current.records.push(record2);
24430
- for (let width = 1; width <= keys.length; width++) {
24431
- const key2 = columnKey(keys, width);
24174
+ for (let width2 = 1; width2 <= keys.length; width2++) {
24175
+ const key2 = columnKey(keys, width2);
24432
24176
  const list2 = current.columns.get(key2);
24433
24177
  if (list2) list2.push(record2);
24434
24178
  else current.columns.set(key2, [record2]);
24435
24179
  }
24436
24180
  }
24437
24181
  }
24438
- const dimensions3 = pivotColumnDimensions(pivot, columns, labelColumns);
24439
- const functions = names.map((name3) => fieldSubtotalFunctions(pivot, name3));
24440
- let rows = 1;
24441
- const count2 = (parent, level) => {
24442
- for (const child7 of parent.children.values()) {
24443
- rows++;
24444
- if (level < depth - 1) {
24445
- const f6 = functions[level];
24446
- rows += f6 === "auto" ? 1 : f6.length;
24447
- count2(child7, level + 1);
24448
- }
24449
- }
24450
- };
24451
- count2(root, 0);
24452
- if ((rows + dimensions3.rows) * dimensions3.width > MAX_CELLS)
24453
- throw new Error("The PivotTable result is too large.");
24454
- const values2 = pivotColumnHeaders(pivot, columns, compact3 ? ["Row Labels"] : names);
24455
- const firstDataRow = values2.length;
24456
- const indents = values2.map(() => 0);
24182
+ const dimensions3 = pivotColumnDimensions(pivot, columns, labelColumns, onRows);
24183
+ const rowTitles = names.map((name3) => name3);
24184
+ if (onRows) rowTitles.splice(valuesAt, 0, "Values");
24185
+ let values2 = [];
24186
+ let indents = [];
24457
24187
  const rowEntries = [];
24458
- const blanks = () => Array(dimensions3.width - labelColumns).fill(null);
24459
- const bands = (group, run2) => columns.entries.flatMap(
24460
- (entry3) => run2(entry3.kind === "grand" ? group.records : group.columns.get(entry3.key) ?? [])
24461
- );
24462
- const numbers3 = (group) => bands(group, (records) => pivotNumbers(pivot, records));
24463
- const subtotalNumbers = (group, fn) => bands(
24464
- group,
24465
- (records) => measures2.map((measure2) => aggregateValues(records, pivot.fields.indexOf(measure2.field), fn))
24466
- );
24467
- const labelCells = (path2, shown, text8) => {
24188
+ let counting = true;
24189
+ let rowCount = 0;
24190
+ const width = dimensions3.width - labelColumns;
24191
+ const blanks = () => Array(width).fill(null);
24192
+ const cells3 = (group, rowFn, measure2) => columns.entries.flatMap((entry3) => {
24193
+ const records = entry3.kind === "grand" ? group.records : group.columns.get(entry3.key) ?? [];
24194
+ const picked = measure2 === void 0 ? measures2 : [measures2[measure2]];
24195
+ if (rowFn && entry3.fn && rowFn !== entry3.fn) return picked.map(() => null);
24196
+ const fn = rowFn ?? entry3.fn;
24197
+ return picked.map(
24198
+ (one2) => fn ? aggregateValues(records, pivot.fields.indexOf(one2.field), fn) : pivotMeasureNumber(pivot, records, one2)
24199
+ );
24200
+ });
24201
+ const labelCells = (path2, shown, level, text8) => {
24468
24202
  if (compact3) return [text8];
24469
- const cells3 = Array(depth).fill(null);
24470
- path2.forEach((value2, level) => {
24471
- if (shown[level]) cells3[level] = label3(value2);
24203
+ const row3 = Array(levels).fill(null);
24204
+ path2.labels.forEach((value2, at2) => {
24205
+ if (shown[at2]) row3[at2] = value2;
24472
24206
  });
24473
- cells3[path2.length] = text8;
24474
- return cells3;
24207
+ row3[level] = text8;
24208
+ return row3;
24475
24209
  };
24476
- const push3 = (cells3, numbersOnRow, entry3, indent) => {
24477
- values2.push([...cells3, ...numbersOnRow]);
24210
+ const push3 = (indent, build3) => {
24211
+ if (counting) {
24212
+ if ((++rowCount + dimensions3.rows) * dimensions3.width > MAX_CELLS)
24213
+ throw new Error("The PivotTable result is too large.");
24214
+ return;
24215
+ }
24216
+ const [cells4, numbers3, entry3] = build3();
24217
+ values2.push([...cells4, ...numbers3]);
24478
24218
  rowEntries.push(entry3);
24479
24219
  indents.push(compact3 ? indent : 0);
24480
24220
  };
24481
- const emit = (parent, level, path2, indices, firsts) => {
24482
- const last = level === depth - 1;
24483
- const own2 = functions[level];
24484
- const children4 = [...parent.children.values()].sort((a2, b) => a2.index - b.index);
24221
+ const entryOf = (indices, measure2, type) => ({
24222
+ indices,
24223
+ ...measure2 !== void 0 ? { measure: measure2 } : {},
24224
+ ...type ? { type } : {}
24225
+ });
24226
+ const walk2 = (level, group, measure2, path2) => {
24227
+ const field2 = fieldOf(level);
24228
+ const last = level === levels - 1;
24229
+ const repeated = Array.from(
24230
+ { length: level },
24231
+ (_v, k) => !!pivot.repeatLabels && fieldOf(k) >= 0
24232
+ );
24233
+ const leafShown = (firsts) => repeated.map((repeat, k) => repeat || tabular && firsts.slice(k + 1).every(Boolean));
24234
+ if (field2 < 0) {
24235
+ measures2.forEach((one2, m) => {
24236
+ const here = {
24237
+ labels: [...path2.labels, one2.caption],
24238
+ indices: [...path2.indices, m],
24239
+ firsts: [...path2.firsts, m === 0]
24240
+ };
24241
+ if (last)
24242
+ return push3(level, () => [
24243
+ labelCells(path2, leafShown(here.firsts), level, one2.caption),
24244
+ cells3(group, void 0, m),
24245
+ entryOf(here.indices, m)
24246
+ ]);
24247
+ if (!tabular)
24248
+ push3(level, () => [
24249
+ labelCells(path2, repeated, level, one2.caption),
24250
+ blanks(),
24251
+ entryOf(here.indices, m)
24252
+ ]);
24253
+ walk2(level + 1, group, m, here);
24254
+ });
24255
+ return;
24256
+ }
24257
+ const own2 = functions[field2];
24258
+ const valuesAbove = !onRows || valuesAt < level;
24259
+ const showsValue = above && own2 === "auto" && valuesAbove;
24260
+ const children4 = [...group.children.values()].sort((a2, b) => a2.index - b.index);
24485
24261
  children4.forEach((child7, position2) => {
24486
- const here = [...path2, child7.value];
24487
- const at2 = [...indices, child7.index];
24488
- const firstHere = [...firsts, position2 === 0];
24489
- const repeated = Array(level).fill(!!pivot.repeatLabels);
24490
- if (last) {
24491
- const shown = repeated.map(
24492
- (repeat, k) => repeat || tabular && firstHere.slice(k + 1).every(Boolean)
24493
- );
24494
- push3(labelCells(path2, shown, label3(child7.value)), numbers3(child7), { indices: at2 }, level);
24495
- return;
24496
- }
24262
+ const here = {
24263
+ labels: [...path2.labels, label2(child7.value)],
24264
+ indices: [...path2.indices, child7.index],
24265
+ firsts: [...path2.firsts, position2 === 0]
24266
+ };
24267
+ const text8 = label2(child7.value);
24268
+ if (last)
24269
+ return push3(level, () => [
24270
+ labelCells(path2, leafShown(here.firsts), level, text8),
24271
+ cells3(child7, void 0, measure2),
24272
+ entryOf(here.indices, measure2)
24273
+ ]);
24497
24274
  if (!tabular)
24498
- push3(
24499
- labelCells(path2, repeated, label3(child7.value)),
24500
- own2 === "auto" && above ? numbers3(child7) : blanks(),
24501
- { indices: at2 },
24502
- level
24503
- );
24504
- emit(child7, level + 1, here, at2, firstHere);
24505
- const caption = String(label3(child7.value));
24275
+ push3(level, () => [
24276
+ labelCells(path2, repeated, level, text8),
24277
+ showsValue ? cells3(child7, void 0, measure2) : blanks(),
24278
+ entryOf(here.indices, measure2)
24279
+ ]);
24280
+ walk2(level + 1, child7, measure2, here);
24281
+ if (field2 === depth - 1) return;
24282
+ const caption = String(text8);
24283
+ const subtotal = (title, fn, one2) => push3(level, () => [
24284
+ labelCells(path2, repeated, level, title),
24285
+ cells3(child7, fn, one2),
24286
+ entryOf(here.indices, one2, fn ?? "default")
24287
+ ]);
24506
24288
  if (own2 === "auto") {
24507
- if (!above)
24508
- push3(
24509
- labelCells(path2, repeated, `${caption} Total`),
24510
- numbers3(child7),
24511
- { indices: at2, type: "default" },
24512
- level
24513
- );
24289
+ if (showsValue) return;
24290
+ if (valuesAbove) subtotal(`${caption} Total`, void 0, measure2);
24291
+ else measures2.forEach((one2, m) => subtotal(`${caption} ${one2.caption}`, void 0, m));
24514
24292
  } else
24515
24293
  for (const fn of own2)
24516
- push3(
24517
- labelCells(path2, repeated, `${caption} ${PIVOT_SUBTOTALS[fn].label}`),
24518
- subtotalNumbers(child7, fn),
24519
- { indices: at2, type: fn },
24520
- level
24521
- );
24294
+ if (valuesAbove) subtotal(`${caption} ${PIVOT_SUBTOTALS[fn].label}`, fn, measure2);
24295
+ else
24296
+ measures2.forEach(
24297
+ (one2, m) => subtotal(`${caption} ${PIVOT_SUBTOTALS[fn].label} of ${one2.field}`, fn, m)
24298
+ );
24522
24299
  });
24523
24300
  };
24524
- emit(root, 0, [], [], []);
24525
- push3(
24526
- compact3 ? ["Grand Total"] : ["Grand Total", ...Array(depth - 1).fill(null)],
24527
- numbers3(root),
24528
- { indices: [0], type: "grand" },
24529
- 0
24530
- );
24301
+ const grand = (text8, measure2) => push3(0, () => [
24302
+ compact3 ? [text8] : [text8, ...Array(levels - 1).fill(null)],
24303
+ cells3(root, void 0, measure2),
24304
+ entryOf([0], measure2, "grand")
24305
+ ]);
24306
+ const build2 = () => {
24307
+ walk2(0, root, void 0, { labels: [], indices: [], firsts: [] });
24308
+ if (onRows) measures2.forEach((one2, m) => grand(`Total ${one2.caption}`, m));
24309
+ else grand("Grand Total");
24310
+ };
24311
+ build2();
24312
+ counting = false;
24313
+ values2 = pivotColumnHeaders(pivot, columns, compact3 ? ["Row Labels"] : rowTitles, onRows);
24314
+ const firstDataRow = values2.length;
24315
+ indents = values2.map(() => 0);
24316
+ build2();
24531
24317
  return {
24532
24318
  values: values2,
24533
24319
  rowItems: axisItems[0],
@@ -24539,105 +24325,15 @@ function nestedPivotGrid(pivot) {
24539
24325
  rowEntries,
24540
24326
  firstDataRow,
24541
24327
  rowLabelColumns: labelColumns,
24542
- indents
24328
+ indents,
24329
+ ...onRows ? { firstHeaderRow: 1 } : {}
24543
24330
  };
24544
24331
  }
24545
24332
 
24546
24333
  // xlsx/pivot/aggregate.ts
24547
24334
  function pivotGrid(pivot) {
24548
24335
  validatePivotFields(pivot);
24549
- return prependPivotPage(pivotDataGrid(pivotPageProjection(pivot)), pivot);
24550
- }
24551
- function pivotDataGrid(pivot) {
24552
- if (pivot.valuesAxis !== "rows") return nestedPivotGrid(pivot);
24553
- if (pivot.secondRowField) return hierarchicalPivotGrid(pivot);
24554
- const rowItems = pivotItems(pivot, pivot.rowField);
24555
- const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
24556
- const compact3 = pivot.layout === "compact";
24557
- const headings = pivot.layout !== void 0 && pivot.layout !== "tabular";
24558
- const dimensions3 = pivotHeaderDimensions(pivot, columnItems.length, compact3 ? 1 : 2);
24559
- const dataRows = (rowItems.length + 1) * (1 + (pivot.additionalValues?.length ?? 0)) + (headings ? rowItems.length : 0);
24560
- if ((dataRows + dimensions3.rows) * dimensions3.width > 1e6)
24561
- throw new Error("The PivotTable result is too large.");
24562
- const label5 = pivotItemLabel;
24563
- const values2 = pivotHeaders(pivot, columnItems, [compact3 ? "Row Labels" : pivot.rowField], label5);
24564
- const rowField = pivot.fields.indexOf(pivot.rowField);
24565
- const colField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
24566
- const groups = /* @__PURE__ */ new Map();
24567
- const cells3 = /* @__PURE__ */ new Map();
24568
- const columns = /* @__PURE__ */ new Map();
24569
- const collect = (map, key2, record2) => {
24570
- const found = map.get(key2);
24571
- if (found) found.push(record2);
24572
- else map.set(key2, [record2]);
24573
- };
24574
- for (const record2 of pivot.records) {
24575
- const key2 = pivotValueKey(record2[rowField] ?? null);
24576
- collect(groups, key2, record2);
24577
- if (pivot.columnField) {
24578
- const col = pivotValueKey(record2[colField] ?? null);
24579
- collect(columns, col, record2);
24580
- collect(cells3, JSON.stringify([key2, col]), record2);
24581
- }
24582
- }
24583
- const firstDataRow = values2.length;
24584
- const measures2 = pivotMeasures(pivot);
24585
- const rowEntries = [];
24586
- const indents = values2.map(() => 0);
24587
- const append = (caption, bands, index3, grand = false) => {
24588
- measures2.forEach((measure2, m) => {
24589
- values2.push([
24590
- ...compact3 ? [grand ? `Total ${measure2.caption}` : measure2.caption] : [
24591
- grand ? `Total ${measure2.caption}` : pivot.repeatLabels || !headings && m === 0 ? caption : null,
24592
- grand ? null : measure2.caption
24593
- ],
24594
- ...bands.map((band2) => band2[m] ?? null)
24595
- ]);
24596
- indents.push(compact3 && !grand ? 1 : 0);
24597
- rowEntries.push({
24598
- indices: grand ? [0] : [index3, m],
24599
- measure: m,
24600
- ...grand ? { type: "grand" } : {}
24601
- });
24602
- });
24603
- };
24604
- rowItems.forEach((item, index3) => {
24605
- const key2 = pivotValueKey(item);
24606
- if (headings) {
24607
- values2.push([label5(item), ...Array(dimensions3.width - 1).fill(null)]);
24608
- rowEntries.push({ indices: [index3] });
24609
- indents.push(0);
24610
- }
24611
- append(
24612
- label5(item),
24613
- [
24614
- ...columnItems.map(
24615
- (col) => pivotNumbers(pivot, cells3.get(JSON.stringify([key2, pivotValueKey(col)])) ?? [])
24616
- ),
24617
- pivotNumbers(pivot, groups.get(key2) ?? [])
24618
- ],
24619
- index3
24620
- );
24621
- });
24622
- append(
24623
- "Grand Total",
24624
- [
24625
- ...columnItems.map((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
24626
- pivotNumbers(pivot, pivot.records)
24627
- ],
24628
- 0,
24629
- true
24630
- );
24631
- return {
24632
- values: values2,
24633
- rowItems,
24634
- columnItems,
24635
- firstDataRow,
24636
- rowLabelColumns: compact3 ? 1 : 2,
24637
- indents,
24638
- firstHeaderRow: 1,
24639
- rowEntries
24640
- };
24336
+ return prependPivotPage(nestedPivotGrid(pivotPageProjection(pivot)), pivot);
24641
24337
  }
24642
24338
  function pivotTableAt(sheet, at2) {
24643
24339
  return sheet.pivotTables?.find((pivot) => rangeContains(pivot.location, at2));
@@ -25262,7 +24958,7 @@ function readFieldGroups(fields, names) {
25262
24958
  throw new Error("Unsupported pivot field group");
25263
24959
  const labels = children(list2, "s", NS.x).map((node3) => decodeEscapes(att(node3, "v") ?? ""));
25264
24960
  const expected = numberGroupLabels({ start, end, by });
25265
- if (elements(list2).length !== labels.length || labels.length !== expected.length || labels.some((label5, i2) => label5 !== expected[i2]))
24961
+ if (elements(list2).length !== labels.length || labels.length !== expected.length || labels.some((label4, i2) => label4 !== expected[i2]))
25266
24962
  throw new Error("Unsupported pivot group items");
25267
24963
  groups.push({ field: names[index3] ?? "", start, end, by });
25268
24964
  });
@@ -25340,14 +25036,18 @@ function readDateGroups(fields, count2, names, dateFields, records, date1904) {
25340
25036
  const expected = dateGroupRange(group, serials);
25341
25037
  if (!close(expected.start, start) || !close(expected.end, end))
25342
25038
  throw unsupported("stale range");
25039
+ const localized = {};
25343
25040
  for (const entry3 of list2) {
25344
- const labels = dateUnitLabels(entry3.unit, expected, dateGroupDays(group), date1904);
25041
+ const labels = englishDateUnitLabels(entry3.unit, expected, dateGroupDays(group), date1904);
25345
25042
  const node3 = first(first(entry3.node, "fieldGroup", NS.x), "groupItems", NS.x);
25346
25043
  const actual = children(node3, "s", NS.x).map((item) => decodeEscapes(att(item, "v") ?? ""));
25347
- 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]))
25044
+ const name3 = decodeEscapes(att(entry3.node, "name") ?? "");
25045
+ if (!name3 || elements(node3).length !== actual.length || actual.length !== labels.length || actual.some((label4) => !label4) || new Set(actual).size !== actual.length)
25348
25046
  throw unsupported("group items");
25047
+ if (name3 !== dateGroupFieldName(entry3.unit, field2) || actual.some((l, i2) => l !== labels[i2]))
25048
+ localized[entry3.unit] = { name: name3, labels: actual };
25349
25049
  }
25350
- groups.push(group);
25050
+ groups.push(Object.keys(localized).length ? { ...group, localized } : group);
25351
25051
  }
25352
25052
  return groups;
25353
25053
  }
@@ -25406,6 +25106,7 @@ function remapPivotRowEntries(entries, axes2) {
25406
25106
  (entry3) => entry3.type === "grand" ? entry3 : {
25407
25107
  ...entry3,
25408
25108
  indices: entry3.indices.map((item, axis) => {
25109
+ if (axes2[axis] === null) return item;
25409
25110
  const index3 = axes2[axis]?.[item];
25410
25111
  if (index3 === void 0) throw new Error("Invalid report row axis item");
25411
25112
  return index3;
@@ -25424,7 +25125,7 @@ function pivotValueIndex(root, axis) {
25424
25125
  const position2 = root.getAttribute("dataPosition");
25425
25126
  if (position2 !== null && (!/^\d+$/.test(position2.trim()) || Number(position2) !== index3))
25426
25127
  throw new Error("Inconsistent Values axis position");
25427
- if (axis.length === 3 && index3 >= 0 && index3 < 2 && position2 === null)
25128
+ if (index3 >= 0 && index3 < axis.length - 1 && position2 === null)
25428
25129
  throw new Error("Missing leading or between-field Values position");
25429
25130
  return index3;
25430
25131
  }
@@ -25439,7 +25140,7 @@ function pivotValueAxisItems(measures2) {
25439
25140
  function supportedPivotAxes(rows, columns, measures2, valuesOnRows) {
25440
25141
  const index3 = pivotFieldIndex;
25441
25142
  if (valuesOnRows)
25442
- 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);
25143
+ 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);
25443
25144
  if (rows.some((field2) => !Number.isInteger(index3(field2)) || index3(field2) < 0)) return false;
25444
25145
  if (measures2 > 1 && (!columns.length || index3(columns.at(-1)) !== -2)) return false;
25445
25146
  return (measures2 > 1 ? columns.slice(0, -1) : columns).every(
@@ -25460,6 +25161,9 @@ function assertPageAxisItems(root, pivot, shared, cache3, recordRoot) {
25460
25161
  literals(cache3);
25461
25162
  literals(recordRoot);
25462
25163
  const cacheFields = children(first(cache3, "cacheFields", NS.x), "cacheField", NS.x);
25164
+ const all2 = expandDateGroups(pivot).fields;
25165
+ const derived = all2.slice(pivot.fields.length).map((name3) => groupLabelsOf(pivot, name3) ?? []);
25166
+ const sharedAll = [...shared, ...derived];
25463
25167
  if (pivot.columnField) {
25464
25168
  const column2 = children(first(root, "pivotFields", NS.x), "pivotField", NS.x)[pivot.fields.indexOf(pivot.columnField)];
25465
25169
  const list2 = first(column2, "extLst", NS.x);
@@ -25478,13 +25182,13 @@ function assertPageAxisItems(root, pivot, shared, cache3, recordRoot) {
25478
25182
  ))
25479
25183
  throw new Error("Repeated report column labels are preserved");
25480
25184
  }
25481
- 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)
25185
+ 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)
25482
25186
  throw new Error("Inconsistent report cache counts");
25483
25187
  for (const name3 of [...pivotRowFields(pivot), pivot.columnField, pivot.pageFilter.field].filter(
25484
25188
  Boolean
25485
25189
  )) {
25486
- const field2 = pivot.fields.indexOf(name3);
25487
- if (integer3(first(cacheFields[field2], "sharedItems", NS.x)?.getAttribute("count") ?? null) !== shared[field2].length)
25190
+ const field2 = all2.indexOf(name3);
25191
+ if (field2 < pivot.fields.length && integer3(first(cacheFields[field2], "sharedItems", NS.x)?.getAttribute("count") ?? null) !== shared[field2].length)
25488
25192
  throw new Error("Inconsistent report shared-item counts");
25489
25193
  }
25490
25194
  for (const name3 of ["rowFields", "colFields"]) {
@@ -25494,7 +25198,7 @@ function assertPageAxisItems(root, pivot, shared, cache3, recordRoot) {
25494
25198
  }
25495
25199
  const projected = pivotPageProjection(pivot), fields = children(first(root, "pivotFields", NS.x), "pivotField", NS.x);
25496
25200
  const axisValues = (name3, axis) => {
25497
- 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;
25201
+ const f6 = all2.indexOf(name3), node3 = fields[f6], list2 = first(node3, "items", NS.x), items = children(list2, "item", NS.x), count2 = sharedAll[f6].length;
25498
25202
  if (node3.getAttribute("axis") !== axis) throw new Error("Inconsistent report axis field");
25499
25203
  const defaults = node3.getAttribute("defaultSubtotal") !== "0";
25500
25204
  if (!list2 || integer3(list2.getAttribute("count")) !== items.length || items.length !== count2 + Number(defaults))
@@ -25503,7 +25207,7 @@ function assertPageAxisItems(root, pivot, shared, cache3, recordRoot) {
25503
25207
  const i2 = integer3(item.getAttribute("x"));
25504
25208
  if (item.hasAttribute("t") || !Number.isInteger(i2) || i2 >= count2)
25505
25209
  throw new Error("Invalid page-axis cache item");
25506
- return shared[f6][i2];
25210
+ return sharedAll[f6][i2];
25507
25211
  });
25508
25212
  if (new Set(data.map(pivotValueKey)).size !== count2 || defaults && (items.at(-1)?.getAttribute("t") !== "default" || items.at(-1)?.hasAttribute("x")))
25509
25213
  throw new Error("Invalid page-axis default item");
@@ -25639,7 +25343,7 @@ function readOne(workbook, source2, part) {
25639
25343
  "dataField",
25640
25344
  NS.x
25641
25345
  );
25642
- 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")
25346
+ if (rowFields.length < 1 || dataFields.length < 1 || dataFields.length > 16 || !supportedPivotAxes(rowFields, colFields, dataFields.length, rowsAxis) || root.getAttribute("rowGrandTotals") === "0" || root.getAttribute("colGrandTotals") === "0")
25643
25347
  throw new Error("Unsupported pivot layout");
25644
25348
  const valueIndex = pivotValueIndex(root, rowsAxis ? rowFields : colFields);
25645
25349
  const measure2 = dataFields[0];
@@ -25709,8 +25413,8 @@ function readOne(workbook, source2, part) {
25709
25413
  const col = columnNames[0];
25710
25414
  const moreColumns = columnNames.slice(1);
25711
25415
  const columnDefinitions = columnDefs.map((field2) => tableFields[Number(att(field2, "x"))]);
25712
- if (fieldSubtotalsOf(columnDefinitions.slice(0, -1), columnNames.slice(0, -1)).length || columnNames.some((name3) => !name3))
25713
- throw new Error("Column subtotal settings are preserved");
25416
+ if (columnNames.some((name3) => !name3)) throw new Error("Invalid pivot column fields");
25417
+ const columnSubtotals = fieldSubtotalsOf(columnDefinitions, columnNames);
25714
25418
  const data = names[Number(att(measure2, "fld"))];
25715
25419
  const location = parseRange(att(first(root, "location", NS.x), "ref") ?? "");
25716
25420
  if (!row3 || !data || !location || hasColumn && !col || realRows.length === 2 && !second)
@@ -25751,8 +25455,10 @@ function readOne(workbook, source2, part) {
25751
25455
  ]);
25752
25456
  if (dateFields.some((field2) => onAxis.has(field2)))
25753
25457
  throw new Error("Date fields used as rows, columns or values are preserved");
25754
- if ([...realRows, ...columnDefs].some((field2) => pivotFieldIndex(field2) >= databaseCount) && (pageFilter || dateFilter || itemFilters || slicerCacheId !== void 0))
25755
- throw new Error("Date groups with filters are preserved");
25458
+ const fieldSubtotals = [
25459
+ ...subtotalSettings.filter((entry4) => entry4.field !== row3 || entry4.functions.length),
25460
+ ...columnSubtotals
25461
+ ];
25756
25462
  const pivot = {
25757
25463
  ...pageFilter ? { pageFilter } : {},
25758
25464
  ...itemFilters ? { itemFilters } : {},
@@ -25767,13 +25473,11 @@ function readOne(workbook, source2, part) {
25767
25473
  rowField: row3,
25768
25474
  layout: layout3,
25769
25475
  ...rowsAxis ? { valuesAxis: "rows" } : {},
25770
- ...rowsAxis && realRows.length === 2 && valueIndex < 2 ? { valuesPosition: valueIndex === 0 ? "first" : "between" } : {},
25771
- subtotalPosition: att(outer, "subtotalTop") === "0" ? "bottom" : "top",
25772
- ...subtotalSettings.some((entry4) => entry4.field !== row3 || entry4.functions.length) ? {
25773
- fieldSubtotals: subtotalSettings.filter(
25774
- (entry4) => entry4.field !== row3 || entry4.functions.length
25775
- )
25476
+ ...rowsAxis && valueIndex < realRows.length ? {
25477
+ valuesPosition: valueIndex === 0 ? "first" : valueIndex === 1 && realRows.length === 2 ? "between" : valueIndex
25776
25478
  } : {},
25479
+ subtotalPosition: att(outer, "subtotalTop") === "0" ? "bottom" : "top",
25480
+ ...fieldSubtotals.length ? { fieldSubtotals } : {},
25777
25481
  ...more.length ? { moreRowFields: more } : {},
25778
25482
  ...second ? { secondRowField: second, subtotals: subtotal, repeatLabels: repeat[0] ?? false } : {
25779
25483
  ...subtotal ? {} : { subtotals: false },
@@ -28021,8 +27725,8 @@ function parseTable3(xml, partName) {
28021
27725
  if (id3 !== void 0 && Number.isInteger(id3) && id3 >= 0) column2.sourceId = id3;
28022
27726
  const fn = att(node3, "totalsRowFunction");
28023
27727
  if (fn && fn !== "none") column2.totalsRowFunction = fn;
28024
- const label5 = att(node3, "totalsRowLabel");
28025
- if (label5 !== void 0) column2.totalsRowLabel = label5;
27728
+ const label4 = att(node3, "totalsRowLabel");
27729
+ if (label4 !== void 0) column2.totalsRowLabel = label4;
28026
27730
  const calculated = xFirst(node3, "calculatedColumnFormula");
28027
27731
  if (calculated) column2.calculatedColumnFormula = stripFuturePrefixes(xText(calculated));
28028
27732
  return column2;
@@ -30899,11 +30603,11 @@ function gammaLn(z) {
30899
30603
 
30900
30604
  // xlsx/formula/functions/database.ts
30901
30605
  var C3 = "Database";
30902
- var label4 = (value2) => value2 === null ? "" : typeof value2 === "string" ? value2 : String(value2);
30606
+ var label3 = (value2) => value2 === null ? "" : typeof value2 === "string" ? value2 : String(value2);
30903
30607
  function tableOf(ctx, value2) {
30904
30608
  const [head, ...records] = ctx.toMatrix(value2 ?? null).data;
30905
30609
  if (!head || records.length === 0) fail(ERR.VALUE);
30906
- return { headers: head.map((v) => label4(v).toLowerCase()), records };
30610
+ return { headers: head.map((v) => label3(v).toLowerCase()), records };
30907
30611
  }
30908
30612
  function fieldIndex(table3, field2) {
30909
30613
  const value2 = scalar2(field2);
@@ -30913,7 +30617,7 @@ function fieldIndex(table3, field2) {
30913
30617
  if (index4 < 0 || index4 >= table3.headers.length) fail(ERR.VALUE);
30914
30618
  return index4;
30915
30619
  }
30916
- const index3 = table3.headers.indexOf(label4(value2).toLowerCase());
30620
+ const index3 = table3.headers.indexOf(label3(value2).toLowerCase());
30917
30621
  if (index3 < 0) fail(ERR.VALUE);
30918
30622
  return index3;
30919
30623
  }
@@ -30922,7 +30626,7 @@ function recordFilter(table3, criteria) {
30922
30626
  if (!head || rows.length === 0) fail(ERR.VALUE);
30923
30627
  const columns = head.map((name3) => {
30924
30628
  if (name3 === null || name3 === "") return -1;
30925
- return table3.headers.indexOf(label4(name3).toLowerCase());
30629
+ return table3.headers.indexOf(label3(name3).toLowerCase());
30926
30630
  });
30927
30631
  const alternatives = rows.map(
30928
30632
  (row3) => row3.flatMap((cell, c2) => {
@@ -43715,15 +43419,15 @@ function derivedFields(pivot, date1904) {
43715
43419
  function derivedFieldXml(pivot, entry3, date1904) {
43716
43420
  const range2 = { start: entry3.group.start, end: entry3.group.end };
43717
43421
  const days = dateGroupDays(entry3.group);
43718
- const labels = dateUnitLabels(entry3.unit, range2, days, date1904);
43422
+ const labels = dateUnitLabels(entry3.unit, range2, days, date1904, entry3.group);
43719
43423
  const base2 = pivot.fields.indexOf(entry3.group.field);
43720
- 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>`;
43424
+ return `<cacheField${attrs2({ name: encodeEscapes(entry3.name), numFmtId: 0, databaseField: false })}><fieldGroup base="${base2}"><rangePr${attrs2({ autoStart: entry3.autoStart ? void 0 : false, autoEnd: entry3.autoEnd ? void 0 : false, groupBy: entry3.unit, startDate: serialToIso(range2.start, date1904), endDate: serialToIso(range2.end, date1904), groupInterval: days > 1 ? days : void 0 })}/><groupItems count="${labels.length}">${labels.map((label4) => `<s v="${escapeAttr3(label4)}"/>`).join("")}</groupItems></fieldGroup></cacheField>`;
43721
43425
  }
43722
43426
  function groupXml2(pivot, name3, index3) {
43723
43427
  const group = groupOf(pivot, name3);
43724
43428
  if (!group) return "";
43725
43429
  const labels = numberGroupLabels(group);
43726
- 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>`;
43430
+ return `<fieldGroup base="${index3}"><rangePr autoStart="0" autoEnd="0" startNum="${group.start}" endNum="${group.end}" groupInterval="${group.by}"/><groupItems count="${labels.length}">${labels.map((label4) => `<s v="${escapeAttr3(label4)}"/>`).join("")}</groupItems></fieldGroup>`;
43727
43431
  }
43728
43432
  function slicerExt(pivot) {
43729
43433
  if (pivot.slicerCacheId === void 0) return "";
@@ -43744,8 +43448,6 @@ function pivotTableXml(source2, cacheId, cache3) {
43744
43448
  const pivot = expandDateGroups(source2);
43745
43449
  const rowNames = pivotRowFields(pivot);
43746
43450
  const rowIdx = rowNames.map((name3) => pivot.fields.indexOf(name3));
43747
- const row3 = rowIdx[0];
43748
- const second = rowIdx[1] ?? -1;
43749
43451
  const page = pivot.pageFilter ? pivot.fields.indexOf(pivot.pageFilter.field) : -1;
43750
43452
  const pageItems = page >= 0 ? pivotItems(pivot, pivot.pageFilter.field) : [];
43751
43453
  const filtered2 = filteredFields(pivot);
@@ -43773,7 +43475,10 @@ function pivotTableXml(source2, cacheId, cache3) {
43773
43475
  const columnIndicesFull = columnNames.map(
43774
43476
  (_name, k) => itemIndices(visibleColumns[k], columnItemsFull[k])
43775
43477
  );
43776
- const rowEntries = anyFull && grid.rowEntries ? remapPivotRowEntries(grid.rowEntries, rowIndicesFull) : grid.rowEntries;
43478
+ const valuesAt = pivotValuesIndex(pivot);
43479
+ const levelAxes = [...rowIndicesFull];
43480
+ if (valuesAt >= 0) levelAxes.splice(valuesAt, 0, null);
43481
+ const rowEntries = anyFull && grid.rowEntries ? remapPivotRowEntries(grid.rowEntries, levelAxes) : grid.rowEntries;
43777
43482
  const pageOffset = page >= 0 ? 2 : 0;
43778
43483
  const col = columnIdx[0] ?? -1;
43779
43484
  const measures2 = pivotMeasures(pivot);
@@ -43788,7 +43493,7 @@ function pivotTableXml(source2, cacheId, cache3) {
43788
43493
  const colAt = columnIdx.indexOf(index3);
43789
43494
  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);
43790
43495
  const hidden = hiddenItemKeys(pivot, name3);
43791
- const functions = at2 >= 0 ? fieldSubtotalFunctions(pivot, name3) : "auto";
43496
+ const functions = at2 >= 0 || colAt >= 0 ? fieldSubtotalFunctions(pivot, name3) : "auto";
43792
43497
  const automatic = functions === "auto";
43793
43498
  const custom = automatic ? [] : functions;
43794
43499
  const repeated = pivot.repeatLabels && at2 >= 0 ? `<extLst><ext uri="{2946ED86-A175-432a-8AC1-64E0C546D7DE}"><x14:pivotField xmlns:x14="${X143}" fillDownLabels="1"/></ext></extLst>` : "";
@@ -43800,33 +43505,23 @@ function pivotTableXml(source2, cacheId, cache3) {
43800
43505
  }).join("");
43801
43506
  const items = (count2, indices) => Array.from({ length: count2 }, (_v, i2) => `<i><x v="${indices?.[i2] ?? i2}"/></i>`).join("") + '<i t="grand"><x/></i>';
43802
43507
  const header = grid.firstHeaderRow !== void 0 ? grid.firstHeaderRow - pageOffset : col >= 0 ? 1 : grid.firstDataRow - pageOffset - 1;
43803
- const rowIndices = rowsAxis && pivot.valuesPosition === "first" ? [-2, row3, second] : rowsAxis && pivot.valuesPosition === "between" ? [row3, -2, second] : [...rowIdx, ...rowsAxis ? [-2] : []];
43508
+ const rowIndices = [...rowIdx];
43509
+ if (valuesAt >= 0) rowIndices.splice(valuesAt, 0, -2);
43804
43510
  let previous = [];
43805
43511
  const rowItems = rowEntries?.map((entry3) => {
43806
43512
  let prefix3 = 0;
43807
43513
  const type = entry3.type === void 0 || entry3.type === "default" || entry3.type === "grand" ? entry3.type : PIVOT_SUBTOTALS[entry3.type].item;
43808
- if (rowsAxis) {
43809
- if (entry3.type === "default" && pivot.valuesPosition === "first") prefix3 = 1;
43810
- else if (!entry3.type)
43811
- while (prefix3 < entry3.indices.length - 1 && entry3.indices[prefix3] === previous[prefix3])
43812
- prefix3++;
43813
- previous = entry3.type && !(entry3.type === "default" && pivot.valuesPosition === "first") ? [] : entry3.indices;
43814
- } else {
43815
- if (entry3.type !== "grand") prefix3 = sharedPrefix(entry3.indices, previous);
43816
- previous = entry3.type === "grand" ? [] : entry3.indices;
43817
- }
43514
+ if (entry3.type !== "grand") prefix3 = sharedPrefix(entry3.indices, previous);
43515
+ previous = entry3.type === "grand" ? [] : entry3.indices;
43818
43516
  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>`;
43819
43517
  }).join("") ?? items(grid.rowItems.length, rowIndicesFull[0]);
43820
43518
  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>`;
43821
- if (!rowsAxis && col >= 0 && grid.columnEntries) {
43822
- const fieldsOnColumns = [...columnIdx, ...multiple ? [-2] : []];
43823
- body += `<colFields count="${fieldsOnColumns.length}">${fieldsOnColumns.map((index3) => `<field x="${index3}"/>`).join("")}</colFields>${pivotColumnItemsXml(grid.columnEntries, measures2.length, (level, index3) => columnIndicesFull[level][index3])}`;
43519
+ if (col >= 0 && grid.columnEntries) {
43520
+ const fieldsOnColumns = [...columnIdx, ...multiple && !rowsAxis ? [-2] : []];
43521
+ 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])}`;
43824
43522
  } else if (multiple && !rowsAxis)
43825
43523
  body += `<colFields count="1"><field x="-2"/></colFields>${pivotValueAxisItems(measures2.length)}`;
43826
- else if (col >= 0)
43827
- body += `<colFields count="1"><field x="${col}"/></colFields><colItems count="${grid.columnItems.length + 1}">${items(grid.columnItems.length, columnIndicesFull[0])}</colItems>`;
43828
- else
43829
- body += rowsAxis ? '<colItems count="1"><i/></colItems>' : page >= 0 ? '<colItems count="1"><i/></colItems>' : '<colItems count="1"><i><x/></i></colItems>';
43524
+ else body += '<colItems count="1"><i/></colItems>';
43830
43525
  if (page >= 0)
43831
43526
  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>`;
43832
43527
  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>`;
@@ -43837,8 +43532,7 @@ function pivotTableXml(source2, cacheId, cache3) {
43837
43532
  root.setAttribute("name", pivot.name);
43838
43533
  root.setAttribute("cacheId", String(cacheId));
43839
43534
  root.setAttribute("dataOnRows", rowsAxis ? "1" : "0");
43840
- if (rowsAxis && (pivot.valuesPosition === "between" || pivot.valuesPosition === "first"))
43841
- root.setAttribute("dataPosition", pivot.valuesPosition === "first" ? "0" : "1");
43535
+ if (rowsAxis && valuesAt < rowIdx.length) root.setAttribute("dataPosition", String(valuesAt));
43842
43536
  else root.removeAttribute("dataPosition");
43843
43537
  root.setAttribute("compact", compact3 ? "1" : "0");
43844
43538
  root.setAttribute("compactData", compact3 ? "1" : "0");
@@ -43904,7 +43598,8 @@ function pivotTableXml(source2, cacheId, cache3) {
43904
43598
  }
43905
43599
  function dateFilterXml(pivot, filter2) {
43906
43600
  const x15 = "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main";
43907
- 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>`;
43601
+ const id3 = Number(/<filter [^>]*\bid="(\d+)"/.exec(pivot.sourceXml ?? "")?.[1] ?? 1);
43602
+ 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>`;
43908
43603
  }
43909
43604
 
43910
43605
  // xlsx/pivot/write.ts
@@ -48889,7 +48584,7 @@ function pixelSizeToExtent(width, height) {
48889
48584
  }
48890
48585
 
48891
48586
  // xlsx/pivot/date-axes.ts
48892
- var dateGroupAxisNames = (group) => dateGroupUnits(group).reverse().map((unit3) => dateGroupFieldName(unit3, group.field));
48587
+ var dateGroupAxisNames = (group) => dateGroupUnits(group).reverse().map((unit3) => dateGroupFieldName(unit3, group.field, group));
48893
48588
  function replace(list2, names, replacement) {
48894
48589
  const at2 = list2.findIndex((name3) => names.includes(name3));
48895
48590
  if (at2 < 0) return list2;
@@ -48925,7 +48620,9 @@ function reconcileDateAxes(next, previous) {
48925
48620
  if (columns.length > 1) next.moreColumnFields = columns.slice(1);
48926
48621
  else delete next.moreColumnFields;
48927
48622
  if (next.fieldSubtotals) {
48928
- const kept = next.fieldSubtotals.filter((entry3) => rows.includes(entry3.field));
48623
+ const kept = next.fieldSubtotals.filter(
48624
+ (entry3) => rows.includes(entry3.field) || columns.includes(entry3.field)
48625
+ );
48929
48626
  if (kept.length) next.fieldSubtotals = kept;
48930
48627
  else delete next.fieldSubtotals;
48931
48628
  }
@@ -48977,12 +48674,12 @@ function plan(ctx, s, pivot, old) {
48977
48674
  if (occupied) throw new Error("The PivotTable would overwrite existing cell content.");
48978
48675
  return { grid, location };
48979
48676
  }
48980
- function writePivot(ctx, s, pivot, old, label5, inside2) {
48677
+ function writePivot(ctx, s, pivot, old, label4, inside2) {
48981
48678
  const sheet = sheetAt(ctx.workbook, s);
48982
48679
  const { grid, location } = plan(ctx, s, pivot, old);
48983
48680
  const ranges = [...old ? [old.location] : [], location];
48984
48681
  ctx.run(
48985
- label5 ?? (old ? "Refresh PivotTable" : "Create PivotTable"),
48682
+ label4 ?? (old ? "Refresh PivotTable" : "Create PivotTable"),
48986
48683
  "annotations",
48987
48684
  [
48988
48685
  { kind: "parts", sheet: s, parts: ["pivotTables"] },
@@ -49141,6 +48838,12 @@ function refreshPivotTable(ctx, s, name3, patch2 = {}) {
49141
48838
  else delete next.dateFields;
49142
48839
  roundDateRecords(next, dates, ctx.workbook.date1904);
49143
48840
  if (next.dateFilter && !dates.includes(next.dateFilter.field)) delete next.dateFilter;
48841
+ if (patch2.fieldSubtotals === void 0 && next.fieldSubtotals) {
48842
+ const onAxes = [...pivotRowFields(next), ...pivotColumnFields(next)];
48843
+ const left2 = next.fieldSubtotals.filter((entry3) => onAxes.includes(entry3.field));
48844
+ if (left2.length) next.fieldSubtotals = left2;
48845
+ else delete next.fieldSubtotals;
48846
+ }
49144
48847
  const kept = pruneItemFilters(next);
49145
48848
  if (kept) next.itemFilters = kept;
49146
48849
  else delete next.itemFilters;
@@ -49596,10 +49299,10 @@ function validatePatch(group, patch2) {
49596
49299
  delete next.manualMax;
49597
49300
  validateSettings(next);
49598
49301
  }
49599
- function save2(ctx, s, next, label5, ranges) {
49302
+ function save2(ctx, s, next, label4, ranges) {
49600
49303
  const sheet = sheetAt(ctx.workbook, s);
49601
49304
  ctx.run(
49602
- label5,
49305
+ label4,
49603
49306
  "annotations",
49604
49307
  [{ kind: "parts", sheet: s, parts: ["preserved"] }],
49605
49308
  () => sheet.preserved.set("extLst", next),
@@ -53712,8 +53415,8 @@ function createEditSession(workbook, options = {}) {
53712
53415
  if (!workbook.warnings.includes(message)) workbook.warnings.push(message);
53713
53416
  }
53714
53417
  };
53715
- const begin = (label5, kind, info) => {
53716
- const step2 = { label: label5, entries: [], structural: info.structural ?? false };
53418
+ const begin = (label4, kind, info) => {
53419
+ const step2 = { label: label4, entries: [], structural: info.structural ?? false };
53717
53420
  if (info.calc) step2.calc = info.calc;
53718
53421
  return { step: step2, kind, sheet: info.sheet, ranges: [...info.ranges ?? []] };
53719
53422
  };
@@ -53737,7 +53440,7 @@ function createEditSession(workbook, options = {}) {
53737
53440
  }
53738
53441
  current.step.entries.length = from;
53739
53442
  };
53740
- const run2 = (label5, kind, scopes, fn, info = {}) => {
53443
+ const run2 = (label4, kind, scopes, fn, info = {}) => {
53741
53444
  if (kind === "cells") {
53742
53445
  for (const scope of scopes)
53743
53446
  if (scope.kind === "cells" && workbook.sheets[scope.sheet]?.pivotTables?.some(
@@ -53754,7 +53457,7 @@ function createEditSession(workbook, options = {}) {
53754
53457
  }))
53755
53458
  throw new Error(DATA_TABLE_PART_ERROR);
53756
53459
  const outer = !open;
53757
- const current = open ?? begin(label5, kind, info);
53460
+ const current = open ?? begin(label4, kind, info);
53758
53461
  if (!outer) {
53759
53462
  delete current.step.calc;
53760
53463
  if (info.structural) current.step.structural = true;
@@ -53924,12 +53627,12 @@ function createEditSession(workbook, options = {}) {
53924
53627
  validate: (s, r, c2, value2) => validateCellInput(workbook, s, r, c2, value2, {
53925
53628
  evaluate: (formula, at2) => calc.evaluate(formula, at2)
53926
53629
  }),
53927
- batch(label5, fn) {
53630
+ batch(label4, fn) {
53928
53631
  if (open) {
53929
53632
  fn();
53930
53633
  return;
53931
53634
  }
53932
- const current = begin(label5, "batch", {});
53635
+ const current = begin(label4, "batch", {});
53933
53636
  open = current;
53934
53637
  try {
53935
53638
  fn();
@@ -54609,9 +54312,9 @@ var VisioPackage = class _VisioPackage {
54609
54312
  };
54610
54313
 
54611
54314
  // visio/metadata.ts
54612
- function metadata(value2, max, label5) {
54315
+ function metadata(value2, max, label4) {
54613
54316
  if (value2.length > max)
54614
- throw new VisioPackageError("METADATA_LIMIT", `${label5} exceeds its metadata length limit.`);
54317
+ throw new VisioPackageError("METADATA_LIMIT", `${label4} exceeds its metadata length limit.`);
54615
54318
  return value2;
54616
54319
  }
54617
54320
  function metadataAttributes(node3) {
@@ -61245,7 +60948,7 @@ function property(row3, budget, report) {
61245
60948
  "Shape data has no supported current cached typed value; original cached text is retained."
61246
60949
  );
61247
60950
  }
61248
- const label5 = get("Label"), format5 = get("Format"), prompt = get("Prompt"), sortKey = get("SortKey");
60951
+ const label4 = get("Label"), format5 = get("Format"), prompt = get("Prompt"), sortKey = get("SortKey");
61249
60952
  const invisible = boolean(row3.cells, "Invisible", budget, report);
61250
60953
  const dataLinked = row3.cells.has("DataLinked") ? boolean(row3.cells, "DataLinked", budget, report) : void 0;
61251
60954
  const unit3 = row3.cells.get("Value")?.unit, error = row3.cells.get("Value")?.error;
@@ -61257,7 +60960,7 @@ function property(row3, budget, report) {
61257
60960
  ...rawType === void 0 ? {} : { rawType },
61258
60961
  ...rawValue === void 0 ? {} : { rawValue },
61259
60962
  ...value2 === void 0 ? {} : { value: value2 },
61260
- ...label5 === void 0 ? {} : { label: label5 },
60963
+ ...label4 === void 0 ? {} : { label: label4 },
61261
60964
  ...format5 === void 0 ? {} : { format: format5 },
61262
60965
  ...prompt === void 0 ? {} : { prompt },
61263
60966
  ...sortKey === void 0 ? {} : { sortKey },
@@ -61490,9 +61193,9 @@ async function readDataRecordsets(pkg, documentPart, check3) {
61490
61193
  const declared = children3(children3(set, "DataColumns")[0], "DataColumn");
61491
61194
  const columns = (declared.length ? declared : []).map((node3) => {
61492
61195
  const name4 = attribute3(node3, "ColumnNameID") ?? attribute3(node3, "Name") ?? "";
61493
- const label5 = attribute3(node3, "Label") ?? attribute3(node3, "Name") ?? name4;
61494
- if (!name4 || name4.length > 255 || label5.length > 255) invalid2("Invalid data column.");
61495
- return { name: name4, label: label5, type: typeFromCode(attribute3(node3, "DataType")) };
61196
+ const label4 = attribute3(node3, "Label") ?? attribute3(node3, "Name") ?? name4;
61197
+ if (!name4 || name4.length > 255 || label4.length > 255) invalid2("Invalid data column.");
61198
+ return { name: name4, label: label4, type: typeFromCode(attribute3(node3, "DataType")) };
61496
61199
  });
61497
61200
  if (!columns.length)
61498
61201
  for (const column2 of ado.columns)
@@ -71377,9 +71080,9 @@ function visioBorderShapes(style3, width, height, title = VISIO_DEFAULT_TITLE) {
71377
71080
  // visio/edit-page-setup-commands.ts
71378
71081
  var VISIO_SCALE_UNITS = Object.freeze(["IN", "FT", "MM", "CM", "M"]);
71379
71082
  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";
71380
- var pageId = (value2, label5) => {
71083
+ var pageId = (value2, label4) => {
71381
71084
  if (typeof value2 !== "string" || !value2 || value2.length > 256)
71382
- fail2("INVALID_EDIT", `Invalid ${label5}.`);
71085
+ fail2("INVALID_EDIT", `Invalid ${label4}.`);
71383
71086
  return value2;
71384
71087
  };
71385
71088
  var newPageId = (value2) => {
@@ -71486,11 +71189,11 @@ var VISIO_SHAPE_DATA_TYPES = [
71486
71189
  "date"
71487
71190
  ];
71488
71191
  var invalidText2 = /[\u0000-\u0008\u000b\u000c\u000e-\u001f￾￿]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/u;
71489
- function shapeDataText(value2, label5) {
71192
+ function shapeDataText(value2, label4) {
71490
71193
  if (typeof value2 !== "string" || value2.length > VISIO_METADATA_TEXT_LIMIT)
71491
- fail2("INVALID_EDIT", `${label5} must be a string within the length limit.`);
71194
+ fail2("INVALID_EDIT", `${label4} must be a string within the length limit.`);
71492
71195
  if (invalidText2.test(value2) || /[\r\n\t]/.test(value2))
71493
- fail2("INVALID_EDIT_TEXT", `${label5} contains invalid characters.`);
71196
+ fail2("INVALID_EDIT_TEXT", `${label4} contains invalid characters.`);
71494
71197
  return value2;
71495
71198
  }
71496
71199
  function shapeDataRowName(value2) {
@@ -71498,9 +71201,9 @@ function shapeDataRowName(value2) {
71498
71201
  fail2("INVALID_EDIT", "Shape Data row names use letters, digits and underscores.");
71499
71202
  return value2;
71500
71203
  }
71501
- function visioShapeDataRowName(label5, taken = []) {
71204
+ function visioShapeDataRowName(label4, taken = []) {
71502
71205
  const used = new Set([...taken].map((name4) => name4.toLowerCase()));
71503
- let base2 = label5.normalize("NFKD").replace(/[^\w]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 48);
71206
+ let base2 = label4.normalize("NFKD").replace(/[^\w]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 48);
71504
71207
  if (!base2) base2 = "Property";
71505
71208
  if (/^\d/.test(base2)) base2 = `_${base2}`;
71506
71209
  let name3 = base2;
@@ -71572,15 +71275,15 @@ var TYPES3 = [
71572
71275
  "unlink-data-rows"
71573
71276
  ];
71574
71277
  var isVisioDataEdit = (edit) => TYPES3.includes(edit.type);
71575
- var id = (value2, label5) => {
71278
+ var id = (value2, label4) => {
71576
71279
  if (typeof value2 !== "string" || !/^(0|[1-9]\d{0,9})$/.test(value2) || Number(value2) > 4294967295)
71577
- fail2("INVALID_EDIT", `Invalid ${label5}.`);
71280
+ fail2("INVALID_EDIT", `Invalid ${label4}.`);
71578
71281
  return value2;
71579
71282
  };
71580
- var name = (value2, label5) => {
71581
- const text8 = shapeDataText(value2, label5);
71283
+ var name = (value2, label4) => {
71284
+ const text8 = shapeDataText(value2, label4);
71582
71285
  if (!text8.trim() || text8.length > 255)
71583
- fail2("INVALID_EDIT", `${label5} must be 1 to 255 characters.`);
71286
+ fail2("INVALID_EDIT", `${label4} must be 1 to 255 characters.`);
71584
71287
  return text8;
71585
71288
  };
71586
71289
  function table2(columns, rows) {
@@ -71695,16 +71398,16 @@ function snapshotPageTheme(edit) {
71695
71398
  var isVisioCommentEdit = (edit) => edit.type === "add-comment" || edit.type === "edit-comment" || edit.type === "delete-comment";
71696
71399
  var invalidText3 = /[\u0000-\u0008\u000b\u000c\u000e-\u001f￾￿]|[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/u;
71697
71400
  var dateTime = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,7})?(?:Z|[+-]\d{2}:\d{2})?$/;
71698
- function string(value2, limit3, label5, required = true) {
71401
+ function string(value2, limit3, label4, required = true) {
71699
71402
  if (typeof value2 !== "string" || value2.length > limit3 || required && !value2.trim())
71700
- fail2("INVALID_EDIT", `${label5} must be a non-empty string within its length limit.`);
71403
+ fail2("INVALID_EDIT", `${label4} must be a non-empty string within its length limit.`);
71701
71404
  if (invalidText3.test(value2))
71702
- fail2("INVALID_EDIT_TEXT", `${label5} contains invalid XML characters.`);
71405
+ fail2("INVALID_EDIT_TEXT", `${label4} contains invalid XML characters.`);
71703
71406
  return value2;
71704
71407
  }
71705
- var id2 = (value2, label5) => {
71408
+ var id2 = (value2, label4) => {
71706
71409
  if (typeof value2 !== "string" || !/^(0|[1-9]\d{0,9})$/.test(value2) || Number(value2) > 4294967295)
71707
- fail2("INVALID_EDIT", `${label5} must be a canonical unsigned integer.`);
71410
+ fail2("INVALID_EDIT", `${label4} must be a canonical unsigned integer.`);
71708
71411
  return value2;
71709
71412
  };
71710
71413
  var date = (value2) => {
@@ -72227,7 +71930,7 @@ async function editVsdxMasterInstance(pkg, parts, pages, edit, limits, maxOutput
72227
71930
 
72228
71931
  // visio/paper-sizes.ts
72229
71932
  var mm = (value2) => value2 / 25.4;
72230
- var size = (id3, label5, width, height, paperKind) => Object.freeze({ id: id3, label: label5, width, height, ...paperKind === void 0 ? {} : { paperKind } });
71933
+ var size = (id3, label4, width, height, paperKind) => Object.freeze({ id: id3, label: label4, width, height, ...paperKind === void 0 ? {} : { paperKind } });
72231
71934
  var VISIO_PAPER_SIZES = Object.freeze([
72232
71935
  size("letter", "Letter", 8.5, 11, 1),
72233
71936
  size("tabloid", "Tabloid", 11, 17, 3),
@@ -73597,7 +73300,7 @@ function snapshotFormatting(edit) {
73597
73300
  if (!Number.isInteger(value2)) fail2("INVALID_EDIT", "Paint patterns require integers.");
73598
73301
  result2[name3] = value2;
73599
73302
  }
73600
- for (const [name3, maximum, label5] of [
73303
+ for (const [name3, maximum, label4] of [
73601
73304
  ["beginArrow", 45, "Arrowheads are numbered 0 to 45."],
73602
73305
  ["endArrow", 45, "Arrowheads are numbered 0 to 45."],
73603
73306
  ["beginArrowSize", 6, "Arrowhead sizes are numbered 0 to 6."],
@@ -73611,7 +73314,7 @@ function snapshotFormatting(edit) {
73611
73314
  const value2 = edit[name3];
73612
73315
  if (value2 === void 0) continue;
73613
73316
  if (typeof value2 !== "number" || !Number.isInteger(value2) || value2 < 0 || value2 > maximum)
73614
- fail2("INVALID_EDIT", label5);
73317
+ fail2("INVALID_EDIT", label4);
73615
73318
  result2[name3] = value2;
73616
73319
  }
73617
73320
  if (edit.rounding !== void 0) result2.rounding = points(edit.rounding, 0, 720);