ooxml-core 1.30.1 → 1.32.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 (418) hide show
  1. package/dist/{PptxHandler-KKLAYUGQ.mjs → PptxHandler-QY5VL3CY.mjs} +2 -2
  2. package/dist/PptxHandler-SJ5ZUIUX.mjs +4 -0
  3. package/dist/{PptxHandler-DHQPVTUI.cjs → PptxHandler-TESZUH66.cjs} +3 -3
  4. package/dist/{PresentationBuilder-YYZYCKTZ.mjs → PresentationBuilder-3CH5TR4W.mjs} +2 -2
  5. package/dist/{PresentationBuilder-JORMF5CP.cjs → PresentationBuilder-5NFBUP7Y.cjs} +5 -5
  6. package/dist/{PresentationBuilder-Q2Z33LLM.mjs → PresentationBuilder-S6HXHKEJ.mjs} +2 -2
  7. package/dist/automation/index.cjs +6446 -3410
  8. package/dist/automation/index.mjs +6446 -3410
  9. package/dist/automation/node.cjs +2 -1
  10. package/dist/automation/node.d.ts.map +1 -1
  11. package/dist/automation/node.mjs +2 -1
  12. package/dist/automation/tools/define.d.ts +2 -0
  13. package/dist/automation/tools/define.d.ts.map +1 -1
  14. package/dist/automation/tools/types.d.ts +6 -0
  15. package/dist/automation/tools/types.d.ts.map +1 -1
  16. package/dist/{chunk-GJDFCP2T.mjs → chunk-3H5UAJB3.mjs} +258 -155
  17. package/dist/{chunk-MKDONWNO.mjs → chunk-4R65YYAD.mjs} +32 -14
  18. package/dist/{chunk-KWJYMAEF.mjs → chunk-IOTGRLJH.mjs} +255 -152
  19. package/dist/{chunk-6FXOAMNL.mjs → chunk-N6424WKA.mjs} +1 -1
  20. package/dist/{chunk-WZJ25K7P.mjs → chunk-NAWLWKOJ.mjs} +1 -1
  21. package/dist/{chunk-DJ3CDTMX.mjs → chunk-O7SVHLD7.mjs} +23 -5
  22. package/dist/{chunk-CZXM4ZJH.cjs → chunk-Q6NM64J2.cjs} +23 -4
  23. package/dist/{chunk-FFJBOR2Y.mjs → chunk-UYMSFJQZ.mjs} +76 -4
  24. package/dist/{chunk-B4LXDHBX.cjs → chunk-X6VNUBES.cjs} +1419 -1316
  25. package/dist/collab/index.cjs +35 -4
  26. package/dist/collab/index.mjs +35 -4
  27. package/dist/collab/websocket-transport.d.ts +9 -1
  28. package/dist/collab/websocket-transport.d.ts.map +1 -1
  29. package/dist/diagram/index.cjs +8 -4
  30. package/dist/diagram/index.mjs +8 -4
  31. package/dist/docx/data-binding.d.ts +9 -0
  32. package/dist/docx/data-binding.d.ts.map +1 -0
  33. package/dist/docx/document-parts.d.ts +1 -0
  34. package/dist/docx/document-parts.d.ts.map +1 -1
  35. package/dist/docx/drawing.d.ts.map +1 -1
  36. package/dist/docx/embedded.cjs +1391 -613
  37. package/dist/docx/embedded.mjs +1391 -613
  38. package/dist/docx/index.cjs +1402 -622
  39. package/dist/docx/index.mjs +1402 -622
  40. package/dist/docx/inline-model.d.ts +2 -0
  41. package/dist/docx/inline-model.d.ts.map +1 -1
  42. package/dist/docx/layout/adapt-floats.d.ts.map +1 -1
  43. package/dist/docx/layout/adapt-table.d.ts.map +1 -1
  44. package/dist/docx/layout/adapter.d.ts.map +1 -1
  45. package/dist/docx/layout/equation-object.d.ts +1 -1
  46. package/dist/docx/layout/equation-object.d.ts.map +1 -1
  47. package/dist/docx/layout/floats.d.ts +1 -1
  48. package/dist/docx/layout/floats.d.ts.map +1 -1
  49. package/dist/docx/layout/flow-paragraph.d.ts +4 -0
  50. package/dist/docx/layout/flow-paragraph.d.ts.map +1 -1
  51. package/dist/docx/layout/flow-table.d.ts.map +1 -1
  52. package/dist/docx/layout/index.cjs +460 -207
  53. package/dist/docx/layout/index.mjs +460 -207
  54. package/dist/docx/layout/input.d.ts +12 -0
  55. package/dist/docx/layout/input.d.ts.map +1 -1
  56. package/dist/docx/layout/nested-frame-profile.d.ts +3 -1
  57. package/dist/docx/layout/nested-frame-profile.d.ts.map +1 -1
  58. package/dist/docx/layout/page-cursor.d.ts +11 -2
  59. package/dist/docx/layout/page-cursor.d.ts.map +1 -1
  60. package/dist/docx/layout/paragraph-fragments.d.ts.map +1 -1
  61. package/dist/docx/layout/paragraph-layout.d.ts +5 -0
  62. package/dist/docx/layout/paragraph-layout.d.ts.map +1 -1
  63. package/dist/docx/layout/result.d.ts +4 -0
  64. package/dist/docx/layout/result.d.ts.map +1 -1
  65. package/dist/docx/layout/section-flow.d.ts +2 -0
  66. package/dist/docx/layout/section-flow.d.ts.map +1 -1
  67. package/dist/docx/layout/table-layout.d.ts +4 -14
  68. package/dist/docx/layout/table-layout.d.ts.map +1 -1
  69. package/dist/docx/layout/table-merged-rows.d.ts +21 -0
  70. package/dist/docx/layout/table-merged-rows.d.ts.map +1 -0
  71. package/dist/docx/layout/table-row-split.d.ts +16 -0
  72. package/dist/docx/layout/table-row-split.d.ts.map +1 -0
  73. package/dist/docx/layout/wrap.d.ts +2 -0
  74. package/dist/docx/layout/wrap.d.ts.map +1 -1
  75. package/dist/docx/load/index.cjs +1405 -627
  76. package/dist/docx/load/index.mjs +1405 -627
  77. package/dist/docx/model-paragraph.d.ts +4 -1
  78. package/dist/docx/model-paragraph.d.ts.map +1 -1
  79. package/dist/docx/model.d.ts +24 -1
  80. package/dist/docx/model.d.ts.map +1 -1
  81. package/dist/docx/paragraph-properties.d.ts.map +1 -1
  82. package/dist/docx/paragraph-styles.d.ts.map +1 -1
  83. package/dist/docx/parse-table.d.ts.map +1 -1
  84. package/dist/docx/parse.d.ts.map +1 -1
  85. package/dist/docx/run-segmentation.d.ts.map +1 -1
  86. package/dist/docx/save-modified.d.ts +4 -0
  87. package/dist/docx/save-modified.d.ts.map +1 -0
  88. package/dist/docx/save.d.ts +2 -2
  89. package/dist/docx/save.d.ts.map +1 -1
  90. package/dist/docx/style-formatting-package.d.ts +9 -0
  91. package/dist/docx/style-formatting-package.d.ts.map +1 -0
  92. package/dist/docx/style-numbering-package.d.ts +4 -1
  93. package/dist/docx/style-numbering-package.d.ts.map +1 -1
  94. package/dist/docx/table-grid.d.ts +35 -0
  95. package/dist/docx/table-grid.d.ts.map +1 -0
  96. package/dist/docx/table-structure-cells.d.ts +19 -0
  97. package/dist/docx/table-structure-cells.d.ts.map +1 -0
  98. package/dist/docx/table-structure-check.d.ts +12 -0
  99. package/dist/docx/table-structure-check.d.ts.map +1 -0
  100. package/dist/docx/table-structure-merge.d.ts +28 -0
  101. package/dist/docx/table-structure-merge.d.ts.map +1 -0
  102. package/dist/docx/table-structure.d.ts +30 -0
  103. package/dist/docx/table-structure.d.ts.map +1 -0
  104. package/dist/docx/ui/index.cjs +725 -260
  105. package/dist/docx/ui/index.d.ts +4 -0
  106. package/dist/docx/ui/index.d.ts.map +1 -1
  107. package/dist/docx/ui/index.mjs +711 -261
  108. package/dist/docx/ui/ribbon-action-ids.d.ts +1 -1
  109. package/dist/docx/ui/ribbon-action-ids.d.ts.map +1 -1
  110. package/dist/docx/ui/table-structure-guard.d.ts +2 -0
  111. package/dist/docx/ui/table-structure-guard.d.ts.map +1 -1
  112. package/dist/docx/word-content-control-docs.d.ts +5 -0
  113. package/dist/docx/word-content-control-docs.d.ts.map +1 -0
  114. package/dist/docx/word-corpus-gaps.d.ts +10 -0
  115. package/dist/docx/word-corpus-gaps.d.ts.map +1 -0
  116. package/dist/docx/word-measurer.d.ts +6 -0
  117. package/dist/docx/word-measurer.d.ts.map +1 -0
  118. package/dist/docx/word-spacing-docs.d.ts +12 -0
  119. package/dist/docx/word-spacing-docs.d.ts.map +1 -0
  120. package/dist/docx/word-table-docs.d.ts +9 -0
  121. package/dist/docx/word-table-docs.d.ts.map +1 -0
  122. package/dist/docx/write-drawing.d.ts.map +1 -1
  123. package/dist/docx/write-fallback.d.ts +5 -0
  124. package/dist/docx/write-fallback.d.ts.map +1 -0
  125. package/dist/docx/write-table-properties.d.ts +1 -0
  126. package/dist/docx/write-table-properties.d.ts.map +1 -1
  127. package/dist/docx/write-table-structure.d.ts +14 -0
  128. package/dist/docx/write-table-structure.d.ts.map +1 -0
  129. package/dist/docx/write-table.d.ts +3 -4
  130. package/dist/docx/write-table.d.ts.map +1 -1
  131. package/dist/geometry/index.cjs +16 -12
  132. package/dist/geometry/index.mjs +16 -12
  133. package/dist/geometry/preset-shape-definitions-table.d.ts.map +1 -1
  134. package/dist/index.cjs +38 -34
  135. package/dist/index.mjs +38 -34
  136. package/dist/math/index.cjs +22 -22
  137. package/dist/math/index.mjs +22 -22
  138. package/dist/math/omml-box-grouped.d.ts.map +1 -1
  139. package/dist/math/omml-box-layout.d.ts +3 -1
  140. package/dist/math/omml-box-layout.d.ts.map +1 -1
  141. package/dist/math/omml-box-structures.d.ts.map +1 -1
  142. package/dist/math/omml-box.d.ts +2 -0
  143. package/dist/math/omml-box.d.ts.map +1 -1
  144. package/dist/math/omml-svg.d.ts +6 -2
  145. package/dist/math/omml-svg.d.ts.map +1 -1
  146. package/dist/pptx/automation/index.cjs +295 -157
  147. package/dist/pptx/automation/index.d.ts +9 -3
  148. package/dist/pptx/automation/index.d.ts.map +1 -1
  149. package/dist/pptx/automation/index.mjs +6 -5
  150. package/dist/pptx/chunks/{index-PdM5zpmu.d.ts → index-D-FdgqrP.d.ts} +102 -3
  151. package/dist/pptx/chunks/index-D-FdgqrP.d.ts.map +1 -0
  152. package/dist/pptx/chunks/{index-BQDcu_0a.d.ts → index-DKybuHPT.d.ts} +51 -3
  153. package/dist/pptx/chunks/{index-BQDcu_0a.d.ts.map → index-DKybuHPT.d.ts.map} +1 -1
  154. package/dist/pptx/chunks/{index-CBV1oHN7.d.ts → index-DnWlmYCy.d.ts} +2 -2
  155. package/dist/pptx/chunks/{index-CBV1oHN7.d.ts.map → index-DnWlmYCy.d.ts.map} +1 -1
  156. package/dist/pptx/cli/index.cjs +294 -157
  157. package/dist/pptx/cli/index.mjs +4 -4
  158. package/dist/pptx/converter/index.cjs +8 -4
  159. package/dist/pptx/converter/index.d.ts +1 -1
  160. package/dist/pptx/converter/index.mjs +2 -2
  161. package/dist/pptx/editor/render/find-replace.cjs +14 -14
  162. package/dist/pptx/editor/render/find-replace.d.ts +1 -1
  163. package/dist/pptx/editor/render/find-replace.mjs +1 -1
  164. package/dist/pptx/editor/render/slide-operations.cjs +8 -8
  165. package/dist/pptx/editor/render/slide-operations.mjs +2 -2
  166. package/dist/pptx/index.cjs +380 -171
  167. package/dist/pptx/index.d.ts +4 -4
  168. package/dist/pptx/index.mjs +5 -5
  169. package/dist/pptx/node/index.d.ts +1 -1
  170. package/dist/teams/chat-rooms.d.ts.map +1 -1
  171. package/dist/teams/chat-view.d.ts +10 -1
  172. package/dist/teams/chat-view.d.ts.map +1 -1
  173. package/dist/teams/chat.d.ts +7 -0
  174. package/dist/teams/chat.d.ts.map +1 -1
  175. package/dist/teams/files.d.ts +1 -1
  176. package/dist/teams/files.d.ts.map +1 -1
  177. package/dist/teams/index.cjs +3471 -1223
  178. package/dist/teams/index.d.ts +4 -0
  179. package/dist/teams/index.d.ts.map +1 -1
  180. package/dist/teams/index.mjs +3435 -1223
  181. package/dist/teams/message-transfer.d.ts +1 -1
  182. package/dist/teams/message-transfer.d.ts.map +1 -1
  183. package/dist/teams/presence-controller.d.ts +18 -3
  184. package/dist/teams/presence-controller.d.ts.map +1 -1
  185. package/dist/teams/presence-meetings.d.ts +21 -0
  186. package/dist/teams/presence-meetings.d.ts.map +1 -0
  187. package/dist/teams/presence.d.ts +40 -2
  188. package/dist/teams/presence.d.ts.map +1 -1
  189. package/dist/teams/protocol.d.ts +30 -0
  190. package/dist/teams/protocol.d.ts.map +1 -0
  191. package/dist/teams/schema.d.ts +59 -0
  192. package/dist/teams/schema.d.ts.map +1 -0
  193. package/dist/teams/server-config.d.ts +19 -2
  194. package/dist/teams/server-config.d.ts.map +1 -1
  195. package/dist/teams/server-file-storage.d.ts +11 -1
  196. package/dist/teams/server-file-storage.d.ts.map +1 -1
  197. package/dist/teams/server-session.d.ts +2 -0
  198. package/dist/teams/server-session.d.ts.map +1 -1
  199. package/dist/teams/signaling.d.ts +2 -0
  200. package/dist/teams/signaling.d.ts.map +1 -1
  201. package/dist/teams/store.d.ts +14 -0
  202. package/dist/teams/store.d.ts.map +1 -1
  203. package/dist/teams/stored-file.d.ts +1 -1
  204. package/dist/teams/stored-file.d.ts.map +1 -1
  205. package/dist/teams/sync-transport.d.ts.map +1 -1
  206. package/dist/teams/validate-members.d.ts +28 -0
  207. package/dist/teams/validate-members.d.ts.map +1 -0
  208. package/dist/teams/validate-owned.d.ts +20 -0
  209. package/dist/teams/validate-owned.d.ts.map +1 -0
  210. package/dist/teams/validate-update.d.ts +70 -0
  211. package/dist/teams/validate-update.d.ts.map +1 -0
  212. package/dist/teams/view.d.ts +5 -0
  213. package/dist/teams/view.d.ts.map +1 -1
  214. package/dist/teams/workspace.d.ts +17 -2
  215. package/dist/teams/workspace.d.ts.map +1 -1
  216. package/dist/visio/connector-route-walk.d.ts +2 -0
  217. package/dist/visio/connector-route-walk.d.ts.map +1 -1
  218. package/dist/visio/edit-connector-reroute.d.ts.map +1 -1
  219. package/dist/visio/edit-connector.d.ts +2 -0
  220. package/dist/visio/edit-connector.d.ts.map +1 -1
  221. package/dist/visio/edit-delete.d.ts.map +1 -1
  222. package/dist/visio/edit-duplicate-line.d.ts +40 -0
  223. package/dist/visio/edit-duplicate-line.d.ts.map +1 -0
  224. package/dist/visio/edit-duplicate.d.ts.map +1 -1
  225. package/dist/visio/edit-formatting-scope.d.ts +5 -1
  226. package/dist/visio/edit-formatting-scope.d.ts.map +1 -1
  227. package/dist/visio/edit-geometry.d.ts.map +1 -1
  228. package/dist/visio/edit-instance-duplicate.d.ts +2 -1
  229. package/dist/visio/edit-instance-duplicate.d.ts.map +1 -1
  230. package/dist/visio/edit-master-move.d.ts.map +1 -1
  231. package/dist/visio/edit-recalculate-index.d.ts +23 -0
  232. package/dist/visio/edit-recalculate-index.d.ts.map +1 -1
  233. package/dist/visio/edit-recalculate-text.d.ts +12 -0
  234. package/dist/visio/edit-recalculate-text.d.ts.map +1 -0
  235. package/dist/visio/edit-recalculate-values.d.ts.map +1 -1
  236. package/dist/visio/edit-recalculate.d.ts +15 -3
  237. package/dist/visio/edit-recalculate.d.ts.map +1 -1
  238. package/dist/visio/edit-resize-anchor.d.ts.map +1 -1
  239. package/dist/visio/edit-stencil-connector-layout.d.ts +1 -1
  240. package/dist/visio/edit-stencil-connector-layout.d.ts.map +1 -1
  241. package/dist/visio/edit-text-scope.d.ts +4 -1
  242. package/dist/visio/edit-text-scope.d.ts.map +1 -1
  243. package/dist/visio/formula-analyze.d.ts +18 -0
  244. package/dist/visio/formula-analyze.d.ts.map +1 -0
  245. package/dist/visio/formula-bound.d.ts +4 -0
  246. package/dist/visio/formula-bound.d.ts.map +1 -0
  247. package/dist/visio/formula-evaluate.d.ts +2 -9
  248. package/dist/visio/formula-evaluate.d.ts.map +1 -1
  249. package/dist/visio/formula-extra-functions.d.ts +23 -0
  250. package/dist/visio/formula-extra-functions.d.ts.map +1 -0
  251. package/dist/visio/formula-indirect.d.ts +6 -0
  252. package/dist/visio/formula-indirect.d.ts.map +1 -0
  253. package/dist/visio/formula-master.d.ts +1 -0
  254. package/dist/visio/formula-master.d.ts.map +1 -1
  255. package/dist/visio/formula-operators.d.ts +6 -0
  256. package/dist/visio/formula-operators.d.ts.map +1 -0
  257. package/dist/visio/formula-text-functions.d.ts +5 -1
  258. package/dist/visio/formula-text-functions.d.ts.map +1 -1
  259. package/dist/visio/formula.d.ts +12 -0
  260. package/dist/visio/formula.d.ts.map +1 -1
  261. package/dist/visio/index.cjs +1359 -396
  262. package/dist/visio/index.mjs +1359 -396
  263. package/dist/visio/ui/index.cjs +1346 -383
  264. package/dist/visio/ui/index.mjs +1346 -383
  265. package/dist/xlsx/collab/apply.d.ts.map +1 -1
  266. package/dist/xlsx/collab/codec.d.ts +2 -0
  267. package/dist/xlsx/collab/codec.d.ts.map +1 -1
  268. package/dist/xlsx/collab/dirty.d.ts +4 -1
  269. package/dist/xlsx/collab/dirty.d.ts.map +1 -1
  270. package/dist/xlsx/collab/index.cjs +551 -106
  271. package/dist/xlsx/collab/index.mjs +551 -106
  272. package/dist/xlsx/collab/keyed.d.ts +36 -0
  273. package/dist/xlsx/collab/keyed.d.ts.map +1 -0
  274. package/dist/xlsx/collab/names.d.ts +2 -0
  275. package/dist/xlsx/collab/names.d.ts.map +1 -1
  276. package/dist/xlsx/collab/part-specs.d.ts +13 -0
  277. package/dist/xlsx/collab/part-specs.d.ts.map +1 -0
  278. package/dist/xlsx/collab/schema.d.ts +8 -0
  279. package/dist/xlsx/collab/schema.d.ts.map +1 -1
  280. package/dist/xlsx/collab/sheet-parts.d.ts +19 -0
  281. package/dist/xlsx/collab/sheet-parts.d.ts.map +1 -0
  282. package/dist/xlsx/collab/sheets.d.ts +6 -0
  283. package/dist/xlsx/collab/sheets.d.ts.map +1 -1
  284. package/dist/xlsx/collab/write.d.ts +3 -0
  285. package/dist/xlsx/collab/write.d.ts.map +1 -1
  286. package/dist/xlsx/edit/clipboard-areas.d.ts +17 -0
  287. package/dist/xlsx/edit/clipboard-areas.d.ts.map +1 -0
  288. package/dist/xlsx/edit/custom-views.d.ts +21 -0
  289. package/dist/xlsx/edit/custom-views.d.ts.map +1 -0
  290. package/dist/xlsx/edit/data-table.d.ts.map +1 -1
  291. package/dist/xlsx/edit/history.d.ts +1 -1
  292. package/dist/xlsx/edit/history.d.ts.map +1 -1
  293. package/dist/xlsx/edit/index.d.ts +2 -0
  294. package/dist/xlsx/edit/index.d.ts.map +1 -1
  295. package/dist/xlsx/edit/paste-selection.d.ts.map +1 -1
  296. package/dist/xlsx/edit/scenario-merge.d.ts +7 -0
  297. package/dist/xlsx/edit/scenario-merge.d.ts.map +1 -0
  298. package/dist/xlsx/edit/session.d.ts.map +1 -1
  299. package/dist/xlsx/edit/shift-data-tables.d.ts +7 -0
  300. package/dist/xlsx/edit/shift-data-tables.d.ts.map +1 -0
  301. package/dist/xlsx/edit/shift-scenarios.d.ts +7 -0
  302. package/dist/xlsx/edit/shift-scenarios.d.ts.map +1 -0
  303. package/dist/xlsx/edit/shift-sheet.d.ts.map +1 -1
  304. package/dist/xlsx/edit/sparkline-grouping.d.ts +10 -0
  305. package/dist/xlsx/edit/sparkline-grouping.d.ts.map +1 -0
  306. package/dist/xlsx/edit/types.d.ts +21 -0
  307. package/dist/xlsx/edit/types.d.ts.map +1 -1
  308. package/dist/xlsx/formula/ets-drift-compare.d.ts +19 -0
  309. package/dist/xlsx/formula/ets-drift-compare.d.ts.map +1 -0
  310. package/dist/xlsx/formula/ets-excel-compare.d.ts +36 -0
  311. package/dist/xlsx/formula/ets-excel-compare.d.ts.map +1 -0
  312. package/dist/xlsx/formula/ets-init-compare.d.ts +24 -0
  313. package/dist/xlsx/formula/ets-init-compare.d.ts.map +1 -0
  314. package/dist/xlsx/formula/ets-init-maps.d.ts +21 -0
  315. package/dist/xlsx/formula/ets-init-maps.d.ts.map +1 -0
  316. package/dist/xlsx/formula/functions/ets-core.d.ts +36 -0
  317. package/dist/xlsx/formula/functions/ets-core.d.ts.map +1 -0
  318. package/dist/xlsx/formula/functions/ets-grid.d.ts +15 -0
  319. package/dist/xlsx/formula/functions/ets-grid.d.ts.map +1 -0
  320. package/dist/xlsx/formula/functions/ets-init-chain.d.ts +11 -0
  321. package/dist/xlsx/formula/functions/ets-init-chain.d.ts.map +1 -0
  322. package/dist/xlsx/formula/functions/ets-init-four.d.ts +3 -0
  323. package/dist/xlsx/formula/functions/ets-init-four.d.ts.map +1 -0
  324. package/dist/xlsx/formula/functions/ets-init-short.d.ts +17 -0
  325. package/dist/xlsx/formula/functions/ets-init-short.d.ts.map +1 -0
  326. package/dist/xlsx/formula/functions/ets-init-states.d.ts +5 -0
  327. package/dist/xlsx/formula/functions/ets-init-states.d.ts.map +1 -0
  328. package/dist/xlsx/formula/functions/ets-init-three.d.ts +23 -0
  329. package/dist/xlsx/formula/functions/ets-init-three.d.ts.map +1 -0
  330. package/dist/xlsx/formula/functions/ets-init-threeplus.d.ts +13 -0
  331. package/dist/xlsx/formula/functions/ets-init-threeplus.d.ts.map +1 -0
  332. package/dist/xlsx/formula/functions/ets-init.d.ts +33 -0
  333. package/dist/xlsx/formula/functions/ets-init.d.ts.map +1 -0
  334. package/dist/xlsx/formula/functions/ets-input.d.ts +13 -0
  335. package/dist/xlsx/formula/functions/ets-input.d.ts.map +1 -0
  336. package/dist/xlsx/formula/functions/ets-search-map.d.ts +24 -0
  337. package/dist/xlsx/formula/functions/ets-search-map.d.ts.map +1 -0
  338. package/dist/xlsx/formula/functions/ets-search.d.ts +17 -0
  339. package/dist/xlsx/formula/functions/ets-search.d.ts.map +1 -0
  340. package/dist/xlsx/formula/functions/ets-season.d.ts +6 -0
  341. package/dist/xlsx/formula/functions/ets-season.d.ts.map +1 -0
  342. package/dist/xlsx/formula/functions/ets-validate.d.ts +16 -0
  343. package/dist/xlsx/formula/functions/ets-validate.d.ts.map +1 -0
  344. package/dist/xlsx/formula/functions/forecast-ets.d.ts +3 -0
  345. package/dist/xlsx/formula/functions/forecast-ets.d.ts.map +1 -0
  346. package/dist/xlsx/formula/functions/statistical.d.ts.map +1 -1
  347. package/dist/xlsx/index.cjs +5118 -2648
  348. package/dist/xlsx/index.mjs +5097 -2649
  349. package/dist/xlsx/layout/form-control-link.d.ts +20 -0
  350. package/dist/xlsx/layout/form-control-link.d.ts.map +1 -0
  351. package/dist/xlsx/layout/form-control-state.d.ts +49 -0
  352. package/dist/xlsx/layout/form-control-state.d.ts.map +1 -0
  353. package/dist/xlsx/layout/form-control-view.d.ts +11 -0
  354. package/dist/xlsx/layout/form-control-view.d.ts.map +1 -0
  355. package/dist/xlsx/layout/header-footer-edit.d.ts +4 -2
  356. package/dist/xlsx/layout/header-footer-edit.d.ts.map +1 -1
  357. package/dist/xlsx/layout/header-footer.d.ts +16 -0
  358. package/dist/xlsx/layout/header-footer.d.ts.map +1 -1
  359. package/dist/xlsx/layout/index.d.ts +5 -0
  360. package/dist/xlsx/layout/index.d.ts.map +1 -1
  361. package/dist/xlsx/layout/ref-evaluator.d.ts +6 -0
  362. package/dist/xlsx/layout/ref-evaluator.d.ts.map +1 -1
  363. package/dist/xlsx/layout/shape-paint.d.ts +25 -0
  364. package/dist/xlsx/layout/shape-paint.d.ts.map +1 -0
  365. package/dist/xlsx/layout/shape-view.d.ts +15 -0
  366. package/dist/xlsx/layout/shape-view.d.ts.map +1 -0
  367. package/dist/xlsx/load/index.cjs +2667 -1163
  368. package/dist/xlsx/load/index.mjs +2667 -1163
  369. package/dist/xlsx/model-custom-views.d.ts +33 -0
  370. package/dist/xlsx/model-custom-views.d.ts.map +1 -0
  371. package/dist/xlsx/model-shapes.d.ts +78 -0
  372. package/dist/xlsx/model-shapes.d.ts.map +1 -0
  373. package/dist/xlsx/model.d.ts +38 -1
  374. package/dist/xlsx/model.d.ts.map +1 -1
  375. package/dist/xlsx/read/custom-views.d.ts +5 -0
  376. package/dist/xlsx/read/custom-views.d.ts.map +1 -0
  377. package/dist/xlsx/read/drawing.d.ts.map +1 -1
  378. package/dist/xlsx/read/form-control.d.ts +14 -0
  379. package/dist/xlsx/read/form-control.d.ts.map +1 -0
  380. package/dist/xlsx/read/header-footer-images.d.ts +5 -0
  381. package/dist/xlsx/read/header-footer-images.d.ts.map +1 -0
  382. package/dist/xlsx/read/load.d.ts.map +1 -1
  383. package/dist/xlsx/read/shape.d.ts +5 -0
  384. package/dist/xlsx/read/shape.d.ts.map +1 -0
  385. package/dist/xlsx/read/sheet-data.d.ts.map +1 -1
  386. package/dist/xlsx/read/workbook-part.d.ts +5 -1
  387. package/dist/xlsx/read/workbook-part.d.ts.map +1 -1
  388. package/dist/xlsx/read/worksheet-children.d.ts +3 -0
  389. package/dist/xlsx/read/worksheet-children.d.ts.map +1 -0
  390. package/dist/xlsx/read/worksheet.d.ts.map +1 -1
  391. package/dist/xlsx/ui/commands/i18n/sparklines.d.ts.map +1 -1
  392. package/dist/xlsx/ui/commands/i18n/what-if.d.ts.map +1 -1
  393. package/dist/xlsx/ui/commands/what-if.d.ts +0 -1
  394. package/dist/xlsx/ui/commands/what-if.d.ts.map +1 -1
  395. package/dist/xlsx/ui/dialogs/forecast-sheet.d.ts +51 -0
  396. package/dist/xlsx/ui/dialogs/forecast-sheet.d.ts.map +1 -0
  397. package/dist/xlsx/ui/dialogs/scenario-summary.d.ts +15 -0
  398. package/dist/xlsx/ui/dialogs/scenario-summary.d.ts.map +1 -0
  399. package/dist/xlsx/ui/index.cjs +5088 -2399
  400. package/dist/xlsx/ui/index.d.ts +2 -0
  401. package/dist/xlsx/ui/index.d.ts.map +1 -1
  402. package/dist/xlsx/ui/index.mjs +5081 -2398
  403. package/dist/xlsx/ui/locales/de/grid.d.ts.map +1 -1
  404. package/dist/xlsx/ui/locales/en/grid.d.ts.map +1 -1
  405. package/dist/xlsx/ui/locales/es/grid.d.ts.map +1 -1
  406. package/dist/xlsx/ui/locales/fr/grid.d.ts.map +1 -1
  407. package/dist/xlsx/ui/locales/zh-CN/grid.d.ts.map +1 -1
  408. package/dist/xlsx/write/custom-views.d.ts +4 -0
  409. package/dist/xlsx/write/custom-views.d.ts.map +1 -0
  410. package/dist/xlsx/write/drawing.d.ts.map +1 -1
  411. package/dist/xlsx/write/form-control.d.ts +4 -0
  412. package/dist/xlsx/write/form-control.d.ts.map +1 -0
  413. package/dist/xlsx/write/sheet-data.d.ts.map +1 -1
  414. package/dist/xlsx/write/workbook-part.d.ts.map +1 -1
  415. package/dist/xlsx/write/worksheet.d.ts.map +1 -1
  416. package/package.json +1 -1
  417. package/dist/PptxHandler-E4DDV3FQ.mjs +0 -4
  418. package/dist/pptx/chunks/index-PdM5zpmu.d.ts.map +0 -1
@@ -180,7 +180,7 @@ function normalizePath(path3, rootName) {
180
180
  }
181
181
  function child(entries, parentId, name) {
182
182
  const children3 = entries.filter((entry2) => entry2.parentId === parentId && entry2.path !== void 0);
183
- const pick2 = (matches) => matches.length === 1 ? matches[0] : void 0;
183
+ const pick2 = (matches2) => matches2.length === 1 ? matches2[0] : void 0;
184
184
  const exact = children3.filter((entry2) => entry2.name === name);
185
185
  if (exact.length)
186
186
  return pick2(exact);
@@ -3192,6 +3192,8 @@ async function encryptStandard(packageData, password, options = {}) {
3192
3192
  var NS = {
3193
3193
  /** WordprocessingML main. */
3194
3194
  w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
3195
+ /** PresentationML main. */
3196
+ p: "http://schemas.openxmlformats.org/presentationml/2006/main",
3195
3197
  /** SpreadsheetML main. */
3196
3198
  x: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
3197
3199
  /** DrawingML main. */
@@ -3206,6 +3208,12 @@ var NS = {
3206
3208
  dgm: "http://schemas.openxmlformats.org/drawingml/2006/diagram",
3207
3209
  /** Office 2007+ diagram drawing (`dsp`). */
3208
3210
  dsp: "http://schemas.microsoft.com/office/drawing/2008/diagram",
3211
+ /** DrawingML Word drawing (`wp:inline`, `wp:anchor`). */
3212
+ wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
3213
+ /** DrawingML picture. */
3214
+ pic: "http://schemas.openxmlformats.org/drawingml/2006/picture",
3215
+ /** Word 2010 shapes (`wps`). */
3216
+ wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
3209
3217
  /** Relationships (`r:id`, `r:embed`). */
3210
3218
  r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
3211
3219
  /** Markup compatibility (`mc:AlternateContent`). */
@@ -3213,7 +3221,42 @@ var NS = {
3213
3221
  /** OPC relationships part. */
3214
3222
  rels: "http://schemas.openxmlformats.org/package/2006/relationships",
3215
3223
  /** OPC content types part. */
3216
- contentTypes: "http://schemas.openxmlformats.org/package/2006/content-types"};
3224
+ contentTypes: "http://schemas.openxmlformats.org/package/2006/content-types",
3225
+ /** Office Math. */
3226
+ m: "http://schemas.openxmlformats.org/officeDocument/2006/math",
3227
+ /** Core properties. */
3228
+ cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
3229
+ /** Dublin Core elements. */
3230
+ dc: "http://purl.org/dc/elements/1.1/",
3231
+ /** Legacy VML. */
3232
+ v: "urn:schemas-microsoft-com:vml",
3233
+ /** Office VML extensions. */
3234
+ o: "urn:schemas-microsoft-com:office:office",
3235
+ /** Word VML extensions. */
3236
+ w10: "urn:schemas-microsoft-com:office:word",
3237
+ /** SpreadsheetML drawing (`xdr:wsDr`, cell anchors). */
3238
+ xdr: "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
3239
+ /** SpreadsheetML 2009 extensions (`x14:conditionalFormatting`, `x14:dataBar`). */
3240
+ x14: "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",
3241
+ /** SpreadsheetML 2009 attribute extensions (`x14ac:dyDescent`). */
3242
+ x14ac: "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac",
3243
+ /** SpreadsheetML revision ids (`xr:uid`). */
3244
+ xr: "http://schemas.microsoft.com/office/spreadsheetml/2014/revision",
3245
+ /** Excel threaded comments and persons. */
3246
+ tc: "http://schemas.microsoft.com/office/spreadsheetml/2018/threadedcomments",
3247
+ /** Legacy VML Excel client data (`x:ClientData`). */
3248
+ xv: "urn:schemas-microsoft-com:office:excel",
3249
+ /** Extended (app) properties. */
3250
+ extendedProperties: "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties",
3251
+ /** Dublin Core terms (`dcterms:created`). */
3252
+ dcterms: "http://purl.org/dc/terms/",
3253
+ /** Custom document properties (`docProps/custom.xml`). */
3254
+ customProperties: "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties",
3255
+ /** Document property variant types (`vt:lpwstr`, `vt:vector`). */
3256
+ vt: "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes",
3257
+ /** XML itself (`xml:space`). */
3258
+ xml: "http://www.w3.org/XML/1998/namespace"
3259
+ };
3217
3260
 
3218
3261
  // xml/xml.ts
3219
3262
  var DEFAULT_XML_LIMITS = {
@@ -3397,12 +3440,12 @@ function childrenNamed(parent, localName2) {
3397
3440
  return found;
3398
3441
  }
3399
3442
  function singleChild(parent, localName2, mustExist) {
3400
- const matches = childrenNamed(parent, localName2);
3401
- if (matches.length > 1) throw new Error(`The EncryptionInfo has several ${localName2} elements.`);
3402
- if (matches.length === 0 && mustExist) {
3443
+ const matches2 = childrenNamed(parent, localName2);
3444
+ if (matches2.length > 1) throw new Error(`The EncryptionInfo has several ${localName2} elements.`);
3445
+ if (matches2.length === 0 && mustExist) {
3403
3446
  throw new Error(`The EncryptionInfo has no ${localName2} element.`);
3404
3447
  }
3405
- return matches[0];
3448
+ return matches2[0];
3406
3449
  }
3407
3450
  function required(element4, attr3) {
3408
3451
  const value = element4.getAttribute(attr3);
@@ -3878,6 +3921,233 @@ async function openZip(input, limits = {}) {
3878
3921
  return guardZip(await JSZip.loadAsync(bytes), limits);
3879
3922
  }
3880
3923
 
3924
+ // opc/properties/patch.ts
3925
+ var XMLNS = "http://www.w3.org/2000/xmlns/";
3926
+ function tagEnd(xml, from) {
3927
+ let quote = "";
3928
+ for (let i2 = from + 1; i2 < xml.length; i2++) {
3929
+ const ch = xml[i2];
3930
+ if (quote) {
3931
+ if (ch === quote) quote = "";
3932
+ } else if (ch === '"' || ch === "'") quote = ch;
3933
+ else if (ch === ">") return i2 + 1;
3934
+ }
3935
+ throw new Error("Unterminated tag in property part");
3936
+ }
3937
+ function skipMarkup(xml, at) {
3938
+ if (xml.startsWith("<!--", at)) return xml.indexOf("-->", at) + 3;
3939
+ if (xml.startsWith("<![CDATA[", at)) return xml.indexOf("]]>", at) + 3;
3940
+ if (xml.startsWith("<?", at)) return xml.indexOf("?>", at) + 2;
3941
+ return void 0;
3942
+ }
3943
+ function scan(xml) {
3944
+ let i2 = 0;
3945
+ let rootStart = -1;
3946
+ while (rootStart < 0) {
3947
+ const lt = xml.indexOf("<", i2);
3948
+ if (lt < 0) throw new Error("Property part has no root element");
3949
+ const skipped = skipMarkup(xml, lt);
3950
+ if (skipped !== void 0) i2 = skipped;
3951
+ else rootStart = lt;
3952
+ }
3953
+ const openEnd = tagEnd(xml, rootStart);
3954
+ if (xml[openEnd - 2] === "/") {
3955
+ const root = {
3956
+ start: rootStart,
3957
+ openEnd,
3958
+ closeStart: openEnd,
3959
+ end: openEnd,
3960
+ selfClosing: true
3961
+ };
3962
+ return { root, children: [] };
3963
+ }
3964
+ const children3 = [];
3965
+ let depth = 0;
3966
+ let child8;
3967
+ i2 = openEnd;
3968
+ for (; ; ) {
3969
+ const lt = xml.indexOf("<", i2);
3970
+ if (lt < 0) throw new Error("Property part root is not closed");
3971
+ const skipped = skipMarkup(xml, lt);
3972
+ if (skipped !== void 0) {
3973
+ i2 = skipped;
3974
+ continue;
3975
+ }
3976
+ const end = tagEnd(xml, lt);
3977
+ i2 = end;
3978
+ if (xml[lt + 1] === "/") {
3979
+ if (depth === 0) {
3980
+ const root = { start: rootStart, openEnd, closeStart: lt, end, selfClosing: false };
3981
+ return { root, children: children3 };
3982
+ }
3983
+ depth--;
3984
+ if (depth === 0 && child8)
3985
+ children3.push({ ...child8, closeStart: lt, end, selfClosing: false });
3986
+ } else if (xml[end - 2] === "/") {
3987
+ if (depth === 0)
3988
+ children3.push({ start: lt, openEnd: end, closeStart: end, end, selfClosing: true });
3989
+ } else {
3990
+ if (depth === 0) child8 = { start: lt, openEnd: end };
3991
+ depth++;
3992
+ }
3993
+ }
3994
+ }
3995
+ var escapeText = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\r/g, "&#xD;");
3996
+ var qualifiedName = (xml, span) => /^<([^\s/>]+)/.exec(xml.slice(span.start, span.openEnd))?.[1] ?? "";
3997
+ var PartPatch = class {
3998
+ constructor(xml, rootElement) {
3999
+ this.xml = xml;
4000
+ const { root, children: children3 } = scan(xml);
4001
+ const kids = elements(rootElement);
4002
+ if (kids.length !== children3.length) throw new Error("Property part markup is not supported");
4003
+ kids.forEach((kid, index) => this.spans.set(kid, children3[index]));
4004
+ this.root = root;
4005
+ for (const attribute2 of Array.from(rootElement.attributes)) {
4006
+ if (attribute2.name === "xmlns") this.defaultNs = attribute2.value;
4007
+ else if (attribute2.namespaceURI === XMLNS || attribute2.name.startsWith("xmlns:"))
4008
+ this.prefixes.set(attribute2.value, attribute2.localName);
4009
+ }
4010
+ }
4011
+ xml;
4012
+ root;
4013
+ spans = /* @__PURE__ */ new Map();
4014
+ edits = [];
4015
+ appended = [];
4016
+ prefixes = /* @__PURE__ */ new Map();
4017
+ defaultNs = null;
4018
+ seq = 0;
4019
+ add(start, end, text) {
4020
+ this.edits.push({ start, end, text, seq: this.seq++ });
4021
+ }
4022
+ span(element4) {
4023
+ const span = this.spans.get(element4);
4024
+ if (!span) throw new Error("Element is not a child of the patched root");
4025
+ return span;
4026
+ }
4027
+ /** The prefix bound to `ns` on the root, declaring `preferred` for it when none is. */
4028
+ prefix(ns, preferred) {
4029
+ const known = this.prefixes.get(ns);
4030
+ if (known !== void 0) return known;
4031
+ const taken = new Set(this.prefixes.values());
4032
+ let prefix2 = preferred;
4033
+ for (let n = 1; taken.has(prefix2); n++) prefix2 = `${preferred}${n}`;
4034
+ this.prefixes.set(ns, prefix2);
4035
+ const at = this.root.openEnd - (this.root.selfClosing ? 2 : 1);
4036
+ this.add(at, at, ` xmlns:${prefix2}="${ns}"`);
4037
+ return prefix2;
4038
+ }
4039
+ /** `local` qualified for an element in `ns`: unprefixed in the default namespace. */
4040
+ qualify(ns, local, preferred) {
4041
+ return this.defaultNs === ns && !this.prefixes.has(ns) ? local : `${this.prefix(ns, preferred)}:${local}`;
4042
+ }
4043
+ /** Replaces the element's content, keeping its start tag (and attributes) as written. */
4044
+ setContent(element4, content) {
4045
+ const span = this.span(element4);
4046
+ if (span.selfClosing)
4047
+ this.add(span.openEnd - 2, span.openEnd, `>${content}</${qualifiedName(this.xml, span)}>`);
4048
+ else this.add(span.openEnd, span.closeStart, content);
4049
+ }
4050
+ /** Adds ` name="value"` text to the element's start tag. */
4051
+ addAttribute(element4, attribute2) {
4052
+ const span = this.span(element4);
4053
+ const at = span.openEnd - (span.selfClosing ? 2 : 1);
4054
+ this.add(at, at, attribute2);
4055
+ }
4056
+ remove(element4) {
4057
+ const span = this.span(element4);
4058
+ this.add(span.start, span.end, "");
4059
+ }
4060
+ /** Inserts `markup` before `before`, or as the root's last child. */
4061
+ insert(markup, before) {
4062
+ if (before) {
4063
+ const at = this.span(before).start;
4064
+ this.add(at, at, markup);
4065
+ } else this.appended.push(markup);
4066
+ }
4067
+ toString() {
4068
+ const edits = [...this.edits];
4069
+ if (this.appended.length) {
4070
+ const text = this.appended.join("");
4071
+ const root = this.root;
4072
+ if (root.selfClosing) {
4073
+ const name = qualifiedName(this.xml, root);
4074
+ edits.push({
4075
+ start: root.end - 2,
4076
+ end: root.end,
4077
+ text: `>${text}</${name}>`,
4078
+ seq: this.seq
4079
+ });
4080
+ } else edits.push({ start: root.closeStart, end: root.closeStart, text, seq: this.seq });
4081
+ }
4082
+ edits.sort((a2, b) => a2.start - b.start || a2.end - a2.start - (b.end - b.start) || a2.seq - b.seq);
4083
+ let out = "";
4084
+ let at = 0;
4085
+ for (const edit of edits) {
4086
+ out += this.xml.slice(at, edit.start) + edit.text;
4087
+ at = Math.max(at, edit.end);
4088
+ }
4089
+ return out + this.xml.slice(at);
4090
+ }
4091
+ };
4092
+
4093
+ // opc/properties/core.ts
4094
+ var XSI = "http://www.w3.org/2001/XMLSchema-instance";
4095
+ var FIELDS = [
4096
+ ["title", "dc", false],
4097
+ ["subject", "dc", false],
4098
+ ["creator", "dc", false],
4099
+ ["keywords", "cp", false],
4100
+ ["description", "dc", false],
4101
+ ["lastModifiedBy", "cp", false],
4102
+ ["created", "dcterms", true],
4103
+ ["modified", "dcterms", true],
4104
+ ["category", "cp", false],
4105
+ ["contentStatus", "cp", false],
4106
+ ["revision", "cp", false],
4107
+ ["language", "dc", false],
4108
+ ["identifier", "dc", false],
4109
+ ["lastPrinted", "cp", false],
4110
+ ["version", "cp", false]
4111
+ ];
4112
+ FIELDS.map(([field]) => field);
4113
+ var EMPTY_CORE = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
4114
+ <cp:coreProperties xmlns:cp="${NS.cp}" xmlns:dc="${NS.dc}" xmlns:dcterms="${NS.dcterms}" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="${XSI}"/>`;
4115
+ function parseCoreProperties(xml) {
4116
+ const out = {};
4117
+ if (!xml) return out;
4118
+ const root = parseXml(xml, { label: "core properties" }).documentElement;
4119
+ for (const [field, prefix2] of FIELDS) {
4120
+ const text = first(root, field, NS[prefix2])?.textContent ?? "";
4121
+ if (text !== "") out[field] = text;
4122
+ }
4123
+ return out;
4124
+ }
4125
+ var formatW3cdtf = (date) => date.toISOString().replace(/\.\d{3}Z$/, "Z");
4126
+ function writeCoreProperties(props, sourceXml) {
4127
+ const xml = sourceXml ?? EMPTY_CORE;
4128
+ const root = parseXml(xml, { label: "core properties" }).documentElement;
4129
+ const patch = new PartPatch(xml, root);
4130
+ for (const [field, prefix2, isDate] of FIELDS) {
4131
+ const ns = NS[prefix2];
4132
+ const value = props[field];
4133
+ const element4 = first(root, field, ns);
4134
+ if (value === void 0 || value === "") {
4135
+ if (element4 && (element4.textContent ?? "") !== "") patch.remove(element4);
4136
+ continue;
4137
+ }
4138
+ if (element4 && element4.textContent === value) continue;
4139
+ const typed = () => ` ${patch.prefix(XSI, "xsi")}:type="${patch.prefix(NS.dcterms, "dcterms")}:W3CDTF"`;
4140
+ if (element4) {
4141
+ if (isDate && !element4.getAttributeNS(XSI, "type")) patch.addAttribute(element4, typed());
4142
+ patch.setContent(element4, escapeText(value));
4143
+ continue;
4144
+ }
4145
+ const name = patch.qualify(ns, field, prefix2);
4146
+ patch.insert(`<${name}${isDate ? typed() : ""}>${escapeText(value)}</${name}>`);
4147
+ }
4148
+ return patch.toString();
4149
+ }
4150
+
3881
4151
  // docx/zip-parts.ts
3882
4152
  var DOCUMENT_RELS_PATH = "word/_rels/document.xml.rels";
3883
4153
  var ensureDocumentRelationship = (zip, type, target) => ensureRelationship(zip, DOCUMENT_RELS_PATH, type, target);
@@ -3893,13 +4163,13 @@ var first2 = (parent, local) => first(parent, local, WORD_NS);
3893
4163
  var getW = (element4, local) => attr(element4, local, WORD_NS, "w");
3894
4164
  var getR = (element4, local) => relAttr(element4, local);
3895
4165
  var makeW = (doc, local) => doc.createElementNS(WORD_NS, `w:${local}`);
3896
- var XMLNS = "http://www.w3.org/2000/xmlns/";
4166
+ var XMLNS2 = "http://www.w3.org/2000/xmlns/";
3897
4167
  function importElement(doc, element4) {
3898
4168
  const imported = doc.importNode(element4, true);
3899
4169
  const root = doc.documentElement;
3900
4170
  const drop = (node) => {
3901
4171
  for (const attribute2 of Array.from(node.attributes))
3902
- if (attribute2.namespaceURI === XMLNS && root?.lookupNamespaceURI(attribute2.prefix ? attribute2.localName : null) === attribute2.value)
4172
+ if (attribute2.namespaceURI === XMLNS2 && root?.lookupNamespaceURI(attribute2.prefix ? attribute2.localName : null) === attribute2.value)
3903
4173
  node.removeAttributeNode(attribute2);
3904
4174
  for (const child8 of Array.from(node.childNodes)) if (isElement(child8)) drop(child8);
3905
4175
  };
@@ -3930,7 +4200,7 @@ var PREFIX = {
3930
4200
  };
3931
4201
  var CORE_TYPE = "application/vnd.openxmlformats-package.core-properties+xml";
3932
4202
  var CORE_REL = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
3933
- function parseCoreProperties(xml) {
4203
+ function parseCoreProperties2(xml) {
3934
4204
  const root = parseXml2(xml).documentElement;
3935
4205
  const result = {};
3936
4206
  for (const field of PROPERTY_FIELDS) {
@@ -3998,6 +4268,146 @@ function dropAddedFolders(zip, source2) {
3998
4268
  if (entry2.dir && !source2.has(name)) delete zip.files[name];
3999
4269
  }
4000
4270
 
4271
+ // docx/save-modified.ts
4272
+ var CORE_PATH2 = "docProps/core.xml";
4273
+ async function stampModified(zip, option) {
4274
+ if (!option) return;
4275
+ const file = zip.file(CORE_PATH2);
4276
+ if (!file) return;
4277
+ const source2 = await file.async("string");
4278
+ const props = parseCoreProperties(source2);
4279
+ props.modified = formatW3cdtf(option.at ?? /* @__PURE__ */ new Date());
4280
+ if (option.author) props.lastModifiedBy = option.author;
4281
+ zip.file(CORE_PATH2, writeCoreProperties(props, source2));
4282
+ }
4283
+
4284
+ // docx/generated/wml-simple-types.ts
4285
+ var ST_HighlightColor = ["black", "blue", "cyan", "green", "magenta", "red", "yellow", "white", "darkBlue", "darkCyan", "darkGreen", "darkMagenta", "darkRed", "darkYellow", "darkGray", "lightGray", "none"];
4286
+ function isStHighlightColor(value) {
4287
+ return typeof value === "string" && ST_HighlightColor.includes(value);
4288
+ }
4289
+ var ST_Underline = ["single", "words", "double", "thick", "dotted", "dottedHeavy", "dash", "dashedHeavy", "dashLong", "dashLongHeavy", "dotDash", "dashDotHeavy", "dotDotDash", "dashDotDotHeavy", "wave", "wavyHeavy", "wavyDouble", "none"];
4290
+ function isStUnderline(value) {
4291
+ return typeof value === "string" && ST_Underline.includes(value);
4292
+ }
4293
+ var ST_Border = ["nil", "none", "single", "thick", "double", "dotted", "dashed", "dotDash", "dotDotDash", "triple", "thinThickSmallGap", "thickThinSmallGap", "thinThickThinSmallGap", "thinThickMediumGap", "thickThinMediumGap", "thinThickThinMediumGap", "thinThickLargeGap", "thickThinLargeGap", "thinThickThinLargeGap", "wave", "doubleWave", "dashSmallGap", "dashDotStroked", "threeDEmboss", "threeDEngrave", "outset", "inset", "apples", "archedScallops", "babyPacifier", "babyRattle", "balloons3Colors", "balloonsHotAir", "basicBlackDashes", "basicBlackDots", "basicBlackSquares", "basicThinLines", "basicWhiteDashes", "basicWhiteDots", "basicWhiteSquares", "basicWideInline", "basicWideMidline", "basicWideOutline", "bats", "birds", "birdsFlight", "cabins", "cakeSlice", "candyCorn", "celticKnotwork", "certificateBanner", "chainLink", "champagneBottle", "checkedBarBlack", "checkedBarColor", "checkered", "christmasTree", "circlesLines", "circlesRectangles", "classicalWave", "clocks", "compass", "confetti", "confettiGrays", "confettiOutline", "confettiStreamers", "confettiWhite", "cornerTriangles", "couponCutoutDashes", "couponCutoutDots", "crazyMaze", "creaturesButterfly", "creaturesFish", "creaturesInsects", "creaturesLadyBug", "crossStitch", "cup", "decoArch", "decoArchColor", "decoBlocks", "diamondsGray", "doubleD", "doubleDiamonds", "earth1", "earth2", "earth3", "eclipsingSquares1", "eclipsingSquares2", "eggsBlack", "fans", "film", "firecrackers", "flowersBlockPrint", "flowersDaisies", "flowersModern1", "flowersModern2", "flowersPansy", "flowersRedRose", "flowersRoses", "flowersTeacup", "flowersTiny", "gems", "gingerbreadMan", "gradient", "handmade1", "handmade2", "heartBalloon", "heartGray", "hearts", "heebieJeebies", "holly", "houseFunky", "hypnotic", "iceCreamCones", "lightBulb", "lightning1", "lightning2", "mapPins", "mapleLeaf", "mapleMuffins", "marquee", "marqueeToothed", "moons", "mosaic", "musicNotes", "northwest", "ovals", "packages", "palmsBlack", "palmsColor", "paperClips", "papyrus", "partyFavor", "partyGlass", "pencils", "people", "peopleWaving", "peopleHats", "poinsettias", "postageStamp", "pumpkin1", "pushPinNote2", "pushPinNote1", "pyramids", "pyramidsAbove", "quadrants", "rings", "safari", "sawtooth", "sawtoothGray", "scaredCat", "seattle", "shadowedSquares", "sharksTeeth", "shorebirdTracks", "skyrocket", "snowflakeFancy", "snowflakes", "sombrero", "southwest", "stars", "starsTop", "stars3d", "starsBlack", "starsShadowed", "sun", "swirligig", "tornPaper", "tornPaperBlack", "trees", "triangleParty", "triangles", "triangle1", "triangle2", "triangleCircle1", "triangleCircle2", "shapes1", "shapes2", "twistedLines1", "twistedLines2", "vine", "waveline", "weavingAngles", "weavingBraid", "weavingRibbon", "weavingStrips", "whiteFlowers", "woodwork", "xIllusions", "zanyTriangles", "zigZag", "zigZagStitch", "custom"];
4294
+ function isStBorder(value) {
4295
+ return typeof value === "string" && ST_Border.includes(value);
4296
+ }
4297
+ var ST_TabJc = ["clear", "start", "center", "end", "decimal", "bar", "num", "left", "right"];
4298
+ function isStTabJc(value) {
4299
+ return typeof value === "string" && ST_TabJc.includes(value);
4300
+ }
4301
+ var ST_TabTlc = ["none", "dot", "hyphen", "underscore", "heavy", "middleDot"];
4302
+ function isStTabTlc(value) {
4303
+ return typeof value === "string" && ST_TabTlc.includes(value);
4304
+ }
4305
+ var ST_LineSpacingRule = ["auto", "exact", "atLeast"];
4306
+ function isStLineSpacingRule(value) {
4307
+ return typeof value === "string" && ST_LineSpacingRule.includes(value);
4308
+ }
4309
+ var ST_Jc = ["start", "center", "end", "both", "mediumKashida", "distribute", "numTab", "highKashida", "lowKashida", "thaiDistribute", "left", "right"];
4310
+ function isStJc(value) {
4311
+ return typeof value === "string" && ST_Jc.includes(value);
4312
+ }
4313
+ var ST_JcTable = ["center", "end", "left", "right", "start"];
4314
+ function isStJcTable(value) {
4315
+ return typeof value === "string" && ST_JcTable.includes(value);
4316
+ }
4317
+ var ST_DocProtect = ["none", "readOnly", "comments", "trackedChanges", "forms"];
4318
+ function isStDocProtect(value) {
4319
+ return typeof value === "string" && ST_DocProtect.includes(value);
4320
+ }
4321
+ var ST_FldCharType = ["begin", "separate", "end"];
4322
+ function isStFldCharType(value) {
4323
+ return typeof value === "string" && ST_FldCharType.includes(value);
4324
+ }
4325
+ var ST_InfoTextType = ["text", "autoText"];
4326
+ function isStInfoTextType(value) {
4327
+ return typeof value === "string" && ST_InfoTextType.includes(value);
4328
+ }
4329
+ var ST_FFTextType = ["regular", "number", "date", "currentTime", "currentDate", "calculated"];
4330
+ function isStFFTextType(value) {
4331
+ return typeof value === "string" && ST_FFTextType.includes(value);
4332
+ }
4333
+ var ST_SectionMark = ["nextPage", "nextColumn", "continuous", "evenPage", "oddPage"];
4334
+ function isStSectionMark(value) {
4335
+ return typeof value === "string" && ST_SectionMark.includes(value);
4336
+ }
4337
+ var ST_NumberFormat = ["decimal", "upperRoman", "lowerRoman", "upperLetter", "lowerLetter", "ordinal", "cardinalText", "ordinalText", "hex", "chicago", "ideographDigital", "japaneseCounting", "aiueo", "iroha", "decimalFullWidth", "decimalHalfWidth", "japaneseLegal", "japaneseDigitalTenThousand", "decimalEnclosedCircle", "decimalFullWidth2", "aiueoFullWidth", "irohaFullWidth", "decimalZero", "bullet", "ganada", "chosung", "decimalEnclosedFullstop", "decimalEnclosedParen", "decimalEnclosedCircleChinese", "ideographEnclosedCircle", "ideographTraditional", "ideographZodiac", "ideographZodiacTraditional", "taiwaneseCounting", "ideographLegalTraditional", "taiwaneseCountingThousand", "taiwaneseDigital", "chineseCounting", "chineseLegalSimplified", "chineseCountingThousand", "koreanDigital", "koreanCounting", "koreanLegal", "koreanDigital2", "vietnameseCounting", "russianLower", "russianUpper", "none", "numberInDash", "hebrew1", "hebrew2", "arabicAlpha", "arabicAbjad", "hindiVowels", "hindiConsonants", "hindiNumbers", "hindiCounting", "thaiLetters", "thaiNumbers", "thaiCounting", "bahtText", "dollarText", "custom"];
4338
+ function isStNumberFormat(value) {
4339
+ return typeof value === "string" && ST_NumberFormat.includes(value);
4340
+ }
4341
+ var ST_PageOrientation = ["portrait", "landscape"];
4342
+ function isStPageOrientation(value) {
4343
+ return typeof value === "string" && ST_PageOrientation.includes(value);
4344
+ }
4345
+ var ST_VerticalJc = ["top", "center", "both", "bottom"];
4346
+ function isStVerticalJc(value) {
4347
+ return typeof value === "string" && ST_VerticalJc.includes(value);
4348
+ }
4349
+ var ST_BrType = ["page", "column", "textWrapping"];
4350
+ function isStBrType(value) {
4351
+ return typeof value === "string" && ST_BrType.includes(value);
4352
+ }
4353
+ var ST_PTabAlignment = ["left", "center", "right"];
4354
+ function isStPTabAlignment(value) {
4355
+ return typeof value === "string" && ST_PTabAlignment.includes(value);
4356
+ }
4357
+ var ST_PTabRelativeTo = ["margin", "indent"];
4358
+ function isStPTabRelativeTo(value) {
4359
+ return typeof value === "string" && ST_PTabRelativeTo.includes(value);
4360
+ }
4361
+ var ST_PTabLeader = ["none", "dot", "hyphen", "underscore", "middleDot"];
4362
+ function isStPTabLeader(value) {
4363
+ return typeof value === "string" && ST_PTabLeader.includes(value);
4364
+ }
4365
+ var ST_Merge = ["continue", "restart"];
4366
+ function isStMerge(value) {
4367
+ return typeof value === "string" && ST_Merge.includes(value);
4368
+ }
4369
+ var ST_WmlColorSchemeIndex = ["dark1", "light1", "dark2", "light2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hyperlink", "followedHyperlink"];
4370
+ function isStWmlColorSchemeIndex(value) {
4371
+ return typeof value === "string" && ST_WmlColorSchemeIndex.includes(value);
4372
+ }
4373
+ var ST_ThemeColor = ["dark1", "light1", "dark2", "light2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hyperlink", "followedHyperlink", "none", "background1", "text1", "background2", "text2"];
4374
+ function isStThemeColor(value) {
4375
+ return typeof value === "string" && ST_ThemeColor.includes(value);
4376
+ }
4377
+ var ST_VerticalAlignRun = ["baseline", "superscript", "subscript"];
4378
+ function isStVerticalAlignRun(value) {
4379
+ return typeof value === "string" && ST_VerticalAlignRun.includes(value);
4380
+ }
4381
+ var ST_RelFromH = ["margin", "page", "column", "character", "leftMargin", "rightMargin", "insideMargin", "outsideMargin"];
4382
+ function isStRelFromH(value) {
4383
+ return typeof value === "string" && ST_RelFromH.includes(value);
4384
+ }
4385
+ var ST_RelFromV = ["margin", "page", "paragraph", "line", "topMargin", "bottomMargin", "insideMargin", "outsideMargin"];
4386
+ function isStRelFromV(value) {
4387
+ return typeof value === "string" && ST_RelFromV.includes(value);
4388
+ }
4389
+
4390
+ // docx/parse-diagnostics.ts
4391
+ var sink;
4392
+ function withParseWarnings(warnings, fn) {
4393
+ const previous = sink;
4394
+ sink = warnings;
4395
+ try {
4396
+ return fn();
4397
+ } finally {
4398
+ sink = previous;
4399
+ }
4400
+ }
4401
+ function reportParseWarning(message) {
4402
+ if (sink && !sink.includes(message)) sink.push(message);
4403
+ }
4404
+ function enumValue(guard, raw2, label) {
4405
+ if (raw2 === null || raw2 === void 0 || raw2 === "") return void 0;
4406
+ if (guard(raw2)) return raw2;
4407
+ reportParseWarning(`Ignored invalid ${label} value \u201C${raw2}\u201D; it is not allowed by the schema.`);
4408
+ return void 0;
4409
+ }
4410
+
4001
4411
  // units/units.ts
4002
4412
  function integer(unit, value, allowNegative = true) {
4003
4413
  if (!Number.isSafeInteger(value)) throw new RangeError(`${unit} must be a safe integer`);
@@ -4103,6 +4513,582 @@ function parseTintShade(value) {
4103
4513
  return value && /^[0-9a-fA-F]{2}$/.test(value) ? Number.parseInt(value, 16) / 255 : void 0;
4104
4514
  }
4105
4515
 
4516
+ // docx/paragraph-alignment.ts
4517
+ function alignFromJustification(jc, rtl) {
4518
+ switch (jc) {
4519
+ case "left":
4520
+ case "center":
4521
+ case "right":
4522
+ return jc;
4523
+ case "start":
4524
+ return rtl ? "right" : "left";
4525
+ case "end":
4526
+ return rtl ? "left" : "right";
4527
+ case "both":
4528
+ case "distribute":
4529
+ case "thaiDistribute":
4530
+ case "mediumKashida":
4531
+ case "highKashida":
4532
+ case "lowKashida":
4533
+ return "justify";
4534
+ default:
4535
+ return void 0;
4536
+ }
4537
+ }
4538
+ function paragraphJustification(paragraph2) {
4539
+ const { align, justification } = paragraph2;
4540
+ if (justification && alignFromJustification(justification, paragraph2.direction === "rtl") === align)
4541
+ return justification;
4542
+ return align === void 0 ? void 0 : align === "justify" ? "both" : align;
4543
+ }
4544
+ function parseJustification(pPr) {
4545
+ const justification = enumValue(isStJc, getW(first2(pPr, "jc"), "val"), "w:jc");
4546
+ if (!justification) return {};
4547
+ const align = alignFromJustification(justification, onOffElement(first2(pPr, "bidi")) === true);
4548
+ return { justification, ...align ? { align } : {} };
4549
+ }
4550
+
4551
+ // docx/element-order.ts
4552
+ var RPR_ORDER = [
4553
+ "rStyle",
4554
+ "rFonts",
4555
+ "b",
4556
+ "bCs",
4557
+ "i",
4558
+ "iCs",
4559
+ "caps",
4560
+ "smallCaps",
4561
+ "strike",
4562
+ "dstrike",
4563
+ "outline",
4564
+ "shadow",
4565
+ "emboss",
4566
+ "imprint",
4567
+ "noProof",
4568
+ "snapToGrid",
4569
+ "vanish",
4570
+ "webHidden",
4571
+ "color",
4572
+ "spacing",
4573
+ "w",
4574
+ "kern",
4575
+ "position",
4576
+ "sz",
4577
+ "szCs",
4578
+ "highlight",
4579
+ "u",
4580
+ "effect",
4581
+ "bdr",
4582
+ "shd",
4583
+ "fitText",
4584
+ "vertAlign",
4585
+ "rtl",
4586
+ "cs",
4587
+ "em",
4588
+ "lang",
4589
+ "eastAsianLayout",
4590
+ "specVanish",
4591
+ "oMath",
4592
+ "ins",
4593
+ "del",
4594
+ "moveFrom",
4595
+ "moveTo",
4596
+ "rPrChange"
4597
+ ];
4598
+ function orderChildren(parent, order) {
4599
+ const elements2 = Array.from(parent.childNodes).filter(isElement);
4600
+ const rankOf = (name) => order.findIndex((entry2) => typeof entry2 === "string" ? entry2 === name : entry2.includes(name));
4601
+ let previousRank = -1;
4602
+ const ranked = elements2.map((element4, index) => {
4603
+ const rank2 = element4.namespaceURI === WORD_NS ? rankOf(element4.localName ?? "") : -1;
4604
+ if (rank2 >= 0) previousRank = rank2;
4605
+ return { element: element4, index, rank: rank2 >= 0 ? rank2 : previousRank + 0.5 };
4606
+ });
4607
+ const sorted = [...ranked].sort((a2, b) => a2.rank - b.rank || a2.index - b.index);
4608
+ if (sorted.every((entry2, index) => entry2.element === elements2[index])) return;
4609
+ for (const { element: element4 } of sorted) parent.appendChild(element4);
4610
+ }
4611
+ var SECTPR_ORDER = [
4612
+ ["headerReference", "footerReference"],
4613
+ "footnotePr",
4614
+ "endnotePr",
4615
+ "type",
4616
+ "pgSz",
4617
+ "pgMar",
4618
+ "paperSrc",
4619
+ "pgBorders",
4620
+ "lnNumType",
4621
+ "pgNumType",
4622
+ "cols",
4623
+ "formProt",
4624
+ "vAlign",
4625
+ "noEndnote",
4626
+ "titlePg",
4627
+ "textDirection",
4628
+ "bidi",
4629
+ "rtlGutter",
4630
+ "docGrid",
4631
+ "printerSettings",
4632
+ "sectPrChange"
4633
+ ];
4634
+ function orderSectionProperties(sectPr) {
4635
+ orderChildren(sectPr, SECTPR_ORDER);
4636
+ }
4637
+
4638
+ // docx/tab-stops.ts
4639
+ function parseTabStops(tabs) {
4640
+ const stops = [];
4641
+ for (const tab of tabs ? children2(tabs, "tab") : []) {
4642
+ const align = enumValue(isStTabJc, getW(tab, "val"), "w:tab/@w:val");
4643
+ const pos = parseSignedTwips(getW(tab, "pos"));
4644
+ if (!align || pos === void 0) continue;
4645
+ const leader = enumValue(isStTabTlc, getW(tab, "leader"), "w:tab/@w:leader");
4646
+ stops.push({ posTwips: pos, align, ...leader ? { leader } : {} });
4647
+ }
4648
+ return stops;
4649
+ }
4650
+ function writeTabStops(doc, props, paragraph2, base) {
4651
+ if (base && JSON.stringify(paragraph2.tabStops ?? []) === JSON.stringify(base.tabStops ?? []))
4652
+ return;
4653
+ for (const tabs2 of children2(props, "tabs")) props.removeChild(tabs2);
4654
+ if (!paragraph2.tabStops?.length) return;
4655
+ const tabs = makeW(doc, "tabs");
4656
+ for (const stop of paragraph2.tabStops) {
4657
+ const tab = makeW(doc, "tab");
4658
+ tab.setAttributeNS(WORD_NS, "w:val", stop.align);
4659
+ if (stop.leader) tab.setAttributeNS(WORD_NS, "w:leader", stop.leader);
4660
+ tab.setAttributeNS(WORD_NS, "w:pos", String(stop.posTwips));
4661
+ tabs.appendChild(tab);
4662
+ }
4663
+ props.appendChild(tabs);
4664
+ }
4665
+ var PPR_ORDER = [
4666
+ "pStyle",
4667
+ "keepNext",
4668
+ "keepLines",
4669
+ "pageBreakBefore",
4670
+ "framePr",
4671
+ "widowControl",
4672
+ "numPr",
4673
+ "suppressLineNumbers",
4674
+ "pBdr",
4675
+ "shd",
4676
+ "tabs",
4677
+ "suppressAutoHyphens",
4678
+ "kinsoku",
4679
+ "wordWrap",
4680
+ "overflowPunct",
4681
+ "topLinePunct",
4682
+ "autoSpaceDE",
4683
+ "autoSpaceDN",
4684
+ "bidi",
4685
+ "adjustRightInd",
4686
+ "snapToGrid",
4687
+ "spacing",
4688
+ "ind",
4689
+ "contextualSpacing",
4690
+ "mirrorIndents",
4691
+ "suppressOverlap",
4692
+ "jc",
4693
+ "textDirection",
4694
+ "textAlignment",
4695
+ "textboxTightWrap",
4696
+ "outlineLvl",
4697
+ "divId",
4698
+ "cnfStyle",
4699
+ "rPr",
4700
+ "sectPr",
4701
+ "pPrChange"
4702
+ ];
4703
+ function orderParagraphProperties(props) {
4704
+ orderChildren(props, PPR_ORDER);
4705
+ }
4706
+
4707
+ // docx/write-paragraph-decoration.ts
4708
+ var SIDES = ["top", "left", "bottom", "right", "between"];
4709
+ function wordColor(color) {
4710
+ const hex = /^#?([0-9a-f]{6})$/i.exec(color ?? "")?.[1];
4711
+ return hex ? hex.toUpperCase() : "auto";
4712
+ }
4713
+ function borderElement(doc, name, side) {
4714
+ const element4 = makeW(doc, name);
4715
+ const set2 = (local, value) => element4.setAttributeNS(WORD_NS, `w:${local}`, value);
4716
+ set2("val", side.style ?? "single");
4717
+ if (side.style !== "none" && side.style !== "nil") {
4718
+ set2("sz", String(side.sizeEighthPoints ?? 4));
4719
+ set2("space", String(side.spacePoints ?? 1));
4720
+ set2("color", wordColor(side.color));
4721
+ if (side.themeColor) set2("themeColor", side.themeColor);
4722
+ }
4723
+ return element4;
4724
+ }
4725
+ var sameJson = (a2, b) => JSON.stringify(a2 ?? null) === JSON.stringify(b ?? null);
4726
+ function updateShading(doc, props, paragraph2, base) {
4727
+ if (base && paragraph2.shadingFill === base.shadingFill) return;
4728
+ for (const element4 of children2(props, "shd")) props.removeChild(element4);
4729
+ if (!paragraph2.shadingFill) return;
4730
+ const shd = makeW(doc, "shd");
4731
+ shd.setAttributeNS(WORD_NS, "w:val", "clear");
4732
+ shd.setAttributeNS(WORD_NS, "w:color", "auto");
4733
+ shd.setAttributeNS(WORD_NS, "w:fill", wordColor(paragraph2.shadingFill));
4734
+ props.appendChild(shd);
4735
+ }
4736
+ function updateBorders(doc, props, paragraph2, base) {
4737
+ if (base && sameJson(paragraph2.borders, base.borders)) return;
4738
+ for (const element4 of children2(props, "pBdr")) props.removeChild(element4);
4739
+ const borders = paragraph2.borders;
4740
+ if (!borders) return;
4741
+ const pBdr = makeW(doc, "pBdr");
4742
+ for (const side of SIDES) {
4743
+ const value = borders[side];
4744
+ if (value) pBdr.appendChild(borderElement(doc, side, value));
4745
+ }
4746
+ if (pBdr.childNodes.length) props.appendChild(pBdr);
4747
+ }
4748
+ function writeParagraphDecoration(doc, props, paragraph2, base) {
4749
+ updateShading(doc, props, paragraph2, base);
4750
+ updateBorders(doc, props, paragraph2, base);
4751
+ }
4752
+
4753
+ // docx/write-paragraph-properties.ts
4754
+ function setAttribute(element4, local, value) {
4755
+ element4.setAttributeNS(WORD_NS, `w:${local}`, value);
4756
+ }
4757
+ function setWordValue(element4, local, value) {
4758
+ if (value === void 0) element4.removeAttributeNS(WORD_NS, local);
4759
+ else setAttribute(element4, local, String(value));
4760
+ }
4761
+ function updateDirection(doc, props, paragraph2, base) {
4762
+ if (base && paragraph2.direction === base.direction) return;
4763
+ let bidi = first2(props, "bidi");
4764
+ if (paragraph2.direction === void 0) {
4765
+ for (const element4 of children2(props, "bidi")) props.removeChild(element4);
4766
+ } else {
4767
+ if (!bidi) {
4768
+ bidi = makeW(doc, "bidi");
4769
+ props.appendChild(bidi);
4770
+ }
4771
+ setAttribute(bidi, "val", paragraph2.direction === "rtl" ? "1" : "0");
4772
+ }
4773
+ }
4774
+ function updateSpacing(doc, props, paragraph2, base) {
4775
+ let spacing2 = first2(props, "spacing");
4776
+ if (!spacing2) {
4777
+ spacing2 = makeW(doc, "spacing");
4778
+ props.appendChild(spacing2);
4779
+ }
4780
+ if (!base || paragraph2.spacingBeforeTwips !== base.spacingBeforeTwips)
4781
+ setWordValue(spacing2, "before", paragraph2.spacingBeforeTwips);
4782
+ if (!base || paragraph2.spacingAfterTwips !== base.spacingAfterTwips)
4783
+ setWordValue(spacing2, "after", paragraph2.spacingAfterTwips);
4784
+ if (!base || paragraph2.lineSpacingTwips !== base.lineSpacingTwips || paragraph2.lineSpacingRule !== base.lineSpacingRule) {
4785
+ setWordValue(spacing2, "line", paragraph2.lineSpacingTwips);
4786
+ setWordValue(
4787
+ spacing2,
4788
+ "lineRule",
4789
+ paragraph2.lineSpacingRule ?? (paragraph2.lineSpacingTwips === void 0 ? void 0 : "auto")
4790
+ );
4791
+ }
4792
+ if (!spacing2.attributes.length && !spacing2.childNodes.length) props.removeChild(spacing2);
4793
+ }
4794
+ function updateIndent(doc, props, paragraph2, base) {
4795
+ let indent = first2(props, "ind");
4796
+ if (!indent) {
4797
+ indent = makeW(doc, "ind");
4798
+ props.appendChild(indent);
4799
+ }
4800
+ if (!base || paragraph2.indentLeftTwips !== base.indentLeftTwips)
4801
+ setWordValue(indent, "left", paragraph2.indentLeftTwips);
4802
+ if (!base || paragraph2.indentRightTwips !== base.indentRightTwips)
4803
+ setWordValue(indent, "right", paragraph2.indentRightTwips);
4804
+ if (!base || paragraph2.indentStartTwips !== base.indentStartTwips)
4805
+ setWordValue(indent, "start", paragraph2.indentStartTwips);
4806
+ if (!base || paragraph2.indentEndTwips !== base.indentEndTwips)
4807
+ setWordValue(indent, "end", paragraph2.indentEndTwips);
4808
+ if (!base || paragraph2.firstLineTwips !== base.firstLineTwips)
4809
+ setWordValue(indent, "firstLine", paragraph2.firstLineTwips);
4810
+ if (!base || paragraph2.hangingTwips !== base.hangingTwips)
4811
+ setWordValue(indent, "hanging", paragraph2.hangingTwips);
4812
+ if (!indent.attributes.length) props.removeChild(indent);
4813
+ }
4814
+ function updatePageBreakBefore(doc, props, paragraph2, base) {
4815
+ if (base && paragraph2.pageBreakBefore === base.pageBreakBefore) return;
4816
+ for (const element4 of children2(props, "pageBreakBefore")) props.removeChild(element4);
4817
+ if (paragraph2.pageBreakBefore !== void 0) {
4818
+ const element4 = makeW(doc, "pageBreakBefore");
4819
+ if (!paragraph2.pageBreakBefore) element4.setAttributeNS(WORD_NS, "w:val", "0");
4820
+ props.appendChild(element4);
4821
+ }
4822
+ }
4823
+ function updateKeepOptions(doc, props, paragraph2, base) {
4824
+ for (const key of [
4825
+ "keepNext",
4826
+ "keepLines",
4827
+ "widowControl",
4828
+ "contextualSpacing",
4829
+ "suppressLineNumbers"
4830
+ ]) {
4831
+ if (base && paragraph2[key] === base[key]) continue;
4832
+ for (const element5 of children2(props, key)) props.removeChild(element5);
4833
+ const value = paragraph2[key];
4834
+ if (value === void 0) continue;
4835
+ const element4 = makeW(doc, key);
4836
+ if (!value) setAttribute(element4, "val", "0");
4837
+ props.appendChild(element4);
4838
+ }
4839
+ }
4840
+ function updateDropCap(doc, props, paragraph2, base) {
4841
+ if (base && JSON.stringify(paragraph2.dropCap) === JSON.stringify(base.dropCap)) return;
4842
+ let frame2 = first2(props, "framePr");
4843
+ const cap = paragraph2.dropCap;
4844
+ if (!cap) {
4845
+ if (frame2) props.removeChild(frame2);
4846
+ return;
4847
+ }
4848
+ if (!frame2) {
4849
+ frame2 = makeW(doc, "framePr");
4850
+ props.appendChild(frame2);
4851
+ setAttribute(frame2, "wrap", "around");
4852
+ setAttribute(frame2, "vAnchor", "text");
4853
+ setAttribute(frame2, "hAnchor", "text");
4854
+ }
4855
+ setAttribute(frame2, "dropCap", cap.style);
4856
+ setAttribute(frame2, "lines", String(cap.lines));
4857
+ setWordValue(frame2, "hSpace", cap.distanceTwips);
4858
+ }
4859
+ function writeParagraphProperties(doc, props, paragraph2, base) {
4860
+ updatePageBreakBefore(doc, props, paragraph2, base);
4861
+ updateKeepOptions(doc, props, paragraph2, base);
4862
+ updateDropCap(doc, props, paragraph2, base);
4863
+ updateDirection(doc, props, paragraph2, base);
4864
+ writeParagraphDecoration(doc, props, paragraph2, base);
4865
+ const spacingKeys = [
4866
+ "spacingBeforeTwips",
4867
+ "spacingAfterTwips",
4868
+ "lineSpacingTwips",
4869
+ "lineSpacingRule"
4870
+ ];
4871
+ if (!base || spacingKeys.some((key) => paragraph2[key] !== base[key]))
4872
+ updateSpacing(doc, props, paragraph2, base);
4873
+ const indentKeys = [
4874
+ "indentLeftTwips",
4875
+ "indentRightTwips",
4876
+ "indentStartTwips",
4877
+ "indentEndTwips",
4878
+ "firstLineTwips",
4879
+ "hangingTwips"
4880
+ ];
4881
+ if (!base || indentKeys.some((key) => paragraph2[key] !== base[key]))
4882
+ updateIndent(doc, props, paragraph2, base);
4883
+ }
4884
+
4885
+ // docx/style-formatting-package.ts
4886
+ var STYLES_PART = "word/styles.xml";
4887
+ var AFTER_PPR = ["rPr", "tblPr", "trPr", "tcPr", "tblStylePr"];
4888
+ var WRITABLE_STYLE_FORMATTING = [
4889
+ "align",
4890
+ "justification",
4891
+ "direction",
4892
+ "spacingBeforeTwips",
4893
+ "spacingAfterTwips",
4894
+ "lineSpacingTwips",
4895
+ "lineSpacingRule",
4896
+ "indentLeftTwips",
4897
+ "indentRightTwips",
4898
+ "indentStartTwips",
4899
+ "indentEndTwips",
4900
+ "firstLineTwips",
4901
+ "hangingTwips",
4902
+ "pageBreakBefore",
4903
+ "keepNext",
4904
+ "keepLines",
4905
+ "widowControl",
4906
+ "contextualSpacing",
4907
+ "suppressLineNumbers",
4908
+ "borders",
4909
+ "shadingFill"
4910
+ ];
4911
+ function unwritableFormatting(formatting) {
4912
+ const rest = { ...formatting };
4913
+ for (const key of WRITABLE_STYLE_FORMATTING) delete rest[key];
4914
+ return rest;
4915
+ }
4916
+ var asParagraph = (formatting) => ({
4917
+ type: "paragraph",
4918
+ id: "style",
4919
+ runs: [],
4920
+ ...formatting
4921
+ });
4922
+ function pPrOf(style) {
4923
+ let pPr = first2(style, "pPr");
4924
+ if (pPr) return pPr;
4925
+ pPr = makeW(style.ownerDocument, "pPr");
4926
+ const anchor = Array.from(style.childNodes).find(
4927
+ (node) => node.nodeType === 1 && AFTER_PPR.includes(node.localName)
4928
+ ) ?? null;
4929
+ style.insertBefore(pPr, anchor);
4930
+ return pPr;
4931
+ }
4932
+ async function applyStyleFormatting(zip, model, base) {
4933
+ const next = model.paragraphStyles?.styles ?? {};
4934
+ const prior = base.paragraphStyles?.styles ?? {};
4935
+ const changed = Object.keys(next).filter(
4936
+ (id) => JSON.stringify(next[id]?.formatting) !== JSON.stringify(prior[id]?.formatting)
4937
+ );
4938
+ if (!changed.length) return;
4939
+ const file = zip.file(STYLES_PART);
4940
+ if (!file) throw new Error("Cannot edit a style: the package has no styles.xml.");
4941
+ const doc = parseXml2(await file.async("string"));
4942
+ const styles = children2(doc.documentElement, "style");
4943
+ for (const id of changed) {
4944
+ const style = styles.find(
4945
+ (element4) => getW(element4, "type") === "paragraph" && getW(element4, "styleId") === id
4946
+ );
4947
+ if (!style) throw new Error(`Cannot edit style "${id}": it is not in styles.xml.`);
4948
+ const after = asParagraph(next[id].formatting);
4949
+ const before = asParagraph(prior[id]?.formatting ?? {});
4950
+ const pPr = pPrOf(style);
4951
+ if (after.align !== before.align || after.justification !== before.justification || after.direction !== before.direction) {
4952
+ for (const jc of children2(pPr, "jc")) pPr.removeChild(jc);
4953
+ const value = paragraphJustification(after);
4954
+ if (value) {
4955
+ const jc = makeW(doc, "jc");
4956
+ jc.setAttributeNS(WORD_NS, "w:val", value);
4957
+ pPr.appendChild(jc);
4958
+ }
4959
+ }
4960
+ writeParagraphProperties(doc, pPr, after, before);
4961
+ orderParagraphProperties(pPr);
4962
+ }
4963
+ zip.file(STYLES_PART, buildXml(doc));
4964
+ }
4965
+
4966
+ // docx/data-binding.ts
4967
+ function parsePrefixes(text) {
4968
+ const map = /* @__PURE__ */ new Map();
4969
+ for (const match of (text ?? "").matchAll(/xmlns:([\w.-]+)\s*=\s*(?:'([^']*)'|"([^"]*)")/g))
4970
+ map.set(match[1], match[2] ?? match[3] ?? "");
4971
+ return map;
4972
+ }
4973
+ function sourceBindings(sourceXml) {
4974
+ const result = /* @__PURE__ */ new Map();
4975
+ const document = parseXml2(sourceXml);
4976
+ for (const sdt of Array.from(document.getElementsByTagNameNS(WORD_NS, "sdt"))) {
4977
+ const sdtPr = first2(sdt, "sdtPr");
4978
+ const element4 = sdtPr && elements(sdtPr).find((node) => node.localName === "dataBinding");
4979
+ const id = getW(first2(sdtPr, "id"), "val");
4980
+ const xpath = element4?.getAttributeNS(WORD_NS, "xpath");
4981
+ const storeItemId = element4?.getAttributeNS(WORD_NS, "storeItemID");
4982
+ if (id && element4 && xpath && storeItemId)
4983
+ result.set(id, {
4984
+ xpath,
4985
+ storeItemId,
4986
+ prefixes: parsePrefixes(element4.getAttributeNS(WORD_NS, "prefixMappings") ?? void 0)
4987
+ });
4988
+ }
4989
+ return result;
4990
+ }
4991
+ function paragraphsOf(blocks) {
4992
+ return blocks.flatMap(
4993
+ (block) => block.type === "paragraph" ? [block] : block.rows.flatMap((row) => row.flatMap((c2) => c2.paragraphs))
4994
+ );
4995
+ }
4996
+ function boundTexts(model) {
4997
+ const parts = /* @__PURE__ */ new Map();
4998
+ const add4 = (id, text) => parts.set(id, [...parts.get(id) ?? [], text]);
4999
+ for (const paragraph2 of paragraphsOf(model.blocks)) {
5000
+ const own2 = paragraph2.contentControl;
5001
+ if (own2?.dataBound) {
5002
+ add4(own2.id, paragraph2.runs.map((run2) => run2.text).join(""));
5003
+ continue;
5004
+ }
5005
+ const inline = /* @__PURE__ */ new Map();
5006
+ for (const run2 of paragraph2.runs) {
5007
+ const control = run2.contentControl;
5008
+ if (!control?.dataBound) continue;
5009
+ if (!inline.has(control.id)) inline.set(control.id, "");
5010
+ if (!control.showingPlaceholder) inline.set(control.id, inline.get(control.id) + run2.text);
5011
+ }
5012
+ for (const [id, text] of inline) add4(id, text);
5013
+ }
5014
+ return new Map([...parts].map(([id, texts]) => [id, texts.join("\n")]));
5015
+ }
5016
+ function parseXPath(binding) {
5017
+ const parts = binding.xpath.split("/");
5018
+ if (parts.shift() !== "" || !parts.length) return void 0;
5019
+ if (parts.at(-1) === "text()") parts.pop();
5020
+ const parse = (raw2, attribute3) => {
5021
+ const match = /^(?:([A-Za-z_][\w.-]*):)?([A-Za-z_][\w.-]*)(?:\[(\d+)\])?$/.exec(raw2);
5022
+ if (!match || attribute3 && match[3]) return void 0;
5023
+ const [, prefix2 = "", name = "", index] = match;
5024
+ if (prefix2 && !binding.prefixes.has(prefix2)) return void 0;
5025
+ return { prefix: prefix2, name, index: index ? Number(index) : 1 };
5026
+ };
5027
+ const last = parts.at(-1);
5028
+ const attribute2 = last?.startsWith("@") ? parse(last.slice(1), true) : void 0;
5029
+ if (last?.startsWith("@")) {
5030
+ parts.pop();
5031
+ if (!attribute2) return void 0;
5032
+ }
5033
+ const steps = parts.map((part) => parse(part, false));
5034
+ if (!steps.length || steps.some((step) => !step)) return void 0;
5035
+ return { steps, ...attribute2 ? { attribute: attribute2 } : {} };
5036
+ }
5037
+ var matches = (element4, step, binding) => element4.localName === step.name && (element4.namespaceURI ?? "") === (step.prefix ? binding.prefixes.get(step.prefix) ?? "" : "");
5038
+ function writeValue(root, binding, value) {
5039
+ const path3 = parseXPath(binding);
5040
+ if (!path3) return "unsupported";
5041
+ let node = root;
5042
+ for (const [depth, step] of path3.steps.entries()) {
5043
+ const candidates = depth === 0 ? [root].filter((e) => matches(e, step, binding)) : elements(node).filter((e) => matches(e, step, binding));
5044
+ node = candidates[step.index - 1];
5045
+ if (!node) return false;
5046
+ }
5047
+ if (path3.attribute) {
5048
+ const { prefix: prefix2, name } = path3.attribute;
5049
+ const ns = prefix2 ? binding.prefixes.get(prefix2) : void 0;
5050
+ if (ns) node.setAttributeNS(ns, `${prefix2}:${name}`, value);
5051
+ else node.setAttribute(name, value);
5052
+ return true;
5053
+ }
5054
+ for (const child8 of Array.from(node.childNodes)) node.removeChild(child8);
5055
+ if (value) node.appendChild(node.ownerDocument.createTextNode(value));
5056
+ return true;
5057
+ }
5058
+ async function findItemPart(zip, storeItemId) {
5059
+ const wanted = storeItemId.toLowerCase();
5060
+ for (const name of Object.keys(zip.files)) {
5061
+ const props = /^customXml\/itemProps(\d+)\.xml$/.exec(name);
5062
+ if (!props) continue;
5063
+ const root = parseXml2(await zip.file(name).async("string")).documentElement;
5064
+ const id = Array.from(root.attributes).find((attribute2) => attribute2.localName === "itemID");
5065
+ if ((id?.value ?? "").toLowerCase() === wanted) return `customXml/item${props[1]}.xml`;
5066
+ }
5067
+ return void 0;
5068
+ }
5069
+ async function applyDataBindings(zip, model, base, sourceXml) {
5070
+ const now = boundTexts(model);
5071
+ if (!now.size) return;
5072
+ const before = boundTexts(base);
5073
+ const bindings = sourceBindings(sourceXml);
5074
+ const parsed = /* @__PURE__ */ new Map();
5075
+ for (const [id, text] of now) {
5076
+ const binding = bindings.get(id);
5077
+ if (!binding || before.get(id) === text) continue;
5078
+ const part = await findItemPart(zip, binding.storeItemId);
5079
+ const file = part ? zip.file(part) : void 0;
5080
+ if (!part || !file) continue;
5081
+ const document = parsed.get(part) ?? parseXml2(await file.async("string"));
5082
+ parsed.set(part, document);
5083
+ const written = writeValue(document.documentElement, binding, text);
5084
+ if (written !== true)
5085
+ throw new Error(
5086
+ written === "unsupported" ? `Cannot update the data-bound content control ${id}: the XPath ${binding.xpath} is not supported, so Word would keep showing the old bound value. The original DOCX package remains unchanged.` : `Cannot update the data-bound content control ${id}: the XPath ${binding.xpath} selects no node in ${part}. The original DOCX package remains unchanged.`
5087
+ );
5088
+ }
5089
+ for (const [part, document] of parsed) zip.file(part, buildXml(document));
5090
+ }
5091
+
4106
5092
  // docx/ligatures.ts
4107
5093
  var LIGATURE_VALUES = [
4108
5094
  "none",
@@ -4125,7 +5111,7 @@ var LIGATURE_VALUES = [
4125
5111
  var isLigatures = (value) => typeof value === "string" && LIGATURE_VALUES.includes(value);
4126
5112
  var WORD_2010_NS = "http://schemas.microsoft.com/office/word/2010/wordml";
4127
5113
  var MC = "http://schemas.openxmlformats.org/markup-compatibility/2006";
4128
- var XMLNS2 = "http://www.w3.org/2000/xmlns/";
5114
+ var XMLNS3 = "http://www.w3.org/2000/xmlns/";
4129
5115
  var ligatureElements = (props) => elements(props).filter(
4130
5116
  (element4) => element4.namespaceURI === WORD_2010_NS && element4.localName === "ligatures"
4131
5117
  );
@@ -4138,7 +5124,7 @@ function extensionPrefix(doc, ns, preferred) {
4138
5124
  let prefix2 = preferred;
4139
5125
  for (let index = 1; root.lookupNamespaceURI(prefix2) && root.lookupNamespaceURI(prefix2) !== ns; index++)
4140
5126
  prefix2 = `${preferred}${index}`;
4141
- root.setAttributeNS(XMLNS2, `xmlns:${prefix2}`, ns);
5127
+ root.setAttributeNS(XMLNS3, `xmlns:${prefix2}`, ns);
4142
5128
  return prefix2;
4143
5129
  }
4144
5130
  function declareIgnorableExtension(doc, ns, preferred) {
@@ -4420,93 +5406,6 @@ var flatRows = (table) => flatChildren(table, ["tr"], "row");
4420
5406
  var flatCells = (row) => flatChildren(row, ["tc"], "cell");
4421
5407
  var flatCellParagraphs = (cell2) => flatChildren(cell2, ["p"]);
4422
5408
 
4423
- // docx/element-order.ts
4424
- var RPR_ORDER = [
4425
- "rStyle",
4426
- "rFonts",
4427
- "b",
4428
- "bCs",
4429
- "i",
4430
- "iCs",
4431
- "caps",
4432
- "smallCaps",
4433
- "strike",
4434
- "dstrike",
4435
- "outline",
4436
- "shadow",
4437
- "emboss",
4438
- "imprint",
4439
- "noProof",
4440
- "snapToGrid",
4441
- "vanish",
4442
- "webHidden",
4443
- "color",
4444
- "spacing",
4445
- "w",
4446
- "kern",
4447
- "position",
4448
- "sz",
4449
- "szCs",
4450
- "highlight",
4451
- "u",
4452
- "effect",
4453
- "bdr",
4454
- "shd",
4455
- "fitText",
4456
- "vertAlign",
4457
- "rtl",
4458
- "cs",
4459
- "em",
4460
- "lang",
4461
- "eastAsianLayout",
4462
- "specVanish",
4463
- "oMath",
4464
- "ins",
4465
- "del",
4466
- "moveFrom",
4467
- "moveTo",
4468
- "rPrChange"
4469
- ];
4470
- function orderChildren(parent, order) {
4471
- const elements2 = Array.from(parent.childNodes).filter(isElement);
4472
- const rankOf = (name) => order.findIndex((entry2) => typeof entry2 === "string" ? entry2 === name : entry2.includes(name));
4473
- let previousRank = -1;
4474
- const ranked = elements2.map((element4, index) => {
4475
- const rank2 = element4.namespaceURI === WORD_NS ? rankOf(element4.localName ?? "") : -1;
4476
- if (rank2 >= 0) previousRank = rank2;
4477
- return { element: element4, index, rank: rank2 >= 0 ? rank2 : previousRank + 0.5 };
4478
- });
4479
- const sorted = [...ranked].sort((a2, b) => a2.rank - b.rank || a2.index - b.index);
4480
- if (sorted.every((entry2, index) => entry2.element === elements2[index])) return;
4481
- for (const { element: element4 } of sorted) parent.appendChild(element4);
4482
- }
4483
- var SECTPR_ORDER = [
4484
- ["headerReference", "footerReference"],
4485
- "footnotePr",
4486
- "endnotePr",
4487
- "type",
4488
- "pgSz",
4489
- "pgMar",
4490
- "paperSrc",
4491
- "pgBorders",
4492
- "lnNumType",
4493
- "pgNumType",
4494
- "cols",
4495
- "formProt",
4496
- "vAlign",
4497
- "noEndnote",
4498
- "titlePg",
4499
- "textDirection",
4500
- "bidi",
4501
- "rtlGutter",
4502
- "docGrid",
4503
- "printerSettings",
4504
- "sectPrChange"
4505
- ];
4506
- function orderSectionProperties(sectPr) {
4507
- orderChildren(sectPr, SECTPR_ORDER);
4508
- }
4509
-
4510
5409
  // docx/content-control-values.ts
4511
5410
  var validLock = (lock) => lock === "sdtLocked" || lock === "contentLocked" || lock === "sdtContentLocked" ? lock : void 0;
4512
5411
  function validId(id) {
@@ -4732,15 +5631,15 @@ function writeDate(doc, sdtPr, control) {
4732
5631
  const fullDate = validDate(control.fullDate) ?? (control.fullDate === existing ? existing : void 0);
4733
5632
  if (fullDate) date.setAttributeNS(WORD_NS, "w:fullDate", fullDate);
4734
5633
  else date.removeAttributeNS(WORD_NS, "fullDate");
4735
- const set = (local, value, order) => {
5634
+ const set2 = (local, value, order) => {
4736
5635
  for (const old of children2(date, local)) date.removeChild(old);
4737
5636
  if (typeof value !== "string") return;
4738
5637
  const element4 = makeW(doc, local);
4739
5638
  element4.setAttributeNS(WORD_NS, "w:val", value);
4740
5639
  date.insertBefore(element4, Array.from(date.childNodes)[order] ?? null);
4741
5640
  };
4742
- set("dateFormat", control.dateFormat, 0);
4743
- set("lid", control.dateLocale, 1);
5641
+ set2("dateFormat", control.dateFormat, 0);
5642
+ set2("lid", control.dateLocale, 1);
4744
5643
  }
4745
5644
  var writesType = (kind) => NAMED_TYPES.has(kind) || ["richText", "text", "checkbox", "dropDownList", "comboBox", "date"].includes(kind);
4746
5645
  function patchContentControl(doc, sdt, control) {
@@ -4918,13 +5817,13 @@ function rangeKeys(run2) {
4918
5817
  keys.push(`${revision.kind}:${revision.move.name}`);
4919
5818
  return keys;
4920
5819
  }
4921
- function paragraphsOf(blocks) {
5820
+ function paragraphsOf2(blocks) {
4922
5821
  return blocks.flatMap(
4923
5822
  (block) => block.type === "paragraph" ? [block] : block.rows.flatMap((row) => row.flatMap((cell2) => cell2.paragraphs))
4924
5823
  );
4925
5824
  }
4926
5825
  function commentContinuations(blocks) {
4927
- const paragraphs = paragraphsOf(blocks);
5826
+ const paragraphs = paragraphsOf2(blocks);
4928
5827
  const first3 = /* @__PURE__ */ new Map();
4929
5828
  const last = /* @__PURE__ */ new Map();
4930
5829
  const idsByParagraph = paragraphs.map((paragraph2, index) => {
@@ -4989,7 +5888,7 @@ var COMMENTS_PATH = "word/comments.xml";
4989
5888
  var COMMENTS_EXTENDED_PATH = "word/commentsExtended.xml";
4990
5889
  var W14_NS = "http://schemas.microsoft.com/office/word/2010/wordml";
4991
5890
  var W15_NS = "http://schemas.microsoft.com/office/word/2012/wordml";
4992
- function setAttribute(element4, local, value) {
5891
+ function setAttribute2(element4, local, value) {
4993
5892
  element4.setAttributeNS(WORD_NS, `w:${local}`, value);
4994
5893
  }
4995
5894
  function paraIdFor(id, index) {
@@ -5004,10 +5903,10 @@ function buildCommentsDocument(comments) {
5004
5903
  const root = doc.documentElement;
5005
5904
  comments.forEach((comment, index) => {
5006
5905
  const el5 = makeW(doc, "comment");
5007
- setAttribute(el5, "id", comment.id);
5008
- setAttribute(el5, "author", comment.author);
5009
- if (comment.date) setAttribute(el5, "date", comment.date);
5010
- if (comment.initials) setAttribute(el5, "initials", comment.initials);
5906
+ setAttribute2(el5, "id", comment.id);
5907
+ setAttribute2(el5, "author", comment.author);
5908
+ if (comment.date) setAttribute2(el5, "date", comment.date);
5909
+ if (comment.initials) setAttribute2(el5, "initials", comment.initials);
5011
5910
  const p = makeW(doc, "p");
5012
5911
  p.setAttributeNS(W14_NS, "w14:paraId", paraIdFor(comment.id, index));
5013
5912
  const r = makeW(doc, "r");
@@ -5071,15 +5970,15 @@ async function applyComments(zip, comments) {
5071
5970
  }
5072
5971
  function commentRangeStartNode(doc, id) {
5073
5972
  const element4 = makeW(doc, "commentRangeStart");
5074
- setAttribute(element4, "id", id);
5973
+ setAttribute2(element4, "id", id);
5075
5974
  return element4;
5076
5975
  }
5077
5976
  function commentRangeEndNodes(doc, id) {
5078
5977
  const end = makeW(doc, "commentRangeEnd");
5079
- setAttribute(end, "id", id);
5978
+ setAttribute2(end, "id", id);
5080
5979
  const run2 = makeW(doc, "r");
5081
5980
  const reference = makeW(doc, "commentReference");
5082
- setAttribute(reference, "id", id);
5981
+ setAttribute2(reference, "id", id);
5083
5982
  run2.appendChild(reference);
5084
5983
  return [end, run2];
5085
5984
  }
@@ -5327,112 +6226,6 @@ var DEFAULT_THEME_COLOR_MAP = {
5327
6226
  tx2: "dk2"
5328
6227
  };
5329
6228
 
5330
- // docx/generated/wml-simple-types.ts
5331
- var ST_HighlightColor = ["black", "blue", "cyan", "green", "magenta", "red", "yellow", "white", "darkBlue", "darkCyan", "darkGreen", "darkMagenta", "darkRed", "darkYellow", "darkGray", "lightGray", "none"];
5332
- function isStHighlightColor(value) {
5333
- return typeof value === "string" && ST_HighlightColor.includes(value);
5334
- }
5335
- var ST_Underline = ["single", "words", "double", "thick", "dotted", "dottedHeavy", "dash", "dashedHeavy", "dashLong", "dashLongHeavy", "dotDash", "dashDotHeavy", "dotDotDash", "dashDotDotHeavy", "wave", "wavyHeavy", "wavyDouble", "none"];
5336
- function isStUnderline(value) {
5337
- return typeof value === "string" && ST_Underline.includes(value);
5338
- }
5339
- var ST_Border = ["nil", "none", "single", "thick", "double", "dotted", "dashed", "dotDash", "dotDotDash", "triple", "thinThickSmallGap", "thickThinSmallGap", "thinThickThinSmallGap", "thinThickMediumGap", "thickThinMediumGap", "thinThickThinMediumGap", "thinThickLargeGap", "thickThinLargeGap", "thinThickThinLargeGap", "wave", "doubleWave", "dashSmallGap", "dashDotStroked", "threeDEmboss", "threeDEngrave", "outset", "inset", "apples", "archedScallops", "babyPacifier", "babyRattle", "balloons3Colors", "balloonsHotAir", "basicBlackDashes", "basicBlackDots", "basicBlackSquares", "basicThinLines", "basicWhiteDashes", "basicWhiteDots", "basicWhiteSquares", "basicWideInline", "basicWideMidline", "basicWideOutline", "bats", "birds", "birdsFlight", "cabins", "cakeSlice", "candyCorn", "celticKnotwork", "certificateBanner", "chainLink", "champagneBottle", "checkedBarBlack", "checkedBarColor", "checkered", "christmasTree", "circlesLines", "circlesRectangles", "classicalWave", "clocks", "compass", "confetti", "confettiGrays", "confettiOutline", "confettiStreamers", "confettiWhite", "cornerTriangles", "couponCutoutDashes", "couponCutoutDots", "crazyMaze", "creaturesButterfly", "creaturesFish", "creaturesInsects", "creaturesLadyBug", "crossStitch", "cup", "decoArch", "decoArchColor", "decoBlocks", "diamondsGray", "doubleD", "doubleDiamonds", "earth1", "earth2", "earth3", "eclipsingSquares1", "eclipsingSquares2", "eggsBlack", "fans", "film", "firecrackers", "flowersBlockPrint", "flowersDaisies", "flowersModern1", "flowersModern2", "flowersPansy", "flowersRedRose", "flowersRoses", "flowersTeacup", "flowersTiny", "gems", "gingerbreadMan", "gradient", "handmade1", "handmade2", "heartBalloon", "heartGray", "hearts", "heebieJeebies", "holly", "houseFunky", "hypnotic", "iceCreamCones", "lightBulb", "lightning1", "lightning2", "mapPins", "mapleLeaf", "mapleMuffins", "marquee", "marqueeToothed", "moons", "mosaic", "musicNotes", "northwest", "ovals", "packages", "palmsBlack", "palmsColor", "paperClips", "papyrus", "partyFavor", "partyGlass", "pencils", "people", "peopleWaving", "peopleHats", "poinsettias", "postageStamp", "pumpkin1", "pushPinNote2", "pushPinNote1", "pyramids", "pyramidsAbove", "quadrants", "rings", "safari", "sawtooth", "sawtoothGray", "scaredCat", "seattle", "shadowedSquares", "sharksTeeth", "shorebirdTracks", "skyrocket", "snowflakeFancy", "snowflakes", "sombrero", "southwest", "stars", "starsTop", "stars3d", "starsBlack", "starsShadowed", "sun", "swirligig", "tornPaper", "tornPaperBlack", "trees", "triangleParty", "triangles", "triangle1", "triangle2", "triangleCircle1", "triangleCircle2", "shapes1", "shapes2", "twistedLines1", "twistedLines2", "vine", "waveline", "weavingAngles", "weavingBraid", "weavingRibbon", "weavingStrips", "whiteFlowers", "woodwork", "xIllusions", "zanyTriangles", "zigZag", "zigZagStitch", "custom"];
5340
- function isStBorder(value) {
5341
- return typeof value === "string" && ST_Border.includes(value);
5342
- }
5343
- var ST_TabJc = ["clear", "start", "center", "end", "decimal", "bar", "num", "left", "right"];
5344
- function isStTabJc(value) {
5345
- return typeof value === "string" && ST_TabJc.includes(value);
5346
- }
5347
- var ST_TabTlc = ["none", "dot", "hyphen", "underscore", "heavy", "middleDot"];
5348
- function isStTabTlc(value) {
5349
- return typeof value === "string" && ST_TabTlc.includes(value);
5350
- }
5351
- var ST_LineSpacingRule = ["auto", "exact", "atLeast"];
5352
- function isStLineSpacingRule(value) {
5353
- return typeof value === "string" && ST_LineSpacingRule.includes(value);
5354
- }
5355
- var ST_Jc = ["start", "center", "end", "both", "mediumKashida", "distribute", "numTab", "highKashida", "lowKashida", "thaiDistribute", "left", "right"];
5356
- function isStJc(value) {
5357
- return typeof value === "string" && ST_Jc.includes(value);
5358
- }
5359
- var ST_JcTable = ["center", "end", "left", "right", "start"];
5360
- function isStJcTable(value) {
5361
- return typeof value === "string" && ST_JcTable.includes(value);
5362
- }
5363
- var ST_DocProtect = ["none", "readOnly", "comments", "trackedChanges", "forms"];
5364
- function isStDocProtect(value) {
5365
- return typeof value === "string" && ST_DocProtect.includes(value);
5366
- }
5367
- var ST_FldCharType = ["begin", "separate", "end"];
5368
- function isStFldCharType(value) {
5369
- return typeof value === "string" && ST_FldCharType.includes(value);
5370
- }
5371
- var ST_InfoTextType = ["text", "autoText"];
5372
- function isStInfoTextType(value) {
5373
- return typeof value === "string" && ST_InfoTextType.includes(value);
5374
- }
5375
- var ST_FFTextType = ["regular", "number", "date", "currentTime", "currentDate", "calculated"];
5376
- function isStFFTextType(value) {
5377
- return typeof value === "string" && ST_FFTextType.includes(value);
5378
- }
5379
- var ST_SectionMark = ["nextPage", "nextColumn", "continuous", "evenPage", "oddPage"];
5380
- function isStSectionMark(value) {
5381
- return typeof value === "string" && ST_SectionMark.includes(value);
5382
- }
5383
- var ST_NumberFormat = ["decimal", "upperRoman", "lowerRoman", "upperLetter", "lowerLetter", "ordinal", "cardinalText", "ordinalText", "hex", "chicago", "ideographDigital", "japaneseCounting", "aiueo", "iroha", "decimalFullWidth", "decimalHalfWidth", "japaneseLegal", "japaneseDigitalTenThousand", "decimalEnclosedCircle", "decimalFullWidth2", "aiueoFullWidth", "irohaFullWidth", "decimalZero", "bullet", "ganada", "chosung", "decimalEnclosedFullstop", "decimalEnclosedParen", "decimalEnclosedCircleChinese", "ideographEnclosedCircle", "ideographTraditional", "ideographZodiac", "ideographZodiacTraditional", "taiwaneseCounting", "ideographLegalTraditional", "taiwaneseCountingThousand", "taiwaneseDigital", "chineseCounting", "chineseLegalSimplified", "chineseCountingThousand", "koreanDigital", "koreanCounting", "koreanLegal", "koreanDigital2", "vietnameseCounting", "russianLower", "russianUpper", "none", "numberInDash", "hebrew1", "hebrew2", "arabicAlpha", "arabicAbjad", "hindiVowels", "hindiConsonants", "hindiNumbers", "hindiCounting", "thaiLetters", "thaiNumbers", "thaiCounting", "bahtText", "dollarText", "custom"];
5384
- function isStNumberFormat(value) {
5385
- return typeof value === "string" && ST_NumberFormat.includes(value);
5386
- }
5387
- var ST_PageOrientation = ["portrait", "landscape"];
5388
- function isStPageOrientation(value) {
5389
- return typeof value === "string" && ST_PageOrientation.includes(value);
5390
- }
5391
- var ST_VerticalJc = ["top", "center", "both", "bottom"];
5392
- function isStVerticalJc(value) {
5393
- return typeof value === "string" && ST_VerticalJc.includes(value);
5394
- }
5395
- var ST_BrType = ["page", "column", "textWrapping"];
5396
- function isStBrType(value) {
5397
- return typeof value === "string" && ST_BrType.includes(value);
5398
- }
5399
- var ST_PTabAlignment = ["left", "center", "right"];
5400
- function isStPTabAlignment(value) {
5401
- return typeof value === "string" && ST_PTabAlignment.includes(value);
5402
- }
5403
- var ST_PTabRelativeTo = ["margin", "indent"];
5404
- function isStPTabRelativeTo(value) {
5405
- return typeof value === "string" && ST_PTabRelativeTo.includes(value);
5406
- }
5407
- var ST_PTabLeader = ["none", "dot", "hyphen", "underscore", "middleDot"];
5408
- function isStPTabLeader(value) {
5409
- return typeof value === "string" && ST_PTabLeader.includes(value);
5410
- }
5411
- var ST_Merge = ["continue", "restart"];
5412
- function isStMerge(value) {
5413
- return typeof value === "string" && ST_Merge.includes(value);
5414
- }
5415
- var ST_WmlColorSchemeIndex = ["dark1", "light1", "dark2", "light2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hyperlink", "followedHyperlink"];
5416
- function isStWmlColorSchemeIndex(value) {
5417
- return typeof value === "string" && ST_WmlColorSchemeIndex.includes(value);
5418
- }
5419
- var ST_ThemeColor = ["dark1", "light1", "dark2", "light2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hyperlink", "followedHyperlink", "none", "background1", "text1", "background2", "text2"];
5420
- function isStThemeColor(value) {
5421
- return typeof value === "string" && ST_ThemeColor.includes(value);
5422
- }
5423
- var ST_VerticalAlignRun = ["baseline", "superscript", "subscript"];
5424
- function isStVerticalAlignRun(value) {
5425
- return typeof value === "string" && ST_VerticalAlignRun.includes(value);
5426
- }
5427
- var ST_RelFromH = ["margin", "page", "column", "character", "leftMargin", "rightMargin", "insideMargin", "outsideMargin"];
5428
- function isStRelFromH(value) {
5429
- return typeof value === "string" && ST_RelFromH.includes(value);
5430
- }
5431
- var ST_RelFromV = ["margin", "page", "paragraph", "line", "topMargin", "bottomMargin", "insideMargin", "outsideMargin"];
5432
- function isStRelFromV(value) {
5433
- return typeof value === "string" && ST_RelFromV.includes(value);
5434
- }
5435
-
5436
6229
  // docx/theme-color.ts
5437
6230
  function isThemeColorToken(value) {
5438
6231
  return isStThemeColor(value);
@@ -5589,10 +6382,10 @@ function buildRowProperties(doc, row, gridAfter) {
5589
6382
  }
5590
6383
 
5591
6384
  // docx/write-table-margins.ts
5592
- var SIDES = ["top", "left", "bottom", "right"];
6385
+ var SIDES2 = ["top", "left", "bottom", "right"];
5593
6386
  var ORDER = ["top", "start", "left", "bottom", "end", "right"];
5594
6387
  function patchMarginProperties(doc, host, propertiesTag, marginTag, propertiesOrder, next, base) {
5595
- const changed = SIDES.filter((side) => next?.[side] !== base?.[side]);
6388
+ const changed = SIDES2.filter((side) => next?.[side] !== base?.[side]);
5596
6389
  if (!changed.length) return;
5597
6390
  for (const side of changed) {
5598
6391
  const value = next?.[side];
@@ -5912,14 +6705,21 @@ function unwrapDroppedControls(elements2, next) {
5912
6705
  });
5913
6706
  }
5914
6707
 
5915
- // docx/write-table.ts
6708
+ // docx/table-structure-check.ts
6709
+ var only = (parent, allowed) => Array.from(parent.childNodes).filter(isElement).every((node) => allowed.some((name) => named2(node, name)));
6710
+ function plainParagraphs(cell2) {
6711
+ for (const paragraph2 of children2(cell2, "p")) {
6712
+ if (!only(paragraph2, ["pPr", "r"])) return false;
6713
+ for (const run2 of children2(paragraph2, "r"))
6714
+ if (!only(run2, ["rPr", "t", "tab", "br", "cr", "noBreakHyphen"])) return false;
6715
+ }
6716
+ return true;
6717
+ }
5916
6718
  function canEditTableStructure(table) {
5917
- const only = (parent, allowed) => Array.from(parent.childNodes).filter(isElement).every((node) => allowed.some((name) => named2(node, name)));
5918
6719
  if (!only(table, ["tblPr", "tblGrid", "tr"])) return false;
5919
6720
  const grid = first2(table, "tblGrid");
5920
6721
  if (grid && !only(grid, ["gridCol"])) return false;
5921
6722
  const rows = children2(table, "tr");
5922
- if (!rows.length) return false;
5923
6723
  const [firstRow] = rows;
5924
6724
  if (!firstRow) return false;
5925
6725
  const width = children2(firstRow, "tc").length;
@@ -5935,15 +6735,206 @@ function canEditTableStructure(table) {
5935
6735
  const props = first2(cell2, "tcPr");
5936
6736
  if (props && ["gridSpan", "vMerge", "hMerge", "tcPrChange"].some((key) => first2(props, key)))
5937
6737
  return false;
5938
- for (const paragraph2 of children2(cell2, "p")) {
5939
- if (!only(paragraph2, ["pPr", "r"])) return false;
5940
- for (const run2 of children2(paragraph2, "r"))
5941
- if (!only(run2, ["rPr", "t", "tab", "br", "cr", "noBreakHyphen"])) return false;
5942
- }
6738
+ if (!plainParagraphs(cell2)) return false;
5943
6739
  }
5944
6740
  }
5945
6741
  return true;
5946
6742
  }
6743
+ function canRestructureTable(table) {
6744
+ if (!only(table, ["tblPr", "tblGrid", "tr"])) return false;
6745
+ const grid = first2(table, "tblGrid");
6746
+ if (!grid || !only(grid, ["gridCol"])) return false;
6747
+ const rows = children2(table, "tr");
6748
+ if (!rows.length) return false;
6749
+ for (const row of rows) {
6750
+ if (!only(row, ["trPr", "tc"]) || !children2(row, "tc").length) return false;
6751
+ const rowProps = first2(row, "trPr");
6752
+ if (rowProps && ["gridBefore", "gridAfter", "wBefore", "wAfter", "trPrChange", "ins", "del"].some(
6753
+ (key) => first2(rowProps, key)
6754
+ ))
6755
+ return false;
6756
+ for (const cell2 of children2(row, "tc")) {
6757
+ if (!only(cell2, ["tcPr", "p", "tbl"]) || !children2(cell2, "p").length) return false;
6758
+ const props = first2(cell2, "tcPr");
6759
+ if (props && ["hMerge", "tcPrChange", "cellIns", "cellDel", "cellMerge"].some((key) => first2(props, key)))
6760
+ return false;
6761
+ if (!plainParagraphs(cell2)) return false;
6762
+ }
6763
+ }
6764
+ return true;
6765
+ }
6766
+
6767
+ // docx/write-table-structure.ts
6768
+ var set = (element4, name, value) => element4.setAttributeNS(WORD_NS, `w:${name}`, value);
6769
+ function restructured(next, base) {
6770
+ const shape = (table) => JSON.stringify([
6771
+ table.grid,
6772
+ table.rows.map(
6773
+ (row) => row.map((cell2) => [
6774
+ cell2.paragraphs.map((p) => p.id),
6775
+ cell2.gridSpan ?? 1,
6776
+ cell2.verticalMerge ?? "",
6777
+ cell2.widthTwips
6778
+ ])
6779
+ )
6780
+ ]);
6781
+ return shape(next) !== shape(base);
6782
+ }
6783
+ function patchCellLayout(doc, tc, cell2, base) {
6784
+ const span = cell2.gridSpan ?? 1;
6785
+ const width = cell2.widthTwips;
6786
+ if (span === (base.gridSpan ?? 1) && width === base.widthTwips && cell2.verticalMerge === base.verticalMerge)
6787
+ return;
6788
+ let props = first2(tc, "tcPr");
6789
+ if (!props) {
6790
+ props = makeW(doc, "tcPr");
6791
+ tc.insertBefore(props, tc.firstChild);
6792
+ }
6793
+ const replace = (name, next) => {
6794
+ for (const old of children2(props, name)) props.removeChild(old);
6795
+ if (next) props.appendChild(next);
6796
+ };
6797
+ if (width !== base.widthTwips) {
6798
+ const old = first2(props, "tcW");
6799
+ if (width === void 0) replace("tcW", void 0);
6800
+ else {
6801
+ const element4 = old ?? makeW(doc, "tcW");
6802
+ set(element4, "w", String(width));
6803
+ set(element4, "type", "dxa");
6804
+ if (!old) props.appendChild(element4);
6805
+ }
6806
+ }
6807
+ if (span !== (base.gridSpan ?? 1)) {
6808
+ const element4 = span > 1 ? makeW(doc, "gridSpan") : void 0;
6809
+ if (element4) set(element4, "val", String(span));
6810
+ replace("gridSpan", element4);
6811
+ }
6812
+ if (cell2.verticalMerge !== base.verticalMerge) {
6813
+ const element4 = cell2.verticalMerge ? makeW(doc, "vMerge") : void 0;
6814
+ if (element4 && cell2.verticalMerge === "restart") set(element4, "val", "restart");
6815
+ replace("vMerge", element4);
6816
+ }
6817
+ orderChildren(props, CELL_ORDER);
6818
+ if (!Array.from(props.childNodes).some((node) => node.nodeType === 1) && !props.attributes.length)
6819
+ tc.removeChild(props);
6820
+ }
6821
+ function patchGrid(doc, node, table) {
6822
+ const grid = first2(node, "tblGrid");
6823
+ if (!grid || !table.grid) return;
6824
+ const old = children2(grid, "gridCol");
6825
+ table.grid.forEach((width, index) => {
6826
+ let column = old[index];
6827
+ if (!column) {
6828
+ column = makeW(doc, "gridCol");
6829
+ grid.appendChild(column);
6830
+ }
6831
+ if (column.getAttributeNS(WORD_NS, "w") !== String(width)) set(column, "w", String(width));
6832
+ });
6833
+ for (const extra of old.slice(table.grid.length)) grid.removeChild(extra);
6834
+ }
6835
+ function writeRestructuredTable(doc, table, node, base, writeParagraph, replaceSlots2, writeNested) {
6836
+ if (table.rows.some((row) => !row.length || row.some((cell2) => !cell2.paragraphs.length)))
6837
+ throw new Error("Every table row needs a cell and every cell a paragraph.");
6838
+ const oldRows = flatRows(node).map((entry2) => entry2.element);
6839
+ const oldCells = oldRows.map((tr) => flatCells(tr).map((entry2) => entry2.element));
6840
+ const cellById = /* @__PURE__ */ new Map();
6841
+ const paragraphById = /* @__PURE__ */ new Map();
6842
+ base.rows.forEach(
6843
+ (row, ri) => row.forEach((cell2, ci) => {
6844
+ const tc = oldCells[ri]?.[ci];
6845
+ if (!tc) return;
6846
+ const id = cell2.paragraphs[0]?.id;
6847
+ if (id) cellById.set(id, { tc, model: cell2, row: ri });
6848
+ const flat = flatCellParagraphs(tc);
6849
+ cell2.paragraphs.forEach((model, pi) => {
6850
+ const entry2 = flat[pi];
6851
+ if (entry2) paragraphById.set(model.id, { element: entry2.element, model });
6852
+ });
6853
+ })
6854
+ );
6855
+ const usedRows = /* @__PURE__ */ new Set();
6856
+ const usedCells = /* @__PURE__ */ new Set();
6857
+ const nextRows = table.rows.map((row, rowIndex) => {
6858
+ const sourceRow = row.map((cell2) => cellById.get(cell2.paragraphs[0]?.id ?? "")?.row).find((index) => index !== void 0 && !usedRows.has(index));
6859
+ if (sourceRow !== void 0) usedRows.add(sourceRow);
6860
+ const tr = sourceRow === void 0 ? makeW(doc, "tr") : oldRows[sourceRow] ?? makeW(doc, "tr");
6861
+ patchRowProperties(
6862
+ doc,
6863
+ tr,
6864
+ table.rowProperties?.[rowIndex],
6865
+ sourceRow === void 0 ? void 0 : base.rowProperties?.[sourceRow]
6866
+ );
6867
+ const nextCells = row.map((cell2) => {
6868
+ const source2 = cellById.get(cell2.paragraphs[0]?.id ?? "");
6869
+ const reuse = source2 && source2.row === sourceRow && !usedCells.has(source2.tc) ? source2 : void 0;
6870
+ const tc = reuse?.tc ?? makeW(doc, "tc");
6871
+ if (reuse) {
6872
+ usedCells.add(reuse.tc);
6873
+ patchCellLayout(doc, tc, cell2, reuse.model);
6874
+ patchCellBorders(doc, tc, cell2.borders, reuse.model.borders);
6875
+ patchCellShading(doc, tc, cell2, reuse.model);
6876
+ patchCellMargins(doc, tc, cell2.margins, reuse.model.margins);
6877
+ patchCellVerticalAlignment(doc, tc, cell2.verticalAlign, reuse.model.verticalAlign);
6878
+ } else {
6879
+ const props = buildCellProperties(doc, cell2);
6880
+ if (props) tc.insertBefore(props, tc.firstChild);
6881
+ }
6882
+ const oldParagraphs = reuse ? flatCellParagraphs(tc).map((entry2) => entry2.element) : [];
6883
+ const owned = new Set(oldParagraphs);
6884
+ const nextParagraphs = cell2.paragraphs.map((paragraph2) => {
6885
+ const found = paragraphById.get(paragraph2.id);
6886
+ const element4 = found ? owned.has(found.element) ? found.element : found.element.cloneNode(true) : makeW(doc, "p");
6887
+ return writeParagraph(doc, paragraph2, element4, found?.model);
6888
+ });
6889
+ replaceSlots2(doc, tc, oldParagraphs, nextParagraphs);
6890
+ if (reuse) writeNested(doc, tc, cell2, reuse.model);
6891
+ return tc;
6892
+ });
6893
+ replaceSlots2(doc, tr, sourceRow === void 0 ? [] : oldCells[sourceRow] ?? [], nextCells);
6894
+ return tr;
6895
+ });
6896
+ replaceSlots2(doc, node, oldRows, nextRows);
6897
+ patchTableMargins(doc, table, node, base);
6898
+ patchGrid(doc, node, table);
6899
+ return node;
6900
+ }
6901
+
6902
+ // docx/table-grid.ts
6903
+ var spanOf = (cell2) => Math.max(1, cell2.gridSpan ?? 1);
6904
+ function tableGrid(table) {
6905
+ const columns = table.grid?.length ?? sumSpans(table.rows[0]);
6906
+ if (!columns || !table.rows.length) return void 0;
6907
+ const rows = [];
6908
+ const cover = [];
6909
+ for (let row = 0; row < table.rows.length; row++) {
6910
+ const cells = table.rows[row] ?? [];
6911
+ if (!cells.length || sumSpans(cells) !== columns) return void 0;
6912
+ const placed = [];
6913
+ const line2 = new Array(columns);
6914
+ let col = 0;
6915
+ cells.forEach((cell2, index) => {
6916
+ const entry2 = { cell: cell2, row, index, col, span: spanOf(cell2) };
6917
+ for (let k = 0; k < entry2.span; k++) line2[col + k] = entry2;
6918
+ col += entry2.span;
6919
+ placed.push(entry2);
6920
+ });
6921
+ rows.push(placed);
6922
+ cover.push(line2);
6923
+ }
6924
+ const grid = { columns, rows, cover };
6925
+ for (const entry2 of rows.flat())
6926
+ if (entry2.cell.verticalMerge === "continue") {
6927
+ const above = entry2.row > 0 ? cover[entry2.row - 1]?.[entry2.col] : void 0;
6928
+ if (!above || above.col !== entry2.col || above.span !== entry2.span) return void 0;
6929
+ if (!above.cell.verticalMerge) return void 0;
6930
+ }
6931
+ return grid;
6932
+ }
6933
+ function sumSpans(cells) {
6934
+ return (cells ?? []).reduce((sum, cell2) => sum + spanOf(cell2), 0);
6935
+ }
6936
+
6937
+ // docx/write-table.ts
5947
6938
  var layout = (table) => table.rows.map((row) => row.map((cell2) => cell2.paragraphs.map((p) => p.id)));
5948
6939
  var TABLE_DESCRIPTOR_KEYS = [
5949
6940
  "grid",
@@ -5961,13 +6952,15 @@ function pick(source2, keys) {
5961
6952
  for (const key of keys) if (record[key] !== void 0) result[key] = record[key];
5962
6953
  return result;
5963
6954
  }
5964
- function assertNoDescriptorEdits(table, base) {
6955
+ function assertNoDescriptorEdits(table, base, layoutEdits = false) {
5965
6956
  if (!base) return;
5966
- if (JSON.stringify(pick(table, TABLE_DESCRIPTOR_KEYS)) !== JSON.stringify(pick(base, TABLE_DESCRIPTOR_KEYS)))
6957
+ const tableKeys = layoutEdits ? TABLE_DESCRIPTOR_KEYS.filter((key) => key !== "grid") : TABLE_DESCRIPTOR_KEYS;
6958
+ if (JSON.stringify(pick(table, tableKeys)) !== JSON.stringify(pick(base, tableKeys)))
5967
6959
  throw new Error(
5968
6960
  "Cannot edit table grid widths, width, alignment, indent, borders, or style; only cell text and row/column structure changes are supported. The original DOCX package remains unchanged."
5969
6961
  );
5970
6962
  const baseCellById = /* @__PURE__ */ new Map();
6963
+ if (layoutEdits) return;
5971
6964
  for (const row of base.rows)
5972
6965
  for (const cell2 of row) {
5973
6966
  const id = cell2.paragraphs[0]?.id;
@@ -5992,11 +6985,24 @@ function writeNestedTables(doc, tc, cell2, base, writeParagraph, replaceSlots2)
5992
6985
  next.forEach((table, index) => {
5993
6986
  const node = nodes[index];
5994
6987
  if (node && before[index])
5995
- writeTable(doc, table, node, before[index], writeParagraph, replaceSlots2);
6988
+ writeTable(doc, table, node, before[index], writeParagraph, replaceSlots2, true);
5996
6989
  });
5997
6990
  }
5998
- function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
6991
+ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2, nested = false) {
5999
6992
  if (base && JSON.stringify(table) === JSON.stringify(base)) return node;
6993
+ const baseGrid = base && tableGrid(base);
6994
+ if (base && baseGrid && (nested || !base.structureEditable || table.structureEditable === false) && restructured(table, base) && canRestructureTable(node)) {
6995
+ assertNoDescriptorEdits(table, base, true);
6996
+ return writeRestructuredTable(
6997
+ doc,
6998
+ table,
6999
+ node,
7000
+ base,
7001
+ writeParagraph,
7002
+ replaceSlots2,
7003
+ (d, tc, cell2, before) => writeNestedTables(d, tc, cell2, before, writeParagraph, replaceSlots2)
7004
+ );
7005
+ }
6000
7006
  assertNoDescriptorEdits(table, base);
6001
7007
  patchTableMargins(doc, table, node, base);
6002
7008
  const structural = base && JSON.stringify(layout(table)) !== JSON.stringify(layout(base));
@@ -6122,13 +7128,13 @@ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
6122
7128
 
6123
7129
  // docx/write-footnote-columns.ts
6124
7130
  var W15 = "http://schemas.microsoft.com/office/word/2012/wordml";
6125
- var XMLNS3 = "http://www.w3.org/2000/xmlns/";
7131
+ var XMLNS4 = "http://www.w3.org/2000/xmlns/";
6126
7132
  var MC2 = "http://schemas.openxmlformats.org/markup-compatibility/2006";
6127
7133
  function prefix(doc, preferred, namespace) {
6128
7134
  let name = preferred;
6129
7135
  for (let suffix = 1; doc.documentElement.lookupNamespaceURI(name) && doc.documentElement.lookupNamespaceURI(name) !== namespace; suffix++)
6130
7136
  name = preferred + suffix;
6131
- doc.documentElement.setAttributeNS(XMLNS3, "xmlns:" + name, namespace);
7137
+ doc.documentElement.setAttributeNS(XMLNS4, "xmlns:" + name, namespace);
6132
7138
  return name;
6133
7139
  }
6134
7140
  function writeFootnoteColumns(doc, section, value) {
@@ -6150,29 +7156,8 @@ function writeFootnoteColumns(doc, section, value) {
6150
7156
  section.appendChild(element4);
6151
7157
  }
6152
7158
 
6153
- // docx/parse-diagnostics.ts
6154
- var sink;
6155
- function withParseWarnings(warnings, fn) {
6156
- const previous = sink;
6157
- sink = warnings;
6158
- try {
6159
- return fn();
6160
- } finally {
6161
- sink = previous;
6162
- }
6163
- }
6164
- function reportParseWarning(message) {
6165
- if (sink && !sink.includes(message)) sink.push(message);
6166
- }
6167
- function enumValue(guard, raw2, label) {
6168
- if (raw2 === null || raw2 === void 0 || raw2 === "") return void 0;
6169
- if (guard(raw2)) return raw2;
6170
- reportParseWarning(`Ignored invalid ${label} value \u201C${raw2}\u201D; it is not allowed by the schema.`);
6171
- return void 0;
6172
- }
6173
-
6174
7159
  // docx/table-borders.ts
6175
- var SIDES2 = [
7160
+ var SIDES3 = [
6176
7161
  "top",
6177
7162
  "bottom",
6178
7163
  "left",
@@ -6198,7 +7183,7 @@ function parseTableBorders(bordersElement) {
6198
7183
  if (!bordersElement) return void 0;
6199
7184
  const result = {};
6200
7185
  const alias = { left: "start", right: "end" };
6201
- for (const side of SIDES2) {
7186
+ for (const side of SIDES3) {
6202
7187
  const aliasName = alias[side];
6203
7188
  const value = borderSide(
6204
7189
  first2(bordersElement, side) ?? (aliasName ? first2(bordersElement, aliasName) : void 0)
@@ -6235,13 +7220,13 @@ function parseParagraphBorders(pBdr) {
6235
7220
  }
6236
7221
 
6237
7222
  // docx/page-borders.ts
6238
- var SIDES3 = ["top", "left", "bottom", "right"];
7223
+ var SIDES4 = ["top", "left", "bottom", "right"];
6239
7224
  var ATTRIBUTES = ["offsetFrom", "display", "zOrder"];
6240
7225
  var setW4 = (element4, name, value) => element4.setAttributeNS(WORD_NS, `w:${name}`, value);
6241
7226
  function parsePageBorders(element4) {
6242
7227
  if (!element4) return void 0;
6243
7228
  const result = {};
6244
- for (const side of SIDES3) {
7229
+ for (const side of SIDES4) {
6245
7230
  const source2 = first2(element4, side);
6246
7231
  const value = borderSide(source2);
6247
7232
  const art = getW(source2, "art");
@@ -6279,7 +7264,7 @@ function patchPageBorders(doc, sectPr, next, base, create2) {
6279
7264
  return;
6280
7265
  }
6281
7266
  const element4 = create2(doc, sectPr, "pgBorders");
6282
- for (const side of SIDES3) {
7267
+ for (const side of SIDES4) {
6283
7268
  if (JSON.stringify(next[side]) === JSON.stringify(base?.[side])) continue;
6284
7269
  for (const old of children2(element4, side)) element4.removeChild(old);
6285
7270
  const value = next[side];
@@ -6460,75 +7445,6 @@ function writePageNumbering(doc, sectPr, section) {
6460
7445
  }
6461
7446
  }
6462
7447
 
6463
- // docx/tab-stops.ts
6464
- function parseTabStops(tabs) {
6465
- const stops = [];
6466
- for (const tab of tabs ? children2(tabs, "tab") : []) {
6467
- const align = enumValue(isStTabJc, getW(tab, "val"), "w:tab/@w:val");
6468
- const pos = parseSignedTwips(getW(tab, "pos"));
6469
- if (!align || pos === void 0) continue;
6470
- const leader = enumValue(isStTabTlc, getW(tab, "leader"), "w:tab/@w:leader");
6471
- stops.push({ posTwips: pos, align, ...leader ? { leader } : {} });
6472
- }
6473
- return stops;
6474
- }
6475
- function writeTabStops(doc, props, paragraph2, base) {
6476
- if (base && JSON.stringify(paragraph2.tabStops ?? []) === JSON.stringify(base.tabStops ?? []))
6477
- return;
6478
- for (const tabs2 of children2(props, "tabs")) props.removeChild(tabs2);
6479
- if (!paragraph2.tabStops?.length) return;
6480
- const tabs = makeW(doc, "tabs");
6481
- for (const stop of paragraph2.tabStops) {
6482
- const tab = makeW(doc, "tab");
6483
- tab.setAttributeNS(WORD_NS, "w:val", stop.align);
6484
- if (stop.leader) tab.setAttributeNS(WORD_NS, "w:leader", stop.leader);
6485
- tab.setAttributeNS(WORD_NS, "w:pos", String(stop.posTwips));
6486
- tabs.appendChild(tab);
6487
- }
6488
- props.appendChild(tabs);
6489
- }
6490
- var PPR_ORDER = [
6491
- "pStyle",
6492
- "keepNext",
6493
- "keepLines",
6494
- "pageBreakBefore",
6495
- "framePr",
6496
- "widowControl",
6497
- "numPr",
6498
- "suppressLineNumbers",
6499
- "pBdr",
6500
- "shd",
6501
- "tabs",
6502
- "suppressAutoHyphens",
6503
- "kinsoku",
6504
- "wordWrap",
6505
- "overflowPunct",
6506
- "topLinePunct",
6507
- "autoSpaceDE",
6508
- "autoSpaceDN",
6509
- "bidi",
6510
- "adjustRightInd",
6511
- "snapToGrid",
6512
- "spacing",
6513
- "ind",
6514
- "contextualSpacing",
6515
- "mirrorIndents",
6516
- "suppressOverlap",
6517
- "jc",
6518
- "textDirection",
6519
- "textAlignment",
6520
- "textboxTightWrap",
6521
- "outlineLvl",
6522
- "divId",
6523
- "cnfStyle",
6524
- "rPr",
6525
- "sectPr",
6526
- "pPrChange"
6527
- ];
6528
- function orderParagraphProperties(props) {
6529
- orderChildren(props, PPR_ORDER);
6530
- }
6531
-
6532
7448
  // docx/write-sections.ts
6533
7449
  var WRITABLE = /* @__PURE__ */ new Set([
6534
7450
  "endsAtBlockId",
@@ -7133,16 +8049,16 @@ function isWordElement(element4, names) {
7133
8049
  }
7134
8050
  var isRevisionWrapperElement = (element4) => isWordElement(element4, REVISION_WRAPPER_NAMES2);
7135
8051
  var isCommentAnchorElement = (element4) => isWordElement(element4, COMMENT_ANCHOR_NAMES);
7136
- function setAttribute2(element4, local, value) {
8052
+ function setAttribute3(element4, local, value) {
7137
8053
  element4.setAttributeNS(WORD_NS, `w:${local}`, value);
7138
8054
  }
7139
8055
  function removeChildren(element4, local) {
7140
8056
  for (const child8 of children2(element4, local)) element4.removeChild(child8);
7141
8057
  }
7142
8058
  function writeRevisionMetadata(element4, revision) {
7143
- setAttribute2(element4, "id", revision.id);
7144
- setAttribute2(element4, "author", revision.author);
7145
- if (revision.date) setAttribute2(element4, "date", revision.date);
8059
+ setAttribute3(element4, "id", revision.id);
8060
+ setAttribute3(element4, "author", revision.author);
8061
+ if (revision.date) setAttribute3(element4, "date", revision.date);
7146
8062
  else element4.removeAttributeNS(WORD_NS, "date");
7147
8063
  if (revision.dateUtc) element4.setAttributeNS(WORD_DATE_UTC_NS, "w16du:dateUtc", revision.dateUtc);
7148
8064
  else element4.removeAttributeNS(WORD_DATE_UTC_NS, "dateUtc");
@@ -7277,184 +8193,6 @@ function restoreAnnotations(markers, before, after) {
7277
8193
  }
7278
8194
  }
7279
8195
 
7280
- // docx/write-paragraph-decoration.ts
7281
- var SIDES4 = ["top", "left", "bottom", "right", "between"];
7282
- function wordColor(color) {
7283
- const hex = /^#?([0-9a-f]{6})$/i.exec(color ?? "")?.[1];
7284
- return hex ? hex.toUpperCase() : "auto";
7285
- }
7286
- function borderElement(doc, name, side) {
7287
- const element4 = makeW(doc, name);
7288
- const set = (local, value) => element4.setAttributeNS(WORD_NS, `w:${local}`, value);
7289
- set("val", side.style ?? "single");
7290
- if (side.style !== "none" && side.style !== "nil") {
7291
- set("sz", String(side.sizeEighthPoints ?? 4));
7292
- set("space", String(side.spacePoints ?? 1));
7293
- set("color", wordColor(side.color));
7294
- if (side.themeColor) set("themeColor", side.themeColor);
7295
- }
7296
- return element4;
7297
- }
7298
- var sameJson = (a2, b) => JSON.stringify(a2 ?? null) === JSON.stringify(b ?? null);
7299
- function updateShading(doc, props, paragraph2, base) {
7300
- if (base && paragraph2.shadingFill === base.shadingFill) return;
7301
- for (const element4 of children2(props, "shd")) props.removeChild(element4);
7302
- if (!paragraph2.shadingFill) return;
7303
- const shd = makeW(doc, "shd");
7304
- shd.setAttributeNS(WORD_NS, "w:val", "clear");
7305
- shd.setAttributeNS(WORD_NS, "w:color", "auto");
7306
- shd.setAttributeNS(WORD_NS, "w:fill", wordColor(paragraph2.shadingFill));
7307
- props.appendChild(shd);
7308
- }
7309
- function updateBorders(doc, props, paragraph2, base) {
7310
- if (base && sameJson(paragraph2.borders, base.borders)) return;
7311
- for (const element4 of children2(props, "pBdr")) props.removeChild(element4);
7312
- const borders = paragraph2.borders;
7313
- if (!borders) return;
7314
- const pBdr = makeW(doc, "pBdr");
7315
- for (const side of SIDES4) {
7316
- const value = borders[side];
7317
- if (value) pBdr.appendChild(borderElement(doc, side, value));
7318
- }
7319
- if (pBdr.childNodes.length) props.appendChild(pBdr);
7320
- }
7321
- function writeParagraphDecoration(doc, props, paragraph2, base) {
7322
- updateShading(doc, props, paragraph2, base);
7323
- updateBorders(doc, props, paragraph2, base);
7324
- }
7325
-
7326
- // docx/write-paragraph-properties.ts
7327
- function setAttribute3(element4, local, value) {
7328
- element4.setAttributeNS(WORD_NS, `w:${local}`, value);
7329
- }
7330
- function setWordValue(element4, local, value) {
7331
- if (value === void 0) element4.removeAttributeNS(WORD_NS, local);
7332
- else setAttribute3(element4, local, String(value));
7333
- }
7334
- function updateDirection(doc, props, paragraph2, base) {
7335
- if (base && paragraph2.direction === base.direction) return;
7336
- let bidi = first2(props, "bidi");
7337
- if (paragraph2.direction === void 0) {
7338
- for (const element4 of children2(props, "bidi")) props.removeChild(element4);
7339
- } else {
7340
- if (!bidi) {
7341
- bidi = makeW(doc, "bidi");
7342
- props.appendChild(bidi);
7343
- }
7344
- setAttribute3(bidi, "val", paragraph2.direction === "rtl" ? "1" : "0");
7345
- }
7346
- }
7347
- function updateSpacing(doc, props, paragraph2, base) {
7348
- let spacing2 = first2(props, "spacing");
7349
- if (!spacing2) {
7350
- spacing2 = makeW(doc, "spacing");
7351
- props.appendChild(spacing2);
7352
- }
7353
- if (!base || paragraph2.spacingBeforeTwips !== base.spacingBeforeTwips)
7354
- setWordValue(spacing2, "before", paragraph2.spacingBeforeTwips);
7355
- if (!base || paragraph2.spacingAfterTwips !== base.spacingAfterTwips)
7356
- setWordValue(spacing2, "after", paragraph2.spacingAfterTwips);
7357
- if (!base || paragraph2.lineSpacingTwips !== base.lineSpacingTwips || paragraph2.lineSpacingRule !== base.lineSpacingRule) {
7358
- setWordValue(spacing2, "line", paragraph2.lineSpacingTwips);
7359
- setWordValue(
7360
- spacing2,
7361
- "lineRule",
7362
- paragraph2.lineSpacingRule ?? (paragraph2.lineSpacingTwips === void 0 ? void 0 : "auto")
7363
- );
7364
- }
7365
- if (!spacing2.attributes.length && !spacing2.childNodes.length) props.removeChild(spacing2);
7366
- }
7367
- function updateIndent(doc, props, paragraph2, base) {
7368
- let indent = first2(props, "ind");
7369
- if (!indent) {
7370
- indent = makeW(doc, "ind");
7371
- props.appendChild(indent);
7372
- }
7373
- if (!base || paragraph2.indentLeftTwips !== base.indentLeftTwips)
7374
- setWordValue(indent, "left", paragraph2.indentLeftTwips);
7375
- if (!base || paragraph2.indentRightTwips !== base.indentRightTwips)
7376
- setWordValue(indent, "right", paragraph2.indentRightTwips);
7377
- if (!base || paragraph2.indentStartTwips !== base.indentStartTwips)
7378
- setWordValue(indent, "start", paragraph2.indentStartTwips);
7379
- if (!base || paragraph2.indentEndTwips !== base.indentEndTwips)
7380
- setWordValue(indent, "end", paragraph2.indentEndTwips);
7381
- if (!base || paragraph2.firstLineTwips !== base.firstLineTwips)
7382
- setWordValue(indent, "firstLine", paragraph2.firstLineTwips);
7383
- if (!base || paragraph2.hangingTwips !== base.hangingTwips)
7384
- setWordValue(indent, "hanging", paragraph2.hangingTwips);
7385
- if (!indent.attributes.length) props.removeChild(indent);
7386
- }
7387
- function updatePageBreakBefore(doc, props, paragraph2, base) {
7388
- if (base && paragraph2.pageBreakBefore === base.pageBreakBefore) return;
7389
- for (const element4 of children2(props, "pageBreakBefore")) props.removeChild(element4);
7390
- if (paragraph2.pageBreakBefore !== void 0) {
7391
- const element4 = makeW(doc, "pageBreakBefore");
7392
- if (!paragraph2.pageBreakBefore) element4.setAttributeNS(WORD_NS, "w:val", "0");
7393
- props.appendChild(element4);
7394
- }
7395
- }
7396
- function updateKeepOptions(doc, props, paragraph2, base) {
7397
- for (const key of [
7398
- "keepNext",
7399
- "keepLines",
7400
- "widowControl",
7401
- "contextualSpacing",
7402
- "suppressLineNumbers"
7403
- ]) {
7404
- if (base && paragraph2[key] === base[key]) continue;
7405
- for (const element5 of children2(props, key)) props.removeChild(element5);
7406
- const value = paragraph2[key];
7407
- if (value === void 0) continue;
7408
- const element4 = makeW(doc, key);
7409
- if (!value) setAttribute3(element4, "val", "0");
7410
- props.appendChild(element4);
7411
- }
7412
- }
7413
- function updateDropCap(doc, props, paragraph2, base) {
7414
- if (base && JSON.stringify(paragraph2.dropCap) === JSON.stringify(base.dropCap)) return;
7415
- let frame2 = first2(props, "framePr");
7416
- const cap = paragraph2.dropCap;
7417
- if (!cap) {
7418
- if (frame2) props.removeChild(frame2);
7419
- return;
7420
- }
7421
- if (!frame2) {
7422
- frame2 = makeW(doc, "framePr");
7423
- props.appendChild(frame2);
7424
- setAttribute3(frame2, "wrap", "around");
7425
- setAttribute3(frame2, "vAnchor", "text");
7426
- setAttribute3(frame2, "hAnchor", "text");
7427
- }
7428
- setAttribute3(frame2, "dropCap", cap.style);
7429
- setAttribute3(frame2, "lines", String(cap.lines));
7430
- setWordValue(frame2, "hSpace", cap.distanceTwips);
7431
- }
7432
- function writeParagraphProperties(doc, props, paragraph2, base) {
7433
- updatePageBreakBefore(doc, props, paragraph2, base);
7434
- updateKeepOptions(doc, props, paragraph2, base);
7435
- updateDropCap(doc, props, paragraph2, base);
7436
- updateDirection(doc, props, paragraph2, base);
7437
- writeParagraphDecoration(doc, props, paragraph2, base);
7438
- const spacingKeys = [
7439
- "spacingBeforeTwips",
7440
- "spacingAfterTwips",
7441
- "lineSpacingTwips",
7442
- "lineSpacingRule"
7443
- ];
7444
- if (!base || spacingKeys.some((key) => paragraph2[key] !== base[key]))
7445
- updateSpacing(doc, props, paragraph2, base);
7446
- const indentKeys = [
7447
- "indentLeftTwips",
7448
- "indentRightTwips",
7449
- "indentStartTwips",
7450
- "indentEndTwips",
7451
- "firstLineTwips",
7452
- "hangingTwips"
7453
- ];
7454
- if (!base || indentKeys.some((key) => paragraph2[key] !== base[key]))
7455
- updateIndent(doc, props, paragraph2, base);
7456
- }
7457
-
7458
8196
  // docx/bookmarks.ts
7459
8197
  function paragraphBookmarkNames(node) {
7460
8198
  return children2(node, "bookmarkStart").map((el5) => getW(el5, "name")).filter((name) => Boolean(name));
@@ -7504,41 +8242,6 @@ function writeNumberingProperties(doc, props, paragraph2, base) {
7504
8242
  props.appendChild(numPr);
7505
8243
  }
7506
8244
 
7507
- // docx/paragraph-alignment.ts
7508
- function alignFromJustification(jc, rtl) {
7509
- switch (jc) {
7510
- case "left":
7511
- case "center":
7512
- case "right":
7513
- return jc;
7514
- case "start":
7515
- return rtl ? "right" : "left";
7516
- case "end":
7517
- return rtl ? "left" : "right";
7518
- case "both":
7519
- case "distribute":
7520
- case "thaiDistribute":
7521
- case "mediumKashida":
7522
- case "highKashida":
7523
- case "lowKashida":
7524
- return "justify";
7525
- default:
7526
- return void 0;
7527
- }
7528
- }
7529
- function paragraphJustification(paragraph2) {
7530
- const { align, justification } = paragraph2;
7531
- if (justification && alignFromJustification(justification, paragraph2.direction === "rtl") === align)
7532
- return justification;
7533
- return align === void 0 ? void 0 : align === "justify" ? "both" : align;
7534
- }
7535
- function parseJustification(pPr) {
7536
- const justification = enumValue(isStJc, getW(first2(pPr, "jc"), "val"), "w:jc");
7537
- if (!justification) return {};
7538
- const align = alignFromJustification(justification, onOffElement(first2(pPr, "bidi")) === true);
7539
- return { justification, ...align ? { align } : {} };
7540
- }
7541
-
7542
8245
  // docx/underline.ts
7543
8246
  var WORD_UNDERLINE_TOKENS = [
7544
8247
  "single",
@@ -8414,7 +9117,7 @@ function applyPictureEffects(blip, effects) {
8414
9117
  const node = source2 ? blip.ownerDocument.importNode(source2, true) : blip.ownerDocument.createElementNS(NS.a, `a:${name}`);
8415
9118
  if (effect.kind !== "unsupported" && (node.namespaceURI !== NS.a || node.localName !== name))
8416
9119
  throw new Error("Picture effect source does not match its kind");
8417
- const set = (name2, value) => {
9120
+ const set2 = (name2, value) => {
8418
9121
  const original = picturePercentage(node.getAttribute(name2));
8419
9122
  if (value === void 0) node.removeAttribute(name2);
8420
9123
  else if (value !== original) {
@@ -8427,12 +9130,12 @@ function applyPictureEffects(blip, effects) {
8427
9130
  (value) => value !== void 0 && (!Number.isFinite(value) || Math.abs(value) > 1)
8428
9131
  ))
8429
9132
  throw new RangeError("Picture luminance must be between -1 and 1");
8430
- set("bright", effect.brightness);
8431
- set("contrast", effect.contrast);
9133
+ set2("bright", effect.brightness);
9134
+ set2("contrast", effect.contrast);
8432
9135
  }
8433
9136
  if (effect.kind === "alphaModFix") {
8434
9137
  if (effect.amount < 0) throw new RangeError("Picture alpha must be nonnegative");
8435
- set("amt", effect.amount);
9138
+ set2("amt", effect.amount);
8436
9139
  }
8437
9140
  return node;
8438
9141
  });
@@ -10932,10 +11635,10 @@ function writeDrawingRichTextBody(container2, body) {
10932
11635
  const paragraphs = body.paragraphs.length ? body.paragraphs : [{ items: [] }];
10933
11636
  for (const paragraph2 of paragraphs) container2.appendChild(writeDrawingParagraph(doc, paragraph2));
10934
11637
  }
10935
- function drawingRichTextBodyXml(body, qualifiedName = "a:txBody", namespace = NS.a) {
10936
- const prefix2 = qualifiedName.includes(":") ? qualifiedName.split(":")[0] : void 0;
11638
+ function drawingRichTextBodyXml(body, qualifiedName2 = "a:txBody", namespace = NS.a) {
11639
+ const prefix2 = qualifiedName2.includes(":") ? qualifiedName2.split(":")[0] : void 0;
10937
11640
  const declaration = prefix2 && prefix2 !== "a" ? ` xmlns:${prefix2}="${namespace}"` : "";
10938
- const doc = parseXml(`<${qualifiedName}${declaration} xmlns:a="${NS.a}" xmlns:r="${NS.r}"/>`);
11641
+ const doc = parseXml(`<${qualifiedName2}${declaration} xmlns:a="${NS.a}" xmlns:r="${NS.r}"/>`);
10939
11642
  writeDrawingRichTextBody(doc.documentElement, body);
10940
11643
  return buildXml(doc);
10941
11644
  }
@@ -17860,7 +18563,8 @@ var pie = {
17860
18563
  gd16("stAng", "pin 0 adj1 21599999"),
17861
18564
  gd16("endAng", "pin 0 adj2 21599999"),
17862
18565
  gd16("swAng", "+- endAng 0 stAng"),
17863
- gd16("swAng2", "?: swAng swAng +- 21600000 swAng 0"),
18566
+ gd16("swAngWrap", "+- swAng 21600000 0"),
18567
+ gd16("swAng2", "?: swAng swAng swAngWrap"),
17864
18568
  gd16("stx", "cos wd2 stAng"),
17865
18569
  gd16("sty", "sin hd2 stAng"),
17866
18570
  gd16("x1", "+- hc stx 0"),
@@ -17905,7 +18609,8 @@ var chord = {
17905
18609
  gd16("stAng", "pin 0 adj1 21599999"),
17906
18610
  gd16("endAng", "pin 0 adj2 21599999"),
17907
18611
  gd16("swAng", "+- endAng 0 stAng"),
17908
- gd16("swAng2", "?: swAng swAng +- 21600000 swAng 0"),
18612
+ gd16("swAngWrap", "+- swAng 21600000 0"),
18613
+ gd16("swAng2", "?: swAng swAng swAngWrap"),
17909
18614
  gd16("stx", "cos wd2 stAng"),
17910
18615
  gd16("sty", "sin hd2 stAng"),
17911
18616
  gd16("x1", "+- hc stx 0"),
@@ -17929,7 +18634,8 @@ var arc = {
17929
18634
  gd16("stAng", "pin 0 adj1 21599999"),
17930
18635
  gd16("endAng", "pin 0 adj2 21599999"),
17931
18636
  gd16("swAng", "+- endAng 0 stAng"),
17932
- gd16("swAng2", "?: swAng swAng +- 21600000 swAng 0"),
18637
+ gd16("swAngWrap", "+- swAng 21600000 0"),
18638
+ gd16("swAng2", "?: swAng swAng swAngWrap"),
17933
18639
  gd16("stx", "cos wd2 stAng"),
17934
18640
  gd16("sty", "sin hd2 stAng"),
17935
18641
  gd16("x1", "+- hc stx 0"),
@@ -18024,7 +18730,8 @@ var blockArc = {
18024
18730
  gd16("iwd2", "+- wd2 0 thw"),
18025
18731
  gd16("ihd2", "+- hd2 0 thh2"),
18026
18732
  gd16("swAng", "+- endAng 0 stAng"),
18027
- gd16("swAng2", "?: swAng swAng +- 21600000 swAng 0"),
18733
+ gd16("swAngWrap", "+- swAng 21600000 0"),
18734
+ gd16("swAng2", "?: swAng swAng swAngWrap"),
18028
18735
  gd16("mswAng", "+- 0 0 swAng2"),
18029
18736
  gd16("stx", "cos wd2 stAng"),
18030
18737
  gd16("sty", "sin hd2 stAng"),
@@ -20187,12 +20894,12 @@ function shapeParagraphs(wsp) {
20187
20894
  function textIsPlain(wsp) {
20188
20895
  const content = child5(child5(wsp, WPS_NS2, "txbx"), W_NS2, "txbxContent");
20189
20896
  if (!content) return true;
20190
- const only = (node, allowed) => elementsOf(node).every(
20897
+ const only2 = (node, allowed) => elementsOf(node).every(
20191
20898
  (item2) => item2.namespaceURI === W_NS2 && allowed.includes(item2.localName)
20192
20899
  );
20193
- return only(content, ["p"]) && Array.from(content.getElementsByTagNameNS(W_NS2, "p")).every(
20194
- (paragraph2) => only(paragraph2, ["pPr", "r"]) && Array.from(paragraph2.getElementsByTagNameNS(W_NS2, "r")).every(
20195
- (run2) => only(run2, ["rPr", "t"])
20900
+ return only2(content, ["p"]) && Array.from(content.getElementsByTagNameNS(W_NS2, "p")).every(
20901
+ (paragraph2) => only2(paragraph2, ["pPr", "r"]) && Array.from(paragraph2.getElementsByTagNameNS(W_NS2, "r")).every(
20902
+ (run2) => only2(run2, ["rPr", "t"])
20196
20903
  )
20197
20904
  );
20198
20905
  }
@@ -20435,7 +21142,7 @@ function parseAttributes(source2) {
20435
21142
  }
20436
21143
  return attrs2;
20437
21144
  }
20438
- function tagEnd(xml, from) {
21145
+ function tagEnd2(xml, from) {
20439
21146
  let quote = "";
20440
21147
  for (let i2 = from; i2 < xml.length; i2++) {
20441
21148
  const ch = xml[i2];
@@ -20466,7 +21173,7 @@ function parseOrderedXml(xml) {
20466
21173
  i2 = close < 0 ? -1 : xml.indexOf("<", close + 3);
20467
21174
  continue;
20468
21175
  }
20469
- const end = tagEnd(xml, i2 + 1);
21176
+ const end = tagEnd2(xml, i2 + 1);
20470
21177
  if (end < 0) {
20471
21178
  break;
20472
21179
  }
@@ -21046,17 +21753,17 @@ function isShadowedBound(node, constraint) {
21046
21753
 
21047
21754
  // diagram/engine/constraint-eval.ts
21048
21755
  function relatedNodes(node, relation2, name, ptType) {
21049
- const matches = (candidate) => (!name || candidate.name === name) && (matchesPointType(candidate.point, ptType) || candidate.presOf.length > 0 && matchesPointType(candidate.presOf[0], ptType));
21756
+ const matches2 = (candidate) => (!name || candidate.name === name) && (matchesPointType(candidate.point, ptType) || candidate.presOf.length > 0 && matchesPointType(candidate.presOf[0], ptType));
21050
21757
  if (relation2 === "self") {
21051
21758
  return name && node.name !== name ? [] : [node];
21052
21759
  }
21053
21760
  if (relation2 === "ch") {
21054
- return node.children.filter(matches);
21761
+ return node.children.filter(matches2);
21055
21762
  }
21056
21763
  const out = [];
21057
21764
  const visit = (current) => {
21058
21765
  for (const child8 of current.children) {
21059
- if (matches(child8)) {
21766
+ if (matches2(child8)) {
21060
21767
  out.push(child8);
21061
21768
  }
21062
21769
  visit(child8);
@@ -28214,8 +28921,8 @@ function parseDisplayUnits(context, element4) {
28214
28921
 
28215
28922
  // chart/write-util.ts
28216
28923
  var INVALID_XML = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/g;
28217
- var escapeText = (value) => value.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
28218
- var escapeAttribute = (value) => escapeText(value).replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;").replace(/\t/g, "&#9;");
28924
+ var escapeText2 = (value) => value.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
28925
+ var escapeAttribute = (value) => escapeText2(value).replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;").replace(/\t/g, "&#9;");
28219
28926
  function chartNumber(value) {
28220
28927
  if (!Number.isFinite(value)) throw new Error(`Chart number ${value} is not finite`);
28221
28928
  const text = String(value);
@@ -28895,7 +29602,7 @@ function run(value) {
28895
29602
  const hasProperties = Object.keys(properties).length > 0;
28896
29603
  if (text === "\n")
28897
29604
  return hasProperties ? `<a:br>${runProperties("rPr", properties)}</a:br>` : "<a:br/>";
28898
- return `<a:r>${hasProperties ? runProperties("rPr", properties) : ""}<a:t>${escapeText(text)}</a:t></a:r>`;
29605
+ return `<a:r>${hasProperties ? runProperties("rPr", properties) : ""}<a:t>${escapeText2(text)}</a:t></a:r>`;
28899
29606
  }
28900
29607
  function paragraph(value) {
28901
29608
  const align = value.align ? ` algn="${escapeAttribute(value.align)}"` : "";
@@ -29015,7 +29722,7 @@ function numberFormatXml(format) {
29015
29722
  }
29016
29723
 
29017
29724
  // chart/write-text.ts
29018
- var textElement = (local, value) => `<c:${local}>${escapeText(value)}</c:${local}>`;
29725
+ var textElement = (local, value) => `<c:${local}>${escapeText2(value)}</c:${local}>`;
29019
29726
  function cachePoints(cache) {
29020
29727
  return cache.points.map((point, position2) => {
29021
29728
  const format = point.formatCode === void 0 ? "" : ` formatCode="${escapeAttribute(point.formatCode)}"`;
@@ -29145,7 +29852,7 @@ function trendlineLabelXml(context, label) {
29145
29852
  function trendlineXml(context, trendline) {
29146
29853
  return elementXml(
29147
29854
  "trendline",
29148
- (trendline.name === void 0 ? "" : `<c:name>${escapeText(trendline.name)}</c:name>`) + shapePropertiesXml(context, trendline.spPr) + valXml("trendlineType", trendline.trendlineType ?? "linear") + valXml("order", trendline.order) + valXml("period", trendline.period) + valXml("forward", trendline.forward) + valXml("backward", trendline.backward) + valXml("intercept", trendline.intercept) + valXml("dispRSqr", trendline.displayRSquared) + valXml("dispEq", trendline.displayEquation) + trendlineLabelXml(context, trendline.label) + raw(context, trendline.extLst)
29855
+ (trendline.name === void 0 ? "" : `<c:name>${escapeText2(trendline.name)}</c:name>`) + shapePropertiesXml(context, trendline.spPr) + valXml("trendlineType", trendline.trendlineType ?? "linear") + valXml("order", trendline.order) + valXml("period", trendline.period) + valXml("forward", trendline.forward) + valXml("backward", trendline.backward) + valXml("intercept", trendline.intercept) + valXml("dispRSqr", trendline.displayRSquared) + valXml("dispEq", trendline.displayEquation) + trendlineLabelXml(context, trendline.label) + raw(context, trendline.extLst)
29149
29856
  );
29150
29857
  }
29151
29858
  function errorBarsXml(context, bars) {
@@ -29890,7 +30597,7 @@ function attributes(entries) {
29890
30597
  }).join("");
29891
30598
  }
29892
30599
  var cxElement = (local, content = "", attrs2 = "") => content ? `<cx:${local}${attrs2}>${content}</cx:${local}>` : `<cx:${local}${attrs2}/>`;
29893
- var cxText = (local, text, attrs2 = "") => text === void 0 ? "" : `<cx:${local}${attrs2}>${escapeText(text)}</cx:${local}>`;
30600
+ var cxText = (local, text, attrs2 = "") => text === void 0 ? "" : `<cx:${local}${attrs2}>${escapeText2(text)}</cx:${local}>`;
29894
30601
  var cxVal = (local, value) => value === void 0 ? "" : `<cx:${local}${attributes([["val", value]])}/>`;
29895
30602
  var formulaXml = (local, formula2) => formula2 ? cxText(local, formula2.formula, attributes([["dir", formula2.direction]])) : "";
29896
30603
  var shapeXml = (context, shape) => shape ? cxElement("spPr", shapePropertiesInnerXml(context, shape)) : "";
@@ -31660,6 +32367,10 @@ var WRAPS = [
31660
32367
  function parsePlacement(anchor) {
31661
32368
  const wrap2 = WRAPS.find(([local]) => firstNS(anchor, WP_NS2, local))?.[1] ?? "none";
31662
32369
  const placement = { wrap: wrap2 };
32370
+ const wrapElement2 = WRAPS.map(([local]) => firstNS(anchor, WP_NS2, local)).find(Boolean);
32371
+ const wrapText = wrapElement2?.getAttribute("wrapText");
32372
+ if (wrapText === "bothSides" || wrapText === "left" || wrapText === "right" || wrapText === "largest")
32373
+ placement.wrapText = wrapText;
31663
32374
  if (anchor.getAttribute("behindDoc") === "1") placement.behindText = true;
31664
32375
  const positionH = firstNS(anchor, WP_NS2, "positionH");
31665
32376
  const relativeFrom = enumValue(
@@ -32091,6 +32802,34 @@ function chartRun(doc, node, image, base, oldDrawing, oldContainer, allocator) {
32091
32802
  return void 0;
32092
32803
  }
32093
32804
 
32805
+ // docx/write-fallback.ts
32806
+ var PT_PER_PX2 = 0.75;
32807
+ function setStyleSize(style, name, pt) {
32808
+ const value = `${Math.round(pt * 100) / 100}pt`;
32809
+ const pattern = new RegExp(`(^|;)\\s*${name}\\s*:\\s*[^;]*`, "i");
32810
+ return pattern.test(style) ? style.replace(pattern, (_all, lead) => `${lead}${name}:${value}`) : style;
32811
+ }
32812
+ function patchFallbackSize(content, image, base) {
32813
+ if (!base || image.widthPx === base.widthPx && image.heightPx === base.heightPx) return;
32814
+ const fallback = Array.from(content.childNodes).filter(isElement).find((node) => node.localName === "Fallback");
32815
+ if (!fallback) return;
32816
+ const stack = [fallback];
32817
+ while (stack.length) {
32818
+ const node = stack.pop();
32819
+ const style = node.getAttribute("style");
32820
+ if (style && /(^|;)\s*width\s*:/i.test(style)) {
32821
+ let next = style;
32822
+ if (image.widthPx !== base.widthPx)
32823
+ next = setStyleSize(next, "width", image.widthPx * PT_PER_PX2);
32824
+ if (image.heightPx !== base.heightPx)
32825
+ next = setStyleSize(next, "height", image.heightPx * PT_PER_PX2);
32826
+ node.setAttribute("style", next);
32827
+ continue;
32828
+ }
32829
+ for (const child8 of Array.from(node.childNodes)) if (isElement(child8)) stack.push(child8);
32830
+ }
32831
+ }
32832
+
32094
32833
  // docx/diagram-document.ts
32095
32834
  function diagramsIn(blocks) {
32096
32835
  const diagrams = [];
@@ -32714,6 +33453,13 @@ function createImageRun(doc, image, base, old, allocator) {
32714
33453
  }
32715
33454
  if (base && oldDrawing && image.shape?.editable && base.shape?.editable) {
32716
33455
  const next = rebuildShapeDrawing(doc, image, oldDrawing);
33456
+ const choice = oldDrawing.parentNode;
33457
+ if (oldContainer?.localName === "AlternateContent" && choice) {
33458
+ choice.replaceChild(next, oldDrawing);
33459
+ patchFallbackSize(oldContainer, image, base);
33460
+ clearNonProperties(node, oldContainer);
33461
+ return node;
33462
+ }
32717
33463
  clearNonProperties(node);
32718
33464
  node.appendChild(next);
32719
33465
  return node;
@@ -33925,15 +34671,15 @@ function runIsSafe(run2) {
33925
34671
  const content = Array.from(run2.childNodes).filter(
33926
34672
  (child8) => isElement(child8) && !named2(child8, "rPr") && !isCachedPageBreak(child8)
33927
34673
  );
33928
- const only = content.length === 1 ? content[0] : void 0;
33929
- if (only && named2(only, "br") && isModeledBreak(only)) return true;
33930
- if (only && ["footnoteReference", "endnoteReference", "footnoteRef", "endnoteRef"].some(
33931
- (name) => named2(only, name)
34674
+ const only2 = content.length === 1 ? content[0] : void 0;
34675
+ if (only2 && named2(only2, "br") && isModeledBreak(only2)) return true;
34676
+ if (only2 && ["footnoteReference", "endnoteReference", "footnoteRef", "endnoteRef"].some(
34677
+ (name) => named2(only2, name)
33932
34678
  ))
33933
34679
  return true;
33934
- if (only && named2(only, "fldChar")) {
33935
- const type = getW(only, "fldCharType") ?? "";
33936
- const data = Array.from(only.childNodes).filter(
34680
+ if (only2 && named2(only2, "fldChar")) {
34681
+ const type = getW(only2, "fldCharType") ?? "";
34682
+ const data = Array.from(only2.childNodes).filter(
33937
34683
  (node) => isElement(node) || Boolean(node.textContent?.trim())
33938
34684
  );
33939
34685
  if (!data.length) return ["begin", "separate", "end"].includes(type);
@@ -34066,6 +34812,10 @@ function parseFormatting(pPr) {
34066
34812
  const line2 = signedTwipValue(getW(spacing2, "line"));
34067
34813
  if (before !== void 0) result.spacingBeforeTwips = before;
34068
34814
  if (after !== void 0) result.spacingAfterTwips = after;
34815
+ const beforeAuto = parseOnOff(getW(spacing2, "beforeAutospacing"));
34816
+ const afterAuto = parseOnOff(getW(spacing2, "afterAutospacing"));
34817
+ if (beforeAuto !== void 0) result.spacingBeforeAuto = beforeAuto;
34818
+ if (afterAuto !== void 0) result.spacingAfterAuto = afterAuto;
34069
34819
  if (line2 !== void 0) result.lineSpacingTwips = line2;
34070
34820
  const rule = getW(spacing2, "lineRule");
34071
34821
  if (rule === "auto" || rule === "exact" || rule === "atLeast") result.lineSpacingRule = rule;
@@ -34195,6 +34945,10 @@ function parseDirectParagraphProperties(props) {
34195
34945
  const line2 = signedTwipValue2(getW(spacing2, "line"));
34196
34946
  if (before !== void 0) paragraph2.spacingBeforeTwips = before;
34197
34947
  if (after !== void 0) paragraph2.spacingAfterTwips = after;
34948
+ const beforeAuto = parseOnOff(getW(spacing2, "beforeAutospacing"));
34949
+ const afterAuto = parseOnOff(getW(spacing2, "afterAutospacing"));
34950
+ if (beforeAuto !== void 0) paragraph2.spacingBeforeAuto = beforeAuto;
34951
+ if (afterAuto !== void 0) paragraph2.spacingAfterAuto = afterAuto;
34198
34952
  if (line2 !== void 0) {
34199
34953
  paragraph2.lineSpacingTwips = line2;
34200
34954
  }
@@ -34226,8 +34980,8 @@ function parseDirectParagraphProperties(props) {
34226
34980
 
34227
34981
  // docx/run-segmentation.ts
34228
34982
  var basisOf = (run2) => run2.restoredRunPropertiesXml ?? run2.sourceRunPropertiesXml;
34229
- function keepsUnmodeledProperties(before, after) {
34230
- const owners = (runs) => runs.flatMap((run2) => Array.from({ length: positionText(run2).length }, () => basisOf(run2)));
34983
+ function keepsUnmodeledProperties(before, after, basis = basisOf) {
34984
+ const owners = (runs) => runs.flatMap((run2) => Array.from({ length: positionText(run2).length }, () => basis(run2)));
34231
34985
  const was = owners(before);
34232
34986
  const now = owners(after);
34233
34987
  const kept = (from, to, shift) => {
@@ -34261,13 +35015,22 @@ function runsToWriteAnew(paragraph2, base, slots) {
34261
35015
  return !remaining.length || remaining.every((run2) => run2.restoredRunPropertiesXml || run2.sourceRunPropertiesXml);
34262
35016
  }))
34263
35017
  return none;
34264
- if (paragraph2.runs.every(
34265
- (run2) => !run2.image && !run2.equation && (run2.restoredRunPropertiesXml || run2.sourceRunPropertiesXml)
34266
- ))
34267
- return none;
34268
35018
  const sameText = paragraph2.runs.map((run2) => run2.text).join("") === base.runs.map((run2) => run2.text).join("");
34269
35019
  const sameBoundaries = paragraph2.runs.length === base.runs.length && paragraph2.runs.every((run2, index) => run2.text === base.runs[index]?.text);
34270
35020
  if (sameBoundaries || !sameText && paragraph2.runs.length === base.runs.length) return none;
35021
+ if (paragraph2.runs.every(
35022
+ (run2) => !run2.image && !run2.equation && (run2.restoredRunPropertiesXml || run2.sourceRunPropertiesXml)
35023
+ )) {
35024
+ if (keepsUnmodeledProperties(
35025
+ base.runs,
35026
+ paragraph2.runs,
35027
+ (run2) => run2.sourceRunPropertiesXml ?? run2.restoredRunPropertiesXml
35028
+ ))
35029
+ return none;
35030
+ throw new Error(
35031
+ `Cannot edit paragraph ${paragraph2.id}: changing run boundaries could drop unsupported run properties because the merged runs carry different unsupported properties. The original DOCX package remains unchanged.`
35032
+ );
35033
+ }
34271
35034
  const object = (run2) => Boolean(run2.image || run2.equation);
34272
35035
  if (!paragraph2.runs.some(object) && !base.runs.some(object) && keepsUnmodeledProperties(base.runs, paragraph2.runs))
34273
35036
  return new Set(
@@ -35404,14 +36167,14 @@ async function applyNumberingCatalog(zip, model, binding) {
35404
36167
  }
35405
36168
 
35406
36169
  // docx/style-numbering-package.ts
35407
- var STYLES_PART = "word/styles.xml";
35408
- var AFTER_PPR = ["rPr", "tblPr", "trPr", "tcPr", "tblStylePr"];
36170
+ var STYLES_PART2 = "word/styles.xml";
36171
+ var AFTER_PPR2 = ["rPr", "tblPr", "trPr", "tcPr", "tblStylePr"];
35409
36172
  var withoutNumbering = (catalog) => catalog ? {
35410
36173
  ...catalog,
35411
36174
  styles: Object.fromEntries(
35412
36175
  Object.entries(catalog.styles).map(([id, style]) => {
35413
- const { numbering: _numbering, ...rest } = style;
35414
- return [id, rest];
36176
+ const { numbering: _numbering, formatting, ...rest } = style;
36177
+ return [id, { ...rest, formatting: unwritableFormatting(formatting) }];
35415
36178
  })
35416
36179
  )
35417
36180
  } : void 0;
@@ -35424,7 +36187,7 @@ function setNumPr(style, numbering) {
35424
36187
  if (!numbering && !pPr) return;
35425
36188
  if (!pPr) {
35426
36189
  pPr = makeW(doc, "pPr");
35427
- const anchor = elementsOf2(style).find((child8) => AFTER_PPR.includes(child8.localName)) ?? null;
36190
+ const anchor = elementsOf2(style).find((child8) => AFTER_PPR2.includes(child8.localName)) ?? null;
35428
36191
  style.insertBefore(pPr, anchor);
35429
36192
  }
35430
36193
  for (const existing of children2(pPr, "numPr")) pPr.removeChild(existing);
@@ -35448,7 +36211,7 @@ async function applyStyleNumbering(zip, model, base) {
35448
36211
  (id) => JSON.stringify(next[id]?.numbering) !== JSON.stringify(prior[id]?.numbering)
35449
36212
  );
35450
36213
  if (!changed.length) return;
35451
- const file = zip.file(STYLES_PART);
36214
+ const file = zip.file(STYLES_PART2);
35452
36215
  if (!file) throw new Error("Cannot link styles to a list: the package has no styles.xml.");
35453
36216
  const doc = parseXml2(await file.async("string"));
35454
36217
  const styles = children2(doc.documentElement, "style");
@@ -35459,7 +36222,7 @@ async function applyStyleNumbering(zip, model, base) {
35459
36222
  if (!style) throw new Error(`Cannot link style "${id}" to a list: it is not in styles.xml.`);
35460
36223
  setNumPr(style, next[id]?.numbering);
35461
36224
  }
35462
- zip.file(STYLES_PART, buildXml(doc));
36225
+ zip.file(STYLES_PART2, buildXml(doc));
35463
36226
  }
35464
36227
 
35465
36228
  // docx/write-header-footer.ts
@@ -36999,7 +37762,7 @@ function headerFooterResults(model) {
36999
37762
  return void 0;
37000
37763
  }
37001
37764
  }
37002
- async function saveDocx(model, pendingMedia) {
37765
+ async function saveDocx(model, pendingMedia, options) {
37003
37766
  const ids = /* @__PURE__ */ new Set();
37004
37767
  for (const block of model.blocks) {
37005
37768
  if (ids.has(block.id)) throw new Error(`Duplicate document block id: ${block.id}`);
@@ -37090,6 +37853,7 @@ async function saveDocx(model, pendingMedia) {
37090
37853
  await applyNumberingCatalog(zip, model, binding);
37091
37854
  await applyCoreProperties(zip, model.properties, binding?.base.properties);
37092
37855
  if (binding) await applyStyleNumbering(zip, model, binding.base);
37856
+ if (binding) await applyStyleFormatting(zip, model, binding.base);
37093
37857
  if (model.compatibilityMode !== binding?.base.compatibilityMode)
37094
37858
  await applyCompatibilityMode(zip, model.compatibilityMode);
37095
37859
  if (Boolean(model.evenAndOddHeaders) !== Boolean(binding?.base.evenAndOddHeaders))
@@ -37121,6 +37885,8 @@ async function saveDocx(model, pendingMedia) {
37121
37885
  }
37122
37886
  if (JSON.stringify(model.comments ?? []) !== JSON.stringify(binding?.base.comments ?? []))
37123
37887
  await applyComments(zip, model.comments ?? []);
37888
+ if (binding) await applyDataBindings(zip, model, binding.base, binding.context.sourceXml);
37889
+ if (binding) await stampModified(zip, options?.modified);
37124
37890
  dropAddedFolders(zip, sourceEntries);
37125
37891
  return zip.generateAsync({ type: "uint8array", compression: "DEFLATE" });
37126
37892
  }
@@ -37176,8 +37942,11 @@ function parseCell(cell2, parseParagraph3, id, control) {
37176
37942
  const element4 = child8;
37177
37943
  if (element4.namespaceURI !== WORD_NS) return [];
37178
37944
  if (element4.localName === "p") return [result.paragraphs[paragraphIndex++]];
37179
- if (element4.localName === "tbl")
37180
- return [parseTable(element4, `${id}-nested${tableIndex++}`, parseParagraph3)];
37945
+ if (element4.localName === "tbl") {
37946
+ const inner = parseTable(element4, `${id}-nested${tableIndex++}`, parseParagraph3);
37947
+ markRestructurable(inner, element4);
37948
+ return [inner];
37949
+ }
37181
37950
  return [];
37182
37951
  }
37183
37952
  );
@@ -37233,6 +38002,9 @@ function parseRowProperties(row) {
37233
38002
  if (onOffElement(first2(trPr, "tblHeader"))) result.header = true;
37234
38003
  return result;
37235
38004
  }
38005
+ function markRestructurable(table, node) {
38006
+ if (canRestructureTable(node) && tableGrid(table)) table.restructurable = true;
38007
+ }
37236
38008
  function parseTable(node, id, parseParagraph3) {
37237
38009
  const rowEntries = flatRows(node);
37238
38010
  const rows = rowEntries.map(
@@ -37273,6 +38045,7 @@ function parseTable(node, id, parseParagraph3) {
37273
38045
  return properties;
37274
38046
  });
37275
38047
  if (rowProperties.some((row) => Object.keys(row).length)) table.rowProperties = rowProperties;
38048
+ if (!table.structureEditable) markRestructurable(table, node);
37276
38049
  return table;
37277
38050
  }
37278
38051
 
@@ -37406,23 +38179,23 @@ function parseRun2(node, revision) {
37406
38179
  let noteSeparator;
37407
38180
  let fieldChar;
37408
38181
  const fieldCode = content.length > 0 && content.every((child8) => named2(child8, "instrText")) ? content.map((child8) => textContent(child8)).join("") : void 0;
37409
- const only = content.length === 1 ? content[0] : void 0;
37410
- if (only) {
37411
- if (named2(only, "br")) {
37412
- const kind = classifyBreak(only);
38182
+ const only2 = content.length === 1 ? content[0] : void 0;
38183
+ if (only2) {
38184
+ if (named2(only2, "br")) {
38185
+ const kind = classifyBreak(only2);
37413
38186
  if (kind === "page" || kind === "column") breakKind = kind;
37414
- } else if (named2(only, "footnoteReference")) {
37415
- const id = getW(only, "id");
38187
+ } else if (named2(only2, "footnoteReference")) {
38188
+ const id = getW(only2, "id");
37416
38189
  if (id) noteReference = { kind: "footnote", id };
37417
- } else if (named2(only, "endnoteReference")) {
37418
- const id = getW(only, "id");
38190
+ } else if (named2(only2, "endnoteReference")) {
38191
+ const id = getW(only2, "id");
37419
38192
  if (id) noteReference = { kind: "endnote", id };
37420
- } else if (named2(only, "footnoteRef")) noteMark = "footnote";
37421
- else if (named2(only, "endnoteRef")) noteMark = "endnote";
37422
- else if (named2(only, "separator")) noteSeparator = "separator";
37423
- else if (named2(only, "continuationSeparator")) noteSeparator = "continuationSeparator";
37424
- else if (named2(only, "fldChar")) {
37425
- const type = getW(only, "fldCharType");
38193
+ } else if (named2(only2, "footnoteRef")) noteMark = "footnote";
38194
+ else if (named2(only2, "endnoteRef")) noteMark = "endnote";
38195
+ else if (named2(only2, "separator")) noteSeparator = "separator";
38196
+ else if (named2(only2, "continuationSeparator")) noteSeparator = "continuationSeparator";
38197
+ else if (named2(only2, "fldChar")) {
38198
+ const type = getW(only2, "fldCharType");
37426
38199
  if (type === "begin" || type === "separate" || type === "end") fieldChar = type;
37427
38200
  }
37428
38201
  }
@@ -37444,9 +38217,9 @@ function parseRun2(node, revision) {
37444
38217
  if (noteSeparator) run2.noteSeparator = noteSeparator;
37445
38218
  if (fieldChar) {
37446
38219
  run2.fieldChar = fieldChar;
37447
- const flags = parseFieldFlags(only);
38220
+ const flags = parseFieldFlags(only2);
37448
38221
  if (flags) run2.fieldFlags = flags;
37449
- const data = fieldChar === "begin" ? first2(only, "ffData") : void 0;
38222
+ const data = fieldChar === "begin" ? first2(only2, "ffData") : void 0;
37450
38223
  const formField = data && parseFormField(data);
37451
38224
  if (formField) run2.formField = formField;
37452
38225
  }
@@ -37786,6 +38559,7 @@ function parseSettings(xml) {
37786
38559
  );
37787
38560
  return {
37788
38561
  ...compatibilityMode !== void 0 && Number.isInteger(compatibilityMode) && compatibilityMode > 0 ? { compatibilityMode } : {},
38562
+ ...onOffElement(first2(first2(root, "compat"), "doNotUseHTMLParagraphAutoSpacing")) === true ? { doNotUseHtmlParagraphAutoSpacing: true } : {},
37789
38563
  evenAndOddHeaders: onOffElement(first2(root, "evenAndOddHeaders")) === true,
37790
38564
  autoHyphenation: onOffElement(first2(root, "autoHyphenation")) === true,
37791
38565
  ...footnoteNumFmt ? { footnoteNumFmt } : {},
@@ -37866,6 +38640,7 @@ async function parseDocumentParts(zip, body, blocks, drawings) {
37866
38640
  return {
37867
38641
  sections,
37868
38642
  ...settings.compatibilityMode !== void 0 ? { compatibilityMode: settings.compatibilityMode } : {},
38643
+ ...settings.doNotUseHtmlParagraphAutoSpacing ? { doNotUseHtmlParagraphAutoSpacing: true } : {},
37869
38644
  ...footnotes ? { footnotes } : {},
37870
38645
  ...footnoteSeparators ? { footnoteSeparators } : {},
37871
38646
  ...endnotes ? { endnotes } : {},
@@ -38163,6 +38938,7 @@ async function readPackage(input) {
38163
38938
  const parts = await parseDocumentParts(zip, body, blocks, drawings);
38164
38939
  model.sections = parts.sections;
38165
38940
  if (parts.compatibilityMode !== void 0) model.compatibilityMode = parts.compatibilityMode;
38941
+ if (parts.doNotUseHtmlParagraphAutoSpacing) model.doNotUseHtmlParagraphAutoSpacing = true;
38166
38942
  if (parts.footnotes) model.footnotes = parts.footnotes;
38167
38943
  if (parts.footnoteSeparators) model.footnoteSeparators = parts.footnoteSeparators;
38168
38944
  if (parts.endnotes) model.endnotes = parts.endnotes;
@@ -38172,14 +38948,16 @@ async function readPackage(input) {
38172
38948
  if (parts.autoHyphenation) model.autoHyphenation = true;
38173
38949
  const coreFile = zip.file("docProps/core.xml");
38174
38950
  if (coreFile) {
38175
- const properties = parseCoreProperties(await coreFile.async("string"));
38951
+ const properties = parseCoreProperties2(await coreFile.async("string"));
38176
38952
  if (properties) model.properties = properties;
38177
38953
  }
38178
38954
  await readPlaceholderTexts(zip, drawings.rels, model);
38179
38955
  const pageColor = parsePageBackground(document.documentElement);
38180
38956
  if (pageColor) model.pageColor = pageColor;
38181
38957
  model.warnings.push(...parts.warnings);
38182
- if (blocks.some((block) => block.type === "table" && !block.structureEditable))
38958
+ if (blocks.some(
38959
+ (block) => block.type === "table" && !block.structureEditable && !block.restructurable
38960
+ ))
38183
38961
  model.warnings.push(
38184
38962
  "Merged, nested, or complex tables can be read, but their row and column structure cannot be edited safely."
38185
38963
  );
@@ -38205,7 +38983,7 @@ async function readPackage(input) {
38205
38983
  (block) => block.type === "table" && block.rows.some((row) => row.some((cell2) => cell2.nestedTables?.length))
38206
38984
  ))
38207
38985
  model.warnings.push(
38208
- "Text in nested tables is editable; the grid, merges and formatting of a nested table are preserved but cannot be changed."
38986
+ "Text and structure (rows, columns, merged and split cells) of nested tables are editable; their borders, shading and other formatting are preserved but cannot be changed."
38209
38987
  );
38210
38988
  const pictureBlocks = documentDrawingBlocks({ ...model, blocks });
38211
38989
  await resolveDocumentDiagrams(
@@ -38243,9 +39021,9 @@ async function loadDocx(input) {
38243
39021
  return {
38244
39022
  model,
38245
39023
  media,
38246
- save: (next = model, pendingMedia) => {
39024
+ save: (next = model, pendingMedia, options) => {
38247
39025
  if (next !== model) remember(next, context);
38248
- return saveDocx(next, pendingMedia);
39026
+ return saveDocx(next, pendingMedia, options);
38249
39027
  }
38250
39028
  };
38251
39029
  }
@@ -38538,7 +39316,7 @@ function processCompoundFileStream(input, path3, replacement) {
38538
39316
  return reject();
38539
39317
  let parent = root, target;
38540
39318
  for (let partIndex = 0; partIndex < path3.length; partIndex++) {
38541
- const matches = [], seen = /* @__PURE__ */ new Set();
39319
+ const matches2 = [], seen = /* @__PURE__ */ new Set();
38542
39320
  const visit = (id) => {
38543
39321
  if (id === NIL)
38544
39322
  return;
@@ -38550,13 +39328,13 @@ function processCompoundFileStream(input, path3, replacement) {
38550
39328
  throw new Error("Invalid directory ID");
38551
39329
  visit(e.left);
38552
39330
  if (e.name.toLocaleLowerCase() === path3[partIndex].toLocaleLowerCase())
38553
- matches.push(e);
39331
+ matches2.push(e);
38554
39332
  visit(e.right);
38555
39333
  };
38556
39334
  visit(parent.child);
38557
- if (matches.length !== 1)
39335
+ if (matches2.length !== 1)
38558
39336
  return reject();
38559
- target = matches[0];
39337
+ target = matches2[0];
38560
39338
  if (partIndex < path3.length - 1) {
38561
39339
  if (target.type !== 1)
38562
39340
  return reject();
@@ -38714,7 +39492,7 @@ function findSlot(slots, path3) {
38714
39492
  if (parents.has(parent.id))
38715
39493
  throw new Error("Cyclic storage hierarchy");
38716
39494
  parents.add(parent.id);
38717
- const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches = [];
39495
+ const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches2 = [];
38718
39496
  while (stack.length) {
38719
39497
  const id = stack.pop();
38720
39498
  if (id === FREE)
@@ -38726,12 +39504,12 @@ function findSlot(slots, path3) {
38726
39504
  if (!slot2)
38727
39505
  throw new Error("Missing directory slot");
38728
39506
  if (slot2.name.toLocaleLowerCase() === path3[part].toLocaleLowerCase())
38729
- matches.push(slot2);
39507
+ matches2.push(slot2);
38730
39508
  stack.push(slot2.left, slot2.right);
38731
39509
  }
38732
- if (matches.length !== 1)
39510
+ if (matches2.length !== 1)
38733
39511
  throw new Error("Missing or ambiguous stream");
38734
- parent = matches[0];
39512
+ parent = matches2[0];
38735
39513
  if (parent.type !== (part === path3.length - 1 ? 2 : 1))
38736
39514
  throw new Error("Invalid storage path");
38737
39515
  }
@@ -39023,7 +39801,7 @@ function findSlot2(slots, path3) {
39023
39801
  if (parents.has(parent.id))
39024
39802
  throw new Error("Cyclic storage hierarchy");
39025
39803
  parents.add(parent.id);
39026
- const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches = [];
39804
+ const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches2 = [];
39027
39805
  while (stack.length) {
39028
39806
  const id = stack.pop();
39029
39807
  if (id === FREE3)
@@ -39035,12 +39813,12 @@ function findSlot2(slots, path3) {
39035
39813
  if (!slot2)
39036
39814
  throw new Error("Missing directory slot");
39037
39815
  if (slot2.name.toLocaleLowerCase() === path3[part].toLocaleLowerCase())
39038
- matches.push(slot2);
39816
+ matches2.push(slot2);
39039
39817
  stack.push(slot2.left, slot2.right);
39040
39818
  }
39041
- if (matches.length !== 1)
39819
+ if (matches2.length !== 1)
39042
39820
  throw new Error("Missing or ambiguous stream");
39043
- parent = matches[0];
39821
+ parent = matches2[0];
39044
39822
  if (parent.type !== (part === path3.length - 1 ? 2 : 1))
39045
39823
  throw new Error("Invalid storage path");
39046
39824
  }