ooxml-core 1.9.0 → 1.10.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 (126) hide show
  1. package/dist/PptxHandler-5UURGJEV.mjs +2 -0
  2. package/dist/{PptxHandler-EX4WBIQQ.mjs → PptxHandler-ADEFY476.mjs} +2 -2
  3. package/dist/PptxHandler-U5XB2HUE.cjs +11 -0
  4. package/dist/automation/index.cjs +744 -192
  5. package/dist/automation/index.mjs +744 -192
  6. package/dist/{chunk-SWF7KVL5.cjs → chunk-3N6XMMTT.cjs} +1365 -1062
  7. package/dist/{chunk-FIELY5PI.mjs → chunk-5NVJN4E6.mjs} +30 -2
  8. package/dist/{chunk-IGOA57LE.mjs → chunk-A6P7G3UK.mjs} +1 -1
  9. package/dist/{chunk-CPKNMQLX.cjs → chunk-AWIDASUW.cjs} +25 -2
  10. package/dist/{chunk-SVQZXP3F.mjs → chunk-CBNKBVX5.mjs} +25 -2
  11. package/dist/{chunk-OXHMZS7B.mjs → chunk-CCHYFCPD.mjs} +649 -172
  12. package/dist/{chunk-OB277ZGE.mjs → chunk-R6KSBNKX.mjs} +27 -1
  13. package/dist/{chunk-AT66SA5M.cjs → chunk-S6DOCMQC.cjs} +28 -0
  14. package/dist/{chunk-WSO4T2LJ.mjs → chunk-WUE5ZHU3.mjs} +26 -3
  15. package/dist/{chunk-LCS3J3QI.mjs → chunk-ZE53K7DH.mjs} +474 -171
  16. package/dist/{chunk-M76PHYRR.mjs → chunk-ZOUGMAZG.mjs} +1 -1
  17. package/dist/docx/layout/adapt-table.d.ts +2 -2
  18. package/dist/docx/layout/adapt-table.d.ts.map +1 -1
  19. package/dist/docx/layout/flow-table.d.ts.map +1 -1
  20. package/dist/docx/layout/index.cjs +477 -75
  21. package/dist/docx/layout/index.mjs +477 -76
  22. package/dist/docx/layout/nested-frame-profile.d.ts +9 -0
  23. package/dist/docx/layout/nested-frame-profile.d.ts.map +1 -0
  24. package/dist/docx/layout/page-cursor.d.ts +2 -0
  25. package/dist/docx/layout/page-cursor.d.ts.map +1 -1
  26. package/dist/docx/layout/result.d.ts +13 -0
  27. package/dist/docx/layout/result.d.ts.map +1 -1
  28. package/dist/docx/layout/table-border-layout.d.ts +16 -0
  29. package/dist/docx/layout/table-border-layout.d.ts.map +1 -0
  30. package/dist/docx/layout/table-cell-layout.d.ts +2 -1
  31. package/dist/docx/layout/table-cell-layout.d.ts.map +1 -1
  32. package/dist/docx/layout/table-content.d.ts +4 -0
  33. package/dist/docx/layout/table-content.d.ts.map +1 -0
  34. package/dist/docx/layout/table-footnotes.d.ts +5 -0
  35. package/dist/docx/layout/table-footnotes.d.ts.map +1 -1
  36. package/dist/docx/layout/table-frames.d.ts +4 -0
  37. package/dist/docx/layout/table-frames.d.ts.map +1 -0
  38. package/dist/docx/layout/table-layout.d.ts +8 -3
  39. package/dist/docx/layout/table-layout.d.ts.map +1 -1
  40. package/dist/docx/layout/table-note-completion.d.ts +5 -0
  41. package/dist/docx/layout/table-note-completion.d.ts.map +1 -0
  42. package/dist/docx/layout/table-note-stories.d.ts +6 -0
  43. package/dist/docx/layout/table-note-stories.d.ts.map +1 -0
  44. package/dist/pptx/automation/index.cjs +535 -182
  45. package/dist/pptx/automation/index.d.ts +4 -4
  46. package/dist/pptx/automation/index.mjs +5 -5
  47. package/dist/pptx/chunks/{index-BZh-IMkN.d.ts → index-Cuxtr76Y.d.ts} +17 -3
  48. package/dist/pptx/chunks/index-Cuxtr76Y.d.ts.map +1 -0
  49. package/dist/pptx/chunks/{index-B4cnSPNz.d.ts → index-DUCGeZh7.d.ts} +65 -5
  50. package/dist/pptx/chunks/index-DUCGeZh7.d.ts.map +1 -0
  51. package/dist/pptx/chunks/{smart-art-Q2kZQtHh.d.ts → smart-art-D-sXa_Nb.d.ts} +11 -1
  52. package/dist/pptx/chunks/smart-art-D-sXa_Nb.d.ts.map +1 -0
  53. package/dist/pptx/chunks/{text-operations-BLodkuXE.d.ts → text-operations-BqHmLaLA.d.ts} +26 -2
  54. package/dist/pptx/chunks/text-operations-BqHmLaLA.d.ts.map +1 -0
  55. package/dist/pptx/cli/index.cjs +535 -182
  56. package/dist/pptx/cli/index.d.ts +1 -1
  57. package/dist/pptx/cli/index.mjs +4 -4
  58. package/dist/pptx/converter/index.cjs +1 -0
  59. package/dist/pptx/converter/index.d.ts +1 -1
  60. package/dist/pptx/converter/index.mjs +2 -2
  61. package/dist/pptx/editor/render/collaboration-live-patch-target.cjs +2 -2
  62. package/dist/pptx/editor/render/collaboration-live-patch-target.mjs +1 -1
  63. package/dist/pptx/editor/render/find-replace.cjs +18 -18
  64. package/dist/pptx/editor/render/find-replace.d.ts +2 -2
  65. package/dist/pptx/editor/render/find-replace.mjs +2 -2
  66. package/dist/pptx/editor/render/remap-text.cjs +2 -2
  67. package/dist/pptx/editor/render/remap-text.d.ts.map +1 -1
  68. package/dist/pptx/editor/render/remap-text.mjs +1 -1
  69. package/dist/pptx/editor/render/slide-operations.cjs +8 -8
  70. package/dist/pptx/editor/render/slide-operations.mjs +2 -2
  71. package/dist/pptx/index.cjs +762 -182
  72. package/dist/pptx/index.d.ts +5 -5
  73. package/dist/pptx/index.mjs +5 -5
  74. package/dist/pptx/smartart-layouts/index.d.ts +1 -1
  75. package/dist/teams/index.cjs +486 -114
  76. package/dist/teams/index.mjs +486 -114
  77. package/dist/visio/date-cache.d.ts +3 -0
  78. package/dist/visio/date-cache.d.ts.map +1 -0
  79. package/dist/visio/edit-text-field.d.ts.map +1 -1
  80. package/dist/visio/index.cjs +131 -22
  81. package/dist/visio/index.mjs +131 -22
  82. package/dist/visio/shape-metadata.d.ts.map +1 -1
  83. package/dist/visio/text-field-display.d.ts.map +1 -1
  84. package/dist/visio/text-field-fraction.d.ts +3 -0
  85. package/dist/visio/text-field-fraction.d.ts.map +1 -0
  86. package/dist/visio/text-field-numeric.d.ts +1 -1
  87. package/dist/visio/text-field-numeric.d.ts.map +1 -1
  88. package/dist/visio/text-field-system-date.d.ts +4 -0
  89. package/dist/visio/text-field-system-date.d.ts.map +1 -0
  90. package/dist/visio/text-fields.d.ts +1 -0
  91. package/dist/visio/text-fields.d.ts.map +1 -1
  92. package/dist/visio/ui/index.cjs +132 -22
  93. package/dist/visio/ui/index.mjs +132 -22
  94. package/dist/visio/ui/text-field-catalog.d.ts.map +1 -1
  95. package/dist/xlsx/edit/pivots.d.ts.map +1 -1
  96. package/dist/xlsx/index.cjs +614 -170
  97. package/dist/xlsx/index.mjs +614 -170
  98. package/dist/xlsx/load/index.cjs +575 -163
  99. package/dist/xlsx/load/index.mjs +575 -163
  100. package/dist/xlsx/model-pivots.d.ts +23 -2
  101. package/dist/xlsx/model-pivots.d.ts.map +1 -1
  102. package/dist/xlsx/pivot/admission.d.ts.map +1 -1
  103. package/dist/xlsx/pivot/aggregate.d.ts +3 -1
  104. package/dist/xlsx/pivot/aggregate.d.ts.map +1 -1
  105. package/dist/xlsx/pivot/data.d.ts +1 -1
  106. package/dist/xlsx/pivot/data.d.ts.map +1 -1
  107. package/dist/xlsx/pivot/hierarchy-first.d.ts +21 -0
  108. package/dist/xlsx/pivot/hierarchy-first.d.ts.map +1 -0
  109. package/dist/xlsx/pivot/hierarchy.d.ts +2 -4
  110. package/dist/xlsx/pivot/hierarchy.d.ts.map +1 -1
  111. package/dist/xlsx/pivot/measures.d.ts +13 -0
  112. package/dist/xlsx/pivot/measures.d.ts.map +1 -0
  113. package/dist/xlsx/pivot/read.d.ts.map +1 -1
  114. package/dist/xlsx/pivot/table-xml.d.ts.map +1 -1
  115. package/dist/xlsx/pivot/values-axis.d.ts +9 -0
  116. package/dist/xlsx/pivot/values-axis.d.ts.map +1 -0
  117. package/dist/xlsx/ui/commands/i18n/pivots.d.ts.map +1 -1
  118. package/dist/xlsx/ui/index.cjs +547 -127
  119. package/dist/xlsx/ui/index.mjs +547 -127
  120. package/package.json +1 -1
  121. package/dist/PptxHandler-AT7FVG5Q.mjs +0 -2
  122. package/dist/PptxHandler-VFSCECPL.cjs +0 -11
  123. package/dist/pptx/chunks/index-B4cnSPNz.d.ts.map +0 -1
  124. package/dist/pptx/chunks/index-BZh-IMkN.d.ts.map +0 -1
  125. package/dist/pptx/chunks/smart-art-Q2kZQtHh.d.ts.map +0 -1
  126. package/dist/pptx/chunks/text-operations-BLodkuXE.d.ts.map +0 -1
@@ -15033,6 +15033,25 @@ function validatePivotFields(pivot) {
15033
15033
  ...pivot.columnField ? [pivot.columnField] : [],
15034
15034
  pivot.valueField
15035
15035
  ];
15036
+ const extras = pivot.additionalValues ?? [];
15037
+ if (pivot.valuesAxis !== void 0 && !["columns", "rows"].includes(pivot.valuesAxis))
15038
+ throw new Error("Choose a valid Values axis.");
15039
+ if (pivot.valuesPosition !== void 0 && !["last", "between", "first"].includes(pivot.valuesPosition))
15040
+ throw new Error("Choose a valid Values position.");
15041
+ if ((pivot.valuesPosition === "between" || pivot.valuesPosition === "first") && (pivot.valuesAxis !== "rows" || !pivot.secondRowField))
15042
+ throw new Error("Values before or between fields require two row fields and Values on rows.");
15043
+ if (pivot.valuesAxis === "rows" && (!Array.isArray(extras) || !extras.length))
15044
+ throw new Error("Values on rows require multiple measures.");
15045
+ if (extras.length > 0 && pivot.sourceXml && parseXml(pivot.sourceXml).documentElement.getAttribute("dataCaption") !== "Values")
15046
+ throw new Error("This PivotTable uses unsupported Values header captions.");
15047
+ if (!Array.isArray(extras) || extras.length > 15 || extras.some(
15048
+ (measure) => !measure || !pivot.fields.includes(measure.field) || !PIVOT_AGGREGATES.includes(measure.aggregate) || typeof measure.caption !== "string" || !measure.caption.trim() || measure.caption.length > 255 || pivot.fields.some((field) => field.toLowerCase() === measure.caption.toLowerCase())
15049
+ ) || new Set(
15050
+ [pivot.valueCaption, ...extras.map((measure) => measure.caption)].map(
15051
+ (caption) => caption?.toLowerCase()
15052
+ )
15053
+ ).size !== extras.length + 1)
15054
+ throw new Error("Choose PivotTable value fields with valid aggregates and unique captions.");
15036
15055
  if (pivot.layout !== void 0 && !["tabular", "compact", "outline"].includes(pivot.layout) || pivot.subtotalPosition !== void 0 && !["top", "bottom"].includes(pivot.subtotalPosition) || !PIVOT_AGGREGATES.includes(pivot.aggregate) || used.some((field) => !pivot.fields.includes(field)) || new Set([pivot.rowField, pivot.secondRowField, pivot.columnField].filter(Boolean)).size !== [pivot.rowField, pivot.secondRowField, pivot.columnField].filter(Boolean).length || pivot.subtotals !== void 0 && typeof pivot.subtotals !== "boolean" || pivot.repeatLabels !== void 0 && typeof pivot.repeatLabels !== "boolean")
15037
15056
  throw new Error("Choose valid PivotTable fields; row and column fields must differ.");
15038
15057
  }
@@ -15040,21 +15059,191 @@ function pivotCaption(aggregate3, field) {
15040
15059
  return `${aggregate3[0].toUpperCase()}${aggregate3.slice(1)} of ${field}`;
15041
15060
  }
15042
15061
 
15062
+ // xlsx/pivot/measures.ts
15063
+ var pivotMeasures = (pivot) => [
15064
+ { field: pivot.valueField, aggregate: pivot.aggregate, caption: pivot.valueCaption },
15065
+ ...pivot.additionalValues ?? []
15066
+ ];
15067
+ function normalizedPivotMeasures(values2) {
15068
+ if (!Array.isArray(values2) || values2.length > 15)
15069
+ throw new Error("Choose between one and sixteen PivotTable value fields.");
15070
+ return values2.map((value2) => {
15071
+ if (!value2 || typeof value2.field !== "string")
15072
+ throw new Error("Choose valid PivotTable value fields.");
15073
+ const aggregate3 = value2.aggregate ?? "sum";
15074
+ if (!PIVOT_AGGREGATES.includes(aggregate3))
15075
+ throw new Error("Choose a valid PivotTable aggregate.");
15076
+ return {
15077
+ field: value2.field,
15078
+ aggregate: aggregate3,
15079
+ caption: value2.caption ?? `${aggregate3[0].toUpperCase()}${aggregate3.slice(1)} of ${value2.field}`
15080
+ };
15081
+ });
15082
+ }
15083
+ function aggregate2(records, field, type) {
15084
+ if (!records.length) return null;
15085
+ const values2 = records.map((record) => record[field] ?? null);
15086
+ if (type === "count") return values2.filter((value2) => value2 !== null && value2 !== "").length;
15087
+ const error = values2.find(isCellError);
15088
+ if (error) return error;
15089
+ const numbers3 = values2.filter((value2) => typeof value2 === "number");
15090
+ if (!numbers3.length) return type === "average" ? { error: "#DIV/0!" } : 0;
15091
+ if (type === "min") return numbers3.reduce((a2, b) => Math.min(a2, b));
15092
+ if (type === "max") return numbers3.reduce((a2, b) => Math.max(a2, b));
15093
+ const sum2 = numbers3.reduce((total2, value2) => total2 + value2, 0);
15094
+ return type === "average" ? sum2 / numbers3.length : sum2;
15095
+ }
15096
+ var pivotMeasureNumber = (pivot, records, measure) => aggregate2(records, pivot.fields.indexOf(measure.field), measure.aggregate);
15097
+ var pivotNumbers = (pivot, records) => pivotMeasures(pivot).map((measure) => pivotMeasureNumber(pivot, records, measure));
15098
+ function pivotHeaderDimensions(pivot, columnItems, rowLabels) {
15099
+ const measures = 1 + (pivot.additionalValues?.length ?? 0);
15100
+ if (pivot.valuesAxis === "rows")
15101
+ return {
15102
+ rows: pivot.columnField ? 2 : 1,
15103
+ width: rowLabels + (pivot.columnField ? columnItems + 1 : 1)
15104
+ };
15105
+ return {
15106
+ rows: pivot.columnField ? measures > 1 ? 3 : 2 : 1,
15107
+ width: rowLabels + (pivot.columnField ? measures === 1 ? Math.max(1, columnItems) + 1 : (columnItems + 1) * measures : measures)
15108
+ };
15109
+ }
15110
+ function pivotHeaders(pivot, columns, labels, label3) {
15111
+ const measures = pivotMeasures(pivot);
15112
+ if (pivot.valuesAxis === "rows") {
15113
+ const rowLabels = pivot.layout === "compact" ? ["Row Labels"] : pivot.valuesPosition === "first" ? ["Values", ...labels] : pivot.valuesPosition === "between" ? [labels[0], "Values", labels[1]] : [...labels, "Values"];
15114
+ return pivot.columnField ? [
15115
+ [
15116
+ ...rowLabels.map(() => null),
15117
+ pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
15118
+ ...columns.map(() => null)
15119
+ ],
15120
+ [...rowLabels, ...columns.map(label3), "Grand Total"]
15121
+ ] : [[...rowLabels, null]];
15122
+ }
15123
+ if (!pivot.columnField) return [[...labels, ...measures.map((measure) => measure.caption)]];
15124
+ if (measures.length === 1)
15125
+ return [
15126
+ [
15127
+ pivot.valueCaption,
15128
+ ...labels.slice(1).map(() => null),
15129
+ pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
15130
+ ...columns.slice(1).map(() => null),
15131
+ null
15132
+ ],
15133
+ [...labels, ...columns.map(label3), "Grand Total"]
15134
+ ];
15135
+ const { width } = pivotHeaderDimensions(pivot, columns.length, labels.length);
15136
+ const first2 = Array(width).fill(null);
15137
+ first2[labels.length] = pivot.layout === "compact" ? "Column Labels" : pivot.columnField;
15138
+ if (pivot.layout !== "compact") first2[labels.length + 1] = "Values";
15139
+ return [
15140
+ first2,
15141
+ [
15142
+ ...labels.map(() => null),
15143
+ ...columns.flatMap((column) => [label3(column), ...measures.slice(1).map(() => null)]),
15144
+ ...measures.map((measure) => `Total ${measure.caption}`)
15145
+ ],
15146
+ [
15147
+ ...labels,
15148
+ ...columns.flatMap(() => measures.map((measure) => measure.caption)),
15149
+ ...measures.map(() => null)
15150
+ ]
15151
+ ];
15152
+ }
15153
+
15154
+ // xlsx/pivot/hierarchy-first.ts
15155
+ function appendFirstPivotValues(pivot, context) {
15156
+ const {
15157
+ rowItems,
15158
+ secondRowItems,
15159
+ columnItems,
15160
+ children: children2,
15161
+ innerIndices,
15162
+ groups,
15163
+ details,
15164
+ buckets,
15165
+ width,
15166
+ rowLabels,
15167
+ top,
15168
+ bottom,
15169
+ append
15170
+ } = context;
15171
+ const compact3 = pivot.layout === "compact";
15172
+ const tabular = !pivot.layout || pivot.layout === "tabular";
15173
+ const blank = () => Array(width - rowLabels).fill(null);
15174
+ pivotMeasures(pivot).forEach((measure, m) => {
15175
+ const numbers3 = (keys, records) => [
15176
+ ...columnItems.map(
15177
+ (column) => pivotMeasureNumber(
15178
+ pivot,
15179
+ buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
15180
+ measure
15181
+ )
15182
+ ),
15183
+ pivotMeasureNumber(pivot, records, measure)
15184
+ ];
15185
+ if (!tabular)
15186
+ append([measure.caption, ...Array(rowLabels - 1).fill(null)], blank(), {
15187
+ indices: [m],
15188
+ measure: m
15189
+ });
15190
+ let first2 = true;
15191
+ rowItems.forEach((outer, outerIndex) => {
15192
+ const key = pivotValueKey(outer);
15193
+ const group = groups.get(key) ?? [];
15194
+ if (!tabular)
15195
+ append(
15196
+ compact3 ? [pivotItemLabel(outer)] : [null, pivotItemLabel(outer), null],
15197
+ top ? numbers3([key], group) : blank(),
15198
+ { indices: [m, outerIndex], measure: m },
15199
+ compact3 ? 1 : 0
15200
+ );
15201
+ const innerKeys = [...children2.get(key)].sort(
15202
+ (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
15203
+ );
15204
+ innerKeys.forEach((innerKey, child3) => {
15205
+ const innerIndex = innerIndices.get(innerKey);
15206
+ append(
15207
+ compact3 ? [pivotItemLabel(secondRowItems[innerIndex])] : [
15208
+ tabular && first2 ? measure.caption : null,
15209
+ pivot.repeatLabels || tabular && child3 === 0 ? pivotItemLabel(outer) : null,
15210
+ pivotItemLabel(secondRowItems[innerIndex])
15211
+ ],
15212
+ numbers3([key, innerKey], details.get(JSON.stringify([key, innerKey]))),
15213
+ { indices: [m, outerIndex, innerIndex], measure: m },
15214
+ compact3 ? 2 : 0
15215
+ );
15216
+ first2 = false;
15217
+ });
15218
+ if (bottom)
15219
+ append(
15220
+ compact3 ? [`${String(pivotItemLabel(outer))} Total`] : [null, `${String(pivotItemLabel(outer))} Total`, null],
15221
+ numbers3([key], group),
15222
+ { indices: [m, outerIndex], measure: m, type: "default" },
15223
+ compact3 ? 1 : 0
15224
+ );
15225
+ });
15226
+ });
15227
+ }
15228
+
15043
15229
  // xlsx/pivot/hierarchy.ts
15044
15230
  var label2 = pivotItemLabel;
15045
- function hierarchicalPivotGrid(pivot, aggregate3) {
15231
+ function hierarchicalPivotGrid(pivot) {
15046
15232
  const rowItems = pivotItems(pivot, pivot.rowField);
15047
15233
  const secondRowItems = pivotItems(pivot, pivot.secondRowField);
15048
15234
  const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
15049
15235
  const outerField = pivot.fields.indexOf(pivot.rowField);
15050
15236
  const innerField = pivot.fields.indexOf(pivot.secondRowField);
15051
15237
  const columnField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
15052
- const valueField = pivot.fields.indexOf(pivot.valueField);
15053
15238
  const layout2 = pivot.layout ?? "tabular";
15054
15239
  const compact3 = layout2 === "compact";
15055
- const top = layout2 !== "tabular" && pivot.subtotals !== false && (pivot.subtotalPosition ?? "top") === "top";
15240
+ const rowsAxis = pivot.valuesAxis === "rows";
15241
+ const firstValues = rowsAxis && pivot.valuesPosition === "first";
15242
+ const between = rowsAxis && pivot.valuesPosition === "between";
15243
+ const measures = pivotMeasures(pivot);
15244
+ const top = (!rowsAxis || firstValues) && layout2 !== "tabular" && pivot.subtotals !== false && (pivot.subtotalPosition ?? "top") === "top";
15056
15245
  const bottom = pivot.subtotals !== false && !top;
15057
- const rowLabelColumns = compact3 ? 1 : 2;
15246
+ const rowLabelColumns = compact3 ? 1 : rowsAxis ? 3 : 2;
15058
15247
  const groups = /* @__PURE__ */ new Map();
15059
15248
  const details = /* @__PURE__ */ new Map();
15060
15249
  const children2 = /* @__PURE__ */ new Map();
@@ -15078,20 +15267,12 @@ function hierarchicalPivotGrid(pivot, aggregate3) {
15078
15267
  collect2(buckets, JSON.stringify([...key, column]), record);
15079
15268
  }
15080
15269
  }
15081
- const rows = details.size + rowItems.length * (Number(layout2 !== "tabular") + Number(bottom)) + 3;
15082
- if (rows * (columnItems.length + 3) > 1e6)
15083
- throw new Error("The PivotTable result is too large.");
15270
+ const dimensions = pivotHeaderDimensions(pivot, columnItems.length, rowLabelColumns);
15271
+ const rows = (details.size + rowItems.length * Number(bottom) + 1) * (rowsAxis ? measures.length : 1) + rowItems.length * Number(layout2 !== "tabular") * (firstValues ? measures.length : 1) + (firstValues ? measures.length : between ? rowItems.length * measures.length : details.size) * Number(rowsAxis && layout2 !== "tabular") + dimensions.rows;
15272
+ if (rows * dimensions.width > 1e6) throw new Error("The PivotTable result is too large.");
15084
15273
  const labels = compact3 ? ["Row Labels"] : [pivot.rowField, pivot.secondRowField];
15085
- const values2 = pivot.columnField ? [
15086
- [
15087
- pivot.valueCaption,
15088
- ...compact3 ? [] : [null],
15089
- compact3 ? "Column Labels" : pivot.columnField,
15090
- ...columnItems.slice(1).map(() => null),
15091
- null
15092
- ],
15093
- [...labels, ...columnItems.map(label2), "Grand Total"]
15094
- ] : [[...labels, pivot.valueCaption]];
15274
+ const values2 = pivotHeaders(pivot, columnItems, labels, label2);
15275
+ const firstDataRow = values2.length;
15095
15276
  const indents = values2.map(() => 0);
15096
15277
  const rowEntries = [];
15097
15278
  const append = (labels2, numbers4, entry3, indent = 0) => {
@@ -15099,91 +15280,184 @@ function hierarchicalPivotGrid(pivot, aggregate3) {
15099
15280
  rowEntries.push(entry3);
15100
15281
  indents.push(indent);
15101
15282
  };
15102
- const numbers3 = (keys, records) => [
15283
+ const bands = (keys, records) => [
15103
15284
  ...columnItems.map(
15104
- (column) => aggregate3(
15105
- buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
15106
- valueField,
15107
- pivot.aggregate
15108
- )
15285
+ (column) => pivotNumbers(pivot, buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [])
15109
15286
  ),
15110
- aggregate3(records, valueField, pivot.aggregate)
15287
+ pivotNumbers(pivot, records)
15111
15288
  ];
15112
- rowItems.forEach((outer, outerIndex) => {
15113
- const key = pivotValueKey(outer);
15114
- if (layout2 !== "tabular")
15115
- append(
15116
- [label2(outer), ...compact3 ? [] : [null]],
15117
- top ? numbers3([key], groups.get(key) ?? []) : Array(columnItems.length + 1).fill(null),
15118
- { indices: [outerIndex] }
15119
- );
15120
- let first2 = true;
15121
- [...children2.get(key)].sort((a2, b) => innerIndices.get(a2) - innerIndices.get(b)).forEach((innerKey) => {
15122
- const innerIndex = innerIndices.get(innerKey);
15123
- const inner2 = secondRowItems[innerIndex];
15124
- const keys = [key, innerKey];
15125
- const records = details.get(JSON.stringify(keys));
15126
- if (!records) return;
15127
- append(
15128
- compact3 ? [label2(inner2)] : [
15129
- pivot.repeatLabels || layout2 === "tabular" && first2 ? label2(outer) : null,
15130
- label2(inner2)
15289
+ const numbers3 = (keys, records) => bands(keys, records).flat();
15290
+ const appendMeasures = (labels2, keys, records, indices, type) => {
15291
+ const values3 = bands(keys, records);
15292
+ measures.forEach(
15293
+ (measure, m) => append(
15294
+ type ? [
15295
+ `${type === "grand" ? "Total" : String(labels2[0])} ${measure.caption}`,
15296
+ ...Array(rowLabelColumns - 1).fill(null)
15297
+ ] : compact3 ? [measure.caption] : [
15298
+ ...labels2.map(
15299
+ (label3) => layout2 === "tabular" && m === 0 || pivot.repeatLabels ? label3 : null
15300
+ ),
15301
+ measure.caption
15131
15302
  ],
15132
- numbers3(keys, records),
15133
- { indices: [outerIndex, innerIndex] },
15134
- compact3 ? 1 : 0
15135
- );
15136
- first2 = false;
15303
+ values3.map((band) => band[m] ?? null),
15304
+ { indices: type ? indices : [...indices, m], measure: m, ...type ? { type } : {} },
15305
+ compact3 && !type ? 2 : 0
15306
+ )
15307
+ );
15308
+ };
15309
+ if (firstValues)
15310
+ appendFirstPivotValues(pivot, {
15311
+ rowItems,
15312
+ secondRowItems,
15313
+ columnItems,
15314
+ children: children2,
15315
+ innerIndices,
15316
+ groups,
15317
+ details,
15318
+ buckets,
15319
+ width: dimensions.width,
15320
+ rowLabels: rowLabelColumns,
15321
+ top,
15322
+ bottom,
15323
+ append
15137
15324
  });
15138
- if (bottom) {
15139
- const caption = String(label2(outer));
15140
- append(
15141
- [`${caption} Total`, ...compact3 ? [] : [null]],
15142
- numbers3([key], groups.get(key) ?? []),
15143
- { indices: [outerIndex], type: "default" }
15325
+ else
15326
+ rowItems.forEach((outer, outerIndex) => {
15327
+ const key = pivotValueKey(outer);
15328
+ if (layout2 !== "tabular")
15329
+ append(
15330
+ [label2(outer), ...Array(rowLabelColumns - 1).fill(null)],
15331
+ top ? numbers3([key], groups.get(key) ?? []) : Array(dimensions.width - rowLabelColumns).fill(null),
15332
+ { indices: [outerIndex] }
15333
+ );
15334
+ let first2 = true;
15335
+ const innerKeys = [...children2.get(key)].sort(
15336
+ (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
15144
15337
  );
15145
- }
15146
- });
15147
- append(["Grand Total", ...compact3 ? [] : [null]], numbers3([], pivot.records), {
15148
- indices: [0],
15149
- type: "grand"
15150
- });
15338
+ if (between)
15339
+ measures.forEach((measure, m) => {
15340
+ if (layout2 !== "tabular")
15341
+ append(
15342
+ compact3 ? [measure.caption] : [pivot.repeatLabels ? label2(outer) : null, measure.caption, null],
15343
+ Array(dimensions.width - rowLabelColumns).fill(null),
15344
+ { indices: [outerIndex, m], measure: m },
15345
+ compact3 ? 1 : 0
15346
+ );
15347
+ innerKeys.forEach((innerKey, child3) => {
15348
+ const innerIndex = innerIndices.get(innerKey);
15349
+ const keys = [key, innerKey];
15350
+ const records = details.get(JSON.stringify(keys));
15351
+ append(
15352
+ compact3 ? [label2(secondRowItems[innerIndex])] : [
15353
+ pivot.repeatLabels || layout2 === "tabular" && m === 0 && child3 === 0 ? label2(outer) : null,
15354
+ layout2 === "tabular" && child3 === 0 ? measure.caption : null,
15355
+ label2(secondRowItems[innerIndex])
15356
+ ],
15357
+ [
15358
+ ...columnItems.map(
15359
+ (column) => pivotMeasureNumber(
15360
+ pivot,
15361
+ buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
15362
+ measure
15363
+ )
15364
+ ),
15365
+ pivotMeasureNumber(pivot, records, measure)
15366
+ ],
15367
+ { indices: [outerIndex, m, innerIndex], measure: m },
15368
+ compact3 ? 2 : 0
15369
+ );
15370
+ });
15371
+ });
15372
+ else
15373
+ innerKeys.forEach((innerKey) => {
15374
+ const innerIndex = innerIndices.get(innerKey);
15375
+ const inner2 = secondRowItems[innerIndex];
15376
+ const keys = [key, innerKey];
15377
+ const records = details.get(JSON.stringify(keys));
15378
+ if (!records) return;
15379
+ if (rowsAxis) {
15380
+ if (layout2 !== "tabular")
15381
+ append(
15382
+ compact3 ? [label2(inner2)] : [pivot.repeatLabels ? label2(outer) : null, label2(inner2), null],
15383
+ Array(dimensions.width - rowLabelColumns).fill(null),
15384
+ { indices: [outerIndex, innerIndex] },
15385
+ compact3 ? 1 : 0
15386
+ );
15387
+ appendMeasures(
15388
+ [pivot.repeatLabels || first2 ? label2(outer) : null, label2(inner2)],
15389
+ keys,
15390
+ records,
15391
+ [outerIndex, innerIndex]
15392
+ );
15393
+ first2 = false;
15394
+ return;
15395
+ }
15396
+ append(
15397
+ compact3 ? [label2(inner2)] : [
15398
+ pivot.repeatLabels || layout2 === "tabular" && first2 ? label2(outer) : null,
15399
+ label2(inner2)
15400
+ ],
15401
+ numbers3(keys, records),
15402
+ { indices: [outerIndex, innerIndex] },
15403
+ compact3 ? 1 : 0
15404
+ );
15405
+ first2 = false;
15406
+ });
15407
+ if (bottom) {
15408
+ if (rowsAxis) {
15409
+ appendMeasures([label2(outer)], [key], groups.get(key) ?? [], [outerIndex], "default");
15410
+ return;
15411
+ }
15412
+ const caption = String(label2(outer));
15413
+ append(
15414
+ [`${caption} Total`, ...compact3 ? [] : [null]],
15415
+ numbers3([key], groups.get(key) ?? []),
15416
+ { indices: [outerIndex], type: "default" }
15417
+ );
15418
+ }
15419
+ });
15420
+ if (rowsAxis) appendMeasures([], [], pivot.records, [0], "grand");
15421
+ else
15422
+ append(["Grand Total", ...compact3 ? [] : [null]], numbers3([], pivot.records), {
15423
+ indices: [0],
15424
+ type: "grand"
15425
+ });
15151
15426
  return {
15152
15427
  values: values2,
15153
15428
  rowItems,
15154
15429
  secondRowItems,
15155
15430
  columnItems,
15156
15431
  rowEntries,
15157
- firstDataRow: pivot.columnField ? 2 : 1,
15432
+ firstDataRow,
15158
15433
  rowLabelColumns,
15159
- indents
15434
+ indents,
15435
+ ...rowsAxis ? { firstHeaderRow: 1 } : {}
15160
15436
  };
15161
15437
  }
15162
15438
 
15163
15439
  // xlsx/pivot/aggregate.ts
15164
- function aggregate2(records, field, type) {
15165
- if (!records.length) return null;
15166
- const values2 = records.map((record) => record[field] ?? null);
15167
- if (type === "count") return values2.filter((value2) => value2 !== null && value2 !== "").length;
15168
- const error = values2.find(isCellError);
15169
- if (error) return error;
15170
- const numbers3 = values2.filter((value2) => typeof value2 === "number");
15171
- if (!numbers3.length) return type === "average" ? { error: "#DIV/0!" } : 0;
15172
- if (type === "min") return numbers3.reduce((a2, b) => Math.min(a2, b));
15173
- if (type === "max") return numbers3.reduce((a2, b) => Math.max(a2, b));
15174
- const sum2 = numbers3.reduce((total2, value2) => total2 + value2, 0);
15175
- return type === "average" ? sum2 / numbers3.length : sum2;
15176
- }
15177
15440
  function pivotGrid(pivot) {
15178
15441
  validatePivotFields(pivot);
15179
- if (pivot.secondRowField) return hierarchicalPivotGrid(pivot, aggregate2);
15442
+ if (pivot.secondRowField) return hierarchicalPivotGrid(pivot);
15180
15443
  const rowItems = pivotItems(pivot, pivot.rowField);
15181
15444
  const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
15182
- if ((rowItems.length + 3) * (columnItems.length + 2) > 1e6)
15445
+ const rowsAxis = pivot.valuesAxis === "rows";
15446
+ const compact3 = pivot.layout === "compact";
15447
+ const headings = rowsAxis && pivot.layout !== void 0 && pivot.layout !== "tabular";
15448
+ const dimensions = pivotHeaderDimensions(pivot, columnItems.length, rowsAxis && !compact3 ? 2 : 1);
15449
+ const dataRows = (rowItems.length + 1) * (rowsAxis ? 1 + (pivot.additionalValues?.length ?? 0) : 1) + (headings ? rowItems.length : 0);
15450
+ if ((dataRows + dimensions.rows) * dimensions.width > 1e6)
15183
15451
  throw new Error("The PivotTable result is too large.");
15452
+ const label3 = pivotItemLabel;
15453
+ const values2 = pivotHeaders(
15454
+ pivot,
15455
+ columnItems,
15456
+ [pivot.layout === "compact" ? "Row Labels" : pivot.rowField],
15457
+ label3
15458
+ );
15184
15459
  const rowField = pivot.fields.indexOf(pivot.rowField);
15185
15460
  const colField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
15186
- const valueField = pivot.fields.indexOf(pivot.valueField);
15187
15461
  const groups = /* @__PURE__ */ new Map();
15188
15462
  const cells = /* @__PURE__ */ new Map();
15189
15463
  const columns = /* @__PURE__ */ new Map();
@@ -15201,42 +15475,85 @@ function pivotGrid(pivot) {
15201
15475
  collect2(cells, JSON.stringify([key, col]), record);
15202
15476
  }
15203
15477
  }
15204
- const label3 = pivotItemLabel;
15205
- const values2 = pivot.columnField ? [
15206
- [
15207
- pivot.valueCaption,
15208
- pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
15209
- ...columnItems.slice(1).map(() => null),
15210
- null
15211
- ],
15212
- [
15213
- pivot.layout === "compact" ? "Row Labels" : pivot.rowField,
15214
- ...columnItems.map(label3),
15215
- "Grand Total"
15216
- ]
15217
- ] : [[pivot.layout === "compact" ? "Row Labels" : pivot.rowField, pivot.valueCaption]];
15478
+ const firstDataRow = values2.length;
15479
+ if (rowsAxis) {
15480
+ const measures = pivotMeasures(pivot);
15481
+ const rowEntries = [];
15482
+ const indents = values2.map(() => 0);
15483
+ const append = (caption, bands, index2, grand = false) => {
15484
+ measures.forEach((measure, m) => {
15485
+ values2.push([
15486
+ ...compact3 ? [grand ? `Total ${measure.caption}` : measure.caption] : [
15487
+ grand ? `Total ${measure.caption}` : pivot.repeatLabels || !headings && m === 0 ? caption : null,
15488
+ grand ? null : measure.caption
15489
+ ],
15490
+ ...bands.map((band) => band[m] ?? null)
15491
+ ]);
15492
+ indents.push(compact3 && !grand ? 1 : 0);
15493
+ rowEntries.push({
15494
+ indices: grand ? [0] : [index2, m],
15495
+ measure: m,
15496
+ ...grand ? { type: "grand" } : {}
15497
+ });
15498
+ });
15499
+ };
15500
+ rowItems.forEach((item, index2) => {
15501
+ const key = pivotValueKey(item);
15502
+ if (headings) {
15503
+ values2.push([label3(item), ...Array(dimensions.width - 1).fill(null)]);
15504
+ rowEntries.push({ indices: [index2] });
15505
+ indents.push(0);
15506
+ }
15507
+ append(
15508
+ label3(item),
15509
+ [
15510
+ ...columnItems.map(
15511
+ (col) => pivotNumbers(pivot, cells.get(JSON.stringify([key, pivotValueKey(col)])) ?? [])
15512
+ ),
15513
+ pivotNumbers(pivot, groups.get(key) ?? [])
15514
+ ],
15515
+ index2
15516
+ );
15517
+ });
15518
+ append(
15519
+ "Grand Total",
15520
+ [
15521
+ ...columnItems.map((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
15522
+ pivotNumbers(pivot, pivot.records)
15523
+ ],
15524
+ 0,
15525
+ true
15526
+ );
15527
+ return {
15528
+ values: values2,
15529
+ rowItems,
15530
+ columnItems,
15531
+ firstDataRow,
15532
+ rowLabelColumns: compact3 ? 1 : 2,
15533
+ indents,
15534
+ firstHeaderRow: 1,
15535
+ rowEntries
15536
+ };
15537
+ }
15218
15538
  for (const row2 of rowItems) {
15219
15539
  const records = groups.get(pivotValueKey(row2)) ?? [];
15220
15540
  values2.push([
15221
15541
  label3(row2),
15222
- ...columnItems.map(
15223
- (col) => aggregate2(
15224
- cells.get(JSON.stringify([pivotValueKey(row2), pivotValueKey(col)])) ?? [],
15225
- valueField,
15226
- pivot.aggregate
15542
+ ...columnItems.flatMap(
15543
+ (col) => pivotNumbers(
15544
+ pivot,
15545
+ cells.get(JSON.stringify([pivotValueKey(row2), pivotValueKey(col)])) ?? []
15227
15546
  )
15228
15547
  ),
15229
- aggregate2(records, valueField, pivot.aggregate)
15548
+ ...pivotNumbers(pivot, records)
15230
15549
  ]);
15231
15550
  }
15232
15551
  values2.push([
15233
15552
  "Grand Total",
15234
- ...columnItems.map(
15235
- (col) => aggregate2(columns.get(pivotValueKey(col)) ?? [], valueField, pivot.aggregate)
15236
- ),
15237
- aggregate2(pivot.records, valueField, pivot.aggregate)
15553
+ ...columnItems.flatMap((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
15554
+ ...pivotNumbers(pivot, pivot.records)
15238
15555
  ]);
15239
- return { values: values2, rowItems, columnItems, firstDataRow: pivot.columnField ? 2 : 1 };
15556
+ return { values: values2, rowItems, columnItems, firstDataRow };
15240
15557
  }
15241
15558
  function pivotTableAt(sheet, at) {
15242
15559
  return sheet.pivotTables?.find((pivot) => rangeContains(pivot.location, at));
@@ -15246,7 +15563,7 @@ function pivotTableAt(sheet, at) {
15246
15563
  var X14 = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main";
15247
15564
  var LAYOUT = "http://schemas.microsoft.com/office/spreadsheetml/2016/pivotdefaultlayout";
15248
15565
  var TABLE = {
15249
- pivotTableDefinition: "name cacheId dataCaption updatedVersion minRefreshableVersion createdVersion applyNumberFormats applyBorderFormats applyFontFormats applyPatternFormats applyAlignmentFormats applyWidthHeightFormats useAutoFormatting itemPrintTitles indent compact compactData outline outlineData multipleFieldFilters rowGrandTotals colGrandTotals",
15566
+ pivotTableDefinition: "name cacheId dataCaption dataOnRows dataPosition updatedVersion minRefreshableVersion createdVersion applyNumberFormats applyBorderFormats applyFontFormats applyPatternFormats applyAlignmentFormats applyWidthHeightFormats useAutoFormatting itemPrintTitles indent compact compactData outline outlineData multipleFieldFilters rowGrandTotals colGrandTotals",
15250
15567
  location: "ref firstHeaderRow firstDataRow firstDataCol",
15251
15568
  pivotFields: "count",
15252
15569
  pivotField: "axis dataField compact outline showAll subtotalTop defaultSubtotal",
@@ -15257,7 +15574,7 @@ var TABLE = {
15257
15574
  field: "x",
15258
15575
  rowItems: "count",
15259
15576
  colItems: "count",
15260
- i: "t r",
15577
+ i: "t r i",
15261
15578
  x: "v",
15262
15579
  dataFields: "count",
15263
15580
  dataField: "name fld subtotal baseField baseItem showDataAs",
@@ -15288,7 +15605,7 @@ function inspect(node, profile, cache3) {
15288
15605
  for (let i2 = 0; i2 < node.attributes.length; i2++) {
15289
15606
  const attr2 = node.attributes.item(i2);
15290
15607
  if (attr2.name.startsWith("xmlns")) continue;
15291
- if (!cache3 && node.namespaceURI === X14 && node.localName === "pivotTableDefinition" && attr2.name === "hideValuesRow" && attr2.value === "1")
15608
+ if (!cache3 && node.namespaceURI === X14 && node.localName === "pivotTableDefinition" && attr2.name === "hideValuesRow" && ["0", "1"].includes(attr2.value))
15292
15609
  continue;
15293
15610
  if (!cache3 && node.namespaceURI === X14 && (node.localName === "pivotField" && attr2.name === "fillDownLabels" || node.localName === "pivotTableDefinition" && attr2.name === "fillDownLabelsDefault") && ["0", "1"].includes(attr2.value))
15294
15611
  continue;
@@ -15317,7 +15634,9 @@ function inspect(node, profile, cache3) {
15317
15634
  throw new Error("Unsupported PivotTable option");
15318
15635
  if (attr2.localName === "numFmtId" && attr2.value !== "0")
15319
15636
  throw new Error("Unsupported PivotTable field number format");
15320
- if (node.localName === "pivotTableDefinition" && ["compact", "compactData", "outline", "outlineData"].includes(attr2.localName) && !["0", "1"].includes(attr2.value))
15637
+ if (node.localName === "pivotTableDefinition" && ["compact", "compactData", "outline", "outlineData", "dataOnRows"].includes(
15638
+ attr2.localName
15639
+ ) && !["0", "1"].includes(attr2.value))
15321
15640
  throw new Error("Unsupported PivotTable global layout");
15322
15641
  if (node.localName === "item" && attr2.localName === "t" && !["default", "data"].includes(attr2.value))
15323
15642
  throw new Error("Unsupported PivotTable subtotal");
@@ -15340,6 +15659,88 @@ function assertPivotRecords(records) {
15340
15659
  );
15341
15660
  }
15342
15661
 
15662
+ // xlsx/write/xml-out.ts
15663
+ var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
15664
+ var CONTROL2 = "\0-\b\v\f-" + String.fromCharCode(65534, 65535);
15665
+ var NEEDS_ESCAPE = new RegExp(`[${CONTROL2}\r]|_x[0-9A-Fa-f]{4}_`);
15666
+ var ESCAPABLE = new RegExp(`[${CONTROL2}\r]|_(?=x[0-9A-Fa-f]{4}_)`, "g");
15667
+ function encodeEscapes(text3) {
15668
+ if (!NEEDS_ESCAPE.test(text3)) return text3;
15669
+ return text3.replace(
15670
+ ESCAPABLE,
15671
+ (ch) => `_x${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}_`
15672
+ );
15673
+ }
15674
+ var INVALID_XML = new RegExp(`[${CONTROL2}]`, "g");
15675
+ var escapeText2 = (text3) => text3.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
15676
+ var escapeAttr3 = (text3) => text3.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;").replace(/\t/g, "&#9;");
15677
+ function attrs(values2) {
15678
+ let out = "";
15679
+ for (const [name, value2] of Object.entries(values2)) {
15680
+ if (value2 === void 0) continue;
15681
+ const text3 = typeof value2 === "boolean" ? value2 ? "1" : "0" : typeof value2 === "number" ? num2(value2) : value2;
15682
+ out += ` ${name}="${escapeAttr3(text3)}"`;
15683
+ }
15684
+ return out;
15685
+ }
15686
+ var el = (name, values2 = {}, content2 = "") => content2 ? `<${name}${attrs(values2)}>${content2}</${name}>` : `<${name}${attrs(values2)}/>`;
15687
+ var num2 = (value2) => Object.is(value2, -0) ? "0" : String(value2);
15688
+ function tElement(text3, name = "t") {
15689
+ const encoded = escapeText2(encodeEscapes(text3));
15690
+ const preserve = /^\s|\s$|\n|\t/.test(text3) ? ' xml:space="preserve"' : "";
15691
+ return `<${name}${preserve}>${encoded}</${name}>`;
15692
+ }
15693
+ var MAIN_NS = ' xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"';
15694
+ function inlineFragment(xml) {
15695
+ const end = xml.indexOf(">");
15696
+ if (end < 0) return xml;
15697
+ const head = xml.slice(0, end);
15698
+ return head.includes(MAIN_NS) ? head.replace(MAIN_NS, "") + xml.slice(end) : xml;
15699
+ }
15700
+
15701
+ // xlsx/pivot/values-axis.ts
15702
+ function pivotFieldIndex(field) {
15703
+ const raw2 = field?.getAttribute("x");
15704
+ if (raw2 === null || raw2 === void 0 || !/^-?\d+$/.test(raw2.trim())) return NaN;
15705
+ const value2 = Number(raw2);
15706
+ return Number.isSafeInteger(value2) ? value2 : NaN;
15707
+ }
15708
+ function pivotValueIndex(root, axis) {
15709
+ const index2 = axis.findIndex((field) => pivotFieldIndex(field) === -2);
15710
+ const position = root.getAttribute("dataPosition");
15711
+ if (position !== null && (!/^\d+$/.test(position.trim()) || Number(position) !== index2))
15712
+ throw new Error("Inconsistent Values axis position");
15713
+ if (axis.length === 3 && index2 < 2 && position === null)
15714
+ throw new Error("Missing leading or between-field Values position");
15715
+ return index2;
15716
+ }
15717
+ function pivotValueAxisItems(measures, columns) {
15718
+ const entries = [];
15719
+ if (columns === void 0) {
15720
+ for (let measure = 0; measure < measures; measure++)
15721
+ entries.push(
15722
+ `<i${attrs({ i: measure || void 0 })}><x${attrs({ v: measure || void 0 })}/></i>`
15723
+ );
15724
+ } else {
15725
+ for (let column = 0; column < columns; column++)
15726
+ for (let measure = 0; measure < measures; measure++) {
15727
+ entries.push(
15728
+ `<i${attrs({ r: measure ? 1 : void 0, i: measure || void 0 })}>${measure ? "" : `<x${attrs({ v: column || void 0 })}/>`}<x${attrs({ v: measure || void 0 })}/></i>`
15729
+ );
15730
+ }
15731
+ for (let measure = 0; measure < measures; measure++)
15732
+ entries.push(`<i${attrs({ t: "grand", i: measure || void 0 })}><x/></i>`);
15733
+ }
15734
+ return `<colItems count="${entries.length}">${entries.join("")}</colItems>`;
15735
+ }
15736
+ function supportedPivotAxes(rows, columns, measures, valuesOnRows) {
15737
+ const index2 = pivotFieldIndex;
15738
+ if (valuesOnRows)
15739
+ return measures > 1 && (rows.length === 2 || rows.length === 3) && (index2(rows[0]) >= 0 || rows.length === 3) && rows.filter((field) => index2(field) === -2).length === 1 && rows.filter((field) => index2(field) !== -2).every((field) => index2(field) >= 0) && columns.length <= 1 && (!columns.length || index2(columns[0]) >= 0);
15740
+ if (rows.some((field) => !Number.isInteger(index2(field)) || index2(field) < 0)) return false;
15741
+ return measures === 1 ? columns.length <= 1 : columns.length >= 1 && columns.length <= 2 && index2(columns.at(-1)) === -2 && (columns.length !== 2 || index2(columns[0]) >= 0);
15742
+ }
15743
+
15343
15744
  // xlsx/pivot/read.ts
15344
15745
  function value(node) {
15345
15746
  const v = att(node, "v") ?? "";
@@ -15374,6 +15775,7 @@ function readOne(workbook, source2, part) {
15374
15775
  const dataSheet = sourceNode && att(sourceNode, "sheet");
15375
15776
  const dataRange = sourceNode && parseRange(att(sourceNode, "ref") ?? "");
15376
15777
  const recordPart = source2.targetOfType(cachePart, `${NS.r}/pivotCacheRecords`);
15778
+ const rowsAxis = att(root, "dataOnRows") === "1";
15377
15779
  if (!dataSheet || !dataRange || !recordPart || !workbook.sheets.some((sheet) => sheet.name === dataSheet))
15378
15780
  throw new Error("Unsupported pivot source");
15379
15781
  assertPivotRecords(parseXml(source2.text(recordPart)).documentElement);
@@ -15409,17 +15811,42 @@ function readOne(workbook, source2, part) {
15409
15811
  "dataField",
15410
15812
  NS.x
15411
15813
  );
15412
- if (rowFields.length < 1 || rowFields.length > 2 || colFields.length > 1 || dataFields.length !== 1 || first(root, "pageFields", NS.x) || first(root, "filters", NS.x) || root.getAttribute("rowGrandTotals") === "0" || root.getAttribute("colGrandTotals") === "0")
15814
+ if (rowFields.length < 1 || rowFields.length > (rowsAxis ? 3 : 2) || dataFields.length < 1 || dataFields.length > 16 || !supportedPivotAxes(rowFields, colFields, dataFields.length, rowsAxis) || first(root, "pageFields", NS.x) || first(root, "filters", NS.x) || root.getAttribute("rowGrandTotals") === "0" || root.getAttribute("colGrandTotals") === "0")
15413
15815
  throw new Error("Unsupported pivot layout");
15816
+ const valueIndex = pivotValueIndex(root, rowsAxis ? rowFields : colFields);
15414
15817
  const measure = dataFields[0];
15818
+ const definition = elements(first(root, "extLst", NS.x) ?? parseXml("<root/>").documentElement).map(
15819
+ (extension) => first(
15820
+ extension,
15821
+ "pivotTableDefinition",
15822
+ "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
15823
+ )
15824
+ ).find(Boolean);
15825
+ if (dataFields.length > 1 && att(definition, "hideValuesRow") !== "1")
15826
+ throw new Error("Visible Values header rows are preserved");
15827
+ for (const [axis, count2] of [
15828
+ ["rowItems", rowsAxis ? dataFields.length : 1],
15829
+ ["colItems", rowsAxis ? 1 : dataFields.length]
15830
+ ]) {
15831
+ for (const item of children(
15832
+ first(root, axis, NS.x) ?? parseXml("<root/>").documentElement,
15833
+ "i",
15834
+ NS.x
15835
+ )) {
15836
+ const index2 = Number(att(item, "i") ?? "0");
15837
+ if (!Number.isInteger(index2) || index2 < 0 || index2 >= count2)
15838
+ throw new Error("Unsupported Values axis item");
15839
+ }
15840
+ }
15415
15841
  const aggregate3 = att(measure, "subtotal") ?? "sum";
15416
15842
  if (!PIVOT_AGGREGATES.includes(aggregate3) || att(measure, "showDataAs") && att(measure, "showDataAs") !== "normal")
15417
15843
  throw new Error("Unsupported pivot aggregate");
15418
15844
  const names = fields.map((field) => decodeEscapes(att(field, "name") ?? ""));
15419
- const row2 = names[Number(att(rowFields[0], "x"))];
15420
- const second = rowFields[1] && names[Number(att(rowFields[1], "x"))];
15845
+ const realRows = rowsAxis ? rowFields.filter((field) => pivotFieldIndex(field) !== -2) : rowFields;
15846
+ const row2 = names[pivotFieldIndex(realRows[0])];
15847
+ const second = realRows[1] ? names[Number(att(realRows[1], "x"))] : void 0;
15421
15848
  const tableFields = children(first(root, "pivotFields", NS.x), "pivotField", NS.x);
15422
- const outer = tableFields[Number(att(rowFields[0], "x"))];
15849
+ const outer = tableFields[pivotFieldIndex(realRows[0])];
15423
15850
  const compact3 = att(outer, "compact") !== "0";
15424
15851
  const outline = att(outer, "outline") !== "0";
15425
15852
  const layout2 = compact3 ? "compact" : outline ? "outline" : "tabular";
@@ -15428,7 +15855,7 @@ function readOne(workbook, source2, part) {
15428
15855
  ) || att(root, "compact") !== "0" !== compact3 || att(root, "compactData") !== "0" !== compact3 || att(root, "outline") === "1" !== outline || att(root, "outlineData") === "1" !== outline || layout2 === "compact" && att(root, "indent") !== "0")
15429
15856
  throw new Error("Mixed field layouts or custom compact indentation are preserved");
15430
15857
  const subtotal = att(outer, "defaultSubtotal") !== "0";
15431
- const repeat = rowFields.map((field) => {
15858
+ const repeat = realRows.map((field) => {
15432
15859
  const node = tableFields[Number(att(field, "x"))];
15433
15860
  const extension = first(first(node, "extLst", NS.x), "ext", NS.x);
15434
15861
  return att(
@@ -15441,16 +15868,19 @@ function readOne(workbook, source2, part) {
15441
15868
  ) === "1";
15442
15869
  });
15443
15870
  if (repeat.some((entry4) => entry4 !== repeat[0])) throw new Error("Mixed field label repetition");
15444
- const col = colFields[0] && names[Number(att(colFields[0], "x"))];
15871
+ const hasColumn = colFields.length > (dataFields.length > 1 && !rowsAxis ? 1 : 0);
15872
+ const col = hasColumn ? names[Number(att(colFields[0], "x"))] : void 0;
15445
15873
  const data = names[Number(att(measure, "fld"))];
15446
15874
  const location = parseRange(att(first(root, "location", NS.x), "ref") ?? "");
15447
- if (!row2 || !data || !location || colFields.length && !col || rowFields.length === 2 && !second)
15875
+ if (!row2 || !data || !location || hasColumn && !col || realRows.length === 2 && !second)
15448
15876
  throw new Error("Invalid pivot fields");
15449
15877
  const pivot = {
15450
15878
  name: att(root, "name") ?? "PivotTable",
15451
15879
  source: `${quoteSheetName(dataSheet)}!${formatRange(dataRange)}`,
15452
15880
  rowField: row2,
15453
15881
  layout: layout2,
15882
+ ...rowsAxis ? { valuesAxis: "rows" } : {},
15883
+ ...rowsAxis && realRows.length === 2 && valueIndex < 2 ? { valuesPosition: valueIndex === 0 ? "first" : "between" } : {},
15454
15884
  subtotalPosition: att(outer, "subtotalTop") === "0" ? "bottom" : "top",
15455
15885
  ...second ? { secondRowField: second, subtotals: subtotal, repeatLabels: repeat[0] ?? false } : {
15456
15886
  ...subtotal ? {} : { subtotals: false },
@@ -15459,6 +15889,15 @@ function readOne(workbook, source2, part) {
15459
15889
  valueField: data,
15460
15890
  aggregate: aggregate3,
15461
15891
  valueCaption: decodeEscapes(att(measure, "name") ?? data),
15892
+ ...dataFields.length > 1 ? {
15893
+ additionalValues: dataFields.slice(1).map((measure2) => {
15894
+ const field = names[Number(att(measure2, "fld"))];
15895
+ const aggregate4 = att(measure2, "subtotal") ?? "sum";
15896
+ if (!field || !PIVOT_AGGREGATES.includes(aggregate4) || att(measure2, "showDataAs") && att(measure2, "showDataAs") !== "normal")
15897
+ throw new Error("Unsupported pivot measure");
15898
+ return { field, aggregate: aggregate4, caption: decodeEscapes(att(measure2, "name") ?? field) };
15899
+ })
15900
+ } : {},
15462
15901
  fields: names,
15463
15902
  records,
15464
15903
  location,
@@ -18987,45 +19426,6 @@ function readDataValidations(node) {
18987
19426
  return out;
18988
19427
  }
18989
19428
 
18990
- // xlsx/write/xml-out.ts
18991
- var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
18992
- var CONTROL2 = "\0-\b\v\f-" + String.fromCharCode(65534, 65535);
18993
- var NEEDS_ESCAPE = new RegExp(`[${CONTROL2}\r]|_x[0-9A-Fa-f]{4}_`);
18994
- var ESCAPABLE = new RegExp(`[${CONTROL2}\r]|_(?=x[0-9A-Fa-f]{4}_)`, "g");
18995
- function encodeEscapes(text3) {
18996
- if (!NEEDS_ESCAPE.test(text3)) return text3;
18997
- return text3.replace(
18998
- ESCAPABLE,
18999
- (ch) => `_x${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}_`
19000
- );
19001
- }
19002
- var INVALID_XML = new RegExp(`[${CONTROL2}]`, "g");
19003
- var escapeText2 = (text3) => text3.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
19004
- var escapeAttr3 = (text3) => text3.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;").replace(/\t/g, "&#9;");
19005
- function attrs(values2) {
19006
- let out = "";
19007
- for (const [name, value2] of Object.entries(values2)) {
19008
- if (value2 === void 0) continue;
19009
- const text3 = typeof value2 === "boolean" ? value2 ? "1" : "0" : typeof value2 === "number" ? num2(value2) : value2;
19010
- out += ` ${name}="${escapeAttr3(text3)}"`;
19011
- }
19012
- return out;
19013
- }
19014
- var el = (name, values2 = {}, content2 = "") => content2 ? `<${name}${attrs(values2)}>${content2}</${name}>` : `<${name}${attrs(values2)}/>`;
19015
- var num2 = (value2) => Object.is(value2, -0) ? "0" : String(value2);
19016
- function tElement(text3, name = "t") {
19017
- const encoded = escapeText2(encodeEscapes(text3));
19018
- const preserve = /^\s|\s$|\n|\t/.test(text3) ? ' xml:space="preserve"' : "";
19019
- return `<${name}${preserve}>${encoded}</${name}>`;
19020
- }
19021
- var MAIN_NS = ' xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"';
19022
- function inlineFragment(xml) {
19023
- const end = xml.indexOf(">");
19024
- if (end < 0) return xml;
19025
- const head = xml.slice(0, end);
19026
- return head.includes(MAIN_NS) ? head.replace(MAIN_NS, "") + xml.slice(end) : xml;
19027
- }
19028
-
19029
19429
  // xlsx/conditional-extensions.ts
19030
19430
  var XM = "http://schemas.microsoft.com/office/excel/2006/main";
19031
19431
  var URI = "{78C0D931-6437-407d-A8EE-F0AAD7539E65}";
@@ -25494,7 +25894,9 @@ function pivotTableXml(pivot, cacheId, cache3) {
25494
25894
  const row2 = pivot.fields.indexOf(pivot.rowField);
25495
25895
  const second = pivot.secondRowField ? pivot.fields.indexOf(pivot.secondRowField) : -1;
25496
25896
  const col = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
25497
- const value2 = pivot.fields.indexOf(pivot.valueField);
25897
+ const measures = pivotMeasures(pivot);
25898
+ const multiple = measures.length > 1;
25899
+ const rowsAxis = pivot.valuesAxis === "rows";
25498
25900
  const compact3 = pivot.layout === "compact";
25499
25901
  const outline = pivot.layout === "compact" || pivot.layout === "outline";
25500
25902
  const top = (pivot.subtotalPosition ?? (outline ? "top" : "bottom")) === "top";
@@ -25502,36 +25904,61 @@ function pivotTableXml(pivot, cacheId, cache3) {
25502
25904
  const items2 = index2 === row2 ? grid.rowItems : index2 === second ? grid.secondRowItems : index2 === col ? grid.columnItems : void 0;
25503
25905
  const subtotal = !(index2 === row2 && pivot.subtotals === false);
25504
25906
  const repeated = pivot.repeatLabels && (index2 === row2 || index2 === second) ? '<extLst><ext uri="{2946ED86-A175-432a-8AC1-64E0C546D7DE}"><x14:pivotField xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" fillDownLabels="1"/></ext></extLst>' : "";
25505
- return `<pivotField${attrs({ axis: index2 === row2 || index2 === second ? "axisRow" : index2 === col ? "axisCol" : void 0, dataField: index2 === value2 ? true : void 0, compact: compact3, outline, showAll: false, subtotalTop: index2 === row2 ? top : void 0, defaultSubtotal: subtotal ? void 0 : false })}>${items2 ? `<items count="${items2.length + Number(subtotal)}">${items2.map((item) => `<item x="${cache3.indices[index2].get(pivotValueKey(item))}"/>`).join("")}${subtotal ? '<item t="default"/>' : ""}</items>` : ""}${repeated}</pivotField>`;
25907
+ return `<pivotField${attrs({ axis: index2 === row2 || index2 === second ? "axisRow" : index2 === col ? "axisCol" : void 0, dataField: measures.some((measure) => pivot.fields.indexOf(measure.field) === index2) ? true : void 0, compact: compact3, outline, showAll: false, subtotalTop: index2 === row2 ? top : void 0, defaultSubtotal: subtotal ? void 0 : false })}>${items2 ? `<items count="${items2.length + Number(subtotal)}">${items2.map((item) => `<item x="${cache3.indices[index2].get(pivotValueKey(item))}"/>`).join("")}${subtotal ? '<item t="default"/>' : ""}</items>` : ""}${repeated}</pivotField>`;
25506
25908
  }).join("");
25507
25909
  const items = (count2) => Array.from({ length: count2 }, (_v, i2) => `<i><x v="${i2}"/></i>`).join("") + '<i t="grand"><x/></i>';
25508
- const header = grid.firstDataRow - 1;
25509
- const rowIndices = [row2, ...second >= 0 ? [second] : []];
25910
+ const header = grid.firstHeaderRow ?? (multiple && col >= 0 ? 1 : grid.firstDataRow - 1);
25911
+ const rowIndices = rowsAxis && pivot.valuesPosition === "first" ? [-2, row2, second] : rowsAxis && pivot.valuesPosition === "between" ? [row2, -2, second] : [row2, ...second >= 0 ? [second] : [], ...rowsAxis ? [-2] : []];
25510
25912
  let previous = [];
25511
25913
  const rowItems = grid.rowEntries?.map((entry3) => {
25512
25914
  let prefix = 0;
25513
- if (!entry3.type)
25915
+ if (entry3.type === "default" && rowsAxis && pivot.valuesPosition === "first") prefix = 1;
25916
+ else if (!entry3.type)
25514
25917
  while (prefix < entry3.indices.length - 1 && entry3.indices[prefix] === previous[prefix])
25515
25918
  prefix++;
25516
- previous = entry3.type ? [] : entry3.indices;
25517
- return `<i${attrs({ t: entry3.type, r: prefix || void 0 })}>${entry3.indices.slice(prefix).map((index2) => `<x${attrs({ v: index2 || void 0 })}/>`).join("")}</i>`;
25919
+ previous = entry3.type && !(entry3.type === "default" && pivot.valuesPosition === "first") ? [] : entry3.indices;
25920
+ return `<i${attrs({ t: entry3.type, r: prefix || void 0, i: entry3.measure || void 0 })}>${entry3.indices.slice(prefix).map((index2) => `<x${attrs({ v: index2 || void 0 })}/>`).join("")}</i>`;
25518
25921
  }).join("") ?? items(grid.rowItems.length);
25519
25922
  let body = `<location${attrs({ ref: formatRange(pivot.location), firstHeaderRow: header, firstDataRow: grid.firstDataRow, firstDataCol: grid.rowLabelColumns ?? 1 })}/><pivotFields count="${pivot.fields.length}">${fields}</pivotFields><rowFields count="${rowIndices.length}">${rowIndices.map((index2) => `<field x="${index2}"/>`).join("")}</rowFields><rowItems count="${grid.rowEntries?.length ?? grid.rowItems.length + 1}">${rowItems}</rowItems>`;
25520
- if (col >= 0)
25923
+ if (multiple && !rowsAxis)
25924
+ body += `<colFields count="${col >= 0 ? 2 : 1}">${col >= 0 ? `<field x="${col}"/>` : ""}<field x="-2"/></colFields>${pivotValueAxisItems(measures.length, col >= 0 ? grid.columnItems.length : void 0)}`;
25925
+ else if (col >= 0)
25521
25926
  body += `<colFields count="1"><field x="${col}"/></colFields><colItems count="${grid.columnItems.length + 1}">${items(grid.columnItems.length)}</colItems>`;
25522
- else body += '<colItems count="1"><i><x/></i></colItems>';
25523
- body += `<dataFields count="1"><dataField${attrs({ name: encodeEscapes(pivot.valueCaption), fld: value2, subtotal: pivot.aggregate, baseField: 0, baseItem: 0 })}/></dataFields>`;
25927
+ else
25928
+ body += rowsAxis ? '<colItems count="1"><i/></colItems>' : '<colItems count="1"><i><x/></i></colItems>';
25929
+ body += `<dataFields count="${measures.length}">${measures.map((measure) => `<dataField${attrs({ name: encodeEscapes(measure.caption), fld: pivot.fields.indexOf(measure.field), subtotal: measure.aggregate, baseField: 0, baseItem: 0 })}/>`).join("")}</dataFields>`;
25524
25930
  const doc = parseXml(
25525
25931
  pivot.sourceXml ?? `<pivotTableDefinition xmlns="${NS.x}" dataCaption="Values" updatedVersion="6" minRefreshableVersion="3" createdVersion="6"><pivotTableStyleInfo name="PivotStyleLight16" showRowHeaders="1" showColHeaders="1" showRowStripes="0" showColStripes="0" showLastColumn="1"/></pivotTableDefinition>`
25526
25932
  );
25527
25933
  const root = doc.documentElement;
25528
25934
  root.setAttribute("name", pivot.name);
25529
25935
  root.setAttribute("cacheId", String(cacheId));
25936
+ root.setAttribute("dataOnRows", rowsAxis ? "1" : "0");
25937
+ if (rowsAxis && (pivot.valuesPosition === "between" || pivot.valuesPosition === "first"))
25938
+ root.setAttribute("dataPosition", pivot.valuesPosition === "first" ? "0" : "1");
25939
+ else root.removeAttribute("dataPosition");
25530
25940
  root.setAttribute("compact", compact3 ? "1" : "0");
25531
25941
  root.setAttribute("compactData", compact3 ? "1" : "0");
25532
25942
  root.setAttribute("outline", outline ? "1" : "0");
25533
25943
  root.setAttribute("outlineData", outline ? "1" : "0");
25534
25944
  if (compact3) root.setAttribute("indent", "0");
25945
+ if (multiple && !elements(first(root, "extLst", NS.x) ?? parseXml("<root/>").documentElement).some(
25946
+ (extension) => first(
25947
+ extension,
25948
+ "pivotTableDefinition",
25949
+ "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
25950
+ )
25951
+ )) {
25952
+ let list = first(root, "extLst", NS.x);
25953
+ if (!list) {
25954
+ list = doc.createElementNS(NS.x, "extLst");
25955
+ root.appendChild(list);
25956
+ }
25957
+ const extension = parseXml(
25958
+ `<ext xmlns="${NS.x}" uri="{962EF5D1-5CA2-4c93-8EF4-DBF5C05439D2}"><x14:pivotTableDefinition xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" hideValuesRow="1"/></ext>`
25959
+ ).documentElement;
25960
+ list.appendChild(doc.importNode(extension, true));
25961
+ }
25535
25962
  root.setAttribute("rowGrandTotals", "1");
25536
25963
  root.setAttribute("colGrandTotals", "1");
25537
25964
  for (const extension of elements(
@@ -25542,6 +25969,7 @@ function pivotTableXml(pivot, cacheId, cache3) {
25542
25969
  "pivotTableDefinition",
25543
25970
  "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
25544
25971
  );
25972
+ if (multiple && definition) definition.setAttribute("hideValuesRow", "1");
25545
25973
  if (definition?.hasAttribute("fillDownLabelsDefault"))
25546
25974
  definition.setAttribute("fillDownLabelsDefault", pivot.repeatLabels ? "1" : "0");
25547
25975
  }
@@ -29765,12 +30193,16 @@ function write(ctx, s, pivot, old) {
29765
30193
  ],
29766
30194
  () => {
29767
30195
  const compact3 = pivot.layout === "compact";
29768
- const indents = [
29769
- stylePatcher(ctx.workbook, {
29770
- alignment: { indent: 0, ...compact3 ? { horizontal: "left" } : {} }
29771
- }),
29772
- stylePatcher(ctx.workbook, { alignment: { indent: 1, horizontal: "left" } })
29773
- ];
30196
+ const indents = new Map(
30197
+ [.../* @__PURE__ */ new Set([0, ...grid.indents ?? []])].map(
30198
+ (indent) => [
30199
+ indent,
30200
+ stylePatcher(ctx.workbook, {
30201
+ alignment: { indent, ...compact3 || indent > 0 ? { horizontal: "left" } : {} }
30202
+ })
30203
+ ]
30204
+ )
30205
+ );
29774
30206
  const styles = /* @__PURE__ */ new Map();
29775
30207
  forEachCellInRange(sheet, location, (cell, row2, col) => {
29776
30208
  if (cell.styleId !== void 0) styles.set(`${row2}:${col}`, cell.styleId);
@@ -29793,7 +30225,7 @@ function write(ctx, s, pivot, old) {
29793
30225
  const indent = col === 0 ? grid.indents?.[row2] ?? 0 : 0;
29794
30226
  const alignment = styleAt(ctx.workbook, styleId).alignment;
29795
30227
  if ((alignment?.indent ?? 0) !== indent || compact3 && alignment?.horizontal !== "left")
29796
- styleId = indents[indent](styleId);
30228
+ styleId = indents.get(indent)(styleId);
29797
30229
  }
29798
30230
  putCell(sheet, r, c2, { value: value2, ...styleId !== void 0 ? { styleId } : {} });
29799
30231
  })
@@ -29820,6 +30252,9 @@ function createPivotTable(ctx, s, destination, options) {
29820
30252
  valueField: options.valueField,
29821
30253
  aggregate: aggregate3,
29822
30254
  valueCaption: pivotCaption(aggregate3, options.valueField),
30255
+ ...options.valuesAxis !== void 0 ? { valuesAxis: options.valuesAxis } : {},
30256
+ ...options.valuesPosition !== void 0 ? { valuesPosition: options.valuesPosition } : {},
30257
+ ...options.additionalValues ? { additionalValues: normalizedPivotMeasures(options.additionalValues) } : {},
29823
30258
  location: { start: { ...destination }, end: { ...destination } },
29824
30259
  ...options.columnField ? { columnField: options.columnField } : {}
29825
30260
  };
@@ -29851,6 +30286,15 @@ function refreshPivotTable(ctx, s, name, patch3 = {}) {
29851
30286
  if (patch3.repeatLabels !== void 0) next.repeatLabels = patch3.repeatLabels;
29852
30287
  if (patch3.layout !== void 0) next.layout = patch3.layout;
29853
30288
  if (patch3.subtotalPosition !== void 0) next.subtotalPosition = patch3.subtotalPosition;
30289
+ if (patch3.valuesAxis !== void 0) next.valuesAxis = patch3.valuesAxis;
30290
+ if (patch3.valuesPosition !== void 0) next.valuesPosition = patch3.valuesPosition;
30291
+ else if (patch3.valuesAxis === "columns" || patch3.secondRowField === "")
30292
+ delete next.valuesPosition;
30293
+ if (patch3.additionalValues !== void 0) {
30294
+ const measures = normalizedPivotMeasures(patch3.additionalValues);
30295
+ if (measures.length) next.additionalValues = measures;
30296
+ else delete next.additionalValues;
30297
+ }
29854
30298
  validatePivotFields(next);
29855
30299
  write(ctx, s, next, old);
29856
30300
  }