@poe-platform/safe-bash 0.1.812 → 0.1.813
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/id3-source.d.ts +27 -0
- package/dist/audio-ast/index.d.ts +4 -0
- package/dist/audio-ast/index.js +996 -596
- package/dist/audio-ast/mp3-source.d.ts +18 -0
- package/dist/audio-ast/ogg-source.d.ts +25 -0
- package/dist/audio-ast/ogg-stream-source.d.ts +22 -0
- package/dist/image-ast/index.js +139 -9
- package/dist/mp4-ast/containers/adapters.d.ts +7 -0
- package/dist/office-xml/retained-xml-document.d.ts +8 -0
- package/dist/pdf-ast/ast.d.ts +2 -0
- package/dist/pdf-ast/content/dictionary-cursor.d.ts +15 -0
- package/dist/pdf-ast/content/range-operator-parser.d.ts +4 -0
- package/dist/pdf-ast/content/stored-dictionary.d.ts +10 -0
- package/dist/pdf-ast/cos/lexer.d.ts +8 -5
- package/dist/pdf-ast/cos/object-reader.d.ts +4 -3
- package/dist/pdf-ast/cos/range-parser.d.ts +4 -0
- package/dist/pdf-ast/cos/retained-objects.d.ts +1 -0
- package/dist/pdf-ast/cos/retained-writer.d.ts +1 -0
- package/dist/pdf-ast/cos/value-parser.d.ts +9 -0
- package/dist/pdf-ast/edit/retained-append-attachments.d.ts +13 -0
- package/dist/pdf-ast/edit/retained-bookmarks.d.ts +13 -0
- package/dist/pdf-ast/edit/retained-graph.d.ts +6 -0
- package/dist/pdf-ast/edit/retained-save.d.ts +2 -0
- package/dist/pdf-ast/edit/retained-stamps.d.ts +9 -0
- package/dist/pdf-ast/fonts/resolve.d.ts +3 -1
- package/dist/pdf-ast/index.d.ts +3 -1
- package/dist/pdf-ast/index.js +1557 -770
- package/dist/safe-bash/audio-ast.browser.js +6 -1
- package/dist/safe-bash/chunks/{chunk-HHSOUC3Z.js → chunk-HPQE675Q.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-BUYRKFW2.js → chunk-I6ECNJMR.js} +1 -1
- package/dist/safe-bash/chunks/{pdftk-WRYEP3CA.js → pdftk-Y2TX74LY.js} +2 -1
- package/dist/safe-bash/command-chunks/biff-4ALVARRF-7SRX6R6N.js +5192 -0
- package/dist/safe-bash/command-chunks/{chunk-EHSM5ZQS.js → chunk-2DGJOOXM.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-Q6S57NOQ.js → chunk-2E2H7MBH.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-MMBZTYXO.js → chunk-2PQRZDNR.js} +221 -0
- package/dist/safe-bash/command-chunks/{chunk-NARD63DY.js → chunk-2V6FOLXV.js} +22 -66
- package/dist/safe-bash/command-chunks/{chunk-56NYSX65.js → chunk-2Z3WRRFT.js} +9 -9
- package/dist/safe-bash/command-chunks/chunk-3D24WDND.js +63 -0
- package/dist/safe-bash/command-chunks/{chunk-47NEG4UO.js → chunk-3JST2Q7G.js} +219 -43
- package/dist/safe-bash/command-chunks/{chunk-WGG6G2KG.js → chunk-3LJAXFH5.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-AHA6IWAJ.js → chunk-3TYDSGAH.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-YSMNXMAO.js → chunk-3Y4XZB24.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-ZIIO6GRY.js → chunk-4PBNMKAT.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-JFYWVQ4V.js → chunk-4Z6W5EOC.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-GEM47B2P.js → chunk-57DDYKE5.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-4CKFNXRN.js → chunk-5IFRAI7Y.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-RHYJVTJO.js → chunk-5KGEZ3RW.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-A5FZBR7X.js → chunk-5MFDRSGG.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-7GKKMNL6.js → chunk-5P6I2T63.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-6M6TM5Z5.js → chunk-5VQVZPP3.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-MIRL7HTF.js → chunk-6244HYJY.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-63EMPQ7Z.js +115 -0
- package/dist/safe-bash/command-chunks/{chunk-XRVKWGVQ.js → chunk-6CY5BHBS.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-XVP6V5K3.js → chunk-6IWE7PTK.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-6QBMND4A.js → chunk-6SRHWVEB.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-6ZHQB453.js +35 -0
- package/dist/safe-bash/command-chunks/chunk-73NYFNAS.js +173 -0
- package/dist/safe-bash/command-chunks/{chunk-2JSDKQ4J.js → chunk-7NXTEWPR.js} +119 -44
- package/dist/safe-bash/command-chunks/{chunk-554Z6IKP.js → chunk-7PRL6RJ6.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-SDTPO2VV.js → chunk-7PZHWMK6.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-XZ2FWFNV.js → chunk-7QZ2HP2F.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-OEJM666F.js → chunk-7UC2Q6Z6.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-COKYZUBW.js → chunk-AJI55RS7.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WXRYDALR.js → chunk-BBAB7LC4.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-QYMEASQ6.js → chunk-BEHUSUOY.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-Z2JW6M2D.js → chunk-BK7ISUJL.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-33YCKZZX.js → chunk-C5KLFZGT.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-TVH4JORU.js → chunk-C5QDEB3I.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-N4R2SHSS.js → chunk-CCZZVCHX.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-2VLAXKTS.js → chunk-CTDC4LJT.js} +121 -85
- package/dist/safe-bash/command-chunks/{chunk-S6R3IB36.js → chunk-D55REQA3.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-Y4EYCZFT.js → chunk-D6WJY6QO.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-2CORNDGF.js → chunk-DBLHCJJU.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-SPW4GW4Z.js → chunk-DFI7QF3M.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-456PHA3L.js → chunk-DMCI6T6N.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-TW73OXPR.js → chunk-EJTNVXWF.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-QD7ZRDUN.js → chunk-ET2VPDUA.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-CJQSAATC.js → chunk-EXOQGXEU.js} +26 -26
- package/dist/safe-bash/command-chunks/{chunk-CRV2Q3PB.js → chunk-EZ4NQIPL.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-FWKLBDMK.js +0 -0
- package/dist/safe-bash/command-chunks/{chunk-22MOB45U.js → chunk-FWPVQGYK.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-QC5RMGSA.js → chunk-G3RUXKVY.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-JYUJAF4L.js → chunk-G7NENPYV.js} +4 -0
- package/dist/safe-bash/command-chunks/{chunk-KCOJA7EM.js → chunk-GKILM4HZ.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-HTVIYLVB.js → chunk-GNXTMSYN.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-D2ASPM7R.js → chunk-GOBUDKZ3.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-RNSKXOG3.js → chunk-GVWVRPG6.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-FDCIPJBQ.js → chunk-HCKYUQ3L.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-AGLK7OJR.js → chunk-HDSIIQBS.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DM2CPMB4.js → chunk-HKOMXGJS.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-IT7TAC3F.js → chunk-HVW53ARH.js} +16 -16
- package/dist/safe-bash/command-chunks/{chunk-M7QE2MN7.js → chunk-I4GMCWAT.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-HWQ2UHMT.js → chunk-IHSOOSNC.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-LCZDBW55.js → chunk-JAHJWVGF.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-MOZD7RUY.js → chunk-JORIVUPM.js} +27 -11
- package/dist/safe-bash/command-chunks/{chunk-PMAM4N33.js → chunk-JUJHYPYL.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-ENT3IV2G.js → chunk-KBUBSMCQ.js} +12 -12
- package/dist/safe-bash/command-chunks/{chunk-ZXR6LXV5.js → chunk-KCE5D4Z4.js} +48 -4
- package/dist/safe-bash/command-chunks/{chunk-FIIAYCWS.js → chunk-KZ5ODST6.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-PNGDJA6M.js → chunk-LD7BONZY.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-KJ4XXZIL.js → chunk-M3Z5PU2M.js} +582 -59
- package/dist/safe-bash/command-chunks/{chunk-LXLLA4PM.js → chunk-MKX4JAZ6.js} +17 -17
- package/dist/safe-bash/command-chunks/{chunk-RQIQ75W5.js → chunk-MNHBQBF6.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-A2CLZMQZ.js → chunk-MPKY37QR.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-K5GB2YMN.js → chunk-MUUWBZIC.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-JOCFI7TG.js → chunk-N32GSM3J.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-EUT24Y5Z.js → chunk-NKTULXVD.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-5HPU7D36.js → chunk-NMPED6L5.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-QZZ73J2O.js → chunk-NPFHUS4X.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-X7FA7ZD5.js → chunk-O675URF4.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-R6EGGK5M.js → chunk-P7EL2FWW.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-YS25EI54.js → chunk-PCCFLPUQ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-RRL3Y562.js → chunk-PI6MOMHA.js} +11 -11
- package/dist/safe-bash/command-chunks/{chunk-26VCZHLJ.js → chunk-PIOQBOEK.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-PK36TVXB.js +175 -0
- package/dist/safe-bash/command-chunks/{chunk-3Q247UDJ.js → chunk-PKLJRB7W.js} +264 -129
- package/dist/safe-bash/command-chunks/{chunk-6CCQI6XZ.js → chunk-PSCOXGCA.js} +12 -12
- package/dist/safe-bash/command-chunks/{chunk-XPD636C4.js → chunk-PVGZMLC6.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-JQVHUSDD.js → chunk-PXWS3Q7L.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-HDJVJTCK.js → chunk-QFF5KBOM.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-MPUHH2KR.js → chunk-QM2HZJSJ.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-UAXSE3XE.js → chunk-R2BMZAHG.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-KB7DUBVL.js → chunk-RGOQKIG6.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-D2KZ66W4.js → chunk-RLCQ7BN3.js} +187 -39
- package/dist/safe-bash/command-chunks/{chunk-B5LDP7AA.js → chunk-S2N2V5U4.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-OA75SGN2.js → chunk-SGPCXAG7.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-QUM3SYAJ.js → chunk-SYSX46IV.js} +3 -3
- package/dist/safe-bash/command-chunks/chunk-T3E5RV3U.js +737 -0
- package/dist/safe-bash/command-chunks/{chunk-YORJDX4V.js → chunk-T5ERNELL.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-ZEX53S5I.js → chunk-T6C5QP7T.js} +6368 -6230
- package/dist/safe-bash/command-chunks/{chunk-ATTWQVR2.js → chunk-TKRLZIFI.js} +17 -17
- package/dist/safe-bash/command-chunks/{chunk-ZMHEGDU2.js → chunk-TODWFDYB.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-XVLWZTPY.js → chunk-TQEB4DH4.js} +543 -144
- package/dist/safe-bash/command-chunks/{chunk-36XGIPOG.js → chunk-U5TWQFZY.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-APEWTWCC.js → chunk-UAF4IX5H.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-6VPQ3CDZ.js → chunk-V37D6AHO.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-RID6VYS3.js → chunk-V6XBEYPC.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-WJCN2IXI.js → chunk-VQOINPVF.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-W5YSINXC.js → chunk-VVWXY6IA.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-HKATEVAP.js → chunk-WPVBUVFK.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-UYWSIIUX.js → chunk-X53AEG36.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-L5MCW6CM.js → chunk-X64XGIXZ.js} +9 -155
- package/dist/safe-bash/command-chunks/{chunk-Q73EMLLZ.js → chunk-X6RHJ6YN.js} +84 -5
- package/dist/safe-bash/command-chunks/{chunk-7PVHO47B.js → chunk-XG6UWQV5.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-NQDIT667.js → chunk-XIDGHIGB.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-CV7M2QJU.js → chunk-XLYIVBAR.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-WVMHRNXZ.js → chunk-YUXTK3XA.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-SPLOIABU.js → chunk-YXD6VGVG.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-2ZFLMWOX.js → chunk-Z5BIM5B7.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-ZYLGNIGA.js +156 -0
- package/dist/safe-bash/command-chunks/{command-engine-BCUQGJJ4.js → command-engine-X3OLN7N6.js} +150 -67
- package/dist/safe-bash/command-chunks/{engine-LAUEWYSQ-DQCEI5HE.js → engine-XUCIFZ7V-LJFGZM6O.js} +1 -1
- package/dist/safe-bash/command-chunks/paradox-4FCZE53D-LQPGVMEL.js +365 -0
- package/dist/safe-bash/commands/pandoc/index.browser.js +1 -1
- package/dist/safe-bash/full-core.browser.js +2 -2
- package/dist/safe-bash/plugins/index.browser.js +2 -2
- package/dist/safe-bash-command-diff/diff.js +1 -1
- package/dist/safe-bash-command-diff/index.js +1 -1
- 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.d.ts +3 -1
- package/dist/safe-bash-command-ffprobe/media.js +2 -2
- package/dist/safe-bash-command-html-to-markdown/budget.js +2 -1
- package/dist/safe-bash-command-html-to-markdown/entities.js +4 -3
- package/dist/safe-bash-command-html-to-markdown/index.js +564 -110
- package/dist/safe-bash-command-html-to-markdown/input.js +6 -5
- package/dist/safe-bash-command-html-to-markdown/options.js +2 -1
- package/dist/safe-bash-command-html-to-markdown/parser.js +5 -4
- package/dist/safe-bash-command-html-to-markdown/render.js +6 -5
- package/dist/safe-bash-command-html-to-markdown/text.js +3 -2
- package/dist/safe-bash-command-htmlq/index.js +361 -37
- package/dist/safe-bash-command-htmlq/tree.d.ts +3 -2
- package/dist/safe-bash-command-pandoc/command.js +7 -7
- package/dist/safe-bash-command-pandoc/index.js +55 -55
- package/dist/safe-bash-command-patch/index.js +6 -6
- package/dist/safe-bash-command-patch/patch-envelope.js +53 -3
- package/dist/safe-bash-command-patch/patch-formats.d.ts +2 -2
- package/dist/safe-bash-command-patch/patch-formats.js +2 -2
- package/dist/safe-bash-command-patch/patch-gnu-reject.d.ts +2 -1
- package/dist/safe-bash-command-patch/patch-gnu-reject.js +4 -3
- package/dist/safe-bash-command-patch/patch-publication.js +2 -1
- package/dist/safe-bash-command-patch/patch.js +6 -6
- package/dist/safe-bash-command-patch/unified.d.ts +10 -2
- package/dist/safe-bash-command-patch/unified.js +1 -1
- package/dist/safe-bash-command-pdftk/index.d.ts +6 -2
- package/dist/safe-bash-command-pdftk/index.js +830 -271
- package/dist/safe-bash-command-pptx/command-engine.d.ts +3 -0
- package/dist/safe-bash-command-pptx/engine.js +1 -1
- package/dist/safe-bash-command-pptx/index.js +9 -2
- 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-xmllint/index.js +22 -31
- package/dist/safe-bash-presentation-engine/accessibility.js +31 -30
- package/dist/safe-bash-presentation-engine/animation-editing.js +16 -15
- package/dist/safe-bash-presentation-engine/animations.js +16 -15
- package/dist/safe-bash-presentation-engine/backgrounds.js +17 -16
- package/dist/safe-bash-presentation-engine/bytes.js +3 -3
- package/dist/safe-bash-presentation-engine/chart-editing.js +34 -33
- package/dist/safe-bash-presentation-engine/chart-object-operations.js +25 -24
- package/dist/safe-bash-presentation-engine/charts.js +31 -30
- package/dist/safe-bash-presentation-engine/command-placeholder.js +59 -56
- package/dist/safe-bash-presentation-engine/comments.js +17 -16
- package/dist/safe-bash-presentation-engine/connector-operations.js +32 -31
- package/dist/safe-bash-presentation-engine/connectors.js +29 -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 +32 -31
- package/dist/safe-bash-presentation-engine/drawing-enums.d.ts +10 -10
- package/dist/safe-bash-presentation-engine/drawing-format.js +20 -19
- package/dist/safe-bash-presentation-engine/drawing-operations.js +31 -30
- package/dist/safe-bash-presentation-engine/drawing-schema.js +21 -20
- package/dist/safe-bash-presentation-engine/equations.js +17 -16
- package/dist/safe-bash-presentation-engine/errors.js +2 -2
- package/dist/safe-bash-presentation-engine/fields.js +17 -16
- package/dist/safe-bash-presentation-engine/font-metrics.js +3 -3
- package/dist/safe-bash-presentation-engine/image-extraction.js +20 -19
- package/dist/safe-bash-presentation-engine/image-formatting.js +32 -31
- package/dist/safe-bash-presentation-engine/image-insertion.js +18 -17
- package/dist/safe-bash-presentation-engine/image-replacement.js +21 -20
- package/dist/safe-bash-presentation-engine/image-value.js +4 -4
- package/dist/safe-bash-presentation-engine/images.js +19 -18
- package/dist/safe-bash-presentation-engine/index.d.ts +5 -1
- package/dist/safe-bash-presentation-engine/index.js +109 -96
- package/dist/safe-bash-presentation-engine/layouts.js +16 -15
- package/dist/safe-bash-presentation-engine/length.js +3 -3
- package/dist/safe-bash-presentation-engine/links.js +16 -15
- package/dist/safe-bash-presentation-engine/masters.js +15 -14
- package/dist/safe-bash-presentation-engine/media-editing.js +24 -23
- package/dist/safe-bash-presentation-engine/media-extraction.js +17 -16
- package/dist/safe-bash-presentation-engine/media.js +16 -15
- package/dist/safe-bash-presentation-engine/memberships.js +15 -14
- package/dist/safe-bash-presentation-engine/notes.js +16 -15
- package/dist/safe-bash-presentation-engine/ole-enum.js +4 -4
- package/dist/safe-bash-presentation-engine/ole-insertion.js +20 -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.d.ts +3 -0
- package/dist/safe-bash-presentation-engine/package-tools.js +27 -17
- 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 +58 -55
- package/dist/safe-bash-presentation-engine/presentation-settings.js +14 -13
- package/dist/safe-bash-presentation-engine/properties.js +16 -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-archive-staging.d.ts +19 -0
- package/dist/safe-bash-presentation-engine/retained-extraction-output.d.ts +18 -0
- package/dist/safe-bash-presentation-engine/retained-inspection.js +14 -12
- package/dist/safe-bash-presentation-engine/retained-package-extraction.d.ts +22 -0
- package/dist/safe-bash-presentation-engine/retained-package-packing.d.ts +19 -0
- package/dist/safe-bash-presentation-engine/retained-package.d.ts +2 -0
- package/dist/safe-bash-presentation-engine/retained-package.js +6 -4
- package/dist/safe-bash-presentation-engine/retained-text.js +19 -17
- package/dist/safe-bash-presentation-engine/retained-xml-parts.d.ts +5 -1
- package/dist/safe-bash-presentation-engine/retained-xml-publication.d.ts +18 -0
- package/dist/safe-bash-presentation-engine/retained-xml-replacement.d.ts +13 -0
- package/dist/safe-bash-presentation-engine/sanitize.js +17 -16
- package/dist/safe-bash-presentation-engine/selectors.js +10 -10
- package/dist/safe-bash-presentation-engine/shape-groups.js +31 -30
- package/dist/safe-bash-presentation-engine/shape-operations.js +30 -29
- package/dist/safe-bash-presentation-engine/shape-path-operations.js +32 -31
- package/dist/safe-bash-presentation-engine/shape-paths.js +16 -15
- package/dist/safe-bash-presentation-engine/shape-presets.js +3 -3
- package/dist/safe-bash-presentation-engine/shape-selection.js +31 -30
- package/dist/safe-bash-presentation-engine/shape-transforms.js +18 -17
- package/dist/safe-bash-presentation-engine/shapes.d.ts +1 -1
- package/dist/safe-bash-presentation-engine/shapes.js +27 -26
- package/dist/safe-bash-presentation-engine/slide-copy.js +17 -16
- package/dist/safe-bash-presentation-engine/slide-import.js +18 -17
- package/dist/safe-bash-presentation-engine/slide-merge-split.js +20 -19
- package/dist/safe-bash-presentation-engine/slide-model.js +43 -42
- package/dist/safe-bash-presentation-engine/slide-removal.js +18 -17
- package/dist/safe-bash-presentation-engine/slide-transfer-budget.js +9 -9
- package/dist/safe-bash-presentation-engine/slides.js +19 -16
- package/dist/safe-bash-presentation-engine/table-operations.js +33 -32
- package/dist/safe-bash-presentation-engine/table-spans.js +32 -31
- package/dist/safe-bash-presentation-engine/tables.js +31 -30
- package/dist/safe-bash-presentation-engine/tags.js +16 -15
- package/dist/safe-bash-presentation-engine/template-bindings.js +33 -32
- package/dist/safe-bash-presentation-engine/template-repeat.js +40 -39
- package/dist/safe-bash-presentation-engine/text-fitting.js +27 -26
- package/dist/safe-bash-presentation-engine/text-frames.js +27 -26
- package/dist/safe-bash-presentation-engine/text-paragraphs.js +27 -26
- package/dist/safe-bash-presentation-engine/text-reading.js +11 -11
- package/dist/safe-bash-presentation-engine/text-replacement.js +17 -16
- package/dist/safe-bash-presentation-engine/text-runs.js +20 -19
- package/dist/safe-bash-presentation-engine/themes.js +16 -15
- package/dist/safe-bash-presentation-engine/transitions.js +16 -15
- package/dist/safe-bash-presentation-engine/validation.js +10 -9
- package/dist/safe-bash-presentation-engine/xml-parts.d.ts +2 -0
- package/dist/safe-bash-presentation-engine/xml-parts.js +23 -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-regex-engine/index.js +1 -1
- package/dist/safe-bash-regex-engine/python-glob.js +1 -1
- package/dist/safe-bash-regex-engine/text/regex.d.ts +19 -0
- package/dist/safe-bash-regex-engine/text/regex.js +1 -1
- package/dist/safe-bash-xml-engine/document.js +3 -3
- package/dist/safe-bash-xml-engine/evaluate.js +1 -1
- package/dist/safe-bash-xml-engine/index.d.ts +1 -0
- package/dist/safe-bash-xml-engine/index.js +8 -4
- package/dist/safe-bash-xml-engine/query.js +2 -2
- package/dist/safe-bash-xml-engine/recovery.d.ts +10 -0
- package/dist/safe-bash-xml-engine/stored-document.d.ts +1 -1
- package/dist/safe-bash-xml-engine/stored-document.js +1 -1
- package/dist/safe-bash-xml-engine/stored-evaluate.js +1 -1
- package/dist/spreadsheet-engine/formulas/functions/python-printf.js +56 -33
- package/dist/spreadsheet-format-xls/biff-encrypted-properties.d.ts +1 -1
- package/dist/spreadsheet-format-xls/biff-encrypted-properties.js +47 -18
- package/dist/spreadsheet-format-xls/biff-properties-merge.d.ts +6 -2
- package/dist/spreadsheet-format-xls/biff-properties-merge.js +413 -296
- package/dist/spreadsheet-format-xls/biff-properties-write.js +40 -23
- package/dist/spreadsheet-format-xls/biff-properties.js +3 -68
- package/dist/spreadsheet-format-xls/biff-property-index.d.ts +23 -0
- package/dist/spreadsheet-format-xls/biff-property-index.js +93 -0
- package/dist/spreadsheet-format-xls/biff-property-name.d.ts +4 -0
- package/dist/spreadsheet-format-xls/biff-property-name.js +114 -0
- package/dist/spreadsheet-format-xls/biff-property-text.d.ts +6 -0
- package/dist/spreadsheet-format-xls/biff-property-text.js +68 -0
- package/dist/spreadsheet-format-xls/biff-property-transcode.d.ts +5 -0
- package/dist/spreadsheet-format-xls/biff-property-transcode.js +45 -0
- package/package.json +6 -3
- package/dist/safe-bash/command-chunks/biff-YKPDH35C-MVQIWNKV.js +0 -4974
- package/dist/safe-bash/command-chunks/chunk-5Q22ZLNC.js +0 -127
- package/dist/safe-bash/command-chunks/chunk-JKLOBSMP.js +0 -56
- package/dist/safe-bash/command-chunks/chunk-JYTESTBS.js +0 -99
- package/dist/safe-bash/command-chunks/chunk-ZEGNRZV2.js +0 -333
- package/dist/safe-bash/command-chunks/paradox-ZWWXYY4J-JYOSWSBL.js +0 -362
- package/dist/spreadsheet-format-xls/biff-properties-layout.js +0 -56
|
@@ -1,49 +1,51 @@
|
|
|
1
1
|
import "../safe-bash/command-chunks/chunk-65DS4IOB.js";
|
|
2
2
|
|
|
3
|
-
// packages/safe-bash-command-pdftk/src/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
// packages/safe-bash-command-pdftk/src/burst-filename.ts
|
|
4
|
+
function formatBurstFilename(pattern, pageNum) {
|
|
5
|
+
let out = "";
|
|
6
|
+
let replaced = false;
|
|
7
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
8
|
+
if (pattern[i] !== "%") {
|
|
9
|
+
out += pattern[i];
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (pattern[i + 1] === "%") {
|
|
13
|
+
out += "%";
|
|
14
|
+
i++;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (!replaced) {
|
|
18
|
+
let j = i + 1;
|
|
19
|
+
let zeroPad = false;
|
|
20
|
+
if (pattern[j] === "0") {
|
|
21
|
+
zeroPad = true;
|
|
22
|
+
j++;
|
|
23
|
+
}
|
|
24
|
+
let widthStr = "";
|
|
25
|
+
while (j < pattern.length && pattern[j] >= "0" && pattern[j] <= "9") {
|
|
26
|
+
widthStr += pattern[j];
|
|
27
|
+
j++;
|
|
28
|
+
}
|
|
29
|
+
if (pattern[j] === "d") {
|
|
30
|
+
const width = widthStr ? Number.parseInt(widthStr, 10) : 1;
|
|
31
|
+
out += zeroPad ? String(pageNum).padStart(width, "0") : String(pageNum);
|
|
32
|
+
replaced = true;
|
|
33
|
+
i = j;
|
|
34
|
+
continue;
|
|
17
35
|
}
|
|
18
36
|
}
|
|
19
|
-
|
|
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);
|
|
37
|
+
out += "%";
|
|
33
38
|
}
|
|
39
|
+
return out;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
|
-
// packages/safe-bash-command-pdftk/src/retained.ts
|
|
37
|
-
import {
|
|
38
|
-
import { FsError } from "../safe-bash-contracts/errors.js";
|
|
39
|
-
import { writeBytes } from "../safe-bash-contracts/io.js";
|
|
40
|
-
import { resolvePath } from "../safe-bash-contracts/path.js";
|
|
41
|
-
import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
|
|
42
|
+
// packages/safe-bash-command-pdftk/src/retained-burst.ts
|
|
43
|
+
import { createRetainedPageCopy, saveRetainedDocumentChunks } from "../pdf-ast/index.js";
|
|
42
44
|
|
|
43
|
-
// packages/safe-bash-command-pdftk/src/retained-
|
|
45
|
+
// packages/safe-bash-command-pdftk/src/retained-inspection.ts
|
|
44
46
|
import { IntegerTable, PagedStorage } from "@poe-platform/safe-fs/storage";
|
|
45
|
-
import { PdfMutableObjectStore, decodePdfString, dictGet } from "../pdf-ast/index.js";
|
|
46
|
-
async function*
|
|
47
|
+
import { PdfMutableObjectStore, PdfNameIndex, cosArray, cosNumber, decodePdfString, dictGet } from "../pdf-ast/index.js";
|
|
48
|
+
async function* retainedInspectionReport(document, storage, utf8, signal, kind) {
|
|
47
49
|
const backing = new PagedStorage({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), pages = new IntegerTable(backing, 64);
|
|
48
50
|
let pageCount = 0, work = 0, failed = false;
|
|
49
51
|
const encoder = new TextEncoder();
|
|
@@ -74,26 +76,34 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
74
76
|
if (!start) return;
|
|
75
77
|
const stack = new PdfMutableObjectStore(storage, { signal }), seen = new IntegerTable(backing, 64);
|
|
76
78
|
let pending = 0, failed2 = false;
|
|
77
|
-
const push = async (value) => {
|
|
79
|
+
const push = async (value, level = 1) => {
|
|
78
80
|
await checkpoint();
|
|
79
|
-
await stack.set({ objectNumber: ++pending, generationNumber: 0, value });
|
|
81
|
+
await stack.set({ objectNumber: ++pending, generationNumber: 0, value: cosArray([value, cosNumber(level)]) });
|
|
80
82
|
};
|
|
81
83
|
try {
|
|
82
84
|
await push(start);
|
|
83
85
|
while (pending) {
|
|
84
86
|
await checkpoint();
|
|
85
|
-
const
|
|
87
|
+
const frame = (await stack.get(pending--)).value;
|
|
88
|
+
if (frame.kind !== "array") continue;
|
|
89
|
+
const raw = frame.items[0], levelNode = frame.items[1], level = levelNode.kind === "number" ? levelNode.value : 1;
|
|
86
90
|
if (raw.kind === "ref") {
|
|
87
91
|
if (await seen.get(BigInt(raw.objectNumber))) continue;
|
|
88
92
|
await seen.set(BigInt(raw.objectNumber), 1n);
|
|
89
93
|
}
|
|
90
94
|
const value = await resolve(raw);
|
|
91
95
|
if (value?.kind === "array" && key === "Next") {
|
|
92
|
-
for (let i = value.items.length - 1; i >= 0; i--) await push(value.items[i]);
|
|
96
|
+
for (let i = value.items.length - 1; i >= 0; i--) await push(value.items[i], level);
|
|
93
97
|
continue;
|
|
94
98
|
}
|
|
95
99
|
if (value?.kind !== "dict") continue;
|
|
96
|
-
yield value;
|
|
100
|
+
yield { dict: value, level };
|
|
101
|
+
if (key === "Outlines") {
|
|
102
|
+
const next = dictGet(value, "Next"), first = dictGet(value, "First");
|
|
103
|
+
if (next) await push(next, level);
|
|
104
|
+
if (first) await push(first, level + 1);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
97
107
|
const child = dictGet(value, key);
|
|
98
108
|
if (key === "Next") {
|
|
99
109
|
if (child) await push(child);
|
|
@@ -126,7 +136,7 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
126
136
|
if (legacy?.kind === "dict") target = dictGet(legacy, name);
|
|
127
137
|
if (!target) {
|
|
128
138
|
const names = await resolve(dictGet(root, "Names"));
|
|
129
|
-
if (names?.kind === "dict") for await (const branch of walk(dictGet(names, "Dests"), "Kids")) {
|
|
139
|
+
if (names?.kind === "dict") for await (const { dict: branch } of walk(dictGet(names, "Dests"), "Kids")) {
|
|
130
140
|
const pairs = await resolve(dictGet(branch, "Names"));
|
|
131
141
|
if (pairs?.kind === "array") for (let i = 0; i + 1 < pairs.items.length; i += 2) {
|
|
132
142
|
const key = await resolve(pairs.items[i]);
|
|
@@ -180,6 +190,40 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
180
190
|
pageCount++;
|
|
181
191
|
if (page.reference && !await pages.get(BigInt(page.reference.objectNumber))) await pages.set(BigInt(page.reference.objectNumber), BigInt(page.index + 1));
|
|
182
192
|
}
|
|
193
|
+
if (kind === "document") {
|
|
194
|
+
const emitted = new PdfNameIndex(storage, Infinity, signal);
|
|
195
|
+
let failed2 = false;
|
|
196
|
+
try {
|
|
197
|
+
const info = await resolve(document.crossReference.infoRef);
|
|
198
|
+
if (info?.kind === "dict") {
|
|
199
|
+
for (const key of ["Title", "Author", "Subject", "Keywords", "Creator", "Producer"]) {
|
|
200
|
+
const node = await resolve(dictGet(info, key));
|
|
201
|
+
const value = node?.kind === "string" ? decodePdfString(node) : node?.kind === "name" ? node.decoded : "";
|
|
202
|
+
if (value) {
|
|
203
|
+
await emitted.intern(key);
|
|
204
|
+
yield* line("", "InfoBegin");
|
|
205
|
+
yield* line("InfoKey: ", key, true);
|
|
206
|
+
yield* line("InfoValue: ", value, true);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
for (const entry of info.entries) {
|
|
210
|
+
const node = await resolve(entry.value), value = node?.kind === "string" ? decodePdfString(node) : "";
|
|
211
|
+
if (value && (await emitted.intern(entry.key.decoded)).added) {
|
|
212
|
+
yield* line("", "InfoBegin");
|
|
213
|
+
yield* line("InfoKey: ", entry.key.decoded, true);
|
|
214
|
+
yield* line("InfoValue: ", value, true);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
} catch (error) {
|
|
219
|
+
failed2 = true;
|
|
220
|
+
throw error;
|
|
221
|
+
} finally {
|
|
222
|
+
await emitted.close().catch((error) => {
|
|
223
|
+
if (!failed2) throw error;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
183
227
|
for (let i = 0; i < 2; i++) {
|
|
184
228
|
const id = await resolve(document.crossReference.idArray?.items[i]);
|
|
185
229
|
if (id?.kind !== "string") yield* line(`PdfID${i}: `, "00000000000000000000000000000000");
|
|
@@ -195,6 +239,75 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
195
239
|
}
|
|
196
240
|
}
|
|
197
241
|
yield* line("NumberOfPages: ", pageCount);
|
|
242
|
+
if (kind === "document") {
|
|
243
|
+
const catalog = await resolve(document.crossReference.rootRef);
|
|
244
|
+
const outlines = catalog?.kind === "dict" ? await resolve(dictGet(catalog, "Outlines")) : void 0;
|
|
245
|
+
if (outlines?.kind === "dict") for await (const { dict, level } of walk(dictGet(outlines, "First"), "Outlines")) {
|
|
246
|
+
const titleNode = await resolve(dictGet(dict, "Title"));
|
|
247
|
+
const title = titleNode?.kind === "string" ? decodePdfString(titleNode) : titleNode?.kind === "name" ? titleNode.decoded : "";
|
|
248
|
+
const index = await destinationIndex(dictGet(dict, "Dest") ?? dictGet(dict, "A"));
|
|
249
|
+
if (title) {
|
|
250
|
+
yield* line("", "BookmarkBegin");
|
|
251
|
+
yield* line("BookmarkTitle: ", title, true);
|
|
252
|
+
yield* line("BookmarkLevel: ", level);
|
|
253
|
+
yield* line("BookmarkPageNumber: ", index === void 0 ? 1 : index + 1);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async function rectangle(raw, strict) {
|
|
257
|
+
const node = await resolve(raw);
|
|
258
|
+
if (node?.kind !== "array" || node.items.length < 4) return;
|
|
259
|
+
const result = [];
|
|
260
|
+
for (const item of node.items.slice(0, 4)) {
|
|
261
|
+
const number = await resolve(item);
|
|
262
|
+
if (strict && number?.kind !== "number") return;
|
|
263
|
+
result.push(number?.kind === "number" ? number.value : 0);
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
for await (const page of document.pages()) {
|
|
268
|
+
let media, rotate, hasMedia = false, hasRotate = false;
|
|
269
|
+
for await (const parent of document.pageAncestors(page.dict)) {
|
|
270
|
+
if (!hasMedia && dictGet(parent, "MediaBox")) {
|
|
271
|
+
hasMedia = true;
|
|
272
|
+
media = dictGet(parent, "MediaBox");
|
|
273
|
+
}
|
|
274
|
+
if (!hasRotate && dictGet(parent, "Rotate")) {
|
|
275
|
+
hasRotate = true;
|
|
276
|
+
rotate = dictGet(parent, "Rotate");
|
|
277
|
+
}
|
|
278
|
+
if (hasMedia && hasRotate) break;
|
|
279
|
+
}
|
|
280
|
+
const box = await rectangle(media, true) ?? [0, 0, 612, 792], width = Math.abs(box[2] - box[0]), height = Math.abs(box[3] - box[1]);
|
|
281
|
+
const rotation = await resolve(rotate), norm = rotation?.kind === "number" ? (rotation.value % 360 + 360) % 360 : 0;
|
|
282
|
+
const direct = await rectangle(dictGet(page.dict, "MediaBox"), false) ?? [0, 0, width, height];
|
|
283
|
+
yield* line("", "PageMediaBegin");
|
|
284
|
+
yield* line("PageMediaNumber: ", page.index + 1);
|
|
285
|
+
yield* line("PageMediaRotation: ", norm === 90 || norm === 180 || norm === 270 ? norm : 0);
|
|
286
|
+
yield* line("PageMediaRect: ", direct.join(" "));
|
|
287
|
+
yield* line("PageMediaDimensions: ", `${width} ${height}`);
|
|
288
|
+
const crop = await rectangle(dictGet(page.dict, "CropBox"), false);
|
|
289
|
+
if (crop) {
|
|
290
|
+
yield* line("PageMediaCropBox: ", crop.join(" "));
|
|
291
|
+
yield* line("PageMediaCropRect: ", crop.join(" "));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const styles = { D: "DecimalArabicNumerals", R: "UppercaseRomanNumerals", r: "LowercaseRomanNumerals", A: "UppercaseLetters", a: "LowercaseLetters" };
|
|
295
|
+
if (catalog?.kind === "dict") for await (const { dict } of walk(dictGet(catalog, "PageLabels"), "Kids")) {
|
|
296
|
+
const pairs = await resolve(dictGet(dict, "Nums"));
|
|
297
|
+
if (pairs?.kind !== "array") continue;
|
|
298
|
+
for (let i = 0; i + 1 < pairs.items.length; i += 2) {
|
|
299
|
+
const number = await resolve(pairs.items[i]), label = await resolve(pairs.items[i + 1]);
|
|
300
|
+
if (number?.kind !== "number" || label?.kind !== "dict") continue;
|
|
301
|
+
const start = await resolve(dictGet(label, "St")), prefix = await resolve(dictGet(label, "P")), style = await resolve(dictGet(label, "S"));
|
|
302
|
+
yield* line("", "PageLabelBegin");
|
|
303
|
+
yield* line("PageLabelNewIndex: ", Math.max(1, number.value + 1));
|
|
304
|
+
yield* line("PageLabelStart: ", start?.kind === "number" ? start.value : 1);
|
|
305
|
+
if (prefix?.kind === "string" && decodePdfString(prefix)) yield* line("PageLabelPrefix: ", decodePdfString(prefix), true);
|
|
306
|
+
yield* line("PageLabelNumStyle: ", style?.kind === "name" ? styles[style.decoded] ?? "NoNumber" : "NoNumber");
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
198
311
|
for await (const page of document.pages()) {
|
|
199
312
|
const annotations = await resolve(dictGet(page.dict, "Annots"));
|
|
200
313
|
if (annotations?.kind !== "array") continue;
|
|
@@ -228,7 +341,7 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
228
341
|
yield* line("AnnotFlags: ", flags?.kind === "number" ? flags.value : 0);
|
|
229
342
|
yield* line("AnnotPageNumber: ", page.index + 1);
|
|
230
343
|
const action = dictGet(annotation, "A");
|
|
231
|
-
if (action) for await (const dict of walk(action, "Next")) {
|
|
344
|
+
if (action) for await (const { dict } of walk(action, "Next")) {
|
|
232
345
|
const type = await resolve(dictGet(dict, "S"));
|
|
233
346
|
if (type?.kind === "name" && type.decoded) yield* line("AnnotActionType: ", type.decoded);
|
|
234
347
|
yield* stringField(dict, "URI", "AnnotActionURI: ");
|
|
@@ -262,10 +375,466 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
262
375
|
}
|
|
263
376
|
}
|
|
264
377
|
|
|
378
|
+
// packages/safe-bash-command-pdftk/src/retained-burst.ts
|
|
379
|
+
async function* retainedBurst(document, storage, options, pageCount, signal) {
|
|
380
|
+
const pattern = options.outputTarget ?? "pg_%04d.pdf";
|
|
381
|
+
const slash = pattern.lastIndexOf("/");
|
|
382
|
+
const report = slash < 0 ? "doc_data.txt" : `${pattern.slice(0, slash + 1)}doc_data.txt`;
|
|
383
|
+
const repeated = formatBurstFilename(pattern, 1) === formatBurstFilename(pattern, 2);
|
|
384
|
+
for (let index = repeated ? Math.max(0, pageCount - 1) : 0; index < pageCount; index++) {
|
|
385
|
+
signal.throwIfAborted();
|
|
386
|
+
const path = formatBurstFilename(pattern, index + 1);
|
|
387
|
+
if (path === "-" || path === report) continue;
|
|
388
|
+
const copy = await createRetainedPageCopy(document, [index], storage, { signal });
|
|
389
|
+
let failed = false;
|
|
390
|
+
try {
|
|
391
|
+
const chunks = options.compressStreams || options.uncompressStreams ? saveRetainedDocumentChunks(await copy.openDocument(), storage, { signal, streamMode: options.uncompressStreams ? "uncompress" : "compress" }) : copy.chunks();
|
|
392
|
+
yield { path, chunks };
|
|
393
|
+
} catch (error) {
|
|
394
|
+
failed = true;
|
|
395
|
+
throw error;
|
|
396
|
+
} finally {
|
|
397
|
+
await copy.close().catch((error) => {
|
|
398
|
+
if (!failed) throw error;
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
yield { path: report, chunks: retainedInspectionReport(document, storage, false, signal, "document") };
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// packages/safe-bash-command-pdftk/src/retained-rotate.ts
|
|
406
|
+
import { PagedStorage as PagedStorage2 } from "@poe-platform/safe-fs/storage";
|
|
407
|
+
async function* retainedRotations(args, handles, primaryHandle, pageCount, storage, signal) {
|
|
408
|
+
const records = new PagedStorage2({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
|
|
409
|
+
const base = records.allocate(pageCount * 16);
|
|
410
|
+
let failed = false, work = 0;
|
|
411
|
+
try {
|
|
412
|
+
for (const arg of args) for (const selection of iteratePdftkRangeToken(arg, handles, primaryHandle)) {
|
|
413
|
+
signal.throwIfAborted();
|
|
414
|
+
if (++work % 64 === 0) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
415
|
+
if (!selection.rotation || selection.pageNumber > pageCount) continue;
|
|
416
|
+
const bytes = new Uint8Array(16), view = new DataView(bytes.buffer);
|
|
417
|
+
view.setFloat64(0, selection.rotation.kind === "relative" ? 2 : 1);
|
|
418
|
+
view.setFloat64(8, selection.rotation.degrees);
|
|
419
|
+
await records.write(base + (selection.pageNumber - 1) * 16, bytes);
|
|
420
|
+
}
|
|
421
|
+
for (let pageIndex = 0; pageIndex < pageCount; pageIndex++) {
|
|
422
|
+
signal.throwIfAborted();
|
|
423
|
+
if (++work % 64 === 0) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
424
|
+
const bytes = await records.read(base + pageIndex * 16, 16), view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length), kind = view.getFloat64(0);
|
|
425
|
+
if (kind) yield { pageIndex, degrees: view.getFloat64(8), relative: kind === 2 };
|
|
426
|
+
}
|
|
427
|
+
} catch (error) {
|
|
428
|
+
failed = true;
|
|
429
|
+
throw error;
|
|
430
|
+
} finally {
|
|
431
|
+
await records.close().catch((error) => {
|
|
432
|
+
if (!failed) throw error;
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// packages/safe-bash-command-pdftk/src/retained-output.ts
|
|
438
|
+
import { editRetainedDocument, PdfFileSource, PdfMutableObjectStore as PdfMutableObjectStore2, PdfRetainedDocument, cosBool, dictDelete, dictGet as dictGet2, dictSet, encryptRetainedPdfChunks, retainedCosObjects, saveRetainedDocumentChunks as saveRetainedDocumentChunks2 } from "../pdf-ast/index.js";
|
|
439
|
+
async function* retainedOutput(source, storage, options, selectedId, signal, handles, pageCount, attachments, attachmentPage, stamps) {
|
|
440
|
+
const store = new PdfMutableObjectStore2(storage, { signal });
|
|
441
|
+
let edited;
|
|
442
|
+
let document, plaintext, failed = false;
|
|
443
|
+
try {
|
|
444
|
+
if (options.operation === "attach_files" || stamps) {
|
|
445
|
+
const pageIndex = attachmentPage !== void 0 && pageCount > 0 ? attachmentPage.toLowerCase() === "end" ? pageCount - 1 : Math.max(0, Math.min(pageCount - 1, (Number.parseInt(attachmentPage, 10) || 1) - 1)) : void 0;
|
|
446
|
+
edited = await editRetainedDocument(source, storage, { signal, ...options.operation === "attach_files" ? { appendAttachments: attachments } : {}, ...stamps ? { stamps } : {}, ...pageIndex !== void 0 ? { attachmentPageIndex: pageIndex } : {} });
|
|
447
|
+
}
|
|
448
|
+
const input = edited?.document ?? source;
|
|
449
|
+
const pageReferences = edited ? { pageReferences: async function* () {
|
|
450
|
+
for await (const page of input.pages()) if (page.reference) yield page.reference;
|
|
451
|
+
} } : {};
|
|
452
|
+
for await (const object of retainedCosObjects(input, storage, { signal })) await store.set(object);
|
|
453
|
+
const reference = source.crossReference;
|
|
454
|
+
const idArray = options.keepFinalId || options.keepFirstId ? selectedId ?? reference.idArray : reference.idArray ?? selectedId;
|
|
455
|
+
document = await PdfRetainedDocument.openStore(store, storage, { rootRef: reference.rootRef, version: reference.version, ...pageReferences, ...reference.infoRef ? { infoRef: reference.infoRef } : {}, ...idArray ? { idArray } : {}, signal });
|
|
456
|
+
const root = await document.lookup(reference.rootRef);
|
|
457
|
+
if (root?.value.kind === "dict" && !root.stream && root.reference) {
|
|
458
|
+
const form = await document.lookup(dictGet2(root.value, "AcroForm"));
|
|
459
|
+
if (form?.value.kind === "dict" && !form.stream) {
|
|
460
|
+
if (options.dropXfa) dictDelete(form.value, "XFA");
|
|
461
|
+
if (options.needAppearances) dictSet(form.value, "NeedAppearances", cosBool(true));
|
|
462
|
+
if (form.reference) await store.set({ objectNumber: form.reference.objectNumber, generationNumber: form.reference.generationNumber, value: form.value });
|
|
463
|
+
else dictSet(root.value, "AcroForm", form.value);
|
|
464
|
+
}
|
|
465
|
+
await store.set({ objectNumber: root.reference.objectNumber, generationNumber: root.reference.generationNumber, value: root.value });
|
|
466
|
+
}
|
|
467
|
+
const chunks = saveRetainedDocumentChunks2(document, storage, { signal, ...options.operation === "rotate" ? { rotations: retainedRotations(options.opArgs, handles, options.inputs[0].handle, pageCount, storage, signal) } : {}, removeMetadata: options.dropXmp, streamMode: options.uncompressStreams ? "uncompress" : options.compressStreams ? "compress" : "preserve" });
|
|
468
|
+
if (!options.userPassword && !options.ownerPassword) {
|
|
469
|
+
yield* chunks;
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
plaintext = await PdfFileSource.fromStream(storage.fs, storage.directory, chunks, { signal });
|
|
473
|
+
const allow = options.allowPermissions, all = allow.has("allfeatures");
|
|
474
|
+
yield* encryptRetainedPdfChunks(plaintext, storage, {
|
|
475
|
+
userPassword: options.userPassword ?? "",
|
|
476
|
+
ownerPassword: options.ownerPassword ?? options.userPassword ?? "owner",
|
|
477
|
+
revision: 6,
|
|
478
|
+
signal,
|
|
479
|
+
...allow.size ? { permissions: { print: all || allow.has("printing") || allow.has("degradedprinting"), modify: all || allow.has("modifycontents"), copy: all || allow.has("copycontents"), addNotes: all || allow.has("modifyannotations"), fillForms: all || allow.has("fillin") || allow.has("modifyannotations"), extractAccessibility: all || allow.has("screenreaders"), assemble: all || allow.has("assembly") || allow.has("modifycontents"), printHighRes: all || allow.has("printing") } } : {}
|
|
480
|
+
});
|
|
481
|
+
} catch (error) {
|
|
482
|
+
failed = true;
|
|
483
|
+
throw error;
|
|
484
|
+
} finally {
|
|
485
|
+
const results = await Promise.allSettled([document?.close(), plaintext?.close(), store.close(), edited?.close()]);
|
|
486
|
+
if (!failed) {
|
|
487
|
+
for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// packages/safe-bash-command-pdftk/src/retained-unpack.ts
|
|
493
|
+
import { IntegerTable as IntegerTable2, PagedStorage as PagedStorage3 } from "@poe-platform/safe-fs/storage";
|
|
494
|
+
import { PdfFileSource as PdfFileSource2, PdfMutableObjectStore as PdfMutableObjectStore3, PdfNameIndex as PdfNameIndex2, cosDict, cosString, decodePdfString as decodePdfString2, dictGet as dictGet3 } from "../pdf-ast/index.js";
|
|
495
|
+
async function* retainedUnpack(document, storage, directory, inputNames, signal) {
|
|
496
|
+
const names = new PdfNameIndex2(storage, Infinity, signal), outputs = new PdfMutableObjectStore3(storage, { signal });
|
|
497
|
+
const stack = new PdfMutableObjectStore3(storage, { signal }), backing = new PagedStorage3({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), seen = new IntegerTable2(backing, 64);
|
|
498
|
+
const cleanDir = directory.endsWith("/") ? directory.slice(0, -1) : directory;
|
|
499
|
+
let pending = 0, work = 0, failed = false;
|
|
500
|
+
async function checkpoint() {
|
|
501
|
+
signal.throwIfAborted();
|
|
502
|
+
if (++work % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
503
|
+
signal.throwIfAborted();
|
|
504
|
+
}
|
|
505
|
+
async function resolve(node) {
|
|
506
|
+
await checkpoint();
|
|
507
|
+
const found = await document.lookup(node);
|
|
508
|
+
return found?.stream ? void 0 : found?.value;
|
|
509
|
+
}
|
|
510
|
+
async function spec(raw, fallback = "attachment.bin") {
|
|
511
|
+
const dict = await resolve(raw);
|
|
512
|
+
if (dict?.kind !== "dict") return;
|
|
513
|
+
const filename = await resolve(dictGet3(dict, "UF") ?? dictGet3(dict, "F"));
|
|
514
|
+
const name = filename?.kind === "string" ? decodePdfString2(filename) : fallback;
|
|
515
|
+
const leaf = name.slice(Math.max(name.lastIndexOf("/"), name.lastIndexOf("\\")) + 1);
|
|
516
|
+
if (!leaf || leaf === "." || leaf === ".." || leaf.includes("\0")) throw new Error("Invalid embedded attachment filename");
|
|
517
|
+
const ef = await resolve(dictGet3(dict, "EF"));
|
|
518
|
+
if (ef?.kind !== "dict") return;
|
|
519
|
+
const data = await document.lookup(dictGet3(ef, "UF") ?? dictGet3(ef, "F") ?? dictGet3(ef, "DOS") ?? dictGet3(ef, "Mac") ?? dictGet3(ef, "Unix"));
|
|
520
|
+
if (!data?.stream || !data.reference) return;
|
|
521
|
+
const path = cleanDir && cleanDir !== "." ? `${cleanDir}/${leaf}` : leaf;
|
|
522
|
+
const nameIndex = await names.intern(path);
|
|
523
|
+
const staged = await PdfFileSource2.fromStream(storage.fs, storage.directory, document.objects.decodeStream(data.reference.objectNumber, data.reference.generationNumber), { signal });
|
|
524
|
+
let failed2 = false;
|
|
525
|
+
try {
|
|
526
|
+
await outputs.set({ objectNumber: nameIndex.index + 1, generationNumber: 0, value: cosDict({ Path: cosString(path) }), stream: { length: staged.size, chunks: staged.stream(0, staged.size, signal) } });
|
|
527
|
+
} catch (error) {
|
|
528
|
+
failed2 = true;
|
|
529
|
+
throw error;
|
|
530
|
+
} finally {
|
|
531
|
+
await staged.close().catch((error) => {
|
|
532
|
+
if (!failed2) throw error;
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
const push = async (value) => {
|
|
537
|
+
await checkpoint();
|
|
538
|
+
await stack.set({ objectNumber: ++pending, generationNumber: 0, value });
|
|
539
|
+
};
|
|
540
|
+
async function associated(raw) {
|
|
541
|
+
const array = await resolve(raw);
|
|
542
|
+
if (array?.kind === "array") for (const item of array.items) await spec(item);
|
|
543
|
+
}
|
|
544
|
+
try {
|
|
545
|
+
for (const name of inputNames) await names.intern(name);
|
|
546
|
+
const root = await resolve(document.crossReference.rootRef);
|
|
547
|
+
if (root?.kind === "dict") {
|
|
548
|
+
const dictionary = await resolve(dictGet3(root, "Names")), tree = dictionary?.kind === "dict" ? dictGet3(dictionary, "EmbeddedFiles") : void 0;
|
|
549
|
+
if (tree) await push(tree);
|
|
550
|
+
while (pending) {
|
|
551
|
+
await checkpoint();
|
|
552
|
+
const raw = (await stack.get(pending--)).value;
|
|
553
|
+
if (raw.kind === "ref") {
|
|
554
|
+
if (await seen.get(BigInt(raw.objectNumber))) continue;
|
|
555
|
+
await seen.set(BigInt(raw.objectNumber), 1n);
|
|
556
|
+
}
|
|
557
|
+
const branch = await resolve(raw);
|
|
558
|
+
if (branch?.kind !== "dict") continue;
|
|
559
|
+
const pairs = await resolve(dictGet3(branch, "Names"));
|
|
560
|
+
if (pairs?.kind === "array") for (let i = 0; i + 1 < pairs.items.length; i += 2) {
|
|
561
|
+
const name = await resolve(pairs.items[i]);
|
|
562
|
+
await spec(pairs.items[i + 1], name?.kind === "string" ? decodePdfString2(name) : "attachment.bin");
|
|
563
|
+
}
|
|
564
|
+
const kids = await resolve(dictGet3(branch, "Kids"));
|
|
565
|
+
if (kids?.kind === "array") for (let i = kids.items.length - 1; i >= 0; i--) await push(kids.items[i]);
|
|
566
|
+
}
|
|
567
|
+
await associated(dictGet3(root, "AF"));
|
|
568
|
+
}
|
|
569
|
+
for await (const page of document.pages()) {
|
|
570
|
+
await associated(dictGet3(page.dict, "AF"));
|
|
571
|
+
const annotations = await resolve(dictGet3(page.dict, "Annots"));
|
|
572
|
+
if (annotations?.kind === "array") for (const raw of annotations.items) {
|
|
573
|
+
const annotation = await resolve(raw);
|
|
574
|
+
if (annotation?.kind !== "dict") continue;
|
|
575
|
+
const type = await resolve(dictGet3(annotation, "Subtype"));
|
|
576
|
+
if (type?.kind === "name" && type.decoded === "FileAttachment") await spec(dictGet3(annotation, "FS"));
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
for await (const output of outputs.objects()) {
|
|
580
|
+
const path = output.value.kind === "dict" ? dictGet3(output.value, "Path") : void 0;
|
|
581
|
+
if (path?.kind === "string" && output.stream) {
|
|
582
|
+
const name = decodePdfString2(path);
|
|
583
|
+
if (name !== "-") yield { path: name, chunks: output.stream.chunks };
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
} catch (error) {
|
|
587
|
+
failed = true;
|
|
588
|
+
throw error;
|
|
589
|
+
} finally {
|
|
590
|
+
const results = await Promise.allSettled([names.close(), outputs.close(), stack.close(), backing.close()]);
|
|
591
|
+
if (!failed) {
|
|
592
|
+
for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// packages/safe-bash-command-pdftk/src/retained-fdf.ts
|
|
598
|
+
import { PdfError, PdfFileSource as PdfFileSource3, PdfMutableObjectStore as PdfMutableObjectStore4, PdfNameIndex as PdfNameIndex3, cosArray as cosArray2, cosDict as cosDict2, cosNumber as cosNumber2, cosString as cosString2, decodePdfString as decodePdfString3, dictGet as dictGet4 } from "../pdf-ast/index.js";
|
|
599
|
+
async function* retainedFdf(document, storage, signal) {
|
|
600
|
+
const names = new PdfNameIndex3(storage, Infinity, signal);
|
|
601
|
+
const values = new PdfMutableObjectStore4(storage, { signal });
|
|
602
|
+
const tree = new PdfMutableObjectStore4(storage, { signal });
|
|
603
|
+
const encoder = new TextEncoder();
|
|
604
|
+
let work = 0, failed = false;
|
|
605
|
+
async function checkpoint() {
|
|
606
|
+
signal.throwIfAborted();
|
|
607
|
+
if (++work % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
608
|
+
signal.throwIfAborted();
|
|
609
|
+
}
|
|
610
|
+
async function resolve(node) {
|
|
611
|
+
await checkpoint();
|
|
612
|
+
const found = await document.lookup(node);
|
|
613
|
+
return found?.stream ? void 0 : found?.value;
|
|
614
|
+
}
|
|
615
|
+
async function* text(value, escape = false) {
|
|
616
|
+
let chunk = "";
|
|
617
|
+
for (const char of value) {
|
|
618
|
+
chunk += escape ? char === "\\" || char === "(" || char === ")" ? `\\${char}` : char === "\r" ? "\\r" : char === "\n" ? "\\n" : char : char;
|
|
619
|
+
if (chunk.length >= 4096) {
|
|
620
|
+
await checkpoint();
|
|
621
|
+
yield encoder.encode(chunk);
|
|
622
|
+
chunk = "";
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
if (chunk) {
|
|
626
|
+
signal.throwIfAborted();
|
|
627
|
+
yield encoder.encode(chunk);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
async function* fieldValue(field) {
|
|
631
|
+
if (field.checked !== void 0) {
|
|
632
|
+
yield* text(`/${field.checked ? field.stateValue ?? "Yes" : "Off"}`);
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
let count = 0;
|
|
636
|
+
for await (const ignored of field.values()) {
|
|
637
|
+
void ignored;
|
|
638
|
+
if (++count > 1) break;
|
|
639
|
+
}
|
|
640
|
+
if (count > 1) yield* text("[ ");
|
|
641
|
+
let first = true;
|
|
642
|
+
for await (const value of field.values()) {
|
|
643
|
+
if (!first) yield* text(" ");
|
|
644
|
+
first = false;
|
|
645
|
+
yield* text("(");
|
|
646
|
+
yield* text(value, true);
|
|
647
|
+
yield* text(")");
|
|
648
|
+
}
|
|
649
|
+
if (count > 1) yield* text(" ]");
|
|
650
|
+
}
|
|
651
|
+
async function record(id) {
|
|
652
|
+
const node = (await tree.get(id))?.value;
|
|
653
|
+
if (node?.kind !== "array") throw new PdfError("E_PARSE", "Invalid FDF traversal record");
|
|
654
|
+
return node.items;
|
|
655
|
+
}
|
|
656
|
+
const number = (items, at) => {
|
|
657
|
+
const node = items[at];
|
|
658
|
+
if (node?.kind !== "number") throw new PdfError("E_PARSE", "Invalid FDF traversal number");
|
|
659
|
+
return node.value;
|
|
660
|
+
};
|
|
661
|
+
const string = (items, at) => {
|
|
662
|
+
const node = items[at];
|
|
663
|
+
if (node?.kind !== "string") throw new PdfError("E_PARSE", "Invalid FDF traversal name");
|
|
664
|
+
return decodePdfString3(node);
|
|
665
|
+
};
|
|
666
|
+
const save = async (id, items) => tree.set({ objectNumber: id, generationNumber: 0, value: cosArray2(items) });
|
|
667
|
+
try {
|
|
668
|
+
for await (const field of document.formFieldDetails()) {
|
|
669
|
+
for await (const ignored of field.options()) void ignored;
|
|
670
|
+
const name = await names.intern(field.name);
|
|
671
|
+
const staged = await PdfFileSource3.fromStream(storage.fs, storage.directory, fieldValue(field), { signal });
|
|
672
|
+
let valueFailed = false;
|
|
673
|
+
try {
|
|
674
|
+
await values.set({ objectNumber: name.index + 1, generationNumber: 0, value: cosDict2({}), stream: { length: staged.size, chunks: staged.stream(0, staged.size, signal) } });
|
|
675
|
+
} catch (error) {
|
|
676
|
+
valueFailed = true;
|
|
677
|
+
throw error;
|
|
678
|
+
} finally {
|
|
679
|
+
await staged.close().catch((error) => {
|
|
680
|
+
if (!valueFailed) throw error;
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
const catalog = await resolve(document.crossReference.rootRef);
|
|
685
|
+
const form = catalog?.kind === "dict" ? await resolve(dictGet4(catalog, "AcroForm")) : void 0;
|
|
686
|
+
const roots = form?.kind === "dict" ? await resolve(dictGet4(form, "Fields")) : void 0;
|
|
687
|
+
await save(1, [cosDict2({}), cosString2(""), cosString2(""), ...Array.from({ length: 6 }, () => cosNumber2(0))]);
|
|
688
|
+
let top = 1, next = 1;
|
|
689
|
+
while (top) {
|
|
690
|
+
await checkpoint();
|
|
691
|
+
const frame = await record(top), node = await resolve(frame[0]);
|
|
692
|
+
const kids = top === 1 ? roots : node?.kind === "dict" ? await resolve(dictGet4(node, "Kids")) : void 0;
|
|
693
|
+
let descended = false, cursor = number(frame, 3);
|
|
694
|
+
while (kids?.kind === "array" && cursor < kids.items.length) {
|
|
695
|
+
const childNode = kids.items[cursor++], child = await resolve(childNode);
|
|
696
|
+
if (child?.kind !== "dict" || top !== 1 && !dictGet4(child, "T")) continue;
|
|
697
|
+
const name = await resolve(dictGet4(child, "T")), partial = name?.kind === "string" ? decodePdfString3(name) : "";
|
|
698
|
+
const prefix = string(frame, 1), full = prefix && partial ? `${prefix}.${partial}` : partial || prefix;
|
|
699
|
+
const depth = number(frame, 8) + 1;
|
|
700
|
+
if (depth > document.depthLimit) throw new PdfError("E_LIMIT", "PDF FDF field depth limit exceeded");
|
|
701
|
+
frame[3] = cosNumber2(cursor);
|
|
702
|
+
await save(top, frame);
|
|
703
|
+
await save(++next, [childNode, cosString2(full), cosString2(partial), cosNumber2(0), cosNumber2(0), cosNumber2(0), cosNumber2(0), cosNumber2(top), cosNumber2(depth)]);
|
|
704
|
+
top = next;
|
|
705
|
+
descended = true;
|
|
706
|
+
break;
|
|
707
|
+
}
|
|
708
|
+
if (descended) continue;
|
|
709
|
+
const parent = number(frame, 7);
|
|
710
|
+
if (parent && (number(frame, 4) || string(frame, 1) || string(frame, 2))) {
|
|
711
|
+
const owner = await record(parent), last = number(owner, 5);
|
|
712
|
+
if (last) {
|
|
713
|
+
const sibling = await record(last);
|
|
714
|
+
sibling[6] = cosNumber2(top);
|
|
715
|
+
await save(last, sibling);
|
|
716
|
+
} else owner[4] = cosNumber2(top);
|
|
717
|
+
owner[5] = cosNumber2(top);
|
|
718
|
+
await save(parent, owner);
|
|
719
|
+
}
|
|
720
|
+
top = parent;
|
|
721
|
+
}
|
|
722
|
+
yield* text("%FDF-1.2\n1 0 obj\n<< /FDF << /Fields [\n");
|
|
723
|
+
let current = number(await record(1), 4);
|
|
724
|
+
if (current) yield* text(" ");
|
|
725
|
+
while (current) {
|
|
726
|
+
await checkpoint();
|
|
727
|
+
const frame = await record(current), child = number(frame, 4);
|
|
728
|
+
yield* text("<< /T (");
|
|
729
|
+
yield* text(string(frame, 2) || string(frame, 1), true);
|
|
730
|
+
yield* text(")");
|
|
731
|
+
if (child) {
|
|
732
|
+
yield* text(" /Kids [ ");
|
|
733
|
+
current = child;
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
yield* text(" /V ");
|
|
737
|
+
const name = await names.intern(string(frame, 1)), value = name.added ? void 0 : await values.get(name.index + 1);
|
|
738
|
+
if (value?.stream) yield* value.stream.chunks;
|
|
739
|
+
else {
|
|
740
|
+
const dict = await resolve(frame[0]), raw = dict?.kind === "dict" ? await resolve(dictGet4(dict, "V")) : void 0;
|
|
741
|
+
if (raw?.kind === "name") yield* text(`/${raw.decoded}`);
|
|
742
|
+
else {
|
|
743
|
+
yield* text("(");
|
|
744
|
+
if (raw?.kind === "string") yield* text(decodePdfString3(raw), true);
|
|
745
|
+
yield* text(")");
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
yield* text(" >>");
|
|
749
|
+
while (current) {
|
|
750
|
+
const done = await record(current), sibling = number(done, 6), parent = number(done, 7);
|
|
751
|
+
if (sibling) {
|
|
752
|
+
yield* text(parent === 1 ? "\n " : " ");
|
|
753
|
+
current = sibling;
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
current = parent === 1 ? 0 : parent;
|
|
757
|
+
if (current) yield* text(" ] >>");
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
yield* text("\n] >> >>\nendobj\ntrailer\n<< /Root 1 0 R >>\n%%EOF\n");
|
|
761
|
+
} catch (error) {
|
|
762
|
+
failed = true;
|
|
763
|
+
throw error;
|
|
764
|
+
} finally {
|
|
765
|
+
const results = await Promise.allSettled([names.close(), values.close(), tree.close()]);
|
|
766
|
+
if (!failed) {
|
|
767
|
+
for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// packages/safe-bash-command-pdftk/src/retained-fields.ts
|
|
773
|
+
async function* retainedFieldReport(document, utf8, signal) {
|
|
774
|
+
const encoder = new TextEncoder();
|
|
775
|
+
let work = 0;
|
|
776
|
+
async function* line(prefix, value) {
|
|
777
|
+
let part = prefix;
|
|
778
|
+
for (const char of String(value)) {
|
|
779
|
+
const code = char.codePointAt(0);
|
|
780
|
+
part += !utf8 && code > 127 ? `&#${code};` : char;
|
|
781
|
+
if (part.length >= 4096) {
|
|
782
|
+
signal.throwIfAborted();
|
|
783
|
+
if (++work % 16 === 0) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
784
|
+
yield encoder.encode(part);
|
|
785
|
+
part = "";
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
signal.throwIfAborted();
|
|
789
|
+
yield encoder.encode(part + "\n");
|
|
790
|
+
}
|
|
791
|
+
for await (const field of document.formFieldDetails()) {
|
|
792
|
+
yield encoder.encode("---\n");
|
|
793
|
+
yield* line("FieldType: ", field.type === "checkbox" ? "Button" : field.type === "choice" ? "Choice" : "Text");
|
|
794
|
+
yield* line("FieldName: ", field.name);
|
|
795
|
+
if (field.altName) yield* line("FieldNameAlt: ", field.altName);
|
|
796
|
+
yield* line("FieldFlags: ", field.flags);
|
|
797
|
+
for await (const value of field.values()) yield* line("FieldValue: ", value);
|
|
798
|
+
if (field.defaultValue !== void 0 && field.defaultValue !== "") yield* line("FieldValueDefault: ", field.defaultValue);
|
|
799
|
+
yield* line("FieldJustification: ", field.justification);
|
|
800
|
+
for await (const option of field.options()) yield* line("FieldStateOption: ", option);
|
|
801
|
+
if (field.maxLength !== void 0) yield* line("FieldMaxLength: ", field.maxLength);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
265
805
|
// packages/safe-bash-command-pdftk/src/retained.ts
|
|
806
|
+
import { PdfError as PdfError2, PdfFileSource as PdfFileSource4, PdfRetainedDocument as PdfRetainedDocument2, retainedCosObjects as retainedCosObjects2 } from "../pdf-ast/index.js";
|
|
807
|
+
import { FsError } from "../safe-bash-contracts/errors.js";
|
|
808
|
+
import { writeBytes } from "../safe-bash-contracts/io.js";
|
|
809
|
+
import { resolvePath } from "../safe-bash-contracts/path.js";
|
|
810
|
+
import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
|
|
266
811
|
async function executeRetainedPdftk(context, options) {
|
|
267
812
|
const signal = context.signal, storage = { fs: context.fs, directory: resolvePath(context.cwd, context.env.TMPDIR || "/tmp") };
|
|
813
|
+
const handles = /* @__PURE__ */ new Map();
|
|
814
|
+
for (const input of options.inputs) {
|
|
815
|
+
handles.set(input.handle, input);
|
|
816
|
+
if (!handles.has("")) handles.set("", input);
|
|
817
|
+
}
|
|
818
|
+
const primary = options.inputs[0];
|
|
819
|
+
let idInput = handles.values().next().value;
|
|
820
|
+
if (options.keepFinalId) for (const input of handles.values()) idInput = input;
|
|
821
|
+
let selectedId;
|
|
822
|
+
const counts = /* @__PURE__ */ new Map();
|
|
268
823
|
const inputs = /* @__PURE__ */ new Map();
|
|
824
|
+
const overlayPath = ["stamp", "multistamp", "background", "multibackground"].includes(options.operation) ? options.opArgs[0] ?? "-" : void 0;
|
|
825
|
+
const attachmentPaths = [];
|
|
826
|
+
let attachmentPage;
|
|
827
|
+
if (options.operation === "attach_files") for (let i = 0; i < options.opArgs.length; i++) {
|
|
828
|
+
if (options.opArgs[i].toLowerCase() === "to_page") attachmentPage = options.opArgs[++i];
|
|
829
|
+
else attachmentPaths.push(options.opArgs[i]);
|
|
830
|
+
}
|
|
831
|
+
async function* attachments() {
|
|
832
|
+
for (const path of attachmentPaths) {
|
|
833
|
+
const source = inputs.get(path);
|
|
834
|
+
if (source) yield { filename: path.slice(path.lastIndexOf("/") + 1), chunks: source.stream(0, source.size, signal) };
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
let overlayDocument;
|
|
269
838
|
let document, output, total = 0, failed = false;
|
|
270
839
|
const diagnostic = async (message) => {
|
|
271
840
|
await writeBytes(context.stderr, new TextEncoder().encode(message), signal);
|
|
@@ -274,20 +843,20 @@ async function executeRetainedPdftk(context, options) {
|
|
|
274
843
|
try {
|
|
275
844
|
await context.fs.mkdir(storage.directory, { recursive: true, signal });
|
|
276
845
|
const maximum = context.inputBudget?.maxBytes ?? Infinity;
|
|
277
|
-
if (options.inputs.some((input) => input.file === "-")) {
|
|
278
|
-
const source = await
|
|
846
|
+
if (options.inputs.some((input) => input.file === "-") || attachmentPaths.includes("-") || overlayPath === "-") {
|
|
847
|
+
const source = await PdfFileSource4.fromStream(context.fs, storage.directory, context.stdin, { signal, maxInputBytes: maximum });
|
|
279
848
|
inputs.set("-", source);
|
|
280
849
|
total += source.size;
|
|
281
850
|
context.inputBudget?.check(total);
|
|
282
851
|
}
|
|
283
|
-
for (const input of options.inputs) {
|
|
852
|
+
for (const input of [...options.inputs, ...attachmentPaths.map((file) => ({ file })), ...overlayPath !== void 0 ? [{ file: overlayPath }] : []]) {
|
|
284
853
|
if (inputs.has(input.file)) continue;
|
|
285
854
|
let source;
|
|
286
855
|
try {
|
|
287
|
-
source = await
|
|
856
|
+
source = await PdfFileSource4.open(context.fs, resolvePath(context.cwd, input.file), { signal, maxInputBytes: maximum - total });
|
|
288
857
|
} catch (error) {
|
|
289
858
|
signal.throwIfAborted();
|
|
290
|
-
if (error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR", "EACCES", "EISDIR"].includes(String(error.code)) || error instanceof
|
|
859
|
+
if (error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR", "EACCES", "EISDIR"].includes(String(error.code)) || error instanceof PdfError2 && error.message === "PDF source must be a regular file") {
|
|
291
860
|
inputs.set(input.file, void 0);
|
|
292
861
|
continue;
|
|
293
862
|
}
|
|
@@ -302,12 +871,18 @@ async function executeRetainedPdftk(context, options) {
|
|
|
302
871
|
if (!source) return await diagnostic(`Error: Unable to find file '${input.file}'
|
|
303
872
|
`);
|
|
304
873
|
try {
|
|
305
|
-
document = await
|
|
306
|
-
|
|
307
|
-
for await (const
|
|
874
|
+
document = await PdfRetainedDocument2.open(source, storage, { signal, recovery: "strict", ...input.password ? { password: input.password } : {} });
|
|
875
|
+
if (input === idInput) selectedId = document.crossReference.idArray;
|
|
876
|
+
for await (const object of retainedCosObjects2(document, storage, { signal })) if (object.stream) for await (const ignored of object.stream.chunks) void ignored;
|
|
877
|
+
let count = 0;
|
|
878
|
+
for await (const ignored of document.pages()) {
|
|
879
|
+
void ignored;
|
|
880
|
+
count++;
|
|
881
|
+
}
|
|
882
|
+
counts.set(input, count);
|
|
308
883
|
} catch (error) {
|
|
309
884
|
signal.throwIfAborted();
|
|
310
|
-
if (!(error instanceof
|
|
885
|
+
if (!(error instanceof PdfError2) || error.code === "E_LIMIT" || error.code === "E_CANCELLED") throw error;
|
|
311
886
|
return await diagnostic(`Error: Failed to open PDF '${input.file}': ${error.message}
|
|
312
887
|
`);
|
|
313
888
|
}
|
|
@@ -315,14 +890,42 @@ async function executeRetainedPdftk(context, options) {
|
|
|
315
890
|
document = void 0;
|
|
316
891
|
await source.releaseCache();
|
|
317
892
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
893
|
+
document = await PdfRetainedDocument2.open(inputs.get(primary.file), storage, { signal, recovery: "strict", ...primary.password ? { password: primary.password } : {} });
|
|
894
|
+
let overlayPages = 0;
|
|
895
|
+
if (overlayPath !== void 0) {
|
|
896
|
+
const source = inputs.get(overlayPath);
|
|
897
|
+
if (!source) return await diagnostic(`Error: Unable to open '${overlayPath}'
|
|
898
|
+
`);
|
|
899
|
+
overlayDocument = await PdfRetainedDocument2.open(source, storage, { signal, recovery: "strict" });
|
|
900
|
+
for await (const object of retainedCosObjects2(overlayDocument, storage, { signal })) if (object.stream) for await (const ignored of object.stream.chunks) void ignored;
|
|
901
|
+
for await (const ignored of overlayDocument.pages()) {
|
|
902
|
+
void ignored;
|
|
903
|
+
overlayPages++;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
async function* stampPages() {
|
|
907
|
+
if (overlayPages) for (let targetIndex = 0; targetIndex < counts.get(primary); targetIndex++) yield { targetIndex, sourceIndex: options.operation.startsWith("multi") ? Math.min(targetIndex, overlayPages - 1) : 0 };
|
|
908
|
+
}
|
|
909
|
+
if (options.operation === "unpack_files" || options.operation === "burst") {
|
|
910
|
+
const files = options.operation === "burst" ? retainedBurst(document, storage, options, counts.get(primary), signal) : retainedUnpack(document, storage, options.outputTarget ?? ".", inputs.keys(), signal);
|
|
911
|
+
for await (const file of files) {
|
|
912
|
+
try {
|
|
913
|
+
await publish(context, resolvePath(context.cwd, file.path), file.chunks);
|
|
914
|
+
} catch (error) {
|
|
915
|
+
signal.throwIfAborted();
|
|
916
|
+
if (!(error instanceof Error) || !("code" in error)) throw error;
|
|
917
|
+
return await diagnostic(`Error: Failed to open output file '${file.path}': ${error.code}.
|
|
918
|
+
`);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
return { exitCode: 0 };
|
|
922
|
+
}
|
|
923
|
+
output = await PdfFileSource4.fromStream(context.fs, storage.directory, ["output", "rotate", "attach_files", "stamp", "multistamp", "background", "multibackground"].includes(options.operation) ? retainedOutput(document, storage, options, selectedId, signal, new Map([...handles].map(([handle, input]) => [handle, { pageCount: counts.get(input) }])), counts.get(primary), attachments(), attachmentPage, overlayDocument ? [{ source: overlayDocument, mode: options.operation.includes("background") ? "underlay" : "overlay", preserveStreams: true, pages: stampPages() }] : void 0) : options.operation === "generate_fdf" ? retainedFdf(document, storage, signal) : options.operation === "dump_data_fields" || options.operation === "dump_data_fields_utf8" ? retainedFieldReport(document, options.operation.endsWith("_utf8"), signal) : retainedInspectionReport(document, storage, options.operation.endsWith("_utf8"), signal, options.operation === "dump_data" || options.operation === "dump_data_utf8" ? "document" : "annotations"), { signal });
|
|
321
924
|
const destination = options.outputTarget;
|
|
322
925
|
if (!destination || destination === "-") for await (const bytes of output.stream(0, output.size, signal)) await writeBytes(context.stdout, bytes, signal);
|
|
323
926
|
else {
|
|
324
927
|
try {
|
|
325
|
-
await publish(context, resolvePath(context.cwd, destination), output);
|
|
928
|
+
await publish(context, resolvePath(context.cwd, destination), output.stream(0, output.size, signal));
|
|
326
929
|
} catch (error) {
|
|
327
930
|
signal.throwIfAborted();
|
|
328
931
|
if (!(error instanceof Error) || !("code" in error)) throw error;
|
|
@@ -335,13 +938,13 @@ async function executeRetainedPdftk(context, options) {
|
|
|
335
938
|
failed = true;
|
|
336
939
|
throw error;
|
|
337
940
|
} finally {
|
|
338
|
-
const results = await Promise.allSettled([document?.close(), output?.close(), ...[...inputs.values()].map((source) => source?.close())]);
|
|
941
|
+
const results = await Promise.allSettled([document?.close(), overlayDocument?.close(), output?.close(), ...[...inputs.values()].map((source) => source?.close())]);
|
|
339
942
|
if (!failed) {
|
|
340
943
|
for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
|
|
341
944
|
}
|
|
342
945
|
}
|
|
343
946
|
}
|
|
344
|
-
async function publish(context, path,
|
|
947
|
+
async function publish(context, path, chunks) {
|
|
345
948
|
const fs = context.fs, signal = context.signal;
|
|
346
949
|
const capabilities = await fs.capabilitiesFor?.(path, { signal, create: true, stagingAncestry: true }) ?? fs.capabilities;
|
|
347
950
|
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" });
|
|
@@ -350,7 +953,7 @@ async function publish(context, path, source) {
|
|
|
350
953
|
let failed = false;
|
|
351
954
|
try {
|
|
352
955
|
if (!staging.writer || !staging.cleanup) throw new FsError("ENOTSUP", { path, message: "PDF backend omitted retained staging handles" });
|
|
353
|
-
for await (const bytes of
|
|
956
|
+
for await (const bytes of chunks) await writeFileOutput(context, bytes, (data) => staging.writer.write(data, { signal }));
|
|
354
957
|
const stat = await staging.writer.finish({ signal });
|
|
355
958
|
await fs.publishStagedFile({ ...staging, file: { ...staging.file, stat } }, resolution.path, { parent: resolution.parent, destination: resolution.destination, ancestors: resolution.ancestors, commitGuard: resolution.validate, signal });
|
|
356
959
|
} catch (error) {
|
|
@@ -548,17 +1151,17 @@ import { readBytes, writeBytes as writeBytes2 } from "../safe-bash-contracts/io.
|
|
|
548
1151
|
import { createOutputOperation } from "../safe-bash-contracts/output.js";
|
|
549
1152
|
import {
|
|
550
1153
|
PdfDocument,
|
|
551
|
-
cosArray,
|
|
552
|
-
cosDict,
|
|
1154
|
+
cosArray as cosArray3,
|
|
1155
|
+
cosDict as cosDict3,
|
|
553
1156
|
cosHexString,
|
|
554
1157
|
cosName,
|
|
555
|
-
cosNumber,
|
|
1158
|
+
cosNumber as cosNumber3,
|
|
556
1159
|
cosStream,
|
|
557
|
-
cosString,
|
|
558
|
-
decodePdfString as
|
|
559
|
-
dictDelete,
|
|
560
|
-
dictGet as
|
|
561
|
-
dictSet,
|
|
1160
|
+
cosString as cosString3,
|
|
1161
|
+
decodePdfString as decodePdfString4,
|
|
1162
|
+
dictDelete as dictDelete2,
|
|
1163
|
+
dictGet as dictGet5,
|
|
1164
|
+
dictSet as dictSet2,
|
|
562
1165
|
flattenDocumentFormFields,
|
|
563
1166
|
getDocumentFormFields,
|
|
564
1167
|
parseFormDataBytes,
|
|
@@ -616,6 +1219,9 @@ function resolvePageEndpoint(token, totalPages) {
|
|
|
616
1219
|
return Number.isFinite(num) && num >= 1 ? Math.min(totalPages, num) : 1;
|
|
617
1220
|
}
|
|
618
1221
|
function parsePdftkRangeToken(token, handles, defaultHandle) {
|
|
1222
|
+
return Array.from(iteratePdftkRangeToken(token, handles, defaultHandle));
|
|
1223
|
+
}
|
|
1224
|
+
function* iteratePdftkRangeToken(token, handles, defaultHandle) {
|
|
619
1225
|
let work = token.trim();
|
|
620
1226
|
let handle = defaultHandle;
|
|
621
1227
|
const sortedHandleKeys = [...handles.keys()].sort((a, b) => b.length - a.length);
|
|
@@ -661,22 +1267,11 @@ function parsePdftkRangeToken(token, handles, defaultHandle) {
|
|
|
661
1267
|
endPage = resolvePageEndpoint(work.slice(dashIdx + 1), totalPages);
|
|
662
1268
|
}
|
|
663
1269
|
}
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
for (let p = startPage; p >= endPage; p--) pages.push(p);
|
|
1270
|
+
const step = startPage <= endPage ? 1 : -1;
|
|
1271
|
+
for (let pageNumber = startPage; step > 0 ? pageNumber <= endPage : pageNumber >= endPage; pageNumber += step) {
|
|
1272
|
+
if (qualifier === "even" && pageNumber % 2 !== 0 || qualifier === "odd" && pageNumber % 2 !== 1) continue;
|
|
1273
|
+
yield { handle, pageNumber, rotation };
|
|
669
1274
|
}
|
|
670
|
-
const filtered = pages.filter((p) => {
|
|
671
|
-
if (qualifier === "even") return p % 2 === 0;
|
|
672
|
-
if (qualifier === "odd") return p % 2 === 1;
|
|
673
|
-
return true;
|
|
674
|
-
});
|
|
675
|
-
return filtered.map((pageNumber) => ({
|
|
676
|
-
handle,
|
|
677
|
-
pageNumber,
|
|
678
|
-
rotation
|
|
679
|
-
}));
|
|
680
1275
|
}
|
|
681
1276
|
function encodePdftkText(str, utf8) {
|
|
682
1277
|
if (utf8) return str;
|
|
@@ -773,40 +1368,40 @@ function formatDumpDataAnnots(doc, utf8 = false) {
|
|
|
773
1368
|
lines.push(`NumberOfPages: ${doc.pageCount}`);
|
|
774
1369
|
for (let p = 0; p < doc.pageCount; p++) {
|
|
775
1370
|
const pageDict = doc.getPage(p).pageDict;
|
|
776
|
-
const annotsArr = doc.cos.resolveArray(
|
|
1371
|
+
const annotsArr = doc.cos.resolveArray(dictGet5(pageDict, "Annots"));
|
|
777
1372
|
if (!annotsArr) continue;
|
|
778
1373
|
for (const item of annotsArr.items) {
|
|
779
1374
|
const annotDict = doc.cos.resolveDict(item);
|
|
780
1375
|
if (!annotDict) continue;
|
|
781
|
-
const subNode = doc.cos.resolve(
|
|
1376
|
+
const subNode = doc.cos.resolve(dictGet5(annotDict, "Subtype"));
|
|
782
1377
|
const subtype = subNode?.kind === "name" ? subNode.decoded : "Annot";
|
|
783
|
-
const rectArr = doc.cos.resolveArray(
|
|
1378
|
+
const rectArr = doc.cos.resolveArray(dictGet5(annotDict, "Rect"));
|
|
784
1379
|
const rectNums = rectArr ? rectArr.items.map((it) => {
|
|
785
1380
|
const r = doc.cos.resolve(it);
|
|
786
1381
|
return r?.kind === "number" ? r.value : 0;
|
|
787
1382
|
}) : [0, 0, 0, 0];
|
|
788
|
-
const flagsNode = doc.cos.resolve(
|
|
1383
|
+
const flagsNode = doc.cos.resolve(dictGet5(annotDict, "F"));
|
|
789
1384
|
const flags = flagsNode?.kind === "number" ? flagsNode.value : 0;
|
|
790
1385
|
lines.push("---");
|
|
791
1386
|
lines.push(`AnnotSubtype: ${subtype}`);
|
|
792
1387
|
lines.push(`AnnotRect: ${rectNums.slice(0, 4).join(" ")}`);
|
|
793
|
-
const nmNode = doc.cos.resolve(
|
|
1388
|
+
const nmNode = doc.cos.resolve(dictGet5(annotDict, "NM"));
|
|
794
1389
|
if (nmNode?.kind === "string") {
|
|
795
|
-
lines.push(`AnnotName: ${encodePdftkText(
|
|
1390
|
+
lines.push(`AnnotName: ${encodePdftkText(decodePdfString4(nmNode), utf8)}`);
|
|
796
1391
|
}
|
|
797
|
-
const tNode = doc.cos.resolve(
|
|
1392
|
+
const tNode = doc.cos.resolve(dictGet5(annotDict, "T"));
|
|
798
1393
|
if (tNode?.kind === "string") {
|
|
799
|
-
lines.push(`AnnotTitle: ${encodePdftkText(
|
|
1394
|
+
lines.push(`AnnotTitle: ${encodePdftkText(decodePdfString4(tNode), utf8)}`);
|
|
800
1395
|
}
|
|
801
|
-
const subjNode = doc.cos.resolve(
|
|
1396
|
+
const subjNode = doc.cos.resolve(dictGet5(annotDict, "Subj"));
|
|
802
1397
|
if (subjNode?.kind === "string") {
|
|
803
|
-
lines.push(`AnnotSubj: ${encodePdftkText(
|
|
1398
|
+
lines.push(`AnnotSubj: ${encodePdftkText(decodePdfString4(subjNode), utf8)}`);
|
|
804
1399
|
}
|
|
805
|
-
const cNode = doc.cos.resolve(
|
|
1400
|
+
const cNode = doc.cos.resolve(dictGet5(annotDict, "Contents"));
|
|
806
1401
|
if (cNode?.kind === "string") {
|
|
807
|
-
lines.push(`AnnotContents: ${encodePdftkText(
|
|
1402
|
+
lines.push(`AnnotContents: ${encodePdftkText(decodePdfString4(cNode), utf8)}`);
|
|
808
1403
|
}
|
|
809
|
-
const colArr = doc.cos.resolveArray(
|
|
1404
|
+
const colArr = doc.cos.resolveArray(dictGet5(annotDict, "C"));
|
|
810
1405
|
if (colArr && colArr.items.length >= 3) {
|
|
811
1406
|
const colNums = colArr.items.slice(0, 3).map((it) => {
|
|
812
1407
|
const r = doc.cos.resolve(it);
|
|
@@ -814,20 +1409,20 @@ function formatDumpDataAnnots(doc, utf8 = false) {
|
|
|
814
1409
|
});
|
|
815
1410
|
lines.push(`AnnotColor: ${colNums.join(" ")}`);
|
|
816
1411
|
}
|
|
817
|
-
const openNode = doc.cos.resolve(
|
|
1412
|
+
const openNode = doc.cos.resolve(dictGet5(annotDict, "Open"));
|
|
818
1413
|
if (openNode?.kind === "boolean") {
|
|
819
1414
|
lines.push(`AnnotOpen: ${openNode.value}`);
|
|
820
1415
|
}
|
|
821
|
-
const mNode = doc.cos.resolve(
|
|
1416
|
+
const mNode = doc.cos.resolve(dictGet5(annotDict, "M"));
|
|
822
1417
|
if (mNode?.kind === "string") {
|
|
823
|
-
lines.push(`AnnotModificationDate: ${encodePdftkText(
|
|
1418
|
+
lines.push(`AnnotModificationDate: ${encodePdftkText(decodePdfString4(mNode), utf8)}`);
|
|
824
1419
|
}
|
|
825
1420
|
lines.push(`AnnotFlags: ${flags}`);
|
|
826
1421
|
lines.push(`AnnotPageNumber: ${p + 1}`);
|
|
827
1422
|
const formatDestTarget = (dRaw) => {
|
|
828
1423
|
if (!dRaw) return void 0;
|
|
829
1424
|
const resolved = doc.cos.resolve(dRaw);
|
|
830
|
-
if (resolved?.kind === "string") return
|
|
1425
|
+
if (resolved?.kind === "string") return decodePdfString4(resolved);
|
|
831
1426
|
if (resolved?.kind === "name") return resolved.decoded;
|
|
832
1427
|
if (resolved?.kind === "array" && resolved.items.length > 0) {
|
|
833
1428
|
const first = resolved.items[0];
|
|
@@ -860,16 +1455,16 @@ function formatDumpDataAnnots(doc, utf8 = false) {
|
|
|
860
1455
|
}
|
|
861
1456
|
const actionDict = doc.cos.resolveDict(aNode);
|
|
862
1457
|
if (!actionDict) return;
|
|
863
|
-
const sNode = doc.cos.resolve(
|
|
1458
|
+
const sNode = doc.cos.resolve(dictGet5(actionDict, "S"));
|
|
864
1459
|
const sType = sNode?.kind === "name" ? sNode.decoded : "";
|
|
865
1460
|
if (sType) {
|
|
866
1461
|
lines.push(`AnnotActionType: ${sType}`);
|
|
867
1462
|
}
|
|
868
|
-
const uriNode = doc.cos.resolve(
|
|
1463
|
+
const uriNode = doc.cos.resolve(dictGet5(actionDict, "URI"));
|
|
869
1464
|
if (uriNode?.kind === "string") {
|
|
870
|
-
lines.push(`AnnotActionURI: ${encodePdftkText(
|
|
1465
|
+
lines.push(`AnnotActionURI: ${encodePdftkText(decodePdfString4(uriNode), utf8)}`);
|
|
871
1466
|
}
|
|
872
|
-
const dNode =
|
|
1467
|
+
const dNode = dictGet5(actionDict, "D");
|
|
873
1468
|
const destTarget = formatDestTarget(dNode);
|
|
874
1469
|
if (destTarget) {
|
|
875
1470
|
lines.push(`AnnotActionDest: ${encodePdftkText(destTarget, utf8)}`);
|
|
@@ -878,23 +1473,23 @@ function formatDumpDataAnnots(doc, utf8 = false) {
|
|
|
878
1473
|
if (resolvedIdx !== void 0) {
|
|
879
1474
|
lines.push(`AnnotActionPageNumber: ${resolvedIdx + 1}`);
|
|
880
1475
|
}
|
|
881
|
-
const fRaw = doc.cos.resolve(
|
|
1476
|
+
const fRaw = doc.cos.resolve(dictGet5(actionDict, "F"));
|
|
882
1477
|
if (fRaw?.kind === "string") {
|
|
883
|
-
lines.push(`AnnotActionFile: ${encodePdftkText(
|
|
1478
|
+
lines.push(`AnnotActionFile: ${encodePdftkText(decodePdfString4(fRaw), utf8)}`);
|
|
884
1479
|
} else if (fRaw?.kind === "dict") {
|
|
885
|
-
const ufNode = doc.cos.resolve(
|
|
1480
|
+
const ufNode = doc.cos.resolve(dictGet5(fRaw, "UF") ?? dictGet5(fRaw, "F"));
|
|
886
1481
|
if (ufNode?.kind === "string") {
|
|
887
|
-
lines.push(`AnnotActionFile: ${encodePdftkText(
|
|
1482
|
+
lines.push(`AnnotActionFile: ${encodePdftkText(decodePdfString4(ufNode), utf8)}`);
|
|
888
1483
|
}
|
|
889
1484
|
}
|
|
890
|
-
emitActionChain(
|
|
1485
|
+
emitActionChain(dictGet5(actionDict, "Next"), visited);
|
|
891
1486
|
};
|
|
892
|
-
const rawA =
|
|
1487
|
+
const rawA = dictGet5(annotDict, "A");
|
|
893
1488
|
if (rawA) {
|
|
894
1489
|
emitActionChain(rawA);
|
|
895
|
-
} else if (
|
|
1490
|
+
} else if (dictGet5(annotDict, "Dest")) {
|
|
896
1491
|
lines.push("AnnotActionType: GoTo");
|
|
897
|
-
const dNode =
|
|
1492
|
+
const dNode = dictGet5(annotDict, "Dest");
|
|
898
1493
|
const destTarget = formatDestTarget(dNode);
|
|
899
1494
|
if (destTarget) {
|
|
900
1495
|
lines.push(`AnnotActionDest: ${encodePdftkText(destTarget, utf8)}`);
|
|
@@ -940,18 +1535,18 @@ function collectOutlineBookmarks(doc, firstNode, level, out, visited = /* @__PUR
|
|
|
940
1535
|
}
|
|
941
1536
|
const dict = doc.cos.resolveDict(curr);
|
|
942
1537
|
if (!dict) break;
|
|
943
|
-
const titleNode = doc.cos.resolve(
|
|
944
|
-
const title = titleNode?.kind === "string" ?
|
|
945
|
-
const resolvedIdx = resolveDestinationPageIndex(doc,
|
|
1538
|
+
const titleNode = doc.cos.resolve(dictGet5(dict, "Title"));
|
|
1539
|
+
const title = titleNode?.kind === "string" ? decodePdfString4(titleNode) : titleNode?.kind === "name" ? titleNode.decoded : "";
|
|
1540
|
+
const resolvedIdx = resolveDestinationPageIndex(doc, dictGet5(dict, "Dest") ?? dictGet5(dict, "A"));
|
|
946
1541
|
const pageNumber = resolvedIdx !== void 0 ? resolvedIdx + 1 : 1;
|
|
947
1542
|
if (title) {
|
|
948
1543
|
out.push({ title, level, pageNumber });
|
|
949
1544
|
}
|
|
950
|
-
const childFirst =
|
|
1545
|
+
const childFirst = dictGet5(dict, "First");
|
|
951
1546
|
if (childFirst) {
|
|
952
1547
|
collectOutlineBookmarks(doc, childFirst, level + 1, out, visited);
|
|
953
1548
|
}
|
|
954
|
-
curr =
|
|
1549
|
+
curr = dictGet5(dict, "Next");
|
|
955
1550
|
}
|
|
956
1551
|
}
|
|
957
1552
|
function collectNameTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ new Set()) {
|
|
@@ -962,16 +1557,16 @@ function collectNameTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ new
|
|
|
962
1557
|
}
|
|
963
1558
|
const dict = doc.cos.resolveDict(nodeOrRef);
|
|
964
1559
|
if (!dict) return;
|
|
965
|
-
const namesArr = doc.cos.resolveArray(
|
|
1560
|
+
const namesArr = doc.cos.resolveArray(dictGet5(dict, "Names"));
|
|
966
1561
|
if (namesArr) {
|
|
967
1562
|
for (let i = 0; i + 1 < namesArr.items.length; i += 2) {
|
|
968
1563
|
const k = doc.cos.resolve(namesArr.items[i]);
|
|
969
1564
|
const v = namesArr.items[i + 1];
|
|
970
|
-
const name = k?.kind === "string" ?
|
|
1565
|
+
const name = k?.kind === "string" ? decodePdfString4(k) : "attachment.bin";
|
|
971
1566
|
out.push({ name, value: v });
|
|
972
1567
|
}
|
|
973
1568
|
}
|
|
974
|
-
const kidsArr = doc.cos.resolveArray(
|
|
1569
|
+
const kidsArr = doc.cos.resolveArray(dictGet5(dict, "Kids"));
|
|
975
1570
|
if (kidsArr) {
|
|
976
1571
|
for (const kid of kidsArr.items) {
|
|
977
1572
|
collectNameTreePairs(doc, kid, out, visited);
|
|
@@ -986,7 +1581,7 @@ function collectNumberTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ n
|
|
|
986
1581
|
}
|
|
987
1582
|
const dict = doc.cos.resolveDict(nodeOrRef);
|
|
988
1583
|
if (!dict) return;
|
|
989
|
-
const numsArr = doc.cos.resolveArray(
|
|
1584
|
+
const numsArr = doc.cos.resolveArray(dictGet5(dict, "Nums"));
|
|
990
1585
|
if (numsArr) {
|
|
991
1586
|
for (let i = 0; i + 1 < numsArr.items.length; i += 2) {
|
|
992
1587
|
const k = doc.cos.resolve(numsArr.items[i]);
|
|
@@ -996,7 +1591,7 @@ function collectNumberTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ n
|
|
|
996
1591
|
}
|
|
997
1592
|
}
|
|
998
1593
|
}
|
|
999
|
-
const kidsArr = doc.cos.resolveArray(
|
|
1594
|
+
const kidsArr = doc.cos.resolveArray(dictGet5(dict, "Kids"));
|
|
1000
1595
|
if (kidsArr) {
|
|
1001
1596
|
for (const kid of kidsArr.items) {
|
|
1002
1597
|
collectNumberTreePairs(doc, kid, out, visited);
|
|
@@ -1050,7 +1645,7 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
1050
1645
|
if (emittedKeys.has(k)) continue;
|
|
1051
1646
|
const r = doc.cos.resolve(entry.value);
|
|
1052
1647
|
if (r?.kind === "string") {
|
|
1053
|
-
const val =
|
|
1648
|
+
const val = decodePdfString4(r);
|
|
1054
1649
|
if (val) {
|
|
1055
1650
|
emittedKeys.add(k);
|
|
1056
1651
|
lines.push(
|
|
@@ -1071,10 +1666,10 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
1071
1666
|
lines.push(`PdfID1: ${id1Hex}`);
|
|
1072
1667
|
lines.push(`NumberOfPages: ${doc.pageCount}`);
|
|
1073
1668
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
1074
|
-
const outlinesDict = catalog ? doc.cos.resolveDict(
|
|
1669
|
+
const outlinesDict = catalog ? doc.cos.resolveDict(dictGet5(catalog, "Outlines")) : void 0;
|
|
1075
1670
|
if (outlinesDict) {
|
|
1076
1671
|
const bookmarks = [];
|
|
1077
|
-
collectOutlineBookmarks(doc,
|
|
1672
|
+
collectOutlineBookmarks(doc, dictGet5(outlinesDict, "First"), 1, bookmarks);
|
|
1078
1673
|
for (const bm of bookmarks) {
|
|
1079
1674
|
lines.push(
|
|
1080
1675
|
"BookmarkBegin",
|
|
@@ -1088,7 +1683,7 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
1088
1683
|
const page = doc.getPage(i);
|
|
1089
1684
|
const { width, height } = page.getSize();
|
|
1090
1685
|
const rot = page.getRotation();
|
|
1091
|
-
const mbArr = doc.cos.resolveArray(
|
|
1686
|
+
const mbArr = doc.cos.resolveArray(dictGet5(page.pageDict, "MediaBox"));
|
|
1092
1687
|
let mbRectStr = `0 0 ${width} ${height}`;
|
|
1093
1688
|
if (mbArr && mbArr.items.length >= 4) {
|
|
1094
1689
|
const mbNums = mbArr.items.slice(0, 4).map((item) => {
|
|
@@ -1104,7 +1699,7 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
1104
1699
|
`PageMediaRect: ${mbRectStr}`,
|
|
1105
1700
|
`PageMediaDimensions: ${width} ${height}`
|
|
1106
1701
|
);
|
|
1107
|
-
const cbArr = doc.cos.resolveArray(
|
|
1702
|
+
const cbArr = doc.cos.resolveArray(dictGet5(page.pageDict, "CropBox"));
|
|
1108
1703
|
if (cbArr && cbArr.items.length >= 4) {
|
|
1109
1704
|
const nums = cbArr.items.slice(0, 4).map((item) => {
|
|
1110
1705
|
const r = doc.cos.resolve(item);
|
|
@@ -1116,17 +1711,17 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
1116
1711
|
}
|
|
1117
1712
|
const pageLabelsPairs = [];
|
|
1118
1713
|
if (catalog) {
|
|
1119
|
-
collectNumberTreePairs(doc,
|
|
1714
|
+
collectNumberTreePairs(doc, dictGet5(catalog, "PageLabels"), pageLabelsPairs);
|
|
1120
1715
|
}
|
|
1121
1716
|
for (const pair of pageLabelsPairs) {
|
|
1122
1717
|
const lblDict = doc.cos.resolveDict(pair.value);
|
|
1123
1718
|
if (lblDict) {
|
|
1124
1719
|
const newIndex = Math.max(1, pair.num + 1);
|
|
1125
|
-
const stNode = doc.cos.resolve(
|
|
1720
|
+
const stNode = doc.cos.resolve(dictGet5(lblDict, "St"));
|
|
1126
1721
|
const startNum = stNode?.kind === "number" ? stNode.value : 1;
|
|
1127
|
-
const pNode = doc.cos.resolve(
|
|
1128
|
-
const prefix = pNode?.kind === "string" ?
|
|
1129
|
-
const sNode = doc.cos.resolve(
|
|
1722
|
+
const pNode = doc.cos.resolve(dictGet5(lblDict, "P"));
|
|
1723
|
+
const prefix = pNode?.kind === "string" ? decodePdfString4(pNode) : void 0;
|
|
1724
|
+
const sNode = doc.cos.resolve(dictGet5(lblDict, "S"));
|
|
1130
1725
|
const styleCode = sNode?.kind === "name" ? sNode.decoded : "";
|
|
1131
1726
|
const numStyle = PDF_TO_PAGE_LABEL_STYLE[styleCode] ?? "NoNumber";
|
|
1132
1727
|
lines.push(
|
|
@@ -1157,23 +1752,23 @@ function formatGenerateFdf(doc) {
|
|
|
1157
1752
|
}
|
|
1158
1753
|
return `(${escapeFdfString(String(f.value ?? ""))})`;
|
|
1159
1754
|
}
|
|
1160
|
-
const vNode = doc.cos.resolve(
|
|
1755
|
+
const vNode = doc.cos.resolve(dictGet5(dict, "V"));
|
|
1161
1756
|
if (vNode?.kind === "name") return `/${vNode.decoded}`;
|
|
1162
|
-
if (vNode?.kind === "string") return `(${escapeFdfString(
|
|
1757
|
+
if (vNode?.kind === "string") return `(${escapeFdfString(decodePdfString4(vNode))})`;
|
|
1163
1758
|
return "()";
|
|
1164
1759
|
};
|
|
1165
1760
|
const serializeCosFieldNode = (nodeOrRef, prefix) => {
|
|
1166
1761
|
const dict = doc.cos.resolveDict(nodeOrRef);
|
|
1167
1762
|
if (!dict) return void 0;
|
|
1168
|
-
const tNode = doc.cos.resolve(
|
|
1169
|
-
const partialName = tNode?.kind === "string" ?
|
|
1763
|
+
const tNode = doc.cos.resolve(dictGet5(dict, "T"));
|
|
1764
|
+
const partialName = tNode?.kind === "string" ? decodePdfString4(tNode) : "";
|
|
1170
1765
|
const fullName = prefix && partialName ? `${prefix}.${partialName}` : partialName || prefix;
|
|
1171
|
-
const kidsArr = doc.cos.resolveArray(
|
|
1766
|
+
const kidsArr = doc.cos.resolveArray(dictGet5(dict, "Kids"));
|
|
1172
1767
|
const namedKids = [];
|
|
1173
1768
|
if (kidsArr) {
|
|
1174
1769
|
for (const k of kidsArr.items) {
|
|
1175
1770
|
const kDict = doc.cos.resolveDict(k);
|
|
1176
|
-
if (kDict &&
|
|
1771
|
+
if (kDict && dictGet5(kDict, "T")) {
|
|
1177
1772
|
const serializedKid = serializeCosFieldNode(k, fullName);
|
|
1178
1773
|
if (serializedKid) namedKids.push(serializedKid);
|
|
1179
1774
|
}
|
|
@@ -1187,8 +1782,8 @@ function formatGenerateFdf(doc) {
|
|
|
1187
1782
|
};
|
|
1188
1783
|
const entries = [];
|
|
1189
1784
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
1190
|
-
const acroForm = catalog ? doc.cos.resolveDict(
|
|
1191
|
-
const fieldsArr = acroForm ? doc.cos.resolveArray(
|
|
1785
|
+
const acroForm = catalog ? doc.cos.resolveDict(dictGet5(catalog, "AcroForm")) : void 0;
|
|
1786
|
+
const fieldsArr = acroForm ? doc.cos.resolveArray(dictGet5(acroForm, "Fields")) : void 0;
|
|
1192
1787
|
if (fieldsArr && fieldsArr.items.length > 0) {
|
|
1193
1788
|
for (const item of fieldsArr.items) {
|
|
1194
1789
|
const s = serializeCosFieldNode(item, "");
|
|
@@ -1196,7 +1791,7 @@ function formatGenerateFdf(doc) {
|
|
|
1196
1791
|
}
|
|
1197
1792
|
} else {
|
|
1198
1793
|
for (const f of fields) {
|
|
1199
|
-
entries.push(`<< /T (${escapeFdfString(f.name)}) /V ${formatFieldVal(f.name,
|
|
1794
|
+
entries.push(`<< /T (${escapeFdfString(f.name)}) /V ${formatFieldVal(f.name, cosDict3({}))} >>`);
|
|
1200
1795
|
}
|
|
1201
1796
|
}
|
|
1202
1797
|
return `%FDF-1.2
|
|
@@ -1214,9 +1809,9 @@ function setDocumentBookmarks(doc, bookmarks) {
|
|
|
1214
1809
|
if (bookmarks.length === 0 || doc.pageCount === 0) return;
|
|
1215
1810
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
1216
1811
|
if (!catalog) return;
|
|
1217
|
-
const outlinesDict =
|
|
1812
|
+
const outlinesDict = cosDict3({ Type: cosName("Outlines") });
|
|
1218
1813
|
const outlinesRef = doc.cos.allocateObject(outlinesDict);
|
|
1219
|
-
|
|
1814
|
+
dictSet2(catalog, "Outlines", outlinesRef);
|
|
1220
1815
|
const stack = [{ ref: outlinesRef, dict: outlinesDict, children: [] }];
|
|
1221
1816
|
for (const bm of bookmarks) {
|
|
1222
1817
|
const targetLevel = Math.max(1, bm.level);
|
|
@@ -1235,22 +1830,22 @@ function setDocumentBookmarks(doc, bookmarks) {
|
|
|
1235
1830
|
const parentState = stack[stack.length - 1];
|
|
1236
1831
|
const pageIdx = Math.max(0, Math.min(doc.pageCount - 1, bm.pageNumber - 1));
|
|
1237
1832
|
const pageRef = doc.getPage(pageIdx).ref;
|
|
1238
|
-
const itemDict =
|
|
1239
|
-
Title:
|
|
1833
|
+
const itemDict = cosDict3({
|
|
1834
|
+
Title: cosString3(bm.title),
|
|
1240
1835
|
Parent: parentState.ref,
|
|
1241
|
-
Dest:
|
|
1836
|
+
Dest: cosArray3([pageRef, cosName("XYZ"), { kind: "null" }, { kind: "null" }, { kind: "null" }])
|
|
1242
1837
|
});
|
|
1243
1838
|
const itemRef = doc.cos.allocateObject(itemDict);
|
|
1244
1839
|
const prevSibling = parentState.children[parentState.children.length - 1];
|
|
1245
1840
|
if (prevSibling) {
|
|
1246
|
-
|
|
1247
|
-
|
|
1841
|
+
dictSet2(prevSibling.dict, "Next", itemRef);
|
|
1842
|
+
dictSet2(itemDict, "Prev", prevSibling.ref);
|
|
1248
1843
|
} else {
|
|
1249
|
-
|
|
1844
|
+
dictSet2(parentState.dict, "First", itemRef);
|
|
1250
1845
|
}
|
|
1251
|
-
|
|
1846
|
+
dictSet2(parentState.dict, "Last", itemRef);
|
|
1252
1847
|
parentState.children.push({ ref: itemRef, dict: itemDict });
|
|
1253
|
-
|
|
1848
|
+
dictSet2(parentState.dict, "Count", cosNumber3(parentState.children.length));
|
|
1254
1849
|
}
|
|
1255
1850
|
}
|
|
1256
1851
|
function applyUpdateInfoText(doc, text) {
|
|
@@ -1341,7 +1936,7 @@ function applyUpdateInfoText(doc, text) {
|
|
|
1341
1936
|
}
|
|
1342
1937
|
const infoDict = doc.cos.infoRef ? doc.cos.resolveDict(doc.cos.infoRef) : void 0;
|
|
1343
1938
|
if (infoDict) {
|
|
1344
|
-
|
|
1939
|
+
dictSet2(infoDict, curKey, cosString3(val));
|
|
1345
1940
|
}
|
|
1346
1941
|
}
|
|
1347
1942
|
mode = "none";
|
|
@@ -1388,7 +1983,7 @@ function applyUpdateInfoText(doc, text) {
|
|
|
1388
1983
|
const existing1 = doc.cos.idArray?.items[1] && doc.cos.resolve(doc.cos.idArray.items[1])?.kind === "string" ? doc.cos.resolve(doc.cos.idArray.items[1]).bytes : existing0;
|
|
1389
1984
|
const b0 = pdfId0Hex !== void 0 ? hexToBytes(pdfId0Hex) : existing0;
|
|
1390
1985
|
const b1 = pdfId1Hex !== void 0 ? hexToBytes(pdfId1Hex) : existing1;
|
|
1391
|
-
doc.cos.idArray =
|
|
1986
|
+
doc.cos.idArray = cosArray3([cosHexString(b0), cosHexString(b1)]);
|
|
1392
1987
|
}
|
|
1393
1988
|
for (const [pageNum, rot] of pageRotations.entries()) {
|
|
1394
1989
|
if (pageNum >= 1 && pageNum <= doc.pageCount) {
|
|
@@ -1397,28 +1992,28 @@ function applyUpdateInfoText(doc, text) {
|
|
|
1397
1992
|
}
|
|
1398
1993
|
for (const [pageNum, [w, h]] of pageDimensions.entries()) {
|
|
1399
1994
|
if (pageNum >= 1 && pageNum <= doc.pageCount) {
|
|
1400
|
-
|
|
1995
|
+
dictSet2(
|
|
1401
1996
|
doc.getPage(pageNum - 1).pageDict,
|
|
1402
1997
|
"MediaBox",
|
|
1403
|
-
|
|
1998
|
+
cosArray3([cosNumber3(0), cosNumber3(0), cosNumber3(w), cosNumber3(h)])
|
|
1404
1999
|
);
|
|
1405
2000
|
}
|
|
1406
2001
|
}
|
|
1407
2002
|
for (const [pageNum, [x0, y0, x1, y1]] of pageMediaRects.entries()) {
|
|
1408
2003
|
if (pageNum >= 1 && pageNum <= doc.pageCount) {
|
|
1409
|
-
|
|
2004
|
+
dictSet2(
|
|
1410
2005
|
doc.getPage(pageNum - 1).pageDict,
|
|
1411
2006
|
"MediaBox",
|
|
1412
|
-
|
|
2007
|
+
cosArray3([cosNumber3(x0), cosNumber3(y0), cosNumber3(x1), cosNumber3(y1)])
|
|
1413
2008
|
);
|
|
1414
2009
|
}
|
|
1415
2010
|
}
|
|
1416
2011
|
for (const [pageNum, [x0, y0, x1, y1]] of pageCropBoxes.entries()) {
|
|
1417
2012
|
if (pageNum >= 1 && pageNum <= doc.pageCount) {
|
|
1418
|
-
|
|
2013
|
+
dictSet2(
|
|
1419
2014
|
doc.getPage(pageNum - 1).pageDict,
|
|
1420
2015
|
"CropBox",
|
|
1421
|
-
|
|
2016
|
+
cosArray3([cosNumber3(x0), cosNumber3(y0), cosNumber3(x1), cosNumber3(y1)])
|
|
1422
2017
|
);
|
|
1423
2018
|
}
|
|
1424
2019
|
}
|
|
@@ -1427,21 +2022,21 @@ function applyUpdateInfoText(doc, text) {
|
|
|
1427
2022
|
if (catalog) {
|
|
1428
2023
|
const numsItems = [];
|
|
1429
2024
|
for (const pl of pageLabels) {
|
|
1430
|
-
numsItems.push(
|
|
2025
|
+
numsItems.push(cosNumber3(Math.max(0, pl.newIndex - 1)));
|
|
1431
2026
|
const lblEntries = {
|
|
1432
|
-
St:
|
|
2027
|
+
St: cosNumber3(pl.start)
|
|
1433
2028
|
};
|
|
1434
2029
|
if (pl.prefix) {
|
|
1435
|
-
lblEntries.P =
|
|
2030
|
+
lblEntries.P = cosString3(pl.prefix);
|
|
1436
2031
|
}
|
|
1437
2032
|
const pdfStyle = PAGE_LABEL_STYLE_TO_PDF[pl.style];
|
|
1438
2033
|
if (pdfStyle) {
|
|
1439
2034
|
lblEntries.S = cosName(pdfStyle);
|
|
1440
2035
|
}
|
|
1441
|
-
numsItems.push(
|
|
2036
|
+
numsItems.push(cosDict3(lblEntries));
|
|
1442
2037
|
}
|
|
1443
|
-
const plDict =
|
|
1444
|
-
|
|
2038
|
+
const plDict = cosDict3({ Nums: cosArray3(numsItems) });
|
|
2039
|
+
dictSet2(catalog, "PageLabels", doc.cos.allocateObject(plDict));
|
|
1445
2040
|
}
|
|
1446
2041
|
}
|
|
1447
2042
|
setDocumentBookmarks(doc, bookmarks);
|
|
@@ -1449,20 +2044,20 @@ function applyUpdateInfoText(doc, text) {
|
|
|
1449
2044
|
function attachFilesToDocument(doc, filePaths, files, toPageSpec) {
|
|
1450
2045
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
1451
2046
|
if (!catalog) return;
|
|
1452
|
-
let namesDict = doc.cos.resolveDict(
|
|
2047
|
+
let namesDict = doc.cos.resolveDict(dictGet5(catalog, "Names"));
|
|
1453
2048
|
if (!namesDict) {
|
|
1454
|
-
namesDict =
|
|
1455
|
-
|
|
2049
|
+
namesDict = cosDict3({});
|
|
2050
|
+
dictSet2(catalog, "Names", doc.cos.allocateObject(namesDict));
|
|
1456
2051
|
}
|
|
1457
|
-
let efTree = doc.cos.resolveDict(
|
|
2052
|
+
let efTree = doc.cos.resolveDict(dictGet5(namesDict, "EmbeddedFiles"));
|
|
1458
2053
|
if (!efTree) {
|
|
1459
|
-
efTree =
|
|
1460
|
-
|
|
2054
|
+
efTree = cosDict3({ Names: cosArray3([]) });
|
|
2055
|
+
dictSet2(namesDict, "EmbeddedFiles", doc.cos.allocateObject(efTree));
|
|
1461
2056
|
}
|
|
1462
|
-
let namesArr = doc.cos.resolveArray(
|
|
2057
|
+
let namesArr = doc.cos.resolveArray(dictGet5(efTree, "Names"));
|
|
1463
2058
|
if (!namesArr) {
|
|
1464
|
-
namesArr =
|
|
1465
|
-
|
|
2059
|
+
namesArr = cosArray3([]);
|
|
2060
|
+
dictSet2(efTree, "Names", namesArr);
|
|
1466
2061
|
}
|
|
1467
2062
|
const targetPageIdx = toPageSpec !== void 0 && doc.pageCount > 0 ? toPageSpec.toLowerCase() === "end" ? doc.pageCount - 1 : Math.max(0, Math.min(doc.pageCount - 1, (Number.parseInt(toPageSpec, 10) || 1) - 1)) : void 0;
|
|
1468
2063
|
for (const fp of filePaths) {
|
|
@@ -1471,34 +2066,34 @@ function attachFilesToDocument(doc, filePaths, files, toPageSpec) {
|
|
|
1471
2066
|
const baseName = fp.slice(fp.lastIndexOf("/") + 1);
|
|
1472
2067
|
const efStreamRef = doc.cos.allocateObject(
|
|
1473
2068
|
cosStream(bytes, {
|
|
1474
|
-
dict:
|
|
2069
|
+
dict: cosDict3({ Type: cosName("EmbeddedFile") }),
|
|
1475
2070
|
compress: true
|
|
1476
2071
|
})
|
|
1477
2072
|
);
|
|
1478
2073
|
const filespecRef = doc.cos.allocateObject(
|
|
1479
|
-
|
|
2074
|
+
cosDict3({
|
|
1480
2075
|
Type: cosName("Filespec"),
|
|
1481
|
-
F:
|
|
1482
|
-
UF:
|
|
1483
|
-
EF:
|
|
2076
|
+
F: cosString3(baseName),
|
|
2077
|
+
UF: cosString3(baseName),
|
|
2078
|
+
EF: cosDict3({ F: efStreamRef })
|
|
1484
2079
|
})
|
|
1485
2080
|
);
|
|
1486
|
-
namesArr.items.push(
|
|
2081
|
+
namesArr.items.push(cosString3(baseName), filespecRef);
|
|
1487
2082
|
if (targetPageIdx !== void 0) {
|
|
1488
2083
|
const pageDict = doc.getPage(targetPageIdx).pageDict;
|
|
1489
|
-
let annotsArr = doc.cos.resolveArray(
|
|
2084
|
+
let annotsArr = doc.cos.resolveArray(dictGet5(pageDict, "Annots"));
|
|
1490
2085
|
if (!annotsArr) {
|
|
1491
|
-
annotsArr =
|
|
1492
|
-
|
|
2086
|
+
annotsArr = cosArray3([]);
|
|
2087
|
+
dictSet2(pageDict, "Annots", annotsArr);
|
|
1493
2088
|
}
|
|
1494
2089
|
const annotRef = doc.cos.allocateObject(
|
|
1495
|
-
|
|
2090
|
+
cosDict3({
|
|
1496
2091
|
Type: cosName("Annot"),
|
|
1497
2092
|
Subtype: cosName("FileAttachment"),
|
|
1498
2093
|
Name: cosName("PushPin"),
|
|
1499
|
-
Contents:
|
|
2094
|
+
Contents: cosString3(baseName),
|
|
1500
2095
|
FS: filespecRef,
|
|
1501
|
-
Rect:
|
|
2096
|
+
Rect: cosArray3([cosNumber3(20), cosNumber3(20), cosNumber3(40), cosNumber3(40)])
|
|
1502
2097
|
})
|
|
1503
2098
|
);
|
|
1504
2099
|
annotsArr.items.push(annotRef);
|
|
@@ -1515,11 +2110,11 @@ function attachmentBasename(name) {
|
|
|
1515
2110
|
function unpackFilesFromDocument(doc, outDir, files) {
|
|
1516
2111
|
const cleanDir = outDir.endsWith("/") ? outDir.slice(0, -1) : outDir;
|
|
1517
2112
|
const writeSpecDict = (specDict, fallbackName = "attachment.bin") => {
|
|
1518
|
-
const ufNode = doc.cos.resolve(
|
|
1519
|
-
const fileName = attachmentBasename(ufNode?.kind === "string" ?
|
|
1520
|
-
const efDict = doc.cos.resolveDict(
|
|
2113
|
+
const ufNode = doc.cos.resolve(dictGet5(specDict, "UF") ?? dictGet5(specDict, "F"));
|
|
2114
|
+
const fileName = attachmentBasename(ufNode?.kind === "string" ? decodePdfString4(ufNode) : fallbackName);
|
|
2115
|
+
const efDict = doc.cos.resolveDict(dictGet5(specDict, "EF"));
|
|
1521
2116
|
const fStream = efDict ? doc.cos.resolve(
|
|
1522
|
-
|
|
2117
|
+
dictGet5(efDict, "UF") ?? dictGet5(efDict, "F") ?? dictGet5(efDict, "DOS") ?? dictGet5(efDict, "Mac") ?? dictGet5(efDict, "Unix")
|
|
1523
2118
|
) : void 0;
|
|
1524
2119
|
if (fStream?.kind === "stream") {
|
|
1525
2120
|
const decoded = doc.cos.decodeStream(fStream);
|
|
@@ -1529,10 +2124,10 @@ function unpackFilesFromDocument(doc, outDir, files) {
|
|
|
1529
2124
|
};
|
|
1530
2125
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
1531
2126
|
if (catalog) {
|
|
1532
|
-
const namesDict = doc.cos.resolveDict(
|
|
2127
|
+
const namesDict = doc.cos.resolveDict(dictGet5(catalog, "Names"));
|
|
1533
2128
|
const efPairs = [];
|
|
1534
2129
|
if (namesDict) {
|
|
1535
|
-
collectNameTreePairs(doc,
|
|
2130
|
+
collectNameTreePairs(doc, dictGet5(namesDict, "EmbeddedFiles"), efPairs);
|
|
1536
2131
|
}
|
|
1537
2132
|
for (const pair of efPairs) {
|
|
1538
2133
|
const specDict = doc.cos.resolveDict(pair.value);
|
|
@@ -1540,7 +2135,7 @@ function unpackFilesFromDocument(doc, outDir, files) {
|
|
|
1540
2135
|
writeSpecDict(specDict, pair.name);
|
|
1541
2136
|
}
|
|
1542
2137
|
}
|
|
1543
|
-
const rootAfArr = doc.cos.resolveArray(
|
|
2138
|
+
const rootAfArr = doc.cos.resolveArray(dictGet5(catalog, "AF"));
|
|
1544
2139
|
if (rootAfArr) {
|
|
1545
2140
|
for (const item of rootAfArr.items) {
|
|
1546
2141
|
const specDict = doc.cos.resolveDict(item);
|
|
@@ -1549,69 +2144,32 @@ function unpackFilesFromDocument(doc, outDir, files) {
|
|
|
1549
2144
|
}
|
|
1550
2145
|
}
|
|
1551
2146
|
for (let p = 0; p < doc.pageCount; p++) {
|
|
1552
|
-
const pageAfArr = doc.cos.resolveArray(
|
|
2147
|
+
const pageAfArr = doc.cos.resolveArray(dictGet5(doc.getPage(p).pageDict, "AF"));
|
|
1553
2148
|
if (pageAfArr) {
|
|
1554
2149
|
for (const item of pageAfArr.items) {
|
|
1555
2150
|
const specDict = doc.cos.resolveDict(item);
|
|
1556
2151
|
if (specDict) writeSpecDict(specDict);
|
|
1557
2152
|
}
|
|
1558
2153
|
}
|
|
1559
|
-
const annotsArr = doc.cos.resolveArray(
|
|
2154
|
+
const annotsArr = doc.cos.resolveArray(dictGet5(doc.getPage(p).pageDict, "Annots"));
|
|
1560
2155
|
if (!annotsArr) continue;
|
|
1561
2156
|
for (const item of annotsArr.items) {
|
|
1562
2157
|
const annotDict = doc.cos.resolveDict(item);
|
|
1563
2158
|
if (!annotDict) continue;
|
|
1564
|
-
const subNode = doc.cos.resolve(
|
|
2159
|
+
const subNode = doc.cos.resolve(dictGet5(annotDict, "Subtype"));
|
|
1565
2160
|
if (subNode?.kind === "name" && subNode.decoded === "FileAttachment") {
|
|
1566
|
-
const specDict = doc.cos.resolveDict(
|
|
2161
|
+
const specDict = doc.cos.resolveDict(dictGet5(annotDict, "FS"));
|
|
1567
2162
|
if (specDict) writeSpecDict(specDict);
|
|
1568
2163
|
}
|
|
1569
2164
|
}
|
|
1570
2165
|
}
|
|
1571
2166
|
}
|
|
1572
|
-
function formatBurstFilename(pattern, pageNum) {
|
|
1573
|
-
let out = "";
|
|
1574
|
-
let replaced = false;
|
|
1575
|
-
for (let i = 0; i < pattern.length; i++) {
|
|
1576
|
-
if (pattern[i] !== "%") {
|
|
1577
|
-
out += pattern[i];
|
|
1578
|
-
continue;
|
|
1579
|
-
}
|
|
1580
|
-
if (pattern[i + 1] === "%") {
|
|
1581
|
-
out += "%";
|
|
1582
|
-
i++;
|
|
1583
|
-
continue;
|
|
1584
|
-
}
|
|
1585
|
-
if (!replaced) {
|
|
1586
|
-
let j = i + 1;
|
|
1587
|
-
let zeroPad = false;
|
|
1588
|
-
if (pattern[j] === "0") {
|
|
1589
|
-
zeroPad = true;
|
|
1590
|
-
j++;
|
|
1591
|
-
}
|
|
1592
|
-
let widthStr = "";
|
|
1593
|
-
while (j < pattern.length && pattern[j] >= "0" && pattern[j] <= "9") {
|
|
1594
|
-
widthStr += pattern[j];
|
|
1595
|
-
j++;
|
|
1596
|
-
}
|
|
1597
|
-
if (pattern[j] === "d") {
|
|
1598
|
-
const width = widthStr ? Number.parseInt(widthStr, 10) : 1;
|
|
1599
|
-
out += zeroPad ? String(pageNum).padStart(width, "0") : String(pageNum);
|
|
1600
|
-
replaced = true;
|
|
1601
|
-
i = j;
|
|
1602
|
-
continue;
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
out += "%";
|
|
1606
|
-
}
|
|
1607
|
-
return out;
|
|
1608
|
-
}
|
|
1609
2167
|
function cloneCosSubgraphInto(srcDoc, dstDoc, node, memo = /* @__PURE__ */ new Map()) {
|
|
1610
2168
|
if (!node) return void 0;
|
|
1611
2169
|
if (node.kind === "ref") {
|
|
1612
2170
|
const cached = memo.get(node.objectNumber);
|
|
1613
2171
|
if (cached) return cached;
|
|
1614
|
-
const placeholder = dstDoc.cos.allocateObject(
|
|
2172
|
+
const placeholder = dstDoc.cos.allocateObject(cosDict3({}));
|
|
1615
2173
|
memo.set(node.objectNumber, placeholder);
|
|
1616
2174
|
const resolved = srcDoc.cos.resolve(node);
|
|
1617
2175
|
const cloned = cloneCosSubgraphInto(srcDoc, dstDoc, resolved, memo);
|
|
@@ -1625,14 +2183,14 @@ function cloneCosSubgraphInto(srcDoc, dstDoc, node, memo = /* @__PURE__ */ new M
|
|
|
1625
2183
|
return placeholder;
|
|
1626
2184
|
}
|
|
1627
2185
|
if (node.kind === "array") {
|
|
1628
|
-
return
|
|
2186
|
+
return cosArray3(node.items.map((it) => cloneCosSubgraphInto(srcDoc, dstDoc, it, memo)).filter(Boolean));
|
|
1629
2187
|
}
|
|
1630
2188
|
if (node.kind === "dict") {
|
|
1631
|
-
const next =
|
|
2189
|
+
const next = cosDict3({});
|
|
1632
2190
|
for (const entry of node.entries) {
|
|
1633
2191
|
if (entry.key.decoded === "Parent") continue;
|
|
1634
2192
|
const clonedVal = cloneCosSubgraphInto(srcDoc, dstDoc, entry.value, memo);
|
|
1635
|
-
if (clonedVal)
|
|
2193
|
+
if (clonedVal) dictSet2(next, entry.key.decoded, clonedVal);
|
|
1636
2194
|
}
|
|
1637
2195
|
return next;
|
|
1638
2196
|
}
|
|
@@ -1697,31 +2255,31 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
|
|
|
1697
2255
|
const srcRes = srcPage.getResourcesDict();
|
|
1698
2256
|
const renamedResources = /* @__PURE__ */ new Map();
|
|
1699
2257
|
for (const subKey of ["Font", "XObject", "ExtGState", "ColorSpace", "Pattern", "Shading", "Properties"]) {
|
|
1700
|
-
const srcSub = overlayDoc.cos.resolveDict(
|
|
2258
|
+
const srcSub = overlayDoc.cos.resolveDict(dictGet5(srcRes, subKey));
|
|
1701
2259
|
if (!srcSub) continue;
|
|
1702
|
-
let dstSub = targetDoc.cos.resolveDict(
|
|
2260
|
+
let dstSub = targetDoc.cos.resolveDict(dictGet5(dstRes, subKey));
|
|
1703
2261
|
if (!dstSub) {
|
|
1704
|
-
dstSub =
|
|
1705
|
-
|
|
2262
|
+
dstSub = cosDict3({});
|
|
2263
|
+
dictSet2(dstRes, subKey, dstSub);
|
|
1706
2264
|
}
|
|
1707
2265
|
for (const entry of srcSub.entries) {
|
|
1708
2266
|
const origKey = entry.key.decoded;
|
|
1709
2267
|
const cloned = cloneCosSubgraphInto(overlayDoc, targetDoc, entry.value, memo);
|
|
1710
2268
|
if (!cloned) continue;
|
|
1711
|
-
if (!
|
|
1712
|
-
|
|
2269
|
+
if (!dictGet5(dstSub, origKey)) {
|
|
2270
|
+
dictSet2(dstSub, origKey, cloned);
|
|
1713
2271
|
} else {
|
|
1714
2272
|
let newKey = `Ov_${i}_${origKey}`;
|
|
1715
2273
|
let suffix = 1;
|
|
1716
|
-
while (
|
|
2274
|
+
while (dictGet5(dstSub, newKey)) {
|
|
1717
2275
|
newKey = `Ov_${i}_${suffix++}_${origKey}`;
|
|
1718
2276
|
}
|
|
1719
|
-
|
|
2277
|
+
dictSet2(dstSub, newKey, cloned);
|
|
1720
2278
|
renamedResources.set(origKey, newKey);
|
|
1721
2279
|
}
|
|
1722
2280
|
}
|
|
1723
2281
|
}
|
|
1724
|
-
const srcContents =
|
|
2282
|
+
const srcContents = dictGet5(srcPage.pageDict, "Contents");
|
|
1725
2283
|
if (!srcContents) continue;
|
|
1726
2284
|
const rawSrcNodes = [];
|
|
1727
2285
|
const resolvedSrcContents = overlayDoc.cos.resolve(srcContents);
|
|
@@ -1747,7 +2305,7 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
|
|
|
1747
2305
|
}
|
|
1748
2306
|
}
|
|
1749
2307
|
if (srcList.length === 0) continue;
|
|
1750
|
-
const dstContents =
|
|
2308
|
+
const dstContents = dictGet5(dstPage.pageDict, "Contents");
|
|
1751
2309
|
const toStreamList = (c) => {
|
|
1752
2310
|
if (!c) return [];
|
|
1753
2311
|
const r = targetDoc.cos.resolve(c);
|
|
@@ -1796,7 +2354,7 @@ ${fmt6(s)} 0 0 ${fmt6(s)} ${fmt4(tx)} ${fmt4(ty)} cm
|
|
|
1796
2354
|
const qOpenSrc = targetDoc.cos.allocateObject(cosStream(new TextEncoder().encode(srcOpenCmd), { compress: false }));
|
|
1797
2355
|
const qClose = targetDoc.cos.allocateObject(cosStream(new TextEncoder().encode("\nQ\n"), { compress: false }));
|
|
1798
2356
|
const combined = mode === "background" ? [qOpenSrc, ...srcList, qClose, qOpenDst, ...dstList, qClose] : [qOpenDst, ...dstList, qClose, qOpenSrc, ...srcList, qClose];
|
|
1799
|
-
|
|
2357
|
+
dictSet2(dstPage.pageDict, "Contents", cosArray3(combined));
|
|
1800
2358
|
}
|
|
1801
2359
|
}
|
|
1802
2360
|
function normalizeQuarterTurn(degrees) {
|
|
@@ -1870,8 +2428,8 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
1870
2428
|
if (obj.value.kind !== "stream")
|
|
1871
2429
|
continue;
|
|
1872
2430
|
const raw = singleDoc.cos.decodeStream(obj.value);
|
|
1873
|
-
|
|
1874
|
-
|
|
2431
|
+
dictDelete2(obj.value.dict, "Filter");
|
|
2432
|
+
dictDelete2(obj.value.dict, "DecodeParms");
|
|
1875
2433
|
singleDoc.cos.objects.set(obj.objectNumber, {
|
|
1876
2434
|
...obj,
|
|
1877
2435
|
value: cosStream(raw, {
|
|
@@ -1980,9 +2538,9 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
1980
2538
|
if (!cached) {
|
|
1981
2539
|
cached = [];
|
|
1982
2540
|
const cat = d.cos.resolveDict(d.cos.rootRef);
|
|
1983
|
-
const outDict = cat ? d.cos.resolveDict(
|
|
2541
|
+
const outDict = cat ? d.cos.resolveDict(dictGet5(cat, "Outlines")) : void 0;
|
|
1984
2542
|
if (outDict) {
|
|
1985
|
-
collectOutlineBookmarks(d,
|
|
2543
|
+
collectOutlineBookmarks(d, dictGet5(outDict, "First"), 1, cached);
|
|
1986
2544
|
}
|
|
1987
2545
|
bookmarksByDoc.set(d, cached);
|
|
1988
2546
|
}
|
|
@@ -2072,14 +2630,14 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
2072
2630
|
}
|
|
2073
2631
|
if (dropXfa) {
|
|
2074
2632
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
2075
|
-
const acroForm = root ? resultDoc.cos.resolveDict(
|
|
2633
|
+
const acroForm = root ? resultDoc.cos.resolveDict(dictGet5(root, "AcroForm")) : void 0;
|
|
2076
2634
|
if (acroForm)
|
|
2077
|
-
|
|
2635
|
+
dictDelete2(acroForm, "XFA");
|
|
2078
2636
|
}
|
|
2079
2637
|
if (dropXmp) {
|
|
2080
2638
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
2081
2639
|
if (root)
|
|
2082
|
-
|
|
2640
|
+
dictDelete2(root, "Metadata");
|
|
2083
2641
|
}
|
|
2084
2642
|
if (replacementFont && operation === "fill_form") {
|
|
2085
2643
|
const cleanFontName = replacementFont.startsWith("/") ? replacementFont.slice(1) : replacementFont;
|
|
@@ -2087,28 +2645,28 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
2087
2645
|
if (++cooperativeWork % 64 === 0)
|
|
2088
2646
|
yield;
|
|
2089
2647
|
if (obj.value.kind === "dict") {
|
|
2090
|
-
const stNode =
|
|
2091
|
-
const bfNode =
|
|
2648
|
+
const stNode = dictGet5(obj.value, "Subtype");
|
|
2649
|
+
const bfNode = dictGet5(obj.value, "BaseFont");
|
|
2092
2650
|
const subtype = stNode?.kind === "name" ? stNode.decoded : void 0;
|
|
2093
2651
|
const baseFont = bfNode?.kind === "name" ? bfNode.decoded : void 0;
|
|
2094
2652
|
if (subtype === "Type1" && baseFont === "Helvetica") {
|
|
2095
|
-
|
|
2653
|
+
dictSet2(obj.value, "BaseFont", cosName(cleanFontName));
|
|
2096
2654
|
}
|
|
2097
2655
|
}
|
|
2098
2656
|
}
|
|
2099
2657
|
}
|
|
2100
2658
|
if (operation === "fill_form" && !shouldFlatten) {
|
|
2101
2659
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
2102
|
-
const acroForm = root ? resultDoc.cos.resolveDict(
|
|
2660
|
+
const acroForm = root ? resultDoc.cos.resolveDict(dictGet5(root, "AcroForm")) : void 0;
|
|
2103
2661
|
if (acroForm) {
|
|
2104
|
-
|
|
2662
|
+
dictSet2(acroForm, "NeedAppearances", { kind: "boolean", value: needAppearances });
|
|
2105
2663
|
}
|
|
2106
2664
|
} else if (needAppearances && !shouldFlatten) {
|
|
2107
2665
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
2108
2666
|
if (root) {
|
|
2109
|
-
const acroForm = resultDoc.cos.resolveDict(
|
|
2667
|
+
const acroForm = resultDoc.cos.resolveDict(dictGet5(root, "AcroForm"));
|
|
2110
2668
|
if (acroForm) {
|
|
2111
|
-
|
|
2669
|
+
dictSet2(acroForm, "NeedAppearances", { kind: "boolean", value: true });
|
|
2112
2670
|
}
|
|
2113
2671
|
}
|
|
2114
2672
|
}
|
|
@@ -2116,12 +2674,12 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
2116
2674
|
if (keepFinalId) {
|
|
2117
2675
|
const lastInput = handleDocs[handleDocs.length - 1];
|
|
2118
2676
|
if (lastInput?.cos.idArray) {
|
|
2119
|
-
resultDoc.cos.idArray =
|
|
2677
|
+
resultDoc.cos.idArray = cosArray3([...lastInput.cos.idArray.items]);
|
|
2120
2678
|
}
|
|
2121
2679
|
} else if (keepFirstId || !resultDoc.cos.idArray) {
|
|
2122
2680
|
const firstInput = handleDocs[0];
|
|
2123
2681
|
if (firstInput?.cos.idArray) {
|
|
2124
|
-
resultDoc.cos.idArray =
|
|
2682
|
+
resultDoc.cos.idArray = cosArray3([...firstInput.cos.idArray.items]);
|
|
2125
2683
|
}
|
|
2126
2684
|
}
|
|
2127
2685
|
if (uncompressStreams || compressStreams) {
|
|
@@ -2131,8 +2689,8 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
2131
2689
|
if (obj.value.kind !== "stream")
|
|
2132
2690
|
continue;
|
|
2133
2691
|
const raw = resultDoc.cos.decodeStream(obj.value);
|
|
2134
|
-
|
|
2135
|
-
|
|
2692
|
+
dictDelete2(obj.value.dict, "Filter");
|
|
2693
|
+
dictDelete2(obj.value.dict, "DecodeParms");
|
|
2136
2694
|
resultDoc.cos.objects.set(obj.objectNumber, {
|
|
2137
2695
|
...obj,
|
|
2138
2696
|
value: cosStream(raw, {
|
|
@@ -2180,7 +2738,7 @@ function runPdftkCliSync(argv, files, signal) {
|
|
|
2180
2738
|
}
|
|
2181
2739
|
return next.value;
|
|
2182
2740
|
}
|
|
2183
|
-
async function executePdftk(context) {
|
|
2741
|
+
async function executePdftk(context, retainedContext = context) {
|
|
2184
2742
|
let cooperativeWork = 63;
|
|
2185
2743
|
const invocation = createOutputOperation(context, { write: async () => {
|
|
2186
2744
|
} });
|
|
@@ -2188,8 +2746,8 @@ async function executePdftk(context) {
|
|
|
2188
2746
|
const carrier = getCommandArguments(context);
|
|
2189
2747
|
const argv = [...carrier.args];
|
|
2190
2748
|
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({ ...
|
|
2749
|
+
if (parsed.options && (["output", "rotate", "attach_files", "stamp", "multistamp", "background", "multibackground", "burst"].includes(parsed.options.operation) && !parsed.options.shouldFlatten || ["dump_data", "dump_data_utf8", "dump_data_annots", "dump_data_annots_utf8", "dump_data_fields", "dump_data_fields_utf8", "generate_fdf", "unpack_files"].includes(parsed.options.operation))) {
|
|
2750
|
+
return await executeRetainedPdftk({ ...retainedContext, signal: invocation.signal, stdout: invocation.child(context.stdout).output }, parsed.options);
|
|
2193
2751
|
}
|
|
2194
2752
|
const vfsFiles = /* @__PURE__ */ new Map();
|
|
2195
2753
|
let accountedBytes = 0;
|
|
@@ -2290,7 +2848,7 @@ function createPdftkCommand(options = {}) {
|
|
|
2290
2848
|
runtimeIdentity: commandRuntimeIdentity,
|
|
2291
2849
|
description: "Manipulate PDF documents, fill/flatten AcroForms, and assemble pages via @poe-code/pdf-ast",
|
|
2292
2850
|
execute(context) {
|
|
2293
|
-
return new InputByteBudget(maxInputBytes).run(context, executePdftk);
|
|
2851
|
+
return new InputByteBudget(maxInputBytes).run(context, (limited) => executePdftk(limited, { ...context, inputBudget: limited.inputBudget }));
|
|
2294
2852
|
}
|
|
2295
2853
|
});
|
|
2296
2854
|
}
|
|
@@ -2312,6 +2870,7 @@ function createPdftkCommands(options = {}) {
|
|
|
2312
2870
|
export {
|
|
2313
2871
|
createPdftkCommand,
|
|
2314
2872
|
createPdftkCommands,
|
|
2873
|
+
iteratePdftkRangeToken,
|
|
2315
2874
|
parsePdftkRangeToken,
|
|
2316
2875
|
pdftkCommand,
|
|
2317
2876
|
pdftkCommands,
|