ooxml-core 1.9.0 → 1.11.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 (202) hide show
  1. package/dist/PptxHandler-DNZHAHUY.cjs +12 -0
  2. package/dist/PptxHandler-E44KDHMQ.mjs +3 -0
  3. package/dist/{PptxHandler-EX4WBIQQ.mjs → PptxHandler-NROFYT2N.mjs} +2 -2
  4. package/dist/automation/index.cjs +3236 -2258
  5. package/dist/automation/index.mjs +3236 -2258
  6. package/dist/{chunk-SWF7KVL5.cjs → chunk-2UVH6RHI.cjs} +1608 -1163
  7. package/dist/{chunk-M76PHYRR.mjs → chunk-7DSZI7S6.mjs} +1 -1
  8. package/dist/{chunk-AT66SA5M.cjs → chunk-7QZGRB3T.cjs} +28 -10
  9. package/dist/chunk-ANZ4Q6I3.cjs +21 -0
  10. package/dist/{chunk-CPKNMQLX.cjs → chunk-AWIDASUW.cjs} +25 -2
  11. package/dist/{chunk-SVQZXP3F.mjs → chunk-CBNKBVX5.mjs} +25 -2
  12. package/dist/{chunk-FIELY5PI.mjs → chunk-EC2W2MDY.mjs} +30 -2
  13. package/dist/chunk-EGTRL3QJ.mjs +19 -0
  14. package/dist/chunk-GXHKNSZX.mjs +9 -0
  15. package/dist/{chunk-OXHMZS7B.mjs → chunk-HCXUI5UC.mjs} +943 -273
  16. package/dist/chunk-HDQXPSHY.cjs +17 -0
  17. package/dist/chunk-KTYBFGEY.mjs +14 -0
  18. package/dist/chunk-QOO36KG4.cjs +42 -0
  19. package/dist/chunk-R2KZXD6U.mjs +39 -0
  20. package/dist/{chunk-IGOA57LE.mjs → chunk-U2DF3EGK.mjs} +1 -1
  21. package/dist/{chunk-OB277ZGE.mjs → chunk-UAY26XOI.mjs} +27 -9
  22. package/dist/{chunk-WSO4T2LJ.mjs → chunk-W5ARCUJB.mjs} +26 -3
  23. package/dist/chunk-XZPZHXV4.cjs +12 -0
  24. package/dist/{chunk-LCS3J3QI.mjs → chunk-YB5SRNFS.mjs} +717 -272
  25. package/dist/docx/layout/adapt-table.d.ts +2 -2
  26. package/dist/docx/layout/adapt-table.d.ts.map +1 -1
  27. package/dist/docx/layout/flow-table.d.ts.map +1 -1
  28. package/dist/docx/layout/index.cjs +554 -83
  29. package/dist/docx/layout/index.mjs +554 -84
  30. package/dist/docx/layout/nested-fragment-edges.d.ts +9 -0
  31. package/dist/docx/layout/nested-fragment-edges.d.ts.map +1 -0
  32. package/dist/docx/layout/nested-frame-profile.d.ts +9 -0
  33. package/dist/docx/layout/nested-frame-profile.d.ts.map +1 -0
  34. package/dist/docx/layout/page-cursor.d.ts +2 -0
  35. package/dist/docx/layout/page-cursor.d.ts.map +1 -1
  36. package/dist/docx/layout/result.d.ts +20 -0
  37. package/dist/docx/layout/result.d.ts.map +1 -1
  38. package/dist/docx/layout/table-border-layout.d.ts +16 -0
  39. package/dist/docx/layout/table-border-layout.d.ts.map +1 -0
  40. package/dist/docx/layout/table-cell-layout.d.ts +3 -2
  41. package/dist/docx/layout/table-cell-layout.d.ts.map +1 -1
  42. package/dist/docx/layout/table-content.d.ts +4 -0
  43. package/dist/docx/layout/table-content.d.ts.map +1 -0
  44. package/dist/docx/layout/table-footnotes.d.ts +5 -0
  45. package/dist/docx/layout/table-footnotes.d.ts.map +1 -1
  46. package/dist/docx/layout/table-frames.d.ts +4 -0
  47. package/dist/docx/layout/table-frames.d.ts.map +1 -0
  48. package/dist/docx/layout/table-layout.d.ts +8 -3
  49. package/dist/docx/layout/table-layout.d.ts.map +1 -1
  50. package/dist/docx/layout/table-note-completion.d.ts +5 -0
  51. package/dist/docx/layout/table-note-completion.d.ts.map +1 -0
  52. package/dist/docx/layout/table-note-stories.d.ts +6 -0
  53. package/dist/docx/layout/table-note-stories.d.ts.map +1 -0
  54. package/dist/pptx/automation/index.cjs +801 -296
  55. package/dist/pptx/automation/index.d.ts +5 -4
  56. package/dist/pptx/automation/index.d.ts.map +1 -1
  57. package/dist/pptx/automation/index.mjs +5 -5
  58. package/dist/pptx/chunks/{text-operations-BLodkuXE.d.ts → elements-DD3UGOMd.d.ts} +27 -3248
  59. package/dist/pptx/chunks/elements-DD3UGOMd.d.ts.map +1 -0
  60. package/dist/pptx/chunks/{index-B4cnSPNz.d.ts → index-BZrFyNtU.d.ts} +113 -5
  61. package/dist/pptx/chunks/index-BZrFyNtU.d.ts.map +1 -0
  62. package/dist/pptx/chunks/{index-BZh-IMkN.d.ts → index-DdX02BSm.d.ts} +19 -3
  63. package/dist/pptx/chunks/index-DdX02BSm.d.ts.map +1 -0
  64. package/dist/pptx/chunks/smart-art-ENMMEbmW.d.ts +1512 -0
  65. package/dist/pptx/chunks/smart-art-ENMMEbmW.d.ts.map +1 -0
  66. package/dist/pptx/chunks/text-D49FKllA.d.ts +1473 -0
  67. package/dist/pptx/chunks/text-D49FKllA.d.ts.map +1 -0
  68. package/dist/pptx/chunks/text-operations-CyMTMfID.d.ts +3261 -0
  69. package/dist/pptx/chunks/text-operations-CyMTMfID.d.ts.map +1 -0
  70. package/dist/pptx/cli/index.cjs +801 -296
  71. package/dist/pptx/cli/index.d.ts +1 -1
  72. package/dist/pptx/cli/index.mjs +4 -4
  73. package/dist/pptx/converter/index.cjs +1 -0
  74. package/dist/pptx/converter/index.d.ts +1 -1
  75. package/dist/pptx/converter/index.mjs +2 -2
  76. package/dist/pptx/editor/render/collaboration-live-patch-target.cjs +2 -2
  77. package/dist/pptx/editor/render/collaboration-live-patch-target.mjs +1 -1
  78. package/dist/pptx/editor/render/find-replace.cjs +19 -18
  79. package/dist/pptx/editor/render/find-replace.d.ts +2 -2
  80. package/dist/pptx/editor/render/find-replace.mjs +3 -2
  81. package/dist/pptx/editor/render/font-family-update.cjs +14 -0
  82. package/dist/pptx/editor/render/font-family-update.d.ts +17 -0
  83. package/dist/pptx/editor/render/font-family-update.d.ts.map +1 -0
  84. package/dist/pptx/editor/render/font-family-update.mjs +1 -0
  85. package/dist/pptx/editor/render/paragraph-geometry-overrides.cjs +14 -0
  86. package/dist/pptx/editor/render/paragraph-geometry-overrides.d.ts +17 -0
  87. package/dist/pptx/editor/render/paragraph-geometry-overrides.d.ts.map +1 -0
  88. package/dist/pptx/editor/render/paragraph-geometry-overrides.mjs +12 -0
  89. package/dist/pptx/editor/render/remap-text.cjs +2 -2
  90. package/dist/pptx/editor/render/remap-text.d.ts.map +1 -1
  91. package/dist/pptx/editor/render/remap-text.mjs +1 -1
  92. package/dist/pptx/editor/render/slide-operations.cjs +9 -8
  93. package/dist/pptx/editor/render/slide-operations.mjs +3 -2
  94. package/dist/pptx/editor/render/table-data-grid-ops.cjs +1 -1
  95. package/dist/pptx/editor/render/table-data-grid-ops.mjs +1 -1
  96. package/dist/pptx/editor/render/text-content-style.cjs +18 -0
  97. package/dist/pptx/editor/render/text-content-style.d.ts +9 -0
  98. package/dist/pptx/editor/render/text-content-style.d.ts.map +1 -0
  99. package/dist/pptx/editor/render/text-content-style.mjs +5 -0
  100. package/dist/pptx/editor/render/text-runs-style-patch.cjs +17 -0
  101. package/dist/pptx/editor/render/text-runs-style-patch.d.ts +7 -0
  102. package/dist/pptx/editor/render/text-runs-style-patch.d.ts.map +1 -0
  103. package/dist/pptx/editor/render/text-runs-style-patch.mjs +15 -0
  104. package/dist/pptx/editor/render/text-style-scope.cjs +173 -0
  105. package/dist/pptx/editor/render/text-style-scope.d.ts +76 -0
  106. package/dist/pptx/editor/render/text-style-scope.d.ts.map +1 -0
  107. package/dist/pptx/editor/render/text-style-scope.mjs +164 -0
  108. package/dist/pptx/editor/render/theme-editor-model.cjs +1 -1
  109. package/dist/pptx/editor/render/theme-editor-model.mjs +1 -1
  110. package/dist/pptx/editor/render/update-text-segment-style.cjs +11 -0
  111. package/dist/pptx/editor/render/update-text-segment-style.d.ts +14 -0
  112. package/dist/pptx/editor/render/update-text-segment-style.d.ts.map +1 -0
  113. package/dist/pptx/editor/render/update-text-segment-style.mjs +2 -0
  114. package/dist/pptx/index.cjs +1091 -296
  115. package/dist/pptx/index.d.ts +7 -5
  116. package/dist/pptx/index.mjs +5 -5
  117. package/dist/pptx/smartart-layouts/index.d.ts +1 -1
  118. package/dist/teams/index.cjs +590 -122
  119. package/dist/teams/index.mjs +590 -122
  120. package/dist/visio/date-cache.d.ts +3 -0
  121. package/dist/visio/date-cache.d.ts.map +1 -0
  122. package/dist/visio/edit-commands.d.ts +3 -3
  123. package/dist/visio/edit-commands.d.ts.map +1 -1
  124. package/dist/visio/edit-formatting-scope.d.ts.map +1 -1
  125. package/dist/visio/edit-recalculate-index.d.ts.map +1 -1
  126. package/dist/visio/edit-text-field-commands.d.ts +15 -0
  127. package/dist/visio/edit-text-field-commands.d.ts.map +1 -1
  128. package/dist/visio/edit-text-field.d.ts +2 -2
  129. package/dist/visio/edit-text-field.d.ts.map +1 -1
  130. package/dist/visio/edit.d.ts +1 -1
  131. package/dist/visio/edit.d.ts.map +1 -1
  132. package/dist/visio/index.cjs +501 -220
  133. package/dist/visio/index.d.ts +1 -1
  134. package/dist/visio/index.d.ts.map +1 -1
  135. package/dist/visio/index.mjs +501 -220
  136. package/dist/visio/model.d.ts +6 -0
  137. package/dist/visio/model.d.ts.map +1 -1
  138. package/dist/visio/shape-metadata.d.ts.map +1 -1
  139. package/dist/visio/shapes.d.ts.map +1 -1
  140. package/dist/visio/style.d.ts +1 -1
  141. package/dist/visio/style.d.ts.map +1 -1
  142. package/dist/visio/text-field-display.d.ts +3 -0
  143. package/dist/visio/text-field-display.d.ts.map +1 -1
  144. package/dist/visio/text-field-editability.d.ts +6 -0
  145. package/dist/visio/text-field-editability.d.ts.map +1 -0
  146. package/dist/visio/text-field-fraction.d.ts +3 -0
  147. package/dist/visio/text-field-fraction.d.ts.map +1 -0
  148. package/dist/visio/text-field-independent.d.ts +4 -0
  149. package/dist/visio/text-field-independent.d.ts.map +1 -0
  150. package/dist/visio/text-field-numeric.d.ts +1 -1
  151. package/dist/visio/text-field-numeric.d.ts.map +1 -1
  152. package/dist/visio/text-field-source.d.ts +6 -0
  153. package/dist/visio/text-field-source.d.ts.map +1 -0
  154. package/dist/visio/text-field-system-date.d.ts +4 -0
  155. package/dist/visio/text-field-system-date.d.ts.map +1 -0
  156. package/dist/visio/text-fields.d.ts +1 -0
  157. package/dist/visio/text-fields.d.ts.map +1 -1
  158. package/dist/visio/ui/edit-commands.d.ts.map +1 -1
  159. package/dist/visio/ui/index.cjs +514 -221
  160. package/dist/visio/ui/index.mjs +514 -221
  161. package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
  162. package/dist/visio/ui/text-field-catalog.d.ts.map +1 -1
  163. package/dist/xlsx/edit/pivots.d.ts.map +1 -1
  164. package/dist/xlsx/index.cjs +1362 -659
  165. package/dist/xlsx/index.mjs +1361 -660
  166. package/dist/xlsx/load/index.cjs +1091 -430
  167. package/dist/xlsx/load/index.mjs +1091 -430
  168. package/dist/xlsx/model-pivots.d.ts +31 -2
  169. package/dist/xlsx/model-pivots.d.ts.map +1 -1
  170. package/dist/xlsx/pivot/admission.d.ts.map +1 -1
  171. package/dist/xlsx/pivot/aggregate.d.ts +3 -1
  172. package/dist/xlsx/pivot/aggregate.d.ts.map +1 -1
  173. package/dist/xlsx/pivot/data.d.ts +2 -2
  174. package/dist/xlsx/pivot/data.d.ts.map +1 -1
  175. package/dist/xlsx/pivot/hierarchy-first.d.ts +21 -0
  176. package/dist/xlsx/pivot/hierarchy-first.d.ts.map +1 -0
  177. package/dist/xlsx/pivot/hierarchy.d.ts +2 -4
  178. package/dist/xlsx/pivot/hierarchy.d.ts.map +1 -1
  179. package/dist/xlsx/pivot/index.d.ts +2 -0
  180. package/dist/xlsx/pivot/index.d.ts.map +1 -1
  181. package/dist/xlsx/pivot/measures.d.ts +13 -0
  182. package/dist/xlsx/pivot/measures.d.ts.map +1 -0
  183. package/dist/xlsx/pivot/page-filter-admission.d.ts +5 -0
  184. package/dist/xlsx/pivot/page-filter-admission.d.ts.map +1 -0
  185. package/dist/xlsx/pivot/page-filter.d.ts +11 -0
  186. package/dist/xlsx/pivot/page-filter.d.ts.map +1 -0
  187. package/dist/xlsx/pivot/read.d.ts.map +1 -1
  188. package/dist/xlsx/pivot/table-xml.d.ts.map +1 -1
  189. package/dist/xlsx/pivot/values-axis.d.ts +12 -0
  190. package/dist/xlsx/pivot/values-axis.d.ts.map +1 -0
  191. package/dist/xlsx/ui/commands/i18n/navigation.d.ts.map +1 -1
  192. package/dist/xlsx/ui/commands/i18n/pivots.d.ts.map +1 -1
  193. package/dist/xlsx/ui/index.cjs +640 -137
  194. package/dist/xlsx/ui/index.mjs +640 -137
  195. package/package.json +2 -2
  196. package/dist/PptxHandler-AT7FVG5Q.mjs +0 -2
  197. package/dist/PptxHandler-VFSCECPL.cjs +0 -11
  198. package/dist/pptx/chunks/index-B4cnSPNz.d.ts.map +0 -1
  199. package/dist/pptx/chunks/index-BZh-IMkN.d.ts.map +0 -1
  200. package/dist/pptx/chunks/smart-art-Q2kZQtHh.d.ts +0 -2970
  201. package/dist/pptx/chunks/smart-art-Q2kZQtHh.d.ts.map +0 -1
  202. package/dist/pptx/chunks/text-operations-BLodkuXE.d.ts.map +0 -1
@@ -1003,7 +1003,7 @@ function i(x, y, z) {
1003
1003
  }
1004
1004
  var T = Array.from(
1005
1005
  { length: 64 },
1006
- (_, index2) => Math.floor(Math.abs(Math.sin(index2 + 1)) * 2 ** 32)
1006
+ (_, index3) => Math.floor(Math.abs(Math.sin(index3 + 1)) * 2 ** 32)
1007
1007
  );
1008
1008
  var SHIFTS = [
1009
1009
  [7, 12, 17, 22],
@@ -2531,7 +2531,7 @@ function toArrayBuffer(bytes) {
2531
2531
  }
2532
2532
  function isCompoundFile(input) {
2533
2533
  const bytes = toBytes(input);
2534
- return bytes.length >= 8 && OLE_MAGIC2.every((value2, index2) => bytes[index2] === value2);
2534
+ return bytes.length >= 8 && OLE_MAGIC2.every((value2, index3) => bytes[index3] === value2);
2535
2535
  }
2536
2536
  function openEncryptedPackage(input) {
2537
2537
  const bytes = toBytes(input);
@@ -3712,7 +3712,7 @@ var PartPatch = class {
3712
3712
  const { root, children: children2 } = scan(xml);
3713
3713
  const kids2 = elements(rootElement);
3714
3714
  if (kids2.length !== children2.length) throw new Error("Property part markup is not supported");
3715
- kids2.forEach((kid, index2) => this.spans.set(kid, children2[index2]));
3715
+ kids2.forEach((kid, index3) => this.spans.set(kid, children2[index3]));
3716
3716
  this.root = root;
3717
3717
  for (const attribute2 of Array.from(rootElement.attributes)) {
3718
3718
  if (attribute2.name === "xmlns") this.defaultNs = attribute2.value;
@@ -3962,7 +3962,7 @@ function writeAppProperties(props, sourceXml) {
3962
3962
  const patch = new PartPatch(xml, root);
3963
3963
  const prior = readKnown(root, ns);
3964
3964
  const ownPrefix = root.prefix ? `${root.prefix}:` : "";
3965
- FIELDS2.forEach(([field, local, kind], index2) => {
3965
+ FIELDS2.forEach(([field, local, kind], index3) => {
3966
3966
  const value2 = props[field];
3967
3967
  const existing = first(root, local, ns.app);
3968
3968
  if (value2 === void 0 || kind === "text" && value2 === "") {
@@ -3976,7 +3976,7 @@ function writeAppProperties(props, sourceXml) {
3976
3976
  patch.setContent(existing, body);
3977
3977
  return;
3978
3978
  }
3979
- const next = FIELDS2.slice(index2 + 1).map(([, name]) => first(root, name, ns.app)).find((node) => node !== void 0);
3979
+ const next = FIELDS2.slice(index3 + 1).map(([, name]) => first(root, name, ns.app)).find((node) => node !== void 0);
3980
3980
  patch.insert(`<${ownPrefix}${local}>${body}</${ownPrefix}${local}>`, next);
3981
3981
  });
3982
3982
  return patch.toString();
@@ -4071,9 +4071,9 @@ function writeCustomProperties(properties2) {
4071
4071
  });
4072
4072
  if (!unique2.length) return void 0;
4073
4073
  const pids = allocateCustomPropertyIds(unique2);
4074
- const body = unique2.map((property, index2) => {
4074
+ const body = unique2.map((property, index3) => {
4075
4075
  const link = property.linkTarget ? ` linkTarget="${escape(property.linkTarget, true)}"` : "";
4076
- return `<property fmtid="${CUSTOM_PROPERTIES_FMTID}" pid="${pids[index2] ?? index2 + 2}" name="${escape(property.name, true)}"${link}>${variantXml(property)}</property>`;
4076
+ return `<property fmtid="${CUSTOM_PROPERTIES_FMTID}" pid="${pids[index3] ?? index3 + 2}" name="${escape(property.name, true)}"${link}>${variantXml(property)}</property>`;
4077
4077
  }).join("");
4078
4078
  return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
4079
4079
  <Properties xmlns="${NS.customProperties}" xmlns:vt="${NS.vt}">${body}</Properties>`;
@@ -5298,10 +5298,10 @@ var MONTH_NAMES = [
5298
5298
  function monthFromName(name) {
5299
5299
  const lower2 = name.toLowerCase();
5300
5300
  if (lower2.length < 3) return void 0;
5301
- const index2 = MONTH_NAMES.findIndex(
5301
+ const index3 = MONTH_NAMES.findIndex(
5302
5302
  (m) => m.startsWith(lower2) || lower2.length > 3 && lower2 === m
5303
5303
  );
5304
- return index2 < 0 ? void 0 : index2 + 1;
5304
+ return index3 < 0 ? void 0 : index3 + 1;
5305
5305
  }
5306
5306
  function fullYear(text) {
5307
5307
  const y = Number(text);
@@ -5528,10 +5528,10 @@ function internStyle(workbook, style2) {
5528
5528
  const known = cache2.get(key);
5529
5529
  if (known !== void 0 && workbook.styles[known] && styleKey(workbook.styles[known]) === key)
5530
5530
  return known;
5531
- const index2 = workbook.styles.findIndex((candidate) => styleKey(candidate) === key);
5532
- if (index2 >= 0) {
5533
- cache2.set(key, index2);
5534
- return index2;
5531
+ const index3 = workbook.styles.findIndex((candidate) => styleKey(candidate) === key);
5532
+ if (index3 >= 0) {
5533
+ cache2.set(key, index3);
5534
+ return index3;
5535
5535
  }
5536
5536
  workbook.styles.push(style2);
5537
5537
  cache2.set(key, workbook.styles.length - 1);
@@ -5638,7 +5638,7 @@ function createWorksheet(name, sheetId) {
5638
5638
  function createWorkbook(options = {}) {
5639
5639
  const names = options.sheets?.length ? options.sheets : ["Sheet1"];
5640
5640
  return {
5641
- sheets: names.map((name, index2) => createWorksheet(name, index2 + 1)),
5641
+ sheets: names.map((name, index3) => createWorksheet(name, index3 + 1)),
5642
5642
  styles: [defaultCellStyle()],
5643
5643
  namedStyles: [{ name: "Normal", style: defaultCellStyle(), builtinId: 0 }],
5644
5644
  definedNames: [],
@@ -6413,9 +6413,99 @@ function sparklineDataRange(workbook, sheet, source2) {
6413
6413
  }
6414
6414
  if (ast.type !== "ref" || !ast.ref || !["cell", "area"].includes(ast.ref.kind) || ast.prefix?.book || ast.prefix?.sheet2 || ast.spill)
6415
6415
  throw new Error("The reference is not valid.");
6416
- const index2 = ast.prefix ? workbook.sheets.findIndex((ws) => ws.name.toLowerCase() === ast.prefix.sheet.toLowerCase()) : sheet;
6417
- if (!workbook.sheets[index2]) throw new Error("The reference is not valid.");
6418
- return { sheet: index2, range: checkedSparklineRange({ start: ast.ref.start, end: ast.ref.end }) };
6416
+ const index3 = ast.prefix ? workbook.sheets.findIndex((ws) => ws.name.toLowerCase() === ast.prefix.sheet.toLowerCase()) : sheet;
6417
+ if (!workbook.sheets[index3]) throw new Error("The reference is not valid.");
6418
+ return { sheet: index3, range: checkedSparklineRange({ start: ast.ref.start, end: ast.ref.end }) };
6419
+ }
6420
+
6421
+ // xlsx/pivot/page-filter.ts
6422
+ function validatePivotPageFilter(pivot) {
6423
+ const filter2 = pivot.pageFilter;
6424
+ const extras = Array.isArray(pivot.additionalValues) ? pivot.additionalValues : [];
6425
+ if (filter2 === void 0) return;
6426
+ if (!filter2 || typeof filter2 !== "object" || Array.isArray(filter2) || Object.keys(filter2).some((key) => key !== "field" && key !== "item") || typeof filter2.field !== "string" || !pivot.fields.includes(filter2.field) || [
6427
+ pivot.rowField,
6428
+ pivot.secondRowField,
6429
+ pivot.columnField,
6430
+ pivot.valueField,
6431
+ ...extras.map((v) => v?.field)
6432
+ ].includes(filter2.field) || pivot.valuesAxis === "rows")
6433
+ throw new Error("Report filters require Values on columns and a separate source field.");
6434
+ if (filter2.item !== void 0 && !(filter2.item === null || typeof filter2.item === "string" || typeof filter2.item === "boolean" || typeof filter2.item === "number" && Number.isFinite(filter2.item) || isCellError(filter2.item) && isErrorCode(filter2.item.error) && Object.keys(filter2.item).length === 1))
6435
+ throw new Error("Choose a cached literal report filter item.");
6436
+ }
6437
+ function pivotPageProjection(pivot) {
6438
+ const filter2 = pivot.pageFilter;
6439
+ if (!filter2) return pivot;
6440
+ const labels = /* @__PURE__ */ new Map();
6441
+ for (const item of pivotItems(pivot, filter2.field)) {
6442
+ const label3 = String(pivotItemLabel(item)).toLowerCase(), key2 = pivotValueKey(item);
6443
+ if (label3 === "(all)" || labels.has(label3) && labels.get(label3) !== key2)
6444
+ throw new Error("Ambiguous report filter item captions are preserved.");
6445
+ labels.set(label3, key2);
6446
+ }
6447
+ if (filter2.item === void 0) return pivot;
6448
+ const index3 = pivot.fields.indexOf(filter2.field), key = pivotValueKey(filter2.item);
6449
+ const records = pivot.records.filter((record) => pivotValueKey(record[index3] ?? null) === key);
6450
+ if (!records.length) throw new Error("The report filter item is missing from the source.");
6451
+ if (JSON.stringify(records[0][index3] ?? null) !== JSON.stringify(filter2.item))
6452
+ throw new Error("Choose an exact cached literal report filter item.");
6453
+ return { ...pivot, records };
6454
+ }
6455
+ function prependPivotPage(grid, pivot) {
6456
+ if (!pivot.pageFilter) return grid;
6457
+ const width = grid.values[0].length;
6458
+ return {
6459
+ ...grid,
6460
+ values: [
6461
+ [
6462
+ pivot.pageFilter.field,
6463
+ pivot.pageFilter.item === void 0 ? "(All)" : pivotItemLabel(pivot.pageFilter.item),
6464
+ ...Array(width - 2).fill(null)
6465
+ ],
6466
+ Array(width).fill(null),
6467
+ ...grid.values
6468
+ ],
6469
+ firstDataRow: grid.firstDataRow + 2,
6470
+ ...grid.firstHeaderRow !== void 0 ? { firstHeaderRow: grid.firstHeaderRow + 2 } : {},
6471
+ ...grid.indents ? { indents: [0, 0, ...grid.indents] } : {}
6472
+ };
6473
+ }
6474
+ var index = (raw2) => raw2 !== null && /^\d+$/.test(raw2.trim()) && Number.isSafeInteger(Number(raw2)) ? Number(raw2) : NaN;
6475
+ function readPivotPageFilter(root, fields, shared) {
6476
+ const list = first(root, "pageFields", NS.x), location = first(root, "location", NS.x);
6477
+ const definitions = children(first(root, "pivotFields", NS.x), "pivotField", NS.x);
6478
+ if (!list) {
6479
+ if (definitions.some((n) => n.getAttribute("axis") === "axisPage") || location?.hasAttribute("rowPageCount") || location?.hasAttribute("colPageCount"))
6480
+ throw new Error("Unmodeled report filter metadata");
6481
+ return;
6482
+ }
6483
+ if (root.getAttribute("multipleFieldFilters") === "1")
6484
+ throw new Error("Multiple report filters are preserved");
6485
+ const pages = children(list, "pageField", NS.x);
6486
+ if (pages.length !== 1 || list.getAttribute("count") !== "1" || location?.getAttribute("rowPageCount") !== "1" || location.getAttribute("colPageCount") !== "1")
6487
+ throw new Error("Only one report filter is modeled");
6488
+ const page = pages[0], field = index(page.getAttribute("fld"));
6489
+ if (page.getAttribute("hier") !== "-1" || !fields[field] || definitions[field]?.getAttribute("axis") !== "axisPage" || definitions.filter((n) => n.getAttribute("axis") === "axisPage").length !== 1)
6490
+ throw new Error("Unsupported report field");
6491
+ const container2 = first(definitions[field], "items", NS.x);
6492
+ const items = children(container2, "item", NS.x);
6493
+ if (!container2 || index(container2.getAttribute("count")) !== items.length || items.filter((n) => n.getAttribute("t") === "default").length !== 1 || items.at(-1)?.getAttribute("t") !== "default" || items.at(-1)?.hasAttribute("x"))
6494
+ throw new Error("Unsupported report field items");
6495
+ const data = items.slice(0, -1).map((item2) => {
6496
+ const i2 = index(item2.getAttribute("x"));
6497
+ if (item2.hasAttribute("t") || !Number.isInteger(i2) || i2 >= shared[field].length)
6498
+ throw new Error("Invalid report cache item");
6499
+ return i2;
6500
+ });
6501
+ if (new Set(data).size !== data.length || data.length !== shared[field].length)
6502
+ throw new Error("Incomplete report cache items");
6503
+ const item = page.getAttribute("item");
6504
+ if (item === null) return { field: fields[field] };
6505
+ const selected2 = index(item);
6506
+ if (!Number.isInteger(selected2) || selected2 >= data.length)
6507
+ throw new Error("Invalid report item selection");
6508
+ return { field: fields[field], item: shared[field][data[selected2]] };
6419
6509
  }
6420
6510
 
6421
6511
  // xlsx/pivot/data.ts
@@ -6424,10 +6514,10 @@ function pivotValueKey(value2) {
6424
6514
  return value2 === null || value2 === "" ? "blank" : isCellError(value2) ? `error:${value2.error}` : `${typeof value2}:${String(value2).toLowerCase()}`;
6425
6515
  }
6426
6516
  function pivotItems(pivot, field) {
6427
- const index2 = pivot.fields.indexOf(field);
6517
+ const index3 = pivot.fields.indexOf(field);
6428
6518
  const items = /* @__PURE__ */ new Map();
6429
6519
  for (const record of pivot.records) {
6430
- const value2 = record[index2] ?? null;
6520
+ const value2 = record[index3] ?? null;
6431
6521
  const key = pivotValueKey(value2);
6432
6522
  if (!items.has(key)) items.set(key, value2);
6433
6523
  }
@@ -6445,35 +6535,209 @@ function pivotItemLabel(value2) {
6445
6535
  return isCellError(value2) ? value2.error : value2;
6446
6536
  }
6447
6537
  function validatePivotFields(pivot) {
6538
+ validatePivotPageFilter(pivot);
6448
6539
  const used = [
6449
6540
  pivot.rowField,
6450
6541
  ...pivot.secondRowField ? [pivot.secondRowField] : [],
6451
6542
  ...pivot.columnField ? [pivot.columnField] : [],
6452
6543
  pivot.valueField
6453
6544
  ];
6545
+ const extras = pivot.additionalValues ?? [];
6546
+ if (pivot.valuesAxis !== void 0 && !["columns", "rows"].includes(pivot.valuesAxis))
6547
+ throw new Error("Choose a valid Values axis.");
6548
+ if (pivot.valuesPosition !== void 0 && !["last", "between", "first"].includes(pivot.valuesPosition))
6549
+ throw new Error("Choose a valid Values position.");
6550
+ if ((pivot.valuesPosition === "between" || pivot.valuesPosition === "first") && (pivot.valuesAxis !== "rows" || !pivot.secondRowField))
6551
+ throw new Error("Values before or between fields require two row fields and Values on rows.");
6552
+ if (pivot.valuesAxis === "rows" && (!Array.isArray(extras) || !extras.length))
6553
+ throw new Error("Values on rows require multiple measures.");
6554
+ if (extras.length > 0 && pivot.sourceXml && parseXml(pivot.sourceXml).documentElement.getAttribute("dataCaption") !== "Values")
6555
+ throw new Error("This PivotTable uses unsupported Values header captions.");
6556
+ if (!Array.isArray(extras) || extras.length > 15 || extras.some(
6557
+ (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())
6558
+ ) || new Set(
6559
+ [pivot.valueCaption, ...extras.map((measure) => measure.caption)].map(
6560
+ (caption) => caption?.toLowerCase()
6561
+ )
6562
+ ).size !== extras.length + 1)
6563
+ throw new Error("Choose PivotTable value fields with valid aggregates and unique captions.");
6454
6564
  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")
6455
6565
  throw new Error("Choose valid PivotTable fields; row and column fields must differ.");
6456
6566
  }
6457
6567
 
6568
+ // xlsx/pivot/measures.ts
6569
+ var pivotMeasures = (pivot) => [
6570
+ { field: pivot.valueField, aggregate: pivot.aggregate, caption: pivot.valueCaption },
6571
+ ...pivot.additionalValues ?? []
6572
+ ];
6573
+ function aggregate(records, field, type) {
6574
+ if (!records.length) return null;
6575
+ const values2 = records.map((record) => record[field] ?? null);
6576
+ if (type === "count") return values2.filter((value2) => value2 !== null && value2 !== "").length;
6577
+ const error = values2.find(isCellError);
6578
+ if (error) return error;
6579
+ const numbers3 = values2.filter((value2) => typeof value2 === "number");
6580
+ if (!numbers3.length) return type === "average" ? { error: "#DIV/0!" } : 0;
6581
+ if (type === "min") return numbers3.reduce((a2, b) => Math.min(a2, b));
6582
+ if (type === "max") return numbers3.reduce((a2, b) => Math.max(a2, b));
6583
+ const sum2 = numbers3.reduce((total2, value2) => total2 + value2, 0);
6584
+ return type === "average" ? sum2 / numbers3.length : sum2;
6585
+ }
6586
+ var pivotMeasureNumber = (pivot, records, measure) => aggregate(records, pivot.fields.indexOf(measure.field), measure.aggregate);
6587
+ var pivotNumbers = (pivot, records) => pivotMeasures(pivot).map((measure) => pivotMeasureNumber(pivot, records, measure));
6588
+ function pivotHeaderDimensions(pivot, columnItems, rowLabels) {
6589
+ const measures = 1 + (pivot.additionalValues?.length ?? 0);
6590
+ if (pivot.valuesAxis === "rows")
6591
+ return {
6592
+ rows: (pivot.columnField ? 2 : 1) + (pivot.pageFilter ? 2 : 0),
6593
+ width: rowLabels + (pivot.columnField ? columnItems + 1 : 1)
6594
+ };
6595
+ return {
6596
+ rows: (pivot.columnField ? measures > 1 ? 3 : 2 : 1) + (pivot.pageFilter ? 2 : 0),
6597
+ width: rowLabels + (pivot.columnField ? measures === 1 ? Math.max(1, columnItems) + 1 : (columnItems + 1) * measures : measures)
6598
+ };
6599
+ }
6600
+ function pivotHeaders(pivot, columns, labels, label3) {
6601
+ const measures = pivotMeasures(pivot);
6602
+ if (pivot.valuesAxis === "rows") {
6603
+ const rowLabels = pivot.layout === "compact" ? ["Row Labels"] : pivot.valuesPosition === "first" ? ["Values", ...labels] : pivot.valuesPosition === "between" ? [labels[0], "Values", labels[1]] : [...labels, "Values"];
6604
+ return pivot.columnField ? [
6605
+ [
6606
+ ...rowLabels.map(() => null),
6607
+ pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
6608
+ ...columns.map(() => null)
6609
+ ],
6610
+ [...rowLabels, ...columns.map(label3), "Grand Total"]
6611
+ ] : [[...rowLabels, null]];
6612
+ }
6613
+ if (!pivot.columnField) return [[...labels, ...measures.map((measure) => measure.caption)]];
6614
+ if (measures.length === 1)
6615
+ return [
6616
+ [
6617
+ pivot.valueCaption,
6618
+ ...labels.slice(1).map(() => null),
6619
+ pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
6620
+ ...columns.slice(1).map(() => null),
6621
+ null
6622
+ ],
6623
+ [...labels, ...columns.map(label3), "Grand Total"]
6624
+ ];
6625
+ const { width } = pivotHeaderDimensions(pivot, columns.length, labels.length);
6626
+ const first2 = Array(width).fill(null);
6627
+ first2[labels.length] = pivot.layout === "compact" ? "Column Labels" : pivot.columnField;
6628
+ if (pivot.layout !== "compact") first2[labels.length + 1] = "Values";
6629
+ return [
6630
+ first2,
6631
+ [
6632
+ ...labels.map(() => null),
6633
+ ...columns.flatMap((column) => [label3(column), ...measures.slice(1).map(() => null)]),
6634
+ ...measures.map((measure) => `Total ${measure.caption}`)
6635
+ ],
6636
+ [
6637
+ ...labels,
6638
+ ...columns.flatMap(() => measures.map((measure) => measure.caption)),
6639
+ ...measures.map(() => null)
6640
+ ]
6641
+ ];
6642
+ }
6643
+
6644
+ // xlsx/pivot/hierarchy-first.ts
6645
+ function appendFirstPivotValues(pivot, context) {
6646
+ const {
6647
+ rowItems,
6648
+ secondRowItems,
6649
+ columnItems,
6650
+ children: children2,
6651
+ innerIndices,
6652
+ groups,
6653
+ details,
6654
+ buckets,
6655
+ width,
6656
+ rowLabels,
6657
+ top,
6658
+ bottom,
6659
+ append
6660
+ } = context;
6661
+ const compact = pivot.layout === "compact";
6662
+ const tabular = !pivot.layout || pivot.layout === "tabular";
6663
+ const blank = () => Array(width - rowLabels).fill(null);
6664
+ pivotMeasures(pivot).forEach((measure, m) => {
6665
+ const numbers3 = (keys, records) => [
6666
+ ...columnItems.map(
6667
+ (column) => pivotMeasureNumber(
6668
+ pivot,
6669
+ buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
6670
+ measure
6671
+ )
6672
+ ),
6673
+ pivotMeasureNumber(pivot, records, measure)
6674
+ ];
6675
+ if (!tabular)
6676
+ append([measure.caption, ...Array(rowLabels - 1).fill(null)], blank(), {
6677
+ indices: [m],
6678
+ measure: m
6679
+ });
6680
+ let first2 = true;
6681
+ rowItems.forEach((outer, outerIndex) => {
6682
+ const key = pivotValueKey(outer);
6683
+ const group = groups.get(key) ?? [];
6684
+ if (!tabular)
6685
+ append(
6686
+ compact ? [pivotItemLabel(outer)] : [null, pivotItemLabel(outer), null],
6687
+ top ? numbers3([key], group) : blank(),
6688
+ { indices: [m, outerIndex], measure: m },
6689
+ compact ? 1 : 0
6690
+ );
6691
+ const innerKeys = [...children2.get(key)].sort(
6692
+ (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
6693
+ );
6694
+ innerKeys.forEach((innerKey, child4) => {
6695
+ const innerIndex = innerIndices.get(innerKey);
6696
+ append(
6697
+ compact ? [pivotItemLabel(secondRowItems[innerIndex])] : [
6698
+ tabular && first2 ? measure.caption : null,
6699
+ pivot.repeatLabels || tabular && child4 === 0 ? pivotItemLabel(outer) : null,
6700
+ pivotItemLabel(secondRowItems[innerIndex])
6701
+ ],
6702
+ numbers3([key, innerKey], details.get(JSON.stringify([key, innerKey]))),
6703
+ { indices: [m, outerIndex, innerIndex], measure: m },
6704
+ compact ? 2 : 0
6705
+ );
6706
+ first2 = false;
6707
+ });
6708
+ if (bottom)
6709
+ append(
6710
+ compact ? [`${String(pivotItemLabel(outer))} Total`] : [null, `${String(pivotItemLabel(outer))} Total`, null],
6711
+ numbers3([key], group),
6712
+ { indices: [m, outerIndex], measure: m, type: "default" },
6713
+ compact ? 1 : 0
6714
+ );
6715
+ });
6716
+ });
6717
+ }
6718
+
6458
6719
  // xlsx/pivot/hierarchy.ts
6459
6720
  var label = pivotItemLabel;
6460
- function hierarchicalPivotGrid(pivot, aggregate3) {
6721
+ function hierarchicalPivotGrid(pivot) {
6461
6722
  const rowItems = pivotItems(pivot, pivot.rowField);
6462
6723
  const secondRowItems = pivotItems(pivot, pivot.secondRowField);
6463
6724
  const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
6464
6725
  const outerField = pivot.fields.indexOf(pivot.rowField);
6465
6726
  const innerField = pivot.fields.indexOf(pivot.secondRowField);
6466
6727
  const columnField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
6467
- const valueField = pivot.fields.indexOf(pivot.valueField);
6468
6728
  const layout3 = pivot.layout ?? "tabular";
6469
6729
  const compact = layout3 === "compact";
6470
- const top = layout3 !== "tabular" && pivot.subtotals !== false && (pivot.subtotalPosition ?? "top") === "top";
6730
+ const rowsAxis = pivot.valuesAxis === "rows";
6731
+ const firstValues = rowsAxis && pivot.valuesPosition === "first";
6732
+ const between = rowsAxis && pivot.valuesPosition === "between";
6733
+ const measures = pivotMeasures(pivot);
6734
+ const top = (!rowsAxis || firstValues) && layout3 !== "tabular" && pivot.subtotals !== false && (pivot.subtotalPosition ?? "top") === "top";
6471
6735
  const bottom = pivot.subtotals !== false && !top;
6472
- const rowLabelColumns = compact ? 1 : 2;
6736
+ const rowLabelColumns = compact ? 1 : rowsAxis ? 3 : 2;
6473
6737
  const groups = /* @__PURE__ */ new Map();
6474
6738
  const details = /* @__PURE__ */ new Map();
6475
6739
  const children2 = /* @__PURE__ */ new Map();
6476
- const innerIndices = new Map(secondRowItems.map((item, index2) => [pivotValueKey(item), index2]));
6740
+ const innerIndices = new Map(secondRowItems.map((item, index3) => [pivotValueKey(item), index3]));
6477
6741
  const buckets = /* @__PURE__ */ new Map();
6478
6742
  const collect = (map, key, record) => {
6479
6743
  const list = map.get(key);
@@ -6493,20 +6757,12 @@ function hierarchicalPivotGrid(pivot, aggregate3) {
6493
6757
  collect(buckets, JSON.stringify([...key, column]), record);
6494
6758
  }
6495
6759
  }
6496
- const rows = details.size + rowItems.length * (Number(layout3 !== "tabular") + Number(bottom)) + 3;
6497
- if (rows * (columnItems.length + 3) > 1e6)
6498
- throw new Error("The PivotTable result is too large.");
6760
+ const dimensions = pivotHeaderDimensions(pivot, columnItems.length, rowLabelColumns);
6761
+ const rows = (details.size + rowItems.length * Number(bottom) + 1) * (rowsAxis ? measures.length : 1) + rowItems.length * Number(layout3 !== "tabular") * (firstValues ? measures.length : 1) + (firstValues ? measures.length : between ? rowItems.length * measures.length : details.size) * Number(rowsAxis && layout3 !== "tabular") + dimensions.rows;
6762
+ if (rows * dimensions.width > 1e6) throw new Error("The PivotTable result is too large.");
6499
6763
  const labels = compact ? ["Row Labels"] : [pivot.rowField, pivot.secondRowField];
6500
- const values2 = pivot.columnField ? [
6501
- [
6502
- pivot.valueCaption,
6503
- ...compact ? [] : [null],
6504
- compact ? "Column Labels" : pivot.columnField,
6505
- ...columnItems.slice(1).map(() => null),
6506
- null
6507
- ],
6508
- [...labels, ...columnItems.map(label), "Grand Total"]
6509
- ] : [[...labels, pivot.valueCaption]];
6764
+ const values2 = pivotHeaders(pivot, columnItems, labels, label);
6765
+ const firstDataRow = values2.length;
6510
6766
  const indents = values2.map(() => 0);
6511
6767
  const rowEntries = [];
6512
6768
  const append = (labels2, numbers4, entry3, indent = 0) => {
@@ -6514,91 +6770,187 @@ function hierarchicalPivotGrid(pivot, aggregate3) {
6514
6770
  rowEntries.push(entry3);
6515
6771
  indents.push(indent);
6516
6772
  };
6517
- const numbers3 = (keys, records) => [
6773
+ const bands = (keys, records) => [
6518
6774
  ...columnItems.map(
6519
- (column) => aggregate3(
6520
- buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
6521
- valueField,
6522
- pivot.aggregate
6523
- )
6775
+ (column) => pivotNumbers(pivot, buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [])
6524
6776
  ),
6525
- aggregate3(records, valueField, pivot.aggregate)
6777
+ pivotNumbers(pivot, records)
6526
6778
  ];
6527
- rowItems.forEach((outer, outerIndex) => {
6528
- const key = pivotValueKey(outer);
6529
- if (layout3 !== "tabular")
6530
- append(
6531
- [label(outer), ...compact ? [] : [null]],
6532
- top ? numbers3([key], groups.get(key) ?? []) : Array(columnItems.length + 1).fill(null),
6533
- { indices: [outerIndex] }
6534
- );
6535
- let first2 = true;
6536
- [...children2.get(key)].sort((a2, b) => innerIndices.get(a2) - innerIndices.get(b)).forEach((innerKey) => {
6537
- const innerIndex = innerIndices.get(innerKey);
6538
- const inner = secondRowItems[innerIndex];
6539
- const keys = [key, innerKey];
6540
- const records = details.get(JSON.stringify(keys));
6541
- if (!records) return;
6542
- append(
6543
- compact ? [label(inner)] : [
6544
- pivot.repeatLabels || layout3 === "tabular" && first2 ? label(outer) : null,
6545
- label(inner)
6779
+ const numbers3 = (keys, records) => bands(keys, records).flat();
6780
+ const appendMeasures = (labels2, keys, records, indices, type) => {
6781
+ const values3 = bands(keys, records);
6782
+ measures.forEach(
6783
+ (measure, m) => append(
6784
+ type ? [
6785
+ `${type === "grand" ? "Total" : String(labels2[0])} ${measure.caption}`,
6786
+ ...Array(rowLabelColumns - 1).fill(null)
6787
+ ] : compact ? [measure.caption] : [
6788
+ ...labels2.map(
6789
+ (label3) => layout3 === "tabular" && m === 0 || pivot.repeatLabels ? label3 : null
6790
+ ),
6791
+ measure.caption
6546
6792
  ],
6547
- numbers3(keys, records),
6548
- { indices: [outerIndex, innerIndex] },
6549
- compact ? 1 : 0
6550
- );
6551
- first2 = false;
6793
+ values3.map((band) => band[m] ?? null),
6794
+ { indices: type ? indices : [...indices, m], measure: m, ...type ? { type } : {} },
6795
+ compact && !type ? 2 : 0
6796
+ )
6797
+ );
6798
+ };
6799
+ if (firstValues)
6800
+ appendFirstPivotValues(pivot, {
6801
+ rowItems,
6802
+ secondRowItems,
6803
+ columnItems,
6804
+ children: children2,
6805
+ innerIndices,
6806
+ groups,
6807
+ details,
6808
+ buckets,
6809
+ width: dimensions.width,
6810
+ rowLabels: rowLabelColumns,
6811
+ top,
6812
+ bottom,
6813
+ append
6552
6814
  });
6553
- if (bottom) {
6554
- const caption = String(label(outer));
6555
- append(
6556
- [`${caption} Total`, ...compact ? [] : [null]],
6557
- numbers3([key], groups.get(key) ?? []),
6558
- { indices: [outerIndex], type: "default" }
6815
+ else
6816
+ rowItems.forEach((outer, outerIndex) => {
6817
+ const key = pivotValueKey(outer);
6818
+ if (layout3 !== "tabular")
6819
+ append(
6820
+ [label(outer), ...Array(rowLabelColumns - 1).fill(null)],
6821
+ top ? numbers3([key], groups.get(key) ?? []) : Array(dimensions.width - rowLabelColumns).fill(null),
6822
+ { indices: [outerIndex] }
6823
+ );
6824
+ let first2 = true;
6825
+ const innerKeys = [...children2.get(key)].sort(
6826
+ (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
6559
6827
  );
6560
- }
6561
- });
6562
- append(["Grand Total", ...compact ? [] : [null]], numbers3([], pivot.records), {
6563
- indices: [0],
6564
- type: "grand"
6565
- });
6828
+ if (between)
6829
+ measures.forEach((measure, m) => {
6830
+ if (layout3 !== "tabular")
6831
+ append(
6832
+ compact ? [measure.caption] : [pivot.repeatLabels ? label(outer) : null, measure.caption, null],
6833
+ Array(dimensions.width - rowLabelColumns).fill(null),
6834
+ { indices: [outerIndex, m], measure: m },
6835
+ compact ? 1 : 0
6836
+ );
6837
+ innerKeys.forEach((innerKey, child4) => {
6838
+ const innerIndex = innerIndices.get(innerKey);
6839
+ const keys = [key, innerKey];
6840
+ const records = details.get(JSON.stringify(keys));
6841
+ append(
6842
+ compact ? [label(secondRowItems[innerIndex])] : [
6843
+ pivot.repeatLabels || layout3 === "tabular" && m === 0 && child4 === 0 ? label(outer) : null,
6844
+ layout3 === "tabular" && child4 === 0 ? measure.caption : null,
6845
+ label(secondRowItems[innerIndex])
6846
+ ],
6847
+ [
6848
+ ...columnItems.map(
6849
+ (column) => pivotMeasureNumber(
6850
+ pivot,
6851
+ buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
6852
+ measure
6853
+ )
6854
+ ),
6855
+ pivotMeasureNumber(pivot, records, measure)
6856
+ ],
6857
+ { indices: [outerIndex, m, innerIndex], measure: m },
6858
+ compact ? 2 : 0
6859
+ );
6860
+ });
6861
+ });
6862
+ else
6863
+ innerKeys.forEach((innerKey) => {
6864
+ const innerIndex = innerIndices.get(innerKey);
6865
+ const inner = secondRowItems[innerIndex];
6866
+ const keys = [key, innerKey];
6867
+ const records = details.get(JSON.stringify(keys));
6868
+ if (!records) return;
6869
+ if (rowsAxis) {
6870
+ if (layout3 !== "tabular")
6871
+ append(
6872
+ compact ? [label(inner)] : [pivot.repeatLabels ? label(outer) : null, label(inner), null],
6873
+ Array(dimensions.width - rowLabelColumns).fill(null),
6874
+ { indices: [outerIndex, innerIndex] },
6875
+ compact ? 1 : 0
6876
+ );
6877
+ appendMeasures(
6878
+ [pivot.repeatLabels || first2 ? label(outer) : null, label(inner)],
6879
+ keys,
6880
+ records,
6881
+ [outerIndex, innerIndex]
6882
+ );
6883
+ first2 = false;
6884
+ return;
6885
+ }
6886
+ append(
6887
+ compact ? [label(inner)] : [
6888
+ pivot.repeatLabels || layout3 === "tabular" && first2 ? label(outer) : null,
6889
+ label(inner)
6890
+ ],
6891
+ numbers3(keys, records),
6892
+ { indices: [outerIndex, innerIndex] },
6893
+ compact ? 1 : 0
6894
+ );
6895
+ first2 = false;
6896
+ });
6897
+ if (bottom) {
6898
+ if (rowsAxis) {
6899
+ appendMeasures([label(outer)], [key], groups.get(key) ?? [], [outerIndex], "default");
6900
+ return;
6901
+ }
6902
+ const caption = String(label(outer));
6903
+ append(
6904
+ [`${caption} Total`, ...compact ? [] : [null]],
6905
+ numbers3([key], groups.get(key) ?? []),
6906
+ { indices: [outerIndex], type: "default" }
6907
+ );
6908
+ }
6909
+ });
6910
+ if (rowsAxis) appendMeasures([], [], pivot.records, [0], "grand");
6911
+ else
6912
+ append(["Grand Total", ...compact ? [] : [null]], numbers3([], pivot.records), {
6913
+ indices: [0],
6914
+ type: "grand"
6915
+ });
6566
6916
  return {
6567
6917
  values: values2,
6568
6918
  rowItems,
6569
6919
  secondRowItems,
6570
6920
  columnItems,
6571
6921
  rowEntries,
6572
- firstDataRow: pivot.columnField ? 2 : 1,
6922
+ firstDataRow,
6573
6923
  rowLabelColumns,
6574
- indents
6924
+ indents,
6925
+ ...rowsAxis ? { firstHeaderRow: 1 } : {}
6575
6926
  };
6576
6927
  }
6577
6928
 
6578
6929
  // xlsx/pivot/aggregate.ts
6579
- function aggregate(records, field, type) {
6580
- if (!records.length) return null;
6581
- const values2 = records.map((record) => record[field] ?? null);
6582
- if (type === "count") return values2.filter((value2) => value2 !== null && value2 !== "").length;
6583
- const error = values2.find(isCellError);
6584
- if (error) return error;
6585
- const numbers3 = values2.filter((value2) => typeof value2 === "number");
6586
- if (!numbers3.length) return type === "average" ? { error: "#DIV/0!" } : 0;
6587
- if (type === "min") return numbers3.reduce((a2, b) => Math.min(a2, b));
6588
- if (type === "max") return numbers3.reduce((a2, b) => Math.max(a2, b));
6589
- const sum2 = numbers3.reduce((total2, value2) => total2 + value2, 0);
6590
- return type === "average" ? sum2 / numbers3.length : sum2;
6591
- }
6592
6930
  function pivotGrid(pivot) {
6593
6931
  validatePivotFields(pivot);
6594
- if (pivot.secondRowField) return hierarchicalPivotGrid(pivot, aggregate);
6932
+ return prependPivotPage(pivotDataGrid(pivotPageProjection(pivot)), pivot);
6933
+ }
6934
+ function pivotDataGrid(pivot) {
6935
+ if (pivot.secondRowField) return hierarchicalPivotGrid(pivot);
6595
6936
  const rowItems = pivotItems(pivot, pivot.rowField);
6596
6937
  const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
6597
- if ((rowItems.length + 3) * (columnItems.length + 2) > 1e6)
6938
+ const rowsAxis = pivot.valuesAxis === "rows";
6939
+ const compact = pivot.layout === "compact";
6940
+ const headings = rowsAxis && pivot.layout !== void 0 && pivot.layout !== "tabular";
6941
+ const dimensions = pivotHeaderDimensions(pivot, columnItems.length, rowsAxis && !compact ? 2 : 1);
6942
+ const dataRows = (rowItems.length + 1) * (rowsAxis ? 1 + (pivot.additionalValues?.length ?? 0) : 1) + (headings ? rowItems.length : 0);
6943
+ if ((dataRows + dimensions.rows) * dimensions.width > 1e6)
6598
6944
  throw new Error("The PivotTable result is too large.");
6945
+ const label3 = pivotItemLabel;
6946
+ const values2 = pivotHeaders(
6947
+ pivot,
6948
+ columnItems,
6949
+ [pivot.layout === "compact" ? "Row Labels" : pivot.rowField],
6950
+ label3
6951
+ );
6599
6952
  const rowField = pivot.fields.indexOf(pivot.rowField);
6600
6953
  const colField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
6601
- const valueField = pivot.fields.indexOf(pivot.valueField);
6602
6954
  const groups = /* @__PURE__ */ new Map();
6603
6955
  const cells = /* @__PURE__ */ new Map();
6604
6956
  const columns = /* @__PURE__ */ new Map();
@@ -6616,50 +6968,95 @@ function pivotGrid(pivot) {
6616
6968
  collect(cells, JSON.stringify([key, col]), record);
6617
6969
  }
6618
6970
  }
6619
- const label3 = pivotItemLabel;
6620
- const values2 = pivot.columnField ? [
6621
- [
6622
- pivot.valueCaption,
6623
- pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
6624
- ...columnItems.slice(1).map(() => null),
6625
- null
6626
- ],
6627
- [
6628
- pivot.layout === "compact" ? "Row Labels" : pivot.rowField,
6629
- ...columnItems.map(label3),
6630
- "Grand Total"
6631
- ]
6632
- ] : [[pivot.layout === "compact" ? "Row Labels" : pivot.rowField, pivot.valueCaption]];
6971
+ const firstDataRow = values2.length;
6972
+ if (rowsAxis) {
6973
+ const measures = pivotMeasures(pivot);
6974
+ const rowEntries = [];
6975
+ const indents = values2.map(() => 0);
6976
+ const append = (caption, bands, index3, grand = false) => {
6977
+ measures.forEach((measure, m) => {
6978
+ values2.push([
6979
+ ...compact ? [grand ? `Total ${measure.caption}` : measure.caption] : [
6980
+ grand ? `Total ${measure.caption}` : pivot.repeatLabels || !headings && m === 0 ? caption : null,
6981
+ grand ? null : measure.caption
6982
+ ],
6983
+ ...bands.map((band) => band[m] ?? null)
6984
+ ]);
6985
+ indents.push(compact && !grand ? 1 : 0);
6986
+ rowEntries.push({
6987
+ indices: grand ? [0] : [index3, m],
6988
+ measure: m,
6989
+ ...grand ? { type: "grand" } : {}
6990
+ });
6991
+ });
6992
+ };
6993
+ rowItems.forEach((item, index3) => {
6994
+ const key = pivotValueKey(item);
6995
+ if (headings) {
6996
+ values2.push([label3(item), ...Array(dimensions.width - 1).fill(null)]);
6997
+ rowEntries.push({ indices: [index3] });
6998
+ indents.push(0);
6999
+ }
7000
+ append(
7001
+ label3(item),
7002
+ [
7003
+ ...columnItems.map(
7004
+ (col) => pivotNumbers(pivot, cells.get(JSON.stringify([key, pivotValueKey(col)])) ?? [])
7005
+ ),
7006
+ pivotNumbers(pivot, groups.get(key) ?? [])
7007
+ ],
7008
+ index3
7009
+ );
7010
+ });
7011
+ append(
7012
+ "Grand Total",
7013
+ [
7014
+ ...columnItems.map((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
7015
+ pivotNumbers(pivot, pivot.records)
7016
+ ],
7017
+ 0,
7018
+ true
7019
+ );
7020
+ return {
7021
+ values: values2,
7022
+ rowItems,
7023
+ columnItems,
7024
+ firstDataRow,
7025
+ rowLabelColumns: compact ? 1 : 2,
7026
+ indents,
7027
+ firstHeaderRow: 1,
7028
+ rowEntries
7029
+ };
7030
+ }
6633
7031
  for (const row2 of rowItems) {
6634
7032
  const records = groups.get(pivotValueKey(row2)) ?? [];
6635
7033
  values2.push([
6636
7034
  label3(row2),
6637
- ...columnItems.map(
6638
- (col) => aggregate(
6639
- cells.get(JSON.stringify([pivotValueKey(row2), pivotValueKey(col)])) ?? [],
6640
- valueField,
6641
- pivot.aggregate
7035
+ ...columnItems.flatMap(
7036
+ (col) => pivotNumbers(
7037
+ pivot,
7038
+ cells.get(JSON.stringify([pivotValueKey(row2), pivotValueKey(col)])) ?? []
6642
7039
  )
6643
7040
  ),
6644
- aggregate(records, valueField, pivot.aggregate)
7041
+ ...pivotNumbers(pivot, records)
6645
7042
  ]);
6646
7043
  }
6647
7044
  values2.push([
6648
7045
  "Grand Total",
6649
- ...columnItems.map(
6650
- (col) => aggregate(columns.get(pivotValueKey(col)) ?? [], valueField, pivot.aggregate)
6651
- ),
6652
- aggregate(pivot.records, valueField, pivot.aggregate)
7046
+ ...columnItems.flatMap((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
7047
+ ...pivotNumbers(pivot, pivot.records)
6653
7048
  ]);
6654
- return { values: values2, rowItems, columnItems, firstDataRow: pivot.columnField ? 2 : 1 };
7049
+ return { values: values2, rowItems, columnItems, firstDataRow };
6655
7050
  }
6656
7051
 
6657
7052
  // xlsx/pivot/admission.ts
6658
7053
  var X14 = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main";
6659
7054
  var LAYOUT = "http://schemas.microsoft.com/office/spreadsheetml/2016/pivotdefaultlayout";
6660
7055
  var TABLE = {
6661
- pivotTableDefinition: "name cacheId dataCaption updatedVersion minRefreshableVersion createdVersion applyNumberFormats applyBorderFormats applyFontFormats applyPatternFormats applyAlignmentFormats applyWidthHeightFormats useAutoFormatting itemPrintTitles indent compact compactData outline outlineData multipleFieldFilters rowGrandTotals colGrandTotals",
6662
- location: "ref firstHeaderRow firstDataRow firstDataCol",
7056
+ 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",
7057
+ location: "ref firstHeaderRow firstDataRow firstDataCol rowPageCount colPageCount",
7058
+ pageFields: "count",
7059
+ pageField: "fld item hier",
6663
7060
  pivotFields: "count",
6664
7061
  pivotField: "axis dataField compact outline showAll subtotalTop defaultSubtotal",
6665
7062
  items: "count",
@@ -6669,7 +7066,7 @@ var TABLE = {
6669
7066
  field: "x",
6670
7067
  rowItems: "count",
6671
7068
  colItems: "count",
6672
- i: "t r",
7069
+ i: "t r i",
6673
7070
  x: "v",
6674
7071
  dataFields: "count",
6675
7072
  dataField: "name fld subtotal baseField baseItem showDataAs",
@@ -6700,7 +7097,7 @@ function inspect(node, profile, cache2) {
6700
7097
  for (let i2 = 0; i2 < node.attributes.length; i2++) {
6701
7098
  const attr2 = node.attributes.item(i2);
6702
7099
  if (attr2.name.startsWith("xmlns")) continue;
6703
- if (!cache2 && node.namespaceURI === X14 && node.localName === "pivotTableDefinition" && attr2.name === "hideValuesRow" && attr2.value === "1")
7100
+ if (!cache2 && node.namespaceURI === X14 && node.localName === "pivotTableDefinition" && attr2.name === "hideValuesRow" && ["0", "1"].includes(attr2.value))
6704
7101
  continue;
6705
7102
  if (!cache2 && node.namespaceURI === X14 && (node.localName === "pivotField" && attr2.name === "fillDownLabels" || node.localName === "pivotTableDefinition" && attr2.name === "fillDownLabelsDefault") && ["0", "1"].includes(attr2.value))
6706
7103
  continue;
@@ -6729,7 +7126,9 @@ function inspect(node, profile, cache2) {
6729
7126
  throw new Error("Unsupported PivotTable option");
6730
7127
  if (attr2.localName === "numFmtId" && attr2.value !== "0")
6731
7128
  throw new Error("Unsupported PivotTable field number format");
6732
- if (node.localName === "pivotTableDefinition" && ["compact", "compactData", "outline", "outlineData"].includes(attr2.localName) && !["0", "1"].includes(attr2.value))
7129
+ if (node.localName === "pivotTableDefinition" && ["compact", "compactData", "outline", "outlineData", "dataOnRows"].includes(
7130
+ attr2.localName
7131
+ ) && !["0", "1"].includes(attr2.value))
6733
7132
  throw new Error("Unsupported PivotTable global layout");
6734
7133
  if (node.localName === "item" && attr2.localName === "t" && !["default", "data"].includes(attr2.value))
6735
7134
  throw new Error("Unsupported PivotTable subtotal");
@@ -6752,6 +7151,258 @@ function assertPivotRecords(records) {
6752
7151
  );
6753
7152
  }
6754
7153
 
7154
+ // xlsx/write/xml-out.ts
7155
+ var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
7156
+ var CONTROL = "\0-\b\v\f-" + String.fromCharCode(65534, 65535);
7157
+ var NEEDS_ESCAPE = new RegExp(`[${CONTROL}\r]|_x[0-9A-Fa-f]{4}_`);
7158
+ var ESCAPABLE = new RegExp(`[${CONTROL}\r]|_(?=x[0-9A-Fa-f]{4}_)`, "g");
7159
+ function encodeEscapes(text) {
7160
+ if (!NEEDS_ESCAPE.test(text)) return text;
7161
+ return text.replace(
7162
+ ESCAPABLE,
7163
+ (ch) => `_x${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}_`
7164
+ );
7165
+ }
7166
+ var INVALID_XML = new RegExp(`[${CONTROL}]`, "g");
7167
+ var escapeText2 = (text) => text.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
7168
+ var escapeAttr3 = (text) => text.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;");
7169
+ function attrs(values2) {
7170
+ let out = "";
7171
+ for (const [name, value2] of Object.entries(values2)) {
7172
+ if (value2 === void 0) continue;
7173
+ const text = typeof value2 === "boolean" ? value2 ? "1" : "0" : typeof value2 === "number" ? num(value2) : value2;
7174
+ out += ` ${name}="${escapeAttr3(text)}"`;
7175
+ }
7176
+ return out;
7177
+ }
7178
+ var el = (name, values2 = {}, content2 = "") => content2 ? `<${name}${attrs(values2)}>${content2}</${name}>` : `<${name}${attrs(values2)}/>`;
7179
+ var num = (value2) => Object.is(value2, -0) ? "0" : String(value2);
7180
+ function tElement(text, name = "t") {
7181
+ const encoded = escapeText2(encodeEscapes(text));
7182
+ const preserve = /^\s|\s$|\n|\t/.test(text) ? ' xml:space="preserve"' : "";
7183
+ return `<${name}${preserve}>${encoded}</${name}>`;
7184
+ }
7185
+ var MAIN_NS = ' xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"';
7186
+ function inlineFragment(xml) {
7187
+ const end = xml.indexOf(">");
7188
+ if (end < 0) return xml;
7189
+ const head = xml.slice(0, end);
7190
+ return head.includes(MAIN_NS) ? head.replace(MAIN_NS, "") + xml.slice(end) : xml;
7191
+ }
7192
+
7193
+ // xlsx/pivot/values-axis.ts
7194
+ function remapPivotRowEntries(entries, axes2) {
7195
+ return entries.map(
7196
+ (entry3) => entry3.type === "grand" ? entry3 : {
7197
+ ...entry3,
7198
+ indices: entry3.indices.map((item, axis) => {
7199
+ const index3 = axes2[axis]?.[item];
7200
+ if (index3 === void 0) throw new Error("Invalid report row axis item");
7201
+ return index3;
7202
+ })
7203
+ }
7204
+ );
7205
+ }
7206
+ function pivotFieldIndex(field) {
7207
+ const raw2 = field?.getAttribute("x");
7208
+ if (raw2 === null || raw2 === void 0 || !/^-?\d+$/.test(raw2.trim())) return NaN;
7209
+ const value2 = Number(raw2);
7210
+ return Number.isSafeInteger(value2) ? value2 : NaN;
7211
+ }
7212
+ function pivotValueIndex(root, axis) {
7213
+ const index3 = axis.findIndex((field) => pivotFieldIndex(field) === -2);
7214
+ const position = root.getAttribute("dataPosition");
7215
+ if (position !== null && (!/^\d+$/.test(position.trim()) || Number(position) !== index3))
7216
+ throw new Error("Inconsistent Values axis position");
7217
+ if (axis.length === 3 && index3 < 2 && position === null)
7218
+ throw new Error("Missing leading or between-field Values position");
7219
+ return index3;
7220
+ }
7221
+ function pivotValueAxisItems(measures, columns, columnIndices) {
7222
+ const entries = [];
7223
+ if (columns === void 0) {
7224
+ for (let measure = 0; measure < measures; measure++)
7225
+ entries.push(
7226
+ `<i${attrs({ i: measure || void 0 })}><x${attrs({ v: measure || void 0 })}/></i>`
7227
+ );
7228
+ } else {
7229
+ for (let column = 0; column < columns; column++)
7230
+ for (let measure = 0; measure < measures; measure++) {
7231
+ entries.push(
7232
+ `<i${attrs({ r: measure ? 1 : void 0, i: measure || void 0 })}>${measure ? "" : `<x${attrs({ v: (columnIndices?.[column] ?? column) || void 0 })}/>`}<x${attrs({ v: measure || void 0 })}/></i>`
7233
+ );
7234
+ }
7235
+ for (let measure = 0; measure < measures; measure++)
7236
+ entries.push(`<i${attrs({ t: "grand", i: measure || void 0 })}><x/></i>`);
7237
+ }
7238
+ return `<colItems count="${entries.length}">${entries.join("")}</colItems>`;
7239
+ }
7240
+ function supportedPivotAxes(rows, columns, measures, valuesOnRows) {
7241
+ const index3 = pivotFieldIndex;
7242
+ if (valuesOnRows)
7243
+ return measures > 1 && (rows.length === 2 || rows.length === 3) && (index3(rows[0]) >= 0 || rows.length === 3) && rows.filter((field) => index3(field) === -2).length === 1 && rows.filter((field) => index3(field) !== -2).every((field) => index3(field) >= 0) && columns.length <= 1 && (!columns.length || index3(columns[0]) >= 0);
7244
+ if (rows.some((field) => !Number.isInteger(index3(field)) || index3(field) < 0)) return false;
7245
+ return measures === 1 ? columns.length <= 1 : columns.length >= 1 && columns.length <= 2 && index3(columns.at(-1)) === -2 && (columns.length !== 2 || index3(columns[0]) >= 0);
7246
+ }
7247
+
7248
+ // drawingml/dom.ts
7249
+ function attributeReader(element2) {
7250
+ return (name) => {
7251
+ if (!element2) return void 0;
7252
+ const direct = element2.getAttribute(name);
7253
+ if (direct !== null) return direct;
7254
+ const attributes = element2.attributes;
7255
+ for (let index3 = 0; index3 < attributes.length; index3++) {
7256
+ const candidate = attributes.item(index3);
7257
+ if (candidate && candidate.localName === name) return candidate.value;
7258
+ }
7259
+ return void 0;
7260
+ };
7261
+ }
7262
+ function stringAttribute(element2, name) {
7263
+ const value2 = attributeReader(element2)(name)?.trim();
7264
+ return value2 ? value2 : void 0;
7265
+ }
7266
+ function integerAttribute(element2, name) {
7267
+ const parsed = Number.parseInt(attributeReader(element2)(name) ?? "", 10);
7268
+ return Number.isFinite(parsed) ? parsed : void 0;
7269
+ }
7270
+ function booleanAttribute(element2, name) {
7271
+ const value2 = attributeReader(element2)(name)?.trim().toLowerCase();
7272
+ if (value2 === "1" || value2 === "true") return true;
7273
+ if (value2 === "0" || value2 === "false") return false;
7274
+ return void 0;
7275
+ }
7276
+ function descendants2(root, local) {
7277
+ const result2 = [];
7278
+ const visit = (node) => {
7279
+ for (const child4 of Array.from(node.childNodes)) {
7280
+ if (!isElement(child4)) continue;
7281
+ if (child4.localName === local) result2.push(child4);
7282
+ visit(child4);
7283
+ }
7284
+ };
7285
+ visit(root);
7286
+ return result2;
7287
+ }
7288
+
7289
+ // xlsx/pivot/page-filter-admission.ts
7290
+ var integer = (value2, fallback) => value2 === null ? fallback ?? NaN : /^\d+$/.test(value2.trim()) && Number.isSafeInteger(Number(value2)) ? Number(value2) : NaN;
7291
+ function assertPageAxisItems(root, pivot, shared, cache2, recordRoot) {
7292
+ if (!pivot.pageFilter) return;
7293
+ const literals = (node) => {
7294
+ const raw2 = node.getAttribute("v");
7295
+ if (node.localName === "x" && (raw2 === null || !/^\d+$/.test(raw2.trim())) || node.localName === "b" && !["0", "1"].includes(raw2 ?? "") || node.localName === "n" && (raw2 === null || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(raw2.trim())))
7296
+ throw new Error("Unmodeled report cache literal");
7297
+ for (const child4 of elements(node)) literals(child4);
7298
+ };
7299
+ literals(cache2);
7300
+ literals(recordRoot);
7301
+ const cacheFields = children(first(cache2, "cacheFields", NS.x), "cacheField", NS.x);
7302
+ if (pivot.columnField) {
7303
+ const column = children(first(root, "pivotFields", NS.x), "pivotField", NS.x)[pivot.fields.indexOf(pivot.columnField)];
7304
+ const list = first(column, "extLst", NS.x);
7305
+ const extensions = list ? children(list, "ext", NS.x) : [];
7306
+ if (extensions.some(
7307
+ (extension) => children(
7308
+ extension,
7309
+ "pivotField",
7310
+ "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
7311
+ ).some((field) => {
7312
+ const raw2 = field.getAttribute("fillDownLabels");
7313
+ if (raw2 !== null && !["0", "1", "false", "true"].includes(raw2.trim()))
7314
+ throw new Error("Invalid report column label repetition");
7315
+ return booleanAttribute(field, "fillDownLabels") === true;
7316
+ })
7317
+ ))
7318
+ throw new Error("Repeated report column labels are preserved");
7319
+ }
7320
+ if (integer(first(cache2, "cacheFields", NS.x)?.getAttribute("count") ?? null) !== pivot.fields.length || integer(cache2.getAttribute("recordCount")) !== pivot.records.length || integer(recordRoot.getAttribute("count")) !== pivot.records.length)
7321
+ throw new Error("Inconsistent report cache counts");
7322
+ for (const name of [
7323
+ pivot.rowField,
7324
+ pivot.secondRowField,
7325
+ pivot.columnField,
7326
+ pivot.pageFilter.field
7327
+ ].filter(Boolean)) {
7328
+ const field = pivot.fields.indexOf(name);
7329
+ if (integer(first(cacheFields[field], "sharedItems", NS.x)?.getAttribute("count") ?? null) !== shared[field].length)
7330
+ throw new Error("Inconsistent report shared-item counts");
7331
+ }
7332
+ for (const name of ["rowFields", "colFields"]) {
7333
+ const list = first(root, name, NS.x);
7334
+ if (list && integer(list.getAttribute("count")) !== children(list, "field", NS.x).length)
7335
+ throw new Error("Inconsistent report axis counts");
7336
+ }
7337
+ const projected = pivotPageProjection(pivot), fields = children(first(root, "pivotFields", NS.x), "pivotField", NS.x);
7338
+ const axisValues = (name, axis) => {
7339
+ const f6 = pivot.fields.indexOf(name), node = fields[f6], list = first(node, "items", NS.x), items = children(list, "item", NS.x), count2 = shared[f6].length;
7340
+ if (node.getAttribute("axis") !== axis) throw new Error("Inconsistent report axis field");
7341
+ const defaults = node.getAttribute("defaultSubtotal") !== "0";
7342
+ if (!list || integer(list.getAttribute("count")) !== items.length || items.length !== count2 + Number(defaults))
7343
+ throw new Error("Incomplete page-axis field items");
7344
+ const data = items.slice(0, count2).map((item) => {
7345
+ const i2 = integer(item.getAttribute("x"));
7346
+ if (item.hasAttribute("t") || !Number.isInteger(i2) || i2 >= count2)
7347
+ throw new Error("Invalid page-axis cache item");
7348
+ return shared[f6][i2];
7349
+ });
7350
+ if (new Set(data.map(pivotValueKey)).size !== count2 || defaults && (items.at(-1)?.getAttribute("t") !== "default" || items.at(-1)?.hasAttribute("x")))
7351
+ throw new Error("Invalid page-axis default item");
7352
+ const indices = new Map(data.map((v, i2) => [pivotValueKey(v), i2]));
7353
+ return pivotItems(projected, name).map((v) => indices.get(pivotValueKey(v)));
7354
+ };
7355
+ const read = (name) => {
7356
+ const list = first(root, name, NS.x), items = children(list, "i", NS.x);
7357
+ if (!list || integer(list.getAttribute("count")) !== items.length)
7358
+ throw new Error("Invalid page-axis item count");
7359
+ return items;
7360
+ };
7361
+ const rows = axisValues(pivot.rowField, "axisRow"), rowItems = read("rowItems");
7362
+ const grid = pivotGrid(pivot);
7363
+ const entries = grid.rowEntries ? remapPivotRowEntries(grid.rowEntries, [
7364
+ rows,
7365
+ pivot.secondRowField ? axisValues(pivot.secondRowField, "axisRow") : []
7366
+ ]) : [
7367
+ ...rows.map((index3) => ({ indices: [index3], type: void 0 })),
7368
+ { indices: [0], type: "grand" }
7369
+ ];
7370
+ if (rowItems.length !== entries.length) throw new Error("Invalid page row items");
7371
+ let previousRow = [];
7372
+ rowItems.forEach((item, i2) => {
7373
+ const expected2 = entries[i2];
7374
+ const xs = children(item, "x", NS.x).map((x) => integer(x.getAttribute("v"), 0)), prefix = integer(item.getAttribute("r"), 0);
7375
+ if (item.getAttribute("t") !== (expected2.type ?? null) || !Number.isInteger(prefix) || prefix < 0 || prefix > previousRow.length || prefix >= expected2.indices.length || expected2.type && prefix !== 0 || integer(item.getAttribute("i"), 0) !== 0 || JSON.stringify([...previousRow.slice(0, prefix), ...xs]) !== JSON.stringify(expected2.indices))
7376
+ throw new Error("Unmodeled page row item");
7377
+ previousRow = expected2.type ? [] : expected2.indices;
7378
+ });
7379
+ const measures = 1 + (pivot.additionalValues?.length ?? 0), columns = pivot.columnField ? axisValues(pivot.columnField, "axisCol") : void 0, expected = [];
7380
+ if (columns)
7381
+ for (const col of columns)
7382
+ for (let m = 0; m < measures; m++) expected.push(measures > 1 ? [col, m] : [col]);
7383
+ else for (let m = 0; m < measures; m++) expected.push([m]);
7384
+ const colItems = read("colItems");
7385
+ if (colItems.length !== expected.length + (columns ? measures : 0))
7386
+ throw new Error("Invalid page column items");
7387
+ let previous = [];
7388
+ colItems.forEach((item, i2) => {
7389
+ const grand = i2 >= expected.length, measure = grand ? i2 - expected.length : i2 % measures;
7390
+ const xs = children(item, "x", NS.x).map((x) => integer(x.getAttribute("v"), 0)), prefix = integer(item.getAttribute("r"), 0);
7391
+ if (integer(item.getAttribute("i"), 0) !== measure || !Number.isInteger(prefix) || prefix < 0 || prefix > Math.max(0, previous.length - 1))
7392
+ throw new Error("Invalid page column prefix");
7393
+ if (grand) {
7394
+ if (item.getAttribute("t") !== "grand" || prefix !== 0 || xs.length !== 1 || xs[0] !== 0)
7395
+ throw new Error("Unmodeled page grand item");
7396
+ previous = [];
7397
+ return;
7398
+ }
7399
+ const values2 = !columns && measures === 1 && xs.length === 0 && prefix === 0 ? [0] : [...previous.slice(0, prefix), ...xs];
7400
+ if (item.hasAttribute("t") || JSON.stringify(values2) !== JSON.stringify(expected[i2]))
7401
+ throw new Error("Unmodeled page column item");
7402
+ previous = values2;
7403
+ });
7404
+ }
7405
+
6755
7406
  // xlsx/pivot/read.ts
6756
7407
  function value(node) {
6757
7408
  const v = att(node, "v") ?? "";
@@ -6786,22 +7437,24 @@ function readOne(workbook, source2, part) {
6786
7437
  const dataSheet = sourceNode && att(sourceNode, "sheet");
6787
7438
  const dataRange = sourceNode && parseRange(att(sourceNode, "ref") ?? "");
6788
7439
  const recordPart = source2.targetOfType(cachePart, `${NS.r}/pivotCacheRecords`);
7440
+ const rowsAxis = att(root, "dataOnRows") === "1";
6789
7441
  if (!dataSheet || !dataRange || !recordPart || !workbook.sheets.some((sheet) => sheet.name === dataSheet))
6790
7442
  throw new Error("Unsupported pivot source");
6791
- assertPivotRecords(parseXml(source2.text(recordPart)).documentElement);
7443
+ const recordRoot = parseXml(source2.text(recordPart)).documentElement;
7444
+ assertPivotRecords(recordRoot);
6792
7445
  const fields = children(first(cache2, "cacheFields", NS.x), "cacheField", NS.x);
6793
7446
  if (fields.some((field) => first(field, "fieldGroup", NS.x) || field.hasAttribute("formula")))
6794
7447
  throw new Error("Grouped or calculated cache field");
6795
7448
  const shared = fields.map(
6796
7449
  (field) => elements(first(field, "sharedItems", NS.x) ?? parseXml("<root/>").documentElement).map(value)
6797
7450
  );
6798
- const records = children(parseXml(source2.text(recordPart)).documentElement, "r", NS.x).map(
7451
+ const records = children(recordRoot, "r", NS.x).map(
6799
7452
  (record) => elements(record).map((node, field) => {
6800
7453
  if (node.localName !== "x") return value(node);
6801
- const index2 = Number(att(node, "v"));
6802
- if (!Number.isInteger(index2) || index2 < 0 || index2 >= (shared[field]?.length ?? 0))
7454
+ const index3 = Number(att(node, "v"));
7455
+ if (!Number.isInteger(index3) || index3 < 0 || index3 >= (shared[field]?.length ?? 0))
6803
7456
  throw new Error("Invalid pivot cache index");
6804
- return shared[field][index2];
7457
+ return shared[field][index3];
6805
7458
  })
6806
7459
  );
6807
7460
  if (records.some((record) => record.length !== fields.length) || records.length * fields.length > 1e6)
@@ -6821,17 +7474,43 @@ function readOne(workbook, source2, part) {
6821
7474
  "dataField",
6822
7475
  NS.x
6823
7476
  );
6824
- 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")
7477
+ if (rowFields.length < 1 || rowFields.length > (rowsAxis ? 3 : 2) || dataFields.length < 1 || dataFields.length > 16 || !supportedPivotAxes(rowFields, colFields, dataFields.length, rowsAxis) || first(root, "filters", NS.x) || root.getAttribute("rowGrandTotals") === "0" || root.getAttribute("colGrandTotals") === "0")
6825
7478
  throw new Error("Unsupported pivot layout");
7479
+ const valueIndex = pivotValueIndex(root, rowsAxis ? rowFields : colFields);
6826
7480
  const measure = dataFields[0];
7481
+ const definition = elements(first(root, "extLst", NS.x) ?? parseXml("<root/>").documentElement).map(
7482
+ (extension) => first(
7483
+ extension,
7484
+ "pivotTableDefinition",
7485
+ "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
7486
+ )
7487
+ ).find(Boolean);
7488
+ if (dataFields.length > 1 && att(definition, "hideValuesRow") !== "1")
7489
+ throw new Error("Visible Values header rows are preserved");
7490
+ for (const [axis, count2] of [
7491
+ ["rowItems", rowsAxis ? dataFields.length : 1],
7492
+ ["colItems", rowsAxis ? 1 : dataFields.length]
7493
+ ]) {
7494
+ for (const item of children(
7495
+ first(root, axis, NS.x) ?? parseXml("<root/>").documentElement,
7496
+ "i",
7497
+ NS.x
7498
+ )) {
7499
+ const index3 = Number(att(item, "i") ?? "0");
7500
+ if (!Number.isInteger(index3) || index3 < 0 || index3 >= count2)
7501
+ throw new Error("Unsupported Values axis item");
7502
+ }
7503
+ }
6827
7504
  const aggregate3 = att(measure, "subtotal") ?? "sum";
6828
7505
  if (!PIVOT_AGGREGATES.includes(aggregate3) || att(measure, "showDataAs") && att(measure, "showDataAs") !== "normal")
6829
7506
  throw new Error("Unsupported pivot aggregate");
6830
7507
  const names = fields.map((field) => decodeEscapes(att(field, "name") ?? ""));
6831
- const row2 = names[Number(att(rowFields[0], "x"))];
6832
- const second = rowFields[1] && names[Number(att(rowFields[1], "x"))];
7508
+ const realRows = rowsAxis ? rowFields.filter((field) => pivotFieldIndex(field) !== -2) : rowFields;
7509
+ const row2 = names[pivotFieldIndex(realRows[0])];
7510
+ const second = realRows[1] ? names[Number(att(realRows[1], "x"))] : void 0;
7511
+ const pageFilter = readPivotPageFilter(root, names, shared);
6833
7512
  const tableFields = children(first(root, "pivotFields", NS.x), "pivotField", NS.x);
6834
- const outer = tableFields[Number(att(rowFields[0], "x"))];
7513
+ const outer = tableFields[pivotFieldIndex(realRows[0])];
6835
7514
  const compact = att(outer, "compact") !== "0";
6836
7515
  const outline = att(outer, "outline") !== "0";
6837
7516
  const layout3 = compact ? "compact" : outline ? "outline" : "tabular";
@@ -6840,7 +7519,7 @@ function readOne(workbook, source2, part) {
6840
7519
  ) || att(root, "compact") !== "0" !== compact || att(root, "compactData") !== "0" !== compact || att(root, "outline") === "1" !== outline || att(root, "outlineData") === "1" !== outline || layout3 === "compact" && att(root, "indent") !== "0")
6841
7520
  throw new Error("Mixed field layouts or custom compact indentation are preserved");
6842
7521
  const subtotal = att(outer, "defaultSubtotal") !== "0";
6843
- const repeat = rowFields.map((field) => {
7522
+ const repeat = realRows.map((field) => {
6844
7523
  const node = tableFields[Number(att(field, "x"))];
6845
7524
  const extension = first(first(node, "extLst", NS.x), "ext", NS.x);
6846
7525
  return att(
@@ -6853,16 +7532,24 @@ function readOne(workbook, source2, part) {
6853
7532
  ) === "1";
6854
7533
  });
6855
7534
  if (repeat.some((entry4) => entry4 !== repeat[0])) throw new Error("Mixed field label repetition");
6856
- const col = colFields[0] && names[Number(att(colFields[0], "x"))];
7535
+ const hasColumn = colFields.length > (dataFields.length > 1 && !rowsAxis ? 1 : 0);
7536
+ const col = hasColumn ? names[Number(att(colFields[0], "x"))] : void 0;
6857
7537
  const data = names[Number(att(measure, "fld"))];
6858
7538
  const location = parseRange(att(first(root, "location", NS.x), "ref") ?? "");
6859
- if (!row2 || !data || !location || colFields.length && !col || rowFields.length === 2 && !second)
7539
+ if (!row2 || !data || !location || hasColumn && !col || realRows.length === 2 && !second)
6860
7540
  throw new Error("Invalid pivot fields");
7541
+ if (pageFilter) {
7542
+ if (location.start.row < 2) throw new Error("Invalid report filter location");
7543
+ location.start.row -= 2;
7544
+ }
6861
7545
  const pivot = {
7546
+ ...pageFilter ? { pageFilter } : {},
6862
7547
  name: att(root, "name") ?? "PivotTable",
6863
7548
  source: `${quoteSheetName(dataSheet)}!${formatRange(dataRange)}`,
6864
7549
  rowField: row2,
6865
7550
  layout: layout3,
7551
+ ...rowsAxis ? { valuesAxis: "rows" } : {},
7552
+ ...rowsAxis && realRows.length === 2 && valueIndex < 2 ? { valuesPosition: valueIndex === 0 ? "first" : "between" } : {},
6866
7553
  subtotalPosition: att(outer, "subtotalTop") === "0" ? "bottom" : "top",
6867
7554
  ...second ? { secondRowField: second, subtotals: subtotal, repeatLabels: repeat[0] ?? false } : {
6868
7555
  ...subtotal ? {} : { subtotals: false },
@@ -6871,6 +7558,15 @@ function readOne(workbook, source2, part) {
6871
7558
  valueField: data,
6872
7559
  aggregate: aggregate3,
6873
7560
  valueCaption: decodeEscapes(att(measure, "name") ?? data),
7561
+ ...dataFields.length > 1 ? {
7562
+ additionalValues: dataFields.slice(1).map((measure2) => {
7563
+ const field = names[Number(att(measure2, "fld"))];
7564
+ const aggregate4 = att(measure2, "subtotal") ?? "sum";
7565
+ if (!field || !PIVOT_AGGREGATES.includes(aggregate4) || att(measure2, "showDataAs") && att(measure2, "showDataAs") !== "normal")
7566
+ throw new Error("Unsupported pivot measure");
7567
+ return { field, aggregate: aggregate4, caption: decodeEscapes(att(measure2, "name") ?? field) };
7568
+ })
7569
+ } : {},
6874
7570
  fields: names,
6875
7571
  records,
6876
7572
  location,
@@ -6879,6 +7575,7 @@ function readOne(workbook, source2, part) {
6879
7575
  sourceXml: xml,
6880
7576
  ...col ? { columnField: col } : {}
6881
7577
  };
7578
+ assertPageAxisItems(root, pivot, shared, cache2, recordRoot);
6882
7579
  return pivot;
6883
7580
  }
6884
7581
  function readPivotTables(workbook, source2, warn) {
@@ -7204,10 +7901,10 @@ function parseDynamicArrayMetadata(xml) {
7204
7901
  const flag2 = props?.getAttribute("fDynamic");
7205
7902
  return flag2 === "1" || flag2 === "true";
7206
7903
  });
7207
- childrenNamed(top.get("cellMetadata")?.[0], "bk").forEach((bk, index2) => {
7904
+ childrenNamed(top.get("cellMetadata")?.[0], "bk").forEach((bk, index3) => {
7208
7905
  for (const rc of childrenNamed(bk, "rc")) {
7209
7906
  const type = types[Number(att(rc, "t")) - 1];
7210
- if (type === DYNAMIC_ARRAY_TYPE && dynamic[Number(att(rc, "v"))]) out.add(index2 + 1);
7907
+ if (type === DYNAMIC_ARRAY_TYPE && dynamic[Number(att(rc, "v"))]) out.add(index3 + 1);
7211
7908
  }
7212
7909
  });
7213
7910
  return out;
@@ -7485,13 +8182,13 @@ function parseStyles(xml, warnings) {
7485
8182
  const named2 = namesByXf.get(xfId);
7486
8183
  if (named2 && xfId !== 0 && named2 !== "Normal") style2.cellStyleName = named2;
7487
8184
  const key = styleKey(style2);
7488
- let index2 = keys.get(key);
7489
- if (index2 === void 0) {
7490
- index2 = styles.length;
8185
+ let index3 = keys.get(key);
8186
+ if (index3 === void 0) {
8187
+ index3 = styles.length;
7491
8188
  styles.push(style2);
7492
- keys.set(key, index2);
8189
+ keys.set(key, index3);
7493
8190
  }
7494
- xfMap.push(index2);
8191
+ xfMap.push(index3);
7495
8192
  }
7496
8193
  if (!styles.length) {
7497
8194
  styles.push(fallback);
@@ -7505,47 +8202,6 @@ function parseStyles(xml, warnings) {
7505
8202
  return result2;
7506
8203
  }
7507
8204
 
7508
- // drawingml/dom.ts
7509
- function attributeReader(element2) {
7510
- return (name) => {
7511
- if (!element2) return void 0;
7512
- const direct = element2.getAttribute(name);
7513
- if (direct !== null) return direct;
7514
- const attributes = element2.attributes;
7515
- for (let index2 = 0; index2 < attributes.length; index2++) {
7516
- const candidate = attributes.item(index2);
7517
- if (candidate && candidate.localName === name) return candidate.value;
7518
- }
7519
- return void 0;
7520
- };
7521
- }
7522
- function stringAttribute(element2, name) {
7523
- const value2 = attributeReader(element2)(name)?.trim();
7524
- return value2 ? value2 : void 0;
7525
- }
7526
- function integerAttribute(element2, name) {
7527
- const parsed = Number.parseInt(attributeReader(element2)(name) ?? "", 10);
7528
- return Number.isFinite(parsed) ? parsed : void 0;
7529
- }
7530
- function booleanAttribute(element2, name) {
7531
- const value2 = attributeReader(element2)(name)?.trim().toLowerCase();
7532
- if (value2 === "1" || value2 === "true") return true;
7533
- if (value2 === "0" || value2 === "false") return false;
7534
- return void 0;
7535
- }
7536
- function descendants2(root, local) {
7537
- const result2 = [];
7538
- const visit = (node) => {
7539
- for (const child4 of Array.from(node.childNodes)) {
7540
- if (!isElement(child4)) continue;
7541
- if (child4.localName === local) result2.push(child4);
7542
- visit(child4);
7543
- }
7544
- };
7545
- visit(root);
7546
- return result2;
7547
- }
7548
-
7549
8205
  // drawingml/drawing-color.ts
7550
8206
  var COLOR_ELEMENTS = {
7551
8207
  srgbClr: "srgb",
@@ -7691,7 +8347,7 @@ function parseTheme2(xml) {
7691
8347
  if (!xml) return palette;
7692
8348
  const theme = parseTheme(parseXml(xml, { label: "XLSX theme" }));
7693
8349
  palette.colors = PALETTE_SLOTS.map(
7694
- (slot2, index2) => paletteHex(theme.colorScheme.colors[slot2]) ?? DEFAULT_THEME.colors[index2] ?? "000000"
8350
+ (slot2, index3) => paletteHex(theme.colorScheme.colors[slot2]) ?? DEFAULT_THEME.colors[index3] ?? "000000"
7695
8351
  );
7696
8352
  palette.majorFont = theme.fontScheme.major.latin ?? palette.majorFont;
7697
8353
  palette.minorFont = theme.fontScheme.minor.latin ?? palette.minorFont;
@@ -8079,11 +8735,11 @@ function readModernHash(node, prefix = "") {
8079
8735
  function parseWorkbookPart(xml) {
8080
8736
  const root = parseXml(xml, { label: "XLSX workbook" }).documentElement;
8081
8737
  const sheets = [];
8082
- xChildren(xFirst(root, "sheets") ?? root, "sheet").forEach((node, index2) => {
8738
+ xChildren(xFirst(root, "sheets") ?? root, "sheet").forEach((node, index3) => {
8083
8739
  const state = att(node, "state");
8084
8740
  sheets.push({
8085
- name: att(node, "name") ?? `Sheet${index2 + 1}`,
8086
- sheetId: numAttr(node, "sheetId") ?? index2 + 1,
8741
+ name: att(node, "name") ?? `Sheet${index3 + 1}`,
8742
+ sheetId: numAttr(node, "sheetId") ?? index3 + 1,
8087
8743
  state: state === "hidden" || state === "veryHidden" ? state : "visible",
8088
8744
  relId: relAttr(node, "id") ?? ""
8089
8745
  });
@@ -8433,8 +9089,8 @@ function styleRef(element2) {
8433
9089
  if (element2.localName === "fontRef") {
8434
9090
  if (raw2) ref.fontIndex = raw2;
8435
9091
  } else {
8436
- const index2 = Number.parseInt(raw2 ?? "", 10);
8437
- if (Number.isFinite(index2)) ref.index = index2;
9092
+ const index3 = Number.parseInt(raw2 ?? "", 10);
9093
+ if (Number.isFinite(index3)) ref.index = index3;
8438
9094
  }
8439
9095
  const color = parseDrawingColorIn(element2);
8440
9096
  if (color) ref.color = color;
@@ -8813,11 +9469,11 @@ function groupTransform(group, parent) {
8813
9469
  scaleY: parent.scaleY * local.scaleY
8814
9470
  };
8815
9471
  }
8816
- function parseShape(sp, index2, group, issues) {
9472
+ function parseShape(sp, index3, group, issues) {
8817
9473
  const spPr = first(sp, "spPr", NS.dsp);
8818
9474
  const transform6 = parseTransform(first(spPr, "xfrm", NS.a));
8819
9475
  if (!transform6) return void 0;
8820
- const modelId = stringAttribute(sp, "modelId") ?? stringAttribute(first(first(sp, "nvSpPr", NS.dsp), "cNvPr", NS.dsp), "id") ?? `dsp-${index2}`;
9476
+ const modelId = stringAttribute(sp, "modelId") ?? stringAttribute(first(first(sp, "nvSpPr", NS.dsp), "cNvPr", NS.dsp), "id") ?? `dsp-${index3}`;
8821
9477
  const { geometry, adjustments, paths, issue } = parseDrawingGeometry(spPr);
8822
9478
  if (issue) issues.push({ code: issue, message: `Shape ${modelId}: ${issue}.` });
8823
9479
  const frame = applyGroup(transform6.frame, group);
@@ -9035,8 +9691,8 @@ function drawingFillXml(fill) {
9035
9691
  const stops = children(list, "gs", NS.a).filter(
9036
9692
  (node) => parseDrawingColorIn(node) && Number.isFinite(Number.parseInt(node.getAttribute("pos") ?? "", 10))
9037
9693
  );
9038
- fill.stops.forEach((stop, index2) => {
9039
- const node = stops[index2] ?? doc.createElementNS(NS.a, "a:gs");
9694
+ fill.stops.forEach((stop, index3) => {
9695
+ const node = stops[index3] ?? doc.createElementNS(NS.a, "a:gs");
9040
9696
  if (!node.parentNode) list.appendChild(node);
9041
9697
  node.setAttribute("pos", String(Math.round(stop.position * 1e3)));
9042
9698
  for (const old of elements(node))
@@ -9545,45 +10201,6 @@ function readDataValidations(node) {
9545
10201
  return out;
9546
10202
  }
9547
10203
 
9548
- // xlsx/write/xml-out.ts
9549
- var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
9550
- var CONTROL = "\0-\b\v\f-" + String.fromCharCode(65534, 65535);
9551
- var NEEDS_ESCAPE = new RegExp(`[${CONTROL}\r]|_x[0-9A-Fa-f]{4}_`);
9552
- var ESCAPABLE = new RegExp(`[${CONTROL}\r]|_(?=x[0-9A-Fa-f]{4}_)`, "g");
9553
- function encodeEscapes(text) {
9554
- if (!NEEDS_ESCAPE.test(text)) return text;
9555
- return text.replace(
9556
- ESCAPABLE,
9557
- (ch) => `_x${ch.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}_`
9558
- );
9559
- }
9560
- var INVALID_XML = new RegExp(`[${CONTROL}]`, "g");
9561
- var escapeText2 = (text) => text.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
9562
- var escapeAttr3 = (text) => text.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;");
9563
- function attrs(values2) {
9564
- let out = "";
9565
- for (const [name, value2] of Object.entries(values2)) {
9566
- if (value2 === void 0) continue;
9567
- const text = typeof value2 === "boolean" ? value2 ? "1" : "0" : typeof value2 === "number" ? num(value2) : value2;
9568
- out += ` ${name}="${escapeAttr3(text)}"`;
9569
- }
9570
- return out;
9571
- }
9572
- var el = (name, values2 = {}, content2 = "") => content2 ? `<${name}${attrs(values2)}>${content2}</${name}>` : `<${name}${attrs(values2)}/>`;
9573
- var num = (value2) => Object.is(value2, -0) ? "0" : String(value2);
9574
- function tElement(text, name = "t") {
9575
- const encoded = escapeText2(encodeEscapes(text));
9576
- const preserve = /^\s|\s$|\n|\t/.test(text) ? ' xml:space="preserve"' : "";
9577
- return `<${name}${preserve}>${encoded}</${name}>`;
9578
- }
9579
- var MAIN_NS = ' xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"';
9580
- function inlineFragment(xml) {
9581
- const end = xml.indexOf(">");
9582
- if (end < 0) return xml;
9583
- const head = xml.slice(0, end);
9584
- return head.includes(MAIN_NS) ? head.replace(MAIN_NS, "") + xml.slice(end) : xml;
9585
- }
9586
-
9587
10204
  // xlsx/conditional-extensions.ts
9588
10205
  var XM = "http://schemas.microsoft.com/office/excel/2006/main";
9589
10206
  var URI = "{78C0D931-6437-407d-A8EE-F0AAD7539E65}";
@@ -9593,8 +10210,8 @@ function writeSettings(node, rule) {
9593
10210
  if (rule.minLength !== void 0) bar.setAttribute("minLength", String(rule.minLength));
9594
10211
  if (rule.maxLength !== void 0) bar.setAttribute("maxLength", String(rule.maxLength));
9595
10212
  const thresholds = children(bar, "cfvo", NS.x14);
9596
- for (const [index2, threshold] of [rule.min, rule.max].entries()) {
9597
- const target = thresholds[index2];
10213
+ for (const [index3, threshold] of [rule.min, rule.max].entries()) {
10214
+ const target = thresholds[index3];
9598
10215
  if (!target) continue;
9599
10216
  const oldType = target.getAttribute("type");
9600
10217
  if (oldType === "autoMin" && threshold.type === "min" || oldType === "autoMax" && threshold.type === "max")
@@ -9858,7 +10475,7 @@ function chartCacheValues(cache2) {
9858
10475
  out[point.index ?? out.length] = numeric2 && text.trim() !== "" && Number.isFinite(Number(text)) ? Number(text) : text;
9859
10476
  }
9860
10477
  const size = Math.max(cache2.pointCount ?? 0, out.length);
9861
- for (let index2 = 0; index2 < size; index2++) if (out[index2] === void 0) out[index2] = "";
10478
+ for (let index3 = 0; index3 < size; index3++) if (out[index3] === void 0) out[index3] = "";
9862
10479
  return out;
9863
10480
  }
9864
10481
  var chartSourceValues = (source2) => chartCacheValues(source2?.cache ?? source2?.levels?.[0]);
@@ -9993,8 +10610,8 @@ function parseCache(node) {
9993
10610
  type: node.localName === "numCache" || node.localName === "numLit" ? "number" : "string",
9994
10611
  points: children(node, "pt", NS.c).map((pt) => {
9995
10612
  const point = { value: cChild(pt, "v")?.textContent ?? "" };
9996
- const index2 = Number(attribute(pt, "idx") ?? Number.NaN);
9997
- if (Number.isInteger(index2) && index2 >= 0) point.index = index2;
10613
+ const index3 = Number(attribute(pt, "idx") ?? Number.NaN);
10614
+ if (Number.isInteger(index3) && index3 >= 0) point.index = index3;
9998
10615
  const formatCode2 = attribute(pt, "formatCode");
9999
10616
  if (formatCode2 !== void 0) point.formatCode = formatCode2;
10000
10617
  return point;
@@ -10220,11 +10837,11 @@ var POINT = /* @__PURE__ */ new Set([
10220
10837
  ]);
10221
10838
  function parseDataPoint(context, element2) {
10222
10839
  reportUnmodelled(context, element2, POINT);
10223
- const index2 = cNumber(context, element2, "idx");
10840
+ const index3 = cNumber(context, element2, "idx");
10224
10841
  return assignDefined(
10225
10842
  {},
10226
10843
  {
10227
- index: index2 !== void 0 && Number.isInteger(index2) && index2 >= 0 ? index2 : void 0,
10844
+ index: index3 !== void 0 && Number.isInteger(index3) && index3 >= 0 ? index3 : void 0,
10228
10845
  invertIfNegative: cBool(context, element2, "invertIfNegative"),
10229
10846
  bubble3D: cBool(context, element2, "bubble3D"),
10230
10847
  explosion: cNumber(context, element2, "explosion"),
@@ -10761,8 +11378,8 @@ var SCHEME_INDEX = {
10761
11378
  function legacyColor(color) {
10762
11379
  if (color?.kind === "srgb") return color.value ? { rgb: color.value.toUpperCase() } : void 0;
10763
11380
  if (color?.kind === "scheme") {
10764
- const index2 = SCHEME_INDEX[color.value];
10765
- return index2 === void 0 ? void 0 : { theme: index2 };
11381
+ const index3 = SCHEME_INDEX[color.value];
11382
+ return index3 === void 0 ? void 0 : { theme: index3 };
10766
11383
  }
10767
11384
  return void 0;
10768
11385
  }
@@ -11613,14 +12230,14 @@ var PersonRegistry = class {
11613
12230
  return `${XML_HEADER}<personList xmlns="${NS.tc}" xmlns:x="${NS.x}">${people}</personList>`;
11614
12231
  }
11615
12232
  };
11616
- function vmlShape(comment, index2, id) {
12233
+ function vmlShape(comment, index3, id) {
11617
12234
  const { row: row2, col } = comment.address;
11618
12235
  const anchor = `${col + 1}, 15, ${Math.max(0, row2 - 1)}, 10, ${col + 3}, 15, ${row2 + 3}, 4`;
11619
- return `<v:shape id="_x0000_s${id}" type="#_x0000_t202" style="position:absolute;margin-left:59.25pt;margin-top:1.5pt;width:108pt;height:59.25pt;z-index:${index2 + 1};visibility:hidden" fillcolor="#ffffe1" o:insetmode="auto"><v:fill color2="#ffffe1"/><v:shadow on="t" color="black" obscured="t"/><v:path o:connecttype="none"/><v:textbox style="mso-direction-alt:auto"><div style="text-align:left"></div></v:textbox><x:ClientData ObjectType="Note"><x:MoveWithCells/><x:SizeWithCells/><x:Anchor>${anchor}</x:Anchor><x:AutoFill>False</x:AutoFill><x:Row>${row2}</x:Row><x:Column>${col}</x:Column></x:ClientData></v:shape>`;
12236
+ return `<v:shape id="_x0000_s${id}" type="#_x0000_t202" style="position:absolute;margin-left:59.25pt;margin-top:1.5pt;width:108pt;height:59.25pt;z-index:${index3 + 1};visibility:hidden" fillcolor="#ffffe1" o:insetmode="auto"><v:fill color2="#ffffe1"/><v:shadow on="t" color="black" obscured="t"/><v:path o:connecttype="none"/><v:textbox style="mso-direction-alt:auto"><div style="text-align:left"></div></v:textbox><x:ClientData ObjectType="Note"><x:MoveWithCells/><x:SizeWithCells/><x:Anchor>${anchor}</x:Anchor><x:AutoFill>False</x:AutoFill><x:Row>${row2}</x:Row><x:Column>${col}</x:Column></x:ClientData></v:shape>`;
11620
12237
  }
11621
12238
  var NOTE_SHAPETYPE = '<v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe"><v:stroke joinstyle="miter"/><v:path gradientshapeok="t" o:connecttype="rect"/></v:shapetype>';
11622
12239
  function vmlXml(comments, layout3) {
11623
- const shapes = comments.map((comment, index2) => vmlShape(comment, index2, layout3.ids[index2] ?? 0)).join("");
12240
+ const shapes = comments.map((comment, index3) => vmlShape(comment, index3, layout3.ids[index3] ?? 0)).join("");
11624
12241
  const data = layout3.blocks.join(",");
11625
12242
  const base = layout3.base;
11626
12243
  if (base && /<\/xml>\s*$/.test(base)) {
@@ -11651,8 +12268,8 @@ function commentParts(comments, sheetNumber, persons, sheetName, layout3) {
11651
12268
  const id = guidFrom(`${sheetName}!${ref}:${comment.text}`);
11652
12269
  const personId = persons.id(comment.author);
11653
12270
  threaded += `<threadedComment ref="${ref}" personId="${personId}" id="${id}"><text>${escapeText2(comment.text)}</text></threadedComment>`;
11654
- comment.replies.forEach((reply, index2) => {
11655
- const replyId = guidFrom(`${id}:reply:${index2}:${reply.text}`);
12271
+ comment.replies.forEach((reply, index3) => {
12272
+ const replyId = guidFrom(`${id}:reply:${index3}:${reply.text}`);
11656
12273
  const dT = reply.date ? ` dT="${escapeAttr3(reply.date)}"` : "";
11657
12274
  threaded += `<threadedComment ref="${ref}"${dT} personId="${persons.id(reply.author)}" id="${replyId}" parentId="${id}"><text>${escapeText2(reply.text)}</text></threadedComment>`;
11658
12275
  });
@@ -11669,7 +12286,7 @@ Reply:
11669
12286
  sorted2,
11670
12287
  layout3 ?? {
11671
12288
  blocks: [sheetNumber],
11672
- ids: sorted2.map((_, index2) => 1024 * sheetNumber + index2 + 1)
12289
+ ids: sorted2.map((_, index3) => 1024 * sheetNumber + index3 + 1)
11673
12290
  }
11674
12291
  );
11675
12292
  const parts = { comments: commentsXml, vml };
@@ -12372,11 +12989,11 @@ var GRAY_VARIATIONS = [
12372
12989
  { tint: 8e4 }
12373
12990
  ];
12374
12991
  var ACCENTS = ["accent1", "accent2", "accent3", "accent4", "accent5", "accent6"];
12375
- function colorful(id, index2, base) {
12376
- return { id, group: "colorful", index: index2, meth: "cycle", base, variations: COLORFUL_VARIATIONS };
12992
+ function colorful(id, index3, base) {
12993
+ return { id, group: "colorful", index: index3, meth: "cycle", base, variations: COLORFUL_VARIATIONS };
12377
12994
  }
12378
- function mono(id, index2, accent, meth) {
12379
- return { id, group: "monochromatic", index: index2, meth, base: [accent], variations: [] };
12995
+ function mono(id, index3, accent, meth) {
12996
+ return { id, group: "monochromatic", index: index3, meth, base: [accent], variations: [] };
12380
12997
  }
12381
12998
  var CHART_COLOR_PALETTES = [
12382
12999
  colorful(10, 1, ACCENTS),
@@ -12420,9 +13037,9 @@ function chartPaletteSeriesColorChoice(palette, i2, n) {
12420
13037
  const round2 = Math.floor(i2 / palette.base.length);
12421
13038
  transform6 = (palette.variations.length ? palette.variations[round2 % palette.variations.length] : {}) ?? {};
12422
13039
  } else {
12423
- const index2 = palette.meth === "withinLinearReversed" ? n - 1 - i2 : i2;
13040
+ const index3 = palette.meth === "withinLinearReversed" ? n - 1 - i2 : i2;
12424
13041
  base = palette.base[0];
12425
- transform6 = withinLinearTransform(index2, n);
13042
+ transform6 = withinLinearTransform(index3, n);
12426
13043
  }
12427
13044
  if (!base) throw new RangeError("A chart palette must have a base color");
12428
13045
  return {
@@ -12603,18 +13220,18 @@ var PackageWriter = class {
12603
13220
  var rank = (name) => name === "_rels/.rels" ? 0 : name.startsWith("docProps/") ? 1 : name === "xl/workbook.xml" ? 2 : 3;
12604
13221
 
12605
13222
  // xlsx/write/chart-colors.ts
12606
- function chartSeriesFill(chart, series, index2) {
13223
+ function chartSeriesFill(chart, series, index3) {
12607
13224
  const imported = series.fill && drawingFillXml(series.fill);
12608
13225
  if (imported) return imported;
12609
- return `<a:solidFill>${drawingColorXml(chartSeriesColor(chart, series, index2))}</a:solidFill>`;
13226
+ return `<a:solidFill>${drawingColorXml(chartSeriesColor(chart, series, index3))}</a:solidFill>`;
12610
13227
  }
12611
- function chartSeriesDrawingFill(chart, series, index2) {
13228
+ function chartSeriesDrawingFill(chart, series, index3) {
12612
13229
  if (series.fill && drawingFillXml(series.fill)) return series.fill;
12613
- return { kind: "solid", color: chartSeriesColor(chart, series, index2) };
13230
+ return { kind: "solid", color: chartSeriesColor(chart, series, index3) };
12614
13231
  }
12615
- function chartSeriesColor(chart, series, index2) {
13232
+ function chartSeriesColor(chart, series, index3) {
12616
13233
  const palette = findChartColorPalette(chart.colorPalette ?? 10);
12617
- return series.drawingColor ?? chartDrawingColor(series.color) ?? chartPaletteSeriesColorChoice(palette ?? findChartColorPalette(10), index2, chart.series.length);
13234
+ return series.drawingColor ?? chartDrawingColor(series.color) ?? chartPaletteSeriesColorChoice(palette ?? findChartColorPalette(10), index3, chart.series.length);
12618
13235
  }
12619
13236
  function recolorMarker(marker3, previous, next) {
12620
13237
  for (const paint of [marker3, first(marker3, "ln", NS.a)]) {
@@ -12632,10 +13249,10 @@ function patchChartColors(doc, chartNode, model, before) {
12632
13249
  const palette = findChartColorPalette(model.colorPalette ?? 10);
12633
13250
  const lineLike = ["line", "scatter", "radar"].includes(model.chartType);
12634
13251
  const markerOnly = model.chartType === "scatter" && first(plot2, "scatterStyle", NS.c)?.getAttribute("val") === "marker";
12635
- children(plot2, "ser", NS.c).forEach((ser, index2) => {
12636
- const series = model.series[index2];
13252
+ children(plot2, "ser", NS.c).forEach((ser, index3) => {
13253
+ const series = model.series[index3];
12637
13254
  if (!series) return;
12638
- const old = before.series[index2];
13255
+ const old = before.series[index3];
12639
13256
  if (old?.effectsXml !== series.effectsXml) {
12640
13257
  let shape2 = first(ser, "spPr", NS.c);
12641
13258
  if (!shape2 && series.effectsXml) {
@@ -12681,12 +13298,12 @@ function patchChartColors(doc, chartNode, model, before) {
12681
13298
  paint = doc.createElementNS(NS.a, "a:ln");
12682
13299
  spPr.appendChild(paint);
12683
13300
  }
12684
- setDrawingFillXml(paint, chartSeriesFill(model, series, index2));
13301
+ setDrawingFillXml(paint, chartSeriesFill(model, series, index3));
12685
13302
  }
12686
13303
  if (previousPalette && palette && before.colorPalette !== model.colorPalette) {
12687
13304
  const marker3 = first(first(ser, "marker", NS.c), "spPr", NS.c);
12688
- const previous = chartPaletteSeriesColorChoice(previousPalette, index2, model.series.length);
12689
- const next = chartPaletteSeriesColorChoice(palette, index2, model.series.length);
13305
+ const previous = chartPaletteSeriesColorChoice(previousPalette, index3, model.series.length);
13306
+ const next = chartPaletteSeriesColorChoice(palette, index3, model.series.length);
12690
13307
  recolorMarker(marker3, previous, next);
12691
13308
  for (const point of children(ser, "dPt", NS.c))
12692
13309
  recolorMarker(first(first(point, "marker", NS.c), "spPr", NS.c), previous, next);
@@ -12781,7 +13398,7 @@ var FIRST_AXIS = 500000001;
12781
13398
  var SECOND_AXIS = 500000002;
12782
13399
  function source(kind, formula, values2) {
12783
13400
  const points = values2.flatMap(
12784
- (value2, index2) => value2 === null || value2 === "" ? [] : [{ index: index2, value: String(value2) }]
13401
+ (value2, index3) => value2 === null || value2 === "" ? [] : [{ index: index3, value: String(value2) }]
12785
13402
  );
12786
13403
  return {
12787
13404
  kind: formula ? kind === "str" ? "strRef" : "numRef" : kind === "str" ? "strLit" : "numLit",
@@ -12814,9 +13431,9 @@ function dataPoints(series) {
12814
13431
  return /^\d+$/.test(key) && paint ? [{ index: Number(key), spPr: { fill: paint } }] : [];
12815
13432
  });
12816
13433
  }
12817
- function seriesModel(chart, series, index2) {
13434
+ function seriesModel(chart, series, index3) {
12818
13435
  const type = chart.chartType;
12819
- const out = { index: index2, order: index2, dataPoints: dataPoints(series) };
13436
+ const out = { index: index3, order: index3, dataPoints: dataPoints(series) };
12820
13437
  if (series.nameRef)
12821
13438
  out.tx = {
12822
13439
  reference: source("str", series.nameRef, series.name === void 0 ? [] : [series.name])
@@ -12825,7 +13442,7 @@ function seriesModel(chart, series, index2) {
12825
13442
  const lineLike = type === "line" || type === "scatter" || type === "radar";
12826
13443
  const effectsXml = effects(series);
12827
13444
  if (type !== "pie" && type !== "doughnut" || series.fill || series.color || series.drawingColor || effectsXml) {
12828
- const fill = chartSeriesDrawingFill(chart, series, index2);
13445
+ const fill = chartSeriesDrawingFill(chart, series, index3);
12829
13446
  const shape2 = lineLike ? { line: { widthEmu: 28575, cap: "rnd", fill } } : { fill };
12830
13447
  if (effectsXml) shape2.effectsXml = effectsXml;
12831
13448
  out.spPr = shape2;
@@ -12949,7 +13566,7 @@ function style(chart) {
12949
13566
  return id > 100 ? { c14Style: id, style: id - 100 } : { style: id };
12950
13567
  }
12951
13568
  function chartSpaceFromObject(chart) {
12952
- const series = chart.series.map((entry3, index2) => seriesModel(chart, entry3, index2));
13569
+ const series = chart.series.map((entry3, index3) => seriesModel(chart, entry3, index3));
12953
13570
  const [group, chartAxes] = plot(chart, series);
12954
13571
  const space = {
12955
13572
  roundedCorners: false,
@@ -12990,8 +13607,8 @@ function patchChartReferences(xml, chart) {
12990
13607
  changed = true;
12991
13608
  }
12992
13609
  };
12993
- children(plot2, "ser", NS.c).forEach((ser, index2) => {
12994
- const model = chart.series[index2];
13610
+ children(plot2, "ser", NS.c).forEach((ser, index3) => {
13611
+ const model = chart.series[index3];
12995
13612
  if (!model) return;
12996
13613
  setRef(first(ser, "tx", NS.c), model.nameRef);
12997
13614
  setRef(first(ser, "cat", NS.c) ?? first(ser, "xVal", NS.c), model.categoriesRef);
@@ -13359,10 +13976,10 @@ var MONTHS2 = [
13359
13976
  function monthFromName2(name) {
13360
13977
  const lower2 = name.toLowerCase();
13361
13978
  if (lower2.length < 3) return void 0;
13362
- const index2 = MONTHS2.findIndex((m) => lower2.startsWith(m));
13363
- if (index2 < 0) return void 0;
13364
- const full = new Date(Date.UTC(2e3, index2, 1)).toLocaleString("en-US", { month: "long", timeZone: "UTC" }).toLowerCase();
13365
- return lower2.length === 3 || full.startsWith(lower2) || lower2 === "sept" ? index2 + 1 : void 0;
13979
+ const index3 = MONTHS2.findIndex((m) => lower2.startsWith(m));
13980
+ if (index3 < 0) return void 0;
13981
+ const full = new Date(Date.UTC(2e3, index3, 1)).toLocaleString("en-US", { month: "long", timeZone: "UTC" }).toLowerCase();
13982
+ return lower2.length === 3 || full.startsWith(lower2) || lower2 === "sept" ? index3 + 1 : void 0;
13366
13983
  }
13367
13984
  var NUMBER_RE3 = /^(\d+(?:,\d{3,})+|\d*)(\.\d*)?(?:e([+-]?\d+))?$/i;
13368
13985
  var TIME_RE2 = /^(\d{1,4})(?::(\d+))?(?::(\d+(?:\.\d*)?))?(?:\s+(am|pm|a|p))?$/i;
@@ -14130,11 +14747,11 @@ function sort(args, ctx) {
14130
14747
  if (byCol) m = transpose(m);
14131
14748
  const indexes2 = args.length > 1 && args[1] !== null ? ctx.toMatrix(args[1] ?? null).flat().map((v) => Math.trunc(num2(v))) : [1];
14132
14749
  const orders = args.length > 2 && args[2] !== null ? ctx.toMatrix(args[2] ?? null).flat().map((v) => num2(v)) : [1];
14133
- const keys = indexes2.map((index2, k) => {
14134
- if (index2 < 1 || index2 > m.cols) fail(ERR.VALUE);
14750
+ const keys = indexes2.map((index3, k) => {
14751
+ if (index3 < 1 || index3 > m.cols) fail(ERR.VALUE);
14135
14752
  const order = orders[Math.min(k, orders.length - 1)] ?? 1;
14136
14753
  if (order !== 1 && order !== -1) fail(ERR.VALUE);
14137
- return { values: m.data.map((row2) => row2[index2 - 1] ?? null), descending: order === -1 };
14754
+ return { values: m.data.map((row2) => row2[index3 - 1] ?? null), descending: order === -1 };
14138
14755
  });
14139
14756
  const sorted2 = new Matrix(sortRows(m.data, keys));
14140
14757
  return byCol ? transpose(sorted2) : sorted2;
@@ -14262,14 +14879,14 @@ var ARRAY_FUNCTIONS = [
14262
14879
  const cols = optInt(ctx, args, 1, 1);
14263
14880
  const min = args.length > 2 && args[2] !== null ? num2(ctx.toScalar(args[2] ?? null)) : 0;
14264
14881
  const max = args.length > 3 && args[3] !== null ? num2(ctx.toScalar(args[3] ?? null)) : 1;
14265
- const integer = args.length > 4 && args[4] !== null && toBool(ctx.toScalar(args[4] ?? null));
14882
+ const integer2 = args.length > 4 && args[4] !== null && toBool(ctx.toScalar(args[4] ?? null));
14266
14883
  if (rows < 1 || cols < 1) return ERR.CALC;
14267
14884
  if (min > max) fail(ERR.VALUE);
14268
14885
  const random = () => ctx.frame.host.random();
14269
14886
  return Matrix.build(
14270
14887
  rows,
14271
14888
  cols,
14272
- () => integer ? Math.ceil(min) + Math.floor(random() * (Math.floor(max) - Math.ceil(min) + 1)) : min + random() * (max - min)
14889
+ () => integer2 ? Math.ceil(min) + Math.floor(random() * (Math.floor(max) - Math.ceil(min) + 1)) : min + random() * (max - min)
14273
14890
  );
14274
14891
  },
14275
14892
  ["any"],
@@ -14324,8 +14941,8 @@ function modes(values2) {
14324
14941
  function kth(values2, k, largest) {
14325
14942
  const n = values2.length;
14326
14943
  if (n === 0 || !(k >= 1) || k > n) fail(ERR.NUM);
14327
- const index2 = Math.floor(largest ? n + 1 - k : k) - 1;
14328
- return sorted(values2)[index2];
14944
+ const index3 = Math.floor(largest ? n + 1 - k : k) - 1;
14945
+ return sorted(values2)[index3];
14329
14946
  }
14330
14947
  function extreme(values2, max) {
14331
14948
  if (values2.length === 0) return 0;
@@ -14465,13 +15082,13 @@ function fieldIndex(table2, field) {
14465
15082
  const value2 = scalar(field);
14466
15083
  if (isError(value2)) fail(value2);
14467
15084
  if (typeof value2 === "number") {
14468
- const index3 = Math.trunc(value2) - 1;
14469
- if (index3 < 0 || index3 >= table2.headers.length) fail(ERR.VALUE);
14470
- return index3;
15085
+ const index4 = Math.trunc(value2) - 1;
15086
+ if (index4 < 0 || index4 >= table2.headers.length) fail(ERR.VALUE);
15087
+ return index4;
14471
15088
  }
14472
- const index2 = table2.headers.indexOf(label2(value2).toLowerCase());
14473
- if (index2 < 0) fail(ERR.VALUE);
14474
- return index2;
15089
+ const index3 = table2.headers.indexOf(label2(value2).toLowerCase());
15090
+ if (index3 < 0) fail(ERR.VALUE);
15091
+ return index3;
14475
15092
  }
14476
15093
  function recordFilter(table2, criteria) {
14477
15094
  const [head, ...rows] = criteria;
@@ -15757,8 +16374,8 @@ function cumulative(args, principal) {
15757
16374
 
15758
16375
  // xlsx/formula/functions/bonds.ts
15759
16376
  var C9 = "Financial";
15760
- var basisOf = (args, index2) => {
15761
- const basis = args.length > index2 && args[index2] !== null ? int3(args[index2]) : 0;
16377
+ var basisOf = (args, index3) => {
16378
+ const basis = args.length > index3 && args[index3] !== null ? int3(args[index3]) : 0;
15762
16379
  if (basis < 0 || basis > 4) fail(ERR.NUM);
15763
16380
  return basis;
15764
16381
  };
@@ -15940,9 +16557,9 @@ var AMORLINC = {
15940
16557
  }
15941
16558
  const fraction = purchase === firstPeriod ? 1 : basis === 1 ? (firstPeriod - purchase) / (isLeapYear(serialToYmd(purchase, ctx.date1904).year) ? 366 : 365) : yearFrac(purchase, firstPeriod, basis, ctx);
15942
16559
  const first2 = Math.min(cost - salvage, annual * fraction);
15943
- const index2 = Math.trunc(period);
15944
- if (index2 === 0) return first2;
15945
- return Math.max(0, Math.min(annual, cost - salvage - first2 - (index2 - 1) * annual));
16560
+ const index3 = Math.trunc(period);
16561
+ if (index3 === 0) return first2;
16562
+ return Math.max(0, Math.min(annual, cost - salvage - first2 - (index3 - 1) * annual));
15946
16563
  }
15947
16564
  ),
15948
16565
  missingRequiredError: "#N/A"
@@ -16169,8 +16786,8 @@ var DEPRECIATION_FUNCTIONS = [
16169
16786
 
16170
16787
  // xlsx/formula/functions/securities.ts
16171
16788
  var C11 = "Financial";
16172
- var basisOf2 = (args, index2) => {
16173
- const basis = args.length > index2 && args[index2] !== null ? int3(args[index2]) : 0;
16789
+ var basisOf2 = (args, index3) => {
16790
+ const basis = args.length > index3 && args[index3] !== null ? int3(args[index3]) : 0;
16174
16791
  if (basis < 0 || basis > 4) fail(ERR.NUM);
16175
16792
  return basis;
16176
16793
  };
@@ -16593,8 +17210,8 @@ var INFO_FUNCTIONS = [
16593
17210
  const v = args[0];
16594
17211
  if (v === void 0) return ctx.sheet + 1;
16595
17212
  if (v instanceof RefValue) return (v.areas[0]?.sheet ?? ctx.sheet) + 1;
16596
- const index2 = sheetIndex(ctx.frame.host, str(v));
16597
- return index2 < 0 ? ERR.NA : index2 + 1;
17213
+ const index3 = sheetIndex(ctx.frame.host, str(v));
17214
+ return index3 < 0 ? ERR.NA : index3 + 1;
16598
17215
  },
16599
17216
  ["any"]
16600
17217
  ),
@@ -17063,14 +17680,14 @@ function shape(value2) {
17063
17680
  if (value2 instanceof Matrix) return { rows: value2.rows, cols: value2.cols };
17064
17681
  return { rows: 1, cols: 1 };
17065
17682
  }
17066
- function line(ctx, value2, axis, index2) {
17683
+ function line(ctx, value2, axis, index3) {
17067
17684
  if (value2 instanceof RefValue) {
17068
17685
  const area = value2.areas[0];
17069
17686
  if (!area || value2.areas.length !== 1) fail(ERR.VALUE);
17070
17687
  const { start, end } = area.range;
17071
17688
  const bounds = ctx.frame.host.bounds(area.sheet);
17072
17689
  if (axis === "col") {
17073
- const col = start.col + index2;
17690
+ const col = start.col + index3;
17074
17691
  const length2 = Math.max(0, Math.min(end.row, bounds.rows - 1) - start.row + 1);
17075
17692
  return {
17076
17693
  length: length2,
@@ -17078,7 +17695,7 @@ function line(ctx, value2, axis, index2) {
17078
17695
  get: (i2) => ctx.readCell(area.sheet, start.row + i2, col)
17079
17696
  };
17080
17697
  }
17081
- const row2 = start.row + index2;
17698
+ const row2 = start.row + index3;
17082
17699
  const length = Math.max(0, Math.min(end.col, bounds.cols - 1) - start.col + 1);
17083
17700
  return {
17084
17701
  length,
@@ -17087,8 +17704,8 @@ function line(ctx, value2, axis, index2) {
17087
17704
  };
17088
17705
  }
17089
17706
  const m = value2 instanceof Matrix ? value2 : new Matrix([[value2]]);
17090
- if (axis === "col") return { length: m.rows, get: (i2) => m.get(i2, index2) };
17091
- return { length: m.cols, get: (i2) => m.get(index2, i2) };
17707
+ if (axis === "col") return { length: m.rows, get: (i2) => m.get(i2, index3) };
17708
+ return { length: m.cols, get: (i2) => m.get(index3, i2) };
17092
17709
  }
17093
17710
  function vectorOf(ctx, value2) {
17094
17711
  const { rows, cols } = shape(value2);
@@ -17526,24 +18143,24 @@ function cellOf(value2, row2, col) {
17526
18143
  if (value2 instanceof Matrix) return value2.get(row2, col);
17527
18144
  return value2;
17528
18145
  }
17529
- function sliceOf(value2, axis, index2) {
18146
+ function sliceOf(value2, axis, index3) {
17530
18147
  const { rows } = shape(value2);
17531
18148
  if (value2 instanceof RefValue) {
17532
18149
  const area = value2.areas[0];
17533
18150
  if (!area) fail(ERR.REF);
17534
18151
  const { start, end } = area.range;
17535
18152
  const range = axis === "row" ? {
17536
- start: { row: start.row + index2, col: start.col },
17537
- end: { row: start.row + index2, col: end.col }
18153
+ start: { row: start.row + index3, col: start.col },
18154
+ end: { row: start.row + index3, col: end.col }
17538
18155
  } : {
17539
- start: { row: start.row, col: start.col + index2 },
17540
- end: { row: end.row, col: start.col + index2 }
18156
+ start: { row: start.row, col: start.col + index3 },
18157
+ end: { row: end.row, col: start.col + index3 }
17541
18158
  };
17542
18159
  return new RefValue([{ sheet: area.sheet, range }]);
17543
18160
  }
17544
18161
  const m = value2 instanceof Matrix ? value2 : new Matrix([[value2]]);
17545
- if (axis === "row") return new Matrix([m.data[index2] ?? []]);
17546
- return new Matrix(Array.from({ length: rows }, (_, r) => [m.get(r, index2)]));
18162
+ if (axis === "row") return new Matrix([m.data[index3] ?? []]);
18163
+ return new Matrix(Array.from({ length: rows }, (_, r) => [m.get(r, index3)]));
17547
18164
  }
17548
18165
  function lookupValue(args) {
17549
18166
  const v = scalar(args[0]);
@@ -17559,15 +18176,15 @@ function lookupArray(value2) {
17559
18176
  function vhlookup(args, ctx, vertical) {
17560
18177
  const lookup2 = blankAsZero(args);
17561
18178
  const table2 = lookupArray(args[1] ?? null);
17562
- const index2 = int3(args[2]);
18179
+ const index3 = int3(args[2]);
17563
18180
  const approximate2 = args.length < 4 ? true : bool(args[3]);
17564
18181
  const { rows, cols } = shape(table2);
17565
- if (index2 < 1) fail(ERR.VALUE);
17566
- if (index2 > (vertical ? cols : rows)) fail(ERR.REF);
18182
+ if (index3 < 1) fail(ERR.VALUE);
18183
+ if (index3 > (vertical ? cols : rows)) fail(ERR.REF);
17567
18184
  const keys = line(ctx, table2, vertical ? "col" : "row", 0);
17568
18185
  const at = approximate2 ? findAscending(keys, lookup2) : findExact(keys, lookup2, true);
17569
18186
  if (at < 0) fail(ERR.NA);
17570
- return vertical ? cellOf(table2, at, index2 - 1) : cellOf(table2, index2 - 1, at);
18187
+ return vertical ? cellOf(table2, at, index3 - 1) : cellOf(table2, index3 - 1, at);
17571
18188
  }
17572
18189
  function match(args, ctx) {
17573
18190
  const lookup2 = blankAsZero(args);
@@ -17594,13 +18211,13 @@ function lookup(args, ctx) {
17594
18211
  if (at < 0) fail(ERR.NA);
17595
18212
  return vertical ? cellOf(source2, at, cols - 1) : cellOf(source2, rows - 1, at);
17596
18213
  }
17597
- function index(args) {
18214
+ function index2(args) {
17598
18215
  const source2 = args[0] ?? null;
17599
18216
  if (source2 instanceof RefValue && source2.areas.length > 1) {
17600
18217
  const area = Math.trunc(optNum(args, 3, 1));
17601
18218
  const chosen = source2.areas[area - 1];
17602
18219
  if (!chosen) fail(ERR.REF);
17603
- return index([new RefValue([chosen]), ...args.slice(1, 3)]);
18220
+ return index2([new RefValue([chosen]), ...args.slice(1, 3)]);
17604
18221
  }
17605
18222
  const { rows, cols } = shape(source2);
17606
18223
  let r = args.length > 1 && args[1] !== null ? int3(args[1]) : 0;
@@ -17722,7 +18339,7 @@ var LOOKUP_FUNCTIONS = [
17722
18339
  "The value or reference at a position.",
17723
18340
  1,
17724
18341
  4,
17725
- (args) => index(args),
18342
+ (args) => index2(args),
17726
18343
  ["any", "value", "value", "value"]
17727
18344
  ),
17728
18345
  spec(
@@ -17766,27 +18383,27 @@ function valueKeys(value2, out) {
17766
18383
  }
17767
18384
  }
17768
18385
  function positionsOf(block, key) {
17769
- let index2 = indexes.get(block);
17770
- if (!index2) {
18386
+ let index3 = indexes.get(block);
18387
+ if (!index3) {
17771
18388
  const count2 = (uses.get(block) ?? 0) + 1;
17772
18389
  uses.set(block, count2);
17773
18390
  if (count2 < 2 || block.isPadded) return void 0;
17774
- index2 = /* @__PURE__ */ new Map();
18391
+ index3 = /* @__PURE__ */ new Map();
17775
18392
  const keys = [];
17776
18393
  const cols = block.cols;
17777
18394
  for (let r = 0; r < block.rows; r++) {
17778
18395
  for (let c2 = 0; c2 < cols; c2++) {
17779
18396
  valueKeys(block.get(r, c2), keys);
17780
18397
  for (const k of keys) {
17781
- const list = index2.get(k);
18398
+ const list = index3.get(k);
17782
18399
  if (list) list.push(r * cols + c2);
17783
- else index2.set(k, [r * cols + c2]);
18400
+ else index3.set(k, [r * cols + c2]);
17784
18401
  }
17785
18402
  }
17786
18403
  }
17787
- indexes.set(block, index2);
18404
+ indexes.set(block, index3);
17788
18405
  }
17789
- return index2.get(key) ?? [];
18406
+ return index3.get(key) ?? [];
17790
18407
  }
17791
18408
 
17792
18409
  // xlsx/formula/functions/criteria.ts
@@ -18946,7 +19563,7 @@ function layout(ctx, args) {
18946
19563
  }
18947
19564
  return { y, x, column };
18948
19565
  }
18949
- var withConst = (args, index2) => omitted(args, index2) ? true : bool(args[index2]);
19566
+ var withConst = (args, index3) => omitted(args, index3) ? true : bool(args[index3]);
18950
19567
  var row = (values2, width) => [
18951
19568
  ...values2,
18952
19569
  ...new Array(Math.max(0, width - values2.length)).fill(ERR.NA)
@@ -21260,7 +21877,7 @@ function compile(pattern, caseMode2, global) {
21260
21877
  return fail(ERR.VALUE);
21261
21878
  }
21262
21879
  }
21263
- var caseMode = (args, index2) => optNum(args, index2, 0);
21880
+ var caseMode = (args, index3) => optNum(args, index3, 0);
21264
21881
  function encodeUrl(text) {
21265
21882
  return encodeURIComponent(text).replace(
21266
21883
  /[!'()*]/g,
@@ -21379,9 +21996,9 @@ function textAround(args, ctx, before) {
21379
21996
  if (instance > 0) found.push({ at: text.length, length: 0 });
21380
21997
  else found.unshift({ at: 0, length: 0 });
21381
21998
  }
21382
- const index2 = instance > 0 ? instance - 1 : found.length + instance;
21383
- const hit = found[index2];
21384
- if (!hit || index2 < 0) return notFound;
21999
+ const index3 = instance > 0 ? instance - 1 : found.length + instance;
22000
+ const hit = found[index3];
22001
+ if (!hit || index3 < 0) return notFound;
21385
22002
  return before ? text.slice(0, hit.at) : text.slice(hit.at + hit.length);
21386
22003
  }
21387
22004
  function splitText(text, delimiters, insensitive, ignoreEmpty) {
@@ -21497,10 +22114,10 @@ Object.freeze(
21497
22114
  );
21498
22115
 
21499
22116
  // xlsx/formula/functions/types.ts
21500
- var paramKind = (spec2, index2) => {
22117
+ var paramKind = (spec2, index3) => {
21501
22118
  const params = spec2.params;
21502
22119
  if (!params || params.length === 0) return "value";
21503
- return params[Math.min(index2, params.length - 1)] ?? "value";
22120
+ return params[Math.min(index3, params.length - 1)] ?? "value";
21504
22121
  };
21505
22122
 
21506
22123
  // xlsx/formula/spill.ts
@@ -22080,9 +22697,9 @@ function readSourceStyles(xml) {
22080
22697
  (node) => inlineFragment(outerXml(node))
22081
22698
  );
22082
22699
  const dxfKeys = /* @__PURE__ */ new Map();
22083
- parseStyles(xml, []).dxfs.forEach((dxf, index2) => {
22700
+ parseStyles(xml, []).dxfs.forEach((dxf, index3) => {
22084
22701
  const key = styleKey(dxf);
22085
- if (!dxfKeys.has(key)) dxfKeys.set(key, index2);
22702
+ if (!dxfKeys.has(key)) dxfKeys.set(key, index3);
22086
22703
  });
22087
22704
  const result2 = { numFmts, dxfXml, dxfKeys };
22088
22705
  const tableStyles = xFirst(root, "tableStyles");
@@ -22190,7 +22807,7 @@ var StyleWriter = class {
22190
22807
  });
22191
22808
  const seen = /* @__PURE__ */ new Set();
22192
22809
  const unique2 = named2.filter((entry3) => !seen.has(entry3.name) && seen.add(entry3.name));
22193
- const xfIdOf = new Map(unique2.map((entry3, index2) => [entry3.name, index2]));
22810
+ const xfIdOf = new Map(unique2.map((entry3, index3) => [entry3.name, index3]));
22194
22811
  const base = this.workbook.styles[0] ?? defaultCellStyle();
22195
22812
  this.fonts.id(fontXml(base.font));
22196
22813
  this.borders.id(borderXml({}));
@@ -22199,7 +22816,7 @@ var StyleWriter = class {
22199
22816
  (style2) => this.xf(style2, xfIdOf.get(style2.cellStyleName ?? "Normal") ?? 0)
22200
22817
  );
22201
22818
  const cellStyles = unique2.map(
22202
- (entry3, index2) => el("cellStyle", { name: entry3.name, xfId: index2, builtinId: entry3.builtinId })
22819
+ (entry3, index3) => el("cellStyle", { name: entry3.name, xfId: index3, builtinId: entry3.builtinId })
22203
22820
  );
22204
22821
  const custom = [...this.numFmts].filter(([code]) => builtinFormatIdOf(code) === void 0).sort((a2, b) => a2[1] - b[1]);
22205
22822
  let out = `${XML_HEADER}<styleSheet xmlns="${NS.x}" xmlns:mc="${NS.mc}" mc:Ignorable="x14ac" xmlns:x14ac="${NS.x14ac}">`;
@@ -22364,13 +22981,13 @@ function definedNamesOf(workbook) {
22364
22981
  const names = workbook.definedNames.filter(
22365
22982
  (name) => name.name && (name.localSheet === void 0 || name.localSheet >= 0 && name.localSheet < workbook.sheets.length)
22366
22983
  );
22367
- workbook.sheets.forEach((sheet, index2) => {
22984
+ workbook.sheets.forEach((sheet, index3) => {
22368
22985
  const area = sheet.pageSetup?.printArea;
22369
- if (!area || names.some((n) => n.name === "_xlnm.Print_Area" && n.localSheet === index2)) return;
22986
+ if (!area || names.some((n) => n.name === "_xlnm.Print_Area" && n.localSheet === index3)) return;
22370
22987
  names.push({
22371
22988
  name: "_xlnm.Print_Area",
22372
22989
  formula: `${quoteSheetName(sheet.name)}!${absoluteRange(area)}`,
22373
- localSheet: index2
22990
+ localSheet: index3
22374
22991
  });
22375
22992
  });
22376
22993
  return names;
@@ -22989,9 +23606,9 @@ function sourceColumnsForPatch(root, table2, names) {
22989
23606
  const byName = new Map(source2.map((c2) => [(c2.getAttribute("name") ?? "").toLowerCase(), c2]));
22990
23607
  const tracked = table2.partName !== void 0 || table2.columns.some((c2) => c2.sourceId !== void 0);
22991
23608
  const used = /* @__PURE__ */ new Set();
22992
- return names.map((name, index2) => {
22993
- const id = table2.columns[index2]?.sourceId;
22994
- const match2 = id !== void 0 ? byId.get(id) : tracked ? void 0 : source2.length === names.length ? source2[index2] : byName.get(name.toLowerCase());
23609
+ return names.map((name, index3) => {
23610
+ const id = table2.columns[index3]?.sourceId;
23611
+ const match2 = id !== void 0 ? byId.get(id) : tracked ? void 0 : source2.length === names.length ? source2[index3] : byName.get(name.toLowerCase());
22995
23612
  if (!match2 || used.has(match2)) return void 0;
22996
23613
  used.add(match2);
22997
23614
  return match2;
@@ -23008,12 +23625,12 @@ function patchAutoFilter(doc, root, table2, before, names) {
23008
23625
  filter2.setAttribute("ref", formatRange(range));
23009
23626
  const list = xKid(root, "tableColumns");
23010
23627
  const original = list ? xKids(list, "tableColumn") : [];
23011
- const current = new Map(sourceColumnsForPatch(root, table2, names).map((c2, index2) => [c2, index2]));
23628
+ const current = new Map(sourceColumnsForPatch(root, table2, names).map((c2, index3) => [c2, index3]));
23012
23629
  for (const column of xKids(filter2, "filterColumn")) {
23013
23630
  const old = original[Number(column.getAttribute("colId") ?? "0")];
23014
- const index2 = old ? current.get(old) : void 0;
23015
- if (index2 === void 0) filter2.removeChild(column);
23016
- else column.setAttribute("colId", num(index2));
23631
+ const index3 = old ? current.get(old) : void 0;
23632
+ if (index3 === void 0) filter2.removeChild(column);
23633
+ else column.setAttribute("colId", num(index3));
23017
23634
  }
23018
23635
  if (!existing) insertBefore(root, filter2, ["sortState", "tableColumns"]);
23019
23636
  const sort2 = xKid(filter2, "sortState") ?? xKid(root, "sortState");
@@ -23058,11 +23675,11 @@ function patchColumns(doc, root, sheet, table2, names) {
23058
23675
  for (const column of sourceColumns) list.removeChild(column);
23059
23676
  let nextId = Math.max(0, ...ids) + 1;
23060
23677
  const totalsRow = table2.range.end.row;
23061
- names.forEach((name, index2) => {
23062
- const column = picked[index2] ?? doc.createElementNS(NS.x, "tableColumn");
23678
+ names.forEach((name, index3) => {
23679
+ const column = picked[index3] ?? doc.createElementNS(NS.x, "tableColumn");
23063
23680
  if (!column.getAttribute("id")) column.setAttribute("id", num(nextId++));
23064
23681
  column.setAttribute("name", name);
23065
- const model = table2.columns[index2];
23682
+ const model = table2.columns[index3];
23066
23683
  const fn = table2.totalsRow ? model?.totalsRowFunction : void 0;
23067
23684
  setOrRemove(column, "totalsRowFunction", fn);
23068
23685
  setOrRemove(column, "totalsRowLabel", table2.totalsRow ? model?.totalsRowLabel : void 0);
@@ -23076,7 +23693,7 @@ function patchColumns(doc, root, sheet, table2, names) {
23076
23693
  );
23077
23694
  if (fn !== "custom") setChildText(doc, column, "totalsRowFormula", void 0, []);
23078
23695
  else {
23079
- const cellFormula = sheet.rows.get(totalsRow)?.get(table2.range.start.col + index2)?.formula;
23696
+ const cellFormula = sheet.rows.get(totalsRow)?.get(table2.range.start.col + index3)?.formula;
23080
23697
  if (cellFormula)
23081
23698
  setChildText(
23082
23699
  doc,
@@ -23157,11 +23774,11 @@ function tableXml(table2, id, names) {
23157
23774
  const range = formatRange(table2.range);
23158
23775
  const filterEnd = { ...table2.range.end, row: table2.range.end.row - (table2.totalsRow ? 1 : 0) };
23159
23776
  const filter2 = table2.headerRow && !table2.totalsRow ? `<autoFilter ref="${range}"/>` : table2.headerRow ? `<autoFilter ref="${formatRange({ start: table2.range.start, end: filterEnd })}"/>` : "";
23160
- const columns = names.map((name, index2) => {
23161
- const column = table2.columns[index2];
23777
+ const columns = names.map((name, index3) => {
23778
+ const column = table2.columns[index3];
23162
23779
  const calculated = column?.calculatedColumnFormula ? `<calculatedColumnFormula>${escapeText2(addFuturePrefixes(column.calculatedColumnFormula))}</calculatedColumnFormula>` : "";
23163
23780
  const values2 = attrs({
23164
- id: index2 + 1,
23781
+ id: index3 + 1,
23165
23782
  name,
23166
23783
  totalsRowFunction: table2.totalsRow ? column?.totalsRowFunction : void 0,
23167
23784
  totalsRowLabel: table2.totalsRow ? column?.totalsRowLabel : void 0
@@ -23200,27 +23817,27 @@ function totalsRowFormulas(sheet, table2, names) {
23200
23817
  const out = /* @__PURE__ */ new Map();
23201
23818
  if (!table2.totalsRow) return out;
23202
23819
  const row2 = table2.range.end.row;
23203
- names.forEach((name, index2) => {
23204
- const code = SUBTOTAL_CODES[table2.columns[index2]?.totalsRowFunction ?? ""];
23820
+ names.forEach((name, index3) => {
23821
+ const code = SUBTOTAL_CODES[table2.columns[index3]?.totalsRowFunction ?? ""];
23205
23822
  if (code === void 0) return;
23206
- const col = table2.range.start.col + index2;
23823
+ const col = table2.range.start.col + index3;
23207
23824
  const escaped = name.replace(/['#[\]]/g, "'$&");
23208
23825
  const formula = `SUBTOTAL(${code},${table2.displayName || table2.name}[${escaped}])`;
23209
23826
  if (sheet.rows.get(row2)?.get(col)?.formula !== formula) out.set(`${row2}:${col}`, formula);
23210
23827
  });
23211
23828
  return out;
23212
23829
  }
23213
- function resolveTableNames(table2, before, index2) {
23830
+ function resolveTableNames(table2, before, index3) {
23214
23831
  const display = table2.displayName || table2.name;
23215
- const displayName = before && before.displayName === display ? display : safeTableName(display, index2);
23216
- const name = before && before.name === table2.name ? table2.name : table2.name === display ? displayName : safeTableName(table2.name, index2);
23832
+ const displayName = before && before.displayName === display ? display : safeTableName(display, index3);
23833
+ const name = before && before.name === table2.name ? table2.name : table2.name === display ? displayName : safeTableName(table2.name, index3);
23217
23834
  return { name, displayName };
23218
23835
  }
23219
- function safeTableName(name, index2) {
23836
+ function safeTableName(name, index3) {
23220
23837
  const valid = /^[A-Za-z_\\][A-Za-z0-9_.\\]*$/.test(name) && !/^[A-Za-z]{1,3}\d+$/.test(name) && !/^[RrCc]$/.test(name) && !/^[Rr]\d*[Cc]\d*$/.test(name) && name.length <= 255;
23221
23838
  if (valid) return name;
23222
23839
  const cleaned = name.replace(/[^A-Za-z0-9_.]/g, "_");
23223
- return `Table_${cleaned || index2}`;
23840
+ return `Table_${cleaned || index3}`;
23224
23841
  }
23225
23842
 
23226
23843
  // xlsx/write/sheet-parts.ts
@@ -23233,7 +23850,7 @@ function sourceRelIds(source2, partName) {
23233
23850
  if (legacy) out.legacy = legacy;
23234
23851
  return out;
23235
23852
  }
23236
- function writeComments(ctx, sheet, index2, partName, rels) {
23853
+ function writeComments(ctx, sheet, index3, partName, rels) {
23237
23854
  const { writer, source: source2 } = ctx;
23238
23855
  const name = (pattern) => writer.uniqueName(pattern, ctx.reserved);
23239
23856
  const fromSource = source2 && sheet.partName && source2.has(sheet.partName);
@@ -23278,8 +23895,8 @@ function writeComments(ctx, sheet, index2, partName, rels) {
23278
23895
  }
23279
23896
  }
23280
23897
  const own = base ? vmlIdmapBlocks(base) : [];
23281
- const layout3 = vmlAllocatorFor(ctx, source2).allocate(sheet.comments.length, index2 + 1, own);
23282
- const parts = commentParts(sheet.comments, index2 + 1, ctx.persons, sheet.name, {
23898
+ const layout3 = vmlAllocatorFor(ctx, source2).allocate(sheet.comments.length, index3 + 1, own);
23899
+ const parts = commentParts(sheet.comments, index3 + 1, ctx.persons, sheet.name, {
23283
23900
  ...layout3,
23284
23901
  ...base ? { base } : {}
23285
23902
  });
@@ -23301,11 +23918,11 @@ function sourceVmlPart(source2, sheetPart) {
23301
23918
  }
23302
23919
  function writeTables(ctx, sheet, partName, rels, headerText, formulas) {
23303
23920
  const ids = [];
23304
- for (const [index2, original] of sheet.tables.entries()) {
23921
+ for (const [index3, original] of sheet.tables.entries()) {
23305
23922
  const { writer, source: source2 } = ctx;
23306
23923
  const sourceXml = original.partName ? source2?.text(original.partName) : void 0;
23307
23924
  const before = sourceXml && original.partName ? parseTable(sourceXml, original.partName) : void 0;
23308
- const { name, displayName } = resolveTableNames(original, before, index2 + 1);
23925
+ const { name, displayName } = resolveTableNames(original, before, index3 + 1);
23309
23926
  const table2 = name === original.name && displayName === original.displayName ? original : { ...original, name, displayName };
23310
23927
  const { names, headerText: forced } = resolveTableColumns(sheet, table2);
23311
23928
  for (const [key, text] of forced) headerText.set(key, text);
@@ -23587,7 +24204,7 @@ var REGENERATED = /* @__PURE__ */ new Set([
23587
24204
  ]);
23588
24205
  var NS_XR2 = "http://schemas.microsoft.com/office/spreadsheetml/2015/revision2";
23589
24206
  var NS_XR3 = "http://schemas.microsoft.com/office/spreadsheetml/2016/revision3";
23590
- function writeWorksheet(ctx, sheet, index2, partName) {
24207
+ function writeWorksheet(ctx, sheet, index3, partName) {
23591
24208
  const { writer, source: source2 } = ctx;
23592
24209
  const rels = new RelationshipSet();
23593
24210
  let sourceDrawing;
@@ -23610,7 +24227,7 @@ function writeWorksheet(ctx, sheet, index2, partName) {
23610
24227
  const tableParts = writeTables(ctx, sheet, partName, rels, headerText, formulas);
23611
24228
  blocks.set("sheetPr", sheetPrXml(sheet));
23612
24229
  blocks.set("dimension", dimensionXml(sheet));
23613
- blocks.set("sheetViews", sheetViewsXml(sheet, index2 === ctx.workbook.activeSheet));
24230
+ blocks.set("sheetViews", sheetViewsXml(sheet, index3 === ctx.workbook.activeSheet));
23614
24231
  blocks.set("sheetFormatPr", sheetFormatXml(sheet));
23615
24232
  blocks.set("cols", colsXml(sheet, ctx.workbook.styles.length));
23616
24233
  blocks.set(
@@ -23649,7 +24266,7 @@ function writeWorksheet(ctx, sheet, index2, partName) {
23649
24266
  );
23650
24267
  blocks.set("headerFooter", page.headerFooter);
23651
24268
  blocks.set("drawing", writeSheetDrawing(ctx, sheet, partName, rels, sourceDrawing));
23652
- blocks.set("legacyDrawing", writeComments(ctx, sheet, index2, partName, rels));
24269
+ blocks.set("legacyDrawing", writeComments(ctx, sheet, index3, partName, rels));
23653
24270
  blocks.set("tableParts", tableParts);
23654
24271
  ctx.pivots?.writeSheet(writer, sheet, partName, rels);
23655
24272
  blocks.set("extLst", conditionalExtensionsXml(sheet));
@@ -23674,12 +24291,12 @@ function pivotCacheData(pivot) {
23674
24291
  const items = pivot.fields.map(() => []);
23675
24292
  const indices = pivot.fields.map(() => /* @__PURE__ */ new Map());
23676
24293
  for (const record of pivot.records)
23677
- pivot.fields.forEach((_field, index2) => {
23678
- const value2 = record[index2] ?? null;
24294
+ pivot.fields.forEach((_field, index3) => {
24295
+ const value2 = record[index3] ?? null;
23679
24296
  const key = pivotValueKey(value2);
23680
- if (!indices[index2].has(key)) {
23681
- indices[index2].set(key, items[index2].length);
23682
- items[index2].push(value2);
24297
+ if (!indices[index3].has(key)) {
24298
+ indices[index3].set(key, items[index3].length);
24299
+ items[index3].push(value2);
23683
24300
  }
23684
24301
  });
23685
24302
  return { items, indices };
@@ -23694,8 +24311,8 @@ function valueXml(value2) {
23694
24311
  }
23695
24312
  function pivotCacheDefinitionXml(pivot, workbook, data, recordRel) {
23696
24313
  const source2 = sparklineDataRange(workbook, 0, pivot.source);
23697
- const fields = pivot.fields.map((name, index2) => {
23698
- const items = data.items[index2];
24314
+ const fields = pivot.fields.map((name, index3) => {
24315
+ const items = data.items[index3];
23699
24316
  const types = new Set(
23700
24317
  items.map((value2) => value2 === null || value2 === "" ? "blank" : typeof value2)
23701
24318
  );
@@ -23707,7 +24324,7 @@ function pivotCacheDefinitionXml(pivot, workbook, data, recordRel) {
23707
24324
  }
23708
24325
  function pivotCacheRecordsXml(pivot, data) {
23709
24326
  const records = pivot.records.map(
23710
- (record) => `<r>${pivot.fields.map((_field, index2) => `<x v="${data.indices[index2].get(pivotValueKey(record[index2] ?? null))}"/>`).join("")}</r>`
24327
+ (record) => `<r>${pivot.fields.map((_field, index3) => `<x v="${data.indices[index3].get(pivotValueKey(record[index3] ?? null))}"/>`).join("")}</r>`
23711
24328
  ).join("");
23712
24329
  return `${XML_HEADER}<pivotCacheRecords xmlns="${NS.x}" count="${pivot.records.length}">${records}</pivotCacheRecords>`;
23713
24330
  }
@@ -23717,45 +24334,87 @@ function pivotTableXml(pivot, cacheId, cache2) {
23717
24334
  const grid = pivotGrid(pivot);
23718
24335
  const row2 = pivot.fields.indexOf(pivot.rowField);
23719
24336
  const second = pivot.secondRowField ? pivot.fields.indexOf(pivot.secondRowField) : -1;
24337
+ const page = pivot.pageFilter ? pivot.fields.indexOf(pivot.pageFilter.field) : -1;
24338
+ const pageItems = page >= 0 ? pivotItems(pivot, pivot.pageFilter.field) : [];
24339
+ const axisItems = (field, visible) => page >= 0 ? pivotItems(pivot, field) : visible;
24340
+ const rowItemsFull = axisItems(pivot.rowField, grid.rowItems);
24341
+ const secondRowItemsFull = pivot.secondRowField ? axisItems(pivot.secondRowField, grid.secondRowItems) : [];
24342
+ const columnItemsFull = pivot.columnField ? axisItems(pivot.columnField, grid.columnItems) : [];
24343
+ const itemIndices = (visible, full) => {
24344
+ const indices = new Map(full.map((item, index3) => [pivotValueKey(item), index3]));
24345
+ return visible.map((v) => indices.get(pivotValueKey(v)));
24346
+ };
24347
+ const rowIndicesFull = itemIndices(grid.rowItems, rowItemsFull), secondRowIndicesFull = itemIndices(grid.secondRowItems ?? [], secondRowItemsFull), columnIndicesFull = itemIndices(grid.columnItems, columnItemsFull);
24348
+ const rowEntries = page >= 0 && grid.rowEntries ? remapPivotRowEntries(grid.rowEntries, [rowIndicesFull, secondRowIndicesFull]) : grid.rowEntries;
24349
+ const pageOffset = page >= 0 ? 2 : 0;
23720
24350
  const col = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
23721
- const value2 = pivot.fields.indexOf(pivot.valueField);
24351
+ const measures = pivotMeasures(pivot);
24352
+ const multiple = measures.length > 1;
24353
+ const rowsAxis = pivot.valuesAxis === "rows";
23722
24354
  const compact = pivot.layout === "compact";
23723
24355
  const outline = pivot.layout === "compact" || pivot.layout === "outline";
23724
24356
  const top = (pivot.subtotalPosition ?? (outline ? "top" : "bottom")) === "top";
23725
- const fields = pivot.fields.map((_field, index2) => {
23726
- const items2 = index2 === row2 ? grid.rowItems : index2 === second ? grid.secondRowItems : index2 === col ? grid.columnItems : void 0;
23727
- const subtotal = !(index2 === row2 && pivot.subtotals === false);
23728
- 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>' : "";
23729
- return `<pivotField${attrs({ axis: index2 === row2 || index2 === second ? "axisRow" : index2 === col ? "axisCol" : void 0, dataField: index2 === value2 ? true : void 0, compact, 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="${cache2.indices[index2].get(pivotValueKey(item))}"/>`).join("")}${subtotal ? '<item t="default"/>' : ""}</items>` : ""}${repeated}</pivotField>`;
24357
+ const fields = pivot.fields.map((_field, index3) => {
24358
+ const items2 = index3 === page ? pageItems : index3 === row2 ? rowItemsFull : index3 === second ? secondRowItemsFull : index3 === col ? columnItemsFull : void 0;
24359
+ const subtotal = !(index3 === row2 && pivot.subtotals === false);
24360
+ const repeated = pivot.repeatLabels && (index3 === row2 || index3 === 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>' : "";
24361
+ return `<pivotField${attrs({ axis: index3 === page ? "axisPage" : index3 === row2 || index3 === second ? "axisRow" : index3 === col ? "axisCol" : void 0, dataField: measures.some((measure) => pivot.fields.indexOf(measure.field) === index3) ? true : void 0, compact, outline, showAll: false, subtotalTop: index3 === row2 ? top : void 0, defaultSubtotal: subtotal ? void 0 : false })}>${items2 ? `<items count="${items2.length + Number(subtotal)}">${items2.map((item) => `<item x="${cache2.indices[index3].get(pivotValueKey(item))}"/>`).join("")}${subtotal ? '<item t="default"/>' : ""}</items>` : ""}${repeated}</pivotField>`;
23730
24362
  }).join("");
23731
- const items = (count2) => Array.from({ length: count2 }, (_v, i2) => `<i><x v="${i2}"/></i>`).join("") + '<i t="grand"><x/></i>';
23732
- const header = grid.firstDataRow - 1;
23733
- const rowIndices = [row2, ...second >= 0 ? [second] : []];
24363
+ const items = (count2, indices) => Array.from({ length: count2 }, (_v, i2) => `<i><x v="${indices?.[i2] ?? i2}"/></i>`).join("") + '<i t="grand"><x/></i>';
24364
+ const header = grid.firstHeaderRow !== void 0 ? grid.firstHeaderRow - pageOffset : multiple && col >= 0 ? 1 : grid.firstDataRow - pageOffset - 1;
24365
+ const rowIndices = rowsAxis && pivot.valuesPosition === "first" ? [-2, row2, second] : rowsAxis && pivot.valuesPosition === "between" ? [row2, -2, second] : [row2, ...second >= 0 ? [second] : [], ...rowsAxis ? [-2] : []];
23734
24366
  let previous = [];
23735
- const rowItems = grid.rowEntries?.map((entry3) => {
24367
+ const rowItems = rowEntries?.map((entry3) => {
23736
24368
  let prefix = 0;
23737
- if (!entry3.type)
24369
+ if (entry3.type === "default" && rowsAxis && pivot.valuesPosition === "first") prefix = 1;
24370
+ else if (!entry3.type)
23738
24371
  while (prefix < entry3.indices.length - 1 && entry3.indices[prefix] === previous[prefix])
23739
24372
  prefix++;
23740
- previous = entry3.type ? [] : entry3.indices;
23741
- return `<i${attrs({ t: entry3.type, r: prefix || void 0 })}>${entry3.indices.slice(prefix).map((index2) => `<x${attrs({ v: index2 || void 0 })}/>`).join("")}</i>`;
23742
- }).join("") ?? items(grid.rowItems.length);
23743
- 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>`;
23744
- if (col >= 0)
23745
- body += `<colFields count="1"><field x="${col}"/></colFields><colItems count="${grid.columnItems.length + 1}">${items(grid.columnItems.length)}</colItems>`;
23746
- else body += '<colItems count="1"><i><x/></i></colItems>';
23747
- body += `<dataFields count="1"><dataField${attrs({ name: encodeEscapes(pivot.valueCaption), fld: value2, subtotal: pivot.aggregate, baseField: 0, baseItem: 0 })}/></dataFields>`;
24373
+ previous = entry3.type && !(entry3.type === "default" && pivot.valuesPosition === "first") ? [] : entry3.indices;
24374
+ return `<i${attrs({ t: entry3.type, r: prefix || void 0, i: entry3.measure || void 0 })}>${entry3.indices.slice(prefix).map((index3) => `<x${attrs({ v: index3 || void 0 })}/>`).join("")}</i>`;
24375
+ }).join("") ?? items(grid.rowItems.length, rowIndicesFull);
24376
+ let body = `<location${attrs({ ref: formatRange({ ...pivot.location, start: { ...pivot.location.start, row: pivot.location.start.row + pageOffset } }), firstHeaderRow: header, firstDataRow: grid.firstDataRow - pageOffset, rowPageCount: page >= 0 ? 1 : void 0, colPageCount: page >= 0 ? 1 : void 0, firstDataCol: grid.rowLabelColumns ?? 1 })}/><pivotFields count="${pivot.fields.length}">${fields}</pivotFields><rowFields count="${rowIndices.length}">${rowIndices.map((index3) => `<field x="${index3}"/>`).join("")}</rowFields><rowItems count="${grid.rowEntries?.length ?? grid.rowItems.length + 1}">${rowItems}</rowItems>`;
24377
+ if (multiple && !rowsAxis)
24378
+ 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, columnIndicesFull)}`;
24379
+ else if (col >= 0)
24380
+ body += `<colFields count="1"><field x="${col}"/></colFields><colItems count="${grid.columnItems.length + 1}">${items(grid.columnItems.length, columnIndicesFull)}</colItems>`;
24381
+ else
24382
+ body += rowsAxis ? '<colItems count="1"><i/></colItems>' : page >= 0 ? '<colItems count="1"><i/></colItems>' : '<colItems count="1"><i><x/></i></colItems>';
24383
+ if (page >= 0)
24384
+ body += `<pageFields count="1"><pageField${attrs({ fld: page, hier: -1, item: pivot.pageFilter.item !== void 0 ? pageItems.findIndex((item) => pivotValueKey(item) === pivotValueKey(pivot.pageFilter.item)) : void 0 })}/></pageFields>`;
24385
+ 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>`;
23748
24386
  const doc = parseXml(
23749
24387
  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>`
23750
24388
  );
23751
24389
  const root = doc.documentElement;
23752
24390
  root.setAttribute("name", pivot.name);
23753
24391
  root.setAttribute("cacheId", String(cacheId));
24392
+ root.setAttribute("dataOnRows", rowsAxis ? "1" : "0");
24393
+ if (rowsAxis && (pivot.valuesPosition === "between" || pivot.valuesPosition === "first"))
24394
+ root.setAttribute("dataPosition", pivot.valuesPosition === "first" ? "0" : "1");
24395
+ else root.removeAttribute("dataPosition");
23754
24396
  root.setAttribute("compact", compact ? "1" : "0");
23755
24397
  root.setAttribute("compactData", compact ? "1" : "0");
23756
24398
  root.setAttribute("outline", outline ? "1" : "0");
23757
24399
  root.setAttribute("outlineData", outline ? "1" : "0");
23758
24400
  if (compact) root.setAttribute("indent", "0");
24401
+ if (multiple && !elements(first(root, "extLst", NS.x) ?? parseXml("<root/>").documentElement).some(
24402
+ (extension) => first(
24403
+ extension,
24404
+ "pivotTableDefinition",
24405
+ "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
24406
+ )
24407
+ )) {
24408
+ let list = first(root, "extLst", NS.x);
24409
+ if (!list) {
24410
+ list = doc.createElementNS(NS.x, "extLst");
24411
+ root.appendChild(list);
24412
+ }
24413
+ const extension = parseXml(
24414
+ `<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>`
24415
+ ).documentElement;
24416
+ list.appendChild(doc.importNode(extension, true));
24417
+ }
23759
24418
  root.setAttribute("rowGrandTotals", "1");
23760
24419
  root.setAttribute("colGrandTotals", "1");
23761
24420
  for (const extension of elements(
@@ -23766,6 +24425,7 @@ function pivotTableXml(pivot, cacheId, cache2) {
23766
24425
  "pivotTableDefinition",
23767
24426
  "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
23768
24427
  );
24428
+ if (multiple && definition) definition.setAttribute("hideValuesRow", "1");
23769
24429
  if (definition?.hasAttribute("fillDownLabelsDefault"))
23770
24430
  definition.setAttribute("fillDownLabelsDefault", pivot.repeatLabels ? "1" : "0");
23771
24431
  }
@@ -23776,7 +24436,8 @@ function pivotTableXml(pivot, cacheId, cache2) {
23776
24436
  "rowItems",
23777
24437
  "colFields",
23778
24438
  "colItems",
23779
- "dataFields"
24439
+ "dataFields",
24440
+ "pageFields"
23780
24441
  ]);
23781
24442
  for (const child4 of elements(root)) if (replaced.has(child4.localName)) root.removeChild(child4);
23782
24443
  const replacement = parseXml(`<root xmlns="${NS.x}">${body}</root>`).documentElement;
@@ -23961,8 +24622,8 @@ async function saveXlsx(workbook) {
23961
24622
  return void 0;
23962
24623
  });
23963
24624
  const sheetRefs = [];
23964
- workbook.sheets.forEach((sheet, index2) => {
23965
- let partName = partNames[index2];
24625
+ workbook.sheets.forEach((sheet, index3) => {
24626
+ let partName = partNames[index3];
23966
24627
  const sourceType = partName && source2?.has(partName) ? source2.contentType(partName) : void 0;
23967
24628
  const special = sourceType ? SHEET_TYPES[sourceType] : void 0;
23968
24629
  if (!partName) {
@@ -23973,11 +24634,11 @@ async function saveXlsx(workbook) {
23973
24634
  claimed.add(partName);
23974
24635
  }
23975
24636
  if (special) writer.carry(partName);
23976
- else writeWorksheet(ctx, sheet, index2, partName);
24637
+ else writeWorksheet(ctx, sheet, index3, partName);
23977
24638
  sheetRefs.push({
23978
24639
  name: sheet.name,
23979
24640
  sheetId: sheet.sheetId,
23980
- state: states[index2] ?? "visible",
24641
+ state: states[index3] ?? "visible",
23981
24642
  relId: rels.add(special ?? RELATIONSHIP_TYPES.worksheet, relativeTarget(bookPart, partName))
23982
24643
  });
23983
24644
  });
@@ -24599,10 +25260,10 @@ function hasFlatUniqueStreamLayout(entries, workbookCount) {
24599
25260
  return new Set(names).size === names.length;
24600
25261
  }
24601
25262
  function equalBytes(left2, right2) {
24602
- return left2.length === right2.length && left2.every((value2, index2) => value2 === right2[index2]);
25263
+ return left2.length === right2.length && left2.every((value2, index3) => value2 === right2[index3]);
24603
25264
  }
24604
25265
  function isCfb(bytes) {
24605
- return OLE_MAGIC.every((value2, index2) => bytes[index2] === value2);
25266
+ return OLE_MAGIC.every((value2, index3) => bytes[index3] === value2);
24606
25267
  }
24607
25268
 
24608
25269
  // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-functions.js
@@ -25043,9 +25704,9 @@ function decode2(rgce, extra, context, options) {
25043
25704
  break;
25044
25705
  case 25: {
25045
25706
  const ixti = reader.u16();
25046
- const index2 = reader.u16();
25707
+ const index3 = reader.u16();
25047
25708
  reader.skip(2);
25048
- const name = context.externName(ixti, index2);
25709
+ const name = context.externName(ixti, index3);
25049
25710
  if (name === void 0)
25050
25711
  return void 0;
25051
25712
  push(name);
@@ -25162,9 +25823,9 @@ var XLS_BUILTIN_FORMATS = {
25162
25823
  48: "##0.0E+0",
25163
25824
  49: "@"
25164
25825
  };
25165
- function paletteColor(index2, palette) {
25166
- const rgb = index2 < 64 ? palette[index2] : void 0;
25167
- return rgb ? { index: index2, rgb } : { index: index2, auto: true };
25826
+ function paletteColor(index3, palette) {
25827
+ const rgb = index3 < 64 ? palette[index3] : void 0;
25828
+ return rgb ? { index: index3, rgb } : { index: index3, auto: true };
25168
25829
  }
25169
25830
  var UNDERLINE = {
25170
25831
  1: "single",
@@ -25604,18 +26265,18 @@ function parseGlobals(records) {
25604
26265
  }
25605
26266
  return void 0;
25606
26267
  },
25607
- name(index2) {
25608
- const raw2 = rawNames[index2 - 1];
26268
+ name(index3) {
26269
+ const raw2 = rawNames[index3 - 1];
25609
26270
  return raw2?.name.name;
25610
26271
  },
25611
- externName(ixti, index2) {
26272
+ externName(ixti, index3) {
25612
26273
  const xti = xtis[ixti];
25613
26274
  const book = xti ? supbooks[xti.book] : void 0;
25614
26275
  if (!book)
25615
26276
  return void 0;
25616
26277
  if (book.kind === "self")
25617
- return this.name(index2);
25618
- return book.externNames[index2 - 1];
26278
+ return this.name(index3);
26279
+ return book.externNames[index3 - 1];
25619
26280
  }
25620
26281
  };
25621
26282
  for (const raw2 of rawNames) {
@@ -25946,8 +26607,8 @@ function parseSheet(bound, records, start, globals) {
25946
26607
  sheet.cells.push(result2);
25947
26608
  return result2;
25948
26609
  };
25949
- for (let index2 = start; index2 < records.length; index2++) {
25950
- const record = records[index2];
26610
+ for (let index3 = start; index3 < records.length; index3++) {
26611
+ const record = records[index3];
25951
26612
  const { opcode, data } = record;
25952
26613
  if (opcode === 2057) {
25953
26614
  depth++;
@@ -26155,7 +26816,7 @@ function parseSheet(bound, records, start, globals) {
26155
26816
 
26156
26817
  // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook.js
26157
26818
  function compoundStreamNames(bytes) {
26158
- if (!OLE_MAGIC.every((value2, index2) => bytes[index2] === value2))
26819
+ if (!OLE_MAGIC.every((value2, index3) => bytes[index3] === value2))
26159
26820
  return [];
26160
26821
  try {
26161
26822
  const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
@@ -26167,10 +26828,10 @@ function compoundStreamNames(bytes) {
26167
26828
  function topLevelSubstreams(records) {
26168
26829
  const starts = [];
26169
26830
  let depth = 0;
26170
- records.forEach((record, index2) => {
26831
+ records.forEach((record, index3) => {
26171
26832
  if (record.opcode === 2057) {
26172
- if (depth === 0 && index2 > 0)
26173
- starts.push(index2);
26833
+ if (depth === 0 && index3 > 0)
26834
+ starts.push(index3);
26174
26835
  depth++;
26175
26836
  } else if (record.opcode === 10)
26176
26837
  depth = Math.max(0, depth - 1);
@@ -26195,7 +26856,7 @@ function readXlsWorkbook(bytes) {
26195
26856
  unsupported.push("VBA macros");
26196
26857
  if (streams2.some((name) => name === "_SX_DB_CUR") && !unsupported.includes("pivot caches"))
26197
26858
  unsupported.push("pivot caches");
26198
- const byOffset = new Map(records.map((record, index2) => [record.offset, index2]));
26859
+ const byOffset = new Map(records.map((record, index3) => [record.offset, index3]));
26199
26860
  const substreams = topLevelSubstreams(records);
26200
26861
  const sheets = globals.sheets.map((bound, position) => {
26201
26862
  const start = byOffset.get(bound.offset) ?? substreams[position];
@@ -26319,7 +26980,7 @@ function layout2(bytes) {
26319
26980
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
26320
26981
  if (view.getUint16(0, true) !== 65534 || view.getUint16(2, true) > 1 || view.getUint32(24, true) !== 1)
26321
26982
  return;
26322
- if (!FMTID.every((value2, index2) => bytes[28 + index2] === value2))
26983
+ if (!FMTID.every((value2, index3) => bytes[28 + index3] === value2))
26323
26984
  return;
26324
26985
  const start = view.getUint32(44, true);
26325
26986
  if (start < 48 || start % 4 || start + 8 > bytes.length)
@@ -26477,8 +27138,8 @@ function xfToCellStyle(xls, xf) {
26477
27138
  }
26478
27139
  function defaultXfIndex(xls) {
26479
27140
  if (xls.xfs[15] && !xls.xfs[15].isStyle) return 15;
26480
- const index2 = xls.xfs.findIndex((xf) => !xf.isStyle);
26481
- return index2 >= 0 ? index2 : 0;
27141
+ const index3 = xls.xfs.findIndex((xf) => !xf.isStyle);
27142
+ return index3 >= 0 ? index3 : 0;
26482
27143
  }
26483
27144
 
26484
27145
  // xlsx/load/legacy-xls-sheet.ts
@@ -26672,7 +27333,7 @@ async function loadLegacyXls(input) {
26672
27333
  workbook.sheets = [];
26673
27334
  let undecoded = 0;
26674
27335
  let external = false;
26675
- xls.sheets.forEach((source2, index2) => {
27336
+ xls.sheets.forEach((source2, index3) => {
26676
27337
  if (source2.kind !== "worksheet") {
26677
27338
  const kind = source2.kind === "chart" ? "chart sheet" : `${source2.kind} sheet`;
26678
27339
  warnings.push(
@@ -26681,7 +27342,7 @@ async function loadLegacyXls(input) {
26681
27342
  return;
26682
27343
  }
26683
27344
  const mapped = mapSheet(source2, workbook.sheets.length + 1, resolve2);
26684
- sheetIndex2.set(index2, workbook.sheets.length);
27345
+ sheetIndex2.set(index3, workbook.sheets.length);
26685
27346
  workbook.sheets.push(mapped.sheet);
26686
27347
  undecoded += mapped.undecodedFormulas;
26687
27348
  external ||= mapped.externalReferences;
@@ -26790,7 +27451,7 @@ function decodeSpreadsheetText(bytes) {
26790
27451
  var CFB_MAGIC = [208, 207, 17, 224, 161, 177, 26, 225];
26791
27452
  var ZIP_MAGIC = [80, 75, 3, 4];
26792
27453
  var toBytes3 = (input) => input instanceof Uint8Array ? input : new Uint8Array(input);
26793
- var startsWith = (bytes, magic) => magic.every((value2, index2) => bytes[index2] === value2);
27454
+ var startsWith = (bytes, magic) => magic.every((value2, index3) => bytes[index3] === value2);
26794
27455
  function zipEntryNames(bytes) {
26795
27456
  const names = /* @__PURE__ */ new Set();
26796
27457
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);