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
@@ -186,7 +186,7 @@ function normalizePath(path3, rootName) {
186
186
  }
187
187
  function child(entries, parentId, name) {
188
188
  const children3 = entries.filter((entry2) => entry2.parentId === parentId && entry2.path !== void 0);
189
- const pick2 = (matches) => matches.length === 1 ? matches[0] : void 0;
189
+ const pick2 = (matches2) => matches2.length === 1 ? matches2[0] : void 0;
190
190
  const exact = children3.filter((entry2) => entry2.name === name);
191
191
  if (exact.length)
192
192
  return pick2(exact);
@@ -3198,6 +3198,8 @@ async function encryptStandard(packageData, password, options = {}) {
3198
3198
  var NS = {
3199
3199
  /** WordprocessingML main. */
3200
3200
  w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
3201
+ /** PresentationML main. */
3202
+ p: "http://schemas.openxmlformats.org/presentationml/2006/main",
3201
3203
  /** SpreadsheetML main. */
3202
3204
  x: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
3203
3205
  /** DrawingML main. */
@@ -3212,6 +3214,12 @@ var NS = {
3212
3214
  dgm: "http://schemas.openxmlformats.org/drawingml/2006/diagram",
3213
3215
  /** Office 2007+ diagram drawing (`dsp`). */
3214
3216
  dsp: "http://schemas.microsoft.com/office/drawing/2008/diagram",
3217
+ /** DrawingML Word drawing (`wp:inline`, `wp:anchor`). */
3218
+ wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
3219
+ /** DrawingML picture. */
3220
+ pic: "http://schemas.openxmlformats.org/drawingml/2006/picture",
3221
+ /** Word 2010 shapes (`wps`). */
3222
+ wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
3215
3223
  /** Relationships (`r:id`, `r:embed`). */
3216
3224
  r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
3217
3225
  /** Markup compatibility (`mc:AlternateContent`). */
@@ -3219,7 +3227,42 @@ var NS = {
3219
3227
  /** OPC relationships part. */
3220
3228
  rels: "http://schemas.openxmlformats.org/package/2006/relationships",
3221
3229
  /** OPC content types part. */
3222
- contentTypes: "http://schemas.openxmlformats.org/package/2006/content-types"};
3230
+ contentTypes: "http://schemas.openxmlformats.org/package/2006/content-types",
3231
+ /** Office Math. */
3232
+ m: "http://schemas.openxmlformats.org/officeDocument/2006/math",
3233
+ /** Core properties. */
3234
+ cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
3235
+ /** Dublin Core elements. */
3236
+ dc: "http://purl.org/dc/elements/1.1/",
3237
+ /** Legacy VML. */
3238
+ v: "urn:schemas-microsoft-com:vml",
3239
+ /** Office VML extensions. */
3240
+ o: "urn:schemas-microsoft-com:office:office",
3241
+ /** Word VML extensions. */
3242
+ w10: "urn:schemas-microsoft-com:office:word",
3243
+ /** SpreadsheetML drawing (`xdr:wsDr`, cell anchors). */
3244
+ xdr: "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
3245
+ /** SpreadsheetML 2009 extensions (`x14:conditionalFormatting`, `x14:dataBar`). */
3246
+ x14: "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",
3247
+ /** SpreadsheetML 2009 attribute extensions (`x14ac:dyDescent`). */
3248
+ x14ac: "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac",
3249
+ /** SpreadsheetML revision ids (`xr:uid`). */
3250
+ xr: "http://schemas.microsoft.com/office/spreadsheetml/2014/revision",
3251
+ /** Excel threaded comments and persons. */
3252
+ tc: "http://schemas.microsoft.com/office/spreadsheetml/2018/threadedcomments",
3253
+ /** Legacy VML Excel client data (`x:ClientData`). */
3254
+ xv: "urn:schemas-microsoft-com:office:excel",
3255
+ /** Extended (app) properties. */
3256
+ extendedProperties: "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties",
3257
+ /** Dublin Core terms (`dcterms:created`). */
3258
+ dcterms: "http://purl.org/dc/terms/",
3259
+ /** Custom document properties (`docProps/custom.xml`). */
3260
+ customProperties: "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties",
3261
+ /** Document property variant types (`vt:lpwstr`, `vt:vector`). */
3262
+ vt: "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes",
3263
+ /** XML itself (`xml:space`). */
3264
+ xml: "http://www.w3.org/XML/1998/namespace"
3265
+ };
3223
3266
 
3224
3267
  // xml/xml.ts
3225
3268
  var DEFAULT_XML_LIMITS = {
@@ -3403,12 +3446,12 @@ function childrenNamed(parent, localName2) {
3403
3446
  return found;
3404
3447
  }
3405
3448
  function singleChild(parent, localName2, mustExist) {
3406
- const matches = childrenNamed(parent, localName2);
3407
- if (matches.length > 1) throw new Error(`The EncryptionInfo has several ${localName2} elements.`);
3408
- if (matches.length === 0 && mustExist) {
3449
+ const matches2 = childrenNamed(parent, localName2);
3450
+ if (matches2.length > 1) throw new Error(`The EncryptionInfo has several ${localName2} elements.`);
3451
+ if (matches2.length === 0 && mustExist) {
3409
3452
  throw new Error(`The EncryptionInfo has no ${localName2} element.`);
3410
3453
  }
3411
- return matches[0];
3454
+ return matches2[0];
3412
3455
  }
3413
3456
  function required(element4, attr3) {
3414
3457
  const value = element4.getAttribute(attr3);
@@ -3884,6 +3927,233 @@ async function openZip(input, limits = {}) {
3884
3927
  return guardZip(await JSZip__default.default.loadAsync(bytes), limits);
3885
3928
  }
3886
3929
 
3930
+ // opc/properties/patch.ts
3931
+ var XMLNS = "http://www.w3.org/2000/xmlns/";
3932
+ function tagEnd(xml, from) {
3933
+ let quote = "";
3934
+ for (let i2 = from + 1; i2 < xml.length; i2++) {
3935
+ const ch = xml[i2];
3936
+ if (quote) {
3937
+ if (ch === quote) quote = "";
3938
+ } else if (ch === '"' || ch === "'") quote = ch;
3939
+ else if (ch === ">") return i2 + 1;
3940
+ }
3941
+ throw new Error("Unterminated tag in property part");
3942
+ }
3943
+ function skipMarkup(xml, at) {
3944
+ if (xml.startsWith("<!--", at)) return xml.indexOf("-->", at) + 3;
3945
+ if (xml.startsWith("<![CDATA[", at)) return xml.indexOf("]]>", at) + 3;
3946
+ if (xml.startsWith("<?", at)) return xml.indexOf("?>", at) + 2;
3947
+ return void 0;
3948
+ }
3949
+ function scan(xml) {
3950
+ let i2 = 0;
3951
+ let rootStart = -1;
3952
+ while (rootStart < 0) {
3953
+ const lt = xml.indexOf("<", i2);
3954
+ if (lt < 0) throw new Error("Property part has no root element");
3955
+ const skipped = skipMarkup(xml, lt);
3956
+ if (skipped !== void 0) i2 = skipped;
3957
+ else rootStart = lt;
3958
+ }
3959
+ const openEnd = tagEnd(xml, rootStart);
3960
+ if (xml[openEnd - 2] === "/") {
3961
+ const root = {
3962
+ start: rootStart,
3963
+ openEnd,
3964
+ closeStart: openEnd,
3965
+ end: openEnd,
3966
+ selfClosing: true
3967
+ };
3968
+ return { root, children: [] };
3969
+ }
3970
+ const children3 = [];
3971
+ let depth = 0;
3972
+ let child8;
3973
+ i2 = openEnd;
3974
+ for (; ; ) {
3975
+ const lt = xml.indexOf("<", i2);
3976
+ if (lt < 0) throw new Error("Property part root is not closed");
3977
+ const skipped = skipMarkup(xml, lt);
3978
+ if (skipped !== void 0) {
3979
+ i2 = skipped;
3980
+ continue;
3981
+ }
3982
+ const end = tagEnd(xml, lt);
3983
+ i2 = end;
3984
+ if (xml[lt + 1] === "/") {
3985
+ if (depth === 0) {
3986
+ const root = { start: rootStart, openEnd, closeStart: lt, end, selfClosing: false };
3987
+ return { root, children: children3 };
3988
+ }
3989
+ depth--;
3990
+ if (depth === 0 && child8)
3991
+ children3.push({ ...child8, closeStart: lt, end, selfClosing: false });
3992
+ } else if (xml[end - 2] === "/") {
3993
+ if (depth === 0)
3994
+ children3.push({ start: lt, openEnd: end, closeStart: end, end, selfClosing: true });
3995
+ } else {
3996
+ if (depth === 0) child8 = { start: lt, openEnd: end };
3997
+ depth++;
3998
+ }
3999
+ }
4000
+ }
4001
+ var escapeText = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\r/g, "&#xD;");
4002
+ var qualifiedName = (xml, span) => /^<([^\s/>]+)/.exec(xml.slice(span.start, span.openEnd))?.[1] ?? "";
4003
+ var PartPatch = class {
4004
+ constructor(xml, rootElement) {
4005
+ this.xml = xml;
4006
+ const { root, children: children3 } = scan(xml);
4007
+ const kids = elements(rootElement);
4008
+ if (kids.length !== children3.length) throw new Error("Property part markup is not supported");
4009
+ kids.forEach((kid, index) => this.spans.set(kid, children3[index]));
4010
+ this.root = root;
4011
+ for (const attribute2 of Array.from(rootElement.attributes)) {
4012
+ if (attribute2.name === "xmlns") this.defaultNs = attribute2.value;
4013
+ else if (attribute2.namespaceURI === XMLNS || attribute2.name.startsWith("xmlns:"))
4014
+ this.prefixes.set(attribute2.value, attribute2.localName);
4015
+ }
4016
+ }
4017
+ xml;
4018
+ root;
4019
+ spans = /* @__PURE__ */ new Map();
4020
+ edits = [];
4021
+ appended = [];
4022
+ prefixes = /* @__PURE__ */ new Map();
4023
+ defaultNs = null;
4024
+ seq = 0;
4025
+ add(start, end, text) {
4026
+ this.edits.push({ start, end, text, seq: this.seq++ });
4027
+ }
4028
+ span(element4) {
4029
+ const span = this.spans.get(element4);
4030
+ if (!span) throw new Error("Element is not a child of the patched root");
4031
+ return span;
4032
+ }
4033
+ /** The prefix bound to `ns` on the root, declaring `preferred` for it when none is. */
4034
+ prefix(ns, preferred) {
4035
+ const known = this.prefixes.get(ns);
4036
+ if (known !== void 0) return known;
4037
+ const taken = new Set(this.prefixes.values());
4038
+ let prefix2 = preferred;
4039
+ for (let n = 1; taken.has(prefix2); n++) prefix2 = `${preferred}${n}`;
4040
+ this.prefixes.set(ns, prefix2);
4041
+ const at = this.root.openEnd - (this.root.selfClosing ? 2 : 1);
4042
+ this.add(at, at, ` xmlns:${prefix2}="${ns}"`);
4043
+ return prefix2;
4044
+ }
4045
+ /** `local` qualified for an element in `ns`: unprefixed in the default namespace. */
4046
+ qualify(ns, local, preferred) {
4047
+ return this.defaultNs === ns && !this.prefixes.has(ns) ? local : `${this.prefix(ns, preferred)}:${local}`;
4048
+ }
4049
+ /** Replaces the element's content, keeping its start tag (and attributes) as written. */
4050
+ setContent(element4, content) {
4051
+ const span = this.span(element4);
4052
+ if (span.selfClosing)
4053
+ this.add(span.openEnd - 2, span.openEnd, `>${content}</${qualifiedName(this.xml, span)}>`);
4054
+ else this.add(span.openEnd, span.closeStart, content);
4055
+ }
4056
+ /** Adds ` name="value"` text to the element's start tag. */
4057
+ addAttribute(element4, attribute2) {
4058
+ const span = this.span(element4);
4059
+ const at = span.openEnd - (span.selfClosing ? 2 : 1);
4060
+ this.add(at, at, attribute2);
4061
+ }
4062
+ remove(element4) {
4063
+ const span = this.span(element4);
4064
+ this.add(span.start, span.end, "");
4065
+ }
4066
+ /** Inserts `markup` before `before`, or as the root's last child. */
4067
+ insert(markup, before) {
4068
+ if (before) {
4069
+ const at = this.span(before).start;
4070
+ this.add(at, at, markup);
4071
+ } else this.appended.push(markup);
4072
+ }
4073
+ toString() {
4074
+ const edits = [...this.edits];
4075
+ if (this.appended.length) {
4076
+ const text = this.appended.join("");
4077
+ const root = this.root;
4078
+ if (root.selfClosing) {
4079
+ const name = qualifiedName(this.xml, root);
4080
+ edits.push({
4081
+ start: root.end - 2,
4082
+ end: root.end,
4083
+ text: `>${text}</${name}>`,
4084
+ seq: this.seq
4085
+ });
4086
+ } else edits.push({ start: root.closeStart, end: root.closeStart, text, seq: this.seq });
4087
+ }
4088
+ edits.sort((a2, b) => a2.start - b.start || a2.end - a2.start - (b.end - b.start) || a2.seq - b.seq);
4089
+ let out = "";
4090
+ let at = 0;
4091
+ for (const edit of edits) {
4092
+ out += this.xml.slice(at, edit.start) + edit.text;
4093
+ at = Math.max(at, edit.end);
4094
+ }
4095
+ return out + this.xml.slice(at);
4096
+ }
4097
+ };
4098
+
4099
+ // opc/properties/core.ts
4100
+ var XSI = "http://www.w3.org/2001/XMLSchema-instance";
4101
+ var FIELDS = [
4102
+ ["title", "dc", false],
4103
+ ["subject", "dc", false],
4104
+ ["creator", "dc", false],
4105
+ ["keywords", "cp", false],
4106
+ ["description", "dc", false],
4107
+ ["lastModifiedBy", "cp", false],
4108
+ ["created", "dcterms", true],
4109
+ ["modified", "dcterms", true],
4110
+ ["category", "cp", false],
4111
+ ["contentStatus", "cp", false],
4112
+ ["revision", "cp", false],
4113
+ ["language", "dc", false],
4114
+ ["identifier", "dc", false],
4115
+ ["lastPrinted", "cp", false],
4116
+ ["version", "cp", false]
4117
+ ];
4118
+ FIELDS.map(([field]) => field);
4119
+ var EMPTY_CORE = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
4120
+ <cp:coreProperties xmlns:cp="${NS.cp}" xmlns:dc="${NS.dc}" xmlns:dcterms="${NS.dcterms}" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="${XSI}"/>`;
4121
+ function parseCoreProperties(xml) {
4122
+ const out = {};
4123
+ if (!xml) return out;
4124
+ const root = parseXml(xml, { label: "core properties" }).documentElement;
4125
+ for (const [field, prefix2] of FIELDS) {
4126
+ const text = first(root, field, NS[prefix2])?.textContent ?? "";
4127
+ if (text !== "") out[field] = text;
4128
+ }
4129
+ return out;
4130
+ }
4131
+ var formatW3cdtf = (date) => date.toISOString().replace(/\.\d{3}Z$/, "Z");
4132
+ function writeCoreProperties(props, sourceXml) {
4133
+ const xml = sourceXml ?? EMPTY_CORE;
4134
+ const root = parseXml(xml, { label: "core properties" }).documentElement;
4135
+ const patch = new PartPatch(xml, root);
4136
+ for (const [field, prefix2, isDate] of FIELDS) {
4137
+ const ns = NS[prefix2];
4138
+ const value = props[field];
4139
+ const element4 = first(root, field, ns);
4140
+ if (value === void 0 || value === "") {
4141
+ if (element4 && (element4.textContent ?? "") !== "") patch.remove(element4);
4142
+ continue;
4143
+ }
4144
+ if (element4 && element4.textContent === value) continue;
4145
+ const typed = () => ` ${patch.prefix(XSI, "xsi")}:type="${patch.prefix(NS.dcterms, "dcterms")}:W3CDTF"`;
4146
+ if (element4) {
4147
+ if (isDate && !element4.getAttributeNS(XSI, "type")) patch.addAttribute(element4, typed());
4148
+ patch.setContent(element4, escapeText(value));
4149
+ continue;
4150
+ }
4151
+ const name = patch.qualify(ns, field, prefix2);
4152
+ patch.insert(`<${name}${isDate ? typed() : ""}>${escapeText(value)}</${name}>`);
4153
+ }
4154
+ return patch.toString();
4155
+ }
4156
+
3887
4157
  // docx/zip-parts.ts
3888
4158
  var DOCUMENT_RELS_PATH = "word/_rels/document.xml.rels";
3889
4159
  var ensureDocumentRelationship = (zip, type, target) => ensureRelationship(zip, DOCUMENT_RELS_PATH, type, target);
@@ -3899,13 +4169,13 @@ var first2 = (parent, local) => first(parent, local, WORD_NS);
3899
4169
  var getW = (element4, local) => attr(element4, local, WORD_NS, "w");
3900
4170
  var getR = (element4, local) => relAttr(element4, local);
3901
4171
  var makeW = (doc, local) => doc.createElementNS(WORD_NS, `w:${local}`);
3902
- var XMLNS = "http://www.w3.org/2000/xmlns/";
4172
+ var XMLNS2 = "http://www.w3.org/2000/xmlns/";
3903
4173
  function importElement(doc, element4) {
3904
4174
  const imported = doc.importNode(element4, true);
3905
4175
  const root = doc.documentElement;
3906
4176
  const drop = (node) => {
3907
4177
  for (const attribute2 of Array.from(node.attributes))
3908
- if (attribute2.namespaceURI === XMLNS && root?.lookupNamespaceURI(attribute2.prefix ? attribute2.localName : null) === attribute2.value)
4178
+ if (attribute2.namespaceURI === XMLNS2 && root?.lookupNamespaceURI(attribute2.prefix ? attribute2.localName : null) === attribute2.value)
3909
4179
  node.removeAttributeNode(attribute2);
3910
4180
  for (const child8 of Array.from(node.childNodes)) if (isElement(child8)) drop(child8);
3911
4181
  };
@@ -3936,7 +4206,7 @@ var PREFIX = {
3936
4206
  };
3937
4207
  var CORE_TYPE = "application/vnd.openxmlformats-package.core-properties+xml";
3938
4208
  var CORE_REL = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
3939
- function parseCoreProperties(xml) {
4209
+ function parseCoreProperties2(xml) {
3940
4210
  const root = parseXml2(xml).documentElement;
3941
4211
  const result = {};
3942
4212
  for (const field of PROPERTY_FIELDS) {
@@ -4004,6 +4274,146 @@ function dropAddedFolders(zip, source2) {
4004
4274
  if (entry2.dir && !source2.has(name)) delete zip.files[name];
4005
4275
  }
4006
4276
 
4277
+ // docx/save-modified.ts
4278
+ var CORE_PATH2 = "docProps/core.xml";
4279
+ async function stampModified(zip, option) {
4280
+ if (!option) return;
4281
+ const file = zip.file(CORE_PATH2);
4282
+ if (!file) return;
4283
+ const source2 = await file.async("string");
4284
+ const props = parseCoreProperties(source2);
4285
+ props.modified = formatW3cdtf(option.at ?? /* @__PURE__ */ new Date());
4286
+ if (option.author) props.lastModifiedBy = option.author;
4287
+ zip.file(CORE_PATH2, writeCoreProperties(props, source2));
4288
+ }
4289
+
4290
+ // docx/generated/wml-simple-types.ts
4291
+ var ST_HighlightColor = ["black", "blue", "cyan", "green", "magenta", "red", "yellow", "white", "darkBlue", "darkCyan", "darkGreen", "darkMagenta", "darkRed", "darkYellow", "darkGray", "lightGray", "none"];
4292
+ function isStHighlightColor(value) {
4293
+ return typeof value === "string" && ST_HighlightColor.includes(value);
4294
+ }
4295
+ var ST_Underline = ["single", "words", "double", "thick", "dotted", "dottedHeavy", "dash", "dashedHeavy", "dashLong", "dashLongHeavy", "dotDash", "dashDotHeavy", "dotDotDash", "dashDotDotHeavy", "wave", "wavyHeavy", "wavyDouble", "none"];
4296
+ function isStUnderline(value) {
4297
+ return typeof value === "string" && ST_Underline.includes(value);
4298
+ }
4299
+ 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"];
4300
+ function isStBorder(value) {
4301
+ return typeof value === "string" && ST_Border.includes(value);
4302
+ }
4303
+ var ST_TabJc = ["clear", "start", "center", "end", "decimal", "bar", "num", "left", "right"];
4304
+ function isStTabJc(value) {
4305
+ return typeof value === "string" && ST_TabJc.includes(value);
4306
+ }
4307
+ var ST_TabTlc = ["none", "dot", "hyphen", "underscore", "heavy", "middleDot"];
4308
+ function isStTabTlc(value) {
4309
+ return typeof value === "string" && ST_TabTlc.includes(value);
4310
+ }
4311
+ var ST_LineSpacingRule = ["auto", "exact", "atLeast"];
4312
+ function isStLineSpacingRule(value) {
4313
+ return typeof value === "string" && ST_LineSpacingRule.includes(value);
4314
+ }
4315
+ var ST_Jc = ["start", "center", "end", "both", "mediumKashida", "distribute", "numTab", "highKashida", "lowKashida", "thaiDistribute", "left", "right"];
4316
+ function isStJc(value) {
4317
+ return typeof value === "string" && ST_Jc.includes(value);
4318
+ }
4319
+ var ST_JcTable = ["center", "end", "left", "right", "start"];
4320
+ function isStJcTable(value) {
4321
+ return typeof value === "string" && ST_JcTable.includes(value);
4322
+ }
4323
+ var ST_DocProtect = ["none", "readOnly", "comments", "trackedChanges", "forms"];
4324
+ function isStDocProtect(value) {
4325
+ return typeof value === "string" && ST_DocProtect.includes(value);
4326
+ }
4327
+ var ST_FldCharType = ["begin", "separate", "end"];
4328
+ function isStFldCharType(value) {
4329
+ return typeof value === "string" && ST_FldCharType.includes(value);
4330
+ }
4331
+ var ST_InfoTextType = ["text", "autoText"];
4332
+ function isStInfoTextType(value) {
4333
+ return typeof value === "string" && ST_InfoTextType.includes(value);
4334
+ }
4335
+ var ST_FFTextType = ["regular", "number", "date", "currentTime", "currentDate", "calculated"];
4336
+ function isStFFTextType(value) {
4337
+ return typeof value === "string" && ST_FFTextType.includes(value);
4338
+ }
4339
+ var ST_SectionMark = ["nextPage", "nextColumn", "continuous", "evenPage", "oddPage"];
4340
+ function isStSectionMark(value) {
4341
+ return typeof value === "string" && ST_SectionMark.includes(value);
4342
+ }
4343
+ 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"];
4344
+ function isStNumberFormat(value) {
4345
+ return typeof value === "string" && ST_NumberFormat.includes(value);
4346
+ }
4347
+ var ST_PageOrientation = ["portrait", "landscape"];
4348
+ function isStPageOrientation(value) {
4349
+ return typeof value === "string" && ST_PageOrientation.includes(value);
4350
+ }
4351
+ var ST_VerticalJc = ["top", "center", "both", "bottom"];
4352
+ function isStVerticalJc(value) {
4353
+ return typeof value === "string" && ST_VerticalJc.includes(value);
4354
+ }
4355
+ var ST_BrType = ["page", "column", "textWrapping"];
4356
+ function isStBrType(value) {
4357
+ return typeof value === "string" && ST_BrType.includes(value);
4358
+ }
4359
+ var ST_PTabAlignment = ["left", "center", "right"];
4360
+ function isStPTabAlignment(value) {
4361
+ return typeof value === "string" && ST_PTabAlignment.includes(value);
4362
+ }
4363
+ var ST_PTabRelativeTo = ["margin", "indent"];
4364
+ function isStPTabRelativeTo(value) {
4365
+ return typeof value === "string" && ST_PTabRelativeTo.includes(value);
4366
+ }
4367
+ var ST_PTabLeader = ["none", "dot", "hyphen", "underscore", "middleDot"];
4368
+ function isStPTabLeader(value) {
4369
+ return typeof value === "string" && ST_PTabLeader.includes(value);
4370
+ }
4371
+ var ST_Merge = ["continue", "restart"];
4372
+ function isStMerge(value) {
4373
+ return typeof value === "string" && ST_Merge.includes(value);
4374
+ }
4375
+ var ST_WmlColorSchemeIndex = ["dark1", "light1", "dark2", "light2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hyperlink", "followedHyperlink"];
4376
+ function isStWmlColorSchemeIndex(value) {
4377
+ return typeof value === "string" && ST_WmlColorSchemeIndex.includes(value);
4378
+ }
4379
+ var ST_ThemeColor = ["dark1", "light1", "dark2", "light2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hyperlink", "followedHyperlink", "none", "background1", "text1", "background2", "text2"];
4380
+ function isStThemeColor(value) {
4381
+ return typeof value === "string" && ST_ThemeColor.includes(value);
4382
+ }
4383
+ var ST_VerticalAlignRun = ["baseline", "superscript", "subscript"];
4384
+ function isStVerticalAlignRun(value) {
4385
+ return typeof value === "string" && ST_VerticalAlignRun.includes(value);
4386
+ }
4387
+ var ST_RelFromH = ["margin", "page", "column", "character", "leftMargin", "rightMargin", "insideMargin", "outsideMargin"];
4388
+ function isStRelFromH(value) {
4389
+ return typeof value === "string" && ST_RelFromH.includes(value);
4390
+ }
4391
+ var ST_RelFromV = ["margin", "page", "paragraph", "line", "topMargin", "bottomMargin", "insideMargin", "outsideMargin"];
4392
+ function isStRelFromV(value) {
4393
+ return typeof value === "string" && ST_RelFromV.includes(value);
4394
+ }
4395
+
4396
+ // docx/parse-diagnostics.ts
4397
+ var sink;
4398
+ function withParseWarnings(warnings, fn) {
4399
+ const previous = sink;
4400
+ sink = warnings;
4401
+ try {
4402
+ return fn();
4403
+ } finally {
4404
+ sink = previous;
4405
+ }
4406
+ }
4407
+ function reportParseWarning(message) {
4408
+ if (sink && !sink.includes(message)) sink.push(message);
4409
+ }
4410
+ function enumValue(guard, raw2, label) {
4411
+ if (raw2 === null || raw2 === void 0 || raw2 === "") return void 0;
4412
+ if (guard(raw2)) return raw2;
4413
+ reportParseWarning(`Ignored invalid ${label} value \u201C${raw2}\u201D; it is not allowed by the schema.`);
4414
+ return void 0;
4415
+ }
4416
+
4007
4417
  // units/units.ts
4008
4418
  function integer(unit, value, allowNegative = true) {
4009
4419
  if (!Number.isSafeInteger(value)) throw new RangeError(`${unit} must be a safe integer`);
@@ -4109,6 +4519,582 @@ function parseTintShade(value) {
4109
4519
  return value && /^[0-9a-fA-F]{2}$/.test(value) ? Number.parseInt(value, 16) / 255 : void 0;
4110
4520
  }
4111
4521
 
4522
+ // docx/paragraph-alignment.ts
4523
+ function alignFromJustification(jc, rtl) {
4524
+ switch (jc) {
4525
+ case "left":
4526
+ case "center":
4527
+ case "right":
4528
+ return jc;
4529
+ case "start":
4530
+ return rtl ? "right" : "left";
4531
+ case "end":
4532
+ return rtl ? "left" : "right";
4533
+ case "both":
4534
+ case "distribute":
4535
+ case "thaiDistribute":
4536
+ case "mediumKashida":
4537
+ case "highKashida":
4538
+ case "lowKashida":
4539
+ return "justify";
4540
+ default:
4541
+ return void 0;
4542
+ }
4543
+ }
4544
+ function paragraphJustification(paragraph2) {
4545
+ const { align, justification } = paragraph2;
4546
+ if (justification && alignFromJustification(justification, paragraph2.direction === "rtl") === align)
4547
+ return justification;
4548
+ return align === void 0 ? void 0 : align === "justify" ? "both" : align;
4549
+ }
4550
+ function parseJustification(pPr) {
4551
+ const justification = enumValue(isStJc, getW(first2(pPr, "jc"), "val"), "w:jc");
4552
+ if (!justification) return {};
4553
+ const align = alignFromJustification(justification, onOffElement(first2(pPr, "bidi")) === true);
4554
+ return { justification, ...align ? { align } : {} };
4555
+ }
4556
+
4557
+ // docx/element-order.ts
4558
+ var RPR_ORDER = [
4559
+ "rStyle",
4560
+ "rFonts",
4561
+ "b",
4562
+ "bCs",
4563
+ "i",
4564
+ "iCs",
4565
+ "caps",
4566
+ "smallCaps",
4567
+ "strike",
4568
+ "dstrike",
4569
+ "outline",
4570
+ "shadow",
4571
+ "emboss",
4572
+ "imprint",
4573
+ "noProof",
4574
+ "snapToGrid",
4575
+ "vanish",
4576
+ "webHidden",
4577
+ "color",
4578
+ "spacing",
4579
+ "w",
4580
+ "kern",
4581
+ "position",
4582
+ "sz",
4583
+ "szCs",
4584
+ "highlight",
4585
+ "u",
4586
+ "effect",
4587
+ "bdr",
4588
+ "shd",
4589
+ "fitText",
4590
+ "vertAlign",
4591
+ "rtl",
4592
+ "cs",
4593
+ "em",
4594
+ "lang",
4595
+ "eastAsianLayout",
4596
+ "specVanish",
4597
+ "oMath",
4598
+ "ins",
4599
+ "del",
4600
+ "moveFrom",
4601
+ "moveTo",
4602
+ "rPrChange"
4603
+ ];
4604
+ function orderChildren(parent, order) {
4605
+ const elements2 = Array.from(parent.childNodes).filter(isElement);
4606
+ const rankOf = (name) => order.findIndex((entry2) => typeof entry2 === "string" ? entry2 === name : entry2.includes(name));
4607
+ let previousRank = -1;
4608
+ const ranked = elements2.map((element4, index) => {
4609
+ const rank2 = element4.namespaceURI === WORD_NS ? rankOf(element4.localName ?? "") : -1;
4610
+ if (rank2 >= 0) previousRank = rank2;
4611
+ return { element: element4, index, rank: rank2 >= 0 ? rank2 : previousRank + 0.5 };
4612
+ });
4613
+ const sorted = [...ranked].sort((a2, b) => a2.rank - b.rank || a2.index - b.index);
4614
+ if (sorted.every((entry2, index) => entry2.element === elements2[index])) return;
4615
+ for (const { element: element4 } of sorted) parent.appendChild(element4);
4616
+ }
4617
+ var SECTPR_ORDER = [
4618
+ ["headerReference", "footerReference"],
4619
+ "footnotePr",
4620
+ "endnotePr",
4621
+ "type",
4622
+ "pgSz",
4623
+ "pgMar",
4624
+ "paperSrc",
4625
+ "pgBorders",
4626
+ "lnNumType",
4627
+ "pgNumType",
4628
+ "cols",
4629
+ "formProt",
4630
+ "vAlign",
4631
+ "noEndnote",
4632
+ "titlePg",
4633
+ "textDirection",
4634
+ "bidi",
4635
+ "rtlGutter",
4636
+ "docGrid",
4637
+ "printerSettings",
4638
+ "sectPrChange"
4639
+ ];
4640
+ function orderSectionProperties(sectPr) {
4641
+ orderChildren(sectPr, SECTPR_ORDER);
4642
+ }
4643
+
4644
+ // docx/tab-stops.ts
4645
+ function parseTabStops(tabs) {
4646
+ const stops = [];
4647
+ for (const tab of tabs ? children2(tabs, "tab") : []) {
4648
+ const align = enumValue(isStTabJc, getW(tab, "val"), "w:tab/@w:val");
4649
+ const pos = parseSignedTwips(getW(tab, "pos"));
4650
+ if (!align || pos === void 0) continue;
4651
+ const leader = enumValue(isStTabTlc, getW(tab, "leader"), "w:tab/@w:leader");
4652
+ stops.push({ posTwips: pos, align, ...leader ? { leader } : {} });
4653
+ }
4654
+ return stops;
4655
+ }
4656
+ function writeTabStops(doc, props, paragraph2, base) {
4657
+ if (base && JSON.stringify(paragraph2.tabStops ?? []) === JSON.stringify(base.tabStops ?? []))
4658
+ return;
4659
+ for (const tabs2 of children2(props, "tabs")) props.removeChild(tabs2);
4660
+ if (!paragraph2.tabStops?.length) return;
4661
+ const tabs = makeW(doc, "tabs");
4662
+ for (const stop of paragraph2.tabStops) {
4663
+ const tab = makeW(doc, "tab");
4664
+ tab.setAttributeNS(WORD_NS, "w:val", stop.align);
4665
+ if (stop.leader) tab.setAttributeNS(WORD_NS, "w:leader", stop.leader);
4666
+ tab.setAttributeNS(WORD_NS, "w:pos", String(stop.posTwips));
4667
+ tabs.appendChild(tab);
4668
+ }
4669
+ props.appendChild(tabs);
4670
+ }
4671
+ var PPR_ORDER = [
4672
+ "pStyle",
4673
+ "keepNext",
4674
+ "keepLines",
4675
+ "pageBreakBefore",
4676
+ "framePr",
4677
+ "widowControl",
4678
+ "numPr",
4679
+ "suppressLineNumbers",
4680
+ "pBdr",
4681
+ "shd",
4682
+ "tabs",
4683
+ "suppressAutoHyphens",
4684
+ "kinsoku",
4685
+ "wordWrap",
4686
+ "overflowPunct",
4687
+ "topLinePunct",
4688
+ "autoSpaceDE",
4689
+ "autoSpaceDN",
4690
+ "bidi",
4691
+ "adjustRightInd",
4692
+ "snapToGrid",
4693
+ "spacing",
4694
+ "ind",
4695
+ "contextualSpacing",
4696
+ "mirrorIndents",
4697
+ "suppressOverlap",
4698
+ "jc",
4699
+ "textDirection",
4700
+ "textAlignment",
4701
+ "textboxTightWrap",
4702
+ "outlineLvl",
4703
+ "divId",
4704
+ "cnfStyle",
4705
+ "rPr",
4706
+ "sectPr",
4707
+ "pPrChange"
4708
+ ];
4709
+ function orderParagraphProperties(props) {
4710
+ orderChildren(props, PPR_ORDER);
4711
+ }
4712
+
4713
+ // docx/write-paragraph-decoration.ts
4714
+ var SIDES = ["top", "left", "bottom", "right", "between"];
4715
+ function wordColor(color) {
4716
+ const hex = /^#?([0-9a-f]{6})$/i.exec(color ?? "")?.[1];
4717
+ return hex ? hex.toUpperCase() : "auto";
4718
+ }
4719
+ function borderElement(doc, name, side) {
4720
+ const element4 = makeW(doc, name);
4721
+ const set2 = (local, value) => element4.setAttributeNS(WORD_NS, `w:${local}`, value);
4722
+ set2("val", side.style ?? "single");
4723
+ if (side.style !== "none" && side.style !== "nil") {
4724
+ set2("sz", String(side.sizeEighthPoints ?? 4));
4725
+ set2("space", String(side.spacePoints ?? 1));
4726
+ set2("color", wordColor(side.color));
4727
+ if (side.themeColor) set2("themeColor", side.themeColor);
4728
+ }
4729
+ return element4;
4730
+ }
4731
+ var sameJson = (a2, b) => JSON.stringify(a2 ?? null) === JSON.stringify(b ?? null);
4732
+ function updateShading(doc, props, paragraph2, base) {
4733
+ if (base && paragraph2.shadingFill === base.shadingFill) return;
4734
+ for (const element4 of children2(props, "shd")) props.removeChild(element4);
4735
+ if (!paragraph2.shadingFill) return;
4736
+ const shd = makeW(doc, "shd");
4737
+ shd.setAttributeNS(WORD_NS, "w:val", "clear");
4738
+ shd.setAttributeNS(WORD_NS, "w:color", "auto");
4739
+ shd.setAttributeNS(WORD_NS, "w:fill", wordColor(paragraph2.shadingFill));
4740
+ props.appendChild(shd);
4741
+ }
4742
+ function updateBorders(doc, props, paragraph2, base) {
4743
+ if (base && sameJson(paragraph2.borders, base.borders)) return;
4744
+ for (const element4 of children2(props, "pBdr")) props.removeChild(element4);
4745
+ const borders = paragraph2.borders;
4746
+ if (!borders) return;
4747
+ const pBdr = makeW(doc, "pBdr");
4748
+ for (const side of SIDES) {
4749
+ const value = borders[side];
4750
+ if (value) pBdr.appendChild(borderElement(doc, side, value));
4751
+ }
4752
+ if (pBdr.childNodes.length) props.appendChild(pBdr);
4753
+ }
4754
+ function writeParagraphDecoration(doc, props, paragraph2, base) {
4755
+ updateShading(doc, props, paragraph2, base);
4756
+ updateBorders(doc, props, paragraph2, base);
4757
+ }
4758
+
4759
+ // docx/write-paragraph-properties.ts
4760
+ function setAttribute(element4, local, value) {
4761
+ element4.setAttributeNS(WORD_NS, `w:${local}`, value);
4762
+ }
4763
+ function setWordValue(element4, local, value) {
4764
+ if (value === void 0) element4.removeAttributeNS(WORD_NS, local);
4765
+ else setAttribute(element4, local, String(value));
4766
+ }
4767
+ function updateDirection(doc, props, paragraph2, base) {
4768
+ if (base && paragraph2.direction === base.direction) return;
4769
+ let bidi = first2(props, "bidi");
4770
+ if (paragraph2.direction === void 0) {
4771
+ for (const element4 of children2(props, "bidi")) props.removeChild(element4);
4772
+ } else {
4773
+ if (!bidi) {
4774
+ bidi = makeW(doc, "bidi");
4775
+ props.appendChild(bidi);
4776
+ }
4777
+ setAttribute(bidi, "val", paragraph2.direction === "rtl" ? "1" : "0");
4778
+ }
4779
+ }
4780
+ function updateSpacing(doc, props, paragraph2, base) {
4781
+ let spacing2 = first2(props, "spacing");
4782
+ if (!spacing2) {
4783
+ spacing2 = makeW(doc, "spacing");
4784
+ props.appendChild(spacing2);
4785
+ }
4786
+ if (!base || paragraph2.spacingBeforeTwips !== base.spacingBeforeTwips)
4787
+ setWordValue(spacing2, "before", paragraph2.spacingBeforeTwips);
4788
+ if (!base || paragraph2.spacingAfterTwips !== base.spacingAfterTwips)
4789
+ setWordValue(spacing2, "after", paragraph2.spacingAfterTwips);
4790
+ if (!base || paragraph2.lineSpacingTwips !== base.lineSpacingTwips || paragraph2.lineSpacingRule !== base.lineSpacingRule) {
4791
+ setWordValue(spacing2, "line", paragraph2.lineSpacingTwips);
4792
+ setWordValue(
4793
+ spacing2,
4794
+ "lineRule",
4795
+ paragraph2.lineSpacingRule ?? (paragraph2.lineSpacingTwips === void 0 ? void 0 : "auto")
4796
+ );
4797
+ }
4798
+ if (!spacing2.attributes.length && !spacing2.childNodes.length) props.removeChild(spacing2);
4799
+ }
4800
+ function updateIndent(doc, props, paragraph2, base) {
4801
+ let indent = first2(props, "ind");
4802
+ if (!indent) {
4803
+ indent = makeW(doc, "ind");
4804
+ props.appendChild(indent);
4805
+ }
4806
+ if (!base || paragraph2.indentLeftTwips !== base.indentLeftTwips)
4807
+ setWordValue(indent, "left", paragraph2.indentLeftTwips);
4808
+ if (!base || paragraph2.indentRightTwips !== base.indentRightTwips)
4809
+ setWordValue(indent, "right", paragraph2.indentRightTwips);
4810
+ if (!base || paragraph2.indentStartTwips !== base.indentStartTwips)
4811
+ setWordValue(indent, "start", paragraph2.indentStartTwips);
4812
+ if (!base || paragraph2.indentEndTwips !== base.indentEndTwips)
4813
+ setWordValue(indent, "end", paragraph2.indentEndTwips);
4814
+ if (!base || paragraph2.firstLineTwips !== base.firstLineTwips)
4815
+ setWordValue(indent, "firstLine", paragraph2.firstLineTwips);
4816
+ if (!base || paragraph2.hangingTwips !== base.hangingTwips)
4817
+ setWordValue(indent, "hanging", paragraph2.hangingTwips);
4818
+ if (!indent.attributes.length) props.removeChild(indent);
4819
+ }
4820
+ function updatePageBreakBefore(doc, props, paragraph2, base) {
4821
+ if (base && paragraph2.pageBreakBefore === base.pageBreakBefore) return;
4822
+ for (const element4 of children2(props, "pageBreakBefore")) props.removeChild(element4);
4823
+ if (paragraph2.pageBreakBefore !== void 0) {
4824
+ const element4 = makeW(doc, "pageBreakBefore");
4825
+ if (!paragraph2.pageBreakBefore) element4.setAttributeNS(WORD_NS, "w:val", "0");
4826
+ props.appendChild(element4);
4827
+ }
4828
+ }
4829
+ function updateKeepOptions(doc, props, paragraph2, base) {
4830
+ for (const key of [
4831
+ "keepNext",
4832
+ "keepLines",
4833
+ "widowControl",
4834
+ "contextualSpacing",
4835
+ "suppressLineNumbers"
4836
+ ]) {
4837
+ if (base && paragraph2[key] === base[key]) continue;
4838
+ for (const element5 of children2(props, key)) props.removeChild(element5);
4839
+ const value = paragraph2[key];
4840
+ if (value === void 0) continue;
4841
+ const element4 = makeW(doc, key);
4842
+ if (!value) setAttribute(element4, "val", "0");
4843
+ props.appendChild(element4);
4844
+ }
4845
+ }
4846
+ function updateDropCap(doc, props, paragraph2, base) {
4847
+ if (base && JSON.stringify(paragraph2.dropCap) === JSON.stringify(base.dropCap)) return;
4848
+ let frame2 = first2(props, "framePr");
4849
+ const cap = paragraph2.dropCap;
4850
+ if (!cap) {
4851
+ if (frame2) props.removeChild(frame2);
4852
+ return;
4853
+ }
4854
+ if (!frame2) {
4855
+ frame2 = makeW(doc, "framePr");
4856
+ props.appendChild(frame2);
4857
+ setAttribute(frame2, "wrap", "around");
4858
+ setAttribute(frame2, "vAnchor", "text");
4859
+ setAttribute(frame2, "hAnchor", "text");
4860
+ }
4861
+ setAttribute(frame2, "dropCap", cap.style);
4862
+ setAttribute(frame2, "lines", String(cap.lines));
4863
+ setWordValue(frame2, "hSpace", cap.distanceTwips);
4864
+ }
4865
+ function writeParagraphProperties(doc, props, paragraph2, base) {
4866
+ updatePageBreakBefore(doc, props, paragraph2, base);
4867
+ updateKeepOptions(doc, props, paragraph2, base);
4868
+ updateDropCap(doc, props, paragraph2, base);
4869
+ updateDirection(doc, props, paragraph2, base);
4870
+ writeParagraphDecoration(doc, props, paragraph2, base);
4871
+ const spacingKeys = [
4872
+ "spacingBeforeTwips",
4873
+ "spacingAfterTwips",
4874
+ "lineSpacingTwips",
4875
+ "lineSpacingRule"
4876
+ ];
4877
+ if (!base || spacingKeys.some((key) => paragraph2[key] !== base[key]))
4878
+ updateSpacing(doc, props, paragraph2, base);
4879
+ const indentKeys = [
4880
+ "indentLeftTwips",
4881
+ "indentRightTwips",
4882
+ "indentStartTwips",
4883
+ "indentEndTwips",
4884
+ "firstLineTwips",
4885
+ "hangingTwips"
4886
+ ];
4887
+ if (!base || indentKeys.some((key) => paragraph2[key] !== base[key]))
4888
+ updateIndent(doc, props, paragraph2, base);
4889
+ }
4890
+
4891
+ // docx/style-formatting-package.ts
4892
+ var STYLES_PART = "word/styles.xml";
4893
+ var AFTER_PPR = ["rPr", "tblPr", "trPr", "tcPr", "tblStylePr"];
4894
+ var WRITABLE_STYLE_FORMATTING = [
4895
+ "align",
4896
+ "justification",
4897
+ "direction",
4898
+ "spacingBeforeTwips",
4899
+ "spacingAfterTwips",
4900
+ "lineSpacingTwips",
4901
+ "lineSpacingRule",
4902
+ "indentLeftTwips",
4903
+ "indentRightTwips",
4904
+ "indentStartTwips",
4905
+ "indentEndTwips",
4906
+ "firstLineTwips",
4907
+ "hangingTwips",
4908
+ "pageBreakBefore",
4909
+ "keepNext",
4910
+ "keepLines",
4911
+ "widowControl",
4912
+ "contextualSpacing",
4913
+ "suppressLineNumbers",
4914
+ "borders",
4915
+ "shadingFill"
4916
+ ];
4917
+ function unwritableFormatting(formatting) {
4918
+ const rest = { ...formatting };
4919
+ for (const key of WRITABLE_STYLE_FORMATTING) delete rest[key];
4920
+ return rest;
4921
+ }
4922
+ var asParagraph = (formatting) => ({
4923
+ type: "paragraph",
4924
+ id: "style",
4925
+ runs: [],
4926
+ ...formatting
4927
+ });
4928
+ function pPrOf(style) {
4929
+ let pPr = first2(style, "pPr");
4930
+ if (pPr) return pPr;
4931
+ pPr = makeW(style.ownerDocument, "pPr");
4932
+ const anchor = Array.from(style.childNodes).find(
4933
+ (node) => node.nodeType === 1 && AFTER_PPR.includes(node.localName)
4934
+ ) ?? null;
4935
+ style.insertBefore(pPr, anchor);
4936
+ return pPr;
4937
+ }
4938
+ async function applyStyleFormatting(zip, model, base) {
4939
+ const next = model.paragraphStyles?.styles ?? {};
4940
+ const prior = base.paragraphStyles?.styles ?? {};
4941
+ const changed = Object.keys(next).filter(
4942
+ (id) => JSON.stringify(next[id]?.formatting) !== JSON.stringify(prior[id]?.formatting)
4943
+ );
4944
+ if (!changed.length) return;
4945
+ const file = zip.file(STYLES_PART);
4946
+ if (!file) throw new Error("Cannot edit a style: the package has no styles.xml.");
4947
+ const doc = parseXml2(await file.async("string"));
4948
+ const styles = children2(doc.documentElement, "style");
4949
+ for (const id of changed) {
4950
+ const style = styles.find(
4951
+ (element4) => getW(element4, "type") === "paragraph" && getW(element4, "styleId") === id
4952
+ );
4953
+ if (!style) throw new Error(`Cannot edit style "${id}": it is not in styles.xml.`);
4954
+ const after = asParagraph(next[id].formatting);
4955
+ const before = asParagraph(prior[id]?.formatting ?? {});
4956
+ const pPr = pPrOf(style);
4957
+ if (after.align !== before.align || after.justification !== before.justification || after.direction !== before.direction) {
4958
+ for (const jc of children2(pPr, "jc")) pPr.removeChild(jc);
4959
+ const value = paragraphJustification(after);
4960
+ if (value) {
4961
+ const jc = makeW(doc, "jc");
4962
+ jc.setAttributeNS(WORD_NS, "w:val", value);
4963
+ pPr.appendChild(jc);
4964
+ }
4965
+ }
4966
+ writeParagraphProperties(doc, pPr, after, before);
4967
+ orderParagraphProperties(pPr);
4968
+ }
4969
+ zip.file(STYLES_PART, buildXml(doc));
4970
+ }
4971
+
4972
+ // docx/data-binding.ts
4973
+ function parsePrefixes(text) {
4974
+ const map = /* @__PURE__ */ new Map();
4975
+ for (const match of (text ?? "").matchAll(/xmlns:([\w.-]+)\s*=\s*(?:'([^']*)'|"([^"]*)")/g))
4976
+ map.set(match[1], match[2] ?? match[3] ?? "");
4977
+ return map;
4978
+ }
4979
+ function sourceBindings(sourceXml) {
4980
+ const result = /* @__PURE__ */ new Map();
4981
+ const document = parseXml2(sourceXml);
4982
+ for (const sdt of Array.from(document.getElementsByTagNameNS(WORD_NS, "sdt"))) {
4983
+ const sdtPr = first2(sdt, "sdtPr");
4984
+ const element4 = sdtPr && elements(sdtPr).find((node) => node.localName === "dataBinding");
4985
+ const id = getW(first2(sdtPr, "id"), "val");
4986
+ const xpath = element4?.getAttributeNS(WORD_NS, "xpath");
4987
+ const storeItemId = element4?.getAttributeNS(WORD_NS, "storeItemID");
4988
+ if (id && element4 && xpath && storeItemId)
4989
+ result.set(id, {
4990
+ xpath,
4991
+ storeItemId,
4992
+ prefixes: parsePrefixes(element4.getAttributeNS(WORD_NS, "prefixMappings") ?? void 0)
4993
+ });
4994
+ }
4995
+ return result;
4996
+ }
4997
+ function paragraphsOf(blocks) {
4998
+ return blocks.flatMap(
4999
+ (block) => block.type === "paragraph" ? [block] : block.rows.flatMap((row) => row.flatMap((c2) => c2.paragraphs))
5000
+ );
5001
+ }
5002
+ function boundTexts(model) {
5003
+ const parts = /* @__PURE__ */ new Map();
5004
+ const add4 = (id, text) => parts.set(id, [...parts.get(id) ?? [], text]);
5005
+ for (const paragraph2 of paragraphsOf(model.blocks)) {
5006
+ const own2 = paragraph2.contentControl;
5007
+ if (own2?.dataBound) {
5008
+ add4(own2.id, paragraph2.runs.map((run2) => run2.text).join(""));
5009
+ continue;
5010
+ }
5011
+ const inline = /* @__PURE__ */ new Map();
5012
+ for (const run2 of paragraph2.runs) {
5013
+ const control = run2.contentControl;
5014
+ if (!control?.dataBound) continue;
5015
+ if (!inline.has(control.id)) inline.set(control.id, "");
5016
+ if (!control.showingPlaceholder) inline.set(control.id, inline.get(control.id) + run2.text);
5017
+ }
5018
+ for (const [id, text] of inline) add4(id, text);
5019
+ }
5020
+ return new Map([...parts].map(([id, texts]) => [id, texts.join("\n")]));
5021
+ }
5022
+ function parseXPath(binding) {
5023
+ const parts = binding.xpath.split("/");
5024
+ if (parts.shift() !== "" || !parts.length) return void 0;
5025
+ if (parts.at(-1) === "text()") parts.pop();
5026
+ const parse = (raw2, attribute3) => {
5027
+ const match = /^(?:([A-Za-z_][\w.-]*):)?([A-Za-z_][\w.-]*)(?:\[(\d+)\])?$/.exec(raw2);
5028
+ if (!match || attribute3 && match[3]) return void 0;
5029
+ const [, prefix2 = "", name = "", index] = match;
5030
+ if (prefix2 && !binding.prefixes.has(prefix2)) return void 0;
5031
+ return { prefix: prefix2, name, index: index ? Number(index) : 1 };
5032
+ };
5033
+ const last = parts.at(-1);
5034
+ const attribute2 = last?.startsWith("@") ? parse(last.slice(1), true) : void 0;
5035
+ if (last?.startsWith("@")) {
5036
+ parts.pop();
5037
+ if (!attribute2) return void 0;
5038
+ }
5039
+ const steps = parts.map((part) => parse(part, false));
5040
+ if (!steps.length || steps.some((step) => !step)) return void 0;
5041
+ return { steps, ...attribute2 ? { attribute: attribute2 } : {} };
5042
+ }
5043
+ var matches = (element4, step, binding) => element4.localName === step.name && (element4.namespaceURI ?? "") === (step.prefix ? binding.prefixes.get(step.prefix) ?? "" : "");
5044
+ function writeValue(root, binding, value) {
5045
+ const path3 = parseXPath(binding);
5046
+ if (!path3) return "unsupported";
5047
+ let node = root;
5048
+ for (const [depth, step] of path3.steps.entries()) {
5049
+ const candidates = depth === 0 ? [root].filter((e) => matches(e, step, binding)) : elements(node).filter((e) => matches(e, step, binding));
5050
+ node = candidates[step.index - 1];
5051
+ if (!node) return false;
5052
+ }
5053
+ if (path3.attribute) {
5054
+ const { prefix: prefix2, name } = path3.attribute;
5055
+ const ns = prefix2 ? binding.prefixes.get(prefix2) : void 0;
5056
+ if (ns) node.setAttributeNS(ns, `${prefix2}:${name}`, value);
5057
+ else node.setAttribute(name, value);
5058
+ return true;
5059
+ }
5060
+ for (const child8 of Array.from(node.childNodes)) node.removeChild(child8);
5061
+ if (value) node.appendChild(node.ownerDocument.createTextNode(value));
5062
+ return true;
5063
+ }
5064
+ async function findItemPart(zip, storeItemId) {
5065
+ const wanted = storeItemId.toLowerCase();
5066
+ for (const name of Object.keys(zip.files)) {
5067
+ const props = /^customXml\/itemProps(\d+)\.xml$/.exec(name);
5068
+ if (!props) continue;
5069
+ const root = parseXml2(await zip.file(name).async("string")).documentElement;
5070
+ const id = Array.from(root.attributes).find((attribute2) => attribute2.localName === "itemID");
5071
+ if ((id?.value ?? "").toLowerCase() === wanted) return `customXml/item${props[1]}.xml`;
5072
+ }
5073
+ return void 0;
5074
+ }
5075
+ async function applyDataBindings(zip, model, base, sourceXml) {
5076
+ const now = boundTexts(model);
5077
+ if (!now.size) return;
5078
+ const before = boundTexts(base);
5079
+ const bindings = sourceBindings(sourceXml);
5080
+ const parsed = /* @__PURE__ */ new Map();
5081
+ for (const [id, text] of now) {
5082
+ const binding = bindings.get(id);
5083
+ if (!binding || before.get(id) === text) continue;
5084
+ const part = await findItemPart(zip, binding.storeItemId);
5085
+ const file = part ? zip.file(part) : void 0;
5086
+ if (!part || !file) continue;
5087
+ const document = parsed.get(part) ?? parseXml2(await file.async("string"));
5088
+ parsed.set(part, document);
5089
+ const written = writeValue(document.documentElement, binding, text);
5090
+ if (written !== true)
5091
+ throw new Error(
5092
+ 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.`
5093
+ );
5094
+ }
5095
+ for (const [part, document] of parsed) zip.file(part, buildXml(document));
5096
+ }
5097
+
4112
5098
  // docx/ligatures.ts
4113
5099
  var LIGATURE_VALUES = [
4114
5100
  "none",
@@ -4131,7 +5117,7 @@ var LIGATURE_VALUES = [
4131
5117
  var isLigatures = (value) => typeof value === "string" && LIGATURE_VALUES.includes(value);
4132
5118
  var WORD_2010_NS = "http://schemas.microsoft.com/office/word/2010/wordml";
4133
5119
  var MC = "http://schemas.openxmlformats.org/markup-compatibility/2006";
4134
- var XMLNS2 = "http://www.w3.org/2000/xmlns/";
5120
+ var XMLNS3 = "http://www.w3.org/2000/xmlns/";
4135
5121
  var ligatureElements = (props) => elements(props).filter(
4136
5122
  (element4) => element4.namespaceURI === WORD_2010_NS && element4.localName === "ligatures"
4137
5123
  );
@@ -4144,7 +5130,7 @@ function extensionPrefix(doc, ns, preferred) {
4144
5130
  let prefix2 = preferred;
4145
5131
  for (let index = 1; root.lookupNamespaceURI(prefix2) && root.lookupNamespaceURI(prefix2) !== ns; index++)
4146
5132
  prefix2 = `${preferred}${index}`;
4147
- root.setAttributeNS(XMLNS2, `xmlns:${prefix2}`, ns);
5133
+ root.setAttributeNS(XMLNS3, `xmlns:${prefix2}`, ns);
4148
5134
  return prefix2;
4149
5135
  }
4150
5136
  function declareIgnorableExtension(doc, ns, preferred) {
@@ -4426,93 +5412,6 @@ var flatRows = (table) => flatChildren(table, ["tr"], "row");
4426
5412
  var flatCells = (row) => flatChildren(row, ["tc"], "cell");
4427
5413
  var flatCellParagraphs = (cell2) => flatChildren(cell2, ["p"]);
4428
5414
 
4429
- // docx/element-order.ts
4430
- var RPR_ORDER = [
4431
- "rStyle",
4432
- "rFonts",
4433
- "b",
4434
- "bCs",
4435
- "i",
4436
- "iCs",
4437
- "caps",
4438
- "smallCaps",
4439
- "strike",
4440
- "dstrike",
4441
- "outline",
4442
- "shadow",
4443
- "emboss",
4444
- "imprint",
4445
- "noProof",
4446
- "snapToGrid",
4447
- "vanish",
4448
- "webHidden",
4449
- "color",
4450
- "spacing",
4451
- "w",
4452
- "kern",
4453
- "position",
4454
- "sz",
4455
- "szCs",
4456
- "highlight",
4457
- "u",
4458
- "effect",
4459
- "bdr",
4460
- "shd",
4461
- "fitText",
4462
- "vertAlign",
4463
- "rtl",
4464
- "cs",
4465
- "em",
4466
- "lang",
4467
- "eastAsianLayout",
4468
- "specVanish",
4469
- "oMath",
4470
- "ins",
4471
- "del",
4472
- "moveFrom",
4473
- "moveTo",
4474
- "rPrChange"
4475
- ];
4476
- function orderChildren(parent, order) {
4477
- const elements2 = Array.from(parent.childNodes).filter(isElement);
4478
- const rankOf = (name) => order.findIndex((entry2) => typeof entry2 === "string" ? entry2 === name : entry2.includes(name));
4479
- let previousRank = -1;
4480
- const ranked = elements2.map((element4, index) => {
4481
- const rank2 = element4.namespaceURI === WORD_NS ? rankOf(element4.localName ?? "") : -1;
4482
- if (rank2 >= 0) previousRank = rank2;
4483
- return { element: element4, index, rank: rank2 >= 0 ? rank2 : previousRank + 0.5 };
4484
- });
4485
- const sorted = [...ranked].sort((a2, b) => a2.rank - b.rank || a2.index - b.index);
4486
- if (sorted.every((entry2, index) => entry2.element === elements2[index])) return;
4487
- for (const { element: element4 } of sorted) parent.appendChild(element4);
4488
- }
4489
- var SECTPR_ORDER = [
4490
- ["headerReference", "footerReference"],
4491
- "footnotePr",
4492
- "endnotePr",
4493
- "type",
4494
- "pgSz",
4495
- "pgMar",
4496
- "paperSrc",
4497
- "pgBorders",
4498
- "lnNumType",
4499
- "pgNumType",
4500
- "cols",
4501
- "formProt",
4502
- "vAlign",
4503
- "noEndnote",
4504
- "titlePg",
4505
- "textDirection",
4506
- "bidi",
4507
- "rtlGutter",
4508
- "docGrid",
4509
- "printerSettings",
4510
- "sectPrChange"
4511
- ];
4512
- function orderSectionProperties(sectPr) {
4513
- orderChildren(sectPr, SECTPR_ORDER);
4514
- }
4515
-
4516
5415
  // docx/content-control-values.ts
4517
5416
  var validLock = (lock) => lock === "sdtLocked" || lock === "contentLocked" || lock === "sdtContentLocked" ? lock : void 0;
4518
5417
  function validId(id) {
@@ -4738,15 +5637,15 @@ function writeDate(doc, sdtPr, control) {
4738
5637
  const fullDate = validDate(control.fullDate) ?? (control.fullDate === existing ? existing : void 0);
4739
5638
  if (fullDate) date.setAttributeNS(WORD_NS, "w:fullDate", fullDate);
4740
5639
  else date.removeAttributeNS(WORD_NS, "fullDate");
4741
- const set = (local, value, order) => {
5640
+ const set2 = (local, value, order) => {
4742
5641
  for (const old of children2(date, local)) date.removeChild(old);
4743
5642
  if (typeof value !== "string") return;
4744
5643
  const element4 = makeW(doc, local);
4745
5644
  element4.setAttributeNS(WORD_NS, "w:val", value);
4746
5645
  date.insertBefore(element4, Array.from(date.childNodes)[order] ?? null);
4747
5646
  };
4748
- set("dateFormat", control.dateFormat, 0);
4749
- set("lid", control.dateLocale, 1);
5647
+ set2("dateFormat", control.dateFormat, 0);
5648
+ set2("lid", control.dateLocale, 1);
4750
5649
  }
4751
5650
  var writesType = (kind) => NAMED_TYPES.has(kind) || ["richText", "text", "checkbox", "dropDownList", "comboBox", "date"].includes(kind);
4752
5651
  function patchContentControl(doc, sdt, control) {
@@ -4924,13 +5823,13 @@ function rangeKeys(run2) {
4924
5823
  keys.push(`${revision.kind}:${revision.move.name}`);
4925
5824
  return keys;
4926
5825
  }
4927
- function paragraphsOf(blocks) {
5826
+ function paragraphsOf2(blocks) {
4928
5827
  return blocks.flatMap(
4929
5828
  (block) => block.type === "paragraph" ? [block] : block.rows.flatMap((row) => row.flatMap((cell2) => cell2.paragraphs))
4930
5829
  );
4931
5830
  }
4932
5831
  function commentContinuations(blocks) {
4933
- const paragraphs = paragraphsOf(blocks);
5832
+ const paragraphs = paragraphsOf2(blocks);
4934
5833
  const first3 = /* @__PURE__ */ new Map();
4935
5834
  const last = /* @__PURE__ */ new Map();
4936
5835
  const idsByParagraph = paragraphs.map((paragraph2, index) => {
@@ -4995,7 +5894,7 @@ var COMMENTS_PATH = "word/comments.xml";
4995
5894
  var COMMENTS_EXTENDED_PATH = "word/commentsExtended.xml";
4996
5895
  var W14_NS = "http://schemas.microsoft.com/office/word/2010/wordml";
4997
5896
  var W15_NS = "http://schemas.microsoft.com/office/word/2012/wordml";
4998
- function setAttribute(element4, local, value) {
5897
+ function setAttribute2(element4, local, value) {
4999
5898
  element4.setAttributeNS(WORD_NS, `w:${local}`, value);
5000
5899
  }
5001
5900
  function paraIdFor(id, index) {
@@ -5010,10 +5909,10 @@ function buildCommentsDocument(comments) {
5010
5909
  const root = doc.documentElement;
5011
5910
  comments.forEach((comment, index) => {
5012
5911
  const el5 = makeW(doc, "comment");
5013
- setAttribute(el5, "id", comment.id);
5014
- setAttribute(el5, "author", comment.author);
5015
- if (comment.date) setAttribute(el5, "date", comment.date);
5016
- if (comment.initials) setAttribute(el5, "initials", comment.initials);
5912
+ setAttribute2(el5, "id", comment.id);
5913
+ setAttribute2(el5, "author", comment.author);
5914
+ if (comment.date) setAttribute2(el5, "date", comment.date);
5915
+ if (comment.initials) setAttribute2(el5, "initials", comment.initials);
5017
5916
  const p = makeW(doc, "p");
5018
5917
  p.setAttributeNS(W14_NS, "w14:paraId", paraIdFor(comment.id, index));
5019
5918
  const r = makeW(doc, "r");
@@ -5077,15 +5976,15 @@ async function applyComments(zip, comments) {
5077
5976
  }
5078
5977
  function commentRangeStartNode(doc, id) {
5079
5978
  const element4 = makeW(doc, "commentRangeStart");
5080
- setAttribute(element4, "id", id);
5979
+ setAttribute2(element4, "id", id);
5081
5980
  return element4;
5082
5981
  }
5083
5982
  function commentRangeEndNodes(doc, id) {
5084
5983
  const end = makeW(doc, "commentRangeEnd");
5085
- setAttribute(end, "id", id);
5984
+ setAttribute2(end, "id", id);
5086
5985
  const run2 = makeW(doc, "r");
5087
5986
  const reference = makeW(doc, "commentReference");
5088
- setAttribute(reference, "id", id);
5987
+ setAttribute2(reference, "id", id);
5089
5988
  run2.appendChild(reference);
5090
5989
  return [end, run2];
5091
5990
  }
@@ -5333,112 +6232,6 @@ var DEFAULT_THEME_COLOR_MAP = {
5333
6232
  tx2: "dk2"
5334
6233
  };
5335
6234
 
5336
- // docx/generated/wml-simple-types.ts
5337
- var ST_HighlightColor = ["black", "blue", "cyan", "green", "magenta", "red", "yellow", "white", "darkBlue", "darkCyan", "darkGreen", "darkMagenta", "darkRed", "darkYellow", "darkGray", "lightGray", "none"];
5338
- function isStHighlightColor(value) {
5339
- return typeof value === "string" && ST_HighlightColor.includes(value);
5340
- }
5341
- var ST_Underline = ["single", "words", "double", "thick", "dotted", "dottedHeavy", "dash", "dashedHeavy", "dashLong", "dashLongHeavy", "dotDash", "dashDotHeavy", "dotDotDash", "dashDotDotHeavy", "wave", "wavyHeavy", "wavyDouble", "none"];
5342
- function isStUnderline(value) {
5343
- return typeof value === "string" && ST_Underline.includes(value);
5344
- }
5345
- 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"];
5346
- function isStBorder(value) {
5347
- return typeof value === "string" && ST_Border.includes(value);
5348
- }
5349
- var ST_TabJc = ["clear", "start", "center", "end", "decimal", "bar", "num", "left", "right"];
5350
- function isStTabJc(value) {
5351
- return typeof value === "string" && ST_TabJc.includes(value);
5352
- }
5353
- var ST_TabTlc = ["none", "dot", "hyphen", "underscore", "heavy", "middleDot"];
5354
- function isStTabTlc(value) {
5355
- return typeof value === "string" && ST_TabTlc.includes(value);
5356
- }
5357
- var ST_LineSpacingRule = ["auto", "exact", "atLeast"];
5358
- function isStLineSpacingRule(value) {
5359
- return typeof value === "string" && ST_LineSpacingRule.includes(value);
5360
- }
5361
- var ST_Jc = ["start", "center", "end", "both", "mediumKashida", "distribute", "numTab", "highKashida", "lowKashida", "thaiDistribute", "left", "right"];
5362
- function isStJc(value) {
5363
- return typeof value === "string" && ST_Jc.includes(value);
5364
- }
5365
- var ST_JcTable = ["center", "end", "left", "right", "start"];
5366
- function isStJcTable(value) {
5367
- return typeof value === "string" && ST_JcTable.includes(value);
5368
- }
5369
- var ST_DocProtect = ["none", "readOnly", "comments", "trackedChanges", "forms"];
5370
- function isStDocProtect(value) {
5371
- return typeof value === "string" && ST_DocProtect.includes(value);
5372
- }
5373
- var ST_FldCharType = ["begin", "separate", "end"];
5374
- function isStFldCharType(value) {
5375
- return typeof value === "string" && ST_FldCharType.includes(value);
5376
- }
5377
- var ST_InfoTextType = ["text", "autoText"];
5378
- function isStInfoTextType(value) {
5379
- return typeof value === "string" && ST_InfoTextType.includes(value);
5380
- }
5381
- var ST_FFTextType = ["regular", "number", "date", "currentTime", "currentDate", "calculated"];
5382
- function isStFFTextType(value) {
5383
- return typeof value === "string" && ST_FFTextType.includes(value);
5384
- }
5385
- var ST_SectionMark = ["nextPage", "nextColumn", "continuous", "evenPage", "oddPage"];
5386
- function isStSectionMark(value) {
5387
- return typeof value === "string" && ST_SectionMark.includes(value);
5388
- }
5389
- 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"];
5390
- function isStNumberFormat(value) {
5391
- return typeof value === "string" && ST_NumberFormat.includes(value);
5392
- }
5393
- var ST_PageOrientation = ["portrait", "landscape"];
5394
- function isStPageOrientation(value) {
5395
- return typeof value === "string" && ST_PageOrientation.includes(value);
5396
- }
5397
- var ST_VerticalJc = ["top", "center", "both", "bottom"];
5398
- function isStVerticalJc(value) {
5399
- return typeof value === "string" && ST_VerticalJc.includes(value);
5400
- }
5401
- var ST_BrType = ["page", "column", "textWrapping"];
5402
- function isStBrType(value) {
5403
- return typeof value === "string" && ST_BrType.includes(value);
5404
- }
5405
- var ST_PTabAlignment = ["left", "center", "right"];
5406
- function isStPTabAlignment(value) {
5407
- return typeof value === "string" && ST_PTabAlignment.includes(value);
5408
- }
5409
- var ST_PTabRelativeTo = ["margin", "indent"];
5410
- function isStPTabRelativeTo(value) {
5411
- return typeof value === "string" && ST_PTabRelativeTo.includes(value);
5412
- }
5413
- var ST_PTabLeader = ["none", "dot", "hyphen", "underscore", "middleDot"];
5414
- function isStPTabLeader(value) {
5415
- return typeof value === "string" && ST_PTabLeader.includes(value);
5416
- }
5417
- var ST_Merge = ["continue", "restart"];
5418
- function isStMerge(value) {
5419
- return typeof value === "string" && ST_Merge.includes(value);
5420
- }
5421
- var ST_WmlColorSchemeIndex = ["dark1", "light1", "dark2", "light2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hyperlink", "followedHyperlink"];
5422
- function isStWmlColorSchemeIndex(value) {
5423
- return typeof value === "string" && ST_WmlColorSchemeIndex.includes(value);
5424
- }
5425
- var ST_ThemeColor = ["dark1", "light1", "dark2", "light2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hyperlink", "followedHyperlink", "none", "background1", "text1", "background2", "text2"];
5426
- function isStThemeColor(value) {
5427
- return typeof value === "string" && ST_ThemeColor.includes(value);
5428
- }
5429
- var ST_VerticalAlignRun = ["baseline", "superscript", "subscript"];
5430
- function isStVerticalAlignRun(value) {
5431
- return typeof value === "string" && ST_VerticalAlignRun.includes(value);
5432
- }
5433
- var ST_RelFromH = ["margin", "page", "column", "character", "leftMargin", "rightMargin", "insideMargin", "outsideMargin"];
5434
- function isStRelFromH(value) {
5435
- return typeof value === "string" && ST_RelFromH.includes(value);
5436
- }
5437
- var ST_RelFromV = ["margin", "page", "paragraph", "line", "topMargin", "bottomMargin", "insideMargin", "outsideMargin"];
5438
- function isStRelFromV(value) {
5439
- return typeof value === "string" && ST_RelFromV.includes(value);
5440
- }
5441
-
5442
6235
  // docx/theme-color.ts
5443
6236
  function isThemeColorToken(value) {
5444
6237
  return isStThemeColor(value);
@@ -5595,10 +6388,10 @@ function buildRowProperties(doc, row, gridAfter) {
5595
6388
  }
5596
6389
 
5597
6390
  // docx/write-table-margins.ts
5598
- var SIDES = ["top", "left", "bottom", "right"];
6391
+ var SIDES2 = ["top", "left", "bottom", "right"];
5599
6392
  var ORDER = ["top", "start", "left", "bottom", "end", "right"];
5600
6393
  function patchMarginProperties(doc, host, propertiesTag, marginTag, propertiesOrder, next, base) {
5601
- const changed = SIDES.filter((side) => next?.[side] !== base?.[side]);
6394
+ const changed = SIDES2.filter((side) => next?.[side] !== base?.[side]);
5602
6395
  if (!changed.length) return;
5603
6396
  for (const side of changed) {
5604
6397
  const value = next?.[side];
@@ -5918,14 +6711,21 @@ function unwrapDroppedControls(elements2, next) {
5918
6711
  });
5919
6712
  }
5920
6713
 
5921
- // docx/write-table.ts
6714
+ // docx/table-structure-check.ts
6715
+ var only = (parent, allowed) => Array.from(parent.childNodes).filter(isElement).every((node) => allowed.some((name) => named2(node, name)));
6716
+ function plainParagraphs(cell2) {
6717
+ for (const paragraph2 of children2(cell2, "p")) {
6718
+ if (!only(paragraph2, ["pPr", "r"])) return false;
6719
+ for (const run2 of children2(paragraph2, "r"))
6720
+ if (!only(run2, ["rPr", "t", "tab", "br", "cr", "noBreakHyphen"])) return false;
6721
+ }
6722
+ return true;
6723
+ }
5922
6724
  function canEditTableStructure(table) {
5923
- const only = (parent, allowed) => Array.from(parent.childNodes).filter(isElement).every((node) => allowed.some((name) => named2(node, name)));
5924
6725
  if (!only(table, ["tblPr", "tblGrid", "tr"])) return false;
5925
6726
  const grid = first2(table, "tblGrid");
5926
6727
  if (grid && !only(grid, ["gridCol"])) return false;
5927
6728
  const rows = children2(table, "tr");
5928
- if (!rows.length) return false;
5929
6729
  const [firstRow] = rows;
5930
6730
  if (!firstRow) return false;
5931
6731
  const width = children2(firstRow, "tc").length;
@@ -5941,15 +6741,206 @@ function canEditTableStructure(table) {
5941
6741
  const props = first2(cell2, "tcPr");
5942
6742
  if (props && ["gridSpan", "vMerge", "hMerge", "tcPrChange"].some((key) => first2(props, key)))
5943
6743
  return false;
5944
- for (const paragraph2 of children2(cell2, "p")) {
5945
- if (!only(paragraph2, ["pPr", "r"])) return false;
5946
- for (const run2 of children2(paragraph2, "r"))
5947
- if (!only(run2, ["rPr", "t", "tab", "br", "cr", "noBreakHyphen"])) return false;
5948
- }
6744
+ if (!plainParagraphs(cell2)) return false;
5949
6745
  }
5950
6746
  }
5951
6747
  return true;
5952
6748
  }
6749
+ function canRestructureTable(table) {
6750
+ if (!only(table, ["tblPr", "tblGrid", "tr"])) return false;
6751
+ const grid = first2(table, "tblGrid");
6752
+ if (!grid || !only(grid, ["gridCol"])) return false;
6753
+ const rows = children2(table, "tr");
6754
+ if (!rows.length) return false;
6755
+ for (const row of rows) {
6756
+ if (!only(row, ["trPr", "tc"]) || !children2(row, "tc").length) return false;
6757
+ const rowProps = first2(row, "trPr");
6758
+ if (rowProps && ["gridBefore", "gridAfter", "wBefore", "wAfter", "trPrChange", "ins", "del"].some(
6759
+ (key) => first2(rowProps, key)
6760
+ ))
6761
+ return false;
6762
+ for (const cell2 of children2(row, "tc")) {
6763
+ if (!only(cell2, ["tcPr", "p", "tbl"]) || !children2(cell2, "p").length) return false;
6764
+ const props = first2(cell2, "tcPr");
6765
+ if (props && ["hMerge", "tcPrChange", "cellIns", "cellDel", "cellMerge"].some((key) => first2(props, key)))
6766
+ return false;
6767
+ if (!plainParagraphs(cell2)) return false;
6768
+ }
6769
+ }
6770
+ return true;
6771
+ }
6772
+
6773
+ // docx/write-table-structure.ts
6774
+ var set = (element4, name, value) => element4.setAttributeNS(WORD_NS, `w:${name}`, value);
6775
+ function restructured(next, base) {
6776
+ const shape = (table) => JSON.stringify([
6777
+ table.grid,
6778
+ table.rows.map(
6779
+ (row) => row.map((cell2) => [
6780
+ cell2.paragraphs.map((p) => p.id),
6781
+ cell2.gridSpan ?? 1,
6782
+ cell2.verticalMerge ?? "",
6783
+ cell2.widthTwips
6784
+ ])
6785
+ )
6786
+ ]);
6787
+ return shape(next) !== shape(base);
6788
+ }
6789
+ function patchCellLayout(doc, tc, cell2, base) {
6790
+ const span = cell2.gridSpan ?? 1;
6791
+ const width = cell2.widthTwips;
6792
+ if (span === (base.gridSpan ?? 1) && width === base.widthTwips && cell2.verticalMerge === base.verticalMerge)
6793
+ return;
6794
+ let props = first2(tc, "tcPr");
6795
+ if (!props) {
6796
+ props = makeW(doc, "tcPr");
6797
+ tc.insertBefore(props, tc.firstChild);
6798
+ }
6799
+ const replace = (name, next) => {
6800
+ for (const old of children2(props, name)) props.removeChild(old);
6801
+ if (next) props.appendChild(next);
6802
+ };
6803
+ if (width !== base.widthTwips) {
6804
+ const old = first2(props, "tcW");
6805
+ if (width === void 0) replace("tcW", void 0);
6806
+ else {
6807
+ const element4 = old ?? makeW(doc, "tcW");
6808
+ set(element4, "w", String(width));
6809
+ set(element4, "type", "dxa");
6810
+ if (!old) props.appendChild(element4);
6811
+ }
6812
+ }
6813
+ if (span !== (base.gridSpan ?? 1)) {
6814
+ const element4 = span > 1 ? makeW(doc, "gridSpan") : void 0;
6815
+ if (element4) set(element4, "val", String(span));
6816
+ replace("gridSpan", element4);
6817
+ }
6818
+ if (cell2.verticalMerge !== base.verticalMerge) {
6819
+ const element4 = cell2.verticalMerge ? makeW(doc, "vMerge") : void 0;
6820
+ if (element4 && cell2.verticalMerge === "restart") set(element4, "val", "restart");
6821
+ replace("vMerge", element4);
6822
+ }
6823
+ orderChildren(props, CELL_ORDER);
6824
+ if (!Array.from(props.childNodes).some((node) => node.nodeType === 1) && !props.attributes.length)
6825
+ tc.removeChild(props);
6826
+ }
6827
+ function patchGrid(doc, node, table) {
6828
+ const grid = first2(node, "tblGrid");
6829
+ if (!grid || !table.grid) return;
6830
+ const old = children2(grid, "gridCol");
6831
+ table.grid.forEach((width, index) => {
6832
+ let column = old[index];
6833
+ if (!column) {
6834
+ column = makeW(doc, "gridCol");
6835
+ grid.appendChild(column);
6836
+ }
6837
+ if (column.getAttributeNS(WORD_NS, "w") !== String(width)) set(column, "w", String(width));
6838
+ });
6839
+ for (const extra of old.slice(table.grid.length)) grid.removeChild(extra);
6840
+ }
6841
+ function writeRestructuredTable(doc, table, node, base, writeParagraph, replaceSlots2, writeNested) {
6842
+ if (table.rows.some((row) => !row.length || row.some((cell2) => !cell2.paragraphs.length)))
6843
+ throw new Error("Every table row needs a cell and every cell a paragraph.");
6844
+ const oldRows = flatRows(node).map((entry2) => entry2.element);
6845
+ const oldCells = oldRows.map((tr) => flatCells(tr).map((entry2) => entry2.element));
6846
+ const cellById = /* @__PURE__ */ new Map();
6847
+ const paragraphById = /* @__PURE__ */ new Map();
6848
+ base.rows.forEach(
6849
+ (row, ri) => row.forEach((cell2, ci) => {
6850
+ const tc = oldCells[ri]?.[ci];
6851
+ if (!tc) return;
6852
+ const id = cell2.paragraphs[0]?.id;
6853
+ if (id) cellById.set(id, { tc, model: cell2, row: ri });
6854
+ const flat = flatCellParagraphs(tc);
6855
+ cell2.paragraphs.forEach((model, pi) => {
6856
+ const entry2 = flat[pi];
6857
+ if (entry2) paragraphById.set(model.id, { element: entry2.element, model });
6858
+ });
6859
+ })
6860
+ );
6861
+ const usedRows = /* @__PURE__ */ new Set();
6862
+ const usedCells = /* @__PURE__ */ new Set();
6863
+ const nextRows = table.rows.map((row, rowIndex) => {
6864
+ const sourceRow = row.map((cell2) => cellById.get(cell2.paragraphs[0]?.id ?? "")?.row).find((index) => index !== void 0 && !usedRows.has(index));
6865
+ if (sourceRow !== void 0) usedRows.add(sourceRow);
6866
+ const tr = sourceRow === void 0 ? makeW(doc, "tr") : oldRows[sourceRow] ?? makeW(doc, "tr");
6867
+ patchRowProperties(
6868
+ doc,
6869
+ tr,
6870
+ table.rowProperties?.[rowIndex],
6871
+ sourceRow === void 0 ? void 0 : base.rowProperties?.[sourceRow]
6872
+ );
6873
+ const nextCells = row.map((cell2) => {
6874
+ const source2 = cellById.get(cell2.paragraphs[0]?.id ?? "");
6875
+ const reuse = source2 && source2.row === sourceRow && !usedCells.has(source2.tc) ? source2 : void 0;
6876
+ const tc = reuse?.tc ?? makeW(doc, "tc");
6877
+ if (reuse) {
6878
+ usedCells.add(reuse.tc);
6879
+ patchCellLayout(doc, tc, cell2, reuse.model);
6880
+ patchCellBorders(doc, tc, cell2.borders, reuse.model.borders);
6881
+ patchCellShading(doc, tc, cell2, reuse.model);
6882
+ patchCellMargins(doc, tc, cell2.margins, reuse.model.margins);
6883
+ patchCellVerticalAlignment(doc, tc, cell2.verticalAlign, reuse.model.verticalAlign);
6884
+ } else {
6885
+ const props = buildCellProperties(doc, cell2);
6886
+ if (props) tc.insertBefore(props, tc.firstChild);
6887
+ }
6888
+ const oldParagraphs = reuse ? flatCellParagraphs(tc).map((entry2) => entry2.element) : [];
6889
+ const owned = new Set(oldParagraphs);
6890
+ const nextParagraphs = cell2.paragraphs.map((paragraph2) => {
6891
+ const found = paragraphById.get(paragraph2.id);
6892
+ const element4 = found ? owned.has(found.element) ? found.element : found.element.cloneNode(true) : makeW(doc, "p");
6893
+ return writeParagraph(doc, paragraph2, element4, found?.model);
6894
+ });
6895
+ replaceSlots2(doc, tc, oldParagraphs, nextParagraphs);
6896
+ if (reuse) writeNested(doc, tc, cell2, reuse.model);
6897
+ return tc;
6898
+ });
6899
+ replaceSlots2(doc, tr, sourceRow === void 0 ? [] : oldCells[sourceRow] ?? [], nextCells);
6900
+ return tr;
6901
+ });
6902
+ replaceSlots2(doc, node, oldRows, nextRows);
6903
+ patchTableMargins(doc, table, node, base);
6904
+ patchGrid(doc, node, table);
6905
+ return node;
6906
+ }
6907
+
6908
+ // docx/table-grid.ts
6909
+ var spanOf = (cell2) => Math.max(1, cell2.gridSpan ?? 1);
6910
+ function tableGrid(table) {
6911
+ const columns = table.grid?.length ?? sumSpans(table.rows[0]);
6912
+ if (!columns || !table.rows.length) return void 0;
6913
+ const rows = [];
6914
+ const cover = [];
6915
+ for (let row = 0; row < table.rows.length; row++) {
6916
+ const cells = table.rows[row] ?? [];
6917
+ if (!cells.length || sumSpans(cells) !== columns) return void 0;
6918
+ const placed = [];
6919
+ const line2 = new Array(columns);
6920
+ let col = 0;
6921
+ cells.forEach((cell2, index) => {
6922
+ const entry2 = { cell: cell2, row, index, col, span: spanOf(cell2) };
6923
+ for (let k = 0; k < entry2.span; k++) line2[col + k] = entry2;
6924
+ col += entry2.span;
6925
+ placed.push(entry2);
6926
+ });
6927
+ rows.push(placed);
6928
+ cover.push(line2);
6929
+ }
6930
+ const grid = { columns, rows, cover };
6931
+ for (const entry2 of rows.flat())
6932
+ if (entry2.cell.verticalMerge === "continue") {
6933
+ const above = entry2.row > 0 ? cover[entry2.row - 1]?.[entry2.col] : void 0;
6934
+ if (!above || above.col !== entry2.col || above.span !== entry2.span) return void 0;
6935
+ if (!above.cell.verticalMerge) return void 0;
6936
+ }
6937
+ return grid;
6938
+ }
6939
+ function sumSpans(cells) {
6940
+ return (cells ?? []).reduce((sum, cell2) => sum + spanOf(cell2), 0);
6941
+ }
6942
+
6943
+ // docx/write-table.ts
5953
6944
  var layout = (table) => table.rows.map((row) => row.map((cell2) => cell2.paragraphs.map((p) => p.id)));
5954
6945
  var TABLE_DESCRIPTOR_KEYS = [
5955
6946
  "grid",
@@ -5967,13 +6958,15 @@ function pick(source2, keys) {
5967
6958
  for (const key of keys) if (record[key] !== void 0) result[key] = record[key];
5968
6959
  return result;
5969
6960
  }
5970
- function assertNoDescriptorEdits(table, base) {
6961
+ function assertNoDescriptorEdits(table, base, layoutEdits = false) {
5971
6962
  if (!base) return;
5972
- if (JSON.stringify(pick(table, TABLE_DESCRIPTOR_KEYS)) !== JSON.stringify(pick(base, TABLE_DESCRIPTOR_KEYS)))
6963
+ const tableKeys = layoutEdits ? TABLE_DESCRIPTOR_KEYS.filter((key) => key !== "grid") : TABLE_DESCRIPTOR_KEYS;
6964
+ if (JSON.stringify(pick(table, tableKeys)) !== JSON.stringify(pick(base, tableKeys)))
5973
6965
  throw new Error(
5974
6966
  "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."
5975
6967
  );
5976
6968
  const baseCellById = /* @__PURE__ */ new Map();
6969
+ if (layoutEdits) return;
5977
6970
  for (const row of base.rows)
5978
6971
  for (const cell2 of row) {
5979
6972
  const id = cell2.paragraphs[0]?.id;
@@ -5998,11 +6991,24 @@ function writeNestedTables(doc, tc, cell2, base, writeParagraph, replaceSlots2)
5998
6991
  next.forEach((table, index) => {
5999
6992
  const node = nodes[index];
6000
6993
  if (node && before[index])
6001
- writeTable(doc, table, node, before[index], writeParagraph, replaceSlots2);
6994
+ writeTable(doc, table, node, before[index], writeParagraph, replaceSlots2, true);
6002
6995
  });
6003
6996
  }
6004
- function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
6997
+ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2, nested = false) {
6005
6998
  if (base && JSON.stringify(table) === JSON.stringify(base)) return node;
6999
+ const baseGrid = base && tableGrid(base);
7000
+ if (base && baseGrid && (nested || !base.structureEditable || table.structureEditable === false) && restructured(table, base) && canRestructureTable(node)) {
7001
+ assertNoDescriptorEdits(table, base, true);
7002
+ return writeRestructuredTable(
7003
+ doc,
7004
+ table,
7005
+ node,
7006
+ base,
7007
+ writeParagraph,
7008
+ replaceSlots2,
7009
+ (d, tc, cell2, before) => writeNestedTables(d, tc, cell2, before, writeParagraph, replaceSlots2)
7010
+ );
7011
+ }
6006
7012
  assertNoDescriptorEdits(table, base);
6007
7013
  patchTableMargins(doc, table, node, base);
6008
7014
  const structural = base && JSON.stringify(layout(table)) !== JSON.stringify(layout(base));
@@ -6128,13 +7134,13 @@ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
6128
7134
 
6129
7135
  // docx/write-footnote-columns.ts
6130
7136
  var W15 = "http://schemas.microsoft.com/office/word/2012/wordml";
6131
- var XMLNS3 = "http://www.w3.org/2000/xmlns/";
7137
+ var XMLNS4 = "http://www.w3.org/2000/xmlns/";
6132
7138
  var MC2 = "http://schemas.openxmlformats.org/markup-compatibility/2006";
6133
7139
  function prefix(doc, preferred, namespace) {
6134
7140
  let name = preferred;
6135
7141
  for (let suffix = 1; doc.documentElement.lookupNamespaceURI(name) && doc.documentElement.lookupNamespaceURI(name) !== namespace; suffix++)
6136
7142
  name = preferred + suffix;
6137
- doc.documentElement.setAttributeNS(XMLNS3, "xmlns:" + name, namespace);
7143
+ doc.documentElement.setAttributeNS(XMLNS4, "xmlns:" + name, namespace);
6138
7144
  return name;
6139
7145
  }
6140
7146
  function writeFootnoteColumns(doc, section, value) {
@@ -6156,29 +7162,8 @@ function writeFootnoteColumns(doc, section, value) {
6156
7162
  section.appendChild(element4);
6157
7163
  }
6158
7164
 
6159
- // docx/parse-diagnostics.ts
6160
- var sink;
6161
- function withParseWarnings(warnings, fn) {
6162
- const previous = sink;
6163
- sink = warnings;
6164
- try {
6165
- return fn();
6166
- } finally {
6167
- sink = previous;
6168
- }
6169
- }
6170
- function reportParseWarning(message) {
6171
- if (sink && !sink.includes(message)) sink.push(message);
6172
- }
6173
- function enumValue(guard, raw2, label) {
6174
- if (raw2 === null || raw2 === void 0 || raw2 === "") return void 0;
6175
- if (guard(raw2)) return raw2;
6176
- reportParseWarning(`Ignored invalid ${label} value \u201C${raw2}\u201D; it is not allowed by the schema.`);
6177
- return void 0;
6178
- }
6179
-
6180
7165
  // docx/table-borders.ts
6181
- var SIDES2 = [
7166
+ var SIDES3 = [
6182
7167
  "top",
6183
7168
  "bottom",
6184
7169
  "left",
@@ -6204,7 +7189,7 @@ function parseTableBorders(bordersElement) {
6204
7189
  if (!bordersElement) return void 0;
6205
7190
  const result = {};
6206
7191
  const alias = { left: "start", right: "end" };
6207
- for (const side of SIDES2) {
7192
+ for (const side of SIDES3) {
6208
7193
  const aliasName = alias[side];
6209
7194
  const value = borderSide(
6210
7195
  first2(bordersElement, side) ?? (aliasName ? first2(bordersElement, aliasName) : void 0)
@@ -6241,13 +7226,13 @@ function parseParagraphBorders(pBdr) {
6241
7226
  }
6242
7227
 
6243
7228
  // docx/page-borders.ts
6244
- var SIDES3 = ["top", "left", "bottom", "right"];
7229
+ var SIDES4 = ["top", "left", "bottom", "right"];
6245
7230
  var ATTRIBUTES = ["offsetFrom", "display", "zOrder"];
6246
7231
  var setW4 = (element4, name, value) => element4.setAttributeNS(WORD_NS, `w:${name}`, value);
6247
7232
  function parsePageBorders(element4) {
6248
7233
  if (!element4) return void 0;
6249
7234
  const result = {};
6250
- for (const side of SIDES3) {
7235
+ for (const side of SIDES4) {
6251
7236
  const source2 = first2(element4, side);
6252
7237
  const value = borderSide(source2);
6253
7238
  const art = getW(source2, "art");
@@ -6285,7 +7270,7 @@ function patchPageBorders(doc, sectPr, next, base, create2) {
6285
7270
  return;
6286
7271
  }
6287
7272
  const element4 = create2(doc, sectPr, "pgBorders");
6288
- for (const side of SIDES3) {
7273
+ for (const side of SIDES4) {
6289
7274
  if (JSON.stringify(next[side]) === JSON.stringify(base?.[side])) continue;
6290
7275
  for (const old of children2(element4, side)) element4.removeChild(old);
6291
7276
  const value = next[side];
@@ -6466,75 +7451,6 @@ function writePageNumbering(doc, sectPr, section) {
6466
7451
  }
6467
7452
  }
6468
7453
 
6469
- // docx/tab-stops.ts
6470
- function parseTabStops(tabs) {
6471
- const stops = [];
6472
- for (const tab of tabs ? children2(tabs, "tab") : []) {
6473
- const align = enumValue(isStTabJc, getW(tab, "val"), "w:tab/@w:val");
6474
- const pos = parseSignedTwips(getW(tab, "pos"));
6475
- if (!align || pos === void 0) continue;
6476
- const leader = enumValue(isStTabTlc, getW(tab, "leader"), "w:tab/@w:leader");
6477
- stops.push({ posTwips: pos, align, ...leader ? { leader } : {} });
6478
- }
6479
- return stops;
6480
- }
6481
- function writeTabStops(doc, props, paragraph2, base) {
6482
- if (base && JSON.stringify(paragraph2.tabStops ?? []) === JSON.stringify(base.tabStops ?? []))
6483
- return;
6484
- for (const tabs2 of children2(props, "tabs")) props.removeChild(tabs2);
6485
- if (!paragraph2.tabStops?.length) return;
6486
- const tabs = makeW(doc, "tabs");
6487
- for (const stop of paragraph2.tabStops) {
6488
- const tab = makeW(doc, "tab");
6489
- tab.setAttributeNS(WORD_NS, "w:val", stop.align);
6490
- if (stop.leader) tab.setAttributeNS(WORD_NS, "w:leader", stop.leader);
6491
- tab.setAttributeNS(WORD_NS, "w:pos", String(stop.posTwips));
6492
- tabs.appendChild(tab);
6493
- }
6494
- props.appendChild(tabs);
6495
- }
6496
- var PPR_ORDER = [
6497
- "pStyle",
6498
- "keepNext",
6499
- "keepLines",
6500
- "pageBreakBefore",
6501
- "framePr",
6502
- "widowControl",
6503
- "numPr",
6504
- "suppressLineNumbers",
6505
- "pBdr",
6506
- "shd",
6507
- "tabs",
6508
- "suppressAutoHyphens",
6509
- "kinsoku",
6510
- "wordWrap",
6511
- "overflowPunct",
6512
- "topLinePunct",
6513
- "autoSpaceDE",
6514
- "autoSpaceDN",
6515
- "bidi",
6516
- "adjustRightInd",
6517
- "snapToGrid",
6518
- "spacing",
6519
- "ind",
6520
- "contextualSpacing",
6521
- "mirrorIndents",
6522
- "suppressOverlap",
6523
- "jc",
6524
- "textDirection",
6525
- "textAlignment",
6526
- "textboxTightWrap",
6527
- "outlineLvl",
6528
- "divId",
6529
- "cnfStyle",
6530
- "rPr",
6531
- "sectPr",
6532
- "pPrChange"
6533
- ];
6534
- function orderParagraphProperties(props) {
6535
- orderChildren(props, PPR_ORDER);
6536
- }
6537
-
6538
7454
  // docx/write-sections.ts
6539
7455
  var WRITABLE = /* @__PURE__ */ new Set([
6540
7456
  "endsAtBlockId",
@@ -7139,16 +8055,16 @@ function isWordElement(element4, names) {
7139
8055
  }
7140
8056
  var isRevisionWrapperElement = (element4) => isWordElement(element4, REVISION_WRAPPER_NAMES2);
7141
8057
  var isCommentAnchorElement = (element4) => isWordElement(element4, COMMENT_ANCHOR_NAMES);
7142
- function setAttribute2(element4, local, value) {
8058
+ function setAttribute3(element4, local, value) {
7143
8059
  element4.setAttributeNS(WORD_NS, `w:${local}`, value);
7144
8060
  }
7145
8061
  function removeChildren(element4, local) {
7146
8062
  for (const child8 of children2(element4, local)) element4.removeChild(child8);
7147
8063
  }
7148
8064
  function writeRevisionMetadata(element4, revision) {
7149
- setAttribute2(element4, "id", revision.id);
7150
- setAttribute2(element4, "author", revision.author);
7151
- if (revision.date) setAttribute2(element4, "date", revision.date);
8065
+ setAttribute3(element4, "id", revision.id);
8066
+ setAttribute3(element4, "author", revision.author);
8067
+ if (revision.date) setAttribute3(element4, "date", revision.date);
7152
8068
  else element4.removeAttributeNS(WORD_NS, "date");
7153
8069
  if (revision.dateUtc) element4.setAttributeNS(WORD_DATE_UTC_NS, "w16du:dateUtc", revision.dateUtc);
7154
8070
  else element4.removeAttributeNS(WORD_DATE_UTC_NS, "dateUtc");
@@ -7283,184 +8199,6 @@ function restoreAnnotations(markers, before, after) {
7283
8199
  }
7284
8200
  }
7285
8201
 
7286
- // docx/write-paragraph-decoration.ts
7287
- var SIDES4 = ["top", "left", "bottom", "right", "between"];
7288
- function wordColor(color) {
7289
- const hex = /^#?([0-9a-f]{6})$/i.exec(color ?? "")?.[1];
7290
- return hex ? hex.toUpperCase() : "auto";
7291
- }
7292
- function borderElement(doc, name, side) {
7293
- const element4 = makeW(doc, name);
7294
- const set = (local, value) => element4.setAttributeNS(WORD_NS, `w:${local}`, value);
7295
- set("val", side.style ?? "single");
7296
- if (side.style !== "none" && side.style !== "nil") {
7297
- set("sz", String(side.sizeEighthPoints ?? 4));
7298
- set("space", String(side.spacePoints ?? 1));
7299
- set("color", wordColor(side.color));
7300
- if (side.themeColor) set("themeColor", side.themeColor);
7301
- }
7302
- return element4;
7303
- }
7304
- var sameJson = (a2, b) => JSON.stringify(a2 ?? null) === JSON.stringify(b ?? null);
7305
- function updateShading(doc, props, paragraph2, base) {
7306
- if (base && paragraph2.shadingFill === base.shadingFill) return;
7307
- for (const element4 of children2(props, "shd")) props.removeChild(element4);
7308
- if (!paragraph2.shadingFill) return;
7309
- const shd = makeW(doc, "shd");
7310
- shd.setAttributeNS(WORD_NS, "w:val", "clear");
7311
- shd.setAttributeNS(WORD_NS, "w:color", "auto");
7312
- shd.setAttributeNS(WORD_NS, "w:fill", wordColor(paragraph2.shadingFill));
7313
- props.appendChild(shd);
7314
- }
7315
- function updateBorders(doc, props, paragraph2, base) {
7316
- if (base && sameJson(paragraph2.borders, base.borders)) return;
7317
- for (const element4 of children2(props, "pBdr")) props.removeChild(element4);
7318
- const borders = paragraph2.borders;
7319
- if (!borders) return;
7320
- const pBdr = makeW(doc, "pBdr");
7321
- for (const side of SIDES4) {
7322
- const value = borders[side];
7323
- if (value) pBdr.appendChild(borderElement(doc, side, value));
7324
- }
7325
- if (pBdr.childNodes.length) props.appendChild(pBdr);
7326
- }
7327
- function writeParagraphDecoration(doc, props, paragraph2, base) {
7328
- updateShading(doc, props, paragraph2, base);
7329
- updateBorders(doc, props, paragraph2, base);
7330
- }
7331
-
7332
- // docx/write-paragraph-properties.ts
7333
- function setAttribute3(element4, local, value) {
7334
- element4.setAttributeNS(WORD_NS, `w:${local}`, value);
7335
- }
7336
- function setWordValue(element4, local, value) {
7337
- if (value === void 0) element4.removeAttributeNS(WORD_NS, local);
7338
- else setAttribute3(element4, local, String(value));
7339
- }
7340
- function updateDirection(doc, props, paragraph2, base) {
7341
- if (base && paragraph2.direction === base.direction) return;
7342
- let bidi = first2(props, "bidi");
7343
- if (paragraph2.direction === void 0) {
7344
- for (const element4 of children2(props, "bidi")) props.removeChild(element4);
7345
- } else {
7346
- if (!bidi) {
7347
- bidi = makeW(doc, "bidi");
7348
- props.appendChild(bidi);
7349
- }
7350
- setAttribute3(bidi, "val", paragraph2.direction === "rtl" ? "1" : "0");
7351
- }
7352
- }
7353
- function updateSpacing(doc, props, paragraph2, base) {
7354
- let spacing2 = first2(props, "spacing");
7355
- if (!spacing2) {
7356
- spacing2 = makeW(doc, "spacing");
7357
- props.appendChild(spacing2);
7358
- }
7359
- if (!base || paragraph2.spacingBeforeTwips !== base.spacingBeforeTwips)
7360
- setWordValue(spacing2, "before", paragraph2.spacingBeforeTwips);
7361
- if (!base || paragraph2.spacingAfterTwips !== base.spacingAfterTwips)
7362
- setWordValue(spacing2, "after", paragraph2.spacingAfterTwips);
7363
- if (!base || paragraph2.lineSpacingTwips !== base.lineSpacingTwips || paragraph2.lineSpacingRule !== base.lineSpacingRule) {
7364
- setWordValue(spacing2, "line", paragraph2.lineSpacingTwips);
7365
- setWordValue(
7366
- spacing2,
7367
- "lineRule",
7368
- paragraph2.lineSpacingRule ?? (paragraph2.lineSpacingTwips === void 0 ? void 0 : "auto")
7369
- );
7370
- }
7371
- if (!spacing2.attributes.length && !spacing2.childNodes.length) props.removeChild(spacing2);
7372
- }
7373
- function updateIndent(doc, props, paragraph2, base) {
7374
- let indent = first2(props, "ind");
7375
- if (!indent) {
7376
- indent = makeW(doc, "ind");
7377
- props.appendChild(indent);
7378
- }
7379
- if (!base || paragraph2.indentLeftTwips !== base.indentLeftTwips)
7380
- setWordValue(indent, "left", paragraph2.indentLeftTwips);
7381
- if (!base || paragraph2.indentRightTwips !== base.indentRightTwips)
7382
- setWordValue(indent, "right", paragraph2.indentRightTwips);
7383
- if (!base || paragraph2.indentStartTwips !== base.indentStartTwips)
7384
- setWordValue(indent, "start", paragraph2.indentStartTwips);
7385
- if (!base || paragraph2.indentEndTwips !== base.indentEndTwips)
7386
- setWordValue(indent, "end", paragraph2.indentEndTwips);
7387
- if (!base || paragraph2.firstLineTwips !== base.firstLineTwips)
7388
- setWordValue(indent, "firstLine", paragraph2.firstLineTwips);
7389
- if (!base || paragraph2.hangingTwips !== base.hangingTwips)
7390
- setWordValue(indent, "hanging", paragraph2.hangingTwips);
7391
- if (!indent.attributes.length) props.removeChild(indent);
7392
- }
7393
- function updatePageBreakBefore(doc, props, paragraph2, base) {
7394
- if (base && paragraph2.pageBreakBefore === base.pageBreakBefore) return;
7395
- for (const element4 of children2(props, "pageBreakBefore")) props.removeChild(element4);
7396
- if (paragraph2.pageBreakBefore !== void 0) {
7397
- const element4 = makeW(doc, "pageBreakBefore");
7398
- if (!paragraph2.pageBreakBefore) element4.setAttributeNS(WORD_NS, "w:val", "0");
7399
- props.appendChild(element4);
7400
- }
7401
- }
7402
- function updateKeepOptions(doc, props, paragraph2, base) {
7403
- for (const key of [
7404
- "keepNext",
7405
- "keepLines",
7406
- "widowControl",
7407
- "contextualSpacing",
7408
- "suppressLineNumbers"
7409
- ]) {
7410
- if (base && paragraph2[key] === base[key]) continue;
7411
- for (const element5 of children2(props, key)) props.removeChild(element5);
7412
- const value = paragraph2[key];
7413
- if (value === void 0) continue;
7414
- const element4 = makeW(doc, key);
7415
- if (!value) setAttribute3(element4, "val", "0");
7416
- props.appendChild(element4);
7417
- }
7418
- }
7419
- function updateDropCap(doc, props, paragraph2, base) {
7420
- if (base && JSON.stringify(paragraph2.dropCap) === JSON.stringify(base.dropCap)) return;
7421
- let frame2 = first2(props, "framePr");
7422
- const cap = paragraph2.dropCap;
7423
- if (!cap) {
7424
- if (frame2) props.removeChild(frame2);
7425
- return;
7426
- }
7427
- if (!frame2) {
7428
- frame2 = makeW(doc, "framePr");
7429
- props.appendChild(frame2);
7430
- setAttribute3(frame2, "wrap", "around");
7431
- setAttribute3(frame2, "vAnchor", "text");
7432
- setAttribute3(frame2, "hAnchor", "text");
7433
- }
7434
- setAttribute3(frame2, "dropCap", cap.style);
7435
- setAttribute3(frame2, "lines", String(cap.lines));
7436
- setWordValue(frame2, "hSpace", cap.distanceTwips);
7437
- }
7438
- function writeParagraphProperties(doc, props, paragraph2, base) {
7439
- updatePageBreakBefore(doc, props, paragraph2, base);
7440
- updateKeepOptions(doc, props, paragraph2, base);
7441
- updateDropCap(doc, props, paragraph2, base);
7442
- updateDirection(doc, props, paragraph2, base);
7443
- writeParagraphDecoration(doc, props, paragraph2, base);
7444
- const spacingKeys = [
7445
- "spacingBeforeTwips",
7446
- "spacingAfterTwips",
7447
- "lineSpacingTwips",
7448
- "lineSpacingRule"
7449
- ];
7450
- if (!base || spacingKeys.some((key) => paragraph2[key] !== base[key]))
7451
- updateSpacing(doc, props, paragraph2, base);
7452
- const indentKeys = [
7453
- "indentLeftTwips",
7454
- "indentRightTwips",
7455
- "indentStartTwips",
7456
- "indentEndTwips",
7457
- "firstLineTwips",
7458
- "hangingTwips"
7459
- ];
7460
- if (!base || indentKeys.some((key) => paragraph2[key] !== base[key]))
7461
- updateIndent(doc, props, paragraph2, base);
7462
- }
7463
-
7464
8202
  // docx/bookmarks.ts
7465
8203
  function paragraphBookmarkNames(node) {
7466
8204
  return children2(node, "bookmarkStart").map((el5) => getW(el5, "name")).filter((name) => Boolean(name));
@@ -7510,41 +8248,6 @@ function writeNumberingProperties(doc, props, paragraph2, base) {
7510
8248
  props.appendChild(numPr);
7511
8249
  }
7512
8250
 
7513
- // docx/paragraph-alignment.ts
7514
- function alignFromJustification(jc, rtl) {
7515
- switch (jc) {
7516
- case "left":
7517
- case "center":
7518
- case "right":
7519
- return jc;
7520
- case "start":
7521
- return rtl ? "right" : "left";
7522
- case "end":
7523
- return rtl ? "left" : "right";
7524
- case "both":
7525
- case "distribute":
7526
- case "thaiDistribute":
7527
- case "mediumKashida":
7528
- case "highKashida":
7529
- case "lowKashida":
7530
- return "justify";
7531
- default:
7532
- return void 0;
7533
- }
7534
- }
7535
- function paragraphJustification(paragraph2) {
7536
- const { align, justification } = paragraph2;
7537
- if (justification && alignFromJustification(justification, paragraph2.direction === "rtl") === align)
7538
- return justification;
7539
- return align === void 0 ? void 0 : align === "justify" ? "both" : align;
7540
- }
7541
- function parseJustification(pPr) {
7542
- const justification = enumValue(isStJc, getW(first2(pPr, "jc"), "val"), "w:jc");
7543
- if (!justification) return {};
7544
- const align = alignFromJustification(justification, onOffElement(first2(pPr, "bidi")) === true);
7545
- return { justification, ...align ? { align } : {} };
7546
- }
7547
-
7548
8251
  // docx/underline.ts
7549
8252
  var WORD_UNDERLINE_TOKENS = [
7550
8253
  "single",
@@ -8420,7 +9123,7 @@ function applyPictureEffects(blip, effects) {
8420
9123
  const node = source2 ? blip.ownerDocument.importNode(source2, true) : blip.ownerDocument.createElementNS(NS.a, `a:${name}`);
8421
9124
  if (effect.kind !== "unsupported" && (node.namespaceURI !== NS.a || node.localName !== name))
8422
9125
  throw new Error("Picture effect source does not match its kind");
8423
- const set = (name2, value) => {
9126
+ const set2 = (name2, value) => {
8424
9127
  const original = picturePercentage(node.getAttribute(name2));
8425
9128
  if (value === void 0) node.removeAttribute(name2);
8426
9129
  else if (value !== original) {
@@ -8433,12 +9136,12 @@ function applyPictureEffects(blip, effects) {
8433
9136
  (value) => value !== void 0 && (!Number.isFinite(value) || Math.abs(value) > 1)
8434
9137
  ))
8435
9138
  throw new RangeError("Picture luminance must be between -1 and 1");
8436
- set("bright", effect.brightness);
8437
- set("contrast", effect.contrast);
9139
+ set2("bright", effect.brightness);
9140
+ set2("contrast", effect.contrast);
8438
9141
  }
8439
9142
  if (effect.kind === "alphaModFix") {
8440
9143
  if (effect.amount < 0) throw new RangeError("Picture alpha must be nonnegative");
8441
- set("amt", effect.amount);
9144
+ set2("amt", effect.amount);
8442
9145
  }
8443
9146
  return node;
8444
9147
  });
@@ -10938,10 +11641,10 @@ function writeDrawingRichTextBody(container2, body) {
10938
11641
  const paragraphs = body.paragraphs.length ? body.paragraphs : [{ items: [] }];
10939
11642
  for (const paragraph2 of paragraphs) container2.appendChild(writeDrawingParagraph(doc, paragraph2));
10940
11643
  }
10941
- function drawingRichTextBodyXml(body, qualifiedName = "a:txBody", namespace = NS.a) {
10942
- const prefix2 = qualifiedName.includes(":") ? qualifiedName.split(":")[0] : void 0;
11644
+ function drawingRichTextBodyXml(body, qualifiedName2 = "a:txBody", namespace = NS.a) {
11645
+ const prefix2 = qualifiedName2.includes(":") ? qualifiedName2.split(":")[0] : void 0;
10943
11646
  const declaration = prefix2 && prefix2 !== "a" ? ` xmlns:${prefix2}="${namespace}"` : "";
10944
- const doc = parseXml(`<${qualifiedName}${declaration} xmlns:a="${NS.a}" xmlns:r="${NS.r}"/>`);
11647
+ const doc = parseXml(`<${qualifiedName2}${declaration} xmlns:a="${NS.a}" xmlns:r="${NS.r}"/>`);
10945
11648
  writeDrawingRichTextBody(doc.documentElement, body);
10946
11649
  return buildXml(doc);
10947
11650
  }
@@ -17866,7 +18569,8 @@ var pie = {
17866
18569
  gd16("stAng", "pin 0 adj1 21599999"),
17867
18570
  gd16("endAng", "pin 0 adj2 21599999"),
17868
18571
  gd16("swAng", "+- endAng 0 stAng"),
17869
- gd16("swAng2", "?: swAng swAng +- 21600000 swAng 0"),
18572
+ gd16("swAngWrap", "+- swAng 21600000 0"),
18573
+ gd16("swAng2", "?: swAng swAng swAngWrap"),
17870
18574
  gd16("stx", "cos wd2 stAng"),
17871
18575
  gd16("sty", "sin hd2 stAng"),
17872
18576
  gd16("x1", "+- hc stx 0"),
@@ -17911,7 +18615,8 @@ var chord = {
17911
18615
  gd16("stAng", "pin 0 adj1 21599999"),
17912
18616
  gd16("endAng", "pin 0 adj2 21599999"),
17913
18617
  gd16("swAng", "+- endAng 0 stAng"),
17914
- gd16("swAng2", "?: swAng swAng +- 21600000 swAng 0"),
18618
+ gd16("swAngWrap", "+- swAng 21600000 0"),
18619
+ gd16("swAng2", "?: swAng swAng swAngWrap"),
17915
18620
  gd16("stx", "cos wd2 stAng"),
17916
18621
  gd16("sty", "sin hd2 stAng"),
17917
18622
  gd16("x1", "+- hc stx 0"),
@@ -17935,7 +18640,8 @@ var arc = {
17935
18640
  gd16("stAng", "pin 0 adj1 21599999"),
17936
18641
  gd16("endAng", "pin 0 adj2 21599999"),
17937
18642
  gd16("swAng", "+- endAng 0 stAng"),
17938
- gd16("swAng2", "?: swAng swAng +- 21600000 swAng 0"),
18643
+ gd16("swAngWrap", "+- swAng 21600000 0"),
18644
+ gd16("swAng2", "?: swAng swAng swAngWrap"),
17939
18645
  gd16("stx", "cos wd2 stAng"),
17940
18646
  gd16("sty", "sin hd2 stAng"),
17941
18647
  gd16("x1", "+- hc stx 0"),
@@ -18030,7 +18736,8 @@ var blockArc = {
18030
18736
  gd16("iwd2", "+- wd2 0 thw"),
18031
18737
  gd16("ihd2", "+- hd2 0 thh2"),
18032
18738
  gd16("swAng", "+- endAng 0 stAng"),
18033
- gd16("swAng2", "?: swAng swAng +- 21600000 swAng 0"),
18739
+ gd16("swAngWrap", "+- swAng 21600000 0"),
18740
+ gd16("swAng2", "?: swAng swAng swAngWrap"),
18034
18741
  gd16("mswAng", "+- 0 0 swAng2"),
18035
18742
  gd16("stx", "cos wd2 stAng"),
18036
18743
  gd16("sty", "sin hd2 stAng"),
@@ -20193,12 +20900,12 @@ function shapeParagraphs(wsp) {
20193
20900
  function textIsPlain(wsp) {
20194
20901
  const content = child5(child5(wsp, WPS_NS2, "txbx"), W_NS2, "txbxContent");
20195
20902
  if (!content) return true;
20196
- const only = (node, allowed) => elementsOf(node).every(
20903
+ const only2 = (node, allowed) => elementsOf(node).every(
20197
20904
  (item2) => item2.namespaceURI === W_NS2 && allowed.includes(item2.localName)
20198
20905
  );
20199
- return only(content, ["p"]) && Array.from(content.getElementsByTagNameNS(W_NS2, "p")).every(
20200
- (paragraph2) => only(paragraph2, ["pPr", "r"]) && Array.from(paragraph2.getElementsByTagNameNS(W_NS2, "r")).every(
20201
- (run2) => only(run2, ["rPr", "t"])
20906
+ return only2(content, ["p"]) && Array.from(content.getElementsByTagNameNS(W_NS2, "p")).every(
20907
+ (paragraph2) => only2(paragraph2, ["pPr", "r"]) && Array.from(paragraph2.getElementsByTagNameNS(W_NS2, "r")).every(
20908
+ (run2) => only2(run2, ["rPr", "t"])
20202
20909
  )
20203
20910
  );
20204
20911
  }
@@ -20441,7 +21148,7 @@ function parseAttributes(source2) {
20441
21148
  }
20442
21149
  return attrs2;
20443
21150
  }
20444
- function tagEnd(xml, from) {
21151
+ function tagEnd2(xml, from) {
20445
21152
  let quote = "";
20446
21153
  for (let i2 = from; i2 < xml.length; i2++) {
20447
21154
  const ch = xml[i2];
@@ -20472,7 +21179,7 @@ function parseOrderedXml(xml) {
20472
21179
  i2 = close < 0 ? -1 : xml.indexOf("<", close + 3);
20473
21180
  continue;
20474
21181
  }
20475
- const end = tagEnd(xml, i2 + 1);
21182
+ const end = tagEnd2(xml, i2 + 1);
20476
21183
  if (end < 0) {
20477
21184
  break;
20478
21185
  }
@@ -21052,17 +21759,17 @@ function isShadowedBound(node, constraint) {
21052
21759
 
21053
21760
  // diagram/engine/constraint-eval.ts
21054
21761
  function relatedNodes(node, relation2, name, ptType) {
21055
- const matches = (candidate) => (!name || candidate.name === name) && (matchesPointType(candidate.point, ptType) || candidate.presOf.length > 0 && matchesPointType(candidate.presOf[0], ptType));
21762
+ const matches2 = (candidate) => (!name || candidate.name === name) && (matchesPointType(candidate.point, ptType) || candidate.presOf.length > 0 && matchesPointType(candidate.presOf[0], ptType));
21056
21763
  if (relation2 === "self") {
21057
21764
  return name && node.name !== name ? [] : [node];
21058
21765
  }
21059
21766
  if (relation2 === "ch") {
21060
- return node.children.filter(matches);
21767
+ return node.children.filter(matches2);
21061
21768
  }
21062
21769
  const out = [];
21063
21770
  const visit = (current) => {
21064
21771
  for (const child8 of current.children) {
21065
- if (matches(child8)) {
21772
+ if (matches2(child8)) {
21066
21773
  out.push(child8);
21067
21774
  }
21068
21775
  visit(child8);
@@ -28220,8 +28927,8 @@ function parseDisplayUnits(context, element4) {
28220
28927
 
28221
28928
  // chart/write-util.ts
28222
28929
  var INVALID_XML = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/g;
28223
- var escapeText = (value) => value.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
28224
- var escapeAttribute = (value) => escapeText(value).replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;").replace(/\t/g, "&#9;");
28930
+ var escapeText2 = (value) => value.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
28931
+ var escapeAttribute = (value) => escapeText2(value).replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;").replace(/\t/g, "&#9;");
28225
28932
  function chartNumber(value) {
28226
28933
  if (!Number.isFinite(value)) throw new Error(`Chart number ${value} is not finite`);
28227
28934
  const text = String(value);
@@ -28901,7 +29608,7 @@ function run(value) {
28901
29608
  const hasProperties = Object.keys(properties).length > 0;
28902
29609
  if (text === "\n")
28903
29610
  return hasProperties ? `<a:br>${runProperties("rPr", properties)}</a:br>` : "<a:br/>";
28904
- return `<a:r>${hasProperties ? runProperties("rPr", properties) : ""}<a:t>${escapeText(text)}</a:t></a:r>`;
29611
+ return `<a:r>${hasProperties ? runProperties("rPr", properties) : ""}<a:t>${escapeText2(text)}</a:t></a:r>`;
28905
29612
  }
28906
29613
  function paragraph(value) {
28907
29614
  const align = value.align ? ` algn="${escapeAttribute(value.align)}"` : "";
@@ -29021,7 +29728,7 @@ function numberFormatXml(format) {
29021
29728
  }
29022
29729
 
29023
29730
  // chart/write-text.ts
29024
- var textElement = (local, value) => `<c:${local}>${escapeText(value)}</c:${local}>`;
29731
+ var textElement = (local, value) => `<c:${local}>${escapeText2(value)}</c:${local}>`;
29025
29732
  function cachePoints(cache) {
29026
29733
  return cache.points.map((point, position2) => {
29027
29734
  const format = point.formatCode === void 0 ? "" : ` formatCode="${escapeAttribute(point.formatCode)}"`;
@@ -29151,7 +29858,7 @@ function trendlineLabelXml(context, label) {
29151
29858
  function trendlineXml(context, trendline) {
29152
29859
  return elementXml(
29153
29860
  "trendline",
29154
- (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)
29861
+ (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)
29155
29862
  );
29156
29863
  }
29157
29864
  function errorBarsXml(context, bars) {
@@ -29896,7 +30603,7 @@ function attributes(entries) {
29896
30603
  }).join("");
29897
30604
  }
29898
30605
  var cxElement = (local, content = "", attrs2 = "") => content ? `<cx:${local}${attrs2}>${content}</cx:${local}>` : `<cx:${local}${attrs2}/>`;
29899
- var cxText = (local, text, attrs2 = "") => text === void 0 ? "" : `<cx:${local}${attrs2}>${escapeText(text)}</cx:${local}>`;
30606
+ var cxText = (local, text, attrs2 = "") => text === void 0 ? "" : `<cx:${local}${attrs2}>${escapeText2(text)}</cx:${local}>`;
29900
30607
  var cxVal = (local, value) => value === void 0 ? "" : `<cx:${local}${attributes([["val", value]])}/>`;
29901
30608
  var formulaXml = (local, formula2) => formula2 ? cxText(local, formula2.formula, attributes([["dir", formula2.direction]])) : "";
29902
30609
  var shapeXml = (context, shape) => shape ? cxElement("spPr", shapePropertiesInnerXml(context, shape)) : "";
@@ -31666,6 +32373,10 @@ var WRAPS = [
31666
32373
  function parsePlacement(anchor) {
31667
32374
  const wrap2 = WRAPS.find(([local]) => firstNS(anchor, WP_NS2, local))?.[1] ?? "none";
31668
32375
  const placement = { wrap: wrap2 };
32376
+ const wrapElement2 = WRAPS.map(([local]) => firstNS(anchor, WP_NS2, local)).find(Boolean);
32377
+ const wrapText = wrapElement2?.getAttribute("wrapText");
32378
+ if (wrapText === "bothSides" || wrapText === "left" || wrapText === "right" || wrapText === "largest")
32379
+ placement.wrapText = wrapText;
31669
32380
  if (anchor.getAttribute("behindDoc") === "1") placement.behindText = true;
31670
32381
  const positionH = firstNS(anchor, WP_NS2, "positionH");
31671
32382
  const relativeFrom = enumValue(
@@ -32097,6 +32808,34 @@ function chartRun(doc, node, image, base, oldDrawing, oldContainer, allocator) {
32097
32808
  return void 0;
32098
32809
  }
32099
32810
 
32811
+ // docx/write-fallback.ts
32812
+ var PT_PER_PX2 = 0.75;
32813
+ function setStyleSize(style, name, pt) {
32814
+ const value = `${Math.round(pt * 100) / 100}pt`;
32815
+ const pattern = new RegExp(`(^|;)\\s*${name}\\s*:\\s*[^;]*`, "i");
32816
+ return pattern.test(style) ? style.replace(pattern, (_all, lead) => `${lead}${name}:${value}`) : style;
32817
+ }
32818
+ function patchFallbackSize(content, image, base) {
32819
+ if (!base || image.widthPx === base.widthPx && image.heightPx === base.heightPx) return;
32820
+ const fallback = Array.from(content.childNodes).filter(isElement).find((node) => node.localName === "Fallback");
32821
+ if (!fallback) return;
32822
+ const stack = [fallback];
32823
+ while (stack.length) {
32824
+ const node = stack.pop();
32825
+ const style = node.getAttribute("style");
32826
+ if (style && /(^|;)\s*width\s*:/i.test(style)) {
32827
+ let next = style;
32828
+ if (image.widthPx !== base.widthPx)
32829
+ next = setStyleSize(next, "width", image.widthPx * PT_PER_PX2);
32830
+ if (image.heightPx !== base.heightPx)
32831
+ next = setStyleSize(next, "height", image.heightPx * PT_PER_PX2);
32832
+ node.setAttribute("style", next);
32833
+ continue;
32834
+ }
32835
+ for (const child8 of Array.from(node.childNodes)) if (isElement(child8)) stack.push(child8);
32836
+ }
32837
+ }
32838
+
32100
32839
  // docx/diagram-document.ts
32101
32840
  function diagramsIn(blocks) {
32102
32841
  const diagrams = [];
@@ -32720,6 +33459,13 @@ function createImageRun(doc, image, base, old, allocator) {
32720
33459
  }
32721
33460
  if (base && oldDrawing && image.shape?.editable && base.shape?.editable) {
32722
33461
  const next = rebuildShapeDrawing(doc, image, oldDrawing);
33462
+ const choice = oldDrawing.parentNode;
33463
+ if (oldContainer?.localName === "AlternateContent" && choice) {
33464
+ choice.replaceChild(next, oldDrawing);
33465
+ patchFallbackSize(oldContainer, image, base);
33466
+ clearNonProperties(node, oldContainer);
33467
+ return node;
33468
+ }
32723
33469
  clearNonProperties(node);
32724
33470
  node.appendChild(next);
32725
33471
  return node;
@@ -33931,15 +34677,15 @@ function runIsSafe(run2) {
33931
34677
  const content = Array.from(run2.childNodes).filter(
33932
34678
  (child8) => isElement(child8) && !named2(child8, "rPr") && !isCachedPageBreak(child8)
33933
34679
  );
33934
- const only = content.length === 1 ? content[0] : void 0;
33935
- if (only && named2(only, "br") && isModeledBreak(only)) return true;
33936
- if (only && ["footnoteReference", "endnoteReference", "footnoteRef", "endnoteRef"].some(
33937
- (name) => named2(only, name)
34680
+ const only2 = content.length === 1 ? content[0] : void 0;
34681
+ if (only2 && named2(only2, "br") && isModeledBreak(only2)) return true;
34682
+ if (only2 && ["footnoteReference", "endnoteReference", "footnoteRef", "endnoteRef"].some(
34683
+ (name) => named2(only2, name)
33938
34684
  ))
33939
34685
  return true;
33940
- if (only && named2(only, "fldChar")) {
33941
- const type = getW(only, "fldCharType") ?? "";
33942
- const data = Array.from(only.childNodes).filter(
34686
+ if (only2 && named2(only2, "fldChar")) {
34687
+ const type = getW(only2, "fldCharType") ?? "";
34688
+ const data = Array.from(only2.childNodes).filter(
33943
34689
  (node) => isElement(node) || Boolean(node.textContent?.trim())
33944
34690
  );
33945
34691
  if (!data.length) return ["begin", "separate", "end"].includes(type);
@@ -34072,6 +34818,10 @@ function parseFormatting(pPr) {
34072
34818
  const line2 = signedTwipValue(getW(spacing2, "line"));
34073
34819
  if (before !== void 0) result.spacingBeforeTwips = before;
34074
34820
  if (after !== void 0) result.spacingAfterTwips = after;
34821
+ const beforeAuto = parseOnOff(getW(spacing2, "beforeAutospacing"));
34822
+ const afterAuto = parseOnOff(getW(spacing2, "afterAutospacing"));
34823
+ if (beforeAuto !== void 0) result.spacingBeforeAuto = beforeAuto;
34824
+ if (afterAuto !== void 0) result.spacingAfterAuto = afterAuto;
34075
34825
  if (line2 !== void 0) result.lineSpacingTwips = line2;
34076
34826
  const rule = getW(spacing2, "lineRule");
34077
34827
  if (rule === "auto" || rule === "exact" || rule === "atLeast") result.lineSpacingRule = rule;
@@ -34201,6 +34951,10 @@ function parseDirectParagraphProperties(props) {
34201
34951
  const line2 = signedTwipValue2(getW(spacing2, "line"));
34202
34952
  if (before !== void 0) paragraph2.spacingBeforeTwips = before;
34203
34953
  if (after !== void 0) paragraph2.spacingAfterTwips = after;
34954
+ const beforeAuto = parseOnOff(getW(spacing2, "beforeAutospacing"));
34955
+ const afterAuto = parseOnOff(getW(spacing2, "afterAutospacing"));
34956
+ if (beforeAuto !== void 0) paragraph2.spacingBeforeAuto = beforeAuto;
34957
+ if (afterAuto !== void 0) paragraph2.spacingAfterAuto = afterAuto;
34204
34958
  if (line2 !== void 0) {
34205
34959
  paragraph2.lineSpacingTwips = line2;
34206
34960
  }
@@ -34232,8 +34986,8 @@ function parseDirectParagraphProperties(props) {
34232
34986
 
34233
34987
  // docx/run-segmentation.ts
34234
34988
  var basisOf = (run2) => run2.restoredRunPropertiesXml ?? run2.sourceRunPropertiesXml;
34235
- function keepsUnmodeledProperties(before, after) {
34236
- const owners = (runs) => runs.flatMap((run2) => Array.from({ length: positionText(run2).length }, () => basisOf(run2)));
34989
+ function keepsUnmodeledProperties(before, after, basis = basisOf) {
34990
+ const owners = (runs) => runs.flatMap((run2) => Array.from({ length: positionText(run2).length }, () => basis(run2)));
34237
34991
  const was = owners(before);
34238
34992
  const now = owners(after);
34239
34993
  const kept = (from, to, shift) => {
@@ -34267,13 +35021,22 @@ function runsToWriteAnew(paragraph2, base, slots) {
34267
35021
  return !remaining.length || remaining.every((run2) => run2.restoredRunPropertiesXml || run2.sourceRunPropertiesXml);
34268
35022
  }))
34269
35023
  return none;
34270
- if (paragraph2.runs.every(
34271
- (run2) => !run2.image && !run2.equation && (run2.restoredRunPropertiesXml || run2.sourceRunPropertiesXml)
34272
- ))
34273
- return none;
34274
35024
  const sameText = paragraph2.runs.map((run2) => run2.text).join("") === base.runs.map((run2) => run2.text).join("");
34275
35025
  const sameBoundaries = paragraph2.runs.length === base.runs.length && paragraph2.runs.every((run2, index) => run2.text === base.runs[index]?.text);
34276
35026
  if (sameBoundaries || !sameText && paragraph2.runs.length === base.runs.length) return none;
35027
+ if (paragraph2.runs.every(
35028
+ (run2) => !run2.image && !run2.equation && (run2.restoredRunPropertiesXml || run2.sourceRunPropertiesXml)
35029
+ )) {
35030
+ if (keepsUnmodeledProperties(
35031
+ base.runs,
35032
+ paragraph2.runs,
35033
+ (run2) => run2.sourceRunPropertiesXml ?? run2.restoredRunPropertiesXml
35034
+ ))
35035
+ return none;
35036
+ throw new Error(
35037
+ `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.`
35038
+ );
35039
+ }
34277
35040
  const object = (run2) => Boolean(run2.image || run2.equation);
34278
35041
  if (!paragraph2.runs.some(object) && !base.runs.some(object) && keepsUnmodeledProperties(base.runs, paragraph2.runs))
34279
35042
  return new Set(
@@ -35410,14 +36173,14 @@ async function applyNumberingCatalog(zip, model, binding) {
35410
36173
  }
35411
36174
 
35412
36175
  // docx/style-numbering-package.ts
35413
- var STYLES_PART = "word/styles.xml";
35414
- var AFTER_PPR = ["rPr", "tblPr", "trPr", "tcPr", "tblStylePr"];
36176
+ var STYLES_PART2 = "word/styles.xml";
36177
+ var AFTER_PPR2 = ["rPr", "tblPr", "trPr", "tcPr", "tblStylePr"];
35415
36178
  var withoutNumbering = (catalog) => catalog ? {
35416
36179
  ...catalog,
35417
36180
  styles: Object.fromEntries(
35418
36181
  Object.entries(catalog.styles).map(([id, style]) => {
35419
- const { numbering: _numbering, ...rest } = style;
35420
- return [id, rest];
36182
+ const { numbering: _numbering, formatting, ...rest } = style;
36183
+ return [id, { ...rest, formatting: unwritableFormatting(formatting) }];
35421
36184
  })
35422
36185
  )
35423
36186
  } : void 0;
@@ -35430,7 +36193,7 @@ function setNumPr(style, numbering) {
35430
36193
  if (!numbering && !pPr) return;
35431
36194
  if (!pPr) {
35432
36195
  pPr = makeW(doc, "pPr");
35433
- const anchor = elementsOf2(style).find((child8) => AFTER_PPR.includes(child8.localName)) ?? null;
36196
+ const anchor = elementsOf2(style).find((child8) => AFTER_PPR2.includes(child8.localName)) ?? null;
35434
36197
  style.insertBefore(pPr, anchor);
35435
36198
  }
35436
36199
  for (const existing of children2(pPr, "numPr")) pPr.removeChild(existing);
@@ -35454,7 +36217,7 @@ async function applyStyleNumbering(zip, model, base) {
35454
36217
  (id) => JSON.stringify(next[id]?.numbering) !== JSON.stringify(prior[id]?.numbering)
35455
36218
  );
35456
36219
  if (!changed.length) return;
35457
- const file = zip.file(STYLES_PART);
36220
+ const file = zip.file(STYLES_PART2);
35458
36221
  if (!file) throw new Error("Cannot link styles to a list: the package has no styles.xml.");
35459
36222
  const doc = parseXml2(await file.async("string"));
35460
36223
  const styles = children2(doc.documentElement, "style");
@@ -35465,7 +36228,7 @@ async function applyStyleNumbering(zip, model, base) {
35465
36228
  if (!style) throw new Error(`Cannot link style "${id}" to a list: it is not in styles.xml.`);
35466
36229
  setNumPr(style, next[id]?.numbering);
35467
36230
  }
35468
- zip.file(STYLES_PART, buildXml(doc));
36231
+ zip.file(STYLES_PART2, buildXml(doc));
35469
36232
  }
35470
36233
 
35471
36234
  // docx/write-header-footer.ts
@@ -37005,7 +37768,7 @@ function headerFooterResults(model) {
37005
37768
  return void 0;
37006
37769
  }
37007
37770
  }
37008
- async function saveDocx(model, pendingMedia) {
37771
+ async function saveDocx(model, pendingMedia, options) {
37009
37772
  const ids = /* @__PURE__ */ new Set();
37010
37773
  for (const block of model.blocks) {
37011
37774
  if (ids.has(block.id)) throw new Error(`Duplicate document block id: ${block.id}`);
@@ -37096,6 +37859,7 @@ async function saveDocx(model, pendingMedia) {
37096
37859
  await applyNumberingCatalog(zip, model, binding);
37097
37860
  await applyCoreProperties(zip, model.properties, binding?.base.properties);
37098
37861
  if (binding) await applyStyleNumbering(zip, model, binding.base);
37862
+ if (binding) await applyStyleFormatting(zip, model, binding.base);
37099
37863
  if (model.compatibilityMode !== binding?.base.compatibilityMode)
37100
37864
  await applyCompatibilityMode(zip, model.compatibilityMode);
37101
37865
  if (Boolean(model.evenAndOddHeaders) !== Boolean(binding?.base.evenAndOddHeaders))
@@ -37127,6 +37891,8 @@ async function saveDocx(model, pendingMedia) {
37127
37891
  }
37128
37892
  if (JSON.stringify(model.comments ?? []) !== JSON.stringify(binding?.base.comments ?? []))
37129
37893
  await applyComments(zip, model.comments ?? []);
37894
+ if (binding) await applyDataBindings(zip, model, binding.base, binding.context.sourceXml);
37895
+ if (binding) await stampModified(zip, options?.modified);
37130
37896
  dropAddedFolders(zip, sourceEntries);
37131
37897
  return zip.generateAsync({ type: "uint8array", compression: "DEFLATE" });
37132
37898
  }
@@ -37182,8 +37948,11 @@ function parseCell(cell2, parseParagraph3, id, control) {
37182
37948
  const element4 = child8;
37183
37949
  if (element4.namespaceURI !== WORD_NS) return [];
37184
37950
  if (element4.localName === "p") return [result.paragraphs[paragraphIndex++]];
37185
- if (element4.localName === "tbl")
37186
- return [parseTable(element4, `${id}-nested${tableIndex++}`, parseParagraph3)];
37951
+ if (element4.localName === "tbl") {
37952
+ const inner = parseTable(element4, `${id}-nested${tableIndex++}`, parseParagraph3);
37953
+ markRestructurable(inner, element4);
37954
+ return [inner];
37955
+ }
37187
37956
  return [];
37188
37957
  }
37189
37958
  );
@@ -37239,6 +38008,9 @@ function parseRowProperties(row) {
37239
38008
  if (onOffElement(first2(trPr, "tblHeader"))) result.header = true;
37240
38009
  return result;
37241
38010
  }
38011
+ function markRestructurable(table, node) {
38012
+ if (canRestructureTable(node) && tableGrid(table)) table.restructurable = true;
38013
+ }
37242
38014
  function parseTable(node, id, parseParagraph3) {
37243
38015
  const rowEntries = flatRows(node);
37244
38016
  const rows = rowEntries.map(
@@ -37279,6 +38051,7 @@ function parseTable(node, id, parseParagraph3) {
37279
38051
  return properties;
37280
38052
  });
37281
38053
  if (rowProperties.some((row) => Object.keys(row).length)) table.rowProperties = rowProperties;
38054
+ if (!table.structureEditable) markRestructurable(table, node);
37282
38055
  return table;
37283
38056
  }
37284
38057
 
@@ -37412,23 +38185,23 @@ function parseRun2(node, revision) {
37412
38185
  let noteSeparator;
37413
38186
  let fieldChar;
37414
38187
  const fieldCode = content.length > 0 && content.every((child8) => named2(child8, "instrText")) ? content.map((child8) => textContent(child8)).join("") : void 0;
37415
- const only = content.length === 1 ? content[0] : void 0;
37416
- if (only) {
37417
- if (named2(only, "br")) {
37418
- const kind = classifyBreak(only);
38188
+ const only2 = content.length === 1 ? content[0] : void 0;
38189
+ if (only2) {
38190
+ if (named2(only2, "br")) {
38191
+ const kind = classifyBreak(only2);
37419
38192
  if (kind === "page" || kind === "column") breakKind = kind;
37420
- } else if (named2(only, "footnoteReference")) {
37421
- const id = getW(only, "id");
38193
+ } else if (named2(only2, "footnoteReference")) {
38194
+ const id = getW(only2, "id");
37422
38195
  if (id) noteReference = { kind: "footnote", id };
37423
- } else if (named2(only, "endnoteReference")) {
37424
- const id = getW(only, "id");
38196
+ } else if (named2(only2, "endnoteReference")) {
38197
+ const id = getW(only2, "id");
37425
38198
  if (id) noteReference = { kind: "endnote", id };
37426
- } else if (named2(only, "footnoteRef")) noteMark = "footnote";
37427
- else if (named2(only, "endnoteRef")) noteMark = "endnote";
37428
- else if (named2(only, "separator")) noteSeparator = "separator";
37429
- else if (named2(only, "continuationSeparator")) noteSeparator = "continuationSeparator";
37430
- else if (named2(only, "fldChar")) {
37431
- const type = getW(only, "fldCharType");
38199
+ } else if (named2(only2, "footnoteRef")) noteMark = "footnote";
38200
+ else if (named2(only2, "endnoteRef")) noteMark = "endnote";
38201
+ else if (named2(only2, "separator")) noteSeparator = "separator";
38202
+ else if (named2(only2, "continuationSeparator")) noteSeparator = "continuationSeparator";
38203
+ else if (named2(only2, "fldChar")) {
38204
+ const type = getW(only2, "fldCharType");
37432
38205
  if (type === "begin" || type === "separate" || type === "end") fieldChar = type;
37433
38206
  }
37434
38207
  }
@@ -37450,9 +38223,9 @@ function parseRun2(node, revision) {
37450
38223
  if (noteSeparator) run2.noteSeparator = noteSeparator;
37451
38224
  if (fieldChar) {
37452
38225
  run2.fieldChar = fieldChar;
37453
- const flags = parseFieldFlags(only);
38226
+ const flags = parseFieldFlags(only2);
37454
38227
  if (flags) run2.fieldFlags = flags;
37455
- const data = fieldChar === "begin" ? first2(only, "ffData") : void 0;
38228
+ const data = fieldChar === "begin" ? first2(only2, "ffData") : void 0;
37456
38229
  const formField = data && parseFormField(data);
37457
38230
  if (formField) run2.formField = formField;
37458
38231
  }
@@ -37792,6 +38565,7 @@ function parseSettings(xml) {
37792
38565
  );
37793
38566
  return {
37794
38567
  ...compatibilityMode !== void 0 && Number.isInteger(compatibilityMode) && compatibilityMode > 0 ? { compatibilityMode } : {},
38568
+ ...onOffElement(first2(first2(root, "compat"), "doNotUseHTMLParagraphAutoSpacing")) === true ? { doNotUseHtmlParagraphAutoSpacing: true } : {},
37795
38569
  evenAndOddHeaders: onOffElement(first2(root, "evenAndOddHeaders")) === true,
37796
38570
  autoHyphenation: onOffElement(first2(root, "autoHyphenation")) === true,
37797
38571
  ...footnoteNumFmt ? { footnoteNumFmt } : {},
@@ -37872,6 +38646,7 @@ async function parseDocumentParts(zip, body, blocks, drawings) {
37872
38646
  return {
37873
38647
  sections,
37874
38648
  ...settings.compatibilityMode !== void 0 ? { compatibilityMode: settings.compatibilityMode } : {},
38649
+ ...settings.doNotUseHtmlParagraphAutoSpacing ? { doNotUseHtmlParagraphAutoSpacing: true } : {},
37875
38650
  ...footnotes ? { footnotes } : {},
37876
38651
  ...footnoteSeparators ? { footnoteSeparators } : {},
37877
38652
  ...endnotes ? { endnotes } : {},
@@ -38169,6 +38944,7 @@ async function readPackage(input) {
38169
38944
  const parts = await parseDocumentParts(zip, body, blocks, drawings);
38170
38945
  model.sections = parts.sections;
38171
38946
  if (parts.compatibilityMode !== void 0) model.compatibilityMode = parts.compatibilityMode;
38947
+ if (parts.doNotUseHtmlParagraphAutoSpacing) model.doNotUseHtmlParagraphAutoSpacing = true;
38172
38948
  if (parts.footnotes) model.footnotes = parts.footnotes;
38173
38949
  if (parts.footnoteSeparators) model.footnoteSeparators = parts.footnoteSeparators;
38174
38950
  if (parts.endnotes) model.endnotes = parts.endnotes;
@@ -38178,14 +38954,16 @@ async function readPackage(input) {
38178
38954
  if (parts.autoHyphenation) model.autoHyphenation = true;
38179
38955
  const coreFile = zip.file("docProps/core.xml");
38180
38956
  if (coreFile) {
38181
- const properties = parseCoreProperties(await coreFile.async("string"));
38957
+ const properties = parseCoreProperties2(await coreFile.async("string"));
38182
38958
  if (properties) model.properties = properties;
38183
38959
  }
38184
38960
  await readPlaceholderTexts(zip, drawings.rels, model);
38185
38961
  const pageColor = parsePageBackground(document.documentElement);
38186
38962
  if (pageColor) model.pageColor = pageColor;
38187
38963
  model.warnings.push(...parts.warnings);
38188
- if (blocks.some((block) => block.type === "table" && !block.structureEditable))
38964
+ if (blocks.some(
38965
+ (block) => block.type === "table" && !block.structureEditable && !block.restructurable
38966
+ ))
38189
38967
  model.warnings.push(
38190
38968
  "Merged, nested, or complex tables can be read, but their row and column structure cannot be edited safely."
38191
38969
  );
@@ -38211,7 +38989,7 @@ async function readPackage(input) {
38211
38989
  (block) => block.type === "table" && block.rows.some((row) => row.some((cell2) => cell2.nestedTables?.length))
38212
38990
  ))
38213
38991
  model.warnings.push(
38214
- "Text in nested tables is editable; the grid, merges and formatting of a nested table are preserved but cannot be changed."
38992
+ "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."
38215
38993
  );
38216
38994
  const pictureBlocks = documentDrawingBlocks({ ...model, blocks });
38217
38995
  await resolveDocumentDiagrams(
@@ -38249,9 +39027,9 @@ async function loadDocx(input) {
38249
39027
  return {
38250
39028
  model,
38251
39029
  media,
38252
- save: (next = model, pendingMedia) => {
39030
+ save: (next = model, pendingMedia, options) => {
38253
39031
  if (next !== model) remember(next, context);
38254
- return saveDocx(next, pendingMedia);
39032
+ return saveDocx(next, pendingMedia, options);
38255
39033
  }
38256
39034
  };
38257
39035
  }
@@ -38544,7 +39322,7 @@ function processCompoundFileStream(input, path3, replacement) {
38544
39322
  return reject();
38545
39323
  let parent = root, target;
38546
39324
  for (let partIndex = 0; partIndex < path3.length; partIndex++) {
38547
- const matches = [], seen = /* @__PURE__ */ new Set();
39325
+ const matches2 = [], seen = /* @__PURE__ */ new Set();
38548
39326
  const visit = (id) => {
38549
39327
  if (id === NIL)
38550
39328
  return;
@@ -38556,13 +39334,13 @@ function processCompoundFileStream(input, path3, replacement) {
38556
39334
  throw new Error("Invalid directory ID");
38557
39335
  visit(e.left);
38558
39336
  if (e.name.toLocaleLowerCase() === path3[partIndex].toLocaleLowerCase())
38559
- matches.push(e);
39337
+ matches2.push(e);
38560
39338
  visit(e.right);
38561
39339
  };
38562
39340
  visit(parent.child);
38563
- if (matches.length !== 1)
39341
+ if (matches2.length !== 1)
38564
39342
  return reject();
38565
- target = matches[0];
39343
+ target = matches2[0];
38566
39344
  if (partIndex < path3.length - 1) {
38567
39345
  if (target.type !== 1)
38568
39346
  return reject();
@@ -38720,7 +39498,7 @@ function findSlot(slots, path3) {
38720
39498
  if (parents.has(parent.id))
38721
39499
  throw new Error("Cyclic storage hierarchy");
38722
39500
  parents.add(parent.id);
38723
- const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches = [];
39501
+ const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches2 = [];
38724
39502
  while (stack.length) {
38725
39503
  const id = stack.pop();
38726
39504
  if (id === FREE)
@@ -38732,12 +39510,12 @@ function findSlot(slots, path3) {
38732
39510
  if (!slot2)
38733
39511
  throw new Error("Missing directory slot");
38734
39512
  if (slot2.name.toLocaleLowerCase() === path3[part].toLocaleLowerCase())
38735
- matches.push(slot2);
39513
+ matches2.push(slot2);
38736
39514
  stack.push(slot2.left, slot2.right);
38737
39515
  }
38738
- if (matches.length !== 1)
39516
+ if (matches2.length !== 1)
38739
39517
  throw new Error("Missing or ambiguous stream");
38740
- parent = matches[0];
39518
+ parent = matches2[0];
38741
39519
  if (parent.type !== (part === path3.length - 1 ? 2 : 1))
38742
39520
  throw new Error("Invalid storage path");
38743
39521
  }
@@ -39029,7 +39807,7 @@ function findSlot2(slots, path3) {
39029
39807
  if (parents.has(parent.id))
39030
39808
  throw new Error("Cyclic storage hierarchy");
39031
39809
  parents.add(parent.id);
39032
- const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches = [];
39810
+ const stack = [parent.child], seen = /* @__PURE__ */ new Set(), matches2 = [];
39033
39811
  while (stack.length) {
39034
39812
  const id = stack.pop();
39035
39813
  if (id === FREE3)
@@ -39041,12 +39819,12 @@ function findSlot2(slots, path3) {
39041
39819
  if (!slot2)
39042
39820
  throw new Error("Missing directory slot");
39043
39821
  if (slot2.name.toLocaleLowerCase() === path3[part].toLocaleLowerCase())
39044
- matches.push(slot2);
39822
+ matches2.push(slot2);
39045
39823
  stack.push(slot2.left, slot2.right);
39046
39824
  }
39047
- if (matches.length !== 1)
39825
+ if (matches2.length !== 1)
39048
39826
  throw new Error("Missing or ambiguous stream");
39049
- parent = matches[0];
39827
+ parent = matches2[0];
39050
39828
  if (parent.type !== (part === path3.length - 1 ? 2 : 1))
39051
39829
  throw new Error("Invalid storage path");
39052
39830
  }