@poe-platform/safe-bash 0.1.810 → 0.1.812

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 (276) hide show
  1. package/dist/audio-ast/flac-source.d.ts +13 -0
  2. package/dist/audio-ast/index.d.ts +2 -0
  3. package/dist/audio-ast/index.js +253 -179
  4. package/dist/audio-ast/vorbis.d.ts +14 -0
  5. package/dist/image-ast/index.js +1 -1
  6. package/dist/json-ast/backed-json-parser.d.ts +12 -1
  7. package/dist/json-ast/index.d.ts +1 -1
  8. package/dist/office-xml/index.d.ts +1 -0
  9. package/dist/office-xml/retained-xml-edits.d.ts +22 -0
  10. package/dist/pdf-ast/cos/qpdf-json-document.d.ts +2 -1
  11. package/dist/pdf-ast/cos/value-parser.d.ts +23 -2
  12. package/dist/pdf-ast/extract/retained-form-field-details.d.ts +20 -0
  13. package/dist/pdf-ast/extract/retained-form-fields.d.ts +17 -4
  14. package/dist/pdf-ast/index.d.ts +1 -0
  15. package/dist/pdf-ast/index.js +844 -384
  16. package/dist/pdf-ast/retained-document.d.ts +6 -0
  17. package/dist/safe-bash/audio-ast.browser.js +3 -1
  18. package/dist/safe-bash/chunks/{chunk-65TFMAZU.js → chunk-BUYRKFW2.js} +8 -35
  19. package/dist/safe-bash/chunks/{chunk-ZA5FQ34E.js → chunk-TPG55BAQ.js} +0 -2
  20. package/dist/safe-bash/command-chunks/{biff-ORSHM4YX-QYPGRDAZ.js → biff-YKPDH35C-MVQIWNKV.js} +2192 -2155
  21. package/dist/safe-bash/command-chunks/{chunk-HEHGHIE2.js → chunk-22MOB45U.js} +6 -6
  22. package/dist/safe-bash/command-chunks/{chunk-6DEWZMOL.js → chunk-2CORNDGF.js} +2 -2
  23. package/dist/safe-bash/command-chunks/{chunk-DCD32BEY.js → chunk-2JSDKQ4J.js} +201 -84
  24. package/dist/safe-bash/command-chunks/{chunk-6UHGIWFX.js → chunk-2ZFLMWOX.js} +1 -1
  25. package/dist/safe-bash/command-chunks/{chunk-HONWGFDA.js → chunk-33YCKZZX.js} +6 -6
  26. package/dist/safe-bash/command-chunks/{chunk-AXWPJRY6.js → chunk-36XGIPOG.js} +1 -1
  27. package/dist/safe-bash/command-chunks/{chunk-D5AYP2UM.js → chunk-3Q247UDJ.js} +26 -16
  28. package/dist/safe-bash/command-chunks/{chunk-32ADKP5E.js → chunk-456PHA3L.js} +1 -1
  29. package/dist/safe-bash/command-chunks/{chunk-UJXP3T6R.js → chunk-4CKFNXRN.js} +1 -1
  30. package/dist/safe-bash/command-chunks/{chunk-5L6GHFRW.js → chunk-554Z6IKP.js} +2 -2
  31. package/dist/safe-bash/command-chunks/{chunk-ORZRWT62.js → chunk-56NYSX65.js} +9 -9
  32. package/dist/safe-bash/command-chunks/{chunk-53JP3S6H.js → chunk-5HPU7D36.js} +4 -4
  33. package/dist/safe-bash/command-chunks/{chunk-HARUYHH7.js → chunk-5HUICAWD.js} +1 -1
  34. package/dist/safe-bash/command-chunks/{chunk-IC5GJI7E.js → chunk-5Q22ZLNC.js} +6 -6
  35. package/dist/safe-bash/command-chunks/{chunk-YO3V5RLY.js → chunk-6CCQI6XZ.js} +12 -12
  36. package/dist/safe-bash/command-chunks/{chunk-EO2IVGV7.js → chunk-6M6TM5Z5.js} +3 -3
  37. package/dist/safe-bash/command-chunks/{chunk-Z54Z3KRN.js → chunk-6QBMND4A.js} +1 -1
  38. package/dist/safe-bash/command-chunks/{chunk-INX4JMQ6.js → chunk-6VPQ3CDZ.js} +5 -5
  39. package/dist/safe-bash/command-chunks/{chunk-VGXVN3BX.js → chunk-7GKKMNL6.js} +8 -8
  40. package/dist/safe-bash/command-chunks/{chunk-TZJC67W3.js → chunk-7PVHO47B.js} +6 -6
  41. package/dist/safe-bash/command-chunks/{chunk-CM3C7AXJ.js → chunk-A2CLZMQZ.js} +1 -1
  42. package/dist/safe-bash/command-chunks/{chunk-ASR27KHW.js → chunk-A5FZBR7X.js} +4 -4
  43. package/dist/safe-bash/command-chunks/{chunk-DMDHE5KC.js → chunk-AHA6IWAJ.js} +6 -6
  44. package/dist/safe-bash/command-chunks/{chunk-PTZ55XXN.js → chunk-APEWTWCC.js} +6 -6
  45. package/dist/safe-bash/command-chunks/{chunk-YUVH6CE4.js → chunk-ATTWQVR2.js} +17 -17
  46. package/dist/safe-bash/command-chunks/{chunk-2VCKUNDZ.js → chunk-B2C3UPJS.js} +27 -17
  47. package/dist/safe-bash/command-chunks/{chunk-JON5DB3Z.js → chunk-B5LDP7AA.js} +2 -2
  48. package/dist/safe-bash/command-chunks/{chunk-YTFWPJ3F.js → chunk-CJQSAATC.js} +26 -26
  49. package/dist/safe-bash/command-chunks/{chunk-CHJL6JMU.js → chunk-COKYZUBW.js} +1 -1
  50. package/dist/safe-bash/command-chunks/{chunk-KCTV4NVX.js → chunk-CRV2Q3PB.js} +1 -1
  51. package/dist/safe-bash/command-chunks/{chunk-V3WXPCKN.js → chunk-CV7M2QJU.js} +7 -7
  52. package/dist/safe-bash/command-chunks/{chunk-VPDSQPSN.js → chunk-DM2CPMB4.js} +2 -2
  53. package/dist/safe-bash/command-chunks/{chunk-3DTDMEOP.js → chunk-EAGIJ4VW.js} +1 -1
  54. package/dist/safe-bash/command-chunks/{chunk-JW6CMBF2.js → chunk-EHSM5ZQS.js} +8 -8
  55. package/dist/safe-bash/command-chunks/{chunk-WIOH7ZQN.js → chunk-ENT3IV2G.js} +12 -12
  56. package/dist/safe-bash/command-chunks/{chunk-5IE4LJGB.js → chunk-EUT24Y5Z.js} +8 -8
  57. package/dist/safe-bash/command-chunks/{chunk-WC2OCF4H.js → chunk-FDCIPJBQ.js} +7 -7
  58. package/dist/safe-bash/command-chunks/{chunk-COKZFXHG.js → chunk-FIIAYCWS.js} +2 -2
  59. package/dist/safe-bash/command-chunks/{chunk-MWVFP2HY.js → chunk-GEM47B2P.js} +7 -7
  60. package/dist/safe-bash/command-chunks/{chunk-EHL6B34L.js → chunk-HDJVJTCK.js} +9 -9
  61. package/dist/safe-bash/command-chunks/{chunk-JMM3MNAY.js → chunk-HKATEVAP.js} +6 -6
  62. package/dist/safe-bash/command-chunks/{chunk-VWY3EAVQ.js → chunk-HTVIYLVB.js} +4 -4
  63. package/dist/safe-bash/command-chunks/{chunk-CHR2OD2U.js → chunk-HWQ2UHMT.js} +9 -9
  64. package/dist/safe-bash/command-chunks/{chunk-Z4QJMDK3.js → chunk-IT7TAC3F.js} +16 -16
  65. package/dist/safe-bash/command-chunks/{chunk-EWS4KYJE.js → chunk-JFYWVQ4V.js} +8 -8
  66. package/dist/safe-bash/command-chunks/{chunk-ZCX63QWA.js → chunk-JOCFI7TG.js} +1 -1
  67. package/dist/safe-bash/command-chunks/{chunk-F5WTH4O4.js → chunk-JQVHUSDD.js} +5 -5
  68. package/dist/safe-bash/command-chunks/{chunk-O4VJEGL6.js → chunk-K5GB2YMN.js} +10 -10
  69. package/dist/safe-bash/command-chunks/{chunk-27C3NT5V.js → chunk-KB7DUBVL.js} +5 -5
  70. package/dist/safe-bash/command-chunks/{chunk-4DZ32PI7.js → chunk-KCOJA7EM.js} +7 -7
  71. package/dist/safe-bash/command-chunks/{chunk-CAXJ4RLF.js → chunk-KJ4XXZIL.js} +12 -12
  72. package/dist/safe-bash/command-chunks/{chunk-U6QHTC5J.js → chunk-L5MCW6CM.js} +4 -4
  73. package/dist/safe-bash/command-chunks/{chunk-LVL3A7YE.js → chunk-LCZDBW55.js} +5 -5
  74. package/dist/safe-bash/command-chunks/{chunk-DJVRDUCA.js → chunk-LXLLA4PM.js} +17 -17
  75. package/dist/safe-bash/command-chunks/{chunk-K7AGAS3K.js → chunk-M7QE2MN7.js} +6 -6
  76. package/dist/safe-bash/command-chunks/{chunk-SWT6ILF2.js → chunk-MPUHH2KR.js} +3 -3
  77. package/dist/safe-bash/command-chunks/{chunk-3ZWBBS6U.js → chunk-NARD63DY.js} +437 -34
  78. package/dist/safe-bash/command-chunks/{chunk-DC3OJLRB.js → chunk-NQDIT667.js} +5 -5
  79. package/dist/safe-bash/command-chunks/{chunk-LWZVDDJA.js → chunk-NUGQQDGE.js} +5 -1
  80. package/dist/safe-bash/command-chunks/{chunk-MFLQZLFR.js → chunk-OA75SGN2.js} +7 -7
  81. package/dist/safe-bash/command-chunks/{chunk-5LATYOF7.js → chunk-OEJM666F.js} +5 -5
  82. package/dist/safe-bash/command-chunks/{chunk-AF25YYIO.js → chunk-PMAM4N33.js} +9 -9
  83. package/dist/safe-bash/command-chunks/{chunk-KMMAJ6H6.js → chunk-PNGDJA6M.js} +2 -2
  84. package/dist/safe-bash/command-chunks/{chunk-62BHPSKJ.js → chunk-Q6S57NOQ.js} +7 -7
  85. package/dist/safe-bash/command-chunks/{chunk-KJ3PEDI2.js → chunk-Q73EMLLZ.js} +146 -4
  86. package/dist/safe-bash/command-chunks/{chunk-FXKBM5KJ.js → chunk-QC5RMGSA.js} +3 -3
  87. package/dist/safe-bash/command-chunks/{chunk-UQ6UIZMM.js → chunk-QD7ZRDUN.js} +1 -1
  88. package/dist/safe-bash/command-chunks/{chunk-JHUYZZGV.js → chunk-QYMEASQ6.js} +4 -4
  89. package/dist/safe-bash/command-chunks/{chunk-3GY5VDIX.js → chunk-QZZ73J2O.js} +6 -6
  90. package/dist/safe-bash/command-chunks/{chunk-S2CYIGWH.js → chunk-R6EGGK5M.js} +7 -7
  91. package/dist/safe-bash/command-chunks/{chunk-7AVN3OBH.js → chunk-RHYJVTJO.js} +2 -2
  92. package/dist/safe-bash/command-chunks/{chunk-EWGDSO6U.js → chunk-RID6VYS3.js} +8 -8
  93. package/dist/safe-bash/command-chunks/{chunk-MMBRBANA.js → chunk-RNSKXOG3.js} +6 -6
  94. package/dist/safe-bash/command-chunks/{chunk-D3ZRZTY5.js → chunk-RQIQ75W5.js} +5 -5
  95. package/dist/safe-bash/command-chunks/{chunk-DWKQPLRT.js → chunk-RRL3Y562.js} +11 -11
  96. package/dist/safe-bash/command-chunks/{chunk-NXCMXD74.js → chunk-S6R3IB36.js} +1 -1
  97. package/dist/safe-bash/command-chunks/{chunk-XUPKFHAQ.js → chunk-SDTPO2VV.js} +7 -7
  98. package/dist/safe-bash/command-chunks/{chunk-PIAGKRFW.js → chunk-SPLOIABU.js} +3 -3
  99. package/dist/safe-bash/command-chunks/{chunk-Z5QOVRVH.js → chunk-SU26FZLJ.js} +1 -1
  100. package/dist/safe-bash/command-chunks/{chunk-WLTJDNSQ.js → chunk-TVH4JORU.js} +3 -3
  101. package/dist/safe-bash/command-chunks/{chunk-6XVMWFHD.js → chunk-TW73OXPR.js} +6 -6
  102. package/dist/safe-bash/command-chunks/{chunk-SFO43CID.js → chunk-UAXSE3XE.js} +5 -5
  103. package/dist/safe-bash/command-chunks/{chunk-K35BSUHO.js → chunk-UYWSIIUX.js} +7 -7
  104. package/dist/safe-bash/command-chunks/{chunk-2E2YEDVB.js → chunk-W5YSINXC.js} +6 -6
  105. package/dist/safe-bash/command-chunks/{chunk-EYNT4OEJ.js → chunk-WGG6G2KG.js} +7 -7
  106. package/dist/safe-bash/command-chunks/{chunk-DVQBZXMQ.js → chunk-WJCN2IXI.js} +2 -2
  107. package/dist/safe-bash/command-chunks/{chunk-XBZ4ZWGL.js → chunk-WVMHRNXZ.js} +3 -3
  108. package/dist/safe-bash/command-chunks/{chunk-7GXUCQI4.js → chunk-WXRYDALR.js} +4 -4
  109. package/dist/safe-bash/command-chunks/{chunk-S4IIOSRA.js → chunk-X7FA7ZD5.js} +8 -8
  110. package/dist/safe-bash/command-chunks/{chunk-DPR5CYQV.js → chunk-XITDDJFT.js} +2 -0
  111. package/dist/safe-bash/command-chunks/{chunk-SFCERNHU.js → chunk-XPD636C4.js} +3 -3
  112. package/dist/safe-bash/command-chunks/{chunk-HYDWQLJ3.js → chunk-XRVKWGVQ.js} +6 -6
  113. package/dist/safe-bash/command-chunks/{chunk-ZEPDT6I5.js → chunk-XVLWZTPY.js} +249 -51
  114. package/dist/safe-bash/command-chunks/{chunk-3UJWHRK4.js → chunk-XVP6V5K3.js} +6 -6
  115. package/dist/safe-bash/command-chunks/{chunk-KTI3BULE.js → chunk-XZ2FWFNV.js} +6 -6
  116. package/dist/safe-bash/command-chunks/{chunk-QK3CHRGL.js → chunk-Y4EYCZFT.js} +10 -10
  117. package/dist/safe-bash/command-chunks/{chunk-GTWVMFBK.js → chunk-YORJDX4V.js} +4 -4
  118. package/dist/safe-bash/command-chunks/{chunk-H6F5SN2N.js → chunk-YSMNXMAO.js} +4 -4
  119. package/dist/safe-bash/command-chunks/{chunk-SE5SJ4JT.js → chunk-Z2JW6M2D.js} +3 -3
  120. package/dist/safe-bash/command-chunks/{chunk-WH3TIOTS.js → chunk-ZEGNRZV2.js} +9 -2
  121. package/dist/safe-bash/command-chunks/{chunk-BYZUOF6X.js → chunk-ZEX53S5I.js} +4010 -3980
  122. package/dist/safe-bash/command-chunks/{chunk-HQYFRQ5W.js → chunk-ZIIO6GRY.js} +7 -7
  123. package/dist/safe-bash/command-chunks/{chunk-NTRZMQZP.js → chunk-ZMHEGDU2.js} +2 -2
  124. package/dist/safe-bash/command-chunks/{chunk-EYBXHGA6.js → chunk-ZXR6LXV5.js} +2 -2
  125. package/dist/safe-bash/command-chunks/{command-engine-BEWABZ75.js → command-engine-BCUQGJJ4.js} +58 -21
  126. package/dist/safe-bash/command-chunks/{engine-MEPOXIXT-WZMRHACG.js → engine-LAUEWYSQ-DQCEI5HE.js} +1 -1
  127. package/dist/safe-bash/command-chunks/pdf-XHHFTOT4-UJJYOYJ2.js +573 -0
  128. package/dist/safe-bash/commands/diff-patch/index.js +0 -3
  129. package/dist/safe-bash/commands/diff3/index.js +0 -2
  130. package/dist/safe-bash/full-core.browser.js +2 -2
  131. package/dist/safe-bash/plugins/index.browser.js +2 -2
  132. package/dist/safe-bash/plugins/index.js +3 -1
  133. package/dist/safe-bash/plugins/portable-commands.d.ts +1 -1
  134. package/dist/safe-bash/plugins/portable-commands.js +5 -3
  135. package/dist/safe-bash/registry-entry.browser.js +1 -1
  136. package/dist/safe-bash-command-apply-patch/apply.js +4 -4
  137. package/dist/safe-bash-command-apply-patch/index.js +4 -4
  138. package/dist/safe-bash-command-apply-patch/matcher.js +2 -2
  139. package/dist/safe-bash-command-apply-patch/parser.js +2 -2
  140. package/dist/safe-bash-command-apply-patch/shared.d.ts +2 -0
  141. package/dist/safe-bash-command-apply-patch/shared.js +1 -1
  142. package/dist/safe-bash-command-diff/index.js +0 -2
  143. package/dist/safe-bash-command-diff3/index.js +830 -56
  144. package/dist/safe-bash-command-ffmpeg/index.js +1 -1
  145. package/dist/safe-bash-command-ffprobe/index.js +2 -2
  146. package/dist/safe-bash-command-ffprobe/media.js +2 -2
  147. package/dist/safe-bash-command-html-to-markdown/index.js +75 -21
  148. package/dist/safe-bash-command-pandoc/command.js +3 -3
  149. package/dist/safe-bash-command-pandoc/execution.d.ts +2 -2
  150. package/dist/safe-bash-command-pandoc/index.d.ts +1 -1
  151. package/dist/safe-bash-command-pandoc/index.js +14 -14
  152. package/dist/safe-bash-command-pandoc/lua-filters.js +2 -2
  153. package/dist/safe-bash-command-pandoc/types.d.ts +17 -2
  154. package/dist/safe-bash-command-patch/index.js +2 -2
  155. package/dist/safe-bash-command-patch/patch-publication.js +1 -1
  156. package/dist/safe-bash-command-patch/patch.js +2 -2
  157. package/dist/safe-bash-command-pdftk/index.js +649 -265
  158. package/dist/safe-bash-command-pptx/command-engine.d.ts +12 -3
  159. package/dist/safe-bash-command-pptx/engine.d.ts +2 -2
  160. package/dist/safe-bash-command-pptx/engine.js +1 -1
  161. package/dist/safe-bash-command-qpdf/index.js +115 -9
  162. package/dist/safe-bash-command-soffice/index.js +1 -1
  163. package/dist/safe-bash-command-ssconvert/index.js +2 -2
  164. package/dist/safe-bash-command-xq/index.js +45 -29
  165. package/dist/safe-bash-diff-engine/document.d.ts +2 -1
  166. package/dist/safe-bash-diff-engine/document.js +7 -4
  167. package/dist/safe-bash-presentation-engine/accessibility.js +30 -30
  168. package/dist/safe-bash-presentation-engine/animation-editing.js +15 -15
  169. package/dist/safe-bash-presentation-engine/animations.js +15 -15
  170. package/dist/safe-bash-presentation-engine/backgrounds.js +16 -16
  171. package/dist/safe-bash-presentation-engine/bytes.js +3 -3
  172. package/dist/safe-bash-presentation-engine/chart-editing.js +33 -33
  173. package/dist/safe-bash-presentation-engine/chart-object-operations.js +24 -24
  174. package/dist/safe-bash-presentation-engine/charts.js +30 -30
  175. package/dist/safe-bash-presentation-engine/command-placeholder.js +56 -55
  176. package/dist/safe-bash-presentation-engine/comments.js +16 -16
  177. package/dist/safe-bash-presentation-engine/connector-operations.js +31 -31
  178. package/dist/safe-bash-presentation-engine/connectors.js +28 -28
  179. package/dist/safe-bash-presentation-engine/content-types.js +4 -4
  180. package/dist/safe-bash-presentation-engine/creation.js +6 -6
  181. package/dist/safe-bash-presentation-engine/diff.js +31 -31
  182. package/dist/safe-bash-presentation-engine/drawing-format.js +19 -19
  183. package/dist/safe-bash-presentation-engine/drawing-operations.js +30 -30
  184. package/dist/safe-bash-presentation-engine/drawing-schema.js +20 -20
  185. package/dist/safe-bash-presentation-engine/equations.js +16 -16
  186. package/dist/safe-bash-presentation-engine/errors.js +2 -2
  187. package/dist/safe-bash-presentation-engine/fields.js +16 -16
  188. package/dist/safe-bash-presentation-engine/font-metrics.js +3 -3
  189. package/dist/safe-bash-presentation-engine/image-extraction.js +19 -19
  190. package/dist/safe-bash-presentation-engine/image-formatting.js +31 -31
  191. package/dist/safe-bash-presentation-engine/image-insertion.js +17 -17
  192. package/dist/safe-bash-presentation-engine/image-replacement.js +20 -20
  193. package/dist/safe-bash-presentation-engine/image-value.js +4 -4
  194. package/dist/safe-bash-presentation-engine/images.js +18 -18
  195. package/dist/safe-bash-presentation-engine/index.d.ts +1 -1
  196. package/dist/safe-bash-presentation-engine/index.js +99 -95
  197. package/dist/safe-bash-presentation-engine/layouts.js +15 -15
  198. package/dist/safe-bash-presentation-engine/length.js +3 -3
  199. package/dist/safe-bash-presentation-engine/links.js +15 -15
  200. package/dist/safe-bash-presentation-engine/masters.js +14 -14
  201. package/dist/safe-bash-presentation-engine/media-editing.js +23 -23
  202. package/dist/safe-bash-presentation-engine/media-extraction.js +16 -16
  203. package/dist/safe-bash-presentation-engine/media.js +15 -15
  204. package/dist/safe-bash-presentation-engine/memberships.js +14 -14
  205. package/dist/safe-bash-presentation-engine/notes.js +15 -15
  206. package/dist/safe-bash-presentation-engine/ole-enum.js +4 -4
  207. package/dist/safe-bash-presentation-engine/ole-insertion.js +19 -19
  208. package/dist/safe-bash-presentation-engine/opaque-objects.js +9 -9
  209. package/dist/safe-bash-presentation-engine/package-reader.js +5 -5
  210. package/dist/safe-bash-presentation-engine/package-tools.js +15 -15
  211. package/dist/safe-bash-presentation-engine/package-uri.js +3 -3
  212. package/dist/safe-bash-presentation-engine/package-writer.js +4 -4
  213. package/dist/safe-bash-presentation-engine/presentation-model.js +55 -54
  214. package/dist/safe-bash-presentation-engine/presentation-settings.js +13 -13
  215. package/dist/safe-bash-presentation-engine/properties.js +15 -15
  216. package/dist/safe-bash-presentation-engine/relationships.js +4 -4
  217. package/dist/safe-bash-presentation-engine/resource-limits.js +1 -1
  218. package/dist/safe-bash-presentation-engine/retained-inspection.js +12 -12
  219. package/dist/safe-bash-presentation-engine/retained-package.js +4 -4
  220. package/dist/safe-bash-presentation-engine/retained-slide-publication.d.ts +24 -0
  221. package/dist/safe-bash-presentation-engine/retained-slide-settings.d.ts +15 -0
  222. package/dist/safe-bash-presentation-engine/retained-text.js +17 -17
  223. package/dist/safe-bash-presentation-engine/sanitize.js +16 -16
  224. package/dist/safe-bash-presentation-engine/selectors.js +10 -10
  225. package/dist/safe-bash-presentation-engine/shape-groups.js +30 -30
  226. package/dist/safe-bash-presentation-engine/shape-operations.js +29 -29
  227. package/dist/safe-bash-presentation-engine/shape-path-operations.js +31 -31
  228. package/dist/safe-bash-presentation-engine/shape-paths.js +15 -15
  229. package/dist/safe-bash-presentation-engine/shape-presets.js +3 -3
  230. package/dist/safe-bash-presentation-engine/shape-selection.js +30 -30
  231. package/dist/safe-bash-presentation-engine/shape-transforms.js +17 -17
  232. package/dist/safe-bash-presentation-engine/shapes.js +26 -26
  233. package/dist/safe-bash-presentation-engine/slide-copy.js +16 -16
  234. package/dist/safe-bash-presentation-engine/slide-import.js +17 -17
  235. package/dist/safe-bash-presentation-engine/slide-merge-split.js +19 -19
  236. package/dist/safe-bash-presentation-engine/slide-model.js +42 -42
  237. package/dist/safe-bash-presentation-engine/slide-removal.js +17 -17
  238. package/dist/safe-bash-presentation-engine/slide-transfer-budget.js +9 -9
  239. package/dist/safe-bash-presentation-engine/slides.d.ts +3 -0
  240. package/dist/safe-bash-presentation-engine/slides.js +24 -16
  241. package/dist/safe-bash-presentation-engine/table-operations.js +32 -32
  242. package/dist/safe-bash-presentation-engine/table-spans.js +31 -31
  243. package/dist/safe-bash-presentation-engine/tables.js +30 -30
  244. package/dist/safe-bash-presentation-engine/tags.js +15 -15
  245. package/dist/safe-bash-presentation-engine/template-bindings.js +32 -32
  246. package/dist/safe-bash-presentation-engine/template-repeat.js +39 -39
  247. package/dist/safe-bash-presentation-engine/text-fitting.js +26 -26
  248. package/dist/safe-bash-presentation-engine/text-frames.js +26 -26
  249. package/dist/safe-bash-presentation-engine/text-paragraphs.js +26 -26
  250. package/dist/safe-bash-presentation-engine/text-reading.js +11 -11
  251. package/dist/safe-bash-presentation-engine/text-replacement.js +16 -16
  252. package/dist/safe-bash-presentation-engine/text-runs.js +19 -19
  253. package/dist/safe-bash-presentation-engine/themes.js +15 -15
  254. package/dist/safe-bash-presentation-engine/transitions.js +15 -15
  255. package/dist/safe-bash-presentation-engine/validation.js +9 -9
  256. package/dist/safe-bash-presentation-engine/xml-parts.js +15 -15
  257. package/dist/safe-bash-presentation-engine/xml-view.js +3 -3
  258. package/dist/safe-bash-presentation-engine/xml.js +3 -3
  259. package/dist/safe-bash-xml-engine/json.d.ts +1 -0
  260. package/dist/safe-bash-xml-engine/json.js +203 -0
  261. package/dist/safe-bash-xml-engine/stored-json.d.ts +5 -0
  262. package/dist/spreadsheet-engine/rendering/print/bidi-runs.d.ts +5 -0
  263. package/dist/spreadsheet-engine/rendering/print/bidi-runs.js +35 -0
  264. package/dist/spreadsheet-engine/rendering/print/control-bidi.d.ts +8 -0
  265. package/dist/spreadsheet-engine/rendering/print/control-bidi.js +80 -0
  266. package/dist/spreadsheet-format-xls/biff-encrypted-properties.d.ts +4 -4
  267. package/dist/spreadsheet-format-xls/biff-encrypted-properties.js +76 -30
  268. package/dist/spreadsheet-format-xls/biff-encryption.js +1 -1
  269. package/dist/spreadsheet-format-xls/biff-metadata.d.ts +1 -0
  270. package/dist/spreadsheet-format-xls/biff-metadata.js +2 -2
  271. package/dist/spreadsheet-format-xls/biff-property-bytes.d.ts +4 -1
  272. package/dist/spreadsheet-format-xls/biff-property-bytes.js +1 -1
  273. package/dist/spreadsheet-format-xls/biff-range.js +1 -1
  274. package/dist/spreadsheet-format-xls/biff-write-metadata.js +10 -1
  275. package/package.json +5 -2
  276. package/dist/safe-bash/command-chunks/pdf-LOZAXXS6-ERI57IAV.js +0 -557
@@ -1,35 +1,376 @@
1
1
  import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
2
2
 
3
- // packages/safe-bash-command-pdftk/src/index.ts
3
+ // packages/safe-bash-command-pdftk/src/retained-fields.ts
4
+ async function* retainedFieldReport(document, utf8, signal) {
5
+ const encoder = new TextEncoder();
6
+ let work = 0;
7
+ async function* line(prefix, value) {
8
+ let part = prefix;
9
+ for (const char of String(value)) {
10
+ const code = char.codePointAt(0);
11
+ part += !utf8 && code > 127 ? `&#${code};` : char;
12
+ if (part.length >= 4096) {
13
+ signal.throwIfAborted();
14
+ if (++work % 16 === 0) await new Promise((resolve) => setTimeout(resolve, 0));
15
+ yield encoder.encode(part);
16
+ part = "";
17
+ }
18
+ }
19
+ signal.throwIfAborted();
20
+ yield encoder.encode(part + "\n");
21
+ }
22
+ for await (const field of document.formFieldDetails()) {
23
+ yield encoder.encode("---\n");
24
+ yield* line("FieldType: ", field.type === "checkbox" ? "Button" : field.type === "choice" ? "Choice" : "Text");
25
+ yield* line("FieldName: ", field.name);
26
+ if (field.altName) yield* line("FieldNameAlt: ", field.altName);
27
+ yield* line("FieldFlags: ", field.flags);
28
+ for await (const value of field.values()) yield* line("FieldValue: ", value);
29
+ if (field.defaultValue !== void 0 && field.defaultValue !== "") yield* line("FieldValueDefault: ", field.defaultValue);
30
+ yield* line("FieldJustification: ", field.justification);
31
+ for await (const option of field.options()) yield* line("FieldStateOption: ", option);
32
+ if (field.maxLength !== void 0) yield* line("FieldMaxLength: ", field.maxLength);
33
+ }
34
+ }
35
+
36
+ // packages/safe-bash-command-pdftk/src/retained.ts
37
+ import { PdfError, PdfFileSource, PdfRetainedDocument, retainedCosObjects } from "../pdf-ast/index.js";
38
+ import { FsError } from "../safe-bash-contracts/errors.js";
39
+ import { writeBytes } from "../safe-bash-contracts/io.js";
4
40
  import { resolvePath } from "../safe-bash-contracts/path.js";
5
- import { yieldTurn, drainCooperativeSteps as drainSteps } from "../safe-bash-contracts/yield.js";
6
- import { InputByteBudget } from "../safe-bash-contracts/io.js";
7
41
  import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
8
- import {
9
- commandRuntimeIdentity,
10
- getCommandArguments
11
- } from "../safe-bash-contracts/command.js";
12
- import { readBytes, writeBytes } from "../safe-bash-contracts/io.js";
13
- import { createOutputOperation } from "../safe-bash-contracts/output.js";
14
- import {
15
- PdfDocument,
16
- cosArray,
17
- cosDict,
18
- cosHexString,
19
- cosName,
20
- cosNumber,
21
- cosStream,
22
- cosString,
23
- decodePdfString,
24
- dictDelete,
25
- dictGet,
26
- dictSet,
27
- flattenDocumentFormFields,
28
- getDocumentFormFields,
29
- parseFormDataBytes,
30
- resolveDestinationPageIndex,
31
- setDocumentFormField
32
- } from "../pdf-ast/index.js";
42
+
43
+ // packages/safe-bash-command-pdftk/src/retained-annots.ts
44
+ import { IntegerTable, PagedStorage } from "@poe-platform/safe-fs/storage";
45
+ import { PdfMutableObjectStore, decodePdfString, dictGet } from "../pdf-ast/index.js";
46
+ async function* retainedAnnotationReport(document, storage, utf8, signal) {
47
+ const backing = new PagedStorage({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), pages = new IntegerTable(backing, 64);
48
+ let pageCount = 0, work = 0, failed = false;
49
+ const encoder = new TextEncoder();
50
+ async function checkpoint() {
51
+ signal.throwIfAborted();
52
+ if (++work % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
53
+ signal.throwIfAborted();
54
+ }
55
+ async function resolve(node) {
56
+ await checkpoint();
57
+ const result = await document.lookup(node);
58
+ return result?.stream ? void 0 : result?.value;
59
+ }
60
+ async function* line(prefix, value, encode = false) {
61
+ let part = prefix;
62
+ for (const char of String(value)) {
63
+ const code = char.codePointAt(0);
64
+ part += encode && !utf8 && code > 127 ? `&#${code};` : char;
65
+ if (part.length >= 4096) {
66
+ await checkpoint();
67
+ yield encoder.encode(part);
68
+ part = "";
69
+ }
70
+ }
71
+ yield encoder.encode(part + "\n");
72
+ }
73
+ async function* walk(start, key) {
74
+ if (!start) return;
75
+ const stack = new PdfMutableObjectStore(storage, { signal }), seen = new IntegerTable(backing, 64);
76
+ let pending = 0, failed2 = false;
77
+ const push = async (value) => {
78
+ await checkpoint();
79
+ await stack.set({ objectNumber: ++pending, generationNumber: 0, value });
80
+ };
81
+ try {
82
+ await push(start);
83
+ while (pending) {
84
+ await checkpoint();
85
+ const raw = (await stack.get(pending--)).value;
86
+ if (raw.kind === "ref") {
87
+ if (await seen.get(BigInt(raw.objectNumber))) continue;
88
+ await seen.set(BigInt(raw.objectNumber), 1n);
89
+ }
90
+ const value = await resolve(raw);
91
+ if (value?.kind === "array" && key === "Next") {
92
+ for (let i = value.items.length - 1; i >= 0; i--) await push(value.items[i]);
93
+ continue;
94
+ }
95
+ if (value?.kind !== "dict") continue;
96
+ yield value;
97
+ const child = dictGet(value, key);
98
+ if (key === "Next") {
99
+ if (child) await push(child);
100
+ } else {
101
+ const kids = await resolve(child);
102
+ if (kids?.kind === "array") for (let i = kids.items.length - 1; i >= 0; i--) await push(kids.items[i]);
103
+ }
104
+ }
105
+ } catch (error) {
106
+ failed2 = true;
107
+ throw error;
108
+ } finally {
109
+ await stack.close().catch((error) => {
110
+ if (!failed2) throw error;
111
+ });
112
+ }
113
+ }
114
+ async function destinationIndex(raw) {
115
+ let node = await resolve(raw);
116
+ if (node?.kind === "dict") {
117
+ const target = dictGet(node, "D") ?? dictGet(node, "Dest");
118
+ if (target) node = await resolve(target);
119
+ }
120
+ if (node?.kind === "string" || node?.kind === "name") {
121
+ const name = node.kind === "string" ? decodePdfString(node) : node.decoded;
122
+ const root = await resolve(document.crossReference.rootRef);
123
+ let target;
124
+ if (root?.kind === "dict") {
125
+ const legacy = await resolve(dictGet(root, "Dests"));
126
+ if (legacy?.kind === "dict") target = dictGet(legacy, name);
127
+ if (!target) {
128
+ const names = await resolve(dictGet(root, "Names"));
129
+ if (names?.kind === "dict") for await (const branch of walk(dictGet(names, "Dests"), "Kids")) {
130
+ const pairs = await resolve(dictGet(branch, "Names"));
131
+ if (pairs?.kind === "array") for (let i = 0; i + 1 < pairs.items.length; i += 2) {
132
+ const key = await resolve(pairs.items[i]);
133
+ if ((key?.kind === "string" ? decodePdfString(key) : key?.kind === "name" ? key.decoded : "") === name) {
134
+ target = pairs.items[i + 1];
135
+ break;
136
+ }
137
+ }
138
+ if (target) break;
139
+ }
140
+ }
141
+ }
142
+ node = await resolve(target);
143
+ if (node?.kind === "dict") {
144
+ const inner = dictGet(node, "D");
145
+ if (inner) node = await resolve(inner);
146
+ }
147
+ }
148
+ if (node?.kind !== "array" || !node.items.length) return;
149
+ const first = node.items[0];
150
+ if (first.kind === "ref") {
151
+ const found = await pages.get(BigInt(first.objectNumber));
152
+ return found ? Number(found) - 1 : void 0;
153
+ }
154
+ const number = await resolve(first);
155
+ return number?.kind === "number" && number.value >= 0 && number.value < pageCount ? Math.round(number.value) : void 0;
156
+ }
157
+ async function destinationText(raw) {
158
+ const node = await resolve(raw);
159
+ if (node?.kind === "string") return decodePdfString(node);
160
+ if (node?.kind === "name") return node.decoded;
161
+ if (node?.kind === "array") {
162
+ const first = node.items[0];
163
+ if (first?.kind === "ref") {
164
+ const found = await pages.get(BigInt(first.objectNumber));
165
+ if (found) return `page ${found}`;
166
+ } else if (first?.kind === "number") return `page ${first.value + 1}`;
167
+ }
168
+ if (node?.kind === "dict") {
169
+ const index = await destinationIndex(node);
170
+ if (index !== void 0) return `page ${index + 1}`;
171
+ }
172
+ return;
173
+ }
174
+ async function* stringField(dict, key, label) {
175
+ const node = await resolve(dictGet(dict, key));
176
+ if (node?.kind === "string") yield* line(label, decodePdfString(node), true);
177
+ }
178
+ try {
179
+ for await (const page of document.pages()) {
180
+ pageCount++;
181
+ if (page.reference && !await pages.get(BigInt(page.reference.objectNumber))) await pages.set(BigInt(page.reference.objectNumber), BigInt(page.index + 1));
182
+ }
183
+ for (let i = 0; i < 2; i++) {
184
+ const id = await resolve(document.crossReference.idArray?.items[i]);
185
+ if (id?.kind !== "string") yield* line(`PdfID${i}: `, "00000000000000000000000000000000");
186
+ else {
187
+ yield encoder.encode(`PdfID${i}: `);
188
+ for (let at = 0; at < id.bytes.length; at += 2048) {
189
+ await checkpoint();
190
+ let text = "";
191
+ for (const byte of id.bytes.subarray(at, at + 2048)) text += byte.toString(16).padStart(2, "0");
192
+ yield encoder.encode(text);
193
+ }
194
+ yield encoder.encode("\n");
195
+ }
196
+ }
197
+ yield* line("NumberOfPages: ", pageCount);
198
+ for await (const page of document.pages()) {
199
+ const annotations = await resolve(dictGet(page.dict, "Annots"));
200
+ if (annotations?.kind !== "array") continue;
201
+ for (const item of annotations.items) {
202
+ const annotation = await resolve(item);
203
+ if (annotation?.kind !== "dict") continue;
204
+ const subtype = await resolve(dictGet(annotation, "Subtype")), rect = await resolve(dictGet(annotation, "Rect"));
205
+ const numbers = [];
206
+ if (rect?.kind === "array") for (const value of rect.items) {
207
+ const number = await resolve(value);
208
+ if (numbers.length < 4) numbers.push(number?.kind === "number" ? number.value : 0);
209
+ }
210
+ else numbers.push(0, 0, 0, 0);
211
+ yield encoder.encode("---\n");
212
+ yield* line("AnnotSubtype: ", subtype?.kind === "name" ? subtype.decoded : "Annot");
213
+ yield* line("AnnotRect: ", numbers.join(" "));
214
+ for (const [key, label] of [["NM", "Name"], ["T", "Title"], ["Subj", "Subj"], ["Contents", "Contents"]]) yield* stringField(annotation, key, `Annot${label}: `);
215
+ const color = await resolve(dictGet(annotation, "C"));
216
+ if (color?.kind === "array" && color.items.length >= 3) {
217
+ const channels = [];
218
+ for (const value of color.items.slice(0, 3)) {
219
+ const number = await resolve(value);
220
+ channels.push(number?.kind === "number" ? number.value : 0);
221
+ }
222
+ yield* line("AnnotColor: ", channels.join(" "));
223
+ }
224
+ const open = await resolve(dictGet(annotation, "Open"));
225
+ if (open?.kind === "boolean") yield* line("AnnotOpen: ", open.value);
226
+ yield* stringField(annotation, "M", "AnnotModificationDate: ");
227
+ const flags = await resolve(dictGet(annotation, "F"));
228
+ yield* line("AnnotFlags: ", flags?.kind === "number" ? flags.value : 0);
229
+ yield* line("AnnotPageNumber: ", page.index + 1);
230
+ const action = dictGet(annotation, "A");
231
+ if (action) for await (const dict of walk(action, "Next")) {
232
+ const type = await resolve(dictGet(dict, "S"));
233
+ if (type?.kind === "name" && type.decoded) yield* line("AnnotActionType: ", type.decoded);
234
+ yield* stringField(dict, "URI", "AnnotActionURI: ");
235
+ const dest = dictGet(dict, "D"), text = await destinationText(dest);
236
+ if (text) yield* line("AnnotActionDest: ", text, true);
237
+ const index = await destinationIndex(dest ?? dict);
238
+ if (index !== void 0) yield* line("AnnotActionPageNumber: ", index + 1);
239
+ const file = await resolve(dictGet(dict, "F"));
240
+ if (file?.kind === "string") yield* line("AnnotActionFile: ", decodePdfString(file), true);
241
+ else if (file?.kind === "dict") {
242
+ const name = await resolve(dictGet(file, "UF") ?? dictGet(file, "F"));
243
+ if (name?.kind === "string") yield* line("AnnotActionFile: ", decodePdfString(name), true);
244
+ }
245
+ }
246
+ else if (dictGet(annotation, "Dest")) {
247
+ yield* line("AnnotActionType: ", "GoTo");
248
+ const dest = dictGet(annotation, "Dest"), text = await destinationText(dest);
249
+ if (text) yield* line("AnnotActionDest: ", text, true);
250
+ const index = await destinationIndex(dest);
251
+ if (index !== void 0) yield* line("AnnotActionPageNumber: ", index + 1);
252
+ }
253
+ }
254
+ }
255
+ } catch (error) {
256
+ failed = true;
257
+ throw error;
258
+ } finally {
259
+ await backing.close().catch((error) => {
260
+ if (!failed) throw error;
261
+ });
262
+ }
263
+ }
264
+
265
+ // packages/safe-bash-command-pdftk/src/retained.ts
266
+ async function executeRetainedPdftk(context, options) {
267
+ const signal = context.signal, storage = { fs: context.fs, directory: resolvePath(context.cwd, context.env.TMPDIR || "/tmp") };
268
+ const inputs = /* @__PURE__ */ new Map();
269
+ let document, output, total = 0, failed = false;
270
+ const diagnostic = async (message) => {
271
+ await writeBytes(context.stderr, new TextEncoder().encode(message), signal);
272
+ return { exitCode: 1 };
273
+ };
274
+ try {
275
+ await context.fs.mkdir(storage.directory, { recursive: true, signal });
276
+ const maximum = context.inputBudget?.maxBytes ?? Infinity;
277
+ if (options.inputs.some((input) => input.file === "-")) {
278
+ const source = await PdfFileSource.fromStream(context.fs, storage.directory, context.stdin, { signal, maxInputBytes: maximum });
279
+ inputs.set("-", source);
280
+ total += source.size;
281
+ context.inputBudget?.check(total);
282
+ }
283
+ for (const input of options.inputs) {
284
+ if (inputs.has(input.file)) continue;
285
+ let source;
286
+ try {
287
+ source = await PdfFileSource.open(context.fs, resolvePath(context.cwd, input.file), { signal, maxInputBytes: maximum - total });
288
+ } catch (error) {
289
+ signal.throwIfAborted();
290
+ if (error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR", "EACCES", "EISDIR"].includes(String(error.code)) || error instanceof PdfError && error.message === "PDF source must be a regular file") {
291
+ inputs.set(input.file, void 0);
292
+ continue;
293
+ }
294
+ throw error;
295
+ }
296
+ inputs.set(input.file, source);
297
+ total += source.size;
298
+ context.inputBudget?.check(total);
299
+ }
300
+ for (const input of options.inputs) {
301
+ const source = inputs.get(input.file);
302
+ if (!source) return await diagnostic(`Error: Unable to find file '${input.file}'
303
+ `);
304
+ try {
305
+ document = await PdfRetainedDocument.open(source, storage, { signal, recovery: "strict", ...input.password ? { password: input.password } : {} });
306
+ for await (const object of retainedCosObjects(document, storage, { signal })) if (object.stream) for await (const ignored of object.stream.chunks) void ignored;
307
+ for await (const ignored of document.pages()) void ignored;
308
+ } catch (error) {
309
+ signal.throwIfAborted();
310
+ if (!(error instanceof PdfError) || error.code === "E_LIMIT" || error.code === "E_CANCELLED") throw error;
311
+ return await diagnostic(`Error: Failed to open PDF '${input.file}': ${error.message}
312
+ `);
313
+ }
314
+ await document.close();
315
+ document = void 0;
316
+ await source.releaseCache();
317
+ }
318
+ const primary = options.inputs[0];
319
+ document = await PdfRetainedDocument.open(inputs.get(primary.file), storage, { signal, recovery: "strict", ...primary.password ? { password: primary.password } : {} });
320
+ output = await PdfFileSource.fromStream(context.fs, storage.directory, options.operation === "dump_data_fields" || options.operation === "dump_data_fields_utf8" ? retainedFieldReport(document, options.operation.endsWith("_utf8"), signal) : retainedAnnotationReport(document, storage, options.operation.endsWith("_utf8"), signal), { signal });
321
+ const destination = options.outputTarget;
322
+ if (!destination || destination === "-") for await (const bytes of output.stream(0, output.size, signal)) await writeBytes(context.stdout, bytes, signal);
323
+ else {
324
+ try {
325
+ await publish(context, resolvePath(context.cwd, destination), output);
326
+ } catch (error) {
327
+ signal.throwIfAborted();
328
+ if (!(error instanceof Error) || !("code" in error)) throw error;
329
+ return await diagnostic(`Error: Failed to open output file '${destination}': ${error.code}.
330
+ `);
331
+ }
332
+ }
333
+ return { exitCode: 0 };
334
+ } catch (error) {
335
+ failed = true;
336
+ throw error;
337
+ } finally {
338
+ const results = await Promise.allSettled([document?.close(), output?.close(), ...[...inputs.values()].map((source) => source?.close())]);
339
+ if (!failed) {
340
+ for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
341
+ }
342
+ }
343
+ }
344
+ async function publish(context, path, source) {
345
+ const fs = context.fs, signal = context.signal;
346
+ const capabilities = await fs.capabilitiesFor?.(path, { signal, create: true, stagingAncestry: true }) ?? fs.capabilities;
347
+ if (!capabilities.atomicFileStaging || !capabilities.retainedStagingWrite || !capabilities.retainedStagingCleanup || !capabilities.atomicStagingAncestry || !fs.prepareStagingResolution || !fs.createStagedFile || !fs.publishStagedFile) throw new FsError("ENOTSUP", { path, message: "PDF output requires retained atomic staging" });
348
+ const resolution = await fs.prepareStagingResolution(path, { signal }), directory = resolvePath(resolution.path, "..");
349
+ const staging = await fs.createStagedFile(`${directory}/.pdf-${crypto.randomUUID()}`, "output", { type: "file", data: new Uint8Array() }, { parent: resolution.parent, retainCleanup: true, signal });
350
+ let failed = false;
351
+ try {
352
+ if (!staging.writer || !staging.cleanup) throw new FsError("ENOTSUP", { path, message: "PDF backend omitted retained staging handles" });
353
+ for await (const bytes of source.stream(0, source.size, signal)) await writeFileOutput(context, bytes, (data) => staging.writer.write(data, { signal }));
354
+ const stat = await staging.writer.finish({ signal });
355
+ await fs.publishStagedFile({ ...staging, file: { ...staging.file, stat } }, resolution.path, { parent: resolution.parent, destination: resolution.destination, ancestors: resolution.ancestors, commitGuard: resolution.validate, signal });
356
+ } catch (error) {
357
+ failed = true;
358
+ throw error;
359
+ } finally {
360
+ const cleanup = async () => {
361
+ try {
362
+ await staging.cleanup?.remove();
363
+ } finally {
364
+ await staging.cleanup?.close();
365
+ }
366
+ };
367
+ await cleanup().catch((error) => {
368
+ if (!failed) throw error;
369
+ });
370
+ }
371
+ }
372
+
373
+ // packages/safe-bash-command-pdftk/src/arguments.ts
33
374
  var PDFTK_OPERATIONS = /* @__PURE__ */ new Set([
34
375
  "cat",
35
376
  "shuffle",
@@ -55,6 +396,175 @@ var PDFTK_OPERATIONS = /* @__PURE__ */ new Set([
55
396
  "output",
56
397
  "input_pw"
57
398
  ]);
399
+ function* parsePdftkArgumentsSteps(argv) {
400
+ let cooperativeWork = 63;
401
+ if (argv.length === 0 || argv.includes("--help") || argv.includes("-h")) {
402
+ return { result: {
403
+ exitCode: 0,
404
+ stdout: "Usage: pdftk <input PDF files | [handle]=filename ...> [<operation> <operation arguments>] [output <output filename>] [flatten]\n",
405
+ stderr: ""
406
+ } };
407
+ }
408
+ if (argv.includes("--version") || argv.includes("-v")) {
409
+ return { result: { exitCode: 0, stdout: "pdftk port to Java 3.3.3 (safe-bash @poe-code/pdf-ast)\n", stderr: "" } };
410
+ }
411
+ const inputPasswords = /* @__PURE__ */ new Map();
412
+ let defaultInputPassword = "";
413
+ for (let p = 0; p < argv.length; p++) {
414
+ if (++cooperativeWork % 64 === 0)
415
+ yield;
416
+ if (argv[p]?.toLowerCase() === "input_pw") {
417
+ for (let q = p + 1; q < argv.length; q++) {
418
+ if (++cooperativeWork % 64 === 0)
419
+ yield;
420
+ const tok = argv[q];
421
+ if (PDFTK_OPERATIONS.has(tok.toLowerCase()))
422
+ break;
423
+ const eq = tok.indexOf("=");
424
+ if (eq > 0)
425
+ inputPasswords.set(tok.slice(0, eq), tok.slice(eq + 1));
426
+ else
427
+ defaultInputPassword = tok;
428
+ }
429
+ }
430
+ }
431
+ const inputs = [];
432
+ let idx = 0;
433
+ let autoHandleCharCode = 65;
434
+ while (idx < argv.length) {
435
+ if (++cooperativeWork % 64 === 0)
436
+ yield;
437
+ const token = argv[idx];
438
+ if (PDFTK_OPERATIONS.has(token.toLowerCase()) || token.toLowerCase() === "input_pw")
439
+ break;
440
+ idx++;
441
+ let handleName = "";
442
+ let filePath = token;
443
+ const eqIdx = token.indexOf("=");
444
+ if (eqIdx > 0) {
445
+ handleName = token.slice(0, eqIdx);
446
+ filePath = token.slice(eqIdx + 1);
447
+ } else {
448
+ handleName = String.fromCharCode(autoHandleCharCode++);
449
+ }
450
+ inputs.push({ handle: handleName, file: filePath, password: inputPasswords.get(handleName) ?? defaultInputPassword });
451
+ }
452
+ if (inputs.length === 0) {
453
+ return { result: { exitCode: 1, stdout: "", stderr: "Error: No input PDF files specified.\n" } };
454
+ }
455
+ while (idx < argv.length && argv[idx]?.toLowerCase() === "input_pw") {
456
+ if (++cooperativeWork % 64 === 0)
457
+ yield;
458
+ idx++;
459
+ while (idx < argv.length && !PDFTK_OPERATIONS.has(argv[idx].toLowerCase())) {
460
+ if (++cooperativeWork % 64 === 0)
461
+ yield;
462
+ idx++;
463
+ }
464
+ }
465
+ const operation = (argv[idx] ?? "cat").toLowerCase();
466
+ idx++;
467
+ const opArgs = [];
468
+ let outputTarget;
469
+ if (operation === "output") {
470
+ outputTarget = argv[idx++];
471
+ }
472
+ let shouldFlatten = false;
473
+ let needAppearances = false;
474
+ let dropXfa = false;
475
+ let dropXmp = false;
476
+ let replacementFont;
477
+ let keepFirstId = false;
478
+ let keepFinalId = false;
479
+ let uncompressStreams = false;
480
+ let compressStreams = false;
481
+ let userPassword;
482
+ let ownerPassword;
483
+ const allowPermissions = /* @__PURE__ */ new Set();
484
+ const ALLOW_KEYWORDS = /* @__PURE__ */ new Set([
485
+ "printing",
486
+ "degradedprinting",
487
+ "modifycontents",
488
+ "assembly",
489
+ "copycontents",
490
+ "screenreaders",
491
+ "modifyannotations",
492
+ "fillin",
493
+ "allfeatures"
494
+ ]);
495
+ while (idx < argv.length) {
496
+ if (++cooperativeWork % 64 === 0)
497
+ yield;
498
+ const tok = argv[idx++];
499
+ const lower = tok.toLowerCase();
500
+ if (lower === "output") {
501
+ outputTarget = argv[idx++];
502
+ } else if (lower === "flatten") {
503
+ shouldFlatten = true;
504
+ } else if (lower === "need_appearances") {
505
+ needAppearances = true;
506
+ } else if (lower === "user_pw") {
507
+ userPassword = argv[idx++];
508
+ } else if (lower === "owner_pw") {
509
+ ownerPassword = argv[idx++];
510
+ } else if (lower === "allow") {
511
+ while (idx < argv.length && ALLOW_KEYWORDS.has(argv[idx].toLowerCase())) {
512
+ if (++cooperativeWork % 64 === 0)
513
+ yield;
514
+ allowPermissions.add(argv[idx++].toLowerCase());
515
+ }
516
+ } else if (lower === "keep_first_id") {
517
+ keepFirstId = true;
518
+ } else if (lower === "keep_final_id") {
519
+ keepFinalId = true;
520
+ } else if (lower === "uncompress") {
521
+ uncompressStreams = true;
522
+ } else if (lower === "compress") {
523
+ compressStreams = true;
524
+ } else if (lower === "dont_ask" || lower === "do_ask" || lower === "encrypt_128bit" || lower === "encrypt_40bit" || lower === "verbose") {
525
+ } else if (lower === "drop_xfa") {
526
+ dropXfa = true;
527
+ } else if (lower === "drop_xmp") {
528
+ dropXmp = true;
529
+ } else if (lower === "replacement_font") {
530
+ replacementFont = argv[idx++];
531
+ } else {
532
+ opArgs.push(tok);
533
+ }
534
+ }
535
+ return { options: { inputs, operation, opArgs, outputTarget, shouldFlatten, needAppearances, dropXfa, dropXmp, replacementFont, keepFirstId, keepFinalId, uncompressStreams, compressStreams, userPassword, ownerPassword, allowPermissions } };
536
+ }
537
+
538
+ // packages/safe-bash-command-pdftk/src/index.ts
539
+ import { resolvePath as resolvePath2 } from "../safe-bash-contracts/path.js";
540
+ import { yieldTurn, drainCooperativeSteps as drainSteps } from "../safe-bash-contracts/yield.js";
541
+ import { InputByteBudget } from "../safe-bash-contracts/io.js";
542
+ import { writeFileOutput as writeFileOutput2 } from "../safe-bash-contracts/filesystem-output-budget.js";
543
+ import {
544
+ commandRuntimeIdentity,
545
+ getCommandArguments
546
+ } from "../safe-bash-contracts/command.js";
547
+ import { readBytes, writeBytes as writeBytes2 } from "../safe-bash-contracts/io.js";
548
+ import { createOutputOperation } from "../safe-bash-contracts/output.js";
549
+ import {
550
+ PdfDocument,
551
+ cosArray,
552
+ cosDict,
553
+ cosHexString,
554
+ cosName,
555
+ cosNumber,
556
+ cosStream,
557
+ cosString,
558
+ decodePdfString as decodePdfString2,
559
+ dictDelete,
560
+ dictGet as dictGet2,
561
+ dictSet,
562
+ flattenDocumentFormFields,
563
+ getDocumentFormFields,
564
+ parseFormDataBytes,
565
+ resolveDestinationPageIndex,
566
+ setDocumentFormField
567
+ } from "../pdf-ast/index.js";
58
568
  function parseRotationSuffix(raw) {
59
569
  const lower = raw.toLowerCase();
60
570
  const wordRotations = [
@@ -263,40 +773,40 @@ function formatDumpDataAnnots(doc, utf8 = false) {
263
773
  lines.push(`NumberOfPages: ${doc.pageCount}`);
264
774
  for (let p = 0; p < doc.pageCount; p++) {
265
775
  const pageDict = doc.getPage(p).pageDict;
266
- const annotsArr = doc.cos.resolveArray(dictGet(pageDict, "Annots"));
776
+ const annotsArr = doc.cos.resolveArray(dictGet2(pageDict, "Annots"));
267
777
  if (!annotsArr) continue;
268
778
  for (const item of annotsArr.items) {
269
779
  const annotDict = doc.cos.resolveDict(item);
270
780
  if (!annotDict) continue;
271
- const subNode = doc.cos.resolve(dictGet(annotDict, "Subtype"));
781
+ const subNode = doc.cos.resolve(dictGet2(annotDict, "Subtype"));
272
782
  const subtype = subNode?.kind === "name" ? subNode.decoded : "Annot";
273
- const rectArr = doc.cos.resolveArray(dictGet(annotDict, "Rect"));
783
+ const rectArr = doc.cos.resolveArray(dictGet2(annotDict, "Rect"));
274
784
  const rectNums = rectArr ? rectArr.items.map((it) => {
275
785
  const r = doc.cos.resolve(it);
276
786
  return r?.kind === "number" ? r.value : 0;
277
787
  }) : [0, 0, 0, 0];
278
- const flagsNode = doc.cos.resolve(dictGet(annotDict, "F"));
788
+ const flagsNode = doc.cos.resolve(dictGet2(annotDict, "F"));
279
789
  const flags = flagsNode?.kind === "number" ? flagsNode.value : 0;
280
790
  lines.push("---");
281
791
  lines.push(`AnnotSubtype: ${subtype}`);
282
792
  lines.push(`AnnotRect: ${rectNums.slice(0, 4).join(" ")}`);
283
- const nmNode = doc.cos.resolve(dictGet(annotDict, "NM"));
793
+ const nmNode = doc.cos.resolve(dictGet2(annotDict, "NM"));
284
794
  if (nmNode?.kind === "string") {
285
- lines.push(`AnnotName: ${encodePdftkText(decodePdfString(nmNode), utf8)}`);
795
+ lines.push(`AnnotName: ${encodePdftkText(decodePdfString2(nmNode), utf8)}`);
286
796
  }
287
- const tNode = doc.cos.resolve(dictGet(annotDict, "T"));
797
+ const tNode = doc.cos.resolve(dictGet2(annotDict, "T"));
288
798
  if (tNode?.kind === "string") {
289
- lines.push(`AnnotTitle: ${encodePdftkText(decodePdfString(tNode), utf8)}`);
799
+ lines.push(`AnnotTitle: ${encodePdftkText(decodePdfString2(tNode), utf8)}`);
290
800
  }
291
- const subjNode = doc.cos.resolve(dictGet(annotDict, "Subj"));
801
+ const subjNode = doc.cos.resolve(dictGet2(annotDict, "Subj"));
292
802
  if (subjNode?.kind === "string") {
293
- lines.push(`AnnotSubj: ${encodePdftkText(decodePdfString(subjNode), utf8)}`);
803
+ lines.push(`AnnotSubj: ${encodePdftkText(decodePdfString2(subjNode), utf8)}`);
294
804
  }
295
- const cNode = doc.cos.resolve(dictGet(annotDict, "Contents"));
805
+ const cNode = doc.cos.resolve(dictGet2(annotDict, "Contents"));
296
806
  if (cNode?.kind === "string") {
297
- lines.push(`AnnotContents: ${encodePdftkText(decodePdfString(cNode), utf8)}`);
807
+ lines.push(`AnnotContents: ${encodePdftkText(decodePdfString2(cNode), utf8)}`);
298
808
  }
299
- const colArr = doc.cos.resolveArray(dictGet(annotDict, "C"));
809
+ const colArr = doc.cos.resolveArray(dictGet2(annotDict, "C"));
300
810
  if (colArr && colArr.items.length >= 3) {
301
811
  const colNums = colArr.items.slice(0, 3).map((it) => {
302
812
  const r = doc.cos.resolve(it);
@@ -304,20 +814,20 @@ function formatDumpDataAnnots(doc, utf8 = false) {
304
814
  });
305
815
  lines.push(`AnnotColor: ${colNums.join(" ")}`);
306
816
  }
307
- const openNode = doc.cos.resolve(dictGet(annotDict, "Open"));
817
+ const openNode = doc.cos.resolve(dictGet2(annotDict, "Open"));
308
818
  if (openNode?.kind === "boolean") {
309
819
  lines.push(`AnnotOpen: ${openNode.value}`);
310
820
  }
311
- const mNode = doc.cos.resolve(dictGet(annotDict, "M"));
821
+ const mNode = doc.cos.resolve(dictGet2(annotDict, "M"));
312
822
  if (mNode?.kind === "string") {
313
- lines.push(`AnnotModificationDate: ${encodePdftkText(decodePdfString(mNode), utf8)}`);
823
+ lines.push(`AnnotModificationDate: ${encodePdftkText(decodePdfString2(mNode), utf8)}`);
314
824
  }
315
825
  lines.push(`AnnotFlags: ${flags}`);
316
826
  lines.push(`AnnotPageNumber: ${p + 1}`);
317
827
  const formatDestTarget = (dRaw) => {
318
828
  if (!dRaw) return void 0;
319
829
  const resolved = doc.cos.resolve(dRaw);
320
- if (resolved?.kind === "string") return decodePdfString(resolved);
830
+ if (resolved?.kind === "string") return decodePdfString2(resolved);
321
831
  if (resolved?.kind === "name") return resolved.decoded;
322
832
  if (resolved?.kind === "array" && resolved.items.length > 0) {
323
833
  const first = resolved.items[0];
@@ -350,16 +860,16 @@ function formatDumpDataAnnots(doc, utf8 = false) {
350
860
  }
351
861
  const actionDict = doc.cos.resolveDict(aNode);
352
862
  if (!actionDict) return;
353
- const sNode = doc.cos.resolve(dictGet(actionDict, "S"));
863
+ const sNode = doc.cos.resolve(dictGet2(actionDict, "S"));
354
864
  const sType = sNode?.kind === "name" ? sNode.decoded : "";
355
865
  if (sType) {
356
866
  lines.push(`AnnotActionType: ${sType}`);
357
867
  }
358
- const uriNode = doc.cos.resolve(dictGet(actionDict, "URI"));
868
+ const uriNode = doc.cos.resolve(dictGet2(actionDict, "URI"));
359
869
  if (uriNode?.kind === "string") {
360
- lines.push(`AnnotActionURI: ${encodePdftkText(decodePdfString(uriNode), utf8)}`);
870
+ lines.push(`AnnotActionURI: ${encodePdftkText(decodePdfString2(uriNode), utf8)}`);
361
871
  }
362
- const dNode = dictGet(actionDict, "D");
872
+ const dNode = dictGet2(actionDict, "D");
363
873
  const destTarget = formatDestTarget(dNode);
364
874
  if (destTarget) {
365
875
  lines.push(`AnnotActionDest: ${encodePdftkText(destTarget, utf8)}`);
@@ -368,23 +878,23 @@ function formatDumpDataAnnots(doc, utf8 = false) {
368
878
  if (resolvedIdx !== void 0) {
369
879
  lines.push(`AnnotActionPageNumber: ${resolvedIdx + 1}`);
370
880
  }
371
- const fRaw = doc.cos.resolve(dictGet(actionDict, "F"));
881
+ const fRaw = doc.cos.resolve(dictGet2(actionDict, "F"));
372
882
  if (fRaw?.kind === "string") {
373
- lines.push(`AnnotActionFile: ${encodePdftkText(decodePdfString(fRaw), utf8)}`);
883
+ lines.push(`AnnotActionFile: ${encodePdftkText(decodePdfString2(fRaw), utf8)}`);
374
884
  } else if (fRaw?.kind === "dict") {
375
- const ufNode = doc.cos.resolve(dictGet(fRaw, "UF") ?? dictGet(fRaw, "F"));
885
+ const ufNode = doc.cos.resolve(dictGet2(fRaw, "UF") ?? dictGet2(fRaw, "F"));
376
886
  if (ufNode?.kind === "string") {
377
- lines.push(`AnnotActionFile: ${encodePdftkText(decodePdfString(ufNode), utf8)}`);
887
+ lines.push(`AnnotActionFile: ${encodePdftkText(decodePdfString2(ufNode), utf8)}`);
378
888
  }
379
889
  }
380
- emitActionChain(dictGet(actionDict, "Next"), visited);
890
+ emitActionChain(dictGet2(actionDict, "Next"), visited);
381
891
  };
382
- const rawA = dictGet(annotDict, "A");
892
+ const rawA = dictGet2(annotDict, "A");
383
893
  if (rawA) {
384
894
  emitActionChain(rawA);
385
- } else if (dictGet(annotDict, "Dest")) {
895
+ } else if (dictGet2(annotDict, "Dest")) {
386
896
  lines.push("AnnotActionType: GoTo");
387
- const dNode = dictGet(annotDict, "Dest");
897
+ const dNode = dictGet2(annotDict, "Dest");
388
898
  const destTarget = formatDestTarget(dNode);
389
899
  if (destTarget) {
390
900
  lines.push(`AnnotActionDest: ${encodePdftkText(destTarget, utf8)}`);
@@ -430,18 +940,18 @@ function collectOutlineBookmarks(doc, firstNode, level, out, visited = /* @__PUR
430
940
  }
431
941
  const dict = doc.cos.resolveDict(curr);
432
942
  if (!dict) break;
433
- const titleNode = doc.cos.resolve(dictGet(dict, "Title"));
434
- const title = titleNode?.kind === "string" ? decodePdfString(titleNode) : titleNode?.kind === "name" ? titleNode.decoded : "";
435
- const resolvedIdx = resolveDestinationPageIndex(doc, dictGet(dict, "Dest") ?? dictGet(dict, "A"));
943
+ const titleNode = doc.cos.resolve(dictGet2(dict, "Title"));
944
+ const title = titleNode?.kind === "string" ? decodePdfString2(titleNode) : titleNode?.kind === "name" ? titleNode.decoded : "";
945
+ const resolvedIdx = resolveDestinationPageIndex(doc, dictGet2(dict, "Dest") ?? dictGet2(dict, "A"));
436
946
  const pageNumber = resolvedIdx !== void 0 ? resolvedIdx + 1 : 1;
437
947
  if (title) {
438
948
  out.push({ title, level, pageNumber });
439
949
  }
440
- const childFirst = dictGet(dict, "First");
950
+ const childFirst = dictGet2(dict, "First");
441
951
  if (childFirst) {
442
952
  collectOutlineBookmarks(doc, childFirst, level + 1, out, visited);
443
953
  }
444
- curr = dictGet(dict, "Next");
954
+ curr = dictGet2(dict, "Next");
445
955
  }
446
956
  }
447
957
  function collectNameTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ new Set()) {
@@ -452,16 +962,16 @@ function collectNameTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ new
452
962
  }
453
963
  const dict = doc.cos.resolveDict(nodeOrRef);
454
964
  if (!dict) return;
455
- const namesArr = doc.cos.resolveArray(dictGet(dict, "Names"));
965
+ const namesArr = doc.cos.resolveArray(dictGet2(dict, "Names"));
456
966
  if (namesArr) {
457
967
  for (let i = 0; i + 1 < namesArr.items.length; i += 2) {
458
968
  const k = doc.cos.resolve(namesArr.items[i]);
459
969
  const v = namesArr.items[i + 1];
460
- const name = k?.kind === "string" ? decodePdfString(k) : "attachment.bin";
970
+ const name = k?.kind === "string" ? decodePdfString2(k) : "attachment.bin";
461
971
  out.push({ name, value: v });
462
972
  }
463
973
  }
464
- const kidsArr = doc.cos.resolveArray(dictGet(dict, "Kids"));
974
+ const kidsArr = doc.cos.resolveArray(dictGet2(dict, "Kids"));
465
975
  if (kidsArr) {
466
976
  for (const kid of kidsArr.items) {
467
977
  collectNameTreePairs(doc, kid, out, visited);
@@ -476,7 +986,7 @@ function collectNumberTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ n
476
986
  }
477
987
  const dict = doc.cos.resolveDict(nodeOrRef);
478
988
  if (!dict) return;
479
- const numsArr = doc.cos.resolveArray(dictGet(dict, "Nums"));
989
+ const numsArr = doc.cos.resolveArray(dictGet2(dict, "Nums"));
480
990
  if (numsArr) {
481
991
  for (let i = 0; i + 1 < numsArr.items.length; i += 2) {
482
992
  const k = doc.cos.resolve(numsArr.items[i]);
@@ -486,7 +996,7 @@ function collectNumberTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ n
486
996
  }
487
997
  }
488
998
  }
489
- const kidsArr = doc.cos.resolveArray(dictGet(dict, "Kids"));
999
+ const kidsArr = doc.cos.resolveArray(dictGet2(dict, "Kids"));
490
1000
  if (kidsArr) {
491
1001
  for (const kid of kidsArr.items) {
492
1002
  collectNumberTreePairs(doc, kid, out, visited);
@@ -540,7 +1050,7 @@ function formatDumpData(doc, utf8 = true) {
540
1050
  if (emittedKeys.has(k)) continue;
541
1051
  const r = doc.cos.resolve(entry.value);
542
1052
  if (r?.kind === "string") {
543
- const val = decodePdfString(r);
1053
+ const val = decodePdfString2(r);
544
1054
  if (val) {
545
1055
  emittedKeys.add(k);
546
1056
  lines.push(
@@ -561,10 +1071,10 @@ function formatDumpData(doc, utf8 = true) {
561
1071
  lines.push(`PdfID1: ${id1Hex}`);
562
1072
  lines.push(`NumberOfPages: ${doc.pageCount}`);
563
1073
  const catalog = doc.cos.resolveDict(doc.cos.rootRef);
564
- const outlinesDict = catalog ? doc.cos.resolveDict(dictGet(catalog, "Outlines")) : void 0;
1074
+ const outlinesDict = catalog ? doc.cos.resolveDict(dictGet2(catalog, "Outlines")) : void 0;
565
1075
  if (outlinesDict) {
566
1076
  const bookmarks = [];
567
- collectOutlineBookmarks(doc, dictGet(outlinesDict, "First"), 1, bookmarks);
1077
+ collectOutlineBookmarks(doc, dictGet2(outlinesDict, "First"), 1, bookmarks);
568
1078
  for (const bm of bookmarks) {
569
1079
  lines.push(
570
1080
  "BookmarkBegin",
@@ -578,7 +1088,7 @@ function formatDumpData(doc, utf8 = true) {
578
1088
  const page = doc.getPage(i);
579
1089
  const { width, height } = page.getSize();
580
1090
  const rot = page.getRotation();
581
- const mbArr = doc.cos.resolveArray(dictGet(page.pageDict, "MediaBox"));
1091
+ const mbArr = doc.cos.resolveArray(dictGet2(page.pageDict, "MediaBox"));
582
1092
  let mbRectStr = `0 0 ${width} ${height}`;
583
1093
  if (mbArr && mbArr.items.length >= 4) {
584
1094
  const mbNums = mbArr.items.slice(0, 4).map((item) => {
@@ -594,7 +1104,7 @@ function formatDumpData(doc, utf8 = true) {
594
1104
  `PageMediaRect: ${mbRectStr}`,
595
1105
  `PageMediaDimensions: ${width} ${height}`
596
1106
  );
597
- const cbArr = doc.cos.resolveArray(dictGet(page.pageDict, "CropBox"));
1107
+ const cbArr = doc.cos.resolveArray(dictGet2(page.pageDict, "CropBox"));
598
1108
  if (cbArr && cbArr.items.length >= 4) {
599
1109
  const nums = cbArr.items.slice(0, 4).map((item) => {
600
1110
  const r = doc.cos.resolve(item);
@@ -606,17 +1116,17 @@ function formatDumpData(doc, utf8 = true) {
606
1116
  }
607
1117
  const pageLabelsPairs = [];
608
1118
  if (catalog) {
609
- collectNumberTreePairs(doc, dictGet(catalog, "PageLabels"), pageLabelsPairs);
1119
+ collectNumberTreePairs(doc, dictGet2(catalog, "PageLabels"), pageLabelsPairs);
610
1120
  }
611
1121
  for (const pair of pageLabelsPairs) {
612
1122
  const lblDict = doc.cos.resolveDict(pair.value);
613
1123
  if (lblDict) {
614
1124
  const newIndex = Math.max(1, pair.num + 1);
615
- const stNode = doc.cos.resolve(dictGet(lblDict, "St"));
1125
+ const stNode = doc.cos.resolve(dictGet2(lblDict, "St"));
616
1126
  const startNum = stNode?.kind === "number" ? stNode.value : 1;
617
- const pNode = doc.cos.resolve(dictGet(lblDict, "P"));
618
- const prefix = pNode?.kind === "string" ? decodePdfString(pNode) : void 0;
619
- const sNode = doc.cos.resolve(dictGet(lblDict, "S"));
1127
+ const pNode = doc.cos.resolve(dictGet2(lblDict, "P"));
1128
+ const prefix = pNode?.kind === "string" ? decodePdfString2(pNode) : void 0;
1129
+ const sNode = doc.cos.resolve(dictGet2(lblDict, "S"));
620
1130
  const styleCode = sNode?.kind === "name" ? sNode.decoded : "";
621
1131
  const numStyle = PDF_TO_PAGE_LABEL_STYLE[styleCode] ?? "NoNumber";
622
1132
  lines.push(
@@ -647,23 +1157,23 @@ function formatGenerateFdf(doc) {
647
1157
  }
648
1158
  return `(${escapeFdfString(String(f.value ?? ""))})`;
649
1159
  }
650
- const vNode = doc.cos.resolve(dictGet(dict, "V"));
1160
+ const vNode = doc.cos.resolve(dictGet2(dict, "V"));
651
1161
  if (vNode?.kind === "name") return `/${vNode.decoded}`;
652
- if (vNode?.kind === "string") return `(${escapeFdfString(decodePdfString(vNode))})`;
1162
+ if (vNode?.kind === "string") return `(${escapeFdfString(decodePdfString2(vNode))})`;
653
1163
  return "()";
654
1164
  };
655
1165
  const serializeCosFieldNode = (nodeOrRef, prefix) => {
656
1166
  const dict = doc.cos.resolveDict(nodeOrRef);
657
1167
  if (!dict) return void 0;
658
- const tNode = doc.cos.resolve(dictGet(dict, "T"));
659
- const partialName = tNode?.kind === "string" ? decodePdfString(tNode) : "";
1168
+ const tNode = doc.cos.resolve(dictGet2(dict, "T"));
1169
+ const partialName = tNode?.kind === "string" ? decodePdfString2(tNode) : "";
660
1170
  const fullName = prefix && partialName ? `${prefix}.${partialName}` : partialName || prefix;
661
- const kidsArr = doc.cos.resolveArray(dictGet(dict, "Kids"));
1171
+ const kidsArr = doc.cos.resolveArray(dictGet2(dict, "Kids"));
662
1172
  const namedKids = [];
663
1173
  if (kidsArr) {
664
1174
  for (const k of kidsArr.items) {
665
1175
  const kDict = doc.cos.resolveDict(k);
666
- if (kDict && dictGet(kDict, "T")) {
1176
+ if (kDict && dictGet2(kDict, "T")) {
667
1177
  const serializedKid = serializeCosFieldNode(k, fullName);
668
1178
  if (serializedKid) namedKids.push(serializedKid);
669
1179
  }
@@ -677,8 +1187,8 @@ function formatGenerateFdf(doc) {
677
1187
  };
678
1188
  const entries = [];
679
1189
  const catalog = doc.cos.resolveDict(doc.cos.rootRef);
680
- const acroForm = catalog ? doc.cos.resolveDict(dictGet(catalog, "AcroForm")) : void 0;
681
- const fieldsArr = acroForm ? doc.cos.resolveArray(dictGet(acroForm, "Fields")) : void 0;
1190
+ const acroForm = catalog ? doc.cos.resolveDict(dictGet2(catalog, "AcroForm")) : void 0;
1191
+ const fieldsArr = acroForm ? doc.cos.resolveArray(dictGet2(acroForm, "Fields")) : void 0;
682
1192
  if (fieldsArr && fieldsArr.items.length > 0) {
683
1193
  for (const item of fieldsArr.items) {
684
1194
  const s = serializeCosFieldNode(item, "");
@@ -939,17 +1449,17 @@ function applyUpdateInfoText(doc, text) {
939
1449
  function attachFilesToDocument(doc, filePaths, files, toPageSpec) {
940
1450
  const catalog = doc.cos.resolveDict(doc.cos.rootRef);
941
1451
  if (!catalog) return;
942
- let namesDict = doc.cos.resolveDict(dictGet(catalog, "Names"));
1452
+ let namesDict = doc.cos.resolveDict(dictGet2(catalog, "Names"));
943
1453
  if (!namesDict) {
944
1454
  namesDict = cosDict({});
945
1455
  dictSet(catalog, "Names", doc.cos.allocateObject(namesDict));
946
1456
  }
947
- let efTree = doc.cos.resolveDict(dictGet(namesDict, "EmbeddedFiles"));
1457
+ let efTree = doc.cos.resolveDict(dictGet2(namesDict, "EmbeddedFiles"));
948
1458
  if (!efTree) {
949
1459
  efTree = cosDict({ Names: cosArray([]) });
950
1460
  dictSet(namesDict, "EmbeddedFiles", doc.cos.allocateObject(efTree));
951
1461
  }
952
- let namesArr = doc.cos.resolveArray(dictGet(efTree, "Names"));
1462
+ let namesArr = doc.cos.resolveArray(dictGet2(efTree, "Names"));
953
1463
  if (!namesArr) {
954
1464
  namesArr = cosArray([]);
955
1465
  dictSet(efTree, "Names", namesArr);
@@ -976,7 +1486,7 @@ function attachFilesToDocument(doc, filePaths, files, toPageSpec) {
976
1486
  namesArr.items.push(cosString(baseName), filespecRef);
977
1487
  if (targetPageIdx !== void 0) {
978
1488
  const pageDict = doc.getPage(targetPageIdx).pageDict;
979
- let annotsArr = doc.cos.resolveArray(dictGet(pageDict, "Annots"));
1489
+ let annotsArr = doc.cos.resolveArray(dictGet2(pageDict, "Annots"));
980
1490
  if (!annotsArr) {
981
1491
  annotsArr = cosArray([]);
982
1492
  dictSet(pageDict, "Annots", annotsArr);
@@ -1005,11 +1515,11 @@ function attachmentBasename(name) {
1005
1515
  function unpackFilesFromDocument(doc, outDir, files) {
1006
1516
  const cleanDir = outDir.endsWith("/") ? outDir.slice(0, -1) : outDir;
1007
1517
  const writeSpecDict = (specDict, fallbackName = "attachment.bin") => {
1008
- const ufNode = doc.cos.resolve(dictGet(specDict, "UF") ?? dictGet(specDict, "F"));
1009
- const fileName = attachmentBasename(ufNode?.kind === "string" ? decodePdfString(ufNode) : fallbackName);
1010
- const efDict = doc.cos.resolveDict(dictGet(specDict, "EF"));
1518
+ const ufNode = doc.cos.resolve(dictGet2(specDict, "UF") ?? dictGet2(specDict, "F"));
1519
+ const fileName = attachmentBasename(ufNode?.kind === "string" ? decodePdfString2(ufNode) : fallbackName);
1520
+ const efDict = doc.cos.resolveDict(dictGet2(specDict, "EF"));
1011
1521
  const fStream = efDict ? doc.cos.resolve(
1012
- dictGet(efDict, "UF") ?? dictGet(efDict, "F") ?? dictGet(efDict, "DOS") ?? dictGet(efDict, "Mac") ?? dictGet(efDict, "Unix")
1522
+ dictGet2(efDict, "UF") ?? dictGet2(efDict, "F") ?? dictGet2(efDict, "DOS") ?? dictGet2(efDict, "Mac") ?? dictGet2(efDict, "Unix")
1013
1523
  ) : void 0;
1014
1524
  if (fStream?.kind === "stream") {
1015
1525
  const decoded = doc.cos.decodeStream(fStream);
@@ -1019,10 +1529,10 @@ function unpackFilesFromDocument(doc, outDir, files) {
1019
1529
  };
1020
1530
  const catalog = doc.cos.resolveDict(doc.cos.rootRef);
1021
1531
  if (catalog) {
1022
- const namesDict = doc.cos.resolveDict(dictGet(catalog, "Names"));
1532
+ const namesDict = doc.cos.resolveDict(dictGet2(catalog, "Names"));
1023
1533
  const efPairs = [];
1024
1534
  if (namesDict) {
1025
- collectNameTreePairs(doc, dictGet(namesDict, "EmbeddedFiles"), efPairs);
1535
+ collectNameTreePairs(doc, dictGet2(namesDict, "EmbeddedFiles"), efPairs);
1026
1536
  }
1027
1537
  for (const pair of efPairs) {
1028
1538
  const specDict = doc.cos.resolveDict(pair.value);
@@ -1030,7 +1540,7 @@ function unpackFilesFromDocument(doc, outDir, files) {
1030
1540
  writeSpecDict(specDict, pair.name);
1031
1541
  }
1032
1542
  }
1033
- const rootAfArr = doc.cos.resolveArray(dictGet(catalog, "AF"));
1543
+ const rootAfArr = doc.cos.resolveArray(dictGet2(catalog, "AF"));
1034
1544
  if (rootAfArr) {
1035
1545
  for (const item of rootAfArr.items) {
1036
1546
  const specDict = doc.cos.resolveDict(item);
@@ -1039,21 +1549,21 @@ function unpackFilesFromDocument(doc, outDir, files) {
1039
1549
  }
1040
1550
  }
1041
1551
  for (let p = 0; p < doc.pageCount; p++) {
1042
- const pageAfArr = doc.cos.resolveArray(dictGet(doc.getPage(p).pageDict, "AF"));
1552
+ const pageAfArr = doc.cos.resolveArray(dictGet2(doc.getPage(p).pageDict, "AF"));
1043
1553
  if (pageAfArr) {
1044
1554
  for (const item of pageAfArr.items) {
1045
1555
  const specDict = doc.cos.resolveDict(item);
1046
1556
  if (specDict) writeSpecDict(specDict);
1047
1557
  }
1048
1558
  }
1049
- const annotsArr = doc.cos.resolveArray(dictGet(doc.getPage(p).pageDict, "Annots"));
1559
+ const annotsArr = doc.cos.resolveArray(dictGet2(doc.getPage(p).pageDict, "Annots"));
1050
1560
  if (!annotsArr) continue;
1051
1561
  for (const item of annotsArr.items) {
1052
1562
  const annotDict = doc.cos.resolveDict(item);
1053
1563
  if (!annotDict) continue;
1054
- const subNode = doc.cos.resolve(dictGet(annotDict, "Subtype"));
1564
+ const subNode = doc.cos.resolve(dictGet2(annotDict, "Subtype"));
1055
1565
  if (subNode?.kind === "name" && subNode.decoded === "FileAttachment") {
1056
- const specDict = doc.cos.resolveDict(dictGet(annotDict, "FS"));
1566
+ const specDict = doc.cos.resolveDict(dictGet2(annotDict, "FS"));
1057
1567
  if (specDict) writeSpecDict(specDict);
1058
1568
  }
1059
1569
  }
@@ -1187,9 +1697,9 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
1187
1697
  const srcRes = srcPage.getResourcesDict();
1188
1698
  const renamedResources = /* @__PURE__ */ new Map();
1189
1699
  for (const subKey of ["Font", "XObject", "ExtGState", "ColorSpace", "Pattern", "Shading", "Properties"]) {
1190
- const srcSub = overlayDoc.cos.resolveDict(dictGet(srcRes, subKey));
1700
+ const srcSub = overlayDoc.cos.resolveDict(dictGet2(srcRes, subKey));
1191
1701
  if (!srcSub) continue;
1192
- let dstSub = targetDoc.cos.resolveDict(dictGet(dstRes, subKey));
1702
+ let dstSub = targetDoc.cos.resolveDict(dictGet2(dstRes, subKey));
1193
1703
  if (!dstSub) {
1194
1704
  dstSub = cosDict({});
1195
1705
  dictSet(dstRes, subKey, dstSub);
@@ -1198,12 +1708,12 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
1198
1708
  const origKey = entry.key.decoded;
1199
1709
  const cloned = cloneCosSubgraphInto(overlayDoc, targetDoc, entry.value, memo);
1200
1710
  if (!cloned) continue;
1201
- if (!dictGet(dstSub, origKey)) {
1711
+ if (!dictGet2(dstSub, origKey)) {
1202
1712
  dictSet(dstSub, origKey, cloned);
1203
1713
  } else {
1204
1714
  let newKey = `Ov_${i}_${origKey}`;
1205
1715
  let suffix = 1;
1206
- while (dictGet(dstSub, newKey)) {
1716
+ while (dictGet2(dstSub, newKey)) {
1207
1717
  newKey = `Ov_${i}_${suffix++}_${origKey}`;
1208
1718
  }
1209
1719
  dictSet(dstSub, newKey, cloned);
@@ -1211,7 +1721,7 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
1211
1721
  }
1212
1722
  }
1213
1723
  }
1214
- const srcContents = dictGet(srcPage.pageDict, "Contents");
1724
+ const srcContents = dictGet2(srcPage.pageDict, "Contents");
1215
1725
  if (!srcContents) continue;
1216
1726
  const rawSrcNodes = [];
1217
1727
  const resolvedSrcContents = overlayDoc.cos.resolve(srcContents);
@@ -1237,7 +1747,7 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
1237
1747
  }
1238
1748
  }
1239
1749
  if (srcList.length === 0) continue;
1240
- const dstContents = dictGet(dstPage.pageDict, "Contents");
1750
+ const dstContents = dictGet2(dstPage.pageDict, "Contents");
1241
1751
  const toStreamList = (c) => {
1242
1752
  if (!c) return [];
1243
1753
  const r = targetDoc.cos.resolve(c);
@@ -1296,159 +1806,29 @@ function normalizeQuarterTurn(degrees) {
1296
1806
  }
1297
1807
  function* runPdftkCliSteps(argv, files, signal) {
1298
1808
  let cooperativeWork = 63;
1299
- if (argv.length === 0 || argv.includes("--help") || argv.includes("-h")) {
1300
- return {
1301
- exitCode: 0,
1302
- stdout: "Usage: pdftk <input PDF files | [handle]=filename ...> [<operation> <operation arguments>] [output <output filename>] [flatten]\n",
1303
- stderr: ""
1304
- };
1305
- }
1306
- if (argv.includes("--version") || argv.includes("-v")) {
1307
- return { exitCode: 0, stdout: "pdftk port to Java 3.3.3 (safe-bash @poe-code/pdf-ast)\n", stderr: "" };
1308
- }
1309
- const inputPasswords = /* @__PURE__ */ new Map();
1310
- let defaultInputPassword = "";
1311
- for (let p = 0; p < argv.length; p++) {
1312
- if (++cooperativeWork % 64 === 0)
1313
- yield;
1314
- if (argv[p]?.toLowerCase() === "input_pw") {
1315
- for (let q = p + 1; q < argv.length; q++) {
1316
- if (++cooperativeWork % 64 === 0)
1317
- yield;
1318
- const tok = argv[q];
1319
- if (PDFTK_OPERATIONS.has(tok.toLowerCase()))
1320
- break;
1321
- const eq = tok.indexOf("=");
1322
- if (eq > 0)
1323
- inputPasswords.set(tok.slice(0, eq), tok.slice(eq + 1));
1324
- else
1325
- defaultInputPassword = tok;
1326
- }
1327
- }
1328
- }
1809
+ const parsed = yield* parsePdftkArgumentsSteps(argv);
1810
+ if (parsed.result) return parsed.result;
1811
+ const { inputs, operation, opArgs, outputTarget, shouldFlatten, needAppearances, dropXfa, dropXmp, replacementFont, keepFirstId, keepFinalId, uncompressStreams, compressStreams, userPassword, ownerPassword, allowPermissions } = parsed.options;
1329
1812
  const handles = /* @__PURE__ */ new Map();
1330
1813
  const orderedDocs = [];
1331
- let idx = 0;
1332
- let autoHandleCharCode = 65;
1333
- while (idx < argv.length) {
1334
- if (++cooperativeWork % 64 === 0)
1335
- yield;
1336
- const token = argv[idx];
1337
- if (PDFTK_OPERATIONS.has(token.toLowerCase()) || token.toLowerCase() === "input_pw")
1338
- break;
1339
- idx++;
1340
- let handleName = "";
1341
- let filePath = token;
1342
- const eqIdx = token.indexOf("=");
1343
- if (eqIdx > 0) {
1344
- handleName = token.slice(0, eqIdx);
1345
- filePath = token.slice(eqIdx + 1);
1346
- } else {
1347
- handleName = String.fromCharCode(autoHandleCharCode++);
1348
- }
1349
- const pdfBytes = files.get(filePath);
1350
- if (!pdfBytes) {
1351
- return { exitCode: 1, stdout: "", stderr: `Error: Unable to find file '${filePath}'
1814
+ for (const input of inputs) {
1815
+ signal?.throwIfAborted();
1816
+ if (++cooperativeWork % 64 === 0) yield;
1817
+ const pdfBytes = files.get(input.file);
1818
+ if (!pdfBytes) return { exitCode: 1, stdout: "", stderr: `Error: Unable to find file '${input.file}'
1352
1819
  ` };
1353
- }
1354
- const pw = inputPasswords.get(handleName) ?? defaultInputPassword;
1355
1820
  let doc;
1356
1821
  try {
1357
- doc = PdfDocument.load(pdfBytes, pw ? { password: pw } : void 0);
1358
- } catch (err) {
1359
- return { exitCode: 1, stdout: "", stderr: `Error: Failed to open PDF '${filePath}': ${err.message}
1822
+ doc = PdfDocument.load(pdfBytes, input.password ? { password: input.password } : void 0);
1823
+ } catch (error) {
1824
+ return { exitCode: 1, stdout: "", stderr: `Error: Failed to open PDF '${input.file}': ${error.message}
1360
1825
  ` };
1361
1826
  }
1362
- handles.set(handleName, doc);
1363
- if (!handles.has(""))
1364
- handles.set("", doc);
1365
- orderedDocs.push({ handle: handleName, doc });
1366
- }
1367
- if (orderedDocs.length === 0) {
1368
- return { exitCode: 1, stdout: "", stderr: "Error: No input PDF files specified.\n" };
1369
- }
1370
- while (idx < argv.length && argv[idx]?.toLowerCase() === "input_pw") {
1371
- if (++cooperativeWork % 64 === 0)
1372
- yield;
1373
- idx++;
1374
- while (idx < argv.length && !PDFTK_OPERATIONS.has(argv[idx].toLowerCase())) {
1375
- if (++cooperativeWork % 64 === 0)
1376
- yield;
1377
- idx++;
1378
- }
1379
- }
1380
- const primaryDoc = orderedDocs[0].doc;
1381
- const primaryHandle = orderedDocs[0].handle;
1382
- const operation = (argv[idx] ?? "cat").toLowerCase();
1383
- idx++;
1384
- const opArgs = [];
1385
- let outputTarget;
1386
- if (operation === "output") {
1387
- outputTarget = argv[idx++];
1388
- }
1389
- let shouldFlatten = false;
1390
- let needAppearances = false;
1391
- let dropXfa = false;
1392
- let dropXmp = false;
1393
- let replacementFont;
1394
- let keepFirstId = false;
1395
- let keepFinalId = false;
1396
- let uncompressStreams = false;
1397
- let compressStreams = false;
1398
- let userPassword;
1399
- let ownerPassword;
1400
- const allowPermissions = /* @__PURE__ */ new Set();
1401
- const ALLOW_KEYWORDS = /* @__PURE__ */ new Set([
1402
- "printing",
1403
- "degradedprinting",
1404
- "modifycontents",
1405
- "assembly",
1406
- "copycontents",
1407
- "screenreaders",
1408
- "modifyannotations",
1409
- "fillin",
1410
- "allfeatures"
1411
- ]);
1412
- while (idx < argv.length) {
1413
- if (++cooperativeWork % 64 === 0)
1414
- yield;
1415
- const tok = argv[idx++];
1416
- const lower = tok.toLowerCase();
1417
- if (lower === "output") {
1418
- outputTarget = argv[idx++];
1419
- } else if (lower === "flatten") {
1420
- shouldFlatten = true;
1421
- } else if (lower === "need_appearances") {
1422
- needAppearances = true;
1423
- } else if (lower === "user_pw") {
1424
- userPassword = argv[idx++];
1425
- } else if (lower === "owner_pw") {
1426
- ownerPassword = argv[idx++];
1427
- } else if (lower === "allow") {
1428
- while (idx < argv.length && ALLOW_KEYWORDS.has(argv[idx].toLowerCase())) {
1429
- if (++cooperativeWork % 64 === 0)
1430
- yield;
1431
- allowPermissions.add(argv[idx++].toLowerCase());
1432
- }
1433
- } else if (lower === "keep_first_id") {
1434
- keepFirstId = true;
1435
- } else if (lower === "keep_final_id") {
1436
- keepFinalId = true;
1437
- } else if (lower === "uncompress") {
1438
- uncompressStreams = true;
1439
- } else if (lower === "compress") {
1440
- compressStreams = true;
1441
- } else if (lower === "dont_ask" || lower === "do_ask" || lower === "encrypt_128bit" || lower === "encrypt_40bit" || lower === "verbose") {
1442
- } else if (lower === "drop_xfa") {
1443
- dropXfa = true;
1444
- } else if (lower === "drop_xmp") {
1445
- dropXmp = true;
1446
- } else if (lower === "replacement_font") {
1447
- replacementFont = argv[idx++];
1448
- } else {
1449
- opArgs.push(tok);
1450
- }
1827
+ handles.set(input.handle, doc);
1828
+ if (!handles.has("")) handles.set("", doc);
1829
+ orderedDocs.push({ handle: input.handle, doc });
1451
1830
  }
1831
+ const primaryDoc = orderedDocs[0].doc, primaryHandle = orderedDocs[0].handle;
1452
1832
  if (operation === "dump_data_fields" || operation === "dump_data_fields_utf8") {
1453
1833
  const text = formatDumpDataFields(primaryDoc, operation === "dump_data_fields_utf8");
1454
1834
  if (outputTarget && outputTarget !== "-") {
@@ -1600,9 +1980,9 @@ function* runPdftkCliSteps(argv, files, signal) {
1600
1980
  if (!cached) {
1601
1981
  cached = [];
1602
1982
  const cat = d.cos.resolveDict(d.cos.rootRef);
1603
- const outDict = cat ? d.cos.resolveDict(dictGet(cat, "Outlines")) : void 0;
1983
+ const outDict = cat ? d.cos.resolveDict(dictGet2(cat, "Outlines")) : void 0;
1604
1984
  if (outDict) {
1605
- collectOutlineBookmarks(d, dictGet(outDict, "First"), 1, cached);
1985
+ collectOutlineBookmarks(d, dictGet2(outDict, "First"), 1, cached);
1606
1986
  }
1607
1987
  bookmarksByDoc.set(d, cached);
1608
1988
  }
@@ -1692,7 +2072,7 @@ function* runPdftkCliSteps(argv, files, signal) {
1692
2072
  }
1693
2073
  if (dropXfa) {
1694
2074
  const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
1695
- const acroForm = root ? resultDoc.cos.resolveDict(dictGet(root, "AcroForm")) : void 0;
2075
+ const acroForm = root ? resultDoc.cos.resolveDict(dictGet2(root, "AcroForm")) : void 0;
1696
2076
  if (acroForm)
1697
2077
  dictDelete(acroForm, "XFA");
1698
2078
  }
@@ -1707,8 +2087,8 @@ function* runPdftkCliSteps(argv, files, signal) {
1707
2087
  if (++cooperativeWork % 64 === 0)
1708
2088
  yield;
1709
2089
  if (obj.value.kind === "dict") {
1710
- const stNode = dictGet(obj.value, "Subtype");
1711
- const bfNode = dictGet(obj.value, "BaseFont");
2090
+ const stNode = dictGet2(obj.value, "Subtype");
2091
+ const bfNode = dictGet2(obj.value, "BaseFont");
1712
2092
  const subtype = stNode?.kind === "name" ? stNode.decoded : void 0;
1713
2093
  const baseFont = bfNode?.kind === "name" ? bfNode.decoded : void 0;
1714
2094
  if (subtype === "Type1" && baseFont === "Helvetica") {
@@ -1719,14 +2099,14 @@ function* runPdftkCliSteps(argv, files, signal) {
1719
2099
  }
1720
2100
  if (operation === "fill_form" && !shouldFlatten) {
1721
2101
  const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
1722
- const acroForm = root ? resultDoc.cos.resolveDict(dictGet(root, "AcroForm")) : void 0;
2102
+ const acroForm = root ? resultDoc.cos.resolveDict(dictGet2(root, "AcroForm")) : void 0;
1723
2103
  if (acroForm) {
1724
2104
  dictSet(acroForm, "NeedAppearances", { kind: "boolean", value: needAppearances });
1725
2105
  }
1726
2106
  } else if (needAppearances && !shouldFlatten) {
1727
2107
  const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
1728
2108
  if (root) {
1729
- const acroForm = resultDoc.cos.resolveDict(dictGet(root, "AcroForm"));
2109
+ const acroForm = resultDoc.cos.resolveDict(dictGet2(root, "AcroForm"));
1730
2110
  if (acroForm) {
1731
2111
  dictSet(acroForm, "NeedAppearances", { kind: "boolean", value: true });
1732
2112
  }
@@ -1807,6 +2187,10 @@ async function executePdftk(context) {
1807
2187
  try {
1808
2188
  const carrier = getCommandArguments(context);
1809
2189
  const argv = [...carrier.args];
2190
+ const parsed = await drainSteps(parsePdftkArgumentsSteps(argv), invocation.signal);
2191
+ if (parsed.options && ["dump_data_annots", "dump_data_annots_utf8", "dump_data_fields", "dump_data_fields_utf8"].includes(parsed.options.operation)) {
2192
+ return await executeRetainedPdftk({ ...context, signal: invocation.signal, stdout: invocation.child(context.stdout).output }, parsed.options);
2193
+ }
1810
2194
  const vfsFiles = /* @__PURE__ */ new Map();
1811
2195
  let accountedBytes = 0;
1812
2196
  const chargeBytes = (delta) => {
@@ -1859,7 +2243,7 @@ async function executePdftk(context) {
1859
2243
  if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
1860
2244
  if (filePath === "-") continue;
1861
2245
  try {
1862
- const bytes = await context.fs.readFile(resolvePath(context.cwd, filePath), { signal: invocation.signal });
2246
+ const bytes = await context.fs.readFile(resolvePath2(context.cwd, filePath), { signal: invocation.signal });
1863
2247
  chargeBytes(bytes.byteLength);
1864
2248
  vfsFiles.set(filePath, bytes);
1865
2249
  } catch {
@@ -1869,26 +2253,26 @@ async function executePdftk(context) {
1869
2253
  const existingSnap = new Map(vfsFiles);
1870
2254
  const res = await runPdftkCli(argv, vfsFiles, invocation.signal);
1871
2255
  if (res.stderr) {
1872
- await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
2256
+ await writeBytes2(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
1873
2257
  }
1874
2258
  if (res.stdoutBytes) {
1875
2259
  const stdout = invocation.child(context.stdout);
1876
- await writeBytes(stdout.output, res.stdoutBytes, invocation.signal);
2260
+ await writeBytes2(stdout.output, res.stdoutBytes, invocation.signal);
1877
2261
  } else if (res.stdout) {
1878
2262
  const outBytes = new TextEncoder().encode(res.stdout);
1879
2263
  const stdout = invocation.child(context.stdout);
1880
- await writeBytes(stdout.output, outBytes, invocation.signal);
2264
+ await writeBytes2(stdout.output, outBytes, invocation.signal);
1881
2265
  }
1882
2266
  for (const [key, val] of vfsFiles.entries()) {
1883
2267
  if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
1884
2268
  if (key !== "-" && existingSnap.get(key) !== val) {
1885
- const abs = resolvePath(context.cwd, key);
2269
+ const abs = resolvePath2(context.cwd, key);
1886
2270
  try {
1887
- await writeFileOutput(context, val, (data) => context.fs.writeFile(abs, data, { signal: invocation.signal }));
2271
+ await writeFileOutput2(context, val, (data) => context.fs.writeFile(abs, data, { signal: invocation.signal }));
1888
2272
  } catch (error) {
1889
2273
  invocation.signal.throwIfAborted();
1890
2274
  if (!(error instanceof Error) || !("code" in error)) throw error;
1891
- await writeBytes(context.stderr, new TextEncoder().encode(`Error: Failed to open output file '${key}': ${error.code}.
2275
+ await writeBytes2(context.stderr, new TextEncoder().encode(`Error: Failed to open output file '${key}': ${error.code}.
1892
2276
  `), invocation.signal);
1893
2277
  return { exitCode: 1 };
1894
2278
  }