@poe-platform/safe-bash 0.1.788 → 0.1.790
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/README.md +1 -1
- package/dist/image-ast/index.browser.js +147 -80
- package/dist/image-ast/index.js +147 -80
- package/dist/mp4-ast/mp4.d.ts +2 -0
- package/dist/pdf-ast/cos/parser.d.ts +1 -0
- package/dist/pdf-ast/cos/security.d.ts +2 -0
- package/dist/pdf-ast/cos/writer.d.ts +1 -0
- package/dist/pdf-ast/document.d.ts +3 -0
- package/dist/pdf-ast/edit/forms.d.ts +1 -0
- package/dist/pdf-ast/index.js +171 -82
- package/dist/safe-bash/chunks/{chunk-L5QQLNTO.js → chunk-22PI65AH.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-Q3E6C3DX.js → chunk-2TAGYMPK.js} +49 -34
- package/dist/safe-bash/chunks/{chunk-Z3HX3ZBA.js → chunk-2W4HTMEK.js} +52 -48
- package/dist/safe-bash/chunks/{chunk-FFZXP6ZC.js → chunk-3M7L7XU2.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-XNODZRVD.js → chunk-3QAO6UYS.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-YPETOVQU.js → chunk-3VKFK3NF.js} +2 -2
- package/dist/safe-bash/chunks/chunk-5OST7NOX.js +42 -0
- package/dist/safe-bash/chunks/{chunk-KEBSX2AX.js → chunk-6HLURHVU.js} +2 -2
- package/dist/safe-bash/chunks/chunk-DYEUZE6Z.js +19 -0
- package/dist/safe-bash/chunks/{chunk-T2TGCHKE.js → chunk-FM3WBSZT.js} +2 -2
- package/dist/safe-bash/chunks/chunk-GAYRKQM6.js +22 -0
- package/dist/safe-bash/chunks/{chunk-Q45QCA4J.js → chunk-I3KSESCR.js} +0 -7
- package/dist/safe-bash/chunks/{chunk-OSKDIBQS.js → chunk-JLIMK5TD.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-2AYZCT5X.js → chunk-JQ2FAJJT.js} +27 -23
- package/dist/safe-bash/chunks/{chunk-QA3NVP43.js → chunk-JRE6Z3T7.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-DC5EHLKS.js → chunk-NDIL6T7Y.js} +5 -5
- package/dist/safe-bash/chunks/{chunk-747G42FY.js → chunk-OPR4UAIT.js} +2 -2
- package/dist/safe-bash/chunks/chunk-OSMQCYSP.js +19 -0
- package/dist/safe-bash/chunks/chunk-OYB332PQ.js +17 -0
- package/dist/safe-bash/chunks/{chunk-ZMYVCRAF.js → chunk-QTIH2AFE.js} +77 -69
- package/dist/safe-bash/chunks/{chunk-PYTLIUST.js → chunk-SBESXWT2.js} +43 -44
- package/dist/safe-bash/chunks/{chunk-4FDQJUFW.js → chunk-SDEPGTOF.js} +1 -1
- package/dist/safe-bash/chunks/chunk-UZU5BIJI.js +32 -0
- package/dist/safe-bash/chunks/{chunk-BI6JV62X.js → chunk-VCCMROTL.js} +7 -10
- package/dist/safe-bash/chunks/chunk-W47GHRRF.js +13 -0
- package/dist/safe-bash/chunks/{chunk-NPMQWZUZ.js → chunk-WS7KZIUM.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-3PZYHMGM.js → chunk-YYAERCWS.js} +7 -7
- package/dist/safe-bash/chunks/{chunk-5U7JECDB.js → chunk-ZPGVEUKF.js} +8 -7
- package/dist/safe-bash/chunks/{csvkit-K55OYAQC.js → csvkit-USUJG62I.js} +65 -11
- package/dist/safe-bash/chunks/{ffmpeg-BEFTQ6DZ.js → ffmpeg-KRGG5DLH.js} +21 -10
- package/dist/safe-bash/chunks/{gh-HQWOWLWE.js → gh-UCFDUZCX.js} +16 -8
- package/dist/safe-bash/chunks/{git-UFNPAOYZ.js → git-LPAF6KDG.js} +7 -9
- package/dist/safe-bash/chunks/{imagemagick-53BMHH6D.js → imagemagick-KGREKK4G.js} +38 -7
- package/dist/safe-bash/chunks/{implementation-QUTAAYMT.js → implementation-FXDRYS5A.js} +34 -8
- package/dist/safe-bash/chunks/{pdfimages-4OYI6FLG.js → pdfimages-UADCF4G4.js} +12 -8
- package/dist/safe-bash/chunks/{pdfinfo-I7U6TQPP.js → pdfinfo-O7UWPF4W.js} +38 -13
- package/dist/safe-bash/chunks/{pdftk-SUA6FMHI.js → pdftk-AERXIJTN.js} +13 -8
- package/dist/safe-bash/chunks/{pdftoppm-4C5DGEWX.js → pdftoppm-L466JQKI.js} +17 -10
- package/dist/safe-bash/chunks/{pdftotext-Y4WI225Y.js → pdftotext-SUSI4WXS.js} +19 -9
- package/dist/safe-bash/chunks/{qpdf-IORB4RV5.js → qpdf-YL24KVRH.js} +14 -8
- package/dist/safe-bash/chunks/{sips-WHAMJFEU.js → sips-QXEQZERX.js} +14 -7
- package/dist/safe-bash/chunks/{soffice-SYEK6WJS.js → soffice-TBITRML3.js} +16 -8
- package/dist/safe-bash/chunks/{wkhtmltopdf-ZIICWJLF.js → wkhtmltopdf-NJA2THRC.js} +27 -7
- package/dist/safe-bash/command-chunks/chunk-2C5BEBPY.js +1388 -0
- package/dist/safe-bash/command-chunks/{chunk-FXYWQ6S4.js → chunk-2EXV2ZLV.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-PFBJR2PY.js → chunk-2KRKKW5S.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-4DSJDVBM.js → chunk-32F3RBUW.js} +10 -749
- package/dist/safe-bash/command-chunks/{chunk-L3MLMXL4.js → chunk-3ZK5F23O.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-4QX6XCDD.js → chunk-4RNIZ3RT.js} +79 -0
- package/dist/safe-bash/command-chunks/{chunk-D7TADAYG.js → chunk-64LG3EVJ.js} +17 -0
- package/dist/safe-bash/command-chunks/{chunk-TOSM3T3A.js → chunk-6EASC5EC.js} +20 -9
- package/dist/safe-bash/command-chunks/{chunk-ZF3ZVGQC.js → chunk-7JRITHKW.js} +150 -80
- package/dist/safe-bash/command-chunks/{chunk-IJ3FXP4Q.js → chunk-A3ZX6SCY.js} +1 -1
- package/dist/safe-bash/{chunks/chunk-LD76P7AG.js → command-chunks/chunk-AKDMCNX4.js} +74 -39
- package/dist/safe-bash/command-chunks/{chunk-KSIGF4AG.js → chunk-BK4CMEE6.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-JUDOV5MJ.js → chunk-CBDVLMJB.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-XGMWWUHV.js → chunk-CZ5DAK4K.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-Z57TV6TC.js → chunk-EZ2DTOLI.js} +4 -2
- package/dist/safe-bash/command-chunks/{chunk-ADCGH6A7.js → chunk-FH3D75FC.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WYJTWJZ5.js → chunk-G3G6W5ZE.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-3HDIDEUJ.js → chunk-GF54KE2M.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-H4LWTITX.js +169 -0
- package/dist/safe-bash/command-chunks/chunk-I2MQNBGR.js +145 -0
- package/dist/safe-bash/command-chunks/{chunk-Z7TYZG3A.js → chunk-IHHTTQX6.js} +5 -3
- package/dist/safe-bash/command-chunks/{chunk-5GRLAARV.js → chunk-IOXI5ZAJ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-INDIFLBW.js → chunk-JTAGNROA.js} +4 -0
- package/dist/safe-bash/command-chunks/{chunk-Y5IHIAY3.js → chunk-MDPIOQUD.js} +12 -8
- package/dist/safe-bash/command-chunks/chunk-PGEYORBZ.js +25 -0
- package/dist/safe-bash/command-chunks/chunk-QI4MGIN6.js +6 -0
- package/dist/safe-bash/command-chunks/chunk-QM4UZF3C.js +753 -0
- package/dist/safe-bash/command-chunks/chunk-QTYZAWSB.js +91 -0
- package/dist/safe-bash/command-chunks/chunk-SNK7K3XW.js +90 -0
- package/dist/safe-bash/command-chunks/chunk-T5OLGM43.js +314 -0
- package/dist/safe-bash/command-chunks/chunk-TB7IFMUZ.js +802 -0
- package/dist/safe-bash/command-chunks/{chunk-YNT4ZJHW.js → chunk-TPPBPIWL.js} +3 -3
- package/dist/safe-bash/command-chunks/chunk-VMK4XVKO.js +82 -0
- package/dist/safe-bash/command-chunks/chunk-VNSJKXDU.js +130 -0
- package/dist/safe-bash/command-chunks/{chunk-2LP3VMPA.js → chunk-WFDW4XXD.js} +1 -17
- package/dist/safe-bash/command-chunks/chunk-WR37IS4O.js +318 -0
- package/dist/safe-bash/command-chunks/chunk-YFNTMH6Z.js +6 -0
- package/dist/safe-bash/commands/basic.js +148 -48
- package/dist/safe-bash/commands/bytes/compression/index.js +5 -6
- package/dist/safe-bash/commands/cmp.d.ts +2 -3
- package/dist/safe-bash/commands/cmp.js +2 -689
- package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
- package/dist/safe-bash/commands/docx/index.browser.js +4 -47
- package/dist/safe-bash/commands/docx/index.d.ts +2 -24
- package/dist/safe-bash/commands/docx/index.js +2 -41
- package/dist/safe-bash/commands/docx/io.d.ts +1 -14
- package/dist/safe-bash/commands/docx/io.js +1 -15
- package/dist/safe-bash/commands/factor/index.browser.js +2 -2
- package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
- package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
- package/dist/safe-bash/commands/iconv/index.browser.js +2 -2
- package/dist/safe-bash/commands/line-endings/index.browser.js +2 -2
- package/dist/safe-bash/commands/llm/command.d.ts +1 -4
- package/dist/safe-bash/commands/llm/command.js +1 -248
- package/dist/safe-bash/commands/llm/elevenlabs-stream.d.ts +1 -2
- package/dist/safe-bash/commands/llm/elevenlabs-stream.js +1 -117
- package/dist/safe-bash/commands/llm/elevenlabs.d.ts +1 -15
- package/dist/safe-bash/commands/llm/elevenlabs.js +1 -123
- package/dist/safe-bash/commands/llm/index.browser.js +20 -15
- package/dist/safe-bash/commands/llm/index.d.ts +1 -6
- package/dist/safe-bash/commands/llm/index.js +1 -4
- package/dist/safe-bash/commands/llm/mime.d.ts +1 -2
- package/dist/safe-bash/commands/llm/mime.js +1 -136
- package/dist/safe-bash/commands/llm/openai-http.d.ts +1 -8
- package/dist/safe-bash/commands/llm/openai-http.js +1 -143
- package/dist/safe-bash/commands/llm/openai-sse.d.ts +1 -3
- package/dist/safe-bash/commands/llm/openai-sse.js +1 -78
- package/dist/safe-bash/commands/llm/openai.d.ts +1 -14
- package/dist/safe-bash/commands/llm/openai.js +1 -288
- package/dist/safe-bash/commands/llm/providers/elevenlabs.d.ts +1 -1
- package/dist/safe-bash/commands/llm/providers/elevenlabs.js +1 -1
- package/dist/safe-bash/commands/llm/providers/index.browser.js +6 -6
- package/dist/safe-bash/commands/llm/providers/index.d.ts +1 -3
- package/dist/safe-bash/commands/llm/providers/index.js +1 -2
- package/dist/safe-bash/commands/llm/providers/openai.d.ts +1 -1
- package/dist/safe-bash/commands/llm/providers/openai.js +1 -1
- package/dist/safe-bash/commands/llm/providers/shared.d.ts +1 -23
- package/dist/safe-bash/commands/llm/providers/shared.js +1 -65
- package/dist/safe-bash/commands/llm/service.d.ts +1 -37
- package/dist/safe-bash/commands/llm/service.js +1 -151
- package/dist/safe-bash/commands/llm/types.d.ts +1 -52
- package/dist/safe-bash/commands/llm/types.js +1 -1
- package/dist/safe-bash/commands/mdq/index.browser.js +3 -3
- package/dist/safe-bash/commands/media/index.browser.js +1 -1
- package/dist/safe-bash/commands/network/index.browser.js +9 -9
- package/dist/safe-bash/commands/network/types.d.ts +2 -40
- package/dist/safe-bash/commands/node/index.browser.js +6 -8
- package/dist/safe-bash/commands/op/index.browser.js +3 -3
- package/dist/safe-bash/commands/op/index.js +12 -28
- package/dist/safe-bash/commands/pptx/index.d.ts +2 -28
- package/dist/safe-bash/commands/pptx/index.js +2 -152
- package/dist/safe-bash/commands/pr/index.browser.js +2 -2
- package/dist/safe-bash/commands/printf-float.d.ts +1 -0
- package/dist/safe-bash/commands/printf-float.js +48 -38
- package/dist/safe-bash/commands/printf-format.js +9 -6
- package/dist/safe-bash/commands/printf-quote.d.ts +3 -0
- package/dist/safe-bash/commands/printf-quote.js +62 -0
- package/dist/safe-bash/commands/printf-wide.d.ts +5 -0
- package/dist/safe-bash/commands/printf-wide.js +41 -0
- package/dist/safe-bash/commands/python/index.browser.js +8 -8
- package/dist/safe-bash/commands/python/worker.browser.js +2 -2
- package/dist/safe-bash/commands/truncate.d.ts +2 -3
- package/dist/safe-bash/commands/truncate.js +2 -686
- package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
- package/dist/safe-bash/commands/xml/index.browser.js +2 -2
- package/dist/safe-bash/commands/yq/index.browser.js +3 -3
- package/dist/safe-bash/contracts/diagnostics.d.ts +2 -0
- package/dist/safe-bash/contracts/diagnostics.js +2 -0
- package/dist/safe-bash/contracts/runtime-control.d.ts +2 -0
- package/dist/safe-bash/contracts/runtime-control.js +2 -0
- package/dist/safe-bash/core.browser.d.ts +1 -1
- package/dist/safe-bash/core.browser.js +10645 -14065
- package/dist/safe-bash/core.d.ts +10 -1
- package/dist/safe-bash/core.js +0 -1
- package/dist/safe-bash/jobs.browser.js +5 -4
- package/dist/safe-bash/opt-in/commands/cmp/index.d.ts +6 -2
- package/dist/safe-bash/opt-in/commands/cmp/index.js +776 -79
- package/dist/safe-bash/opt-in/commands/cmp/options.d.ts +0 -12
- package/dist/safe-bash/opt-in/commands/cmp/options.js +0 -153
- package/dist/safe-bash/opt-in/commands/truncate/index.d.ts +8 -3
- package/dist/safe-bash/opt-in/commands/truncate/index.js +790 -272
- package/dist/safe-bash/opt-in/commands/truncate/sync.d.ts +1 -0
- package/dist/safe-bash/opt-in/commands/truncate/sync.js +60 -0
- package/dist/safe-bash/optional-host.browser.js +61 -80
- package/dist/safe-bash/optional-host.d.ts +3 -1
- package/dist/safe-bash/optional-host.js +3 -1
- package/dist/safe-bash/shell/runtime.js +44 -18
- package/dist/safe-bash/yq-browser/index.js +1 -1
- package/dist/safe-bash-checksum-engine/index.d.ts +1 -1
- package/dist/safe-bash-checksum-engine/index.js +14 -2
- package/dist/safe-bash-command-bzip2/index.js +2 -1
- package/dist/safe-bash-command-cmp/index.d.ts +10 -0
- package/dist/safe-bash-command-cmp/index.js +796 -0
- package/dist/safe-bash-command-cmp/options.d.ts +12 -0
- package/dist/safe-bash-command-cmp/options.js +42 -0
- package/dist/safe-bash-command-csvcut/index.js +11 -8
- package/dist/safe-bash-command-csvgrep/index.js +35 -7
- package/dist/safe-bash-command-csvkit/codecs/python.js +4 -3
- package/dist/safe-bash-command-csvkit/codecs/utf8.js +3 -2
- package/dist/safe-bash-command-csvkit/index.js +80 -324
- package/dist/safe-bash-command-csvkit/python-regex.d.ts +5 -0
- package/dist/safe-bash-command-csvkit/python-regex.js +14 -0
- package/dist/safe-bash-command-csvkit/runtime.d.ts +1 -0
- package/dist/safe-bash-command-csvkit/sync-support.js +4 -2
- package/dist/safe-bash-command-diff3/index.js +3 -0
- package/dist/safe-bash-command-docx/LICENSE +21 -0
- package/dist/safe-bash-command-docx/index.d.ts +30 -0
- package/dist/safe-bash-command-docx/index.js +67 -0
- package/dist/safe-bash-command-docx/io.d.ts +14 -0
- package/dist/safe-bash-command-docx/io.js +26 -0
- package/dist/safe-bash-command-envsubst/index.js +34 -3
- package/dist/safe-bash-command-exiftool/index.js +3 -0
- package/dist/safe-bash-command-ffmpeg/index.js +8073 -7940
- package/dist/safe-bash-command-fold/family.js +1 -1
- package/dist/safe-bash-command-fold/index.js +1 -1
- package/dist/safe-bash-command-git/git_rust.wasm +0 -0
- package/dist/safe-bash-command-git/wasm.generated.js +1 -1
- package/dist/safe-bash-command-htmlq/index.js +5 -0
- package/dist/safe-bash-command-imagemagick/index.d.ts +25 -21
- package/dist/safe-bash-command-imagemagick/index.js +671 -273
- package/dist/safe-bash-command-llm/LICENSE +21 -0
- package/dist/safe-bash-command-llm/command.d.ts +5 -0
- package/dist/safe-bash-command-llm/command.js +14 -0
- package/dist/safe-bash-command-llm/configuration.d.ts +18 -0
- package/dist/safe-bash-command-llm/elevenlabs-stream.d.ts +2 -0
- package/dist/safe-bash-command-llm/elevenlabs-stream.js +7 -0
- package/dist/safe-bash-command-llm/elevenlabs.d.ts +15 -0
- package/dist/safe-bash-command-llm/elevenlabs.js +10 -0
- package/dist/safe-bash-command-llm/index.d.ts +10 -0
- package/dist/safe-bash-command-llm/index.js +46 -0
- package/dist/safe-bash-command-llm/mime.d.ts +2 -0
- package/dist/safe-bash-command-llm/mime.js +9 -0
- package/dist/safe-bash-command-llm/model-options.d.ts +3 -0
- package/dist/safe-bash-command-llm/openai-http.d.ts +8 -0
- package/dist/safe-bash-command-llm/openai-http.js +17 -0
- package/dist/safe-bash-command-llm/openai-sse.d.ts +3 -0
- package/dist/safe-bash-command-llm/openai-sse.js +8 -0
- package/dist/safe-bash-command-llm/openai.d.ts +14 -0
- package/dist/safe-bash-command-llm/openai.js +12 -0
- package/dist/safe-bash-command-llm/providers/elevenlabs.d.ts +1 -0
- package/dist/safe-bash-command-llm/providers/elevenlabs.js +11 -0
- package/dist/safe-bash-command-llm/providers/index.d.ts +3 -0
- package/dist/safe-bash-command-llm/providers/index.js +24 -0
- package/dist/safe-bash-command-llm/providers/openai.d.ts +1 -0
- package/dist/safe-bash-command-llm/providers/openai.js +13 -0
- package/dist/safe-bash-command-llm/providers/shared.d.ts +23 -0
- package/dist/safe-bash-command-llm/providers/shared.js +13 -0
- package/dist/safe-bash-command-llm/schemas.d.ts +2 -0
- package/dist/safe-bash-command-llm/service.d.ts +42 -0
- package/dist/safe-bash-command-llm/service.js +9 -0
- package/dist/safe-bash-command-llm/templates.d.ts +27 -0
- package/dist/safe-bash-command-llm/types.d.ts +87 -0
- package/dist/safe-bash-command-llm/types.js +6 -0
- package/dist/safe-bash-command-mmdc/command.d.ts +4 -0
- package/dist/safe-bash-command-mmdc/index.d.ts +1 -1
- package/dist/safe-bash-command-mmdc/index.js +7134 -6699
- package/dist/safe-bash-command-mmdc/layout.d.ts +1 -0
- package/dist/safe-bash-command-mmdc/parser.d.ts +1 -0
- package/dist/safe-bash-command-mmdc/png.d.ts +3 -0
- package/dist/safe-bash-command-mmdc/raster.d.ts +1 -0
- package/dist/safe-bash-command-mmdc/svg.d.ts +1 -0
- package/dist/safe-bash-command-op/index.js +19 -14
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.d.ts +7 -1
- package/dist/safe-bash-command-pdfimages/index.js +210 -113
- package/dist/safe-bash-command-pdfinfo/index.d.ts +24 -20
- package/dist/safe-bash-command-pdfinfo/index.js +517 -241
- package/dist/safe-bash-command-pdftk/index.d.ts +7 -3
- package/dist/safe-bash-command-pdftk/index.js +261 -125
- package/dist/safe-bash-command-pdftoppm/index.d.ts +15 -7
- package/dist/safe-bash-command-pdftoppm/index.js +326 -189
- package/dist/safe-bash-command-pdftotext/index.d.ts +9 -5
- package/dist/safe-bash-command-pdftotext/index.js +237 -107
- package/dist/safe-bash-command-pptx/LICENSE +21 -0
- package/dist/safe-bash-command-pptx/index.d.ts +33 -0
- package/dist/safe-bash-command-pptx/index.js +168 -0
- package/dist/safe-bash-command-qpdf/index.d.ts +9 -3
- package/dist/safe-bash-command-qpdf/index.js +254 -130
- package/dist/safe-bash-command-sha512sum/index.js +12 -475
- package/dist/safe-bash-command-sips/index.d.ts +9 -5
- package/dist/safe-bash-command-sips/index.js +65 -46
- package/dist/safe-bash-command-soffice/index.d.ts +9 -3
- package/dist/safe-bash-command-soffice/index.js +66 -25
- package/dist/safe-bash-command-sqlite3/engine.d.ts +9 -0
- package/dist/safe-bash-command-sqlite3/index.d.ts +1 -0
- package/dist/safe-bash-command-sqlite3/index.js +851 -352
- package/dist/safe-bash-command-ssconvert/formats/xls.js +3 -3
- package/dist/safe-bash-command-ssconvert/index.js +147 -80
- package/dist/safe-bash-command-timeout/index.js +3 -3
- package/dist/safe-bash-command-truncate/index.d.ts +8 -3
- package/dist/safe-bash-command-truncate/index.js +790 -272
- package/dist/safe-bash-command-truncate/sync.d.ts +1 -0
- package/dist/safe-bash-command-truncate/sync.js +60 -0
- package/dist/safe-bash-command-wkhtmltopdf/index.js +239 -118
- package/dist/safe-bash-command-wkhtmltopdf/pdf-renderer.d.ts +1 -1
- package/dist/safe-bash-command-xxd/index.js +78 -20
- package/dist/safe-bash-command-xz/command.d.ts +4 -0
- package/dist/safe-bash-command-xz/index.d.ts +1 -1
- package/dist/safe-bash-command-xz/index.js +1 -1
- package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
- package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
- package/dist/safe-bash-compression-engine/files.js +6 -6
- package/dist/safe-bash-compression-engine/index.js +5 -5
- package/dist/safe-bash-compression-engine/operand.js +6 -6
- package/dist/safe-bash-compression-engine/stream.js +5 -5
- package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
- package/dist/safe-bash-contracts/command.js +3 -3
- package/dist/safe-bash-contracts/default-executor.d.ts +5 -0
- package/dist/safe-bash-contracts/default-executor.js +37 -0
- package/dist/safe-bash-contracts/diagnostics.js +3 -3
- package/dist/safe-bash-contracts/escaping.js +9 -9
- package/dist/safe-bash-contracts/filesystem-descriptor.js +3 -3
- package/dist/safe-bash-contracts/filesystem-output.js +8 -8
- package/dist/safe-bash-contracts/http.d.ts +41 -0
- package/dist/safe-bash-contracts/http.js +6 -0
- package/dist/safe-bash-contracts/index.js +21 -19
- package/dist/safe-bash-contracts/io.d.ts +12 -0
- package/dist/safe-bash-contracts/io.js +4 -1
- package/dist/safe-bash-contracts/output.js +3 -2
- package/dist/safe-bash-contracts/runtime-control.js +2 -2
- package/dist/safe-bash-contracts/signals.js +1 -1
- package/dist/safe-bash-contracts/yield.d.ts +1 -0
- package/dist/safe-bash-contracts/yield.js +3 -1
- package/dist/safe-bash-csv-engine/index.d.ts +10 -1
- package/dist/safe-bash-csv-engine/index.js +78 -6
- package/dist/safe-bash-io-engine/commands/search/requirements.js +3 -3
- package/dist/safe-bash-io-engine/commands/text-programs/shared.js +3 -3
- package/dist/safe-bash-io-engine/gnu-information.d.ts +1 -1
- package/dist/safe-bash-io-engine/gnu-information.js +1 -1
- package/dist/safe-bash-io-engine/internal.d.ts +1 -1
- package/dist/safe-bash-io-engine/internal.js +2 -2
- package/dist/safe-bash-query-engine/index.js +5 -5
- package/dist/safe-bash-query-engine/interpreter.js +3 -3
- package/dist/safe-bash-query-engine/query-core.js +5 -5
- package/package.json +2 -2
- package/dist/safe-bash/chunks/chunk-2G2T5MEM.js +0 -14
- package/dist/safe-bash/chunks/chunk-FJZNUUOQ.js +0 -81
- package/dist/safe-bash/chunks/chunk-GJWUEOT6.js +0 -14
- package/dist/safe-bash/chunks/chunk-LAPF2XE6.js +0 -14
- package/dist/safe-bash/chunks/chunk-O6356Z27.js +0 -37
- package/dist/safe-bash/chunks/chunk-S2LSZFZ6.js +0 -758
- package/dist/safe-bash/chunks/chunk-T3VDYWKZ.js +0 -21
- package/dist/safe-bash/chunks/chunk-VYW4Q6KF.js +0 -12
- package/dist/safe-bash/chunks/chunk-WHURJBET.js +0 -409
- package/dist/safe-bash/opt-in/commands/cmp/compare.js +0 -95
- package/dist/safe-bash/opt-in/commands/cmp/io.js +0 -218
- package/dist/safe-bash/command-chunks/{chunk-RTOJNFFL.js → chunk-KNI4GRXF.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-DEH3CMGL.js → chunk-QJ3ONEBI.js} +3 -3
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// packages/safe-bash-command-pdftk/dist/index.js
|
|
6
6
|
init_buffer();
|
|
7
|
+
import { yieldTurn, drainCooperativeSteps as drainSteps } from "../safe-bash-contracts/yield.js";
|
|
8
|
+
import { InputByteBudget } from "../safe-bash-contracts/io.js";
|
|
7
9
|
import { writeFileOutput } from "../safe-bash-contracts/filesystem-output-budget.js";
|
|
8
10
|
import {
|
|
9
11
|
commandRuntimeIdentity,
|
|
@@ -27100,6 +27102,11 @@ function tokenizeCos(bytes, start = 0, end = bytes.length) {
|
|
|
27100
27102
|
}
|
|
27101
27103
|
return tokens;
|
|
27102
27104
|
}
|
|
27105
|
+
function drainWork(work) {
|
|
27106
|
+
let step = work.next();
|
|
27107
|
+
while (!step.done) step = work.next();
|
|
27108
|
+
return step.value;
|
|
27109
|
+
}
|
|
27103
27110
|
function bytesToString3(bytes) {
|
|
27104
27111
|
if (typeof bytes !== "object" || bytes?.length === void 0) {
|
|
27105
27112
|
throw new Error("Invalid argument for bytesToString");
|
|
@@ -27695,7 +27702,9 @@ function concatByteArrays(chunks) {
|
|
|
27695
27702
|
}
|
|
27696
27703
|
return out;
|
|
27697
27704
|
}
|
|
27698
|
-
function
|
|
27705
|
+
function* serializeCosDocumentSteps(options) {
|
|
27706
|
+
yield;
|
|
27707
|
+
let work = 0;
|
|
27699
27708
|
const maxOutputBytes = options.maxOutputBytes ?? Infinity;
|
|
27700
27709
|
const maxObjects = options.maxObjects ?? Infinity;
|
|
27701
27710
|
const sorted = [...options.objects].sort((a, b) => a.objectNumber - b.objectNumber);
|
|
@@ -27718,6 +27727,7 @@ function serializeCosDocument(options) {
|
|
|
27718
27727
|
const packable = [];
|
|
27719
27728
|
const direct = [];
|
|
27720
27729
|
for (const obj of sorted) {
|
|
27730
|
+
if (++work % 16 === 0) yield;
|
|
27721
27731
|
const isLinearized = obj.value.kind === "dict" && dictGet(obj.value, "Linearized") !== void 0;
|
|
27722
27732
|
if (obj.value.kind !== "stream" && obj.generationNumber === 0 && !isLinearized) {
|
|
27723
27733
|
packable.push(obj);
|
|
@@ -27732,6 +27742,7 @@ function serializeCosDocument(options) {
|
|
|
27732
27742
|
const headerPairs = [];
|
|
27733
27743
|
let relOffset = 0;
|
|
27734
27744
|
for (const pObj of packable) {
|
|
27745
|
+
if (++work % 16 === 0) yield;
|
|
27735
27746
|
headerPairs.push(`${pObj.objectNumber} ${relOffset}`);
|
|
27736
27747
|
const bBytes = serializeCosNodeBytes(pObj.value);
|
|
27737
27748
|
const nl = textEncoder2.encode("\n");
|
|
@@ -27757,6 +27768,7 @@ function serializeCosDocument(options) {
|
|
|
27757
27768
|
];
|
|
27758
27769
|
const directOffsets = /* @__PURE__ */ new Map();
|
|
27759
27770
|
for (const dObj of allDirect) {
|
|
27771
|
+
if (++work % 16 === 0) yield;
|
|
27760
27772
|
directOffsets.set(dObj.objectNumber, { offset, generation: dObj.generationNumber });
|
|
27761
27773
|
const prefix = textEncoder2.encode(`${dObj.objectNumber} ${dObj.generationNumber} obj
|
|
27762
27774
|
`);
|
|
@@ -27767,6 +27779,7 @@ function serializeCosDocument(options) {
|
|
|
27767
27779
|
}
|
|
27768
27780
|
const compressedMap = /* @__PURE__ */ new Map();
|
|
27769
27781
|
for (let idx = 0; idx < packable.length; idx++) {
|
|
27782
|
+
if (++work % 16 === 0) yield;
|
|
27770
27783
|
compressedMap.set(packable[idx].objectNumber, idx);
|
|
27771
27784
|
}
|
|
27772
27785
|
const xrefOffset2 = offset;
|
|
@@ -27784,6 +27797,7 @@ function serializeCosDocument(options) {
|
|
|
27784
27797
|
};
|
|
27785
27798
|
writeEntry7(0, 0, 0, 65535);
|
|
27786
27799
|
for (let i = 1; i < size2; i++) {
|
|
27800
|
+
if (++work % 16 === 0) yield;
|
|
27787
27801
|
if (i === xrefStmNum) {
|
|
27788
27802
|
writeEntry7(i, 1, xrefOffset2, 0);
|
|
27789
27803
|
} else if (compressedMap.has(i)) {
|
|
@@ -27864,6 +27878,7 @@ ${xrefOffset2}
|
|
|
27864
27878
|
let pageCount = 0;
|
|
27865
27879
|
let firstPageObjNum = options.rootRef.objectNumber;
|
|
27866
27880
|
for (const o of sorted) {
|
|
27881
|
+
if (++work % 16 === 0) yield;
|
|
27867
27882
|
if (o.value.kind === "dict") {
|
|
27868
27883
|
const t = dictGet(o.value, "Type");
|
|
27869
27884
|
if (t?.kind === "name" && t.decoded === "Page") {
|
|
@@ -27911,6 +27926,7 @@ ${xrefOffset2}
|
|
|
27911
27926
|
}
|
|
27912
27927
|
const objectOffsets = /* @__PURE__ */ new Map();
|
|
27913
27928
|
for (const obj of sorted) {
|
|
27929
|
+
if (++work % 16 === 0) yield;
|
|
27914
27930
|
objectOffsets.set(obj.objectNumber, { offset, generation: obj.generationNumber });
|
|
27915
27931
|
let value = obj.value;
|
|
27916
27932
|
if (options.normalizeContent && value.kind === "stream" && value.decodedBytes) {
|
|
@@ -27942,6 +27958,7 @@ ${xrefOffset2}
|
|
|
27942
27958
|
0000000000 65535 f
|
|
27943
27959
|
`;
|
|
27944
27960
|
for (let i = 1; i < size; i++) {
|
|
27961
|
+
if (++work % 16 === 0) yield;
|
|
27945
27962
|
const entry = objectOffsets.get(i);
|
|
27946
27963
|
if (entry) {
|
|
27947
27964
|
xrefText += `${String(entry.offset).padStart(10, "0")} ${String(entry.generation).padStart(5, "0")} n
|
|
@@ -27988,6 +28005,7 @@ ${xrefOffset}
|
|
|
27988
28005
|
let endFirstPage = xrefOffset;
|
|
27989
28006
|
const sortedOffsets = [...objectOffsets.entries()].sort((a, b) => a[1].offset - b[1].offset);
|
|
27990
28007
|
for (let i = 0; i < sortedOffsets.length; i++) {
|
|
28008
|
+
if (++work % 16 === 0) yield;
|
|
27991
28009
|
const [objNum, info3] = sortedOffsets[i];
|
|
27992
28010
|
const nextOff = sortedOffsets[i + 1]?.[1].offset ?? xrefOffset;
|
|
27993
28011
|
if (objNum === hintObjAfter.objectNumber) {
|
|
@@ -28021,6 +28039,9 @@ ${xrefOffset}
|
|
|
28021
28039
|
}
|
|
28022
28040
|
return fullBytes;
|
|
28023
28041
|
}
|
|
28042
|
+
function serializeCosDocument(options) {
|
|
28043
|
+
return drainWork(serializeCosDocumentSteps(options));
|
|
28044
|
+
}
|
|
28024
28045
|
function appendIncrementalRevision(originalBytes, doc, updatedObjects) {
|
|
28025
28046
|
const chunks = [originalBytes, textEncoder2.encode("\n")];
|
|
28026
28047
|
let offset = originalBytes.length + 1;
|
|
@@ -28294,48 +28315,30 @@ function encryptPdfBuffer(state, objectNumber, generationNumber, plaintext) {
|
|
|
28294
28315
|
const objKey = md5Bytes([state.fileKey, suffix]).subarray(0, Math.min(16, state.fileKey.length + 5));
|
|
28295
28316
|
return rc4Transform(objKey, plaintext);
|
|
28296
28317
|
}
|
|
28297
|
-
function
|
|
28318
|
+
function* transformNodeStringsAndStreamsSteps(node, transform, transformStream) {
|
|
28319
|
+
yield;
|
|
28298
28320
|
switch (node.kind) {
|
|
28299
28321
|
case "string":
|
|
28300
|
-
return {
|
|
28301
|
-
|
|
28302
|
-
|
|
28303
|
-
|
|
28304
|
-
};
|
|
28305
|
-
|
|
28306
|
-
return {
|
|
28307
|
-
kind: "array",
|
|
28308
|
-
items: node.items.map((item) => transformNodeStringsAndStreams(item, transform, transformStream))
|
|
28309
|
-
};
|
|
28322
|
+
return { kind: "string", format: "hex", bytes: transform(node.bytes) };
|
|
28323
|
+
case "array": {
|
|
28324
|
+
const items = [];
|
|
28325
|
+
for (const item of node.items) items.push(yield* transformNodeStringsAndStreamsSteps(item, transform, transformStream));
|
|
28326
|
+
return { kind: "array", items };
|
|
28327
|
+
}
|
|
28310
28328
|
case "dict": {
|
|
28311
|
-
const type = dictGet(node, "Type");
|
|
28312
|
-
const fieldType = dictGet(node, "FT");
|
|
28313
|
-
const byteRange = dictGet(node, "ByteRange");
|
|
28329
|
+
const type = dictGet(node, "Type"), fieldType = dictGet(node, "FT"), byteRange = dictGet(node, "ByteRange");
|
|
28314
28330
|
const signature = type?.kind === "name" && type.decoded === "Sig" || fieldType?.kind === "name" && fieldType.decoded === "Sig" || byteRange?.kind === "array" && dictGet(node, "Filter")?.kind === "name";
|
|
28315
|
-
|
|
28316
|
-
|
|
28317
|
-
|
|
28318
|
-
key: e.key,
|
|
28319
|
-
value: signature && e.key.decoded === "Contents" ? e.value : transformNodeStringsAndStreams(e.value, transform, transformStream)
|
|
28320
|
-
}))
|
|
28321
|
-
};
|
|
28331
|
+
const entries = [];
|
|
28332
|
+
for (const e of node.entries) entries.push({ key: e.key, value: signature && e.key.decoded === "Contents" ? e.value : yield* transformNodeStringsAndStreamsSteps(e.value, transform, transformStream) });
|
|
28333
|
+
return { kind: "dict", entries };
|
|
28322
28334
|
}
|
|
28323
28335
|
case "stream": {
|
|
28324
28336
|
const type = dictGet(node.dict, "Type");
|
|
28325
28337
|
if (type?.kind === "name" && type.decoded === "XRef") return node;
|
|
28326
28338
|
const stream = transformStream ? transformStream(node) : { ...node, rawBytes: transform(node.rawBytes) };
|
|
28327
|
-
const
|
|
28328
|
-
|
|
28329
|
-
|
|
28330
|
-
key: e.key,
|
|
28331
|
-
value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : transformNodeStringsAndStreams(e.value, transform, transformStream)
|
|
28332
|
-
}))
|
|
28333
|
-
};
|
|
28334
|
-
return {
|
|
28335
|
-
kind: "stream",
|
|
28336
|
-
dict: updatedDict,
|
|
28337
|
-
rawBytes: stream.rawBytes
|
|
28338
|
-
};
|
|
28339
|
+
const entries = [];
|
|
28340
|
+
for (const e of stream.dict.entries) entries.push({ key: e.key, value: e.key.decoded === "Length" ? cosNumber(stream.rawBytes.length) : yield* transformNodeStringsAndStreamsSteps(e.value, transform, transformStream) });
|
|
28341
|
+
return { kind: "stream", dict: { kind: "dict", entries }, rawBytes: stream.rawBytes };
|
|
28339
28342
|
}
|
|
28340
28343
|
default:
|
|
28341
28344
|
return node;
|
|
@@ -28404,7 +28407,8 @@ function createR6Encryption(userPassword, ownerPassword, pMask) {
|
|
|
28404
28407
|
StrF: cosName("StdCF")
|
|
28405
28408
|
}) };
|
|
28406
28409
|
}
|
|
28407
|
-
function
|
|
28410
|
+
function* encryptCosDocumentSteps(doc, options = {}) {
|
|
28411
|
+
yield;
|
|
28408
28412
|
const userPassword = options.userPassword ?? "";
|
|
28409
28413
|
const ownerPassword = options.ownerPassword ?? userPassword;
|
|
28410
28414
|
const revision = options.revision ?? 6;
|
|
@@ -28426,14 +28430,15 @@ function encryptCosDocument(doc, options = {}) {
|
|
|
28426
28430
|
const encryptObjNum = maxObjNum + 1;
|
|
28427
28431
|
const encryptedObjects = [];
|
|
28428
28432
|
for (const obj of doc.objects.values()) {
|
|
28429
|
-
|
|
28433
|
+
yield;
|
|
28434
|
+
const transformed = yield* transformNodeStringsAndStreamsSteps(
|
|
28430
28435
|
obj.value,
|
|
28431
28436
|
(plain) => encryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, plain)
|
|
28432
28437
|
);
|
|
28433
28438
|
encryptedObjects.push({ objectNumber: obj.objectNumber, generationNumber: obj.generationNumber, value: transformed });
|
|
28434
28439
|
}
|
|
28435
28440
|
encryptedObjects.push({ objectNumber: encryptObjNum, generationNumber: 0, value: encryptDict });
|
|
28436
|
-
return
|
|
28441
|
+
return yield* serializeCosDocumentSteps({
|
|
28437
28442
|
objects: encryptedObjects,
|
|
28438
28443
|
rootRef: doc.rootRef,
|
|
28439
28444
|
infoRef: doc.infoRef,
|
|
@@ -28483,17 +28488,19 @@ function decryptStream(doc, stream, transform) {
|
|
|
28483
28488
|
}
|
|
28484
28489
|
return { kind: "stream", dict, rawBytes: bytes };
|
|
28485
28490
|
}
|
|
28486
|
-
function
|
|
28491
|
+
function* decryptCosDocumentSteps(doc, state) {
|
|
28492
|
+
yield;
|
|
28487
28493
|
const encryptObjNum = doc.encryptRef?.objectNumber;
|
|
28488
28494
|
const handler = securityHandlers.get(state);
|
|
28489
28495
|
for (const [num, obj] of doc.objects.entries()) {
|
|
28496
|
+
yield;
|
|
28490
28497
|
if (num === encryptObjNum || handler?.plaintextObjects.has(num)) continue;
|
|
28491
28498
|
if (obj.value.kind === "stream") {
|
|
28492
28499
|
const type = doc.resolve(dictGet(obj.value.dict, "Type"));
|
|
28493
28500
|
if (type?.kind === "name" && (type.decoded === "XRef" || type.decoded === "Metadata" && !state.encryptMetadata)) continue;
|
|
28494
28501
|
}
|
|
28495
28502
|
const transform = handler?.factory.createCipherTransform(obj.objectNumber, obj.generationNumber);
|
|
28496
|
-
const decrypted =
|
|
28503
|
+
const decrypted = yield* transformNodeStringsAndStreamsSteps(
|
|
28497
28504
|
obj.value,
|
|
28498
28505
|
(cipher) => decryptPdfBuffer(state, obj.objectNumber, obj.generationNumber, cipher),
|
|
28499
28506
|
transform ? (stream) => decryptStream(doc, stream, transform) : void 0
|
|
@@ -28607,9 +28614,12 @@ var ParsedCosDocument = class {
|
|
|
28607
28614
|
return void 0;
|
|
28608
28615
|
}
|
|
28609
28616
|
};
|
|
28610
|
-
function
|
|
28617
|
+
function* parseNodeFromLexerSteps(lexer, bytes, maxDepth, repair = false) {
|
|
28618
|
+
yield;
|
|
28619
|
+
let work = 0;
|
|
28611
28620
|
const stack = [];
|
|
28612
28621
|
while (true) {
|
|
28622
|
+
if (++work % 16 === 0) yield;
|
|
28613
28623
|
const tok = lexer.nextToken();
|
|
28614
28624
|
const parent = stack.at(-1);
|
|
28615
28625
|
if (!tok) {
|
|
@@ -28805,7 +28815,8 @@ function parseHeaderVersion(bytes) {
|
|
|
28805
28815
|
}
|
|
28806
28816
|
return head.slice(idx + 5, idx + 8);
|
|
28807
28817
|
}
|
|
28808
|
-
function
|
|
28818
|
+
function* parseObjectAtOffsetSteps(bytes, offset, maxRecursionDepth, repair = false) {
|
|
28819
|
+
yield;
|
|
28809
28820
|
const lexer = new CosByteLexer(bytes, offset);
|
|
28810
28821
|
const objNumTok = lexer.nextToken();
|
|
28811
28822
|
const genNumTok = lexer.nextToken();
|
|
@@ -28813,7 +28824,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
|
|
|
28813
28824
|
if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
|
|
28814
28825
|
throw new PdfError("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
|
|
28815
28826
|
}
|
|
28816
|
-
const value =
|
|
28827
|
+
const value = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, repair);
|
|
28817
28828
|
if (!value) {
|
|
28818
28829
|
throw new PdfError("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
|
|
28819
28830
|
}
|
|
@@ -28824,7 +28835,9 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
|
|
|
28824
28835
|
span: { start: objNumTok.span.start, end: lexer.offset }
|
|
28825
28836
|
};
|
|
28826
28837
|
}
|
|
28827
|
-
function
|
|
28838
|
+
function* parseXrefRevisionAtSteps(bytes, xrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects) {
|
|
28839
|
+
yield;
|
|
28840
|
+
let work = 0;
|
|
28828
28841
|
if (xrefOffset < 0 || xrefOffset >= bytes.length) {
|
|
28829
28842
|
throw new PdfError("E_PARSE", `Invalid xref offset: ${xrefOffset}`);
|
|
28830
28843
|
}
|
|
@@ -28836,6 +28849,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28836
28849
|
if (firstTok.kind === "keyword" && firstTok.value === "xref") {
|
|
28837
28850
|
const entries2 = /* @__PURE__ */ new Map();
|
|
28838
28851
|
while (true) {
|
|
28852
|
+
if (++work % 16 === 0) yield;
|
|
28839
28853
|
const saved = lexer.offset;
|
|
28840
28854
|
const tok = lexer.nextToken();
|
|
28841
28855
|
if (!tok) {
|
|
@@ -28859,6 +28873,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28859
28873
|
}
|
|
28860
28874
|
if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
28861
28875
|
for (let i = 0; i < count; i++) {
|
|
28876
|
+
if (++work % 16 === 0) yield;
|
|
28862
28877
|
const offTok = lexer.nextToken();
|
|
28863
28878
|
const genTok = lexer.nextToken();
|
|
28864
28879
|
const flagTok = lexer.nextToken();
|
|
@@ -28884,7 +28899,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28884
28899
|
if (entries2.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
28885
28900
|
}
|
|
28886
28901
|
}
|
|
28887
|
-
const trailerNode =
|
|
28902
|
+
const trailerNode = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth);
|
|
28888
28903
|
if (!trailerNode || trailerNode.kind !== "dict") {
|
|
28889
28904
|
throw new PdfError("E_PARSE", "Missing trailer dictionary after xref table");
|
|
28890
28905
|
}
|
|
@@ -28896,7 +28911,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28896
28911
|
previousXrefOffset: prevNode2?.kind === "number" ? prevNode2.value : void 0
|
|
28897
28912
|
};
|
|
28898
28913
|
}
|
|
28899
|
-
const xrefObj =
|
|
28914
|
+
const xrefObj = yield* parseObjectAtOffsetSteps(bytes, xrefOffset, maxRecursionDepth);
|
|
28900
28915
|
if (xrefObj.value.kind !== "stream") {
|
|
28901
28916
|
throw new PdfError("E_PARSE", `Expected xref table or XRef stream at offset ${xrefOffset}`);
|
|
28902
28917
|
}
|
|
@@ -28917,6 +28932,7 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28917
28932
|
if (indexArray) {
|
|
28918
28933
|
if (indexArray.kind !== "array" || indexArray.items.length % 2 !== 0) throw new PdfError("E_PARSE", "Invalid XRef range fields");
|
|
28919
28934
|
for (let i = 0; i < indexArray.items.length; i += 2) {
|
|
28935
|
+
if (++work % 16 === 0) yield;
|
|
28920
28936
|
const first = indexArray.items[i];
|
|
28921
28937
|
const count = indexArray.items[i + 1];
|
|
28922
28938
|
if (first?.kind !== "number" || count?.kind !== "number" || !Number.isSafeInteger(first.value) || first.value < 0 || !Number.isSafeInteger(count.value) || count.value < 0 || !Number.isSafeInteger(first.value + count.value)) {
|
|
@@ -28939,9 +28955,11 @@ function parseXrefRevisionAt(bytes, xrefOffset, maxDecompressedBytes, maxRecursi
|
|
|
28939
28955
|
return v;
|
|
28940
28956
|
};
|
|
28941
28957
|
for (const [startObj, count] of subsections) {
|
|
28958
|
+
if (++work % 16 === 0) yield;
|
|
28942
28959
|
if (count > (decoded.length - pos) / stride) throw new PdfError("E_PARSE", "Truncated XRef stream");
|
|
28943
28960
|
if (count > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
28944
28961
|
for (let i = 0; i < count; i++) {
|
|
28962
|
+
if (++work % 16 === 0) yield;
|
|
28945
28963
|
const objNum = startObj + i;
|
|
28946
28964
|
const field0 = w0 > 0 ? readInt(w0) : 1;
|
|
28947
28965
|
const field1 = readInt(w1);
|
|
@@ -28987,12 +29005,16 @@ function isAsciiWhitespace(ch3) {
|
|
|
28987
29005
|
function isAsciiDigit(ch3) {
|
|
28988
29006
|
return ch3 >= 48 && ch3 <= 57;
|
|
28989
29007
|
}
|
|
28990
|
-
function
|
|
29008
|
+
function* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth) {
|
|
29009
|
+
yield;
|
|
29010
|
+
let work = 0;
|
|
28991
29011
|
const objects = /* @__PURE__ */ new Map();
|
|
28992
29012
|
const trailers = [];
|
|
28993
29013
|
let pos = 0;
|
|
28994
29014
|
while (pos < bytes.length) {
|
|
29015
|
+
if (++work % 16 === 0) yield;
|
|
28995
29016
|
while (pos < bytes.length && !isAsciiDigit(bytes[pos])) {
|
|
29017
|
+
if (++work % 16 === 0) yield;
|
|
28996
29018
|
if (bytes[pos] === 37) {
|
|
28997
29019
|
while (pos < bytes.length && bytes[pos] !== 10 && bytes[pos] !== 13) pos++;
|
|
28998
29020
|
continue;
|
|
@@ -29002,7 +29024,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
29002
29024
|
try {
|
|
29003
29025
|
const token = lexer.nextToken();
|
|
29004
29026
|
if (token?.kind === "keyword" && token.value === "trailer") {
|
|
29005
|
-
const trailer =
|
|
29027
|
+
const trailer = yield* parseNodeFromLexerSteps(lexer, bytes, maxRecursionDepth, true);
|
|
29006
29028
|
if (trailer?.kind === "dict") trailers.push(trailer);
|
|
29007
29029
|
pos = lexer.offset;
|
|
29008
29030
|
continue;
|
|
@@ -29035,7 +29057,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
29035
29057
|
bytes[pos + 3] === 40)) {
|
|
29036
29058
|
pos += 3;
|
|
29037
29059
|
try {
|
|
29038
|
-
const parsed =
|
|
29060
|
+
const parsed = yield* parseObjectAtOffsetSteps(bytes, headerStart, maxRecursionDepth, true);
|
|
29039
29061
|
objects.set(parsed.objectNumber, parsed);
|
|
29040
29062
|
if (parsed.value.kind === "stream") {
|
|
29041
29063
|
const type = dictGet(parsed.value.dict, "Type");
|
|
@@ -29052,13 +29074,17 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
|
|
|
29052
29074
|
}
|
|
29053
29075
|
return { objects, trailers };
|
|
29054
29076
|
}
|
|
29055
|
-
function
|
|
29077
|
+
function* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth) {
|
|
29078
|
+
yield;
|
|
29079
|
+
let work = 0;
|
|
29056
29080
|
for (const obj of [...objects.values()]) {
|
|
29081
|
+
if (++work % 16 === 0) yield;
|
|
29057
29082
|
if (obj.value.kind === "stream") {
|
|
29058
29083
|
const t = dictGet(obj.value.dict, "Type");
|
|
29059
29084
|
if (t?.kind === "name" && t.decoded === "ObjStm") {
|
|
29060
29085
|
try {
|
|
29061
|
-
for (const [unpackedNum, unpackedVal] of
|
|
29086
|
+
for (const [unpackedNum, unpackedVal] of (yield* unpackObjectStreamSteps(obj.value, maxDecompressedBytes, maxRecursionDepth, true)).entries()) {
|
|
29087
|
+
if (++work % 16 === 0) yield;
|
|
29062
29088
|
if (!objects.has(unpackedNum)) {
|
|
29063
29089
|
objects.set(unpackedNum, {
|
|
29064
29090
|
objectNumber: unpackedNum,
|
|
@@ -29094,7 +29120,9 @@ function recoveredReferences(objects) {
|
|
|
29094
29120
|
}
|
|
29095
29121
|
return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
|
|
29096
29122
|
}
|
|
29097
|
-
function
|
|
29123
|
+
function* unpackObjectStreamSteps(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
|
|
29124
|
+
yield;
|
|
29125
|
+
let work = 0;
|
|
29098
29126
|
const nNode = dictGet(streamObj.dict, "N");
|
|
29099
29127
|
const firstNode = dictGet(streamObj.dict, "First");
|
|
29100
29128
|
if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
|
|
@@ -29104,6 +29132,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
29104
29132
|
const headerLexer = new CosByteLexer(decoded, 0);
|
|
29105
29133
|
const pairs = [];
|
|
29106
29134
|
for (let i = 0; i < nNode.value; i++) {
|
|
29135
|
+
if (++work % 16 === 0) yield;
|
|
29107
29136
|
const numTok = headerLexer.nextToken();
|
|
29108
29137
|
const offTok = headerLexer.nextToken();
|
|
29109
29138
|
if (numTok?.kind === "number" && offTok?.kind === "number") {
|
|
@@ -29112,9 +29141,10 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
29112
29141
|
}
|
|
29113
29142
|
const result = /* @__PURE__ */ new Map();
|
|
29114
29143
|
for (const pair of pairs) {
|
|
29144
|
+
if (++work % 16 === 0) yield;
|
|
29115
29145
|
try {
|
|
29116
29146
|
const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
|
|
29117
|
-
const node =
|
|
29147
|
+
const node = yield* parseNodeFromLexerSteps(valLexer, decoded, maxRecursionDepth, repair);
|
|
29118
29148
|
if (node) {
|
|
29119
29149
|
result.set(pair.objectNumber, node);
|
|
29120
29150
|
}
|
|
@@ -29124,7 +29154,9 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth,
|
|
|
29124
29154
|
}
|
|
29125
29155
|
return result;
|
|
29126
29156
|
}
|
|
29127
|
-
function
|
|
29157
|
+
function* parseCosDocumentSteps(bytes, options = {}) {
|
|
29158
|
+
yield;
|
|
29159
|
+
let work = 0;
|
|
29128
29160
|
const version = parseHeaderVersion(bytes);
|
|
29129
29161
|
const recovery = options.recovery ?? "strict";
|
|
29130
29162
|
const maxObjects = options.maxObjects ?? Infinity;
|
|
@@ -29159,10 +29191,12 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29159
29191
|
let currentXrefOffset = offsetTok.value;
|
|
29160
29192
|
const visitedOffsets = /* @__PURE__ */ new Set();
|
|
29161
29193
|
while (currentXrefOffset !== void 0 && !visitedOffsets.has(currentXrefOffset)) {
|
|
29194
|
+
if (++work % 16 === 0) yield;
|
|
29162
29195
|
visitedOffsets.add(currentXrefOffset);
|
|
29163
|
-
const rev =
|
|
29196
|
+
const rev = yield* parseXrefRevisionAtSteps(bytes, currentXrefOffset, maxDecompressedBytes, maxRecursionDepth, maxObjects);
|
|
29164
29197
|
revisions.push(rev);
|
|
29165
29198
|
for (const [num, entry] of rev.entries.entries()) {
|
|
29199
|
+
if (++work % 16 === 0) yield;
|
|
29166
29200
|
if (!mergedXref.has(num)) {
|
|
29167
29201
|
mergedXref.set(num, entry);
|
|
29168
29202
|
if (mergedXref.size > maxObjects + 1) throw new PdfError("E_LIMIT", "PDF object count limit exceeded while reading xref entries");
|
|
@@ -29195,8 +29229,9 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29195
29229
|
if (!useRepair && rootRef) {
|
|
29196
29230
|
try {
|
|
29197
29231
|
for (const [objNum, entry] of mergedXref.entries()) {
|
|
29232
|
+
if (++work % 16 === 0) yield;
|
|
29198
29233
|
if (entry.type !== "uncompressed") continue;
|
|
29199
|
-
const parsed =
|
|
29234
|
+
const parsed = yield* parseObjectAtOffsetSteps(bytes, entry.offset ?? 0, maxRecursionDepth, recovery === "repair");
|
|
29200
29235
|
if (parsed.objectNumber !== objNum || parsed.generationNumber !== (entry.generationNumber ?? 0)) {
|
|
29201
29236
|
throw new PdfError("E_PARSE", `Bad uncompressed XRef entry for object ${objNum}`);
|
|
29202
29237
|
}
|
|
@@ -29214,7 +29249,7 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29214
29249
|
throw new PdfError("E_PARSE", "PDF trailer missing /Root reference");
|
|
29215
29250
|
}
|
|
29216
29251
|
useRepair = true;
|
|
29217
|
-
const scanned =
|
|
29252
|
+
const scanned = yield* repairScanCosDocumentSteps(bytes, maxObjects, maxRecursionDepth);
|
|
29218
29253
|
objects = scanned.objects;
|
|
29219
29254
|
revisions.length = 0;
|
|
29220
29255
|
mergedXref.clear();
|
|
@@ -29249,7 +29284,7 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29249
29284
|
encryptNode = encrypt?.kind === "ref" || encrypt?.kind === "dict" ? encrypt : void 0;
|
|
29250
29285
|
encryptRef = encrypt?.kind === "ref" ? encrypt : void 0;
|
|
29251
29286
|
idArray = id?.kind === "array" ? id : void 0;
|
|
29252
|
-
if (!rootRef && !encryptNode)
|
|
29287
|
+
if (!rootRef && !encryptNode) yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
|
|
29253
29288
|
const fallback = recoveredReferences(objects);
|
|
29254
29289
|
rootRef ??= fallback.rootRef;
|
|
29255
29290
|
infoRef ??= fallback.infoRef;
|
|
@@ -29284,20 +29319,21 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29284
29319
|
maxRecursionDepth
|
|
29285
29320
|
});
|
|
29286
29321
|
doc.encryption = encState;
|
|
29287
|
-
|
|
29322
|
+
yield* decryptCosDocumentSteps(doc, encState);
|
|
29288
29323
|
}
|
|
29289
29324
|
if (useRepair) {
|
|
29290
|
-
|
|
29325
|
+
yield* unpackRecoveredObjectsSteps(objects, maxObjects, maxDecompressedBytes, maxRecursionDepth);
|
|
29291
29326
|
doc.infoRef ??= recoveredReferences(objects).infoRef;
|
|
29292
29327
|
}
|
|
29293
29328
|
const objStmCache = /* @__PURE__ */ new Map();
|
|
29294
29329
|
for (const [objNum, entry] of mergedXref.entries()) {
|
|
29330
|
+
if (++work % 16 === 0) yield;
|
|
29295
29331
|
if (entry.type === "compressed" && entry.objectStreamNumber !== void 0) {
|
|
29296
29332
|
let unpacked = objStmCache.get(entry.objectStreamNumber);
|
|
29297
29333
|
if (!unpacked) {
|
|
29298
29334
|
const stmObj = objects.get(entry.objectStreamNumber)?.value;
|
|
29299
29335
|
if (stmObj?.kind === "stream") {
|
|
29300
|
-
unpacked =
|
|
29336
|
+
unpacked = yield* unpackObjectStreamSteps(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
|
|
29301
29337
|
objStmCache.set(entry.objectStreamNumber, unpacked);
|
|
29302
29338
|
}
|
|
29303
29339
|
}
|
|
@@ -29314,6 +29350,9 @@ function parseCosDocument(bytes, options = {}) {
|
|
|
29314
29350
|
}
|
|
29315
29351
|
return doc;
|
|
29316
29352
|
}
|
|
29353
|
+
function parseCosDocument(bytes, options = {}) {
|
|
29354
|
+
return drainWork(parseCosDocumentSteps(bytes, options));
|
|
29355
|
+
}
|
|
29317
29356
|
var WIN_ANSI_HIGH_BYTES = {
|
|
29318
29357
|
128: 8364,
|
|
29319
29358
|
130: 8218,
|
|
@@ -40344,7 +40383,8 @@ function resolveInheritedFieldEntry(doc, dict, key) {
|
|
|
40344
40383
|
}
|
|
40345
40384
|
return void 0;
|
|
40346
40385
|
}
|
|
40347
|
-
function
|
|
40386
|
+
function* collectFieldDictsSteps(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen, yieldState = { work: 0 }) {
|
|
40387
|
+
if (++yieldState.work % 256 === 0) yield;
|
|
40348
40388
|
const dict = doc.resolveDict(node);
|
|
40349
40389
|
if (!dict) return out;
|
|
40350
40390
|
const tNode = doc.resolve(dictGet(dict, "T"));
|
|
@@ -40377,7 +40417,8 @@ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", pare
|
|
|
40377
40417
|
return out;
|
|
40378
40418
|
}
|
|
40379
40419
|
for (const kid of kidsArr.items) {
|
|
40380
|
-
|
|
40420
|
+
if (++yieldState.work % 16 === 0) yield;
|
|
40421
|
+
yield* collectFieldDictsSteps(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen, yieldState);
|
|
40381
40422
|
}
|
|
40382
40423
|
} else if (fullName) {
|
|
40383
40424
|
out.push({
|
|
@@ -41382,6 +41423,9 @@ q ${sx} 0 0 ${sy} ${tx} ${ty} cm /${appearanceName} Do Q
|
|
|
41382
41423
|
dictSet(acroForm, "NeedAppearances", cosBool(false));
|
|
41383
41424
|
}
|
|
41384
41425
|
}
|
|
41426
|
+
function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
|
|
41427
|
+
drainWork(collectFieldDictsSteps(doc, node, prefix, out, parentFt, parentFf, parentQ, parentMaxLen));
|
|
41428
|
+
}
|
|
41385
41429
|
var PdfPage = class {
|
|
41386
41430
|
cosDoc;
|
|
41387
41431
|
pageRef;
|
|
@@ -43835,14 +43879,18 @@ var PdfDocument = class _PdfDocument {
|
|
|
43835
43879
|
});
|
|
43836
43880
|
return new _PdfDocument(parseCosDocument(rawBytes));
|
|
43837
43881
|
}
|
|
43838
|
-
static
|
|
43882
|
+
static *loadSteps(bytes, options) {
|
|
43883
|
+
yield;
|
|
43839
43884
|
return new _PdfDocument(
|
|
43840
|
-
|
|
43885
|
+
yield* parseCosDocumentSteps(bytes, {
|
|
43841
43886
|
...options,
|
|
43842
43887
|
recovery: options?.recovery ?? "repair"
|
|
43843
43888
|
})
|
|
43844
43889
|
);
|
|
43845
43890
|
}
|
|
43891
|
+
static load(bytes, options) {
|
|
43892
|
+
return drainWork(_PdfDocument.loadSteps(bytes, options));
|
|
43893
|
+
}
|
|
43846
43894
|
rebuildPagesList() {
|
|
43847
43895
|
const catalog = this.cos.resolveDict(this.cos.rootRef);
|
|
43848
43896
|
const pagesNode = catalog ? dictGet(catalog, "Pages") : void 0;
|
|
@@ -43924,20 +43972,30 @@ var PdfDocument = class _PdfDocument {
|
|
|
43924
43972
|
this.pages.splice(index, 1);
|
|
43925
43973
|
this.syncPageTree();
|
|
43926
43974
|
}
|
|
43927
|
-
|
|
43975
|
+
*copyPagesFromSteps(sourceDoc, indices) {
|
|
43976
|
+
function* cloneItems(items) {
|
|
43977
|
+
const result = [];
|
|
43978
|
+
for (const item of items) result.push(yield* cloneNode(item));
|
|
43979
|
+
return result;
|
|
43980
|
+
}
|
|
43981
|
+
yield;
|
|
43982
|
+
let work = 0;
|
|
43928
43983
|
const memo = /* @__PURE__ */ new Map();
|
|
43929
43984
|
const sourcePageObjNums = /* @__PURE__ */ new Set();
|
|
43930
43985
|
for (let i = 0; i < sourceDoc.getPageCount(); i++) {
|
|
43986
|
+
if (++work % 16 === 0) yield;
|
|
43931
43987
|
sourcePageObjNums.add(sourceDoc.getPage(i).ref.objectNumber);
|
|
43932
43988
|
}
|
|
43933
43989
|
const targetPageRefs = [];
|
|
43934
43990
|
for (const idx of indices) {
|
|
43991
|
+
if (++work % 16 === 0) yield;
|
|
43935
43992
|
const srcPage = sourceDoc.getPage(idx);
|
|
43936
43993
|
const pageRef = this.cos.allocateObject({ kind: "null" });
|
|
43937
43994
|
targetPageRefs.push(pageRef);
|
|
43938
43995
|
memo.set(srcPage.ref.objectNumber, pageRef);
|
|
43939
43996
|
}
|
|
43940
|
-
const cloneNode = (node)
|
|
43997
|
+
const cloneNode = function* (node) {
|
|
43998
|
+
if (++work % 16 === 0) yield;
|
|
43941
43999
|
if (node.kind === "ref") {
|
|
43942
44000
|
const existing = memo.get(node.objectNumber);
|
|
43943
44001
|
if (existing) return existing;
|
|
@@ -43948,12 +44006,12 @@ var PdfDocument = class _PdfDocument {
|
|
|
43948
44006
|
if (!target) return cosRef(0);
|
|
43949
44007
|
const placeholderRef = this.cos.allocateObject({ kind: "null" });
|
|
43950
44008
|
memo.set(node.objectNumber, placeholderRef);
|
|
43951
|
-
const clonedTarget = cloneNode(target);
|
|
44009
|
+
const clonedTarget = yield* cloneNode(target);
|
|
43952
44010
|
this.cos.setObject(placeholderRef.objectNumber, clonedTarget, 0);
|
|
43953
44011
|
return placeholderRef;
|
|
43954
44012
|
}
|
|
43955
44013
|
if (node.kind === "array") {
|
|
43956
|
-
return cosArray(node.items
|
|
44014
|
+
return cosArray(yield* cloneItems(node.items));
|
|
43957
44015
|
}
|
|
43958
44016
|
if (node.kind === "dict") {
|
|
43959
44017
|
const typeEntry = dictGet(node, "Type");
|
|
@@ -43963,13 +44021,13 @@ var PdfDocument = class _PdfDocument {
|
|
|
43963
44021
|
if (isPageTreeNode && entry.key.decoded === "Parent") continue;
|
|
43964
44022
|
newEntries.push({
|
|
43965
44023
|
key: { ...entry.key },
|
|
43966
|
-
value: cloneNode(entry.value)
|
|
44024
|
+
value: yield* cloneNode(entry.value)
|
|
43967
44025
|
});
|
|
43968
44026
|
}
|
|
43969
44027
|
return { kind: "dict", entries: newEntries };
|
|
43970
44028
|
}
|
|
43971
44029
|
if (node.kind === "stream") {
|
|
43972
|
-
const clonedDict = cloneNode(node.dict);
|
|
44030
|
+
const clonedDict = yield* cloneNode(node.dict);
|
|
43973
44031
|
return {
|
|
43974
44032
|
kind: "stream",
|
|
43975
44033
|
dict: clonedDict,
|
|
@@ -43978,11 +44036,12 @@ var PdfDocument = class _PdfDocument {
|
|
|
43978
44036
|
};
|
|
43979
44037
|
}
|
|
43980
44038
|
return node;
|
|
43981
|
-
};
|
|
44039
|
+
}.bind(this);
|
|
43982
44040
|
const copiedPages = [];
|
|
43983
44041
|
for (const [position, idx] of indices.entries()) {
|
|
44042
|
+
if (++work % 16 === 0) yield;
|
|
43984
44043
|
const srcPage = sourceDoc.getPage(idx);
|
|
43985
|
-
const clonedPageDict = cloneNode(srcPage.pageDict);
|
|
44044
|
+
const clonedPageDict = yield* cloneNode(srcPage.pageDict);
|
|
43986
44045
|
const size = srcPage.getSize();
|
|
43987
44046
|
if (!dictGet(clonedPageDict, "MediaBox")) {
|
|
43988
44047
|
dictSet(
|
|
@@ -43992,13 +44051,14 @@ var PdfDocument = class _PdfDocument {
|
|
|
43992
44051
|
);
|
|
43993
44052
|
}
|
|
43994
44053
|
if (!dictGet(clonedPageDict, "Resources")) {
|
|
43995
|
-
dictSet(clonedPageDict, "Resources", cloneNode(srcPage.getResourcesDict()));
|
|
44054
|
+
dictSet(clonedPageDict, "Resources", yield* cloneNode(srcPage.getResourcesDict()));
|
|
43996
44055
|
}
|
|
43997
44056
|
if (!dictGet(clonedPageDict, "Rotate") && srcPage.getRotation() !== 0) {
|
|
43998
44057
|
dictSet(clonedPageDict, "Rotate", cosNumber(srcPage.getRotation()));
|
|
43999
44058
|
}
|
|
44000
44059
|
const inheritedBoxKeys = ["CropBox", "BleedBox", "TrimBox", "ArtBox"];
|
|
44001
44060
|
for (const boxKey of inheritedBoxKeys) {
|
|
44061
|
+
if (++work % 16 === 0) yield;
|
|
44002
44062
|
if (!dictGet(clonedPageDict, boxKey)) {
|
|
44003
44063
|
const boxVal = boxKey === "CropBox" ? srcPage.getCropBox() : boxKey === "BleedBox" ? srcPage.getBleedBox() : boxKey === "TrimBox" ? srcPage.getTrimBox() : srcPage.getArtBox();
|
|
44004
44064
|
if (boxVal[0] !== 0 || boxVal[1] !== 0 || boxVal[2] !== size.width || boxVal[3] !== size.height) {
|
|
@@ -44040,8 +44100,9 @@ var PdfDocument = class _PdfDocument {
|
|
|
44040
44100
|
};
|
|
44041
44101
|
const clonedRootFieldRefs = [];
|
|
44042
44102
|
for (const item of srcFieldsArr.items) {
|
|
44103
|
+
if (++work % 16 === 0) yield;
|
|
44043
44104
|
if (!hasClonedDescendant(item)) continue;
|
|
44044
|
-
const cloned = cloneNode(item);
|
|
44105
|
+
const cloned = yield* cloneNode(item);
|
|
44045
44106
|
if (cloned.kind === "ref") {
|
|
44046
44107
|
const clonedDict = this.cos.resolveDict(cloned);
|
|
44047
44108
|
const kidsArr = clonedDict ? this.cos.resolveArray(dictGet(clonedDict, "Kids")) : void 0;
|
|
@@ -44075,6 +44136,7 @@ var PdfDocument = class _PdfDocument {
|
|
|
44075
44136
|
dstFields.items.filter((x) => x.kind === "ref").map((x) => x.objectNumber)
|
|
44076
44137
|
);
|
|
44077
44138
|
for (const fRef of clonedRootFieldRefs) {
|
|
44139
|
+
if (++work % 16 === 0) yield;
|
|
44078
44140
|
if (!existingNums.has(fRef.objectNumber)) {
|
|
44079
44141
|
dstFields.items.push(fRef);
|
|
44080
44142
|
existingNums.add(fRef.objectNumber);
|
|
@@ -44082,11 +44144,11 @@ var PdfDocument = class _PdfDocument {
|
|
|
44082
44144
|
}
|
|
44083
44145
|
const srcDr = dictGet(srcAcroForm, "DR");
|
|
44084
44146
|
if (srcDr && !dictGet(dstAcroForm, "DR")) {
|
|
44085
|
-
dictSet(dstAcroForm, "DR", cloneNode(srcDr));
|
|
44147
|
+
dictSet(dstAcroForm, "DR", yield* cloneNode(srcDr));
|
|
44086
44148
|
}
|
|
44087
44149
|
const srcDa = dictGet(srcAcroForm, "DA");
|
|
44088
44150
|
if (srcDa && !dictGet(dstAcroForm, "DA")) {
|
|
44089
|
-
dictSet(dstAcroForm, "DA", cloneNode(srcDa));
|
|
44151
|
+
dictSet(dstAcroForm, "DA", yield* cloneNode(srcDa));
|
|
44090
44152
|
}
|
|
44091
44153
|
}
|
|
44092
44154
|
}
|
|
@@ -44095,12 +44157,15 @@ var PdfDocument = class _PdfDocument {
|
|
|
44095
44157
|
if (srcOcProps) {
|
|
44096
44158
|
const dstCatalog = this.cos.resolveDict(this.cos.rootRef);
|
|
44097
44159
|
if (dstCatalog && !dictGet(dstCatalog, "OCProperties")) {
|
|
44098
|
-
dictSet(dstCatalog, "OCProperties", cloneNode(srcOcProps));
|
|
44160
|
+
dictSet(dstCatalog, "OCProperties", yield* cloneNode(srcOcProps));
|
|
44099
44161
|
}
|
|
44100
44162
|
}
|
|
44101
44163
|
this.syncPageTree();
|
|
44102
44164
|
return copiedPages;
|
|
44103
44165
|
}
|
|
44166
|
+
copyPagesFrom(sourceDoc, indices) {
|
|
44167
|
+
return drainWork(this.copyPagesFromSteps(sourceDoc, indices));
|
|
44168
|
+
}
|
|
44104
44169
|
embedStandardFont(fontName) {
|
|
44105
44170
|
return createStandardFontHandle(fontName);
|
|
44106
44171
|
}
|
|
@@ -44300,14 +44365,15 @@ var PdfDocument = class _PdfDocument {
|
|
|
44300
44365
|
});
|
|
44301
44366
|
return buildSemanticAstFromPages(extractedPages, tablesByPage, displayLists);
|
|
44302
44367
|
}
|
|
44303
|
-
|
|
44368
|
+
*saveSteps(options = {}) {
|
|
44369
|
+
yield;
|
|
44304
44370
|
this.syncPageTree();
|
|
44305
44371
|
if (this.cos.requiresFullRewrite) {
|
|
44306
44372
|
pruneUnusedXObjects(this.cos, this.pages);
|
|
44307
44373
|
discardUnreachableObjects(this.cos);
|
|
44308
44374
|
}
|
|
44309
44375
|
if (options.encrypt) {
|
|
44310
|
-
return
|
|
44376
|
+
return yield* encryptCosDocumentSteps(this.cos, options.encrypt);
|
|
44311
44377
|
}
|
|
44312
44378
|
const allObjects = [...this.cos.objects.values()].sort(
|
|
44313
44379
|
(a, b) => a.objectNumber - b.objectNumber
|
|
@@ -44315,7 +44381,7 @@ var PdfDocument = class _PdfDocument {
|
|
|
44315
44381
|
if (options.incremental && !this.cos.requiresFullRewrite && this.cos.bytes.length > 0) {
|
|
44316
44382
|
return appendIncrementalRevision(this.cos.bytes, this.cos, allObjects);
|
|
44317
44383
|
}
|
|
44318
|
-
return
|
|
44384
|
+
return yield* serializeCosDocumentSteps({
|
|
44319
44385
|
objects: allObjects,
|
|
44320
44386
|
rootRef: this.cos.rootRef,
|
|
44321
44387
|
infoRef: this.cos.infoRef,
|
|
@@ -44326,6 +44392,9 @@ var PdfDocument = class _PdfDocument {
|
|
|
44326
44392
|
linearize: options.linearize
|
|
44327
44393
|
});
|
|
44328
44394
|
}
|
|
44395
|
+
save(options = {}) {
|
|
44396
|
+
return drainWork(this.saveSteps(options));
|
|
44397
|
+
}
|
|
44329
44398
|
};
|
|
44330
44399
|
function resolveDestinationPageIndex(doc, destOrActionNode) {
|
|
44331
44400
|
const cos = doc.cos;
|
|
@@ -45660,10 +45729,8 @@ function normalizeQuarterTurn(degrees) {
|
|
|
45660
45729
|
if (mod === 90 || mod === 180 || mod === 270) return mod;
|
|
45661
45730
|
return 0;
|
|
45662
45731
|
}
|
|
45663
|
-
|
|
45664
|
-
|
|
45665
|
-
}
|
|
45666
|
-
function runPdftkCliSync(argv, files) {
|
|
45732
|
+
function* runPdftkCliSteps(argv, files, signal) {
|
|
45733
|
+
let cooperativeWork = 63;
|
|
45667
45734
|
if (argv.length === 0 || argv.includes("--help") || argv.includes("-h")) {
|
|
45668
45735
|
return {
|
|
45669
45736
|
exitCode: 0,
|
|
@@ -45677,13 +45744,20 @@ function runPdftkCliSync(argv, files) {
|
|
|
45677
45744
|
const inputPasswords = /* @__PURE__ */ new Map();
|
|
45678
45745
|
let defaultInputPassword = "";
|
|
45679
45746
|
for (let p = 0; p < argv.length; p++) {
|
|
45747
|
+
if (++cooperativeWork % 64 === 0)
|
|
45748
|
+
yield;
|
|
45680
45749
|
if (argv[p]?.toLowerCase() === "input_pw") {
|
|
45681
45750
|
for (let q = p + 1; q < argv.length; q++) {
|
|
45751
|
+
if (++cooperativeWork % 64 === 0)
|
|
45752
|
+
yield;
|
|
45682
45753
|
const tok = argv[q];
|
|
45683
|
-
if (PDFTK_OPERATIONS.has(tok.toLowerCase()))
|
|
45754
|
+
if (PDFTK_OPERATIONS.has(tok.toLowerCase()))
|
|
45755
|
+
break;
|
|
45684
45756
|
const eq = tok.indexOf("=");
|
|
45685
|
-
if (eq > 0)
|
|
45686
|
-
|
|
45757
|
+
if (eq > 0)
|
|
45758
|
+
inputPasswords.set(tok.slice(0, eq), tok.slice(eq + 1));
|
|
45759
|
+
else
|
|
45760
|
+
defaultInputPassword = tok;
|
|
45687
45761
|
}
|
|
45688
45762
|
}
|
|
45689
45763
|
}
|
|
@@ -45692,8 +45766,11 @@ function runPdftkCliSync(argv, files) {
|
|
|
45692
45766
|
let idx = 0;
|
|
45693
45767
|
let autoHandleCharCode = 65;
|
|
45694
45768
|
while (idx < argv.length) {
|
|
45769
|
+
if (++cooperativeWork % 64 === 0)
|
|
45770
|
+
yield;
|
|
45695
45771
|
const token = argv[idx];
|
|
45696
|
-
if (PDFTK_OPERATIONS.has(token.toLowerCase()) || token.toLowerCase() === "input_pw")
|
|
45772
|
+
if (PDFTK_OPERATIONS.has(token.toLowerCase()) || token.toLowerCase() === "input_pw")
|
|
45773
|
+
break;
|
|
45697
45774
|
idx++;
|
|
45698
45775
|
let handleName = "";
|
|
45699
45776
|
let filePath = token;
|
|
@@ -45718,15 +45795,20 @@ function runPdftkCliSync(argv, files) {
|
|
|
45718
45795
|
` };
|
|
45719
45796
|
}
|
|
45720
45797
|
handles.set(handleName, doc);
|
|
45721
|
-
if (!handles.has(""))
|
|
45798
|
+
if (!handles.has(""))
|
|
45799
|
+
handles.set("", doc);
|
|
45722
45800
|
orderedDocs.push({ handle: handleName, doc });
|
|
45723
45801
|
}
|
|
45724
45802
|
if (orderedDocs.length === 0) {
|
|
45725
45803
|
return { exitCode: 1, stdout: "", stderr: "Error: No input PDF files specified.\n" };
|
|
45726
45804
|
}
|
|
45727
45805
|
while (idx < argv.length && argv[idx]?.toLowerCase() === "input_pw") {
|
|
45806
|
+
if (++cooperativeWork % 64 === 0)
|
|
45807
|
+
yield;
|
|
45728
45808
|
idx++;
|
|
45729
45809
|
while (idx < argv.length && !PDFTK_OPERATIONS.has(argv[idx].toLowerCase())) {
|
|
45810
|
+
if (++cooperativeWork % 64 === 0)
|
|
45811
|
+
yield;
|
|
45730
45812
|
idx++;
|
|
45731
45813
|
}
|
|
45732
45814
|
}
|
|
@@ -45763,6 +45845,8 @@ function runPdftkCliSync(argv, files) {
|
|
|
45763
45845
|
"allfeatures"
|
|
45764
45846
|
]);
|
|
45765
45847
|
while (idx < argv.length) {
|
|
45848
|
+
if (++cooperativeWork % 64 === 0)
|
|
45849
|
+
yield;
|
|
45766
45850
|
const tok = argv[idx++];
|
|
45767
45851
|
const lower = tok.toLowerCase();
|
|
45768
45852
|
if (lower === "output") {
|
|
@@ -45777,6 +45861,8 @@ function runPdftkCliSync(argv, files) {
|
|
|
45777
45861
|
ownerPassword = argv[idx++];
|
|
45778
45862
|
} else if (lower === "allow") {
|
|
45779
45863
|
while (idx < argv.length && ALLOW_KEYWORDS.has(argv[idx].toLowerCase())) {
|
|
45864
|
+
if (++cooperativeWork % 64 === 0)
|
|
45865
|
+
yield;
|
|
45780
45866
|
allowPermissions.add(argv[idx++].toLowerCase());
|
|
45781
45867
|
}
|
|
45782
45868
|
} else if (lower === "keep_first_id") {
|
|
@@ -45825,6 +45911,7 @@ function runPdftkCliSync(argv, files) {
|
|
|
45825
45911
|
if (operation === "burst") {
|
|
45826
45912
|
const pattern = outputTarget ?? "pg_%04d.pdf";
|
|
45827
45913
|
for (let p = 1; p <= primaryDoc.pageCount; p++) {
|
|
45914
|
+
yield;
|
|
45828
45915
|
const singleDoc = PdfDocument.create();
|
|
45829
45916
|
copyPrimaryMetadata(primaryDoc, singleDoc);
|
|
45830
45917
|
singleDoc.copyPagesFrom(primaryDoc, [p - 1]);
|
|
@@ -45833,7 +45920,10 @@ function runPdftkCliSync(argv, files) {
|
|
|
45833
45920
|
}
|
|
45834
45921
|
if (uncompressStreams || compressStreams) {
|
|
45835
45922
|
for (const obj of singleDoc.cos.objects.values()) {
|
|
45836
|
-
if (
|
|
45923
|
+
if (++cooperativeWork % 64 === 0)
|
|
45924
|
+
yield;
|
|
45925
|
+
if (obj.value.kind !== "stream")
|
|
45926
|
+
continue;
|
|
45837
45927
|
const raw = singleDoc.cos.decodeStream(obj.value);
|
|
45838
45928
|
dictDelete(obj.value.dict, "Filter");
|
|
45839
45929
|
dictDelete(obj.value.dict, "DecodeParms");
|
|
@@ -45879,6 +45969,8 @@ function runPdftkCliSync(argv, files) {
|
|
|
45879
45969
|
const filesToAttach = [];
|
|
45880
45970
|
let toPageSpec;
|
|
45881
45971
|
for (let k = 0; k < opArgs.length; k++) {
|
|
45972
|
+
if (++cooperativeWork % 64 === 0)
|
|
45973
|
+
yield;
|
|
45882
45974
|
if (opArgs[k]?.toLowerCase() === "to_page") {
|
|
45883
45975
|
toPageSpec = opArgs[++k];
|
|
45884
45976
|
continue;
|
|
@@ -45895,6 +45987,8 @@ function runPdftkCliSync(argv, files) {
|
|
|
45895
45987
|
}
|
|
45896
45988
|
const fieldValues = parseFormDataBytes(dataBytes);
|
|
45897
45989
|
for (const [k, v] of fieldValues.entries()) {
|
|
45990
|
+
if (++cooperativeWork % 64 === 0)
|
|
45991
|
+
yield;
|
|
45898
45992
|
setDocumentFormField(resultDoc.cos, k, v);
|
|
45899
45993
|
}
|
|
45900
45994
|
if (shouldFlatten) {
|
|
@@ -45908,7 +46002,10 @@ function runPdftkCliSync(argv, files) {
|
|
|
45908
46002
|
const selections = [];
|
|
45909
46003
|
if (opArgs.length === 0) {
|
|
45910
46004
|
for (const item of orderedDocs) {
|
|
46005
|
+
if (++cooperativeWork % 64 === 0)
|
|
46006
|
+
yield;
|
|
45911
46007
|
for (let p = 1; p <= item.doc.pageCount; p++) {
|
|
46008
|
+
yield;
|
|
45912
46009
|
selections.push({ handle: item.handle, pageNumber: p });
|
|
45913
46010
|
}
|
|
45914
46011
|
}
|
|
@@ -45916,12 +46013,19 @@ function runPdftkCliSync(argv, files) {
|
|
|
45916
46013
|
const groups = opArgs.map((arg) => parsePdftkRangeToken(arg, handles, primaryHandle));
|
|
45917
46014
|
const maxLen = Math.max(0, ...groups.map((g) => g.length));
|
|
45918
46015
|
for (let k = 0; k < maxLen; k++) {
|
|
46016
|
+
if (++cooperativeWork % 64 === 0)
|
|
46017
|
+
yield;
|
|
45919
46018
|
for (const g of groups) {
|
|
45920
|
-
if (
|
|
46019
|
+
if (++cooperativeWork % 64 === 0)
|
|
46020
|
+
yield;
|
|
46021
|
+
if (k < g.length)
|
|
46022
|
+
selections.push(g[k]);
|
|
45921
46023
|
}
|
|
45922
46024
|
}
|
|
45923
46025
|
} else {
|
|
45924
46026
|
for (const arg of opArgs) {
|
|
46027
|
+
if (++cooperativeWork % 64 === 0)
|
|
46028
|
+
yield;
|
|
45925
46029
|
selections.push(...parsePdftkRangeToken(arg, handles, primaryHandle));
|
|
45926
46030
|
}
|
|
45927
46031
|
}
|
|
@@ -45941,6 +46045,8 @@ function runPdftkCliSync(argv, files) {
|
|
|
45941
46045
|
};
|
|
45942
46046
|
const remappedBookmarks = [];
|
|
45943
46047
|
for (let sIdx = 0; sIdx < selections.length; sIdx++) {
|
|
46048
|
+
if (++cooperativeWork % 64 === 0)
|
|
46049
|
+
yield;
|
|
45944
46050
|
const sel = selections[sIdx];
|
|
45945
46051
|
const srcDoc = handles.get(sel.handle) ?? primaryDoc;
|
|
45946
46052
|
const [copied] = resultDoc.copyPagesFrom(srcDoc, [sel.pageNumber - 1]);
|
|
@@ -45950,6 +46056,8 @@ function runPdftkCliSync(argv, files) {
|
|
|
45950
46056
|
copied.setRotation(normalizeQuarterTurn(rawRot));
|
|
45951
46057
|
}
|
|
45952
46058
|
for (const bm of getDocBookmarks(srcDoc)) {
|
|
46059
|
+
if (++cooperativeWork % 64 === 0)
|
|
46060
|
+
yield;
|
|
45953
46061
|
if (bm.pageNumber === sel.pageNumber) {
|
|
45954
46062
|
remappedBookmarks.push({
|
|
45955
46063
|
title: bm.title,
|
|
@@ -45962,11 +46070,15 @@ function runPdftkCliSync(argv, files) {
|
|
|
45962
46070
|
setDocumentBookmarks(resultDoc, remappedBookmarks);
|
|
45963
46071
|
const usedDocs = /* @__PURE__ */ new Set();
|
|
45964
46072
|
for (const sel of selections) {
|
|
46073
|
+
if (++cooperativeWork % 64 === 0)
|
|
46074
|
+
yield;
|
|
45965
46075
|
const d = handles.get(sel.handle) ?? primaryDoc;
|
|
45966
46076
|
usedDocs.add(d);
|
|
45967
46077
|
}
|
|
45968
46078
|
const unpackedMap = /* @__PURE__ */ new Map();
|
|
45969
46079
|
for (const d of usedDocs) {
|
|
46080
|
+
if (++cooperativeWork % 64 === 0)
|
|
46081
|
+
yield;
|
|
45970
46082
|
unpackFilesFromDocument(d, ".", unpackedMap);
|
|
45971
46083
|
}
|
|
45972
46084
|
if (unpackedMap.size > 0) {
|
|
@@ -45978,11 +46090,17 @@ function runPdftkCliSync(argv, files) {
|
|
|
45978
46090
|
} else if (operation === "rotate") {
|
|
45979
46091
|
const rotByPage = /* @__PURE__ */ new Map();
|
|
45980
46092
|
for (const arg of opArgs) {
|
|
46093
|
+
if (++cooperativeWork % 64 === 0)
|
|
46094
|
+
yield;
|
|
45981
46095
|
for (const sel of parsePdftkRangeToken(arg, handles, primaryHandle)) {
|
|
45982
|
-
if (
|
|
46096
|
+
if (++cooperativeWork % 64 === 0)
|
|
46097
|
+
yield;
|
|
46098
|
+
if (sel.rotation)
|
|
46099
|
+
rotByPage.set(sel.pageNumber, sel.rotation);
|
|
45983
46100
|
}
|
|
45984
46101
|
}
|
|
45985
46102
|
for (let p = 1; p <= resultDoc.pageCount; p++) {
|
|
46103
|
+
yield;
|
|
45986
46104
|
const spec = rotByPage.get(p);
|
|
45987
46105
|
if (spec) {
|
|
45988
46106
|
const page = resultDoc.getPage(p - 1);
|
|
@@ -45998,12 +46116,7 @@ function runPdftkCliSync(argv, files) {
|
|
|
45998
46116
|
` };
|
|
45999
46117
|
}
|
|
46000
46118
|
const overlayDoc = PdfDocument.load(overlayBytes);
|
|
46001
|
-
applyOverlayToDocument(
|
|
46002
|
-
resultDoc,
|
|
46003
|
-
overlayDoc,
|
|
46004
|
-
operation.includes("background") ? "background" : "stamp",
|
|
46005
|
-
operation.startsWith("multi")
|
|
46006
|
-
);
|
|
46119
|
+
applyOverlayToDocument(resultDoc, overlayDoc, operation.includes("background") ? "background" : "stamp", operation.startsWith("multi"));
|
|
46007
46120
|
if (shouldFlatten) {
|
|
46008
46121
|
flattenDocumentFormFields(resultDoc.cos);
|
|
46009
46122
|
}
|
|
@@ -46015,15 +46128,19 @@ function runPdftkCliSync(argv, files) {
|
|
|
46015
46128
|
if (dropXfa) {
|
|
46016
46129
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
46017
46130
|
const acroForm = root ? resultDoc.cos.resolveDict(dictGet(root, "AcroForm")) : void 0;
|
|
46018
|
-
if (acroForm)
|
|
46131
|
+
if (acroForm)
|
|
46132
|
+
dictDelete(acroForm, "XFA");
|
|
46019
46133
|
}
|
|
46020
46134
|
if (dropXmp) {
|
|
46021
46135
|
const root = resultDoc.cos.resolveDict(resultDoc.cos.rootRef);
|
|
46022
|
-
if (root)
|
|
46136
|
+
if (root)
|
|
46137
|
+
dictDelete(root, "Metadata");
|
|
46023
46138
|
}
|
|
46024
46139
|
if (replacementFont && operation === "fill_form") {
|
|
46025
46140
|
const cleanFontName = replacementFont.startsWith("/") ? replacementFont.slice(1) : replacementFont;
|
|
46026
46141
|
for (const obj of resultDoc.cos.objects.values()) {
|
|
46142
|
+
if (++cooperativeWork % 64 === 0)
|
|
46143
|
+
yield;
|
|
46027
46144
|
if (obj.value.kind === "dict") {
|
|
46028
46145
|
const stNode = dictGet(obj.value, "Subtype");
|
|
46029
46146
|
const bfNode = dictGet(obj.value, "BaseFont");
|
|
@@ -46064,7 +46181,10 @@ function runPdftkCliSync(argv, files) {
|
|
|
46064
46181
|
}
|
|
46065
46182
|
if (uncompressStreams || compressStreams) {
|
|
46066
46183
|
for (const obj of resultDoc.cos.objects.values()) {
|
|
46067
|
-
if (
|
|
46184
|
+
if (++cooperativeWork % 64 === 0)
|
|
46185
|
+
yield;
|
|
46186
|
+
if (obj.value.kind !== "stream")
|
|
46187
|
+
continue;
|
|
46068
46188
|
const raw = resultDoc.cos.decodeStream(obj.value);
|
|
46069
46189
|
dictDelete(obj.value.dict, "Filter");
|
|
46070
46190
|
dictDelete(obj.value.dict, "DecodeParms");
|
|
@@ -46079,34 +46199,44 @@ function runPdftkCliSync(argv, files) {
|
|
|
46079
46199
|
}
|
|
46080
46200
|
const hasAllow = allowPermissions.size > 0;
|
|
46081
46201
|
const allAllowed = allowPermissions.has("allfeatures");
|
|
46082
|
-
const savedBytes = resultDoc.save(
|
|
46083
|
-
|
|
46084
|
-
|
|
46085
|
-
|
|
46086
|
-
|
|
46087
|
-
|
|
46088
|
-
|
|
46089
|
-
|
|
46090
|
-
|
|
46091
|
-
|
|
46092
|
-
|
|
46093
|
-
|
|
46094
|
-
|
|
46095
|
-
|
|
46096
|
-
|
|
46097
|
-
|
|
46098
|
-
|
|
46099
|
-
|
|
46100
|
-
|
|
46101
|
-
} : {}
|
|
46102
|
-
);
|
|
46202
|
+
const savedBytes = resultDoc.save(userPassword || ownerPassword ? {
|
|
46203
|
+
encrypt: {
|
|
46204
|
+
userPassword: userPassword ?? "",
|
|
46205
|
+
ownerPassword: ownerPassword ?? userPassword ?? "owner",
|
|
46206
|
+
revision: 6,
|
|
46207
|
+
...hasAllow ? {
|
|
46208
|
+
permissions: {
|
|
46209
|
+
print: allAllowed || allowPermissions.has("printing") || allowPermissions.has("degradedprinting"),
|
|
46210
|
+
modify: allAllowed || allowPermissions.has("modifycontents"),
|
|
46211
|
+
copy: allAllowed || allowPermissions.has("copycontents"),
|
|
46212
|
+
addNotes: allAllowed || allowPermissions.has("modifyannotations"),
|
|
46213
|
+
fillForms: allAllowed || allowPermissions.has("fillin") || allowPermissions.has("modifyannotations"),
|
|
46214
|
+
extractAccessibility: allAllowed || allowPermissions.has("screenreaders"),
|
|
46215
|
+
assemble: allAllowed || allowPermissions.has("assembly") || allowPermissions.has("modifycontents"),
|
|
46216
|
+
printHighRes: allAllowed || allowPermissions.has("printing")
|
|
46217
|
+
}
|
|
46218
|
+
} : {}
|
|
46219
|
+
}
|
|
46220
|
+
} : {});
|
|
46103
46221
|
if (!outputTarget || outputTarget === "-") {
|
|
46104
46222
|
return { exitCode: 0, stdout: "", stderr: "", stdoutBytes: savedBytes };
|
|
46105
46223
|
}
|
|
46106
46224
|
files.set(outputTarget, savedBytes);
|
|
46107
46225
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
46108
46226
|
}
|
|
46227
|
+
async function runPdftkCli(argv, files, signal) {
|
|
46228
|
+
return drainSteps(runPdftkCliSteps(argv, files, signal), signal);
|
|
46229
|
+
}
|
|
46230
|
+
function runPdftkCliSync(argv, files, signal) {
|
|
46231
|
+
const steps = runPdftkCliSteps(argv, files, signal);
|
|
46232
|
+
let next = steps.next();
|
|
46233
|
+
while (!next.done) {
|
|
46234
|
+
next = steps.next();
|
|
46235
|
+
}
|
|
46236
|
+
return next.value;
|
|
46237
|
+
}
|
|
46109
46238
|
async function executePdftk(context) {
|
|
46239
|
+
let cooperativeWork = 63;
|
|
46110
46240
|
const invocation = createOutputOperation(context, { write: async () => {
|
|
46111
46241
|
} });
|
|
46112
46242
|
try {
|
|
@@ -46125,6 +46255,7 @@ async function executePdftk(context) {
|
|
|
46125
46255
|
const chunks = [];
|
|
46126
46256
|
let total = 0;
|
|
46127
46257
|
for await (const chunk of readBytes(context.stdin, invocation.signal)) {
|
|
46258
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
46128
46259
|
chunks.push(chunk);
|
|
46129
46260
|
total += chunk.byteLength;
|
|
46130
46261
|
chargeBytes(chunk.byteLength);
|
|
@@ -46132,12 +46263,14 @@ async function executePdftk(context) {
|
|
|
46132
46263
|
const buf = new Uint8Array(total);
|
|
46133
46264
|
let off = 0;
|
|
46134
46265
|
for (const c of chunks) {
|
|
46266
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
46135
46267
|
buf.set(c, off);
|
|
46136
46268
|
off += c.byteLength;
|
|
46137
46269
|
}
|
|
46138
46270
|
vfsFiles.set("-", buf);
|
|
46139
46271
|
}
|
|
46140
46272
|
for (const token of argv) {
|
|
46273
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
46141
46274
|
if (token.startsWith("-") && token !== "-") continue;
|
|
46142
46275
|
const eqIdx = token.indexOf("=");
|
|
46143
46276
|
const filePath = eqIdx > 0 ? token.slice(eqIdx + 1) : token;
|
|
@@ -46149,8 +46282,9 @@ async function executePdftk(context) {
|
|
|
46149
46282
|
} catch {
|
|
46150
46283
|
}
|
|
46151
46284
|
}
|
|
46285
|
+
context.inputBudget?.check(0);
|
|
46152
46286
|
const existingSnap = new Map(vfsFiles);
|
|
46153
|
-
const res = await runPdftkCli(argv, vfsFiles);
|
|
46287
|
+
const res = await runPdftkCli(argv, vfsFiles, invocation.signal);
|
|
46154
46288
|
if (res.stderr) {
|
|
46155
46289
|
await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
|
|
46156
46290
|
}
|
|
@@ -46165,6 +46299,7 @@ async function executePdftk(context) {
|
|
|
46165
46299
|
await writeBytes(stdout.output, outBytes, invocation.signal);
|
|
46166
46300
|
}
|
|
46167
46301
|
for (const [key, val] of vfsFiles.entries()) {
|
|
46302
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
46168
46303
|
if (key !== "-" && existingSnap.get(key) !== val) {
|
|
46169
46304
|
chargeBytes(val.byteLength);
|
|
46170
46305
|
const abs = resolveVfsPath(key);
|
|
@@ -46181,13 +46316,14 @@ async function executePdftk(context) {
|
|
|
46181
46316
|
await invocation.close();
|
|
46182
46317
|
}
|
|
46183
46318
|
}
|
|
46184
|
-
function createPdftkCommand(
|
|
46319
|
+
function createPdftkCommand(options = {}) {
|
|
46320
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
46185
46321
|
return Object.freeze({
|
|
46186
46322
|
name: "pdftk",
|
|
46187
46323
|
runtimeIdentity: commandRuntimeIdentity,
|
|
46188
46324
|
description: "Manipulate PDF documents, fill/flatten AcroForms, and assemble pages via @poe-code/pdf-ast",
|
|
46189
46325
|
execute(context) {
|
|
46190
|
-
return
|
|
46326
|
+
return new InputByteBudget(maxInputBytes).run(context, executePdftk);
|
|
46191
46327
|
}
|
|
46192
46328
|
});
|
|
46193
46329
|
}
|