@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-pdftotext/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,
|
|
@@ -40689,7 +40728,8 @@ function resolveInheritedFieldEntry(doc, dict, key) {
|
|
|
40689
40728
|
}
|
|
40690
40729
|
return void 0;
|
|
40691
40730
|
}
|
|
40692
|
-
function
|
|
40731
|
+
function* collectFieldDictsSteps(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen, yieldState = { work: 0 }) {
|
|
40732
|
+
if (++yieldState.work % 256 === 0) yield;
|
|
40693
40733
|
const dict = doc.resolveDict(node);
|
|
40694
40734
|
if (!dict) return out;
|
|
40695
40735
|
const tNode = doc.resolve(dictGet(dict, "T"));
|
|
@@ -40722,7 +40762,8 @@ function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", pare
|
|
|
40722
40762
|
return out;
|
|
40723
40763
|
}
|
|
40724
40764
|
for (const kid of kidsArr.items) {
|
|
40725
|
-
|
|
40765
|
+
if (++yieldState.work % 16 === 0) yield;
|
|
40766
|
+
yield* collectFieldDictsSteps(doc, kid, fullName, out, currentFt, currentFf, currentQ, currentMaxLen, yieldState);
|
|
40726
40767
|
}
|
|
40727
40768
|
} else if (fullName) {
|
|
40728
40769
|
out.push({
|
|
@@ -41163,6 +41204,9 @@ function escapePdfLiteralString(str) {
|
|
|
41163
41204
|
}
|
|
41164
41205
|
return out;
|
|
41165
41206
|
}
|
|
41207
|
+
function collectFieldDicts(doc, node, prefix = "", out = [], parentFt = "", parentFf = 0, parentQ = 0, parentMaxLen) {
|
|
41208
|
+
drainWork(collectFieldDictsSteps(doc, node, prefix, out, parentFt, parentFf, parentQ, parentMaxLen));
|
|
41209
|
+
}
|
|
41166
41210
|
var PdfPage = class {
|
|
41167
41211
|
cosDoc;
|
|
41168
41212
|
pageRef;
|
|
@@ -43843,14 +43887,18 @@ var PdfDocument = class _PdfDocument {
|
|
|
43843
43887
|
});
|
|
43844
43888
|
return new _PdfDocument(parseCosDocument(rawBytes));
|
|
43845
43889
|
}
|
|
43846
|
-
static
|
|
43890
|
+
static *loadSteps(bytes, options) {
|
|
43891
|
+
yield;
|
|
43847
43892
|
return new _PdfDocument(
|
|
43848
|
-
|
|
43893
|
+
yield* parseCosDocumentSteps(bytes, {
|
|
43849
43894
|
...options,
|
|
43850
43895
|
recovery: options?.recovery ?? "repair"
|
|
43851
43896
|
})
|
|
43852
43897
|
);
|
|
43853
43898
|
}
|
|
43899
|
+
static load(bytes, options) {
|
|
43900
|
+
return drainWork(_PdfDocument.loadSteps(bytes, options));
|
|
43901
|
+
}
|
|
43854
43902
|
rebuildPagesList() {
|
|
43855
43903
|
const catalog = this.cos.resolveDict(this.cos.rootRef);
|
|
43856
43904
|
const pagesNode = catalog ? dictGet(catalog, "Pages") : void 0;
|
|
@@ -43932,20 +43980,30 @@ var PdfDocument = class _PdfDocument {
|
|
|
43932
43980
|
this.pages.splice(index, 1);
|
|
43933
43981
|
this.syncPageTree();
|
|
43934
43982
|
}
|
|
43935
|
-
|
|
43983
|
+
*copyPagesFromSteps(sourceDoc, indices) {
|
|
43984
|
+
function* cloneItems(items) {
|
|
43985
|
+
const result = [];
|
|
43986
|
+
for (const item of items) result.push(yield* cloneNode(item));
|
|
43987
|
+
return result;
|
|
43988
|
+
}
|
|
43989
|
+
yield;
|
|
43990
|
+
let work = 0;
|
|
43936
43991
|
const memo = /* @__PURE__ */ new Map();
|
|
43937
43992
|
const sourcePageObjNums = /* @__PURE__ */ new Set();
|
|
43938
43993
|
for (let i = 0; i < sourceDoc.getPageCount(); i++) {
|
|
43994
|
+
if (++work % 16 === 0) yield;
|
|
43939
43995
|
sourcePageObjNums.add(sourceDoc.getPage(i).ref.objectNumber);
|
|
43940
43996
|
}
|
|
43941
43997
|
const targetPageRefs = [];
|
|
43942
43998
|
for (const idx of indices) {
|
|
43999
|
+
if (++work % 16 === 0) yield;
|
|
43943
44000
|
const srcPage = sourceDoc.getPage(idx);
|
|
43944
44001
|
const pageRef = this.cos.allocateObject({ kind: "null" });
|
|
43945
44002
|
targetPageRefs.push(pageRef);
|
|
43946
44003
|
memo.set(srcPage.ref.objectNumber, pageRef);
|
|
43947
44004
|
}
|
|
43948
|
-
const cloneNode = (node)
|
|
44005
|
+
const cloneNode = function* (node) {
|
|
44006
|
+
if (++work % 16 === 0) yield;
|
|
43949
44007
|
if (node.kind === "ref") {
|
|
43950
44008
|
const existing = memo.get(node.objectNumber);
|
|
43951
44009
|
if (existing) return existing;
|
|
@@ -43956,12 +44014,12 @@ var PdfDocument = class _PdfDocument {
|
|
|
43956
44014
|
if (!target) return cosRef(0);
|
|
43957
44015
|
const placeholderRef = this.cos.allocateObject({ kind: "null" });
|
|
43958
44016
|
memo.set(node.objectNumber, placeholderRef);
|
|
43959
|
-
const clonedTarget = cloneNode(target);
|
|
44017
|
+
const clonedTarget = yield* cloneNode(target);
|
|
43960
44018
|
this.cos.setObject(placeholderRef.objectNumber, clonedTarget, 0);
|
|
43961
44019
|
return placeholderRef;
|
|
43962
44020
|
}
|
|
43963
44021
|
if (node.kind === "array") {
|
|
43964
|
-
return cosArray(node.items
|
|
44022
|
+
return cosArray(yield* cloneItems(node.items));
|
|
43965
44023
|
}
|
|
43966
44024
|
if (node.kind === "dict") {
|
|
43967
44025
|
const typeEntry = dictGet(node, "Type");
|
|
@@ -43971,13 +44029,13 @@ var PdfDocument = class _PdfDocument {
|
|
|
43971
44029
|
if (isPageTreeNode && entry.key.decoded === "Parent") continue;
|
|
43972
44030
|
newEntries.push({
|
|
43973
44031
|
key: { ...entry.key },
|
|
43974
|
-
value: cloneNode(entry.value)
|
|
44032
|
+
value: yield* cloneNode(entry.value)
|
|
43975
44033
|
});
|
|
43976
44034
|
}
|
|
43977
44035
|
return { kind: "dict", entries: newEntries };
|
|
43978
44036
|
}
|
|
43979
44037
|
if (node.kind === "stream") {
|
|
43980
|
-
const clonedDict = cloneNode(node.dict);
|
|
44038
|
+
const clonedDict = yield* cloneNode(node.dict);
|
|
43981
44039
|
return {
|
|
43982
44040
|
kind: "stream",
|
|
43983
44041
|
dict: clonedDict,
|
|
@@ -43986,11 +44044,12 @@ var PdfDocument = class _PdfDocument {
|
|
|
43986
44044
|
};
|
|
43987
44045
|
}
|
|
43988
44046
|
return node;
|
|
43989
|
-
};
|
|
44047
|
+
}.bind(this);
|
|
43990
44048
|
const copiedPages = [];
|
|
43991
44049
|
for (const [position, idx] of indices.entries()) {
|
|
44050
|
+
if (++work % 16 === 0) yield;
|
|
43992
44051
|
const srcPage = sourceDoc.getPage(idx);
|
|
43993
|
-
const clonedPageDict = cloneNode(srcPage.pageDict);
|
|
44052
|
+
const clonedPageDict = yield* cloneNode(srcPage.pageDict);
|
|
43994
44053
|
const size = srcPage.getSize();
|
|
43995
44054
|
if (!dictGet(clonedPageDict, "MediaBox")) {
|
|
43996
44055
|
dictSet(
|
|
@@ -44000,13 +44059,14 @@ var PdfDocument = class _PdfDocument {
|
|
|
44000
44059
|
);
|
|
44001
44060
|
}
|
|
44002
44061
|
if (!dictGet(clonedPageDict, "Resources")) {
|
|
44003
|
-
dictSet(clonedPageDict, "Resources", cloneNode(srcPage.getResourcesDict()));
|
|
44062
|
+
dictSet(clonedPageDict, "Resources", yield* cloneNode(srcPage.getResourcesDict()));
|
|
44004
44063
|
}
|
|
44005
44064
|
if (!dictGet(clonedPageDict, "Rotate") && srcPage.getRotation() !== 0) {
|
|
44006
44065
|
dictSet(clonedPageDict, "Rotate", cosNumber(srcPage.getRotation()));
|
|
44007
44066
|
}
|
|
44008
44067
|
const inheritedBoxKeys = ["CropBox", "BleedBox", "TrimBox", "ArtBox"];
|
|
44009
44068
|
for (const boxKey of inheritedBoxKeys) {
|
|
44069
|
+
if (++work % 16 === 0) yield;
|
|
44010
44070
|
if (!dictGet(clonedPageDict, boxKey)) {
|
|
44011
44071
|
const boxVal = boxKey === "CropBox" ? srcPage.getCropBox() : boxKey === "BleedBox" ? srcPage.getBleedBox() : boxKey === "TrimBox" ? srcPage.getTrimBox() : srcPage.getArtBox();
|
|
44012
44072
|
if (boxVal[0] !== 0 || boxVal[1] !== 0 || boxVal[2] !== size.width || boxVal[3] !== size.height) {
|
|
@@ -44048,8 +44108,9 @@ var PdfDocument = class _PdfDocument {
|
|
|
44048
44108
|
};
|
|
44049
44109
|
const clonedRootFieldRefs = [];
|
|
44050
44110
|
for (const item of srcFieldsArr.items) {
|
|
44111
|
+
if (++work % 16 === 0) yield;
|
|
44051
44112
|
if (!hasClonedDescendant(item)) continue;
|
|
44052
|
-
const cloned = cloneNode(item);
|
|
44113
|
+
const cloned = yield* cloneNode(item);
|
|
44053
44114
|
if (cloned.kind === "ref") {
|
|
44054
44115
|
const clonedDict = this.cos.resolveDict(cloned);
|
|
44055
44116
|
const kidsArr = clonedDict ? this.cos.resolveArray(dictGet(clonedDict, "Kids")) : void 0;
|
|
@@ -44083,6 +44144,7 @@ var PdfDocument = class _PdfDocument {
|
|
|
44083
44144
|
dstFields.items.filter((x) => x.kind === "ref").map((x) => x.objectNumber)
|
|
44084
44145
|
);
|
|
44085
44146
|
for (const fRef of clonedRootFieldRefs) {
|
|
44147
|
+
if (++work % 16 === 0) yield;
|
|
44086
44148
|
if (!existingNums.has(fRef.objectNumber)) {
|
|
44087
44149
|
dstFields.items.push(fRef);
|
|
44088
44150
|
existingNums.add(fRef.objectNumber);
|
|
@@ -44090,11 +44152,11 @@ var PdfDocument = class _PdfDocument {
|
|
|
44090
44152
|
}
|
|
44091
44153
|
const srcDr = dictGet(srcAcroForm, "DR");
|
|
44092
44154
|
if (srcDr && !dictGet(dstAcroForm, "DR")) {
|
|
44093
|
-
dictSet(dstAcroForm, "DR", cloneNode(srcDr));
|
|
44155
|
+
dictSet(dstAcroForm, "DR", yield* cloneNode(srcDr));
|
|
44094
44156
|
}
|
|
44095
44157
|
const srcDa = dictGet(srcAcroForm, "DA");
|
|
44096
44158
|
if (srcDa && !dictGet(dstAcroForm, "DA")) {
|
|
44097
|
-
dictSet(dstAcroForm, "DA", cloneNode(srcDa));
|
|
44159
|
+
dictSet(dstAcroForm, "DA", yield* cloneNode(srcDa));
|
|
44098
44160
|
}
|
|
44099
44161
|
}
|
|
44100
44162
|
}
|
|
@@ -44103,12 +44165,15 @@ var PdfDocument = class _PdfDocument {
|
|
|
44103
44165
|
if (srcOcProps) {
|
|
44104
44166
|
const dstCatalog = this.cos.resolveDict(this.cos.rootRef);
|
|
44105
44167
|
if (dstCatalog && !dictGet(dstCatalog, "OCProperties")) {
|
|
44106
|
-
dictSet(dstCatalog, "OCProperties", cloneNode(srcOcProps));
|
|
44168
|
+
dictSet(dstCatalog, "OCProperties", yield* cloneNode(srcOcProps));
|
|
44107
44169
|
}
|
|
44108
44170
|
}
|
|
44109
44171
|
this.syncPageTree();
|
|
44110
44172
|
return copiedPages;
|
|
44111
44173
|
}
|
|
44174
|
+
copyPagesFrom(sourceDoc, indices) {
|
|
44175
|
+
return drainWork(this.copyPagesFromSteps(sourceDoc, indices));
|
|
44176
|
+
}
|
|
44112
44177
|
embedStandardFont(fontName) {
|
|
44113
44178
|
return createStandardFontHandle(fontName);
|
|
44114
44179
|
}
|
|
@@ -44308,14 +44373,15 @@ var PdfDocument = class _PdfDocument {
|
|
|
44308
44373
|
});
|
|
44309
44374
|
return buildSemanticAstFromPages(extractedPages, tablesByPage, displayLists);
|
|
44310
44375
|
}
|
|
44311
|
-
|
|
44376
|
+
*saveSteps(options = {}) {
|
|
44377
|
+
yield;
|
|
44312
44378
|
this.syncPageTree();
|
|
44313
44379
|
if (this.cos.requiresFullRewrite) {
|
|
44314
44380
|
pruneUnusedXObjects(this.cos, this.pages);
|
|
44315
44381
|
discardUnreachableObjects(this.cos);
|
|
44316
44382
|
}
|
|
44317
44383
|
if (options.encrypt) {
|
|
44318
|
-
return
|
|
44384
|
+
return yield* encryptCosDocumentSteps(this.cos, options.encrypt);
|
|
44319
44385
|
}
|
|
44320
44386
|
const allObjects = [...this.cos.objects.values()].sort(
|
|
44321
44387
|
(a, b) => a.objectNumber - b.objectNumber
|
|
@@ -44323,7 +44389,7 @@ var PdfDocument = class _PdfDocument {
|
|
|
44323
44389
|
if (options.incremental && !this.cos.requiresFullRewrite && this.cos.bytes.length > 0) {
|
|
44324
44390
|
return appendIncrementalRevision(this.cos.bytes, this.cos, allObjects);
|
|
44325
44391
|
}
|
|
44326
|
-
return
|
|
44392
|
+
return yield* serializeCosDocumentSteps({
|
|
44327
44393
|
objects: allObjects,
|
|
44328
44394
|
rootRef: this.cos.rootRef,
|
|
44329
44395
|
infoRef: this.cos.infoRef,
|
|
@@ -44334,6 +44400,9 @@ var PdfDocument = class _PdfDocument {
|
|
|
44334
44400
|
linearize: options.linearize
|
|
44335
44401
|
});
|
|
44336
44402
|
}
|
|
44403
|
+
save(options = {}) {
|
|
44404
|
+
return drainWork(this.saveSteps(options));
|
|
44405
|
+
}
|
|
44337
44406
|
};
|
|
44338
44407
|
function resolveDestinationPageIndex(doc, destOrActionNode) {
|
|
44339
44408
|
const cos = doc.cos;
|
|
@@ -44895,7 +44964,7 @@ function renderTsv(pages, args) {
|
|
|
44895
44964
|
}
|
|
44896
44965
|
return rows.join("\n") + "\n";
|
|
44897
44966
|
}
|
|
44898
|
-
function
|
|
44967
|
+
function* extractPdfToTextBytesSteps(bytes, argv = []) {
|
|
44899
44968
|
const args = parseArgs(argv);
|
|
44900
44969
|
const stderrParts = [];
|
|
44901
44970
|
if (args.invalidEolWarning) {
|
|
@@ -44974,12 +45043,14 @@ ${[...SUPPORTED_ENCODINGS].join("\n")}
|
|
|
44974
45043
|
const mode = args.raw ? "raw" : args.layout ? "layout" : "logical";
|
|
44975
45044
|
const pages = [];
|
|
44976
45045
|
for (let p = firstPage; p <= lastPage; p++) {
|
|
45046
|
+
yield;
|
|
44977
45047
|
const page = doc.getPage(p - 1);
|
|
44978
45048
|
let pageCropBoxPt;
|
|
44979
45049
|
if (args.cropbox) {
|
|
44980
45050
|
let cur = page.pageDict;
|
|
44981
45051
|
const visited = /* @__PURE__ */ new Set();
|
|
44982
45052
|
while (cur && !visited.has(cur)) {
|
|
45053
|
+
yield;
|
|
44983
45054
|
visited.add(cur);
|
|
44984
45055
|
const cb = doc.cos.resolveArray(dictGet(cur, "CropBox"));
|
|
44985
45056
|
if (cb && cb.items.length >= 4) {
|
|
@@ -45058,6 +45129,7 @@ ${escapeXml(tsvText)}</pre>
|
|
|
45058
45129
|
const eolChar = args.eol === "dos" ? "\r\n" : args.eol === "mac" ? "\r" : "\n";
|
|
45059
45130
|
let textOut = "";
|
|
45060
45131
|
for (const { pageNumber, extracted } of pages) {
|
|
45132
|
+
yield;
|
|
45061
45133
|
let pageText = formatExtractedPageText(extracted, {
|
|
45062
45134
|
mode,
|
|
45063
45135
|
rejoinHyphens: mode === "logical" && args.removeHyphens,
|
|
@@ -45069,6 +45141,7 @@ ${escapeXml(tsvText)}</pre>
|
|
|
45069
45141
|
const annots = extractPageAnnotations(doc.cos, doc.getPage(pageNumber - 1).pageDict);
|
|
45070
45142
|
const uris = [];
|
|
45071
45143
|
for (const ann of annots) {
|
|
45144
|
+
yield;
|
|
45072
45145
|
if (ann.uri && !pageText.includes(ann.uri) && !uris.includes(ann.uri)) {
|
|
45073
45146
|
uris.push(ann.uri);
|
|
45074
45147
|
}
|
|
@@ -45123,14 +45196,34 @@ ${escapeXml(textOut)}</pre>
|
|
|
45123
45196
|
outputPath: args.outputFile ?? "-"
|
|
45124
45197
|
};
|
|
45125
45198
|
}
|
|
45126
|
-
|
|
45199
|
+
function extractPdfToTextBytes(bytes, argv = []) {
|
|
45200
|
+
const steps = extractPdfToTextBytesSteps(bytes, argv);
|
|
45201
|
+
for (; ; ) {
|
|
45202
|
+
const step = steps.next();
|
|
45203
|
+
if (step.done) return step.value;
|
|
45204
|
+
}
|
|
45205
|
+
}
|
|
45206
|
+
function* extractPdfToTextBytesCooperativelySteps(bytes, argv = [], signal) {
|
|
45207
|
+
const steps = extractPdfToTextBytesSteps(bytes, argv);
|
|
45208
|
+
try {
|
|
45209
|
+
for (; ; ) {
|
|
45210
|
+
yield;
|
|
45211
|
+
const step = steps.next();
|
|
45212
|
+
if (step.done)
|
|
45213
|
+
return step.value;
|
|
45214
|
+
}
|
|
45215
|
+
} finally {
|
|
45216
|
+
steps.return({ exitCode: 1, output: "", stderr: "", outputPath: "-" });
|
|
45217
|
+
}
|
|
45218
|
+
}
|
|
45219
|
+
function* runPdftotextCliSteps(argv, files, stdinBytes = new Uint8Array(0), signal) {
|
|
45127
45220
|
const args = parseArgs(argv);
|
|
45128
45221
|
if (args.error || args.listenc || args.version || args.help) {
|
|
45129
|
-
return
|
|
45222
|
+
return yield* extractPdfToTextBytesCooperativelySteps(new Uint8Array(0), argv, signal);
|
|
45130
45223
|
}
|
|
45131
45224
|
const target = args.inputFile ?? "-";
|
|
45132
45225
|
if (target === "-") {
|
|
45133
|
-
return
|
|
45226
|
+
return yield* extractPdfToTextBytesCooperativelySteps(stdinBytes, argv, signal);
|
|
45134
45227
|
}
|
|
45135
45228
|
const fileBytes = files.get(target);
|
|
45136
45229
|
if (!fileBytes) {
|
|
@@ -45142,9 +45235,13 @@ async function runPdftotextCli(argv, files, stdinBytes = new Uint8Array(0)) {
|
|
|
45142
45235
|
outputPath: args.outputFile ?? "-"
|
|
45143
45236
|
};
|
|
45144
45237
|
}
|
|
45145
|
-
return
|
|
45238
|
+
return yield* extractPdfToTextBytesCooperativelySteps(fileBytes, argv, signal);
|
|
45239
|
+
}
|
|
45240
|
+
async function runPdftotextCli(argv, files, stdinBytes = new Uint8Array(0), signal) {
|
|
45241
|
+
return drainSteps(runPdftotextCliSteps(argv, files, stdinBytes, signal), signal);
|
|
45146
45242
|
}
|
|
45147
45243
|
async function pdftotext(context) {
|
|
45244
|
+
let cooperativeWork = 63;
|
|
45148
45245
|
const invocation = createOutputOperation(context, { write: async () => {
|
|
45149
45246
|
} });
|
|
45150
45247
|
try {
|
|
@@ -45152,7 +45249,7 @@ async function pdftotext(context) {
|
|
|
45152
45249
|
const argv = [...carrier.args];
|
|
45153
45250
|
const parsed = parseArgs(argv);
|
|
45154
45251
|
if (parsed.error || parsed.listenc || parsed.version || parsed.help) {
|
|
45155
|
-
const res2 =
|
|
45252
|
+
const res2 = await drainSteps(extractPdfToTextBytesCooperativelySteps(new Uint8Array(0), argv, invocation.signal), invocation.signal);
|
|
45156
45253
|
if (res2.stderr) {
|
|
45157
45254
|
await writeBytes(context.stderr, new TextEncoder().encode(res2.stderr), invocation.signal);
|
|
45158
45255
|
}
|
|
@@ -45175,6 +45272,7 @@ async function pdftotext(context) {
|
|
|
45175
45272
|
const chunks = [];
|
|
45176
45273
|
let total = 0;
|
|
45177
45274
|
for await (const chunk of readBytes(context.stdin, invocation.signal)) {
|
|
45275
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45178
45276
|
chunks.push(chunk);
|
|
45179
45277
|
total += chunk.byteLength;
|
|
45180
45278
|
chargeBytes(chunk.byteLength);
|
|
@@ -45182,6 +45280,7 @@ async function pdftotext(context) {
|
|
|
45182
45280
|
pdfBytes = new Uint8Array(total);
|
|
45183
45281
|
let offset = 0;
|
|
45184
45282
|
for (const c of chunks) {
|
|
45283
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45185
45284
|
pdfBytes.set(c, offset);
|
|
45186
45285
|
offset += c.byteLength;
|
|
45187
45286
|
}
|
|
@@ -45199,7 +45298,7 @@ async function pdftotext(context) {
|
|
|
45199
45298
|
return { exitCode: 1 };
|
|
45200
45299
|
}
|
|
45201
45300
|
}
|
|
45202
|
-
const res =
|
|
45301
|
+
const res = await drainSteps(extractPdfToTextBytesCooperativelySteps(pdfBytes, argv, invocation.signal), invocation.signal);
|
|
45203
45302
|
if (res.stderr) {
|
|
45204
45303
|
await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
|
|
45205
45304
|
}
|
|
@@ -45229,13 +45328,14 @@ async function pdftotext(context) {
|
|
|
45229
45328
|
await invocation.close();
|
|
45230
45329
|
}
|
|
45231
45330
|
}
|
|
45232
|
-
function createPdftotextCommand(
|
|
45331
|
+
function createPdftotextCommand(options = {}) {
|
|
45332
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
45233
45333
|
return Object.freeze({
|
|
45234
45334
|
name: "pdftotext",
|
|
45235
45335
|
runtimeIdentity: commandRuntimeIdentity,
|
|
45236
45336
|
description: "Extract PDF text, layout, XHTML bounding boxes, and TSV via @poe-code/pdf-ast",
|
|
45237
45337
|
execute(context) {
|
|
45238
|
-
return
|
|
45338
|
+
return new InputByteBudget(maxInputBytes).run(context, pdftotext);
|
|
45239
45339
|
}
|
|
45240
45340
|
});
|
|
45241
45341
|
}
|
|
@@ -45258,10 +45358,8 @@ function bytesToBase64(bytes) {
|
|
|
45258
45358
|
}
|
|
45259
45359
|
return out;
|
|
45260
45360
|
}
|
|
45261
|
-
|
|
45262
|
-
|
|
45263
|
-
}
|
|
45264
|
-
function runPdftohtmlCliSync(argv, files) {
|
|
45361
|
+
function* runPdftohtmlCliSteps(argv, files, signal) {
|
|
45362
|
+
let cooperativeWork = 63;
|
|
45265
45363
|
let xmlMode = false;
|
|
45266
45364
|
let toStdout = false;
|
|
45267
45365
|
let ignoreImages = false;
|
|
@@ -45274,6 +45372,8 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45274
45372
|
let password = "";
|
|
45275
45373
|
const positionals = [];
|
|
45276
45374
|
for (let i = 0; i < argv.length; i++) {
|
|
45375
|
+
if (++cooperativeWork % 64 === 0)
|
|
45376
|
+
yield;
|
|
45277
45377
|
const arg = argv[i];
|
|
45278
45378
|
if (arg === "-v" || arg === "--version") {
|
|
45279
45379
|
return { exitCode: 0, stdout: "pdftohtml version 24.08.0\n", stderr: "" };
|
|
@@ -45343,6 +45443,7 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45343
45443
|
}
|
|
45344
45444
|
const pageRefToNum = /* @__PURE__ */ new Map();
|
|
45345
45445
|
for (let i = 0; i < doc.pageCount; i++) {
|
|
45446
|
+
yield;
|
|
45346
45447
|
pageRefToNum.set(doc.getPage(i).ref.objectNumber, i + 1);
|
|
45347
45448
|
}
|
|
45348
45449
|
const resolveOutlineDestPage = (itemDict) => {
|
|
@@ -45354,11 +45455,13 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45354
45455
|
let cur = firstNode;
|
|
45355
45456
|
while (cur) {
|
|
45356
45457
|
if (cur.kind === "ref") {
|
|
45357
|
-
if (visited.has(cur.objectNumber))
|
|
45458
|
+
if (visited.has(cur.objectNumber))
|
|
45459
|
+
break;
|
|
45358
45460
|
visited.add(cur.objectNumber);
|
|
45359
45461
|
}
|
|
45360
45462
|
const dict = doc.cos.resolveDict(cur);
|
|
45361
|
-
if (!dict)
|
|
45463
|
+
if (!dict)
|
|
45464
|
+
break;
|
|
45362
45465
|
const tNode = doc.cos.resolve(dictGet(dict, "Title"));
|
|
45363
45466
|
const title = tNode?.kind === "string" ? decodePdfString(tNode) : "";
|
|
45364
45467
|
const pageNumber = resolveOutlineDestPage(dict);
|
|
@@ -45381,6 +45484,7 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45381
45484
|
`<pdf2xml producer="@poe-code/pdf-ast" version="24.08.0">`
|
|
45382
45485
|
];
|
|
45383
45486
|
for (let p = firstPage; p <= endPage; p++) {
|
|
45487
|
+
yield;
|
|
45384
45488
|
const page = doc.getPage(p - 1);
|
|
45385
45489
|
const { width, height } = page.getSize();
|
|
45386
45490
|
const extracted = page.extractPage();
|
|
@@ -45391,6 +45495,8 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45391
45495
|
const fontSubDict = resDict ? doc.cos.resolveDict(dictGet(resDict, "Font")) : void 0;
|
|
45392
45496
|
if (fontSubDict) {
|
|
45393
45497
|
for (const entry of fontSubDict.entries) {
|
|
45498
|
+
if (++cooperativeWork % 64 === 0)
|
|
45499
|
+
yield;
|
|
45394
45500
|
const fDict = doc.cos.resolveDict(entry.value);
|
|
45395
45501
|
const bfNode = fDict ? doc.cos.resolve(dictGet(fDict, "BaseFont") ?? dictGet(fDict, "Name")) : void 0;
|
|
45396
45502
|
if (bfNode?.kind === "name") {
|
|
@@ -45408,6 +45514,7 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45408
45514
|
lines.push(` <page number="${p}" position="absolute" top="0" left="0" height="${Math.round(height * zoom)}" width="${Math.round(width * zoom)}">`);
|
|
45409
45515
|
const imageLines = [];
|
|
45410
45516
|
for (let imgIdx = 0; imgIdx < pageImages.length; imgIdx++) {
|
|
45517
|
+
yield;
|
|
45411
45518
|
const img = pageImages[imgIdx];
|
|
45412
45519
|
const imgBytes = imageFmt === "jpg" ? encodeJpeg(img.bitmap) : encodePng(img.bitmap);
|
|
45413
45520
|
const imgFile = `page${p}_${imgIdx + 1}.${imageFmt}`;
|
|
@@ -45420,7 +45527,11 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45420
45527
|
}
|
|
45421
45528
|
const textLines = [];
|
|
45422
45529
|
for (const block of extracted.blocks) {
|
|
45530
|
+
if (++cooperativeWork % 64 === 0)
|
|
45531
|
+
yield;
|
|
45423
45532
|
for (const line of block.lines) {
|
|
45533
|
+
if (++cooperativeWork % 64 === 0)
|
|
45534
|
+
yield;
|
|
45424
45535
|
const [x0, y0, x1, y1] = line.bbox;
|
|
45425
45536
|
const top = Math.max(0, Math.round((height - y1) * zoom));
|
|
45426
45537
|
const left = Math.max(0, Math.round(x0 * zoom));
|
|
@@ -45436,13 +45547,9 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45436
45547
|
if (specId === void 0) {
|
|
45437
45548
|
specId = fontSpecIdByKey.size;
|
|
45438
45549
|
fontSpecIdByKey.set(specKey, specId);
|
|
45439
|
-
fontSpecLines.push(
|
|
45440
|
-
` <fontspec id="${specId}" size="${scaledSize}" family="${escapeHtmlXml(family)}" color="#000000"/>`
|
|
45441
|
-
);
|
|
45550
|
+
fontSpecLines.push(` <fontspec id="${specId}" size="${scaledSize}" family="${escapeHtmlXml(family)}" color="#000000"/>`);
|
|
45442
45551
|
}
|
|
45443
|
-
const matchingLink = annots.find(
|
|
45444
|
-
(a) => a.uri && Math.min(x1, Math.max(a.rect[0], a.rect[2])) > Math.max(x0, Math.min(a.rect[0], a.rect[2])) && Math.min(y1, Math.max(a.rect[1], a.rect[3])) > Math.max(y0, Math.min(a.rect[1], a.rect[3]))
|
|
45445
|
-
);
|
|
45552
|
+
const matchingLink = annots.find((a) => a.uri && Math.min(x1, Math.max(a.rect[0], a.rect[2])) > Math.max(x0, Math.min(a.rect[0], a.rect[2])) && Math.min(y1, Math.max(a.rect[1], a.rect[3])) > Math.max(y0, Math.min(a.rect[1], a.rect[3])));
|
|
45446
45553
|
let styledText = escapeHtmlXml(line.text);
|
|
45447
45554
|
const lowerFam = family.toLowerCase();
|
|
45448
45555
|
if (lowerFam.includes("italic") || lowerFam.includes("oblique")) {
|
|
@@ -45483,6 +45590,7 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45483
45590
|
`<body>`
|
|
45484
45591
|
];
|
|
45485
45592
|
for (let p = firstPage; p <= endPage; p++) {
|
|
45593
|
+
yield;
|
|
45486
45594
|
const page = doc.getPage(p - 1);
|
|
45487
45595
|
const { width, height } = page.getSize();
|
|
45488
45596
|
const extracted = page.extractPage();
|
|
@@ -45490,6 +45598,7 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45490
45598
|
const pageImages = ignoreImages ? [] : extractDocumentImages(doc.cos, { firstPage: p, lastPage: p });
|
|
45491
45599
|
lines.push(`<div class="page" id="page${p}" style="position:relative;width:${Math.round(width * zoom)}pt;height:${Math.round(height * zoom)}pt;">`);
|
|
45492
45600
|
for (let imgIdx = 0; imgIdx < pageImages.length; imgIdx++) {
|
|
45601
|
+
yield;
|
|
45493
45602
|
const img = pageImages[imgIdx];
|
|
45494
45603
|
const imgBytes = imageFmt === "jpg" ? encodeJpeg(img.bitmap) : encodePng(img.bitmap);
|
|
45495
45604
|
const imgFile = `page${p}_${imgIdx + 1}.${imageFmt}`;
|
|
@@ -45501,13 +45610,15 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45501
45610
|
lines.push(` <img src="${src}" width="${img.width}" height="${img.height}"/>`);
|
|
45502
45611
|
}
|
|
45503
45612
|
for (const block of extracted.blocks) {
|
|
45613
|
+
if (++cooperativeWork % 64 === 0)
|
|
45614
|
+
yield;
|
|
45504
45615
|
for (const line of block.lines) {
|
|
45616
|
+
if (++cooperativeWork % 64 === 0)
|
|
45617
|
+
yield;
|
|
45505
45618
|
const [x0, y0, x1, y1] = line.bbox;
|
|
45506
45619
|
const top = Math.max(0, Math.round((height - y1) * zoom));
|
|
45507
45620
|
const left = Math.max(0, Math.round(x0 * zoom));
|
|
45508
|
-
const matchingLink = annots.find(
|
|
45509
|
-
(a) => a.uri && Math.min(x1, Math.max(a.rect[0], a.rect[2])) > Math.max(x0, Math.min(a.rect[0], a.rect[2])) && Math.min(y1, Math.max(a.rect[1], a.rect[3])) > Math.max(y0, Math.min(a.rect[1], a.rect[3]))
|
|
45510
|
-
);
|
|
45621
|
+
const matchingLink = annots.find((a) => a.uri && Math.min(x1, Math.max(a.rect[0], a.rect[2])) > Math.max(x0, Math.min(a.rect[0], a.rect[2])) && Math.min(y1, Math.max(a.rect[1], a.rect[3])) > Math.max(y0, Math.min(a.rect[1], a.rect[3])));
|
|
45511
45622
|
const firstWord = line.words[0];
|
|
45512
45623
|
const rawFontName = firstWord?.fontName ?? firstWord?.glyphs[0]?.fontName ?? "Helvetica";
|
|
45513
45624
|
const cleanFontKey = rawFontName.startsWith("/") ? rawFontName.slice(1) : rawFontName;
|
|
@@ -45559,7 +45670,19 @@ function runPdftohtmlCliSync(argv, files) {
|
|
|
45559
45670
|
files.set(outPath, new TextEncoder().encode(outputText));
|
|
45560
45671
|
return { exitCode: 0, stdout: "", stderr: "" };
|
|
45561
45672
|
}
|
|
45673
|
+
async function runPdftohtmlCli(argv, files, signal) {
|
|
45674
|
+
return drainSteps(runPdftohtmlCliSteps(argv, files, signal), signal);
|
|
45675
|
+
}
|
|
45676
|
+
function runPdftohtmlCliSync(argv, files, signal) {
|
|
45677
|
+
const steps = runPdftohtmlCliSteps(argv, files, signal);
|
|
45678
|
+
let next = steps.next();
|
|
45679
|
+
while (!next.done) {
|
|
45680
|
+
next = steps.next();
|
|
45681
|
+
}
|
|
45682
|
+
return next.value;
|
|
45683
|
+
}
|
|
45562
45684
|
async function pdftohtml(context) {
|
|
45685
|
+
let cooperativeWork = 63;
|
|
45563
45686
|
const invocation = createOutputOperation(context, { write: async () => {
|
|
45564
45687
|
} });
|
|
45565
45688
|
try {
|
|
@@ -45576,6 +45699,7 @@ async function pdftohtml(context) {
|
|
|
45576
45699
|
};
|
|
45577
45700
|
let inputOperand;
|
|
45578
45701
|
for (let i = 0; i < argv.length; i++) {
|
|
45702
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45579
45703
|
const arg = argv[i];
|
|
45580
45704
|
if (["-f", "-l", "-zoom", "-fmt", "-enc", "-upw", "-opw"].includes(arg)) {
|
|
45581
45705
|
i++;
|
|
@@ -45588,6 +45712,7 @@ async function pdftohtml(context) {
|
|
|
45588
45712
|
const chunks = [];
|
|
45589
45713
|
let total = 0;
|
|
45590
45714
|
for await (const chunk of readBytes(context.stdin, invocation.signal)) {
|
|
45715
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45591
45716
|
chunks.push(chunk);
|
|
45592
45717
|
total += chunk.byteLength;
|
|
45593
45718
|
chargeBytes(chunk.byteLength);
|
|
@@ -45596,6 +45721,7 @@ async function pdftohtml(context) {
|
|
|
45596
45721
|
const buf = new Uint8Array(total);
|
|
45597
45722
|
let off = 0;
|
|
45598
45723
|
for (const c of chunks) {
|
|
45724
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45599
45725
|
buf.set(c, off);
|
|
45600
45726
|
off += c.byteLength;
|
|
45601
45727
|
}
|
|
@@ -45603,6 +45729,7 @@ async function pdftohtml(context) {
|
|
|
45603
45729
|
}
|
|
45604
45730
|
}
|
|
45605
45731
|
for (const token of argv) {
|
|
45732
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45606
45733
|
if (token.startsWith("-") && token !== "-") continue;
|
|
45607
45734
|
try {
|
|
45608
45735
|
const bytes = await context.fs.readFile(resolveVfsPath(token), { signal: invocation.signal });
|
|
@@ -45611,8 +45738,9 @@ async function pdftohtml(context) {
|
|
|
45611
45738
|
} catch {
|
|
45612
45739
|
}
|
|
45613
45740
|
}
|
|
45741
|
+
context.inputBudget?.check(0);
|
|
45614
45742
|
const existingSnap = new Map(vfsFiles);
|
|
45615
|
-
const res = await runPdftohtmlCli(argv, vfsFiles);
|
|
45743
|
+
const res = await runPdftohtmlCli(argv, vfsFiles, invocation.signal);
|
|
45616
45744
|
if (res.stderr) {
|
|
45617
45745
|
await writeBytes(context.stderr, new TextEncoder().encode(res.stderr), invocation.signal);
|
|
45618
45746
|
}
|
|
@@ -45623,6 +45751,7 @@ async function pdftohtml(context) {
|
|
|
45623
45751
|
await writeBytes(stdout.output, outBytes, invocation.signal);
|
|
45624
45752
|
}
|
|
45625
45753
|
for (const [key, val] of vfsFiles.entries()) {
|
|
45754
|
+
if (++cooperativeWork % 64 === 0) await yieldTurn(context.signal);
|
|
45626
45755
|
if (existingSnap.get(key) !== val) {
|
|
45627
45756
|
chargeBytes(val.byteLength);
|
|
45628
45757
|
const abs = resolveVfsPath(key);
|
|
@@ -45634,13 +45763,14 @@ async function pdftohtml(context) {
|
|
|
45634
45763
|
await invocation.close();
|
|
45635
45764
|
}
|
|
45636
45765
|
}
|
|
45637
|
-
function createPdftohtmlCommand(
|
|
45766
|
+
function createPdftohtmlCommand(options = {}) {
|
|
45767
|
+
const maxInputBytes = InputByteBudget.limit(options.limits?.maxInputBytes);
|
|
45638
45768
|
return Object.freeze({
|
|
45639
45769
|
name: "pdftohtml",
|
|
45640
45770
|
runtimeIdentity: commandRuntimeIdentity,
|
|
45641
45771
|
description: "Convert PDF pages into HTML or XML layout documents via @poe-code/pdf-ast",
|
|
45642
45772
|
execute(context) {
|
|
45643
|
-
return
|
|
45773
|
+
return new InputByteBudget(maxInputBytes).run(context, pdftohtml);
|
|
45644
45774
|
}
|
|
45645
45775
|
});
|
|
45646
45776
|
}
|