@poe-platform/safe-bash 0.1.806 → 0.1.807

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 (856) hide show
  1. package/README.md +4 -0
  2. package/dist/image-ast/portable.d.ts +8 -0
  3. package/dist/image-ast/portable.js +2 -0
  4. package/dist/safe-bash/chunks/{chunk-KRA6WK4Z.js → chunk-3Y54SR4R.js} +6 -6
  5. package/dist/safe-bash/chunks/{chunk-OYJI4L4J.js → chunk-PPAA3LJS.js} +1 -1
  6. package/dist/safe-bash/chunks/{chunk-SCROOJV7.js → chunk-XZ2Y4RWC.js} +2 -2
  7. package/dist/safe-bash/command-chunks/{biff-AU4VGVMD-6EQ64QPG.js → biff-YBHP7ZES-M7TU7NA5.js} +1211 -1205
  8. package/dist/safe-bash/command-chunks/chunk-2A6TBB4F.js +14 -0
  9. package/dist/safe-bash/command-chunks/chunk-2AF7J6FE.js +372 -0
  10. package/dist/safe-bash/command-chunks/{chunk-AITNVBXO.js → chunk-2ANW3FXH.js} +4 -4
  11. package/dist/safe-bash/command-chunks/chunk-2B6XWO6A.js +730 -0
  12. package/dist/safe-bash/command-chunks/chunk-2BKOSQD3.js +11 -0
  13. package/dist/safe-bash/command-chunks/chunk-2EUH5B6A.js +127 -0
  14. package/dist/safe-bash/command-chunks/chunk-2FOLUJLI.js +400 -0
  15. package/dist/safe-bash/command-chunks/{chunk-CZLX3KVF.js → chunk-2GILUQJY.js} +4 -6
  16. package/dist/safe-bash/command-chunks/chunk-2HHGDJ7J.js +280 -0
  17. package/dist/safe-bash/command-chunks/chunk-2NE2GPSF.js +546 -0
  18. package/dist/safe-bash/command-chunks/chunk-2P7BLWWI.js +272 -0
  19. package/dist/safe-bash/command-chunks/chunk-2PSVE7I5.js +101 -0
  20. package/dist/safe-bash/command-chunks/chunk-2UUFZMOH.js +503 -0
  21. package/dist/safe-bash/command-chunks/chunk-2VGAC6S6.js +393 -0
  22. package/dist/safe-bash/command-chunks/chunk-2W54TAGI.js +162 -0
  23. package/dist/safe-bash/command-chunks/chunk-326A5G42.js +328 -0
  24. package/dist/safe-bash/command-chunks/chunk-36KIT4DU.js +218 -0
  25. package/dist/safe-bash/command-chunks/chunk-3CHQG25N.js +455 -0
  26. package/dist/safe-bash/command-chunks/chunk-3JQ3RF2O.js +72 -0
  27. package/dist/safe-bash/command-chunks/chunk-3MLJWSYL.js +92 -0
  28. package/dist/safe-bash/command-chunks/{chunk-ASYR2LU7.js → chunk-3RQCLLQA.js} +5 -5
  29. package/dist/safe-bash/command-chunks/chunk-3SEQG5JH.js +521 -0
  30. package/dist/safe-bash/command-chunks/chunk-3SWT2KYH.js +78 -0
  31. package/dist/safe-bash/command-chunks/chunk-3VETFXYR.js +170 -0
  32. package/dist/safe-bash/command-chunks/chunk-3W6PTHHB.js +65 -0
  33. package/dist/safe-bash/command-chunks/chunk-457CU3IC.js +8 -0
  34. package/dist/safe-bash/command-chunks/chunk-45BW6MGM.js +250 -0
  35. package/dist/safe-bash/command-chunks/chunk-47MFDPH4.js +419 -0
  36. package/dist/safe-bash/command-chunks/chunk-4ATHODCG.js +444 -0
  37. package/dist/safe-bash/command-chunks/chunk-4DJICIFV.js +227 -0
  38. package/dist/safe-bash/command-chunks/chunk-4FNQPK7C.js +385 -0
  39. package/dist/safe-bash/command-chunks/chunk-4LXDJES2.js +65 -0
  40. package/dist/safe-bash/command-chunks/chunk-4QRXKUD2.js +662 -0
  41. package/dist/safe-bash/command-chunks/chunk-4QYNOBWZ.js +455 -0
  42. package/dist/safe-bash/command-chunks/{chunk-MWNWT6HG.js → chunk-4XFFIKA3.js} +5 -5
  43. package/dist/safe-bash/command-chunks/chunk-5AU5ENL5.js +180 -0
  44. package/dist/safe-bash/command-chunks/chunk-5DFZAJHL.js +324 -0
  45. package/dist/safe-bash/command-chunks/chunk-5GEFJROP.js +270 -0
  46. package/dist/safe-bash/command-chunks/chunk-5HWX4XYW.js +263 -0
  47. package/dist/safe-bash/command-chunks/chunk-5LKNP4IF.js +872 -0
  48. package/dist/safe-bash/command-chunks/chunk-5OEHUIVE.js +240 -0
  49. package/dist/safe-bash/command-chunks/chunk-6EHVFKM7.js +171 -0
  50. package/dist/safe-bash/command-chunks/chunk-6JTPLJ3B.js +155 -0
  51. package/dist/safe-bash/command-chunks/chunk-6KLUPQ65.js +496 -0
  52. package/dist/safe-bash/command-chunks/chunk-6NS5RXQ7.js +285 -0
  53. package/dist/safe-bash/command-chunks/chunk-6PJIQEH4.js +3472 -0
  54. package/dist/safe-bash/command-chunks/chunk-763ECQWB.js +566 -0
  55. package/dist/safe-bash/command-chunks/chunk-7DADVPKN.js +23 -0
  56. package/dist/safe-bash/command-chunks/chunk-7LEADSSA.js +164 -0
  57. package/dist/safe-bash/command-chunks/chunk-7MMSBVUP.js +732 -0
  58. package/dist/safe-bash/command-chunks/chunk-7OXNWLSL.js +35 -0
  59. package/dist/safe-bash/command-chunks/chunk-7PZASWL6.js +354 -0
  60. package/dist/safe-bash/command-chunks/{chunk-ZBR3UH4P.js → chunk-7QH3WAMQ.js} +2 -2
  61. package/dist/safe-bash/command-chunks/{chunk-CB3HTIDK.js → chunk-7SOE7XIS.js} +11 -11
  62. package/dist/safe-bash/command-chunks/chunk-7Y3ZQ6FE.js +56 -0
  63. package/dist/safe-bash/command-chunks/chunk-A2YEQYCC.js +289 -0
  64. package/dist/safe-bash/command-chunks/chunk-A3XE767Q.js +502 -0
  65. package/dist/safe-bash/command-chunks/{chunk-MWY75E3F.js → chunk-A6LCBGE6.js} +187 -187
  66. package/dist/safe-bash/command-chunks/{chunk-HFUL6E5I.js → chunk-A7CE4EIU.js} +33 -151
  67. package/dist/safe-bash/command-chunks/chunk-A7EMM3SB.js +297 -0
  68. package/dist/safe-bash/command-chunks/{chunk-G3YO3JIN.js → chunk-ABH5FMMA.js} +1 -1
  69. package/dist/safe-bash/command-chunks/chunk-AEJZEGW7.js +1376 -0
  70. package/dist/safe-bash/command-chunks/chunk-AELXRNM6.js +207 -0
  71. package/dist/safe-bash/command-chunks/chunk-AEZIPWRI.js +260 -0
  72. package/dist/safe-bash/command-chunks/{chunk-AHD3CGAY.js → chunk-AFPXADZG.js} +4 -4
  73. package/dist/safe-bash/command-chunks/chunk-AIOB34IX.js +201 -0
  74. package/dist/safe-bash/command-chunks/chunk-AJEYCC4X.js +262 -0
  75. package/dist/safe-bash/command-chunks/chunk-ALMHXDKZ.js +321 -0
  76. package/dist/safe-bash/command-chunks/chunk-AQ6RTM2M.js +309 -0
  77. package/dist/safe-bash/command-chunks/chunk-AQNFEGMZ.js +481 -0
  78. package/dist/safe-bash/command-chunks/{chunk-2AKKYY5G.js → chunk-ASZ4EMKE.js} +1 -1
  79. package/dist/safe-bash/command-chunks/chunk-AYJGINE5.js +144 -0
  80. package/dist/safe-bash/command-chunks/{chunk-MRFW2E6B.js → chunk-B4UWZCQR.js} +1 -1
  81. package/dist/safe-bash/command-chunks/chunk-BDYKJTBQ.js +43 -0
  82. package/dist/safe-bash/command-chunks/chunk-BERVTMQB.js +41 -0
  83. package/dist/safe-bash/command-chunks/chunk-BZOY2UMP.js +275 -0
  84. package/dist/safe-bash/command-chunks/{chunk-W47KIMSP.js → chunk-C2EYJT4S.js} +1 -1
  85. package/dist/safe-bash/command-chunks/chunk-CK5Q6RDE.js +342 -0
  86. package/dist/safe-bash/command-chunks/chunk-CKEODJVT.js +992 -0
  87. package/dist/safe-bash/command-chunks/{chunk-Z7UIOPHJ.js → chunk-DCMSPMMD.js} +1 -1
  88. package/dist/safe-bash/command-chunks/chunk-DE66JRWJ.js +352 -0
  89. package/dist/safe-bash/command-chunks/chunk-DKNNYPOI.js +409 -0
  90. package/dist/safe-bash/command-chunks/chunk-DV745GFU.js +294 -0
  91. package/dist/safe-bash/command-chunks/chunk-DXX2Z2QA.js +33 -0
  92. package/dist/safe-bash/command-chunks/chunk-E7AYF54A.js +473 -0
  93. package/dist/safe-bash/command-chunks/chunk-EDSFQJAU.js +159 -0
  94. package/dist/safe-bash/command-chunks/{chunk-UQ3KEUCF.js → chunk-ESD5ZD74.js} +7 -1
  95. package/dist/safe-bash/command-chunks/chunk-EUXUCRCI.js +1739 -0
  96. package/dist/safe-bash/command-chunks/chunk-F2ORFLCH.js +3669 -0
  97. package/dist/safe-bash/command-chunks/chunk-FANIWOBM.js +311 -0
  98. package/dist/safe-bash/command-chunks/chunk-FOO3AXFK.js +47 -0
  99. package/dist/safe-bash/command-chunks/chunk-FRZ5P5AB.js +131 -0
  100. package/dist/safe-bash/command-chunks/chunk-FZSQMMYV.js +276 -0
  101. package/dist/safe-bash/command-chunks/{chunk-P6NUIMMX.js → chunk-G5F2VSQ7.js} +1 -1
  102. package/dist/safe-bash/command-chunks/chunk-GGOZXIGH.js +299 -0
  103. package/dist/safe-bash/command-chunks/chunk-GIESJLR2.js +241 -0
  104. package/dist/safe-bash/command-chunks/chunk-GLPIFP7N.js +385 -0
  105. package/dist/safe-bash/command-chunks/chunk-GZ2N24A2.js +342 -0
  106. package/dist/safe-bash/command-chunks/chunk-H2NWPMNW.js +216 -0
  107. package/dist/safe-bash/command-chunks/chunk-HHLVI2CB.js +3949 -0
  108. package/dist/safe-bash/command-chunks/chunk-HJDE7ZNV.js +82 -0
  109. package/dist/safe-bash/command-chunks/chunk-HOAM3F5I.js +124 -0
  110. package/dist/safe-bash/command-chunks/chunk-HPKUFWHW.js +482 -0
  111. package/dist/safe-bash/command-chunks/chunk-HPMVMOD2.js +109 -0
  112. package/dist/safe-bash/command-chunks/chunk-HQAHDJPX.js +8 -0
  113. package/dist/safe-bash/command-chunks/chunk-HR2Y6YEP.js +12 -0
  114. package/dist/safe-bash/command-chunks/chunk-HUNXIAOL.js +62 -0
  115. package/dist/safe-bash/command-chunks/chunk-I4JWZOSP.js +244 -0
  116. package/dist/safe-bash/command-chunks/chunk-I6AMDG2T.js +85 -0
  117. package/dist/safe-bash/command-chunks/chunk-IB2Q5CL3.js +288 -0
  118. package/dist/safe-bash/command-chunks/chunk-IFNLDOJ4.js +316 -0
  119. package/dist/safe-bash/command-chunks/chunk-IKHBXETN.js +174 -0
  120. package/dist/safe-bash/command-chunks/chunk-IOSWG5JS.js +228 -0
  121. package/dist/safe-bash/command-chunks/chunk-IQFRPIXH.js +317 -0
  122. package/dist/safe-bash/command-chunks/chunk-IR6ZKAUH.js +582 -0
  123. package/dist/safe-bash/command-chunks/chunk-IW7PEB4I.js +297 -0
  124. package/dist/safe-bash/command-chunks/chunk-JGGRMERW.js +36 -0
  125. package/dist/safe-bash/command-chunks/chunk-JHAY3KYC.js +520 -0
  126. package/dist/safe-bash/command-chunks/{chunk-UO25D4WG.js → chunk-JITDS55R.js} +22 -22
  127. package/dist/safe-bash/command-chunks/chunk-JJK3CU7Z.js +6 -0
  128. package/dist/safe-bash/command-chunks/{chunk-XKZWUMH4.js → chunk-JN7GNI2C.js} +1 -1
  129. package/dist/safe-bash/command-chunks/chunk-JQ3EJKHF.js +160 -0
  130. package/dist/safe-bash/command-chunks/chunk-JQE256UO.js +292 -0
  131. package/dist/safe-bash/command-chunks/chunk-JQZ3BXWY.js +382 -0
  132. package/dist/safe-bash/command-chunks/{chunk-7DLR4HCC.js → chunk-JWSOFSGI.js} +22 -22
  133. package/dist/safe-bash/command-chunks/chunk-K3CDZMUN.js +168 -0
  134. package/dist/safe-bash/command-chunks/{chunk-SUYSZJI3.js → chunk-K5COUQAQ.js} +4 -4
  135. package/dist/safe-bash/command-chunks/chunk-K7HUXUN2.js +489 -0
  136. package/dist/safe-bash/command-chunks/chunk-KB3CY3QO.js +62 -0
  137. package/dist/safe-bash/command-chunks/chunk-KCBVOYAY.js +92 -0
  138. package/dist/safe-bash/command-chunks/chunk-KD25ICP4.js +366 -0
  139. package/dist/safe-bash/command-chunks/chunk-KDKQ5D55.js +180 -0
  140. package/dist/safe-bash/command-chunks/chunk-KNKDUEDW.js +521 -0
  141. package/dist/safe-bash/command-chunks/chunk-KR2PQ7GD.js +174 -0
  142. package/dist/safe-bash/command-chunks/chunk-KS6WUDPM.js +153 -0
  143. package/dist/safe-bash/command-chunks/{chunk-XFHUSZBM.js → chunk-KUGV3SSL.js} +5 -5
  144. package/dist/safe-bash/command-chunks/chunk-L2JAP5KO.js +249 -0
  145. package/dist/safe-bash/command-chunks/chunk-L2KEA6SN.js +271 -0
  146. package/dist/safe-bash/command-chunks/chunk-L3WY5ASN.js +526 -0
  147. package/dist/safe-bash/command-chunks/chunk-L4XEXXVQ.js +399 -0
  148. package/dist/safe-bash/command-chunks/chunk-LDTUZIJK.js +90 -0
  149. package/dist/safe-bash/command-chunks/chunk-LHDB4QO5.js +479 -0
  150. package/dist/safe-bash/command-chunks/chunk-LHL6RWGJ.js +548 -0
  151. package/dist/safe-bash/command-chunks/chunk-LHRXDH45.js +164 -0
  152. package/dist/safe-bash/command-chunks/chunk-LQOKYG3O.js +153 -0
  153. package/dist/safe-bash/command-chunks/chunk-LRDME6WV.js +12 -0
  154. package/dist/safe-bash/command-chunks/chunk-LWVDJB5S.js +305 -0
  155. package/dist/safe-bash/command-chunks/chunk-M57GLLK4.js +27 -0
  156. package/dist/safe-bash/command-chunks/chunk-MAHX3IW3.js +108 -0
  157. package/dist/safe-bash/command-chunks/{chunk-LQZSR6DT.js → chunk-MDV7W5AS.js} +2 -2
  158. package/dist/safe-bash/command-chunks/chunk-MG7AJD5E.js +168 -0
  159. package/dist/safe-bash/command-chunks/chunk-MHJ3DQUE.js +213 -0
  160. package/dist/safe-bash/command-chunks/chunk-MLGNBD7V.js +552 -0
  161. package/dist/safe-bash/command-chunks/chunk-MN2M33JK.js +237 -0
  162. package/dist/safe-bash/command-chunks/chunk-MOL3TRBT.js +32 -0
  163. package/dist/safe-bash/command-chunks/chunk-MQFXMBGD.js +75 -0
  164. package/dist/safe-bash/command-chunks/chunk-MQPWE22J.js +171 -0
  165. package/dist/safe-bash/command-chunks/chunk-MQU6Q75R.js +523 -0
  166. package/dist/safe-bash/command-chunks/chunk-MWAAMNAM.js +353 -0
  167. package/dist/safe-bash/command-chunks/chunk-MZ4BTMTI.js +240 -0
  168. package/dist/safe-bash/command-chunks/chunk-N4DY4FPA.js +679 -0
  169. package/dist/safe-bash/command-chunks/chunk-N74TJL6X.js +183 -0
  170. package/dist/safe-bash/command-chunks/chunk-NA5Q4V2H.js +304 -0
  171. package/dist/safe-bash/command-chunks/chunk-NSM366N6.js +22 -0
  172. package/dist/safe-bash/command-chunks/chunk-NY4ZPV3N.js +523 -0
  173. package/dist/safe-bash/command-chunks/chunk-NYBF2BVE.js +17 -0
  174. package/dist/safe-bash/command-chunks/chunk-OBK24KGM.js +24 -0
  175. package/dist/safe-bash/command-chunks/{chunk-GDAS4LY7.js → chunk-OEKLEUUW.js} +4 -4
  176. package/dist/safe-bash/command-chunks/chunk-OGWJD5QP.js +404 -0
  177. package/dist/safe-bash/command-chunks/chunk-OIPATOZW.js +154 -0
  178. package/dist/safe-bash/command-chunks/chunk-OP6J3OLL.js +243 -0
  179. package/dist/safe-bash/command-chunks/chunk-OTTMIB3C.js +266 -0
  180. package/dist/safe-bash/command-chunks/{chunk-OZHPB4KD.js → chunk-OU4VE5CR.js} +12 -12
  181. package/dist/safe-bash/command-chunks/chunk-P42REFYL.js +228 -0
  182. package/dist/safe-bash/command-chunks/{chunk-YJ3TFZB2.js → chunk-PQOAM5SC.js} +1 -1
  183. package/dist/safe-bash/command-chunks/chunk-PQOIOVF2.js +444 -0
  184. package/dist/safe-bash/command-chunks/chunk-PRQEVUNE.js +205 -0
  185. package/dist/safe-bash/command-chunks/{chunk-W5OR7COJ.js → chunk-PVLPWVRH.js} +21 -21
  186. package/dist/safe-bash/command-chunks/{chunk-BNG4ZMZ3.js → chunk-PXL4NBYP.js} +1 -78
  187. package/dist/safe-bash/command-chunks/chunk-Q6W5FRZG.js +41 -0
  188. package/dist/safe-bash/command-chunks/{chunk-KLCHCSIV.js → chunk-QGD64UHJ.js} +1 -1
  189. package/dist/safe-bash/command-chunks/chunk-QHS7PDG3.js +188 -0
  190. package/dist/safe-bash/command-chunks/chunk-QXCSASIE.js +151 -0
  191. package/dist/safe-bash/command-chunks/chunk-QYCBVKFT.js +255 -0
  192. package/dist/safe-bash/command-chunks/chunk-R4TYL2G6.js +1529 -0
  193. package/dist/safe-bash/command-chunks/chunk-RAXJVM4U.js +625 -0
  194. package/dist/safe-bash/command-chunks/chunk-RBFZYSZZ.js +207 -0
  195. package/dist/safe-bash/command-chunks/chunk-RJHVJZ4H.js +185 -0
  196. package/dist/safe-bash/command-chunks/chunk-RKPPUYZE.js +213 -0
  197. package/dist/safe-bash/command-chunks/chunk-RMJNV6Q7.js +23 -0
  198. package/dist/safe-bash/command-chunks/{chunk-MR2RLUPV.js → chunk-RQHQCJMV.js} +11 -9
  199. package/dist/safe-bash/command-chunks/chunk-RR6QQ25D.js +71 -0
  200. package/dist/safe-bash/command-chunks/{chunk-JW3KIZU6.js → chunk-RUXY7GN5.js} +1 -1
  201. package/dist/safe-bash/command-chunks/chunk-RZC7QHL6.js +112 -0
  202. package/dist/safe-bash/command-chunks/chunk-RZJRR4UJ.js +1677 -0
  203. package/dist/safe-bash/command-chunks/chunk-S4OBYRNI.js +639 -0
  204. package/dist/safe-bash/command-chunks/{chunk-DQNDEWCI.js → chunk-S65T5JJO.js} +12 -12
  205. package/dist/safe-bash/command-chunks/chunk-S6PPBBXX.js +77 -0
  206. package/dist/safe-bash/command-chunks/chunk-SCG4LK5U.js +265 -0
  207. package/dist/safe-bash/command-chunks/chunk-SDTC2BLK.js +143 -0
  208. package/dist/safe-bash/command-chunks/chunk-SEK43FRN.js +357 -0
  209. package/dist/safe-bash/command-chunks/chunk-SH45NZ2P.js +194 -0
  210. package/dist/safe-bash/command-chunks/chunk-SM733XRT.js +250 -0
  211. package/dist/safe-bash/command-chunks/chunk-SSRGI476.js +116 -0
  212. package/dist/safe-bash/command-chunks/chunk-SUUD352U.js +127 -0
  213. package/dist/safe-bash/command-chunks/{chunk-B5F2KQYA.js → chunk-SWUVHT7G.js} +1 -1
  214. package/dist/safe-bash/command-chunks/chunk-TBAH4XGI.js +38 -0
  215. package/dist/safe-bash/command-chunks/chunk-TBVWTZTR.js +469 -0
  216. package/dist/safe-bash/command-chunks/chunk-TGHQGJNR.js +144 -0
  217. package/dist/safe-bash/command-chunks/{chunk-Q6JLT2EY.js → chunk-TL3KDYEM.js} +8 -110
  218. package/dist/safe-bash/command-chunks/chunk-TVAEX4WQ.js +473 -0
  219. package/dist/safe-bash/command-chunks/chunk-TZ2J6LGM.js +163 -0
  220. package/dist/safe-bash/command-chunks/chunk-UICO7H6S.js +186 -0
  221. package/dist/safe-bash/command-chunks/chunk-UJTJFMIN.js +501 -0
  222. package/dist/safe-bash/command-chunks/chunk-UMWWCLBG.js +109 -0
  223. package/dist/safe-bash/command-chunks/chunk-UPXFSGQG.js +134 -0
  224. package/dist/safe-bash/command-chunks/chunk-UWUYSXYT.js +272 -0
  225. package/dist/safe-bash/command-chunks/{chunk-5FMXQUDY.js → chunk-UZOGSYJP.js} +1 -1
  226. package/dist/safe-bash/command-chunks/chunk-V3RGA5PS.js +125 -0
  227. package/dist/safe-bash/command-chunks/chunk-VEUQWV2V.js +287 -0
  228. package/dist/safe-bash/command-chunks/chunk-VGKYTZT5.js +161 -0
  229. package/dist/safe-bash/command-chunks/chunk-VQUEIEVP.js +410 -0
  230. package/dist/safe-bash/command-chunks/chunk-VU3YUC3U.js +169 -0
  231. package/dist/safe-bash/command-chunks/chunk-W32KW66B.js +27 -0
  232. package/dist/safe-bash/command-chunks/chunk-W543LSYH.js +899 -0
  233. package/dist/safe-bash/command-chunks/chunk-W5YFDYHO.js +387 -0
  234. package/dist/safe-bash/command-chunks/chunk-W6DV2CLS.js +267 -0
  235. package/dist/safe-bash/command-chunks/chunk-WAKYUXVQ.js +215 -0
  236. package/dist/safe-bash/command-chunks/chunk-WGOL3MM6.js +125 -0
  237. package/dist/safe-bash/command-chunks/{chunk-N2A7V3WY.js → chunk-WHNYT34N.js} +3 -3
  238. package/dist/safe-bash/command-chunks/chunk-WOZCIRJ5.js +169 -0
  239. package/dist/safe-bash/command-chunks/chunk-WVB6ONZS.js +232 -0
  240. package/dist/safe-bash/command-chunks/chunk-WVESNAND.js +25 -0
  241. package/dist/safe-bash/command-chunks/chunk-XDEA3TL5.js +322 -0
  242. package/dist/safe-bash/command-chunks/chunk-XFEUWSYG.js +357 -0
  243. package/dist/safe-bash/command-chunks/chunk-XFMJ4RMS.js +2849 -0
  244. package/dist/safe-bash/command-chunks/chunk-XH6DXJHX.js +196 -0
  245. package/dist/safe-bash/command-chunks/chunk-XNJ67APB.js +6 -0
  246. package/dist/safe-bash/command-chunks/chunk-XP6BHGZ6.js +227 -0
  247. package/dist/safe-bash/command-chunks/chunk-XXFHTGV2.js +142 -0
  248. package/dist/safe-bash/command-chunks/chunk-Y5GI5PVT.js +139 -0
  249. package/dist/safe-bash/command-chunks/chunk-Y6KHC3JB.js +177 -0
  250. package/dist/safe-bash/command-chunks/{chunk-2UWPMSME.js → chunk-Y72LPXST.js} +8 -8
  251. package/dist/safe-bash/command-chunks/chunk-YDRWQZNB.js +69 -0
  252. package/dist/safe-bash/command-chunks/{chunk-P4OJBL2B.js → chunk-YFZ6FPIC.js} +1 -1
  253. package/dist/safe-bash/command-chunks/chunk-YH4DC4RP.js +171 -0
  254. package/dist/safe-bash/command-chunks/chunk-YH7KKMMN.js +463 -0
  255. package/dist/safe-bash/command-chunks/{chunk-MN3BB4WW.js → chunk-YP3WWV5N.js} +4 -4
  256. package/dist/safe-bash/command-chunks/chunk-YPVBU7QF.js +2817 -0
  257. package/dist/safe-bash/command-chunks/chunk-YQYVEVUE.js +1621 -0
  258. package/dist/safe-bash/command-chunks/chunk-YRNBIU5U.js +175 -0
  259. package/dist/safe-bash/command-chunks/chunk-Z7ESJVFP.js +10 -0
  260. package/dist/safe-bash/command-chunks/chunk-ZTAFAHY3.js +653 -0
  261. package/dist/safe-bash/command-chunks/chunk-ZXKOMB24.js +85 -0
  262. package/dist/safe-bash/command-chunks/{clipboard-XCSQACOK-SHFXT53F.js → clipboard-6SDGQGC3-TVJ3CG7A.js} +4 -4
  263. package/dist/safe-bash/command-chunks/{command-engine-4TEGTXCQ.js → command-engine-KMLHVFMA.js} +356 -316
  264. package/dist/safe-bash/command-chunks/{engine-QDC5VCGO-LYAAFESF.js → engine-EOYR2WTY-KUFLFTDE.js} +2 -4
  265. package/dist/safe-bash/command-chunks/{gnumeric-OCFH63UT-YI7SG7TN.js → gnumeric-ABKSRBZJ-MPIIPXKP.js} +3 -3
  266. package/dist/safe-bash/command-chunks/inspection-command-ULEU7ZVV.js +7 -0
  267. package/dist/safe-bash/command-chunks/model-store-JUFU3RSW.js +54 -0
  268. package/dist/safe-bash/command-chunks/pdf-22JDKKAR-UDWNSWYB.js +338 -0
  269. package/dist/safe-bash/command-chunks/{pptx-XG3YSXWZ-XAG36NAB.js → pptx-YDKHIGCD-H7FU4VMJ.js} +2 -2
  270. package/dist/safe-bash/commands/bc/index.browser.js +2 -2
  271. package/dist/safe-bash/commands/diffpdf/index.d.ts +2 -0
  272. package/dist/safe-bash/commands/diffpdf/index.js +2 -0
  273. package/dist/safe-bash/commands/dot/index.d.ts +2 -0
  274. package/dist/safe-bash/commands/dot/index.js +2 -0
  275. package/dist/safe-bash/commands/llm/collections.browser.js +6 -0
  276. package/dist/safe-bash/commands/llm/collections.d.ts +2 -0
  277. package/dist/safe-bash/commands/llm/collections.js +2 -0
  278. package/dist/safe-bash/commands/pandoc/index.browser.js +1 -1
  279. package/dist/safe-bash/commands/rsvg-convert/index.d.ts +2 -0
  280. package/dist/safe-bash/commands/rsvg-convert/index.js +2 -0
  281. package/dist/safe-bash/commands/safejs/io.d.ts +1 -1
  282. package/dist/safe-bash/commands/safejs/io.js +1 -1
  283. package/dist/safe-bash/commands/safejs/options.d.ts +1 -1
  284. package/dist/safe-bash/commands/safejs/options.js +1 -1
  285. package/dist/safe-bash/commands/safejs/render.d.ts +1 -1
  286. package/dist/safe-bash/commands/safejs/render.js +1 -1
  287. package/dist/safe-bash/commands/safejs/runtime.d.ts +1 -1
  288. package/dist/safe-bash/commands/safejs/runtime.js +1 -1
  289. package/dist/safe-bash/commands/safejs/types.d.ts +1 -1
  290. package/dist/safe-bash/commands/safejs/types.js +1 -1
  291. package/dist/safe-bash/commands/wdiff/index.d.ts +2 -0
  292. package/dist/safe-bash/commands/wdiff/index.js +2 -0
  293. package/dist/safe-bash/core.d.ts +4 -0
  294. package/dist/safe-bash/core.js +4 -0
  295. package/dist/safe-bash/full-core.browser.js +59 -35
  296. package/dist/safe-bash/optional-host.browser.js +7 -7
  297. package/dist/safe-bash/plugins/index.browser.js +7 -7
  298. package/dist/safe-bash/registry-entry.browser.js +6 -6
  299. package/dist/safe-bash/search.browser.js +2 -2
  300. package/dist/safe-bash/shell-entry.browser.js +3 -3
  301. package/dist/safe-bash-checksum-engine/index.js +83 -40
  302. package/dist/safe-bash-checksum-engine/md5.d.ts +2 -0
  303. package/dist/safe-bash-checksum-engine/md5.js +7 -0
  304. package/dist/safe-bash-command-awk/awk-inspection.js +2 -2
  305. package/dist/safe-bash-command-awk/awk-runtime.js +2 -2
  306. package/dist/safe-bash-command-awk/awk.js +7 -7
  307. package/dist/safe-bash-command-awk/index.js +7 -7
  308. package/dist/safe-bash-command-chmod/command.js +1 -1
  309. package/dist/safe-bash-command-chmod/index.js +1 -1
  310. package/dist/safe-bash-command-csvkit/index.js +6 -6
  311. package/dist/safe-bash-command-diff/index.js +3 -3
  312. package/dist/safe-bash-command-diffpdf/LICENSE +21 -0
  313. package/dist/safe-bash-command-diffpdf/index.d.ts +12 -0
  314. package/dist/safe-bash-command-diffpdf/index.js +107 -0
  315. package/dist/safe-bash-command-docx/command.d.ts +36 -0
  316. package/dist/{safe-bash-docx-engine → safe-bash-command-docx}/discovery.d.ts +4 -4
  317. package/dist/safe-bash-command-docx/index.js +1 -1
  318. package/dist/{safe-bash-docx-engine → safe-bash-command-docx}/inspection-command.d.ts +6 -6
  319. package/dist/safe-bash-command-docx/sdk.d.ts +4 -0
  320. package/dist/safe-bash-command-docx/sdk.js +24 -0
  321. package/dist/safe-bash-command-dot/LICENSE +21 -0
  322. package/dist/safe-bash-command-dot/index.d.ts +14 -0
  323. package/dist/safe-bash-command-dot/index.js +1298 -0
  324. package/dist/safe-bash-command-du/arguments.d.ts +1 -1
  325. package/dist/safe-bash-command-du/arguments.js +1 -1
  326. package/dist/safe-bash-command-du/du.js +2 -2
  327. package/dist/safe-bash-command-du/index.js +2 -2
  328. package/dist/safe-bash-command-factor/command.js +2 -2
  329. package/dist/safe-bash-command-factor/index.js +2 -2
  330. package/dist/safe-bash-command-ffmpeg/index.js +16 -16
  331. package/dist/safe-bash-command-imagemagick/index.js +21 -53
  332. package/dist/safe-bash-command-llm/collections-embed.d.ts +23 -0
  333. package/dist/safe-bash-command-llm/collections.d.ts +38 -0
  334. package/dist/safe-bash-command-llm/collections.js +423 -0
  335. package/dist/safe-bash-command-llm/command.js +4 -2
  336. package/dist/safe-bash-command-llm/index.js +12 -8
  337. package/dist/safe-bash-command-llm/openai.js +4 -3
  338. package/dist/safe-bash-command-llm/providers/index.js +6 -4
  339. package/dist/safe-bash-command-llm/providers/openai.js +4 -3
  340. package/dist/safe-bash-command-node/commands/node/browser.js +9 -12
  341. package/dist/safe-bash-command-node/commands/node/buffer.js +2 -2
  342. package/dist/safe-bash-command-node/commands/node/default-runtime.js +9 -12
  343. package/dist/safe-bash-command-node/commands/node/filesystem.js +3 -3
  344. package/dist/safe-bash-command-node/commands/node/safejs.js +9 -12
  345. package/dist/safe-bash-command-node/commands/node/source-maps.js +2 -2
  346. package/dist/safe-bash-command-node/commands/node/timers.js +3 -3
  347. package/dist/safe-bash-command-node/commands/safejs/io.d.ts +1 -35
  348. package/dist/safe-bash-command-node/commands/safejs/io.js +3 -7
  349. package/dist/safe-bash-command-node/commands/safejs/options.d.ts +2 -22
  350. package/dist/safe-bash-command-node/commands/safejs/options.js +1 -1
  351. package/dist/safe-bash-command-node/commands/safejs/render.d.ts +1 -1
  352. package/dist/safe-bash-command-node/commands/safejs/render.js +3 -5
  353. package/dist/safe-bash-command-node/commands/safejs/runtime.d.ts +2 -25
  354. package/dist/safe-bash-command-node/commands/safejs/runtime.js +1 -7
  355. package/dist/safe-bash-command-node/commands/safejs/types.d.ts +2 -85
  356. package/dist/safe-bash-command-node/commands/safejs/types.js +1 -1
  357. package/dist/safe-bash-command-node/integrations/safejs/filesystem.d.ts +2 -5
  358. package/dist/safe-bash-command-node/integrations/safejs/filesystem.js +3 -3
  359. package/dist/safe-bash-command-node/integrations/safejs/shell.js +1 -1
  360. package/dist/safe-bash-command-node/integrations/safejs/values.d.ts +1 -7
  361. package/dist/safe-bash-command-node/integrations/safejs/values.js +1 -1
  362. package/dist/safe-bash-command-openssl/index.js +15452 -420
  363. package/dist/safe-bash-command-pandoc/command.js +1 -1
  364. package/dist/safe-bash-command-pandoc/index.js +1 -1
  365. package/dist/safe-bash-command-patch/index.js +5 -5
  366. package/dist/safe-bash-command-patch/patch.js +4 -4
  367. package/dist/safe-bash-command-playwright-cli/index.js +25 -25
  368. package/dist/safe-bash-command-playwright-cli/playwright/abilities.js +8 -8
  369. package/dist/safe-bash-command-playwright-cli/playwright/controller.js +16 -16
  370. package/dist/safe-bash-command-playwright-cli/playwright/index.js +25 -25
  371. package/dist/safe-bash-command-playwright-cli/playwright/standard-capabilities.js +4 -4
  372. package/dist/{safe-bash-pptx-engine → safe-bash-command-pptx}/command-engine.d.ts +5 -13
  373. package/dist/safe-bash-command-pptx/engine.d.ts +4 -0
  374. package/dist/safe-bash-command-pptx/engine.js +37 -0
  375. package/dist/safe-bash-command-pptx/index.js +1 -1
  376. package/dist/safe-bash-command-python/executor.js +15 -15
  377. package/dist/safe-bash-command-python/index.js +15 -15
  378. package/dist/safe-bash-command-python/jspi.js +4 -4
  379. package/dist/safe-bash-command-qrencode/index.js +1 -4
  380. package/dist/safe-bash-command-rsvg-convert/LICENSE +21 -0
  381. package/dist/safe-bash-command-rsvg-convert/index.d.ts +13 -0
  382. package/dist/safe-bash-command-rsvg-convert/index.js +84 -0
  383. package/dist/safe-bash-command-safejs/LICENSE +21 -0
  384. package/dist/safe-bash-command-safejs/filesystem.d.ts +5 -0
  385. package/dist/safe-bash-command-safejs/filesystem.js +7 -0
  386. package/dist/safe-bash-command-safejs/index.d.ts +4 -0
  387. package/dist/safe-bash-command-safejs/index.js +19 -0
  388. package/dist/safe-bash-command-safejs/io.d.ts +35 -0
  389. package/dist/safe-bash-command-safejs/io.js +12 -0
  390. package/dist/safe-bash-command-safejs/options.d.ts +22 -0
  391. package/dist/safe-bash-command-safejs/options.js +11 -0
  392. package/dist/safe-bash-command-safejs/render.d.ts +1 -0
  393. package/dist/safe-bash-command-safejs/render.js +9 -0
  394. package/dist/safe-bash-command-safejs/runtime.d.ts +25 -0
  395. package/dist/safe-bash-command-safejs/runtime.js +13 -0
  396. package/dist/safe-bash-command-safejs/types.d.ts +85 -0
  397. package/dist/safe-bash-command-safejs/types.js +7 -0
  398. package/dist/safe-bash-command-safejs/values.d.ts +7 -0
  399. package/dist/safe-bash-command-safejs/values.js +19 -0
  400. package/dist/safe-bash-command-sips/index.js +1 -14
  401. package/dist/safe-bash-command-ssconvert/index.js +413 -546
  402. package/dist/safe-bash-command-ssconvert/rendering/chart/axis.d.ts +1 -26
  403. package/dist/safe-bash-command-ssconvert/rendering/chart/error-bar.d.ts +1 -39
  404. package/dist/safe-bash-command-ssconvert/rendering/chart/layout.d.ts +1 -24
  405. package/dist/safe-bash-command-ssconvert/rendering/chart/line.d.ts +1 -23
  406. package/dist/safe-bash-command-ssconvert/rendering/chart/marker.d.ts +1 -35
  407. package/dist/safe-bash-command-ssconvert/rendering/chart/pie.d.ts +1 -32
  408. package/dist/safe-bash-command-ssconvert/rendering/images/index.d.ts +1 -26
  409. package/dist/safe-bash-command-ssconvert/rendering/print/header-footer.d.ts +1 -16
  410. package/dist/safe-bash-command-ssconvert/rendering/print/layout.d.ts +1 -65
  411. package/dist/safe-bash-command-ssconvert/rendering/print/pagination.d.ts +1 -34
  412. package/dist/safe-bash-command-tar/create.js +4 -4
  413. package/dist/safe-bash-command-tar/extract.js +4 -4
  414. package/dist/safe-bash-command-tar/index.js +16 -14
  415. package/dist/safe-bash-command-tar/modes.js +6 -6
  416. package/dist/safe-bash-command-tar/options.d.ts +3 -1
  417. package/dist/safe-bash-command-tar/options.js +1 -1
  418. package/dist/safe-bash-command-unzip/index.js +4 -4
  419. package/dist/safe-bash-command-wdiff/LICENSE +21 -0
  420. package/dist/safe-bash-command-wdiff/index.d.ts +12 -0
  421. package/dist/safe-bash-command-wdiff/index.js +123 -0
  422. package/dist/safe-bash-compression-engine/bounded-codec.js +2 -2
  423. package/dist/safe-bash-compression-engine/codec-loader.js +1 -1
  424. package/dist/safe-bash-compression-engine/files.js +5 -5
  425. package/dist/safe-bash-compression-engine/index.js +4 -4
  426. package/dist/safe-bash-compression-engine/operand.js +5 -5
  427. package/dist/safe-bash-compression-engine/stream.js +4 -4
  428. package/dist/safe-bash-compression-engine/zstd-decode.js +3 -3
  429. package/dist/safe-bash-contracts/escaping.js +2 -2
  430. package/dist/safe-bash-contracts/index.js +15 -15
  431. package/dist/safe-bash-docx-engine/admission.js +31 -0
  432. package/dist/safe-bash-docx-engine/ancillary-resources.js +38 -0
  433. package/dist/safe-bash-docx-engine/archive.js +24 -0
  434. package/dist/safe-bash-docx-engine/argument-json.js +25 -0
  435. package/dist/safe-bash-docx-engine/batch-operations.d.ts +7 -0
  436. package/dist/safe-bash-docx-engine/batch-operations.js +95 -0
  437. package/dist/safe-bash-docx-engine/batch-result-schema.d.ts +2 -0
  438. package/dist/safe-bash-docx-engine/batch-result-schema.js +145 -0
  439. package/dist/safe-bash-docx-engine/batch.js +106 -0
  440. package/dist/safe-bash-docx-engine/bookmarks.js +43 -0
  441. package/dist/safe-bash-docx-engine/budget.js +18 -0
  442. package/dist/safe-bash-docx-engine/charts.js +35 -0
  443. package/dist/safe-bash-docx-engine/command-option-rules.d.ts +1 -0
  444. package/dist/safe-bash-docx-engine/command-option-rules.js +24 -0
  445. package/dist/safe-bash-docx-engine/command-properties.d.ts +1 -0
  446. package/dist/safe-bash-docx-engine/command-properties.js +18 -0
  447. package/dist/safe-bash-docx-engine/command-selection.d.ts +1 -0
  448. package/dist/safe-bash-docx-engine/command-selection.js +15 -0
  449. package/dist/safe-bash-docx-engine/comments.js +53 -0
  450. package/dist/safe-bash-docx-engine/control-bindings.js +45 -0
  451. package/dist/safe-bash-docx-engine/control-repeat.js +46 -0
  452. package/dist/safe-bash-docx-engine/controls.js +52 -0
  453. package/dist/safe-bash-docx-engine/create.js +36 -0
  454. package/dist/safe-bash-docx-engine/diagrams.js +43 -0
  455. package/dist/safe-bash-docx-engine/diff.js +33 -0
  456. package/dist/safe-bash-docx-engine/discovery-result-schema.d.ts +72 -0
  457. package/dist/safe-bash-docx-engine/discovery-result-schema.js +36 -0
  458. package/dist/safe-bash-docx-engine/document-properties.js +43 -0
  459. package/dist/safe-bash-docx-engine/equations.js +53 -0
  460. package/dist/safe-bash-docx-engine/extract.js +40 -0
  461. package/dist/safe-bash-docx-engine/fields.js +48 -0
  462. package/dist/safe-bash-docx-engine/font-inventory.js +40 -0
  463. package/dist/safe-bash-docx-engine/font-resources.js +33 -0
  464. package/dist/safe-bash-docx-engine/image-batch-operations.d.ts +4 -0
  465. package/dist/safe-bash-docx-engine/image-batch-operations.js +35 -0
  466. package/dist/safe-bash-docx-engine/image-insertion.js +46 -0
  467. package/dist/safe-bash-docx-engine/image-layout.js +43 -0
  468. package/dist/safe-bash-docx-engine/image-replacement.js +48 -0
  469. package/dist/safe-bash-docx-engine/images.js +49 -0
  470. package/dist/safe-bash-docx-engine/index.d.ts +1 -3
  471. package/dist/safe-bash-docx-engine/index.js +369 -19350
  472. package/dist/safe-bash-docx-engine/inspection.js +49 -0
  473. package/dist/safe-bash-docx-engine/invocation.d.ts +50 -0
  474. package/dist/safe-bash-docx-engine/invocation.js +66 -0
  475. package/dist/safe-bash-docx-engine/io-errors.js +11 -0
  476. package/dist/safe-bash-docx-engine/io.js +29 -0
  477. package/dist/safe-bash-docx-engine/links.js +47 -0
  478. package/dist/safe-bash-docx-engine/lists.js +46 -0
  479. package/dist/safe-bash-docx-engine/location-token.js +27 -0
  480. package/dist/safe-bash-docx-engine/locations.js +39 -0
  481. package/dist/safe-bash-docx-engine/model-context.js +15 -0
  482. package/dist/safe-bash-docx-engine/model-errors.js +13 -0
  483. package/dist/safe-bash-docx-engine/notes.js +48 -0
  484. package/dist/safe-bash-docx-engine/objects.js +49 -0
  485. package/dist/safe-bash-docx-engine/operation-json-schema.js +21 -0
  486. package/dist/safe-bash-docx-engine/operation-schema.js +29 -0
  487. package/dist/safe-bash-docx-engine/pack-uri-batch-operations.d.ts +3 -0
  488. package/dist/safe-bash-docx-engine/pack-uri-batch-operations.js +15 -0
  489. package/dist/safe-bash-docx-engine/pack.js +38 -0
  490. package/dist/safe-bash-docx-engine/package-view-batch-operations.d.ts +4 -0
  491. package/dist/safe-bash-docx-engine/package-view-batch-operations.js +47 -0
  492. package/dist/safe-bash-docx-engine/package-xml.js +25 -0
  493. package/dist/safe-bash-docx-engine/pandoc-adapter.js +55 -6
  494. package/dist/safe-bash-docx-engine/paragraph-edit.js +52 -0
  495. package/dist/safe-bash-docx-engine/part-provider.js +18 -0
  496. package/dist/safe-bash-docx-engine/property-values.js +46 -0
  497. package/dist/safe-bash-docx-engine/publication.js +40 -0
  498. package/dist/safe-bash-docx-engine/removal.js +44 -0
  499. package/dist/safe-bash-docx-engine/revision-decisions.js +46 -0
  500. package/dist/safe-bash-docx-engine/revision-edit.js +43 -0
  501. package/dist/safe-bash-docx-engine/revisions.js +42 -0
  502. package/dist/safe-bash-docx-engine/run-format.js +43 -0
  503. package/dist/safe-bash-docx-engine/sanitize.js +59 -0
  504. package/dist/safe-bash-docx-engine/sections.js +47 -0
  505. package/dist/safe-bash-docx-engine/settings.js +36 -0
  506. package/dist/safe-bash-docx-engine/shape-edit.js +47 -0
  507. package/dist/safe-bash-docx-engine/signatures.js +42 -0
  508. package/dist/safe-bash-docx-engine/simple-selection.d.ts +1 -1
  509. package/dist/safe-bash-docx-engine/stories.js +48 -0
  510. package/dist/safe-bash-docx-engine/structure-model-batch-operations.d.ts +3 -0
  511. package/dist/safe-bash-docx-engine/structure-model-batch-operations.js +64 -0
  512. package/dist/safe-bash-docx-engine/style-model-batch-operations.js +57 -0
  513. package/dist/safe-bash-docx-engine/style-model-result-schema.d.ts +4 -0
  514. package/dist/safe-bash-docx-engine/style-model-result-schema.js +76 -0
  515. package/dist/safe-bash-docx-engine/styles.js +44 -0
  516. package/dist/safe-bash-docx-engine/table-edit.js +52 -0
  517. package/dist/safe-bash-docx-engine/table-read.js +38 -0
  518. package/dist/safe-bash-docx-engine/template.js +45 -0
  519. package/dist/safe-bash-docx-engine/text-replace.js +47 -0
  520. package/dist/safe-bash-docx-engine/text-resource-read.js +42 -0
  521. package/dist/safe-bash-docx-engine/text.js +36 -0
  522. package/dist/safe-bash-docx-engine/validation.js +30 -0
  523. package/dist/safe-bash-docx-engine/xml-parts.js +48 -0
  524. package/dist/safe-bash-markdown-engine/index.js +3 -3
  525. package/dist/safe-bash-network-engine/aggregate.js +3 -3
  526. package/dist/safe-bash-network-engine/args.js +3 -3
  527. package/dist/safe-bash-network-engine/body.js +4 -4
  528. package/dist/safe-bash-network-engine/decode.js +3 -3
  529. package/dist/safe-bash-network-engine/fetch-transport.js +3 -3
  530. package/dist/safe-bash-network-engine/index.js +3 -3
  531. package/dist/safe-bash-network-engine/output.js +3 -3
  532. package/dist/safe-bash-network-engine/platform-portable.js +3 -3
  533. package/dist/safe-bash-network-engine/shared.js +2 -2
  534. package/dist/safe-bash-network-engine/transfer.js +20 -20
  535. package/dist/safe-bash-pptx-engine/bytes.d.ts +1 -4
  536. package/dist/safe-bash-pptx-engine/bytes.js +2 -11
  537. package/dist/safe-bash-pptx-engine/index.d.ts +1 -103
  538. package/dist/safe-bash-pptx-engine/index.js +1 -662
  539. package/dist/safe-bash-presentation-engine/LICENSE +21 -0
  540. package/dist/safe-bash-presentation-engine/accessibility.js +43 -0
  541. package/dist/safe-bash-presentation-engine/animation-editing.js +29 -0
  542. package/dist/safe-bash-presentation-engine/animations.js +23 -0
  543. package/dist/safe-bash-presentation-engine/backgrounds.js +26 -0
  544. package/dist/safe-bash-presentation-engine/bytes.d.ts +4 -0
  545. package/dist/safe-bash-presentation-engine/bytes.js +13 -0
  546. package/dist/safe-bash-presentation-engine/chart-editing.js +60 -0
  547. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/chart-enums.d.ts +2 -2
  548. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/chart-object-operations.d.ts +1 -1
  549. package/dist/safe-bash-presentation-engine/chart-object-operations.js +35 -0
  550. package/dist/safe-bash-presentation-engine/charts.js +41 -0
  551. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/color-enums.d.ts +5 -5
  552. package/dist/safe-bash-presentation-engine/command-placeholder.js +64 -0
  553. package/dist/safe-bash-presentation-engine/comments.js +32 -0
  554. package/dist/safe-bash-presentation-engine/connector-operations.js +50 -0
  555. package/dist/safe-bash-presentation-engine/connectors.js +49 -0
  556. package/dist/safe-bash-presentation-engine/content-types.js +9 -0
  557. package/dist/safe-bash-presentation-engine/contracts.js +0 -0
  558. package/dist/safe-bash-presentation-engine/creation.js +15 -0
  559. package/dist/safe-bash-presentation-engine/diff.js +40 -0
  560. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/drawing-enums.d.ts +20 -20
  561. package/dist/safe-bash-presentation-engine/drawing-format.js +44 -0
  562. package/dist/safe-bash-presentation-engine/drawing-operations.js +41 -0
  563. package/dist/safe-bash-presentation-engine/drawing-schema.d.ts +1549 -0
  564. package/dist/safe-bash-presentation-engine/drawing-schema.js +33 -0
  565. package/dist/safe-bash-presentation-engine/equations.js +30 -0
  566. package/dist/safe-bash-presentation-engine/errors.js +23 -0
  567. package/dist/safe-bash-presentation-engine/fields.js +32 -0
  568. package/dist/safe-bash-presentation-engine/font-metrics.js +12 -0
  569. package/dist/safe-bash-presentation-engine/image-extraction.js +29 -0
  570. package/dist/safe-bash-presentation-engine/image-formatting.js +43 -0
  571. package/dist/safe-bash-presentation-engine/image-insertion.js +26 -0
  572. package/dist/safe-bash-presentation-engine/image-metadata.d.ts +9 -0
  573. package/dist/safe-bash-presentation-engine/image-metadata.js +9 -0
  574. package/dist/safe-bash-presentation-engine/image-replacement.js +30 -0
  575. package/dist/safe-bash-presentation-engine/image-value.js +15 -0
  576. package/dist/safe-bash-presentation-engine/images.js +30 -0
  577. package/dist/safe-bash-presentation-engine/index.d.ts +100 -0
  578. package/dist/safe-bash-presentation-engine/index.js +791 -0
  579. package/dist/safe-bash-presentation-engine/layouts.js +31 -0
  580. package/dist/safe-bash-presentation-engine/length.js +21 -0
  581. package/dist/safe-bash-presentation-engine/links.js +33 -0
  582. package/dist/safe-bash-presentation-engine/masters.js +54 -0
  583. package/dist/safe-bash-presentation-engine/media-editing.js +35 -0
  584. package/dist/safe-bash-presentation-engine/media-extraction.js +24 -0
  585. package/dist/safe-bash-presentation-engine/media.js +23 -0
  586. package/dist/safe-bash-presentation-engine/memberships.js +24 -0
  587. package/dist/safe-bash-presentation-engine/notes.js +27 -0
  588. package/dist/safe-bash-presentation-engine/ole-enum.js +10 -0
  589. package/dist/safe-bash-presentation-engine/ole-insertion.js +29 -0
  590. package/dist/safe-bash-presentation-engine/opaque-objects.js +21 -0
  591. package/dist/safe-bash-presentation-engine/package-reader.js +13 -0
  592. package/dist/safe-bash-presentation-engine/package-tools.js +25 -0
  593. package/dist/safe-bash-presentation-engine/package-uri.d.ts +13 -0
  594. package/dist/safe-bash-presentation-engine/package-uri.js +16 -0
  595. package/dist/safe-bash-presentation-engine/package-writer.js +13 -0
  596. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/presentation-model.d.ts +1 -1
  597. package/dist/safe-bash-presentation-engine/presentation-model.js +63 -0
  598. package/dist/safe-bash-presentation-engine/presentation-settings.js +25 -0
  599. package/dist/safe-bash-presentation-engine/properties.js +37 -0
  600. package/dist/safe-bash-presentation-engine/publication.d.ts +10 -0
  601. package/dist/safe-bash-presentation-engine/publication.js +0 -0
  602. package/dist/safe-bash-presentation-engine/relationships.js +16 -0
  603. package/dist/safe-bash-presentation-engine/resource-limits.js +8 -0
  604. package/dist/safe-bash-presentation-engine/sanitize.js +24 -0
  605. package/dist/safe-bash-presentation-engine/selector-schema.js +7 -0
  606. package/dist/safe-bash-presentation-engine/selectors.js +26 -0
  607. package/dist/safe-bash-presentation-engine/shape-groups.js +47 -0
  608. package/dist/safe-bash-presentation-engine/shape-operations.js +48 -0
  609. package/dist/safe-bash-presentation-engine/shape-path-operations.js +44 -0
  610. package/dist/safe-bash-presentation-engine/shape-paths.js +31 -0
  611. package/dist/safe-bash-presentation-engine/shape-presets.js +11 -0
  612. package/dist/safe-bash-presentation-engine/shape-selection.js +43 -0
  613. package/dist/safe-bash-presentation-engine/shape-transforms.js +28 -0
  614. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/shape-types.d.ts +1 -1
  615. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/shapes.d.ts +1 -1
  616. package/dist/safe-bash-presentation-engine/shapes.js +66 -0
  617. package/dist/safe-bash-presentation-engine/slide-copy.js +24 -0
  618. package/dist/safe-bash-presentation-engine/slide-import.js +27 -0
  619. package/dist/safe-bash-presentation-engine/slide-merge-split.js +33 -0
  620. package/dist/safe-bash-presentation-engine/slide-model.js +74 -0
  621. package/dist/safe-bash-presentation-engine/slide-removal.js +25 -0
  622. package/dist/safe-bash-presentation-engine/slide-transfer-budget.js +17 -0
  623. package/dist/safe-bash-presentation-engine/slides.js +26 -0
  624. package/dist/safe-bash-presentation-engine/table-operations.js +51 -0
  625. package/dist/safe-bash-presentation-engine/table-spans.js +42 -0
  626. package/dist/safe-bash-presentation-engine/tables.js +45 -0
  627. package/dist/safe-bash-presentation-engine/tags.js +25 -0
  628. package/dist/safe-bash-presentation-engine/template-bindings.js +44 -0
  629. package/dist/safe-bash-presentation-engine/template-repeat.js +51 -0
  630. package/dist/safe-bash-presentation-engine/text-fitting.js +39 -0
  631. package/dist/safe-bash-presentation-engine/text-frames.js +52 -0
  632. package/dist/safe-bash-presentation-engine/text-paragraphs.js +58 -0
  633. package/dist/safe-bash-presentation-engine/text-reading.js +23 -0
  634. package/dist/safe-bash-presentation-engine/text-replacement.js +24 -0
  635. package/dist/safe-bash-presentation-engine/text-runs.js +45 -0
  636. package/dist/safe-bash-presentation-engine/themes.js +31 -0
  637. package/dist/safe-bash-presentation-engine/transitions.js +27 -0
  638. package/dist/safe-bash-presentation-engine/validation.js +14 -0
  639. package/dist/safe-bash-presentation-engine/xml-parts.js +25 -0
  640. package/dist/safe-bash-presentation-engine/xml-view.js +8 -0
  641. package/dist/safe-bash-presentation-engine/xml.js +8 -0
  642. package/dist/safe-bash-sqlite-engine/sqlite-edit-snapshot.d.ts +15 -0
  643. package/dist/safe-bash-sqlite-engine/sqlite-finalization.d.ts +7 -0
  644. package/dist/safe-bash-sqlite-engine/sqlite-pages.d.ts +18 -0
  645. package/dist/safe-bash-sqlite-engine/sqlite-record-read.d.ts +8 -0
  646. package/dist/safe-bash-sqlite-engine/sqlite-record-write.d.ts +20 -0
  647. package/dist/safe-bash-sqlite-engine/storage.d.ts +2 -0
  648. package/dist/safe-bash-sqlite-engine/storage.js +236 -55
  649. package/dist/safe-bash-svg-engine/LICENSE +21 -0
  650. package/dist/safe-bash-svg-engine/index.d.ts +8 -0
  651. package/dist/safe-bash-svg-engine/index.js +477 -0
  652. package/dist/safe-bash-zip-engine/index.js +3 -3
  653. package/dist/safe-bash-zip-engine/zip/repair.js +3 -3
  654. package/dist/safe-bash-zip-engine/zip/sfx.js +3 -3
  655. package/dist/safe-bash-zip-engine/zip-format.js +3 -3
  656. package/dist/safe-playwright-cloudflare/browser-provider.generated.js +55 -18
  657. package/dist/safe-playwright-cloudflare/browser-run-code-guest.generated.js +1 -1
  658. package/dist/spreadsheet-engine/datasource.js +4 -1
  659. package/dist/spreadsheet-engine/formulas/functions/math.js +3 -1
  660. package/dist/spreadsheet-engine/rendering/chart/axis.d.ts +26 -0
  661. package/dist/spreadsheet-engine/rendering/chart/axis.js +61 -0
  662. package/dist/spreadsheet-engine/rendering/chart/error-bar.d.ts +39 -0
  663. package/dist/spreadsheet-engine/rendering/chart/error-bar.js +59 -0
  664. package/dist/spreadsheet-engine/rendering/chart/layout.d.ts +24 -0
  665. package/dist/spreadsheet-engine/rendering/chart/layout.js +54 -0
  666. package/dist/spreadsheet-engine/rendering/chart/line.d.ts +23 -0
  667. package/dist/spreadsheet-engine/rendering/chart/line.js +56 -0
  668. package/dist/spreadsheet-engine/rendering/chart/marker.d.ts +35 -0
  669. package/dist/spreadsheet-engine/rendering/chart/marker.js +52 -0
  670. package/dist/spreadsheet-engine/rendering/chart/pie.d.ts +32 -0
  671. package/dist/spreadsheet-engine/rendering/chart/pie.js +47 -0
  672. package/dist/{safe-bash-command-ssconvert → spreadsheet-engine}/rendering/images/codecs.d.ts +0 -1
  673. package/dist/spreadsheet-engine/rendering/images/codecs.js +253 -0
  674. package/dist/spreadsheet-engine/rendering/images/index.d.ts +26 -0
  675. package/dist/spreadsheet-engine/rendering/images/index.js +144 -0
  676. package/dist/spreadsheet-engine/rendering/images/profile-raster.d.ts +4 -0
  677. package/dist/spreadsheet-engine/rendering/images/profile-raster.js +72 -0
  678. package/dist/spreadsheet-engine/rendering/images/scene.d.ts +3 -0
  679. package/dist/spreadsheet-engine/rendering/images/scene.js +34 -0
  680. package/dist/spreadsheet-engine/rendering/print/cell-style.d.ts +10 -0
  681. package/dist/spreadsheet-engine/rendering/print/cell-style.js +52 -0
  682. package/dist/spreadsheet-engine/rendering/print/font-normalization-data.d.ts +43 -0
  683. package/dist/spreadsheet-engine/rendering/print/font-normalization-data.js +1558 -0
  684. package/dist/spreadsheet-engine/rendering/print/font-normalization.d.ts +3 -0
  685. package/dist/spreadsheet-engine/rendering/print/font-normalization.js +113 -0
  686. package/dist/spreadsheet-engine/rendering/print/font-shaping.d.ts +18 -0
  687. package/dist/spreadsheet-engine/rendering/print/font-shaping.js +271 -0
  688. package/dist/spreadsheet-engine/rendering/print/harfbuzz/data.d.ts +1 -0
  689. package/dist/spreadsheet-engine/rendering/print/harfbuzz/data.js +2 -0
  690. package/dist/spreadsheet-engine/rendering/print/header-footer.d.ts +16 -0
  691. package/dist/spreadsheet-engine/rendering/print/header-footer.js +92 -0
  692. package/dist/spreadsheet-engine/rendering/print/layout.d.ts +65 -0
  693. package/dist/spreadsheet-engine/rendering/print/layout.js +75 -0
  694. package/dist/spreadsheet-engine/rendering/print/pagination.d.ts +34 -0
  695. package/dist/spreadsheet-engine/rendering/print/pagination.js +126 -0
  696. package/dist/spreadsheet-engine/rendering/print/settings.d.ts +42 -0
  697. package/dist/spreadsheet-engine/rendering/print/settings.js +159 -0
  698. package/dist/spreadsheet-format-xls/biff-metadata.js +3 -3
  699. package/dist/spreadsheet-format-xls/biff-write-metadata.d.ts +1 -1
  700. package/dist/spreadsheet-format-xls/biff-write-metadata.js +20 -3
  701. package/dist/spreadsheet-format-xls/biff-write.js +1 -1
  702. package/package.json +239 -12
  703. package/third-party/spreadsheet-engine/scripts/harfbuzz/README.md +39 -0
  704. package/third-party/spreadsheet-engine/scripts/harfbuzz/allocator.cc +18 -0
  705. package/third-party/spreadsheet-engine/scripts/harfbuzz/build.mjs +94 -0
  706. package/third-party/spreadsheet-engine/scripts/harfbuzz/completion.patch +98 -0
  707. package/third-party/spreadsheet-engine/scripts/harfbuzz/config-override.h +19 -0
  708. package/third-party/spreadsheet-engine/scripts/harfbuzz/exports.json +29 -0
  709. package/third-party/spreadsheet-engine/scripts/harfbuzz/sources.json +274 -0
  710. package/third-party/spreadsheet-engine/scripts/harfbuzz/verify.d.mts +10 -0
  711. package/third-party/spreadsheet-engine/scripts/harfbuzz/verify.mjs +96 -0
  712. package/third-party/spreadsheet-engine/scripts/harfbuzz/verify.test.mjs +60 -0
  713. package/third-party/spreadsheet-engine/src/rendering/images/NOTICE.md +22 -0
  714. package/third-party/spreadsheet-engine/src/rendering/print/NOTICE.md +30 -0
  715. package/third-party/spreadsheet-engine/src/rendering/print/font-normalization-NOTICE.md +64 -0
  716. package/third-party/spreadsheet-engine/src/rendering/print/font-normalization-data.ts +1558 -0
  717. package/third-party/spreadsheet-engine/src/rendering/print/font-normalization.ts +91 -0
  718. package/third-party/spreadsheet-engine/src/rendering/print/harfbuzz/EMSCRIPTEN-LICENSE.txt +102 -0
  719. package/third-party/spreadsheet-engine/src/rendering/print/harfbuzz/HARFBUZZ-LICENSE.txt +42 -0
  720. package/third-party/spreadsheet-engine/src/rendering/print/harfbuzz/LIBCXX-LICENSE.txt +311 -0
  721. package/third-party/spreadsheet-engine/src/rendering/print/harfbuzz/LIBCXXABI-LICENSE.txt +311 -0
  722. package/third-party/spreadsheet-engine/src/rendering/print/harfbuzz/MUSL-LICENSE.txt +193 -0
  723. package/third-party/spreadsheet-engine/src/rendering/print/harfbuzz/NOTICE.md +41 -0
  724. package/third-party/spreadsheet-engine/src/rendering/print/harfbuzz/data.ts +2 -0
  725. package/dist/safe-bash/command-chunks/chunk-C5TUE2FE.js +0 -169
  726. package/dist/safe-bash/command-chunks/chunk-CVKW2YIC.js +0 -13631
  727. package/dist/safe-bash/command-chunks/chunk-JBGGUHQY.js +0 -17617
  728. package/dist/safe-bash/command-chunks/chunk-S4R2JDPL.js +0 -35
  729. package/dist/safe-bash/command-chunks/chunk-TU5IFVCX.js +0 -33708
  730. package/dist/safe-bash/command-chunks/chunk-TUWGIF22.js +0 -328
  731. package/dist/safe-bash/command-chunks/data-2FJOPYXA-PDKMLCGR.js +0 -8
  732. package/dist/safe-bash/command-chunks/index.browser-2NLML6H4.js +0 -269
  733. package/dist/safe-bash/command-chunks/model-store-EEI3QS4G.js +0 -10
  734. package/dist/safe-bash/command-chunks/pdf-M2GFAR2A-FCJMJCAP.js +0 -683
  735. package/dist/safe-bash-command-ssconvert/rendering/images/formats.d.ts +0 -2
  736. package/dist/safe-bash-docx-engine/command.d.ts +0 -65
  737. package/dist/safe-bash/chunks/{chunk-4T4RQYRI.js → chunk-5HRGBHZH.js} +10 -10
  738. package/dist/safe-bash/chunks/{chunk-QUS6X4MS.js → chunk-EOQMDRTY.js} +0 -0
  739. package/dist/safe-bash/command-chunks/{chunk-2L3JKGUH.js → chunk-4LYZBDZF.js} +4 -4
  740. package/dist/safe-bash/command-chunks/{chunk-EMMSXKEJ.js → chunk-4Q4R3VZU.js} +0 -0
  741. package/dist/safe-bash/command-chunks/{chunk-5RLK2QSY.js → chunk-7JEIWA3A.js} +5 -5
  742. package/dist/safe-bash/command-chunks/{chunk-AV6N7DDA.js → chunk-DDYPQAXN.js} +3 -3
  743. package/dist/safe-bash/command-chunks/{chunk-OOB7YCFQ.js → chunk-FMJKCVSQ.js} +3 -3
  744. package/dist/safe-bash/command-chunks/{chunk-FUL2C4EX.js → chunk-HFKS6AET.js} +3 -3
  745. package/dist/safe-bash/command-chunks/{chunk-2M3WUEDX.js → chunk-J6K5Q53O.js} +10 -10
  746. package/dist/safe-bash/command-chunks/{chunk-ATWMLV75.js → chunk-RJXZYDSN.js} +7 -7
  747. package/dist/safe-bash/command-chunks/{chunk-JD3NSHFT.js → chunk-TVGIJ56E.js} +3 -3
  748. package/dist/safe-bash/command-chunks/{chunk-3I33KPQH.js → chunk-X2HVVMTW.js} +6 -6
  749. package/dist/safe-bash/command-chunks/{odf-UKSXPNOZ-NCL5P7YL.js → odf-UKSXPNOZ-BV2LCKTB.js} +0 -0
  750. package/dist/{safe-bash/command-chunks/chunk-3SVT5VB7.js → safe-bash-docx-engine/operation-types.js} +0 -0
  751. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/accessibility.d.ts +0 -0
  752. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/animation-editing.d.ts +0 -0
  753. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/animations.d.ts +0 -0
  754. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/backgrounds.d.ts +0 -0
  755. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/chart-data-model.d.ts +0 -0
  756. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/chart-editing.d.ts +0 -0
  757. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/chart-font-operations.d.ts +0 -0
  758. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/chart-model-axes.d.ts +0 -0
  759. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/chart-model-core.d.ts +0 -0
  760. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/chart-model-series.d.ts +0 -0
  761. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/chart-model.d.ts +0 -0
  762. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/chart-objects.d.ts +0 -0
  763. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/chart-workbook.d.ts +0 -0
  764. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/charts.d.ts +0 -0
  765. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/command-placeholder.d.ts +0 -0
  766. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/comments.d.ts +0 -0
  767. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/connector-operations.d.ts +0 -0
  768. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/connectors-model.d.ts +0 -0
  769. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/connectors.d.ts +0 -0
  770. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/content-types.d.ts +0 -0
  771. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/contracts.d.ts +0 -0
  772. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/creation.d.ts +0 -0
  773. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/diagram-resources.d.ts +0 -0
  774. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/diff.d.ts +0 -0
  775. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/drawing-format.d.ts +0 -0
  776. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/drawing-operations.d.ts +0 -0
  777. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/equations.d.ts +0 -0
  778. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/errors.d.ts +0 -0
  779. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/fields.d.ts +0 -0
  780. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/font-metrics.d.ts +0 -0
  781. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/freeform-builder.d.ts +0 -0
  782. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/group-model.d.ts +0 -0
  783. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/image-extraction.d.ts +0 -0
  784. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/image-formatting.d.ts +0 -0
  785. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/image-insertion.d.ts +0 -0
  786. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/image-replacement.d.ts +0 -0
  787. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/image-value.d.ts +0 -0
  788. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/images.d.ts +0 -0
  789. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/inventory.d.ts +0 -0
  790. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/language-enum.d.ts +0 -0
  791. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/layouts.d.ts +0 -0
  792. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/length.d.ts +0 -0
  793. package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/links-model.d.ts +4 -4
  794. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/links.d.ts +0 -0
  795. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/masters.d.ts +0 -0
  796. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/media-editing.d.ts +0 -0
  797. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/media-enum.d.ts +0 -0
  798. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/media-extraction.d.ts +0 -0
  799. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/media.d.ts +0 -0
  800. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/memberships.d.ts +0 -0
  801. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/modern-comments.d.ts +0 -0
  802. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/notes.d.ts +0 -0
  803. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/ole-enum.d.ts +0 -0
  804. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/ole-insertion.d.ts +0 -0
  805. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/opaque-objects.d.ts +0 -0
  806. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/package-reader.d.ts +0 -0
  807. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/package-tools.d.ts +0 -0
  808. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/package-view.d.ts +0 -0
  809. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/package-writer.d.ts +0 -0
  810. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/paragraph-alignment.d.ts +0 -0
  811. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/presentation-settings.d.ts +0 -0
  812. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/properties.d.ts +0 -0
  813. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/relationships.d.ts +0 -0
  814. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/resource-limits.d.ts +0 -0
  815. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/sanitize.d.ts +0 -0
  816. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/selector-schema.d.ts +0 -0
  817. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/selectors.d.ts +0 -0
  818. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/shape-adjustments.d.ts +0 -0
  819. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/shape-groups.d.ts +0 -0
  820. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/shape-operations.d.ts +0 -0
  821. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/shape-path-operations.d.ts +0 -0
  822. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/shape-paths.d.ts +0 -0
  823. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/shape-placeholder-types.d.ts +0 -0
  824. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/shape-presets.d.ts +0 -0
  825. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/shape-selection.d.ts +0 -0
  826. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/shape-transforms.d.ts +0 -0
  827. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/slide-copy.d.ts +0 -0
  828. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/slide-import.d.ts +0 -0
  829. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/slide-layout-model.d.ts +0 -0
  830. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/slide-merge-split.d.ts +0 -0
  831. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/slide-model.d.ts +0 -0
  832. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/slide-removal.d.ts +0 -0
  833. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/slide-transfer-budget.d.ts +0 -0
  834. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/slides.d.ts +0 -0
  835. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/table-operations.d.ts +0 -0
  836. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/table-spans.d.ts +0 -0
  837. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/tables-model.d.ts +0 -0
  838. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/tables.d.ts +0 -0
  839. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/tags.d.ts +0 -0
  840. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/template-bindings.d.ts +0 -0
  841. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/template-repeat.d.ts +0 -0
  842. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/text-fitting.d.ts +0 -0
  843. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/text-frame-enums.d.ts +0 -0
  844. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/text-frames.d.ts +0 -0
  845. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/text-paragraphs.d.ts +0 -0
  846. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/text-reading.d.ts +0 -0
  847. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/text-replacement.d.ts +0 -0
  848. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/text-run-color.d.ts +0 -0
  849. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/text-runs.d.ts +0 -0
  850. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/text-style-resolution.d.ts +0 -0
  851. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/themes.d.ts +0 -0
  852. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/transitions.d.ts +0 -0
  853. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/validation.d.ts +0 -0
  854. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/xml-parts.d.ts +0 -0
  855. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/xml-view.d.ts +0 -0
  856. /package/dist/{safe-bash-pptx-engine → safe-bash-presentation-engine}/xml.d.ts +0 -0
@@ -0,0 +1,3472 @@
1
+ import {
2
+ hyperlinkHistory
3
+ } from "./chunk-NYBF2BVE.js";
4
+ import {
5
+ Font,
6
+ ParagraphFormat,
7
+ bindDocumentStyles,
8
+ modelFormattingOwner,
9
+ modelOutput,
10
+ provisionNamedStyles,
11
+ requireComparisonOperand,
12
+ resolveHeadingStyle,
13
+ styleOwnerCheckpoints
14
+ } from "./chunk-YQYVEVUE.js";
15
+ import {
16
+ DocumentPartView,
17
+ ImagePartView,
18
+ PackageView,
19
+ StoryPart,
20
+ StylesPart,
21
+ XmlPartView,
22
+ admitDocumentModel,
23
+ bindXmlElementView,
24
+ packageAdmitImages,
25
+ packageBindImage,
26
+ packageOwnerCheckpoint,
27
+ packagePart
28
+ } from "./chunk-RZJRR4UJ.js";
29
+ import {
30
+ editMergedTable,
31
+ mergedTableGrid,
32
+ replaceCellContent
33
+ } from "./chunk-47MFDPH4.js";
34
+ import {
35
+ sectionAttribute,
36
+ sectionBoolean,
37
+ sectionChild,
38
+ sectionInteger,
39
+ sectionOrientation,
40
+ sectionPropertyOrder,
41
+ sectionStarts
42
+ } from "./chunk-VU3YUC3U.js";
43
+ import {
44
+ inlineImageRun
45
+ } from "./chunk-WVESNAND.js";
46
+ import {
47
+ Image
48
+ } from "./chunk-A7EMM3SB.js";
49
+ import {
50
+ originalModelDefaults
51
+ } from "./chunk-XH6DXJHX.js";
52
+ import {
53
+ addDocumentStylesPart
54
+ } from "./chunk-MQFXMBGD.js";
55
+ import {
56
+ commentStoryParts,
57
+ nextCommentId,
58
+ storedCommentId
59
+ } from "./chunk-3JQ3RF2O.js";
60
+ import {
61
+ paragraphTextRun,
62
+ replaceParagraphContent,
63
+ replaceRunContent
64
+ } from "./chunk-GGOZXIGH.js";
65
+ import {
66
+ assertLiveCommentMetadataPreserved
67
+ } from "./chunk-IFNLDOJ4.js";
68
+ import {
69
+ findRelationshipPart,
70
+ retainedRelationshipTargets
71
+ } from "./chunk-4LXDJES2.js";
72
+ import {
73
+ tableGridCount
74
+ } from "./chunk-IR6ZKAUH.js";
75
+ import {
76
+ assertDocumentEditable,
77
+ publicationGenerationGuard,
78
+ publishDocumentArchive
79
+ } from "./chunk-HPKUFWHW.js";
80
+ import {
81
+ SemanticValidationError,
82
+ validateDocumentArchive
83
+ } from "./chunk-3SEQG5JH.js";
84
+ import {
85
+ tableRows
86
+ } from "./chunk-BERVTMQB.js";
87
+ import {
88
+ PublicationError
89
+ } from "./chunk-JGGRMERW.js";
90
+ import {
91
+ DocumentPackage,
92
+ documentTypes
93
+ } from "./chunk-GLPIFP7N.js";
94
+ import {
95
+ DocumentXmlEditor,
96
+ UnsupportedEditError,
97
+ activeXmlChildren,
98
+ appendBodyBlocks,
99
+ assertFormattingHistoryEditable,
100
+ editActiveRelationshipXml,
101
+ editInlineShapeExtentXml,
102
+ insertParagraphBefore,
103
+ mergeStyleChildren,
104
+ renderContent,
105
+ runElementOpen,
106
+ styleAttribute,
107
+ styleChild,
108
+ styleInteger,
109
+ styleToggle,
110
+ twips,
111
+ xmlValue
112
+ } from "./chunk-YPVBU7QF.js";
113
+ import {
114
+ parseStoredDateTime
115
+ } from "./chunk-VEUQWV2V.js";
116
+ import {
117
+ relationshipXmlRows
118
+ } from "./chunk-2PSVE7I5.js";
119
+ import {
120
+ dialectForNamespace,
121
+ documentDialects
122
+ } from "./chunk-MG7AJD5E.js";
123
+ import {
124
+ Emu,
125
+ Inches,
126
+ Length,
127
+ Twips,
128
+ WD_BREAK,
129
+ WD_CELL_VERTICAL_ALIGNMENT,
130
+ WD_HEADER_FOOTER_INDEX,
131
+ WD_INLINE_SHAPE,
132
+ WD_ORIENT,
133
+ WD_ROW_HEIGHT_RULE,
134
+ WD_SECTION_START,
135
+ WD_STYLE_TYPE,
136
+ WD_TABLE_ALIGNMENT,
137
+ WD_TABLE_DIRECTION,
138
+ enumValue,
139
+ isEnumMember,
140
+ isLength,
141
+ numericSequence,
142
+ snapshotSequence
143
+ } from "./chunk-R4TYL2G6.js";
144
+ import {
145
+ MarkupCompatibility,
146
+ documentCompatibilityProfile
147
+ } from "./chunk-GZ2N24A2.js";
148
+ import {
149
+ BoundsError,
150
+ MissingKeyError,
151
+ OwnershipError,
152
+ StaleHandleError
153
+ } from "./chunk-OBK24KGM.js";
154
+ import {
155
+ asciiKey,
156
+ normalizePartName,
157
+ relativePartTarget
158
+ } from "./chunk-WAKYUXVQ.js";
159
+ import {
160
+ isXmlContentType,
161
+ parseDocumentXml,
162
+ parseMediaType
163
+ } from "./chunk-MWAAMNAM.js";
164
+ import {
165
+ InputTypeError,
166
+ InvalidDocumentError,
167
+ InvalidValueError,
168
+ ResourceLimitError,
169
+ archiveSettings
170
+ } from "./chunk-IQFRPIXH.js";
171
+
172
+ // packages/safe-bash-docx-engine/src/model-active-children.ts
173
+ var projections = /* @__PURE__ */ new WeakMap();
174
+ function activeModelChildren(store, part) {
175
+ const root = store.xml(part).root;
176
+ let versions = projections.get(store);
177
+ const existing = versions?.get(root);
178
+ if (existing) return existing;
179
+ const children = /* @__PURE__ */ new Map();
180
+ const content = new MarkupCompatibility(root, documentCompatibilityProfile, store.context.budget).content;
181
+ const pending = [{ content, index: 0 }];
182
+ while (pending.length) {
183
+ const frame = pending.at(-1);
184
+ if (frame.index >= frame.content.length) {
185
+ pending.pop();
186
+ continue;
187
+ }
188
+ const item = frame.content[frame.index++];
189
+ if (!("source" in item)) continue;
190
+ store.context.budget.charge("retainedBytes", 96 + item.content.length * 8);
191
+ children.set(item.source, item.content.filter((child) => "source" in child).map((child) => child.source));
192
+ pending.push({ content: item.content, index: 0 });
193
+ }
194
+ const lookup = (node) => {
195
+ store.context.budget.charge("work", 1);
196
+ return children.get(node) ?? [];
197
+ };
198
+ if (!versions) {
199
+ versions = /* @__PURE__ */ new WeakMap();
200
+ projections.set(store, versions);
201
+ }
202
+ versions.set(root, lookup);
203
+ return lookup;
204
+ }
205
+
206
+ // packages/safe-bash-docx-engine/src/section-model.ts
207
+ function refs(store, owner = store.mainPart) {
208
+ const xml = store.xml(owner), children = activeModelChildren(store, owner), body = sectionChild(xml.root, "body", children);
209
+ const nodes = [];
210
+ for (const child of children(body)) {
211
+ if (child.namespace !== body.namespace) continue;
212
+ if (child.localName === "p") {
213
+ const section = sectionChild(sectionChild(child, "pPr", children), "sectPr", children);
214
+ if (section) nodes.push(section);
215
+ } else if (child.localName === "sectPr") nodes.push(child);
216
+ }
217
+ return nodes.map((node) => store.ref(owner, node));
218
+ }
219
+ var Sections = class {
220
+ constructor(store, owner) {
221
+ this.store = store;
222
+ this.owner = owner;
223
+ return numericSequence(this);
224
+ }
225
+ store;
226
+ owner;
227
+ get length() {
228
+ return refs(this.store, this.owner?.part).length;
229
+ }
230
+ at(index2) {
231
+ if (!Number.isSafeInteger(index2))
232
+ throw new InputTypeError("Expected a safe integer section index.");
233
+ const items = refs(this.store, this.owner?.part), ref = items[index2 < 0 ? items.length + index2 : index2];
234
+ if (!ref) throw new BoundsError("Section index is out of bounds.");
235
+ return new Section(this.store, ref);
236
+ }
237
+ *[Symbol.iterator]() {
238
+ for (const ref of refs(this.store, this.owner?.part)) yield new Section(this.store, ref);
239
+ }
240
+ slice(start, end) {
241
+ for (const value of [start, end])
242
+ if (value !== void 0 && !Number.isSafeInteger(value))
243
+ throw new InputTypeError("Expected safe integer slice bounds.");
244
+ return snapshotSequence([...this].slice(start, end));
245
+ }
246
+ count(value) {
247
+ return [...this].filter((section) => section.equals(value)).length;
248
+ }
249
+ index(value, start = 0, stop) {
250
+ for (const bound of [start, stop])
251
+ if (bound !== void 0 && !Number.isSafeInteger(bound))
252
+ throw new InputTypeError("Expected safe integer sequence bounds.");
253
+ const items = [...this], lower = start < 0 ? Math.max(0, items.length + start) : start, upper = stop === void 0 ? items.length : stop < 0 ? Math.max(0, items.length + stop) : Math.min(stop, items.length);
254
+ for (let index2 = lower; index2 < upper; index2++) if (items[index2].equals(value)) return index2;
255
+ throw new InvalidValueError("Section is not in this sequence range.");
256
+ }
257
+ includes(value) {
258
+ return [...this].some((section) => section.equals(value));
259
+ }
260
+ *reversed() {
261
+ yield* [...this].reverse();
262
+ }
263
+ };
264
+ var Section = class _Section {
265
+ constructor(store, ref) {
266
+ this.store = store;
267
+ this.ref = ref;
268
+ }
269
+ store;
270
+ ref;
271
+ get element() {
272
+ return this.store.element(this.ref);
273
+ }
274
+ get part() {
275
+ this.store.node(this.ref);
276
+ return this.store.part(this.ref.part, true);
277
+ }
278
+ equals(other) {
279
+ requireComparisonOperand(other);
280
+ this.store.node(this.ref);
281
+ return other instanceof _Section && other.store === this.store && this.store.node(this.ref) === other.store.node(other.ref);
282
+ }
283
+ length(tag, attr) {
284
+ const value = sectionInteger(sectionChild(this.store.node(this.ref), tag, activeModelChildren(this.store, this.ref.part)), attr, null, 635);
285
+ return value === null ? null : Twips(value);
286
+ }
287
+ set(tag, attr, value) {
288
+ this.store.change(this.ref.part, (xml) => {
289
+ const node = this.store.node(this.ref), children = activeModelChildren(this.store, this.ref.part), child = sectionChild(node, tag, children);
290
+ const markup = child ? mergeStyleChildren(xml, child, /* @__PURE__ */ new Map(), [], { [attr]: value }) : `<sp:${tag} xmlns:sp="${node.namespace}"${value === null ? "" : ` sp:${attr}="${xmlValue(value)}"`}/>`;
291
+ xml.replaceElement(
292
+ node,
293
+ mergeStyleChildren(xml, node, /* @__PURE__ */ new Map([[tag, markup]]), sectionPropertyOrder, {}, children)
294
+ );
295
+ });
296
+ }
297
+ setLength(tag, attr, value) {
298
+ if (value !== null && !isLength(value))
299
+ throw new InputTypeError("Expected a typed length or null.");
300
+ this.set(tag, attr, value === null ? null : String(value.twips));
301
+ }
302
+ get page_width() {
303
+ return this.length("pgSz", "w");
304
+ }
305
+ set page_width(v) {
306
+ this.setLength("pgSz", "w", v);
307
+ }
308
+ get page_height() {
309
+ return this.length("pgSz", "h");
310
+ }
311
+ set page_height(v) {
312
+ this.setLength("pgSz", "h", v);
313
+ }
314
+ get top_margin() {
315
+ return this.length("pgMar", "top");
316
+ }
317
+ set top_margin(v) {
318
+ this.setLength("pgMar", "top", v);
319
+ }
320
+ get bottom_margin() {
321
+ return this.length("pgMar", "bottom");
322
+ }
323
+ set bottom_margin(v) {
324
+ this.setLength("pgMar", "bottom", v);
325
+ }
326
+ get left_margin() {
327
+ return this.length("pgMar", "left");
328
+ }
329
+ set left_margin(v) {
330
+ this.setLength("pgMar", "left", v);
331
+ }
332
+ get right_margin() {
333
+ return this.length("pgMar", "right");
334
+ }
335
+ set right_margin(v) {
336
+ this.setLength("pgMar", "right", v);
337
+ }
338
+ get gutter() {
339
+ return this.length("pgMar", "gutter");
340
+ }
341
+ set gutter(v) {
342
+ this.setLength("pgMar", "gutter", v);
343
+ }
344
+ get header_distance() {
345
+ return this.length("pgMar", "header");
346
+ }
347
+ set header_distance(v) {
348
+ this.setLength("pgMar", "header", v);
349
+ }
350
+ get footer_distance() {
351
+ return this.length("pgMar", "footer");
352
+ }
353
+ set footer_distance(v) {
354
+ this.setLength("pgMar", "footer", v);
355
+ }
356
+ get orientation() {
357
+ return sectionOrientation(sectionChild(this.store.node(this.ref), "pgSz", activeModelChildren(this.store, this.ref.part))) === "landscape" ? WD_ORIENT.LANDSCAPE : WD_ORIENT.PORTRAIT;
358
+ }
359
+ set orientation(value) {
360
+ if (value !== null && !Object.values(WD_ORIENT).includes(value))
361
+ throw new InputTypeError("Expected an orientation enum or null.");
362
+ this.set("pgSz", "orient", value === null || value.name === "PORTRAIT" ? null : "landscape");
363
+ }
364
+ get start_type() {
365
+ const value = sectionAttribute(sectionChild(this.store.node(this.ref), "type", activeModelChildren(this.store, this.ref.part)), "val") ?? "nextPage";
366
+ const name = Object.entries(sectionStarts).find(([, stored]) => value === stored)?.[0];
367
+ if (!name) throw new InvalidValueError("Invalid section start type.");
368
+ return WD_SECTION_START[name];
369
+ }
370
+ set start_type(value) {
371
+ if (value !== null && !Object.values(WD_SECTION_START).includes(value))
372
+ throw new InputTypeError("Expected a section start enum or null.");
373
+ this.store.change(this.ref.part, (xml) => {
374
+ const node = this.store.node(this.ref), markup = value === null || value.name === "NEW_PAGE" ? "" : `<sp:type xmlns:sp="${node.namespace}" sp:val="${sectionStarts[value.name]}"/>`;
375
+ xml.replaceElement(
376
+ node,
377
+ mergeStyleChildren(xml, node, /* @__PURE__ */ new Map([["type", markup]]), sectionPropertyOrder, {}, activeModelChildren(this.store, this.ref.part))
378
+ );
379
+ });
380
+ }
381
+ get different_first_page_header_footer() {
382
+ return sectionBoolean(sectionChild(this.store.node(this.ref), "titlePg", activeModelChildren(this.store, this.ref.part)));
383
+ }
384
+ set different_first_page_header_footer(value) {
385
+ if (typeof value !== "boolean")
386
+ throw new InputTypeError("Expected a first-page policy boolean.");
387
+ this.store.change(this.ref.part, (xml) => {
388
+ const node = this.store.node(this.ref);
389
+ xml.replaceElement(
390
+ node,
391
+ mergeStyleChildren(
392
+ xml,
393
+ node,
394
+ /* @__PURE__ */ new Map([["titlePg", value ? `<sp:titlePg xmlns:sp="${node.namespace}"/>` : ""]]),
395
+ sectionPropertyOrder,
396
+ {},
397
+ activeModelChildren(this.store, this.ref.part)
398
+ )
399
+ );
400
+ });
401
+ }
402
+ get header() {
403
+ return new _Header(this, "default");
404
+ }
405
+ get first_page_header() {
406
+ return new _Header(this, "first");
407
+ }
408
+ get even_page_header() {
409
+ return new _Header(this, "even");
410
+ }
411
+ get footer() {
412
+ return new _Footer(this, "default");
413
+ }
414
+ get first_page_footer() {
415
+ return new _Footer(this, "first");
416
+ }
417
+ get even_page_footer() {
418
+ return new _Footer(this, "even");
419
+ }
420
+ *iter_inner_content() {
421
+ const children = activeModelChildren(this.store, this.ref.part), body = sectionChild(this.store.xml(this.ref.part).root, "body", children), sections = refs(this.store, this.ref.part), position = sections.findIndex((ref) => ref.id === this.ref.id);
422
+ this.store.node(this.ref);
423
+ let current = 0;
424
+ for (const block of children(body)) {
425
+ if (block.namespace !== body.namespace || !["p", "tbl"].includes(block.localName)) continue;
426
+ if (current === position)
427
+ yield block.localName === "p" ? this.store.paragraph(this.store.ref(this.ref.part, block)) : this.store.table(this.store.ref(this.ref.part, block));
428
+ if (sectionChild(sectionChild(block, "pPr", children), "sectPr", children)) current++;
429
+ }
430
+ }
431
+ };
432
+ var HeaderFooter = class _HeaderFooter {
433
+ constructor(section, variant, kind) {
434
+ this.section = section;
435
+ this.variant = variant;
436
+ this.kind = kind;
437
+ }
438
+ section;
439
+ variant;
440
+ kind;
441
+ local() {
442
+ const node = this.section.store.node(this.section.ref);
443
+ const bindings = activeModelChildren(this.section.store, this.section.ref.part)(node).filter(
444
+ (child) => child.namespace === node.namespace && child.localName === this.kind + "Reference" && sectionAttribute(child, "type") === this.variant
445
+ );
446
+ if (bindings.length > 1)
447
+ throw new UnsupportedEditError("Duplicate section story bindings cannot be interpreted.");
448
+ return bindings[0];
449
+ }
450
+ get is_linked_to_previous() {
451
+ return !this.local();
452
+ }
453
+ set is_linked_to_previous(value) {
454
+ if (typeof value !== "boolean") throw new InputTypeError("Expected a linkage boolean.");
455
+ if (value === this.is_linked_to_previous) return;
456
+ if (!value) {
457
+ this.create();
458
+ return;
459
+ }
460
+ const store = this.section.store, local = this.local(), r = documentDialects[dialectForNamespace(local.namespace)].r;
461
+ const id2 = local.attributes.find(
462
+ (attr) => attr.namespace === r && attr.localName === "id"
463
+ )?.value;
464
+ const graph = new DocumentPackage(store.snapshot(), store.context.limits, store.context.budget);
465
+ const edge = graph.relationships(this.section.ref.part).find((edge2) => edge2.rId === id2);
466
+ if (!edge || edge.is_external || edge.reltype !== r + "/" + this.kind)
467
+ throw new InvalidValueError("Invalid story binding.");
468
+ const pending = [store.xml(this.section.ref.part).root];
469
+ store.context.budget.charge("retainedBytes", 8);
470
+ let shared = false;
471
+ while (pending.length) {
472
+ const node = pending.pop();
473
+ store.context.budget.charge("work", 1 + node.attributes.length);
474
+ if (node !== local && node.attributes.some((attr) => attr.namespace === r && attr.value === id2)) {
475
+ shared = true;
476
+ break;
477
+ }
478
+ store.context.budget.charge("retainedBytes", node.children.length * 8);
479
+ for (let index2 = node.children.length - 1; index2 >= 0; index2--) pending.push(node.children[index2]);
480
+ }
481
+ const otherEdge = retainedRelationshipTargets(graph, store.context.budget, [{ owner: this.section.ref.part, id: id2 }]).has(asciiKey(edge.target_part.partname));
482
+ store.transaction(() => {
483
+ store.change(this.section.ref.part, (xml) => xml.replaceElement(this.local(), ""));
484
+ if (!shared) {
485
+ const relationshipPart = this.section.ref.part.slice(0, this.section.ref.part.lastIndexOf("/") + 1) + "_rels/" + this.section.ref.part.slice(this.section.ref.part.lastIndexOf("/") + 1) + ".rels";
486
+ store.change(relationshipPart, (xml) => {
487
+ const relationship = relationshipXmlRows(xml.root, store.context.budget).find((row) => row.rId === id2);
488
+ if (relationship) xml[editActiveRelationshipXml](relationship.element, null);
489
+ });
490
+ if (!otherEdge) {
491
+ const part = edge.target_part.partname, relationshipPart2 = part.slice(0, part.lastIndexOf("/") + 1) + "_rels/" + part.slice(part.lastIndexOf("/") + 1) + ".rels";
492
+ store.change("/[Content_Types].xml", (xml) => {
493
+ for (const child of xml.root.children)
494
+ if (child.attributes.some(
495
+ (attr) => attr.localName === "PartName" && [part, relationshipPart2].includes(attr.value)
496
+ ))
497
+ xml.replaceElement(child, "");
498
+ });
499
+ if (store.snapshot().members.some((member) => "/" + member.name === relationshipPart2))
500
+ store.deletePart(relationshipPart2);
501
+ store.deletePart(part);
502
+ }
503
+ }
504
+ });
505
+ }
506
+ resolve(create = true) {
507
+ const store = this.section.store;
508
+ let owner, local = this.local();
509
+ if (!local) {
510
+ const sections = refs(store, this.section.ref.part), index2 = sections.findIndex((ref) => ref.id === this.section.ref.id);
511
+ for (let previous = index2 - 1; previous >= 0; previous--) {
512
+ store.context.budget.charge("work", 1);
513
+ owner = new _HeaderFooter(new Section(store, sections[previous]), this.variant, this.kind);
514
+ local = owner.local();
515
+ if (local) break;
516
+ }
517
+ }
518
+ if (local) {
519
+ const r = documentDialects[dialectForNamespace(local.namespace)].r;
520
+ const id2 = local.attributes.find(
521
+ (attr) => attr.namespace === r && attr.localName === "id"
522
+ )?.value;
523
+ const graph = new DocumentPackage(
524
+ store.snapshot(),
525
+ store.context.limits,
526
+ store.context.budget
527
+ );
528
+ const edge = graph.relationships(this.section.ref.part).find((edge2) => edge2.rId === id2);
529
+ if (!edge || edge.is_external || edge.reltype !== r + "/" + this.kind)
530
+ throw new InvalidValueError("Invalid story binding.");
531
+ const part = edge.target_part.partname;
532
+ return store.ref(part, store.xml(part).root);
533
+ }
534
+ return create ? (owner ?? this).create() : null;
535
+ }
536
+ create() {
537
+ const store = this.section.store;
538
+ return store.transaction(() => {
539
+ const node = store.node(this.section.ref), w = node.namespace, r = documentDialects[dialectForNamespace(w)].r;
540
+ const graph = new DocumentPackage(
541
+ store.snapshot(),
542
+ store.context.limits,
543
+ store.context.budget
544
+ );
545
+ const part = graph.allocatePartName(
546
+ this.section.ref.part.slice(0, this.section.ref.part.lastIndexOf("/") + 1) + this.kind,
547
+ ".xml"
548
+ ), id2 = graph.allocateRelationshipId(this.section.ref.part);
549
+ const relationshipPart = findRelationshipPart(graph, this.section.ref.part, store.context.budget)?.name;
550
+ const relationshipsName = relationshipPart ? "/" + relationshipPart : this.section.ref.part.slice(0, this.section.ref.part.lastIndexOf("/") + 1) + "_rels/" + this.section.ref.part.slice(this.section.ref.part.lastIndexOf("/") + 1) + ".rels";
551
+ const relationship = `<Relationship xmlns="http://schemas.openxmlformats.org/package/2006/relationships" Id="${id2}" Type="${r}/${this.kind}" Target="${xmlValue(relativePartTarget(this.section.ref.part, part))}"/>`;
552
+ const contentType = `application/vnd.openxmlformats-officedocument.wordprocessingml.${this.kind}+xml`;
553
+ store.setPart(
554
+ part,
555
+ new TextEncoder().encode(
556
+ `<w:${this.kind === "header" ? "hdr" : "ftr"} xmlns:w="${w}"><w:p/></w:${this.kind === "header" ? "hdr" : "ftr"}>`
557
+ ),
558
+ contentType
559
+ );
560
+ if (relationshipPart)
561
+ store.change(relationshipsName, (xml) => xml.insertChildren(xml.root, relationship));
562
+ else
563
+ store.setPart(
564
+ relationshipsName,
565
+ new TextEncoder().encode(
566
+ `<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${relationship}</Relationships>`
567
+ )
568
+ );
569
+ store.change(this.section.ref.part, (xml) => {
570
+ const section = store.node(this.section.ref), markup = `<sp:${this.kind}Reference xmlns:sp="${w}" xmlns:r="${r}" sp:type="${this.variant}" r:id="${id2}"/>`;
571
+ const next = section.children.find(
572
+ (child) => child.namespace === w && sectionPropertyOrder.indexOf(child.localName) > sectionPropertyOrder.indexOf(this.kind + "Reference")
573
+ );
574
+ xml.insertChildren(section, markup, next);
575
+ });
576
+ return store.ref(part, store.xml(part).root);
577
+ });
578
+ }
579
+ get part() {
580
+ return this.section.store.part(this.resolve().part, true);
581
+ }
582
+ get element() {
583
+ return this.section.store.element(this.resolve());
584
+ }
585
+ get paragraphs() {
586
+ const store = this.section.store, ref = this.resolve();
587
+ return snapshotSequence([...store.blocks(ref)].filter(
588
+ (block) => store.node(block.ref).localName === "p"
589
+ ));
590
+ }
591
+ get tables() {
592
+ const store = this.section.store, ref = this.resolve();
593
+ return snapshotSequence([...store.blocks(ref)].filter(
594
+ (block) => store.node(block.ref).localName === "tbl"
595
+ ));
596
+ }
597
+ iter_inner_content() {
598
+ return this.section.store.blocks(this.resolve());
599
+ }
600
+ add_paragraph(text2 = "", style) {
601
+ return this.section.store.addParagraph(this.resolve(), text2, style);
602
+ }
603
+ add_table(rows, cols, width) {
604
+ return this.section.store.addTable(this.resolve(), rows, cols, width);
605
+ }
606
+ };
607
+ function storyVariant(index2) {
608
+ if (index2 === "default" || index2 === "first" || index2 === "even") return index2;
609
+ if (!Object.values(WD_HEADER_FOOTER_INDEX).includes(index2))
610
+ throw new InputTypeError("Expected a header/footer index enum.");
611
+ return index2.name === "PRIMARY" ? "default" : index2.name === "FIRST_PAGE" ? "first" : "even";
612
+ }
613
+ var _Header = class extends HeaderFooter {
614
+ constructor(section, index2 = WD_HEADER_FOOTER_INDEX.PRIMARY) {
615
+ super(section, storyVariant(index2), "header");
616
+ }
617
+ };
618
+ var _Footer = class extends HeaderFooter {
619
+ constructor(section, index2 = WD_HEADER_FOOTER_INDEX.PRIMARY) {
620
+ super(section, storyVariant(index2), "footer");
621
+ }
622
+ };
623
+
624
+ // packages/safe-bash-docx-engine/src/review-model.ts
625
+ function text(value) {
626
+ if (typeof value !== "string") throw new InputTypeError("Expected comment text.");
627
+ }
628
+ function id(node) {
629
+ const value = storedCommentId(sectionAttribute(node, "id"));
630
+ if (value === null)
631
+ throw new InvalidValueError("Expected a nonnegative comment ID.");
632
+ return value;
633
+ }
634
+ var Comments = class {
635
+ constructor(store, ref) {
636
+ this.store = store;
637
+ this.ref = ref;
638
+ }
639
+ store;
640
+ ref;
641
+ get nodes() {
642
+ const node = this.store.node(this.ref);
643
+ return activeModelChildren(this.store, this.ref.part)(node).filter((n) => n.namespace === node.namespace && n.localName === "comment");
644
+ }
645
+ get length() {
646
+ return this.nodes.length;
647
+ }
648
+ *[Symbol.iterator]() {
649
+ for (const node of this.nodes)
650
+ yield new Comment(this.store, this.store.ref(this.ref.part, node));
651
+ }
652
+ get(comment_id) {
653
+ if (!Number.isSafeInteger(comment_id) || comment_id < 0)
654
+ throw new InputTypeError("Expected a nonnegative comment ID.");
655
+ const node = this.nodes.find((n) => id(n) === comment_id);
656
+ return node ? new Comment(this.store, this.store.ref(this.ref.part, node)) : null;
657
+ }
658
+ add_comment(value = "", author = "", initials = "") {
659
+ const timestamp = this.store.context.timestamp;
660
+ if (timestamp === void 0) throw new InputTypeError("Comment creation requires an explicit context timestamp.");
661
+ parseStoredDateTime(timestamp.toISOString(), "xsd");
662
+ text(value);
663
+ text(author);
664
+ if (initials !== null) text(initials);
665
+ return this.store.transaction(() => {
666
+ const next = nextCommentId(this.nodes.map(id), this.store.context.budget);
667
+ const styles = this.store.stylesForStory(this.ref.part);
668
+ const [style, reference] = styles[provisionNamedStyles]([
669
+ { name: "Comment Text", type: WD_STYLE_TYPE.PARAGRAPH },
670
+ { name: "Comment Reference", type: WD_STYLE_TYPE.CHARACTER }
671
+ ]);
672
+ if (!style || !reference) throw new InvalidValueError("Comment styles require scoped definitions.");
673
+ const paragraphStyleId = styles.get_style_id(style, WD_STYLE_TYPE.PARAGRAPH) ?? style.style_id;
674
+ const referenceStyleId = styles.get_style_id(reference, WD_STYLE_TYPE.CHARACTER) ?? reference.style_id;
675
+ if (paragraphStyleId === null || referenceStyleId === null)
676
+ throw new InvalidValueError("Comment styles require scoped definition IDs.");
677
+ this.store.change(this.ref.part, (xml) => {
678
+ const root = this.store.node(this.ref);
679
+ const paragraphs = value.split("\n").map((line, index2) => `<cm:p><cm:pPr><cm:pStyle cm:val="${xmlValue(paragraphStyleId)}"/></cm:pPr>${index2 === 0 ? `<cm:r><cm:rPr><cm:rStyle cm:val="${xmlValue(referenceStyleId)}"/></cm:rPr><cm:annotationRef/></cm:r>` : ""}${line ? paragraphTextRun(root.namespace, line) : ""}</cm:p>`).join("");
680
+ xml.insertChildren(
681
+ root,
682
+ `<cm:comment xmlns:cm="${root.namespace}" cm:id="${next}" cm:author="${xmlValue(author)}" cm:date="${timestamp.toISOString()}"${initials === null ? "" : ` cm:initials="${xmlValue(initials)}"`}>${paragraphs}</cm:comment>`
683
+ );
684
+ });
685
+ return this.get(next);
686
+ });
687
+ }
688
+ };
689
+ var Comment = class _Comment {
690
+ constructor(store, ref) {
691
+ this.store = store;
692
+ this.ref = ref;
693
+ }
694
+ store;
695
+ ref;
696
+ get part() {
697
+ this.store.node(this.ref);
698
+ return this.store.part(this.ref.part, true);
699
+ }
700
+ get element() {
701
+ return this.store.element(this.ref);
702
+ }
703
+ equals(other) {
704
+ requireComparisonOperand(other);
705
+ this.store.node(this.ref);
706
+ return other instanceof _Comment && other.store === this.store && this.store.node(this.ref) === other.store.node(other.ref);
707
+ }
708
+ get comment_id() {
709
+ return id(this.store.node(this.ref));
710
+ }
711
+ get timestamp() {
712
+ const raw = sectionAttribute(this.store.node(this.ref), "date");
713
+ if (raw === void 0) return null;
714
+ try {
715
+ return parseStoredDateTime(raw, "xsd");
716
+ } catch (error) {
717
+ if (error instanceof InvalidValueError) return null;
718
+ throw error;
719
+ }
720
+ }
721
+ get author() {
722
+ return sectionAttribute(this.store.node(this.ref), "author") ?? "";
723
+ }
724
+ set author(value) {
725
+ text(value);
726
+ this.attribute("author", value);
727
+ }
728
+ get initials() {
729
+ return sectionAttribute(this.store.node(this.ref), "initials") ?? null;
730
+ }
731
+ set initials(value) {
732
+ if (value !== null) text(value);
733
+ this.attribute("initials", value);
734
+ }
735
+ attribute(name, value) {
736
+ this.store.change(this.ref.part, (xml) => {
737
+ const node = this.store.node(this.ref);
738
+ xml.setQualifiedAttribute(node, { namespace: node.namespace, localName: name }, value);
739
+ });
740
+ }
741
+ get paragraphs() {
742
+ const node = this.store.node(this.ref);
743
+ return snapshotSequence(activeModelChildren(this.store, this.ref.part)(node).filter((n) => n.namespace === node.namespace && n.localName === "p").map((n) => this.store.paragraph(this.store.ref(this.ref.part, n))));
744
+ }
745
+ get tables() {
746
+ const node = this.store.node(this.ref);
747
+ return snapshotSequence(activeModelChildren(this.store, this.ref.part)(node).filter((n) => n.namespace === node.namespace && n.localName === "tbl").map((n) => this.store.table(this.store.ref(this.ref.part, n))));
748
+ }
749
+ get text() {
750
+ return this.paragraphs.map((paragraph) => paragraph.text).join("\n");
751
+ }
752
+ iter_inner_content() {
753
+ return this.store.blocks(this.ref);
754
+ }
755
+ add_paragraph(value = "", style) {
756
+ text(value);
757
+ return this.store.transaction(() => {
758
+ const paragraph = this.store.addParagraph(this.ref, value);
759
+ paragraph.style = style ?? "Comment Text";
760
+ return paragraph;
761
+ });
762
+ }
763
+ add_table(rows, cols, width) {
764
+ return this.store.addTable(this.ref, rows, cols, width);
765
+ }
766
+ };
767
+ var Hyperlink = class {
768
+ constructor(store, ref) {
769
+ this.store = store;
770
+ this.ref = ref;
771
+ }
772
+ store;
773
+ ref;
774
+ get part() {
775
+ this.store.node(this.ref);
776
+ return this.store.part(this.ref.part);
777
+ }
778
+ get element() {
779
+ return this.store.element(this.ref);
780
+ }
781
+ get address() {
782
+ const node = this.store.node(this.ref), dialect = dialectForNamespace(node.namespace);
783
+ if (!dialect) throw new InvalidValueError("Expected a document hyperlink namespace.");
784
+ const r = documentDialects[dialect].r, attr = node.attributes.find((a) => a.localName === "id" && a.namespace === r);
785
+ if (!attr) return "";
786
+ const edge = this.part.rels.at(attr.value);
787
+ if (!edge.is_external || edge.reltype !== r + "/hyperlink")
788
+ throw new InvalidValueError("Expected an external hyperlink relationship.");
789
+ return edge.target_ref;
790
+ }
791
+ get fragment() {
792
+ return sectionAttribute(this.store.node(this.ref), "anchor") ?? "";
793
+ }
794
+ get url() {
795
+ const address = this.address;
796
+ return address ? address + (this.fragment ? "#" + this.fragment : "") : "";
797
+ }
798
+ get runs() {
799
+ const node = this.store.node(this.ref);
800
+ return snapshotSequence(activeModelChildren(this.store, this.ref.part)(node).filter((n) => n.namespace === node.namespace && n.localName === "r").map((n) => this.store.run(this.store.ref(this.ref.part, n))));
801
+ }
802
+ get text() {
803
+ return this.runs.map((r) => r.text).join("");
804
+ }
805
+ get contains_page_break() {
806
+ const node = this.store.node(this.ref), children = activeModelChildren(this.store, this.ref.part), budget = this.store.context.budget, pending = [node];
807
+ budget.charge("retainedBytes", 8);
808
+ while (pending.length) {
809
+ const current = pending.pop();
810
+ budget.charge("work", 1);
811
+ if (current.namespace !== node.namespace) continue;
812
+ if (current.localName === "lastRenderedPageBreak") return true;
813
+ const nested = children(current);
814
+ budget.charge("work", nested.length);
815
+ budget.charge("retainedBytes", nested.length * 8);
816
+ for (let index2 = nested.length - 1; index2 >= 0; index2--) pending.push(nested[index2]);
817
+ }
818
+ return false;
819
+ }
820
+ get history() {
821
+ return hyperlinkHistory(sectionAttribute(this.store.node(this.ref), "history"));
822
+ }
823
+ };
824
+ var RenderedPageBreak = class {
825
+ constructor(store, ref, paragraphRef) {
826
+ this.store = store;
827
+ this.ref = ref;
828
+ this.paragraphRef = paragraphRef;
829
+ }
830
+ store;
831
+ ref;
832
+ paragraphRef;
833
+ get part() {
834
+ this.store.node(this.ref);
835
+ return this.store.part(this.ref.part);
836
+ }
837
+ get preceding_paragraph_fragment() {
838
+ return this.fragment(true);
839
+ }
840
+ get following_paragraph_fragment() {
841
+ return this.fragment(false);
842
+ }
843
+ fragment(preceding) {
844
+ const xml = this.store.xml(this.ref.part), p = this.store.node(this.paragraphRef), marker = this.store.node(this.ref);
845
+ const children = activeModelChildren(this.store, this.ref.part);
846
+ const budget = this.store.context.budget;
847
+ const parents = /* @__PURE__ */ new Map();
848
+ const pending = [p];
849
+ let activeMarker = false;
850
+ budget.charge("retainedBytes", 8);
851
+ while (pending.length) {
852
+ const node = pending.pop();
853
+ budget.charge("work", 1);
854
+ if (node.namespace !== p.namespace) continue;
855
+ if (node === marker && node.localName === "lastRenderedPageBreak") activeMarker = true;
856
+ const nested = children(node);
857
+ budget.charge("work", nested.length);
858
+ budget.charge("retainedBytes", nested.length * 24);
859
+ for (let index3 = nested.length - 1; index3 >= 0; index3--) {
860
+ parents.set(nested[index3], node);
861
+ pending.push(nested[index3]);
862
+ }
863
+ }
864
+ if (!activeMarker)
865
+ throw new UnsupportedEditError(
866
+ "Fragment extraction requires an active cached break in its paragraph."
867
+ );
868
+ const ancestors = /* @__PURE__ */ new Set();
869
+ const hyperlinkPath = /* @__PURE__ */ new Set();
870
+ let owner = marker, hyperlinkBoundary;
871
+ for (let node = marker; node && node !== p; node = parents.get(node)) {
872
+ budget.charge("work", 1);
873
+ budget.charge("retainedBytes", 8);
874
+ ancestors.add(node);
875
+ if (!hyperlinkBoundary) {
876
+ budget.charge("retainedBytes", 8);
877
+ hyperlinkPath.add(node);
878
+ if (node.localName === "hyperlink") hyperlinkBoundary = node;
879
+ }
880
+ owner = node;
881
+ }
882
+ if (owner === marker && !parents.has(marker))
883
+ throw new InvalidValueError("Cached break is not in its paragraph.");
884
+ const paragraphChildren = children(p);
885
+ const properties2 = paragraphChildren.find((n) => n.namespace === p.namespace && n.localName === "pPr");
886
+ const content = paragraphChildren.filter((n) => n !== properties2), index2 = content.indexOf(owner);
887
+ const standalone = (node) => runElementOpen(node) + (node.content.length ? xml.sourceXml(node, /* @__PURE__ */ new Map(), true) : "") + `</${node.name}>`;
888
+ const hyperlink = owner === hyperlinkBoundary;
889
+ const chunks = [];
890
+ const frames = [owner];
891
+ budget.charge("retainedBytes", 8);
892
+ while (frames.length) {
893
+ const frame = frames.pop();
894
+ budget.charge("work", 1);
895
+ if (typeof frame === "string") {
896
+ chunks.push(frame);
897
+ continue;
898
+ }
899
+ if (frame === marker || frame === hyperlinkBoundary && !preceding) continue;
900
+ if (!ancestors.has(frame)) {
901
+ chunks.push(standalone(frame));
902
+ continue;
903
+ }
904
+ chunks.push(runElementOpen(frame));
905
+ const selected = [];
906
+ let seen = false;
907
+ for (const child of children(frame)) {
908
+ budget.charge("work", 1);
909
+ if (ancestors.has(child)) {
910
+ selected.push(child);
911
+ seen = true;
912
+ } else if (hyperlinkBoundary && hyperlinkPath.has(frame) || child.namespace === frame.namespace && child.localName === "rPr" || (preceding ? !seen : seen)) selected.push(child);
913
+ }
914
+ budget.charge("retainedBytes", (selected.length + 1) * 8);
915
+ frames.push(`</${frame.name}>`);
916
+ for (let childIndex = selected.length - 1; childIndex >= 0; childIndex--)
917
+ frames.push(selected[childIndex]);
918
+ }
919
+ const patchedOwner = chunks.join("");
920
+ const fragment = content.slice(preceding ? 0 : index2 + (hyperlink ? 1 : 0), preceding ? index2 + 1 : void 0).map((n) => n === owner ? patchedOwner : standalone(n)).join("");
921
+ const candidate = runElementOpen(p) + (properties2 ? standalone(properties2) : "") + fragment + `</${p.name}>`;
922
+ budget.charge("retainedBytes", candidate.length * 2);
923
+ const parsed = new DocumentXmlEditor(new TextEncoder().encode(candidate), {}, void 0, budget);
924
+ const fragmentChildren = activeXmlChildren(parsed, budget);
925
+ const meaningful = fragmentChildren(parsed.root).filter((n) => n.localName !== "pPr");
926
+ budget.charge("retainedBytes", meaningful.length * 8);
927
+ let hasContent = false;
928
+ while (meaningful.length) {
929
+ const node = meaningful.pop();
930
+ budget.charge("work", 1);
931
+ if (node.namespace === p.namespace && ["t", "tab", "ptab", "noBreakHyphen", "softHyphen", "br", "cr", "drawing", "pict", "object"].includes(node.localName)) {
932
+ hasContent = true;
933
+ break;
934
+ }
935
+ const nested = fragmentChildren(node);
936
+ budget.charge("retainedBytes", nested.length * 8);
937
+ for (const child of nested) meaningful.push(child);
938
+ }
939
+ if (!hasContent) return null;
940
+ return this.store.detachedParagraph(candidate, this.ref.part);
941
+ }
942
+ };
943
+ function validateCommentRange(store, runs) {
944
+ const selected = Array.isArray(runs) ? runs : [runs];
945
+ if (!selected.length)
946
+ throw new UnsupportedEditError("Comment endpoints require runs from this document.");
947
+ if (selected.some((run) => !run || typeof run !== "object" || !run.store || !run.ref))
948
+ throw new InputTypeError("Expected comment run endpoints.");
949
+ if (selected.some((run) => run.store !== store))
950
+ throw new OwnershipError("Comment endpoints require runs from this document.");
951
+ const first = selected[0], last = selected[selected.length - 1];
952
+ if (selected.some((run) => run.ref.part !== first.ref.part)) {
953
+ const owner = store.documentOwnerForStory(first.ref.part);
954
+ if (selected.some((run) => store.documentOwnerForStory(run.ref.part) !== owner))
955
+ throw new OwnershipError("Comment endpoints require the same document owner.");
956
+ throw new UnsupportedEditError("Comment endpoints cannot cross stories.");
957
+ }
958
+ const xml = store.xml(first.ref.part), firstNode = store.node(first.ref), lastNode = store.node(last.ref);
959
+ const children = activeModelChildren(store, first.ref.part);
960
+ const ordered = [];
961
+ let order = 0, fieldDepth = 0;
962
+ const pending = [{ node: xml.root, parent: xml.root, container: xml.root, safe: true }];
963
+ store.context.budget.charge("retainedBytes", 64);
964
+ while (pending.length) {
965
+ const { node, parent } = pending.at(-1);
966
+ let { container, safe } = pending.pop();
967
+ store.context.budget?.charge("work", 1);
968
+ if (["body", "tc", "footnote", "endnote", "txbxContent", "hdr", "ftr", "comment"].includes(
969
+ node.localName
970
+ ))
971
+ container = node;
972
+ safe &&= node.namespace === xml.root.namespace && ![
973
+ "hdr",
974
+ "ftr",
975
+ "comment",
976
+ "sdt",
977
+ "ins",
978
+ "del",
979
+ "moveFrom",
980
+ "moveTo",
981
+ "hyperlink",
982
+ "fldSimple",
983
+ "customXml"
984
+ ].includes(node.localName);
985
+ if (node.namespace === xml.root.namespace && node.localName === "fldChar") {
986
+ const type = sectionAttribute(node, "fldCharType");
987
+ if (type === "begin") fieldDepth++;
988
+ if (type === "end") fieldDepth = Math.max(0, fieldDepth - 1);
989
+ }
990
+ store.context.budget.charge("retainedBytes", 64);
991
+ ordered.push({ node, parent, container, safe: safe && !fieldDepth, order: order++ });
992
+ if (node.namespace === xml.root.namespace) {
993
+ const selected2 = children(node);
994
+ store.context.budget.charge("retainedBytes", selected2.length * 64);
995
+ for (let index2 = selected2.length - 1; index2 >= 0; index2--)
996
+ pending.push({ node: selected2[index2], parent: node, container, safe });
997
+ }
998
+ }
999
+ const start = ordered.find((n) => n.node === firstNode), end = ordered.find((n) => n.node === lastNode);
1000
+ if (!start || !end || firstNode.localName !== "r" || lastNode.localName !== "r" || start.order > end.order || start.container !== end.container || start.parent.localName !== "p" || end.parent.localName !== "p")
1001
+ throw new UnsupportedEditError(
1002
+ "Comment endpoints require an ordered run range within one container."
1003
+ );
1004
+ const finalDescendants = /* @__PURE__ */ new Set();
1005
+ const finalRun = [lastNode];
1006
+ store.context.budget.charge("retainedBytes", 8);
1007
+ while (finalRun.length) {
1008
+ const node = finalRun.pop();
1009
+ store.context.budget.charge("work", 1);
1010
+ const nested = children(node);
1011
+ store.context.budget.charge("retainedBytes", 24 + nested.length * 8);
1012
+ finalDescendants.add(node);
1013
+ for (const child of nested) finalRun.push(child);
1014
+ }
1015
+ const endOrder = ordered.filter((n) => finalDescendants.has(n.node)).at(-1).order;
1016
+ const span = ordered.filter((n) => n.order >= start.order && n.order <= endOrder);
1017
+ if (!start.safe || !end.safe || span.some(
1018
+ (n) => !n.safe || ["commentRangeStart", "commentRangeEnd", "commentReference", "fldChar"].includes(
1019
+ n.node.localName
1020
+ )
1021
+ ))
1022
+ throw new UnsupportedEditError("Comment anchors cannot cross controlled or annotated content.");
1023
+ let depth = 0;
1024
+ for (const item of ordered) {
1025
+ if (item.node.namespace === xml.root.namespace && item.node.localName === "commentRangeStart") depth++;
1026
+ if (item.order === start.order && depth)
1027
+ throw new UnsupportedEditError("Comment ranges cannot overlap existing comments.");
1028
+ if (item.node.namespace === xml.root.namespace && item.node.localName === "commentRangeEnd") depth = Math.max(0, depth - 1);
1029
+ }
1030
+ const allRuns = span.filter((n) => n.node.localName === "r");
1031
+ if (!allRuns.length || !allRuns.some(
1032
+ (n) => children(n.node).some((c) => c.namespace === xml.root.namespace && (c.localName === "t" ? c.text.length > 0 : ["tab", "ptab", "noBreakHyphen", "softHyphen", "br", "cr", "drawing", "pict"].includes(c.localName)))
1033
+ ))
1034
+ throw new UnsupportedEditError("Comment anchors require nonempty run content.");
1035
+ store.context.budget.charge("retainedBytes", allRuns.length * 32);
1036
+ const physical = allRuns.map(({ node }) => ({ node, index: -1 }));
1037
+ while (physical.length) {
1038
+ const frame = physical.at(-1);
1039
+ if (frame.index === -1) {
1040
+ store.context.budget.charge("work", 1 + frame.node.attributes.length);
1041
+ if (!xml.compatibility.canEdit(frame.node) || frame.node.attributes.some((attribute) => attribute.namespace !== "http://www.w3.org/2000/xmlns/" && !xml.compatibility.canEdit(attribute)))
1042
+ throw new UnsupportedEditError("Comment anchors cannot relocate opaque run ownership.");
1043
+ frame.index = 0;
1044
+ }
1045
+ const child = frame.node.children[frame.index++];
1046
+ if (!child) physical.pop();
1047
+ else {
1048
+ store.context.budget.charge("retainedBytes", 32);
1049
+ physical.push({ node: child, index: -1 });
1050
+ }
1051
+ }
1052
+ return { first, last };
1053
+ }
1054
+ function applyCommentRange(store, first, last, commentId) {
1055
+ const owner = store.documentOwnerForStory(first.ref.part);
1056
+ const dialect = dialectForNamespace(store.xml(owner).root.namespace);
1057
+ const graph = new DocumentPackage(store.snapshot(), store.context.limits, store.context.budget);
1058
+ let referenceStyleId = "CommentReference";
1059
+ if (graph.relationships(owner).some((edge) => edge.reltype === documentDialects[dialect].r + "/styles")) {
1060
+ const styles = store.stylesForStory(first.ref.part);
1061
+ if (styles.has("Comment Reference")) {
1062
+ const reference = styles.at("Comment Reference");
1063
+ const scoped = styles.get_style_id(reference, WD_STYLE_TYPE.CHARACTER) ?? reference.style_id;
1064
+ if (scoped === null) throw new InvalidValueError("Comment reference styles require a scoped definition ID.");
1065
+ referenceStyleId = scoped;
1066
+ }
1067
+ }
1068
+ store.change(first.ref.part, (editor) => {
1069
+ const begin = store.node(first.ref), finish = store.node(last.ref), w = begin.namespace;
1070
+ const beginMarkup = `<cm:commentRangeStart xmlns:cm="${w}" cm:id="${commentId}"/>`, endMarkup = `<cm:commentRangeEnd xmlns:cm="${w}" cm:id="${commentId}"/><cm:r xmlns:cm="${w}"><cm:rPr><cm:rStyle cm:val="${xmlValue(referenceStyleId)}"/></cm:rPr><cm:commentReference cm:id="${commentId}"/></cm:r>`;
1071
+ if (begin === finish)
1072
+ editor.replaceElement(begin, beginMarkup + editor.sourceXml(begin) + endMarkup);
1073
+ else {
1074
+ editor.replaceElement(begin, beginMarkup + editor.sourceXml(begin));
1075
+ editor.replaceElement(finish, editor.sourceXml(finish) + endMarkup);
1076
+ }
1077
+ });
1078
+ }
1079
+ function bindCommentRange(store, runs, value = "", author = "", initials = "", documentPart) {
1080
+ text(value);
1081
+ text(author);
1082
+ if (initials !== null) text(initials);
1083
+ const { first, last } = validateCommentRange(store, runs);
1084
+ if (documentPart !== void 0 && store.documentOwnerForStory(first.ref.part) !== documentPart)
1085
+ throw new OwnershipError("Comment endpoints require runs owned by the receiving document.");
1086
+ const comment = new Comments(store, store.ensureComments(store.documentOwnerForStory(first.ref.part))).add_comment(value, author, initials);
1087
+ applyCommentRange(store, first, last, comment.comment_id);
1088
+ return comment;
1089
+ }
1090
+ function markCommentRange(store, first, last, comment_id) {
1091
+ if (!Number.isSafeInteger(comment_id) || comment_id < 0)
1092
+ throw new InputTypeError("Expected a nonnegative comment ID.");
1093
+ validateCommentRange(store, [first, last]);
1094
+ const owner = store.documentOwnerForStory(first.ref.part), main = store.xml(owner).root, dialect = dialectForNamespace(main.namespace);
1095
+ const edges = [...store.part(owner).rels.values()].filter(
1096
+ (edge) => edge.reltype === documentDialects[dialect].r + "/comments"
1097
+ );
1098
+ if (edges.length !== 1 || edges[0].is_external)
1099
+ throw new UnsupportedEditError("Comment anchoring requires an existing comment body.");
1100
+ const part = edges[0].target_part.partname.toString(), container = store.ref(part, store.xml(part).root), comment = new Comments(store, container).get(comment_id);
1101
+ if (!comment)
1102
+ throw new UnsupportedEditError("Comment anchoring requires an existing comment body.");
1103
+ const graph = new DocumentPackage(store.snapshot(), store.context.limits, store.context.budget);
1104
+ const stories = commentStoryParts(
1105
+ graph,
1106
+ owner,
1107
+ part,
1108
+ documentDialects[dialect].w,
1109
+ documentDialects[dialect].r,
1110
+ (name) => store.xml(name).root,
1111
+ store.context.budget
1112
+ );
1113
+ for (const story of stories) {
1114
+ store.context.budget.charge("retainedBytes", 8);
1115
+ const pending = [store.xml(story).root];
1116
+ while (pending.length) {
1117
+ const node = pending.pop();
1118
+ store.context.budget.charge("work", 1);
1119
+ if (node.namespace === documentDialects[dialect].w && ["commentRangeStart", "commentRangeEnd", "commentReference"].includes(node.localName) && storedCommentId(sectionAttribute(node, "id")) === comment_id)
1120
+ throw new UnsupportedEditError("Comment body already has an anchor.");
1121
+ store.context.budget.charge("retainedBytes", node.children.length * 8);
1122
+ for (let index2 = node.children.length - 1; index2 >= 0; index2--) pending.push(node.children[index2]);
1123
+ }
1124
+ }
1125
+ applyCommentRange(store, first, last, comment_id);
1126
+ }
1127
+
1128
+ // packages/safe-bash-docx-engine/src/settings-model.ts
1129
+ var Settings = class _Settings {
1130
+ constructor(store, partname, owner = store.mainPart) {
1131
+ this.store = store;
1132
+ const graph = new DocumentPackage(store.snapshot(), store.context.limits, store.context.budget);
1133
+ const w = store.xml(owner).root.namespace;
1134
+ const r = documentDialects[dialectForNamespace(w)].r;
1135
+ const edges = graph.relationships(owner).filter((edge) => edge.reltype === r + "/settings");
1136
+ if (partname === void 0 && (edges.length > 1 || edges[0]?.is_external))
1137
+ throw new UnsupportedEditError("Expected one internal settings part.");
1138
+ let part = partname ?? edges[0]?.target_part.partname;
1139
+ if (!part)
1140
+ part = store.transaction(() => {
1141
+ const created = graph.allocatePartName(
1142
+ owner.slice(0, owner.lastIndexOf("/") + 1) + "settings",
1143
+ ".xml"
1144
+ );
1145
+ store.setPart(
1146
+ created,
1147
+ new TextEncoder().encode(`<ds:settings xmlns:ds="${w}"/>`),
1148
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"
1149
+ );
1150
+ const relationshipPart = findRelationshipPart(graph, owner, store.context.budget);
1151
+ const relName = relationshipPart ? "/" + relationshipPart.name : owner.slice(0, owner.lastIndexOf("/") + 1) + "_rels/" + owner.slice(owner.lastIndexOf("/") + 1) + ".rels";
1152
+ const edge = `<Relationship xmlns="http://schemas.openxmlformats.org/package/2006/relationships" Id="${graph.allocateRelationshipId(owner)}" Type="${r}/settings" Target="${xmlValue(relativePartTarget(owner, created))}"/>`;
1153
+ if (relationshipPart)
1154
+ store.change(relName, (xml) => xml.insertChildren(xml.root, edge));
1155
+ else
1156
+ store.setPart(
1157
+ relName,
1158
+ new TextEncoder().encode(
1159
+ `<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${edge}</Relationships>`
1160
+ )
1161
+ );
1162
+ return created;
1163
+ });
1164
+ const root = store.xml(part).root;
1165
+ if (root.namespace !== w || root.localName !== "settings")
1166
+ throw new UnsupportedEditError("Expected a supported settings root.");
1167
+ this.ref = store.ref(part, root);
1168
+ }
1169
+ store;
1170
+ ref;
1171
+ get part() {
1172
+ this.store.node(this.ref);
1173
+ return this.store.part(this.ref.part);
1174
+ }
1175
+ get element() {
1176
+ return this.store.element(this.ref);
1177
+ }
1178
+ equals(other) {
1179
+ requireComparisonOperand(other);
1180
+ this.store.node(this.ref);
1181
+ return other instanceof _Settings && other.store === this.store && this.store.node(this.ref) === other.store.node(other.ref);
1182
+ }
1183
+ get odd_and_even_pages_header_footer() {
1184
+ const root = this.store.node(this.ref);
1185
+ return sectionBoolean(activeModelChildren(this.store, this.ref.part)(root).find((node) => node.namespace === root.namespace && node.localName === "evenAndOddHeaders"));
1186
+ }
1187
+ set odd_and_even_pages_header_footer(value) {
1188
+ if (typeof value !== "boolean")
1189
+ throw new InputTypeError("Expected a page header policy boolean.");
1190
+ this.store.change(this.ref.part, (xml) => {
1191
+ const root = this.store.node(this.ref);
1192
+ const old = activeModelChildren(this.store, this.ref.part)(root).filter(
1193
+ (node) => node.namespace === root.namespace && node.localName === "evenAndOddHeaders"
1194
+ );
1195
+ if (old.length > 1)
1196
+ throw new UnsupportedEditError("Duplicate page header policies cannot be edited.");
1197
+ const flag = old[0];
1198
+ if (flag && (flag.content.length || flag.attributes.some((attribute) => attribute.namespace !== "http://www.w3.org/2000/xmlns/" && !(attribute.namespace === root.namespace && attribute.localName === "val")))) {
1199
+ if (sectionBoolean(flag) === value) return;
1200
+ xml.setQualifiedAttribute(flag, { namespace: root.namespace, localName: "val" }, value ? null : "0");
1201
+ return;
1202
+ }
1203
+ const markup = value ? `<ds:evenAndOddHeaders xmlns:ds="${root.namespace}"/>` : "";
1204
+ if (old[0]) xml.replaceElement(old[0], markup);
1205
+ else if (markup) {
1206
+ const preceding = new Set("writeProtection view zoom removePersonalInformation removeDateAndTime doNotDisplayPageBoundaries displayBackgroundShape printPostScriptOverText printFractionalCharacterWidth printFormsData embedTrueTypeFonts embedSystemFonts saveSubsetFonts saveFormsData mirrorMargins alignBordersAndEdges bordersDoNotSurroundHeader bordersDoNotSurroundFooter gutterAtTop hideSpellingErrors hideGrammaticalErrors activeWritingStyle proofState formsDesign attachedTemplate linkStyles stylePaneFormatFilter stylePaneSortMethod documentType mailMerge revisionView trackRevisions doNotTrackMoves doNotTrackFormatting documentProtection autoFormatOverride styleLockTheme styleLockQFSet defaultTabStop autoHyphenation consecutiveHyphenLimit hyphenationZone doNotHyphenateCaps showEnvelope summaryLength clickAndTypeStyle defaultTableStyle".split(" "));
1207
+ xml.insertChildren(root, markup, root.children.find((node) => node.namespace === root.namespace && !preceding.has(node.localName)));
1208
+ }
1209
+ });
1210
+ }
1211
+ };
1212
+
1213
+ // packages/safe-bash-docx-engine/src/inline-shape-model.ts
1214
+ var Drawing = class {
1215
+ constructor(store, ref) {
1216
+ this.store = store;
1217
+ this.ref = ref;
1218
+ }
1219
+ store;
1220
+ ref;
1221
+ get element() {
1222
+ return this.store.element(this.ref);
1223
+ }
1224
+ get _drawing() {
1225
+ return this.element;
1226
+ }
1227
+ get part() {
1228
+ this.store.node(this.ref);
1229
+ return this.store.part(this.ref.part);
1230
+ }
1231
+ get has_picture() {
1232
+ const node = this.store.node(this.ref), ns = documentDialects[dialectForNamespace(this.store.xml(this.ref.part).root.namespace)];
1233
+ const children = activeModelChildren(this.store, this.ref.part);
1234
+ const picture = descendant(node, ns.pic, "pic", children), blip = picture && descendant(picture, ns.a, "blip", children);
1235
+ return !!blip?.attributes.some((a) => a.namespace === ns.r && a.localName === "embed");
1236
+ }
1237
+ get image() {
1238
+ const node = this.store.node(this.ref), ns = documentDialects[dialectForNamespace(this.store.xml(this.ref.part).root.namespace)];
1239
+ const children = activeModelChildren(this.store, this.ref.part);
1240
+ const picture = descendant(node, ns.pic, "pic", children), blip = picture && descendant(picture, ns.a, "blip", children);
1241
+ const id2 = blip?.attributes.find((a) => a.namespace === ns.r && a.localName === "embed")?.value;
1242
+ if (!id2) throw new MissingKeyError("Drawing has no embedded picture.");
1243
+ const part = this.part.related_parts.get(id2);
1244
+ if (!(part instanceof ImagePartView))
1245
+ throw new InvalidValueError("Drawing picture relationship is invalid.");
1246
+ return part.image;
1247
+ }
1248
+ };
1249
+ function descendant(node, namespace, name, children) {
1250
+ const pending = [node];
1251
+ while (pending.length) {
1252
+ const current = pending.pop();
1253
+ if (current.namespace === namespace && current.localName === name) return current;
1254
+ const content = children(current);
1255
+ for (let index2 = content.length - 1; index2 >= 0; index2--) pending.push(content[index2]);
1256
+ }
1257
+ return void 0;
1258
+ }
1259
+ var InlineShape = class {
1260
+ constructor(store, ref) {
1261
+ this.store = store;
1262
+ this.ref = ref;
1263
+ }
1264
+ store;
1265
+ ref;
1266
+ get element() {
1267
+ return this.store.element(this.ref);
1268
+ }
1269
+ get part() {
1270
+ this.store.node(this.ref);
1271
+ return this.store.part(this.ref.part);
1272
+ }
1273
+ get type() {
1274
+ const node = this.store.node(this.ref), ns = documentDialects[dialectForNamespace(this.store.xml(this.ref.part).root.namespace)];
1275
+ const children = activeModelChildren(this.store, this.ref.part);
1276
+ const data = descendant(node, ns.a, "graphicData", children);
1277
+ const uri = data?.attributes.find((a) => a.namespace === "" && a.localName === "uri")?.value;
1278
+ if (uri === ns.pic) {
1279
+ const blip = descendant(data, ns.a, "blip", children);
1280
+ return blip?.attributes.some((a) => a.namespace === ns.r && a.localName === "link") ? WD_INLINE_SHAPE.LINKED_PICTURE : WD_INLINE_SHAPE.PICTURE;
1281
+ }
1282
+ if ([
1283
+ "http://schemas.openxmlformats.org/drawingml/2006/chart",
1284
+ "http://purl.oclc.org/ooxml/drawingml/chart"
1285
+ ].includes(uri ?? ""))
1286
+ return WD_INLINE_SHAPE.CHART;
1287
+ if ([
1288
+ "http://schemas.openxmlformats.org/drawingml/2006/diagram",
1289
+ "http://purl.oclc.org/ooxml/drawingml/diagram"
1290
+ ].includes(uri ?? ""))
1291
+ return WD_INLINE_SHAPE.SMART_ART;
1292
+ return WD_INLINE_SHAPE.NOT_IMPLEMENTED;
1293
+ }
1294
+ extent(axis) {
1295
+ const node = this.store.node(this.ref), extent = activeModelChildren(
1296
+ this.store,
1297
+ this.ref.part
1298
+ )(node).find((c) => c.namespace === node.namespace && c.localName === "extent");
1299
+ const raw = extent?.attributes.find((a) => a.namespace === "" && a.localName === axis)?.value;
1300
+ if (raw === void 0 || raw.trim() === "" || !Number.isSafeInteger(Number(raw)) || Number(raw) < 0)
1301
+ throw new InvalidValueError("Invalid inline shape extent.");
1302
+ return Emu(Number(raw));
1303
+ }
1304
+ setExtent(axis, value) {
1305
+ if (!isLength(value)) throw new InputTypeError("Expected a typed inline shape length.");
1306
+ if (value.emu < 0) throw new InvalidValueError("Inline shape extent must be nonnegative.");
1307
+ this.store.transaction(() => {
1308
+ const node = this.store.node(this.ref), ns = documentDialects[dialectForNamespace(this.store.xml(this.ref.part).root.namespace)];
1309
+ const children = activeModelChildren(this.store, this.ref.part);
1310
+ const extent = children(node).find(
1311
+ (c) => c.namespace === node.namespace && c.localName === "extent"
1312
+ );
1313
+ const transform = descendant(node, ns.a, "xfrm", children), inner = transform && children(transform).find((c) => c.namespace === ns.a && c.localName === "ext");
1314
+ if (!extent) throw new InvalidValueError("Inline shape extent is missing.");
1315
+ const refs2 = [extent, ...inner ? [inner] : []].map((c) => this.store.ref(this.ref.part, c));
1316
+ for (const ref of refs2)
1317
+ this.store.change(
1318
+ this.ref.part,
1319
+ (xml) => xml[editInlineShapeExtentXml](
1320
+ this.store.node(this.ref),
1321
+ this.store.node(ref),
1322
+ axis,
1323
+ value.emu
1324
+ )
1325
+ );
1326
+ });
1327
+ }
1328
+ get width() {
1329
+ return this.extent("cx");
1330
+ }
1331
+ set width(value) {
1332
+ this.setExtent("cx", value);
1333
+ }
1334
+ get height() {
1335
+ return this.extent("cy");
1336
+ }
1337
+ set height(value) {
1338
+ this.setExtent("cy", value);
1339
+ }
1340
+ };
1341
+ var InlineShapes = class {
1342
+ constructor(store, owner) {
1343
+ this.store = store;
1344
+ this.owner = owner;
1345
+ return numericSequence(this);
1346
+ }
1347
+ store;
1348
+ owner;
1349
+ cache = /* @__PURE__ */ new Map();
1350
+ get part() {
1351
+ this.store.node(this.owner);
1352
+ return this.store.part(this.owner.part);
1353
+ }
1354
+ refs() {
1355
+ const ns = documentDialects[dialectForNamespace(this.store.xml(this.owner.part).root.namespace)];
1356
+ const refs2 = [];
1357
+ const children = activeModelChildren(this.store, this.owner.part);
1358
+ const visit = (node) => {
1359
+ this.store.context.budget.charge("work", 1);
1360
+ if (node.namespace === ns.w && ["ins", "del", "moveFrom", "moveTo"].includes(node.localName))
1361
+ return;
1362
+ if (node.namespace === ns.wp && node.localName === "inline")
1363
+ refs2.push(this.store.ref(this.owner.part, node));
1364
+ for (const child of children(node)) visit(child);
1365
+ };
1366
+ visit(this.store.node(this.owner));
1367
+ return refs2;
1368
+ }
1369
+ get length() {
1370
+ return this.refs().length;
1371
+ }
1372
+ at(index2) {
1373
+ if (!Number.isSafeInteger(index2))
1374
+ throw new InputTypeError("Expected an integer inline shape index.");
1375
+ const refs2 = this.refs(), ref = refs2[index2 < 0 ? refs2.length + index2 : index2];
1376
+ if (!ref) throw new BoundsError("Inline shape index is out of bounds.");
1377
+ let shape = this.cache.get(ref.id);
1378
+ if (!shape) {
1379
+ shape = new InlineShape(this.store, ref);
1380
+ this.cache.set(ref.id, shape);
1381
+ }
1382
+ return shape;
1383
+ }
1384
+ *[Symbol.iterator]() {
1385
+ for (let i = 0; i < this.length; i++) yield this.at(i);
1386
+ }
1387
+ };
1388
+ function insertModelImage(store, ref, image, width, height) {
1389
+ const [cx, cy] = image.scaled_dimensions(width, height);
1390
+ return store.transaction(() => {
1391
+ const owner = store.node(ref), ns = documentDialects[dialectForNamespace(store.xml(ref.part).root.namespace)];
1392
+ if (owner.namespace !== ns.w || !["r", "body"].includes(owner.localName))
1393
+ throw new InputTypeError("Unsupported live picture insertion owner.");
1394
+ const graph = new DocumentPackage(store.snapshot(), store.context.limits, store.context.budget);
1395
+ const suffix = {
1396
+ "image/png": ".png",
1397
+ "image/jpeg": ".jpg",
1398
+ "image/gif": ".gif",
1399
+ "image/bmp": ".bmp",
1400
+ "image/tiff": ".tiff"
1401
+ }[image.content_type];
1402
+ const part = graph.allocatePartName(
1403
+ store.mainPart.slice(0, store.mainPart.lastIndexOf("/") + 1) + "media/image",
1404
+ suffix
1405
+ );
1406
+ const relationshipId = graph.allocateRelationshipId(ref.part), drawingIds = /* @__PURE__ */ new Set();
1407
+ for (const candidate of graph.parts) {
1408
+ if (!isXmlContentType(candidate.content_type)) continue;
1409
+ const collect = (node) => {
1410
+ store.context.budget.charge("work", 1);
1411
+ if (node.namespace === ns.wp && node.localName === "docPr")
1412
+ drawingIds.add(
1413
+ Number(node.attributes.find((a) => a.namespace === "" && a.localName === "id")?.value)
1414
+ );
1415
+ for (const child of node.children) collect(child);
1416
+ };
1417
+ collect(parseDocumentXml(candidate.bytes, {}, store.context.budget).root);
1418
+ }
1419
+ let drawingId = 1;
1420
+ while (drawingIds.has(drawingId)) drawingId++;
1421
+ if (drawingId > 4294967295) throw new ResourceLimitError("No drawing identifier is available.");
1422
+ store.setPart(part, image.blob, image.content_type);
1423
+ const relationshipPart = findRelationshipPart(graph, ref.part, store.context.budget);
1424
+ const relName = relationshipPart ? "/" + relationshipPart.name : ref.part.slice(0, ref.part.lastIndexOf("/") + 1) + "_rels/" + ref.part.slice(ref.part.lastIndexOf("/") + 1) + ".rels";
1425
+ const edge = `<Relationship xmlns="http://schemas.openxmlformats.org/package/2006/relationships" Id="${relationshipId}" Type="${ns.r}/image" Target="${xmlValue(relativePartTarget(ref.part, part))}"/>`;
1426
+ if (relationshipPart)
1427
+ store.change(relName, (xml) => xml.insertChildren(xml.root, edge));
1428
+ else
1429
+ store.setPart(
1430
+ relName,
1431
+ new TextEncoder().encode(
1432
+ `<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${edge}</Relationships>`
1433
+ )
1434
+ );
1435
+ const imagePart = store.package.parts.find(
1436
+ (candidate) => candidate.partname.toString() === part
1437
+ );
1438
+ if (!(imagePart instanceof ImagePartView))
1439
+ throw new InvalidValueError("Inserted image part is unavailable.");
1440
+ store.package[packageBindImage](imagePart, image);
1441
+ const { run } = inlineImageRun(ns, drawingId, relationshipId, {
1442
+ width: cx.emu,
1443
+ height: cy.emu,
1444
+ crop: ""
1445
+ }, { filename: image.filename });
1446
+ store.change(ref.part, (xml) => {
1447
+ const container2 = store.node(ref);
1448
+ const section = container2.children.find(
1449
+ (c) => c.namespace === ns.w && c.localName === "sectPr"
1450
+ );
1451
+ const markup = container2.localName === "r" ? run.slice(run.indexOf(">") + 1, run.lastIndexOf("</")) : `<wi:p xmlns:wi="${ns.w}">${run}</wi:p>`;
1452
+ if (container2.localName === "r") {
1453
+ const namespaces = ` xmlns:wp="${ns.wp}" xmlns:di="${ns.a}" xmlns:pic="${ns.pic}" xmlns:ri="${ns.r}" xmlns:wi="${ns.w}"`;
1454
+ xml.insertChildren(
1455
+ container2,
1456
+ `<wi:drawing${namespaces}>${markup.slice(markup.indexOf(">") + 1, markup.lastIndexOf("</"))}</wi:drawing>`
1457
+ );
1458
+ } else xml.insertChildren(container2, markup, section);
1459
+ });
1460
+ const container = store.node(ref), all = new InlineShapes(store, ref);
1461
+ const inline = all.at(-1);
1462
+ if (container.localName === "r" && inline.ref.part !== ref.part)
1463
+ throw new InputTypeError("Inline image owner is invalid.");
1464
+ return inline;
1465
+ });
1466
+ }
1467
+
1468
+ // packages/safe-bash-docx-engine/src/block-model.ts
1469
+ function modelText(node, children = (node2) => node2.children) {
1470
+ let text2 = "";
1471
+ const pending = [node];
1472
+ while (pending.length) {
1473
+ const current = pending.pop();
1474
+ if (current.namespace !== node.namespace) continue;
1475
+ const name = current.localName;
1476
+ if (name === "t") text2 += current.text;
1477
+ else if (name === "tab" || name === "ptab") text2 += " ";
1478
+ else if (name === "noBreakHyphen") text2 += "\u2011";
1479
+ else if (name === "softHyphen") text2 += "\xAD";
1480
+ else if (name === "cr" || name === "br" && !["page", "column"].includes(
1481
+ current.attributes.find((a) => a.localName === "type" && a.namespace === node.namespace)?.value ?? ""
1482
+ ))
1483
+ text2 += "\n";
1484
+ else if (["p", "hyperlink", "r"].includes(name)) {
1485
+ const content = children(current);
1486
+ for (let index2 = content.length - 1; index2 >= 0; index2--) pending.push(content[index2]);
1487
+ }
1488
+ }
1489
+ return text2;
1490
+ }
1491
+ var Paragraph = class _Paragraph {
1492
+ constructor(store, ref) {
1493
+ this.store = store;
1494
+ this.ref = ref;
1495
+ }
1496
+ store;
1497
+ ref;
1498
+ equals(other) {
1499
+ requireComparisonOperand(other);
1500
+ this.store.node(this.ref);
1501
+ return other instanceof _Paragraph && other.store === this.store && this.store.node(this.ref) === other.store.node(other.ref);
1502
+ }
1503
+ get element() {
1504
+ return this.store.element(this.ref);
1505
+ }
1506
+ get part() {
1507
+ this.store.node(this.ref);
1508
+ return this.store.part(this.ref.part, true);
1509
+ }
1510
+ get text() {
1511
+ return modelText(this.store.node(this.ref), activeModelChildren(this.store, this.ref.part));
1512
+ }
1513
+ set text(value) {
1514
+ if (value !== null && typeof value !== "string") throw new InputTypeError("Expected paragraph text or null.");
1515
+ this.store.change(this.ref.part, (xml) => {
1516
+ const p = this.store.node(this.ref);
1517
+ const props = activeModelChildren(this.store, this.ref.part)(p).find(
1518
+ (child) => child.namespace === p.namespace && child.localName === "pPr"
1519
+ );
1520
+ xml.replaceElement(
1521
+ p,
1522
+ replaceParagraphContent(xml, p, props ? xml.sourceXml(props) : "", value ?? "", this.store.context.budget, { graph: () => new DocumentPackage(this.store.snapshot(), this.store.context.limits, this.store.context.budget), owner: this.ref.part, context: this.store.context })
1523
+ );
1524
+ });
1525
+ }
1526
+ get runs() {
1527
+ const p = this.store.node(this.ref);
1528
+ return snapshotSequence(activeModelChildren(this.store, this.ref.part)(p).filter((child) => child.namespace === p.namespace && child.localName === "r").map((child) => this.store.run(this.store.ref(this.ref.part, child))));
1529
+ }
1530
+ get hyperlinks() {
1531
+ const p = this.store.node(this.ref);
1532
+ return snapshotSequence(activeModelChildren(this.store, this.ref.part)(p).filter((child) => child.namespace === p.namespace && child.localName === "hyperlink").map((child) => new Hyperlink(this.store, this.store.ref(this.ref.part, child))));
1533
+ }
1534
+ *iter_inner_content() {
1535
+ const p = this.store.node(this.ref);
1536
+ for (const child of activeModelChildren(this.store, this.ref.part)(p)) {
1537
+ this.store.context.budget.charge("work", 1);
1538
+ if (child.namespace !== p.namespace) continue;
1539
+ if (child.localName === "r") yield this.store.run(this.store.ref(this.ref.part, child));
1540
+ if (child.localName === "hyperlink")
1541
+ yield new Hyperlink(this.store, this.store.ref(this.ref.part, child));
1542
+ }
1543
+ }
1544
+ get rendered_page_breaks() {
1545
+ const p = this.store.node(this.ref);
1546
+ const children = activeModelChildren(this.store, this.ref.part);
1547
+ const result = [];
1548
+ const pending = [p];
1549
+ this.store.context.budget.charge("retainedBytes", 8);
1550
+ while (pending.length) {
1551
+ const node = pending.pop();
1552
+ this.store.context.budget.charge("work", 1);
1553
+ if (node.namespace !== p.namespace) continue;
1554
+ if (node.localName === "lastRenderedPageBreak")
1555
+ result.push(
1556
+ new RenderedPageBreak(this.store, this.store.ref(this.ref.part, node), this.ref)
1557
+ );
1558
+ else {
1559
+ const nested = children(node);
1560
+ this.store.context.budget.charge("work", nested.length);
1561
+ this.store.context.budget.charge("retainedBytes", nested.length * 8);
1562
+ for (let index2 = nested.length - 1; index2 >= 0; index2--) pending.push(nested[index2]);
1563
+ }
1564
+ }
1565
+ return snapshotSequence(result);
1566
+ }
1567
+ get contains_page_break() {
1568
+ return this.rendered_page_breaks.length > 0;
1569
+ }
1570
+ get paragraph_format() {
1571
+ return new ParagraphFormat(modelFormattingOwner(this.store, this.ref));
1572
+ }
1573
+ get alignment() {
1574
+ return this.paragraph_format.alignment;
1575
+ }
1576
+ set alignment(value) {
1577
+ this.paragraph_format.alignment = value;
1578
+ }
1579
+ get style() {
1580
+ const p = this.store.node(this.ref);
1581
+ const children = activeModelChildren(this.store, this.ref.part);
1582
+ const props = children(p).find((child) => child.namespace === p.namespace && child.localName === "pPr");
1583
+ const id2 = props ? children(props).find((child) => child.namespace === p.namespace && child.localName === "pStyle")?.attributes.find((a) => a.namespace === p.namespace && a.localName === "val")?.value ?? null : null;
1584
+ return this.store.stylesForStory(this.ref.part).get_by_id(id2, WD_STYLE_TYPE.PARAGRAPH);
1585
+ }
1586
+ set style(value) {
1587
+ const id2 = this.store.stylesForStory(this.ref.part).get_style_id(value, WD_STYLE_TYPE.PARAGRAPH);
1588
+ this.store.change(this.ref.part, (xml) => {
1589
+ const children = activeModelChildren(this.store, this.ref.part);
1590
+ const p = this.store.node(this.ref), props = children(p).find((child) => child.namespace === p.namespace && child.localName === "pPr");
1591
+ const old = props && children(props).find((child) => child.namespace === p.namespace && child.localName === "pStyle");
1592
+ const replacement = id2 === null ? "" : `<bm:pStyle xmlns:bm="${p.namespace}" bm:val="${xmlValue(id2)}"/>`;
1593
+ if (old) xml.replaceElement(old, replacement);
1594
+ else if (replacement) {
1595
+ if (props) xml.insertChildren(props, replacement, props.children[0]);
1596
+ else
1597
+ xml.insertChildren(
1598
+ p,
1599
+ `<bm:pPr xmlns:bm="${p.namespace}">${replacement}</bm:pPr>`,
1600
+ p.children[0]
1601
+ );
1602
+ } else if (!props) {
1603
+ xml.insertChildren(p, `<bm:pPr xmlns:bm="${p.namespace}"/>`, p.children[0]);
1604
+ }
1605
+ });
1606
+ }
1607
+ add_run(text2, style) {
1608
+ if (text2 !== void 0 && text2 !== null && typeof text2 !== "string")
1609
+ throw new InputTypeError("Expected run text.");
1610
+ return this.store.transaction(() => {
1611
+ const styleId = style === void 0 || style === null ? null : this.store.stylesForStory(this.ref.part).get_style_id(style, WD_STYLE_TYPE.CHARACTER);
1612
+ this.store.change(this.ref.part, (xml) => {
1613
+ const p2 = this.store.node(this.ref);
1614
+ assertFormattingHistoryEditable(xml.root, p2, activeXmlChildren(xml, this.store.context.budget), this.store.context.budget);
1615
+ xml.insertChildren(p2, paragraphTextRun(p2.namespace, text2 ?? "", styleId ?? void 0));
1616
+ });
1617
+ const p = this.store.node(this.ref);
1618
+ return this.store.run(this.store.ref(this.ref.part, p.children.at(-1)));
1619
+ });
1620
+ }
1621
+ clear() {
1622
+ this.text = "";
1623
+ return this;
1624
+ }
1625
+ insert_paragraph_before(text2, style) {
1626
+ if (text2 !== void 0 && text2 !== null && typeof text2 !== "string")
1627
+ throw new InputTypeError("Expected paragraph text or null.");
1628
+ return this.store.transaction(() => {
1629
+ const styleId = style === void 0 || style === null ? null : this.store.stylesForStory(this.ref.part).get_style_id(style, WD_STYLE_TYPE.PARAGRAPH);
1630
+ const p = this.store.node(this.ref);
1631
+ let path;
1632
+ this.store.change(this.ref.part, (editor) => {
1633
+ assertFormattingHistoryEditable(editor.root, this.store.node(this.ref), activeXmlChildren(editor, this.store.context.budget), this.store.context.budget);
1634
+ path = editor[insertParagraphBefore](
1635
+ this.store.node(this.ref),
1636
+ `<bm:p xmlns:bm="${p.namespace}">${styleId ? `<bm:pPr><bm:pStyle bm:val="${xmlValue(styleId)}"/></bm:pPr>` : ""}${text2 ? paragraphTextRun(p.namespace, text2) : ""}</bm:p>`
1637
+ );
1638
+ });
1639
+ let inserted = this.store.xml(this.ref.part).root;
1640
+ for (const index2 of path) inserted = inserted.children[index2];
1641
+ return this.store.paragraph(this.store.ref(this.ref.part, inserted));
1642
+ });
1643
+ }
1644
+ };
1645
+ var Run = class _Run {
1646
+ constructor(store, ref) {
1647
+ this.store = store;
1648
+ this.ref = ref;
1649
+ }
1650
+ store;
1651
+ ref;
1652
+ equals(other) {
1653
+ requireComparisonOperand(other);
1654
+ this.store.node(this.ref);
1655
+ return other instanceof _Run && other.store === this.store && this.store.node(this.ref) === other.store.node(other.ref);
1656
+ }
1657
+ get element() {
1658
+ return this.store.element(this.ref);
1659
+ }
1660
+ get part() {
1661
+ this.store.node(this.ref);
1662
+ return this.store.part(this.ref.part, true);
1663
+ }
1664
+ get text() {
1665
+ return modelText(this.store.node(this.ref), activeModelChildren(this.store, this.ref.part));
1666
+ }
1667
+ set text(value) {
1668
+ if (typeof value !== "string") throw new InputTypeError("Expected run text.");
1669
+ this.store.change(this.ref.part, (xml) => {
1670
+ const r = this.store.node(this.ref);
1671
+ const props = activeModelChildren(this.store, this.ref.part)(r).find(
1672
+ (child) => child.localName === "rPr" && child.namespace === r.namespace
1673
+ );
1674
+ xml.replaceElement(r, replaceRunContent(xml, r, props ? xml.sourceXml(props) : "", value, this.store.context.budget, { graph: () => new DocumentPackage(this.store.snapshot(), this.store.context.limits, this.store.context.budget), owner: this.ref.part, context: this.store.context }));
1675
+ });
1676
+ }
1677
+ get style() {
1678
+ const r = this.store.node(this.ref);
1679
+ const children = activeModelChildren(this.store, this.ref.part);
1680
+ const props = children(r).find((child) => child.namespace === r.namespace && child.localName === "rPr");
1681
+ const id2 = props ? children(props).find((child) => child.namespace === r.namespace && child.localName === "rStyle")?.attributes.find((a) => a.namespace === r.namespace && a.localName === "val")?.value ?? null : null;
1682
+ return this.store.stylesForStory(this.ref.part).get_by_id(id2, WD_STYLE_TYPE.CHARACTER);
1683
+ }
1684
+ set style(value) {
1685
+ const id2 = this.store.stylesForStory(this.ref.part).get_style_id(value, WD_STYLE_TYPE.CHARACTER);
1686
+ this.store.change(this.ref.part, (xml) => {
1687
+ const children = activeModelChildren(this.store, this.ref.part);
1688
+ const r = this.store.node(this.ref), props = children(r).find((child) => child.namespace === r.namespace && child.localName === "rPr");
1689
+ const old = props && children(props).find((child) => child.namespace === r.namespace && child.localName === "rStyle");
1690
+ const replacement = id2 === null ? "" : `<bm:rStyle xmlns:bm="${r.namespace}" bm:val="${xmlValue(id2)}"/>`;
1691
+ if (old) xml.replaceElement(old, replacement);
1692
+ else if (props) {
1693
+ if (replacement) xml.insertChildren(props, replacement, props.children[0]);
1694
+ } else
1695
+ xml.insertChildren(
1696
+ r,
1697
+ `<bm:rPr xmlns:bm="${r.namespace}">${replacement}</bm:rPr>`,
1698
+ r.children[0]
1699
+ );
1700
+ });
1701
+ }
1702
+ get font() {
1703
+ return new Font(modelFormattingOwner(this.store, this.ref));
1704
+ }
1705
+ get bold() {
1706
+ return this.font.bold;
1707
+ }
1708
+ set bold(value) {
1709
+ this.font.bold = value;
1710
+ }
1711
+ get italic() {
1712
+ return this.font.italic;
1713
+ }
1714
+ set italic(value) {
1715
+ this.font.italic = value;
1716
+ }
1717
+ get underline() {
1718
+ return this.font.underline;
1719
+ }
1720
+ set underline(value) {
1721
+ this.font.underline = value;
1722
+ }
1723
+ clear() {
1724
+ this.text = "";
1725
+ return this;
1726
+ }
1727
+ add_text(text2) {
1728
+ if (typeof text2 !== "string") throw new InputTypeError("Expected run text.");
1729
+ this.store.change(this.ref.part, (xml) => {
1730
+ const r = this.store.node(this.ref);
1731
+ xml.insertChildren(
1732
+ r,
1733
+ `<bm:t xmlns:bm="${r.namespace}" xml:space="preserve">${xmlValue(text2)}</bm:t>`
1734
+ );
1735
+ });
1736
+ return this.element.children.at(-1);
1737
+ }
1738
+ add_tab() {
1739
+ this.store.change(this.ref.part, (xml) => {
1740
+ const r = this.store.node(this.ref);
1741
+ xml.insertChildren(r, `<bm:tab xmlns:bm="${r.namespace}"/>`);
1742
+ });
1743
+ }
1744
+ add_break(type = WD_BREAK.LINE) {
1745
+ if (!isEnumMember(type) || type.enum !== "WD_BREAK_TYPE")
1746
+ throw new InputTypeError("Expected a trusted break enum.");
1747
+ const attributes = {
1748
+ LINE: "",
1749
+ PAGE: ' bm:type="page"',
1750
+ COLUMN: ' bm:type="column"',
1751
+ LINE_CLEAR_LEFT: ' bm:clear="left"',
1752
+ LINE_CLEAR_RIGHT: ' bm:clear="right"',
1753
+ LINE_CLEAR_ALL: ' bm:clear="all"'
1754
+ };
1755
+ const markup = attributes[type.name];
1756
+ if (markup === void 0) throw new InputTypeError("The break cannot be inserted in a run.");
1757
+ this.store.change(this.ref.part, (xml) => {
1758
+ const r = this.store.node(this.ref);
1759
+ xml.insertChildren(r, `<bm:br xmlns:bm="${r.namespace}"${markup}/>`);
1760
+ });
1761
+ }
1762
+ mark_comment_range(last_run, comment_id) {
1763
+ this.store.transaction(() => markCommentRange(this.store, this, last_run, comment_id));
1764
+ }
1765
+ async add_picture(input, width, height) {
1766
+ const image = await Image.from_file(input, this.store.context);
1767
+ return insertModelImage(this.store, this.ref, image, width, height);
1768
+ }
1769
+ get contains_page_break() {
1770
+ const r = this.store.node(this.ref);
1771
+ return activeModelChildren(this.store, this.ref.part)(r).some(
1772
+ (child) => child.localName === "lastRenderedPageBreak" && child.namespace === r.namespace
1773
+ );
1774
+ }
1775
+ *iter_inner_content() {
1776
+ const run = this.store.node(this.ref);
1777
+ const pending = [
1778
+ { node: this.store.xml(this.ref.part).root }
1779
+ ];
1780
+ const budget = this.store.context.budget;
1781
+ budget.charge("retainedBytes", 16);
1782
+ let paragraph;
1783
+ while (pending.length) {
1784
+ const frame = pending.pop();
1785
+ budget.charge("work", 1);
1786
+ const owner = frame.node.localName === "p" && frame.node.namespace === run.namespace ? frame.node : frame.paragraph;
1787
+ if (frame.node === run) {
1788
+ paragraph = owner;
1789
+ break;
1790
+ }
1791
+ budget.charge("retainedBytes", frame.node.children.length * 16);
1792
+ for (let index2 = frame.node.children.length - 1; index2 >= 0; index2--)
1793
+ pending.push({ node: frame.node.children[index2], paragraph: owner });
1794
+ }
1795
+ let text2 = "";
1796
+ for (const child of activeModelChildren(this.store, this.ref.part)(run)) {
1797
+ this.store.context.budget.charge("work", 1);
1798
+ if (child.namespace !== run.namespace) continue;
1799
+ if (child.localName === "lastRenderedPageBreak") {
1800
+ if (text2) {
1801
+ yield text2;
1802
+ text2 = "";
1803
+ }
1804
+ if (paragraph) yield new RenderedPageBreak(this.store, this.store.ref(this.ref.part, child), this.store.ref(this.ref.part, paragraph));
1805
+ } else if (child.localName === "drawing") {
1806
+ if (text2) {
1807
+ yield text2;
1808
+ text2 = "";
1809
+ }
1810
+ yield new Drawing(this.store, this.store.ref(this.ref.part, child));
1811
+ } else if (["t", "tab", "ptab", "noBreakHyphen", "softHyphen", "br", "cr"].includes(child.localName)) {
1812
+ text2 += modelText(child);
1813
+ }
1814
+ }
1815
+ if (text2) yield text2;
1816
+ }
1817
+ };
1818
+
1819
+ // packages/safe-bash-docx-engine/src/document-model.ts
1820
+ var DocumentView = class _DocumentView {
1821
+ constructor(store, owner = store.mainPart) {
1822
+ this.store = store;
1823
+ const root = store.xml(owner).root;
1824
+ const body = activeModelChildren(store, owner)(root).find(
1825
+ (child) => child.namespace === root.namespace && child.localName === "body"
1826
+ );
1827
+ this.ref = store.ref(owner, body);
1828
+ }
1829
+ store;
1830
+ ref;
1831
+ boundSettings;
1832
+ boundInlineShapes;
1833
+ equals(other) {
1834
+ requireComparisonOperand(other);
1835
+ const node = this.store.node(this.ref);
1836
+ return other instanceof _DocumentView && other.store === this.store && other.store.node(other.ref) === node;
1837
+ }
1838
+ get part() {
1839
+ this.store.node(this.ref);
1840
+ const part = this.store.part(this.ref.part);
1841
+ if (!(part instanceof DocumentPartView)) throw new InputTypeError("Expected a native document owner.");
1842
+ return part;
1843
+ }
1844
+ get element() {
1845
+ return this.store.element(
1846
+ this.store.ref(this.ref.part, this.store.xml(this.ref.part).root)
1847
+ );
1848
+ }
1849
+ get paragraphs() {
1850
+ return snapshotSequence([...this.store.blocks(this.ref)].filter(
1851
+ (block) => this.store.node(block.ref).localName === "p"
1852
+ ));
1853
+ }
1854
+ get tables() {
1855
+ return snapshotSequence([...this.store.blocks(this.ref)].filter(
1856
+ (block) => this.store.node(block.ref).localName === "tbl"
1857
+ ));
1858
+ }
1859
+ get styles() {
1860
+ return this.store.stylesForDocument(this.ref.part);
1861
+ }
1862
+ get settings() {
1863
+ return this.boundSettings ??= new Settings(this.store, void 0, this.ref.part);
1864
+ }
1865
+ get inline_shapes() {
1866
+ return this.boundInlineShapes ??= new InlineShapes(this.store, this.ref);
1867
+ }
1868
+ async add_picture(input, width, height) {
1869
+ const image = await Image.from_file(input, this.store.context);
1870
+ return this.store.transaction(() => {
1871
+ const run = this.add_paragraph().add_run();
1872
+ return insertModelImage(this.store, run.ref, image, width, height);
1873
+ });
1874
+ }
1875
+ add_comment(runs, text2 = "", author = "", initials = "") {
1876
+ return this.store.transaction(() => bindCommentRange(this.store, runs, text2, author, initials, this.ref.part));
1877
+ }
1878
+ get sections() {
1879
+ return new Sections(this.store, this.ref);
1880
+ }
1881
+ get comments() {
1882
+ return new Comments(this.store, this.store.ensureComments(this.ref.part));
1883
+ }
1884
+ get core_properties() {
1885
+ return this.store.package.core_properties;
1886
+ }
1887
+ iter_inner_content() {
1888
+ return this.store.blocks(this.ref);
1889
+ }
1890
+ add_paragraph(text2 = "", style) {
1891
+ return this.store.addParagraph(this.ref, text2, style);
1892
+ }
1893
+ add_heading(text2 = "", level = 1) {
1894
+ if (typeof text2 !== "string" || !Number.isSafeInteger(level))
1895
+ throw new InputTypeError("Expected heading text and an integer level.");
1896
+ if (level < 0 || level > 9)
1897
+ throw new InvalidValueError("Heading level must be between 0 and 9.");
1898
+ return this.store.transaction(() => {
1899
+ const style = this.styles[resolveHeadingStyle](level);
1900
+ return this.store.addParagraph(this.ref, text2, style);
1901
+ });
1902
+ }
1903
+ add_page_break() {
1904
+ return this.store.transaction(() => {
1905
+ const paragraph = this.store.addParagraph(this.ref);
1906
+ paragraph.add_run().add_break(WD_BREAK.PAGE);
1907
+ return paragraph;
1908
+ });
1909
+ }
1910
+ add_section(start_type = WD_SECTION_START.NEW_PAGE) {
1911
+ if (!Object.values(WD_SECTION_START).includes(start_type))
1912
+ throw new InputTypeError("Expected a section start enum.");
1913
+ return this.store.transaction(() => {
1914
+ this.store.change(this.ref.part, (xml) => {
1915
+ const body = this.store.node(this.ref), section2 = activeModelChildren(this.store, this.ref.part)(body).find(
1916
+ (node) => node.namespace === body.namespace && node.localName === "sectPr"
1917
+ );
1918
+ const old = section2 ? runElementOpen(section2) + xml.sourceXml(section2, /* @__PURE__ */ new Map(), true) + `</${section2.name}>` : `<ds:sectPr xmlns:ds="${body.namespace}"/>`;
1919
+ xml[appendBodyBlocks](
1920
+ body,
1921
+ `<ds:p xmlns:ds="${body.namespace}"><ds:pPr>${old}</ds:pPr></ds:p>` + (section2 ? "" : old)
1922
+ );
1923
+ });
1924
+ this.store.change(this.ref.part, (xml) => {
1925
+ const section2 = this.store.node(this.sections.at(-1).ref);
1926
+ const bindings = activeModelChildren(this.store, this.ref.part)(section2).filter(
1927
+ (node) => node.namespace === section2.namespace && ["headerReference", "footerReference"].includes(node.localName)
1928
+ );
1929
+ const variants = /* @__PURE__ */ new Set();
1930
+ for (const binding of bindings) {
1931
+ const variant = sectionAttribute(binding, "type"), key = binding.localName + ":" + variant;
1932
+ if (!variant || !["default", "first", "even"].includes(variant) || variants.has(key))
1933
+ throw new UnsupportedEditError("Ambiguous section story bindings cannot be inherited.");
1934
+ variants.add(key);
1935
+ }
1936
+ xml.replaceElement(section2, xml.sourceXml(section2, new Map(bindings.map((binding) => [binding, ""]))));
1937
+ });
1938
+ const section = this.sections.at(-1);
1939
+ section.start_type = start_type;
1940
+ return section;
1941
+ });
1942
+ }
1943
+ add_table(rows, cols, style, width) {
1944
+ if (isLength(style)) {
1945
+ if (width !== void 0) throw new InputTypeError("Choose one table width.");
1946
+ width = style;
1947
+ style = void 0;
1948
+ }
1949
+ if (width !== void 0 && !isLength(width)) throw new InputTypeError("Expected a table width length.");
1950
+ if (width === void 0) {
1951
+ const section = this.sections.at(-1);
1952
+ const page = section.page_width, left = section.left_margin, right = section.right_margin;
1953
+ width = Emu((page ?? Inches(8.5)).emu - (left ?? Inches(1)).emu - (right ?? Inches(1)).emu);
1954
+ }
1955
+ return this.store.transaction(() => {
1956
+ const table = this.store.addTable(this.ref, rows, cols, width);
1957
+ if (style !== void 0 && style !== null) table.style = style;
1958
+ return table;
1959
+ });
1960
+ }
1961
+ async save(output, options) {
1962
+ await this.store.save(output, options);
1963
+ }
1964
+ };
1965
+ async function Document(input, context) {
1966
+ const { archive, settings, source } = await admitDocumentModel(input, context);
1967
+ const store = new ModelStore(archive, settings, archive.mainPart, source);
1968
+ await store.package[packageAdmitImages]();
1969
+ return store.document;
1970
+ }
1971
+
1972
+ // packages/safe-bash-docx-engine/src/table-model.ts
1973
+ var orders = {
1974
+ tblPr: "tblStyle tblpPr tblOverlap bidiVisual tblStyleRowBandSize tblStyleColBandSize tblW jc tblCellSpacing tblInd tblBorders shd tblLayout tblCellMar tblLook tblCaption tblDescription tblPrChange".split(
1975
+ " "
1976
+ ),
1977
+ trPr: "cnfStyle divId gridBefore gridAfter wBefore wAfter cantSplit trHeight tblHeader tblCellSpacing jc hidden ins del trPrChange".split(
1978
+ " "
1979
+ ),
1980
+ tcPr: "cnfStyle tcW gridSpan hMerge vMerge tcBorders shd noWrap tcMar textDirection tcFitText vAlign hideMark cellIns cellDel cellMerge tcPrChange".split(
1981
+ " "
1982
+ )
1983
+ };
1984
+ function mark(w, tag, attrs = {}, body = "") {
1985
+ return `<tm:${tag} xmlns:tm="${w}"${Object.entries(attrs).map(([k, v]) => ` tm:${k}="${xmlValue(v)}"`).join("")}>${body}</tm:${tag}>`;
1986
+ }
1987
+ function index(length, value) {
1988
+ if (!Number.isSafeInteger(value)) throw new InputTypeError("Expected an integer index.");
1989
+ const result = value < 0 ? length + value : value;
1990
+ if (result < 0 || result >= length) throw new BoundsError("Table index is out of range.");
1991
+ return result;
1992
+ }
1993
+ function enumName(value, family, names) {
1994
+ if (value === null) return null;
1995
+ enumValue(value);
1996
+ if (value.enum !== family) throw new InputTypeError(`Expected ${family}.`);
1997
+ if (!Object.hasOwn(names, value.name)) throw new InvalidValueError(`Unknown ${family} value.`);
1998
+ return names[value.name];
1999
+ }
2000
+ function readEnum(raw, symbols, names) {
2001
+ if (raw === void 0) return null;
2002
+ const name = Object.keys(names).find((k) => names[k] === raw);
2003
+ if (!name) throw new InvalidDocumentError("Unknown stored table enumeration value.");
2004
+ return symbols[name];
2005
+ }
2006
+ function properties(store, ref, container, tag, values) {
2007
+ store.change(ref.part, (xml) => {
2008
+ const children = activeModelChildren(store, ref.part);
2009
+ const owner = store.node(ref), props = styleChild(owner, container, children), old = styleChild(props, tag, children);
2010
+ if (!values && !old) return;
2011
+ if (old && values) {
2012
+ const prefix = [...old.namespaces].find(([p, namespace]) => p && namespace === owner.namespace)?.[0] ?? "tm";
2013
+ const attributes = old.attributes.map(
2014
+ (a) => a.namespace === owner.namespace && Object.hasOwn(values, a.localName) ? { ...a, value: values[a.localName] } : a
2015
+ );
2016
+ for (const [localName, value] of Object.entries(values))
2017
+ if (!attributes.some((a) => a.namespace === owner.namespace && a.localName === localName))
2018
+ attributes.push({ name: `${prefix}:${localName}`, namespace: owner.namespace, localName, value });
2019
+ const namespaces = new Map(old.namespaces);
2020
+ namespaces.set(prefix, owner.namespace);
2021
+ xml.replaceElement(old, runElementOpen({ ...old, attributes, namespaces }) + xml.sourceXml(old, /* @__PURE__ */ new Map(), true) + `</${old.name}>`);
2022
+ return;
2023
+ }
2024
+ const markup = values ? mark(owner.namespace, tag, values) : "";
2025
+ if (old) xml.replaceElement(old, markup);
2026
+ else if (props) {
2027
+ const order = orders[container];
2028
+ xml.insertChildren(
2029
+ props,
2030
+ markup,
2031
+ props.children.find(
2032
+ (n) => n.namespace === owner.namespace && order.indexOf(n.localName) > order.indexOf(tag)
2033
+ )
2034
+ );
2035
+ } else
2036
+ xml.insertChildren(
2037
+ owner,
2038
+ mark(owner.namespace, container, {}, markup),
2039
+ container === "trPr" && owner.children[0]?.localName === "tblPrEx" ? owner.children[1] : owner.children[0]
2040
+ );
2041
+ });
2042
+ }
2043
+ function storedLength(node, key = "w") {
2044
+ const raw = styleAttribute(node, key);
2045
+ if (raw !== void 0) {
2046
+ const scale = { in: 914400, cm: 36e4, mm: 36e3, pt: 12700, pc: 152400, pi: 152400 }[raw.slice(-2)];
2047
+ if (scale !== void 0) {
2048
+ const magnitude = raw.slice(0, -2);
2049
+ if (!magnitude || [...magnitude].some((c) => !"0123456789.+-".includes(c)))
2050
+ throw new InputTypeError("Invalid stored table length.");
2051
+ return Length(Number(magnitude) * scale);
2052
+ }
2053
+ }
2054
+ const n = styleInteger(raw);
2055
+ return n === null ? null : Length(n * 635);
2056
+ }
2057
+ var tableGrids = /* @__PURE__ */ new WeakMap();
2058
+ function readProperty(store, ref, container, name) {
2059
+ const children = activeModelChildren(store, ref.part);
2060
+ return styleChild(styleChild(store.node(ref), container, children), name, children);
2061
+ }
2062
+ function activeGrid(store, ref) {
2063
+ const table = store.node(ref), budget = store.context.budget;
2064
+ budget.charge("work", 1);
2065
+ let cache = tableGrids.get(store);
2066
+ const existing = cache?.get(table);
2067
+ if (existing) return existing;
2068
+ if (!cache) {
2069
+ cache = /* @__PURE__ */ new WeakMap();
2070
+ tableGrids.set(store, cache);
2071
+ }
2072
+ const children = activeModelChildren(store, ref.part);
2073
+ const rows = tableRows(
2074
+ table,
2075
+ (n) => n,
2076
+ children,
2077
+ store.context.budget
2078
+ );
2079
+ if (!rows.length) {
2080
+ const grid2 = styleChild(table, "tblGrid", children);
2081
+ const columns = grid2 ? children(grid2).filter((n) => n.namespace === table.namespace && n.localName === "gridCol") : [];
2082
+ store.context.budget.check("tableColumns", columns.length);
2083
+ const value2 = { rows: [], columns, owners: [], physical: [], slots: [], original: (n) => n };
2084
+ budget.charge("retainedBytes", 128 + columns.length * 8);
2085
+ cache.set(table, value2);
2086
+ return value2;
2087
+ }
2088
+ const copy = (n) => {
2089
+ const enter = (node) => {
2090
+ const nodes = children(node);
2091
+ budget.charge("retainedBytes", 128 + nodes.length * 8);
2092
+ return { nodes, copy: { ...node, children: [] }, index: 0 };
2093
+ };
2094
+ const first = enter(n), pending = [first];
2095
+ while (pending.length) {
2096
+ const frame = pending.at(-1);
2097
+ if (frame.index >= frame.nodes.length) {
2098
+ pending.pop();
2099
+ continue;
2100
+ }
2101
+ const next = enter(frame.nodes[frame.index++]);
2102
+ frame.copy.children.push(next.copy);
2103
+ pending.push(next);
2104
+ }
2105
+ return first.copy;
2106
+ };
2107
+ const copied = copy(table), view = {
2108
+ ...copied,
2109
+ children: [
2110
+ ...copied.children.filter((n) => n.localName !== "tr" && n.localName !== "sdt"),
2111
+ ...rows.map(copy)
2112
+ ]
2113
+ };
2114
+ const grid = mergedTableGrid(view, store.context.budget);
2115
+ const originals = /* @__PURE__ */ new Map();
2116
+ const match = (a, b) => {
2117
+ const pending = [{ source: a, copy: b }];
2118
+ while (pending.length) {
2119
+ const { source, copy: copy2 } = pending.pop();
2120
+ originals.set(copy2, source);
2121
+ const kids = children(source);
2122
+ for (let index2 = kids.length - 1; index2 >= 0; index2--) {
2123
+ const copied2 = copy2.children[index2];
2124
+ if (copied2) pending.push({ source: kids[index2], copy: copied2 });
2125
+ }
2126
+ }
2127
+ };
2128
+ const gridSource = children(table).find(
2129
+ (n) => n.namespace === table.namespace && n.localName === "tblGrid"
2130
+ );
2131
+ if (gridSource) match(gridSource, styleChild(view, "tblGrid"));
2132
+ rows.forEach((row, i) => match(row, grid.rows[i]));
2133
+ const value = { ...grid, original: (n) => originals.get(n) ?? n };
2134
+ budget.charge("retainedBytes", 128 + originals.size * 32);
2135
+ cache.set(table, value);
2136
+ return value;
2137
+ }
2138
+ var Table = class {
2139
+ constructor(store, ref) {
2140
+ this.store = store;
2141
+ this.ref = ref;
2142
+ this.rows = new _Rows(this);
2143
+ this.columns = new _Columns(this);
2144
+ }
2145
+ store;
2146
+ ref;
2147
+ cellCache = /* @__PURE__ */ new Map();
2148
+ rows;
2149
+ columns;
2150
+ get part() {
2151
+ this.store.node(this.ref);
2152
+ return this.store.part(this.ref.part, true);
2153
+ }
2154
+ get element() {
2155
+ return this.store.element(this.ref);
2156
+ }
2157
+ get table() {
2158
+ this.store.node(this.ref);
2159
+ return this;
2160
+ }
2161
+ grid() {
2162
+ return activeGrid(this.store, this.ref);
2163
+ }
2164
+ logicalCell(node) {
2165
+ const ref = this.store.ref(this.ref.part, node);
2166
+ let cell = this.cellCache.get(ref.id);
2167
+ if (!cell) {
2168
+ cell = new _Cell(this.store, ref, this);
2169
+ this.cellCache.set(ref.id, cell);
2170
+ }
2171
+ return cell;
2172
+ }
2173
+ cell(row_idx, col_idx) {
2174
+ const grid = this.grid(), row = index(grid.rows.length, row_idx), column = index(grid.columns.length, col_idx), owner = grid.slots[row]?.[column];
2175
+ if (!owner) throw new BoundsError("The selected grid slot is omitted.");
2176
+ return this.logicalCell(grid.original(owner.node));
2177
+ }
2178
+ row_cells(row_idx) {
2179
+ const grid = this.grid(), row = index(grid.rows.length, row_idx);
2180
+ return snapshotSequence(grid.slots[row].filter((o) => o !== void 0).map(
2181
+ (o) => this.logicalCell(grid.original(o.node))
2182
+ ));
2183
+ }
2184
+ column_cells(column_idx) {
2185
+ const grid = this.grid(), column = index(grid.columns.length, column_idx);
2186
+ return snapshotSequence(grid.slots.flatMap(
2187
+ (row) => row[column] ? [this.logicalCell(grid.original(row[column].node))] : []
2188
+ ));
2189
+ }
2190
+ get alignment() {
2191
+ return readEnum(
2192
+ styleAttribute(readProperty(this.store, this.ref, "tblPr", "jc"), "val"),
2193
+ WD_TABLE_ALIGNMENT,
2194
+ { LEFT: "left", CENTER: "center", RIGHT: "right" }
2195
+ );
2196
+ }
2197
+ set alignment(value) {
2198
+ const name = enumName(value, "WD_TABLE_ALIGNMENT", {
2199
+ LEFT: "left",
2200
+ CENTER: "center",
2201
+ RIGHT: "right"
2202
+ });
2203
+ properties(this.store, this.ref, "tblPr", "jc", name === null ? null : { val: name });
2204
+ }
2205
+ get autofit() {
2206
+ return styleAttribute(readProperty(this.store, this.ref, "tblPr", "tblLayout"), "type") !== "fixed";
2207
+ }
2208
+ set autofit(value) {
2209
+ if (typeof value !== "boolean") throw new TypeError("Expected a boolean.");
2210
+ properties(this.store, this.ref, "tblPr", "tblLayout", { type: value ? "autofit" : "fixed" });
2211
+ }
2212
+ get table_direction() {
2213
+ const value = styleToggle(readProperty(this.store, this.ref, "tblPr", "bidiVisual"));
2214
+ return value === null ? null : value ? WD_TABLE_DIRECTION.RTL : WD_TABLE_DIRECTION.LTR;
2215
+ }
2216
+ set table_direction(value) {
2217
+ const name = enumName(value, "WD_TABLE_DIRECTION", { LTR: "0", RTL: "1" });
2218
+ properties(this.store, this.ref, "tblPr", "bidiVisual", name === null ? null : { val: name });
2219
+ }
2220
+ get style() {
2221
+ return this.store.tableStyle(
2222
+ styleAttribute(readProperty(this.store, this.ref, "tblPr", "tblStyle"), "val") ?? null,
2223
+ this.ref.part
2224
+ );
2225
+ }
2226
+ set style(value) {
2227
+ const id2 = this.store.tableStyleId(value, this.ref.part);
2228
+ properties(this.store, this.ref, "tblPr", "tblStyle", id2 === null ? null : { val: id2 });
2229
+ }
2230
+ add_row() {
2231
+ const grid = this.grid();
2232
+ if (!grid.columns.length) throw new InvalidValueError("Adding a row requires declared columns.");
2233
+ this.store.context.budget.table(grid.rows.length + 1, grid.columns.length);
2234
+ this.store.change(this.ref.part, (xml) => {
2235
+ const table = this.store.node(this.ref), cells = grid.columns.map(
2236
+ (c) => mark(
2237
+ table.namespace,
2238
+ "tc",
2239
+ {},
2240
+ mark(
2241
+ table.namespace,
2242
+ "tcPr",
2243
+ {},
2244
+ mark(table.namespace, "tcW", { w: styleAttribute(c, "w") ?? "0", type: "dxa" })
2245
+ ) + mark(table.namespace, "p")
2246
+ )
2247
+ ).join("");
2248
+ xml.insertChildren(table, mark(table.namespace, "tr", {}, cells));
2249
+ });
2250
+ return this.rows.at(-1);
2251
+ }
2252
+ add_column(width) {
2253
+ const value = String(twips(width, false)), grid = this.grid(), rowRefs = grid.rows.map((row) => this.store.ref(this.ref.part, grid.original(row)));
2254
+ if (grid.slots.some((slots) => slots.filter(Boolean).length !== grid.columns.length))
2255
+ throw new UnsupportedEditError("Adding columns requires a rectangular table without omitted cells.");
2256
+ if (grid.rows.length) this.store.context.budget.table(grid.rows.length, grid.columns.length + 1);
2257
+ else this.store.context.budget.check("tableColumns", grid.columns.length + 1);
2258
+ this.store.change(this.ref.part, (xml) => {
2259
+ const table = this.store.node(this.ref), decl = styleChild(table, "tblGrid", activeModelChildren(this.store, this.ref.part));
2260
+ xml.insertChildren(decl, mark(table.namespace, "gridCol", { w: value }));
2261
+ for (const row of rowRefs)
2262
+ xml.insertChildren(
2263
+ this.store.node(row),
2264
+ mark(
2265
+ table.namespace,
2266
+ "tc",
2267
+ {},
2268
+ mark(
2269
+ table.namespace,
2270
+ "tcPr",
2271
+ {},
2272
+ mark(table.namespace, "tcW", { w: value, type: "dxa" })
2273
+ ) + mark(table.namespace, "p")
2274
+ )
2275
+ );
2276
+ });
2277
+ return this.columns.at(-1);
2278
+ }
2279
+ };
2280
+ var _Cell = class __Cell {
2281
+ constructor(store, ref, owner) {
2282
+ this.store = store;
2283
+ this.ref = ref;
2284
+ this.owner = owner;
2285
+ }
2286
+ store;
2287
+ ref;
2288
+ owner;
2289
+ get table() {
2290
+ this.store.node(this.ref);
2291
+ return this.owner;
2292
+ }
2293
+ get part() {
2294
+ this.store.node(this.ref);
2295
+ return this.store.part(this.ref.part, true);
2296
+ }
2297
+ get element() {
2298
+ return this.store.element(this.ref);
2299
+ }
2300
+ get grid_span() {
2301
+ return tableGridCount(readProperty(this.store, this.ref, "tcPr", "gridSpan"), 1);
2302
+ }
2303
+ *iter_inner_content() {
2304
+ yield* this.store.blocks(this.ref);
2305
+ }
2306
+ get paragraphs() {
2307
+ return snapshotSequence([...this.iter_inner_content()].filter((n) => !(n instanceof Table)));
2308
+ }
2309
+ get tables() {
2310
+ return snapshotSequence([...this.iter_inner_content()].filter((n) => n instanceof Table));
2311
+ }
2312
+ get text() {
2313
+ return this.paragraphs.map((p) => p.text).join("\n");
2314
+ }
2315
+ set text(value) {
2316
+ if (typeof value !== "string") throw new InputTypeError("Expected text.");
2317
+ this.store.cellText(this.ref, value);
2318
+ }
2319
+ add_paragraph(text2 = "", style = null) {
2320
+ return this.store.addParagraph(this.ref, text2, style);
2321
+ }
2322
+ add_table(rows, cols) {
2323
+ return this.store.addTable(this.ref, rows, cols, this.width ?? Length(914400));
2324
+ }
2325
+ get vertical_alignment() {
2326
+ return readEnum(
2327
+ styleAttribute(readProperty(this.store, this.ref, "tcPr", "vAlign"), "val"),
2328
+ WD_CELL_VERTICAL_ALIGNMENT,
2329
+ { TOP: "top", CENTER: "center", BOTTOM: "bottom", BOTH: "both" }
2330
+ );
2331
+ }
2332
+ set vertical_alignment(value) {
2333
+ const name = enumName(value, "WD_CELL_VERTICAL_ALIGNMENT", {
2334
+ TOP: "top",
2335
+ CENTER: "center",
2336
+ BOTTOM: "bottom",
2337
+ BOTH: "both"
2338
+ });
2339
+ properties(this.store, this.ref, "tcPr", "vAlign", name === null ? null : { val: name });
2340
+ }
2341
+ get width() {
2342
+ const node = readProperty(this.store, this.ref, "tcPr", "tcW");
2343
+ return styleAttribute(node, "type") === "dxa" ? storedLength(node) : null;
2344
+ }
2345
+ set width(value) {
2346
+ properties(
2347
+ this.store,
2348
+ this.ref,
2349
+ "tcPr",
2350
+ "tcW",
2351
+ value === null ? null : { w: String(twips(value, false)), type: "dxa" }
2352
+ );
2353
+ }
2354
+ merge(other_cell) {
2355
+ const tableOwner = this.table;
2356
+ if (!(other_cell instanceof __Cell) || other_cell.table !== this.table)
2357
+ throw new TypeError("Merge requires cells from the same table.");
2358
+ const grid = this.table.grid(), a = grid.owners.find((o) => grid.original(o.node) === this.store.node(this.ref)), b = grid.owners.find((o) => grid.original(o.node) === this.store.node(other_cell.ref));
2359
+ for (const [start, size] of [["row", "rowSpan"], ["column", "columnSpan"]]) {
2360
+ const aStart = a[start], bStart = b[start], aEnd = aStart + a[size], bEnd = bStart + b[size];
2361
+ if (aStart === bStart && aEnd !== bEnd || aStart < bStart && aEnd > bEnd || bStart < aStart && bEnd > aEnd)
2362
+ throw new InvalidValueError("Merge endpoints do not define a rectangle.");
2363
+ }
2364
+ const top = Math.min(a.row, b.row), left = Math.min(a.column, b.column), bottom = Math.max(a.row + a.rowSpan - 1, b.row + b.rowSpan - 1), right = Math.max(a.column + a.columnSpan - 1, b.column + b.columnSpan - 1);
2365
+ const coordinate = (r, c) => {
2366
+ let s = "", n = c + 1;
2367
+ while (n) {
2368
+ n--;
2369
+ s = String.fromCharCode(65 + n % 26) + s;
2370
+ n = Math.floor(n / 26);
2371
+ }
2372
+ return s + (r + 1);
2373
+ };
2374
+ this.store.change(this.ref.part, (xml) => {
2375
+ const table = this.store.node(this.table.ref);
2376
+ xml.replaceElement(
2377
+ table,
2378
+ editMergedTable(
2379
+ xml,
2380
+ table,
2381
+ table,
2382
+ "tables.merge",
2383
+ { from: coordinate(top, left), to: coordinate(bottom, right), join: "paragraphs" },
2384
+ this.store.context.budget,
2385
+ activeModelChildren(this.store, this.ref.part)
2386
+ )
2387
+ );
2388
+ });
2389
+ return tableOwner.cell(top, left);
2390
+ }
2391
+ };
2392
+ var _Row = class {
2393
+ constructor(owner, ref) {
2394
+ this.owner = owner;
2395
+ this.ref = ref;
2396
+ }
2397
+ owner;
2398
+ ref;
2399
+ get table() {
2400
+ this.owner.store.node(this.ref);
2401
+ return this.owner;
2402
+ }
2403
+ get part() {
2404
+ return this.table.part;
2405
+ }
2406
+ get element() {
2407
+ return this.table.store.element(this.ref);
2408
+ }
2409
+ get cells() {
2410
+ const grid = this.table.grid(), row = grid.rows.findIndex((n) => grid.original(n) === this.table.store.node(this.ref));
2411
+ return this.table.row_cells(row);
2412
+ }
2413
+ get grid_cols_before() {
2414
+ return tableGridCount(readProperty(this.table.store, this.ref, "trPr", "gridBefore"), 0);
2415
+ }
2416
+ get grid_cols_after() {
2417
+ return tableGridCount(readProperty(this.table.store, this.ref, "trPr", "gridAfter"), 0);
2418
+ }
2419
+ get height() {
2420
+ return storedLength(readProperty(this.table.store, this.ref, "trPr", "trHeight"), "val");
2421
+ }
2422
+ set height(value) {
2423
+ if (value === null) this.clearHeightAttribute("val");
2424
+ else
2425
+ properties(this.table.store, this.ref, "trPr", "trHeight", {
2426
+ val: String(twips(value, false))
2427
+ });
2428
+ }
2429
+ get height_rule() {
2430
+ const n = readProperty(this.table.store, this.ref, "trPr", "trHeight");
2431
+ return n ? readEnum(styleAttribute(n, "hRule") ?? "atLeast", WD_ROW_HEIGHT_RULE, {
2432
+ AUTO: "auto",
2433
+ AT_LEAST: "atLeast",
2434
+ EXACTLY: "exact"
2435
+ }) : null;
2436
+ }
2437
+ set height_rule(value) {
2438
+ const name = enumName(value, "WD_ROW_HEIGHT_RULE", {
2439
+ AUTO: "auto",
2440
+ AT_LEAST: "atLeast",
2441
+ EXACTLY: "exact"
2442
+ });
2443
+ if (name === null) this.clearHeightAttribute("hRule");
2444
+ else properties(this.table.store, this.ref, "trPr", "trHeight", { hRule: name });
2445
+ }
2446
+ clearHeightAttribute(name) {
2447
+ this.table.store.change(this.ref.part, (xml) => {
2448
+ const node = readProperty(this.table.store, this.ref, "trPr", "trHeight");
2449
+ if (node)
2450
+ if (!node.attributes.some((a) => a.namespace === node.namespace && a.localName !== name) && !node.content.some((c) => c.kind !== "text" || c.text.trim())) xml.replaceElement(node, "");
2451
+ else xml.setQualifiedAttribute(node, { namespace: node.namespace, localName: name }, null);
2452
+ });
2453
+ }
2454
+ };
2455
+ var _Column = class {
2456
+ constructor(owner, ref) {
2457
+ this.owner = owner;
2458
+ this.ref = ref;
2459
+ }
2460
+ owner;
2461
+ ref;
2462
+ get table() {
2463
+ this.owner.store.node(this.ref);
2464
+ return this.owner;
2465
+ }
2466
+ get part() {
2467
+ return this.table.part;
2468
+ }
2469
+ get element() {
2470
+ return this.table.store.element(this.ref);
2471
+ }
2472
+ get cells() {
2473
+ const grid = this.table.grid(), col = grid.columns.findIndex((n) => grid.original(n) === this.table.store.node(this.ref));
2474
+ return this.table.column_cells(col);
2475
+ }
2476
+ get width() {
2477
+ return storedLength(this.table.store.node(this.ref));
2478
+ }
2479
+ set width(value) {
2480
+ this.table.store.change(this.ref.part, (xml) => {
2481
+ xml.setQualifiedAttribute(
2482
+ this.table.store.node(this.ref),
2483
+ { namespace: this.table.store.node(this.ref).namespace, localName: "w" },
2484
+ value === null ? null : String(twips(value, false))
2485
+ );
2486
+ });
2487
+ }
2488
+ };
2489
+ var _Rows = class {
2490
+ constructor(owner) {
2491
+ this.owner = owner;
2492
+ return numericSequence(this);
2493
+ }
2494
+ owner;
2495
+ cache = /* @__PURE__ */ new Map();
2496
+ get table() {
2497
+ this.owner.store.node(this.owner.ref);
2498
+ return this.owner;
2499
+ }
2500
+ get part() {
2501
+ return this.table.part;
2502
+ }
2503
+ get length() {
2504
+ return this.table.grid().rows.length;
2505
+ }
2506
+ slice(start = 0, end = this.length) {
2507
+ for (const value of [start, end])
2508
+ if (!Number.isSafeInteger(value))
2509
+ throw new InputTypeError("Expected safe integer slice bounds.");
2510
+ return snapshotSequence([...this].slice(start, end));
2511
+ }
2512
+ at(value) {
2513
+ const grid = this.table.grid(), node = grid.original(grid.rows[index(grid.rows.length, value)]), ref = this.table.store.ref(this.table.ref.part, node);
2514
+ let row = this.cache.get(ref.id);
2515
+ if (!row) {
2516
+ row = new _Row(this.table, ref);
2517
+ this.cache.set(ref.id, row);
2518
+ }
2519
+ return row;
2520
+ }
2521
+ *[Symbol.iterator]() {
2522
+ for (let i = 0; i < this.length; i++) yield this.at(i);
2523
+ }
2524
+ };
2525
+ var _Columns = class {
2526
+ constructor(owner) {
2527
+ this.owner = owner;
2528
+ return numericSequence(this);
2529
+ }
2530
+ owner;
2531
+ cache = /* @__PURE__ */ new Map();
2532
+ get table() {
2533
+ this.owner.store.node(this.owner.ref);
2534
+ return this.owner;
2535
+ }
2536
+ get part() {
2537
+ return this.table.part;
2538
+ }
2539
+ get length() {
2540
+ return this.table.grid().columns.length;
2541
+ }
2542
+ at(value) {
2543
+ const grid = this.table.grid(), node = grid.original(grid.columns[index(grid.columns.length, value)]), ref = this.table.store.ref(this.table.ref.part, node);
2544
+ let col = this.cache.get(ref.id);
2545
+ if (!col) {
2546
+ col = new _Column(this.table, ref);
2547
+ this.cache.set(ref.id, col);
2548
+ }
2549
+ return col;
2550
+ }
2551
+ *[Symbol.iterator]() {
2552
+ for (let i = 0; i < this.length; i++) yield this.at(i);
2553
+ }
2554
+ };
2555
+
2556
+ // packages/safe-bash-docx-engine/src/model-store.ts
2557
+ var ModelStore = class _ModelStore {
2558
+ constructor(archive, context, mainPart, source) {
2559
+ this.context = context;
2560
+ this.source = source;
2561
+ this.archive = archive;
2562
+ this.mainPartName = mainPart.startsWith("/") ? mainPart : "/" + mainPart;
2563
+ this.package = new PackageView({
2564
+ model: this,
2565
+ context,
2566
+ snapshot: () => this.snapshot(),
2567
+ version: () => this.revision,
2568
+ writable: () => this.writable(),
2569
+ stage: (candidate, rename) => {
2570
+ context.budget.charge(
2571
+ "retainedBytes",
2572
+ (this.archive.members.length + candidate.members.length) * 96
2573
+ );
2574
+ const current = new Map(
2575
+ this.snapshot().members.map((member) => ["/" + member.name, member.bytes])
2576
+ );
2577
+ const from = rename ? "/" + this.memberName(rename.from) : void 0;
2578
+ if (rename && from) current.set(rename.to, current.get(from));
2579
+ const unchanged = new Set(
2580
+ candidate.members.filter((member) => {
2581
+ const previous = current.get("/" + member.name);
2582
+ context.budget.charge("work", member.bytes.length + 1);
2583
+ return previous?.length === member.bytes.length && previous.every((byte, index2) => byte === member.bytes[index2]);
2584
+ }).map((member) => "/" + member.name)
2585
+ );
2586
+ for (const member of candidate.members) {
2587
+ const part = "/" + member.name;
2588
+ if (current.has(part) && !unchanged.has(part))
2589
+ this.assertCommentPartMetadataPreserved(rename && part === rename.to ? from : part, member.bytes);
2590
+ }
2591
+ const rootOwners = /* @__PURE__ */ new Map();
2592
+ for (const member of candidate.members) {
2593
+ const part = "/" + member.name, previousPart = rename && part === rename.to ? from : part;
2594
+ const previous = this.editors.get(previousPart);
2595
+ if (unchanged.has(part) || !previous) continue;
2596
+ let retained = false;
2597
+ for (const handle of this.handles.values()) {
2598
+ context.budget.charge("work", 1);
2599
+ if (handle.ref.part === previousPart && handle.node === previous.root) {
2600
+ retained = true;
2601
+ break;
2602
+ }
2603
+ }
2604
+ if (!retained) continue;
2605
+ const next = new DocumentXmlEditor(member.bytes, {}, void 0, context.budget);
2606
+ if (previous.root.namespace === next.root.namespace && previous.root.localName === next.root.localName) {
2607
+ context.budget.charge("retainedBytes", 64);
2608
+ rootOwners.set(part, { previous: previous.root, next });
2609
+ }
2610
+ }
2611
+ if (rename && from) {
2612
+ const editor = this.editors.get(from);
2613
+ if (editor) {
2614
+ this.editors.delete(from);
2615
+ this.editors.set(rename.to, editor);
2616
+ }
2617
+ for (const handle of this.handles.values()) if (handle.part === from) handle.part = rename.to;
2618
+ if ("/" + this.memberName(this.mainPart) === from) this.mainPartName = rename.to;
2619
+ }
2620
+ this.archive = candidate;
2621
+ for (const part of this.editors.keys()) if (!unchanged.has(part)) {
2622
+ const root = rootOwners.get(part);
2623
+ if (root) this.editors.set(part, root.next);
2624
+ else this.editors.delete(part);
2625
+ }
2626
+ for (const handle of this.handles.values())
2627
+ if (!unchanged.has(handle.ref.part)) {
2628
+ const root = rootOwners.get(handle.ref.part);
2629
+ handle.node = root && handle.node === root.previous ? root.next.root : null;
2630
+ }
2631
+ this.handleIndex = void 0;
2632
+ this.revision++;
2633
+ },
2634
+ save: (output, options) => this.save(output, options)
2635
+ });
2636
+ const dialect = dialectForNamespace(this.xml(this.mainPart).root.namespace);
2637
+ const styleEdges = new DocumentPackage(this.snapshot(), context.limits, context.budget).relationships(this.mainPart).filter((edge) => edge.reltype === documentDialects[dialect].r + "/styles");
2638
+ if (styleEdges.length === 1 && !styleEdges[0].is_external)
2639
+ this.bindStyles(styleEdges[0].target_part.partname);
2640
+ }
2641
+ context;
2642
+ source;
2643
+ package;
2644
+ mainPartName;
2645
+ get mainPart() {
2646
+ return this.mainPartName;
2647
+ }
2648
+ boundStyles;
2649
+ boundDocument;
2650
+ documents = /* @__PURE__ */ new WeakMap();
2651
+ get document() {
2652
+ return this.boundDocument ??= new DocumentView(this);
2653
+ }
2654
+ nativeDocument(part) {
2655
+ if (part.package !== this.package) throw new InputTypeError("Expected this package's document owner.");
2656
+ const name = part.partname.toString();
2657
+ if (this.memberName(name) === this.memberName(this.mainPart)) return this.document;
2658
+ let document = this.documents.get(part);
2659
+ if (!document) {
2660
+ document = new DocumentView(this, name);
2661
+ this.documents.set(part, document);
2662
+ }
2663
+ return document;
2664
+ }
2665
+ styleBindingToken = null;
2666
+ archive;
2667
+ editors = /* @__PURE__ */ new Map();
2668
+ handles = /* @__PURE__ */ new Map();
2669
+ handleIndex;
2670
+ objects = /* @__PURE__ */ new Map();
2671
+ elements = /* @__PURE__ */ new Map();
2672
+ nextId = 0;
2673
+ revision = 0;
2674
+ publishing = false;
2675
+ transactionDepth = 0;
2676
+ bindStyles(partname) {
2677
+ const token = Object.freeze({});
2678
+ this.styleBindingToken = token;
2679
+ const valid = () => {
2680
+ if (this.styleBindingToken !== token)
2681
+ throw new StaleHandleError("The styles owner is detached.");
2682
+ };
2683
+ this.boundStyles = bindDocumentStyles({
2684
+ context: this.context,
2685
+ package: this.package,
2686
+ partname,
2687
+ read: () => {
2688
+ valid();
2689
+ return this.xml(partname).serialize();
2690
+ },
2691
+ write: (bytes) => {
2692
+ valid();
2693
+ this.setPart(partname, bytes);
2694
+ },
2695
+ writable: () => {
2696
+ valid();
2697
+ this.writable();
2698
+ }
2699
+ });
2700
+ }
2701
+ nativeStyles(part) {
2702
+ if (part.package !== this.package) throw new InputTypeError("Expected this document's styles part.");
2703
+ return bindDocumentStyles({
2704
+ context: this.context,
2705
+ package: this.package,
2706
+ partname: part.partname.toString(),
2707
+ part,
2708
+ read: () => this.xml(part.partname.toString()).serialize(),
2709
+ write: (bytes) => this.setPart(part.partname.toString(), bytes),
2710
+ writable: () => {
2711
+ void part.content_type;
2712
+ this.writable();
2713
+ }
2714
+ });
2715
+ }
2716
+ nativeSettings(part) {
2717
+ if (part.package !== this.package) throw new InputTypeError("Expected this document's settings part.");
2718
+ return new Settings(this, part.partname.toString());
2719
+ }
2720
+ nativeComments(part) {
2721
+ if (part.package !== this.package) throw new InputTypeError("Expected this document's comments part.");
2722
+ const name = part.partname.toString(), root = this.xml(name).root;
2723
+ if (root.localName !== "comments" || root.namespace !== this.xml(this.mainPart).root.namespace)
2724
+ throw new InputTypeError("Expected an owned comments root.");
2725
+ return new Comments(this, this.ref(name, root));
2726
+ }
2727
+ stylesForDocument(owner) {
2728
+ if (this.memberName(owner) === this.memberName(this.mainPart)) return this.styles;
2729
+ const graph = new DocumentPackage(this.snapshot(), this.context.limits, this.context.budget);
2730
+ const dialect = dialectForNamespace(this.xml(owner).root.namespace);
2731
+ const edges = graph.relationships(owner).filter((edge) => edge.reltype === documentDialects[dialect].r + "/styles");
2732
+ if (edges.length > 1 || edges[0]?.is_external) throw new UnsupportedEditError("Expected one internal styles owner.");
2733
+ let name = edges[0]?.target_part.partname;
2734
+ if (!name) name = this.transaction(() => {
2735
+ const added = addDocumentStylesPart(this.snapshot(), { mainPart: this.memberName(owner), dialect, package: graph }, originalModelDefaults(documentDialects[dialect].w), this.context.budget);
2736
+ this.archive = added.archive;
2737
+ const rel = findRelationshipPart(graph, owner, this.context.budget);
2738
+ if (rel) this.editors.delete("/" + rel.name);
2739
+ this.editors.delete("/[Content_Types].xml");
2740
+ this.handleIndex = void 0;
2741
+ this.revision++;
2742
+ return "/" + added.name;
2743
+ });
2744
+ const part = this.part(name);
2745
+ if (!(part instanceof StylesPart)) throw new InputTypeError("Expected a native styles part.");
2746
+ return part.styles;
2747
+ }
2748
+ stylesForStory(part) {
2749
+ return this.stylesForDocument(this.documentOwnerForStory(part));
2750
+ }
2751
+ documentOwnerForStory(part) {
2752
+ const root = this.xml(part).root;
2753
+ if (root.localName === "document") return part;
2754
+ const role = root.localName === "hdr" ? "header" : root.localName === "ftr" ? "footer" : root.localName;
2755
+ const dialect = dialectForNamespace(root.namespace);
2756
+ if (!dialect) throw new InputTypeError("Expected a native story namespace.");
2757
+ const graph = new DocumentPackage(this.snapshot(), this.context.limits, this.context.budget);
2758
+ const target = asciiKey(normalizePartName(part));
2759
+ const owners = graph.parts.filter((owner) => Object.values(documentTypes).includes(parseMediaType(owner.content_type))).filter((owner) => graph.relationships(owner.partname).some((edge) => !edge.is_external && edge.reltype === documentDialects[dialect].r + "/" + role && asciiKey(edge.target_part.partname) === target));
2760
+ if (owners.length > 1) {
2761
+ const definitions = owners.map((owner) => graph.relationships(owner.partname).filter((edge) => edge.reltype === documentDialects[dialect].r + "/styles"));
2762
+ if (definitions.some((edges) => edges.length !== 1 || edges[0].is_external) || new Set(definitions.map((edges) => asciiKey(edges[0].target_part.partname))).size !== 1)
2763
+ throw new UnsupportedEditError("The story has ambiguous document style ownership.");
2764
+ }
2765
+ return owners[0]?.partname ?? this.mainPart;
2766
+ }
2767
+ withStyleDefinitions(resolve, owner = this.mainPart) {
2768
+ owner = this.documentOwnerForStory(owner);
2769
+ if (this.memberName(owner) === this.memberName(this.mainPart) && this.boundStyles) return resolve(this.styles);
2770
+ const graph = new DocumentPackage(this.snapshot(), this.context.limits, this.context.budget);
2771
+ const dialect = dialectForNamespace(this.xml(owner).root.namespace);
2772
+ if (graph.relationships(owner).some((edge) => edge.reltype === documentDialects[dialect].r + "/styles"))
2773
+ return resolve(this.stylesForDocument(owner));
2774
+ return this.transaction(() => resolve(this.stylesForDocument(owner)));
2775
+ }
2776
+ get styles() {
2777
+ const dialect = dialectForNamespace(this.xml(this.mainPart).root.namespace);
2778
+ const edges = [...this.part(this.mainPart).rels.values()].filter((edge) => edge.reltype === documentDialects[dialect].r + "/styles");
2779
+ if (edges.length > 1 || edges[0]?.is_external) throw new UnsupportedEditError("Expected one internal styles owner.");
2780
+ if (!this.boundStyles) {
2781
+ this.writable();
2782
+ const added = addDocumentStylesPart(
2783
+ this.snapshot(),
2784
+ {
2785
+ mainPart: this.mainPart.slice(1),
2786
+ dialect,
2787
+ package: new DocumentPackage(this.snapshot(), this.context.limits, this.context.budget)
2788
+ },
2789
+ originalModelDefaults(documentDialects[dialect].w),
2790
+ this.context.budget
2791
+ );
2792
+ this.archive = added.archive;
2793
+ this.editors.delete(
2794
+ "/" + this.memberName(this.mainPart.slice(0, this.mainPart.lastIndexOf("/") + 1) + "_rels/" + this.mainPart.slice(this.mainPart.lastIndexOf("/") + 1) + ".rels")
2795
+ );
2796
+ this.editors.delete("/[Content_Types].xml");
2797
+ this.handleIndex = void 0;
2798
+ this.revision++;
2799
+ this.bindStyles("/" + added.name);
2800
+ }
2801
+ return this.boundStyles;
2802
+ }
2803
+ writable() {
2804
+ this.context.budget.check("work", 0);
2805
+ if (this.publishing) throw new PublicationError("conflict", "Model publication is committing.");
2806
+ if (!this.transactionDepth) assertDocumentEditable(this.snapshot(), this.context);
2807
+ }
2808
+ transaction(action) {
2809
+ this.writable();
2810
+ const archive = this.snapshot(), editors = new Map(this.editors), revision = this.revision, mainPart = this.mainPart, boundStyles = this.boundStyles, styleBindingToken = this.styleBindingToken;
2811
+ const restoreStyles = boundStyles && styleOwnerCheckpoints.get(boundStyles)?.();
2812
+ const restorePackage = this.package[packageOwnerCheckpoint]();
2813
+ const handles = new Map([...this.handles].map(([id2, handle]) => [id2, { ...handle }]));
2814
+ this.transactionDepth++;
2815
+ try {
2816
+ const result = action();
2817
+ if (this.transactionDepth === 1) {
2818
+ const report = validateDocumentArchive(this.snapshot(), {}, this.context.budget);
2819
+ if (!report.valid) throw new SemanticValidationError(report.diagnostics);
2820
+ }
2821
+ return result;
2822
+ } catch (error) {
2823
+ this.archive = archive;
2824
+ this.editors.clear();
2825
+ for (const [part, xml] of editors) this.editors.set(part, xml);
2826
+ this.handles.clear();
2827
+ for (const [id2, handle] of handles) this.handles.set(id2, handle);
2828
+ this.handleIndex = void 0;
2829
+ this.revision = revision;
2830
+ this.mainPartName = mainPart;
2831
+ this.boundStyles = boundStyles;
2832
+ this.styleBindingToken = styleBindingToken;
2833
+ restoreStyles?.();
2834
+ restorePackage();
2835
+ throw error;
2836
+ } finally {
2837
+ this.transactionDepth--;
2838
+ }
2839
+ }
2840
+ assertReplaceable(node) {
2841
+ const visit = (child) => {
2842
+ this.context.budget.charge("work", 1);
2843
+ if (child.namespace !== node.namespace || [
2844
+ "drawing",
2845
+ "pict",
2846
+ "object",
2847
+ "fldSimple",
2848
+ "fldChar",
2849
+ "instrText",
2850
+ "footnoteReference",
2851
+ "endnoteReference",
2852
+ "commentRangeStart",
2853
+ "commentRangeEnd",
2854
+ "commentReference",
2855
+ "bookmarkStart",
2856
+ "bookmarkEnd",
2857
+ "permStart",
2858
+ "permEnd",
2859
+ "ins",
2860
+ "del",
2861
+ "moveFrom",
2862
+ "moveTo"
2863
+ ].includes(child.localName))
2864
+ throw new UnsupportedEditError(
2865
+ "Whole text replacement cannot discard independently owned content."
2866
+ );
2867
+ for (const nested of child.children) visit(nested);
2868
+ };
2869
+ visit(node);
2870
+ }
2871
+ deletePart(part) {
2872
+ this.writable();
2873
+ const name = this.memberName(part);
2874
+ this.archive = this.snapshot();
2875
+ this.archive = {
2876
+ ...this.archive,
2877
+ members: this.archive.members.filter((member) => member.name !== name)
2878
+ };
2879
+ this.editors.delete("/" + name);
2880
+ for (const handle of this.handles.values())
2881
+ if (handle.ref.part === "/" + name) handle.node = null;
2882
+ this.handleIndex = void 0;
2883
+ this.revision++;
2884
+ }
2885
+ snapshot() {
2886
+ return {
2887
+ comment: this.archive.comment.slice(),
2888
+ members: this.archive.members.map((member) => ({
2889
+ ...member,
2890
+ bytes: this.editors.get("/" + member.name)?.serialize() ?? member.bytes.slice(),
2891
+ modified: new Date(member.modified.getTime())
2892
+ }))
2893
+ };
2894
+ }
2895
+ memberName(part) {
2896
+ const name = part.startsWith("/") ? part.slice(1) : part;
2897
+ const key = asciiKey(name) === "[content_types].xml" ? "/[content_types].xml" : asciiKey(normalizePartName("/" + name));
2898
+ for (const member of this.archive.members) {
2899
+ this.context.budget.charge("work", 1 + member.name.length);
2900
+ if (member.directory) continue;
2901
+ const candidate = asciiKey(member.name) === "[content_types].xml" ? "/[content_types].xml" : asciiKey(normalizePartName("/" + member.name));
2902
+ if (key === candidate) return member.name;
2903
+ }
2904
+ return name;
2905
+ }
2906
+ xml(part) {
2907
+ part = "/" + this.memberName(part);
2908
+ let xml = this.editors.get(part);
2909
+ if (!xml) {
2910
+ const member = this.archive.members.find((member2) => "/" + member2.name === part);
2911
+ if (!member) throw new StaleHandleError("The part is no longer attached.");
2912
+ xml = new DocumentXmlEditor(member.bytes, {}, void 0, this.context.budget);
2913
+ this.editors.set(part, xml);
2914
+ }
2915
+ return xml;
2916
+ }
2917
+ ref(part, node) {
2918
+ part = "/" + this.memberName(part);
2919
+ this.context.budget.charge("work", 1);
2920
+ if (!this.handleIndex) {
2921
+ const index2 = /* @__PURE__ */ new WeakMap();
2922
+ for (const handle2 of this.handles.values()) {
2923
+ this.context.budget.charge("work", 1);
2924
+ if (!handle2.node) continue;
2925
+ this.context.budget.charge("retainedBytes", 128);
2926
+ let parts2 = index2.get(handle2.node);
2927
+ if (!parts2) index2.set(handle2.node, parts2 = /* @__PURE__ */ new Map());
2928
+ parts2.set(handle2.part, handle2);
2929
+ }
2930
+ this.handleIndex = index2;
2931
+ }
2932
+ const existing = this.handleIndex.get(node)?.get(part);
2933
+ if (existing) return existing.ref;
2934
+ this.context.budget.charge("retainedBytes", 320);
2935
+ const id2 = this.nextId++, handles = this.handles;
2936
+ const ref = Object.freeze({ get part() {
2937
+ return handles.get(id2)?.part ?? part;
2938
+ }, id: id2 });
2939
+ const handle = { ref, part, node, identity: Object.freeze({}) };
2940
+ this.handles.set(ref.id, handle);
2941
+ let parts = this.handleIndex.get(node);
2942
+ if (!parts) this.handleIndex.set(node, parts = /* @__PURE__ */ new Map());
2943
+ parts.set(part, handle);
2944
+ return ref;
2945
+ }
2946
+ node(ref) {
2947
+ this.context.budget.check("work", 0);
2948
+ const handle = this.handles.get(ref.id);
2949
+ if (handle?.ref !== ref || !handle.node)
2950
+ throw new StaleHandleError("The model handle is detached.");
2951
+ return handle.node;
2952
+ }
2953
+ identity(ref) {
2954
+ this.node(ref);
2955
+ return this.handles.get(ref.id).identity;
2956
+ }
2957
+ invalidateDescendants(ref) {
2958
+ const root = this.node(ref);
2959
+ const descendants = /* @__PURE__ */ new Set();
2960
+ const visit = (node) => {
2961
+ for (const child of node.children) {
2962
+ descendants.add(child);
2963
+ visit(child);
2964
+ }
2965
+ };
2966
+ visit(root);
2967
+ for (const handle of this.handles.values())
2968
+ if (handle.node && descendants.has(handle.node)) handle.node = null;
2969
+ this.handleIndex = void 0;
2970
+ }
2971
+ change(part, action) {
2972
+ this.writable();
2973
+ part = "/" + this.memberName(part);
2974
+ const old = this.xml(part);
2975
+ const candidate = new DocumentXmlEditor(old.serialize(), {}, void 0, this.context.budget);
2976
+ this.editors.set(part, candidate);
2977
+ const oldToCandidate = /* @__PURE__ */ new Map();
2978
+ const pairs = [{ left: old.root, right: candidate.root }];
2979
+ while (pairs.length) {
2980
+ const { left, right } = pairs.pop();
2981
+ this.context.budget.charge("work", 1);
2982
+ oldToCandidate.set(left, right);
2983
+ for (let i = left.children.length - 1; i >= 0; i--) if (right.children[i]) {
2984
+ this.context.budget.charge("retainedBytes", 32);
2985
+ pairs.push({ left: left.children[i], right: right.children[i] });
2986
+ }
2987
+ }
2988
+ const retained = [...this.handles.values()].filter((handle) => handle.ref.part === part);
2989
+ const prior = retained.map((handle) => handle.node);
2990
+ retained.forEach((handle) => {
2991
+ if (handle.node) handle.node = oldToCandidate.get(handle.node) ?? null;
2992
+ });
2993
+ this.handleIndex = void 0;
2994
+ const replacements = /* @__PURE__ */ new Map();
2995
+ const insertions = /* @__PURE__ */ new Map();
2996
+ const fragment = (node, markup) => {
2997
+ const namespaces = [...node.namespaces].filter(([prefix]) => prefix !== "xml").map(([prefix, value]) => ` ${prefix ? "xmlns:" + prefix : "xmlns"}="${xmlValue(value)}"`).join("");
2998
+ return parseDocumentXml(
2999
+ new TextEncoder().encode(`<fragment${namespaces}>${markup}</fragment>`),
3000
+ {},
3001
+ this.context.budget
3002
+ ).root.children;
3003
+ };
3004
+ const replace = candidate.replaceElement.bind(candidate), insert = candidate.insertChildren.bind(candidate);
3005
+ candidate.replaceElement = (node, markup) => {
3006
+ const children = fragment(node, markup);
3007
+ replace(node, markup);
3008
+ replacements.set(node, children);
3009
+ };
3010
+ candidate.insertChildren = (node, markup, before) => {
3011
+ const children = fragment(node, markup);
3012
+ insert(node, markup, before);
3013
+ const list = insertions.get(node) ?? [];
3014
+ list.push({ before, count: children.length });
3015
+ insertions.set(node, list);
3016
+ };
3017
+ for (const authority of [appendBodyBlocks, insertParagraphBefore]) {
3018
+ const insertOwned = candidate[authority].bind(candidate);
3019
+ candidate[authority] = (owner, markup) => {
3020
+ const path = insertOwned(owner, markup);
3021
+ let parent = candidate.root;
3022
+ for (const index2 of path.slice(0, -1)) parent = parent.children[index2];
3023
+ const children = fragment(parent, markup);
3024
+ const list = insertions.get(parent) ?? [];
3025
+ list.push({ before: parent.children[path.at(-1)], count: children.length });
3026
+ insertions.set(parent, list);
3027
+ return path;
3028
+ };
3029
+ }
3030
+ try {
3031
+ action(candidate);
3032
+ const bytes = candidate.serialize();
3033
+ const next = new DocumentXmlEditor(bytes, {}, void 0, this.context.budget);
3034
+ assertLiveCommentMetadataPreserved(
3035
+ old,
3036
+ next,
3037
+ part,
3038
+ () => new DocumentPackage(this.snapshot(), this.context.limits, this.context.budget),
3039
+ this.context.budget
3040
+ );
3041
+ const map = /* @__PURE__ */ new Map();
3042
+ const budget = this.context.budget;
3043
+ const reconcile = function* (left, right) {
3044
+ budget.charge("work", 1);
3045
+ map.set(left, right);
3046
+ const oldChildren = left.children, newChildren = right.children;
3047
+ if (!replacements.has(left)) {
3048
+ let position = 0;
3049
+ for (const child of oldChildren) {
3050
+ position += (insertions.get(left) ?? []).filter((item) => item.before === child).reduce((count, item) => count + item.count, 0);
3051
+ const roots = replacements.get(child);
3052
+ if (roots) {
3053
+ const offset = roots.findIndex(
3054
+ (root) => root.namespace === child.namespace && root.localName === child.localName
3055
+ );
3056
+ if (offset >= 0 && newChildren[position + offset])
3057
+ yield { left: child, right: newChildren[position + offset] };
3058
+ position += roots.length;
3059
+ } else {
3060
+ if (newChildren[position]) yield { left: child, right: newChildren[position] };
3061
+ position++;
3062
+ }
3063
+ }
3064
+ return;
3065
+ }
3066
+ const used = /* @__PURE__ */ new Set();
3067
+ const matched = /* @__PURE__ */ new Map();
3068
+ let floor = 0;
3069
+ oldChildren.forEach((child, i) => {
3070
+ const source = candidate.sourceXml(child);
3071
+ let j = floor;
3072
+ for (; j < newChildren.length; j++) {
3073
+ budget.charge("work", 1);
3074
+ if (source === next.sourceXml(newChildren[j])) break;
3075
+ }
3076
+ if (j < newChildren.length) {
3077
+ matched.set(i, j);
3078
+ used.add(j);
3079
+ floor = j + 1;
3080
+ }
3081
+ });
3082
+ for (let i = 0; i < oldChildren.length; i++) {
3083
+ const child = oldChildren[i];
3084
+ let j = matched.get(i);
3085
+ if (j === void 0 && ["p", "tbl", "tr", "tc", "sectPr", "tblGrid", "gridCol", "pPr", "rPr"].includes(
3086
+ child.localName
3087
+ ) && oldChildren.length === newChildren.length && !used.has(i) && child.localName === newChildren[i]?.localName && child.namespace === newChildren[i]?.namespace) {
3088
+ j = i;
3089
+ used.add(i);
3090
+ }
3091
+ if (j !== void 0) {
3092
+ if (candidate.sourceXml(child) !== next.sourceXml(newChildren[j]))
3093
+ replacements.set(child, [newChildren[j]]);
3094
+ yield { left: child, right: newChildren[j] };
3095
+ }
3096
+ }
3097
+ };
3098
+ budget.charge("retainedBytes", 128);
3099
+ const pending = [reconcile(candidate.root, next.root)];
3100
+ while (pending.length) {
3101
+ const step = pending[pending.length - 1].next();
3102
+ if (step.done) pending.pop();
3103
+ else {
3104
+ budget.charge("retainedBytes", 128);
3105
+ pending.push(reconcile(step.value.left, step.value.right));
3106
+ }
3107
+ }
3108
+ for (const handle of retained) if (handle.node) handle.node = map.get(handle.node) ?? null;
3109
+ this.editors.set(part, next);
3110
+ this.handleIndex = void 0;
3111
+ this.revision++;
3112
+ } catch (error) {
3113
+ this.editors.set(part, old);
3114
+ retained.forEach((handle, index2) => {
3115
+ handle.node = prior[index2];
3116
+ });
3117
+ this.handleIndex = void 0;
3118
+ throw error;
3119
+ }
3120
+ }
3121
+ tableStyle(id2, owner) {
3122
+ return this.stylesForStory(owner).get_by_id(id2, WD_STYLE_TYPE.TABLE);
3123
+ }
3124
+ tableStyleId(value, owner) {
3125
+ return this.stylesForStory(owner).get_style_id(value, WD_STYLE_TYPE.TABLE);
3126
+ }
3127
+ part(part, story = false) {
3128
+ const name = normalizePartName(part.startsWith("/") ? part : "/" + part);
3129
+ const view = this.package[packagePart](name);
3130
+ if (!(view instanceof XmlPartView)) throw new StaleHandleError("The XML part is detached.");
3131
+ if (story && !(view instanceof StoryPart)) throw new InputTypeError("Expected a native story part owner.");
3132
+ return view;
3133
+ }
3134
+ element(ref) {
3135
+ this.node(ref);
3136
+ let view = this.elements.get(ref.id);
3137
+ if (!view) {
3138
+ view = bindXmlElementView({
3139
+ budget: this.context.budget,
3140
+ read: () => this.xml(ref.part),
3141
+ resolve: () => this.node(ref),
3142
+ change: (action) => this.transaction(() => this.change(ref.part, action)),
3143
+ removeRoot: () => this.transaction(() => this.change(ref.part, (xml) => xml.replaceElement(this.node(ref), "")))
3144
+ });
3145
+ this.elements.set(ref.id, view);
3146
+ }
3147
+ return view;
3148
+ }
3149
+ paragraph(ref) {
3150
+ let view = this.objects.get(ref.id);
3151
+ if (!view) {
3152
+ view = new Paragraph(this, ref);
3153
+ this.objects.set(ref.id, view);
3154
+ }
3155
+ return view;
3156
+ }
3157
+ run(ref) {
3158
+ let view = this.objects.get(ref.id);
3159
+ if (!view) {
3160
+ view = new Run(this, ref);
3161
+ this.objects.set(ref.id, view);
3162
+ }
3163
+ return view;
3164
+ }
3165
+ table(ref) {
3166
+ let view = this.objects.get(ref.id);
3167
+ if (!view) {
3168
+ view = new Table(this, ref);
3169
+ this.objects.set(ref.id, view);
3170
+ }
3171
+ return view;
3172
+ }
3173
+ *blocks(ref) {
3174
+ const node = this.node(ref);
3175
+ for (const child of activeModelChildren(this, ref.part)(node)) {
3176
+ this.context.budget.charge("work", 1);
3177
+ if (child.namespace !== node.namespace) continue;
3178
+ if (child.localName === "p") yield this.paragraph(this.ref(ref.part, child));
3179
+ if (child.localName === "tbl") yield this.table(this.ref(ref.part, child));
3180
+ }
3181
+ }
3182
+ addParagraph(ref, text2 = "", style) {
3183
+ if (typeof text2 !== "string") throw new InputTypeError("Expected paragraph text.");
3184
+ const styleId = style === void 0 || style === null ? null : this.stylesForStory(ref.part).get_style_id(style, WD_STYLE_TYPE.PARAGRAPH);
3185
+ const node = this.node(ref);
3186
+ const count = node.children.length;
3187
+ let insertedPath;
3188
+ this.change(ref.part, (xml) => {
3189
+ const parent2 = this.node(ref);
3190
+ assertFormattingHistoryEditable(xml.root, parent2, activeXmlChildren(xml, this.context.budget), this.context.budget);
3191
+ const markup = `<bm:p xmlns:bm="${parent2.namespace}">${styleId ? `<bm:pPr><bm:pStyle bm:val="${xmlValue(styleId)}"/></bm:pPr>` : ""}${text2 ? paragraphTextRun(parent2.namespace, text2) : ""}</bm:p>`;
3192
+ if (parent2.localName === "body") {
3193
+ insertedPath = xml[appendBodyBlocks](parent2, markup);
3194
+ return;
3195
+ }
3196
+ const section = parent2.children.find(
3197
+ (child2) => child2.namespace === parent2.namespace && child2.localName === "sectPr"
3198
+ );
3199
+ xml.insertChildren(
3200
+ parent2,
3201
+ markup,
3202
+ section
3203
+ );
3204
+ });
3205
+ if (insertedPath) {
3206
+ let inserted2 = this.xml(ref.part).root;
3207
+ for (const index2 of insertedPath) inserted2 = inserted2.children[index2];
3208
+ return this.paragraph(this.ref(ref.part, inserted2));
3209
+ }
3210
+ const parent = this.node(ref);
3211
+ const child = parent.children[Math.min(count, parent.children.length - 1)];
3212
+ const inserted = child.localName === "sectPr" ? parent.children[parent.children.indexOf(child) - 1] : child;
3213
+ return this.paragraph(this.ref(ref.part, inserted));
3214
+ }
3215
+ addTable(ref, rows, cols, width) {
3216
+ if (![rows, cols].every((value) => Number.isSafeInteger(value) && value > 0))
3217
+ throw new RangeError("Expected positive table dimensions.");
3218
+ const parent = this.node(ref);
3219
+ const section = parent.children.find(
3220
+ (child) => child.localName === "sectPr" && child.namespace === parent.namespace
3221
+ );
3222
+ const insertionIndex = section ? parent.children.indexOf(section) : parent.children.length;
3223
+ let insertedPath;
3224
+ const markup = renderContent(
3225
+ {
3226
+ version: 1,
3227
+ blocks: [
3228
+ {
3229
+ kind: "table",
3230
+ rows: Array.from(
3231
+ { length: rows },
3232
+ () => Array.from({ length: cols }, () => ({ blocks: [] }))
3233
+ ),
3234
+ ...width ? { width: { value: width.emu, unit: "emu" } } : {}
3235
+ }
3236
+ ]
3237
+ },
3238
+ parent.namespace,
3239
+ this.context.budget,
3240
+ void 0,
3241
+ width?.twips
3242
+ ).body;
3243
+ this.change(ref.part, (xml) => {
3244
+ const owner = this.node(ref);
3245
+ assertFormattingHistoryEditable(xml.root, owner, activeXmlChildren(xml, this.context.budget), this.context.budget);
3246
+ if (owner.localName === "body") {
3247
+ insertedPath = xml[appendBodyBlocks](owner, markup);
3248
+ return;
3249
+ }
3250
+ xml.insertChildren(
3251
+ owner,
3252
+ markup + (owner.localName === "tc" ? `<bm:p xmlns:bm="${owner.namespace}"/>` : ""),
3253
+ owner.children.find(
3254
+ (child) => child.localName === "sectPr" && child.namespace === owner.namespace
3255
+ )
3256
+ );
3257
+ });
3258
+ if (insertedPath) {
3259
+ let inserted = this.xml(ref.part).root;
3260
+ for (const index2 of insertedPath) inserted = inserted.children[index2];
3261
+ return this.table(this.ref(ref.part, inserted));
3262
+ }
3263
+ const node = this.node(ref);
3264
+ const table = node.children[insertionIndex];
3265
+ return this.table(this.ref(ref.part, table));
3266
+ }
3267
+ cellText(ref, text2) {
3268
+ if (typeof text2 !== "string") throw new InputTypeError("Expected cell text.");
3269
+ this.change(ref.part, (xml) => {
3270
+ const cell = this.node(ref);
3271
+ assertFormattingHistoryEditable(xml.root, cell, activeXmlChildren(xml, this.context.budget), this.context.budget);
3272
+ xml.replaceElement(cell, replaceCellContent(xml, cell, text2, this.context.budget, {
3273
+ graph: () => new DocumentPackage(this.snapshot(), this.context.limits, this.context.budget),
3274
+ owner: ref.part,
3275
+ context: this.context
3276
+ }));
3277
+ });
3278
+ this.invalidateDescendants(ref);
3279
+ }
3280
+ setPart(part, bytes, contentType) {
3281
+ if (!this.transactionDepth) {
3282
+ this.transaction(() => this.setPart(part, bytes, contentType));
3283
+ return;
3284
+ }
3285
+ this.writable();
3286
+ const name = this.memberName(part);
3287
+ this.archive = this.snapshot();
3288
+ const found = this.archive.members.find((member) => member.name === name);
3289
+ if (found) {
3290
+ this.assertCommentPartMetadataPreserved("/" + name, bytes);
3291
+ this.archive = {
3292
+ ...this.archive,
3293
+ members: this.archive.members.map(
3294
+ (member) => member === found ? { ...member, bytes: bytes.slice() } : member
3295
+ )
3296
+ };
3297
+ this.editors.delete("/" + name);
3298
+ for (const handle of this.handles.values())
3299
+ if (handle.ref.part === "/" + name) handle.node = null;
3300
+ } else
3301
+ this.archive = {
3302
+ ...this.archive,
3303
+ members: [
3304
+ ...this.archive.members,
3305
+ {
3306
+ name,
3307
+ bytes: bytes.slice(),
3308
+ directory: false,
3309
+ modified: /* @__PURE__ */ new Date("1980-01-01T00:00:00Z")
3310
+ }
3311
+ ]
3312
+ };
3313
+ this.handleIndex = void 0;
3314
+ this.revision++;
3315
+ if (contentType)
3316
+ this.change("/[Content_Types].xml", (xml) => {
3317
+ if (!xml.root.children.some(
3318
+ (child) => child.attributes.some((a) => a.localName === "PartName" && a.value === "/" + name)
3319
+ ))
3320
+ xml.insertChildren(
3321
+ xml.root,
3322
+ `<Override xmlns="${xml.root.namespace}" PartName="/${xmlValue(name)}" ContentType="${xmlValue(contentType)}"/>`
3323
+ );
3324
+ });
3325
+ }
3326
+ assertCommentPartMetadataPreserved(part, bytes) {
3327
+ if (part === "/[Content_Types].xml") return;
3328
+ if (parseMediaType(this.part(part).content_type) !== "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml") return;
3329
+ assertLiveCommentMetadataPreserved(
3330
+ this.xml(part),
3331
+ new DocumentXmlEditor(bytes, {}, void 0, this.context.budget),
3332
+ part,
3333
+ () => new DocumentPackage(this.snapshot(), this.context.limits, this.context.budget),
3334
+ this.context.budget
3335
+ );
3336
+ }
3337
+ ensureComments(owner = this.mainPart) {
3338
+ if (!this.transactionDepth) return this.transaction(() => this.ensureComments(owner));
3339
+ const graph = new DocumentPackage(this.snapshot(), this.context.limits, this.context.budget);
3340
+ const r = documentDialects[dialectForNamespace(this.xml(owner).root.namespace)].r;
3341
+ const edges = graph.relationships(owner).filter((edge) => edge.reltype === r + "/comments");
3342
+ if (edges.length > 1 || edges[0]?.is_external)
3343
+ throw new UnsupportedEditError("Expected one internal comments part.");
3344
+ let part = edges[0]?.target_part.partname;
3345
+ if (!part) {
3346
+ part = graph.allocatePartName(
3347
+ owner.slice(0, owner.lastIndexOf("/") + 1) + "comments",
3348
+ ".xml"
3349
+ );
3350
+ const w = this.xml(owner).root.namespace;
3351
+ this.setPart(
3352
+ part,
3353
+ new TextEncoder().encode(`<bm:comments xmlns:bm="${w}"/>`),
3354
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"
3355
+ );
3356
+ const relationshipPart = findRelationshipPart(graph, owner, this.context.budget);
3357
+ const relName = relationshipPart ? "/" + relationshipPart.name : owner.slice(0, owner.lastIndexOf("/") + 1) + "_rels/" + owner.slice(owner.lastIndexOf("/") + 1) + ".rels";
3358
+ if (!relationshipPart)
3359
+ this.setPart(
3360
+ relName,
3361
+ new TextEncoder().encode(
3362
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"/>'
3363
+ )
3364
+ );
3365
+ this.change(
3366
+ relName,
3367
+ (xml) => xml.insertChildren(
3368
+ xml.root,
3369
+ `<Relationship xmlns="${xml.root.namespace}" Id="${graph.allocateRelationshipId(owner)}" Type="${r}/comments" Target="${relativePartTarget(owner, part)}"/>`
3370
+ )
3371
+ );
3372
+ }
3373
+ return this.ref(part, this.xml(part).root);
3374
+ }
3375
+ detachedParagraph(xml, part) {
3376
+ const snapshot = this.snapshot(), root = this.xml(this.mainPart).root;
3377
+ const bytes = new TextEncoder().encode(
3378
+ `<bm:document xmlns:bm="${root.namespace}"><bm:body>${xml}<bm:sectPr/></bm:body></bm:document>`
3379
+ );
3380
+ const archive = {
3381
+ ...snapshot,
3382
+ members: snapshot.members.map(
3383
+ (member) => "/" + member.name === this.mainPart ? { ...member, bytes } : member
3384
+ )
3385
+ };
3386
+ const detached = new _ModelStore(archive, this.context, this.mainPart), body = detached.xml(this.mainPart).root.children[0];
3387
+ const result = detached.paragraph(detached.ref(this.mainPart, body.children[0]));
3388
+ Object.defineProperty(result, "part", { get: () => this.part(part) });
3389
+ return result;
3390
+ }
3391
+ async publish(options, context) {
3392
+ const revision = this.revision, caller = archiveSettings(context);
3393
+ const signal = AbortSignal.any([this.context.signal, caller.signal]);
3394
+ const limits = Object.fromEntries(
3395
+ Object.entries(this.context.limits).map(([key, value]) => [
3396
+ key,
3397
+ Math.min(value, caller.limits[key])
3398
+ ])
3399
+ );
3400
+ const budget = this.context.budget.lower(
3401
+ Object.fromEntries(
3402
+ Object.entries(this.context.budget.limits).map(([key, value]) => [
3403
+ key,
3404
+ Math.min(value, caller.budget.limits[key])
3405
+ ])
3406
+ ),
3407
+ signal
3408
+ );
3409
+ return publishDocumentArchive(this.snapshot(), options, {
3410
+ ...context,
3411
+ limits,
3412
+ signal,
3413
+ budget,
3414
+ encoding: { order: "input", compression: "store" },
3415
+ [publicationGenerationGuard]: () => {
3416
+ if (this.publishing || revision !== this.revision)
3417
+ throw new PublicationError("conflict", "Model changed before publication.");
3418
+ this.publishing = true;
3419
+ return () => {
3420
+ this.publishing = false;
3421
+ };
3422
+ }
3423
+ });
3424
+ }
3425
+ async save(output, options = {}) {
3426
+ const target = modelOutput(output, options, this.context, this.source);
3427
+ const revision = this.revision;
3428
+ await publishDocumentArchive(
3429
+ this.snapshot(),
3430
+ target.options,
3431
+ {
3432
+ ...this.context,
3433
+ ...target,
3434
+ encoding: { order: "input", compression: "store" },
3435
+ [publicationGenerationGuard]: () => {
3436
+ if (this.publishing || revision !== this.revision)
3437
+ throw new PublicationError("conflict", "Model changed before publication.");
3438
+ this.publishing = true;
3439
+ return () => {
3440
+ this.publishing = false;
3441
+ };
3442
+ }
3443
+ }
3444
+ );
3445
+ }
3446
+ };
3447
+
3448
+ export {
3449
+ Sections,
3450
+ Section,
3451
+ _Header,
3452
+ _Footer,
3453
+ Comments,
3454
+ Comment,
3455
+ Hyperlink,
3456
+ RenderedPageBreak,
3457
+ Settings,
3458
+ Drawing,
3459
+ InlineShape,
3460
+ InlineShapes,
3461
+ Paragraph,
3462
+ Run,
3463
+ DocumentView,
3464
+ Document,
3465
+ Table,
3466
+ _Cell,
3467
+ _Row,
3468
+ _Column,
3469
+ _Rows,
3470
+ _Columns,
3471
+ ModelStore
3472
+ };