@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,7 +4,7 @@ import {
4
4
 
5
5
  // packages/safe-bash-command-wkhtmltopdf/dist/index.js
6
6
  init_buffer();
7
- import { yieldTurn } from "../safe-bash-contracts/yield.js";
7
+ import { drainCooperativeSteps } from "../safe-bash-contracts/yield.js";
8
8
  import { commandRuntimeIdentity, getCommandArguments } from "../safe-bash-contracts/command.js";
9
9
  import { readBytes, writeBytes } from "../safe-bash-contracts/io.js";
10
10
  import { shellValueByteLength } from "../safe-bash-contracts/value.js";
@@ -3646,6 +3646,11 @@ function tokenizeCos(bytes, start = 0, end = bytes.length) {
3646
3646
  }
3647
3647
  return tokens;
3648
3648
  }
3649
+ function drainWork(work) {
3650
+ let step = work.next();
3651
+ while (!step.done) step = work.next();
3652
+ return step.value;
3653
+ }
3649
3654
  function bytesToString3(bytes) {
3650
3655
  if (typeof bytes !== "object" || bytes?.length === void 0) {
3651
3656
  throw new Error("Invalid argument for bytesToString");
@@ -4067,7 +4072,9 @@ function concatByteArrays(chunks) {
4067
4072
  }
4068
4073
  return out;
4069
4074
  }
4070
- function serializeCosDocument(options) {
4075
+ function* serializeCosDocumentSteps(options) {
4076
+ yield;
4077
+ let work = 0;
4071
4078
  const maxOutputBytes = options.maxOutputBytes ?? Infinity;
4072
4079
  const maxObjects = options.maxObjects ?? Infinity;
4073
4080
  const sorted = [...options.objects].sort((a, b) => a.objectNumber - b.objectNumber);
@@ -4090,6 +4097,7 @@ function serializeCosDocument(options) {
4090
4097
  const packable = [];
4091
4098
  const direct = [];
4092
4099
  for (const obj of sorted) {
4100
+ if (++work % 16 === 0) yield;
4093
4101
  const isLinearized = obj.value.kind === "dict" && dictGet(obj.value, "Linearized") !== void 0;
4094
4102
  if (obj.value.kind !== "stream" && obj.generationNumber === 0 && !isLinearized) {
4095
4103
  packable.push(obj);
@@ -4104,6 +4112,7 @@ function serializeCosDocument(options) {
4104
4112
  const headerPairs = [];
4105
4113
  let relOffset = 0;
4106
4114
  for (const pObj of packable) {
4115
+ if (++work % 16 === 0) yield;
4107
4116
  headerPairs.push(`${pObj.objectNumber} ${relOffset}`);
4108
4117
  const bBytes = serializeCosNodeBytes(pObj.value);
4109
4118
  const nl = textEncoder2.encode("\n");
@@ -4129,6 +4138,7 @@ function serializeCosDocument(options) {
4129
4138
  ];
4130
4139
  const directOffsets = /* @__PURE__ */ new Map();
4131
4140
  for (const dObj of allDirect) {
4141
+ if (++work % 16 === 0) yield;
4132
4142
  directOffsets.set(dObj.objectNumber, { offset, generation: dObj.generationNumber });
4133
4143
  const prefix = textEncoder2.encode(`${dObj.objectNumber} ${dObj.generationNumber} obj
4134
4144
  `);
@@ -4139,6 +4149,7 @@ function serializeCosDocument(options) {
4139
4149
  }
4140
4150
  const compressedMap = /* @__PURE__ */ new Map();
4141
4151
  for (let idx = 0; idx < packable.length; idx++) {
4152
+ if (++work % 16 === 0) yield;
4142
4153
  compressedMap.set(packable[idx].objectNumber, idx);
4143
4154
  }
4144
4155
  const xrefOffset2 = offset;
@@ -4156,6 +4167,7 @@ function serializeCosDocument(options) {
4156
4167
  };
4157
4168
  writeEntry7(0, 0, 0, 65535);
4158
4169
  for (let i = 1; i < size2; i++) {
4170
+ if (++work % 16 === 0) yield;
4159
4171
  if (i === xrefStmNum) {
4160
4172
  writeEntry7(i, 1, xrefOffset2, 0);
4161
4173
  } else if (compressedMap.has(i)) {
@@ -4236,6 +4248,7 @@ ${xrefOffset2}
4236
4248
  let pageCount = 0;
4237
4249
  let firstPageObjNum = options.rootRef.objectNumber;
4238
4250
  for (const o of sorted) {
4251
+ if (++work % 16 === 0) yield;
4239
4252
  if (o.value.kind === "dict") {
4240
4253
  const t = dictGet(o.value, "Type");
4241
4254
  if (t?.kind === "name" && t.decoded === "Page") {
@@ -4283,6 +4296,7 @@ ${xrefOffset2}
4283
4296
  }
4284
4297
  const objectOffsets = /* @__PURE__ */ new Map();
4285
4298
  for (const obj of sorted) {
4299
+ if (++work % 16 === 0) yield;
4286
4300
  objectOffsets.set(obj.objectNumber, { offset, generation: obj.generationNumber });
4287
4301
  let value = obj.value;
4288
4302
  if (options.normalizeContent && value.kind === "stream" && value.decodedBytes) {
@@ -4314,6 +4328,7 @@ ${xrefOffset2}
4314
4328
  0000000000 65535 f
4315
4329
  `;
4316
4330
  for (let i = 1; i < size; i++) {
4331
+ if (++work % 16 === 0) yield;
4317
4332
  const entry = objectOffsets.get(i);
4318
4333
  if (entry) {
4319
4334
  xrefText += `${String(entry.offset).padStart(10, "0")} ${String(entry.generation).padStart(5, "0")} n
@@ -4360,6 +4375,7 @@ ${xrefOffset}
4360
4375
  let endFirstPage = xrefOffset;
4361
4376
  const sortedOffsets = [...objectOffsets.entries()].sort((a, b) => a[1].offset - b[1].offset);
4362
4377
  for (let i = 0; i < sortedOffsets.length; i++) {
4378
+ if (++work % 16 === 0) yield;
4363
4379
  const [objNum, info3] = sortedOffsets[i];
4364
4380
  const nextOff = sortedOffsets[i + 1]?.[1].offset ?? xrefOffset;
4365
4381
  if (objNum === hintObjAfter.objectNumber) {
@@ -4393,6 +4409,9 @@ ${xrefOffset}
4393
4409
  }
4394
4410
  return fullBytes;
4395
4411
  }
4412
+ function serializeCosDocument(options) {
4413
+ return drainWork(serializeCosDocumentSteps(options));
4414
+ }
4396
4415
  function appendIncrementalRevision(originalBytes, doc, updatedObjects) {
4397
4416
  const chunks = [originalBytes, textEncoder2.encode("\n")];
4398
4417
  let offset = originalBytes.length + 1;
@@ -4631,48 +4650,30 @@ function encryptPdfBuffer(state, objectNumber, generationNumber, plaintext) {
4631
4650
  const objKey = md5Bytes([state.fileKey, suffix]).subarray(0, Math.min(16, state.fileKey.length + 5));
4632
4651
  return rc4Transform(objKey, plaintext);
4633
4652
  }
4634
- function transformNodeStringsAndStreams(node, transform, transformStream) {
4653
+ function* transformNodeStringsAndStreamsSteps(node, transform, transformStream) {
4654
+ yield;
4635
4655
  switch (node.kind) {
4636
4656
  case "string":
4637
- return {
4638
- kind: "string",
4639
- format: "hex",
4640
- bytes: transform(node.bytes)
4641
- };
4642
- case "array":
4643
- return {
4644
- kind: "array",
4645
- items: node.items.map((item) => transformNodeStringsAndStreams(item, transform, transformStream))
4646
- };
4657
+ return { kind: "string", format: "hex", bytes: transform(node.bytes) };
4658
+ case "array": {
4659
+ const items = [];
4660
+ for (const item of node.items) items.push(yield* transformNodeStringsAndStreamsSteps(item, transform, transformStream));
4661
+ return { kind: "array", items };
4662
+ }
4647
4663
  case "dict": {
4648
- const type = dictGet(node, "Type");
4649
- const fieldType = dictGet(node, "FT");
4650
- const byteRange = dictGet(node, "ByteRange");
4664
+ const type = dictGet(node, "Type"), fieldType = dictGet(node, "FT"), byteRange = dictGet(node, "ByteRange");
4651
4665
  const signature = type?.kind === "name" && type.decoded === "Sig" || fieldType?.kind === "name" && fieldType.decoded === "Sig" || byteRange?.kind === "array" && dictGet(node, "Filter")?.kind === "name";
4652
- return {
4653
- kind: "dict",
4654
- entries: node.entries.map((e) => ({
4655
- key: e.key,
4656
- value: signature && e.key.decoded === "Contents" ? e.value : transformNodeStringsAndStreams(e.value, transform, transformStream)
4657
- }))
4658
- };
4666
+ const entries = [];
4667
+ 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) });
4668
+ return { kind: "dict", entries };
4659
4669
  }
4660
4670
  case "stream": {
4661
4671
  const type = dictGet(node.dict, "Type");
4662
4672
  if (type?.kind === "name" && type.decoded === "XRef") return node;
4663
4673
  const stream = transformStream ? transformStream(node) : { ...node, rawBytes: transform(node.rawBytes) };
4664
- const updatedDict = {
4665
- kind: "dict",
4666
- entries: stream.dict.entries.map((e) => ({
4667
- key: e.key,
4668
- value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : transformNodeStringsAndStreams(e.value, transform, transformStream)
4669
- }))
4670
- };
4671
- return {
4672
- kind: "stream",
4673
- dict: updatedDict,
4674
- rawBytes: stream.rawBytes
4675
- };
4674
+ const entries = [];
4675
+ 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) });
4676
+ return { kind: "stream", dict: { kind: "dict", entries }, rawBytes: stream.rawBytes };
4676
4677
  }
4677
4678
  default:
4678
4679
  return node;
@@ -4741,7 +4742,8 @@ function createR6Encryption(userPassword, ownerPassword, pMask) {
4741
4742
  StrF: cosName("StdCF")
4742
4743
  }) };
4743
4744
  }
4744
- function encryptCosDocument(doc, options = {}) {
4745
+ function* encryptCosDocumentSteps(doc, options = {}) {
4746
+ yield;
4745
4747
  const userPassword = options.userPassword ?? "";
4746
4748
  const ownerPassword = options.ownerPassword ?? userPassword;
4747
4749
  const revision = options.revision ?? 6;
@@ -4763,14 +4765,15 @@ function encryptCosDocument(doc, options = {}) {
4763
4765
  const encryptObjNum = maxObjNum + 1;
4764
4766
  const encryptedObjects = [];
4765
4767
  for (const obj of doc.objects.values()) {
4766
- const transformed = transformNodeStringsAndStreams(
4768
+ yield;
4769
+ const transformed = yield* transformNodeStringsAndStreamsSteps(
4767
4770
  obj.value,
4768
4771
  (plain) => encryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, plain)
4769
4772
  );
4770
4773
  encryptedObjects.push({ objectNumber: obj.objectNumber, generationNumber: obj.generationNumber, value: transformed });
4771
4774
  }
4772
4775
  encryptedObjects.push({ objectNumber: encryptObjNum, generationNumber: 0, value: encryptDict });
4773
- return serializeCosDocument({
4776
+ return yield* serializeCosDocumentSteps({
4774
4777
  objects: encryptedObjects,
4775
4778
  rootRef: doc.rootRef,
4776
4779
  infoRef: doc.infoRef,
@@ -4820,17 +4823,19 @@ function decryptStream(doc, stream, transform) {
4820
4823
  }
4821
4824
  return { kind: "stream", dict, rawBytes: bytes };
4822
4825
  }
4823
- function decryptCosDocument(doc, state) {
4826
+ function* decryptCosDocumentSteps(doc, state) {
4827
+ yield;
4824
4828
  const encryptObjNum = doc.encryptRef?.objectNumber;
4825
4829
  const handler = securityHandlers.get(state);
4826
4830
  for (const [num, obj] of doc.objects.entries()) {
4831
+ yield;
4827
4832
  if (num === encryptObjNum || handler?.plaintextObjects.has(num)) continue;
4828
4833
  if (obj.value.kind === "stream") {
4829
4834
  const type = doc.resolve(dictGet(obj.value.dict, "Type"));
4830
4835
  if (type?.kind === "name" && (type.decoded === "XRef" || type.decoded === "Metadata" && !state.encryptMetadata)) continue;
4831
4836
  }
4832
4837
  const transform = handler?.factory.createCipherTransform(obj.objectNumber, obj.generationNumber);
4833
- const decrypted = transformNodeStringsAndStreams(
4838
+ const decrypted = yield* transformNodeStringsAndStreamsSteps(
4834
4839
  obj.value,
4835
4840
  (cipher) => decryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, cipher),
4836
4841
  transform ? (stream) => decryptStream(doc, stream, transform) : void 0
@@ -4838,9 +4843,12 @@ function decryptCosDocument(doc, state) {
4838
4843
  doc.objects.set(num, { objectNumber: obj.objectNumber, generationNumber: obj.generationNumber, value: decrypted, span: obj.span });
4839
4844
  }
4840
4845
  }
4841
- function parseNodeFromLexer(lexer, bytes, maxDepth, repair = false) {
4846
+ function* parseNodeFromLexerSteps(lexer, bytes, maxDepth, repair = false) {
4847
+ yield;
4848
+ let work = 0;
4842
4849
  const stack = [];
4843
4850
  while (true) {
4851
+ if (++work % 16 === 0) yield;
4844
4852
  const tok = lexer.nextToken();
4845
4853
  const parent = stack.at(-1);
4846
4854
  if (!tok) {
@@ -5034,7 +5042,8 @@ function parseHeaderVersion(bytes) {
5034
5042
  }
5035
5043
  return head.slice(idx + 5, idx + 8);
5036
5044
  }
5037
- function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
5045
+ function* parseObjectAtOffsetSteps(bytes, offset, maxRecursionDepth, repair = false) {
5046
+ yield;
5038
5047
  const lexer = new CosByteLexer(bytes, offset);
5039
5048
  const objNumTok = lexer.nextToken();
5040
5049
  const genNumTok = lexer.nextToken();
@@ -5042,7 +5051,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
5042
5051
  if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
5043
5052
  throw new PdfError("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
5044
5053
  }
5045
- const value = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, repair);
5054
+ const value = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, repair);
5046
5055
  if (!value) {
5047
5056
  throw new PdfError("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
5048
5057
  }
@@ -5053,7 +5062,9 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
5053
5062
  span: { start: objNumTok.span.start, end: lexer.offset }
5054
5063
  };
5055
5064
  }
5056
- function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
5065
+ function* parseXrefRevisionAtSteps(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
5066
+ yield;
5067
+ let work = 0;
5057
5068
  if (xrefOffset < 0 || xrefOffset >= bytes.length) {
5058
5069
  throw new PdfError("E_PARSE", `Invalid xref offset: ${xrefOffset}`);
5059
5070
  }
@@ -5065,6 +5076,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
5065
5076
  if (firstTok.kind === "keyword" && firstTok.value === "xref") {
5066
5077
  const entries2 = /* @__PURE__ */ new Map();
5067
5078
  while (true) {
5079
+ if (++work % 16 === 0) yield;
5068
5080
  const saved = lexer.offset;
5069
5081
  const tok = lexer.nextToken();
5070
5082
  if (!tok) {
@@ -5088,6 +5100,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
5088
5100
  }
5089
5101
  if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
5090
5102
  for (let i = 0; i < count; i++) {
5103
+ if (++work % 16 === 0) yield;
5091
5104
  const offTok = lexer.nextToken();
5092
5105
  const genTok = lexer.nextToken();
5093
5106
  const flagTok = lexer.nextToken();
@@ -5113,7 +5126,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
5113
5126
  if (entries2.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
5114
5127
  }
5115
5128
  }
5116
- const trailerNode = parseNodeFromLexer(lexer, bytes, maxRecursionDepth);
5129
+ const trailerNode = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth);
5117
5130
  if (!trailerNode || trailerNode.kind !== "dict") {
5118
5131
  throw new PdfError("E_PARSE", "Missing trailer dictionary after xref table");
5119
5132
  }
@@ -5125,7 +5138,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
5125
5138
  previousXrefOffset: prevNode2?.kind === "number" ? prevNode2.value : void 0
5126
5139
  };
5127
5140
  }
5128
- const xrefObj = parseObjectAtOffset(bytes, xrefOffset, maxRecursionDepth);
5141
+ const xrefObj = yield* parseObjectAtOffsetSteps(bytes, xrefOffset, maxRecursionDepth);
5129
5142
  if (xrefObj.value.kind !== "stream") {
5130
5143
  throw new PdfError("E_PARSE", `Expected xref table or XRef stream at offset ${xrefOffset}`);
5131
5144
  }
@@ -5146,6 +5159,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
5146
5159
  if (indexArray) {
5147
5160
  if (indexArray.kind !== "array" || indexArray.items.length % 2 !== 0) throw new PdfError("E_PARSE", "Invalid XRef range fields");
5148
5161
  for (let i = 0; i < indexArray.items.length; i += 2) {
5162
+ if (++work % 16 === 0) yield;
5149
5163
  const first = indexArray.items[i];
5150
5164
  const count = indexArray.items[i + 1];
5151
5165
  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)) {
@@ -5168,9 +5182,11 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
5168
5182
  return v;
5169
5183
  };
5170
5184
  for (const [startObj, count] of subsections) {
5185
+ if (++work % 16 === 0) yield;
5171
5186
  if (count > (decoded.length - pos) / stride) throw new PdfError("E_PARSE", "Truncated XRef stream");
5172
5187
  if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
5173
5188
  for (let i = 0; i < count; i++) {
5189
+ if (++work % 16 === 0) yield;
5174
5190
  const objNum = startObj + i;
5175
5191
  const field0 = w0 > 0 ? readInt(w0) : 1;
5176
5192
  const field1 = readInt(w1);
@@ -5216,12 +5232,16 @@ function isAsciiWhitespace(ch3) {
5216
5232
  function isAsciiDigit(ch3) {
5217
5233
  return ch3 >= 48 && ch3 <= 57;
5218
5234
  }
5219
- function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
5235
+ function* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth) {
5236
+ yield;
5237
+ let work = 0;
5220
5238
  const objects = /* @__PURE__ */ new Map();
5221
5239
  const trailers = [];
5222
5240
  let pos = 0;
5223
5241
  while (pos < bytes.length) {
5242
+ if (++work % 16 === 0) yield;
5224
5243
  while (pos < bytes.length && !isAsciiDigit(bytes[pos])) {
5244
+ if (++work % 16 === 0) yield;
5225
5245
  if (bytes[pos] === 37) {
5226
5246
  while (pos < bytes.length && bytes[pos] !== 10 && bytes[pos] !== 13) pos++;
5227
5247
  continue;
@@ -5231,7 +5251,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
5231
5251
  try {
5232
5252
  const token = lexer.nextToken();
5233
5253
  if (token?.kind === "keyword" && token.value === "trailer") {
5234
- const trailer = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, true);
5254
+ const trailer = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, true);
5235
5255
  if (trailer?.kind === "dict") trailers.push(trailer);
5236
5256
  pos = lexer.offset;
5237
5257
  continue;
@@ -5264,7 +5284,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
5264
5284
  bytes[pos + 3] === 40)) {
5265
5285
  pos += 3;
5266
5286
  try {
5267
- const parsed = parseObjectAtOffset(bytes, headerStart, maxRecursionDepth, true);
5287
+ const parsed = yield* parseObjectAtOffsetSteps(bytes, headerStart, maxRecursionDepth, true);
5268
5288
  objects.set(parsed.objectNumber, parsed);
5269
5289
  if (parsed.value.kind === "stream") {
5270
5290
  const type = dictGet(parsed.value.dict, "Type");
@@ -5281,13 +5301,17 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
5281
5301
  }
5282
5302
  return { objects, trailers };
5283
5303
  }
5284
- function unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
5304
+ function* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
5305
+ yield;
5306
+ let work = 0;
5285
5307
  for (const obj of [...objects.values()]) {
5308
+ if (++work % 16 === 0) yield;
5286
5309
  if (obj.value.kind === "stream") {
5287
5310
  const t = dictGet(obj.value.dict, "Type");
5288
5311
  if (t?.kind === "name" && t.decoded === "ObjStm") {
5289
5312
  try {
5290
- for (const [unpackedNum, unpackedVal] of unpackObjectStream(obj.value, maxDecompressedBytes, maxRecursionDepth, true).entries()) {
5313
+ for (const [unpackedNum, unpackedVal] of (yield* unpackObjectStreamSteps(obj.value, maxDecompressedBytes, maxRecursionDepth, true)).entries()) {
5314
+ if (++work % 16 === 0) yield;
5291
5315
  if (!objects.has(unpackedNum)) {
5292
5316
  objects.set(unpackedNum, {
5293
5317
  objectNumber: unpackedNum,
@@ -5323,7 +5347,9 @@ function recoveredReferences(objects) {
5323
5347
  }
5324
5348
  return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
5325
5349
  }
5326
- function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
5350
+ function* unpackObjectStreamSteps(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
5351
+ yield;
5352
+ let work = 0;
5327
5353
  const nNode = dictGet(streamObj.dict, "N");
5328
5354
  const firstNode = dictGet(streamObj.dict, "First");
5329
5355
  if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
@@ -5333,6 +5359,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
5333
5359
  const headerLexer = new CosByteLexer(decoded, 0);
5334
5360
  const pairs = [];
5335
5361
  for (let i = 0; i < nNode.value; i++) {
5362
+ if (++work % 16 === 0) yield;
5336
5363
  const numTok = headerLexer.nextToken();
5337
5364
  const offTok = headerLexer.nextToken();
5338
5365
  if (numTok?.kind === "number" && offTok?.kind === "number") {
@@ -5341,9 +5368,10 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
5341
5368
  }
5342
5369
  const result = /* @__PURE__ */ new Map();
5343
5370
  for (const pair of pairs) {
5371
+ if (++work % 16 === 0) yield;
5344
5372
  try {
5345
5373
  const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
5346
- const node = parseNodeFromLexer(valLexer, decoded, maxRecursionDepth, repair);
5374
+ const node = yield* parseNodeFromLexerSteps(valLexer, decoded, maxRecursionDepth, repair);
5347
5375
  if (node) {
5348
5376
  result.set(pair.objectNumber, node);
5349
5377
  }
@@ -5353,7 +5381,9 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
5353
5381
  }
5354
5382
  return result;
5355
5383
  }
5356
- function parseCosDocument(bytes, options = {}) {
5384
+ function* parseCosDocumentSteps(bytes, options = {}) {
5385
+ yield;
5386
+ let work = 0;
5357
5387
  const version = parseHeaderVersion(bytes);
5358
5388
  const recovery = options.recovery ?? "strict";
5359
5389
  const maxObjects = options.maxObjects ?? Infinity;
@@ -5388,10 +5418,12 @@ function parseCosDocument(bytes, options = {}) {
5388
5418
  let currentXrefOffset = offsetTok.value;
5389
5419
  const visitedOffsets = /* @__PURE__ */ new Set();
5390
5420
  while (currentXrefOffset !== void 0 && !visitedOffsets.has(currentXrefOffset)) {
5421
+ if (++work % 16 === 0) yield;
5391
5422
  visitedOffsets.add(currentXrefOffset);
5392
- const rev = parseXrefRevisionAt(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
5423
+ const rev = yield* parseXrefRevisionAtSteps(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
5393
5424
  revisions.push(rev);
5394
5425
  for (const [num, entry] of rev.entries.entries()) {
5426
+ if (++work % 16 === 0) yield;
5395
5427
  if (!mergedXref.has(num)) {
5396
5428
  mergedXref.set(num, entry);
5397
5429
  if (mergedXref.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
@@ -5424,8 +5456,9 @@ function parseCosDocument(bytes, options = {}) {
5424
5456
  if (!useRepair && rootRef) {
5425
5457
  try {
5426
5458
  for (const [objNum, entry] of mergedXref.entries()) {
5459
+ if (++work % 16 === 0) yield;
5427
5460
  if (entry.type !== "uncompressed") continue;
5428
- const parsed = parseObjectAtOffset(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
5461
+ const parsed = yield* parseObjectAtOffsetSteps(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
5429
5462
  if (parsed.objectNumber !== objNum || parsed.generationNumber !== (entry.generationNumber ?? 0)) {
5430
5463
  throw new PdfError("E_PARSE", `Bad uncompressed XRef entry for object ${objNum}`);
5431
5464
  }
@@ -5443,7 +5476,7 @@ function parseCosDocument(bytes, options = {}) {
5443
5476
  throw new PdfError("E_PARSE", "PDF trailer missing /Root reference");
5444
5477
  }
5445
5478
  useRepair = true;
5446
- const scanned = repairScanCosDocument(bytes, maxObjects, maxRecursionDepth);
5479
+ const scanned = yield* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth);
5447
5480
  objects = scanned.objects;
5448
5481
  revisions.length = 0;
5449
5482
  mergedXref.clear();
@@ -5478,7 +5511,7 @@ function parseCosDocument(bytes, options = {}) {
5478
5511
  encryptNode = encrypt?.kind === "ref" || encrypt?.kind === "dict" ? encrypt : void 0;
5479
5512
  encryptRef = encrypt?.kind === "ref" ? encrypt : void 0;
5480
5513
  idArray = id?.kind === "array" ? id : void 0;
5481
- if (!rootRef && !encryptNode) unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
5514
+ if (!rootRef && !encryptNode) yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
5482
5515
  const fallback = recoveredReferences(objects);
5483
5516
  rootRef ??= fallback.rootRef;
5484
5517
  infoRef ??= fallback.infoRef;
@@ -5513,20 +5546,21 @@ function parseCosDocument(bytes, options = {}) {
5513
5546
  maxRecursionDepth
5514
5547
  });
5515
5548
  doc.encryption = encState;
5516
- decryptCosDocument(doc, encState);
5549
+ yield* decryptCosDocumentSteps(doc, encState);
5517
5550
  }
5518
5551
  if (useRepair) {
5519
- unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
5552
+ yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
5520
5553
  doc.infoRef ??= recoveredReferences(objects).infoRef;
5521
5554
  }
5522
5555
  const objStmCache = /* @__PURE__ */ new Map();
5523
5556
  for (const [objNum, entry] of mergedXref.entries()) {
5557
+ if (++work % 16 === 0) yield;
5524
5558
  if (entry.type === "compressed" && entry.objectStreamNumber !== void 0) {
5525
5559
  let unpacked = objStmCache.get(entry.objectStreamNumber);
5526
5560
  if (!unpacked) {
5527
5561
  const stmObj = objects.get(entry.objectStreamNumber)?.value;
5528
5562
  if (stmObj?.kind === "stream") {
5529
- unpacked = unpackObjectStream(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
5563
+ unpacked = yield* unpackObjectStreamSteps(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
5530
5564
  objStmCache.set(entry.objectStreamNumber, unpacked);
5531
5565
  }
5532
5566
  }
@@ -5543,6 +5577,9 @@ function parseCosDocument(bytes, options = {}) {
5543
5577
  }
5544
5578
  return doc;
5545
5579
  }
5580
+ function parseCosDocument(bytes, options = {}) {
5581
+ return drainWork(parseCosDocumentSteps(bytes, options));
5582
+ }
5546
5583
  function isAsciiHexDigit(ch3) {
5547
5584
  return ch3 >= 48 && ch3 <= 57 || ch3 >= 65 && ch3 <= 70 || ch3 >= 97 && ch3 <= 102;
5548
5585
  }
@@ -13345,7 +13382,8 @@ function resolveInheritedFieldEntry(doc, dict, key) {
13345
13382
  }
13346
13383
  return void 0;
13347
13384
  }
13348
- function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
13385
+ function* collectFieldDictsSteps(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen, yieldState = { work: 0 }) {
13386
+ if (++yieldState.work % 256 === 0) yield;
13349
13387
  const dict = doc.resolveDict(node);
13350
13388
  if (!dict) return out;
13351
13389
  const tNode = doc.resolve(dictGet(dict, "T"));
@@ -13378,7 +13416,8 @@ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", pare
13378
13416
  return out;
13379
13417
  }
13380
13418
  for (const kid of kidsArr.items) {
13381
- collectFieldDicts(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen);
13419
+ if (++yieldState.work % 16 === 0) yield;
13420
+ yield* collectFieldDictsSteps(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen, yieldState);
13382
13421
  }
13383
13422
  } else if (fullName) {
13384
13423
  out.push({
@@ -13803,6 +13842,9 @@ function escapePdfLiteralString(str) {
13803
13842
  }
13804
13843
  return out;
13805
13844
  }
13845
+ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
13846
+ drainWork(collectFieldDictsSteps(doc, node, prefix, out, parentFt, parentFf, parentQ, parentMaxLen));
13847
+ }
13806
13848
  function createStandardFontHandle(standardName) {
13807
13849
  return {
13808
13850
  kind: "standard14",
@@ -44917,14 +44959,18 @@ var init_dist = __esm({
44917
44959
  });
44918
44960
  return new _PdfDocument(parseCosDocument(rawBytes));
44919
44961
  }
44920
- static load(bytes, options) {
44962
+ static *loadSteps(bytes, options) {
44963
+ yield;
44921
44964
  return new _PdfDocument(
44922
- parseCosDocument(bytes, {
44965
+ yield* parseCosDocumentSteps(bytes, {
44923
44966
  ...options,
44924
44967
  recovery: options?.recovery ?? "repair"
44925
44968
  })
44926
44969
  );
44927
44970
  }
44971
+ static load(bytes, options) {
44972
+ return drainWork(_PdfDocument.loadSteps(bytes, options));
44973
+ }
44928
44974
  rebuildPagesList() {
44929
44975
  const catalog = this.cos.resolveDict(this.cos.rootRef);
44930
44976
  const pagesNode = catalog ? dictGet(catalog, "Pages") : void 0;
@@ -45006,20 +45052,30 @@ var init_dist = __esm({
45006
45052
  this.pages.splice(index, 1);
45007
45053
  this.syncPageTree();
45008
45054
  }
45009
- copyPagesFrom(sourceDoc, indices) {
45055
+ *copyPagesFromSteps(sourceDoc, indices) {
45056
+ function* cloneItems(items) {
45057
+ const result = [];
45058
+ for (const item of items) result.push(yield* cloneNode(item));
45059
+ return result;
45060
+ }
45061
+ yield;
45062
+ let work = 0;
45010
45063
  const memo = /* @__PURE__ */ new Map();
45011
45064
  const sourcePageObjNums = /* @__PURE__ */ new Set();
45012
45065
  for (let i = 0; i < sourceDoc.getPageCount(); i++) {
45066
+ if (++work % 16 === 0) yield;
45013
45067
  sourcePageObjNums.add(sourceDoc.getPage(i).ref.objectNumber);
45014
45068
  }
45015
45069
  const targetPageRefs = [];
45016
45070
  for (const idx of indices) {
45071
+ if (++work % 16 === 0) yield;
45017
45072
  const srcPage = sourceDoc.getPage(idx);
45018
45073
  const pageRef = this.cos.allocateObject({ kind: "null" });
45019
45074
  targetPageRefs.push(pageRef);
45020
45075
  memo.set(srcPage.ref.objectNumber, pageRef);
45021
45076
  }
45022
- const cloneNode = (node) => {
45077
+ const cloneNode = function* (node) {
45078
+ if (++work % 16 === 0) yield;
45023
45079
  if (node.kind === "ref") {
45024
45080
  const existing = memo.get(node.objectNumber);
45025
45081
  if (existing) return existing;
@@ -45030,12 +45086,12 @@ var init_dist = __esm({
45030
45086
  if (!target) return cosRef(0);
45031
45087
  const placeholderRef = this.cos.allocateObject({ kind: "null" });
45032
45088
  memo.set(node.objectNumber, placeholderRef);
45033
- const clonedTarget = cloneNode(target);
45089
+ const clonedTarget = yield* cloneNode(target);
45034
45090
  this.cos.setObject(placeholderRef.objectNumber, clonedTarget, 0);
45035
45091
  return placeholderRef;
45036
45092
  }
45037
45093
  if (node.kind === "array") {
45038
- return cosArray(node.items.map(cloneNode));
45094
+ return cosArray(yield* cloneItems(node.items));
45039
45095
  }
45040
45096
  if (node.kind === "dict") {
45041
45097
  const typeEntry = dictGet(node, "Type");
@@ -45045,13 +45101,13 @@ var init_dist = __esm({
45045
45101
  if (isPageTreeNode && entry.key.decoded === "Parent") continue;
45046
45102
  newEntries.push({
45047
45103
  key: { ...entry.key },
45048
- value: cloneNode(entry.value)
45104
+ value: yield* cloneNode(entry.value)
45049
45105
  });
45050
45106
  }
45051
45107
  return { kind: "dict", entries: newEntries };
45052
45108
  }
45053
45109
  if (node.kind === "stream") {
45054
- const clonedDict = cloneNode(node.dict);
45110
+ const clonedDict = yield* cloneNode(node.dict);
45055
45111
  return {
45056
45112
  kind: "stream",
45057
45113
  dict: clonedDict,
@@ -45060,11 +45116,12 @@ var init_dist = __esm({
45060
45116
  };
45061
45117
  }
45062
45118
  return node;
45063
- };
45119
+ }.bind(this);
45064
45120
  const copiedPages = [];
45065
45121
  for (const [position, idx] of indices.entries()) {
45122
+ if (++work % 16 === 0) yield;
45066
45123
  const srcPage = sourceDoc.getPage(idx);
45067
- const clonedPageDict = cloneNode(srcPage.pageDict);
45124
+ const clonedPageDict = yield* cloneNode(srcPage.pageDict);
45068
45125
  const size = srcPage.getSize();
45069
45126
  if (!dictGet(clonedPageDict, "MediaBox")) {
45070
45127
  dictSet(
@@ -45074,13 +45131,14 @@ var init_dist = __esm({
45074
45131
  );
45075
45132
  }
45076
45133
  if (!dictGet(clonedPageDict, "Resources")) {
45077
- dictSet(clonedPageDict, "Resources", cloneNode(srcPage.getResourcesDict()));
45134
+ dictSet(clonedPageDict, "Resources", yield* cloneNode(srcPage.getResourcesDict()));
45078
45135
  }
45079
45136
  if (!dictGet(clonedPageDict, "Rotate") && srcPage.getRotation() !== 0) {
45080
45137
  dictSet(clonedPageDict, "Rotate", cosNumber(srcPage.getRotation()));
45081
45138
  }
45082
45139
  const inheritedBoxKeys = ["CropBox", "BleedBox", "TrimBox", "ArtBox"];
45083
45140
  for (const boxKey of inheritedBoxKeys) {
45141
+ if (++work % 16 === 0) yield;
45084
45142
  if (!dictGet(clonedPageDict, boxKey)) {
45085
45143
  const boxVal = boxKey === "CropBox" ? srcPage.getCropBox() : boxKey === "BleedBox" ? srcPage.getBleedBox() : boxKey === "TrimBox" ? srcPage.getTrimBox() : srcPage.getArtBox();
45086
45144
  if (boxVal[0] !== 0 || boxVal[1] !== 0 || boxVal[2] !== size.width || boxVal[3] !== size.height) {
@@ -45122,8 +45180,9 @@ var init_dist = __esm({
45122
45180
  };
45123
45181
  const clonedRootFieldRefs = [];
45124
45182
  for (const item of srcFieldsArr.items) {
45183
+ if (++work % 16 === 0) yield;
45125
45184
  if (!hasClonedDescendant(item)) continue;
45126
- const cloned = cloneNode(item);
45185
+ const cloned = yield* cloneNode(item);
45127
45186
  if (cloned.kind === "ref") {
45128
45187
  const clonedDict = this.cos.resolveDict(cloned);
45129
45188
  const kidsArr = clonedDict ? this.cos.resolveArray(dictGet(clonedDict, "Kids")) : void 0;
@@ -45157,6 +45216,7 @@ var init_dist = __esm({
45157
45216
  dstFields.items.filter((x) => x.kind === "ref").map((x) => x.objectNumber)
45158
45217
  );
45159
45218
  for (const fRef of clonedRootFieldRefs) {
45219
+ if (++work % 16 === 0) yield;
45160
45220
  if (!existingNums.has(fRef.objectNumber)) {
45161
45221
  dstFields.items.push(fRef);
45162
45222
  existingNums.add(fRef.objectNumber);
@@ -45164,11 +45224,11 @@ var init_dist = __esm({
45164
45224
  }
45165
45225
  const srcDr = dictGet(srcAcroForm, "DR");
45166
45226
  if (srcDr && !dictGet(dstAcroForm, "DR")) {
45167
- dictSet(dstAcroForm, "DR", cloneNode(srcDr));
45227
+ dictSet(dstAcroForm, "DR", yield* cloneNode(srcDr));
45168
45228
  }
45169
45229
  const srcDa = dictGet(srcAcroForm, "DA");
45170
45230
  if (srcDa && !dictGet(dstAcroForm, "DA")) {
45171
- dictSet(dstAcroForm, "DA", cloneNode(srcDa));
45231
+ dictSet(dstAcroForm, "DA", yield* cloneNode(srcDa));
45172
45232
  }
45173
45233
  }
45174
45234
  }
@@ -45177,12 +45237,15 @@ var init_dist = __esm({
45177
45237
  if (srcOcProps) {
45178
45238
  const dstCatalog = this.cos.resolveDict(this.cos.rootRef);
45179
45239
  if (dstCatalog && !dictGet(dstCatalog, "OCProperties")) {
45180
- dictSet(dstCatalog, "OCProperties", cloneNode(srcOcProps));
45240
+ dictSet(dstCatalog, "OCProperties", yield* cloneNode(srcOcProps));
45181
45241
  }
45182
45242
  }
45183
45243
  this.syncPageTree();
45184
45244
  return copiedPages;
45185
45245
  }
45246
+ copyPagesFrom(sourceDoc, indices) {
45247
+ return drainWork(this.copyPagesFromSteps(sourceDoc, indices));
45248
+ }
45186
45249
  embedStandardFont(fontName) {
45187
45250
  return createStandardFontHandle(fontName);
45188
45251
  }
@@ -45382,14 +45445,15 @@ var init_dist = __esm({
45382
45445
  });
45383
45446
  return buildSemanticAstFromPages(extractedPages, tablesByPage, displayLists);
45384
45447
  }
45385
- save(options = {}) {
45448
+ *saveSteps(options = {}) {
45449
+ yield;
45386
45450
  this.syncPageTree();
45387
45451
  if (this.cos.requiresFullRewrite) {
45388
45452
  pruneUnusedXObjects(this.cos, this.pages);
45389
45453
  discardUnreachableObjects(this.cos);
45390
45454
  }
45391
45455
  if (options.encrypt) {
45392
- return encryptCosDocument(this.cos, options.encrypt);
45456
+ return yield* encryptCosDocumentSteps(this.cos, options.encrypt);
45393
45457
  }
45394
45458
  const allObjects = [...this.cos.objects.values()].sort(
45395
45459
  (a, b) => a.objectNumber - b.objectNumber
@@ -45397,7 +45461,7 @@ var init_dist = __esm({
45397
45461
  if (options.incremental && !this.cos.requiresFullRewrite && this.cos.bytes.length > 0) {
45398
45462
  return appendIncrementalRevision(this.cos.bytes, this.cos, allObjects);
45399
45463
  }
45400
- return serializeCosDocument({
45464
+ return yield* serializeCosDocumentSteps({
45401
45465
  objects: allObjects,
45402
45466
  rootRef: this.cos.rootRef,
45403
45467
  infoRef: this.cos.infoRef,
@@ -45408,6 +45472,9 @@ var init_dist = __esm({
45408
45472
  linearize: options.linearize
45409
45473
  });
45410
45474
  }
45475
+ save(options = {}) {
45476
+ return drainWork(this.saveSteps(options));
45477
+ }
45411
45478
  };
45412
45479
  }
45413
45480
  });
@@ -45520,10 +45587,14 @@ function extractLinks(html) {
45520
45587
  }
45521
45588
  return links;
45522
45589
  }
45523
- function parseHtmlDocumentSync(rawHtml, replacements, signal) {
45590
+ function* parseHtmlDocumentSteps(rawHtml, replacements, signal) {
45591
+ let cooperativeWork = 0;
45524
45592
  let html = rawHtml;
45525
45593
  for (const [key, value] of replacements) {
45526
- if (key) html = html.split(key).join(value);
45594
+ if (++cooperativeWork % 64 === 0)
45595
+ yield;
45596
+ if (key)
45597
+ html = html.split(key).join(value);
45527
45598
  }
45528
45599
  const titleMatch = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);
45529
45600
  const title = titleMatch ? stripTags(titleMatch[1] ?? "") : "";
@@ -45534,8 +45605,11 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
45534
45605
  let match;
45535
45606
  let work = 0;
45536
45607
  while ((match = tokenRegex.exec(bodyHtml)) !== null) {
45608
+ if (++cooperativeWork % 64 === 0)
45609
+ yield;
45537
45610
  signal.throwIfAborted();
45538
- if (++work % 64 === 0) signal.throwIfAborted();
45611
+ if (++work % 64 === 0)
45612
+ signal.throwIfAborted();
45539
45613
  const leadingText = stripTags(bodyHtml.slice(lastIndex, match.index));
45540
45614
  if (leadingText) {
45541
45615
  blocks.push({ kind: "paragraph", text: leadingText, links: extractLinks(bodyHtml.slice(lastIndex, match.index)) });
@@ -45584,8 +45658,11 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
45584
45658
  const liRegex = /<li\b[^>]*>([\s\S]*?)<\/li>/gi;
45585
45659
  let liMatch;
45586
45660
  while ((liMatch = liRegex.exec(inner)) !== null) {
45661
+ if (++cooperativeWork % 64 === 0)
45662
+ yield;
45587
45663
  const itemText = stripTags(liMatch[1] ?? "");
45588
- if (itemText) items.push(itemText);
45664
+ if (itemText)
45665
+ items.push(itemText);
45589
45666
  }
45590
45667
  if (items.length > 0) {
45591
45668
  blocks.push({ kind: "list", ordered: tag === "ol", items });
@@ -45596,6 +45673,8 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
45596
45673
  let m;
45597
45674
  let currentTerm = "";
45598
45675
  while ((m = dtDdRegex.exec(inner)) !== null) {
45676
+ if (++cooperativeWork % 64 === 0)
45677
+ yield;
45599
45678
  const t = m[1].toLowerCase();
45600
45679
  const txt = stripTags(m[2] ?? "");
45601
45680
  if (t === "dt") {
@@ -45617,6 +45696,8 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
45617
45696
  const rectRe = /<rect\b([^>]*)\/?>/gi;
45618
45697
  let rm;
45619
45698
  while ((rm = rectRe.exec(inner)) !== null) {
45699
+ if (++cooperativeWork % 64 === 0)
45700
+ yield;
45620
45701
  const ra = rm[1] ?? "";
45621
45702
  const rx = Number(/\bx=["']?([\d.]+)/i.exec(ra)?.[1] ?? 0);
45622
45703
  const ry = Number(/\by=["']?([\d.]+)/i.exec(ra)?.[1] ?? 0);
@@ -45627,11 +45708,14 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
45627
45708
  const textRe = /<text\b([^>]*)>([\s\S]*?)<\/text>/gi;
45628
45709
  let tm;
45629
45710
  while ((tm = textRe.exec(inner)) !== null) {
45711
+ if (++cooperativeWork % 64 === 0)
45712
+ yield;
45630
45713
  const ta = tm[1] ?? "";
45631
45714
  const tx = Number(/\bx=["']?([\d.]+)/i.exec(ta)?.[1] ?? 8);
45632
45715
  const ty = Number(/\by=["']?([\d.]+)/i.exec(ta)?.[1] ?? 16);
45633
45716
  const txt = stripTags(tm[2] ?? "");
45634
- if (txt) svgPrimitives.push({ kind: "text", x: tx, y: ty, text: txt });
45717
+ if (txt)
45718
+ svgPrimitives.push({ kind: "text", x: tx, y: ty, text: txt });
45635
45719
  }
45636
45720
  blocks.push({ kind: "svg", displayWidth, displayHeight, svgPrimitives });
45637
45721
  } else if (tag === "blockquote") {
@@ -45644,13 +45728,18 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
45644
45728
  const trRegex = /<tr\b[^>]*>([\s\S]*?)<\/tr>/gi;
45645
45729
  let trMatch;
45646
45730
  while ((trMatch = trRegex.exec(inner)) !== null) {
45731
+ if (++cooperativeWork % 64 === 0)
45732
+ yield;
45647
45733
  const rowHtml = trMatch[1] ?? "";
45648
45734
  const cells = [];
45649
45735
  let header = false;
45650
45736
  const cellRegex = /<(th|td)\b([^>]*)>([\s\S]*?)<\/\1>/gi;
45651
45737
  let cellMatch;
45652
45738
  while ((cellMatch = cellRegex.exec(rowHtml)) !== null) {
45653
- if (cellMatch[1]?.toLowerCase() === "th") header = true;
45739
+ if (++cooperativeWork % 64 === 0)
45740
+ yield;
45741
+ if (cellMatch[1]?.toLowerCase() === "th")
45742
+ header = true;
45654
45743
  const cellAttrs = cellMatch[2] ?? "";
45655
45744
  const colspanMatch = /colspan=["']?(\d+)/i.exec(cellAttrs);
45656
45745
  const colspan = Math.max(1, colspanMatch ? Number(colspanMatch[1]) : 1);
@@ -45665,7 +45754,7 @@ function parseHtmlDocumentSync(rawHtml, replacements, signal) {
45665
45754
  }
45666
45755
  } else {
45667
45756
  if (/<(h[1-6]|p|pre|ul|ol|dl|table|svg|hr|img|blockquote|div|section|article)\b/i.test(inner)) {
45668
- const nested = parseHtmlDocumentSync(inner, [], signal);
45757
+ const nested = yield* parseHtmlDocumentSteps(inner, [], signal);
45669
45758
  blocks.push(...nested.blocks);
45670
45759
  } else {
45671
45760
  const text = stripTags(inner);
@@ -45712,7 +45801,8 @@ function rgbColor(r, g, b, grayscale) {
45712
45801
  const lum = Math.round((0.299 * r + 0.587 * g + 0.114 * b) * 1e3) / 1e3;
45713
45802
  return { r: lum, g: lum, b: lum };
45714
45803
  }
45715
- function layoutObjectPagesSync(blocks, box, settings, signal) {
45804
+ function* layoutObjectPagesSteps(blocks, box, settings, signal) {
45805
+ let cooperativeWork = 0;
45716
45806
  const pages = [];
45717
45807
  let currentActions = [];
45718
45808
  const headerReserve = settings.header.left || settings.header.center || settings.header.right ? 24 : 0;
@@ -45733,8 +45823,11 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
45733
45823
  };
45734
45824
  let work = 0;
45735
45825
  for (const block of blocks) {
45826
+ if (++cooperativeWork % 64 === 0)
45827
+ yield;
45736
45828
  signal.throwIfAborted();
45737
- if (++work % 64 === 0) signal.throwIfAborted();
45829
+ if (++work % 64 === 0)
45830
+ signal.throwIfAborted();
45738
45831
  if (block.kind === "pagebreak") {
45739
45832
  flushPage();
45740
45833
  continue;
@@ -45749,6 +45842,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
45749
45842
  cursorY -= 4;
45750
45843
  const blockTopY = cursorY;
45751
45844
  for (const line of lines) {
45845
+ if (++cooperativeWork % 64 === 0)
45846
+ yield;
45752
45847
  const drawY = cursorY - fontSize;
45753
45848
  const x = box.marginLeft;
45754
45849
  currentActions.push((page, _doc, grayscale) => {
@@ -45766,6 +45861,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
45766
45861
  const rectBottom = cursorY;
45767
45862
  const rectTop = blockTopY;
45768
45863
  for (const link of block.links) {
45864
+ if (++cooperativeWork % 64 === 0)
45865
+ yield;
45769
45866
  currentActions.push((page) => {
45770
45867
  page.addLinkAnnotation({
45771
45868
  rect: [box.marginLeft, rectBottom, box.marginLeft + Math.min(contentWidth, 220), rectTop],
@@ -45785,6 +45882,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
45785
45882
  ensureHeight(lines.length * lineHeight + 6);
45786
45883
  const blockTopY = cursorY;
45787
45884
  for (const line of lines) {
45885
+ if (++cooperativeWork % 64 === 0)
45886
+ yield;
45788
45887
  const drawY = cursorY - fontSize;
45789
45888
  const x = box.marginLeft;
45790
45889
  const hasLink = (block.links?.length ?? 0) > 0;
@@ -45803,6 +45902,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
45803
45902
  const rectBottom = cursorY;
45804
45903
  const rectTop = blockTopY;
45805
45904
  for (const link of block.links) {
45905
+ if (++cooperativeWork % 64 === 0)
45906
+ yield;
45806
45907
  currentActions.push((page) => {
45807
45908
  page.addLinkAnnotation({
45808
45909
  rect: [box.marginLeft, rectBottom, box.marginLeft + Math.min(contentWidth, 220), rectTop],
@@ -45835,6 +45936,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
45835
45936
  });
45836
45937
  cursorY -= 6;
45837
45938
  for (const rawLine of rawLines) {
45939
+ if (++cooperativeWork % 64 === 0)
45940
+ yield;
45838
45941
  const drawY = cursorY - fontSize;
45839
45942
  const x = box.marginLeft + 6;
45840
45943
  currentActions.push((page, _doc, grayscale) => {
@@ -45856,10 +45959,14 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
45856
45959
  const lineHeight = 15;
45857
45960
  const items = block.items ?? [];
45858
45961
  for (let idx = 0; idx < items.length; idx++) {
45962
+ if (++cooperativeWork % 64 === 0)
45963
+ yield;
45859
45964
  const prefix = block.ordered ? `${idx + 1}. ` : "\u2022 ";
45860
45965
  const lines = wrapTextLines(prefix + items[idx], Math.max(20, Math.floor((contentWidth - 14) / 5.8)));
45861
45966
  ensureHeight(lines.length * lineHeight + 2);
45862
45967
  for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
45968
+ if (++cooperativeWork % 64 === 0)
45969
+ yield;
45863
45970
  const drawY = cursorY - fontSize;
45864
45971
  const x = box.marginLeft + (lineIdx === 0 ? 10 : 22);
45865
45972
  const lineText = lines[lineIdx];
@@ -45898,6 +46005,8 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
45898
46005
  });
45899
46006
  });
45900
46007
  for (const line of lines) {
46008
+ if (++cooperativeWork % 64 === 0)
46009
+ yield;
45901
46010
  const drawY = cursorY - fontSize;
45902
46011
  const x = box.marginLeft + 14;
45903
46012
  currentActions.push((page, _doc, grayscale) => {
@@ -45949,19 +46058,21 @@ function layoutObjectPagesSync(blocks, box, settings, signal) {
45949
46058
  }
45950
46059
  if (block.kind === "table") {
45951
46060
  const rows = block.rows ?? [];
45952
- const colCount = Math.max(
45953
- 1,
45954
- ...rows.map((r) => r.cells.reduce((sum, c) => sum + c.colspan, 0))
45955
- );
46061
+ const colCount = Math.max(1, ...rows.map((r) => r.cells.reduce((sum, c) => sum + c.colspan, 0)));
45956
46062
  const colWidth = contentWidth / colCount;
45957
46063
  const rowHeight = 20;
45958
46064
  ensureHeight(rows.length * rowHeight + 8);
45959
46065
  for (const row of rows) {
46066
+ if (++cooperativeWork % 64 === 0)
46067
+ yield;
45960
46068
  ensureHeight(rowHeight);
45961
46069
  const rowBottom = cursorY - rowHeight;
45962
46070
  let colCursor = 0;
45963
46071
  for (const cell of row.cells) {
45964
- if (colCursor >= colCount) break;
46072
+ if (++cooperativeWork % 64 === 0)
46073
+ yield;
46074
+ if (colCursor >= colCount)
46075
+ break;
45965
46076
  const span = Math.min(cell.colspan, colCount - colCursor);
45966
46077
  const cellX = box.marginLeft + colCursor * colWidth;
45967
46078
  const cellW = span * colWidth;
@@ -46035,7 +46146,8 @@ function substituteFurnitureTokens(template, tokens) {
46035
46146
  const isoDate = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
46036
46147
  return template.replace(/\[page\]/g, String(tokens.page)).replace(/\[topage\]/g, String(tokens.topage)).replace(/\[webpage\]/g, tokens.webpage).replace(/\[title\]/g, tokens.title).replace(/\[section\]/g, tokens.section ?? tokens.title).replace(/\[subsection\]/g, tokens.subsection ?? "").replace(/\[isodate\]/g, isoDate).replace(/\[date\]/g, isoDate);
46037
46148
  }
46038
- function renderPdfAstSync(request) {
46149
+ function* renderPdfAstSteps(request) {
46150
+ let cooperativeWork = 0;
46039
46151
  request.signal.throwIfAborted();
46040
46152
  const { job, inputs, signal, limits } = request;
46041
46153
  const decoder2 = new TextDecoder("utf-8", { fatal: false, ignoreBOM: true });
@@ -46045,15 +46157,17 @@ function renderPdfAstSync(request) {
46045
46157
  const objectMeta = [];
46046
46158
  let inferredDocumentTitle = job.global.documentTitle;
46047
46159
  for (let i = 0; i < job.objects.length; i++) {
46160
+ if (++cooperativeWork % 64 === 0)
46161
+ yield;
46048
46162
  signal.throwIfAborted();
46049
46163
  const obj = job.objects[i];
46050
46164
  const htmlBytes = inputs[i] ?? new Uint8Array(0);
46051
46165
  const htmlText = decoder2.decode(htmlBytes);
46052
- const parsed = parseHtmlDocumentSync(htmlText, obj.settings.replacements, signal);
46166
+ const parsed = yield* parseHtmlDocumentSteps(htmlText, obj.settings.replacements, signal);
46053
46167
  if (!inferredDocumentTitle && parsed.title) {
46054
46168
  inferredDocumentTitle = parsed.title;
46055
46169
  }
46056
- const pages = layoutObjectPagesSync(parsed.blocks, box, obj.settings, signal);
46170
+ const pages = yield* layoutObjectPagesSteps(parsed.blocks, box, obj.settings, signal);
46057
46171
  laidOutPerObject.push(pages);
46058
46172
  objectMeta.push({
46059
46173
  title: parsed.title || inferredDocumentTitle || "Document",
@@ -46061,23 +46175,20 @@ function renderPdfAstSync(request) {
46061
46175
  settings: obj.settings
46062
46176
  });
46063
46177
  }
46064
- const sequence = planPageSequence(
46065
- laidOutPerObject.map((pages, idx) => ({
46066
- physicalPages: pages.length,
46067
- pagesCount: job.objects[idx].settings.pagesCount
46068
- })),
46069
- {
46070
- copies: job.global.copies,
46071
- collate: job.global.collate,
46072
- pageOffset: job.global.pageOffset,
46073
- limits: {
46074
- maxObjects: limits.parse.maxObjects,
46075
- maxPhysicalPages: Infinity,
46076
- maxWork: limits.resources.maxWork
46077
- },
46078
- signal
46079
- }
46080
- );
46178
+ const sequence = planPageSequence(laidOutPerObject.map((pages, idx) => ({
46179
+ physicalPages: pages.length,
46180
+ pagesCount: job.objects[idx].settings.pagesCount
46181
+ })), {
46182
+ copies: job.global.copies,
46183
+ collate: job.global.collate,
46184
+ pageOffset: job.global.pageOffset,
46185
+ limits: {
46186
+ maxObjects: limits.parse.maxObjects,
46187
+ maxPhysicalPages: Infinity,
46188
+ maxWork: limits.resources.maxWork
46189
+ },
46190
+ signal
46191
+ });
46081
46192
  const doc = PdfDocument.create();
46082
46193
  doc.setMetadata({
46083
46194
  title: inferredDocumentTitle || "Document",
@@ -46085,11 +46196,16 @@ function renderPdfAstSync(request) {
46085
46196
  producer: "@poe-code/pdf-ast"
46086
46197
  });
46087
46198
  for (const outPage of sequence.pages) {
46199
+ yield;
46088
46200
  signal.throwIfAborted();
46089
46201
  const spec = laidOutPerObject[outPage.objectIndex][outPage.pageIndex];
46090
46202
  const meta = objectMeta[outPage.objectIndex];
46091
46203
  const page = doc.addPage({ width: box.width, height: box.height });
46092
- for (const action of spec.actions) action(page, doc, grayscale);
46204
+ for (const action of spec.actions) {
46205
+ if (++cooperativeWork % 64 === 0)
46206
+ yield;
46207
+ action(page, doc, grayscale);
46208
+ }
46093
46209
  const tokens = {
46094
46210
  page: outPage.logicalPage,
46095
46211
  topage: sequence.logicalTotal + job.global.pageOffset,
@@ -46185,8 +46301,7 @@ function createPdfAstRenderer() {
46185
46301
  return Object.freeze({
46186
46302
  profile: pdfAstRendererProfile,
46187
46303
  async open(request) {
46188
- await yieldTurn(request.signal);
46189
- const pdfBytes = renderPdfAstSync(request);
46304
+ const pdfBytes = await drainCooperativeSteps(renderPdfAstSteps(request), request.signal);
46190
46305
  return {
46191
46306
  success: true,
46192
46307
  errorCode: 0,
@@ -46211,6 +46326,12 @@ function pdfAstWkhtmltopdfCommands(options = {}) {
46211
46326
  ...options.replace === void 0 ? {} : { replace: options.replace }
46212
46327
  });
46213
46328
  }
46329
+ function renderPdfAstSync(request) {
46330
+ const steps = renderPdfAstSteps(request);
46331
+ let next = steps.next();
46332
+ while (!next.done) next = steps.next();
46333
+ return next.value;
46334
+ }
46214
46335
  var pdfAstRendererProfile;
46215
46336
  var PAGE_SIZES_PT;
46216
46337
  var pdfAstRenderer;