ooxml-core 1.8.4 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (347) hide show
  1. package/dist/PptxHandler-5UURGJEV.mjs +2 -0
  2. package/dist/{PptxHandler-BL4B7CZO.mjs → PptxHandler-ADEFY476.mjs} +2 -2
  3. package/dist/PptxHandler-U5XB2HUE.cjs +11 -0
  4. package/dist/automation/index.cjs +7239 -4037
  5. package/dist/automation/index.mjs +7239 -4037
  6. package/dist/chunk-3N6XMMTT.cjs +87913 -0
  7. package/dist/{chunk-TTPZITQN.mjs → chunk-5NVJN4E6.mjs} +30 -2
  8. package/dist/{chunk-ZAP5WLEN.mjs → chunk-A6P7G3UK.mjs} +1 -1
  9. package/dist/{chunk-CPKNMQLX.cjs → chunk-AWIDASUW.cjs} +25 -2
  10. package/dist/{chunk-SVQZXP3F.mjs → chunk-CBNKBVX5.mjs} +25 -2
  11. package/dist/{chunk-GAGSCAR3.mjs → chunk-CCHYFCPD.mjs} +1199 -348
  12. package/dist/chunk-R6KSBNKX.mjs +44133 -0
  13. package/dist/chunk-S6DOCMQC.cjs +44451 -0
  14. package/dist/{chunk-Z7IQR4S4.mjs → chunk-WUE5ZHU3.mjs} +269 -21
  15. package/dist/chunk-ZE53K7DH.mjs +87907 -0
  16. package/dist/{chunk-NIHPA63A.mjs → chunk-ZOUGMAZG.mjs} +54 -37
  17. package/dist/docx/block-parser.d.ts.map +1 -1
  18. package/dist/docx/cell-blocks.d.ts +4 -0
  19. package/dist/docx/cell-blocks.d.ts.map +1 -0
  20. package/dist/docx/document-paragraphs.d.ts.map +1 -1
  21. package/dist/docx/document-parts.d.ts +2 -0
  22. package/dist/docx/document-parts.d.ts.map +1 -1
  23. package/dist/docx/embedded.cjs +189 -20
  24. package/dist/docx/embedded.mjs +189 -20
  25. package/dist/docx/index.cjs +219 -24
  26. package/dist/docx/index.mjs +219 -24
  27. package/dist/docx/layout/adapt-table.d.ts +2 -2
  28. package/dist/docx/layout/adapt-table.d.ts.map +1 -1
  29. package/dist/docx/layout/adapter.d.ts.map +1 -1
  30. package/dist/docx/layout/flow-paragraph.d.ts +5 -0
  31. package/dist/docx/layout/flow-paragraph.d.ts.map +1 -1
  32. package/dist/docx/layout/flow-table.d.ts +2 -1
  33. package/dist/docx/layout/flow-table.d.ts.map +1 -1
  34. package/dist/docx/layout/footnote-columns.d.ts +22 -0
  35. package/dist/docx/layout/footnote-columns.d.ts.map +1 -0
  36. package/dist/docx/layout/footnote-flow.d.ts +27 -0
  37. package/dist/docx/layout/footnote-flow.d.ts.map +1 -0
  38. package/dist/docx/layout/footnote-split.d.ts +7 -0
  39. package/dist/docx/layout/footnote-split.d.ts.map +1 -0
  40. package/dist/docx/layout/index.cjs +1528 -119
  41. package/dist/docx/layout/index.mjs +1528 -120
  42. package/dist/docx/layout/input.d.ts +17 -1
  43. package/dist/docx/layout/input.d.ts.map +1 -1
  44. package/dist/docx/layout/legacy-footnote-flow.d.ts +18 -0
  45. package/dist/docx/layout/legacy-footnote-flow.d.ts.map +1 -0
  46. package/dist/docx/layout/line-metrics.d.ts.map +1 -1
  47. package/dist/docx/layout/nested-frame-profile.d.ts +9 -0
  48. package/dist/docx/layout/nested-frame-profile.d.ts.map +1 -0
  49. package/dist/docx/layout/page-cursor.d.ts +15 -8
  50. package/dist/docx/layout/page-cursor.d.ts.map +1 -1
  51. package/dist/docx/layout/page-flow.d.ts.map +1 -1
  52. package/dist/docx/layout/paragraph-layout.d.ts.map +1 -1
  53. package/dist/docx/layout/paragraph-tokens.d.ts +2 -0
  54. package/dist/docx/layout/paragraph-tokens.d.ts.map +1 -1
  55. package/dist/docx/layout/reference-footnotes.d.ts +7 -0
  56. package/dist/docx/layout/reference-footnotes.d.ts.map +1 -0
  57. package/dist/docx/layout/result.d.ts +44 -0
  58. package/dist/docx/layout/result.d.ts.map +1 -1
  59. package/dist/docx/layout/section-flow.d.ts +2 -0
  60. package/dist/docx/layout/section-flow.d.ts.map +1 -1
  61. package/dist/docx/layout/table-border-layout.d.ts +16 -0
  62. package/dist/docx/layout/table-border-layout.d.ts.map +1 -0
  63. package/dist/docx/layout/table-cell-layout.d.ts +12 -0
  64. package/dist/docx/layout/table-cell-layout.d.ts.map +1 -0
  65. package/dist/docx/layout/table-content.d.ts +4 -0
  66. package/dist/docx/layout/table-content.d.ts.map +1 -0
  67. package/dist/docx/layout/table-footnotes.d.ts +32 -0
  68. package/dist/docx/layout/table-footnotes.d.ts.map +1 -0
  69. package/dist/docx/layout/table-frames.d.ts +4 -0
  70. package/dist/docx/layout/table-frames.d.ts.map +1 -0
  71. package/dist/docx/layout/table-layout.d.ts +16 -5
  72. package/dist/docx/layout/table-layout.d.ts.map +1 -1
  73. package/dist/docx/layout/table-note-completion.d.ts +5 -0
  74. package/dist/docx/layout/table-note-completion.d.ts.map +1 -0
  75. package/dist/docx/layout/table-note-stories.d.ts +6 -0
  76. package/dist/docx/layout/table-note-stories.d.ts.map +1 -0
  77. package/dist/docx/load/index.cjs +194 -25
  78. package/dist/docx/load/index.mjs +194 -25
  79. package/dist/docx/model-run.d.ts +2 -0
  80. package/dist/docx/model-run.d.ts.map +1 -1
  81. package/dist/docx/model.d.ts +7 -0
  82. package/dist/docx/model.d.ts.map +1 -1
  83. package/dist/docx/notes.d.ts +5 -0
  84. package/dist/docx/notes.d.ts.map +1 -1
  85. package/dist/docx/parse-table.d.ts.map +1 -1
  86. package/dist/docx/parse.d.ts.map +1 -1
  87. package/dist/docx/save.d.ts.map +1 -1
  88. package/dist/docx/section-model.d.ts +2 -0
  89. package/dist/docx/section-model.d.ts.map +1 -1
  90. package/dist/docx/sections.d.ts.map +1 -1
  91. package/dist/docx/settings.d.ts +2 -0
  92. package/dist/docx/settings.d.ts.map +1 -1
  93. package/dist/docx/table-model.d.ts +3 -1
  94. package/dist/docx/table-model.d.ts.map +1 -1
  95. package/dist/docx/ui/index.cjs +55 -0
  96. package/dist/docx/ui/index.d.ts +1 -0
  97. package/dist/docx/ui/index.d.ts.map +1 -1
  98. package/dist/docx/ui/index.mjs +55 -1
  99. package/dist/docx/ui/table-structure-guard.d.ts +4 -0
  100. package/dist/docx/ui/table-structure-guard.d.ts.map +1 -0
  101. package/dist/docx/write-footnote-columns.d.ts +3 -0
  102. package/dist/docx/write-footnote-columns.d.ts.map +1 -0
  103. package/dist/docx/write-notes.d.ts.map +1 -1
  104. package/dist/docx/write-run.d.ts.map +1 -1
  105. package/dist/docx/write-sections.d.ts.map +1 -1
  106. package/dist/index.cjs +8 -5
  107. package/dist/index.mjs +8 -5
  108. package/dist/opc/clone-part-graph.d.ts +4 -0
  109. package/dist/opc/clone-part-graph.d.ts.map +1 -1
  110. package/dist/opc/index.cjs +8 -5
  111. package/dist/opc/index.mjs +8 -5
  112. package/dist/pptx/automation/index.cjs +1156 -389
  113. package/dist/pptx/automation/index.d.ts +4 -4
  114. package/dist/pptx/automation/index.mjs +5 -5
  115. package/dist/pptx/chunks/{index-CKIUurnd.d.ts → index-Cuxtr76Y.d.ts} +29 -10
  116. package/dist/pptx/chunks/index-Cuxtr76Y.d.ts.map +1 -0
  117. package/dist/pptx/chunks/{index-Cn-GzYGp.d.ts → index-DUCGeZh7.d.ts} +94 -5
  118. package/dist/pptx/chunks/index-DUCGeZh7.d.ts.map +1 -0
  119. package/dist/pptx/chunks/{smart-art-Q2kZQtHh.d.ts → smart-art-D-sXa_Nb.d.ts} +11 -1
  120. package/dist/pptx/chunks/smart-art-D-sXa_Nb.d.ts.map +1 -0
  121. package/dist/pptx/chunks/{text-operations-BHfAm5K9.d.ts → text-operations-BqHmLaLA.d.ts} +54 -13
  122. package/dist/pptx/chunks/text-operations-BqHmLaLA.d.ts.map +1 -0
  123. package/dist/pptx/cli/index.cjs +1157 -395
  124. package/dist/pptx/cli/index.d.ts +1 -1
  125. package/dist/pptx/cli/index.mjs +4 -4
  126. package/dist/pptx/converter/index.cjs +54 -36
  127. package/dist/pptx/converter/index.d.ts +1 -1
  128. package/dist/pptx/converter/index.mjs +2 -2
  129. package/dist/pptx/editor/render/collaboration-live-patch-target.cjs +2 -2
  130. package/dist/pptx/editor/render/collaboration-live-patch-target.mjs +1 -1
  131. package/dist/pptx/editor/render/find-replace.cjs +416 -45
  132. package/dist/pptx/editor/render/find-replace.d.ts +35 -4
  133. package/dist/pptx/editor/render/find-replace.d.ts.map +1 -1
  134. package/dist/pptx/editor/render/find-replace.mjs +416 -46
  135. package/dist/pptx/editor/render/remap-text.cjs +2 -2
  136. package/dist/pptx/editor/render/remap-text.d.ts.map +1 -1
  137. package/dist/pptx/editor/render/remap-text.mjs +1 -1
  138. package/dist/pptx/editor/render/slide-operations.cjs +87 -0
  139. package/dist/pptx/editor/render/slide-operations.d.ts +17 -1
  140. package/dist/pptx/editor/render/slide-operations.d.ts.map +1 -1
  141. package/dist/pptx/editor/render/slide-operations.mjs +83 -1
  142. package/dist/pptx/editor/render/slide-search.cjs +6 -10
  143. package/dist/pptx/editor/render/slide-search.d.ts +1 -1
  144. package/dist/pptx/editor/render/slide-search.mjs +6 -10
  145. package/dist/pptx/editor/render/template-editing.d.ts +1 -1
  146. package/dist/pptx/editor/render/template-editing.d.ts.map +1 -1
  147. package/dist/pptx/index.cjs +1651 -419
  148. package/dist/pptx/index.d.ts +5 -5
  149. package/dist/pptx/index.mjs +5 -5
  150. package/dist/pptx/smartart-layouts/index.d.ts +1 -1
  151. package/dist/teams/index.cjs +965 -34
  152. package/dist/teams/index.mjs +965 -34
  153. package/dist/visio/accessibility.d.ts +10 -0
  154. package/dist/visio/accessibility.d.ts.map +1 -0
  155. package/dist/visio/cell-formula.d.ts +2 -0
  156. package/dist/visio/cell-formula.d.ts.map +1 -1
  157. package/dist/visio/connector-curve-aligned.d.ts +5 -0
  158. package/dist/visio/connector-curve-aligned.d.ts.map +1 -0
  159. package/dist/visio/connector-curve-spans.d.ts +14 -0
  160. package/dist/visio/connector-curve-spans.d.ts.map +1 -0
  161. package/dist/visio/connector-jumps.d.ts +5 -0
  162. package/dist/visio/connector-jumps.d.ts.map +1 -0
  163. package/dist/visio/connector-route-walk.d.ts +2 -1
  164. package/dist/visio/connector-route-walk.d.ts.map +1 -1
  165. package/dist/visio/date-cache.d.ts +3 -0
  166. package/dist/visio/date-cache.d.ts.map +1 -0
  167. package/dist/visio/edit-alt-text-scope.d.ts +5 -0
  168. package/dist/visio/edit-alt-text-scope.d.ts.map +1 -0
  169. package/dist/visio/edit-alt-text.d.ts +3 -0
  170. package/dist/visio/edit-alt-text.d.ts.map +1 -0
  171. package/dist/visio/edit-commands.d.ts +7 -2
  172. package/dist/visio/edit-commands.d.ts.map +1 -1
  173. package/dist/visio/edit-formatting-commands.d.ts +5 -0
  174. package/dist/visio/edit-formatting-commands.d.ts.map +1 -1
  175. package/dist/visio/edit-formatting-paint.d.ts.map +1 -1
  176. package/dist/visio/edit-formatting-scope.d.ts.map +1 -1
  177. package/dist/visio/edit-line-jump-cache.d.ts +4 -0
  178. package/dist/visio/edit-line-jump-cache.d.ts.map +1 -0
  179. package/dist/visio/edit-master-index.d.ts.map +1 -1
  180. package/dist/visio/edit-metadata-commands.d.ts +10 -2
  181. package/dist/visio/edit-metadata-commands.d.ts.map +1 -1
  182. package/dist/visio/edit-metadata.d.ts +3 -1
  183. package/dist/visio/edit-metadata.d.ts.map +1 -1
  184. package/dist/visio/edit-page-alt-text.d.ts +4 -0
  185. package/dist/visio/edit-page-alt-text.d.ts.map +1 -0
  186. package/dist/visio/edit-page-layout.d.ts.map +1 -1
  187. package/dist/visio/edit-page-rename.d.ts.map +1 -1
  188. package/dist/visio/edit-page-setup-commands.d.ts +7 -1
  189. package/dist/visio/edit-page-setup-commands.d.ts.map +1 -1
  190. package/dist/visio/edit-page-size.d.ts.map +1 -1
  191. package/dist/visio/edit-pages.d.ts.map +1 -1
  192. package/dist/visio/edit-recalculate-index.d.ts.map +1 -1
  193. package/dist/visio/edit-scope.d.ts.map +1 -1
  194. package/dist/visio/edit-shape-create.d.ts.map +1 -1
  195. package/dist/visio/edit-stencil-connector-write.d.ts.map +1 -1
  196. package/dist/visio/edit-style-admission.d.ts.map +1 -1
  197. package/dist/visio/edit-text-field.d.ts.map +1 -1
  198. package/dist/visio/edit-text.d.ts.map +1 -1
  199. package/dist/visio/edit.d.ts +1 -1
  200. package/dist/visio/edit.d.ts.map +1 -1
  201. package/dist/visio/index.cjs +1215 -248
  202. package/dist/visio/index.d.ts +2 -1
  203. package/dist/visio/index.d.ts.map +1 -1
  204. package/dist/visio/index.mjs +1215 -249
  205. package/dist/visio/line-jumps.d.ts +1 -5
  206. package/dist/visio/line-jumps.d.ts.map +1 -1
  207. package/dist/visio/model.d.ts +13 -0
  208. package/dist/visio/model.d.ts.map +1 -1
  209. package/dist/visio/page-layout.d.ts +11 -2
  210. package/dist/visio/page-layout.d.ts.map +1 -1
  211. package/dist/visio/parser.d.ts.map +1 -1
  212. package/dist/visio/shape-metadata.d.ts +6 -0
  213. package/dist/visio/shape-metadata.d.ts.map +1 -1
  214. package/dist/visio/shapes.d.ts.map +1 -1
  215. package/dist/visio/text-field-case.d.ts +2 -0
  216. package/dist/visio/text-field-case.d.ts.map +1 -0
  217. package/dist/visio/text-field-display.d.ts.map +1 -1
  218. package/dist/visio/text-field-fraction.d.ts +3 -0
  219. package/dist/visio/text-field-fraction.d.ts.map +1 -0
  220. package/dist/visio/text-field-numeric.d.ts +4 -0
  221. package/dist/visio/text-field-numeric.d.ts.map +1 -0
  222. package/dist/visio/text-field-system-date.d.ts +4 -0
  223. package/dist/visio/text-field-system-date.d.ts.map +1 -0
  224. package/dist/visio/text-fields.d.ts +1 -0
  225. package/dist/visio/text-fields.d.ts.map +1 -1
  226. package/dist/visio/ui/connector-preview.d.ts +1 -1
  227. package/dist/visio/ui/connector-preview.d.ts.map +1 -1
  228. package/dist/visio/ui/data-graphic-rules.d.ts +2 -0
  229. package/dist/visio/ui/data-graphic-rules.d.ts.map +1 -1
  230. package/dist/visio/ui/data-graphics.d.ts +3 -2
  231. package/dist/visio/ui/data-graphics.d.ts.map +1 -1
  232. package/dist/visio/ui/edit-commands.d.ts.map +1 -1
  233. package/dist/visio/ui/index.cjs +19310 -18157
  234. package/dist/visio/ui/index.mjs +19310 -18158
  235. package/dist/visio/ui/scene-details.d.ts.map +1 -1
  236. package/dist/visio/ui/scene-validation.d.ts.map +1 -1
  237. package/dist/visio/ui/snapshot-scene.d.ts +2 -1
  238. package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
  239. package/dist/visio/ui/text-field-catalog.d.ts.map +1 -1
  240. package/dist/visio/xml-attribute-whitespace.d.ts +5 -0
  241. package/dist/visio/xml-attribute-whitespace.d.ts.map +1 -0
  242. package/dist/xlsx/edit/index.d.ts +1 -0
  243. package/dist/xlsx/edit/index.d.ts.map +1 -1
  244. package/dist/xlsx/edit/insert-guard.d.ts.map +1 -1
  245. package/dist/xlsx/edit/merge.d.ts.map +1 -1
  246. package/dist/xlsx/edit/page-breaks.d.ts +5 -0
  247. package/dist/xlsx/edit/page-breaks.d.ts.map +1 -0
  248. package/dist/xlsx/edit/pivots.d.ts +8 -0
  249. package/dist/xlsx/edit/pivots.d.ts.map +1 -0
  250. package/dist/xlsx/edit/print-titles.d.ts +7 -0
  251. package/dist/xlsx/edit/print-titles.d.ts.map +1 -0
  252. package/dist/xlsx/edit/session.d.ts.map +1 -1
  253. package/dist/xlsx/edit/sheets.d.ts.map +1 -1
  254. package/dist/xlsx/edit/shift-formulas.d.ts.map +1 -1
  255. package/dist/xlsx/edit/shift-sheet.d.ts.map +1 -1
  256. package/dist/xlsx/edit/sparkline-ranges.d.ts +11 -0
  257. package/dist/xlsx/edit/sparkline-ranges.d.ts.map +1 -0
  258. package/dist/xlsx/edit/sparkline-xml.d.ts +13 -0
  259. package/dist/xlsx/edit/sparkline-xml.d.ts.map +1 -0
  260. package/dist/xlsx/edit/sparklines.d.ts +16 -0
  261. package/dist/xlsx/edit/sparklines.d.ts.map +1 -0
  262. package/dist/xlsx/edit/table-edits.d.ts.map +1 -1
  263. package/dist/xlsx/edit/tables.d.ts.map +1 -1
  264. package/dist/xlsx/edit/types.d.ts +22 -1
  265. package/dist/xlsx/edit/types.d.ts.map +1 -1
  266. package/dist/xlsx/formula/functions/text-regex.d.ts.map +1 -1
  267. package/dist/xlsx/index.cjs +3638 -1199
  268. package/dist/xlsx/index.d.ts +1 -0
  269. package/dist/xlsx/index.d.ts.map +1 -1
  270. package/dist/xlsx/index.mjs +3619 -1200
  271. package/dist/xlsx/layout/cell-view.d.ts +2 -0
  272. package/dist/xlsx/layout/cell-view.d.ts.map +1 -1
  273. package/dist/xlsx/layout/header-footer.d.ts +58 -0
  274. package/dist/xlsx/layout/header-footer.d.ts.map +1 -0
  275. package/dist/xlsx/layout/index.d.ts +5 -0
  276. package/dist/xlsx/layout/index.d.ts.map +1 -1
  277. package/dist/xlsx/layout/print-breaks.d.ts +11 -0
  278. package/dist/xlsx/layout/print-breaks.d.ts.map +1 -0
  279. package/dist/xlsx/layout/print-layout.d.ts +34 -0
  280. package/dist/xlsx/layout/print-layout.d.ts.map +1 -0
  281. package/dist/xlsx/layout/print-merges.d.ts +18 -0
  282. package/dist/xlsx/layout/print-merges.d.ts.map +1 -0
  283. package/dist/xlsx/layout/print-repeat.d.ts +12 -0
  284. package/dist/xlsx/layout/print-repeat.d.ts.map +1 -0
  285. package/dist/xlsx/layout/print-titles.d.ts +20 -0
  286. package/dist/xlsx/layout/print-titles.d.ts.map +1 -0
  287. package/dist/xlsx/layout/sparkline-data.d.ts.map +1 -1
  288. package/dist/xlsx/layout/sparkline-view.d.ts.map +1 -1
  289. package/dist/xlsx/load/index.cjs +8165 -6945
  290. package/dist/xlsx/load/index.mjs +8165 -6945
  291. package/dist/xlsx/model-pivots.d.ts +67 -0
  292. package/dist/xlsx/model-pivots.d.ts.map +1 -0
  293. package/dist/xlsx/model.d.ts +5 -0
  294. package/dist/xlsx/model.d.ts.map +1 -1
  295. package/dist/xlsx/pivot/admission.d.ts +5 -0
  296. package/dist/xlsx/pivot/admission.d.ts.map +1 -0
  297. package/dist/xlsx/pivot/aggregate.d.ts +21 -0
  298. package/dist/xlsx/pivot/aggregate.d.ts.map +1 -0
  299. package/dist/xlsx/pivot/cache-xml.d.ts +9 -0
  300. package/dist/xlsx/pivot/cache-xml.d.ts.map +1 -0
  301. package/dist/xlsx/pivot/data.d.ts +12 -0
  302. package/dist/xlsx/pivot/data.d.ts.map +1 -0
  303. package/dist/xlsx/pivot/hierarchy-first.d.ts +21 -0
  304. package/dist/xlsx/pivot/hierarchy-first.d.ts.map +1 -0
  305. package/dist/xlsx/pivot/hierarchy.d.ts +5 -0
  306. package/dist/xlsx/pivot/hierarchy.d.ts.map +1 -0
  307. package/dist/xlsx/pivot/index.d.ts +3 -0
  308. package/dist/xlsx/pivot/index.d.ts.map +1 -0
  309. package/dist/xlsx/pivot/measures.d.ts +13 -0
  310. package/dist/xlsx/pivot/measures.d.ts.map +1 -0
  311. package/dist/xlsx/pivot/read.d.ts +5 -0
  312. package/dist/xlsx/pivot/read.d.ts.map +1 -0
  313. package/dist/xlsx/pivot/table-xml.d.ts +5 -0
  314. package/dist/xlsx/pivot/table-xml.d.ts.map +1 -0
  315. package/dist/xlsx/pivot/values-axis.d.ts +9 -0
  316. package/dist/xlsx/pivot/values-axis.d.ts.map +1 -0
  317. package/dist/xlsx/pivot/write.d.ts +11 -0
  318. package/dist/xlsx/pivot/write.d.ts.map +1 -0
  319. package/dist/xlsx/read/load.d.ts.map +1 -1
  320. package/dist/xlsx/read/sheet-props.d.ts.map +1 -1
  321. package/dist/xlsx/ui/commands/i18n/index.d.ts.map +1 -1
  322. package/dist/xlsx/ui/commands/i18n/navigation.d.ts.map +1 -1
  323. package/dist/xlsx/ui/commands/i18n/pivots.d.ts +3 -0
  324. package/dist/xlsx/ui/commands/i18n/pivots.d.ts.map +1 -0
  325. package/dist/xlsx/ui/commands/i18n/print-layout.d.ts +3 -0
  326. package/dist/xlsx/ui/commands/i18n/print-layout.d.ts.map +1 -0
  327. package/dist/xlsx/ui/commands/i18n/sparklines.d.ts +3 -0
  328. package/dist/xlsx/ui/commands/i18n/sparklines.d.ts.map +1 -0
  329. package/dist/xlsx/ui/commands/i18n/tools.d.ts.map +1 -1
  330. package/dist/xlsx/ui/commands/page-breaks.d.ts +3 -0
  331. package/dist/xlsx/ui/commands/page-breaks.d.ts.map +1 -0
  332. package/dist/xlsx/ui/index.cjs +2421 -288
  333. package/dist/xlsx/ui/index.d.ts +1 -0
  334. package/dist/xlsx/ui/index.d.ts.map +1 -1
  335. package/dist/xlsx/ui/index.mjs +2421 -289
  336. package/dist/xlsx/write/page-setup.d.ts.map +1 -1
  337. package/dist/xlsx/write/save.d.ts.map +1 -1
  338. package/dist/xlsx/write/sheet-parts.d.ts +1 -0
  339. package/dist/xlsx/write/sheet-parts.d.ts.map +1 -1
  340. package/dist/xlsx/write/workbook-part.d.ts +1 -1
  341. package/dist/xlsx/write/workbook-part.d.ts.map +1 -1
  342. package/dist/xlsx/write/worksheet.d.ts.map +1 -1
  343. package/package.json +1 -1
  344. package/dist/pptx/chunks/index-CKIUurnd.d.ts.map +0 -1
  345. package/dist/pptx/chunks/index-Cn-GzYGp.d.ts.map +0 -1
  346. package/dist/pptx/chunks/smart-art-Q2kZQtHh.d.ts.map +0 -1
  347. package/dist/pptx/chunks/text-operations-BHfAm5K9.d.ts.map +0 -1
@@ -288,9 +288,9 @@ var init_namespaces = __esm({
288
288
  }
289
289
  });
290
290
  function parseXml(xml, options = {}) {
291
- const label2 = options.label ?? "OOXML";
291
+ const label3 = options.label ?? "OOXML";
292
292
  if (/<!DOCTYPE|<!ENTITY/i.test(xml))
293
- throw new Error(`${label2} XML with DTD or entity declarations is not supported`);
293
+ throw new Error(`${label3} XML with DTD or entity declarations is not supported`);
294
294
  let parseError = "";
295
295
  let parsed;
296
296
  try {
@@ -301,12 +301,12 @@ function parseXml(xml, options = {}) {
301
301
  }).parseFromString(xml, "application/xml");
302
302
  } catch (error) {
303
303
  throw new Error(
304
- `Invalid ${label2} XML: ${error instanceof Error ? error.message : String(error)}`,
304
+ `Invalid ${label3} XML: ${error instanceof Error ? error.message : String(error)}`,
305
305
  { cause: error }
306
306
  );
307
307
  }
308
308
  if (parseError || !parsed.documentElement)
309
- throw new Error(`Invalid ${label2} XML: ${parseError || "missing root element"}`);
309
+ throw new Error(`Invalid ${label3} XML: ${parseError || "missing root element"}`);
310
310
  return parsed;
311
311
  }
312
312
  function named(element2, local, ns, lenient = true) {
@@ -940,19 +940,19 @@ var init_opc = __esm({
940
940
 
941
941
  // xlsx/address.ts
942
942
  function columnLabel(col) {
943
- let label2 = "";
943
+ let label3 = "";
944
944
  let n = col + 1;
945
945
  while (n > 0) {
946
946
  const rem = (n - 1) % 26;
947
- label2 = String.fromCharCode(65 + rem) + label2;
947
+ label3 = String.fromCharCode(65 + rem) + label3;
948
948
  n = Math.floor((n - 1) / 26);
949
949
  }
950
- return label2;
950
+ return label3;
951
951
  }
952
- function columnIndex(label2) {
953
- if (!/^[A-Za-z]{1,3}$/.test(label2)) return -1;
952
+ function columnIndex(label3) {
953
+ if (!/^[A-Za-z]{1,3}$/.test(label3)) return -1;
954
954
  let n = 0;
955
- for (const ch of label2.toUpperCase()) n = n * 26 + (ch.charCodeAt(0) - 64);
955
+ for (const ch of label3.toUpperCase()) n = n * 26 + (ch.charCodeAt(0) - 64);
956
956
  return n - 1;
957
957
  }
958
958
  function parseAddress(ref) {
@@ -2618,10 +2618,10 @@ function titleXml(context, title) {
2618
2618
  function labelOptionsXml(context, options) {
2619
2619
  return numberFormatXml(options.numberFormat) + shapePropertiesXml(context, options.spPr) + textBodyXml(context, options.txPr) + valXml("dLblPos", options.position) + valXml("showLegendKey", options.showLegendKey) + valXml("showVal", options.showValue) + valXml("showCatName", options.showCategoryName) + valXml("showSerName", options.showSeriesName) + valXml("showPercent", options.showPercent) + valXml("showBubbleSize", options.showBubbleSize) + (options.separator === void 0 ? "" : textElement("separator", options.separator));
2620
2620
  }
2621
- function labelXml(context, label2) {
2621
+ function labelXml(context, label3) {
2622
2622
  return elementXml(
2623
2623
  "dLbl",
2624
- valXml("idx", label2.index) + valXml("delete", label2.deleted) + layoutXml(context, label2.layout) + chartTextXml(context, label2.tx, false) + labelOptionsXml(context, label2) + raw(context, label2.extLst)
2624
+ valXml("idx", label3.index) + valXml("delete", label3.deleted) + layoutXml(context, label3.layout) + chartTextXml(context, label3.tx, false) + labelOptionsXml(context, label3) + raw(context, label3.extLst)
2625
2625
  );
2626
2626
  }
2627
2627
  function dataLabelsXml(context, labels) {
@@ -2629,7 +2629,7 @@ function dataLabelsXml(context, labels) {
2629
2629
  const leaderLines = labels.leaderLines ? elementXml("leaderLines", shapePropertiesXml(context, labels.leaderLines.spPr)) : "";
2630
2630
  return elementXml(
2631
2631
  "dLbls",
2632
- labels.labels.map((label2) => labelXml(context, label2)).join("") + valXml("delete", labels.deleted) + labelOptionsXml(context, labels) + valXml("showLeaderLines", labels.showLeaderLines) + leaderLines + raw(context, labels.extLst)
2632
+ labels.labels.map((label3) => labelXml(context, label3)).join("") + valXml("delete", labels.deleted) + labelOptionsXml(context, labels) + valXml("showLeaderLines", labels.showLeaderLines) + leaderLines + raw(context, labels.extLst)
2633
2633
  );
2634
2634
  }
2635
2635
  var textElement, dataSourceXml;
@@ -2660,12 +2660,12 @@ function dataTableXml(context, table2) {
2660
2660
  }
2661
2661
  function displayUnitsXml(context, units) {
2662
2662
  if (!units) return "";
2663
- const label2 = units.label;
2663
+ const label3 = units.label;
2664
2664
  return elementXml(
2665
2665
  "dispUnits",
2666
- valXml("custUnit", units.customUnit) + (units.customUnit === void 0 ? valXml("builtInUnit", units.builtInUnit) : "") + (label2 ? elementXml(
2666
+ valXml("custUnit", units.customUnit) + (units.customUnit === void 0 ? valXml("builtInUnit", units.builtInUnit) : "") + (label3 ? elementXml(
2667
2667
  "dispUnitsLbl",
2668
- layoutXml(context, label2.layout) + chartTextXml(context, label2.tx, false) + shapePropertiesXml(context, label2.spPr) + textBodyXml(context, label2.txPr)
2668
+ layoutXml(context, label3.layout) + chartTextXml(context, label3.tx, false) + shapePropertiesXml(context, label3.spPr) + textBodyXml(context, label3.txPr)
2669
2669
  ) : "") + raw(context, units.extLst)
2670
2670
  );
2671
2671
  }
@@ -2876,10 +2876,10 @@ function parseDisplayUnits(context, element2) {
2876
2876
  if (!element2) return void 0;
2877
2877
  reportUnmodelled(context, element2, DISPLAY_UNITS);
2878
2878
  const labelElement = cChild(element2, "dispUnitsLbl");
2879
- let label2;
2879
+ let label3;
2880
2880
  if (labelElement) {
2881
2881
  reportUnmodelled(context, labelElement, DISPLAY_UNITS_LABEL);
2882
- label2 = assignDefined(
2882
+ label3 = assignDefined(
2883
2883
  {},
2884
2884
  {
2885
2885
  layout: manualLayout(labelElement),
@@ -2894,7 +2894,7 @@ function parseDisplayUnits(context, element2) {
2894
2894
  {
2895
2895
  builtInUnit: cVal(element2, "builtInUnit"),
2896
2896
  customUnit: cNumber(context, element2, "custUnit"),
2897
- label: label2,
2897
+ label: label3,
2898
2898
  extLst: extensionList(element2)
2899
2899
  }
2900
2900
  );
@@ -15841,13 +15841,27 @@ var init_text_regex = __esm({
15841
15841
  "REGEXEXTRACT",
15842
15842
  C36,
15843
15843
  "REGEXEXTRACT(text, pattern, [return_mode], [case_sensitivity])",
15844
- "The first part of the text that matches the pattern.",
15844
+ "Extracts the first match (0), all matches (1), or the first match\u2019s capture groups (2).",
15845
15845
  2,
15846
15846
  4,
15847
15847
  (args) => {
15848
- if (optNum(args, 2, 0) !== 0) fail(ERR.VALUE);
15849
- const match2 = compile(str(args[1]), caseMode(args, 3), false).exec(str(args[0]));
15850
- return match2 ? match2[0] : fail(ERR.NA);
15848
+ const mode = optNum(args, 2, 0);
15849
+ if (mode !== 0 && mode !== 1 && mode !== 2) fail(ERR.VALUE);
15850
+ const regex = compile(str(args[1]), caseMode(args, 3), mode === 1);
15851
+ const text = str(args[0]);
15852
+ if (mode === 1) {
15853
+ const matches2 = [];
15854
+ for (const match3 of text.matchAll(regex)) {
15855
+ checkArraySize(matches2.length + 1, 1);
15856
+ matches2.push(match3[0]);
15857
+ }
15858
+ return matches2.length ? new Matrix(matches2.map((match3) => [match3])) : fail(ERR.NA);
15859
+ }
15860
+ const match2 = regex.exec(text);
15861
+ if (!match2) fail(ERR.NA);
15862
+ if (mode === 0) return match2[0];
15863
+ if (match2.length === 1) fail(ERR.VALUE);
15864
+ return new Matrix([match2.slice(1).map((group) => group ?? "")]);
15851
15865
  }
15852
15866
  ),
15853
15867
  spec(
@@ -17526,7 +17540,7 @@ function definedNamesOf(workbook) {
17526
17540
  });
17527
17541
  return names2;
17528
17542
  }
17529
- function workbookXml(workbook, sheets, activeTab, sourceXml) {
17543
+ function workbookXml(workbook, sheets, activeTab, sourceXml, pivotCachesXml) {
17530
17544
  const kept = /* @__PURE__ */ new Map();
17531
17545
  if (sourceXml) {
17532
17546
  try {
@@ -17570,7 +17584,7 @@ function workbookXml(workbook, sheets, activeTab, sourceXml) {
17570
17584
  const iterate = workbook.iterate ? ` iterate="1" iterateCount="${workbook.iterate.count}" iterateDelta="${workbook.iterate.delta}"` : "";
17571
17585
  const owned = ["fullCalcOnLoad", "calcId", "calcMode", "iterate", "iterateCount", "iterateDelta"];
17572
17586
  out += `<calcPr${copyAttrs(calc, owned)} calcId="191029"${mode}${iterate} fullCalcOnLoad="1"/>`;
17573
- out += raw2(KEPT_TAIL);
17587
+ out += pivotCachesXml === void 0 ? raw2(KEPT_TAIL) : raw2(KEPT_TAIL.slice(0, 2)) + pivotCachesXml + raw2(KEPT_TAIL.slice(3));
17574
17588
  return `${out}</workbook>`;
17575
17589
  }
17576
17590
  var KEPT_BEFORE_SHEETS, KEPT_AFTER_SHEETS, KEPT_TAIL, copyAttrs;
@@ -17998,6 +18012,11 @@ function readHeaderFooter(node) {
17998
18012
  function readPageSetup(margins, setup, headerFooter, fitToPage) {
17999
18013
  const page = {};
18000
18014
  if (setup) {
18015
+ if (/^(1|true)$/.test(att(setup, "useFirstPageNumber") ?? "")) {
18016
+ page.firstPageNumber = numAttr(setup, "firstPageNumber") ?? 1;
18017
+ }
18018
+ const order = att(setup, "pageOrder");
18019
+ if (order === "downThenOver" || order === "overThenDown") page.pageOrder = order;
18001
18020
  const orientation = att(setup, "orientation");
18002
18021
  if (orientation && ORIENTATIONS.has(orientation))
18003
18022
  page.orientation = orientation;
@@ -18495,9 +18514,9 @@ var init_gradient_preset_data = __esm({
18495
18514
  var init_gradient_presets = __esm({
18496
18515
  "drawingml/gradient-presets.ts"() {
18497
18516
  init_gradient_preset_data();
18498
- OFFICE_GRADIENT_PRESET_DATA.map(([label2], index2) => ({
18517
+ OFFICE_GRADIENT_PRESET_DATA.map(([label3], index2) => ({
18499
18518
  id: index2 + 1,
18500
- label: label2
18519
+ label: label3
18501
18520
  }));
18502
18521
  }
18503
18522
  });
@@ -18733,8 +18752,8 @@ function parseTable(xml, partName) {
18733
18752
  if (id !== void 0 && Number.isInteger(id) && id >= 0) column.sourceId = id;
18734
18753
  const fn = att(node, "totalsRowFunction");
18735
18754
  if (fn && fn !== "none") column.totalsRowFunction = fn;
18736
- const label2 = att(node, "totalsRowLabel");
18737
- if (label2 !== void 0) column.totalsRowLabel = label2;
18755
+ const label3 = att(node, "totalsRowLabel");
18756
+ if (label3 !== void 0) column.totalsRowLabel = label3;
18738
18757
  const calculated = xFirst(node, "calculatedColumnFormula");
18739
18758
  if (calculated) column.calculatedColumnFormula = stripFuturePrefixes(xText(calculated));
18740
18759
  return column;
@@ -18816,20 +18835,28 @@ function setupXml(sheet, page) {
18816
18835
  const source2 = snapshotElement(sheet, "pageSetup");
18817
18836
  const fit = page.fitToWidth !== void 0 || page.fitToHeight !== void 0;
18818
18837
  const pick2 = (p) => ({
18838
+ firstPageNumber: p.firstPageNumber,
18839
+ pageOrder: p.pageOrder,
18819
18840
  orientation: p.orientation,
18820
18841
  paperSize: p.paperSize,
18821
18842
  scale: p.scale,
18822
18843
  fitToWidth: p.fitToWidth,
18823
18844
  fitToHeight: p.fitToHeight
18824
18845
  });
18825
- const modelled = fit || page.orientation !== void 0 || page.paperSize !== void 0 || page.scale !== void 0;
18846
+ const modelled = page.firstPageNumber !== void 0 || page.pageOrder !== void 0 || fit || page.orientation !== void 0 || page.paperSize !== void 0 || page.scale !== void 0;
18826
18847
  if (!source2 && !modelled) return "";
18827
18848
  if (source2) {
18828
18849
  const before = readPageSetup(void 0, source2, void 0, fit) ?? {};
18829
18850
  if (sameModel(pick2(before), pick2(page))) return snapshotXml(sheet, "pageSetup") ?? "";
18830
18851
  }
18831
18852
  const fitValues = fit ? { fitToWidth: page.fitToWidth, fitToHeight: page.fitToHeight } : {};
18853
+ const numbering = page.firstPageNumber !== void 0 || !source2 || readPageSetup(void 0, source2, void 0, fit)?.firstPageNumber !== void 0 ? {
18854
+ firstPageNumber: page.firstPageNumber,
18855
+ useFirstPageNumber: page.firstPageNumber !== void 0 ? true : void 0
18856
+ } : {};
18832
18857
  return `<pageSetup${mergedAttrs(source2, {
18858
+ ...numbering,
18859
+ pageOrder: page.pageOrder,
18833
18860
  paperSize: page.paperSize,
18834
18861
  scale: page.scale,
18835
18862
  ...fitValues,
@@ -19779,6 +19806,8 @@ function writeWorksheet(ctx, sheet, index2, partName) {
19779
19806
  const ids = sourceRelIds(source2, sheet.partName);
19780
19807
  for (const [id, rel] of source2.rels(sheet.partName)) {
19781
19808
  const target = source2.target(sheet.partName, rel);
19809
+ if (rel.type === RELATIONSHIP_TYPES.pivotTable && target && sheet.preserved.get("source:pivotTables")?.includes(target))
19810
+ continue;
19782
19811
  if (rel.type === RELATIONSHIP_TYPES.drawing && id === ids.drawing) sourceDrawing = target;
19783
19812
  if (REGENERATED.has(rel.type) || rel.type === RELATIONSHIP_TYPES.vmlDrawing && id === ids.legacy)
19784
19813
  continue;
@@ -19833,6 +19862,7 @@ function writeWorksheet(ctx, sheet, index2, partName) {
19833
19862
  blocks.set("drawing", writeSheetDrawing(ctx, sheet, partName, rels, sourceDrawing));
19834
19863
  blocks.set("legacyDrawing", writeComments(ctx, sheet, index2, partName, rels));
19835
19864
  blocks.set("tableParts", tableParts);
19865
+ ctx.pivots?.writeSheet(writer, sheet, partName, rels);
19836
19866
  blocks.set("extLst", conditionalExtensionsXml(sheet));
19837
19867
  for (const [key, list] of sheet.preserved) {
19838
19868
  if (key.startsWith("source:") || !ORDER2.includes(key) || (blocks.get(key) ?? "") !== "")
@@ -19918,6 +19948,904 @@ var init_worksheet2 = __esm({
19918
19948
  }
19919
19949
  });
19920
19950
 
19951
+ // xlsx/edit/sparkline-ranges.ts
19952
+ function checkedSparklineRange(raw2) {
19953
+ const range = normalizeRange(raw2);
19954
+ for (const point of [range.start, range.end])
19955
+ if (!Number.isInteger(point.row) || !Number.isInteger(point.col) || point.row < 0 || point.col < 0 || point.row > MAX_ROW || point.col > MAX_COL)
19956
+ throw new RangeError("The reference is not valid.");
19957
+ return range;
19958
+ }
19959
+ function sparklineDataRange(workbook, sheet, source2) {
19960
+ let ast;
19961
+ try {
19962
+ ast = parseFormula(source2.trim().replace(/^=/, ""));
19963
+ } catch {
19964
+ throw new Error("The reference is not valid.");
19965
+ }
19966
+ if (ast.type !== "ref" || !ast.ref || !["cell", "area"].includes(ast.ref.kind) || ast.prefix?.book || ast.prefix?.sheet2 || ast.spill)
19967
+ throw new Error("The reference is not valid.");
19968
+ const index2 = ast.prefix ? workbook.sheets.findIndex((ws) => ws.name.toLowerCase() === ast.prefix.sheet.toLowerCase()) : sheet;
19969
+ if (!workbook.sheets[index2]) throw new Error("The reference is not valid.");
19970
+ return { sheet: index2, range: checkedSparklineRange({ start: ast.ref.start, end: ast.ref.end }) };
19971
+ }
19972
+ var init_sparkline_ranges = __esm({
19973
+ "xlsx/edit/sparkline-ranges.ts"() {
19974
+ init_address();
19975
+ init_parser();
19976
+ }
19977
+ });
19978
+
19979
+ // xlsx/pivot/data.ts
19980
+ function pivotValueKey(value) {
19981
+ return value === null || value === "" ? "blank" : isCellError(value) ? `error:${value.error}` : `${typeof value}:${String(value).toLowerCase()}`;
19982
+ }
19983
+ function pivotItems(pivot, field) {
19984
+ const index2 = pivot.fields.indexOf(field);
19985
+ const items = /* @__PURE__ */ new Map();
19986
+ for (const record of pivot.records) {
19987
+ const value = record[index2] ?? null;
19988
+ const key = pivotValueKey(value);
19989
+ if (!items.has(key)) items.set(key, value);
19990
+ }
19991
+ const rank3 = (value) => value === null || value === "" ? 4 : isCellError(value) ? 3 : typeof value === "boolean" ? 2 : typeof value === "string" ? 1 : 0;
19992
+ return [...items.values()].sort(
19993
+ (a2, b) => rank3(a2) - rank3(b) || (typeof a2 === "number" && typeof b === "number" ? a2 - b : String(pivotItemLabel(a2)).localeCompare(String(pivotItemLabel(b)), "en", {
19994
+ sensitivity: "base",
19995
+ numeric: true
19996
+ }))
19997
+ );
19998
+ }
19999
+ function pivotItemLabel(value) {
20000
+ if (value === null || value === "") return "(blank)";
20001
+ if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
20002
+ return isCellError(value) ? value.error : value;
20003
+ }
20004
+ function validatePivotFields(pivot) {
20005
+ const used = [
20006
+ pivot.rowField,
20007
+ ...pivot.secondRowField ? [pivot.secondRowField] : [],
20008
+ ...pivot.columnField ? [pivot.columnField] : [],
20009
+ pivot.valueField
20010
+ ];
20011
+ const extras = pivot.additionalValues ?? [];
20012
+ if (pivot.valuesAxis !== void 0 && !["columns", "rows"].includes(pivot.valuesAxis))
20013
+ throw new Error("Choose a valid Values axis.");
20014
+ if (pivot.valuesPosition !== void 0 && !["last", "between", "first"].includes(pivot.valuesPosition))
20015
+ throw new Error("Choose a valid Values position.");
20016
+ if ((pivot.valuesPosition === "between" || pivot.valuesPosition === "first") && (pivot.valuesAxis !== "rows" || !pivot.secondRowField))
20017
+ throw new Error("Values before or between fields require two row fields and Values on rows.");
20018
+ if (pivot.valuesAxis === "rows" && (!Array.isArray(extras) || !extras.length))
20019
+ throw new Error("Values on rows require multiple measures.");
20020
+ if (extras.length > 0 && pivot.sourceXml && parseXml(pivot.sourceXml).documentElement.getAttribute("dataCaption") !== "Values")
20021
+ throw new Error("This PivotTable uses unsupported Values header captions.");
20022
+ if (!Array.isArray(extras) || extras.length > 15 || extras.some(
20023
+ (measure) => !measure || !pivot.fields.includes(measure.field) || !PIVOT_AGGREGATES.includes(measure.aggregate) || typeof measure.caption !== "string" || !measure.caption.trim() || measure.caption.length > 255 || pivot.fields.some((field) => field.toLowerCase() === measure.caption.toLowerCase())
20024
+ ) || new Set(
20025
+ [pivot.valueCaption, ...extras.map((measure) => measure.caption)].map(
20026
+ (caption) => caption?.toLowerCase()
20027
+ )
20028
+ ).size !== extras.length + 1)
20029
+ throw new Error("Choose PivotTable value fields with valid aggregates and unique captions.");
20030
+ if (pivot.layout !== void 0 && !["tabular", "compact", "outline"].includes(pivot.layout) || pivot.subtotalPosition !== void 0 && !["top", "bottom"].includes(pivot.subtotalPosition) || !PIVOT_AGGREGATES.includes(pivot.aggregate) || used.some((field) => !pivot.fields.includes(field)) || new Set([pivot.rowField, pivot.secondRowField, pivot.columnField].filter(Boolean)).size !== [pivot.rowField, pivot.secondRowField, pivot.columnField].filter(Boolean).length || pivot.subtotals !== void 0 && typeof pivot.subtotals !== "boolean" || pivot.repeatLabels !== void 0 && typeof pivot.repeatLabels !== "boolean")
20031
+ throw new Error("Choose valid PivotTable fields; row and column fields must differ.");
20032
+ }
20033
+ var PIVOT_AGGREGATES;
20034
+ var init_data = __esm({
20035
+ "xlsx/pivot/data.ts"() {
20036
+ init_model();
20037
+ init_xml2();
20038
+ PIVOT_AGGREGATES = ["sum", "count", "average", "min", "max"];
20039
+ }
20040
+ });
20041
+
20042
+ // xlsx/pivot/cache-xml.ts
20043
+ function pivotCacheData(pivot) {
20044
+ const items = pivot.fields.map(() => []);
20045
+ const indices = pivot.fields.map(() => /* @__PURE__ */ new Map());
20046
+ for (const record of pivot.records)
20047
+ pivot.fields.forEach((_field, index2) => {
20048
+ const value = record[index2] ?? null;
20049
+ const key = pivotValueKey(value);
20050
+ if (!indices[index2].has(key)) {
20051
+ indices[index2].set(key, items[index2].length);
20052
+ items[index2].push(value);
20053
+ }
20054
+ });
20055
+ return { items, indices };
20056
+ }
20057
+ function valueXml(value) {
20058
+ if (value === null || value === "") return "<m/>";
20059
+ if (isCellError(value)) return `<e${attrs({ v: value.error })}/>`;
20060
+ if (typeof value === "string") return `<s${attrs({ v: encodeEscapes(value) })}/>`;
20061
+ if (typeof value === "boolean") return `<b v="${value ? 1 : 0}"/>`;
20062
+ if (!Number.isFinite(value)) throw new Error("The PivotTable cache contains an invalid value.");
20063
+ return `<n v="${value}"/>`;
20064
+ }
20065
+ function pivotCacheDefinitionXml(pivot, workbook, data, recordRel) {
20066
+ const source2 = sparklineDataRange(workbook, 0, pivot.source);
20067
+ const fields = pivot.fields.map((name, index2) => {
20068
+ const items = data.items[index2];
20069
+ const types = new Set(
20070
+ items.map((value) => value === null || value === "" ? "blank" : typeof value)
20071
+ );
20072
+ const nums = items.filter((value) => typeof value === "number");
20073
+ const text = items.some((item) => item !== null && item !== "" && typeof item !== "number");
20074
+ return `<cacheField${attrs({ name: encodeEscapes(name), numFmtId: 0 })}><sharedItems${attrs({ count: items.length, containsString: !nums.length || text, containsNumber: !!nums.length, containsInteger: nums.length > 0 && nums.every(Number.isInteger), containsBlank: types.has("blank"), containsMixedTypes: nums.length > 0 && text, containsSemiMixedTypes: !nums.length || types.size > 1 })}>${items.map(valueXml).join("")}</sharedItems></cacheField>`;
20075
+ }).join("");
20076
+ return `${XML_HEADER}<pivotCacheDefinition xmlns="${NS.x}" xmlns:r="${NS.r}" r:id="${recordRel}" createdVersion="6" refreshedVersion="6" minRefreshableVersion="3" recordCount="${pivot.records.length}"><cacheSource type="worksheet"><worksheetSource${attrs({ ref: formatRange(source2.range), sheet: workbook.sheets[source2.sheet].name })}/></cacheSource><cacheFields count="${pivot.fields.length}">${fields}</cacheFields></pivotCacheDefinition>`;
20077
+ }
20078
+ function pivotCacheRecordsXml(pivot, data) {
20079
+ const records = pivot.records.map(
20080
+ (record) => `<r>${pivot.fields.map((_field, index2) => `<x v="${data.indices[index2].get(pivotValueKey(record[index2] ?? null))}"/>`).join("")}</r>`
20081
+ ).join("");
20082
+ return `${XML_HEADER}<pivotCacheRecords xmlns="${NS.x}" count="${pivot.records.length}">${records}</pivotCacheRecords>`;
20083
+ }
20084
+ var init_cache_xml = __esm({
20085
+ "xlsx/pivot/cache-xml.ts"() {
20086
+ init_xml2();
20087
+ init_model();
20088
+ init_address();
20089
+ init_sparkline_ranges();
20090
+ init_xml_out();
20091
+ init_data();
20092
+ }
20093
+ });
20094
+
20095
+ // xlsx/pivot/measures.ts
20096
+ function aggregate2(records, field, type) {
20097
+ if (!records.length) return null;
20098
+ const values2 = records.map((record) => record[field] ?? null);
20099
+ if (type === "count") return values2.filter((value) => value !== null && value !== "").length;
20100
+ const error = values2.find(isCellError);
20101
+ if (error) return error;
20102
+ const numbers3 = values2.filter((value) => typeof value === "number");
20103
+ if (!numbers3.length) return type === "average" ? { error: "#DIV/0!" } : 0;
20104
+ if (type === "min") return numbers3.reduce((a2, b) => Math.min(a2, b));
20105
+ if (type === "max") return numbers3.reduce((a2, b) => Math.max(a2, b));
20106
+ const sum2 = numbers3.reduce((total2, value) => total2 + value, 0);
20107
+ return type === "average" ? sum2 / numbers3.length : sum2;
20108
+ }
20109
+ function pivotHeaderDimensions(pivot, columnItems, rowLabels) {
20110
+ const measures = 1 + (pivot.additionalValues?.length ?? 0);
20111
+ if (pivot.valuesAxis === "rows")
20112
+ return {
20113
+ rows: pivot.columnField ? 2 : 1,
20114
+ width: rowLabels + (pivot.columnField ? columnItems + 1 : 1)
20115
+ };
20116
+ return {
20117
+ rows: pivot.columnField ? measures > 1 ? 3 : 2 : 1,
20118
+ width: rowLabels + (pivot.columnField ? measures === 1 ? Math.max(1, columnItems) + 1 : (columnItems + 1) * measures : measures)
20119
+ };
20120
+ }
20121
+ function pivotHeaders(pivot, columns, labels, label3) {
20122
+ const measures = pivotMeasures(pivot);
20123
+ if (pivot.valuesAxis === "rows") {
20124
+ const rowLabels = pivot.layout === "compact" ? ["Row Labels"] : pivot.valuesPosition === "first" ? ["Values", ...labels] : pivot.valuesPosition === "between" ? [labels[0], "Values", labels[1]] : [...labels, "Values"];
20125
+ return pivot.columnField ? [
20126
+ [
20127
+ ...rowLabels.map(() => null),
20128
+ pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
20129
+ ...columns.map(() => null)
20130
+ ],
20131
+ [...rowLabels, ...columns.map(label3), "Grand Total"]
20132
+ ] : [[...rowLabels, null]];
20133
+ }
20134
+ if (!pivot.columnField) return [[...labels, ...measures.map((measure) => measure.caption)]];
20135
+ if (measures.length === 1)
20136
+ return [
20137
+ [
20138
+ pivot.valueCaption,
20139
+ ...labels.slice(1).map(() => null),
20140
+ pivot.layout === "compact" ? "Column Labels" : pivot.columnField,
20141
+ ...columns.slice(1).map(() => null),
20142
+ null
20143
+ ],
20144
+ [...labels, ...columns.map(label3), "Grand Total"]
20145
+ ];
20146
+ const { width } = pivotHeaderDimensions(pivot, columns.length, labels.length);
20147
+ const first2 = Array(width).fill(null);
20148
+ first2[labels.length] = pivot.layout === "compact" ? "Column Labels" : pivot.columnField;
20149
+ if (pivot.layout !== "compact") first2[labels.length + 1] = "Values";
20150
+ return [
20151
+ first2,
20152
+ [
20153
+ ...labels.map(() => null),
20154
+ ...columns.flatMap((column) => [label3(column), ...measures.slice(1).map(() => null)]),
20155
+ ...measures.map((measure) => `Total ${measure.caption}`)
20156
+ ],
20157
+ [
20158
+ ...labels,
20159
+ ...columns.flatMap(() => measures.map((measure) => measure.caption)),
20160
+ ...measures.map(() => null)
20161
+ ]
20162
+ ];
20163
+ }
20164
+ var pivotMeasures, pivotMeasureNumber, pivotNumbers;
20165
+ var init_measures = __esm({
20166
+ "xlsx/pivot/measures.ts"() {
20167
+ init_model();
20168
+ pivotMeasures = (pivot) => [
20169
+ { field: pivot.valueField, aggregate: pivot.aggregate, caption: pivot.valueCaption },
20170
+ ...pivot.additionalValues ?? []
20171
+ ];
20172
+ pivotMeasureNumber = (pivot, records, measure) => aggregate2(records, pivot.fields.indexOf(measure.field), measure.aggregate);
20173
+ pivotNumbers = (pivot, records) => pivotMeasures(pivot).map((measure) => pivotMeasureNumber(pivot, records, measure));
20174
+ }
20175
+ });
20176
+
20177
+ // xlsx/pivot/hierarchy-first.ts
20178
+ function appendFirstPivotValues(pivot, context) {
20179
+ const {
20180
+ rowItems,
20181
+ secondRowItems,
20182
+ columnItems,
20183
+ children: children2,
20184
+ innerIndices,
20185
+ groups,
20186
+ details,
20187
+ buckets,
20188
+ width,
20189
+ rowLabels,
20190
+ top,
20191
+ bottom,
20192
+ append
20193
+ } = context;
20194
+ const compact = pivot.layout === "compact";
20195
+ const tabular = !pivot.layout || pivot.layout === "tabular";
20196
+ const blank = () => Array(width - rowLabels).fill(null);
20197
+ pivotMeasures(pivot).forEach((measure, m) => {
20198
+ const numbers3 = (keys, records) => [
20199
+ ...columnItems.map(
20200
+ (column) => pivotMeasureNumber(
20201
+ pivot,
20202
+ buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
20203
+ measure
20204
+ )
20205
+ ),
20206
+ pivotMeasureNumber(pivot, records, measure)
20207
+ ];
20208
+ if (!tabular)
20209
+ append([measure.caption, ...Array(rowLabels - 1).fill(null)], blank(), {
20210
+ indices: [m],
20211
+ measure: m
20212
+ });
20213
+ let first2 = true;
20214
+ rowItems.forEach((outer, outerIndex) => {
20215
+ const key = pivotValueKey(outer);
20216
+ const group = groups.get(key) ?? [];
20217
+ if (!tabular)
20218
+ append(
20219
+ compact ? [pivotItemLabel(outer)] : [null, pivotItemLabel(outer), null],
20220
+ top ? numbers3([key], group) : blank(),
20221
+ { indices: [m, outerIndex], measure: m },
20222
+ compact ? 1 : 0
20223
+ );
20224
+ const innerKeys = [...children2.get(key)].sort(
20225
+ (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
20226
+ );
20227
+ innerKeys.forEach((innerKey, child3) => {
20228
+ const innerIndex = innerIndices.get(innerKey);
20229
+ append(
20230
+ compact ? [pivotItemLabel(secondRowItems[innerIndex])] : [
20231
+ tabular && first2 ? measure.caption : null,
20232
+ pivot.repeatLabels || tabular && child3 === 0 ? pivotItemLabel(outer) : null,
20233
+ pivotItemLabel(secondRowItems[innerIndex])
20234
+ ],
20235
+ numbers3([key, innerKey], details.get(JSON.stringify([key, innerKey]))),
20236
+ { indices: [m, outerIndex, innerIndex], measure: m },
20237
+ compact ? 2 : 0
20238
+ );
20239
+ first2 = false;
20240
+ });
20241
+ if (bottom)
20242
+ append(
20243
+ compact ? [`${String(pivotItemLabel(outer))} Total`] : [null, `${String(pivotItemLabel(outer))} Total`, null],
20244
+ numbers3([key], group),
20245
+ { indices: [m, outerIndex], measure: m, type: "default" },
20246
+ compact ? 1 : 0
20247
+ );
20248
+ });
20249
+ });
20250
+ }
20251
+ var init_hierarchy_first = __esm({
20252
+ "xlsx/pivot/hierarchy-first.ts"() {
20253
+ init_data();
20254
+ init_measures();
20255
+ }
20256
+ });
20257
+
20258
+ // xlsx/pivot/hierarchy.ts
20259
+ function hierarchicalPivotGrid(pivot) {
20260
+ const rowItems = pivotItems(pivot, pivot.rowField);
20261
+ const secondRowItems = pivotItems(pivot, pivot.secondRowField);
20262
+ const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
20263
+ const outerField = pivot.fields.indexOf(pivot.rowField);
20264
+ const innerField = pivot.fields.indexOf(pivot.secondRowField);
20265
+ const columnField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
20266
+ const layout2 = pivot.layout ?? "tabular";
20267
+ const compact = layout2 === "compact";
20268
+ const rowsAxis = pivot.valuesAxis === "rows";
20269
+ const firstValues = rowsAxis && pivot.valuesPosition === "first";
20270
+ const between = rowsAxis && pivot.valuesPosition === "between";
20271
+ const measures = pivotMeasures(pivot);
20272
+ const top = (!rowsAxis || firstValues) && layout2 !== "tabular" && pivot.subtotals !== false && (pivot.subtotalPosition ?? "top") === "top";
20273
+ const bottom = pivot.subtotals !== false && !top;
20274
+ const rowLabelColumns = compact ? 1 : rowsAxis ? 3 : 2;
20275
+ const groups = /* @__PURE__ */ new Map();
20276
+ const details = /* @__PURE__ */ new Map();
20277
+ const children2 = /* @__PURE__ */ new Map();
20278
+ const innerIndices = new Map(secondRowItems.map((item, index2) => [pivotValueKey(item), index2]));
20279
+ const buckets = /* @__PURE__ */ new Map();
20280
+ const collect = (map, key, record) => {
20281
+ const list = map.get(key);
20282
+ if (list) list.push(record);
20283
+ else map.set(key, [record]);
20284
+ };
20285
+ for (const record of pivot.records) {
20286
+ const outer = pivotValueKey(record[outerField] ?? null);
20287
+ const inner = pivotValueKey(record[innerField] ?? null);
20288
+ collect(groups, outer, record);
20289
+ collect(details, JSON.stringify([outer, inner]), record);
20290
+ if (!children2.has(outer)) children2.set(outer, /* @__PURE__ */ new Set());
20291
+ children2.get(outer).add(inner);
20292
+ if (pivot.columnField) {
20293
+ const column = pivotValueKey(record[columnField] ?? null);
20294
+ for (const key of [[], [outer], [outer, inner]])
20295
+ collect(buckets, JSON.stringify([...key, column]), record);
20296
+ }
20297
+ }
20298
+ const dimensions = pivotHeaderDimensions(pivot, columnItems.length, rowLabelColumns);
20299
+ const rows = (details.size + rowItems.length * Number(bottom) + 1) * (rowsAxis ? measures.length : 1) + rowItems.length * Number(layout2 !== "tabular") * (firstValues ? measures.length : 1) + (firstValues ? measures.length : between ? rowItems.length * measures.length : details.size) * Number(rowsAxis && layout2 !== "tabular") + dimensions.rows;
20300
+ if (rows * dimensions.width > 1e6) throw new Error("The PivotTable result is too large.");
20301
+ const labels = compact ? ["Row Labels"] : [pivot.rowField, pivot.secondRowField];
20302
+ const values2 = pivotHeaders(pivot, columnItems, labels, label2);
20303
+ const firstDataRow = values2.length;
20304
+ const indents = values2.map(() => 0);
20305
+ const rowEntries = [];
20306
+ const append = (labels2, numbers4, entry3, indent = 0) => {
20307
+ values2.push([...labels2, ...numbers4]);
20308
+ rowEntries.push(entry3);
20309
+ indents.push(indent);
20310
+ };
20311
+ const bands = (keys, records) => [
20312
+ ...columnItems.map(
20313
+ (column) => pivotNumbers(pivot, buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [])
20314
+ ),
20315
+ pivotNumbers(pivot, records)
20316
+ ];
20317
+ const numbers3 = (keys, records) => bands(keys, records).flat();
20318
+ const appendMeasures = (labels2, keys, records, indices, type) => {
20319
+ const values3 = bands(keys, records);
20320
+ measures.forEach(
20321
+ (measure, m) => append(
20322
+ type ? [
20323
+ `${type === "grand" ? "Total" : String(labels2[0])} ${measure.caption}`,
20324
+ ...Array(rowLabelColumns - 1).fill(null)
20325
+ ] : compact ? [measure.caption] : [
20326
+ ...labels2.map(
20327
+ (label3) => layout2 === "tabular" && m === 0 || pivot.repeatLabels ? label3 : null
20328
+ ),
20329
+ measure.caption
20330
+ ],
20331
+ values3.map((band) => band[m] ?? null),
20332
+ { indices: type ? indices : [...indices, m], measure: m, ...type ? { type } : {} },
20333
+ compact && !type ? 2 : 0
20334
+ )
20335
+ );
20336
+ };
20337
+ if (firstValues)
20338
+ appendFirstPivotValues(pivot, {
20339
+ rowItems,
20340
+ secondRowItems,
20341
+ columnItems,
20342
+ children: children2,
20343
+ innerIndices,
20344
+ groups,
20345
+ details,
20346
+ buckets,
20347
+ width: dimensions.width,
20348
+ rowLabels: rowLabelColumns,
20349
+ top,
20350
+ bottom,
20351
+ append
20352
+ });
20353
+ else
20354
+ rowItems.forEach((outer, outerIndex) => {
20355
+ const key = pivotValueKey(outer);
20356
+ if (layout2 !== "tabular")
20357
+ append(
20358
+ [label2(outer), ...Array(rowLabelColumns - 1).fill(null)],
20359
+ top ? numbers3([key], groups.get(key) ?? []) : Array(dimensions.width - rowLabelColumns).fill(null),
20360
+ { indices: [outerIndex] }
20361
+ );
20362
+ let first2 = true;
20363
+ const innerKeys = [...children2.get(key)].sort(
20364
+ (a2, b) => innerIndices.get(a2) - innerIndices.get(b)
20365
+ );
20366
+ if (between)
20367
+ measures.forEach((measure, m) => {
20368
+ if (layout2 !== "tabular")
20369
+ append(
20370
+ compact ? [measure.caption] : [pivot.repeatLabels ? label2(outer) : null, measure.caption, null],
20371
+ Array(dimensions.width - rowLabelColumns).fill(null),
20372
+ { indices: [outerIndex, m], measure: m },
20373
+ compact ? 1 : 0
20374
+ );
20375
+ innerKeys.forEach((innerKey, child3) => {
20376
+ const innerIndex = innerIndices.get(innerKey);
20377
+ const keys = [key, innerKey];
20378
+ const records = details.get(JSON.stringify(keys));
20379
+ append(
20380
+ compact ? [label2(secondRowItems[innerIndex])] : [
20381
+ pivot.repeatLabels || layout2 === "tabular" && m === 0 && child3 === 0 ? label2(outer) : null,
20382
+ layout2 === "tabular" && child3 === 0 ? measure.caption : null,
20383
+ label2(secondRowItems[innerIndex])
20384
+ ],
20385
+ [
20386
+ ...columnItems.map(
20387
+ (column) => pivotMeasureNumber(
20388
+ pivot,
20389
+ buckets.get(JSON.stringify([...keys, pivotValueKey(column)])) ?? [],
20390
+ measure
20391
+ )
20392
+ ),
20393
+ pivotMeasureNumber(pivot, records, measure)
20394
+ ],
20395
+ { indices: [outerIndex, m, innerIndex], measure: m },
20396
+ compact ? 2 : 0
20397
+ );
20398
+ });
20399
+ });
20400
+ else
20401
+ innerKeys.forEach((innerKey) => {
20402
+ const innerIndex = innerIndices.get(innerKey);
20403
+ const inner = secondRowItems[innerIndex];
20404
+ const keys = [key, innerKey];
20405
+ const records = details.get(JSON.stringify(keys));
20406
+ if (!records) return;
20407
+ if (rowsAxis) {
20408
+ if (layout2 !== "tabular")
20409
+ append(
20410
+ compact ? [label2(inner)] : [pivot.repeatLabels ? label2(outer) : null, label2(inner), null],
20411
+ Array(dimensions.width - rowLabelColumns).fill(null),
20412
+ { indices: [outerIndex, innerIndex] },
20413
+ compact ? 1 : 0
20414
+ );
20415
+ appendMeasures(
20416
+ [pivot.repeatLabels || first2 ? label2(outer) : null, label2(inner)],
20417
+ keys,
20418
+ records,
20419
+ [outerIndex, innerIndex]
20420
+ );
20421
+ first2 = false;
20422
+ return;
20423
+ }
20424
+ append(
20425
+ compact ? [label2(inner)] : [
20426
+ pivot.repeatLabels || layout2 === "tabular" && first2 ? label2(outer) : null,
20427
+ label2(inner)
20428
+ ],
20429
+ numbers3(keys, records),
20430
+ { indices: [outerIndex, innerIndex] },
20431
+ compact ? 1 : 0
20432
+ );
20433
+ first2 = false;
20434
+ });
20435
+ if (bottom) {
20436
+ if (rowsAxis) {
20437
+ appendMeasures([label2(outer)], [key], groups.get(key) ?? [], [outerIndex], "default");
20438
+ return;
20439
+ }
20440
+ const caption = String(label2(outer));
20441
+ append(
20442
+ [`${caption} Total`, ...compact ? [] : [null]],
20443
+ numbers3([key], groups.get(key) ?? []),
20444
+ { indices: [outerIndex], type: "default" }
20445
+ );
20446
+ }
20447
+ });
20448
+ if (rowsAxis) appendMeasures([], [], pivot.records, [0], "grand");
20449
+ else
20450
+ append(["Grand Total", ...compact ? [] : [null]], numbers3([], pivot.records), {
20451
+ indices: [0],
20452
+ type: "grand"
20453
+ });
20454
+ return {
20455
+ values: values2,
20456
+ rowItems,
20457
+ secondRowItems,
20458
+ columnItems,
20459
+ rowEntries,
20460
+ firstDataRow,
20461
+ rowLabelColumns,
20462
+ indents,
20463
+ ...rowsAxis ? { firstHeaderRow: 1 } : {}
20464
+ };
20465
+ }
20466
+ var label2;
20467
+ var init_hierarchy2 = __esm({
20468
+ "xlsx/pivot/hierarchy.ts"() {
20469
+ init_data();
20470
+ init_hierarchy_first();
20471
+ init_measures();
20472
+ label2 = pivotItemLabel;
20473
+ }
20474
+ });
20475
+
20476
+ // xlsx/pivot/aggregate.ts
20477
+ function pivotGrid(pivot) {
20478
+ validatePivotFields(pivot);
20479
+ if (pivot.secondRowField) return hierarchicalPivotGrid(pivot);
20480
+ const rowItems = pivotItems(pivot, pivot.rowField);
20481
+ const columnItems = pivot.columnField ? pivotItems(pivot, pivot.columnField) : [];
20482
+ const rowsAxis = pivot.valuesAxis === "rows";
20483
+ const compact = pivot.layout === "compact";
20484
+ const headings = rowsAxis && pivot.layout !== void 0 && pivot.layout !== "tabular";
20485
+ const dimensions = pivotHeaderDimensions(pivot, columnItems.length, rowsAxis && !compact ? 2 : 1);
20486
+ const dataRows = (rowItems.length + 1) * (rowsAxis ? 1 + (pivot.additionalValues?.length ?? 0) : 1) + (headings ? rowItems.length : 0);
20487
+ if ((dataRows + dimensions.rows) * dimensions.width > 1e6)
20488
+ throw new Error("The PivotTable result is too large.");
20489
+ const label3 = pivotItemLabel;
20490
+ const values2 = pivotHeaders(
20491
+ pivot,
20492
+ columnItems,
20493
+ [pivot.layout === "compact" ? "Row Labels" : pivot.rowField],
20494
+ label3
20495
+ );
20496
+ const rowField = pivot.fields.indexOf(pivot.rowField);
20497
+ const colField = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
20498
+ const groups = /* @__PURE__ */ new Map();
20499
+ const cells2 = /* @__PURE__ */ new Map();
20500
+ const columns = /* @__PURE__ */ new Map();
20501
+ const collect = (map, key, record) => {
20502
+ const found = map.get(key);
20503
+ if (found) found.push(record);
20504
+ else map.set(key, [record]);
20505
+ };
20506
+ for (const record of pivot.records) {
20507
+ const key = pivotValueKey(record[rowField] ?? null);
20508
+ collect(groups, key, record);
20509
+ if (pivot.columnField) {
20510
+ const col = pivotValueKey(record[colField] ?? null);
20511
+ collect(columns, col, record);
20512
+ collect(cells2, JSON.stringify([key, col]), record);
20513
+ }
20514
+ }
20515
+ const firstDataRow = values2.length;
20516
+ if (rowsAxis) {
20517
+ const measures = pivotMeasures(pivot);
20518
+ const rowEntries = [];
20519
+ const indents = values2.map(() => 0);
20520
+ const append = (caption, bands, index2, grand = false) => {
20521
+ measures.forEach((measure, m) => {
20522
+ values2.push([
20523
+ ...compact ? [grand ? `Total ${measure.caption}` : measure.caption] : [
20524
+ grand ? `Total ${measure.caption}` : pivot.repeatLabels || !headings && m === 0 ? caption : null,
20525
+ grand ? null : measure.caption
20526
+ ],
20527
+ ...bands.map((band) => band[m] ?? null)
20528
+ ]);
20529
+ indents.push(compact && !grand ? 1 : 0);
20530
+ rowEntries.push({
20531
+ indices: grand ? [0] : [index2, m],
20532
+ measure: m,
20533
+ ...grand ? { type: "grand" } : {}
20534
+ });
20535
+ });
20536
+ };
20537
+ rowItems.forEach((item, index2) => {
20538
+ const key = pivotValueKey(item);
20539
+ if (headings) {
20540
+ values2.push([label3(item), ...Array(dimensions.width - 1).fill(null)]);
20541
+ rowEntries.push({ indices: [index2] });
20542
+ indents.push(0);
20543
+ }
20544
+ append(
20545
+ label3(item),
20546
+ [
20547
+ ...columnItems.map(
20548
+ (col) => pivotNumbers(pivot, cells2.get(JSON.stringify([key, pivotValueKey(col)])) ?? [])
20549
+ ),
20550
+ pivotNumbers(pivot, groups.get(key) ?? [])
20551
+ ],
20552
+ index2
20553
+ );
20554
+ });
20555
+ append(
20556
+ "Grand Total",
20557
+ [
20558
+ ...columnItems.map((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
20559
+ pivotNumbers(pivot, pivot.records)
20560
+ ],
20561
+ 0,
20562
+ true
20563
+ );
20564
+ return {
20565
+ values: values2,
20566
+ rowItems,
20567
+ columnItems,
20568
+ firstDataRow,
20569
+ rowLabelColumns: compact ? 1 : 2,
20570
+ indents,
20571
+ firstHeaderRow: 1,
20572
+ rowEntries
20573
+ };
20574
+ }
20575
+ for (const row2 of rowItems) {
20576
+ const records = groups.get(pivotValueKey(row2)) ?? [];
20577
+ values2.push([
20578
+ label3(row2),
20579
+ ...columnItems.flatMap(
20580
+ (col) => pivotNumbers(
20581
+ pivot,
20582
+ cells2.get(JSON.stringify([pivotValueKey(row2), pivotValueKey(col)])) ?? []
20583
+ )
20584
+ ),
20585
+ ...pivotNumbers(pivot, records)
20586
+ ]);
20587
+ }
20588
+ values2.push([
20589
+ "Grand Total",
20590
+ ...columnItems.flatMap((col) => pivotNumbers(pivot, columns.get(pivotValueKey(col)) ?? [])),
20591
+ ...pivotNumbers(pivot, pivot.records)
20592
+ ]);
20593
+ return { values: values2, rowItems, columnItems, firstDataRow };
20594
+ }
20595
+ var init_aggregate = __esm({
20596
+ "xlsx/pivot/aggregate.ts"() {
20597
+ init_data();
20598
+ init_hierarchy2();
20599
+ init_measures();
20600
+ }
20601
+ });
20602
+
20603
+ // xlsx/pivot/values-axis.ts
20604
+ function pivotValueAxisItems(measures, columns) {
20605
+ const entries = [];
20606
+ if (columns === void 0) {
20607
+ for (let measure = 0; measure < measures; measure++)
20608
+ entries.push(
20609
+ `<i${attrs({ i: measure || void 0 })}><x${attrs({ v: measure || void 0 })}/></i>`
20610
+ );
20611
+ } else {
20612
+ for (let column = 0; column < columns; column++)
20613
+ for (let measure = 0; measure < measures; measure++) {
20614
+ entries.push(
20615
+ `<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>`
20616
+ );
20617
+ }
20618
+ for (let measure = 0; measure < measures; measure++)
20619
+ entries.push(`<i${attrs({ t: "grand", i: measure || void 0 })}><x/></i>`);
20620
+ }
20621
+ return `<colItems count="${entries.length}">${entries.join("")}</colItems>`;
20622
+ }
20623
+ var init_values_axis = __esm({
20624
+ "xlsx/pivot/values-axis.ts"() {
20625
+ init_xml_out();
20626
+ }
20627
+ });
20628
+
20629
+ // xlsx/pivot/table-xml.ts
20630
+ function pivotTableXml(pivot, cacheId, cache2) {
20631
+ const grid = pivotGrid(pivot);
20632
+ const row2 = pivot.fields.indexOf(pivot.rowField);
20633
+ const second = pivot.secondRowField ? pivot.fields.indexOf(pivot.secondRowField) : -1;
20634
+ const col = pivot.columnField ? pivot.fields.indexOf(pivot.columnField) : -1;
20635
+ const measures = pivotMeasures(pivot);
20636
+ const multiple = measures.length > 1;
20637
+ const rowsAxis = pivot.valuesAxis === "rows";
20638
+ const compact = pivot.layout === "compact";
20639
+ const outline = pivot.layout === "compact" || pivot.layout === "outline";
20640
+ const top = (pivot.subtotalPosition ?? (outline ? "top" : "bottom")) === "top";
20641
+ const fields = pivot.fields.map((_field, index2) => {
20642
+ const items2 = index2 === row2 ? grid.rowItems : index2 === second ? grid.secondRowItems : index2 === col ? grid.columnItems : void 0;
20643
+ const subtotal = !(index2 === row2 && pivot.subtotals === false);
20644
+ 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>' : "";
20645
+ 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>`;
20646
+ }).join("");
20647
+ const items = (count2) => Array.from({ length: count2 }, (_v, i) => `<i><x v="${i}"/></i>`).join("") + '<i t="grand"><x/></i>';
20648
+ const header = grid.firstHeaderRow ?? (multiple && col >= 0 ? 1 : grid.firstDataRow - 1);
20649
+ const rowIndices = rowsAxis && pivot.valuesPosition === "first" ? [-2, row2, second] : rowsAxis && pivot.valuesPosition === "between" ? [row2, -2, second] : [row2, ...second >= 0 ? [second] : [], ...rowsAxis ? [-2] : []];
20650
+ let previous = [];
20651
+ const rowItems = grid.rowEntries?.map((entry3) => {
20652
+ let prefix = 0;
20653
+ if (entry3.type === "default" && rowsAxis && pivot.valuesPosition === "first") prefix = 1;
20654
+ else if (!entry3.type)
20655
+ while (prefix < entry3.indices.length - 1 && entry3.indices[prefix] === previous[prefix])
20656
+ prefix++;
20657
+ previous = entry3.type && !(entry3.type === "default" && pivot.valuesPosition === "first") ? [] : entry3.indices;
20658
+ 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>`;
20659
+ }).join("") ?? items(grid.rowItems.length);
20660
+ 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>`;
20661
+ if (multiple && !rowsAxis)
20662
+ 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)}`;
20663
+ else if (col >= 0)
20664
+ body += `<colFields count="1"><field x="${col}"/></colFields><colItems count="${grid.columnItems.length + 1}">${items(grid.columnItems.length)}</colItems>`;
20665
+ else
20666
+ body += rowsAxis ? '<colItems count="1"><i/></colItems>' : '<colItems count="1"><i><x/></i></colItems>';
20667
+ 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>`;
20668
+ const doc = parseXml(
20669
+ 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>`
20670
+ );
20671
+ const root = doc.documentElement;
20672
+ root.setAttribute("name", pivot.name);
20673
+ root.setAttribute("cacheId", String(cacheId));
20674
+ root.setAttribute("dataOnRows", rowsAxis ? "1" : "0");
20675
+ if (rowsAxis && (pivot.valuesPosition === "between" || pivot.valuesPosition === "first"))
20676
+ root.setAttribute("dataPosition", pivot.valuesPosition === "first" ? "0" : "1");
20677
+ else root.removeAttribute("dataPosition");
20678
+ root.setAttribute("compact", compact ? "1" : "0");
20679
+ root.setAttribute("compactData", compact ? "1" : "0");
20680
+ root.setAttribute("outline", outline ? "1" : "0");
20681
+ root.setAttribute("outlineData", outline ? "1" : "0");
20682
+ if (compact) root.setAttribute("indent", "0");
20683
+ if (multiple && !elements(first(root, "extLst", NS.x) ?? parseXml("<root/>").documentElement).some(
20684
+ (extension) => first(
20685
+ extension,
20686
+ "pivotTableDefinition",
20687
+ "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
20688
+ )
20689
+ )) {
20690
+ let list = first(root, "extLst", NS.x);
20691
+ if (!list) {
20692
+ list = doc.createElementNS(NS.x, "extLst");
20693
+ root.appendChild(list);
20694
+ }
20695
+ const extension = parseXml(
20696
+ `<ext xmlns="${NS.x}" uri="{962EF5D1-5CA2-4c93-8EF4-DBF5C05439D2}"><x14:pivotTableDefinition xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" hideValuesRow="1"/></ext>`
20697
+ ).documentElement;
20698
+ list.appendChild(doc.importNode(extension, true));
20699
+ }
20700
+ root.setAttribute("rowGrandTotals", "1");
20701
+ root.setAttribute("colGrandTotals", "1");
20702
+ for (const extension of elements(
20703
+ first(root, "extLst", NS.x) ?? parseXml("<root/>").documentElement
20704
+ )) {
20705
+ const definition = first(
20706
+ extension,
20707
+ "pivotTableDefinition",
20708
+ "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"
20709
+ );
20710
+ if (multiple && definition) definition.setAttribute("hideValuesRow", "1");
20711
+ if (definition?.hasAttribute("fillDownLabelsDefault"))
20712
+ definition.setAttribute("fillDownLabelsDefault", pivot.repeatLabels ? "1" : "0");
20713
+ }
20714
+ const replaced = /* @__PURE__ */ new Set([
20715
+ "location",
20716
+ "pivotFields",
20717
+ "rowFields",
20718
+ "rowItems",
20719
+ "colFields",
20720
+ "colItems",
20721
+ "dataFields"
20722
+ ]);
20723
+ for (const child3 of elements(root)) if (replaced.has(child3.localName)) root.removeChild(child3);
20724
+ const replacement = parseXml(`<root xmlns="${NS.x}">${body}</root>`).documentElement;
20725
+ const before = root.firstChild;
20726
+ for (const child3 of elements(replacement)) root.insertBefore(doc.importNode(child3, true), before);
20727
+ return XML_HEADER + buildXml(root);
20728
+ }
20729
+ var init_table_xml = __esm({
20730
+ "xlsx/pivot/table-xml.ts"() {
20731
+ init_xml2();
20732
+ init_address();
20733
+ init_xml_out();
20734
+ init_aggregate();
20735
+ init_data();
20736
+ init_measures();
20737
+ init_values_axis();
20738
+ }
20739
+ });
20740
+
20741
+ // xlsx/pivot/write.ts
20742
+ var TYPES, PivotWritePlan;
20743
+ var init_write = __esm({
20744
+ "xlsx/pivot/write.ts"() {
20745
+ init_opc();
20746
+ init_xml2();
20747
+ init_xml_util();
20748
+ init_package_writer();
20749
+ init_drawing();
20750
+ init_cache_xml();
20751
+ init_table_xml();
20752
+ TYPES = {
20753
+ table: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",
20754
+ definition: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",
20755
+ records: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"
20756
+ };
20757
+ PivotWritePlan = class {
20758
+ tableParts = /* @__PURE__ */ new Map();
20759
+ cachesXml;
20760
+ constructor(writer, workbook, source2, bookPart, bookRels, reserved) {
20761
+ const sourceCaches = source2?.text(bookPart) ? children(
20762
+ first(parseXml(source2.text(bookPart)).documentElement, "pivotCaches", NS.x) ?? parseXml("<root/>").documentElement,
20763
+ "pivotCache",
20764
+ NS.x
20765
+ ) : [];
20766
+ const retained = /* @__PURE__ */ new Set();
20767
+ const owns = workbook.sheets.some((sheet) => sheet.pivotTables !== void 0);
20768
+ for (const sheet of workbook.sheets)
20769
+ if (source2 && sheet.partName)
20770
+ for (const rel of source2.rels(sheet.partName).values()) {
20771
+ if (rel.type !== RELATIONSHIP_TYPES.pivotTable) continue;
20772
+ const part = source2.target(sheet.partName, rel);
20773
+ if (!part) continue;
20774
+ const pivot = sheet.pivotTables?.find((entry3) => entry3.partName === part);
20775
+ if (pivot?.dirty || !pivot && sheet.preserved.get("source:pivotTables")?.includes(part))
20776
+ continue;
20777
+ const xml = source2.text(part);
20778
+ if (xml) retained.add(Number(parseXml(xml).documentElement.getAttribute("cacheId")));
20779
+ }
20780
+ const entries = [];
20781
+ for (const node of sourceCaches) {
20782
+ const id = Number(node.getAttribute("cacheId"));
20783
+ if (owns && !retained.has(id)) continue;
20784
+ const rid = relAttr(node, "id");
20785
+ const rel = rid && source2?.rels(bookPart).get(rid);
20786
+ const part = rel && source2?.target(bookPart, rel);
20787
+ if (rel && rid && part) {
20788
+ bookRels.keep(rid, rel);
20789
+ writer.carry(part);
20790
+ entries.push(selfContainedXml(node));
20791
+ }
20792
+ }
20793
+ let cacheId = Math.max(
20794
+ -1,
20795
+ ...sourceCaches.map((node) => Number(node.getAttribute("cacheId"))).filter((id) => Number.isInteger(id) && id >= 0)
20796
+ ) + 1;
20797
+ for (const sheet of workbook.sheets)
20798
+ for (const pivot of sheet.pivotTables ?? []) {
20799
+ if (pivot.partName && !pivot.dirty) {
20800
+ this.tableParts.set(pivot, pivot.partName);
20801
+ continue;
20802
+ }
20803
+ const table2 = pivot.partName ?? writer.uniqueName((n) => `xl/pivotTables/pivotTable${n}.xml`, reserved);
20804
+ const definition = writer.uniqueName(
20805
+ (n) => `xl/pivotCache/pivotCacheDefinition${n}.xml`,
20806
+ reserved
20807
+ );
20808
+ const records = writer.uniqueName(
20809
+ (n) => `xl/pivotCache/pivotCacheRecords${n}.xml`,
20810
+ reserved
20811
+ );
20812
+ const cache2 = pivotCacheData(pivot);
20813
+ const cacheRels = new RelationshipSet();
20814
+ const recordRel = cacheRels.add(
20815
+ `${NS.r}/pivotCacheRecords`,
20816
+ relativeTarget(definition, records)
20817
+ );
20818
+ writer.add(records, pivotCacheRecordsXml(pivot, cache2), TYPES.records);
20819
+ writer.add(
20820
+ definition,
20821
+ pivotCacheDefinitionXml(pivot, workbook, cache2, recordRel),
20822
+ TYPES.definition
20823
+ );
20824
+ writer.rels(definition, cacheRels);
20825
+ writer.add(table2, pivotTableXml(pivot, cacheId, cache2), TYPES.table);
20826
+ const tableRels = new RelationshipSet();
20827
+ tableRels.add(RELATIONSHIP_TYPES.pivotCacheDefinition, relativeTarget(table2, definition));
20828
+ writer.rels(table2, tableRels);
20829
+ const rid = bookRels.add(
20830
+ RELATIONSHIP_TYPES.pivotCacheDefinition,
20831
+ relativeTarget(bookPart, definition)
20832
+ );
20833
+ entries.push(`<pivotCache cacheId="${cacheId++}" r:id="${rid}"/>`);
20834
+ this.tableParts.set(pivot, table2);
20835
+ }
20836
+ this.cachesXml = owns ? entries.length ? `<pivotCaches>${entries.join("")}</pivotCaches>` : "" : void 0;
20837
+ }
20838
+ writeSheet(writer, sheet, part, rels) {
20839
+ for (const pivot of sheet.pivotTables ?? []) {
20840
+ const table2 = this.tableParts.get(pivot);
20841
+ writer.carry(table2);
20842
+ rels.add(RELATIONSHIP_TYPES.pivotTable, relativeTarget(part, table2));
20843
+ }
20844
+ }
20845
+ };
20846
+ }
20847
+ });
20848
+
19921
20849
  // xlsx/write/save.ts
19922
20850
  async function saveXlsx(workbook) {
19923
20851
  if (!workbook.sheets.length) throw new Error("A workbook needs at least one sheet");
@@ -19960,6 +20888,7 @@ async function saveXlsx(workbook) {
19960
20888
  if (target) writer.carry(target);
19961
20889
  }
19962
20890
  }
20891
+ ctx.pivots = new PivotWritePlan(writer, workbook, source2, bookPart, rels, reserved);
19963
20892
  const states = workbook.sheets.map((sheet) => sheet.state);
19964
20893
  if (!states.includes("visible")) states[0] = "visible";
19965
20894
  let activeTab = Math.min(Math.max(0, workbook.activeSheet), workbook.sheets.length - 1);
@@ -20025,7 +20954,7 @@ async function saveXlsx(workbook) {
20025
20954
  const sourceXml = sourceBook ? source2?.text(sourceBook) : void 0;
20026
20955
  writer.add(
20027
20956
  bookPart,
20028
- workbookXml(workbook, sheetRefs, Math.max(0, activeTab), sourceXml),
20957
+ workbookXml(workbook, sheetRefs, Math.max(0, activeTab), sourceXml, ctx.pivots.cachesXml),
20029
20958
  keptVba ? CONTENT_TYPES.workbookMacro : CONTENT_TYPES.workbook
20030
20959
  );
20031
20960
  writer.rels(bookPart, rels);
@@ -20068,6 +20997,7 @@ var init_save = __esm({
20068
20997
  init_doc_props();
20069
20998
  init_workbook_part2();
20070
20999
  init_worksheet2();
21000
+ init_write();
20071
21001
  REGENERATED2 = /* @__PURE__ */ new Set([
20072
21002
  RELATIONSHIP_TYPES.worksheet,
20073
21003
  RELATIONSHIP_TYPES.chartsheet,
@@ -20078,7 +21008,8 @@ var init_save = __esm({
20078
21008
  RELATIONSHIP_TYPES.theme,
20079
21009
  RELATIONSHIP_TYPES.calcChain,
20080
21010
  RELATIONSHIP_TYPES.person,
20081
- RELATIONSHIP_TYPES.sheetMetadata
21011
+ RELATIONSHIP_TYPES.sheetMetadata,
21012
+ RELATIONSHIP_TYPES.pivotCacheDefinition
20082
21013
  ]);
20083
21014
  SHEET_TYPES = {
20084
21015
  [CONTENT_TYPES.chartsheet]: RELATIONSHIP_TYPES.chartsheet,
@@ -20098,7 +21029,7 @@ var write_exports = {};
20098
21029
  __export(write_exports, {
20099
21030
  saveXlsx: () => saveXlsx
20100
21031
  });
20101
- var init_write = __esm({
21032
+ var init_write2 = __esm({
20102
21033
  "xlsx/write/index.ts"() {
20103
21034
  init_save();
20104
21035
  }
@@ -21613,7 +22544,7 @@ function createFileActions(context) {
21613
22544
  checkFileAbort(options?.signal);
21614
22545
  const [{ createWorkbook: createWorkbook2 }, { saveXlsx: saveXlsx2 }] = await Promise.all([
21615
22546
  Promise.resolve().then(() => (init_workbook(), workbook_exports)),
21616
- Promise.resolve().then(() => (init_write(), write_exports))
22547
+ Promise.resolve().then(() => (init_write2(), write_exports))
21617
22548
  ]);
21618
22549
  checkFileAbort(options?.signal);
21619
22550
  const bytes = await withFileAbort(() => saveXlsx2(createWorkbook2()), options?.signal);