ooxml-core 1.50.2 → 1.51.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 (361) hide show
  1. package/README.md +11 -0
  2. package/dist/{PptxHandler-PVQW47CY.mjs → PptxHandler-6GRVJRHP.mjs} +2 -2
  3. package/dist/PptxHandler-E6QYPF7X.mjs +8 -0
  4. package/dist/PptxHandler-UNQVCIGM.cjs +17 -0
  5. package/dist/PresentationBuilder-DVDJSV5R.mjs +8 -0
  6. package/dist/PresentationBuilder-F5UWRF6H.cjs +25 -0
  7. package/dist/{PresentationBuilder-ZOOVSBPR.mjs → PresentationBuilder-T6YKWPF7.mjs} +2 -2
  8. package/dist/automation/index.cjs +5806 -4494
  9. package/dist/automation/index.mjs +5806 -4494
  10. package/dist/chunk-25IJEN7R.cjs +36 -0
  11. package/dist/chunk-25JN3ZQM.mjs +58 -0
  12. package/dist/{chunk-7XYVFUB3.cjs → chunk-2IO523MM.cjs} +1 -0
  13. package/dist/{chunk-53KMIHYN.mjs → chunk-4LUZHBTT.mjs} +83 -31
  14. package/dist/chunk-554UZLPS.mjs +237 -0
  15. package/dist/{chunk-VLKUMQGT.mjs → chunk-63RAF3TS.mjs} +1 -1
  16. package/dist/{chunk-7UM5IFPR.mjs → chunk-6IUYKP77.mjs} +1 -1
  17. package/dist/{chunk-VK2G4BGX.mjs → chunk-BIMV5FVL.mjs} +481 -193
  18. package/dist/{chunk-CODMW5KF.cjs → chunk-CVUMILG3.cjs} +1 -0
  19. package/dist/{chunk-NBMXEVHL.mjs → chunk-FX6WL42B.mjs} +1 -0
  20. package/dist/chunk-GI4Y6BBX.mjs +21 -0
  21. package/dist/{chunk-MX2GFMZS.mjs → chunk-GZL4ERW3.mjs} +1 -1
  22. package/dist/chunk-HWL2AGLD.cjs +98 -0
  23. package/dist/chunk-HZAB3YDO.cjs +234 -0
  24. package/dist/chunk-IDATIFCG.mjs +226 -0
  25. package/dist/chunk-LO55N7VL.cjs +247 -0
  26. package/dist/{chunk-FFLU4LUQ.cjs → chunk-LUBPW5NP.cjs} +1629 -1609
  27. package/dist/chunk-MUNEIE2J.cjs +62 -0
  28. package/dist/{chunk-ZCKEKP7N.mjs → chunk-RYUADJV6.mjs} +4 -4
  29. package/dist/chunk-TOBK5FC4.mjs +88 -0
  30. package/dist/chunk-UV4LMGVZ.mjs +31 -0
  31. package/dist/{chunk-O3YGBYGZ.mjs → chunk-VRVHM6TJ.mjs} +1 -0
  32. package/dist/chunk-W7LVJC32.cjs +25 -0
  33. package/dist/chunk-WAZ7T2BL.cjs +169 -0
  34. package/dist/{chunk-3OKY56UM.mjs → chunk-YX33WEKS.mjs} +411 -391
  35. package/dist/docx/auto-number-fields.d.ts +22 -0
  36. package/dist/docx/auto-number-fields.d.ts.map +1 -0
  37. package/dist/docx/block-parser.d.ts.map +1 -1
  38. package/dist/docx/character-styles.d.ts.map +1 -1
  39. package/dist/docx/clipboard/css.d.ts +21 -0
  40. package/dist/docx/clipboard/css.d.ts.map +1 -0
  41. package/dist/docx/clipboard/html-tokens.d.ts +38 -0
  42. package/dist/docx/clipboard/html-tokens.d.ts.map +1 -0
  43. package/dist/docx/clipboard/index.d.ts +6 -0
  44. package/dist/docx/clipboard/index.d.ts.map +1 -0
  45. package/dist/docx/clipboard/word-fields.d.ts +13 -0
  46. package/dist/docx/clipboard/word-fields.d.ts.map +1 -0
  47. package/dist/docx/clipboard/word-fragment.d.ts +14 -0
  48. package/dist/docx/clipboard/word-fragment.d.ts.map +1 -0
  49. package/dist/docx/clipboard/word-html.d.ts +22 -0
  50. package/dist/docx/clipboard/word-html.d.ts.map +1 -0
  51. package/dist/docx/clipboard/word-list-scan.d.ts +25 -0
  52. package/dist/docx/clipboard/word-list-scan.d.ts.map +1 -0
  53. package/dist/docx/clipboard/word-lists.d.ts +13 -0
  54. package/dist/docx/clipboard/word-lists.d.ts.map +1 -0
  55. package/dist/docx/clipboard/word-runs.d.ts +18 -0
  56. package/dist/docx/clipboard/word-runs.d.ts.map +1 -0
  57. package/dist/docx/clipboard/word-styles.d.ts +35 -0
  58. package/dist/docx/clipboard/word-styles.d.ts.map +1 -0
  59. package/dist/docx/compare/build.d.ts +48 -0
  60. package/dist/docx/compare/build.d.ts.map +1 -0
  61. package/dist/docx/compare/compare.d.ts +18 -0
  62. package/dist/docx/compare/compare.d.ts.map +1 -0
  63. package/dist/docx/compare/context.d.ts +42 -0
  64. package/dist/docx/compare/context.d.ts.map +1 -0
  65. package/dist/docx/compare/diff.d.ts +20 -0
  66. package/dist/docx/compare/diff.d.ts.map +1 -0
  67. package/dist/docx/compare/index.d.ts +4 -0
  68. package/dist/docx/compare/index.d.ts.map +1 -0
  69. package/dist/docx/compare/slide.d.ts +9 -0
  70. package/dist/docx/compare/slide.d.ts.map +1 -0
  71. package/dist/docx/compare/spans.d.ts +13 -0
  72. package/dist/docx/compare/spans.d.ts.map +1 -0
  73. package/dist/docx/compare/story.d.ts +7 -0
  74. package/dist/docx/compare/story.d.ts.map +1 -0
  75. package/dist/docx/compare/table.d.ts +23 -0
  76. package/dist/docx/compare/table.d.ts.map +1 -0
  77. package/dist/docx/compare/tokens.d.ts +50 -0
  78. package/dist/docx/compare/tokens.d.ts.map +1 -0
  79. package/dist/docx/compare/types.d.ts +51 -0
  80. package/dist/docx/compare/types.d.ts.map +1 -0
  81. package/dist/docx/compatibility.d.ts +46 -0
  82. package/dist/docx/compatibility.d.ts.map +1 -0
  83. package/dist/docx/computed-fields.d.ts +39 -0
  84. package/dist/docx/computed-fields.d.ts.map +1 -0
  85. package/dist/docx/doc-property-field.d.ts +17 -0
  86. package/dist/docx/doc-property-field.d.ts.map +1 -0
  87. package/dist/docx/document-parts.d.ts +2 -0
  88. package/dist/docx/document-parts.d.ts.map +1 -1
  89. package/dist/docx/drawing-wrap.d.ts +21 -0
  90. package/dist/docx/drawing-wrap.d.ts.map +1 -0
  91. package/dist/docx/drawing.d.ts.map +1 -1
  92. package/dist/docx/embedded.cjs +3965 -2313
  93. package/dist/docx/embedded.mjs +3965 -2313
  94. package/dist/docx/field-format.d.ts +45 -0
  95. package/dist/docx/field-format.d.ts.map +1 -0
  96. package/dist/docx/field-result-spans.d.ts +62 -0
  97. package/dist/docx/field-result-spans.d.ts.map +1 -0
  98. package/dist/docx/field-runs.d.ts.map +1 -1
  99. package/dist/docx/field-stories.d.ts +9 -0
  100. package/dist/docx/field-stories.d.ts.map +1 -0
  101. package/dist/docx/find-stories.d.ts +27 -0
  102. package/dist/docx/find-stories.d.ts.map +1 -0
  103. package/dist/docx/highlight.d.ts +19 -0
  104. package/dist/docx/highlight.d.ts.map +1 -1
  105. package/dist/docx/hyperlink.d.ts +7 -0
  106. package/dist/docx/hyperlink.d.ts.map +1 -1
  107. package/dist/docx/index.cjs +7359 -3476
  108. package/dist/docx/index.d.ts +13 -1
  109. package/dist/docx/index.d.ts.map +1 -1
  110. package/dist/docx/index.mjs +7327 -3476
  111. package/dist/docx/inline-model.d.ts +21 -0
  112. package/dist/docx/inline-model.d.ts.map +1 -1
  113. package/dist/docx/inline-slots.d.ts.map +1 -1
  114. package/dist/docx/inspect-document.d.ts +21 -0
  115. package/dist/docx/inspect-document.d.ts.map +1 -0
  116. package/dist/docx/kinsoku-settings.d.ts +9 -0
  117. package/dist/docx/kinsoku-settings.d.ts.map +1 -0
  118. package/dist/docx/layout/adapt-table-floating.d.ts +11 -0
  119. package/dist/docx/layout/adapt-table-floating.d.ts.map +1 -0
  120. package/dist/docx/layout/adapt-table.d.ts.map +1 -1
  121. package/dist/docx/layout/adapter.d.ts.map +1 -1
  122. package/dist/docx/layout/computed-field-runs.d.ts +8 -0
  123. package/dist/docx/layout/computed-field-runs.d.ts.map +1 -0
  124. package/dist/docx/layout/floats.d.ts +3 -1
  125. package/dist/docx/layout/floats.d.ts.map +1 -1
  126. package/dist/docx/layout/flow-floating-table.d.ts +13 -0
  127. package/dist/docx/layout/flow-floating-table.d.ts.map +1 -0
  128. package/dist/docx/layout/flow-table.d.ts +1 -1
  129. package/dist/docx/layout/flow-table.d.ts.map +1 -1
  130. package/dist/docx/layout/index.cjs +2280 -941
  131. package/dist/docx/layout/index.mjs +2276 -942
  132. package/dist/docx/layout/input.d.ts +50 -0
  133. package/dist/docx/layout/input.d.ts.map +1 -1
  134. package/dist/docx/layout/layout.d.ts.map +1 -1
  135. package/dist/docx/layout/page-cursor.d.ts.map +1 -1
  136. package/dist/docx/layout/page-flow.d.ts.map +1 -1
  137. package/dist/docx/layout/paragraph-layout.d.ts.map +1 -1
  138. package/dist/docx/layout/paragraph-tokens.d.ts +6 -0
  139. package/dist/docx/layout/paragraph-tokens.d.ts.map +1 -1
  140. package/dist/docx/layout/result.d.ts +12 -0
  141. package/dist/docx/layout/result.d.ts.map +1 -1
  142. package/dist/docx/layout/section-flow.d.ts.map +1 -1
  143. package/dist/docx/layout/table-autofit-distribute.d.ts +18 -0
  144. package/dist/docx/layout/table-autofit-distribute.d.ts.map +1 -0
  145. package/dist/docx/layout/table-autofit-measure.d.ts +15 -0
  146. package/dist/docx/layout/table-autofit-measure.d.ts.map +1 -0
  147. package/dist/docx/layout/table-autofit.d.ts +10 -0
  148. package/dist/docx/layout/table-autofit.d.ts.map +1 -0
  149. package/dist/docx/layout/table-cell-layout.d.ts.map +1 -1
  150. package/dist/docx/layout/text-breaks.d.ts +38 -13
  151. package/dist/docx/layout/text-breaks.d.ts.map +1 -1
  152. package/dist/docx/layout/wrap.d.ts +1 -1
  153. package/dist/docx/layout/wrap.d.ts.map +1 -1
  154. package/dist/docx/list-number-fields.d.ts +25 -0
  155. package/dist/docx/list-number-fields.d.ts.map +1 -0
  156. package/dist/docx/load/index.cjs +4355 -2703
  157. package/dist/docx/load/index.mjs +4355 -2703
  158. package/dist/docx/model-paragraph.d.ts +12 -1
  159. package/dist/docx/model-paragraph.d.ts.map +1 -1
  160. package/dist/docx/model.d.ts +26 -1
  161. package/dist/docx/model.d.ts.map +1 -1
  162. package/dist/docx/note-convert.d.ts +45 -0
  163. package/dist/docx/note-convert.d.ts.map +1 -0
  164. package/dist/docx/numbering-counters.d.ts +17 -0
  165. package/dist/docx/numbering-counters.d.ts.map +1 -0
  166. package/dist/docx/numbering-format.d.ts +11 -2
  167. package/dist/docx/numbering-format.d.ts.map +1 -1
  168. package/dist/docx/outline-numbering.d.ts +6 -0
  169. package/dist/docx/outline-numbering.d.ts.map +1 -0
  170. package/dist/docx/package-information-save.d.ts +9 -0
  171. package/dist/docx/package-information-save.d.ts.map +1 -0
  172. package/dist/docx/package-information.d.ts +43 -0
  173. package/dist/docx/package-information.d.ts.map +1 -0
  174. package/dist/docx/package-properties.d.ts +5 -0
  175. package/dist/docx/package-properties.d.ts.map +1 -0
  176. package/dist/docx/paragraph-styles.d.ts +2 -0
  177. package/dist/docx/paragraph-styles.d.ts.map +1 -1
  178. package/dist/docx/parse-revisions.d.ts +2 -0
  179. package/dist/docx/parse-revisions.d.ts.map +1 -1
  180. package/dist/docx/parse-table-floating.d.ts +5 -0
  181. package/dist/docx/parse-table-floating.d.ts.map +1 -0
  182. package/dist/docx/parse-table.d.ts.map +1 -1
  183. package/dist/docx/parse.d.ts.map +1 -1
  184. package/dist/docx/part-relationships.d.ts.map +1 -1
  185. package/dist/docx/personal-information.d.ts +18 -0
  186. package/dist/docx/personal-information.d.ts.map +1 -0
  187. package/dist/docx/picture-crop-edit.d.ts +18 -0
  188. package/dist/docx/picture-crop-edit.d.ts.map +1 -0
  189. package/dist/docx/picture-watermark.d.ts +29 -0
  190. package/dist/docx/picture-watermark.d.ts.map +1 -0
  191. package/dist/docx/relationship-allocator.d.ts.map +1 -1
  192. package/dist/docx/remove-document-information.d.ts +8 -0
  193. package/dist/docx/remove-document-information.d.ts.map +1 -0
  194. package/dist/docx/revision-commands.d.ts +6 -1
  195. package/dist/docx/revision-commands.d.ts.map +1 -1
  196. package/dist/docx/revision-ids.d.ts.map +1 -1
  197. package/dist/docx/run-language.d.ts +9 -0
  198. package/dist/docx/run-language.d.ts.map +1 -0
  199. package/dist/docx/run-properties-snapshot.d.ts +9 -0
  200. package/dist/docx/run-properties-snapshot.d.ts.map +1 -0
  201. package/dist/docx/run-style-model.d.ts +4 -0
  202. package/dist/docx/run-style-model.d.ts.map +1 -1
  203. package/dist/docx/save-modified.d.ts +2 -1
  204. package/dist/docx/save-modified.d.ts.map +1 -1
  205. package/dist/docx/save.d.ts.map +1 -1
  206. package/dist/docx/style-ref-fields.d.ts +1 -8
  207. package/dist/docx/style-ref-fields.d.ts.map +1 -1
  208. package/dist/docx/symbol-field.d.ts +21 -0
  209. package/dist/docx/symbol-field.d.ts.map +1 -0
  210. package/dist/docx/table-cell-write.d.ts.map +1 -1
  211. package/dist/docx/table-defaults.d.ts +2 -0
  212. package/dist/docx/table-defaults.d.ts.map +1 -1
  213. package/dist/docx/table-margins.d.ts +18 -0
  214. package/dist/docx/table-margins.d.ts.map +1 -0
  215. package/dist/docx/table-model.d.ts +23 -0
  216. package/dist/docx/table-model.d.ts.map +1 -1
  217. package/dist/docx/table-structure-check.d.ts.map +1 -1
  218. package/dist/docx/table-styles.d.ts.map +1 -1
  219. package/dist/docx/ui/index.cjs +787 -435
  220. package/dist/docx/ui/index.d.ts +1 -0
  221. package/dist/docx/ui/index.d.ts.map +1 -1
  222. package/dist/docx/ui/index.mjs +784 -436
  223. package/dist/docx/ui/inline-content-schema.d.ts.map +1 -1
  224. package/dist/docx/ui/paragraph-attributes.d.ts +6 -0
  225. package/dist/docx/ui/paragraph-attributes.d.ts.map +1 -1
  226. package/dist/docx/ui/ribbon-action-ids.d.ts +1 -1
  227. package/dist/docx/ui/ribbon-action-ids.d.ts.map +1 -1
  228. package/dist/docx/ui/ribbon-legacy-labels.d.ts +1 -1
  229. package/dist/docx/ui/ribbon-legacy-labels.d.ts.map +1 -1
  230. package/dist/docx/ui/run-adapter.d.ts.map +1 -1
  231. package/dist/docx/ui/schema-marks.d.ts +2 -19
  232. package/dist/docx/ui/schema-marks.d.ts.map +1 -1
  233. package/dist/docx/ui/track-run-formatting.d.ts.map +1 -1
  234. package/dist/docx/ui/yjs-document-attributes.d.ts +5 -0
  235. package/dist/docx/ui/yjs-document-attributes.d.ts.map +1 -1
  236. package/dist/docx/write-drawing-wrap.d.ts +22 -0
  237. package/dist/docx/write-drawing-wrap.d.ts.map +1 -0
  238. package/dist/docx/write-drawing.d.ts.map +1 -1
  239. package/dist/docx/write-revisions.d.ts +3 -1
  240. package/dist/docx/write-revisions.d.ts.map +1 -1
  241. package/dist/docx/write-shape.d.ts.map +1 -1
  242. package/dist/docx/write-table-properties.d.ts.map +1 -1
  243. package/dist/docx/write.d.ts.map +1 -1
  244. package/dist/drawingml/html-text-paste.d.ts +28 -0
  245. package/dist/drawingml/html-text-paste.d.ts.map +1 -0
  246. package/dist/drawingml/html-text-style.d.ts +18 -0
  247. package/dist/drawingml/html-text-style.d.ts.map +1 -0
  248. package/dist/drawingml/index.cjs +762 -0
  249. package/dist/drawingml/index.d.ts +1 -0
  250. package/dist/drawingml/index.d.ts.map +1 -1
  251. package/dist/drawingml/index.mjs +760 -1
  252. package/dist/index.cjs +1147 -251
  253. package/dist/index.mjs +1147 -251
  254. package/dist/pptx/automation/index.cjs +561 -180
  255. package/dist/pptx/automation/index.d.ts +4 -4
  256. package/dist/pptx/automation/index.mjs +6 -5
  257. package/dist/pptx/chunks/{index-BCy58n13.d.ts → index-8ZfPndYR.d.ts} +2 -2
  258. package/dist/pptx/chunks/{index-BCy58n13.d.ts.map → index-8ZfPndYR.d.ts.map} +1 -1
  259. package/dist/pptx/chunks/{index-OwiX5IVw.d.ts → index-DVhD9Kd5.d.ts} +4 -4
  260. package/dist/pptx/chunks/{index-OwiX5IVw.d.ts.map → index-DVhD9Kd5.d.ts.map} +1 -1
  261. package/dist/pptx/chunks/{index-oQHWAO7M.d.ts → index-DsUnUj-V.d.ts} +5 -5
  262. package/dist/pptx/chunks/{index-oQHWAO7M.d.ts.map → index-DsUnUj-V.d.ts.map} +1 -1
  263. package/dist/pptx/chunks/{index-AZN38e6S.d.ts → index-xB7MDLI7.d.ts} +4 -4
  264. package/dist/pptx/chunks/{index-AZN38e6S.d.ts.map → index-xB7MDLI7.d.ts.map} +1 -1
  265. package/dist/pptx/chunks/{presentation-DOaYIW-l.d.ts → presentation-BvnVkFPJ.d.ts} +26 -2
  266. package/dist/pptx/chunks/{presentation-DOaYIW-l.d.ts.map → presentation-BvnVkFPJ.d.ts.map} +1 -1
  267. package/dist/pptx/chunks/{text-operations-CYSXno9L.d.ts → text-operations-D7TCPhlv.d.ts} +2 -2
  268. package/dist/pptx/chunks/{text-operations-CYSXno9L.d.ts.map → text-operations-D7TCPhlv.d.ts.map} +1 -1
  269. package/dist/pptx/cli/index.cjs +504 -124
  270. package/dist/pptx/cli/index.d.ts +1 -1
  271. package/dist/pptx/cli/index.mjs +4 -4
  272. package/dist/pptx/converter/index.d.ts +1 -1
  273. package/dist/pptx/converter/index.mjs +2 -2
  274. package/dist/pptx/editor/render/custom-show-operations.cjs +2 -2
  275. package/dist/pptx/editor/render/custom-show-operations.mjs +1 -1
  276. package/dist/pptx/editor/render/find-replace.cjs +16 -15
  277. package/dist/pptx/editor/render/find-replace.d.ts +2 -2
  278. package/dist/pptx/editor/render/find-replace.mjs +3 -2
  279. package/dist/pptx/editor/render/font-family-update.d.ts +2 -2
  280. package/dist/pptx/editor/render/paragraph-geometry-overrides.d.ts +2 -2
  281. package/dist/pptx/editor/render/segments-text-edit.cjs +159 -0
  282. package/dist/pptx/editor/render/segments-text-edit.d.ts +26 -0
  283. package/dist/pptx/editor/render/segments-text-edit.d.ts.map +1 -0
  284. package/dist/pptx/editor/render/segments-text-edit.mjs +156 -0
  285. package/dist/pptx/editor/render/slide-operations.cjs +12 -9
  286. package/dist/pptx/editor/render/slide-operations.mjs +6 -3
  287. package/dist/pptx/editor/render/table-cell-edit.cjs +5 -5
  288. package/dist/pptx/editor/render/table-cell-edit.d.ts.map +1 -1
  289. package/dist/pptx/editor/render/table-cell-edit.mjs +1 -1
  290. package/dist/pptx/editor/render/table-cell-merge.cjs +3 -3
  291. package/dist/pptx/editor/render/table-cell-merge.mjs +1 -1
  292. package/dist/pptx/editor/render/table-cell-rich-text.cjs +41 -0
  293. package/dist/pptx/editor/render/table-cell-rich-text.d.ts +50 -0
  294. package/dist/pptx/editor/render/table-cell-rich-text.d.ts.map +1 -0
  295. package/dist/pptx/editor/render/table-cell-rich-text.mjs +8 -0
  296. package/dist/pptx/editor/render/table-cell-source.cjs +23 -0
  297. package/dist/pptx/editor/render/table-cell-source.d.ts +31 -0
  298. package/dist/pptx/editor/render/table-cell-source.d.ts.map +1 -0
  299. package/dist/pptx/editor/render/table-cell-source.mjs +6 -0
  300. package/dist/pptx/editor/render/table-cells-text-style.cjs +116 -0
  301. package/dist/pptx/editor/render/table-cells-text-style.d.ts +37 -0
  302. package/dist/pptx/editor/render/table-cells-text-style.d.ts.map +1 -0
  303. package/dist/pptx/editor/render/table-cells-text-style.mjs +113 -0
  304. package/dist/pptx/editor/render/table-data-grid-ops.cjs +40 -94
  305. package/dist/pptx/editor/render/table-data-grid-ops.mjs +3 -88
  306. package/dist/pptx/editor/render/table-grid-fill.cjs +30 -0
  307. package/dist/pptx/editor/render/table-grid-fill.d.ts +34 -0
  308. package/dist/pptx/editor/render/table-grid-fill.d.ts.map +1 -0
  309. package/dist/pptx/editor/render/table-grid-fill.mjs +28 -0
  310. package/dist/pptx/editor/render/table-layout.cjs +6 -6
  311. package/dist/pptx/editor/render/table-layout.d.ts +2 -2
  312. package/dist/pptx/editor/render/table-layout.d.ts.map +1 -1
  313. package/dist/pptx/editor/render/table-layout.mjs +1 -1
  314. package/dist/pptx/editor/render/table-merge.cjs +5 -5
  315. package/dist/pptx/editor/render/table-merge.mjs +1 -1
  316. package/dist/pptx/editor/render/text-content-style.d.ts +2 -2
  317. package/dist/pptx/editor/render/text-runs-style-patch.d.ts +2 -2
  318. package/dist/pptx/editor/render/text-style-scope.d.ts +2 -2
  319. package/dist/pptx/editor/render/update-text-segment-style.d.ts +2 -2
  320. package/dist/pptx/index.cjs +519 -201
  321. package/dist/pptx/index.d.ts +7 -7
  322. package/dist/pptx/index.mjs +5 -5
  323. package/dist/pptx/node/index.d.ts +1 -1
  324. package/dist/pptx/smartart-layouts/index.d.ts +2 -2
  325. package/dist/teams/index.cjs +35 -25
  326. package/dist/teams/index.mjs +35 -25
  327. package/dist/text/complex-breaks.d.ts +24 -0
  328. package/dist/text/complex-breaks.d.ts.map +1 -0
  329. package/dist/text/east-asian.d.ts +32 -0
  330. package/dist/text/east-asian.d.ts.map +1 -0
  331. package/dist/text/html-tokens.d.ts +45 -0
  332. package/dist/text/html-tokens.d.ts.map +1 -0
  333. package/dist/text/index.cjs +477 -62
  334. package/dist/text/index.d.ts +5 -0
  335. package/dist/text/index.d.ts.map +1 -1
  336. package/dist/text/index.mjs +456 -63
  337. package/dist/text/kinsoku.d.ts +55 -0
  338. package/dist/text/kinsoku.d.ts.map +1 -0
  339. package/dist/text/truetype/embedding.d.ts +42 -0
  340. package/dist/text/truetype/embedding.d.ts.map +1 -0
  341. package/dist/text/windows-1252.d.ts +10 -0
  342. package/dist/text/windows-1252.d.ts.map +1 -0
  343. package/dist/xlsx/collab/index.cjs +10 -6
  344. package/dist/xlsx/collab/index.mjs +10 -6
  345. package/dist/xlsx/edit/clipboard-html-parse.d.ts +1 -0
  346. package/dist/xlsx/edit/clipboard-html-parse.d.ts.map +1 -1
  347. package/dist/xlsx/formula/functions/text-convert.d.ts.map +1 -1
  348. package/dist/xlsx/index.cjs +96 -51
  349. package/dist/xlsx/index.mjs +96 -51
  350. package/dist/xlsx/load/index.cjs +10 -6
  351. package/dist/xlsx/load/index.mjs +10 -6
  352. package/dist/xlsx/ui/index.cjs +97 -52
  353. package/dist/xlsx/ui/index.mjs +97 -52
  354. package/package.json +1 -1
  355. package/dist/PptxHandler-72NTA5ZY.cjs +0 -14
  356. package/dist/PptxHandler-O4IJ3TKZ.mjs +0 -5
  357. package/dist/PresentationBuilder-ORM22QGC.mjs +0 -5
  358. package/dist/PresentationBuilder-T2ETYT3L.cjs +0 -22
  359. package/dist/chunk-X4RL5AZ7.cjs +0 -120
  360. package/dist/{chunk-PRGXRAAU.mjs → chunk-4Y76EAKK.mjs} +131 -131
  361. package/dist/{chunk-EN3KSEW5.cjs → chunk-MMULWQOM.cjs} +131 -131
@@ -92,8 +92,8 @@ function parseXml(xml, options2 = {}) {
92
92
  let parsed;
93
93
  try {
94
94
  parsed = new xmldom.DOMParser({
95
- onError: (level2, message) => {
96
- if (level2 !== "warning" || options2.warningsAsErrors) parseError = message;
95
+ onError: (level3, message) => {
96
+ if (level3 !== "warning" || options2.warningsAsErrors) parseError = message;
97
97
  }
98
98
  }).parseFromString(xml, "application/xml");
99
99
  } catch (error) {
@@ -230,8 +230,8 @@ function universalMeasureToTwips(value) {
230
230
  }
231
231
  function parseSignedTwips(value) {
232
232
  if (value === null || value === void 0) return void 0;
233
- const text2 = value.trim();
234
- const parsed = SAFE_INTEGER.test(text2) ? parseInteger(text2) : universalMeasureToTwips(text2);
233
+ const text3 = value.trim();
234
+ const parsed = SAFE_INTEGER.test(text3) ? parseInteger(text3) : universalMeasureToTwips(text3);
235
235
  return parsed === void 0 ? void 0 : signedTwips(parsed);
236
236
  }
237
237
  function parseTwips(value) {
@@ -240,26 +240,26 @@ function parseTwips(value) {
240
240
  }
241
241
  function parseHalfPoints(value) {
242
242
  if (value === null || value === void 0) return void 0;
243
- const text2 = value.trim();
244
- if (/^\d+$/.test(text2)) {
245
- const parsed = parseInteger(text2);
243
+ const text3 = value.trim();
244
+ if (/^\d+$/.test(text3)) {
245
+ const parsed = parseInteger(text3);
246
246
  return parsed === void 0 ? void 0 : halfPoints(parsed);
247
247
  }
248
- const asTwips = UNIVERSAL_MEASURE.test(text2) ? universalMeasureToTwips(text2) : void 0;
248
+ const asTwips = UNIVERSAL_MEASURE.test(text3) ? universalMeasureToTwips(text3) : void 0;
249
249
  return asTwips !== void 0 && asTwips >= 0 ? halfPoints(Math.round(asTwips / 10)) : void 0;
250
250
  }
251
251
  function parseSignedHalfPoints(value) {
252
252
  if (value === null || value === void 0) return void 0;
253
- const text2 = value.trim();
254
- const integer2 = parseInteger(text2);
253
+ const text3 = value.trim();
254
+ const integer2 = parseInteger(text3);
255
255
  if (integer2 !== void 0) return halfPoints(integer2);
256
- const twips2 = universalMeasureToTwips(text2);
256
+ const twips2 = universalMeasureToTwips(text3);
257
257
  return twips2 === void 0 ? void 0 : halfPoints(Math.sign(twips2) * Math.round(Math.abs(twips2) / 10));
258
258
  }
259
259
  function parseTextScale(value) {
260
- const text2 = value?.trim();
261
- if (text2?.endsWith("%") && !/^\d+%$/.test(text2)) return void 0;
262
- const parsed = parseUnsignedInteger(text2?.endsWith("%") ? text2.slice(0, -1) : text2);
260
+ const text3 = value?.trim();
261
+ if (text3?.endsWith("%") && !/^\d+%$/.test(text3)) return void 0;
262
+ const parsed = parseUnsignedInteger(text3?.endsWith("%") ? text3.slice(0, -1) : text3);
263
263
  return parsed !== void 0 && parsed <= 600 ? parsed : void 0;
264
264
  }
265
265
  function parseEighthPoints(value) {
@@ -518,6 +518,12 @@ var PAGINATION_KEYS = [
518
518
  "contextualSpacing",
519
519
  "suppressLineNumbers"
520
520
  ];
521
+ var EAST_ASIAN_TYPOGRAPHY_KEYS = [
522
+ "kinsoku",
523
+ "autoSpaceDE",
524
+ "autoSpaceDN",
525
+ "overflowPunct"
526
+ ];
521
527
  function parseOutlineLevel(element) {
522
528
  const raw = getW(element, "val");
523
529
  if (raw === void 0) return void 0;
@@ -562,6 +568,7 @@ function resolveParagraphFormatting(paragraph, catalog) {
562
568
  "hangingTwips",
563
569
  "pageBreakBefore",
564
570
  ...PAGINATION_KEYS,
571
+ ...EAST_ASIAN_TYPOGRAPHY_KEYS,
565
572
  "outlineLevel",
566
573
  "borders",
567
574
  "shadingFill"
@@ -594,6 +601,45 @@ function resolveStyleNumbering(styleId, catalog) {
594
601
  return chain.find((style) => style.numbering)?.numbering;
595
602
  }
596
603
 
604
+ // docx/table-margins.ts
605
+ var SIDES = ["top", "right", "bottom", "left"];
606
+ var BUILT_IN = {
607
+ top: signedTwips(0),
608
+ right: signedTwips(108),
609
+ bottom: signedTwips(0),
610
+ left: signedTwips(108)
611
+ };
612
+ var UNSTYLED = {
613
+ top: signedTwips(0),
614
+ right: signedTwips(10),
615
+ bottom: signedTwips(0),
616
+ left: signedTwips(10)
617
+ };
618
+ function styleChain(id, catalog) {
619
+ const chain = [];
620
+ let style = id ? catalog.styles[id] : void 0;
621
+ while (style && !chain.includes(style)) {
622
+ chain.push(style);
623
+ style = style.basedOn ? catalog.styles[style.basedOn] : void 0;
624
+ }
625
+ return chain;
626
+ }
627
+ function resolveTableCellMargins(table, catalog) {
628
+ if (!catalog) return { ...BUILT_IN, ...table.cellMargins };
629
+ const defaultStyle = Object.values(catalog.styles).find((style) => style.isDefault);
630
+ const layers = [
631
+ table.cellMargins,
632
+ ...styleChain(table.style, catalog).map((style) => style.cellMargins),
633
+ ...styleChain(defaultStyle?.id, catalog).map((style) => style.cellMargins)
634
+ ];
635
+ const result = { ...UNSTYLED };
636
+ for (const side of SIDES) {
637
+ const value = layers.find((layer) => layer?.[side] !== void 0)?.[side];
638
+ if (value !== void 0) result[side] = value;
639
+ }
640
+ return result;
641
+ }
642
+
597
643
  // docx/highlight.ts
598
644
  var WORD_HIGHLIGHT_TOKENS = [
599
645
  "black",
@@ -626,7 +672,7 @@ function isValidLanguageTag(value) {
626
672
  }
627
673
 
628
674
  // docx/resolve-table.ts
629
- function styleChain(styleId, catalog) {
675
+ function styleChain2(styleId, catalog) {
630
676
  if (!styleId || !catalog) return [];
631
677
  const chain = [];
632
678
  const visited = /* @__PURE__ */ new Set();
@@ -651,7 +697,7 @@ function applicableRegions(look, rowIndex, rowCount, colIndex, colCount) {
651
697
  return regions;
652
698
  }
653
699
  function resolveTableStyleFormatting(tableStyleId, catalog, look, rowIndex, rowCount, colIndex, colCount) {
654
- const chain = styleChain(tableStyleId, catalog);
700
+ const chain = styleChain2(tableStyleId, catalog);
655
701
  const regions = applicableRegions(look, rowIndex, rowCount, colIndex, colCount);
656
702
  const result = {};
657
703
  for (const style of chain) {
@@ -769,8 +815,8 @@ function resolveRunFormatting(run, context = {}) {
769
815
  if (state) result[key] = true;
770
816
  }
771
817
  for (const key of OVERRIDE_KEYS) {
772
- for (const level2 of levels) {
773
- const value = level2[key];
818
+ for (const level3 of levels) {
819
+ const value = level3[key];
774
820
  if (value !== void 0) result[key] = value;
775
821
  }
776
822
  }
@@ -792,13 +838,13 @@ function hexToRgbChannels(color) {
792
838
  b: Number.parseInt(normalized.slice(4, 6), 16)
793
839
  };
794
840
  }
795
- function percentDivisorFor(text2) {
796
- return text2.endsWith("%") ? 100 : 1e5;
841
+ function percentDivisorFor(text3) {
842
+ return text3.endsWith("%") ? 100 : 1e5;
797
843
  }
798
844
  function parseOoxmlPercent(value) {
799
- const text2 = String(value ?? "").trim();
800
- const divisor = percentDivisorFor(text2);
801
- const magnitude = Number.parseFloat(divisor === 100 ? text2.slice(0, -1) : text2);
845
+ const text3 = String(value ?? "").trim();
846
+ const divisor = percentDivisorFor(text3);
847
+ const magnitude = Number.parseFloat(divisor === 100 ? text3.slice(0, -1) : text3);
802
848
  if (!Number.isFinite(magnitude)) {
803
849
  return void 0;
804
850
  }
@@ -1581,10 +1627,10 @@ function parseStandardPictureEffect(node) {
1581
1627
 
1582
1628
  // drawingml/picture-effects.ts
1583
1629
  function picturePercentage(value) {
1584
- const text2 = String(value ?? "").trim();
1585
- if (!text2) return void 0;
1586
- const percent = text2.endsWith("%");
1587
- const n2 = Number(percent ? text2.slice(0, -1) : text2) / (percent ? 100 : 1e5);
1630
+ const text3 = String(value ?? "").trim();
1631
+ if (!text3) return void 0;
1632
+ const percent = text3.endsWith("%");
1633
+ const n2 = Number(percent ? text3.slice(0, -1) : text3) / (percent ? 100 : 1e5);
1588
1634
  return Number.isFinite(n2) ? n2 : void 0;
1589
1635
  }
1590
1636
  function readPictureEffect(name2, attribute) {
@@ -1665,12 +1711,12 @@ function parsePictureLayout(fill) {
1665
1711
  }
1666
1712
 
1667
1713
  // drawingml/picture-crop.ts
1668
- var SIDES = { l: "cropLeft", t: "cropTop", r: "cropRight", b: "cropBottom" };
1714
+ var SIDES2 = { l: "cropLeft", t: "cropTop", r: "cropRight", b: "cropBottom" };
1669
1715
  function parsePictureCrop(blipFill) {
1670
1716
  const rect3 = first(blipFill, "srcRect", NS.a);
1671
1717
  if (!rect3) return void 0;
1672
1718
  const result = {};
1673
- for (const [attr3, key] of Object.entries(SIDES)) {
1719
+ for (const [attr3, key] of Object.entries(SIDES2)) {
1674
1720
  const raw = rect3.getAttribute(attr3);
1675
1721
  if (raw === null || !raw.trim()) continue;
1676
1722
  const percent = raw.endsWith("%");
@@ -2064,13 +2110,13 @@ function expectDefined(value, context) {
2064
2110
 
2065
2111
  // docx/special-characters.ts
2066
2112
  function symbolCharacter(char) {
2067
- const code = /^[0-9a-f]{1,6}$/i.test(char) ? Number.parseInt(char, 16) : Number.NaN;
2068
- if (!Number.isInteger(code) || code > 1114111 || code >= 55296 && code <= 57343) return "";
2069
- return String.fromCodePoint(code < 256 ? 61440 + code : code);
2113
+ const code2 = /^[0-9a-f]{1,6}$/i.test(char) ? Number.parseInt(char, 16) : Number.NaN;
2114
+ if (!Number.isInteger(code2) || code2 > 1114111 || code2 >= 55296 && code2 <= 57343) return "";
2115
+ return String.fromCodePoint(code2 < 256 ? 61440 + code2 : code2);
2070
2116
  }
2071
2117
  function symbolOnly(run) {
2072
2118
  const symbol = run.symbol && symbolCharacter(run.symbol.char);
2073
- return Boolean(symbol && run.text && [...run.text].every((character) => character === symbol));
2119
+ return Boolean(symbol && run.text && [...run.text].every((character2) => character2 === symbol));
2074
2120
  }
2075
2121
  function symbolSegments(run) {
2076
2122
  const symbol = run.symbol && symbolCharacter(run.symbol.char);
@@ -2078,13 +2124,13 @@ function symbolSegments(run) {
2078
2124
  const segments = [];
2079
2125
  let piece = "";
2080
2126
  let symbols = false;
2081
- for (const character of run.text) {
2082
- const isSymbol = character === symbol;
2127
+ for (const character2 of run.text) {
2128
+ const isSymbol = character2 === symbol;
2083
2129
  if (piece && isSymbol !== symbols) {
2084
2130
  segments.push({ ...run, text: piece });
2085
2131
  piece = "";
2086
2132
  }
2087
- piece += character;
2133
+ piece += character2;
2088
2134
  symbols = isSymbol;
2089
2135
  }
2090
2136
  if (piece) segments.push({ ...run, text: piece });
@@ -2318,15 +2364,15 @@ function operand(value, vars) {
2318
2364
  const literal = Number(value);
2319
2365
  return Number.isFinite(literal) ? literal : vars.get(value) ?? NaN;
2320
2366
  }
2321
- function parseCustomGeometry(custom, width, height) {
2322
- const pathList = first(custom, "pathLst", NS.a);
2367
+ function parseCustomGeometry(custom2, width, height) {
2368
+ const pathList = first(custom2, "pathLst", NS.a);
2323
2369
  if (!pathList) return void 0;
2324
2370
  const pathNodes = children(pathList, "path", NS.a);
2325
2371
  const contextWidth = width;
2326
2372
  const contextHeight = height;
2327
2373
  const vars = createBuiltinVariables({ w: contextWidth, h: contextHeight });
2328
2374
  for (const list of ["avLst", "gdLst"]) {
2329
- const parent = first(custom, list, NS.a);
2375
+ const parent = first(custom2, list, NS.a);
2330
2376
  if (!parent) continue;
2331
2377
  for (const guide of children(parent, "gd", NS.a)) {
2332
2378
  const name2 = guide.getAttribute("name");
@@ -2458,10 +2504,10 @@ function lerpStops(a, b, t) {
2458
2504
  };
2459
2505
  }
2460
2506
  function gradientColorAt(stops, position) {
2461
- const first3 = stops[0];
2507
+ const first4 = stops[0];
2462
2508
  const last = stops[stops.length - 1];
2463
- if (position <= first3.position) {
2464
- return { color: first3.color, opacity: first3.opacity ?? 1 };
2509
+ if (position <= first4.position) {
2510
+ return { color: first4.color, opacity: first4.opacity ?? 1 };
2465
2511
  }
2466
2512
  if (position >= last.position) {
2467
2513
  return { color: last.color, opacity: last.opacity ?? 1 };
@@ -2786,8 +2832,8 @@ var Glyph = class {
2786
2832
  }
2787
2833
  /** `M p0 L p1 ... Z` through the points. */
2788
2834
  poly(points, close = true) {
2789
- const [first3, ...rest] = points;
2790
- return `M ${this.pt(first3)}${rest.map((q) => ` L ${this.pt(q)}`).join("")}${close ? " Z" : ""}`;
2835
+ const [first4, ...rest] = points;
2836
+ return `M ${this.pt(first4)}${rest.map((q) => ` L ${this.pt(q)}`).join("")}${close ? " Z" : ""}`;
2791
2837
  }
2792
2838
  /** A full circle of radius `r` centred on `(cx, cy)`. */
2793
2839
  circle(cx, cy, r) {
@@ -9344,15 +9390,15 @@ var heart2 = {
9344
9390
  };
9345
9391
  function buildIrregularSeal(name2, points) {
9346
9392
  const commands = [];
9347
- const first3 = points[0];
9348
- if (!first3) {
9393
+ const first4 = points[0];
9394
+ if (!first4) {
9349
9395
  return {
9350
9396
  name: name2,
9351
9397
  rect: FULL_RECT7,
9352
9398
  pathLst: [{ commands: [{ kind: "close" }] }]
9353
9399
  };
9354
9400
  }
9355
- commands.push({ kind: "moveTo", x: String(first3[0]), y: String(first3[1]) });
9401
+ commands.push({ kind: "moveTo", x: String(first4[0]), y: String(first4[1]) });
9356
9402
  for (let i = 1; i < points.length; i++) {
9357
9403
  const p2 = points[i];
9358
9404
  commands.push({ kind: "lnTo", x: String(p2[0]), y: String(p2[1]) });
@@ -13865,14 +13911,14 @@ var NAMED_FORMAT_COLORS = {
13865
13911
  yellow: "#FFFF00"
13866
13912
  };
13867
13913
  var PLACEHOLDER = /[0#?]/u;
13868
- function parsePattern(code) {
13914
+ function parsePattern(code2) {
13869
13915
  let scale = 1;
13870
13916
  let scientific = false;
13871
13917
  let color;
13872
13918
  const chars = [];
13873
13919
  let inQuotes = false;
13874
- for (let i = 0; i < code.length; i += 1) {
13875
- const ch = code[i] ?? "";
13920
+ for (let i = 0; i < code2.length; i += 1) {
13921
+ const ch = code2[i] ?? "";
13876
13922
  if (ch === '"') {
13877
13923
  inQuotes = !inQuotes;
13878
13924
  continue;
@@ -13882,7 +13928,7 @@ function parsePattern(code) {
13882
13928
  continue;
13883
13929
  }
13884
13930
  if (ch === "\\" || ch === "*" || ch === "_") {
13885
- const next = code[i + 1];
13931
+ const next = code2[i + 1];
13886
13932
  i += 1;
13887
13933
  if (ch === "\\" && next !== void 0) {
13888
13934
  chars.push({ ch: next, literal: true });
@@ -13894,20 +13940,20 @@ function parsePattern(code) {
13894
13940
  chars.push({ ch, literal: true });
13895
13941
  continue;
13896
13942
  }
13897
- if (ch === "E" && (code[i + 1] === "+" || code[i + 1] === "-")) {
13943
+ if (ch === "E" && (code2[i + 1] === "+" || code2[i + 1] === "-")) {
13898
13944
  scientific = true;
13899
13945
  chars.push({ ch: "E", literal: false });
13900
13946
  i += 1;
13901
13947
  continue;
13902
13948
  }
13903
13949
  if (ch === "[") {
13904
- const close = code.indexOf("]", i);
13905
- const token = code.slice(i + 1, close === -1 ? code.length : close);
13950
+ const close = code2.indexOf("]", i);
13951
+ const token = code2.slice(i + 1, close === -1 ? code2.length : close);
13906
13952
  const named3 = NAMED_FORMAT_COLORS[token.trim().toLowerCase()];
13907
13953
  if (named3 && color === void 0) {
13908
13954
  color = named3;
13909
13955
  }
13910
- i = close === -1 ? code.length : close;
13956
+ i = close === -1 ? code2.length : close;
13911
13957
  continue;
13912
13958
  }
13913
13959
  chars.push({ ch, literal: false });
@@ -14027,19 +14073,19 @@ function applyPattern(value, pattern, forcePositive) {
14027
14073
 
14028
14074
  // chart/number-format.ts
14029
14075
  var GENERAL = /* @__PURE__ */ new Set(["", "general", "@"]);
14030
- function sections(code) {
14076
+ function sections(code2) {
14031
14077
  const out = [];
14032
14078
  let current = "";
14033
14079
  let inQuotes = false;
14034
- for (let i = 0; i < code.length; i += 1) {
14035
- const ch = code[i];
14080
+ for (let i = 0; i < code2.length; i += 1) {
14081
+ const ch = code2[i];
14036
14082
  if (ch === '"') {
14037
14083
  inQuotes = !inQuotes;
14038
14084
  current += ch;
14039
14085
  continue;
14040
14086
  }
14041
14087
  if (ch === "\\") {
14042
- current += ch + (code[i + 1] ?? "");
14088
+ current += ch + (code2[i + 1] ?? "");
14043
14089
  i += 1;
14044
14090
  continue;
14045
14091
  }
@@ -14069,14 +14115,14 @@ function formatChartNumberWithColor(value, formatCode) {
14069
14115
  if (!Number.isFinite(value)) {
14070
14116
  return void 0;
14071
14117
  }
14072
- const code = (formatCode ?? "").trim();
14073
- if (GENERAL.has(code.toLowerCase())) {
14118
+ const code2 = (formatCode ?? "").trim();
14119
+ if (GENERAL.has(code2.toLowerCase())) {
14074
14120
  return void 0;
14075
14121
  }
14076
- if (/(?:^|[^\\"])(?:yy|mm?m|dd?|hh|ss)/iu.test(code) && !/[0#?]/u.test(code)) {
14122
+ if (/(?:^|[^\\"])(?:yy|mm?m|dd?|hh|ss)/iu.test(code2) && !/[0#?]/u.test(code2)) {
14077
14123
  return void 0;
14078
14124
  }
14079
- const { code: section, forcePositive } = sectionFor(value, sections(code));
14125
+ const { code: section, forcePositive } = sectionFor(value, sections(code2));
14080
14126
  const pattern = parsePattern(section);
14081
14127
  if (!pattern) {
14082
14128
  return void 0;
@@ -14116,14 +14162,14 @@ function resolveDataLabelFlags(levels) {
14116
14162
  };
14117
14163
  }
14118
14164
  function composeDataLabelText(input) {
14119
- const { flags, value, numberFormat } = input;
14165
+ const { flags, value, numberFormat: numberFormat2 } = input;
14120
14166
  const parts = [];
14121
14167
  let valueColor;
14122
14168
  if (flags.showSeriesName && input.seriesName) parts.push(input.seriesName);
14123
14169
  if (flags.showCategory && input.category) parts.push(input.category);
14124
14170
  if (flags.showValue) {
14125
- const formatted = formatChartNumberWithColor(value, numberFormat);
14126
- parts.push(formatted?.text ?? (input.formatValue ?? String)(value, numberFormat));
14171
+ const formatted = formatChartNumberWithColor(value, numberFormat2);
14172
+ parts.push(formatted?.text ?? (input.formatValue ?? String)(value, numberFormat2));
14127
14173
  valueColor = formatted?.color;
14128
14174
  }
14129
14175
  if (flags.showPercent) {
@@ -14132,9 +14178,9 @@ function composeDataLabelText(input) {
14132
14178
  }
14133
14179
  if (flags.showBubbleSize && input.bubbleSize !== void 0)
14134
14180
  parts.push((input.formatBubbleSize ?? String)(input.bubbleSize));
14135
- const text2 = parts.join(flags.separator);
14136
- if (text2.length === 0) return void 0;
14137
- return { text: text2, color: parts.length === 1 && flags.showValue ? valueColor : void 0 };
14181
+ const text3 = parts.join(flags.separator);
14182
+ if (text3.length === 0) return void 0;
14183
+ return { text: text3, color: parts.length === 1 && flags.showValue ? valueColor : void 0 };
14138
14184
  }
14139
14185
 
14140
14186
  // chart/extent.ts
@@ -14222,10 +14268,10 @@ function squarify(nodes, box) {
14222
14268
  const result = [];
14223
14269
  let rect3 = { ...box };
14224
14270
  let remaining = items;
14225
- for (let first3 = remaining[0]; first3 !== void 0; first3 = remaining[0]) {
14271
+ for (let first4 = remaining[0]; first4 !== void 0; first4 = remaining[0]) {
14226
14272
  const side = Math.min(rect3.w, rect3.h);
14227
- let row2 = [first3];
14228
- let rowAreas = [first3.area];
14273
+ let row2 = [first4];
14274
+ let rowAreas = [first4.area];
14229
14275
  let worst = worstAspectRatio(rowAreas, side);
14230
14276
  let cursor = 1;
14231
14277
  for (let next = remaining[cursor]; next !== void 0; next = remaining[cursor]) {
@@ -14260,10 +14306,10 @@ function squarify(nodes, box) {
14260
14306
 
14261
14307
  // chart/hierarchy.ts
14262
14308
  function normalizeLevels(levels, pointCount) {
14263
- return levels.map((level2) => {
14309
+ return levels.map((level3) => {
14264
14310
  let previous = "";
14265
14311
  return Array.from({ length: pointCount }, (_, index) => {
14266
- const label = level2[index]?.trim() ?? "";
14312
+ const label = level3[index]?.trim() ?? "";
14267
14313
  if (label) previous = label;
14268
14314
  return label || previous;
14269
14315
  });
@@ -14421,12 +14467,12 @@ function computeSunburstArcs(series, cx, cy, maxR) {
14421
14467
  });
14422
14468
  return out;
14423
14469
  }
14424
- function hierarchyKey(levels, level2, index) {
14425
- return levels.slice(level2).map((labels) => labels[index] ?? "").join("\0");
14470
+ function hierarchyKey(levels, level3, index) {
14471
+ return levels.slice(level3).map((labels) => labels[index] ?? "").join("\0");
14426
14472
  }
14427
14473
  function computeHierarchicalSunburstArcs(categoryLevels, values, cx, cy, maxR) {
14428
- const levels = categoryLevels.filter((level2) => level2.length > 0);
14429
- const leafCount = Math.max(values.length, ...levels.map((level2) => level2.length), 0);
14474
+ const levels = categoryLevels.filter((level3) => level3.length > 0);
14475
+ const leafCount = Math.max(values.length, ...levels.map((level3) => level3.length), 0);
14430
14476
  if (levels.length === 0 || leafCount === 0) return [];
14431
14477
  const rawWeights = Array.from({ length: leafCount }, (_, index) => Math.abs(values[index] ?? 0));
14432
14478
  const weights = rawWeights.some((value) => value !== 0) ? rawWeights : rawWeights.map(() => 1);
@@ -14437,15 +14483,15 @@ function computeHierarchicalSunburstArcs(categoryLevels, values, cx, cy, maxR) {
14437
14483
  const rootLabels = levels[levels.length - 1] ?? [];
14438
14484
  const rootColors = /* @__PURE__ */ new Map();
14439
14485
  const out = [];
14440
- for (let level2 = levels.length - 1; level2 >= 0; level2--) {
14441
- const ringIndex = levels.length - 1 - level2;
14486
+ for (let level3 = levels.length - 1; level3 >= 0; level3--) {
14487
+ const ringIndex = levels.length - 1 - level3;
14442
14488
  const innerRadius = ringWidth * (ringIndex + 0.5);
14443
14489
  const outerRadius = ringWidth * (ringIndex + 1.5);
14444
14490
  let start = 0;
14445
14491
  while (start < leafCount) {
14446
- const key = hierarchyKey(levels, level2, start);
14492
+ const key = hierarchyKey(levels, level3, start);
14447
14493
  let end = start + 1;
14448
- while (end < leafCount && hierarchyKey(levels, level2, end) === key) end++;
14494
+ while (end < leafCount && hierarchyKey(levels, level3, end) === key) end++;
14449
14495
  const startAngle = -Math.PI / 2 + (prefix2[start] ?? 0) / total * Math.PI * 2;
14450
14496
  const endAngle = -Math.PI / 2 + (prefix2[end] ?? 0) / total * Math.PI * 2;
14451
14497
  const rootLabel = rootLabels[start] ?? "";
@@ -14455,8 +14501,8 @@ function computeHierarchicalSunburstArcs(categoryLevels, values, cx, cy, maxR) {
14455
14501
  colorIndex: rootColors.get(rootLabel) ?? start,
14456
14502
  opacity: Math.max(0.1, 0.9 - ringIndex * 0.1),
14457
14503
  level: ringIndex,
14458
- label: levels[level2]?.[start] ?? "",
14459
- ...level2 === 0 && end === start + 1 ? { pointIndex: start } : {},
14504
+ label: levels[level3]?.[start] ?? "",
14505
+ ...level3 === 0 && end === start + 1 ? { pointIndex: start } : {},
14460
14506
  ...arcLabelPlacement(cx, cy, (innerRadius + outerRadius) / 2, startAngle, endAngle)
14461
14507
  });
14462
14508
  start = end;
@@ -15190,15 +15236,15 @@ var KIND_OF_TYPE = {
15190
15236
  var chartTrendlineKind = (type) => type !== void 0 && Object.hasOwn(KIND_OF_TYPE, type) ? KIND_OF_TYPE[type] : void 0;
15191
15237
 
15192
15238
  // chart/data-cache.ts
15193
- function chartCacheValues(cache2) {
15194
- if (!cache2) return [];
15195
- const numeric = cache2.type === "number";
15239
+ function chartCacheValues(cache3) {
15240
+ if (!cache3) return [];
15241
+ const numeric = cache3.type === "number";
15196
15242
  const out = [];
15197
- for (const point of cache2.points) {
15198
- const text2 = point.value;
15199
- out[point.index ?? out.length] = numeric && text2.trim() !== "" && Number.isFinite(Number(text2)) ? Number(text2) : text2;
15243
+ for (const point of cache3.points) {
15244
+ const text3 = point.value;
15245
+ out[point.index ?? out.length] = numeric && text3.trim() !== "" && Number.isFinite(Number(text3)) ? Number(text3) : text3;
15200
15246
  }
15201
- const size = Math.max(cache2.pointCount ?? 0, out.length);
15247
+ const size = Math.max(cache3.pointCount ?? 0, out.length);
15202
15248
  for (let index = 0; index < size; index++) if (out[index] === void 0) out[index] = "";
15203
15249
  return out;
15204
15250
  }
@@ -15430,7 +15476,7 @@ function summaryAnalysis(series) {
15430
15476
  }
15431
15477
 
15432
15478
  // chart/render/summary-labels.ts
15433
- function level(options2, custom) {
15479
+ function level(options2, custom2) {
15434
15480
  const out = {};
15435
15481
  if (options2.layout) out.layout = options2.layout;
15436
15482
  if (options2.showLeaderLines !== void 0) out.showLeaderLines = options2.showLeaderLines;
@@ -15444,7 +15490,7 @@ function level(options2, custom) {
15444
15490
  if (options2.separator !== void 0) out.separator = options2.separator;
15445
15491
  if (options2.position) out.position = options2.position;
15446
15492
  if (options2.numberFormat?.formatCode) out.numberFormat = options2.numberFormat.formatCode;
15447
- if (custom?.text !== void 0) out.text = custom.text;
15493
+ if (custom2?.text !== void 0) out.text = custom2.text;
15448
15494
  return out;
15449
15495
  }
15450
15496
  function shows(levels, point) {
@@ -15543,9 +15589,9 @@ function stockStyle(group2) {
15543
15589
  };
15544
15590
  }
15545
15591
  function extraGroups(chartSpace, firstType) {
15546
- const [first3, ...rest] = chartSpace.plotArea.groups;
15547
- if (!first3 || !["column", "line", "area"].includes(firstType)) return [];
15548
- const primary = valueAxisId(chartSpace, first3.axisIds);
15592
+ const [first4, ...rest] = chartSpace.plotArea.groups;
15593
+ if (!first4 || !["column", "line", "area"].includes(firstType)) return [];
15594
+ const primary = valueAxisId(chartSpace, first4.axisIds);
15549
15595
  const out = [];
15550
15596
  for (const group2 of rest) {
15551
15597
  const stockOverColumns = group2.kind === "stock" && firstType === "column";
@@ -15719,12 +15765,12 @@ var TEXT_PARTS = [
15719
15765
  "legend",
15720
15766
  "dataLabel"
15721
15767
  ];
15722
- function inheritChartText(part, entry, builtIn, root) {
15768
+ function inheritChartText(part, entry, builtIn2, root) {
15723
15769
  if (!root || !TEXT_PARTS.includes(part)) return entry;
15724
15770
  const out = { ...entry };
15725
15771
  for (const key of TEXT_KEYS) {
15726
15772
  delete out[key];
15727
- const value = root[key] ?? builtIn?.[key];
15773
+ const value = root[key] ?? builtIn2?.[key];
15728
15774
  if (value !== void 0) Object.assign(out, { [key]: value });
15729
15775
  }
15730
15776
  if (part === "title" && root.fontSize !== void 0) out.fontSize = root.fontSize * 1.2;
@@ -16054,11 +16100,11 @@ var TEXT_COLOR = "#595959";
16054
16100
  var GRID_COLOR = "#D9D9D9";
16055
16101
  var AXIS_COLOR = "#BFBFBF";
16056
16102
  var FONT_SIZE = 10;
16057
- function esc(text2) {
16058
- return text2.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
16103
+ function esc(text3) {
16104
+ return text3.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
16059
16105
  }
16060
16106
  var n = (value) => String(Math.round(value * 100) / 100);
16061
- var textWidth = (text2, size = FONT_SIZE) => text2.length * size * 0.55;
16107
+ var textWidth = (text3, size = FONT_SIZE) => text3.length * size * 0.55;
16062
16108
  function text(x, y, content, attrs2 = {}) {
16063
16109
  const parts = [`x="${n(x)}"`, `y="${n(y)}"`];
16064
16110
  parts.push(`font-size="${attrs2.size ?? FONT_SIZE}"`);
@@ -16560,8 +16606,8 @@ function excelSerialToDate(serial, date1904 = false) {
16560
16606
  const epoch = date1904 ? Date.UTC(1904, 0, 1) : Date.UTC(1899, 11, serial < 60 ? 31 : 30);
16561
16607
  return new Date(epoch + serial * DAY_MS);
16562
16608
  }
16563
- function addUnit(date, amount, unit) {
16564
- const next = new Date(date);
16609
+ function addUnit(date2, amount, unit) {
16610
+ const next = new Date(date2);
16565
16611
  if (unit === "days") {
16566
16612
  next.setUTCDate(next.getUTCDate() + amount);
16567
16613
  } else if (unit === "months") {
@@ -16573,10 +16619,10 @@ function addUnit(date, amount, unit) {
16573
16619
  }
16574
16620
  function calendarTicks(min, max, date1904, unit, step) {
16575
16621
  const result = [];
16576
- let date = excelSerialToDate(min, date1904);
16577
- for (let guard = 0; guard < 1e3 && date.getTime() <= excelSerialToDate(max, date1904).getTime(); guard++) {
16578
- result.push(min + (date.getTime() - excelSerialToDate(min, date1904).getTime()) / DAY_MS);
16579
- date = addUnit(date, step, unit);
16622
+ let date2 = excelSerialToDate(min, date1904);
16623
+ for (let guard = 0; guard < 1e3 && date2.getTime() <= excelSerialToDate(max, date1904).getTime(); guard++) {
16624
+ result.push(min + (date2.getTime() - excelSerialToDate(min, date1904).getTime()) / DAY_MS);
16625
+ date2 = addUnit(date2, step, unit);
16580
16626
  }
16581
16627
  return result;
16582
16628
  }
@@ -16612,26 +16658,26 @@ var MONTH_FULL = [
16612
16658
  ];
16613
16659
  var WEEKDAY_ABBR = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
16614
16660
  var WEEKDAY_FULL = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
16615
- function scanDateFormatTokens(code) {
16661
+ function scanDateFormatTokens(code2) {
16616
16662
  const tokens = [];
16617
16663
  let i = 0;
16618
- while (i < code.length) {
16619
- const ch = code[i];
16664
+ while (i < code2.length) {
16665
+ const ch = code2[i];
16620
16666
  if (ch === '"') {
16621
- const close = code.indexOf('"', i + 1);
16667
+ const close = code2.indexOf('"', i + 1);
16622
16668
  tokens.push({
16623
16669
  kind: "literal",
16624
- text: close === -1 ? code.slice(i + 1) : code.slice(i + 1, close)
16670
+ text: close === -1 ? code2.slice(i + 1) : code2.slice(i + 1, close)
16625
16671
  });
16626
- i = close === -1 ? code.length : close + 1;
16672
+ i = close === -1 ? code2.length : close + 1;
16627
16673
  continue;
16628
16674
  }
16629
16675
  if (ch === "\\") {
16630
- tokens.push({ kind: "literal", text: code[i + 1] ?? "" });
16676
+ tokens.push({ kind: "literal", text: code2[i + 1] ?? "" });
16631
16677
  i += 2;
16632
16678
  continue;
16633
16679
  }
16634
- const rest = code.slice(i);
16680
+ const rest = code2.slice(i);
16635
16681
  if (/^am\/pm/iu.test(rest)) {
16636
16682
  tokens.push({ kind: "ampm", upper: ch === ch.toUpperCase(), short: false });
16637
16683
  i += 5;
@@ -16644,7 +16690,7 @@ function scanDateFormatTokens(code) {
16644
16690
  }
16645
16691
  if (/[ymdhs]/iu.test(ch)) {
16646
16692
  let j = i + 1;
16647
- while (j < code.length && code[j].toLowerCase() === ch.toLowerCase()) {
16693
+ while (j < code2.length && code2[j].toLowerCase() === ch.toLowerCase()) {
16648
16694
  j += 1;
16649
16695
  }
16650
16696
  tokens.push({
@@ -16671,39 +16717,39 @@ function findNonLiteral(tokens, index, step) {
16671
16717
  function pad(n2, width) {
16672
16718
  return String(n2).padStart(width, "0");
16673
16719
  }
16674
- function renderDatePart(part, count, date, twelveHour) {
16720
+ function renderDatePart(part, count, date2, twelveHour) {
16675
16721
  switch (part) {
16676
16722
  case "year":
16677
- return count >= 4 ? pad(date.getUTCFullYear(), 4) : pad(date.getUTCFullYear() % 100, 2);
16723
+ return count >= 4 ? pad(date2.getUTCFullYear(), 4) : pad(date2.getUTCFullYear() % 100, 2);
16678
16724
  case "month":
16679
16725
  if (count >= 4) {
16680
- return MONTH_FULL[date.getUTCMonth()] ?? "";
16726
+ return MONTH_FULL[date2.getUTCMonth()] ?? "";
16681
16727
  }
16682
16728
  if (count === 3) {
16683
- return MONTH_ABBR[date.getUTCMonth()] ?? "";
16729
+ return MONTH_ABBR[date2.getUTCMonth()] ?? "";
16684
16730
  }
16685
- return count >= 2 ? pad(date.getUTCMonth() + 1, 2) : String(date.getUTCMonth() + 1);
16731
+ return count >= 2 ? pad(date2.getUTCMonth() + 1, 2) : String(date2.getUTCMonth() + 1);
16686
16732
  case "day":
16687
16733
  if (count >= 4) {
16688
- return WEEKDAY_FULL[date.getUTCDay()] ?? "";
16734
+ return WEEKDAY_FULL[date2.getUTCDay()] ?? "";
16689
16735
  }
16690
16736
  if (count === 3) {
16691
- return WEEKDAY_ABBR[date.getUTCDay()] ?? "";
16737
+ return WEEKDAY_ABBR[date2.getUTCDay()] ?? "";
16692
16738
  }
16693
- return count >= 2 ? pad(date.getUTCDate(), 2) : String(date.getUTCDate());
16739
+ return count >= 2 ? pad(date2.getUTCDate(), 2) : String(date2.getUTCDate());
16694
16740
  case "hour": {
16695
- const h24 = date.getUTCHours();
16741
+ const h24 = date2.getUTCHours();
16696
16742
  const h = twelveHour ? h24 % 12 === 0 ? 12 : h24 % 12 : h24;
16697
16743
  return count >= 2 ? pad(h, 2) : String(h);
16698
16744
  }
16699
16745
  case "minute":
16700
- return count >= 2 ? pad(date.getUTCMinutes(), 2) : String(date.getUTCMinutes());
16746
+ return count >= 2 ? pad(date2.getUTCMinutes(), 2) : String(date2.getUTCMinutes());
16701
16747
  case "second":
16702
- return count >= 2 ? pad(date.getUTCSeconds(), 2) : String(date.getUTCSeconds());
16748
+ return count >= 2 ? pad(date2.getUTCSeconds(), 2) : String(date2.getUTCSeconds());
16703
16749
  }
16704
16750
  }
16705
- function renderExcelDateFormat(date, code) {
16706
- const tokens = scanDateFormatTokens(code);
16751
+ function renderExcelDateFormat(date2, code2) {
16752
+ const tokens = scanDateFormatTokens(code2);
16707
16753
  const hasAmPm = tokens.some((t) => t.kind === "ampm");
16708
16754
  let out = "";
16709
16755
  for (const [index, token] of tokens.entries()) {
@@ -16712,28 +16758,28 @@ function renderExcelDateFormat(date, code) {
16712
16758
  continue;
16713
16759
  }
16714
16760
  if (token.kind === "ampm") {
16715
- const hour = date.getUTCHours(), text2 = token.short ? hour < 12 ? "A" : "P" : hour < 12 ? "AM" : "PM";
16716
- out += token.upper ? text2 : text2.toLowerCase();
16761
+ const hour = date2.getUTCHours(), text3 = token.short ? hour < 12 ? "A" : "P" : hour < 12 ? "AM" : "PM";
16762
+ out += token.upper ? text3 : text3.toLowerCase();
16717
16763
  continue;
16718
16764
  }
16719
16765
  if (token.letter === "m") {
16720
16766
  const prev = findNonLiteral(tokens, index, -1), next = findNonLiteral(tokens, index, 1), isMinute = prev?.kind === "letters" && prev.letter === "h" || next?.kind === "letters" && next.letter === "s";
16721
- out += renderDatePart(isMinute ? "minute" : "month", token.count, date, hasAmPm);
16767
+ out += renderDatePart(isMinute ? "minute" : "month", token.count, date2, hasAmPm);
16722
16768
  continue;
16723
16769
  }
16724
16770
  const part = { y: "year", d: "day", h: "hour", s: "second" };
16725
- out += renderDatePart(part[token.letter], token.count, date, hasAmPm);
16771
+ out += renderDatePart(part[token.letter], token.count, date2, hasAmPm);
16726
16772
  }
16727
16773
  return out;
16728
16774
  }
16729
- function formatDate(date, unit, format) {
16775
+ function formatDate(date2, unit, format) {
16730
16776
  if (format && /[ymdhs]/iu.test(format)) {
16731
- const rendered = renderExcelDateFormat(date, format);
16777
+ const rendered = renderExcelDateFormat(date2, format);
16732
16778
  if (rendered.length > 0) {
16733
16779
  return rendered;
16734
16780
  }
16735
16781
  }
16736
- const month = date.toLocaleString("en-US", { month: "short", timeZone: "UTC" }), year = String(date.getUTCFullYear()), day = String(date.getUTCDate());
16782
+ const month = date2.toLocaleString("en-US", { month: "short", timeZone: "UTC" }), year = String(date2.getUTCFullYear()), day = String(date2.getUTCDate());
16737
16783
  if (unit === "years") {
16738
16784
  return year;
16739
16785
  }
@@ -17037,10 +17083,10 @@ function generateIntervalTicks(range, unit) {
17037
17083
  return [];
17038
17084
  }
17039
17085
  const tolerance = Math.max(1, Math.abs(range.min), Math.abs(range.max)) * 1e-12;
17040
- const first3 = Math.ceil((range.min - tolerance) / unit);
17086
+ const first4 = Math.ceil((range.min - tolerance) / unit);
17041
17087
  const last = Math.floor((range.max + tolerance) / unit);
17042
- const count = Math.min(Math.max(last - first3 + 1, 0), 2e3);
17043
- return Array.from({ length: count }, (_, index) => (first3 + index) * unit);
17088
+ const count = Math.min(Math.max(last - first4 + 1, 0), 2e3);
17089
+ return Array.from({ length: count }, (_, index) => (first4 + index) * unit);
17044
17090
  }
17045
17091
  function generateAxisTicks(range, axis, defaultIntervals) {
17046
17092
  if (range.logScale && range.logBase) {
@@ -17397,10 +17443,10 @@ function liveLevels(ref, evaluateRef) {
17397
17443
  return levels;
17398
17444
  }
17399
17445
  function hierarchyView(chart, model, evaluateRef) {
17400
- const first3 = model.series[0];
17446
+ const first4 = model.series[0];
17401
17447
  const live = liveLevels(chart.series[0]?.categoriesRef, evaluateRef);
17402
17448
  if (live?.[0]) model.categories = live[0];
17403
- const count = Math.max(first3?.values.length ?? 0, model.categories.length);
17449
+ const count = Math.max(first4?.values.length ?? 0, model.categories.length);
17404
17450
  const supplied = live ?? chart.hierarchy?.levels ?? [];
17405
17451
  const levels = supplied.length > 1 ? normalizeLevels(supplied, count) : [];
17406
17452
  model.hierarchy = {
@@ -17490,7 +17536,7 @@ function categoryTotals(model) {
17490
17536
  }
17491
17537
 
17492
17538
  // chart/render/chart-view-labels.ts
17493
- function labelsOf(source, view, categories, numberFormat, resolveColor) {
17539
+ function labelsOf(source, view, categories, numberFormat2, resolveColor) {
17494
17540
  const { chart, series, points } = source;
17495
17541
  if ((series?.deleted ?? chart?.deleted) === true) return void 0;
17496
17542
  const percentBase = view.values.reduce(
@@ -17518,7 +17564,7 @@ function labelsOf(source, view, categories, numberFormat, resolveColor) {
17518
17564
  seriesName: view.name,
17519
17565
  category,
17520
17566
  value,
17521
- numberFormat: point?.numberFormat ?? series?.numberFormat ?? chart?.numberFormat ?? numberFormat,
17567
+ numberFormat: point?.numberFormat ?? series?.numberFormat ?? chart?.numberFormat ?? numberFormat2,
17522
17568
  percentBase,
17523
17569
  bubbleSize: view.sizes?.[i] ?? void 0,
17524
17570
  formatValue: (v) => formatAxisValue(v),
@@ -17630,16 +17676,16 @@ function waterfallView(chart, model, ctx) {
17630
17676
  model.categories = steps.map((_, i) => labels[i] ?? String(i + 1));
17631
17677
  }
17632
17678
  function histogramView(chart, model) {
17633
- const first3 = model.series[0];
17634
- if (!first3) return;
17635
- const raw = first3.values.map((v) => v ?? Number.NaN);
17679
+ const first4 = model.series[0];
17680
+ if (!first4) return;
17681
+ const raw = first4.values.map((v) => v ?? Number.NaN);
17636
17682
  const options2 = chart.histogram ?? {};
17637
17683
  const bins = options2.aggregateByCategory ? aggregateByCategory(
17638
- first3.values.map((v) => v ?? 0),
17684
+ first4.values.map((v) => v ?? 0),
17639
17685
  model.categories
17640
17686
  ) : computeHistogramBins(raw, options2, formatAxisValue);
17641
17687
  model.categories = bins.map((bin) => bin.label);
17642
- first3.values = bins.map((bin) => bin.value);
17688
+ first4.values = bins.map((bin) => bin.value);
17643
17689
  model.barGapWidth = 0;
17644
17690
  model.barOverlap = 0;
17645
17691
  }
@@ -18547,11 +18593,11 @@ function valueAtSource(values, indices, sourceIndex) {
18547
18593
  const position = indices.indexOf(sourceIndex);
18548
18594
  return position >= 0 ? values[position] : void 0;
18549
18595
  }
18550
- function cachedEntityName(cache2, entityId) {
18551
- if (!cache2 || typeof cache2 !== "object") {
18596
+ function cachedEntityName(cache3, entityId) {
18597
+ if (!cache3 || typeof cache3 !== "object") {
18552
18598
  return void 0;
18553
18599
  }
18554
- const record = cache2;
18600
+ const record = cache3;
18555
18601
  if (String(record["@_entityId"] ?? "") === entityId && record["@_entityName"] !== void 0) {
18556
18602
  return String(record["@_entityName"]);
18557
18603
  }
@@ -18603,13 +18649,13 @@ function buildRegionMapEntries(categories, values, options2, resolveCode) {
18603
18649
  const value = valueAtSource(values, valueIndices, sourceIndex);
18604
18650
  if (value === null || value === void 0 || !Number.isFinite(value)) return [];
18605
18651
  const entityId = valueAtSource(entityIds, entityIndices, sourceIndex);
18606
- const code = resolveRegionEntityCode(entityId, options2, resolveCode) ?? resolveCode(category);
18652
+ const code2 = resolveRegionEntityCode(entityId, options2, resolveCode) ?? resolveCode(category);
18607
18653
  return {
18608
18654
  sourceIndex,
18609
18655
  label: category || entityId || `Region ${sourceIndex + 1}`,
18610
18656
  value,
18611
18657
  ...entityId ? { entityId } : {},
18612
- ...code ? { code } : {}
18658
+ ...code2 ? { code: code2 } : {}
18613
18659
  };
18614
18660
  });
18615
18661
  }
@@ -18663,12 +18709,12 @@ function resolveValueColorStops(valueColors, valueColorPositions, minVal, maxVal
18663
18709
  function buildValueColorScale(stops) {
18664
18710
  const sorted = [...stops].sort((a, b) => a.position - b.position);
18665
18711
  return (t) => {
18666
- const clamped = Math.max(0, Math.min(1, t)), first3 = sorted[0];
18667
- if (!first3) {
18712
+ const clamped = Math.max(0, Math.min(1, t)), first4 = sorted[0];
18713
+ if (!first4) {
18668
18714
  return "#94a3b8";
18669
18715
  }
18670
18716
  if (sorted.length === 1) {
18671
- return first3.color;
18717
+ return first4.color;
18672
18718
  }
18673
18719
  for (let i = 0; i < sorted.length - 1; i++) {
18674
18720
  const a = sorted[i], b = sorted[i + 1];
@@ -18680,8 +18726,8 @@ function buildValueColorScale(stops) {
18680
18726
  );
18681
18727
  }
18682
18728
  }
18683
- const last = sorted[sorted.length - 1] ?? first3;
18684
- return clamped <= first3.position ? first3.color : last.color;
18729
+ const last = sorted[sorted.length - 1] ?? first4;
18730
+ return clamped <= first4.position ? first4.color : last.color;
18685
18731
  };
18686
18732
  }
18687
18733
 
@@ -19074,11 +19120,11 @@ function projectGeoPoint(point, projection = "mercator") {
19074
19120
 
19075
19121
  // chart/region-map/geometry.ts
19076
19122
  function regionMapGeometry(options2) {
19077
- const cache2 = readGeographyCache(options2?.geographyCacheXml);
19078
- if (!cache2.regions.length)
19079
- return { regions: WORLD_REGIONS, approximate: true, issues: cache2.issues, copyright: [] };
19123
+ const cache3 = readGeographyCache(options2?.geographyCacheXml);
19124
+ if (!cache3.regions.length)
19125
+ return { regions: WORLD_REGIONS, approximate: true, issues: cache3.issues, copyright: [] };
19080
19126
  const projection = options2?.projectionType ?? "robinson";
19081
- const projected = cache2.regions.map((region) => ({
19127
+ const projected = cache3.regions.map((region) => ({
19082
19128
  region,
19083
19129
  rings: region.rings.map((ring) => ring.map((p2) => projectGeoPoint(p2, projection)))
19084
19130
  }));
@@ -19086,7 +19132,7 @@ function regionMapGeometry(options2) {
19086
19132
  return {
19087
19133
  regions: [],
19088
19134
  approximate: false,
19089
- issues: [...cache2.issues, "Unsupported geographic projection."],
19135
+ issues: [...cache3.issues, "Unsupported geographic projection."],
19090
19136
  copyright: []
19091
19137
  };
19092
19138
  const all = projected.flatMap((r) => r.rings.flatMap((ring) => ring));
@@ -19125,8 +19171,8 @@ function regionMapGeometry(options2) {
19125
19171
  return {
19126
19172
  regions,
19127
19173
  approximate: false,
19128
- issues: cache2.issues,
19129
- copyright: [...new Set(cache2.regions.flatMap((r) => r.copyright))]
19174
+ issues: cache3.issues,
19175
+ copyright: [...new Set(cache3.regions.flatMap((r) => r.copyright))]
19130
19176
  };
19131
19177
  }
19132
19178
 
@@ -19714,15 +19760,15 @@ function sliceLabels(model, marks, out) {
19714
19760
  outside: Math.hypot(x - mark.cx, y - mark.cy) > mark.outer
19715
19761
  });
19716
19762
  }
19717
- const first3 = marks[0];
19718
- if (!first3) return;
19763
+ const first4 = marks[0];
19764
+ if (!first4) return;
19719
19765
  const nudges = nudgeOutsideLabels(
19720
19766
  items.flatMap(
19721
19767
  (item, id) => item.outside && !item.label.layout ? [{ id, x: item.x, y: item.y, w: item.m.w, h: item.m.h }] : []
19722
19768
  ),
19723
- { cx: first3.cx, cy: first3.cy, r: first3.outer },
19724
- first3.cy - first3.outer,
19725
- first3.cy + first3.outer
19769
+ { cx: first4.cx, cy: first4.cy, r: first4.outer },
19770
+ first4.cy - first4.outer,
19771
+ first4.cy + first4.outer
19726
19772
  );
19727
19773
  for (const [id, item] of items.entries()) {
19728
19774
  const { mark, label, m } = item;
@@ -19870,9 +19916,9 @@ function radarSvg(model, area) {
19870
19916
 
19871
19917
  // chart/render/chart-svg-hierarchy.ts
19872
19918
  var colorAt = (model, index) => {
19873
- const first3 = model.series[0];
19874
- const colors = first3?.pointColors;
19875
- return (colors && colors.length > 0 ? colors[index % colors.length] : void 0) ?? first3?.color ?? "#4472C4";
19919
+ const first4 = model.series[0];
19920
+ const colors = first4?.pointColors;
19921
+ return (colors && colors.length > 0 ? colors[index % colors.length] : void 0) ?? first4?.color ?? "#4472C4";
19876
19922
  };
19877
19923
  var leafValues = (model) => (model.series[0]?.values ?? []).map((v) => v ?? 0);
19878
19924
  function treemapSvg(model, area) {
@@ -20032,17 +20078,17 @@ function chartLegendSvg(model, area, frame2, options2) {
20032
20078
  }
20033
20079
  function legendEntries(model) {
20034
20080
  if (model.type === "pie" || model.type === "doughnut") {
20035
- const first3 = model.series[0];
20081
+ const first4 = model.series[0];
20036
20082
  return model.categories.map((label, i) => ({
20037
20083
  label,
20038
- color: first3?.pointColors?.[i] ?? first3?.color ?? "#4472C4"
20084
+ color: first4?.pointColors?.[i] ?? first4?.color ?? "#4472C4"
20039
20085
  }));
20040
20086
  }
20041
20087
  if ((model.type === "treemap" || model.type === "sunburst") && model.hierarchy) {
20042
- const first3 = model.series[0];
20088
+ const first4 = model.series[0];
20043
20089
  return model.hierarchy.branches.map((label, i) => ({
20044
20090
  label,
20045
- color: first3?.pointColors?.[i % Math.max(1, first3.pointColors.length)] ?? first3?.color ?? "#4472C4"
20091
+ color: first4?.pointColors?.[i % Math.max(1, first4.pointColors.length)] ?? first4?.color ?? "#4472C4"
20046
20092
  }));
20047
20093
  }
20048
20094
  if (model.type === "waterfall" && model.waterfall)
@@ -20679,7 +20725,7 @@ function parseDirectParagraphProperties(props) {
20679
20725
  if (style) paragraph.style = style;
20680
20726
  const pageBreakBefore = onOffElement(first2(props, "pageBreakBefore"));
20681
20727
  if (pageBreakBefore !== void 0) paragraph.pageBreakBefore = pageBreakBefore;
20682
- for (const key of PAGINATION_KEYS) {
20728
+ for (const key of [...PAGINATION_KEYS, ...EAST_ASIAN_TYPOGRAPHY_KEYS]) {
20683
20729
  const value = onOffElement(first2(props, key));
20684
20730
  if (value !== void 0) paragraph[key] = value;
20685
20731
  }
@@ -20748,11 +20794,11 @@ function pictureBulletSizePt(picture, fontSizePt) {
20748
20794
 
20749
20795
  // docx/numbering-parse.ts
20750
20796
  var own = (map, key) => Object.prototype.hasOwnProperty.call(map, key) ? map[key] : void 0;
20751
- function resolveNumberingLevel(catalog, numId, level2) {
20797
+ function resolveNumberingLevel(catalog, numId, level3) {
20752
20798
  const num = own(catalog.nums, numId);
20753
20799
  if (!num) return void 0;
20754
- const override = num.levelOverrides?.[level2];
20755
- const sourceAbstract = own(catalog.abstractNums, num.abstractNumId)?.levels[level2];
20800
+ const override = num.levelOverrides?.[level3];
20801
+ const sourceAbstract = own(catalog.abstractNums, num.abstractNumId)?.levels[level3];
20756
20802
  const abstract = sourceAbstract?.startWasOmitted && sourceAbstract.start === 1 ? { ...sourceAbstract, start: 0 } : sourceAbstract;
20757
20803
  let base = override?.lvl ?? abstract;
20758
20804
  if (!base) return void 0;
@@ -20772,6 +20818,183 @@ function resolveNumberingLevel(catalog, numId, level2) {
20772
20818
  return start !== base.start ? { ...base, start } : base;
20773
20819
  }
20774
20820
 
20821
+ // docx/field-result-spans.ts
20822
+ var removed = (run) => run.revision?.kind === "delete" || run.revision?.kind === "moveFrom";
20823
+ function fieldResultSpans(runs, options2 = {}) {
20824
+ const found = [];
20825
+ const open = [];
20826
+ runs.forEach((run, index) => {
20827
+ const top = open.at(-1);
20828
+ if (run.fieldChar === "begin")
20829
+ open.push({ begin: index, code: "", locked: isFieldLocked(run) });
20830
+ else if (run.fieldCode !== void 0 && top && top.separate === void 0) {
20831
+ top.code += run.fieldCode;
20832
+ top.codeRun ??= index;
20833
+ if (top.nameRun === void 0 && /\S/.test(run.fieldCode)) top.nameRun = index;
20834
+ } else if (run.fieldChar === "separate" && top) top.separate = index;
20835
+ else if (run.fieldChar === "end" && top) {
20836
+ open.pop();
20837
+ const instr = top.code.trim();
20838
+ const names = {
20839
+ ...top.codeRun !== void 0 ? { code: top.codeRun } : {},
20840
+ ...top.nameRun !== void 0 ? { name: top.nameRun } : {}
20841
+ };
20842
+ if (top.separate === void 0) {
20843
+ if (options2.resultless)
20844
+ found.push({
20845
+ from: top.begin,
20846
+ to: index,
20847
+ instr,
20848
+ locked: top.locked,
20849
+ runs: [],
20850
+ ...names,
20851
+ insertAt: index,
20852
+ resultless: true
20853
+ });
20854
+ return;
20855
+ }
20856
+ const results = [];
20857
+ let gone = false;
20858
+ for (let at = top.separate + 1; at < index; at++) {
20859
+ const item = runs[at];
20860
+ if (item.field?.instr !== instr || item.fieldChar || item.fieldCode !== void 0) continue;
20861
+ if (removed(item)) gone = true;
20862
+ else results.push(at);
20863
+ }
20864
+ found.push({
20865
+ from: top.begin,
20866
+ to: index,
20867
+ instr,
20868
+ locked: top.locked || results.some((at) => isFieldLocked(runs[at])),
20869
+ runs: results,
20870
+ ...names,
20871
+ insertAt: top.separate + 1,
20872
+ ...gone && !results.length ? { removed: true } : {}
20873
+ });
20874
+ }
20875
+ });
20876
+ let simple;
20877
+ let identity;
20878
+ runs.forEach((run, index) => {
20879
+ if (!run.field?.simple) {
20880
+ simple = void 0;
20881
+ return;
20882
+ }
20883
+ if (simple && simple.instr === run.field.instr && identity === run.fieldInstanceId) {
20884
+ if (!removed(run)) simple.runs.push(index);
20885
+ simple.to = index;
20886
+ } else {
20887
+ simple = {
20888
+ from: index,
20889
+ to: index,
20890
+ instr: run.field.instr,
20891
+ locked: false,
20892
+ runs: removed(run) ? [] : [index],
20893
+ insertAt: index
20894
+ };
20895
+ identity = run.fieldInstanceId;
20896
+ found.push(simple);
20897
+ }
20898
+ simple.locked ||= isFieldLocked(run);
20899
+ });
20900
+ return found;
20901
+ }
20902
+ var STRUCTURE = [
20903
+ "fieldChar",
20904
+ "fieldCode",
20905
+ "fieldInstanceId",
20906
+ "fieldFlags",
20907
+ "break",
20908
+ "noteReference",
20909
+ "noteMark",
20910
+ "noteSeparator",
20911
+ "equation",
20912
+ "image"
20913
+ ];
20914
+ var NOT_FORMATTING = [
20915
+ ...STRUCTURE,
20916
+ "text",
20917
+ "field",
20918
+ "revision",
20919
+ "formatRevision",
20920
+ "restoredRunPropertiesXml",
20921
+ "commentIds",
20922
+ "link",
20923
+ "contentControl"
20924
+ ];
20925
+ function withFieldCodeFormatting(result, code2, text3) {
20926
+ const formatted = { ...code2 };
20927
+ const own2 = {};
20928
+ for (const key of NOT_FORMATTING) {
20929
+ delete formatted[key];
20930
+ if (result[key] !== void 0) Object.assign(own2, { [key]: result[key] });
20931
+ }
20932
+ return { ...formatted, ...own2, text: text3 };
20933
+ }
20934
+ function sameRun(a, b) {
20935
+ const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
20936
+ return [...keys].every((key) => JSON.stringify(a[key]) === JSON.stringify(b[key]));
20937
+ }
20938
+ function fieldResultRun(code2, instr, text3) {
20939
+ const formatted = { ...code2 };
20940
+ for (const key of STRUCTURE) delete formatted[key];
20941
+ return { ...formatted, text: text3, field: { instr } };
20942
+ }
20943
+ function replaceFieldResult(runs, field, text3, charFormat) {
20944
+ if (field.resultless) return void 0;
20945
+ const current = field.runs.map((at) => runs[at].text).join("") === text3;
20946
+ const next = [...runs];
20947
+ const [first4, ...rest] = field.runs;
20948
+ const name2 = field.name ?? field.code;
20949
+ if (first4 !== void 0) {
20950
+ const formatted = charFormat && name2 !== void 0 ? withFieldCodeFormatting(runs[first4], runs[name2], text3) : void 0;
20951
+ if (current && (!formatted || sameRun(formatted, runs[first4]) && rest.every((at) => !runs[at].text)))
20952
+ return void 0;
20953
+ next[first4] = formatted ?? { ...runs[first4], text: text3 };
20954
+ for (const at of rest) next[at] = { ...runs[at], text: "" };
20955
+ return next;
20956
+ }
20957
+ const code2 = charFormat ? name2 : field.code;
20958
+ if (current || code2 === void 0 || field.removed) return void 0;
20959
+ next.splice(field.insertAt, 0, fieldResultRun(runs[code2], field.instr, text3));
20960
+ return next;
20961
+ }
20962
+ function paragraphWithResults(paragraph, evaluate) {
20963
+ let runs = paragraph.runs;
20964
+ const start = (field) => field.runs[0] ?? field.insertAt;
20965
+ for (const field of fieldResultSpans(runs).sort((a, b) => start(b) - start(a))) {
20966
+ const update = field.locked ? void 0 : evaluate(field, paragraph);
20967
+ if (update)
20968
+ runs = replaceFieldResult(runs, field, update.text, update.charFormat === true) ?? runs;
20969
+ }
20970
+ return runs === paragraph.runs ? paragraph : { ...paragraph, runs: [...runs] };
20971
+ }
20972
+ function tableWithResults(table, evaluate) {
20973
+ let changed = false;
20974
+ const rows2 = table.rows.map(
20975
+ (row2) => row2.map((cell) => {
20976
+ const paragraphs = cell.paragraphs.map((item) => paragraphWithResults(item, evaluate));
20977
+ const sourceBlocks = cell.sourceBlocks?.map(
20978
+ (item) => item.type === "table" ? tableWithResults(item, evaluate) : item
20979
+ );
20980
+ if (paragraphs.every((item, index) => item === cell.paragraphs[index]) && (sourceBlocks ?? []).every((item, index) => item === cell.sourceBlocks[index]))
20981
+ return cell;
20982
+ changed = true;
20983
+ return { ...cell, paragraphs, ...sourceBlocks ? { sourceBlocks } : {} };
20984
+ })
20985
+ );
20986
+ return changed ? { ...table, rows: rows2 } : table;
20987
+ }
20988
+ function withFieldResults(blocks, evaluate) {
20989
+ let changed = false;
20990
+ const next = blocks.map((block) => {
20991
+ const updated = block.type === "paragraph" ? paragraphWithResults(block, evaluate) : tableWithResults(block, evaluate);
20992
+ changed ||= updated !== block;
20993
+ return updated;
20994
+ });
20995
+ return changed ? next : blocks;
20996
+ }
20997
+
20775
20998
  // docx/field-instruction.ts
20776
20999
  function fieldTokens(instr) {
20777
21000
  const tokens = [];
@@ -20807,19 +21030,19 @@ function fieldTokens(instr) {
20807
21030
  }
20808
21031
  var TEXT_CASES = /* @__PURE__ */ new Set(["upper", "lower", "firstcap", "caps"]);
20809
21032
  var isFieldTextCase = (format) => TEXT_CASES.has(format.toLowerCase());
20810
- function applyFieldTextCase(text2, format) {
20811
- if (format === "upper") return text2.toUpperCase();
20812
- if (format === "lower") return text2.toLowerCase();
21033
+ function applyFieldTextCase(text3, format) {
21034
+ if (format === "upper") return text3.toUpperCase();
21035
+ if (format === "lower") return text3.toLowerCase();
20813
21036
  const capitalize = (word) => word.replace(
20814
21037
  /^(\P{L}*)(\p{L})/u,
20815
21038
  (_match, lead, letter) => `${lead}${letter.toUpperCase()}`
20816
21039
  );
20817
21040
  if (format === "firstcap")
20818
- return text2.replace(
21041
+ return text3.replace(
20819
21042
  /^(\s*)(\S+)/,
20820
21043
  (_match, space, word) => `${space}${capitalize(word)}`
20821
21044
  );
20822
- return text2.replace(/\S+/g, capitalize);
21045
+ return text3.replace(/\S+/g, capitalize);
20823
21046
  }
20824
21047
 
20825
21048
  // docx/cell-blocks.ts
@@ -20859,73 +21082,449 @@ function documentParagraphs(blocks) {
20859
21082
  return result;
20860
21083
  }
20861
21084
 
20862
- // docx/numbering-text.ts
20863
- function romanNumeral(n2) {
20864
- const values = [1e3, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
20865
- const numerals = [
20866
- "M",
20867
- "CM",
20868
- "D",
20869
- "CD",
20870
- "C",
20871
- "XC",
20872
- "L",
20873
- "XL",
20874
- "X",
20875
- "IX",
20876
- "V",
20877
- "IV",
20878
- "I"
20879
- ];
20880
- let remaining = Math.max(1, Math.min(Math.trunc(n2), 3999));
20881
- let result = "";
20882
- for (const [i, value] of values.entries()) {
20883
- while (remaining >= value) {
20884
- result += numerals[i] ?? "";
20885
- remaining -= value;
21085
+ // docx/numbering-counters.ts
21086
+ var NumberingCounters = class {
21087
+ counts = /* @__PURE__ */ new Map();
21088
+ started = /* @__PURE__ */ new Map();
21089
+ forNum(numId) {
21090
+ let counts2 = this.counts.get(numId);
21091
+ if (!counts2) {
21092
+ counts2 = /* @__PURE__ */ new Map();
21093
+ this.counts.set(numId, counts2);
20886
21094
  }
21095
+ return counts2;
20887
21096
  }
20888
- return result;
20889
- }
20890
- var LATIN_LOWER = Array.from("abcdefghijklmnopqrstuvwxyz");
20891
- var MAX_LETTER_LABEL = 64;
20892
- function letterLabel(n2) {
20893
- const index = Math.max(0, Math.trunc(n2) - 1);
20894
- const letter = LATIN_LOWER[index % LATIN_LOWER.length] ?? "a";
20895
- const repeats = Math.min(Math.floor(index / LATIN_LOWER.length) + 1, MAX_LETTER_LABEL);
20896
- return letter.repeat(repeats);
20897
- }
20898
- var ORDINAL_SUFFIX = (n2) => {
20899
- const abs = Math.abs(Math.trunc(n2));
20900
- if (abs % 100 >= 11 && abs % 100 <= 13) return "th";
20901
- switch (abs % 10) {
20902
- case 1:
20903
- return "st";
20904
- case 2:
20905
- return "nd";
20906
- case 3:
20907
- return "rd";
20908
- default:
20909
- return "th";
21097
+ startedLevels(numId) {
21098
+ let started = this.started.get(numId);
21099
+ if (!started) {
21100
+ started = /* @__PURE__ */ new Set();
21101
+ this.started.set(numId, started);
21102
+ }
21103
+ return started;
21104
+ }
21105
+ /** Advances one level and resets deeper counters according to their resolved restart rules. */
21106
+ advance(numId, level3, def, catalog) {
21107
+ const counts2 = this.forNum(numId);
21108
+ const started = this.startedLevels(numId);
21109
+ const next = started.has(level3) ? (counts2.get(level3) ?? def.start) + 1 : def.start;
21110
+ counts2.set(level3, next);
21111
+ started.add(level3);
21112
+ for (const deeper of [...started]) {
21113
+ if (deeper <= level3) continue;
21114
+ const deeperDef = resolveNumberingLevel(catalog, numId, deeper);
21115
+ const restart = deeperDef?.lvlRestart;
21116
+ if (restart === 0) continue;
21117
+ const trigger = restart !== void 0 && restart > 0 && restart <= deeper ? restart - 1 : deeper - 1;
21118
+ if (level3 > trigger) continue;
21119
+ counts2.delete(deeper);
21120
+ started.delete(deeper);
21121
+ }
21122
+ for (let ancestor = 0; ancestor < level3; ancestor++) {
21123
+ if (started.has(ancestor)) continue;
21124
+ const ancestorDef = resolveNumberingLevel(catalog, numId, ancestor);
21125
+ if (!ancestorDef) continue;
21126
+ counts2.set(ancestor, ancestorDef.start);
21127
+ started.add(ancestor);
21128
+ }
21129
+ return next;
21130
+ }
21131
+ /** Sets a level's value, as a LISTNUM `\s` start does, restarting the deeper levels. */
21132
+ set(numId, level3, value) {
21133
+ const counts2 = this.forNum(numId);
21134
+ const started = this.startedLevels(numId);
21135
+ counts2.set(level3, value);
21136
+ started.add(level3);
21137
+ for (const deeper of [...started])
21138
+ if (deeper > level3) {
21139
+ counts2.delete(deeper);
21140
+ started.delete(deeper);
21141
+ }
21142
+ }
21143
+ /** Current value for an ancestor placeholder, defaulting to its own start when never instantiated. */
21144
+ current(numId, level3, start) {
21145
+ return this.forNum(numId).get(level3) ?? start;
20910
21146
  }
20911
21147
  };
20912
- function ordinalNumeral(n2) {
20913
- return `${Math.trunc(n2)}${ORDINAL_SUFFIX(n2)}`;
21148
+ function substituteLvlText(lvlText, numId, level3, catalog, counters, forceDecimal) {
21149
+ return lvlText.replace(/%([1-9])/g, (match, digit) => {
21150
+ const ancestorLevel = Number(digit) - 1;
21151
+ if (ancestorLevel > level3) return match;
21152
+ const ancestorDef = resolveNumberingLevel(catalog, numId, ancestorLevel);
21153
+ const start = ancestorDef?.start ?? 1;
21154
+ const value = counters.current(numId, ancestorLevel, start);
21155
+ const fmt = forceDecimal ? "decimal" : ancestorDef?.numFmt ?? "decimal";
21156
+ return formatListNumber(fmt, value);
21157
+ });
20914
21158
  }
20915
- var ONES = [
20916
- "",
20917
- "one",
20918
- "two",
20919
- "three",
20920
- "four",
20921
- "five",
20922
- "six",
20923
- "seven",
20924
- "eight",
20925
- "nine",
20926
- "ten",
20927
- "eleven",
20928
- "twelve",
21159
+
21160
+ // docx/outline-numbering.ts
21161
+ var OUTLINE_NUMBERING = [
21162
+ ["", "upperRoman", "."],
21163
+ ["", "upperLetter", "."],
21164
+ ["", "decimal", "."],
21165
+ ["", "lowerLetter", ")"],
21166
+ ["(", "decimal", ")"],
21167
+ ["(", "lowerLetter", ")"],
21168
+ ["(", "lowerRoman", ")"],
21169
+ ["(", "lowerLetter", ")"],
21170
+ ["(", "lowerRoman", ")"]
21171
+ ];
21172
+
21173
+ // docx/field-runs.ts
21174
+ function fieldName(instr) {
21175
+ return instr.trim().split(/\s+/)[0]?.toUpperCase() ?? "";
21176
+ }
21177
+
21178
+ // text/date-picture.ts
21179
+ var TOKENS = /yyyy|yy|MMMM|MMM|MM|M|dddd|ddd|dd|d|EEEE|EEE|HH|H|hh|h|mm|m|ss|s|tt|am\/pm|AM\/PM|A\/P|a\/p|'[^']*'|"[^"]*"/g;
21180
+ var pad2 = (value, length = 2) => String(value).padStart(length, "0");
21181
+ function name(date2, locale, utc, options2) {
21182
+ try {
21183
+ return new Intl.DateTimeFormat(locale, utc ? { ...options2, timeZone: "UTC" } : options2).format(
21184
+ date2
21185
+ );
21186
+ } catch {
21187
+ return new Intl.DateTimeFormat("en-US", utc ? { ...options2, timeZone: "UTC" } : options2).format(
21188
+ date2
21189
+ );
21190
+ }
21191
+ }
21192
+ function formatDatePicture(date2, picture, options2 = {}) {
21193
+ const locale = options2.locale ?? "en-US";
21194
+ const utc = options2.utc ?? false;
21195
+ const year = utc ? date2.getUTCFullYear() : date2.getFullYear();
21196
+ const month = utc ? date2.getUTCMonth() : date2.getMonth();
21197
+ const day = utc ? date2.getUTCDate() : date2.getDate();
21198
+ const hours = utc ? date2.getUTCHours() : date2.getHours();
21199
+ const minutes = utc ? date2.getUTCMinutes() : date2.getMinutes();
21200
+ const seconds = utc ? date2.getUTCSeconds() : date2.getSeconds();
21201
+ const hours12 = hours % 12 || 12;
21202
+ const label = (options3) => name(date2, locale, utc, options3);
21203
+ return picture.replace(TOKENS, (token) => {
21204
+ switch (token) {
21205
+ case "yyyy":
21206
+ return pad2(year, 4);
21207
+ case "yy":
21208
+ return pad2(year % 100);
21209
+ case "MMMM":
21210
+ return label({ month: "long" });
21211
+ case "MMM":
21212
+ return label({ month: "short" });
21213
+ case "MM":
21214
+ return pad2(month + 1);
21215
+ case "M":
21216
+ return String(month + 1);
21217
+ case "dddd":
21218
+ case "EEEE":
21219
+ return label({ weekday: "long" });
21220
+ case "ddd":
21221
+ case "EEE":
21222
+ return label({ weekday: "short" });
21223
+ case "dd":
21224
+ return pad2(day);
21225
+ case "d":
21226
+ return String(day);
21227
+ case "HH":
21228
+ return pad2(hours);
21229
+ case "H":
21230
+ return String(hours);
21231
+ case "hh":
21232
+ return pad2(hours12);
21233
+ case "h":
21234
+ return String(hours12);
21235
+ case "mm":
21236
+ return pad2(minutes);
21237
+ case "m":
21238
+ return String(minutes);
21239
+ case "ss":
21240
+ return pad2(seconds);
21241
+ case "s":
21242
+ return String(seconds);
21243
+ case "tt":
21244
+ case "AM/PM":
21245
+ return hours < 12 ? "AM" : "PM";
21246
+ case "am/pm":
21247
+ return hours < 12 ? "am" : "pm";
21248
+ case "A/P":
21249
+ return hours < 12 ? "A" : "P";
21250
+ case "a/p":
21251
+ return hours < 12 ? "a" : "p";
21252
+ default:
21253
+ return token.slice(1, -1);
21254
+ }
21255
+ });
21256
+ }
21257
+
21258
+ // docx/field-date.ts
21259
+ function datePicture(instr) {
21260
+ const match = /\\@\s*(?:"([^"]*)"|(\S+))/.exec(instr);
21261
+ return match ? match[1] ?? match[2] : void 0;
21262
+ }
21263
+ function formatWordDate(date2, picture, locale = "en-US") {
21264
+ return formatDatePicture(date2, picture, { locale });
21265
+ }
21266
+ function dateFieldResult(name2, instr, now, locale) {
21267
+ const picture = datePicture(instr) ?? (name2 === "DATE" ? "M/d/yyyy" : "h:mm am/pm");
21268
+ return formatWordDate(now, picture, locale);
21269
+ }
21270
+
21271
+ // docx/field-format.ts
21272
+ function numberFormat(argument) {
21273
+ const lower = argument.toLowerCase();
21274
+ const upper = argument[0] !== argument[0].toLowerCase();
21275
+ if (lower === "arabic") return "decimal";
21276
+ if (lower === "roman") return upper ? "upperRoman" : "lowerRoman";
21277
+ if (lower === "alphabetic") return upper ? "upperLetter" : "lowerLetter";
21278
+ if (lower === "cardtext") return "cardinalText";
21279
+ if (lower === "ordtext") return "ordinalText";
21280
+ if (lower === "ordinal") return "ordinal";
21281
+ if (lower === "hex") return "hex";
21282
+ if (lower === "arabicdash") return "arabicDash";
21283
+ return void 0;
21284
+ }
21285
+ function parseFieldInstruction(instr, own2 = {}) {
21286
+ const tokens = fieldTokens(instr);
21287
+ const head2 = tokens[0];
21288
+ if (head2?.kind !== "text") return void 0;
21289
+ const field = {
21290
+ name: head2.value.toUpperCase(),
21291
+ args: [],
21292
+ switches: /* @__PURE__ */ new Map(),
21293
+ format: { steps: [] }
21294
+ };
21295
+ for (let index = 1; index < tokens.length; index++) {
21296
+ const token = tokens[index];
21297
+ if (token.kind === "text") {
21298
+ field.args.push(token.value);
21299
+ continue;
21300
+ }
21301
+ const argument = () => {
21302
+ const next = tokens[index + 1];
21303
+ if (next?.kind !== "text") return void 0;
21304
+ index++;
21305
+ return next.value;
21306
+ };
21307
+ if (token.value === "*") {
21308
+ const format = argument();
21309
+ if (format === void 0) return void 0;
21310
+ const lower = format.toLowerCase();
21311
+ if (lower === "mergeformat") continue;
21312
+ if (lower === "charformat") field.format.charFormat = true;
21313
+ else if (isFieldTextCase(lower)) field.format.steps.push({ kind: "case", textCase: lower });
21314
+ else {
21315
+ const numFmt = numberFormat(format);
21316
+ if (!numFmt) return void 0;
21317
+ field.format.steps.push({ kind: "number", numFmt });
21318
+ }
21319
+ } else if (token.value === "@") {
21320
+ const picture = argument();
21321
+ if (picture === void 0) return void 0;
21322
+ field.format.datePicture = picture;
21323
+ } else if (token.value === "!") continue;
21324
+ else if (own2[token.value] === "arg") {
21325
+ const value = argument();
21326
+ field.switches.set(token.value, value ?? true);
21327
+ } else if (own2[token.value] === "flag") field.switches.set(token.value, true);
21328
+ else return void 0;
21329
+ }
21330
+ return field;
21331
+ }
21332
+ function formatFieldNumber(value, numFmt) {
21333
+ const whole = Math.round(value);
21334
+ if (numFmt === "arabicDash") return `- ${whole} -`;
21335
+ return formatListNumber(numFmt, whole);
21336
+ }
21337
+ function applyFieldFormat(text3, format) {
21338
+ let result = text3;
21339
+ for (const step of format.steps) {
21340
+ if (step.kind === "case") result = applyFieldTextCase(result, step.textCase);
21341
+ else if (/^\s*-?\d+(\.\d+)?\s*$/.test(result))
21342
+ result = formatFieldNumber(Number(result), step.numFmt);
21343
+ }
21344
+ return result;
21345
+ }
21346
+ function fieldDateResult(date2, format) {
21347
+ return format.datePicture === void 0 ? void 0 : applyFieldFormat(formatWordDate(date2, format.datePicture), format);
21348
+ }
21349
+
21350
+ // docx/list-number-fields.ts
21351
+ var DEFAULT_LISTS = ["NumberDefault", "OutlineDefault", "LegalDefault"];
21352
+ var DEFAULT_ID = "\0listnum";
21353
+ var FORMATS = {
21354
+ NumberDefault: [
21355
+ ["", "decimal", ")"],
21356
+ ["", "lowerLetter", ")"],
21357
+ ["", "lowerRoman", ")"],
21358
+ ["(", "decimal", ")"],
21359
+ ["(", "lowerLetter", ")"],
21360
+ ["(", "lowerRoman", ")"],
21361
+ ["", "decimal", "."],
21362
+ ["", "lowerLetter", "."],
21363
+ ["", "lowerRoman", "."]
21364
+ ],
21365
+ OutlineDefault: OUTLINE_NUMBERING
21366
+ };
21367
+ var level2 = (index) => ({
21368
+ level: index,
21369
+ start: 1,
21370
+ numFmt: "decimal",
21371
+ lvlText: ""
21372
+ });
21373
+ var DEFAULT_CATALOG = {
21374
+ abstractNums: {
21375
+ [DEFAULT_ID]: {
21376
+ id: DEFAULT_ID,
21377
+ levels: Object.fromEntries([...Array(9).keys()].map((i) => [i, level2(i)]))
21378
+ }
21379
+ },
21380
+ nums: { [DEFAULT_ID]: { id: DEFAULT_ID, abstractNumId: DEFAULT_ID } },
21381
+ warnings: []
21382
+ };
21383
+ var keyOf = (target) => target.kind === "default" ? target.name : `#${target.numId}`;
21384
+ var isListNum = (field) => fieldName(field.instr) === "LISTNUM";
21385
+ var ListNumberFields = class {
21386
+ constructor(counters, catalog) {
21387
+ this.counters = counters;
21388
+ this.catalog = catalog;
21389
+ }
21390
+ counters;
21391
+ catalog;
21392
+ results = /* @__PURE__ */ new Map();
21393
+ context = { kind: "default", name: "NumberDefault" };
21394
+ leadLevels = /* @__PURE__ */ new Map();
21395
+ /** What the LISTNUM starting at run `from` of a paragraph (or with its result there) shows. */
21396
+ result(paragraphId, from) {
21397
+ return this.results.get(paragraphId)?.get(from);
21398
+ }
21399
+ /**
21400
+ * Counts a paragraph's LISTNUM fields, after its own list number (`numbering`, its list and
21401
+ * zero-based level, when it has one).
21402
+ */
21403
+ paragraph(paragraph, numbering) {
21404
+ if (numbering) this.context = { kind: "num", numId: numbering.numId };
21405
+ if (!paragraph.runs.some((run) => /LISTNUM/i.test(run.fieldCode ?? run.field?.instr ?? "")))
21406
+ return;
21407
+ const fields = fieldResultSpans(paragraph.runs, { resultless: true }).filter(isListNum).sort((a, b) => a.from - b.from);
21408
+ const blank = (from, to) => paragraph.runs.slice(from, to).every((run) => run.fieldCode !== void 0 || !/\S/.test(run.text));
21409
+ const leads = fields.length > 0 && blank(0, fields[0].from);
21410
+ let leading = leads;
21411
+ let previous;
21412
+ let end = -1;
21413
+ const shown = /* @__PURE__ */ new Map();
21414
+ for (const field of fields) {
21415
+ leading &&= blank(end + 1, field.from);
21416
+ end = field.to;
21417
+ const parsed = parseFieldInstruction(field.instr, { l: "arg", s: "arg" });
21418
+ if (!parsed) continue;
21419
+ const name2 = parsed.args[0];
21420
+ const named3 = name2 && DEFAULT_LISTS.find((item) => item.toLowerCase() === name2.toLowerCase());
21421
+ if (name2 && !named3) continue;
21422
+ const target = named3 ? { kind: "default", name: named3 } : numbering ? { kind: "num", numId: numbering.numId } : this.context;
21423
+ if (named3 && !numbering) this.context = target;
21424
+ const given = parsed.switches.get("l");
21425
+ const explicit = typeof given === "string" && /^-?\d+$/.test(given) ? Math.min(9, Math.max(1, Number(given))) : void 0;
21426
+ const own2 = explicit ?? (previous === void 0 ? numbering && !named3 ? numbering.level + 1 : this.leadLevels.get(keyOf(target)) ?? 1 : leads ? Math.min(9, previous + 1) : previous);
21427
+ const start = parsed.switches.get("s");
21428
+ const text3 = this.count(
21429
+ target,
21430
+ own2 - 1,
21431
+ typeof start === "string" && /^\d+$/.test(start) ? Number(start) : void 0
21432
+ );
21433
+ if (text3 === void 0) continue;
21434
+ for (const at of [field.from, ...field.runs]) shown.set(at, text3);
21435
+ if (leading) this.leadLevels.set(keyOf(target), own2);
21436
+ previous = own2;
21437
+ }
21438
+ if (shown.size) this.results.set(paragraph.id, shown);
21439
+ }
21440
+ /** Advances `target` at zero-based level `wanted` (or sets it to `start`) and draws its number. */
21441
+ count(target, wanted, start) {
21442
+ const numId = target.kind === "default" ? DEFAULT_ID : target.numId;
21443
+ const catalog = target.kind === "default" ? DEFAULT_CATALOG : this.catalog;
21444
+ if (!catalog) return void 0;
21445
+ let index = wanted;
21446
+ let def = resolveNumberingLevel(catalog, numId, index);
21447
+ while (!def && index > 0) def = resolveNumberingLevel(catalog, numId, --index);
21448
+ if (!def) return void 0;
21449
+ if (start === void 0) this.counters.advance(numId, index, def, catalog);
21450
+ else this.counters.set(numId, index, start);
21451
+ if (target.kind === "num")
21452
+ return def.numFmt === "bullet" ? displayListLabel(def.lvlText) : substituteLvlText(def.lvlText, numId, index, catalog, this.counters, Boolean(def.isLgl));
21453
+ const value = (at) => this.counters.current(DEFAULT_ID, at, 1);
21454
+ if (target.name === "LegalDefault")
21455
+ return `${[...Array(index + 1).keys()].map(value).join(".")}.`;
21456
+ const [open, numFmt, close] = FORMATS[target.name][index];
21457
+ return `${open}${formatListNumber(numFmt, value(index))}${close}`;
21458
+ }
21459
+ };
21460
+
21461
+ // docx/numbering-text.ts
21462
+ function romanNumeral(n2) {
21463
+ const values = [1e3, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
21464
+ const numerals = [
21465
+ "M",
21466
+ "CM",
21467
+ "D",
21468
+ "CD",
21469
+ "C",
21470
+ "XC",
21471
+ "L",
21472
+ "XL",
21473
+ "X",
21474
+ "IX",
21475
+ "V",
21476
+ "IV",
21477
+ "I"
21478
+ ];
21479
+ let remaining = Math.max(1, Math.min(Math.trunc(n2), 3999));
21480
+ let result = "";
21481
+ for (const [i, value] of values.entries()) {
21482
+ while (remaining >= value) {
21483
+ result += numerals[i] ?? "";
21484
+ remaining -= value;
21485
+ }
21486
+ }
21487
+ return result;
21488
+ }
21489
+ var LATIN_LOWER = Array.from("abcdefghijklmnopqrstuvwxyz");
21490
+ var MAX_LETTER_LABEL = 64;
21491
+ function letterLabel(n2) {
21492
+ const index = Math.max(0, Math.trunc(n2) - 1);
21493
+ const letter = LATIN_LOWER[index % LATIN_LOWER.length] ?? "a";
21494
+ const repeats = Math.min(Math.floor(index / LATIN_LOWER.length) + 1, MAX_LETTER_LABEL);
21495
+ return letter.repeat(repeats);
21496
+ }
21497
+ var ORDINAL_SUFFIX = (n2) => {
21498
+ const abs = Math.abs(Math.trunc(n2));
21499
+ if (abs % 100 >= 11 && abs % 100 <= 13) return "th";
21500
+ switch (abs % 10) {
21501
+ case 1:
21502
+ return "st";
21503
+ case 2:
21504
+ return "nd";
21505
+ case 3:
21506
+ return "rd";
21507
+ default:
21508
+ return "th";
21509
+ }
21510
+ };
21511
+ function ordinalNumeral(n2) {
21512
+ return `${Math.trunc(n2)}${ORDINAL_SUFFIX(n2)}`;
21513
+ }
21514
+ var ONES = [
21515
+ "",
21516
+ "one",
21517
+ "two",
21518
+ "three",
21519
+ "four",
21520
+ "five",
21521
+ "six",
21522
+ "seven",
21523
+ "eight",
21524
+ "nine",
21525
+ "ten",
21526
+ "eleven",
21527
+ "twelve",
20929
21528
  "thirteen",
20930
21529
  "fourteen",
20931
21530
  "fifteen",
@@ -21018,108 +21617,57 @@ function resolveParagraphNumbering(paragraph, styleCatalog, numberingCatalog) {
21018
21617
  const inherited = resolveStyleNumbering(paragraph.style, styleCatalog);
21019
21618
  if (!inherited || inherited.numId <= 0) return void 0;
21020
21619
  if (numberingCatalog && paragraph.style && styleCatalog.styles[paragraph.style]) {
21021
- for (let level2 = 0; level2 < 9; level2++) {
21022
- const definition = resolveNumberingLevel(numberingCatalog, String(inherited.numId), level2);
21620
+ for (let level3 = 0; level3 < 9; level3++) {
21621
+ const definition = resolveNumberingLevel(numberingCatalog, String(inherited.numId), level3);
21023
21622
  if (definition?.paragraphStyleId === paragraph.style)
21024
- return { numId: inherited.numId, level: level2 };
21623
+ return { numId: inherited.numId, level: level3 };
21025
21624
  }
21026
21625
  }
21027
21626
  return inherited;
21028
21627
  }
21029
- var NumberingCounters = class {
21030
- counts = /* @__PURE__ */ new Map();
21031
- started = /* @__PURE__ */ new Map();
21032
- forNum(numId) {
21033
- let counts = this.counts.get(numId);
21034
- if (!counts) {
21035
- counts = /* @__PURE__ */ new Map();
21036
- this.counts.set(numId, counts);
21037
- }
21038
- return counts;
21039
- }
21040
- startedLevels(numId) {
21041
- let started = this.started.get(numId);
21042
- if (!started) {
21043
- started = /* @__PURE__ */ new Set();
21044
- this.started.set(numId, started);
21045
- }
21046
- return started;
21047
- }
21048
- /** Advances one level and resets deeper counters according to their resolved restart rules. */
21049
- advance(numId, level2, def, catalog) {
21050
- const counts = this.forNum(numId);
21051
- const started = this.startedLevels(numId);
21052
- const next = started.has(level2) ? (counts.get(level2) ?? def.start) + 1 : def.start;
21053
- counts.set(level2, next);
21054
- started.add(level2);
21055
- for (const deeper of [...started]) {
21056
- if (deeper <= level2) continue;
21057
- const deeperDef = resolveNumberingLevel(catalog, numId, deeper);
21058
- const restart = deeperDef?.lvlRestart;
21059
- if (restart === 0) continue;
21060
- const trigger = restart !== void 0 && restart > 0 && restart <= deeper ? restart - 1 : deeper - 1;
21061
- if (level2 > trigger) continue;
21062
- counts.delete(deeper);
21063
- started.delete(deeper);
21064
- }
21065
- for (let ancestor = 0; ancestor < level2; ancestor++) {
21066
- if (started.has(ancestor)) continue;
21067
- const ancestorDef = resolveNumberingLevel(catalog, numId, ancestor);
21068
- if (!ancestorDef) continue;
21069
- counts.set(ancestor, ancestorDef.start);
21070
- started.add(ancestor);
21071
- }
21072
- return next;
21073
- }
21074
- /** Current value for an ancestor placeholder, defaulting to its own start when never instantiated. */
21075
- current(numId, level2, start) {
21076
- return this.forNum(numId).get(level2) ?? start;
21077
- }
21078
- };
21079
- function substituteLvlText(lvlText, numId, level2, catalog, counters, forceDecimal) {
21080
- return lvlText.replace(/%([1-9])/g, (match, digit) => {
21081
- const ancestorLevel = Number(digit) - 1;
21082
- if (ancestorLevel > level2) return match;
21083
- const ancestorDef = resolveNumberingLevel(catalog, numId, ancestorLevel);
21084
- const start = ancestorDef?.start ?? 1;
21085
- const value = counters.current(numId, ancestorLevel, start);
21086
- const fmt = forceDecimal ? "decimal" : ancestorDef?.numFmt ?? "decimal";
21087
- return formatListNumber(fmt, value);
21088
- });
21089
- }
21090
- function computeListLabels(model) {
21628
+ function computeListNumbering(model) {
21091
21629
  const catalog = model.numberingCatalog;
21092
21630
  const labels = /* @__PURE__ */ new Map();
21093
- if (!catalog) return labels;
21094
21631
  const counters = new NumberingCounters();
21632
+ const listNumbers = new ListNumberFields(counters, catalog);
21095
21633
  for (const paragraph of documentParagraphs(model.blocks)) {
21096
- const numbering = resolveParagraphNumbering(paragraph, model.paragraphStyles, catalog);
21097
- if (!numbering) continue;
21098
- const numId = String(numbering.numId);
21099
- const level2 = Math.min(8, Math.max(0, numbering.level));
21100
- const def = resolveNumberingLevel(catalog, numId, level2);
21101
- if (!def) continue;
21102
- if (def.numFmt === "none") continue;
21103
- counters.advance(numId, level2, def, catalog);
21104
- const text2 = def.numFmt === "bullet" ? def.lvlText : substituteLvlText(def.lvlText, numId, level2, catalog, counters, Boolean(def.isLgl));
21105
- const picture = def.pictureBulletId !== void 0 ? catalog.pictureBullets?.[def.pictureBulletId] : void 0;
21106
- labels.set(paragraph.id, {
21107
- numId,
21108
- level: level2,
21109
- text: text2,
21110
- suffix: def.suffix ?? "tab",
21111
- ...definedProps({
21112
- alignment: def.lvlJc,
21113
- indentLeftTwips: def.indentLeftTwips,
21114
- hangingTwips: def.hangingTwips,
21115
- firstLineTwips: def.firstLineTwips,
21116
- markerFormat: def.markerFormat,
21117
- tabStopTwips: def.tabStopTwips,
21118
- picture
21119
- })
21120
- });
21634
+ const label = catalog && paragraphLabel(paragraph, model, catalog, counters);
21635
+ if (label) labels.set(paragraph.id, label);
21636
+ listNumbers.paragraph(
21637
+ paragraph,
21638
+ label ? { numId: label.numId, level: label.level } : void 0
21639
+ );
21121
21640
  }
21122
- return labels;
21641
+ return { labels, listNumbers };
21642
+ }
21643
+ function computeListLabels(model) {
21644
+ return computeListNumbering(model).labels;
21645
+ }
21646
+ function paragraphLabel(paragraph, model, catalog, counters) {
21647
+ const numbering = resolveParagraphNumbering(paragraph, model.paragraphStyles, catalog);
21648
+ if (!numbering) return void 0;
21649
+ const numId = String(numbering.numId);
21650
+ const level3 = Math.min(8, Math.max(0, numbering.level));
21651
+ const def = resolveNumberingLevel(catalog, numId, level3);
21652
+ if (!def || def.numFmt === "none") return void 0;
21653
+ counters.advance(numId, level3, def, catalog);
21654
+ const text3 = def.numFmt === "bullet" ? def.lvlText : substituteLvlText(def.lvlText, numId, level3, catalog, counters, Boolean(def.isLgl));
21655
+ const picture = def.pictureBulletId !== void 0 ? catalog.pictureBullets?.[def.pictureBulletId] : void 0;
21656
+ return {
21657
+ numId,
21658
+ level: level3,
21659
+ text: text3,
21660
+ suffix: def.suffix ?? "tab",
21661
+ ...definedProps({
21662
+ alignment: def.lvlJc,
21663
+ indentLeftTwips: def.indentLeftTwips,
21664
+ hangingTwips: def.hangingTwips,
21665
+ firstLineTwips: def.firstLineTwips,
21666
+ markerFormat: def.markerFormat,
21667
+ tabStopTwips: def.tabStopTwips,
21668
+ picture
21669
+ })
21670
+ };
21123
21671
  }
21124
21672
  var SYMBOL_BULLETS = {
21125
21673
  "\uF0B7": "\u2022",
@@ -21132,8 +21680,8 @@ var SYMBOL_BULLETS = {
21132
21680
  "\uF0E0": "\u27A9",
21133
21681
  "\uF0B2": "\u25CB"
21134
21682
  };
21135
- function displayListLabel(text2) {
21136
- return text2.replace(/[-]/g, (char) => SYMBOL_BULLETS[char] ?? "\u2022");
21683
+ function displayListLabel(text3) {
21684
+ return text3.replace(/[-]/g, (char) => SYMBOL_BULLETS[char] ?? "\u2022");
21137
21685
  }
21138
21686
 
21139
21687
  // docx/style-ref.ts
@@ -21183,10 +21731,10 @@ function styleTarget(model, style) {
21183
21731
  id: definition.id,
21184
21732
  ...definition.isDefault ? { isDefault: true } : {}
21185
21733
  };
21186
- const character = (definition) => definition && { kind: "character", id: definition.id };
21734
+ const character2 = (definition) => definition && { kind: "character", id: definition.id };
21187
21735
  const named3 = (list) => list.find((definition) => definition.name?.toLowerCase() === key);
21188
21736
  const withId = (list) => list.find((definition) => definition.id === name2) ?? list.find((definition) => definition.id.toLowerCase() === key);
21189
- return paragraph(named3(paragraphs)) ?? character(named3(characters)) ?? paragraph(withId(paragraphs)) ?? character(withId(characters));
21737
+ return paragraph(named3(paragraphs)) ?? character2(named3(characters)) ?? paragraph(withId(paragraphs)) ?? character2(withId(characters));
21190
21738
  }
21191
21739
  var shownText = (run) => run.vanish || run.revision?.kind === "delete" || run.revision?.kind === "moveFrom" ? "" : run.text;
21192
21740
  function characterPortions(paragraph, id, hidden, skip) {
@@ -21202,11 +21750,11 @@ function characterPortions(paragraph, id, hidden, skip) {
21202
21750
  open = void 0;
21203
21751
  return;
21204
21752
  }
21205
- const text2 = hidden(run, paragraph) ? "" : run.text;
21753
+ const text3 = hidden(run, paragraph) ? "" : run.text;
21206
21754
  if (open) {
21207
- open.text += text2;
21755
+ open.text += text3;
21208
21756
  open.to = index;
21209
- } else portions.push(open = { text: text2, from: index, to: index });
21757
+ } else portions.push(open = { text: text3, from: index, to: index });
21210
21758
  });
21211
21759
  return portions;
21212
21760
  }
@@ -21228,20 +21776,20 @@ function styleRefSource(model) {
21228
21776
  labels ??= computeListLabels(model);
21229
21777
  const label = labels.get(paragraph.id);
21230
21778
  if (!label || !model.numberingCatalog) return "0";
21231
- const level2 = resolveNumberingLevel(model.numberingCatalog, label.numId, label.level);
21232
- if (!level2 || level2.numFmt === "bullet") return null;
21233
- let text2 = label.text;
21779
+ const level3 = resolveNumberingLevel(model.numberingCatalog, label.numId, label.level);
21780
+ if (!level3 || level3.numFmt === "bullet") return null;
21781
+ let text3 = label.text;
21234
21782
  if (numberOnly) {
21235
- const first3 = level2.lvlText.indexOf("%");
21236
- const end = level2.lvlText.search(/%[1-9](?!.*%[1-9])/);
21237
- const prefix2 = first3 < 0 ? "" : level2.lvlText.slice(0, first3);
21238
- const suffix = end < 0 ? "" : level2.lvlText.slice(end + 2);
21239
- const inner = first3 < 0 || end < 0 ? "" : level2.lvlText.slice(first3, end + 2);
21783
+ const first4 = level3.lvlText.indexOf("%");
21784
+ const end = level3.lvlText.search(/%[1-9](?!.*%[1-9])/);
21785
+ const prefix2 = first4 < 0 ? "" : level3.lvlText.slice(0, first4);
21786
+ const suffix = end < 0 ? "" : level3.lvlText.slice(end + 2);
21787
+ const inner = first4 < 0 || end < 0 ? "" : level3.lvlText.slice(first4, end + 2);
21240
21788
  if (/\p{L}/u.test(inner.replace(/%[1-9]/g, ""))) return null;
21241
- if (prefix2 && text2.startsWith(prefix2)) text2 = text2.slice(prefix2.length);
21242
- if (suffix && text2.endsWith(suffix)) text2 = text2.slice(0, -suffix.length);
21789
+ if (prefix2 && text3.startsWith(prefix2)) text3 = text3.slice(prefix2.length);
21790
+ if (suffix && text3.endsWith(suffix)) text3 = text3.slice(0, -suffix.length);
21243
21791
  }
21244
- return text2.trim().replace(/\.+$/, "");
21792
+ return text3.trim().replace(/\.+$/, "");
21245
21793
  };
21246
21794
  const portions = (at, reference, target, skip) => {
21247
21795
  const paragraph = paragraphs[at];
@@ -21278,164 +21826,299 @@ function styleRefSource(model) {
21278
21826
  }
21279
21827
 
21280
21828
  // docx/style-ref-fields.ts
21281
- var removed = (run) => run.revision?.kind === "delete" || run.revision?.kind === "moveFrom";
21282
- function fieldResults(runs) {
21283
- const found = [];
21284
- const open = [];
21285
- runs.forEach((run, index) => {
21286
- const top = open.at(-1);
21287
- if (run.fieldChar === "begin")
21288
- open.push({ begin: index, code: "", locked: isFieldLocked(run) });
21289
- else if (run.fieldCode !== void 0 && top && top.separate === void 0) {
21290
- top.code += run.fieldCode;
21291
- top.codeRun ??= index;
21292
- if (top.nameRun === void 0 && /\S/.test(run.fieldCode)) top.nameRun = index;
21293
- } else if (run.fieldChar === "separate" && top) top.separate = index;
21294
- else if (run.fieldChar === "end" && top) {
21295
- open.pop();
21296
- if (top.separate === void 0) return;
21297
- const instr = top.code.trim();
21298
- const results = [];
21299
- let gone = false;
21300
- for (let at = top.separate + 1; at < index; at++) {
21301
- const item = runs[at];
21302
- if (item.field?.instr !== instr || item.fieldChar || item.fieldCode !== void 0) continue;
21303
- if (removed(item)) gone = true;
21304
- else results.push(at);
21305
- }
21306
- found.push({
21307
- from: top.begin,
21308
- to: index,
21309
- instr,
21310
- locked: top.locked || results.some((at) => isFieldLocked(runs[at])),
21311
- runs: results,
21312
- ...top.codeRun !== void 0 ? { code: top.codeRun } : {},
21313
- ...top.nameRun !== void 0 ? { name: top.nameRun } : {},
21314
- insertAt: top.separate + 1,
21315
- ...gone && !results.length ? { removed: true } : {}
21316
- });
21317
- }
21318
- });
21319
- let simple;
21320
- let identity;
21321
- runs.forEach((run, index) => {
21322
- if (!run.field?.simple) {
21323
- simple = void 0;
21324
- return;
21325
- }
21326
- if (simple && simple.instr === run.field.instr && identity === run.fieldInstanceId) {
21327
- if (!removed(run)) simple.runs.push(index);
21328
- simple.to = index;
21329
- } else {
21330
- simple = {
21331
- from: index,
21332
- to: index,
21333
- instr: run.field.instr,
21334
- locked: false,
21335
- runs: removed(run) ? [] : [index],
21336
- insertAt: index
21337
- };
21338
- identity = run.fieldInstanceId;
21339
- found.push(simple);
21340
- }
21341
- simple.locked ||= isFieldLocked(run);
21829
+ function withStyleRefResults(blocks, evaluate) {
21830
+ return withFieldResults(blocks, (field, paragraph) => {
21831
+ const reference = parseStyleReference(field.instr);
21832
+ const text3 = reference && evaluate(reference, paragraph, field);
21833
+ return text3 === void 0 ? void 0 : { text: text3, charFormat: reference?.charFormat === true };
21342
21834
  });
21343
- return found;
21344
21835
  }
21345
- var STRUCTURE = [
21346
- "fieldChar",
21347
- "fieldCode",
21348
- "fieldInstanceId",
21349
- "fieldFlags",
21350
- "break",
21351
- "noteReference",
21352
- "noteMark",
21353
- "noteSeparator",
21354
- "equation",
21355
- "image"
21356
- ];
21357
- var NOT_FORMATTING = [
21358
- ...STRUCTURE,
21359
- "text",
21360
- "field",
21361
- "revision",
21362
- "formatRevision",
21363
- "restoredRunPropertiesXml",
21364
- "commentIds",
21365
- "link",
21366
- "contentControl"
21367
- ];
21368
- function withFieldCodeFormatting(result, code, text2) {
21369
- const formatted = { ...code };
21370
- const own2 = {};
21371
- for (const key of NOT_FORMATTING) {
21372
- delete formatted[key];
21373
- if (result[key] !== void 0) Object.assign(own2, { [key]: result[key] });
21374
- }
21375
- return { ...formatted, ...own2, text: text2 };
21836
+
21837
+ // docx/auto-number-fields.ts
21838
+ var AUTO_NUMBER_FIELDS = /* @__PURE__ */ new Set([
21839
+ "AUTONUM",
21840
+ "AUTONUMLGL",
21841
+ "AUTONUMOUT"
21842
+ ]);
21843
+ function counts(paragraph) {
21844
+ return fieldResultSpans(paragraph.runs, { resultless: true }).some(
21845
+ (field) => AUTO_NUMBER_FIELDS.has(fieldName(field.instr))
21846
+ );
21376
21847
  }
21377
- function replaceResult(runs, field, text2, charFormat) {
21378
- const current = field.runs.map((at) => runs[at].text).join("") === text2;
21379
- const next = [...runs];
21380
- const [first3, ...rest] = field.runs;
21381
- const name2 = field.name ?? field.code;
21382
- if (first3 !== void 0) {
21383
- const formatted = charFormat && name2 !== void 0 ? withFieldCodeFormatting(runs[first3], runs[name2], text2) : void 0;
21384
- if (current && (!formatted || sameRun(formatted, runs[first3]) && rest.every((at) => !runs[at].text)))
21848
+ function autoNumberStates(model) {
21849
+ const states = /* @__PURE__ */ new Map();
21850
+ const headings = new Array(11).fill(0);
21851
+ const bodies = new Array(11).fill(0);
21852
+ let lastHeading = 0;
21853
+ for (const paragraph of documentParagraphs(model.blocks)) {
21854
+ const outline2 = model.paragraphStyles ? resolveParagraphFormatting(paragraph, model.paragraphStyles).outlineLevel : paragraph.outlineLevel;
21855
+ const heading = outline2 !== void 0 && outline2 >= 1 && outline2 <= 9;
21856
+ const level3 = heading ? outline2 : lastHeading + 1;
21857
+ if (!counts(paragraph)) continue;
21858
+ if (heading) lastHeading = outline2;
21859
+ const own2 = heading ? headings : bodies;
21860
+ own2[level3]++;
21861
+ for (let deeper = level3 + 1; deeper <= 10; deeper++) {
21862
+ bodies[deeper] = 0;
21863
+ if (heading) headings[deeper] = 0;
21864
+ }
21865
+ states.set(paragraph.id, {
21866
+ level: level3,
21867
+ heading,
21868
+ counts: [...headings.slice(1, level3), own2[level3]]
21869
+ });
21870
+ }
21871
+ return states;
21872
+ }
21873
+ function autoNumberResult(instr, state) {
21874
+ const field = parseFieldInstruction(instr, { s: "arg", e: "flag" });
21875
+ if (!field || !AUTO_NUMBER_FIELDS.has(field.name)) return void 0;
21876
+ const own2 = state.counts.at(-1);
21877
+ if (field.name === "AUTONUMOUT") {
21878
+ const [open, numFmt, close] = state.heading ? OUTLINE_NUMBERING[state.level - 1] : ["", "decimal", "."];
21879
+ return `${open}${formatListNumber(numFmt, own2)}${close}`;
21880
+ }
21881
+ const given = field.switches.get("s");
21882
+ const separator = typeof given === "string" && given ? [...given][0] : ".";
21883
+ if (field.name === "AUTONUMLGL")
21884
+ return state.counts.join(separator) + (field.switches.has("e") ? "" : separator);
21885
+ return applyFieldFormat(String(own2), field.format) + separator;
21886
+ }
21887
+
21888
+ // docx/doc-property-field.ts
21889
+ var UNKNOWN_PROPERTY = "Error! Unknown document property name.";
21890
+ var NO_PROPERTY_NAME = "Error! No property name supplied.";
21891
+ var text2 = (value) => ({
21892
+ kind: "text",
21893
+ text: value === void 0 ? "" : String(value)
21894
+ });
21895
+ function date(value) {
21896
+ if (value === void 0) return text2(void 0);
21897
+ const parsed = new Date(value);
21898
+ return Number.isNaN(parsed.getTime()) ? { kind: "stale" } : { kind: "date", date: parsed };
21899
+ }
21900
+ function builtIn(name2, core, app) {
21901
+ switch (name2) {
21902
+ case "title":
21903
+ return text2(core.title);
21904
+ case "subject":
21905
+ return text2(core.subject);
21906
+ case "author":
21907
+ return text2(core.creator);
21908
+ case "keywords":
21909
+ return text2(core.keywords);
21910
+ case "comments":
21911
+ return text2(core.description);
21912
+ case "lastsavedby":
21913
+ return text2(core.lastModifiedBy);
21914
+ case "revisionnumber":
21915
+ return text2(core.revision);
21916
+ case "category":
21917
+ return text2(core.category);
21918
+ case "manager":
21919
+ return text2(app.manager);
21920
+ case "company":
21921
+ return text2(app.company);
21922
+ case "hyperlinkbase":
21923
+ return text2(app.hyperlinkBase);
21924
+ case "template":
21925
+ return text2(app.template);
21926
+ case "nameofapplication":
21927
+ return text2(app.application);
21928
+ case "security":
21929
+ return text2(app.docSecurity ?? 0);
21930
+ case "createtime":
21931
+ return date(core.created);
21932
+ case "lastsavedtime":
21933
+ return date(core.modified);
21934
+ case "lastprinted":
21935
+ return date(core.lastPrinted);
21936
+ case "pages":
21937
+ case "words":
21938
+ case "characters":
21939
+ case "characterswithspaces":
21940
+ case "lines":
21941
+ case "paragraphs":
21942
+ case "bytes":
21943
+ case "totaleditingtime":
21944
+ return { kind: "stale" };
21945
+ default:
21385
21946
  return void 0;
21386
- next[first3] = formatted ?? { ...runs[first3], text: text2 };
21387
- for (const at of rest) next[at] = { ...runs[at], text: "" };
21388
- return next;
21389
21947
  }
21390
- const code = charFormat ? name2 : field.code;
21391
- if (current || code === void 0 || field.removed) return void 0;
21392
- next.splice(field.insertAt, 0, fieldResultRun(runs[code], field.instr, text2));
21393
- return next;
21394
21948
  }
21395
- function sameRun(a, b) {
21396
- const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
21397
- return [...keys].every((key) => JSON.stringify(a[key]) === JSON.stringify(b[key]));
21398
- }
21399
- function fieldResultRun(code, instr, text2) {
21400
- const formatted = { ...code };
21401
- for (const key of STRUCTURE) delete formatted[key];
21402
- return { ...formatted, text: text2, field: { instr } };
21403
- }
21404
- function paragraphWithResults(paragraph, evaluate) {
21405
- let runs = paragraph.runs;
21406
- const start = (field) => field.runs[0] ?? field.insertAt;
21407
- for (const field of fieldResults(runs).sort((a, b) => start(b) - start(a))) {
21408
- const reference = field.locked ? void 0 : parseStyleReference(field.instr);
21409
- const text2 = reference && evaluate(reference, paragraph, field);
21410
- if (text2 !== void 0)
21411
- runs = replaceResult(runs, field, text2, reference?.charFormat === true) ?? runs;
21949
+ function custom(property) {
21950
+ switch (property.type) {
21951
+ case "lpwstr":
21952
+ return text2(property.value);
21953
+ case "i4":
21954
+ case "r8":
21955
+ return text2(property.value);
21956
+ case "bool":
21957
+ return text2(property.value ? "Y" : "N");
21958
+ case "filetime":
21959
+ return date(property.value);
21960
+ default:
21961
+ return { kind: "stale" };
21412
21962
  }
21413
- return runs === paragraph.runs ? paragraph : { ...paragraph, runs: [...runs] };
21414
- }
21415
- function tableWithResults(table, evaluate) {
21416
- let changed = false;
21417
- const rows2 = table.rows.map(
21418
- (row2) => row2.map((cell) => {
21419
- const paragraphs = cell.paragraphs.map((item) => paragraphWithResults(item, evaluate));
21420
- const sourceBlocks = cell.sourceBlocks?.map(
21421
- (item) => item.type === "table" ? tableWithResults(item, evaluate) : item
21422
- );
21423
- if (paragraphs.every((item, index) => item === cell.paragraphs[index]) && (sourceBlocks ?? []).every((item, index) => item === cell.sourceBlocks[index]))
21424
- return cell;
21425
- changed = true;
21426
- return { ...cell, paragraphs, ...sourceBlocks ? { sourceBlocks } : {} };
21427
- })
21428
- );
21429
- return changed ? { ...table, rows: rows2 } : table;
21430
21963
  }
21431
- function withStyleRefResults(blocks, evaluate) {
21432
- let changed = false;
21433
- const next = blocks.map((block) => {
21434
- const updated = block.type === "paragraph" ? paragraphWithResults(block, evaluate) : tableWithResults(block, evaluate);
21435
- changed ||= updated !== block;
21436
- return updated;
21964
+ function docPropertyResult(instr, properties) {
21965
+ const field = parseFieldInstruction(instr);
21966
+ if (field?.name !== "DOCPROPERTY") return void 0;
21967
+ const name2 = field.args[0];
21968
+ if (name2 === void 0) return NO_PROPERTY_NAME;
21969
+ const key = name2.toLowerCase();
21970
+ const value = builtIn(key, properties.core, properties.app) ?? (() => {
21971
+ const found = properties.custom.find((item) => item.name.toLowerCase() === key);
21972
+ return found && custom(found);
21973
+ })();
21974
+ if (!value) return UNKNOWN_PROPERTY;
21975
+ if (value.kind === "stale") return void 0;
21976
+ if (value.kind === "date") return fieldDateResult(value.date, field.format);
21977
+ return applyFieldFormat(value.text, field.format);
21978
+ }
21979
+ var EDITABLE = [
21980
+ "title",
21981
+ "subject",
21982
+ "creator",
21983
+ "keywords",
21984
+ "description",
21985
+ "lastModifiedBy"
21986
+ ];
21987
+ function fieldProperties(model) {
21988
+ const loaded = model.packageProperties;
21989
+ const core = { ...loaded?.core };
21990
+ if (model.properties || !loaded)
21991
+ for (const key of EDITABLE) {
21992
+ const value = model.properties?.[key];
21993
+ if (value === void 0) delete core[key];
21994
+ else core[key] = value;
21995
+ }
21996
+ return { core, app: loaded?.app ?? {}, custom: loaded?.custom ?? [] };
21997
+ }
21998
+
21999
+ // text/windows-1252.ts
22000
+ var WINDOWS_1252_HIGH = {
22001
+ 128: 8364,
22002
+ 130: 8218,
22003
+ 131: 402,
22004
+ 132: 8222,
22005
+ 133: 8230,
22006
+ 134: 8224,
22007
+ 135: 8225,
22008
+ 136: 710,
22009
+ 137: 8240,
22010
+ 138: 352,
22011
+ 139: 8249,
22012
+ 140: 338,
22013
+ 142: 381,
22014
+ 145: 8216,
22015
+ 146: 8217,
22016
+ 147: 8220,
22017
+ 148: 8221,
22018
+ 149: 8226,
22019
+ 150: 8211,
22020
+ 151: 8212,
22021
+ 152: 732,
22022
+ 153: 8482,
22023
+ 154: 353,
22024
+ 155: 8250,
22025
+ 156: 339,
22026
+ 158: 382,
22027
+ 159: 376
22028
+ };
22029
+ var REVERSE = new Map(Object.entries(WINDOWS_1252_HIGH).map(([code2, char]) => [char, +code2]));
22030
+ var windows1252CodePoint = (byte) => WINDOWS_1252_HIGH[byte] ?? byte;
22031
+ var windows1252HighByte = (codePoint) => REVERSE.get(codePoint);
22032
+
22033
+ // docx/symbol-field.ts
22034
+ var SYMBOL_ERROR = "###";
22035
+ var SYMBOL_FONTS = /* @__PURE__ */ new Set([
22036
+ "symbol",
22037
+ "wingdings",
22038
+ "wingdings 2",
22039
+ "wingdings 3",
22040
+ "webdings",
22041
+ "marlett",
22042
+ "mt extra"
22043
+ ]);
22044
+ var isSymbolFont = (font) => font !== void 0 && SYMBOL_FONTS.has(font.trim().toLowerCase());
22045
+ function code(argument) {
22046
+ if (/^0x[0-9a-f]+$/i.test(argument)) return Number.parseInt(argument.slice(2), 16);
22047
+ return /^\d+(\.\d*)?$/.test(argument) ? Math.trunc(Number(argument)) : Number.NaN;
22048
+ }
22049
+ function character(value, unicode, font) {
22050
+ if (!Number.isFinite(value) || value <= 0) return void 0;
22051
+ const point = unicode ? value & 65535 : value;
22052
+ if (point === 0) return void 0;
22053
+ if (isSymbolFont(font) && point < 256) return String.fromCharCode(61440 + point);
22054
+ if (unicode || isSymbolFont(font)) return String.fromCharCode(point);
22055
+ if (point < 256) return String.fromCharCode(windows1252CodePoint(point));
22056
+ return windows1252HighByte(point) === void 0 ? void 0 : String.fromCharCode(point);
22057
+ }
22058
+ function symbolFieldResult(instr) {
22059
+ const field = parseFieldInstruction(instr, {
22060
+ f: "arg",
22061
+ s: "arg",
22062
+ u: "flag",
22063
+ a: "flag",
22064
+ j: "flag",
22065
+ h: "flag"
21437
22066
  });
21438
- return changed ? next : blocks;
22067
+ if (field?.name !== "SYMBOL") return void 0;
22068
+ const font = field.switches.get("f");
22069
+ const fontFamily = typeof font === "string" && font.trim() ? font : void 0;
22070
+ const text3 = character(code(field.args[0] ?? ""), field.switches.has("u"), fontFamily);
22071
+ if (text3 === void 0) return { text: SYMBOL_ERROR };
22072
+ const size = field.switches.get("s");
22073
+ const points = typeof size === "string" && /^\d/.test(size) ? Math.trunc(Number.parseFloat(size)) : 0;
22074
+ return {
22075
+ text: text3,
22076
+ ...fontFamily ? { fontFamily } : {},
22077
+ ...points > 0 ? { fontSizePt: Math.min(points, 1638) } : {},
22078
+ ...field.switches.has("h") ? { keepLineSpacing: true } : {}
22079
+ };
22080
+ }
22081
+
22082
+ // docx/computed-fields.ts
22083
+ /* @__PURE__ */ new Set([
22084
+ "DOCPROPERTY",
22085
+ ...AUTO_NUMBER_FIELDS,
22086
+ "LISTNUM",
22087
+ "SYMBOL"
22088
+ ]);
22089
+ function computedFields(model, options2 = {}) {
22090
+ let properties;
22091
+ let autoNumbers;
22092
+ let listNumbers;
22093
+ return {
22094
+ result(field, paragraph) {
22095
+ const name2 = fieldName(field.instr);
22096
+ if (name2 === "DOCPROPERTY") {
22097
+ const text3 = docPropertyResult(field.instr, properties ??= fieldProperties(model));
22098
+ const error = text3 === UNKNOWN_PROPERTY || text3 === NO_PROPERTY_NAME;
22099
+ return text3 === void 0 || error && !options2.errors ? void 0 : { text: text3 };
22100
+ }
22101
+ if (AUTO_NUMBER_FIELDS.has(name2)) {
22102
+ const state = (autoNumbers ??= autoNumberStates(model)).get(paragraph.id);
22103
+ const text3 = state && autoNumberResult(field.instr, state);
22104
+ return text3 === void 0 ? void 0 : { text: text3 };
22105
+ }
22106
+ if (name2 === "SYMBOL") {
22107
+ const symbol = symbolFieldResult(field.instr);
22108
+ return symbol && {
22109
+ text: symbol.text,
22110
+ ...symbol.fontFamily ? { fontFamily: symbol.fontFamily } : {},
22111
+ ...symbol.fontSizePt ? { fontSizePt: symbol.fontSizePt } : {}
22112
+ };
22113
+ }
22114
+ if (name2 === "LISTNUM") {
22115
+ listNumbers ??= computeListNumbering(model).listNumbers;
22116
+ const text3 = listNumbers.result(paragraph.id, field.from);
22117
+ return text3 === void 0 ? void 0 : { text: text3 };
22118
+ }
22119
+ return void 0;
22120
+ }
22121
+ };
21439
22122
  }
21440
22123
 
21441
22124
  // docx/diagram-theme.ts
@@ -21515,9 +22198,29 @@ function mapDocumentParagraphs(model, map) {
21515
22198
  };
21516
22199
  }
21517
22200
 
21518
- // docx/field-runs.ts
21519
- function fieldName(instr) {
21520
- return instr.trim().split(/\s+/)[0]?.toUpperCase() ?? "";
22201
+ // docx/compatibility.ts
22202
+ function compatibilityProfile(settings) {
22203
+ const mode = settings.compatibilityMode;
22204
+ return {
22205
+ generation: mode !== void 0 && mode >= 15 ? "modern" : "legacy",
22206
+ ...mode !== void 0 ? { mode } : {},
22207
+ doNotUseHtmlParagraphAutoSpacing: settings.doNotUseHtmlParagraphAutoSpacing === true
22208
+ };
22209
+ }
22210
+ function addsParagraphSpacing(profile) {
22211
+ return profile.doNotUseHtmlParagraphAutoSpacing;
22212
+ }
22213
+ function keepsSpaceBeforePageBreak(profile) {
22214
+ return profile.mode !== 15;
22215
+ }
22216
+ function usesModernFootnoteLayout(profile) {
22217
+ return profile.mode === 15;
22218
+ }
22219
+ function attachesFootnotesToBodyColumns(profile) {
22220
+ return profile.mode === 12 || profile.mode === 14;
22221
+ }
22222
+ function autofitOverhangsCellMargins(profile) {
22223
+ return profile.generation === "legacy";
21521
22224
  }
21522
22225
 
21523
22226
  // docx/notes.ts
@@ -21739,100 +22442,7 @@ function reviewDocumentFormatting(model, mode) {
21739
22442
  });
21740
22443
  return { ...prior.value, runs };
21741
22444
  });
21742
- return { model: projected, diagnostics };
21743
- }
21744
-
21745
- // text/date-picture.ts
21746
- var TOKENS = /yyyy|yy|MMMM|MMM|MM|M|dddd|ddd|dd|d|EEEE|EEE|HH|H|hh|h|mm|m|ss|s|tt|am\/pm|AM\/PM|A\/P|a\/p|'[^']*'|"[^"]*"/g;
21747
- var pad2 = (value, length = 2) => String(value).padStart(length, "0");
21748
- function name(date, locale, utc, options2) {
21749
- try {
21750
- return new Intl.DateTimeFormat(locale, utc ? { ...options2, timeZone: "UTC" } : options2).format(
21751
- date
21752
- );
21753
- } catch {
21754
- return new Intl.DateTimeFormat("en-US", utc ? { ...options2, timeZone: "UTC" } : options2).format(
21755
- date
21756
- );
21757
- }
21758
- }
21759
- function formatDatePicture(date, picture, options2 = {}) {
21760
- const locale = options2.locale ?? "en-US";
21761
- const utc = options2.utc ?? false;
21762
- const year = utc ? date.getUTCFullYear() : date.getFullYear();
21763
- const month = utc ? date.getUTCMonth() : date.getMonth();
21764
- const day = utc ? date.getUTCDate() : date.getDate();
21765
- const hours = utc ? date.getUTCHours() : date.getHours();
21766
- const minutes = utc ? date.getUTCMinutes() : date.getMinutes();
21767
- const seconds = utc ? date.getUTCSeconds() : date.getSeconds();
21768
- const hours12 = hours % 12 || 12;
21769
- const label = (options3) => name(date, locale, utc, options3);
21770
- return picture.replace(TOKENS, (token) => {
21771
- switch (token) {
21772
- case "yyyy":
21773
- return pad2(year, 4);
21774
- case "yy":
21775
- return pad2(year % 100);
21776
- case "MMMM":
21777
- return label({ month: "long" });
21778
- case "MMM":
21779
- return label({ month: "short" });
21780
- case "MM":
21781
- return pad2(month + 1);
21782
- case "M":
21783
- return String(month + 1);
21784
- case "dddd":
21785
- case "EEEE":
21786
- return label({ weekday: "long" });
21787
- case "ddd":
21788
- case "EEE":
21789
- return label({ weekday: "short" });
21790
- case "dd":
21791
- return pad2(day);
21792
- case "d":
21793
- return String(day);
21794
- case "HH":
21795
- return pad2(hours);
21796
- case "H":
21797
- return String(hours);
21798
- case "hh":
21799
- return pad2(hours12);
21800
- case "h":
21801
- return String(hours12);
21802
- case "mm":
21803
- return pad2(minutes);
21804
- case "m":
21805
- return String(minutes);
21806
- case "ss":
21807
- return pad2(seconds);
21808
- case "s":
21809
- return String(seconds);
21810
- case "tt":
21811
- case "AM/PM":
21812
- return hours < 12 ? "AM" : "PM";
21813
- case "am/pm":
21814
- return hours < 12 ? "am" : "pm";
21815
- case "A/P":
21816
- return hours < 12 ? "A" : "P";
21817
- case "a/p":
21818
- return hours < 12 ? "a" : "p";
21819
- default:
21820
- return token.slice(1, -1);
21821
- }
21822
- });
21823
- }
21824
-
21825
- // docx/field-date.ts
21826
- function datePicture(instr) {
21827
- const match = /\\@\s*(?:"([^"]*)"|(\S+))/.exec(instr);
21828
- return match ? match[1] ?? match[2] : void 0;
21829
- }
21830
- function formatWordDate(date, picture, locale = "en-US") {
21831
- return formatDatePicture(date, picture, { locale });
21832
- }
21833
- function dateFieldResult(name2, instr, now, locale) {
21834
- const picture = datePicture(instr) ?? (name2 === "DATE" ? "M/d/yyyy" : "h:mm am/pm");
21835
- return formatWordDate(now, picture, locale);
22445
+ return { model: projected, diagnostics };
21836
22446
  }
21837
22447
 
21838
22448
  // docx/table-visuals.ts
@@ -21874,7 +22484,7 @@ var DEFAULT_SHAPE_LINE_EMU = 12700;
21874
22484
  var isLinePreset = (preset) => /^(line|straightConnector1|bentConnector\d|curvedConnector\d)$/.test(preset);
21875
22485
 
21876
22486
  // docx/shape-svg.ts
21877
- var escapeXml = (text2) => text2.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
22487
+ var escapeXml = (text3) => text3.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
21878
22488
  var round = (value) => Math.round(value * 100) / 100;
21879
22489
  function shapeColorCss(color, theme) {
21880
22490
  return drawingColorCss(resolveDrawingColor(color, diagramColorTheme(theme)));
@@ -21954,16 +22564,16 @@ function shapeSvg(spec, widthPx, heightPx, theme) {
21954
22564
  const lines = spec.text?.some(Boolean) ? wrapShapeText(spec.text, textRect.r - textRect.l - 14) : [];
21955
22565
  const color = shapeTextColor(fillPaint(spec.fill, theme));
21956
22566
  const lineHeight = FONT_PX * 1.2;
21957
- const first3 = (textRect.t + textRect.b) / 2 - (lines.length - 1) * lineHeight / 2;
21958
- const text2 = lines.length ? `<text font-family="Calibri,Arial,sans-serif" font-size="${FONT_PX}" fill="${color}" text-anchor="middle" dominant-baseline="central">${lines.map(
21959
- (line4, index) => `<tspan x="${round((textRect.l + textRect.r) / 2)}" y="${round(first3 + index * lineHeight)}">${escapeXml(line4)}</tspan>`
22567
+ const first4 = (textRect.t + textRect.b) / 2 - (lines.length - 1) * lineHeight / 2;
22568
+ const text3 = lines.length ? `<text font-family="Calibri,Arial,sans-serif" font-size="${FONT_PX}" fill="${color}" text-anchor="middle" dominant-baseline="central">${lines.map(
22569
+ (line4, index) => `<tspan x="${round((textRect.l + textRect.r) / 2)}" y="${round(first4 + index * lineHeight)}">${escapeXml(line4)}</tspan>`
21960
22570
  ).join("")}</text>` : "";
21961
22571
  const transform = [
21962
22572
  spec.rotation ? `rotate(${spec.rotation} ${round(w / 2)} ${round(h / 2)})` : "",
21963
22573
  spec.flipH || spec.flipV ? `translate(${spec.flipH ? w : 0} ${spec.flipV ? h : 0}) scale(${spec.flipH ? -1 : 1} ${spec.flipV ? -1 : 1})` : ""
21964
22574
  ].filter(Boolean).join(" ");
21965
22575
  const label = escapeXml(lookupPresetShape(spec.preset) ? spec.preset : "Shape");
21966
- return `<svg xmlns="http://www.w3.org/2000/svg" width="${round(w)}" height="${round(h)}" viewBox="0 0 ${round(w)} ${round(h)}" style="overflow:visible" role="img" aria-label="${label}"><g${transform ? ` transform="${escapeXml(transform)}"` : ""}>${paths}${text2}</g></svg>`;
22576
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${round(w)}" height="${round(h)}" viewBox="0 0 ${round(w)} ${round(h)}" style="overflow:visible" role="img" aria-label="${label}"><g${transform ? ` transform="${escapeXml(transform)}"` : ""}>${paths}${text3}</g></svg>`;
21967
22577
  }
21968
22578
 
21969
22579
  // docx/layout/units.ts
@@ -21992,9 +22602,9 @@ function createFakeMeasurer(options2 = {}) {
21992
22602
  const charWidthFactor = options2.charWidthFactor ?? 0.6;
21993
22603
  const lineHeightFactor = options2.lineHeightFactor ?? 1.15;
21994
22604
  return {
21995
- widthOf(text2, font) {
22605
+ widthOf(text3, font) {
21996
22606
  let width = 0;
21997
- for (const ch of text2) {
22607
+ for (const ch of text3) {
21998
22608
  if (ch === " " || ch === "\n") continue;
21999
22609
  width += font.sizePx * charWidthFactor * (font.bold ? 1.08 : 1) * (ch === " " ? 0.6 : 1);
22000
22610
  }
@@ -22012,40 +22622,155 @@ function ligatureCss(value) {
22012
22622
  return `${enabled("standard") ? "common-ligatures" : "no-common-ligatures"} ${enabled("contextual") ? "contextual" : "no-contextual"} ${enabled("historical") ? "historical-ligatures" : "no-historical-ligatures"} ${enabled("discretional") ? "discretionary-ligatures" : "no-discretionary-ligatures"}`;
22013
22623
  }
22014
22624
 
22015
- // docx/layout/text-breaks.ts
22625
+ // text/complex-breaks.ts
22626
+ function isComplexBreakChar(ch) {
22627
+ const cp = ch.codePointAt(0) ?? 0;
22628
+ return cp >= 3584 && cp <= 3839 || // Thai, Lao
22629
+ cp >= 4096 && cp <= 4255 || // Myanmar
22630
+ cp >= 6016 && cp <= 6143 || // Khmer
22631
+ cp >= 6624 && cp <= 6655 || // Khmer Symbols
22632
+ cp >= 43488 && cp <= 43519 || // Myanmar Extended-B
22633
+ cp >= 43616 && cp <= 43647;
22634
+ }
22635
+ function isLeadingVowel(cp) {
22636
+ return cp >= 3648 && cp <= 3652 || cp >= 3776 && cp <= 3780;
22637
+ }
22638
+ function isStacker(cp) {
22639
+ return cp === 6098 || cp === 4153;
22640
+ }
22641
+ function complexBreakAllowed(before, after) {
22642
+ if (!before || !after) return false;
22643
+ if (!isComplexBreakChar(before) || !isComplexBreakChar(after)) return false;
22644
+ const last = before.codePointAt(before.length - 1) ?? 0;
22645
+ const lead = before.codePointAt(0) ?? 0;
22646
+ return !(before.length === 1 && isLeadingVowel(lead)) && !isStacker(last);
22647
+ }
22648
+
22649
+ // text/east-asian.ts
22016
22650
  function isEastAsianChar(ch) {
22017
22651
  const cp = ch.codePointAt(0) ?? 0;
22018
22652
  return cp >= 4352 && cp <= 4607 || cp >= 11904 && cp <= 40959 || cp >= 43360 && cp <= 43391 || cp >= 44032 && cp <= 55295 || cp >= 63744 && cp <= 64255 || cp >= 65072 && cp <= 65103 || cp >= 65280 && cp <= 65519 || cp >= 131072 && cp <= 262143;
22019
22653
  }
22020
- function tokenizeRun(text2, runIndex) {
22654
+ var EAST_ASIAN_LETTER = /^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u;
22655
+ var LETTER = /^\p{L}/u;
22656
+ var DIGIT = /^\p{Nd}/u;
22657
+ function isEastAsianLetter(grapheme) {
22658
+ return EAST_ASIAN_LETTER.test(grapheme);
22659
+ }
22660
+ function westernKind(grapheme) {
22661
+ if (!grapheme || isEastAsianChar(grapheme)) return void 0;
22662
+ if (DIGIT.test(grapheme)) return "digit";
22663
+ return LETTER.test(grapheme) ? "alpha" : void 0;
22664
+ }
22665
+ function eastAsianAutoSpace(before, after) {
22666
+ if (isEastAsianLetter(before)) return westernKind(after);
22667
+ if (isEastAsianLetter(after)) return westernKind(before);
22668
+ return void 0;
22669
+ }
22670
+ var AUTO_SPACE_EM = 0.25;
22671
+
22672
+ // text/kinsoku.ts
22673
+ var JAPANESE = {
22674
+ noStart: "!%),.:;?]}\xA2\xB0\u2019\u201D\u2030\u2032\u2033\u2103\u3001\u3002\u3005\u3009\u300B\u300D\u300F\u3011\u3015\u309B\u309C\u309D\u309E\u30FB\u30FD\u30FE\uFF01\uFF05\uFF09\uFF0C\uFF0E\uFF1A\uFF1B\uFF1F\uFF3D\uFF5D\uFF61\uFF63\uFF64\uFF65\uFF9E\uFF9F\uFFE0",
22675
+ noEnd: "$([\\{\xA3\xA5\u2018\u201C\u3008\u300A\u300C\u300E\u3010\u3014\uFF04\uFF08\uFF3B\uFF5B\uFF62\uFFE1\uFFE5"
22676
+ };
22677
+ var JAPANESE_STRICT_EXTRA = "\u3041\u3043\u3045\u3047\u3049\u3063\u3083\u3085\u3087\u308E\u30A1\u30A3\u30A5\u30A7\u30A9\u30C3\u30E3\u30E5\u30E7\u30EE\u30F5\u30F6\u30FC\uFF67\uFF68\uFF69\uFF6A\uFF6B\uFF6C\uFF6D\uFF6E\uFF6F\uFF70";
22678
+ var DEFAULTS = {
22679
+ ja: JAPANESE,
22680
+ "zh-Hans": {
22681
+ noStart: "!%),.:;>?]}\xA2\xA8\xB0\xB7\u2015\u2016\u2019\u201D\u2026\u2030\u2032\u2033\u203A\u2103\u3001\u3002\u3003\u3009\u300B\u300D\u300F\u3011\u3015\u3017\u301E\uFE36\uFE3A\uFE3E\uFE40\uFE44\uFE5A\uFE5C\uFE5E\uFF01\uFF02\uFF05\uFF07\uFF09\uFF0C\uFF0E\uFF1A\uFF1B\uFF1F\uFF3D\uFF40\uFF5C\uFF5D\uFF5E\uFFE0",
22682
+ noEnd: "$([{\xA3\xA5\xB7\u2018\u201C\u3008\u300A\u300C\u300E\u3010\u3014\u3016\u301D\uFE59\uFE5B\uFE5D\uFF04\uFF08\uFF0E\uFF3B\uFF5B\uFFE1\uFFE5"
22683
+ },
22684
+ "zh-Hant": {
22685
+ noStart: "!),.:;?]}\xA2\xB7\u2019\u201D\u2022\u2025\u2026\u2027\u2032\u3001\u3002\u3009\u300B\u300D\u300F\u3011\u3015\u301E\uFE30\uFE31\uFE33\uFE34\uFE36\uFE38\uFE3A\uFE3C\uFE3E\uFE40\uFE42\uFE44\uFE4F\uFE50\uFE51\uFE52\uFE54\uFE55\uFE56\uFE57\uFE5A\uFE5C\uFE5E\uFF01\uFF09\uFF0C\uFF0E\uFF1A\uFF1B\uFF1F\uFF3D\uFF5C\uFF5D\uFF64",
22686
+ noEnd: "([{\xA3\xA5\u2018\u201C\u2035\u3008\u300A\u300C\u300E\u3010\u3014\u301D\uFE35\uFE37\uFE39\uFE3B\uFE3D\uFE3F\uFE41\uFE43\uFE59\uFE5B\uFE5D\uFF08\uFF5B"
22687
+ },
22688
+ ko: { noStart: "", noEnd: "" }
22689
+ };
22690
+ function kinsokuLanguage(tag) {
22691
+ if (!tag) return void 0;
22692
+ const lower = tag.toLowerCase();
22693
+ const [primary] = lower.split(/[-_]/);
22694
+ if (primary === "ja") return "ja";
22695
+ if (primary === "ko") return "ko";
22696
+ if (primary !== "zh") return void 0;
22697
+ return /-(hant|tw|hk|mo)(-|$)/.test(lower) ? "zh-Hant" : "zh-Hans";
22698
+ }
22699
+ function kinsokuSets(language, settings = {}) {
22700
+ const base = DEFAULTS[language];
22701
+ const custom2 = (override) => override && kinsokuLanguage(override.language) === language ? override.chars : void 0;
22702
+ const strictExtra = settings.strict && language === "ja" ? JAPANESE_STRICT_EXTRA : "";
22703
+ return {
22704
+ noStart: custom2(settings.noLineBreaksBefore) ?? base.noStart + strictExtra,
22705
+ noEnd: custom2(settings.noLineBreaksAfter) ?? base.noEnd
22706
+ };
22707
+ }
22708
+ var first3 = (text3) => String.fromCodePoint(text3.codePointAt(0) ?? 0);
22709
+ function prohibitedAtLineStart(grapheme, sets) {
22710
+ return grapheme.length > 0 && sets.noStart.includes(first3(grapheme));
22711
+ }
22712
+ function prohibitedAtLineEnd(grapheme, sets) {
22713
+ return grapheme.length > 0 && sets.noEnd.includes(first3(grapheme));
22714
+ }
22715
+ var HANGING = {
22716
+ ja: ",.\u2019\u201D\u3001\u3002\u300D\u300F\u3011\uFF09\uFF0C\uFF0E\uFF3D\uFF5D\uFF61\uFF64",
22717
+ "zh-Hans": "!%),.:;>?]}\xA2\xB0\u2019\u201D\u2030\u2032\u2033\u2103\u3001\u3002\u3003\u3009\u300B\u300D\u300F\u3011\u3015\u3017\u301E\uFE5A\uFE5C\uFE5E\uFF01\uFF02\uFF05\uFF07\uFF09\uFF0C\uFF1A\uFF1B\uFF1F\uFF3D\uFF5D\uFFE0",
22718
+ "zh-Hant": "!),.:;?]}\u2019\u201D\u2032\u3001\u3002\u3009\u300B\u300D\u300F\u3011\u3015\u301E\uFE5A\uFE5C\uFE5E\uFF01\uFF09\uFF0C\uFF0E\uFF1A\uFF1B\uFF1F\uFF3D\uFF5D",
22719
+ ko: ""
22720
+ };
22721
+ function hangsAtLineEnd(grapheme, language) {
22722
+ return grapheme.length > 0 && HANGING[language].includes(first3(grapheme));
22723
+ }
22724
+
22725
+ // docx/layout/text-breaks.ts
22726
+ var ZERO_WIDTH_SPACE = "\u200B";
22727
+ function breakAllowedBetween(before, after) {
22728
+ if (!before || !after) return false;
22729
+ if (before === "-" || before.endsWith(ZERO_WIDTH_SPACE)) return true;
22730
+ return isEastAsianChar(before) || isEastAsianChar(after) || complexBreakAllowed(before, after);
22731
+ }
22732
+ function kinsokuForbids(before, after, beforeSets, afterSets) {
22733
+ return afterSets !== void 0 && prohibitedAtLineStart(after, afterSets) || beforeSets !== void 0 && prohibitedAtLineEnd(before, beforeSets);
22734
+ }
22735
+ var graphemeSegmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
22736
+ function graphemesOf(text3) {
22737
+ return [...graphemeSegmenter.segment(text3)].map((part) => part.segment);
22738
+ }
22739
+ function tokenizeRun(text3, runIndex, kinsoku) {
22021
22740
  const tokens = [];
22022
22741
  let word = "";
22023
22742
  let wordStart = 0;
22743
+ let glue;
22744
+ let previous = "";
22024
22745
  const flushWord = () => {
22025
- if (word) tokens.push({ kind: "word", text: word, runIndex, sourceStart: wordStart });
22746
+ if (word)
22747
+ tokens.push({
22748
+ kind: "word",
22749
+ text: word,
22750
+ runIndex,
22751
+ sourceStart: wordStart,
22752
+ ...glue ? { glue } : {}
22753
+ });
22026
22754
  word = "";
22755
+ glue = void 0;
22027
22756
  };
22028
- const chars = [...new Intl.Segmenter(void 0, { granularity: "grapheme" }).segment(text2)].map(
22029
- (part) => part.segment
22030
- );
22031
22757
  let offset = 0;
22032
- for (const ch of chars) {
22033
- if (ch === "\n") {
22034
- flushWord();
22035
- tokens.push({ kind: "lineBreak", runIndex, sourceStart: offset });
22036
- } else if (ch === " ") {
22037
- flushWord();
22038
- tokens.push({ kind: "tab", runIndex, sourceStart: offset });
22039
- } else if (ch === " ") {
22758
+ for (const ch of graphemesOf(text3)) {
22759
+ if (ch === "\n" || ch === " " || ch === " ") {
22040
22760
  flushWord();
22041
- tokens.push({ kind: "space", text: ch, runIndex, sourceStart: offset });
22042
- } else if (isEastAsianChar(ch)) {
22043
- flushWord();
22044
- tokens.push({ kind: "word", text: ch, runIndex, sourceStart: offset });
22761
+ previous = "";
22762
+ if (ch === "\n") tokens.push({ kind: "lineBreak", runIndex, sourceStart: offset });
22763
+ else if (ch === " ") tokens.push({ kind: "tab", runIndex, sourceStart: offset });
22764
+ else tokens.push({ kind: "space", text: ch, runIndex, sourceStart: offset });
22045
22765
  } else {
22766
+ if (word && breakAllowedBetween(previous, ch)) {
22767
+ const kept = kinsokuForbids(previous, ch, kinsoku, kinsoku);
22768
+ flushWord();
22769
+ if (kept) glue = "kinsoku";
22770
+ }
22046
22771
  if (!word) wordStart = offset;
22047
22772
  word += ch;
22048
- if (ch === "-") flushWord();
22773
+ previous = ch;
22049
22774
  }
22050
22775
  offset += ch.length;
22051
22776
  }
@@ -22055,8 +22780,22 @@ function tokenizeRun(text2, runIndex) {
22055
22780
  function appendBreakMarker(tokens, runIndex, sourceStart, kind) {
22056
22781
  tokens.push({ kind: kind === "page" ? "pageBreak" : "columnBreak", runIndex, sourceStart });
22057
22782
  }
22783
+ function gluedCarry(tokens, index, placed2) {
22784
+ let carry = 0;
22785
+ for (let current = index; ; current--) {
22786
+ const token = tokens[current];
22787
+ if (token?.kind !== "word" || !token.glue) return carry;
22788
+ const previous = placed2[placed2.length - 1 - carry];
22789
+ if (!previous || previous !== tokens[current - 1]) return carry;
22790
+ carry++;
22791
+ if (carry >= placed2.length) return 0;
22792
+ }
22793
+ }
22058
22794
 
22059
22795
  // docx/layout/result.ts
22796
+ function inFlow(block) {
22797
+ return block.kind !== "table" || !block.floating;
22798
+ }
22060
22799
  function cellVerticalOffset(geometry, rowHeightPx) {
22061
22800
  const free = Math.max(0, (geometry.alignmentHeightPx ?? rowHeightPx) - geometry.contentHeightPx);
22062
22801
  return geometry.verticalAlign === "center" ? free / 2 : geometry.verticalAlign === "bottom" ? free : 0;
@@ -22106,11 +22845,11 @@ function pageNumbers(model, pages) {
22106
22845
  );
22107
22846
  }
22108
22847
  function sectionPageCounts(pages) {
22109
- const counts = /* @__PURE__ */ new Map();
22848
+ const counts2 = /* @__PURE__ */ new Map();
22110
22849
  for (const page of pages)
22111
22850
  for (const index of page.sectionIndices ?? [page.sectionIndex])
22112
- counts.set(index, (counts.get(index) ?? 0) + 1);
22113
- return counts;
22851
+ counts2.set(index, (counts2.get(index) ?? 0) + 1);
22852
+ return counts2;
22114
22853
  }
22115
22854
  function headerFooterSlotForPage(model, page, pageNumber) {
22116
22855
  const section = model.sections?.[page.sectionIndex];
@@ -22207,9 +22946,9 @@ function pageStyleRefs(model, pages) {
22207
22946
  last = pagesOf.get(at)?.at(-1) ?? last;
22208
22947
  }
22209
22948
  const firstAfter = [];
22210
- for (let at = count - 1, first3 = pages.length; at >= 0; at--) {
22211
- firstAfter[at] = first3;
22212
- first3 = pagesOf.get(at)?.[0] ?? first3;
22949
+ for (let at = count - 1, first4 = pages.length; at >= 0; at--) {
22950
+ firstAfter[at] = first4;
22951
+ first4 = pagesOf.get(at)?.[0] ?? first4;
22213
22952
  }
22214
22953
  const placed2 = [];
22215
22954
  for (const [at, found] of portions) {
@@ -22280,13 +23019,13 @@ function pageStyleRefs(model, pages) {
22280
23019
  // docx/layout/tab-stops.ts
22281
23020
  function placeTab(positionPx, stops, hangingStopPx, followingPx, beforeDecimalPx) {
22282
23021
  const epsilon = 0.5;
22283
- const custom = stops.filter((stop) => stop.align !== "clear" && stop.align !== "bar").sort((a, b) => a.posPx - b.posPx).find((stop) => stop.posPx > positionPx + epsilon);
22284
- if (custom) {
22285
- const distance = custom.posPx - positionPx;
22286
- const shift = custom.align === "right" || custom.align === "end" ? followingPx : custom.align === "center" ? followingPx / 2 : custom.align === "decimal" ? beforeDecimalPx : 0;
23022
+ const custom2 = stops.filter((stop) => stop.align !== "clear" && stop.align !== "bar").sort((a, b) => a.posPx - b.posPx).find((stop) => stop.posPx > positionPx + epsilon);
23023
+ if (custom2) {
23024
+ const distance = custom2.posPx - positionPx;
23025
+ const shift = custom2.align === "right" || custom2.align === "end" ? followingPx : custom2.align === "center" ? followingPx / 2 : custom2.align === "decimal" ? beforeDecimalPx : 0;
22287
23026
  return {
22288
23027
  widthPx: Math.max(0, distance - shift),
22289
- ...custom.leader && custom.leader !== "none" ? { leader: custom.leader } : {}
23028
+ ...custom2.leader && custom2.leader !== "none" ? { leader: custom2.leader } : {}
22290
23029
  };
22291
23030
  }
22292
23031
  if (hangingStopPx !== void 0 && hangingStopPx > positionPx + epsilon)
@@ -22317,14 +23056,14 @@ function fontOf(run) {
22317
23056
  };
22318
23057
  }
22319
23058
  var graphemes2 = new Intl.Segmenter(void 0, { granularity: "grapheme" });
22320
- function runTextWidth(text2, run, measurer, font = fontOf(run)) {
23059
+ function runTextWidth(text3, run, measurer, font = fontOf(run)) {
22321
23060
  let characters = 0;
22322
23061
  if (run.characterSpacingPx) {
22323
- for (const _segment of graphemes2.segment(text2)) characters++;
23062
+ for (const _segment of graphemes2.segment(text3)) characters++;
22324
23063
  }
22325
23064
  return Math.max(
22326
23065
  0,
22327
- measurer.widthOf(text2, font) * (run.textScalePercent ?? 100) / 100 + characters * (run.characterSpacingPx ?? 0)
23066
+ measurer.widthOf(text3, font) * (run.textScalePercent ?? 100) / 100 + characters * (run.characterSpacingPx ?? 0)
22328
23067
  );
22329
23068
  }
22330
23069
  function resolveIndents(paragraph) {
@@ -22343,11 +23082,56 @@ function resolveIndents(paragraph) {
22343
23082
  function sourceLengthOf(run) {
22344
23083
  return run.sourceLength ?? (run.object ? 1 : run.text.length || (run.breakAfter ? 1 : 0));
22345
23084
  }
23085
+ function runKinsoku(paragraph, run) {
23086
+ if (paragraph.kinsoku === false || !run?.kinsokuLanguage || run.synthetic) return void 0;
23087
+ return kinsokuSets(run.kinsokuLanguage, paragraph.kinsokuSettings);
23088
+ }
23089
+ function glueAcrossRuns(paragraph, tokens, start) {
23090
+ const token = tokens[start];
23091
+ const previous = tokens[start - 1];
23092
+ if (token?.kind !== "word" || previous?.kind !== "word") return;
23093
+ const before = paragraph.runs[previous.runIndex];
23094
+ const after = paragraph.runs[token.runIndex];
23095
+ if (before?.synthetic || before?.marker) return;
23096
+ const last = graphemesOf(previous.text).at(-1) ?? "";
23097
+ const first4 = graphemesOf(token.text)[0] ?? "";
23098
+ if (!breakAllowedBetween(last, first4)) token.glue = "word";
23099
+ else if (kinsokuForbids(last, first4, runKinsoku(paragraph, before), runKinsoku(paragraph, after)))
23100
+ token.glue = "kinsoku";
23101
+ }
23102
+ function applyAutoSpace(paragraph, tokens) {
23103
+ if (paragraph.autoSpaceDE === false && paragraph.autoSpaceDN === false) return;
23104
+ for (let index = 1; index < tokens.length; index++) {
23105
+ const previous = tokens[index - 1];
23106
+ const token = tokens[index];
23107
+ if (previous?.kind !== "word" || token?.kind !== "word") continue;
23108
+ const run = paragraph.runs[previous.runIndex];
23109
+ if (!run || run.synthetic || paragraph.runs[token.runIndex]?.synthetic) continue;
23110
+ const kind = eastAsianAutoSpace(
23111
+ graphemesOf(previous.text).at(-1) ?? "",
23112
+ graphemesOf(token.text)[0] ?? ""
23113
+ );
23114
+ if (!kind || (kind === "alpha" ? paragraph.autoSpaceDE : paragraph.autoSpaceDN) === false)
23115
+ continue;
23116
+ previous.spaceAfterPx = fontOf(run).sizePx * AUTO_SPACE_EM;
23117
+ }
23118
+ }
23119
+ function hangsPastLineEnd(paragraph, tokens, index) {
23120
+ const token = tokens[index];
23121
+ if (token?.kind !== "word" || token.glue !== "kinsoku") return false;
23122
+ if (paragraph.overflowPunct === false || paragraph.align !== "justify") return false;
23123
+ const language = paragraph.runs[token.runIndex]?.kinsokuLanguage;
23124
+ const [mark, ...rest] = graphemesOf(token.text);
23125
+ if (!language || !mark || rest.length || !hangsAtLineEnd(mark, language)) return false;
23126
+ const next = tokens[index + 1];
23127
+ return !(next?.kind === "word" && next.glue);
23128
+ }
22346
23129
  function tokenizeParagraph(paragraph) {
22347
23130
  const tokens = [];
22348
23131
  const runOffsets = [];
22349
23132
  let cursor = 0;
22350
23133
  paragraph.runs.forEach((run, runIndex) => {
23134
+ const start = tokens.length;
22351
23135
  runOffsets.push(cursor);
22352
23136
  if (run.hidden) {
22353
23137
  if (!run.synthetic) cursor += sourceLengthOf(run);
@@ -22362,12 +23146,16 @@ function tokenizeParagraph(paragraph) {
22362
23146
  text: run.text.slice(0, run.marker.length)
22363
23147
  });
22364
23148
  tokens.push(...tokenizeRun(run.text.slice(run.marker.length), runIndex));
22365
- } else tokens.push(...tokenizeRun(run.text, runIndex));
23149
+ } else {
23150
+ tokens.push(...tokenizeRun(run.text, runIndex, runKinsoku(paragraph, run)));
23151
+ glueAcrossRuns(paragraph, tokens, start);
23152
+ }
22366
23153
  if (run.breakAfter) appendBreakMarker(tokens, runIndex, run.text.length, run.breakAfter);
22367
23154
  if (run.synthetic) {
22368
23155
  for (const token of tokens) if (token.runIndex === runIndex) token.sourceStart = 0;
22369
23156
  } else cursor += sourceLengthOf(run);
22370
23157
  });
23158
+ applyAutoSpace(paragraph, tokens);
22371
23159
  return { tokens, runOffsets };
22372
23160
  }
22373
23161
 
@@ -22410,9 +23198,9 @@ function buildFragments(tokensOnLine, paragraph) {
22410
23198
  let x = 0;
22411
23199
  for (const { token, widthPx, leader, xOffsetPx, advancePx } of tokensOnLine) {
22412
23200
  const run = paragraph.runs[token.runIndex];
22413
- const text2 = token.kind === "word" || token.kind === "space" ? token.text : "";
23201
+ const text3 = token.kind === "word" || token.kind === "space" ? token.text : "";
22414
23202
  fragments.push({
22415
- text: text2,
23203
+ text: text3,
22416
23204
  xPx: x + (xOffsetPx ?? 0),
22417
23205
  widthPx,
22418
23206
  runIndex: token.runIndex,
@@ -22468,10 +23256,10 @@ function registerParagraphCache(measurer) {
22468
23256
  sessions.set(measurer, /* @__PURE__ */ new Map());
22469
23257
  }
22470
23258
  function cachedParagraphLayout(measurer, key, note, compute) {
22471
- const cache2 = sessions.get(measurer);
22472
- if (!cache2) return compute(note);
23259
+ const cache3 = sessions.get(measurer);
23260
+ if (!cache3) return compute(note);
22473
23261
  const { index, signature } = key();
22474
- const cached = cache2.get(index);
23262
+ const cached = cache3.get(index);
22475
23263
  if (cached?.signature === signature) {
22476
23264
  for (const warning of cached.warnings) note(warning);
22477
23265
  return structuredClone(cached.result);
@@ -22481,8 +23269,8 @@ function cachedParagraphLayout(measurer, key, note, compute) {
22481
23269
  warnings.push(warning);
22482
23270
  note(warning);
22483
23271
  });
22484
- if (!cache2.has(index) && cache2.size >= 4e3) cache2.delete(cache2.keys().next().value);
22485
- cache2.set(index, { signature, result: structuredClone(result), warnings });
23272
+ if (!cache3.has(index) && cache3.size >= 4e3) cache3.delete(cache3.keys().next().value);
23273
+ cache3.set(index, { signature, result: structuredClone(result), warnings });
22486
23274
  return result;
22487
23275
  }
22488
23276
 
@@ -22592,6 +23380,8 @@ function measureParagraph(paragraph, contentWidthPx, measurer, note, lineBox, st
22592
23380
  return { followingPx, beforeDecimalPx: beforeDecimalPx ?? followingPx };
22593
23381
  }
22594
23382
  const hangingStopPx = firstLineExtraPx < 0 ? leftPx : void 0;
23383
+ const placedTokens = () => placed2.map((entry) => entry.token);
23384
+ const hangingPx = /* @__PURE__ */ new Map();
22595
23385
  function flushLine(forceEmpty, forcedByBreak) {
22596
23386
  if (!placed2.length && !forceEmpty) return;
22597
23387
  const lineIndex = lines.length;
@@ -22638,8 +23428,8 @@ function measureParagraph(paragraph, contentWidthPx, measurer, note, lineBox, st
22638
23428
  jump = void 0;
22639
23429
  marginReachPx = 0;
22640
23430
  }
22641
- for (const [tokenIndex, token] of tokens.entries()) {
22642
- if (tokenIndex < startToken) continue;
23431
+ for (let tokenIndex = startToken; tokenIndex < tokens.length; tokenIndex++) {
23432
+ const token = expectDefined(tokens[tokenIndex], "token index");
22643
23433
  tokenCursor = tokenIndex + 1;
22644
23434
  if (token.kind === "lineBreak") {
22645
23435
  if (!placed2.length) firstToken = tokenIndex;
@@ -22656,6 +23446,7 @@ function measureParagraph(paragraph, contentWidthPx, measurer, note, lineBox, st
22656
23446
  const marker = paragraph.runs[token.runIndex]?.marker;
22657
23447
  const markerFactor = marker && token.kind === "word" && tokenIndex === 0 ? marker.alignment === "right" ? 1 : marker.alignment === "center" ? 0.5 : 0 : 0;
22658
23448
  const advance = width * (1 - markerFactor);
23449
+ const spacePx = token.kind === "word" ? token.spaceAfterPx ?? 0 : 0;
22659
23450
  const positional = token.kind === "tab" && paragraph.runs[token.runIndex]?.positionalTab;
22660
23451
  if (positional) {
22661
23452
  const { followingPx } = segmentAfter(tokenIndex);
@@ -22695,9 +23486,19 @@ function measureParagraph(paragraph, contentWidthPx, measurer, note, lineBox, st
22695
23486
  const fits = lineWidthPx + (token.kind === "tab" ? width : advance) <= limit + squeezePx;
22696
23487
  const wouldFit = fits || placed2.every((placed3) => paragraph.runs[placed3.token.runIndex]?.synthetic);
22697
23488
  const pastHole = !fits && hole && !jump && token.kind === "word" ? hole.endPx - lineStart(lineIndex) - lineWidthPx : void 0;
23489
+ const hanging = !wouldFit && !hole && !jump && placed2.length > 0 && hangsPastLineEnd(paragraph, tokens, tokenIndex);
23490
+ if (hanging) hangingPx.set(lineIndex, advance);
22698
23491
  if (pastHole !== void 0 && lineWidthPx + pastHole + advance <= availableWidth(lineIndex)) {
22699
23492
  jump = { index: placed2.length, shiftPx: pastHole };
22700
- } else if (!wouldFit && token.kind !== "space") {
23493
+ } else if (!wouldFit && token.kind !== "space" && !hanging) {
23494
+ const carry = jump ? 0 : gluedCarry(tokens, tokenIndex, placedTokens());
23495
+ if (carry) {
23496
+ placed2.splice(placed2.length - carry);
23497
+ tokenCursor = tokenIndex - carry;
23498
+ flushLine(false, void 0);
23499
+ tokenIndex -= carry + 1;
23500
+ continue;
23501
+ }
22701
23502
  tokenCursor = tokenIndex;
22702
23503
  flushLine(false, void 0);
22703
23504
  tokenCursor = tokenIndex + 1;
@@ -22714,9 +23515,10 @@ function measureParagraph(paragraph, contentWidthPx, measurer, note, lineBox, st
22714
23515
  token,
22715
23516
  widthPx: width,
22716
23517
  ...leader ? { leader } : {},
22717
- ...markerFactor ? { xOffsetPx: -width * markerFactor, advancePx: advance } : {}
23518
+ ...markerFactor ? { xOffsetPx: -width * markerFactor } : {},
23519
+ ...markerFactor || spacePx ? { advancePx: advance + spacePx } : {}
22718
23520
  });
22719
- lineWidthPx += token.kind === "tab" ? width : advance;
23521
+ lineWidthPx += token.kind === "tab" ? width : advance + spacePx;
22720
23522
  if (token.kind === "space") lineSpacePx += advance;
22721
23523
  }
22722
23524
  flushLine(lines.length === 0, void 0);
@@ -22726,7 +23528,7 @@ function measureParagraph(paragraph, contentWidthPx, measurer, note, lineBox, st
22726
23528
  ...line4,
22727
23529
  fragments: alignFragments(
22728
23530
  line4.fragments,
22729
- availableWidth(index),
23531
+ availableWidth(index) + (hangingPx.get(index) ?? 0),
22730
23532
  index === lastIndex,
22731
23533
  // A line that runs around a picture is not aligned across it.
22732
23534
  boxes[index]?.hole ? "left" : effectiveAlign
@@ -22804,9 +23606,9 @@ function nestedFrameProfile(table, tableWidthPx = table.widthPx, merges = false)
22804
23606
  const gridKnown = merges && table.rows.every(
22805
23607
  (row2) => row2.cells.every((cell) => cell.xPx !== void 0 && cell.widthPx !== void 0)
22806
23608
  );
22807
- const first3 = table.rows[0], left = first3.cells[0].borders.left, right = first3.cells.at(-1).borders.right;
23609
+ const first4 = table.rows[0], left = first4.cells[0].borders.left, right = first4.cells.at(-1).borders.right;
22808
23610
  for (const [index, row2] of table.rows.entries()) {
22809
- if (!gridKnown && row2.cells.length !== first3.cells.length || !equal(row2.cells[0]?.borders?.left, left) || !equal(row2.cells.at(-1)?.borders?.right, right))
23611
+ if (!gridKnown && row2.cells.length !== first4.cells.length || !equal(row2.cells[0]?.borders?.left, left) || !equal(row2.cells.at(-1)?.borders?.right, right))
22810
23612
  return void 0;
22811
23613
  for (const [column, cell] of row2.cells.entries()) {
22812
23614
  const sourceWidth = cell.widthPx ?? (tableWidthPx === void 0 ? void 0 : tableWidthPx / row2.cells.length);
@@ -22879,6 +23681,276 @@ function cellContentBottom(boxes, paddingBottom = 0) {
22879
23681
  );
22880
23682
  }
22881
23683
 
23684
+ // docx/layout/table-autofit-measure.ts
23685
+ var TWIP_PX = 1 / 15;
23686
+ var EMPTY_CONTENT_PX = 6 * TWIP_PX;
23687
+ var ceilTwips = (px) => Math.ceil(px / TWIP_PX - 1e-6) * TWIP_PX;
23688
+ function breaksBetween(previous, next) {
23689
+ if (previous.kind !== "word" || next.kind !== "word") return true;
23690
+ if (previous.runIndex === next.runIndex) return true;
23691
+ const last = [...previous.text].at(-1) ?? "";
23692
+ const firstChar = [...next.text][0] ?? "";
23693
+ return last === "-" || isEastAsianChar(last) || isEastAsianChar(firstChar);
23694
+ }
23695
+ function paragraphRange(paragraph, measurer) {
23696
+ const { leftPx, rightPx, firstLineExtraPx } = resolveIndents(paragraph);
23697
+ const fonts = paragraph.runs.map(fontOf);
23698
+ const { tokens } = tokenizeParagraph(paragraph);
23699
+ const widthOf = (token) => {
23700
+ const run = paragraph.runs[token.runIndex];
23701
+ if (!run) return 0;
23702
+ if (token.kind === "object") return run.object?.widthPx ?? 0;
23703
+ if (token.kind !== "word" && token.kind !== "space") return 0;
23704
+ if (run.marker?.widthPx !== void 0 && token.kind === "word" && token.sourceStart === 0) {
23705
+ if (token.text === run.text.slice(0, run.marker.length)) return run.marker.widthPx;
23706
+ }
23707
+ return runTextWidth(token.text, run, measurer, fonts[token.runIndex]);
23708
+ };
23709
+ const hangingStopPx = firstLineExtraPx < 0 ? leftPx : void 0;
23710
+ let minPx = 0;
23711
+ let maxPx = 0;
23712
+ let line4 = Math.max(0, firstLineExtraPx);
23713
+ let trailingSpace = 0;
23714
+ let chunk = 0;
23715
+ let previous;
23716
+ const endLine = () => {
23717
+ maxPx = Math.max(maxPx, line4 - trailingSpace);
23718
+ line4 = 0;
23719
+ trailingSpace = 0;
23720
+ };
23721
+ for (const token of tokens) {
23722
+ const width = widthOf(token);
23723
+ if (token.kind === "word" || token.kind === "object") {
23724
+ chunk = previous && !breaksBetween(previous, token) ? chunk + width : width;
23725
+ minPx = Math.max(minPx, chunk);
23726
+ line4 += width;
23727
+ trailingSpace = 0;
23728
+ } else if (token.kind === "space") {
23729
+ line4 += width;
23730
+ trailingSpace += width;
23731
+ } else if (token.kind === "tab") {
23732
+ line4 += placeTab(line4, paragraph.tabStops ?? [], hangingStopPx, 0, 0).widthPx;
23733
+ trailingSpace = 0;
23734
+ } else endLine();
23735
+ previous = token.kind === "word" || token.kind === "object" ? token : void 0;
23736
+ }
23737
+ endLine();
23738
+ const indents = leftPx + rightPx;
23739
+ return { minPx: minPx + indents, maxPx: maxPx + indents };
23740
+ }
23741
+ function blocksRange(blocks, measurer, nestedTable) {
23742
+ let minPx = 0;
23743
+ let maxPx = 0;
23744
+ for (const block of blocks) {
23745
+ const range = block.kind === "paragraph" ? paragraphRange(block, measurer) : nestedTable(block);
23746
+ minPx = Math.max(minPx, range.minPx);
23747
+ maxPx = Math.max(maxPx, range.maxPx);
23748
+ }
23749
+ return { minPx, maxPx };
23750
+ }
23751
+ function cellRange(cell, measurer, nestedTable) {
23752
+ const content = blocksRange(cell.blocks ?? cell.paragraphs, measurer, nestedTable);
23753
+ const margins = (cell.padding?.left ?? 0) + (cell.padding?.right ?? 0);
23754
+ const maxPx = content.maxPx > 0 ? content.maxPx : EMPTY_CONTENT_PX;
23755
+ const minPx = content.minPx > 0 ? content.minPx : Math.min(maxPx, EMPTY_CONTENT_PX);
23756
+ return { minPx: ceilTwips(minPx + margins), maxPx: ceilTwips(Math.max(minPx, maxPx) + margins) };
23757
+ }
23758
+
23759
+ // docx/layout/table-autofit-distribute.ts
23760
+ var toTwips = (px) => Math.round(px * 15);
23761
+ function interpolate(from, to, total) {
23762
+ const low = from.reduce((sum, value) => sum + value, 0);
23763
+ const high = to.reduce((sum, value) => sum + value, 0);
23764
+ const k = high > low ? Math.min(1, Math.max(0, (total - low) / (high - low))) : 0;
23765
+ return from.map((value, index) => value + (to[index] - value) * k);
23766
+ }
23767
+ function roundToTotal(widths) {
23768
+ const total = Math.round(widths.reduce((sum, value) => sum + value, 0));
23769
+ const floors = widths.map(Math.floor);
23770
+ let spare = total - floors.reduce((sum, value) => sum + value, 0);
23771
+ const order = widths.map((value, index) => ({ index, rest: value - Math.floor(value) })).sort((a, b) => b.rest - a.rest);
23772
+ for (const { index } of order) {
23773
+ if (spare <= 0) break;
23774
+ floors[index] += 1;
23775
+ spare -= 1;
23776
+ }
23777
+ return floors;
23778
+ }
23779
+ function distributeColumns(columns, target) {
23780
+ if (!columns.length) return [];
23781
+ const available = toTwips(target.availablePx);
23782
+ const tableWidth = target.targetPx !== void 0 ? toTwips(target.targetPx) : void 0;
23783
+ const min = columns.map((column) => toTwips(column.minPx));
23784
+ const contentMax = columns.map((column, index) => Math.max(min[index], toTwips(column.maxPx)));
23785
+ const fractions = columns.map(
23786
+ (column) => column.preferredPx === void 0 ? column.preferredFraction ?? 0 : 0
23787
+ );
23788
+ const fractionSum = Math.min(
23789
+ 0.99,
23790
+ fractions.reduce((sum2, value) => sum2 + value, 0)
23791
+ );
23792
+ const percentBase = tableWidth ?? Math.min(
23793
+ available,
23794
+ columns.reduce(
23795
+ (sum2, column, index) => fractions[index] ? sum2 : sum2 + Math.max(contentMax[index], toTwips(column.preferredPx ?? 0)),
23796
+ 0
23797
+ ) / (1 - fractionSum)
23798
+ );
23799
+ const preferred = columns.map(
23800
+ (column, index) => column.preferredPx !== void 0 ? toTwips(column.preferredPx) : fractions[index] ? fractions[index] * percentBase : void 0
23801
+ );
23802
+ const fixed = preferred.map((value) => value !== void 0);
23803
+ const max = contentMax.map(
23804
+ (value, index) => fixed[index] ? Math.max(min[index], preferred[index]) : value
23805
+ );
23806
+ const sum = (values) => values.reduce((acc, value) => acc + value, 0);
23807
+ const limit = tableWidth ?? available;
23808
+ if (sum(min) >= limit) return roundToTotal(min);
23809
+ if (sum(max) <= limit) {
23810
+ if (tableWidth === void 0) return roundToTotal(max);
23811
+ const grow = fixed.every(Boolean) ? fixed.map(() => true) : fixed.map((value) => !value);
23812
+ const growing = sum(max.filter((_, index) => grow[index]));
23813
+ const extra = tableWidth - sum(max);
23814
+ return roundToTotal(
23815
+ max.map(
23816
+ (value, index) => grow[index] ? value + (growing > 0 ? extra * value / growing : 0) : value
23817
+ )
23818
+ );
23819
+ }
23820
+ const pick = (values, wanted) => values.map((value, index) => fixed[index] === wanted ? value : 0);
23821
+ const fixedMax = sum(pick(max, true));
23822
+ const autoMin = sum(pick(min, false));
23823
+ const widths = fixedMax + autoMin <= limit ? interpolate(pick(min, false), pick(max, false), limit - fixedMax).map(
23824
+ (value, index) => fixed[index] ? max[index] : value
23825
+ ) : interpolate(pick(min, true), pick(max, true), limit - autoMin).map(
23826
+ (value, index) => fixed[index] ? value : min[index]
23827
+ );
23828
+ return roundToTotal(widths);
23829
+ }
23830
+
23831
+ // docx/layout/table-autofit.ts
23832
+ var AUTOFIT_SPAN_PREFERRED_NOTE = "AutoFit tables size a merged cell\u2019s preferred width like its content, which has not been measured against Word.";
23833
+ function placedCells(table) {
23834
+ return table.rows.map((row2) => {
23835
+ let start = 0;
23836
+ return row2.cells.map((cell) => {
23837
+ const span = Math.max(1, cell.gridSpan ?? 1);
23838
+ const placed2 = { cell, start, span };
23839
+ start += span;
23840
+ return placed2;
23841
+ });
23842
+ });
23843
+ }
23844
+ function spread(columns, total, weight, apply) {
23845
+ const sum = columns.reduce((acc, column) => acc + weight(column), 0);
23846
+ for (const column of columns)
23847
+ apply(column, sum > 0 ? total * weight(column) / sum : total / columns.length);
23848
+ }
23849
+ function measureColumns(table, count, measurer, note) {
23850
+ const columns = Array.from({ length: count }, () => ({ minPx: 0, maxPx: 0 }));
23851
+ const nested = (inner) => tableRange(inner, measurer, note);
23852
+ const spans = [];
23853
+ for (const row2 of placedCells(table))
23854
+ for (const placed2 of row2) {
23855
+ if (placed2.start >= count) continue;
23856
+ const range = cellRange(placed2.cell, measurer, nested);
23857
+ if (placed2.span > 1) {
23858
+ spans.push({ placed: placed2, range });
23859
+ continue;
23860
+ }
23861
+ const column = columns[placed2.start];
23862
+ column.minPx = Math.max(column.minPx, range.minPx);
23863
+ column.maxPx = Math.max(column.maxPx, range.maxPx);
23864
+ const { preferredWidthPx, preferredFraction } = placed2.cell;
23865
+ if (preferredWidthPx !== void 0)
23866
+ column.preferredPx = Math.max(column.preferredPx ?? 0, preferredWidthPx);
23867
+ else if (preferredFraction !== void 0)
23868
+ column.preferredFraction = Math.max(column.preferredFraction ?? 0, preferredFraction);
23869
+ }
23870
+ spans.sort((a, b) => a.placed.span - b.placed.span);
23871
+ for (const { placed: placed2, range } of spans) {
23872
+ const covered = columns.slice(placed2.start, placed2.start + placed2.span);
23873
+ const preferred = placed2.cell.preferredWidthPx;
23874
+ if (preferred !== void 0) note(AUTOFIT_SPAN_PREFERRED_NOTE);
23875
+ const maxPx = Math.max(range.maxPx, preferred ?? 0);
23876
+ if (range.minPx > covered.reduce((sum, column) => sum + column.minPx, 0))
23877
+ spread(
23878
+ covered,
23879
+ range.minPx,
23880
+ (column) => column.minPx + column.maxPx,
23881
+ (column, share) => {
23882
+ column.minPx = Math.max(column.minPx, share);
23883
+ column.maxPx = Math.max(column.maxPx, column.minPx);
23884
+ }
23885
+ );
23886
+ if (maxPx > covered.reduce((sum, column) => sum + column.maxPx, 0))
23887
+ spread(
23888
+ covered,
23889
+ maxPx,
23890
+ (column) => column.maxPx,
23891
+ (column, share) => {
23892
+ column.maxPx = Math.max(column.maxPx, share);
23893
+ }
23894
+ );
23895
+ }
23896
+ return columns;
23897
+ }
23898
+ function tableRange(table, measurer, note) {
23899
+ if (!table.autofit) {
23900
+ const width = table.widthPx ?? 0;
23901
+ return { minPx: width, maxPx: width };
23902
+ }
23903
+ const columns = measureColumns(table, table.autofit.columns, measurer, note);
23904
+ const sum = (pick) => columns.reduce((acc, column) => acc + pick(column), 0);
23905
+ return {
23906
+ minPx: sum((column) => column.minPx),
23907
+ maxPx: sum((column) => Math.max(column.minPx, column.preferredPx ?? column.maxPx))
23908
+ };
23909
+ }
23910
+ var cache = /* @__PURE__ */ new WeakMap();
23911
+ function resolveTableAutofit(table, availablePx, measurer, note = () => {
23912
+ }) {
23913
+ const autofit = table.autofit;
23914
+ if (!autofit) return table;
23915
+ const hit = cache.get(table);
23916
+ if (hit && hit.availablePx === availablePx && hit.measurer === measurer) return hit.result;
23917
+ const columns = measureColumns(table, autofit.columns, measurer, note);
23918
+ const first4 = table.rows[0]?.cells[0]?.padding;
23919
+ const last = table.rows[0]?.cells.at(-1)?.padding;
23920
+ const overhang = autofit.legacyMargins ? first4?.left ?? 0 : 0;
23921
+ const reference = autofit.legacyMargins ? availablePx + (first4?.left ?? 0) + (last?.right ?? 0) : availablePx;
23922
+ const widths = distributeColumns(columns, {
23923
+ availablePx: availablePx + overhang - Math.max(0, table.indentPx ?? 0),
23924
+ ...autofit.widthPx !== void 0 ? { targetPx: autofit.widthPx } : autofit.widthFraction !== void 0 ? { targetPx: autofit.widthFraction * reference } : {}
23925
+ }).map((twips2) => twips2 * TWIP_PX);
23926
+ const offsets = widths.map(
23927
+ (_, index) => widths.slice(0, index).reduce((sum, width) => sum + width, 0)
23928
+ );
23929
+ const placedRows = placedCells(table);
23930
+ const result = {
23931
+ ...table,
23932
+ widthPx: widths.reduce((sum, width) => sum + width, 0),
23933
+ rows: table.rows.map((row2, rowIndex) => {
23934
+ const placed2 = placedRows[rowIndex];
23935
+ return {
23936
+ ...row2,
23937
+ cells: row2.cells.map((cell, cellIndex) => {
23938
+ const { start, span } = placed2[cellIndex];
23939
+ if (start >= widths.length) return cell;
23940
+ const end = Math.min(widths.length, start + span);
23941
+ return {
23942
+ ...cell,
23943
+ xPx: offsets[start],
23944
+ widthPx: widths.slice(start, end).reduce((sum, width) => sum + width, 0)
23945
+ };
23946
+ })
23947
+ };
23948
+ })
23949
+ };
23950
+ cache.set(table, { availablePx, measurer, result });
23951
+ return result;
23952
+ }
23953
+
22882
23954
  // docx/layout/table-cell-layout.ts
22883
23955
  function cellParagraphs(cell) {
22884
23956
  const walk = (blocks) => blocks.flatMap(
@@ -22899,14 +23971,15 @@ function stackCellBlocks(cell, width, measurer, note, top, starts, physicalFragm
22899
23971
  let y = top;
22900
23972
  const boxes = [];
22901
23973
  const tables = [];
22902
- for (const block of cell.blocks) {
22903
- if (block.kind === "paragraph") {
22904
- if (starts && !starts.has(block.id)) continue;
22905
- const result = stackParagraphs([block], width, measurer, note, y, starts);
23974
+ for (const source of cell.blocks) {
23975
+ if (source.kind === "paragraph") {
23976
+ if (starts && !starts.has(source.id)) continue;
23977
+ const result = stackParagraphs([source], width, measurer, note, y, starts);
22906
23978
  boxes.push(...result.boxes);
22907
23979
  y = result.heightPx;
22908
23980
  continue;
22909
23981
  }
23982
+ const block = resolveTableAutofit(source, width, measurer, note);
22910
23983
  const edges = physicalFragments ? nestedFragmentEdges(block) : void 0;
22911
23984
  const tableWidth = block.widthPx ?? width;
22912
23985
  const profile = nestedFrameProfile(block, tableWidth);
@@ -23262,15 +24335,15 @@ function splitNote(note, budget) {
23262
24335
  const bottom = head2.at(-1).yPx + head2.at(-1).heightPx;
23263
24336
  before.push({ ...paragraph, heightPx: bottom, lines: head2 });
23264
24337
  }
23265
- const first3 = tail[0];
24338
+ const first4 = tail[0];
23266
24339
  if (head2.length)
23267
24340
  sourceTokenStarts[paragraph.blockId] = head2.at(-1).nextToken ?? sourceTokenStarts[paragraph.blockId] ?? 0;
23268
- origin = paragraph.yPx + (first3?.yPx ?? 0);
24341
+ origin = paragraph.yPx + (first4?.yPx ?? 0);
23269
24342
  after.push({
23270
24343
  ...paragraph,
23271
24344
  yPx: 0,
23272
- heightPx: Math.max(0, paragraph.heightPx - (first3?.yPx ?? 0)),
23273
- lines: tail.map((line4) => ({ ...line4, yPx: line4.yPx - (first3?.yPx ?? 0) }))
24345
+ heightPx: Math.max(0, paragraph.heightPx - (first4?.yPx ?? 0)),
24346
+ lines: tail.map((line4) => ({ ...line4, yPx: line4.yPx - (first4?.yPx ?? 0) }))
23274
24347
  });
23275
24348
  }
23276
24349
  if (!before.length) return { after: note };
@@ -23349,8 +24422,8 @@ function minimumFootnoteHeight(notes, columns, reflow) {
23349
24422
 
23350
24423
  // docx/layout/footnote-flow.ts
23351
24424
  function firstLineBottom(note) {
23352
- const first3 = note?.paragraphs[0];
23353
- return first3 ? first3.yPx + (first3.lines[0]?.yPx ?? 0) + (first3.lines[0]?.heightPx ?? first3.heightPx) : note?.heightPx ?? 0;
24425
+ const first4 = note?.paragraphs[0];
24426
+ return first4 ? first4.yPx + (first4.lines[0]?.yPx ?? 0) + (first4.lines[0]?.heightPx ?? first4.heightPx) : note?.heightPx ?? 0;
23354
24427
  }
23355
24428
  var FOOTNOTE_SEPARATOR_PX = 12;
23356
24429
  var FootnoteFlow = class {
@@ -23673,9 +24746,7 @@ var PageCursor = class {
23673
24746
  /** Reject trials that overflow an earlier column, including a kept table row. */
23674
24747
  get columnContentFits() {
23675
24748
  return this.activeColumns.every(
23676
- (column) => column.blocks.every(
23677
- (block) => block.yPx + block.heightPx <= this.columnTopPx + this.columnHeightPx
23678
- )
24749
+ (column) => column.blocks.filter(inFlow).every((block) => block.yPx + block.heightPx <= this.columnTopPx + this.columnHeightPx)
23679
24750
  );
23680
24751
  }
23681
24752
  endBalance() {
@@ -23726,7 +24797,7 @@ var PageCursor = class {
23726
24797
  const bottom = Math.max(
23727
24798
  this.yPx,
23728
24799
  ...this.activeColumns.flatMap(
23729
- (column) => column.blocks.map((block) => block.yPx + block.heightPx)
24800
+ (column) => column.blocks.filter(inFlow).map((block) => block.yPx + block.heightPx)
23730
24801
  )
23731
24802
  );
23732
24803
  for (const column of this.activeColumns) {
@@ -23767,7 +24838,7 @@ var PageCursor = class {
23767
24838
  Math.max(
23768
24839
  0,
23769
24840
  ...this.activeColumns.slice(0, this.columnIndex).flatMap(
23770
- (column) => column.blocks.map((block) => block.yPx + block.heightPx - this.columnTopPx)
24841
+ (column) => column.blocks.filter(inFlow).map((block) => block.yPx + block.heightPx - this.columnTopPx)
23771
24842
  )
23772
24843
  )
23773
24844
  ))
@@ -23803,7 +24874,7 @@ var PageCursor = class {
23803
24874
  const bodyBottom = this.legacyFootnoteColumns ? this.yPx : Math.max(
23804
24875
  this.yPx,
23805
24876
  ...this.activeColumns.flatMap(
23806
- (column) => column.blocks.map((block) => block.yPx + block.heightPx)
24877
+ (column) => column.blocks.filter(inFlow).map((block) => block.yPx + block.heightPx)
23807
24878
  )
23808
24879
  );
23809
24880
  this.footnotes.commit(
@@ -23940,8 +25011,8 @@ function placeParagraph(cursor, placement, note) {
23940
25011
  layout.lines.slice(lineCursor, lineCursor + placedCount),
23941
25012
  cumulative + (firstSegment ? spacingBeforePx : 0)
23942
25013
  );
23943
- const first3 = expectDefined(layout.lines[lineCursor], "first line of paragraph segment");
23944
- const origin = first3.yPx - (firstSegment ? (first3.gapBeforePx ?? 0) + layout.insetTopPx : 0);
25014
+ const first4 = expectDefined(layout.lines[lineCursor], "first line of paragraph segment");
25015
+ const origin = first4.yPx - (firstSegment ? (first4.gapBeforePx ?? 0) + layout.insetTopPx : 0);
23945
25016
  const segmentLines = layout.lines.slice(lineCursor, lineCursor + placedCount).map((line4, index) => ({
23946
25017
  ...line4,
23947
25018
  yPx: line4.yPx - origin,
@@ -23997,8 +25068,8 @@ var TableParagraphKeeps = class {
23997
25068
  return Math.max(
23998
25069
  0,
23999
25070
  ...row2.cells.map((cell, index) => {
24000
- const first3 = cell[0];
24001
- return first3 && this.sources.get(first3.blockId)?.keepLines ? first3.yPx + first3.heightPx + (row2.cellPadding?.[index]?.bottom ?? 0) : 0;
25071
+ const first4 = cell[0];
25072
+ return first4 && this.sources.get(first4.blockId)?.keepLines ? first4.yPx + first4.heightPx + (row2.cellPadding?.[index]?.bottom ?? 0) : 0;
24002
25073
  })
24003
25074
  );
24004
25075
  }
@@ -24022,13 +25093,13 @@ var TableParagraphKeeps = class {
24022
25093
 
24023
25094
  // docx/layout/table-note-stories.ts
24024
25095
  function independentNoteStories(cell) {
24025
- const first3 = cell.blocks?.[0];
24026
- if (first3?.kind !== "table" || first3.rows.length !== 1 || cell.verticalAlign && cell.verticalAlign !== "top")
25096
+ const first4 = cell.blocks?.[0];
25097
+ if (first4?.kind !== "table" || first4.rows.length !== 1 || cell.verticalAlign && cell.verticalAlign !== "top")
24027
25098
  return void 0;
24028
25099
  if (cell.blocks.slice(1).some((block) => block.kind !== "paragraph" || block.footnotes?.length))
24029
25100
  return void 0;
24030
- const row2 = first3.rows[0];
24031
- if (row2.heightPx !== void 0 || row2.cantSplit || row2.isHeader || !nestedFrameProfile(first3, first3.widthPx))
25101
+ const row2 = first4.rows[0];
25102
+ if (row2.heightPx !== void 0 || row2.cantSplit || row2.isHeader || !nestedFrameProfile(first4, first4.widthPx))
24032
25103
  return void 0;
24033
25104
  if (row2.cells.some(
24034
25105
  (inner) => inner.blocks?.some((block) => block.kind === "table") || cellParagraphs(inner).some(
@@ -24039,7 +25110,7 @@ function independentNoteStories(cell) {
24039
25110
  if (!measuredNoteReferences(row2.cells.flatMap(cellParagraphs))) return void 0;
24040
25111
  const groups = /* @__PURE__ */ new Map();
24041
25112
  row2.cells.forEach((inner, index) => {
24042
- for (const paragraph of cellParagraphs(inner)) groups.set(paragraph.id, first3.id + ":" + index);
25113
+ for (const paragraph of cellParagraphs(inner)) groups.set(paragraph.id, first4.id + ":" + index);
24043
25114
  });
24044
25115
  return groups.size ? groups : void 0;
24045
25116
  }
@@ -24347,82 +25418,269 @@ var TableFootnotes = class {
24347
25418
  return { layout: candidate, cut };
24348
25419
  }
24349
25420
  }
24350
- }
24351
- this.holdFragment();
24352
- return void 0;
24353
- }
24354
- add(row2, repeated) {
24355
- if (repeated) return;
24356
- for (const ref of this.references(row2))
24357
- if (!this.fragment.has(ref.note.id))
24358
- this.fragment.set(ref.note.id, { ...ref, bottom: this.height() + ref.bottom });
24359
- }
24360
- holdFragment() {
24361
- this.hold(this.fragment);
24362
- }
24363
- flushed() {
24364
- for (const id of this.fragment.keys()) this.placed.add(id);
24365
- this.fragment.clear();
25421
+ }
25422
+ this.holdFragment();
25423
+ return void 0;
25424
+ }
25425
+ add(row2, repeated) {
25426
+ if (repeated) return;
25427
+ for (const ref of this.references(row2))
25428
+ if (!this.fragment.has(ref.note.id))
25429
+ this.fragment.set(ref.note.id, { ...ref, bottom: this.height() + ref.bottom });
25430
+ }
25431
+ holdFragment() {
25432
+ this.hold(this.fragment);
25433
+ }
25434
+ flushed() {
25435
+ for (const id of this.fragment.keys()) this.placed.add(id);
25436
+ this.fragment.clear();
25437
+ }
25438
+ };
25439
+
25440
+ // docx/layout/table-merged-rows.ts
25441
+ var MergedRowPlan = class {
25442
+ constructor(rows2) {
25443
+ this.rows = rows2;
25444
+ }
25445
+ rows;
25446
+ legacy = /* @__PURE__ */ new Set();
25447
+ minimum = /* @__PURE__ */ new Map();
25448
+ cache = /* @__PURE__ */ new Map();
25449
+ apply(source) {
25450
+ const minimum = this.minimum.get(source);
25451
+ if (minimum === void 0 && !this.legacy.has(source)) return source;
25452
+ return {
25453
+ ...source,
25454
+ ...minimum === void 0 ? {} : { heightPx: minimum, heightRule: "atLeast" },
25455
+ ...this.legacy.has(source) ? { mergedTextInRow: true } : {}
25456
+ };
25457
+ }
25458
+ /** The row to lay out and place (the source row itself when the plan leaves it alone). */
25459
+ effective(source) {
25460
+ let row2 = this.cache.get(source);
25461
+ if (!row2) {
25462
+ row2 = this.apply(source);
25463
+ this.cache.set(source, row2);
25464
+ }
25465
+ return row2;
25466
+ }
25467
+ /** Plans the rows a merge starting at `index` covers, given the room left for them. */
25468
+ plan(index, layout, availablePx) {
25469
+ const start = this.rows[index];
25470
+ const spans = start?.cells.map((cell) => cell.rowSpan ?? 1) ?? [];
25471
+ const longest = Math.max(1, ...spans);
25472
+ if (!start || longest < 2) return;
25473
+ const covered = this.rows.slice(index, index + longest);
25474
+ const natural = covered.map((row2) => layout(this.apply(row2)));
25475
+ const heights = natural.map((item) => item.heightPx);
25476
+ spans.forEach((span, cell) => {
25477
+ if (span < 2) return;
25478
+ const count = Math.min(span, covered.length);
25479
+ const need = (natural[0]?.geometry[cell]?.contentHeightPx ?? 0) + (natural[count - 1]?.borderBottomPx ?? 0);
25480
+ const have = heights.slice(0, count).reduce((sum, h) => sum + h, 0);
25481
+ if (need > have) heights[count - 1] = (heights[count - 1] ?? 0) + need - have;
25482
+ });
25483
+ if (heights.reduce((sum, h) => sum + h, 0) > availablePx) {
25484
+ this.legacy.add(start);
25485
+ return;
25486
+ }
25487
+ covered.forEach((row2, at) => {
25488
+ const grown = heights[at] - natural[at].heightPx;
25489
+ if (grown > 1e-6 && row2.heightRule !== "exact")
25490
+ this.minimum.set(row2, heights[at] - (natural[at].borderBottomPx ?? 0));
25491
+ });
25492
+ }
25493
+ };
25494
+
25495
+ // docx/layout/floats.ts
25496
+ var FLOAT_WRAP_NOTE = "Text wraps around floating pictures on their largest side, or on both sides of a square, tight or through picture whose wrapText is bothSides (all use the picture\u2019s rectangle, not its outline); lines continuing onto a later page keep their wrapped widths.";
25497
+ function horizontalArea(float, page, column) {
25498
+ const contentLeft = page.marginLeftPx;
25499
+ switch (float.relativeFromH) {
25500
+ case "page":
25501
+ return { start: 0, size: page.widthPx };
25502
+ case "margin":
25503
+ return { start: contentLeft, size: page.widthPx - contentLeft - page.marginRightPx };
25504
+ case "leftMargin":
25505
+ case "insideMargin":
25506
+ return { start: 0, size: contentLeft };
25507
+ case "rightMargin":
25508
+ case "outsideMargin":
25509
+ return { start: page.widthPx - page.marginRightPx, size: page.marginRightPx };
25510
+ default:
25511
+ return { start: contentLeft + column.xPx, size: column.widthPx };
25512
+ }
25513
+ }
25514
+ function verticalArea(float, page, paragraphTopPx, paragraphHeightPx) {
25515
+ switch (float.relativeFromV) {
25516
+ case "page":
25517
+ return { start: 0, size: page.heightPx };
25518
+ case "margin":
25519
+ return {
25520
+ start: page.marginTopPx,
25521
+ size: page.heightPx - page.marginTopPx - page.marginBottomPx
25522
+ };
25523
+ case "topMargin":
25524
+ case "insideMargin":
25525
+ return { start: 0, size: page.marginTopPx };
25526
+ case "bottomMargin":
25527
+ case "outsideMargin":
25528
+ return { start: page.heightPx - page.marginBottomPx, size: page.marginBottomPx };
25529
+ default:
25530
+ return { start: paragraphTopPx, size: paragraphHeightPx };
25531
+ }
25532
+ }
25533
+ function place(area, size, align, offset) {
25534
+ if (align === "center") return area.start + (area.size - size) / 2;
25535
+ if (align === "right" || align === "bottom" || align === "outside")
25536
+ return area.start + area.size - size;
25537
+ if (align) return area.start;
25538
+ return area.start + (offset ?? 0);
25539
+ }
25540
+ function floatPosition(float, page, column, paragraph) {
25541
+ const h = horizontalArea(float, page, column);
25542
+ const v = verticalArea(float, page, paragraph.topPx, paragraph.heightPx);
25543
+ return {
25544
+ xPx: place(h, float.widthPx, float.alignH, float.offsetXPx),
25545
+ yPx: place(v, float.heightPx, float.alignV, float.offsetYPx)
25546
+ };
25547
+ }
25548
+ function floatOrigin(float, page, column, paragraph) {
25549
+ return {
25550
+ xPx: horizontalArea(float, page, column).start,
25551
+ yPx: verticalArea(float, page, paragraph.topPx, paragraph.heightPx).start
25552
+ };
25553
+ }
25554
+ function positionFloats(input, pages) {
25555
+ const floatsById = /* @__PURE__ */ new Map();
25556
+ for (const section of input.sections)
25557
+ for (const block of section.blocks)
25558
+ if (block.kind === "paragraph" && block.floats?.length)
25559
+ floatsById.set(block.id, block.floats);
25560
+ if (!floatsById.size) return false;
25561
+ const placed2 = /* @__PURE__ */ new Set();
25562
+ for (const page of pages) {
25563
+ const boxes = [];
25564
+ for (const column of page.columns)
25565
+ for (const block of column.blocks) {
25566
+ const floats = block.kind === "paragraph" ? floatsById.get(block.blockId) : void 0;
25567
+ if (!floats || placed2.has(block.blockId)) continue;
25568
+ placed2.add(block.blockId);
25569
+ const top = page.marginTopPx + block.yPx;
25570
+ for (const float of floats) {
25571
+ const frame2 = { topPx: top, heightPx: block.heightPx };
25572
+ const position = floatPosition(float, page, column, frame2);
25573
+ const origin = floatOrigin(float, page, column, frame2);
25574
+ boxes.push({
25575
+ blockId: block.blockId,
25576
+ index: float.index ?? floats.indexOf(float),
25577
+ originXPx: origin.xPx,
25578
+ originYPx: origin.yPx,
25579
+ ...position,
25580
+ widthPx: float.widthPx,
25581
+ heightPx: float.heightPx,
25582
+ partName: float.partName,
25583
+ ...float.pictureFill ? { pictureFill: float.pictureFill } : {},
25584
+ contentType: float.contentType,
25585
+ ...float.chart ? { chart: float.chart } : {},
25586
+ behindText: Boolean(float.behindText),
25587
+ ...float.wrap ? { wrap: float.wrap } : {},
25588
+ ...float.wrapText ? { wrapText: float.wrapText } : {}
25589
+ });
25590
+ }
25591
+ }
25592
+ if (boxes.length) page.floats = boxes;
24366
25593
  }
24367
- };
25594
+ return true;
25595
+ }
24368
25596
 
24369
- // docx/layout/table-merged-rows.ts
24370
- var MergedRowPlan = class {
24371
- constructor(rows2) {
24372
- this.rows = rows2;
24373
- }
24374
- rows;
24375
- legacy = /* @__PURE__ */ new Set();
24376
- minimum = /* @__PURE__ */ new Map();
24377
- cache = /* @__PURE__ */ new Map();
24378
- apply(source) {
24379
- const minimum = this.minimum.get(source);
24380
- if (minimum === void 0 && !this.legacy.has(source)) return source;
24381
- return {
24382
- ...source,
24383
- ...minimum === void 0 ? {} : { heightPx: minimum, heightRule: "atLeast" },
24384
- ...this.legacy.has(source) ? { mergedTextInRow: true } : {}
24385
- };
24386
- }
24387
- /** The row to lay out and place (the source row itself when the plan leaves it alone). */
24388
- effective(source) {
24389
- let row2 = this.cache.get(source);
24390
- if (!row2) {
24391
- row2 = this.apply(source);
24392
- this.cache.set(source, row2);
24393
- }
24394
- return row2;
25597
+ // docx/layout/flow-floating-table.ts
25598
+ var FLOATING_TABLE_NOTE = "Floating tables are placed whole on the page where they occur and text wraps around their rectangle; narrow gaps beside them stay empty.";
25599
+ var FLOATING_TABLE_IN_FLOW_NOTE = "Floating tables that do not fit on their page, hold footnote references or merge cells vertically are laid out in the text flow.";
25600
+ function floatable(table) {
25601
+ return table.rows.every(
25602
+ (row2) => row2.cells.every(
25603
+ (cell) => !cell.verticalMerge && !(cell.rowSpan && cell.rowSpan > 1) && cellParagraphs(cell).every((paragraph) => !paragraph.footnotes?.length)
25604
+ )
25605
+ );
25606
+ }
25607
+ function placeFloatingTable(cursor, table, measurer, note) {
25608
+ if (!floatable(table)) {
25609
+ note(FLOATING_TABLE_IN_FLOW_NOTE);
25610
+ return false;
24395
25611
  }
24396
- /** Plans the rows a merge starting at `index` covers, given the room left for them. */
24397
- plan(index, layout, availablePx) {
24398
- const start = this.rows[index];
24399
- const spans = start?.cells.map((cell) => cell.rowSpan ?? 1) ?? [];
24400
- const longest = Math.max(1, ...spans);
24401
- if (!start || longest < 2) return;
24402
- const covered = this.rows.slice(index, index + longest);
24403
- const natural = covered.map((row2) => layout(this.apply(row2)));
24404
- const heights = natural.map((item) => item.heightPx);
24405
- spans.forEach((span, cell) => {
24406
- if (span < 2) return;
24407
- const count = Math.min(span, covered.length);
24408
- const need = (natural[0]?.geometry[cell]?.contentHeightPx ?? 0) + (natural[count - 1]?.borderBottomPx ?? 0);
24409
- const have = heights.slice(0, count).reduce((sum, h) => sum + h, 0);
24410
- if (need > have) heights[count - 1] = (heights[count - 1] ?? 0) + need - have;
24411
- });
24412
- if (heights.reduce((sum, h) => sum + h, 0) > availablePx) {
24413
- this.legacy.add(start);
24414
- return;
24415
- }
24416
- covered.forEach((row2, at) => {
24417
- const grown = heights[at] - natural[at].heightPx;
24418
- if (grown > 1e-6 && row2.heightRule !== "exact")
24419
- this.minimum.set(row2, heights[at] - (natural[at].borderBottomPx ?? 0));
25612
+ const widthPx = table.widthPx ?? cursor.columnWidthPx;
25613
+ const profile = nestedFrameProfile(table, widthPx, true);
25614
+ const borders = new TableFragmentBorders();
25615
+ const rows2 = [];
25616
+ let heightPx = 0;
25617
+ for (const row2 of table.rows) {
25618
+ const layout = layoutBorderedRow(row2, widthPx, measurer, note, profile);
25619
+ heightPx += borders.remove(rows2.at(-1));
25620
+ rows2.push({
25621
+ yPx: heightPx,
25622
+ heightPx: layout.heightPx,
25623
+ repeated: false,
25624
+ cells: layout.cells,
25625
+ geometry: layout.geometry,
25626
+ ...layout.cellTables ? { cellTables: layout.cellTables } : {}
24420
25627
  });
25628
+ heightPx += layout.heightPx;
25629
+ borders.record(layout.borderBottomPx);
25630
+ }
25631
+ heightPx += borders.restore(rows2.at(-1));
25632
+ if (!profile) {
25633
+ const edge = (row2, side) => Math.max(0, ...(row2?.cells ?? []).map((cell) => cell.borders?.[side]?.widthPx ?? 0));
25634
+ heightPx += edge(table.rows[0], "top") + edge(table.rows.at(-1), "bottom");
25635
+ }
25636
+ const page = cursor.page;
25637
+ const column = cursor.column;
25638
+ const frame2 = table.floating;
25639
+ const position = floatPosition(
25640
+ {
25641
+ widthPx,
25642
+ heightPx,
25643
+ relativeFromH: frame2.relativeFromH,
25644
+ ...frame2.alignH ? { alignH: frame2.alignH } : {},
25645
+ offsetXPx: frame2.offsetXPx,
25646
+ relativeFromV: frame2.relativeFromV,
25647
+ ...frame2.alignV ? { alignV: frame2.alignV } : {},
25648
+ offsetYPx: frame2.offsetYPx
25649
+ },
25650
+ page,
25651
+ column,
25652
+ { topPx: page.marginTopPx + cursor.y, heightPx }
25653
+ );
25654
+ const topPx = position.yPx;
25655
+ if (topPx < 0 || topPx + heightPx > page.heightPx - page.marginBottomPx) {
25656
+ note(FLOATING_TABLE_IN_FLOW_NOTE);
25657
+ return false;
24421
25658
  }
24422
- };
25659
+ note(FLOATING_TABLE_NOTE);
25660
+ const box = {
25661
+ kind: "table",
25662
+ blockId: table.id,
25663
+ xPx: position.xPx - page.marginLeftPx - column.xPx,
25664
+ widthPx,
25665
+ yPx: 0,
25666
+ heightPx,
25667
+ rows: rows2,
25668
+ floating: {
25669
+ topPx: frame2.distance.topPx,
25670
+ rightPx: frame2.distance.rightPx,
25671
+ bottomPx: frame2.distance.bottomPx,
25672
+ leftPx: frame2.distance.leftPx
25673
+ }
25674
+ };
25675
+ cursor.place(box, 0, topPx - page.marginTopPx - cursor.y);
25676
+ return true;
25677
+ }
24423
25678
 
24424
25679
  // docx/layout/flow-table.ts
24425
- function placeTable(cursor, table, measurer, note, resolveFootnotes) {
25680
+ function placeTable(cursor, source, measurer, note, resolveFootnotes) {
25681
+ const table = resolveTableAutofit(source, cursor.columnWidthPx, measurer, note);
25682
+ if (table.floating && placeFloatingTable(cursor, { ...table, floating: table.floating }, measurer, note))
25683
+ return;
24426
25684
  const firstBodyRow = table.rows.findIndex((row2) => !row2.isHeader);
24427
25685
  const headerRows = table.rows.slice(0, firstBodyRow < 0 ? table.rows.length : firstBodyRow);
24428
25686
  const nativeFragments = new Map(table.rows.map((row2) => [row2, reflowNestedFragments(row2)]));
@@ -24649,15 +25907,15 @@ function placeTable(cursor, table, measurer, note, resolveFootnotes) {
24649
25907
  }
24650
25908
  }
24651
25909
  const merged = new MergedRowPlan(table.rows);
24652
- for (const [index, source] of table.rows.entries()) {
25910
+ for (const [index, source2] of table.rows.entries()) {
24653
25911
  merged.plan(
24654
25912
  index,
24655
25913
  (candidate) => layoutRow2(candidate, cursor.columnWidthPx, measurer, () => {
24656
- }, void 0, source),
25914
+ }, void 0, source2),
24657
25915
  cursor.remainingHeightPx() - fragmentHeight
24658
25916
  );
24659
- const row2 = merged.effective(source);
24660
- if (row2 !== source) nativeFragments.set(row2, nativeFragments.get(source) ?? false);
25917
+ const row2 = merged.effective(source2);
25918
+ if (row2 !== source2) nativeFragments.set(row2, nativeFragments.get(source2) ?? false);
24661
25919
  const layout = layoutRow2(row2, cursor.columnWidthPx, measurer, note);
24662
25920
  if (layout.heightPx > cursor.remainingHeightPx() && !nativeFragments.get(row2) && row2.cells.some(
24663
25921
  (cell) => cell.blocks?.some((block) => block.kind === "table" && block.rows.length > 1)
@@ -24674,7 +25932,7 @@ function placeTable(cursor, table, measurer, note, resolveFootnotes) {
24674
25932
  placeRow(
24675
25933
  row2,
24676
25934
  layout,
24677
- Boolean(row2.cantSplit) || headerRows.includes(source) || !!footnotes && row2.heightRule === "exact"
25935
+ Boolean(row2.cantSplit) || headerRows.includes(source2) || !!footnotes && row2.heightRule === "exact"
24678
25936
  );
24679
25937
  }
24680
25938
  flushFragment();
@@ -24694,7 +25952,7 @@ function alignMergedCells(rows2) {
24694
25952
 
24695
25953
  // docx/layout/reference-footnotes.ts
24696
25954
  function createReferenceFootnotes(width, measurer, report) {
24697
- const cache2 = /* @__PURE__ */ new Map();
25955
+ const cache3 = /* @__PURE__ */ new Map();
24698
25956
  return (paragraph, lines, includeUnanchored) => {
24699
25957
  const selected = new Set(
24700
25958
  lines.flatMap(
@@ -24704,11 +25962,11 @@ function createReferenceFootnotes(width, measurer, report) {
24704
25962
  const anchored = new Set(paragraph.runs.map((run) => run.footnoteReferenceId));
24705
25963
  return (paragraph.footnotes ?? []).filter((note) => selected.has(note.id) || includeUnanchored && !anchored.has(note.id)).map((note) => {
24706
25964
  const key = `${note.id}:${width()}`;
24707
- const prior = cache2.get(key);
25965
+ const prior = cache3.get(key);
24708
25966
  if (prior) return prior;
24709
25967
  const stacked = stackParagraphs(note.paragraphs, width(), measurer, report);
24710
25968
  const box = { id: note.id, yPx: 0, heightPx: stacked.heightPx, paragraphs: stacked.boxes };
24711
- cache2.set(key, box);
25969
+ cache3.set(key, box);
24712
25970
  return box;
24713
25971
  });
24714
25972
  };
@@ -24728,6 +25986,19 @@ function wrapExclusions(pages) {
24728
25986
  topAndBottom: float.wrap === "topAndBottom",
24729
25987
  ...float.wrapText === "bothSides" ? { bothSides: true } : {}
24730
25988
  }));
25989
+ for (const column of page.columns)
25990
+ for (const block of column.blocks) {
25991
+ if (block.kind !== "table" || !block.floating) continue;
25992
+ const distance = block.floating;
25993
+ list.push({
25994
+ xPx: page.marginLeftPx + column.xPx + (block.xPx ?? 0) - distance.leftPx,
25995
+ yPx: page.marginTopPx + block.yPx - distance.topPx,
25996
+ widthPx: (block.widthPx ?? 0) + distance.leftPx + distance.rightPx,
25997
+ heightPx: block.heightPx + distance.topPx + distance.bottomPx,
25998
+ topAndBottom: false,
25999
+ bothSides: true
26000
+ });
26001
+ }
24731
26002
  if (list.length) exclusions.set(page.index, list);
24732
26003
  }
24733
26004
  return exclusions;
@@ -24928,7 +26199,11 @@ var SectionFlow = class {
24928
26199
  const key = `${index}:${this.cursor.columnWidthPx}`;
24929
26200
  let cached = this.firstRowHeightCache.get(key);
24930
26201
  if (cached === void 0) {
24931
- const table = this.blocks[index];
26202
+ const table = resolveTableAutofit(
26203
+ this.blocks[index],
26204
+ this.cursor.columnWidthPx,
26205
+ this.measurer
26206
+ );
24932
26207
  const [firstRow] = table.rows;
24933
26208
  cached = firstRow ? layoutRow(firstRow, this.cursor.columnWidthPx, this.measurer, this.note).heightPx : 0;
24934
26209
  this.firstRowHeightCache.set(key, cached);
@@ -24957,7 +26232,7 @@ var SectionFlow = class {
24957
26232
  requiredKeepHeight(index, depth = 0) {
24958
26233
  if (index >= this.blocks.length || depth > 64) return 0;
24959
26234
  const block = expectDefined(this.blocks[index], "keep-chain block index");
24960
- if (block.kind === "table") return this.firstRowHeight(index);
26235
+ if (block.kind === "table") return block.floating ? 0 : this.firstRowHeight(index);
24961
26236
  const layout = this.paragraphLayout(index);
24962
26237
  const before = this.spacingBeforeFor(index);
24963
26238
  const own2 = before + (block.keepLines ? layout.contentHeightPx + layout.spacingAfterPx : layout.lines[0]?.heightPx ?? 0);
@@ -25116,7 +26391,9 @@ function alignVertically(pages, section, note) {
25116
26391
  const available = page.heightPx - page.marginTopPx - page.marginBottomPx - footnoteHeight;
25117
26392
  const used = Math.max(
25118
26393
  0,
25119
- ...page.columns.flatMap((column) => column.blocks.map((block) => block.yPx + block.heightPx))
26394
+ ...page.columns.flatMap(
26395
+ (column) => column.blocks.filter(inFlow).map((block) => block.yPx + block.heightPx)
26396
+ )
25120
26397
  );
25121
26398
  const shift = (available - used) / (align === "center" ? 2 : 1);
25122
26399
  if (shift <= 0) continue;
@@ -25130,7 +26407,7 @@ function layoutSections(input, measurer, exclusions) {
25130
26407
  let previousFlow;
25131
26408
  input.sections.forEach((section, index) => {
25132
26409
  insertParityBlank(pages, section);
25133
- const first3 = pages.length;
26410
+ const first4 = pages.length;
25134
26411
  const previous = input.sections[index - 1];
25135
26412
  const page = pages.at(-1);
25136
26413
  let continueAt;
@@ -25182,7 +26459,7 @@ function layoutSections(input, measurer, exclusions) {
25182
26459
  }
25183
26460
  }
25184
26461
  previousFlow = flow;
25185
- alignVertically(pages.slice(first3), section, note);
26462
+ alignVertically(pages.slice(first4), section, note);
25186
26463
  });
25187
26464
  return { pages, approximations: [...approximations] };
25188
26465
  }
@@ -25441,21 +26718,21 @@ function detectFontScript(codePoint) {
25441
26718
  }
25442
26719
  return "latin";
25443
26720
  }
25444
- function segmentByScript(text2) {
25445
- if (!text2) {
26721
+ function segmentByScript(text3) {
26722
+ if (!text3) {
25446
26723
  return [];
25447
26724
  }
25448
26725
  const runs = [];
25449
26726
  let currentScript = null;
25450
26727
  let currentStart = 0;
25451
26728
  let currentText = "";
25452
- for (let i = 0; i < text2.length; i++) {
25453
- const codePoint = text2.codePointAt(i);
26729
+ for (let i = 0; i < text3.length; i++) {
26730
+ const codePoint = text3.codePointAt(i);
25454
26731
  if (codePoint === void 0) {
25455
26732
  continue;
25456
26733
  }
25457
26734
  const charLength = codePoint > 65535 ? 2 : 1;
25458
- const char = text2.substring(i, i + charLength);
26735
+ const char = text3.substring(i, i + charLength);
25459
26736
  const isNeutral = codePoint <= 127 && !/[a-zA-Z0-9]/u.test(char);
25460
26737
  const script = isNeutral ? currentScript ?? "latin" : detectFontScript(codePoint);
25461
26738
  if (script !== currentScript && currentScript !== null) {
@@ -25496,9 +26773,9 @@ function resolveFontForScript(script, fonts) {
25496
26773
  }
25497
26774
 
25498
26775
  // text/script-fonts.ts
25499
- function segmentByFont(text2, fonts) {
26776
+ function segmentByFont(text3, fonts) {
25500
26777
  const result = [];
25501
- for (const run of segmentByScript(text2)) {
26778
+ for (const run of segmentByScript(text3)) {
25502
26779
  const fontFamily = resolveFontForScript(run.script, fonts) ?? fonts.latin;
25503
26780
  const previous = result.at(-1);
25504
26781
  if (previous?.fontFamily === fontFamily) previous.text += run.text;
@@ -25597,13 +26874,13 @@ function mergeSiblings(nodes) {
25597
26874
  }
25598
26875
  }
25599
26876
  if (!isGroupedByTag(entries.map(([key]) => key))) {
25600
- const counts = /* @__PURE__ */ new Map();
26877
+ const counts2 = /* @__PURE__ */ new Map();
25601
26878
  for (const [key] of entries) {
25602
- counts.set(key, (counts.get(key) ?? 0) + 1);
26879
+ counts2.set(key, (counts2.get(key) ?? 0) + 1);
25603
26880
  }
25604
26881
  const ordered = /* @__PURE__ */ Object.create(null);
25605
26882
  for (const [position, [key, value]] of entries.entries()) {
25606
- ordered[(counts.get(key) ?? 0) > 1 ? orderedXmlKey(key, position) : key] = value;
26883
+ ordered[(counts2.get(key) ?? 0) > 1 ? orderedXmlKey(key, position) : key] = value;
25607
26884
  }
25608
26885
  return ordered;
25609
26886
  }
@@ -25916,16 +27193,16 @@ function escapeChar(ch) {
25916
27193
  }
25917
27194
  return REVERSE_ESCAPE[ch] ?? ch;
25918
27195
  }
25919
- function escapeMathText(text2) {
25920
- return Array.from(text2).map(escapeChar).join("");
27196
+ function escapeMathText(text3) {
27197
+ return Array.from(text3).map(escapeChar).join("");
25921
27198
  }
25922
27199
  var TEXT_ARGUMENT_ESCAPES = {
25923
27200
  "\\": "\\backslash ",
25924
27201
  "{": "\\{",
25925
27202
  "}": "\\}"
25926
27203
  };
25927
- function escapeTextArgument(text2) {
25928
- return text2.replace(/[\\{}]/gu, (ch) => TEXT_ARGUMENT_ESCAPES[ch] ?? ch);
27204
+ function escapeTextArgument(text3) {
27205
+ return text3.replace(/[\\{}]/gu, (ch) => TEXT_ARGUMENT_ESCAPES[ch] ?? ch);
25929
27206
  }
25930
27207
  function isSingleAtom(container) {
25931
27208
  const sole = soleChild(container);
@@ -25935,11 +27212,11 @@ function isSingleAtom(container) {
25935
27212
  if (sole.tag !== "m:r") {
25936
27213
  return true;
25937
27214
  }
25938
- const text2 = readRunText(sole.node);
27215
+ const text3 = readRunText(sole.node);
25939
27216
  if (isOn(childNode(childNode(sole.node, "m:rPr"), "m:nor"))) {
25940
27217
  return true;
25941
27218
  }
25942
- return Array.from(text2).length === 1;
27219
+ return Array.from(text3).length === 1;
25943
27220
  }
25944
27221
  function collectText(node) {
25945
27222
  if (node === null || node === void 0) {
@@ -26074,14 +27351,14 @@ function scriptBase(node) {
26074
27351
  return isSingleAtom(childNode(node, "m:e")) || base.length <= 1 ? base : `{${base}}`;
26075
27352
  }
26076
27353
  function runToLatex(node) {
26077
- const text2 = readRunText(node);
26078
- if (text2.length === 0) {
27354
+ const text3 = readRunText(node);
27355
+ if (text3.length === 0) {
26079
27356
  return "";
26080
27357
  }
26081
27358
  if (isOn(childNode(childNode(node, "m:rPr"), "m:nor"))) {
26082
- return `\\text{${escapeTextArgument(text2)}}`;
27359
+ return `\\text{${escapeTextArgument(text3)}}`;
26083
27360
  }
26084
- return escapeMathText(text2);
27361
+ return escapeMathText(text3);
26085
27362
  }
26086
27363
  function fractionToLatex(node) {
26087
27364
  const type = attrVal(childNode(childNode(node, "m:fPr"), "m:type"));
@@ -26263,8 +27540,8 @@ function attr2(node, name2) {
26263
27540
  function val(node) {
26264
27541
  return attr2(node, "val");
26265
27542
  }
26266
- function escapeXml2(text2) {
26267
- return text2.replace(/&/gu, "&amp;").replace(/</gu, "&lt;").replace(/>/gu, "&gt;");
27543
+ function escapeXml2(text3) {
27544
+ return text3.replace(/&/gu, "&amp;").replace(/</gu, "&lt;").replace(/>/gu, "&gt;");
26268
27545
  }
26269
27546
  function readText(node) {
26270
27547
  const textNode = node["m:t"];
@@ -26364,8 +27641,8 @@ function glyphEm(ch, bold) {
26364
27641
  return bold ? em * 1.08 : em;
26365
27642
  }
26366
27643
  var isOn2 = (value) => value === "1" || value === "on" || value === "true";
26367
- function glyph(text2, size, stretch = 1) {
26368
- const width = Array.from(text2).reduce((sum, ch) => sum + glyphEm(ch, false), 0) * size;
27644
+ function glyph(text3, size, stretch = 1) {
27645
+ const width = Array.from(text3).reduce((sum, ch) => sum + glyphEm(ch, false), 0) * size;
26369
27646
  const box = emptyBox();
26370
27647
  box.width = width;
26371
27648
  box.ascent = size * 0.78 * stretch;
@@ -26374,7 +27651,7 @@ function glyph(text2, size, stretch = 1) {
26374
27651
  kind: "text",
26375
27652
  x: 0,
26376
27653
  y: 0,
26377
- text: text2,
27654
+ text: text3,
26378
27655
  size,
26379
27656
  italic: false,
26380
27657
  bold: false,
@@ -26688,12 +27965,12 @@ function layoutStructure(tag, node, style, ctx) {
26688
27965
  var isOn3 = (value) => value === "1" || value === "on" || value === "true";
26689
27966
  var isUnaryContext = (ch) => isRelation(ch) || isBinary(ch) || /[([{,;:]/.test(ch);
26690
27967
  function lastCharOf(node) {
26691
- const text2 = readText(node);
26692
- return text2 ? Array.from(text2).at(-1) ?? "" : "";
27968
+ const text3 = readText(node);
27969
+ return text3 ? Array.from(text3).at(-1) ?? "" : "";
26693
27970
  }
26694
27971
  function layoutRun(node, style, atStart) {
26695
- const text2 = readText(node);
26696
- if (!text2) return emptyBox();
27972
+ const text3 = readText(node);
27973
+ if (!text3) return emptyBox();
26697
27974
  const rPr = child(node, "m:rPr");
26698
27975
  const sty = val(child(rPr, "m:sty"));
26699
27976
  const plain2 = style.plain || isOn3(val(child(rPr, "m:nor"))) || sty === "p" || sty === "b";
@@ -26701,7 +27978,7 @@ function layoutRun(node, style, atStart) {
26701
27978
  const boxes = [];
26702
27979
  let index = 0;
26703
27980
  let previous = atStart ? "(" : "x";
26704
- for (const raw of Array.from(text2)) {
27981
+ for (const raw of Array.from(text3)) {
26705
27982
  const ch = raw === "-" ? "\u2212" : raw;
26706
27983
  const italic = !plain2 && /[A-Za-zα-ω]/.test(ch);
26707
27984
  const unary = index === 0 ? atStart : isUnaryContext(previous);
@@ -26794,8 +28071,8 @@ function ommlFromElement(element) {
26794
28071
  if (attribute.namespaceURI === "http://www.w3.org/2000/xmlns/") continue;
26795
28072
  body[`@_${attribute.localName}`] = attribute.value;
26796
28073
  }
26797
- const text2 = Array.from(node.childNodes).filter((child2) => child2.nodeType === 3 || child2.nodeType === 4).map((child2) => child2.nodeValue ?? "").join("");
26798
- if (text2 && (!elements(node).length || text2.trim())) body["#text"] = text2;
28074
+ const text3 = Array.from(node.childNodes).filter((child2) => child2.nodeType === 3 || child2.nodeType === 4).map((child2) => child2.nodeValue ?? "").join("");
28075
+ if (text3 && (!elements(node).length || text3.trim())) body["#text"] = text3;
26799
28076
  return { [name2]: body };
26800
28077
  };
26801
28078
  return visit(element, 1);
@@ -26843,7 +28120,7 @@ function drawEquation(omml, sizePx, label = "", options2 = {}) {
26843
28120
  }
26844
28121
 
26845
28122
  // docx/layout/equation-object.ts
26846
- var cache = /* @__PURE__ */ new Map();
28123
+ var cache2 = /* @__PURE__ */ new Map();
26847
28124
  var CACHE_LIMIT = 256;
26848
28125
  function latexLabel(omml) {
26849
28126
  try {
@@ -26854,7 +28131,7 @@ function latexLabel(omml) {
26854
28131
  }
26855
28132
  function equationObject(omml, sizePx, display = false) {
26856
28133
  const key = `${sizePx}|${display}|${omml}`;
26857
- const hit = cache.get(key);
28134
+ const hit = cache2.get(key);
26858
28135
  if (hit !== void 0) return hit ?? void 0;
26859
28136
  const drawing = drawEquation(omml, sizePx, latexLabel(omml), { display });
26860
28137
  const object = drawing ? {
@@ -26865,19 +28142,55 @@ function equationObject(omml, sizePx, display = false) {
26865
28142
  descentPx: drawing.descentPx,
26866
28143
  chart: { svg: drawing.svg, label: "Equation" }
26867
28144
  } : null;
26868
- if (cache.size >= CACHE_LIMIT) cache.delete(cache.keys().next().value);
26869
- cache.set(key, object);
28145
+ if (cache2.size >= CACHE_LIMIT) cache2.delete(cache2.keys().next().value);
28146
+ cache2.set(key, object);
26870
28147
  return object ?? void 0;
26871
28148
  }
26872
28149
 
28150
+ // docx/run-language.ts
28151
+ function resolveEastAsiaLanguage(run, context = {}) {
28152
+ if (run.eastAsiaLanguage !== void 0) return run.eastAsiaLanguage;
28153
+ const catalog = context.runCatalog;
28154
+ if (!catalog) return void 0;
28155
+ const chainLanguage = (styleId) => {
28156
+ const visited = /* @__PURE__ */ new Set();
28157
+ for (let current = styleId; current && !visited.has(current); ) {
28158
+ visited.add(current);
28159
+ const style = catalog.styles[current];
28160
+ if (!style) return void 0;
28161
+ if (style.eastAsiaLanguage !== void 0) return style.eastAsiaLanguage;
28162
+ current = style.basedOn;
28163
+ }
28164
+ return void 0;
28165
+ };
28166
+ const paragraphStyle = context.paragraphStyleId || (context.paragraphCatalog ? Object.values(context.paragraphCatalog.styles).find((style) => style.isDefault)?.id : void 0);
28167
+ return chainLanguage(run.style) ?? chainLanguage(paragraphStyle) ?? catalog.docDefaultsEastAsiaLanguage;
28168
+ }
28169
+
28170
+ // docx/layout/adapt-table-floating.ts
28171
+ function floatingFrame(position) {
28172
+ const px = (twips2) => twips2 === void 0 ? 0 : twipsToPixels(twips2);
28173
+ const relativeFromH = position.horizontalAnchor === "page" || position.horizontalAnchor === "margin" ? position.horizontalAnchor : "column";
28174
+ const relativeFromV = position.verticalAnchor === "page" ? "page" : position.verticalAnchor === "text" || position.yAlign === "inline" ? "paragraph" : "margin";
28175
+ const alignV = position.yAlign === "inline" ? void 0 : position.yAlign;
28176
+ return {
28177
+ relativeFromH,
28178
+ ...position.xAlign ? { alignH: position.xAlign } : {},
28179
+ offsetXPx: px(position.xTwips),
28180
+ relativeFromV,
28181
+ ...alignV ? { alignV } : {},
28182
+ offsetYPx: position.yAlign === "inline" ? 0 : px(position.yTwips),
28183
+ distance: {
28184
+ topPx: px(position.topFromTextTwips),
28185
+ rightPx: px(position.rightFromTextTwips),
28186
+ bottomPx: px(position.bottomFromTextTwips),
28187
+ leftPx: px(position.leftFromTextTwips)
28188
+ }
28189
+ };
28190
+ }
28191
+
26873
28192
  // docx/layout/adapt-table.ts
26874
28193
  var twipsToPx2 = twipsToPixels;
26875
- var DEFAULT_PADDING_TWIPS = {
26876
- top: twips(0),
26877
- right: twips(108),
26878
- bottom: twips(0),
26879
- left: twips(108)
26880
- };
26881
28194
  function cssHex(value) {
26882
28195
  const hex = value?.replace(/^#/, "");
26883
28196
  return hex && /^[0-9a-f]{6}$/i.test(hex) ? `#${hex}` : void 0;
@@ -26915,6 +28228,7 @@ function adaptTable(table, model, adaptParagraph, _nested = false) {
26915
28228
  });
26916
28229
  });
26917
28230
  const merges = tableGrid(table);
28231
+ const tableMargins = resolveTableCellMargins(table, model.tableStyles);
26918
28232
  const cellAt = (rowIndex, gridIndex) => {
26919
28233
  const position = gridIndexes[rowIndex]?.indexOf(gridIndex) ?? -1;
26920
28234
  return position >= 0 ? table.rows[rowIndex]?.[position] : void 0;
@@ -26925,6 +28239,18 @@ function adaptTable(table, model, adaptParagraph, _nested = false) {
26925
28239
  ...grid ? { widthPx: grid.reduce((sum, width) => sum + width, 0) } : {},
26926
28240
  ...table.indentTwips ? { indentPx: twipsToPx2(table.indentTwips) } : {},
26927
28241
  ...table.alignment ? { alignment: table.alignment } : {},
28242
+ ...table.layout === "autofit" ? {
28243
+ autofit: {
28244
+ columns: Math.max(
28245
+ columnCount,
28246
+ ...table.rows.map((row2) => row2.reduce((sum, cell) => sum + (cell.gridSpan ?? 1), 0))
28247
+ ),
28248
+ ...table.widthTwips ? { widthPx: twipsToPx2(table.widthTwips) } : {},
28249
+ ...table.widthPercent ? { widthFraction: table.widthPercent } : {},
28250
+ ...autofitOverhangsCellMargins(compatibilityProfile(model)) ? { legacyMargins: true } : {}
28251
+ }
28252
+ } : {},
28253
+ ...table.floating && !_nested ? { floating: floatingFrame(table.floating) } : {},
26928
28254
  rows: table.rows.map((row2, rowIndex) => ({
26929
28255
  ...rowLayout(table.rowProperties?.[rowIndex]),
26930
28256
  cells: row2.map((cell, cellIndex) => {
@@ -26950,7 +28276,7 @@ function adaptTable(table, model, adaptParagraph, _nested = false) {
26950
28276
  }
26951
28277
  if (cell.verticalMerge === "continue") delete borders.top;
26952
28278
  if (cellAt(rowIndex + 1, start)?.verticalMerge === "continue") delete borders.bottom;
26953
- const margins = { ...DEFAULT_PADDING_TWIPS, ...table.cellMargins, ...cell.margins };
28279
+ const margins = { ...tableMargins, ...cell.margins };
26954
28280
  const padding = {
26955
28281
  top: twipsToPx2(margins.top),
26956
28282
  right: twipsToPx2(margins.right),
@@ -26974,6 +28300,8 @@ function adaptTable(table, model, adaptParagraph, _nested = false) {
26974
28300
  } : {},
26975
28301
  ...width !== void 0 ? { widthPx: width } : {},
26976
28302
  ...grid && xPx !== void 0 ? { xPx } : {},
28303
+ ...cell.widthTwips ? { preferredWidthPx: twipsToPx2(cell.widthTwips) } : {},
28304
+ ...cell.widthPercent ? { preferredFraction: cell.widthPercent } : {},
26977
28305
  padding,
26978
28306
  ...Object.keys(borders).length ? { borders } : {},
26979
28307
  ...fill ? { shading: fill } : {},
@@ -27114,8 +28442,9 @@ function adaptDocumentModel(model, note = () => {
27114
28442
  const reviewMode = options2.reviewDisplayMode ?? "all";
27115
28443
  const visibleModel = visibleReviewModel(model, reviewMode);
27116
28444
  const catalog = model.paragraphStyles;
27117
- const addParagraphSpacing = model.doNotUseHtmlParagraphAutoSpacing === true;
27118
- const keepSpaceBeforePageBreak = model.compatibilityMode !== 15;
28445
+ const compatibility = compatibilityProfile(model);
28446
+ const addParagraphSpacing = addsParagraphSpacing(compatibility);
28447
+ const keepSpaceBeforePageBreak = keepsSpaceBeforePageBreak(compatibility);
27119
28448
  const autoSpaced = (auto, twipsValue) => auto && !addParagraphSpacing ? HTML_AUTO_SPACING_TWIPS : twipsValue;
27120
28449
  const noted = /* @__PURE__ */ new Set();
27121
28450
  const reportOnce = (message) => {
@@ -27152,7 +28481,7 @@ function adaptDocumentModel(model, note = () => {
27152
28481
  const noteText = run.noteReference ? noteLabel(run.noteReference.kind, run.noteReference.id) : run.noteMark ? markLabel ?? "" : void 0;
27153
28482
  const formText = formFieldDisplayText(run);
27154
28483
  const shaded = model.formFieldShading !== false && (formText !== void 0 || name2 === "FORMTEXT");
27155
- const text2 = noteText ?? formText ?? (run.field && !isFieldLocked(run) && (name2 === "DATE" || name2 === "TIME") ? dateFieldResult(name2, run.field.instr, now) : run.equation ? equation ? "" : "[Equation]" : run.text);
28484
+ const text3 = noteText ?? formText ?? (run.field && !isFieldLocked(run) && (name2 === "DATE" || name2 === "TIME") ? dateFieldResult(name2, run.field.instr, now) : run.equation ? equation ? "" : "[Equation]" : run.text);
27156
28485
  const script = formatting.verticalAlign === "superscript" || noteText !== void 0 && formatting.verticalAlign === void 0 ? "super" : formatting.verticalAlign === "subscript" ? "sub" : void 0;
27157
28486
  const image = run.image;
27158
28487
  if (image?.unsupported === "Text box") reportOnce(TEXT_BOX_NOTE);
@@ -27162,19 +28491,22 @@ function adaptDocumentModel(model, note = () => {
27162
28491
  widthPx: 192,
27163
28492
  heightPx: 1,
27164
28493
  noteSeparator: run.noteSeparator
27165
- } : image && !image.anchored ? {
27166
- partName: image.partName,
27167
- ...image.pictureFill ? { pictureFill: image.pictureFill } : {},
27168
- contentType: image.contentType,
27169
- widthPx: image.widthPx,
27170
- heightPx: image.heightPx,
27171
- ...image.chart ? { chart: docxChartPaint(image.chart, image.widthPx, image.heightPx, theme) } : {},
27172
- ...image.shape ? shapeChart(image.shape, image.widthPx, image.heightPx, theme) : {}
27173
- } : void 0);
28494
+ } : (
28495
+ // A picture watermark floats behind the page text and takes no room in the header.
28496
+ image && !image.anchored && !image.pictureWatermark ? {
28497
+ partName: image.partName,
28498
+ ...image.pictureFill ? { pictureFill: image.pictureFill } : {},
28499
+ contentType: image.contentType,
28500
+ widthPx: image.widthPx,
28501
+ heightPx: image.heightPx,
28502
+ ...image.chart ? { chart: docxChartPaint(image.chart, image.widthPx, image.heightPx, theme) } : {},
28503
+ ...image.shape ? shapeChart(image.shape, image.widthPx, image.heightPx, theme) : {}
28504
+ } : void 0
28505
+ ));
27174
28506
  return {
27175
28507
  sourceLength: reviewSourceLength(run),
27176
28508
  // Hidden text (`w:vanish`) takes no space when printed, as in Word by default.
27177
- text: image || formatting.vanish ? "" : formatting.caps ? text2.toUpperCase() : text2,
28509
+ text: image || formatting.vanish ? "" : formatting.caps ? text3.toUpperCase() : text3,
27178
28510
  ...run.noteReference?.kind === "footnote" ? { footnoteReferenceId: run.noteReference.id } : {},
27179
28511
  ...object ? { object } : {},
27180
28512
  ...definedProps({
@@ -27194,17 +28526,26 @@ function adaptDocumentModel(model, note = () => {
27194
28526
  ...formatting.underline ? { underline: true } : {},
27195
28527
  ...formatting.strike || formatting.doubleStrike ? { strike: true } : {},
27196
28528
  ...run.break ? { breakAfter: run.break } : {},
27197
- ...script ? { script } : {}
28529
+ ...script ? { script } : {},
28530
+ ...definedProps({
28531
+ kinsokuLanguage: kinsokuLanguage(
28532
+ resolveEastAsiaLanguage(run, {
28533
+ runCatalog: model.characterStyles,
28534
+ paragraphCatalog: catalog,
28535
+ paragraphStyleId
28536
+ })
28537
+ )
28538
+ })
27198
28539
  };
27199
28540
  }
27200
28541
  const labels = computeListLabels(model);
27201
28542
  function labelRun(paragraph, label) {
27202
- const first3 = adaptRun(paragraph.runs[0] ?? { text: "" }, paragraph.style);
28543
+ const first4 = adaptRun(paragraph.runs[0] ?? { text: "" }, paragraph.style);
27203
28544
  const marker = label.markerFormat;
27204
28545
  const suffix = label.suffix === "tab" ? " " : label.suffix === "space" ? " " : "";
27205
28546
  const pictureWidthPx = label.picture ? pictureBulletSizePt(
27206
28547
  label.picture,
27207
- marker?.fontSizeHalfPoints ? marker.fontSizeHalfPoints / 2 : first3.fontSizePt ?? 11
28548
+ marker?.fontSizeHalfPoints ? marker.fontSizeHalfPoints / 2 : first4.fontSizePt ?? 11
27208
28549
  ).widthPt * 4 / 3 : void 0;
27209
28550
  return {
27210
28551
  text: `${displayListLabel(label.text)}${suffix}`,
@@ -27215,12 +28556,12 @@ function adaptDocumentModel(model, note = () => {
27215
28556
  ...pictureWidthPx !== void 0 ? { widthPx: pictureWidthPx } : {}
27216
28557
  },
27217
28558
  ...definedProps({
27218
- bold: marker?.bold ?? first3.bold,
27219
- italic: marker?.italic ?? first3.italic,
27220
- fontFamily: marker?.fontFamily ?? first3.fontFamily,
27221
- fontSizePt: marker?.fontSizeHalfPoints ? marker.fontSizeHalfPoints / 2 : first3.fontSizePt
28559
+ bold: marker?.bold ?? first4.bold,
28560
+ italic: marker?.italic ?? first4.italic,
28561
+ fontFamily: marker?.fontFamily ?? first4.fontFamily,
28562
+ fontSizePt: marker?.fontSizeHalfPoints ? marker.fontSizeHalfPoints / 2 : first4.fontSizePt
27222
28563
  }),
27223
- ...marker?.color || first3.color ? { color: marker?.color ?? first3.color } : {}
28564
+ ...marker?.color || first4.color ? { color: marker?.color ?? first4.color } : {}
27224
28565
  };
27225
28566
  }
27226
28567
  const betweenBorders = /* @__PURE__ */ new Map();
@@ -27286,7 +28627,12 @@ function adaptDocumentModel(model, note = () => {
27286
28627
  ...resolved.keepNext ? { keepNext: true } : {},
27287
28628
  ...resolved.keepLines ? { keepLines: true } : {},
27288
28629
  ...resolved.widowControl === false ? { widowControl: false } : {},
27289
- ...resolved.contextualSpacing ? { contextualSpacing: true } : {}
28630
+ ...resolved.contextualSpacing ? { contextualSpacing: true } : {},
28631
+ ...resolved.kinsoku === false ? { kinsoku: false } : {},
28632
+ ...resolved.autoSpaceDE === false ? { autoSpaceDE: false } : {},
28633
+ ...resolved.autoSpaceDN === false ? { autoSpaceDN: false } : {},
28634
+ ...resolved.overflowPunct === false ? { overflowPunct: false } : {},
28635
+ ...model.kinsoku ? { kinsokuSettings: model.kinsoku } : {}
27290
28636
  };
27291
28637
  }
27292
28638
  function adaptBlock(block) {
@@ -27319,8 +28665,8 @@ function adaptDocumentModel(model, note = () => {
27319
28665
  ])
27320
28666
  ) : void 0;
27321
28667
  const sections2 = model.sections;
27322
- const modernFootnoteSeparator = model.compatibilityMode === 15;
27323
- const legacyFootnoteColumns = model.compatibilityMode === 12 || model.compatibilityMode === 14;
28668
+ const modernFootnoteSeparator = usesModernFootnoteLayout(compatibility);
28669
+ const legacyFootnoteColumns = attachesFootnotesToBodyColumns(compatibility);
27324
28670
  if (!modernFootnoteSeparator && !legacyFootnoteColumns && model.sections?.some((section) => section.footnoteColumns !== void 0))
27325
28671
  reportOnce(
27326
28672
  "Footnote column settings are preserved, but this compatibility mode has not been verified against native Word; Print Layout uses the existing page-wide fallback."
@@ -27429,112 +28775,100 @@ function adaptDocumentModel(model, note = () => {
27429
28775
  };
27430
28776
  }
27431
28777
 
27432
- // docx/layout/floats.ts
27433
- var FLOAT_WRAP_NOTE = "Text wraps around floating pictures on their largest side, or on both sides of a square, tight or through picture whose wrapText is bothSides (all use the picture\u2019s rectangle, not its outline); lines continuing onto a later page keep their wrapped widths.";
27434
- function horizontalArea(float, page, column) {
27435
- const contentLeft = page.marginLeftPx;
27436
- switch (float.relativeFromH) {
27437
- case "page":
27438
- return { start: 0, size: page.widthPx };
27439
- case "margin":
27440
- return { start: contentLeft, size: page.widthPx - contentLeft - page.marginRightPx };
27441
- case "leftMargin":
27442
- case "insideMargin":
27443
- return { start: 0, size: contentLeft };
27444
- case "rightMargin":
27445
- case "outsideMargin":
27446
- return { start: page.widthPx - page.marginRightPx, size: page.marginRightPx };
27447
- default:
27448
- return { start: contentLeft + column.xPx, size: column.widthPx };
28778
+ // docx/layout/computed-field-runs.ts
28779
+ function patches(paragraph, fields) {
28780
+ if (!paragraph.runs.some((run) => run.field || run.fieldChar)) return [];
28781
+ const starts = [];
28782
+ let offset = 0;
28783
+ for (const run of paragraph.runs) {
28784
+ starts.push(offset);
28785
+ offset += reviewSourceLength(run);
27449
28786
  }
27450
- }
27451
- function verticalArea(float, page, paragraphTopPx, paragraphHeightPx) {
27452
- switch (float.relativeFromV) {
27453
- case "page":
27454
- return { start: 0, size: page.heightPx };
27455
- case "margin":
27456
- return {
27457
- start: page.marginTopPx,
27458
- size: page.heightPx - page.marginTopPx - page.marginBottomPx
27459
- };
27460
- case "topMargin":
27461
- case "insideMargin":
27462
- return { start: 0, size: page.marginTopPx };
27463
- case "bottomMargin":
27464
- case "outsideMargin":
27465
- return { start: page.heightPx - page.marginBottomPx, size: page.marginBottomPx };
27466
- default:
27467
- return { start: paragraphTopPx, size: paragraphHeightPx };
28787
+ const stretch = (at) => ({
28788
+ from: starts[at],
28789
+ to: starts[at] + reviewSourceLength(paragraph.runs[at]),
28790
+ source: paragraph.runs[at].text
28791
+ });
28792
+ const found = [];
28793
+ for (const field of fieldResultSpans(paragraph.runs, { resultless: true })) {
28794
+ if (field.locked) continue;
28795
+ const result = fields.result(field, paragraph);
28796
+ if (!result) continue;
28797
+ if (field.resultless) found.push({ ...stretch(field.to), result });
28798
+ else
28799
+ field.runs.forEach(
28800
+ (at, index) => found.push({ ...stretch(at), result: index === 0 ? result : void 0 })
28801
+ );
27468
28802
  }
28803
+ return found;
27469
28804
  }
27470
- function place(area, size, align, offset) {
27471
- if (align === "center") return area.start + (area.size - size) / 2;
27472
- if (align === "right" || align === "bottom" || align === "outside")
27473
- return area.start + area.size - size;
27474
- if (align) return area.start;
27475
- return area.start + (offset ?? 0);
27476
- }
27477
- function floatPosition(float, page, column, paragraph) {
27478
- const h = horizontalArea(float, page, column);
27479
- const v = verticalArea(float, page, paragraph.topPx, paragraph.heightPx);
28805
+ function patched(run, patch, first4) {
28806
+ const { result } = patch;
28807
+ const sourceLength = run.sourceLength ?? run.text.length;
28808
+ const text3 = first4 && result ? result.text : "";
28809
+ const caps = run.text !== patch.source && run.text === patch.source.toUpperCase();
27480
28810
  return {
27481
- xPx: place(h, float.widthPx, float.alignH, float.offsetXPx),
27482
- yPx: place(v, float.heightPx, float.alignV, float.offsetYPx)
28811
+ ...run,
28812
+ text: caps ? text3.toUpperCase() : text3,
28813
+ sourceLength,
28814
+ ...first4 && result?.fontFamily ? { fontFamily: result.fontFamily } : {},
28815
+ ...first4 && result?.fontSizePt ? { fontSizePt: result.fontSizePt } : {}
27483
28816
  };
27484
28817
  }
27485
- function floatOrigin(float, page, column, paragraph) {
27486
- return {
27487
- xPx: horizontalArea(float, page, column).start,
27488
- yPx: verticalArea(float, page, paragraph.topPx, paragraph.heightPx).start
28818
+ function paragraphWithResults2(paragraph, model, fields) {
28819
+ const list = model ? patches(model, fields) : [];
28820
+ if (!list.length) return paragraph;
28821
+ let offset = 0;
28822
+ let changed = false;
28823
+ const runs = paragraph.runs.map((run) => {
28824
+ if (run.synthetic) return run;
28825
+ const from = offset;
28826
+ offset += run.sourceLength ?? run.text.length;
28827
+ const patch = list.find((item) => from >= item.from && from < item.to);
28828
+ if (!patch || run.hidden || run.object || run.text === "" && patch.source !== "") return run;
28829
+ changed = true;
28830
+ return patched(run, patch, from === patch.from);
28831
+ });
28832
+ return changed ? { ...paragraph, runs } : paragraph;
28833
+ }
28834
+ function withComputedFieldRuns(input, model) {
28835
+ const fields = computedFields(model);
28836
+ const paragraphs = new Map(documentParagraphs(model.blocks).map((item) => [item.id, item]));
28837
+ const block = (item) => {
28838
+ if (item.kind === "paragraph")
28839
+ return paragraphWithResults2(item, paragraphs.get(item.id), fields);
28840
+ let changed2 = false;
28841
+ const rows2 = item.rows.map((row2) => {
28842
+ const cells = row2.cells.map((cell) => {
28843
+ const next = cell.paragraphs.map((paragraph) => block(paragraph));
28844
+ const blocks = cell.blocks?.map(block);
28845
+ if (next.every((paragraph, index) => paragraph === cell.paragraphs[index]) && (blocks ?? []).every((child2, index) => child2 === cell.blocks[index]))
28846
+ return cell;
28847
+ changed2 = true;
28848
+ return { ...cell, paragraphs: next, ...blocks ? { blocks } : {} };
28849
+ });
28850
+ return cells.every((cell, index) => cell === row2.cells[index]) ? row2 : { ...row2, cells };
28851
+ });
28852
+ return changed2 ? { ...item, rows: rows2 } : item;
27489
28853
  };
27490
- }
27491
- function positionFloats(input, pages) {
27492
- const floatsById = /* @__PURE__ */ new Map();
27493
- for (const section of input.sections)
27494
- for (const block of section.blocks)
27495
- if (block.kind === "paragraph" && block.floats?.length)
27496
- floatsById.set(block.id, block.floats);
27497
- if (!floatsById.size) return false;
27498
- const placed2 = /* @__PURE__ */ new Set();
27499
- for (const page of pages) {
27500
- const boxes = [];
27501
- for (const column of page.columns)
27502
- for (const block of column.blocks) {
27503
- const floats = block.kind === "paragraph" ? floatsById.get(block.blockId) : void 0;
27504
- if (!floats || placed2.has(block.blockId)) continue;
27505
- placed2.add(block.blockId);
27506
- const top = page.marginTopPx + block.yPx;
27507
- for (const float of floats) {
27508
- const frame2 = { topPx: top, heightPx: block.heightPx };
27509
- const position = floatPosition(float, page, column, frame2);
27510
- const origin = floatOrigin(float, page, column, frame2);
27511
- boxes.push({
27512
- blockId: block.blockId,
27513
- index: float.index ?? floats.indexOf(float),
27514
- originXPx: origin.xPx,
27515
- originYPx: origin.yPx,
27516
- ...position,
27517
- widthPx: float.widthPx,
27518
- heightPx: float.heightPx,
27519
- partName: float.partName,
27520
- ...float.pictureFill ? { pictureFill: float.pictureFill } : {},
27521
- contentType: float.contentType,
27522
- ...float.chart ? { chart: float.chart } : {},
27523
- behindText: Boolean(float.behindText),
27524
- ...float.wrap ? { wrap: float.wrap } : {},
27525
- ...float.wrapText ? { wrapText: float.wrapText } : {}
27526
- });
27527
- }
27528
- }
27529
- if (boxes.length) page.floats = boxes;
27530
- }
27531
- return true;
28854
+ let changed = false;
28855
+ const sections2 = input.sections.map((section) => {
28856
+ const blocks = section.blocks.map(block);
28857
+ if (blocks.every((item, index) => item === section.blocks[index])) return section;
28858
+ changed = true;
28859
+ return { ...section, blocks };
28860
+ });
28861
+ return changed ? { ...input, sections: sections2 } : input;
27532
28862
  }
27533
28863
 
27534
28864
  // docx/layout/layout.ts
27535
28865
  function layoutDocument(input, measurer) {
27536
28866
  let result = layoutSections(input, measurer);
27537
- if (!positionFloats(input, result.pages)) return result;
28867
+ const pictures = positionFloats(input, result.pages);
28868
+ const tables = input.sections.some(
28869
+ (section) => section.blocks.some((block) => block.kind === "table" && block.floating)
28870
+ );
28871
+ if (!pictures && !tables) return result;
27538
28872
  let exclusions = wrapExclusions(result.pages);
27539
28873
  for (let pass = 0; exclusions.size && pass < 3; pass++) {
27540
28874
  result = layoutSections(input, measurer, exclusions);
@@ -27543,15 +28877,15 @@ function layoutDocument(input, measurer) {
27543
28877
  if (sameExclusions(next, exclusions)) break;
27544
28878
  exclusions = next;
27545
28879
  }
27546
- return { ...result, approximations: [.../* @__PURE__ */ new Set([...result.approximations, FLOAT_WRAP_NOTE])] };
28880
+ const notes = pictures ? [...result.approximations, FLOAT_WRAP_NOTE] : result.approximations;
28881
+ return { ...result, approximations: [...new Set(notes)] };
27547
28882
  }
27548
28883
  function layoutDocumentModel(model, measurer, options2 = {}, layout = layoutDocument) {
27549
28884
  const projected = reviewDocumentFormatting(model, options2.reviewDisplayMode ?? "all");
27550
28885
  const approximations = reviewFormattingWarnings(projected.diagnostics);
27551
- const input = adaptDocumentModel(
27552
- projected.model,
27553
- (message) => approximations.push(message),
27554
- options2
28886
+ const input = withComputedFieldRuns(
28887
+ adaptDocumentModel(projected.model, (message) => approximations.push(message), options2),
28888
+ projected.model
27555
28889
  );
27556
28890
  const result = layout(input, measurer);
27557
28891
  return {
@@ -27611,7 +28945,7 @@ function collectDocxWebfontRuns(model) {
27611
28945
  text: ""
27612
28946
  });
27613
28947
  };
27614
- const emit = (text2, formatting, family) => {
28948
+ const emit = (text3, formatting, family) => {
27615
28949
  const latin = family || DEFAULT_FONT_FAMILY;
27616
28950
  const eaRole = formatting.fontTheme?.eastAsia;
27617
28951
  const csRole = formatting.fontTheme?.cs;
@@ -27623,7 +28957,7 @@ function collectDocxWebfontRuns(model) {
27623
28957
  complexScript: formatting.fontFamilyComplexScript || csRole && theme?.fonts[csRole]?.complexScript || latin,
27624
28958
  symbol: latin
27625
28959
  };
27626
- for (const piece of segmentByFont(text2, fonts))
28960
+ for (const piece of segmentByFont(text3, fonts))
27627
28961
  push({ family: piece.fontFamily, bold, italic, text: piece.text });
27628
28962
  };
27629
28963
  const paragraphRuns = (paragraph, tableStyleRun) => {
@@ -27725,9 +29059,9 @@ function describePages(pages, indexOf) {
27725
29059
  const firstBlock = [];
27726
29060
  const startsBlock = [];
27727
29061
  for (const page of pages) {
27728
- const first3 = paragraphBoxes(page)[0];
27729
- firstBlock.push(first3 ? indexOf.get(first3.blockId) : void 0);
27730
- const line4 = first3?.kind === "paragraph" ? first3.lines[0] : void 0;
29062
+ const first4 = paragraphBoxes(page)[0];
29063
+ firstBlock.push(first4 ? indexOf.get(first4.blockId) : void 0);
29064
+ const line4 = first4?.kind === "paragraph" ? first4.lines[0] : void 0;
27731
29065
  startsBlock.push(line4 !== void 0 && line4.sourceStart === 0);
27732
29066
  }
27733
29067
  return { firstBlock, startsBlock };
@@ -27795,8 +29129,8 @@ function layoutDocumentIncremental(input, measurer, memory) {
27795
29129
  const delta = oldCount - blocks.length;
27796
29130
  let page = 0;
27797
29131
  for (let index = previous.firstBlock.length - 1; index > 0; index--) {
27798
- const first3 = previous.firstBlock[index];
27799
- if (first3 !== void 0 && previous.startsBlock[index] && first3 <= prefix2 - LOOKAHEAD_BLOCKS) {
29132
+ const first4 = previous.firstBlock[index];
29133
+ if (first4 !== void 0 && previous.startsBlock[index] && first4 <= prefix2 - LOOKAHEAD_BLOCKS) {
27800
29134
  page = index;
27801
29135
  break;
27802
29136
  }
@@ -27857,7 +29191,7 @@ function layoutDocumentIncremental(input, measurer, memory) {
27857
29191
  // docx/layout/layout-session.ts
27858
29192
  function createLayoutSession(measurer, options2 = {}) {
27859
29193
  const sessionMeasurer = {
27860
- widthOf: (text2, font) => measurer.widthOf(text2, font),
29194
+ widthOf: (text3, font) => measurer.widthOf(text3, font),
27861
29195
  lineHeightOf: (font) => measurer.lineHeightOf(font),
27862
29196
  ...measurer.ascentOf ? { ascentOf: measurer.ascentOf.bind(measurer) } : {}
27863
29197
  };
@@ -27882,6 +29216,7 @@ exports.SINGLE_LINE_SPACING_UNITS = SINGLE_LINE_SPACING_UNITS;
27882
29216
  exports.adaptDocumentModel = adaptDocumentModel;
27883
29217
  exports.adjustForWidowOrphan = adjustForWidowOrphan;
27884
29218
  exports.appendBreakMarker = appendBreakMarker;
29219
+ exports.breakAllowedBetween = breakAllowedBetween;
27885
29220
  exports.cellVerticalOffset = cellVerticalOffset;
27886
29221
  exports.collectDocxWebfontRuns = collectDocxWebfontRuns;
27887
29222
  exports.createFakeMeasurer = createFakeMeasurer;
@@ -27891,9 +29226,13 @@ exports.fieldDisplayText = fieldDisplayText;
27891
29226
  exports.floatOrigin = floatOrigin;
27892
29227
  exports.floatPosition = floatPosition;
27893
29228
  exports.fontMetrics = fontMetrics;
29229
+ exports.gluedCarry = gluedCarry;
29230
+ exports.graphemesOf = graphemesOf;
27894
29231
  exports.headerFooterForPage = headerFooterForPage;
27895
29232
  exports.headerFooterSlotForPage = headerFooterSlotForPage;
29233
+ exports.inFlow = inFlow;
27896
29234
  exports.isEastAsianChar = isEastAsianChar;
29235
+ exports.kinsokuForbids = kinsokuForbids;
27897
29236
  exports.layoutDocument = layoutDocument;
27898
29237
  exports.layoutDocumentModel = layoutDocumentModel;
27899
29238
  exports.layoutParagraph = layoutParagraph;