@poe-platform/safe-bash 0.1.809 → 0.1.811

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 (316) hide show
  1. package/dist/audio-ast/flac-source.d.ts +13 -0
  2. package/dist/audio-ast/index.d.ts +2 -1
  3. package/dist/audio-ast/index.js +254 -179
  4. package/dist/audio-ast/wav-source.d.ts +7 -1
  5. package/dist/image-ast/index.js +1 -1
  6. package/dist/json-ast/backed-json-parser.d.ts +12 -1
  7. package/dist/json-ast/index.d.ts +1 -1
  8. package/dist/office-xml/index.d.ts +1 -0
  9. package/dist/office-xml/retained-xml-edits.d.ts +22 -0
  10. package/dist/pdf-ast/cos/mutable-object-store.d.ts +3 -0
  11. package/dist/pdf-ast/cos/qpdf-json-document.d.ts +43 -0
  12. package/dist/pdf-ast/cos/qpdf-json-values.d.ts +7 -0
  13. package/dist/pdf-ast/index.d.ts +1 -0
  14. package/dist/pdf-ast/index.js +653 -87
  15. package/dist/pdf-ast/retained-document.d.ts +5 -1
  16. package/dist/safe-bash/audio-ast.browser.js +2 -1
  17. package/dist/safe-bash/chunks/{chunk-RQCK77SC.js → chunk-BUYRKFW2.js} +9 -36
  18. package/dist/safe-bash/chunks/{chunk-SOFBGDXG.js → chunk-HHSOUC3Z.js} +32 -0
  19. package/dist/safe-bash/chunks/{chunk-WAZEELYB.js → chunk-TPG55BAQ.js} +10 -7
  20. package/dist/safe-bash/command-chunks/biff-3EFLKBAH-NYWZOYQS.js +4942 -0
  21. package/dist/safe-bash/command-chunks/{chunk-HEHGHIE2.js → chunk-22MOB45U.js} +6 -6
  22. package/dist/safe-bash/command-chunks/{chunk-6DEWZMOL.js → chunk-2CORNDGF.js} +2 -2
  23. package/dist/safe-bash/command-chunks/{chunk-62ZAHKFS.js → chunk-2VCKUNDZ.js} +130 -14
  24. package/dist/safe-bash/command-chunks/{chunk-6UHGIWFX.js → chunk-2ZFLMWOX.js} +1 -1
  25. package/dist/safe-bash/command-chunks/{chunk-HONWGFDA.js → chunk-33YCKZZX.js} +6 -6
  26. package/dist/safe-bash/command-chunks/{chunk-AXWPJRY6.js → chunk-36XGIPOG.js} +1 -1
  27. package/dist/safe-bash/command-chunks/{chunk-32ADKP5E.js → chunk-456PHA3L.js} +1 -1
  28. package/dist/safe-bash/command-chunks/{chunk-UJXP3T6R.js → chunk-4CKFNXRN.js} +1 -1
  29. package/dist/safe-bash/command-chunks/{chunk-5L6GHFRW.js → chunk-554Z6IKP.js} +2 -2
  30. package/dist/safe-bash/command-chunks/{chunk-ORZRWT62.js → chunk-56NYSX65.js} +9 -9
  31. package/dist/safe-bash/command-chunks/{chunk-53JP3S6H.js → chunk-5HPU7D36.js} +4 -4
  32. package/dist/safe-bash/command-chunks/{chunk-NB7JO7FE.js → chunk-5LI2DLNZ.js} +26 -26
  33. package/dist/safe-bash/command-chunks/{chunk-YJJBGN7U.js → chunk-5MB64DWR.js} +9 -9
  34. package/dist/safe-bash/command-chunks/{chunk-3ZWBBS6U.js → chunk-5OO2P27R.js} +340 -34
  35. package/dist/safe-bash/command-chunks/{chunk-IC5GJI7E.js → chunk-5Q22ZLNC.js} +6 -6
  36. package/dist/safe-bash/command-chunks/{chunk-YO3V5RLY.js → chunk-6CCQI6XZ.js} +12 -12
  37. package/dist/safe-bash/command-chunks/{chunk-EO2IVGV7.js → chunk-6M6TM5Z5.js} +3 -3
  38. package/dist/safe-bash/command-chunks/{chunk-Z54Z3KRN.js → chunk-6QBMND4A.js} +1 -1
  39. package/dist/safe-bash/command-chunks/{chunk-INX4JMQ6.js → chunk-6VPQ3CDZ.js} +5 -5
  40. package/dist/safe-bash/command-chunks/chunk-72C3TZ2U.js +826 -0
  41. package/dist/safe-bash/command-chunks/{chunk-VGXVN3BX.js → chunk-7GKKMNL6.js} +8 -8
  42. package/dist/safe-bash/command-chunks/{chunk-TZJC67W3.js → chunk-7PVHO47B.js} +6 -6
  43. package/dist/safe-bash/command-chunks/{chunk-CM3C7AXJ.js → chunk-A2CLZMQZ.js} +1 -1
  44. package/dist/safe-bash/command-chunks/{chunk-ASR27KHW.js → chunk-A5FZBR7X.js} +4 -4
  45. package/dist/safe-bash/command-chunks/{chunk-DMDHE5KC.js → chunk-AHA6IWAJ.js} +6 -6
  46. package/dist/safe-bash/command-chunks/{chunk-PTZ55XXN.js → chunk-APEWTWCC.js} +6 -6
  47. package/dist/safe-bash/command-chunks/{chunk-YUVH6CE4.js → chunk-ATTWQVR2.js} +17 -17
  48. package/dist/safe-bash/command-chunks/{chunk-JON5DB3Z.js → chunk-B5LDP7AA.js} +2 -2
  49. package/dist/safe-bash/command-chunks/{chunk-CHJL6JMU.js → chunk-COKYZUBW.js} +1 -1
  50. package/dist/safe-bash/command-chunks/{chunk-KCTV4NVX.js → chunk-CRV2Q3PB.js} +1 -1
  51. package/dist/safe-bash/command-chunks/{chunk-V3WXPCKN.js → chunk-CV7M2QJU.js} +7 -7
  52. package/dist/safe-bash/command-chunks/{chunk-D7XBUF76.js → chunk-D2ASPM7R.js} +109 -23
  53. package/dist/safe-bash/command-chunks/{chunk-VPDSQPSN.js → chunk-DM2CPMB4.js} +2 -2
  54. package/dist/safe-bash/command-chunks/{chunk-3DTDMEOP.js → chunk-EAGIJ4VW.js} +1 -1
  55. package/dist/safe-bash/command-chunks/{chunk-WFDG3N5R.js → chunk-ECDEPKKW.js} +1 -1
  56. package/dist/safe-bash/command-chunks/{chunk-JW6CMBF2.js → chunk-EHSM5ZQS.js} +8 -8
  57. package/dist/safe-bash/command-chunks/{chunk-WIOH7ZQN.js → chunk-ENT3IV2G.js} +12 -12
  58. package/dist/safe-bash/command-chunks/{chunk-5IE4LJGB.js → chunk-EUT24Y5Z.js} +8 -8
  59. package/dist/safe-bash/command-chunks/{chunk-COKZFXHG.js → chunk-FIIAYCWS.js} +2 -2
  60. package/dist/safe-bash/command-chunks/{chunk-MWVFP2HY.js → chunk-GEM47B2P.js} +7 -7
  61. package/dist/safe-bash/command-chunks/{chunk-OQCJGUI6.js → chunk-HARUYHH7.js} +10 -10
  62. package/dist/safe-bash/command-chunks/{chunk-EHL6B34L.js → chunk-HDJVJTCK.js} +9 -9
  63. package/dist/safe-bash/command-chunks/{chunk-JMM3MNAY.js → chunk-HKATEVAP.js} +6 -6
  64. package/dist/safe-bash/command-chunks/{chunk-NVBUC644.js → chunk-HKGNBH7Z.js} +2 -2
  65. package/dist/safe-bash/command-chunks/{chunk-VWY3EAVQ.js → chunk-HTVIYLVB.js} +4 -4
  66. package/dist/safe-bash/command-chunks/{chunk-Z4QJMDK3.js → chunk-IT7TAC3F.js} +16 -16
  67. package/dist/safe-bash/command-chunks/{chunk-EWS4KYJE.js → chunk-JFYWVQ4V.js} +8 -8
  68. package/dist/safe-bash/command-chunks/{chunk-ZCX63QWA.js → chunk-JOCFI7TG.js} +1 -1
  69. package/dist/safe-bash/command-chunks/{chunk-F5WTH4O4.js → chunk-JQVHUSDD.js} +5 -5
  70. package/dist/safe-bash/command-chunks/{chunk-O4VJEGL6.js → chunk-K5GB2YMN.js} +10 -10
  71. package/dist/safe-bash/command-chunks/{chunk-27C3NT5V.js → chunk-KB7DUBVL.js} +5 -5
  72. package/dist/safe-bash/command-chunks/{chunk-4DZ32PI7.js → chunk-KCOJA7EM.js} +7 -7
  73. package/dist/safe-bash/command-chunks/{chunk-6OKH4X67.js → chunk-KJ4XXZIL.js} +273 -10
  74. package/dist/safe-bash/command-chunks/{chunk-GLVD3JJG.js → chunk-KL3OIBKB.js} +4712 -4654
  75. package/dist/safe-bash/command-chunks/{chunk-U6QHTC5J.js → chunk-L5MCW6CM.js} +4 -4
  76. package/dist/safe-bash/command-chunks/{chunk-LVL3A7YE.js → chunk-LCZDBW55.js} +5 -5
  77. package/dist/safe-bash/command-chunks/{chunk-DJVRDUCA.js → chunk-LXLLA4PM.js} +17 -17
  78. package/dist/safe-bash/command-chunks/{chunk-K7AGAS3K.js → chunk-M7QE2MN7.js} +6 -6
  79. package/dist/safe-bash/command-chunks/chunk-MGBHGZEX.js +12 -0
  80. package/dist/safe-bash/command-chunks/{chunk-SWT6ILF2.js → chunk-MPUHH2KR.js} +3 -3
  81. package/dist/safe-bash/command-chunks/{chunk-DC3OJLRB.js → chunk-NQDIT667.js} +5 -5
  82. package/dist/safe-bash/command-chunks/{chunk-LWZVDDJA.js → chunk-NUGQQDGE.js} +5 -1
  83. package/dist/safe-bash/command-chunks/{chunk-MFLQZLFR.js → chunk-OA75SGN2.js} +7 -7
  84. package/dist/safe-bash/command-chunks/{chunk-5LATYOF7.js → chunk-OEJM666F.js} +5 -5
  85. package/dist/safe-bash/command-chunks/{chunk-AF25YYIO.js → chunk-PMAM4N33.js} +9 -9
  86. package/dist/safe-bash/command-chunks/{chunk-4557HE3J.js → chunk-PMWW7KSB.js} +161 -42
  87. package/dist/safe-bash/command-chunks/{chunk-KMMAJ6H6.js → chunk-PNGDJA6M.js} +2 -2
  88. package/dist/safe-bash/command-chunks/{chunk-62BHPSKJ.js → chunk-Q6S57NOQ.js} +7 -7
  89. package/dist/safe-bash/command-chunks/{chunk-KJ3PEDI2.js → chunk-Q73EMLLZ.js} +146 -4
  90. package/dist/safe-bash/command-chunks/{chunk-FXKBM5KJ.js → chunk-QC5RMGSA.js} +3 -3
  91. package/dist/safe-bash/command-chunks/{chunk-UQ6UIZMM.js → chunk-QD7ZRDUN.js} +1 -1
  92. package/dist/safe-bash/command-chunks/{chunk-JHUYZZGV.js → chunk-QYMEASQ6.js} +4 -4
  93. package/dist/safe-bash/command-chunks/{chunk-3GY5VDIX.js → chunk-QZZ73J2O.js} +6 -6
  94. package/dist/safe-bash/command-chunks/{chunk-S2CYIGWH.js → chunk-R6EGGK5M.js} +7 -7
  95. package/dist/safe-bash/command-chunks/{chunk-7AVN3OBH.js → chunk-RHYJVTJO.js} +2 -2
  96. package/dist/safe-bash/command-chunks/{chunk-EWGDSO6U.js → chunk-RID6VYS3.js} +8 -8
  97. package/dist/safe-bash/command-chunks/{chunk-MMBRBANA.js → chunk-RNSKXOG3.js} +6 -6
  98. package/dist/safe-bash/command-chunks/{chunk-D3ZRZTY5.js → chunk-RQIQ75W5.js} +5 -5
  99. package/dist/safe-bash/command-chunks/{chunk-DWKQPLRT.js → chunk-RRL3Y562.js} +11 -11
  100. package/dist/safe-bash/command-chunks/{chunk-JW3KIZU6.js → chunk-RUXY7GN5.js} +1 -1
  101. package/dist/safe-bash/command-chunks/{chunk-NXCMXD74.js → chunk-S6R3IB36.js} +1 -1
  102. package/dist/safe-bash/command-chunks/{chunk-XUPKFHAQ.js → chunk-SDTPO2VV.js} +7 -7
  103. package/dist/safe-bash/command-chunks/{chunk-PIAGKRFW.js → chunk-SPLOIABU.js} +3 -3
  104. package/dist/safe-bash/command-chunks/{chunk-KELMIFVV.js → chunk-TI52LKLL.js} +1 -1
  105. package/dist/safe-bash/command-chunks/{chunk-WLTJDNSQ.js → chunk-TVH4JORU.js} +3 -3
  106. package/dist/safe-bash/command-chunks/{chunk-6XVMWFHD.js → chunk-TW73OXPR.js} +6 -6
  107. package/dist/safe-bash/command-chunks/{chunk-SFO43CID.js → chunk-UAXSE3XE.js} +5 -5
  108. package/dist/safe-bash/command-chunks/{chunk-K35BSUHO.js → chunk-UYWSIIUX.js} +7 -7
  109. package/dist/safe-bash/command-chunks/{chunk-JJQ72P3V.js → chunk-VCML4T5D.js} +1 -1
  110. package/dist/safe-bash/command-chunks/{chunk-DCD32BEY.js → chunk-VU3EQF7F.js} +91 -53
  111. package/dist/safe-bash/command-chunks/{chunk-2E2YEDVB.js → chunk-W5YSINXC.js} +6 -6
  112. package/dist/safe-bash/command-chunks/{chunk-EYNT4OEJ.js → chunk-WGG6G2KG.js} +7 -7
  113. package/dist/safe-bash/command-chunks/chunk-WH3TIOTS.js +326 -0
  114. package/dist/safe-bash/command-chunks/{chunk-DVQBZXMQ.js → chunk-WJCN2IXI.js} +2 -2
  115. package/dist/safe-bash/command-chunks/{chunk-45FI2IPY.js → chunk-WQ6ABTJU.js} +3 -6
  116. package/dist/safe-bash/command-chunks/{chunk-XBZ4ZWGL.js → chunk-WVMHRNXZ.js} +3 -3
  117. package/dist/safe-bash/command-chunks/{chunk-7GXUCQI4.js → chunk-WXRYDALR.js} +4 -4
  118. package/dist/safe-bash/command-chunks/{chunk-S4IIOSRA.js → chunk-X7FA7ZD5.js} +8 -8
  119. package/dist/safe-bash/command-chunks/{chunk-SFCERNHU.js → chunk-XPD636C4.js} +3 -3
  120. package/dist/safe-bash/command-chunks/{chunk-HYDWQLJ3.js → chunk-XRVKWGVQ.js} +6 -6
  121. package/dist/safe-bash/command-chunks/{chunk-3UJWHRK4.js → chunk-XVP6V5K3.js} +6 -6
  122. package/dist/safe-bash/command-chunks/{chunk-KTI3BULE.js → chunk-XZ2FWFNV.js} +6 -6
  123. package/dist/safe-bash/command-chunks/{chunk-QK3CHRGL.js → chunk-Y4EYCZFT.js} +10 -10
  124. package/dist/safe-bash/command-chunks/{chunk-GTWVMFBK.js → chunk-YORJDX4V.js} +4 -4
  125. package/dist/safe-bash/command-chunks/{chunk-H6F5SN2N.js → chunk-YSMNXMAO.js} +4 -4
  126. package/dist/safe-bash/command-chunks/{chunk-GKYCV6BU.js → chunk-YSY6R6AS.js} +493 -183
  127. package/dist/safe-bash/command-chunks/{chunk-SE5SJ4JT.js → chunk-Z2JW6M2D.js} +3 -3
  128. package/dist/safe-bash/command-chunks/{chunk-5HGEXQVD.js → chunk-ZHRGYR7B.js} +7 -7
  129. package/dist/safe-bash/command-chunks/{chunk-HQYFRQ5W.js → chunk-ZIIO6GRY.js} +7 -7
  130. package/dist/safe-bash/command-chunks/{chunk-NTRZMQZP.js → chunk-ZMHEGDU2.js} +2 -2
  131. package/dist/safe-bash/command-chunks/{chunk-EYBXHGA6.js → chunk-ZXR6LXV5.js} +2 -2
  132. package/dist/safe-bash/command-chunks/{command-engine-P5DFM4OU.js → command-engine-BEWABZ75.js} +10 -3
  133. package/dist/safe-bash/command-chunks/{engine-RU4OFLPO-CPLFYD67.js → engine-AXXFTGCL-QBQNBI6K.js} +1 -1
  134. package/dist/safe-bash/command-chunks/pdf-XHHFTOT4-UJJYOYJ2.js +573 -0
  135. package/dist/safe-bash/commands/audio/index.browser.js +2 -14
  136. package/dist/safe-bash/commands/diff-patch/index.js +0 -5
  137. package/dist/safe-bash/commands/diff3/index.js +0 -2
  138. package/dist/safe-bash/commands/ffprobe/index.browser.js +2 -5
  139. package/dist/safe-bash/commands/pandoc/index.browser.js +3 -1
  140. package/dist/safe-bash/commands/text.js +10 -1
  141. package/dist/safe-bash/core.d.ts +2 -2
  142. package/dist/safe-bash/core.js +2 -2
  143. package/dist/safe-bash/full-core.browser.js +18 -22
  144. package/dist/safe-bash/lazy-optional.d.ts +9 -0
  145. package/dist/safe-bash/lazy-optional.js +24 -0
  146. package/dist/safe-bash/plugins/index.browser.js +5 -3
  147. package/dist/safe-bash/plugins/index.js +3 -1
  148. package/dist/safe-bash/plugins/portable-commands.d.ts +1 -1
  149. package/dist/safe-bash/plugins/portable-commands.js +5 -3
  150. package/dist/safe-bash/registry-entry.browser.js +1 -1
  151. package/dist/safe-bash-command-apply-patch/apply.js +2 -2
  152. package/dist/safe-bash-command-apply-patch/index.js +2 -2
  153. package/dist/safe-bash-command-apply-patch/parser.d.ts +20 -1
  154. package/dist/safe-bash-command-apply-patch/parser.js +1 -1
  155. package/dist/safe-bash-command-diff/index.js +0 -2
  156. package/dist/safe-bash-command-diff3/index.js +830 -56
  157. package/dist/safe-bash-command-ffmpeg/index.js +1 -1
  158. package/dist/safe-bash-command-ffprobe/index.js +3 -2
  159. package/dist/safe-bash-command-ffprobe/media.js +3 -2
  160. package/dist/safe-bash-command-ffprobe/options.d.ts +15 -0
  161. package/dist/safe-bash-command-ffprobe/options.js +7 -0
  162. package/dist/safe-bash-command-html-to-markdown/index.js +75 -21
  163. package/dist/safe-bash-command-media/index.js +2 -2
  164. package/dist/safe-bash-command-media/plugin.js +1 -1
  165. package/dist/safe-bash-command-media/remote.js +2 -2
  166. package/dist/safe-bash-command-pandoc/command.js +8 -8
  167. package/dist/safe-bash-command-pandoc/execution.d.ts +2 -2
  168. package/dist/safe-bash-command-pandoc/index.d.ts +1 -1
  169. package/dist/safe-bash-command-pandoc/index.js +37 -37
  170. package/dist/safe-bash-command-pandoc/lua-filters.js +2 -2
  171. package/dist/safe-bash-command-pandoc/types.d.ts +17 -2
  172. package/dist/safe-bash-command-patch/index.js +2 -2
  173. package/dist/safe-bash-command-patch/patch-publication.d.ts +2 -2
  174. package/dist/safe-bash-command-patch/patch-publication.js +1 -1
  175. package/dist/safe-bash-command-patch/patch.js +2 -2
  176. package/dist/safe-bash-command-pdftk/index.js +616 -265
  177. package/dist/safe-bash-command-pptx/engine.js +1 -1
  178. package/dist/safe-bash-command-qpdf/index.js +115 -9
  179. package/dist/safe-bash-command-soffice/index.js +1 -1
  180. package/dist/safe-bash-command-ssconvert/index.js +2 -2
  181. package/dist/safe-bash-command-xmllint/index.js +137 -30
  182. package/dist/safe-bash-command-xq/index.js +45 -29
  183. package/dist/safe-bash-compression-engine/bounded-codec.js +2 -2
  184. package/dist/safe-bash-compression-engine/codec-loader.js +1 -1
  185. package/dist/safe-bash-compression-engine/files.js +5 -5
  186. package/dist/safe-bash-compression-engine/index.js +4 -4
  187. package/dist/safe-bash-compression-engine/operand.js +5 -5
  188. package/dist/safe-bash-compression-engine/stream.js +4 -4
  189. package/dist/safe-bash-compression-engine/zstd-decode.js +3 -3
  190. package/dist/safe-bash-media-engine/imagemagick.d.ts +2 -0
  191. package/dist/safe-bash-media-engine/index.js +162 -72
  192. package/dist/safe-bash-network-engine/body.d.ts +1 -0
  193. package/dist/safe-bash-network-engine/body.js +1 -1
  194. package/dist/safe-bash-network-engine/transfer.js +11 -3
  195. package/dist/safe-bash-presentation-engine/accessibility.js +30 -30
  196. package/dist/safe-bash-presentation-engine/animation-editing.js +15 -15
  197. package/dist/safe-bash-presentation-engine/animations.js +15 -15
  198. package/dist/safe-bash-presentation-engine/backgrounds.js +16 -16
  199. package/dist/safe-bash-presentation-engine/bytes.js +3 -3
  200. package/dist/safe-bash-presentation-engine/chart-editing.js +33 -33
  201. package/dist/safe-bash-presentation-engine/chart-object-operations.js +24 -24
  202. package/dist/safe-bash-presentation-engine/charts.js +30 -30
  203. package/dist/safe-bash-presentation-engine/command-placeholder.js +55 -54
  204. package/dist/safe-bash-presentation-engine/comments.js +16 -16
  205. package/dist/safe-bash-presentation-engine/connector-operations.js +31 -31
  206. package/dist/safe-bash-presentation-engine/connectors.js +28 -28
  207. package/dist/safe-bash-presentation-engine/content-types.js +4 -4
  208. package/dist/safe-bash-presentation-engine/creation.js +6 -6
  209. package/dist/safe-bash-presentation-engine/diff.js +31 -31
  210. package/dist/safe-bash-presentation-engine/drawing-format.js +19 -19
  211. package/dist/safe-bash-presentation-engine/drawing-operations.js +30 -30
  212. package/dist/safe-bash-presentation-engine/drawing-schema.js +20 -20
  213. package/dist/safe-bash-presentation-engine/equations.js +16 -16
  214. package/dist/safe-bash-presentation-engine/errors.js +2 -2
  215. package/dist/safe-bash-presentation-engine/fields.js +16 -16
  216. package/dist/safe-bash-presentation-engine/font-metrics.js +3 -3
  217. package/dist/safe-bash-presentation-engine/image-extraction.js +19 -19
  218. package/dist/safe-bash-presentation-engine/image-formatting.js +31 -31
  219. package/dist/safe-bash-presentation-engine/image-insertion.js +17 -17
  220. package/dist/safe-bash-presentation-engine/image-replacement.js +20 -20
  221. package/dist/safe-bash-presentation-engine/image-value.js +4 -4
  222. package/dist/safe-bash-presentation-engine/images.js +18 -18
  223. package/dist/safe-bash-presentation-engine/index.d.ts +2 -2
  224. package/dist/safe-bash-presentation-engine/index.js +100 -93
  225. package/dist/safe-bash-presentation-engine/layouts.js +15 -15
  226. package/dist/safe-bash-presentation-engine/length.js +3 -3
  227. package/dist/safe-bash-presentation-engine/links.js +15 -15
  228. package/dist/safe-bash-presentation-engine/masters.js +14 -14
  229. package/dist/safe-bash-presentation-engine/media-editing.js +23 -23
  230. package/dist/safe-bash-presentation-engine/media-extraction.js +16 -16
  231. package/dist/safe-bash-presentation-engine/media.js +15 -15
  232. package/dist/safe-bash-presentation-engine/memberships.js +14 -14
  233. package/dist/safe-bash-presentation-engine/notes.js +15 -15
  234. package/dist/safe-bash-presentation-engine/ole-enum.js +4 -4
  235. package/dist/safe-bash-presentation-engine/ole-insertion.js +19 -19
  236. package/dist/safe-bash-presentation-engine/opaque-objects.js +9 -9
  237. package/dist/safe-bash-presentation-engine/package-reader.js +5 -5
  238. package/dist/safe-bash-presentation-engine/package-tools.js +15 -15
  239. package/dist/safe-bash-presentation-engine/package-uri.js +3 -3
  240. package/dist/safe-bash-presentation-engine/package-writer.js +4 -4
  241. package/dist/safe-bash-presentation-engine/presentation-model.js +54 -53
  242. package/dist/safe-bash-presentation-engine/presentation-settings.js +13 -13
  243. package/dist/safe-bash-presentation-engine/properties.js +15 -15
  244. package/dist/safe-bash-presentation-engine/relationships.js +4 -4
  245. package/dist/safe-bash-presentation-engine/resource-limits.js +1 -1
  246. package/dist/safe-bash-presentation-engine/retained-inspection.js +12 -12
  247. package/dist/safe-bash-presentation-engine/retained-package.js +4 -4
  248. package/dist/safe-bash-presentation-engine/retained-slide-settings.d.ts +15 -0
  249. package/dist/safe-bash-presentation-engine/retained-text.js +19 -19
  250. package/dist/safe-bash-presentation-engine/retained-xml-parts.d.ts +26 -0
  251. package/dist/safe-bash-presentation-engine/sanitize.js +16 -16
  252. package/dist/safe-bash-presentation-engine/selectors.js +10 -10
  253. package/dist/safe-bash-presentation-engine/shape-groups.js +30 -30
  254. package/dist/safe-bash-presentation-engine/shape-operations.js +29 -29
  255. package/dist/safe-bash-presentation-engine/shape-path-operations.js +31 -31
  256. package/dist/safe-bash-presentation-engine/shape-paths.js +15 -15
  257. package/dist/safe-bash-presentation-engine/shape-presets.js +3 -3
  258. package/dist/safe-bash-presentation-engine/shape-selection.js +30 -30
  259. package/dist/safe-bash-presentation-engine/shape-transforms.js +17 -17
  260. package/dist/safe-bash-presentation-engine/shapes.js +26 -26
  261. package/dist/safe-bash-presentation-engine/slide-copy.js +16 -16
  262. package/dist/safe-bash-presentation-engine/slide-import.js +17 -17
  263. package/dist/safe-bash-presentation-engine/slide-merge-split.js +19 -19
  264. package/dist/safe-bash-presentation-engine/slide-model.js +42 -42
  265. package/dist/safe-bash-presentation-engine/slide-removal.js +17 -17
  266. package/dist/safe-bash-presentation-engine/slide-transfer-budget.js +9 -9
  267. package/dist/safe-bash-presentation-engine/slides.d.ts +2 -0
  268. package/dist/safe-bash-presentation-engine/slides.js +21 -16
  269. package/dist/safe-bash-presentation-engine/table-operations.js +32 -32
  270. package/dist/safe-bash-presentation-engine/table-spans.js +31 -31
  271. package/dist/safe-bash-presentation-engine/tables.js +30 -30
  272. package/dist/safe-bash-presentation-engine/tags.js +15 -15
  273. package/dist/safe-bash-presentation-engine/template-bindings.js +32 -32
  274. package/dist/safe-bash-presentation-engine/template-repeat.js +39 -39
  275. package/dist/safe-bash-presentation-engine/text-fitting.js +26 -26
  276. package/dist/safe-bash-presentation-engine/text-frames.js +26 -26
  277. package/dist/safe-bash-presentation-engine/text-paragraphs.js +26 -26
  278. package/dist/safe-bash-presentation-engine/text-reading.js +11 -11
  279. package/dist/safe-bash-presentation-engine/text-replacement.js +16 -16
  280. package/dist/safe-bash-presentation-engine/text-runs.js +19 -19
  281. package/dist/safe-bash-presentation-engine/themes.js +15 -15
  282. package/dist/safe-bash-presentation-engine/transitions.js +15 -15
  283. package/dist/safe-bash-presentation-engine/validation.js +9 -9
  284. package/dist/safe-bash-presentation-engine/xml-parts.d.ts +1 -0
  285. package/dist/safe-bash-presentation-engine/xml-parts.js +19 -13
  286. package/dist/safe-bash-presentation-engine/xml-view.js +3 -3
  287. package/dist/safe-bash-presentation-engine/xml.js +3 -3
  288. package/dist/safe-bash-xml-engine/document.js +1 -1
  289. package/dist/safe-bash-xml-engine/index.js +1 -1
  290. package/dist/safe-bash-xml-engine/json.d.ts +1 -0
  291. package/dist/safe-bash-xml-engine/json.js +203 -0
  292. package/dist/safe-bash-xml-engine/stored-json.d.ts +5 -0
  293. package/dist/spreadsheet-engine/rendering/print/bidi-runs.d.ts +5 -0
  294. package/dist/spreadsheet-engine/rendering/print/bidi-runs.js +35 -0
  295. package/dist/spreadsheet-engine/rendering/print/control-bidi.d.ts +8 -0
  296. package/dist/spreadsheet-engine/rendering/print/control-bidi.js +80 -0
  297. package/dist/spreadsheet-engine/rendering/print/tab-layout.d.ts +11 -0
  298. package/dist/spreadsheet-engine/rendering/print/tab-layout.js +15 -0
  299. package/dist/spreadsheet-engine/rendering/print/text-lines.d.ts +2 -2
  300. package/dist/spreadsheet-engine/rendering/print/text-lines.js +3 -3
  301. package/dist/spreadsheet-format-xls/biff-encrypted-properties.d.ts +5 -1
  302. package/dist/spreadsheet-format-xls/biff-encrypted-properties.js +151 -57
  303. package/dist/spreadsheet-format-xls/biff-encryption.d.ts +1 -1
  304. package/dist/spreadsheet-format-xls/biff-encryption.js +8 -3
  305. package/dist/spreadsheet-format-xls/biff-property-bytes.d.ts +4 -1
  306. package/dist/spreadsheet-format-xls/biff-property-bytes.js +3 -3
  307. package/dist/spreadsheet-format-xls/biff-range.js +1 -1
  308. package/dist/spreadsheet-format-xls/biff.js +11 -3
  309. package/package.json +6 -2
  310. package/dist/safe-bash/chunks/chunk-I2A5ZCPD.js +0 -17
  311. package/dist/safe-bash/chunks/chunk-PQTT2EZP.js +0 -8
  312. package/dist/safe-bash/command-chunks/biff-DS263V2K-2GP4GZT7.js +0 -4868
  313. package/dist/safe-bash/command-chunks/chunk-6ZFYWT3U.js +0 -581
  314. package/dist/safe-bash/command-chunks/chunk-S244SWDH.js +0 -153
  315. package/dist/safe-bash/command-chunks/pdf-T7AWYZGQ-KNAYJ7YF.js +0 -552
  316. /package/dist/safe-bash/command-chunks/{chunk-EMMSXKEJ.js → chunk-4Q4R3VZU.js} +0 -0
@@ -5,9 +5,11 @@ import {
5
5
  transformBytes
6
6
  } from "../safe-bash/command-chunks/chunk-E6SK3OU2.js";
7
7
  import {
8
+ BackedJson,
8
9
  indexJsonObjects,
10
+ parseBackedJson,
9
11
  readJsonNumber
10
- } from "../safe-bash/command-chunks/chunk-LWZVDDJA.js";
12
+ } from "../safe-bash/command-chunks/chunk-NUGQQDGE.js";
11
13
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
12
14
 
13
15
  // packages/pdf-ast/src/source.ts
@@ -31439,6 +31441,39 @@ function parseCosDocument(bytes, options = {}) {
31439
31441
  return drainWork(parseCosDocumentSteps(bytes, options));
31440
31442
  }
31441
31443
 
31444
+ // packages/pdf-ast/src/content/array-cursor.ts
31445
+ var PdfArrayCursor = class {
31446
+ constructor(array, state) {
31447
+ this.array = array;
31448
+ this.length = array.storedItems?.length ?? array.items.length;
31449
+ if (!Number.isSafeInteger(this.length) || this.length < 0) throw new RangeError("Invalid stored array length");
31450
+ this.position = state?.position ?? array.storedItems?.position ?? -1;
31451
+ this.index = state?.index ?? 0;
31452
+ }
31453
+ array;
31454
+ index = 0;
31455
+ position;
31456
+ length;
31457
+ snapshot() {
31458
+ return { array: this.array, index: this.index, position: this.position };
31459
+ }
31460
+ *next() {
31461
+ if (this.index === this.length) {
31462
+ if (this.array.storedItems && this.position !== -1) throw new Error("Invalid stored array terminator");
31463
+ return { done: true, value: void 0 };
31464
+ }
31465
+ let node = this.array.items[this.index];
31466
+ if (this.array.storedItems) {
31467
+ const reply = yield { kind: "array-item", items: this.array.storedItems, position: this.position };
31468
+ if (!reply || typeof reply !== "object" || reply.kind !== "array" || reply.items[0]?.kind !== "number" || !reply.items[1]) throw new TypeError("Expected a PDF array record");
31469
+ this.position = reply.items[0].value;
31470
+ node = reply.items[1];
31471
+ }
31472
+ this.index++;
31473
+ return { done: false, value: node };
31474
+ }
31475
+ };
31476
+
31442
31477
  // packages/pdf-ast/src/content/sampled-vertices.ts
31443
31478
  function* sampledVertices(size, domain, encode3, inputs, sampleCount) {
31444
31479
  const dimensions = Math.max(1, size.length), axes = [];
@@ -31476,22 +31511,30 @@ function* sampledVertices(size, domain, encode3, inputs, sampleCount) {
31476
31511
  }
31477
31512
 
31478
31513
  // packages/pdf-ast/src/content/annotations.ts
31479
- function* resolveNode(node) {
31514
+ function* resolveNode(node, arrayKey) {
31480
31515
  if (!node) return void 0;
31481
- const result = yield { kind: "resolve", node };
31482
- if (typeof result === "number" || typeof result === "boolean") throw new TypeError("Expected a PDF annotation object");
31516
+ const result = yield { kind: "resolve", node, ...arrayKey ? { arrayKey } : {} };
31517
+ if (typeof result === "number" || typeof result === "boolean" || result?.kind === "annotation-page-frame") throw new TypeError("Expected a PDF annotation object");
31483
31518
  return result;
31484
31519
  }
31485
31520
  function* resolveDict(node) {
31486
31521
  const result = yield* resolveNode(node);
31487
31522
  return result?.kind === "dict" ? result : void 0;
31488
31523
  }
31489
- function* resolveArray(node) {
31490
- const result = yield* resolveNode(node);
31524
+ function* resolveArray(node, arrayKey) {
31525
+ const result = yield* resolveNode(node, arrayKey);
31491
31526
  return result?.kind === "array" ? result : void 0;
31492
31527
  }
31528
+ function* visitChildren(array, visit) {
31529
+ const cursor = new PdfArrayCursor(array);
31530
+ for (let step = yield* cursor.next(); !step.done; step = yield* cursor.next()) {
31531
+ const found = yield* visit(step.value);
31532
+ if (found !== void 0) return found;
31533
+ }
31534
+ return void 0;
31535
+ }
31493
31536
  function* extractPageAnnotationSteps(pageDict, root, maxDepth = Infinity) {
31494
- const annotsArr = yield* resolveArray(dictGet(pageDict, "Annots"));
31537
+ const annotsArr = yield* resolveArray(dictGet(pageDict, "Annots"), "Annots");
31495
31538
  if (!annotsArr) return;
31496
31539
  function* resolveDestToPageNum(destNode, depth = 0) {
31497
31540
  if (!destNode || depth > 4) return void 0;
@@ -31540,12 +31583,10 @@ function* extractPageAnnotationSteps(pageDict, root, maxDepth = Infinity) {
31540
31583
  if (kStr === destName) return namesArr.items[i + 1];
31541
31584
  }
31542
31585
  }
31543
- const kidsArr = yield* resolveArray(dictGet(treeDict, "Kids"));
31586
+ const kidsArr = yield* resolveArray(dictGet(treeDict, "Kids"), "Kids");
31544
31587
  if (kidsArr) {
31545
- for (const kid of kidsArr.items) {
31546
- const res = yield* searchNameTree(kid, depth2 + 1);
31547
- if (res) return res;
31548
- }
31588
+ const found = yield* visitChildren(kidsArr, (kid) => searchNameTree(kid, depth2 + 1));
31589
+ if (found) return found;
31549
31590
  }
31550
31591
  return void 0;
31551
31592
  } finally {
@@ -31558,7 +31599,9 @@ function* extractPageAnnotationSteps(pageDict, root, maxDepth = Infinity) {
31558
31599
  }
31559
31600
  return void 0;
31560
31601
  }
31561
- for (const item of annotsArr.items) {
31602
+ const annotations = new PdfArrayCursor(annotsArr);
31603
+ for (let step = yield* annotations.next(); !step.done; step = yield* annotations.next()) {
31604
+ const item = step.value;
31562
31605
  const dict = yield* resolveDict(item);
31563
31606
  if (!dict) continue;
31564
31607
  const rectArr = yield* resolveArray(dictGet(dict, "Rect"));
@@ -31596,28 +31639,45 @@ function* extractPageAnnotationSteps(pageDict, root, maxDepth = Infinity) {
31596
31639
  }
31597
31640
  }
31598
31641
  function* annotationPageNumberSteps(root, reference, maxDepth = Infinity) {
31599
- let index2 = 0;
31600
- function* walk(node, depth = 0) {
31601
- if (!node) return void 0;
31642
+ let index2 = 0, depth = 0;
31643
+ const catalog = yield* resolveDict(root);
31644
+ let node = catalog ? dictGet(catalog, "Pages") : void 0;
31645
+ let cursor, cursorDepth = 0;
31646
+ while (true) {
31647
+ if (!node) {
31648
+ if (!cursor) {
31649
+ const frame = yield { kind: "pop-page-frame" };
31650
+ if (frame === void 0) return void 0;
31651
+ if (typeof frame !== "object" || frame.kind !== "annotation-page-frame") throw new TypeError("Expected an annotation page frame");
31652
+ cursor = new PdfArrayCursor(frame.cursor.array, frame.cursor);
31653
+ cursorDepth = frame.depth;
31654
+ }
31655
+ const step = yield* cursor.next();
31656
+ if (step.done) {
31657
+ cursor = void 0;
31658
+ continue;
31659
+ }
31660
+ node = step.value;
31661
+ depth = cursorDepth;
31662
+ if (!node) continue;
31663
+ }
31664
+ const current = node;
31665
+ node = void 0;
31602
31666
  if (depth > maxDepth) throw new PdfError("E_LIMIT", "PDF annotation page-tree depth limit exceeded");
31603
- if (node.kind === "ref" && !(yield { kind: "visit-page", reference: node })) return void 0;
31604
- const dict = yield* resolveDict(node);
31605
- if (!dict) return void 0;
31667
+ if (current.kind === "ref" && !(yield { kind: "visit-page", reference: current })) continue;
31668
+ const dict = yield* resolveDict(current);
31669
+ if (!dict) continue;
31606
31670
  const type = yield* resolveNode(dictGet(dict, "Type"));
31607
- const kids = yield* resolveArray(dictGet(dict, "Kids"));
31671
+ const kids = yield* resolveArray(dictGet(dict, "Kids"), "Kids");
31608
31672
  if (kids && (type?.kind !== "name" || type.decoded !== "Page")) {
31609
- for (const child of kids.items) {
31610
- const found = yield* walk(child, depth + 1);
31611
- if (found !== void 0) return found;
31612
- }
31673
+ if (cursor) yield { kind: "push-page-frame", frame: { kind: "annotation-page-frame", cursor: cursor.snapshot(), depth: cursorDepth } };
31674
+ cursor = new PdfArrayCursor(kids);
31675
+ cursorDepth = depth + 1;
31613
31676
  } else {
31614
31677
  index2++;
31615
- if (node.kind === "ref" && node.objectNumber === reference.objectNumber) return index2;
31678
+ if (current.kind === "ref" && current.objectNumber === reference.objectNumber) return index2;
31616
31679
  }
31617
- return void 0;
31618
31680
  }
31619
- const catalog = yield* resolveDict(root);
31620
- return yield* walk(catalog ? dictGet(catalog, "Pages") : void 0);
31621
31681
  }
31622
31682
 
31623
31683
  // packages/pdf-ast/src/fonts/stored-widths.ts
@@ -43877,11 +43937,16 @@ function evaluateContentStreamToDisplayList(params) {
43877
43937
  function extractPageAnnotations(cosDoc, pageDict) {
43878
43938
  function pageNumber(reference) {
43879
43939
  const visited = /* @__PURE__ */ new Set();
43940
+ const frames = [];
43880
43941
  const work2 = annotationPageNumberSteps(cosDoc.rootRef, reference);
43881
43942
  let step2 = work2.next();
43882
43943
  while (!step2.done) {
43883
43944
  const request = step2.value;
43884
43945
  if (request.kind === "resolve") step2 = work2.next(cosDoc.resolve(request.node));
43946
+ else if (request.kind === "push-page-frame") {
43947
+ frames.push(request.frame);
43948
+ step2 = work2.next();
43949
+ } else if (request.kind === "pop-page-frame") step2 = work2.next(frames.pop());
43885
43950
  else if (request.kind === "visit-page") {
43886
43951
  const number = request.reference.objectNumber, added = !visited.has(number);
43887
43952
  visited.add(number);
@@ -43916,8 +43981,8 @@ function* resolveDict3(node, arrayPathPrefix) {
43916
43981
  const value = yield* resolveNode2(node, arrayPathPrefix);
43917
43982
  return value?.kind === "dict" ? value : void 0;
43918
43983
  }
43919
- function* resolveArray3(node) {
43920
- const value = yield* resolveNode2(node);
43984
+ function* resolveArray3(node, arrayPathPrefix) {
43985
+ const value = yield* resolveNode2(node, arrayPathPrefix);
43921
43986
  return value?.kind === "array" ? value : void 0;
43922
43987
  }
43923
43988
  function* visible(node) {
@@ -43948,9 +44013,11 @@ function* preparePageAppearanceSteps(pageDict, pageRes, evalResourcesDict, hideA
43948
44013
  dictSet(evalResourcesDict, entry.key.decoded, entry.value);
43949
44014
  }
43950
44015
  }
43951
- const annotsArr = yield* resolveArray3(dictGet(pageDict, "Annots"));
43952
- if (!hideAnnotations && annotsArr && annotsArr.items.length > 0) {
43953
- for (const item of annotsArr.items) {
44016
+ const annotsArr = yield* resolveArray3(dictGet(pageDict, "Annots"), ["Annots"]);
44017
+ if (!hideAnnotations && annotsArr) {
44018
+ const annotations = new PdfArrayCursor(annotsArr);
44019
+ for (let step = yield* annotations.next(); !step.done; step = yield* annotations.next()) {
44020
+ const item = step.value;
43954
44021
  const annotDict = yield* resolveDict3(item);
43955
44022
  if (!annotDict) continue;
43956
44023
  const fNode = yield* resolveNode2(dictGet(annotDict, "F"));
@@ -57444,7 +57511,22 @@ var PdfMutableObjectStore = class {
57444
57511
  const parsed = await parseCosRangeValue(source, 0, { ...this.options, signal });
57445
57512
  if (!parsed.value) throw new PdfError("E_PARSE", "Missing mutable PDF value");
57446
57513
  const object = { objectNumber: number, generationNumber: generation, value: restoreStringFormats(parsed.value) };
57447
- if (!hasStream) return object;
57514
+ const stream = hasStream ? this.streamSnapshot(at, streamAt, length, hasStream) : void 0;
57515
+ return stream ? { ...object, stream } : object;
57516
+ }
57517
+ /** Borrow encoded stream bytes without parsing the object's dictionary. */
57518
+ getStream(number) {
57519
+ return this.operation(async () => {
57520
+ if (!Number.isSafeInteger(number) || number < 1) throw new RangeError("Invalid PDF object number");
57521
+ const at = await this.index.get(BigInt(number));
57522
+ if (at === void 0 || at === DELETED_OBJECT) return void 0;
57523
+ const bytes = await this.backing.read(Number(at), 64), record = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
57524
+ const flag = record.getFloat64(40);
57525
+ return flag ? this.streamSnapshot(Number(at), record.getFloat64(24), record.getFloat64(32), flag) : void 0;
57526
+ });
57527
+ }
57528
+ streamSnapshot(at, streamAt, length, flag) {
57529
+ const backing = this.backing, signal = this.signal;
57448
57530
  async function* chunks() {
57449
57531
  for (let offset = 0; offset < length; offset += 16384) {
57450
57532
  if (offset > 0 && offset % (16384 * 64) === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
@@ -57452,9 +57534,9 @@ var PdfMutableObjectStore = class {
57452
57534
  yield await backing.read(streamAt + offset, Math.min(16384, length - offset));
57453
57535
  }
57454
57536
  }
57455
- const stream = { length, chunks: { [Symbol.asyncIterator]: chunks }, decoded: hasStream === 2 };
57537
+ const stream = { length, chunks: { [Symbol.asyncIterator]: chunks }, decoded: flag === 2 };
57456
57538
  this.receipts.set(stream, at);
57457
- return { ...object, stream };
57539
+ return stream;
57458
57540
  }
57459
57541
  /** Remember successful decoding only while this stream snapshot is current. */
57460
57542
  markDecoded(object) {
@@ -59857,19 +59939,69 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
59857
59939
  ...arrayPathPrefix.length && arrays.storedStringKeys?.includes(arrayPathPrefix[arrayPathPrefix.length - 1]) ? { storeRootString: true } : {}
59858
59940
  };
59859
59941
  let reference;
59860
- const visited = /* @__PURE__ */ new Set();
59942
+ const visited = new PdfReferenceSet(this.storage, this.options.maxTraversalStagingBytes, this.options.signal);
59861
59943
  const maximum10 = this.options.maxRecursionDepth ?? 100;
59862
- while (node?.kind === "ref") {
59863
- if (visited.size >= maximum10) throw new PdfError("E_LIMIT", "PDF reference depth limit exceeded");
59864
- if (visited.has(node.objectNumber)) throw new PdfError("E_PARSE", "Circular PDF indirect reference");
59865
- visited.add(node.objectNumber);
59866
- reference = node;
59867
- const object = await this.objects.get(node.objectNumber, node.generationNumber, arrays);
59868
- this.assertOpen();
59869
- if (object?.stream) return { value: object.value, reference, stream: object.stream };
59870
- node = object?.value;
59944
+ let depth = 0, failed = false;
59945
+ try {
59946
+ while (node?.kind === "ref") {
59947
+ if (depth >= maximum10) throw new PdfError("E_LIMIT", "PDF reference depth limit exceeded");
59948
+ if (!await visited.add(node.objectNumber)) throw new PdfError("E_PARSE", "Circular PDF indirect reference");
59949
+ if (++depth % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
59950
+ this.assertOpen();
59951
+ reference = node;
59952
+ const object = await this.objects.get(node.objectNumber, node.generationNumber, arrays);
59953
+ this.assertOpen();
59954
+ if (object?.stream) return { value: object.value, reference, stream: object.stream };
59955
+ node = object?.value;
59956
+ }
59957
+ return node ? { value: node, ...reference ? { reference } : {} } : void 0;
59958
+ } catch (error) {
59959
+ failed = true;
59960
+ throw error;
59961
+ } finally {
59962
+ await visited.close().catch((error) => {
59963
+ if (!failed) throw error;
59964
+ });
59965
+ }
59966
+ }
59967
+ /** Visit page dictionaries in inheritance order using caller-backed cycle state. */
59968
+ pageAncestors(first) {
59969
+ async function* visit(doc) {
59970
+ doc.assertOpen();
59971
+ doc.walks.add(work);
59972
+ const visited = new PdfReferenceSet(doc.storage, doc.options.maxTraversalStagingBytes, doc.options.signal);
59973
+ let current = first, depth = 0, failed = false;
59974
+ try {
59975
+ while (current) {
59976
+ if (depth++ > doc.depthLimit) throw new PdfError("E_LIMIT", "PDF inherited page depth limit exceeded");
59977
+ if (depth % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
59978
+ doc.assertOpen();
59979
+ yield current;
59980
+ doc.assertOpen();
59981
+ const parent = dictGet(current, "Parent");
59982
+ if (parent?.kind === "ref" && !await visited.add(parent.objectNumber)) break;
59983
+ const resolved = (await doc.lookup(parent))?.value;
59984
+ current = resolved?.kind === "dict" ? resolved : void 0;
59985
+ }
59986
+ } catch (error) {
59987
+ failed = true;
59988
+ throw error;
59989
+ } finally {
59990
+ doc.walks.delete(work);
59991
+ await visited.close().catch((error) => {
59992
+ if (!failed) throw error;
59993
+ });
59994
+ }
59871
59995
  }
59872
- return node ? { value: node, ...reference ? { reference } : {} } : void 0;
59996
+ const work = visit(this);
59997
+ return work;
59998
+ }
59999
+ /** Read one caller-backed array record with document cancellation and ownership. */
60000
+ async readArrayItem(items, position) {
60001
+ this.assertOpen();
60002
+ const record = await readStoredRecord(items.storage, position, this.options.signal);
60003
+ this.assertOpen();
60004
+ return cosArray([cosNumber(record.next), record.value]);
59873
60005
  }
59874
60006
  async info() {
59875
60007
  const node = (await this.lookup(this.crossReference.infoRef))?.value;
@@ -59885,17 +60017,26 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
59885
60017
  async annotationPageNumber(reference) {
59886
60018
  this.assertOpen();
59887
60019
  const visited = new PdfReferenceSet(this.storage, this.options.maxTraversalStagingBytes, this.options.signal);
60020
+ const backing = this.options.valueArrays?.storedArrayKeys?.includes("Kids") ? this.options.valueArrays.arrayStorage : void 0;
60021
+ const frames = backing ? new StoredMetadataStack(backing, this.options.signal) : [];
59888
60022
  const work = annotationPageNumberSteps(this.crossReference.rootRef, reference, this.depthLimit);
59889
60023
  let failed = false;
59890
60024
  try {
59891
- let step = work.next();
60025
+ let step = work.next(), turns = 0;
59892
60026
  while (!step.done) {
60027
+ if (++turns % 256 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
59893
60028
  this.assertOpen();
59894
60029
  const request = step.value;
59895
60030
  if (request.kind === "resolve") {
59896
- const resolved = await this.lookup(request.node);
60031
+ const resolved = await this.lookup(request.node, void 0, request.arrayKey ? [request.arrayKey] : void 0);
59897
60032
  step = work.next(resolved?.stream && resolved.value.kind === "dict" ? { kind: "stream", dict: resolved.value, rawBytes: new Uint8Array() } : resolved?.value);
59898
- } else if (request.kind === "visit-page") step = work.next(await visited.add(request.reference.objectNumber));
60033
+ } else if (request.kind === "array-item") {
60034
+ step = work.next(await this.readArrayItem(request.items, request.position));
60035
+ } else if (request.kind === "push-page-frame") {
60036
+ await frames.push(request.frame);
60037
+ step = work.next();
60038
+ } else if (request.kind === "pop-page-frame") step = work.next(await frames.pop());
60039
+ else if (request.kind === "visit-page") step = work.next(await visited.add(request.reference.objectNumber));
59899
60040
  else throw new TypeError("Unexpected annotation page lookup request");
59900
60041
  }
59901
60042
  return step.value;
@@ -59916,21 +60057,50 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
59916
60057
  const visited = new PdfReferenceSet(doc.storage, doc.options.maxTraversalStagingBytes, doc.options.signal);
59917
60058
  let count = 0;
59918
60059
  let failed = false;
59919
- async function* walk(node, depth) {
59920
- doc.assertOpen();
59921
- if (!node) return;
59922
- if (depth > doc.depthLimit) throw new PdfError("E_LIMIT", "PDF page tree depth limit exceeded");
59923
- if (node.kind === "ref" && !await visited.add(node.objectNumber)) return;
59924
- const resolved = await doc.lookup(node);
59925
- if (resolved?.value.kind !== "dict") return;
59926
- const dict = resolved.value;
59927
- const type = (await doc.lookup(dictGet(dict, "Type")))?.value;
59928
- const kids = (await doc.lookup(dictGet(dict, "Kids")))?.value;
59929
- if (type?.kind === "name" && type.decoded === "Pages" || kids?.kind === "array") {
59930
- if (kids?.kind === "array") for (const kid of kids.items) yield* walk(kid, depth + 1);
59931
- } else if (type?.kind === "name" && type.decoded === "Page" || dictGet(dict, "MediaBox") || dictGet(dict, "Contents")) {
59932
- if (count >= Math.min(doc.options.maxPages, Number.MAX_SAFE_INTEGER)) throw new PdfError("E_LIMIT", "PDF page count limit exceeded");
59933
- yield new PdfRetainedPage(doc, count++, dict, node.kind === "ref" ? node : void 0);
60060
+ async function* walk(first) {
60061
+ const backing = doc.options.valueArrays?.storedArrayKeys?.includes("Kids") ? doc.options.valueArrays.arrayStorage : void 0;
60062
+ const frames = backing ? new StoredMetadataStack(backing, doc.options.signal) : [];
60063
+ let frame, node = first, depth = 0, turns = 0;
60064
+ while (true) {
60065
+ if (++turns % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
60066
+ doc.assertOpen();
60067
+ if (!node) {
60068
+ frame ??= await frames.pop();
60069
+ if (!frame) return;
60070
+ const stored = frame.kids.storedItems, length = stored?.length ?? frame.kids.items.length;
60071
+ if (!Number.isSafeInteger(length) || length < 0) throw new RangeError("Invalid stored array length");
60072
+ if (frame.index === length) {
60073
+ if (stored && frame.position !== -1) throw new Error("Invalid stored array terminator");
60074
+ frame = void 0;
60075
+ continue;
60076
+ }
60077
+ if (stored) {
60078
+ const record = await readStoredRecord(stored.storage, frame.position, doc.options.signal);
60079
+ frame.position = record.next;
60080
+ node = record.value;
60081
+ } else node = frame.kids.items[frame.index];
60082
+ frame.index++;
60083
+ depth = frame.depth;
60084
+ if (!node) continue;
60085
+ }
60086
+ const current = node;
60087
+ node = void 0;
60088
+ if (depth > doc.depthLimit) throw new PdfError("E_LIMIT", "PDF page tree depth limit exceeded");
60089
+ if (current.kind === "ref" && !await visited.add(current.objectNumber)) continue;
60090
+ const resolved = await doc.lookup(current);
60091
+ if (resolved?.value.kind !== "dict") continue;
60092
+ const dict = resolved.value;
60093
+ const type = (await doc.lookup(dictGet(dict, "Type")))?.value;
60094
+ const kids = (await doc.lookup(dictGet(dict, "Kids"), void 0, ["Kids"]))?.value;
60095
+ if (type?.kind === "name" && type.decoded === "Pages" || kids?.kind === "array") {
60096
+ if (kids?.kind === "array") {
60097
+ if (frame) await frames.push(frame);
60098
+ frame = { kids, index: 0, position: kids.storedItems?.position ?? -1, depth: depth + 1 };
60099
+ }
60100
+ } else if (type?.kind === "name" && type.decoded === "Page" || dictGet(dict, "MediaBox") || dictGet(dict, "Contents")) {
60101
+ if (count >= Math.min(doc.options.maxPages, Number.MAX_SAFE_INTEGER)) throw new PdfError("E_LIMIT", "PDF page count limit exceeded");
60102
+ yield new PdfRetainedPage(doc, count++, dict, current.kind === "ref" ? current : void 0);
60103
+ }
59934
60104
  }
59935
60105
  }
59936
60106
  try {
@@ -59944,7 +60114,7 @@ var PdfRetainedDocument = class _PdfRetainedDocument {
59944
60114
  }
59945
60115
  } else {
59946
60116
  const root = (await doc.lookup(doc.crossReference.rootRef))?.value;
59947
- if (root?.kind === "dict") yield* walk(dictGet(root, "Pages"), 0);
60117
+ if (root?.kind === "dict") yield* walk(dictGet(root, "Pages"));
59948
60118
  }
59949
60119
  } catch (error) {
59950
60120
  failed = true;
@@ -60175,11 +60345,7 @@ var PdfRetainedPage = class {
60175
60345
  const values = /* @__PURE__ */ new Map();
60176
60346
  const boxes = /* @__PURE__ */ new Map();
60177
60347
  const keys = ["MediaBox", "CropBox", "BleedBox", "TrimBox", "ArtBox", "Rotate", "Resources"];
60178
- let current = this.dict;
60179
- const visited = /* @__PURE__ */ new Set();
60180
- let depth = 0;
60181
- while (current) {
60182
- if (depth++ > this.document.depthLimit) throw new PdfError("E_LIMIT", "PDF inherited page depth limit exceeded");
60348
+ for await (const current of this.document.pageAncestors(this.dict)) {
60183
60349
  for (const key of keys) {
60184
60350
  const entry = dictGet(current, key);
60185
60351
  if (values.has(key) || !entry) continue;
@@ -60192,13 +60358,6 @@ var PdfRetainedPage = class {
60192
60358
  values.set(key, value);
60193
60359
  }
60194
60360
  if (values.size === keys.length) break;
60195
- const parent = dictGet(current, "Parent");
60196
- if (parent?.kind === "ref") {
60197
- if (visited.has(parent.objectNumber)) break;
60198
- visited.add(parent.objectNumber);
60199
- }
60200
- const resolved = (await this.document.lookup(parent))?.value;
60201
- current = resolved?.kind === "dict" ? resolved : void 0;
60202
60361
  }
60203
60362
  async function box(node, document2) {
60204
60363
  if (node?.kind !== "array" || node.items.length < 4) return void 0;
@@ -60301,14 +60460,17 @@ var PdfRetainedPage = class {
60301
60460
  async *annotations() {
60302
60461
  const work = extractPageAnnotationSteps(this.dict, this.document.crossReference.rootRef, this.document.depthLimit);
60303
60462
  try {
60304
- let step = work.next();
60463
+ let step = work.next(), turns = 0;
60305
60464
  while (!step.done) {
60465
+ if (++turns % 256 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
60306
60466
  const request = step.value;
60307
60467
  let result;
60308
60468
  if (request.kind === "annotation") yield request.annotation;
60309
60469
  else if (request.kind === "resolve") {
60310
- const resolved = await this.document.lookup(request.node);
60470
+ const resolved = await this.document.lookup(request.node, void 0, request.arrayKey ? [request.arrayKey] : void 0);
60311
60471
  result = resolved?.stream && resolved.value.kind === "dict" ? { kind: "stream", dict: resolved.value, rawBytes: new Uint8Array() } : resolved?.value;
60472
+ } else if (request.kind === "array-item") {
60473
+ result = await this.document.readArrayItem(request.items, request.position);
60312
60474
  } else if (request.kind === "page-number") result = await this.document.annotationPageNumber(request.reference);
60313
60475
  else throw new TypeError("Unexpected annotation request");
60314
60476
  step = work.next(result);
@@ -60319,13 +60481,22 @@ var PdfRetainedPage = class {
60319
60481
  }
60320
60482
  /** Preserve the buffered page API's newline after each content-array stream. */
60321
60483
  async *streamContents() {
60322
- const content = await this.document.lookup(dictGet(this.dict, "Contents"));
60484
+ const content = await this.document.lookup(dictGet(this.dict, "Contents"), void 0, ["Contents"]);
60323
60485
  if (content?.stream && content.reference) yield* this.document.objects.decodeStream(content.reference.objectNumber, content.reference.generationNumber);
60324
- else if (content?.value.kind === "array") for (const item of content.value.items) {
60325
- const stream = await this.document.lookup(item);
60326
- if (!stream?.stream || !stream.reference) continue;
60327
- yield* this.document.objects.decodeStream(stream.reference.objectNumber, stream.reference.generationNumber);
60328
- yield new Uint8Array([10]);
60486
+ else if (content?.value.kind === "array") {
60487
+ const cursor = new PdfArrayCursor(content.value);
60488
+ let turns = 0;
60489
+ while (true) {
60490
+ if (++turns % 256 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
60491
+ const work = cursor.next();
60492
+ let step = work.next();
60493
+ while (!step.done) step = work.next(await this.document.readArrayItem(step.value.items, step.value.position));
60494
+ if (step.value.done) break;
60495
+ const stream = await this.document.lookup(step.value.value);
60496
+ if (!stream?.stream || !stream.reference) continue;
60497
+ yield* this.document.objects.decodeStream(stream.reference.objectNumber, stream.reference.generationNumber);
60498
+ yield new Uint8Array([10]);
60499
+ }
60329
60500
  }
60330
60501
  }
60331
60502
  };
@@ -63291,6 +63462,7 @@ var QpdfJsonValues = class _QpdfJsonValues {
63291
63462
  scratch;
63292
63463
  first;
63293
63464
  next;
63465
+ sourceOrder;
63294
63466
  closed = false;
63295
63467
  work = 0;
63296
63468
  async cooperate(units = 1) {
@@ -63366,7 +63538,7 @@ var QpdfJsonValues = class _QpdfJsonValues {
63366
63538
  }
63367
63539
  }
63368
63540
  async index() {
63369
- const order = await indexJsonObjects(this.tree, this.scratch, (units) => this.cooperate(units));
63541
+ const order = this.sourceOrder = await indexJsonObjects(this.tree, this.scratch, (units) => this.cooperate(units));
63370
63542
  const pointer = async (at) => {
63371
63543
  const bytes = await this.scratch.read(at, 8);
63372
63544
  return new DataView(bytes.buffer, bytes.byteOffset, bytes.length).getFloat64(0, true);
@@ -63541,7 +63713,102 @@ var QpdfJsonValues = class _QpdfJsonValues {
63541
63713
  }
63542
63714
  yield encoder.encode(utf16 ? ">" : ")");
63543
63715
  }
63716
+ // JSON.parse removes duplicate JSON names before conversion, but decoded PDF
63717
+ // name collisions happen after each value is converted. Validate the former
63718
+ // view before emitting the latter so overwritten invalid numbers still fail.
63719
+ async validate(root) {
63720
+ let position = root;
63721
+ for (; ; ) {
63722
+ await this.cooperate();
63723
+ let header2 = await this.tree.describe(position);
63724
+ if (header2.kind === "object" || header2.kind === "array") {
63725
+ const child = header2.kind === "object" ? await this.sourceOrder.first(position) : header2.children ? position + 32 : 0;
63726
+ if (child) {
63727
+ position = child;
63728
+ continue;
63729
+ }
63730
+ } else if (header2.kind === "literal") {
63731
+ const token2 = await this.tree.smallText(position, 5);
63732
+ if (token2 !== "null" && token2 !== "true" && token2 !== "false") cosNumber(await readJsonNumber(this.text(position), (units) => this.cooperate(units), false));
63733
+ }
63734
+ for (; ; ) {
63735
+ if (position === root) return;
63736
+ await this.cooperate();
63737
+ const parent = await this.tree.describe(header2.parent);
63738
+ const next = parent.kind === "object" && header2.kind !== "key" ? await this.sourceOrder.next(position, header2.parent) : header2.end < parent.end ? header2.end : 0;
63739
+ if (next) {
63740
+ position = next;
63741
+ break;
63742
+ }
63743
+ position = header2.parent;
63744
+ header2 = parent;
63745
+ }
63746
+ }
63747
+ }
63748
+ /** Look up a converted PDF dictionary name, after prefix decoding/collisions. */
63749
+ async property(root, name) {
63750
+ if ((await this.tree.describe(root)).kind !== "object") return void 0;
63751
+ for (let key = Number(await this.first.get(BigInt(root)) ?? 0n); key; ) {
63752
+ await this.cooperate();
63753
+ const value = (await this.tree.describe(key)).end;
63754
+ if (await this.keyEquals(key, name)) return value;
63755
+ key = Number(await this.next.get(BigInt(value)) ?? 0n);
63756
+ }
63757
+ return void 0;
63758
+ }
63759
+ async keyEquals(key, name) {
63760
+ const text = await this.tree.smallText(key, name.length + 3);
63761
+ return text !== void 0 && text.slice(text.startsWith("n:/") ? 3 : text.startsWith("/") ? 1 : 0) === name;
63762
+ }
63763
+ /** Stream an imported stream dictionary with legacy filter/length handling. */
63764
+ async *streamDictionary(root, length) {
63765
+ if (!Number.isSafeInteger(length) || length < 0) throw new RangeError("Invalid PDF stream length");
63766
+ if (root !== void 0) await this.validate(root);
63767
+ const encoder = new TextEncoder();
63768
+ const object = root !== void 0 && (await this.tree.describe(root)).kind === "object";
63769
+ let strip = false;
63770
+ if (object) {
63771
+ const filter = await this.property(root, "Filter");
63772
+ const recognized = async (position) => {
63773
+ if ((await this.tree.describe(position)).kind !== "string") return false;
63774
+ const text = await this.tree.smallText(position, 32);
63775
+ if (text === void 0) return false;
63776
+ const skip = text.startsWith("n:/") ? 3 : text.startsWith("n:") ? 2 : text.startsWith("/") ? 1 : 0;
63777
+ return skip > 0 && ["FlateDecode", "ASCIIHexDecode", "ASCII85Decode", "LZWDecode", "RunLengthDecode"].includes(text.slice(skip));
63778
+ };
63779
+ if (filter !== void 0) {
63780
+ strip = await recognized(filter);
63781
+ if ((await this.tree.describe(filter)).kind === "array") {
63782
+ strip = true;
63783
+ for await (const child of this.tree.children(filter)) if (!await recognized(child)) {
63784
+ strip = false;
63785
+ break;
63786
+ }
63787
+ }
63788
+ }
63789
+ }
63790
+ yield encoder.encode("<<\n");
63791
+ let hasLength = false;
63792
+ for (let key = object ? Number(await this.first.get(BigInt(root)) ?? 0n) : 0; key; ) {
63793
+ await this.cooperate();
63794
+ const value = (await this.tree.describe(key)).end;
63795
+ if (!strip || !await this.keyEquals(key, "Filter") && !await this.keyEquals(key, "DecodeParms")) {
63796
+ yield* this.scalar(key, true);
63797
+ yield encoder.encode(" ");
63798
+ if (await this.keyEquals(key, "Length")) {
63799
+ hasLength = true;
63800
+ yield serializeCosNodeBytes(cosNumber(length));
63801
+ } else yield* this.chunks(value);
63802
+ yield encoder.encode("\n");
63803
+ }
63804
+ key = Number(await this.next.get(BigInt(value)) ?? 0n);
63805
+ }
63806
+ if (!hasLength) yield encoder.encode(`/Length ${length}
63807
+ `);
63808
+ yield encoder.encode(">>");
63809
+ }
63544
63810
  async *chunks(root) {
63811
+ await this.validate(root);
63545
63812
  const encoder = new TextEncoder();
63546
63813
  let position = root, closing = false;
63547
63814
  while (position) {
@@ -63577,6 +63844,304 @@ var QpdfJsonValues = class _QpdfJsonValues {
63577
63844
  await this.scratch.close();
63578
63845
  }
63579
63846
  };
63847
+
63848
+ // packages/pdf-ast/src/cos/qpdf-json-document.ts
63849
+ import { IntegerTable as IntegerTable15, PagedStorage as PagedStorage25 } from "@poe-platform/safe-fs/storage";
63850
+ var QpdfJsonDocument = class _QpdfJsonDocument {
63851
+ constructor(storage, options = {}) {
63852
+ this.storage = storage;
63853
+ this.signal = options.signal ? AbortSignal.any([options.signal, this.controller.signal]) : this.controller.signal;
63854
+ this.store = new PdfMutableObjectStore(storage, { signal: this.signal });
63855
+ this.backing = new PagedStorage25(
63856
+ { fs: storage.fs, cwd: storage.directory, env: {}, signal: this.signal },
63857
+ 4
63858
+ );
63859
+ this.positions = new IntegerTable15(this.backing, 64);
63860
+ this.order = new IntegerTable15(this.backing, 64);
63861
+ this.catalogs = new IntegerTable15(this.backing, 64);
63862
+ }
63863
+ storage;
63864
+ rootRef;
63865
+ infoRef;
63866
+ store;
63867
+ backing;
63868
+ positions;
63869
+ order;
63870
+ catalogs;
63871
+ ordinal = 0;
63872
+ controller = new AbortController();
63873
+ signal;
63874
+ pending = Promise.resolve();
63875
+ closing;
63876
+ async remember(number) {
63877
+ if (!await this.positions.get(BigInt(number))) {
63878
+ const ordinal = ++this.ordinal;
63879
+ await this.positions.set(BigInt(number), BigInt(ordinal));
63880
+ await this.order.set(BigInt(ordinal), BigInt(number));
63881
+ }
63882
+ }
63883
+ static async fromDocument(document2, source, storage, options = {}) {
63884
+ const owner = new _QpdfJsonDocument(storage, options);
63885
+ try {
63886
+ owner.rootRef = document2.crossReference.rootRef;
63887
+ owner.infoRef = document2.crossReference.infoRef;
63888
+ for await (const object of retainedCosObjects(document2, storage, { signal: owner.signal })) {
63889
+ await owner.store.set(object);
63890
+ const type = object.value.kind === "dict" && !object.stream ? dictGet(object.value, "Type") : void 0;
63891
+ await owner.catalogs.set(
63892
+ BigInt(object.objectNumber),
63893
+ type?.kind === "name" && type.decoded === "Catalog" ? BigInt(object.generationNumber + 1) : 0n
63894
+ );
63895
+ }
63896
+ for await (const number of retainedObjectOrder(document2, source, storage, owner.signal))
63897
+ await owner.remember(number);
63898
+ return owner;
63899
+ } catch (error) {
63900
+ try {
63901
+ await owner.close();
63902
+ } catch {
63903
+ }
63904
+ throw error;
63905
+ }
63906
+ }
63907
+ apply(input, options = {}) {
63908
+ const task = this.pending.then(() => this.update(input, options));
63909
+ this.pending = task.catch(() => {
63910
+ });
63911
+ return task;
63912
+ }
63913
+ async update(input, options) {
63914
+ this.signal.throwIfAborted();
63915
+ const maximum10 = options.maxInputBytes ?? Infinity;
63916
+ if (maximum10 !== Infinity && (!Number.isSafeInteger(maximum10) || maximum10 < 0))
63917
+ throw new RangeError("Invalid QPDF JSON input limit");
63918
+ const context = {
63919
+ fs: this.storage.fs,
63920
+ cwd: this.storage.directory,
63921
+ env: {},
63922
+ signal: this.signal
63923
+ };
63924
+ const tape = new PagedStorage25(context, 4), scratch = new PagedStorage25(context, 4);
63925
+ let values, failed = false, work = 0;
63926
+ const cooperate = async (units = 1) => {
63927
+ this.signal.throwIfAborted();
63928
+ work += units;
63929
+ if (work >= 4096) {
63930
+ work = 0;
63931
+ await new Promise((resolve2) => setTimeout(resolve2, 0));
63932
+ this.signal.throwIfAborted();
63933
+ }
63934
+ };
63935
+ const tree = new BackedJson(tape, cooperate);
63936
+ async function* text() {
63937
+ const decoder = new TextDecoder();
63938
+ let total = 0;
63939
+ for await (const bytes of input) {
63940
+ if (bytes.length > maximum10 - total)
63941
+ throw new PdfError("E_LIMIT", "QPDF JSON input byte limit exceeded");
63942
+ total += bytes.length;
63943
+ for (let at = 0; at < bytes.length; at += 16384) {
63944
+ await cooperate(16384);
63945
+ yield decoder.decode(bytes.subarray(at, at + 16384), { stream: true });
63946
+ }
63947
+ }
63948
+ yield decoder.decode();
63949
+ }
63950
+ const isNull = async (position) => position !== void 0 && (await tree.describe(position)).kind === "literal" && await tree.smallText(position, 4) === "null";
63951
+ try {
63952
+ await parseBackedJson(
63953
+ text(),
63954
+ tree,
63955
+ scratch,
63956
+ cooperate,
63957
+ options.syntaxError ?? ((offset, message) => {
63958
+ throw new SyntaxError(`${message} at offset ${offset}`);
63959
+ }),
63960
+ void 0,
63961
+ true
63962
+ );
63963
+ const order = await indexJsonObjects(tree, scratch, cooperate);
63964
+ const property = async (position, name) => position !== void 0 && (await tree.describe(position)).kind === "object" ? order.property(position, name) : void 0;
63965
+ const objectLike = async (position) => position !== void 0 && ["object", "array"].includes((await tree.describe(position)).kind);
63966
+ const root = tree.rootPosition;
63967
+ if (!await objectLike(root)) throw new Error("Invalid QPDF JSON root");
63968
+ let section;
63969
+ const qpdf = await property(root, "qpdf");
63970
+ let selected = false;
63971
+ if (qpdf !== void 0 && (await tree.describe(qpdf)).kind === "array") {
63972
+ let index2 = 0;
63973
+ for await (const child of tree.children(qpdf)) {
63974
+ if (index2++ === 1) {
63975
+ if (await objectLike(child) || await isNull(child)) {
63976
+ section = child;
63977
+ selected = true;
63978
+ }
63979
+ break;
63980
+ }
63981
+ }
63982
+ }
63983
+ if (!selected) {
63984
+ const objects = await property(root, "objects");
63985
+ if (await objectLike(objects)) section = objects;
63986
+ }
63987
+ if (section === void 0 || await isNull(section))
63988
+ throw new Error("Missing QPDF JSON objects section");
63989
+ values = await QpdfJsonValues.open(tree, this.storage, { signal: this.signal });
63990
+ let rootRef, infoRef;
63991
+ if ((await tree.describe(section)).kind === "object")
63992
+ for await (const { key, value: entry } of order.entries(section)) {
63993
+ await cooperate();
63994
+ if (!await objectLike(entry)) continue;
63995
+ const value = await property(entry, "value");
63996
+ if (await tree.smallText(key, 7) === "trailer") {
63997
+ if (value !== void 0) {
63998
+ for await (const bytes of values.chunks(value)) void bytes;
63999
+ const root2 = await values.property(value, "Root"), info3 = await values.property(value, "Info");
64000
+ if (root2 !== void 0) rootRef = await values.reference(root2) ?? rootRef;
64001
+ if (info3 !== void 0) infoRef = await values.reference(info3) ?? infoRef;
64002
+ }
64003
+ continue;
64004
+ }
64005
+ const ref = await values.reference(key);
64006
+ if (!ref) continue;
64007
+ const stream = await property(entry, "stream");
64008
+ if (await objectLike(stream)) {
64009
+ const dict = await property(stream, "dict"), data = await property(stream, "data"), datafile = await property(stream, "datafile");
64010
+ if (dict !== void 0) await values.validate(dict);
64011
+ let staged;
64012
+ let streamFailed = false;
64013
+ try {
64014
+ let raw;
64015
+ if (data !== void 0 && (await tree.describe(data)).kind === "string") {
64016
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
64017
+ async function* decoded() {
64018
+ let accumulator = 0, bits = 0, used = 0, buffer = new Uint8Array(8192);
64019
+ for await (const text2 of tree.scalarChunks(data)) {
64020
+ await cooperate(text2.length);
64021
+ for (const char of text2) {
64022
+ const code = alphabet.indexOf(char);
64023
+ if (code < 0) continue;
64024
+ accumulator = accumulator << 6 | code;
64025
+ bits += 6;
64026
+ if (bits >= 8) {
64027
+ bits -= 8;
64028
+ buffer[used++] = accumulator >>> bits & 255;
64029
+ accumulator &= (1 << bits) - 1;
64030
+ if (used === buffer.length) {
64031
+ yield buffer;
64032
+ buffer = new Uint8Array(8192);
64033
+ used = 0;
64034
+ }
64035
+ }
64036
+ }
64037
+ }
64038
+ if (used) yield buffer.subarray(0, used);
64039
+ }
64040
+ staged = await PdfFileSource.fromStream(
64041
+ this.storage.fs,
64042
+ this.storage.directory,
64043
+ decoded(),
64044
+ { signal: this.signal }
64045
+ );
64046
+ raw = { length: staged.size, chunks: staged.stream(0, staged.size, this.signal) };
64047
+ } else if (datafile !== void 0 && (await tree.describe(datafile)).kind === "string") {
64048
+ let path = "";
64049
+ for await (const part of tree.scalarChunks(datafile)) {
64050
+ await cooperate(part.length);
64051
+ path += part;
64052
+ }
64053
+ const file = await options.dataFile?.(path);
64054
+ if (!file) throw new Error(`cannot open stream datafile ${path}`);
64055
+ raw = { length: file.size, chunks: file.stream(0, file.size, this.signal) };
64056
+ } else
64057
+ raw = await this.store.getStream(ref.objectNumber) ?? { length: 0, chunks: [] };
64058
+ const dictionary = await isNull(dict) ? void 0 : dict;
64059
+ let length = 0;
64060
+ for await (const bytes of values.streamDictionary(dictionary, raw.length))
64061
+ length += bytes.length;
64062
+ await this.store.setSerializedValue({
64063
+ ...ref,
64064
+ body: { length, chunks: values.streamDictionary(dictionary, raw.length) },
64065
+ stream: raw
64066
+ });
64067
+ await this.remember(ref.objectNumber);
64068
+ await this.catalogs.set(BigInt(ref.objectNumber), 0n);
64069
+ } catch (error) {
64070
+ streamFailed = true;
64071
+ throw error;
64072
+ } finally {
64073
+ await staged?.close().catch((error) => {
64074
+ if (!streamFailed) throw error;
64075
+ });
64076
+ }
64077
+ } else if (value !== void 0) {
64078
+ if (await isNull(value)) {
64079
+ await this.store.delete(ref.objectNumber);
64080
+ await this.positions.set(BigInt(ref.objectNumber), 0n);
64081
+ await this.catalogs.set(BigInt(ref.objectNumber), 0n);
64082
+ } else {
64083
+ let length = 0;
64084
+ for await (const bytes of values.chunks(value)) length += bytes.length;
64085
+ await this.store.setSerializedValue({
64086
+ ...ref,
64087
+ body: { length, chunks: values.chunks(value) }
64088
+ });
64089
+ await this.remember(ref.objectNumber);
64090
+ const type = await values.property(value, "Type"), token2 = type === void 0 ? void 0 : await tree.smallText(type, 11);
64091
+ await this.catalogs.set(
64092
+ BigInt(ref.objectNumber),
64093
+ token2 === "/Catalog" || token2 === "n:/Catalog" || token2 === "n:Catalog" ? BigInt(ref.generationNumber + 1) : 0n
64094
+ );
64095
+ }
64096
+ }
64097
+ }
64098
+ if (!rootRef)
64099
+ for await (const [ordinal, number] of this.order.entries()) {
64100
+ await cooperate();
64101
+ if (await this.positions.get(number) !== ordinal) continue;
64102
+ const generation = await this.catalogs.get(number);
64103
+ if (generation) {
64104
+ rootRef = cosRef(Number(number), Number(generation) - 1);
64105
+ break;
64106
+ }
64107
+ }
64108
+ if (rootRef) this.rootRef = rootRef;
64109
+ if (infoRef) this.infoRef = infoRef;
64110
+ } catch (error) {
64111
+ failed = true;
64112
+ throw error;
64113
+ } finally {
64114
+ const results = await Promise.allSettled([values?.close(), tape.close(), scratch.close()]);
64115
+ if (!failed) {
64116
+ for (const result of results)
64117
+ if (result.status === "rejected") await Promise.reject(result.reason);
64118
+ }
64119
+ }
64120
+ }
64121
+ async *chunks(options = {}) {
64122
+ await this.pending;
64123
+ this.signal.throwIfAborted();
64124
+ if (!this.rootRef) throw new Error("missing trailer /Root");
64125
+ yield* serializeRetainedCosDocumentChunks(
64126
+ {
64127
+ ...options,
64128
+ objects: this.store.outputObjects(),
64129
+ rootRef: this.rootRef,
64130
+ infoRef: this.infoRef,
64131
+ signal: this.signal
64132
+ },
64133
+ this.storage
64134
+ );
64135
+ }
64136
+ close() {
64137
+ this.controller.abort(new PdfError("E_CANCELLED", "QPDF JSON document closed"));
64138
+ return this.closing ??= (async () => {
64139
+ await this.pending;
64140
+ const results = await Promise.allSettled([this.store.close(), this.backing.close()]);
64141
+ for (const result of results) if (result.status === "rejected") throw result.reason;
64142
+ })();
64143
+ }
64144
+ };
63580
64145
  export {
63581
64146
  CosByteLexer,
63582
64147
  CosRangeLexer,
@@ -63600,6 +64165,7 @@ export {
63600
64165
  PdfRetainedPage,
63601
64166
  PdfStagedOutputs,
63602
64167
  PdfStagingStorage,
64168
+ QpdfJsonDocument,
63603
64169
  QpdfJsonValues,
63604
64170
  STANDARD_14_FONTS,
63605
64171
  appendIncrementalRevision,