@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,2817 @@
1
+ import {
2
+ propertyGroupDefinition,
3
+ readPropertyNodes,
4
+ storedBoolean,
5
+ storedBooleanValue,
6
+ storedIntegerIdentity,
7
+ trimXmlWhitespace
8
+ } from "./chunk-VEUQWV2V.js";
9
+ import {
10
+ relationshipXmlRows
11
+ } from "./chunk-2PSVE7I5.js";
12
+ import {
13
+ dialectForNamespace,
14
+ documentDialects,
15
+ validateXmlDialect
16
+ } from "./chunk-MG7AJD5E.js";
17
+ import {
18
+ styleFontFlags
19
+ } from "./chunk-M57GLLK4.js";
20
+ import {
21
+ Length,
22
+ Pt,
23
+ Twips
24
+ } from "./chunk-R4TYL2G6.js";
25
+ import {
26
+ MarkupCompatibility,
27
+ compatibilityContainers,
28
+ compatibilityProfileForRoot,
29
+ compatibilitySettings,
30
+ hasCompatibilityMarkup
31
+ } from "./chunk-GZ2N24A2.js";
32
+ import {
33
+ OwnershipError
34
+ } from "./chunk-OBK24KGM.js";
35
+ import {
36
+ InvalidXmlError,
37
+ documentXmlSettings,
38
+ parseDocumentXml
39
+ } from "./chunk-MWAAMNAM.js";
40
+ import {
41
+ DocxUsageError,
42
+ validFontName
43
+ } from "./chunk-2P7BLWWI.js";
44
+ import {
45
+ DocumentBudget,
46
+ InputTypeError,
47
+ InvalidDocumentError,
48
+ InvalidValueError,
49
+ ResourceLimitError,
50
+ documentXmlCache
51
+ } from "./chunk-IQFRPIXH.js";
52
+
53
+ // packages/safe-bash-docx-engine/src/xml-active-children.ts
54
+ var projections = /* @__PURE__ */ new WeakMap();
55
+ var immutableProjections = /* @__PURE__ */ new WeakMap();
56
+ function activeXmlChildren(xml2, budget) {
57
+ let children = projections.get(xml2);
58
+ if (!children) {
59
+ const content = "kind" in xml2 ? new MarkupCompatibility(xml2, void 0, budget).content : xml2.compatibility.content;
60
+ const root = "kind" in xml2 ? xml2 : xml2.root;
61
+ const cache = budget[documentXmlCache], profiles = cache.compatibility?.get(root);
62
+ let immutable = false;
63
+ if (cache.immutableRoots?.has(root) && profiles) {
64
+ for (const profile of profiles.values()) if (profile.content === content) {
65
+ immutable = true;
66
+ break;
67
+ }
68
+ }
69
+ const shared = immutable ? immutableProjections.get(content) : void 0;
70
+ const constructed = shared ? void 0 : /* @__PURE__ */ new Map();
71
+ const pending = [{ content, index: 0 }];
72
+ while (pending.length) {
73
+ const frame = pending.at(-1);
74
+ if (frame.index >= frame.content.length) {
75
+ pending.pop();
76
+ continue;
77
+ }
78
+ const item = frame.content[frame.index++];
79
+ if (!("source" in item)) continue;
80
+ budget.charge("retainedBytes", 96 + item.content.length * 8);
81
+ constructed?.set(
82
+ item.source,
83
+ Object.freeze(item.content.filter((node) => "source" in node).map((node) => node.source))
84
+ );
85
+ pending.push({ content: item.content, index: 0 });
86
+ }
87
+ children = shared ?? constructed;
88
+ if (immutable && !shared) immutableProjections.set(content, children);
89
+ projections.set(xml2, children);
90
+ }
91
+ return (node) => {
92
+ budget.charge("work", 1);
93
+ return children.get(node) ?? [];
94
+ };
95
+ }
96
+
97
+ // packages/safe-bash-docx-engine/src/xml-display.ts
98
+ function displayXml(root, budget, pretty) {
99
+ const chunks = [];
100
+ let size = 0;
101
+ const append = (text) => {
102
+ const bytes = new TextEncoder().encode(text).length;
103
+ budget.check("serializedOutput", size + bytes);
104
+ budget.charge("retainedBytes", text.length * 2 + 64);
105
+ budget.charge("work", text.length);
106
+ size += bytes;
107
+ chunks.push(text);
108
+ };
109
+ const escaped = (text, attribute = false) => {
110
+ let chunk = "";
111
+ for (const char of text) {
112
+ chunk += char === "&" ? "&amp;" : char === "<" ? "&lt;" : char === ">" ? "&gt;" : char === "\r" ? "&#13;" : attribute && char === '"' ? "&quot;" : attribute && char === "\n" ? "&#10;" : attribute && char === " " ? "&#9;" : char;
113
+ if (chunk.length >= 4096) {
114
+ append(chunk);
115
+ chunk = "";
116
+ }
117
+ }
118
+ if (chunk) append(chunk);
119
+ };
120
+ const visit = (node, depth, preserve) => {
121
+ budget.charge("retainedBytes", 64);
122
+ const pending = [{ node, depth, preserve, index: -1, indent: false }];
123
+ while (pending.length) {
124
+ const frame = pending.at(-1);
125
+ const current = frame.node;
126
+ if (frame.index === -1) {
127
+ budget.charge("work", 1);
128
+ if (current.kind !== "element") {
129
+ if (current.kind === "comment") append("<!--" + current.text + "-->");
130
+ else if (current.kind === "processing-instruction") append("<?" + current.target + (current.text ? " " + current.text : "") + "?>");
131
+ else if (current.kind === "cdata") append("<![CDATA[" + current.text + "]]>");
132
+ else escaped(current.text);
133
+ pending.pop();
134
+ continue;
135
+ }
136
+ const space = current.attributes.find((a) => a.namespace === "http://www.w3.org/XML/1998/namespace" && a.localName === "space")?.value;
137
+ frame.preserve = space === "preserve" || space !== "default" && frame.preserve;
138
+ append("<" + current.name);
139
+ for (const attr of current.attributes) {
140
+ append(" " + attr.name + '="');
141
+ escaped(attr.value, true);
142
+ append('"');
143
+ }
144
+ if (!current.content.length) {
145
+ append("/>");
146
+ pending.pop();
147
+ continue;
148
+ }
149
+ append(">");
150
+ frame.indent = pretty && !frame.preserve && !current.content.some((child2) => child2.kind === "text" || child2.kind === "cdata");
151
+ frame.index = 0;
152
+ }
153
+ if (current.kind !== "element") continue;
154
+ const child = current.content[frame.index++];
155
+ if (child) {
156
+ if (frame.indent) append("\n" + " ".repeat(frame.depth + 1));
157
+ budget.charge("retainedBytes", 64);
158
+ pending.push({ node: child, depth: frame.depth + 1, preserve: frame.preserve, index: -1, indent: false });
159
+ } else {
160
+ if (frame.indent) append("\n" + " ".repeat(frame.depth));
161
+ append("</" + current.name + ">");
162
+ pending.pop();
163
+ }
164
+ }
165
+ };
166
+ if (root.declaration !== void 0) append('<?xml version="1.0" encoding="UTF-8"?>');
167
+ for (const node of root.prolog ?? []) visit(node, 0, false);
168
+ visit(root, 0, false);
169
+ for (const node of root.epilog ?? []) visit(node, 0, false);
170
+ return chunks.join("");
171
+ }
172
+
173
+ // packages/safe-bash-docx-engine/src/xml-retention.ts
174
+ function opaqueXmlContent(root, budget, profile) {
175
+ const view = new MarkupCompatibility(root, profile, budget);
176
+ const containers = new Set(view[compatibilityContainers]);
177
+ const records = [];
178
+ const nativeProperties = (node) => (node.namespace === documentDialects.strict.w || node.namespace === documentDialects.transitional.w) && ["pPr", "rPr", "sectPr", "tabs", "tblPr", "trPr", "tcPr"].includes(node.localName);
179
+ const path = [];
180
+ budget.charge("retainedBytes", 128);
181
+ const pending = [{ node: root, inherited: /* @__PURE__ */ new Map(), propertyContext: false, ordinals: /* @__PURE__ */ new Map(), contentIndex: 0, index: -1 }];
182
+ while (pending.length) {
183
+ const frame = pending.at(-1);
184
+ const node = frame.node;
185
+ if (frame.index === -1) {
186
+ const inherited = frame.inherited;
187
+ budget.charge("work", 1 + node.attributes.length + inherited.size);
188
+ budget.charge("retainedBytes", (inherited.size + 1) * 48);
189
+ const context = new Map(inherited);
190
+ for (const attribute of node.attributes) {
191
+ if (attribute.namespace !== "http://www.w3.org/XML/1998/namespace" || !["lang", "space", "base"].includes(attribute.localName)) continue;
192
+ budget.charge("retainedBytes", attribute.localName === "base" ? ((context.get("base")?.length ?? 0) + 1) * 8 : 8);
193
+ context.set(attribute.localName, attribute.localName === "base" ? [...context.get("base") ?? [], attribute.value] : [attribute.value]);
194
+ }
195
+ frame.context = context;
196
+ const namedStyleFields = (node.namespace === documentDialects.strict.w || node.namespace === documentDialects.transitional.w) && node.localName === "style";
197
+ frame.namedProperties = nativeProperties(node) || namedStyleFields || containers.has(node) && frame.propertyContext;
198
+ const retainPath = () => {
199
+ budget.charge("retainedBytes", path.length * 8);
200
+ return path.slice();
201
+ };
202
+ if (containers.has(node)) {
203
+ records.push([retainPath(), node.namespace, node.localName, [...node.namespaces], [...context], node.attributes, node.content.filter((item) => item.kind !== "element")]);
204
+ } else if (!view.canEdit(node)) {
205
+ const { declaration: ignoredDeclaration, ...content } = node;
206
+ budget.charge("retainedBytes", 192);
207
+ records.push([retainPath(), [...node.namespaces], [...context], displayXml(content, budget, false)]);
208
+ pending.pop();
209
+ path.pop();
210
+ continue;
211
+ } else {
212
+ const attributes = node.attributes.filter((attribute) => attribute.namespace !== "http://www.w3.org/2000/xmlns/" && !view.canEdit(attribute));
213
+ if (attributes.length) records.push([retainPath(), [...node.namespaces], [...context], attributes]);
214
+ }
215
+ frame.index = 0;
216
+ }
217
+ const child = node.children[frame.index++];
218
+ if (!child) {
219
+ pending.pop();
220
+ path.pop();
221
+ continue;
222
+ }
223
+ let slot;
224
+ if (frame.namedProperties || nativeProperties(child)) {
225
+ const name = JSON.stringify([child.namespace, child.localName]);
226
+ const ordinal = frame.ordinals.get(name) ?? 0;
227
+ frame.ordinals.set(name, ordinal + 1);
228
+ budget.charge("work", name.length);
229
+ budget.charge("retainedBytes", name.length * 4 + 48);
230
+ slot = name + ":" + ordinal;
231
+ } else slot = frame.contentIndex++;
232
+ budget.charge("retainedBytes", 136);
233
+ path.push(slot);
234
+ pending.push({ node: child, inherited: frame.context, propertyContext: frame.namedProperties, ordinals: /* @__PURE__ */ new Map(), contentIndex: 0, index: -1 });
235
+ }
236
+ return JSON.stringify(records);
237
+ }
238
+
239
+ // packages/safe-bash-docx-engine/src/stored-measure.ts
240
+ function storedMeasure(raw, unit = "twip", message = "Invalid stored document measure.") {
241
+ const text = trimXmlWhitespace(raw), multiplier = { in: 914400, cm: 36e4, mm: 36e3, pt: 12700, pc: 152400, pi: 152400 }[text.slice(-2)];
242
+ const physical = multiplier !== void 0, scalar = physical ? text.slice(0, -2) : text;
243
+ let start = scalar[0] === "-" || !physical && scalar[0] === "+" ? 1 : 0;
244
+ if (start === scalar.length || physical && unit !== "twip" && scalar[0] === "-") throw new InvalidDocumentError(message);
245
+ let digits = 0, decimal = false;
246
+ for (; start < scalar.length; start++) {
247
+ const character = scalar[start];
248
+ if (character >= "0" && character <= "9") {
249
+ digits++;
250
+ continue;
251
+ }
252
+ if (physical && character === "." && !decimal && digits > 0 && start < scalar.length - 1) {
253
+ decimal = true;
254
+ continue;
255
+ }
256
+ throw new InvalidDocumentError(message);
257
+ }
258
+ const value = Number(scalar);
259
+ if (!digits || !Number.isFinite(value) || !physical && !Number.isSafeInteger(value) || unit !== "twip" && value < 0) throw new InvalidDocumentError(message);
260
+ try {
261
+ return physical ? Length(value * multiplier) : unit === "half-point" ? Pt(value / 2) : Twips(value);
262
+ } catch (error) {
263
+ if (error instanceof RangeError || error instanceof TypeError) throw new InvalidDocumentError(message);
264
+ throw error;
265
+ }
266
+ }
267
+
268
+ // packages/safe-bash-docx-engine/src/run-properties.ts
269
+ var underline = { NONE: "none", SINGLE: "single", WORDS: "words", DOUBLE: "double", DOTTED: "dotted", THICK: "thick", DASH: "dash", DOT_DASH: "dotDash", DOT_DOT_DASH: "dotDotDash", WAVY: "wave", DOTTED_HEAVY: "dottedHeavy", DASH_HEAVY: "dashedHeavy", DOT_DASH_HEAVY: "dashDotHeavy", DOT_DOT_DASH_HEAVY: "dashDotDotHeavy", WAVY_HEAVY: "wavyHeavy", DASH_LONG: "dashLong", WAVY_DOUBLE: "wavyDouble", DASH_LONG_HEAVY: "dashLongHeavy" };
270
+ var highlights = { AUTO: "default", BLACK: "black", BLUE: "blue", BRIGHT_GREEN: "green", DARK_BLUE: "darkBlue", DARK_RED: "darkRed", DARK_YELLOW: "darkYellow", GRAY_25: "lightGray", GRAY_50: "darkGray", GREEN: "darkGreen", PINK: "magenta", RED: "red", TEAL: "darkCyan", TURQUOISE: "cyan", VIOLET: "darkMagenta", WHITE: "white", YELLOW: "yellow" };
271
+ var themes = { ACCENT_1: "accent1", ACCENT_2: "accent2", ACCENT_3: "accent3", ACCENT_4: "accent4", ACCENT_5: "accent5", ACCENT_6: "accent6", BACKGROUND_1: "background1", BACKGROUND_2: "background2", DARK_1: "dark1", DARK_2: "dark2", FOLLOWED_HYPERLINK: "followedHyperlink", HYPERLINK: "hyperlink", LIGHT_1: "light1", LIGHT_2: "light2", TEXT_1: "text1", TEXT_2: "text2" };
272
+ var order = "rStyle rFonts b bCs i iCs caps smallCaps strike dstrike outline shadow emboss imprint noProof snapToGrid vanish webHidden color spacing w kern position sz szCs highlight u effect bdr shd fitText vertAlign rtl cs em lang eastAsianLayout specVanish oMath rPrChange".split(" ");
273
+ var toggles = new Set("b bCs i iCs caps smallCaps strike dstrike outline shadow emboss imprint noProof snapToGrid vanish webHidden rtl cs specVanish oMath".split(" "));
274
+ var xmlns = "http://www.w3.org/2000/xmlns/";
275
+ function runElementOpen(node) {
276
+ return `<${node.name}${[...node.namespaces].filter(([prefix]) => prefix !== "xml").map(([prefix, uri]) => ` ${prefix ? "xmlns:" + prefix : "xmlns"}="${xmlValue(uri)}"`).join("")}${node.attributes.filter((a) => a.namespace !== xmlns).map((a) => ` ${a.name}="${xmlValue(a.value)}"`).join("")}>`;
277
+ }
278
+ function formattedRunProperties(editor, run, options, children = (node) => node.children, metadata = {}) {
279
+ for (const value of [
280
+ options.font,
281
+ options.ascii,
282
+ options.highAnsi,
283
+ options.eastAsia,
284
+ options.complexScript,
285
+ metadata.ascii,
286
+ metadata.highAnsi,
287
+ metadata.eastAsia,
288
+ metadata.complexScript
289
+ ]) {
290
+ if (value !== void 0 && value !== null && !validFontName(value))
291
+ throw new InvalidValueError("Font references must be nonempty names without control characters.");
292
+ }
293
+ const w = run.namespace;
294
+ const containers = children(run).filter((c) => c.namespace === w && c.localName === "rPr");
295
+ if (containers.length > 1) throw new UnsupportedEditError("Duplicate run property containers cannot be edited.");
296
+ const props = containers[0];
297
+ const patches = /* @__PURE__ */ new Map();
298
+ const added = [];
299
+ const property = (name, attrs) => {
300
+ const matches = props ? children(props).filter((c) => c.namespace === w && c.localName === name) : [];
301
+ if (matches.length > 1) throw new UnsupportedEditError("Duplicate direct properties cannot be edited.");
302
+ const node = matches[0];
303
+ if (attrs === null) {
304
+ if (node) patches.set(node, "");
305
+ return;
306
+ }
307
+ const old = new Map(node?.attributes.filter((a) => a.namespace === w).map((a) => [a.localName, a.value]));
308
+ if (node && Object.entries(attrs).every(([key, value]) => {
309
+ const existing = old.get(key);
310
+ if (value === null) return existing === void 0;
311
+ if (key === "val" && toggles.has(name)) return storedBooleanValue(existing ?? "1") === (value === "1");
312
+ if (key === "val" && name === "sz") return existing !== void 0 && Number(existing) === Number(value);
313
+ return existing === value;
314
+ })) return;
315
+ const prefix = node?.name.includes(":") ? node.name.split(":")[0] : [...node?.namespaces ?? run.namespaces].find(([prefix2, uri]) => prefix2 && uri === w)?.[0] ?? "fmt";
316
+ const qualified = node?.name ?? `${prefix}:${name}`;
317
+ const retained = node?.attributes.filter((a) => a.namespace !== xmlns && !(a.namespace === w && Object.hasOwn(attrs, a.localName))).map((a) => ` ${a.name}="${xmlValue(a.value)}"`).join("") ?? "";
318
+ const bindings = new Map(node?.namespaces ?? run.namespaces);
319
+ bindings.set(prefix, w);
320
+ const declarations = [...bindings].filter(([p]) => p !== "xml").map(([p, uri]) => ` ${p ? "xmlns:" + p : "xmlns"}="${xmlValue(uri)}"`).join("");
321
+ const values = Object.entries(attrs).filter(([, value]) => value !== null).map(([key, value]) => ` ${prefix}:${key}="${xmlValue(value)}"`).join("");
322
+ const content2 = node ? editor.sourceXml(node, /* @__PURE__ */ new Map(), true) : "";
323
+ const xml2 = !retained && !values && !content2 ? "" : `<${qualified}${declarations}${retained}${values}${content2 ? ">" + content2 + `</${qualified}>` : "/>"}`;
324
+ if (node) patches.set(node, xml2);
325
+ else if (xml2) added.push({ name, xml: xml2 });
326
+ };
327
+ for (const [key, name] of [["bold", "b"], ["italic", "i"], ["strike", "strike"], ["hidden", "vanish"], ["rtl", "rtl"], ["allCaps", "caps"], ["complexScriptEnabled", "cs"], ["csBold", "bCs"], ["csItalic", "iCs"], ["doubleStrike", "dstrike"], ["emboss", "emboss"], ["imprint", "imprint"], ["math", "oMath"], ["noProof", "noProof"], ["outline", "outline"], ["shadow", "shadow"], ["smallCaps", "smallCaps"], ["snapToGrid", "snapToGrid"], ["specVanish", "specVanish"], ["webHidden", "webHidden"]]) {
328
+ const value = options[key];
329
+ if (value !== void 0) property(name, value === null ? null : { val: String(Number(value)) });
330
+ }
331
+ if (options.underline !== void 0) property("u", options.underline === null ? null : { val: typeof options.underline === "boolean" ? options.underline ? "single" : "none" : underline[options.underline.name] });
332
+ if (options.highlight !== void 0) property("highlight", options.highlight === null ? null : { val: highlights[options.highlight.name] });
333
+ if (options.size !== void 0) {
334
+ const units = { emu: 1, in: 914400, cm: 36e4, mm: 36e3, pt: 12700 };
335
+ property("sz", options.size === null ? null : { val: String(Math.round(Math.round(options.size.value * units[options.size.unit]) / 6350)) });
336
+ }
337
+ const fonts = {};
338
+ if (options.font !== void 0) Object.assign(fonts, { ascii: options.font, hAnsi: options.font });
339
+ for (const [key, attr] of [["ascii", "ascii"], ["highAnsi", "hAnsi"], ["eastAsia", "eastAsia"], ["complexScript", "cs"], ["asciiTheme", "asciiTheme"], ["highAnsiTheme", "hAnsiTheme"], ["eastAsiaTheme", "eastAsiaTheme"], ["complexScriptTheme", "cstheme"]])
340
+ if (options[key] !== void 0) fonts[attr] = options[key];
341
+ for (const [key, attr] of [["ascii", "ascii"], ["highAnsi", "hAnsi"], ["eastAsia", "eastAsia"], ["complexScript", "cs"]]) {
342
+ if (metadata[key] !== void 0) fonts[attr] = metadata[key];
343
+ if (metadata.theme === null) fonts[attr === "cs" ? "cstheme" : attr + "Theme"] = null;
344
+ else if (metadata.theme?.[key] !== void 0) fonts[attr === "cs" ? "cstheme" : attr + "Theme"] = metadata.theme[key];
345
+ }
346
+ if (Object.keys(fonts).length) property("rFonts", fonts);
347
+ const language = {};
348
+ if (options.language !== void 0) language.val = options.language;
349
+ for (const [key, attr] of [["latin", "val"], ["eastAsia", "eastAsia"], ["bidi", "bidi"]]) {
350
+ if (metadata.language === null) language[attr] = null;
351
+ else if (metadata.language?.[key] !== void 0) language[attr] = metadata.language[key];
352
+ }
353
+ if (Object.keys(language).length) property("lang", language);
354
+ if (options.color !== void 0 && options.themeColor === void 0) property("color", options.color === null ? null : { val: options.color.toUpperCase(), themeColor: null, themeTint: null, themeShade: null });
355
+ if (options.themeColor !== void 0) {
356
+ const color = props && children(props).find((c) => c.namespace === w && c.localName === "color");
357
+ property("color", options.themeColor === null ? { themeColor: null, themeTint: null, themeShade: null } : {
358
+ ...color?.attributes.some((a) => a.namespace === w && a.localName === "val") ? {} : { val: options.color ?? "auto" },
359
+ themeColor: themes[options.themeColor.name]
360
+ });
361
+ }
362
+ const baseline = options.baseline !== void 0 ? options.baseline : options.superscript === true ? "superscript" : options.subscript === true ? "subscript" : options.superscript === false || options.subscript === false ? "baseline" : options.superscript === null || options.subscript === null ? null : void 0;
363
+ if (baseline !== void 0) property("vertAlign", baseline === null ? null : { val: baseline });
364
+ if (!patches.size && !added.length) return props ? editor.sourceXml(props) : "";
365
+ let tail = "";
366
+ const insertions = /* @__PURE__ */ new Map();
367
+ for (const addition of added.sort((a, b) => order.indexOf(a.name) - order.indexOf(b.name))) {
368
+ const next = props && children(props).find((child) => child.namespace === w && order.indexOf(child.localName) > order.indexOf(addition.name));
369
+ if (next) insertions.set(next, (insertions.get(next) ?? "") + addition.xml);
370
+ else tail += addition.xml;
371
+ }
372
+ for (const [node, markup] of insertions) patches.set(node, markup + (patches.get(node) ?? editor.sourceXml(node)));
373
+ const content = (props ? editor.sourceXml(props, patches, true) : "") + tail;
374
+ if (!content && (!props || props.attributes.every((a) => a.namespace === xmlns))) return "";
375
+ return props ? runElementOpen(props) + content + `</${props.name}>` : `<fmt:rPr xmlns:fmt="${xmlValue(w)}">${content}</fmt:rPr>`;
376
+ }
377
+ function equivalentRunKey(run) {
378
+ const w = run.namespace;
379
+ if (run.content.some((c) => c.kind !== "element") || run.children.some((c) => c.namespace !== w || !["rPr", "t", "tab", "br", "cr", "noBreakHyphen", "softHyphen"].includes(c.localName))) return void 0;
380
+ if (run.children.some((c) => c.localName !== "rPr" && c.content.some((child) => child.kind !== "text"))) return void 0;
381
+ const props = run.children.filter((c) => c.localName === "rPr");
382
+ if (props.length > 1 || props.some((p) => p.content.some((c) => c.kind !== "element") || p.children.some((c) => c.namespace !== w || c.content.length || !order.includes(c.localName)))) return void 0;
383
+ const attributes = (node, toggle = false) => {
384
+ const attrs = node.attributes.filter((a) => a.namespace !== xmlns).map((a) => [a.namespace, a.localName, toggle && a.namespace === w && a.localName === "val" ? storedBooleanValue(a.value) === false ? "0" : storedBooleanValue(a.value) === true ? "1" : a.value : a.value]);
385
+ if (toggle && !attrs.some((a) => a[0] === w && a[1] === "val")) attrs.push([w, "val", "1"]);
386
+ return attrs.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
387
+ };
388
+ const children = props[0]?.children ?? [];
389
+ if (new Set(children.map((c) => c.localName)).size !== children.length) return void 0;
390
+ return JSON.stringify([attributes(run), props[0] ? attributes(props[0]) : [], children.map((c) => [c.localName, attributes(c, toggles.has(c.localName))]).sort((a, b) => String(a[0]).localeCompare(String(b[0])))]);
391
+ }
392
+
393
+ // packages/safe-bash-docx-engine/src/paragraph-properties.ts
394
+ function paragraphUnits(value, divisor = 635) {
395
+ const emu = value.value * { emu: 1, in: 914400, cm: 36e4, mm: 36e3, pt: 12700, twip: 635 }[value.unit];
396
+ const rounded = Math.sign(emu) * Math.round(Math.abs(emu));
397
+ const result = Math.sign(rounded) * Math.round(Math.abs(rounded) / divisor);
398
+ if (!Number.isSafeInteger(rounded) || !Number.isSafeInteger(result))
399
+ throw new DocxUsageError("Paragraph length exceeds safe integer storage.");
400
+ return result;
401
+ }
402
+ var order2 = "pStyle keepNext keepLines pageBreakBefore framePr widowControl numPr suppressLineNumbers pBdr shd tabs suppressAutoHyphens kinsoku wordWrap overflowPunct topLinePunct autoSpaceDE autoSpaceDN bidi adjustRightInd snapToGrid spacing ind contextualSpacing mirrorIndents suppressOverlap jc textDirection textAlignment textboxTightWrap outlineLvl divId cnfStyle rPr sectPr pPrChange".split(" ");
403
+ var alignments = { LEFT: "left", CENTER: "center", RIGHT: "right", JUSTIFY: "both", DISTRIBUTE: "distribute", JUSTIFY_MED: "mediumKashida", JUSTIFY_HI: "highKashida", JUSTIFY_LOW: "lowKashida", THAI_JUSTIFY: "thaiDistribute" };
404
+ var tabAlignments = { LEFT: "left", CENTER: "center", RIGHT: "right", DECIMAL: "decimal", BAR: "bar", LIST: "list", CLEAR: "clear", END: "end", NUM: "num", START: "start" };
405
+ function tabAlignmentXml(namespace, name) {
406
+ const strict = namespace === documentDialects.strict.w;
407
+ if (strict && name === "LIST") throw new UnsupportedEditError("The deprecated list tab alignment is unavailable in Strict documents.");
408
+ const value = tabAlignments[name];
409
+ return strict ? { left: "start", right: "end" }[value] ?? value : value;
410
+ }
411
+ var leaders = { SPACES: "none", DOTS: "dot", DASHES: "hyphen", LINES: "underscore", HEAVY: "heavy", MIDDLE_DOT: "middleDot" };
412
+ var paragraphLineMultiples = { SINGLE: 1, ONE_POINT_FIVE: 1.5, DOUBLE: 2 };
413
+ function newTabStopXml(namespace, tab, spacesLeader = "none") {
414
+ const leader = !tab.leader || tab.leader.name === "SPACES" ? spacesLeader : leaders[tab.leader.name];
415
+ return `<pf:tab xmlns:pf="${xmlValue(namespace)}" pf:pos="${paragraphUnits(tab.position)}" pf:val="${tabAlignmentXml(namespace, tab.alignment?.name ?? "LEFT")}"${leader === null ? "" : ` pf:leader="${leader}"`}></pf:tab>`;
416
+ }
417
+ function paragraphProperties(xml2, paragraph, options, styleId, children = (node) => node.children, spacesLeader = "none") {
418
+ for (const value of [options.spaceBefore, options.spaceAfter, typeof options.lineSpacing === "object" ? options.lineSpacing : void 0]) {
419
+ if (value != null && value.value < 0) throw new DocxUsageError("Paragraph spacing cannot be negative.");
420
+ }
421
+ if (typeof options.lineSpacing === "number") {
422
+ const line = Math.round(options.lineSpacing * 240);
423
+ if (line < 1 || !Number.isSafeInteger(line)) throw new DocxUsageError("Line spacing multiples must round to positive safe integer storage.");
424
+ }
425
+ const w = paragraph.namespace;
426
+ const strict = w === documentDialects.strict.w;
427
+ const directional = (value) => strict ? { left: "start", right: "end" }[value] ?? value : value;
428
+ const containers = children(paragraph).filter((c) => c.namespace === w && c.localName === "pPr");
429
+ if (containers.length > 1) throw new UnsupportedEditError("Duplicate paragraph property containers cannot be edited.");
430
+ const props = containers[0];
431
+ const patches = /* @__PURE__ */ new Map();
432
+ const added = /* @__PURE__ */ new Map();
433
+ const mergeOrdered = (parent, replacements, additions, names) => {
434
+ const prefixes = /* @__PURE__ */ new Map();
435
+ let tail = "";
436
+ for (const name of names) {
437
+ const markup = additions.get(name);
438
+ if (markup === void 0) continue;
439
+ const next = parent && children(parent).find((c) => c.namespace === w && names.indexOf(c.localName) > names.indexOf(name));
440
+ if (next) prefixes.set(next, (prefixes.get(next) ?? "") + markup);
441
+ else tail += markup;
442
+ }
443
+ for (const [node, prefix] of prefixes) replacements.set(node, prefix + (replacements.get(node) ?? xml2.sourceXml(node)));
444
+ return (parent ? xml2.sourceXml(parent, replacements, true) : "") + tail;
445
+ };
446
+ const find = (name, parent = props) => {
447
+ const matches = parent ? children(parent).filter((c) => c.namespace === w && c.localName === name) : [];
448
+ if (matches.length > 1) throw new UnsupportedEditError("Duplicate paragraph properties cannot be edited.");
449
+ return matches[0];
450
+ };
451
+ const element = (name, attrs, node, content2) => {
452
+ const prefix = node?.name.includes(":") ? node.name.split(":")[0] : [...node?.namespaces ?? paragraph.namespaces].find(([prefix2, uri]) => prefix2 && uri === w)?.[0] ?? "pf";
453
+ const qualified = node?.name ?? `${prefix}:${name}`;
454
+ const retained = node?.attributes.filter((a) => a.namespace !== "http://www.w3.org/2000/xmlns/" && !(a.namespace === w && Object.hasOwn(attrs, a.localName))) ?? [];
455
+ const attributes = [...retained.map((a) => ` ${a.name}="${xmlValue(a.value)}"`), ...Object.entries(attrs).filter(([, v]) => v !== null).map(([k, v]) => ` ${prefix}:${k}="${xmlValue(v)}"`)].join("");
456
+ const namespaces = new Map(node?.namespaces);
457
+ namespaces.set(prefix, w);
458
+ const bindings = [...namespaces].filter(([p]) => p !== "xml").map(([p, uri]) => ` ${p ? "xmlns:" + p : "xmlns"}="${xmlValue(uri)}"`).join("");
459
+ const inner = content2 ?? (node ? xml2.sourceXml(node, /* @__PURE__ */ new Map(), true) : "");
460
+ return `<${qualified}${bindings}${attributes}>${inner}</${qualified}>`;
461
+ };
462
+ const set = (name, attrs, content2) => {
463
+ const node = find(name);
464
+ if (attrs === null) {
465
+ if (node) patches.set(node, "");
466
+ return;
467
+ }
468
+ if (!node && !content2 && Object.values(attrs).every((value) => value === null)) return;
469
+ if (node && content2 === void 0 && Object.entries(attrs).every(([key, value]) => {
470
+ const old = node.attributes.find((a) => a.namespace === w && a.localName === key)?.value;
471
+ if (["keepNext", "keepLines", "widowControl", "pageBreakBefore"].includes(name) && key === "val")
472
+ return (value === "1" || value === "0") && storedBooleanValue(old ?? "1") === (value === "1");
473
+ return value === null ? old === void 0 : old === value;
474
+ })) return;
475
+ const markup = element(name, attrs, node, content2);
476
+ if (node) patches.set(node, markup);
477
+ else added.set(name, markup);
478
+ };
479
+ if (styleId !== void 0) set("pStyle", { val: styleId });
480
+ if (options.alignment !== void 0) set("jc", options.alignment === null ? null : { val: directional(alignments[options.alignment.name]) });
481
+ for (const [key, name] of [["keepWithNext", "keepNext"], ["keepTogether", "keepLines"], ["widowControl", "widowControl"], ["pageBreakBefore", "pageBreakBefore"]]) {
482
+ const value = options[key];
483
+ if (value !== void 0) set(name, value === null ? null : { val: String(Number(value)) });
484
+ }
485
+ if (options.outlineLevel !== void 0) set("outlineLvl", options.outlineLevel === null ? null : { val: String(options.outlineLevel) });
486
+ const indentation = {};
487
+ for (const [key, name, alternate] of [["leftIndent", "left", "start"], ["rightIndent", "right", "end"]]) {
488
+ const value = options[key];
489
+ if (value !== void 0) Object.assign(indentation, { [strict ? alternate : name]: value === null ? null : String(paragraphUnits(value)), [name + "Chars"]: null, [strict ? name : alternate]: null, [alternate + "Chars"]: null });
490
+ }
491
+ if (options.firstLineIndent !== void 0) {
492
+ const n = options.firstLineIndent === null ? null : paragraphUnits(options.firstLineIndent);
493
+ Object.assign(indentation, { firstLine: n !== null && n >= 0 ? String(n) : null, hanging: n !== null && n < 0 ? String(-n) : null, firstLineChars: null, hangingChars: null });
494
+ }
495
+ if (Object.keys(indentation).length) set("ind", indentation);
496
+ const spacing = {};
497
+ for (const [key, name] of [["spaceBefore", "before"], ["spaceAfter", "after"]]) {
498
+ const value = options[key];
499
+ if (value !== void 0) Object.assign(spacing, { [name]: value === null ? null : String(paragraphUnits(value)), [name + "Lines"]: null, [name + "Autospacing"]: null });
500
+ }
501
+ if (options.lineSpacing !== void 0) {
502
+ const value = options.lineSpacing;
503
+ Object.assign(spacing, { line: value === null ? null : String(typeof value === "number" ? Math.round(value * 240) : paragraphUnits(value)), lineRule: value === null ? null : typeof value === "number" ? "auto" : "exact" });
504
+ }
505
+ if (options.lineSpacingRule !== void 0) {
506
+ const rule = options.lineSpacingRule?.name;
507
+ if (rule === void 0) spacing.lineRule = null;
508
+ else {
509
+ spacing.lineRule = rule === "EXACTLY" ? "exact" : rule === "AT_LEAST" ? "atLeast" : "auto";
510
+ const fixed = paragraphLineMultiples[rule];
511
+ if (fixed !== void 0) spacing.line = String(fixed * 240);
512
+ }
513
+ }
514
+ if (Object.keys(spacing).length) set("spacing", spacing);
515
+ if (options.tabStops !== void 0) set("tabs", options.tabStops === null || options.tabStops.length === 0 ? null : {}, options.tabStops?.slice().sort((a, b) => paragraphUnits(a.position) - paragraphUnits(b.position)).map((tab) => element("tab", { pos: String(paragraphUnits(tab.position)), val: tabAlignmentXml(w, tab.alignment?.name ?? "LEFT"), leader: !tab.leader || tab.leader.name === "SPACES" ? spacesLeader : leaders[tab.leader.name] })).join(""));
516
+ if (options.tabStopsClear === true) {
517
+ const container = find("tabs");
518
+ if (container) {
519
+ const stops = children(container).filter((c) => c.namespace === w && c.localName === "tab");
520
+ if (container.attributes.every((a) => a.namespace === "http://www.w3.org/2000/xmlns/") && container.content.every((c) => c.kind === "element" && stops.includes(c))) set("tabs", null);
521
+ else {
522
+ const removals = new Map(stops.map((stop) => [stop, ""]));
523
+ patches.set(container, runElementOpen(container) + xml2.sourceXml(container, removals, true) + `</${container.name}>`);
524
+ }
525
+ }
526
+ }
527
+ if (options.tabStopAdd !== void 0 || options.tabStopDelete !== void 0) {
528
+ const container = find("tabs");
529
+ const stops = container ? children(container).filter((c) => c.namespace === w && c.localName === "tab") : [];
530
+ const changes = /* @__PURE__ */ new Map();
531
+ let tail = "";
532
+ if (options.tabStopDelete !== void 0) {
533
+ const index = options.tabStopDelete < 0 ? stops.length + options.tabStopDelete : options.tabStopDelete;
534
+ const stop = stops[index];
535
+ if (!stop) throw new UnsupportedEditError("Tab stop index is out of range.");
536
+ changes.set(stop, "");
537
+ } else {
538
+ const tab = options.tabStopAdd;
539
+ const position = paragraphUnits(tab.position);
540
+ const markup = newTabStopXml(w, tab, spacesLeader);
541
+ const positions = stops.map((stop) => {
542
+ const stored = stop.attributes.find((a) => a.namespace === w && a.localName === "pos")?.value;
543
+ if (stored === void 0) throw new UnsupportedEditError("Malformed tab stop positions cannot be edited.");
544
+ try {
545
+ return storedMeasure(stored).emu / 635;
546
+ } catch (error) {
547
+ if (error instanceof InvalidDocumentError) throw new UnsupportedEditError("Malformed tab stop positions cannot be edited.");
548
+ throw error;
549
+ }
550
+ });
551
+ const next = stops.find((_, index) => positions[index] > position);
552
+ if (next) changes.set(next, markup + xml2.sourceXml(next));
553
+ else tail = markup;
554
+ }
555
+ const content2 = (container ? xml2.sourceXml(container, changes, true) : "") + tail;
556
+ if (options.tabStopDelete !== void 0 && stops.length === 1 && container?.content.every((c) => c.kind === "element" && c.namespace === w && c.localName === "tab")) set("tabs", null);
557
+ else if (container) patches.set(container, runElementOpen(container) + content2 + `</${container.name}>`);
558
+ else set("tabs", {}, content2);
559
+ }
560
+ if (options.shading !== void 0) set("shd", options.shading === null ? null : { fill: options.shading.fill.toUpperCase(), color: options.shading.color?.toUpperCase() ?? "000000", val: options.shading.pattern, themeFill: null, themeFillTint: null, themeFillShade: null, themeColor: null, themeTint: null, themeShade: null });
561
+ if (options.borders !== void 0) {
562
+ if (options.borders === null) set("pBdr", null);
563
+ else if (Object.keys(options.borders).length) {
564
+ const container = find("pBdr"), replacements = /* @__PURE__ */ new Map();
565
+ const additions = /* @__PURE__ */ new Map();
566
+ for (const name of ["top", "left", "bottom", "right", "between"]) {
567
+ const border = options.borders[name];
568
+ if (!border) continue;
569
+ const node = find(name, container);
570
+ const markup = element(name, { val: border.style, sz: String(paragraphUnits(border.width, 12700 / 8)), color: border.color.toUpperCase(), ...border.space === void 0 ? node ? {} : { space: "0" } : { space: String(paragraphUnits(border.space, 12700)) }, themeColor: null, themeTint: null, themeShade: null }, node);
571
+ if (node) replacements.set(node, markup);
572
+ else additions.set(name, markup);
573
+ }
574
+ set("pBdr", {}, mergeOrdered(container, replacements, additions, ["top", "left", "bottom", "right", "between", "bar"]));
575
+ }
576
+ }
577
+ if (!patches.size && !added.size) return props ? xml2.sourceXml(props) : "";
578
+ const content = mergeOrdered(props, patches, added, order2);
579
+ return props ? runElementOpen(props) + content + `</${props.name}>` : `<pf:pPr xmlns:pf="${w}">${content}</pf:pPr>`;
580
+ }
581
+
582
+ // packages/safe-bash-docx-engine/src/table-content.ts
583
+ function tableBorders(borders, tag, w) {
584
+ if (!borders) return "";
585
+ const edges = ["top", "left", "bottom", "right", "insideH", "insideV"];
586
+ return `<w:${tag}>${edges.map((edge) => {
587
+ const border = borders[edge];
588
+ if (!border) return "";
589
+ const size = paragraphUnits(border.width, 12700 / 8), space = border.space ? paragraphUnits(border.space, 12700) : 0;
590
+ if (border.width.value < 0 || size < (border.style === "none" ? 0 : 2) || size > 96 || (border.space?.value ?? 0) < 0 || space > 31)
591
+ throw new InvalidValueError("Table border width or spacing is outside the supported range.");
592
+ const name = w === documentDialects.strict.w ? { left: "start", right: "end" }[edge] ?? edge : edge;
593
+ return `<w:${name} w:val="${border.style}" w:sz="${size}" w:color="${border.color.toUpperCase()}" w:space="${space}"/>`;
594
+ }).join("")}</w:${tag}>`;
595
+ }
596
+ function tableShading(shading) {
597
+ return shading ? `<w:shd w:val="${shading.pattern}" w:color="${shading.color?.toUpperCase() ?? "auto"}" w:fill="${shading.fill.toUpperCase()}"/>` : "";
598
+ }
599
+ function tableMargins(margins, tag, w) {
600
+ if (!margins) return "";
601
+ return `<w:${tag}>${["top", "left", "bottom", "right"].map((edge) => {
602
+ const value = margins[edge];
603
+ if (!value) return "";
604
+ const name = w === documentDialects.strict.w ? { left: "start", right: "end" }[edge] ?? edge : edge;
605
+ return `<w:${name} w:w="${twips(value, false)}" w:type="dxa"/>`;
606
+ }).join("")}</w:${tag}>`;
607
+ }
608
+ function tableGeometry(table, available, w) {
609
+ const columns = table.rows[0].length;
610
+ const supplied = table.columnWidths?.map((v) => twips(v));
611
+ if (supplied && supplied.length !== columns) throw new InvalidValueError("Column widths must match the grid column count.");
612
+ const sum = supplied?.reduce((total, width2) => total + width2, 0);
613
+ const width = table.width ? twips(table.width) : sum ?? available;
614
+ if (width < columns || width > available || !Number.isSafeInteger(width) || sum !== void 0 && width !== sum)
615
+ throw new InvalidValueError("Table grid widths must sum to a positive width within the container.");
616
+ const widths = supplied ?? Array.from({ length: columns }, (_, i) => Math.floor(width / columns) + (i < width % columns ? 1 : 0));
617
+ if (table.repeatHeader !== void 0 && table.headerRows !== void 0) throw new InvalidValueError("Choose repeatHeader or headerRows.");
618
+ const headers = table.headerRows ?? (table.repeatHeader ? 1 : 0);
619
+ if (headers > table.rows.length || table.rowOptions && table.rowOptions.length !== table.rows.length)
620
+ throw new InvalidValueError("Row options and header count must fit the table rows.");
621
+ let endedHeaders = false;
622
+ const rows = table.rows.map((_, index) => {
623
+ const options = { ...table.allowRowSplit === void 0 ? {} : { allowRowSplit: table.allowRowSplit }, ...table.rowHeight ? { height: table.rowHeight } : {}, ...table.heightRule ? { heightRule: table.heightRule } : {}, repeatHeader: index < headers, ...table.rowOptions?.[index] };
624
+ if (options.repeatHeader && endedHeaders) throw new InvalidValueError("Repeated headers must be consecutive leading rows.");
625
+ if (!options.repeatHeader) endedHeaders = true;
626
+ if (!options.height && options.heightRule && options.heightRule.name !== "AUTO") throw new InvalidValueError("A fixed or minimum row height requires a height.");
627
+ const height = options.height ? twips(options.height, false) : 0;
628
+ const rule = { AUTO: "auto", AT_LEAST: "atLeast", EXACTLY: "exact" }[options.heightRule?.name ?? "AT_LEAST"];
629
+ return `<w:trPr>${options.allowRowSplit === void 0 ? "" : `<w:cantSplit w:val="${Number(!options.allowRowSplit)}"/>`}${options.height || options.heightRule ? `<w:trHeight w:val="${height}" w:hRule="${rule}"/>` : ""}${options.repeatHeader ? '<w:tblHeader w:val="1"/>' : ""}</w:trPr>`;
630
+ });
631
+ const margins = table.cellMargin ? { top: table.cellMargin, left: table.cellMargin, bottom: table.cellMargin, right: table.cellMargin } : void 0;
632
+ const properties = `<w:tblW w:w="${width}" w:type="dxa"/>` + tableBorders(table.borders, "tblBorders", w) + tableShading(table.shading) + `<w:tblLayout w:type="${table.autofit === false ? "fixed" : "autofit"}"/>` + tableMargins(margins, "tblCellMar", w);
633
+ return { widths, rows, properties, margin: table.cellMargin ? twips(table.cellMargin, false) : 0 };
634
+ }
635
+
636
+ // packages/safe-bash-docx-engine/src/style-properties.ts
637
+ function styleChild(node, name, children = (node2) => node2.children) {
638
+ return node && children(node).find((c) => c.namespace === node.namespace && c.localName === name);
639
+ }
640
+ function styleAttribute(node, name) {
641
+ return node?.attributes.find((a) => a.namespace === node.namespace && a.localName === name)?.value;
642
+ }
643
+ function styleIds(root, budget) {
644
+ const ids = /* @__PURE__ */ new Set(), stack = [root];
645
+ while (stack.length) {
646
+ const node = stack.pop();
647
+ budget.charge("work", 1 + node.children.length);
648
+ if (node.namespace === root.namespace && node.localName === "style") {
649
+ const id = styleAttribute(node, "styleId");
650
+ if (id !== void 0) ids.add(id);
651
+ }
652
+ for (const child of node.children) stack.push(child);
653
+ }
654
+ return ids;
655
+ }
656
+ function styleToggle(node) {
657
+ if (!node) return null;
658
+ return storedBoolean(styleAttribute(node, "val") ?? "1", "Invalid style boolean value.");
659
+ }
660
+ var styleToggleFlags = ["bold", "italic", "csBold", "csItalic", "allCaps", "smallCaps", "strike", "doubleStrike", "outline", "shadow", "emboss", "imprint", "fontHidden"];
661
+ function styleInteger(raw) {
662
+ if (raw === void 0) return null;
663
+ const text = trimXmlWhitespace(raw), digits = text[0] === "+" || text[0] === "-" ? text.slice(1) : text;
664
+ if (!digits.length || [...digits].some((char) => char < "0" || char > "9") || !Number.isSafeInteger(Number(text))) throw new InvalidDocumentError("Invalid integer style property.");
665
+ return Number(text);
666
+ }
667
+ function readStyleProperties(run, paragraph, children = (node) => node.children) {
668
+ const child = (node, name) => styleChild(node, name, children);
669
+ const numeric = (node, attribute = "val", divisor = 1) => {
670
+ const raw = styleAttribute(node, attribute);
671
+ if (raw === void 0) return null;
672
+ if (divisor !== 1) {
673
+ const unsigned = node?.localName === "spacing" && ["before", "after"].includes(attribute) || node?.localName === "ind" && ["firstLine", "hanging"].includes(attribute);
674
+ return storedMeasure(raw, divisor === 2 ? "half-point" : unsigned ? "unsigned-twip" : "twip").emu / (divisor === 2 ? 12700 : divisor * 635);
675
+ }
676
+ return styleInteger(raw) / divisor;
677
+ };
678
+ const num = child(paragraph, "numPr"), spacing = child(paragraph, "spacing"), ind = child(paragraph, "ind");
679
+ const tabs = child(paragraph, "tabs");
680
+ const lineRule = styleAttribute(spacing, "lineRule") ?? null;
681
+ const hanging = numeric(ind, "hanging", 20);
682
+ return {
683
+ ...Object.fromEntries(Object.entries(styleFontFlags).map(([key, tag]) => [key, styleToggle(child(run, tag))])),
684
+ font: styleAttribute(child(run, "rFonts"), "ascii") ?? null,
685
+ size: numeric(child(run, "sz"), "val", 2),
686
+ color: styleAttribute(child(run, "color"), "val") ?? null,
687
+ themeColor: styleAttribute(child(run, "color"), "themeColor") ?? null,
688
+ underline: styleAttribute(child(run, "u"), "val") ?? null,
689
+ highlight: styleAttribute(child(run, "highlight"), "val") ?? null,
690
+ baseline: styleAttribute(child(run, "vertAlign"), "val") ?? null,
691
+ language: styleAttribute(child(run, "lang"), "val") ?? null,
692
+ outlineLevel: numeric(child(paragraph, "outlineLvl")),
693
+ keepWithNext: styleToggle(child(paragraph, "keepNext")),
694
+ keepTogether: styleToggle(child(paragraph, "keepLines")),
695
+ widowControl: styleToggle(child(paragraph, "widowControl")),
696
+ pageBreakBefore: styleToggle(child(paragraph, "pageBreakBefore")),
697
+ leftIndent: numeric(ind, "start", 20) ?? numeric(ind, "left", 20),
698
+ rightIndent: numeric(ind, "end", 20) ?? numeric(ind, "right", 20),
699
+ firstLineIndent: hanging === null ? numeric(ind, "firstLine", 20) : -hanging,
700
+ lineSpacing: numeric(spacing, "line", lineRule === "auto" || lineRule === null ? 240 : 20),
701
+ lineSpacingRule: lineRule,
702
+ alignment: styleAttribute(child(paragraph, "jc"), "val") ?? null,
703
+ spaceBefore: numeric(spacing, "before", 20),
704
+ spaceAfter: numeric(spacing, "after", 20),
705
+ tabStops: tabs ? children(tabs).filter((n) => n.namespace === tabs.namespace && n.localName === "tab").map((n) => ({ position: numeric(n, "pos", 20) ?? 0, alignment: styleAttribute(n, "val") ?? "left", leader: styleAttribute(n, "leader") ?? "none" })) : null,
706
+ numbering: num ? { id: styleAttribute(child(num, "numId"), "val") ?? null, level: numeric(child(num, "ilvl")) } : null
707
+ };
708
+ }
709
+ function inheritStyleProperties(inherited, direct) {
710
+ const value = Object.fromEntries(Object.entries(direct).map(([key, item]) => [key, item === null ? inherited[key] : item]));
711
+ const toggles2 = Object.fromEntries(styleToggleFlags.map((key) => [key, direct[key] === null || direct[key] === false ? inherited[key] : !inherited[key]]));
712
+ const tabs = new Map(inherited.tabStops?.map((tab) => [tab.position, tab]));
713
+ for (const tab of direct.tabStops ?? []) {
714
+ if (tab.alignment === "clear") tabs.delete(tab.position);
715
+ else tabs.set(tab.position, tab);
716
+ }
717
+ return {
718
+ ...value,
719
+ ...toggles2,
720
+ tabStops: direct.tabStops === null ? inherited.tabStops : [...tabs.values()].sort((a, b) => a.position - b.position),
721
+ numbering: direct.numbering === null ? inherited.numbering : { id: direct.numbering.id ?? inherited.numbering?.id ?? null, level: direct.numbering.level ?? inherited.numbering?.level ?? null }
722
+ };
723
+ }
724
+ function mergeStyleChildren(xml2, parent, updates, order3, attributes = {}, children = (node) => node.children) {
725
+ const replacements = /* @__PURE__ */ new Map();
726
+ const prefixes = /* @__PURE__ */ new Map();
727
+ let tail = "";
728
+ for (const [name, markup] of [...updates].sort(([a], [b]) => order3.indexOf(a) - order3.indexOf(b))) {
729
+ const matches = children(parent).filter((c) => c.namespace === parent.namespace && c.localName === name);
730
+ if (matches.length > 1) throw new UnsupportedEditError("Duplicate style properties cannot be edited.");
731
+ if (matches[0]) {
732
+ replacements.set(matches[0], markup);
733
+ continue;
734
+ }
735
+ if (!markup) continue;
736
+ const next = children(parent).find((c) => c.namespace === parent.namespace && order3.indexOf(c.localName) > order3.indexOf(name));
737
+ if (next) prefixes.set(next, (prefixes.get(next) ?? "") + markup);
738
+ else tail += markup;
739
+ }
740
+ for (const [node, prefix2] of prefixes) replacements.set(node, prefix2 + (replacements.get(node) ?? xml2.sourceXml(node)));
741
+ const content = xml2.sourceXml(parent, replacements, true) + tail;
742
+ if (!Object.keys(attributes).length && !tail && !prefixes.size) return xml2.sourceXml(parent, replacements);
743
+ const retained = parent.attributes.filter((a) => a.namespace !== parent.namespace || !Object.hasOwn(attributes, a.localName));
744
+ const namespaces = new Map(parent.namespaces);
745
+ let prefix = [...namespaces].find(([name, namespace]) => name && namespace === parent.namespace)?.[0] ?? "st";
746
+ for (let n = 1; namespaces.has(prefix) && namespaces.get(prefix) !== parent.namespace; n++) prefix = `st${n}`;
747
+ namespaces.set(prefix, parent.namespace);
748
+ const open = runElementOpen({ ...parent, attributes: retained, namespaces });
749
+ const added = Object.entries(attributes).filter(([, v]) => v !== null).map(([key, value]) => ` ${prefix}:${key}="${xmlValue(value)}"`).join("");
750
+ return open.slice(0, -1) + added + ">" + content + `</${parent.name}>`;
751
+ }
752
+
753
+ // packages/safe-bash-docx-engine/src/style-names.ts
754
+ var displayNames = ["Caption", "Header", "Footer", "Heading 1", "Heading 2", "Heading 3", "Heading 4", "Heading 5", "Heading 6", "Heading 7", "Heading 8", "Heading 9"];
755
+ function styleDisplayName(name, builtin = true) {
756
+ return builtin ? displayNames.find((value) => value.toLowerCase() === name) ?? name : name;
757
+ }
758
+ function styleStoredName(name, builtin = true) {
759
+ if (builtin && /^Heading[1-9]$/.test(name)) return `heading ${name.slice(7)}`;
760
+ return builtin && displayNames.includes(name) ? name.toLowerCase() : name;
761
+ }
762
+ function selectNamedStyles(nodes, name, children, budget) {
763
+ const entries = nodes.map((node) => {
764
+ const fields = children(node), definition = fields.find((child) => child.namespace === node.namespace && child.localName === "name");
765
+ budget.charge("work", 1 + node.attributes.length + fields.length + (definition?.attributes.length ?? 0));
766
+ const stored = definition?.attributes.find((attribute) => attribute.namespace === node.namespace && attribute.localName === "val")?.value;
767
+ const builtin = !storedBoolean(node.attributes.find((attribute) => attribute.namespace === node.namespace && attribute.localName === "customStyle")?.value ?? "0");
768
+ return { node, stored, builtin, displayed: stored === void 0 ? void 0 : styleDisplayName(stored, builtin) };
769
+ });
770
+ const exact = entries.filter((entry) => entry.displayed === name);
771
+ return (exact.length ? exact : entries.filter((entry) => entry.builtin && entry.stored !== void 0 && styleStoredName(entry.stored) === styleStoredName(name))).map((entry) => entry.node);
772
+ }
773
+
774
+ // packages/safe-bash-docx-engine/src/create-content.ts
775
+ function xmlValue(value) {
776
+ let result = "";
777
+ for (const char of value) {
778
+ const n = char.codePointAt(0);
779
+ if (!(n === 9 || n === 10 || n === 13 || n >= 32 && n <= 55295 || n >= 57344 && n <= 65533 || n >= 65536 && n <= 1114111))
780
+ throw new InvalidValueError("Invalid XML character in structured content.");
781
+ result += { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "\r": "&#13;", "\n": "&#10;", " ": "&#9;" }[char] ?? char;
782
+ }
783
+ return result;
784
+ }
785
+ function lengthEmu(value, positive = true) {
786
+ if (value.value < 0 || positive && value.value === 0) throw new InvalidValueError("Document length must be nonnegative or positive for this setting.");
787
+ const scale = { emu: 1, in: 914400, cm: 36e4, mm: 36e3, pt: 12700, twip: 635 }[value.unit];
788
+ const emu = Math.round(value.value * scale);
789
+ if (!Number.isSafeInteger(emu)) throw new InvalidValueError("Document length is outside the safe integer range.");
790
+ return emu;
791
+ }
792
+ function twips(value, positive = true) {
793
+ const result = Math.round(lengthEmu(value, positive) / 635);
794
+ if (result < (positive ? 1 : 0) || result > 31680)
795
+ throw new InvalidValueError("Document length is outside the supported page range.");
796
+ return result;
797
+ }
798
+ function pageGeometry(page, existing, w, children = (node) => node.children) {
799
+ const attribute = (element, name) => {
800
+ const node = existing && children(existing).find((child) => child.namespace === w && child.localName === element);
801
+ const raw = node?.attributes.find((a) => a.namespace === w && a.localName === name)?.value;
802
+ return raw === void 0 ? void 0 : Number(raw);
803
+ };
804
+ const width = page?.width ? twips(page.width) : attribute("pgSz", "w") ?? 12240;
805
+ const height = page?.height ? twips(page.height) : attribute("pgSz", "h") ?? 15840;
806
+ const margins = Object.fromEntries(Object.entries({ top: 1440, right: 1440, bottom: 1440, left: 1440, header: 720, footer: 720, gutter: 0 }).map(([key, fallback]) => {
807
+ const value = page?.margins?.[key];
808
+ return [key, value ? twips(value, false) : attribute("pgMar", key) ?? fallback];
809
+ }));
810
+ if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || Object.values(margins).some((v) => !Number.isSafeInteger(v) || v < 0) || width <= margins.left + margins.right + margins.gutter || height <= margins.top + margins.bottom)
811
+ throw new InvalidValueError("Page margins must leave positive content extent.");
812
+ const xml2 = `<w:pgSz w:w="${width}" w:h="${height}"${page?.orientation ? ` w:orient="${page.orientation}"` : ""}/><w:pgMar ${Object.entries(margins).map(([key, value]) => `w:${key}="${value}"`).join(" ")}/><w:cols w:num="1"/>`;
813
+ return { width: width - margins.left - margins.right - margins.gutter, xml: xml2 };
814
+ }
815
+ function renderContent(content, w, budget, stylesRoot, containerWidth = 9360, reservedStyleIds = /* @__PURE__ */ new Set()) {
816
+ const styles = /* @__PURE__ */ new Map();
817
+ const ids = stylesRoot ? styleIds(stylesRoot, budget) : /* @__PURE__ */ new Set();
818
+ for (const id of reservedStyleIds) {
819
+ budget.charge("work", 1);
820
+ ids.add(id);
821
+ }
822
+ const children = stylesRoot ? activeXmlChildren(stylesRoot, budget) : (node) => node.children;
823
+ for (const style of stylesRoot ? children(stylesRoot) : []) {
824
+ if (style.namespace !== w || style.localName !== "style") continue;
825
+ const attribute = (node, key) => node.attributes.find((a) => a.namespace === w && a.localName === key)?.value;
826
+ const id = attribute(style, "styleId"), type = attribute(style, "type") ?? "paragraph";
827
+ const name = children(style).find((c) => c.namespace === w && c.localName === "name");
828
+ const stored = name && attribute(name, "val");
829
+ const builtin = !storedBoolean(attribute(style, "customStyle") ?? "0");
830
+ const value = stored === void 0 ? void 0 : styleDisplayName(stored, builtin);
831
+ if (value && id && type) {
832
+ if (styles.has(value)) throw new InvalidValueError("Ambiguous style name in template.");
833
+ const properties = children(style).find((child) => child.namespace === w && child.localName === "pPr");
834
+ const outline = properties && children(properties).find((child) => child.namespace === w && child.localName === "outlineLvl");
835
+ styles.set(value, { id, type, outline: outline ? attribute(outline, "val") : void 0, builtin });
836
+ }
837
+ }
838
+ const added = [];
839
+ const builtinOverrides = /* @__PURE__ */ new Map();
840
+ const allocate = () => {
841
+ let n = 1;
842
+ while (ids.has(`Style${n}`)) n++;
843
+ const id = `Style${n}`;
844
+ ids.add(id);
845
+ return id;
846
+ };
847
+ for (const style of content.styles ?? []) {
848
+ const name = style.name;
849
+ const size = style.size === void 0 ? void 0 : Math.round(lengthEmu(style.size) / 6350);
850
+ if (size !== void 0 && (size < 1 || size > 3276)) throw new InvalidValueError("Font size must round to 1 through 3276 half-points.");
851
+ const formatting = (style.font === void 0 ? "" : `<w:rFonts w:ascii="${xmlValue(style.font)}" w:hAnsi="${xmlValue(style.font)}"/>`) + (size === void 0 ? "" : `<w:sz w:val="${size}"/>`) + (style.bold === void 0 ? "" : `<w:b w:val="${Number(style.bold)}"/>`) + (style.italic === void 0 ? "" : `<w:i w:val="${Number(style.italic)}"/>`);
852
+ if (styles.has(name)) {
853
+ const existing = styles.get(name);
854
+ if (!existing.builtin || existing.type !== style.type || builtinOverrides.has(existing.id) || reservedStyleIds.size > 0) {
855
+ throw new InvalidValueError("A declared style name already exists.");
856
+ }
857
+ builtinOverrides.set(existing.id, formatting);
858
+ continue;
859
+ }
860
+ const headingMatch = style.type === "paragraph" && reservedStyleIds.size === 0 ? name === "Title" ? 0 : /^Heading ?([1-9])$/.exec(name) ? Number(/^Heading ?([1-9])$/.exec(name)[1]) : void 0 : void 0;
861
+ if (headingMatch !== void 0) {
862
+ const stem = headingMatch === 0 ? "Title" : `Heading${headingMatch}`;
863
+ if (!ids.has(stem)) {
864
+ ids.add(stem);
865
+ const displayName = headingMatch === 0 ? "Title" : `Heading ${headingMatch}`;
866
+ const entry = { id: stem, type: "paragraph", builtin: true, outline: headingMatch ? String(headingMatch - 1) : void 0 };
867
+ styles.set(name, entry);
868
+ styles.set(displayName, entry);
869
+ styles.set(stem, entry);
870
+ added.push(`<w:style xmlns:w="${w}" w:type="paragraph" w:customStyle="0" w:styleId="${stem}"><w:name w:val="${xmlValue(displayName)}"/><w:qFormat/>${headingMatch ? `<w:pPr><w:outlineLvl w:val="${headingMatch - 1}"/></w:pPr>` : ""}${formatting ? `<w:rPr>${formatting}</w:rPr>` : ""}</w:style>`);
871
+ continue;
872
+ }
873
+ }
874
+ const id = allocate();
875
+ styles.set(name, { id, type: style.type });
876
+ added.push(`<w:style xmlns:w="${w}" w:type="${style.type}" w:customStyle="1" w:styleId="${id}"><w:name w:val="${xmlValue(style.name)}"/>${formatting ? `<w:rPr>${formatting}</w:rPr>` : ""}</w:style>`);
877
+ }
878
+ const resolve = (name, type) => {
879
+ const exact = styles.get(name), alias = styles.get(styleDisplayName(name));
880
+ const style = exact ?? (alias?.builtin ? alias : void 0);
881
+ if (!style && type === "paragraph" && reservedStyleIds.size === 0) {
882
+ const m = name === "Title" ? 0 : /^Heading ?([1-9])$/.exec(name) ? Number(/^Heading ?([1-9])$/.exec(name)[1]) : void 0;
883
+ if (m !== void 0) return heading(m);
884
+ }
885
+ if (!style || style.type !== type) throw new InvalidValueError("Expected an existing style of the selected kind.");
886
+ return style.id;
887
+ };
888
+ const headings = /* @__PURE__ */ new Map();
889
+ const heading = (level) => {
890
+ if (headings.has(level)) return headings.get(level);
891
+ const name = level === 0 ? "Title" : `Heading ${level}`;
892
+ const stem = level === 0 ? "Title" : `Heading${level}`;
893
+ const found = [...styles.entries()].find(([label2, style]) => {
894
+ const suffix = style.id.slice(stem.length);
895
+ const identity = style.id === stem || style.id.startsWith(stem) && suffix.length > 0 && [...suffix].every((c) => c >= "0" && c <= "9");
896
+ return identity && style.builtin && style.type === "paragraph" && (label2 === name || label2.startsWith(name + " ")) && (level === 0 || styleInteger(style.outline) === level - 1);
897
+ })?.[1];
898
+ if (found) {
899
+ headings.set(level, found.id);
900
+ return found.id;
901
+ }
902
+ let id = stem;
903
+ for (let n = 1; ids.has(id); n++) id = `${stem}${n}`;
904
+ ids.add(id);
905
+ let label = name;
906
+ for (let n = 1; styles.has(label); n++) label = `${name} ${n}`;
907
+ styles.set(label, { id, type: "paragraph", builtin: true, outline: level ? String(level - 1) : void 0 });
908
+ added.push(`<w:style xmlns:w="${w}" w:type="paragraph" w:customStyle="0" w:styleId="${id}"><w:name w:val="${label}"/><w:qFormat/>${level ? `<w:pPr><w:outlineLvl w:val="${level - 1}"/></w:pPr>` : ""}</w:style>`);
909
+ headings.set(level, id);
910
+ return id;
911
+ };
912
+ const run = (input) => {
913
+ let formatting = input.style === void 0 ? "" : `<w:rStyle w:val="${xmlValue(resolve(input.style, "character"))}"/>`;
914
+ for (const [key, tag] of [["bold", "b"], ["italic", "i"]]) if (input[key] != null) formatting += `<w:${tag} w:val="${Number(input[key])}"/>`;
915
+ if (input.underline != null) {
916
+ const values = { NONE: "none", SINGLE: "single", WORDS: "words", DOUBLE: "double", DOTTED: "dotted", THICK: "thick", DASH: "dash", DOT_DASH: "dotDash", DOT_DOT_DASH: "dotDotDash", WAVY: "wave", DOTTED_HEAVY: "dottedHeavy", DASH_HEAVY: "dashedHeavy", DOT_DASH_HEAVY: "dashDotHeavy", DOT_DOT_DASH_HEAVY: "dashDotDotHeavy", WAVY_HEAVY: "wavyHeavy", DASH_LONG: "dashLong", WAVY_DOUBLE: "wavyDouble", DASH_LONG_HEAVY: "dashLongHeavy" };
917
+ const value = typeof input.underline === "boolean" ? input.underline ? "single" : "none" : values[input.underline.name];
918
+ formatting += `<w:u w:val="${value}"/>`;
919
+ }
920
+ let text = "", pending = "";
921
+ const flush = () => {
922
+ if (pending) {
923
+ text += `<w:t xml:space="preserve">${xmlValue(pending)}</w:t>`;
924
+ pending = "";
925
+ }
926
+ };
927
+ for (const char of input.text) {
928
+ if (char === " " || char === "\n" || char === "\r") {
929
+ flush();
930
+ text += char === " " ? "<w:tab/>" : "<w:br/>";
931
+ } else pending += char;
932
+ }
933
+ flush();
934
+ return `<w:r>${formatting ? `<w:rPr>${formatting}</w:rPr>` : ""}${text}</w:r>`;
935
+ };
936
+ const blocks = (items, width, depth) => {
937
+ budget.check("xmlDepth", depth);
938
+ return items.map((block) => {
939
+ budget.charge("work", 1);
940
+ if (block.kind === "paragraph") {
941
+ const style2 = block.level !== void 0 ? heading(block.level) : block.style === void 0 ? void 0 : resolve(block.style, "paragraph");
942
+ const props = style2 ? `<w:pPr><w:pStyle w:val="${xmlValue(style2)}"/></w:pPr>` : "";
943
+ return `<w:p xmlns:w="${w}">${props}${block.runs ? block.runs.map(run).join("") : block.text === void 0 ? "" : run({ text: block.text })}</w:p>`;
944
+ }
945
+ const rows = block.rows.length, columns = block.rows[0].length;
946
+ budget.check("tableRows", rows);
947
+ budget.check("tableColumns", columns);
948
+ budget.charge("tableCells", rows * columns);
949
+ const geometry = tableGeometry(block, width, w);
950
+ const { widths } = geometry;
951
+ const style = block.style !== void 0 ? `<w:tblStyle w:val="${xmlValue(resolve(block.style, "table"))}"/>` : "";
952
+ return `<w:tbl xmlns:w="${w}"><w:tblPr>${style}${geometry.properties}</w:tblPr><w:tblGrid>${widths.map((value) => `<w:gridCol w:w="${value}"/>`).join("")}</w:tblGrid>${block.rows.map((row, rowIndex) => `<w:tr>${geometry.rows[rowIndex]}${row.map((cell, i) => {
953
+ const innerWidth = widths[i] - (cell.margins?.left ? twips(cell.margins.left, false) : geometry.margin) - (cell.margins?.right ? twips(cell.margins.right, false) : geometry.margin);
954
+ if (innerWidth <= 0) throw new InvalidValueError("Cell margins must leave positive content width.");
955
+ const properties = `<w:tcW w:w="${widths[i]}" w:type="dxa"/>` + tableBorders(cell.borders, "tcBorders", w) + tableShading(cell.shading) + tableMargins(cell.margins, "tcMar", w);
956
+ return `<w:tc><w:tcPr>${properties}</w:tcPr>${blocks(cell.blocks, innerWidth, depth + 3)}${cell.blocks.at(-1)?.kind !== "paragraph" ? "<w:p/>" : ""}</w:tc>`;
957
+ }).join("")}</w:tr>`).join("")}</w:tbl>`;
958
+ }).join("");
959
+ };
960
+ const body = blocks(content.blocks, containerWidth, 3);
961
+ budget.charge("retainedBytes", (body.length + added.join("").length) * 8);
962
+ return { body, styles: added.join(""), builtinOverrides };
963
+ }
964
+ function renderTheme(theme, a) {
965
+ const colors = { dark1: "000000", light1: "FFFFFF", dark2: "202020", light2: "F0F0F0", accent1: "305070", accent2: "507050", accent3: "705030", accent4: "604070", accent5: "307070", accent6: "706030", hyperlink: "0000FF", followedHyperlink: "800080", ...theme.colors };
966
+ const tags = { dark1: "dk1", light1: "lt1", dark2: "dk2", light2: "lt2", accent1: "accent1", accent2: "accent2", accent3: "accent3", accent4: "accent4", accent5: "accent5", accent6: "accent6", hyperlink: "hlink", followedHyperlink: "folHlink" };
967
+ const fill = '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>';
968
+ return `<a:theme xmlns:a="${a}" name="${xmlValue(theme.name)}"><a:themeElements><a:clrScheme name="${xmlValue(theme.name)}">${Object.entries(colors).map(([key, value]) => `<a:${tags[key]}><a:srgbClr val="${value.toUpperCase()}"/></a:${tags[key]}>`).join("")}</a:clrScheme><a:fontScheme name="${xmlValue(theme.name)}">${[["majorFont", theme.majorFont], ["minorFont", theme.minorFont]].map(([tag, font]) => `<a:${tag}><a:latin typeface="${xmlValue(font)}"/><a:ea typeface=""/><a:cs typeface=""/></a:${tag}>`).join("")}</a:fontScheme><a:fmtScheme name="${xmlValue(theme.name)}"><a:fillStyleLst>${fill.repeat(3)}</a:fillStyleLst><a:lnStyleLst>${`<a:ln w="6350">${fill}<a:prstDash val="solid"/></a:ln>`.repeat(3)}</a:lnStyleLst><a:effectStyleLst>${"<a:effectStyle><a:effectLst/></a:effectStyle>".repeat(3)}</a:effectStyleLst><a:bgFillStyleLst>${fill.repeat(3)}</a:bgFillStyleLst></a:fmtScheme></a:themeElements></a:theme>`;
969
+ }
970
+
971
+ // packages/safe-bash-docx-engine/src/native-property-copy.ts
972
+ function copiedNativeProperties(markup, property, root, profile, budget, moveSection = false) {
973
+ if (!markup) return "";
974
+ const chain = [];
975
+ budget.charge("retainedBytes", 48);
976
+ const ancestry = [{ node: root, index: -1 }];
977
+ let found = false;
978
+ while (ancestry.length) {
979
+ const frame = ancestry.at(-1);
980
+ if (frame.index === -1) {
981
+ budget.charge("work", 1);
982
+ chain.push(frame.node);
983
+ if (frame.node === property) {
984
+ found = true;
985
+ break;
986
+ }
987
+ frame.index = 0;
988
+ }
989
+ const child = frame.node.children[frame.index++];
990
+ if (!child) {
991
+ ancestry.pop();
992
+ chain.pop();
993
+ continue;
994
+ }
995
+ budget.charge("retainedBytes", 48);
996
+ ancestry.push({ node: child, index: -1 });
997
+ }
998
+ if (!found) throw new TypeError("Native properties have no original owner.");
999
+ let source = markup;
1000
+ const childIndexes = [];
1001
+ for (let i = chain.length - 2; i >= 0; i--) {
1002
+ const node = chain[i], next = chain[i + 1];
1003
+ const siblings = node.namespace === "http://schemas.openxmlformats.org/markup-compatibility/2006" && node.localName === "AlternateContent" ? node.children.filter((child) => child.namespace === node.namespace && ["Choice", "Fallback"].includes(child.localName)) : [next];
1004
+ childIndexes.unshift(siblings.indexOf(next));
1005
+ source = runElementOpen(node) + siblings.map((child) => child === next ? source : runElementOpen(child) + `</${child.name}>`).join("") + `</${node.name}>`;
1006
+ }
1007
+ const editor = new DocumentXmlEditor(new TextEncoder().encode(source), {}, profile, budget), parsed = editor.root;
1008
+ const view = new MarkupCompatibility(parsed, profile, budget), active = /* @__PURE__ */ new Set(), containers = new Set(view[compatibilityContainers]);
1009
+ const collect = (content) => {
1010
+ for (const item of content) if ("source" in item && item.disposition === "understood") {
1011
+ active.add(item.source);
1012
+ collect(item.content);
1013
+ }
1014
+ };
1015
+ collect(view.content);
1016
+ let parent = parsed;
1017
+ for (const index of childIndexes) parent = parent.children[index];
1018
+ const chunks = [];
1019
+ const pending = [];
1020
+ const enter = (node) => {
1021
+ budget.charge("work", 1 + node.content.length);
1022
+ if (moveSection && node.namespace === property.namespace && node.localName === "sectPr") {
1023
+ chunks.push(editor.sourceXml(node));
1024
+ return;
1025
+ }
1026
+ const branch = node.namespace === "http://schemas.openxmlformats.org/markup-compatibility/2006" && ["Choice", "Fallback"].includes(node.localName);
1027
+ if (!active.has(node) && !containers.has(node)) {
1028
+ if (!branch) return;
1029
+ const attributes2 = node.attributes.filter((attribute) => ["http://www.w3.org/2000/xmlns/", "http://www.w3.org/XML/1998/namespace", "http://schemas.openxmlformats.org/markup-compatibility/2006"].includes(attribute.namespace) || attribute.namespace === "" && node.localName === "Choice" && attribute.localName === "Requires");
1030
+ chunks.push(runElementOpen({ ...node, attributes: attributes2 }) + `</${node.name}>`);
1031
+ return;
1032
+ }
1033
+ const attributes = node.attributes.filter((attribute) => ["http://www.w3.org/2000/xmlns/", "http://www.w3.org/XML/1998/namespace", "http://schemas.openxmlformats.org/markup-compatibility/2006"].includes(attribute.namespace) || view.canEdit(attribute) || branch && attribute.namespace === "" && node.localName === "Choice" && attribute.localName === "Requires");
1034
+ const retainedTokens = attributes.length === node.attributes.length && node.content.every((item) => ["element", "text", "cdata"].includes(item.kind));
1035
+ const [opening, closing] = retainedTokens ? editor[nativeElementSourceTokens](node) : [runElementOpen({ ...node, attributes }), `</${node.name}>`];
1036
+ budget.charge("retainedBytes", 64 + (retainedTokens ? 0 : (opening.length + closing.length) * 2));
1037
+ chunks.push(opening);
1038
+ pending.push({ node, index: 0, closing });
1039
+ };
1040
+ enter(parent);
1041
+ while (pending.length) {
1042
+ const frame = pending.at(-1), item = frame.node.content[frame.index++];
1043
+ budget.charge("work", 1);
1044
+ if (!item) {
1045
+ chunks.push(frame.closing);
1046
+ pending.pop();
1047
+ continue;
1048
+ }
1049
+ if (item.kind === "element") enter(item);
1050
+ else if (item.kind === "text" || item.kind === "cdata") {
1051
+ budget.charge("work", item.text.length);
1052
+ budget.charge("retainedBytes", item.text.length * 12 + 8);
1053
+ chunks.push(xmlValue(item.text));
1054
+ }
1055
+ }
1056
+ const result = chunks.join("");
1057
+ budget.charge("retainedBytes", result.length * 2);
1058
+ return result;
1059
+ }
1060
+
1061
+ // packages/safe-bash-docx-engine/src/revision-markup.ts
1062
+ function revisionInfo(node) {
1063
+ const name = node.localName;
1064
+ if (name === "clrChange" && (node.namespace === documentDialects.transitional.a || node.namespace === documentDialects.strict.a)) return void 0;
1065
+ const attr = (name2) => node.attributes.find((a) => a.localName === name2 && (a.namespace === node.namespace || a.namespace === documentDialects.transitional.w || a.namespace === documentDialects.strict.w))?.value ?? null;
1066
+ const word = node.namespace === documentDialects.transitional.w || node.namespace === documentDialects.strict.w;
1067
+ const type = !word ? "unsupported" : name === "ins" ? "insert" : name === "del" ? "delete" : ["moveFrom", "moveTo", "moveFromRangeStart", "moveFromRangeEnd", "moveToRangeStart", "moveToRangeEnd"].includes(name) ? "move" : ["rPrChange", "pPrChange"].includes(name) ? "format" : name === "sectPrChange" ? "section" : ["tblPrChange", "tblGridChange", "trPrChange", "tcPrChange", "cellIns", "cellDel", "cellMerge"].includes(name) ? "table" : "unsupported";
1068
+ if (type === "unsupported" && !name.endsWith("Change") && !name.startsWith("conflict") && !(name.startsWith("customXml") && (name.endsWith("RangeStart") || name.endsWith("RangeEnd"))) && !(attr("author") !== null && attr("id") !== null && name !== "comment")) return void 0;
1069
+ const snapshot = type === "format" ? node.children.filter((n) => n.namespace === node.namespace && n.localName === name.slice(0, -6)) : [];
1070
+ const seen = /* @__PURE__ */ new Set();
1071
+ const supported = type === "insert" || type === "delete" || type === "move" || type === "format" && snapshot.length === 1 && node.children.length === 1 && [node, snapshot[0], ...snapshot[0].children].every((element) => {
1072
+ for (const char of element.text) if (char !== " " && char !== " " && char !== "\r" && char !== "\n") return false;
1073
+ return true;
1074
+ }) && snapshot[0].attributes.every((attribute) => attribute.namespace === "http://www.w3.org/2000/xmlns/" || attribute.namespace === "http://www.w3.org/XML/1998/namespace" && (attribute.localName === "lang" || attribute.localName === "space" && ["default", "preserve"].includes(attribute.value))) && snapshot[0].children.every((property) => {
1075
+ const field = property.localName;
1076
+ if (property.namespace !== node.namespace || property.children.length || seen.has(field) || !(name === "rPrChange" ? ["b", "i", "rtl", "vanish", "rStyle", "lang", "rFonts"] : ["pStyle", "bidi"]).includes(field)) return false;
1077
+ seen.add(field);
1078
+ const allowed = field === "lang" ? ["val", "eastAsia", "bidi"] : field === "rFonts" ? ["ascii", "hAnsi", "eastAsia", "cs", "asciiTheme", "hAnsiTheme", "eastAsiaTheme", "cstheme", "hint"] : ["val"];
1079
+ if (property.attributes.some((attribute) => attribute.namespace !== "http://www.w3.org/2000/xmlns/" && (attribute.namespace !== node.namespace || !allowed.includes(attribute.localName)))) return false;
1080
+ const val = property.attributes.find((attribute) => attribute.namespace === node.namespace && attribute.localName === "val")?.value;
1081
+ if (["b", "i", "rtl", "vanish", "bidi"].includes(field)) return val === void 0 || storedBooleanValue(val) !== null;
1082
+ return !["rStyle", "pStyle"].includes(field) || val !== void 0;
1083
+ });
1084
+ return { id: attr("id"), author: attr("author"), timestamp: attr("date"), markup: name, namespace: node.namespace, name: attr("name"), type, support: supported ? "supported" : "opaque" };
1085
+ }
1086
+ function containsRevision(node, budget) {
1087
+ budget?.charge("retainedBytes", 8);
1088
+ const pending = [node];
1089
+ while (pending.length) {
1090
+ const current = pending.pop();
1091
+ budget?.charge("work", 1);
1092
+ if (revisionInfo(current) !== void 0) return true;
1093
+ budget?.charge("retainedBytes", current.children.length * 8);
1094
+ for (let index = current.children.length - 1; index >= 0; index--) pending.push(current.children[index]);
1095
+ }
1096
+ return false;
1097
+ }
1098
+ function assertOutsideRevisionRanges(root, target, budget, branches, children = activeXmlChildren(root, budget)) {
1099
+ const selected = new Map(branches.map((branch) => [branch.alternateContent, branch.selected]));
1100
+ const active = /* @__PURE__ */ new Set();
1101
+ const pending = [root];
1102
+ while (pending.length) {
1103
+ const node = pending.pop();
1104
+ budget.charge("work", 1);
1105
+ if (node === target) {
1106
+ if (active.size) throw new UnsupportedEditError("Text removal cannot cross a review range.");
1107
+ return;
1108
+ }
1109
+ const info = revisionInfo(node);
1110
+ if (info && (info.markup.endsWith("RangeStart") || info.markup.endsWith("RangeEnd"))) {
1111
+ const key = info.namespace + ":" + info.markup.slice(0, info.markup.lastIndexOf("Range")) + ":" + (storedIntegerIdentity(info.id ?? void 0) ?? info.id);
1112
+ if (info.markup.endsWith("RangeStart")) active.add(key);
1113
+ else active.delete(key);
1114
+ }
1115
+ if (selected.has(node)) {
1116
+ const branch = selected.get(node);
1117
+ if (branch) pending.push(branch);
1118
+ } else {
1119
+ const activeChildren = children(node);
1120
+ for (let index = activeChildren.length - 1; index >= 0; index--) pending.push(activeChildren[index]);
1121
+ }
1122
+ }
1123
+ }
1124
+ function containsActiveTableHistory(node, children, budget) {
1125
+ if (node.namespace !== documentDialects.transitional.w && node.namespace !== documentDialects.strict.w || !["tbl", "tr", "tc"].includes(node.localName)) return false;
1126
+ const pending = children(node).filter((property) => property.namespace === node.namespace && (property.localName === node.localName + "Pr" || node.localName === "tbl" && property.localName === "tblGrid"));
1127
+ budget.charge("retainedBytes", pending.length * 8);
1128
+ while (pending.length) {
1129
+ const current = pending.pop();
1130
+ budget.charge("work", 1);
1131
+ if (revisionInfo(current) !== void 0) return true;
1132
+ const active = children(current);
1133
+ budget.charge("retainedBytes", active.length * 8);
1134
+ for (let index = active.length - 1; index >= 0; index--) pending.push(active[index]);
1135
+ }
1136
+ return false;
1137
+ }
1138
+ function assertFormattingHistoryEditable(root, target, children, budget) {
1139
+ assertOutsideRevisionRanges(root, target, budget, [], children);
1140
+ const pending = [{ node: root, blocked: false }];
1141
+ while (pending.length) {
1142
+ const { node, blocked } = pending.pop();
1143
+ budget.charge("work", 1);
1144
+ const active = children(node);
1145
+ const history = containsActiveTableHistory(node, children, budget) || node.namespace === target.namespace && (["p", "r"].includes(node.localName) || node === target) && active.filter((property) => property.namespace === target.namespace && ["pPr", "rPr"].includes(property.localName)).some((property) => children(property).some((change) => {
1146
+ const revision = revisionInfo(change);
1147
+ return revision?.type === "format" && revision.support === "opaque";
1148
+ }));
1149
+ if (node === target) {
1150
+ if (blocked || history) throw new UnsupportedEditError("Formatting cannot reconcile complex property history.");
1151
+ return;
1152
+ }
1153
+ for (let index = active.length - 1; index >= 0; index--) pending.push({ node: active[index], blocked: blocked || history });
1154
+ }
1155
+ throw new UnsupportedEditError("Formatting requires an active owned element.");
1156
+ }
1157
+ function paragraphTextHistory(root, paragraphs, children, budget) {
1158
+ budget.charge("retainedBytes", paragraphs.length * 112);
1159
+ const targets = new Set(paragraphs), activeRanges = /* @__PURE__ */ new Set();
1160
+ if (!targets.size) return { root, paragraphs: targets };
1161
+ const namespace = paragraphs[0].namespace;
1162
+ const pending = [{ node: root, blocked: false }];
1163
+ const startWork = budget.usage.work;
1164
+ let ordinal = 0, formatWork = 0, proofWork = 0, remaining = targets.size;
1165
+ while (pending.length) {
1166
+ const { node, blocked } = pending.pop();
1167
+ budget.charge("work", 1);
1168
+ ordinal++;
1169
+ const target = targets.has(node), outsideWork = ordinal * 2 - 1;
1170
+ if (target) {
1171
+ budget.charge("work", Math.max(0, proofWork + outsideWork - (budget.usage.work - startWork)));
1172
+ if (activeRanges.size) throw new UnsupportedEditError("Text removal cannot cross a review range.");
1173
+ }
1174
+ const active = children(node);
1175
+ formatWork += 2;
1176
+ const history = node.namespace === namespace && ["p", "r"].includes(node.localName) && active.filter((property) => property.namespace === namespace && ["pPr", "rPr"].includes(property.localName)).some((property) => {
1177
+ formatWork++;
1178
+ return children(property).some((change) => {
1179
+ const revision = revisionInfo(change);
1180
+ return revision?.type === "format" && revision.support === "opaque";
1181
+ });
1182
+ });
1183
+ if (target) {
1184
+ if (node.namespace !== namespace || node.localName !== "p") throw new UnsupportedEditError("Cell text requires native paragraph owners.");
1185
+ proofWork += outsideWork * 2 + formatWork;
1186
+ budget.charge("work", proofWork - (budget.usage.work - startWork));
1187
+ if (blocked || history) throw new UnsupportedEditError("Formatting cannot reconcile complex property history.");
1188
+ if (--remaining === 0) return { root, paragraphs: targets };
1189
+ }
1190
+ const info = revisionInfo(node);
1191
+ if (info && (info.markup.endsWith("RangeStart") || info.markup.endsWith("RangeEnd"))) {
1192
+ const key = info.namespace + ":" + info.markup.slice(0, info.markup.lastIndexOf("Range")) + ":" + info.id;
1193
+ if (info.markup.endsWith("RangeStart")) activeRanges.add(key);
1194
+ else activeRanges.delete(key);
1195
+ }
1196
+ for (let index = active.length - 1; index >= 0; index--) pending.push({ node: active[index], blocked: blocked || history });
1197
+ }
1198
+ throw new UnsupportedEditError("Formatting requires an active owned element.");
1199
+ }
1200
+
1201
+ // packages/safe-bash-docx-engine/src/shape-carriers.ts
1202
+ var officeShape = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
1203
+ var officeGroup = "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup";
1204
+ var vml = "urn:schemas-microsoft-com:vml";
1205
+ var wordExtension = "http://schemas.microsoft.com/office/word/2006/wordml";
1206
+ var mc = "http://schemas.openxmlformats.org/markup-compatibility/2006";
1207
+ function collectShapeCarriers(root, dialect, budget, branches) {
1208
+ const vocabulary = documentDialects[dialect];
1209
+ const bodyRoots = /* @__PURE__ */ new Set();
1210
+ const records = [];
1211
+ const attr = (n, name) => n.attributes.find((a) => !a.namespace && a.localName === name)?.value;
1212
+ const pending = [{ node: root, owner: void 0, group: null, canvas: false, active: true, ancestry: void 0 }];
1213
+ while (pending.length) {
1214
+ const frame = pending.pop();
1215
+ const { node, active, ancestry } = frame;
1216
+ let { owner, group, canvas } = frame;
1217
+ budget.charge("work", 1);
1218
+ if (node.namespace === vocabulary.w && ["drawing", "pict"].includes(node.localName)) {
1219
+ owner = node;
1220
+ group = null;
1221
+ canvas = false;
1222
+ }
1223
+ if (node.namespace === vocabulary.wp && node.localName === "wpc" && owner) canvas = true;
1224
+ let representation;
1225
+ let kind = "shape";
1226
+ if (owner && node.namespace === vocabulary.wp && ["wsp", "wgp", "grpSp"].includes(node.localName)) {
1227
+ representation = "native";
1228
+ kind = node.localName === "wsp" ? "shape" : "group";
1229
+ }
1230
+ if (owner && node.namespace === officeShape && node.localName === "wsp") representation = "office";
1231
+ if (owner && node.namespace === officeGroup && ["wgp", "grpSp"].includes(node.localName)) {
1232
+ representation = "office";
1233
+ kind = "group";
1234
+ }
1235
+ if (owner && node.namespace === vml && ["shape", "arc", "curve", "line", "oval", "polyline", "rect", "roundrect", "group"].includes(node.localName)) {
1236
+ representation = "vml";
1237
+ kind = node.localName === "group" ? "group" : "shape";
1238
+ }
1239
+ if (representation) {
1240
+ budget.charge("retainedBytes", 32);
1241
+ const ancestors = [];
1242
+ for (let link = ancestry; link; link = link.parent) {
1243
+ budget.charge("work", 1);
1244
+ budget.charge("retainedBytes", 24);
1245
+ ancestors.push(link.node);
1246
+ }
1247
+ ancestors.reverse();
1248
+ const candidates = [], admitted = /* @__PURE__ */ new Set(), links = [], ids = [];
1249
+ const enclosing = ancestors.slice(ancestors.indexOf(owner) + 1);
1250
+ const foreignEnvelope = enclosing.some((n) => !(n.namespace === vocabulary.wp && ["inline", "anchor", "wpc", "wgp", "grpSp"].includes(n.localName) || n.namespace === vocabulary.a && ["graphic", "graphicData"].includes(n.localName) || n.namespace === officeGroup && ["wgp", "grpSp"].includes(n.localName) || n.namespace === vml && n.localName === "group" || n.namespace === mc && ["AlternateContent", "Choice", "Fallback"].includes(n.localName)));
1251
+ const scan = [{ n: node, parent: void 0, grandparent: void 0 }];
1252
+ while (scan.length) {
1253
+ const { n, parent, grandparent } = scan.pop();
1254
+ budget.charge("work", 1);
1255
+ if (n !== node && (n.namespace === vocabulary.wp && ["wsp", "wgp", "grpSp"].includes(n.localName) || n.namespace === officeShape && n.localName === "wsp" || n.namespace === officeGroup || n.namespace === vml && ["shape", "group"].includes(n.localName))) continue;
1256
+ if (n.localName === "txbxContent" && [vocabulary.wp, vocabulary.w, documentDialects.transitional.w, wordExtension].includes(n.namespace)) {
1257
+ candidates.push(n);
1258
+ if (parent && grandparent === node && (representation === "native" ? parent.namespace === vocabulary.wp && parent.localName === "txbx" && n.namespace === vocabulary.wp : representation === "office" ? parent.namespace === officeShape && parent.localName === "txbx" && n.namespace === documentDialects.transitional.w : parent.namespace === vml && parent.localName === "textbox" && n.namespace === documentDialects.transitional.w)) admitted.add(n);
1259
+ }
1260
+ if (n.localName === "linkedTxbx" && [vocabulary.wp, officeShape].includes(n.namespace)) links.push(attr(n, "id") ?? "");
1261
+ if (n.localName === "txbx" && [vocabulary.wp, officeShape].includes(n.namespace)) ids.push(attr(n, "id") ?? "0");
1262
+ for (let i = n.children.length - 1; i >= 0; i--) {
1263
+ budget.charge("retainedBytes", 32);
1264
+ scan.push({ n: n.children[i], parent: n, grandparent: parent });
1265
+ }
1266
+ }
1267
+ candidates.forEach((n) => bodyRoots.add(n));
1268
+ const reasons = [];
1269
+ if (foreignEnvelope) reasons.push("foreign-envelope");
1270
+ if (candidates.some((n) => !admitted.has(n))) reasons.push("unsupported-body");
1271
+ if (group) reasons.push("group-contained");
1272
+ if (canvas) reasons.push("canvas");
1273
+ if (candidates.length > 1) reasons.push("multiple-bodies");
1274
+ if (candidates.some((n) => n.namespace === wordExtension)) reasons.push("opaque-body");
1275
+ if (dialect === "strict" && representation !== "native") reasons.push("strict-extension");
1276
+ const expected = representation === "native" ? vocabulary.wp : documentDialects.transitional.w;
1277
+ const bodies = candidates.length === 1 && candidates[0].namespace === expected && admitted.has(candidates[0]) && !reasons.includes("strict-extension") && !foreignEnvelope ? [{ node: candidates[0], wordNamespace: representation === "native" ? vocabulary.w : documentDialects.transitional.w }] : [];
1278
+ if (candidates.length && !bodies.length && !reasons.length) reasons.push("unsupported-body");
1279
+ const style = attr(node, "style") ?? "";
1280
+ for (const declaration of style.split(";")) {
1281
+ const colon = declaration.indexOf(":");
1282
+ if (colon >= 0 && declaration.slice(0, colon).trim().toLowerCase() === "mso-next-textbox" && declaration.slice(colon + 1).trim()) links.push("vml-flow");
1283
+ }
1284
+ if (links.length) reasons.push("linked-flow");
1285
+ records.push({ node, kind, representation, group, bodies, refusalReasons: reasons, active, opaque: !!candidates.length && !bodies.length, support: reasons.length || kind === "group" ? "preserve-only" : "supported", owner: [...ancestors].reverse().find((n) => ["body", "hdr", "ftr", "footnote", "endnote", "comment", "txbxContent"].includes(n.localName) && (n.namespace === vocabulary.w || n.namespace === vocabulary.wp)) ?? root, links, ids, ancestors });
1286
+ if (kind === "group") group = node;
1287
+ }
1288
+ if (node.children.length) budget.charge("retainedBytes", 32);
1289
+ const descendantAncestry = node.children.length ? { node, parent: ancestry } : void 0;
1290
+ for (let i = node.children.length - 1; i >= 0; i--) {
1291
+ const child = node.children[i];
1292
+ const selected = node.namespace === mc && node.localName === "AlternateContent" ? branches.get(node) : void 0;
1293
+ budget.charge("work", 1);
1294
+ budget.charge("retainedBytes", 64);
1295
+ pending.push({ node: child, owner, group, canvas, active: active && (!(node.namespace === mc && node.localName === "AlternateContent") || selected === child), ancestry: descendantAncestry });
1296
+ }
1297
+ }
1298
+ for (const record of records) {
1299
+ for (const other of records) {
1300
+ budget.charge("work", 1);
1301
+ if (record.owner === other.owner && other.links.some((id) => record.ids.includes(id))) {
1302
+ if (!record.refusalReasons.includes("linked-flow")) record.refusalReasons.push("linked-flow");
1303
+ }
1304
+ if (other !== record && other.bodies.some((body) => record.ancestors.includes(body.node))) {
1305
+ if (!record.refusalReasons.includes("nested-box")) record.refusalReasons.push("nested-box");
1306
+ if (!other.refusalReasons.includes("containing-box")) other.refusalReasons.push("containing-box");
1307
+ }
1308
+ }
1309
+ record.support = record.refusalReasons.length || record.kind === "group" ? "preserve-only" : "supported";
1310
+ }
1311
+ return { carriers: records.filter((r) => r.active), rawCarriers: records, bodyRoots };
1312
+ }
1313
+
1314
+ // packages/safe-bash-docx-engine/src/xml-write.ts
1315
+ function containsMath(root, budget) {
1316
+ const pending = [root];
1317
+ while (pending.length) {
1318
+ const node = pending.pop();
1319
+ budget.charge("work", 1);
1320
+ if (node.namespace === mathNamespace(false) || node.namespace === mathNamespace(true)) return true;
1321
+ budget.charge("retainedBytes", node.children.length * 8);
1322
+ for (const child of node.children) pending.push(child);
1323
+ }
1324
+ return false;
1325
+ }
1326
+ var UnsupportedEditError = class extends Error {
1327
+ code = "unsupported-edit";
1328
+ };
1329
+ var replaceListPropertyXml = /* @__PURE__ */ Symbol("replace-list-property-xml");
1330
+ var replaceCommentRangeXml = /* @__PURE__ */ Symbol("replace-comment-range-xml");
1331
+ var replaceNativeTabCollectionXml = /* @__PURE__ */ Symbol("replace-native-tab-collection-xml");
1332
+ var sourceRootEnvelope = /* @__PURE__ */ Symbol("source-root-envelope");
1333
+ var appendBodyBlocks = /* @__PURE__ */ Symbol("append-body-blocks");
1334
+ var insertParagraphBefore = /* @__PURE__ */ Symbol("insert-paragraph-before");
1335
+ var insertParagraphAfter = /* @__PURE__ */ Symbol("insert-paragraph-after");
1336
+ var insertTableRowXml = /* @__PURE__ */ Symbol("insert-table-row-xml");
1337
+ var removeTableRowXml = /* @__PURE__ */ Symbol("remove-table-row-xml");
1338
+ var removeNoteBodyXml = /* @__PURE__ */ Symbol("remove-note-body-xml");
1339
+ var replaceActiveStyleXml = /* @__PURE__ */ Symbol("replace-active-style-xml");
1340
+ var insertActiveLatentStyles = /* @__PURE__ */ Symbol("insert-active-latent-styles");
1341
+ var editActiveRelationshipXml = /* @__PURE__ */ Symbol("edit-active-relationship-xml");
1342
+ var editActivePropertyXml = /* @__PURE__ */ Symbol("edit-active-property-xml");
1343
+ var replaceSplitTextRunXml = /* @__PURE__ */ Symbol("replace-split-text-run-xml");
1344
+ var splitNativeTextRunXml = /* @__PURE__ */ Symbol("split-native-text-run-xml");
1345
+ var nativeElementSourceTokens = /* @__PURE__ */ Symbol("native-element-source-tokens");
1346
+ var nativeXmlTriviaSource = /* @__PURE__ */ Symbol("native-xml-trivia-source");
1347
+ var nativeScalarTextSource = /* @__PURE__ */ Symbol("native-scalar-text-source");
1348
+ var replaceSplitParagraphXml = /* @__PURE__ */ Symbol("replace-split-paragraph-xml");
1349
+ var copiedSplitParagraphProperties = /* @__PURE__ */ Symbol("copied-split-paragraph-properties");
1350
+ var editInlineShapeExtentXml = /* @__PURE__ */ Symbol("edit-inline-shape-extent-xml");
1351
+ var cloneableRunProperties = new Set("rStyle rFonts b bCs i iCs caps smallCaps strike dstrike outline shadow emboss imprint noProof snapToGrid vanish webHidden color spacing w kern position sz szCs highlight u effect bdr shd fitText vertAlign rtl cs em lang eastAsianLayout specVanish oMath".split(" "));
1352
+ var cloneableParagraphProperties = new Set("pPr pStyle keepNext keepLines pageBreakBefore framePr widowControl numPr ilvl numId suppressLineNumbers pBdr top left bottom right between bar start end shd tabs tab suppressAutoHyphens kinsoku wordWrap overflowPunct topLinePunct autoSpaceDE autoSpaceDN bidi adjustRightInd snapToGrid spacing ind contextualSpacing mirrorIndents suppressOverlap jc textDirection textAlignment textboxTightWrap outlineLvl divId cnfStyle rPr sectPr headerReference footerReference footnotePr endnotePr type pgSz pgMar paperSrc pgBorders lnNumType pgNumType cols col formProt vAlign noEndnote titlePg textDirection bidi rtlGutter docGrid printerSettings".split(" "));
1353
+ function cloneableRunProperty(element, w, containers, budget, children = (node) => node.children) {
1354
+ budget.charge("work", 1 + element.attributes.length);
1355
+ const storedProperty = (node) => {
1356
+ budget.charge("retainedBytes", 40);
1357
+ const pending = [{ node, index: -1 }];
1358
+ while (pending.length) {
1359
+ const frame = pending.at(-1);
1360
+ if (frame.index === -1) {
1361
+ budget.charge("work", 1);
1362
+ if (frame.node.namespace === w && frame.node.localName !== "rPr" && !cloneableRunProperties.has(frame.node.localName)) return false;
1363
+ frame.index = 0;
1364
+ }
1365
+ const child = frame.node.children[frame.index++];
1366
+ if (!child) {
1367
+ pending.pop();
1368
+ continue;
1369
+ }
1370
+ budget.charge("retainedBytes", 40);
1371
+ pending.push({ node: child, index: -1 });
1372
+ }
1373
+ return true;
1374
+ };
1375
+ return (element.namespace === w && (element.localName === "rPr" || cloneableRunProperties.has(element.localName) && !children(element).length) || element.namespace === "http://schemas.openxmlformats.org/markup-compatibility/2006" || containers.has(element)) && element.attributes.every((attribute) => [w, "http://www.w3.org/2000/xmlns/", "http://www.w3.org/XML/1998/namespace", "http://schemas.openxmlformats.org/markup-compatibility/2006"].includes(attribute.namespace) || attribute.namespace === "" && element.localName === "Choice" && attribute.localName === "Requires") && element.children.every((child) => (child.namespace === w || containers.has(child)) && storedProperty(child)) && children(element).every((child) => cloneableRunProperty(child, w, containers, budget, children));
1376
+ }
1377
+ function unsupported() {
1378
+ throw new UnsupportedEditError("The XML edit cannot establish faithful preservation.");
1379
+ }
1380
+ var sourceIndexes = /* @__PURE__ */ new WeakMap();
1381
+ var editorOwners = /* @__PURE__ */ new WeakMap();
1382
+ function indexSource(document, source, budget) {
1383
+ const cacheable = Object.isFrozen(document);
1384
+ if (cacheable) budget.charge("work", source.length);
1385
+ const cached = cacheable ? sourceIndexes.get(document) : void 0;
1386
+ if (cached?.source === source) {
1387
+ budget.charge("work", cached.work);
1388
+ budget.charge("retainedBytes", cached.retainedBytes);
1389
+ return cached.spans;
1390
+ }
1391
+ const before = cacheable ? budget.usage : void 0;
1392
+ const spans = /* @__PURE__ */ new Map();
1393
+ let offset = source.charCodeAt(0) === 65279 ? 1 : 0;
1394
+ const consume = (value) => {
1395
+ if (!source.startsWith(value, offset)) unsupported();
1396
+ offset += value.length;
1397
+ };
1398
+ const whitespace = () => {
1399
+ while (offset < source.length && " \r\n".includes(source[offset])) offset++;
1400
+ };
1401
+ const until = (delimiter) => {
1402
+ const end = source.indexOf(delimiter, offset);
1403
+ if (end < 0) unsupported();
1404
+ return end;
1405
+ };
1406
+ const visit = (root) => {
1407
+ budget.charge("retainedBytes", 64);
1408
+ const pending = [{ node: root }];
1409
+ while (pending.length) {
1410
+ const { node, close } = pending.pop();
1411
+ budget.charge("work", 1);
1412
+ if (close && node.kind === "element") {
1413
+ const contentEnd = offset;
1414
+ consume("</" + node.name);
1415
+ whitespace();
1416
+ consume(">");
1417
+ spans.set(node, { ...close, end: offset, contentEnd, owner: node });
1418
+ continue;
1419
+ }
1420
+ if (node.kind === "element") {
1421
+ const start2 = offset;
1422
+ consume("<" + node.name);
1423
+ for (const attribute of node.attributes) {
1424
+ whitespace();
1425
+ const attributeStart = offset;
1426
+ consume(attribute.name);
1427
+ whitespace();
1428
+ consume("=");
1429
+ whitespace();
1430
+ const quote = source[offset++];
1431
+ if (quote !== '"' && quote !== "'") unsupported();
1432
+ const start3 = offset;
1433
+ offset = until(quote);
1434
+ offset++;
1435
+ spans.set(attribute, { start: start3, end: offset - 1, owner: node, attributeStart, attributeEnd: offset });
1436
+ }
1437
+ whitespace();
1438
+ if (source.startsWith("/>", offset)) {
1439
+ if (node.content.length) unsupported();
1440
+ const contentStart = offset;
1441
+ offset += 2;
1442
+ spans.set(node, { start: start2, end: offset, contentStart, contentEnd: contentStart, empty: true, owner: node });
1443
+ } else {
1444
+ consume(">");
1445
+ const contentStart = offset;
1446
+ budget.charge("retainedBytes", 64 * (node.content.length + 1));
1447
+ pending.push({ node, close: { start: start2, contentStart } });
1448
+ for (let i = node.content.length - 1; i >= 0; i--) pending.push({ node: node.content[i] });
1449
+ }
1450
+ continue;
1451
+ }
1452
+ let suffix = "";
1453
+ if (node.kind === "comment") {
1454
+ consume("<!--");
1455
+ suffix = "-->";
1456
+ } else if (node.kind === "cdata") {
1457
+ consume("<![CDATA[");
1458
+ suffix = "]]>";
1459
+ } else if (node.kind === "processing-instruction") {
1460
+ consume("<?" + node.target);
1461
+ whitespace();
1462
+ suffix = "?>";
1463
+ }
1464
+ const start = offset;
1465
+ if (suffix) offset = until(suffix);
1466
+ else {
1467
+ const next = source.indexOf("<", offset);
1468
+ offset = next < 0 ? source.length : next;
1469
+ if (offset === start) unsupported();
1470
+ }
1471
+ spans.set(node, { start, end: offset, owner: node });
1472
+ offset += suffix.length;
1473
+ }
1474
+ };
1475
+ if (document.root.declaration !== void 0) {
1476
+ consume("<?xml");
1477
+ offset = until("?>") + 2;
1478
+ }
1479
+ for (const node of document.root.prolog ?? []) visit(node);
1480
+ visit(document.root);
1481
+ for (const node of document.root.epilog ?? []) visit(node);
1482
+ if (offset !== source.length) unsupported();
1483
+ if (before) {
1484
+ budget.charge("retainedBytes", 128);
1485
+ const after = budget.usage;
1486
+ sourceIndexes.set(document, { source, spans, work: after.work - before.work, retainedBytes: after.retainedBytes - before.retainedBytes });
1487
+ }
1488
+ return spans;
1489
+ }
1490
+ function escapeValue(value, attribute) {
1491
+ let escaped = "";
1492
+ for (const char of value) {
1493
+ if (char === "&") escaped += "&amp;";
1494
+ else if (char === "<") escaped += "&lt;";
1495
+ else if (char === ">") escaped += "&gt;";
1496
+ else if (char === "\r") escaped += "&#13;";
1497
+ else if (attribute && char === "\n") escaped += "&#10;";
1498
+ else if (attribute && char === " ") escaped += "&#9;";
1499
+ else if (attribute && char === '"') escaped += "&quot;";
1500
+ else if (attribute && char === "'") escaped += "&apos;";
1501
+ else escaped += char;
1502
+ }
1503
+ return escaped;
1504
+ }
1505
+ var DocumentXmlEditor = class _DocumentXmlEditor {
1506
+ #budget;
1507
+ #profile;
1508
+ #compatibility;
1509
+ #guardCompatibility = false;
1510
+ #document;
1511
+ #source;
1512
+ #limits;
1513
+ #spans;
1514
+ #patches = /* @__PURE__ */ new Map();
1515
+ #namespaces;
1516
+ #elements;
1517
+ #dialect;
1518
+ #shapes;
1519
+ #boxViews = /* @__PURE__ */ new Map();
1520
+ constructor(bytes, limits = {}, profile = void 0, budget = new DocumentBudget()) {
1521
+ this.#budget = budget;
1522
+ this.#limits = documentXmlSettings(limits, budget);
1523
+ this.#document = parseDocumentXml(bytes, this.#limits, budget);
1524
+ this.#profile = compatibilitySettings(profile === void 0 ? compatibilityProfileForRoot(this.#document.root) : profile);
1525
+ budget.charge("retainedBytes", bytes.length * 8);
1526
+ budget.charge("work", bytes.length * 8);
1527
+ this.#dialect = dialectForNamespace(this.#document.root.namespace);
1528
+ this.#guardCompatibility = this.#dialect !== void 0;
1529
+ this.#source = new TextDecoder(this.#document.encoding, { fatal: true, ignoreBOM: true }).decode(this.#document.bytes);
1530
+ this.#spans = indexSource(this.#document, this.#source, this.#budget);
1531
+ const cacheable = Object.isFrozen(this.#document);
1532
+ if (cacheable) budget.charge("retainedBytes", 128);
1533
+ const cached = cacheable ? editorOwners.get(this.#document) : void 0;
1534
+ if (cached) {
1535
+ this.#elements = cached.elements;
1536
+ this.#namespaces = cached.namespaces;
1537
+ if (!this.#guardCompatibility) for (const node of this.#elements) {
1538
+ if (hasCompatibilityMarkup(node, this.#profile)) {
1539
+ this.#guardCompatibility = true;
1540
+ break;
1541
+ }
1542
+ }
1543
+ return;
1544
+ }
1545
+ const elements = /* @__PURE__ */ new Set();
1546
+ const namespaces = /* @__PURE__ */ new Map();
1547
+ const stack = [this.#document.root];
1548
+ const immutable = budget[documentXmlCache].immutableRoots?.has(this.#document.root) === true;
1549
+ while (stack.length) {
1550
+ const node = stack.pop();
1551
+ if (node.kind === "element") {
1552
+ elements.add(node);
1553
+ if (!this.#guardCompatibility && hasCompatibilityMarkup(node, this.#profile)) this.#guardCompatibility = true;
1554
+ if (!namespaces.has(node.namespaces))
1555
+ namespaces.set(node.namespaces, new Map(node.namespaces));
1556
+ if (!immutable) {
1557
+ for (const attribute of node.attributes) Object.freeze(attribute);
1558
+ Object.freeze(node.content);
1559
+ Object.freeze(node.children);
1560
+ Object.freeze(node.attributes);
1561
+ if (node.prolog) Object.freeze(node.prolog);
1562
+ if (node.epilog) Object.freeze(node.epilog);
1563
+ }
1564
+ for (const child of node.content) stack.push(child);
1565
+ if (node.prolog) for (const child of node.prolog) stack.push(child);
1566
+ if (node.epilog) for (const child of node.epilog) stack.push(child);
1567
+ }
1568
+ if (!immutable) Object.freeze(node);
1569
+ }
1570
+ this.#elements = elements;
1571
+ this.#namespaces = namespaces;
1572
+ if (cacheable) editorOwners.set(this.#document, { elements, namespaces });
1573
+ }
1574
+ get compatibility() {
1575
+ return this.#compatibility ??= new MarkupCompatibility(this.root, this.#profile, this.#budget);
1576
+ }
1577
+ get root() {
1578
+ return this.#document.root;
1579
+ }
1580
+ [sourceRootEnvelope]() {
1581
+ const span = this.#spans.get(this.root);
1582
+ const length = this.#source.length - (span.end - span.start);
1583
+ this.#budget.charge("work", length);
1584
+ this.#budget.charge("retainedBytes", length * 2);
1585
+ return [this.#source.slice(0, span.start), this.#source.slice(span.end)];
1586
+ }
1587
+ get dirtyNodes() {
1588
+ return [...new Set([...this.#patches.keys()].map((token) => this.#spans.get(token).owner))];
1589
+ }
1590
+ /** Every affected native box must admit the operation, even before a no-op edit. */
1591
+ assertShapeEditAllowed(node) {
1592
+ this.#assertOwnedElement(node);
1593
+ if (!this.#dialect) return;
1594
+ const span = this.#spans.get(node);
1595
+ if (!span) unsupported();
1596
+ for (const carrier of this.#shapeCensus().rawCarriers) {
1597
+ for (const body of this.#shapeCensus().bodyRoots) {
1598
+ const bodySpan = this.#spans.get(body);
1599
+ const carrierSpan = this.#spans.get(carrier.node);
1600
+ if (!(carrierSpan.start <= bodySpan.start && bodySpan.end <= carrierSpan.end)) continue;
1601
+ if (span.start <= bodySpan.start && bodySpan.end <= span.end || bodySpan.start <= span.start && span.end <= bodySpan.end) {
1602
+ if (!carrier.active || carrier.refusalReasons.length || !carrier.bodies.some((b) => b.node === body)) unsupported();
1603
+ }
1604
+ }
1605
+ }
1606
+ }
1607
+ #shapeCensus() {
1608
+ return this.#shapes ??= collectShapeCarriers(
1609
+ this.root,
1610
+ this.#dialect,
1611
+ this.#budget,
1612
+ new Map(this.compatibility.branches.map((branch) => [branch.alternateContent, branch.selected]))
1613
+ );
1614
+ }
1615
+ #canEdit(token) {
1616
+ if (this.compatibility.canEdit(token)) return true;
1617
+ if (!this.#dialect) return false;
1618
+ const span = this.#spans.get(token);
1619
+ if (!span) return false;
1620
+ for (const carrier of this.#shapeCensus().carriers) {
1621
+ if (carrier.refusalReasons.length) continue;
1622
+ for (const body of carrier.bodies) {
1623
+ const boundary = this.#spans.get(body.node);
1624
+ if (boundary.contentStart <= span.start && span.end <= boundary.contentEnd) {
1625
+ let view = this.#boxViews.get(body.node);
1626
+ if (!view) {
1627
+ view = new MarkupCompatibility(body.node, this.#profile, this.#budget);
1628
+ this.#boxViews.set(body.node, view);
1629
+ }
1630
+ return view.canEdit(token);
1631
+ }
1632
+ }
1633
+ }
1634
+ return false;
1635
+ }
1636
+ /** Exact admitted source, for engine-authored fragments retaining lexical XML. */
1637
+ [nativeElementSourceTokens](node, omittedAttribute) {
1638
+ this.#assertOwnedElement(node);
1639
+ const span = this.#spans.get(node);
1640
+ const openingEnd = span.empty ? span.end : span.contentStart;
1641
+ const closingStart = span.empty ? span.end : span.contentEnd;
1642
+ this.#budget.charge("work", openingEnd - span.start + span.end - closingStart);
1643
+ this.#budget.charge("retainedBytes", (openingEnd - span.start + span.end - closingStart) * 2 + 16);
1644
+ let opening = this.#source.slice(span.start, openingEnd);
1645
+ if (omittedAttribute) {
1646
+ this.#budget.charge("work", opening.length);
1647
+ this.#budget.charge("retainedBytes", opening.length * 4 + 24);
1648
+ if (!node.attributes.includes(omittedAttribute)) throw new OwnershipError("Expected an attribute owned by this XML element.");
1649
+ if (omittedAttribute.namespace === "http://www.w3.org/2000/xmlns/") unsupported();
1650
+ const attribute = this.#spans.get(omittedAttribute);
1651
+ if (attribute.attributeStart < span.start || attribute.attributeEnd > openingEnd) unsupported();
1652
+ opening = this.#source.slice(span.start, attribute.attributeStart) + this.#source.slice(attribute.attributeEnd, openingEnd);
1653
+ }
1654
+ return [opening, this.#source.slice(closingStart, span.end)];
1655
+ }
1656
+ [nativeXmlTriviaSource](node) {
1657
+ if (!node || typeof node !== "object" || !["comment", "processing-instruction"].includes(node.kind))
1658
+ throw new InputTypeError("Expected an XML comment or processing instruction.");
1659
+ const span = this.#spans.get(node);
1660
+ if (!span) throw new OwnershipError("Expected XML trivia owned by this editor.");
1661
+ let start = span.start;
1662
+ if (node.kind === "comment") start -= 4;
1663
+ else if (node.kind === "processing-instruction") {
1664
+ while (start > 0 && " \r\n".includes(this.#source[start - 1])) {
1665
+ this.#budget.charge("work", 1);
1666
+ start--;
1667
+ }
1668
+ start -= node.target.length + 2;
1669
+ }
1670
+ const end = span.end + (node.kind === "comment" ? 3 : 2);
1671
+ this.#budget.charge("work", end - start);
1672
+ this.#budget.charge("retainedBytes", (end - start) * 2);
1673
+ return this.#source.slice(start, end);
1674
+ }
1675
+ [nativeScalarTextSource](node, text, options = {}) {
1676
+ this.#assertOwnedElement(node);
1677
+ if (typeof text !== "string") throw new InputTypeError("Expected XML scalar text.");
1678
+ const content = options.content ?? node.content, span = this.#spans.get(node);
1679
+ const maximum = span.end - span.start + text.length * 6 + node.name.length + 3 + (options.preserveSpace ? 24 : 0);
1680
+ this.#budget.charge("retainedBytes", maximum * 8);
1681
+ this.#budget.charge("work", maximum * 4);
1682
+ const chunks = [];
1683
+ let offset = span.contentStart, replaced = false;
1684
+ for (const token of content) {
1685
+ if (token.kind !== "text" && token.kind !== "cdata") continue;
1686
+ const scalar = this.#spans.get(token);
1687
+ if (!scalar) throw new OwnershipError("Expected owned XML scalar content.");
1688
+ const start = scalar.start - (token.kind === "cdata" ? 9 : 0);
1689
+ const end = scalar.end + (token.kind === "cdata" ? 3 : 0);
1690
+ if (start < offset || end > span.contentEnd) unsupported();
1691
+ chunks.push(this.#source.slice(offset, start), replaced ? "" : escapeValue(text, false));
1692
+ offset = end;
1693
+ replaced = true;
1694
+ }
1695
+ chunks.push(this.#source.slice(offset, span.contentEnd), replaced ? "" : escapeValue(text, false));
1696
+ let source = this.#source.slice(span.start, span.contentStart) + (span.empty ? ">" : "") + chunks.join("") + (span.empty ? `</${node.name}>` : this.#source.slice(span.contentEnd, span.end));
1697
+ if (options.preserveSpace) {
1698
+ const space = node.attributes.find((attribute) => attribute.namespace === "http://www.w3.org/XML/1998/namespace" && attribute.localName === "space");
1699
+ if (space) {
1700
+ const attribute = this.#spans.get(space);
1701
+ source = source.slice(0, attribute.start - span.start) + "preserve" + source.slice(attribute.end - span.start);
1702
+ } else {
1703
+ const index = span.contentStart - span.start - (span.empty ? 0 : 1);
1704
+ source = source.slice(0, index) + ' xml:space="preserve"' + source.slice(index);
1705
+ }
1706
+ }
1707
+ return source;
1708
+ }
1709
+ /** Exact admitted source, for engine-authored fragments retaining lexical XML. */
1710
+ sourceXml(node, replacements = /* @__PURE__ */ new Map(), contentOnly = false) {
1711
+ this.#assertOwnedElement(node);
1712
+ const span = this.#spans.get(node);
1713
+ this.#budget.charge("work", span.end - span.start);
1714
+ this.#budget.charge("retainedBytes", (span.end - span.start) * 2);
1715
+ let offset = contentOnly ? span.contentStart : span.start;
1716
+ const chunks = [];
1717
+ const descendants = [...replacements.keys()];
1718
+ for (const child of descendants) {
1719
+ this.#assertOwnedElement(child);
1720
+ const childSpan = this.#spans.get(child);
1721
+ if (child === node || !childSpan || childSpan.start < span.contentStart || childSpan.end > span.contentEnd) unsupported();
1722
+ }
1723
+ descendants.sort((left, right) => this.#spans.get(left).start - this.#spans.get(right).start);
1724
+ for (const child of descendants) {
1725
+ const replacement = replacements.get(child);
1726
+ if (replacement === void 0) continue;
1727
+ if (typeof replacement !== "string") throw new InputTypeError("Expected XML markup.");
1728
+ const childSpan = this.#spans.get(child);
1729
+ if (childSpan.start < offset) unsupported();
1730
+ this.#budget.charge("work", replacement.length);
1731
+ this.#budget.charge("retainedBytes", replacement.length * 2);
1732
+ chunks.push(this.#source.slice(offset, childSpan.start), replacement);
1733
+ offset = childSpan.end;
1734
+ }
1735
+ chunks.push(this.#source.slice(offset, contentOnly ? span.contentEnd : span.end));
1736
+ return chunks.join("");
1737
+ }
1738
+ /** Replace an owned editable subtree; validate the complete candidate atomically. */
1739
+ replaceElement(node, xml2) {
1740
+ if (typeof xml2 !== "string") throw new InputTypeError("Expected XML markup.");
1741
+ this.#assertOwnedElement(node);
1742
+ if (node === this.root || this.#patches.has(node)) unsupported();
1743
+ this.assertShapeEditAllowed(node);
1744
+ if (this.#guardCompatibility && !this.#canEdit(node)) unsupported();
1745
+ this.#stageReplacement(node, xml2, !this.#canReplaceSubtree(node, (token) => this.#canEdit(token)), true);
1746
+ }
1747
+ [replaceCommentRangeXml](paragraph, xml2) {
1748
+ this.#assertOwnedElement(paragraph);
1749
+ if (typeof xml2 !== "string") throw new InputTypeError("Expected XML markup.");
1750
+ if (!this.#dialect || paragraph.namespace !== documentDialects[this.#dialect].w || paragraph.localName !== "p" || this.#patches.has(paragraph) || !this.#canEdit(paragraph)) unsupported();
1751
+ this.assertShapeEditAllowed(paragraph);
1752
+ this.#stageReplacement(
1753
+ paragraph,
1754
+ xml2,
1755
+ !this.#canReplaceSubtree(paragraph, (token) => this.#canEdit(token)),
1756
+ true,
1757
+ true
1758
+ );
1759
+ }
1760
+ [splitNativeTextRunXml](node, fragments, stage = true, wrap) {
1761
+ this.#assertOwnedElement(node);
1762
+ const children = activeXmlChildren(this, this.#budget), active = children(node);
1763
+ const props = active.filter((child) => child.namespace === node.namespace && child.localName === "rPr");
1764
+ const leaves2 = active.filter((child) => !props.includes(child));
1765
+ const containers = new Set(this.compatibility[compatibilityContainers]);
1766
+ const branchElements = new Set(this.compatibility.branches.flatMap((branch) => branch.alternateContent.children).filter((child) => child.namespace === "http://schemas.openxmlformats.org/markup-compatibility/2006" && ["Choice", "Fallback"].includes(child.localName)));
1767
+ let previousCacheFragment = -1;
1768
+ if (!this.#dialect || node.namespace !== documentDialects[this.#dialect].w || node.localName !== "r" || !this.#canEdit(node) || this.#patches.has(node) || props.length > 1 || !fragments.length || node.attributes.some((attribute) => attribute.namespace !== "http://www.w3.org/2000/xmlns/" && !this.#canEdit(attribute)) || props.some((property) => !cloneableRunProperty(property, node.namespace, containers, this.#budget, children)) || leaves2.some((leaf) => {
1769
+ if (leaf.namespace !== node.namespace || !["t", "delText", "tab", "ptab", "br", "cr", "noBreakHyphen", "softHyphen", "lastRenderedPageBreak", "footnoteRef", "endnoteRef", "annotationRef"].includes(leaf.localName)) return true;
1770
+ if (leaf.localName === "lastRenderedPageBreak") {
1771
+ const original = this.sourceXml(leaf);
1772
+ let copies = 0;
1773
+ for (const [index, fragment] of fragments.entries()) {
1774
+ this.#budget.charge("work", 1);
1775
+ if (!fragment.content.has(leaf)) continue;
1776
+ if (fragment.content.get(leaf) !== original || index < previousCacheFragment) return true;
1777
+ previousCacheFragment = index;
1778
+ copies++;
1779
+ }
1780
+ return leaf.children.length > 0 || copies !== 1;
1781
+ }
1782
+ return leaf.content.some((content) => content.kind !== "text") || leaf.attributes.some((attribute) => attribute.namespace !== "http://www.w3.org/2000/xmlns/" && !this.#canEdit(attribute));
1783
+ }) || fragments.some((fragment) => [...fragment.content.keys()].some((leaf) => !leaves2.includes(leaf)))) unsupported();
1784
+ const selected = /* @__PURE__ */ new Set([...leaves2, ...props]);
1785
+ const paths = /* @__PURE__ */ new Set();
1786
+ this.#budget.charge("retainedBytes", 40);
1787
+ const traversal = [{ element: node, index: -1, found: false }];
1788
+ while (traversal.length) {
1789
+ const frame = traversal.at(-1), element = frame.element;
1790
+ if (frame.index === -1) {
1791
+ this.#budget.charge("work", 1);
1792
+ frame.index = 0;
1793
+ if (selected.has(element)) {
1794
+ paths.add(element);
1795
+ traversal.pop();
1796
+ if (traversal.length) traversal.at(-1).found = true;
1797
+ continue;
1798
+ }
1799
+ }
1800
+ const child = element.children[frame.index++];
1801
+ if (child) {
1802
+ this.#budget.charge("retainedBytes", 40);
1803
+ traversal.push({ element: child, index: -1, found: false });
1804
+ continue;
1805
+ }
1806
+ if (frame.found) {
1807
+ if (element !== node && !containers.has(element)) unsupported();
1808
+ if (element.content.some((content) => (content.kind === "text" || content.kind === "cdata") && content.text.trim()) || element !== node && element.attributes.some((attribute) => !["http://www.w3.org/2000/xmlns/", "http://www.w3.org/XML/1998/namespace", "http://schemas.openxmlformats.org/markup-compatibility/2006"].includes(attribute.namespace) && !(attribute.namespace === "" && element.localName === "Choice" && attribute.localName === "Requires"))) unsupported();
1809
+ paths.add(element);
1810
+ }
1811
+ traversal.pop();
1812
+ if (frame.found && traversal.length) traversal.at(-1).found = true;
1813
+ }
1814
+ const open = (element, attributes = element.attributes) => `<${element.name}${[...element.namespaces].filter(([prefix]) => prefix !== "xml").map(([prefix, uri]) => ` ${prefix ? "xmlns:" + prefix : "xmlns"}="${escapeValue(uri, true)}"`).join("")}${attributes.filter((attribute) => attribute.namespace !== "http://www.w3.org/2000/xmlns/").map((attribute) => ` ${attribute.name}="${escapeValue(attribute.value, true)}"`).join("")}>`;
1815
+ const markup = fragments.map((fragment, index) => {
1816
+ const patches = new Map(leaves2.map((leaf) => [leaf, fragment.content.get(leaf) ?? ""]));
1817
+ if (props[0]) patches.set(props[0], index ? copiedNativeProperties(fragment.properties, props[0], this.root, this.#profile, this.#budget) : fragment.properties);
1818
+ if (index) {
1819
+ this.#budget.charge("retainedBytes", 40);
1820
+ const pending = [{ element: node, index: 0 }];
1821
+ while (pending.length) {
1822
+ const frame = pending.at(-1), child = frame.element.children[frame.index++];
1823
+ this.#budget.charge("work", 1);
1824
+ if (!child) {
1825
+ pending.pop();
1826
+ continue;
1827
+ }
1828
+ if (selected.has(child)) continue;
1829
+ if (paths.has(child)) {
1830
+ this.#budget.charge("retainedBytes", 40);
1831
+ pending.push({ element: child, index: 0 });
1832
+ } else if (branchElements.has(child)) {
1833
+ const attributes = child.attributes.filter((attribute) => ["http://www.w3.org/2000/xmlns/", "http://schemas.openxmlformats.org/markup-compatibility/2006"].includes(attribute.namespace) || attribute.namespace === "" && child.localName === "Choice" && attribute.localName === "Requires");
1834
+ patches.set(child, attributes.length === child.attributes.length ? this[nativeElementSourceTokens](child).join("") : open(child, attributes) + `</${child.name}>`);
1835
+ } else patches.set(child, "");
1836
+ }
1837
+ }
1838
+ let content;
1839
+ if (!index) content = this.sourceXml(node, patches, true);
1840
+ else {
1841
+ const chunks = [];
1842
+ this.#budget.charge("retainedBytes", 48);
1843
+ const pending = [{ element: node, index: 0, closing: "" }];
1844
+ while (pending.length) {
1845
+ const frame = pending.at(-1), item = frame.element.content[frame.index++];
1846
+ this.#budget.charge("work", 1);
1847
+ if (!item) {
1848
+ pending.pop();
1849
+ if (pending.length) chunks.push(frame.closing);
1850
+ continue;
1851
+ }
1852
+ if (item.kind !== "element") {
1853
+ if (item.kind === "text" || item.kind === "cdata") chunks.push(escapeValue(item.text, false));
1854
+ continue;
1855
+ }
1856
+ this.#budget.charge("work", 1 + item.content.length);
1857
+ const replacement = patches.get(item);
1858
+ if (replacement !== void 0) chunks.push(replacement);
1859
+ else if (!paths.has(item)) chunks.push(this.sourceXml(item));
1860
+ else {
1861
+ this.#budget.charge("retainedBytes", 48);
1862
+ const [opening, closing] = this[nativeElementSourceTokens](item);
1863
+ chunks.push(opening);
1864
+ pending.push({ element: item, index: 0, closing });
1865
+ }
1866
+ }
1867
+ content = chunks.join("");
1868
+ }
1869
+ return open(node) + (props.length ? "" : fragment.properties) + content + `</${node.name}>`;
1870
+ });
1871
+ const wrapped = wrap ? markup.map((fragment, index) => {
1872
+ const result = wrap(fragment, index);
1873
+ if (typeof result !== "string") throw new InputTypeError("Expected XML markup.");
1874
+ return result;
1875
+ }) : markup;
1876
+ this.assertShapeEditAllowed(node);
1877
+ if (stage) this.#stageReplacement(node, wrapped.join(""), false, true);
1878
+ return wrapped;
1879
+ }
1880
+ [replaceSplitParagraphXml](node, markup) {
1881
+ this.#assertOwnedElement(node);
1882
+ const children = activeXmlChildren(this, this.#budget);
1883
+ if (!this.#dialect || node.namespace !== documentDialects[this.#dialect].w || node.localName !== "p" || !this.#canEdit(node) || this.#patches.has(node) || children(node).some((child) => child.namespace !== node.namespace || !["pPr", "r", "bookmarkStart", "bookmarkEnd", "commentRangeStart", "commentRangeEnd", "proofErr", "permStart", "permEnd"].includes(child.localName))) unsupported();
1884
+ for (const run of children(node).filter((child) => child.localName === "r")) {
1885
+ if (children(run).some((child) => child.namespace !== node.namespace || !["rPr", "t", "tab", "ptab", "br", "cr", "noBreakHyphen", "softHyphen", "lastRenderedPageBreak", "footnoteRef", "endnoteRef", "annotationRef"].includes(child.localName))) unsupported();
1886
+ }
1887
+ this.assertShapeEditAllowed(node);
1888
+ this.#stageReplacement(node, markup, false, true);
1889
+ }
1890
+ [copiedSplitParagraphProperties](paragraph, props) {
1891
+ this.#assertOwnedElement(paragraph);
1892
+ this.#assertOwnedElement(props);
1893
+ const children = activeXmlChildren(this, this.#budget), containers = new Set(this.compatibility[compatibilityContainers]);
1894
+ const validate = (node) => {
1895
+ this.#budget.charge("work", 1 + node.attributes.length);
1896
+ if (node.namespace === paragraph.namespace && node.localName === "sectPr" && this.#canEdit(node)) return;
1897
+ if (!this.#canEdit(node) || node.namespace !== paragraph.namespace || !(cloneableParagraphProperties.has(node.localName) || cloneableRunProperties.has(node.localName)) || node.attributes.some((attribute) => !["http://www.w3.org/2000/xmlns/", "http://www.w3.org/XML/1998/namespace", "http://schemas.openxmlformats.org/markup-compatibility/2006"].includes(attribute.namespace) && !this.#canEdit(attribute)) || node.children.some((child) => child.namespace !== paragraph.namespace && !containers.has(child)) || node.content.some((item) => item.kind !== "element" && (item.kind !== "text" || item.text.trim()))) unsupported();
1898
+ for (const child of children(node)) validate(child);
1899
+ };
1900
+ if (props.localName !== "pPr" || !children(paragraph).includes(props)) unsupported();
1901
+ validate(props);
1902
+ return copiedNativeProperties(this.sourceXml(props), props, this.root, this.#profile, this.#budget, true);
1903
+ }
1904
+ /** Native formatting alternatives can follow each fragment of a split run. */
1905
+ [replaceSplitTextRunXml](node, xml2) {
1906
+ this.#assertOwnedElement(node);
1907
+ const containers = new Set(this.compatibility[compatibilityContainers]);
1908
+ if (!this.#dialect || node.namespace !== documentDialects[this.#dialect].w || node.localName !== "r" || node.attributes.some((attribute) => attribute.namespace !== "http://www.w3.org/2000/xmlns/" && !this.#canEdit(attribute)) || node.children.some((child) => child.namespace !== node.namespace || !["rPr", "t", "tab", "ptab", "br", "cr", "noBreakHyphen", "softHyphen", "lastRenderedPageBreak", "footnoteRef", "endnoteRef", "annotationRef"].includes(child.localName) || (child.localName === "rPr" ? !cloneableRunProperty(child, node.namespace, containers, this.#budget) : child.children.length > 0 || child.localName !== "lastRenderedPageBreak" && child.attributes.some((attribute) => attribute.namespace !== "http://www.w3.org/2000/xmlns/" && !this.#canEdit(attribute))))) {
1909
+ this.replaceElement(node, xml2);
1910
+ return;
1911
+ }
1912
+ this.assertShapeEditAllowed(node);
1913
+ if (!this.#canEdit(node) || this.#patches.has(node)) unsupported();
1914
+ const caches = node.children.filter((child) => child.localName === "lastRenderedPageBreak");
1915
+ if (caches.length) {
1916
+ const bindings = [...node.namespaces].filter(([prefix]) => prefix !== "xml").map(([prefix, uri]) => ` ${prefix ? "xmlns:" + prefix : "xmlns"}="${escapeValue(uri, true)}"`).join("");
1917
+ const candidate = new _DocumentXmlEditor(new TextEncoder().encode(`<fragment${bindings}>${xml2}</fragment>`), this.#limits, this.#profile, this.#budget);
1918
+ const retained = [];
1919
+ const collect = (parent) => {
1920
+ this.#budget.charge("work", 1 + parent.children.length);
1921
+ for (const child of parent.children) {
1922
+ if (child.namespace === node.namespace && child.localName === "lastRenderedPageBreak") {
1923
+ if (parent.namespace !== node.namespace || parent.localName !== "r" || child.children.length) unsupported();
1924
+ retained.push(child);
1925
+ }
1926
+ collect(child);
1927
+ }
1928
+ };
1929
+ collect(candidate.root);
1930
+ if (retained.length !== caches.length || caches.some((cache, index) => {
1931
+ const after = retained[index];
1932
+ this.#budget.charge("work", 1 + cache.namespaces.size);
1933
+ return candidate.sourceXml(after) !== this.sourceXml(cache) || after.namespaces.size !== cache.namespaces.size || [...cache.namespaces].some(([prefix, uri]) => after.namespaces.get(prefix) !== uri);
1934
+ })) unsupported();
1935
+ }
1936
+ this.#stageReplacement(node, xml2, false, true);
1937
+ }
1938
+ #canReplaceSubtree(node, canEdit) {
1939
+ const pending = [node];
1940
+ while (pending.length) {
1941
+ const element = pending.pop();
1942
+ this.#budget.charge("work", 1);
1943
+ if (this.#guardCompatibility && (!canEdit(element) || element.attributes.some((attribute) => attribute.namespace !== "http://www.w3.org/2000/xmlns/" && !canEdit(attribute)))) return false;
1944
+ for (let index = element.children.length - 1; index >= 0; index--) pending.push(element.children[index]);
1945
+ }
1946
+ return true;
1947
+ }
1948
+ /** Resolve the selected declaration, retaining its physical compatibility carrier. */
1949
+ [replaceActiveStyleXml](node, xml2) {
1950
+ if (typeof xml2 !== "string") throw new InputTypeError("Expected XML markup.");
1951
+ if (!this.#elements.has(node) || this.#patches.has(node) || !this.#dialect || this.root.namespace !== documentDialects[this.#dialect].w || this.root.localName !== "styles" || node.namespace !== this.root.namespace || node.localName !== "style" || !activeXmlChildren(this, this.#budget)(this.root).includes(node)) unsupported();
1952
+ const view = this.compatibility;
1953
+ if (!this.#canEdit(node)) unsupported();
1954
+ this.#stageReplacement(node, xml2, !this.#canReplaceSubtree(node, (token) => view.canEdit(token)), true);
1955
+ }
1956
+ [insertActiveLatentStyles]() {
1957
+ if (!this.#dialect || this.root.namespace !== documentDialects[this.#dialect].w || this.root.localName !== "styles" || this.#patches.size) unsupported();
1958
+ const children = activeXmlChildren(this, this.#budget)(this.root);
1959
+ if (children.some((node) => node.namespace === this.root.namespace && node.localName === "latentStyles")) unsupported();
1960
+ const markup = `<st:latentStyles xmlns:st="${this.root.namespace}"/>`;
1961
+ const firstStyle = children.find((node) => node.namespace === this.root.namespace && node.localName === "style");
1962
+ if (!firstStyle) {
1963
+ this.insertChildren(this.root, markup);
1964
+ return;
1965
+ }
1966
+ if (!this.#canEdit(firstStyle)) unsupported();
1967
+ const containingParent = (parent2) => {
1968
+ this.#budget.charge("work", 1);
1969
+ if (parent2.children.includes(firstStyle)) return parent2;
1970
+ for (const child of parent2.children) {
1971
+ const found = containingParent(child);
1972
+ if (found) return found;
1973
+ }
1974
+ return void 0;
1975
+ };
1976
+ const parent = containingParent(this.root);
1977
+ if (!parent) unsupported();
1978
+ this.#stageInsertion(parent, markup, firstStyle);
1979
+ }
1980
+ /** Change native fields in the selected row without reconstructing its carrier. */
1981
+ [editActiveRelationshipXml](node, values) {
1982
+ if (!this.#elements.has(node) || !relationshipXmlRows(this.root, this.#budget).some((row) => row.element === node)) unsupported();
1983
+ const span = this.#spans.get(node);
1984
+ for (const patched of this.#patches.keys()) {
1985
+ const other = this.#spans.get(patched);
1986
+ if (span.start < other.end && other.start < span.end) unsupported();
1987
+ }
1988
+ if (values === null) {
1989
+ this.#stageReplacement(node, "");
1990
+ return;
1991
+ }
1992
+ const patches = [];
1993
+ let inserted = 0;
1994
+ for (const [name, value] of Object.entries(values)) {
1995
+ if (!["Type", "Target", "TargetMode"].includes(name) || value !== null && typeof value !== "string") throw new InputTypeError("Expected native relationship fields.");
1996
+ const attribute = node.attributes.find((attribute2) => !attribute2.namespace && attribute2.localName === name);
1997
+ if (attribute) {
1998
+ if (attribute.value === value) continue;
1999
+ const field = this.#spans.get(attribute);
2000
+ patches.push(value === null ? { start: field.attributeStart, end: field.attributeEnd, value: "" } : { start: field.start, end: field.end, value: escapeValue(value, true) });
2001
+ } else if (value !== null) {
2002
+ const offset = span.empty ? span.contentStart : span.contentStart - 1;
2003
+ patches.push({ start: offset, end: offset, value: ` ${name}="${escapeValue(value, true)}"` });
2004
+ inserted++;
2005
+ }
2006
+ }
2007
+ if (!patches.length) return;
2008
+ let source = this.#source.slice(span.start, span.end);
2009
+ for (const patch of patches.sort((left, right) => right.start - left.start))
2010
+ source = source.slice(0, patch.start - span.start) + patch.value + source.slice(patch.end - span.start);
2011
+ this.#acceptOwnedPatch(node, source, inserted);
2012
+ }
2013
+ /** The list domain validates active references and retains every other token. */
2014
+ [replaceListPropertyXml](node, xml2) {
2015
+ if (typeof xml2 !== "string") throw new InputTypeError("Expected XML markup.");
2016
+ if (!this.#elements.has(node) || this.#patches.has(node) || !this.#dialect || node.namespace !== documentDialects[this.#dialect].w || node.localName !== "pPr") unsupported();
2017
+ this.assertShapeEditAllowed(node);
2018
+ this.#stageReplacement(node, xml2);
2019
+ }
2020
+ #stageReplacement(node, xml2, preserveOpaque = false, checkMath = false, preflightOwnership = false) {
2021
+ this.#budget.charge("retainedBytes", xml2.length * 8);
2022
+ this.#budget.charge("work", xml2.length * 4);
2023
+ this.#patches.set(node, xml2);
2024
+ try {
2025
+ const bindings = [...node.namespaces].filter(([prefix]) => prefix !== "xml").map(([prefix, value]) => ` ${prefix ? "xmlns:" + prefix : "xmlns"}="${escapeValue(value, true)}"`).join("");
2026
+ const fragment = parseDocumentXml(new TextEncoder().encode(`<fragment${bindings}>${xml2}</fragment>`), this.#limits, this.#budget);
2027
+ if (checkMath && containsMath(fragment.root, this.#budget)) preserveOpaque = true;
2028
+ this.#budget.charge("retainedBytes", 64 + fragment.root.content.length * 8);
2029
+ const pending = [...fragment.root.content];
2030
+ let inserted = 0;
2031
+ while (pending.length) {
2032
+ const token = pending.pop();
2033
+ this.#budget.charge("work", 1);
2034
+ inserted++;
2035
+ if (token.kind === "element") {
2036
+ inserted += token.attributes.length;
2037
+ this.#budget.charge("work", token.attributes.length);
2038
+ this.#budget.charge("retainedBytes", token.content.length * 8);
2039
+ for (const child of token.content) pending.push(child);
2040
+ }
2041
+ }
2042
+ if (!preflightOwnership) this.#budget.charge("insertedNodes", inserted);
2043
+ const serialized = this.serialize();
2044
+ this.#budget[documentXmlCache].admitted?.add(serialized);
2045
+ const candidate = parseDocumentXml(serialized, this.#limits, this.#budget);
2046
+ if (this.#dialect) validateXmlDialect(candidate.root, this.#dialect, this.#profile, this.#budget);
2047
+ if (preserveOpaque && opaqueXmlContent(this.root, this.#budget, this.#profile) !== opaqueXmlContent(candidate.root, this.#budget, this.#profile)) unsupported();
2048
+ if (preflightOwnership) this.#budget.charge("insertedNodes", inserted);
2049
+ } catch (error) {
2050
+ this.#patches.delete(node);
2051
+ throw error;
2052
+ }
2053
+ }
2054
+ /** Explicit bounded math authority; generic subtree replacement remains conservative. */
2055
+ replaceEquationElement(node, markup) {
2056
+ this.#assertOwnedElement(node);
2057
+ if (typeof markup !== "string") throw new InputTypeError("Expected equation markup.");
2058
+ if (!this.#elements.has(node) || node === this.root || this.#patches.has(node) || !this.#dialect) unsupported();
2059
+ const namespace = mathNamespace(this.#dialect === "strict");
2060
+ if (node.namespace !== namespace || !["oMath", "oMathPara"].includes(node.localName) || inspectEquationFragment(node, namespace, this.#budget).length) unsupported();
2061
+ const fragment = admitEquationFragment(new TextEncoder().encode(markup), namespace, this.#budget);
2062
+ if (fragment.root.localName !== node.localName) unsupported();
2063
+ this.#assertEquationHost(node);
2064
+ this.assertShapeEditAllowed(node);
2065
+ this.#stageReplacement(node, fragment.xml);
2066
+ }
2067
+ /** Append one bounded math root without granting generic compatibility insertion. */
2068
+ appendEquationElement(paragraph, markup) {
2069
+ this.#assertOwnedElement(paragraph);
2070
+ if (typeof markup !== "string") throw new InputTypeError("Expected equation markup.");
2071
+ if (!this.#elements.has(paragraph) || this.#patches.has(paragraph) || !this.#dialect || paragraph.namespace !== documentDialects[this.#dialect].w || paragraph.localName !== "p") unsupported();
2072
+ const fragment = admitEquationFragment(new TextEncoder().encode(markup), mathNamespace(this.#dialect === "strict"), this.#budget);
2073
+ this.#assertEquationHost(paragraph);
2074
+ this.assertShapeEditAllowed(paragraph);
2075
+ this.#stageInsertion(paragraph, fragment.xml);
2076
+ }
2077
+ #assertEquationHost(node) {
2078
+ const namespace = mathNamespace(this.#dialect === "strict"), w = documentDialects[this.#dialect].w;
2079
+ let chain;
2080
+ const search = (current, parents) => {
2081
+ this.#budget.charge("work", 1);
2082
+ if (current === node) {
2083
+ chain = [...parents, current];
2084
+ return;
2085
+ }
2086
+ for (const child of current.children) {
2087
+ if (chain) return;
2088
+ search(child, [...parents, current]);
2089
+ }
2090
+ };
2091
+ search(this.root, []);
2092
+ if (!chain) unsupported();
2093
+ let paragraphIndex = -1;
2094
+ for (let i = chain.length - 1; i >= 0; i--) if (chain[i].namespace === w && chain[i].localName === "p") {
2095
+ paragraphIndex = i;
2096
+ break;
2097
+ }
2098
+ if (paragraphIndex < 0) unsupported();
2099
+ const native = ["document", "body", "hdr", "ftr", "footnotes", "footnote", "endnotes", "endnote", "comments", "comment", "tbl", "tr", "tc", "p"];
2100
+ const mc2 = "http://schemas.openxmlformats.org/markup-compatibility/2006";
2101
+ if (chain.slice(0, paragraphIndex + 1).some((n) => n.namespace === w ? !native.includes(n.localName) : n.namespace !== mc2 || !["AlternateContent", "Choice", "Fallback"].includes(n.localName)) || chain.slice(paragraphIndex + 1, -1).some((n) => n.namespace !== mc2 || !["AlternateContent", "Choice", "Fallback"].includes(n.localName))) unsupported();
2102
+ const paragraph = chain[paragraphIndex], view = this.compatibility, active = /* @__PURE__ */ new Set();
2103
+ const projected = (content) => {
2104
+ for (const item of content) {
2105
+ this.#budget.charge("work", 1);
2106
+ if ("source" in item) {
2107
+ active.add(item.source);
2108
+ this.#budget.charge("retainedBytes", 32);
2109
+ if (item.disposition === "understood") projected(item.content);
2110
+ }
2111
+ }
2112
+ };
2113
+ projected(view.content);
2114
+ if (!active.has(node) || !active.has(paragraph)) unsupported();
2115
+ const check = (current) => {
2116
+ this.#budget.charge("work", 1 + current.attributes.length);
2117
+ if (current.namespace === mc2 && current.localName === "AlternateContent") {
2118
+ view.branches.find((b) => b.alternateContent === current)?.selected?.children.forEach(check);
2119
+ return;
2120
+ }
2121
+ if (!active.has(current)) return;
2122
+ if (![w, namespace].includes(current.namespace) || current.namespace === w && ["sdt", "fldSimple", "fldChar", "instrText", "ins", "del", "moveFrom", "moveTo", "pPrChange", "rPrChange", "moveFromRangeStart", "moveFromRangeEnd", "moveToRangeStart", "moveToRangeEnd"].includes(current.localName) || current.attributes.some((a) => ![w, namespace, mc2, "", "http://www.w3.org/XML/1998/namespace", "http://www.w3.org/2000/xmlns/"].includes(a.namespace))) unsupported();
2123
+ current.children.forEach(check);
2124
+ };
2125
+ check(paragraph);
2126
+ assertOutsideRevisionRanges(this.root, paragraph, this.#budget, view.branches);
2127
+ }
2128
+ /** Replace only scalar text content while preserving the exact owned element shell. */
2129
+ replaceScalarText(node, text) {
2130
+ if (typeof text !== "string") throw new InputTypeError("Expected an XML text string.");
2131
+ this.#assertOwnedElement(node);
2132
+ if (this.#patches.has(node) || node.children.length) unsupported();
2133
+ if (this.#guardCompatibility && (!this.#canEdit(node) || node.content.some((token) => !this.#canEdit(token)))) unsupported();
2134
+ this.assertShapeEditAllowed(node);
2135
+ this.#stageScalarText(node, text);
2136
+ }
2137
+ /** Preserve original tab tokens while admitting a proven insertion or position move. */
2138
+ [replaceNativeTabCollectionXml](owner, markup, tabs, leaf, position, moving) {
2139
+ this.#assertOwnedElement(owner);
2140
+ this.#assertOwnedElement(tabs);
2141
+ if (this.#guardCompatibility && !this.#canEdit(owner)) unsupported();
2142
+ this.assertShapeEditAllowed(owner);
2143
+ const ownerSpan = this.#spans.get(owner);
2144
+ for (const patched of this.#patches.keys()) {
2145
+ const span = this.#spans.get(patched);
2146
+ if (ownerSpan.start < span.end && span.start < ownerSpan.end) unsupported();
2147
+ }
2148
+ const children = activeXmlChildren(this, this.#budget), stops = children(tabs).filter((n) => n.namespace === tabs.namespace && n.localName === "tab");
2149
+ if (!this.#dialect || tabs.namespace !== documentDialects[this.#dialect].w || tabs.localName !== "tabs" || !this.#canEdit(tabs) || !Number.isSafeInteger(position) || position < -2147483648 || position > 2147483647 || moving && (!stops.includes(moving) || !this.#canEdit(moving))) unsupported();
2150
+ const bindings = [...tabs.namespaces].filter(([p]) => p !== "xml").map(([p, uri]) => ` ${p ? "xmlns:" + p : "xmlns"}="${escapeValue(uri, true)}"`).join("");
2151
+ const fragmentSource = `<fragment${bindings}>${leaf}</fragment>`, fragment = parseDocumentXml(new TextEncoder().encode(fragmentSource), this.#limits, this.#budget), added = fragment.root.children[0];
2152
+ if (fragment.root.content.length !== 1 || !added || added.namespace !== tabs.namespace || added.localName !== "tab" || added.attributes.find((a) => a.namespace === tabs.namespace && a.localName === "pos")?.value !== String(position)) unsupported();
2153
+ const attributes = (node, omitPosition = false) => node.attributes.filter((a) => a.namespace !== "http://www.w3.org/2000/xmlns/" && !(omitPosition && a.namespace === tabs.namespace && a.localName === "pos")).map((a) => [a.namespace, a.localName, a.value]).sort();
2154
+ const spans = indexSource(fragment, fragmentSource, this.#budget), addedSpan = spans.get(added);
2155
+ if (moving) {
2156
+ if (JSON.stringify(attributes(added, true)) !== JSON.stringify(attributes(moving, true)) || JSON.stringify([...added.namespaces]) !== JSON.stringify([...moving.namespaces]) || fragmentSource.slice(addedSpan.contentStart, addedSpan.contentEnd) !== this.sourceXml(moving, /* @__PURE__ */ new Map(), true)) unsupported();
2157
+ } else if (added.content.length || added.attributes.some((a) => a.namespace !== "http://www.w3.org/2000/xmlns/" && (a.namespace !== tabs.namespace || !["pos", "val", "leader"].includes(a.localName)))) unsupported();
2158
+ const next = stops.find((n) => n !== moving && storedMeasure(n.attributes.find((a) => a.namespace === tabs.namespace && a.localName === "pos")?.value ?? "").emu > position * 635), patches = /* @__PURE__ */ new Map();
2159
+ if (moving) patches.set(moving, "");
2160
+ if (next) patches.set(next, leaf + this.sourceXml(next));
2161
+ const expected = this.sourceXml(tabs, patches, true) + (next ? "" : leaf);
2162
+ const pathTo = (root, target) => {
2163
+ this.#budget.charge("work", 1);
2164
+ if (root === target) return [];
2165
+ for (const [i, child] of root.children.entries()) {
2166
+ const path = pathTo(child, target);
2167
+ if (path) return [i, ...path];
2168
+ }
2169
+ return void 0;
2170
+ };
2171
+ const ownerPath = pathTo(this.root, owner);
2172
+ if (!ownerPath || owner === this.root || !pathTo(owner, tabs)) unsupported();
2173
+ this.#acceptOwnedPatch(owner, markup, moving ? 0 : 1);
2174
+ try {
2175
+ const candidate = parseDocumentXml(this.serialize(), this.#limits, this.#budget), source = new TextDecoder(candidate.encoding, { fatal: true, ignoreBOM: true }).decode(candidate.bytes), projected = activeXmlChildren(candidate.root, this.#budget);
2176
+ let afterOwner = candidate.root;
2177
+ for (const index of ownerPath) afterOwner = afterOwner.children[index];
2178
+ const afterProps = afterOwner.localName === "pPr" ? afterOwner : projected(afterOwner).find((n) => n.namespace === tabs.namespace && n.localName === "pPr"), afterTabs = afterOwner.localName === "tabs" ? afterOwner : afterProps && projected(afterProps).find((n) => n.namespace === tabs.namespace && n.localName === "tabs");
2179
+ if (!afterTabs) unsupported();
2180
+ const candidateSpans = indexSource(candidate, source, this.#budget), span = candidateSpans.get(afterTabs);
2181
+ if (source.slice(span.contentStart, span.contentEnd) !== expected || JSON.stringify(attributes(afterTabs)) !== JSON.stringify(attributes(tabs)) || JSON.stringify([...afterTabs.namespaces]) !== JSON.stringify([...tabs.namespaces])) unsupported();
2182
+ if (moving) {
2183
+ const afterStops = projected(afterTabs).filter((n) => n.namespace === tabs.namespace && n.localName === "tab"), moved = afterStops[stops.filter((n) => n !== moving && storedMeasure(n.attributes.find((a) => a.namespace === tabs.namespace && a.localName === "pos")?.value ?? "").emu <= position * 635).length];
2184
+ const inheritedContext = (root, target) => {
2185
+ const path = pathTo(root, target);
2186
+ if (!path) unsupported();
2187
+ const context = /* @__PURE__ */ new Map();
2188
+ let node = root;
2189
+ for (const index of [...path, -1]) {
2190
+ for (const a of node.attributes) if (a.namespace === "http://www.w3.org/XML/1998/namespace" && ["lang", "space", "base"].includes(a.localName)) context.set(a.localName, a.localName === "base" ? [...context.get("base") ?? [], a.value] : [a.value]);
2191
+ if (index !== -1) node = node.children[index];
2192
+ }
2193
+ return JSON.stringify([...context]);
2194
+ };
2195
+ if (!moved || inheritedContext(this.root, moving) !== inheritedContext(candidate.root, moved)) unsupported();
2196
+ }
2197
+ const restoreTabs = (node) => {
2198
+ this.#budget.charge("work", 1 + node.children.length + node.content.length);
2199
+ this.#budget.charge("retainedBytes", 192 + node.children.length * 64 + node.content.length * 8);
2200
+ if (node === afterTabs) return tabs;
2201
+ const children2 = new Map(node.children.map((child) => [child, restoreTabs(child)]));
2202
+ return { ...node, children: [...children2.values()], content: node.content.map((item) => item.kind === "element" ? children2.get(item) : item) };
2203
+ };
2204
+ if (opaqueXmlContent(this.root, this.#budget, this.#profile) !== opaqueXmlContent(restoreTabs(candidate.root), this.#budget, this.#profile)) unsupported();
2205
+ } catch (error) {
2206
+ this.#patches.delete(owner);
2207
+ throw error;
2208
+ }
2209
+ }
2210
+ /** Resolve native property ownership before editing within its physical MCE carrier. */
2211
+ [editActivePropertyXml](node, value) {
2212
+ if (value !== null && typeof value !== "string") throw new InputTypeError("Expected scalar property text or removal.");
2213
+ if (!this.#elements.has(node) || this.#patches.size) unsupported();
2214
+ for (const dialect of ["strict", "transitional"]) for (const group of ["core", "extended", "custom"]) {
2215
+ const definition = propertyGroupDefinition(group, dialect);
2216
+ if (this.root.namespace !== definition.namespace || this.root.localName !== definition.root) continue;
2217
+ const property = readPropertyNodes(this.root, group, dialect, this.#budget).find((property2) => property2.node === node);
2218
+ if (!property?.value?.writable || !property.valueNode || !property.valueContent) unsupported();
2219
+ if (value === null) {
2220
+ if (property.valueNode.children.length || node !== property.valueNode && (node.children.length !== 1 || node.children[0] !== property.valueNode)) unsupported();
2221
+ const view = new MarkupCompatibility(node, this.#profile, this.#budget);
2222
+ if (!this.#canReplaceSubtree(node, (token) => view.canEdit(token))) unsupported();
2223
+ this.#stageReplacement(node, "");
2224
+ } else this.#stageScalarText(property.valueNode, value, property.valueContent);
2225
+ return;
2226
+ }
2227
+ unsupported();
2228
+ }
2229
+ #stageScalarText(node, text, content = node.content) {
2230
+ const length = content.reduce((size, token) => size + (token.kind === "text" || token.kind === "cdata" ? token.text.length : 0), 0);
2231
+ this.#budget.charge("retainedBytes", length * 2 + content.length * 16);
2232
+ this.#budget.charge("work", length + content.length);
2233
+ if (content.filter((token) => token.kind === "text" || token.kind === "cdata").map((token) => token.text).join("") === text) return;
2234
+ this.#budget.charge("insertedNodes", text.length ? 1 : 0);
2235
+ const patch = this[nativeScalarTextSource](node, text, { content });
2236
+ this.#patches.set(node, patch);
2237
+ try {
2238
+ const candidate = parseDocumentXml(this.serialize(), this.#limits, this.#budget);
2239
+ if (this.#dialect) validateXmlDialect(candidate.root, this.#dialect, this.#profile, this.#budget);
2240
+ } catch (error) {
2241
+ this.#patches.delete(node);
2242
+ throw error;
2243
+ }
2244
+ }
2245
+ [removeNoteBodyXml](note) {
2246
+ this.#assertOwnedElement(note);
2247
+ if (!this.#dialect || !["footnote", "endnote"].includes(note.localName) || note.namespace !== documentDialects[this.#dialect].w || this.root.localName !== note.localName + "s" || !activeXmlChildren(this, this.#budget)(this.root).includes(note) || this.#patches.has(note)) unsupported();
2248
+ this.assertShapeEditAllowed(note);
2249
+ const containers = new Set(this.compatibility[compatibilityContainers]), pending = [note];
2250
+ while (pending.length) {
2251
+ const node = pending.pop();
2252
+ this.#budget.charge("work", 1 + node.attributes.length);
2253
+ if (!containers.has(node) && (!this.#canEdit(node) || node.attributes.some((a) => !["http://www.w3.org/2000/xmlns/", "http://www.w3.org/XML/1998/namespace"].includes(a.namespace) && !this.#canEdit(a)))) unsupported();
2254
+ this.#budget.charge("retainedBytes", node.children.length * 8);
2255
+ for (const child of node.children) pending.push(child);
2256
+ }
2257
+ this.#stageReplacement(note, "", false, true);
2258
+ }
2259
+ /** Inserts admitted markup at an owned child boundary, retaining source tokens. */
2260
+ [appendBodyBlocks](body, xml2) {
2261
+ if (typeof xml2 !== "string") throw new InputTypeError("Expected XML markup.");
2262
+ const children = activeXmlChildren(this, this.#budget);
2263
+ if (!this.#dialect || this.root.localName !== "document" || body.namespace !== this.root.namespace || body.localName !== "body" || !children(this.root).includes(body)) unsupported();
2264
+ const sections = children(body).filter((node) => node.namespace === body.namespace && node.localName === "sectPr");
2265
+ if (sections.length > 1) unsupported();
2266
+ const section = sections[0], target = section ?? body;
2267
+ let path;
2268
+ const locate = (node, current) => {
2269
+ this.#budget.charge("work", 1);
2270
+ if (node === target) {
2271
+ path = current;
2272
+ return;
2273
+ }
2274
+ for (const [index, child] of node.children.entries()) {
2275
+ if (path) break;
2276
+ this.#budget.charge("retainedBytes", (current.length + 1) * 8);
2277
+ locate(child, [...current, index]);
2278
+ }
2279
+ };
2280
+ locate(this.root, []);
2281
+ if (!path) unsupported();
2282
+ const insertionPath = section ? path : [...path, body.children.length];
2283
+ let parent = this.root;
2284
+ for (const index of insertionPath.slice(0, -1)) parent = parent.children[index];
2285
+ this.#stageInsertion(parent, xml2, section);
2286
+ return insertionPath;
2287
+ }
2288
+ [insertParagraphBefore](paragraph, xml2) {
2289
+ if (typeof xml2 !== "string") throw new InputTypeError("Expected XML markup.");
2290
+ this.#assertOwnedElement(paragraph);
2291
+ if (!this.#dialect || paragraph.namespace !== documentDialects[this.#dialect].w || paragraph.localName !== "p" || !this.#canEdit(paragraph)) unsupported();
2292
+ this.assertShapeEditAllowed(paragraph);
2293
+ const fragment = parseDocumentXml(new TextEncoder().encode(`<root>${xml2}</root>`), this.#limits, this.#budget);
2294
+ if (fragment.root.children.length !== 1 || fragment.root.children[0].namespace !== paragraph.namespace || fragment.root.children[0].localName !== "p" || fragment.root.content.some((node) => node.kind !== "element")) unsupported();
2295
+ let path;
2296
+ let parent;
2297
+ const locate = (node, current) => {
2298
+ this.#budget.charge("work", 1);
2299
+ for (const [index, child] of node.children.entries()) {
2300
+ this.#budget.charge("retainedBytes", (current.length + 1) * 8);
2301
+ if (child === paragraph) {
2302
+ path = [...current, index];
2303
+ parent = node;
2304
+ return;
2305
+ }
2306
+ locate(child, [...current, index]);
2307
+ if (path) return;
2308
+ }
2309
+ };
2310
+ locate(this.root, []);
2311
+ if (!path || !parent) unsupported();
2312
+ this.#stageInsertion(parent, xml2, paragraph, true);
2313
+ return path;
2314
+ }
2315
+ /** Insert beside an editable native anchor without rewriting its MCE carrier. */
2316
+ [insertParagraphAfter](paragraph, xml2, path) {
2317
+ if (typeof xml2 !== "string") throw new InputTypeError("Expected XML markup.");
2318
+ this.#assertOwnedElement(paragraph);
2319
+ if (!this.#dialect || paragraph.namespace !== documentDialects[this.#dialect].w || paragraph.localName !== "p" || !this.#canEdit(paragraph) || !path.length) unsupported();
2320
+ this.assertShapeEditAllowed(paragraph);
2321
+ const fragment = parseDocumentXml(new TextEncoder().encode(`<root>${xml2}</root>`), this.#limits, this.#budget);
2322
+ if (fragment.root.children.length !== 1 || fragment.root.children[0].namespace !== paragraph.namespace || fragment.root.children[0].localName !== "p" || fragment.root.content.some((node) => node.kind !== "element")) unsupported();
2323
+ let parent = this.root;
2324
+ for (const index2 of path.slice(0, -1)) {
2325
+ this.#budget.charge("work", 1);
2326
+ if (!Number.isSafeInteger(index2) || index2 < 0 || !parent.children[index2]) unsupported();
2327
+ parent = parent.children[index2];
2328
+ }
2329
+ const index = path.at(-1);
2330
+ if (!Number.isSafeInteger(index) || index < 0 || parent.children[index] !== paragraph) unsupported();
2331
+ this.#stageInsertion(parent, xml2, parent.children[index + 1], true);
2332
+ return [...path.slice(0, -1), index + 1];
2333
+ }
2334
+ /** Insert a typed row while retaining the physical boundary's original carrier. */
2335
+ [insertTableRowXml](row, xml2, before) {
2336
+ this.#assertOwnedElement(row);
2337
+ if (typeof xml2 !== "string" || !this.#dialect || row.namespace !== documentDialects[this.#dialect].w || row.localName !== "tr" || !this.#canEdit(row)) unsupported();
2338
+ this.assertShapeEditAllowed(row);
2339
+ const fragment = parseDocumentXml(new TextEncoder().encode(`<root>${xml2}</root>`), this.#limits, this.#budget);
2340
+ if (fragment.root.children.length !== 1 || fragment.root.children[0].namespace !== row.namespace || fragment.root.children[0].localName !== "tr" || fragment.root.content.some((item) => item.kind !== "element")) unsupported();
2341
+ const pending = [this.root];
2342
+ while (pending.length) {
2343
+ const parent = pending.pop();
2344
+ this.#budget.charge("work", 1 + parent.children.length);
2345
+ const index = parent.children.indexOf(row);
2346
+ if (index >= 0) {
2347
+ this.#stageInsertion(parent, xml2, before ? row : parent.children[index + 1], true);
2348
+ return;
2349
+ }
2350
+ for (const child of parent.children) pending.push(child);
2351
+ }
2352
+ unsupported();
2353
+ }
2354
+ [removeTableRowXml](table, row, markup) {
2355
+ this.#assertOwnedElement(table);
2356
+ this.#assertOwnedElement(row);
2357
+ if (typeof markup !== "string" || !this.#dialect || table.namespace !== documentDialects[this.#dialect].w || table.localName !== "tbl" || row.namespace !== table.namespace || row.localName !== "tr" || !this.#canEdit(table) || !this.#canEdit(row) || this.#patches.has(table)) unsupported();
2358
+ this.assertShapeEditAllowed(table);
2359
+ const containers = new Set(this.compatibility[compatibilityContainers]), pending = [row];
2360
+ while (pending.length) {
2361
+ const node = pending.pop();
2362
+ this.#budget.charge("work", 1 + node.attributes.length);
2363
+ if (!containers.has(node) && (!this.#canEdit(node) || node.attributes.some((a) => !["http://www.w3.org/2000/xmlns/", "http://www.w3.org/XML/1998/namespace"].includes(a.namespace) && !this.#canEdit(a)))) unsupported();
2364
+ for (const child of node.children) pending.push(child);
2365
+ }
2366
+ const expected = parseDocumentXml(new TextEncoder().encode(this.sourceXml(this.root, /* @__PURE__ */ new Map([[row, ""]]))), this.#limits, this.#budget);
2367
+ const candidate = parseDocumentXml(new TextEncoder().encode(this.sourceXml(this.root, /* @__PURE__ */ new Map([[table, markup]]))), this.#limits, this.#budget);
2368
+ if (opaqueXmlContent(expected.root, this.#budget, this.#profile) !== opaqueXmlContent(candidate.root, this.#budget, this.#profile)) unsupported();
2369
+ this.#stageReplacement(table, markup, false, true);
2370
+ }
2371
+ /** Inserts admitted markup at an owned child boundary, retaining source tokens. */
2372
+ insertChildren(parent, xml2, before) {
2373
+ if (typeof xml2 !== "string") throw new InputTypeError("Expected XML markup.");
2374
+ this.#assertOwnedElement(parent);
2375
+ if (before !== void 0) this.#assertOwnedElement(before);
2376
+ if (before && !parent.children.includes(before)) unsupported();
2377
+ if (this.#guardCompatibility && !this.#canEdit(parent)) unsupported();
2378
+ this.assertShapeEditAllowed(parent);
2379
+ this.#stageInsertion(parent, xml2, before, true);
2380
+ }
2381
+ #stageInsertion(parent, xml2, before, checkMath = false) {
2382
+ const span = this.#spans.get(parent);
2383
+ const offset = before ? this.#spans.get(before).start : span.contentEnd;
2384
+ const prefix = this.#source.slice(span.start, offset);
2385
+ const suffix = this.#source.slice(offset, span.end);
2386
+ const patch = span.empty ? prefix + ">" + xml2 + `</${parent.name}>` : prefix + xml2 + suffix;
2387
+ this.#budget.charge("retainedBytes", patch.length * 8);
2388
+ this.#budget.charge("work", patch.length * 4);
2389
+ if (this.#patches.has(parent)) unsupported();
2390
+ this.#patches.set(parent, patch);
2391
+ try {
2392
+ const serialized = this.serialize();
2393
+ if (this.#dialect && this.root.localName === "styles" || this.#budget[documentXmlCache].immutableRoots?.has(this.root)) {
2394
+ const cache = this.#budget[documentXmlCache];
2395
+ cache.staged ??= /* @__PURE__ */ new WeakSet();
2396
+ cache.staged.add(serialized);
2397
+ }
2398
+ const candidate = parseDocumentXml(serialized, this.#limits, this.#budget);
2399
+ if (this.#dialect) validateXmlDialect(candidate.root, this.#dialect, this.#profile, this.#budget);
2400
+ const inserted = parseDocumentXml(new TextEncoder().encode(`<root>${xml2}</root>`), this.#limits, this.#budget);
2401
+ if (checkMath && containsMath(inserted.root, this.#budget)) unsupported();
2402
+ const count = (node) => node.kind === "element" ? 1 + node.content.reduce((n, child) => n + count(child), 0) : 1;
2403
+ this.#budget.charge("insertedNodes", inserted.root.content.reduce((n, node) => n + count(node), 0));
2404
+ } catch (error) {
2405
+ this.#patches.delete(parent);
2406
+ throw error;
2407
+ }
2408
+ }
2409
+ setText(node, text) {
2410
+ if (typeof text !== "string") throw new InputTypeError("Expected an XML text string.");
2411
+ if (!node || typeof node !== "object" || !["element", "text", "cdata", "comment", "processing-instruction"].includes(node.kind)) throw new InputTypeError("Expected an XML content node.");
2412
+ if (!this.#spans.has(node)) throw new OwnershipError("Expected content owned by this XML editor.");
2413
+ if (node.kind === "element") unsupported();
2414
+ if (node.kind !== "text" && text.includes("\r")) unsupported();
2415
+ if (node.kind === "cdata" && text.includes("]]>")) unsupported();
2416
+ if (node.kind === "comment" && (text.includes("--") || text.endsWith("-"))) unsupported();
2417
+ if (node.kind === "processing-instruction" && (text.includes("?>") || text.length && " \n".includes(text[0]))) unsupported();
2418
+ this.#stage(node, text, node.text, node.kind === "text");
2419
+ }
2420
+ setAttribute(element, name, value) {
2421
+ if (typeof name !== "string" && (!name || typeof name !== "object" || Array.isArray(name) || typeof name.namespace !== "string" || typeof name.localName !== "string" || Object.keys(name).some((key) => key !== "namespace" && key !== "localName")) || typeof value !== "string")
2422
+ throw new InputTypeError("Expected an XML attribute name or expanded name and string value.");
2423
+ this.#assertOwnedElement(element);
2424
+ const attribute = element.attributes.find((item) => typeof name === "string" ? item.name === name : item.namespace === name.namespace && item.localName === name.localName);
2425
+ if (!attribute || attribute.namespace === "http://www.w3.org/2000/xmlns/") unsupported();
2426
+ this.#stage(attribute, value, attribute.value, true);
2427
+ }
2428
+ /** Leading scalar XML text, retaining every child and non-text token. */
2429
+ setLeadingText(element, value) {
2430
+ this.#assertOwnedEdit(element);
2431
+ const leading = [];
2432
+ for (const token of element.content) {
2433
+ if (token.kind !== "text" && token.kind !== "cdata") break;
2434
+ leading.push(token);
2435
+ }
2436
+ if (this.#guardCompatibility && leading.some((token) => !this.#canEdit(token))) unsupported();
2437
+ const span = this.#spans.get(element);
2438
+ const end = leading.length ? this.#spans.get(leading.at(-1)).end + (leading.at(-1).kind === "cdata" ? 3 : 0) : span.contentStart;
2439
+ const patch = this.#source.slice(span.start, span.contentStart) + (span.empty ? ">" : "") + escapeValue(value ?? "", false) + (span.empty ? `</${element.name}>` : this.#source.slice(end, span.end));
2440
+ this.#acceptOwnedPatch(element, patch, value ? 1 : 0);
2441
+ }
2442
+ /** Tail text is owned by the containing element, never by an external resource. */
2443
+ setElementTail(element, value) {
2444
+ this.#assertOwnedElement(element);
2445
+ const parent = [...this.#elements].find((node) => node.children.includes(element));
2446
+ const owner = parent ?? element;
2447
+ this.#assertOwnedEdit(owner);
2448
+ const content = parent?.content ?? this.root.epilog ?? [];
2449
+ const index = parent ? content.indexOf(element) + 1 : 0;
2450
+ let end = this.#spans.get(element).end;
2451
+ for (let offset = index; offset < content.length; offset++) {
2452
+ const token = content[offset];
2453
+ if (token.kind !== "text" && token.kind !== "cdata") break;
2454
+ if (parent && this.#guardCompatibility && !this.#canEdit(token)) unsupported();
2455
+ end = this.#spans.get(token).end + (token.kind === "cdata" ? 3 : 0);
2456
+ }
2457
+ if (!parent) {
2458
+ if (end !== this.#spans.get(element).end) {
2459
+ let first = true;
2460
+ for (const token of content) {
2461
+ if (token.kind !== "text") break;
2462
+ this.setText(token, first ? value ?? "" : "");
2463
+ first = false;
2464
+ }
2465
+ return;
2466
+ }
2467
+ if (!value) return;
2468
+ this.#acceptOwnedPatch(element, this.sourceXml(element) + escapeValue(value ?? "", false), value ? 1 : 0);
2469
+ return;
2470
+ }
2471
+ const span = this.#spans.get(parent);
2472
+ const start = this.#spans.get(element).end;
2473
+ this.#acceptOwnedPatch(parent, this.#source.slice(span.start, start) + escapeValue(value ?? "", false) + this.#source.slice(end, span.end), value ? 1 : 0);
2474
+ }
2475
+ /** Native frame dimensions may edit an active branch with empty alternatives. */
2476
+ [editInlineShapeExtentXml](inline, extent, axis, value) {
2477
+ this.#assertOwnedElement(inline);
2478
+ this.#assertOwnedElement(extent);
2479
+ if (!this.#dialect || this.#patches.size || !Number.isSafeInteger(value) || value < 0 || !["cx", "cy"].includes(axis)) unsupported();
2480
+ const ns = documentDialects[this.#dialect], children = activeXmlChildren(this, this.#budget);
2481
+ if (inline.namespace !== ns.wp || inline.localName !== "inline" || extent.children.length) unsupported();
2482
+ const frames = children(inline).filter((node) => node.namespace === ns.wp && node.localName === "extent");
2483
+ if (frames.length !== 1) unsupported();
2484
+ const transforms = [];
2485
+ const visit = (node) => {
2486
+ this.#budget.charge("work", 1);
2487
+ if (!this.#profile.understoodNamespaces.includes(node.namespace) || node.localName === "extLst") unsupported();
2488
+ if (node.namespace === ns.a && node.localName === "xfrm") transforms.push(...children(node).filter((child) => child.namespace === ns.a && child.localName === "ext"));
2489
+ for (const child of children(node)) visit(child);
2490
+ };
2491
+ if (extent !== frames[0] && (extent.namespace !== ns.a || extent.localName !== "ext")) unsupported();
2492
+ this.assertShapeEditAllowed(inline);
2493
+ if (this.#canEdit(extent)) {
2494
+ this.setQualifiedAttribute(extent, { namespace: "", localName: axis }, String(value));
2495
+ return;
2496
+ }
2497
+ visit(inline);
2498
+ if (transforms.length > 1 || extent !== frames[0] && transforms[0] !== extent) unsupported();
2499
+ const ownerSpan = this.#spans.get(inline), extentSpan = this.#spans.get(extent);
2500
+ let alternatives = 0;
2501
+ for (const branch of this.compatibility.branches) {
2502
+ this.#budget.charge("work", 1 + branch.alternateContent.children.length);
2503
+ const span = this.#spans.get(branch.alternateContent);
2504
+ if (!(span.start <= ownerSpan.start && ownerSpan.end <= span.end || ownerSpan.start <= span.start && span.end <= ownerSpan.end || span.start <= extentSpan.start && extentSpan.end <= span.end)) continue;
2505
+ alternatives++;
2506
+ if (!branch.selected || branch.alternateContent.children.some((node) => node !== branch.selected && node.children.length)) unsupported();
2507
+ }
2508
+ if (!alternatives) unsupported();
2509
+ for (const node of this.#elements) {
2510
+ this.#budget.charge("work", 1);
2511
+ const span = this.#spans.get(node);
2512
+ if (span.start > ownerSpan.start || ownerSpan.end > span.end) continue;
2513
+ if (node.namespace === mathNamespace(false) || node.namespace === mathNamespace(true) || node.namespace === ns.a && ["ext", "extLst"].includes(node.localName) || node.namespace === ns.w && ["pict", "object"].includes(node.localName)) unsupported();
2514
+ }
2515
+ const attributes = extent.attributes.filter((attribute) => attribute.namespace === "" && attribute.localName === axis);
2516
+ if (attributes.length !== 1) unsupported();
2517
+ const attributeSpan = this.#spans.get(attributes[0]);
2518
+ this.#stageReplacement(extent, this.#source.slice(extentSpan.start, attributeSpan.start) + String(value) + this.#source.slice(attributeSpan.end, extentSpan.end));
2519
+ }
2520
+ /** Qualified attribute insertion/removal preserves unrelated lexical shells. */
2521
+ setQualifiedAttribute(element, name, value) {
2522
+ this.#assertOwnedEdit(element);
2523
+ if (name.namespace === "http://www.w3.org/2000/xmlns/" || name.localName === "xmlns") unsupported();
2524
+ const existing = element.attributes.find((attribute) => attribute.namespace === name.namespace && attribute.localName === name.localName);
2525
+ const understood = this.#profile.understoodNamespaces.includes(name.namespace) || this.#profile.understoodElements?.some((node) => node.namespace === element.namespace && node.localName === element.localName && node.attributes.some((attribute) => attribute.namespace === name.namespace && attribute.localName === name.localName));
2526
+ if (existing && this.#guardCompatibility && !this.#canEdit(existing)) unsupported();
2527
+ if (!existing && this.#guardCompatibility && !understood) unsupported();
2528
+ if (!existing && value === null) return;
2529
+ if (existing && value !== null) {
2530
+ this.setAttribute(element, name, value);
2531
+ return;
2532
+ }
2533
+ if (existing?.value === value) return;
2534
+ const span = this.#spans.get(element);
2535
+ let patch;
2536
+ if (existing) {
2537
+ const attribute = this.#spans.get(existing);
2538
+ patch = value === null ? this.#source.slice(span.start, attribute.attributeStart) + this.#source.slice(attribute.attributeEnd, span.end) : this.#source.slice(span.start, attribute.start) + escapeValue(value, true) + this.#source.slice(attribute.end, span.end);
2539
+ } else {
2540
+ let prefix = "", declaration = "";
2541
+ if (name.namespace) {
2542
+ prefix = [...element.namespaces].find(([prefix2, namespace]) => prefix2 && namespace === name.namespace)?.[0] ?? "xv";
2543
+ if (!element.namespaces.has(prefix)) declaration = ` xmlns:${prefix}="${escapeValue(name.namespace, true)}"`;
2544
+ else if (element.namespaces.get(prefix) !== name.namespace) {
2545
+ while (element.namespaces.has(prefix)) prefix += "v";
2546
+ declaration = ` xmlns:${prefix}="${escapeValue(name.namespace, true)}"`;
2547
+ }
2548
+ }
2549
+ const offset = span.empty ? span.contentStart : span.contentStart - 1;
2550
+ patch = this.#source.slice(span.start, offset) + declaration + ` ${prefix ? prefix + ":" : ""}${name.localName}="${escapeValue(value, true)}"` + this.#source.slice(offset, span.end);
2551
+ }
2552
+ this.#acceptOwnedPatch(element, patch, existing ? 0 : 1);
2553
+ }
2554
+ #assertOwnedElement(element) {
2555
+ if (!element || typeof element !== "object" || element.kind !== "element") throw new InputTypeError("Expected an XML element.");
2556
+ if (!this.#elements.has(element)) throw new OwnershipError("Expected an element owned by this XML editor.");
2557
+ }
2558
+ #assertOwnedEdit(element) {
2559
+ this.#assertOwnedElement(element);
2560
+ if (this.#patches.size || this.#guardCompatibility && !this.#canEdit(element)) unsupported();
2561
+ this.assertShapeEditAllowed(element);
2562
+ }
2563
+ #acceptOwnedPatch(element, patch, inserted) {
2564
+ this.#budget.charge("work", patch.length * 4);
2565
+ this.#budget.charge("retainedBytes", patch.length * 8);
2566
+ this.#patches.set(element, patch);
2567
+ try {
2568
+ const serialized = this.serialize();
2569
+ if (this.#dialect && this.root.localName === "styles") {
2570
+ const cache = this.#budget[documentXmlCache];
2571
+ cache.staged ??= /* @__PURE__ */ new WeakSet();
2572
+ cache.staged.add(serialized);
2573
+ }
2574
+ const candidate = parseDocumentXml(serialized, this.#limits, this.#budget);
2575
+ if (this.#dialect) validateXmlDialect(candidate.root, this.#dialect, this.#profile, this.#budget);
2576
+ this.#budget.charge("insertedNodes", inserted);
2577
+ } catch (error) {
2578
+ this.#patches.delete(element);
2579
+ throw error;
2580
+ }
2581
+ }
2582
+ #stage(token, value, original, escape) {
2583
+ if (value.length > (this.#limits.maxBytes ?? Infinity))
2584
+ throw new ResourceLimitError("XML output byte limit exceeded.");
2585
+ this.#budget.charge("work", value.length * 8);
2586
+ this.#budget.charge("retainedBytes", value.length * 12);
2587
+ for (const char of value) {
2588
+ const point = char.codePointAt(0);
2589
+ if (!(point === 9 || point === 10 || point === 13 || point >= 32 && point <= 55295 || point >= 57344 && point <= 65533 || point >= 65536 && point <= 1114111))
2590
+ throw new InvalidXmlError("Invalid XML character in replacement value.");
2591
+ }
2592
+ if (value !== original && this.#guardCompatibility && !this.#canEdit(token) && !("kind" in token && token.kind === "text" && this.root.epilog?.includes(token))) unsupported();
2593
+ const owner = this.#spans.get(token).owner;
2594
+ const element = owner.kind === "element" ? owner : [...this.#elements].find((n) => n.content.includes(owner));
2595
+ if (element) this.assertShapeEditAllowed(element);
2596
+ const before = new Map(this.#patches);
2597
+ if (value === original) this.#patches.delete(token);
2598
+ else {
2599
+ let patch = escape ? escapeValue(value, !("kind" in token)) : value;
2600
+ if ("kind" in token && token.kind === "processing-instruction" && value && !" \r\n".includes(this.#source[this.#spans.get(token).start - 1])) patch = " " + patch;
2601
+ this.#patches.set(token, patch);
2602
+ }
2603
+ try {
2604
+ const candidate = parseDocumentXml(this.serialize(), this.#limits, this.#budget);
2605
+ if (this.#dialect && this.#patches.size) validateXmlDialect(candidate.root, this.#dialect, this.#profile, this.#budget);
2606
+ } catch (error) {
2607
+ this.#patches.clear();
2608
+ for (const [key, patch] of before) this.#patches.set(key, patch);
2609
+ throw error;
2610
+ }
2611
+ }
2612
+ serialize() {
2613
+ for (const [current, original] of this.#namespaces) {
2614
+ if (current.size !== original.size) unsupported();
2615
+ for (const [prefix, uri] of original) if (current.get(prefix) !== uri) unsupported();
2616
+ }
2617
+ if (!this.#patches.size) {
2618
+ this.#budget.charge("work", this.#document.bytes.length);
2619
+ this.#budget.charge("retainedBytes", this.#document.bytes.length);
2620
+ return new Uint8Array(this.#document.bytes);
2621
+ }
2622
+ const patches = [...this.#patches].map(([token, value]) => ({ ...this.#spans.get(token), value }));
2623
+ patches.sort((a, b) => a.start - b.start);
2624
+ const maxBytes = this.#limits.maxBytes ?? Infinity;
2625
+ let length = this.#source.length;
2626
+ for (const patch of patches) length += patch.value.length - (patch.end - patch.start);
2627
+ const utf8 = this.#document.encoding === "UTF-8";
2628
+ if (length * (utf8 ? 1 : 2) > maxBytes)
2629
+ throw new ResourceLimitError("XML output byte limit exceeded.");
2630
+ this.#budget.charge("retainedBytes", length * 8);
2631
+ this.#budget.charge("work", length * 4);
2632
+ const chunks = [];
2633
+ let offset = 0;
2634
+ for (const patch of patches) {
2635
+ if (patch.start < offset) unsupported();
2636
+ chunks.push(this.#source.slice(offset, patch.start), patch.value);
2637
+ offset = patch.end;
2638
+ }
2639
+ chunks.push(this.#source.slice(offset));
2640
+ const source = chunks.join("");
2641
+ let bytes;
2642
+ if (utf8) bytes = new TextEncoder().encode(source);
2643
+ else {
2644
+ bytes = new Uint8Array(source.length * 2);
2645
+ const view = new DataView(bytes.buffer);
2646
+ for (let index = 0; index < source.length; index++)
2647
+ view.setUint16(index * 2, source.charCodeAt(index), this.#document.encoding === "UTF-16LE");
2648
+ }
2649
+ if (bytes.length > maxBytes) throw new ResourceLimitError("XML output byte limit exceeded.");
2650
+ return bytes;
2651
+ }
2652
+ };
2653
+
2654
+ // packages/safe-bash-docx-engine/src/equation-fragments.ts
2655
+ var xml = "http://www.w3.org/XML/1998/namespace";
2656
+ var xmlns2 = "http://www.w3.org/2000/xmlns/";
2657
+ var mathNamespace = (strict) => strict ? "http://purl.oclc.org/ooxml/officeDocument/math" : "http://schemas.openxmlformats.org/officeDocument/2006/math";
2658
+ var expressions = ["r", "f", "m", "sSub"];
2659
+ function normalized(value) {
2660
+ let start = 0, end = value.length;
2661
+ while (start < end && " \r\n".includes(value[start])) start++;
2662
+ while (end > start && " \r\n".includes(value[end - 1])) end--;
2663
+ return value.slice(start, end);
2664
+ }
2665
+ var leaves = { type: { attribute: "val", required: true, values: ["bar", "skw", "lin", "noBar"] }, argSz: { attribute: "val", required: true, min: -2, max: 2 }, jc: { attribute: "val", values: ["left", "right", "center", "centerGroup"] }, scr: { attribute: "val", values: ["roman", "script", "fraktur", "double-struck", "sans-serif", "monospace"] }, sty: { attribute: "val", values: ["p", "b", "i", "bi"] }, lit: { attribute: "val", values: ["true", "false", "1", "0", "on", "off"] }, nor: { attribute: "val", values: ["true", "false", "1", "0", "on", "off"] }, aln: { attribute: "val", values: ["true", "false", "1", "0", "on", "off"] }, brk: { attribute: "alnAt", min: 1, max: 255 } };
2666
+ function integer(value, min, max) {
2667
+ const s = normalized(value);
2668
+ let i = s[0] === "+" || s[0] === "-" ? 1 : 0;
2669
+ if (i === s.length) return false;
2670
+ for (; i < s.length; i++) if (!"0123456789".includes(s[i])) return false;
2671
+ const n = Number(s);
2672
+ return Number.isSafeInteger(n) && n >= min && n <= max;
2673
+ }
2674
+ function inspectEquationFragment(root, namespace, budget, part = "", base = []) {
2675
+ const issues = [];
2676
+ const issue = (path) => {
2677
+ budget.charge("diagnosticBytes", 160 + part.length + path.length * 8);
2678
+ budget.charge("retainedBytes", 256 + path.length * 8);
2679
+ issues.push({ code: "opaque-equation-fragment", part, path: [...path], message: "Stored math is outside the bounded equation fragment grammar." });
2680
+ };
2681
+ const visit = (node, path) => {
2682
+ budget.charge("work", 1 + node.attributes.length + node.content.length);
2683
+ let valid = node.namespace === namespace;
2684
+ const names = node.children.map((n) => n.localName), optional = (property, allowed, minimum = 0) => {
2685
+ const offset = names[0] === property ? 1 : 0;
2686
+ return names.length - offset >= minimum && names.slice(offset).every((n) => allowed.includes(n));
2687
+ }, exact = (property, children) => {
2688
+ const offset = names[0] === property ? 1 : 0;
2689
+ return names.slice(offset).length === children.length && children.every((n, i) => names[i + offset] === n);
2690
+ };
2691
+ if (node.localName === "oMath") valid &&= names.every((n) => expressions.includes(n));
2692
+ else if (node.localName === "oMathPara") valid &&= optional("oMathParaPr", ["oMath"], 1);
2693
+ else if (node.localName === "r") valid &&= optional("rPr", ["t"]);
2694
+ else if (node.localName === "f") valid &&= exact("fPr", ["num", "den"]);
2695
+ else if (node.localName === "m") valid &&= optional("mPr", ["mr"], 1);
2696
+ else if (node.localName === "mr") valid &&= names.length > 0 && names.every((n) => n === "e");
2697
+ else if (node.localName === "sSub") valid &&= exact("sSubPr", ["e", "sub"]);
2698
+ else if (["num", "den", "e", "sub"].includes(node.localName)) valid &&= optional("argPr", expressions);
2699
+ else if (["mPr", "sSubPr", "t"].includes(node.localName)) valid &&= names.length === 0;
2700
+ else if (["argPr", "fPr", "oMathParaPr"].includes(node.localName)) {
2701
+ const child = { argPr: "argSz", fPr: "type", oMathParaPr: "jc" }[node.localName];
2702
+ valid &&= names.length <= 1 && names.every((n) => n === child);
2703
+ } else if (node.localName === "rPr") {
2704
+ const order3 = ["lit", "nor", "scr", "sty", "brk", "aln"];
2705
+ let previous = -1;
2706
+ valid &&= !names.includes("nor") || !names.some((n) => ["scr", "sty"].includes(n));
2707
+ for (const n of names) {
2708
+ const index = order3.indexOf(n);
2709
+ if (index <= previous) valid = false;
2710
+ previous = index;
2711
+ }
2712
+ } else if (leaves[node.localName]) valid &&= names.length === 0;
2713
+ else valid = false;
2714
+ for (const content of node.content) {
2715
+ if (content.kind === "element") continue;
2716
+ if (content.kind !== "text" && content.kind !== "cdata") valid = false;
2717
+ else if (node.localName !== "t" && normalized(content.text)) valid = false;
2718
+ }
2719
+ for (const attribute of node.attributes) {
2720
+ budget.charge("work", attribute.value.length);
2721
+ if (attribute.namespace === xmlns2) {
2722
+ if (attribute.value !== namespace && attribute.value !== xml) valid = false;
2723
+ continue;
2724
+ }
2725
+ if (node.localName === "t" && attribute.namespace === xml && attribute.localName === "space" && ["default", "preserve"].includes(attribute.value)) continue;
2726
+ const leaf2 = leaves[node.localName];
2727
+ if (!leaf2 || attribute.namespace !== namespace || attribute.localName !== leaf2.attribute) valid = false;
2728
+ else if (leaf2.values) {
2729
+ const value = ["lit", "nor", "aln"].includes(node.localName) ? normalized(attribute.value) : attribute.value;
2730
+ if (!leaf2.values.includes(value) || namespace === mathNamespace(true) && ["on", "off"].includes(value)) valid = false;
2731
+ } else if (!integer(attribute.value, leaf2.min, leaf2.max)) valid = false;
2732
+ }
2733
+ const leaf = leaves[node.localName];
2734
+ if (leaf?.required && !node.attributes.some((a) => a.namespace === namespace && a.localName === leaf.attribute)) valid = false;
2735
+ if (!valid) issue(path);
2736
+ node.children.forEach((child, i) => visit(child, [...path, i]));
2737
+ };
2738
+ if (root.namespace !== namespace || !["oMath", "oMathPara"].includes(root.localName)) issue(base);
2739
+ visit(root, base);
2740
+ return issues;
2741
+ }
2742
+ function admitEquationFragment(bytes, namespace, budget) {
2743
+ const parsed = parseDocumentXml(bytes, {}, budget), root = parsed.root;
2744
+ const framing = [...root.prolog ?? [], ...root.epilog ?? []];
2745
+ if (framing.some((n) => n.kind !== "text" && !(n.kind === "processing-instruction" && "target" in n && n.target === "xml") || n.kind === "text" && normalized(n.text)) || inspectEquationFragment(root, namespace, budget).length) throw new UnsupportedEditError("Equation fragment is outside the bounded grammar.");
2746
+ const editor = new DocumentXmlEditor(bytes, {}, void 0, budget);
2747
+ return { root, xml: editor.sourceXml(editor.root) };
2748
+ }
2749
+
2750
+ export {
2751
+ storedMeasure,
2752
+ activeXmlChildren,
2753
+ displayXml,
2754
+ opaqueXmlContent,
2755
+ mathNamespace,
2756
+ inspectEquationFragment,
2757
+ admitEquationFragment,
2758
+ revisionInfo,
2759
+ containsRevision,
2760
+ assertOutsideRevisionRanges,
2761
+ containsActiveTableHistory,
2762
+ assertFormattingHistoryEditable,
2763
+ paragraphTextHistory,
2764
+ collectShapeCarriers,
2765
+ UnsupportedEditError,
2766
+ replaceListPropertyXml,
2767
+ replaceCommentRangeXml,
2768
+ replaceNativeTabCollectionXml,
2769
+ sourceRootEnvelope,
2770
+ appendBodyBlocks,
2771
+ insertParagraphBefore,
2772
+ insertParagraphAfter,
2773
+ insertTableRowXml,
2774
+ removeTableRowXml,
2775
+ removeNoteBodyXml,
2776
+ replaceActiveStyleXml,
2777
+ insertActiveLatentStyles,
2778
+ editActiveRelationshipXml,
2779
+ editActivePropertyXml,
2780
+ replaceSplitTextRunXml,
2781
+ splitNativeTextRunXml,
2782
+ nativeElementSourceTokens,
2783
+ nativeXmlTriviaSource,
2784
+ nativeScalarTextSource,
2785
+ replaceSplitParagraphXml,
2786
+ copiedSplitParagraphProperties,
2787
+ editInlineShapeExtentXml,
2788
+ DocumentXmlEditor,
2789
+ underline,
2790
+ highlights,
2791
+ themes,
2792
+ runElementOpen,
2793
+ formattedRunProperties,
2794
+ equivalentRunKey,
2795
+ styleChild,
2796
+ styleAttribute,
2797
+ styleIds,
2798
+ styleToggle,
2799
+ styleInteger,
2800
+ readStyleProperties,
2801
+ inheritStyleProperties,
2802
+ mergeStyleChildren,
2803
+ styleDisplayName,
2804
+ styleStoredName,
2805
+ selectNamedStyles,
2806
+ xmlValue,
2807
+ twips,
2808
+ pageGeometry,
2809
+ renderContent,
2810
+ renderTheme,
2811
+ paragraphUnits,
2812
+ alignments,
2813
+ tabAlignmentXml,
2814
+ paragraphLineMultiples,
2815
+ newTabStopXml,
2816
+ paragraphProperties
2817
+ };