@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-pdfinfo/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,
@@ -40883,7 +40922,8 @@ function resolveInheritedFieldEntry(doc, dict, key) {
40883
40922
  }
40884
40923
  return void 0;
40885
40924
  }
40886
- function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
40925
+ function* collectFieldDictsSteps(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen, yieldState = { work: 0 }) {
40926
+ if (++yieldState.work % 256 === 0) yield;
40887
40927
  const dict = doc.resolveDict(node);
40888
40928
  if (!dict) return out;
40889
40929
  const tNode = doc.resolve(dictGet(dict, "T"));
@@ -40916,7 +40956,8 @@ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", pare
40916
40956
  return out;
40917
40957
  }
40918
40958
  for (const kid of kidsArr.items) {
40919
- collectFieldDicts(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen);
40959
+ if (++yieldState.work % 16 === 0) yield;
40960
+ yield* collectFieldDictsSteps(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen, yieldState);
40920
40961
  }
40921
40962
  } else if (fullName) {
40922
40963
  out.push({
@@ -41357,6 +41398,9 @@ function escapePdfLiteralString(str) {
41357
41398
  }
41358
41399
  return out;
41359
41400
  }
41401
+ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
41402
+ drainWork(collectFieldDictsSteps(doc, node, prefix, out, parentFt, parentFf, parentQ, parentMaxLen));
41403
+ }
41360
41404
  var PdfPage = class {
41361
41405
  cosDoc;
41362
41406
  pageRef;
@@ -44434,14 +44478,18 @@ var PdfDocument = class _PdfDocument {
44434
44478
  });
44435
44479
  return new _PdfDocument(parseCosDocument(rawBytes));
44436
44480
  }
44437
- static load(bytes, options) {
44481
+ static *loadSteps(bytes, options) {
44482
+ yield;
44438
44483
  return new _PdfDocument(
44439
- parseCosDocument(bytes, {
44484
+ yield* parseCosDocumentSteps(bytes, {
44440
44485
  ...options,
44441
44486
  recovery: options?.recovery ?? "repair"
44442
44487
  })
44443
44488
  );
44444
44489
  }
44490
+ static load(bytes, options) {
44491
+ return drainWork(_PdfDocument.loadSteps(bytes, options));
44492
+ }
44445
44493
  rebuildPagesList() {
44446
44494
  const catalog = this.cos.resolveDict(this.cos.rootRef);
44447
44495
  const pagesNode = catalog ? dictGet(catalog, "Pages") : void 0;
@@ -44523,20 +44571,30 @@ var PdfDocument = class _PdfDocument {
44523
44571
  this.pages.splice(index, 1);
44524
44572
  this.syncPageTree();
44525
44573
  }
44526
- copyPagesFrom(sourceDoc, indices) {
44574
+ *copyPagesFromSteps(sourceDoc, indices) {
44575
+ function* cloneItems(items) {
44576
+ const result = [];
44577
+ for (const item of items) result.push(yield* cloneNode(item));
44578
+ return result;
44579
+ }
44580
+ yield;
44581
+ let work = 0;
44527
44582
  const memo = /* @__PURE__ */ new Map();
44528
44583
  const sourcePageObjNums = /* @__PURE__ */ new Set();
44529
44584
  for (let i = 0; i < sourceDoc.getPageCount(); i++) {
44585
+ if (++work % 16 === 0) yield;
44530
44586
  sourcePageObjNums.add(sourceDoc.getPage(i).ref.objectNumber);
44531
44587
  }
44532
44588
  const targetPageRefs = [];
44533
44589
  for (const idx of indices) {
44590
+ if (++work % 16 === 0) yield;
44534
44591
  const srcPage = sourceDoc.getPage(idx);
44535
44592
  const pageRef = this.cos.allocateObject({ kind: "null" });
44536
44593
  targetPageRefs.push(pageRef);
44537
44594
  memo.set(srcPage.ref.objectNumber, pageRef);
44538
44595
  }
44539
- const cloneNode = (node) => {
44596
+ const cloneNode = function* (node) {
44597
+ if (++work % 16 === 0) yield;
44540
44598
  if (node.kind === "ref") {
44541
44599
  const existing = memo.get(node.objectNumber);
44542
44600
  if (existing) return existing;
@@ -44547,12 +44605,12 @@ var PdfDocument = class _PdfDocument {
44547
44605
  if (!target) return cosRef(0);
44548
44606
  const placeholderRef = this.cos.allocateObject({ kind: "null" });
44549
44607
  memo.set(node.objectNumber, placeholderRef);
44550
- const clonedTarget = cloneNode(target);
44608
+ const clonedTarget = yield* cloneNode(target);
44551
44609
  this.cos.setObject(placeholderRef.objectNumber, clonedTarget, 0);
44552
44610
  return placeholderRef;
44553
44611
  }
44554
44612
  if (node.kind === "array") {
44555
- return cosArray(node.items.map(cloneNode));
44613
+ return cosArray(yield* cloneItems(node.items));
44556
44614
  }
44557
44615
  if (node.kind === "dict") {
44558
44616
  const typeEntry = dictGet(node, "Type");
@@ -44562,13 +44620,13 @@ var PdfDocument = class _PdfDocument {
44562
44620
  if (isPageTreeNode && entry.key.decoded === "Parent") continue;
44563
44621
  newEntries.push({
44564
44622
  key: { ...entry.key },
44565
- value: cloneNode(entry.value)
44623
+ value: yield* cloneNode(entry.value)
44566
44624
  });
44567
44625
  }
44568
44626
  return { kind: "dict", entries: newEntries };
44569
44627
  }
44570
44628
  if (node.kind === "stream") {
44571
- const clonedDict = cloneNode(node.dict);
44629
+ const clonedDict = yield* cloneNode(node.dict);
44572
44630
  return {
44573
44631
  kind: "stream",
44574
44632
  dict: clonedDict,
@@ -44577,11 +44635,12 @@ var PdfDocument = class _PdfDocument {
44577
44635
  };
44578
44636
  }
44579
44637
  return node;
44580
- };
44638
+ }.bind(this);
44581
44639
  const copiedPages = [];
44582
44640
  for (const [position, idx] of indices.entries()) {
44641
+ if (++work % 16 === 0) yield;
44583
44642
  const srcPage = sourceDoc.getPage(idx);
44584
- const clonedPageDict = cloneNode(srcPage.pageDict);
44643
+ const clonedPageDict = yield* cloneNode(srcPage.pageDict);
44585
44644
  const size = srcPage.getSize();
44586
44645
  if (!dictGet(clonedPageDict, "MediaBox")) {
44587
44646
  dictSet(
@@ -44591,13 +44650,14 @@ var PdfDocument = class _PdfDocument {
44591
44650
  );
44592
44651
  }
44593
44652
  if (!dictGet(clonedPageDict, "Resources")) {
44594
- dictSet(clonedPageDict, "Resources", cloneNode(srcPage.getResourcesDict()));
44653
+ dictSet(clonedPageDict, "Resources", yield* cloneNode(srcPage.getResourcesDict()));
44595
44654
  }
44596
44655
  if (!dictGet(clonedPageDict, "Rotate") && srcPage.getRotation() !== 0) {
44597
44656
  dictSet(clonedPageDict, "Rotate", cosNumber(srcPage.getRotation()));
44598
44657
  }
44599
44658
  const inheritedBoxKeys = ["CropBox", "BleedBox", "TrimBox", "ArtBox"];
44600
44659
  for (const boxKey of inheritedBoxKeys) {
44660
+ if (++work % 16 === 0) yield;
44601
44661
  if (!dictGet(clonedPageDict, boxKey)) {
44602
44662
  const boxVal = boxKey === "CropBox" ? srcPage.getCropBox() : boxKey === "BleedBox" ? srcPage.getBleedBox() : boxKey === "TrimBox" ? srcPage.getTrimBox() : srcPage.getArtBox();
44603
44663
  if (boxVal[0] !== 0 || boxVal[1] !== 0 || boxVal[2] !== size.width || boxVal[3] !== size.height) {
@@ -44639,8 +44699,9 @@ var PdfDocument = class _PdfDocument {
44639
44699
  };
44640
44700
  const clonedRootFieldRefs = [];
44641
44701
  for (const item of srcFieldsArr.items) {
44702
+ if (++work % 16 === 0) yield;
44642
44703
  if (!hasClonedDescendant(item)) continue;
44643
- const cloned = cloneNode(item);
44704
+ const cloned = yield* cloneNode(item);
44644
44705
  if (cloned.kind === "ref") {
44645
44706
  const clonedDict = this.cos.resolveDict(cloned);
44646
44707
  const kidsArr = clonedDict ? this.cos.resolveArray(dictGet(clonedDict, "Kids")) : void 0;
@@ -44674,6 +44735,7 @@ var PdfDocument = class _PdfDocument {
44674
44735
  dstFields.items.filter((x) => x.kind === "ref").map((x) => x.objectNumber)
44675
44736
  );
44676
44737
  for (const fRef of clonedRootFieldRefs) {
44738
+ if (++work % 16 === 0) yield;
44677
44739
  if (!existingNums.has(fRef.objectNumber)) {
44678
44740
  dstFields.items.push(fRef);
44679
44741
  existingNums.add(fRef.objectNumber);
@@ -44681,11 +44743,11 @@ var PdfDocument = class _PdfDocument {
44681
44743
  }
44682
44744
  const srcDr = dictGet(srcAcroForm, "DR");
44683
44745
  if (srcDr && !dictGet(dstAcroForm, "DR")) {
44684
- dictSet(dstAcroForm, "DR", cloneNode(srcDr));
44746
+ dictSet(dstAcroForm, "DR", yield* cloneNode(srcDr));
44685
44747
  }
44686
44748
  const srcDa = dictGet(srcAcroForm, "DA");
44687
44749
  if (srcDa && !dictGet(dstAcroForm, "DA")) {
44688
- dictSet(dstAcroForm, "DA", cloneNode(srcDa));
44750
+ dictSet(dstAcroForm, "DA", yield* cloneNode(srcDa));
44689
44751
  }
44690
44752
  }
44691
44753
  }
@@ -44694,12 +44756,15 @@ var PdfDocument = class _PdfDocument {
44694
44756
  if (srcOcProps) {
44695
44757
  const dstCatalog = this.cos.resolveDict(this.cos.rootRef);
44696
44758
  if (dstCatalog && !dictGet(dstCatalog, "OCProperties")) {
44697
- dictSet(dstCatalog, "OCProperties", cloneNode(srcOcProps));
44759
+ dictSet(dstCatalog, "OCProperties", yield* cloneNode(srcOcProps));
44698
44760
  }
44699
44761
  }
44700
44762
  this.syncPageTree();
44701
44763
  return copiedPages;
44702
44764
  }
44765
+ copyPagesFrom(sourceDoc, indices) {
44766
+ return drainWork(this.copyPagesFromSteps(sourceDoc, indices));
44767
+ }
44703
44768
  embedStandardFont(fontName) {
44704
44769
  return createStandardFontHandle(fontName);
44705
44770
  }
@@ -44899,14 +44964,15 @@ var PdfDocument = class _PdfDocument {
44899
44964
  });
44900
44965
  return buildSemanticAstFromPages(extractedPages, tablesByPage, displayLists);
44901
44966
  }
44902
- save(options = {}) {
44967
+ *saveSteps(options = {}) {
44968
+ yield;
44903
44969
  this.syncPageTree();
44904
44970
  if (this.cos.requiresFullRewrite) {
44905
44971
  pruneUnusedXObjects(this.cos, this.pages);
44906
44972
  discardUnreachableObjects(this.cos);
44907
44973
  }
44908
44974
  if (options.encrypt) {
44909
- return encryptCosDocument(this.cos, options.encrypt);
44975
+ return yield* encryptCosDocumentSteps(this.cos, options.encrypt);
44910
44976
  }
44911
44977
  const allObjects = [...this.cos.objects.values()].sort(
44912
44978
  (a, b) => a.objectNumber - b.objectNumber
@@ -44914,7 +44980,7 @@ var PdfDocument = class _PdfDocument {
44914
44980
  if (options.incremental && !this.cos.requiresFullRewrite && this.cos.bytes.length > 0) {
44915
44981
  return appendIncrementalRevision(this.cos.bytes, this.cos, allObjects);
44916
44982
  }
44917
- return serializeCosDocument({
44983
+ return yield* serializeCosDocumentSteps({
44918
44984
  objects: allObjects,
44919
44985
  rootRef: this.cos.rootRef,
44920
44986
  infoRef: this.cos.infoRef,
@@ -44925,6 +44991,9 @@ var PdfDocument = class _PdfDocument {
44925
44991
  linearize: options.linearize
44926
44992
  });
44927
44993
  }
44994
+ save(options = {}) {
44995
+ return drainWork(this.saveSteps(options));
44996
+ }
44928
44997
  };
44929
44998
  function resolveDestinationPageIndex(doc, destOrActionNode) {
44930
44999
  const cos = doc.cos;
@@ -45687,7 +45756,7 @@ function applyPopplerOutputEncoding(text, encoding) {
45687
45756
  }
45688
45757
  return text;
45689
45758
  }
45690
- function inspectPdfBytes(bytes, argv = [], options = {}) {
45759
+ function* inspectPdfBytesSteps(bytes, argv = [], options = {}) {
45691
45760
  const args = parseArgs(argv);
45692
45761
  if (args.error) {
45693
45762
  return { exitCode: args.errorExitCode ?? 99, stdout: "", stderr: args.error };
@@ -45760,6 +45829,7 @@ ${[...SUPPORTED_ENCODINGS].join("\n")}
45760
45829
  const actions = collectJavaScriptActions(cos);
45761
45830
  let out2 = "";
45762
45831
  for (const act of actions) {
45832
+ yield;
45763
45833
  out2 += `Name: ${act.name}
45764
45834
  JS:
45765
45835
  ${act.js}
@@ -45791,6 +45861,7 @@ ${act.js}
45791
45861
  const customKeys = [];
45792
45862
  if (info3) {
45793
45863
  for (const entry of info3.entries) {
45864
+ yield;
45794
45865
  const key = entry.key.decoded;
45795
45866
  const resolved = cos.resolve(entry.value);
45796
45867
  if (resolved?.kind === "string") {
@@ -45805,15 +45876,18 @@ ${act.js}
45805
45876
  customKeys.sort((a, b) => a.localeCompare(b));
45806
45877
  let out = "";
45807
45878
  for (const key of ["Title", "Subject", "Keywords", "Author", "Creator", "Producer"]) {
45879
+ yield;
45808
45880
  const val = infoMap.get(key);
45809
45881
  if (val !== void 0) out += formatField(key, val);
45810
45882
  }
45811
45883
  for (const dateKey of ["CreationDate", "ModDate"]) {
45884
+ yield;
45812
45885
  const val = infoMap.get(dateKey);
45813
45886
  if (val !== void 0) out += formatField(dateKey, formatPdfDate(val, dateMode));
45814
45887
  }
45815
45888
  if (args.custom) {
45816
45889
  for (const customKey of customKeys) {
45890
+ yield;
45817
45891
  const val = infoMap.get(customKey);
45818
45892
  if (val !== void 0) out += formatField(customKey, val);
45819
45893
  }
@@ -45855,6 +45929,7 @@ ${act.js}
45855
45929
  out += formatField("Encrypted", "no");
45856
45930
  }
45857
45931
  for (let p = firstPage; p <= lastPage; p++) {
45932
+ yield;
45858
45933
  const page = doc.getPage(p - 1);
45859
45934
  const mediaBox = resolvePageBox(cos, page, "MediaBox", [0, 0, 612, 792]);
45860
45935
  const cropBox = resolvePageBox(cos, page, "CropBox", mediaBox);
@@ -45885,17 +45960,37 @@ ${act.js}
45885
45960
  out += formatField("PDF version", cos.version);
45886
45961
  return { exitCode: 0, stdout: applyPopplerOutputEncoding(out, args.encoding), stderr: "" };
45887
45962
  }
45888
- async function runPdfinfoCli(argv, files, stdinBytes = new Uint8Array(0)) {
45963
+ function inspectPdfBytes(bytes, argv = [], options = {}) {
45964
+ const steps = inspectPdfBytesSteps(bytes, argv, options);
45965
+ for (; ; ) {
45966
+ const step = steps.next();
45967
+ if (step.done) return step.value;
45968
+ }
45969
+ }
45970
+ function* inspectPdfBytesCooperativelySteps(bytes, argv = [], options = {}, signal) {
45971
+ const steps = inspectPdfBytesSteps(bytes, argv, options);
45972
+ try {
45973
+ for (; ; ) {
45974
+ yield;
45975
+ const step = steps.next();
45976
+ if (step.done)
45977
+ return step.value;
45978
+ }
45979
+ } finally {
45980
+ steps.return({ exitCode: 1, stdout: "", stderr: "" });
45981
+ }
45982
+ }
45983
+ function* runPdfinfoCliSteps(argv, files, stdinBytes = new Uint8Array(0), signal) {
45889
45984
  const args = parseArgs(argv);
45890
45985
  if (args.error) {
45891
45986
  return { exitCode: args.errorExitCode ?? 99, stdout: "", stderr: args.error };
45892
45987
  }
45893
45988
  if (args.listenc || args.version || args.help) {
45894
- return inspectPdfBytes(new Uint8Array(0), argv);
45989
+ return yield* inspectPdfBytesCooperativelySteps(new Uint8Array(0), argv, void 0, signal);
45895
45990
  }
45896
45991
  const target = args.inputFile ?? "-";
45897
45992
  if (target === "-") {
45898
- return inspectPdfBytes(stdinBytes, argv, { isStdin: true, fileSize: 0 });
45993
+ return yield* inspectPdfBytesCooperativelySteps(stdinBytes, argv, { isStdin: true, fileSize: 0 }, signal);
45899
45994
  }
45900
45995
  const fileBytes = files.get(target);
45901
45996
  if (!fileBytes) {
@@ -45906,9 +46001,13 @@ async function runPdfinfoCli(argv, files, stdinBytes = new Uint8Array(0)) {
45906
46001
  `
45907
46002
  };
45908
46003
  }
45909
- return inspectPdfBytes(fileBytes, argv, { fileSize: fileBytes.byteLength });
46004
+ return yield* inspectPdfBytesCooperativelySteps(fileBytes, argv, { fileSize: fileBytes.byteLength }, signal);
46005
+ }
46006
+ async function runPdfinfoCli(argv, files, stdinBytes = new Uint8Array(0), signal) {
46007
+ return drainSteps(runPdfinfoCliSteps(argv, files, stdinBytes, signal), signal);
45910
46008
  }
45911
46009
  async function pdfinfo(context) {
46010
+ let cooperativeWork = 63;
45912
46011
  const invocation = createOutputOperation(context, { write: async () => {
45913
46012
  } });
45914
46013
  try {
@@ -45924,7 +46023,7 @@ async function pdfinfo(context) {
45924
46023
  return { exitCode: parsed.errorExitCode ?? 99 };
45925
46024
  }
45926
46025
  if (parsed.listenc || parsed.version || parsed.help) {
45927
- const res2 = inspectPdfBytes(new Uint8Array(0), argv);
46026
+ const res2 = await drainSteps(inspectPdfBytesCooperativelySteps(new Uint8Array(0), argv, void 0, invocation.signal), invocation.signal);
45928
46027
  if (res2.stdout) {
45929
46028
  const stdout = invocation.child(context.stdout);
45930
46029
  await writeBytes(stdout.output, new TextEncoder().encode(res2.stdout), invocation.signal);
@@ -45946,6 +46045,7 @@ async function pdfinfo(context) {
45946
46045
  const chunks = [];
45947
46046
  let total = 0;
45948
46047
  for await (const chunk of readBytes(context.stdin, invocation.signal)) {
46048
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
45949
46049
  chunks.push(chunk);
45950
46050
  total += chunk.byteLength;
45951
46051
  chargeBytes(chunk.byteLength);
@@ -45953,6 +46053,7 @@ async function pdfinfo(context) {
45953
46053
  pdfBytes = new Uint8Array(total);
45954
46054
  let offset = 0;
45955
46055
  for (const c of chunks) {
46056
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
45956
46057
  pdfBytes.set(c, offset);
45957
46058
  offset += c.byteLength;
45958
46059
  }
@@ -45968,10 +46069,10 @@ async function pdfinfo(context) {
45968
46069
  return { exitCode: 1 };
45969
46070
  }
45970
46071
  }
45971
- const res = inspectPdfBytes(pdfBytes, argv, {
46072
+ const res = await drainSteps(inspectPdfBytesCooperativelySteps(pdfBytes, argv, {
45972
46073
  fileSize: isStdin ? 0 : pdfBytes.byteLength,
45973
46074
  isStdin
45974
- });
46075
+ }, invocation.signal), invocation.signal);
45975
46076
  if (res.stderr) {
45976
46077
  await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
45977
46078
  }
@@ -45984,18 +46085,20 @@ async function pdfinfo(context) {
45984
46085
  await invocation.close();
45985
46086
  }
45986
46087
  }
45987
- function createPdfinfoCommand(_options = {}) {
46088
+ function createPdfinfoCommand(options = {}) {
46089
+ const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
45988
46090
  return Object.freeze({
45989
46091
  name: "pdfinfo",
45990
46092
  runtimeIdentity: commandRuntimeIdentity,
45991
46093
  description: "Extract PDF metadata, page boxes, encryption, and structure via @poe-code/pdf-ast",
45992
46094
  execute(context) {
45993
- return pdfinfo(context);
46095
+ return new InputByteBudget(maxInputBytes).run(context, pdfinfo);
45994
46096
  }
45995
46097
  });
45996
46098
  }
45997
46099
  var pdfinfoCommand = createPdfinfoCommand();
45998
- async function runPdftoppmCli(argv, files) {
46100
+ function* runPdftoppmCliSteps(argv, files, signal) {
46101
+ let cooperativeWork = 63;
45999
46102
  let format = "ppm";
46000
46103
  let colorMode = "color";
46001
46104
  let dpi = 150;
@@ -46026,6 +46129,8 @@ async function runPdftoppmCli(argv, files) {
46026
46129
  let password = "";
46027
46130
  const positionals = [];
46028
46131
  for (let i = 0; i < argv.length; i++) {
46132
+ if (++cooperativeWork % 64 === 0)
46133
+ yield;
46029
46134
  const arg = argv[i];
46030
46135
  if (arg === "-v" || arg === "--version") {
46031
46136
  return { exitCode: 0, stdout: "pdftoppm version 24.08.0\n", stderr: "" };
@@ -46064,6 +46169,8 @@ async function runPdftoppmCli(argv, files) {
46064
46169
  } else if (arg === "-jpegopt") {
46065
46170
  const optStr = argv[++i] ?? "";
46066
46171
  for (const part of optStr.split(",")) {
46172
+ if (++cooperativeWork % 64 === 0)
46173
+ yield;
46067
46174
  const eqIdx = part.indexOf("=");
46068
46175
  if (eqIdx > 0 && part.slice(0, eqIdx).trim().toLowerCase() === "quality") {
46069
46176
  const qVal = Number(part.slice(eqIdx + 1).trim());
@@ -46126,8 +46233,11 @@ async function runPdftoppmCli(argv, files) {
46126
46233
  const outChunks = [];
46127
46234
  const progressLines = [];
46128
46235
  for (let p = firstPage; p <= endPage; p++) {
46129
- if (oddOnly && p % 2 === 0) continue;
46130
- if (evenOnly && p % 2 === 1) continue;
46236
+ yield;
46237
+ if (oddOnly && p % 2 === 0)
46238
+ continue;
46239
+ if (evenOnly && p % 2 === 1)
46240
+ continue;
46131
46241
  const page = doc.getPage(p - 1);
46132
46242
  let rawSize = page.getSize();
46133
46243
  let resolvedCropBox;
@@ -46135,6 +46245,8 @@ async function runPdftoppmCli(argv, files) {
46135
46245
  let cur = page.pageDict;
46136
46246
  const visited = /* @__PURE__ */ new Set();
46137
46247
  while (cur && !visited.has(cur)) {
46248
+ if (++cooperativeWork % 64 === 0)
46249
+ yield;
46138
46250
  visited.add(cur);
46139
46251
  const cb = doc.cos.resolveArray(dictGet(cur, "CropBox"));
46140
46252
  if (cb && cb.items.length >= 4) {
@@ -46164,11 +46276,13 @@ async function runPdftoppmCli(argv, files) {
46164
46276
  } else {
46165
46277
  if (scaleToX > 0) {
46166
46278
  effDpiX = scaleToX * 72 / ptW;
46167
- if (scaleToY <= 0) effDpiY = effDpiX;
46279
+ if (scaleToY <= 0)
46280
+ effDpiY = effDpiX;
46168
46281
  }
46169
46282
  if (scaleToY > 0) {
46170
46283
  effDpiY = scaleToY * 72 / ptH;
46171
- if (scaleToX <= 0) effDpiX = effDpiY;
46284
+ if (scaleToX <= 0)
46285
+ effDpiX = effDpiY;
46172
46286
  }
46173
46287
  }
46174
46288
  let renderedBytes;
@@ -46211,6 +46325,8 @@ async function runPdftoppmCli(argv, files) {
46211
46325
  });
46212
46326
  if (colorMode !== "color" && (format === "png" || format === "tif" || format === "jpeg")) {
46213
46327
  for (let px = 0; px < bitmap.data.length; px += 4) {
46328
+ if (++cooperativeWork % 65536 === 0)
46329
+ yield;
46214
46330
  const r = bitmap.data[px];
46215
46331
  const g = bitmap.data[px + 1];
46216
46332
  const b = bitmap.data[px + 2];
@@ -46221,27 +46337,33 @@ async function runPdftoppmCli(argv, files) {
46221
46337
  bitmap.data[px + 2] = v;
46222
46338
  }
46223
46339
  }
46224
- if (format === "png") renderedBytes = encodePng(bitmap);
46225
- else if (format === "tif") renderedBytes = encodeTiff(bitmap, effDpiX);
46226
- else if (format === "ppm") renderedBytes = encodePpm(bitmap);
46227
- else if (format === "pgm") renderedBytes = encodePgm(bitmap);
46228
- else if (format === "pbm") renderedBytes = encodePbm(bitmap);
46229
- else renderedBytes = encodeJpeg(bitmap, jpegQuality);
46340
+ if (format === "png")
46341
+ renderedBytes = encodePng(bitmap);
46342
+ else if (format === "tif")
46343
+ renderedBytes = encodeTiff(bitmap, effDpiX);
46344
+ else if (format === "ppm")
46345
+ renderedBytes = encodePpm(bitmap);
46346
+ else if (format === "pgm")
46347
+ renderedBytes = encodePgm(bitmap);
46348
+ else if (format === "pbm")
46349
+ renderedBytes = encodePbm(bitmap);
46350
+ else
46351
+ renderedBytes = encodeJpeg(bitmap, jpegQuality);
46230
46352
  }
46231
46353
  if (!prefix || prefix === "-") {
46232
46354
  outChunks.push(renderedBytes);
46233
- if (progress && !quiet) progressLines.push(`${p} ${endPage} -`);
46355
+ if (progress && !quiet)
46356
+ progressLines.push(`${p} ${endPage} -`);
46234
46357
  } else {
46235
46358
  const effectivePageNo = setPageNo !== void 0 ? setPageNo + (p - firstPage) : p;
46236
- const pageNumStr = String(effectivePageNo).padStart(
46237
- Math.max(padWidth, String(effectivePageNo).length),
46238
- "0"
46239
- );
46359
+ const pageNumStr = String(effectivePageNo).padStart(Math.max(padWidth, String(effectivePageNo).length), "0");
46240
46360
  const fileName = singleFile && !forceNum ? `${prefix}.${ext}` : `${prefix}${sep}${pageNumStr}.${ext}`;
46241
46361
  files.set(fileName, renderedBytes);
46242
- if (progress && !quiet) progressLines.push(`${p} ${endPage} ${fileName}`);
46362
+ if (progress && !quiet)
46363
+ progressLines.push(`${p} ${endPage} ${fileName}`);
46243
46364
  }
46244
- if (singleFile) break;
46365
+ if (singleFile)
46366
+ break;
46245
46367
  }
46246
46368
  const stderrText = progressLines.length > 0 ? progressLines.join("\n") + "\n" : "";
46247
46369
  if (outChunks.length > 0) {
@@ -46249,6 +46371,8 @@ async function runPdftoppmCli(argv, files) {
46249
46371
  const merged = new Uint8Array(totalLen);
46250
46372
  let off = 0;
46251
46373
  for (const c of outChunks) {
46374
+ if (++cooperativeWork % 64 === 0)
46375
+ yield;
46252
46376
  merged.set(c, off);
46253
46377
  off += c.byteLength;
46254
46378
  }
@@ -46256,6 +46380,9 @@ async function runPdftoppmCli(argv, files) {
46256
46380
  }
46257
46381
  return { exitCode: 0, stdout: "", stderr: stderrText };
46258
46382
  }
46383
+ async function runPdftoppmCli(argv, files, signal) {
46384
+ return drainSteps(runPdftoppmCliSteps(argv, files, signal), signal);
46385
+ }
46259
46386
  function formatPopplerSize(byteLength) {
46260
46387
  if (byteLength >= 1024 * 1024) {
46261
46388
  return `${(byteLength / (1024 * 1024)).toFixed(1)}M`;
@@ -46271,7 +46398,8 @@ function formatPopplerRatio(byteLength, width, height, components, bpc) {
46271
46398
  const pct = Math.min(999, Math.max(0.1, byteLength / uncompressedBytes * 100));
46272
46399
  return `${pct.toFixed(1)}%`;
46273
46400
  }
46274
- async function runPdfimagesCli(argv, files) {
46401
+ function* runPdfimagesCliSteps(argv, files, signal) {
46402
+ let cooperativeWork = 63;
46275
46403
  let listOnly = false;
46276
46404
  let usePng = false;
46277
46405
  let useJpeg = false;
@@ -46288,6 +46416,8 @@ async function runPdfimagesCli(argv, files) {
46288
46416
  let password = "";
46289
46417
  const positionals = [];
46290
46418
  for (let i = 0; i < argv.length; i++) {
46419
+ if (++cooperativeWork % 64 === 0)
46420
+ yield;
46291
46421
  const arg = argv[i];
46292
46422
  if (arg === "-v" || arg === "--version") {
46293
46423
  return { exitCode: 0, stdout: "pdfimages version 24.08.0\n", stderr: "" };
@@ -46299,23 +46429,34 @@ async function runPdfimagesCli(argv, files) {
46299
46429
  stderr: ""
46300
46430
  };
46301
46431
  }
46302
- if (arg === "-list") listOnly = true;
46303
- else if (arg === "-png") usePng = true;
46304
- else if (arg === "-j") useJpeg = true;
46305
- else if (arg === "-tiff") useTiff = true;
46306
- else if (arg === "-jp2") useJp2 = true;
46307
- else if (arg === "-jbig2") useJbig2 = true;
46308
- else if (arg === "-ccitt") useCcitt = true;
46432
+ if (arg === "-list")
46433
+ listOnly = true;
46434
+ else if (arg === "-png")
46435
+ usePng = true;
46436
+ else if (arg === "-j")
46437
+ useJpeg = true;
46438
+ else if (arg === "-tiff")
46439
+ useTiff = true;
46440
+ else if (arg === "-jp2")
46441
+ useJp2 = true;
46442
+ else if (arg === "-jbig2")
46443
+ useJbig2 = true;
46444
+ else if (arg === "-ccitt")
46445
+ useCcitt = true;
46309
46446
  else if (arg === "-all") {
46310
46447
  usePng = true;
46311
46448
  useJpeg = true;
46312
46449
  useJp2 = true;
46313
46450
  useJbig2 = true;
46314
46451
  useCcitt = true;
46315
- } else if (arg === "-p") includePage = true;
46316
- else if (arg === "-u") uniqueOnly = true;
46317
- else if (arg === "-print-filenames") printFilenames = true;
46318
- else if (arg === "-q") quiet = true;
46452
+ } else if (arg === "-p")
46453
+ includePage = true;
46454
+ else if (arg === "-u")
46455
+ uniqueOnly = true;
46456
+ else if (arg === "-print-filenames")
46457
+ printFilenames = true;
46458
+ else if (arg === "-q")
46459
+ quiet = true;
46319
46460
  else if (arg === "-f") {
46320
46461
  firstPage = Math.max(1, Number.parseInt(argv[++i] ?? "1", 10) || 1);
46321
46462
  } else if (arg === "-l") {
@@ -46358,9 +46499,11 @@ async function runPdfimagesCli(argv, files) {
46358
46499
  });
46359
46500
  const seenObjectIds = /* @__PURE__ */ new Set();
46360
46501
  const extracted = uniqueOnly ? allExtracted.filter((img) => {
46361
- if (img.inline || !img.objectId) return true;
46502
+ if (img.inline || !img.objectId)
46503
+ return true;
46362
46504
  const key = `${img.objectId.objNum}:${img.objectId.genNum}`;
46363
- if (seenObjectIds.has(key)) return false;
46505
+ if (seenObjectIds.has(key))
46506
+ return false;
46364
46507
  seenObjectIds.add(key);
46365
46508
  return true;
46366
46509
  }) : allExtracted;
@@ -46371,22 +46514,16 @@ async function runPdfimagesCli(argv, files) {
46371
46514
  const root = positionals[1] ?? "image";
46372
46515
  const printedFilenames = [];
46373
46516
  for (let idx = 0; idx < extracted.length; idx++) {
46517
+ if (++cooperativeWork % 64 === 0)
46518
+ yield;
46374
46519
  const img = extracted[idx];
46375
46520
  const numStr = String(idx).padStart(3, "0");
46376
46521
  const objField = img.inline || !img.objectId ? " [inline]" : `${String(img.objectId.objNum).padStart(6)} ${String(img.objectId.genNum).padStart(2)}`;
46377
46522
  const sizeStr = formatPopplerSize(img.byteLength).padStart(5);
46378
- const ratioStr = formatPopplerRatio(
46379
- img.byteLength,
46380
- img.width,
46381
- img.height,
46382
- img.components,
46383
- img.bitsPerComponent
46384
- ).padStart(5);
46523
+ const ratioStr = formatPopplerRatio(img.byteLength, img.width, img.height, img.components, img.bitsPerComponent).padStart(5);
46385
46524
  const interpStr = (img.interpolate ? "yes" : "no").padStart(6);
46386
46525
  const colorCol = (img.colorSpaceLabel ?? img.colorSpace).padEnd(5);
46387
- listLines.push(
46388
- `${String(img.pageNumber).padStart(4)} ${String(idx).padStart(5)} ${img.type.padEnd(6)} ${String(img.width).padStart(5)} ${String(img.height).padStart(6)} ${colorCol} ${String(img.components).padStart(4)} ${String(img.bitsPerComponent).padStart(3)} ${img.encoding.padEnd(5)} ${interpStr} ${objField} ${String(img.xPpi).padStart(5)} ${String(img.yPpi).padStart(5)} ${sizeStr} ${ratioStr}`
46389
- );
46526
+ listLines.push(`${String(img.pageNumber).padStart(4)} ${String(idx).padStart(5)} ${img.type.padEnd(6)} ${String(img.width).padStart(5)} ${String(img.height).padStart(6)} ${colorCol} ${String(img.components).padStart(4)} ${String(img.bitsPerComponent).padStart(3)} ${img.encoding.padEnd(5)} ${interpStr} ${objField} ${String(img.xPpi).padStart(5)} ${String(img.yPpi).padStart(5)} ${sizeStr} ${ratioStr}`);
46390
46527
  if (!listOnly) {
46391
46528
  let ext;
46392
46529
  let outBytes;
@@ -46420,7 +46557,8 @@ async function runPdfimagesCli(argv, files) {
46420
46557
  if (ext === "jb2e" && img.jbig2GlobalsBytes) {
46421
46558
  const jb2gName = includePage ? `${root}-${String(img.pageNumber).padStart(3, "0")}-${numStr}.jb2g` : `${root}-${numStr}.jb2g`;
46422
46559
  files.set(jb2gName, img.jbig2GlobalsBytes);
46423
- if (printFilenames) printedFilenames.push(jb2gName);
46560
+ if (printFilenames)
46561
+ printedFilenames.push(jb2gName);
46424
46562
  }
46425
46563
  if (ext === "ccitt") {
46426
46564
  const paramsBase = includePage ? `${root}-${String(img.pageNumber).padStart(3, "0")}-${numStr}.params` : `${root}-${numStr}.params`;
@@ -46435,9 +46573,11 @@ async function runPdfimagesCli(argv, files) {
46435
46573
  ].join(" ");
46436
46574
  files.set(paramsBase, new TextEncoder().encode(`${extraFlags}
46437
46575
  `));
46438
- if (printFilenames) printedFilenames.push(paramsBase);
46576
+ if (printFilenames)
46577
+ printedFilenames.push(paramsBase);
46439
46578
  }
46440
- if (printFilenames) printedFilenames.push(outName);
46579
+ if (printFilenames)
46580
+ printedFilenames.push(outName);
46441
46581
  }
46442
46582
  }
46443
46583
  if (listOnly) {
@@ -46448,6 +46588,9 @@ async function runPdfimagesCli(argv, files) {
46448
46588
  }
46449
46589
  return { exitCode: 0, stdout: "", stderr: "" };
46450
46590
  }
46591
+ async function runPdfimagesCli(argv, files, signal) {
46592
+ return drainSteps(runPdfimagesCliSteps(argv, files, signal), signal);
46593
+ }
46451
46594
  function copyDocumentMetadata(srcDoc, dstDoc) {
46452
46595
  const meta = srcDoc.getMetadata();
46453
46596
  if (meta.title) dstDoc.setTitle(meta.title);
@@ -46457,10 +46600,13 @@ function copyDocumentMetadata(srcDoc, dstDoc) {
46457
46600
  if (meta.creator) dstDoc.setCreator(meta.creator);
46458
46601
  if (meta.producer) dstDoc.setProducer(meta.producer);
46459
46602
  }
46460
- async function runPdfuniteCli(argv, files) {
46603
+ function* runPdfuniteCliSteps(argv, files, signal) {
46604
+ let cooperativeWork = 63;
46461
46605
  const positionals = [];
46462
46606
  let password = "";
46463
46607
  for (let i = 0; i < argv.length; i++) {
46608
+ if (++cooperativeWork % 64 === 0)
46609
+ yield;
46464
46610
  const arg = argv[i];
46465
46611
  if (arg === "-v" || arg === "--version") {
46466
46612
  return { exitCode: 0, stdout: "pdfunite version 24.08.0\n", stderr: "" };
@@ -46476,7 +46622,8 @@ async function runPdfuniteCli(argv, files) {
46476
46622
  password = argv[++i] ?? "";
46477
46623
  continue;
46478
46624
  }
46479
- if (!arg.startsWith("-")) positionals.push(arg);
46625
+ if (!arg.startsWith("-"))
46626
+ positionals.push(arg);
46480
46627
  }
46481
46628
  if (positionals.length < 3) {
46482
46629
  return {
@@ -46495,6 +46642,8 @@ async function runPdfuniteCli(argv, files) {
46495
46642
  const mergedPageLabelNums = [];
46496
46643
  let pageOffset = 0;
46497
46644
  for (const srcPath of sourcePaths) {
46645
+ if (++cooperativeWork % 64 === 0)
46646
+ yield;
46498
46647
  const srcBytes = files.get(srcPath);
46499
46648
  if (!srcBytes) {
46500
46649
  return { exitCode: 1, stdout: "", stderr: `I/O Error: Couldn't open file '${srcPath}'
@@ -46512,6 +46661,8 @@ async function runPdfuniteCli(argv, files) {
46512
46661
  copiedMeta = true;
46513
46662
  }
46514
46663
  for (const att of collectEmbeddedAttachments(srcDoc)) {
46664
+ if (++cooperativeWork % 64 === 0)
46665
+ yield;
46515
46666
  if (!seenAttachmentNames.has(att.name)) {
46516
46667
  seenAttachmentNames.add(att.name);
46517
46668
  mergedAttachments.push(att);
@@ -46519,7 +46670,8 @@ async function runPdfuniteCli(argv, files) {
46519
46670
  }
46520
46671
  const srcCat = srcDoc.cos.resolveDict(srcDoc.cos.rootRef);
46521
46672
  const collectSrcPageLabels = (plNode, visited = /* @__PURE__ */ new Set()) => {
46522
- if (!plNode) return;
46673
+ if (!plNode)
46674
+ return;
46523
46675
  const numsArr = srcDoc.cos.resolveArray(dictGet(plNode, "Nums"));
46524
46676
  if (numsArr) {
46525
46677
  for (let idx = 0; idx + 1 < numsArr.items.length; idx += 2) {
@@ -46530,9 +46682,12 @@ async function runPdfuniteCli(argv, files) {
46530
46682
  const sNode = srcDoc.cos.resolve(dictGet(vDict, "S"));
46531
46683
  const stNode = srcDoc.cos.resolve(dictGet(vDict, "St"));
46532
46684
  const pNode = srcDoc.cos.resolve(dictGet(vDict, "P"));
46533
- if (sNode?.kind === "name") clonedEntries.S = cosName(sNode.decoded);
46534
- if (stNode?.kind === "number") clonedEntries.St = cosNumber(stNode.value);
46535
- if (pNode?.kind === "string") clonedEntries.P = { kind: "string", bytes: new Uint8Array(pNode.bytes), format: pNode.format };
46685
+ if (sNode?.kind === "name")
46686
+ clonedEntries.S = cosName(sNode.decoded);
46687
+ if (stNode?.kind === "number")
46688
+ clonedEntries.St = cosNumber(stNode.value);
46689
+ if (pNode?.kind === "string")
46690
+ clonedEntries.P = { kind: "string", bytes: new Uint8Array(pNode.bytes), format: pNode.format };
46536
46691
  mergedPageLabelNums.push(cosNumber(pageOffset + kNode.value), cosDict(clonedEntries));
46537
46692
  }
46538
46693
  }
@@ -46541,7 +46696,8 @@ async function runPdfuniteCli(argv, files) {
46541
46696
  if (kidsArr) {
46542
46697
  for (const kid of kidsArr.items) {
46543
46698
  if (kid.kind === "ref") {
46544
- if (visited.has(kid.objectNumber)) continue;
46699
+ if (visited.has(kid.objectNumber))
46700
+ continue;
46545
46701
  visited.add(kid.objectNumber);
46546
46702
  }
46547
46703
  collectSrcPageLabels(srcDoc.cos.resolveDict(kid), visited);
@@ -46556,11 +46712,13 @@ async function runPdfuniteCli(argv, files) {
46556
46712
  let cur = nodeOrRef;
46557
46713
  while (cur) {
46558
46714
  if (cur.kind === "ref") {
46559
- if (visited.has(cur.objectNumber)) break;
46715
+ if (visited.has(cur.objectNumber))
46716
+ break;
46560
46717
  visited.add(cur.objectNumber);
46561
46718
  }
46562
46719
  const d = srcDoc.cos.resolveDict(cur);
46563
- if (!d) break;
46720
+ if (!d)
46721
+ break;
46564
46722
  const tNode = srcDoc.cos.resolve(dictGet(d, "Title"));
46565
46723
  const title = tNode?.kind === "string" ? decodePdfString(tNode) : "";
46566
46724
  const localPage = resolveDestinationPageIndex(srcDoc, dictGet(d, "Dest") ?? dictGet(d, "A")) ?? 0;
@@ -46568,11 +46726,13 @@ async function runPdfuniteCli(argv, files) {
46568
46726
  mergedOutlineItems.push({ title, targetPageIdx: pageOffset + localPage });
46569
46727
  }
46570
46728
  const firstChild = dictGet(d, "First");
46571
- if (firstChild) collectOutlinesFromSrc(firstChild, visited);
46729
+ if (firstChild)
46730
+ collectOutlinesFromSrc(firstChild, visited);
46572
46731
  cur = dictGet(d, "Next");
46573
46732
  }
46574
46733
  };
46575
- if (srcOutlines) collectOutlinesFromSrc(dictGet(srcOutlines, "First"));
46734
+ if (srcOutlines)
46735
+ collectOutlinesFromSrc(dictGet(srcOutlines, "First"));
46576
46736
  const indices = Array.from({ length: srcDoc.pageCount }, (_, idx) => idx);
46577
46737
  merged.copyPagesFrom(srcDoc, indices);
46578
46738
  pageOffset += srcDoc.pageCount;
@@ -46584,6 +46744,8 @@ async function runPdfuniteCli(argv, files) {
46584
46744
  const outlinesRef = merged.cos.allocateObject(outlinesDict);
46585
46745
  const itemRefs = [];
46586
46746
  for (const bm of mergedOutlineItems) {
46747
+ if (++cooperativeWork % 64 === 0)
46748
+ yield;
46587
46749
  const pRef = merged.getPage(Math.min(merged.pageCount - 1, Math.max(0, bm.targetPageIdx))).ref;
46588
46750
  const iDict = cosDict({
46589
46751
  Title: { kind: "string", bytes: new TextEncoder().encode(bm.title), format: "literal" },
@@ -46613,21 +46775,19 @@ async function runPdfuniteCli(argv, files) {
46613
46775
  if (mergedAttachments.length > 0) {
46614
46776
  const namesPairs = [];
46615
46777
  for (const att of mergedAttachments) {
46616
- const efRef = merged.cos.allocateObject(
46617
- cosStream(att.data, {
46618
- dict: cosDict({ Type: cosName("EmbeddedFile") }),
46619
- compress: true
46620
- })
46621
- );
46778
+ if (++cooperativeWork % 64 === 0)
46779
+ yield;
46780
+ const efRef = merged.cos.allocateObject(cosStream(att.data, {
46781
+ dict: cosDict({ Type: cosName("EmbeddedFile") }),
46782
+ compress: true
46783
+ }));
46622
46784
  const fnBytes = new TextEncoder().encode(att.name);
46623
- const fsRef = merged.cos.allocateObject(
46624
- cosDict({
46625
- Type: cosName("Filespec"),
46626
- F: { kind: "string", bytes: fnBytes, format: "literal" },
46627
- UF: { kind: "string", bytes: fnBytes, format: "literal" },
46628
- EF: cosDict({ F: efRef, UF: efRef })
46629
- })
46630
- );
46785
+ const fsRef = merged.cos.allocateObject(cosDict({
46786
+ Type: cosName("Filespec"),
46787
+ F: { kind: "string", bytes: fnBytes, format: "literal" },
46788
+ UF: { kind: "string", bytes: fnBytes, format: "literal" },
46789
+ EF: cosDict({ F: efRef, UF: efRef })
46790
+ }));
46631
46791
  namesPairs.push({ kind: "string", bytes: fnBytes, format: "literal" }, fsRef);
46632
46792
  }
46633
46793
  const efTreeRef = merged.cos.allocateObject(cosDict({ Names: cosArray(namesPairs) }));
@@ -46646,6 +46806,9 @@ async function runPdfuniteCli(argv, files) {
46646
46806
  files.set(destPath, merged.save());
46647
46807
  return { exitCode: 0, stdout: "", stderr: "" };
46648
46808
  }
46809
+ async function runPdfuniteCli(argv, files, signal) {
46810
+ return drainSteps(runPdfuniteCliSteps(argv, files, signal), signal);
46811
+ }
46649
46812
  function parsePdfseparateSpec(pattern) {
46650
46813
  let hasPageSpec = false;
46651
46814
  for (let i = 0; i < pattern.length; i++) {
@@ -46698,12 +46861,15 @@ function parsePdfseparateSpec(pattern) {
46698
46861
  }
46699
46862
  };
46700
46863
  }
46701
- async function runPdfseparateCli(argv, files) {
46864
+ function* runPdfseparateCliSteps(argv, files, signal) {
46865
+ let cooperativeWork = 63;
46702
46866
  let firstPage = 1;
46703
46867
  let lastPage = 0;
46704
46868
  let password = "";
46705
46869
  const positionals = [];
46706
46870
  for (let i = 0; i < argv.length; i++) {
46871
+ if (++cooperativeWork % 64 === 0)
46872
+ yield;
46707
46873
  const arg = argv[i];
46708
46874
  if (arg === "-v" || arg === "--version") {
46709
46875
  return { exitCode: 0, stdout: "pdfseparate version 24.08.0\n", stderr: "" };
@@ -46715,10 +46881,14 @@ async function runPdfseparateCli(argv, files) {
46715
46881
  stderr: ""
46716
46882
  };
46717
46883
  }
46718
- if (arg === "-f") firstPage = Math.max(1, Number(argv[++i] ?? "1") || 1);
46719
- else if (arg === "-l") lastPage = Math.max(0, Number(argv[++i] ?? "0") || 0);
46720
- else if (arg === "-upw" || arg === "-opw") password = argv[++i] ?? "";
46721
- else if (!arg.startsWith("-")) positionals.push(arg);
46884
+ if (arg === "-f")
46885
+ firstPage = Math.max(1, Number(argv[++i] ?? "1") || 1);
46886
+ else if (arg === "-l")
46887
+ lastPage = Math.max(0, Number(argv[++i] ?? "0") || 0);
46888
+ else if (arg === "-upw" || arg === "-opw")
46889
+ password = argv[++i] ?? "";
46890
+ else if (!arg.startsWith("-"))
46891
+ positionals.push(arg);
46722
46892
  }
46723
46893
  if (positionals.length < 2) {
46724
46894
  return {
@@ -46761,6 +46931,7 @@ async function runPdfseparateCli(argv, files) {
46761
46931
  };
46762
46932
  }
46763
46933
  for (let p = firstPage; p <= endPage; p++) {
46934
+ yield;
46764
46935
  const singleDoc = PdfDocument.create();
46765
46936
  copyDocumentMetadata(srcDoc, singleDoc);
46766
46937
  singleDoc.copyPagesFrom(srcDoc, [p - 1]);
@@ -46769,6 +46940,9 @@ async function runPdfseparateCli(argv, files) {
46769
46940
  }
46770
46941
  return { exitCode: 0, stdout: "", stderr: "" };
46771
46942
  }
46943
+ async function runPdfseparateCli(argv, files, signal) {
46944
+ return drainSteps(runPdfseparateCliSteps(argv, files, signal), signal);
46945
+ }
46772
46946
  function isSubsetFontTag(fontName) {
46773
46947
  if (fontName.length < 8 || fontName[6] !== "+") return false;
46774
46948
  for (let i = 0; i < 6; i++) {
@@ -46777,10 +46951,8 @@ function isSubsetFontTag(fontName) {
46777
46951
  }
46778
46952
  return true;
46779
46953
  }
46780
- async function runPdffontsCli(argv, files) {
46781
- return runPdffontsCliSync(argv, files);
46782
- }
46783
- function runPdffontsCliSync(argv, files) {
46954
+ function* runPdffontsCliSteps(argv, files, signal) {
46955
+ let cooperativeWork = 63;
46784
46956
  let firstPage = 1;
46785
46957
  let lastPage = 0;
46786
46958
  let password = "";
@@ -46789,6 +46961,8 @@ function runPdffontsCliSync(argv, files) {
46789
46961
  let showSubst = false;
46790
46962
  const positionals = [];
46791
46963
  for (let i = 0; i < argv.length; i++) {
46964
+ if (++cooperativeWork % 64 === 0)
46965
+ yield;
46792
46966
  const arg = argv[i];
46793
46967
  if (arg === "-v" || arg === "--version") {
46794
46968
  return { exitCode: 0, stdout: "pdffonts version 24.08.0\n", stderr: "" };
@@ -46800,15 +46974,21 @@ function runPdffontsCliSync(argv, files) {
46800
46974
  stderr: ""
46801
46975
  };
46802
46976
  }
46803
- if (arg === "-f") firstPage = Math.max(1, Number.parseInt(argv[++i] ?? "1", 10) || 1);
46804
- else if (arg === "-l") lastPage = Math.max(0, Number.parseInt(argv[++i] ?? "0", 10) || 0);
46805
- else if (arg === "-upw" || arg === "-opw") password = argv[++i] ?? "";
46806
- else if (arg === "-loc") showLoc = true;
46977
+ if (arg === "-f")
46978
+ firstPage = Math.max(1, Number.parseInt(argv[++i] ?? "1", 10) || 1);
46979
+ else if (arg === "-l")
46980
+ lastPage = Math.max(0, Number.parseInt(argv[++i] ?? "0", 10) || 0);
46981
+ else if (arg === "-upw" || arg === "-opw")
46982
+ password = argv[++i] ?? "";
46983
+ else if (arg === "-loc")
46984
+ showLoc = true;
46807
46985
  else if (arg === "-locPS") {
46808
46986
  showLoc = true;
46809
46987
  showLocPs = true;
46810
- } else if (arg === "-subst") showSubst = true;
46811
- else if (!arg.startsWith("-") || arg === "-") positionals.push(arg);
46988
+ } else if (arg === "-subst")
46989
+ showSubst = true;
46990
+ else if (!arg.startsWith("-") || arg === "-")
46991
+ positionals.push(arg);
46812
46992
  }
46813
46993
  const inputPath = positionals[0] ?? (files.has("-") ? "-" : void 0);
46814
46994
  if (!inputPath) {
@@ -46848,16 +47028,19 @@ function runPdffontsCliSync(argv, files) {
46848
47028
  "------------------------------------ ----------------- ---------------- --- --- --- ---------"
46849
47029
  ];
46850
47030
  const collectFontsFromResources = (resDict, visitedForms = /* @__PURE__ */ new Set()) => {
46851
- if (!resDict) return;
47031
+ if (!resDict)
47032
+ return;
46852
47033
  const fontMap = cos.resolveDict(dictGet(resDict, "Font"));
46853
47034
  if (fontMap) {
46854
47035
  for (const entry of fontMap.entries) {
46855
47036
  const rawVal = entry.value;
46856
47037
  const objKey = rawVal.kind === "ref" ? `${rawVal.objectNumber}:${rawVal.generationNumber}` : `inline:${entry.key.decoded}`;
46857
- if (seenFontKeys.has(objKey)) continue;
47038
+ if (seenFontKeys.has(objKey))
47039
+ continue;
46858
47040
  seenFontKeys.add(objKey);
46859
47041
  const fontDict = cos.resolveDict(rawVal);
46860
- if (!fontDict) continue;
47042
+ if (!fontDict)
47043
+ continue;
46861
47044
  const baseFontNode = cos.resolve(dictGet(fontDict, "BaseFont") ?? dictGet(fontDict, "Name"));
46862
47045
  const fontName = baseFontNode?.kind === "name" ? baseFontNode.decoded : baseFontNode?.kind === "string" ? decodePdfString(baseFontNode) : "[none]";
46863
47046
  const subtypeNode = cos.resolve(dictGet(fontDict, "Subtype"));
@@ -46870,13 +47053,14 @@ function runPdffontsCliSync(argv, files) {
46870
47053
  }
46871
47054
  }
46872
47055
  const descriptorDict = cos.resolveDict(dictGet(fontDict, "FontDescriptor")) ?? (descFontDict ? cos.resolveDict(dictGet(descFontDict, "FontDescriptor")) : void 0);
46873
- const hasEmbeddedFile = Boolean(
46874
- rawSubtype === "Type3" || descriptorDict && (dictGet(descriptorDict, "FontFile") || dictGet(descriptorDict, "FontFile2") || dictGet(descriptorDict, "FontFile3"))
46875
- );
47056
+ const hasEmbeddedFile = Boolean(rawSubtype === "Type3" || descriptorDict && (dictGet(descriptorDict, "FontFile") || dictGet(descriptorDict, "FontFile2") || dictGet(descriptorDict, "FontFile3")));
46876
47057
  let fontTypeLabel = "Type 1";
46877
- if (rawSubtype === "TrueType") fontTypeLabel = "TrueType";
46878
- else if (rawSubtype === "MMType1") fontTypeLabel = "MM Type 1";
46879
- else if (rawSubtype === "Type3") fontTypeLabel = "Type 3";
47058
+ if (rawSubtype === "TrueType")
47059
+ fontTypeLabel = "TrueType";
47060
+ else if (rawSubtype === "MMType1")
47061
+ fontTypeLabel = "MM Type 1";
47062
+ else if (rawSubtype === "Type3")
47063
+ fontTypeLabel = "Type 3";
46880
47064
  else if (rawSubtype === "Type0") {
46881
47065
  const descSubtype = descFontDict ? cos.resolve(dictGet(descFontDict, "Subtype")) : void 0;
46882
47066
  fontTypeLabel = descSubtype?.kind === "name" && descSubtype.decoded === "CIDFontType2" ? "CID TrueType" : "CID Type 0";
@@ -46887,10 +47071,14 @@ function runPdffontsCliSync(argv, files) {
46887
47071
  let encodingLabel = "Builtin";
46888
47072
  if (encNode?.kind === "name") {
46889
47073
  const eName = encNode.decoded;
46890
- if (eName === "WinAnsiEncoding") encodingLabel = "WinAnsi";
46891
- else if (eName === "MacRomanEncoding") encodingLabel = "MacRoman";
46892
- else if (eName === "StandardEncoding") encodingLabel = "Standard";
46893
- else encodingLabel = eName;
47074
+ if (eName === "WinAnsiEncoding")
47075
+ encodingLabel = "WinAnsi";
47076
+ else if (eName === "MacRomanEncoding")
47077
+ encodingLabel = "MacRoman";
47078
+ else if (eName === "StandardEncoding")
47079
+ encodingLabel = "Standard";
47080
+ else
47081
+ encodingLabel = eName;
46894
47082
  } else if (encNode?.kind === "dict") {
46895
47083
  encodingLabel = "Custom";
46896
47084
  }
@@ -46908,14 +47096,10 @@ function runPdffontsCliSync(argv, files) {
46908
47096
  else if (fontName === "Symbol") subFontName = "Standard Symbols PS";
46909
47097
  else if (fontName === "ZapfDingbats") subFontName = "D050000L";
46910
47098
  const subFontFile = `/usr/share/fonts/type1/urw-base35/${subFontName.replaceAll(" ", "")}.t1`;
46911
- rows.push(
46912
- `${fontName.slice(0, 36).padEnd(36)} ${objIdStr} ${subFontName.slice(0, 36).padEnd(36)} ${subFontFile}`
46913
- );
47099
+ rows.push(`${fontName.slice(0, 36).padEnd(36)} ${objIdStr} ${subFontName.slice(0, 36).padEnd(36)} ${subFontFile}`);
46914
47100
  }
46915
47101
  } else {
46916
- rows.push(
46917
- `${fontName.slice(0, 36).padEnd(36)} ${fontTypeLabel.padEnd(17)} ${encodingLabel.slice(0, 16).padEnd(16)} ${embStr} ${subStr} ${uniStr} ${objIdStr}${locSuffix}`
46918
- );
47102
+ rows.push(`${fontName.slice(0, 36).padEnd(36)} ${fontTypeLabel.padEnd(17)} ${encodingLabel.slice(0, 16).padEnd(16)} ${embStr} ${subStr} ${uniStr} ${objIdStr}${locSuffix}`);
46919
47103
  }
46920
47104
  if (rawSubtype === "Type3") {
46921
47105
  collectFontsFromResources(cos.resolveDict(dictGet(fontDict, "Resources")), visitedForms);
@@ -46928,10 +47112,7 @@ function runPdffontsCliSync(argv, files) {
46928
47112
  const gsDict = cos.resolveDict(gsEntry.value);
46929
47113
  const gsFontArr = gsDict ? cos.resolveArray(dictGet(gsDict, "Font")) : void 0;
46930
47114
  if (gsFontArr && gsFontArr.items.length >= 1) {
46931
- collectFontsFromResources(
46932
- { kind: "dict", entries: [{ key: { kind: "name", decoded: "Font", rawBytes: new Uint8Array(0) }, value: { kind: "dict", entries: [{ key: { kind: "name", decoded: `ExtGS_${gsEntry.key.decoded}`, rawBytes: new Uint8Array(0) }, value: gsFontArr.items[0] }] } }] },
46933
- visitedForms
46934
- );
47115
+ collectFontsFromResources({ kind: "dict", entries: [{ key: { kind: "name", decoded: "Font", rawBytes: new Uint8Array(0) }, value: { kind: "dict", entries: [{ key: { kind: "name", decoded: `ExtGS_${gsEntry.key.decoded}`, rawBytes: new Uint8Array(0) }, value: gsFontArr.items[0] }] } }] }, visitedForms);
46935
47116
  }
46936
47117
  }
46937
47118
  }
@@ -46939,7 +47120,8 @@ function runPdffontsCliSync(argv, files) {
46939
47120
  if (xobjMap) {
46940
47121
  for (const entry of xobjMap.entries) {
46941
47122
  if (entry.value.kind === "ref") {
46942
- if (visitedForms.has(entry.value.objectNumber)) continue;
47123
+ if (visitedForms.has(entry.value.objectNumber))
47124
+ continue;
46943
47125
  visitedForms.add(entry.value.objectNumber);
46944
47126
  }
46945
47127
  const xobj = cos.resolve(entry.value);
@@ -46955,7 +47137,8 @@ function runPdffontsCliSync(argv, files) {
46955
47137
  if (patMap) {
46956
47138
  for (const entry of patMap.entries) {
46957
47139
  if (entry.value.kind === "ref") {
46958
- if (visitedForms.has(entry.value.objectNumber)) continue;
47140
+ if (visitedForms.has(entry.value.objectNumber))
47141
+ continue;
46959
47142
  visitedForms.add(entry.value.objectNumber);
46960
47143
  }
46961
47144
  const pat = cos.resolve(entry.value);
@@ -46969,20 +47152,28 @@ function runPdffontsCliSync(argv, files) {
46969
47152
  const acroFormDict = rootDict ? cos.resolveDict(dictGet(rootDict, "AcroForm")) : void 0;
46970
47153
  const acroDrDict = acroFormDict ? cos.resolveDict(dictGet(acroFormDict, "DR")) : void 0;
46971
47154
  for (let p = firstPage; p <= endPage; p++) {
47155
+ yield;
46972
47156
  const page = doc.getPage(p - 1);
46973
47157
  collectFontsFromResources(page.getResourcesDict());
46974
47158
  const annots = cos.resolveArray(dictGet(page.pageDict, "Annots"));
46975
47159
  if (annots) {
46976
47160
  for (const item of annots.items) {
47161
+ if (++cooperativeWork % 64 === 0)
47162
+ yield;
46977
47163
  const annotDict = cos.resolveDict(item);
46978
47164
  const apDict = annotDict ? cos.resolveDict(dictGet(annotDict, "AP")) : void 0;
46979
- if (!apDict) continue;
47165
+ if (!apDict)
47166
+ continue;
46980
47167
  for (const apKey of ["N", "R", "D"]) {
47168
+ if (++cooperativeWork % 64 === 0)
47169
+ yield;
46981
47170
  const apVal = cos.resolve(dictGet(apDict, apKey));
46982
47171
  if (apVal?.kind === "stream") {
46983
47172
  collectFontsFromResources(cos.resolveDict(dictGet(apVal.dict, "Resources")));
46984
47173
  } else if (apVal?.kind === "dict") {
46985
47174
  for (const sub of apVal.entries) {
47175
+ if (++cooperativeWork % 64 === 0)
47176
+ yield;
46986
47177
  const subStream = cos.resolve(sub.value);
46987
47178
  if (subStream?.kind === "stream") {
46988
47179
  collectFontsFromResources(cos.resolveDict(dictGet(subStream.dict, "Resources")));
@@ -46998,6 +47189,17 @@ function runPdffontsCliSync(argv, files) {
46998
47189
  }
46999
47190
  return { exitCode: 0, stdout: rows.join("\n") + "\n", stderr: "" };
47000
47191
  }
47192
+ async function runPdffontsCli(argv, files, signal) {
47193
+ return drainSteps(runPdffontsCliSteps(argv, files, signal), signal);
47194
+ }
47195
+ function runPdffontsCliSync(argv, files, signal) {
47196
+ const steps = runPdffontsCliSteps(argv, files, signal);
47197
+ let next = steps.next();
47198
+ while (!next.done) {
47199
+ next = steps.next();
47200
+ }
47201
+ return next.value;
47202
+ }
47001
47203
  function collectEmbeddedAttachments(doc) {
47002
47204
  const cos = doc.cos;
47003
47205
  const results = [];
@@ -47069,7 +47271,8 @@ function collectEmbeddedAttachments(doc) {
47069
47271
  }
47070
47272
  return results;
47071
47273
  }
47072
- function runPdfdetachCliSync(argv, files) {
47274
+ function* runPdfdetachCliSteps(argv, files, signal) {
47275
+ let cooperativeWork = 63;
47073
47276
  let listOnly = false;
47074
47277
  let saveNumber = 0;
47075
47278
  let saveFileName = "";
@@ -47079,6 +47282,8 @@ function runPdfdetachCliSync(argv, files) {
47079
47282
  let encoding = "UTF-8";
47080
47283
  const positionals = [];
47081
47284
  for (let i = 0; i < argv.length; i++) {
47285
+ if (++cooperativeWork % 64 === 0)
47286
+ yield;
47082
47287
  const arg = argv[i];
47083
47288
  if (arg === "-v" || arg === "--version") {
47084
47289
  return { exitCode: 0, stdout: "pdfdetach version 24.08.0\n", stderr: "" };
@@ -47090,12 +47295,18 @@ function runPdfdetachCliSync(argv, files) {
47090
47295
  stderr: ""
47091
47296
  };
47092
47297
  }
47093
- if (arg === "-list") listOnly = true;
47094
- else if (arg === "-save") saveNumber = Number.parseInt(argv[++i] ?? "0", 10) || 0;
47095
- else if (arg === "-savefile") saveFileName = argv[++i] ?? "";
47096
- else if (arg === "-saveall") saveAll = true;
47097
- else if (arg === "-o") outputPath = argv[++i] ?? "";
47098
- else if (arg === "-upw" || arg === "-opw") password = argv[++i] ?? "";
47298
+ if (arg === "-list")
47299
+ listOnly = true;
47300
+ else if (arg === "-save")
47301
+ saveNumber = Number.parseInt(argv[++i] ?? "0", 10) || 0;
47302
+ else if (arg === "-savefile")
47303
+ saveFileName = argv[++i] ?? "";
47304
+ else if (arg === "-saveall")
47305
+ saveAll = true;
47306
+ else if (arg === "-o")
47307
+ outputPath = argv[++i] ?? "";
47308
+ else if (arg === "-upw" || arg === "-opw")
47309
+ password = argv[++i] ?? "";
47099
47310
  else if (arg === "-enc") {
47100
47311
  const nextEnc = argv[++i] ?? "";
47101
47312
  if (!SUPPORTED_ENCODINGS.has(nextEnc)) {
@@ -47107,7 +47318,8 @@ function runPdfdetachCliSync(argv, files) {
47107
47318
  };
47108
47319
  }
47109
47320
  encoding = nextEnc;
47110
- } else if (!arg.startsWith("-") || arg === "-") positionals.push(arg);
47321
+ } else if (!arg.startsWith("-") || arg === "-")
47322
+ positionals.push(arg);
47111
47323
  }
47112
47324
  const inputPath = positionals[0] ?? (files.has("-") ? "-" : void 0);
47113
47325
  if (!inputPath) {
@@ -47129,6 +47341,8 @@ function runPdfdetachCliSync(argv, files) {
47129
47341
  if (listOnly || !saveNumber && !saveFileName && !saveAll) {
47130
47342
  const lines = [`${attachments.length} embedded files`];
47131
47343
  for (let i = 0; i < attachments.length; i++) {
47344
+ if (++cooperativeWork % 64 === 0)
47345
+ yield;
47132
47346
  const attName = applyPopplerOutputEncoding(attachments[i].name, encoding);
47133
47347
  lines.push(`${i + 1}: ${attName}`);
47134
47348
  }
@@ -47157,13 +47371,23 @@ function runPdfdetachCliSync(argv, files) {
47157
47371
  if (saveAll) {
47158
47372
  const prefix = outputPath ? outputPath.endsWith("/") ? outputPath.slice(0, -1) : outputPath : "";
47159
47373
  for (const att of attachments) {
47374
+ if (++cooperativeWork % 64 === 0)
47375
+ yield;
47160
47376
  files.set(prefix ? `${prefix}/${att.name}` : att.name, att.data);
47161
47377
  }
47162
47378
  }
47163
47379
  return { exitCode: 0, stdout: "", stderr: "" };
47164
47380
  }
47165
- async function runPdfdetachCli(argv, files) {
47166
- return runPdfdetachCliSync(argv, files);
47381
+ async function runPdfdetachCli(argv, files, signal) {
47382
+ return drainSteps(runPdfdetachCliSteps(argv, files, signal), signal);
47383
+ }
47384
+ function runPdfdetachCliSync(argv, files, signal) {
47385
+ const steps = runPdfdetachCliSteps(argv, files, signal);
47386
+ let next = steps.next();
47387
+ while (!next.done) {
47388
+ next = steps.next();
47389
+ }
47390
+ return next.value;
47167
47391
  }
47168
47392
  var POPPLER_FILE_TOOL_VALUE_FLAGS = /* @__PURE__ */ new Set([
47169
47393
  "-r",
@@ -47213,6 +47437,7 @@ function extractPopplerFileToolPositionals(argv) {
47213
47437
  return pos;
47214
47438
  }
47215
47439
  async function executePopplerFileTool(context, runner) {
47440
+ let cooperativeWork = 63;
47216
47441
  const invocation = createOutputOperation(context, { write: async () => {
47217
47442
  } });
47218
47443
  try {
@@ -47232,6 +47457,7 @@ async function executePopplerFileTool(context, runner) {
47232
47457
  const chunks = [];
47233
47458
  let total = 0;
47234
47459
  for await (const chunk of readBytes(context.stdin, invocation.signal)) {
47460
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
47235
47461
  chunks.push(chunk);
47236
47462
  total += chunk.byteLength;
47237
47463
  chargeBytes(chunk.byteLength);
@@ -47240,6 +47466,7 @@ async function executePopplerFileTool(context, runner) {
47240
47466
  const buf = new Uint8Array(total);
47241
47467
  let off = 0;
47242
47468
  for (const c of chunks) {
47469
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
47243
47470
  buf.set(c, off);
47244
47471
  off += c.byteLength;
47245
47472
  }
@@ -47247,6 +47474,7 @@ async function executePopplerFileTool(context, runner) {
47247
47474
  }
47248
47475
  }
47249
47476
  for (const token of positionals) {
47477
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
47250
47478
  if (token === "-") continue;
47251
47479
  try {
47252
47480
  const bytes = await context.fs.readFile(resolveVfsPath(token), { signal: invocation.signal });
@@ -47255,8 +47483,9 @@ async function executePopplerFileTool(context, runner) {
47255
47483
  } catch {
47256
47484
  }
47257
47485
  }
47486
+ context.inputBudget?.check(0);
47258
47487
  const existingSnap = new Map(vfsFiles);
47259
- const res = await runner(argv, vfsFiles);
47488
+ const res = await runner(argv, vfsFiles, invocation.signal);
47260
47489
  if (res.stderr) {
47261
47490
  await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
47262
47491
  }
@@ -47271,6 +47500,7 @@ async function executePopplerFileTool(context, runner) {
47271
47500
  await writeBytes(stdout.output, outBytes, invocation.signal);
47272
47501
  }
47273
47502
  for (const [key, val] of vfsFiles.entries()) {
47503
+ if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
47274
47504
  if (key !== "-" && existingSnap.get(key) !== val) {
47275
47505
  chargeBytes(val.byteLength);
47276
47506
  const abs = resolveVfsPath(key);
@@ -47287,73 +47517,92 @@ async function executePopplerFileTool(context, runner) {
47287
47517
  await invocation.close();
47288
47518
  }
47289
47519
  }
47290
- function createPdftoppmCommand(_options = {}) {
47520
+ function createPdftoppmCommand(options = {}) {
47521
+ const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
47291
47522
  return Object.freeze({
47292
47523
  name: "pdftoppm",
47293
47524
  runtimeIdentity: commandRuntimeIdentity,
47294
47525
  description: "Render PDF pages to PNG, PPM, PGM, or PBM images via @poe-code/pdf-ast",
47295
47526
  execute(context) {
47296
- return executePopplerFileTool(context, runPdftoppmCli);
47527
+ return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
47528
+ return executePopplerFileTool(context2, runPdftoppmCli);
47529
+ });
47297
47530
  }
47298
47531
  });
47299
47532
  }
47300
47533
  var pdftoppmCommand = createPdftoppmCommand();
47301
- function createPdfimagesCommand(_options = {}) {
47534
+ function createPdfimagesCommand(options = {}) {
47535
+ const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
47302
47536
  return Object.freeze({
47303
47537
  name: "pdfimages",
47304
47538
  runtimeIdentity: commandRuntimeIdentity,
47305
47539
  description: "List and extract embedded images from PDF pages via @poe-code/pdf-ast",
47306
47540
  execute(context) {
47307
- return executePopplerFileTool(context, runPdfimagesCli);
47541
+ return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
47542
+ return executePopplerFileTool(context2, runPdfimagesCli);
47543
+ });
47308
47544
  }
47309
47545
  });
47310
47546
  }
47311
47547
  var pdfimagesCommand = createPdfimagesCommand();
47312
- function createPdfuniteCommand(_options = {}) {
47548
+ function createPdfuniteCommand(options = {}) {
47549
+ const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
47313
47550
  return Object.freeze({
47314
47551
  name: "pdfunite",
47315
47552
  runtimeIdentity: commandRuntimeIdentity,
47316
47553
  description: "Merge multiple PDF documents into a single PDF via @poe-code/pdf-ast",
47317
47554
  execute(context) {
47318
- return executePopplerFileTool(context, runPdfuniteCli);
47555
+ return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
47556
+ return executePopplerFileTool(context2, runPdfuniteCli);
47557
+ });
47319
47558
  }
47320
47559
  });
47321
47560
  }
47322
47561
  var pdfuniteCommand = createPdfuniteCommand();
47323
- function createPdfseparateCommand(_options = {}) {
47562
+ function createPdfseparateCommand(options = {}) {
47563
+ const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
47324
47564
  return Object.freeze({
47325
47565
  name: "pdfseparate",
47326
47566
  runtimeIdentity: commandRuntimeIdentity,
47327
47567
  description: "Split PDF pages into individual PDF files via @poe-code/pdf-ast",
47328
47568
  execute(context) {
47329
- return executePopplerFileTool(context, runPdfseparateCli);
47569
+ return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
47570
+ return executePopplerFileTool(context2, runPdfseparateCli);
47571
+ });
47330
47572
  }
47331
47573
  });
47332
47574
  }
47333
47575
  var pdfseparateCommand = createPdfseparateCommand();
47334
- function createPdffontsCommand(_options = {}) {
47576
+ function createPdffontsCommand(options = {}) {
47577
+ const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
47335
47578
  return Object.freeze({
47336
47579
  name: "pdffonts",
47337
47580
  runtimeIdentity: commandRuntimeIdentity,
47338
47581
  description: "List fonts used in a PDF document via @poe-code/pdf-ast",
47339
47582
  execute(context) {
47340
- return executePopplerFileTool(context, runPdffontsCli);
47583
+ return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
47584
+ return executePopplerFileTool(context2, runPdffontsCli);
47585
+ });
47341
47586
  }
47342
47587
  });
47343
47588
  }
47344
47589
  var pdffontsCommand = createPdffontsCommand();
47345
- function createPdfdetachCommand(_options = {}) {
47590
+ function createPdfdetachCommand(options = {}) {
47591
+ const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
47346
47592
  return Object.freeze({
47347
47593
  name: "pdfdetach",
47348
47594
  runtimeIdentity: commandRuntimeIdentity,
47349
47595
  description: "List and extract embedded file attachments from PDF documents via @poe-code/pdf-ast",
47350
47596
  execute(context) {
47351
- return executePopplerFileTool(context, runPdfdetachCli);
47597
+ return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
47598
+ return executePopplerFileTool(context2, runPdfdetachCli);
47599
+ });
47352
47600
  }
47353
47601
  });
47354
47602
  }
47355
47603
  var pdfdetachCommand = createPdfdetachCommand();
47356
- async function runPdftocairoCli(argv, files) {
47604
+ function* runPdftocairoCliSteps(argv, files, signal) {
47605
+ let cooperativeWork = 63;
47357
47606
  let format = "png";
47358
47607
  let grayMode = false;
47359
47608
  let monoMode = false;
@@ -47371,6 +47620,8 @@ async function runPdftocairoCli(argv, files) {
47371
47620
  const forwardedArgs = [];
47372
47621
  const positionals = [];
47373
47622
  for (let i = 0; i < argv.length; i++) {
47623
+ if (++cooperativeWork % 64 === 0)
47624
+ yield;
47374
47625
  const arg = argv[i];
47375
47626
  if (arg === "-v" || arg === "--version") {
47376
47627
  return { exitCode: 0, stdout: "pdftocairo version 24.08.0\n", stderr: "" };
@@ -47391,12 +47642,18 @@ async function runPdftocairoCli(argv, files) {
47391
47642
  } else if (arg === "-tiff") {
47392
47643
  format = "tif";
47393
47644
  forwardedArgs.push("-tiff");
47394
- } else if (arg === "-svg") format = "svg";
47395
- else if (arg === "-pdf") format = "pdf";
47396
- else if (arg === "-ps") format = "ps";
47397
- else if (arg === "-eps") format = "eps";
47398
- else if (arg === "-gray") grayMode = true;
47399
- else if (arg === "-mono") monoMode = true;
47645
+ } else if (arg === "-svg")
47646
+ format = "svg";
47647
+ else if (arg === "-pdf")
47648
+ format = "pdf";
47649
+ else if (arg === "-ps")
47650
+ format = "ps";
47651
+ else if (arg === "-eps")
47652
+ format = "eps";
47653
+ else if (arg === "-gray")
47654
+ grayMode = true;
47655
+ else if (arg === "-mono")
47656
+ monoMode = true;
47400
47657
  else if (arg === "-antialias") {
47401
47658
  const m = (argv[++i] ?? "").toLowerCase();
47402
47659
  if (!["default", "none", "gray", "subpixel", "fast", "good", "best"].includes(m)) {
@@ -47405,8 +47662,10 @@ async function runPdftocairoCli(argv, files) {
47405
47662
  } else if (POPPLER_FILE_TOOL_VALUE_FLAGS.has(arg)) {
47406
47663
  const v = argv[++i] ?? "";
47407
47664
  forwardedArgs.push(arg, v);
47408
- if (arg === "-f") firstPage = Math.max(1, Number.parseInt(v, 10) || 1);
47409
- else if (arg === "-l") lastPage = Math.max(0, Number.parseInt(v, 10) || 0);
47665
+ if (arg === "-f")
47666
+ firstPage = Math.max(1, Number.parseInt(v, 10) || 1);
47667
+ else if (arg === "-l")
47668
+ lastPage = Math.max(0, Number.parseInt(v, 10) || 0);
47410
47669
  else if (arg === "-x") {
47411
47670
  cropX = Math.max(0, Number.parseInt(v, 10) || 0);
47412
47671
  hasCrop = true;
@@ -47419,7 +47678,8 @@ async function runPdftocairoCli(argv, files) {
47419
47678
  } else if (arg === "-H") {
47420
47679
  cropH = Math.max(0, Number.parseInt(v, 10) || 0);
47421
47680
  hasCrop = true;
47422
- } else if (arg === "-upw" || arg === "-opw") password = v;
47681
+ } else if (arg === "-upw" || arg === "-opw")
47682
+ password = v;
47423
47683
  } else if (arg.startsWith("-") && arg !== "-") {
47424
47684
  forwardedArgs.push(arg);
47425
47685
  } else {
@@ -47434,11 +47694,12 @@ async function runPdftocairoCli(argv, files) {
47434
47694
  if (format === "svg") {
47435
47695
  const rawOut = positionals[1] ?? (inputPath === "-" ? "-" : `${inputStem}.svg`);
47436
47696
  const rootForSvg = rawOut.toLowerCase().endsWith(".svg") ? rawOut.slice(0, -4) : rawOut;
47437
- return runPdftoppmCli(["-svg", "-singlefile", ...forwardedArgs, inputPath, rootForSvg], files);
47697
+ return yield* runPdftoppmCliSteps(["-svg", "-singlefile", ...forwardedArgs, inputPath, rootForSvg], files, signal);
47438
47698
  }
47439
47699
  if (format === "pdf" || format === "ps" || format === "eps") {
47440
47700
  const pdfBytes = files.get(inputPath);
47441
- if (!pdfBytes) return { exitCode: 1, stdout: "", stderr: `I/O Error: Couldn't open file '${inputPath}'
47701
+ if (!pdfBytes)
47702
+ return { exitCode: 1, stdout: "", stderr: `I/O Error: Couldn't open file '${inputPath}'
47442
47703
  ` };
47443
47704
  const doc = PdfDocument.load(pdfBytes, password ? { password } : void 0);
47444
47705
  const endPage = lastPage > 0 ? Math.min(doc.pageCount, lastPage) : doc.pageCount;
@@ -47450,6 +47711,7 @@ async function runPdftocairoCli(argv, files) {
47450
47711
  if (format === "pdf") {
47451
47712
  const outDoc = PdfDocument.create();
47452
47713
  for (let p = firstPage; p <= endPage; p++) {
47714
+ yield;
47453
47715
  const [copied] = outDoc.copyPagesFrom(doc, [p - 1]);
47454
47716
  if (copied && hasCrop) {
47455
47717
  const origSize = copied.getSize();
@@ -47460,7 +47722,8 @@ async function runPdftocairoCli(argv, files) {
47460
47722
  }
47461
47723
  }
47462
47724
  const outBytes = outDoc.save();
47463
- if (finalOut === "-") return { exitCode: 0, stdout: "", stderr: "", stdoutBytes: outBytes };
47725
+ if (finalOut === "-")
47726
+ return { exitCode: 0, stdout: "", stderr: "", stdoutBytes: outBytes };
47464
47727
  files.set(finalOut, outBytes);
47465
47728
  return { exitCode: 0, stdout: "", stderr: "" };
47466
47729
  }
@@ -47472,10 +47735,14 @@ async function runPdftocairoCli(argv, files) {
47472
47735
  "%%EndComments"
47473
47736
  ];
47474
47737
  for (let p = firstPage; p <= endPage; p++) {
47738
+ yield;
47475
47739
  const page = doc.getPage(p - 1);
47476
47740
  psLines.push(`%%Page: ${p - firstPage + 1} ${p - firstPage + 1}`);
47477
47741
  for (const b of page.extractPage().blocks) {
47742
+ yield;
47478
47743
  for (const l of b.lines) {
47744
+ if (++cooperativeWork % 64 === 0)
47745
+ yield;
47479
47746
  psLines.push(`${Math.round(l.bbox[0])} ${Math.round(l.bbox[1])} moveto (${l.text}) show`);
47480
47747
  }
47481
47748
  }
@@ -47483,13 +47750,14 @@ async function runPdftocairoCli(argv, files) {
47483
47750
  }
47484
47751
  psLines.push("%%Trailer", "%%EOF", "");
47485
47752
  const psBytes = new TextEncoder().encode(psLines.join("\n"));
47486
- if (finalOut === "-") return { exitCode: 0, stdout: "", stderr: "", stdoutBytes: psBytes };
47753
+ if (finalOut === "-")
47754
+ return { exitCode: 0, stdout: "", stderr: "", stdoutBytes: psBytes };
47487
47755
  files.set(finalOut, psBytes);
47488
47756
  return { exitCode: 0, stdout: "", stderr: "" };
47489
47757
  }
47490
47758
  const rasterPositionals = positionals.length === 1 && inputPath !== "-" ? [inputPath, inputStem] : positionals;
47491
47759
  const snapBefore = new Map(files);
47492
- const res = await runPdftoppmCli([...forwardedArgs, ...rasterPositionals], files);
47760
+ const res = yield* runPdftoppmCliSteps([...forwardedArgs, ...rasterPositionals], files, signal);
47493
47761
  if (res.exitCode !== 0 || !grayMode && !monoMode) {
47494
47762
  return res;
47495
47763
  }
@@ -47508,6 +47776,8 @@ async function runPdftocairoCli(argv, files) {
47508
47776
  return { ...res, stdoutBytes: encodePng(decoded) };
47509
47777
  }
47510
47778
  for (const [k, v] of files.entries()) {
47779
+ if (++cooperativeWork % 64 === 0)
47780
+ yield;
47511
47781
  if (snapBefore.get(k) !== v && k.endsWith(".png")) {
47512
47782
  const decoded = decodePng(v);
47513
47783
  convertRgbaInPlace(decoded.data);
@@ -47516,13 +47786,19 @@ async function runPdftocairoCli(argv, files) {
47516
47786
  }
47517
47787
  return res;
47518
47788
  }
47519
- function createPdftocairoCommand(_options = {}) {
47789
+ async function runPdftocairoCli(argv, files, signal) {
47790
+ return drainSteps(runPdftocairoCliSteps(argv, files, signal), signal);
47791
+ }
47792
+ function createPdftocairoCommand(options = {}) {
47793
+ const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
47520
47794
  return Object.freeze({
47521
47795
  name: "pdftocairo",
47522
47796
  runtimeIdentity: commandRuntimeIdentity,
47523
47797
  description: "Render PDF pages to PNG, JPEG, TIFF, PDF, PS, EPS, or SVG via @poe-code/pdf-ast",
47524
47798
  execute(context) {
47525
- return executePopplerFileTool(context, runPdftocairoCli);
47799
+ return new InputByteBudget(maxInputBytes).run(context, async (context2) => {
47800
+ return executePopplerFileTool(context2, runPdftocairoCli);
47801
+ });
47526
47802
  }
47527
47803
  });
47528
47804
  }