ooxml-core 1.10.0 → 1.12.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 (205) hide show
  1. package/dist/PptxHandler-DNZHAHUY.cjs +12 -0
  2. package/dist/PptxHandler-E44KDHMQ.mjs +3 -0
  3. package/dist/{PptxHandler-ADEFY476.mjs → PptxHandler-NROFYT2N.mjs} +2 -2
  4. package/dist/automation/index.cjs +3504 -2888
  5. package/dist/automation/index.mjs +3504 -2888
  6. package/dist/{chunk-3N6XMMTT.cjs → chunk-2UVH6RHI.cjs} +1138 -996
  7. package/dist/{chunk-ZOUGMAZG.mjs → chunk-7DSZI7S6.mjs} +1 -1
  8. package/dist/{chunk-S6DOCMQC.cjs → chunk-7QZGRB3T.cjs} +0 -10
  9. package/dist/chunk-ANZ4Q6I3.cjs +21 -0
  10. package/dist/{chunk-5NVJN4E6.mjs → chunk-EC2W2MDY.mjs} +1 -1
  11. package/dist/chunk-EGTRL3QJ.mjs +19 -0
  12. package/dist/chunk-GXHKNSZX.mjs +9 -0
  13. package/dist/{chunk-CCHYFCPD.mjs → chunk-HCXUI5UC.mjs} +296 -103
  14. package/dist/chunk-HDQXPSHY.cjs +17 -0
  15. package/dist/chunk-KTYBFGEY.mjs +14 -0
  16. package/dist/chunk-QOO36KG4.cjs +42 -0
  17. package/dist/chunk-R2KZXD6U.mjs +39 -0
  18. package/dist/{chunk-A6P7G3UK.mjs → chunk-U2DF3EGK.mjs} +1 -1
  19. package/dist/{chunk-R6KSBNKX.mjs → chunk-UAY26XOI.mjs} +1 -9
  20. package/dist/{chunk-WUE5ZHU3.mjs → chunk-W5ARCUJB.mjs} +3 -3
  21. package/dist/chunk-XZPZHXV4.cjs +12 -0
  22. package/dist/{chunk-ZE53K7DH.mjs → chunk-YB5SRNFS.mjs} +244 -102
  23. package/dist/docx/embedded.cjs +1 -1
  24. package/dist/docx/embedded.mjs +1 -1
  25. package/dist/docx/index.cjs +1 -1
  26. package/dist/docx/index.mjs +1 -1
  27. package/dist/docx/layout/adapt-table.d.ts.map +1 -1
  28. package/dist/docx/layout/flow-table.d.ts.map +1 -1
  29. package/dist/docx/layout/index.cjs +266 -61
  30. package/dist/docx/layout/index.d.ts +1 -0
  31. package/dist/docx/layout/index.d.ts.map +1 -1
  32. package/dist/docx/layout/index.mjs +266 -62
  33. package/dist/docx/layout/input.d.ts +5 -0
  34. package/dist/docx/layout/input.d.ts.map +1 -1
  35. package/dist/docx/layout/layout-session.d.ts +10 -0
  36. package/dist/docx/layout/layout-session.d.ts.map +1 -0
  37. package/dist/docx/layout/nested-fragment-edges.d.ts +9 -0
  38. package/dist/docx/layout/nested-fragment-edges.d.ts.map +1 -0
  39. package/dist/docx/layout/paragraph-cache.d.ts +8 -0
  40. package/dist/docx/layout/paragraph-cache.d.ts.map +1 -0
  41. package/dist/docx/layout/paragraph-layout.d.ts.map +1 -1
  42. package/dist/docx/layout/paragraph-tokens.d.ts +1 -1
  43. package/dist/docx/layout/paragraph-tokens.d.ts.map +1 -1
  44. package/dist/docx/layout/result.d.ts +7 -0
  45. package/dist/docx/layout/result.d.ts.map +1 -1
  46. package/dist/docx/layout/table-border-layout.d.ts +1 -1
  47. package/dist/docx/layout/table-border-layout.d.ts.map +1 -1
  48. package/dist/docx/layout/table-cell-layout.d.ts +1 -1
  49. package/dist/docx/layout/table-cell-layout.d.ts.map +1 -1
  50. package/dist/docx/layout/table-frames.d.ts.map +1 -1
  51. package/dist/docx/layout/table-layout.d.ts +1 -1
  52. package/dist/docx/layout/table-layout.d.ts.map +1 -1
  53. package/dist/docx/layout/table-paragraph-keeps.d.ts +14 -0
  54. package/dist/docx/layout/table-paragraph-keeps.d.ts.map +1 -0
  55. package/dist/docx/load/index.cjs +1 -1
  56. package/dist/docx/load/index.mjs +1 -1
  57. package/dist/docx/ui/index.cjs +83 -6
  58. package/dist/docx/ui/index.mjs +83 -7
  59. package/dist/docx/ui/ribbon-action-ids.d.ts +1 -1
  60. package/dist/docx/ui/ribbon-action-ids.d.ts.map +1 -1
  61. package/dist/docx/ui/word-count.d.ts +3 -0
  62. package/dist/docx/ui/word-count.d.ts.map +1 -1
  63. package/dist/geometry/element-transform.d.ts +90 -0
  64. package/dist/geometry/element-transform.d.ts.map +1 -0
  65. package/dist/geometry/index.cjs +90 -0
  66. package/dist/geometry/index.d.ts +1 -0
  67. package/dist/geometry/index.d.ts.map +1 -1
  68. package/dist/geometry/index.mjs +83 -1
  69. package/dist/index.cjs +90 -0
  70. package/dist/index.mjs +90 -0
  71. package/dist/pptx/automation/index.cjs +266 -114
  72. package/dist/pptx/automation/index.d.ts +5 -4
  73. package/dist/pptx/automation/index.d.ts.map +1 -1
  74. package/dist/pptx/automation/index.mjs +5 -5
  75. package/dist/pptx/chunks/{text-operations-BqHmLaLA.d.ts → elements-DD3UGOMd.d.ts} +17 -3262
  76. package/dist/pptx/chunks/elements-DD3UGOMd.d.ts.map +1 -0
  77. package/dist/pptx/chunks/{index-DUCGeZh7.d.ts → index-BZrFyNtU.d.ts} +53 -5
  78. package/dist/pptx/chunks/index-BZrFyNtU.d.ts.map +1 -0
  79. package/dist/pptx/chunks/{index-Cuxtr76Y.d.ts → index-DdX02BSm.d.ts} +5 -3
  80. package/dist/pptx/chunks/index-DdX02BSm.d.ts.map +1 -0
  81. package/dist/pptx/chunks/smart-art-ENMMEbmW.d.ts +1512 -0
  82. package/dist/pptx/chunks/smart-art-ENMMEbmW.d.ts.map +1 -0
  83. package/dist/pptx/chunks/text-D49FKllA.d.ts +1473 -0
  84. package/dist/pptx/chunks/text-D49FKllA.d.ts.map +1 -0
  85. package/dist/pptx/chunks/text-operations-CyMTMfID.d.ts +3261 -0
  86. package/dist/pptx/chunks/text-operations-CyMTMfID.d.ts.map +1 -0
  87. package/dist/pptx/cli/index.cjs +266 -114
  88. package/dist/pptx/cli/index.d.ts +1 -1
  89. package/dist/pptx/cli/index.mjs +4 -4
  90. package/dist/pptx/converter/index.d.ts +1 -1
  91. package/dist/pptx/converter/index.mjs +2 -2
  92. package/dist/pptx/editor/render/find-replace.cjs +17 -16
  93. package/dist/pptx/editor/render/find-replace.d.ts +2 -2
  94. package/dist/pptx/editor/render/find-replace.mjs +2 -1
  95. package/dist/pptx/editor/render/font-family-update.cjs +14 -0
  96. package/dist/pptx/editor/render/font-family-update.d.ts +17 -0
  97. package/dist/pptx/editor/render/font-family-update.d.ts.map +1 -0
  98. package/dist/pptx/editor/render/font-family-update.mjs +1 -0
  99. package/dist/pptx/editor/render/paragraph-geometry-overrides.cjs +14 -0
  100. package/dist/pptx/editor/render/paragraph-geometry-overrides.d.ts +17 -0
  101. package/dist/pptx/editor/render/paragraph-geometry-overrides.d.ts.map +1 -0
  102. package/dist/pptx/editor/render/paragraph-geometry-overrides.mjs +12 -0
  103. package/dist/pptx/editor/render/slide-operations.cjs +9 -8
  104. package/dist/pptx/editor/render/slide-operations.mjs +3 -2
  105. package/dist/pptx/editor/render/table-data-grid-ops.cjs +1 -1
  106. package/dist/pptx/editor/render/table-data-grid-ops.mjs +1 -1
  107. package/dist/pptx/editor/render/text-content-style.cjs +18 -0
  108. package/dist/pptx/editor/render/text-content-style.d.ts +9 -0
  109. package/dist/pptx/editor/render/text-content-style.d.ts.map +1 -0
  110. package/dist/pptx/editor/render/text-content-style.mjs +5 -0
  111. package/dist/pptx/editor/render/text-runs-style-patch.cjs +17 -0
  112. package/dist/pptx/editor/render/text-runs-style-patch.d.ts +7 -0
  113. package/dist/pptx/editor/render/text-runs-style-patch.d.ts.map +1 -0
  114. package/dist/pptx/editor/render/text-runs-style-patch.mjs +15 -0
  115. package/dist/pptx/editor/render/text-style-scope.cjs +173 -0
  116. package/dist/pptx/editor/render/text-style-scope.d.ts +76 -0
  117. package/dist/pptx/editor/render/text-style-scope.d.ts.map +1 -0
  118. package/dist/pptx/editor/render/text-style-scope.mjs +164 -0
  119. package/dist/pptx/editor/render/theme-editor-model.cjs +1 -1
  120. package/dist/pptx/editor/render/theme-editor-model.mjs +1 -1
  121. package/dist/pptx/editor/render/update-text-segment-style.cjs +11 -0
  122. package/dist/pptx/editor/render/update-text-segment-style.d.ts +14 -0
  123. package/dist/pptx/editor/render/update-text-segment-style.d.ts.map +1 -0
  124. package/dist/pptx/editor/render/update-text-segment-style.mjs +2 -0
  125. package/dist/pptx/index.cjs +329 -114
  126. package/dist/pptx/index.d.ts +7 -5
  127. package/dist/pptx/index.mjs +5 -5
  128. package/dist/pptx/smartart-layouts/index.d.ts +1 -1
  129. package/dist/teams/index.cjs +112 -16
  130. package/dist/teams/index.mjs +112 -16
  131. package/dist/visio/edit-commands.d.ts +3 -3
  132. package/dist/visio/edit-commands.d.ts.map +1 -1
  133. package/dist/visio/edit-formatting-scope.d.ts.map +1 -1
  134. package/dist/visio/edit-recalculate-index.d.ts.map +1 -1
  135. package/dist/visio/edit-text-field-commands.d.ts +15 -0
  136. package/dist/visio/edit-text-field-commands.d.ts.map +1 -1
  137. package/dist/visio/edit-text-field.d.ts +2 -2
  138. package/dist/visio/edit-text-field.d.ts.map +1 -1
  139. package/dist/visio/edit.d.ts +1 -1
  140. package/dist/visio/edit.d.ts.map +1 -1
  141. package/dist/visio/index.cjs +696 -249
  142. package/dist/visio/index.d.ts +2 -1
  143. package/dist/visio/index.d.ts.map +1 -1
  144. package/dist/visio/index.mjs +695 -250
  145. package/dist/visio/model.d.ts +18 -0
  146. package/dist/visio/model.d.ts.map +1 -1
  147. package/dist/visio/paper-sizes.d.ts +5 -0
  148. package/dist/visio/paper-sizes.d.ts.map +1 -1
  149. package/dist/visio/parser.d.ts.map +1 -1
  150. package/dist/visio/print-count.d.ts +20 -0
  151. package/dist/visio/print-count.d.ts.map +1 -0
  152. package/dist/visio/print-settings.d.ts +14 -0
  153. package/dist/visio/print-settings.d.ts.map +1 -0
  154. package/dist/visio/shapes.d.ts.map +1 -1
  155. package/dist/visio/style.d.ts +1 -1
  156. package/dist/visio/style.d.ts.map +1 -1
  157. package/dist/visio/text-field-display.d.ts +3 -0
  158. package/dist/visio/text-field-display.d.ts.map +1 -1
  159. package/dist/visio/text-field-editability.d.ts +6 -0
  160. package/dist/visio/text-field-editability.d.ts.map +1 -0
  161. package/dist/visio/text-field-independent.d.ts +4 -0
  162. package/dist/visio/text-field-independent.d.ts.map +1 -0
  163. package/dist/visio/text-field-source.d.ts +6 -0
  164. package/dist/visio/text-field-source.d.ts.map +1 -0
  165. package/dist/visio/ui/edit-commands.d.ts.map +1 -1
  166. package/dist/visio/ui/index.cjs +588 -215
  167. package/dist/visio/ui/index.mjs +588 -215
  168. package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
  169. package/dist/xlsx/edit/pivots.d.ts.map +1 -1
  170. package/dist/xlsx/index.cjs +773 -514
  171. package/dist/xlsx/index.mjs +772 -515
  172. package/dist/xlsx/load/index.cjs +541 -292
  173. package/dist/xlsx/load/index.mjs +541 -292
  174. package/dist/xlsx/model-pivots.d.ts +8 -0
  175. package/dist/xlsx/model-pivots.d.ts.map +1 -1
  176. package/dist/xlsx/pivot/admission.d.ts.map +1 -1
  177. package/dist/xlsx/pivot/aggregate.d.ts.map +1 -1
  178. package/dist/xlsx/pivot/data.d.ts +2 -2
  179. package/dist/xlsx/pivot/data.d.ts.map +1 -1
  180. package/dist/xlsx/pivot/index.d.ts +2 -0
  181. package/dist/xlsx/pivot/index.d.ts.map +1 -1
  182. package/dist/xlsx/pivot/measures.d.ts +1 -1
  183. package/dist/xlsx/pivot/measures.d.ts.map +1 -1
  184. package/dist/xlsx/pivot/page-filter-admission.d.ts +5 -0
  185. package/dist/xlsx/pivot/page-filter-admission.d.ts.map +1 -0
  186. package/dist/xlsx/pivot/page-filter.d.ts +11 -0
  187. package/dist/xlsx/pivot/page-filter.d.ts.map +1 -0
  188. package/dist/xlsx/pivot/read.d.ts.map +1 -1
  189. package/dist/xlsx/pivot/table-xml.d.ts.map +1 -1
  190. package/dist/xlsx/pivot/values-axis.d.ts +4 -1
  191. package/dist/xlsx/pivot/values-axis.d.ts.map +1 -1
  192. package/dist/xlsx/ui/commands/i18n/navigation.d.ts.map +1 -1
  193. package/dist/xlsx/ui/commands/i18n/pivots.d.ts.map +1 -1
  194. package/dist/xlsx/ui/index.cjs +95 -12
  195. package/dist/xlsx/ui/index.mjs +95 -12
  196. package/dist/xlsx/ui/ribbon/parts.d.ts +1 -0
  197. package/dist/xlsx/ui/ribbon/parts.d.ts.map +1 -1
  198. package/package.json +2 -2
  199. package/dist/PptxHandler-5UURGJEV.mjs +0 -2
  200. package/dist/PptxHandler-U5XB2HUE.cjs +0 -11
  201. package/dist/pptx/chunks/index-Cuxtr76Y.d.ts.map +0 -1
  202. package/dist/pptx/chunks/index-DUCGeZh7.d.ts.map +0 -1
  203. package/dist/pptx/chunks/smart-art-D-sXa_Nb.d.ts +0 -2980
  204. package/dist/pptx/chunks/smart-art-D-sXa_Nb.d.ts.map +0 -1
  205. package/dist/pptx/chunks/text-operations-BqHmLaLA.d.ts.map +0 -1
@@ -1009,7 +1009,7 @@ function i(x, y, z) {
1009
1009
  }
1010
1010
  var T = Array.from(
1011
1011
  { length: 64 },
1012
- (_, index2) => Math.floor(Math.abs(Math.sin(index2 + 1)) * 2 ** 32)
1012
+ (_, index3) => Math.floor(Math.abs(Math.sin(index3 + 1)) * 2 ** 32)
1013
1013
  );
1014
1014
  var SHIFTS = [
1015
1015
  [7, 12, 17, 22],
@@ -2537,7 +2537,7 @@ function toArrayBuffer(bytes) {
2537
2537
  }
2538
2538
  function isCompoundFile(input) {
2539
2539
  const bytes = toBytes(input);
2540
- return bytes.length >= 8 && OLE_MAGIC2.every((value2, index2) => bytes[index2] === value2);
2540
+ return bytes.length >= 8 && OLE_MAGIC2.every((value2, index3) => bytes[index3] === value2);
2541
2541
  }
2542
2542
  function openEncryptedPackage(input) {
2543
2543
  const bytes = toBytes(input);
@@ -3718,7 +3718,7 @@ var PartPatch = class {
3718
3718
  const { root, children: children2 } = scan(xml);
3719
3719
  const kids2 = elements(rootElement);
3720
3720
  if (kids2.length !== children2.length) throw new Error("Property part markup is not supported");
3721
- kids2.forEach((kid, index2) => this.spans.set(kid, children2[index2]));
3721
+ kids2.forEach((kid, index3) => this.spans.set(kid, children2[index3]));
3722
3722
  this.root = root;
3723
3723
  for (const attribute2 of Array.from(rootElement.attributes)) {
3724
3724
  if (attribute2.name === "xmlns") this.defaultNs = attribute2.value;
@@ -3968,7 +3968,7 @@ function writeAppProperties(props, sourceXml) {
3968
3968
  const patch = new PartPatch(xml, root);
3969
3969
  const prior = readKnown(root, ns);
3970
3970
  const ownPrefix = root.prefix ? `${root.prefix}:` : "";
3971
- FIELDS2.forEach(([field, local, kind], index2) => {
3971
+ FIELDS2.forEach(([field, local, kind], index3) => {
3972
3972
  const value2 = props[field];
3973
3973
  const existing = first(root, local, ns.app);
3974
3974
  if (value2 === void 0 || kind === "text" && value2 === "") {
@@ -3982,7 +3982,7 @@ function writeAppProperties(props, sourceXml) {
3982
3982
  patch.setContent(existing, body);
3983
3983
  return;
3984
3984
  }
3985
- const next = FIELDS2.slice(index2 + 1).map(([, name]) => first(root, name, ns.app)).find((node) => node !== void 0);
3985
+ const next = FIELDS2.slice(index3 + 1).map(([, name]) => first(root, name, ns.app)).find((node) => node !== void 0);
3986
3986
  patch.insert(`<${ownPrefix}${local}>${body}</${ownPrefix}${local}>`, next);
3987
3987
  });
3988
3988
  return patch.toString();
@@ -4077,9 +4077,9 @@ function writeCustomProperties(properties2) {
4077
4077
  });
4078
4078
  if (!unique2.length) return void 0;
4079
4079
  const pids = allocateCustomPropertyIds(unique2);
4080
- const body = unique2.map((property, index2) => {
4080
+ const body = unique2.map((property, index3) => {
4081
4081
  const link = property.linkTarget ? ` linkTarget="${escape(property.linkTarget, true)}"` : "";
4082
- return `<property fmtid="${CUSTOM_PROPERTIES_FMTID}" pid="${pids[index2] ?? index2 + 2}" name="${escape(property.name, true)}"${link}>${variantXml(property)}</property>`;
4082
+ return `<property fmtid="${CUSTOM_PROPERTIES_FMTID}" pid="${pids[index3] ?? index3 + 2}" name="${escape(property.name, true)}"${link}>${variantXml(property)}</property>`;
4083
4083
  }).join("");
4084
4084
  return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
4085
4085
  <Properties xmlns="${NS.customProperties}" xmlns:vt="${NS.vt}">${body}</Properties>`;
@@ -5304,10 +5304,10 @@ var MONTH_NAMES = [
5304
5304
  function monthFromName(name) {
5305
5305
  const lower2 = name.toLowerCase();
5306
5306
  if (lower2.length < 3) return void 0;
5307
- const index2 = MONTH_NAMES.findIndex(
5307
+ const index3 = MONTH_NAMES.findIndex(
5308
5308
  (m) => m.startsWith(lower2) || lower2.length > 3 && lower2 === m
5309
5309
  );
5310
- return index2 < 0 ? void 0 : index2 + 1;
5310
+ return index3 < 0 ? void 0 : index3 + 1;
5311
5311
  }
5312
5312
  function fullYear(text) {
5313
5313
  const y = Number(text);
@@ -5534,10 +5534,10 @@ function internStyle(workbook, style2) {
5534
5534
  const known = cache2.get(key);
5535
5535
  if (known !== void 0 && workbook.styles[known] && styleKey(workbook.styles[known]) === key)
5536
5536
  return known;
5537
- const index2 = workbook.styles.findIndex((candidate) => styleKey(candidate) === key);
5538
- if (index2 >= 0) {
5539
- cache2.set(key, index2);
5540
- return index2;
5537
+ const index3 = workbook.styles.findIndex((candidate) => styleKey(candidate) === key);
5538
+ if (index3 >= 0) {
5539
+ cache2.set(key, index3);
5540
+ return index3;
5541
5541
  }
5542
5542
  workbook.styles.push(style2);
5543
5543
  cache2.set(key, workbook.styles.length - 1);
@@ -5644,7 +5644,7 @@ function createWorksheet(name, sheetId) {
5644
5644
  function createWorkbook(options = {}) {
5645
5645
  const names = options.sheets?.length ? options.sheets : ["Sheet1"];
5646
5646
  return {
5647
- sheets: names.map((name, index2) => createWorksheet(name, index2 + 1)),
5647
+ sheets: names.map((name, index3) => createWorksheet(name, index3 + 1)),
5648
5648
  styles: [defaultCellStyle()],
5649
5649
  namedStyles: [{ name: "Normal", style: defaultCellStyle(), builtinId: 0 }],
5650
5650
  definedNames: [],
@@ -6419,9 +6419,99 @@ function sparklineDataRange(workbook, sheet, source2) {
6419
6419
  }
6420
6420
  if (ast.type !== "ref" || !ast.ref || !["cell", "area"].includes(ast.ref.kind) || ast.prefix?.book || ast.prefix?.sheet2 || ast.spill)
6421
6421
  throw new Error("The reference is not valid.");
6422
- const index2 = ast.prefix ? workbook.sheets.findIndex((ws) => ws.name.toLowerCase() === ast.prefix.sheet.toLowerCase()) : sheet;
6423
- if (!workbook.sheets[index2]) throw new Error("The reference is not valid.");
6424
- return { sheet: index2, range: checkedSparklineRange({ start: ast.ref.start, end: ast.ref.end }) };
6422
+ const index3 = ast.prefix ? workbook.sheets.findIndex((ws) => ws.name.toLowerCase() === ast.prefix.sheet.toLowerCase()) : sheet;
6423
+ if (!workbook.sheets[index3]) throw new Error("The reference is not valid.");
6424
+ return { sheet: index3, range: checkedSparklineRange({ start: ast.ref.start, end: ast.ref.end }) };
6425
+ }
6426
+
6427
+ // xlsx/pivot/page-filter.ts
6428
+ function validatePivotPageFilter(pivot) {
6429
+ const filter2 = pivot.pageFilter;
6430
+ const extras = Array.isArray(pivot.additionalValues) ? pivot.additionalValues : [];
6431
+ if (filter2 === void 0) return;
6432
+ 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) || [
6433
+ pivot.rowField,
6434
+ pivot.secondRowField,
6435
+ pivot.columnField,
6436
+ pivot.valueField,
6437
+ ...extras.map((v) => v?.field)
6438
+ ].includes(filter2.field) || pivot.valuesAxis === "rows")
6439
+ throw new Error("Report filters require Values on columns and a separate source field.");
6440
+ 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))
6441
+ throw new Error("Choose a cached literal report filter item.");
6442
+ }
6443
+ function pivotPageProjection(pivot) {
6444
+ const filter2 = pivot.pageFilter;
6445
+ if (!filter2) return pivot;
6446
+ const labels = /* @__PURE__ */ new Map();
6447
+ for (const item of pivotItems(pivot, filter2.field)) {
6448
+ const label3 = String(pivotItemLabel(item)).toLowerCase(), key2 = pivotValueKey(item);
6449
+ if (label3 === "(all)" || labels.has(label3) && labels.get(label3) !== key2)
6450
+ throw new Error("Ambiguous report filter item captions are preserved.");
6451
+ labels.set(label3, key2);
6452
+ }
6453
+ if (filter2.item === void 0) return pivot;
6454
+ const index3 = pivot.fields.indexOf(filter2.field), key = pivotValueKey(filter2.item);
6455
+ const records = pivot.records.filter((record) => pivotValueKey(record[index3] ?? null) === key);
6456
+ if (!records.length) throw new Error("The report filter item is missing from the source.");
6457
+ if (JSON.stringify(records[0][index3] ?? null) !== JSON.stringify(filter2.item))
6458
+ throw new Error("Choose an exact cached literal report filter item.");
6459
+ return { ...pivot, records };
6460
+ }
6461
+ function prependPivotPage(grid, pivot) {
6462
+ if (!pivot.pageFilter) return grid;
6463
+ const width = grid.values[0].length;
6464
+ return {
6465
+ ...grid,
6466
+ values: [
6467
+ [
6468
+ pivot.pageFilter.field,
6469
+ pivot.pageFilter.item === void 0 ? "(All)" : pivotItemLabel(pivot.pageFilter.item),
6470
+ ...Array(width - 2).fill(null)
6471
+ ],
6472
+ Array(width).fill(null),
6473
+ ...grid.values
6474
+ ],
6475
+ firstDataRow: grid.firstDataRow + 2,
6476
+ ...grid.firstHeaderRow !== void 0 ? { firstHeaderRow: grid.firstHeaderRow + 2 } : {},
6477
+ ...grid.indents ? { indents: [0, 0, ...grid.indents] } : {}
6478
+ };
6479
+ }
6480
+ var index = (raw2) => raw2 !== null && /^\d+$/.test(raw2.trim()) && Number.isSafeInteger(Number(raw2)) ? Number(raw2) : NaN;
6481
+ function readPivotPageFilter(root, fields, shared) {
6482
+ const list = first(root, "pageFields", NS.x), location = first(root, "location", NS.x);
6483
+ const definitions = children(first(root, "pivotFields", NS.x), "pivotField", NS.x);
6484
+ if (!list) {
6485
+ if (definitions.some((n) => n.getAttribute("axis") === "axisPage") || location?.hasAttribute("rowPageCount") || location?.hasAttribute("colPageCount"))
6486
+ throw new Error("Unmodeled report filter metadata");
6487
+ return;
6488
+ }
6489
+ if (root.getAttribute("multipleFieldFilters") === "1")
6490
+ throw new Error("Multiple report filters are preserved");
6491
+ const pages = children(list, "pageField", NS.x);
6492
+ if (pages.length !== 1 || list.getAttribute("count") !== "1" || location?.getAttribute("rowPageCount") !== "1" || location.getAttribute("colPageCount") !== "1")
6493
+ throw new Error("Only one report filter is modeled");
6494
+ const page = pages[0], field = index(page.getAttribute("fld"));
6495
+ if (page.getAttribute("hier") !== "-1" || !fields[field] || definitions[field]?.getAttribute("axis") !== "axisPage" || definitions.filter((n) => n.getAttribute("axis") === "axisPage").length !== 1)
6496
+ throw new Error("Unsupported report field");
6497
+ const container2 = first(definitions[field], "items", NS.x);
6498
+ const items = children(container2, "item", NS.x);
6499
+ 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"))
6500
+ throw new Error("Unsupported report field items");
6501
+ const data = items.slice(0, -1).map((item2) => {
6502
+ const i2 = index(item2.getAttribute("x"));
6503
+ if (item2.hasAttribute("t") || !Number.isInteger(i2) || i2 >= shared[field].length)
6504
+ throw new Error("Invalid report cache item");
6505
+ return i2;
6506
+ });
6507
+ if (new Set(data).size !== data.length || data.length !== shared[field].length)
6508
+ throw new Error("Incomplete report cache items");
6509
+ const item = page.getAttribute("item");
6510
+ if (item === null) return { field: fields[field] };
6511
+ const selected2 = index(item);
6512
+ if (!Number.isInteger(selected2) || selected2 >= data.length)
6513
+ throw new Error("Invalid report item selection");
6514
+ return { field: fields[field], item: shared[field][data[selected2]] };
6425
6515
  }
6426
6516
 
6427
6517
  // xlsx/pivot/data.ts
@@ -6430,10 +6520,10 @@ function pivotValueKey(value2) {
6430
6520
  return value2 === null || value2 === "" ? "blank" : isCellError(value2) ? `error:${value2.error}` : `${typeof value2}:${String(value2).toLowerCase()}`;
6431
6521
  }
6432
6522
  function pivotItems(pivot, field) {
6433
- const index2 = pivot.fields.indexOf(field);
6523
+ const index3 = pivot.fields.indexOf(field);
6434
6524
  const items = /* @__PURE__ */ new Map();
6435
6525
  for (const record of pivot.records) {
6436
- const value2 = record[index2] ?? null;
6526
+ const value2 = record[index3] ?? null;
6437
6527
  const key = pivotValueKey(value2);
6438
6528
  if (!items.has(key)) items.set(key, value2);
6439
6529
  }
@@ -6451,6 +6541,7 @@ function pivotItemLabel(value2) {
6451
6541
  return isCellError(value2) ? value2.error : value2;
6452
6542
  }
6453
6543
  function validatePivotFields(pivot) {
6544
+ validatePivotPageFilter(pivot);
6454
6545
  const used = [
6455
6546
  pivot.rowField,
6456
6547
  ...pivot.secondRowField ? [pivot.secondRowField] : [],
@@ -6504,11 +6595,11 @@ function pivotHeaderDimensions(pivot, columnItems, rowLabels) {
6504
6595
  const measures = 1 + (pivot.additionalValues?.length ?? 0);
6505
6596
  if (pivot.valuesAxis === "rows")
6506
6597
  return {
6507
- rows: pivot.columnField ? 2 : 1,
6598
+ rows: (pivot.columnField ? 2 : 1) + (pivot.pageFilter ? 2 : 0),
6508
6599
  width: rowLabels + (pivot.columnField ? columnItems + 1 : 1)
6509
6600
  };
6510
6601
  return {
6511
- rows: pivot.columnField ? measures > 1 ? 3 : 2 : 1,
6602
+ rows: (pivot.columnField ? measures > 1 ? 3 : 2 : 1) + (pivot.pageFilter ? 2 : 0),
6512
6603
  width: rowLabels + (pivot.columnField ? measures === 1 ? Math.max(1, columnItems) + 1 : (columnItems + 1) * measures : measures)
6513
6604
  };
6514
6605
  }
@@ -6652,7 +6743,7 @@ function hierarchicalPivotGrid(pivot) {
6652
6743
  const groups = /* @__PURE__ */ new Map();
6653
6744
  const details = /* @__PURE__ */ new Map();
6654
6745
  const children2 = /* @__PURE__ */ new Map();
6655
- const innerIndices = new Map(secondRowItems.map((item, index2) => [pivotValueKey(item), index2]));
6746
+ const innerIndices = new Map(secondRowItems.map((item, index3) => [pivotValueKey(item), index3]));
6656
6747
  const buckets = /* @__PURE__ */ new Map();
6657
6748
  const collect = (map, key, record) => {
6658
6749
  const list = map.get(key);
@@ -6844,6 +6935,9 @@ function hierarchicalPivotGrid(pivot) {
6844
6935
  // xlsx/pivot/aggregate.ts
6845
6936
  function pivotGrid(pivot) {
6846
6937
  validatePivotFields(pivot);
6938
+ return prependPivotPage(pivotDataGrid(pivotPageProjection(pivot)), pivot);
6939
+ }
6940
+ function pivotDataGrid(pivot) {
6847
6941
  if (pivot.secondRowField) return hierarchicalPivotGrid(pivot);
6848
6942
  const rowItems = pivotItems(pivot, pivot.rowField);
6849
6943
  const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
@@ -6885,7 +6979,7 @@ function pivotGrid(pivot) {
6885
6979
  const measures = pivotMeasures(pivot);
6886
6980
  const rowEntries = [];
6887
6981
  const indents = values2.map(() => 0);
6888
- const append = (caption, bands, index2, grand = false) => {
6982
+ const append = (caption, bands, index3, grand = false) => {
6889
6983
  measures.forEach((measure, m) => {
6890
6984
  values2.push([
6891
6985
  ...compact ? [grand ? `Total ${measure.caption}` : measure.caption] : [
@@ -6896,17 +6990,17 @@ function pivotGrid(pivot) {
6896
6990
  ]);
6897
6991
  indents.push(compact && !grand ? 1 : 0);
6898
6992
  rowEntries.push({
6899
- indices: grand ? [0] : [index2, m],
6993
+ indices: grand ? [0] : [index3, m],
6900
6994
  measure: m,
6901
6995
  ...grand ? { type: "grand" } : {}
6902
6996
  });
6903
6997
  });
6904
6998
  };
6905
- rowItems.forEach((item, index2) => {
6999
+ rowItems.forEach((item, index3) => {
6906
7000
  const key = pivotValueKey(item);
6907
7001
  if (headings) {
6908
7002
  values2.push([label3(item), ...Array(dimensions.width - 1).fill(null)]);
6909
- rowEntries.push({ indices: [index2] });
7003
+ rowEntries.push({ indices: [index3] });
6910
7004
  indents.push(0);
6911
7005
  }
6912
7006
  append(
@@ -6917,7 +7011,7 @@ function pivotGrid(pivot) {
6917
7011
  ),
6918
7012
  pivotNumbers(pivot, groups.get(key) ?? [])
6919
7013
  ],
6920
- index2
7014
+ index3
6921
7015
  );
6922
7016
  });
6923
7017
  append(
@@ -6966,7 +7060,9 @@ var X14 = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main";
6966
7060
  var LAYOUT = "http://schemas.microsoft.com/office/spreadsheetml/2016/pivotdefaultlayout";
6967
7061
  var TABLE = {
6968
7062
  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",
6969
- location: "ref firstHeaderRow firstDataRow firstDataCol",
7063
+ location: "ref firstHeaderRow firstDataRow firstDataCol rowPageCount colPageCount",
7064
+ pageFields: "count",
7065
+ pageField: "fld item hier",
6970
7066
  pivotFields: "count",
6971
7067
  pivotField: "axis dataField compact outline showAll subtotalTop defaultSubtotal",
6972
7068
  items: "count",
@@ -7101,6 +7197,18 @@ function inlineFragment(xml) {
7101
7197
  }
7102
7198
 
7103
7199
  // xlsx/pivot/values-axis.ts
7200
+ function remapPivotRowEntries(entries, axes2) {
7201
+ return entries.map(
7202
+ (entry3) => entry3.type === "grand" ? entry3 : {
7203
+ ...entry3,
7204
+ indices: entry3.indices.map((item, axis) => {
7205
+ const index3 = axes2[axis]?.[item];
7206
+ if (index3 === void 0) throw new Error("Invalid report row axis item");
7207
+ return index3;
7208
+ })
7209
+ }
7210
+ );
7211
+ }
7104
7212
  function pivotFieldIndex(field) {
7105
7213
  const raw2 = field?.getAttribute("x");
7106
7214
  if (raw2 === null || raw2 === void 0 || !/^-?\d+$/.test(raw2.trim())) return NaN;
@@ -7108,15 +7216,15 @@ function pivotFieldIndex(field) {
7108
7216
  return Number.isSafeInteger(value2) ? value2 : NaN;
7109
7217
  }
7110
7218
  function pivotValueIndex(root, axis) {
7111
- const index2 = axis.findIndex((field) => pivotFieldIndex(field) === -2);
7219
+ const index3 = axis.findIndex((field) => pivotFieldIndex(field) === -2);
7112
7220
  const position = root.getAttribute("dataPosition");
7113
- if (position !== null && (!/^\d+$/.test(position.trim()) || Number(position) !== index2))
7221
+ if (position !== null && (!/^\d+$/.test(position.trim()) || Number(position) !== index3))
7114
7222
  throw new Error("Inconsistent Values axis position");
7115
- if (axis.length === 3 && index2 < 2 && position === null)
7223
+ if (axis.length === 3 && index3 < 2 && position === null)
7116
7224
  throw new Error("Missing leading or between-field Values position");
7117
- return index2;
7225
+ return index3;
7118
7226
  }
7119
- function pivotValueAxisItems(measures, columns) {
7227
+ function pivotValueAxisItems(measures, columns, columnIndices) {
7120
7228
  const entries = [];
7121
7229
  if (columns === void 0) {
7122
7230
  for (let measure = 0; measure < measures; measure++)
@@ -7127,7 +7235,7 @@ function pivotValueAxisItems(measures, columns) {
7127
7235
  for (let column = 0; column < columns; column++)
7128
7236
  for (let measure = 0; measure < measures; measure++) {
7129
7237
  entries.push(
7130
- `<i${attrs({ r: measure ? 1 : void 0, i: measure || void 0 })}>${measure ? "" : `<x${attrs({ v: column || void 0 })}/>`}<x${attrs({ v: measure || void 0 })}/></i>`
7238
+ `<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>`
7131
7239
  );
7132
7240
  }
7133
7241
  for (let measure = 0; measure < measures; measure++)
@@ -7136,11 +7244,169 @@ function pivotValueAxisItems(measures, columns) {
7136
7244
  return `<colItems count="${entries.length}">${entries.join("")}</colItems>`;
7137
7245
  }
7138
7246
  function supportedPivotAxes(rows, columns, measures, valuesOnRows) {
7139
- const index2 = pivotFieldIndex;
7247
+ const index3 = pivotFieldIndex;
7140
7248
  if (valuesOnRows)
7141
- return measures > 1 && (rows.length === 2 || rows.length === 3) && (index2(rows[0]) >= 0 || rows.length === 3) && rows.filter((field) => index2(field) === -2).length === 1 && rows.filter((field) => index2(field) !== -2).every((field) => index2(field) >= 0) && columns.length <= 1 && (!columns.length || index2(columns[0]) >= 0);
7142
- if (rows.some((field) => !Number.isInteger(index2(field)) || index2(field) < 0)) return false;
7143
- return measures === 1 ? columns.length <= 1 : columns.length >= 1 && columns.length <= 2 && index2(columns.at(-1)) === -2 && (columns.length !== 2 || index2(columns[0]) >= 0);
7249
+ 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);
7250
+ if (rows.some((field) => !Number.isInteger(index3(field)) || index3(field) < 0)) return false;
7251
+ return measures === 1 ? columns.length <= 1 : columns.length >= 1 && columns.length <= 2 && index3(columns.at(-1)) === -2 && (columns.length !== 2 || index3(columns[0]) >= 0);
7252
+ }
7253
+
7254
+ // drawingml/dom.ts
7255
+ function attributeReader(element2) {
7256
+ return (name) => {
7257
+ if (!element2) return void 0;
7258
+ const direct = element2.getAttribute(name);
7259
+ if (direct !== null) return direct;
7260
+ const attributes = element2.attributes;
7261
+ for (let index3 = 0; index3 < attributes.length; index3++) {
7262
+ const candidate = attributes.item(index3);
7263
+ if (candidate && candidate.localName === name) return candidate.value;
7264
+ }
7265
+ return void 0;
7266
+ };
7267
+ }
7268
+ function stringAttribute(element2, name) {
7269
+ const value2 = attributeReader(element2)(name)?.trim();
7270
+ return value2 ? value2 : void 0;
7271
+ }
7272
+ function integerAttribute(element2, name) {
7273
+ const parsed = Number.parseInt(attributeReader(element2)(name) ?? "", 10);
7274
+ return Number.isFinite(parsed) ? parsed : void 0;
7275
+ }
7276
+ function booleanAttribute(element2, name) {
7277
+ const value2 = attributeReader(element2)(name)?.trim().toLowerCase();
7278
+ if (value2 === "1" || value2 === "true") return true;
7279
+ if (value2 === "0" || value2 === "false") return false;
7280
+ return void 0;
7281
+ }
7282
+ function descendants2(root, local) {
7283
+ const result2 = [];
7284
+ const visit = (node) => {
7285
+ for (const child4 of Array.from(node.childNodes)) {
7286
+ if (!isElement(child4)) continue;
7287
+ if (child4.localName === local) result2.push(child4);
7288
+ visit(child4);
7289
+ }
7290
+ };
7291
+ visit(root);
7292
+ return result2;
7293
+ }
7294
+
7295
+ // xlsx/pivot/page-filter-admission.ts
7296
+ var integer = (value2, fallback) => value2 === null ? fallback ?? NaN : /^\d+$/.test(value2.trim()) && Number.isSafeInteger(Number(value2)) ? Number(value2) : NaN;
7297
+ function assertPageAxisItems(root, pivot, shared, cache2, recordRoot) {
7298
+ if (!pivot.pageFilter) return;
7299
+ const literals = (node) => {
7300
+ const raw2 = node.getAttribute("v");
7301
+ 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())))
7302
+ throw new Error("Unmodeled report cache literal");
7303
+ for (const child4 of elements(node)) literals(child4);
7304
+ };
7305
+ literals(cache2);
7306
+ literals(recordRoot);
7307
+ const cacheFields = children(first(cache2, "cacheFields", NS.x), "cacheField", NS.x);
7308
+ if (pivot.columnField) {
7309
+ const column = children(first(root, "pivotFields", NS.x), "pivotField", NS.x)[pivot.fields.indexOf(pivot.columnField)];
7310
+ const list = first(column, "extLst", NS.x);
7311
+ const extensions = list ? children(list, "ext", NS.x) : [];
7312
+ if (extensions.some(
7313
+ (extension) => children(
7314
+ extension,
7315
+ "pivotField",
7316
+ "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
7317
+ ).some((field) => {
7318
+ const raw2 = field.getAttribute("fillDownLabels");
7319
+ if (raw2 !== null && !["0", "1", "false", "true"].includes(raw2.trim()))
7320
+ throw new Error("Invalid report column label repetition");
7321
+ return booleanAttribute(field, "fillDownLabels") === true;
7322
+ })
7323
+ ))
7324
+ throw new Error("Repeated report column labels are preserved");
7325
+ }
7326
+ 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)
7327
+ throw new Error("Inconsistent report cache counts");
7328
+ for (const name of [
7329
+ pivot.rowField,
7330
+ pivot.secondRowField,
7331
+ pivot.columnField,
7332
+ pivot.pageFilter.field
7333
+ ].filter(Boolean)) {
7334
+ const field = pivot.fields.indexOf(name);
7335
+ if (integer(first(cacheFields[field], "sharedItems", NS.x)?.getAttribute("count") ?? null) !== shared[field].length)
7336
+ throw new Error("Inconsistent report shared-item counts");
7337
+ }
7338
+ for (const name of ["rowFields", "colFields"]) {
7339
+ const list = first(root, name, NS.x);
7340
+ if (list && integer(list.getAttribute("count")) !== children(list, "field", NS.x).length)
7341
+ throw new Error("Inconsistent report axis counts");
7342
+ }
7343
+ const projected = pivotPageProjection(pivot), fields = children(first(root, "pivotFields", NS.x), "pivotField", NS.x);
7344
+ const axisValues = (name, axis) => {
7345
+ 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;
7346
+ if (node.getAttribute("axis") !== axis) throw new Error("Inconsistent report axis field");
7347
+ const defaults = node.getAttribute("defaultSubtotal") !== "0";
7348
+ if (!list || integer(list.getAttribute("count")) !== items.length || items.length !== count2 + Number(defaults))
7349
+ throw new Error("Incomplete page-axis field items");
7350
+ const data = items.slice(0, count2).map((item) => {
7351
+ const i2 = integer(item.getAttribute("x"));
7352
+ if (item.hasAttribute("t") || !Number.isInteger(i2) || i2 >= count2)
7353
+ throw new Error("Invalid page-axis cache item");
7354
+ return shared[f6][i2];
7355
+ });
7356
+ if (new Set(data.map(pivotValueKey)).size !== count2 || defaults && (items.at(-1)?.getAttribute("t") !== "default" || items.at(-1)?.hasAttribute("x")))
7357
+ throw new Error("Invalid page-axis default item");
7358
+ const indices = new Map(data.map((v, i2) => [pivotValueKey(v), i2]));
7359
+ return pivotItems(projected, name).map((v) => indices.get(pivotValueKey(v)));
7360
+ };
7361
+ const read = (name) => {
7362
+ const list = first(root, name, NS.x), items = children(list, "i", NS.x);
7363
+ if (!list || integer(list.getAttribute("count")) !== items.length)
7364
+ throw new Error("Invalid page-axis item count");
7365
+ return items;
7366
+ };
7367
+ const rows = axisValues(pivot.rowField, "axisRow"), rowItems = read("rowItems");
7368
+ const grid = pivotGrid(pivot);
7369
+ const entries = grid.rowEntries ? remapPivotRowEntries(grid.rowEntries, [
7370
+ rows,
7371
+ pivot.secondRowField ? axisValues(pivot.secondRowField, "axisRow") : []
7372
+ ]) : [
7373
+ ...rows.map((index3) => ({ indices: [index3], type: void 0 })),
7374
+ { indices: [0], type: "grand" }
7375
+ ];
7376
+ if (rowItems.length !== entries.length) throw new Error("Invalid page row items");
7377
+ let previousRow = [];
7378
+ rowItems.forEach((item, i2) => {
7379
+ const expected2 = entries[i2];
7380
+ const xs = children(item, "x", NS.x).map((x) => integer(x.getAttribute("v"), 0)), prefix = integer(item.getAttribute("r"), 0);
7381
+ 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))
7382
+ throw new Error("Unmodeled page row item");
7383
+ previousRow = expected2.type ? [] : expected2.indices;
7384
+ });
7385
+ const measures = 1 + (pivot.additionalValues?.length ?? 0), columns = pivot.columnField ? axisValues(pivot.columnField, "axisCol") : void 0, expected = [];
7386
+ if (columns)
7387
+ for (const col of columns)
7388
+ for (let m = 0; m < measures; m++) expected.push(measures > 1 ? [col, m] : [col]);
7389
+ else for (let m = 0; m < measures; m++) expected.push([m]);
7390
+ const colItems = read("colItems");
7391
+ if (colItems.length !== expected.length + (columns ? measures : 0))
7392
+ throw new Error("Invalid page column items");
7393
+ let previous = [];
7394
+ colItems.forEach((item, i2) => {
7395
+ const grand = i2 >= expected.length, measure = grand ? i2 - expected.length : i2 % measures;
7396
+ const xs = children(item, "x", NS.x).map((x) => integer(x.getAttribute("v"), 0)), prefix = integer(item.getAttribute("r"), 0);
7397
+ if (integer(item.getAttribute("i"), 0) !== measure || !Number.isInteger(prefix) || prefix < 0 || prefix > Math.max(0, previous.length - 1))
7398
+ throw new Error("Invalid page column prefix");
7399
+ if (grand) {
7400
+ if (item.getAttribute("t") !== "grand" || prefix !== 0 || xs.length !== 1 || xs[0] !== 0)
7401
+ throw new Error("Unmodeled page grand item");
7402
+ previous = [];
7403
+ return;
7404
+ }
7405
+ const values2 = !columns && measures === 1 && xs.length === 0 && prefix === 0 ? [0] : [...previous.slice(0, prefix), ...xs];
7406
+ if (item.hasAttribute("t") || JSON.stringify(values2) !== JSON.stringify(expected[i2]))
7407
+ throw new Error("Unmodeled page column item");
7408
+ previous = values2;
7409
+ });
7144
7410
  }
7145
7411
 
7146
7412
  // xlsx/pivot/read.ts
@@ -7180,20 +7446,21 @@ function readOne(workbook, source2, part) {
7180
7446
  const rowsAxis = att(root, "dataOnRows") === "1";
7181
7447
  if (!dataSheet || !dataRange || !recordPart || !workbook.sheets.some((sheet) => sheet.name === dataSheet))
7182
7448
  throw new Error("Unsupported pivot source");
7183
- assertPivotRecords(parseXml(source2.text(recordPart)).documentElement);
7449
+ const recordRoot = parseXml(source2.text(recordPart)).documentElement;
7450
+ assertPivotRecords(recordRoot);
7184
7451
  const fields = children(first(cache2, "cacheFields", NS.x), "cacheField", NS.x);
7185
7452
  if (fields.some((field) => first(field, "fieldGroup", NS.x) || field.hasAttribute("formula")))
7186
7453
  throw new Error("Grouped or calculated cache field");
7187
7454
  const shared = fields.map(
7188
7455
  (field) => elements(first(field, "sharedItems", NS.x) ?? parseXml("<root/>").documentElement).map(value)
7189
7456
  );
7190
- const records = children(parseXml(source2.text(recordPart)).documentElement, "r", NS.x).map(
7457
+ const records = children(recordRoot, "r", NS.x).map(
7191
7458
  (record) => elements(record).map((node, field) => {
7192
7459
  if (node.localName !== "x") return value(node);
7193
- const index2 = Number(att(node, "v"));
7194
- if (!Number.isInteger(index2) || index2 < 0 || index2 >= (shared[field]?.length ?? 0))
7460
+ const index3 = Number(att(node, "v"));
7461
+ if (!Number.isInteger(index3) || index3 < 0 || index3 >= (shared[field]?.length ?? 0))
7195
7462
  throw new Error("Invalid pivot cache index");
7196
- return shared[field][index2];
7463
+ return shared[field][index3];
7197
7464
  })
7198
7465
  );
7199
7466
  if (records.some((record) => record.length !== fields.length) || records.length * fields.length > 1e6)
@@ -7213,7 +7480,7 @@ function readOne(workbook, source2, part) {
7213
7480
  "dataField",
7214
7481
  NS.x
7215
7482
  );
7216
- if (rowFields.length < 1 || rowFields.length > (rowsAxis ? 3 : 2) || dataFields.length < 1 || dataFields.length > 16 || !supportedPivotAxes(rowFields, colFields, dataFields.length, rowsAxis) || first(root, "pageFields", NS.x) || first(root, "filters", NS.x) || root.getAttribute("rowGrandTotals") === "0" || root.getAttribute("colGrandTotals") === "0")
7483
+ 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")
7217
7484
  throw new Error("Unsupported pivot layout");
7218
7485
  const valueIndex = pivotValueIndex(root, rowsAxis ? rowFields : colFields);
7219
7486
  const measure = dataFields[0];
@@ -7235,8 +7502,8 @@ function readOne(workbook, source2, part) {
7235
7502
  "i",
7236
7503
  NS.x
7237
7504
  )) {
7238
- const index2 = Number(att(item, "i") ?? "0");
7239
- if (!Number.isInteger(index2) || index2 < 0 || index2 >= count2)
7505
+ const index3 = Number(att(item, "i") ?? "0");
7506
+ if (!Number.isInteger(index3) || index3 < 0 || index3 >= count2)
7240
7507
  throw new Error("Unsupported Values axis item");
7241
7508
  }
7242
7509
  }
@@ -7247,6 +7514,7 @@ function readOne(workbook, source2, part) {
7247
7514
  const realRows = rowsAxis ? rowFields.filter((field) => pivotFieldIndex(field) !== -2) : rowFields;
7248
7515
  const row2 = names[pivotFieldIndex(realRows[0])];
7249
7516
  const second = realRows[1] ? names[Number(att(realRows[1], "x"))] : void 0;
7517
+ const pageFilter = readPivotPageFilter(root, names, shared);
7250
7518
  const tableFields = children(first(root, "pivotFields", NS.x), "pivotField", NS.x);
7251
7519
  const outer = tableFields[pivotFieldIndex(realRows[0])];
7252
7520
  const compact = att(outer, "compact") !== "0";
@@ -7276,7 +7544,12 @@ function readOne(workbook, source2, part) {
7276
7544
  const location = parseRange(att(first(root, "location", NS.x), "ref") ?? "");
7277
7545
  if (!row2 || !data || !location || hasColumn && !col || realRows.length === 2 && !second)
7278
7546
  throw new Error("Invalid pivot fields");
7547
+ if (pageFilter) {
7548
+ if (location.start.row < 2) throw new Error("Invalid report filter location");
7549
+ location.start.row -= 2;
7550
+ }
7279
7551
  const pivot = {
7552
+ ...pageFilter ? { pageFilter } : {},
7280
7553
  name: att(root, "name") ?? "PivotTable",
7281
7554
  source: `${quoteSheetName(dataSheet)}!${formatRange(dataRange)}`,
7282
7555
  rowField: row2,
@@ -7308,6 +7581,7 @@ function readOne(workbook, source2, part) {
7308
7581
  sourceXml: xml,
7309
7582
  ...col ? { columnField: col } : {}
7310
7583
  };
7584
+ assertPageAxisItems(root, pivot, shared, cache2, recordRoot);
7311
7585
  return pivot;
7312
7586
  }
7313
7587
  function readPivotTables(workbook, source2, warn) {
@@ -7633,10 +7907,10 @@ function parseDynamicArrayMetadata(xml) {
7633
7907
  const flag2 = props?.getAttribute("fDynamic");
7634
7908
  return flag2 === "1" || flag2 === "true";
7635
7909
  });
7636
- childrenNamed(top.get("cellMetadata")?.[0], "bk").forEach((bk, index2) => {
7910
+ childrenNamed(top.get("cellMetadata")?.[0], "bk").forEach((bk, index3) => {
7637
7911
  for (const rc of childrenNamed(bk, "rc")) {
7638
7912
  const type = types[Number(att(rc, "t")) - 1];
7639
- if (type === DYNAMIC_ARRAY_TYPE && dynamic[Number(att(rc, "v"))]) out.add(index2 + 1);
7913
+ if (type === DYNAMIC_ARRAY_TYPE && dynamic[Number(att(rc, "v"))]) out.add(index3 + 1);
7640
7914
  }
7641
7915
  });
7642
7916
  return out;
@@ -7914,13 +8188,13 @@ function parseStyles(xml, warnings) {
7914
8188
  const named2 = namesByXf.get(xfId);
7915
8189
  if (named2 && xfId !== 0 && named2 !== "Normal") style2.cellStyleName = named2;
7916
8190
  const key = styleKey(style2);
7917
- let index2 = keys.get(key);
7918
- if (index2 === void 0) {
7919
- index2 = styles.length;
8191
+ let index3 = keys.get(key);
8192
+ if (index3 === void 0) {
8193
+ index3 = styles.length;
7920
8194
  styles.push(style2);
7921
- keys.set(key, index2);
8195
+ keys.set(key, index3);
7922
8196
  }
7923
- xfMap.push(index2);
8197
+ xfMap.push(index3);
7924
8198
  }
7925
8199
  if (!styles.length) {
7926
8200
  styles.push(fallback);
@@ -7934,47 +8208,6 @@ function parseStyles(xml, warnings) {
7934
8208
  return result2;
7935
8209
  }
7936
8210
 
7937
- // drawingml/dom.ts
7938
- function attributeReader(element2) {
7939
- return (name) => {
7940
- if (!element2) return void 0;
7941
- const direct = element2.getAttribute(name);
7942
- if (direct !== null) return direct;
7943
- const attributes = element2.attributes;
7944
- for (let index2 = 0; index2 < attributes.length; index2++) {
7945
- const candidate = attributes.item(index2);
7946
- if (candidate && candidate.localName === name) return candidate.value;
7947
- }
7948
- return void 0;
7949
- };
7950
- }
7951
- function stringAttribute(element2, name) {
7952
- const value2 = attributeReader(element2)(name)?.trim();
7953
- return value2 ? value2 : void 0;
7954
- }
7955
- function integerAttribute(element2, name) {
7956
- const parsed = Number.parseInt(attributeReader(element2)(name) ?? "", 10);
7957
- return Number.isFinite(parsed) ? parsed : void 0;
7958
- }
7959
- function booleanAttribute(element2, name) {
7960
- const value2 = attributeReader(element2)(name)?.trim().toLowerCase();
7961
- if (value2 === "1" || value2 === "true") return true;
7962
- if (value2 === "0" || value2 === "false") return false;
7963
- return void 0;
7964
- }
7965
- function descendants2(root, local) {
7966
- const result2 = [];
7967
- const visit = (node) => {
7968
- for (const child4 of Array.from(node.childNodes)) {
7969
- if (!isElement(child4)) continue;
7970
- if (child4.localName === local) result2.push(child4);
7971
- visit(child4);
7972
- }
7973
- };
7974
- visit(root);
7975
- return result2;
7976
- }
7977
-
7978
8211
  // drawingml/drawing-color.ts
7979
8212
  var COLOR_ELEMENTS = {
7980
8213
  srgbClr: "srgb",
@@ -8120,7 +8353,7 @@ function parseTheme2(xml) {
8120
8353
  if (!xml) return palette;
8121
8354
  const theme = parseTheme(parseXml(xml, { label: "XLSX theme" }));
8122
8355
  palette.colors = PALETTE_SLOTS.map(
8123
- (slot2, index2) => paletteHex(theme.colorScheme.colors[slot2]) ?? DEFAULT_THEME.colors[index2] ?? "000000"
8356
+ (slot2, index3) => paletteHex(theme.colorScheme.colors[slot2]) ?? DEFAULT_THEME.colors[index3] ?? "000000"
8124
8357
  );
8125
8358
  palette.majorFont = theme.fontScheme.major.latin ?? palette.majorFont;
8126
8359
  palette.minorFont = theme.fontScheme.minor.latin ?? palette.minorFont;
@@ -8508,11 +8741,11 @@ function readModernHash(node, prefix = "") {
8508
8741
  function parseWorkbookPart(xml) {
8509
8742
  const root = parseXml(xml, { label: "XLSX workbook" }).documentElement;
8510
8743
  const sheets = [];
8511
- xChildren(xFirst(root, "sheets") ?? root, "sheet").forEach((node, index2) => {
8744
+ xChildren(xFirst(root, "sheets") ?? root, "sheet").forEach((node, index3) => {
8512
8745
  const state = att(node, "state");
8513
8746
  sheets.push({
8514
- name: att(node, "name") ?? `Sheet${index2 + 1}`,
8515
- sheetId: numAttr(node, "sheetId") ?? index2 + 1,
8747
+ name: att(node, "name") ?? `Sheet${index3 + 1}`,
8748
+ sheetId: numAttr(node, "sheetId") ?? index3 + 1,
8516
8749
  state: state === "hidden" || state === "veryHidden" ? state : "visible",
8517
8750
  relId: relAttr(node, "id") ?? ""
8518
8751
  });
@@ -8862,8 +9095,8 @@ function styleRef(element2) {
8862
9095
  if (element2.localName === "fontRef") {
8863
9096
  if (raw2) ref.fontIndex = raw2;
8864
9097
  } else {
8865
- const index2 = Number.parseInt(raw2 ?? "", 10);
8866
- if (Number.isFinite(index2)) ref.index = index2;
9098
+ const index3 = Number.parseInt(raw2 ?? "", 10);
9099
+ if (Number.isFinite(index3)) ref.index = index3;
8867
9100
  }
8868
9101
  const color = parseDrawingColorIn(element2);
8869
9102
  if (color) ref.color = color;
@@ -9242,11 +9475,11 @@ function groupTransform(group, parent) {
9242
9475
  scaleY: parent.scaleY * local.scaleY
9243
9476
  };
9244
9477
  }
9245
- function parseShape(sp, index2, group, issues) {
9478
+ function parseShape(sp, index3, group, issues) {
9246
9479
  const spPr = first(sp, "spPr", NS.dsp);
9247
9480
  const transform6 = parseTransform(first(spPr, "xfrm", NS.a));
9248
9481
  if (!transform6) return void 0;
9249
- const modelId = stringAttribute(sp, "modelId") ?? stringAttribute(first(first(sp, "nvSpPr", NS.dsp), "cNvPr", NS.dsp), "id") ?? `dsp-${index2}`;
9482
+ const modelId = stringAttribute(sp, "modelId") ?? stringAttribute(first(first(sp, "nvSpPr", NS.dsp), "cNvPr", NS.dsp), "id") ?? `dsp-${index3}`;
9250
9483
  const { geometry, adjustments, paths, issue } = parseDrawingGeometry(spPr);
9251
9484
  if (issue) issues.push({ code: issue, message: `Shape ${modelId}: ${issue}.` });
9252
9485
  const frame = applyGroup(transform6.frame, group);
@@ -9464,8 +9697,8 @@ function drawingFillXml(fill) {
9464
9697
  const stops = children(list, "gs", NS.a).filter(
9465
9698
  (node) => parseDrawingColorIn(node) && Number.isFinite(Number.parseInt(node.getAttribute("pos") ?? "", 10))
9466
9699
  );
9467
- fill.stops.forEach((stop, index2) => {
9468
- const node = stops[index2] ?? doc.createElementNS(NS.a, "a:gs");
9700
+ fill.stops.forEach((stop, index3) => {
9701
+ const node = stops[index3] ?? doc.createElementNS(NS.a, "a:gs");
9469
9702
  if (!node.parentNode) list.appendChild(node);
9470
9703
  node.setAttribute("pos", String(Math.round(stop.position * 1e3)));
9471
9704
  for (const old of elements(node))
@@ -9983,8 +10216,8 @@ function writeSettings(node, rule) {
9983
10216
  if (rule.minLength !== void 0) bar.setAttribute("minLength", String(rule.minLength));
9984
10217
  if (rule.maxLength !== void 0) bar.setAttribute("maxLength", String(rule.maxLength));
9985
10218
  const thresholds = children(bar, "cfvo", NS.x14);
9986
- for (const [index2, threshold] of [rule.min, rule.max].entries()) {
9987
- const target = thresholds[index2];
10219
+ for (const [index3, threshold] of [rule.min, rule.max].entries()) {
10220
+ const target = thresholds[index3];
9988
10221
  if (!target) continue;
9989
10222
  const oldType = target.getAttribute("type");
9990
10223
  if (oldType === "autoMin" && threshold.type === "min" || oldType === "autoMax" && threshold.type === "max")
@@ -10248,7 +10481,7 @@ function chartCacheValues(cache2) {
10248
10481
  out[point.index ?? out.length] = numeric2 && text.trim() !== "" && Number.isFinite(Number(text)) ? Number(text) : text;
10249
10482
  }
10250
10483
  const size = Math.max(cache2.pointCount ?? 0, out.length);
10251
- for (let index2 = 0; index2 < size; index2++) if (out[index2] === void 0) out[index2] = "";
10484
+ for (let index3 = 0; index3 < size; index3++) if (out[index3] === void 0) out[index3] = "";
10252
10485
  return out;
10253
10486
  }
10254
10487
  var chartSourceValues = (source2) => chartCacheValues(source2?.cache ?? source2?.levels?.[0]);
@@ -10383,8 +10616,8 @@ function parseCache(node) {
10383
10616
  type: node.localName === "numCache" || node.localName === "numLit" ? "number" : "string",
10384
10617
  points: children(node, "pt", NS.c).map((pt) => {
10385
10618
  const point = { value: cChild(pt, "v")?.textContent ?? "" };
10386
- const index2 = Number(attribute(pt, "idx") ?? Number.NaN);
10387
- if (Number.isInteger(index2) && index2 >= 0) point.index = index2;
10619
+ const index3 = Number(attribute(pt, "idx") ?? Number.NaN);
10620
+ if (Number.isInteger(index3) && index3 >= 0) point.index = index3;
10388
10621
  const formatCode2 = attribute(pt, "formatCode");
10389
10622
  if (formatCode2 !== void 0) point.formatCode = formatCode2;
10390
10623
  return point;
@@ -10610,11 +10843,11 @@ var POINT = /* @__PURE__ */ new Set([
10610
10843
  ]);
10611
10844
  function parseDataPoint(context, element2) {
10612
10845
  reportUnmodelled(context, element2, POINT);
10613
- const index2 = cNumber(context, element2, "idx");
10846
+ const index3 = cNumber(context, element2, "idx");
10614
10847
  return assignDefined(
10615
10848
  {},
10616
10849
  {
10617
- index: index2 !== void 0 && Number.isInteger(index2) && index2 >= 0 ? index2 : void 0,
10850
+ index: index3 !== void 0 && Number.isInteger(index3) && index3 >= 0 ? index3 : void 0,
10618
10851
  invertIfNegative: cBool(context, element2, "invertIfNegative"),
10619
10852
  bubble3D: cBool(context, element2, "bubble3D"),
10620
10853
  explosion: cNumber(context, element2, "explosion"),
@@ -11151,8 +11384,8 @@ var SCHEME_INDEX = {
11151
11384
  function legacyColor(color) {
11152
11385
  if (color?.kind === "srgb") return color.value ? { rgb: color.value.toUpperCase() } : void 0;
11153
11386
  if (color?.kind === "scheme") {
11154
- const index2 = SCHEME_INDEX[color.value];
11155
- return index2 === void 0 ? void 0 : { theme: index2 };
11387
+ const index3 = SCHEME_INDEX[color.value];
11388
+ return index3 === void 0 ? void 0 : { theme: index3 };
11156
11389
  }
11157
11390
  return void 0;
11158
11391
  }
@@ -12003,14 +12236,14 @@ var PersonRegistry = class {
12003
12236
  return `${XML_HEADER}<personList xmlns="${NS.tc}" xmlns:x="${NS.x}">${people}</personList>`;
12004
12237
  }
12005
12238
  };
12006
- function vmlShape(comment, index2, id) {
12239
+ function vmlShape(comment, index3, id) {
12007
12240
  const { row: row2, col } = comment.address;
12008
12241
  const anchor = `${col + 1}, 15, ${Math.max(0, row2 - 1)}, 10, ${col + 3}, 15, ${row2 + 3}, 4`;
12009
- 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>`;
12242
+ 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>`;
12010
12243
  }
12011
12244
  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>';
12012
12245
  function vmlXml(comments, layout3) {
12013
- const shapes = comments.map((comment, index2) => vmlShape(comment, index2, layout3.ids[index2] ?? 0)).join("");
12246
+ const shapes = comments.map((comment, index3) => vmlShape(comment, index3, layout3.ids[index3] ?? 0)).join("");
12014
12247
  const data = layout3.blocks.join(",");
12015
12248
  const base = layout3.base;
12016
12249
  if (base && /<\/xml>\s*$/.test(base)) {
@@ -12041,8 +12274,8 @@ function commentParts(comments, sheetNumber, persons, sheetName, layout3) {
12041
12274
  const id = guidFrom(`${sheetName}!${ref}:${comment.text}`);
12042
12275
  const personId = persons.id(comment.author);
12043
12276
  threaded += `<threadedComment ref="${ref}" personId="${personId}" id="${id}"><text>${escapeText2(comment.text)}</text></threadedComment>`;
12044
- comment.replies.forEach((reply, index2) => {
12045
- const replyId = guidFrom(`${id}:reply:${index2}:${reply.text}`);
12277
+ comment.replies.forEach((reply, index3) => {
12278
+ const replyId = guidFrom(`${id}:reply:${index3}:${reply.text}`);
12046
12279
  const dT = reply.date ? ` dT="${escapeAttr3(reply.date)}"` : "";
12047
12280
  threaded += `<threadedComment ref="${ref}"${dT} personId="${persons.id(reply.author)}" id="${replyId}" parentId="${id}"><text>${escapeText2(reply.text)}</text></threadedComment>`;
12048
12281
  });
@@ -12059,7 +12292,7 @@ Reply:
12059
12292
  sorted2,
12060
12293
  layout3 ?? {
12061
12294
  blocks: [sheetNumber],
12062
- ids: sorted2.map((_, index2) => 1024 * sheetNumber + index2 + 1)
12295
+ ids: sorted2.map((_, index3) => 1024 * sheetNumber + index3 + 1)
12063
12296
  }
12064
12297
  );
12065
12298
  const parts = { comments: commentsXml, vml };
@@ -12762,11 +12995,11 @@ var GRAY_VARIATIONS = [
12762
12995
  { tint: 8e4 }
12763
12996
  ];
12764
12997
  var ACCENTS = ["accent1", "accent2", "accent3", "accent4", "accent5", "accent6"];
12765
- function colorful(id, index2, base) {
12766
- return { id, group: "colorful", index: index2, meth: "cycle", base, variations: COLORFUL_VARIATIONS };
12998
+ function colorful(id, index3, base) {
12999
+ return { id, group: "colorful", index: index3, meth: "cycle", base, variations: COLORFUL_VARIATIONS };
12767
13000
  }
12768
- function mono(id, index2, accent, meth) {
12769
- return { id, group: "monochromatic", index: index2, meth, base: [accent], variations: [] };
13001
+ function mono(id, index3, accent, meth) {
13002
+ return { id, group: "monochromatic", index: index3, meth, base: [accent], variations: [] };
12770
13003
  }
12771
13004
  var CHART_COLOR_PALETTES = [
12772
13005
  colorful(10, 1, ACCENTS),
@@ -12810,9 +13043,9 @@ function chartPaletteSeriesColorChoice(palette, i2, n) {
12810
13043
  const round2 = Math.floor(i2 / palette.base.length);
12811
13044
  transform6 = (palette.variations.length ? palette.variations[round2 % palette.variations.length] : {}) ?? {};
12812
13045
  } else {
12813
- const index2 = palette.meth === "withinLinearReversed" ? n - 1 - i2 : i2;
13046
+ const index3 = palette.meth === "withinLinearReversed" ? n - 1 - i2 : i2;
12814
13047
  base = palette.base[0];
12815
- transform6 = withinLinearTransform(index2, n);
13048
+ transform6 = withinLinearTransform(index3, n);
12816
13049
  }
12817
13050
  if (!base) throw new RangeError("A chart palette must have a base color");
12818
13051
  return {
@@ -12993,18 +13226,18 @@ var PackageWriter = class {
12993
13226
  var rank = (name) => name === "_rels/.rels" ? 0 : name.startsWith("docProps/") ? 1 : name === "xl/workbook.xml" ? 2 : 3;
12994
13227
 
12995
13228
  // xlsx/write/chart-colors.ts
12996
- function chartSeriesFill(chart, series, index2) {
13229
+ function chartSeriesFill(chart, series, index3) {
12997
13230
  const imported = series.fill && drawingFillXml(series.fill);
12998
13231
  if (imported) return imported;
12999
- return `<a:solidFill>${drawingColorXml(chartSeriesColor(chart, series, index2))}</a:solidFill>`;
13232
+ return `<a:solidFill>${drawingColorXml(chartSeriesColor(chart, series, index3))}</a:solidFill>`;
13000
13233
  }
13001
- function chartSeriesDrawingFill(chart, series, index2) {
13234
+ function chartSeriesDrawingFill(chart, series, index3) {
13002
13235
  if (series.fill && drawingFillXml(series.fill)) return series.fill;
13003
- return { kind: "solid", color: chartSeriesColor(chart, series, index2) };
13236
+ return { kind: "solid", color: chartSeriesColor(chart, series, index3) };
13004
13237
  }
13005
- function chartSeriesColor(chart, series, index2) {
13238
+ function chartSeriesColor(chart, series, index3) {
13006
13239
  const palette = findChartColorPalette(chart.colorPalette ?? 10);
13007
- return series.drawingColor ?? chartDrawingColor(series.color) ?? chartPaletteSeriesColorChoice(palette ?? findChartColorPalette(10), index2, chart.series.length);
13240
+ return series.drawingColor ?? chartDrawingColor(series.color) ?? chartPaletteSeriesColorChoice(palette ?? findChartColorPalette(10), index3, chart.series.length);
13008
13241
  }
13009
13242
  function recolorMarker(marker3, previous, next) {
13010
13243
  for (const paint of [marker3, first(marker3, "ln", NS.a)]) {
@@ -13022,10 +13255,10 @@ function patchChartColors(doc, chartNode, model, before) {
13022
13255
  const palette = findChartColorPalette(model.colorPalette ?? 10);
13023
13256
  const lineLike = ["line", "scatter", "radar"].includes(model.chartType);
13024
13257
  const markerOnly = model.chartType === "scatter" && first(plot2, "scatterStyle", NS.c)?.getAttribute("val") === "marker";
13025
- children(plot2, "ser", NS.c).forEach((ser, index2) => {
13026
- const series = model.series[index2];
13258
+ children(plot2, "ser", NS.c).forEach((ser, index3) => {
13259
+ const series = model.series[index3];
13027
13260
  if (!series) return;
13028
- const old = before.series[index2];
13261
+ const old = before.series[index3];
13029
13262
  if (old?.effectsXml !== series.effectsXml) {
13030
13263
  let shape2 = first(ser, "spPr", NS.c);
13031
13264
  if (!shape2 && series.effectsXml) {
@@ -13071,12 +13304,12 @@ function patchChartColors(doc, chartNode, model, before) {
13071
13304
  paint = doc.createElementNS(NS.a, "a:ln");
13072
13305
  spPr.appendChild(paint);
13073
13306
  }
13074
- setDrawingFillXml(paint, chartSeriesFill(model, series, index2));
13307
+ setDrawingFillXml(paint, chartSeriesFill(model, series, index3));
13075
13308
  }
13076
13309
  if (previousPalette && palette && before.colorPalette !== model.colorPalette) {
13077
13310
  const marker3 = first(first(ser, "marker", NS.c), "spPr", NS.c);
13078
- const previous = chartPaletteSeriesColorChoice(previousPalette, index2, model.series.length);
13079
- const next = chartPaletteSeriesColorChoice(palette, index2, model.series.length);
13311
+ const previous = chartPaletteSeriesColorChoice(previousPalette, index3, model.series.length);
13312
+ const next = chartPaletteSeriesColorChoice(palette, index3, model.series.length);
13080
13313
  recolorMarker(marker3, previous, next);
13081
13314
  for (const point of children(ser, "dPt", NS.c))
13082
13315
  recolorMarker(first(first(point, "marker", NS.c), "spPr", NS.c), previous, next);
@@ -13171,7 +13404,7 @@ var FIRST_AXIS = 500000001;
13171
13404
  var SECOND_AXIS = 500000002;
13172
13405
  function source(kind, formula, values2) {
13173
13406
  const points = values2.flatMap(
13174
- (value2, index2) => value2 === null || value2 === "" ? [] : [{ index: index2, value: String(value2) }]
13407
+ (value2, index3) => value2 === null || value2 === "" ? [] : [{ index: index3, value: String(value2) }]
13175
13408
  );
13176
13409
  return {
13177
13410
  kind: formula ? kind === "str" ? "strRef" : "numRef" : kind === "str" ? "strLit" : "numLit",
@@ -13204,9 +13437,9 @@ function dataPoints(series) {
13204
13437
  return /^\d+$/.test(key) && paint ? [{ index: Number(key), spPr: { fill: paint } }] : [];
13205
13438
  });
13206
13439
  }
13207
- function seriesModel(chart, series, index2) {
13440
+ function seriesModel(chart, series, index3) {
13208
13441
  const type = chart.chartType;
13209
- const out = { index: index2, order: index2, dataPoints: dataPoints(series) };
13442
+ const out = { index: index3, order: index3, dataPoints: dataPoints(series) };
13210
13443
  if (series.nameRef)
13211
13444
  out.tx = {
13212
13445
  reference: source("str", series.nameRef, series.name === void 0 ? [] : [series.name])
@@ -13215,7 +13448,7 @@ function seriesModel(chart, series, index2) {
13215
13448
  const lineLike = type === "line" || type === "scatter" || type === "radar";
13216
13449
  const effectsXml = effects(series);
13217
13450
  if (type !== "pie" && type !== "doughnut" || series.fill || series.color || series.drawingColor || effectsXml) {
13218
- const fill = chartSeriesDrawingFill(chart, series, index2);
13451
+ const fill = chartSeriesDrawingFill(chart, series, index3);
13219
13452
  const shape2 = lineLike ? { line: { widthEmu: 28575, cap: "rnd", fill } } : { fill };
13220
13453
  if (effectsXml) shape2.effectsXml = effectsXml;
13221
13454
  out.spPr = shape2;
@@ -13339,7 +13572,7 @@ function style(chart) {
13339
13572
  return id > 100 ? { c14Style: id, style: id - 100 } : { style: id };
13340
13573
  }
13341
13574
  function chartSpaceFromObject(chart) {
13342
- const series = chart.series.map((entry3, index2) => seriesModel(chart, entry3, index2));
13575
+ const series = chart.series.map((entry3, index3) => seriesModel(chart, entry3, index3));
13343
13576
  const [group, chartAxes] = plot(chart, series);
13344
13577
  const space = {
13345
13578
  roundedCorners: false,
@@ -13380,8 +13613,8 @@ function patchChartReferences(xml, chart) {
13380
13613
  changed = true;
13381
13614
  }
13382
13615
  };
13383
- children(plot2, "ser", NS.c).forEach((ser, index2) => {
13384
- const model = chart.series[index2];
13616
+ children(plot2, "ser", NS.c).forEach((ser, index3) => {
13617
+ const model = chart.series[index3];
13385
13618
  if (!model) return;
13386
13619
  setRef(first(ser, "tx", NS.c), model.nameRef);
13387
13620
  setRef(first(ser, "cat", NS.c) ?? first(ser, "xVal", NS.c), model.categoriesRef);
@@ -13749,10 +13982,10 @@ var MONTHS2 = [
13749
13982
  function monthFromName2(name) {
13750
13983
  const lower2 = name.toLowerCase();
13751
13984
  if (lower2.length < 3) return void 0;
13752
- const index2 = MONTHS2.findIndex((m) => lower2.startsWith(m));
13753
- if (index2 < 0) return void 0;
13754
- const full = new Date(Date.UTC(2e3, index2, 1)).toLocaleString("en-US", { month: "long", timeZone: "UTC" }).toLowerCase();
13755
- return lower2.length === 3 || full.startsWith(lower2) || lower2 === "sept" ? index2 + 1 : void 0;
13985
+ const index3 = MONTHS2.findIndex((m) => lower2.startsWith(m));
13986
+ if (index3 < 0) return void 0;
13987
+ const full = new Date(Date.UTC(2e3, index3, 1)).toLocaleString("en-US", { month: "long", timeZone: "UTC" }).toLowerCase();
13988
+ return lower2.length === 3 || full.startsWith(lower2) || lower2 === "sept" ? index3 + 1 : void 0;
13756
13989
  }
13757
13990
  var NUMBER_RE3 = /^(\d+(?:,\d{3,})+|\d*)(\.\d*)?(?:e([+-]?\d+))?$/i;
13758
13991
  var TIME_RE2 = /^(\d{1,4})(?::(\d+))?(?::(\d+(?:\.\d*)?))?(?:\s+(am|pm|a|p))?$/i;
@@ -14520,11 +14753,11 @@ function sort(args, ctx) {
14520
14753
  if (byCol) m = transpose(m);
14521
14754
  const indexes2 = args.length > 1 && args[1] !== null ? ctx.toMatrix(args[1] ?? null).flat().map((v) => Math.trunc(num2(v))) : [1];
14522
14755
  const orders = args.length > 2 && args[2] !== null ? ctx.toMatrix(args[2] ?? null).flat().map((v) => num2(v)) : [1];
14523
- const keys = indexes2.map((index2, k) => {
14524
- if (index2 < 1 || index2 > m.cols) fail(ERR.VALUE);
14756
+ const keys = indexes2.map((index3, k) => {
14757
+ if (index3 < 1 || index3 > m.cols) fail(ERR.VALUE);
14525
14758
  const order = orders[Math.min(k, orders.length - 1)] ?? 1;
14526
14759
  if (order !== 1 && order !== -1) fail(ERR.VALUE);
14527
- return { values: m.data.map((row2) => row2[index2 - 1] ?? null), descending: order === -1 };
14760
+ return { values: m.data.map((row2) => row2[index3 - 1] ?? null), descending: order === -1 };
14528
14761
  });
14529
14762
  const sorted2 = new Matrix(sortRows(m.data, keys));
14530
14763
  return byCol ? transpose(sorted2) : sorted2;
@@ -14652,14 +14885,14 @@ var ARRAY_FUNCTIONS = [
14652
14885
  const cols = optInt(ctx, args, 1, 1);
14653
14886
  const min = args.length > 2 && args[2] !== null ? num2(ctx.toScalar(args[2] ?? null)) : 0;
14654
14887
  const max = args.length > 3 && args[3] !== null ? num2(ctx.toScalar(args[3] ?? null)) : 1;
14655
- const integer = args.length > 4 && args[4] !== null && toBool(ctx.toScalar(args[4] ?? null));
14888
+ const integer2 = args.length > 4 && args[4] !== null && toBool(ctx.toScalar(args[4] ?? null));
14656
14889
  if (rows < 1 || cols < 1) return ERR.CALC;
14657
14890
  if (min > max) fail(ERR.VALUE);
14658
14891
  const random = () => ctx.frame.host.random();
14659
14892
  return Matrix.build(
14660
14893
  rows,
14661
14894
  cols,
14662
- () => integer ? Math.ceil(min) + Math.floor(random() * (Math.floor(max) - Math.ceil(min) + 1)) : min + random() * (max - min)
14895
+ () => integer2 ? Math.ceil(min) + Math.floor(random() * (Math.floor(max) - Math.ceil(min) + 1)) : min + random() * (max - min)
14663
14896
  );
14664
14897
  },
14665
14898
  ["any"],
@@ -14714,8 +14947,8 @@ function modes(values2) {
14714
14947
  function kth(values2, k, largest) {
14715
14948
  const n = values2.length;
14716
14949
  if (n === 0 || !(k >= 1) || k > n) fail(ERR.NUM);
14717
- const index2 = Math.floor(largest ? n + 1 - k : k) - 1;
14718
- return sorted(values2)[index2];
14950
+ const index3 = Math.floor(largest ? n + 1 - k : k) - 1;
14951
+ return sorted(values2)[index3];
14719
14952
  }
14720
14953
  function extreme(values2, max) {
14721
14954
  if (values2.length === 0) return 0;
@@ -14855,13 +15088,13 @@ function fieldIndex(table2, field) {
14855
15088
  const value2 = scalar(field);
14856
15089
  if (isError(value2)) fail(value2);
14857
15090
  if (typeof value2 === "number") {
14858
- const index3 = Math.trunc(value2) - 1;
14859
- if (index3 < 0 || index3 >= table2.headers.length) fail(ERR.VALUE);
14860
- return index3;
15091
+ const index4 = Math.trunc(value2) - 1;
15092
+ if (index4 < 0 || index4 >= table2.headers.length) fail(ERR.VALUE);
15093
+ return index4;
14861
15094
  }
14862
- const index2 = table2.headers.indexOf(label2(value2).toLowerCase());
14863
- if (index2 < 0) fail(ERR.VALUE);
14864
- return index2;
15095
+ const index3 = table2.headers.indexOf(label2(value2).toLowerCase());
15096
+ if (index3 < 0) fail(ERR.VALUE);
15097
+ return index3;
14865
15098
  }
14866
15099
  function recordFilter(table2, criteria) {
14867
15100
  const [head, ...rows] = criteria;
@@ -16147,8 +16380,8 @@ function cumulative(args, principal) {
16147
16380
 
16148
16381
  // xlsx/formula/functions/bonds.ts
16149
16382
  var C9 = "Financial";
16150
- var basisOf = (args, index2) => {
16151
- const basis = args.length > index2 && args[index2] !== null ? int3(args[index2]) : 0;
16383
+ var basisOf = (args, index3) => {
16384
+ const basis = args.length > index3 && args[index3] !== null ? int3(args[index3]) : 0;
16152
16385
  if (basis < 0 || basis > 4) fail(ERR.NUM);
16153
16386
  return basis;
16154
16387
  };
@@ -16330,9 +16563,9 @@ var AMORLINC = {
16330
16563
  }
16331
16564
  const fraction = purchase === firstPeriod ? 1 : basis === 1 ? (firstPeriod - purchase) / (isLeapYear(serialToYmd(purchase, ctx.date1904).year) ? 366 : 365) : yearFrac(purchase, firstPeriod, basis, ctx);
16332
16565
  const first2 = Math.min(cost - salvage, annual * fraction);
16333
- const index2 = Math.trunc(period);
16334
- if (index2 === 0) return first2;
16335
- return Math.max(0, Math.min(annual, cost - salvage - first2 - (index2 - 1) * annual));
16566
+ const index3 = Math.trunc(period);
16567
+ if (index3 === 0) return first2;
16568
+ return Math.max(0, Math.min(annual, cost - salvage - first2 - (index3 - 1) * annual));
16336
16569
  }
16337
16570
  ),
16338
16571
  missingRequiredError: "#N/A"
@@ -16559,8 +16792,8 @@ var DEPRECIATION_FUNCTIONS = [
16559
16792
 
16560
16793
  // xlsx/formula/functions/securities.ts
16561
16794
  var C11 = "Financial";
16562
- var basisOf2 = (args, index2) => {
16563
- const basis = args.length > index2 && args[index2] !== null ? int3(args[index2]) : 0;
16795
+ var basisOf2 = (args, index3) => {
16796
+ const basis = args.length > index3 && args[index3] !== null ? int3(args[index3]) : 0;
16564
16797
  if (basis < 0 || basis > 4) fail(ERR.NUM);
16565
16798
  return basis;
16566
16799
  };
@@ -16983,8 +17216,8 @@ var INFO_FUNCTIONS = [
16983
17216
  const v = args[0];
16984
17217
  if (v === void 0) return ctx.sheet + 1;
16985
17218
  if (v instanceof RefValue) return (v.areas[0]?.sheet ?? ctx.sheet) + 1;
16986
- const index2 = sheetIndex(ctx.frame.host, str(v));
16987
- return index2 < 0 ? ERR.NA : index2 + 1;
17219
+ const index3 = sheetIndex(ctx.frame.host, str(v));
17220
+ return index3 < 0 ? ERR.NA : index3 + 1;
16988
17221
  },
16989
17222
  ["any"]
16990
17223
  ),
@@ -17453,14 +17686,14 @@ function shape(value2) {
17453
17686
  if (value2 instanceof Matrix) return { rows: value2.rows, cols: value2.cols };
17454
17687
  return { rows: 1, cols: 1 };
17455
17688
  }
17456
- function line(ctx, value2, axis, index2) {
17689
+ function line(ctx, value2, axis, index3) {
17457
17690
  if (value2 instanceof RefValue) {
17458
17691
  const area = value2.areas[0];
17459
17692
  if (!area || value2.areas.length !== 1) fail(ERR.VALUE);
17460
17693
  const { start, end } = area.range;
17461
17694
  const bounds = ctx.frame.host.bounds(area.sheet);
17462
17695
  if (axis === "col") {
17463
- const col = start.col + index2;
17696
+ const col = start.col + index3;
17464
17697
  const length2 = Math.max(0, Math.min(end.row, bounds.rows - 1) - start.row + 1);
17465
17698
  return {
17466
17699
  length: length2,
@@ -17468,7 +17701,7 @@ function line(ctx, value2, axis, index2) {
17468
17701
  get: (i2) => ctx.readCell(area.sheet, start.row + i2, col)
17469
17702
  };
17470
17703
  }
17471
- const row2 = start.row + index2;
17704
+ const row2 = start.row + index3;
17472
17705
  const length = Math.max(0, Math.min(end.col, bounds.cols - 1) - start.col + 1);
17473
17706
  return {
17474
17707
  length,
@@ -17477,8 +17710,8 @@ function line(ctx, value2, axis, index2) {
17477
17710
  };
17478
17711
  }
17479
17712
  const m = value2 instanceof Matrix ? value2 : new Matrix([[value2]]);
17480
- if (axis === "col") return { length: m.rows, get: (i2) => m.get(i2, index2) };
17481
- return { length: m.cols, get: (i2) => m.get(index2, i2) };
17713
+ if (axis === "col") return { length: m.rows, get: (i2) => m.get(i2, index3) };
17714
+ return { length: m.cols, get: (i2) => m.get(index3, i2) };
17482
17715
  }
17483
17716
  function vectorOf(ctx, value2) {
17484
17717
  const { rows, cols } = shape(value2);
@@ -17916,24 +18149,24 @@ function cellOf(value2, row2, col) {
17916
18149
  if (value2 instanceof Matrix) return value2.get(row2, col);
17917
18150
  return value2;
17918
18151
  }
17919
- function sliceOf(value2, axis, index2) {
18152
+ function sliceOf(value2, axis, index3) {
17920
18153
  const { rows } = shape(value2);
17921
18154
  if (value2 instanceof RefValue) {
17922
18155
  const area = value2.areas[0];
17923
18156
  if (!area) fail(ERR.REF);
17924
18157
  const { start, end } = area.range;
17925
18158
  const range = axis === "row" ? {
17926
- start: { row: start.row + index2, col: start.col },
17927
- end: { row: start.row + index2, col: end.col }
18159
+ start: { row: start.row + index3, col: start.col },
18160
+ end: { row: start.row + index3, col: end.col }
17928
18161
  } : {
17929
- start: { row: start.row, col: start.col + index2 },
17930
- end: { row: end.row, col: start.col + index2 }
18162
+ start: { row: start.row, col: start.col + index3 },
18163
+ end: { row: end.row, col: start.col + index3 }
17931
18164
  };
17932
18165
  return new RefValue([{ sheet: area.sheet, range }]);
17933
18166
  }
17934
18167
  const m = value2 instanceof Matrix ? value2 : new Matrix([[value2]]);
17935
- if (axis === "row") return new Matrix([m.data[index2] ?? []]);
17936
- return new Matrix(Array.from({ length: rows }, (_, r) => [m.get(r, index2)]));
18168
+ if (axis === "row") return new Matrix([m.data[index3] ?? []]);
18169
+ return new Matrix(Array.from({ length: rows }, (_, r) => [m.get(r, index3)]));
17937
18170
  }
17938
18171
  function lookupValue(args) {
17939
18172
  const v = scalar(args[0]);
@@ -17949,15 +18182,15 @@ function lookupArray(value2) {
17949
18182
  function vhlookup(args, ctx, vertical) {
17950
18183
  const lookup2 = blankAsZero(args);
17951
18184
  const table2 = lookupArray(args[1] ?? null);
17952
- const index2 = int3(args[2]);
18185
+ const index3 = int3(args[2]);
17953
18186
  const approximate2 = args.length < 4 ? true : bool(args[3]);
17954
18187
  const { rows, cols } = shape(table2);
17955
- if (index2 < 1) fail(ERR.VALUE);
17956
- if (index2 > (vertical ? cols : rows)) fail(ERR.REF);
18188
+ if (index3 < 1) fail(ERR.VALUE);
18189
+ if (index3 > (vertical ? cols : rows)) fail(ERR.REF);
17957
18190
  const keys = line(ctx, table2, vertical ? "col" : "row", 0);
17958
18191
  const at = approximate2 ? findAscending(keys, lookup2) : findExact(keys, lookup2, true);
17959
18192
  if (at < 0) fail(ERR.NA);
17960
- return vertical ? cellOf(table2, at, index2 - 1) : cellOf(table2, index2 - 1, at);
18193
+ return vertical ? cellOf(table2, at, index3 - 1) : cellOf(table2, index3 - 1, at);
17961
18194
  }
17962
18195
  function match(args, ctx) {
17963
18196
  const lookup2 = blankAsZero(args);
@@ -17984,13 +18217,13 @@ function lookup(args, ctx) {
17984
18217
  if (at < 0) fail(ERR.NA);
17985
18218
  return vertical ? cellOf(source2, at, cols - 1) : cellOf(source2, rows - 1, at);
17986
18219
  }
17987
- function index(args) {
18220
+ function index2(args) {
17988
18221
  const source2 = args[0] ?? null;
17989
18222
  if (source2 instanceof RefValue && source2.areas.length > 1) {
17990
18223
  const area = Math.trunc(optNum(args, 3, 1));
17991
18224
  const chosen = source2.areas[area - 1];
17992
18225
  if (!chosen) fail(ERR.REF);
17993
- return index([new RefValue([chosen]), ...args.slice(1, 3)]);
18226
+ return index2([new RefValue([chosen]), ...args.slice(1, 3)]);
17994
18227
  }
17995
18228
  const { rows, cols } = shape(source2);
17996
18229
  let r = args.length > 1 && args[1] !== null ? int3(args[1]) : 0;
@@ -18112,7 +18345,7 @@ var LOOKUP_FUNCTIONS = [
18112
18345
  "The value or reference at a position.",
18113
18346
  1,
18114
18347
  4,
18115
- (args) => index(args),
18348
+ (args) => index2(args),
18116
18349
  ["any", "value", "value", "value"]
18117
18350
  ),
18118
18351
  spec(
@@ -18156,27 +18389,27 @@ function valueKeys(value2, out) {
18156
18389
  }
18157
18390
  }
18158
18391
  function positionsOf(block, key) {
18159
- let index2 = indexes.get(block);
18160
- if (!index2) {
18392
+ let index3 = indexes.get(block);
18393
+ if (!index3) {
18161
18394
  const count2 = (uses.get(block) ?? 0) + 1;
18162
18395
  uses.set(block, count2);
18163
18396
  if (count2 < 2 || block.isPadded) return void 0;
18164
- index2 = /* @__PURE__ */ new Map();
18397
+ index3 = /* @__PURE__ */ new Map();
18165
18398
  const keys = [];
18166
18399
  const cols = block.cols;
18167
18400
  for (let r = 0; r < block.rows; r++) {
18168
18401
  for (let c2 = 0; c2 < cols; c2++) {
18169
18402
  valueKeys(block.get(r, c2), keys);
18170
18403
  for (const k of keys) {
18171
- const list = index2.get(k);
18404
+ const list = index3.get(k);
18172
18405
  if (list) list.push(r * cols + c2);
18173
- else index2.set(k, [r * cols + c2]);
18406
+ else index3.set(k, [r * cols + c2]);
18174
18407
  }
18175
18408
  }
18176
18409
  }
18177
- indexes.set(block, index2);
18410
+ indexes.set(block, index3);
18178
18411
  }
18179
- return index2.get(key) ?? [];
18412
+ return index3.get(key) ?? [];
18180
18413
  }
18181
18414
 
18182
18415
  // xlsx/formula/functions/criteria.ts
@@ -19336,7 +19569,7 @@ function layout(ctx, args) {
19336
19569
  }
19337
19570
  return { y, x, column };
19338
19571
  }
19339
- var withConst = (args, index2) => omitted(args, index2) ? true : bool(args[index2]);
19572
+ var withConst = (args, index3) => omitted(args, index3) ? true : bool(args[index3]);
19340
19573
  var row = (values2, width) => [
19341
19574
  ...values2,
19342
19575
  ...new Array(Math.max(0, width - values2.length)).fill(ERR.NA)
@@ -21650,7 +21883,7 @@ function compile(pattern, caseMode2, global) {
21650
21883
  return fail(ERR.VALUE);
21651
21884
  }
21652
21885
  }
21653
- var caseMode = (args, index2) => optNum(args, index2, 0);
21886
+ var caseMode = (args, index3) => optNum(args, index3, 0);
21654
21887
  function encodeUrl(text) {
21655
21888
  return encodeURIComponent(text).replace(
21656
21889
  /[!'()*]/g,
@@ -21769,9 +22002,9 @@ function textAround(args, ctx, before) {
21769
22002
  if (instance > 0) found.push({ at: text.length, length: 0 });
21770
22003
  else found.unshift({ at: 0, length: 0 });
21771
22004
  }
21772
- const index2 = instance > 0 ? instance - 1 : found.length + instance;
21773
- const hit = found[index2];
21774
- if (!hit || index2 < 0) return notFound;
22005
+ const index3 = instance > 0 ? instance - 1 : found.length + instance;
22006
+ const hit = found[index3];
22007
+ if (!hit || index3 < 0) return notFound;
21775
22008
  return before ? text.slice(0, hit.at) : text.slice(hit.at + hit.length);
21776
22009
  }
21777
22010
  function splitText(text, delimiters, insensitive, ignoreEmpty) {
@@ -21887,10 +22120,10 @@ Object.freeze(
21887
22120
  );
21888
22121
 
21889
22122
  // xlsx/formula/functions/types.ts
21890
- var paramKind = (spec2, index2) => {
22123
+ var paramKind = (spec2, index3) => {
21891
22124
  const params = spec2.params;
21892
22125
  if (!params || params.length === 0) return "value";
21893
- return params[Math.min(index2, params.length - 1)] ?? "value";
22126
+ return params[Math.min(index3, params.length - 1)] ?? "value";
21894
22127
  };
21895
22128
 
21896
22129
  // xlsx/formula/spill.ts
@@ -22470,9 +22703,9 @@ function readSourceStyles(xml) {
22470
22703
  (node) => inlineFragment(outerXml(node))
22471
22704
  );
22472
22705
  const dxfKeys = /* @__PURE__ */ new Map();
22473
- parseStyles(xml, []).dxfs.forEach((dxf, index2) => {
22706
+ parseStyles(xml, []).dxfs.forEach((dxf, index3) => {
22474
22707
  const key = styleKey(dxf);
22475
- if (!dxfKeys.has(key)) dxfKeys.set(key, index2);
22708
+ if (!dxfKeys.has(key)) dxfKeys.set(key, index3);
22476
22709
  });
22477
22710
  const result2 = { numFmts, dxfXml, dxfKeys };
22478
22711
  const tableStyles = xFirst(root, "tableStyles");
@@ -22580,7 +22813,7 @@ var StyleWriter = class {
22580
22813
  });
22581
22814
  const seen = /* @__PURE__ */ new Set();
22582
22815
  const unique2 = named2.filter((entry3) => !seen.has(entry3.name) && seen.add(entry3.name));
22583
- const xfIdOf = new Map(unique2.map((entry3, index2) => [entry3.name, index2]));
22816
+ const xfIdOf = new Map(unique2.map((entry3, index3) => [entry3.name, index3]));
22584
22817
  const base = this.workbook.styles[0] ?? defaultCellStyle();
22585
22818
  this.fonts.id(fontXml(base.font));
22586
22819
  this.borders.id(borderXml({}));
@@ -22589,7 +22822,7 @@ var StyleWriter = class {
22589
22822
  (style2) => this.xf(style2, xfIdOf.get(style2.cellStyleName ?? "Normal") ?? 0)
22590
22823
  );
22591
22824
  const cellStyles = unique2.map(
22592
- (entry3, index2) => el("cellStyle", { name: entry3.name, xfId: index2, builtinId: entry3.builtinId })
22825
+ (entry3, index3) => el("cellStyle", { name: entry3.name, xfId: index3, builtinId: entry3.builtinId })
22593
22826
  );
22594
22827
  const custom = [...this.numFmts].filter(([code]) => builtinFormatIdOf(code) === void 0).sort((a2, b) => a2[1] - b[1]);
22595
22828
  let out = `${XML_HEADER}<styleSheet xmlns="${NS.x}" xmlns:mc="${NS.mc}" mc:Ignorable="x14ac" xmlns:x14ac="${NS.x14ac}">`;
@@ -22754,13 +22987,13 @@ function definedNamesOf(workbook) {
22754
22987
  const names = workbook.definedNames.filter(
22755
22988
  (name) => name.name && (name.localSheet === void 0 || name.localSheet >= 0 && name.localSheet < workbook.sheets.length)
22756
22989
  );
22757
- workbook.sheets.forEach((sheet, index2) => {
22990
+ workbook.sheets.forEach((sheet, index3) => {
22758
22991
  const area = sheet.pageSetup?.printArea;
22759
- if (!area || names.some((n) => n.name === "_xlnm.Print_Area" && n.localSheet === index2)) return;
22992
+ if (!area || names.some((n) => n.name === "_xlnm.Print_Area" && n.localSheet === index3)) return;
22760
22993
  names.push({
22761
22994
  name: "_xlnm.Print_Area",
22762
22995
  formula: `${quoteSheetName(sheet.name)}!${absoluteRange(area)}`,
22763
- localSheet: index2
22996
+ localSheet: index3
22764
22997
  });
22765
22998
  });
22766
22999
  return names;
@@ -23379,9 +23612,9 @@ function sourceColumnsForPatch(root, table2, names) {
23379
23612
  const byName = new Map(source2.map((c2) => [(c2.getAttribute("name") ?? "").toLowerCase(), c2]));
23380
23613
  const tracked = table2.partName !== void 0 || table2.columns.some((c2) => c2.sourceId !== void 0);
23381
23614
  const used = /* @__PURE__ */ new Set();
23382
- return names.map((name, index2) => {
23383
- const id = table2.columns[index2]?.sourceId;
23384
- const match2 = id !== void 0 ? byId.get(id) : tracked ? void 0 : source2.length === names.length ? source2[index2] : byName.get(name.toLowerCase());
23615
+ return names.map((name, index3) => {
23616
+ const id = table2.columns[index3]?.sourceId;
23617
+ const match2 = id !== void 0 ? byId.get(id) : tracked ? void 0 : source2.length === names.length ? source2[index3] : byName.get(name.toLowerCase());
23385
23618
  if (!match2 || used.has(match2)) return void 0;
23386
23619
  used.add(match2);
23387
23620
  return match2;
@@ -23398,12 +23631,12 @@ function patchAutoFilter(doc, root, table2, before, names) {
23398
23631
  filter2.setAttribute("ref", formatRange(range));
23399
23632
  const list = xKid(root, "tableColumns");
23400
23633
  const original = list ? xKids(list, "tableColumn") : [];
23401
- const current = new Map(sourceColumnsForPatch(root, table2, names).map((c2, index2) => [c2, index2]));
23634
+ const current = new Map(sourceColumnsForPatch(root, table2, names).map((c2, index3) => [c2, index3]));
23402
23635
  for (const column of xKids(filter2, "filterColumn")) {
23403
23636
  const old = original[Number(column.getAttribute("colId") ?? "0")];
23404
- const index2 = old ? current.get(old) : void 0;
23405
- if (index2 === void 0) filter2.removeChild(column);
23406
- else column.setAttribute("colId", num(index2));
23637
+ const index3 = old ? current.get(old) : void 0;
23638
+ if (index3 === void 0) filter2.removeChild(column);
23639
+ else column.setAttribute("colId", num(index3));
23407
23640
  }
23408
23641
  if (!existing) insertBefore(root, filter2, ["sortState", "tableColumns"]);
23409
23642
  const sort2 = xKid(filter2, "sortState") ?? xKid(root, "sortState");
@@ -23448,11 +23681,11 @@ function patchColumns(doc, root, sheet, table2, names) {
23448
23681
  for (const column of sourceColumns) list.removeChild(column);
23449
23682
  let nextId = Math.max(0, ...ids) + 1;
23450
23683
  const totalsRow = table2.range.end.row;
23451
- names.forEach((name, index2) => {
23452
- const column = picked[index2] ?? doc.createElementNS(NS.x, "tableColumn");
23684
+ names.forEach((name, index3) => {
23685
+ const column = picked[index3] ?? doc.createElementNS(NS.x, "tableColumn");
23453
23686
  if (!column.getAttribute("id")) column.setAttribute("id", num(nextId++));
23454
23687
  column.setAttribute("name", name);
23455
- const model = table2.columns[index2];
23688
+ const model = table2.columns[index3];
23456
23689
  const fn = table2.totalsRow ? model?.totalsRowFunction : void 0;
23457
23690
  setOrRemove(column, "totalsRowFunction", fn);
23458
23691
  setOrRemove(column, "totalsRowLabel", table2.totalsRow ? model?.totalsRowLabel : void 0);
@@ -23466,7 +23699,7 @@ function patchColumns(doc, root, sheet, table2, names) {
23466
23699
  );
23467
23700
  if (fn !== "custom") setChildText(doc, column, "totalsRowFormula", void 0, []);
23468
23701
  else {
23469
- const cellFormula = sheet.rows.get(totalsRow)?.get(table2.range.start.col + index2)?.formula;
23702
+ const cellFormula = sheet.rows.get(totalsRow)?.get(table2.range.start.col + index3)?.formula;
23470
23703
  if (cellFormula)
23471
23704
  setChildText(
23472
23705
  doc,
@@ -23547,11 +23780,11 @@ function tableXml(table2, id, names) {
23547
23780
  const range = formatRange(table2.range);
23548
23781
  const filterEnd = { ...table2.range.end, row: table2.range.end.row - (table2.totalsRow ? 1 : 0) };
23549
23782
  const filter2 = table2.headerRow && !table2.totalsRow ? `<autoFilter ref="${range}"/>` : table2.headerRow ? `<autoFilter ref="${formatRange({ start: table2.range.start, end: filterEnd })}"/>` : "";
23550
- const columns = names.map((name, index2) => {
23551
- const column = table2.columns[index2];
23783
+ const columns = names.map((name, index3) => {
23784
+ const column = table2.columns[index3];
23552
23785
  const calculated = column?.calculatedColumnFormula ? `<calculatedColumnFormula>${escapeText2(addFuturePrefixes(column.calculatedColumnFormula))}</calculatedColumnFormula>` : "";
23553
23786
  const values2 = attrs({
23554
- id: index2 + 1,
23787
+ id: index3 + 1,
23555
23788
  name,
23556
23789
  totalsRowFunction: table2.totalsRow ? column?.totalsRowFunction : void 0,
23557
23790
  totalsRowLabel: table2.totalsRow ? column?.totalsRowLabel : void 0
@@ -23590,27 +23823,27 @@ function totalsRowFormulas(sheet, table2, names) {
23590
23823
  const out = /* @__PURE__ */ new Map();
23591
23824
  if (!table2.totalsRow) return out;
23592
23825
  const row2 = table2.range.end.row;
23593
- names.forEach((name, index2) => {
23594
- const code = SUBTOTAL_CODES[table2.columns[index2]?.totalsRowFunction ?? ""];
23826
+ names.forEach((name, index3) => {
23827
+ const code = SUBTOTAL_CODES[table2.columns[index3]?.totalsRowFunction ?? ""];
23595
23828
  if (code === void 0) return;
23596
- const col = table2.range.start.col + index2;
23829
+ const col = table2.range.start.col + index3;
23597
23830
  const escaped = name.replace(/['#[\]]/g, "'$&");
23598
23831
  const formula = `SUBTOTAL(${code},${table2.displayName || table2.name}[${escaped}])`;
23599
23832
  if (sheet.rows.get(row2)?.get(col)?.formula !== formula) out.set(`${row2}:${col}`, formula);
23600
23833
  });
23601
23834
  return out;
23602
23835
  }
23603
- function resolveTableNames(table2, before, index2) {
23836
+ function resolveTableNames(table2, before, index3) {
23604
23837
  const display = table2.displayName || table2.name;
23605
- const displayName = before && before.displayName === display ? display : safeTableName(display, index2);
23606
- const name = before && before.name === table2.name ? table2.name : table2.name === display ? displayName : safeTableName(table2.name, index2);
23838
+ const displayName = before && before.displayName === display ? display : safeTableName(display, index3);
23839
+ const name = before && before.name === table2.name ? table2.name : table2.name === display ? displayName : safeTableName(table2.name, index3);
23607
23840
  return { name, displayName };
23608
23841
  }
23609
- function safeTableName(name, index2) {
23842
+ function safeTableName(name, index3) {
23610
23843
  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;
23611
23844
  if (valid) return name;
23612
23845
  const cleaned = name.replace(/[^A-Za-z0-9_.]/g, "_");
23613
- return `Table_${cleaned || index2}`;
23846
+ return `Table_${cleaned || index3}`;
23614
23847
  }
23615
23848
 
23616
23849
  // xlsx/write/sheet-parts.ts
@@ -23623,7 +23856,7 @@ function sourceRelIds(source2, partName) {
23623
23856
  if (legacy) out.legacy = legacy;
23624
23857
  return out;
23625
23858
  }
23626
- function writeComments(ctx, sheet, index2, partName, rels) {
23859
+ function writeComments(ctx, sheet, index3, partName, rels) {
23627
23860
  const { writer, source: source2 } = ctx;
23628
23861
  const name = (pattern) => writer.uniqueName(pattern, ctx.reserved);
23629
23862
  const fromSource = source2 && sheet.partName && source2.has(sheet.partName);
@@ -23668,8 +23901,8 @@ function writeComments(ctx, sheet, index2, partName, rels) {
23668
23901
  }
23669
23902
  }
23670
23903
  const own = base ? vmlIdmapBlocks(base) : [];
23671
- const layout3 = vmlAllocatorFor(ctx, source2).allocate(sheet.comments.length, index2 + 1, own);
23672
- const parts = commentParts(sheet.comments, index2 + 1, ctx.persons, sheet.name, {
23904
+ const layout3 = vmlAllocatorFor(ctx, source2).allocate(sheet.comments.length, index3 + 1, own);
23905
+ const parts = commentParts(sheet.comments, index3 + 1, ctx.persons, sheet.name, {
23673
23906
  ...layout3,
23674
23907
  ...base ? { base } : {}
23675
23908
  });
@@ -23691,11 +23924,11 @@ function sourceVmlPart(source2, sheetPart) {
23691
23924
  }
23692
23925
  function writeTables(ctx, sheet, partName, rels, headerText, formulas) {
23693
23926
  const ids = [];
23694
- for (const [index2, original] of sheet.tables.entries()) {
23927
+ for (const [index3, original] of sheet.tables.entries()) {
23695
23928
  const { writer, source: source2 } = ctx;
23696
23929
  const sourceXml = original.partName ? source2?.text(original.partName) : void 0;
23697
23930
  const before = sourceXml && original.partName ? parseTable(sourceXml, original.partName) : void 0;
23698
- const { name, displayName } = resolveTableNames(original, before, index2 + 1);
23931
+ const { name, displayName } = resolveTableNames(original, before, index3 + 1);
23699
23932
  const table2 = name === original.name && displayName === original.displayName ? original : { ...original, name, displayName };
23700
23933
  const { names, headerText: forced } = resolveTableColumns(sheet, table2);
23701
23934
  for (const [key, text] of forced) headerText.set(key, text);
@@ -23977,7 +24210,7 @@ var REGENERATED = /* @__PURE__ */ new Set([
23977
24210
  ]);
23978
24211
  var NS_XR2 = "http://schemas.microsoft.com/office/spreadsheetml/2015/revision2";
23979
24212
  var NS_XR3 = "http://schemas.microsoft.com/office/spreadsheetml/2016/revision3";
23980
- function writeWorksheet(ctx, sheet, index2, partName) {
24213
+ function writeWorksheet(ctx, sheet, index3, partName) {
23981
24214
  const { writer, source: source2 } = ctx;
23982
24215
  const rels = new RelationshipSet();
23983
24216
  let sourceDrawing;
@@ -24000,7 +24233,7 @@ function writeWorksheet(ctx, sheet, index2, partName) {
24000
24233
  const tableParts = writeTables(ctx, sheet, partName, rels, headerText, formulas);
24001
24234
  blocks.set("sheetPr", sheetPrXml(sheet));
24002
24235
  blocks.set("dimension", dimensionXml(sheet));
24003
- blocks.set("sheetViews", sheetViewsXml(sheet, index2 === ctx.workbook.activeSheet));
24236
+ blocks.set("sheetViews", sheetViewsXml(sheet, index3 === ctx.workbook.activeSheet));
24004
24237
  blocks.set("sheetFormatPr", sheetFormatXml(sheet));
24005
24238
  blocks.set("cols", colsXml(sheet, ctx.workbook.styles.length));
24006
24239
  blocks.set(
@@ -24039,7 +24272,7 @@ function writeWorksheet(ctx, sheet, index2, partName) {
24039
24272
  );
24040
24273
  blocks.set("headerFooter", page.headerFooter);
24041
24274
  blocks.set("drawing", writeSheetDrawing(ctx, sheet, partName, rels, sourceDrawing));
24042
- blocks.set("legacyDrawing", writeComments(ctx, sheet, index2, partName, rels));
24275
+ blocks.set("legacyDrawing", writeComments(ctx, sheet, index3, partName, rels));
24043
24276
  blocks.set("tableParts", tableParts);
24044
24277
  ctx.pivots?.writeSheet(writer, sheet, partName, rels);
24045
24278
  blocks.set("extLst", conditionalExtensionsXml(sheet));
@@ -24064,12 +24297,12 @@ function pivotCacheData(pivot) {
24064
24297
  const items = pivot.fields.map(() => []);
24065
24298
  const indices = pivot.fields.map(() => /* @__PURE__ */ new Map());
24066
24299
  for (const record of pivot.records)
24067
- pivot.fields.forEach((_field, index2) => {
24068
- const value2 = record[index2] ?? null;
24300
+ pivot.fields.forEach((_field, index3) => {
24301
+ const value2 = record[index3] ?? null;
24069
24302
  const key = pivotValueKey(value2);
24070
- if (!indices[index2].has(key)) {
24071
- indices[index2].set(key, items[index2].length);
24072
- items[index2].push(value2);
24303
+ if (!indices[index3].has(key)) {
24304
+ indices[index3].set(key, items[index3].length);
24305
+ items[index3].push(value2);
24073
24306
  }
24074
24307
  });
24075
24308
  return { items, indices };
@@ -24084,8 +24317,8 @@ function valueXml(value2) {
24084
24317
  }
24085
24318
  function pivotCacheDefinitionXml(pivot, workbook, data, recordRel) {
24086
24319
  const source2 = sparklineDataRange(workbook, 0, pivot.source);
24087
- const fields = pivot.fields.map((name, index2) => {
24088
- const items = data.items[index2];
24320
+ const fields = pivot.fields.map((name, index3) => {
24321
+ const items = data.items[index3];
24089
24322
  const types = new Set(
24090
24323
  items.map((value2) => value2 === null || value2 === "" ? "blank" : typeof value2)
24091
24324
  );
@@ -24097,7 +24330,7 @@ function pivotCacheDefinitionXml(pivot, workbook, data, recordRel) {
24097
24330
  }
24098
24331
  function pivotCacheRecordsXml(pivot, data) {
24099
24332
  const records = pivot.records.map(
24100
- (record) => `<r>${pivot.fields.map((_field, index2) => `<x v="${data.indices[index2].get(pivotValueKey(record[index2] ?? null))}"/>`).join("")}</r>`
24333
+ (record) => `<r>${pivot.fields.map((_field, index3) => `<x v="${data.indices[index3].get(pivotValueKey(record[index3] ?? null))}"/>`).join("")}</r>`
24101
24334
  ).join("");
24102
24335
  return `${XML_HEADER}<pivotCacheRecords xmlns="${NS.x}" count="${pivot.records.length}">${records}</pivotCacheRecords>`;
24103
24336
  }
@@ -24107,6 +24340,19 @@ function pivotTableXml(pivot, cacheId, cache2) {
24107
24340
  const grid = pivotGrid(pivot);
24108
24341
  const row2 = pivot.fields.indexOf(pivot.rowField);
24109
24342
  const second = pivot.secondRowField ? pivot.fields.indexOf(pivot.secondRowField) : -1;
24343
+ const page = pivot.pageFilter ? pivot.fields.indexOf(pivot.pageFilter.field) : -1;
24344
+ const pageItems = page >= 0 ? pivotItems(pivot, pivot.pageFilter.field) : [];
24345
+ const axisItems = (field, visible) => page >= 0 ? pivotItems(pivot, field) : visible;
24346
+ const rowItemsFull = axisItems(pivot.rowField, grid.rowItems);
24347
+ const secondRowItemsFull = pivot.secondRowField ? axisItems(pivot.secondRowField, grid.secondRowItems) : [];
24348
+ const columnItemsFull = pivot.columnField ? axisItems(pivot.columnField, grid.columnItems) : [];
24349
+ const itemIndices = (visible, full) => {
24350
+ const indices = new Map(full.map((item, index3) => [pivotValueKey(item), index3]));
24351
+ return visible.map((v) => indices.get(pivotValueKey(v)));
24352
+ };
24353
+ const rowIndicesFull = itemIndices(grid.rowItems, rowItemsFull), secondRowIndicesFull = itemIndices(grid.secondRowItems ?? [], secondRowItemsFull), columnIndicesFull = itemIndices(grid.columnItems, columnItemsFull);
24354
+ const rowEntries = page >= 0 && grid.rowEntries ? remapPivotRowEntries(grid.rowEntries, [rowIndicesFull, secondRowIndicesFull]) : grid.rowEntries;
24355
+ const pageOffset = page >= 0 ? 2 : 0;
24110
24356
  const col = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
24111
24357
  const measures = pivotMeasures(pivot);
24112
24358
  const multiple = measures.length > 1;
@@ -24114,32 +24360,34 @@ function pivotTableXml(pivot, cacheId, cache2) {
24114
24360
  const compact = pivot.layout === "compact";
24115
24361
  const outline = pivot.layout === "compact" || pivot.layout === "outline";
24116
24362
  const top = (pivot.subtotalPosition ?? (outline ? "top" : "bottom")) === "top";
24117
- const fields = pivot.fields.map((_field, index2) => {
24118
- const items2 = index2 === row2 ? grid.rowItems : index2 === second ? grid.secondRowItems : index2 === col ? grid.columnItems : void 0;
24119
- const subtotal = !(index2 === row2 && pivot.subtotals === false);
24120
- 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>' : "";
24121
- return `<pivotField${attrs({ axis: index2 === row2 || index2 === second ? "axisRow" : index2 === col ? "axisCol" : void 0, dataField: measures.some((measure) => pivot.fields.indexOf(measure.field) === index2) ? true : void 0, compact, 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>`;
24363
+ const fields = pivot.fields.map((_field, index3) => {
24364
+ const items2 = index3 === page ? pageItems : index3 === row2 ? rowItemsFull : index3 === second ? secondRowItemsFull : index3 === col ? columnItemsFull : void 0;
24365
+ const subtotal = !(index3 === row2 && pivot.subtotals === false);
24366
+ 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>' : "";
24367
+ 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>`;
24122
24368
  }).join("");
24123
- const items = (count2) => Array.from({ length: count2 }, (_v, i2) => `<i><x v="${i2}"/></i>`).join("") + '<i t="grand"><x/></i>';
24124
- const header = grid.firstHeaderRow ?? (multiple && col >= 0 ? 1 : grid.firstDataRow - 1);
24369
+ const items = (count2, indices) => Array.from({ length: count2 }, (_v, i2) => `<i><x v="${indices?.[i2] ?? i2}"/></i>`).join("") + '<i t="grand"><x/></i>';
24370
+ const header = grid.firstHeaderRow !== void 0 ? grid.firstHeaderRow - pageOffset : multiple && col >= 0 ? 1 : grid.firstDataRow - pageOffset - 1;
24125
24371
  const rowIndices = rowsAxis && pivot.valuesPosition === "first" ? [-2, row2, second] : rowsAxis && pivot.valuesPosition === "between" ? [row2, -2, second] : [row2, ...second >= 0 ? [second] : [], ...rowsAxis ? [-2] : []];
24126
24372
  let previous = [];
24127
- const rowItems = grid.rowEntries?.map((entry3) => {
24373
+ const rowItems = rowEntries?.map((entry3) => {
24128
24374
  let prefix = 0;
24129
24375
  if (entry3.type === "default" && rowsAxis && pivot.valuesPosition === "first") prefix = 1;
24130
24376
  else if (!entry3.type)
24131
24377
  while (prefix < entry3.indices.length - 1 && entry3.indices[prefix] === previous[prefix])
24132
24378
  prefix++;
24133
24379
  previous = entry3.type && !(entry3.type === "default" && pivot.valuesPosition === "first") ? [] : entry3.indices;
24134
- return `<i${attrs({ t: entry3.type, r: prefix || void 0, i: entry3.measure || void 0 })}>${entry3.indices.slice(prefix).map((index2) => `<x${attrs({ v: index2 || void 0 })}/>`).join("")}</i>`;
24135
- }).join("") ?? items(grid.rowItems.length);
24136
- 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>`;
24380
+ 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>`;
24381
+ }).join("") ?? items(grid.rowItems.length, rowIndicesFull);
24382
+ 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>`;
24137
24383
  if (multiple && !rowsAxis)
24138
- 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)}`;
24384
+ 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)}`;
24139
24385
  else if (col >= 0)
24140
- body += `<colFields count="1"><field x="${col}"/></colFields><colItems count="${grid.columnItems.length + 1}">${items(grid.columnItems.length)}</colItems>`;
24386
+ body += `<colFields count="1"><field x="${col}"/></colFields><colItems count="${grid.columnItems.length + 1}">${items(grid.columnItems.length, columnIndicesFull)}</colItems>`;
24141
24387
  else
24142
- body += rowsAxis ? '<colItems count="1"><i/></colItems>' : '<colItems count="1"><i><x/></i></colItems>';
24388
+ body += rowsAxis ? '<colItems count="1"><i/></colItems>' : page >= 0 ? '<colItems count="1"><i/></colItems>' : '<colItems count="1"><i><x/></i></colItems>';
24389
+ if (page >= 0)
24390
+ 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>`;
24143
24391
  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>`;
24144
24392
  const doc = parseXml(
24145
24393
  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>`
@@ -24194,7 +24442,8 @@ function pivotTableXml(pivot, cacheId, cache2) {
24194
24442
  "rowItems",
24195
24443
  "colFields",
24196
24444
  "colItems",
24197
- "dataFields"
24445
+ "dataFields",
24446
+ "pageFields"
24198
24447
  ]);
24199
24448
  for (const child4 of elements(root)) if (replaced.has(child4.localName)) root.removeChild(child4);
24200
24449
  const replacement = parseXml(`<root xmlns="${NS.x}">${body}</root>`).documentElement;
@@ -24379,8 +24628,8 @@ async function saveXlsx(workbook) {
24379
24628
  return void 0;
24380
24629
  });
24381
24630
  const sheetRefs = [];
24382
- workbook.sheets.forEach((sheet, index2) => {
24383
- let partName = partNames[index2];
24631
+ workbook.sheets.forEach((sheet, index3) => {
24632
+ let partName = partNames[index3];
24384
24633
  const sourceType = partName && source2?.has(partName) ? source2.contentType(partName) : void 0;
24385
24634
  const special = sourceType ? SHEET_TYPES[sourceType] : void 0;
24386
24635
  if (!partName) {
@@ -24391,11 +24640,11 @@ async function saveXlsx(workbook) {
24391
24640
  claimed.add(partName);
24392
24641
  }
24393
24642
  if (special) writer.carry(partName);
24394
- else writeWorksheet(ctx, sheet, index2, partName);
24643
+ else writeWorksheet(ctx, sheet, index3, partName);
24395
24644
  sheetRefs.push({
24396
24645
  name: sheet.name,
24397
24646
  sheetId: sheet.sheetId,
24398
- state: states[index2] ?? "visible",
24647
+ state: states[index3] ?? "visible",
24399
24648
  relId: rels.add(special ?? RELATIONSHIP_TYPES.worksheet, relativeTarget(bookPart, partName))
24400
24649
  });
24401
24650
  });
@@ -25017,10 +25266,10 @@ function hasFlatUniqueStreamLayout(entries, workbookCount) {
25017
25266
  return new Set(names).size === names.length;
25018
25267
  }
25019
25268
  function equalBytes(left2, right2) {
25020
- return left2.length === right2.length && left2.every((value2, index2) => value2 === right2[index2]);
25269
+ return left2.length === right2.length && left2.every((value2, index3) => value2 === right2[index3]);
25021
25270
  }
25022
25271
  function isCfb(bytes) {
25023
- return OLE_MAGIC.every((value2, index2) => bytes[index2] === value2);
25272
+ return OLE_MAGIC.every((value2, index3) => bytes[index3] === value2);
25024
25273
  }
25025
25274
 
25026
25275
  // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook-functions.js
@@ -25461,9 +25710,9 @@ function decode2(rgce, extra, context, options) {
25461
25710
  break;
25462
25711
  case 25: {
25463
25712
  const ixti = reader.u16();
25464
- const index2 = reader.u16();
25713
+ const index3 = reader.u16();
25465
25714
  reader.skip(2);
25466
- const name = context.externName(ixti, index2);
25715
+ const name = context.externName(ixti, index3);
25467
25716
  if (name === void 0)
25468
25717
  return void 0;
25469
25718
  push(name);
@@ -25580,9 +25829,9 @@ var XLS_BUILTIN_FORMATS = {
25580
25829
  48: "##0.0E+0",
25581
25830
  49: "@"
25582
25831
  };
25583
- function paletteColor(index2, palette) {
25584
- const rgb = index2 < 64 ? palette[index2] : void 0;
25585
- return rgb ? { index: index2, rgb } : { index: index2, auto: true };
25832
+ function paletteColor(index3, palette) {
25833
+ const rgb = index3 < 64 ? palette[index3] : void 0;
25834
+ return rgb ? { index: index3, rgb } : { index: index3, auto: true };
25586
25835
  }
25587
25836
  var UNDERLINE = {
25588
25837
  1: "single",
@@ -26022,18 +26271,18 @@ function parseGlobals(records) {
26022
26271
  }
26023
26272
  return void 0;
26024
26273
  },
26025
- name(index2) {
26026
- const raw2 = rawNames[index2 - 1];
26274
+ name(index3) {
26275
+ const raw2 = rawNames[index3 - 1];
26027
26276
  return raw2?.name.name;
26028
26277
  },
26029
- externName(ixti, index2) {
26278
+ externName(ixti, index3) {
26030
26279
  const xti = xtis[ixti];
26031
26280
  const book = xti ? supbooks[xti.book] : void 0;
26032
26281
  if (!book)
26033
26282
  return void 0;
26034
26283
  if (book.kind === "self")
26035
- return this.name(index2);
26036
- return book.externNames[index2 - 1];
26284
+ return this.name(index3);
26285
+ return book.externNames[index3 - 1];
26037
26286
  }
26038
26287
  };
26039
26288
  for (const raw2 of rawNames) {
@@ -26364,8 +26613,8 @@ function parseSheet(bound, records, start, globals) {
26364
26613
  sheet.cells.push(result2);
26365
26614
  return result2;
26366
26615
  };
26367
- for (let index2 = start; index2 < records.length; index2++) {
26368
- const record = records[index2];
26616
+ for (let index3 = start; index3 < records.length; index3++) {
26617
+ const record = records[index3];
26369
26618
  const { opcode, data } = record;
26370
26619
  if (opcode === 2057) {
26371
26620
  depth++;
@@ -26573,7 +26822,7 @@ function parseSheet(bound, records, start, globals) {
26573
26822
 
26574
26823
  // ../../node_modules/.bun/@christophervr+ole2@0.13.0/node_modules/@christophervr/ole2/dist/legacy-excel-workbook.js
26575
26824
  function compoundStreamNames(bytes) {
26576
- if (!OLE_MAGIC.every((value2, index2) => bytes[index2] === value2))
26825
+ if (!OLE_MAGIC.every((value2, index3) => bytes[index3] === value2))
26577
26826
  return [];
26578
26827
  try {
26579
26828
  const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
@@ -26585,10 +26834,10 @@ function compoundStreamNames(bytes) {
26585
26834
  function topLevelSubstreams(records) {
26586
26835
  const starts = [];
26587
26836
  let depth = 0;
26588
- records.forEach((record, index2) => {
26837
+ records.forEach((record, index3) => {
26589
26838
  if (record.opcode === 2057) {
26590
- if (depth === 0 && index2 > 0)
26591
- starts.push(index2);
26839
+ if (depth === 0 && index3 > 0)
26840
+ starts.push(index3);
26592
26841
  depth++;
26593
26842
  } else if (record.opcode === 10)
26594
26843
  depth = Math.max(0, depth - 1);
@@ -26613,7 +26862,7 @@ function readXlsWorkbook(bytes) {
26613
26862
  unsupported.push("VBA macros");
26614
26863
  if (streams2.some((name) => name === "_SX_DB_CUR") && !unsupported.includes("pivot caches"))
26615
26864
  unsupported.push("pivot caches");
26616
- const byOffset = new Map(records.map((record, index2) => [record.offset, index2]));
26865
+ const byOffset = new Map(records.map((record, index3) => [record.offset, index3]));
26617
26866
  const substreams = topLevelSubstreams(records);
26618
26867
  const sheets = globals.sheets.map((bound, position) => {
26619
26868
  const start = byOffset.get(bound.offset) ?? substreams[position];
@@ -26737,7 +26986,7 @@ function layout2(bytes) {
26737
26986
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
26738
26987
  if (view.getUint16(0, true) !== 65534 || view.getUint16(2, true) > 1 || view.getUint32(24, true) !== 1)
26739
26988
  return;
26740
- if (!FMTID.every((value2, index2) => bytes[28 + index2] === value2))
26989
+ if (!FMTID.every((value2, index3) => bytes[28 + index3] === value2))
26741
26990
  return;
26742
26991
  const start = view.getUint32(44, true);
26743
26992
  if (start < 48 || start % 4 || start + 8 > bytes.length)
@@ -26895,8 +27144,8 @@ function xfToCellStyle(xls, xf) {
26895
27144
  }
26896
27145
  function defaultXfIndex(xls) {
26897
27146
  if (xls.xfs[15] && !xls.xfs[15].isStyle) return 15;
26898
- const index2 = xls.xfs.findIndex((xf) => !xf.isStyle);
26899
- return index2 >= 0 ? index2 : 0;
27147
+ const index3 = xls.xfs.findIndex((xf) => !xf.isStyle);
27148
+ return index3 >= 0 ? index3 : 0;
26900
27149
  }
26901
27150
 
26902
27151
  // xlsx/load/legacy-xls-sheet.ts
@@ -27090,7 +27339,7 @@ async function loadLegacyXls(input) {
27090
27339
  workbook.sheets = [];
27091
27340
  let undecoded = 0;
27092
27341
  let external = false;
27093
- xls.sheets.forEach((source2, index2) => {
27342
+ xls.sheets.forEach((source2, index3) => {
27094
27343
  if (source2.kind !== "worksheet") {
27095
27344
  const kind = source2.kind === "chart" ? "chart sheet" : `${source2.kind} sheet`;
27096
27345
  warnings.push(
@@ -27099,7 +27348,7 @@ async function loadLegacyXls(input) {
27099
27348
  return;
27100
27349
  }
27101
27350
  const mapped = mapSheet(source2, workbook.sheets.length + 1, resolve2);
27102
- sheetIndex2.set(index2, workbook.sheets.length);
27351
+ sheetIndex2.set(index3, workbook.sheets.length);
27103
27352
  workbook.sheets.push(mapped.sheet);
27104
27353
  undecoded += mapped.undecodedFormulas;
27105
27354
  external ||= mapped.externalReferences;
@@ -27208,7 +27457,7 @@ function decodeSpreadsheetText(bytes) {
27208
27457
  var CFB_MAGIC = [208, 207, 17, 224, 161, 177, 26, 225];
27209
27458
  var ZIP_MAGIC = [80, 75, 3, 4];
27210
27459
  var toBytes3 = (input) => input instanceof Uint8Array ? input : new Uint8Array(input);
27211
- var startsWith = (bytes, magic) => magic.every((value2, index2) => bytes[index2] === value2);
27460
+ var startsWith = (bytes, magic) => magic.every((value2, index3) => bytes[index3] === value2);
27212
27461
  function zipEntryNames(bytes) {
27213
27462
  const names = /* @__PURE__ */ new Set();
27214
27463
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);