@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
@@ -27418,6 +27418,13 @@ function tokenizeCos(bytes, start = 0, end = bytes.length) {
27418
27418
  return tokens;
27419
27419
  }
27420
27420
 
27421
+ // src/work.ts
27422
+ function drainWork(work) {
27423
+ let step = work.next();
27424
+ while (!step.done) step = work.next();
27425
+ return step.value;
27426
+ }
27427
+
27421
27428
  // src/bytes.ts
27422
27429
  function bytesToString3(bytes) {
27423
27430
  if (typeof bytes !== "object" || bytes?.length === void 0) {
@@ -28020,7 +28027,9 @@ function concatByteArrays(chunks) {
28020
28027
  }
28021
28028
  return out;
28022
28029
  }
28023
- function serializeCosDocument(options) {
28030
+ function* serializeCosDocumentSteps(options) {
28031
+ yield;
28032
+ let work = 0;
28024
28033
  const maxOutputBytes = options.maxOutputBytes ?? Infinity;
28025
28034
  const maxObjects = options.maxObjects ?? Infinity;
28026
28035
  const sorted = [...options.objects].sort((a, b) => a.objectNumber - b.objectNumber);
@@ -28043,6 +28052,7 @@ function serializeCosDocument(options) {
28043
28052
  const packable = [];
28044
28053
  const direct = [];
28045
28054
  for (const obj of sorted) {
28055
+ if (++work % 16 === 0) yield;
28046
28056
  const isLinearized = obj.value.kind === "dict" && dictGet(obj.value, "Linearized") !== void 0;
28047
28057
  if (obj.value.kind !== "stream" && obj.generationNumber === 0 && !isLinearized) {
28048
28058
  packable.push(obj);
@@ -28057,6 +28067,7 @@ function serializeCosDocument(options) {
28057
28067
  const headerPairs = [];
28058
28068
  let relOffset = 0;
28059
28069
  for (const pObj of packable) {
28070
+ if (++work % 16 === 0) yield;
28060
28071
  headerPairs.push(`${pObj.objectNumber} ${relOffset}`);
28061
28072
  const bBytes = serializeCosNodeBytes(pObj.value);
28062
28073
  const nl = textEncoder2.encode("\n");
@@ -28082,6 +28093,7 @@ function serializeCosDocument(options) {
28082
28093
  ];
28083
28094
  const directOffsets = /* @__PURE__ */ new Map();
28084
28095
  for (const dObj of allDirect) {
28096
+ if (++work % 16 === 0) yield;
28085
28097
  directOffsets.set(dObj.objectNumber, { offset, generation: dObj.generationNumber });
28086
28098
  const prefix = textEncoder2.encode(`${dObj.objectNumber} ${dObj.generationNumber} obj
28087
28099
  `);
@@ -28092,6 +28104,7 @@ function serializeCosDocument(options) {
28092
28104
  }
28093
28105
  const compressedMap = /* @__PURE__ */ new Map();
28094
28106
  for (let idx = 0; idx < packable.length; idx++) {
28107
+ if (++work % 16 === 0) yield;
28095
28108
  compressedMap.set(packable[idx].objectNumber, idx);
28096
28109
  }
28097
28110
  const xrefOffset2 = offset;
@@ -28109,6 +28122,7 @@ function serializeCosDocument(options) {
28109
28122
  };
28110
28123
  writeEntry7(0, 0, 0, 65535);
28111
28124
  for (let i = 1; i < size2; i++) {
28125
+ if (++work % 16 === 0) yield;
28112
28126
  if (i === xrefStmNum) {
28113
28127
  writeEntry7(i, 1, xrefOffset2, 0);
28114
28128
  } else if (compressedMap.has(i)) {
@@ -28189,6 +28203,7 @@ ${xrefOffset2}
28189
28203
  let pageCount = 0;
28190
28204
  let firstPageObjNum = options.rootRef.objectNumber;
28191
28205
  for (const o of sorted) {
28206
+ if (++work % 16 === 0) yield;
28192
28207
  if (o.value.kind === "dict") {
28193
28208
  const t = dictGet(o.value, "Type");
28194
28209
  if (t?.kind === "name" && t.decoded === "Page") {
@@ -28236,6 +28251,7 @@ ${xrefOffset2}
28236
28251
  }
28237
28252
  const objectOffsets = /* @__PURE__ */ new Map();
28238
28253
  for (const obj of sorted) {
28254
+ if (++work % 16 === 0) yield;
28239
28255
  objectOffsets.set(obj.objectNumber, { offset, generation: obj.generationNumber });
28240
28256
  let value = obj.value;
28241
28257
  if (options.normalizeContent && value.kind === "stream" && value.decodedBytes) {
@@ -28267,6 +28283,7 @@ ${xrefOffset2}
28267
28283
  0000000000 65535 f
28268
28284
  `;
28269
28285
  for (let i = 1; i < size; i++) {
28286
+ if (++work % 16 === 0) yield;
28270
28287
  const entry = objectOffsets.get(i);
28271
28288
  if (entry) {
28272
28289
  xrefText += `${String(entry.offset).padStart(10, "0")} ${String(entry.generation).padStart(5, "0")} n
@@ -28313,6 +28330,7 @@ ${xrefOffset}
28313
28330
  let endFirstPage = xrefOffset;
28314
28331
  const sortedOffsets = [...objectOffsets.entries()].sort((a, b) => a[1].offset - b[1].offset);
28315
28332
  for (let i = 0; i < sortedOffsets.length; i++) {
28333
+ if (++work % 16 === 0) yield;
28316
28334
  const [objNum, info3] = sortedOffsets[i];
28317
28335
  const nextOff = sortedOffsets[i + 1]?.[1].offset ?? xrefOffset;
28318
28336
  if (objNum === hintObjAfter.objectNumber) {
@@ -28346,6 +28364,9 @@ ${xrefOffset}
28346
28364
  }
28347
28365
  return fullBytes;
28348
28366
  }
28367
+ function serializeCosDocument(options) {
28368
+ return drainWork(serializeCosDocumentSteps(options));
28369
+ }
28349
28370
  function appendIncrementalRevision(originalBytes, doc, updatedObjects) {
28350
28371
  const chunks = [originalBytes, textEncoder2.encode("\n")];
28351
28372
  let offset = originalBytes.length + 1;
@@ -28621,48 +28642,30 @@ function encryptPdfBuffer(state, objectNumber, generationNumber, plaintext) {
28621
28642
  const objKey = md5Bytes([state.fileKey, suffix]).subarray(0, Math.min(16, state.fileKey.length + 5));
28622
28643
  return rc4Transform(objKey, plaintext);
28623
28644
  }
28624
- function transformNodeStringsAndStreams(node, transform, transformStream) {
28645
+ function* transformNodeStringsAndStreamsSteps(node, transform, transformStream) {
28646
+ yield;
28625
28647
  switch (node.kind) {
28626
28648
  case "string":
28627
- return {
28628
- kind: "string",
28629
- format: "hex",
28630
- bytes: transform(node.bytes)
28631
- };
28632
- case "array":
28633
- return {
28634
- kind: "array",
28635
- items: node.items.map((item) => transformNodeStringsAndStreams(item, transform, transformStream))
28636
- };
28649
+ return { kind: "string", format: "hex", bytes: transform(node.bytes) };
28650
+ case "array": {
28651
+ const items = [];
28652
+ for (const item of node.items) items.push(yield* transformNodeStringsAndStreamsSteps(item, transform, transformStream));
28653
+ return { kind: "array", items };
28654
+ }
28637
28655
  case "dict": {
28638
- const type = dictGet(node, "Type");
28639
- const fieldType = dictGet(node, "FT");
28640
- const byteRange = dictGet(node, "ByteRange");
28656
+ const type = dictGet(node, "Type"), fieldType = dictGet(node, "FT"), byteRange = dictGet(node, "ByteRange");
28641
28657
  const signature = type?.kind === "name" && type.decoded === "Sig" || fieldType?.kind === "name" && fieldType.decoded === "Sig" || byteRange?.kind === "array" && dictGet(node, "Filter")?.kind === "name";
28642
- return {
28643
- kind: "dict",
28644
- entries: node.entries.map((e) => ({
28645
- key: e.key,
28646
- value: signature && e.key.decoded === "Contents" ? e.value : transformNodeStringsAndStreams(e.value, transform, transformStream)
28647
- }))
28648
- };
28658
+ const entries = [];
28659
+ 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) });
28660
+ return { kind: "dict", entries };
28649
28661
  }
28650
28662
  case "stream": {
28651
28663
  const type = dictGet(node.dict, "Type");
28652
28664
  if (type?.kind === "name" && type.decoded === "XRef") return node;
28653
28665
  const stream = transformStream ? transformStream(node) : { ...node, rawBytes: transform(node.rawBytes) };
28654
- const updatedDict = {
28655
- kind: "dict",
28656
- entries: stream.dict.entries.map((e) => ({
28657
- key: e.key,
28658
- value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : transformNodeStringsAndStreams(e.value, transform, transformStream)
28659
- }))
28660
- };
28661
- return {
28662
- kind: "stream",
28663
- dict: updatedDict,
28664
- rawBytes: stream.rawBytes
28665
- };
28666
+ const entries = [];
28667
+ 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) });
28668
+ return { kind: "stream", dict: { kind: "dict", entries }, rawBytes: stream.rawBytes };
28666
28669
  }
28667
28670
  default:
28668
28671
  return node;
@@ -28731,7 +28734,8 @@ function createR6Encryption(userPassword, ownerPassword, pMask) {
28731
28734
  StrF: cosName("StdCF")
28732
28735
  }) };
28733
28736
  }
28734
- function encryptCosDocument(doc, options = {}) {
28737
+ function* encryptCosDocumentSteps(doc, options = {}) {
28738
+ yield;
28735
28739
  const userPassword = options.userPassword ?? "";
28736
28740
  const ownerPassword = options.ownerPassword ?? userPassword;
28737
28741
  const revision = options.revision ?? 6;
@@ -28753,14 +28757,15 @@ function encryptCosDocument(doc, options = {}) {
28753
28757
  const encryptObjNum = maxObjNum + 1;
28754
28758
  const encryptedObjects = [];
28755
28759
  for (const obj of doc.objects.values()) {
28756
- const transformed = transformNodeStringsAndStreams(
28760
+ yield;
28761
+ const transformed = yield* transformNodeStringsAndStreamsSteps(
28757
28762
  obj.value,
28758
28763
  (plain) => encryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, plain)
28759
28764
  );
28760
28765
  encryptedObjects.push({ objectNumber: obj.objectNumber, generationNumber: obj.generationNumber, value: transformed });
28761
28766
  }
28762
28767
  encryptedObjects.push({ objectNumber: encryptObjNum, generationNumber: 0, value: encryptDict });
28763
- return serializeCosDocument({
28768
+ return yield* serializeCosDocumentSteps({
28764
28769
  objects: encryptedObjects,
28765
28770
  rootRef: doc.rootRef,
28766
28771
  infoRef: doc.infoRef,
@@ -28769,6 +28774,9 @@ function encryptCosDocument(doc, options = {}) {
28769
28774
  version: revision === 6 ? "2.0" : Number.parseFloat(doc.version) < 1.4 ? "1.4" : doc.version
28770
28775
  });
28771
28776
  }
28777
+ function encryptCosDocument(doc, options = {}) {
28778
+ return drainWork(encryptCosDocumentSteps(doc, options));
28779
+ }
28772
28780
  function decryptStream(doc, stream, transform) {
28773
28781
  const type = doc.resolve(dictGet(stream.dict, "Type"));
28774
28782
  const decrypt2 = (bytes2, cryptName) => {
@@ -28810,17 +28818,19 @@ function decryptStream(doc, stream, transform) {
28810
28818
  }
28811
28819
  return { kind: "stream", dict, rawBytes: bytes };
28812
28820
  }
28813
- function decryptCosDocument(doc, state) {
28821
+ function* decryptCosDocumentSteps(doc, state) {
28822
+ yield;
28814
28823
  const encryptObjNum = doc.encryptRef?.objectNumber;
28815
28824
  const handler = securityHandlers.get(state);
28816
28825
  for (const [num, obj] of doc.objects.entries()) {
28826
+ yield;
28817
28827
  if (num === encryptObjNum || handler?.plaintextObjects.has(num)) continue;
28818
28828
  if (obj.value.kind === "stream") {
28819
28829
  const type = doc.resolve(dictGet(obj.value.dict, "Type"));
28820
28830
  if (type?.kind === "name" && (type.decoded === "XRef" || type.decoded === "Metadata" && !state.encryptMetadata)) continue;
28821
28831
  }
28822
28832
  const transform = handler?.factory.createCipherTransform(obj.objectNumber, obj.generationNumber);
28823
- const decrypted = transformNodeStringsAndStreams(
28833
+ const decrypted = yield* transformNodeStringsAndStreamsSteps(
28824
28834
  obj.value,
28825
28835
  (cipher) => decryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, cipher),
28826
28836
  transform ? (stream) => decryptStream(doc, stream, transform) : void 0
@@ -28828,6 +28838,9 @@ function decryptCosDocument(doc, state) {
28828
28838
  doc.objects.set(num, { objectNumber: obj.objectNumber, generationNumber: obj.generationNumber, value: decrypted, span: obj.span });
28829
28839
  }
28830
28840
  }
28841
+ function decryptCosDocument(doc, state) {
28842
+ return drainWork(decryptCosDocumentSteps(doc, state));
28843
+ }
28831
28844
  var authenticateStandardEncryption = derivePdfEncryptionKey;
28832
28845
 
28833
28846
  // src/cos/parser.ts
@@ -28936,9 +28949,12 @@ var ParsedCosDocument = class {
28936
28949
  return void 0;
28937
28950
  }
28938
28951
  };
28939
- function parseNodeFromLexer(lexer, bytes, maxDepth, repair = false) {
28952
+ function* parseNodeFromLexerSteps(lexer, bytes, maxDepth, repair = false) {
28953
+ yield;
28954
+ let work = 0;
28940
28955
  const stack = [];
28941
28956
  while (true) {
28957
+ if (++work % 16 === 0) yield;
28942
28958
  const tok = lexer.nextToken();
28943
28959
  const parent = stack.at(-1);
28944
28960
  if (!tok) {
@@ -29134,7 +29150,8 @@ function parseHeaderVersion(bytes) {
29134
29150
  }
29135
29151
  return head.slice(idx + 5, idx + 8);
29136
29152
  }
29137
- function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
29153
+ function* parseObjectAtOffsetSteps(bytes, offset, maxRecursionDepth, repair = false) {
29154
+ yield;
29138
29155
  const lexer = new CosByteLexer(bytes, offset);
29139
29156
  const objNumTok = lexer.nextToken();
29140
29157
  const genNumTok = lexer.nextToken();
@@ -29142,7 +29159,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
29142
29159
  if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
29143
29160
  throw new PdfError("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
29144
29161
  }
29145
- const value = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, repair);
29162
+ const value = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, repair);
29146
29163
  if (!value) {
29147
29164
  throw new PdfError("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
29148
29165
  }
@@ -29153,7 +29170,9 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
29153
29170
  span: { start: objNumTok.span.start, end: lexer.offset }
29154
29171
  };
29155
29172
  }
29156
- function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
29173
+ function* parseXrefRevisionAtSteps(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
29174
+ yield;
29175
+ let work = 0;
29157
29176
  if (xrefOffset < 0 || xrefOffset >= bytes.length) {
29158
29177
  throw new PdfError("E_PARSE", `Invalid xref offset: ${xrefOffset}`);
29159
29178
  }
@@ -29165,6 +29184,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29165
29184
  if (firstTok.kind === "keyword" && firstTok.value === "xref") {
29166
29185
  const entries2 = /* @__PURE__ */ new Map();
29167
29186
  while (true) {
29187
+ if (++work % 16 === 0) yield;
29168
29188
  const saved = lexer.offset;
29169
29189
  const tok = lexer.nextToken();
29170
29190
  if (!tok) {
@@ -29188,6 +29208,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29188
29208
  }
29189
29209
  if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
29190
29210
  for (let i = 0; i < count; i++) {
29211
+ if (++work % 16 === 0) yield;
29191
29212
  const offTok = lexer.nextToken();
29192
29213
  const genTok = lexer.nextToken();
29193
29214
  const flagTok = lexer.nextToken();
@@ -29213,7 +29234,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29213
29234
  if (entries2.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
29214
29235
  }
29215
29236
  }
29216
- const trailerNode = parseNodeFromLexer(lexer, bytes, maxRecursionDepth);
29237
+ const trailerNode = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth);
29217
29238
  if (!trailerNode || trailerNode.kind !== "dict") {
29218
29239
  throw new PdfError("E_PARSE", "Missing trailer dictionary after xref table");
29219
29240
  }
@@ -29225,7 +29246,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29225
29246
  previousXrefOffset: prevNode2?.kind === "number" ? prevNode2.value : void 0
29226
29247
  };
29227
29248
  }
29228
- const xrefObj = parseObjectAtOffset(bytes, xrefOffset, maxRecursionDepth);
29249
+ const xrefObj = yield* parseObjectAtOffsetSteps(bytes, xrefOffset, maxRecursionDepth);
29229
29250
  if (xrefObj.value.kind !== "stream") {
29230
29251
  throw new PdfError("E_PARSE", `Expected xref table or XRef stream at offset ${xrefOffset}`);
29231
29252
  }
@@ -29246,6 +29267,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29246
29267
  if (indexArray) {
29247
29268
  if (indexArray.kind !== "array" || indexArray.items.length % 2 !== 0) throw new PdfError("E_PARSE", "Invalid XRef range fields");
29248
29269
  for (let i = 0; i < indexArray.items.length; i += 2) {
29270
+ if (++work % 16 === 0) yield;
29249
29271
  const first = indexArray.items[i];
29250
29272
  const count = indexArray.items[i + 1];
29251
29273
  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)) {
@@ -29268,9 +29290,11 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
29268
29290
  return v;
29269
29291
  };
29270
29292
  for (const [startObj, count] of subsections) {
29293
+ if (++work % 16 === 0) yield;
29271
29294
  if (count > (decoded.length - pos) / stride) throw new PdfError("E_PARSE", "Truncated XRef stream");
29272
29295
  if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
29273
29296
  for (let i = 0; i < count; i++) {
29297
+ if (++work % 16 === 0) yield;
29274
29298
  const objNum = startObj + i;
29275
29299
  const field0 = w0 > 0 ? readInt(w0) : 1;
29276
29300
  const field1 = readInt(w1);
@@ -29316,12 +29340,16 @@ function isAsciiWhitespace(ch3) {
29316
29340
  function isAsciiDigit(ch3) {
29317
29341
  return ch3 >= 48 && ch3 <= 57;
29318
29342
  }
29319
- function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29343
+ function* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth) {
29344
+ yield;
29345
+ let work = 0;
29320
29346
  const objects = /* @__PURE__ */ new Map();
29321
29347
  const trailers = [];
29322
29348
  let pos = 0;
29323
29349
  while (pos < bytes.length) {
29350
+ if (++work % 16 === 0) yield;
29324
29351
  while (pos < bytes.length && !isAsciiDigit(bytes[pos])) {
29352
+ if (++work % 16 === 0) yield;
29325
29353
  if (bytes[pos] === 37) {
29326
29354
  while (pos < bytes.length && bytes[pos] !== 10 && bytes[pos] !== 13) pos++;
29327
29355
  continue;
@@ -29331,7 +29359,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29331
29359
  try {
29332
29360
  const token = lexer.nextToken();
29333
29361
  if (token?.kind === "keyword" && token.value === "trailer") {
29334
- const trailer = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, true);
29362
+ const trailer = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, true);
29335
29363
  if (trailer?.kind === "dict") trailers.push(trailer);
29336
29364
  pos = lexer.offset;
29337
29365
  continue;
@@ -29364,7 +29392,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29364
29392
  bytes[pos + 3] === 40)) {
29365
29393
  pos += 3;
29366
29394
  try {
29367
- const parsed = parseObjectAtOffset(bytes, headerStart, maxRecursionDepth, true);
29395
+ const parsed = yield* parseObjectAtOffsetSteps(bytes, headerStart, maxRecursionDepth, true);
29368
29396
  objects.set(parsed.objectNumber, parsed);
29369
29397
  if (parsed.value.kind === "stream") {
29370
29398
  const type = dictGet(parsed.value.dict, "Type");
@@ -29381,13 +29409,17 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
29381
29409
  }
29382
29410
  return { objects, trailers };
29383
29411
  }
29384
- function unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
29412
+ function* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
29413
+ yield;
29414
+ let work = 0;
29385
29415
  for (const obj of [...objects.values()]) {
29416
+ if (++work % 16 === 0) yield;
29386
29417
  if (obj.value.kind === "stream") {
29387
29418
  const t = dictGet(obj.value.dict, "Type");
29388
29419
  if (t?.kind === "name" && t.decoded === "ObjStm") {
29389
29420
  try {
29390
- for (const [unpackedNum, unpackedVal] of unpackObjectStream(obj.value, maxDecompressedBytes, maxRecursionDepth, true).entries()) {
29421
+ for (const [unpackedNum, unpackedVal] of (yield* unpackObjectStreamSteps(obj.value, maxDecompressedBytes, maxRecursionDepth, true)).entries()) {
29422
+ if (++work % 16 === 0) yield;
29391
29423
  if (!objects.has(unpackedNum)) {
29392
29424
  objects.set(unpackedNum, {
29393
29425
  objectNumber: unpackedNum,
@@ -29423,7 +29455,9 @@ function recoveredReferences(objects) {
29423
29455
  }
29424
29456
  return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
29425
29457
  }
29426
- function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
29458
+ function* unpackObjectStreamSteps(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
29459
+ yield;
29460
+ let work = 0;
29427
29461
  const nNode = dictGet(streamObj.dict, "N");
29428
29462
  const firstNode = dictGet(streamObj.dict, "First");
29429
29463
  if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
@@ -29433,6 +29467,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29433
29467
  const headerLexer = new CosByteLexer(decoded, 0);
29434
29468
  const pairs = [];
29435
29469
  for (let i = 0; i < nNode.value; i++) {
29470
+ if (++work % 16 === 0) yield;
29436
29471
  const numTok = headerLexer.nextToken();
29437
29472
  const offTok = headerLexer.nextToken();
29438
29473
  if (numTok?.kind === "number" && offTok?.kind === "number") {
@@ -29441,9 +29476,10 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29441
29476
  }
29442
29477
  const result = /* @__PURE__ */ new Map();
29443
29478
  for (const pair of pairs) {
29479
+ if (++work % 16 === 0) yield;
29444
29480
  try {
29445
29481
  const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
29446
- const node = parseNodeFromLexer(valLexer, decoded, maxRecursionDepth, repair);
29482
+ const node = yield* parseNodeFromLexerSteps(valLexer, decoded, maxRecursionDepth, repair);
29447
29483
  if (node) {
29448
29484
  result.set(pair.objectNumber, node);
29449
29485
  }
@@ -29453,7 +29489,9 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
29453
29489
  }
29454
29490
  return result;
29455
29491
  }
29456
- function parseCosDocument(bytes, options = {}) {
29492
+ function* parseCosDocumentSteps(bytes, options = {}) {
29493
+ yield;
29494
+ let work = 0;
29457
29495
  const version = parseHeaderVersion(bytes);
29458
29496
  const recovery = options.recovery ?? "strict";
29459
29497
  const maxObjects = options.maxObjects ?? Infinity;
@@ -29488,10 +29526,12 @@ function parseCosDocument(bytes, options = {}) {
29488
29526
  let currentXrefOffset = offsetTok.value;
29489
29527
  const visitedOffsets = /* @__PURE__ */ new Set();
29490
29528
  while (currentXrefOffset !== void 0 && !visitedOffsets.has(currentXrefOffset)) {
29529
+ if (++work % 16 === 0) yield;
29491
29530
  visitedOffsets.add(currentXrefOffset);
29492
- const rev = parseXrefRevisionAt(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
29531
+ const rev = yield* parseXrefRevisionAtSteps(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
29493
29532
  revisions.push(rev);
29494
29533
  for (const [num, entry] of rev.entries.entries()) {
29534
+ if (++work % 16 === 0) yield;
29495
29535
  if (!mergedXref.has(num)) {
29496
29536
  mergedXref.set(num, entry);
29497
29537
  if (mergedXref.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
@@ -29524,8 +29564,9 @@ function parseCosDocument(bytes, options = {}) {
29524
29564
  if (!useRepair && rootRef) {
29525
29565
  try {
29526
29566
  for (const [objNum, entry] of mergedXref.entries()) {
29567
+ if (++work % 16 === 0) yield;
29527
29568
  if (entry.type !== "uncompressed") continue;
29528
- const parsed = parseObjectAtOffset(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
29569
+ const parsed = yield* parseObjectAtOffsetSteps(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
29529
29570
  if (parsed.objectNumber !== objNum || parsed.generationNumber !== (entry.generationNumber ?? 0)) {
29530
29571
  throw new PdfError("E_PARSE", `Bad uncompressed XRef entry for object ${objNum}`);
29531
29572
  }
@@ -29543,7 +29584,7 @@ function parseCosDocument(bytes, options = {}) {
29543
29584
  throw new PdfError("E_PARSE", "PDF trailer missing /Root reference");
29544
29585
  }
29545
29586
  useRepair = true;
29546
- const scanned = repairScanCosDocument(bytes, maxObjects, maxRecursionDepth);
29587
+ const scanned = yield* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth);
29547
29588
  objects = scanned.objects;
29548
29589
  revisions.length = 0;
29549
29590
  mergedXref.clear();
@@ -29578,7 +29619,7 @@ function parseCosDocument(bytes, options = {}) {
29578
29619
  encryptNode = encrypt?.kind === "ref" || encrypt?.kind === "dict" ? encrypt : void 0;
29579
29620
  encryptRef = encrypt?.kind === "ref" ? encrypt : void 0;
29580
29621
  idArray = id?.kind === "array" ? id : void 0;
29581
- if (!rootRef && !encryptNode) unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29622
+ if (!rootRef && !encryptNode) yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29582
29623
  const fallback = recoveredReferences(objects);
29583
29624
  rootRef ??= fallback.rootRef;
29584
29625
  infoRef ??= fallback.infoRef;
@@ -29613,20 +29654,21 @@ function parseCosDocument(bytes, options = {}) {
29613
29654
  maxRecursionDepth
29614
29655
  });
29615
29656
  doc.encryption = encState;
29616
- decryptCosDocument(doc, encState);
29657
+ yield* decryptCosDocumentSteps(doc, encState);
29617
29658
  }
29618
29659
  if (useRepair) {
29619
- unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29660
+ yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
29620
29661
  doc.infoRef ??= recoveredReferences(objects).infoRef;
29621
29662
  }
29622
29663
  const objStmCache = /* @__PURE__ */ new Map();
29623
29664
  for (const [objNum, entry] of mergedXref.entries()) {
29665
+ if (++work % 16 === 0) yield;
29624
29666
  if (entry.type === "compressed" && entry.objectStreamNumber !== void 0) {
29625
29667
  let unpacked = objStmCache.get(entry.objectStreamNumber);
29626
29668
  if (!unpacked) {
29627
29669
  const stmObj = objects.get(entry.objectStreamNumber)?.value;
29628
29670
  if (stmObj?.kind === "stream") {
29629
- unpacked = unpackObjectStream(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
29671
+ unpacked = yield* unpackObjectStreamSteps(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
29630
29672
  objStmCache.set(entry.objectStreamNumber, unpacked);
29631
29673
  }
29632
29674
  }
@@ -29643,6 +29685,9 @@ function parseCosDocument(bytes, options = {}) {
29643
29685
  }
29644
29686
  return doc;
29645
29687
  }
29688
+ function parseCosDocument(bytes, options = {}) {
29689
+ return drainWork(parseCosDocumentSteps(bytes, options));
29690
+ }
29646
29691
 
29647
29692
  // src/fonts/standard14.ts
29648
29693
  var WIN_ANSI_HIGH_BYTES = {
@@ -41069,7 +41114,8 @@ function resolveInheritedFieldEntry(doc, dict, key) {
41069
41114
  }
41070
41115
  return void 0;
41071
41116
  }
41072
- function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
41117
+ function* collectFieldDictsSteps(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen, yieldState = { work: 0 }) {
41118
+ if (++yieldState.work % 256 === 0) yield;
41073
41119
  const dict = doc.resolveDict(node);
41074
41120
  if (!dict) return out;
41075
41121
  const tNode = doc.resolve(dictGet(dict, "T"));
@@ -41102,7 +41148,8 @@ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", pare
41102
41148
  return out;
41103
41149
  }
41104
41150
  for (const kid of kidsArr.items) {
41105
- collectFieldDicts(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen);
41151
+ if (++yieldState.work % 16 === 0) yield;
41152
+ yield* collectFieldDictsSteps(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen, yieldState);
41106
41153
  }
41107
41154
  } else if (fullName) {
41108
41155
  out.push({
@@ -41531,7 +41578,9 @@ function setDocumentFormField(doc, fieldName, value) {
41531
41578
  const fieldRef = doc.allocateObject(newFieldDict);
41532
41579
  fieldsArr.items.push(fieldRef);
41533
41580
  }
41534
- function generateDocumentFormAppearances(doc) {
41581
+ function* generateDocumentFormAppearancesSteps(doc) {
41582
+ yield;
41583
+ let work = 0;
41535
41584
  const catalog = doc.resolveDict(doc.rootRef);
41536
41585
  if (!catalog) return;
41537
41586
  const acroForm = doc.resolveDict(dictGet(catalog, "AcroForm"));
@@ -41542,9 +41591,11 @@ function generateDocumentFormAppearances(doc) {
41542
41591
  if (fieldsArr) {
41543
41592
  const all = [];
41544
41593
  for (const item of fieldsArr.items) {
41545
- collectFieldDicts(doc, item, "", all);
41594
+ if (++work % 16 === 0) yield;
41595
+ yield* collectFieldDictsSteps(doc, item, "", all);
41546
41596
  }
41547
41597
  for (const entry of all) {
41598
+ if (++work % 16 === 0) yield;
41548
41599
  const ftNode = doc.resolve(dictGet(entry.dict, "FT"));
41549
41600
  const ft = entry.inheritedFt || (ftNode?.kind === "name" ? ftNode.decoded : "");
41550
41601
  const vNode = doc.resolve(dictGet(entry.dict, "V"));
@@ -41594,6 +41645,7 @@ function generateDocumentFormAppearances(doc) {
41594
41645
  const optArr = doc.resolveArray(dictGet(entry.dict, "Opt"));
41595
41646
  if (optArr) {
41596
41647
  for (const optItem of optArr.items) {
41648
+ if (++work % 16 === 0) yield;
41597
41649
  const resolvedOpt = doc.resolve(optItem);
41598
41650
  if (resolvedOpt?.kind === "array" && resolvedOpt.items.length >= 2) {
41599
41651
  const expNode = doc.resolve(resolvedOpt.items[0]);
@@ -41622,6 +41674,7 @@ function generateDocumentFormAppearances(doc) {
41622
41674
  const kidsArr = doc.resolveArray(dictGet(entry.dict, "Kids"));
41623
41675
  if (kidsArr) {
41624
41676
  for (const kid of kidsArr.items) {
41677
+ if (++work % 16 === 0) yield;
41625
41678
  const kidDict = doc.resolveDict(kid);
41626
41679
  if (kidDict && !dictGet(kidDict, "T")) {
41627
41680
  synthesizeTextAppearanceStream(
@@ -41641,6 +41694,9 @@ function generateDocumentFormAppearances(doc) {
41641
41694
  }
41642
41695
  dictSet(acroForm, "NeedAppearances", cosBool(false));
41643
41696
  }
41697
+ function generateDocumentFormAppearances(doc) {
41698
+ return drainWork(generateDocumentFormAppearancesSteps(doc));
41699
+ }
41644
41700
  function decodeXmlEntities(text) {
41645
41701
  let out = "";
41646
41702
  let i = 0;
@@ -42217,6 +42273,9 @@ q ${sx} 0 0 ${sy} ${tx} ${ty} cm /${appearanceName} Do Q
42217
42273
  dictSet(acroForm, "NeedAppearances", cosBool(false));
42218
42274
  }
42219
42275
  }
42276
+ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
42277
+ drainWork(collectFieldDictsSteps(doc, node, prefix, out, parentFt, parentFf, parentQ, parentMaxLen));
42278
+ }
42220
42279
 
42221
42280
  // src/canvas.ts
42222
42281
  function rgb(r, g, b) {
@@ -45317,14 +45376,18 @@ var PdfDocument = class _PdfDocument {
45317
45376
  });
45318
45377
  return new _PdfDocument(parseCosDocument(rawBytes));
45319
45378
  }
45320
- static load(bytes, options) {
45379
+ static *loadSteps(bytes, options) {
45380
+ yield;
45321
45381
  return new _PdfDocument(
45322
- parseCosDocument(bytes, {
45382
+ yield* parseCosDocumentSteps(bytes, {
45323
45383
  ...options,
45324
45384
  recovery: options?.recovery ?? "repair"
45325
45385
  })
45326
45386
  );
45327
45387
  }
45388
+ static load(bytes, options) {
45389
+ return drainWork(_PdfDocument.loadSteps(bytes, options));
45390
+ }
45328
45391
  rebuildPagesList() {
45329
45392
  const catalog = this.cos.resolveDict(this.cos.rootRef);
45330
45393
  const pagesNode = catalog ? dictGet(catalog, "Pages") : void 0;
@@ -45406,20 +45469,30 @@ var PdfDocument = class _PdfDocument {
45406
45469
  this.pages.splice(index, 1);
45407
45470
  this.syncPageTree();
45408
45471
  }
45409
- copyPagesFrom(sourceDoc, indices) {
45472
+ *copyPagesFromSteps(sourceDoc, indices) {
45473
+ function* cloneItems(items) {
45474
+ const result = [];
45475
+ for (const item of items) result.push(yield* cloneNode(item));
45476
+ return result;
45477
+ }
45478
+ yield;
45479
+ let work = 0;
45410
45480
  const memo = /* @__PURE__ */ new Map();
45411
45481
  const sourcePageObjNums = /* @__PURE__ */ new Set();
45412
45482
  for (let i = 0; i < sourceDoc.getPageCount(); i++) {
45483
+ if (++work % 16 === 0) yield;
45413
45484
  sourcePageObjNums.add(sourceDoc.getPage(i).ref.objectNumber);
45414
45485
  }
45415
45486
  const targetPageRefs = [];
45416
45487
  for (const idx of indices) {
45488
+ if (++work % 16 === 0) yield;
45417
45489
  const srcPage = sourceDoc.getPage(idx);
45418
45490
  const pageRef = this.cos.allocateObject({ kind: "null" });
45419
45491
  targetPageRefs.push(pageRef);
45420
45492
  memo.set(srcPage.ref.objectNumber, pageRef);
45421
45493
  }
45422
- const cloneNode = (node) => {
45494
+ const cloneNode = function* (node) {
45495
+ if (++work % 16 === 0) yield;
45423
45496
  if (node.kind === "ref") {
45424
45497
  const existing = memo.get(node.objectNumber);
45425
45498
  if (existing) return existing;
@@ -45430,12 +45503,12 @@ var PdfDocument = class _PdfDocument {
45430
45503
  if (!target) return cosRef(0);
45431
45504
  const placeholderRef = this.cos.allocateObject({ kind: "null" });
45432
45505
  memo.set(node.objectNumber, placeholderRef);
45433
- const clonedTarget = cloneNode(target);
45506
+ const clonedTarget = yield* cloneNode(target);
45434
45507
  this.cos.setObject(placeholderRef.objectNumber, clonedTarget, 0);
45435
45508
  return placeholderRef;
45436
45509
  }
45437
45510
  if (node.kind === "array") {
45438
- return cosArray(node.items.map(cloneNode));
45511
+ return cosArray(yield* cloneItems(node.items));
45439
45512
  }
45440
45513
  if (node.kind === "dict") {
45441
45514
  const typeEntry = dictGet(node, "Type");
@@ -45445,13 +45518,13 @@ var PdfDocument = class _PdfDocument {
45445
45518
  if (isPageTreeNode && entry.key.decoded === "Parent") continue;
45446
45519
  newEntries.push({
45447
45520
  key: { ...entry.key },
45448
- value: cloneNode(entry.value)
45521
+ value: yield* cloneNode(entry.value)
45449
45522
  });
45450
45523
  }
45451
45524
  return { kind: "dict", entries: newEntries };
45452
45525
  }
45453
45526
  if (node.kind === "stream") {
45454
- const clonedDict = cloneNode(node.dict);
45527
+ const clonedDict = yield* cloneNode(node.dict);
45455
45528
  return {
45456
45529
  kind: "stream",
45457
45530
  dict: clonedDict,
@@ -45460,11 +45533,12 @@ var PdfDocument = class _PdfDocument {
45460
45533
  };
45461
45534
  }
45462
45535
  return node;
45463
- };
45536
+ }.bind(this);
45464
45537
  const copiedPages = [];
45465
45538
  for (const [position, idx] of indices.entries()) {
45539
+ if (++work % 16 === 0) yield;
45466
45540
  const srcPage = sourceDoc.getPage(idx);
45467
- const clonedPageDict = cloneNode(srcPage.pageDict);
45541
+ const clonedPageDict = yield* cloneNode(srcPage.pageDict);
45468
45542
  const size = srcPage.getSize();
45469
45543
  if (!dictGet(clonedPageDict, "MediaBox")) {
45470
45544
  dictSet(
@@ -45474,13 +45548,14 @@ var PdfDocument = class _PdfDocument {
45474
45548
  );
45475
45549
  }
45476
45550
  if (!dictGet(clonedPageDict, "Resources")) {
45477
- dictSet(clonedPageDict, "Resources", cloneNode(srcPage.getResourcesDict()));
45551
+ dictSet(clonedPageDict, "Resources", yield* cloneNode(srcPage.getResourcesDict()));
45478
45552
  }
45479
45553
  if (!dictGet(clonedPageDict, "Rotate") && srcPage.getRotation() !== 0) {
45480
45554
  dictSet(clonedPageDict, "Rotate", cosNumber(srcPage.getRotation()));
45481
45555
  }
45482
45556
  const inheritedBoxKeys = ["CropBox", "BleedBox", "TrimBox", "ArtBox"];
45483
45557
  for (const boxKey of inheritedBoxKeys) {
45558
+ if (++work % 16 === 0) yield;
45484
45559
  if (!dictGet(clonedPageDict, boxKey)) {
45485
45560
  const boxVal = boxKey === "CropBox" ? srcPage.getCropBox() : boxKey === "BleedBox" ? srcPage.getBleedBox() : boxKey === "TrimBox" ? srcPage.getTrimBox() : srcPage.getArtBox();
45486
45561
  if (boxVal[0] !== 0 || boxVal[1] !== 0 || boxVal[2] !== size.width || boxVal[3] !== size.height) {
@@ -45522,8 +45597,9 @@ var PdfDocument = class _PdfDocument {
45522
45597
  };
45523
45598
  const clonedRootFieldRefs = [];
45524
45599
  for (const item of srcFieldsArr.items) {
45600
+ if (++work % 16 === 0) yield;
45525
45601
  if (!hasClonedDescendant(item)) continue;
45526
- const cloned = cloneNode(item);
45602
+ const cloned = yield* cloneNode(item);
45527
45603
  if (cloned.kind === "ref") {
45528
45604
  const clonedDict = this.cos.resolveDict(cloned);
45529
45605
  const kidsArr = clonedDict ? this.cos.resolveArray(dictGet(clonedDict, "Kids")) : void 0;
@@ -45557,6 +45633,7 @@ var PdfDocument = class _PdfDocument {
45557
45633
  dstFields.items.filter((x) => x.kind === "ref").map((x) => x.objectNumber)
45558
45634
  );
45559
45635
  for (const fRef of clonedRootFieldRefs) {
45636
+ if (++work % 16 === 0) yield;
45560
45637
  if (!existingNums.has(fRef.objectNumber)) {
45561
45638
  dstFields.items.push(fRef);
45562
45639
  existingNums.add(fRef.objectNumber);
@@ -45564,11 +45641,11 @@ var PdfDocument = class _PdfDocument {
45564
45641
  }
45565
45642
  const srcDr = dictGet(srcAcroForm, "DR");
45566
45643
  if (srcDr && !dictGet(dstAcroForm, "DR")) {
45567
- dictSet(dstAcroForm, "DR", cloneNode(srcDr));
45644
+ dictSet(dstAcroForm, "DR", yield* cloneNode(srcDr));
45568
45645
  }
45569
45646
  const srcDa = dictGet(srcAcroForm, "DA");
45570
45647
  if (srcDa && !dictGet(dstAcroForm, "DA")) {
45571
- dictSet(dstAcroForm, "DA", cloneNode(srcDa));
45648
+ dictSet(dstAcroForm, "DA", yield* cloneNode(srcDa));
45572
45649
  }
45573
45650
  }
45574
45651
  }
@@ -45577,12 +45654,15 @@ var PdfDocument = class _PdfDocument {
45577
45654
  if (srcOcProps) {
45578
45655
  const dstCatalog = this.cos.resolveDict(this.cos.rootRef);
45579
45656
  if (dstCatalog && !dictGet(dstCatalog, "OCProperties")) {
45580
- dictSet(dstCatalog, "OCProperties", cloneNode(srcOcProps));
45657
+ dictSet(dstCatalog, "OCProperties", yield* cloneNode(srcOcProps));
45581
45658
  }
45582
45659
  }
45583
45660
  this.syncPageTree();
45584
45661
  return copiedPages;
45585
45662
  }
45663
+ copyPagesFrom(sourceDoc, indices) {
45664
+ return drainWork(this.copyPagesFromSteps(sourceDoc, indices));
45665
+ }
45586
45666
  embedStandardFont(fontName) {
45587
45667
  return createStandardFontHandle(fontName);
45588
45668
  }
@@ -45782,14 +45862,15 @@ var PdfDocument = class _PdfDocument {
45782
45862
  });
45783
45863
  return buildSemanticAstFromPages(extractedPages, tablesByPage, displayLists);
45784
45864
  }
45785
- save(options = {}) {
45865
+ *saveSteps(options = {}) {
45866
+ yield;
45786
45867
  this.syncPageTree();
45787
45868
  if (this.cos.requiresFullRewrite) {
45788
45869
  pruneUnusedXObjects(this.cos, this.pages);
45789
45870
  discardUnreachableObjects(this.cos);
45790
45871
  }
45791
45872
  if (options.encrypt) {
45792
- return encryptCosDocument(this.cos, options.encrypt);
45873
+ return yield* encryptCosDocumentSteps(this.cos, options.encrypt);
45793
45874
  }
45794
45875
  const allObjects = [...this.cos.objects.values()].sort(
45795
45876
  (a, b) => a.objectNumber - b.objectNumber
@@ -45797,7 +45878,7 @@ var PdfDocument = class _PdfDocument {
45797
45878
  if (options.incremental && !this.cos.requiresFullRewrite && this.cos.bytes.length > 0) {
45798
45879
  return appendIncrementalRevision(this.cos.bytes, this.cos, allObjects);
45799
45880
  }
45800
- return serializeCosDocument({
45881
+ return yield* serializeCosDocumentSteps({
45801
45882
  objects: allObjects,
45802
45883
  rootRef: this.cos.rootRef,
45803
45884
  infoRef: this.cos.infoRef,
@@ -45808,6 +45889,9 @@ var PdfDocument = class _PdfDocument {
45808
45889
  linearize: options.linearize
45809
45890
  });
45810
45891
  }
45892
+ save(options = {}) {
45893
+ return drainWork(this.saveSteps(options));
45894
+ }
45811
45895
  };
45812
45896
  function resolveDestinationPageIndex(doc, destOrActionNode) {
45813
45897
  const cos = doc.cos;
@@ -45932,6 +46016,7 @@ export {
45932
46016
  decodeWinAnsiByte,
45933
46017
  decodeXObjectImageToRgba,
45934
46018
  decryptCosDocument,
46019
+ decryptCosDocumentSteps,
45935
46020
  decryptPdfBuffer,
45936
46021
  derivePdfEncryptionKey,
45937
46022
  dictDelete,
@@ -45954,6 +46039,7 @@ export {
45954
46039
  encodeWinAnsiBytes,
45955
46040
  encodeWinAnsiChar,
45956
46041
  encryptCosDocument,
46042
+ encryptCosDocumentSteps,
45957
46043
  encryptPdfBuffer,
45958
46044
  evalShadingFunctionToComponents,
45959
46045
  evaluateContentStreamToDisplayList,
@@ -45965,6 +46051,7 @@ export {
45965
46051
  formatExtractedPageText,
45966
46052
  formatPdfNumber,
45967
46053
  generateDocumentFormAppearances,
46054
+ generateDocumentFormAppearancesSteps,
45968
46055
  generateToUnicodeCMap,
45969
46056
  getDisplayListCropBox,
45970
46057
  getDocumentFormFields,
@@ -45978,6 +46065,7 @@ export {
45978
46065
  parseCharacterCMap,
45979
46066
  parseContentStream,
45980
46067
  parseCosDocument,
46068
+ parseCosDocumentSteps,
45981
46069
  parseFormDataBytes,
45982
46070
  parseToUnicodeCMap,
45983
46071
  parseTrueTypeFont,
@@ -45996,6 +46084,7 @@ export {
45996
46084
  serializeContentAst,
45997
46085
  serializeContentNodesToLines,
45998
46086
  serializeCosDocument,
46087
+ serializeCosDocumentSteps,
45999
46088
  serializeCosNodeBytes,
46000
46089
  setDocumentFormField,
46001
46090
  tokenizeCos,