ooxml-core 1.30.1 → 1.31.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 (342) hide show
  1. package/dist/automation/index.cjs +5829 -3266
  2. package/dist/automation/index.mjs +5829 -3266
  3. package/dist/automation/node.cjs +2 -1
  4. package/dist/automation/node.d.ts.map +1 -1
  5. package/dist/automation/node.mjs +2 -1
  6. package/dist/automation/tools/define.d.ts +2 -0
  7. package/dist/automation/tools/define.d.ts.map +1 -1
  8. package/dist/automation/tools/types.d.ts +6 -0
  9. package/dist/automation/tools/types.d.ts.map +1 -1
  10. package/dist/collab/index.cjs +35 -4
  11. package/dist/collab/index.mjs +35 -4
  12. package/dist/collab/websocket-transport.d.ts +9 -1
  13. package/dist/collab/websocket-transport.d.ts.map +1 -1
  14. package/dist/docx/data-binding.d.ts +9 -0
  15. package/dist/docx/data-binding.d.ts.map +1 -0
  16. package/dist/docx/document-parts.d.ts +1 -0
  17. package/dist/docx/document-parts.d.ts.map +1 -1
  18. package/dist/docx/drawing.d.ts.map +1 -1
  19. package/dist/docx/embedded.cjs +1383 -609
  20. package/dist/docx/embedded.mjs +1383 -609
  21. package/dist/docx/index.cjs +1394 -618
  22. package/dist/docx/index.mjs +1394 -618
  23. package/dist/docx/inline-model.d.ts +2 -0
  24. package/dist/docx/inline-model.d.ts.map +1 -1
  25. package/dist/docx/layout/adapt-floats.d.ts.map +1 -1
  26. package/dist/docx/layout/adapt-table.d.ts.map +1 -1
  27. package/dist/docx/layout/adapter.d.ts.map +1 -1
  28. package/dist/docx/layout/equation-object.d.ts +1 -1
  29. package/dist/docx/layout/equation-object.d.ts.map +1 -1
  30. package/dist/docx/layout/floats.d.ts +1 -1
  31. package/dist/docx/layout/floats.d.ts.map +1 -1
  32. package/dist/docx/layout/flow-paragraph.d.ts +4 -0
  33. package/dist/docx/layout/flow-paragraph.d.ts.map +1 -1
  34. package/dist/docx/layout/flow-table.d.ts.map +1 -1
  35. package/dist/docx/layout/index.cjs +452 -203
  36. package/dist/docx/layout/index.mjs +452 -203
  37. package/dist/docx/layout/input.d.ts +12 -0
  38. package/dist/docx/layout/input.d.ts.map +1 -1
  39. package/dist/docx/layout/nested-frame-profile.d.ts +3 -1
  40. package/dist/docx/layout/nested-frame-profile.d.ts.map +1 -1
  41. package/dist/docx/layout/page-cursor.d.ts +11 -2
  42. package/dist/docx/layout/page-cursor.d.ts.map +1 -1
  43. package/dist/docx/layout/paragraph-fragments.d.ts.map +1 -1
  44. package/dist/docx/layout/paragraph-layout.d.ts +5 -0
  45. package/dist/docx/layout/paragraph-layout.d.ts.map +1 -1
  46. package/dist/docx/layout/result.d.ts +4 -0
  47. package/dist/docx/layout/result.d.ts.map +1 -1
  48. package/dist/docx/layout/section-flow.d.ts +2 -0
  49. package/dist/docx/layout/section-flow.d.ts.map +1 -1
  50. package/dist/docx/layout/table-layout.d.ts +4 -14
  51. package/dist/docx/layout/table-layout.d.ts.map +1 -1
  52. package/dist/docx/layout/table-merged-rows.d.ts +21 -0
  53. package/dist/docx/layout/table-merged-rows.d.ts.map +1 -0
  54. package/dist/docx/layout/table-row-split.d.ts +16 -0
  55. package/dist/docx/layout/table-row-split.d.ts.map +1 -0
  56. package/dist/docx/layout/wrap.d.ts +2 -0
  57. package/dist/docx/layout/wrap.d.ts.map +1 -1
  58. package/dist/docx/load/index.cjs +1397 -623
  59. package/dist/docx/load/index.mjs +1397 -623
  60. package/dist/docx/model-paragraph.d.ts +4 -1
  61. package/dist/docx/model-paragraph.d.ts.map +1 -1
  62. package/dist/docx/model.d.ts +24 -1
  63. package/dist/docx/model.d.ts.map +1 -1
  64. package/dist/docx/paragraph-properties.d.ts.map +1 -1
  65. package/dist/docx/paragraph-styles.d.ts.map +1 -1
  66. package/dist/docx/parse-table.d.ts.map +1 -1
  67. package/dist/docx/parse.d.ts.map +1 -1
  68. package/dist/docx/run-segmentation.d.ts.map +1 -1
  69. package/dist/docx/save-modified.d.ts +4 -0
  70. package/dist/docx/save-modified.d.ts.map +1 -0
  71. package/dist/docx/save.d.ts +2 -2
  72. package/dist/docx/save.d.ts.map +1 -1
  73. package/dist/docx/style-formatting-package.d.ts +9 -0
  74. package/dist/docx/style-formatting-package.d.ts.map +1 -0
  75. package/dist/docx/style-numbering-package.d.ts +4 -1
  76. package/dist/docx/style-numbering-package.d.ts.map +1 -1
  77. package/dist/docx/table-grid.d.ts +35 -0
  78. package/dist/docx/table-grid.d.ts.map +1 -0
  79. package/dist/docx/table-structure-cells.d.ts +19 -0
  80. package/dist/docx/table-structure-cells.d.ts.map +1 -0
  81. package/dist/docx/table-structure-check.d.ts +12 -0
  82. package/dist/docx/table-structure-check.d.ts.map +1 -0
  83. package/dist/docx/table-structure-merge.d.ts +28 -0
  84. package/dist/docx/table-structure-merge.d.ts.map +1 -0
  85. package/dist/docx/table-structure.d.ts +30 -0
  86. package/dist/docx/table-structure.d.ts.map +1 -0
  87. package/dist/docx/ui/index.cjs +717 -256
  88. package/dist/docx/ui/index.d.ts +4 -0
  89. package/dist/docx/ui/index.d.ts.map +1 -1
  90. package/dist/docx/ui/index.mjs +703 -257
  91. package/dist/docx/ui/ribbon-action-ids.d.ts +1 -1
  92. package/dist/docx/ui/ribbon-action-ids.d.ts.map +1 -1
  93. package/dist/docx/ui/table-structure-guard.d.ts +2 -0
  94. package/dist/docx/ui/table-structure-guard.d.ts.map +1 -1
  95. package/dist/docx/word-content-control-docs.d.ts +5 -0
  96. package/dist/docx/word-content-control-docs.d.ts.map +1 -0
  97. package/dist/docx/word-corpus-gaps.d.ts +10 -0
  98. package/dist/docx/word-corpus-gaps.d.ts.map +1 -0
  99. package/dist/docx/word-measurer.d.ts +6 -0
  100. package/dist/docx/word-measurer.d.ts.map +1 -0
  101. package/dist/docx/word-spacing-docs.d.ts +12 -0
  102. package/dist/docx/word-spacing-docs.d.ts.map +1 -0
  103. package/dist/docx/word-table-docs.d.ts +9 -0
  104. package/dist/docx/word-table-docs.d.ts.map +1 -0
  105. package/dist/docx/write-drawing.d.ts.map +1 -1
  106. package/dist/docx/write-fallback.d.ts +5 -0
  107. package/dist/docx/write-fallback.d.ts.map +1 -0
  108. package/dist/docx/write-table-properties.d.ts +1 -0
  109. package/dist/docx/write-table-properties.d.ts.map +1 -1
  110. package/dist/docx/write-table-structure.d.ts +14 -0
  111. package/dist/docx/write-table-structure.d.ts.map +1 -0
  112. package/dist/docx/write-table.d.ts +3 -4
  113. package/dist/docx/write-table.d.ts.map +1 -1
  114. package/dist/index.cjs +22 -22
  115. package/dist/index.mjs +22 -22
  116. package/dist/math/index.cjs +22 -22
  117. package/dist/math/index.mjs +22 -22
  118. package/dist/math/omml-box-grouped.d.ts.map +1 -1
  119. package/dist/math/omml-box-layout.d.ts +3 -1
  120. package/dist/math/omml-box-layout.d.ts.map +1 -1
  121. package/dist/math/omml-box-structures.d.ts.map +1 -1
  122. package/dist/math/omml-box.d.ts +2 -0
  123. package/dist/math/omml-box.d.ts.map +1 -1
  124. package/dist/math/omml-svg.d.ts +6 -2
  125. package/dist/math/omml-svg.d.ts.map +1 -1
  126. package/dist/pptx/automation/index.cjs +1 -0
  127. package/dist/pptx/automation/index.d.ts +6 -0
  128. package/dist/pptx/automation/index.d.ts.map +1 -1
  129. package/dist/pptx/automation/index.mjs +1 -0
  130. package/dist/teams/chat-rooms.d.ts.map +1 -1
  131. package/dist/teams/chat.d.ts +7 -0
  132. package/dist/teams/chat.d.ts.map +1 -1
  133. package/dist/teams/files.d.ts +1 -1
  134. package/dist/teams/files.d.ts.map +1 -1
  135. package/dist/teams/index.cjs +2735 -1148
  136. package/dist/teams/index.d.ts +3 -0
  137. package/dist/teams/index.d.ts.map +1 -1
  138. package/dist/teams/index.mjs +2710 -1148
  139. package/dist/teams/message-transfer.d.ts +1 -1
  140. package/dist/teams/message-transfer.d.ts.map +1 -1
  141. package/dist/teams/protocol.d.ts +30 -0
  142. package/dist/teams/protocol.d.ts.map +1 -0
  143. package/dist/teams/schema.d.ts +59 -0
  144. package/dist/teams/schema.d.ts.map +1 -0
  145. package/dist/teams/server-config.d.ts +19 -2
  146. package/dist/teams/server-config.d.ts.map +1 -1
  147. package/dist/teams/server-file-storage.d.ts +11 -1
  148. package/dist/teams/server-file-storage.d.ts.map +1 -1
  149. package/dist/teams/server-session.d.ts +2 -0
  150. package/dist/teams/server-session.d.ts.map +1 -1
  151. package/dist/teams/signaling.d.ts +2 -0
  152. package/dist/teams/signaling.d.ts.map +1 -1
  153. package/dist/teams/store.d.ts +9 -0
  154. package/dist/teams/store.d.ts.map +1 -1
  155. package/dist/teams/stored-file.d.ts +1 -1
  156. package/dist/teams/stored-file.d.ts.map +1 -1
  157. package/dist/teams/sync-transport.d.ts.map +1 -1
  158. package/dist/teams/validate-members.d.ts +28 -0
  159. package/dist/teams/validate-members.d.ts.map +1 -0
  160. package/dist/teams/validate-owned.d.ts +20 -0
  161. package/dist/teams/validate-owned.d.ts.map +1 -0
  162. package/dist/teams/validate-update.d.ts +70 -0
  163. package/dist/teams/validate-update.d.ts.map +1 -0
  164. package/dist/teams/workspace.d.ts +12 -0
  165. package/dist/teams/workspace.d.ts.map +1 -1
  166. package/dist/visio/connector-route-walk.d.ts +2 -0
  167. package/dist/visio/connector-route-walk.d.ts.map +1 -1
  168. package/dist/visio/edit-connector-reroute.d.ts.map +1 -1
  169. package/dist/visio/edit-connector.d.ts +2 -0
  170. package/dist/visio/edit-connector.d.ts.map +1 -1
  171. package/dist/visio/edit-delete.d.ts.map +1 -1
  172. package/dist/visio/edit-duplicate-line.d.ts +40 -0
  173. package/dist/visio/edit-duplicate-line.d.ts.map +1 -0
  174. package/dist/visio/edit-duplicate.d.ts.map +1 -1
  175. package/dist/visio/edit-formatting-scope.d.ts +5 -1
  176. package/dist/visio/edit-formatting-scope.d.ts.map +1 -1
  177. package/dist/visio/edit-geometry.d.ts.map +1 -1
  178. package/dist/visio/edit-instance-duplicate.d.ts +2 -1
  179. package/dist/visio/edit-instance-duplicate.d.ts.map +1 -1
  180. package/dist/visio/edit-master-move.d.ts.map +1 -1
  181. package/dist/visio/edit-recalculate-index.d.ts +23 -0
  182. package/dist/visio/edit-recalculate-index.d.ts.map +1 -1
  183. package/dist/visio/edit-recalculate-text.d.ts +12 -0
  184. package/dist/visio/edit-recalculate-text.d.ts.map +1 -0
  185. package/dist/visio/edit-recalculate-values.d.ts.map +1 -1
  186. package/dist/visio/edit-recalculate.d.ts +15 -3
  187. package/dist/visio/edit-recalculate.d.ts.map +1 -1
  188. package/dist/visio/edit-resize-anchor.d.ts.map +1 -1
  189. package/dist/visio/edit-stencil-connector-layout.d.ts +1 -1
  190. package/dist/visio/edit-stencil-connector-layout.d.ts.map +1 -1
  191. package/dist/visio/edit-text-scope.d.ts +4 -1
  192. package/dist/visio/edit-text-scope.d.ts.map +1 -1
  193. package/dist/visio/formula-analyze.d.ts +18 -0
  194. package/dist/visio/formula-analyze.d.ts.map +1 -0
  195. package/dist/visio/formula-bound.d.ts +4 -0
  196. package/dist/visio/formula-bound.d.ts.map +1 -0
  197. package/dist/visio/formula-evaluate.d.ts +2 -9
  198. package/dist/visio/formula-evaluate.d.ts.map +1 -1
  199. package/dist/visio/formula-extra-functions.d.ts +23 -0
  200. package/dist/visio/formula-extra-functions.d.ts.map +1 -0
  201. package/dist/visio/formula-indirect.d.ts +6 -0
  202. package/dist/visio/formula-indirect.d.ts.map +1 -0
  203. package/dist/visio/formula-master.d.ts +1 -0
  204. package/dist/visio/formula-master.d.ts.map +1 -1
  205. package/dist/visio/formula-operators.d.ts +6 -0
  206. package/dist/visio/formula-operators.d.ts.map +1 -0
  207. package/dist/visio/formula-text-functions.d.ts +5 -1
  208. package/dist/visio/formula-text-functions.d.ts.map +1 -1
  209. package/dist/visio/formula.d.ts +12 -0
  210. package/dist/visio/formula.d.ts.map +1 -1
  211. package/dist/visio/index.cjs +1354 -396
  212. package/dist/visio/index.mjs +1354 -396
  213. package/dist/visio/ui/index.cjs +1341 -383
  214. package/dist/visio/ui/index.mjs +1341 -383
  215. package/dist/xlsx/collab/apply.d.ts.map +1 -1
  216. package/dist/xlsx/collab/codec.d.ts +2 -0
  217. package/dist/xlsx/collab/codec.d.ts.map +1 -1
  218. package/dist/xlsx/collab/dirty.d.ts +4 -1
  219. package/dist/xlsx/collab/dirty.d.ts.map +1 -1
  220. package/dist/xlsx/collab/index.cjs +551 -106
  221. package/dist/xlsx/collab/index.mjs +551 -106
  222. package/dist/xlsx/collab/keyed.d.ts +36 -0
  223. package/dist/xlsx/collab/keyed.d.ts.map +1 -0
  224. package/dist/xlsx/collab/names.d.ts +2 -0
  225. package/dist/xlsx/collab/names.d.ts.map +1 -1
  226. package/dist/xlsx/collab/part-specs.d.ts +13 -0
  227. package/dist/xlsx/collab/part-specs.d.ts.map +1 -0
  228. package/dist/xlsx/collab/schema.d.ts +8 -0
  229. package/dist/xlsx/collab/schema.d.ts.map +1 -1
  230. package/dist/xlsx/collab/sheet-parts.d.ts +19 -0
  231. package/dist/xlsx/collab/sheet-parts.d.ts.map +1 -0
  232. package/dist/xlsx/collab/sheets.d.ts +6 -0
  233. package/dist/xlsx/collab/sheets.d.ts.map +1 -1
  234. package/dist/xlsx/collab/write.d.ts +3 -0
  235. package/dist/xlsx/collab/write.d.ts.map +1 -1
  236. package/dist/xlsx/edit/clipboard-areas.d.ts +17 -0
  237. package/dist/xlsx/edit/clipboard-areas.d.ts.map +1 -0
  238. package/dist/xlsx/edit/custom-views.d.ts +21 -0
  239. package/dist/xlsx/edit/custom-views.d.ts.map +1 -0
  240. package/dist/xlsx/edit/data-table.d.ts.map +1 -1
  241. package/dist/xlsx/edit/history.d.ts +1 -1
  242. package/dist/xlsx/edit/history.d.ts.map +1 -1
  243. package/dist/xlsx/edit/index.d.ts +2 -0
  244. package/dist/xlsx/edit/index.d.ts.map +1 -1
  245. package/dist/xlsx/edit/paste-selection.d.ts.map +1 -1
  246. package/dist/xlsx/edit/scenario-merge.d.ts +7 -0
  247. package/dist/xlsx/edit/scenario-merge.d.ts.map +1 -0
  248. package/dist/xlsx/edit/session.d.ts.map +1 -1
  249. package/dist/xlsx/edit/shift-data-tables.d.ts +7 -0
  250. package/dist/xlsx/edit/shift-data-tables.d.ts.map +1 -0
  251. package/dist/xlsx/edit/shift-scenarios.d.ts +7 -0
  252. package/dist/xlsx/edit/shift-scenarios.d.ts.map +1 -0
  253. package/dist/xlsx/edit/shift-sheet.d.ts.map +1 -1
  254. package/dist/xlsx/edit/sparkline-grouping.d.ts +10 -0
  255. package/dist/xlsx/edit/sparkline-grouping.d.ts.map +1 -0
  256. package/dist/xlsx/edit/types.d.ts +21 -0
  257. package/dist/xlsx/edit/types.d.ts.map +1 -1
  258. package/dist/xlsx/formula/ets-excel-compare.d.ts +24 -0
  259. package/dist/xlsx/formula/ets-excel-compare.d.ts.map +1 -0
  260. package/dist/xlsx/formula/functions/ets-core.d.ts +36 -0
  261. package/dist/xlsx/formula/functions/ets-core.d.ts.map +1 -0
  262. package/dist/xlsx/formula/functions/ets-grid.d.ts +15 -0
  263. package/dist/xlsx/formula/functions/ets-grid.d.ts.map +1 -0
  264. package/dist/xlsx/formula/functions/ets-init.d.ts +15 -0
  265. package/dist/xlsx/formula/functions/ets-init.d.ts.map +1 -0
  266. package/dist/xlsx/formula/functions/ets-input.d.ts +13 -0
  267. package/dist/xlsx/formula/functions/ets-input.d.ts.map +1 -0
  268. package/dist/xlsx/formula/functions/ets-season.d.ts +6 -0
  269. package/dist/xlsx/formula/functions/ets-season.d.ts.map +1 -0
  270. package/dist/xlsx/formula/functions/forecast-ets.d.ts +3 -0
  271. package/dist/xlsx/formula/functions/forecast-ets.d.ts.map +1 -0
  272. package/dist/xlsx/formula/functions/statistical.d.ts.map +1 -1
  273. package/dist/xlsx/index.cjs +4444 -2447
  274. package/dist/xlsx/index.mjs +4423 -2448
  275. package/dist/xlsx/layout/form-control-link.d.ts +20 -0
  276. package/dist/xlsx/layout/form-control-link.d.ts.map +1 -0
  277. package/dist/xlsx/layout/form-control-state.d.ts +49 -0
  278. package/dist/xlsx/layout/form-control-state.d.ts.map +1 -0
  279. package/dist/xlsx/layout/form-control-view.d.ts +11 -0
  280. package/dist/xlsx/layout/form-control-view.d.ts.map +1 -0
  281. package/dist/xlsx/layout/header-footer-edit.d.ts +4 -2
  282. package/dist/xlsx/layout/header-footer-edit.d.ts.map +1 -1
  283. package/dist/xlsx/layout/header-footer.d.ts +16 -0
  284. package/dist/xlsx/layout/header-footer.d.ts.map +1 -1
  285. package/dist/xlsx/layout/index.d.ts +5 -0
  286. package/dist/xlsx/layout/index.d.ts.map +1 -1
  287. package/dist/xlsx/layout/ref-evaluator.d.ts +6 -0
  288. package/dist/xlsx/layout/ref-evaluator.d.ts.map +1 -1
  289. package/dist/xlsx/layout/shape-paint.d.ts +25 -0
  290. package/dist/xlsx/layout/shape-paint.d.ts.map +1 -0
  291. package/dist/xlsx/layout/shape-view.d.ts +15 -0
  292. package/dist/xlsx/layout/shape-view.d.ts.map +1 -0
  293. package/dist/xlsx/load/index.cjs +2134 -1103
  294. package/dist/xlsx/load/index.mjs +2134 -1103
  295. package/dist/xlsx/model-custom-views.d.ts +33 -0
  296. package/dist/xlsx/model-custom-views.d.ts.map +1 -0
  297. package/dist/xlsx/model-shapes.d.ts +78 -0
  298. package/dist/xlsx/model-shapes.d.ts.map +1 -0
  299. package/dist/xlsx/model.d.ts +38 -1
  300. package/dist/xlsx/model.d.ts.map +1 -1
  301. package/dist/xlsx/read/custom-views.d.ts +5 -0
  302. package/dist/xlsx/read/custom-views.d.ts.map +1 -0
  303. package/dist/xlsx/read/drawing.d.ts.map +1 -1
  304. package/dist/xlsx/read/form-control.d.ts +14 -0
  305. package/dist/xlsx/read/form-control.d.ts.map +1 -0
  306. package/dist/xlsx/read/header-footer-images.d.ts +5 -0
  307. package/dist/xlsx/read/header-footer-images.d.ts.map +1 -0
  308. package/dist/xlsx/read/load.d.ts.map +1 -1
  309. package/dist/xlsx/read/shape.d.ts +5 -0
  310. package/dist/xlsx/read/shape.d.ts.map +1 -0
  311. package/dist/xlsx/read/sheet-data.d.ts.map +1 -1
  312. package/dist/xlsx/read/workbook-part.d.ts +5 -1
  313. package/dist/xlsx/read/workbook-part.d.ts.map +1 -1
  314. package/dist/xlsx/read/worksheet-children.d.ts +3 -0
  315. package/dist/xlsx/read/worksheet-children.d.ts.map +1 -0
  316. package/dist/xlsx/read/worksheet.d.ts.map +1 -1
  317. package/dist/xlsx/ui/commands/i18n/sparklines.d.ts.map +1 -1
  318. package/dist/xlsx/ui/commands/i18n/what-if.d.ts.map +1 -1
  319. package/dist/xlsx/ui/commands/what-if.d.ts +0 -1
  320. package/dist/xlsx/ui/commands/what-if.d.ts.map +1 -1
  321. package/dist/xlsx/ui/dialogs/forecast-sheet.d.ts +51 -0
  322. package/dist/xlsx/ui/dialogs/forecast-sheet.d.ts.map +1 -0
  323. package/dist/xlsx/ui/dialogs/scenario-summary.d.ts +15 -0
  324. package/dist/xlsx/ui/dialogs/scenario-summary.d.ts.map +1 -0
  325. package/dist/xlsx/ui/index.cjs +4411 -2195
  326. package/dist/xlsx/ui/index.d.ts +2 -0
  327. package/dist/xlsx/ui/index.d.ts.map +1 -1
  328. package/dist/xlsx/ui/index.mjs +4404 -2194
  329. package/dist/xlsx/ui/locales/de/grid.d.ts.map +1 -1
  330. package/dist/xlsx/ui/locales/en/grid.d.ts.map +1 -1
  331. package/dist/xlsx/ui/locales/es/grid.d.ts.map +1 -1
  332. package/dist/xlsx/ui/locales/fr/grid.d.ts.map +1 -1
  333. package/dist/xlsx/ui/locales/zh-CN/grid.d.ts.map +1 -1
  334. package/dist/xlsx/write/custom-views.d.ts +4 -0
  335. package/dist/xlsx/write/custom-views.d.ts.map +1 -0
  336. package/dist/xlsx/write/drawing.d.ts.map +1 -1
  337. package/dist/xlsx/write/form-control.d.ts +4 -0
  338. package/dist/xlsx/write/form-control.d.ts.map +1 -0
  339. package/dist/xlsx/write/sheet-data.d.ts.map +1 -1
  340. package/dist/xlsx/write/workbook-part.d.ts.map +1 -1
  341. package/dist/xlsx/write/worksheet.d.ts.map +1 -1
  342. package/package.json +1 -1
@@ -5,6 +5,8 @@ import JSZip from 'jszip';
5
5
  var NS = {
6
6
  /** WordprocessingML main. */
7
7
  w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
8
+ /** PresentationML main. */
9
+ p: "http://schemas.openxmlformats.org/presentationml/2006/main",
8
10
  /** SpreadsheetML main. */
9
11
  x: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
10
12
  /** DrawingML main. */
@@ -19,6 +21,12 @@ var NS = {
19
21
  dgm: "http://schemas.openxmlformats.org/drawingml/2006/diagram",
20
22
  /** Office 2007+ diagram drawing (`dsp`). */
21
23
  dsp: "http://schemas.microsoft.com/office/drawing/2008/diagram",
24
+ /** DrawingML Word drawing (`wp:inline`, `wp:anchor`). */
25
+ wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
26
+ /** DrawingML picture. */
27
+ pic: "http://schemas.openxmlformats.org/drawingml/2006/picture",
28
+ /** Word 2010 shapes (`wps`). */
29
+ wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
22
30
  /** Relationships (`r:id`, `r:embed`). */
23
31
  r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
24
32
  /** Markup compatibility (`mc:AlternateContent`). */
@@ -26,7 +34,42 @@ var NS = {
26
34
  /** OPC relationships part. */
27
35
  rels: "http://schemas.openxmlformats.org/package/2006/relationships",
28
36
  /** OPC content types part. */
29
- contentTypes: "http://schemas.openxmlformats.org/package/2006/content-types"};
37
+ contentTypes: "http://schemas.openxmlformats.org/package/2006/content-types",
38
+ /** Office Math. */
39
+ m: "http://schemas.openxmlformats.org/officeDocument/2006/math",
40
+ /** Core properties. */
41
+ cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
42
+ /** Dublin Core elements. */
43
+ dc: "http://purl.org/dc/elements/1.1/",
44
+ /** Legacy VML. */
45
+ v: "urn:schemas-microsoft-com:vml",
46
+ /** Office VML extensions. */
47
+ o: "urn:schemas-microsoft-com:office:office",
48
+ /** Word VML extensions. */
49
+ w10: "urn:schemas-microsoft-com:office:word",
50
+ /** SpreadsheetML drawing (`xdr:wsDr`, cell anchors). */
51
+ xdr: "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
52
+ /** SpreadsheetML 2009 extensions (`x14:conditionalFormatting`, `x14:dataBar`). */
53
+ x14: "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",
54
+ /** SpreadsheetML 2009 attribute extensions (`x14ac:dyDescent`). */
55
+ x14ac: "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac",
56
+ /** SpreadsheetML revision ids (`xr:uid`). */
57
+ xr: "http://schemas.microsoft.com/office/spreadsheetml/2014/revision",
58
+ /** Excel threaded comments and persons. */
59
+ tc: "http://schemas.microsoft.com/office/spreadsheetml/2018/threadedcomments",
60
+ /** Legacy VML Excel client data (`x:ClientData`). */
61
+ xv: "urn:schemas-microsoft-com:office:excel",
62
+ /** Extended (app) properties. */
63
+ extendedProperties: "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties",
64
+ /** Dublin Core terms (`dcterms:created`). */
65
+ dcterms: "http://purl.org/dc/terms/",
66
+ /** Custom document properties (`docProps/custom.xml`). */
67
+ customProperties: "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties",
68
+ /** Document property variant types (`vt:lpwstr`, `vt:vector`). */
69
+ vt: "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes",
70
+ /** XML itself (`xml:space`). */
71
+ xml: "http://www.w3.org/XML/1998/namespace"
72
+ };
30
73
  var DEFAULT_XML_LIMITS = {
31
74
  maxDepth: 512,
32
75
  maxNodes: 5e6
@@ -787,6 +830,10 @@ function parseFormatting(pPr) {
787
830
  const line2 = signedTwipValue(getW(spacing2, "line"));
788
831
  if (before !== void 0) result.spacingBeforeTwips = before;
789
832
  if (after !== void 0) result.spacingAfterTwips = after;
833
+ const beforeAuto = parseOnOff(getW(spacing2, "beforeAutospacing"));
834
+ const afterAuto = parseOnOff(getW(spacing2, "afterAutospacing"));
835
+ if (beforeAuto !== void 0) result.spacingBeforeAuto = beforeAuto;
836
+ if (afterAuto !== void 0) result.spacingAfterAuto = afterAuto;
790
837
  if (line2 !== void 0) result.lineSpacingTwips = line2;
791
838
  const rule = getW(spacing2, "lineRule");
792
839
  if (rule === "auto" || rule === "exact" || rule === "atLeast") result.lineSpacingRule = rule;
@@ -1586,7 +1633,7 @@ function applyPictureEffects(blip, effects) {
1586
1633
  const node = source2 ? blip.ownerDocument.importNode(source2, true) : blip.ownerDocument.createElementNS(NS.a, `a:${name}`);
1587
1634
  if (effect.kind !== "unsupported" && (node.namespaceURI !== NS.a || node.localName !== name))
1588
1635
  throw new Error("Picture effect source does not match its kind");
1589
- const set = (name2, value) => {
1636
+ const set2 = (name2, value) => {
1590
1637
  const original = picturePercentage(node.getAttribute(name2));
1591
1638
  if (value === void 0) node.removeAttribute(name2);
1592
1639
  else if (value !== original) {
@@ -1599,12 +1646,12 @@ function applyPictureEffects(blip, effects) {
1599
1646
  (value) => value !== void 0 && (!Number.isFinite(value) || Math.abs(value) > 1)
1600
1647
  ))
1601
1648
  throw new RangeError("Picture luminance must be between -1 and 1");
1602
- set("bright", effect.brightness);
1603
- set("contrast", effect.contrast);
1649
+ set2("bright", effect.brightness);
1650
+ set2("contrast", effect.contrast);
1604
1651
  }
1605
1652
  if (effect.kind === "alphaModFix") {
1606
1653
  if (effect.amount < 0) throw new RangeError("Picture alpha must be nonnegative");
1607
- set("amt", effect.amount);
1654
+ set2("amt", effect.amount);
1608
1655
  }
1609
1656
  return node;
1610
1657
  });
@@ -2917,6 +2964,233 @@ async function openZip(input, limits = {}) {
2917
2964
  return guardZip(await JSZip.loadAsync(bytes), limits);
2918
2965
  }
2919
2966
 
2967
+ // opc/properties/patch.ts
2968
+ var XMLNS3 = "http://www.w3.org/2000/xmlns/";
2969
+ function tagEnd(xml, from) {
2970
+ let quote = "";
2971
+ for (let i = from + 1; i < xml.length; i++) {
2972
+ const ch = xml[i];
2973
+ if (quote) {
2974
+ if (ch === quote) quote = "";
2975
+ } else if (ch === '"' || ch === "'") quote = ch;
2976
+ else if (ch === ">") return i + 1;
2977
+ }
2978
+ throw new Error("Unterminated tag in property part");
2979
+ }
2980
+ function skipMarkup(xml, at) {
2981
+ if (xml.startsWith("<!--", at)) return xml.indexOf("-->", at) + 3;
2982
+ if (xml.startsWith("<![CDATA[", at)) return xml.indexOf("]]>", at) + 3;
2983
+ if (xml.startsWith("<?", at)) return xml.indexOf("?>", at) + 2;
2984
+ return void 0;
2985
+ }
2986
+ function scan(xml) {
2987
+ let i = 0;
2988
+ let rootStart = -1;
2989
+ while (rootStart < 0) {
2990
+ const lt = xml.indexOf("<", i);
2991
+ if (lt < 0) throw new Error("Property part has no root element");
2992
+ const skipped = skipMarkup(xml, lt);
2993
+ if (skipped !== void 0) i = skipped;
2994
+ else rootStart = lt;
2995
+ }
2996
+ const openEnd = tagEnd(xml, rootStart);
2997
+ if (xml[openEnd - 2] === "/") {
2998
+ const root = {
2999
+ start: rootStart,
3000
+ openEnd,
3001
+ closeStart: openEnd,
3002
+ end: openEnd,
3003
+ selfClosing: true
3004
+ };
3005
+ return { root, children: [] };
3006
+ }
3007
+ const children3 = [];
3008
+ let depth = 0;
3009
+ let child7;
3010
+ i = openEnd;
3011
+ for (; ; ) {
3012
+ const lt = xml.indexOf("<", i);
3013
+ if (lt < 0) throw new Error("Property part root is not closed");
3014
+ const skipped = skipMarkup(xml, lt);
3015
+ if (skipped !== void 0) {
3016
+ i = skipped;
3017
+ continue;
3018
+ }
3019
+ const end = tagEnd(xml, lt);
3020
+ i = end;
3021
+ if (xml[lt + 1] === "/") {
3022
+ if (depth === 0) {
3023
+ const root = { start: rootStart, openEnd, closeStart: lt, end, selfClosing: false };
3024
+ return { root, children: children3 };
3025
+ }
3026
+ depth--;
3027
+ if (depth === 0 && child7)
3028
+ children3.push({ ...child7, closeStart: lt, end, selfClosing: false });
3029
+ } else if (xml[end - 2] === "/") {
3030
+ if (depth === 0)
3031
+ children3.push({ start: lt, openEnd: end, closeStart: end, end, selfClosing: true });
3032
+ } else {
3033
+ if (depth === 0) child7 = { start: lt, openEnd: end };
3034
+ depth++;
3035
+ }
3036
+ }
3037
+ }
3038
+ var escapeText = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\r/g, "&#xD;");
3039
+ var qualifiedName = (xml, span) => /^<([^\s/>]+)/.exec(xml.slice(span.start, span.openEnd))?.[1] ?? "";
3040
+ var PartPatch = class {
3041
+ constructor(xml, rootElement) {
3042
+ this.xml = xml;
3043
+ const { root, children: children3 } = scan(xml);
3044
+ const kids = elements(rootElement);
3045
+ if (kids.length !== children3.length) throw new Error("Property part markup is not supported");
3046
+ kids.forEach((kid, index) => this.spans.set(kid, children3[index]));
3047
+ this.root = root;
3048
+ for (const attribute2 of Array.from(rootElement.attributes)) {
3049
+ if (attribute2.name === "xmlns") this.defaultNs = attribute2.value;
3050
+ else if (attribute2.namespaceURI === XMLNS3 || attribute2.name.startsWith("xmlns:"))
3051
+ this.prefixes.set(attribute2.value, attribute2.localName);
3052
+ }
3053
+ }
3054
+ xml;
3055
+ root;
3056
+ spans = /* @__PURE__ */ new Map();
3057
+ edits = [];
3058
+ appended = [];
3059
+ prefixes = /* @__PURE__ */ new Map();
3060
+ defaultNs = null;
3061
+ seq = 0;
3062
+ add(start, end, text) {
3063
+ this.edits.push({ start, end, text, seq: this.seq++ });
3064
+ }
3065
+ span(element4) {
3066
+ const span = this.spans.get(element4);
3067
+ if (!span) throw new Error("Element is not a child of the patched root");
3068
+ return span;
3069
+ }
3070
+ /** The prefix bound to `ns` on the root, declaring `preferred` for it when none is. */
3071
+ prefix(ns, preferred) {
3072
+ const known = this.prefixes.get(ns);
3073
+ if (known !== void 0) return known;
3074
+ const taken = new Set(this.prefixes.values());
3075
+ let prefix2 = preferred;
3076
+ for (let n = 1; taken.has(prefix2); n++) prefix2 = `${preferred}${n}`;
3077
+ this.prefixes.set(ns, prefix2);
3078
+ const at = this.root.openEnd - (this.root.selfClosing ? 2 : 1);
3079
+ this.add(at, at, ` xmlns:${prefix2}="${ns}"`);
3080
+ return prefix2;
3081
+ }
3082
+ /** `local` qualified for an element in `ns`: unprefixed in the default namespace. */
3083
+ qualify(ns, local, preferred) {
3084
+ return this.defaultNs === ns && !this.prefixes.has(ns) ? local : `${this.prefix(ns, preferred)}:${local}`;
3085
+ }
3086
+ /** Replaces the element's content, keeping its start tag (and attributes) as written. */
3087
+ setContent(element4, content) {
3088
+ const span = this.span(element4);
3089
+ if (span.selfClosing)
3090
+ this.add(span.openEnd - 2, span.openEnd, `>${content}</${qualifiedName(this.xml, span)}>`);
3091
+ else this.add(span.openEnd, span.closeStart, content);
3092
+ }
3093
+ /** Adds ` name="value"` text to the element's start tag. */
3094
+ addAttribute(element4, attribute2) {
3095
+ const span = this.span(element4);
3096
+ const at = span.openEnd - (span.selfClosing ? 2 : 1);
3097
+ this.add(at, at, attribute2);
3098
+ }
3099
+ remove(element4) {
3100
+ const span = this.span(element4);
3101
+ this.add(span.start, span.end, "");
3102
+ }
3103
+ /** Inserts `markup` before `before`, or as the root's last child. */
3104
+ insert(markup, before) {
3105
+ if (before) {
3106
+ const at = this.span(before).start;
3107
+ this.add(at, at, markup);
3108
+ } else this.appended.push(markup);
3109
+ }
3110
+ toString() {
3111
+ const edits = [...this.edits];
3112
+ if (this.appended.length) {
3113
+ const text = this.appended.join("");
3114
+ const root = this.root;
3115
+ if (root.selfClosing) {
3116
+ const name = qualifiedName(this.xml, root);
3117
+ edits.push({
3118
+ start: root.end - 2,
3119
+ end: root.end,
3120
+ text: `>${text}</${name}>`,
3121
+ seq: this.seq
3122
+ });
3123
+ } else edits.push({ start: root.closeStart, end: root.closeStart, text, seq: this.seq });
3124
+ }
3125
+ edits.sort((a2, b) => a2.start - b.start || a2.end - a2.start - (b.end - b.start) || a2.seq - b.seq);
3126
+ let out = "";
3127
+ let at = 0;
3128
+ for (const edit of edits) {
3129
+ out += this.xml.slice(at, edit.start) + edit.text;
3130
+ at = Math.max(at, edit.end);
3131
+ }
3132
+ return out + this.xml.slice(at);
3133
+ }
3134
+ };
3135
+
3136
+ // opc/properties/core.ts
3137
+ var XSI = "http://www.w3.org/2001/XMLSchema-instance";
3138
+ var FIELDS = [
3139
+ ["title", "dc", false],
3140
+ ["subject", "dc", false],
3141
+ ["creator", "dc", false],
3142
+ ["keywords", "cp", false],
3143
+ ["description", "dc", false],
3144
+ ["lastModifiedBy", "cp", false],
3145
+ ["created", "dcterms", true],
3146
+ ["modified", "dcterms", true],
3147
+ ["category", "cp", false],
3148
+ ["contentStatus", "cp", false],
3149
+ ["revision", "cp", false],
3150
+ ["language", "dc", false],
3151
+ ["identifier", "dc", false],
3152
+ ["lastPrinted", "cp", false],
3153
+ ["version", "cp", false]
3154
+ ];
3155
+ FIELDS.map(([field]) => field);
3156
+ var EMPTY_CORE = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3157
+ <cp:coreProperties xmlns:cp="${NS.cp}" xmlns:dc="${NS.dc}" xmlns:dcterms="${NS.dcterms}" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="${XSI}"/>`;
3158
+ function parseCoreProperties(xml) {
3159
+ const out = {};
3160
+ if (!xml) return out;
3161
+ const root = parseXml(xml, { label: "core properties" }).documentElement;
3162
+ for (const [field, prefix2] of FIELDS) {
3163
+ const text = first(root, field, NS[prefix2])?.textContent ?? "";
3164
+ if (text !== "") out[field] = text;
3165
+ }
3166
+ return out;
3167
+ }
3168
+ var formatW3cdtf = (date) => date.toISOString().replace(/\.\d{3}Z$/, "Z");
3169
+ function writeCoreProperties(props, sourceXml) {
3170
+ const xml = sourceXml ?? EMPTY_CORE;
3171
+ const root = parseXml(xml, { label: "core properties" }).documentElement;
3172
+ const patch = new PartPatch(xml, root);
3173
+ for (const [field, prefix2, isDate] of FIELDS) {
3174
+ const ns = NS[prefix2];
3175
+ const value = props[field];
3176
+ const element4 = first(root, field, ns);
3177
+ if (value === void 0 || value === "") {
3178
+ if (element4 && (element4.textContent ?? "") !== "") patch.remove(element4);
3179
+ continue;
3180
+ }
3181
+ if (element4 && element4.textContent === value) continue;
3182
+ const typed = () => ` ${patch.prefix(XSI, "xsi")}:type="${patch.prefix(NS.dcterms, "dcterms")}:W3CDTF"`;
3183
+ if (element4) {
3184
+ if (isDate && !element4.getAttributeNS(XSI, "type")) patch.addAttribute(element4, typed());
3185
+ patch.setContent(element4, escapeText(value));
3186
+ continue;
3187
+ }
3188
+ const name = patch.qualify(ns, field, prefix2);
3189
+ patch.insert(`<${name}${isDate ? typed() : ""}>${escapeText(value)}</${name}>`);
3190
+ }
3191
+ return patch.toString();
3192
+ }
3193
+
2920
3194
  // docx/zip-parts.ts
2921
3195
  var DOCUMENT_RELS_PATH = "word/_rels/document.xml.rels";
2922
3196
  var ensureDocumentRelationship = (zip, type, target) => ensureRelationship(zip, DOCUMENT_RELS_PATH, type, target);
@@ -2944,7 +3218,7 @@ var PREFIX = {
2944
3218
  };
2945
3219
  var CORE_TYPE = "application/vnd.openxmlformats-package.core-properties+xml";
2946
3220
  var CORE_REL = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
2947
- function parseCoreProperties(xml) {
3221
+ function parseCoreProperties2(xml) {
2948
3222
  const root = parseXml2(xml).documentElement;
2949
3223
  const result = {};
2950
3224
  for (const field of PROPERTY_FIELDS) {
@@ -3012,265 +3286,18 @@ function dropAddedFolders(zip, source2) {
3012
3286
  if (entry2.dir && !source2.has(name)) delete zip.files[name];
3013
3287
  }
3014
3288
 
3015
- // docx/content-control.ts
3016
- var WORD_2012_NS = "http://schemas.microsoft.com/office/word/2012/wordml";
3017
- var sdtContent = (sdt) => first2(sdt, "sdtContent");
3018
- var isSdt = (element4) => named2(element4, "sdt");
3019
- var TYPE_ELEMENTS = {
3020
- text: "text",
3021
- dropDownList: "dropDownList",
3022
- comboBox: "comboBox",
3023
- date: "date",
3024
- picture: "picture",
3025
- group: "group",
3026
- equation: "equation",
3027
- citation: "citation",
3028
- bibliography: "bibliography",
3029
- docPartObj: "docPartObj",
3030
- docPartList: "docPartList"
3031
- };
3032
- function attrW14(element4, local) {
3033
- return element4?.getAttributeNS(WORD_2010_NS, local) ?? void 0;
3289
+ // docx/save-modified.ts
3290
+ var CORE_PATH2 = "docProps/core.xml";
3291
+ async function stampModified(zip, option) {
3292
+ if (!option) return;
3293
+ const file = zip.file(CORE_PATH2);
3294
+ if (!file) return;
3295
+ const source2 = await file.async("string");
3296
+ const props = parseCoreProperties(source2);
3297
+ props.modified = formatW3cdtf(option.at ?? /* @__PURE__ */ new Date());
3298
+ if (option.author) props.lastModifiedBy = option.author;
3299
+ zip.file(CORE_PATH2, writeCoreProperties(props, source2));
3034
3300
  }
3035
- function glyph(element4) {
3036
- const code = attrW14(element4, "val");
3037
- if (!code) return void 0;
3038
- const font = attrW14(element4, "font");
3039
- return { code, ...font ? { font } : {} };
3040
- }
3041
- function kindOf(child7) {
3042
- if (child7.namespaceURI === WORD_NS)
3043
- return Object.hasOwn(TYPE_ELEMENTS, child7.localName) ? TYPE_ELEMENTS[child7.localName] : void 0;
3044
- if (child7.namespaceURI === WORD_2010_NS && child7.localName === "checkbox") return "checkbox";
3045
- if (child7.namespaceURI === WORD_2012_NS && child7.localName === "repeatingSection")
3046
- return "repeatingSection";
3047
- return void 0;
3048
- }
3049
- var typeElements = (sdtPr) => Array.from(sdtPr.childNodes).filter(isElement).filter(
3050
- (child7) => kindOf(child7) !== void 0 || child7.namespaceURI === WORD_NS && child7.localName === "richText" || child7.namespaceURI === WORD_2010_NS && child7.localName === "entityPicker" || child7.namespaceURI === WORD_2012_NS && child7.localName === "repeatingSectionItem"
3051
- );
3052
- function parseKind(sdtPr) {
3053
- const [type] = typeElements(sdtPr);
3054
- return (type && kindOf(type)) ?? "richText";
3055
- }
3056
- var generated = 0;
3057
- function parseContentControl(sdt, level3) {
3058
- const sdtPr = first2(sdt, "sdtPr");
3059
- if (!sdtPr) return { id: `sdt-gen-${++generated}`, level: level3, kind: "richText" };
3060
- const kind = parseKind(sdtPr);
3061
- const control = {
3062
- id: getW(first2(sdtPr, "id"), "val") ?? `sdt-gen-${++generated}`,
3063
- level: level3,
3064
- kind
3065
- };
3066
- const alias = getW(first2(sdtPr, "alias"), "val");
3067
- if (alias !== void 0) control.alias = alias;
3068
- const tag = getW(first2(sdtPr, "tag"), "val");
3069
- if (tag !== void 0) control.tag = tag;
3070
- const lock = getW(first2(sdtPr, "lock"), "val");
3071
- if (lock === "sdtLocked" || lock === "contentLocked" || lock === "sdtContentLocked")
3072
- control.lock = lock;
3073
- const showing = first2(sdtPr, "showingPlcHdr");
3074
- if (showing) control.showingPlaceholder = parseOnOff(getW(showing, "val")) ?? true;
3075
- if (first2(sdtPr, "dataBinding")) control.dataBound = true;
3076
- const temporary = first2(sdtPr, "temporary");
3077
- if (temporary && (parseOnOff(getW(temporary, "val")) ?? true)) control.temporary = true;
3078
- const placeholder = getW(first2(first2(sdtPr, "placeholder"), "docPart"), "val");
3079
- if (placeholder) control.placeholder = placeholder;
3080
- if (kind === "text") {
3081
- const multi = parseOnOff(getW(first2(sdtPr, "text"), "multiLine"));
3082
- if (multi) control.multiLine = true;
3083
- }
3084
- if (kind === "checkbox") {
3085
- const box = children(sdtPr, "checkbox", WORD_2010_NS, false)[0];
3086
- const checked = first(box, "checked", WORD_2010_NS, false);
3087
- control.checked = parseOnOff(attrW14(checked, "val")) ?? false;
3088
- const on = glyph(first(box, "checkedState", WORD_2010_NS, false));
3089
- const off = glyph(first(box, "uncheckedState", WORD_2010_NS, false));
3090
- if (on) control.checkedGlyph = on;
3091
- if (off) control.uncheckedGlyph = off;
3092
- }
3093
- if (kind === "dropDownList" || kind === "comboBox") {
3094
- const list2 = first2(sdtPr, kind);
3095
- control.items = (list2 ? Array.from(list2.childNodes).filter(isElement) : []).filter((item2) => named2(item2, "listItem")).map((item2) => {
3096
- const display = getW(item2, "displayText");
3097
- const value = getW(item2, "value") ?? display ?? "";
3098
- return { display: display ?? value, value };
3099
- });
3100
- }
3101
- if (kind === "date") {
3102
- const date = first2(sdtPr, "date");
3103
- const fullDate = getW(date, "fullDate");
3104
- if (fullDate) control.fullDate = fullDate;
3105
- const format = getW(first2(date, "dateFormat"), "val");
3106
- if (format) control.dateFormat = format;
3107
- const lid = getW(first2(date, "lid"), "val");
3108
- if (lid) control.dateLocale = lid;
3109
- }
3110
- control.sourceXml = buildXml(sdtPr);
3111
- const end = first2(sdt, "sdtEndPr");
3112
- if (end) control.endSourceXml = buildXml(end);
3113
- return control;
3114
- }
3115
-
3116
- // docx/expect-defined.ts
3117
- function expectDefined(value, context) {
3118
- if (value === void 0 || value === null) {
3119
- throw new Error(`Internal invariant violated: ${context} is missing.`);
3120
- }
3121
- return value;
3122
- }
3123
-
3124
- // docx/parse-revisions.ts
3125
- var REVISION_WRAPPERS = {
3126
- ins: "insert",
3127
- del: "delete",
3128
- moveFrom: "moveFrom",
3129
- moveTo: "moveTo"
3130
- };
3131
- var MOVE_RANGES = {
3132
- moveFromRangeStart: { kind: "moveFrom", start: true },
3133
- moveFromRangeEnd: { kind: "moveFrom", start: false },
3134
- moveToRangeStart: { kind: "moveTo", start: true },
3135
- moveToRangeEnd: { kind: "moveTo", start: false }
3136
- };
3137
- function trackMoveRange(item2, moves) {
3138
- if (item2.namespaceURI && item2.namespaceURI !== WORD_NS) return false;
3139
- const range = MOVE_RANGES[item2.localName ?? ""];
3140
- if (!range) return false;
3141
- const id = getW(item2, "id") ?? "";
3142
- const open = moves[range.kind];
3143
- if (range.start) open.push({ name: getW(item2, "name") ?? id, id });
3144
- else {
3145
- const index = open.findIndex((entry2) => entry2.id === id);
3146
- if (index >= 0) open.splice(index, 1);
3147
- }
3148
- return true;
3149
- }
3150
- function isCommentReferenceRun(run2) {
3151
- const content = Array.from(run2.childNodes).filter(
3152
- (child7) => isElement(child7) && !named2(child7, "rPr")
3153
- );
3154
- return content.length > 0 && content.every((child7) => named2(child7, "commentReference"));
3155
- }
3156
- function revisionFrom(node, kind) {
3157
- const revision = {
3158
- kind,
3159
- author: getW(node, "author") || "Unknown",
3160
- id: getW(node, "id") ?? "0"
3161
- };
3162
- const date = getW(node, "date");
3163
- if (date) revision.date = date;
3164
- const dateUtc = node.getAttributeNS(WORD_DATE_UTC_NS, "dateUtc");
3165
- if (dateUtc) revision.dateUtc = dateUtc;
3166
- return revision;
3167
- }
3168
- function paragraphMarkRevision(pPr) {
3169
- const rPr = first2(pPr, "rPr");
3170
- const ins = first2(rPr, "ins");
3171
- if (ins) return revisionFrom(ins, "insert");
3172
- const del = first2(rPr, "del");
3173
- if (del) return revisionFrom(del, "delete");
3174
- return void 0;
3175
- }
3176
- function paragraphFormatRevision(pPr) {
3177
- const change = first2(pPr, "pPrChange");
3178
- if (!change) return void 0;
3179
- const revision = revisionFrom(change, "paragraphChange");
3180
- const previous = first2(change, "pPr");
3181
- if (previous) revision.previousParagraphPropertiesXml = buildXml(previous);
3182
- return revision;
3183
- }
3184
- function runFormatRevision(rPr) {
3185
- const change = first2(rPr, "rPrChange");
3186
- if (!change) return void 0;
3187
- const revision = revisionFrom(change, "formatChange");
3188
- const previous = first2(change, "rPr");
3189
- if (previous) revision.previousRunPropertiesXml = buildXml(previous);
3190
- return revision;
3191
- }
3192
- function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active = [], moves = { moveFrom: [], moveTo: [] }) {
3193
- const runs = [];
3194
- let hasMove = false;
3195
- const push = (run2) => {
3196
- if (active.length) run2.commentIds = [.../* @__PURE__ */ new Set([...active, ...run2.commentIds ?? []])];
3197
- runs.push(run2);
3198
- };
3199
- for (const item2 of Array.from(node.childNodes).filter(isElement)) {
3200
- if (named2(item2, "r")) {
3201
- if (!isCommentReferenceRun(item2)) push(parseRun3(item2));
3202
- } else if (named2(item2, "hyperlink")) {
3203
- const link = resolveLink?.(item2);
3204
- for (const child7 of Array.from(item2.childNodes).filter(isElement)) {
3205
- for (const parsed of named2(child7, "r") ? [parseRun3(child7)] : parseOther?.(child7) ?? []) {
3206
- if (link) parsed.link = link;
3207
- push(parsed);
3208
- }
3209
- }
3210
- } else if ((!item2.namespaceURI || item2.namespaceURI === WORD_NS) && Object.hasOwn(REVISION_WRAPPERS, item2.localName)) {
3211
- const kind = expectDefined(
3212
- REVISION_WRAPPERS[item2.localName],
3213
- `revision wrapper ${item2.localName}`
3214
- );
3215
- if (kind === "moveFrom" || kind === "moveTo") hasMove = true;
3216
- const revision = revisionFrom(item2, kind);
3217
- const range = kind === "moveFrom" || kind === "moveTo" ? moves[kind].at(-1) : void 0;
3218
- if (range) revision.move = { name: range.name, rangeId: range.id };
3219
- for (const child7 of Array.from(item2.childNodes).filter(isElement)) {
3220
- for (const parsed of named2(child7, "r") ? [parseRun3(child7, revision)] : parseOther?.(child7) ?? []) {
3221
- parsed.revision = revision;
3222
- push(parsed);
3223
- }
3224
- }
3225
- } else if (trackMoveRange(item2, moves)) {
3226
- continue;
3227
- } else if (named2(item2, "commentRangeStart")) {
3228
- const id = getW(item2, "id");
3229
- if (id !== void 0) active.push(id);
3230
- } else if (named2(item2, "commentRangeEnd")) {
3231
- const id = getW(item2, "id");
3232
- const index = id === void 0 ? -1 : active.indexOf(id);
3233
- if (index >= 0) active.splice(index, 1);
3234
- } else {
3235
- for (const run2 of parseOther?.(item2) ?? []) push(run2);
3236
- }
3237
- }
3238
- return { runs, hasMove };
3239
- }
3240
-
3241
- // docx/parse-content-control.ts
3242
- function parseInlineControl(sdt, parseRun3, parseOther, resolveLink, comments, moves) {
3243
- const control = parseContentControl(sdt, "inline");
3244
- const content = sdtContent(sdt);
3245
- const runs = content ? collectParagraphRuns(content, parseRun3, parseOther, resolveLink, comments, moves).runs : [];
3246
- if (!runs.length) return [{ text: "", contentControl: control }];
3247
- for (const run2 of runs) run2.contentControl ??= control;
3248
- return runs;
3249
- }
3250
- function flatChildren(parent, names, level3 = "block", enclosing, controls = /* @__PURE__ */ new Map()) {
3251
- const found = [];
3252
- for (const child7 of Array.from(parent.childNodes).filter(isElement)) {
3253
- if (isSdt(child7)) {
3254
- const content = sdtContent(child7);
3255
- if (!content) continue;
3256
- let control = controls.get(child7);
3257
- if (!control) {
3258
- control = parseContentControl(child7, level3);
3259
- controls.set(child7, control);
3260
- }
3261
- found.push(...flatChildren(content, names, level3, { control, sdt: child7 }, controls));
3262
- } else if (names.some((name) => named2(child7, name)))
3263
- found.push({
3264
- element: child7,
3265
- ...enclosing ? { control: enclosing.control, sdt: enclosing.sdt } : {}
3266
- });
3267
- }
3268
- return found;
3269
- }
3270
- var flatBlocks = (container) => flatChildren(container, ["p", "tbl"]);
3271
- var flatRows = (table) => flatChildren(table, ["tr"], "row");
3272
- var flatCells = (row) => flatChildren(row, ["tc"], "cell");
3273
- var flatCellParagraphs = (cell2) => flatChildren(cell2, ["p"]);
3274
3301
 
3275
3302
  // docx/element-order.ts
3276
3303
  var RPR_ORDER = [
@@ -3359,6 +3386,720 @@ function orderSectionProperties(sectPr) {
3359
3386
  orderChildren(sectPr, SECTPR_ORDER);
3360
3387
  }
3361
3388
 
3389
+ // docx/tab-stops.ts
3390
+ function parseTabStops(tabs) {
3391
+ const stops = [];
3392
+ for (const tab of tabs ? children2(tabs, "tab") : []) {
3393
+ const align = enumValue(isStTabJc, getW(tab, "val"), "w:tab/@w:val");
3394
+ const pos = parseSignedTwips(getW(tab, "pos"));
3395
+ if (!align || pos === void 0) continue;
3396
+ const leader = enumValue(isStTabTlc, getW(tab, "leader"), "w:tab/@w:leader");
3397
+ stops.push({ posTwips: pos, align, ...leader ? { leader } : {} });
3398
+ }
3399
+ return stops;
3400
+ }
3401
+ function writeTabStops(doc, props, paragraph2, base) {
3402
+ if (base && JSON.stringify(paragraph2.tabStops ?? []) === JSON.stringify(base.tabStops ?? []))
3403
+ return;
3404
+ for (const tabs2 of children2(props, "tabs")) props.removeChild(tabs2);
3405
+ if (!paragraph2.tabStops?.length) return;
3406
+ const tabs = makeW(doc, "tabs");
3407
+ for (const stop of paragraph2.tabStops) {
3408
+ const tab = makeW(doc, "tab");
3409
+ tab.setAttributeNS(WORD_NS, "w:val", stop.align);
3410
+ if (stop.leader) tab.setAttributeNS(WORD_NS, "w:leader", stop.leader);
3411
+ tab.setAttributeNS(WORD_NS, "w:pos", String(stop.posTwips));
3412
+ tabs.appendChild(tab);
3413
+ }
3414
+ props.appendChild(tabs);
3415
+ }
3416
+ var PPR_ORDER = [
3417
+ "pStyle",
3418
+ "keepNext",
3419
+ "keepLines",
3420
+ "pageBreakBefore",
3421
+ "framePr",
3422
+ "widowControl",
3423
+ "numPr",
3424
+ "suppressLineNumbers",
3425
+ "pBdr",
3426
+ "shd",
3427
+ "tabs",
3428
+ "suppressAutoHyphens",
3429
+ "kinsoku",
3430
+ "wordWrap",
3431
+ "overflowPunct",
3432
+ "topLinePunct",
3433
+ "autoSpaceDE",
3434
+ "autoSpaceDN",
3435
+ "bidi",
3436
+ "adjustRightInd",
3437
+ "snapToGrid",
3438
+ "spacing",
3439
+ "ind",
3440
+ "contextualSpacing",
3441
+ "mirrorIndents",
3442
+ "suppressOverlap",
3443
+ "jc",
3444
+ "textDirection",
3445
+ "textAlignment",
3446
+ "textboxTightWrap",
3447
+ "outlineLvl",
3448
+ "divId",
3449
+ "cnfStyle",
3450
+ "rPr",
3451
+ "sectPr",
3452
+ "pPrChange"
3453
+ ];
3454
+ function orderParagraphProperties(props) {
3455
+ orderChildren(props, PPR_ORDER);
3456
+ }
3457
+
3458
+ // docx/write-paragraph-decoration.ts
3459
+ var SIDES3 = ["top", "left", "bottom", "right", "between"];
3460
+ function wordColor(color) {
3461
+ const hex = /^#?([0-9a-f]{6})$/i.exec(color ?? "")?.[1];
3462
+ return hex ? hex.toUpperCase() : "auto";
3463
+ }
3464
+ function borderElement(doc, name, side) {
3465
+ const element4 = makeW(doc, name);
3466
+ const set2 = (local, value) => element4.setAttributeNS(WORD_NS, `w:${local}`, value);
3467
+ set2("val", side.style ?? "single");
3468
+ if (side.style !== "none" && side.style !== "nil") {
3469
+ set2("sz", String(side.sizeEighthPoints ?? 4));
3470
+ set2("space", String(side.spacePoints ?? 1));
3471
+ set2("color", wordColor(side.color));
3472
+ if (side.themeColor) set2("themeColor", side.themeColor);
3473
+ }
3474
+ return element4;
3475
+ }
3476
+ var sameJson = (a2, b) => JSON.stringify(a2 ?? null) === JSON.stringify(b ?? null);
3477
+ function updateShading(doc, props, paragraph2, base) {
3478
+ if (base && paragraph2.shadingFill === base.shadingFill) return;
3479
+ for (const element4 of children2(props, "shd")) props.removeChild(element4);
3480
+ if (!paragraph2.shadingFill) return;
3481
+ const shd = makeW(doc, "shd");
3482
+ shd.setAttributeNS(WORD_NS, "w:val", "clear");
3483
+ shd.setAttributeNS(WORD_NS, "w:color", "auto");
3484
+ shd.setAttributeNS(WORD_NS, "w:fill", wordColor(paragraph2.shadingFill));
3485
+ props.appendChild(shd);
3486
+ }
3487
+ function updateBorders(doc, props, paragraph2, base) {
3488
+ if (base && sameJson(paragraph2.borders, base.borders)) return;
3489
+ for (const element4 of children2(props, "pBdr")) props.removeChild(element4);
3490
+ const borders = paragraph2.borders;
3491
+ if (!borders) return;
3492
+ const pBdr = makeW(doc, "pBdr");
3493
+ for (const side of SIDES3) {
3494
+ const value = borders[side];
3495
+ if (value) pBdr.appendChild(borderElement(doc, side, value));
3496
+ }
3497
+ if (pBdr.childNodes.length) props.appendChild(pBdr);
3498
+ }
3499
+ function writeParagraphDecoration(doc, props, paragraph2, base) {
3500
+ updateShading(doc, props, paragraph2, base);
3501
+ updateBorders(doc, props, paragraph2, base);
3502
+ }
3503
+
3504
+ // docx/write-paragraph-properties.ts
3505
+ function setAttribute(element4, local, value) {
3506
+ element4.setAttributeNS(WORD_NS, `w:${local}`, value);
3507
+ }
3508
+ function setWordValue(element4, local, value) {
3509
+ if (value === void 0) element4.removeAttributeNS(WORD_NS, local);
3510
+ else setAttribute(element4, local, String(value));
3511
+ }
3512
+ function updateDirection(doc, props, paragraph2, base) {
3513
+ if (base && paragraph2.direction === base.direction) return;
3514
+ let bidi = first2(props, "bidi");
3515
+ if (paragraph2.direction === void 0) {
3516
+ for (const element4 of children2(props, "bidi")) props.removeChild(element4);
3517
+ } else {
3518
+ if (!bidi) {
3519
+ bidi = makeW(doc, "bidi");
3520
+ props.appendChild(bidi);
3521
+ }
3522
+ setAttribute(bidi, "val", paragraph2.direction === "rtl" ? "1" : "0");
3523
+ }
3524
+ }
3525
+ function updateSpacing(doc, props, paragraph2, base) {
3526
+ let spacing2 = first2(props, "spacing");
3527
+ if (!spacing2) {
3528
+ spacing2 = makeW(doc, "spacing");
3529
+ props.appendChild(spacing2);
3530
+ }
3531
+ if (!base || paragraph2.spacingBeforeTwips !== base.spacingBeforeTwips)
3532
+ setWordValue(spacing2, "before", paragraph2.spacingBeforeTwips);
3533
+ if (!base || paragraph2.spacingAfterTwips !== base.spacingAfterTwips)
3534
+ setWordValue(spacing2, "after", paragraph2.spacingAfterTwips);
3535
+ if (!base || paragraph2.lineSpacingTwips !== base.lineSpacingTwips || paragraph2.lineSpacingRule !== base.lineSpacingRule) {
3536
+ setWordValue(spacing2, "line", paragraph2.lineSpacingTwips);
3537
+ setWordValue(
3538
+ spacing2,
3539
+ "lineRule",
3540
+ paragraph2.lineSpacingRule ?? (paragraph2.lineSpacingTwips === void 0 ? void 0 : "auto")
3541
+ );
3542
+ }
3543
+ if (!spacing2.attributes.length && !spacing2.childNodes.length) props.removeChild(spacing2);
3544
+ }
3545
+ function updateIndent(doc, props, paragraph2, base) {
3546
+ let indent = first2(props, "ind");
3547
+ if (!indent) {
3548
+ indent = makeW(doc, "ind");
3549
+ props.appendChild(indent);
3550
+ }
3551
+ if (!base || paragraph2.indentLeftTwips !== base.indentLeftTwips)
3552
+ setWordValue(indent, "left", paragraph2.indentLeftTwips);
3553
+ if (!base || paragraph2.indentRightTwips !== base.indentRightTwips)
3554
+ setWordValue(indent, "right", paragraph2.indentRightTwips);
3555
+ if (!base || paragraph2.indentStartTwips !== base.indentStartTwips)
3556
+ setWordValue(indent, "start", paragraph2.indentStartTwips);
3557
+ if (!base || paragraph2.indentEndTwips !== base.indentEndTwips)
3558
+ setWordValue(indent, "end", paragraph2.indentEndTwips);
3559
+ if (!base || paragraph2.firstLineTwips !== base.firstLineTwips)
3560
+ setWordValue(indent, "firstLine", paragraph2.firstLineTwips);
3561
+ if (!base || paragraph2.hangingTwips !== base.hangingTwips)
3562
+ setWordValue(indent, "hanging", paragraph2.hangingTwips);
3563
+ if (!indent.attributes.length) props.removeChild(indent);
3564
+ }
3565
+ function updatePageBreakBefore(doc, props, paragraph2, base) {
3566
+ if (base && paragraph2.pageBreakBefore === base.pageBreakBefore) return;
3567
+ for (const element4 of children2(props, "pageBreakBefore")) props.removeChild(element4);
3568
+ if (paragraph2.pageBreakBefore !== void 0) {
3569
+ const element4 = makeW(doc, "pageBreakBefore");
3570
+ if (!paragraph2.pageBreakBefore) element4.setAttributeNS(WORD_NS, "w:val", "0");
3571
+ props.appendChild(element4);
3572
+ }
3573
+ }
3574
+ function updateKeepOptions(doc, props, paragraph2, base) {
3575
+ for (const key of [
3576
+ "keepNext",
3577
+ "keepLines",
3578
+ "widowControl",
3579
+ "contextualSpacing",
3580
+ "suppressLineNumbers"
3581
+ ]) {
3582
+ if (base && paragraph2[key] === base[key]) continue;
3583
+ for (const element5 of children2(props, key)) props.removeChild(element5);
3584
+ const value = paragraph2[key];
3585
+ if (value === void 0) continue;
3586
+ const element4 = makeW(doc, key);
3587
+ if (!value) setAttribute(element4, "val", "0");
3588
+ props.appendChild(element4);
3589
+ }
3590
+ }
3591
+ function updateDropCap(doc, props, paragraph2, base) {
3592
+ if (base && JSON.stringify(paragraph2.dropCap) === JSON.stringify(base.dropCap)) return;
3593
+ let frame2 = first2(props, "framePr");
3594
+ const cap = paragraph2.dropCap;
3595
+ if (!cap) {
3596
+ if (frame2) props.removeChild(frame2);
3597
+ return;
3598
+ }
3599
+ if (!frame2) {
3600
+ frame2 = makeW(doc, "framePr");
3601
+ props.appendChild(frame2);
3602
+ setAttribute(frame2, "wrap", "around");
3603
+ setAttribute(frame2, "vAnchor", "text");
3604
+ setAttribute(frame2, "hAnchor", "text");
3605
+ }
3606
+ setAttribute(frame2, "dropCap", cap.style);
3607
+ setAttribute(frame2, "lines", String(cap.lines));
3608
+ setWordValue(frame2, "hSpace", cap.distanceTwips);
3609
+ }
3610
+ function writeParagraphProperties(doc, props, paragraph2, base) {
3611
+ updatePageBreakBefore(doc, props, paragraph2, base);
3612
+ updateKeepOptions(doc, props, paragraph2, base);
3613
+ updateDropCap(doc, props, paragraph2, base);
3614
+ updateDirection(doc, props, paragraph2, base);
3615
+ writeParagraphDecoration(doc, props, paragraph2, base);
3616
+ const spacingKeys = [
3617
+ "spacingBeforeTwips",
3618
+ "spacingAfterTwips",
3619
+ "lineSpacingTwips",
3620
+ "lineSpacingRule"
3621
+ ];
3622
+ if (!base || spacingKeys.some((key) => paragraph2[key] !== base[key]))
3623
+ updateSpacing(doc, props, paragraph2, base);
3624
+ const indentKeys = [
3625
+ "indentLeftTwips",
3626
+ "indentRightTwips",
3627
+ "indentStartTwips",
3628
+ "indentEndTwips",
3629
+ "firstLineTwips",
3630
+ "hangingTwips"
3631
+ ];
3632
+ if (!base || indentKeys.some((key) => paragraph2[key] !== base[key]))
3633
+ updateIndent(doc, props, paragraph2, base);
3634
+ }
3635
+
3636
+ // docx/style-formatting-package.ts
3637
+ var STYLES_PART = "word/styles.xml";
3638
+ var AFTER_PPR = ["rPr", "tblPr", "trPr", "tcPr", "tblStylePr"];
3639
+ var WRITABLE_STYLE_FORMATTING = [
3640
+ "align",
3641
+ "justification",
3642
+ "direction",
3643
+ "spacingBeforeTwips",
3644
+ "spacingAfterTwips",
3645
+ "lineSpacingTwips",
3646
+ "lineSpacingRule",
3647
+ "indentLeftTwips",
3648
+ "indentRightTwips",
3649
+ "indentStartTwips",
3650
+ "indentEndTwips",
3651
+ "firstLineTwips",
3652
+ "hangingTwips",
3653
+ "pageBreakBefore",
3654
+ "keepNext",
3655
+ "keepLines",
3656
+ "widowControl",
3657
+ "contextualSpacing",
3658
+ "suppressLineNumbers",
3659
+ "borders",
3660
+ "shadingFill"
3661
+ ];
3662
+ function unwritableFormatting(formatting) {
3663
+ const rest = { ...formatting };
3664
+ for (const key of WRITABLE_STYLE_FORMATTING) delete rest[key];
3665
+ return rest;
3666
+ }
3667
+ var asParagraph = (formatting) => ({
3668
+ type: "paragraph",
3669
+ id: "style",
3670
+ runs: [],
3671
+ ...formatting
3672
+ });
3673
+ function pPrOf(style) {
3674
+ let pPr = first2(style, "pPr");
3675
+ if (pPr) return pPr;
3676
+ pPr = makeW(style.ownerDocument, "pPr");
3677
+ const anchor = Array.from(style.childNodes).find(
3678
+ (node) => node.nodeType === 1 && AFTER_PPR.includes(node.localName)
3679
+ ) ?? null;
3680
+ style.insertBefore(pPr, anchor);
3681
+ return pPr;
3682
+ }
3683
+ async function applyStyleFormatting(zip, model, base) {
3684
+ const next = model.paragraphStyles?.styles ?? {};
3685
+ const prior = base.paragraphStyles?.styles ?? {};
3686
+ const changed = Object.keys(next).filter(
3687
+ (id) => JSON.stringify(next[id]?.formatting) !== JSON.stringify(prior[id]?.formatting)
3688
+ );
3689
+ if (!changed.length) return;
3690
+ const file = zip.file(STYLES_PART);
3691
+ if (!file) throw new Error("Cannot edit a style: the package has no styles.xml.");
3692
+ const doc = parseXml2(await file.async("string"));
3693
+ const styles = children2(doc.documentElement, "style");
3694
+ for (const id of changed) {
3695
+ const style = styles.find(
3696
+ (element4) => getW(element4, "type") === "paragraph" && getW(element4, "styleId") === id
3697
+ );
3698
+ if (!style) throw new Error(`Cannot edit style "${id}": it is not in styles.xml.`);
3699
+ const after = asParagraph(next[id].formatting);
3700
+ const before = asParagraph(prior[id]?.formatting ?? {});
3701
+ const pPr = pPrOf(style);
3702
+ if (after.align !== before.align || after.justification !== before.justification || after.direction !== before.direction) {
3703
+ for (const jc of children2(pPr, "jc")) pPr.removeChild(jc);
3704
+ const value = paragraphJustification(after);
3705
+ if (value) {
3706
+ const jc = makeW(doc, "jc");
3707
+ jc.setAttributeNS(WORD_NS, "w:val", value);
3708
+ pPr.appendChild(jc);
3709
+ }
3710
+ }
3711
+ writeParagraphProperties(doc, pPr, after, before);
3712
+ orderParagraphProperties(pPr);
3713
+ }
3714
+ zip.file(STYLES_PART, buildXml(doc));
3715
+ }
3716
+
3717
+ // docx/data-binding.ts
3718
+ function parsePrefixes(text) {
3719
+ const map = /* @__PURE__ */ new Map();
3720
+ for (const match of (text ?? "").matchAll(/xmlns:([\w.-]+)\s*=\s*(?:'([^']*)'|"([^"]*)")/g))
3721
+ map.set(match[1], match[2] ?? match[3] ?? "");
3722
+ return map;
3723
+ }
3724
+ function sourceBindings(sourceXml) {
3725
+ const result = /* @__PURE__ */ new Map();
3726
+ const document = parseXml2(sourceXml);
3727
+ for (const sdt of Array.from(document.getElementsByTagNameNS(WORD_NS, "sdt"))) {
3728
+ const sdtPr = first2(sdt, "sdtPr");
3729
+ const element4 = sdtPr && elements(sdtPr).find((node) => node.localName === "dataBinding");
3730
+ const id = getW(first2(sdtPr, "id"), "val");
3731
+ const xpath = element4?.getAttributeNS(WORD_NS, "xpath");
3732
+ const storeItemId = element4?.getAttributeNS(WORD_NS, "storeItemID");
3733
+ if (id && element4 && xpath && storeItemId)
3734
+ result.set(id, {
3735
+ xpath,
3736
+ storeItemId,
3737
+ prefixes: parsePrefixes(element4.getAttributeNS(WORD_NS, "prefixMappings") ?? void 0)
3738
+ });
3739
+ }
3740
+ return result;
3741
+ }
3742
+ function paragraphsOf(blocks) {
3743
+ return blocks.flatMap(
3744
+ (block) => block.type === "paragraph" ? [block] : block.rows.flatMap((row) => row.flatMap((c2) => c2.paragraphs))
3745
+ );
3746
+ }
3747
+ function boundTexts(model) {
3748
+ const parts = /* @__PURE__ */ new Map();
3749
+ const add4 = (id, text) => parts.set(id, [...parts.get(id) ?? [], text]);
3750
+ for (const paragraph2 of paragraphsOf(model.blocks)) {
3751
+ const own2 = paragraph2.contentControl;
3752
+ if (own2?.dataBound) {
3753
+ add4(own2.id, paragraph2.runs.map((run2) => run2.text).join(""));
3754
+ continue;
3755
+ }
3756
+ const inline = /* @__PURE__ */ new Map();
3757
+ for (const run2 of paragraph2.runs) {
3758
+ const control = run2.contentControl;
3759
+ if (!control?.dataBound) continue;
3760
+ if (!inline.has(control.id)) inline.set(control.id, "");
3761
+ if (!control.showingPlaceholder) inline.set(control.id, inline.get(control.id) + run2.text);
3762
+ }
3763
+ for (const [id, text] of inline) add4(id, text);
3764
+ }
3765
+ return new Map([...parts].map(([id, texts]) => [id, texts.join("\n")]));
3766
+ }
3767
+ function parseXPath(binding) {
3768
+ const parts = binding.xpath.split("/");
3769
+ if (parts.shift() !== "" || !parts.length) return void 0;
3770
+ if (parts.at(-1) === "text()") parts.pop();
3771
+ const parse = (raw2, attribute3) => {
3772
+ const match = /^(?:([A-Za-z_][\w.-]*):)?([A-Za-z_][\w.-]*)(?:\[(\d+)\])?$/.exec(raw2);
3773
+ if (!match || attribute3 && match[3]) return void 0;
3774
+ const [, prefix2 = "", name = "", index] = match;
3775
+ if (prefix2 && !binding.prefixes.has(prefix2)) return void 0;
3776
+ return { prefix: prefix2, name, index: index ? Number(index) : 1 };
3777
+ };
3778
+ const last = parts.at(-1);
3779
+ const attribute2 = last?.startsWith("@") ? parse(last.slice(1), true) : void 0;
3780
+ if (last?.startsWith("@")) {
3781
+ parts.pop();
3782
+ if (!attribute2) return void 0;
3783
+ }
3784
+ const steps = parts.map((part) => parse(part, false));
3785
+ if (!steps.length || steps.some((step) => !step)) return void 0;
3786
+ return { steps, ...attribute2 ? { attribute: attribute2 } : {} };
3787
+ }
3788
+ var matches = (element4, step, binding) => element4.localName === step.name && (element4.namespaceURI ?? "") === (step.prefix ? binding.prefixes.get(step.prefix) ?? "" : "");
3789
+ function writeValue(root, binding, value) {
3790
+ const path3 = parseXPath(binding);
3791
+ if (!path3) return "unsupported";
3792
+ let node = root;
3793
+ for (const [depth, step] of path3.steps.entries()) {
3794
+ const candidates = depth === 0 ? [root].filter((e) => matches(e, step, binding)) : elements(node).filter((e) => matches(e, step, binding));
3795
+ node = candidates[step.index - 1];
3796
+ if (!node) return false;
3797
+ }
3798
+ if (path3.attribute) {
3799
+ const { prefix: prefix2, name } = path3.attribute;
3800
+ const ns = prefix2 ? binding.prefixes.get(prefix2) : void 0;
3801
+ if (ns) node.setAttributeNS(ns, `${prefix2}:${name}`, value);
3802
+ else node.setAttribute(name, value);
3803
+ return true;
3804
+ }
3805
+ for (const child7 of Array.from(node.childNodes)) node.removeChild(child7);
3806
+ if (value) node.appendChild(node.ownerDocument.createTextNode(value));
3807
+ return true;
3808
+ }
3809
+ async function findItemPart(zip, storeItemId) {
3810
+ const wanted = storeItemId.toLowerCase();
3811
+ for (const name of Object.keys(zip.files)) {
3812
+ const props = /^customXml\/itemProps(\d+)\.xml$/.exec(name);
3813
+ if (!props) continue;
3814
+ const root = parseXml2(await zip.file(name).async("string")).documentElement;
3815
+ const id = Array.from(root.attributes).find((attribute2) => attribute2.localName === "itemID");
3816
+ if ((id?.value ?? "").toLowerCase() === wanted) return `customXml/item${props[1]}.xml`;
3817
+ }
3818
+ return void 0;
3819
+ }
3820
+ async function applyDataBindings(zip, model, base, sourceXml) {
3821
+ const now = boundTexts(model);
3822
+ if (!now.size) return;
3823
+ const before = boundTexts(base);
3824
+ const bindings = sourceBindings(sourceXml);
3825
+ const parsed = /* @__PURE__ */ new Map();
3826
+ for (const [id, text] of now) {
3827
+ const binding = bindings.get(id);
3828
+ if (!binding || before.get(id) === text) continue;
3829
+ const part = await findItemPart(zip, binding.storeItemId);
3830
+ const file = part ? zip.file(part) : void 0;
3831
+ if (!part || !file) continue;
3832
+ const document = parsed.get(part) ?? parseXml2(await file.async("string"));
3833
+ parsed.set(part, document);
3834
+ const written = writeValue(document.documentElement, binding, text);
3835
+ if (written !== true)
3836
+ throw new Error(
3837
+ 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.`
3838
+ );
3839
+ }
3840
+ for (const [part, document] of parsed) zip.file(part, buildXml(document));
3841
+ }
3842
+
3843
+ // docx/content-control.ts
3844
+ var WORD_2012_NS = "http://schemas.microsoft.com/office/word/2012/wordml";
3845
+ var sdtContent = (sdt) => first2(sdt, "sdtContent");
3846
+ var isSdt = (element4) => named2(element4, "sdt");
3847
+ var TYPE_ELEMENTS = {
3848
+ text: "text",
3849
+ dropDownList: "dropDownList",
3850
+ comboBox: "comboBox",
3851
+ date: "date",
3852
+ picture: "picture",
3853
+ group: "group",
3854
+ equation: "equation",
3855
+ citation: "citation",
3856
+ bibliography: "bibliography",
3857
+ docPartObj: "docPartObj",
3858
+ docPartList: "docPartList"
3859
+ };
3860
+ function attrW14(element4, local) {
3861
+ return element4?.getAttributeNS(WORD_2010_NS, local) ?? void 0;
3862
+ }
3863
+ function glyph(element4) {
3864
+ const code = attrW14(element4, "val");
3865
+ if (!code) return void 0;
3866
+ const font = attrW14(element4, "font");
3867
+ return { code, ...font ? { font } : {} };
3868
+ }
3869
+ function kindOf(child7) {
3870
+ if (child7.namespaceURI === WORD_NS)
3871
+ return Object.hasOwn(TYPE_ELEMENTS, child7.localName) ? TYPE_ELEMENTS[child7.localName] : void 0;
3872
+ if (child7.namespaceURI === WORD_2010_NS && child7.localName === "checkbox") return "checkbox";
3873
+ if (child7.namespaceURI === WORD_2012_NS && child7.localName === "repeatingSection")
3874
+ return "repeatingSection";
3875
+ return void 0;
3876
+ }
3877
+ var typeElements = (sdtPr) => Array.from(sdtPr.childNodes).filter(isElement).filter(
3878
+ (child7) => kindOf(child7) !== void 0 || child7.namespaceURI === WORD_NS && child7.localName === "richText" || child7.namespaceURI === WORD_2010_NS && child7.localName === "entityPicker" || child7.namespaceURI === WORD_2012_NS && child7.localName === "repeatingSectionItem"
3879
+ );
3880
+ function parseKind(sdtPr) {
3881
+ const [type] = typeElements(sdtPr);
3882
+ return (type && kindOf(type)) ?? "richText";
3883
+ }
3884
+ var generated = 0;
3885
+ function parseContentControl(sdt, level3) {
3886
+ const sdtPr = first2(sdt, "sdtPr");
3887
+ if (!sdtPr) return { id: `sdt-gen-${++generated}`, level: level3, kind: "richText" };
3888
+ const kind = parseKind(sdtPr);
3889
+ const control = {
3890
+ id: getW(first2(sdtPr, "id"), "val") ?? `sdt-gen-${++generated}`,
3891
+ level: level3,
3892
+ kind
3893
+ };
3894
+ const alias = getW(first2(sdtPr, "alias"), "val");
3895
+ if (alias !== void 0) control.alias = alias;
3896
+ const tag = getW(first2(sdtPr, "tag"), "val");
3897
+ if (tag !== void 0) control.tag = tag;
3898
+ const lock = getW(first2(sdtPr, "lock"), "val");
3899
+ if (lock === "sdtLocked" || lock === "contentLocked" || lock === "sdtContentLocked")
3900
+ control.lock = lock;
3901
+ const showing = first2(sdtPr, "showingPlcHdr");
3902
+ if (showing) control.showingPlaceholder = parseOnOff(getW(showing, "val")) ?? true;
3903
+ if (first2(sdtPr, "dataBinding")) control.dataBound = true;
3904
+ const temporary = first2(sdtPr, "temporary");
3905
+ if (temporary && (parseOnOff(getW(temporary, "val")) ?? true)) control.temporary = true;
3906
+ const placeholder = getW(first2(first2(sdtPr, "placeholder"), "docPart"), "val");
3907
+ if (placeholder) control.placeholder = placeholder;
3908
+ if (kind === "text") {
3909
+ const multi = parseOnOff(getW(first2(sdtPr, "text"), "multiLine"));
3910
+ if (multi) control.multiLine = true;
3911
+ }
3912
+ if (kind === "checkbox") {
3913
+ const box = children(sdtPr, "checkbox", WORD_2010_NS, false)[0];
3914
+ const checked = first(box, "checked", WORD_2010_NS, false);
3915
+ control.checked = parseOnOff(attrW14(checked, "val")) ?? false;
3916
+ const on = glyph(first(box, "checkedState", WORD_2010_NS, false));
3917
+ const off = glyph(first(box, "uncheckedState", WORD_2010_NS, false));
3918
+ if (on) control.checkedGlyph = on;
3919
+ if (off) control.uncheckedGlyph = off;
3920
+ }
3921
+ if (kind === "dropDownList" || kind === "comboBox") {
3922
+ const list2 = first2(sdtPr, kind);
3923
+ control.items = (list2 ? Array.from(list2.childNodes).filter(isElement) : []).filter((item2) => named2(item2, "listItem")).map((item2) => {
3924
+ const display = getW(item2, "displayText");
3925
+ const value = getW(item2, "value") ?? display ?? "";
3926
+ return { display: display ?? value, value };
3927
+ });
3928
+ }
3929
+ if (kind === "date") {
3930
+ const date = first2(sdtPr, "date");
3931
+ const fullDate = getW(date, "fullDate");
3932
+ if (fullDate) control.fullDate = fullDate;
3933
+ const format = getW(first2(date, "dateFormat"), "val");
3934
+ if (format) control.dateFormat = format;
3935
+ const lid = getW(first2(date, "lid"), "val");
3936
+ if (lid) control.dateLocale = lid;
3937
+ }
3938
+ control.sourceXml = buildXml(sdtPr);
3939
+ const end = first2(sdt, "sdtEndPr");
3940
+ if (end) control.endSourceXml = buildXml(end);
3941
+ return control;
3942
+ }
3943
+
3944
+ // docx/expect-defined.ts
3945
+ function expectDefined(value, context) {
3946
+ if (value === void 0 || value === null) {
3947
+ throw new Error(`Internal invariant violated: ${context} is missing.`);
3948
+ }
3949
+ return value;
3950
+ }
3951
+
3952
+ // docx/parse-revisions.ts
3953
+ var REVISION_WRAPPERS = {
3954
+ ins: "insert",
3955
+ del: "delete",
3956
+ moveFrom: "moveFrom",
3957
+ moveTo: "moveTo"
3958
+ };
3959
+ var MOVE_RANGES = {
3960
+ moveFromRangeStart: { kind: "moveFrom", start: true },
3961
+ moveFromRangeEnd: { kind: "moveFrom", start: false },
3962
+ moveToRangeStart: { kind: "moveTo", start: true },
3963
+ moveToRangeEnd: { kind: "moveTo", start: false }
3964
+ };
3965
+ function trackMoveRange(item2, moves) {
3966
+ if (item2.namespaceURI && item2.namespaceURI !== WORD_NS) return false;
3967
+ const range = MOVE_RANGES[item2.localName ?? ""];
3968
+ if (!range) return false;
3969
+ const id = getW(item2, "id") ?? "";
3970
+ const open = moves[range.kind];
3971
+ if (range.start) open.push({ name: getW(item2, "name") ?? id, id });
3972
+ else {
3973
+ const index = open.findIndex((entry2) => entry2.id === id);
3974
+ if (index >= 0) open.splice(index, 1);
3975
+ }
3976
+ return true;
3977
+ }
3978
+ function isCommentReferenceRun(run2) {
3979
+ const content = Array.from(run2.childNodes).filter(
3980
+ (child7) => isElement(child7) && !named2(child7, "rPr")
3981
+ );
3982
+ return content.length > 0 && content.every((child7) => named2(child7, "commentReference"));
3983
+ }
3984
+ function revisionFrom(node, kind) {
3985
+ const revision = {
3986
+ kind,
3987
+ author: getW(node, "author") || "Unknown",
3988
+ id: getW(node, "id") ?? "0"
3989
+ };
3990
+ const date = getW(node, "date");
3991
+ if (date) revision.date = date;
3992
+ const dateUtc = node.getAttributeNS(WORD_DATE_UTC_NS, "dateUtc");
3993
+ if (dateUtc) revision.dateUtc = dateUtc;
3994
+ return revision;
3995
+ }
3996
+ function paragraphMarkRevision(pPr) {
3997
+ const rPr = first2(pPr, "rPr");
3998
+ const ins = first2(rPr, "ins");
3999
+ if (ins) return revisionFrom(ins, "insert");
4000
+ const del = first2(rPr, "del");
4001
+ if (del) return revisionFrom(del, "delete");
4002
+ return void 0;
4003
+ }
4004
+ function paragraphFormatRevision(pPr) {
4005
+ const change = first2(pPr, "pPrChange");
4006
+ if (!change) return void 0;
4007
+ const revision = revisionFrom(change, "paragraphChange");
4008
+ const previous = first2(change, "pPr");
4009
+ if (previous) revision.previousParagraphPropertiesXml = buildXml(previous);
4010
+ return revision;
4011
+ }
4012
+ function runFormatRevision(rPr) {
4013
+ const change = first2(rPr, "rPrChange");
4014
+ if (!change) return void 0;
4015
+ const revision = revisionFrom(change, "formatChange");
4016
+ const previous = first2(change, "rPr");
4017
+ if (previous) revision.previousRunPropertiesXml = buildXml(previous);
4018
+ return revision;
4019
+ }
4020
+ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active = [], moves = { moveFrom: [], moveTo: [] }) {
4021
+ const runs = [];
4022
+ let hasMove = false;
4023
+ const push = (run2) => {
4024
+ if (active.length) run2.commentIds = [.../* @__PURE__ */ new Set([...active, ...run2.commentIds ?? []])];
4025
+ runs.push(run2);
4026
+ };
4027
+ for (const item2 of Array.from(node.childNodes).filter(isElement)) {
4028
+ if (named2(item2, "r")) {
4029
+ if (!isCommentReferenceRun(item2)) push(parseRun3(item2));
4030
+ } else if (named2(item2, "hyperlink")) {
4031
+ const link = resolveLink?.(item2);
4032
+ for (const child7 of Array.from(item2.childNodes).filter(isElement)) {
4033
+ for (const parsed of named2(child7, "r") ? [parseRun3(child7)] : parseOther?.(child7) ?? []) {
4034
+ if (link) parsed.link = link;
4035
+ push(parsed);
4036
+ }
4037
+ }
4038
+ } else if ((!item2.namespaceURI || item2.namespaceURI === WORD_NS) && Object.hasOwn(REVISION_WRAPPERS, item2.localName)) {
4039
+ const kind = expectDefined(
4040
+ REVISION_WRAPPERS[item2.localName],
4041
+ `revision wrapper ${item2.localName}`
4042
+ );
4043
+ if (kind === "moveFrom" || kind === "moveTo") hasMove = true;
4044
+ const revision = revisionFrom(item2, kind);
4045
+ const range = kind === "moveFrom" || kind === "moveTo" ? moves[kind].at(-1) : void 0;
4046
+ if (range) revision.move = { name: range.name, rangeId: range.id };
4047
+ for (const child7 of Array.from(item2.childNodes).filter(isElement)) {
4048
+ for (const parsed of named2(child7, "r") ? [parseRun3(child7, revision)] : parseOther?.(child7) ?? []) {
4049
+ parsed.revision = revision;
4050
+ push(parsed);
4051
+ }
4052
+ }
4053
+ } else if (trackMoveRange(item2, moves)) {
4054
+ continue;
4055
+ } else if (named2(item2, "commentRangeStart")) {
4056
+ const id = getW(item2, "id");
4057
+ if (id !== void 0) active.push(id);
4058
+ } else if (named2(item2, "commentRangeEnd")) {
4059
+ const id = getW(item2, "id");
4060
+ const index = id === void 0 ? -1 : active.indexOf(id);
4061
+ if (index >= 0) active.splice(index, 1);
4062
+ } else {
4063
+ for (const run2 of parseOther?.(item2) ?? []) push(run2);
4064
+ }
4065
+ }
4066
+ return { runs, hasMove };
4067
+ }
4068
+
4069
+ // docx/parse-content-control.ts
4070
+ function parseInlineControl(sdt, parseRun3, parseOther, resolveLink, comments, moves) {
4071
+ const control = parseContentControl(sdt, "inline");
4072
+ const content = sdtContent(sdt);
4073
+ const runs = content ? collectParagraphRuns(content, parseRun3, parseOther, resolveLink, comments, moves).runs : [];
4074
+ if (!runs.length) return [{ text: "", contentControl: control }];
4075
+ for (const run2 of runs) run2.contentControl ??= control;
4076
+ return runs;
4077
+ }
4078
+ function flatChildren(parent, names, level3 = "block", enclosing, controls = /* @__PURE__ */ new Map()) {
4079
+ const found = [];
4080
+ for (const child7 of Array.from(parent.childNodes).filter(isElement)) {
4081
+ if (isSdt(child7)) {
4082
+ const content = sdtContent(child7);
4083
+ if (!content) continue;
4084
+ let control = controls.get(child7);
4085
+ if (!control) {
4086
+ control = parseContentControl(child7, level3);
4087
+ controls.set(child7, control);
4088
+ }
4089
+ found.push(...flatChildren(content, names, level3, { control, sdt: child7 }, controls));
4090
+ } else if (names.some((name) => named2(child7, name)))
4091
+ found.push({
4092
+ element: child7,
4093
+ ...enclosing ? { control: enclosing.control, sdt: enclosing.sdt } : {}
4094
+ });
4095
+ }
4096
+ return found;
4097
+ }
4098
+ var flatBlocks = (container) => flatChildren(container, ["p", "tbl"]);
4099
+ var flatRows = (table) => flatChildren(table, ["tr"], "row");
4100
+ var flatCells = (row) => flatChildren(row, ["tc"], "cell");
4101
+ var flatCellParagraphs = (cell2) => flatChildren(cell2, ["p"]);
4102
+
3362
4103
  // docx/content-control-values.ts
3363
4104
  var validLock = (lock) => lock === "sdtLocked" || lock === "contentLocked" || lock === "sdtContentLocked" ? lock : void 0;
3364
4105
  function validId(id) {
@@ -3584,15 +4325,15 @@ function writeDate(doc, sdtPr, control) {
3584
4325
  const fullDate = validDate(control.fullDate) ?? (control.fullDate === existing ? existing : void 0);
3585
4326
  if (fullDate) date.setAttributeNS(WORD_NS, "w:fullDate", fullDate);
3586
4327
  else date.removeAttributeNS(WORD_NS, "fullDate");
3587
- const set = (local, value, order) => {
4328
+ const set2 = (local, value, order) => {
3588
4329
  for (const old of children2(date, local)) date.removeChild(old);
3589
4330
  if (typeof value !== "string") return;
3590
4331
  const element4 = makeW(doc, local);
3591
4332
  element4.setAttributeNS(WORD_NS, "w:val", value);
3592
4333
  date.insertBefore(element4, Array.from(date.childNodes)[order] ?? null);
3593
4334
  };
3594
- set("dateFormat", control.dateFormat, 0);
3595
- set("lid", control.dateLocale, 1);
4335
+ set2("dateFormat", control.dateFormat, 0);
4336
+ set2("lid", control.dateLocale, 1);
3596
4337
  }
3597
4338
  var writesType = (kind) => NAMED_TYPES.has(kind) || ["richText", "text", "checkbox", "dropDownList", "comboBox", "date"].includes(kind);
3598
4339
  function patchContentControl(doc, sdt, control) {
@@ -3770,13 +4511,13 @@ function rangeKeys(run2) {
3770
4511
  keys.push(`${revision.kind}:${revision.move.name}`);
3771
4512
  return keys;
3772
4513
  }
3773
- function paragraphsOf(blocks) {
4514
+ function paragraphsOf2(blocks) {
3774
4515
  return blocks.flatMap(
3775
4516
  (block) => block.type === "paragraph" ? [block] : block.rows.flatMap((row) => row.flatMap((cell2) => cell2.paragraphs))
3776
4517
  );
3777
4518
  }
3778
4519
  function commentContinuations(blocks) {
3779
- const paragraphs = paragraphsOf(blocks);
4520
+ const paragraphs = paragraphsOf2(blocks);
3780
4521
  const first3 = /* @__PURE__ */ new Map();
3781
4522
  const last = /* @__PURE__ */ new Map();
3782
4523
  const idsByParagraph = paragraphs.map((paragraph2, index) => {
@@ -3841,7 +4582,7 @@ var COMMENTS_PATH = "word/comments.xml";
3841
4582
  var COMMENTS_EXTENDED_PATH = "word/commentsExtended.xml";
3842
4583
  var W14_NS = "http://schemas.microsoft.com/office/word/2010/wordml";
3843
4584
  var W15_NS = "http://schemas.microsoft.com/office/word/2012/wordml";
3844
- function setAttribute(element4, local, value) {
4585
+ function setAttribute2(element4, local, value) {
3845
4586
  element4.setAttributeNS(WORD_NS, `w:${local}`, value);
3846
4587
  }
3847
4588
  function paraIdFor(id, index) {
@@ -3856,10 +4597,10 @@ function buildCommentsDocument(comments) {
3856
4597
  const root = doc.documentElement;
3857
4598
  comments.forEach((comment, index) => {
3858
4599
  const el5 = makeW(doc, "comment");
3859
- setAttribute(el5, "id", comment.id);
3860
- setAttribute(el5, "author", comment.author);
3861
- if (comment.date) setAttribute(el5, "date", comment.date);
3862
- if (comment.initials) setAttribute(el5, "initials", comment.initials);
4600
+ setAttribute2(el5, "id", comment.id);
4601
+ setAttribute2(el5, "author", comment.author);
4602
+ if (comment.date) setAttribute2(el5, "date", comment.date);
4603
+ if (comment.initials) setAttribute2(el5, "initials", comment.initials);
3863
4604
  const p = makeW(doc, "p");
3864
4605
  p.setAttributeNS(W14_NS, "w14:paraId", paraIdFor(comment.id, index));
3865
4606
  const r = makeW(doc, "r");
@@ -3923,15 +4664,15 @@ async function applyComments(zip, comments) {
3923
4664
  }
3924
4665
  function commentRangeStartNode(doc, id) {
3925
4666
  const element4 = makeW(doc, "commentRangeStart");
3926
- setAttribute(element4, "id", id);
4667
+ setAttribute2(element4, "id", id);
3927
4668
  return element4;
3928
4669
  }
3929
4670
  function commentRangeEndNodes(doc, id) {
3930
4671
  const end = makeW(doc, "commentRangeEnd");
3931
- setAttribute(end, "id", id);
4672
+ setAttribute2(end, "id", id);
3932
4673
  const run2 = makeW(doc, "r");
3933
4674
  const reference = makeW(doc, "commentReference");
3934
- setAttribute(reference, "id", id);
4675
+ setAttribute2(reference, "id", id);
3935
4676
  run2.appendChild(reference);
3936
4677
  return [end, run2];
3937
4678
  }
@@ -4177,10 +4918,10 @@ function buildRowProperties(doc, row, gridAfter) {
4177
4918
  }
4178
4919
 
4179
4920
  // docx/write-table-margins.ts
4180
- var SIDES3 = ["top", "left", "bottom", "right"];
4921
+ var SIDES4 = ["top", "left", "bottom", "right"];
4181
4922
  var ORDER2 = ["top", "start", "left", "bottom", "end", "right"];
4182
4923
  function patchMarginProperties(doc, host, propertiesTag, marginTag, propertiesOrder, next, base) {
4183
- const changed = SIDES3.filter((side) => next?.[side] !== base?.[side]);
4924
+ const changed = SIDES4.filter((side) => next?.[side] !== base?.[side]);
4184
4925
  if (!changed.length) return;
4185
4926
  for (const side of changed) {
4186
4927
  const value = next?.[side];
@@ -4500,14 +5241,21 @@ function unwrapDroppedControls(elements2, next) {
4500
5241
  });
4501
5242
  }
4502
5243
 
4503
- // docx/write-table.ts
5244
+ // docx/table-structure-check.ts
5245
+ var only = (parent, allowed) => Array.from(parent.childNodes).filter(isElement).every((node) => allowed.some((name) => named2(node, name)));
5246
+ function plainParagraphs(cell2) {
5247
+ for (const paragraph2 of children2(cell2, "p")) {
5248
+ if (!only(paragraph2, ["pPr", "r"])) return false;
5249
+ for (const run2 of children2(paragraph2, "r"))
5250
+ if (!only(run2, ["rPr", "t", "tab", "br", "cr", "noBreakHyphen"])) return false;
5251
+ }
5252
+ return true;
5253
+ }
4504
5254
  function canEditTableStructure(table) {
4505
- const only = (parent, allowed) => Array.from(parent.childNodes).filter(isElement).every((node) => allowed.some((name) => named2(node, name)));
4506
5255
  if (!only(table, ["tblPr", "tblGrid", "tr"])) return false;
4507
5256
  const grid = first2(table, "tblGrid");
4508
5257
  if (grid && !only(grid, ["gridCol"])) return false;
4509
5258
  const rows = children2(table, "tr");
4510
- if (!rows.length) return false;
4511
5259
  const [firstRow] = rows;
4512
5260
  if (!firstRow) return false;
4513
5261
  const width = children2(firstRow, "tc").length;
@@ -4523,15 +5271,206 @@ function canEditTableStructure(table) {
4523
5271
  const props = first2(cell2, "tcPr");
4524
5272
  if (props && ["gridSpan", "vMerge", "hMerge", "tcPrChange"].some((key) => first2(props, key)))
4525
5273
  return false;
4526
- for (const paragraph2 of children2(cell2, "p")) {
4527
- if (!only(paragraph2, ["pPr", "r"])) return false;
4528
- for (const run2 of children2(paragraph2, "r"))
4529
- if (!only(run2, ["rPr", "t", "tab", "br", "cr", "noBreakHyphen"])) return false;
4530
- }
5274
+ if (!plainParagraphs(cell2)) return false;
5275
+ }
5276
+ }
5277
+ return true;
5278
+ }
5279
+ function canRestructureTable(table) {
5280
+ if (!only(table, ["tblPr", "tblGrid", "tr"])) return false;
5281
+ const grid = first2(table, "tblGrid");
5282
+ if (!grid || !only(grid, ["gridCol"])) return false;
5283
+ const rows = children2(table, "tr");
5284
+ if (!rows.length) return false;
5285
+ for (const row of rows) {
5286
+ if (!only(row, ["trPr", "tc"]) || !children2(row, "tc").length) return false;
5287
+ const rowProps = first2(row, "trPr");
5288
+ if (rowProps && ["gridBefore", "gridAfter", "wBefore", "wAfter", "trPrChange", "ins", "del"].some(
5289
+ (key) => first2(rowProps, key)
5290
+ ))
5291
+ return false;
5292
+ for (const cell2 of children2(row, "tc")) {
5293
+ if (!only(cell2, ["tcPr", "p", "tbl"]) || !children2(cell2, "p").length) return false;
5294
+ const props = first2(cell2, "tcPr");
5295
+ if (props && ["hMerge", "tcPrChange", "cellIns", "cellDel", "cellMerge"].some((key) => first2(props, key)))
5296
+ return false;
5297
+ if (!plainParagraphs(cell2)) return false;
4531
5298
  }
4532
5299
  }
4533
5300
  return true;
4534
5301
  }
5302
+
5303
+ // docx/write-table-structure.ts
5304
+ var set = (element4, name, value) => element4.setAttributeNS(WORD_NS, `w:${name}`, value);
5305
+ function restructured(next, base) {
5306
+ const shape = (table) => JSON.stringify([
5307
+ table.grid,
5308
+ table.rows.map(
5309
+ (row) => row.map((cell2) => [
5310
+ cell2.paragraphs.map((p) => p.id),
5311
+ cell2.gridSpan ?? 1,
5312
+ cell2.verticalMerge ?? "",
5313
+ cell2.widthTwips
5314
+ ])
5315
+ )
5316
+ ]);
5317
+ return shape(next) !== shape(base);
5318
+ }
5319
+ function patchCellLayout(doc, tc, cell2, base) {
5320
+ const span = cell2.gridSpan ?? 1;
5321
+ const width = cell2.widthTwips;
5322
+ if (span === (base.gridSpan ?? 1) && width === base.widthTwips && cell2.verticalMerge === base.verticalMerge)
5323
+ return;
5324
+ let props = first2(tc, "tcPr");
5325
+ if (!props) {
5326
+ props = makeW(doc, "tcPr");
5327
+ tc.insertBefore(props, tc.firstChild);
5328
+ }
5329
+ const replace = (name, next) => {
5330
+ for (const old of children2(props, name)) props.removeChild(old);
5331
+ if (next) props.appendChild(next);
5332
+ };
5333
+ if (width !== base.widthTwips) {
5334
+ const old = first2(props, "tcW");
5335
+ if (width === void 0) replace("tcW", void 0);
5336
+ else {
5337
+ const element4 = old ?? makeW(doc, "tcW");
5338
+ set(element4, "w", String(width));
5339
+ set(element4, "type", "dxa");
5340
+ if (!old) props.appendChild(element4);
5341
+ }
5342
+ }
5343
+ if (span !== (base.gridSpan ?? 1)) {
5344
+ const element4 = span > 1 ? makeW(doc, "gridSpan") : void 0;
5345
+ if (element4) set(element4, "val", String(span));
5346
+ replace("gridSpan", element4);
5347
+ }
5348
+ if (cell2.verticalMerge !== base.verticalMerge) {
5349
+ const element4 = cell2.verticalMerge ? makeW(doc, "vMerge") : void 0;
5350
+ if (element4 && cell2.verticalMerge === "restart") set(element4, "val", "restart");
5351
+ replace("vMerge", element4);
5352
+ }
5353
+ orderChildren(props, CELL_ORDER);
5354
+ if (!Array.from(props.childNodes).some((node) => node.nodeType === 1) && !props.attributes.length)
5355
+ tc.removeChild(props);
5356
+ }
5357
+ function patchGrid(doc, node, table) {
5358
+ const grid = first2(node, "tblGrid");
5359
+ if (!grid || !table.grid) return;
5360
+ const old = children2(grid, "gridCol");
5361
+ table.grid.forEach((width, index) => {
5362
+ let column = old[index];
5363
+ if (!column) {
5364
+ column = makeW(doc, "gridCol");
5365
+ grid.appendChild(column);
5366
+ }
5367
+ if (column.getAttributeNS(WORD_NS, "w") !== String(width)) set(column, "w", String(width));
5368
+ });
5369
+ for (const extra of old.slice(table.grid.length)) grid.removeChild(extra);
5370
+ }
5371
+ function writeRestructuredTable(doc, table, node, base, writeParagraph, replaceSlots2, writeNested) {
5372
+ if (table.rows.some((row) => !row.length || row.some((cell2) => !cell2.paragraphs.length)))
5373
+ throw new Error("Every table row needs a cell and every cell a paragraph.");
5374
+ const oldRows = flatRows(node).map((entry2) => entry2.element);
5375
+ const oldCells = oldRows.map((tr) => flatCells(tr).map((entry2) => entry2.element));
5376
+ const cellById = /* @__PURE__ */ new Map();
5377
+ const paragraphById = /* @__PURE__ */ new Map();
5378
+ base.rows.forEach(
5379
+ (row, ri) => row.forEach((cell2, ci) => {
5380
+ const tc = oldCells[ri]?.[ci];
5381
+ if (!tc) return;
5382
+ const id = cell2.paragraphs[0]?.id;
5383
+ if (id) cellById.set(id, { tc, model: cell2, row: ri });
5384
+ const flat = flatCellParagraphs(tc);
5385
+ cell2.paragraphs.forEach((model, pi) => {
5386
+ const entry2 = flat[pi];
5387
+ if (entry2) paragraphById.set(model.id, { element: entry2.element, model });
5388
+ });
5389
+ })
5390
+ );
5391
+ const usedRows = /* @__PURE__ */ new Set();
5392
+ const usedCells = /* @__PURE__ */ new Set();
5393
+ const nextRows = table.rows.map((row, rowIndex) => {
5394
+ const sourceRow = row.map((cell2) => cellById.get(cell2.paragraphs[0]?.id ?? "")?.row).find((index) => index !== void 0 && !usedRows.has(index));
5395
+ if (sourceRow !== void 0) usedRows.add(sourceRow);
5396
+ const tr = sourceRow === void 0 ? makeW(doc, "tr") : oldRows[sourceRow] ?? makeW(doc, "tr");
5397
+ patchRowProperties(
5398
+ doc,
5399
+ tr,
5400
+ table.rowProperties?.[rowIndex],
5401
+ sourceRow === void 0 ? void 0 : base.rowProperties?.[sourceRow]
5402
+ );
5403
+ const nextCells = row.map((cell2) => {
5404
+ const source2 = cellById.get(cell2.paragraphs[0]?.id ?? "");
5405
+ const reuse = source2 && source2.row === sourceRow && !usedCells.has(source2.tc) ? source2 : void 0;
5406
+ const tc = reuse?.tc ?? makeW(doc, "tc");
5407
+ if (reuse) {
5408
+ usedCells.add(reuse.tc);
5409
+ patchCellLayout(doc, tc, cell2, reuse.model);
5410
+ patchCellBorders(doc, tc, cell2.borders, reuse.model.borders);
5411
+ patchCellShading(doc, tc, cell2, reuse.model);
5412
+ patchCellMargins(doc, tc, cell2.margins, reuse.model.margins);
5413
+ patchCellVerticalAlignment(doc, tc, cell2.verticalAlign, reuse.model.verticalAlign);
5414
+ } else {
5415
+ const props = buildCellProperties(doc, cell2);
5416
+ if (props) tc.insertBefore(props, tc.firstChild);
5417
+ }
5418
+ const oldParagraphs = reuse ? flatCellParagraphs(tc).map((entry2) => entry2.element) : [];
5419
+ const owned = new Set(oldParagraphs);
5420
+ const nextParagraphs = cell2.paragraphs.map((paragraph2) => {
5421
+ const found = paragraphById.get(paragraph2.id);
5422
+ const element4 = found ? owned.has(found.element) ? found.element : found.element.cloneNode(true) : makeW(doc, "p");
5423
+ return writeParagraph(doc, paragraph2, element4, found?.model);
5424
+ });
5425
+ replaceSlots2(doc, tc, oldParagraphs, nextParagraphs);
5426
+ if (reuse) writeNested(doc, tc, cell2, reuse.model);
5427
+ return tc;
5428
+ });
5429
+ replaceSlots2(doc, tr, sourceRow === void 0 ? [] : oldCells[sourceRow] ?? [], nextCells);
5430
+ return tr;
5431
+ });
5432
+ replaceSlots2(doc, node, oldRows, nextRows);
5433
+ patchTableMargins(doc, table, node, base);
5434
+ patchGrid(doc, node, table);
5435
+ return node;
5436
+ }
5437
+
5438
+ // docx/table-grid.ts
5439
+ var spanOf = (cell2) => Math.max(1, cell2.gridSpan ?? 1);
5440
+ function tableGrid(table) {
5441
+ const columns = table.grid?.length ?? sumSpans(table.rows[0]);
5442
+ if (!columns || !table.rows.length) return void 0;
5443
+ const rows = [];
5444
+ const cover = [];
5445
+ for (let row = 0; row < table.rows.length; row++) {
5446
+ const cells = table.rows[row] ?? [];
5447
+ if (!cells.length || sumSpans(cells) !== columns) return void 0;
5448
+ const placed = [];
5449
+ const line2 = new Array(columns);
5450
+ let col = 0;
5451
+ cells.forEach((cell2, index) => {
5452
+ const entry2 = { cell: cell2, row, index, col, span: spanOf(cell2) };
5453
+ for (let k = 0; k < entry2.span; k++) line2[col + k] = entry2;
5454
+ col += entry2.span;
5455
+ placed.push(entry2);
5456
+ });
5457
+ rows.push(placed);
5458
+ cover.push(line2);
5459
+ }
5460
+ const grid = { columns, rows, cover };
5461
+ for (const entry2 of rows.flat())
5462
+ if (entry2.cell.verticalMerge === "continue") {
5463
+ const above = entry2.row > 0 ? cover[entry2.row - 1]?.[entry2.col] : void 0;
5464
+ if (!above || above.col !== entry2.col || above.span !== entry2.span) return void 0;
5465
+ if (!above.cell.verticalMerge) return void 0;
5466
+ }
5467
+ return grid;
5468
+ }
5469
+ function sumSpans(cells) {
5470
+ return (cells ?? []).reduce((sum, cell2) => sum + spanOf(cell2), 0);
5471
+ }
5472
+
5473
+ // docx/write-table.ts
4535
5474
  var layout = (table) => table.rows.map((row) => row.map((cell2) => cell2.paragraphs.map((p) => p.id)));
4536
5475
  var TABLE_DESCRIPTOR_KEYS = [
4537
5476
  "grid",
@@ -4549,13 +5488,15 @@ function pick(source2, keys) {
4549
5488
  for (const key of keys) if (record[key] !== void 0) result[key] = record[key];
4550
5489
  return result;
4551
5490
  }
4552
- function assertNoDescriptorEdits(table, base) {
5491
+ function assertNoDescriptorEdits(table, base, layoutEdits = false) {
4553
5492
  if (!base) return;
4554
- if (JSON.stringify(pick(table, TABLE_DESCRIPTOR_KEYS)) !== JSON.stringify(pick(base, TABLE_DESCRIPTOR_KEYS)))
5493
+ const tableKeys = layoutEdits ? TABLE_DESCRIPTOR_KEYS.filter((key) => key !== "grid") : TABLE_DESCRIPTOR_KEYS;
5494
+ if (JSON.stringify(pick(table, tableKeys)) !== JSON.stringify(pick(base, tableKeys)))
4555
5495
  throw new Error(
4556
5496
  "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."
4557
5497
  );
4558
5498
  const baseCellById = /* @__PURE__ */ new Map();
5499
+ if (layoutEdits) return;
4559
5500
  for (const row of base.rows)
4560
5501
  for (const cell2 of row) {
4561
5502
  const id = cell2.paragraphs[0]?.id;
@@ -4580,11 +5521,24 @@ function writeNestedTables(doc, tc, cell2, base, writeParagraph, replaceSlots2)
4580
5521
  next.forEach((table, index) => {
4581
5522
  const node = nodes[index];
4582
5523
  if (node && before[index])
4583
- writeTable(doc, table, node, before[index], writeParagraph, replaceSlots2);
5524
+ writeTable(doc, table, node, before[index], writeParagraph, replaceSlots2, true);
4584
5525
  });
4585
5526
  }
4586
- function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
5527
+ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2, nested = false) {
4587
5528
  if (base && JSON.stringify(table) === JSON.stringify(base)) return node;
5529
+ const baseGrid = base && tableGrid(base);
5530
+ if (base && baseGrid && (nested || !base.structureEditable || table.structureEditable === false) && restructured(table, base) && canRestructureTable(node)) {
5531
+ assertNoDescriptorEdits(table, base, true);
5532
+ return writeRestructuredTable(
5533
+ doc,
5534
+ table,
5535
+ node,
5536
+ base,
5537
+ writeParagraph,
5538
+ replaceSlots2,
5539
+ (d, tc, cell2, before) => writeNestedTables(d, tc, cell2, before, writeParagraph, replaceSlots2)
5540
+ );
5541
+ }
4588
5542
  assertNoDescriptorEdits(table, base);
4589
5543
  patchTableMargins(doc, table, node, base);
4590
5544
  const structural = base && JSON.stringify(layout(table)) !== JSON.stringify(layout(base));
@@ -4710,13 +5664,13 @@ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
4710
5664
 
4711
5665
  // docx/write-footnote-columns.ts
4712
5666
  var W15 = "http://schemas.microsoft.com/office/word/2012/wordml";
4713
- var XMLNS3 = "http://www.w3.org/2000/xmlns/";
5667
+ var XMLNS4 = "http://www.w3.org/2000/xmlns/";
4714
5668
  var MC2 = "http://schemas.openxmlformats.org/markup-compatibility/2006";
4715
5669
  function prefix(doc, preferred, namespace) {
4716
5670
  let name = preferred;
4717
5671
  for (let suffix = 1; doc.documentElement.lookupNamespaceURI(name) && doc.documentElement.lookupNamespaceURI(name) !== namespace; suffix++)
4718
5672
  name = preferred + suffix;
4719
- doc.documentElement.setAttributeNS(XMLNS3, "xmlns:" + name, namespace);
5673
+ doc.documentElement.setAttributeNS(XMLNS4, "xmlns:" + name, namespace);
4720
5674
  return name;
4721
5675
  }
4722
5676
  function writeFootnoteColumns(doc, section, value) {
@@ -4739,13 +5693,13 @@ function writeFootnoteColumns(doc, section, value) {
4739
5693
  }
4740
5694
 
4741
5695
  // docx/page-borders.ts
4742
- var SIDES4 = ["top", "left", "bottom", "right"];
5696
+ var SIDES5 = ["top", "left", "bottom", "right"];
4743
5697
  var ATTRIBUTES = ["offsetFrom", "display", "zOrder"];
4744
5698
  var setW4 = (element4, name, value) => element4.setAttributeNS(WORD_NS, `w:${name}`, value);
4745
5699
  function parsePageBorders(element4) {
4746
5700
  if (!element4) return void 0;
4747
5701
  const result = {};
4748
- for (const side of SIDES4) {
5702
+ for (const side of SIDES5) {
4749
5703
  const source2 = first2(element4, side);
4750
5704
  const value = borderSide(source2);
4751
5705
  const art = getW(source2, "art");
@@ -4783,7 +5737,7 @@ function patchPageBorders(doc, sectPr, next, base, create2) {
4783
5737
  return;
4784
5738
  }
4785
5739
  const element4 = create2(doc, sectPr, "pgBorders");
4786
- for (const side of SIDES4) {
5740
+ for (const side of SIDES5) {
4787
5741
  if (JSON.stringify(next[side]) === JSON.stringify(base?.[side])) continue;
4788
5742
  for (const old of children2(element4, side)) element4.removeChild(old);
4789
5743
  const value = next[side];
@@ -4964,75 +5918,6 @@ function writePageNumbering(doc, sectPr, section) {
4964
5918
  }
4965
5919
  }
4966
5920
 
4967
- // docx/tab-stops.ts
4968
- function parseTabStops(tabs) {
4969
- const stops = [];
4970
- for (const tab of tabs ? children2(tabs, "tab") : []) {
4971
- const align = enumValue(isStTabJc, getW(tab, "val"), "w:tab/@w:val");
4972
- const pos = parseSignedTwips(getW(tab, "pos"));
4973
- if (!align || pos === void 0) continue;
4974
- const leader = enumValue(isStTabTlc, getW(tab, "leader"), "w:tab/@w:leader");
4975
- stops.push({ posTwips: pos, align, ...leader ? { leader } : {} });
4976
- }
4977
- return stops;
4978
- }
4979
- function writeTabStops(doc, props, paragraph2, base) {
4980
- if (base && JSON.stringify(paragraph2.tabStops ?? []) === JSON.stringify(base.tabStops ?? []))
4981
- return;
4982
- for (const tabs2 of children2(props, "tabs")) props.removeChild(tabs2);
4983
- if (!paragraph2.tabStops?.length) return;
4984
- const tabs = makeW(doc, "tabs");
4985
- for (const stop of paragraph2.tabStops) {
4986
- const tab = makeW(doc, "tab");
4987
- tab.setAttributeNS(WORD_NS, "w:val", stop.align);
4988
- if (stop.leader) tab.setAttributeNS(WORD_NS, "w:leader", stop.leader);
4989
- tab.setAttributeNS(WORD_NS, "w:pos", String(stop.posTwips));
4990
- tabs.appendChild(tab);
4991
- }
4992
- props.appendChild(tabs);
4993
- }
4994
- var PPR_ORDER = [
4995
- "pStyle",
4996
- "keepNext",
4997
- "keepLines",
4998
- "pageBreakBefore",
4999
- "framePr",
5000
- "widowControl",
5001
- "numPr",
5002
- "suppressLineNumbers",
5003
- "pBdr",
5004
- "shd",
5005
- "tabs",
5006
- "suppressAutoHyphens",
5007
- "kinsoku",
5008
- "wordWrap",
5009
- "overflowPunct",
5010
- "topLinePunct",
5011
- "autoSpaceDE",
5012
- "autoSpaceDN",
5013
- "bidi",
5014
- "adjustRightInd",
5015
- "snapToGrid",
5016
- "spacing",
5017
- "ind",
5018
- "contextualSpacing",
5019
- "mirrorIndents",
5020
- "suppressOverlap",
5021
- "jc",
5022
- "textDirection",
5023
- "textAlignment",
5024
- "textboxTightWrap",
5025
- "outlineLvl",
5026
- "divId",
5027
- "cnfStyle",
5028
- "rPr",
5029
- "sectPr",
5030
- "pPrChange"
5031
- ];
5032
- function orderParagraphProperties(props) {
5033
- orderChildren(props, PPR_ORDER);
5034
- }
5035
-
5036
5921
  // docx/write-sections.ts
5037
5922
  var WRITABLE = /* @__PURE__ */ new Set([
5038
5923
  "endsAtBlockId",
@@ -5637,16 +6522,16 @@ function isWordElement(element4, names) {
5637
6522
  }
5638
6523
  var isRevisionWrapperElement = (element4) => isWordElement(element4, REVISION_WRAPPER_NAMES2);
5639
6524
  var isCommentAnchorElement = (element4) => isWordElement(element4, COMMENT_ANCHOR_NAMES);
5640
- function setAttribute2(element4, local, value) {
6525
+ function setAttribute3(element4, local, value) {
5641
6526
  element4.setAttributeNS(WORD_NS, `w:${local}`, value);
5642
6527
  }
5643
6528
  function removeChildren(element4, local) {
5644
6529
  for (const child7 of children2(element4, local)) element4.removeChild(child7);
5645
6530
  }
5646
6531
  function writeRevisionMetadata(element4, revision) {
5647
- setAttribute2(element4, "id", revision.id);
5648
- setAttribute2(element4, "author", revision.author);
5649
- if (revision.date) setAttribute2(element4, "date", revision.date);
6532
+ setAttribute3(element4, "id", revision.id);
6533
+ setAttribute3(element4, "author", revision.author);
6534
+ if (revision.date) setAttribute3(element4, "date", revision.date);
5650
6535
  else element4.removeAttributeNS(WORD_NS, "date");
5651
6536
  if (revision.dateUtc) element4.setAttributeNS(WORD_DATE_UTC_NS, "w16du:dateUtc", revision.dateUtc);
5652
6537
  else element4.removeAttributeNS(WORD_DATE_UTC_NS, "dateUtc");
@@ -5781,184 +6666,6 @@ function restoreAnnotations(markers, before, after) {
5781
6666
  }
5782
6667
  }
5783
6668
 
5784
- // docx/write-paragraph-decoration.ts
5785
- var SIDES5 = ["top", "left", "bottom", "right", "between"];
5786
- function wordColor(color) {
5787
- const hex = /^#?([0-9a-f]{6})$/i.exec(color ?? "")?.[1];
5788
- return hex ? hex.toUpperCase() : "auto";
5789
- }
5790
- function borderElement(doc, name, side) {
5791
- const element4 = makeW(doc, name);
5792
- const set = (local, value) => element4.setAttributeNS(WORD_NS, `w:${local}`, value);
5793
- set("val", side.style ?? "single");
5794
- if (side.style !== "none" && side.style !== "nil") {
5795
- set("sz", String(side.sizeEighthPoints ?? 4));
5796
- set("space", String(side.spacePoints ?? 1));
5797
- set("color", wordColor(side.color));
5798
- if (side.themeColor) set("themeColor", side.themeColor);
5799
- }
5800
- return element4;
5801
- }
5802
- var sameJson = (a2, b) => JSON.stringify(a2 ?? null) === JSON.stringify(b ?? null);
5803
- function updateShading(doc, props, paragraph2, base) {
5804
- if (base && paragraph2.shadingFill === base.shadingFill) return;
5805
- for (const element4 of children2(props, "shd")) props.removeChild(element4);
5806
- if (!paragraph2.shadingFill) return;
5807
- const shd = makeW(doc, "shd");
5808
- shd.setAttributeNS(WORD_NS, "w:val", "clear");
5809
- shd.setAttributeNS(WORD_NS, "w:color", "auto");
5810
- shd.setAttributeNS(WORD_NS, "w:fill", wordColor(paragraph2.shadingFill));
5811
- props.appendChild(shd);
5812
- }
5813
- function updateBorders(doc, props, paragraph2, base) {
5814
- if (base && sameJson(paragraph2.borders, base.borders)) return;
5815
- for (const element4 of children2(props, "pBdr")) props.removeChild(element4);
5816
- const borders = paragraph2.borders;
5817
- if (!borders) return;
5818
- const pBdr = makeW(doc, "pBdr");
5819
- for (const side of SIDES5) {
5820
- const value = borders[side];
5821
- if (value) pBdr.appendChild(borderElement(doc, side, value));
5822
- }
5823
- if (pBdr.childNodes.length) props.appendChild(pBdr);
5824
- }
5825
- function writeParagraphDecoration(doc, props, paragraph2, base) {
5826
- updateShading(doc, props, paragraph2, base);
5827
- updateBorders(doc, props, paragraph2, base);
5828
- }
5829
-
5830
- // docx/write-paragraph-properties.ts
5831
- function setAttribute3(element4, local, value) {
5832
- element4.setAttributeNS(WORD_NS, `w:${local}`, value);
5833
- }
5834
- function setWordValue(element4, local, value) {
5835
- if (value === void 0) element4.removeAttributeNS(WORD_NS, local);
5836
- else setAttribute3(element4, local, String(value));
5837
- }
5838
- function updateDirection(doc, props, paragraph2, base) {
5839
- if (base && paragraph2.direction === base.direction) return;
5840
- let bidi = first2(props, "bidi");
5841
- if (paragraph2.direction === void 0) {
5842
- for (const element4 of children2(props, "bidi")) props.removeChild(element4);
5843
- } else {
5844
- if (!bidi) {
5845
- bidi = makeW(doc, "bidi");
5846
- props.appendChild(bidi);
5847
- }
5848
- setAttribute3(bidi, "val", paragraph2.direction === "rtl" ? "1" : "0");
5849
- }
5850
- }
5851
- function updateSpacing(doc, props, paragraph2, base) {
5852
- let spacing2 = first2(props, "spacing");
5853
- if (!spacing2) {
5854
- spacing2 = makeW(doc, "spacing");
5855
- props.appendChild(spacing2);
5856
- }
5857
- if (!base || paragraph2.spacingBeforeTwips !== base.spacingBeforeTwips)
5858
- setWordValue(spacing2, "before", paragraph2.spacingBeforeTwips);
5859
- if (!base || paragraph2.spacingAfterTwips !== base.spacingAfterTwips)
5860
- setWordValue(spacing2, "after", paragraph2.spacingAfterTwips);
5861
- if (!base || paragraph2.lineSpacingTwips !== base.lineSpacingTwips || paragraph2.lineSpacingRule !== base.lineSpacingRule) {
5862
- setWordValue(spacing2, "line", paragraph2.lineSpacingTwips);
5863
- setWordValue(
5864
- spacing2,
5865
- "lineRule",
5866
- paragraph2.lineSpacingRule ?? (paragraph2.lineSpacingTwips === void 0 ? void 0 : "auto")
5867
- );
5868
- }
5869
- if (!spacing2.attributes.length && !spacing2.childNodes.length) props.removeChild(spacing2);
5870
- }
5871
- function updateIndent(doc, props, paragraph2, base) {
5872
- let indent = first2(props, "ind");
5873
- if (!indent) {
5874
- indent = makeW(doc, "ind");
5875
- props.appendChild(indent);
5876
- }
5877
- if (!base || paragraph2.indentLeftTwips !== base.indentLeftTwips)
5878
- setWordValue(indent, "left", paragraph2.indentLeftTwips);
5879
- if (!base || paragraph2.indentRightTwips !== base.indentRightTwips)
5880
- setWordValue(indent, "right", paragraph2.indentRightTwips);
5881
- if (!base || paragraph2.indentStartTwips !== base.indentStartTwips)
5882
- setWordValue(indent, "start", paragraph2.indentStartTwips);
5883
- if (!base || paragraph2.indentEndTwips !== base.indentEndTwips)
5884
- setWordValue(indent, "end", paragraph2.indentEndTwips);
5885
- if (!base || paragraph2.firstLineTwips !== base.firstLineTwips)
5886
- setWordValue(indent, "firstLine", paragraph2.firstLineTwips);
5887
- if (!base || paragraph2.hangingTwips !== base.hangingTwips)
5888
- setWordValue(indent, "hanging", paragraph2.hangingTwips);
5889
- if (!indent.attributes.length) props.removeChild(indent);
5890
- }
5891
- function updatePageBreakBefore(doc, props, paragraph2, base) {
5892
- if (base && paragraph2.pageBreakBefore === base.pageBreakBefore) return;
5893
- for (const element4 of children2(props, "pageBreakBefore")) props.removeChild(element4);
5894
- if (paragraph2.pageBreakBefore !== void 0) {
5895
- const element4 = makeW(doc, "pageBreakBefore");
5896
- if (!paragraph2.pageBreakBefore) element4.setAttributeNS(WORD_NS, "w:val", "0");
5897
- props.appendChild(element4);
5898
- }
5899
- }
5900
- function updateKeepOptions(doc, props, paragraph2, base) {
5901
- for (const key of [
5902
- "keepNext",
5903
- "keepLines",
5904
- "widowControl",
5905
- "contextualSpacing",
5906
- "suppressLineNumbers"
5907
- ]) {
5908
- if (base && paragraph2[key] === base[key]) continue;
5909
- for (const element5 of children2(props, key)) props.removeChild(element5);
5910
- const value = paragraph2[key];
5911
- if (value === void 0) continue;
5912
- const element4 = makeW(doc, key);
5913
- if (!value) setAttribute3(element4, "val", "0");
5914
- props.appendChild(element4);
5915
- }
5916
- }
5917
- function updateDropCap(doc, props, paragraph2, base) {
5918
- if (base && JSON.stringify(paragraph2.dropCap) === JSON.stringify(base.dropCap)) return;
5919
- let frame2 = first2(props, "framePr");
5920
- const cap = paragraph2.dropCap;
5921
- if (!cap) {
5922
- if (frame2) props.removeChild(frame2);
5923
- return;
5924
- }
5925
- if (!frame2) {
5926
- frame2 = makeW(doc, "framePr");
5927
- props.appendChild(frame2);
5928
- setAttribute3(frame2, "wrap", "around");
5929
- setAttribute3(frame2, "vAnchor", "text");
5930
- setAttribute3(frame2, "hAnchor", "text");
5931
- }
5932
- setAttribute3(frame2, "dropCap", cap.style);
5933
- setAttribute3(frame2, "lines", String(cap.lines));
5934
- setWordValue(frame2, "hSpace", cap.distanceTwips);
5935
- }
5936
- function writeParagraphProperties(doc, props, paragraph2, base) {
5937
- updatePageBreakBefore(doc, props, paragraph2, base);
5938
- updateKeepOptions(doc, props, paragraph2, base);
5939
- updateDropCap(doc, props, paragraph2, base);
5940
- updateDirection(doc, props, paragraph2, base);
5941
- writeParagraphDecoration(doc, props, paragraph2, base);
5942
- const spacingKeys = [
5943
- "spacingBeforeTwips",
5944
- "spacingAfterTwips",
5945
- "lineSpacingTwips",
5946
- "lineSpacingRule"
5947
- ];
5948
- if (!base || spacingKeys.some((key) => paragraph2[key] !== base[key]))
5949
- updateSpacing(doc, props, paragraph2, base);
5950
- const indentKeys = [
5951
- "indentLeftTwips",
5952
- "indentRightTwips",
5953
- "indentStartTwips",
5954
- "indentEndTwips",
5955
- "firstLineTwips",
5956
- "hangingTwips"
5957
- ];
5958
- if (!base || indentKeys.some((key) => paragraph2[key] !== base[key]))
5959
- updateIndent(doc, props, paragraph2, base);
5960
- }
5961
-
5962
6669
  // docx/bookmarks.ts
5963
6670
  function paragraphBookmarkNames(node) {
5964
6671
  return children2(node, "bookmarkStart").map((el5) => getW(el5, "name")).filter((name) => Boolean(name));
@@ -8039,10 +8746,10 @@ function writeDrawingRichTextBody(container, body) {
8039
8746
  const paragraphs = body.paragraphs.length ? body.paragraphs : [{ items: [] }];
8040
8747
  for (const paragraph2 of paragraphs) container.appendChild(writeDrawingParagraph(doc, paragraph2));
8041
8748
  }
8042
- function drawingRichTextBodyXml(body, qualifiedName = "a:txBody", namespace = NS.a) {
8043
- const prefix2 = qualifiedName.includes(":") ? qualifiedName.split(":")[0] : void 0;
8749
+ function drawingRichTextBodyXml(body, qualifiedName2 = "a:txBody", namespace = NS.a) {
8750
+ const prefix2 = qualifiedName2.includes(":") ? qualifiedName2.split(":")[0] : void 0;
8044
8751
  const declaration = prefix2 && prefix2 !== "a" ? ` xmlns:${prefix2}="${namespace}"` : "";
8045
- const doc = parseXml(`<${qualifiedName}${declaration} xmlns:a="${NS.a}" xmlns:r="${NS.r}"/>`);
8752
+ const doc = parseXml(`<${qualifiedName2}${declaration} xmlns:a="${NS.a}" xmlns:r="${NS.r}"/>`);
8046
8753
  writeDrawingRichTextBody(doc.documentElement, body);
8047
8754
  return buildXml(doc);
8048
8755
  }
@@ -17294,12 +18001,12 @@ function shapeParagraphs(wsp) {
17294
18001
  function textIsPlain(wsp) {
17295
18002
  const content = child4(child4(wsp, WPS_NS2, "txbx"), W_NS2, "txbxContent");
17296
18003
  if (!content) return true;
17297
- const only = (node, allowed) => elementsOf(node).every(
18004
+ const only2 = (node, allowed) => elementsOf(node).every(
17298
18005
  (item2) => item2.namespaceURI === W_NS2 && allowed.includes(item2.localName)
17299
18006
  );
17300
- return only(content, ["p"]) && Array.from(content.getElementsByTagNameNS(W_NS2, "p")).every(
17301
- (paragraph2) => only(paragraph2, ["pPr", "r"]) && Array.from(paragraph2.getElementsByTagNameNS(W_NS2, "r")).every(
17302
- (run2) => only(run2, ["rPr", "t"])
18007
+ return only2(content, ["p"]) && Array.from(content.getElementsByTagNameNS(W_NS2, "p")).every(
18008
+ (paragraph2) => only2(paragraph2, ["pPr", "r"]) && Array.from(paragraph2.getElementsByTagNameNS(W_NS2, "r")).every(
18009
+ (run2) => only2(run2, ["rPr", "t"])
17303
18010
  )
17304
18011
  );
17305
18012
  }
@@ -17542,7 +18249,7 @@ function parseAttributes(source2) {
17542
18249
  }
17543
18250
  return attrs2;
17544
18251
  }
17545
- function tagEnd(xml, from) {
18252
+ function tagEnd2(xml, from) {
17546
18253
  let quote = "";
17547
18254
  for (let i = from; i < xml.length; i++) {
17548
18255
  const ch = xml[i];
@@ -17573,7 +18280,7 @@ function parseOrderedXml(xml) {
17573
18280
  i = close < 0 ? -1 : xml.indexOf("<", close + 3);
17574
18281
  continue;
17575
18282
  }
17576
- const end = tagEnd(xml, i + 1);
18283
+ const end = tagEnd2(xml, i + 1);
17577
18284
  if (end < 0) {
17578
18285
  break;
17579
18286
  }
@@ -18153,17 +18860,17 @@ function isShadowedBound(node, constraint) {
18153
18860
 
18154
18861
  // diagram/engine/constraint-eval.ts
18155
18862
  function relatedNodes(node, relation2, name, ptType) {
18156
- const matches = (candidate) => (!name || candidate.name === name) && (matchesPointType(candidate.point, ptType) || candidate.presOf.length > 0 && matchesPointType(candidate.presOf[0], ptType));
18863
+ const matches2 = (candidate) => (!name || candidate.name === name) && (matchesPointType(candidate.point, ptType) || candidate.presOf.length > 0 && matchesPointType(candidate.presOf[0], ptType));
18157
18864
  if (relation2 === "self") {
18158
18865
  return name && node.name !== name ? [] : [node];
18159
18866
  }
18160
18867
  if (relation2 === "ch") {
18161
- return node.children.filter(matches);
18868
+ return node.children.filter(matches2);
18162
18869
  }
18163
18870
  const out = [];
18164
18871
  const visit = (current) => {
18165
18872
  for (const child7 of current.children) {
18166
- if (matches(child7)) {
18873
+ if (matches2(child7)) {
18167
18874
  out.push(child7);
18168
18875
  }
18169
18876
  visit(child7);
@@ -25475,8 +26182,8 @@ function parseDisplayUnits(context, element4) {
25475
26182
 
25476
26183
  // chart/write-util.ts
25477
26184
  var INVALID_XML = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/g;
25478
- var escapeText = (value) => value.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
25479
- var escapeAttribute = (value) => escapeText(value).replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;").replace(/\t/g, "&#9;");
26185
+ var escapeText2 = (value) => value.replace(INVALID_XML, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
26186
+ var escapeAttribute = (value) => escapeText2(value).replace(/"/g, "&quot;").replace(/\r/g, "&#13;").replace(/\n/g, "&#10;").replace(/\t/g, "&#9;");
25480
26187
  function chartNumber(value) {
25481
26188
  if (!Number.isFinite(value)) throw new Error(`Chart number ${value} is not finite`);
25482
26189
  const text = String(value);
@@ -26156,7 +26863,7 @@ function run(value) {
26156
26863
  const hasProperties = Object.keys(properties).length > 0;
26157
26864
  if (text === "\n")
26158
26865
  return hasProperties ? `<a:br>${runProperties("rPr", properties)}</a:br>` : "<a:br/>";
26159
- return `<a:r>${hasProperties ? runProperties("rPr", properties) : ""}<a:t>${escapeText(text)}</a:t></a:r>`;
26866
+ return `<a:r>${hasProperties ? runProperties("rPr", properties) : ""}<a:t>${escapeText2(text)}</a:t></a:r>`;
26160
26867
  }
26161
26868
  function paragraph(value) {
26162
26869
  const align = value.align ? ` algn="${escapeAttribute(value.align)}"` : "";
@@ -26276,7 +26983,7 @@ function numberFormatXml(format) {
26276
26983
  }
26277
26984
 
26278
26985
  // chart/write-text.ts
26279
- var textElement = (local, value) => `<c:${local}>${escapeText(value)}</c:${local}>`;
26986
+ var textElement = (local, value) => `<c:${local}>${escapeText2(value)}</c:${local}>`;
26280
26987
  function cachePoints(cache) {
26281
26988
  return cache.points.map((point, position2) => {
26282
26989
  const format = point.formatCode === void 0 ? "" : ` formatCode="${escapeAttribute(point.formatCode)}"`;
@@ -26406,7 +27113,7 @@ function trendlineLabelXml(context, label) {
26406
27113
  function trendlineXml(context, trendline) {
26407
27114
  return elementXml(
26408
27115
  "trendline",
26409
- (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)
27116
+ (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)
26410
27117
  );
26411
27118
  }
26412
27119
  function errorBarsXml(context, bars) {
@@ -27151,7 +27858,7 @@ function attributes(entries) {
27151
27858
  }).join("");
27152
27859
  }
27153
27860
  var cxElement = (local, content = "", attrs2 = "") => content ? `<cx:${local}${attrs2}>${content}</cx:${local}>` : `<cx:${local}${attrs2}/>`;
27154
- var cxText = (local, text, attrs2 = "") => text === void 0 ? "" : `<cx:${local}${attrs2}>${escapeText(text)}</cx:${local}>`;
27861
+ var cxText = (local, text, attrs2 = "") => text === void 0 ? "" : `<cx:${local}${attrs2}>${escapeText2(text)}</cx:${local}>`;
27155
27862
  var cxVal = (local, value) => value === void 0 ? "" : `<cx:${local}${attributes([["val", value]])}/>`;
27156
27863
  var formulaXml = (local, formula2) => formula2 ? cxText(local, formula2.formula, attributes([["dir", formula2.direction]])) : "";
27157
27864
  var shapeXml = (context, shape) => shape ? cxElement("spPr", shapePropertiesInnerXml(context, shape)) : "";
@@ -28921,6 +29628,10 @@ var WRAPS = [
28921
29628
  function parsePlacement(anchor) {
28922
29629
  const wrap2 = WRAPS.find(([local]) => firstNS(anchor, WP_NS2, local))?.[1] ?? "none";
28923
29630
  const placement = { wrap: wrap2 };
29631
+ const wrapElement2 = WRAPS.map(([local]) => firstNS(anchor, WP_NS2, local)).find(Boolean);
29632
+ const wrapText = wrapElement2?.getAttribute("wrapText");
29633
+ if (wrapText === "bothSides" || wrapText === "left" || wrapText === "right" || wrapText === "largest")
29634
+ placement.wrapText = wrapText;
28924
29635
  if (anchor.getAttribute("behindDoc") === "1") placement.behindText = true;
28925
29636
  const positionH = firstNS(anchor, WP_NS2, "positionH");
28926
29637
  const relativeFrom = enumValue(
@@ -29352,6 +30063,34 @@ function chartRun(doc, node, image, base, oldDrawing, oldContainer, allocator) {
29352
30063
  return void 0;
29353
30064
  }
29354
30065
 
30066
+ // docx/write-fallback.ts
30067
+ var PT_PER_PX2 = 0.75;
30068
+ function setStyleSize(style, name, pt) {
30069
+ const value = `${Math.round(pt * 100) / 100}pt`;
30070
+ const pattern = new RegExp(`(^|;)\\s*${name}\\s*:\\s*[^;]*`, "i");
30071
+ return pattern.test(style) ? style.replace(pattern, (_all, lead) => `${lead}${name}:${value}`) : style;
30072
+ }
30073
+ function patchFallbackSize(content, image, base) {
30074
+ if (!base || image.widthPx === base.widthPx && image.heightPx === base.heightPx) return;
30075
+ const fallback = Array.from(content.childNodes).filter(isElement).find((node) => node.localName === "Fallback");
30076
+ if (!fallback) return;
30077
+ const stack = [fallback];
30078
+ while (stack.length) {
30079
+ const node = stack.pop();
30080
+ const style = node.getAttribute("style");
30081
+ if (style && /(^|;)\s*width\s*:/i.test(style)) {
30082
+ let next = style;
30083
+ if (image.widthPx !== base.widthPx)
30084
+ next = setStyleSize(next, "width", image.widthPx * PT_PER_PX2);
30085
+ if (image.heightPx !== base.heightPx)
30086
+ next = setStyleSize(next, "height", image.heightPx * PT_PER_PX2);
30087
+ node.setAttribute("style", next);
30088
+ continue;
30089
+ }
30090
+ for (const child7 of Array.from(node.childNodes)) if (isElement(child7)) stack.push(child7);
30091
+ }
30092
+ }
30093
+
29355
30094
  // docx/diagram-document.ts
29356
30095
  function diagramsIn(blocks) {
29357
30096
  const diagrams = [];
@@ -29975,6 +30714,13 @@ function createImageRun(doc, image, base, old, allocator) {
29975
30714
  }
29976
30715
  if (base && oldDrawing && image.shape?.editable && base.shape?.editable) {
29977
30716
  const next = rebuildShapeDrawing(doc, image, oldDrawing);
30717
+ const choice = oldDrawing.parentNode;
30718
+ if (oldContainer?.localName === "AlternateContent" && choice) {
30719
+ choice.replaceChild(next, oldDrawing);
30720
+ patchFallbackSize(oldContainer, image, base);
30721
+ clearNonProperties(node, oldContainer);
30722
+ return node;
30723
+ }
29978
30724
  clearNonProperties(node);
29979
30725
  node.appendChild(next);
29980
30726
  return node;
@@ -31047,15 +31793,15 @@ function runIsSafe(run2) {
31047
31793
  const content = Array.from(run2.childNodes).filter(
31048
31794
  (child7) => isElement(child7) && !named2(child7, "rPr") && !isCachedPageBreak(child7)
31049
31795
  );
31050
- const only = content.length === 1 ? content[0] : void 0;
31051
- if (only && named2(only, "br") && isModeledBreak(only)) return true;
31052
- if (only && ["footnoteReference", "endnoteReference", "footnoteRef", "endnoteRef"].some(
31053
- (name) => named2(only, name)
31796
+ const only2 = content.length === 1 ? content[0] : void 0;
31797
+ if (only2 && named2(only2, "br") && isModeledBreak(only2)) return true;
31798
+ if (only2 && ["footnoteReference", "endnoteReference", "footnoteRef", "endnoteRef"].some(
31799
+ (name) => named2(only2, name)
31054
31800
  ))
31055
31801
  return true;
31056
- if (only && named2(only, "fldChar")) {
31057
- const type = getW(only, "fldCharType") ?? "";
31058
- const data = Array.from(only.childNodes).filter(
31802
+ if (only2 && named2(only2, "fldChar")) {
31803
+ const type = getW(only2, "fldCharType") ?? "";
31804
+ const data = Array.from(only2.childNodes).filter(
31059
31805
  (node) => isElement(node) || Boolean(node.textContent?.trim())
31060
31806
  );
31061
31807
  if (!data.length) return ["begin", "separate", "end"].includes(type);
@@ -31187,6 +31933,10 @@ function parseDirectParagraphProperties(props) {
31187
31933
  const line2 = signedTwipValue2(getW(spacing2, "line"));
31188
31934
  if (before !== void 0) paragraph2.spacingBeforeTwips = before;
31189
31935
  if (after !== void 0) paragraph2.spacingAfterTwips = after;
31936
+ const beforeAuto = parseOnOff(getW(spacing2, "beforeAutospacing"));
31937
+ const afterAuto = parseOnOff(getW(spacing2, "afterAutospacing"));
31938
+ if (beforeAuto !== void 0) paragraph2.spacingBeforeAuto = beforeAuto;
31939
+ if (afterAuto !== void 0) paragraph2.spacingAfterAuto = afterAuto;
31190
31940
  if (line2 !== void 0) {
31191
31941
  paragraph2.lineSpacingTwips = line2;
31192
31942
  }
@@ -31218,8 +31968,8 @@ function parseDirectParagraphProperties(props) {
31218
31968
 
31219
31969
  // docx/run-segmentation.ts
31220
31970
  var basisOf = (run2) => run2.restoredRunPropertiesXml ?? run2.sourceRunPropertiesXml;
31221
- function keepsUnmodeledProperties(before, after) {
31222
- const owners = (runs) => runs.flatMap((run2) => Array.from({ length: positionText(run2).length }, () => basisOf(run2)));
31971
+ function keepsUnmodeledProperties(before, after, basis = basisOf) {
31972
+ const owners = (runs) => runs.flatMap((run2) => Array.from({ length: positionText(run2).length }, () => basis(run2)));
31223
31973
  const was = owners(before);
31224
31974
  const now = owners(after);
31225
31975
  const kept = (from, to, shift) => {
@@ -31253,13 +32003,22 @@ function runsToWriteAnew(paragraph2, base, slots) {
31253
32003
  return !remaining.length || remaining.every((run2) => run2.restoredRunPropertiesXml || run2.sourceRunPropertiesXml);
31254
32004
  }))
31255
32005
  return none;
31256
- if (paragraph2.runs.every(
31257
- (run2) => !run2.image && !run2.equation && (run2.restoredRunPropertiesXml || run2.sourceRunPropertiesXml)
31258
- ))
31259
- return none;
31260
32006
  const sameText = paragraph2.runs.map((run2) => run2.text).join("") === base.runs.map((run2) => run2.text).join("");
31261
32007
  const sameBoundaries = paragraph2.runs.length === base.runs.length && paragraph2.runs.every((run2, index) => run2.text === base.runs[index]?.text);
31262
32008
  if (sameBoundaries || !sameText && paragraph2.runs.length === base.runs.length) return none;
32009
+ if (paragraph2.runs.every(
32010
+ (run2) => !run2.image && !run2.equation && (run2.restoredRunPropertiesXml || run2.sourceRunPropertiesXml)
32011
+ )) {
32012
+ if (keepsUnmodeledProperties(
32013
+ base.runs,
32014
+ paragraph2.runs,
32015
+ (run2) => run2.sourceRunPropertiesXml ?? run2.restoredRunPropertiesXml
32016
+ ))
32017
+ return none;
32018
+ throw new Error(
32019
+ `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.`
32020
+ );
32021
+ }
31263
32022
  const object = (run2) => Boolean(run2.image || run2.equation);
31264
32023
  if (!paragraph2.runs.some(object) && !base.runs.some(object) && keepsUnmodeledProperties(base.runs, paragraph2.runs))
31265
32024
  return new Set(
@@ -32396,14 +33155,14 @@ async function applyNumberingCatalog(zip, model, binding) {
32396
33155
  }
32397
33156
 
32398
33157
  // docx/style-numbering-package.ts
32399
- var STYLES_PART = "word/styles.xml";
32400
- var AFTER_PPR = ["rPr", "tblPr", "trPr", "tcPr", "tblStylePr"];
33158
+ var STYLES_PART2 = "word/styles.xml";
33159
+ var AFTER_PPR2 = ["rPr", "tblPr", "trPr", "tcPr", "tblStylePr"];
32401
33160
  var withoutNumbering = (catalog) => catalog ? {
32402
33161
  ...catalog,
32403
33162
  styles: Object.fromEntries(
32404
33163
  Object.entries(catalog.styles).map(([id, style]) => {
32405
- const { numbering: _numbering, ...rest } = style;
32406
- return [id, rest];
33164
+ const { numbering: _numbering, formatting, ...rest } = style;
33165
+ return [id, { ...rest, formatting: unwritableFormatting(formatting) }];
32407
33166
  })
32408
33167
  )
32409
33168
  } : void 0;
@@ -32416,7 +33175,7 @@ function setNumPr(style, numbering) {
32416
33175
  if (!numbering && !pPr) return;
32417
33176
  if (!pPr) {
32418
33177
  pPr = makeW(doc, "pPr");
32419
- const anchor = elementsOf2(style).find((child7) => AFTER_PPR.includes(child7.localName)) ?? null;
33178
+ const anchor = elementsOf2(style).find((child7) => AFTER_PPR2.includes(child7.localName)) ?? null;
32420
33179
  style.insertBefore(pPr, anchor);
32421
33180
  }
32422
33181
  for (const existing of children2(pPr, "numPr")) pPr.removeChild(existing);
@@ -32440,7 +33199,7 @@ async function applyStyleNumbering(zip, model, base) {
32440
33199
  (id) => JSON.stringify(next[id]?.numbering) !== JSON.stringify(prior[id]?.numbering)
32441
33200
  );
32442
33201
  if (!changed.length) return;
32443
- const file = zip.file(STYLES_PART);
33202
+ const file = zip.file(STYLES_PART2);
32444
33203
  if (!file) throw new Error("Cannot link styles to a list: the package has no styles.xml.");
32445
33204
  const doc = parseXml2(await file.async("string"));
32446
33205
  const styles = children2(doc.documentElement, "style");
@@ -32451,7 +33210,7 @@ async function applyStyleNumbering(zip, model, base) {
32451
33210
  if (!style) throw new Error(`Cannot link style "${id}" to a list: it is not in styles.xml.`);
32452
33211
  setNumPr(style, next[id]?.numbering);
32453
33212
  }
32454
- zip.file(STYLES_PART, buildXml(doc));
33213
+ zip.file(STYLES_PART2, buildXml(doc));
32455
33214
  }
32456
33215
 
32457
33216
  // docx/write-header-footer.ts
@@ -33844,7 +34603,7 @@ function headerFooterResults(model) {
33844
34603
  return void 0;
33845
34604
  }
33846
34605
  }
33847
- async function saveDocx(model, pendingMedia) {
34606
+ async function saveDocx(model, pendingMedia, options) {
33848
34607
  const ids = /* @__PURE__ */ new Set();
33849
34608
  for (const block of model.blocks) {
33850
34609
  if (ids.has(block.id)) throw new Error(`Duplicate document block id: ${block.id}`);
@@ -33935,6 +34694,7 @@ async function saveDocx(model, pendingMedia) {
33935
34694
  await applyNumberingCatalog(zip, model, binding);
33936
34695
  await applyCoreProperties(zip, model.properties, binding?.base.properties);
33937
34696
  if (binding) await applyStyleNumbering(zip, model, binding.base);
34697
+ if (binding) await applyStyleFormatting(zip, model, binding.base);
33938
34698
  if (model.compatibilityMode !== binding?.base.compatibilityMode)
33939
34699
  await applyCompatibilityMode(zip, model.compatibilityMode);
33940
34700
  if (Boolean(model.evenAndOddHeaders) !== Boolean(binding?.base.evenAndOddHeaders))
@@ -33966,6 +34726,8 @@ async function saveDocx(model, pendingMedia) {
33966
34726
  }
33967
34727
  if (JSON.stringify(model.comments ?? []) !== JSON.stringify(binding?.base.comments ?? []))
33968
34728
  await applyComments(zip, model.comments ?? []);
34729
+ if (binding) await applyDataBindings(zip, model, binding.base, binding.context.sourceXml);
34730
+ if (binding) await stampModified(zip, options?.modified);
33969
34731
  dropAddedFolders(zip, sourceEntries);
33970
34732
  return zip.generateAsync({ type: "uint8array", compression: "DEFLATE" });
33971
34733
  }
@@ -34021,8 +34783,11 @@ function parseCell(cell2, parseParagraph3, id, control) {
34021
34783
  const element4 = child7;
34022
34784
  if (element4.namespaceURI !== WORD_NS) return [];
34023
34785
  if (element4.localName === "p") return [result.paragraphs[paragraphIndex++]];
34024
- if (element4.localName === "tbl")
34025
- return [parseTable(element4, `${id}-nested${tableIndex++}`, parseParagraph3)];
34786
+ if (element4.localName === "tbl") {
34787
+ const inner = parseTable(element4, `${id}-nested${tableIndex++}`, parseParagraph3);
34788
+ markRestructurable(inner, element4);
34789
+ return [inner];
34790
+ }
34026
34791
  return [];
34027
34792
  }
34028
34793
  );
@@ -34078,6 +34843,9 @@ function parseRowProperties(row) {
34078
34843
  if (onOffElement(first2(trPr, "tblHeader"))) result.header = true;
34079
34844
  return result;
34080
34845
  }
34846
+ function markRestructurable(table, node) {
34847
+ if (canRestructureTable(node) && tableGrid(table)) table.restructurable = true;
34848
+ }
34081
34849
  function parseTable(node, id, parseParagraph3) {
34082
34850
  const rowEntries = flatRows(node);
34083
34851
  const rows = rowEntries.map(
@@ -34118,6 +34886,7 @@ function parseTable(node, id, parseParagraph3) {
34118
34886
  return properties;
34119
34887
  });
34120
34888
  if (rowProperties.some((row) => Object.keys(row).length)) table.rowProperties = rowProperties;
34889
+ if (!table.structureEditable) markRestructurable(table, node);
34121
34890
  return table;
34122
34891
  }
34123
34892
 
@@ -34251,23 +35020,23 @@ function parseRun2(node, revision) {
34251
35020
  let noteSeparator;
34252
35021
  let fieldChar;
34253
35022
  const fieldCode = content.length > 0 && content.every((child7) => named2(child7, "instrText")) ? content.map((child7) => textContent(child7)).join("") : void 0;
34254
- const only = content.length === 1 ? content[0] : void 0;
34255
- if (only) {
34256
- if (named2(only, "br")) {
34257
- const kind = classifyBreak(only);
35023
+ const only2 = content.length === 1 ? content[0] : void 0;
35024
+ if (only2) {
35025
+ if (named2(only2, "br")) {
35026
+ const kind = classifyBreak(only2);
34258
35027
  if (kind === "page" || kind === "column") breakKind = kind;
34259
- } else if (named2(only, "footnoteReference")) {
34260
- const id = getW(only, "id");
35028
+ } else if (named2(only2, "footnoteReference")) {
35029
+ const id = getW(only2, "id");
34261
35030
  if (id) noteReference = { kind: "footnote", id };
34262
- } else if (named2(only, "endnoteReference")) {
34263
- const id = getW(only, "id");
35031
+ } else if (named2(only2, "endnoteReference")) {
35032
+ const id = getW(only2, "id");
34264
35033
  if (id) noteReference = { kind: "endnote", id };
34265
- } else if (named2(only, "footnoteRef")) noteMark = "footnote";
34266
- else if (named2(only, "endnoteRef")) noteMark = "endnote";
34267
- else if (named2(only, "separator")) noteSeparator = "separator";
34268
- else if (named2(only, "continuationSeparator")) noteSeparator = "continuationSeparator";
34269
- else if (named2(only, "fldChar")) {
34270
- const type = getW(only, "fldCharType");
35034
+ } else if (named2(only2, "footnoteRef")) noteMark = "footnote";
35035
+ else if (named2(only2, "endnoteRef")) noteMark = "endnote";
35036
+ else if (named2(only2, "separator")) noteSeparator = "separator";
35037
+ else if (named2(only2, "continuationSeparator")) noteSeparator = "continuationSeparator";
35038
+ else if (named2(only2, "fldChar")) {
35039
+ const type = getW(only2, "fldCharType");
34271
35040
  if (type === "begin" || type === "separate" || type === "end") fieldChar = type;
34272
35041
  }
34273
35042
  }
@@ -34289,9 +35058,9 @@ function parseRun2(node, revision) {
34289
35058
  if (noteSeparator) run2.noteSeparator = noteSeparator;
34290
35059
  if (fieldChar) {
34291
35060
  run2.fieldChar = fieldChar;
34292
- const flags = parseFieldFlags(only);
35061
+ const flags = parseFieldFlags(only2);
34293
35062
  if (flags) run2.fieldFlags = flags;
34294
- const data = fieldChar === "begin" ? first2(only, "ffData") : void 0;
35063
+ const data = fieldChar === "begin" ? first2(only2, "ffData") : void 0;
34295
35064
  const formField = data && parseFormField(data);
34296
35065
  if (formField) run2.formField = formField;
34297
35066
  }
@@ -34631,6 +35400,7 @@ function parseSettings(xml) {
34631
35400
  );
34632
35401
  return {
34633
35402
  ...compatibilityMode !== void 0 && Number.isInteger(compatibilityMode) && compatibilityMode > 0 ? { compatibilityMode } : {},
35403
+ ...onOffElement(first2(first2(root, "compat"), "doNotUseHTMLParagraphAutoSpacing")) === true ? { doNotUseHtmlParagraphAutoSpacing: true } : {},
34634
35404
  evenAndOddHeaders: onOffElement(first2(root, "evenAndOddHeaders")) === true,
34635
35405
  autoHyphenation: onOffElement(first2(root, "autoHyphenation")) === true,
34636
35406
  ...footnoteNumFmt ? { footnoteNumFmt } : {},
@@ -34711,6 +35481,7 @@ async function parseDocumentParts(zip, body, blocks, drawings) {
34711
35481
  return {
34712
35482
  sections,
34713
35483
  ...settings.compatibilityMode !== void 0 ? { compatibilityMode: settings.compatibilityMode } : {},
35484
+ ...settings.doNotUseHtmlParagraphAutoSpacing ? { doNotUseHtmlParagraphAutoSpacing: true } : {},
34714
35485
  ...footnotes ? { footnotes } : {},
34715
35486
  ...footnoteSeparators ? { footnoteSeparators } : {},
34716
35487
  ...endnotes ? { endnotes } : {},
@@ -34953,6 +35724,7 @@ async function readPackage(input) {
34953
35724
  const parts = await parseDocumentParts(zip, body, blocks, drawings);
34954
35725
  model.sections = parts.sections;
34955
35726
  if (parts.compatibilityMode !== void 0) model.compatibilityMode = parts.compatibilityMode;
35727
+ if (parts.doNotUseHtmlParagraphAutoSpacing) model.doNotUseHtmlParagraphAutoSpacing = true;
34956
35728
  if (parts.footnotes) model.footnotes = parts.footnotes;
34957
35729
  if (parts.footnoteSeparators) model.footnoteSeparators = parts.footnoteSeparators;
34958
35730
  if (parts.endnotes) model.endnotes = parts.endnotes;
@@ -34962,14 +35734,16 @@ async function readPackage(input) {
34962
35734
  if (parts.autoHyphenation) model.autoHyphenation = true;
34963
35735
  const coreFile = zip.file("docProps/core.xml");
34964
35736
  if (coreFile) {
34965
- const properties = parseCoreProperties(await coreFile.async("string"));
35737
+ const properties = parseCoreProperties2(await coreFile.async("string"));
34966
35738
  if (properties) model.properties = properties;
34967
35739
  }
34968
35740
  await readPlaceholderTexts(zip, drawings.rels, model);
34969
35741
  const pageColor = parsePageBackground(document.documentElement);
34970
35742
  if (pageColor) model.pageColor = pageColor;
34971
35743
  model.warnings.push(...parts.warnings);
34972
- if (blocks.some((block) => block.type === "table" && !block.structureEditable))
35744
+ if (blocks.some(
35745
+ (block) => block.type === "table" && !block.structureEditable && !block.restructurable
35746
+ ))
34973
35747
  model.warnings.push(
34974
35748
  "Merged, nested, or complex tables can be read, but their row and column structure cannot be edited safely."
34975
35749
  );
@@ -34995,7 +35769,7 @@ async function readPackage(input) {
34995
35769
  (block) => block.type === "table" && block.rows.some((row) => row.some((cell2) => cell2.nestedTables?.length))
34996
35770
  ))
34997
35771
  model.warnings.push(
34998
- "Text in nested tables is editable; the grid, merges and formatting of a nested table are preserved but cannot be changed."
35772
+ "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."
34999
35773
  );
35000
35774
  const pictureBlocks = documentDrawingBlocks({ ...model, blocks });
35001
35775
  await resolveDocumentDiagrams(
@@ -35033,9 +35807,9 @@ async function loadDocx(input) {
35033
35807
  return {
35034
35808
  model,
35035
35809
  media,
35036
- save: (next = model, pendingMedia) => {
35810
+ save: (next = model, pendingMedia, options) => {
35037
35811
  if (next !== model) remember(next, context);
35038
- return saveDocx(next, pendingMedia);
35812
+ return saveDocx(next, pendingMedia, options);
35039
35813
  }
35040
35814
  };
35041
35815
  }