@poe-platform/safe-bash 0.1.810 → 0.1.811
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.
- package/dist/audio-ast/flac-source.d.ts +13 -0
- package/dist/audio-ast/index.d.ts +1 -0
- package/dist/audio-ast/index.js +248 -179
- package/dist/json-ast/backed-json-parser.d.ts +12 -1
- package/dist/json-ast/index.d.ts +1 -1
- package/dist/office-xml/index.d.ts +1 -0
- package/dist/office-xml/retained-xml-edits.d.ts +22 -0
- package/dist/pdf-ast/cos/qpdf-json-document.d.ts +2 -1
- package/dist/pdf-ast/index.js +151 -56
- package/dist/pdf-ast/retained-document.d.ts +2 -0
- package/dist/safe-bash/audio-ast.browser.js +2 -1
- package/dist/safe-bash/chunks/{chunk-65TFMAZU.js → chunk-BUYRKFW2.js} +8 -35
- package/dist/safe-bash/chunks/{chunk-ZA5FQ34E.js → chunk-TPG55BAQ.js} +0 -2
- package/dist/safe-bash/command-chunks/{biff-ORSHM4YX-QYPGRDAZ.js → biff-3EFLKBAH-NYWZOYQS.js} +2141 -2136
- package/dist/safe-bash/command-chunks/{chunk-HEHGHIE2.js → chunk-22MOB45U.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-6DEWZMOL.js → chunk-2CORNDGF.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-6UHGIWFX.js → chunk-2ZFLMWOX.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-HONWGFDA.js → chunk-33YCKZZX.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-AXWPJRY6.js → chunk-36XGIPOG.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-32ADKP5E.js → chunk-456PHA3L.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-UJXP3T6R.js → chunk-4CKFNXRN.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-5L6GHFRW.js → chunk-554Z6IKP.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-ORZRWT62.js → chunk-56NYSX65.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-53JP3S6H.js → chunk-5HPU7D36.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-YTFWPJ3F.js → chunk-5LI2DLNZ.js} +26 -26
- package/dist/safe-bash/command-chunks/{chunk-CHR2OD2U.js → chunk-5MB64DWR.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-3ZWBBS6U.js → chunk-5OO2P27R.js} +340 -34
- package/dist/safe-bash/command-chunks/{chunk-IC5GJI7E.js → chunk-5Q22ZLNC.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-YO3V5RLY.js → chunk-6CCQI6XZ.js} +12 -12
- package/dist/safe-bash/command-chunks/{chunk-EO2IVGV7.js → chunk-6M6TM5Z5.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-Z54Z3KRN.js → chunk-6QBMND4A.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-INX4JMQ6.js → chunk-6VPQ3CDZ.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-D5AYP2UM.js → chunk-72C3TZ2U.js} +25 -15
- package/dist/safe-bash/command-chunks/{chunk-VGXVN3BX.js → chunk-7GKKMNL6.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-TZJC67W3.js → chunk-7PVHO47B.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-CM3C7AXJ.js → chunk-A2CLZMQZ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-ASR27KHW.js → chunk-A5FZBR7X.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-DMDHE5KC.js → chunk-AHA6IWAJ.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-PTZ55XXN.js → chunk-APEWTWCC.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-YUVH6CE4.js → chunk-ATTWQVR2.js} +17 -17
- package/dist/safe-bash/command-chunks/{chunk-JON5DB3Z.js → chunk-B5LDP7AA.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-CHJL6JMU.js → chunk-COKYZUBW.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-KCTV4NVX.js → chunk-CRV2Q3PB.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-V3WXPCKN.js → chunk-CV7M2QJU.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-VPDSQPSN.js → chunk-DM2CPMB4.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-3DTDMEOP.js → chunk-EAGIJ4VW.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-JW6CMBF2.js → chunk-EHSM5ZQS.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-WIOH7ZQN.js → chunk-ENT3IV2G.js} +12 -12
- package/dist/safe-bash/command-chunks/{chunk-5IE4LJGB.js → chunk-EUT24Y5Z.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-COKZFXHG.js → chunk-FIIAYCWS.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-MWVFP2HY.js → chunk-GEM47B2P.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-EHL6B34L.js → chunk-HDJVJTCK.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-JMM3MNAY.js → chunk-HKATEVAP.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-VWY3EAVQ.js → chunk-HTVIYLVB.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-Z4QJMDK3.js → chunk-IT7TAC3F.js} +16 -16
- package/dist/safe-bash/command-chunks/{chunk-EWS4KYJE.js → chunk-JFYWVQ4V.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-ZCX63QWA.js → chunk-JOCFI7TG.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-F5WTH4O4.js → chunk-JQVHUSDD.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-O4VJEGL6.js → chunk-K5GB2YMN.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-27C3NT5V.js → chunk-KB7DUBVL.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-4DZ32PI7.js → chunk-KCOJA7EM.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-CAXJ4RLF.js → chunk-KJ4XXZIL.js} +12 -12
- package/dist/safe-bash/command-chunks/{chunk-BYZUOF6X.js → chunk-KL3OIBKB.js} +3742 -3726
- package/dist/safe-bash/command-chunks/{chunk-U6QHTC5J.js → chunk-L5MCW6CM.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-LVL3A7YE.js → chunk-LCZDBW55.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-DJVRDUCA.js → chunk-LXLLA4PM.js} +17 -17
- package/dist/safe-bash/command-chunks/{chunk-K7AGAS3K.js → chunk-M7QE2MN7.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-SWT6ILF2.js → chunk-MPUHH2KR.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-DC3OJLRB.js → chunk-NQDIT667.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-LWZVDDJA.js → chunk-NUGQQDGE.js} +5 -1
- package/dist/safe-bash/command-chunks/{chunk-MFLQZLFR.js → chunk-OA75SGN2.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-5LATYOF7.js → chunk-OEJM666F.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-AF25YYIO.js → chunk-PMAM4N33.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-KMMAJ6H6.js → chunk-PNGDJA6M.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-62BHPSKJ.js → chunk-Q6S57NOQ.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-KJ3PEDI2.js → chunk-Q73EMLLZ.js} +146 -4
- package/dist/safe-bash/command-chunks/{chunk-FXKBM5KJ.js → chunk-QC5RMGSA.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-UQ6UIZMM.js → chunk-QD7ZRDUN.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-JHUYZZGV.js → chunk-QYMEASQ6.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-3GY5VDIX.js → chunk-QZZ73J2O.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-S2CYIGWH.js → chunk-R6EGGK5M.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-7AVN3OBH.js → chunk-RHYJVTJO.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-EWGDSO6U.js → chunk-RID6VYS3.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-MMBRBANA.js → chunk-RNSKXOG3.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-D3ZRZTY5.js → chunk-RQIQ75W5.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-DWKQPLRT.js → chunk-RRL3Y562.js} +11 -11
- package/dist/safe-bash/command-chunks/{chunk-NXCMXD74.js → chunk-S6R3IB36.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-XUPKFHAQ.js → chunk-SDTPO2VV.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-PIAGKRFW.js → chunk-SPLOIABU.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-WLTJDNSQ.js → chunk-TVH4JORU.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-6XVMWFHD.js → chunk-TW73OXPR.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-SFO43CID.js → chunk-UAXSE3XE.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-K35BSUHO.js → chunk-UYWSIIUX.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-DCD32BEY.js → chunk-VU3EQF7F.js} +91 -53
- package/dist/safe-bash/command-chunks/{chunk-2E2YEDVB.js → chunk-W5YSINXC.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-EYNT4OEJ.js → chunk-WGG6G2KG.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-DVQBZXMQ.js → chunk-WJCN2IXI.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-XBZ4ZWGL.js → chunk-WVMHRNXZ.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-7GXUCQI4.js → chunk-WXRYDALR.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-S4IIOSRA.js → chunk-X7FA7ZD5.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-SFCERNHU.js → chunk-XPD636C4.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-HYDWQLJ3.js → chunk-XRVKWGVQ.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-3UJWHRK4.js → chunk-XVP6V5K3.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-KTI3BULE.js → chunk-XZ2FWFNV.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-QK3CHRGL.js → chunk-Y4EYCZFT.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-GTWVMFBK.js → chunk-YORJDX4V.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-H6F5SN2N.js → chunk-YSMNXMAO.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-ZEPDT6I5.js → chunk-YSY6R6AS.js} +21 -25
- package/dist/safe-bash/command-chunks/{chunk-SE5SJ4JT.js → chunk-Z2JW6M2D.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-WC2OCF4H.js → chunk-ZHRGYR7B.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-HQYFRQ5W.js → chunk-ZIIO6GRY.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-NTRZMQZP.js → chunk-ZMHEGDU2.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-EYBXHGA6.js → chunk-ZXR6LXV5.js} +2 -2
- package/dist/safe-bash/command-chunks/{engine-MEPOXIXT-WZMRHACG.js → engine-AXXFTGCL-QBQNBI6K.js} +1 -1
- package/dist/safe-bash/command-chunks/pdf-XHHFTOT4-UJJYOYJ2.js +573 -0
- package/dist/safe-bash/commands/diff-patch/index.js +0 -3
- package/dist/safe-bash/commands/diff3/index.js +0 -2
- package/dist/safe-bash/full-core.browser.js +2 -2
- package/dist/safe-bash/plugins/index.browser.js +2 -2
- package/dist/safe-bash/plugins/index.js +3 -1
- package/dist/safe-bash/plugins/portable-commands.d.ts +1 -1
- package/dist/safe-bash/plugins/portable-commands.js +5 -3
- package/dist/safe-bash/registry-entry.browser.js +1 -1
- package/dist/safe-bash-command-diff/index.js +0 -2
- package/dist/safe-bash-command-diff3/index.js +830 -56
- package/dist/safe-bash-command-ffmpeg/index.js +1 -1
- package/dist/safe-bash-command-ffprobe/index.js +2 -2
- package/dist/safe-bash-command-ffprobe/media.js +2 -2
- package/dist/safe-bash-command-html-to-markdown/index.js +75 -21
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/execution.d.ts +2 -2
- package/dist/safe-bash-command-pandoc/index.d.ts +1 -1
- package/dist/safe-bash-command-pandoc/index.js +14 -14
- package/dist/safe-bash-command-pandoc/lua-filters.js +2 -2
- package/dist/safe-bash-command-pandoc/types.d.ts +17 -2
- package/dist/safe-bash-command-patch/index.js +1 -1
- package/dist/safe-bash-command-patch/patch.js +1 -1
- package/dist/safe-bash-command-pdftk/index.js +616 -265
- package/dist/safe-bash-command-qpdf/index.js +115 -9
- package/dist/safe-bash-command-soffice/index.js +1 -1
- package/dist/safe-bash-command-ssconvert/index.js +2 -2
- package/dist/safe-bash-command-xq/index.js +45 -29
- package/dist/safe-bash-presentation-engine/accessibility.js +30 -30
- package/dist/safe-bash-presentation-engine/animation-editing.js +15 -15
- package/dist/safe-bash-presentation-engine/animations.js +15 -15
- package/dist/safe-bash-presentation-engine/backgrounds.js +16 -16
- package/dist/safe-bash-presentation-engine/bytes.js +3 -3
- package/dist/safe-bash-presentation-engine/chart-editing.js +33 -33
- package/dist/safe-bash-presentation-engine/chart-object-operations.js +24 -24
- package/dist/safe-bash-presentation-engine/charts.js +30 -30
- package/dist/safe-bash-presentation-engine/command-placeholder.js +55 -55
- package/dist/safe-bash-presentation-engine/comments.js +16 -16
- package/dist/safe-bash-presentation-engine/connector-operations.js +31 -31
- package/dist/safe-bash-presentation-engine/connectors.js +28 -28
- package/dist/safe-bash-presentation-engine/content-types.js +4 -4
- package/dist/safe-bash-presentation-engine/creation.js +6 -6
- package/dist/safe-bash-presentation-engine/diff.js +31 -31
- package/dist/safe-bash-presentation-engine/drawing-format.js +19 -19
- package/dist/safe-bash-presentation-engine/drawing-operations.js +30 -30
- package/dist/safe-bash-presentation-engine/drawing-schema.js +20 -20
- package/dist/safe-bash-presentation-engine/equations.js +16 -16
- package/dist/safe-bash-presentation-engine/errors.js +2 -2
- package/dist/safe-bash-presentation-engine/fields.js +16 -16
- package/dist/safe-bash-presentation-engine/font-metrics.js +3 -3
- package/dist/safe-bash-presentation-engine/image-extraction.js +19 -19
- package/dist/safe-bash-presentation-engine/image-formatting.js +31 -31
- package/dist/safe-bash-presentation-engine/image-insertion.js +17 -17
- package/dist/safe-bash-presentation-engine/image-replacement.js +20 -20
- package/dist/safe-bash-presentation-engine/image-value.js +4 -4
- package/dist/safe-bash-presentation-engine/images.js +18 -18
- package/dist/safe-bash-presentation-engine/index.d.ts +1 -1
- package/dist/safe-bash-presentation-engine/index.js +95 -93
- package/dist/safe-bash-presentation-engine/layouts.js +15 -15
- package/dist/safe-bash-presentation-engine/length.js +3 -3
- package/dist/safe-bash-presentation-engine/links.js +15 -15
- package/dist/safe-bash-presentation-engine/masters.js +14 -14
- package/dist/safe-bash-presentation-engine/media-editing.js +23 -23
- package/dist/safe-bash-presentation-engine/media-extraction.js +16 -16
- package/dist/safe-bash-presentation-engine/media.js +15 -15
- package/dist/safe-bash-presentation-engine/memberships.js +14 -14
- package/dist/safe-bash-presentation-engine/notes.js +15 -15
- package/dist/safe-bash-presentation-engine/ole-enum.js +4 -4
- package/dist/safe-bash-presentation-engine/ole-insertion.js +19 -19
- package/dist/safe-bash-presentation-engine/opaque-objects.js +9 -9
- package/dist/safe-bash-presentation-engine/package-reader.js +5 -5
- package/dist/safe-bash-presentation-engine/package-tools.js +15 -15
- package/dist/safe-bash-presentation-engine/package-uri.js +3 -3
- package/dist/safe-bash-presentation-engine/package-writer.js +4 -4
- package/dist/safe-bash-presentation-engine/presentation-model.js +54 -54
- package/dist/safe-bash-presentation-engine/presentation-settings.js +13 -13
- package/dist/safe-bash-presentation-engine/properties.js +15 -15
- package/dist/safe-bash-presentation-engine/relationships.js +4 -4
- package/dist/safe-bash-presentation-engine/resource-limits.js +1 -1
- package/dist/safe-bash-presentation-engine/retained-inspection.js +12 -12
- package/dist/safe-bash-presentation-engine/retained-package.js +4 -4
- package/dist/safe-bash-presentation-engine/retained-slide-settings.d.ts +15 -0
- package/dist/safe-bash-presentation-engine/retained-text.js +17 -17
- package/dist/safe-bash-presentation-engine/sanitize.js +16 -16
- package/dist/safe-bash-presentation-engine/selectors.js +10 -10
- package/dist/safe-bash-presentation-engine/shape-groups.js +30 -30
- package/dist/safe-bash-presentation-engine/shape-operations.js +29 -29
- package/dist/safe-bash-presentation-engine/shape-path-operations.js +31 -31
- package/dist/safe-bash-presentation-engine/shape-paths.js +15 -15
- package/dist/safe-bash-presentation-engine/shape-presets.js +3 -3
- package/dist/safe-bash-presentation-engine/shape-selection.js +30 -30
- package/dist/safe-bash-presentation-engine/shape-transforms.js +17 -17
- package/dist/safe-bash-presentation-engine/shapes.js +26 -26
- package/dist/safe-bash-presentation-engine/slide-copy.js +16 -16
- package/dist/safe-bash-presentation-engine/slide-import.js +17 -17
- package/dist/safe-bash-presentation-engine/slide-merge-split.js +19 -19
- package/dist/safe-bash-presentation-engine/slide-model.js +42 -42
- package/dist/safe-bash-presentation-engine/slide-removal.js +17 -17
- package/dist/safe-bash-presentation-engine/slide-transfer-budget.js +9 -9
- package/dist/safe-bash-presentation-engine/slides.d.ts +2 -0
- package/dist/safe-bash-presentation-engine/slides.js +21 -16
- package/dist/safe-bash-presentation-engine/table-operations.js +32 -32
- package/dist/safe-bash-presentation-engine/table-spans.js +31 -31
- package/dist/safe-bash-presentation-engine/tables.js +30 -30
- package/dist/safe-bash-presentation-engine/tags.js +15 -15
- package/dist/safe-bash-presentation-engine/template-bindings.js +32 -32
- package/dist/safe-bash-presentation-engine/template-repeat.js +39 -39
- package/dist/safe-bash-presentation-engine/text-fitting.js +26 -26
- package/dist/safe-bash-presentation-engine/text-frames.js +26 -26
- package/dist/safe-bash-presentation-engine/text-paragraphs.js +26 -26
- package/dist/safe-bash-presentation-engine/text-reading.js +11 -11
- package/dist/safe-bash-presentation-engine/text-replacement.js +16 -16
- package/dist/safe-bash-presentation-engine/text-runs.js +19 -19
- package/dist/safe-bash-presentation-engine/themes.js +15 -15
- package/dist/safe-bash-presentation-engine/transitions.js +15 -15
- package/dist/safe-bash-presentation-engine/validation.js +9 -9
- package/dist/safe-bash-presentation-engine/xml-parts.js +15 -15
- package/dist/safe-bash-presentation-engine/xml-view.js +3 -3
- package/dist/safe-bash-presentation-engine/xml.js +3 -3
- package/dist/safe-bash-xml-engine/json.d.ts +1 -0
- package/dist/safe-bash-xml-engine/json.js +203 -0
- package/dist/safe-bash-xml-engine/stored-json.d.ts +5 -0
- package/dist/spreadsheet-engine/rendering/print/bidi-runs.d.ts +5 -0
- package/dist/spreadsheet-engine/rendering/print/bidi-runs.js +35 -0
- package/dist/spreadsheet-engine/rendering/print/control-bidi.d.ts +8 -0
- package/dist/spreadsheet-engine/rendering/print/control-bidi.js +80 -0
- package/dist/spreadsheet-format-xls/biff-encrypted-properties.d.ts +4 -4
- package/dist/spreadsheet-format-xls/biff-encrypted-properties.js +36 -23
- package/dist/spreadsheet-format-xls/biff-encryption.js +1 -1
- package/dist/spreadsheet-format-xls/biff-property-bytes.d.ts +4 -1
- package/dist/spreadsheet-format-xls/biff-property-bytes.js +1 -1
- package/dist/spreadsheet-format-xls/biff-range.js +1 -1
- package/package.json +5 -2
- package/dist/safe-bash/command-chunks/pdf-LOZAXXS6-ERI57IAV.js +0 -557
|
@@ -1,35 +1,343 @@
|
|
|
1
1
|
import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
|
|
2
2
|
|
|
3
|
-
// packages/safe-bash-command-pdftk/src/
|
|
3
|
+
// packages/safe-bash-command-pdftk/src/retained.ts
|
|
4
|
+
import { PdfError, PdfFileSource, PdfRetainedDocument, retainedCosObjects } from "../pdf-ast/index.js";
|
|
5
|
+
import { FsError } from "../safe-bash-contracts/errors.js";
|
|
6
|
+
import { writeBytes } from "../safe-bash-contracts/io.js";
|
|
4
7
|
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
8
|
import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from "../
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
9
|
+
|
|
10
|
+
// packages/safe-bash-command-pdftk/src/retained-annots.ts
|
|
11
|
+
import { IntegerTable, PagedStorage } from "@poe-platform/safe-fs/storage";
|
|
12
|
+
import { PdfMutableObjectStore, decodePdfString, dictGet } from "../pdf-ast/index.js";
|
|
13
|
+
async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
14
|
+
const backing = new PagedStorage({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), pages = new IntegerTable(backing, 64);
|
|
15
|
+
let pageCount = 0, work = 0, failed = false;
|
|
16
|
+
const encoder = new TextEncoder();
|
|
17
|
+
async function checkpoint() {
|
|
18
|
+
signal.throwIfAborted();
|
|
19
|
+
if (++work % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
20
|
+
signal.throwIfAborted();
|
|
21
|
+
}
|
|
22
|
+
async function resolve(node) {
|
|
23
|
+
await checkpoint();
|
|
24
|
+
const result = await document.lookup(node);
|
|
25
|
+
return result?.stream ? void 0 : result?.value;
|
|
26
|
+
}
|
|
27
|
+
async function* line(prefix, value, encode = false) {
|
|
28
|
+
let part = prefix;
|
|
29
|
+
for (const char of String(value)) {
|
|
30
|
+
const code = char.codePointAt(0);
|
|
31
|
+
part += encode && !utf8 && code > 127 ? `&#${code};` : char;
|
|
32
|
+
if (part.length >= 4096) {
|
|
33
|
+
await checkpoint();
|
|
34
|
+
yield encoder.encode(part);
|
|
35
|
+
part = "";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
yield encoder.encode(part + "\n");
|
|
39
|
+
}
|
|
40
|
+
async function* walk(start, key) {
|
|
41
|
+
if (!start) return;
|
|
42
|
+
const stack = new PdfMutableObjectStore(storage, { signal }), seen = new IntegerTable(backing, 64);
|
|
43
|
+
let pending = 0, failed2 = false;
|
|
44
|
+
const push = async (value) => {
|
|
45
|
+
await checkpoint();
|
|
46
|
+
await stack.set({ objectNumber: ++pending, generationNumber: 0, value });
|
|
47
|
+
};
|
|
48
|
+
try {
|
|
49
|
+
await push(start);
|
|
50
|
+
while (pending) {
|
|
51
|
+
await checkpoint();
|
|
52
|
+
const raw = (await stack.get(pending--)).value;
|
|
53
|
+
if (raw.kind === "ref") {
|
|
54
|
+
if (await seen.get(BigInt(raw.objectNumber))) continue;
|
|
55
|
+
await seen.set(BigInt(raw.objectNumber), 1n);
|
|
56
|
+
}
|
|
57
|
+
const value = await resolve(raw);
|
|
58
|
+
if (value?.kind === "array" && key === "Next") {
|
|
59
|
+
for (let i = value.items.length - 1; i >= 0; i--) await push(value.items[i]);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (value?.kind !== "dict") continue;
|
|
63
|
+
yield value;
|
|
64
|
+
const child = dictGet(value, key);
|
|
65
|
+
if (key === "Next") {
|
|
66
|
+
if (child) await push(child);
|
|
67
|
+
} else {
|
|
68
|
+
const kids = await resolve(child);
|
|
69
|
+
if (kids?.kind === "array") for (let i = kids.items.length - 1; i >= 0; i--) await push(kids.items[i]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
failed2 = true;
|
|
74
|
+
throw error;
|
|
75
|
+
} finally {
|
|
76
|
+
await stack.close().catch((error) => {
|
|
77
|
+
if (!failed2) throw error;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function destinationIndex(raw) {
|
|
82
|
+
let node = await resolve(raw);
|
|
83
|
+
if (node?.kind === "dict") {
|
|
84
|
+
const target = dictGet(node, "D") ?? dictGet(node, "Dest");
|
|
85
|
+
if (target) node = await resolve(target);
|
|
86
|
+
}
|
|
87
|
+
if (node?.kind === "string" || node?.kind === "name") {
|
|
88
|
+
const name = node.kind === "string" ? decodePdfString(node) : node.decoded;
|
|
89
|
+
const root = await resolve(document.crossReference.rootRef);
|
|
90
|
+
let target;
|
|
91
|
+
if (root?.kind === "dict") {
|
|
92
|
+
const legacy = await resolve(dictGet(root, "Dests"));
|
|
93
|
+
if (legacy?.kind === "dict") target = dictGet(legacy, name);
|
|
94
|
+
if (!target) {
|
|
95
|
+
const names = await resolve(dictGet(root, "Names"));
|
|
96
|
+
if (names?.kind === "dict") for await (const branch of walk(dictGet(names, "Dests"), "Kids")) {
|
|
97
|
+
const pairs = await resolve(dictGet(branch, "Names"));
|
|
98
|
+
if (pairs?.kind === "array") for (let i = 0; i + 1 < pairs.items.length; i += 2) {
|
|
99
|
+
const key = await resolve(pairs.items[i]);
|
|
100
|
+
if ((key?.kind === "string" ? decodePdfString(key) : key?.kind === "name" ? key.decoded : "") === name) {
|
|
101
|
+
target = pairs.items[i + 1];
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (target) break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
node = await resolve(target);
|
|
110
|
+
if (node?.kind === "dict") {
|
|
111
|
+
const inner = dictGet(node, "D");
|
|
112
|
+
if (inner) node = await resolve(inner);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (node?.kind !== "array" || !node.items.length) return;
|
|
116
|
+
const first = node.items[0];
|
|
117
|
+
if (first.kind === "ref") {
|
|
118
|
+
const found = await pages.get(BigInt(first.objectNumber));
|
|
119
|
+
return found ? Number(found) - 1 : void 0;
|
|
120
|
+
}
|
|
121
|
+
const number = await resolve(first);
|
|
122
|
+
return number?.kind === "number" && number.value >= 0 && number.value < pageCount ? Math.round(number.value) : void 0;
|
|
123
|
+
}
|
|
124
|
+
async function destinationText(raw) {
|
|
125
|
+
const node = await resolve(raw);
|
|
126
|
+
if (node?.kind === "string") return decodePdfString(node);
|
|
127
|
+
if (node?.kind === "name") return node.decoded;
|
|
128
|
+
if (node?.kind === "array") {
|
|
129
|
+
const first = node.items[0];
|
|
130
|
+
if (first?.kind === "ref") {
|
|
131
|
+
const found = await pages.get(BigInt(first.objectNumber));
|
|
132
|
+
if (found) return `page ${found}`;
|
|
133
|
+
} else if (first?.kind === "number") return `page ${first.value + 1}`;
|
|
134
|
+
}
|
|
135
|
+
if (node?.kind === "dict") {
|
|
136
|
+
const index = await destinationIndex(node);
|
|
137
|
+
if (index !== void 0) return `page ${index + 1}`;
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
async function* stringField(dict, key, label) {
|
|
142
|
+
const node = await resolve(dictGet(dict, key));
|
|
143
|
+
if (node?.kind === "string") yield* line(label, decodePdfString(node), true);
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
for await (const page of document.pages()) {
|
|
147
|
+
pageCount++;
|
|
148
|
+
if (page.reference && !await pages.get(BigInt(page.reference.objectNumber))) await pages.set(BigInt(page.reference.objectNumber), BigInt(page.index + 1));
|
|
149
|
+
}
|
|
150
|
+
for (let i = 0; i < 2; i++) {
|
|
151
|
+
const id = await resolve(document.crossReference.idArray?.items[i]);
|
|
152
|
+
if (id?.kind !== "string") yield* line(`PdfID${i}: `, "00000000000000000000000000000000");
|
|
153
|
+
else {
|
|
154
|
+
yield encoder.encode(`PdfID${i}: `);
|
|
155
|
+
for (let at = 0; at < id.bytes.length; at += 2048) {
|
|
156
|
+
await checkpoint();
|
|
157
|
+
let text = "";
|
|
158
|
+
for (const byte of id.bytes.subarray(at, at + 2048)) text += byte.toString(16).padStart(2, "0");
|
|
159
|
+
yield encoder.encode(text);
|
|
160
|
+
}
|
|
161
|
+
yield encoder.encode("\n");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
yield* line("NumberOfPages: ", pageCount);
|
|
165
|
+
for await (const page of document.pages()) {
|
|
166
|
+
const annotations = await resolve(dictGet(page.dict, "Annots"));
|
|
167
|
+
if (annotations?.kind !== "array") continue;
|
|
168
|
+
for (const item of annotations.items) {
|
|
169
|
+
const annotation = await resolve(item);
|
|
170
|
+
if (annotation?.kind !== "dict") continue;
|
|
171
|
+
const subtype = await resolve(dictGet(annotation, "Subtype")), rect = await resolve(dictGet(annotation, "Rect"));
|
|
172
|
+
const numbers = [];
|
|
173
|
+
if (rect?.kind === "array") for (const value of rect.items) {
|
|
174
|
+
const number = await resolve(value);
|
|
175
|
+
if (numbers.length < 4) numbers.push(number?.kind === "number" ? number.value : 0);
|
|
176
|
+
}
|
|
177
|
+
else numbers.push(0, 0, 0, 0);
|
|
178
|
+
yield encoder.encode("---\n");
|
|
179
|
+
yield* line("AnnotSubtype: ", subtype?.kind === "name" ? subtype.decoded : "Annot");
|
|
180
|
+
yield* line("AnnotRect: ", numbers.join(" "));
|
|
181
|
+
for (const [key, label] of [["NM", "Name"], ["T", "Title"], ["Subj", "Subj"], ["Contents", "Contents"]]) yield* stringField(annotation, key, `Annot${label}: `);
|
|
182
|
+
const color = await resolve(dictGet(annotation, "C"));
|
|
183
|
+
if (color?.kind === "array" && color.items.length >= 3) {
|
|
184
|
+
const channels = [];
|
|
185
|
+
for (const value of color.items.slice(0, 3)) {
|
|
186
|
+
const number = await resolve(value);
|
|
187
|
+
channels.push(number?.kind === "number" ? number.value : 0);
|
|
188
|
+
}
|
|
189
|
+
yield* line("AnnotColor: ", channels.join(" "));
|
|
190
|
+
}
|
|
191
|
+
const open = await resolve(dictGet(annotation, "Open"));
|
|
192
|
+
if (open?.kind === "boolean") yield* line("AnnotOpen: ", open.value);
|
|
193
|
+
yield* stringField(annotation, "M", "AnnotModificationDate: ");
|
|
194
|
+
const flags = await resolve(dictGet(annotation, "F"));
|
|
195
|
+
yield* line("AnnotFlags: ", flags?.kind === "number" ? flags.value : 0);
|
|
196
|
+
yield* line("AnnotPageNumber: ", page.index + 1);
|
|
197
|
+
const action = dictGet(annotation, "A");
|
|
198
|
+
if (action) for await (const dict of walk(action, "Next")) {
|
|
199
|
+
const type = await resolve(dictGet(dict, "S"));
|
|
200
|
+
if (type?.kind === "name" && type.decoded) yield* line("AnnotActionType: ", type.decoded);
|
|
201
|
+
yield* stringField(dict, "URI", "AnnotActionURI: ");
|
|
202
|
+
const dest = dictGet(dict, "D"), text = await destinationText(dest);
|
|
203
|
+
if (text) yield* line("AnnotActionDest: ", text, true);
|
|
204
|
+
const index = await destinationIndex(dest ?? dict);
|
|
205
|
+
if (index !== void 0) yield* line("AnnotActionPageNumber: ", index + 1);
|
|
206
|
+
const file = await resolve(dictGet(dict, "F"));
|
|
207
|
+
if (file?.kind === "string") yield* line("AnnotActionFile: ", decodePdfString(file), true);
|
|
208
|
+
else if (file?.kind === "dict") {
|
|
209
|
+
const name = await resolve(dictGet(file, "UF") ?? dictGet(file, "F"));
|
|
210
|
+
if (name?.kind === "string") yield* line("AnnotActionFile: ", decodePdfString(name), true);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (dictGet(annotation, "Dest")) {
|
|
214
|
+
yield* line("AnnotActionType: ", "GoTo");
|
|
215
|
+
const dest = dictGet(annotation, "Dest"), text = await destinationText(dest);
|
|
216
|
+
if (text) yield* line("AnnotActionDest: ", text, true);
|
|
217
|
+
const index = await destinationIndex(dest);
|
|
218
|
+
if (index !== void 0) yield* line("AnnotActionPageNumber: ", index + 1);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
} catch (error) {
|
|
223
|
+
failed = true;
|
|
224
|
+
throw error;
|
|
225
|
+
} finally {
|
|
226
|
+
await backing.close().catch((error) => {
|
|
227
|
+
if (!failed) throw error;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// packages/safe-bash-command-pdftk/src/retained.ts
|
|
233
|
+
async function executeRetainedPdftk(context, options) {
|
|
234
|
+
const signal = context.signal, storage = { fs: context.fs, directory: resolvePath(context.cwd, context.env.TMPDIR || "/tmp") };
|
|
235
|
+
const inputs = /* @__PURE__ */ new Map();
|
|
236
|
+
let document, output, total = 0, failed = false;
|
|
237
|
+
const diagnostic = async (message) => {
|
|
238
|
+
await writeBytes(context.stderr, new TextEncoder().encode(message), signal);
|
|
239
|
+
return { exitCode: 1 };
|
|
240
|
+
};
|
|
241
|
+
try {
|
|
242
|
+
await context.fs.mkdir(storage.directory, { recursive: true, signal });
|
|
243
|
+
const maximum = context.inputBudget?.maxBytes ?? Infinity;
|
|
244
|
+
if (options.inputs.some((input) => input.file === "-")) {
|
|
245
|
+
const source = await PdfFileSource.fromStream(context.fs, storage.directory, context.stdin, { signal, maxInputBytes: maximum });
|
|
246
|
+
inputs.set("-", source);
|
|
247
|
+
total += source.size;
|
|
248
|
+
context.inputBudget?.check(total);
|
|
249
|
+
}
|
|
250
|
+
for (const input of options.inputs) {
|
|
251
|
+
if (inputs.has(input.file)) continue;
|
|
252
|
+
let source;
|
|
253
|
+
try {
|
|
254
|
+
source = await PdfFileSource.open(context.fs, resolvePath(context.cwd, input.file), { signal, maxInputBytes: maximum - total });
|
|
255
|
+
} catch (error) {
|
|
256
|
+
signal.throwIfAborted();
|
|
257
|
+
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") {
|
|
258
|
+
inputs.set(input.file, void 0);
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
inputs.set(input.file, source);
|
|
264
|
+
total += source.size;
|
|
265
|
+
context.inputBudget?.check(total);
|
|
266
|
+
}
|
|
267
|
+
for (const input of options.inputs) {
|
|
268
|
+
const source = inputs.get(input.file);
|
|
269
|
+
if (!source) return await diagnostic(`Error: Unable to find file '${input.file}'
|
|
270
|
+
`);
|
|
271
|
+
try {
|
|
272
|
+
document = await PdfRetainedDocument.open(source, storage, { signal, recovery: "strict", ...input.password ? { password: input.password } : {} });
|
|
273
|
+
for await (const object of retainedCosObjects(document, storage, { signal })) if (object.stream) for await (const ignored of object.stream.chunks) void ignored;
|
|
274
|
+
for await (const ignored of document.pages()) void ignored;
|
|
275
|
+
} catch (error) {
|
|
276
|
+
signal.throwIfAborted();
|
|
277
|
+
if (!(error instanceof PdfError) || error.code === "E_LIMIT" || error.code === "E_CANCELLED") throw error;
|
|
278
|
+
return await diagnostic(`Error: Failed to open PDF '${input.file}': ${error.message}
|
|
279
|
+
`);
|
|
280
|
+
}
|
|
281
|
+
await document.close();
|
|
282
|
+
document = void 0;
|
|
283
|
+
await source.releaseCache();
|
|
284
|
+
}
|
|
285
|
+
const primary = options.inputs[0];
|
|
286
|
+
document = await PdfRetainedDocument.open(inputs.get(primary.file), storage, { signal, recovery: "strict", ...primary.password ? { password: primary.password } : {} });
|
|
287
|
+
output = await PdfFileSource.fromStream(context.fs, storage.directory, retainedAnnotationReport(document, storage, options.operation.endsWith("_utf8"), signal), { signal });
|
|
288
|
+
const destination = options.outputTarget;
|
|
289
|
+
if (!destination || destination === "-") for await (const bytes of output.stream(0, output.size, signal)) await writeBytes(context.stdout, bytes, signal);
|
|
290
|
+
else {
|
|
291
|
+
try {
|
|
292
|
+
await publish(context, resolvePath(context.cwd, destination), output);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
signal.throwIfAborted();
|
|
295
|
+
if (!(error instanceof Error) || !("code" in error)) throw error;
|
|
296
|
+
return await diagnostic(`Error: Failed to open output file '${destination}': ${error.code}.
|
|
297
|
+
`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return { exitCode: 0 };
|
|
301
|
+
} catch (error) {
|
|
302
|
+
failed = true;
|
|
303
|
+
throw error;
|
|
304
|
+
} finally {
|
|
305
|
+
const results = await Promise.allSettled([document?.close(), output?.close(), ...[...inputs.values()].map((source) => source?.close())]);
|
|
306
|
+
if (!failed) {
|
|
307
|
+
for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async function publish(context, path, source) {
|
|
312
|
+
const fs = context.fs, signal = context.signal;
|
|
313
|
+
const capabilities = await fs.capabilitiesFor?.(path, { signal, create: true, stagingAncestry: true }) ?? fs.capabilities;
|
|
314
|
+
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" });
|
|
315
|
+
const resolution = await fs.prepareStagingResolution(path, { signal }), directory = resolvePath(resolution.path, "..");
|
|
316
|
+
const staging = await fs.createStagedFile(`${directory}/.pdf-${crypto.randomUUID()}`, "output", { type: "file", data: new Uint8Array() }, { parent: resolution.parent, retainCleanup: true, signal });
|
|
317
|
+
let failed = false;
|
|
318
|
+
try {
|
|
319
|
+
if (!staging.writer || !staging.cleanup) throw new FsError("ENOTSUP", { path, message: "PDF backend omitted retained staging handles" });
|
|
320
|
+
for await (const bytes of source.stream(0, source.size, signal)) await writeFileOutput(context, bytes, (data) => staging.writer.write(data, { signal }));
|
|
321
|
+
const stat = await staging.writer.finish({ signal });
|
|
322
|
+
await fs.publishStagedFile({ ...staging, file: { ...staging.file, stat } }, resolution.path, { parent: resolution.parent, destination: resolution.destination, ancestors: resolution.ancestors, commitGuard: resolution.validate, signal });
|
|
323
|
+
} catch (error) {
|
|
324
|
+
failed = true;
|
|
325
|
+
throw error;
|
|
326
|
+
} finally {
|
|
327
|
+
const cleanup = async () => {
|
|
328
|
+
try {
|
|
329
|
+
await staging.cleanup?.remove();
|
|
330
|
+
} finally {
|
|
331
|
+
await staging.cleanup?.close();
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
await cleanup().catch((error) => {
|
|
335
|
+
if (!failed) throw error;
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// packages/safe-bash-command-pdftk/src/arguments.ts
|
|
33
341
|
var PDFTK_OPERATIONS = /* @__PURE__ */ new Set([
|
|
34
342
|
"cat",
|
|
35
343
|
"shuffle",
|
|
@@ -55,6 +363,175 @@ var PDFTK_OPERATIONS = /* @__PURE__ */ new Set([
|
|
|
55
363
|
"output",
|
|
56
364
|
"input_pw"
|
|
57
365
|
]);
|
|
366
|
+
function* parsePdftkArgumentsSteps(argv) {
|
|
367
|
+
let cooperativeWork = 63;
|
|
368
|
+
if (argv.length === 0 || argv.includes("--help") || argv.includes("-h")) {
|
|
369
|
+
return { result: {
|
|
370
|
+
exitCode: 0,
|
|
371
|
+
stdout: "Usage: pdftk <input PDF files | [handle]=filename ...> [<operation> <operation arguments>] [output <output filename>] [flatten]\n",
|
|
372
|
+
stderr: ""
|
|
373
|
+
} };
|
|
374
|
+
}
|
|
375
|
+
if (argv.includes("--version") || argv.includes("-v")) {
|
|
376
|
+
return { result: { exitCode: 0, stdout: "pdftk port to Java 3.3.3 (safe-bash @poe-code/pdf-ast)\n", stderr: "" } };
|
|
377
|
+
}
|
|
378
|
+
const inputPasswords = /* @__PURE__ */ new Map();
|
|
379
|
+
let defaultInputPassword = "";
|
|
380
|
+
for (let p = 0; p < argv.length; p++) {
|
|
381
|
+
if (++cooperativeWork % 64 === 0)
|
|
382
|
+
yield;
|
|
383
|
+
if (argv[p]?.toLowerCase() === "input_pw") {
|
|
384
|
+
for (let q = p + 1; q < argv.length; q++) {
|
|
385
|
+
if (++cooperativeWork % 64 === 0)
|
|
386
|
+
yield;
|
|
387
|
+
const tok = argv[q];
|
|
388
|
+
if (PDFTK_OPERATIONS.has(tok.toLowerCase()))
|
|
389
|
+
break;
|
|
390
|
+
const eq = tok.indexOf("=");
|
|
391
|
+
if (eq > 0)
|
|
392
|
+
inputPasswords.set(tok.slice(0, eq), tok.slice(eq + 1));
|
|
393
|
+
else
|
|
394
|
+
defaultInputPassword = tok;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const inputs = [];
|
|
399
|
+
let idx = 0;
|
|
400
|
+
let autoHandleCharCode = 65;
|
|
401
|
+
while (idx < argv.length) {
|
|
402
|
+
if (++cooperativeWork % 64 === 0)
|
|
403
|
+
yield;
|
|
404
|
+
const token = argv[idx];
|
|
405
|
+
if (PDFTK_OPERATIONS.has(token.toLowerCase()) || token.toLowerCase() === "input_pw")
|
|
406
|
+
break;
|
|
407
|
+
idx++;
|
|
408
|
+
let handleName = "";
|
|
409
|
+
let filePath = token;
|
|
410
|
+
const eqIdx = token.indexOf("=");
|
|
411
|
+
if (eqIdx > 0) {
|
|
412
|
+
handleName = token.slice(0, eqIdx);
|
|
413
|
+
filePath = token.slice(eqIdx + 1);
|
|
414
|
+
} else {
|
|
415
|
+
handleName = String.fromCharCode(autoHandleCharCode++);
|
|
416
|
+
}
|
|
417
|
+
inputs.push({ handle: handleName, file: filePath, password: inputPasswords.get(handleName) ?? defaultInputPassword });
|
|
418
|
+
}
|
|
419
|
+
if (inputs.length === 0) {
|
|
420
|
+
return { result: { exitCode: 1, stdout: "", stderr: "Error: No input PDF files specified.\n" } };
|
|
421
|
+
}
|
|
422
|
+
while (idx < argv.length && argv[idx]?.toLowerCase() === "input_pw") {
|
|
423
|
+
if (++cooperativeWork % 64 === 0)
|
|
424
|
+
yield;
|
|
425
|
+
idx++;
|
|
426
|
+
while (idx < argv.length && !PDFTK_OPERATIONS.has(argv[idx].toLowerCase())) {
|
|
427
|
+
if (++cooperativeWork % 64 === 0)
|
|
428
|
+
yield;
|
|
429
|
+
idx++;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
const operation = (argv[idx] ?? "cat").toLowerCase();
|
|
433
|
+
idx++;
|
|
434
|
+
const opArgs = [];
|
|
435
|
+
let outputTarget;
|
|
436
|
+
if (operation === "output") {
|
|
437
|
+
outputTarget = argv[idx++];
|
|
438
|
+
}
|
|
439
|
+
let shouldFlatten = false;
|
|
440
|
+
let needAppearances = false;
|
|
441
|
+
let dropXfa = false;
|
|
442
|
+
let dropXmp = false;
|
|
443
|
+
let replacementFont;
|
|
444
|
+
let keepFirstId = false;
|
|
445
|
+
let keepFinalId = false;
|
|
446
|
+
let uncompressStreams = false;
|
|
447
|
+
let compressStreams = false;
|
|
448
|
+
let userPassword;
|
|
449
|
+
let ownerPassword;
|
|
450
|
+
const allowPermissions = /* @__PURE__ */ new Set();
|
|
451
|
+
const ALLOW_KEYWORDS = /* @__PURE__ */ new Set([
|
|
452
|
+
"printing",
|
|
453
|
+
"degradedprinting",
|
|
454
|
+
"modifycontents",
|
|
455
|
+
"assembly",
|
|
456
|
+
"copycontents",
|
|
457
|
+
"screenreaders",
|
|
458
|
+
"modifyannotations",
|
|
459
|
+
"fillin",
|
|
460
|
+
"allfeatures"
|
|
461
|
+
]);
|
|
462
|
+
while (idx < argv.length) {
|
|
463
|
+
if (++cooperativeWork % 64 === 0)
|
|
464
|
+
yield;
|
|
465
|
+
const tok = argv[idx++];
|
|
466
|
+
const lower = tok.toLowerCase();
|
|
467
|
+
if (lower === "output") {
|
|
468
|
+
outputTarget = argv[idx++];
|
|
469
|
+
} else if (lower === "flatten") {
|
|
470
|
+
shouldFlatten = true;
|
|
471
|
+
} else if (lower === "need_appearances") {
|
|
472
|
+
needAppearances = true;
|
|
473
|
+
} else if (lower === "user_pw") {
|
|
474
|
+
userPassword = argv[idx++];
|
|
475
|
+
} else if (lower === "owner_pw") {
|
|
476
|
+
ownerPassword = argv[idx++];
|
|
477
|
+
} else if (lower === "allow") {
|
|
478
|
+
while (idx < argv.length && ALLOW_KEYWORDS.has(argv[idx].toLowerCase())) {
|
|
479
|
+
if (++cooperativeWork % 64 === 0)
|
|
480
|
+
yield;
|
|
481
|
+
allowPermissions.add(argv[idx++].toLowerCase());
|
|
482
|
+
}
|
|
483
|
+
} else if (lower === "keep_first_id") {
|
|
484
|
+
keepFirstId = true;
|
|
485
|
+
} else if (lower === "keep_final_id") {
|
|
486
|
+
keepFinalId = true;
|
|
487
|
+
} else if (lower === "uncompress") {
|
|
488
|
+
uncompressStreams = true;
|
|
489
|
+
} else if (lower === "compress") {
|
|
490
|
+
compressStreams = true;
|
|
491
|
+
} else if (lower === "dont_ask" || lower === "do_ask" || lower === "encrypt_128bit" || lower === "encrypt_40bit" || lower === "verbose") {
|
|
492
|
+
} else if (lower === "drop_xfa") {
|
|
493
|
+
dropXfa = true;
|
|
494
|
+
} else if (lower === "drop_xmp") {
|
|
495
|
+
dropXmp = true;
|
|
496
|
+
} else if (lower === "replacement_font") {
|
|
497
|
+
replacementFont = argv[idx++];
|
|
498
|
+
} else {
|
|
499
|
+
opArgs.push(tok);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return { options: { inputs, operation, opArgs, outputTarget, shouldFlatten, needAppearances, dropXfa, dropXmp, replacementFont, keepFirstId, keepFinalId, uncompressStreams, compressStreams, userPassword, ownerPassword, allowPermissions } };
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// packages/safe-bash-command-pdftk/src/index.ts
|
|
506
|
+
import { resolvePath as resolvePath2 } from "../safe-bash-contracts/path.js";
|
|
507
|
+
import { yieldTurn, drainCooperativeSteps as drainSteps } from "../safe-bash-contracts/yield.js";
|
|
508
|
+
import { InputByteBudget } from "../safe-bash-contracts/io.js";
|
|
509
|
+
import { writeFileOutput as writeFileOutput2 } from "../safe-bash-contracts/filesystem-output-budget.js";
|
|
510
|
+
import {
|
|
511
|
+
commandRuntimeIdentity,
|
|
512
|
+
getCommandArguments
|
|
513
|
+
} from "../safe-bash-contracts/command.js";
|
|
514
|
+
import { readBytes, writeBytes as writeBytes2 } from "../safe-bash-contracts/io.js";
|
|
515
|
+
import { createOutputOperation } from "../safe-bash-contracts/output.js";
|
|
516
|
+
import {
|
|
517
|
+
PdfDocument,
|
|
518
|
+
cosArray,
|
|
519
|
+
cosDict,
|
|
520
|
+
cosHexString,
|
|
521
|
+
cosName,
|
|
522
|
+
cosNumber,
|
|
523
|
+
cosStream,
|
|
524
|
+
cosString,
|
|
525
|
+
decodePdfString as decodePdfString2,
|
|
526
|
+
dictDelete,
|
|
527
|
+
dictGet as dictGet2,
|
|
528
|
+
dictSet,
|
|
529
|
+
flattenDocumentFormFields,
|
|
530
|
+
getDocumentFormFields,
|
|
531
|
+
parseFormDataBytes,
|
|
532
|
+
resolveDestinationPageIndex,
|
|
533
|
+
setDocumentFormField
|
|
534
|
+
} from "../pdf-ast/index.js";
|
|
58
535
|
function parseRotationSuffix(raw) {
|
|
59
536
|
const lower = raw.toLowerCase();
|
|
60
537
|
const wordRotations = [
|
|
@@ -263,40 +740,40 @@ function formatDumpDataAnnots(doc, utf8 = false) {
|
|
|
263
740
|
lines.push(`NumberOfPages: ${doc.pageCount}`);
|
|
264
741
|
for (let p = 0; p < doc.pageCount; p++) {
|
|
265
742
|
const pageDict = doc.getPage(p).pageDict;
|
|
266
|
-
const annotsArr = doc.cos.resolveArray(
|
|
743
|
+
const annotsArr = doc.cos.resolveArray(dictGet2(pageDict, "Annots"));
|
|
267
744
|
if (!annotsArr) continue;
|
|
268
745
|
for (const item of annotsArr.items) {
|
|
269
746
|
const annotDict = doc.cos.resolveDict(item);
|
|
270
747
|
if (!annotDict) continue;
|
|
271
|
-
const subNode = doc.cos.resolve(
|
|
748
|
+
const subNode = doc.cos.resolve(dictGet2(annotDict, "Subtype"));
|
|
272
749
|
const subtype = subNode?.kind === "name" ? subNode.decoded : "Annot";
|
|
273
|
-
const rectArr = doc.cos.resolveArray(
|
|
750
|
+
const rectArr = doc.cos.resolveArray(dictGet2(annotDict, "Rect"));
|
|
274
751
|
const rectNums = rectArr ? rectArr.items.map((it) => {
|
|
275
752
|
const r = doc.cos.resolve(it);
|
|
276
753
|
return r?.kind === "number" ? r.value : 0;
|
|
277
754
|
}) : [0, 0, 0, 0];
|
|
278
|
-
const flagsNode = doc.cos.resolve(
|
|
755
|
+
const flagsNode = doc.cos.resolve(dictGet2(annotDict, "F"));
|
|
279
756
|
const flags = flagsNode?.kind === "number" ? flagsNode.value : 0;
|
|
280
757
|
lines.push("---");
|
|
281
758
|
lines.push(`AnnotSubtype: ${subtype}`);
|
|
282
759
|
lines.push(`AnnotRect: ${rectNums.slice(0, 4).join(" ")}`);
|
|
283
|
-
const nmNode = doc.cos.resolve(
|
|
760
|
+
const nmNode = doc.cos.resolve(dictGet2(annotDict, "NM"));
|
|
284
761
|
if (nmNode?.kind === "string") {
|
|
285
|
-
lines.push(`AnnotName: ${encodePdftkText(
|
|
762
|
+
lines.push(`AnnotName: ${encodePdftkText(decodePdfString2(nmNode), utf8)}`);
|
|
286
763
|
}
|
|
287
|
-
const tNode = doc.cos.resolve(
|
|
764
|
+
const tNode = doc.cos.resolve(dictGet2(annotDict, "T"));
|
|
288
765
|
if (tNode?.kind === "string") {
|
|
289
|
-
lines.push(`AnnotTitle: ${encodePdftkText(
|
|
766
|
+
lines.push(`AnnotTitle: ${encodePdftkText(decodePdfString2(tNode), utf8)}`);
|
|
290
767
|
}
|
|
291
|
-
const subjNode = doc.cos.resolve(
|
|
768
|
+
const subjNode = doc.cos.resolve(dictGet2(annotDict, "Subj"));
|
|
292
769
|
if (subjNode?.kind === "string") {
|
|
293
|
-
lines.push(`AnnotSubj: ${encodePdftkText(
|
|
770
|
+
lines.push(`AnnotSubj: ${encodePdftkText(decodePdfString2(subjNode), utf8)}`);
|
|
294
771
|
}
|
|
295
|
-
const cNode = doc.cos.resolve(
|
|
772
|
+
const cNode = doc.cos.resolve(dictGet2(annotDict, "Contents"));
|
|
296
773
|
if (cNode?.kind === "string") {
|
|
297
|
-
lines.push(`AnnotContents: ${encodePdftkText(
|
|
774
|
+
lines.push(`AnnotContents: ${encodePdftkText(decodePdfString2(cNode), utf8)}`);
|
|
298
775
|
}
|
|
299
|
-
const colArr = doc.cos.resolveArray(
|
|
776
|
+
const colArr = doc.cos.resolveArray(dictGet2(annotDict, "C"));
|
|
300
777
|
if (colArr && colArr.items.length >= 3) {
|
|
301
778
|
const colNums = colArr.items.slice(0, 3).map((it) => {
|
|
302
779
|
const r = doc.cos.resolve(it);
|
|
@@ -304,20 +781,20 @@ function formatDumpDataAnnots(doc, utf8 = false) {
|
|
|
304
781
|
});
|
|
305
782
|
lines.push(`AnnotColor: ${colNums.join(" ")}`);
|
|
306
783
|
}
|
|
307
|
-
const openNode = doc.cos.resolve(
|
|
784
|
+
const openNode = doc.cos.resolve(dictGet2(annotDict, "Open"));
|
|
308
785
|
if (openNode?.kind === "boolean") {
|
|
309
786
|
lines.push(`AnnotOpen: ${openNode.value}`);
|
|
310
787
|
}
|
|
311
|
-
const mNode = doc.cos.resolve(
|
|
788
|
+
const mNode = doc.cos.resolve(dictGet2(annotDict, "M"));
|
|
312
789
|
if (mNode?.kind === "string") {
|
|
313
|
-
lines.push(`AnnotModificationDate: ${encodePdftkText(
|
|
790
|
+
lines.push(`AnnotModificationDate: ${encodePdftkText(decodePdfString2(mNode), utf8)}`);
|
|
314
791
|
}
|
|
315
792
|
lines.push(`AnnotFlags: ${flags}`);
|
|
316
793
|
lines.push(`AnnotPageNumber: ${p + 1}`);
|
|
317
794
|
const formatDestTarget = (dRaw) => {
|
|
318
795
|
if (!dRaw) return void 0;
|
|
319
796
|
const resolved = doc.cos.resolve(dRaw);
|
|
320
|
-
if (resolved?.kind === "string") return
|
|
797
|
+
if (resolved?.kind === "string") return decodePdfString2(resolved);
|
|
321
798
|
if (resolved?.kind === "name") return resolved.decoded;
|
|
322
799
|
if (resolved?.kind === "array" && resolved.items.length > 0) {
|
|
323
800
|
const first = resolved.items[0];
|
|
@@ -350,16 +827,16 @@ function formatDumpDataAnnots(doc, utf8 = false) {
|
|
|
350
827
|
}
|
|
351
828
|
const actionDict = doc.cos.resolveDict(aNode);
|
|
352
829
|
if (!actionDict) return;
|
|
353
|
-
const sNode = doc.cos.resolve(
|
|
830
|
+
const sNode = doc.cos.resolve(dictGet2(actionDict, "S"));
|
|
354
831
|
const sType = sNode?.kind === "name" ? sNode.decoded : "";
|
|
355
832
|
if (sType) {
|
|
356
833
|
lines.push(`AnnotActionType: ${sType}`);
|
|
357
834
|
}
|
|
358
|
-
const uriNode = doc.cos.resolve(
|
|
835
|
+
const uriNode = doc.cos.resolve(dictGet2(actionDict, "URI"));
|
|
359
836
|
if (uriNode?.kind === "string") {
|
|
360
|
-
lines.push(`AnnotActionURI: ${encodePdftkText(
|
|
837
|
+
lines.push(`AnnotActionURI: ${encodePdftkText(decodePdfString2(uriNode), utf8)}`);
|
|
361
838
|
}
|
|
362
|
-
const dNode =
|
|
839
|
+
const dNode = dictGet2(actionDict, "D");
|
|
363
840
|
const destTarget = formatDestTarget(dNode);
|
|
364
841
|
if (destTarget) {
|
|
365
842
|
lines.push(`AnnotActionDest: ${encodePdftkText(destTarget, utf8)}`);
|
|
@@ -368,23 +845,23 @@ function formatDumpDataAnnots(doc, utf8 = false) {
|
|
|
368
845
|
if (resolvedIdx !== void 0) {
|
|
369
846
|
lines.push(`AnnotActionPageNumber: ${resolvedIdx + 1}`);
|
|
370
847
|
}
|
|
371
|
-
const fRaw = doc.cos.resolve(
|
|
848
|
+
const fRaw = doc.cos.resolve(dictGet2(actionDict, "F"));
|
|
372
849
|
if (fRaw?.kind === "string") {
|
|
373
|
-
lines.push(`AnnotActionFile: ${encodePdftkText(
|
|
850
|
+
lines.push(`AnnotActionFile: ${encodePdftkText(decodePdfString2(fRaw), utf8)}`);
|
|
374
851
|
} else if (fRaw?.kind === "dict") {
|
|
375
|
-
const ufNode = doc.cos.resolve(
|
|
852
|
+
const ufNode = doc.cos.resolve(dictGet2(fRaw, "UF") ?? dictGet2(fRaw, "F"));
|
|
376
853
|
if (ufNode?.kind === "string") {
|
|
377
|
-
lines.push(`AnnotActionFile: ${encodePdftkText(
|
|
854
|
+
lines.push(`AnnotActionFile: ${encodePdftkText(decodePdfString2(ufNode), utf8)}`);
|
|
378
855
|
}
|
|
379
856
|
}
|
|
380
|
-
emitActionChain(
|
|
857
|
+
emitActionChain(dictGet2(actionDict, "Next"), visited);
|
|
381
858
|
};
|
|
382
|
-
const rawA =
|
|
859
|
+
const rawA = dictGet2(annotDict, "A");
|
|
383
860
|
if (rawA) {
|
|
384
861
|
emitActionChain(rawA);
|
|
385
|
-
} else if (
|
|
862
|
+
} else if (dictGet2(annotDict, "Dest")) {
|
|
386
863
|
lines.push("AnnotActionType: GoTo");
|
|
387
|
-
const dNode =
|
|
864
|
+
const dNode = dictGet2(annotDict, "Dest");
|
|
388
865
|
const destTarget = formatDestTarget(dNode);
|
|
389
866
|
if (destTarget) {
|
|
390
867
|
lines.push(`AnnotActionDest: ${encodePdftkText(destTarget, utf8)}`);
|
|
@@ -430,18 +907,18 @@ function collectOutlineBookmarks(doc, firstNode, level, out, visited = /* @__PUR
|
|
|
430
907
|
}
|
|
431
908
|
const dict = doc.cos.resolveDict(curr);
|
|
432
909
|
if (!dict) break;
|
|
433
|
-
const titleNode = doc.cos.resolve(
|
|
434
|
-
const title = titleNode?.kind === "string" ?
|
|
435
|
-
const resolvedIdx = resolveDestinationPageIndex(doc,
|
|
910
|
+
const titleNode = doc.cos.resolve(dictGet2(dict, "Title"));
|
|
911
|
+
const title = titleNode?.kind === "string" ? decodePdfString2(titleNode) : titleNode?.kind === "name" ? titleNode.decoded : "";
|
|
912
|
+
const resolvedIdx = resolveDestinationPageIndex(doc, dictGet2(dict, "Dest") ?? dictGet2(dict, "A"));
|
|
436
913
|
const pageNumber = resolvedIdx !== void 0 ? resolvedIdx + 1 : 1;
|
|
437
914
|
if (title) {
|
|
438
915
|
out.push({ title, level, pageNumber });
|
|
439
916
|
}
|
|
440
|
-
const childFirst =
|
|
917
|
+
const childFirst = dictGet2(dict, "First");
|
|
441
918
|
if (childFirst) {
|
|
442
919
|
collectOutlineBookmarks(doc, childFirst, level + 1, out, visited);
|
|
443
920
|
}
|
|
444
|
-
curr =
|
|
921
|
+
curr = dictGet2(dict, "Next");
|
|
445
922
|
}
|
|
446
923
|
}
|
|
447
924
|
function collectNameTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ new Set()) {
|
|
@@ -452,16 +929,16 @@ function collectNameTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ new
|
|
|
452
929
|
}
|
|
453
930
|
const dict = doc.cos.resolveDict(nodeOrRef);
|
|
454
931
|
if (!dict) return;
|
|
455
|
-
const namesArr = doc.cos.resolveArray(
|
|
932
|
+
const namesArr = doc.cos.resolveArray(dictGet2(dict, "Names"));
|
|
456
933
|
if (namesArr) {
|
|
457
934
|
for (let i = 0; i + 1 < namesArr.items.length; i += 2) {
|
|
458
935
|
const k = doc.cos.resolve(namesArr.items[i]);
|
|
459
936
|
const v = namesArr.items[i + 1];
|
|
460
|
-
const name = k?.kind === "string" ?
|
|
937
|
+
const name = k?.kind === "string" ? decodePdfString2(k) : "attachment.bin";
|
|
461
938
|
out.push({ name, value: v });
|
|
462
939
|
}
|
|
463
940
|
}
|
|
464
|
-
const kidsArr = doc.cos.resolveArray(
|
|
941
|
+
const kidsArr = doc.cos.resolveArray(dictGet2(dict, "Kids"));
|
|
465
942
|
if (kidsArr) {
|
|
466
943
|
for (const kid of kidsArr.items) {
|
|
467
944
|
collectNameTreePairs(doc, kid, out, visited);
|
|
@@ -476,7 +953,7 @@ function collectNumberTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ n
|
|
|
476
953
|
}
|
|
477
954
|
const dict = doc.cos.resolveDict(nodeOrRef);
|
|
478
955
|
if (!dict) return;
|
|
479
|
-
const numsArr = doc.cos.resolveArray(
|
|
956
|
+
const numsArr = doc.cos.resolveArray(dictGet2(dict, "Nums"));
|
|
480
957
|
if (numsArr) {
|
|
481
958
|
for (let i = 0; i + 1 < numsArr.items.length; i += 2) {
|
|
482
959
|
const k = doc.cos.resolve(numsArr.items[i]);
|
|
@@ -486,7 +963,7 @@ function collectNumberTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ n
|
|
|
486
963
|
}
|
|
487
964
|
}
|
|
488
965
|
}
|
|
489
|
-
const kidsArr = doc.cos.resolveArray(
|
|
966
|
+
const kidsArr = doc.cos.resolveArray(dictGet2(dict, "Kids"));
|
|
490
967
|
if (kidsArr) {
|
|
491
968
|
for (const kid of kidsArr.items) {
|
|
492
969
|
collectNumberTreePairs(doc, kid, out, visited);
|
|
@@ -540,7 +1017,7 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
540
1017
|
if (emittedKeys.has(k)) continue;
|
|
541
1018
|
const r = doc.cos.resolve(entry.value);
|
|
542
1019
|
if (r?.kind === "string") {
|
|
543
|
-
const val =
|
|
1020
|
+
const val = decodePdfString2(r);
|
|
544
1021
|
if (val) {
|
|
545
1022
|
emittedKeys.add(k);
|
|
546
1023
|
lines.push(
|
|
@@ -561,10 +1038,10 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
561
1038
|
lines.push(`PdfID1: ${id1Hex}`);
|
|
562
1039
|
lines.push(`NumberOfPages: ${doc.pageCount}`);
|
|
563
1040
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
564
|
-
const outlinesDict = catalog ? doc.cos.resolveDict(
|
|
1041
|
+
const outlinesDict = catalog ? doc.cos.resolveDict(dictGet2(catalog, "Outlines")) : void 0;
|
|
565
1042
|
if (outlinesDict) {
|
|
566
1043
|
const bookmarks = [];
|
|
567
|
-
collectOutlineBookmarks(doc,
|
|
1044
|
+
collectOutlineBookmarks(doc, dictGet2(outlinesDict, "First"), 1, bookmarks);
|
|
568
1045
|
for (const bm of bookmarks) {
|
|
569
1046
|
lines.push(
|
|
570
1047
|
"BookmarkBegin",
|
|
@@ -578,7 +1055,7 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
578
1055
|
const page = doc.getPage(i);
|
|
579
1056
|
const { width, height } = page.getSize();
|
|
580
1057
|
const rot = page.getRotation();
|
|
581
|
-
const mbArr = doc.cos.resolveArray(
|
|
1058
|
+
const mbArr = doc.cos.resolveArray(dictGet2(page.pageDict, "MediaBox"));
|
|
582
1059
|
let mbRectStr = `0 0 ${width} ${height}`;
|
|
583
1060
|
if (mbArr && mbArr.items.length >= 4) {
|
|
584
1061
|
const mbNums = mbArr.items.slice(0, 4).map((item) => {
|
|
@@ -594,7 +1071,7 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
594
1071
|
`PageMediaRect: ${mbRectStr}`,
|
|
595
1072
|
`PageMediaDimensions: ${width} ${height}`
|
|
596
1073
|
);
|
|
597
|
-
const cbArr = doc.cos.resolveArray(
|
|
1074
|
+
const cbArr = doc.cos.resolveArray(dictGet2(page.pageDict, "CropBox"));
|
|
598
1075
|
if (cbArr && cbArr.items.length >= 4) {
|
|
599
1076
|
const nums = cbArr.items.slice(0, 4).map((item) => {
|
|
600
1077
|
const r = doc.cos.resolve(item);
|
|
@@ -606,17 +1083,17 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
606
1083
|
}
|
|
607
1084
|
const pageLabelsPairs = [];
|
|
608
1085
|
if (catalog) {
|
|
609
|
-
collectNumberTreePairs(doc,
|
|
1086
|
+
collectNumberTreePairs(doc, dictGet2(catalog, "PageLabels"), pageLabelsPairs);
|
|
610
1087
|
}
|
|
611
1088
|
for (const pair of pageLabelsPairs) {
|
|
612
1089
|
const lblDict = doc.cos.resolveDict(pair.value);
|
|
613
1090
|
if (lblDict) {
|
|
614
1091
|
const newIndex = Math.max(1, pair.num + 1);
|
|
615
|
-
const stNode = doc.cos.resolve(
|
|
1092
|
+
const stNode = doc.cos.resolve(dictGet2(lblDict, "St"));
|
|
616
1093
|
const startNum = stNode?.kind === "number" ? stNode.value : 1;
|
|
617
|
-
const pNode = doc.cos.resolve(
|
|
618
|
-
const prefix = pNode?.kind === "string" ?
|
|
619
|
-
const sNode = doc.cos.resolve(
|
|
1094
|
+
const pNode = doc.cos.resolve(dictGet2(lblDict, "P"));
|
|
1095
|
+
const prefix = pNode?.kind === "string" ? decodePdfString2(pNode) : void 0;
|
|
1096
|
+
const sNode = doc.cos.resolve(dictGet2(lblDict, "S"));
|
|
620
1097
|
const styleCode = sNode?.kind === "name" ? sNode.decoded : "";
|
|
621
1098
|
const numStyle = PDF_TO_PAGE_LABEL_STYLE[styleCode] ?? "NoNumber";
|
|
622
1099
|
lines.push(
|
|
@@ -647,23 +1124,23 @@ function formatGenerateFdf(doc) {
|
|
|
647
1124
|
}
|
|
648
1125
|
return `(${escapeFdfString(String(f.value ?? ""))})`;
|
|
649
1126
|
}
|
|
650
|
-
const vNode = doc.cos.resolve(
|
|
1127
|
+
const vNode = doc.cos.resolve(dictGet2(dict, "V"));
|
|
651
1128
|
if (vNode?.kind === "name") return `/${vNode.decoded}`;
|
|
652
|
-
if (vNode?.kind === "string") return `(${escapeFdfString(
|
|
1129
|
+
if (vNode?.kind === "string") return `(${escapeFdfString(decodePdfString2(vNode))})`;
|
|
653
1130
|
return "()";
|
|
654
1131
|
};
|
|
655
1132
|
const serializeCosFieldNode = (nodeOrRef, prefix) => {
|
|
656
1133
|
const dict = doc.cos.resolveDict(nodeOrRef);
|
|
657
1134
|
if (!dict) return void 0;
|
|
658
|
-
const tNode = doc.cos.resolve(
|
|
659
|
-
const partialName = tNode?.kind === "string" ?
|
|
1135
|
+
const tNode = doc.cos.resolve(dictGet2(dict, "T"));
|
|
1136
|
+
const partialName = tNode?.kind === "string" ? decodePdfString2(tNode) : "";
|
|
660
1137
|
const fullName = prefix && partialName ? `${prefix}.${partialName}` : partialName || prefix;
|
|
661
|
-
const kidsArr = doc.cos.resolveArray(
|
|
1138
|
+
const kidsArr = doc.cos.resolveArray(dictGet2(dict, "Kids"));
|
|
662
1139
|
const namedKids = [];
|
|
663
1140
|
if (kidsArr) {
|
|
664
1141
|
for (const k of kidsArr.items) {
|
|
665
1142
|
const kDict = doc.cos.resolveDict(k);
|
|
666
|
-
if (kDict &&
|
|
1143
|
+
if (kDict && dictGet2(kDict, "T")) {
|
|
667
1144
|
const serializedKid = serializeCosFieldNode(k, fullName);
|
|
668
1145
|
if (serializedKid) namedKids.push(serializedKid);
|
|
669
1146
|
}
|
|
@@ -677,8 +1154,8 @@ function formatGenerateFdf(doc) {
|
|
|
677
1154
|
};
|
|
678
1155
|
const entries = [];
|
|
679
1156
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
680
|
-
const acroForm = catalog ? doc.cos.resolveDict(
|
|
681
|
-
const fieldsArr = acroForm ? doc.cos.resolveArray(
|
|
1157
|
+
const acroForm = catalog ? doc.cos.resolveDict(dictGet2(catalog, "AcroForm")) : void 0;
|
|
1158
|
+
const fieldsArr = acroForm ? doc.cos.resolveArray(dictGet2(acroForm, "Fields")) : void 0;
|
|
682
1159
|
if (fieldsArr && fieldsArr.items.length > 0) {
|
|
683
1160
|
for (const item of fieldsArr.items) {
|
|
684
1161
|
const s = serializeCosFieldNode(item, "");
|
|
@@ -939,17 +1416,17 @@ function applyUpdateInfoText(doc, text) {
|
|
|
939
1416
|
function attachFilesToDocument(doc, filePaths, files, toPageSpec) {
|
|
940
1417
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
941
1418
|
if (!catalog) return;
|
|
942
|
-
let namesDict = doc.cos.resolveDict(
|
|
1419
|
+
let namesDict = doc.cos.resolveDict(dictGet2(catalog, "Names"));
|
|
943
1420
|
if (!namesDict) {
|
|
944
1421
|
namesDict = cosDict({});
|
|
945
1422
|
dictSet(catalog, "Names", doc.cos.allocateObject(namesDict));
|
|
946
1423
|
}
|
|
947
|
-
let efTree = doc.cos.resolveDict(
|
|
1424
|
+
let efTree = doc.cos.resolveDict(dictGet2(namesDict, "EmbeddedFiles"));
|
|
948
1425
|
if (!efTree) {
|
|
949
1426
|
efTree = cosDict({ Names: cosArray([]) });
|
|
950
1427
|
dictSet(namesDict, "EmbeddedFiles", doc.cos.allocateObject(efTree));
|
|
951
1428
|
}
|
|
952
|
-
let namesArr = doc.cos.resolveArray(
|
|
1429
|
+
let namesArr = doc.cos.resolveArray(dictGet2(efTree, "Names"));
|
|
953
1430
|
if (!namesArr) {
|
|
954
1431
|
namesArr = cosArray([]);
|
|
955
1432
|
dictSet(efTree, "Names", namesArr);
|
|
@@ -976,7 +1453,7 @@ function attachFilesToDocument(doc, filePaths, files, toPageSpec) {
|
|
|
976
1453
|
namesArr.items.push(cosString(baseName), filespecRef);
|
|
977
1454
|
if (targetPageIdx !== void 0) {
|
|
978
1455
|
const pageDict = doc.getPage(targetPageIdx).pageDict;
|
|
979
|
-
let annotsArr = doc.cos.resolveArray(
|
|
1456
|
+
let annotsArr = doc.cos.resolveArray(dictGet2(pageDict, "Annots"));
|
|
980
1457
|
if (!annotsArr) {
|
|
981
1458
|
annotsArr = cosArray([]);
|
|
982
1459
|
dictSet(pageDict, "Annots", annotsArr);
|
|
@@ -1005,11 +1482,11 @@ function attachmentBasename(name) {
|
|
|
1005
1482
|
function unpackFilesFromDocument(doc, outDir, files) {
|
|
1006
1483
|
const cleanDir = outDir.endsWith("/") ? outDir.slice(0, -1) : outDir;
|
|
1007
1484
|
const writeSpecDict = (specDict, fallbackName = "attachment.bin") => {
|
|
1008
|
-
const ufNode = doc.cos.resolve(
|
|
1009
|
-
const fileName = attachmentBasename(ufNode?.kind === "string" ?
|
|
1010
|
-
const efDict = doc.cos.resolveDict(
|
|
1485
|
+
const ufNode = doc.cos.resolve(dictGet2(specDict, "UF") ?? dictGet2(specDict, "F"));
|
|
1486
|
+
const fileName = attachmentBasename(ufNode?.kind === "string" ? decodePdfString2(ufNode) : fallbackName);
|
|
1487
|
+
const efDict = doc.cos.resolveDict(dictGet2(specDict, "EF"));
|
|
1011
1488
|
const fStream = efDict ? doc.cos.resolve(
|
|
1012
|
-
|
|
1489
|
+
dictGet2(efDict, "UF") ?? dictGet2(efDict, "F") ?? dictGet2(efDict, "DOS") ?? dictGet2(efDict, "Mac") ?? dictGet2(efDict, "Unix")
|
|
1013
1490
|
) : void 0;
|
|
1014
1491
|
if (fStream?.kind === "stream") {
|
|
1015
1492
|
const decoded = doc.cos.decodeStream(fStream);
|
|
@@ -1019,10 +1496,10 @@ function unpackFilesFromDocument(doc, outDir, files) {
|
|
|
1019
1496
|
};
|
|
1020
1497
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
1021
1498
|
if (catalog) {
|
|
1022
|
-
const namesDict = doc.cos.resolveDict(
|
|
1499
|
+
const namesDict = doc.cos.resolveDict(dictGet2(catalog, "Names"));
|
|
1023
1500
|
const efPairs = [];
|
|
1024
1501
|
if (namesDict) {
|
|
1025
|
-
collectNameTreePairs(doc,
|
|
1502
|
+
collectNameTreePairs(doc, dictGet2(namesDict, "EmbeddedFiles"), efPairs);
|
|
1026
1503
|
}
|
|
1027
1504
|
for (const pair of efPairs) {
|
|
1028
1505
|
const specDict = doc.cos.resolveDict(pair.value);
|
|
@@ -1030,7 +1507,7 @@ function unpackFilesFromDocument(doc, outDir, files) {
|
|
|
1030
1507
|
writeSpecDict(specDict, pair.name);
|
|
1031
1508
|
}
|
|
1032
1509
|
}
|
|
1033
|
-
const rootAfArr = doc.cos.resolveArray(
|
|
1510
|
+
const rootAfArr = doc.cos.resolveArray(dictGet2(catalog, "AF"));
|
|
1034
1511
|
if (rootAfArr) {
|
|
1035
1512
|
for (const item of rootAfArr.items) {
|
|
1036
1513
|
const specDict = doc.cos.resolveDict(item);
|
|
@@ -1039,21 +1516,21 @@ function unpackFilesFromDocument(doc, outDir, files) {
|
|
|
1039
1516
|
}
|
|
1040
1517
|
}
|
|
1041
1518
|
for (let p = 0; p < doc.pageCount; p++) {
|
|
1042
|
-
const pageAfArr = doc.cos.resolveArray(
|
|
1519
|
+
const pageAfArr = doc.cos.resolveArray(dictGet2(doc.getPage(p).pageDict, "AF"));
|
|
1043
1520
|
if (pageAfArr) {
|
|
1044
1521
|
for (const item of pageAfArr.items) {
|
|
1045
1522
|
const specDict = doc.cos.resolveDict(item);
|
|
1046
1523
|
if (specDict) writeSpecDict(specDict);
|
|
1047
1524
|
}
|
|
1048
1525
|
}
|
|
1049
|
-
const annotsArr = doc.cos.resolveArray(
|
|
1526
|
+
const annotsArr = doc.cos.resolveArray(dictGet2(doc.getPage(p).pageDict, "Annots"));
|
|
1050
1527
|
if (!annotsArr) continue;
|
|
1051
1528
|
for (const item of annotsArr.items) {
|
|
1052
1529
|
const annotDict = doc.cos.resolveDict(item);
|
|
1053
1530
|
if (!annotDict) continue;
|
|
1054
|
-
const subNode = doc.cos.resolve(
|
|
1531
|
+
const subNode = doc.cos.resolve(dictGet2(annotDict, "Subtype"));
|
|
1055
1532
|
if (subNode?.kind === "name" && subNode.decoded === "FileAttachment") {
|
|
1056
|
-
const specDict = doc.cos.resolveDict(
|
|
1533
|
+
const specDict = doc.cos.resolveDict(dictGet2(annotDict, "FS"));
|
|
1057
1534
|
if (specDict) writeSpecDict(specDict);
|
|
1058
1535
|
}
|
|
1059
1536
|
}
|
|
@@ -1187,9 +1664,9 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
|
|
|
1187
1664
|
const srcRes = srcPage.getResourcesDict();
|
|
1188
1665
|
const renamedResources = /* @__PURE__ */ new Map();
|
|
1189
1666
|
for (const subKey of ["Font", "XObject", "ExtGState", "ColorSpace", "Pattern", "Shading", "Properties"]) {
|
|
1190
|
-
const srcSub = overlayDoc.cos.resolveDict(
|
|
1667
|
+
const srcSub = overlayDoc.cos.resolveDict(dictGet2(srcRes, subKey));
|
|
1191
1668
|
if (!srcSub) continue;
|
|
1192
|
-
let dstSub = targetDoc.cos.resolveDict(
|
|
1669
|
+
let dstSub = targetDoc.cos.resolveDict(dictGet2(dstRes, subKey));
|
|
1193
1670
|
if (!dstSub) {
|
|
1194
1671
|
dstSub = cosDict({});
|
|
1195
1672
|
dictSet(dstRes, subKey, dstSub);
|
|
@@ -1198,12 +1675,12 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
|
|
|
1198
1675
|
const origKey = entry.key.decoded;
|
|
1199
1676
|
const cloned = cloneCosSubgraphInto(overlayDoc, targetDoc, entry.value, memo);
|
|
1200
1677
|
if (!cloned) continue;
|
|
1201
|
-
if (!
|
|
1678
|
+
if (!dictGet2(dstSub, origKey)) {
|
|
1202
1679
|
dictSet(dstSub, origKey, cloned);
|
|
1203
1680
|
} else {
|
|
1204
1681
|
let newKey = `Ov_${i}_${origKey}`;
|
|
1205
1682
|
let suffix = 1;
|
|
1206
|
-
while (
|
|
1683
|
+
while (dictGet2(dstSub, newKey)) {
|
|
1207
1684
|
newKey = `Ov_${i}_${suffix++}_${origKey}`;
|
|
1208
1685
|
}
|
|
1209
1686
|
dictSet(dstSub, newKey, cloned);
|
|
@@ -1211,7 +1688,7 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
|
|
|
1211
1688
|
}
|
|
1212
1689
|
}
|
|
1213
1690
|
}
|
|
1214
|
-
const srcContents =
|
|
1691
|
+
const srcContents = dictGet2(srcPage.pageDict, "Contents");
|
|
1215
1692
|
if (!srcContents) continue;
|
|
1216
1693
|
const rawSrcNodes = [];
|
|
1217
1694
|
const resolvedSrcContents = overlayDoc.cos.resolve(srcContents);
|
|
@@ -1237,7 +1714,7 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
|
|
|
1237
1714
|
}
|
|
1238
1715
|
}
|
|
1239
1716
|
if (srcList.length === 0) continue;
|
|
1240
|
-
const dstContents =
|
|
1717
|
+
const dstContents = dictGet2(dstPage.pageDict, "Contents");
|
|
1241
1718
|
const toStreamList = (c) => {
|
|
1242
1719
|
if (!c) return [];
|
|
1243
1720
|
const r = targetDoc.cos.resolve(c);
|
|
@@ -1296,159 +1773,29 @@ function normalizeQuarterTurn(degrees) {
|
|
|
1296
1773
|
}
|
|
1297
1774
|
function* runPdftkCliSteps(argv, files, signal) {
|
|
1298
1775
|
let cooperativeWork = 63;
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
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
|
-
}
|
|
1776
|
+
const parsed = yield* parsePdftkArgumentsSteps(argv);
|
|
1777
|
+
if (parsed.result) return parsed.result;
|
|
1778
|
+
const { inputs, operation, opArgs, outputTarget, shouldFlatten, needAppearances, dropXfa, dropXmp, replacementFont, keepFirstId, keepFinalId, uncompressStreams, compressStreams, userPassword, ownerPassword, allowPermissions } = parsed.options;
|
|
1329
1779
|
const handles = /* @__PURE__ */ new Map();
|
|
1330
1780
|
const orderedDocs = [];
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
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}'
|
|
1781
|
+
for (const input of inputs) {
|
|
1782
|
+
signal?.throwIfAborted();
|
|
1783
|
+
if (++cooperativeWork % 64 === 0) yield;
|
|
1784
|
+
const pdfBytes = files.get(input.file);
|
|
1785
|
+
if (!pdfBytes) return { exitCode: 1, stdout: "", stderr: `Error: Unable to find file '${input.file}'
|
|
1352
1786
|
` };
|
|
1353
|
-
}
|
|
1354
|
-
const pw = inputPasswords.get(handleName) ?? defaultInputPassword;
|
|
1355
1787
|
let doc;
|
|
1356
1788
|
try {
|
|
1357
|
-
doc = PdfDocument.load(pdfBytes,
|
|
1358
|
-
} catch (
|
|
1359
|
-
return { exitCode: 1, stdout: "", stderr: `Error: Failed to open PDF '${
|
|
1789
|
+
doc = PdfDocument.load(pdfBytes, input.password ? { password: input.password } : void 0);
|
|
1790
|
+
} catch (error) {
|
|
1791
|
+
return { exitCode: 1, stdout: "", stderr: `Error: Failed to open PDF '${input.file}': ${error.message}
|
|
1360
1792
|
` };
|
|
1361
1793
|
}
|
|
1362
|
-
handles.set(
|
|
1363
|
-
if (!handles.has(""))
|
|
1364
|
-
|
|
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
|
-
}
|
|
1794
|
+
handles.set(input.handle, doc);
|
|
1795
|
+
if (!handles.has("")) handles.set("", doc);
|
|
1796
|
+
orderedDocs.push({ handle: input.handle, doc });
|
|
1451
1797
|
}
|
|
1798
|
+
const primaryDoc = orderedDocs[0].doc, primaryHandle = orderedDocs[0].handle;
|
|
1452
1799
|
if (operation === "dump_data_fields" || operation === "dump_data_fields_utf8") {
|
|
1453
1800
|
const text = formatDumpDataFields(primaryDoc, operation === "dump_data_fields_utf8");
|
|
1454
1801
|
if (outputTarget && outputTarget !== "-") {
|
|
@@ -1600,9 +1947,9 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
1600
1947
|
if (!cached) {
|
|
1601
1948
|
cached = [];
|
|
1602
1949
|
const cat = d.cos.resolveDict(d.cos.rootRef);
|
|
1603
|
-
const outDict = cat ? d.cos.resolveDict(
|
|
1950
|
+
const outDict = cat ? d.cos.resolveDict(dictGet2(cat, "Outlines")) : void 0;
|
|
1604
1951
|
if (outDict) {
|
|
1605
|
-
collectOutlineBookmarks(d,
|
|
1952
|
+
collectOutlineBookmarks(d, dictGet2(outDict, "First"), 1, cached);
|
|
1606
1953
|
}
|
|
1607
1954
|
bookmarksByDoc.set(d, cached);
|
|
1608
1955
|
}
|
|
@@ -1692,7 +2039,7 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
1692
2039
|
}
|
|
1693
2040
|
if (dropXfa) {
|
|
1694
2041
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
1695
|
-
const acroForm = root ? resultDoc.cos.resolveDict(
|
|
2042
|
+
const acroForm = root ? resultDoc.cos.resolveDict(dictGet2(root, "AcroForm")) : void 0;
|
|
1696
2043
|
if (acroForm)
|
|
1697
2044
|
dictDelete(acroForm, "XFA");
|
|
1698
2045
|
}
|
|
@@ -1707,8 +2054,8 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
1707
2054
|
if (++cooperativeWork % 64 === 0)
|
|
1708
2055
|
yield;
|
|
1709
2056
|
if (obj.value.kind === "dict") {
|
|
1710
|
-
const stNode =
|
|
1711
|
-
const bfNode =
|
|
2057
|
+
const stNode = dictGet2(obj.value, "Subtype");
|
|
2058
|
+
const bfNode = dictGet2(obj.value, "BaseFont");
|
|
1712
2059
|
const subtype = stNode?.kind === "name" ? stNode.decoded : void 0;
|
|
1713
2060
|
const baseFont = bfNode?.kind === "name" ? bfNode.decoded : void 0;
|
|
1714
2061
|
if (subtype === "Type1" && baseFont === "Helvetica") {
|
|
@@ -1719,14 +2066,14 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
1719
2066
|
}
|
|
1720
2067
|
if (operation === "fill_form" && !shouldFlatten) {
|
|
1721
2068
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
1722
|
-
const acroForm = root ? resultDoc.cos.resolveDict(
|
|
2069
|
+
const acroForm = root ? resultDoc.cos.resolveDict(dictGet2(root, "AcroForm")) : void 0;
|
|
1723
2070
|
if (acroForm) {
|
|
1724
2071
|
dictSet(acroForm, "NeedAppearances", { kind: "boolean", value: needAppearances });
|
|
1725
2072
|
}
|
|
1726
2073
|
} else if (needAppearances && !shouldFlatten) {
|
|
1727
2074
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
1728
2075
|
if (root) {
|
|
1729
|
-
const acroForm = resultDoc.cos.resolveDict(
|
|
2076
|
+
const acroForm = resultDoc.cos.resolveDict(dictGet2(root, "AcroForm"));
|
|
1730
2077
|
if (acroForm) {
|
|
1731
2078
|
dictSet(acroForm, "NeedAppearances", { kind: "boolean", value: true });
|
|
1732
2079
|
}
|
|
@@ -1807,6 +2154,10 @@ async function executePdftk(context) {
|
|
|
1807
2154
|
try {
|
|
1808
2155
|
const carrier = getCommandArguments(context);
|
|
1809
2156
|
const argv = [...carrier.args];
|
|
2157
|
+
const parsed = await drainSteps(parsePdftkArgumentsSteps(argv), invocation.signal);
|
|
2158
|
+
if (parsed.options && ["dump_data_annots", "dump_data_annots_utf8"].includes(parsed.options.operation)) {
|
|
2159
|
+
return await executeRetainedPdftk({ ...context, signal: invocation.signal, stdout: invocation.child(context.stdout).output }, parsed.options);
|
|
2160
|
+
}
|
|
1810
2161
|
const vfsFiles = /* @__PURE__ */ new Map();
|
|
1811
2162
|
let accountedBytes = 0;
|
|
1812
2163
|
const chargeBytes = (delta) => {
|
|
@@ -1859,7 +2210,7 @@ async function executePdftk(context) {
|
|
|
1859
2210
|
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
1860
2211
|
if (filePath === "-") continue;
|
|
1861
2212
|
try {
|
|
1862
|
-
const bytes = await context.fs.readFile(
|
|
2213
|
+
const bytes = await context.fs.readFile(resolvePath2(context.cwd, filePath), { signal: invocation.signal });
|
|
1863
2214
|
chargeBytes(bytes.byteLength);
|
|
1864
2215
|
vfsFiles.set(filePath, bytes);
|
|
1865
2216
|
} catch {
|
|
@@ -1869,26 +2220,26 @@ async function executePdftk(context) {
|
|
|
1869
2220
|
const existingSnap = new Map(vfsFiles);
|
|
1870
2221
|
const res = await runPdftkCli(argv, vfsFiles, invocation.signal);
|
|
1871
2222
|
if (res.stderr) {
|
|
1872
|
-
await
|
|
2223
|
+
await writeBytes2(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
|
|
1873
2224
|
}
|
|
1874
2225
|
if (res.stdoutBytes) {
|
|
1875
2226
|
const stdout = invocation.child(context.stdout);
|
|
1876
|
-
await
|
|
2227
|
+
await writeBytes2(stdout.output, res.stdoutBytes, invocation.signal);
|
|
1877
2228
|
} else if (res.stdout) {
|
|
1878
2229
|
const outBytes = new TextEncoder().encode(res.stdout);
|
|
1879
2230
|
const stdout = invocation.child(context.stdout);
|
|
1880
|
-
await
|
|
2231
|
+
await writeBytes2(stdout.output, outBytes, invocation.signal);
|
|
1881
2232
|
}
|
|
1882
2233
|
for (const [key, val] of vfsFiles.entries()) {
|
|
1883
2234
|
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
1884
2235
|
if (key !== "-" && existingSnap.get(key) !== val) {
|
|
1885
|
-
const abs =
|
|
2236
|
+
const abs = resolvePath2(context.cwd, key);
|
|
1886
2237
|
try {
|
|
1887
|
-
await
|
|
2238
|
+
await writeFileOutput2(context, val, (data) => context.fs.writeFile(abs, data, { signal: invocation.signal }));
|
|
1888
2239
|
} catch (error) {
|
|
1889
2240
|
invocation.signal.throwIfAborted();
|
|
1890
2241
|
if (!(error instanceof Error) || !("code" in error)) throw error;
|
|
1891
|
-
await
|
|
2242
|
+
await writeBytes2(context.stderr, new TextEncoder().encode(`Error: Failed to open output file '${key}': ${error.code}.
|
|
1892
2243
|
`), invocation.signal);
|
|
1893
2244
|
return { exitCode: 1 };
|
|
1894
2245
|
}
|