@poe-platform/safe-bash 0.1.817 → 0.1.818

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 (439) hide show
  1. package/dist/image-ast/index.js +2 -2
  2. package/dist/mp4-ast/index.d.ts +2 -1
  3. package/dist/mp4-ast/mp4-metadata-source.d.ts +10 -0
  4. package/dist/mp4-ast/mp4-packets-source.d.ts +8 -1
  5. package/dist/mp4-ast/types.d.ts +21 -3
  6. package/dist/pdf-ast/ast.d.ts +2 -0
  7. package/dist/pdf-ast/content/evaluator.d.ts +7 -0
  8. package/dist/pdf-ast/content/retained-evaluator.d.ts +2 -2
  9. package/dist/pdf-ast/content/retained-page.d.ts +2 -2
  10. package/dist/pdf-ast/extract/html-text-stream.d.ts +14 -0
  11. package/dist/pdf-ast/extract/logical-text-stream.d.ts +14 -0
  12. package/dist/pdf-ast/extract/raw-text-index.d.ts +18 -4
  13. package/dist/pdf-ast/extract/retained-color.d.ts +6 -6
  14. package/dist/pdf-ast/extract/retained-decoded-image.d.ts +2 -2
  15. package/dist/pdf-ast/extract/stored-text-glyphs.d.ts +8 -0
  16. package/dist/pdf-ast/fonts/retained.d.ts +2 -2
  17. package/dist/pdf-ast/image.d.ts +2 -0
  18. package/dist/pdf-ast/image.js +19 -0
  19. package/dist/pdf-ast/index.d.ts +3 -0
  20. package/dist/pdf-ast/index.js +264 -66852
  21. package/dist/pdf-ast/render/postscript.d.ts +6 -0
  22. package/dist/pdf-ast/render/raster.d.ts +21 -1
  23. package/dist/pdf-ast/retained-document.d.ts +16 -95
  24. package/dist/pdf-ast/retained-reader.d.ts +109 -0
  25. package/dist/safe-bash/command-chunks/biff-AYJZR2YV-JPESBEOO.js +5741 -0
  26. package/dist/safe-bash/command-chunks/{chunk-SL4LD25A.js → chunk-232N24HE.js} +9 -9
  27. package/dist/safe-bash/command-chunks/{chunk-ALD53QFL.js → chunk-2C4QMQQD.js} +42 -12
  28. package/dist/safe-bash/command-chunks/{chunk-3PM46VWH.js → chunk-2FEMMALH.js} +4 -4
  29. package/dist/safe-bash/command-chunks/{chunk-QDV2NIFR.js → chunk-2TMTGVJR.js} +1 -1
  30. package/dist/safe-bash/command-chunks/{chunk-ARE267HR.js → chunk-2WTDP3TP.js} +5 -5
  31. package/dist/safe-bash/command-chunks/{chunk-FSG6UC2N.js → chunk-2XR7B6DY.js} +420 -167
  32. package/dist/safe-bash/command-chunks/{chunk-EY3UE26F.js → chunk-2YC6MWQB.js} +1 -1
  33. package/dist/safe-bash/command-chunks/{chunk-UPWLHHZ2.js → chunk-37KBCKDF.js} +13 -13
  34. package/dist/safe-bash/command-chunks/{chunk-DOVWHVHI.js → chunk-3B6554G6.js} +5 -5
  35. package/dist/safe-bash/command-chunks/{chunk-FB2WPI3M.js → chunk-3ZGO24WG.js} +1 -1
  36. package/dist/safe-bash/command-chunks/{chunk-GR4ONCQ5.js → chunk-424NYO35.js} +7 -7
  37. package/dist/safe-bash/command-chunks/{chunk-MQE77MEQ.js → chunk-45GTHPL5.js} +3 -3
  38. package/dist/safe-bash/command-chunks/{chunk-AF2IO57Q.js → chunk-4OHTYYNU.js} +8 -136
  39. package/dist/safe-bash/command-chunks/{chunk-ICJH6A73.js → chunk-4PMMJ45F.js} +3 -3
  40. package/dist/safe-bash/command-chunks/{chunk-57PK2QFX.js → chunk-4SFX6YGC.js} +6 -6
  41. package/dist/safe-bash/command-chunks/{chunk-G3LUT475.js → chunk-4WHTTCKY.js} +6 -6
  42. package/dist/safe-bash/command-chunks/{chunk-UYZ6EFZE.js → chunk-4Z7PBIMP.js} +6 -6
  43. package/dist/safe-bash/command-chunks/{chunk-A4P37F3P.js → chunk-57SKL76U.js} +3 -3
  44. package/dist/safe-bash/command-chunks/{chunk-J6FNSVHT.js → chunk-5GP4A3TD.js} +5 -5
  45. package/dist/safe-bash/command-chunks/{chunk-OFONWWEZ.js → chunk-5IHJWBDR.js} +2 -2
  46. package/dist/safe-bash/command-chunks/{chunk-A2L3U7DW.js → chunk-5OS4Q3AX.js} +4 -4
  47. package/dist/safe-bash/command-chunks/{chunk-FUYZUETI.js → chunk-5PMLTSQ5.js} +2 -2
  48. package/dist/safe-bash/command-chunks/{chunk-TXU7MMHN.js → chunk-5RDS6CNQ.js} +13 -13
  49. package/dist/safe-bash/command-chunks/{chunk-FR63MJSO.js → chunk-5UGQGB5Y.js} +7 -7
  50. package/dist/safe-bash/command-chunks/{chunk-UKAGRRLZ.js → chunk-5VY5O37W.js} +1 -1
  51. package/dist/safe-bash/command-chunks/chunk-5WS6DXYE.js +68444 -0
  52. package/dist/safe-bash/command-chunks/{chunk-2ALHVXEM.js → chunk-6EK76ERE.js} +2 -2
  53. package/dist/safe-bash/command-chunks/{chunk-4772DJKS.js → chunk-6GCK2KSL.js} +61 -26
  54. package/dist/safe-bash/command-chunks/{chunk-T5OQ53XS.js → chunk-6IID5HTY.js} +1 -1
  55. package/dist/safe-bash/command-chunks/{chunk-EZDWPTYB.js → chunk-6LOAJOWK.js} +13 -13
  56. package/dist/safe-bash/command-chunks/{chunk-WMBELKPP.js → chunk-6PE2L522.js} +6 -6
  57. package/dist/safe-bash/command-chunks/{chunk-ZAYTFXUX.js → chunk-73KY3MZ3.js} +4 -4
  58. package/dist/safe-bash/command-chunks/{chunk-BOVDUJ3A.js → chunk-77WBFVZQ.js} +7 -7
  59. package/dist/safe-bash/command-chunks/{chunk-3DWFXESW.js → chunk-7GJJDM2F.js} +2 -2
  60. package/dist/safe-bash/command-chunks/{chunk-WIW3KDBS.js → chunk-7NFICYRU.js} +2 -2
  61. package/dist/safe-bash/command-chunks/{chunk-35DU6I2M.js → chunk-7ZEGARPB.js} +5 -5
  62. package/dist/safe-bash/command-chunks/{chunk-A5SPMSKD.js → chunk-A32PUWYE.js} +2 -2
  63. package/dist/safe-bash/command-chunks/{chunk-KYIGYYEY.js → chunk-A32ZROH5.js} +3 -3
  64. package/dist/safe-bash/command-chunks/{chunk-IOXMGD2H.js → chunk-ADVQZLLE.js} +2 -2
  65. package/dist/safe-bash/command-chunks/{chunk-CGJ7GMHO.js → chunk-AEZU6NZE.js} +2 -2
  66. package/dist/safe-bash/command-chunks/{chunk-KDDXLHN7.js → chunk-ATHU53C2.js} +3 -3
  67. package/dist/safe-bash/command-chunks/{chunk-R7LF4XQV.js → chunk-B6T2526I.js} +2 -2
  68. package/dist/safe-bash/command-chunks/{chunk-PPN53PX3.js → chunk-BB7HBO56.js} +2 -2
  69. package/dist/safe-bash/command-chunks/{chunk-ZM7HMBAJ.js → chunk-BDGNKRY4.js} +7 -7
  70. package/dist/safe-bash/command-chunks/{chunk-VMZIAFVJ.js → chunk-BFRSYJUC.js} +8 -8
  71. package/dist/safe-bash/command-chunks/{chunk-X42MJT2J.js → chunk-BJL7AGA5.js} +1 -1
  72. package/dist/safe-bash/command-chunks/{chunk-VZTVR3JI.js → chunk-C2QUG7IP.js} +3 -3
  73. package/dist/safe-bash/command-chunks/{chunk-IVKAFEPO.js → chunk-C34RLMAC.js} +9 -9
  74. package/dist/safe-bash/command-chunks/{chunk-5O45KGW5.js → chunk-C5VUJOUQ.js} +1 -1
  75. package/dist/safe-bash/command-chunks/{chunk-LQDANF2B.js → chunk-CCNOZKAK.js} +8 -8
  76. package/dist/safe-bash/command-chunks/{chunk-FEBTT5NH.js → chunk-CEHICGP6.js} +2 -2
  77. package/dist/safe-bash/command-chunks/{chunk-SICTBSLW.js → chunk-CODJMTSA.js} +6 -6
  78. package/dist/safe-bash/command-chunks/{chunk-LJ3UYESS.js → chunk-CP5EO5TT.js} +1 -1
  79. package/dist/safe-bash/command-chunks/{chunk-45DKGZYO.js → chunk-CSS5KXQC.js} +329 -152
  80. package/dist/safe-bash/command-chunks/{chunk-6RLWPB44.js → chunk-CZSLXQU2.js} +1 -1
  81. package/dist/safe-bash/command-chunks/{chunk-3ZWFE4CK.js → chunk-D2ZT2UUT.js} +3 -3
  82. package/dist/safe-bash/command-chunks/{chunk-WH624PKJ.js → chunk-D5XSGHXN.js} +2 -2
  83. package/dist/safe-bash/command-chunks/{chunk-NDALIHKK.js → chunk-D7UFAIBS.js} +18 -18
  84. package/dist/safe-bash/command-chunks/{chunk-ISFGPCED.js → chunk-DCKAY6HV.js} +6 -6
  85. package/dist/safe-bash/command-chunks/{chunk-LNAZ3E4Q.js → chunk-DGCJVZW6.js} +1 -1
  86. package/dist/safe-bash/command-chunks/{chunk-LFSWLJPR.js → chunk-DJB5RB6U.js} +288 -32
  87. package/dist/safe-bash/command-chunks/{chunk-FGHSE3RZ.js → chunk-DZ4ELL34.js} +1 -1
  88. package/dist/safe-bash/command-chunks/{chunk-LQX7RAF7.js → chunk-EBKKYRQJ.js} +5 -5
  89. package/dist/safe-bash/command-chunks/{chunk-QNETPOMH.js → chunk-EDBNI7WE.js} +14 -14
  90. package/dist/safe-bash/command-chunks/{chunk-5GDF5FAS.js → chunk-EEJ3YXVO.js} +1 -1
  91. package/dist/safe-bash/command-chunks/{chunk-RTHYAGKI.js → chunk-ETN25WCR.js} +2 -2
  92. package/dist/safe-bash/command-chunks/{chunk-ET6LMDEX.js → chunk-EV3DPRWE.js} +9 -9
  93. package/dist/safe-bash/command-chunks/{chunk-3MUFXGA2.js → chunk-F2JUB7JI.js} +1 -1
  94. package/dist/safe-bash/command-chunks/{chunk-345YBIHP.js → chunk-F42WV2YO.js} +19 -19
  95. package/dist/safe-bash/command-chunks/{chunk-FTZFCMVI.js → chunk-FAVWWMFW.js} +12 -12
  96. package/dist/safe-bash/command-chunks/{chunk-XBWD6SI3.js → chunk-FDRE535F.js} +16 -16
  97. package/dist/safe-bash/command-chunks/{chunk-WMV5224N.js → chunk-FILE5PBI.js} +3 -3
  98. package/dist/safe-bash/command-chunks/{chunk-XPQUUFQD.js → chunk-FPOM47UA.js} +2 -2
  99. package/dist/safe-bash/command-chunks/{chunk-QMBMZSJF.js → chunk-FQ2WRT4Q.js} +3 -3
  100. package/dist/safe-bash/command-chunks/{chunk-H56BSMFQ.js → chunk-FVAFISPY.js} +4 -4
  101. package/dist/safe-bash/command-chunks/{chunk-2QZUAZTH.js → chunk-GIQUIF6E.js} +1 -1
  102. package/dist/safe-bash/command-chunks/{chunk-2TWXRJPB.js → chunk-GNORF6RY.js} +13 -13
  103. package/dist/safe-bash/command-chunks/{chunk-ABL2DPJI.js → chunk-GPLN6JV2.js} +12 -12
  104. package/dist/safe-bash/command-chunks/{chunk-DZOKH5BL.js → chunk-GQ7BD75U.js} +3 -3
  105. package/dist/safe-bash/command-chunks/{chunk-N4HWOLGZ.js → chunk-GY2C555A.js} +2 -2
  106. package/dist/safe-bash/command-chunks/{chunk-N32AP43V.js → chunk-GZNX5SS4.js} +7 -7
  107. package/dist/safe-bash/command-chunks/{chunk-YPG55QTP.js → chunk-HCJWEB6P.js} +1 -1
  108. package/dist/safe-bash/command-chunks/{chunk-4ABR3KGK.js → chunk-HNY7LZ5P.js} +3 -3
  109. package/dist/safe-bash/command-chunks/{chunk-P462JTNT.js → chunk-HOBXZX23.js} +5 -5
  110. package/dist/safe-bash/command-chunks/{chunk-5KZMR6AJ.js → chunk-HW3IOXT6.js} +6 -6
  111. package/dist/safe-bash/command-chunks/{chunk-3VGQTLO6.js → chunk-HX7QQNWS.js} +4 -4
  112. package/dist/safe-bash/command-chunks/{chunk-TXWDR2P4.js → chunk-IBT3OWXB.js} +1 -1
  113. package/dist/safe-bash/command-chunks/{chunk-OHEZQ4QA.js → chunk-IFBLXBBM.js} +9 -9
  114. package/dist/safe-bash/command-chunks/{chunk-HOJ7WDTS.js → chunk-IJZUUXLL.js} +3 -3
  115. package/dist/safe-bash/command-chunks/{chunk-BZRWZ6GO.js → chunk-IKU7ZBF3.js} +2 -2
  116. package/dist/safe-bash/command-chunks/{chunk-CKIXC7AO.js → chunk-IPKYPADE.js} +3 -3
  117. package/dist/safe-bash/command-chunks/{chunk-IWVANZWH.js → chunk-JLPBGKVC.js} +3 -3
  118. package/dist/safe-bash/command-chunks/{chunk-6M3JTPKE.js → chunk-JNRX5EFF.js} +5 -5
  119. package/dist/safe-bash/command-chunks/{chunk-5YL453ZF.js → chunk-JSX5CFZY.js} +36 -36
  120. package/dist/safe-bash/command-chunks/{chunk-V6JPIZUW.js → chunk-JT656DKZ.js} +7 -7
  121. package/dist/safe-bash/command-chunks/{chunk-DM5WURQL.js → chunk-JY2T3KV2.js} +2 -2
  122. package/dist/safe-bash/command-chunks/{chunk-IZ3SD5S2.js → chunk-K2NV6H7E.js} +4 -4
  123. package/dist/safe-bash/command-chunks/{chunk-62RG3GHF.js → chunk-K6E56LND.js} +6 -6
  124. package/dist/safe-bash/command-chunks/{chunk-FLSXHLJG.js → chunk-KADQKXZE.js} +9 -9
  125. package/dist/safe-bash/command-chunks/{chunk-URQSUMMJ.js → chunk-KFFV7HBL.js} +4 -4
  126. package/dist/safe-bash/command-chunks/{chunk-ONQP4FNV.js → chunk-KZICRCQ7.js} +1 -1
  127. package/dist/safe-bash/command-chunks/{chunk-N35IJXBK.js → chunk-L6X4EEN6.js} +9 -9
  128. package/dist/safe-bash/command-chunks/{chunk-SHLT5R64.js → chunk-LF7YJ5VQ.js} +9 -9
  129. package/dist/safe-bash/command-chunks/{chunk-GMBUOYTN.js → chunk-LNHTLWIL.js} +4 -4
  130. package/dist/safe-bash/command-chunks/{chunk-A6OTPNNI.js → chunk-LPKMNCC5.js} +3 -3
  131. package/dist/safe-bash/command-chunks/{chunk-MUTARE5I.js → chunk-LSKA4IR4.js} +6 -6
  132. package/dist/safe-bash/command-chunks/{chunk-N3ZH4YYH.js → chunk-LTWX23FS.js} +3 -3
  133. package/dist/safe-bash/command-chunks/{chunk-JA36YOZI.js → chunk-LUJUYUOG.js} +1 -1
  134. package/dist/safe-bash/command-chunks/{chunk-4X2MPZXW.js → chunk-M42GCI5F.js} +2 -2
  135. package/dist/safe-bash/command-chunks/{chunk-AYQPJQJR.js → chunk-M5BFAMXD.js} +6 -6
  136. package/dist/safe-bash/command-chunks/{chunk-OFDJJRAD.js → chunk-M7DZ7COK.js} +9 -9
  137. package/dist/safe-bash/command-chunks/{chunk-E64ZI2YB.js → chunk-MMSKDYK6.js} +224 -115
  138. package/dist/safe-bash/command-chunks/{chunk-NKK76B4V.js → chunk-MN7EEK6Y.js} +8 -8
  139. package/dist/safe-bash/command-chunks/{chunk-OBIXFO25.js → chunk-MOJQT6RW.js} +8 -8
  140. package/dist/safe-bash/command-chunks/{chunk-HOKPYTHQ.js → chunk-MPRUGL4W.js} +2 -2
  141. package/dist/safe-bash/command-chunks/{chunk-CORUUCS2.js → chunk-MRBX4KEP.js} +3 -3
  142. package/dist/safe-bash/command-chunks/chunk-MTWFSBNG.js +137 -0
  143. package/dist/safe-bash/command-chunks/{chunk-RRAQII52.js → chunk-MURNTGDL.js} +5 -5
  144. package/dist/safe-bash/command-chunks/{chunk-KDBU5Q2N.js → chunk-MWVELMXZ.js} +6 -6
  145. package/dist/safe-bash/command-chunks/{chunk-PRO7JOIH.js → chunk-N3MAYM6Y.js} +8 -8
  146. package/dist/safe-bash/command-chunks/{chunk-E22EAYJN.js → chunk-NFWLZDMY.js} +177 -34
  147. package/dist/safe-bash/command-chunks/{chunk-GAROGIVU.js → chunk-NP2QXF2X.js} +1 -1
  148. package/dist/safe-bash/command-chunks/{chunk-SNA2LVBX.js → chunk-NPVOYY2A.js} +1 -1
  149. package/dist/safe-bash/command-chunks/{chunk-ENMJHB2C.js → chunk-NTXRKJPZ.js} +3 -3
  150. package/dist/safe-bash/command-chunks/{chunk-3K5CVXUV.js → chunk-NZF56C25.js} +10 -10
  151. package/dist/safe-bash/command-chunks/{chunk-5MNQTHED.js → chunk-OA4MEWTN.js} +4 -4
  152. package/dist/safe-bash/command-chunks/{chunk-SWIF6BBY.js → chunk-OL75SBZL.js} +5 -5
  153. package/dist/safe-bash/command-chunks/{chunk-LT2YCGC5.js → chunk-OVQSILY3.js} +5 -5
  154. package/dist/safe-bash/command-chunks/{chunk-WDVPHDBH.js → chunk-P57V45F2.js} +2 -2
  155. package/dist/safe-bash/command-chunks/{chunk-OWCBX5M2.js → chunk-PAY4ULWY.js} +1 -1
  156. package/dist/safe-bash/command-chunks/{chunk-CHZE6FNT.js → chunk-PFUZPAXQ.js} +2 -2
  157. package/dist/safe-bash/command-chunks/{chunk-NLCUQD7Y.js → chunk-PX6E5MHY.js} +9 -9
  158. package/dist/safe-bash/command-chunks/{chunk-POGVOCOB.js → chunk-QCN7MRRU.js} +8 -8
  159. package/dist/safe-bash/command-chunks/{chunk-ZZERSKAR.js → chunk-QLE6JUR7.js} +5 -5
  160. package/dist/safe-bash/command-chunks/{chunk-LZY46GYY.js → chunk-QMWBKR4C.js} +5 -5
  161. package/dist/safe-bash/command-chunks/{chunk-BIJW6QWB.js → chunk-QNLX3CZH.js} +13 -13
  162. package/dist/safe-bash/command-chunks/{chunk-MDFNUNK5.js → chunk-QWX5IERU.js} +6 -6
  163. package/dist/safe-bash/command-chunks/{chunk-WOL3LBXE.js → chunk-R2N3E267.js} +1 -1
  164. package/dist/safe-bash/command-chunks/{chunk-ZNCPIZCN.js → chunk-R6X63VAO.js} +1 -1
  165. package/dist/safe-bash/command-chunks/{chunk-FGARVKAX.js → chunk-RNIFPFGC.js} +13 -11
  166. package/dist/safe-bash/command-chunks/{chunk-OIHQXURE.js → chunk-ROE6KD4C.js} +1 -1
  167. package/dist/safe-bash/command-chunks/{chunk-BKK4MS3V.js → chunk-RR6XG2I6.js} +1 -1
  168. package/dist/safe-bash/command-chunks/{chunk-ZHHALBM7.js → chunk-RYOHOS2I.js} +4 -4
  169. package/dist/safe-bash/command-chunks/{chunk-U42WHQRH.js → chunk-TTTNFKT6.js} +5 -5
  170. package/dist/safe-bash/command-chunks/{chunk-EWC56JNI.js → chunk-TTVJJZOM.js} +5 -5
  171. package/dist/safe-bash/command-chunks/{chunk-TY7JXEWI.js → chunk-UBX5I5HY.js} +11 -11
  172. package/dist/safe-bash/command-chunks/{chunk-QOKFSYD5.js → chunk-UE34SQET.js} +9 -9
  173. package/dist/safe-bash/command-chunks/{chunk-DXOXUKQB.js → chunk-UH4CQIU3.js} +4 -4
  174. package/dist/safe-bash/command-chunks/{chunk-VNNNVT4C.js → chunk-UZZ2WJQV.js} +4 -4
  175. package/dist/safe-bash/command-chunks/{chunk-QNX5LZBK.js → chunk-V6NZVM7C.js} +7 -7
  176. package/dist/safe-bash/command-chunks/{chunk-KLAC2MIZ.js → chunk-VEZULAIA.js} +6 -6
  177. package/dist/safe-bash/command-chunks/{chunk-OCV5ZU35.js → chunk-VSTAHYCV.js} +3 -3
  178. package/dist/safe-bash/command-chunks/{chunk-UFLMOU3B.js → chunk-VUJCVXD4.js} +1 -1
  179. package/dist/safe-bash/command-chunks/{chunk-5V7WIQ2D.js → chunk-VW67MA53.js} +3 -3
  180. package/dist/safe-bash/command-chunks/{chunk-2IMIKROX.js → chunk-WI5NEHPD.js} +2 -2
  181. package/dist/safe-bash/command-chunks/{chunk-SBXS4S6Y.js → chunk-WJSU2UVG.js} +2 -2
  182. package/dist/safe-bash/command-chunks/{chunk-VVWHFNHD.js → chunk-WPEIOUJN.js} +415 -25
  183. package/dist/safe-bash/command-chunks/{chunk-YKODRSGT.js → chunk-WRCYZJNO.js} +1 -1
  184. package/dist/safe-bash/command-chunks/{chunk-TID5TSQW.js → chunk-WRJV7OVO.js} +1 -1
  185. package/dist/safe-bash/command-chunks/{chunk-T4SEQU66.js → chunk-X4TWJNW7.js} +3 -3
  186. package/dist/safe-bash/command-chunks/{chunk-CKA7ZROU.js → chunk-X6KFCAWZ.js} +7 -7
  187. package/dist/safe-bash/command-chunks/{chunk-ROQ3VNVX.js → chunk-X6KO7D6R.js} +8 -8
  188. package/dist/safe-bash/command-chunks/{chunk-S5ER73EA.js → chunk-XB5ZZHFD.js} +3 -3
  189. package/dist/safe-bash/command-chunks/{chunk-FHQOFEQK.js → chunk-XLFOLLUZ.js} +8 -8
  190. package/dist/safe-bash/command-chunks/{chunk-UJYXSLM6.js → chunk-XLPEPCQC.js} +2 -2
  191. package/dist/safe-bash/command-chunks/{chunk-UT5X6QRU.js → chunk-XQFEP43Y.js} +5 -5
  192. package/dist/safe-bash/command-chunks/chunk-Y7XL6CWB.js +771 -0
  193. package/dist/safe-bash/command-chunks/{chunk-RVWIEXR7.js → chunk-YKEMSPJZ.js} +4 -4
  194. package/dist/safe-bash/command-chunks/{chunk-ERWIJYCS.js → chunk-YN3OEJAZ.js} +7 -7
  195. package/dist/safe-bash/command-chunks/{chunk-6YF2QADH.js → chunk-YOYK2I4N.js} +2 -2
  196. package/dist/safe-bash/command-chunks/{chunk-26JE5JEB.js → chunk-YS5ZKMRJ.js} +4 -4
  197. package/dist/safe-bash/command-chunks/{chunk-LMLBQSAM.js → chunk-YW7WU7W2.js} +5 -5
  198. package/dist/safe-bash/command-chunks/{chunk-YXR4JE4U.js → chunk-Z33YS3DW.js} +3 -3
  199. package/dist/safe-bash/command-chunks/{chunk-T2FRXSQT.js → chunk-ZBXUAM34.js} +2 -2
  200. package/dist/safe-bash/command-chunks/{chunk-VVV45NLY.js → chunk-ZJUU5IAS.js} +1 -1
  201. package/dist/safe-bash/command-chunks/{chunk-7OCTMVYJ.js → chunk-ZNABMTV3.js} +1 -1
  202. package/dist/safe-bash/command-chunks/{chunk-6JGICYHP.js → chunk-ZSF2T5D4.js} +1 -1
  203. package/dist/safe-bash/command-chunks/{command-engine-2QXVRRH3.js → command-engine-PFYHL7GS.js} +10 -4
  204. package/dist/safe-bash/command-chunks/{engine-T4GP6QOK-ECFKMR5V.js → engine-5AVSKFBI-D7Q5VPUN.js} +1 -1
  205. package/dist/safe-bash/command-chunks/model-store-IIWQHSEZ.js +54 -0
  206. package/dist/safe-bash-command-awk/awk-inspection.js +2 -2
  207. package/dist/safe-bash-command-awk/awk.js +5 -5
  208. package/dist/safe-bash-command-awk/index.js +5 -5
  209. package/dist/safe-bash-command-cp/index.js +4 -4
  210. package/dist/safe-bash-command-diff/diff.js +2 -2
  211. package/dist/safe-bash-command-diff/index.js +2 -2
  212. package/dist/safe-bash-command-ffmpeg/index.js +1 -1
  213. package/dist/safe-bash-command-ffprobe/index.js +2 -2
  214. package/dist/safe-bash-command-ffprobe/media.js +2 -2
  215. package/dist/safe-bash-command-node/commands/node/browser.js +6 -6
  216. package/dist/safe-bash-command-node/commands/node/default-runtime.js +6 -6
  217. package/dist/safe-bash-command-node/commands/node/filesystem.js +2 -2
  218. package/dist/safe-bash-command-node/commands/node/safejs.js +6 -6
  219. package/dist/safe-bash-command-node/commands/node/timers.js +2 -2
  220. package/dist/safe-bash-command-patch/index.js +3 -3
  221. package/dist/safe-bash-command-patch/patch-formats.js +2 -2
  222. package/dist/safe-bash-command-patch/patch.js +3 -3
  223. package/dist/safe-bash-command-patch/unified.js +1 -1
  224. package/dist/safe-bash-command-pdftoppm/index.js +89 -124
  225. package/dist/safe-bash-command-pdftotext/index.d.ts +1 -1
  226. package/dist/safe-bash-command-pdftotext/index.js +538 -379
  227. package/dist/safe-bash-command-playwright-cli/index.js +19 -19
  228. package/dist/safe-bash-command-playwright-cli/playwright/abilities.js +6 -6
  229. package/dist/safe-bash-command-playwright-cli/playwright/adapter.js +3 -3
  230. package/dist/safe-bash-command-playwright-cli/playwright/controller.js +13 -13
  231. package/dist/safe-bash-command-playwright-cli/playwright/index.js +19 -19
  232. package/dist/safe-bash-command-playwright-cli/playwright/native-storage-replacement.js +2 -2
  233. package/dist/safe-bash-command-playwright-cli/playwright/open-options.js +2 -2
  234. package/dist/safe-bash-command-playwright-cli/playwright/profile.js +5 -5
  235. package/dist/safe-bash-command-playwright-cli/playwright/standard-capabilities.js +4 -4
  236. package/dist/safe-bash-command-playwright-cli/playwright/storage-capabilities.js +3 -3
  237. package/dist/safe-bash-command-pptx/engine.js +1 -1
  238. package/dist/safe-bash-command-python/executor.js +10 -10
  239. package/dist/safe-bash-command-python/index.js +10 -10
  240. package/dist/safe-bash-command-python/jspi.js +2 -2
  241. package/dist/safe-bash-command-safejs/index.js +2 -2
  242. package/dist/safe-bash-command-safejs/runtime.js +2 -2
  243. package/dist/safe-bash-command-ssconvert/index.js +13 -13
  244. package/dist/safe-bash-command-unzip/index.js +4 -4
  245. package/dist/safe-bash-docx-engine/ancillary-resources.js +10 -10
  246. package/dist/safe-bash-docx-engine/batch-operations.js +67 -67
  247. package/dist/safe-bash-docx-engine/batch-result-schema.js +79 -79
  248. package/dist/safe-bash-docx-engine/batch.js +78 -78
  249. package/dist/safe-bash-docx-engine/bookmarks.js +18 -18
  250. package/dist/safe-bash-docx-engine/charts.js +11 -11
  251. package/dist/safe-bash-docx-engine/command-option-rules.js +6 -6
  252. package/dist/safe-bash-docx-engine/command-properties.js +3 -3
  253. package/dist/safe-bash-docx-engine/comments.js +26 -26
  254. package/dist/safe-bash-docx-engine/control-bindings.js +21 -21
  255. package/dist/safe-bash-docx-engine/control-repeat.js +21 -21
  256. package/dist/safe-bash-docx-engine/controls.js +19 -19
  257. package/dist/safe-bash-docx-engine/create.js +11 -11
  258. package/dist/safe-bash-docx-engine/diagrams.js +11 -11
  259. package/dist/safe-bash-docx-engine/diff.js +13 -13
  260. package/dist/safe-bash-docx-engine/document-properties.js +16 -16
  261. package/dist/safe-bash-docx-engine/equations.js +17 -17
  262. package/dist/safe-bash-docx-engine/extract.js +14 -14
  263. package/dist/safe-bash-docx-engine/fields.js +23 -23
  264. package/dist/safe-bash-docx-engine/font-inventory.js +18 -18
  265. package/dist/safe-bash-docx-engine/font-resources.js +6 -6
  266. package/dist/safe-bash-docx-engine/image-batch-operations.js +14 -14
  267. package/dist/safe-bash-docx-engine/image-insertion.js +21 -21
  268. package/dist/safe-bash-docx-engine/image-layout.js +19 -19
  269. package/dist/safe-bash-docx-engine/image-replacement.js +22 -22
  270. package/dist/safe-bash-docx-engine/images.js +19 -19
  271. package/dist/safe-bash-docx-engine/index.js +111 -111
  272. package/dist/safe-bash-docx-engine/inspection.js +20 -20
  273. package/dist/safe-bash-docx-engine/invocation.js +9 -9
  274. package/dist/safe-bash-docx-engine/io.js +9 -9
  275. package/dist/safe-bash-docx-engine/links.js +21 -21
  276. package/dist/safe-bash-docx-engine/lists.js +20 -20
  277. package/dist/safe-bash-docx-engine/locations.js +15 -15
  278. package/dist/safe-bash-docx-engine/notes.js +22 -22
  279. package/dist/safe-bash-docx-engine/objects.js +19 -19
  280. package/dist/safe-bash-docx-engine/operation-json-schema.js +3 -3
  281. package/dist/safe-bash-docx-engine/operation-schema.js +2 -2
  282. package/dist/safe-bash-docx-engine/pack.js +14 -14
  283. package/dist/safe-bash-docx-engine/package-view-batch-operations.js +22 -22
  284. package/dist/safe-bash-docx-engine/pandoc-adapter.js +29 -29
  285. package/dist/safe-bash-docx-engine/paragraph-edit.js +25 -25
  286. package/dist/safe-bash-docx-engine/part-provider.js +3 -3
  287. package/dist/safe-bash-docx-engine/property-values.js +3 -3
  288. package/dist/safe-bash-docx-engine/publication.js +9 -9
  289. package/dist/safe-bash-docx-engine/removal.js +21 -21
  290. package/dist/safe-bash-docx-engine/revision-decisions.js +22 -22
  291. package/dist/safe-bash-docx-engine/revision-edit.js +20 -20
  292. package/dist/safe-bash-docx-engine/revisions.js +18 -18
  293. package/dist/safe-bash-docx-engine/run-format.js +20 -20
  294. package/dist/safe-bash-docx-engine/sanitize.js +34 -34
  295. package/dist/safe-bash-docx-engine/sections.js +19 -19
  296. package/dist/safe-bash-docx-engine/settings.js +11 -11
  297. package/dist/safe-bash-docx-engine/shape-edit.js +21 -21
  298. package/dist/safe-bash-docx-engine/signatures.js +15 -15
  299. package/dist/safe-bash-docx-engine/stories.js +22 -22
  300. package/dist/safe-bash-docx-engine/structure-model-batch-operations.js +38 -38
  301. package/dist/safe-bash-docx-engine/style-model-batch-operations.js +27 -27
  302. package/dist/safe-bash-docx-engine/style-model-result-schema.js +44 -44
  303. package/dist/safe-bash-docx-engine/styles.js +18 -18
  304. package/dist/safe-bash-docx-engine/table-edit.js +27 -27
  305. package/dist/safe-bash-docx-engine/table-read.js +16 -16
  306. package/dist/safe-bash-docx-engine/template.js +22 -22
  307. package/dist/safe-bash-docx-engine/text-replace.js +20 -20
  308. package/dist/safe-bash-docx-engine/text-resource-read.js +16 -16
  309. package/dist/safe-bash-docx-engine/text.js +16 -16
  310. package/dist/safe-bash-docx-engine/validation.js +7 -7
  311. package/dist/safe-bash-docx-engine/xml-parts.js +22 -22
  312. package/dist/safe-bash-network-engine/index.js +4 -4
  313. package/dist/safe-bash-network-engine/transfer.js +12 -12
  314. package/dist/safe-bash-presentation-engine/accessibility.js +15 -15
  315. package/dist/safe-bash-presentation-engine/animation-editing.js +5 -5
  316. package/dist/safe-bash-presentation-engine/animations.js +5 -5
  317. package/dist/safe-bash-presentation-engine/backgrounds.js +6 -6
  318. package/dist/safe-bash-presentation-engine/chart-editing.js +18 -18
  319. package/dist/safe-bash-presentation-engine/chart-object-operations.js +12 -12
  320. package/dist/safe-bash-presentation-engine/charts.js +15 -15
  321. package/dist/safe-bash-presentation-engine/command-placeholder.js +39 -38
  322. package/dist/safe-bash-presentation-engine/comments.js +6 -6
  323. package/dist/safe-bash-presentation-engine/connector-operations.js +16 -16
  324. package/dist/safe-bash-presentation-engine/connectors.js +13 -13
  325. package/dist/safe-bash-presentation-engine/diff.js +21 -20
  326. package/dist/safe-bash-presentation-engine/drawing-format.js +7 -7
  327. package/dist/safe-bash-presentation-engine/drawing-operations.js +15 -15
  328. package/dist/safe-bash-presentation-engine/drawing-schema.js +8 -8
  329. package/dist/safe-bash-presentation-engine/equations.js +6 -6
  330. package/dist/safe-bash-presentation-engine/fields.js +6 -6
  331. package/dist/safe-bash-presentation-engine/image-extraction.js +7 -7
  332. package/dist/safe-bash-presentation-engine/image-formatting.js +16 -16
  333. package/dist/safe-bash-presentation-engine/image-insertion.js +6 -6
  334. package/dist/safe-bash-presentation-engine/image-replacement.js +7 -7
  335. package/dist/safe-bash-presentation-engine/images.js +6 -6
  336. package/dist/safe-bash-presentation-engine/index.js +96 -95
  337. package/dist/safe-bash-presentation-engine/layouts.js +5 -5
  338. package/dist/safe-bash-presentation-engine/links.js +5 -5
  339. package/dist/safe-bash-presentation-engine/masters.js +4 -4
  340. package/dist/safe-bash-presentation-engine/media-editing.js +10 -10
  341. package/dist/safe-bash-presentation-engine/media-extraction.js +6 -6
  342. package/dist/safe-bash-presentation-engine/media.js +5 -5
  343. package/dist/safe-bash-presentation-engine/memberships.d.ts +1 -0
  344. package/dist/safe-bash-presentation-engine/memberships.js +12 -6
  345. package/dist/safe-bash-presentation-engine/notes.js +6 -6
  346. package/dist/safe-bash-presentation-engine/ole-insertion.js +6 -6
  347. package/dist/safe-bash-presentation-engine/opaque-objects.js +2 -2
  348. package/dist/safe-bash-presentation-engine/package-tools.js +6 -6
  349. package/dist/safe-bash-presentation-engine/presentation-model.js +38 -37
  350. package/dist/safe-bash-presentation-engine/presentation-settings.d.ts +1 -0
  351. package/dist/safe-bash-presentation-engine/presentation-settings.js +12 -5
  352. package/dist/safe-bash-presentation-engine/properties.js +7 -6
  353. package/dist/safe-bash-presentation-engine/retained-inspection.js +3 -3
  354. package/dist/safe-bash-presentation-engine/retained-memberships.d.ts +25 -0
  355. package/dist/safe-bash-presentation-engine/retained-presentation-settings.d.ts +25 -0
  356. package/dist/safe-bash-presentation-engine/retained-text.d.ts +24 -4
  357. package/dist/safe-bash-presentation-engine/retained-text.js +17 -15
  358. package/dist/safe-bash-presentation-engine/sanitize.js +8 -7
  359. package/dist/safe-bash-presentation-engine/selectors.js +2 -2
  360. package/dist/safe-bash-presentation-engine/shape-groups.js +15 -15
  361. package/dist/safe-bash-presentation-engine/shape-operations.js +14 -14
  362. package/dist/safe-bash-presentation-engine/shape-path-operations.js +16 -16
  363. package/dist/safe-bash-presentation-engine/shape-paths.js +5 -5
  364. package/dist/safe-bash-presentation-engine/shape-selection.js +15 -15
  365. package/dist/safe-bash-presentation-engine/shape-transforms.js +5 -5
  366. package/dist/safe-bash-presentation-engine/shapes.js +11 -11
  367. package/dist/safe-bash-presentation-engine/slide-copy.js +7 -5
  368. package/dist/safe-bash-presentation-engine/slide-import.js +6 -6
  369. package/dist/safe-bash-presentation-engine/slide-merge-split.js +8 -8
  370. package/dist/safe-bash-presentation-engine/slide-model.js +24 -24
  371. package/dist/safe-bash-presentation-engine/slide-removal.js +7 -7
  372. package/dist/safe-bash-presentation-engine/slide-transfer-budget.js +2 -2
  373. package/dist/safe-bash-presentation-engine/slides.js +5 -5
  374. package/dist/safe-bash-presentation-engine/table-operations.js +17 -17
  375. package/dist/safe-bash-presentation-engine/table-spans.js +16 -16
  376. package/dist/safe-bash-presentation-engine/tables.js +15 -15
  377. package/dist/safe-bash-presentation-engine/tags.js +6 -6
  378. package/dist/safe-bash-presentation-engine/template-bindings.js +16 -16
  379. package/dist/safe-bash-presentation-engine/template-repeat.js +24 -22
  380. package/dist/safe-bash-presentation-engine/text-fitting.js +11 -11
  381. package/dist/safe-bash-presentation-engine/text-frames.js +11 -11
  382. package/dist/safe-bash-presentation-engine/text-paragraphs.js +11 -11
  383. package/dist/safe-bash-presentation-engine/text-reading.js +3 -3
  384. package/dist/safe-bash-presentation-engine/text-replacement.js +6 -6
  385. package/dist/safe-bash-presentation-engine/text-runs.js +8 -8
  386. package/dist/safe-bash-presentation-engine/themes.js +5 -5
  387. package/dist/safe-bash-presentation-engine/transitions.js +5 -5
  388. package/dist/safe-bash-presentation-engine/validation.js +2 -2
  389. package/dist/safe-bash-presentation-engine/xml-parts.js +5 -5
  390. package/dist/safe-bash-xml-engine/document.js +2 -2
  391. package/dist/safe-bash-xml-engine/index.js +2 -2
  392. package/dist/safe-bash-xml-engine/recovery.d.ts +6 -2
  393. package/dist/safe-bash-xml-engine/stored-document.d.ts +2 -1
  394. package/dist/safe-bash-xml-engine/stored-document.js +1 -1
  395. package/dist/safe-bash-xml-engine/{stored-namespaces.d.ts → stored-map.d.ts} +6 -6
  396. package/dist/safe-bash-zip-engine/index.js +3 -3
  397. package/dist/safe-bash-zip-engine/zip/repair.js +3 -3
  398. package/dist/safe-bash-zip-engine/zip/sfx.js +3 -3
  399. package/dist/safe-bash-zip-engine/zip-format.js +3 -3
  400. package/dist/spreadsheet-engine/formatting/cell-text.js +1 -1
  401. package/dist/spreadsheet-engine/{rendering/print → formatting}/general-number.js +3 -3
  402. package/dist/spreadsheet-engine/formulas/functions/python-printf.js +9 -7
  403. package/dist/spreadsheet-engine/solver/program.js +3 -2
  404. package/dist/spreadsheet-engine/solver/run.js +8 -2
  405. package/dist/spreadsheet-engine/solver/sensitivity.d.ts +4 -2
  406. package/dist/spreadsheet-engine/solver/sensitivity.js +80 -42
  407. package/dist/spreadsheet-format-xls/biff-properties-merge.d.ts +2 -1
  408. package/dist/spreadsheet-format-xls/biff-properties-merge.js +35 -29
  409. package/dist/spreadsheet-format-xls/biff-properties-write.js +16 -7
  410. package/dist/spreadsheet-format-xls/biff-property-names.d.ts +3 -0
  411. package/dist/spreadsheet-format-xls/biff-property-names.js +44 -1
  412. package/dist/spreadsheet-format-xls/biff-property-observations.d.ts +33 -0
  413. package/dist/spreadsheet-format-xls/biff-property-observations.js +160 -0
  414. package/package.json +6 -4
  415. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +15 -0
  416. package/third-party/pdf-ast/licenses/PYTHON-PSF.txt +254 -0
  417. package/third-party/pdf-ast/licenses/V8-BSD.txt +61 -0
  418. package/dist/safe-bash/command-chunks/biff-KLS4T7FP-UO3CXFFF.js +0 -5581
  419. package/dist/safe-bash/command-chunks/chunk-6EZWG56T.js +0 -455
  420. package/dist/safe-bash/command-chunks/model-store-I7YAWL5V.js +0 -54
  421. package/dist/safe-bash/command-chunks/{chunk-SRXARACJ.js → chunk-3TP4SSPS.js} +3 -3
  422. package/dist/safe-bash/command-chunks/{chunk-NCNHJRIY.js → chunk-3W3HLPCX.js} +3 -3
  423. package/dist/safe-bash/command-chunks/{chunk-P4OWVKMD.js → chunk-BQXKO3X7.js} +3 -3
  424. package/dist/safe-bash/command-chunks/{chunk-OCOJMKDP.js → chunk-CVMHDJ7J.js} +3 -3
  425. package/dist/safe-bash/command-chunks/{chunk-AV6N7DDA.js → chunk-DDYPQAXN.js} +3 -3
  426. package/dist/safe-bash/command-chunks/{chunk-FEKECRJP.js → chunk-EBTKM7KX.js} +3 -3
  427. package/dist/safe-bash/command-chunks/{chunk-WVD5WZXD.js → chunk-FPNUGKCX.js} +3 -3
  428. package/dist/safe-bash/command-chunks/{chunk-6W4RMBFH.js → chunk-N6VNHC3B.js} +3 -3
  429. package/dist/safe-bash/command-chunks/{chunk-M3OXQXCU.js → chunk-NBRXQUK7.js} +3 -3
  430. package/dist/safe-bash/command-chunks/{chunk-LECGQSQW.js → chunk-SF56V6QK.js} +3 -3
  431. package/dist/safe-bash/command-chunks/{chunk-2ANW3FXH.js → chunk-U33GIOUY.js} +3 -3
  432. package/dist/safe-bash/command-chunks/{chunk-5QXRIZSS.js → chunk-V3NKL42J.js} +3 -3
  433. package/dist/safe-bash/command-chunks/{chunk-OEKLEUUW.js → chunk-YZE7BKHC.js} +3 -3
  434. package/dist/safe-bash/command-chunks/{chunk-WXW665TV.js → chunk-ZSHXZ3XG.js} +6 -6
  435. package/dist/safe-bash/command-chunks/{dif-BXKPQOCO-4KB3RC6G.js → dif-BXKPQOCO-FVJYYGYB.js} +4 -4
  436. package/dist/safe-bash/command-chunks/{pln-DFS7VLVS-OVOBS4QX.js → pln-DFS7VLVS-JATX6FS7.js} +3 -3
  437. package/dist/safe-bash/command-chunks/{psion-YBI6JEQI-GY4S6ZLC.js → psion-YBI6JEQI-6OMC2PGC.js} +3 -3
  438. package/dist/safe-bash/command-chunks/{sylk-25D7TL2Y-RU6ANKGT.js → sylk-25D7TL2Y-NJKBZZTF.js} +4 -4
  439. /package/dist/spreadsheet-engine/{rendering/print → formatting}/general-number.d.ts +0 -0
@@ -1,43 +1,20 @@
1
1
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
2
2
 
3
- // packages/safe-bash-command-pdftotext/src/text-markup.ts
4
- function escapeXml(text) {
5
- return text.replaceAll("&", "&amp;").replaceAll("'", "&apos;").replaceAll('"', "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
6
- }
7
- function* escaped(value) {
8
- const encoder = new TextEncoder();
9
- for (let offset = 0; offset < value.length; ) {
10
- let end = Math.min(value.length, offset + 4096);
11
- if (end < value.length && value.charCodeAt(end - 1) >= 55296 && value.charCodeAt(end - 1) <= 56319) end--;
12
- yield encoder.encode(escapeXml(value.slice(offset, end)));
13
- offset = end;
14
- }
15
- }
16
- function* streamTextHtmlStart(metadata, element) {
17
- const encoder = new TextEncoder();
18
- yield encoder.encode('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">\n<head>\n');
19
- yield encoder.encode("<title>");
20
- yield* escaped(metadata.Title ?? "");
21
- yield encoder.encode("</title>\n");
22
- for (const name of ["Author", "Subject", "Creator", "Producer"]) {
23
- const value = metadata[name];
24
- if (!value) continue;
25
- yield encoder.encode(`<meta name="${name}" content="`);
26
- yield* escaped(value);
27
- yield encoder.encode('"/>\n');
28
- }
29
- yield encoder.encode(`</head>
30
- <body>
31
- <${element}>
32
- `);
33
- }
34
- async function* streamTextHtml(input, metadata) {
35
- const decoder = new TextDecoder();
36
- yield* streamTextHtmlStart(metadata, "pre");
37
- for await (const bytes of input) yield* escaped(decoder.decode(bytes, { stream: true }));
38
- yield* escaped(decoder.decode());
39
- yield new TextEncoder().encode("</pre>\n</body>\n</html>\n");
40
- }
3
+ // packages/safe-bash-command-pdftotext/src/retained-html.ts
4
+ import {
5
+ PdfFileSource,
6
+ PdfRetainedDocument,
7
+ PdfRetainedDecodedImage,
8
+ PdfStagingStorage,
9
+ PdfStagedOutputs,
10
+ PdfError,
11
+ encodeRetainedPng,
12
+ encodeJpegChunks,
13
+ streamHtmlPageText
14
+ } from "../pdf-ast/index.js";
15
+ import { InputByteBudget, readBytes, writeBytes } from "../safe-bash-contracts/io.js";
16
+ import { resolvePath as resolvePath2 } from "../safe-bash-contracts/path.js";
17
+ import { yieldTurn } from "../safe-bash-contracts/yield.js";
41
18
 
42
19
  // packages/safe-bash-command-pdftotext/src/output-encoding.ts
43
20
  var ASCII7_COMPAT_MAP = {
@@ -112,9 +89,436 @@ async function* encodePopplerChunks(input, encoding, eol) {
112
89
  if (final.length) yield final;
113
90
  }
114
91
 
92
+ // packages/safe-bash-command-pdftotext/src/retained-output.ts
93
+ import { FsError } from "../safe-bash-contracts/errors.js";
94
+ import { resolvePath } from "../safe-bash-contracts/path.js";
95
+ import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
96
+ async function publishPdfOutput(context, path, source, signal) {
97
+ const fs = context.fs;
98
+ const capabilities = await fs.capabilitiesFor?.(path, { signal, create: true, stagingAncestry: true }) ?? fs.capabilities;
99
+ if (!capabilities.atomicFileStaging || !capabilities.retainedStagingWrite || !capabilities.retainedStagingCleanup || !capabilities.atomicStagingAncestry || !fs.prepareStagingResolution || !fs.createStagedFile || !fs.publishStagedFile) {
100
+ throw new FsError("ENOTSUP", { path, message: "PDF text output requires retained atomic staging" });
101
+ }
102
+ const resolution = await fs.prepareStagingResolution(path, { signal });
103
+ const directory = resolvePath(resolution.path, "..");
104
+ const staging = await fs.createStagedFile(
105
+ `${directory}/.pdf-text-${crypto.randomUUID()}`,
106
+ "output",
107
+ { type: "file", data: new Uint8Array() },
108
+ { parent: resolution.parent, retainCleanup: true, signal }
109
+ );
110
+ let failed = false;
111
+ try {
112
+ if (!staging.writer || !staging.cleanup) throw new FsError("ENOTSUP", { path, message: "PDF backend omitted retained staging handles" });
113
+ for await (const bytes of source) {
114
+ await writeFileOutput({ ...context, signal }, bytes, (data) => staging.writer.write(data, { signal }));
115
+ }
116
+ const stat = await staging.writer.finish({ signal });
117
+ await fs.publishStagedFile(
118
+ { ...staging, file: { ...staging.file, stat } },
119
+ resolution.path,
120
+ { parent: resolution.parent, destination: resolution.destination, ancestors: resolution.ancestors, commitGuard: resolution.validate, signal }
121
+ );
122
+ } catch (error) {
123
+ failed = true;
124
+ throw error;
125
+ } finally {
126
+ const cleanup = async () => {
127
+ try {
128
+ await staging.cleanup?.remove();
129
+ } finally {
130
+ await staging.cleanup?.close();
131
+ }
132
+ };
133
+ await cleanup().catch((error) => {
134
+ if (!failed) throw error;
135
+ });
136
+ }
137
+ }
138
+
139
+ // packages/safe-bash-command-pdftotext/src/retained-html.ts
140
+ var escape = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
141
+ var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
142
+ async function* base64(input, signal) {
143
+ let value = 0, count = 0, text = "";
144
+ for await (const bytes of input) {
145
+ signal.throwIfAborted();
146
+ for (const byte of bytes) {
147
+ value = value << 8 | byte;
148
+ if (++count !== 3) continue;
149
+ text += alphabet[value >>> 18 & 63] + alphabet[value >>> 12 & 63] + alphabet[value >>> 6 & 63] + alphabet[value & 63];
150
+ count = 0;
151
+ value = 0;
152
+ if (text.length >= 4096) {
153
+ yield text;
154
+ text = "";
155
+ }
156
+ }
157
+ }
158
+ if (count) {
159
+ value <<= (3 - count) * 8;
160
+ text += alphabet[value >>> 18 & 63] + alphabet[value >>> 12 & 63] + (count === 2 ? alphabet[value >>> 6 & 63] : "=") + "=";
161
+ }
162
+ if (text) yield text;
163
+ }
164
+ async function executeRetainedHtml(context, plan, stdout, signal, maxInputBytes = Infinity) {
165
+ const encoder = new TextEncoder(), directory = resolvePath2(context.cwd, context.env.TMPDIR || "/tmp");
166
+ const budget = new InputByteBudget(maxInputBytes, context.inputBudget);
167
+ const maximum = Math.min(maxInputBytes, context.inputBudget?.maxBytes ?? Infinity);
168
+ const storage = new PdfStagingStorage({ fs: context.fs, directory });
169
+ let source, document, outputs, failed = false;
170
+ const error = async (message, exitCode) => {
171
+ await writeBytes(context.stderr, encoder.encode(message), signal);
172
+ return { exitCode };
173
+ };
174
+ try {
175
+ await context.fs.mkdir(directory, { recursive: true, signal });
176
+ try {
177
+ if (plan.inputPath === "-") {
178
+ async function* input() {
179
+ for await (const bytes of readBytes(context.stdin, signal)) {
180
+ budget.charge(bytes.length);
181
+ yield bytes;
182
+ }
183
+ }
184
+ source = await PdfFileSource.fromStream(storage.fs, directory, input(), { signal, maxInputBytes: maximum });
185
+ if (!source.size) return await error("I/O Error: Couldn't open file '-'\n", 1);
186
+ } else {
187
+ const path = resolvePath2(context.cwd, plan.inputPath);
188
+ const size = (await context.fs.stat(path, { signal })).size;
189
+ budget.charge(size);
190
+ source = await PdfFileSource.open(context.fs, path, { signal, maxInputBytes: maximum });
191
+ if (source.size > size) budget.charge(source.size - size);
192
+ }
193
+ } catch (failure) {
194
+ signal.throwIfAborted();
195
+ budget.assertOpen();
196
+ if (failure instanceof PdfError && failure.code === "E_LIMIT") throw failure;
197
+ return await error(`I/O Error: Couldn't open file '${plan.inputPath}'
198
+ `, 1);
199
+ }
200
+ let pageCount = 0;
201
+ try {
202
+ document = await PdfRetainedDocument.open(source, storage, { signal, recovery: "repair", ...plan.password ? { password: plan.password } : {} });
203
+ for await (const ignored of document.pages()) {
204
+ void ignored;
205
+ pageCount++;
206
+ }
207
+ } catch (failure) {
208
+ signal.throwIfAborted();
209
+ return await error(`PDF Error: ${failure.message}
210
+ `, 1);
211
+ }
212
+ const totalPages = Math.max(1, pageCount), endPage = plan.lastPage > 0 ? Math.min(totalPages, plan.lastPage) : totalPages;
213
+ if (plan.firstPage > totalPages || plan.lastPage > 0 && plan.firstPage > endPage) {
214
+ return await error(`Command Line Error: Wrong page range given: the first page (${plan.firstPage}) can not be after the last page (${endPage}).
215
+ `, 99);
216
+ }
217
+ if (!pageCount) throw new PdfError("E_CAPABILITY", "Page index out of bounds: 0");
218
+ const doc = document;
219
+ async function* images(firstPage, lastPage) {
220
+ let pageNumber = 0, number = 0;
221
+ for await (const occurrence of doc.images({ firstPage, lastPage })) {
222
+ await yieldTurn(signal);
223
+ if (pageNumber !== occurrence.pageNumber) {
224
+ pageNumber = occurrence.pageNumber;
225
+ number = 0;
226
+ }
227
+ const name = `page${pageNumber}_${++number}.${plan.imageFmt}`;
228
+ const decoded = await PdfRetainedDecodedImage.open(doc, occurrence, storage, { signal });
229
+ let imageFailed = false;
230
+ try {
231
+ const chunks = () => plan.imageFmt === "jpg" ? encodeJpegChunks(decoded.width, decoded.height, decoded.rows(), { signal }) : encodeRetainedPng(decoded.width, decoded.height, decoded.rows(), storage, { signal });
232
+ yield { name, width: decoded.width, height: decoded.height, chunks };
233
+ } catch (failure) {
234
+ imageFailed = true;
235
+ throw failure;
236
+ } finally {
237
+ await decoded.close().catch((failure) => {
238
+ if (!imageFailed) throw failure;
239
+ });
240
+ }
241
+ }
242
+ }
243
+ async function* imageMarkup(page) {
244
+ if (plan.ignoreImages) return;
245
+ for await (const image of images(page, page)) {
246
+ if (plan.xmlMode) yield ` <image top="0" left="0" width="${image.width}" height="${image.height}" src="`;
247
+ else yield ' <img src="';
248
+ if (plan.dataUrls) {
249
+ yield `data:image/${plan.imageFmt === "jpg" ? "jpeg" : "png"};base64,`;
250
+ yield* base64(image.chunks(), signal);
251
+ } else {
252
+ if (plan.stdoutOutput) for await (const ignored of image.chunks()) void ignored;
253
+ yield image.name;
254
+ }
255
+ yield plan.xmlMode ? '"/>\n' : `" width="${image.width}" height="${image.height}"/>
256
+ `;
257
+ }
258
+ }
259
+ async function* indent(level) {
260
+ for (let left = level * 2; left > 0; left -= 2048) {
261
+ signal.throwIfAborted();
262
+ yield " ".repeat(Math.min(left, 2048));
263
+ }
264
+ }
265
+ async function* outlines() {
266
+ let depth = 0, skipLevel;
267
+ for await (const item of doc.outlineDetails({ includeUntitled: true, includeNameTitles: false })) {
268
+ if (skipLevel !== void 0) {
269
+ if (item.level > skipLevel) continue;
270
+ skipLevel = void 0;
271
+ }
272
+ if (!item.title) {
273
+ skipLevel = item.level;
274
+ continue;
275
+ }
276
+ await yieldTurn(signal);
277
+ if (!depth) yield plan.xmlMode ? " <outline>\n" : '<hr/>\n<a name="outline"></a><h1>Document Outline</h1>\n<ul>\n';
278
+ const level = Math.max(1, item.level);
279
+ if (depth) {
280
+ if (level > depth) {
281
+ for (let at = depth; at < level; at++) {
282
+ if (plan.xmlMode) yield* indent(at + 1);
283
+ yield plan.xmlMode ? "<outline>\n" : "<ul>\n";
284
+ }
285
+ } else {
286
+ if (!plan.xmlMode) yield "</li>\n";
287
+ for (let at = depth; at > level; at--) {
288
+ if (plan.xmlMode) yield* indent(at);
289
+ yield plan.xmlMode ? "</outline>\n" : "</ul>\n</li>\n";
290
+ }
291
+ }
292
+ }
293
+ depth = level;
294
+ if (plan.xmlMode) yield* indent(depth + 1);
295
+ yield plan.xmlMode ? `<item page="${item.pageIndex + 1}">` : `<li><a href="#page${item.pageIndex + 1}">`;
296
+ for (let at = 0; at < item.title.length; at += 2048) yield escape(item.title.slice(at, at + 2048));
297
+ yield plan.xmlMode ? "</item>\n" : "</a>\n";
298
+ }
299
+ if (depth && !plan.xmlMode) yield "</li>\n";
300
+ for (let at = depth; at > 0; at--) {
301
+ if (plan.xmlMode) yield* indent(at);
302
+ yield plan.xmlMode ? "</outline>\n" : at > 1 ? "</ul>\n</li>\n" : "</ul>\n";
303
+ }
304
+ }
305
+ async function* markup() {
306
+ if (plan.xmlMode) yield '<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE pdf2xml SYSTEM "pdf2xml.dtd">\n<pdf2xml producer="@poe-code/pdf-ast" version="24.08.0">\n';
307
+ else {
308
+ yield '<!DOCTYPE html>\n<html>\n<head><meta charset="utf-8"/><title>';
309
+ const title = (await doc.info()).Title ?? plan.inputPath;
310
+ for (let at = 0; at < title.length; at += 2048) yield escape(title.slice(at, at + 2048));
311
+ yield "</title></head>\n<body>\n";
312
+ }
313
+ for await (const page of doc.pages()) {
314
+ await yieldTurn(signal);
315
+ const number = page.index + 1;
316
+ if (number < plan.firstPage) continue;
317
+ if (number > endPage) break;
318
+ const { mediaBox } = await page.attributes(), width = Math.abs(mediaBox[2] - mediaBox[0]), height = Math.abs(mediaBox[3] - mediaBox[1]);
319
+ yield plan.xmlMode ? ` <page number="${number}" position="absolute" top="0" left="0" height="${Math.round(height * plan.zoom)}" width="${Math.round(width * plan.zoom)}">
320
+ ` : `<div class="page" id="page${number}" style="position:relative;width:${Math.round(width * plan.zoom)}pt;height:${Math.round(height * plan.zoom)}pt;">
321
+ `;
322
+ const index = await page.indexText(storage, { mode: "layout", retainFontNames: true, signal });
323
+ let pageFailed = false;
324
+ try {
325
+ yield* streamHtmlPageText(doc, page, index, storage, { xml: plan.xmlMode, zoom: plan.zoom, height, signal, images: () => imageMarkup(number) });
326
+ } catch (failure) {
327
+ pageFailed = true;
328
+ throw failure;
329
+ } finally {
330
+ await index.close().catch((failure) => {
331
+ if (!pageFailed) throw failure;
332
+ });
333
+ }
334
+ yield plan.xmlMode ? " </page>\n" : "</div>\n";
335
+ }
336
+ yield* outlines();
337
+ yield plan.xmlMode ? "</pdf2xml>\n" : "</body>\n</html>\n";
338
+ }
339
+ async function* encoded() {
340
+ let high = "";
341
+ for await (const part of markup()) {
342
+ let text = high + part;
343
+ high = "";
344
+ const last = text.charCodeAt(text.length - 1);
345
+ if (last >= 55296 && last <= 56319) {
346
+ high = text.slice(-1);
347
+ text = text.slice(0, -1);
348
+ }
349
+ if (text) yield encoder.encode(applyPopplerOutputEncoding(text, plan.encoding));
350
+ }
351
+ if (high) yield encoder.encode(applyPopplerOutputEncoding(high, plan.encoding));
352
+ }
353
+ let inputReplaced = plan.outPath === plan.inputPath;
354
+ async function* entries() {
355
+ if (!plan.stdoutOutput) yield { name: plan.inputPath, chunks: [] };
356
+ if (!plan.ignoreImages && !plan.dataUrls && !plan.stdoutOutput) {
357
+ for await (const image of images(plan.firstPage, endPage)) {
358
+ const name = plan.imageDirectory + image.name;
359
+ if (name === plan.inputPath) inputReplaced = true;
360
+ yield { name, chunks: image.chunks() };
361
+ }
362
+ }
363
+ yield { name: plan.outPath, chunks: encoded() };
364
+ }
365
+ outputs = await PdfStagedOutputs.create(storage, entries(), { signal });
366
+ for await (const output of outputs.entries()) {
367
+ if (!plan.stdoutOutput && output.name === plan.inputPath && !inputReplaced) continue;
368
+ if (plan.stdoutOutput) for await (const bytes of output.contents()) await writeBytes(stdout, bytes, signal);
369
+ else try {
370
+ await publishPdfOutput(context, resolvePath2(context.cwd, output.name), output.contents(), signal);
371
+ } catch (failure) {
372
+ signal.throwIfAborted();
373
+ if (!(failure instanceof Error) || !("code" in failure)) throw failure;
374
+ return await error(`I/O Error: Couldn't open html file '${output.name}'
375
+ `, 0);
376
+ }
377
+ }
378
+ return { exitCode: 0 };
379
+ } catch (failure) {
380
+ failed = true;
381
+ throw failure;
382
+ } finally {
383
+ const closed = await Promise.allSettled([outputs?.close(), document?.close(), source?.close()]);
384
+ if (!failed) {
385
+ for (const result of closed) if (result.status === "rejected") await Promise.reject(result.reason);
386
+ }
387
+ }
388
+ }
389
+
390
+ // packages/safe-bash-command-pdftotext/src/html-arguments.ts
391
+ var SUPPORTED_ENCODINGS = /* @__PURE__ */ new Set([
392
+ "ASCII7",
393
+ "Latin1",
394
+ "UTF-8",
395
+ "UCS-2",
396
+ "Symbol",
397
+ "ZapfDingbats"
398
+ ]);
399
+ function parseHtmlArguments(argv, hasStdin = false) {
400
+ let xmlMode = false;
401
+ let toStdout = false;
402
+ let ignoreImages = false;
403
+ let dataUrls = false;
404
+ let firstPage = 1;
405
+ let lastPage = 0;
406
+ let zoom = 1;
407
+ let imageFmt = "png";
408
+ let encoding = "UTF-8";
409
+ let password = "";
410
+ const positionals = [];
411
+ for (let i = 0; i < argv.length; i++) {
412
+ const arg = argv[i];
413
+ if (arg === "--") {
414
+ positionals.push(...argv.slice(i + 1));
415
+ break;
416
+ }
417
+ if (arg === "-v" || arg === "--version") {
418
+ return { exitCode: 0, stdout: "pdftohtml version 24.08.0\n", stderr: "" };
419
+ }
420
+ if (arg === "-h" || arg === "-help" || arg === "--help" || arg === "-?") {
421
+ return {
422
+ exitCode: 0,
423
+ stdout: "Usage: pdftohtml [options] <PDF-file> [<html-file>|<xml-file>]\n -xml / -stdout / -s / -i / -noframes / -c / -f <int> / -l <int>\n",
424
+ stderr: ""
425
+ };
426
+ }
427
+ if (arg === "-xml")
428
+ xmlMode = true;
429
+ else if (arg === "-stdout")
430
+ toStdout = true;
431
+ else if (arg === "-i")
432
+ ignoreImages = true;
433
+ else if (arg === "-dataurls")
434
+ dataUrls = true;
435
+ else if (arg === "-f")
436
+ firstPage = Math.max(1, Number(argv[++i] ?? "1") || 1);
437
+ else if (arg === "-l")
438
+ lastPage = Math.max(0, Number(argv[++i] ?? "0") || 0);
439
+ else if (arg === "-zoom") {
440
+ const z = Number.parseFloat(argv[++i] ?? "1");
441
+ if (Number.isFinite(z) && z > 0)
442
+ zoom = z;
443
+ } else if (arg === "-fmt") {
444
+ const fmtVal = (argv[++i] ?? "").toLowerCase();
445
+ if (fmtVal === "png")
446
+ imageFmt = "png";
447
+ else if (fmtVal === "jpg" || fmtVal === "jpeg")
448
+ imageFmt = "jpg";
449
+ else {
450
+ return { exitCode: 99, stdout: "", stderr: `Command Line Error: Invalid image format '${fmtVal}'
451
+ ` };
452
+ }
453
+ } else if (arg === "-enc") {
454
+ const nextEnc = argv[++i] ?? "";
455
+ if (!SUPPORTED_ENCODINGS.has(nextEnc)) {
456
+ return { exitCode: 99, stdout: "", stderr: `Command Line Error: Unknown encoding '${nextEnc}'
457
+ ` };
458
+ }
459
+ encoding = nextEnc;
460
+ } else if (arg === "-upw" || arg === "-opw")
461
+ password = argv[++i] ?? "";
462
+ else if (arg === "-s" || arg === "-noframes" || arg === "-c" || arg === "-p" || arg === "-q" || arg === "-hidden" || arg === "-nomerge" || arg === "-nodrm") {
463
+ } else if (!arg.startsWith("-") || arg === "-") {
464
+ positionals.push(arg);
465
+ }
466
+ }
467
+ const inputPath = positionals[0] ?? (hasStdin ? "-" : void 0);
468
+ if (!inputPath) {
469
+ return { exitCode: 99, stdout: "", stderr: "Usage: pdftohtml [options] <PDF-file> [<html-file>]\n" };
470
+ }
471
+ const explicitOut = positionals[1];
472
+ const stdoutOutput = toStdout || explicitOut === "-" || inputPath === "-" && !explicitOut;
473
+ const defaultExt = xmlMode ? ".xml" : ".html";
474
+ const inputStem = inputPath.toLowerCase().endsWith(".pdf") ? inputPath.slice(0, -4) : inputPath;
475
+ const outPath = explicitOut ? explicitOut.endsWith(".html") || explicitOut.endsWith(".xml") ? explicitOut : `${explicitOut}${defaultExt}` : inputStem + defaultExt;
476
+ const imageDirectory = outPath.slice(0, outPath.lastIndexOf("/") + 1);
477
+ return { inputPath, outPath, imageDirectory, xmlMode, stdoutOutput, ignoreImages, dataUrls, firstPage, lastPage, zoom, imageFmt, encoding, password };
478
+ }
479
+
480
+ // packages/safe-bash-command-pdftotext/src/text-markup.ts
481
+ function escapeXml(text) {
482
+ return text.replaceAll("&", "&amp;").replaceAll("'", "&apos;").replaceAll('"', "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
483
+ }
484
+ function* escaped(value) {
485
+ const encoder = new TextEncoder();
486
+ for (let offset = 0; offset < value.length; ) {
487
+ let end = Math.min(value.length, offset + 4096);
488
+ if (end < value.length && value.charCodeAt(end - 1) >= 55296 && value.charCodeAt(end - 1) <= 56319) end--;
489
+ yield encoder.encode(escapeXml(value.slice(offset, end)));
490
+ offset = end;
491
+ }
492
+ }
493
+ function* streamTextHtmlStart(metadata, element) {
494
+ const encoder = new TextEncoder();
495
+ yield encoder.encode('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">\n<head>\n');
496
+ yield encoder.encode("<title>");
497
+ yield* escaped(metadata.Title ?? "");
498
+ yield encoder.encode("</title>\n");
499
+ for (const name of ["Author", "Subject", "Creator", "Producer"]) {
500
+ const value = metadata[name];
501
+ if (!value) continue;
502
+ yield encoder.encode(`<meta name="${name}" content="`);
503
+ yield* escaped(value);
504
+ yield encoder.encode('"/>\n');
505
+ }
506
+ yield encoder.encode(`</head>
507
+ <body>
508
+ <${element}>
509
+ `);
510
+ }
511
+ async function* streamTextHtml(input, metadata) {
512
+ const decoder = new TextDecoder();
513
+ yield* streamTextHtmlStart(metadata, "pre");
514
+ for await (const bytes of input) yield* escaped(decoder.decode(bytes, { stream: true }));
515
+ yield* escaped(decoder.decode());
516
+ yield new TextEncoder().encode("</pre>\n</body>\n</html>\n");
517
+ }
518
+
115
519
  // packages/safe-bash-command-pdftotext/src/retained-bbox.ts
116
- async function* streamRawBboxPage(page, storage, geometry, options) {
117
- const index = await page.indexRawText(storage, { discardDiagonal: options.nodiag, clipText: options.clip, signal: options.signal });
520
+ async function* streamTextGeometryPage(page, storage, geometry, options) {
521
+ const index = await page.indexText(storage, { mode: options.raw ? "raw" : options.layout ? "layout" : "logical", colSpacing: options.colspacing, discardDiagonal: options.nodiag, clipText: options.clip, signal: options.signal });
118
522
  const encoder = new TextEncoder(), scale = options.resolution / 72;
119
523
  let failed = false, hasWords = false;
120
524
  function selected(box) {
@@ -136,8 +540,15 @@ async function* streamRawBboxPage(page, storage, geometry, options) {
136
540
  function coordinates(box) {
137
541
  return `xMin="${(box[0] * scale).toFixed(6)}" yMin="${((geometry.height - box[3]) * scale).toFixed(6)}" xMax="${(box[2] * scale).toFixed(6)}" yMax="${((geometry.height - box[1]) * scale).toFixed(6)}"`;
138
542
  }
543
+ function tsvCoordinates(box, precision) {
544
+ return [box[0] * scale, (geometry.height - box[3]) * scale, (box[2] - box[0]) * scale, (box[3] - box[1]) * scale].map((value) => value.toFixed(precision)).join(" ");
545
+ }
546
+ const tsv = options.tsv === true;
547
+ let blockIndex = 0;
139
548
  try {
140
- yield encoder.encode(` <page width="${geometry.width.toFixed(6)}" height="${geometry.height.toFixed(6)}">
549
+ if (tsv) yield encoder.encode(`1 ${page.index + 1} 0 0 0 0 0.000000 0.000000 ${geometry.width.toFixed(6)} ${geometry.height.toFixed(6)} -1 ###PAGE###
550
+ `);
551
+ else yield encoder.encode(` <page width="${geometry.width.toFixed(6)}" height="${geometry.height.toFixed(6)}">
141
552
  `);
142
553
  for await (const block of index.blocks()) {
143
554
  let blockBox;
@@ -146,27 +557,37 @@ async function* streamRawBboxPage(page, storage, geometry, options) {
146
557
  if (box) blockBox = union(blockBox, box);
147
558
  }
148
559
  if (!blockBox) continue;
149
- if (options.bboxLayout) yield encoder.encode(` <flow>
560
+ if (tsv) yield encoder.encode(`3 ${page.index + 1} ${blockIndex} ${blockIndex} 0 0 ${tsvCoordinates(blockBox, 6)} -1 ###FLOW###
561
+ `);
562
+ else if (options.bboxLayout) yield encoder.encode(` <flow>
150
563
  <block ${coordinates(blockBox)}>
151
564
  `);
565
+ let lineIndex = 0;
152
566
  for await (const line of block.lines()) {
153
567
  const box = await lineBounds(line);
154
568
  if (!box) continue;
155
- if (options.bboxLayout) yield encoder.encode(` <line ${coordinates(box)}>
569
+ if (tsv) yield encoder.encode(`4 ${page.index + 1} ${blockIndex} ${blockIndex} ${lineIndex} 0 ${tsvCoordinates(box, 6)} -1 ###LINE###
570
+ `);
571
+ else if (options.bboxLayout) yield encoder.encode(` <line ${coordinates(box)}>
156
572
  `);
573
+ let wordIndex = 0;
157
574
  for await (const word of line.words()) {
158
575
  const wordBox = selected(word.bbox);
159
576
  if (!wordBox) continue;
160
577
  hasWords = true;
161
- yield encoder.encode(` <word ${coordinates(wordBox)}>`);
162
- for await (const text of word.text()) yield encoder.encode(escapeXml(text));
163
- yield encoder.encode("</word>\n");
578
+ if (tsv) yield encoder.encode(`5 ${page.index + 1} ${blockIndex} ${blockIndex} ${lineIndex} ${wordIndex} ${tsvCoordinates(wordBox, 2)} 100 `);
579
+ else yield encoder.encode(` <word ${coordinates(wordBox)}>`);
580
+ for await (const text of word.text()) yield encoder.encode(tsv ? text : escapeXml(text));
581
+ yield encoder.encode(tsv ? "\n" : "</word>\n");
582
+ wordIndex++;
164
583
  }
165
- if (options.bboxLayout) yield encoder.encode(" </line>\n");
584
+ if (!tsv && options.bboxLayout) yield encoder.encode(" </line>\n");
585
+ lineIndex++;
166
586
  }
167
- if (options.bboxLayout) yield encoder.encode(" </block>\n </flow>\n");
587
+ if (!tsv && options.bboxLayout) yield encoder.encode(" </block>\n </flow>\n");
588
+ blockIndex++;
168
589
  }
169
- yield encoder.encode(" </page>\n");
590
+ if (!tsv) yield encoder.encode(" </page>\n");
170
591
  return hasWords;
171
592
  } catch (error) {
172
593
  failed = true;
@@ -179,63 +600,19 @@ async function* streamRawBboxPage(page, storage, geometry, options) {
179
600
  }
180
601
 
181
602
  // packages/safe-bash-command-pdftotext/src/retained-raw.ts
182
- import { PdfError, PdfNameIndex, PdfFileSource, PdfRetainedDocument, PdfStagingStorage, dictGet } from "../pdf-ast/index.js";
183
- import { FsError } from "../safe-bash-contracts/errors.js";
184
- import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
185
- import { readBytes, writeBytes } from "../safe-bash-contracts/io.js";
186
- import { resolvePath } from "../safe-bash-contracts/path.js";
187
- import { yieldTurn } from "../safe-bash-contracts/yield.js";
188
- async function publish(context, path, source, signal) {
189
- const fs = context.fs;
190
- const capabilities = await fs.capabilitiesFor?.(path, { signal, create: true, stagingAncestry: true }) ?? fs.capabilities;
191
- if (!capabilities.atomicFileStaging || !capabilities.retainedStagingWrite || !capabilities.retainedStagingCleanup || !capabilities.atomicStagingAncestry || !fs.prepareStagingResolution || !fs.createStagedFile || !fs.publishStagedFile) {
192
- throw new FsError("ENOTSUP", { path, message: "PDF text output requires retained atomic staging" });
193
- }
194
- const resolution = await fs.prepareStagingResolution(path, { signal });
195
- const directory = resolvePath(resolution.path, "..");
196
- const staging = await fs.createStagedFile(
197
- `${directory}/.pdf-text-${crypto.randomUUID()}`,
198
- "output",
199
- { type: "file", data: new Uint8Array() },
200
- { parent: resolution.parent, retainCleanup: true, signal }
201
- );
202
- let failed = false;
203
- try {
204
- if (!staging.writer || !staging.cleanup) throw new FsError("ENOTSUP", { path, message: "PDF backend omitted retained staging handles" });
205
- for await (const bytes of source.stream(0, source.size, signal)) {
206
- await writeFileOutput({ ...context, signal }, bytes, (data) => staging.writer.write(data, { signal }));
207
- }
208
- const stat = await staging.writer.finish({ signal });
209
- await fs.publishStagedFile(
210
- { ...staging, file: { ...staging.file, stat } },
211
- resolution.path,
212
- { parent: resolution.parent, destination: resolution.destination, ancestors: resolution.ancestors, commitGuard: resolution.validate, signal }
213
- );
214
- } catch (error) {
215
- failed = true;
216
- throw error;
217
- } finally {
218
- const cleanup = async () => {
219
- try {
220
- await staging.cleanup?.remove();
221
- } finally {
222
- await staging.cleanup?.close();
223
- }
224
- };
225
- await cleanup().catch((error) => {
226
- if (!failed) throw error;
227
- });
228
- }
229
- }
230
- async function executeRetainedRawText(context, plan, stdout, signal, maxInputBytes = Infinity) {
603
+ import { PdfError as PdfError2, PdfNameIndex, PdfFileSource as PdfFileSource2, PdfRetainedDocument as PdfRetainedDocument2, PdfStagingStorage as PdfStagingStorage2, dictGet } from "../pdf-ast/index.js";
604
+ import { readBytes as readBytes2, writeBytes as writeBytes2 } from "../safe-bash-contracts/io.js";
605
+ import { resolvePath as resolvePath3 } from "../safe-bash-contracts/path.js";
606
+ import { yieldTurn as yieldTurn2 } from "../safe-bash-contracts/yield.js";
607
+ async function executeRetainedText(context, plan, stdout, signal, maxInputBytes = Infinity) {
231
608
  const encoder = new TextEncoder(), inputPath = plan.inputFile ?? "-", outputPath = plan.outputFile ?? "-";
232
609
  const warning = plan.invalidEolWarning ? "Bad '-eol' value on command line\n" : "";
233
610
  async function error(message, exitCode, includeWarning = true) {
234
- if (!plan.quiet) await writeBytes(context.stderr, encoder.encode((includeWarning ? warning : "") + message), signal);
611
+ if (!plan.quiet) await writeBytes2(context.stderr, encoder.encode((includeWarning ? warning : "") + message), signal);
235
612
  return { exitCode };
236
613
  }
237
- const directory = resolvePath(context.cwd, context.env.TMPDIR || "/tmp");
238
- const storage = new PdfStagingStorage({ fs: context.fs, directory });
614
+ const directory = resolvePath3(context.cwd, context.env.TMPDIR || "/tmp");
615
+ const storage = new PdfStagingStorage2({ fs: context.fs, directory });
239
616
  let source, document, result, failed = false;
240
617
  try {
241
618
  await context.fs.mkdir(directory, { recursive: true, signal });
@@ -244,18 +621,18 @@ async function executeRetainedRawText(context, plan, stdout, signal, maxInputByt
244
621
  if (inputPath === "-") {
245
622
  async function* input() {
246
623
  let total = 0, turns = 0;
247
- for await (const bytes of readBytes(context.stdin, signal)) {
248
- if (++turns % 64 === 0) await yieldTurn(signal);
624
+ for await (const bytes of readBytes2(context.stdin, signal)) {
625
+ if (++turns % 64 === 0) await yieldTurn2(signal);
249
626
  total += bytes.length;
250
627
  context.inputBudget?.check(total);
251
628
  yield bytes;
252
629
  }
253
630
  }
254
- source = await PdfFileSource.fromStream(storage.fs, directory, input(), { maxInputBytes: maximum, signal });
631
+ source = await PdfFileSource2.fromStream(storage.fs, directory, input(), { maxInputBytes: maximum, signal });
255
632
  } else {
256
- const path = resolvePath(context.cwd, inputPath);
633
+ const path = resolvePath3(context.cwd, inputPath);
257
634
  context.inputBudget?.check((await context.fs.stat(path, { signal })).size);
258
- source = await PdfFileSource.open(context.fs, path, { maxInputBytes: maximum, signal });
635
+ source = await PdfFileSource2.open(context.fs, path, { maxInputBytes: maximum, signal });
259
636
  context.inputBudget?.check(source.size);
260
637
  }
261
638
  } catch (failure) {
@@ -270,15 +647,15 @@ async function executeRetainedRawText(context, plan, stdout, signal, maxInputByt
270
647
  let pageCount = 0;
271
648
  try {
272
649
  const password = plan.opw ?? plan.upw;
273
- document = await PdfRetainedDocument.open(source, storage, { recovery: "repair", signal, ...password !== void 0 ? { password } : {} });
650
+ document = await PdfRetainedDocument2.open(source, storage, { recovery: "repair", signal, ...password !== void 0 ? { password } : {} });
274
651
  for await (const ignored of document.pages()) {
275
652
  void ignored;
276
653
  pageCount++;
277
- await yieldTurn(signal);
654
+ await yieldTurn2(signal);
278
655
  }
279
656
  } catch (failure) {
280
657
  signal.throwIfAborted();
281
- if (!(failure instanceof PdfError)) throw failure;
658
+ if (!(failure instanceof PdfError2)) throw failure;
282
659
  if (failure.code === "E_PASSWORD" || failure.code === "E_CAPABILITY" && failure.message === "Invalid PDF password") return await error("Command Line Error: Incorrect password\n", 1);
283
660
  if (failure.code !== "E_PARSE") throw failure;
284
661
  return await error(`Syntax Error: ${failure.message}
@@ -294,13 +671,13 @@ async function executeRetainedRawText(context, plan, stdout, signal, maxInputByt
294
671
  if (plan.bbox) yield* streamTextHtmlStart(await retained.info(), "doc");
295
672
  else if (plan.tsv) yield encoder.encode("level page_num par_num block_num line_num word_num left top width height conf text\n");
296
673
  for await (const page of retained.pages()) {
297
- await yieldTurn(signal);
674
+ await yieldTurn2(signal);
298
675
  if (page.index + 1 < first) continue;
299
676
  if (page.index + 1 > last) break;
300
677
  const geometry = await rawGeometry(retained, page, plan);
301
- if (plan.bbox) {
302
- const hasWords = yield* streamRawBboxPage(page, storage, geometry, { ...plan, signal });
303
- if (!hasWords && !plan.bboxLayout && !plan.quiet) emptyPageWarning = true;
678
+ if (plan.bbox || plan.tsv && !plan.raw) {
679
+ const hasWords = yield* streamTextGeometryPage(page, storage, geometry, { ...plan, tsv: plan.tsv && !plan.bbox, signal });
680
+ if (plan.bbox && !hasWords && !plan.bboxLayout && !plan.quiet) emptyPageWarning = true;
304
681
  continue;
305
682
  }
306
683
  if (plan.tsv) {
@@ -312,14 +689,19 @@ async function executeRetainedRawText(context, plan, stdout, signal, maxInputByt
312
689
  continue;
313
690
  }
314
691
  const crop = geometry?.crop;
315
- const raw = page.streamRawText(storage, { ...crop ? { crop } : {}, rejoinHyphens: false, discardDiagonal: plan.nodiag, clipText: plan.clip, signal });
316
- if (!plan.urls) yield* raw;
317
- else {
692
+ const textOptions = { ...crop ? { crop } : {}, rejoinHyphens: !plan.raw && plan.removeHyphens, discardDiagonal: plan.nodiag, clipText: plan.clip, colSpacing: plan.colspacing, fixedPitch: plan.fixed, lineSpacing: plan.linespacing, signal };
693
+ const raw = plan.raw ? page.streamRawText(storage, textOptions) : plan.layout ? page.streamLayoutText(storage, textOptions) : page.streamLogicalText(storage, textOptions);
694
+ let lastByte;
695
+ if (!plan.urls) {
696
+ for await (const bytes of raw) {
697
+ lastByte = bytes.at(-1) ?? lastByte;
698
+ yield bytes;
699
+ }
700
+ } else {
318
701
  const names = new PdfNameIndex(storage, Infinity, signal);
319
702
  let body, pageFailed = false;
320
703
  try {
321
- body = await PdfFileSource.fromStream(storage.fs, directory, raw, { signal });
322
- let lastByte;
704
+ body = await PdfFileSource2.fromStream(storage.fs, directory, raw, { signal });
323
705
  for await (const bytes of body.stream(0, body.size, signal)) {
324
706
  lastByte = bytes.at(-1) ?? lastByte;
325
707
  yield bytes;
@@ -342,18 +724,22 @@ async function executeRetainedRawText(context, plan, stdout, signal, maxInputByt
342
724
  }
343
725
  }
344
726
  }
727
+ if (!plan.raw && lastByte !== void 0) {
728
+ if (lastByte !== 10) yield new Uint8Array([10]);
729
+ if (!plan.layout) yield new Uint8Array([10]);
730
+ }
345
731
  if (!plan.nopgbrk) yield new Uint8Array([12]);
346
732
  }
347
733
  if (plan.bbox) yield encoder.encode("</doc>\n</body>\n</html>\n");
348
734
  }
349
735
  const formatted = plan.htmlmeta && !plan.bbox ? streamTextHtml(encodePopplerChunks(text(), "UTF-8", plan.tsv ? "unix" : plan.eol), await document.info()) : text();
350
- result = await PdfFileSource.fromStream(storage.fs, directory, encodePopplerChunks(formatted, plan.encoding, plan.htmlmeta || plan.tsv || plan.bbox ? "unix" : plan.eol), { signal });
351
- if (warning || emptyPageWarning) await writeBytes(context.stderr, encoder.encode(warning + (emptyPageWarning ? "no word list\n" : "")), signal);
736
+ result = await PdfFileSource2.fromStream(storage.fs, directory, encodePopplerChunks(formatted, plan.encoding, plan.htmlmeta || plan.tsv || plan.bbox ? "unix" : plan.eol), { signal });
737
+ if (warning || emptyPageWarning) await writeBytes2(context.stderr, encoder.encode(warning + (emptyPageWarning ? "no word list\n" : "")), signal);
352
738
  if (outputPath === "-") {
353
- for await (const bytes of result.stream(0, result.size, signal)) await writeBytes(stdout, bytes, signal);
739
+ for await (const bytes of result.stream(0, result.size, signal)) await writeBytes2(stdout, bytes, signal);
354
740
  } else {
355
741
  try {
356
- await publish(context, resolvePath(context.cwd, outputPath), result, signal);
742
+ await publishPdfOutput(context, resolvePath3(context.cwd, outputPath), result.stream(0, result.size, signal), signal);
357
743
  } catch (failure) {
358
744
  signal.throwIfAborted();
359
745
  if (!(failure instanceof Error) || !("code" in failure)) throw failure;
@@ -376,7 +762,7 @@ async function containsText(source, needle, signal) {
376
762
  const decoder = new TextDecoder();
377
763
  let overlap = "";
378
764
  for await (const bytes of source.stream(0, source.size, signal)) {
379
- await yieldTurn(signal);
765
+ await yieldTurn2(signal);
380
766
  const text = overlap + decoder.decode(bytes, { stream: true });
381
767
  if (text.includes(needle)) return true;
382
768
  overlap = needle.length > 1 ? text.slice(-(needle.length - 1)) : "";
@@ -389,7 +775,7 @@ async function rawGeometry(document, page, plan) {
389
775
  let current = page.dict, depth = 0;
390
776
  const visited = /* @__PURE__ */ new Set();
391
777
  while (current) {
392
- if (++depth > document.depthLimit) throw new PdfError("E_LIMIT", "PDF inherited crop depth limit exceeded");
778
+ if (++depth > document.depthLimit) throw new PdfError2("E_LIMIT", "PDF inherited crop depth limit exceeded");
393
779
  const candidate = (await document.lookup(dictGet(current, "CropBox")))?.value;
394
780
  if (candidate?.kind === "array" && candidate.items.length >= 4) {
395
781
  box = [];
@@ -426,25 +812,15 @@ async function rawGeometry(document, page, plan) {
426
812
  }
427
813
 
428
814
  // packages/safe-bash-command-pdftotext/src/index.ts
429
- import { resolvePath as resolvePath2 } from "../safe-bash-contracts/path.js";
430
- import { yieldTurn as yieldTurn2, drainCooperativeSteps as drainSteps } from "../safe-bash-contracts/yield.js";
431
- import { InputByteBudget } from "../safe-bash-contracts/io.js";
432
- import { writeFileOutput as writeFileOutput2 } from "../safe-bash-contracts/filesystem-output-budget.js";
815
+ import { drainCooperativeSteps as drainSteps } from "../safe-bash-contracts/yield.js";
816
+ import { InputByteBudget as InputByteBudget2 } from "../safe-bash-contracts/io.js";
433
817
  import {
434
818
  commandRuntimeIdentity,
435
819
  getCommandArguments
436
820
  } from "../safe-bash-contracts/command.js";
437
- import { readBytes as readBytes2, writeBytes as writeBytes2 } from "../safe-bash-contracts/io.js";
821
+ import { writeBytes as writeBytes3 } from "../safe-bash-contracts/io.js";
438
822
  import { createOutputOperation } from "../safe-bash-contracts/output.js";
439
823
  import { PdfDocument, decodePdfString, dictGet as dictGet2, extractPageAnnotations, formatExtractedPageText, resolveDestinationPageIndex, encodeJpegSteps, encodePngSteps, extractDocumentImagesSteps } from "../pdf-ast/index.js";
440
- var SUPPORTED_ENCODINGS = /* @__PURE__ */ new Set([
441
- "ASCII7",
442
- "Latin1",
443
- "UTF-8",
444
- "UCS-2",
445
- "Symbol",
446
- "ZapfDingbats"
447
- ]);
448
824
  function parseStrictIntArg(raw) {
449
825
  if (!raw || raw.length === 0) return void 0;
450
826
  let start = 0;
@@ -1145,11 +1521,10 @@ function* runPdftotextCliSteps(argv, files, stdinBytes = new Uint8Array(0), sign
1145
1521
  async function runPdftotextCli(argv, files, stdinBytes = new Uint8Array(0), signal) {
1146
1522
  return drainSteps(runPdftotextCliSteps(argv, files, stdinBytes, signal), signal);
1147
1523
  }
1148
- function usesRetainedRaw(parsed) {
1149
- return !parsed.error && !parsed.listenc && !parsed.version && !parsed.help && parsed.raw;
1524
+ function usesRetainedText(parsed) {
1525
+ return !parsed.error && !parsed.listenc && !parsed.version && !parsed.help;
1150
1526
  }
1151
1527
  async function pdftotext(context) {
1152
- let cooperativeWork = 63;
1153
1528
  const invocation = createOutputOperation(context, { write: async () => {
1154
1529
  } });
1155
1530
  try {
@@ -1157,105 +1532,39 @@ async function pdftotext(context) {
1157
1532
  const argv = [...carrier.args];
1158
1533
  const parsed = parseArgs(argv);
1159
1534
  if (parsed.error || parsed.listenc || parsed.version || parsed.help) {
1160
- const res2 = await drainSteps(extractPdfToTextBytesCooperativelySteps(new Uint8Array(0), argv, invocation.signal), invocation.signal);
1161
- if (res2.stderr) {
1162
- await writeBytes2(context.stderr, new TextEncoder().encode(res2.stderr), invocation.signal);
1535
+ const res = await drainSteps(extractPdfToTextBytesCooperativelySteps(new Uint8Array(0), argv, invocation.signal), invocation.signal);
1536
+ if (res.stderr) {
1537
+ await writeBytes3(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
1163
1538
  }
1164
- if (res2.output) {
1539
+ if (res.output) {
1165
1540
  const stdout = invocation.child(context.stdout);
1166
- await writeBytes2(stdout.output, new TextEncoder().encode(res2.output), invocation.signal);
1167
- }
1168
- return { exitCode: res2.exitCode };
1169
- }
1170
- if (usesRetainedRaw(parsed)) {
1171
- return await executeRetainedRawText(context, parsed, invocation.child(context.stdout).output, invocation.signal);
1172
- }
1173
- const inputTarget = parsed.inputFile ?? "-";
1174
- let pdfBytes;
1175
- let accountedBytes = 0;
1176
- const chargeBytes = (delta) => {
1177
- if (delta > 0) {
1178
- accountedBytes += delta;
1179
- context.inputBudget?.check(accountedBytes);
1180
- }
1181
- };
1182
- if (inputTarget === "-") {
1183
- const chunks = [];
1184
- let total = 0;
1185
- for await (const chunk of readBytes2(context.stdin, invocation.signal)) {
1186
- if (++cooperativeWork % 64 === 0) await yieldTurn2(context.signal);
1187
- chunks.push(chunk);
1188
- total += chunk.byteLength;
1189
- chargeBytes(chunk.byteLength);
1190
- }
1191
- pdfBytes = new Uint8Array(total);
1192
- let offset = 0;
1193
- for (const c of chunks) {
1194
- if (++cooperativeWork % 64 === 0) await yieldTurn2(context.signal);
1195
- pdfBytes.set(c, offset);
1196
- offset += c.byteLength;
1541
+ await writeBytes3(stdout.output, new TextEncoder().encode(res.output), invocation.signal);
1197
1542
  }
1198
- } else {
1199
- const resolvedPath = resolvePath2(context.cwd, inputTarget);
1200
- try {
1201
- pdfBytes = await context.fs.readFile(resolvedPath, { signal: invocation.signal });
1202
- chargeBytes(pdfBytes.byteLength);
1203
- } catch {
1204
- if (!parsed.quiet) {
1205
- const msg = `I/O Error: Couldn't open file '${inputTarget}': No such file or directory.
1206
- `;
1207
- await writeBytes2(context.stderr, new TextEncoder().encode(msg), invocation.signal);
1208
- }
1209
- return { exitCode: 1 };
1210
- }
1211
- }
1212
- const res = await drainSteps(extractPdfToTextBytesCooperativelySteps(pdfBytes, argv, invocation.signal), invocation.signal);
1213
- if (res.stderr) {
1214
- await writeBytes2(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
1215
- }
1216
- if (res.exitCode !== 0) {
1217
1543
  return { exitCode: res.exitCode };
1218
1544
  }
1219
- const outBytes = parsed.encoding === "Latin1" ? Uint8Array.from(res.output, (char) => char.charCodeAt(0)) : parsed.encoding === "UCS-2" ? encodeUcs2(res.output) : new TextEncoder().encode(res.output);
1220
- if (res.outputPath === "-") {
1221
- const stdout = invocation.child(context.stdout);
1222
- await writeBytes2(stdout.output, outBytes, invocation.signal);
1223
- } else {
1224
- const outResolved = resolvePath2(context.cwd, res.outputPath);
1225
- try {
1226
- await writeFileOutput2(context, outBytes, (data) => context.fs.writeFile(outResolved, data, { signal: invocation.signal }));
1227
- } catch {
1228
- if (!parsed.quiet) {
1229
- const msg = `I/O Error: Couldn't open text file '${res.outputPath}'
1230
- `;
1231
- await writeBytes2(context.stderr, new TextEncoder().encode(msg), invocation.signal);
1232
- }
1233
- return { exitCode: 2 };
1234
- }
1235
- }
1236
- return { exitCode: 0 };
1545
+ return await executeRetainedText(context, parsed, invocation.child(context.stdout).output, invocation.signal);
1237
1546
  } finally {
1238
1547
  await invocation.close();
1239
1548
  }
1240
1549
  }
1241
1550
  function createPdftotextCommand(options = {}) {
1242
- const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
1551
+ const maxInputBytes = InputByteBudget2.limit(options.limits?.maxInputBytes);
1243
1552
  return Object.freeze({
1244
1553
  name: "pdftotext",
1245
1554
  runtimeIdentity: commandRuntimeIdentity,
1246
1555
  description: "Extract PDF text, layout, XHTML bounding boxes, and TSV via @poe-code/pdf-ast",
1247
1556
  async execute(context) {
1248
1557
  const parsed = parseArgs(getCommandArguments(context).args);
1249
- if (usesRetainedRaw(parsed)) {
1558
+ if (usesRetainedText(parsed)) {
1250
1559
  const invocation = createOutputOperation(context, { write: async () => {
1251
1560
  } });
1252
1561
  try {
1253
- return await executeRetainedRawText(context, parsed, invocation.child(context.stdout).output, invocation.signal, maxInputBytes);
1562
+ return await executeRetainedText(context, parsed, invocation.child(context.stdout).output, invocation.signal, maxInputBytes);
1254
1563
  } finally {
1255
1564
  await invocation.close();
1256
1565
  }
1257
1566
  }
1258
- return new InputByteBudget(maxInputBytes).run(context, pdftotext);
1567
+ return new InputByteBudget2(maxInputBytes).run(context, pdftotext);
1259
1568
  }
1260
1569
  });
1261
1570
  }
@@ -1280,85 +1589,9 @@ function bytesToBase64(bytes) {
1280
1589
  }
1281
1590
  function* runPdftohtmlCliSteps(argv, files, signal) {
1282
1591
  let cooperativeWork = 63;
1283
- let xmlMode = false;
1284
- let toStdout = false;
1285
- let ignoreImages = false;
1286
- let dataUrls = false;
1287
- let firstPage = 1;
1288
- let lastPage = 0;
1289
- let zoom = 1;
1290
- let imageFmt = "png";
1291
- let encoding = "UTF-8";
1292
- let password = "";
1293
- const positionals = [];
1294
- for (let i = 0; i < argv.length; i++) {
1295
- if (++cooperativeWork % 64 === 0)
1296
- yield;
1297
- const arg = argv[i];
1298
- if (arg === "--") {
1299
- positionals.push(...argv.slice(i + 1));
1300
- break;
1301
- }
1302
- if (arg === "-v" || arg === "--version") {
1303
- return { exitCode: 0, stdout: "pdftohtml version 24.08.0\n", stderr: "" };
1304
- }
1305
- if (arg === "-h" || arg === "-help" || arg === "--help" || arg === "-?") {
1306
- return {
1307
- exitCode: 0,
1308
- stdout: "Usage: pdftohtml [options] <PDF-file> [<html-file>|<xml-file>]\n -xml / -stdout / -s / -i / -noframes / -c / -f <int> / -l <int>\n",
1309
- stderr: ""
1310
- };
1311
- }
1312
- if (arg === "-xml")
1313
- xmlMode = true;
1314
- else if (arg === "-stdout")
1315
- toStdout = true;
1316
- else if (arg === "-i")
1317
- ignoreImages = true;
1318
- else if (arg === "-dataurls")
1319
- dataUrls = true;
1320
- else if (arg === "-f")
1321
- firstPage = Math.max(1, Number(argv[++i] ?? "1") || 1);
1322
- else if (arg === "-l")
1323
- lastPage = Math.max(0, Number(argv[++i] ?? "0") || 0);
1324
- else if (arg === "-zoom") {
1325
- const z = Number.parseFloat(argv[++i] ?? "1");
1326
- if (Number.isFinite(z) && z > 0)
1327
- zoom = z;
1328
- } else if (arg === "-fmt") {
1329
- const fmtVal = (argv[++i] ?? "").toLowerCase();
1330
- if (fmtVal === "png")
1331
- imageFmt = "png";
1332
- else if (fmtVal === "jpg" || fmtVal === "jpeg")
1333
- imageFmt = "jpg";
1334
- else {
1335
- return { exitCode: 99, stdout: "", stderr: `Command Line Error: Invalid image format '${fmtVal}'
1336
- ` };
1337
- }
1338
- } else if (arg === "-enc") {
1339
- const nextEnc = argv[++i] ?? "";
1340
- if (!SUPPORTED_ENCODINGS.has(nextEnc)) {
1341
- return { exitCode: 99, stdout: "", stderr: `Command Line Error: Unknown encoding '${nextEnc}'
1342
- ` };
1343
- }
1344
- encoding = nextEnc;
1345
- } else if (arg === "-upw" || arg === "-opw")
1346
- password = argv[++i] ?? "";
1347
- else if (arg === "-s" || arg === "-noframes" || arg === "-c" || arg === "-p" || arg === "-q" || arg === "-hidden" || arg === "-nomerge" || arg === "-nodrm") {
1348
- } else if (!arg.startsWith("-") || arg === "-") {
1349
- positionals.push(arg);
1350
- }
1351
- }
1352
- const inputPath = positionals[0] ?? (files.has("-") ? "-" : void 0);
1353
- if (!inputPath) {
1354
- return { exitCode: 99, stdout: "", stderr: "Usage: pdftohtml [options] <PDF-file> [<html-file>]\n" };
1355
- }
1356
- const explicitOut = positionals[1];
1357
- const stdoutOutput = toStdout || explicitOut === "-" || inputPath === "-" && !explicitOut;
1358
- const defaultExt = xmlMode ? ".xml" : ".html";
1359
- const inputStem = inputPath.toLowerCase().endsWith(".pdf") ? inputPath.slice(0, -4) : inputPath;
1360
- const outPath = explicitOut ? explicitOut.endsWith(".html") || explicitOut.endsWith(".xml") ? explicitOut : `${explicitOut}${defaultExt}` : inputStem + defaultExt;
1361
- const imageDirectory = outPath.slice(0, outPath.lastIndexOf("/") + 1);
1592
+ const parsed = parseHtmlArguments(argv, files.has("-"));
1593
+ if ("exitCode" in parsed) return parsed;
1594
+ const { inputPath, outPath, imageDirectory, xmlMode, stdoutOutput, ignoreImages, dataUrls, firstPage, lastPage, zoom, imageFmt, encoding, password } = parsed;
1362
1595
  const pdfBytes = files.get(inputPath);
1363
1596
  if (!pdfBytes) {
1364
1597
  return { exitCode: 1, stdout: "", stderr: `I/O Error: Couldn't open file '${inputPath}'
@@ -1615,104 +1848,30 @@ function runPdftohtmlCliSync(argv, files, signal) {
1615
1848
  }
1616
1849
  return next.value;
1617
1850
  }
1618
- async function pdftohtml(context) {
1619
- let cooperativeWork = 63;
1851
+ async function pdftohtml(context, maxInputBytes = Infinity) {
1620
1852
  const invocation = createOutputOperation(context, { write: async () => {
1621
1853
  } });
1622
1854
  try {
1623
- const carrier = getCommandArguments(context);
1624
- const argv = [...carrier.args];
1625
- const vfsFiles = /* @__PURE__ */ new Map();
1626
- let accountedBytes = 0;
1627
- const chargeBytes = (delta) => {
1628
- if (delta > 0) {
1629
- accountedBytes += delta;
1630
- context.inputBudget?.check(accountedBytes);
1631
- }
1632
- };
1633
- let inputOperand;
1634
- for (let i = 0; i < argv.length; i++) {
1635
- if (++cooperativeWork % 64 === 0) await yieldTurn2(context.signal);
1636
- const arg = argv[i];
1637
- if (arg === "--") {
1638
- inputOperand = argv[i + 1];
1639
- break;
1640
- }
1641
- if (["-f", "-l", "-zoom", "-fmt", "-enc", "-upw", "-opw"].includes(arg)) {
1642
- i++;
1643
- } else if (arg === "-" || !arg.startsWith("-")) {
1644
- inputOperand = arg;
1645
- break;
1646
- }
1647
- }
1648
- if (inputOperand === "-") {
1649
- const chunks = [];
1650
- let total = 0;
1651
- for await (const chunk of readBytes2(context.stdin, invocation.signal)) {
1652
- if (++cooperativeWork % 64 === 0) await yieldTurn2(context.signal);
1653
- chunks.push(chunk);
1654
- total += chunk.byteLength;
1655
- chargeBytes(chunk.byteLength);
1656
- }
1657
- if (total > 0) {
1658
- const buf = new Uint8Array(total);
1659
- let off = 0;
1660
- for (const c of chunks) {
1661
- if (++cooperativeWork % 64 === 0) await yieldTurn2(context.signal);
1662
- buf.set(c, off);
1663
- off += c.byteLength;
1664
- }
1665
- vfsFiles.set("-", buf);
1666
- }
1667
- }
1668
- for (const token of inputOperand && inputOperand !== "-" ? [inputOperand] : []) {
1669
- if (++cooperativeWork % 64 === 0) await yieldTurn2(context.signal);
1670
- try {
1671
- const bytes = await context.fs.readFile(resolvePath2(context.cwd, token), { signal: invocation.signal });
1672
- chargeBytes(bytes.byteLength);
1673
- vfsFiles.set(token, bytes);
1674
- } catch {
1675
- }
1676
- }
1677
- context.inputBudget?.check(0);
1678
- const existingSnap = new Map(vfsFiles);
1679
- const res = await runPdftohtmlCli(argv, vfsFiles, invocation.signal);
1680
- if (res.stderr) {
1681
- await writeBytes2(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
1682
- }
1683
- if (res.stdout) {
1684
- const outBytes = new TextEncoder().encode(res.stdout);
1685
- const stdout = invocation.child(context.stdout);
1686
- await writeBytes2(stdout.output, outBytes, invocation.signal);
1687
- }
1688
- for (const [key, val] of vfsFiles.entries()) {
1689
- if (++cooperativeWork % 64 === 0) await yieldTurn2(context.signal);
1690
- if (existingSnap.get(key) !== val) {
1691
- const abs = resolvePath2(context.cwd, key);
1692
- try {
1693
- await writeFileOutput2(context, val, (data) => context.fs.writeFile(abs, data, { signal: invocation.signal }));
1694
- } catch (error) {
1695
- invocation.signal.throwIfAborted();
1696
- if (!(error instanceof Error) || !("code" in error)) throw error;
1697
- await writeBytes2(context.stderr, new TextEncoder().encode(`I/O Error: Couldn't open html file '${key}'
1698
- `), invocation.signal);
1699
- return { exitCode: 0 };
1700
- }
1701
- }
1855
+ const plan = parseHtmlArguments(getCommandArguments(context).args);
1856
+ const stdout = invocation.child(context.stdout);
1857
+ if ("exitCode" in plan) {
1858
+ if (plan.stdout) await writeBytes3(stdout.output, new TextEncoder().encode(plan.stdout), invocation.signal);
1859
+ if (plan.stderr) await writeBytes3(context.stderr, new TextEncoder().encode(plan.stderr), invocation.signal);
1860
+ return { exitCode: plan.exitCode };
1702
1861
  }
1703
- return { exitCode: res.exitCode };
1862
+ return await executeRetainedHtml(context, plan, stdout.output, invocation.signal, maxInputBytes);
1704
1863
  } finally {
1705
1864
  await invocation.close();
1706
1865
  }
1707
1866
  }
1708
1867
  function createPdftohtmlCommand(options = {}) {
1709
- const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
1868
+ const maxInputBytes = InputByteBudget2.limit(options.limits?.maxInputBytes);
1710
1869
  return Object.freeze({
1711
1870
  name: "pdftohtml",
1712
1871
  runtimeIdentity: commandRuntimeIdentity,
1713
1872
  description: "Convert PDF pages into HTML or XML layout documents via @poe-code/pdf-ast",
1714
1873
  execute(context) {
1715
- return new InputByteBudget(maxInputBytes).run(context, pdftohtml);
1874
+ return pdftohtml(context, maxInputBytes);
1716
1875
  }
1717
1876
  });
1718
1877
  }