@poe-platform/safe-bash 0.1.812 → 0.1.814
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/mp4-ast/index.d.ts +2 -0
- package/dist/mp4-ast/mp4-sample-source.d.ts +52 -0
- package/dist/mp4-ast/mp4-source.d.ts +32 -0
- package/dist/office-xml/retained-xml-document.d.ts +14 -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/evaluator.d.ts +4 -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 +11 -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 +10 -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-form-appearances.d.ts +10 -0
- package/dist/pdf-ast/edit/retained-graph.d.ts +12 -0
- package/dist/pdf-ast/edit/retained-info-updates.d.ts +33 -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 +1966 -844
- package/dist/pdf-ast/retained-document.d.ts +5 -0
- 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-KRHJ63K3-VQPJCVIL.js +5309 -0
- package/dist/safe-bash/command-chunks/{chunk-34G2SQX2.js → chunk-2BLTUQNK.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-LLU2IQEJ.js → chunk-2BNGPR6Z.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-HWQ2UHMT.js → chunk-2ETEJOYX.js} +18 -18
- package/dist/safe-bash/command-chunks/{chunk-NQDIT667.js → chunk-2PKBXGXD.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-MMBZTYXO.js → chunk-2PQRZDNR.js} +221 -0
- package/dist/safe-bash/command-chunks/{chunk-6QBMND4A.js → chunk-2VVJRVYM.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-G5QVZQCO.js → chunk-3EASXF5D.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-U3SBHEKH.js → chunk-3EB2FSAN.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-VB2TUPO2.js → chunk-3EW7GYHM.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-RNSKXOG3.js → chunk-3GRMU7TM.js} +6 -6
- package/dist/safe-bash/command-chunks/chunk-3JM7E42I.js +197 -0
- package/dist/safe-bash/command-chunks/{chunk-6L4IYQAT.js → chunk-3MG5EAMX.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-RASQPOSV.js → chunk-3SPLP2DB.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-K5COUQAQ.js → chunk-3VGQTLO6.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-K7CV55K5.js → chunk-3YEQI5B7.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-ZXR6LXV5.js → chunk-3ZRCL756.js} +48 -4
- package/dist/safe-bash/command-chunks/{chunk-SOFM3GPG.js → chunk-42MEXZBJ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-GQ2ZSPZ3.js → chunk-46AMTJPE.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-MTWZEPAR.js → chunk-47IAU25U.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-6GI3NTCW.js → chunk-4B2ZUGLT.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-L5MCW6CM.js → chunk-4EHY6J2Z.js} +9 -155
- package/dist/safe-bash/command-chunks/{chunk-QQVACHZA.js → chunk-4EZJV4FZ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-SSKMPDN4.js → chunk-4GQKCUS5.js} +15 -15
- package/dist/safe-bash/command-chunks/{chunk-UOBW5K3M.js → chunk-4RRYWHED.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-PINR7QET.js → chunk-4UPKVQWH.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-M7QE2MN7.js → chunk-4YLACJHE.js} +6 -6
- package/dist/safe-bash/command-chunks/chunk-5BIQWWLB.js +175 -0
- package/dist/safe-bash/command-chunks/{chunk-P3WU3PSL.js → chunk-5L4YGRQU.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-HKATEVAP.js → chunk-5LFGXN3D.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-SPLOIABU.js → chunk-5OM3UIK3.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-TVH4JORU.js → chunk-6LPSKLLD.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-CV7M2QJU.js → chunk-6QYSF7I2.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-XVP6V5K3.js → chunk-6VBDJC6V.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-6N5GHM72.js → chunk-6WNVGCXD.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-6CCQI6XZ.js → chunk-6XES7Z4G.js} +12 -12
- package/dist/safe-bash/command-chunks/{chunk-AFROLW6S.js → chunk-6XGDWFNQ.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-WTE23QXN.js → chunk-6ZGCKUAM.js} +3 -3
- package/dist/safe-bash/command-chunks/chunk-6ZHQB453.js +35 -0
- package/dist/safe-bash/command-chunks/{chunk-RIV6XN7K.js → chunk-7DOLY7IV.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-QD7ZRDUN.js → chunk-7KZ5LWV2.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-NGR5KOPQ.js → chunk-A347DLRB.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-ZM2Y4Z3C.js → chunk-A45UG4KT.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-56NYSX65.js → chunk-ADHFF2IM.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-ATI464W3.js → chunk-AG2SNMP5.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-FDCIPJBQ.js → chunk-AM5LANIE.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-3Q247UDJ.js → chunk-AVGXFWEB.js} +278 -135
- package/dist/safe-bash/command-chunks/{chunk-RBTC7OFT.js → chunk-AVOGFREX.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-QC5RMGSA.js → chunk-AWPI4DZR.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-FYMNHG7R.js → chunk-AXXZNB7U.js} +13 -13
- package/dist/safe-bash/command-chunks/{chunk-Q6S57NOQ.js → chunk-AY3KQ4EN.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-456PHA3L.js → chunk-BLGGAHQW.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-CU4DLVME.js → chunk-BLIFGBIO.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-NARD63DY.js → chunk-BS3ZEQGT.js} +22 -66
- package/dist/safe-bash/command-chunks/{chunk-WFVSUXJL.js → chunk-BS5JEUEW.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-UYWSIIUX.js → chunk-BZMNC7Q5.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-RHYJVTJO.js → chunk-CCMAHM3I.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-N4R2SHSS.js → chunk-CCZZVCHX.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-WGG6G2KG.js → chunk-CIRDVCAZ.js} +7 -7
- package/dist/safe-bash/command-chunks/chunk-CK2WFJZN.js +178 -0
- package/dist/safe-bash/command-chunks/{chunk-UZL7G57V.js → chunk-CKEMZUE3.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-B5LDP7AA.js → chunk-CQBACD2V.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-JYUJAF4L.js → chunk-CSE4VQKG.js} +16 -1
- package/dist/safe-bash/command-chunks/{chunk-Q73EMLLZ.js → chunk-CXME4YHU.js} +107 -5
- package/dist/safe-bash/command-chunks/{chunk-FTLDRH47.js → chunk-CZ5K2YPU.js} +16 -16
- package/dist/safe-bash/command-chunks/{chunk-554Z6IKP.js → chunk-DBLQUZGN.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-6M6TM5Z5.js → chunk-DBNJEXHK.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-SPW4GW4Z.js → chunk-DFI7QF3M.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-ZO5WBWLL.js → chunk-DN6MSXY7.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-GXLXWZWH.js → chunk-DZH54L3F.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-XRVKWGVQ.js → chunk-EBHOZIBS.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-3Y5EME26.js → chunk-ENEIE44W.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-ATTWQVR2.js → chunk-EQWFKNHJ.js} +17 -17
- package/dist/safe-bash/command-chunks/{chunk-YV72XQKL.js → chunk-ETXPMVR6.js} +13 -13
- package/dist/safe-bash/command-chunks/{chunk-JFYWVQ4V.js → chunk-EV5G535P.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-PZMU3Z4L.js → chunk-EVYKV3QI.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-D6UMSC45.js → chunk-F4YFTO2K.js} +11 -11
- package/dist/safe-bash/command-chunks/{chunk-MPUHH2KR.js → chunk-F762XDNG.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-D2ASPM7R.js → chunk-FF7UGJWS.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-OA75SGN2.js → chunk-FOONI6BD.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-DYLNU57U.js → chunk-FSVJ67G5.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-CLKOGAR3.js → chunk-FSYMSWJU.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-22MOB45U.js → chunk-FUQMEUAT.js} +6 -6
- package/dist/safe-bash/command-chunks/chunk-FWKLBDMK.js +0 -0
- package/dist/safe-bash/command-chunks/{chunk-KXPCSVAT.js → chunk-FXCSPPYE.js} +20 -20
- package/dist/safe-bash/command-chunks/{chunk-XZ2FWFNV.js → chunk-FYYFV6PW.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-3OETVNJA.js → chunk-G2COZLXX.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-ZEX53S5I.js → chunk-G3TAX3CV.js} +7369 -7221
- package/dist/safe-bash/command-chunks/{chunk-LXLLA4PM.js → chunk-GCHB7VNX.js} +17 -17
- package/dist/safe-bash/command-chunks/{chunk-4Y6O2K35.js → chunk-GLAF45M7.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-OEJM666F.js → chunk-GQGMQMIM.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-RRL3Y562.js → chunk-GXMPXMDP.js} +11 -11
- package/dist/safe-bash/command-chunks/{chunk-GEM47B2P.js → chunk-GYM5ICK4.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-A5FZBR7X.js → chunk-H33D4R26.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-AGLK7OJR.js → chunk-HDSIIQBS.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-3ZDANXIC.js → chunk-HELAVGZH.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-S4QH5BXZ.js → chunk-HGIMFVI2.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-35IPOBWL.js → chunk-HI6ZYH3W.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-KB7DUBVL.js → chunk-HK6MSB7Z.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-7ZE3VIAN.js → chunk-IB5QP4LF.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-UCR5YDV3.js → chunk-IBYMPAUW.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-LABOWPFB.js → chunk-IHXZMAMY.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-XPD636C4.js → chunk-IWHNRYER.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-PPO7YUZF.js → chunk-JGKSWDGP.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-KCOJA7EM.js → chunk-JR3Q6QNL.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-S6R3IB36.js → chunk-JUHOL5KB.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-3O2YEI47.js → chunk-JVKE7YZN.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-6NATRKUJ.js → chunk-JW6WVNTM.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-IK6K2HCG.js → chunk-JWORWL72.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-JOCFI7TG.js → chunk-K2WOMJOQ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-XVLWZTPY.js → chunk-K4XNUJVJ.js} +543 -144
- package/dist/safe-bash/command-chunks/{chunk-DM2CPMB4.js → chunk-KBAQHE5Y.js} +2 -2
- package/dist/safe-bash/command-chunks/chunk-KCLJGRU7.js +737 -0
- package/dist/safe-bash/command-chunks/{chunk-TUDFMNPP.js → chunk-KINIV2SV.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-43TRBJ2N.js → chunk-KPHLESD4.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-47NEG4UO.js → chunk-KRRG4MGH.js} +222 -46
- package/dist/safe-bash/command-chunks/{chunk-33YCKZZX.js → chunk-KSBNZTAZ.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-4Y34ZG4T.js → chunk-KUOCGGEU.js} +11 -11
- package/dist/safe-bash/command-chunks/{chunk-ML5R5JML.js → chunk-KY4LCHUF.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-2JSDKQ4J.js → chunk-LAPOMHGY.js} +251 -239
- package/dist/safe-bash/command-chunks/{chunk-ENT3IV2G.js → chunk-LDW3RF7Y.js} +12 -12
- package/dist/safe-bash/command-chunks/{chunk-U27XPNLP.js → chunk-LEO4VRIN.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-GZ3VIWNN.js → chunk-LKGTH2Q7.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-ZMHEGDU2.js → chunk-LNTEV56A.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-DVGXLBUW.js → chunk-LZ2JFMKT.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-6D2BMAF4.js → chunk-MEM2ZPMI.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-HTVIYLVB.js → chunk-MGMTRGKM.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-B3NLITWP.js → chunk-MKK6FM5H.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-Z2JW6M2D.js → chunk-MKOIPOXX.js} +3 -3
- package/dist/safe-bash/command-chunks/chunk-MLOYUXUV.js +244 -0
- package/dist/safe-bash/command-chunks/{chunk-CBNKHBLD.js → chunk-MNK3DDH6.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-JVGUVHWI.js → chunk-MPXMRTMY.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-TW73OXPR.js → chunk-MVLVIMJ6.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-TY4WDAHM.js → chunk-MYZ46FQL.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-TBAIMDGL.js → chunk-N4MUBJCT.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-NPLVFAD6.js → chunk-N6G3345Q.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-ZIIO6GRY.js → chunk-NEMUPUUB.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-K5GB2YMN.js → chunk-NEVQWOU6.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-FIIAYCWS.js → chunk-NFGCBQN3.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-PNGDJA6M.js → chunk-NFII726L.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-JQPNA77Y.js → chunk-NHNZYWPW.js} +2 -2
- package/dist/safe-bash/command-chunks/chunk-NQINS4XY.js +156 -0
- package/dist/safe-bash/command-chunks/{chunk-APEWTWCC.js → chunk-NRFTYZ2R.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-THMZLJQD.js → chunk-NYFYTL5G.js} +18 -18
- package/dist/safe-bash/command-chunks/{chunk-SMSGLRIH.js → chunk-OTF2AJ5M.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-QZZ73J2O.js → chunk-OVQP6KH5.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-HDJVJTCK.js → chunk-P2LT6TGR.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-YS25EI54.js → chunk-PCCFLPUQ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-26VCZHLJ.js → chunk-PIOQBOEK.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-D2KZ66W4.js → chunk-PIVH35EQ.js} +190 -42
- package/dist/safe-bash/command-chunks/{chunk-QYMEASQ6.js → chunk-PLMF35XK.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-JQVHUSDD.js → chunk-PLR5IULU.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-2CORNDGF.js → chunk-PS5GDFIP.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-R6EGGK5M.js → chunk-Q5PWYPQV.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-COKYZUBW.js → chunk-Q7TVCBU2.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-EHTOHOTR.js → chunk-QB72X7FF.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-F3GP3EXE.js → chunk-RGDOYWOD.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-RQIQ75W5.js → chunk-RHDERFMR.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-3KMOXEGH.js → chunk-RHU44OMN.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-7PVHO47B.js → chunk-RIVKF77R.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-UOR6PXZZ.js → chunk-ROL5AEX6.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-AHA6IWAJ.js → chunk-RQYPFLZJ.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-YSMNXMAO.js → chunk-RTNI47C5.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-W5LLKV5H.js → chunk-RV5AGXOV.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-PMAM4N33.js → chunk-RXQ2G2YK.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-EVU7FLDA.js → chunk-S2QNBAN6.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-YE6OAKK7.js → chunk-S43QRKDC.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-774GLJAO.js → chunk-S7HIOT7Z.js} +4 -4
- package/dist/safe-bash/command-chunks/chunk-SEPUP6TZ.js +63 -0
- package/dist/safe-bash/command-chunks/{chunk-JPMYPOYZ.js → chunk-SUTHGUD3.js} +28 -28
- package/dist/safe-bash/command-chunks/chunk-SW37YCBW.js +286 -0
- package/dist/safe-bash/command-chunks/{chunk-Y4EYCZFT.js → chunk-SWAKALDJ.js} +10 -10
- package/dist/safe-bash/command-chunks/{chunk-QUM3SYAJ.js → chunk-SYSX46IV.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-WGH3RLJY.js → chunk-T5S4SJGO.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-7JEIWA3A.js → chunk-TID5TSQW.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-CRV2Q3PB.js → chunk-TJLXSENN.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-IT7TAC3F.js → chunk-TKCUGMRZ.js} +24 -20
- package/dist/safe-bash/command-chunks/{chunk-7GKKMNL6.js → chunk-TXPDKEGY.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-A2CLZMQZ.js → chunk-UJERQEJB.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-6VPQ3CDZ.js → chunk-USGZN2KE.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-LCZDBW55.js → chunk-UYGQEQIP.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-MPORWUTU.js → chunk-V5XC43BX.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-AIMSZBWP.js → chunk-V7E3PZOK.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-CNHRVUHA.js → chunk-VDTFVRYX.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-KJ4XXZIL.js → chunk-VT2PHQ63.js} +582 -59
- package/dist/safe-bash/command-chunks/{chunk-MOZD7RUY.js → chunk-VT7UBPAE.js} +38 -15
- package/dist/safe-bash/command-chunks/{chunk-QDVI2YB6.js → chunk-VUWXLH3E.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-X7FA7ZD5.js → chunk-W3ZSWK76.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-JPA2PUYI.js → chunk-WBKB7HBZ.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-MIRL7HTF.js → chunk-WJ2ERUCQ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-36XGIPOG.js → chunk-WTVJLHMG.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-SLQWQKXP.js → chunk-WWHMI4S3.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-2UBZALAK.js → chunk-WYZG3DRR.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-YORJDX4V.js → chunk-WZRFS5OY.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-EHSM5ZQS.js → chunk-X6OHFKBL.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-S6ZTBXYO.js → chunk-XKAUKLF7.js} +13 -13
- package/dist/safe-bash/command-chunks/{chunk-EUT24Y5Z.js → chunk-XM5QJCPD.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-WXRYDALR.js → chunk-XMTR7QGL.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-4CKFNXRN.js → chunk-XNGM3W5R.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-2ZFLMWOX.js → chunk-XTEIT5CI.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-4DLIUTQV.js → chunk-XU6S3XUZ.js} +11 -11
- package/dist/safe-bash/command-chunks/{chunk-CJQSAATC.js → chunk-XUJAQA3S.js} +30 -30
- package/dist/safe-bash/command-chunks/{chunk-W5YSINXC.js → chunk-Y42KSX63.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-UAXSE3XE.js → chunk-Y54L4P4J.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-6WQD7LRA.js → chunk-YAD7EV4N.js} +14 -14
- package/dist/safe-bash/command-chunks/{chunk-WVMHRNXZ.js → chunk-YRPXBGRX.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-5HPU7D36.js → chunk-Z2WNYEPD.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-SDTPO2VV.js → chunk-Z7QOSXQC.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-WJCN2IXI.js → chunk-ZQM37BGE.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-W3HV45CI.js → chunk-ZSQZHFWS.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-IDJQP3A6.js → chunk-ZTMZO4IT.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-RID6VYS3.js → chunk-ZU2KJMXO.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-YXKNJ6EM.js → chunk-ZXELXF2H.js} +5 -5
- package/dist/safe-bash/command-chunks/{clipboard-BBDK33GP-VB22F7GI.js → clipboard-BBDK33GP-QZ4ERNQX.js} +2 -2
- package/dist/safe-bash/command-chunks/{command-engine-BCUQGJJ4.js → command-engine-7V6PZR7G.js} +1012 -678
- package/dist/safe-bash/command-chunks/{engine-LAUEWYSQ-DQCEI5HE.js → engine-UYJENSWK-VSCGKSQV.js} +1 -1
- package/dist/safe-bash/command-chunks/{gnumeric-UJPXWBVR-YPXTNEDZ.js → gnumeric-UJPXWBVR-7VOHQAPM.js} +2 -2
- package/dist/safe-bash/command-chunks/{model-store-E7BHBFJC.js → model-store-UB5DWMAP.js} +24 -24
- 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-awk/awk-runtime.js +3 -3
- package/dist/safe-bash-command-awk/awk.js +4 -4
- package/dist/safe-bash-command-awk/index.js +4 -4
- package/dist/safe-bash-command-diff/diff.js +2 -2
- package/dist/safe-bash-command-diff/index.js +3 -3
- package/dist/safe-bash-command-diff/sync.js +2 -2
- package/dist/safe-bash-command-du/du.js +2 -2
- package/dist/safe-bash-command-du/index.js +2 -2
- 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 +533 -310
- 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/stored-text.d.ts +50 -0
- package/dist/safe-bash-command-html-to-markdown/stored-text.js +12 -0
- package/dist/safe-bash-command-html-to-markdown/text.js +3 -2
- package/dist/safe-bash-command-htmlq/contracts.d.ts +5 -0
- package/dist/safe-bash-command-htmlq/index.js +2006 -259
- package/dist/safe-bash-command-htmlq/selectors.d.ts +38 -1
- package/dist/safe-bash-command-htmlq/serializer.d.ts +1 -0
- package/dist/safe-bash-command-htmlq/tree.d.ts +4 -2
- package/dist/safe-bash-command-iconv/command.js +2 -2
- package/dist/safe-bash-command-iconv/index.js +2 -2
- package/dist/safe-bash-command-llm/command.js +3 -3
- package/dist/safe-bash-command-llm/index.js +9 -9
- package/dist/safe-bash-command-llm/openai.js +2 -2
- package/dist/safe-bash-command-llm/providers/index.js +2 -2
- package/dist/safe-bash-command-llm/providers/openai.js +2 -2
- package/dist/safe-bash-command-node/commands/node/browser.js +2 -2
- package/dist/safe-bash-command-node/commands/node/default-runtime.js +2 -2
- package/dist/safe-bash-command-node/commands/node/safejs.js +2 -2
- package/dist/safe-bash-command-pandoc/command.js +7 -7
- package/dist/safe-bash-command-pandoc/index.js +46 -46
- 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 +7 -2
- package/dist/safe-bash-command-patch/patch-formats.js +6 -4
- package/dist/safe-bash-command-patch/patch-gnu-paths.d.ts +7 -7
- package/dist/safe-bash-command-patch/patch-gnu-reject.d.ts +3 -2
- 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/stored-patch.d.ts +26 -0
- package/dist/safe-bash-command-patch/stored-target.d.ts +40 -0
- package/dist/safe-bash-command-patch/unified.d.ts +23 -10
- package/dist/safe-bash-command-patch/unified.js +3 -1
- package/dist/safe-bash-command-pdftk/index.d.ts +6 -2
- package/dist/safe-bash-command-pdftk/index.js +1247 -373
- package/dist/safe-bash-command-playwright-cli/index.js +26 -26
- package/dist/safe-bash-command-playwright-cli/playwright/abilities.js +10 -10
- package/dist/safe-bash-command-playwright-cli/playwright/controller.js +14 -14
- package/dist/safe-bash-command-playwright-cli/playwright/index.js +23 -23
- package/dist/safe-bash-command-playwright-cli/playwright/snapshot.js +2 -2
- package/dist/safe-bash-command-playwright-cli/playwright/standard-capabilities.js +6 -6
- package/dist/safe-bash-command-playwright-cli/playwright/storage-capabilities.js +4 -4
- package/dist/safe-bash-command-pptx/command-engine.d.ts +5 -1
- package/dist/safe-bash-command-pptx/engine.js +1 -1
- package/dist/safe-bash-command-pptx/index.d.ts +1 -1
- package/dist/safe-bash-command-pptx/index.js +172 -19
- package/dist/safe-bash-command-pptx/streaming-inputs.d.ts +7 -2
- package/dist/safe-bash-command-python/executor.js +5 -5
- package/dist/safe-bash-command-python/index.js +5 -5
- package/dist/safe-bash-command-python/jspi.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +1 -1
- package/dist/safe-bash-command-sort/index.js +3 -3
- package/dist/safe-bash-command-ssconvert/index.js +2 -2
- package/dist/safe-bash-command-tar/create.js +2 -2
- package/dist/safe-bash-command-tar/extract.js +2 -2
- package/dist/safe-bash-command-tar/index.js +8 -8
- package/dist/safe-bash-command-tar/modes.js +4 -4
- package/dist/safe-bash-command-timeout/index.js +3 -3
- package/dist/safe-bash-command-tree/index.js +2 -2
- package/dist/safe-bash-command-tree/tree.js +2 -2
- package/dist/safe-bash-command-xmllint/index.js +22 -31
- package/dist/safe-bash-command-xz/index.js +5 -5
- package/dist/safe-bash-compression-engine/files.js +2 -2
- package/dist/safe-bash-compression-engine/operand.js +4 -4
- package/dist/safe-bash-contracts/diagnostics.js +3 -3
- package/dist/safe-bash-contracts/escaping.js +10 -10
- package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
- package/dist/safe-bash-contracts/filesystem-output.js +6 -6
- package/dist/safe-bash-contracts/index.js +33 -33
- package/dist/safe-bash-contracts/io.js +2 -2
- package/dist/safe-bash-contracts/output.js +3 -3
- package/dist/safe-bash-docx-engine/ancillary-resources.js +5 -5
- package/dist/safe-bash-docx-engine/batch-operations.js +63 -63
- package/dist/safe-bash-docx-engine/batch-result-schema.js +74 -74
- package/dist/safe-bash-docx-engine/batch.js +74 -74
- package/dist/safe-bash-docx-engine/bookmarks.js +13 -13
- package/dist/safe-bash-docx-engine/charts.js +6 -6
- package/dist/safe-bash-docx-engine/command-option-rules.js +3 -3
- package/dist/safe-bash-docx-engine/comments.js +21 -21
- package/dist/safe-bash-docx-engine/control-bindings.js +16 -16
- package/dist/safe-bash-docx-engine/control-repeat.js +16 -16
- package/dist/safe-bash-docx-engine/controls.js +14 -14
- package/dist/safe-bash-docx-engine/create.js +8 -8
- package/dist/safe-bash-docx-engine/diagrams.js +6 -6
- package/dist/safe-bash-docx-engine/diff.js +8 -8
- package/dist/safe-bash-docx-engine/document-properties.js +12 -12
- package/dist/safe-bash-docx-engine/equations.js +12 -12
- package/dist/safe-bash-docx-engine/extract.js +9 -9
- package/dist/safe-bash-docx-engine/fields.js +18 -18
- package/dist/safe-bash-docx-engine/font-inventory.js +13 -13
- package/dist/safe-bash-docx-engine/font-resources.js +3 -3
- package/dist/safe-bash-docx-engine/image-batch-operations.js +11 -11
- package/dist/safe-bash-docx-engine/image-insertion.js +17 -17
- package/dist/safe-bash-docx-engine/image-layout.js +14 -14
- package/dist/safe-bash-docx-engine/image-replacement.js +19 -19
- package/dist/safe-bash-docx-engine/images.js +14 -14
- package/dist/safe-bash-docx-engine/index.js +102 -102
- package/dist/safe-bash-docx-engine/inspection.js +15 -15
- package/dist/safe-bash-docx-engine/invocation.js +4 -4
- package/dist/safe-bash-docx-engine/io.js +6 -6
- package/dist/safe-bash-docx-engine/links.js +17 -17
- package/dist/safe-bash-docx-engine/lists.js +16 -16
- package/dist/safe-bash-docx-engine/locations.js +10 -10
- package/dist/safe-bash-docx-engine/notes.js +18 -18
- package/dist/safe-bash-docx-engine/objects.js +14 -14
- package/dist/safe-bash-docx-engine/pack.js +9 -9
- package/dist/safe-bash-docx-engine/package-view-batch-operations.js +19 -19
- package/dist/safe-bash-docx-engine/pandoc-adapter.js +25 -25
- package/dist/safe-bash-docx-engine/paragraph-edit.js +21 -21
- package/dist/safe-bash-docx-engine/publication.js +6 -6
- package/dist/safe-bash-docx-engine/removal.js +16 -16
- package/dist/safe-bash-docx-engine/revision-decisions.js +16 -16
- package/dist/safe-bash-docx-engine/revision-edit.js +15 -15
- package/dist/safe-bash-docx-engine/revisions.js +12 -12
- package/dist/safe-bash-docx-engine/run-format.js +15 -15
- package/dist/safe-bash-docx-engine/sanitize.js +29 -29
- package/dist/safe-bash-docx-engine/sections.js +15 -15
- package/dist/safe-bash-docx-engine/settings.js +6 -6
- package/dist/safe-bash-docx-engine/shape-edit.js +16 -16
- package/dist/safe-bash-docx-engine/signatures.js +11 -11
- package/dist/safe-bash-docx-engine/stories.js +18 -18
- package/dist/safe-bash-docx-engine/structure-model-batch-operations.js +34 -34
- package/dist/safe-bash-docx-engine/style-model-batch-operations.js +24 -24
- package/dist/safe-bash-docx-engine/style-model-result-schema.js +39 -39
- package/dist/safe-bash-docx-engine/styles.js +14 -14
- package/dist/safe-bash-docx-engine/table-edit.js +23 -23
- package/dist/safe-bash-docx-engine/table-read.js +11 -11
- package/dist/safe-bash-docx-engine/template.js +17 -17
- package/dist/safe-bash-docx-engine/text-replace.js +15 -15
- package/dist/safe-bash-docx-engine/text-resource-read.js +11 -11
- package/dist/safe-bash-docx-engine/text.js +11 -11
- package/dist/safe-bash-docx-engine/validation.js +4 -4
- package/dist/safe-bash-docx-engine/xml-parts.js +17 -17
- package/dist/safe-bash-io-engine/commands/text-programs/shared.js +4 -4
- package/dist/safe-bash-line-ending-engine/command.js +3 -3
- package/dist/safe-bash-line-ending-engine/convert.js +2 -2
- package/dist/safe-bash-line-ending-engine/index.js +6 -6
- package/dist/safe-bash-line-ending-engine/info.js +2 -2
- package/dist/safe-bash-markdown-engine/commonmark-blocks.js +4 -4
- package/dist/safe-bash-markdown-engine/commonmark-inlines.js +4 -4
- package/dist/safe-bash-markdown-engine/commonmark-syntax.js +2 -2
- package/dist/safe-bash-markdown-engine/gfm-syntax.js +3 -3
- package/dist/safe-bash-markdown-engine/index.js +5 -5
- package/dist/safe-bash-network-engine/transfer.js +3 -3
- 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 +121 -108
- 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-frame-formatting.d.ts +14 -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.d.ts +9 -2
- package/dist/safe-bash-presentation-engine/retained-text.js +131 -30
- package/dist/safe-bash-presentation-engine/retained-xml-document.d.ts +1 -0
- 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.d.ts +13 -0
- package/dist/safe-bash-presentation-engine/text-frames.js +29 -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-query-engine/index.js +4 -4
- package/dist/safe-bash-query-engine/interpreter.js +2 -2
- package/dist/safe-bash-query-engine/query-core.js +4 -4
- 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 +9 -5
- 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 +3 -3
- package/dist/safe-bash-xml-engine/stored-document.js +1 -1
- package/dist/safe-bash-xml-engine/stored-evaluate.js +1 -1
- package/dist/safe-bash-zip-engine/zip/repair.js +3 -3
- package/dist/safe-bash-zip-engine/zip/volumes.js +3 -3
- package/dist/spreadsheet-engine/datasource.js +16 -2
- package/dist/spreadsheet-engine/formulas/diagnostics.d.ts +2 -1
- package/dist/spreadsheet-engine/formulas/diagnostics.js +2 -2
- package/dist/spreadsheet-engine/formulas/evaluator.d.ts +1 -1
- package/dist/spreadsheet-engine/formulas/evaluator.js +2 -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 +54 -24
- 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 +95 -175
- package/dist/spreadsheet-format-xls/biff-property-dictionary.d.ts +5 -0
- package/dist/spreadsheet-format-xls/biff-property-dictionary.js +75 -0
- 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-range.d.ts +17 -3
- package/dist/spreadsheet-format-xls/biff-property-range.js +178 -37
- 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 +8 -3
- package/dist/safe-bash/command-chunks/biff-YKPDH35C-MVQIWNKV.js +0 -4974
- package/dist/safe-bash/command-chunks/chunk-2VLAXKTS.js +0 -245
- 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
- package/dist/safe-bash/command-chunks/{chunk-X2HVVMTW.js → chunk-AW4Q3GZW.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-JC2EV66U.js → chunk-BJXADHRT.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-XI2LETBJ.js → chunk-BXU5Y7I5.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-PVLPWVRH.js → chunk-D3HW7R2N.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-OLK3DCJD.js → chunk-DYERIXPU.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-WYBCSJFG.js → chunk-FWCUEZ3K.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-FF2SQ2GP.js → chunk-GGH376XQ.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-D66Q7QJ3.js → chunk-JRSZ5IGD.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-Z3YB4EVE.js → chunk-KSM5CCHT.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-NJ4NTTCR.js → chunk-LNLACEAN.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-NBTG6NF6.js → chunk-LTJRUMK6.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-XCYTG7CR.js → chunk-NJGL5JQ6.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-SZ66JC25.js → chunk-Q7J2NTH2.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-MDV7W5AS.js → chunk-SKNI2XQA.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-7ZWACKCG.js → chunk-T6OXG7QQ.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-ECDEPKKW.js → chunk-W25EIKDJ.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-4YSBUQPV.js → chunk-W2FKFEVY.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-2CIDPOUV.js → chunk-WSNHJZQ5.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-4H3TYOVC.js → chunk-Y7AXMCFV.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-U6IEK2CI.js → chunk-YPG55QTP.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-252L5YC5.js → chunk-Z37OM247.js} +6 -6
- package/dist/safe-bash/command-chunks/{pln-DFS7VLVS-JATX6FS7.js → pln-DFS7VLVS-OVOBS4QX.js} +3 -3
- package/dist/safe-bash/command-chunks/{psion-YBI6JEQI-6OMC2PGC.js → psion-YBI6JEQI-GY4S6ZLC.js} +3 -3
|
@@ -1,50 +1,493 @@
|
|
|
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/info-text.ts
|
|
4
|
+
function decodePdftkEntities(str) {
|
|
5
|
+
let out = "";
|
|
6
|
+
let i = 0;
|
|
7
|
+
while (i < str.length) {
|
|
8
|
+
if (str[i] === "&" && str[i + 1] === "#") {
|
|
9
|
+
const semi = str.indexOf(";", i + 2);
|
|
10
|
+
if (semi !== -1) {
|
|
11
|
+
const body = str.slice(i + 2, semi);
|
|
12
|
+
const cp = body.startsWith("x") || body.startsWith("X") ? Number.parseInt(body.slice(1), 16) : Number.parseInt(body, 10);
|
|
13
|
+
if (Number.isFinite(cp) && cp >= 0) {
|
|
14
|
+
out += String.fromCodePoint(cp);
|
|
15
|
+
i = semi + 1;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
17
18
|
}
|
|
18
19
|
}
|
|
20
|
+
out += str[i];
|
|
21
|
+
i++;
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
function hexToBytes(hex) {
|
|
26
|
+
const clean = hex.trim();
|
|
27
|
+
const len = Math.floor(clean.length / 2);
|
|
28
|
+
const out = new Uint8Array(len);
|
|
29
|
+
for (let i = 0; i < len; i++) {
|
|
30
|
+
const byteVal = Number.parseInt(clean.slice(i * 2, i * 2 + 2), 16);
|
|
31
|
+
out[i] = Number.isNaN(byteVal) ? 0 : byteVal;
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// packages/safe-bash-command-pdftk/src/burst-filename.ts
|
|
37
|
+
function formatBurstFilename(pattern, pageNum) {
|
|
38
|
+
let out = "";
|
|
39
|
+
let replaced = false;
|
|
40
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
41
|
+
if (pattern[i] !== "%") {
|
|
42
|
+
out += pattern[i];
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (pattern[i + 1] === "%") {
|
|
46
|
+
out += "%";
|
|
47
|
+
i++;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (!replaced) {
|
|
51
|
+
let j = i + 1;
|
|
52
|
+
let zeroPad = false;
|
|
53
|
+
if (pattern[j] === "0") {
|
|
54
|
+
zeroPad = true;
|
|
55
|
+
j++;
|
|
56
|
+
}
|
|
57
|
+
let widthStr = "";
|
|
58
|
+
while (j < pattern.length && pattern[j] >= "0" && pattern[j] <= "9") {
|
|
59
|
+
widthStr += pattern[j];
|
|
60
|
+
j++;
|
|
61
|
+
}
|
|
62
|
+
if (pattern[j] === "d") {
|
|
63
|
+
const width = widthStr ? Number.parseInt(widthStr, 10) : 1;
|
|
64
|
+
out += zeroPad ? String(pageNum).padStart(width, "0") : String(pageNum);
|
|
65
|
+
replaced = true;
|
|
66
|
+
i = j;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
out += "%";
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// packages/safe-bash-command-pdftk/src/retained-assembly.ts
|
|
76
|
+
import { IntegerTable as IntegerTable2, PagedStorage as PagedStorage2 } from "@poe-platform/safe-fs/storage";
|
|
77
|
+
import { PdfMutableObjectStore as PdfMutableObjectStore2, PdfNameIndex as PdfNameIndex2, PdfFileSource as PdfFileSource2, createRetainedPageCopy, editRetainedDocument, cosArray, cosDict as cosDict2, cosNumber, cosString as cosString2, decodePdfString as decodePdfString2, dictGet as dictGet2, dictSet } from "../pdf-ast/index.js";
|
|
78
|
+
|
|
79
|
+
// packages/safe-bash-command-pdftk/src/retained-unpack.ts
|
|
80
|
+
import { IntegerTable, PagedStorage } from "@poe-platform/safe-fs/storage";
|
|
81
|
+
import { PdfFileSource, PdfMutableObjectStore, PdfNameIndex, cosDict, cosString, decodePdfString, dictGet } from "../pdf-ast/index.js";
|
|
82
|
+
async function* retainedUnpack(document, storage, directory, inputNames, signal, includeSentinel = false) {
|
|
83
|
+
const names = new PdfNameIndex(storage, Infinity, signal), outputs = new PdfMutableObjectStore(storage, { signal });
|
|
84
|
+
const stack = new PdfMutableObjectStore(storage, { signal }), backing = new PagedStorage({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), seen = new IntegerTable(backing, 64);
|
|
85
|
+
const cleanDir = directory.endsWith("/") ? directory.slice(0, -1) : directory;
|
|
86
|
+
let pending = 0, work = 0, failed = false;
|
|
87
|
+
async function checkpoint() {
|
|
88
|
+
signal.throwIfAborted();
|
|
89
|
+
if (++work % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
19
90
|
signal.throwIfAborted();
|
|
20
|
-
yield encoder.encode(part + "\n");
|
|
21
91
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
92
|
+
async function resolve(node) {
|
|
93
|
+
await checkpoint();
|
|
94
|
+
const found = await document.lookup(node);
|
|
95
|
+
return found?.stream ? void 0 : found?.value;
|
|
96
|
+
}
|
|
97
|
+
async function spec(raw, fallback = "attachment.bin") {
|
|
98
|
+
const dict = await resolve(raw);
|
|
99
|
+
if (dict?.kind !== "dict") return;
|
|
100
|
+
const filename = await resolve(dictGet(dict, "UF") ?? dictGet(dict, "F"));
|
|
101
|
+
const name = filename?.kind === "string" ? decodePdfString(filename) : fallback;
|
|
102
|
+
const leaf = name.slice(Math.max(name.lastIndexOf("/"), name.lastIndexOf("\\")) + 1);
|
|
103
|
+
if (!leaf || leaf === "." || leaf === ".." || leaf.includes("\0")) throw new Error("Invalid embedded attachment filename");
|
|
104
|
+
const ef = await resolve(dictGet(dict, "EF"));
|
|
105
|
+
if (ef?.kind !== "dict") return;
|
|
106
|
+
const data = await document.lookup(dictGet(ef, "UF") ?? dictGet(ef, "F") ?? dictGet(ef, "DOS") ?? dictGet(ef, "Mac") ?? dictGet(ef, "Unix"));
|
|
107
|
+
if (!data?.stream || !data.reference) return;
|
|
108
|
+
const path = cleanDir && cleanDir !== "." ? `${cleanDir}/${leaf}` : leaf;
|
|
109
|
+
const nameIndex = await names.intern(path);
|
|
110
|
+
const staged = await PdfFileSource.fromStream(storage.fs, storage.directory, document.objects.decodeStream(data.reference.objectNumber, data.reference.generationNumber), { signal });
|
|
111
|
+
let failed2 = false;
|
|
112
|
+
try {
|
|
113
|
+
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) } });
|
|
114
|
+
} catch (error) {
|
|
115
|
+
failed2 = true;
|
|
116
|
+
throw error;
|
|
117
|
+
} finally {
|
|
118
|
+
await staged.close().catch((error) => {
|
|
119
|
+
if (!failed2) throw error;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const push = async (value) => {
|
|
124
|
+
await checkpoint();
|
|
125
|
+
await stack.set({ objectNumber: ++pending, generationNumber: 0, value });
|
|
126
|
+
};
|
|
127
|
+
async function associated(raw) {
|
|
128
|
+
const array = await resolve(raw);
|
|
129
|
+
if (array?.kind === "array") for (const item of array.items) await spec(item);
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
for (const name of inputNames) await names.intern(name);
|
|
133
|
+
const root = await resolve(document.crossReference.rootRef);
|
|
134
|
+
if (root?.kind === "dict") {
|
|
135
|
+
const dictionary = await resolve(dictGet(root, "Names")), tree = dictionary?.kind === "dict" ? dictGet(dictionary, "EmbeddedFiles") : void 0;
|
|
136
|
+
if (tree) await push(tree);
|
|
137
|
+
while (pending) {
|
|
138
|
+
await checkpoint();
|
|
139
|
+
const raw = (await stack.get(pending--)).value;
|
|
140
|
+
if (raw.kind === "ref") {
|
|
141
|
+
if (await seen.get(BigInt(raw.objectNumber))) continue;
|
|
142
|
+
await seen.set(BigInt(raw.objectNumber), 1n);
|
|
143
|
+
}
|
|
144
|
+
const branch = await resolve(raw);
|
|
145
|
+
if (branch?.kind !== "dict") continue;
|
|
146
|
+
const pairs = await resolve(dictGet(branch, "Names"));
|
|
147
|
+
if (pairs?.kind === "array") for (let i = 0; i + 1 < pairs.items.length; i += 2) {
|
|
148
|
+
const name = await resolve(pairs.items[i]);
|
|
149
|
+
await spec(pairs.items[i + 1], name?.kind === "string" ? decodePdfString(name) : "attachment.bin");
|
|
150
|
+
}
|
|
151
|
+
const kids = await resolve(dictGet(branch, "Kids"));
|
|
152
|
+
if (kids?.kind === "array") for (let i = kids.items.length - 1; i >= 0; i--) await push(kids.items[i]);
|
|
153
|
+
}
|
|
154
|
+
await associated(dictGet(root, "AF"));
|
|
155
|
+
}
|
|
156
|
+
for await (const page of document.pages()) {
|
|
157
|
+
await associated(dictGet(page.dict, "AF"));
|
|
158
|
+
const annotations = await resolve(dictGet(page.dict, "Annots"));
|
|
159
|
+
if (annotations?.kind === "array") for (const raw of annotations.items) {
|
|
160
|
+
const annotation = await resolve(raw);
|
|
161
|
+
if (annotation?.kind !== "dict") continue;
|
|
162
|
+
const type = await resolve(dictGet(annotation, "Subtype"));
|
|
163
|
+
if (type?.kind === "name" && type.decoded === "FileAttachment") await spec(dictGet(annotation, "FS"));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for await (const output of outputs.objects()) {
|
|
167
|
+
const path = output.value.kind === "dict" ? dictGet(output.value, "Path") : void 0;
|
|
168
|
+
if (path?.kind === "string" && output.stream) {
|
|
169
|
+
const name = decodePdfString(path);
|
|
170
|
+
if (includeSentinel || name !== "-") yield { path: name, chunks: output.stream.chunks };
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} catch (error) {
|
|
174
|
+
failed = true;
|
|
175
|
+
throw error;
|
|
176
|
+
} finally {
|
|
177
|
+
const results = await Promise.allSettled([names.close(), outputs.close(), stack.close(), backing.close()]);
|
|
178
|
+
if (!failed) {
|
|
179
|
+
for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// packages/safe-bash-command-pdftk/src/retained-assembly.ts
|
|
185
|
+
async function assembleRetainedPdftk(primary, storage, options, counts, handles, open, signal) {
|
|
186
|
+
const backing = new PagedStorage2({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
|
|
187
|
+
const sourceBookmarks = new PdfMutableObjectStore2(storage, { signal }), outputBookmarks = new PdfMutableObjectStore2(storage, { signal }), rotations = new PdfMutableObjectStore2(storage, { signal }), attachments = new PdfMutableObjectStore2(storage, { signal });
|
|
188
|
+
const names = new PdfNameIndex2(storage, Infinity, signal);
|
|
189
|
+
const states = /* @__PURE__ */ new Map();
|
|
190
|
+
const used = /* @__PURE__ */ new Set(), rangeHandles = new Map([...handles].map(([handle, input]) => [handle, { pageCount: counts.get(input) }]));
|
|
191
|
+
let current, currentInput, copy, edited;
|
|
192
|
+
let work = 0, attachmentCount = 0, failed = false;
|
|
193
|
+
async function checkpoint() {
|
|
194
|
+
signal.throwIfAborted();
|
|
195
|
+
if (++work % 64 === 0) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
196
|
+
signal.throwIfAborted();
|
|
197
|
+
}
|
|
198
|
+
async function document(input) {
|
|
199
|
+
if (currentInput !== input) {
|
|
200
|
+
await current?.close();
|
|
201
|
+
current = void 0;
|
|
202
|
+
currentInput = void 0;
|
|
203
|
+
current = await open(input);
|
|
204
|
+
currentInput = input;
|
|
205
|
+
}
|
|
206
|
+
return current;
|
|
207
|
+
}
|
|
208
|
+
function* selections() {
|
|
209
|
+
if (!options.opArgs.length) {
|
|
210
|
+
for (const input of options.inputs) for (let pageNumber = 1; pageNumber <= counts.get(input); pageNumber++) yield { handle: input.handle, pageNumber };
|
|
211
|
+
} else if (options.operation === "shuffle") {
|
|
212
|
+
const iterators = options.opArgs.map((arg) => iteratePdftkRangeToken(arg, rangeHandles, options.inputs[0].handle));
|
|
213
|
+
try {
|
|
214
|
+
let pending = true;
|
|
215
|
+
while (pending) {
|
|
216
|
+
pending = false;
|
|
217
|
+
for (const iterator of iterators) {
|
|
218
|
+
const next = iterator.next();
|
|
219
|
+
if (!next.done) {
|
|
220
|
+
pending = true;
|
|
221
|
+
yield next.value;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
} finally {
|
|
226
|
+
for (const iterator of iterators) iterator.return(void 0);
|
|
227
|
+
}
|
|
228
|
+
} else for (const arg of options.opArgs) yield* iteratePdftkRangeToken(arg, rangeHandles, options.inputs[0].handle);
|
|
229
|
+
}
|
|
230
|
+
async function state(input, source) {
|
|
231
|
+
let result = states.get(input);
|
|
232
|
+
if (result) return result;
|
|
233
|
+
result = { bookmarks: new IntegerTable2(backing, 64), resources: new IntegerTable2(backing, 64) };
|
|
234
|
+
states.set(input, result);
|
|
235
|
+
for await (const bookmark of source.outlineDetails()) {
|
|
236
|
+
await checkpoint();
|
|
237
|
+
const key = BigInt(bookmark.pageIndex) * 2n, previous = await result.bookmarks.get(key + 1n);
|
|
238
|
+
const ref = await sourceBookmarks.allocate(cosDict2({ Title: cosString2(bookmark.title), Level: cosNumber(bookmark.level), Next: cosNumber(0) }));
|
|
239
|
+
if (previous) {
|
|
240
|
+
const row = await sourceBookmarks.get(Number(previous));
|
|
241
|
+
if (row.value.kind === "dict") {
|
|
242
|
+
dictSet(row.value, "Next", cosNumber(ref.objectNumber));
|
|
243
|
+
await sourceBookmarks.set(row);
|
|
244
|
+
}
|
|
245
|
+
} else await result.bookmarks.set(key, BigInt(ref.objectNumber));
|
|
246
|
+
await result.bookmarks.set(key + 1n, BigInt(ref.objectNumber));
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
async function* sources() {
|
|
251
|
+
let ordinal = 0, pageIndex = 0;
|
|
252
|
+
for (const selection of selections()) {
|
|
253
|
+
await checkpoint();
|
|
254
|
+
ordinal++;
|
|
255
|
+
const input = handles.get(selection.handle) ?? options.inputs[0], source = await document(input), record = await state(input, source);
|
|
256
|
+
used.add(input);
|
|
257
|
+
yield { document: source, indices: [selection.pageNumber - 1], resourceState: { has: async (index) => Boolean(await record.resources.get(BigInt(index))), add: async (index) => {
|
|
258
|
+
await record.resources.set(BigInt(index), 1n);
|
|
259
|
+
} } };
|
|
260
|
+
if (selection.rotation) await rotations.allocate(cosArray([cosNumber(pageIndex), cosNumber(selection.rotation.degrees), cosNumber(selection.rotation.kind === "relative" ? 1 : 0)]));
|
|
261
|
+
pageIndex++;
|
|
262
|
+
let item = Number(await record.bookmarks.get(BigInt(selection.pageNumber - 1) * 2n) ?? 0n);
|
|
263
|
+
while (item) {
|
|
264
|
+
await checkpoint();
|
|
265
|
+
const row = (await sourceBookmarks.get(item)).value;
|
|
266
|
+
if (row.kind !== "dict") throw new Error("Invalid bookmark record");
|
|
267
|
+
await outputBookmarks.allocate(cosArray([dictGet2(row, "Title"), dictGet2(row, "Level"), cosNumber(ordinal)]));
|
|
268
|
+
const next = dictGet2(row, "Next");
|
|
269
|
+
item = next?.kind === "number" ? next.value : 0;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async function* bookmarkEdits() {
|
|
274
|
+
for await (const object of outputBookmarks.objects()) {
|
|
275
|
+
await checkpoint();
|
|
276
|
+
const value = object.value;
|
|
277
|
+
if (value.kind !== "array" || value.items[0]?.kind !== "string" || value.items[1]?.kind !== "number" || value.items[2]?.kind !== "number") throw new Error("Invalid output bookmark");
|
|
278
|
+
yield { title: decodePdfString2(value.items[0]), level: value.items[1].value, pageNumber: value.items[2].value };
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async function* rotationEdits() {
|
|
282
|
+
for await (const object of rotations.objects()) {
|
|
283
|
+
await checkpoint();
|
|
284
|
+
const value = object.value;
|
|
285
|
+
if (value.kind !== "array" || value.items[0]?.kind !== "number" || value.items[1]?.kind !== "number" || value.items[2]?.kind !== "number") throw new Error("Invalid output rotation");
|
|
286
|
+
yield { pageIndex: value.items[0].value, degrees: value.items[1].value, relative: value.items[2].value === 1 };
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async function* attachmentEdits() {
|
|
290
|
+
for await (const object of attachments.objects()) {
|
|
291
|
+
await checkpoint();
|
|
292
|
+
const name = object.value.kind === "dict" ? dictGet2(object.value, "Filename") : void 0, filename = name?.kind === "string" ? decodePdfString2(name) : "";
|
|
293
|
+
if (object.stream) yield { filename, chunks: (async function* () {
|
|
294
|
+
yield* object.stream.chunks;
|
|
295
|
+
})() };
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
try {
|
|
299
|
+
copy = await createRetainedPageCopy(sources(), storage, { signal, metadata: await primary.info() });
|
|
300
|
+
for (const input of used) {
|
|
301
|
+
await checkpoint();
|
|
302
|
+
const source = await document(input);
|
|
303
|
+
for await (const file of retainedUnpack(source, storage, ".", [], signal, true)) {
|
|
304
|
+
const name = await names.intern(file.path);
|
|
305
|
+
if (name.added) attachmentCount++;
|
|
306
|
+
const payload = await PdfFileSource2.fromStream(storage.fs, storage.directory, file.chunks, { signal });
|
|
307
|
+
let failed2 = false;
|
|
308
|
+
try {
|
|
309
|
+
await attachments.set({ objectNumber: name.index + 1, generationNumber: 0, value: cosDict2({ Filename: cosString2(file.path) }), stream: { length: payload.size, chunks: payload.stream(0, payload.size, signal) } });
|
|
310
|
+
} catch (error) {
|
|
311
|
+
failed2 = true;
|
|
312
|
+
throw error;
|
|
313
|
+
} finally {
|
|
314
|
+
await payload.close().catch((error) => {
|
|
315
|
+
if (!failed2) throw error;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
edited = await editRetainedDocument(await copy.openDocument(), storage, { signal, rotations: rotationEdits(), bookmarks: bookmarkEdits(), ...attachmentCount ? { appendAttachments: attachmentEdits() } : {} });
|
|
321
|
+
const result = edited, pages = copy;
|
|
322
|
+
return { document: result.document, async close() {
|
|
323
|
+
const results = await Promise.allSettled([result.close(), pages.close()]);
|
|
324
|
+
for (const outcome of results) if (outcome.status === "rejected") throw outcome.reason;
|
|
325
|
+
} };
|
|
326
|
+
} catch (error) {
|
|
327
|
+
failed = true;
|
|
328
|
+
await Promise.allSettled([edited?.close(), copy?.close()]);
|
|
329
|
+
throw error;
|
|
330
|
+
} finally {
|
|
331
|
+
const results = await Promise.allSettled([current?.close(), sourceBookmarks.close(), outputBookmarks.close(), rotations.close(), attachments.close(), names.close(), backing.close()]);
|
|
332
|
+
if (!failed) {
|
|
333
|
+
for (const outcome of results) if (outcome.status === "rejected") {
|
|
334
|
+
await Promise.allSettled([edited?.close(), copy?.close()]);
|
|
335
|
+
await Promise.reject(outcome.reason);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// packages/safe-bash-command-pdftk/src/retained-info-updates.ts
|
|
342
|
+
var styles = { DecimalArabicNumerals: "D", UppercaseRomanNumerals: "R", LowercaseRomanNumerals: "r", UppercaseLetters: "A", LowercaseLetters: "a" };
|
|
343
|
+
async function* lines(chunks, signal) {
|
|
344
|
+
const decoder = new TextDecoder();
|
|
345
|
+
let pending = "", work = 0;
|
|
346
|
+
for await (const bytes of chunks) {
|
|
347
|
+
signal.throwIfAborted();
|
|
348
|
+
pending += decoder.decode(bytes, { stream: true });
|
|
349
|
+
let offset = 0, end;
|
|
350
|
+
while ((end = pending.indexOf("\n", offset)) >= 0) {
|
|
351
|
+
if (++work % 64 === 0) {
|
|
352
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
353
|
+
signal.throwIfAborted();
|
|
354
|
+
}
|
|
355
|
+
yield pending.slice(offset, end);
|
|
356
|
+
offset = end + 1;
|
|
357
|
+
}
|
|
358
|
+
pending = pending.slice(offset);
|
|
359
|
+
}
|
|
360
|
+
pending += decoder.decode();
|
|
361
|
+
if (pending) yield pending;
|
|
362
|
+
}
|
|
363
|
+
async function* retainedInfoUpdates(chunks, signal) {
|
|
364
|
+
let mode = "none";
|
|
365
|
+
let curKey = "";
|
|
366
|
+
let bmTitle = "";
|
|
367
|
+
let bmLevel = 1;
|
|
368
|
+
let bmPage = 1;
|
|
369
|
+
const pending = [];
|
|
370
|
+
let plNewIndex = 1;
|
|
371
|
+
let plStart = 1;
|
|
372
|
+
let plPrefix = "";
|
|
373
|
+
let plStyle = "DecimalArabicNumerals";
|
|
374
|
+
let pmNumber = 0;
|
|
375
|
+
let pmRotation;
|
|
376
|
+
let pmMediaRect;
|
|
377
|
+
let pmDimensions;
|
|
378
|
+
let pmCropBox;
|
|
379
|
+
const flushStanza = () => {
|
|
380
|
+
if (mode === "bookmark" && bmTitle) {
|
|
381
|
+
pending.push({ kind: "bookmark", title: bmTitle, level: Math.min(Number.MAX_SAFE_INTEGER, Math.max(1, bmLevel)), pageNumber: Math.min(Number.MAX_SAFE_INTEGER, Math.max(1, bmPage)) });
|
|
382
|
+
} else if (mode === "pagelabel") {
|
|
383
|
+
pending.push({
|
|
384
|
+
kind: "label",
|
|
385
|
+
index: Math.max(0, plNewIndex - 1),
|
|
386
|
+
start: Math.max(1, plStart),
|
|
387
|
+
prefix: plPrefix,
|
|
388
|
+
...styles[plStyle] ? { style: styles[plStyle] } : {}
|
|
389
|
+
});
|
|
390
|
+
} else if (mode === "pagemedia" && pmNumber >= 1) {
|
|
391
|
+
if (pmRotation !== void 0) pending.push({ kind: "page", pageNumber: pmNumber, property: "rotation", values: [Number.isFinite(pmRotation) ? pmRotation : 0] });
|
|
392
|
+
if (pmMediaRect !== void 0) pending.push({ kind: "page", pageNumber: pmNumber, property: "media", values: pmMediaRect });
|
|
393
|
+
if (pmDimensions !== void 0) pending.push({ kind: "page", pageNumber: pmNumber, property: "dimensions", values: pmDimensions });
|
|
394
|
+
if (pmCropBox !== void 0) pending.push({ kind: "page", pageNumber: pmNumber, property: "crop", values: pmCropBox });
|
|
395
|
+
}
|
|
396
|
+
bmTitle = "";
|
|
397
|
+
bmLevel = 1;
|
|
398
|
+
bmPage = 1;
|
|
399
|
+
plNewIndex = 1;
|
|
400
|
+
plStart = 1;
|
|
401
|
+
plPrefix = "";
|
|
402
|
+
plStyle = "DecimalArabicNumerals";
|
|
403
|
+
pmNumber = 0;
|
|
404
|
+
pmRotation = void 0;
|
|
405
|
+
pmMediaRect = void 0;
|
|
406
|
+
pmDimensions = void 0;
|
|
407
|
+
pmCropBox = void 0;
|
|
408
|
+
};
|
|
409
|
+
for await (const raw of lines(chunks, signal)) {
|
|
410
|
+
const line = raw.trim();
|
|
411
|
+
if (line === "InfoBegin") {
|
|
412
|
+
flushStanza();
|
|
413
|
+
yield* pending;
|
|
414
|
+
pending.length = 0;
|
|
415
|
+
mode = "info";
|
|
416
|
+
curKey = "";
|
|
417
|
+
} else if (line === "BookmarkBegin") {
|
|
418
|
+
flushStanza();
|
|
419
|
+
yield* pending;
|
|
420
|
+
pending.length = 0;
|
|
421
|
+
mode = "bookmark";
|
|
422
|
+
} else if (line === "PageLabelBegin") {
|
|
423
|
+
flushStanza();
|
|
424
|
+
yield* pending;
|
|
425
|
+
pending.length = 0;
|
|
426
|
+
mode = "pagelabel";
|
|
427
|
+
} else if (line === "PageMediaBegin") {
|
|
428
|
+
flushStanza();
|
|
429
|
+
yield* pending;
|
|
430
|
+
pending.length = 0;
|
|
431
|
+
mode = "pagemedia";
|
|
432
|
+
} else if (line.startsWith("PdfID0:")) {
|
|
433
|
+
yield { kind: "id", index: 0, bytes: hexToBytes(line.slice("PdfID0:".length)) };
|
|
434
|
+
} else if (line.startsWith("PdfID1:")) {
|
|
435
|
+
yield { kind: "id", index: 1, bytes: hexToBytes(line.slice("PdfID1:".length)) };
|
|
436
|
+
} else if (mode === "info" && line.startsWith("InfoKey:")) {
|
|
437
|
+
curKey = decodePdftkEntities(line.slice("InfoKey:".length).trim());
|
|
438
|
+
} else if (mode === "info" && line.startsWith("InfoValue:") && curKey) {
|
|
439
|
+
const val = decodePdftkEntities(line.slice("InfoValue:".length).trim());
|
|
440
|
+
yield { kind: "info", key: curKey, value: val };
|
|
441
|
+
mode = "none";
|
|
442
|
+
curKey = "";
|
|
443
|
+
} else if (mode === "bookmark" && line.startsWith("BookmarkTitle:")) {
|
|
444
|
+
bmTitle = decodePdftkEntities(line.slice("BookmarkTitle:".length).trim());
|
|
445
|
+
} else if (mode === "bookmark" && line.startsWith("BookmarkLevel:")) {
|
|
446
|
+
bmLevel = Number.parseInt(line.slice("BookmarkLevel:".length).trim(), 10) || 1;
|
|
447
|
+
} else if (mode === "bookmark" && line.startsWith("BookmarkPageNumber:")) {
|
|
448
|
+
bmPage = Number.parseInt(line.slice("BookmarkPageNumber:".length).trim(), 10) || 1;
|
|
449
|
+
} else if (mode === "pagelabel" && line.startsWith("PageLabelNewIndex:")) {
|
|
450
|
+
plNewIndex = Number.parseInt(line.slice("PageLabelNewIndex:".length).trim(), 10) || 1;
|
|
451
|
+
} else if (mode === "pagelabel" && line.startsWith("PageLabelStart:")) {
|
|
452
|
+
plStart = Number.parseInt(line.slice("PageLabelStart:".length).trim(), 10) || 1;
|
|
453
|
+
} else if (mode === "pagelabel" && line.startsWith("PageLabelPrefix:")) {
|
|
454
|
+
plPrefix = decodePdftkEntities(line.slice("PageLabelPrefix:".length).trim());
|
|
455
|
+
} else if (mode === "pagelabel" && line.startsWith("PageLabelNumStyle:")) {
|
|
456
|
+
plStyle = line.slice("PageLabelNumStyle:".length).trim();
|
|
457
|
+
} else if (mode === "pagemedia" && line.startsWith("PageMediaNumber:")) {
|
|
458
|
+
pmNumber = Number.parseInt(line.slice("PageMediaNumber:".length).trim(), 10) || 0;
|
|
459
|
+
} else if (mode === "pagemedia" && line.startsWith("PageMediaRotation:")) {
|
|
460
|
+
pmRotation = Number.parseInt(line.slice("PageMediaRotation:".length).trim(), 10) || 0;
|
|
461
|
+
} else if (mode === "pagemedia" && line.startsWith("PageMediaRect:")) {
|
|
462
|
+
const parts = line.slice("PageMediaRect:".length).trim().split(" ").filter(Boolean).map(Number);
|
|
463
|
+
if (parts.length >= 4 && parts.every(Number.isFinite)) {
|
|
464
|
+
pmMediaRect = [parts[0], parts[1], parts[2], parts[3]];
|
|
465
|
+
}
|
|
466
|
+
} else if (mode === "pagemedia" && line.startsWith("PageMediaDimensions:")) {
|
|
467
|
+
const parts = line.slice("PageMediaDimensions:".length).trim().split(" ").filter(Boolean).map(Number);
|
|
468
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
469
|
+
pmDimensions = [parts[0], parts[1]];
|
|
470
|
+
}
|
|
471
|
+
} else if (mode === "pagemedia" && (line.startsWith("PageMediaCropBox:") || line.startsWith("PageMediaCropRect:"))) {
|
|
472
|
+
const prefix = line.startsWith("PageMediaCropRect:") ? "PageMediaCropRect:" : "PageMediaCropBox:";
|
|
473
|
+
const parts = line.slice(prefix.length).trim().split(" ").filter(Boolean).map(Number);
|
|
474
|
+
if (parts.length >= 4 && parts.every(Number.isFinite)) {
|
|
475
|
+
pmCropBox = [parts[0], parts[1], parts[2], parts[3]];
|
|
476
|
+
}
|
|
477
|
+
}
|
|
33
478
|
}
|
|
479
|
+
flushStanza();
|
|
480
|
+
yield* pending;
|
|
34
481
|
}
|
|
35
482
|
|
|
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";
|
|
483
|
+
// packages/safe-bash-command-pdftk/src/retained-burst.ts
|
|
484
|
+
import { createRetainedPageCopy as createRetainedPageCopy2, saveRetainedDocumentChunks } from "../pdf-ast/index.js";
|
|
42
485
|
|
|
43
|
-
// packages/safe-bash-command-pdftk/src/retained-
|
|
44
|
-
import { IntegerTable, PagedStorage } from "@poe-platform/safe-fs/storage";
|
|
45
|
-
import { PdfMutableObjectStore, decodePdfString, dictGet } from "../pdf-ast/index.js";
|
|
46
|
-
async function*
|
|
47
|
-
const backing = new
|
|
486
|
+
// packages/safe-bash-command-pdftk/src/retained-inspection.ts
|
|
487
|
+
import { IntegerTable as IntegerTable3, PagedStorage as PagedStorage3 } from "@poe-platform/safe-fs/storage";
|
|
488
|
+
import { PdfMutableObjectStore as PdfMutableObjectStore3, PdfNameIndex as PdfNameIndex3, cosArray as cosArray2, cosNumber as cosNumber2, decodePdfString as decodePdfString3, dictGet as dictGet3 } from "../pdf-ast/index.js";
|
|
489
|
+
async function* retainedInspectionReport(document, storage, utf8, signal, kind) {
|
|
490
|
+
const backing = new PagedStorage3({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4), pages = new IntegerTable3(backing, 64);
|
|
48
491
|
let pageCount = 0, work = 0, failed = false;
|
|
49
492
|
const encoder = new TextEncoder();
|
|
50
493
|
async function checkpoint() {
|
|
@@ -72,29 +515,37 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
72
515
|
}
|
|
73
516
|
async function* walk(start, key) {
|
|
74
517
|
if (!start) return;
|
|
75
|
-
const stack = new
|
|
518
|
+
const stack = new PdfMutableObjectStore3(storage, { signal }), seen = new IntegerTable3(backing, 64);
|
|
76
519
|
let pending = 0, failed2 = false;
|
|
77
|
-
const push = async (value) => {
|
|
520
|
+
const push = async (value, level = 1) => {
|
|
78
521
|
await checkpoint();
|
|
79
|
-
await stack.set({ objectNumber: ++pending, generationNumber: 0, value });
|
|
522
|
+
await stack.set({ objectNumber: ++pending, generationNumber: 0, value: cosArray2([value, cosNumber2(level)]) });
|
|
80
523
|
};
|
|
81
524
|
try {
|
|
82
525
|
await push(start);
|
|
83
526
|
while (pending) {
|
|
84
527
|
await checkpoint();
|
|
85
|
-
const
|
|
528
|
+
const frame = (await stack.get(pending--)).value;
|
|
529
|
+
if (frame.kind !== "array") continue;
|
|
530
|
+
const raw = frame.items[0], levelNode = frame.items[1], level = levelNode.kind === "number" ? levelNode.value : 1;
|
|
86
531
|
if (raw.kind === "ref") {
|
|
87
532
|
if (await seen.get(BigInt(raw.objectNumber))) continue;
|
|
88
533
|
await seen.set(BigInt(raw.objectNumber), 1n);
|
|
89
534
|
}
|
|
90
535
|
const value = await resolve(raw);
|
|
91
536
|
if (value?.kind === "array" && key === "Next") {
|
|
92
|
-
for (let i = value.items.length - 1; i >= 0; i--) await push(value.items[i]);
|
|
537
|
+
for (let i = value.items.length - 1; i >= 0; i--) await push(value.items[i], level);
|
|
93
538
|
continue;
|
|
94
539
|
}
|
|
95
540
|
if (value?.kind !== "dict") continue;
|
|
96
|
-
yield value;
|
|
97
|
-
|
|
541
|
+
yield { dict: value, level };
|
|
542
|
+
if (key === "Outlines") {
|
|
543
|
+
const next = dictGet3(value, "Next"), first = dictGet3(value, "First");
|
|
544
|
+
if (next) await push(next, level);
|
|
545
|
+
if (first) await push(first, level + 1);
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
const child = dictGet3(value, key);
|
|
98
549
|
if (key === "Next") {
|
|
99
550
|
if (child) await push(child);
|
|
100
551
|
} else {
|
|
@@ -114,23 +565,23 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
114
565
|
async function destinationIndex(raw) {
|
|
115
566
|
let node = await resolve(raw);
|
|
116
567
|
if (node?.kind === "dict") {
|
|
117
|
-
const target =
|
|
568
|
+
const target = dictGet3(node, "D") ?? dictGet3(node, "Dest");
|
|
118
569
|
if (target) node = await resolve(target);
|
|
119
570
|
}
|
|
120
571
|
if (node?.kind === "string" || node?.kind === "name") {
|
|
121
|
-
const name = node.kind === "string" ?
|
|
572
|
+
const name = node.kind === "string" ? decodePdfString3(node) : node.decoded;
|
|
122
573
|
const root = await resolve(document.crossReference.rootRef);
|
|
123
574
|
let target;
|
|
124
575
|
if (root?.kind === "dict") {
|
|
125
|
-
const legacy = await resolve(
|
|
126
|
-
if (legacy?.kind === "dict") target =
|
|
576
|
+
const legacy = await resolve(dictGet3(root, "Dests"));
|
|
577
|
+
if (legacy?.kind === "dict") target = dictGet3(legacy, name);
|
|
127
578
|
if (!target) {
|
|
128
|
-
const names = await resolve(
|
|
129
|
-
if (names?.kind === "dict") for await (const branch of walk(
|
|
130
|
-
const pairs = await resolve(
|
|
579
|
+
const names = await resolve(dictGet3(root, "Names"));
|
|
580
|
+
if (names?.kind === "dict") for await (const { dict: branch } of walk(dictGet3(names, "Dests"), "Kids")) {
|
|
581
|
+
const pairs = await resolve(dictGet3(branch, "Names"));
|
|
131
582
|
if (pairs?.kind === "array") for (let i = 0; i + 1 < pairs.items.length; i += 2) {
|
|
132
583
|
const key = await resolve(pairs.items[i]);
|
|
133
|
-
if ((key?.kind === "string" ?
|
|
584
|
+
if ((key?.kind === "string" ? decodePdfString3(key) : key?.kind === "name" ? key.decoded : "") === name) {
|
|
134
585
|
target = pairs.items[i + 1];
|
|
135
586
|
break;
|
|
136
587
|
}
|
|
@@ -141,7 +592,7 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
141
592
|
}
|
|
142
593
|
node = await resolve(target);
|
|
143
594
|
if (node?.kind === "dict") {
|
|
144
|
-
const inner =
|
|
595
|
+
const inner = dictGet3(node, "D");
|
|
145
596
|
if (inner) node = await resolve(inner);
|
|
146
597
|
}
|
|
147
598
|
}
|
|
@@ -156,7 +607,7 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
156
607
|
}
|
|
157
608
|
async function destinationText(raw) {
|
|
158
609
|
const node = await resolve(raw);
|
|
159
|
-
if (node?.kind === "string") return
|
|
610
|
+
if (node?.kind === "string") return decodePdfString3(node);
|
|
160
611
|
if (node?.kind === "name") return node.decoded;
|
|
161
612
|
if (node?.kind === "array") {
|
|
162
613
|
const first = node.items[0];
|
|
@@ -172,14 +623,48 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
172
623
|
return;
|
|
173
624
|
}
|
|
174
625
|
async function* stringField(dict, key, label) {
|
|
175
|
-
const node = await resolve(
|
|
176
|
-
if (node?.kind === "string") yield* line(label,
|
|
626
|
+
const node = await resolve(dictGet3(dict, key));
|
|
627
|
+
if (node?.kind === "string") yield* line(label, decodePdfString3(node), true);
|
|
177
628
|
}
|
|
178
629
|
try {
|
|
179
630
|
for await (const page of document.pages()) {
|
|
180
631
|
pageCount++;
|
|
181
632
|
if (page.reference && !await pages.get(BigInt(page.reference.objectNumber))) await pages.set(BigInt(page.reference.objectNumber), BigInt(page.index + 1));
|
|
182
633
|
}
|
|
634
|
+
if (kind === "document") {
|
|
635
|
+
const emitted = new PdfNameIndex3(storage, Infinity, signal);
|
|
636
|
+
let failed2 = false;
|
|
637
|
+
try {
|
|
638
|
+
const info = await resolve(document.crossReference.infoRef);
|
|
639
|
+
if (info?.kind === "dict") {
|
|
640
|
+
for (const key of ["Title", "Author", "Subject", "Keywords", "Creator", "Producer"]) {
|
|
641
|
+
const node = await resolve(dictGet3(info, key));
|
|
642
|
+
const value = node?.kind === "string" ? decodePdfString3(node) : node?.kind === "name" ? node.decoded : "";
|
|
643
|
+
if (value) {
|
|
644
|
+
await emitted.intern(key);
|
|
645
|
+
yield* line("", "InfoBegin");
|
|
646
|
+
yield* line("InfoKey: ", key, true);
|
|
647
|
+
yield* line("InfoValue: ", value, true);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
for (const entry of info.entries) {
|
|
651
|
+
const node = await resolve(entry.value), value = node?.kind === "string" ? decodePdfString3(node) : "";
|
|
652
|
+
if (value && (await emitted.intern(entry.key.decoded)).added) {
|
|
653
|
+
yield* line("", "InfoBegin");
|
|
654
|
+
yield* line("InfoKey: ", entry.key.decoded, true);
|
|
655
|
+
yield* line("InfoValue: ", value, true);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
} catch (error) {
|
|
660
|
+
failed2 = true;
|
|
661
|
+
throw error;
|
|
662
|
+
} finally {
|
|
663
|
+
await emitted.close().catch((error) => {
|
|
664
|
+
if (!failed2) throw error;
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
}
|
|
183
668
|
for (let i = 0; i < 2; i++) {
|
|
184
669
|
const id = await resolve(document.crossReference.idArray?.items[i]);
|
|
185
670
|
if (id?.kind !== "string") yield* line(`PdfID${i}: `, "00000000000000000000000000000000");
|
|
@@ -195,13 +680,82 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
195
680
|
}
|
|
196
681
|
}
|
|
197
682
|
yield* line("NumberOfPages: ", pageCount);
|
|
683
|
+
if (kind === "document") {
|
|
684
|
+
const catalog = await resolve(document.crossReference.rootRef);
|
|
685
|
+
const outlines = catalog?.kind === "dict" ? await resolve(dictGet3(catalog, "Outlines")) : void 0;
|
|
686
|
+
if (outlines?.kind === "dict") for await (const { dict, level } of walk(dictGet3(outlines, "First"), "Outlines")) {
|
|
687
|
+
const titleNode = await resolve(dictGet3(dict, "Title"));
|
|
688
|
+
const title = titleNode?.kind === "string" ? decodePdfString3(titleNode) : titleNode?.kind === "name" ? titleNode.decoded : "";
|
|
689
|
+
const index = await destinationIndex(dictGet3(dict, "Dest") ?? dictGet3(dict, "A"));
|
|
690
|
+
if (title) {
|
|
691
|
+
yield* line("", "BookmarkBegin");
|
|
692
|
+
yield* line("BookmarkTitle: ", title, true);
|
|
693
|
+
yield* line("BookmarkLevel: ", level);
|
|
694
|
+
yield* line("BookmarkPageNumber: ", index === void 0 ? 1 : index + 1);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
async function rectangle(raw, strict) {
|
|
698
|
+
const node = await resolve(raw);
|
|
699
|
+
if (node?.kind !== "array" || node.items.length < 4) return;
|
|
700
|
+
const result = [];
|
|
701
|
+
for (const item of node.items.slice(0, 4)) {
|
|
702
|
+
const number = await resolve(item);
|
|
703
|
+
if (strict && number?.kind !== "number") return;
|
|
704
|
+
result.push(number?.kind === "number" ? number.value : 0);
|
|
705
|
+
}
|
|
706
|
+
return result;
|
|
707
|
+
}
|
|
708
|
+
for await (const page of document.pages()) {
|
|
709
|
+
let media, rotate, hasMedia = false, hasRotate = false;
|
|
710
|
+
for await (const parent of document.pageAncestors(page.dict)) {
|
|
711
|
+
if (!hasMedia && dictGet3(parent, "MediaBox")) {
|
|
712
|
+
hasMedia = true;
|
|
713
|
+
media = dictGet3(parent, "MediaBox");
|
|
714
|
+
}
|
|
715
|
+
if (!hasRotate && dictGet3(parent, "Rotate")) {
|
|
716
|
+
hasRotate = true;
|
|
717
|
+
rotate = dictGet3(parent, "Rotate");
|
|
718
|
+
}
|
|
719
|
+
if (hasMedia && hasRotate) break;
|
|
720
|
+
}
|
|
721
|
+
const box = await rectangle(media, true) ?? [0, 0, 612, 792], width = Math.abs(box[2] - box[0]), height = Math.abs(box[3] - box[1]);
|
|
722
|
+
const rotation = await resolve(rotate), norm = rotation?.kind === "number" ? (rotation.value % 360 + 360) % 360 : 0;
|
|
723
|
+
const direct = await rectangle(dictGet3(page.dict, "MediaBox"), false) ?? [0, 0, width, height];
|
|
724
|
+
yield* line("", "PageMediaBegin");
|
|
725
|
+
yield* line("PageMediaNumber: ", page.index + 1);
|
|
726
|
+
yield* line("PageMediaRotation: ", norm === 90 || norm === 180 || norm === 270 ? norm : 0);
|
|
727
|
+
yield* line("PageMediaRect: ", direct.join(" "));
|
|
728
|
+
yield* line("PageMediaDimensions: ", `${width} ${height}`);
|
|
729
|
+
const crop = await rectangle(dictGet3(page.dict, "CropBox"), false);
|
|
730
|
+
if (crop) {
|
|
731
|
+
yield* line("PageMediaCropBox: ", crop.join(" "));
|
|
732
|
+
yield* line("PageMediaCropRect: ", crop.join(" "));
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
const styles2 = { D: "DecimalArabicNumerals", R: "UppercaseRomanNumerals", r: "LowercaseRomanNumerals", A: "UppercaseLetters", a: "LowercaseLetters" };
|
|
736
|
+
if (catalog?.kind === "dict") for await (const { dict } of walk(dictGet3(catalog, "PageLabels"), "Kids")) {
|
|
737
|
+
const pairs = await resolve(dictGet3(dict, "Nums"));
|
|
738
|
+
if (pairs?.kind !== "array") continue;
|
|
739
|
+
for (let i = 0; i + 1 < pairs.items.length; i += 2) {
|
|
740
|
+
const number = await resolve(pairs.items[i]), label = await resolve(pairs.items[i + 1]);
|
|
741
|
+
if (number?.kind !== "number" || label?.kind !== "dict") continue;
|
|
742
|
+
const start = await resolve(dictGet3(label, "St")), prefix = await resolve(dictGet3(label, "P")), style = await resolve(dictGet3(label, "S"));
|
|
743
|
+
yield* line("", "PageLabelBegin");
|
|
744
|
+
yield* line("PageLabelNewIndex: ", Math.max(1, number.value + 1));
|
|
745
|
+
yield* line("PageLabelStart: ", start?.kind === "number" ? start.value : 1);
|
|
746
|
+
if (prefix?.kind === "string" && decodePdfString3(prefix)) yield* line("PageLabelPrefix: ", decodePdfString3(prefix), true);
|
|
747
|
+
yield* line("PageLabelNumStyle: ", style?.kind === "name" ? styles2[style.decoded] ?? "NoNumber" : "NoNumber");
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
198
752
|
for await (const page of document.pages()) {
|
|
199
|
-
const annotations = await resolve(
|
|
753
|
+
const annotations = await resolve(dictGet3(page.dict, "Annots"));
|
|
200
754
|
if (annotations?.kind !== "array") continue;
|
|
201
755
|
for (const item of annotations.items) {
|
|
202
756
|
const annotation = await resolve(item);
|
|
203
757
|
if (annotation?.kind !== "dict") continue;
|
|
204
|
-
const subtype = await resolve(
|
|
758
|
+
const subtype = await resolve(dictGet3(annotation, "Subtype")), rect = await resolve(dictGet3(annotation, "Rect"));
|
|
205
759
|
const numbers = [];
|
|
206
760
|
if (rect?.kind === "array") for (const value of rect.items) {
|
|
207
761
|
const number = await resolve(value);
|
|
@@ -212,7 +766,7 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
212
766
|
yield* line("AnnotSubtype: ", subtype?.kind === "name" ? subtype.decoded : "Annot");
|
|
213
767
|
yield* line("AnnotRect: ", numbers.join(" "));
|
|
214
768
|
for (const [key, label] of [["NM", "Name"], ["T", "Title"], ["Subj", "Subj"], ["Contents", "Contents"]]) yield* stringField(annotation, key, `Annot${label}: `);
|
|
215
|
-
const color = await resolve(
|
|
769
|
+
const color = await resolve(dictGet3(annotation, "C"));
|
|
216
770
|
if (color?.kind === "array" && color.items.length >= 3) {
|
|
217
771
|
const channels = [];
|
|
218
772
|
for (const value of color.items.slice(0, 3)) {
|
|
@@ -221,31 +775,31 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
221
775
|
}
|
|
222
776
|
yield* line("AnnotColor: ", channels.join(" "));
|
|
223
777
|
}
|
|
224
|
-
const open = await resolve(
|
|
778
|
+
const open = await resolve(dictGet3(annotation, "Open"));
|
|
225
779
|
if (open?.kind === "boolean") yield* line("AnnotOpen: ", open.value);
|
|
226
780
|
yield* stringField(annotation, "M", "AnnotModificationDate: ");
|
|
227
|
-
const flags = await resolve(
|
|
781
|
+
const flags = await resolve(dictGet3(annotation, "F"));
|
|
228
782
|
yield* line("AnnotFlags: ", flags?.kind === "number" ? flags.value : 0);
|
|
229
783
|
yield* line("AnnotPageNumber: ", page.index + 1);
|
|
230
|
-
const action =
|
|
231
|
-
if (action) for await (const dict of walk(action, "Next")) {
|
|
232
|
-
const type = await resolve(
|
|
784
|
+
const action = dictGet3(annotation, "A");
|
|
785
|
+
if (action) for await (const { dict } of walk(action, "Next")) {
|
|
786
|
+
const type = await resolve(dictGet3(dict, "S"));
|
|
233
787
|
if (type?.kind === "name" && type.decoded) yield* line("AnnotActionType: ", type.decoded);
|
|
234
788
|
yield* stringField(dict, "URI", "AnnotActionURI: ");
|
|
235
|
-
const dest =
|
|
789
|
+
const dest = dictGet3(dict, "D"), text = await destinationText(dest);
|
|
236
790
|
if (text) yield* line("AnnotActionDest: ", text, true);
|
|
237
791
|
const index = await destinationIndex(dest ?? dict);
|
|
238
792
|
if (index !== void 0) yield* line("AnnotActionPageNumber: ", index + 1);
|
|
239
|
-
const file = await resolve(
|
|
240
|
-
if (file?.kind === "string") yield* line("AnnotActionFile: ",
|
|
793
|
+
const file = await resolve(dictGet3(dict, "F"));
|
|
794
|
+
if (file?.kind === "string") yield* line("AnnotActionFile: ", decodePdfString3(file), true);
|
|
241
795
|
else if (file?.kind === "dict") {
|
|
242
|
-
const name = await resolve(
|
|
243
|
-
if (name?.kind === "string") yield* line("AnnotActionFile: ",
|
|
796
|
+
const name = await resolve(dictGet3(file, "UF") ?? dictGet3(file, "F"));
|
|
797
|
+
if (name?.kind === "string") yield* line("AnnotActionFile: ", decodePdfString3(name), true);
|
|
244
798
|
}
|
|
245
799
|
}
|
|
246
|
-
else if (
|
|
800
|
+
else if (dictGet3(annotation, "Dest")) {
|
|
247
801
|
yield* line("AnnotActionType: ", "GoTo");
|
|
248
|
-
const dest =
|
|
802
|
+
const dest = dictGet3(annotation, "Dest"), text = await destinationText(dest);
|
|
249
803
|
if (text) yield* line("AnnotActionDest: ", text, true);
|
|
250
804
|
const index = await destinationIndex(dest);
|
|
251
805
|
if (index !== void 0) yield* line("AnnotActionPageNumber: ", index + 1);
|
|
@@ -262,10 +816,365 @@ async function* retainedAnnotationReport(document, storage, utf8, signal) {
|
|
|
262
816
|
}
|
|
263
817
|
}
|
|
264
818
|
|
|
819
|
+
// packages/safe-bash-command-pdftk/src/retained-burst.ts
|
|
820
|
+
async function* retainedBurst(document, storage, options, pageCount, signal) {
|
|
821
|
+
const pattern = options.outputTarget ?? "pg_%04d.pdf";
|
|
822
|
+
const slash = pattern.lastIndexOf("/");
|
|
823
|
+
const report = slash < 0 ? "doc_data.txt" : `${pattern.slice(0, slash + 1)}doc_data.txt`;
|
|
824
|
+
const repeated = formatBurstFilename(pattern, 1) === formatBurstFilename(pattern, 2);
|
|
825
|
+
for (let index = repeated ? Math.max(0, pageCount - 1) : 0; index < pageCount; index++) {
|
|
826
|
+
signal.throwIfAborted();
|
|
827
|
+
const path = formatBurstFilename(pattern, index + 1);
|
|
828
|
+
if (path === "-" || path === report) continue;
|
|
829
|
+
const copy = await createRetainedPageCopy2(document, [index], storage, { signal });
|
|
830
|
+
let failed = false;
|
|
831
|
+
try {
|
|
832
|
+
const chunks = options.compressStreams || options.uncompressStreams ? saveRetainedDocumentChunks(await copy.openDocument(), storage, { signal, streamMode: options.uncompressStreams ? "uncompress" : "compress" }) : copy.chunks();
|
|
833
|
+
yield { path, chunks };
|
|
834
|
+
} catch (error) {
|
|
835
|
+
failed = true;
|
|
836
|
+
throw error;
|
|
837
|
+
} finally {
|
|
838
|
+
await copy.close().catch((error) => {
|
|
839
|
+
if (!failed) throw error;
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
yield { path: report, chunks: retainedInspectionReport(document, storage, false, signal, "document") };
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
// packages/safe-bash-command-pdftk/src/retained-rotate.ts
|
|
847
|
+
import { PagedStorage as PagedStorage4 } from "@poe-platform/safe-fs/storage";
|
|
848
|
+
async function* retainedRotations(args, handles, primaryHandle, pageCount, storage, signal) {
|
|
849
|
+
const records = new PagedStorage4({ fs: storage.fs, cwd: storage.directory, env: {}, signal }, 4);
|
|
850
|
+
const base = records.allocate(pageCount * 16);
|
|
851
|
+
let failed = false, work = 0;
|
|
852
|
+
try {
|
|
853
|
+
for (const arg of args) for (const selection of iteratePdftkRangeToken(arg, handles, primaryHandle)) {
|
|
854
|
+
signal.throwIfAborted();
|
|
855
|
+
if (++work % 64 === 0) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
856
|
+
if (!selection.rotation || selection.pageNumber > pageCount) continue;
|
|
857
|
+
const bytes = new Uint8Array(16), view = new DataView(bytes.buffer);
|
|
858
|
+
view.setFloat64(0, selection.rotation.kind === "relative" ? 2 : 1);
|
|
859
|
+
view.setFloat64(8, selection.rotation.degrees);
|
|
860
|
+
await records.write(base + (selection.pageNumber - 1) * 16, bytes);
|
|
861
|
+
}
|
|
862
|
+
for (let pageIndex = 0; pageIndex < pageCount; pageIndex++) {
|
|
863
|
+
signal.throwIfAborted();
|
|
864
|
+
if (++work % 64 === 0) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
865
|
+
const bytes = await records.read(base + pageIndex * 16, 16), view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length), kind = view.getFloat64(0);
|
|
866
|
+
if (kind) yield { pageIndex, degrees: view.getFloat64(8), relative: kind === 2 };
|
|
867
|
+
}
|
|
868
|
+
} catch (error) {
|
|
869
|
+
failed = true;
|
|
870
|
+
throw error;
|
|
871
|
+
} finally {
|
|
872
|
+
await records.close().catch((error) => {
|
|
873
|
+
if (!failed) throw error;
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// packages/safe-bash-command-pdftk/src/retained-output.ts
|
|
879
|
+
import { editRetainedDocument as editRetainedDocument2, PdfFileSource as PdfFileSource3, PdfMutableObjectStore as PdfMutableObjectStore4, PdfRetainedDocument, cosBool, dictDelete, dictGet as dictGet4, dictSet as dictSet2, encryptRetainedPdfChunks, retainedCosObjects, saveRetainedDocumentChunks as saveRetainedDocumentChunks2 } from "../pdf-ast/index.js";
|
|
880
|
+
async function* retainedOutput(source, storage, options, selectedId, signal, handles, pageCount, attachments, attachmentPage, stamps, info) {
|
|
881
|
+
const infoUpdates = info?.updates;
|
|
882
|
+
const store = new PdfMutableObjectStore4(storage, { signal });
|
|
883
|
+
let edited;
|
|
884
|
+
let document, plaintext, failed = false;
|
|
885
|
+
try {
|
|
886
|
+
if (options.operation === "attach_files" || stamps || infoUpdates) {
|
|
887
|
+
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;
|
|
888
|
+
edited = await editRetainedDocument2(source, storage, { signal, ...infoUpdates ? { infoUpdates } : {}, ...options.operation === "attach_files" ? { appendAttachments: attachments } : {}, ...stamps ? { stamps } : {}, ...pageIndex !== void 0 ? { attachmentPageIndex: pageIndex } : {} });
|
|
889
|
+
}
|
|
890
|
+
const input = edited?.document ?? source;
|
|
891
|
+
const pageReferences = edited ? { pageReferences: async function* () {
|
|
892
|
+
for await (const page of input.pages()) if (page.reference) yield page.reference;
|
|
893
|
+
} } : {};
|
|
894
|
+
for await (const object of retainedCosObjects(input, storage, { signal })) await store.set(object);
|
|
895
|
+
const reference = input.crossReference;
|
|
896
|
+
const chosenId = info?.useUpdatedId ? reference.idArray : selectedId;
|
|
897
|
+
const idArray = options.keepFinalId || options.keepFirstId ? chosenId ?? reference.idArray : reference.idArray ?? chosenId;
|
|
898
|
+
document = await PdfRetainedDocument.openStore(store, storage, { rootRef: reference.rootRef, version: reference.version, ...pageReferences, ...reference.infoRef ? { infoRef: reference.infoRef } : {}, ...idArray ? { idArray } : {}, signal });
|
|
899
|
+
const root = await document.lookup(reference.rootRef);
|
|
900
|
+
if (root?.value.kind === "dict" && !root.stream && root.reference) {
|
|
901
|
+
const form = await document.lookup(dictGet4(root.value, "AcroForm"));
|
|
902
|
+
if (form?.value.kind === "dict" && !form.stream) {
|
|
903
|
+
if (options.dropXfa) dictDelete(form.value, "XFA");
|
|
904
|
+
if (options.needAppearances) dictSet2(form.value, "NeedAppearances", cosBool(true));
|
|
905
|
+
if (form.reference) await store.set({ objectNumber: form.reference.objectNumber, generationNumber: form.reference.generationNumber, value: form.value });
|
|
906
|
+
else dictSet2(root.value, "AcroForm", form.value);
|
|
907
|
+
}
|
|
908
|
+
await store.set({ objectNumber: root.reference.objectNumber, generationNumber: root.reference.generationNumber, value: root.value });
|
|
909
|
+
}
|
|
910
|
+
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" });
|
|
911
|
+
if (!options.userPassword && !options.ownerPassword) {
|
|
912
|
+
yield* chunks;
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
plaintext = await PdfFileSource3.fromStream(storage.fs, storage.directory, chunks, { signal });
|
|
916
|
+
const allow = options.allowPermissions, all = allow.has("allfeatures");
|
|
917
|
+
yield* encryptRetainedPdfChunks(plaintext, storage, {
|
|
918
|
+
userPassword: options.userPassword ?? "",
|
|
919
|
+
ownerPassword: options.ownerPassword ?? options.userPassword ?? "owner",
|
|
920
|
+
revision: 6,
|
|
921
|
+
signal,
|
|
922
|
+
...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") } } : {}
|
|
923
|
+
});
|
|
924
|
+
} catch (error) {
|
|
925
|
+
failed = true;
|
|
926
|
+
throw error;
|
|
927
|
+
} finally {
|
|
928
|
+
const results = await Promise.allSettled([document?.close(), plaintext?.close(), store.close(), edited?.close()]);
|
|
929
|
+
if (!failed) {
|
|
930
|
+
for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// packages/safe-bash-command-pdftk/src/retained-fdf.ts
|
|
936
|
+
import { PdfError, PdfFileSource as PdfFileSource4, PdfMutableObjectStore as PdfMutableObjectStore5, PdfNameIndex as PdfNameIndex4, cosArray as cosArray3, cosDict as cosDict3, cosNumber as cosNumber3, cosString as cosString3, decodePdfString as decodePdfString4, dictGet as dictGet5 } from "../pdf-ast/index.js";
|
|
937
|
+
async function* retainedFdf(document, storage, signal) {
|
|
938
|
+
const names = new PdfNameIndex4(storage, Infinity, signal);
|
|
939
|
+
const values = new PdfMutableObjectStore5(storage, { signal });
|
|
940
|
+
const tree = new PdfMutableObjectStore5(storage, { signal });
|
|
941
|
+
const encoder = new TextEncoder();
|
|
942
|
+
let work = 0, failed = false;
|
|
943
|
+
async function checkpoint() {
|
|
944
|
+
signal.throwIfAborted();
|
|
945
|
+
if (++work % 64 === 0) await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
946
|
+
signal.throwIfAborted();
|
|
947
|
+
}
|
|
948
|
+
async function resolve(node) {
|
|
949
|
+
await checkpoint();
|
|
950
|
+
const found = await document.lookup(node);
|
|
951
|
+
return found?.stream ? void 0 : found?.value;
|
|
952
|
+
}
|
|
953
|
+
async function* text(value, escape = false) {
|
|
954
|
+
let chunk = "";
|
|
955
|
+
for (const char of value) {
|
|
956
|
+
chunk += escape ? char === "\\" || char === "(" || char === ")" ? `\\${char}` : char === "\r" ? "\\r" : char === "\n" ? "\\n" : char : char;
|
|
957
|
+
if (chunk.length >= 4096) {
|
|
958
|
+
await checkpoint();
|
|
959
|
+
yield encoder.encode(chunk);
|
|
960
|
+
chunk = "";
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
if (chunk) {
|
|
964
|
+
signal.throwIfAborted();
|
|
965
|
+
yield encoder.encode(chunk);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
async function* fieldValue(field) {
|
|
969
|
+
if (field.checked !== void 0) {
|
|
970
|
+
yield* text(`/${field.checked ? field.stateValue ?? "Yes" : "Off"}`);
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
let count = 0;
|
|
974
|
+
for await (const ignored of field.values()) {
|
|
975
|
+
void ignored;
|
|
976
|
+
if (++count > 1) break;
|
|
977
|
+
}
|
|
978
|
+
if (count > 1) yield* text("[ ");
|
|
979
|
+
let first = true;
|
|
980
|
+
for await (const value of field.values()) {
|
|
981
|
+
if (!first) yield* text(" ");
|
|
982
|
+
first = false;
|
|
983
|
+
yield* text("(");
|
|
984
|
+
yield* text(value, true);
|
|
985
|
+
yield* text(")");
|
|
986
|
+
}
|
|
987
|
+
if (count > 1) yield* text(" ]");
|
|
988
|
+
}
|
|
989
|
+
async function record(id) {
|
|
990
|
+
const node = (await tree.get(id))?.value;
|
|
991
|
+
if (node?.kind !== "array") throw new PdfError("E_PARSE", "Invalid FDF traversal record");
|
|
992
|
+
return node.items;
|
|
993
|
+
}
|
|
994
|
+
const number = (items, at) => {
|
|
995
|
+
const node = items[at];
|
|
996
|
+
if (node?.kind !== "number") throw new PdfError("E_PARSE", "Invalid FDF traversal number");
|
|
997
|
+
return node.value;
|
|
998
|
+
};
|
|
999
|
+
const string = (items, at) => {
|
|
1000
|
+
const node = items[at];
|
|
1001
|
+
if (node?.kind !== "string") throw new PdfError("E_PARSE", "Invalid FDF traversal name");
|
|
1002
|
+
return decodePdfString4(node);
|
|
1003
|
+
};
|
|
1004
|
+
const save = async (id, items) => tree.set({ objectNumber: id, generationNumber: 0, value: cosArray3(items) });
|
|
1005
|
+
try {
|
|
1006
|
+
for await (const field of document.formFieldDetails()) {
|
|
1007
|
+
for await (const ignored of field.options()) void ignored;
|
|
1008
|
+
const name = await names.intern(field.name);
|
|
1009
|
+
const staged = await PdfFileSource4.fromStream(storage.fs, storage.directory, fieldValue(field), { signal });
|
|
1010
|
+
let valueFailed = false;
|
|
1011
|
+
try {
|
|
1012
|
+
await values.set({ objectNumber: name.index + 1, generationNumber: 0, value: cosDict3({}), stream: { length: staged.size, chunks: staged.stream(0, staged.size, signal) } });
|
|
1013
|
+
} catch (error) {
|
|
1014
|
+
valueFailed = true;
|
|
1015
|
+
throw error;
|
|
1016
|
+
} finally {
|
|
1017
|
+
await staged.close().catch((error) => {
|
|
1018
|
+
if (!valueFailed) throw error;
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
const catalog = await resolve(document.crossReference.rootRef);
|
|
1023
|
+
const form = catalog?.kind === "dict" ? await resolve(dictGet5(catalog, "AcroForm")) : void 0;
|
|
1024
|
+
const roots = form?.kind === "dict" ? await resolve(dictGet5(form, "Fields")) : void 0;
|
|
1025
|
+
await save(1, [cosDict3({}), cosString3(""), cosString3(""), ...Array.from({ length: 6 }, () => cosNumber3(0))]);
|
|
1026
|
+
let top = 1, next = 1;
|
|
1027
|
+
while (top) {
|
|
1028
|
+
await checkpoint();
|
|
1029
|
+
const frame = await record(top), node = await resolve(frame[0]);
|
|
1030
|
+
const kids = top === 1 ? roots : node?.kind === "dict" ? await resolve(dictGet5(node, "Kids")) : void 0;
|
|
1031
|
+
let descended = false, cursor = number(frame, 3);
|
|
1032
|
+
while (kids?.kind === "array" && cursor < kids.items.length) {
|
|
1033
|
+
const childNode = kids.items[cursor++], child = await resolve(childNode);
|
|
1034
|
+
if (child?.kind !== "dict" || top !== 1 && !dictGet5(child, "T")) continue;
|
|
1035
|
+
const name = await resolve(dictGet5(child, "T")), partial = name?.kind === "string" ? decodePdfString4(name) : "";
|
|
1036
|
+
const prefix = string(frame, 1), full = prefix && partial ? `${prefix}.${partial}` : partial || prefix;
|
|
1037
|
+
const depth = number(frame, 8) + 1;
|
|
1038
|
+
if (depth > document.depthLimit) throw new PdfError("E_LIMIT", "PDF FDF field depth limit exceeded");
|
|
1039
|
+
frame[3] = cosNumber3(cursor);
|
|
1040
|
+
await save(top, frame);
|
|
1041
|
+
await save(++next, [childNode, cosString3(full), cosString3(partial), cosNumber3(0), cosNumber3(0), cosNumber3(0), cosNumber3(0), cosNumber3(top), cosNumber3(depth)]);
|
|
1042
|
+
top = next;
|
|
1043
|
+
descended = true;
|
|
1044
|
+
break;
|
|
1045
|
+
}
|
|
1046
|
+
if (descended) continue;
|
|
1047
|
+
const parent = number(frame, 7);
|
|
1048
|
+
if (parent && (number(frame, 4) || string(frame, 1) || string(frame, 2))) {
|
|
1049
|
+
const owner = await record(parent), last = number(owner, 5);
|
|
1050
|
+
if (last) {
|
|
1051
|
+
const sibling = await record(last);
|
|
1052
|
+
sibling[6] = cosNumber3(top);
|
|
1053
|
+
await save(last, sibling);
|
|
1054
|
+
} else owner[4] = cosNumber3(top);
|
|
1055
|
+
owner[5] = cosNumber3(top);
|
|
1056
|
+
await save(parent, owner);
|
|
1057
|
+
}
|
|
1058
|
+
top = parent;
|
|
1059
|
+
}
|
|
1060
|
+
yield* text("%FDF-1.2\n1 0 obj\n<< /FDF << /Fields [\n");
|
|
1061
|
+
let current = number(await record(1), 4);
|
|
1062
|
+
if (current) yield* text(" ");
|
|
1063
|
+
while (current) {
|
|
1064
|
+
await checkpoint();
|
|
1065
|
+
const frame = await record(current), child = number(frame, 4);
|
|
1066
|
+
yield* text("<< /T (");
|
|
1067
|
+
yield* text(string(frame, 2) || string(frame, 1), true);
|
|
1068
|
+
yield* text(")");
|
|
1069
|
+
if (child) {
|
|
1070
|
+
yield* text(" /Kids [ ");
|
|
1071
|
+
current = child;
|
|
1072
|
+
continue;
|
|
1073
|
+
}
|
|
1074
|
+
yield* text(" /V ");
|
|
1075
|
+
const name = await names.intern(string(frame, 1)), value = name.added ? void 0 : await values.get(name.index + 1);
|
|
1076
|
+
if (value?.stream) yield* value.stream.chunks;
|
|
1077
|
+
else {
|
|
1078
|
+
const dict = await resolve(frame[0]), raw = dict?.kind === "dict" ? await resolve(dictGet5(dict, "V")) : void 0;
|
|
1079
|
+
if (raw?.kind === "name") yield* text(`/${raw.decoded}`);
|
|
1080
|
+
else {
|
|
1081
|
+
yield* text("(");
|
|
1082
|
+
if (raw?.kind === "string") yield* text(decodePdfString4(raw), true);
|
|
1083
|
+
yield* text(")");
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
yield* text(" >>");
|
|
1087
|
+
while (current) {
|
|
1088
|
+
const done = await record(current), sibling = number(done, 6), parent = number(done, 7);
|
|
1089
|
+
if (sibling) {
|
|
1090
|
+
yield* text(parent === 1 ? "\n " : " ");
|
|
1091
|
+
current = sibling;
|
|
1092
|
+
break;
|
|
1093
|
+
}
|
|
1094
|
+
current = parent === 1 ? 0 : parent;
|
|
1095
|
+
if (current) yield* text(" ] >>");
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
yield* text("\n] >> >>\nendobj\ntrailer\n<< /Root 1 0 R >>\n%%EOF\n");
|
|
1099
|
+
} catch (error) {
|
|
1100
|
+
failed = true;
|
|
1101
|
+
throw error;
|
|
1102
|
+
} finally {
|
|
1103
|
+
const results = await Promise.allSettled([names.close(), values.close(), tree.close()]);
|
|
1104
|
+
if (!failed) {
|
|
1105
|
+
for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// packages/safe-bash-command-pdftk/src/retained-fields.ts
|
|
1111
|
+
async function* retainedFieldReport(document, utf8, signal) {
|
|
1112
|
+
const encoder = new TextEncoder();
|
|
1113
|
+
let work = 0;
|
|
1114
|
+
async function* line(prefix, value) {
|
|
1115
|
+
let part = prefix;
|
|
1116
|
+
for (const char of String(value)) {
|
|
1117
|
+
const code = char.codePointAt(0);
|
|
1118
|
+
part += !utf8 && code > 127 ? `&#${code};` : char;
|
|
1119
|
+
if (part.length >= 4096) {
|
|
1120
|
+
signal.throwIfAborted();
|
|
1121
|
+
if (++work % 16 === 0) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1122
|
+
yield encoder.encode(part);
|
|
1123
|
+
part = "";
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
signal.throwIfAborted();
|
|
1127
|
+
yield encoder.encode(part + "\n");
|
|
1128
|
+
}
|
|
1129
|
+
for await (const field of document.formFieldDetails()) {
|
|
1130
|
+
yield encoder.encode("---\n");
|
|
1131
|
+
yield* line("FieldType: ", field.type === "checkbox" ? "Button" : field.type === "choice" ? "Choice" : "Text");
|
|
1132
|
+
yield* line("FieldName: ", field.name);
|
|
1133
|
+
if (field.altName) yield* line("FieldNameAlt: ", field.altName);
|
|
1134
|
+
yield* line("FieldFlags: ", field.flags);
|
|
1135
|
+
for await (const value of field.values()) yield* line("FieldValue: ", value);
|
|
1136
|
+
if (field.defaultValue !== void 0 && field.defaultValue !== "") yield* line("FieldValueDefault: ", field.defaultValue);
|
|
1137
|
+
yield* line("FieldJustification: ", field.justification);
|
|
1138
|
+
for await (const option of field.options()) yield* line("FieldStateOption: ", option);
|
|
1139
|
+
if (field.maxLength !== void 0) yield* line("FieldMaxLength: ", field.maxLength);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
|
|
265
1143
|
// packages/safe-bash-command-pdftk/src/retained.ts
|
|
1144
|
+
import { PdfError as PdfError2, PdfFileSource as PdfFileSource5, PdfRetainedDocument as PdfRetainedDocument2, retainedCosObjects as retainedCosObjects2 } from "../pdf-ast/index.js";
|
|
1145
|
+
import { FsError } from "../safe-bash-contracts/errors.js";
|
|
1146
|
+
import { writeBytes } from "../safe-bash-contracts/io.js";
|
|
1147
|
+
import { resolvePath } from "../safe-bash-contracts/path.js";
|
|
1148
|
+
import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
|
|
266
1149
|
async function executeRetainedPdftk(context, options) {
|
|
267
1150
|
const signal = context.signal, storage = { fs: context.fs, directory: resolvePath(context.cwd, context.env.TMPDIR || "/tmp") };
|
|
1151
|
+
const handles = /* @__PURE__ */ new Map();
|
|
1152
|
+
for (const input of options.inputs) {
|
|
1153
|
+
handles.set(input.handle, input);
|
|
1154
|
+
if (!handles.has("")) handles.set("", input);
|
|
1155
|
+
}
|
|
1156
|
+
const primary = options.inputs[0];
|
|
1157
|
+
let idInput = handles.values().next().value;
|
|
1158
|
+
if (options.keepFinalId) for (const input of handles.values()) idInput = input;
|
|
1159
|
+
let selectedId;
|
|
1160
|
+
const counts = /* @__PURE__ */ new Map();
|
|
268
1161
|
const inputs = /* @__PURE__ */ new Map();
|
|
1162
|
+
const infoPath = options.operation === "update_info" || options.operation === "update_info_utf8" ? options.opArgs[0] ?? "-" : void 0;
|
|
1163
|
+
const overlayPath = ["stamp", "multistamp", "background", "multibackground"].includes(options.operation) ? options.opArgs[0] ?? "-" : void 0;
|
|
1164
|
+
const attachmentPaths = [];
|
|
1165
|
+
let attachmentPage;
|
|
1166
|
+
if (options.operation === "attach_files") for (let i = 0; i < options.opArgs.length; i++) {
|
|
1167
|
+
if (options.opArgs[i].toLowerCase() === "to_page") attachmentPage = options.opArgs[++i];
|
|
1168
|
+
else attachmentPaths.push(options.opArgs[i]);
|
|
1169
|
+
}
|
|
1170
|
+
async function* attachments() {
|
|
1171
|
+
for (const path of attachmentPaths) {
|
|
1172
|
+
const source = inputs.get(path);
|
|
1173
|
+
if (source) yield { filename: path.slice(path.lastIndexOf("/") + 1), chunks: source.stream(0, source.size, signal) };
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
let assembled;
|
|
1177
|
+
let overlayDocument;
|
|
269
1178
|
let document, output, total = 0, failed = false;
|
|
270
1179
|
const diagnostic = async (message) => {
|
|
271
1180
|
await writeBytes(context.stderr, new TextEncoder().encode(message), signal);
|
|
@@ -274,20 +1183,20 @@ async function executeRetainedPdftk(context, options) {
|
|
|
274
1183
|
try {
|
|
275
1184
|
await context.fs.mkdir(storage.directory, { recursive: true, signal });
|
|
276
1185
|
const maximum = context.inputBudget?.maxBytes ?? Infinity;
|
|
277
|
-
if (options.inputs.some((input) => input.file === "-")) {
|
|
278
|
-
const source = await
|
|
1186
|
+
if (options.inputs.some((input) => input.file === "-") || attachmentPaths.includes("-") || overlayPath === "-" || infoPath === "-") {
|
|
1187
|
+
const source = await PdfFileSource5.fromStream(context.fs, storage.directory, context.stdin, { signal, maxInputBytes: maximum });
|
|
279
1188
|
inputs.set("-", source);
|
|
280
1189
|
total += source.size;
|
|
281
1190
|
context.inputBudget?.check(total);
|
|
282
1191
|
}
|
|
283
|
-
for (const input of options.inputs) {
|
|
1192
|
+
for (const input of [...options.inputs, ...attachmentPaths.map((file) => ({ file })), ...overlayPath !== void 0 ? [{ file: overlayPath }] : [], ...infoPath !== void 0 ? [{ file: infoPath }] : []]) {
|
|
284
1193
|
if (inputs.has(input.file)) continue;
|
|
285
1194
|
let source;
|
|
286
1195
|
try {
|
|
287
|
-
source = await
|
|
1196
|
+
source = await PdfFileSource5.open(context.fs, resolvePath(context.cwd, input.file), { signal, maxInputBytes: maximum - total });
|
|
288
1197
|
} catch (error) {
|
|
289
1198
|
signal.throwIfAborted();
|
|
290
|
-
if (error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR", "EACCES", "EISDIR"].includes(String(error.code)) || error instanceof
|
|
1199
|
+
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
1200
|
inputs.set(input.file, void 0);
|
|
292
1201
|
continue;
|
|
293
1202
|
}
|
|
@@ -302,12 +1211,18 @@ async function executeRetainedPdftk(context, options) {
|
|
|
302
1211
|
if (!source) return await diagnostic(`Error: Unable to find file '${input.file}'
|
|
303
1212
|
`);
|
|
304
1213
|
try {
|
|
305
|
-
document = await
|
|
306
|
-
|
|
307
|
-
for await (const
|
|
1214
|
+
document = await PdfRetainedDocument2.open(source, storage, { signal, recovery: "strict", ...input.password ? { password: input.password } : {} });
|
|
1215
|
+
if (input === idInput) selectedId = document.crossReference.idArray;
|
|
1216
|
+
for await (const object of retainedCosObjects2(document, storage, { signal })) if (object.stream) for await (const ignored of object.stream.chunks) void ignored;
|
|
1217
|
+
let count = 0;
|
|
1218
|
+
for await (const ignored of document.pages()) {
|
|
1219
|
+
void ignored;
|
|
1220
|
+
count++;
|
|
1221
|
+
}
|
|
1222
|
+
counts.set(input, count);
|
|
308
1223
|
} catch (error) {
|
|
309
1224
|
signal.throwIfAborted();
|
|
310
|
-
if (!(error instanceof
|
|
1225
|
+
if (!(error instanceof PdfError2) || error.code === "E_LIMIT" || error.code === "E_CANCELLED") throw error;
|
|
311
1226
|
return await diagnostic(`Error: Failed to open PDF '${input.file}': ${error.message}
|
|
312
1227
|
`);
|
|
313
1228
|
}
|
|
@@ -315,14 +1230,48 @@ async function executeRetainedPdftk(context, options) {
|
|
|
315
1230
|
document = void 0;
|
|
316
1231
|
await source.releaseCache();
|
|
317
1232
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
1233
|
+
document = await PdfRetainedDocument2.open(inputs.get(primary.file), storage, { signal, recovery: "strict", ...primary.password ? { password: primary.password } : {} });
|
|
1234
|
+
const infoSource = infoPath === void 0 ? void 0 : inputs.get(infoPath);
|
|
1235
|
+
if (infoPath !== void 0 && !infoSource) return await diagnostic(`Error: Unable to open info file '${infoPath}'
|
|
1236
|
+
`);
|
|
1237
|
+
let overlayPages = 0;
|
|
1238
|
+
if (overlayPath !== void 0) {
|
|
1239
|
+
const source = inputs.get(overlayPath);
|
|
1240
|
+
if (!source) return await diagnostic(`Error: Unable to open '${overlayPath}'
|
|
1241
|
+
`);
|
|
1242
|
+
overlayDocument = await PdfRetainedDocument2.open(source, storage, { signal, recovery: "strict" });
|
|
1243
|
+
for await (const object of retainedCosObjects2(overlayDocument, storage, { signal })) if (object.stream) for await (const ignored of object.stream.chunks) void ignored;
|
|
1244
|
+
for await (const ignored of overlayDocument.pages()) {
|
|
1245
|
+
void ignored;
|
|
1246
|
+
overlayPages++;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
async function* stampPages() {
|
|
1250
|
+
if (overlayPages) for (let targetIndex = 0; targetIndex < counts.get(primary); targetIndex++) yield { targetIndex, sourceIndex: options.operation.startsWith("multi") ? Math.min(targetIndex, overlayPages - 1) : 0 };
|
|
1251
|
+
}
|
|
1252
|
+
if (options.operation === "unpack_files" || options.operation === "burst") {
|
|
1253
|
+
const files = options.operation === "burst" ? retainedBurst(document, storage, options, counts.get(primary), signal) : retainedUnpack(document, storage, options.outputTarget ?? ".", inputs.keys(), signal);
|
|
1254
|
+
for await (const file of files) {
|
|
1255
|
+
try {
|
|
1256
|
+
await publish(context, resolvePath(context.cwd, file.path), file.chunks);
|
|
1257
|
+
} catch (error) {
|
|
1258
|
+
signal.throwIfAborted();
|
|
1259
|
+
if (!(error instanceof Error) || !("code" in error)) throw error;
|
|
1260
|
+
return await diagnostic(`Error: Failed to open output file '${file.path}': ${error.code}.
|
|
1261
|
+
`);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
return { exitCode: 0 };
|
|
1265
|
+
}
|
|
1266
|
+
if (options.operation === "cat" || options.operation === "shuffle") {
|
|
1267
|
+
assembled = await assembleRetainedPdftk(document, storage, options, counts, handles, async (input) => PdfRetainedDocument2.open(inputs.get(input.file), storage, { signal, recovery: "strict", ...input.password ? { password: input.password } : {} }), signal);
|
|
1268
|
+
}
|
|
1269
|
+
output = await PdfFileSource5.fromStream(context.fs, storage.directory, ["output", "rotate", "attach_files", "stamp", "multistamp", "background", "multibackground", "update_info", "update_info_utf8", "cat", "shuffle"].includes(options.operation) ? retainedOutput(assembled?.document ?? 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, infoSource ? { updates: retainedInfoUpdates(infoSource.stream(0, infoSource.size, signal), signal), useUpdatedId: idInput === primary } : 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
1270
|
const destination = options.outputTarget;
|
|
322
1271
|
if (!destination || destination === "-") for await (const bytes of output.stream(0, output.size, signal)) await writeBytes(context.stdout, bytes, signal);
|
|
323
1272
|
else {
|
|
324
1273
|
try {
|
|
325
|
-
await publish(context, resolvePath(context.cwd, destination), output);
|
|
1274
|
+
await publish(context, resolvePath(context.cwd, destination), output.stream(0, output.size, signal));
|
|
326
1275
|
} catch (error) {
|
|
327
1276
|
signal.throwIfAborted();
|
|
328
1277
|
if (!(error instanceof Error) || !("code" in error)) throw error;
|
|
@@ -335,13 +1284,13 @@ async function executeRetainedPdftk(context, options) {
|
|
|
335
1284
|
failed = true;
|
|
336
1285
|
throw error;
|
|
337
1286
|
} finally {
|
|
338
|
-
const results = await Promise.allSettled([document?.close(), output?.close(), ...[...inputs.values()].map((source) => source?.close())]);
|
|
1287
|
+
const results = await Promise.allSettled([assembled?.close(), document?.close(), overlayDocument?.close(), output?.close(), ...[...inputs.values()].map((source) => source?.close())]);
|
|
339
1288
|
if (!failed) {
|
|
340
1289
|
for (const result of results) if (result.status === "rejected") await Promise.reject(result.reason);
|
|
341
1290
|
}
|
|
342
1291
|
}
|
|
343
1292
|
}
|
|
344
|
-
async function publish(context, path,
|
|
1293
|
+
async function publish(context, path, chunks) {
|
|
345
1294
|
const fs = context.fs, signal = context.signal;
|
|
346
1295
|
const capabilities = await fs.capabilitiesFor?.(path, { signal, create: true, stagingAncestry: true }) ?? fs.capabilities;
|
|
347
1296
|
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 +1299,7 @@ async function publish(context, path, source) {
|
|
|
350
1299
|
let failed = false;
|
|
351
1300
|
try {
|
|
352
1301
|
if (!staging.writer || !staging.cleanup) throw new FsError("ENOTSUP", { path, message: "PDF backend omitted retained staging handles" });
|
|
353
|
-
for await (const bytes of
|
|
1302
|
+
for await (const bytes of chunks) await writeFileOutput(context, bytes, (data) => staging.writer.write(data, { signal }));
|
|
354
1303
|
const stat = await staging.writer.finish({ signal });
|
|
355
1304
|
await fs.publishStagedFile({ ...staging, file: { ...staging.file, stat } }, resolution.path, { parent: resolution.parent, destination: resolution.destination, ancestors: resolution.ancestors, commitGuard: resolution.validate, signal });
|
|
356
1305
|
} catch (error) {
|
|
@@ -548,17 +1497,17 @@ import { readBytes, writeBytes as writeBytes2 } from "../safe-bash-contracts/io.
|
|
|
548
1497
|
import { createOutputOperation } from "../safe-bash-contracts/output.js";
|
|
549
1498
|
import {
|
|
550
1499
|
PdfDocument,
|
|
551
|
-
cosArray,
|
|
552
|
-
cosDict,
|
|
1500
|
+
cosArray as cosArray4,
|
|
1501
|
+
cosDict as cosDict4,
|
|
553
1502
|
cosHexString,
|
|
554
1503
|
cosName,
|
|
555
|
-
cosNumber,
|
|
1504
|
+
cosNumber as cosNumber4,
|
|
556
1505
|
cosStream,
|
|
557
|
-
cosString,
|
|
558
|
-
decodePdfString as
|
|
559
|
-
dictDelete,
|
|
560
|
-
dictGet as
|
|
561
|
-
dictSet,
|
|
1506
|
+
cosString as cosString4,
|
|
1507
|
+
decodePdfString as decodePdfString5,
|
|
1508
|
+
dictDelete as dictDelete2,
|
|
1509
|
+
dictGet as dictGet6,
|
|
1510
|
+
dictSet as dictSet3,
|
|
562
1511
|
flattenDocumentFormFields,
|
|
563
1512
|
getDocumentFormFields,
|
|
564
1513
|
parseFormDataBytes,
|
|
@@ -616,6 +1565,9 @@ function resolvePageEndpoint(token, totalPages) {
|
|
|
616
1565
|
return Number.isFinite(num) && num >= 1 ? Math.min(totalPages, num) : 1;
|
|
617
1566
|
}
|
|
618
1567
|
function parsePdftkRangeToken(token, handles, defaultHandle) {
|
|
1568
|
+
return Array.from(iteratePdftkRangeToken(token, handles, defaultHandle));
|
|
1569
|
+
}
|
|
1570
|
+
function* iteratePdftkRangeToken(token, handles, defaultHandle) {
|
|
619
1571
|
let work = token.trim();
|
|
620
1572
|
let handle = defaultHandle;
|
|
621
1573
|
const sortedHandleKeys = [...handles.keys()].sort((a, b) => b.length - a.length);
|
|
@@ -661,22 +1613,11 @@ function parsePdftkRangeToken(token, handles, defaultHandle) {
|
|
|
661
1613
|
endPage = resolvePageEndpoint(work.slice(dashIdx + 1), totalPages);
|
|
662
1614
|
}
|
|
663
1615
|
}
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
for (let p = startPage; p >= endPage; p--) pages.push(p);
|
|
1616
|
+
const step = startPage <= endPage ? 1 : -1;
|
|
1617
|
+
for (let pageNumber = startPage; step > 0 ? pageNumber <= endPage : pageNumber >= endPage; pageNumber += step) {
|
|
1618
|
+
if (qualifier === "even" && pageNumber % 2 !== 0 || qualifier === "odd" && pageNumber % 2 !== 1) continue;
|
|
1619
|
+
yield { handle, pageNumber, rotation };
|
|
669
1620
|
}
|
|
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
1621
|
}
|
|
681
1622
|
function encodePdftkText(str, utf8) {
|
|
682
1623
|
if (utf8) return str;
|
|
@@ -691,27 +1632,6 @@ function encodePdftkText(str, utf8) {
|
|
|
691
1632
|
}
|
|
692
1633
|
return out;
|
|
693
1634
|
}
|
|
694
|
-
function decodePdftkEntities(str) {
|
|
695
|
-
let out = "";
|
|
696
|
-
let i = 0;
|
|
697
|
-
while (i < str.length) {
|
|
698
|
-
if (str[i] === "&" && str[i + 1] === "#") {
|
|
699
|
-
const semi = str.indexOf(";", i + 2);
|
|
700
|
-
if (semi !== -1) {
|
|
701
|
-
const body = str.slice(i + 2, semi);
|
|
702
|
-
const cp = body.startsWith("x") || body.startsWith("X") ? Number.parseInt(body.slice(1), 16) : Number.parseInt(body, 10);
|
|
703
|
-
if (Number.isFinite(cp) && cp >= 0) {
|
|
704
|
-
out += String.fromCodePoint(cp);
|
|
705
|
-
i = semi + 1;
|
|
706
|
-
continue;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
out += str[i];
|
|
711
|
-
i++;
|
|
712
|
-
}
|
|
713
|
-
return out;
|
|
714
|
-
}
|
|
715
1635
|
function escapeFdfString(str) {
|
|
716
1636
|
return str.replaceAll("\\", "\\\\").replaceAll("(", "\\(").replaceAll(")", "\\)").replaceAll("\r", "\\r").replaceAll("\n", "\\n");
|
|
717
1637
|
}
|
|
@@ -732,102 +1652,102 @@ function formatDumpDataFields(doc, utf8 = true) {
|
|
|
732
1652
|
} else {
|
|
733
1653
|
valStr = String(field.value ?? "");
|
|
734
1654
|
}
|
|
735
|
-
const
|
|
1655
|
+
const lines2 = [
|
|
736
1656
|
"---",
|
|
737
1657
|
`FieldType: ${fieldType}`,
|
|
738
1658
|
`FieldName: ${encodePdftkText(field.name, utf8)}`
|
|
739
1659
|
];
|
|
740
1660
|
if (field.altName) {
|
|
741
|
-
|
|
1661
|
+
lines2.push(`FieldNameAlt: ${encodePdftkText(field.altName, utf8)}`);
|
|
742
1662
|
}
|
|
743
|
-
|
|
1663
|
+
lines2.push(`FieldFlags: ${flags}`);
|
|
744
1664
|
if (field.selectedValues && field.selectedValues.length > 0) {
|
|
745
1665
|
for (const sv of field.selectedValues) {
|
|
746
|
-
|
|
1666
|
+
lines2.push(`FieldValue: ${encodePdftkText(sv, utf8)}`);
|
|
747
1667
|
}
|
|
748
1668
|
} else {
|
|
749
|
-
|
|
1669
|
+
lines2.push(`FieldValue: ${encodePdftkText(valStr, utf8)}`);
|
|
750
1670
|
}
|
|
751
1671
|
if (field.defaultValue !== void 0 && field.defaultValue !== "") {
|
|
752
|
-
|
|
1672
|
+
lines2.push(`FieldValueDefault: ${encodePdftkText(field.defaultValue, utf8)}`);
|
|
753
1673
|
}
|
|
754
|
-
|
|
1674
|
+
lines2.push(`FieldJustification: ${field.justification ?? "Left"}`);
|
|
755
1675
|
for (const opt of options) {
|
|
756
|
-
|
|
1676
|
+
lines2.push(`FieldStateOption: ${encodePdftkText(opt, utf8)}`);
|
|
757
1677
|
}
|
|
758
1678
|
if (field.maxLength !== void 0) {
|
|
759
|
-
|
|
1679
|
+
lines2.push(`FieldMaxLength: ${field.maxLength}`);
|
|
760
1680
|
}
|
|
761
|
-
stanzas.push(
|
|
1681
|
+
stanzas.push(lines2.join("\n"));
|
|
762
1682
|
}
|
|
763
1683
|
return stanzas.join("\n") + "\n";
|
|
764
1684
|
}
|
|
765
1685
|
function formatDumpDataAnnots(doc, utf8 = false) {
|
|
766
|
-
const
|
|
1686
|
+
const lines2 = [];
|
|
767
1687
|
const id0Node = doc.cos.idArray?.items[0] ? doc.cos.resolve(doc.cos.idArray.items[0]) : void 0;
|
|
768
1688
|
const id1Node = doc.cos.idArray?.items[1] ? doc.cos.resolve(doc.cos.idArray.items[1]) : void 0;
|
|
769
1689
|
const id0Hex = id0Node?.kind === "string" ? bytesToHexLower(id0Node.bytes) : "00000000000000000000000000000000";
|
|
770
1690
|
const id1Hex = id1Node?.kind === "string" ? bytesToHexLower(id1Node.bytes) : "00000000000000000000000000000000";
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
1691
|
+
lines2.push(`PdfID0: ${id0Hex}`);
|
|
1692
|
+
lines2.push(`PdfID1: ${id1Hex}`);
|
|
1693
|
+
lines2.push(`NumberOfPages: ${doc.pageCount}`);
|
|
774
1694
|
for (let p = 0; p < doc.pageCount; p++) {
|
|
775
1695
|
const pageDict = doc.getPage(p).pageDict;
|
|
776
|
-
const annotsArr = doc.cos.resolveArray(
|
|
1696
|
+
const annotsArr = doc.cos.resolveArray(dictGet6(pageDict, "Annots"));
|
|
777
1697
|
if (!annotsArr) continue;
|
|
778
1698
|
for (const item of annotsArr.items) {
|
|
779
1699
|
const annotDict = doc.cos.resolveDict(item);
|
|
780
1700
|
if (!annotDict) continue;
|
|
781
|
-
const subNode = doc.cos.resolve(
|
|
1701
|
+
const subNode = doc.cos.resolve(dictGet6(annotDict, "Subtype"));
|
|
782
1702
|
const subtype = subNode?.kind === "name" ? subNode.decoded : "Annot";
|
|
783
|
-
const rectArr = doc.cos.resolveArray(
|
|
1703
|
+
const rectArr = doc.cos.resolveArray(dictGet6(annotDict, "Rect"));
|
|
784
1704
|
const rectNums = rectArr ? rectArr.items.map((it) => {
|
|
785
1705
|
const r = doc.cos.resolve(it);
|
|
786
1706
|
return r?.kind === "number" ? r.value : 0;
|
|
787
1707
|
}) : [0, 0, 0, 0];
|
|
788
|
-
const flagsNode = doc.cos.resolve(
|
|
1708
|
+
const flagsNode = doc.cos.resolve(dictGet6(annotDict, "F"));
|
|
789
1709
|
const flags = flagsNode?.kind === "number" ? flagsNode.value : 0;
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
const nmNode = doc.cos.resolve(
|
|
1710
|
+
lines2.push("---");
|
|
1711
|
+
lines2.push(`AnnotSubtype: ${subtype}`);
|
|
1712
|
+
lines2.push(`AnnotRect: ${rectNums.slice(0, 4).join(" ")}`);
|
|
1713
|
+
const nmNode = doc.cos.resolve(dictGet6(annotDict, "NM"));
|
|
794
1714
|
if (nmNode?.kind === "string") {
|
|
795
|
-
|
|
1715
|
+
lines2.push(`AnnotName: ${encodePdftkText(decodePdfString5(nmNode), utf8)}`);
|
|
796
1716
|
}
|
|
797
|
-
const tNode = doc.cos.resolve(
|
|
1717
|
+
const tNode = doc.cos.resolve(dictGet6(annotDict, "T"));
|
|
798
1718
|
if (tNode?.kind === "string") {
|
|
799
|
-
|
|
1719
|
+
lines2.push(`AnnotTitle: ${encodePdftkText(decodePdfString5(tNode), utf8)}`);
|
|
800
1720
|
}
|
|
801
|
-
const subjNode = doc.cos.resolve(
|
|
1721
|
+
const subjNode = doc.cos.resolve(dictGet6(annotDict, "Subj"));
|
|
802
1722
|
if (subjNode?.kind === "string") {
|
|
803
|
-
|
|
1723
|
+
lines2.push(`AnnotSubj: ${encodePdftkText(decodePdfString5(subjNode), utf8)}`);
|
|
804
1724
|
}
|
|
805
|
-
const cNode = doc.cos.resolve(
|
|
1725
|
+
const cNode = doc.cos.resolve(dictGet6(annotDict, "Contents"));
|
|
806
1726
|
if (cNode?.kind === "string") {
|
|
807
|
-
|
|
1727
|
+
lines2.push(`AnnotContents: ${encodePdftkText(decodePdfString5(cNode), utf8)}`);
|
|
808
1728
|
}
|
|
809
|
-
const colArr = doc.cos.resolveArray(
|
|
1729
|
+
const colArr = doc.cos.resolveArray(dictGet6(annotDict, "C"));
|
|
810
1730
|
if (colArr && colArr.items.length >= 3) {
|
|
811
1731
|
const colNums = colArr.items.slice(0, 3).map((it) => {
|
|
812
1732
|
const r = doc.cos.resolve(it);
|
|
813
1733
|
return r?.kind === "number" ? r.value : 0;
|
|
814
1734
|
});
|
|
815
|
-
|
|
1735
|
+
lines2.push(`AnnotColor: ${colNums.join(" ")}`);
|
|
816
1736
|
}
|
|
817
|
-
const openNode = doc.cos.resolve(
|
|
1737
|
+
const openNode = doc.cos.resolve(dictGet6(annotDict, "Open"));
|
|
818
1738
|
if (openNode?.kind === "boolean") {
|
|
819
|
-
|
|
1739
|
+
lines2.push(`AnnotOpen: ${openNode.value}`);
|
|
820
1740
|
}
|
|
821
|
-
const mNode = doc.cos.resolve(
|
|
1741
|
+
const mNode = doc.cos.resolve(dictGet6(annotDict, "M"));
|
|
822
1742
|
if (mNode?.kind === "string") {
|
|
823
|
-
|
|
1743
|
+
lines2.push(`AnnotModificationDate: ${encodePdftkText(decodePdfString5(mNode), utf8)}`);
|
|
824
1744
|
}
|
|
825
|
-
|
|
826
|
-
|
|
1745
|
+
lines2.push(`AnnotFlags: ${flags}`);
|
|
1746
|
+
lines2.push(`AnnotPageNumber: ${p + 1}`);
|
|
827
1747
|
const formatDestTarget = (dRaw) => {
|
|
828
1748
|
if (!dRaw) return void 0;
|
|
829
1749
|
const resolved = doc.cos.resolve(dRaw);
|
|
830
|
-
if (resolved?.kind === "string") return
|
|
1750
|
+
if (resolved?.kind === "string") return decodePdfString5(resolved);
|
|
831
1751
|
if (resolved?.kind === "name") return resolved.decoded;
|
|
832
1752
|
if (resolved?.kind === "array" && resolved.items.length > 0) {
|
|
833
1753
|
const first = resolved.items[0];
|
|
@@ -860,53 +1780,53 @@ function formatDumpDataAnnots(doc, utf8 = false) {
|
|
|
860
1780
|
}
|
|
861
1781
|
const actionDict = doc.cos.resolveDict(aNode);
|
|
862
1782
|
if (!actionDict) return;
|
|
863
|
-
const sNode = doc.cos.resolve(
|
|
1783
|
+
const sNode = doc.cos.resolve(dictGet6(actionDict, "S"));
|
|
864
1784
|
const sType = sNode?.kind === "name" ? sNode.decoded : "";
|
|
865
1785
|
if (sType) {
|
|
866
|
-
|
|
1786
|
+
lines2.push(`AnnotActionType: ${sType}`);
|
|
867
1787
|
}
|
|
868
|
-
const uriNode = doc.cos.resolve(
|
|
1788
|
+
const uriNode = doc.cos.resolve(dictGet6(actionDict, "URI"));
|
|
869
1789
|
if (uriNode?.kind === "string") {
|
|
870
|
-
|
|
1790
|
+
lines2.push(`AnnotActionURI: ${encodePdftkText(decodePdfString5(uriNode), utf8)}`);
|
|
871
1791
|
}
|
|
872
|
-
const dNode =
|
|
1792
|
+
const dNode = dictGet6(actionDict, "D");
|
|
873
1793
|
const destTarget = formatDestTarget(dNode);
|
|
874
1794
|
if (destTarget) {
|
|
875
|
-
|
|
1795
|
+
lines2.push(`AnnotActionDest: ${encodePdftkText(destTarget, utf8)}`);
|
|
876
1796
|
}
|
|
877
1797
|
const resolvedIdx = resolveDestinationPageIndex(doc, dNode ?? actionDict);
|
|
878
1798
|
if (resolvedIdx !== void 0) {
|
|
879
|
-
|
|
1799
|
+
lines2.push(`AnnotActionPageNumber: ${resolvedIdx + 1}`);
|
|
880
1800
|
}
|
|
881
|
-
const fRaw = doc.cos.resolve(
|
|
1801
|
+
const fRaw = doc.cos.resolve(dictGet6(actionDict, "F"));
|
|
882
1802
|
if (fRaw?.kind === "string") {
|
|
883
|
-
|
|
1803
|
+
lines2.push(`AnnotActionFile: ${encodePdftkText(decodePdfString5(fRaw), utf8)}`);
|
|
884
1804
|
} else if (fRaw?.kind === "dict") {
|
|
885
|
-
const ufNode = doc.cos.resolve(
|
|
1805
|
+
const ufNode = doc.cos.resolve(dictGet6(fRaw, "UF") ?? dictGet6(fRaw, "F"));
|
|
886
1806
|
if (ufNode?.kind === "string") {
|
|
887
|
-
|
|
1807
|
+
lines2.push(`AnnotActionFile: ${encodePdftkText(decodePdfString5(ufNode), utf8)}`);
|
|
888
1808
|
}
|
|
889
1809
|
}
|
|
890
|
-
emitActionChain(
|
|
1810
|
+
emitActionChain(dictGet6(actionDict, "Next"), visited);
|
|
891
1811
|
};
|
|
892
|
-
const rawA =
|
|
1812
|
+
const rawA = dictGet6(annotDict, "A");
|
|
893
1813
|
if (rawA) {
|
|
894
1814
|
emitActionChain(rawA);
|
|
895
|
-
} else if (
|
|
896
|
-
|
|
897
|
-
const dNode =
|
|
1815
|
+
} else if (dictGet6(annotDict, "Dest")) {
|
|
1816
|
+
lines2.push("AnnotActionType: GoTo");
|
|
1817
|
+
const dNode = dictGet6(annotDict, "Dest");
|
|
898
1818
|
const destTarget = formatDestTarget(dNode);
|
|
899
1819
|
if (destTarget) {
|
|
900
|
-
|
|
1820
|
+
lines2.push(`AnnotActionDest: ${encodePdftkText(destTarget, utf8)}`);
|
|
901
1821
|
}
|
|
902
1822
|
const resolvedIdx = resolveDestinationPageIndex(doc, dNode);
|
|
903
1823
|
if (resolvedIdx !== void 0) {
|
|
904
|
-
|
|
1824
|
+
lines2.push(`AnnotActionPageNumber: ${resolvedIdx + 1}`);
|
|
905
1825
|
}
|
|
906
1826
|
}
|
|
907
1827
|
}
|
|
908
1828
|
}
|
|
909
|
-
return
|
|
1829
|
+
return lines2.join("\n") + "\n";
|
|
910
1830
|
}
|
|
911
1831
|
function copyPrimaryMetadata(srcDoc, dstDoc) {
|
|
912
1832
|
const meta = srcDoc.getMetadata();
|
|
@@ -940,18 +1860,18 @@ function collectOutlineBookmarks(doc, firstNode, level, out, visited = /* @__PUR
|
|
|
940
1860
|
}
|
|
941
1861
|
const dict = doc.cos.resolveDict(curr);
|
|
942
1862
|
if (!dict) break;
|
|
943
|
-
const titleNode = doc.cos.resolve(
|
|
944
|
-
const title = titleNode?.kind === "string" ?
|
|
945
|
-
const resolvedIdx = resolveDestinationPageIndex(doc,
|
|
1863
|
+
const titleNode = doc.cos.resolve(dictGet6(dict, "Title"));
|
|
1864
|
+
const title = titleNode?.kind === "string" ? decodePdfString5(titleNode) : titleNode?.kind === "name" ? titleNode.decoded : "";
|
|
1865
|
+
const resolvedIdx = resolveDestinationPageIndex(doc, dictGet6(dict, "Dest") ?? dictGet6(dict, "A"));
|
|
946
1866
|
const pageNumber = resolvedIdx !== void 0 ? resolvedIdx + 1 : 1;
|
|
947
1867
|
if (title) {
|
|
948
1868
|
out.push({ title, level, pageNumber });
|
|
949
1869
|
}
|
|
950
|
-
const childFirst =
|
|
1870
|
+
const childFirst = dictGet6(dict, "First");
|
|
951
1871
|
if (childFirst) {
|
|
952
1872
|
collectOutlineBookmarks(doc, childFirst, level + 1, out, visited);
|
|
953
1873
|
}
|
|
954
|
-
curr =
|
|
1874
|
+
curr = dictGet6(dict, "Next");
|
|
955
1875
|
}
|
|
956
1876
|
}
|
|
957
1877
|
function collectNameTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ new Set()) {
|
|
@@ -962,16 +1882,16 @@ function collectNameTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ new
|
|
|
962
1882
|
}
|
|
963
1883
|
const dict = doc.cos.resolveDict(nodeOrRef);
|
|
964
1884
|
if (!dict) return;
|
|
965
|
-
const namesArr = doc.cos.resolveArray(
|
|
1885
|
+
const namesArr = doc.cos.resolveArray(dictGet6(dict, "Names"));
|
|
966
1886
|
if (namesArr) {
|
|
967
1887
|
for (let i = 0; i + 1 < namesArr.items.length; i += 2) {
|
|
968
1888
|
const k = doc.cos.resolve(namesArr.items[i]);
|
|
969
1889
|
const v = namesArr.items[i + 1];
|
|
970
|
-
const name = k?.kind === "string" ?
|
|
1890
|
+
const name = k?.kind === "string" ? decodePdfString5(k) : "attachment.bin";
|
|
971
1891
|
out.push({ name, value: v });
|
|
972
1892
|
}
|
|
973
1893
|
}
|
|
974
|
-
const kidsArr = doc.cos.resolveArray(
|
|
1894
|
+
const kidsArr = doc.cos.resolveArray(dictGet6(dict, "Kids"));
|
|
975
1895
|
if (kidsArr) {
|
|
976
1896
|
for (const kid of kidsArr.items) {
|
|
977
1897
|
collectNameTreePairs(doc, kid, out, visited);
|
|
@@ -986,7 +1906,7 @@ function collectNumberTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ n
|
|
|
986
1906
|
}
|
|
987
1907
|
const dict = doc.cos.resolveDict(nodeOrRef);
|
|
988
1908
|
if (!dict) return;
|
|
989
|
-
const numsArr = doc.cos.resolveArray(
|
|
1909
|
+
const numsArr = doc.cos.resolveArray(dictGet6(dict, "Nums"));
|
|
990
1910
|
if (numsArr) {
|
|
991
1911
|
for (let i = 0; i + 1 < numsArr.items.length; i += 2) {
|
|
992
1912
|
const k = doc.cos.resolve(numsArr.items[i]);
|
|
@@ -996,7 +1916,7 @@ function collectNumberTreePairs(doc, nodeOrRef, out, visited = /* @__PURE__ */ n
|
|
|
996
1916
|
}
|
|
997
1917
|
}
|
|
998
1918
|
}
|
|
999
|
-
const kidsArr = doc.cos.resolveArray(
|
|
1919
|
+
const kidsArr = doc.cos.resolveArray(dictGet6(dict, "Kids"));
|
|
1000
1920
|
if (kidsArr) {
|
|
1001
1921
|
for (const kid of kidsArr.items) {
|
|
1002
1922
|
collectNumberTreePairs(doc, kid, out, visited);
|
|
@@ -1010,19 +1930,9 @@ function bytesToHexLower(bytes) {
|
|
|
1010
1930
|
}
|
|
1011
1931
|
return hex;
|
|
1012
1932
|
}
|
|
1013
|
-
function hexToBytes(hex) {
|
|
1014
|
-
const clean = hex.trim();
|
|
1015
|
-
const len = Math.floor(clean.length / 2);
|
|
1016
|
-
const out = new Uint8Array(len);
|
|
1017
|
-
for (let i = 0; i < len; i++) {
|
|
1018
|
-
const byteVal = Number.parseInt(clean.slice(i * 2, i * 2 + 2), 16);
|
|
1019
|
-
out[i] = Number.isNaN(byteVal) ? 0 : byteVal;
|
|
1020
|
-
}
|
|
1021
|
-
return out;
|
|
1022
|
-
}
|
|
1023
1933
|
function formatDumpData(doc, utf8 = true) {
|
|
1024
1934
|
const meta = doc.getMetadata();
|
|
1025
|
-
const
|
|
1935
|
+
const lines2 = [];
|
|
1026
1936
|
const emittedKeys = /* @__PURE__ */ new Set();
|
|
1027
1937
|
const infoEntries = [
|
|
1028
1938
|
["Title", meta.title],
|
|
@@ -1035,7 +1945,7 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
1035
1945
|
for (const [key, val] of infoEntries) {
|
|
1036
1946
|
if (val !== void 0 && val !== "") {
|
|
1037
1947
|
emittedKeys.add(key);
|
|
1038
|
-
|
|
1948
|
+
lines2.push(
|
|
1039
1949
|
"InfoBegin",
|
|
1040
1950
|
`InfoKey: ${encodePdftkText(key, utf8)}`,
|
|
1041
1951
|
`InfoValue: ${encodePdftkText(val, utf8)}`
|
|
@@ -1050,10 +1960,10 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
1050
1960
|
if (emittedKeys.has(k)) continue;
|
|
1051
1961
|
const r = doc.cos.resolve(entry.value);
|
|
1052
1962
|
if (r?.kind === "string") {
|
|
1053
|
-
const val =
|
|
1963
|
+
const val = decodePdfString5(r);
|
|
1054
1964
|
if (val) {
|
|
1055
1965
|
emittedKeys.add(k);
|
|
1056
|
-
|
|
1966
|
+
lines2.push(
|
|
1057
1967
|
"InfoBegin",
|
|
1058
1968
|
`InfoKey: ${encodePdftkText(k, utf8)}`,
|
|
1059
1969
|
`InfoValue: ${encodePdftkText(val, utf8)}`
|
|
@@ -1067,16 +1977,16 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
1067
1977
|
const id1Node = doc.cos.idArray?.items[1] ? doc.cos.resolve(doc.cos.idArray.items[1]) : void 0;
|
|
1068
1978
|
const id0Hex = id0Node?.kind === "string" ? bytesToHexLower(id0Node.bytes) : "00000000000000000000000000000000";
|
|
1069
1979
|
const id1Hex = id1Node?.kind === "string" ? bytesToHexLower(id1Node.bytes) : "00000000000000000000000000000000";
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1980
|
+
lines2.push(`PdfID0: ${id0Hex}`);
|
|
1981
|
+
lines2.push(`PdfID1: ${id1Hex}`);
|
|
1982
|
+
lines2.push(`NumberOfPages: ${doc.pageCount}`);
|
|
1073
1983
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
1074
|
-
const outlinesDict = catalog ? doc.cos.resolveDict(
|
|
1984
|
+
const outlinesDict = catalog ? doc.cos.resolveDict(dictGet6(catalog, "Outlines")) : void 0;
|
|
1075
1985
|
if (outlinesDict) {
|
|
1076
1986
|
const bookmarks = [];
|
|
1077
|
-
collectOutlineBookmarks(doc,
|
|
1987
|
+
collectOutlineBookmarks(doc, dictGet6(outlinesDict, "First"), 1, bookmarks);
|
|
1078
1988
|
for (const bm of bookmarks) {
|
|
1079
|
-
|
|
1989
|
+
lines2.push(
|
|
1080
1990
|
"BookmarkBegin",
|
|
1081
1991
|
`BookmarkTitle: ${encodePdftkText(bm.title, utf8)}`,
|
|
1082
1992
|
`BookmarkLevel: ${bm.level}`,
|
|
@@ -1088,7 +1998,7 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
1088
1998
|
const page = doc.getPage(i);
|
|
1089
1999
|
const { width, height } = page.getSize();
|
|
1090
2000
|
const rot = page.getRotation();
|
|
1091
|
-
const mbArr = doc.cos.resolveArray(
|
|
2001
|
+
const mbArr = doc.cos.resolveArray(dictGet6(page.pageDict, "MediaBox"));
|
|
1092
2002
|
let mbRectStr = `0 0 ${width} ${height}`;
|
|
1093
2003
|
if (mbArr && mbArr.items.length >= 4) {
|
|
1094
2004
|
const mbNums = mbArr.items.slice(0, 4).map((item) => {
|
|
@@ -1097,50 +2007,50 @@ function formatDumpData(doc, utf8 = true) {
|
|
|
1097
2007
|
});
|
|
1098
2008
|
mbRectStr = `${mbNums[0]} ${mbNums[1]} ${mbNums[2]} ${mbNums[3]}`;
|
|
1099
2009
|
}
|
|
1100
|
-
|
|
2010
|
+
lines2.push(
|
|
1101
2011
|
"PageMediaBegin",
|
|
1102
2012
|
`PageMediaNumber: ${i + 1}`,
|
|
1103
2013
|
`PageMediaRotation: ${rot}`,
|
|
1104
2014
|
`PageMediaRect: ${mbRectStr}`,
|
|
1105
2015
|
`PageMediaDimensions: ${width} ${height}`
|
|
1106
2016
|
);
|
|
1107
|
-
const cbArr = doc.cos.resolveArray(
|
|
2017
|
+
const cbArr = doc.cos.resolveArray(dictGet6(page.pageDict, "CropBox"));
|
|
1108
2018
|
if (cbArr && cbArr.items.length >= 4) {
|
|
1109
2019
|
const nums = cbArr.items.slice(0, 4).map((item) => {
|
|
1110
2020
|
const r = doc.cos.resolve(item);
|
|
1111
2021
|
return r?.kind === "number" ? r.value : 0;
|
|
1112
2022
|
});
|
|
1113
|
-
|
|
1114
|
-
|
|
2023
|
+
lines2.push(`PageMediaCropBox: ${nums[0]} ${nums[1]} ${nums[2]} ${nums[3]}`);
|
|
2024
|
+
lines2.push(`PageMediaCropRect: ${nums[0]} ${nums[1]} ${nums[2]} ${nums[3]}`);
|
|
1115
2025
|
}
|
|
1116
2026
|
}
|
|
1117
2027
|
const pageLabelsPairs = [];
|
|
1118
2028
|
if (catalog) {
|
|
1119
|
-
collectNumberTreePairs(doc,
|
|
2029
|
+
collectNumberTreePairs(doc, dictGet6(catalog, "PageLabels"), pageLabelsPairs);
|
|
1120
2030
|
}
|
|
1121
2031
|
for (const pair of pageLabelsPairs) {
|
|
1122
2032
|
const lblDict = doc.cos.resolveDict(pair.value);
|
|
1123
2033
|
if (lblDict) {
|
|
1124
2034
|
const newIndex = Math.max(1, pair.num + 1);
|
|
1125
|
-
const stNode = doc.cos.resolve(
|
|
2035
|
+
const stNode = doc.cos.resolve(dictGet6(lblDict, "St"));
|
|
1126
2036
|
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(
|
|
2037
|
+
const pNode = doc.cos.resolve(dictGet6(lblDict, "P"));
|
|
2038
|
+
const prefix = pNode?.kind === "string" ? decodePdfString5(pNode) : void 0;
|
|
2039
|
+
const sNode = doc.cos.resolve(dictGet6(lblDict, "S"));
|
|
1130
2040
|
const styleCode = sNode?.kind === "name" ? sNode.decoded : "";
|
|
1131
2041
|
const numStyle = PDF_TO_PAGE_LABEL_STYLE[styleCode] ?? "NoNumber";
|
|
1132
|
-
|
|
2042
|
+
lines2.push(
|
|
1133
2043
|
"PageLabelBegin",
|
|
1134
2044
|
`PageLabelNewIndex: ${newIndex}`,
|
|
1135
2045
|
`PageLabelStart: ${startNum}`
|
|
1136
2046
|
);
|
|
1137
2047
|
if (prefix !== void 0 && prefix !== "") {
|
|
1138
|
-
|
|
2048
|
+
lines2.push(`PageLabelPrefix: ${encodePdftkText(prefix, utf8)}`);
|
|
1139
2049
|
}
|
|
1140
|
-
|
|
2050
|
+
lines2.push(`PageLabelNumStyle: ${numStyle}`);
|
|
1141
2051
|
}
|
|
1142
2052
|
}
|
|
1143
|
-
return
|
|
2053
|
+
return lines2.join("\n") + "\n";
|
|
1144
2054
|
}
|
|
1145
2055
|
function formatGenerateFdf(doc) {
|
|
1146
2056
|
const fields = getDocumentFormFields(doc.cos);
|
|
@@ -1157,23 +2067,23 @@ function formatGenerateFdf(doc) {
|
|
|
1157
2067
|
}
|
|
1158
2068
|
return `(${escapeFdfString(String(f.value ?? ""))})`;
|
|
1159
2069
|
}
|
|
1160
|
-
const vNode = doc.cos.resolve(
|
|
2070
|
+
const vNode = doc.cos.resolve(dictGet6(dict, "V"));
|
|
1161
2071
|
if (vNode?.kind === "name") return `/${vNode.decoded}`;
|
|
1162
|
-
if (vNode?.kind === "string") return `(${escapeFdfString(
|
|
2072
|
+
if (vNode?.kind === "string") return `(${escapeFdfString(decodePdfString5(vNode))})`;
|
|
1163
2073
|
return "()";
|
|
1164
2074
|
};
|
|
1165
2075
|
const serializeCosFieldNode = (nodeOrRef, prefix) => {
|
|
1166
2076
|
const dict = doc.cos.resolveDict(nodeOrRef);
|
|
1167
2077
|
if (!dict) return void 0;
|
|
1168
|
-
const tNode = doc.cos.resolve(
|
|
1169
|
-
const partialName = tNode?.kind === "string" ?
|
|
2078
|
+
const tNode = doc.cos.resolve(dictGet6(dict, "T"));
|
|
2079
|
+
const partialName = tNode?.kind === "string" ? decodePdfString5(tNode) : "";
|
|
1170
2080
|
const fullName = prefix && partialName ? `${prefix}.${partialName}` : partialName || prefix;
|
|
1171
|
-
const kidsArr = doc.cos.resolveArray(
|
|
2081
|
+
const kidsArr = doc.cos.resolveArray(dictGet6(dict, "Kids"));
|
|
1172
2082
|
const namedKids = [];
|
|
1173
2083
|
if (kidsArr) {
|
|
1174
2084
|
for (const k of kidsArr.items) {
|
|
1175
2085
|
const kDict = doc.cos.resolveDict(k);
|
|
1176
|
-
if (kDict &&
|
|
2086
|
+
if (kDict && dictGet6(kDict, "T")) {
|
|
1177
2087
|
const serializedKid = serializeCosFieldNode(k, fullName);
|
|
1178
2088
|
if (serializedKid) namedKids.push(serializedKid);
|
|
1179
2089
|
}
|
|
@@ -1187,8 +2097,8 @@ function formatGenerateFdf(doc) {
|
|
|
1187
2097
|
};
|
|
1188
2098
|
const entries = [];
|
|
1189
2099
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
1190
|
-
const acroForm = catalog ? doc.cos.resolveDict(
|
|
1191
|
-
const fieldsArr = acroForm ? doc.cos.resolveArray(
|
|
2100
|
+
const acroForm = catalog ? doc.cos.resolveDict(dictGet6(catalog, "AcroForm")) : void 0;
|
|
2101
|
+
const fieldsArr = acroForm ? doc.cos.resolveArray(dictGet6(acroForm, "Fields")) : void 0;
|
|
1192
2102
|
if (fieldsArr && fieldsArr.items.length > 0) {
|
|
1193
2103
|
for (const item of fieldsArr.items) {
|
|
1194
2104
|
const s = serializeCosFieldNode(item, "");
|
|
@@ -1196,7 +2106,7 @@ function formatGenerateFdf(doc) {
|
|
|
1196
2106
|
}
|
|
1197
2107
|
} else {
|
|
1198
2108
|
for (const f of fields) {
|
|
1199
|
-
entries.push(`<< /T (${escapeFdfString(f.name)}) /V ${formatFieldVal(f.name,
|
|
2109
|
+
entries.push(`<< /T (${escapeFdfString(f.name)}) /V ${formatFieldVal(f.name, cosDict4({}))} >>`);
|
|
1200
2110
|
}
|
|
1201
2111
|
}
|
|
1202
2112
|
return `%FDF-1.2
|
|
@@ -1214,9 +2124,9 @@ function setDocumentBookmarks(doc, bookmarks) {
|
|
|
1214
2124
|
if (bookmarks.length === 0 || doc.pageCount === 0) return;
|
|
1215
2125
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
1216
2126
|
if (!catalog) return;
|
|
1217
|
-
const outlinesDict =
|
|
2127
|
+
const outlinesDict = cosDict4({ Type: cosName("Outlines") });
|
|
1218
2128
|
const outlinesRef = doc.cos.allocateObject(outlinesDict);
|
|
1219
|
-
|
|
2129
|
+
dictSet3(catalog, "Outlines", outlinesRef);
|
|
1220
2130
|
const stack = [{ ref: outlinesRef, dict: outlinesDict, children: [] }];
|
|
1221
2131
|
for (const bm of bookmarks) {
|
|
1222
2132
|
const targetLevel = Math.max(1, bm.level);
|
|
@@ -1235,26 +2145,26 @@ function setDocumentBookmarks(doc, bookmarks) {
|
|
|
1235
2145
|
const parentState = stack[stack.length - 1];
|
|
1236
2146
|
const pageIdx = Math.max(0, Math.min(doc.pageCount - 1, bm.pageNumber - 1));
|
|
1237
2147
|
const pageRef = doc.getPage(pageIdx).ref;
|
|
1238
|
-
const itemDict =
|
|
1239
|
-
Title:
|
|
2148
|
+
const itemDict = cosDict4({
|
|
2149
|
+
Title: cosString4(bm.title),
|
|
1240
2150
|
Parent: parentState.ref,
|
|
1241
|
-
Dest:
|
|
2151
|
+
Dest: cosArray4([pageRef, cosName("XYZ"), { kind: "null" }, { kind: "null" }, { kind: "null" }])
|
|
1242
2152
|
});
|
|
1243
2153
|
const itemRef = doc.cos.allocateObject(itemDict);
|
|
1244
2154
|
const prevSibling = parentState.children[parentState.children.length - 1];
|
|
1245
2155
|
if (prevSibling) {
|
|
1246
|
-
|
|
1247
|
-
|
|
2156
|
+
dictSet3(prevSibling.dict, "Next", itemRef);
|
|
2157
|
+
dictSet3(itemDict, "Prev", prevSibling.ref);
|
|
1248
2158
|
} else {
|
|
1249
|
-
|
|
2159
|
+
dictSet3(parentState.dict, "First", itemRef);
|
|
1250
2160
|
}
|
|
1251
|
-
|
|
2161
|
+
dictSet3(parentState.dict, "Last", itemRef);
|
|
1252
2162
|
parentState.children.push({ ref: itemRef, dict: itemDict });
|
|
1253
|
-
|
|
2163
|
+
dictSet3(parentState.dict, "Count", cosNumber4(parentState.children.length));
|
|
1254
2164
|
}
|
|
1255
2165
|
}
|
|
1256
2166
|
function applyUpdateInfoText(doc, text) {
|
|
1257
|
-
const
|
|
2167
|
+
const lines2 = text.replaceAll("\r\n", "\n").split("\n");
|
|
1258
2168
|
let mode = "none";
|
|
1259
2169
|
let curKey = "";
|
|
1260
2170
|
let bmTitle = "";
|
|
@@ -1306,7 +2216,7 @@ function applyUpdateInfoText(doc, text) {
|
|
|
1306
2216
|
pmDimensions = void 0;
|
|
1307
2217
|
pmCropBox = void 0;
|
|
1308
2218
|
};
|
|
1309
|
-
for (const raw of
|
|
2219
|
+
for (const raw of lines2) {
|
|
1310
2220
|
const line = raw.trim();
|
|
1311
2221
|
if (line === "InfoBegin") {
|
|
1312
2222
|
flushStanza();
|
|
@@ -1341,7 +2251,7 @@ function applyUpdateInfoText(doc, text) {
|
|
|
1341
2251
|
}
|
|
1342
2252
|
const infoDict = doc.cos.infoRef ? doc.cos.resolveDict(doc.cos.infoRef) : void 0;
|
|
1343
2253
|
if (infoDict) {
|
|
1344
|
-
|
|
2254
|
+
dictSet3(infoDict, curKey, cosString4(val));
|
|
1345
2255
|
}
|
|
1346
2256
|
}
|
|
1347
2257
|
mode = "none";
|
|
@@ -1388,7 +2298,7 @@ function applyUpdateInfoText(doc, text) {
|
|
|
1388
2298
|
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
2299
|
const b0 = pdfId0Hex !== void 0 ? hexToBytes(pdfId0Hex) : existing0;
|
|
1390
2300
|
const b1 = pdfId1Hex !== void 0 ? hexToBytes(pdfId1Hex) : existing1;
|
|
1391
|
-
doc.cos.idArray =
|
|
2301
|
+
doc.cos.idArray = cosArray4([cosHexString(b0), cosHexString(b1)]);
|
|
1392
2302
|
}
|
|
1393
2303
|
for (const [pageNum, rot] of pageRotations.entries()) {
|
|
1394
2304
|
if (pageNum >= 1 && pageNum <= doc.pageCount) {
|
|
@@ -1397,28 +2307,28 @@ function applyUpdateInfoText(doc, text) {
|
|
|
1397
2307
|
}
|
|
1398
2308
|
for (const [pageNum, [w, h]] of pageDimensions.entries()) {
|
|
1399
2309
|
if (pageNum >= 1 && pageNum <= doc.pageCount) {
|
|
1400
|
-
|
|
2310
|
+
dictSet3(
|
|
1401
2311
|
doc.getPage(pageNum - 1).pageDict,
|
|
1402
2312
|
"MediaBox",
|
|
1403
|
-
|
|
2313
|
+
cosArray4([cosNumber4(0), cosNumber4(0), cosNumber4(w), cosNumber4(h)])
|
|
1404
2314
|
);
|
|
1405
2315
|
}
|
|
1406
2316
|
}
|
|
1407
2317
|
for (const [pageNum, [x0, y0, x1, y1]] of pageMediaRects.entries()) {
|
|
1408
2318
|
if (pageNum >= 1 && pageNum <= doc.pageCount) {
|
|
1409
|
-
|
|
2319
|
+
dictSet3(
|
|
1410
2320
|
doc.getPage(pageNum - 1).pageDict,
|
|
1411
2321
|
"MediaBox",
|
|
1412
|
-
|
|
2322
|
+
cosArray4([cosNumber4(x0), cosNumber4(y0), cosNumber4(x1), cosNumber4(y1)])
|
|
1413
2323
|
);
|
|
1414
2324
|
}
|
|
1415
2325
|
}
|
|
1416
2326
|
for (const [pageNum, [x0, y0, x1, y1]] of pageCropBoxes.entries()) {
|
|
1417
2327
|
if (pageNum >= 1 && pageNum <= doc.pageCount) {
|
|
1418
|
-
|
|
2328
|
+
dictSet3(
|
|
1419
2329
|
doc.getPage(pageNum - 1).pageDict,
|
|
1420
2330
|
"CropBox",
|
|
1421
|
-
|
|
2331
|
+
cosArray4([cosNumber4(x0), cosNumber4(y0), cosNumber4(x1), cosNumber4(y1)])
|
|
1422
2332
|
);
|
|
1423
2333
|
}
|
|
1424
2334
|
}
|
|
@@ -1427,21 +2337,21 @@ function applyUpdateInfoText(doc, text) {
|
|
|
1427
2337
|
if (catalog) {
|
|
1428
2338
|
const numsItems = [];
|
|
1429
2339
|
for (const pl of pageLabels) {
|
|
1430
|
-
numsItems.push(
|
|
2340
|
+
numsItems.push(cosNumber4(Math.max(0, pl.newIndex - 1)));
|
|
1431
2341
|
const lblEntries = {
|
|
1432
|
-
St:
|
|
2342
|
+
St: cosNumber4(pl.start)
|
|
1433
2343
|
};
|
|
1434
2344
|
if (pl.prefix) {
|
|
1435
|
-
lblEntries.P =
|
|
2345
|
+
lblEntries.P = cosString4(pl.prefix);
|
|
1436
2346
|
}
|
|
1437
2347
|
const pdfStyle = PAGE_LABEL_STYLE_TO_PDF[pl.style];
|
|
1438
2348
|
if (pdfStyle) {
|
|
1439
2349
|
lblEntries.S = cosName(pdfStyle);
|
|
1440
2350
|
}
|
|
1441
|
-
numsItems.push(
|
|
2351
|
+
numsItems.push(cosDict4(lblEntries));
|
|
1442
2352
|
}
|
|
1443
|
-
const plDict =
|
|
1444
|
-
|
|
2353
|
+
const plDict = cosDict4({ Nums: cosArray4(numsItems) });
|
|
2354
|
+
dictSet3(catalog, "PageLabels", doc.cos.allocateObject(plDict));
|
|
1445
2355
|
}
|
|
1446
2356
|
}
|
|
1447
2357
|
setDocumentBookmarks(doc, bookmarks);
|
|
@@ -1449,20 +2359,20 @@ function applyUpdateInfoText(doc, text) {
|
|
|
1449
2359
|
function attachFilesToDocument(doc, filePaths, files, toPageSpec) {
|
|
1450
2360
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
1451
2361
|
if (!catalog) return;
|
|
1452
|
-
let namesDict = doc.cos.resolveDict(
|
|
2362
|
+
let namesDict = doc.cos.resolveDict(dictGet6(catalog, "Names"));
|
|
1453
2363
|
if (!namesDict) {
|
|
1454
|
-
namesDict =
|
|
1455
|
-
|
|
2364
|
+
namesDict = cosDict4({});
|
|
2365
|
+
dictSet3(catalog, "Names", doc.cos.allocateObject(namesDict));
|
|
1456
2366
|
}
|
|
1457
|
-
let efTree = doc.cos.resolveDict(
|
|
2367
|
+
let efTree = doc.cos.resolveDict(dictGet6(namesDict, "EmbeddedFiles"));
|
|
1458
2368
|
if (!efTree) {
|
|
1459
|
-
efTree =
|
|
1460
|
-
|
|
2369
|
+
efTree = cosDict4({ Names: cosArray4([]) });
|
|
2370
|
+
dictSet3(namesDict, "EmbeddedFiles", doc.cos.allocateObject(efTree));
|
|
1461
2371
|
}
|
|
1462
|
-
let namesArr = doc.cos.resolveArray(
|
|
2372
|
+
let namesArr = doc.cos.resolveArray(dictGet6(efTree, "Names"));
|
|
1463
2373
|
if (!namesArr) {
|
|
1464
|
-
namesArr =
|
|
1465
|
-
|
|
2374
|
+
namesArr = cosArray4([]);
|
|
2375
|
+
dictSet3(efTree, "Names", namesArr);
|
|
1466
2376
|
}
|
|
1467
2377
|
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
2378
|
for (const fp of filePaths) {
|
|
@@ -1471,34 +2381,34 @@ function attachFilesToDocument(doc, filePaths, files, toPageSpec) {
|
|
|
1471
2381
|
const baseName = fp.slice(fp.lastIndexOf("/") + 1);
|
|
1472
2382
|
const efStreamRef = doc.cos.allocateObject(
|
|
1473
2383
|
cosStream(bytes, {
|
|
1474
|
-
dict:
|
|
2384
|
+
dict: cosDict4({ Type: cosName("EmbeddedFile") }),
|
|
1475
2385
|
compress: true
|
|
1476
2386
|
})
|
|
1477
2387
|
);
|
|
1478
2388
|
const filespecRef = doc.cos.allocateObject(
|
|
1479
|
-
|
|
2389
|
+
cosDict4({
|
|
1480
2390
|
Type: cosName("Filespec"),
|
|
1481
|
-
F:
|
|
1482
|
-
UF:
|
|
1483
|
-
EF:
|
|
2391
|
+
F: cosString4(baseName),
|
|
2392
|
+
UF: cosString4(baseName),
|
|
2393
|
+
EF: cosDict4({ F: efStreamRef })
|
|
1484
2394
|
})
|
|
1485
2395
|
);
|
|
1486
|
-
namesArr.items.push(
|
|
2396
|
+
namesArr.items.push(cosString4(baseName), filespecRef);
|
|
1487
2397
|
if (targetPageIdx !== void 0) {
|
|
1488
2398
|
const pageDict = doc.getPage(targetPageIdx).pageDict;
|
|
1489
|
-
let annotsArr = doc.cos.resolveArray(
|
|
2399
|
+
let annotsArr = doc.cos.resolveArray(dictGet6(pageDict, "Annots"));
|
|
1490
2400
|
if (!annotsArr) {
|
|
1491
|
-
annotsArr =
|
|
1492
|
-
|
|
2401
|
+
annotsArr = cosArray4([]);
|
|
2402
|
+
dictSet3(pageDict, "Annots", annotsArr);
|
|
1493
2403
|
}
|
|
1494
2404
|
const annotRef = doc.cos.allocateObject(
|
|
1495
|
-
|
|
2405
|
+
cosDict4({
|
|
1496
2406
|
Type: cosName("Annot"),
|
|
1497
2407
|
Subtype: cosName("FileAttachment"),
|
|
1498
2408
|
Name: cosName("PushPin"),
|
|
1499
|
-
Contents:
|
|
2409
|
+
Contents: cosString4(baseName),
|
|
1500
2410
|
FS: filespecRef,
|
|
1501
|
-
Rect:
|
|
2411
|
+
Rect: cosArray4([cosNumber4(20), cosNumber4(20), cosNumber4(40), cosNumber4(40)])
|
|
1502
2412
|
})
|
|
1503
2413
|
);
|
|
1504
2414
|
annotsArr.items.push(annotRef);
|
|
@@ -1515,11 +2425,11 @@ function attachmentBasename(name) {
|
|
|
1515
2425
|
function unpackFilesFromDocument(doc, outDir, files) {
|
|
1516
2426
|
const cleanDir = outDir.endsWith("/") ? outDir.slice(0, -1) : outDir;
|
|
1517
2427
|
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(
|
|
2428
|
+
const ufNode = doc.cos.resolve(dictGet6(specDict, "UF") ?? dictGet6(specDict, "F"));
|
|
2429
|
+
const fileName = attachmentBasename(ufNode?.kind === "string" ? decodePdfString5(ufNode) : fallbackName);
|
|
2430
|
+
const efDict = doc.cos.resolveDict(dictGet6(specDict, "EF"));
|
|
1521
2431
|
const fStream = efDict ? doc.cos.resolve(
|
|
1522
|
-
|
|
2432
|
+
dictGet6(efDict, "UF") ?? dictGet6(efDict, "F") ?? dictGet6(efDict, "DOS") ?? dictGet6(efDict, "Mac") ?? dictGet6(efDict, "Unix")
|
|
1523
2433
|
) : void 0;
|
|
1524
2434
|
if (fStream?.kind === "stream") {
|
|
1525
2435
|
const decoded = doc.cos.decodeStream(fStream);
|
|
@@ -1529,10 +2439,10 @@ function unpackFilesFromDocument(doc, outDir, files) {
|
|
|
1529
2439
|
};
|
|
1530
2440
|
const catalog = doc.cos.resolveDict(doc.cos.rootRef);
|
|
1531
2441
|
if (catalog) {
|
|
1532
|
-
const namesDict = doc.cos.resolveDict(
|
|
2442
|
+
const namesDict = doc.cos.resolveDict(dictGet6(catalog, "Names"));
|
|
1533
2443
|
const efPairs = [];
|
|
1534
2444
|
if (namesDict) {
|
|
1535
|
-
collectNameTreePairs(doc,
|
|
2445
|
+
collectNameTreePairs(doc, dictGet6(namesDict, "EmbeddedFiles"), efPairs);
|
|
1536
2446
|
}
|
|
1537
2447
|
for (const pair of efPairs) {
|
|
1538
2448
|
const specDict = doc.cos.resolveDict(pair.value);
|
|
@@ -1540,7 +2450,7 @@ function unpackFilesFromDocument(doc, outDir, files) {
|
|
|
1540
2450
|
writeSpecDict(specDict, pair.name);
|
|
1541
2451
|
}
|
|
1542
2452
|
}
|
|
1543
|
-
const rootAfArr = doc.cos.resolveArray(
|
|
2453
|
+
const rootAfArr = doc.cos.resolveArray(dictGet6(catalog, "AF"));
|
|
1544
2454
|
if (rootAfArr) {
|
|
1545
2455
|
for (const item of rootAfArr.items) {
|
|
1546
2456
|
const specDict = doc.cos.resolveDict(item);
|
|
@@ -1549,69 +2459,32 @@ function unpackFilesFromDocument(doc, outDir, files) {
|
|
|
1549
2459
|
}
|
|
1550
2460
|
}
|
|
1551
2461
|
for (let p = 0; p < doc.pageCount; p++) {
|
|
1552
|
-
const pageAfArr = doc.cos.resolveArray(
|
|
2462
|
+
const pageAfArr = doc.cos.resolveArray(dictGet6(doc.getPage(p).pageDict, "AF"));
|
|
1553
2463
|
if (pageAfArr) {
|
|
1554
2464
|
for (const item of pageAfArr.items) {
|
|
1555
2465
|
const specDict = doc.cos.resolveDict(item);
|
|
1556
2466
|
if (specDict) writeSpecDict(specDict);
|
|
1557
2467
|
}
|
|
1558
2468
|
}
|
|
1559
|
-
const annotsArr = doc.cos.resolveArray(
|
|
2469
|
+
const annotsArr = doc.cos.resolveArray(dictGet6(doc.getPage(p).pageDict, "Annots"));
|
|
1560
2470
|
if (!annotsArr) continue;
|
|
1561
2471
|
for (const item of annotsArr.items) {
|
|
1562
2472
|
const annotDict = doc.cos.resolveDict(item);
|
|
1563
2473
|
if (!annotDict) continue;
|
|
1564
|
-
const subNode = doc.cos.resolve(
|
|
2474
|
+
const subNode = doc.cos.resolve(dictGet6(annotDict, "Subtype"));
|
|
1565
2475
|
if (subNode?.kind === "name" && subNode.decoded === "FileAttachment") {
|
|
1566
|
-
const specDict = doc.cos.resolveDict(
|
|
2476
|
+
const specDict = doc.cos.resolveDict(dictGet6(annotDict, "FS"));
|
|
1567
2477
|
if (specDict) writeSpecDict(specDict);
|
|
1568
2478
|
}
|
|
1569
2479
|
}
|
|
1570
2480
|
}
|
|
1571
2481
|
}
|
|
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
2482
|
function cloneCosSubgraphInto(srcDoc, dstDoc, node, memo = /* @__PURE__ */ new Map()) {
|
|
1610
2483
|
if (!node) return void 0;
|
|
1611
2484
|
if (node.kind === "ref") {
|
|
1612
2485
|
const cached = memo.get(node.objectNumber);
|
|
1613
2486
|
if (cached) return cached;
|
|
1614
|
-
const placeholder = dstDoc.cos.allocateObject(
|
|
2487
|
+
const placeholder = dstDoc.cos.allocateObject(cosDict4({}));
|
|
1615
2488
|
memo.set(node.objectNumber, placeholder);
|
|
1616
2489
|
const resolved = srcDoc.cos.resolve(node);
|
|
1617
2490
|
const cloned = cloneCosSubgraphInto(srcDoc, dstDoc, resolved, memo);
|
|
@@ -1625,14 +2498,14 @@ function cloneCosSubgraphInto(srcDoc, dstDoc, node, memo = /* @__PURE__ */ new M
|
|
|
1625
2498
|
return placeholder;
|
|
1626
2499
|
}
|
|
1627
2500
|
if (node.kind === "array") {
|
|
1628
|
-
return
|
|
2501
|
+
return cosArray4(node.items.map((it) => cloneCosSubgraphInto(srcDoc, dstDoc, it, memo)).filter(Boolean));
|
|
1629
2502
|
}
|
|
1630
2503
|
if (node.kind === "dict") {
|
|
1631
|
-
const next =
|
|
2504
|
+
const next = cosDict4({});
|
|
1632
2505
|
for (const entry of node.entries) {
|
|
1633
2506
|
if (entry.key.decoded === "Parent") continue;
|
|
1634
2507
|
const clonedVal = cloneCosSubgraphInto(srcDoc, dstDoc, entry.value, memo);
|
|
1635
|
-
if (clonedVal)
|
|
2508
|
+
if (clonedVal) dictSet3(next, entry.key.decoded, clonedVal);
|
|
1636
2509
|
}
|
|
1637
2510
|
return next;
|
|
1638
2511
|
}
|
|
@@ -1697,31 +2570,31 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
|
|
|
1697
2570
|
const srcRes = srcPage.getResourcesDict();
|
|
1698
2571
|
const renamedResources = /* @__PURE__ */ new Map();
|
|
1699
2572
|
for (const subKey of ["Font", "XObject", "ExtGState", "ColorSpace", "Pattern", "Shading", "Properties"]) {
|
|
1700
|
-
const srcSub = overlayDoc.cos.resolveDict(
|
|
2573
|
+
const srcSub = overlayDoc.cos.resolveDict(dictGet6(srcRes, subKey));
|
|
1701
2574
|
if (!srcSub) continue;
|
|
1702
|
-
let dstSub = targetDoc.cos.resolveDict(
|
|
2575
|
+
let dstSub = targetDoc.cos.resolveDict(dictGet6(dstRes, subKey));
|
|
1703
2576
|
if (!dstSub) {
|
|
1704
|
-
dstSub =
|
|
1705
|
-
|
|
2577
|
+
dstSub = cosDict4({});
|
|
2578
|
+
dictSet3(dstRes, subKey, dstSub);
|
|
1706
2579
|
}
|
|
1707
2580
|
for (const entry of srcSub.entries) {
|
|
1708
2581
|
const origKey = entry.key.decoded;
|
|
1709
2582
|
const cloned = cloneCosSubgraphInto(overlayDoc, targetDoc, entry.value, memo);
|
|
1710
2583
|
if (!cloned) continue;
|
|
1711
|
-
if (!
|
|
1712
|
-
|
|
2584
|
+
if (!dictGet6(dstSub, origKey)) {
|
|
2585
|
+
dictSet3(dstSub, origKey, cloned);
|
|
1713
2586
|
} else {
|
|
1714
2587
|
let newKey = `Ov_${i}_${origKey}`;
|
|
1715
2588
|
let suffix = 1;
|
|
1716
|
-
while (
|
|
2589
|
+
while (dictGet6(dstSub, newKey)) {
|
|
1717
2590
|
newKey = `Ov_${i}_${suffix++}_${origKey}`;
|
|
1718
2591
|
}
|
|
1719
|
-
|
|
2592
|
+
dictSet3(dstSub, newKey, cloned);
|
|
1720
2593
|
renamedResources.set(origKey, newKey);
|
|
1721
2594
|
}
|
|
1722
2595
|
}
|
|
1723
2596
|
}
|
|
1724
|
-
const srcContents =
|
|
2597
|
+
const srcContents = dictGet6(srcPage.pageDict, "Contents");
|
|
1725
2598
|
if (!srcContents) continue;
|
|
1726
2599
|
const rawSrcNodes = [];
|
|
1727
2600
|
const resolvedSrcContents = overlayDoc.cos.resolve(srcContents);
|
|
@@ -1747,7 +2620,7 @@ function applyOverlayToDocument(targetDoc, overlayDoc, mode, multi) {
|
|
|
1747
2620
|
}
|
|
1748
2621
|
}
|
|
1749
2622
|
if (srcList.length === 0) continue;
|
|
1750
|
-
const dstContents =
|
|
2623
|
+
const dstContents = dictGet6(dstPage.pageDict, "Contents");
|
|
1751
2624
|
const toStreamList = (c) => {
|
|
1752
2625
|
if (!c) return [];
|
|
1753
2626
|
const r = targetDoc.cos.resolve(c);
|
|
@@ -1796,7 +2669,7 @@ ${fmt6(s)} 0 0 ${fmt6(s)} ${fmt4(tx)} ${fmt4(ty)} cm
|
|
|
1796
2669
|
const qOpenSrc = targetDoc.cos.allocateObject(cosStream(new TextEncoder().encode(srcOpenCmd), { compress: false }));
|
|
1797
2670
|
const qClose = targetDoc.cos.allocateObject(cosStream(new TextEncoder().encode("\nQ\n"), { compress: false }));
|
|
1798
2671
|
const combined = mode === "background" ? [qOpenSrc, ...srcList, qClose, qOpenDst, ...dstList, qClose] : [qOpenDst, ...dstList, qClose, qOpenSrc, ...srcList, qClose];
|
|
1799
|
-
|
|
2672
|
+
dictSet3(dstPage.pageDict, "Contents", cosArray4(combined));
|
|
1800
2673
|
}
|
|
1801
2674
|
}
|
|
1802
2675
|
function normalizeQuarterTurn(degrees) {
|
|
@@ -1870,8 +2743,8 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
1870
2743
|
if (obj.value.kind !== "stream")
|
|
1871
2744
|
continue;
|
|
1872
2745
|
const raw = singleDoc.cos.decodeStream(obj.value);
|
|
1873
|
-
|
|
1874
|
-
|
|
2746
|
+
dictDelete2(obj.value.dict, "Filter");
|
|
2747
|
+
dictDelete2(obj.value.dict, "DecodeParms");
|
|
1875
2748
|
singleDoc.cos.objects.set(obj.objectNumber, {
|
|
1876
2749
|
...obj,
|
|
1877
2750
|
value: cosStream(raw, {
|
|
@@ -1980,9 +2853,9 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
1980
2853
|
if (!cached) {
|
|
1981
2854
|
cached = [];
|
|
1982
2855
|
const cat = d.cos.resolveDict(d.cos.rootRef);
|
|
1983
|
-
const outDict = cat ? d.cos.resolveDict(
|
|
2856
|
+
const outDict = cat ? d.cos.resolveDict(dictGet6(cat, "Outlines")) : void 0;
|
|
1984
2857
|
if (outDict) {
|
|
1985
|
-
collectOutlineBookmarks(d,
|
|
2858
|
+
collectOutlineBookmarks(d, dictGet6(outDict, "First"), 1, cached);
|
|
1986
2859
|
}
|
|
1987
2860
|
bookmarksByDoc.set(d, cached);
|
|
1988
2861
|
}
|
|
@@ -2072,14 +2945,14 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
2072
2945
|
}
|
|
2073
2946
|
if (dropXfa) {
|
|
2074
2947
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
2075
|
-
const acroForm = root ? resultDoc.cos.resolveDict(
|
|
2948
|
+
const acroForm = root ? resultDoc.cos.resolveDict(dictGet6(root, "AcroForm")) : void 0;
|
|
2076
2949
|
if (acroForm)
|
|
2077
|
-
|
|
2950
|
+
dictDelete2(acroForm, "XFA");
|
|
2078
2951
|
}
|
|
2079
2952
|
if (dropXmp) {
|
|
2080
2953
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
2081
2954
|
if (root)
|
|
2082
|
-
|
|
2955
|
+
dictDelete2(root, "Metadata");
|
|
2083
2956
|
}
|
|
2084
2957
|
if (replacementFont && operation === "fill_form") {
|
|
2085
2958
|
const cleanFontName = replacementFont.startsWith("/") ? replacementFont.slice(1) : replacementFont;
|
|
@@ -2087,28 +2960,28 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
2087
2960
|
if (++cooperativeWork % 64 === 0)
|
|
2088
2961
|
yield;
|
|
2089
2962
|
if (obj.value.kind === "dict") {
|
|
2090
|
-
const stNode =
|
|
2091
|
-
const bfNode =
|
|
2963
|
+
const stNode = dictGet6(obj.value, "Subtype");
|
|
2964
|
+
const bfNode = dictGet6(obj.value, "BaseFont");
|
|
2092
2965
|
const subtype = stNode?.kind === "name" ? stNode.decoded : void 0;
|
|
2093
2966
|
const baseFont = bfNode?.kind === "name" ? bfNode.decoded : void 0;
|
|
2094
2967
|
if (subtype === "Type1" && baseFont === "Helvetica") {
|
|
2095
|
-
|
|
2968
|
+
dictSet3(obj.value, "BaseFont", cosName(cleanFontName));
|
|
2096
2969
|
}
|
|
2097
2970
|
}
|
|
2098
2971
|
}
|
|
2099
2972
|
}
|
|
2100
2973
|
if (operation === "fill_form" && !shouldFlatten) {
|
|
2101
2974
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
2102
|
-
const acroForm = root ? resultDoc.cos.resolveDict(
|
|
2975
|
+
const acroForm = root ? resultDoc.cos.resolveDict(dictGet6(root, "AcroForm")) : void 0;
|
|
2103
2976
|
if (acroForm) {
|
|
2104
|
-
|
|
2977
|
+
dictSet3(acroForm, "NeedAppearances", { kind: "boolean", value: needAppearances });
|
|
2105
2978
|
}
|
|
2106
2979
|
} else if (needAppearances && !shouldFlatten) {
|
|
2107
2980
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
2108
2981
|
if (root) {
|
|
2109
|
-
const acroForm = resultDoc.cos.resolveDict(
|
|
2982
|
+
const acroForm = resultDoc.cos.resolveDict(dictGet6(root, "AcroForm"));
|
|
2110
2983
|
if (acroForm) {
|
|
2111
|
-
|
|
2984
|
+
dictSet3(acroForm, "NeedAppearances", { kind: "boolean", value: true });
|
|
2112
2985
|
}
|
|
2113
2986
|
}
|
|
2114
2987
|
}
|
|
@@ -2116,12 +2989,12 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
2116
2989
|
if (keepFinalId) {
|
|
2117
2990
|
const lastInput = handleDocs[handleDocs.length - 1];
|
|
2118
2991
|
if (lastInput?.cos.idArray) {
|
|
2119
|
-
resultDoc.cos.idArray =
|
|
2992
|
+
resultDoc.cos.idArray = cosArray4([...lastInput.cos.idArray.items]);
|
|
2120
2993
|
}
|
|
2121
2994
|
} else if (keepFirstId || !resultDoc.cos.idArray) {
|
|
2122
2995
|
const firstInput = handleDocs[0];
|
|
2123
2996
|
if (firstInput?.cos.idArray) {
|
|
2124
|
-
resultDoc.cos.idArray =
|
|
2997
|
+
resultDoc.cos.idArray = cosArray4([...firstInput.cos.idArray.items]);
|
|
2125
2998
|
}
|
|
2126
2999
|
}
|
|
2127
3000
|
if (uncompressStreams || compressStreams) {
|
|
@@ -2131,8 +3004,8 @@ function* runPdftkCliSteps(argv, files, signal) {
|
|
|
2131
3004
|
if (obj.value.kind !== "stream")
|
|
2132
3005
|
continue;
|
|
2133
3006
|
const raw = resultDoc.cos.decodeStream(obj.value);
|
|
2134
|
-
|
|
2135
|
-
|
|
3007
|
+
dictDelete2(obj.value.dict, "Filter");
|
|
3008
|
+
dictDelete2(obj.value.dict, "DecodeParms");
|
|
2136
3009
|
resultDoc.cos.objects.set(obj.objectNumber, {
|
|
2137
3010
|
...obj,
|
|
2138
3011
|
value: cosStream(raw, {
|
|
@@ -2180,7 +3053,7 @@ function runPdftkCliSync(argv, files, signal) {
|
|
|
2180
3053
|
}
|
|
2181
3054
|
return next.value;
|
|
2182
3055
|
}
|
|
2183
|
-
async function executePdftk(context) {
|
|
3056
|
+
async function executePdftk(context, retainedContext = context) {
|
|
2184
3057
|
let cooperativeWork = 63;
|
|
2185
3058
|
const invocation = createOutputOperation(context, { write: async () => {
|
|
2186
3059
|
} });
|
|
@@ -2188,8 +3061,8 @@ async function executePdftk(context) {
|
|
|
2188
3061
|
const carrier = getCommandArguments(context);
|
|
2189
3062
|
const argv = [...carrier.args];
|
|
2190
3063
|
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({ ...
|
|
3064
|
+
if (parsed.options && (["output", "rotate", "attach_files", "stamp", "multistamp", "background", "multibackground", "burst", "update_info", "update_info_utf8", "cat", "shuffle"].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))) {
|
|
3065
|
+
return await executeRetainedPdftk({ ...retainedContext, signal: invocation.signal, stdout: invocation.child(context.stdout).output }, parsed.options);
|
|
2193
3066
|
}
|
|
2194
3067
|
const vfsFiles = /* @__PURE__ */ new Map();
|
|
2195
3068
|
let accountedBytes = 0;
|
|
@@ -2290,7 +3163,7 @@ function createPdftkCommand(options = {}) {
|
|
|
2290
3163
|
runtimeIdentity: commandRuntimeIdentity,
|
|
2291
3164
|
description: "Manipulate PDF documents, fill/flatten AcroForms, and assemble pages via @poe-code/pdf-ast",
|
|
2292
3165
|
execute(context) {
|
|
2293
|
-
return new InputByteBudget(maxInputBytes).run(context, executePdftk);
|
|
3166
|
+
return new InputByteBudget(maxInputBytes).run(context, (limited) => executePdftk(limited, { ...context, inputBudget: limited.inputBudget }));
|
|
2294
3167
|
}
|
|
2295
3168
|
});
|
|
2296
3169
|
}
|
|
@@ -2312,6 +3185,7 @@ function createPdftkCommands(options = {}) {
|
|
|
2312
3185
|
export {
|
|
2313
3186
|
createPdftkCommand,
|
|
2314
3187
|
createPdftkCommands,
|
|
3188
|
+
iteratePdftkRangeToken,
|
|
2315
3189
|
parsePdftkRangeToken,
|
|
2316
3190
|
pdftkCommand,
|
|
2317
3191
|
pdftkCommands,
|