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
@@ -15039,6 +15039,25 @@ function validatePivotFields(pivot) {
15039
15039
  ...pivot.columnField ? [pivot.columnField] : [],
15040
15040
  pivot.valueField
15041
15041
  ];
15042
+ const extras = pivot.additionalValues ?? [];
15043
+ if (pivot.valuesAxis !== void 0 && !["columns", "rows"].includes(pivot.valuesAxis))
15044
+ throw new Error("Choose a valid Values axis.");
15045
+ if (pivot.valuesPosition !== void 0 && !["last", "between", "first"].includes(pivot.valuesPosition))
15046
+ throw new Error("Choose a valid Values position.");
15047
+ if ((pivot.valuesPosition === "between" || pivot.valuesPosition === "first") && (pivot.valuesAxis !== "rows" || !pivot.secondRowField))
15048
+ throw new Error("Values before or between fields require two row fields and Values on rows.");
15049
+ if (pivot.valuesAxis === "rows" && (!Array.isArray(extras) || !extras.length))
15050
+ throw new Error("Values on rows require multiple measures.");
15051
+ if (extras.length > 0 && pivot.sourceXml && parseXml(pivot.sourceXml).documentElement.getAttribute("dataCaption") !== "Values")
15052
+ throw new Error("This PivotTable uses unsupported Values header captions.");
15053
+ if (!Array.isArray(extras) || extras.length > 15 || extras.some(
15054
+ (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())
15055
+ ) || new Set(
15056
+ [pivot.valueCaption, ...extras.map((measure) => measure.caption)].map(
15057
+ (caption) => caption?.toLowerCase()
15058
+ )
15059
+ ).size !== extras.length + 1)
15060
+ throw new Error("Choose PivotTable value fields with valid aggregates and unique captions.");
15042
15061
  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")
15043
15062
  throw new Error("Choose valid PivotTable fields; row and column fields must differ.");
15044
15063
  }
@@ -15046,21 +15065,191 @@ function pivotCaption(aggregate3, field) {
15046
15065
  return `${aggregate3[0].toUpperCase()}${aggregate3.slice(1)} of ${field}`;
15047
15066
  }
15048
15067
 
15068
+ // xlsx/pivot/measures.ts
15069
+ var pivotMeasures = (pivot) => [
15070
+ { field: pivot.valueField, aggregate: pivot.aggregate, caption: pivot.valueCaption },
15071
+ ...pivot.additionalValues ?? []
15072
+ ];
15073
+ function normalizedPivotMeasures(values2) {
15074
+ if (!Array.isArray(values2) || values2.length > 15)
15075
+ throw new Error("Choose between one and sixteen PivotTable value fields.");
15076
+ return values2.map((value2) => {
15077
+ if (!value2 || typeof value2.field !== "string")
15078
+ throw new Error("Choose valid PivotTable value fields.");
15079
+ const aggregate3 = value2.aggregate ?? "sum";
15080
+ if (!PIVOT_AGGREGATES.includes(aggregate3))
15081
+ throw new Error("Choose a valid PivotTable aggregate.");
15082
+ return {
15083
+ field: value2.field,
15084
+ aggregate: aggregate3,
15085
+ caption: value2.caption ?? `${aggregate3[0].toUpperCase()}${aggregate3.slice(1)} of ${value2.field}`
15086
+ };
15087
+ });
15088
+ }
15089
+ function aggregate2(records, field, type) {
15090
+ if (!records.length) return null;
15091
+ const values2 = records.map((record) => record[field] ?? null);
15092
+ if (type === "count") return values2.filter((value2) => value2 !== null && value2 !== "").length;
15093
+ const error = values2.find(isCellError);
15094
+ if (error) return error;
15095
+ const numbers3 = values2.filter((value2) => typeof value2 === "number");
15096
+ if (!numbers3.length) return type === "average" ? { error: "#DIV/0!" } : 0;
15097
+ if (type === "min") return numbers3.reduce((a2, b) => Math.min(a2, b));
15098
+ if (type === "max") return numbers3.reduce((a2, b) => Math.max(a2, b));
15099
+ const sum2 = numbers3.reduce((total2, value2) => total2 + value2, 0);
15100
+ return type === "average" ? sum2 / numbers3.length : sum2;
15101
+ }
15102
+ var pivotMeasureNumber = (pivot, records, measure) => aggregate2(records, pivot.fields.indexOf(measure.field), measure.aggregate);
15103
+ var pivotNumbers = (pivot, records) => pivotMeasures(pivot).map((measure) => pivotMeasureNumber(pivot, records, measure));
15104
+ function pivotHeaderDimensions(pivot, columnItems, rowLabels) {
15105
+ const measures = 1 + (pivot.additionalValues?.length ?? 0);
15106
+ if (pivot.valuesAxis === "rows")
15107
+ return {
15108
+ rows: pivot.columnField ? 2 : 1,
15109
+ width: rowLabels + (pivot.columnField ? columnItems + 1 : 1)
15110
+ };
15111
+ return {
15112
+ rows: pivot.columnField ? measures > 1 ? 3 : 2 : 1,
15113
+ width: rowLabels + (pivot.columnField ? measures === 1 ? Math.max(1, columnItems) + 1 : (columnItems + 1) * measures : measures)
15114
+ };
15115
+ }
15116
+ function pivotHeaders(pivot, columns, labels, label3) {
15117
+ const measures = pivotMeasures(pivot);
15118
+ if (pivot.valuesAxis === "rows") {
15119
+ const rowLabels = pivot.layout === "compact" ? ["Row Labels"] : pivot.valuesPosition === "first" ? ["Values", ...labels] : pivot.valuesPosition === "between" ? [labels[0], "Values", labels[1]] : [...labels, "Values"];
15120
+ return pivot.columnField ? [
15121
+ [
15122
+ ...rowLabels.map(() => null),
15123
+ pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
15124
+ ...columns.map(() => null)
15125
+ ],
15126
+ [...rowLabels, ...columns.map(label3), "Grand Total"]
15127
+ ] : [[...rowLabels, null]];
15128
+ }
15129
+ if (!pivot.columnField) return [[...labels, ...measures.map((measure) => measure.caption)]];
15130
+ if (measures.length === 1)
15131
+ return [
15132
+ [
15133
+ pivot.valueCaption,
15134
+ ...labels.slice(1).map(() => null),
15135
+ pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
15136
+ ...columns.slice(1).map(() => null),
15137
+ null
15138
+ ],
15139
+ [...labels, ...columns.map(label3), "Grand Total"]
15140
+ ];
15141
+ const { width } = pivotHeaderDimensions(pivot, columns.length, labels.length);
15142
+ const first2 = Array(width).fill(null);
15143
+ first2[labels.length] = pivot.layout === "compact" ? "Column Labels" : pivot.columnField;
15144
+ if (pivot.layout !== "compact") first2[labels.length + 1] = "Values";
15145
+ return [
15146
+ first2,
15147
+ [
15148
+ ...labels.map(() => null),
15149
+ ...columns.flatMap((column) => [label3(column), ...measures.slice(1).map(() => null)]),
15150
+ ...measures.map((measure) => `Total ${measure.caption}`)
15151
+ ],
15152
+ [
15153
+ ...labels,
15154
+ ...columns.flatMap(() => measures.map((measure) => measure.caption)),
15155
+ ...measures.map(() => null)
15156
+ ]
15157
+ ];
15158
+ }
15159
+
15160
+ // xlsx/pivot/hierarchy-first.ts
15161
+ function appendFirstPivotValues(pivot, context) {
15162
+ const {
15163
+ rowItems,
15164
+ secondRowItems,
15165
+ columnItems,
15166
+ children: children2,
15167
+ innerIndices,
15168
+ groups,
15169
+ details,
15170
+ buckets,
15171
+ width,
15172
+ rowLabels,
15173
+ top,
15174
+ bottom,
15175
+ append
15176
+ } = context;
15177
+ const compact3 = pivot.layout === "compact";
15178
+ const tabular = !pivot.layout || pivot.layout === "tabular";
15179
+ const blank = () => Array(width - rowLabels).fill(null);
15180
+ pivotMeasures(pivot).forEach((measure, m) => {
15181
+ const numbers3 = (keys, records) => [
15182
+ ...columnItems.map(
15183
+ (column) => pivotMeasureNumber(
15184
+ pivot,
15185
+ buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
15186
+ measure
15187
+ )
15188
+ ),
15189
+ pivotMeasureNumber(pivot, records, measure)
15190
+ ];
15191
+ if (!tabular)
15192
+ append([measure.caption, ...Array(rowLabels - 1).fill(null)], blank(), {
15193
+ indices: [m],
15194
+ measure: m
15195
+ });
15196
+ let first2 = true;
15197
+ rowItems.forEach((outer, outerIndex) => {
15198
+ const key = pivotValueKey(outer);
15199
+ const group = groups.get(key) ?? [];
15200
+ if (!tabular)
15201
+ append(
15202
+ compact3 ? [pivotItemLabel(outer)] : [null, pivotItemLabel(outer), null],
15203
+ top ? numbers3([key], group) : blank(),
15204
+ { indices: [m, outerIndex], measure: m },
15205
+ compact3 ? 1 : 0
15206
+ );
15207
+ const innerKeys = [...children2.get(key)].sort(
15208
+ (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
15209
+ );
15210
+ innerKeys.forEach((innerKey, child3) => {
15211
+ const innerIndex = innerIndices.get(innerKey);
15212
+ append(
15213
+ compact3 ? [pivotItemLabel(secondRowItems[innerIndex])] : [
15214
+ tabular && first2 ? measure.caption : null,
15215
+ pivot.repeatLabels || tabular && child3 === 0 ? pivotItemLabel(outer) : null,
15216
+ pivotItemLabel(secondRowItems[innerIndex])
15217
+ ],
15218
+ numbers3([key, innerKey], details.get(JSON.stringify([key, innerKey]))),
15219
+ { indices: [m, outerIndex, innerIndex], measure: m },
15220
+ compact3 ? 2 : 0
15221
+ );
15222
+ first2 = false;
15223
+ });
15224
+ if (bottom)
15225
+ append(
15226
+ compact3 ? [`${String(pivotItemLabel(outer))} Total`] : [null, `${String(pivotItemLabel(outer))} Total`, null],
15227
+ numbers3([key], group),
15228
+ { indices: [m, outerIndex], measure: m, type: "default" },
15229
+ compact3 ? 1 : 0
15230
+ );
15231
+ });
15232
+ });
15233
+ }
15234
+
15049
15235
  // xlsx/pivot/hierarchy.ts
15050
15236
  var label2 = pivotItemLabel;
15051
- function hierarchicalPivotGrid(pivot, aggregate3) {
15237
+ function hierarchicalPivotGrid(pivot) {
15052
15238
  const rowItems = pivotItems(pivot, pivot.rowField);
15053
15239
  const secondRowItems = pivotItems(pivot, pivot.secondRowField);
15054
15240
  const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
15055
15241
  const outerField = pivot.fields.indexOf(pivot.rowField);
15056
15242
  const innerField = pivot.fields.indexOf(pivot.secondRowField);
15057
15243
  const columnField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
15058
- const valueField = pivot.fields.indexOf(pivot.valueField);
15059
15244
  const layout2 = pivot.layout ?? "tabular";
15060
15245
  const compact3 = layout2 === "compact";
15061
- const top = layout2 !== "tabular" && pivot.subtotals !== false && (pivot.subtotalPosition ?? "top") === "top";
15246
+ const rowsAxis = pivot.valuesAxis === "rows";
15247
+ const firstValues = rowsAxis && pivot.valuesPosition === "first";
15248
+ const between = rowsAxis && pivot.valuesPosition === "between";
15249
+ const measures = pivotMeasures(pivot);
15250
+ const top = (!rowsAxis || firstValues) && layout2 !== "tabular" && pivot.subtotals !== false && (pivot.subtotalPosition ?? "top") === "top";
15062
15251
  const bottom = pivot.subtotals !== false && !top;
15063
- const rowLabelColumns = compact3 ? 1 : 2;
15252
+ const rowLabelColumns = compact3 ? 1 : rowsAxis ? 3 : 2;
15064
15253
  const groups = /* @__PURE__ */ new Map();
15065
15254
  const details = /* @__PURE__ */ new Map();
15066
15255
  const children2 = /* @__PURE__ */ new Map();
@@ -15084,20 +15273,12 @@ function hierarchicalPivotGrid(pivot, aggregate3) {
15084
15273
  collect2(buckets, JSON.stringify([...key, column]), record);
15085
15274
  }
15086
15275
  }
15087
- const rows = details.size + rowItems.length * (Number(layout2 !== "tabular") + Number(bottom)) + 3;
15088
- if (rows * (columnItems.length + 3) > 1e6)
15089
- throw new Error("The PivotTable result is too large.");
15276
+ const dimensions = pivotHeaderDimensions(pivot, columnItems.length, rowLabelColumns);
15277
+ 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;
15278
+ if (rows * dimensions.width > 1e6) throw new Error("The PivotTable result is too large.");
15090
15279
  const labels = compact3 ? ["Row Labels"] : [pivot.rowField, pivot.secondRowField];
15091
- const values2 = pivot.columnField ? [
15092
- [
15093
- pivot.valueCaption,
15094
- ...compact3 ? [] : [null],
15095
- compact3 ? "Column Labels" : pivot.columnField,
15096
- ...columnItems.slice(1).map(() => null),
15097
- null
15098
- ],
15099
- [...labels, ...columnItems.map(label2), "Grand Total"]
15100
- ] : [[...labels, pivot.valueCaption]];
15280
+ const values2 = pivotHeaders(pivot, columnItems, labels, label2);
15281
+ const firstDataRow = values2.length;
15101
15282
  const indents = values2.map(() => 0);
15102
15283
  const rowEntries = [];
15103
15284
  const append = (labels2, numbers4, entry3, indent = 0) => {
@@ -15105,91 +15286,184 @@ function hierarchicalPivotGrid(pivot, aggregate3) {
15105
15286
  rowEntries.push(entry3);
15106
15287
  indents.push(indent);
15107
15288
  };
15108
- const numbers3 = (keys, records) => [
15289
+ const bands = (keys, records) => [
15109
15290
  ...columnItems.map(
15110
- (column) => aggregate3(
15111
- buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
15112
- valueField,
15113
- pivot.aggregate
15114
- )
15291
+ (column) => pivotNumbers(pivot, buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [])
15115
15292
  ),
15116
- aggregate3(records, valueField, pivot.aggregate)
15293
+ pivotNumbers(pivot, records)
15117
15294
  ];
15118
- rowItems.forEach((outer, outerIndex) => {
15119
- const key = pivotValueKey(outer);
15120
- if (layout2 !== "tabular")
15121
- append(
15122
- [label2(outer), ...compact3 ? [] : [null]],
15123
- top ? numbers3([key], groups.get(key) ?? []) : Array(columnItems.length + 1).fill(null),
15124
- { indices: [outerIndex] }
15125
- );
15126
- let first2 = true;
15127
- [...children2.get(key)].sort((a2, b) => innerIndices.get(a2) - innerIndices.get(b)).forEach((innerKey) => {
15128
- const innerIndex = innerIndices.get(innerKey);
15129
- const inner2 = secondRowItems[innerIndex];
15130
- const keys = [key, innerKey];
15131
- const records = details.get(JSON.stringify(keys));
15132
- if (!records) return;
15133
- append(
15134
- compact3 ? [label2(inner2)] : [
15135
- pivot.repeatLabels || layout2 === "tabular" && first2 ? label2(outer) : null,
15136
- label2(inner2)
15295
+ const numbers3 = (keys, records) => bands(keys, records).flat();
15296
+ const appendMeasures = (labels2, keys, records, indices, type) => {
15297
+ const values3 = bands(keys, records);
15298
+ measures.forEach(
15299
+ (measure, m) => append(
15300
+ type ? [
15301
+ `${type === "grand" ? "Total" : String(labels2[0])} ${measure.caption}`,
15302
+ ...Array(rowLabelColumns - 1).fill(null)
15303
+ ] : compact3 ? [measure.caption] : [
15304
+ ...labels2.map(
15305
+ (label3) => layout2 === "tabular" && m === 0 || pivot.repeatLabels ? label3 : null
15306
+ ),
15307
+ measure.caption
15137
15308
  ],
15138
- numbers3(keys, records),
15139
- { indices: [outerIndex, innerIndex] },
15140
- compact3 ? 1 : 0
15141
- );
15142
- first2 = false;
15309
+ values3.map((band) => band[m] ?? null),
15310
+ { indices: type ? indices : [...indices, m], measure: m, ...type ? { type } : {} },
15311
+ compact3 && !type ? 2 : 0
15312
+ )
15313
+ );
15314
+ };
15315
+ if (firstValues)
15316
+ appendFirstPivotValues(pivot, {
15317
+ rowItems,
15318
+ secondRowItems,
15319
+ columnItems,
15320
+ children: children2,
15321
+ innerIndices,
15322
+ groups,
15323
+ details,
15324
+ buckets,
15325
+ width: dimensions.width,
15326
+ rowLabels: rowLabelColumns,
15327
+ top,
15328
+ bottom,
15329
+ append
15143
15330
  });
15144
- if (bottom) {
15145
- const caption = String(label2(outer));
15146
- append(
15147
- [`${caption} Total`, ...compact3 ? [] : [null]],
15148
- numbers3([key], groups.get(key) ?? []),
15149
- { indices: [outerIndex], type: "default" }
15331
+ else
15332
+ rowItems.forEach((outer, outerIndex) => {
15333
+ const key = pivotValueKey(outer);
15334
+ if (layout2 !== "tabular")
15335
+ append(
15336
+ [label2(outer), ...Array(rowLabelColumns - 1).fill(null)],
15337
+ top ? numbers3([key], groups.get(key) ?? []) : Array(dimensions.width - rowLabelColumns).fill(null),
15338
+ { indices: [outerIndex] }
15339
+ );
15340
+ let first2 = true;
15341
+ const innerKeys = [...children2.get(key)].sort(
15342
+ (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
15150
15343
  );
15151
- }
15152
- });
15153
- append(["Grand Total", ...compact3 ? [] : [null]], numbers3([], pivot.records), {
15154
- indices: [0],
15155
- type: "grand"
15156
- });
15344
+ if (between)
15345
+ measures.forEach((measure, m) => {
15346
+ if (layout2 !== "tabular")
15347
+ append(
15348
+ compact3 ? [measure.caption] : [pivot.repeatLabels ? label2(outer) : null, measure.caption, null],
15349
+ Array(dimensions.width - rowLabelColumns).fill(null),
15350
+ { indices: [outerIndex, m], measure: m },
15351
+ compact3 ? 1 : 0
15352
+ );
15353
+ innerKeys.forEach((innerKey, child3) => {
15354
+ const innerIndex = innerIndices.get(innerKey);
15355
+ const keys = [key, innerKey];
15356
+ const records = details.get(JSON.stringify(keys));
15357
+ append(
15358
+ compact3 ? [label2(secondRowItems[innerIndex])] : [
15359
+ pivot.repeatLabels || layout2 === "tabular" && m === 0 && child3 === 0 ? label2(outer) : null,
15360
+ layout2 === "tabular" && child3 === 0 ? measure.caption : null,
15361
+ label2(secondRowItems[innerIndex])
15362
+ ],
15363
+ [
15364
+ ...columnItems.map(
15365
+ (column) => pivotMeasureNumber(
15366
+ pivot,
15367
+ buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
15368
+ measure
15369
+ )
15370
+ ),
15371
+ pivotMeasureNumber(pivot, records, measure)
15372
+ ],
15373
+ { indices: [outerIndex, m, innerIndex], measure: m },
15374
+ compact3 ? 2 : 0
15375
+ );
15376
+ });
15377
+ });
15378
+ else
15379
+ innerKeys.forEach((innerKey) => {
15380
+ const innerIndex = innerIndices.get(innerKey);
15381
+ const inner2 = secondRowItems[innerIndex];
15382
+ const keys = [key, innerKey];
15383
+ const records = details.get(JSON.stringify(keys));
15384
+ if (!records) return;
15385
+ if (rowsAxis) {
15386
+ if (layout2 !== "tabular")
15387
+ append(
15388
+ compact3 ? [label2(inner2)] : [pivot.repeatLabels ? label2(outer) : null, label2(inner2), null],
15389
+ Array(dimensions.width - rowLabelColumns).fill(null),
15390
+ { indices: [outerIndex, innerIndex] },
15391
+ compact3 ? 1 : 0
15392
+ );
15393
+ appendMeasures(
15394
+ [pivot.repeatLabels || first2 ? label2(outer) : null, label2(inner2)],
15395
+ keys,
15396
+ records,
15397
+ [outerIndex, innerIndex]
15398
+ );
15399
+ first2 = false;
15400
+ return;
15401
+ }
15402
+ append(
15403
+ compact3 ? [label2(inner2)] : [
15404
+ pivot.repeatLabels || layout2 === "tabular" && first2 ? label2(outer) : null,
15405
+ label2(inner2)
15406
+ ],
15407
+ numbers3(keys, records),
15408
+ { indices: [outerIndex, innerIndex] },
15409
+ compact3 ? 1 : 0
15410
+ );
15411
+ first2 = false;
15412
+ });
15413
+ if (bottom) {
15414
+ if (rowsAxis) {
15415
+ appendMeasures([label2(outer)], [key], groups.get(key) ?? [], [outerIndex], "default");
15416
+ return;
15417
+ }
15418
+ const caption = String(label2(outer));
15419
+ append(
15420
+ [`${caption} Total`, ...compact3 ? [] : [null]],
15421
+ numbers3([key], groups.get(key) ?? []),
15422
+ { indices: [outerIndex], type: "default" }
15423
+ );
15424
+ }
15425
+ });
15426
+ if (rowsAxis) appendMeasures([], [], pivot.records, [0], "grand");
15427
+ else
15428
+ append(["Grand Total", ...compact3 ? [] : [null]], numbers3([], pivot.records), {
15429
+ indices: [0],
15430
+ type: "grand"
15431
+ });
15157
15432
  return {
15158
15433
  values: values2,
15159
15434
  rowItems,
15160
15435
  secondRowItems,
15161
15436
  columnItems,
15162
15437
  rowEntries,
15163
- firstDataRow: pivot.columnField ? 2 : 1,
15438
+ firstDataRow,
15164
15439
  rowLabelColumns,
15165
- indents
15440
+ indents,
15441
+ ...rowsAxis ? { firstHeaderRow: 1 } : {}
15166
15442
  };
15167
15443
  }
15168
15444
 
15169
15445
  // xlsx/pivot/aggregate.ts
15170
- function aggregate2(records, field, type) {
15171
- if (!records.length) return null;
15172
- const values2 = records.map((record) => record[field] ?? null);
15173
- if (type === "count") return values2.filter((value2) => value2 !== null && value2 !== "").length;
15174
- const error = values2.find(isCellError);
15175
- if (error) return error;
15176
- const numbers3 = values2.filter((value2) => typeof value2 === "number");
15177
- if (!numbers3.length) return type === "average" ? { error: "#DIV/0!" } : 0;
15178
- if (type === "min") return numbers3.reduce((a2, b) => Math.min(a2, b));
15179
- if (type === "max") return numbers3.reduce((a2, b) => Math.max(a2, b));
15180
- const sum2 = numbers3.reduce((total2, value2) => total2 + value2, 0);
15181
- return type === "average" ? sum2 / numbers3.length : sum2;
15182
- }
15183
15446
  function pivotGrid(pivot) {
15184
15447
  validatePivotFields(pivot);
15185
- if (pivot.secondRowField) return hierarchicalPivotGrid(pivot, aggregate2);
15448
+ if (pivot.secondRowField) return hierarchicalPivotGrid(pivot);
15186
15449
  const rowItems = pivotItems(pivot, pivot.rowField);
15187
15450
  const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
15188
- if ((rowItems.length + 3) * (columnItems.length + 2) > 1e6)
15451
+ const rowsAxis = pivot.valuesAxis === "rows";
15452
+ const compact3 = pivot.layout === "compact";
15453
+ const headings = rowsAxis && pivot.layout !== void 0 && pivot.layout !== "tabular";
15454
+ const dimensions = pivotHeaderDimensions(pivot, columnItems.length, rowsAxis && !compact3 ? 2 : 1);
15455
+ const dataRows = (rowItems.length + 1) * (rowsAxis ? 1 + (pivot.additionalValues?.length ?? 0) : 1) + (headings ? rowItems.length : 0);
15456
+ if ((dataRows + dimensions.rows) * dimensions.width > 1e6)
15189
15457
  throw new Error("The PivotTable result is too large.");
15458
+ const label3 = pivotItemLabel;
15459
+ const values2 = pivotHeaders(
15460
+ pivot,
15461
+ columnItems,
15462
+ [pivot.layout === "compact" ? "Row Labels" : pivot.rowField],
15463
+ label3
15464
+ );
15190
15465
  const rowField = pivot.fields.indexOf(pivot.rowField);
15191
15466
  const colField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
15192
- const valueField = pivot.fields.indexOf(pivot.valueField);
15193
15467
  const groups = /* @__PURE__ */ new Map();
15194
15468
  const cells = /* @__PURE__ */ new Map();
15195
15469
  const columns = /* @__PURE__ */ new Map();
@@ -15207,42 +15481,85 @@ function pivotGrid(pivot) {
15207
15481
  collect2(cells, JSON.stringify([key, col]), record);
15208
15482
  }
15209
15483
  }
15210
- const label3 = pivotItemLabel;
15211
- const values2 = pivot.columnField ? [
15212
- [
15213
- pivot.valueCaption,
15214
- pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
15215
- ...columnItems.slice(1).map(() => null),
15216
- null
15217
- ],
15218
- [
15219
- pivot.layout === "compact" ? "Row Labels" : pivot.rowField,
15220
- ...columnItems.map(label3),
15221
- "Grand Total"
15222
- ]
15223
- ] : [[pivot.layout === "compact" ? "Row Labels" : pivot.rowField, pivot.valueCaption]];
15484
+ const firstDataRow = values2.length;
15485
+ if (rowsAxis) {
15486
+ const measures = pivotMeasures(pivot);
15487
+ const rowEntries = [];
15488
+ const indents = values2.map(() => 0);
15489
+ const append = (caption, bands, index2, grand = false) => {
15490
+ measures.forEach((measure, m) => {
15491
+ values2.push([
15492
+ ...compact3 ? [grand ? `Total ${measure.caption}` : measure.caption] : [
15493
+ grand ? `Total ${measure.caption}` : pivot.repeatLabels || !headings && m === 0 ? caption : null,
15494
+ grand ? null : measure.caption
15495
+ ],
15496
+ ...bands.map((band) => band[m] ?? null)
15497
+ ]);
15498
+ indents.push(compact3 && !grand ? 1 : 0);
15499
+ rowEntries.push({
15500
+ indices: grand ? [0] : [index2, m],
15501
+ measure: m,
15502
+ ...grand ? { type: "grand" } : {}
15503
+ });
15504
+ });
15505
+ };
15506
+ rowItems.forEach((item, index2) => {
15507
+ const key = pivotValueKey(item);
15508
+ if (headings) {
15509
+ values2.push([label3(item), ...Array(dimensions.width - 1).fill(null)]);
15510
+ rowEntries.push({ indices: [index2] });
15511
+ indents.push(0);
15512
+ }
15513
+ append(
15514
+ label3(item),
15515
+ [
15516
+ ...columnItems.map(
15517
+ (col) => pivotNumbers(pivot, cells.get(JSON.stringify([key, pivotValueKey(col)])) ?? [])
15518
+ ),
15519
+ pivotNumbers(pivot, groups.get(key) ?? [])
15520
+ ],
15521
+ index2
15522
+ );
15523
+ });
15524
+ append(
15525
+ "Grand Total",
15526
+ [
15527
+ ...columnItems.map((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
15528
+ pivotNumbers(pivot, pivot.records)
15529
+ ],
15530
+ 0,
15531
+ true
15532
+ );
15533
+ return {
15534
+ values: values2,
15535
+ rowItems,
15536
+ columnItems,
15537
+ firstDataRow,
15538
+ rowLabelColumns: compact3 ? 1 : 2,
15539
+ indents,
15540
+ firstHeaderRow: 1,
15541
+ rowEntries
15542
+ };
15543
+ }
15224
15544
  for (const row2 of rowItems) {
15225
15545
  const records = groups.get(pivotValueKey(row2)) ?? [];
15226
15546
  values2.push([
15227
15547
  label3(row2),
15228
- ...columnItems.map(
15229
- (col) => aggregate2(
15230
- cells.get(JSON.stringify([pivotValueKey(row2), pivotValueKey(col)])) ?? [],
15231
- valueField,
15232
- pivot.aggregate
15548
+ ...columnItems.flatMap(
15549
+ (col) => pivotNumbers(
15550
+ pivot,
15551
+ cells.get(JSON.stringify([pivotValueKey(row2), pivotValueKey(col)])) ?? []
15233
15552
  )
15234
15553
  ),
15235
- aggregate2(records, valueField, pivot.aggregate)
15554
+ ...pivotNumbers(pivot, records)
15236
15555
  ]);
15237
15556
  }
15238
15557
  values2.push([
15239
15558
  "Grand Total",
15240
- ...columnItems.map(
15241
- (col) => aggregate2(columns.get(pivotValueKey(col)) ?? [], valueField, pivot.aggregate)
15242
- ),
15243
- aggregate2(pivot.records, valueField, pivot.aggregate)
15559
+ ...columnItems.flatMap((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
15560
+ ...pivotNumbers(pivot, pivot.records)
15244
15561
  ]);
15245
- return { values: values2, rowItems, columnItems, firstDataRow: pivot.columnField ? 2 : 1 };
15562
+ return { values: values2, rowItems, columnItems, firstDataRow };
15246
15563
  }
15247
15564
  function pivotTableAt(sheet, at) {
15248
15565
  return sheet.pivotTables?.find((pivot) => rangeContains(pivot.location, at));
@@ -15252,7 +15569,7 @@ function pivotTableAt(sheet, at) {
15252
15569
  var X14 = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main";
15253
15570
  var LAYOUT = "http://schemas.microsoft.com/office/spreadsheetml/2016/pivotdefaultlayout";
15254
15571
  var TABLE = {
15255
- pivotTableDefinition: "name cacheId dataCaption updatedVersion minRefreshableVersion createdVersion applyNumberFormats applyBorderFormats applyFontFormats applyPatternFormats applyAlignmentFormats applyWidthHeightFormats useAutoFormatting itemPrintTitles indent compact compactData outline outlineData multipleFieldFilters rowGrandTotals colGrandTotals",
15572
+ 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",
15256
15573
  location: "ref firstHeaderRow firstDataRow firstDataCol",
15257
15574
  pivotFields: "count",
15258
15575
  pivotField: "axis dataField compact outline showAll subtotalTop defaultSubtotal",
@@ -15263,7 +15580,7 @@ var TABLE = {
15263
15580
  field: "x",
15264
15581
  rowItems: "count",
15265
15582
  colItems: "count",
15266
- i: "t r",
15583
+ i: "t r i",
15267
15584
  x: "v",
15268
15585
  dataFields: "count",
15269
15586
  dataField: "name fld subtotal baseField baseItem showDataAs",
@@ -15294,7 +15611,7 @@ function inspect(node, profile, cache3) {
15294
15611
  for (let i2 = 0; i2 < node.attributes.length; i2++) {
15295
15612
  const attr2 = node.attributes.item(i2);
15296
15613
  if (attr2.name.startsWith("xmlns")) continue;
15297
- if (!cache3 && node.namespaceURI === X14 && node.localName === "pivotTableDefinition" && attr2.name === "hideValuesRow" && attr2.value === "1")
15614
+ if (!cache3 && node.namespaceURI === X14 && node.localName === "pivotTableDefinition" && attr2.name === "hideValuesRow" && ["0", "1"].includes(attr2.value))
15298
15615
  continue;
15299
15616
  if (!cache3 && node.namespaceURI === X14 && (node.localName === "pivotField" && attr2.name === "fillDownLabels" || node.localName === "pivotTableDefinition" && attr2.name === "fillDownLabelsDefault") && ["0", "1"].includes(attr2.value))
15300
15617
  continue;
@@ -15323,7 +15640,9 @@ function inspect(node, profile, cache3) {
15323
15640
  throw new Error("Unsupported PivotTable option");
15324
15641
  if (attr2.localName === "numFmtId" && attr2.value !== "0")
15325
15642
  throw new Error("Unsupported PivotTable field number format");
15326
- if (node.localName === "pivotTableDefinition" && ["compact", "compactData", "outline", "outlineData"].includes(attr2.localName) && !["0", "1"].includes(attr2.value))
15643
+ if (node.localName === "pivotTableDefinition" && ["compact", "compactData", "outline", "outlineData", "dataOnRows"].includes(
15644
+ attr2.localName
15645
+ ) && !["0", "1"].includes(attr2.value))
15327
15646
  throw new Error("Unsupported PivotTable global layout");
15328
15647
  if (node.localName === "item" && attr2.localName === "t" && !["default", "data"].includes(attr2.value))
15329
15648
  throw new Error("Unsupported PivotTable subtotal");
@@ -15346,6 +15665,88 @@ function assertPivotRecords(records) {
15346
15665
  );
15347
15666
  }
15348
15667
 
15668
+ // xlsx/write/xml-out.ts
15669
+ var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
15670
+ var CONTROL2 = "\0-\b\v\f-" + String.fromCharCode(65534, 65535);
15671
+ var NEEDS_ESCAPE = new RegExp(`[${CONTROL2}\r]|_x[0-9A-Fa-f]{4}_`);
15672
+ var ESCAPABLE = new RegExp(`[${CONTROL2}\r]|_(?=x[0-9A-Fa-f]{4}_)`, "g");
15673
+ function encodeEscapes(text3) {
15674
+ if (!NEEDS_ESCAPE.test(text3)) return text3;
15675
+ return text3.replace(
15676
+ ESCAPABLE,
15677
+ (ch) => `_x${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}_`
15678
+ );
15679
+ }
15680
+ var INVALID_XML = new RegExp(`[${CONTROL2}]`, "g");
15681
+ var escapeText2 = (text3) => text3.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
15682
+ 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;");
15683
+ function attrs(values2) {
15684
+ let out = "";
15685
+ for (const [name, value2] of Object.entries(values2)) {
15686
+ if (value2 === void 0) continue;
15687
+ const text3 = typeof value2 === "boolean" ? value2 ? "1" : "0" : typeof value2 === "number" ? num2(value2) : value2;
15688
+ out += ` ${name}="${escapeAttr3(text3)}"`;
15689
+ }
15690
+ return out;
15691
+ }
15692
+ var el = (name, values2 = {}, content2 = "") => content2 ? `<${name}${attrs(values2)}>${content2}</${name}>` : `<${name}${attrs(values2)}/>`;
15693
+ var num2 = (value2) => Object.is(value2, -0) ? "0" : String(value2);
15694
+ function tElement(text3, name = "t") {
15695
+ const encoded = escapeText2(encodeEscapes(text3));
15696
+ const preserve = /^\s|\s$|\n|\t/.test(text3) ? ' xml:space="preserve"' : "";
15697
+ return `<${name}${preserve}>${encoded}</${name}>`;
15698
+ }
15699
+ var MAIN_NS = ' xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"';
15700
+ function inlineFragment(xml) {
15701
+ const end = xml.indexOf(">");
15702
+ if (end < 0) return xml;
15703
+ const head = xml.slice(0, end);
15704
+ return head.includes(MAIN_NS) ? head.replace(MAIN_NS, "") + xml.slice(end) : xml;
15705
+ }
15706
+
15707
+ // xlsx/pivot/values-axis.ts
15708
+ function pivotFieldIndex(field) {
15709
+ const raw2 = field?.getAttribute("x");
15710
+ if (raw2 === null || raw2 === void 0 || !/^-?\d+$/.test(raw2.trim())) return NaN;
15711
+ const value2 = Number(raw2);
15712
+ return Number.isSafeInteger(value2) ? value2 : NaN;
15713
+ }
15714
+ function pivotValueIndex(root, axis) {
15715
+ const index2 = axis.findIndex((field) => pivotFieldIndex(field) === -2);
15716
+ const position = root.getAttribute("dataPosition");
15717
+ if (position !== null && (!/^\d+$/.test(position.trim()) || Number(position) !== index2))
15718
+ throw new Error("Inconsistent Values axis position");
15719
+ if (axis.length === 3 && index2 < 2 && position === null)
15720
+ throw new Error("Missing leading or between-field Values position");
15721
+ return index2;
15722
+ }
15723
+ function pivotValueAxisItems(measures, columns) {
15724
+ const entries = [];
15725
+ if (columns === void 0) {
15726
+ for (let measure = 0; measure < measures; measure++)
15727
+ entries.push(
15728
+ `<i${attrs({ i: measure || void 0 })}><x${attrs({ v: measure || void 0 })}/></i>`
15729
+ );
15730
+ } else {
15731
+ for (let column = 0; column < columns; column++)
15732
+ for (let measure = 0; measure < measures; measure++) {
15733
+ entries.push(
15734
+ `<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>`
15735
+ );
15736
+ }
15737
+ for (let measure = 0; measure < measures; measure++)
15738
+ entries.push(`<i${attrs({ t: "grand", i: measure || void 0 })}><x/></i>`);
15739
+ }
15740
+ return `<colItems count="${entries.length}">${entries.join("")}</colItems>`;
15741
+ }
15742
+ function supportedPivotAxes(rows, columns, measures, valuesOnRows) {
15743
+ const index2 = pivotFieldIndex;
15744
+ if (valuesOnRows)
15745
+ 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);
15746
+ if (rows.some((field) => !Number.isInteger(index2(field)) || index2(field) < 0)) return false;
15747
+ return measures === 1 ? columns.length <= 1 : columns.length >= 1 && columns.length <= 2 && index2(columns.at(-1)) === -2 && (columns.length !== 2 || index2(columns[0]) >= 0);
15748
+ }
15749
+
15349
15750
  // xlsx/pivot/read.ts
15350
15751
  function value(node) {
15351
15752
  const v = att(node, "v") ?? "";
@@ -15380,6 +15781,7 @@ function readOne(workbook, source2, part) {
15380
15781
  const dataSheet = sourceNode && att(sourceNode, "sheet");
15381
15782
  const dataRange = sourceNode && parseRange(att(sourceNode, "ref") ?? "");
15382
15783
  const recordPart = source2.targetOfType(cachePart, `${NS.r}/pivotCacheRecords`);
15784
+ const rowsAxis = att(root, "dataOnRows") === "1";
15383
15785
  if (!dataSheet || !dataRange || !recordPart || !workbook.sheets.some((sheet) => sheet.name === dataSheet))
15384
15786
  throw new Error("Unsupported pivot source");
15385
15787
  assertPivotRecords(parseXml(source2.text(recordPart)).documentElement);
@@ -15415,17 +15817,42 @@ function readOne(workbook, source2, part) {
15415
15817
  "dataField",
15416
15818
  NS.x
15417
15819
  );
15418
- 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")
15820
+ 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")
15419
15821
  throw new Error("Unsupported pivot layout");
15822
+ const valueIndex = pivotValueIndex(root, rowsAxis ? rowFields : colFields);
15420
15823
  const measure = dataFields[0];
15824
+ const definition = elements(first(root, "extLst", NS.x) ?? parseXml("<root/>").documentElement).map(
15825
+ (extension) => first(
15826
+ extension,
15827
+ "pivotTableDefinition",
15828
+ "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
15829
+ )
15830
+ ).find(Boolean);
15831
+ if (dataFields.length > 1 && att(definition, "hideValuesRow") !== "1")
15832
+ throw new Error("Visible Values header rows are preserved");
15833
+ for (const [axis, count2] of [
15834
+ ["rowItems", rowsAxis ? dataFields.length : 1],
15835
+ ["colItems", rowsAxis ? 1 : dataFields.length]
15836
+ ]) {
15837
+ for (const item of children(
15838
+ first(root, axis, NS.x) ?? parseXml("<root/>").documentElement,
15839
+ "i",
15840
+ NS.x
15841
+ )) {
15842
+ const index2 = Number(att(item, "i") ?? "0");
15843
+ if (!Number.isInteger(index2) || index2 < 0 || index2 >= count2)
15844
+ throw new Error("Unsupported Values axis item");
15845
+ }
15846
+ }
15421
15847
  const aggregate3 = att(measure, "subtotal") ?? "sum";
15422
15848
  if (!PIVOT_AGGREGATES.includes(aggregate3) || att(measure, "showDataAs") && att(measure, "showDataAs") !== "normal")
15423
15849
  throw new Error("Unsupported pivot aggregate");
15424
15850
  const names = fields.map((field) => decodeEscapes(att(field, "name") ?? ""));
15425
- const row2 = names[Number(att(rowFields[0], "x"))];
15426
- const second = rowFields[1] && names[Number(att(rowFields[1], "x"))];
15851
+ const realRows = rowsAxis ? rowFields.filter((field) => pivotFieldIndex(field) !== -2) : rowFields;
15852
+ const row2 = names[pivotFieldIndex(realRows[0])];
15853
+ const second = realRows[1] ? names[Number(att(realRows[1], "x"))] : void 0;
15427
15854
  const tableFields = children(first(root, "pivotFields", NS.x), "pivotField", NS.x);
15428
- const outer = tableFields[Number(att(rowFields[0], "x"))];
15855
+ const outer = tableFields[pivotFieldIndex(realRows[0])];
15429
15856
  const compact3 = att(outer, "compact") !== "0";
15430
15857
  const outline = att(outer, "outline") !== "0";
15431
15858
  const layout2 = compact3 ? "compact" : outline ? "outline" : "tabular";
@@ -15434,7 +15861,7 @@ function readOne(workbook, source2, part) {
15434
15861
  ) || 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")
15435
15862
  throw new Error("Mixed field layouts or custom compact indentation are preserved");
15436
15863
  const subtotal = att(outer, "defaultSubtotal") !== "0";
15437
- const repeat = rowFields.map((field) => {
15864
+ const repeat = realRows.map((field) => {
15438
15865
  const node = tableFields[Number(att(field, "x"))];
15439
15866
  const extension = first(first(node, "extLst", NS.x), "ext", NS.x);
15440
15867
  return att(
@@ -15447,16 +15874,19 @@ function readOne(workbook, source2, part) {
15447
15874
  ) === "1";
15448
15875
  });
15449
15876
  if (repeat.some((entry4) => entry4 !== repeat[0])) throw new Error("Mixed field label repetition");
15450
- const col = colFields[0] && names[Number(att(colFields[0], "x"))];
15877
+ const hasColumn = colFields.length > (dataFields.length > 1 && !rowsAxis ? 1 : 0);
15878
+ const col = hasColumn ? names[Number(att(colFields[0], "x"))] : void 0;
15451
15879
  const data = names[Number(att(measure, "fld"))];
15452
15880
  const location = parseRange(att(first(root, "location", NS.x), "ref") ?? "");
15453
- if (!row2 || !data || !location || colFields.length && !col || rowFields.length === 2 && !second)
15881
+ if (!row2 || !data || !location || hasColumn && !col || realRows.length === 2 && !second)
15454
15882
  throw new Error("Invalid pivot fields");
15455
15883
  const pivot = {
15456
15884
  name: att(root, "name") ?? "PivotTable",
15457
15885
  source: `${quoteSheetName(dataSheet)}!${formatRange(dataRange)}`,
15458
15886
  rowField: row2,
15459
15887
  layout: layout2,
15888
+ ...rowsAxis ? { valuesAxis: "rows" } : {},
15889
+ ...rowsAxis && realRows.length === 2 && valueIndex < 2 ? { valuesPosition: valueIndex === 0 ? "first" : "between" } : {},
15460
15890
  subtotalPosition: att(outer, "subtotalTop") === "0" ? "bottom" : "top",
15461
15891
  ...second ? { secondRowField: second, subtotals: subtotal, repeatLabels: repeat[0] ?? false } : {
15462
15892
  ...subtotal ? {} : { subtotals: false },
@@ -15465,6 +15895,15 @@ function readOne(workbook, source2, part) {
15465
15895
  valueField: data,
15466
15896
  aggregate: aggregate3,
15467
15897
  valueCaption: decodeEscapes(att(measure, "name") ?? data),
15898
+ ...dataFields.length > 1 ? {
15899
+ additionalValues: dataFields.slice(1).map((measure2) => {
15900
+ const field = names[Number(att(measure2, "fld"))];
15901
+ const aggregate4 = att(measure2, "subtotal") ?? "sum";
15902
+ if (!field || !PIVOT_AGGREGATES.includes(aggregate4) || att(measure2, "showDataAs") && att(measure2, "showDataAs") !== "normal")
15903
+ throw new Error("Unsupported pivot measure");
15904
+ return { field, aggregate: aggregate4, caption: decodeEscapes(att(measure2, "name") ?? field) };
15905
+ })
15906
+ } : {},
15468
15907
  fields: names,
15469
15908
  records,
15470
15909
  location,
@@ -18993,45 +19432,6 @@ function readDataValidations(node) {
18993
19432
  return out;
18994
19433
  }
18995
19434
 
18996
- // xlsx/write/xml-out.ts
18997
- var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
18998
- var CONTROL2 = "\0-\b\v\f-" + String.fromCharCode(65534, 65535);
18999
- var NEEDS_ESCAPE = new RegExp(`[${CONTROL2}\r]|_x[0-9A-Fa-f]{4}_`);
19000
- var ESCAPABLE = new RegExp(`[${CONTROL2}\r]|_(?=x[0-9A-Fa-f]{4}_)`, "g");
19001
- function encodeEscapes(text3) {
19002
- if (!NEEDS_ESCAPE.test(text3)) return text3;
19003
- return text3.replace(
19004
- ESCAPABLE,
19005
- (ch) => `_x${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}_`
19006
- );
19007
- }
19008
- var INVALID_XML = new RegExp(`[${CONTROL2}]`, "g");
19009
- var escapeText2 = (text3) => text3.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
19010
- 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;");
19011
- function attrs(values2) {
19012
- let out = "";
19013
- for (const [name, value2] of Object.entries(values2)) {
19014
- if (value2 === void 0) continue;
19015
- const text3 = typeof value2 === "boolean" ? value2 ? "1" : "0" : typeof value2 === "number" ? num2(value2) : value2;
19016
- out += ` ${name}="${escapeAttr3(text3)}"`;
19017
- }
19018
- return out;
19019
- }
19020
- var el = (name, values2 = {}, content2 = "") => content2 ? `<${name}${attrs(values2)}>${content2}</${name}>` : `<${name}${attrs(values2)}/>`;
19021
- var num2 = (value2) => Object.is(value2, -0) ? "0" : String(value2);
19022
- function tElement(text3, name = "t") {
19023
- const encoded = escapeText2(encodeEscapes(text3));
19024
- const preserve = /^\s|\s$|\n|\t/.test(text3) ? ' xml:space="preserve"' : "";
19025
- return `<${name}${preserve}>${encoded}</${name}>`;
19026
- }
19027
- var MAIN_NS = ' xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"';
19028
- function inlineFragment(xml) {
19029
- const end = xml.indexOf(">");
19030
- if (end < 0) return xml;
19031
- const head = xml.slice(0, end);
19032
- return head.includes(MAIN_NS) ? head.replace(MAIN_NS, "") + xml.slice(end) : xml;
19033
- }
19034
-
19035
19435
  // xlsx/conditional-extensions.ts
19036
19436
  var XM = "http://schemas.microsoft.com/office/excel/2006/main";
19037
19437
  var URI = "{78C0D931-6437-407d-A8EE-F0AAD7539E65}";
@@ -25500,7 +25900,9 @@ function pivotTableXml(pivot, cacheId, cache3) {
25500
25900
  const row2 = pivot.fields.indexOf(pivot.rowField);
25501
25901
  const second = pivot.secondRowField ? pivot.fields.indexOf(pivot.secondRowField) : -1;
25502
25902
  const col = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
25503
- const value2 = pivot.fields.indexOf(pivot.valueField);
25903
+ const measures = pivotMeasures(pivot);
25904
+ const multiple = measures.length > 1;
25905
+ const rowsAxis = pivot.valuesAxis === "rows";
25504
25906
  const compact3 = pivot.layout === "compact";
25505
25907
  const outline = pivot.layout === "compact" || pivot.layout === "outline";
25506
25908
  const top = (pivot.subtotalPosition ?? (outline ? "top" : "bottom")) === "top";
@@ -25508,36 +25910,61 @@ function pivotTableXml(pivot, cacheId, cache3) {
25508
25910
  const items2 = index2 === row2 ? grid.rowItems : index2 === second ? grid.secondRowItems : index2 === col ? grid.columnItems : void 0;
25509
25911
  const subtotal = !(index2 === row2 && pivot.subtotals === false);
25510
25912
  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>' : "";
25511
- 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>`;
25913
+ 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>`;
25512
25914
  }).join("");
25513
25915
  const items = (count2) => Array.from({ length: count2 }, (_v, i2) => `<i><x v="${i2}"/></i>`).join("") + '<i t="grand"><x/></i>';
25514
- const header = grid.firstDataRow - 1;
25515
- const rowIndices = [row2, ...second >= 0 ? [second] : []];
25916
+ const header = grid.firstHeaderRow ?? (multiple && col >= 0 ? 1 : grid.firstDataRow - 1);
25917
+ const rowIndices = rowsAxis && pivot.valuesPosition === "first" ? [-2, row2, second] : rowsAxis && pivot.valuesPosition === "between" ? [row2, -2, second] : [row2, ...second >= 0 ? [second] : [], ...rowsAxis ? [-2] : []];
25516
25918
  let previous = [];
25517
25919
  const rowItems = grid.rowEntries?.map((entry3) => {
25518
25920
  let prefix = 0;
25519
- if (!entry3.type)
25921
+ if (entry3.type === "default" && rowsAxis && pivot.valuesPosition === "first") prefix = 1;
25922
+ else if (!entry3.type)
25520
25923
  while (prefix < entry3.indices.length - 1 && entry3.indices[prefix] === previous[prefix])
25521
25924
  prefix++;
25522
- previous = entry3.type ? [] : entry3.indices;
25523
- return `<i${attrs({ t: entry3.type, r: prefix || void 0 })}>${entry3.indices.slice(prefix).map((index2) => `<x${attrs({ v: index2 || void 0 })}/>`).join("")}</i>`;
25925
+ previous = entry3.type && !(entry3.type === "default" && pivot.valuesPosition === "first") ? [] : entry3.indices;
25926
+ 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>`;
25524
25927
  }).join("") ?? items(grid.rowItems.length);
25525
25928
  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>`;
25526
- if (col >= 0)
25929
+ if (multiple && !rowsAxis)
25930
+ 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)}`;
25931
+ else if (col >= 0)
25527
25932
  body += `<colFields count="1"><field x="${col}"/></colFields><colItems count="${grid.columnItems.length + 1}">${items(grid.columnItems.length)}</colItems>`;
25528
- else body += '<colItems count="1"><i><x/></i></colItems>';
25529
- body += `<dataFields count="1"><dataField${attrs({ name: encodeEscapes(pivot.valueCaption), fld: value2, subtotal: pivot.aggregate, baseField: 0, baseItem: 0 })}/></dataFields>`;
25933
+ else
25934
+ body += rowsAxis ? '<colItems count="1"><i/></colItems>' : '<colItems count="1"><i><x/></i></colItems>';
25935
+ 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>`;
25530
25936
  const doc = parseXml(
25531
25937
  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>`
25532
25938
  );
25533
25939
  const root = doc.documentElement;
25534
25940
  root.setAttribute("name", pivot.name);
25535
25941
  root.setAttribute("cacheId", String(cacheId));
25942
+ root.setAttribute("dataOnRows", rowsAxis ? "1" : "0");
25943
+ if (rowsAxis && (pivot.valuesPosition === "between" || pivot.valuesPosition === "first"))
25944
+ root.setAttribute("dataPosition", pivot.valuesPosition === "first" ? "0" : "1");
25945
+ else root.removeAttribute("dataPosition");
25536
25946
  root.setAttribute("compact", compact3 ? "1" : "0");
25537
25947
  root.setAttribute("compactData", compact3 ? "1" : "0");
25538
25948
  root.setAttribute("outline", outline ? "1" : "0");
25539
25949
  root.setAttribute("outlineData", outline ? "1" : "0");
25540
25950
  if (compact3) root.setAttribute("indent", "0");
25951
+ if (multiple && !elements(first(root, "extLst", NS.x) ?? parseXml("<root/>").documentElement).some(
25952
+ (extension) => first(
25953
+ extension,
25954
+ "pivotTableDefinition",
25955
+ "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
25956
+ )
25957
+ )) {
25958
+ let list = first(root, "extLst", NS.x);
25959
+ if (!list) {
25960
+ list = doc.createElementNS(NS.x, "extLst");
25961
+ root.appendChild(list);
25962
+ }
25963
+ const extension = parseXml(
25964
+ `<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>`
25965
+ ).documentElement;
25966
+ list.appendChild(doc.importNode(extension, true));
25967
+ }
25541
25968
  root.setAttribute("rowGrandTotals", "1");
25542
25969
  root.setAttribute("colGrandTotals", "1");
25543
25970
  for (const extension of elements(
@@ -25548,6 +25975,7 @@ function pivotTableXml(pivot, cacheId, cache3) {
25548
25975
  "pivotTableDefinition",
25549
25976
  "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
25550
25977
  );
25978
+ if (multiple && definition) definition.setAttribute("hideValuesRow", "1");
25551
25979
  if (definition?.hasAttribute("fillDownLabelsDefault"))
25552
25980
  definition.setAttribute("fillDownLabelsDefault", pivot.repeatLabels ? "1" : "0");
25553
25981
  }
@@ -29771,12 +30199,16 @@ function write(ctx, s, pivot, old) {
29771
30199
  ],
29772
30200
  () => {
29773
30201
  const compact3 = pivot.layout === "compact";
29774
- const indents = [
29775
- stylePatcher(ctx.workbook, {
29776
- alignment: { indent: 0, ...compact3 ? { horizontal: "left" } : {} }
29777
- }),
29778
- stylePatcher(ctx.workbook, { alignment: { indent: 1, horizontal: "left" } })
29779
- ];
30202
+ const indents = new Map(
30203
+ [.../* @__PURE__ */ new Set([0, ...grid.indents ?? []])].map(
30204
+ (indent) => [
30205
+ indent,
30206
+ stylePatcher(ctx.workbook, {
30207
+ alignment: { indent, ...compact3 || indent > 0 ? { horizontal: "left" } : {} }
30208
+ })
30209
+ ]
30210
+ )
30211
+ );
29780
30212
  const styles = /* @__PURE__ */ new Map();
29781
30213
  forEachCellInRange(sheet, location, (cell, row2, col) => {
29782
30214
  if (cell.styleId !== void 0) styles.set(`${row2}:${col}`, cell.styleId);
@@ -29799,7 +30231,7 @@ function write(ctx, s, pivot, old) {
29799
30231
  const indent = col === 0 ? grid.indents?.[row2] ?? 0 : 0;
29800
30232
  const alignment = styleAt(ctx.workbook, styleId).alignment;
29801
30233
  if ((alignment?.indent ?? 0) !== indent || compact3 && alignment?.horizontal !== "left")
29802
- styleId = indents[indent](styleId);
30234
+ styleId = indents.get(indent)(styleId);
29803
30235
  }
29804
30236
  putCell(sheet, r, c2, { value: value2, ...styleId !== void 0 ? { styleId } : {} });
29805
30237
  })
@@ -29826,6 +30258,9 @@ function createPivotTable(ctx, s, destination, options) {
29826
30258
  valueField: options.valueField,
29827
30259
  aggregate: aggregate3,
29828
30260
  valueCaption: pivotCaption(aggregate3, options.valueField),
30261
+ ...options.valuesAxis !== void 0 ? { valuesAxis: options.valuesAxis } : {},
30262
+ ...options.valuesPosition !== void 0 ? { valuesPosition: options.valuesPosition } : {},
30263
+ ...options.additionalValues ? { additionalValues: normalizedPivotMeasures(options.additionalValues) } : {},
29829
30264
  location: { start: { ...destination }, end: { ...destination } },
29830
30265
  ...options.columnField ? { columnField: options.columnField } : {}
29831
30266
  };
@@ -29857,6 +30292,15 @@ function refreshPivotTable(ctx, s, name, patch3 = {}) {
29857
30292
  if (patch3.repeatLabels !== void 0) next.repeatLabels = patch3.repeatLabels;
29858
30293
  if (patch3.layout !== void 0) next.layout = patch3.layout;
29859
30294
  if (patch3.subtotalPosition !== void 0) next.subtotalPosition = patch3.subtotalPosition;
30295
+ if (patch3.valuesAxis !== void 0) next.valuesAxis = patch3.valuesAxis;
30296
+ if (patch3.valuesPosition !== void 0) next.valuesPosition = patch3.valuesPosition;
30297
+ else if (patch3.valuesAxis === "columns" || patch3.secondRowField === "")
30298
+ delete next.valuesPosition;
30299
+ if (patch3.additionalValues !== void 0) {
30300
+ const measures = normalizedPivotMeasures(patch3.additionalValues);
30301
+ if (measures.length) next.additionalValues = measures;
30302
+ else delete next.additionalValues;
30303
+ }
29860
30304
  validatePivotFields(next);
29861
30305
  write(ctx, s, next, old);
29862
30306
  }