@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,8 @@ import {
4
4
 
5
5
  // packages/safe-bash-command-pdftoppm/dist/index.js
6
6
  init_buffer();
7
+ import { yieldTurn, drainCooperativeSteps as drainSteps } from "../safe-bash-contracts/yield.js";
8
+ import { InputByteBudget } from "../safe-bash-contracts/io.js";
7
9
  import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
8
10
  import {
9
11
  commandRuntimeIdentity,
@@ -27294,6 +27296,11 @@ function tokenizeCos(bytes, start = 0, end = bytes.length) {
27294
27296
  }
27295
27297
  return tokens;
27296
27298
  }
27299
+ function drainWork(work) {
27300
+ let step = work.next();
27301
+ while (!step.done) step = work.next();
27302
+ return step.value;
27303
+ }
27297
27304
  function bytesToString3(bytes) {
27298
27305
  if (typeof bytes !== "object" || bytes?.length === void 0) {
27299
27306
  throw new Error("Invalid argument for bytesToString");
@@ -27889,7 +27896,9 @@ function concatByteArrays(chunks) {
27889
27896
  }
27890
27897
  return out;
27891
27898
  }
27892
- function serializeCosDocument(options) {
27899
+ function* serializeCosDocumentSteps(options) {
27900
+ yield;
27901
+ let work = 0;
27893
27902
  const maxOutputBytes = options.maxOutputBytes ?? Infinity;
27894
27903
  const maxObjects = options.maxObjects ?? Infinity;
27895
27904
  const sorted = [...options.objects].sort((a, b) => a.objectNumber - b.objectNumber);
@@ -27912,6 +27921,7 @@ function serializeCosDocument(options) {
27912
27921
  const packable = [];
27913
27922
  const direct = [];
27914
27923
  for (const obj of sorted) {
27924
+ if (++work % 16 === 0) yield;
27915
27925
  const isLinearized = obj.value.kind === "dict" && dictGet(obj.value, "Linearized") !== void 0;
27916
27926
  if (obj.value.kind !== "stream" && obj.generationNumber === 0 && !isLinearized) {
27917
27927
  packable.push(obj);
@@ -27926,6 +27936,7 @@ function serializeCosDocument(options) {
27926
27936
  const headerPairs = [];
27927
27937
  let relOffset = 0;
27928
27938
  for (const pObj of packable) {
27939
+ if (++work % 16 === 0) yield;
27929
27940
  headerPairs.push(`${pObj.objectNumber} ${relOffset}`);
27930
27941
  const bBytes = serializeCosNodeBytes(pObj.value);
27931
27942
  const nl = textEncoder2.encode("\n");
@@ -27951,6 +27962,7 @@ function serializeCosDocument(options) {
27951
27962
  ];
27952
27963
  const directOffsets = /* @__PURE__ */ new Map();
27953
27964
  for (const dObj of allDirect) {
27965
+ if (++work % 16 === 0) yield;
27954
27966
  directOffsets.set(dObj.objectNumber, { offset, generation: dObj.generationNumber });
27955
27967
  const prefix = textEncoder2.encode(`${dObj.objectNumber} ${dObj.generationNumber} obj
27956
27968
  `);
@@ -27961,6 +27973,7 @@ function serializeCosDocument(options) {
27961
27973
  }
27962
27974
  const compressedMap = /* @__PURE__ */ new Map();
27963
27975
  for (let idx = 0; idx < packable.length; idx++) {
27976
+ if (++work % 16 === 0) yield;
27964
27977
  compressedMap.set(packable[idx].objectNumber, idx);
27965
27978
  }
27966
27979
  const xrefOffset2 = offset;
@@ -27978,6 +27991,7 @@ function serializeCosDocument(options) {
27978
27991
  };
27979
27992
  writeEntry7(0, 0, 0, 65535);
27980
27993
  for (let i = 1; i < size2; i++) {
27994
+ if (++work % 16 === 0) yield;
27981
27995
  if (i === xrefStmNum) {
27982
27996
  writeEntry7(i, 1, xrefOffset2, 0);
27983
27997
  } else if (compressedMap.has(i)) {
@@ -28058,6 +28072,7 @@ ${xrefOffset2}
28058
28072
  let pageCount = 0;
28059
28073
  let firstPageObjNum = options.rootRef.objectNumber;
28060
28074
  for (const o of sorted) {
28075
+ if (++work % 16 === 0) yield;
28061
28076
  if (o.value.kind === "dict") {
28062
28077
  const t = dictGet(o.value, "Type");
28063
28078
  if (t?.kind === "name" && t.decoded === "Page") {
@@ -28105,6 +28120,7 @@ ${xrefOffset2}
28105
28120
  }
28106
28121
  const objectOffsets = /* @__PURE__ */ new Map();
28107
28122
  for (const obj of sorted) {
28123
+ if (++work % 16 === 0) yield;
28108
28124
  objectOffsets.set(obj.objectNumber, { offset, generation: obj.generationNumber });
28109
28125
  let value = obj.value;
28110
28126
  if (options.normalizeContent && value.kind === "stream" && value.decodedBytes) {
@@ -28136,6 +28152,7 @@ ${xrefOffset2}
28136
28152
  0000000000 65535 f
28137
28153
  `;
28138
28154
  for (let i = 1; i < size; i++) {
28155
+ if (++work % 16 === 0) yield;
28139
28156
  const entry = objectOffsets.get(i);
28140
28157
  if (entry) {
28141
28158
  xrefText += `${String(entry.offset).padStart(10, "0")} ${String(entry.generation).padStart(5, "0")} n
@@ -28182,6 +28199,7 @@ ${xrefOffset}
28182
28199
  let endFirstPage = xrefOffset;
28183
28200
  const sortedOffsets = [...objectOffsets.entries()].sort((a, b) => a[1].offset - b[1].offset);
28184
28201
  for (let i = 0; i < sortedOffsets.length; i++) {
28202
+ if (++work % 16 === 0) yield;
28185
28203
  const [objNum, info3] = sortedOffsets[i];
28186
28204
  const nextOff = sortedOffsets[i + 1]?.[1].offset ?? xrefOffset;
28187
28205
  if (objNum === hintObjAfter.objectNumber) {
@@ -28215,6 +28233,9 @@ ${xrefOffset}
28215
28233
  }
28216
28234
  return fullBytes;
28217
28235
  }
28236
+ function serializeCosDocument(options) {
28237
+ return drainWork(serializeCosDocumentSteps(options));
28238
+ }
28218
28239
  function appendIncrementalRevision(originalBytes, doc, updatedObjects) {
28219
28240
  const chunks = [originalBytes, textEncoder2.encode("\n")];
28220
28241
  let offset = originalBytes.length + 1;
@@ -28488,48 +28509,30 @@ function encryptPdfBuffer(state, objectNumber, generationNumber, plaintext) {
28488
28509
  const objKey = md5Bytes([state.fileKey, suffix]).subarray(0, Math.min(16, state.fileKey.length + 5));
28489
28510
  return rc4Transform(objKey, plaintext);
28490
28511
  }
28491
- function transformNodeStringsAndStreams(node, transform, transformStream) {
28512
+ function* transformNodeStringsAndStreamsSteps(node, transform, transformStream) {
28513
+ yield;
28492
28514
  switch (node.kind) {
28493
28515
  case "string":
28494
- return {
28495
- kind: "string",
28496
- format: "hex",
28497
- bytes: transform(node.bytes)
28498
- };
28499
- case "array":
28500
- return {
28501
- kind: "array",
28502
- items: node.items.map((item) => transformNodeStringsAndStreams(item, transform, transformStream))
28503
- };
28516
+ return { kind: "string", format: "hex", bytes: transform(node.bytes) };
28517
+ case "array": {
28518
+ const items = [];
28519
+ for (const item of node.items) items.push(yield* transformNodeStringsAndStreamsSteps(item, transform, transformStream));
28520
+ return { kind: "array", items };
28521
+ }
28504
28522
  case "dict": {
28505
- const type = dictGet(node, "Type");
28506
- const fieldType = dictGet(node, "FT");
28507
- const byteRange = dictGet(node, "ByteRange");
28523
+ const type = dictGet(node, "Type"), fieldType = dictGet(node, "FT"), byteRange = dictGet(node, "ByteRange");
28508
28524
  const signature = type?.kind === "name" && type.decoded === "Sig" || fieldType?.kind === "name" && fieldType.decoded === "Sig" || byteRange?.kind === "array" && dictGet(node, "Filter")?.kind === "name";
28509
- return {
28510
- kind: "dict",
28511
- entries: node.entries.map((e) => ({
28512
- key: e.key,
28513
- value: signature && e.key.decoded === "Contents" ? e.value : transformNodeStringsAndStreams(e.value, transform, transformStream)
28514
- }))
28515
- };
28525
+ const entries = [];
28526
+ 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) });
28527
+ return { kind: "dict", entries };
28516
28528
  }
28517
28529
  case "stream": {
28518
28530
  const type = dictGet(node.dict, "Type");
28519
28531
  if (type?.kind === "name" && type.decoded === "XRef") return node;
28520
28532
  const stream = transformStream ? transformStream(node) : { ...node, rawBytes: transform(node.rawBytes) };
28521
- const updatedDict = {
28522
- kind: "dict",
28523
- entries: stream.dict.entries.map((e) => ({
28524
- key: e.key,
28525
- value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : transformNodeStringsAndStreams(e.value, transform, transformStream)
28526
- }))
28527
- };
28528
- return {
28529
- kind: "stream",
28530
- dict: updatedDict,
28531
- rawBytes: stream.rawBytes
28532
- };
28533
+ const entries = [];
28534
+ 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) });
28535
+ return { kind: "stream", dict: { kind: "dict", entries }, rawBytes: stream.rawBytes };
28533
28536
  }
28534
28537
  default:
28535
28538
  return node;
@@ -28598,7 +28601,8 @@ function createR6Encryption(userPassword, ownerPassword, pMask) {
28598
28601
  StrF: cosName("StdCF")
28599
28602
  }) };
28600
28603
  }
28601
- function encryptCosDocument(doc, options = {}) {
28604
+ function* encryptCosDocumentSteps(doc, options = {}) {
28605
+ yield;
28602
28606
  const userPassword = options.userPassword ?? "";
28603
28607
  const ownerPassword = options.ownerPassword ?? userPassword;
28604
28608
  const revision = options.revision ?? 6;
@@ -28620,14 +28624,15 @@ function encryptCosDocument(doc, options = {}) {
28620
28624
  const encryptObjNum = maxObjNum + 1;
28621
28625
  const encryptedObjects = [];
28622
28626
  for (const obj of doc.objects.values()) {
28623
- const transformed = transformNodeStringsAndStreams(
28627
+ yield;
28628
+ const transformed = yield* transformNodeStringsAndStreamsSteps(
28624
28629
  obj.value,
28625
28630
  (plain) => encryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, plain)
28626
28631
  );
28627
28632
  encryptedObjects.push({ objectNumber: obj.objectNumber, generationNumber: obj.generationNumber, value: transformed });
28628
28633
  }
28629
28634
  encryptedObjects.push({ objectNumber: encryptObjNum, generationNumber: 0, value: encryptDict });
28630
- return serializeCosDocument({
28635
+ return yield* serializeCosDocumentSteps({
28631
28636
  objects: encryptedObjects,
28632
28637
  rootRef: doc.rootRef,
28633
28638
  infoRef: doc.infoRef,
@@ -28677,17 +28682,19 @@ function decryptStream(doc, stream, transform) {
28677
28682
  }
28678
28683
  return { kind: "stream", dict, rawBytes: bytes };
28679
28684
  }
28680
- function decryptCosDocument(doc, state) {
28685
+ function* decryptCosDocumentSteps(doc, state) {
28686
+ yield;
28681
28687
  const encryptObjNum = doc.encryptRef?.objectNumber;
28682
28688
  const handler = securityHandlers.get(state);
28683
28689
  for (const [num, obj] of doc.objects.entries()) {
28690
+ yield;
28684
28691
  if (num === encryptObjNum || handler?.plaintextObjects.has(num)) continue;
28685
28692
  if (obj.value.kind === "stream") {
28686
28693
  const type = doc.resolve(dictGet(obj.value.dict, "Type"));
28687
28694
  if (type?.kind === "name" && (type.decoded === "XRef" || type.decoded === "Metadata" && !state.encryptMetadata)) continue;
28688
28695
  }
28689
28696
  const transform = handler?.factory.createCipherTransform(obj.objectNumber, obj.generationNumber);
28690
- const decrypted = transformNodeStringsAndStreams(
28697
+ const decrypted = yield* transformNodeStringsAndStreamsSteps(
28691
28698
  obj.value,
28692
28699
  (cipher) => decryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, cipher),
28693
28700
  transform ? (stream) => decryptStream(doc, stream, transform) : void 0
@@ -28801,9 +28808,12 @@ var ParsedCosDocument = class {
28801
28808
  return void 0;
28802
28809
  }
28803
28810
  };
28804
- function parseNodeFromLexer(lexer, bytes, maxDepth, repair = false) {
28811
+ function* parseNodeFromLexerSteps(lexer, bytes, maxDepth, repair = false) {
28812
+ yield;
28813
+ let work = 0;
28805
28814
  const stack = [];
28806
28815
  while (true) {
28816
+ if (++work % 16 === 0) yield;
28807
28817
  const tok = lexer.nextToken();
28808
28818
  const parent = stack.at(-1);
28809
28819
  if (!tok) {
@@ -28999,7 +29009,8 @@ function parseHeaderVersion(bytes) {
28999
29009
  }
29000
29010
  return head.slice(idx + 5, idx + 8);
29001
29011
  }
29002
- function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
29012
+ function* parseObjectAtOffsetSteps(bytes, offset, maxRecursionDepth, repair = false) {
29013
+ yield;
29003
29014
  const lexer = new CosByteLexer(bytes, offset);
29004
29015
  const objNumTok = lexer.nextToken();
29005
29016
  const genNumTok = lexer.nextToken();
@@ -29007,7 +29018,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
29007
29018
  if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
29008
29019
  throw new PdfError("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
29009
29020
  }
29010
- const value = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, repair);
29021
+ const value = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, repair);
29011
29022
  if (!value) {
29012
29023
  throw new PdfError("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
29013
29024
  }
@@ -29018,7 +29029,9 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
29018
29029
  span: { start: objNumTok.span.start, end: lexer.offset }
29019
29030
  };
29020
29031
  }
29021
- function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
29032
+ function* parseXrefRevisionAtSteps(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
29033
+ yield;
29034
+ let work = 0;
29022
29035
  if (xrefOffset < 0 || xrefOffset >= bytes.length) {
29023
29036
  throw new PdfError("E_PARSE", `Invalid xref offset: ${xrefOffset}`);
29024
29037
  }
@@ -29030,6 +29043,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29030
29043
  if (firstTok.kind === "keyword" && firstTok.value === "xref") {
29031
29044
  const entries2 = /* @__PURE__ */ new Map();
29032
29045
  while (true) {
29046
+ if (++work % 16 === 0) yield;
29033
29047
  const saved = lexer.offset;
29034
29048
  const tok = lexer.nextToken();
29035
29049
  if (!tok) {
@@ -29053,6 +29067,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29053
29067
  }
29054
29068
  if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
29055
29069
  for (let i = 0; i < count; i++) {
29070
+ if (++work % 16 === 0) yield;
29056
29071
  const offTok = lexer.nextToken();
29057
29072
  const genTok = lexer.nextToken();
29058
29073
  const flagTok = lexer.nextToken();
@@ -29078,7 +29093,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29078
29093
  if (entries2.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
29079
29094
  }
29080
29095
  }
29081
- const trailerNode = parseNodeFromLexer(lexer, bytes, maxRecursionDepth);
29096
+ const trailerNode = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth);
29082
29097
  if (!trailerNode || trailerNode.kind !== "dict") {
29083
29098
  throw new PdfError("E_PARSE", "Missing trailer dictionary after xref table");
29084
29099
  }
@@ -29090,7 +29105,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29090
29105
  previousXrefOffset: prevNode2?.kind === "number" ? prevNode2.value : void 0
29091
29106
  };
29092
29107
  }
29093
- const xrefObj = parseObjectAtOffset(bytes, xrefOffset, maxRecursionDepth);
29108
+ const xrefObj = yield* parseObjectAtOffsetSteps(bytes, xrefOffset, maxRecursionDepth);
29094
29109
  if (xrefObj.value.kind !== "stream") {
29095
29110
  throw new PdfError("E_PARSE", `Expected xref table or XRef stream at offset ${xrefOffset}`);
29096
29111
  }
@@ -29111,6 +29126,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29111
29126
  if (indexArray) {
29112
29127
  if (indexArray.kind !== "array" || indexArray.items.length % 2 !== 0) throw new PdfError("E_PARSE", "Invalid XRef range fields");
29113
29128
  for (let i = 0; i < indexArray.items.length; i += 2) {
29129
+ if (++work % 16 === 0) yield;
29114
29130
  const first = indexArray.items[i];
29115
29131
  const count = indexArray.items[i + 1];
29116
29132
  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)) {
@@ -29133,9 +29149,11 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29133
29149
  return v;
29134
29150
  };
29135
29151
  for (const [startObj, count] of subsections) {
29152
+ if (++work % 16 === 0) yield;
29136
29153
  if (count > (decoded.length - pos) / stride) throw new PdfError("E_PARSE", "Truncated XRef stream");
29137
29154
  if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
29138
29155
  for (let i = 0; i < count; i++) {
29156
+ if (++work % 16 === 0) yield;
29139
29157
  const objNum = startObj + i;
29140
29158
  const field0 = w0 > 0 ? readInt(w0) : 1;
29141
29159
  const field1 = readInt(w1);
@@ -29181,12 +29199,16 @@ function isAsciiWhitespace(ch3) {
29181
29199
  function isAsciiDigit(ch3) {
29182
29200
  return ch3 >= 48 && ch3 <= 57;
29183
29201
  }
29184
- function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29202
+ function* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth) {
29203
+ yield;
29204
+ let work = 0;
29185
29205
  const objects = /* @__PURE__ */ new Map();
29186
29206
  const trailers = [];
29187
29207
  let pos = 0;
29188
29208
  while (pos < bytes.length) {
29209
+ if (++work % 16 === 0) yield;
29189
29210
  while (pos < bytes.length && !isAsciiDigit(bytes[pos])) {
29211
+ if (++work % 16 === 0) yield;
29190
29212
  if (bytes[pos] === 37) {
29191
29213
  while (pos < bytes.length && bytes[pos] !== 10 && bytes[pos] !== 13) pos++;
29192
29214
  continue;
@@ -29196,7 +29218,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29196
29218
  try {
29197
29219
  const token = lexer.nextToken();
29198
29220
  if (token?.kind === "keyword" && token.value === "trailer") {
29199
- const trailer = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, true);
29221
+ const trailer = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, true);
29200
29222
  if (trailer?.kind === "dict") trailers.push(trailer);
29201
29223
  pos = lexer.offset;
29202
29224
  continue;
@@ -29229,7 +29251,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29229
29251
  bytes[pos + 3] === 40)) {
29230
29252
  pos += 3;
29231
29253
  try {
29232
- const parsed = parseObjectAtOffset(bytes, headerStart, maxRecursionDepth, true);
29254
+ const parsed = yield* parseObjectAtOffsetSteps(bytes, headerStart, maxRecursionDepth, true);
29233
29255
  objects.set(parsed.objectNumber, parsed);
29234
29256
  if (parsed.value.kind === "stream") {
29235
29257
  const type = dictGet(parsed.value.dict, "Type");
@@ -29246,13 +29268,17 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29246
29268
  }
29247
29269
  return { objects, trailers };
29248
29270
  }
29249
- function unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
29271
+ function* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
29272
+ yield;
29273
+ let work = 0;
29250
29274
  for (const obj of [...objects.values()]) {
29275
+ if (++work % 16 === 0) yield;
29251
29276
  if (obj.value.kind === "stream") {
29252
29277
  const t = dictGet(obj.value.dict, "Type");
29253
29278
  if (t?.kind === "name" && t.decoded === "ObjStm") {
29254
29279
  try {
29255
- for (const [unpackedNum, unpackedVal] of unpackObjectStream(obj.value, maxDecompressedBytes, maxRecursionDepth, true).entries()) {
29280
+ for (const [unpackedNum, unpackedVal] of (yield* unpackObjectStreamSteps(obj.value, maxDecompressedBytes, maxRecursionDepth, true)).entries()) {
29281
+ if (++work % 16 === 0) yield;
29256
29282
  if (!objects.has(unpackedNum)) {
29257
29283
  objects.set(unpackedNum, {
29258
29284
  objectNumber: unpackedNum,
@@ -29288,7 +29314,9 @@ function recoveredReferences(objects) {
29288
29314
  }
29289
29315
  return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
29290
29316
  }
29291
- function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
29317
+ function* unpackObjectStreamSteps(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
29318
+ yield;
29319
+ let work = 0;
29292
29320
  const nNode = dictGet(streamObj.dict, "N");
29293
29321
  const firstNode = dictGet(streamObj.dict, "First");
29294
29322
  if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
@@ -29298,6 +29326,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29298
29326
  const headerLexer = new CosByteLexer(decoded, 0);
29299
29327
  const pairs = [];
29300
29328
  for (let i = 0; i < nNode.value; i++) {
29329
+ if (++work % 16 === 0) yield;
29301
29330
  const numTok = headerLexer.nextToken();
29302
29331
  const offTok = headerLexer.nextToken();
29303
29332
  if (numTok?.kind === "number" && offTok?.kind === "number") {
@@ -29306,9 +29335,10 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29306
29335
  }
29307
29336
  const result = /* @__PURE__ */ new Map();
29308
29337
  for (const pair of pairs) {
29338
+ if (++work % 16 === 0) yield;
29309
29339
  try {
29310
29340
  const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
29311
- const node = parseNodeFromLexer(valLexer, decoded, maxRecursionDepth, repair);
29341
+ const node = yield* parseNodeFromLexerSteps(valLexer, decoded, maxRecursionDepth, repair);
29312
29342
  if (node) {
29313
29343
  result.set(pair.objectNumber, node);
29314
29344
  }
@@ -29318,7 +29348,9 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29318
29348
  }
29319
29349
  return result;
29320
29350
  }
29321
- function parseCosDocument(bytes, options = {}) {
29351
+ function* parseCosDocumentSteps(bytes, options = {}) {
29352
+ yield;
29353
+ let work = 0;
29322
29354
  const version = parseHeaderVersion(bytes);
29323
29355
  const recovery = options.recovery ?? "strict";
29324
29356
  const maxObjects = options.maxObjects ?? Infinity;
@@ -29353,10 +29385,12 @@ function parseCosDocument(bytes, options = {}) {
29353
29385
  let currentXrefOffset = offsetTok.value;
29354
29386
  const visitedOffsets = /* @__PURE__ */ new Set();
29355
29387
  while (currentXrefOffset !== void 0 && !visitedOffsets.has(currentXrefOffset)) {
29388
+ if (++work % 16 === 0) yield;
29356
29389
  visitedOffsets.add(currentXrefOffset);
29357
- const rev = parseXrefRevisionAt(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
29390
+ const rev = yield* parseXrefRevisionAtSteps(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
29358
29391
  revisions.push(rev);
29359
29392
  for (const [num, entry] of rev.entries.entries()) {
29393
+ if (++work % 16 === 0) yield;
29360
29394
  if (!mergedXref.has(num)) {
29361
29395
  mergedXref.set(num, entry);
29362
29396
  if (mergedXref.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
@@ -29389,8 +29423,9 @@ function parseCosDocument(bytes, options = {}) {
29389
29423
  if (!useRepair && rootRef) {
29390
29424
  try {
29391
29425
  for (const [objNum, entry] of mergedXref.entries()) {
29426
+ if (++work % 16 === 0) yield;
29392
29427
  if (entry.type !== "uncompressed") continue;
29393
- const parsed = parseObjectAtOffset(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
29428
+ const parsed = yield* parseObjectAtOffsetSteps(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
29394
29429
  if (parsed.objectNumber !== objNum || parsed.generationNumber !== (entry.generationNumber ?? 0)) {
29395
29430
  throw new PdfError("E_PARSE", `Bad uncompressed XRef entry for object ${objNum}`);
29396
29431
  }
@@ -29408,7 +29443,7 @@ function parseCosDocument(bytes, options = {}) {
29408
29443
  throw new PdfError("E_PARSE", "PDF trailer missing /Root reference");
29409
29444
  }
29410
29445
  useRepair = true;
29411
- const scanned = repairScanCosDocument(bytes, maxObjects, maxRecursionDepth);
29446
+ const scanned = yield* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth);
29412
29447
  objects = scanned.objects;
29413
29448
  revisions.length = 0;
29414
29449
  mergedXref.clear();
@@ -29443,7 +29478,7 @@ function parseCosDocument(bytes, options = {}) {
29443
29478
  encryptNode = encrypt?.kind === "ref" || encrypt?.kind === "dict" ? encrypt : void 0;
29444
29479
  encryptRef = encrypt?.kind === "ref" ? encrypt : void 0;
29445
29480
  idArray = id?.kind === "array" ? id : void 0;
29446
- if (!rootRef && !encryptNode) unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29481
+ if (!rootRef && !encryptNode) yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29447
29482
  const fallback = recoveredReferences(objects);
29448
29483
  rootRef ??= fallback.rootRef;
29449
29484
  infoRef ??= fallback.infoRef;
@@ -29478,20 +29513,21 @@ function parseCosDocument(bytes, options = {}) {
29478
29513
  maxRecursionDepth
29479
29514
  });
29480
29515
  doc.encryption = encState;
29481
- decryptCosDocument(doc, encState);
29516
+ yield* decryptCosDocumentSteps(doc, encState);
29482
29517
  }
29483
29518
  if (useRepair) {
29484
- unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29519
+ yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29485
29520
  doc.infoRef ??= recoveredReferences(objects).infoRef;
29486
29521
  }
29487
29522
  const objStmCache = /* @__PURE__ */ new Map();
29488
29523
  for (const [objNum, entry] of mergedXref.entries()) {
29524
+ if (++work % 16 === 0) yield;
29489
29525
  if (entry.type === "compressed" && entry.objectStreamNumber !== void 0) {
29490
29526
  let unpacked = objStmCache.get(entry.objectStreamNumber);
29491
29527
  if (!unpacked) {
29492
29528
  const stmObj = objects.get(entry.objectStreamNumber)?.value;
29493
29529
  if (stmObj?.kind === "stream") {
29494
- unpacked = unpackObjectStream(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
29530
+ unpacked = yield* unpackObjectStreamSteps(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
29495
29531
  objStmCache.set(entry.objectStreamNumber, unpacked);
29496
29532
  }
29497
29533
  }
@@ -29508,6 +29544,9 @@ function parseCosDocument(bytes, options = {}) {
29508
29544
  }
29509
29545
  return doc;
29510
29546
  }
29547
+ function parseCosDocument(bytes, options = {}) {
29548
+ return drainWork(parseCosDocumentSteps(bytes, options));
29549
+ }
29511
29550
  var WIN_ANSI_HIGH_BYTES = {
29512
29551
  128: 8364,
29513
29552
  130: 8218,
@@ -40538,7 +40577,8 @@ function resolveInheritedFieldEntry(doc, dict, key) {
40538
40577
  }
40539
40578
  return void 0;
40540
40579
  }
40541
- function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
40580
+ function* collectFieldDictsSteps(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen, yieldState = { work: 0 }) {
40581
+ if (++yieldState.work % 256 === 0) yield;
40542
40582
  const dict = doc.resolveDict(node);
40543
40583
  if (!dict) return out;
40544
40584
  const tNode = doc.resolve(dictGet(dict, "T"));
@@ -40571,7 +40611,8 @@ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", pare
40571
40611
  return out;
40572
40612
  }
40573
40613
  for (const kid of kidsArr.items) {
40574
- collectFieldDicts(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen);
40614
+ if (++yieldState.work % 16 === 0) yield;
40615
+ yield* collectFieldDictsSteps(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen, yieldState);
40575
40616
  }
40576
40617
  } else if (fullName) {
40577
40618
  out.push({
@@ -41012,6 +41053,9 @@ function escapePdfLiteralString(str) {
41012
41053
  }
41013
41054
  return out;
41014
41055
  }
41056
+ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
41057
+ drainWork(collectFieldDictsSteps(doc, node, prefix, out, parentFt, parentFf, parentQ, parentMaxLen));
41058
+ }
41015
41059
  var PdfPage = class {
41016
41060
  cosDoc;
41017
41061
  pageRef;
@@ -44061,14 +44105,18 @@ var PdfDocument = class _PdfDocument {
44061
44105
  });
44062
44106
  return new _PdfDocument(parseCosDocument(rawBytes));
44063
44107
  }
44064
- static load(bytes, options) {
44108
+ static *loadSteps(bytes, options) {
44109
+ yield;
44065
44110
  return new _PdfDocument(
44066
- parseCosDocument(bytes, {
44111
+ yield* parseCosDocumentSteps(bytes, {
44067
44112
  ...options,
44068
44113
  recovery: options?.recovery ?? "repair"
44069
44114
  })
44070
44115
  );
44071
44116
  }
44117
+ static load(bytes, options) {
44118
+ return drainWork(_PdfDocument.loadSteps(bytes, options));
44119
+ }
44072
44120
  rebuildPagesList() {
44073
44121
  const catalog = this.cos.resolveDict(this.cos.rootRef);
44074
44122
  const pagesNode = catalog ? dictGet(catalog, "Pages") : void 0;
@@ -44150,20 +44198,30 @@ var PdfDocument = class _PdfDocument {
44150
44198
  this.pages.splice(index, 1);
44151
44199
  this.syncPageTree();
44152
44200
  }
44153
- copyPagesFrom(sourceDoc, indices) {
44201
+ *copyPagesFromSteps(sourceDoc, indices) {
44202
+ function* cloneItems(items) {
44203
+ const result = [];
44204
+ for (const item of items) result.push(yield* cloneNode(item));
44205
+ return result;
44206
+ }
44207
+ yield;
44208
+ let work = 0;
44154
44209
  const memo = /* @__PURE__ */ new Map();
44155
44210
  const sourcePageObjNums = /* @__PURE__ */ new Set();
44156
44211
  for (let i = 0; i < sourceDoc.getPageCount(); i++) {
44212
+ if (++work % 16 === 0) yield;
44157
44213
  sourcePageObjNums.add(sourceDoc.getPage(i).ref.objectNumber);
44158
44214
  }
44159
44215
  const targetPageRefs = [];
44160
44216
  for (const idx of indices) {
44217
+ if (++work % 16 === 0) yield;
44161
44218
  const srcPage = sourceDoc.getPage(idx);
44162
44219
  const pageRef = this.cos.allocateObject({ kind: "null" });
44163
44220
  targetPageRefs.push(pageRef);
44164
44221
  memo.set(srcPage.ref.objectNumber, pageRef);
44165
44222
  }
44166
- const cloneNode = (node) => {
44223
+ const cloneNode = function* (node) {
44224
+ if (++work % 16 === 0) yield;
44167
44225
  if (node.kind === "ref") {
44168
44226
  const existing = memo.get(node.objectNumber);
44169
44227
  if (existing) return existing;
@@ -44174,12 +44232,12 @@ var PdfDocument = class _PdfDocument {
44174
44232
  if (!target) return cosRef(0);
44175
44233
  const placeholderRef = this.cos.allocateObject({ kind: "null" });
44176
44234
  memo.set(node.objectNumber, placeholderRef);
44177
- const clonedTarget = cloneNode(target);
44235
+ const clonedTarget = yield* cloneNode(target);
44178
44236
  this.cos.setObject(placeholderRef.objectNumber, clonedTarget, 0);
44179
44237
  return placeholderRef;
44180
44238
  }
44181
44239
  if (node.kind === "array") {
44182
- return cosArray(node.items.map(cloneNode));
44240
+ return cosArray(yield* cloneItems(node.items));
44183
44241
  }
44184
44242
  if (node.kind === "dict") {
44185
44243
  const typeEntry = dictGet(node, "Type");
@@ -44189,13 +44247,13 @@ var PdfDocument = class _PdfDocument {
44189
44247
  if (isPageTreeNode && entry.key.decoded === "Parent") continue;
44190
44248
  newEntries.push({
44191
44249
  key: { ...entry.key },
44192
- value: cloneNode(entry.value)
44250
+ value: yield* cloneNode(entry.value)
44193
44251
  });
44194
44252
  }
44195
44253
  return { kind: "dict", entries: newEntries };
44196
44254
  }
44197
44255
  if (node.kind === "stream") {
44198
- const clonedDict = cloneNode(node.dict);
44256
+ const clonedDict = yield* cloneNode(node.dict);
44199
44257
  return {
44200
44258
  kind: "stream",
44201
44259
  dict: clonedDict,
@@ -44204,11 +44262,12 @@ var PdfDocument = class _PdfDocument {
44204
44262
  };
44205
44263
  }
44206
44264
  return node;
44207
- };
44265
+ }.bind(this);
44208
44266
  const copiedPages = [];
44209
44267
  for (const [position, idx] of indices.entries()) {
44268
+ if (++work % 16 === 0) yield;
44210
44269
  const srcPage = sourceDoc.getPage(idx);
44211
- const clonedPageDict = cloneNode(srcPage.pageDict);
44270
+ const clonedPageDict = yield* cloneNode(srcPage.pageDict);
44212
44271
  const size = srcPage.getSize();
44213
44272
  if (!dictGet(clonedPageDict, "MediaBox")) {
44214
44273
  dictSet(
@@ -44218,13 +44277,14 @@ var PdfDocument = class _PdfDocument {
44218
44277
  );
44219
44278
  }
44220
44279
  if (!dictGet(clonedPageDict, "Resources")) {
44221
- dictSet(clonedPageDict, "Resources", cloneNode(srcPage.getResourcesDict()));
44280
+ dictSet(clonedPageDict, "Resources", yield* cloneNode(srcPage.getResourcesDict()));
44222
44281
  }
44223
44282
  if (!dictGet(clonedPageDict, "Rotate") && srcPage.getRotation() !== 0) {
44224
44283
  dictSet(clonedPageDict, "Rotate", cosNumber(srcPage.getRotation()));
44225
44284
  }
44226
44285
  const inheritedBoxKeys = ["CropBox", "BleedBox", "TrimBox", "ArtBox"];
44227
44286
  for (const boxKey of inheritedBoxKeys) {
44287
+ if (++work % 16 === 0) yield;
44228
44288
  if (!dictGet(clonedPageDict, boxKey)) {
44229
44289
  const boxVal = boxKey === "CropBox" ? srcPage.getCropBox() : boxKey === "BleedBox" ? srcPage.getBleedBox() : boxKey === "TrimBox" ? srcPage.getTrimBox() : srcPage.getArtBox();
44230
44290
  if (boxVal[0] !== 0 || boxVal[1] !== 0 || boxVal[2] !== size.width || boxVal[3] !== size.height) {
@@ -44266,8 +44326,9 @@ var PdfDocument = class _PdfDocument {
44266
44326
  };
44267
44327
  const clonedRootFieldRefs = [];
44268
44328
  for (const item of srcFieldsArr.items) {
44329
+ if (++work % 16 === 0) yield;
44269
44330
  if (!hasClonedDescendant(item)) continue;
44270
- const cloned = cloneNode(item);
44331
+ const cloned = yield* cloneNode(item);
44271
44332
  if (cloned.kind === "ref") {
44272
44333
  const clonedDict = this.cos.resolveDict(cloned);
44273
44334
  const kidsArr = clonedDict ? this.cos.resolveArray(dictGet(clonedDict, "Kids")) : void 0;
@@ -44301,6 +44362,7 @@ var PdfDocument = class _PdfDocument {
44301
44362
  dstFields.items.filter((x) => x.kind === "ref").map((x) => x.objectNumber)
44302
44363
  );
44303
44364
  for (const fRef of clonedRootFieldRefs) {
44365
+ if (++work % 16 === 0) yield;
44304
44366
  if (!existingNums.has(fRef.objectNumber)) {
44305
44367
  dstFields.items.push(fRef);
44306
44368
  existingNums.add(fRef.objectNumber);
@@ -44308,11 +44370,11 @@ var PdfDocument = class _PdfDocument {
44308
44370
  }
44309
44371
  const srcDr = dictGet(srcAcroForm, "DR");
44310
44372
  if (srcDr && !dictGet(dstAcroForm, "DR")) {
44311
- dictSet(dstAcroForm, "DR", cloneNode(srcDr));
44373
+ dictSet(dstAcroForm, "DR", yield* cloneNode(srcDr));
44312
44374
  }
44313
44375
  const srcDa = dictGet(srcAcroForm, "DA");
44314
44376
  if (srcDa && !dictGet(dstAcroForm, "DA")) {
44315
- dictSet(dstAcroForm, "DA", cloneNode(srcDa));
44377
+ dictSet(dstAcroForm, "DA", yield* cloneNode(srcDa));
44316
44378
  }
44317
44379
  }
44318
44380
  }
@@ -44321,12 +44383,15 @@ var PdfDocument = class _PdfDocument {
44321
44383
  if (srcOcProps) {
44322
44384
  const dstCatalog = this.cos.resolveDict(this.cos.rootRef);
44323
44385
  if (dstCatalog && !dictGet(dstCatalog, "OCProperties")) {
44324
- dictSet(dstCatalog, "OCProperties", cloneNode(srcOcProps));
44386
+ dictSet(dstCatalog, "OCProperties", yield* cloneNode(srcOcProps));
44325
44387
  }
44326
44388
  }
44327
44389
  this.syncPageTree();
44328
44390
  return copiedPages;
44329
44391
  }
44392
+ copyPagesFrom(sourceDoc, indices) {
44393
+ return drainWork(this.copyPagesFromSteps(sourceDoc, indices));
44394
+ }
44330
44395
  embedStandardFont(fontName) {
44331
44396
  return createStandardFontHandle(fontName);
44332
44397
  }
@@ -44526,14 +44591,15 @@ var PdfDocument = class _PdfDocument {
44526
44591
  });
44527
44592
  return buildSemanticAstFromPages(extractedPages, tablesByPage, displayLists);
44528
44593
  }
44529
- save(options = {}) {
44594
+ *saveSteps(options = {}) {
44595
+ yield;
44530
44596
  this.syncPageTree();
44531
44597
  if (this.cos.requiresFullRewrite) {
44532
44598
  pruneUnusedXObjects(this.cos, this.pages);
44533
44599
  discardUnreachableObjects(this.cos);
44534
44600
  }
44535
44601
  if (options.encrypt) {
44536
- return encryptCosDocument(this.cos, options.encrypt);
44602
+ return yield* encryptCosDocumentSteps(this.cos, options.encrypt);
44537
44603
  }
44538
44604
  const allObjects = [...this.cos.objects.values()].sort(
44539
44605
  (a, b) => a.objectNumber - b.objectNumber
@@ -44541,7 +44607,7 @@ var PdfDocument = class _PdfDocument {
44541
44607
  if (options.incremental && !this.cos.requiresFullRewrite && this.cos.bytes.length > 0) {
44542
44608
  return appendIncrementalRevision(this.cos.bytes, this.cos, allObjects);
44543
44609
  }
44544
- return serializeCosDocument({
44610
+ return yield* serializeCosDocumentSteps({
44545
44611
  objects: allObjects,
44546
44612
  rootRef: this.cos.rootRef,
44547
44613
  infoRef: this.cos.infoRef,
@@ -44552,6 +44618,9 @@ var PdfDocument = class _PdfDocument {
44552
44618
  linearize: options.linearize
44553
44619
  });
44554
44620
  }
44621
+ save(options = {}) {
44622
+ return drainWork(this.saveSteps(options));
44623
+ }
44555
44624
  };
44556
44625
  var VALUE_FLAGS = /* @__PURE__ */ new Set([
44557
44626
  "-r",
@@ -44595,7 +44664,8 @@ function extractPdftoppmPositionals(argv) {
44595
44664
  }
44596
44665
  return pos;
44597
44666
  }
44598
- function runPdftoppmCliSync(argv, files, options = {}) {
44667
+ function* runPdftoppmCliSteps(argv, files, options = {}) {
44668
+ let cooperativeWork = 63;
44599
44669
  let format = "ppm";
44600
44670
  let explicitContainer;
44601
44671
  let colorMode = "rgb";
@@ -44631,6 +44701,8 @@ function runPdftoppmCliSync(argv, files, options = {}) {
44631
44701
  let password = "";
44632
44702
  const positionals = [];
44633
44703
  for (let i = 0; i < argv.length; i++) {
44704
+ if (++cooperativeWork % 64 === 0)
44705
+ yield;
44634
44706
  const arg = argv[i];
44635
44707
  if (arg === "-v" || arg === "--version") {
44636
44708
  return { exitCode: 0, stdout: "pdftoppm version 24.08.0\n", stderr: "" };
@@ -44674,6 +44746,8 @@ function runPdftoppmCliSync(argv, files, options = {}) {
44674
44746
  else if (arg === "-jpegopt") {
44675
44747
  const optStr = argv[++i] ?? "";
44676
44748
  for (const part of optStr.split(",")) {
44749
+ if (++cooperativeWork % 64 === 0)
44750
+ yield;
44677
44751
  const eqIdx = part.indexOf("=");
44678
44752
  if (eqIdx > 0 && part.slice(0, eqIdx).trim().toLowerCase() === "quality") {
44679
44753
  const qVal = Number(part.slice(eqIdx + 1).trim());
@@ -44795,8 +44869,11 @@ function runPdftoppmCliSync(argv, files, options = {}) {
44795
44869
  const outChunks = [];
44796
44870
  const progressLines = [];
44797
44871
  for (let p = firstPage; p <= endPage; p++) {
44798
- if (oddOnly && p % 2 === 0) continue;
44799
- if (evenOnly && p % 2 === 1) continue;
44872
+ yield;
44873
+ if (oddOnly && p % 2 === 0)
44874
+ continue;
44875
+ if (evenOnly && p % 2 === 1)
44876
+ continue;
44800
44877
  const page = doc.getPage(p - 1);
44801
44878
  const displayList = page.evaluateDisplayList({ hideAnnotations });
44802
44879
  const box = useCropBox ? getDisplayListCropBox(displayList) : [0, 0, displayList.width, displayList.height];
@@ -44813,11 +44890,13 @@ function runPdftoppmCliSync(argv, files, options = {}) {
44813
44890
  } else {
44814
44891
  if (scaleToX > 0) {
44815
44892
  effDpiX = scaleToX * 72 / Math.max(ptW, 1);
44816
- if (scaleToY < 0) effDpiY = effDpiX;
44893
+ if (scaleToY < 0)
44894
+ effDpiY = effDpiX;
44817
44895
  }
44818
44896
  if (scaleToY > 0) {
44819
44897
  effDpiY = scaleToY * 72 / Math.max(ptH, 1);
44820
- if (scaleToX < 0) effDpiX = effDpiY;
44898
+ if (scaleToX < 0)
44899
+ effDpiX = effDpiY;
44821
44900
  }
44822
44901
  }
44823
44902
  const cropRect = hasCrop ? { x: cropX, y: cropY, width: cropW, height: cropH } : void 0;
@@ -44847,6 +44926,8 @@ function runPdftoppmCliSync(argv, files, options = {}) {
44847
44926
  options.onAllocateBytes?.(bitmap.width * bitmap.height * 4);
44848
44927
  if (colorMode !== "rgb" && (format === "png" || format === "tif" || format === "jpg")) {
44849
44928
  for (let px = 0; px < bitmap.data.length; px += 4) {
44929
+ if (++cooperativeWork % 65536 === 0)
44930
+ yield;
44850
44931
  const r = bitmap.data[px];
44851
44932
  const g = bitmap.data[px + 1];
44852
44933
  const b = bitmap.data[px + 2];
@@ -44857,12 +44938,18 @@ function runPdftoppmCliSync(argv, files, options = {}) {
44857
44938
  bitmap.data[px + 2] = v;
44858
44939
  }
44859
44940
  }
44860
- if (format === "png") renderedBytes = encodePng(bitmap);
44861
- else if (format === "tif") renderedBytes = encodeTiff(bitmap, effDpiX, tiffCompression);
44862
- else if (format === "jpg") renderedBytes = encodeJpeg(bitmap, jpegQuality);
44863
- else if (format === "pgm") renderedBytes = encodePgm(bitmap);
44864
- else if (format === "pbm") renderedBytes = encodePbm(bitmap);
44865
- else renderedBytes = encodePpm(bitmap);
44941
+ if (format === "png")
44942
+ renderedBytes = encodePng(bitmap);
44943
+ else if (format === "tif")
44944
+ renderedBytes = encodeTiff(bitmap, effDpiX, tiffCompression);
44945
+ else if (format === "jpg")
44946
+ renderedBytes = encodeJpeg(bitmap, jpegQuality);
44947
+ else if (format === "pgm")
44948
+ renderedBytes = encodePgm(bitmap);
44949
+ else if (format === "pbm")
44950
+ renderedBytes = encodePbm(bitmap);
44951
+ else
44952
+ renderedBytes = encodePpm(bitmap);
44866
44953
  }
44867
44954
  options.onAllocateBytes?.(renderedBytes.byteLength);
44868
44955
  if (!prefix || prefix === "-") {
@@ -44872,17 +44959,15 @@ function runPdftoppmCliSync(argv, files, options = {}) {
44872
44959
  }
44873
44960
  } else {
44874
44961
  const effectivePageNo = setPageNo !== void 0 ? setPageNo + (p - firstPage) : p;
44875
- const pageSuffix = String(effectivePageNo).padStart(
44876
- Math.max(padWidth, String(effectivePageNo).length),
44877
- "0"
44878
- );
44962
+ const pageSuffix = String(effectivePageNo).padStart(Math.max(padWidth, String(effectivePageNo).length), "0");
44879
44963
  const fileName = singleFile && !forceNum ? `${prefix}.${ext}` : `${prefix}${sep}${pageSuffix}.${ext}`;
44880
44964
  files.set(fileName, renderedBytes);
44881
44965
  if (progress && !quiet) {
44882
44966
  progressLines.push(`${p} ${endPage} ${fileName}`);
44883
44967
  }
44884
44968
  }
44885
- if (singleFile) break;
44969
+ if (singleFile)
44970
+ break;
44886
44971
  }
44887
44972
  const stderrText = progressLines.length > 0 ? progressLines.join("\n") + "\n" : "";
44888
44973
  if (outChunks.length > 0) {
@@ -44890,6 +44975,8 @@ function runPdftoppmCliSync(argv, files, options = {}) {
44890
44975
  const merged = new Uint8Array(totalLen);
44891
44976
  let off = 0;
44892
44977
  for (const c of outChunks) {
44978
+ if (++cooperativeWork % 64 === 0)
44979
+ yield;
44893
44980
  merged.set(c, off);
44894
44981
  off += c.byteLength;
44895
44982
  }
@@ -44898,9 +44985,18 @@ function runPdftoppmCliSync(argv, files, options = {}) {
44898
44985
  return { exitCode: 0, stdout: "", stderr: stderrText };
44899
44986
  }
44900
44987
  async function runPdftoppmCli(argv, files, options = {}) {
44901
- return runPdftoppmCliSync(argv, files, options);
44988
+ return drainSteps(runPdftoppmCliSteps(argv, files, options), options.signal);
44989
+ }
44990
+ function runPdftoppmCliSync(argv, files, options = {}) {
44991
+ const steps = runPdftoppmCliSteps(argv, files, options);
44992
+ let next = steps.next();
44993
+ while (!next.done) {
44994
+ next = steps.next();
44995
+ }
44996
+ return next.value;
44902
44997
  }
44903
44998
  async function executePdftoppm(context) {
44999
+ let cooperativeWork = 63;
44904
45000
  const invocation = createOutputOperation(context, { write: async () => {
44905
45001
  } });
44906
45002
  try {
@@ -44921,6 +45017,7 @@ async function executePdftoppm(context) {
44921
45017
  const chunks = [];
44922
45018
  let total = 0;
44923
45019
  for await (const chunk of readBytes(context.stdin, invocation.signal)) {
45020
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
44924
45021
  chunks.push(chunk);
44925
45022
  total += chunk.byteLength;
44926
45023
  chargeBytes(chunk.byteLength);
@@ -44929,6 +45026,7 @@ async function executePdftoppm(context) {
44929
45026
  const buf = new Uint8Array(total);
44930
45027
  let off = 0;
44931
45028
  for (const c of chunks) {
45029
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
44932
45030
  buf.set(c, off);
44933
45031
  off += c.byteLength;
44934
45032
  }
@@ -44936,6 +45034,7 @@ async function executePdftoppm(context) {
44936
45034
  }
44937
45035
  }
44938
45036
  for (const token of positionals) {
45037
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
44939
45038
  if (token === "-") continue;
44940
45039
  try {
44941
45040
  const bytes = await context.fs.readFile(resolveVfsPath(token), { signal: invocation.signal });
@@ -44944,8 +45043,9 @@ async function executePdftoppm(context) {
44944
45043
  } catch {
44945
45044
  }
44946
45045
  }
45046
+ context.inputBudget?.check(0);
44947
45047
  const existingSnap = new Map(vfsFiles);
44948
- const res = await runPdftoppmCli(argv, vfsFiles, { onAllocateBytes: chargeBytes });
45048
+ const res = await runPdftoppmCli(argv, vfsFiles, { onAllocateBytes: chargeBytes, signal: invocation.signal });
44949
45049
  if (res.stderr) {
44950
45050
  await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
44951
45051
  }
@@ -44957,6 +45057,7 @@ async function executePdftoppm(context) {
44957
45057
  await writeBytes(stdout.output, new TextEncoder().encode(res.stdout), invocation.signal);
44958
45058
  }
44959
45059
  for (const [key, val] of vfsFiles.entries()) {
45060
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
44960
45061
  if (key !== "-" && existingSnap.get(key) !== val) {
44961
45062
  const abs = resolveVfsPath(key);
44962
45063
  const parentDir = abs.slice(0, abs.lastIndexOf("/")) || "/";
@@ -44972,13 +45073,14 @@ async function executePdftoppm(context) {
44972
45073
  await invocation.close();
44973
45074
  }
44974
45075
  }
44975
- function createPdftoppmCommand(_options = {}) {
45076
+ function createPdftoppmCommand(options = {}) {
45077
+ const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
44976
45078
  return Object.freeze({
44977
45079
  name: "pdftoppm",
44978
45080
  runtimeIdentity: commandRuntimeIdentity,
44979
45081
  description: "Render PDF pages to PNG, PPM, PGM, PBM, or SVG via @poe-code/pdf-ast",
44980
45082
  execute(context) {
44981
- return executePdftoppm(context);
45083
+ return new InputByteBudget(maxInputBytes).run(context, executePdftoppm);
44982
45084
  }
44983
45085
  });
44984
45086
  }
@@ -45014,7 +45116,8 @@ function extractPdftocairoPositionals(argv) {
45014
45116
  }
45015
45117
  return pos;
45016
45118
  }
45017
- function runPdftocairoCliSync(argv, files, options = {}) {
45119
+ function* runPdftocairoCliSteps(argv, files, options = {}) {
45120
+ let cooperativeWork = 63;
45018
45121
  let format = "png";
45019
45122
  let grayMode = false;
45020
45123
  let monoMode = false;
@@ -45035,6 +45138,8 @@ function runPdftocairoCliSync(argv, files, options = {}) {
45035
45138
  const forwardedArgs = [];
45036
45139
  const positionals = [];
45037
45140
  for (let i = 0; i < argv.length; i++) {
45141
+ if (++cooperativeWork % 64 === 0)
45142
+ yield;
45038
45143
  const arg = argv[i];
45039
45144
  if (arg === "-v" || arg === "--version") {
45040
45145
  return { exitCode: 0, stdout: "pdftocairo version 24.08.0\n", stderr: "" };
@@ -45115,8 +45220,10 @@ function runPdftocairoCliSync(argv, files, options = {}) {
45115
45220
  } else if (VALUE_FLAGS.has(arg)) {
45116
45221
  const val = argv[++i] ?? "";
45117
45222
  forwardedArgs.push(arg, val);
45118
- if (arg === "-f") firstPage = Math.max(1, Number.parseInt(val, 10) || 1);
45119
- else if (arg === "-l") lastPage = Math.max(0, Number.parseInt(val, 10) || 0);
45223
+ if (arg === "-f")
45224
+ firstPage = Math.max(1, Number.parseInt(val, 10) || 1);
45225
+ else if (arg === "-l")
45226
+ lastPage = Math.max(0, Number.parseInt(val, 10) || 0);
45120
45227
  else if (arg === "-x") {
45121
45228
  cropX = Math.max(0, Number.parseInt(val, 10) || 0);
45122
45229
  hasCrop = true;
@@ -45138,8 +45245,10 @@ function runPdftocairoCliSync(argv, files, options = {}) {
45138
45245
  password = val;
45139
45246
  }
45140
45247
  } else if (arg.startsWith("-") && arg !== "-") {
45141
- if (arg === "-o") oddOnly = true;
45142
- if (arg === "-e") evenOnly = true;
45248
+ if (arg === "-o")
45249
+ oddOnly = true;
45250
+ if (arg === "-e")
45251
+ evenOnly = true;
45143
45252
  forwardedArgs.push(arg);
45144
45253
  } else {
45145
45254
  positionals.push(arg);
@@ -45153,7 +45262,7 @@ function runPdftocairoCliSync(argv, files, options = {}) {
45153
45262
  if (format === "svg") {
45154
45263
  const rawOut = positionals[1] ?? (inputPath === "-" ? "-" : `${inputStem}.svg`);
45155
45264
  const rootForSvg = rawOut.toLowerCase().endsWith(".svg") ? rawOut.slice(0, -4) : rawOut;
45156
- return runPdftoppmCliSync(["-svg", "-singlefile", ...forwardedArgs, inputPath, rootForSvg], files, options);
45265
+ return yield* runPdftoppmCliSteps(["-svg", "-singlefile", ...forwardedArgs, inputPath, rootForSvg], files, options);
45157
45266
  }
45158
45267
  if (format === "pdf" || format === "ps" || format === "eps") {
45159
45268
  const pdfBytes = files.get(inputPath);
@@ -45180,8 +45289,11 @@ function runPdftocairoCliSync(argv, files, options = {}) {
45180
45289
  }
45181
45290
  const selectedIndices = [];
45182
45291
  for (let p = firstPage; p <= endPage; p++) {
45183
- if (oddOnly && p % 2 === 0) continue;
45184
- if (evenOnly && p % 2 !== 0) continue;
45292
+ yield;
45293
+ if (oddOnly && p % 2 === 0)
45294
+ continue;
45295
+ if (evenOnly && p % 2 !== 0)
45296
+ continue;
45185
45297
  selectedIndices.push(p - 1);
45186
45298
  }
45187
45299
  const rawOut = positionals[1] ?? (inputPath === "-" ? "-" : `${inputStem}.${format}`);
@@ -45189,29 +45301,29 @@ function runPdftocairoCliSync(argv, files, options = {}) {
45189
45301
  if (format === "pdf") {
45190
45302
  const outDoc = PdfDocument.create();
45191
45303
  const srcMeta = doc.getMetadata();
45192
- if (srcMeta.title) outDoc.setTitle(srcMeta.title);
45193
- if (srcMeta.author) outDoc.setAuthor(srcMeta.author);
45194
- if (srcMeta.subject) outDoc.setSubject(srcMeta.subject);
45195
- if (srcMeta.keywords) outDoc.setKeywords(srcMeta.keywords);
45196
- if (srcMeta.creator) outDoc.setCreator(srcMeta.creator);
45197
- if (srcMeta.producer) outDoc.setProducer(srcMeta.producer);
45304
+ if (srcMeta.title)
45305
+ outDoc.setTitle(srcMeta.title);
45306
+ if (srcMeta.author)
45307
+ outDoc.setAuthor(srcMeta.author);
45308
+ if (srcMeta.subject)
45309
+ outDoc.setSubject(srcMeta.subject);
45310
+ if (srcMeta.keywords)
45311
+ outDoc.setKeywords(srcMeta.keywords);
45312
+ if (srcMeta.creator)
45313
+ outDoc.setCreator(srcMeta.creator);
45314
+ if (srcMeta.producer)
45315
+ outDoc.setProducer(srcMeta.producer);
45198
45316
  const hasPaper = !origPageSizes && paperW > 0 && paperH > 0;
45199
45317
  for (const idx of selectedIndices) {
45318
+ if (++cooperativeWork % 64 === 0)
45319
+ yield;
45200
45320
  const [copied] = outDoc.copyPagesFrom(doc, [idx]);
45201
45321
  if (copied && (hasCrop || hasPaper)) {
45202
45322
  const origSize = copied.getSize();
45203
45323
  const effW = hasPaper ? paperW : cropW > 0 ? cropW : Math.max(1, origSize.width - cropX);
45204
45324
  const effH = hasPaper ? paperH : cropH > 0 ? cropH : Math.max(1, origSize.height - cropY);
45205
- dictSet(
45206
- copied.pageDict,
45207
- "MediaBox",
45208
- cosArray([cosNumber(0), cosNumber(0), cosNumber(effW), cosNumber(effH)])
45209
- );
45210
- dictSet(
45211
- copied.pageDict,
45212
- "CropBox",
45213
- cosArray([cosNumber(0), cosNumber(0), cosNumber(effW), cosNumber(effH)])
45214
- );
45325
+ dictSet(copied.pageDict, "MediaBox", cosArray([cosNumber(0), cosNumber(0), cosNumber(effW), cosNumber(effH)]));
45326
+ dictSet(copied.pageDict, "CropBox", cosArray([cosNumber(0), cosNumber(0), cosNumber(effW), cosNumber(effH)]));
45215
45327
  }
45216
45328
  }
45217
45329
  const outBytes = outDoc.save();
@@ -45233,12 +45345,18 @@ function runPdftocairoCliSync(argv, files, options = {}) {
45233
45345
  "%%EndComments"
45234
45346
  ];
45235
45347
  for (let s = 0; s < selectedIndices.length; s++) {
45348
+ if (++cooperativeWork % 64 === 0)
45349
+ yield;
45236
45350
  const page = doc.getPage(selectedIndices[s]);
45237
45351
  psLines.push(`%%Page: ${s + 1} ${s + 1}`);
45238
45352
  psLines.push("/Helvetica findfont 12 scalefont setfont");
45239
45353
  const extracted = page.extractPage();
45240
45354
  for (const block of extracted.blocks) {
45355
+ if (++cooperativeWork % 64 === 0)
45356
+ yield;
45241
45357
  for (const line of block.lines) {
45358
+ if (++cooperativeWork % 64 === 0)
45359
+ yield;
45242
45360
  const escaped = line.text.replaceAll("\\", "\\\\").replaceAll("(", "\\(").replaceAll(")", "\\)");
45243
45361
  psLines.push(`${Math.round(line.bbox[0])} ${Math.round(line.bbox[1])} moveto (${escaped}) show`);
45244
45362
  }
@@ -45255,7 +45373,7 @@ function runPdftocairoCliSync(argv, files, options = {}) {
45255
45373
  }
45256
45374
  const snapBefore = new Map(files);
45257
45375
  const rasterPositionals = positionals.length === 1 && inputPath !== "-" ? [inputPath, inputStem] : positionals;
45258
- const res = runPdftoppmCliSync([...forwardedArgs, ...rasterPositionals], files, options);
45376
+ const res = yield* runPdftoppmCliSteps([...forwardedArgs, ...rasterPositionals], files, options);
45259
45377
  if (res.exitCode !== 0 || !grayMode && !monoMode) {
45260
45378
  return res;
45261
45379
  }
@@ -45269,6 +45387,8 @@ function runPdftocairoCliSync(argv, files, options = {}) {
45269
45387
  }
45270
45388
  };
45271
45389
  for (const [k, v] of files.entries()) {
45390
+ if (++cooperativeWork % 64 === 0)
45391
+ yield;
45272
45392
  if (snapBefore.get(k) !== v && k.endsWith(".png")) {
45273
45393
  const decoded = decodePng(v);
45274
45394
  convertRgbaInPlace(decoded.data);
@@ -45278,83 +45398,100 @@ function runPdftocairoCliSync(argv, files, options = {}) {
45278
45398
  return res;
45279
45399
  }
45280
45400
  async function runPdftocairoCli(argv, files, options = {}) {
45281
- return runPdftocairoCliSync(argv, files, options);
45401
+ return drainSteps(runPdftocairoCliSteps(argv, files, options), options.signal);
45282
45402
  }
45283
- function createPdftocairoCommand(_options = {}) {
45403
+ function runPdftocairoCliSync(argv, files, options = {}) {
45404
+ const steps = runPdftocairoCliSteps(argv, files, options);
45405
+ let next = steps.next();
45406
+ while (!next.done) {
45407
+ next = steps.next();
45408
+ }
45409
+ return next.value;
45410
+ }
45411
+ function createPdftocairoCommand(options = {}) {
45412
+ const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
45284
45413
  return Object.freeze({
45285
45414
  name: "pdftocairo",
45286
45415
  runtimeIdentity: commandRuntimeIdentity,
45287
45416
  description: "Render PDF pages to PNG, JPEG, TIFF, PDF, PS, EPS, or SVG via @poe-code/pdf-ast",
45288
45417
  async execute(context) {
45289
- const invocation = createOutputOperation(context, { write: async () => {
45290
- } });
45291
- try {
45292
- const carrier = getCommandArguments(context);
45293
- const argv = [...carrier.args];
45294
- const vfsFiles = /* @__PURE__ */ new Map();
45295
- const resolveVfsPath = (p) => p.startsWith("/") ? p : `${context.cwd === "/" ? "" : context.cwd}/${p}`;
45296
- let accountedBytes = 0;
45297
- const chargeBytes = (delta) => {
45298
- if (delta > 0) {
45299
- accountedBytes += delta;
45300
- context.inputBudget?.check(accountedBytes);
45301
- }
45302
- };
45303
- const positionals = extractPdftocairoPositionals(argv);
45304
- if (positionals.length === 0 || positionals[0] === "-") {
45305
- const chunks = [];
45306
- let total = 0;
45307
- for await (const chunk of readBytes(context.stdin, invocation.signal)) {
45308
- chunks.push(chunk);
45309
- total += chunk.byteLength;
45310
- chargeBytes(chunk.byteLength);
45311
- }
45312
- if (total > 0) {
45313
- const buf = new Uint8Array(total);
45314
- let off = 0;
45315
- for (const c of chunks) {
45316
- buf.set(c, off);
45317
- off += c.byteLength;
45418
+ return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
45419
+ let cooperativeWork = 63;
45420
+ const invocation = createOutputOperation(context2, { write: async () => {
45421
+ } });
45422
+ try {
45423
+ const carrier = getCommandArguments(context2);
45424
+ const argv = [...carrier.args];
45425
+ const vfsFiles = /* @__PURE__ */ new Map();
45426
+ const resolveVfsPath = (p) => p.startsWith("/") ? p : `${context2.cwd === "/" ? "" : context2.cwd}/${p}`;
45427
+ let accountedBytes = 0;
45428
+ const chargeBytes = (delta) => {
45429
+ if (delta > 0) {
45430
+ accountedBytes += delta;
45431
+ context2.inputBudget?.check(accountedBytes);
45432
+ }
45433
+ };
45434
+ const positionals = extractPdftocairoPositionals(argv);
45435
+ if (positionals.length === 0 || positionals[0] === "-") {
45436
+ const chunks = [];
45437
+ let total = 0;
45438
+ for await (const chunk of readBytes(context2.stdin, invocation.signal)) {
45439
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context2.signal);
45440
+ chunks.push(chunk);
45441
+ total += chunk.byteLength;
45442
+ chargeBytes(chunk.byteLength);
45443
+ }
45444
+ if (total > 0) {
45445
+ const buf = new Uint8Array(total);
45446
+ let off = 0;
45447
+ for (const c of chunks) {
45448
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context2.signal);
45449
+ buf.set(c, off);
45450
+ off += c.byteLength;
45451
+ }
45452
+ vfsFiles.set("-", buf);
45318
45453
  }
45319
- vfsFiles.set("-", buf);
45320
45454
  }
45321
- }
45322
- for (const token of positionals) {
45323
- if (token === "-") continue;
45324
- try {
45325
- const bytes = await context.fs.readFile(resolveVfsPath(token), { signal: invocation.signal });
45326
- chargeBytes(bytes.byteLength);
45327
- vfsFiles.set(token, bytes);
45328
- } catch {
45329
- }
45330
- }
45331
- const existingSnap = new Map(vfsFiles);
45332
- const res = await runPdftocairoCli(argv, vfsFiles, { onAllocateBytes: chargeBytes });
45333
- if (res.stderr) {
45334
- await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
45335
- }
45336
- if (res.stdoutBytes) {
45337
- const stdout = invocation.child(context.stdout);
45338
- await writeBytes(stdout.output, res.stdoutBytes, invocation.signal);
45339
- } else if (res.stdout) {
45340
- const stdout = invocation.child(context.stdout);
45341
- await writeBytes(stdout.output, new TextEncoder().encode(res.stdout), invocation.signal);
45342
- }
45343
- for (const [key, val] of vfsFiles.entries()) {
45344
- if (key !== "-" && existingSnap.get(key) !== val) {
45345
- const abs = resolveVfsPath(key);
45346
- const parentDir = abs.slice(0, abs.lastIndexOf("/")) || "/";
45455
+ for (const token of positionals) {
45456
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context2.signal);
45457
+ if (token === "-") continue;
45347
45458
  try {
45348
- await context.fs.mkdir(parentDir, { recursive: true, signal: invocation.signal });
45459
+ const bytes = await context2.fs.readFile(resolveVfsPath(token), { signal: invocation.signal });
45460
+ chargeBytes(bytes.byteLength);
45461
+ vfsFiles.set(token, bytes);
45349
45462
  } catch {
45350
45463
  }
45351
- await writeFileOutput(context, val, (data) => context.fs.writeFile(abs, data, { signal: invocation.signal }));
45352
45464
  }
45465
+ context2.inputBudget?.check(0);
45466
+ const existingSnap = new Map(vfsFiles);
45467
+ const res = await runPdftocairoCli(argv, vfsFiles, { onAllocateBytes: chargeBytes, signal: invocation.signal });
45468
+ if (res.stderr) {
45469
+ await writeBytes(context2.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
45470
+ }
45471
+ if (res.stdoutBytes) {
45472
+ const stdout = invocation.child(context2.stdout);
45473
+ await writeBytes(stdout.output, res.stdoutBytes, invocation.signal);
45474
+ } else if (res.stdout) {
45475
+ const stdout = invocation.child(context2.stdout);
45476
+ await writeBytes(stdout.output, new TextEncoder().encode(res.stdout), invocation.signal);
45477
+ }
45478
+ for (const [key, val] of vfsFiles.entries()) {
45479
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context2.signal);
45480
+ if (key !== "-" && existingSnap.get(key) !== val) {
45481
+ const abs = resolveVfsPath(key);
45482
+ const parentDir = abs.slice(0, abs.lastIndexOf("/")) || "/";
45483
+ try {
45484
+ await context2.fs.mkdir(parentDir, { recursive: true, signal: invocation.signal });
45485
+ } catch {
45486
+ }
45487
+ await writeFileOutput(context2, val, (data) => context2.fs.writeFile(abs, data, { signal: invocation.signal }));
45488
+ }
45489
+ }
45490
+ return { exitCode: res.exitCode };
45491
+ } finally {
45492
+ await invocation.close();
45353
45493
  }
45354
- return { exitCode: res.exitCode };
45355
- } finally {
45356
- await invocation.close();
45357
- }
45494
+ });
45358
45495
  }
45359
45496
  });
45360
45497
  }