@poe-platform/safe-bash 0.1.788 → 0.1.790

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (342) hide show
  1. package/README.md +1 -1
  2. package/dist/image-ast/index.browser.js +147 -80
  3. package/dist/image-ast/index.js +147 -80
  4. package/dist/mp4-ast/mp4.d.ts +2 -0
  5. package/dist/pdf-ast/cos/parser.d.ts +1 -0
  6. package/dist/pdf-ast/cos/security.d.ts +2 -0
  7. package/dist/pdf-ast/cos/writer.d.ts +1 -0
  8. package/dist/pdf-ast/document.d.ts +3 -0
  9. package/dist/pdf-ast/edit/forms.d.ts +1 -0
  10. package/dist/pdf-ast/index.js +171 -82
  11. package/dist/safe-bash/chunks/{chunk-L5QQLNTO.js → chunk-22PI65AH.js} +2 -2
  12. package/dist/safe-bash/chunks/{chunk-Q3E6C3DX.js → chunk-2TAGYMPK.js} +49 -34
  13. package/dist/safe-bash/chunks/{chunk-Z3HX3ZBA.js → chunk-2W4HTMEK.js} +52 -48
  14. package/dist/safe-bash/chunks/{chunk-FFZXP6ZC.js → chunk-3M7L7XU2.js} +2 -2
  15. package/dist/safe-bash/chunks/{chunk-XNODZRVD.js → chunk-3QAO6UYS.js} +2 -2
  16. package/dist/safe-bash/chunks/{chunk-YPETOVQU.js → chunk-3VKFK3NF.js} +2 -2
  17. package/dist/safe-bash/chunks/chunk-5OST7NOX.js +42 -0
  18. package/dist/safe-bash/chunks/{chunk-KEBSX2AX.js → chunk-6HLURHVU.js} +2 -2
  19. package/dist/safe-bash/chunks/chunk-DYEUZE6Z.js +19 -0
  20. package/dist/safe-bash/chunks/{chunk-T2TGCHKE.js → chunk-FM3WBSZT.js} +2 -2
  21. package/dist/safe-bash/chunks/chunk-GAYRKQM6.js +22 -0
  22. package/dist/safe-bash/chunks/{chunk-Q45QCA4J.js → chunk-I3KSESCR.js} +0 -7
  23. package/dist/safe-bash/chunks/{chunk-OSKDIBQS.js → chunk-JLIMK5TD.js} +1 -1
  24. package/dist/safe-bash/chunks/{chunk-2AYZCT5X.js → chunk-JQ2FAJJT.js} +27 -23
  25. package/dist/safe-bash/chunks/{chunk-QA3NVP43.js → chunk-JRE6Z3T7.js} +2 -2
  26. package/dist/safe-bash/chunks/{chunk-DC5EHLKS.js → chunk-NDIL6T7Y.js} +5 -5
  27. package/dist/safe-bash/chunks/{chunk-747G42FY.js → chunk-OPR4UAIT.js} +2 -2
  28. package/dist/safe-bash/chunks/chunk-OSMQCYSP.js +19 -0
  29. package/dist/safe-bash/chunks/chunk-OYB332PQ.js +17 -0
  30. package/dist/safe-bash/chunks/{chunk-ZMYVCRAF.js → chunk-QTIH2AFE.js} +77 -69
  31. package/dist/safe-bash/chunks/{chunk-PYTLIUST.js → chunk-SBESXWT2.js} +43 -44
  32. package/dist/safe-bash/chunks/{chunk-4FDQJUFW.js → chunk-SDEPGTOF.js} +1 -1
  33. package/dist/safe-bash/chunks/chunk-UZU5BIJI.js +32 -0
  34. package/dist/safe-bash/chunks/{chunk-BI6JV62X.js → chunk-VCCMROTL.js} +7 -10
  35. package/dist/safe-bash/chunks/chunk-W47GHRRF.js +13 -0
  36. package/dist/safe-bash/chunks/{chunk-NPMQWZUZ.js → chunk-WS7KZIUM.js} +2 -2
  37. package/dist/safe-bash/chunks/{chunk-3PZYHMGM.js → chunk-YYAERCWS.js} +7 -7
  38. package/dist/safe-bash/chunks/{chunk-5U7JECDB.js → chunk-ZPGVEUKF.js} +8 -7
  39. package/dist/safe-bash/chunks/{csvkit-K55OYAQC.js → csvkit-USUJG62I.js} +65 -11
  40. package/dist/safe-bash/chunks/{ffmpeg-BEFTQ6DZ.js → ffmpeg-KRGG5DLH.js} +21 -10
  41. package/dist/safe-bash/chunks/{gh-HQWOWLWE.js → gh-UCFDUZCX.js} +16 -8
  42. package/dist/safe-bash/chunks/{git-UFNPAOYZ.js → git-LPAF6KDG.js} +7 -9
  43. package/dist/safe-bash/chunks/{imagemagick-53BMHH6D.js → imagemagick-KGREKK4G.js} +38 -7
  44. package/dist/safe-bash/chunks/{implementation-QUTAAYMT.js → implementation-FXDRYS5A.js} +34 -8
  45. package/dist/safe-bash/chunks/{pdfimages-4OYI6FLG.js → pdfimages-UADCF4G4.js} +12 -8
  46. package/dist/safe-bash/chunks/{pdfinfo-I7U6TQPP.js → pdfinfo-O7UWPF4W.js} +38 -13
  47. package/dist/safe-bash/chunks/{pdftk-SUA6FMHI.js → pdftk-AERXIJTN.js} +13 -8
  48. package/dist/safe-bash/chunks/{pdftoppm-4C5DGEWX.js → pdftoppm-L466JQKI.js} +17 -10
  49. package/dist/safe-bash/chunks/{pdftotext-Y4WI225Y.js → pdftotext-SUSI4WXS.js} +19 -9
  50. package/dist/safe-bash/chunks/{qpdf-IORB4RV5.js → qpdf-YL24KVRH.js} +14 -8
  51. package/dist/safe-bash/chunks/{sips-WHAMJFEU.js → sips-QXEQZERX.js} +14 -7
  52. package/dist/safe-bash/chunks/{soffice-SYEK6WJS.js → soffice-TBITRML3.js} +16 -8
  53. package/dist/safe-bash/chunks/{wkhtmltopdf-ZIICWJLF.js → wkhtmltopdf-NJA2THRC.js} +27 -7
  54. package/dist/safe-bash/command-chunks/chunk-2C5BEBPY.js +1388 -0
  55. package/dist/safe-bash/command-chunks/{chunk-FXYWQ6S4.js → chunk-2EXV2ZLV.js} +2 -2
  56. package/dist/safe-bash/command-chunks/{chunk-PFBJR2PY.js → chunk-2KRKKW5S.js} +2 -2
  57. package/dist/safe-bash/command-chunks/{chunk-4DSJDVBM.js → chunk-32F3RBUW.js} +10 -749
  58. package/dist/safe-bash/command-chunks/{chunk-L3MLMXL4.js → chunk-3ZK5F23O.js} +1 -1
  59. package/dist/safe-bash/command-chunks/{chunk-4QX6XCDD.js → chunk-4RNIZ3RT.js} +79 -0
  60. package/dist/safe-bash/command-chunks/{chunk-D7TADAYG.js → chunk-64LG3EVJ.js} +17 -0
  61. package/dist/safe-bash/command-chunks/{chunk-TOSM3T3A.js → chunk-6EASC5EC.js} +20 -9
  62. package/dist/safe-bash/command-chunks/{chunk-ZF3ZVGQC.js → chunk-7JRITHKW.js} +150 -80
  63. package/dist/safe-bash/command-chunks/{chunk-IJ3FXP4Q.js → chunk-A3ZX6SCY.js} +1 -1
  64. package/dist/safe-bash/{chunks/chunk-LD76P7AG.js → command-chunks/chunk-AKDMCNX4.js} +74 -39
  65. package/dist/safe-bash/command-chunks/{chunk-KSIGF4AG.js → chunk-BK4CMEE6.js} +1 -1
  66. package/dist/safe-bash/command-chunks/{chunk-JUDOV5MJ.js → chunk-CBDVLMJB.js} +1 -1
  67. package/dist/safe-bash/command-chunks/{chunk-XGMWWUHV.js → chunk-CZ5DAK4K.js} +1 -1
  68. package/dist/safe-bash/command-chunks/{chunk-Z57TV6TC.js → chunk-EZ2DTOLI.js} +4 -2
  69. package/dist/safe-bash/command-chunks/{chunk-ADCGH6A7.js → chunk-FH3D75FC.js} +1 -1
  70. package/dist/safe-bash/command-chunks/{chunk-WYJTWJZ5.js → chunk-G3G6W5ZE.js} +1 -1
  71. package/dist/safe-bash/command-chunks/{chunk-3HDIDEUJ.js → chunk-GF54KE2M.js} +1 -1
  72. package/dist/safe-bash/command-chunks/chunk-H4LWTITX.js +169 -0
  73. package/dist/safe-bash/command-chunks/chunk-I2MQNBGR.js +145 -0
  74. package/dist/safe-bash/command-chunks/{chunk-Z7TYZG3A.js → chunk-IHHTTQX6.js} +5 -3
  75. package/dist/safe-bash/command-chunks/{chunk-5GRLAARV.js → chunk-IOXI5ZAJ.js} +1 -1
  76. package/dist/safe-bash/command-chunks/{chunk-INDIFLBW.js → chunk-JTAGNROA.js} +4 -0
  77. package/dist/safe-bash/command-chunks/{chunk-Y5IHIAY3.js → chunk-MDPIOQUD.js} +12 -8
  78. package/dist/safe-bash/command-chunks/chunk-PGEYORBZ.js +25 -0
  79. package/dist/safe-bash/command-chunks/chunk-QI4MGIN6.js +6 -0
  80. package/dist/safe-bash/command-chunks/chunk-QM4UZF3C.js +753 -0
  81. package/dist/safe-bash/command-chunks/chunk-QTYZAWSB.js +91 -0
  82. package/dist/safe-bash/command-chunks/chunk-SNK7K3XW.js +90 -0
  83. package/dist/safe-bash/command-chunks/chunk-T5OLGM43.js +314 -0
  84. package/dist/safe-bash/command-chunks/chunk-TB7IFMUZ.js +802 -0
  85. package/dist/safe-bash/command-chunks/{chunk-YNT4ZJHW.js → chunk-TPPBPIWL.js} +3 -3
  86. package/dist/safe-bash/command-chunks/chunk-VMK4XVKO.js +82 -0
  87. package/dist/safe-bash/command-chunks/chunk-VNSJKXDU.js +130 -0
  88. package/dist/safe-bash/command-chunks/{chunk-2LP3VMPA.js → chunk-WFDW4XXD.js} +1 -17
  89. package/dist/safe-bash/command-chunks/chunk-WR37IS4O.js +318 -0
  90. package/dist/safe-bash/command-chunks/chunk-YFNTMH6Z.js +6 -0
  91. package/dist/safe-bash/commands/basic.js +148 -48
  92. package/dist/safe-bash/commands/bytes/compression/index.js +5 -6
  93. package/dist/safe-bash/commands/cmp.d.ts +2 -3
  94. package/dist/safe-bash/commands/cmp.js +2 -689
  95. package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
  96. package/dist/safe-bash/commands/docx/index.browser.js +4 -47
  97. package/dist/safe-bash/commands/docx/index.d.ts +2 -24
  98. package/dist/safe-bash/commands/docx/index.js +2 -41
  99. package/dist/safe-bash/commands/docx/io.d.ts +1 -14
  100. package/dist/safe-bash/commands/docx/io.js +1 -15
  101. package/dist/safe-bash/commands/factor/index.browser.js +2 -2
  102. package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
  103. package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
  104. package/dist/safe-bash/commands/iconv/index.browser.js +2 -2
  105. package/dist/safe-bash/commands/line-endings/index.browser.js +2 -2
  106. package/dist/safe-bash/commands/llm/command.d.ts +1 -4
  107. package/dist/safe-bash/commands/llm/command.js +1 -248
  108. package/dist/safe-bash/commands/llm/elevenlabs-stream.d.ts +1 -2
  109. package/dist/safe-bash/commands/llm/elevenlabs-stream.js +1 -117
  110. package/dist/safe-bash/commands/llm/elevenlabs.d.ts +1 -15
  111. package/dist/safe-bash/commands/llm/elevenlabs.js +1 -123
  112. package/dist/safe-bash/commands/llm/index.browser.js +20 -15
  113. package/dist/safe-bash/commands/llm/index.d.ts +1 -6
  114. package/dist/safe-bash/commands/llm/index.js +1 -4
  115. package/dist/safe-bash/commands/llm/mime.d.ts +1 -2
  116. package/dist/safe-bash/commands/llm/mime.js +1 -136
  117. package/dist/safe-bash/commands/llm/openai-http.d.ts +1 -8
  118. package/dist/safe-bash/commands/llm/openai-http.js +1 -143
  119. package/dist/safe-bash/commands/llm/openai-sse.d.ts +1 -3
  120. package/dist/safe-bash/commands/llm/openai-sse.js +1 -78
  121. package/dist/safe-bash/commands/llm/openai.d.ts +1 -14
  122. package/dist/safe-bash/commands/llm/openai.js +1 -288
  123. package/dist/safe-bash/commands/llm/providers/elevenlabs.d.ts +1 -1
  124. package/dist/safe-bash/commands/llm/providers/elevenlabs.js +1 -1
  125. package/dist/safe-bash/commands/llm/providers/index.browser.js +6 -6
  126. package/dist/safe-bash/commands/llm/providers/index.d.ts +1 -3
  127. package/dist/safe-bash/commands/llm/providers/index.js +1 -2
  128. package/dist/safe-bash/commands/llm/providers/openai.d.ts +1 -1
  129. package/dist/safe-bash/commands/llm/providers/openai.js +1 -1
  130. package/dist/safe-bash/commands/llm/providers/shared.d.ts +1 -23
  131. package/dist/safe-bash/commands/llm/providers/shared.js +1 -65
  132. package/dist/safe-bash/commands/llm/service.d.ts +1 -37
  133. package/dist/safe-bash/commands/llm/service.js +1 -151
  134. package/dist/safe-bash/commands/llm/types.d.ts +1 -52
  135. package/dist/safe-bash/commands/llm/types.js +1 -1
  136. package/dist/safe-bash/commands/mdq/index.browser.js +3 -3
  137. package/dist/safe-bash/commands/media/index.browser.js +1 -1
  138. package/dist/safe-bash/commands/network/index.browser.js +9 -9
  139. package/dist/safe-bash/commands/network/types.d.ts +2 -40
  140. package/dist/safe-bash/commands/node/index.browser.js +6 -8
  141. package/dist/safe-bash/commands/op/index.browser.js +3 -3
  142. package/dist/safe-bash/commands/op/index.js +12 -28
  143. package/dist/safe-bash/commands/pptx/index.d.ts +2 -28
  144. package/dist/safe-bash/commands/pptx/index.js +2 -152
  145. package/dist/safe-bash/commands/pr/index.browser.js +2 -2
  146. package/dist/safe-bash/commands/printf-float.d.ts +1 -0
  147. package/dist/safe-bash/commands/printf-float.js +48 -38
  148. package/dist/safe-bash/commands/printf-format.js +9 -6
  149. package/dist/safe-bash/commands/printf-quote.d.ts +3 -0
  150. package/dist/safe-bash/commands/printf-quote.js +62 -0
  151. package/dist/safe-bash/commands/printf-wide.d.ts +5 -0
  152. package/dist/safe-bash/commands/printf-wide.js +41 -0
  153. package/dist/safe-bash/commands/python/index.browser.js +8 -8
  154. package/dist/safe-bash/commands/python/worker.browser.js +2 -2
  155. package/dist/safe-bash/commands/truncate.d.ts +2 -3
  156. package/dist/safe-bash/commands/truncate.js +2 -686
  157. package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
  158. package/dist/safe-bash/commands/xml/index.browser.js +2 -2
  159. package/dist/safe-bash/commands/yq/index.browser.js +3 -3
  160. package/dist/safe-bash/contracts/diagnostics.d.ts +2 -0
  161. package/dist/safe-bash/contracts/diagnostics.js +2 -0
  162. package/dist/safe-bash/contracts/runtime-control.d.ts +2 -0
  163. package/dist/safe-bash/contracts/runtime-control.js +2 -0
  164. package/dist/safe-bash/core.browser.d.ts +1 -1
  165. package/dist/safe-bash/core.browser.js +10645 -14065
  166. package/dist/safe-bash/core.d.ts +10 -1
  167. package/dist/safe-bash/core.js +0 -1
  168. package/dist/safe-bash/jobs.browser.js +5 -4
  169. package/dist/safe-bash/opt-in/commands/cmp/index.d.ts +6 -2
  170. package/dist/safe-bash/opt-in/commands/cmp/index.js +776 -79
  171. package/dist/safe-bash/opt-in/commands/cmp/options.d.ts +0 -12
  172. package/dist/safe-bash/opt-in/commands/cmp/options.js +0 -153
  173. package/dist/safe-bash/opt-in/commands/truncate/index.d.ts +8 -3
  174. package/dist/safe-bash/opt-in/commands/truncate/index.js +790 -272
  175. package/dist/safe-bash/opt-in/commands/truncate/sync.d.ts +1 -0
  176. package/dist/safe-bash/opt-in/commands/truncate/sync.js +60 -0
  177. package/dist/safe-bash/optional-host.browser.js +61 -80
  178. package/dist/safe-bash/optional-host.d.ts +3 -1
  179. package/dist/safe-bash/optional-host.js +3 -1
  180. package/dist/safe-bash/shell/runtime.js +44 -18
  181. package/dist/safe-bash/yq-browser/index.js +1 -1
  182. package/dist/safe-bash-checksum-engine/index.d.ts +1 -1
  183. package/dist/safe-bash-checksum-engine/index.js +14 -2
  184. package/dist/safe-bash-command-bzip2/index.js +2 -1
  185. package/dist/safe-bash-command-cmp/index.d.ts +10 -0
  186. package/dist/safe-bash-command-cmp/index.js +796 -0
  187. package/dist/safe-bash-command-cmp/options.d.ts +12 -0
  188. package/dist/safe-bash-command-cmp/options.js +42 -0
  189. package/dist/safe-bash-command-csvcut/index.js +11 -8
  190. package/dist/safe-bash-command-csvgrep/index.js +35 -7
  191. package/dist/safe-bash-command-csvkit/codecs/python.js +4 -3
  192. package/dist/safe-bash-command-csvkit/codecs/utf8.js +3 -2
  193. package/dist/safe-bash-command-csvkit/index.js +80 -324
  194. package/dist/safe-bash-command-csvkit/python-regex.d.ts +5 -0
  195. package/dist/safe-bash-command-csvkit/python-regex.js +14 -0
  196. package/dist/safe-bash-command-csvkit/runtime.d.ts +1 -0
  197. package/dist/safe-bash-command-csvkit/sync-support.js +4 -2
  198. package/dist/safe-bash-command-diff3/index.js +3 -0
  199. package/dist/safe-bash-command-docx/LICENSE +21 -0
  200. package/dist/safe-bash-command-docx/index.d.ts +30 -0
  201. package/dist/safe-bash-command-docx/index.js +67 -0
  202. package/dist/safe-bash-command-docx/io.d.ts +14 -0
  203. package/dist/safe-bash-command-docx/io.js +26 -0
  204. package/dist/safe-bash-command-envsubst/index.js +34 -3
  205. package/dist/safe-bash-command-exiftool/index.js +3 -0
  206. package/dist/safe-bash-command-ffmpeg/index.js +8073 -7940
  207. package/dist/safe-bash-command-fold/family.js +1 -1
  208. package/dist/safe-bash-command-fold/index.js +1 -1
  209. package/dist/safe-bash-command-git/git_rust.wasm +0 -0
  210. package/dist/safe-bash-command-git/wasm.generated.js +1 -1
  211. package/dist/safe-bash-command-htmlq/index.js +5 -0
  212. package/dist/safe-bash-command-imagemagick/index.d.ts +25 -21
  213. package/dist/safe-bash-command-imagemagick/index.js +671 -273
  214. package/dist/safe-bash-command-llm/LICENSE +21 -0
  215. package/dist/safe-bash-command-llm/command.d.ts +5 -0
  216. package/dist/safe-bash-command-llm/command.js +14 -0
  217. package/dist/safe-bash-command-llm/configuration.d.ts +18 -0
  218. package/dist/safe-bash-command-llm/elevenlabs-stream.d.ts +2 -0
  219. package/dist/safe-bash-command-llm/elevenlabs-stream.js +7 -0
  220. package/dist/safe-bash-command-llm/elevenlabs.d.ts +15 -0
  221. package/dist/safe-bash-command-llm/elevenlabs.js +10 -0
  222. package/dist/safe-bash-command-llm/index.d.ts +10 -0
  223. package/dist/safe-bash-command-llm/index.js +46 -0
  224. package/dist/safe-bash-command-llm/mime.d.ts +2 -0
  225. package/dist/safe-bash-command-llm/mime.js +9 -0
  226. package/dist/safe-bash-command-llm/model-options.d.ts +3 -0
  227. package/dist/safe-bash-command-llm/openai-http.d.ts +8 -0
  228. package/dist/safe-bash-command-llm/openai-http.js +17 -0
  229. package/dist/safe-bash-command-llm/openai-sse.d.ts +3 -0
  230. package/dist/safe-bash-command-llm/openai-sse.js +8 -0
  231. package/dist/safe-bash-command-llm/openai.d.ts +14 -0
  232. package/dist/safe-bash-command-llm/openai.js +12 -0
  233. package/dist/safe-bash-command-llm/providers/elevenlabs.d.ts +1 -0
  234. package/dist/safe-bash-command-llm/providers/elevenlabs.js +11 -0
  235. package/dist/safe-bash-command-llm/providers/index.d.ts +3 -0
  236. package/dist/safe-bash-command-llm/providers/index.js +24 -0
  237. package/dist/safe-bash-command-llm/providers/openai.d.ts +1 -0
  238. package/dist/safe-bash-command-llm/providers/openai.js +13 -0
  239. package/dist/safe-bash-command-llm/providers/shared.d.ts +23 -0
  240. package/dist/safe-bash-command-llm/providers/shared.js +13 -0
  241. package/dist/safe-bash-command-llm/schemas.d.ts +2 -0
  242. package/dist/safe-bash-command-llm/service.d.ts +42 -0
  243. package/dist/safe-bash-command-llm/service.js +9 -0
  244. package/dist/safe-bash-command-llm/templates.d.ts +27 -0
  245. package/dist/safe-bash-command-llm/types.d.ts +87 -0
  246. package/dist/safe-bash-command-llm/types.js +6 -0
  247. package/dist/safe-bash-command-mmdc/command.d.ts +4 -0
  248. package/dist/safe-bash-command-mmdc/index.d.ts +1 -1
  249. package/dist/safe-bash-command-mmdc/index.js +7134 -6699
  250. package/dist/safe-bash-command-mmdc/layout.d.ts +1 -0
  251. package/dist/safe-bash-command-mmdc/parser.d.ts +1 -0
  252. package/dist/safe-bash-command-mmdc/png.d.ts +3 -0
  253. package/dist/safe-bash-command-mmdc/raster.d.ts +1 -0
  254. package/dist/safe-bash-command-mmdc/svg.d.ts +1 -0
  255. package/dist/safe-bash-command-op/index.js +19 -14
  256. package/dist/safe-bash-command-pandoc/command.js +3 -3
  257. package/dist/safe-bash-command-pandoc/index.js +3 -3
  258. package/dist/safe-bash-command-pdfimages/index.d.ts +7 -1
  259. package/dist/safe-bash-command-pdfimages/index.js +210 -113
  260. package/dist/safe-bash-command-pdfinfo/index.d.ts +24 -20
  261. package/dist/safe-bash-command-pdfinfo/index.js +517 -241
  262. package/dist/safe-bash-command-pdftk/index.d.ts +7 -3
  263. package/dist/safe-bash-command-pdftk/index.js +261 -125
  264. package/dist/safe-bash-command-pdftoppm/index.d.ts +15 -7
  265. package/dist/safe-bash-command-pdftoppm/index.js +326 -189
  266. package/dist/safe-bash-command-pdftotext/index.d.ts +9 -5
  267. package/dist/safe-bash-command-pdftotext/index.js +237 -107
  268. package/dist/safe-bash-command-pptx/LICENSE +21 -0
  269. package/dist/safe-bash-command-pptx/index.d.ts +33 -0
  270. package/dist/safe-bash-command-pptx/index.js +168 -0
  271. package/dist/safe-bash-command-qpdf/index.d.ts +9 -3
  272. package/dist/safe-bash-command-qpdf/index.js +254 -130
  273. package/dist/safe-bash-command-sha512sum/index.js +12 -475
  274. package/dist/safe-bash-command-sips/index.d.ts +9 -5
  275. package/dist/safe-bash-command-sips/index.js +65 -46
  276. package/dist/safe-bash-command-soffice/index.d.ts +9 -3
  277. package/dist/safe-bash-command-soffice/index.js +66 -25
  278. package/dist/safe-bash-command-sqlite3/engine.d.ts +9 -0
  279. package/dist/safe-bash-command-sqlite3/index.d.ts +1 -0
  280. package/dist/safe-bash-command-sqlite3/index.js +851 -352
  281. package/dist/safe-bash-command-ssconvert/formats/xls.js +3 -3
  282. package/dist/safe-bash-command-ssconvert/index.js +147 -80
  283. package/dist/safe-bash-command-timeout/index.js +3 -3
  284. package/dist/safe-bash-command-truncate/index.d.ts +8 -3
  285. package/dist/safe-bash-command-truncate/index.js +790 -272
  286. package/dist/safe-bash-command-truncate/sync.d.ts +1 -0
  287. package/dist/safe-bash-command-truncate/sync.js +60 -0
  288. package/dist/safe-bash-command-wkhtmltopdf/index.js +239 -118
  289. package/dist/safe-bash-command-wkhtmltopdf/pdf-renderer.d.ts +1 -1
  290. package/dist/safe-bash-command-xxd/index.js +78 -20
  291. package/dist/safe-bash-command-xz/command.d.ts +4 -0
  292. package/dist/safe-bash-command-xz/index.d.ts +1 -1
  293. package/dist/safe-bash-command-xz/index.js +1 -1
  294. package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
  295. package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
  296. package/dist/safe-bash-compression-engine/files.js +6 -6
  297. package/dist/safe-bash-compression-engine/index.js +5 -5
  298. package/dist/safe-bash-compression-engine/operand.js +6 -6
  299. package/dist/safe-bash-compression-engine/stream.js +5 -5
  300. package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
  301. package/dist/safe-bash-contracts/command.js +3 -3
  302. package/dist/safe-bash-contracts/default-executor.d.ts +5 -0
  303. package/dist/safe-bash-contracts/default-executor.js +37 -0
  304. package/dist/safe-bash-contracts/diagnostics.js +3 -3
  305. package/dist/safe-bash-contracts/escaping.js +9 -9
  306. package/dist/safe-bash-contracts/filesystem-descriptor.js +3 -3
  307. package/dist/safe-bash-contracts/filesystem-output.js +8 -8
  308. package/dist/safe-bash-contracts/http.d.ts +41 -0
  309. package/dist/safe-bash-contracts/http.js +6 -0
  310. package/dist/safe-bash-contracts/index.js +21 -19
  311. package/dist/safe-bash-contracts/io.d.ts +12 -0
  312. package/dist/safe-bash-contracts/io.js +4 -1
  313. package/dist/safe-bash-contracts/output.js +3 -2
  314. package/dist/safe-bash-contracts/runtime-control.js +2 -2
  315. package/dist/safe-bash-contracts/signals.js +1 -1
  316. package/dist/safe-bash-contracts/yield.d.ts +1 -0
  317. package/dist/safe-bash-contracts/yield.js +3 -1
  318. package/dist/safe-bash-csv-engine/index.d.ts +10 -1
  319. package/dist/safe-bash-csv-engine/index.js +78 -6
  320. package/dist/safe-bash-io-engine/commands/search/requirements.js +3 -3
  321. package/dist/safe-bash-io-engine/commands/text-programs/shared.js +3 -3
  322. package/dist/safe-bash-io-engine/gnu-information.d.ts +1 -1
  323. package/dist/safe-bash-io-engine/gnu-information.js +1 -1
  324. package/dist/safe-bash-io-engine/internal.d.ts +1 -1
  325. package/dist/safe-bash-io-engine/internal.js +2 -2
  326. package/dist/safe-bash-query-engine/index.js +5 -5
  327. package/dist/safe-bash-query-engine/interpreter.js +3 -3
  328. package/dist/safe-bash-query-engine/query-core.js +5 -5
  329. package/package.json +2 -2
  330. package/dist/safe-bash/chunks/chunk-2G2T5MEM.js +0 -14
  331. package/dist/safe-bash/chunks/chunk-FJZNUUOQ.js +0 -81
  332. package/dist/safe-bash/chunks/chunk-GJWUEOT6.js +0 -14
  333. package/dist/safe-bash/chunks/chunk-LAPF2XE6.js +0 -14
  334. package/dist/safe-bash/chunks/chunk-O6356Z27.js +0 -37
  335. package/dist/safe-bash/chunks/chunk-S2LSZFZ6.js +0 -758
  336. package/dist/safe-bash/chunks/chunk-T3VDYWKZ.js +0 -21
  337. package/dist/safe-bash/chunks/chunk-VYW4Q6KF.js +0 -12
  338. package/dist/safe-bash/chunks/chunk-WHURJBET.js +0 -409
  339. package/dist/safe-bash/opt-in/commands/cmp/compare.js +0 -95
  340. package/dist/safe-bash/opt-in/commands/cmp/io.js +0 -218
  341. package/dist/safe-bash/command-chunks/{chunk-RTOJNFFL.js → chunk-KNI4GRXF.js} +7 -7
  342. package/dist/safe-bash/command-chunks/{chunk-DEH3CMGL.js → chunk-QJ3ONEBI.js} +3 -3
@@ -4,6 +4,7 @@ import {
4
4
 
5
5
  // packages/safe-bash-command-qpdf/dist/index.js
6
6
  init_buffer();
7
+ import { yieldTurn } from "../safe-bash-contracts/yield.js";
7
8
  import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
8
9
  import {
9
10
  commandRuntimeIdentity,
@@ -27100,6 +27101,11 @@ function tokenizeCos(bytes, start = 0, end = bytes.length) {
27100
27101
  }
27101
27102
  return tokens;
27102
27103
  }
27104
+ function drainWork(work) {
27105
+ let step = work.next();
27106
+ while (!step.done) step = work.next();
27107
+ return step.value;
27108
+ }
27103
27109
  function bytesToString3(bytes) {
27104
27110
  if (typeof bytes !== "object" || bytes?.length === void 0) {
27105
27111
  throw new Error("Invalid argument for bytesToString");
@@ -27695,7 +27701,9 @@ function concatByteArrays(chunks) {
27695
27701
  }
27696
27702
  return out;
27697
27703
  }
27698
- function serializeCosDocument(options) {
27704
+ function* serializeCosDocumentSteps(options) {
27705
+ yield;
27706
+ let work = 0;
27699
27707
  const maxOutputBytes = options.maxOutputBytes ?? Infinity;
27700
27708
  const maxObjects = options.maxObjects ?? Infinity;
27701
27709
  const sorted = [...options.objects].sort((a, b) => a.objectNumber - b.objectNumber);
@@ -27718,6 +27726,7 @@ function serializeCosDocument(options) {
27718
27726
  const packable = [];
27719
27727
  const direct = [];
27720
27728
  for (const obj of sorted) {
27729
+ if (++work % 16 === 0) yield;
27721
27730
  const isLinearized = obj.value.kind === "dict" && dictGet(obj.value, "Linearized") !== void 0;
27722
27731
  if (obj.value.kind !== "stream" && obj.generationNumber === 0 && !isLinearized) {
27723
27732
  packable.push(obj);
@@ -27732,6 +27741,7 @@ function serializeCosDocument(options) {
27732
27741
  const headerPairs = [];
27733
27742
  let relOffset = 0;
27734
27743
  for (const pObj of packable) {
27744
+ if (++work % 16 === 0) yield;
27735
27745
  headerPairs.push(`${pObj.objectNumber} ${relOffset}`);
27736
27746
  const bBytes = serializeCosNodeBytes(pObj.value);
27737
27747
  const nl = textEncoder2.encode("\n");
@@ -27757,6 +27767,7 @@ function serializeCosDocument(options) {
27757
27767
  ];
27758
27768
  const directOffsets = /* @__PURE__ */ new Map();
27759
27769
  for (const dObj of allDirect) {
27770
+ if (++work % 16 === 0) yield;
27760
27771
  directOffsets.set(dObj.objectNumber, { offset, generation: dObj.generationNumber });
27761
27772
  const prefix = textEncoder2.encode(`${dObj.objectNumber} ${dObj.generationNumber} obj
27762
27773
  `);
@@ -27767,6 +27778,7 @@ function serializeCosDocument(options) {
27767
27778
  }
27768
27779
  const compressedMap = /* @__PURE__ */ new Map();
27769
27780
  for (let idx = 0; idx < packable.length; idx++) {
27781
+ if (++work % 16 === 0) yield;
27770
27782
  compressedMap.set(packable[idx].objectNumber, idx);
27771
27783
  }
27772
27784
  const xrefOffset2 = offset;
@@ -27784,6 +27796,7 @@ function serializeCosDocument(options) {
27784
27796
  };
27785
27797
  writeEntry7(0, 0, 0, 65535);
27786
27798
  for (let i = 1; i < size2; i++) {
27799
+ if (++work % 16 === 0) yield;
27787
27800
  if (i === xrefStmNum) {
27788
27801
  writeEntry7(i, 1, xrefOffset2, 0);
27789
27802
  } else if (compressedMap.has(i)) {
@@ -27864,6 +27877,7 @@ ${xrefOffset2}
27864
27877
  let pageCount = 0;
27865
27878
  let firstPageObjNum = options.rootRef.objectNumber;
27866
27879
  for (const o of sorted) {
27880
+ if (++work % 16 === 0) yield;
27867
27881
  if (o.value.kind === "dict") {
27868
27882
  const t = dictGet(o.value, "Type");
27869
27883
  if (t?.kind === "name" && t.decoded === "Page") {
@@ -27911,6 +27925,7 @@ ${xrefOffset2}
27911
27925
  }
27912
27926
  const objectOffsets = /* @__PURE__ */ new Map();
27913
27927
  for (const obj of sorted) {
27928
+ if (++work % 16 === 0) yield;
27914
27929
  objectOffsets.set(obj.objectNumber, { offset, generation: obj.generationNumber });
27915
27930
  let value = obj.value;
27916
27931
  if (options.normalizeContent && value.kind === "stream" && value.decodedBytes) {
@@ -27942,6 +27957,7 @@ ${xrefOffset2}
27942
27957
  0000000000 65535 f
27943
27958
  `;
27944
27959
  for (let i = 1; i < size; i++) {
27960
+ if (++work % 16 === 0) yield;
27945
27961
  const entry = objectOffsets.get(i);
27946
27962
  if (entry) {
27947
27963
  xrefText += `${String(entry.offset).padStart(10, "0")} ${String(entry.generation).padStart(5, "0")} n
@@ -27988,6 +28004,7 @@ ${xrefOffset}
27988
28004
  let endFirstPage = xrefOffset;
27989
28005
  const sortedOffsets = [...objectOffsets.entries()].sort((a, b) => a[1].offset - b[1].offset);
27990
28006
  for (let i = 0; i < sortedOffsets.length; i++) {
28007
+ if (++work % 16 === 0) yield;
27991
28008
  const [objNum, info3] = sortedOffsets[i];
27992
28009
  const nextOff = sortedOffsets[i + 1]?.[1].offset ?? xrefOffset;
27993
28010
  if (objNum === hintObjAfter.objectNumber) {
@@ -28021,6 +28038,9 @@ ${xrefOffset}
28021
28038
  }
28022
28039
  return fullBytes;
28023
28040
  }
28041
+ function serializeCosDocument(options) {
28042
+ return drainWork(serializeCosDocumentSteps(options));
28043
+ }
28024
28044
  function appendIncrementalRevision(originalBytes, doc, updatedObjects) {
28025
28045
  const chunks = [originalBytes, textEncoder2.encode("\n")];
28026
28046
  let offset = originalBytes.length + 1;
@@ -28294,48 +28314,30 @@ function encryptPdfBuffer(state, objectNumber, generationNumber, plaintext) {
28294
28314
  const objKey = md5Bytes([state.fileKey, suffix]).subarray(0, Math.min(16, state.fileKey.length + 5));
28295
28315
  return rc4Transform(objKey, plaintext);
28296
28316
  }
28297
- function transformNodeStringsAndStreams(node, transform, transformStream) {
28317
+ function* transformNodeStringsAndStreamsSteps(node, transform, transformStream) {
28318
+ yield;
28298
28319
  switch (node.kind) {
28299
28320
  case "string":
28300
- return {
28301
- kind: "string",
28302
- format: "hex",
28303
- bytes: transform(node.bytes)
28304
- };
28305
- case "array":
28306
- return {
28307
- kind: "array",
28308
- items: node.items.map((item) => transformNodeStringsAndStreams(item, transform, transformStream))
28309
- };
28321
+ return { kind: "string", format: "hex", bytes: transform(node.bytes) };
28322
+ case "array": {
28323
+ const items = [];
28324
+ for (const item of node.items) items.push(yield* transformNodeStringsAndStreamsSteps(item, transform, transformStream));
28325
+ return { kind: "array", items };
28326
+ }
28310
28327
  case "dict": {
28311
- const type = dictGet(node, "Type");
28312
- const fieldType = dictGet(node, "FT");
28313
- const byteRange = dictGet(node, "ByteRange");
28328
+ const type = dictGet(node, "Type"), fieldType = dictGet(node, "FT"), byteRange = dictGet(node, "ByteRange");
28314
28329
  const signature = type?.kind === "name" && type.decoded === "Sig" || fieldType?.kind === "name" && fieldType.decoded === "Sig" || byteRange?.kind === "array" && dictGet(node, "Filter")?.kind === "name";
28315
- return {
28316
- kind: "dict",
28317
- entries: node.entries.map((e) => ({
28318
- key: e.key,
28319
- value: signature && e.key.decoded === "Contents" ? e.value : transformNodeStringsAndStreams(e.value, transform, transformStream)
28320
- }))
28321
- };
28330
+ const entries = [];
28331
+ for (const e of node.entries) entries.push({ key: e.key, value: signature && e.key.decoded === "Contents" ? e.value : yield* transformNodeStringsAndStreamsSteps(e.value, transform, transformStream) });
28332
+ return { kind: "dict", entries };
28322
28333
  }
28323
28334
  case "stream": {
28324
28335
  const type = dictGet(node.dict, "Type");
28325
28336
  if (type?.kind === "name" && type.decoded === "XRef") return node;
28326
28337
  const stream = transformStream ? transformStream(node) : { ...node, rawBytes: transform(node.rawBytes) };
28327
- const updatedDict = {
28328
- kind: "dict",
28329
- entries: stream.dict.entries.map((e) => ({
28330
- key: e.key,
28331
- value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : transformNodeStringsAndStreams(e.value, transform, transformStream)
28332
- }))
28333
- };
28334
- return {
28335
- kind: "stream",
28336
- dict: updatedDict,
28337
- rawBytes: stream.rawBytes
28338
- };
28338
+ const entries = [];
28339
+ for (const e of stream.dict.entries) entries.push({ key: e.key, value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : yield* transformNodeStringsAndStreamsSteps(e.value, transform, transformStream) });
28340
+ return { kind: "stream", dict: { kind: "dict", entries }, rawBytes: stream.rawBytes };
28339
28341
  }
28340
28342
  default:
28341
28343
  return node;
@@ -28404,7 +28406,8 @@ function createR6Encryption(userPassword, ownerPassword, pMask) {
28404
28406
  StrF: cosName("StdCF")
28405
28407
  }) };
28406
28408
  }
28407
- function encryptCosDocument(doc, options = {}) {
28409
+ function* encryptCosDocumentSteps(doc, options = {}) {
28410
+ yield;
28408
28411
  const userPassword = options.userPassword ?? "";
28409
28412
  const ownerPassword = options.ownerPassword ?? userPassword;
28410
28413
  const revision = options.revision ?? 6;
@@ -28426,14 +28429,15 @@ function encryptCosDocument(doc, options = {}) {
28426
28429
  const encryptObjNum = maxObjNum + 1;
28427
28430
  const encryptedObjects = [];
28428
28431
  for (const obj of doc.objects.values()) {
28429
- const transformed = transformNodeStringsAndStreams(
28432
+ yield;
28433
+ const transformed = yield* transformNodeStringsAndStreamsSteps(
28430
28434
  obj.value,
28431
28435
  (plain) => encryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, plain)
28432
28436
  );
28433
28437
  encryptedObjects.push({ objectNumber: obj.objectNumber, generationNumber: obj.generationNumber, value: transformed });
28434
28438
  }
28435
28439
  encryptedObjects.push({ objectNumber: encryptObjNum, generationNumber: 0, value: encryptDict });
28436
- return serializeCosDocument({
28440
+ return yield* serializeCosDocumentSteps({
28437
28441
  objects: encryptedObjects,
28438
28442
  rootRef: doc.rootRef,
28439
28443
  infoRef: doc.infoRef,
@@ -28483,17 +28487,19 @@ function decryptStream(doc, stream, transform) {
28483
28487
  }
28484
28488
  return { kind: "stream", dict, rawBytes: bytes };
28485
28489
  }
28486
- function decryptCosDocument(doc, state) {
28490
+ function* decryptCosDocumentSteps(doc, state) {
28491
+ yield;
28487
28492
  const encryptObjNum = doc.encryptRef?.objectNumber;
28488
28493
  const handler = securityHandlers.get(state);
28489
28494
  for (const [num, obj] of doc.objects.entries()) {
28495
+ yield;
28490
28496
  if (num === encryptObjNum || handler?.plaintextObjects.has(num)) continue;
28491
28497
  if (obj.value.kind === "stream") {
28492
28498
  const type = doc.resolve(dictGet(obj.value.dict, "Type"));
28493
28499
  if (type?.kind === "name" && (type.decoded === "XRef" || type.decoded === "Metadata" && !state.encryptMetadata)) continue;
28494
28500
  }
28495
28501
  const transform = handler?.factory.createCipherTransform(obj.objectNumber, obj.generationNumber);
28496
- const decrypted = transformNodeStringsAndStreams(
28502
+ const decrypted = yield* transformNodeStringsAndStreamsSteps(
28497
28503
  obj.value,
28498
28504
  (cipher) => decryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, cipher),
28499
28505
  transform ? (stream) => decryptStream(doc, stream, transform) : void 0
@@ -28607,9 +28613,12 @@ var ParsedCosDocument = class {
28607
28613
  return void 0;
28608
28614
  }
28609
28615
  };
28610
- function parseNodeFromLexer(lexer, bytes, maxDepth, repair = false) {
28616
+ function* parseNodeFromLexerSteps(lexer, bytes, maxDepth, repair = false) {
28617
+ yield;
28618
+ let work = 0;
28611
28619
  const stack = [];
28612
28620
  while (true) {
28621
+ if (++work % 16 === 0) yield;
28613
28622
  const tok = lexer.nextToken();
28614
28623
  const parent = stack.at(-1);
28615
28624
  if (!tok) {
@@ -28805,7 +28814,8 @@ function parseHeaderVersion(bytes) {
28805
28814
  }
28806
28815
  return head.slice(idx + 5, idx + 8);
28807
28816
  }
28808
- function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
28817
+ function* parseObjectAtOffsetSteps(bytes, offset, maxRecursionDepth, repair = false) {
28818
+ yield;
28809
28819
  const lexer = new CosByteLexer(bytes, offset);
28810
28820
  const objNumTok = lexer.nextToken();
28811
28821
  const genNumTok = lexer.nextToken();
@@ -28813,7 +28823,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
28813
28823
  if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
28814
28824
  throw new PdfError("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
28815
28825
  }
28816
- const value = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, repair);
28826
+ const value = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, repair);
28817
28827
  if (!value) {
28818
28828
  throw new PdfError("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
28819
28829
  }
@@ -28824,7 +28834,9 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
28824
28834
  span: { start: objNumTok.span.start, end: lexer.offset }
28825
28835
  };
28826
28836
  }
28827
- function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
28837
+ function* parseXrefRevisionAtSteps(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
28838
+ yield;
28839
+ let work = 0;
28828
28840
  if (xrefOffset < 0 || xrefOffset >= bytes.length) {
28829
28841
  throw new PdfError("E_PARSE", `Invalid xref offset: ${xrefOffset}`);
28830
28842
  }
@@ -28836,6 +28848,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28836
28848
  if (firstTok.kind === "keyword" && firstTok.value === "xref") {
28837
28849
  const entries2 = /* @__PURE__ */ new Map();
28838
28850
  while (true) {
28851
+ if (++work % 16 === 0) yield;
28839
28852
  const saved = lexer.offset;
28840
28853
  const tok = lexer.nextToken();
28841
28854
  if (!tok) {
@@ -28859,6 +28872,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28859
28872
  }
28860
28873
  if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
28861
28874
  for (let i = 0; i < count; i++) {
28875
+ if (++work % 16 === 0) yield;
28862
28876
  const offTok = lexer.nextToken();
28863
28877
  const genTok = lexer.nextToken();
28864
28878
  const flagTok = lexer.nextToken();
@@ -28884,7 +28898,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28884
28898
  if (entries2.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
28885
28899
  }
28886
28900
  }
28887
- const trailerNode = parseNodeFromLexer(lexer, bytes, maxRecursionDepth);
28901
+ const trailerNode = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth);
28888
28902
  if (!trailerNode || trailerNode.kind !== "dict") {
28889
28903
  throw new PdfError("E_PARSE", "Missing trailer dictionary after xref table");
28890
28904
  }
@@ -28896,7 +28910,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28896
28910
  previousXrefOffset: prevNode2?.kind === "number" ? prevNode2.value : void 0
28897
28911
  };
28898
28912
  }
28899
- const xrefObj = parseObjectAtOffset(bytes, xrefOffset, maxRecursionDepth);
28913
+ const xrefObj = yield* parseObjectAtOffsetSteps(bytes, xrefOffset, maxRecursionDepth);
28900
28914
  if (xrefObj.value.kind !== "stream") {
28901
28915
  throw new PdfError("E_PARSE", `Expected xref table or XRef stream at offset ${xrefOffset}`);
28902
28916
  }
@@ -28917,6 +28931,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28917
28931
  if (indexArray) {
28918
28932
  if (indexArray.kind !== "array" || indexArray.items.length % 2 !== 0) throw new PdfError("E_PARSE", "Invalid XRef range fields");
28919
28933
  for (let i = 0; i < indexArray.items.length; i += 2) {
28934
+ if (++work % 16 === 0) yield;
28920
28935
  const first = indexArray.items[i];
28921
28936
  const count = indexArray.items[i + 1];
28922
28937
  if (first?.kind !== "number" || count?.kind !== "number" || !Number.isSafeInteger(first.value) || first.value < 0 || !Number.isSafeInteger(count.value) || count.value < 0 || !Number.isSafeInteger(first.value + count.value)) {
@@ -28939,9 +28954,11 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
28939
28954
  return v;
28940
28955
  };
28941
28956
  for (const [startObj, count] of subsections) {
28957
+ if (++work % 16 === 0) yield;
28942
28958
  if (count > (decoded.length - pos) / stride) throw new PdfError("E_PARSE", "Truncated XRef stream");
28943
28959
  if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
28944
28960
  for (let i = 0; i < count; i++) {
28961
+ if (++work % 16 === 0) yield;
28945
28962
  const objNum = startObj + i;
28946
28963
  const field0 = w0 > 0 ? readInt(w0) : 1;
28947
28964
  const field1 = readInt(w1);
@@ -28987,12 +29004,16 @@ function isAsciiWhitespace(ch3) {
28987
29004
  function isAsciiDigit(ch3) {
28988
29005
  return ch3 >= 48 && ch3 <= 57;
28989
29006
  }
28990
- function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29007
+ function* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth) {
29008
+ yield;
29009
+ let work = 0;
28991
29010
  const objects = /* @__PURE__ */ new Map();
28992
29011
  const trailers = [];
28993
29012
  let pos = 0;
28994
29013
  while (pos < bytes.length) {
29014
+ if (++work % 16 === 0) yield;
28995
29015
  while (pos < bytes.length && !isAsciiDigit(bytes[pos])) {
29016
+ if (++work % 16 === 0) yield;
28996
29017
  if (bytes[pos] === 37) {
28997
29018
  while (pos < bytes.length && bytes[pos] !== 10 && bytes[pos] !== 13) pos++;
28998
29019
  continue;
@@ -29002,7 +29023,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29002
29023
  try {
29003
29024
  const token = lexer.nextToken();
29004
29025
  if (token?.kind === "keyword" && token.value === "trailer") {
29005
- const trailer = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, true);
29026
+ const trailer = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, true);
29006
29027
  if (trailer?.kind === "dict") trailers.push(trailer);
29007
29028
  pos = lexer.offset;
29008
29029
  continue;
@@ -29035,7 +29056,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29035
29056
  bytes[pos + 3] === 40)) {
29036
29057
  pos += 3;
29037
29058
  try {
29038
- const parsed = parseObjectAtOffset(bytes, headerStart, maxRecursionDepth, true);
29059
+ const parsed = yield* parseObjectAtOffsetSteps(bytes, headerStart, maxRecursionDepth, true);
29039
29060
  objects.set(parsed.objectNumber, parsed);
29040
29061
  if (parsed.value.kind === "stream") {
29041
29062
  const type = dictGet(parsed.value.dict, "Type");
@@ -29052,13 +29073,17 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29052
29073
  }
29053
29074
  return { objects, trailers };
29054
29075
  }
29055
- function unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
29076
+ function* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
29077
+ yield;
29078
+ let work = 0;
29056
29079
  for (const obj of [...objects.values()]) {
29080
+ if (++work % 16 === 0) yield;
29057
29081
  if (obj.value.kind === "stream") {
29058
29082
  const t = dictGet(obj.value.dict, "Type");
29059
29083
  if (t?.kind === "name" && t.decoded === "ObjStm") {
29060
29084
  try {
29061
- for (const [unpackedNum, unpackedVal] of unpackObjectStream(obj.value, maxDecompressedBytes, maxRecursionDepth, true).entries()) {
29085
+ for (const [unpackedNum, unpackedVal] of (yield* unpackObjectStreamSteps(obj.value, maxDecompressedBytes, maxRecursionDepth, true)).entries()) {
29086
+ if (++work % 16 === 0) yield;
29062
29087
  if (!objects.has(unpackedNum)) {
29063
29088
  objects.set(unpackedNum, {
29064
29089
  objectNumber: unpackedNum,
@@ -29094,7 +29119,9 @@ function recoveredReferences(objects) {
29094
29119
  }
29095
29120
  return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
29096
29121
  }
29097
- function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
29122
+ function* unpackObjectStreamSteps(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
29123
+ yield;
29124
+ let work = 0;
29098
29125
  const nNode = dictGet(streamObj.dict, "N");
29099
29126
  const firstNode = dictGet(streamObj.dict, "First");
29100
29127
  if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
@@ -29104,6 +29131,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29104
29131
  const headerLexer = new CosByteLexer(decoded, 0);
29105
29132
  const pairs = [];
29106
29133
  for (let i = 0; i < nNode.value; i++) {
29134
+ if (++work % 16 === 0) yield;
29107
29135
  const numTok = headerLexer.nextToken();
29108
29136
  const offTok = headerLexer.nextToken();
29109
29137
  if (numTok?.kind === "number" && offTok?.kind === "number") {
@@ -29112,9 +29140,10 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29112
29140
  }
29113
29141
  const result = /* @__PURE__ */ new Map();
29114
29142
  for (const pair of pairs) {
29143
+ if (++work % 16 === 0) yield;
29115
29144
  try {
29116
29145
  const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
29117
- const node = parseNodeFromLexer(valLexer, decoded, maxRecursionDepth, repair);
29146
+ const node = yield* parseNodeFromLexerSteps(valLexer, decoded, maxRecursionDepth, repair);
29118
29147
  if (node) {
29119
29148
  result.set(pair.objectNumber, node);
29120
29149
  }
@@ -29124,7 +29153,9 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29124
29153
  }
29125
29154
  return result;
29126
29155
  }
29127
- function parseCosDocument(bytes, options = {}) {
29156
+ function* parseCosDocumentSteps(bytes, options = {}) {
29157
+ yield;
29158
+ let work = 0;
29128
29159
  const version = parseHeaderVersion(bytes);
29129
29160
  const recovery = options.recovery ?? "strict";
29130
29161
  const maxObjects = options.maxObjects ?? Infinity;
@@ -29159,10 +29190,12 @@ function parseCosDocument(bytes, options = {}) {
29159
29190
  let currentXrefOffset = offsetTok.value;
29160
29191
  const visitedOffsets = /* @__PURE__ */ new Set();
29161
29192
  while (currentXrefOffset !== void 0 && !visitedOffsets.has(currentXrefOffset)) {
29193
+ if (++work % 16 === 0) yield;
29162
29194
  visitedOffsets.add(currentXrefOffset);
29163
- const rev = parseXrefRevisionAt(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
29195
+ const rev = yield* parseXrefRevisionAtSteps(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
29164
29196
  revisions.push(rev);
29165
29197
  for (const [num, entry] of rev.entries.entries()) {
29198
+ if (++work % 16 === 0) yield;
29166
29199
  if (!mergedXref.has(num)) {
29167
29200
  mergedXref.set(num, entry);
29168
29201
  if (mergedXref.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
@@ -29195,8 +29228,9 @@ function parseCosDocument(bytes, options = {}) {
29195
29228
  if (!useRepair && rootRef) {
29196
29229
  try {
29197
29230
  for (const [objNum, entry] of mergedXref.entries()) {
29231
+ if (++work % 16 === 0) yield;
29198
29232
  if (entry.type !== "uncompressed") continue;
29199
- const parsed = parseObjectAtOffset(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
29233
+ const parsed = yield* parseObjectAtOffsetSteps(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
29200
29234
  if (parsed.objectNumber !== objNum || parsed.generationNumber !== (entry.generationNumber ?? 0)) {
29201
29235
  throw new PdfError("E_PARSE", `Bad uncompressed XRef entry for object ${objNum}`);
29202
29236
  }
@@ -29214,7 +29248,7 @@ function parseCosDocument(bytes, options = {}) {
29214
29248
  throw new PdfError("E_PARSE", "PDF trailer missing /Root reference");
29215
29249
  }
29216
29250
  useRepair = true;
29217
- const scanned = repairScanCosDocument(bytes, maxObjects, maxRecursionDepth);
29251
+ const scanned = yield* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth);
29218
29252
  objects = scanned.objects;
29219
29253
  revisions.length = 0;
29220
29254
  mergedXref.clear();
@@ -29249,7 +29283,7 @@ function parseCosDocument(bytes, options = {}) {
29249
29283
  encryptNode = encrypt?.kind === "ref" || encrypt?.kind === "dict" ? encrypt : void 0;
29250
29284
  encryptRef = encrypt?.kind === "ref" ? encrypt : void 0;
29251
29285
  idArray = id?.kind === "array" ? id : void 0;
29252
- if (!rootRef && !encryptNode) unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29286
+ if (!rootRef && !encryptNode) yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29253
29287
  const fallback = recoveredReferences(objects);
29254
29288
  rootRef ??= fallback.rootRef;
29255
29289
  infoRef ??= fallback.infoRef;
@@ -29284,20 +29318,21 @@ function parseCosDocument(bytes, options = {}) {
29284
29318
  maxRecursionDepth
29285
29319
  });
29286
29320
  doc.encryption = encState;
29287
- decryptCosDocument(doc, encState);
29321
+ yield* decryptCosDocumentSteps(doc, encState);
29288
29322
  }
29289
29323
  if (useRepair) {
29290
- unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29324
+ yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29291
29325
  doc.infoRef ??= recoveredReferences(objects).infoRef;
29292
29326
  }
29293
29327
  const objStmCache = /* @__PURE__ */ new Map();
29294
29328
  for (const [objNum, entry] of mergedXref.entries()) {
29329
+ if (++work % 16 === 0) yield;
29295
29330
  if (entry.type === "compressed" && entry.objectStreamNumber !== void 0) {
29296
29331
  let unpacked = objStmCache.get(entry.objectStreamNumber);
29297
29332
  if (!unpacked) {
29298
29333
  const stmObj = objects.get(entry.objectStreamNumber)?.value;
29299
29334
  if (stmObj?.kind === "stream") {
29300
- unpacked = unpackObjectStream(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
29335
+ unpacked = yield* unpackObjectStreamSteps(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
29301
29336
  objStmCache.set(entry.objectStreamNumber, unpacked);
29302
29337
  }
29303
29338
  }
@@ -29314,6 +29349,9 @@ function parseCosDocument(bytes, options = {}) {
29314
29349
  }
29315
29350
  return doc;
29316
29351
  }
29352
+ function parseCosDocument(bytes, options = {}) {
29353
+ return drainWork(parseCosDocumentSteps(bytes, options));
29354
+ }
29317
29355
  var WIN_ANSI_HIGH_BYTES = {
29318
29356
  128: 8364,
29319
29357
  130: 8218,
@@ -40344,7 +40382,8 @@ function resolveInheritedFieldEntry(doc, dict, key) {
40344
40382
  }
40345
40383
  return void 0;
40346
40384
  }
40347
- function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
40385
+ function* collectFieldDictsSteps(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen, yieldState = { work: 0 }) {
40386
+ if (++yieldState.work % 256 === 0) yield;
40348
40387
  const dict = doc.resolveDict(node);
40349
40388
  if (!dict) return out;
40350
40389
  const tNode = doc.resolve(dictGet(dict, "T"));
@@ -40377,7 +40416,8 @@ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", pare
40377
40416
  return out;
40378
40417
  }
40379
40418
  for (const kid of kidsArr.items) {
40380
- collectFieldDicts(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen);
40419
+ if (++yieldState.work % 16 === 0) yield;
40420
+ yield* collectFieldDictsSteps(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen, yieldState);
40381
40421
  }
40382
40422
  } else if (fullName) {
40383
40423
  out.push({
@@ -40806,7 +40846,9 @@ function setDocumentFormField(doc, fieldName, value) {
40806
40846
  const fieldRef = doc.allocateObject(newFieldDict);
40807
40847
  fieldsArr.items.push(fieldRef);
40808
40848
  }
40809
- function generateDocumentFormAppearances(doc) {
40849
+ function* generateDocumentFormAppearancesSteps(doc) {
40850
+ yield;
40851
+ let work = 0;
40810
40852
  const catalog = doc.resolveDict(doc.rootRef);
40811
40853
  if (!catalog) return;
40812
40854
  const acroForm = doc.resolveDict(dictGet(catalog, "AcroForm"));
@@ -40817,9 +40859,11 @@ function generateDocumentFormAppearances(doc) {
40817
40859
  if (fieldsArr) {
40818
40860
  const all = [];
40819
40861
  for (const item of fieldsArr.items) {
40820
- collectFieldDicts(doc, item, "", all);
40862
+ if (++work % 16 === 0) yield;
40863
+ yield* collectFieldDictsSteps(doc, item, "", all);
40821
40864
  }
40822
40865
  for (const entry of all) {
40866
+ if (++work % 16 === 0) yield;
40823
40867
  const ftNode = doc.resolve(dictGet(entry.dict, "FT"));
40824
40868
  const ft = entry.inheritedFt || (ftNode?.kind === "name" ? ftNode.decoded : "");
40825
40869
  const vNode = doc.resolve(dictGet(entry.dict, "V"));
@@ -40869,6 +40913,7 @@ function generateDocumentFormAppearances(doc) {
40869
40913
  const optArr = doc.resolveArray(dictGet(entry.dict, "Opt"));
40870
40914
  if (optArr) {
40871
40915
  for (const optItem of optArr.items) {
40916
+ if (++work % 16 === 0) yield;
40872
40917
  const resolvedOpt = doc.resolve(optItem);
40873
40918
  if (resolvedOpt?.kind === "array" && resolvedOpt.items.length >= 2) {
40874
40919
  const expNode = doc.resolve(resolvedOpt.items[0]);
@@ -40897,6 +40942,7 @@ function generateDocumentFormAppearances(doc) {
40897
40942
  const kidsArr = doc.resolveArray(dictGet(entry.dict, "Kids"));
40898
40943
  if (kidsArr) {
40899
40944
  for (const kid of kidsArr.items) {
40945
+ if (++work % 16 === 0) yield;
40900
40946
  const kidDict = doc.resolveDict(kid);
40901
40947
  if (kidDict && !dictGet(kidDict, "T")) {
40902
40948
  synthesizeTextAppearanceStream(
@@ -40928,6 +40974,9 @@ function escapePdfLiteralString(str) {
40928
40974
  }
40929
40975
  return out;
40930
40976
  }
40977
+ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
40978
+ drainWork(collectFieldDictsSteps(doc, node, prefix, out, parentFt, parentFf, parentQ, parentMaxLen));
40979
+ }
40931
40980
  var PdfPage = class {
40932
40981
  cosDoc;
40933
40982
  pageRef;
@@ -43381,14 +43430,18 @@ var PdfDocument = class _PdfDocument {
43381
43430
  });
43382
43431
  return new _PdfDocument(parseCosDocument(rawBytes));
43383
43432
  }
43384
- static load(bytes, options) {
43433
+ static *loadSteps(bytes, options) {
43434
+ yield;
43385
43435
  return new _PdfDocument(
43386
- parseCosDocument(bytes, {
43436
+ yield* parseCosDocumentSteps(bytes, {
43387
43437
  ...options,
43388
43438
  recovery: options?.recovery ?? "repair"
43389
43439
  })
43390
43440
  );
43391
43441
  }
43442
+ static load(bytes, options) {
43443
+ return drainWork(_PdfDocument.loadSteps(bytes, options));
43444
+ }
43392
43445
  rebuildPagesList() {
43393
43446
  const catalog = this.cos.resolveDict(this.cos.rootRef);
43394
43447
  const pagesNode = catalog ? dictGet(catalog, "Pages") : void 0;
@@ -43470,20 +43523,30 @@ var PdfDocument = class _PdfDocument {
43470
43523
  this.pages.splice(index, 1);
43471
43524
  this.syncPageTree();
43472
43525
  }
43473
- copyPagesFrom(sourceDoc, indices) {
43526
+ *copyPagesFromSteps(sourceDoc, indices) {
43527
+ function* cloneItems(items) {
43528
+ const result = [];
43529
+ for (const item of items) result.push(yield* cloneNode(item));
43530
+ return result;
43531
+ }
43532
+ yield;
43533
+ let work = 0;
43474
43534
  const memo = /* @__PURE__ */ new Map();
43475
43535
  const sourcePageObjNums = /* @__PURE__ */ new Set();
43476
43536
  for (let i = 0; i < sourceDoc.getPageCount(); i++) {
43537
+ if (++work % 16 === 0) yield;
43477
43538
  sourcePageObjNums.add(sourceDoc.getPage(i).ref.objectNumber);
43478
43539
  }
43479
43540
  const targetPageRefs = [];
43480
43541
  for (const idx of indices) {
43542
+ if (++work % 16 === 0) yield;
43481
43543
  const srcPage = sourceDoc.getPage(idx);
43482
43544
  const pageRef = this.cos.allocateObject({ kind: "null" });
43483
43545
  targetPageRefs.push(pageRef);
43484
43546
  memo.set(srcPage.ref.objectNumber, pageRef);
43485
43547
  }
43486
- const cloneNode = (node) => {
43548
+ const cloneNode = function* (node) {
43549
+ if (++work % 16 === 0) yield;
43487
43550
  if (node.kind === "ref") {
43488
43551
  const existing = memo.get(node.objectNumber);
43489
43552
  if (existing) return existing;
@@ -43494,12 +43557,12 @@ var PdfDocument = class _PdfDocument {
43494
43557
  if (!target) return cosRef(0);
43495
43558
  const placeholderRef = this.cos.allocateObject({ kind: "null" });
43496
43559
  memo.set(node.objectNumber, placeholderRef);
43497
- const clonedTarget = cloneNode(target);
43560
+ const clonedTarget = yield* cloneNode(target);
43498
43561
  this.cos.setObject(placeholderRef.objectNumber, clonedTarget, 0);
43499
43562
  return placeholderRef;
43500
43563
  }
43501
43564
  if (node.kind === "array") {
43502
- return cosArray(node.items.map(cloneNode));
43565
+ return cosArray(yield* cloneItems(node.items));
43503
43566
  }
43504
43567
  if (node.kind === "dict") {
43505
43568
  const typeEntry = dictGet(node, "Type");
@@ -43509,13 +43572,13 @@ var PdfDocument = class _PdfDocument {
43509
43572
  if (isPageTreeNode && entry.key.decoded === "Parent") continue;
43510
43573
  newEntries.push({
43511
43574
  key: { ...entry.key },
43512
- value: cloneNode(entry.value)
43575
+ value: yield* cloneNode(entry.value)
43513
43576
  });
43514
43577
  }
43515
43578
  return { kind: "dict", entries: newEntries };
43516
43579
  }
43517
43580
  if (node.kind === "stream") {
43518
- const clonedDict = cloneNode(node.dict);
43581
+ const clonedDict = yield* cloneNode(node.dict);
43519
43582
  return {
43520
43583
  kind: "stream",
43521
43584
  dict: clonedDict,
@@ -43524,11 +43587,12 @@ var PdfDocument = class _PdfDocument {
43524
43587
  };
43525
43588
  }
43526
43589
  return node;
43527
- };
43590
+ }.bind(this);
43528
43591
  const copiedPages = [];
43529
43592
  for (const [position, idx] of indices.entries()) {
43593
+ if (++work % 16 === 0) yield;
43530
43594
  const srcPage = sourceDoc.getPage(idx);
43531
- const clonedPageDict = cloneNode(srcPage.pageDict);
43595
+ const clonedPageDict = yield* cloneNode(srcPage.pageDict);
43532
43596
  const size = srcPage.getSize();
43533
43597
  if (!dictGet(clonedPageDict, "MediaBox")) {
43534
43598
  dictSet(
@@ -43538,13 +43602,14 @@ var PdfDocument = class _PdfDocument {
43538
43602
  );
43539
43603
  }
43540
43604
  if (!dictGet(clonedPageDict, "Resources")) {
43541
- dictSet(clonedPageDict, "Resources", cloneNode(srcPage.getResourcesDict()));
43605
+ dictSet(clonedPageDict, "Resources", yield* cloneNode(srcPage.getResourcesDict()));
43542
43606
  }
43543
43607
  if (!dictGet(clonedPageDict, "Rotate") && srcPage.getRotation() !== 0) {
43544
43608
  dictSet(clonedPageDict, "Rotate", cosNumber(srcPage.getRotation()));
43545
43609
  }
43546
43610
  const inheritedBoxKeys = ["CropBox", "BleedBox", "TrimBox", "ArtBox"];
43547
43611
  for (const boxKey of inheritedBoxKeys) {
43612
+ if (++work % 16 === 0) yield;
43548
43613
  if (!dictGet(clonedPageDict, boxKey)) {
43549
43614
  const boxVal = boxKey === "CropBox" ? srcPage.getCropBox() : boxKey === "BleedBox" ? srcPage.getBleedBox() : boxKey === "TrimBox" ? srcPage.getTrimBox() : srcPage.getArtBox();
43550
43615
  if (boxVal[0] !== 0 || boxVal[1] !== 0 || boxVal[2] !== size.width || boxVal[3] !== size.height) {
@@ -43586,8 +43651,9 @@ var PdfDocument = class _PdfDocument {
43586
43651
  };
43587
43652
  const clonedRootFieldRefs = [];
43588
43653
  for (const item of srcFieldsArr.items) {
43654
+ if (++work % 16 === 0) yield;
43589
43655
  if (!hasClonedDescendant(item)) continue;
43590
- const cloned = cloneNode(item);
43656
+ const cloned = yield* cloneNode(item);
43591
43657
  if (cloned.kind === "ref") {
43592
43658
  const clonedDict = this.cos.resolveDict(cloned);
43593
43659
  const kidsArr = clonedDict ? this.cos.resolveArray(dictGet(clonedDict, "Kids")) : void 0;
@@ -43621,6 +43687,7 @@ var PdfDocument = class _PdfDocument {
43621
43687
  dstFields.items.filter((x) => x.kind === "ref").map((x) => x.objectNumber)
43622
43688
  );
43623
43689
  for (const fRef of clonedRootFieldRefs) {
43690
+ if (++work % 16 === 0) yield;
43624
43691
  if (!existingNums.has(fRef.objectNumber)) {
43625
43692
  dstFields.items.push(fRef);
43626
43693
  existingNums.add(fRef.objectNumber);
@@ -43628,11 +43695,11 @@ var PdfDocument = class _PdfDocument {
43628
43695
  }
43629
43696
  const srcDr = dictGet(srcAcroForm, "DR");
43630
43697
  if (srcDr && !dictGet(dstAcroForm, "DR")) {
43631
- dictSet(dstAcroForm, "DR", cloneNode(srcDr));
43698
+ dictSet(dstAcroForm, "DR", yield* cloneNode(srcDr));
43632
43699
  }
43633
43700
  const srcDa = dictGet(srcAcroForm, "DA");
43634
43701
  if (srcDa && !dictGet(dstAcroForm, "DA")) {
43635
- dictSet(dstAcroForm, "DA", cloneNode(srcDa));
43702
+ dictSet(dstAcroForm, "DA", yield* cloneNode(srcDa));
43636
43703
  }
43637
43704
  }
43638
43705
  }
@@ -43641,12 +43708,15 @@ var PdfDocument = class _PdfDocument {
43641
43708
  if (srcOcProps) {
43642
43709
  const dstCatalog = this.cos.resolveDict(this.cos.rootRef);
43643
43710
  if (dstCatalog && !dictGet(dstCatalog, "OCProperties")) {
43644
- dictSet(dstCatalog, "OCProperties", cloneNode(srcOcProps));
43711
+ dictSet(dstCatalog, "OCProperties", yield* cloneNode(srcOcProps));
43645
43712
  }
43646
43713
  }
43647
43714
  this.syncPageTree();
43648
43715
  return copiedPages;
43649
43716
  }
43717
+ copyPagesFrom(sourceDoc, indices) {
43718
+ return drainWork(this.copyPagesFromSteps(sourceDoc, indices));
43719
+ }
43650
43720
  embedStandardFont(fontName) {
43651
43721
  return createStandardFontHandle(fontName);
43652
43722
  }
@@ -43846,14 +43916,15 @@ var PdfDocument = class _PdfDocument {
43846
43916
  });
43847
43917
  return buildSemanticAstFromPages(extractedPages, tablesByPage, displayLists);
43848
43918
  }
43849
- save(options = {}) {
43919
+ *saveSteps(options = {}) {
43920
+ yield;
43850
43921
  this.syncPageTree();
43851
43922
  if (this.cos.requiresFullRewrite) {
43852
43923
  pruneUnusedXObjects(this.cos, this.pages);
43853
43924
  discardUnreachableObjects(this.cos);
43854
43925
  }
43855
43926
  if (options.encrypt) {
43856
- return encryptCosDocument(this.cos, options.encrypt);
43927
+ return yield* encryptCosDocumentSteps(this.cos, options.encrypt);
43857
43928
  }
43858
43929
  const allObjects = [...this.cos.objects.values()].sort(
43859
43930
  (a, b) => a.objectNumber - b.objectNumber
@@ -43861,7 +43932,7 @@ var PdfDocument = class _PdfDocument {
43861
43932
  if (options.incremental && !this.cos.requiresFullRewrite && this.cos.bytes.length > 0) {
43862
43933
  return appendIncrementalRevision(this.cos.bytes, this.cos, allObjects);
43863
43934
  }
43864
- return serializeCosDocument({
43935
+ return yield* serializeCosDocumentSteps({
43865
43936
  objects: allObjects,
43866
43937
  rootRef: this.cos.rootRef,
43867
43938
  infoRef: this.cos.infoRef,
@@ -43872,6 +43943,9 @@ var PdfDocument = class _PdfDocument {
43872
43943
  linearize: options.linearize
43873
43944
  });
43874
43945
  }
43946
+ save(options = {}) {
43947
+ return drainWork(this.saveSteps(options));
43948
+ }
43875
43949
  };
43876
43950
  function resolveDestinationPageIndex(doc, destOrActionNode) {
43877
43951
  const cos = doc.cos;
@@ -43993,6 +44067,13 @@ function replacePdfNameToken(content, oldName, newName) {
43993
44067
  }
43994
44068
  return out;
43995
44069
  }
44070
+ function resolveLimits(options) {
44071
+ const limits = { maxInputBytes: Infinity, maxOutputBytes: Infinity, maxArgumentBytes: Infinity, ...options.limits };
44072
+ for (const [name, value] of Object.entries(limits)) {
44073
+ if (value !== Infinity && (!Number.isSafeInteger(value) || value < 0)) throw new RangeError(`${name} limit must be a nonnegative safe integer or Infinity`);
44074
+ }
44075
+ return limits;
44076
+ }
43996
44077
  function parseSingleTokenPageNumber(tok, totalPages) {
43997
44078
  const trimmed = tok.trim();
43998
44079
  if (trimmed === "z") return totalPages;
@@ -44417,13 +44498,25 @@ function collectNumberTreeDicts(doc, treeDict, visited = /* @__PURE__ */ new Set
44417
44498
  }
44418
44499
  return out;
44419
44500
  }
44420
- async function runQpdfCli(argv, files, readStdin) {
44501
+ async function runQpdfCli(argv, files, readStdin, signal) {
44502
+ signal?.throwIfAborted();
44421
44503
  const parsed = parseQpdfArguments(argv);
44422
44504
  if (parsed.result) return parsed.result;
44423
44505
  const { inputFile, pageSpecs, stampSpecs, addAttachmentSpecs, copyAttachmentsSpecs, updateFromJsonFiles } = parsed.options;
44424
44506
  const usesStdin = inputFile === "-" || updateFromJsonFiles.includes("-") || [...pageSpecs, ...stampSpecs, ...addAttachmentSpecs, ...copyAttachmentsSpecs].some((spec) => spec.file === "-");
44425
44507
  if (readStdin && usesStdin) await readStdin();
44426
- return executeQpdfCli(parsed.options, files);
44508
+ const steps = executeQpdfCli(parsed.options, files);
44509
+ try {
44510
+ let step = steps.next();
44511
+ while (!step.done) {
44512
+ await yieldTurn(signal);
44513
+ signal?.throwIfAborted();
44514
+ step = steps.next();
44515
+ }
44516
+ return step.value;
44517
+ } finally {
44518
+ steps.return({ exitCode: 2, stdout: "", stderr: "" });
44519
+ }
44427
44520
  }
44428
44521
  function parseQpdfArguments(argv) {
44429
44522
  let check = false;
@@ -44845,9 +44938,12 @@ function parseQpdfArguments(argv) {
44845
44938
  function runQpdfCliSync(argv, files) {
44846
44939
  const parsed = parseQpdfArguments(argv);
44847
44940
  if (parsed.result) return parsed.result;
44848
- return executeQpdfCli(parsed.options, files);
44941
+ const steps = executeQpdfCli(parsed.options, files);
44942
+ let step = steps.next();
44943
+ while (!step.done) step = steps.next();
44944
+ return step.value;
44849
44945
  }
44850
- function executeQpdfCli(options, files) {
44946
+ function* executeQpdfCli(options, files) {
44851
44947
  const {
44852
44948
  check,
44853
44949
  showNpages,
@@ -44928,7 +45024,7 @@ function executeQpdfCli(options, files) {
44928
45024
  return { exitCode: 0, stdout: "", stderr: "" };
44929
45025
  }
44930
45026
  try {
44931
- parseCosDocument(raw, { password });
45027
+ yield* parseCosDocumentSteps(raw, { password });
44932
45028
  return { exitCode: 3, stdout: "", stderr: "" };
44933
45029
  } catch {
44934
45030
  return { exitCode: 0, stdout: "", stderr: "" };
@@ -44956,12 +45052,12 @@ function executeQpdfCli(options, files) {
44956
45052
  return { exitCode: 2, stdout: "", stderr: `qpdf: ${inputFile}: missing trailer /Root
44957
45053
  ` };
44958
45054
  }
44959
- const rebuiltBytes = serializeCosDocument({
45055
+ const rebuiltBytes = yield* serializeCosDocumentSteps({
44960
45056
  objects: [...objectsMap.values()],
44961
45057
  rootRef,
44962
45058
  infoRef
44963
45059
  });
44964
- baseDoc = PdfDocument.load(rebuiltBytes);
45060
+ baseDoc = yield* PdfDocument.loadSteps(rebuiltBytes);
44965
45061
  } catch (err2) {
44966
45062
  const msg = err2 instanceof Error ? err2.message : String(err2);
44967
45063
  return { exitCode: 2, stdout: "", stderr: `qpdf: ${inputFile}: ${msg}
@@ -44969,10 +45065,10 @@ function executeQpdfCli(options, files) {
44969
45065
  }
44970
45066
  } else {
44971
45067
  try {
44972
- baseDoc = PdfDocument.load(raw, password !== void 0 ? { password } : {});
45068
+ baseDoc = yield* PdfDocument.loadSteps(raw, password !== void 0 ? { password } : {});
44973
45069
  } catch {
44974
45070
  try {
44975
- baseDoc = PdfDocument.load(raw, {
45071
+ baseDoc = yield* PdfDocument.loadSteps(raw, {
44976
45072
  ...password !== void 0 ? { password } : {},
44977
45073
  recovery: "repair"
44978
45074
  });
@@ -45003,12 +45099,12 @@ function executeQpdfCli(options, files) {
45003
45099
  ` };
45004
45100
  }
45005
45101
  }
45006
- const updatedBytes = serializeCosDocument({
45102
+ const updatedBytes = yield* serializeCosDocumentSteps({
45007
45103
  objects: [...baseDoc.cos.objects.values()],
45008
45104
  rootRef: baseDoc.cos.rootRef,
45009
45105
  infoRef: baseDoc.cos.infoRef
45010
45106
  });
45011
- baseDoc = PdfDocument.load(updatedBytes);
45107
+ baseDoc = yield* PdfDocument.loadSteps(updatedBytes);
45012
45108
  }
45013
45109
  if (showLinearization) {
45014
45110
  const cos = baseDoc.cos;
@@ -45316,13 +45412,14 @@ extract for accessibility: ${enc.permissions.copy ? "allowed" : "not allowed"}
45316
45412
  }
45317
45413
  const loadedSpecs = [];
45318
45414
  for (const spec of pageSpecs) {
45415
+ yield;
45319
45416
  const srcBytes = loadBytes(spec.file);
45320
45417
  if (!srcBytes) {
45321
45418
  return { exitCode: 2, stdout: "", stderr: `qpdf: cannot open ${spec.file}
45322
45419
  ` };
45323
45420
  }
45324
45421
  const srcPw = spec.password ?? password;
45325
- const srcDoc = PdfDocument.load(srcBytes, srcPw !== void 0 ? { password: srcPw } : {});
45422
+ const srcDoc = yield* PdfDocument.loadSteps(srcBytes, srcPw !== void 0 ? { password: srcPw } : {});
45326
45423
  const pageNumbers = parseQpdfPageRange(spec.range, srcDoc.getPageCount());
45327
45424
  loadedSpecs.push({ doc: srcDoc, indices: pageNumbers.map((p) => p - 1) });
45328
45425
  }
@@ -45336,7 +45433,7 @@ extract for accessibility: ${enc.permissions.copy ? "allowed" : "not allowed"}
45336
45433
  const cur = cursors[s];
45337
45434
  if (cur < item.indices.length) {
45338
45435
  const slice = item.indices.slice(cur, cur + collateCount);
45339
- mergedDoc.copyPagesFrom(item.doc, slice);
45436
+ yield* mergedDoc.copyPagesFromSteps(item.doc, slice);
45340
45437
  cursors[s] = cur + slice.length;
45341
45438
  if (cursors[s] < item.indices.length) remaining = true;
45342
45439
  }
@@ -45344,7 +45441,7 @@ extract for accessibility: ${enc.permissions.copy ? "allowed" : "not allowed"}
45344
45441
  }
45345
45442
  } else {
45346
45443
  for (const item of loadedSpecs) {
45347
- mergedDoc.copyPagesFrom(item.doc, item.indices);
45444
+ yield* mergedDoc.copyPagesFromSteps(item.doc, item.indices);
45348
45445
  }
45349
45446
  }
45350
45447
  workingDoc = mergedDoc;
@@ -45352,6 +45449,7 @@ extract for accessibility: ${enc.permissions.copy ? "allowed" : "not allowed"}
45352
45449
  for (const rot of rotateSpecs) {
45353
45450
  const pageNums = parseQpdfPageRange(rot.range, workingDoc.getPageCount());
45354
45451
  for (const pNum of pageNums) {
45452
+ yield;
45355
45453
  const page = workingDoc.getPage(pNum - 1);
45356
45454
  if (rot.relative) {
45357
45455
  const current = page.getRotation();
@@ -45372,7 +45470,7 @@ extract for accessibility: ${enc.permissions.copy ? "allowed" : "not allowed"}
45372
45470
  ` };
45373
45471
  }
45374
45472
  const stampPw = stamp.password ?? password;
45375
- const stampDoc = PdfDocument.load(stampBytes, stampPw !== void 0 ? { password: stampPw } : {});
45473
+ const stampDoc = yield* PdfDocument.loadSteps(stampBytes, stampPw !== void 0 ? { password: stampPw } : {});
45376
45474
  const fromPages = parseQpdfPageRange(stamp.fromRange, stampDoc.getPageCount());
45377
45475
  const toPages = parseQpdfPageRange(stamp.toRange, workingDoc.getPageCount());
45378
45476
  const repeatPages = stamp.repeatRange ? parseQpdfPageRange(stamp.repeatRange, stampDoc.getPageCount()) : fromPages;
@@ -45508,6 +45606,7 @@ ${fmt6(s)} 0 0 ${fmt6(s)} ${fmt4(tx)} ${fmt4(ty)} cm
45508
45606
  if (flattenRotation) {
45509
45607
  const enc = new TextEncoder();
45510
45608
  for (const page of workingDoc.getPages()) {
45609
+ yield;
45511
45610
  const rot = page.getRotation();
45512
45611
  if (rot === 90 || rot === 180 || rot === 270) {
45513
45612
  const { width: W, height: H } = page.getSize();
@@ -45576,6 +45675,7 @@ ${fmt6(s)} 0 0 ${fmt6(s)} ${fmt4(tx)} ${fmt4(ty)} cm
45576
45675
  if (flattenAnnotations !== false) {
45577
45676
  const enc = new TextEncoder();
45578
45677
  for (const page of workingDoc.getPages()) {
45678
+ yield;
45579
45679
  const annotsNode = workingDoc.cos.resolve(dictGet(page.dict, "Annots"));
45580
45680
  const annotsArr = asArray(annotsNode);
45581
45681
  if (!annotsArr) continue;
@@ -45754,6 +45854,7 @@ Q
45754
45854
  };
45755
45855
  let extCounter = 1;
45756
45856
  for (const page of workingDoc.getPages()) {
45857
+ yield;
45757
45858
  let modified = false;
45758
45859
  const pageRes = page.getResourcesDict();
45759
45860
  let xobjSub = asDict(workingDoc.cos.resolve(dictGet(pageRes, "XObject")));
@@ -45839,6 +45940,7 @@ Q
45839
45940
  "Properties"
45840
45941
  ];
45841
45942
  for (const page of workingDoc.getPages()) {
45943
+ yield;
45842
45944
  const refNames = /* @__PURE__ */ new Set();
45843
45945
  collectPdfNamesFromBytes(page.getRawContentStream(), refNames);
45844
45946
  const annotsArr = asArray(workingDoc.cos.resolve(dictGet(page.dict, "Annots")));
@@ -45928,7 +46030,7 @@ Q
45928
46030
  }
45929
46031
  }
45930
46032
  if (generateAppearances && !removeAcroform) {
45931
- generateDocumentFormAppearances(workingDoc.cos);
46033
+ yield* generateDocumentFormAppearancesSteps(workingDoc.cos);
45932
46034
  }
45933
46035
  if (removeInfo || removeMetadata || removeStructure || removeAcroform) {
45934
46036
  const rootDict = asDict(workingDoc.cos.resolve(workingDoc.cos.rootRef));
@@ -45957,12 +46059,13 @@ Q
45957
46059
  }
45958
46060
  }
45959
46061
  for (const copySpec of copyAttachmentsSpecs) {
46062
+ yield;
45960
46063
  const srcBytes = loadBytes(copySpec.file);
45961
46064
  if (!srcBytes) {
45962
46065
  return { exitCode: 2, stdout: "", stderr: `qpdf: cannot open ${copySpec.file}
45963
46066
  ` };
45964
46067
  }
45965
- const srcDoc = PdfDocument.load(srcBytes, copySpec.password ? { password: copySpec.password } : {});
46068
+ const srcDoc = yield* PdfDocument.loadSteps(srcBytes, copySpec.password ? { password: copySpec.password } : {});
45966
46069
  const srcRoot = asDict(srcDoc.cos.resolve(srcDoc.cos.rootRef));
45967
46070
  const srcNames = srcRoot ? asDict(srcDoc.cos.resolve(dictGet(srcRoot, "Names"))) : void 0;
45968
46071
  const srcEf = srcNames ? asDict(srcDoc.cos.resolve(dictGet(srcNames, "EmbeddedFiles"))) : void 0;
@@ -46092,6 +46195,7 @@ Q
46092
46195
  namesArr = asArray(dictGet(efTree, "Names"));
46093
46196
  }
46094
46197
  for (const addSpec of addAttachmentSpecs) {
46198
+ yield;
46095
46199
  const attBytes = loadBytes(addSpec.file);
46096
46200
  if (!attBytes) {
46097
46201
  return { exitCode: 2, stdout: "", stderr: `qpdf: cannot open attachment ${addSpec.file}
@@ -46190,6 +46294,7 @@ Q
46190
46294
  return replaced ? out : void 0;
46191
46295
  };
46192
46296
  for (let startIdx = 0; startIdx < total; startIdx += splitPagesGroup) {
46297
+ yield;
46193
46298
  const endIdx = Math.min(total - 1, startIdx + splitPagesGroup - 1);
46194
46299
  const subDoc = PdfDocument.create();
46195
46300
  if (wMeta.title) subDoc.setTitle(wMeta.title);
@@ -46198,24 +46303,24 @@ Q
46198
46303
  if (wMeta.keywords) subDoc.setKeywords(wMeta.keywords);
46199
46304
  const indices = [];
46200
46305
  for (let k = startIdx; k <= endIdx; k++) indices.push(k);
46201
- subDoc.copyPagesFrom(workingDoc, indices);
46306
+ yield* subDoc.copyPagesFromSteps(workingDoc, indices);
46202
46307
  const sPad = String(startIdx + 1).padStart(padLen, "0");
46203
46308
  const ePad = String(endIdx + 1).padStart(padLen, "0");
46204
46309
  const suffix = splitPagesGroup === 1 ? sPad : `${sPad}-${ePad}`;
46205
46310
  const formattedSpec = formatSplitSpec(finalTarget, startIdx + 1, endIdx + 1);
46206
46311
  const splitName = formattedSpec ?? `${baseStem}-${suffix}.pdf`;
46207
- files.set(splitName, subDoc.save({ normalizeContent: qdf }));
46312
+ files.set(splitName, yield* subDoc.saveSteps({ normalizeContent: qdf }));
46208
46313
  }
46209
46314
  return { exitCode: 0, stdout: "", stderr: "" };
46210
46315
  }
46211
46316
  const shouldNormalizeContent = normalizeContentFlag !== void 0 ? normalizeContentFlag : qdf || streamDataMode === "uncompress";
46212
- let outBytes = workingDoc.save({
46317
+ let outBytes = yield* workingDoc.saveSteps({
46213
46318
  normalizeContent: shouldNormalizeContent,
46214
46319
  objectStreams: objectStreamsMode
46215
46320
  });
46216
46321
  if (encryptConfig && !decrypt2) {
46217
- const parsedOut = parseCosDocument(outBytes);
46218
- outBytes = encryptCosDocument(parsedOut, {
46322
+ const parsedOut = yield* parseCosDocumentSteps(outBytes);
46323
+ outBytes = yield* encryptCosDocumentSteps(parsedOut, {
46219
46324
  userPassword: encryptConfig.userPassword,
46220
46325
  ownerPassword: encryptConfig.ownerPassword,
46221
46326
  permissions: {
@@ -46228,7 +46333,7 @@ Q
46228
46333
  } else if (decrypt2 && workingDoc.cos.encryption) {
46229
46334
  workingDoc.cos.encryptRef = void 0;
46230
46335
  workingDoc.cos.encryption = void 0;
46231
- outBytes = serializeCosDocument({
46336
+ outBytes = yield* serializeCosDocumentSteps({
46232
46337
  objects: [...workingDoc.cos.objects.values()],
46233
46338
  rootRef: workingDoc.cos.rootRef,
46234
46339
  infoRef: workingDoc.cos.infoRef
@@ -46237,12 +46342,20 @@ Q
46237
46342
  files.set(finalTarget, outBytes);
46238
46343
  return { exitCode: repairedWarning && !warningExit0 ? 3 : 0, stdout: "", stderr: "" };
46239
46344
  }
46240
- async function qpdf(context) {
46345
+ async function qpdf(context, options = {}) {
46346
+ const limits = resolveLimits(options);
46347
+ let outputBytes = 0;
46348
+ const chargeOutput = (bytes) => {
46349
+ outputBytes += bytes;
46350
+ if (outputBytes > limits.maxOutputBytes) throw new RangeError("Output byte limit exceeded");
46351
+ };
46241
46352
  const invocation = createOutputOperation(context, { write: async () => {
46242
46353
  } });
46243
46354
  try {
46244
46355
  const carrier = getCommandArguments(context);
46245
46356
  const argv = [...carrier.args];
46357
+ const argumentBytes = argv.reduce((total, arg) => total + new TextEncoder().encode(arg).byteLength + 1, 0);
46358
+ if (argumentBytes > limits.maxArgumentBytes) throw new RangeError("Argument byte limit exceeded");
46246
46359
  const vfsFiles = /* @__PURE__ */ new Map();
46247
46360
  const resolveVfsPath = (p) => p.startsWith("/") ? p : `${context.cwd === "/" ? "" : context.cwd}/${p}`;
46248
46361
  let accountedBytes = 0;
@@ -46250,6 +46363,7 @@ async function qpdf(context) {
46250
46363
  if (delta > 0) {
46251
46364
  accountedBytes += delta;
46252
46365
  context.inputBudget?.check(accountedBytes);
46366
+ if (accountedBytes > limits.maxInputBytes) throw new RangeError("Input byte limit exceeded");
46253
46367
  }
46254
46368
  };
46255
46369
  for (let i = 0; i < argv.length; i++) {
@@ -46270,39 +46384,49 @@ async function qpdf(context) {
46270
46384
  i += args.length - 1;
46271
46385
  }
46272
46386
  for (const token of argv) {
46387
+ await yieldTurn(invocation.signal);
46388
+ invocation.signal.throwIfAborted();
46273
46389
  let candidate = token;
46274
- if (token.startsWith("--overlay=") || token.startsWith("--underlay=") || token.startsWith("--update-from-json=")) {
46390
+ if (token.startsWith("--overlay=") || token.startsWith("--underlay=") || token.startsWith("--add-attachment=") || token.startsWith("--copy-attachments-from=") || token.startsWith("--update-from-json=")) {
46275
46391
  candidate = token.slice(token.indexOf("=") + 1);
46276
46392
  } else if (token.startsWith("-") || token === "--" || token === ".") {
46277
46393
  continue;
46278
46394
  }
46279
46395
  const abs = resolveVfsPath(candidate);
46396
+ let bytes;
46280
46397
  try {
46281
- const bytes = await context.fs.readFile(abs, { signal: invocation.signal });
46282
- chargeBytes(bytes.byteLength);
46283
- vfsFiles.set(candidate, bytes);
46398
+ bytes = await context.fs.readFile(abs, { signal: invocation.signal });
46284
46399
  } catch {
46400
+ invocation.signal.throwIfAborted();
46401
+ continue;
46285
46402
  }
46403
+ chargeBytes(bytes.byteLength);
46404
+ vfsFiles.set(candidate, bytes);
46286
46405
  }
46287
46406
  if (argv.includes("--json-input") || argv.some((t) => t.startsWith("--update-from-json="))) {
46288
46407
  for (const fileBytes of [...vfsFiles.values()]) {
46408
+ let parsed;
46289
46409
  try {
46290
- const parsed = JSON.parse(new TextDecoder().decode(fileBytes));
46291
- const objs = Array.isArray(parsed.qpdf) && typeof parsed.qpdf[1] === "object" ? parsed.qpdf[1] : typeof parsed.objects === "object" && parsed.objects !== null ? parsed.objects : void 0;
46292
- if (!objs) continue;
46293
- for (const entry of Object.values(objs)) {
46294
- if (typeof entry === "object" && entry !== null && "stream" in entry) {
46295
- const st = entry.stream;
46296
- if (st && typeof st.datafile === "string" && !vfsFiles.has(st.datafile)) {
46297
- const dfBytes = await context.fs.readFile(resolveVfsPath(st.datafile), {
46298
- signal: invocation.signal
46299
- });
46300
- chargeBytes(dfBytes.byteLength);
46301
- vfsFiles.set(st.datafile, dfBytes);
46302
- }
46303
- }
46304
- }
46410
+ parsed = JSON.parse(new TextDecoder().decode(fileBytes));
46305
46411
  } catch {
46412
+ continue;
46413
+ }
46414
+ if (!parsed || typeof parsed !== "object") continue;
46415
+ const objs = Array.isArray(parsed.qpdf) && typeof parsed.qpdf[1] === "object" ? parsed.qpdf[1] : typeof parsed.objects === "object" && parsed.objects !== null ? parsed.objects : void 0;
46416
+ if (!objs) continue;
46417
+ for (const entry of Object.values(objs)) {
46418
+ if (typeof entry !== "object" || entry === null || !("stream" in entry)) continue;
46419
+ const stream = entry.stream;
46420
+ if (!stream || typeof stream.datafile !== "string" || vfsFiles.has(stream.datafile)) continue;
46421
+ let bytes;
46422
+ try {
46423
+ bytes = await context.fs.readFile(resolveVfsPath(stream.datafile), { signal: invocation.signal });
46424
+ } catch {
46425
+ invocation.signal.throwIfAborted();
46426
+ continue;
46427
+ }
46428
+ chargeBytes(bytes.byteLength);
46429
+ vfsFiles.set(stream.datafile, bytes);
46306
46430
  }
46307
46431
  }
46308
46432
  }
@@ -46323,19 +46447,19 @@ async function qpdf(context) {
46323
46447
  }
46324
46448
  vfsFiles.set("-", bytes);
46325
46449
  existingSnap.set("-", bytes);
46326
- });
46450
+ }, invocation.signal);
46327
46451
  if (res.stderr) {
46328
46452
  await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
46329
46453
  }
46330
46454
  if (res.stdout) {
46331
46455
  const outBytes = new TextEncoder().encode(res.stdout);
46332
- chargeBytes(outBytes.byteLength);
46456
+ chargeOutput(outBytes.byteLength);
46333
46457
  const stdout = invocation.child(context.stdout);
46334
46458
  await writeBytes(stdout.output, outBytes, invocation.signal);
46335
46459
  }
46336
46460
  for (const [fileKey, fileBytes] of vfsFiles.entries()) {
46337
46461
  if (existingSnap.get(fileKey) !== fileBytes) {
46338
- chargeBytes(fileBytes.byteLength);
46462
+ chargeOutput(fileBytes.byteLength);
46339
46463
  if (fileKey === "-") {
46340
46464
  const stdout = invocation.child(context.stdout);
46341
46465
  await writeBytes(stdout.output, fileBytes, invocation.signal);
@@ -46350,13 +46474,13 @@ async function qpdf(context) {
46350
46474
  await invocation.close();
46351
46475
  }
46352
46476
  }
46353
- function createQpdfCommand(_options = {}) {
46477
+ function createQpdfCommand(options = {}) {
46354
46478
  return Object.freeze({
46355
46479
  name: "qpdf",
46356
46480
  runtimeIdentity: commandRuntimeIdentity,
46357
46481
  description: "Structural PDF inspection, encryption, page selection, and transformation via @poe-code/pdf-ast",
46358
46482
  execute(context) {
46359
- return qpdf(context);
46483
+ return qpdf(context, options);
46360
46484
  }
46361
46485
  });
46362
46486
  }