@poe-platform/safe-bash 0.1.802 → 0.1.804
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 +60 -33
- package/dist/image-ast/ast.d.ts +1 -0
- package/dist/image-ast/browser/ast.d.ts +1 -0
- package/dist/image-ast/browser/codecs/jpeg.d.ts +2 -2
- package/dist/image-ast/codecs/jpeg.d.ts +2 -2
- package/dist/image-ast/index.browser.js +692 -8355
- package/dist/image-ast/index.js +692 -8355
- package/dist/mp4-ast/codecs.d.ts +7 -2
- package/dist/safe-bash/chunks/{chunk-CHYGPFVM.js → chunk-22SX3F2R.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-FBUCWVTE.js → chunk-2IVBJTBD.js} +1 -1
- package/dist/safe-bash/chunks/chunk-2POETUMB.js +190 -0
- package/dist/safe-bash/chunks/{chunk-XVOSKJE2.js → chunk-47D7WBJK.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-VKNVHEX3.js → chunk-4ESI236Y.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-74GHTNJA.js → chunk-4KTMKD5W.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-55YJASTN.js → chunk-4T53AERN.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-DQP3VHSB.js → chunk-5XIFJVOO.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-NZQXYWA3.js → chunk-62BOHHJT.js} +1 -2
- package/dist/safe-bash/chunks/{chunk-HZAMGT5I.js → chunk-67WIFM3N.js} +17 -6
- package/dist/safe-bash/chunks/{chunk-4D4N7IU2.js → chunk-6LNFRPW5.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-6O77NL2S.js → chunk-6SMICPI3.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-4BSJLKNM.js → chunk-7O76UFQD.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-44ALJ4QG.js → chunk-AW5KIT6V.js} +3549 -84
- package/dist/safe-bash/chunks/{chunk-RSTHLAF3.js → chunk-B2Z73HTZ.js} +52 -28
- package/dist/safe-bash/chunks/chunk-B3ZMOJVM.js +319 -0
- package/dist/safe-bash/chunks/{chunk-7ZBU7KYV.js → chunk-CFAWS3O4.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-I5HZ4FGE.js → chunk-CL2FCTTO.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-KDNSPLII.js → chunk-CTXNARJH.js} +2 -1
- package/dist/safe-bash/chunks/{chunk-TFIBK2GI.js → chunk-D5Q7NFWI.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-OQRVVGR6.js → chunk-DSOOVZ6Q.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-VTH3MLDU.js → chunk-DUTAG6ZD.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-XAQMU6OY.js → chunk-EE5YGFIZ.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-FZE4HW6G.js → chunk-EJOYT2ME.js} +1 -1
- package/dist/safe-bash/chunks/chunk-FAAIR6EJ.js +887 -0
- package/dist/safe-bash/chunks/{chunk-OV6IHKO6.js → chunk-FOB2FZR4.js} +2 -2
- package/dist/safe-bash/chunks/chunk-G6V4RRSQ.js +14 -0
- package/dist/safe-bash/chunks/{chunk-UTBUUFDM.js → chunk-GGQAGQXQ.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-K6VCD7IY.js → chunk-HIIYIJ5G.js} +2 -4
- package/dist/safe-bash/chunks/chunk-IOHH2GTI.js +56 -0
- package/dist/safe-bash/chunks/{chunk-CTVWDACF.js → chunk-IQW34XQT.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-HZ7BWKQ3.js → chunk-IS572AAT.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-AUSNDQTJ.js → chunk-JPSUHHOA.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-ZVD5IS4V.js → chunk-KBZ4UB2O.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-AM5ESLPH.js → chunk-KU5CVWKA.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-NQCM3TYR.js → chunk-LPOVNKNB.js} +225 -176
- package/dist/safe-bash/chunks/{chunk-46Z5E5EV.js → chunk-MBOC3LZ4.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-6PAVEFT3.js → chunk-N4BQFD3P.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-CS4MNM6I.js → chunk-NGKCVNWS.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-7R5BDCG7.js → chunk-OHML2BEU.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-C5OWC2TL.js → chunk-OQ3AGYCZ.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-B7TAL7S5.js → chunk-PTAEWLSE.js} +0 -2
- package/dist/safe-bash/chunks/{chunk-LVOBFF4D.js → chunk-Q4FNLOTI.js} +1 -1
- package/dist/safe-bash/chunks/chunk-Q5XO3NAS.js +1036 -0
- package/dist/safe-bash/chunks/{chunk-GEG3BWGE.js → chunk-RHFRJIWQ.js} +1 -1
- package/dist/safe-bash/chunks/chunk-RUR6J33T.js +11 -0
- package/dist/safe-bash/chunks/{chunk-WDLGKIHD.js → chunk-S4RFUUXO.js} +841 -26
- package/dist/safe-bash/chunks/{chunk-RRR7AQ24.js → chunk-SD2ISU5L.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-3NDIFSNM.js → chunk-SUJ3NTMH.js} +3 -3
- package/dist/safe-bash/chunks/{chunk-R3NAKOED.js → chunk-SZRUU5HS.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-PH63PLPZ.js → chunk-TC3F4UFF.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-3R3AANOR.js → chunk-TCKYOLUE.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-D3ANYGMC.js → chunk-UV4X32QU.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-E7OYNDGL.js → chunk-V7QT2RWC.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-SHEMU2Z7.js → chunk-W2IYOVHK.js} +839 -1211
- package/dist/safe-bash/chunks/{chunk-3HQU4OJO.js → chunk-XNGVOSGI.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-J42RIHHJ.js → chunk-XQWCQSRN.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-BJA5XNP6.js → chunk-Y7FW6GLT.js} +6 -6
- package/dist/safe-bash/chunks/{chunk-QGUV42T5.js → chunk-YL3GBUG4.js} +1 -1
- package/dist/safe-bash/chunks/chunk-YOXUCJER.js +389 -0
- package/dist/safe-bash/chunks/{chunk-HBCN24ZA.js → chunk-Z2AAYYJN.js} +2 -2
- package/dist/safe-bash/chunks/chunk-ZKYKJCZZ.js +30 -0
- package/dist/safe-bash/chunks/core-IE3AFIDX.js +85806 -0
- package/dist/safe-bash/chunks/{ffmpeg-WTC3TEFI.js → ffmpeg-YANDK6HU.js} +2 -2
- package/dist/safe-bash/chunks/{gh-6WU6PXL4.js → gh-4MBJ2S5V.js} +2 -2
- package/dist/safe-bash/chunks/{git-EFZIGJW4.js → git-2QONJNRQ.js} +2 -2
- package/dist/safe-bash/chunks/{imagemagick-EIEYGWPF.js → imagemagick-JLEHGYSN.js} +2 -2
- package/dist/safe-bash/chunks/{mmdc-ROQJT5HQ.js → mmdc-6LD7A6ND.js} +2 -2
- package/dist/safe-bash/chunks/{pdfimages-DW7LWXFI.js → pdfimages-RSHL7LOP.js} +2 -2
- package/dist/safe-bash/chunks/{pdfinfo-TIP6XLUQ.js → pdfinfo-L3SGWPNG.js} +2 -2
- package/dist/safe-bash/chunks/{pdftk-DMG22ITZ.js → pdftk-LFBJNU5A.js} +2 -2
- package/dist/safe-bash/chunks/{pdftoppm-WNDYR72T.js → pdftoppm-NXXFUIHG.js} +2 -2
- package/dist/safe-bash/chunks/{pdftotext-5IPZ4NI7.js → pdftotext-4IHNWT6F.js} +2 -2
- package/dist/safe-bash/chunks/{qpdf-TTX2DIUA.js → qpdf-ZEIREV63.js} +2 -2
- package/dist/safe-bash/chunks/read-builtin-A4QKAT45.js +9 -0
- package/dist/safe-bash/chunks/{sips-XYS46JPJ.js → sips-D5YBG2V3.js} +2 -2
- package/dist/safe-bash/chunks/{soffice-TU73E5KL.js → soffice-RAJU3JUT.js} +2 -2
- package/dist/safe-bash/chunks/source-files-3XWRRHFA.js +7 -0
- package/dist/safe-bash/chunks/{wkhtmltopdf-FSZ2CHGE.js → wkhtmltopdf-7UE4FORZ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-7KWZXKY6.js → chunk-26RTBV2I.js} +1 -0
- package/dist/safe-bash/command-chunks/{chunk-AQJ2ROJO.js → chunk-2WYNMZR2.js} +10 -8
- package/dist/safe-bash/command-chunks/{chunk-BDSMROQZ.js → chunk-36GFRF2N.js} +2 -1
- package/dist/safe-bash/command-chunks/{chunk-GC5TJZOF.js → chunk-3VIA2IA7.js} +114 -31
- package/dist/safe-bash/command-chunks/{chunk-NKFYQSES.js → chunk-4CTI3ZTX.js} +1 -0
- package/dist/safe-bash/command-chunks/{chunk-WH627NJL.js → chunk-4MYP2FX4.js} +2 -1
- package/dist/safe-bash/command-chunks/chunk-4R5ADJM5.js +178 -0
- package/dist/safe-bash/command-chunks/{chunk-P2N33UMN.js → chunk-5MIKM54M.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-DB453IE6.js → chunk-6FZQUOSJ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WPYIOKE3.js → chunk-6GKYHPJG.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-7K6JYKPJ.js → chunk-6M2ELGEN.js} +17 -15
- package/dist/safe-bash/command-chunks/{chunk-PXEIT2O4.js → chunk-6UR7V3ET.js} +8 -1
- package/dist/safe-bash/command-chunks/{chunk-6KJ3LPI2.js → chunk-6XBS5B46.js} +26 -3
- package/dist/safe-bash/command-chunks/{chunk-5PWJG2UK.js → chunk-6YXLZX7L.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-EK6YNAXT.js → chunk-753YOR54.js} +31 -5
- package/dist/safe-bash/command-chunks/{chunk-RMWQAAO5.js → chunk-7IR4NRNE.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-FZTK4MFI.js → chunk-7NM73SVK.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-NXEQ3ESQ.js → chunk-7QD5YY4F.js} +6 -11
- package/dist/safe-bash/command-chunks/{chunk-EMPU65ZK.js → chunk-A5LBSJGH.js} +1 -0
- package/dist/safe-bash/command-chunks/chunk-A7MU7762.js +200 -0
- package/dist/safe-bash/command-chunks/{chunk-ORYGZYKW.js → chunk-ARZMP2L2.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-OQKC5ZU2.js → chunk-BAKFZ477.js} +62 -20
- package/dist/safe-bash/command-chunks/{chunk-QRRYN2KO.js → chunk-BC7BK6R6.js} +0 -2424
- package/dist/safe-bash/command-chunks/{chunk-F4TEEZTL.js → chunk-BOEOJS2Q.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-XS72HTMA.js → chunk-BWGGLYEB.js} +5 -22
- package/dist/safe-bash/command-chunks/{chunk-PMBFZXTK.js → chunk-C5ZZKP7V.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-LHIOAFWW.js → chunk-C7SEB6WU.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-XPT2UGBF.js → chunk-CHJKFRT7.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-TIOCQVUQ.js → chunk-CON26Q2O.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-E55UKBIE.js → chunk-DBAT3IK2.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-Z45N42QC.js → chunk-DPAYAVMS.js} +15 -1
- package/dist/safe-bash/command-chunks/chunk-DS3NXVUM.js +368 -0
- package/dist/safe-bash/command-chunks/{chunk-5ZMZ573Q.js → chunk-DSJ3VRL3.js} +16 -4
- package/dist/safe-bash/command-chunks/{chunk-K2GDEMEU.js → chunk-EFRCFWVR.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-DZCY63VJ.js → chunk-EV6HIJ5H.js} +6 -5
- package/dist/safe-bash/command-chunks/{chunk-JDYXY44P.js → chunk-FJURV46Y.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-TZZ4WUKH.js → chunk-FZAWGKSE.js} +6 -4
- package/dist/safe-bash/command-chunks/{chunk-YHFXOX6U.js → chunk-GOCFQ6XV.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-YOFC45RK.js → chunk-HH5O7DJI.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-3HHCU5YU.js → chunk-HK7F5SDC.js} +13 -0
- package/dist/safe-bash/command-chunks/{chunk-JNZ3CVAE.js → chunk-HQBXIZC7.js} +8 -3
- package/dist/safe-bash/command-chunks/{chunk-2JRBIDAD.js → chunk-I63DBZXZ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-WNE7FPVR.js → chunk-I64TLTIW.js} +24 -16
- package/dist/safe-bash/command-chunks/{chunk-QKFSRZGQ.js → chunk-ICANWOXH.js} +7 -31
- package/dist/safe-bash/command-chunks/{chunk-SQRQW3CT.js → chunk-IJ6LGLXM.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-5E4WAO4O.js → chunk-JD5QNRNO.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-KJIMDLBB.js → chunk-JNANXVJV.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-TGSNCQSR.js → chunk-JT4RYCA6.js} +1771 -1663
- package/dist/safe-bash/command-chunks/{chunk-II77KPZN.js → chunk-JWW6FYBN.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-ZYXH3B66.js → chunk-LCJWKTCJ.js} +250 -203
- package/dist/safe-bash/command-chunks/{chunk-I237SNW5.js → chunk-LFJJQQND.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-LU4HBPP2.js +97 -0
- package/dist/safe-bash/command-chunks/{chunk-XJXU3VVH.js → chunk-LWOE65OE.js} +20 -5
- package/dist/safe-bash/command-chunks/{chunk-GMIHJYDG.js → chunk-M32HFSX7.js} +22 -6
- package/dist/safe-bash/command-chunks/{chunk-YG4EPFWC.js → chunk-M3NINRDU.js} +2880 -172
- package/dist/safe-bash/command-chunks/chunk-MQREDAL6.js +164 -0
- package/dist/safe-bash/command-chunks/{chunk-LWS62ISU.js → chunk-N6DIASO2.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-NGL7YK7O.js +188 -0
- package/dist/safe-bash/command-chunks/{chunk-PEF7K3UQ.js → chunk-NJYHWKIL.js} +40 -10
- package/dist/safe-bash/command-chunks/{chunk-VXSLJH7G.js → chunk-OJQRSCBP.js} +27 -7
- package/dist/safe-bash/command-chunks/{chunk-OQU6UT6X.js → chunk-OV3XREFN.js} +11 -0
- package/dist/safe-bash/command-chunks/{chunk-MIXBO6U7.js → chunk-PTZLF456.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-ALDC4XP4.js → chunk-QILLRNES.js} +34 -10
- package/dist/safe-bash/command-chunks/{chunk-L22T3H7L.js → chunk-QR25JLKO.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-7U7EXOXX.js → chunk-R7C4MGZ5.js} +17 -223
- package/dist/safe-bash/command-chunks/{chunk-LCF3OB7P.js → chunk-RBME3JEH.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-2KG2QLJE.js → chunk-RFWGYT7G.js} +3 -0
- package/dist/safe-bash/command-chunks/{chunk-5TBUOBDE.js → chunk-RZMVRT26.js} +27 -13
- package/dist/safe-bash/command-chunks/chunk-TFR6B3WB.js +44 -0
- package/dist/safe-bash/command-chunks/chunk-TOH3OF3O.js +179 -0
- package/dist/safe-bash/command-chunks/{chunk-VGG2DL5Q.js → chunk-TRR4MYWF.js} +4 -0
- package/dist/safe-bash/command-chunks/chunk-TT4DAFBT.js +13621 -0
- package/dist/safe-bash/command-chunks/{chunk-LWSBAWLT.js → chunk-TXI64OAG.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-TZRI7BJZ.js +496 -0
- package/dist/safe-bash/command-chunks/{chunk-QOKBZFFD.js → chunk-U3MMODA5.js} +2 -7
- package/dist/safe-bash/command-chunks/{chunk-ZYHTWNAE.js → chunk-UAW423ZL.js} +11 -11
- package/dist/safe-bash/command-chunks/{chunk-C5YYCQHW.js → chunk-UXEEUGOV.js} +222 -12
- package/dist/safe-bash/command-chunks/{chunk-GY3BWK7K.js → chunk-VOZPMJRX.js} +87 -80
- package/dist/safe-bash/command-chunks/{chunk-MQFIPHIQ.js → chunk-WPANOB4A.js} +38 -35
- package/dist/safe-bash/command-chunks/{chunk-Y2WBSJG6.js → chunk-X4QZQI5Q.js} +65 -64
- package/dist/safe-bash/command-chunks/{chunk-FPVUD6TH.js → chunk-XGI57GCN.js} +10 -8
- package/dist/safe-bash/command-chunks/{chunk-5UBXNSFZ.js → chunk-XUCU7QQT.js} +1281 -1278
- package/dist/safe-bash/command-chunks/chunk-Y22VXJBD.js +296 -0
- package/dist/safe-bash/command-chunks/{chunk-WVHONVZ4.js → chunk-YMFUUPDX.js} +5 -3
- package/dist/safe-bash/command-chunks/{chunk-IR2BY7EL.js → chunk-YYGIBXFZ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-MSFXC3OC.js → chunk-Z4FO6OHE.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-6GWJUQAV.js → chunk-Z5ZZVDUD.js} +181 -133
- package/dist/safe-bash/command-chunks/{chunk-W5DNF4JH.js → chunk-ZHN3QDCI.js} +1 -1
- package/dist/safe-bash/commands/alias/index.d.ts +2 -0
- package/dist/safe-bash/commands/alias/index.js +2 -0
- package/dist/safe-bash/commands/apply-patch/index.browser.js +2 -3
- package/dist/safe-bash/commands/apply-patch/index.d.ts +0 -1
- package/dist/safe-bash/commands/apply-patch/index.js +0 -1
- package/dist/safe-bash/commands/archive/index.browser.js +2 -3
- package/dist/safe-bash/commands/archive/index.d.ts +0 -1
- package/dist/safe-bash/commands/archive/index.js +0 -1
- package/dist/safe-bash/commands/bytes/compression/index.js +54 -51
- package/dist/safe-bash/commands/bytes/index.js +2 -1
- package/dist/safe-bash/commands/chmod/index.browser.js +14 -0
- package/dist/safe-bash/commands/chmod/index.d.ts +2 -0
- package/dist/safe-bash/commands/chmod/index.js +2 -0
- package/dist/safe-bash/commands/column/index.browser.js +2 -3
- package/dist/safe-bash/commands/column/index.d.ts +0 -1
- package/dist/safe-bash/commands/column/index.js +0 -1
- package/dist/safe-bash/commands/copy-source.js +1 -0
- package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
- package/dist/safe-bash/commands/csvkit/index.browser.js +72 -0
- package/dist/safe-bash/commands/csvkit/index.d.ts +0 -5
- package/dist/safe-bash/commands/csvkit/index.js +0 -50
- package/dist/safe-bash/commands/docx/index.browser.js +5 -7
- package/dist/safe-bash/commands/du/index.browser.js +2 -3
- package/dist/safe-bash/commands/du/index.d.ts +0 -1
- package/dist/safe-bash/commands/du/index.js +0 -1
- package/dist/safe-bash/commands/expr/index.browser.js +2 -3
- package/dist/safe-bash/commands/expr/index.d.ts +0 -1
- package/dist/safe-bash/commands/expr/index.js +0 -1
- package/dist/safe-bash/commands/factor/index.browser.js +2 -2
- package/dist/safe-bash/commands/file/index.browser.js +2 -3
- package/dist/safe-bash/commands/file/index.d.ts +0 -1
- package/dist/safe-bash/commands/file/index.js +0 -1
- package/dist/safe-bash/commands/filesystem.js +1 -1
- package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
- package/dist/safe-bash/commands/grep-aliases/index.browser.js +3 -3
- package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
- package/dist/safe-bash/commands/html-to-markdown/index.browser.js +2 -3
- package/dist/safe-bash/commands/html-to-markdown/index.d.ts +0 -1
- package/dist/safe-bash/commands/html-to-markdown/index.js +0 -1
- package/dist/safe-bash/commands/htmlq/index.d.ts +1 -5
- package/dist/safe-bash/commands/htmlq/index.js +1 -143
- 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/index.browser.js +2 -2
- package/dist/safe-bash/commands/llm/providers/index.browser.js +1 -1
- package/dist/safe-bash/commands/mdq/index.browser.js +3 -3
- package/dist/safe-bash/commands/media/index.browser.js +4 -16314
- package/dist/safe-bash/commands/media/index.d.ts +1 -5
- package/dist/safe-bash/commands/media/index.js +1 -3
- package/dist/safe-bash/commands/media/plugin.d.ts +1 -18
- package/dist/safe-bash/commands/media/plugin.js +1 -90
- package/dist/safe-bash/commands/media/remote.d.ts +1 -63
- package/dist/safe-bash/commands/media/remote.js +1 -405
- package/dist/safe-bash/commands/media/settings.d.ts +1 -4
- package/dist/safe-bash/commands/media/settings.js +1 -26
- package/dist/safe-bash/commands/metadata/chmod.d.ts +1 -7
- package/dist/safe-bash/commands/metadata/chmod.js +1 -204
- package/dist/safe-bash/commands/metadata/index.browser.js +3 -8
- package/dist/safe-bash/commands/metadata/index.d.ts +0 -1
- package/dist/safe-bash/commands/metadata/index.js +2 -2
- package/dist/safe-bash/commands/metadata/internal.d.ts +1 -30
- package/dist/safe-bash/commands/metadata/internal.js +1 -76
- package/dist/safe-bash/commands/metadata/mktemp.d.ts +1 -3
- package/dist/safe-bash/commands/metadata/mktemp.js +1 -202
- package/dist/safe-bash/commands/metadata/stat.d.ts +1 -7
- package/dist/safe-bash/commands/metadata/stat.js +1 -530
- package/dist/safe-bash/commands/mktemp/index.browser.js +13 -0
- package/dist/safe-bash/commands/mktemp/index.d.ts +2 -0
- package/dist/safe-bash/commands/mktemp/index.js +2 -0
- package/dist/safe-bash/commands/network/curl.js +1 -3
- package/dist/safe-bash/commands/network/index.browser.js +3 -4
- package/dist/safe-bash/commands/network/public.d.ts +0 -1
- package/dist/safe-bash/commands/network/public.js +0 -1
- package/dist/safe-bash/commands/network/transport.js +2 -1
- package/dist/safe-bash/commands/network/wget.js +1 -3
- package/dist/safe-bash/commands/node/browser.d.ts +0 -1
- package/dist/safe-bash/commands/node/browser.js +0 -1
- package/dist/safe-bash/commands/node/default-runtime.d.ts +3 -0
- package/dist/safe-bash/commands/node/default-runtime.js +15 -0
- package/dist/safe-bash/commands/node/index.browser.js +7 -8
- package/dist/safe-bash/commands/node/index.js +3 -3
- package/dist/safe-bash/commands/node/path.js +1 -1
- package/dist/safe-bash/commands/node/preload.d.ts +1 -1
- package/dist/safe-bash/commands/node/preload.js +4 -1
- package/dist/safe-bash/commands/node/quickjs.d.ts +2 -0
- package/dist/safe-bash/commands/node/quickjs.js +2 -0
- package/dist/safe-bash/commands/node/safejs.js +26 -12
- package/dist/safe-bash/commands/op/index.browser.js +2 -3
- package/dist/safe-bash/commands/op/index.d.ts +0 -11
- package/dist/safe-bash/commands/op/index.js +0 -84
- package/dist/safe-bash/commands/pandoc/index.browser.js +44 -0
- package/dist/safe-bash/commands/pandoc/index.d.ts +0 -1
- package/dist/safe-bash/commands/pandoc/index.js +0 -1
- package/dist/safe-bash/commands/portable-random.d.ts +1 -1
- package/dist/safe-bash/commands/portable-random.js +1 -12
- package/dist/safe-bash/commands/pr/index.browser.js +2 -2
- package/dist/safe-bash/commands/python/docker-runner.js +4 -3
- package/dist/safe-bash/commands/python/docker.d.ts +1 -0
- package/dist/safe-bash/commands/python/docker.js +5 -2
- package/dist/safe-bash/commands/python/index.browser.js +17 -13
- package/dist/safe-bash/commands/python/index.d.ts +2 -1
- package/dist/safe-bash/commands/python/index.js +10 -8
- package/dist/safe-bash/commands/python/llm-capability.js +65 -2
- package/dist/safe-bash/commands/python/llm-dependencies.d.ts +27 -0
- package/dist/safe-bash/commands/python/llm-dependencies.js +66 -0
- package/dist/safe-bash/commands/python/llm-module.js +6 -4
- package/dist/safe-bash/commands/python/llm-reference-module.d.ts +3 -0
- package/dist/safe-bash/commands/python/llm-reference-module.js +690 -0
- package/dist/safe-bash/commands/python/worker.browser.js +2 -3
- package/dist/safe-bash/commands/python/worker.d.ts +0 -1
- package/dist/safe-bash/commands/python/worker.js +0 -1
- package/dist/safe-bash/commands/regex-execution/ere/transport/wire-engine.d.ts +1 -1
- package/dist/safe-bash/commands/regex-execution/ere/transport/wire-engine.js +3 -3
- package/dist/safe-bash/commands/regex-execution/public.browser.js +7 -7
- package/dist/safe-bash/commands/safejs/options.js +5 -1
- package/dist/safe-bash/commands/safejs/runtime.d.ts +1 -0
- package/dist/safe-bash/commands/safejs/runtime.js +1 -1
- package/dist/safe-bash/commands/split/index.browser.js +2 -3
- package/dist/safe-bash/commands/split/index.d.ts +0 -1
- package/dist/safe-bash/commands/split/index.js +0 -1
- package/dist/safe-bash/commands/ssconvert/index.browser.js +98 -0
- package/dist/safe-bash/commands/stat/index.browser.js +13 -0
- package/dist/safe-bash/commands/stat/index.d.ts +2 -0
- package/dist/safe-bash/commands/stat/index.js +2 -0
- package/dist/safe-bash/commands/stream-format/index.browser.js +3 -4
- package/dist/safe-bash/commands/stream-format/index.d.ts +0 -1
- package/dist/safe-bash/commands/stream-format/index.js +0 -1
- package/dist/safe-bash/commands/stream-inspection/index.browser.js +3 -4
- package/dist/safe-bash/commands/stream-inspection/index.d.ts +0 -1
- package/dist/safe-bash/commands/stream-inspection/index.js +0 -1
- package/dist/safe-bash/commands/streams.js +2 -1
- package/dist/safe-bash/commands/table-text/index.browser.js +3 -4
- package/dist/safe-bash/commands/table-text/index.d.ts +0 -1
- package/dist/safe-bash/commands/table-text/index.js +0 -1
- package/dist/safe-bash/commands/text.js +74 -34
- package/dist/safe-bash/commands/time-env/index.browser.js +3 -4
- package/dist/safe-bash/commands/time-env/index.d.ts +0 -1
- package/dist/safe-bash/commands/time-env/index.js +0 -1
- package/dist/safe-bash/commands/tree/index.browser.js +2 -3
- package/dist/safe-bash/commands/tree/index.d.ts +0 -1
- package/dist/safe-bash/commands/tree/index.js +0 -1
- package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
- package/dist/safe-bash/commands/unalias/index.d.ts +2 -0
- package/dist/safe-bash/commands/unalias/index.js +2 -0
- package/dist/safe-bash/commands/xml/index.browser.js +2 -2
- package/dist/safe-bash/commands/yq/index.browser.js +2 -2
- package/dist/safe-bash/core.browser.js +2 -2
- package/dist/safe-bash/core.d.ts +7 -1
- package/dist/safe-bash/core.js +7 -1
- package/dist/safe-bash/execution-runtime.js +2 -1
- package/dist/safe-bash/fs/s3/http/index.d.ts +2 -2
- package/dist/safe-bash/fs/s3/http/index.js +1 -1
- package/dist/safe-bash/full-core.browser.js +254 -916
- package/dist/safe-bash/internal/op/types.d.ts +1 -0
- package/dist/safe-bash/jobs.browser.js +5 -5
- package/dist/safe-bash/lazy-optional.d.ts +3 -3
- package/dist/safe-bash/lazy-optional.js +1 -1
- package/dist/safe-bash/opt-in/commands/cmp/index.js +7 -6
- package/dist/safe-bash/opt-in/commands/dd/index.js +1 -1
- package/dist/safe-bash/opt-in/commands/dd/io.js +51 -5
- package/dist/safe-bash/opt-in/commands/truncate/index.js +2 -2
- package/dist/safe-bash/opt-in/commands/yq/native-work.js +3 -0
- package/dist/safe-bash/opt-in/optional/commands/shuf/input.js +2 -1
- package/dist/safe-bash/opt-in/optional/commands/shuf/shuf.js +4 -2
- package/dist/safe-bash/opt-in/optional.d.ts +1 -1
- package/dist/safe-bash/opt-in/optional.js +1 -1
- package/dist/safe-bash/opt-in/shell/extensions/read/index.js +2 -344
- package/dist/safe-bash/optional-host.browser.js +19 -14
- package/dist/safe-bash/optional-host.d.ts +1 -0
- package/dist/safe-bash/optional-host.js +1 -0
- package/dist/safe-bash/playwright/controller.js +41 -3
- package/dist/safe-bash/playwright/native-storage-targets.js +4 -2
- package/dist/safe-bash/plugins/base.d.ts +1 -1
- package/dist/safe-bash/plugins/base.js +3 -3
- package/dist/safe-bash/plugins/composition.d.ts +5 -2
- package/dist/safe-bash/plugins/composition.js +10 -7
- package/dist/safe-bash/plugins/index.browser.js +44 -41
- package/dist/safe-bash/plugins/index.js +3 -2
- package/dist/safe-bash/plugins/portable-commands.d.ts +3 -0
- package/dist/safe-bash/plugins/portable-commands.js +31 -0
- package/dist/safe-bash/registry-entry.browser.js +41 -42
- package/dist/safe-bash/search.browser.js +32 -33
- package/dist/safe-bash/shell/arithmetic.js +19 -6
- package/dist/safe-bash/shell/arrays/state.js +1 -1
- package/dist/safe-bash/shell/arrays/syntax.js +4 -3
- package/dist/safe-bash/shell/index.d.ts +0 -1
- package/dist/safe-bash/shell/index.js +0 -1
- package/dist/safe-bash/shell/parser.d.ts +2 -2
- package/dist/safe-bash/shell/parser.js +268 -64
- package/dist/safe-bash/shell/read-builtin.d.ts +3 -0
- package/dist/safe-bash/shell/read-builtin.js +344 -0
- package/dist/safe-bash/shell/runtime.d.ts +24 -4
- package/dist/safe-bash/shell/runtime.js +392 -414
- package/dist/safe-bash/shell/session-state.js +25 -0
- package/dist/safe-bash/shell/shell.js +76 -154
- package/dist/safe-bash/shell/tilde-expansion.d.ts +1 -1
- package/dist/safe-bash/shell/tilde-expansion.js +2 -2
- package/dist/safe-bash/shell/types.d.ts +7 -0
- package/dist/safe-bash/shell/value-state.js +1 -1
- package/dist/safe-bash/shell/worker-limits.js +1 -0
- package/dist/safe-bash/shell-entry.browser.js +32 -33
- package/dist/safe-bash/trap.browser.js +4 -4
- package/dist/safe-bash/worker/host.js +1 -1
- package/dist/safe-bash/yq-browser/index.js +1 -1
- package/dist/safe-bash-calendar-engine/time-env/calendar.d.ts +1 -1
- package/dist/safe-bash-calendar-engine/time-env/calendar.js +1 -1
- package/dist/safe-bash-calendar-engine/time-env/format.js +1 -1
- package/dist/safe-bash-command-alias/index.d.ts +13 -0
- package/dist/safe-bash-command-alias/index.js +88 -0
- package/dist/safe-bash-command-apply-patch/apply.js +3 -3
- package/dist/safe-bash-command-apply-patch/index.js +3 -3
- package/dist/safe-bash-command-apply-patch/matcher.js +1 -1
- package/dist/safe-bash-command-apply-patch/parser.js +1 -1
- package/dist/safe-bash-command-awk/awk-pipes.js +2 -2
- package/dist/safe-bash-command-awk/awk-reader.js +1 -1
- package/dist/safe-bash-command-awk/awk-runtime.js +3 -3
- package/dist/safe-bash-command-awk/awk.js +5 -5
- package/dist/safe-bash-command-awk/index.js +5 -5
- package/dist/safe-bash-command-bc/index.js +218 -65
- package/dist/safe-bash-command-bzip2/index.js +4 -3
- package/dist/safe-bash-command-chmod/LICENSE +21 -0
- package/dist/safe-bash-command-chmod/command.d.ts +7 -0
- package/dist/safe-bash-command-chmod/command.js +11 -0
- package/dist/safe-bash-command-chmod/index.d.ts +6 -0
- package/dist/safe-bash-command-chmod/index.js +27 -0
- package/dist/safe-bash-command-cmp/index.js +7 -6
- package/dist/safe-bash-command-column/column.js +3 -3
- package/dist/safe-bash-command-column/index.js +3 -3
- package/dist/safe-bash-command-column/layout.js +2 -2
- package/dist/safe-bash-command-csvkit/index.d.ts +1 -0
- package/dist/safe-bash-command-csvkit/index.js +1505 -7
- package/dist/safe-bash-command-csvkit/sync-support.js +2 -7
- package/dist/safe-bash-command-curl/curl.js +1 -1
- package/dist/safe-bash-command-curl/index.js +1 -1
- package/dist/safe-bash-command-date/date.js +1 -1
- package/dist/safe-bash-command-date/index.js +1 -1
- package/dist/safe-bash-command-dd/index.js +1 -1
- package/dist/safe-bash-command-dd/io.js +51 -5
- package/dist/safe-bash-command-diff/diff.js +1 -1
- package/dist/safe-bash-command-diff/index.js +1 -1
- package/dist/safe-bash-command-diff3/index.js +10 -13
- package/dist/safe-bash-command-exiftool/index.js +283 -55
- package/dist/safe-bash-command-exiftool/registry.d.ts +4 -2
- package/dist/safe-bash-command-factor/command.js +2 -2
- package/dist/safe-bash-command-factor/index.js +2 -2
- package/dist/safe-bash-command-fd/arguments.d.ts +2 -0
- package/dist/safe-bash-command-fd/index.js +42 -12
- package/dist/safe-bash-command-ffmpeg/index.js +356 -66
- package/dist/safe-bash-command-find/find-format.d.ts +3 -0
- package/dist/safe-bash-command-find/find-format.js +1 -1
- package/dist/safe-bash-command-find/find.js +2 -2
- package/dist/safe-bash-command-find/index.js +2 -2
- package/dist/safe-bash-command-fmt/index.js +10 -6
- package/dist/safe-bash-command-fold/engine.d.ts +1 -1
- package/dist/safe-bash-command-fold/family.js +2 -2
- package/dist/safe-bash-command-fold/index.js +1 -1
- package/dist/safe-bash-command-gzip/index.js +45 -42
- package/dist/safe-bash-command-hexdump/command.js +2 -2
- package/dist/safe-bash-command-hexdump/index.js +2 -2
- package/dist/safe-bash-command-html-to-markdown/entities.js +1 -1
- package/dist/safe-bash-command-html-to-markdown/index.js +4 -4
- package/dist/safe-bash-command-html-to-markdown/input.js +3 -3
- package/dist/safe-bash-command-html-to-markdown/parser.js +2 -2
- package/dist/safe-bash-command-html-to-markdown/render.js +3 -3
- package/dist/safe-bash-command-htmlq/contracts.d.ts +5 -2
- package/dist/safe-bash-command-htmlq/index.d.ts +2 -1
- package/dist/safe-bash-command-htmlq/index.js +175 -49
- package/dist/safe-bash-command-htmlq/sync.d.ts +1 -0
- package/dist/safe-bash-command-imagemagick/index.js +59 -7
- package/dist/safe-bash-command-install/arguments.d.ts +27 -0
- package/dist/safe-bash-command-install/arguments.js +224 -0
- package/dist/safe-bash-command-install/index.d.ts +7 -0
- package/dist/safe-bash-command-install/index.js +942 -0
- package/dist/safe-bash-command-install/mode.d.ts +6 -0
- package/dist/safe-bash-command-install/mode.js +71 -0
- package/dist/safe-bash-command-install/options.d.ts +40 -0
- package/dist/safe-bash-command-install/options.js +27 -0
- package/dist/safe-bash-command-jq/index.js +1 -1
- package/dist/safe-bash-command-jq/jq.js +1 -1
- package/dist/safe-bash-command-less/index.js +42 -57
- package/dist/safe-bash-command-llm/command.js +1 -1
- package/dist/safe-bash-command-llm/elevenlabs.js +2 -2
- package/dist/safe-bash-command-llm/index.js +4 -4
- package/dist/safe-bash-command-llm/openai.js +2 -2
- package/dist/safe-bash-command-llm/providers/elevenlabs.js +2 -2
- package/dist/safe-bash-command-llm/providers/index.js +3 -3
- package/dist/safe-bash-command-llm/providers/openai.js +2 -2
- package/dist/safe-bash-command-llm/providers/shared.js +1 -1
- package/dist/{safe-bash-mcp → safe-bash-command-mcp}/index.browser.d.ts +463 -46
- package/dist/safe-bash-command-mcp/index.browser.js +19308 -0
- package/dist/{safe-bash-mcp → safe-bash-command-mcp}/index.d.ts +15 -6
- package/dist/{safe-bash-mcp → safe-bash-command-mcp}/index.js +2835 -2783
- package/dist/safe-bash-command-media/LICENSE +21 -0
- package/dist/safe-bash-command-media/index.d.ts +6 -0
- package/dist/safe-bash-command-media/index.js +30 -0
- package/dist/safe-bash-command-media/plugin.d.ts +18 -0
- package/dist/safe-bash-command-media/plugin.js +11 -0
- package/dist/safe-bash-command-media/remote.d.ts +63 -0
- package/dist/safe-bash-command-media/remote.js +11 -0
- package/dist/safe-bash-command-media/settings.d.ts +4 -0
- package/dist/safe-bash-command-media/settings.js +41 -0
- package/dist/safe-bash-command-mktemp/LICENSE +21 -0
- package/dist/safe-bash-command-mktemp/command.d.ts +3 -0
- package/dist/safe-bash-command-mktemp/command.js +9 -0
- package/dist/safe-bash-command-mktemp/index.d.ts +6 -0
- package/dist/safe-bash-command-mktemp/index.js +25 -0
- package/dist/safe-bash-command-mmdc/arguments.d.ts +1 -0
- package/dist/safe-bash-command-mmdc/command.d.ts +2 -0
- package/dist/safe-bash-command-mmdc/contracts.d.ts +8 -1
- package/dist/safe-bash-command-mmdc/index.js +359 -7
- package/dist/safe-bash-command-nl/index.js +1 -1
- package/dist/safe-bash-command-nl/nl.js +1 -1
- package/dist/safe-bash-command-node/LICENSE +21 -0
- package/dist/safe-bash-command-node/index.d.ts +17 -0
- package/dist/safe-bash-command-node/index.js +328 -0
- package/dist/safe-bash-command-numfmt/index.js +1 -0
- package/dist/safe-bash-command-od/index.js +16 -8
- package/dist/safe-bash-command-op/index.js +62 -36
- package/dist/safe-bash-command-op/types.d.ts +1 -0
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.d.ts +1 -0
- package/dist/safe-bash-command-pandoc/index.js +5 -3
- package/dist/safe-bash-command-pandoc/sync.d.ts +1 -0
- package/dist/safe-bash-command-patch/index.js +4 -4
- package/dist/safe-bash-command-patch/patch.js +4 -4
- package/dist/safe-bash-command-pdfimages/index.js +1 -1
- package/dist/safe-bash-command-pdfinfo/index.js +30 -5
- package/dist/safe-bash-command-pdftk/index.js +21 -23
- package/dist/safe-bash-command-pdftoppm/index.js +17 -4
- package/dist/safe-bash-command-pdftotext/index.js +11 -14
- package/dist/safe-bash-command-qpdf/index.d.ts +1 -0
- package/dist/safe-bash-command-qpdf/index.js +9 -6
- package/dist/safe-bash-command-rg/index.js +1 -1
- package/dist/safe-bash-command-rg/rg-command.js +1 -1
- package/dist/safe-bash-command-sed/index.js +1 -1
- package/dist/safe-bash-command-sed/sed.js +1 -1
- package/dist/safe-bash-command-shuf/input.d.ts +2 -2
- package/dist/safe-bash-command-shuf/input.js +2 -1
- package/dist/safe-bash-command-shuf/shuf.js +4 -2
- package/dist/safe-bash-command-sips/index.js +15 -7
- package/dist/safe-bash-command-soffice/index.js +97 -12
- package/dist/safe-bash-command-sponge/index.js +13 -3
- package/dist/safe-bash-command-sqlite3/engine.d.ts +1 -0
- package/dist/safe-bash-command-sqlite3/index.js +510 -70
- package/dist/safe-bash-command-ssconvert/formats/xlsx.js +2 -2
- package/dist/safe-bash-command-ssconvert/index.js +44 -22
- package/dist/safe-bash-command-stat/LICENSE +21 -0
- package/dist/safe-bash-command-stat/command.d.ts +7 -0
- package/dist/safe-bash-command-stat/command.js +9 -0
- package/dist/safe-bash-command-stat/index.d.ts +6 -0
- package/dist/safe-bash-command-stat/index.js +25 -0
- package/dist/safe-bash-command-tar/create.d.ts +1 -0
- package/dist/safe-bash-command-tar/create.js +2 -2
- package/dist/safe-bash-command-tar/extract.js +2 -2
- package/dist/safe-bash-command-tar/index.js +4 -4
- package/dist/safe-bash-command-tar/modes.js +4 -4
- package/dist/safe-bash-command-tar/options.js +1 -1
- package/dist/safe-bash-command-truncate/index.js +2 -2
- package/dist/safe-bash-command-tsort/command.js +2 -2
- package/dist/safe-bash-command-tsort/index.js +2 -2
- package/dist/safe-bash-command-unalias/index.d.ts +12 -0
- package/dist/safe-bash-command-unalias/index.js +67 -0
- package/dist/safe-bash-command-unrtf/index.js +37 -5
- package/dist/safe-bash-command-xan/argv.d.ts +1 -1
- package/dist/safe-bash-command-xan/argv.js +2 -2
- package/dist/safe-bash-command-xan/budget.d.ts +0 -1
- package/dist/safe-bash-command-xan/budget.js +1 -1
- package/dist/safe-bash-command-xan/commands.js +6 -6
- package/dist/safe-bash-command-xan/csv.js +2 -2
- package/dist/safe-bash-command-xan/index.js +8 -9
- package/dist/safe-bash-command-xan/io.js +4 -4
- package/dist/safe-bash-command-xan/options.js +1 -1
- package/dist/safe-bash-command-xan/selector.js +2 -2
- package/dist/safe-bash-command-xmllint/index.js +45 -23
- package/dist/safe-bash-command-xxd/index.js +47 -12
- package/dist/safe-bash-command-xz/command.d.ts +1 -1
- package/dist/safe-bash-command-xz/index.js +3 -2
- package/dist/safe-bash-command-yq/accounting.js +1 -1
- package/dist/safe-bash-command-yq/index.js +4 -2
- package/dist/safe-bash-command-yq/native-work.js +3 -0
- package/dist/safe-bash-command-yq/parser.js +2 -2
- package/dist/safe-bash-command-yq/query.js +8 -5
- package/dist/safe-bash-command-yq/toml.js +2 -2
- package/dist/safe-bash-command-zip/index.js +3 -3
- 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/options.js +1 -1
- 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.js +2 -2
- package/dist/safe-bash-contracts/diagnostics.js +3 -3
- package/dist/safe-bash-contracts/escaping.js +6 -6
- package/dist/safe-bash-contracts/filesystem-descriptor.js +3 -3
- package/dist/safe-bash-contracts/filesystem-output.js +5 -5
- package/dist/safe-bash-contracts/http.d.ts +7 -0
- package/dist/safe-bash-contracts/index.js +8 -8
- package/dist/safe-bash-contracts/io.d.ts +2 -0
- package/dist/safe-bash-contracts/io.js +2 -2
- package/dist/safe-bash-contracts/output.js +3 -3
- package/dist/safe-bash-contracts/runtime-control.d.ts +2 -2
- package/dist/safe-bash-contracts/runtime-control.js +4 -2
- package/dist/safe-bash-contracts/signals.d.ts +2 -0
- package/dist/safe-bash-contracts/signals.js +3 -1
- package/dist/safe-bash-contracts/yield.js +1 -1
- package/dist/safe-bash-csv-engine/index.d.ts +2 -1
- package/dist/safe-bash-csv-engine/index.js +21 -15
- package/dist/safe-bash-io-engine/commands/search/requirements.js +2 -2
- package/dist/safe-bash-io-engine/commands/text-programs/shared.js +6 -6
- package/dist/safe-bash-io-engine/internal.js +1 -1
- package/dist/safe-bash-io-engine/shell/pattern.js +38 -18
- package/dist/safe-bash-line-ending-engine/convert.js +9 -204
- package/dist/safe-bash-line-ending-engine/encoding.js +9 -42
- package/dist/safe-bash-line-ending-engine/index.js +48 -0
- package/dist/safe-bash-line-ending-engine/info.js +9 -90
- package/dist/safe-bash-line-ending-engine/internal.js +15 -160
- package/dist/safe-bash-line-ending-engine/io.js +12 -289
- package/dist/safe-bash-line-ending-engine/stage.js +10 -160
- package/dist/safe-bash-markdown-engine/index.js +3 -3
- package/dist/safe-bash-metadata-engine/LICENSE +21 -0
- package/dist/safe-bash-metadata-engine/index.d.ts +30 -0
- package/dist/safe-bash-metadata-engine/index.js +82 -0
- package/dist/safe-bash-metadata-engine/random.d.ts +1 -0
- package/dist/safe-bash-metadata-engine/random.js +21 -0
- package/dist/safe-bash-network-engine/args.d.ts +6 -0
- package/dist/safe-bash-network-engine/args.js +4 -2
- package/dist/safe-bash-network-engine/body.js +1 -1
- package/dist/safe-bash-network-engine/fetch-transport.js +3 -1
- package/dist/safe-bash-network-engine/index.js +3 -1
- package/dist/safe-bash-network-engine/input.js +2 -2
- package/dist/safe-bash-network-engine/platform-portable.js +3 -1
- package/dist/safe-bash-query-engine/dates.d.ts +1 -1
- package/dist/safe-bash-query-engine/dates.js +1 -1
- package/dist/safe-bash-query-engine/index.js +6 -6
- package/dist/safe-bash-query-engine/interpreter.js +4 -4
- package/dist/safe-bash-query-engine/parser.js +1 -1
- package/dist/safe-bash-query-engine/query-core.js +6 -6
- package/dist/safe-bash-regex-engine/execution/bounded-provider.js +10 -0
- package/dist/safe-bash-regex-engine/index.js +1 -1
- package/dist/safe-bash-regex-engine/text/regex.d.ts +1 -1
- package/dist/safe-bash-regex-engine/text/regex.js +1 -1
- package/dist/safe-bash-search-engine/ergonomic-regex.d.ts +1 -0
- package/dist/safe-bash-search-engine/ergonomic-regex.js +2 -2
- package/dist/safe-bash-search-engine/glob.js +2 -2
- package/dist/safe-bash-search-engine/grep.js +17 -10
- package/dist/safe-bash-search-engine/matcher.d.ts +2 -2
- package/dist/safe-bash-search-engine/matcher.js +13 -9
- package/dist/safe-bash-search-engine/options.d.ts +2 -0
- package/dist/safe-bash-search-engine/options.js +1 -1
- package/dist/safe-bash-search-engine/output.js +1 -1
- package/dist/safe-bash-search-engine/shared.js +2 -2
- package/dist/safe-bash-search-engine/walk.js +15 -3
- package/dist/safe-bash-text-stream-engine/stream-format/shared.d.ts +1 -1
- package/dist/safe-bash-text-stream-engine/stream-format/shared.js +2 -1
- package/dist/safe-bash-xml-engine/document.js +3 -3
- package/dist/safe-bash-xml-engine/evaluate.js +2 -2
- package/dist/safe-bash-xml-engine/index.js +4 -4
- package/dist/safe-bash-xml-engine/io.js +7 -2
- package/dist/safe-bash-xml-engine/limits.d.ts +0 -2
- package/dist/safe-bash-xml-engine/limits.js +1 -1
- package/dist/safe-bash-xml-engine/query.js +3 -3
- package/dist/safe-bash-zip-engine/index.js +3 -3
- package/dist/safe-bash-zip-engine/zip/repair.js +3 -3
- package/dist/safe-bash-zip-engine/zip/safety.js +1 -1
- package/dist/safe-bash-zip-engine/zip/sfx.js +3 -3
- package/dist/safe-bash-zip-engine/zip/volumes.js +1 -1
- package/dist/safe-bash-zip-engine/zip-format.js +3 -3
- package/dist/safe-playwright-cloudflare/browser-snapshot-json.js +2 -2
- package/dist/safe-playwright-cloudflare/browser-snapshot-references.js +1 -1
- package/dist/safe-playwright-cloudflare/browser-socket-closure.js +18 -3
- package/dist/safe-playwright-cloudflare/shell-browser-resource.js +1 -1
- package/dist/xlsx-ast/xlsx.js +6 -5
- package/package.json +112 -98
- package/dist/media-cli/bytes.d.ts +0 -8
- package/dist/media-cli/bytes.js +0 -40
- package/dist/media-cli/concat.d.ts +0 -30
- package/dist/media-cli/concat.js +0 -197
- package/dist/media-cli/content.js +0 -66
- package/dist/media-cli/dependency-grammars.d.ts +0 -12
- package/dist/media-cli/dependency-grammars.js +0 -557
- package/dist/media-cli/discover.js +0 -286
- package/dist/media-cli/engine.js +0 -190
- package/dist/media-cli/filename-expression.js +0 -147
- package/dist/media-cli/filesystem.js +0 -35
- package/dist/media-cli/frontend-contract.js +0 -8
- package/dist/media-cli/frontend-issues.d.ts +0 -6
- package/dist/media-cli/frontend-issues.js +0 -9
- package/dist/media-cli/imagemagick-operand.d.ts +0 -42
- package/dist/media-cli/imagemagick-operand.js +0 -229
- package/dist/media-cli/imagemagick-references.d.ts +0 -7
- package/dist/media-cli/imagemagick-references.js +0 -42
- package/dist/media-cli/imagemagick.generated.js +0 -3254
- package/dist/media-cli/imagemagick.js +0 -615
- package/dist/media-cli/index.js +0 -12
- package/dist/media-cli/mvg.d.ts +0 -10
- package/dist/media-cli/mvg.js +0 -102
- package/dist/media-cli/network.js +0 -78
- package/dist/media-cli/options.generated.js +0 -3312
- package/dist/media-cli/preset.d.ts +0 -11
- package/dist/media-cli/preset.js +0 -57
- package/dist/media-cli/resolution-path.d.ts +0 -23
- package/dist/media-cli/resolution-path.js +0 -217
- package/dist/media-cli/resolver.js +0 -494
- package/dist/media-cli/resources.d.ts +0 -16
- package/dist/media-cli/resources.js +0 -187
- package/dist/media-cli/shim.js +0 -52
- package/dist/media-cli/tee.d.ts +0 -6
- package/dist/media-cli/tee.js +0 -38
- package/dist/office-package/zip-sync.js +0 -111
- package/dist/remote-execution/binary.js +0 -178
- package/dist/remote-execution/callback-result.js +0 -26
- package/dist/remote-execution/canonical-capabilities.d.ts +0 -5
- package/dist/remote-execution/canonical-capabilities.js +0 -45
- package/dist/remote-execution/canonical-metadata.d.ts +0 -4
- package/dist/remote-execution/canonical-metadata.js +0 -32
- package/dist/remote-execution/client.js +0 -824
- package/dist/remote-execution/deployment.js +0 -131
- package/dist/remote-execution/descriptors.js +0 -267
- package/dist/remote-execution/effects.js +0 -357
- package/dist/remote-execution/endpoint.js +0 -224
- package/dist/remote-execution/files.js +0 -291
- package/dist/remote-execution/hosting-operation.js +0 -26
- package/dist/remote-execution/hosting-request.d.ts +0 -4
- package/dist/remote-execution/hosting-request.js +0 -12
- package/dist/remote-execution/hosting-stream.d.ts +0 -8
- package/dist/remote-execution/hosting-stream.js +0 -64
- package/dist/remote-execution/index.js +0 -18
- package/dist/remote-execution/invocation-admission.d.ts +0 -3
- package/dist/remote-execution/invocation-admission.js +0 -17
- package/dist/remote-execution/job-binding.js +0 -1269
- package/dist/remote-execution/materializations.js +0 -284
- package/dist/remote-execution/modal-driver.js +0 -90
- package/dist/remote-execution/native-result.d.ts +0 -3
- package/dist/remote-execution/native-result.js +0 -16
- package/dist/remote-execution/output-freshness.d.ts +0 -4
- package/dist/remote-execution/output-freshness.js +0 -19
- package/dist/remote-execution/output-retrieval.js +0 -474
- package/dist/remote-execution/process-http.js +0 -607
- package/dist/remote-execution/process.js +0 -577
- package/dist/remote-execution/protocol.js +0 -208
- package/dist/remote-execution/relay.js +0 -91
- package/dist/remote-execution/rest-driver.js +0 -93
- package/dist/remote-execution/upload-descriptor.js +0 -201
- package/dist/remote-execution/upload-protocol.js +0 -62
- package/dist/remote-execution/uploads.js +0 -324
- package/dist/remote-execution/wire-json.d.ts +0 -4
- package/dist/remote-execution/wire-json.js +0 -44
- package/dist/remote-execution/wire-validation.js +0 -131
- package/dist/remote-execution/wire.generated.js +0 -4224
- package/dist/safe-bash/chunks/chunk-GETUOD5D.js +0 -161
- package/dist/safe-bash/chunks/chunk-IWDICZVK.js +0 -20
- package/dist/safe-bash/chunks/chunk-MHMMRCYC.js +0 -3464
- package/dist/safe-bash/chunks/chunk-UE5KZDEK.js +0 -77
- package/dist/safe-bash/chunks/chunk-VSAJ4OTM.js +0 -962
- package/dist/safe-bash/chunks/csvkit-TACDU7FC.js +0 -1618
- package/dist/safe-bash/chunks/implementation-MLFHUQ5M.js +0 -133
- package/dist/safe-bash/commands/csvkit/sync.js +0 -1639
- package/dist/safe-bash/commands/node/unconfigured.d.ts +0 -3
- package/dist/safe-bash/commands/node/unconfigured.js +0 -10
- package/dist/safe-bash/commands/pandoc/implementation.d.ts +0 -8
- package/dist/safe-bash/commands/pandoc/implementation.js +0 -94
- package/dist/safe-bash-mcp/index.browser.js +0 -9157
- package/dist/safe-bash/command-chunks/{chunk-ZRRBXU3M.js → chunk-GIN5GUDP.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-LAOM65EE.js → chunk-IEO4XVN6.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-364TMWBT.js → chunk-MWREVL44.js} +6 -6
- package/dist/safe-bash/command-chunks/{chunk-464RVBGB.js → chunk-Q5TDKFHK.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-AJR3AQYA.js → chunk-UKX3LZHR.js} +0 -0
- package/dist/safe-bash/command-chunks/{chunk-XIIBTGC5.js → chunk-XPXEQKRW.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-FDBUV4HJ.js → chunk-Y4HGTG3E.js} +3 -3
- /package/dist/{safe-bash/commands/csvkit → safe-bash-command-csvkit}/sync.d.ts +0 -0
|
@@ -1,47 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
affineImage,
|
|
3
|
-
applyExifOrientation,
|
|
4
|
-
bandboolImage,
|
|
5
|
-
blurImage,
|
|
6
|
-
booleanImage,
|
|
7
|
-
claheImage,
|
|
8
|
-
compositeImage,
|
|
9
|
-
computeImageStats,
|
|
10
|
-
convolveImage,
|
|
11
|
-
decodeImage,
|
|
12
|
-
dilateImage,
|
|
13
|
-
encodeImage,
|
|
14
|
-
ensureAlphaImage,
|
|
15
|
-
erodeImage,
|
|
16
|
-
extendImage,
|
|
17
|
-
extractChannelImage,
|
|
18
|
-
extractImage,
|
|
19
|
-
flattenImage,
|
|
20
|
-
flipImage,
|
|
21
|
-
flopImage,
|
|
22
|
-
gammaImage,
|
|
23
|
-
grayscaleImage,
|
|
24
|
-
joinChannelImage,
|
|
25
|
-
linearImage,
|
|
26
|
-
medianImage,
|
|
27
|
-
modulateImage,
|
|
28
|
-
negateImage,
|
|
29
|
-
normalizeImage,
|
|
30
|
-
parseColor,
|
|
31
|
-
premultiplyRgbaImage,
|
|
32
|
-
readImageMetadata,
|
|
33
|
-
recombImage,
|
|
34
|
-
removeAlphaImage,
|
|
35
|
-
resizeImage,
|
|
36
|
-
rotateImage,
|
|
37
|
-
sharpenImage,
|
|
38
|
-
thresholdImage,
|
|
39
|
-
tintImage,
|
|
40
|
-
toColorspaceImage,
|
|
41
|
-
trimImage,
|
|
42
|
-
unflattenImage,
|
|
43
|
-
unpremultiplyRgbaImage
|
|
44
|
-
} from "./chunk-YG4EPFWC.js";
|
|
45
1
|
import {
|
|
46
2
|
init_buffer
|
|
47
3
|
} from "./chunk-HX3SHTCE.js";
|
|
@@ -49,2386 +5,6 @@ import {
|
|
|
49
5
|
// packages/image-ast/src/index.ts
|
|
50
6
|
init_buffer();
|
|
51
7
|
|
|
52
|
-
// packages/image-ast/src/sharp.ts
|
|
53
|
-
init_buffer();
|
|
54
|
-
|
|
55
|
-
// packages/image-ast/src/streams/web.ts
|
|
56
|
-
init_buffer();
|
|
57
|
-
var outputBytes = Uint8Array.from.bind(Uint8Array);
|
|
58
|
-
var isBuffer = (_input) => false;
|
|
59
|
-
var EventEmitter = class {
|
|
60
|
-
listeners = /* @__PURE__ */ new Map();
|
|
61
|
-
on(event, listener) {
|
|
62
|
-
let listeners = this.listeners.get(event);
|
|
63
|
-
if (!listeners) this.listeners.set(event, listeners = /* @__PURE__ */ new Set());
|
|
64
|
-
listeners.add(listener);
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
once(event, listener) {
|
|
68
|
-
const once = (...args) => {
|
|
69
|
-
this.removeListener(event, once);
|
|
70
|
-
listener(...args);
|
|
71
|
-
};
|
|
72
|
-
return this.on(event, once);
|
|
73
|
-
}
|
|
74
|
-
removeListener(event, listener) {
|
|
75
|
-
this.listeners.get(event)?.delete(listener);
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
emit(event, ...args) {
|
|
79
|
-
const listeners = [...this.listeners.get(event) ?? []];
|
|
80
|
-
for (const listener of listeners) listener(...args);
|
|
81
|
-
return listeners.length > 0;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
var Duplex = class extends EventEmitter {
|
|
85
|
-
readable;
|
|
86
|
-
writable;
|
|
87
|
-
writableFinished = false;
|
|
88
|
-
controller;
|
|
89
|
-
closed = false;
|
|
90
|
-
constructor() {
|
|
91
|
-
super();
|
|
92
|
-
this.readable = new ReadableStream({
|
|
93
|
-
start: (controller) => {
|
|
94
|
-
this.controller = controller;
|
|
95
|
-
},
|
|
96
|
-
pull: () => {
|
|
97
|
-
this._read();
|
|
98
|
-
},
|
|
99
|
-
cancel: (reason) => {
|
|
100
|
-
this.destroy(reason instanceof Error ? reason : void 0);
|
|
101
|
-
}
|
|
102
|
-
}, { highWaterMark: 0 });
|
|
103
|
-
this.writable = new WritableStream({
|
|
104
|
-
write: (chunk) => new Promise((resolve, reject) => {
|
|
105
|
-
this._write(chunk, "utf8", (error) => {
|
|
106
|
-
if (error) {
|
|
107
|
-
this.destroy(error);
|
|
108
|
-
reject(error);
|
|
109
|
-
} else resolve();
|
|
110
|
-
});
|
|
111
|
-
}),
|
|
112
|
-
close: () => {
|
|
113
|
-
this.writableFinished = true;
|
|
114
|
-
this.emit("finish");
|
|
115
|
-
},
|
|
116
|
-
abort: (reason) => {
|
|
117
|
-
this.destroy(reason instanceof Error ? reason : void 0);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
_write(_chunk, _encoding, callback) {
|
|
122
|
-
callback(new Error("Writable operation is not implemented"));
|
|
123
|
-
}
|
|
124
|
-
_read() {
|
|
125
|
-
throw new Error("Readable operation is not implemented");
|
|
126
|
-
}
|
|
127
|
-
push(chunk) {
|
|
128
|
-
if (this.closed) return false;
|
|
129
|
-
if (chunk === null) {
|
|
130
|
-
this.closed = true;
|
|
131
|
-
this.controller.close();
|
|
132
|
-
} else this.controller.enqueue(new Uint8Array(chunk));
|
|
133
|
-
return (this.controller.desiredSize ?? 0) > 0;
|
|
134
|
-
}
|
|
135
|
-
destroy(error) {
|
|
136
|
-
if (!this.closed) {
|
|
137
|
-
this.closed = true;
|
|
138
|
-
this.controller.error(error ?? new Error("Stream cancelled"));
|
|
139
|
-
this.emit("error", error ?? new Error("Stream cancelled"));
|
|
140
|
-
}
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
async *[Symbol.asyncIterator]() {
|
|
144
|
-
const reader = this.readable.getReader();
|
|
145
|
-
try {
|
|
146
|
-
while (true) {
|
|
147
|
-
const result = await reader.read();
|
|
148
|
-
if (result.done) return;
|
|
149
|
-
yield result.value;
|
|
150
|
-
}
|
|
151
|
-
} finally {
|
|
152
|
-
await reader.cancel();
|
|
153
|
-
reader.releaseLock();
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
// packages/image-ast/src/sharp.ts
|
|
159
|
-
import { extname, normalizePath } from "@poe-platform/safe-fs/core";
|
|
160
|
-
function inferTypedArrayDepth(input) {
|
|
161
|
-
if (!input || !ArrayBuffer.isView(input)) return void 0;
|
|
162
|
-
if (input instanceof Int8Array) return "char";
|
|
163
|
-
if (input instanceof Uint16Array) return "ushort";
|
|
164
|
-
if (input instanceof Int16Array) return "short";
|
|
165
|
-
if (input instanceof Uint32Array) return "uint";
|
|
166
|
-
if (input instanceof Int32Array) return "int";
|
|
167
|
-
if (input instanceof Float32Array) return "float";
|
|
168
|
-
if (input instanceof Float64Array) return "double";
|
|
169
|
-
return "uchar";
|
|
170
|
-
}
|
|
171
|
-
function validateInputOptions(opts) {
|
|
172
|
-
if (!opts || typeof opts !== "object") return;
|
|
173
|
-
const anyOpts = opts;
|
|
174
|
-
if (anyOpts.failOnError !== void 0 && typeof anyOpts.failOnError !== "boolean") {
|
|
175
|
-
throw new Error(`Expected boolean for failOnError but received ${anyOpts.failOnError} of type ${typeof anyOpts.failOnError}`);
|
|
176
|
-
}
|
|
177
|
-
if (opts.failOn !== void 0 && !["none", "truncated", "error", "warning"].includes(opts.failOn)) {
|
|
178
|
-
throw new Error(`Expected one of: none, truncated, error, warning for failOn but received ${opts.failOn} of type ${typeof opts.failOn}`);
|
|
179
|
-
}
|
|
180
|
-
for (const boolKey of ["animated", "autoOrient", "sequentialRead", "unlimited", "ignoreIcc"]) {
|
|
181
|
-
if (anyOpts[boolKey] !== void 0 && typeof anyOpts[boolKey] !== "boolean") {
|
|
182
|
-
throw new Error(`Expected boolean for ${boolKey} but received ${anyOpts[boolKey]} of type ${typeof anyOpts[boolKey]}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (opts.density !== void 0 && (typeof opts.density !== "number" || Number.isNaN(opts.density) || opts.density < 1 || opts.density > 1e5)) {
|
|
186
|
-
throw new Error(`Expected number between 1 and 100000 for density but received ${opts.density} of type ${typeof opts.density}`);
|
|
187
|
-
}
|
|
188
|
-
if (opts.limitInputPixels !== void 0 && typeof opts.limitInputPixels !== "boolean" && (!Number.isInteger(opts.limitInputPixels) || opts.limitInputPixels < 0 || opts.limitInputPixels > Number.MAX_SAFE_INTEGER)) {
|
|
189
|
-
throw new Error(
|
|
190
|
-
`Expected positive integer for limitInputPixels but received ${opts.limitInputPixels} of type ${typeof opts.limitInputPixels}`
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
if (opts.page !== void 0 && (!Number.isInteger(opts.page) || opts.page < 0 || opts.page > 1e5)) {
|
|
194
|
-
throw new Error(`Expected integer between 0 and 100000 for page but received ${opts.page} of type ${typeof opts.page}`);
|
|
195
|
-
}
|
|
196
|
-
if (opts.pages !== void 0 && (!Number.isInteger(opts.pages) || opts.pages < -1 || opts.pages > 1e5)) {
|
|
197
|
-
throw new Error(`Expected integer between -1 and 100000 for pages but received ${opts.pages} of type ${typeof opts.pages}`);
|
|
198
|
-
}
|
|
199
|
-
if (opts.raw !== void 0) {
|
|
200
|
-
const raw = opts.raw;
|
|
201
|
-
if (!raw || typeof raw !== "object" || !Number.isInteger(raw.width) || raw.width <= 0 || !Number.isInteger(raw.height) || raw.height <= 0 || !Number.isInteger(raw.channels) || raw.channels < 1 || raw.channels > 4) {
|
|
202
|
-
throw new Error("Expected width, height and channels for raw pixel input");
|
|
203
|
-
}
|
|
204
|
-
if (raw.premultiplied !== void 0 && typeof raw.premultiplied !== "boolean") {
|
|
205
|
-
throw new Error(`Expected boolean for raw.premultiplied but received ${raw.premultiplied}`);
|
|
206
|
-
}
|
|
207
|
-
if (raw.pageHeight !== void 0) {
|
|
208
|
-
if (!Number.isInteger(raw.pageHeight) || raw.pageHeight <= 0 || raw.pageHeight > raw.height) {
|
|
209
|
-
throw new Error(`Expected positive integer for raw.pageHeight but received ${raw.pageHeight}`);
|
|
210
|
-
}
|
|
211
|
-
if (raw.height % raw.pageHeight !== 0) {
|
|
212
|
-
throw new Error(`Expected raw.height ${raw.height} to be a multiple of raw.pageHeight ${raw.pageHeight}`);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
const validAlignments = ["left", "top", "low", "center", "centre", "right", "bottom", "high"];
|
|
217
|
-
if (opts.join !== void 0) {
|
|
218
|
-
const join = opts.join;
|
|
219
|
-
if (join && typeof join === "object") {
|
|
220
|
-
if (join.across !== void 0 && (!Number.isInteger(join.across) || join.across < 1 || join.across > 1e5)) {
|
|
221
|
-
throw new Error(`Expected integer between 1 and 100000 for join.across but received ${join.across} of type ${typeof join.across}`);
|
|
222
|
-
}
|
|
223
|
-
if (join.shim !== void 0 && (!Number.isInteger(join.shim) || join.shim < 0 || join.shim > 1e5)) {
|
|
224
|
-
throw new Error(`Expected integer between 0 and 100000 for join.shim but received ${join.shim} of type ${typeof join.shim}`);
|
|
225
|
-
}
|
|
226
|
-
if (join.halign !== void 0 && !validAlignments.includes(join.halign)) {
|
|
227
|
-
throw new Error(`Expected valid alignment for join.halign but received ${join.halign} of type ${typeof join.halign}`);
|
|
228
|
-
}
|
|
229
|
-
if (join.valign !== void 0 && !validAlignments.includes(join.valign)) {
|
|
230
|
-
throw new Error(`Expected valid alignment for join.valign but received ${join.valign} of type ${typeof join.valign}`);
|
|
231
|
-
}
|
|
232
|
-
if (join.animated !== void 0 && typeof join.animated !== "boolean") {
|
|
233
|
-
throw new Error(`Expected boolean for join.animated but received ${join.animated} of type ${typeof join.animated}`);
|
|
234
|
-
}
|
|
235
|
-
if (join.background !== void 0) {
|
|
236
|
-
parseColor(join.background, 255);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
if (opts.text !== void 0) {
|
|
241
|
-
const text = opts.text;
|
|
242
|
-
if (!text || typeof text !== "object" || typeof text.text !== "string" || text.text.trim().length === 0) {
|
|
243
|
-
throw new Error("Expected a valid string to create an image with text.");
|
|
244
|
-
}
|
|
245
|
-
if (text.width !== void 0 && (!Number.isInteger(text.width) || text.width <= 0)) {
|
|
246
|
-
throw new Error(`Expected positive integer for text.width but received ${text.width} of type ${typeof text.width}`);
|
|
247
|
-
}
|
|
248
|
-
if (text.height !== void 0 && (!Number.isInteger(text.height) || text.height <= 0)) {
|
|
249
|
-
throw new Error(`Expected positive integer for text.height but received ${text.height} of type ${typeof text.height}`);
|
|
250
|
-
}
|
|
251
|
-
if (text.dpi !== void 0 && (!Number.isInteger(text.dpi) || text.dpi < 1 || text.dpi > 1e6)) {
|
|
252
|
-
throw new Error(`Expected integer between 1 and 1000000 for text.dpi but received ${text.dpi} of type ${typeof text.dpi}`);
|
|
253
|
-
}
|
|
254
|
-
if (text.align !== void 0 && !validAlignments.includes(text.align)) {
|
|
255
|
-
throw new Error(`Expected valid alignment for text.align but received ${text.align} of type ${typeof text.align}`);
|
|
256
|
-
}
|
|
257
|
-
if (text.justify !== void 0 && typeof text.justify !== "boolean") {
|
|
258
|
-
throw new Error(`Expected boolean for text.justify but received ${text.justify} of type ${typeof text.justify}`);
|
|
259
|
-
}
|
|
260
|
-
if (text.rgba !== void 0 && typeof text.rgba !== "boolean") {
|
|
261
|
-
throw new Error(`Expected bool for text.rgba but received ${text.rgba} of type ${typeof text.rgba}`);
|
|
262
|
-
}
|
|
263
|
-
if (text.wrap !== void 0 && !["word", "char", "word-char", "none"].includes(text.wrap)) {
|
|
264
|
-
throw new Error(`Expected one of: word, char, word-char, none for text.wrap but received ${text.wrap} of type ${typeof text.wrap}`);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (opts.create !== void 0) {
|
|
268
|
-
const create = opts.create;
|
|
269
|
-
if (!create || typeof create !== "object" || !Number.isInteger(create.width) || create.width <= 0 || !Number.isInteger(create.height) || create.height <= 0 || !Number.isInteger(create.channels)) {
|
|
270
|
-
throw new Error("Expected valid width, height and channels to create a new input image");
|
|
271
|
-
}
|
|
272
|
-
if (create.pageHeight !== void 0) {
|
|
273
|
-
if (!Number.isInteger(create.pageHeight) || create.pageHeight <= 0 || create.pageHeight > create.height) {
|
|
274
|
-
throw new Error(`Expected positive integer for create.pageHeight but received ${create.pageHeight}`);
|
|
275
|
-
}
|
|
276
|
-
if (create.height % create.pageHeight !== 0) {
|
|
277
|
-
throw new Error(`Expected create.height ${create.height} to be a multiple of create.pageHeight ${create.pageHeight}`);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
if (create.noise !== void 0) {
|
|
281
|
-
if (!create.noise || typeof create.noise !== "object") {
|
|
282
|
-
throw new Error("Expected noise to be an object");
|
|
283
|
-
}
|
|
284
|
-
if (create.noise.type !== "gaussian") {
|
|
285
|
-
throw new Error("Only gaussian noise is supported at the moment");
|
|
286
|
-
}
|
|
287
|
-
if (create.channels < 1 || create.channels > 4) {
|
|
288
|
-
throw new Error(
|
|
289
|
-
`Expected number between 1 and 4 for create.channels but received ${create.channels} of type ${typeof create.channels}`
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
} else if (create.background !== void 0) {
|
|
293
|
-
if (create.channels < 3 || create.channels > 4) {
|
|
294
|
-
throw new Error(
|
|
295
|
-
`Expected number between 3 and 4 for create.channels but received ${create.channels} of type ${typeof create.channels}`
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
} else {
|
|
299
|
-
throw new Error("Expected valid noise or background to create a new input image");
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
function toBytes(input, readFile) {
|
|
304
|
-
if (!input) return void 0;
|
|
305
|
-
if (isBuffer(input)) {
|
|
306
|
-
const bytes = input;
|
|
307
|
-
if (bytes.length === 0) {
|
|
308
|
-
throw new Error("Input Buffer is empty");
|
|
309
|
-
}
|
|
310
|
-
return bytes;
|
|
311
|
-
}
|
|
312
|
-
if (ArrayBuffer.isView(input)) {
|
|
313
|
-
if (input.byteLength === 0) {
|
|
314
|
-
throw new Error("Input Bit Array is empty");
|
|
315
|
-
}
|
|
316
|
-
return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
317
|
-
}
|
|
318
|
-
if (input instanceof ArrayBuffer) {
|
|
319
|
-
if (input.byteLength === 0) {
|
|
320
|
-
throw new Error("Input bit Array is empty");
|
|
321
|
-
}
|
|
322
|
-
return new Uint8Array(input);
|
|
323
|
-
}
|
|
324
|
-
if (typeof input === "string") {
|
|
325
|
-
if (input.trimStart().startsWith("<")) {
|
|
326
|
-
return new TextEncoder().encode(input);
|
|
327
|
-
}
|
|
328
|
-
if (!readFile) throw new Error("File inputs require an explicit filesystem and an asynchronous output method");
|
|
329
|
-
return readFile(input);
|
|
330
|
-
}
|
|
331
|
-
return void 0;
|
|
332
|
-
}
|
|
333
|
-
function inferFormatFromPath(fileOut) {
|
|
334
|
-
const ext = extname(fileOut).toLowerCase().slice(1);
|
|
335
|
-
switch (ext) {
|
|
336
|
-
case "png":
|
|
337
|
-
return "png";
|
|
338
|
-
case "jpg":
|
|
339
|
-
case "jpeg":
|
|
340
|
-
case "jpe":
|
|
341
|
-
return "jpeg";
|
|
342
|
-
case "webp":
|
|
343
|
-
return "webp";
|
|
344
|
-
case "gif":
|
|
345
|
-
return "gif";
|
|
346
|
-
case "tif":
|
|
347
|
-
case "tiff":
|
|
348
|
-
return "tiff";
|
|
349
|
-
case "avif":
|
|
350
|
-
return "avif";
|
|
351
|
-
case "heic":
|
|
352
|
-
return "heic";
|
|
353
|
-
case "heif":
|
|
354
|
-
return "heif";
|
|
355
|
-
case "pdf":
|
|
356
|
-
return "pdf";
|
|
357
|
-
case "ppm":
|
|
358
|
-
return "ppm";
|
|
359
|
-
case "pgm":
|
|
360
|
-
return "pgm";
|
|
361
|
-
case "pbm":
|
|
362
|
-
return "pbm";
|
|
363
|
-
case "bmp":
|
|
364
|
-
return "bmp";
|
|
365
|
-
case "raw":
|
|
366
|
-
return "raw";
|
|
367
|
-
default:
|
|
368
|
-
return void 0;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
var SharpInstance = class _SharpInstance extends Duplex {
|
|
372
|
-
inputBytes;
|
|
373
|
-
inputFilePath;
|
|
374
|
-
joinInputs;
|
|
375
|
-
inputOptions;
|
|
376
|
-
nodes = [];
|
|
377
|
-
outputOptions = {};
|
|
378
|
-
streamIn = false;
|
|
379
|
-
streamInFinished = false;
|
|
380
|
-
streamFailure;
|
|
381
|
-
streamChunks = [];
|
|
382
|
-
fileInputs = /* @__PURE__ */ new Map();
|
|
383
|
-
fileLoads = /* @__PURE__ */ new Map();
|
|
384
|
-
clonedStreams = [];
|
|
385
|
-
streamOutStarted = false;
|
|
386
|
-
constructor(input, options) {
|
|
387
|
-
super();
|
|
388
|
-
if (Array.isArray(input)) {
|
|
389
|
-
if (input.length < 2) {
|
|
390
|
-
throw new Error("Expected at least two images to join");
|
|
391
|
-
}
|
|
392
|
-
if (input.some((item) => Array.isArray(item))) {
|
|
393
|
-
throw new Error("Recursive join is unsupported");
|
|
394
|
-
}
|
|
395
|
-
this.inputBytes = void 0;
|
|
396
|
-
this.joinInputs = input;
|
|
397
|
-
this.inputOptions = options;
|
|
398
|
-
} else if (input && typeof input === "object" && !ArrayBuffer.isView(input) && !(input instanceof ArrayBuffer)) {
|
|
399
|
-
this.inputBytes = void 0;
|
|
400
|
-
this.joinInputs = void 0;
|
|
401
|
-
this.inputOptions = input;
|
|
402
|
-
if (this.inputOptions.join !== void 0) {
|
|
403
|
-
throw new Error("Expected input to be an array of images to join");
|
|
404
|
-
}
|
|
405
|
-
validateInputOptions(this.inputOptions);
|
|
406
|
-
if (!this.inputOptions.create && !this.inputOptions.text && Object.keys(this.inputOptions).length > 0) {
|
|
407
|
-
this.streamIn = true;
|
|
408
|
-
}
|
|
409
|
-
} else {
|
|
410
|
-
if (options?.join !== void 0) {
|
|
411
|
-
throw new Error("Expected input to be an array of images to join");
|
|
412
|
-
}
|
|
413
|
-
this.inputFilePath = typeof input === "string" && !input.trimStart().startsWith("<") ? input : void 0;
|
|
414
|
-
const inferredDepth = inferTypedArrayDepth(input);
|
|
415
|
-
let effectiveOptions = options;
|
|
416
|
-
if (effectiveOptions?.raw && inferredDepth && !effectiveOptions.raw.depth) {
|
|
417
|
-
effectiveOptions = {
|
|
418
|
-
...effectiveOptions,
|
|
419
|
-
raw: {
|
|
420
|
-
...effectiveOptions.raw,
|
|
421
|
-
depth: inferredDepth
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
validateInputOptions(effectiveOptions);
|
|
426
|
-
this.inputBytes = this.inputFilePath ? void 0 : toBytes(input);
|
|
427
|
-
this.joinInputs = void 0;
|
|
428
|
-
this.inputOptions = effectiveOptions;
|
|
429
|
-
if (input === void 0 && (!effectiveOptions || !effectiveOptions.create && !effectiveOptions.text)) {
|
|
430
|
-
this.streamIn = true;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
validateInputOptions(this.inputOptions);
|
|
434
|
-
this.on("error", (error) => {
|
|
435
|
-
this.streamFailure = error;
|
|
436
|
-
for (const child of this.clonedStreams) {
|
|
437
|
-
child.streamFailure = error;
|
|
438
|
-
child.destroy(error);
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
if (this.streamIn) {
|
|
442
|
-
this.on("finish", () => {
|
|
443
|
-
this.flattenStreamInput();
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
if (this.inputOptions?.autoOrient) {
|
|
447
|
-
this.nodes.push({ kind: "autoOrient" });
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
flattenStreamInput() {
|
|
451
|
-
if (this.streamIn && !this.streamInFinished) {
|
|
452
|
-
const merged = new Uint8Array(this.streamChunks.reduce((total, bytes) => total + bytes.length, 0));
|
|
453
|
-
let offset = 0;
|
|
454
|
-
for (const bytes of this.streamChunks) {
|
|
455
|
-
merged.set(bytes, offset);
|
|
456
|
-
offset += bytes.length;
|
|
457
|
-
}
|
|
458
|
-
this.receiveStreamInput(merged);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
receiveStreamInput(merged) {
|
|
462
|
-
this.inputBytes = merged;
|
|
463
|
-
this.streamInFinished = true;
|
|
464
|
-
for (const child of this.clonedStreams) {
|
|
465
|
-
child.receiveStreamInput(merged);
|
|
466
|
-
}
|
|
467
|
-
this.emit("streamReady");
|
|
468
|
-
}
|
|
469
|
-
async waitForStreamInput() {
|
|
470
|
-
if (this.streamFailure) throw this.streamFailure;
|
|
471
|
-
await this.loadFileInputs();
|
|
472
|
-
if (this.streamFailure) throw this.streamFailure;
|
|
473
|
-
if (!this.streamIn || this.streamInFinished) {
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
if (this.writableFinished) {
|
|
477
|
-
this.flattenStreamInput();
|
|
478
|
-
if (this.streamInFinished) return;
|
|
479
|
-
}
|
|
480
|
-
await new Promise((resolve, reject) => {
|
|
481
|
-
const onReady = () => {
|
|
482
|
-
this.removeListener("finish", onReady);
|
|
483
|
-
this.removeListener("streamReady", onReady);
|
|
484
|
-
this.removeListener("error", onError);
|
|
485
|
-
this.flattenStreamInput();
|
|
486
|
-
resolve();
|
|
487
|
-
};
|
|
488
|
-
const onError = (err) => {
|
|
489
|
-
this.removeListener("finish", onReady);
|
|
490
|
-
this.removeListener("streamReady", onReady);
|
|
491
|
-
reject(err);
|
|
492
|
-
};
|
|
493
|
-
this.once("finish", onReady);
|
|
494
|
-
this.once("streamReady", onReady);
|
|
495
|
-
this.once("error", onError);
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
operationInput(input) {
|
|
499
|
-
if (typeof input !== "string" || input.trimStart().startsWith("<")) return toBytes(input);
|
|
500
|
-
return input;
|
|
501
|
-
}
|
|
502
|
-
loadedFile(path) {
|
|
503
|
-
const bytes = this.fileInputs.get(path);
|
|
504
|
-
if (!bytes) throw new Error("File inputs require an explicit filesystem and an asynchronous output method");
|
|
505
|
-
return bytes;
|
|
506
|
-
}
|
|
507
|
-
async loadFileInputs() {
|
|
508
|
-
const paths = /* @__PURE__ */ new Set();
|
|
509
|
-
if (this.inputFilePath) paths.add(this.inputFilePath);
|
|
510
|
-
for (const input of this.joinInputs ?? []) {
|
|
511
|
-
if (typeof input === "string" && !input.trimStart().startsWith("<")) paths.add(input);
|
|
512
|
-
}
|
|
513
|
-
for (const node of this.nodes) {
|
|
514
|
-
if (node.kind === "boolean" && typeof node.operand === "string") paths.add(node.operand);
|
|
515
|
-
if (node.kind === "joinChannel") {
|
|
516
|
-
for (const input of node.inputs) if (typeof input.data === "string") paths.add(input.data);
|
|
517
|
-
}
|
|
518
|
-
if (node.kind !== "composite") continue;
|
|
519
|
-
for (const layer of node.layers) {
|
|
520
|
-
if (typeof layer.input === "string" && !layer.input.trimStart().startsWith("<")) paths.add(layer.input);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
await Promise.all([...paths].map((path) => {
|
|
524
|
-
if (this.fileInputs.has(path)) return;
|
|
525
|
-
let pending = this.fileLoads.get(path);
|
|
526
|
-
if (!pending) {
|
|
527
|
-
if (!this.inputOptions?.filesystem) throw new Error("File inputs require an explicit filesystem");
|
|
528
|
-
pending = this.inputOptions.filesystem.readFile(path).then((bytes) => {
|
|
529
|
-
this.fileInputs.set(path, new Uint8Array(bytes));
|
|
530
|
-
});
|
|
531
|
-
this.fileLoads.set(path, pending);
|
|
532
|
-
}
|
|
533
|
-
return pending;
|
|
534
|
-
}));
|
|
535
|
-
if (this.inputFilePath) this.inputBytes = this.loadedFile(this.inputFilePath);
|
|
536
|
-
}
|
|
537
|
-
_write(chunk, _encoding, callback) {
|
|
538
|
-
if (this.streamIn && !this.streamInFinished) {
|
|
539
|
-
if (chunk instanceof Uint8Array) {
|
|
540
|
-
this.streamChunks.push(new Uint8Array(chunk));
|
|
541
|
-
callback();
|
|
542
|
-
} else {
|
|
543
|
-
callback(new Error("Non-Buffer data on Writable Stream"));
|
|
544
|
-
}
|
|
545
|
-
} else {
|
|
546
|
-
callback(new Error("Unexpected data on Writable Stream"));
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
_read() {
|
|
550
|
-
if (!this.streamOutStarted) {
|
|
551
|
-
this.streamOutStarted = true;
|
|
552
|
-
this.waitForStreamInput().then(() => {
|
|
553
|
-
const res = this.toBufferWithObjectSync();
|
|
554
|
-
this.emit("info", res.info);
|
|
555
|
-
this.push(res.data);
|
|
556
|
-
this.push(null);
|
|
557
|
-
}).catch((err) => {
|
|
558
|
-
this.destroy(err);
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
clone() {
|
|
563
|
-
if (this.streamIn && !this.streamInFinished) {
|
|
564
|
-
const copy2 = new _SharpInstance(void 0, this.inputOptions);
|
|
565
|
-
copy2.nodes.length = 0;
|
|
566
|
-
copy2.nodes.push(...this.nodes);
|
|
567
|
-
copy2.outputOptions = { ...this.outputOptions };
|
|
568
|
-
this.clonedStreams.push(copy2);
|
|
569
|
-
if (this.streamFailure) {
|
|
570
|
-
copy2.streamFailure = this.streamFailure;
|
|
571
|
-
copy2.destroy(this.streamFailure);
|
|
572
|
-
}
|
|
573
|
-
return copy2;
|
|
574
|
-
}
|
|
575
|
-
const copy = this.joinInputs !== void 0 ? new _SharpInstance(this.joinInputs, this.inputOptions) : this.inputFilePath !== void 0 ? new _SharpInstance(this.inputFilePath, this.inputOptions) : this.inputBytes !== void 0 ? new _SharpInstance(this.inputBytes, this.inputOptions) : new _SharpInstance(this.inputOptions);
|
|
576
|
-
copy.inputFilePath = this.inputFilePath;
|
|
577
|
-
for (const [path, bytes] of this.fileInputs) copy.fileInputs.set(path, bytes);
|
|
578
|
-
copy.nodes.length = 0;
|
|
579
|
-
copy.nodes.push(...this.nodes);
|
|
580
|
-
copy.outputOptions = { ...this.outputOptions };
|
|
581
|
-
return copy;
|
|
582
|
-
}
|
|
583
|
-
decodeInitialImage() {
|
|
584
|
-
if (!this.joinInputs) {
|
|
585
|
-
return decodeImage(this.inputFilePath ? this.loadedFile(this.inputFilePath) : this.inputBytes, this.inputOptions);
|
|
586
|
-
}
|
|
587
|
-
const imgs = this.joinInputs.map((item) => {
|
|
588
|
-
if (item && typeof item === "object" && !(item instanceof Uint8Array) && !(item instanceof ArrayBuffer)) {
|
|
589
|
-
return decodeImage(void 0, item);
|
|
590
|
-
}
|
|
591
|
-
return decodeImage(toBytes(item, (path) => this.loadedFile(path)), this.inputOptions);
|
|
592
|
-
});
|
|
593
|
-
const n = imgs.length;
|
|
594
|
-
const cellW = Math.max(...imgs.map((i) => i.width));
|
|
595
|
-
const cellH = Math.max(...imgs.map((i) => i.height));
|
|
596
|
-
const joinOpts = this.inputOptions?.join;
|
|
597
|
-
const animated = Boolean(joinOpts?.animated);
|
|
598
|
-
const across = Math.max(1, joinOpts?.across ?? 1);
|
|
599
|
-
const cols = Math.min(n, across);
|
|
600
|
-
const rows = Math.ceil(n / cols);
|
|
601
|
-
const shim = Math.max(0, joinOpts?.shim ?? 0);
|
|
602
|
-
const outW = cols * cellW + (cols - 1) * shim;
|
|
603
|
-
const outH = rows * cellH + (rows - 1) * shim;
|
|
604
|
-
const anyAlpha = imgs.some((i) => i.hasAlpha);
|
|
605
|
-
const bg = parseColor(joinOpts?.background ?? { r: 0, g: 0, b: 0, alpha: 1 }, 255);
|
|
606
|
-
const hasAlpha = anyAlpha || bg.a < 255;
|
|
607
|
-
const channels = hasAlpha ? 4 : 3;
|
|
608
|
-
const out = new Uint8Array(outW * outH * 4);
|
|
609
|
-
const bgA = hasAlpha ? bg.a : 255;
|
|
610
|
-
const bgWord = (bgA << 24 | bg.b << 16 | bg.g << 8 | bg.r) >>> 0;
|
|
611
|
-
new Uint32Array(out.buffer, out.byteOffset, outW * outH).fill(bgWord);
|
|
612
|
-
const halign = joinOpts?.halign ?? "left";
|
|
613
|
-
const valign = joinOpts?.valign ?? "top";
|
|
614
|
-
for (let k = 0; k < n; k++) {
|
|
615
|
-
const im = imgs[k];
|
|
616
|
-
const col = k % cols;
|
|
617
|
-
const row = Math.floor(k / cols);
|
|
618
|
-
const cellX = col * (cellW + shim);
|
|
619
|
-
const cellY = row * (cellH + shim);
|
|
620
|
-
const dx = halign === "centre" || halign === "center" ? Math.floor((cellW - im.width) / 2) : halign === "right" || halign === "high" ? cellW - im.width : 0;
|
|
621
|
-
const dy = valign === "centre" || valign === "center" ? Math.floor((cellH - im.height) / 2) : valign === "bottom" || valign === "high" ? cellH - im.height : 0;
|
|
622
|
-
for (let y = 0; y < im.height; y++) {
|
|
623
|
-
const dstY = cellY + dy + y;
|
|
624
|
-
const sRow = y * im.width * 4;
|
|
625
|
-
const dRow = (dstY * outW + cellX + dx) * 4;
|
|
626
|
-
out.set(im.data.subarray(sRow, sRow + im.width * 4), dRow);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
const animPageHeight = animated && n > 0 ? Math.floor(outH / n) : 0;
|
|
630
|
-
const validAnim = animated && animPageHeight > 0 && outH % animPageHeight === 0 && outH / animPageHeight === n;
|
|
631
|
-
return {
|
|
632
|
-
width: outW,
|
|
633
|
-
height: outH,
|
|
634
|
-
data: out,
|
|
635
|
-
format: "raw",
|
|
636
|
-
space: "srgb",
|
|
637
|
-
channels,
|
|
638
|
-
depth: "uchar",
|
|
639
|
-
density: this.inputOptions?.density ?? 72,
|
|
640
|
-
hasAlpha,
|
|
641
|
-
...validAnim ? { pages: n, pageHeight: animPageHeight } : {}
|
|
642
|
-
};
|
|
643
|
-
}
|
|
644
|
-
getAst() {
|
|
645
|
-
return this.nodes;
|
|
646
|
-
}
|
|
647
|
-
upsertNode(nextNode, beforeGrayscale = false) {
|
|
648
|
-
const idx = this.nodes.findIndex((n) => n.kind === nextNode.kind);
|
|
649
|
-
if (idx !== -1) {
|
|
650
|
-
this.nodes[idx] = nextNode;
|
|
651
|
-
return;
|
|
652
|
-
}
|
|
653
|
-
if (nextNode.kind === "removeAlpha" || nextNode.kind === "flatten") {
|
|
654
|
-
const ensureIdx = this.nodes.findIndex((n) => n.kind === "ensureAlpha");
|
|
655
|
-
if (ensureIdx !== -1) {
|
|
656
|
-
this.nodes.splice(ensureIdx, 0, nextNode);
|
|
657
|
-
return;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
if (beforeGrayscale) {
|
|
661
|
-
const grayIdx = this.nodes.findIndex((n) => n.kind === "grayscale");
|
|
662
|
-
if (grayIdx !== -1) {
|
|
663
|
-
this.nodes.splice(grayIdx, 0, nextNode);
|
|
664
|
-
return;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
this.nodes.push(nextNode);
|
|
668
|
-
}
|
|
669
|
-
evaluateImage() {
|
|
670
|
-
let img = this.decodeInitialImage();
|
|
671
|
-
const resizeIdx = this.nodes.findIndex((n) => n.kind === "resize");
|
|
672
|
-
const postScaleIndices = /* @__PURE__ */ new Set();
|
|
673
|
-
if (resizeIdx !== -1) {
|
|
674
|
-
for (let i = resizeIdx + 1; i < this.nodes.length; i++) {
|
|
675
|
-
const n = this.nodes[i];
|
|
676
|
-
if (n.kind === "flip" || n.kind === "flop" || n.kind === "rotate" && n.angle % 90 === 0) {
|
|
677
|
-
postScaleIndices.add(i);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
const postScaleNodes = this.nodes.filter((_, idx) => postScaleIndices.has(idx));
|
|
682
|
-
const postScaleTransform = postScaleNodes.length > 0 ? (scaled) => {
|
|
683
|
-
let cur = scaled;
|
|
684
|
-
for (const pNode of postScaleNodes) {
|
|
685
|
-
if (pNode.kind === "rotate") {
|
|
686
|
-
cur = rotateImage(cur, pNode.angle, pNode.background);
|
|
687
|
-
} else if (pNode.kind === "flip") {
|
|
688
|
-
cur = flipImage(cur);
|
|
689
|
-
} else if (pNode.kind === "flop") {
|
|
690
|
-
cur = flopImage(cur);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
return cur;
|
|
694
|
-
} : void 0;
|
|
695
|
-
const gammaNode = this.nodes.find((n) => n.kind === "gamma");
|
|
696
|
-
const splitGamma = gammaNode !== void 0 && this.nodes.some(
|
|
697
|
-
(n) => n.kind === "resize" || n.kind === "blur" || n.kind === "convolve" || n.kind === "recomb" || n.kind === "modulate" || n.kind === "sharpen" || n.kind === "composite"
|
|
698
|
-
);
|
|
699
|
-
const postStageRank = {
|
|
700
|
-
extend: 10,
|
|
701
|
-
median: 20,
|
|
702
|
-
threshold: 30,
|
|
703
|
-
dilate: 40,
|
|
704
|
-
erode: 50,
|
|
705
|
-
blur: 60,
|
|
706
|
-
unflatten: 70,
|
|
707
|
-
convolve: 80,
|
|
708
|
-
recomb: 90,
|
|
709
|
-
modulate: 100,
|
|
710
|
-
sharpen: 110,
|
|
711
|
-
composite: 120,
|
|
712
|
-
gamma: 130,
|
|
713
|
-
linear: 140,
|
|
714
|
-
normalize: 150,
|
|
715
|
-
clahe: 160,
|
|
716
|
-
negate: 170,
|
|
717
|
-
tint: 180,
|
|
718
|
-
grayscale: 190,
|
|
719
|
-
toColorspace: 200,
|
|
720
|
-
bandbool: 210,
|
|
721
|
-
boolean: 220,
|
|
722
|
-
joinChannel: 230,
|
|
723
|
-
extractChannel: 240,
|
|
724
|
-
withMetadata: 250
|
|
725
|
-
};
|
|
726
|
-
const activeNodes = this.nodes.filter((_, idx) => !postScaleIndices.has(idx));
|
|
727
|
-
const preNodes = activeNodes.filter((n) => !(n.kind in postStageRank));
|
|
728
|
-
const postNodes = activeNodes.filter((n) => n.kind in postStageRank).sort((a, b) => (postStageRank[a.kind] ?? 999) - (postStageRank[b.kind] ?? 999));
|
|
729
|
-
const orderedNodes = [...preNodes, ...postNodes];
|
|
730
|
-
const isPremulStageKind = (kind) => kind === "resize" || kind === "blur" || kind === "convolve" || kind === "sharpen";
|
|
731
|
-
const premulStageCount = orderedNodes.filter((n) => isPremulStageKind(n.kind)).length;
|
|
732
|
-
const firstPremulIdx = orderedNodes.findIndex((n) => isPremulStageKind(n.kind));
|
|
733
|
-
let lastPremulIdx = -1;
|
|
734
|
-
for (let i = orderedNodes.length - 1; i >= 0; i--) {
|
|
735
|
-
if (isPremulStageKind(orderedNodes[i].kind)) {
|
|
736
|
-
lastPremulIdx = i;
|
|
737
|
-
break;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
let gammaInApplied = false;
|
|
741
|
-
let gammaOutApplied = false;
|
|
742
|
-
for (let i = 0; i < orderedNodes.length; i++) {
|
|
743
|
-
const node = orderedNodes[i];
|
|
744
|
-
if (splitGamma && gammaNode && !gammaInApplied && (i === firstPremulIdx || node.kind === "recomb" || node.kind === "modulate" || node.kind === "composite")) {
|
|
745
|
-
img = gammaImage(img, gammaNode.gamma, 1);
|
|
746
|
-
gammaInApplied = true;
|
|
747
|
-
}
|
|
748
|
-
if (i === firstPremulIdx && img.hasAlpha) {
|
|
749
|
-
if (premulStageCount > 1) {
|
|
750
|
-
img = premultiplyRgbaImage(img);
|
|
751
|
-
} else {
|
|
752
|
-
img = { ...img, wasPremultiplied: true };
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
switch (node.kind) {
|
|
756
|
-
case "autoOrient":
|
|
757
|
-
img = applyExifOrientation(img);
|
|
758
|
-
break;
|
|
759
|
-
case "rotate":
|
|
760
|
-
img = rotateImage(img, node.angle, node.background);
|
|
761
|
-
break;
|
|
762
|
-
case "flip":
|
|
763
|
-
img = flipImage(img);
|
|
764
|
-
break;
|
|
765
|
-
case "flop":
|
|
766
|
-
img = flopImage(img);
|
|
767
|
-
break;
|
|
768
|
-
case "extract":
|
|
769
|
-
img = extractImage(img, node);
|
|
770
|
-
break;
|
|
771
|
-
case "trim":
|
|
772
|
-
img = trimImage(img, {
|
|
773
|
-
threshold: node.threshold,
|
|
774
|
-
...node.background !== void 0 ? { background: node.background } : {},
|
|
775
|
-
...node.lineArt !== void 0 ? { lineArt: node.lineArt } : {}
|
|
776
|
-
});
|
|
777
|
-
break;
|
|
778
|
-
case "resize":
|
|
779
|
-
img = resizeImage(img, node, postScaleTransform);
|
|
780
|
-
if (img.hasAlpha && !img.isPremultiplied) {
|
|
781
|
-
if (i < lastPremulIdx) {
|
|
782
|
-
img = premultiplyRgbaImage(img);
|
|
783
|
-
} else {
|
|
784
|
-
img = { ...img, wasPremultiplied: true };
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
break;
|
|
788
|
-
case "extend":
|
|
789
|
-
img = extendImage(img, node);
|
|
790
|
-
break;
|
|
791
|
-
case "composite":
|
|
792
|
-
img = compositeImage(img, node.layers, (path) => this.loadedFile(path));
|
|
793
|
-
break;
|
|
794
|
-
case "grayscale":
|
|
795
|
-
img = grayscaleImage(img);
|
|
796
|
-
break;
|
|
797
|
-
case "flatten":
|
|
798
|
-
img = flattenImage(img, node.background);
|
|
799
|
-
break;
|
|
800
|
-
case "unflatten":
|
|
801
|
-
img = unflattenImage(img);
|
|
802
|
-
break;
|
|
803
|
-
case "negate":
|
|
804
|
-
img = negateImage(img, { alpha: node.alpha });
|
|
805
|
-
break;
|
|
806
|
-
case "modulate":
|
|
807
|
-
img = modulateImage(img, node);
|
|
808
|
-
break;
|
|
809
|
-
case "tint":
|
|
810
|
-
img = tintImage(img, node.color);
|
|
811
|
-
break;
|
|
812
|
-
case "gamma":
|
|
813
|
-
if (splitGamma) {
|
|
814
|
-
img = gammaImage(img, 1, node.gammaOut);
|
|
815
|
-
gammaOutApplied = true;
|
|
816
|
-
} else {
|
|
817
|
-
img = gammaImage(img, node.gamma, node.gammaOut);
|
|
818
|
-
}
|
|
819
|
-
break;
|
|
820
|
-
case "linear":
|
|
821
|
-
img = linearImage(img, node.a, node.b);
|
|
822
|
-
break;
|
|
823
|
-
case "normalize":
|
|
824
|
-
img = normalizeImage(img, { lower: node.lower, upper: node.upper });
|
|
825
|
-
break;
|
|
826
|
-
case "threshold":
|
|
827
|
-
img = thresholdImage(img, node.value, node.grayscale);
|
|
828
|
-
break;
|
|
829
|
-
case "blur":
|
|
830
|
-
img = blurImage(img, node.sigma, node.minAmplitude, node.precision);
|
|
831
|
-
break;
|
|
832
|
-
case "sharpen":
|
|
833
|
-
img = sharpenImage(img, node.sigma, node.m1, node.m2, node.x1, node.y2, node.y3);
|
|
834
|
-
break;
|
|
835
|
-
case "median":
|
|
836
|
-
img = medianImage(img, node.size);
|
|
837
|
-
break;
|
|
838
|
-
case "dilate":
|
|
839
|
-
img = dilateImage(img, node.width);
|
|
840
|
-
break;
|
|
841
|
-
case "erode":
|
|
842
|
-
img = erodeImage(img, node.width);
|
|
843
|
-
break;
|
|
844
|
-
case "convolve":
|
|
845
|
-
img = convolveImage(img, node);
|
|
846
|
-
break;
|
|
847
|
-
case "ensureAlpha":
|
|
848
|
-
img = ensureAlphaImage(img, node.alpha);
|
|
849
|
-
break;
|
|
850
|
-
case "removeAlpha":
|
|
851
|
-
img = removeAlphaImage(img);
|
|
852
|
-
break;
|
|
853
|
-
case "extractChannel":
|
|
854
|
-
img = extractChannelImage(img, node.channel);
|
|
855
|
-
break;
|
|
856
|
-
case "recomb":
|
|
857
|
-
img = recombImage(img, node.matrix);
|
|
858
|
-
break;
|
|
859
|
-
case "toColorspace":
|
|
860
|
-
img = toColorspaceImage(img, node.space);
|
|
861
|
-
break;
|
|
862
|
-
case "bandbool":
|
|
863
|
-
img = bandboolImage(img, node.op);
|
|
864
|
-
break;
|
|
865
|
-
case "boolean": {
|
|
866
|
-
const opImg = decodeImage(typeof node.operand === "string" ? this.loadedFile(node.operand) : node.operand, node.options);
|
|
867
|
-
img = booleanImage(img, opImg, node.op);
|
|
868
|
-
break;
|
|
869
|
-
}
|
|
870
|
-
case "joinChannel": {
|
|
871
|
-
const extras = node.inputs.map((item) => decodeImage(typeof item.data === "string" ? this.loadedFile(item.data) : item.data, item.options));
|
|
872
|
-
img = joinChannelImage(img, extras);
|
|
873
|
-
break;
|
|
874
|
-
}
|
|
875
|
-
case "clahe": {
|
|
876
|
-
const explicitBw = this.nodes.some(
|
|
877
|
-
(n) => n.kind === "grayscale" || n.kind === "toColorspace" && (n.space === "b-w" || n.space === "grey16")
|
|
878
|
-
);
|
|
879
|
-
if (!explicitBw && (img.channels === 1 || img.channels === 2)) {
|
|
880
|
-
img = {
|
|
881
|
-
...img,
|
|
882
|
-
channels: img.channels === 2 ? 4 : 3,
|
|
883
|
-
space: "srgb",
|
|
884
|
-
hasAlpha: img.channels === 2
|
|
885
|
-
};
|
|
886
|
-
}
|
|
887
|
-
img = claheImage(img, node);
|
|
888
|
-
break;
|
|
889
|
-
}
|
|
890
|
-
case "affine":
|
|
891
|
-
img = affineImage(img, node);
|
|
892
|
-
break;
|
|
893
|
-
case "withMetadata":
|
|
894
|
-
img = {
|
|
895
|
-
...img,
|
|
896
|
-
...node.density !== void 0 ? { density: node.density } : {},
|
|
897
|
-
...node.orientation !== void 0 ? { orientation: node.orientation } : {}
|
|
898
|
-
};
|
|
899
|
-
break;
|
|
900
|
-
}
|
|
901
|
-
if (i === lastPremulIdx && img.isPremultiplied) {
|
|
902
|
-
img = unpremultiplyRgbaImage(img);
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
if (splitGamma && gammaNode && gammaInApplied && !gammaOutApplied) {
|
|
906
|
-
img = gammaImage(img, 1, gammaNode.gammaOut);
|
|
907
|
-
}
|
|
908
|
-
return img;
|
|
909
|
-
}
|
|
910
|
-
metadataSync() {
|
|
911
|
-
const computeAutoOrient = (w, h, orient) => orient !== void 0 && orient >= 5 && orient <= 8 ? { width: h, height: w } : { width: w, height: h };
|
|
912
|
-
const rawMeta = this.joinInputs ? (() => {
|
|
913
|
-
const joined = this.decodeInitialImage();
|
|
914
|
-
return {
|
|
915
|
-
format: joined.format,
|
|
916
|
-
width: joined.width,
|
|
917
|
-
height: joined.height,
|
|
918
|
-
space: joined.space,
|
|
919
|
-
channels: joined.channels,
|
|
920
|
-
depth: joined.depth,
|
|
921
|
-
density: joined.density,
|
|
922
|
-
hasAlpha: joined.hasAlpha,
|
|
923
|
-
...joined.pages !== void 0 ? { pages: joined.pages } : {},
|
|
924
|
-
...joined.pageHeight !== void 0 ? { pageHeight: joined.pageHeight } : {},
|
|
925
|
-
size: joined.data.byteLength
|
|
926
|
-
};
|
|
927
|
-
})() : readImageMetadata(this.inputFilePath ? this.loadedFile(this.inputFilePath) : this.inputBytes, this.inputOptions);
|
|
928
|
-
if (this.nodes.length === 0) {
|
|
929
|
-
return {
|
|
930
|
-
...rawMeta,
|
|
931
|
-
autoOrient: computeAutoOrient(rawMeta.width, rawMeta.height, rawMeta.orientation)
|
|
932
|
-
};
|
|
933
|
-
}
|
|
934
|
-
const evaluated = this.evaluateImage();
|
|
935
|
-
return {
|
|
936
|
-
format: this.outputOptions.format ?? evaluated.format,
|
|
937
|
-
width: evaluated.width,
|
|
938
|
-
height: evaluated.height,
|
|
939
|
-
space: evaluated.space,
|
|
940
|
-
channels: evaluated.channels,
|
|
941
|
-
depth: evaluated.depth,
|
|
942
|
-
density: this.outputOptions.density ?? evaluated.density,
|
|
943
|
-
hasAlpha: evaluated.hasAlpha,
|
|
944
|
-
autoOrient: computeAutoOrient(evaluated.width, evaluated.height, evaluated.orientation),
|
|
945
|
-
...evaluated.orientation !== void 0 ? { orientation: evaluated.orientation } : {},
|
|
946
|
-
...rawMeta.pages !== void 0 ? { pages: rawMeta.pages } : {},
|
|
947
|
-
...rawMeta.pagePrimary !== void 0 ? { pagePrimary: rawMeta.pagePrimary } : {},
|
|
948
|
-
...rawMeta.isProgressive !== void 0 ? { isProgressive: rawMeta.isProgressive } : {},
|
|
949
|
-
...rawMeta.size !== void 0 ? { size: rawMeta.size } : {}
|
|
950
|
-
};
|
|
951
|
-
}
|
|
952
|
-
async metadata(callback) {
|
|
953
|
-
try {
|
|
954
|
-
await this.waitForStreamInput();
|
|
955
|
-
const res = this.metadataSync();
|
|
956
|
-
if (callback) callback(null, res);
|
|
957
|
-
return res;
|
|
958
|
-
} catch (err) {
|
|
959
|
-
if (callback) callback(err);
|
|
960
|
-
throw err;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
statsSync() {
|
|
964
|
-
const img = this.evaluateImage();
|
|
965
|
-
return computeImageStats(img);
|
|
966
|
-
}
|
|
967
|
-
async stats(callback) {
|
|
968
|
-
try {
|
|
969
|
-
await this.waitForStreamInput();
|
|
970
|
-
const res = this.statsSync();
|
|
971
|
-
if (callback) callback(null, res);
|
|
972
|
-
return res;
|
|
973
|
-
} catch (err) {
|
|
974
|
-
if (callback) callback(err);
|
|
975
|
-
throw err;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
autoOrient() {
|
|
979
|
-
return this.rotate();
|
|
980
|
-
}
|
|
981
|
-
rotate(angle, options) {
|
|
982
|
-
if (angle === void 0) {
|
|
983
|
-
if (!this.nodes.some((n) => n.kind === "autoOrient")) {
|
|
984
|
-
const insertIdx = this.nodes.findIndex(
|
|
985
|
-
(n) => n.kind === "rotate" || n.kind === "flip" || n.kind === "flop" || n.kind === "resize"
|
|
986
|
-
);
|
|
987
|
-
if (insertIdx !== -1) {
|
|
988
|
-
this.nodes.splice(insertIdx, 0, { kind: "autoOrient" });
|
|
989
|
-
} else {
|
|
990
|
-
this.nodes.push({ kind: "autoOrient" });
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
} else {
|
|
994
|
-
if (typeof angle !== "number" || Number.isNaN(angle)) {
|
|
995
|
-
throw new Error(`Expected numeric for angle but received ${angle} of type ${typeof angle}`);
|
|
996
|
-
}
|
|
997
|
-
const isOrthogonal = Number.isInteger(angle) && angle % 90 === 0;
|
|
998
|
-
const nextNode = {
|
|
999
|
-
kind: "rotate",
|
|
1000
|
-
angle,
|
|
1001
|
-
background: isOrthogonal ? { r: 0, g: 0, b: 0, a: 255 } : parseColor(options?.background, 255)
|
|
1002
|
-
};
|
|
1003
|
-
const existingIdx = this.nodes.findIndex((n) => n.kind === "rotate");
|
|
1004
|
-
if (existingIdx !== -1) {
|
|
1005
|
-
this.nodes[existingIdx] = nextNode;
|
|
1006
|
-
} else {
|
|
1007
|
-
this.nodes.push(nextNode);
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
return this;
|
|
1011
|
-
}
|
|
1012
|
-
flip(flip = true) {
|
|
1013
|
-
const existingIdx = this.nodes.findIndex((n) => n.kind === "flip");
|
|
1014
|
-
if (flip) {
|
|
1015
|
-
if (existingIdx !== -1) return this;
|
|
1016
|
-
const rotIdx = this.nodes.findIndex((n) => n.kind === "rotate");
|
|
1017
|
-
if (rotIdx !== -1) this.nodes.splice(rotIdx, 0, { kind: "flip" });
|
|
1018
|
-
else this.nodes.push({ kind: "flip" });
|
|
1019
|
-
} else if (existingIdx !== -1) {
|
|
1020
|
-
this.nodes.splice(existingIdx, 1);
|
|
1021
|
-
}
|
|
1022
|
-
return this;
|
|
1023
|
-
}
|
|
1024
|
-
flop(flop = true) {
|
|
1025
|
-
const existingIdx = this.nodes.findIndex((n) => n.kind === "flop");
|
|
1026
|
-
if (flop) {
|
|
1027
|
-
if (existingIdx !== -1) return this;
|
|
1028
|
-
const rotIdx = this.nodes.findIndex((n) => n.kind === "rotate");
|
|
1029
|
-
if (rotIdx !== -1) this.nodes.splice(rotIdx, 0, { kind: "flop" });
|
|
1030
|
-
else this.nodes.push({ kind: "flop" });
|
|
1031
|
-
} else if (existingIdx !== -1) {
|
|
1032
|
-
this.nodes.splice(existingIdx, 1);
|
|
1033
|
-
}
|
|
1034
|
-
return this;
|
|
1035
|
-
}
|
|
1036
|
-
extract(region) {
|
|
1037
|
-
if (!region || typeof region !== "object") {
|
|
1038
|
-
throw new Error("Expected object for extract region");
|
|
1039
|
-
}
|
|
1040
|
-
for (const name of ["left", "top", "width", "height"]) {
|
|
1041
|
-
const val = region[name];
|
|
1042
|
-
if (!Number.isInteger(val) || val < 0) {
|
|
1043
|
-
throw new Error(`Expected integer for ${name} but received ${val}`);
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
const nextNode = {
|
|
1047
|
-
kind: "extract",
|
|
1048
|
-
left: region.left,
|
|
1049
|
-
top: region.top,
|
|
1050
|
-
width: region.width,
|
|
1051
|
-
height: region.height
|
|
1052
|
-
};
|
|
1053
|
-
const resizeIdx = this.nodes.findIndex((n) => n.kind === "resize");
|
|
1054
|
-
const extractIndices = [];
|
|
1055
|
-
for (let i = 0; i < this.nodes.length; i++) {
|
|
1056
|
-
if (this.nodes[i].kind === "extract") extractIndices.push(i);
|
|
1057
|
-
}
|
|
1058
|
-
if (resizeIdx !== -1) {
|
|
1059
|
-
const postIdx = extractIndices.find((idx) => idx > resizeIdx);
|
|
1060
|
-
if (postIdx !== void 0) {
|
|
1061
|
-
this.nodes[postIdx] = nextNode;
|
|
1062
|
-
return this;
|
|
1063
|
-
}
|
|
1064
|
-
} else if (extractIndices.length >= 2) {
|
|
1065
|
-
this.nodes[extractIndices[1]] = nextNode;
|
|
1066
|
-
return this;
|
|
1067
|
-
}
|
|
1068
|
-
const extIdx = this.nodes.findIndex((n) => n.kind === "extend");
|
|
1069
|
-
if (extIdx !== -1) this.nodes.splice(extIdx, 0, nextNode);
|
|
1070
|
-
else this.nodes.push(nextNode);
|
|
1071
|
-
return this;
|
|
1072
|
-
}
|
|
1073
|
-
trim(options) {
|
|
1074
|
-
if (options !== void 0 && typeof options !== "number" && (typeof options !== "object" || options === null || Array.isArray(options))) {
|
|
1075
|
-
throw new Error(`Expected object or number for trim but received ${options} of type ${typeof options}`);
|
|
1076
|
-
}
|
|
1077
|
-
if (typeof options === "object" && options !== null && options.lineArt !== void 0 && typeof options.lineArt !== "boolean") {
|
|
1078
|
-
throw new Error(
|
|
1079
|
-
`Expected boolean for trimLineArt but received ${options.lineArt} of type ${typeof options.lineArt}`
|
|
1080
|
-
);
|
|
1081
|
-
}
|
|
1082
|
-
const threshold = typeof options === "number" ? options : options?.threshold ?? 10;
|
|
1083
|
-
if (typeof threshold !== "number" || Number.isNaN(threshold) || threshold < 0) {
|
|
1084
|
-
throw new Error(`Expected positive number for threshold but received ${threshold} of type ${typeof threshold}`);
|
|
1085
|
-
}
|
|
1086
|
-
const background = typeof options === "object" && options?.background ? parseColor(options.background) : void 0;
|
|
1087
|
-
const lineArt = typeof options === "object" && typeof options?.lineArt === "boolean" ? options.lineArt : void 0;
|
|
1088
|
-
const nextNode = {
|
|
1089
|
-
kind: "trim",
|
|
1090
|
-
threshold,
|
|
1091
|
-
...background ? { background } : {},
|
|
1092
|
-
...lineArt !== void 0 ? { lineArt } : {}
|
|
1093
|
-
};
|
|
1094
|
-
const existingIdx = this.nodes.findIndex((n) => n.kind === "trim");
|
|
1095
|
-
if (existingIdx !== -1) {
|
|
1096
|
-
this.nodes[existingIdx] = nextNode;
|
|
1097
|
-
return this;
|
|
1098
|
-
}
|
|
1099
|
-
const geomIdx = this.nodes.findIndex(
|
|
1100
|
-
(n) => n.kind === "resize" || n.kind === "extend" || n.kind === "extract" || n.kind === "rotate"
|
|
1101
|
-
);
|
|
1102
|
-
if (geomIdx !== -1) this.nodes.splice(geomIdx, 0, nextNode);
|
|
1103
|
-
else this.nodes.push(nextNode);
|
|
1104
|
-
return this;
|
|
1105
|
-
}
|
|
1106
|
-
resize(widthOrOptions, height, options) {
|
|
1107
|
-
let w = null;
|
|
1108
|
-
let h = null;
|
|
1109
|
-
let wProvided = false;
|
|
1110
|
-
let hProvided = false;
|
|
1111
|
-
let opts = {};
|
|
1112
|
-
if (typeof widthOrOptions === "object" && widthOrOptions !== null) {
|
|
1113
|
-
opts = widthOrOptions;
|
|
1114
|
-
w = opts.width ?? null;
|
|
1115
|
-
h = opts.height ?? null;
|
|
1116
|
-
wProvided = opts.width !== void 0;
|
|
1117
|
-
hProvided = true;
|
|
1118
|
-
} else {
|
|
1119
|
-
opts = options ?? {};
|
|
1120
|
-
w = widthOrOptions !== void 0 ? widthOrOptions : opts.width ?? null;
|
|
1121
|
-
h = height !== void 0 ? height : opts.height ?? null;
|
|
1122
|
-
wProvided = true;
|
|
1123
|
-
hProvided = true;
|
|
1124
|
-
}
|
|
1125
|
-
if (w !== null && (!Number.isInteger(w) || w <= 0)) {
|
|
1126
|
-
throw new Error(`Expected positive integer for width but received ${w}`);
|
|
1127
|
-
}
|
|
1128
|
-
if (h !== null && (!Number.isInteger(h) || h <= 0)) {
|
|
1129
|
-
throw new Error(`Expected positive integer for height but received ${h}`);
|
|
1130
|
-
}
|
|
1131
|
-
if (opts.fit !== void 0 && !["contain", "cover", "fill", "inside", "outside"].includes(opts.fit)) {
|
|
1132
|
-
throw new Error(`Expected valid fit for fit but received ${opts.fit} of type ${typeof opts.fit}`);
|
|
1133
|
-
}
|
|
1134
|
-
if (opts.kernel !== void 0 && !["nearest", "linear", "cubic", "mitchell", "lanczos2", "lanczos3", "mks2013", "mks2021"].includes(opts.kernel)) {
|
|
1135
|
-
throw new Error(`Expected valid kernel name for kernel but received ${opts.kernel} of type ${typeof opts.kernel}`);
|
|
1136
|
-
}
|
|
1137
|
-
if (opts.position !== void 0) {
|
|
1138
|
-
const validPosStrings = [
|
|
1139
|
-
"top",
|
|
1140
|
-
"right",
|
|
1141
|
-
"bottom",
|
|
1142
|
-
"left",
|
|
1143
|
-
"right top",
|
|
1144
|
-
"right bottom",
|
|
1145
|
-
"left bottom",
|
|
1146
|
-
"left top",
|
|
1147
|
-
"north",
|
|
1148
|
-
"northeast",
|
|
1149
|
-
"east",
|
|
1150
|
-
"southeast",
|
|
1151
|
-
"south",
|
|
1152
|
-
"southwest",
|
|
1153
|
-
"west",
|
|
1154
|
-
"northwest",
|
|
1155
|
-
"center",
|
|
1156
|
-
"centre",
|
|
1157
|
-
"entropy",
|
|
1158
|
-
"attention"
|
|
1159
|
-
];
|
|
1160
|
-
const isValidPos = typeof opts.position === "string" ? validPosStrings.includes(opts.position) : typeof opts.position === "number" && Number.isInteger(opts.position) && (opts.position >= 0 && opts.position <= 8 || opts.position === 16 || opts.position === 17);
|
|
1161
|
-
if (!isValidPos) {
|
|
1162
|
-
throw new Error(
|
|
1163
|
-
`Expected valid position/gravity/strategy for position but received ${opts.position} of type ${typeof opts.position}`
|
|
1164
|
-
);
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
const anyResizeOpts = opts;
|
|
1168
|
-
for (const boolKey of ["withoutEnlargement", "withoutReduction", "fastShrinkOnLoad"]) {
|
|
1169
|
-
if (anyResizeOpts[boolKey] !== void 0 && typeof anyResizeOpts[boolKey] !== "boolean") {
|
|
1170
|
-
throw new Error(
|
|
1171
|
-
`Expected boolean for ${boolKey} but received ${anyResizeOpts[boolKey]} of type ${typeof anyResizeOpts[boolKey]}`
|
|
1172
|
-
);
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
const existingIdx = this.nodes.findIndex((n) => n.kind === "resize");
|
|
1176
|
-
if (existingIdx !== -1) {
|
|
1177
|
-
const prev = this.nodes[existingIdx];
|
|
1178
|
-
this.nodes[existingIdx] = {
|
|
1179
|
-
kind: "resize",
|
|
1180
|
-
width: wProvided ? w : prev.width,
|
|
1181
|
-
height: hProvided ? h : prev.height,
|
|
1182
|
-
fit: opts.fit ?? prev.fit,
|
|
1183
|
-
position: opts.position ?? prev.position,
|
|
1184
|
-
kernel: opts.kernel ?? prev.kernel,
|
|
1185
|
-
background: opts.background !== void 0 ? parseColor(opts.background, 255) : prev.background,
|
|
1186
|
-
withoutEnlargement: opts.withoutEnlargement ?? prev.withoutEnlargement,
|
|
1187
|
-
withoutReduction: opts.withoutReduction ?? prev.withoutReduction
|
|
1188
|
-
};
|
|
1189
|
-
return this;
|
|
1190
|
-
}
|
|
1191
|
-
const nextResizeNode = {
|
|
1192
|
-
kind: "resize",
|
|
1193
|
-
width: w,
|
|
1194
|
-
height: h,
|
|
1195
|
-
fit: opts.fit ?? "cover",
|
|
1196
|
-
position: opts.position ?? "centre",
|
|
1197
|
-
kernel: opts.kernel ?? "lanczos3",
|
|
1198
|
-
background: parseColor(opts.background, 255),
|
|
1199
|
-
withoutEnlargement: opts.withoutEnlargement ?? false,
|
|
1200
|
-
withoutReduction: opts.withoutReduction ?? false
|
|
1201
|
-
};
|
|
1202
|
-
const extIdx = this.nodes.findIndex((n) => n.kind === "extend");
|
|
1203
|
-
if (extIdx !== -1) this.nodes.splice(extIdx, 0, nextResizeNode);
|
|
1204
|
-
else this.nodes.push(nextResizeNode);
|
|
1205
|
-
return this;
|
|
1206
|
-
}
|
|
1207
|
-
extend(edges) {
|
|
1208
|
-
if (typeof edges === "number") {
|
|
1209
|
-
if (!Number.isInteger(edges) || edges <= 0) {
|
|
1210
|
-
throw new Error(`Expected positive integer for extend but received ${edges}`);
|
|
1211
|
-
}
|
|
1212
|
-
} else if (edges && typeof edges === "object") {
|
|
1213
|
-
for (const side of ["top", "bottom", "left", "right"]) {
|
|
1214
|
-
const val = edges[side];
|
|
1215
|
-
if (val !== void 0 && (!Number.isInteger(val) || val < 0)) {
|
|
1216
|
-
throw new Error(`Expected positive integer for ${side} but received ${val}`);
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
if (edges.extendWith !== void 0 && edges.extendWith !== "background" && edges.extendWith !== "copy" && edges.extendWith !== "repeat" && edges.extendWith !== "mirror") {
|
|
1220
|
-
throw new Error(`Expected one of: background, copy, repeat, mirror for extendWith but received ${edges.extendWith}`);
|
|
1221
|
-
}
|
|
1222
|
-
} else {
|
|
1223
|
-
throw new Error(`Expected integer or object for extend but received ${edges}`);
|
|
1224
|
-
}
|
|
1225
|
-
const nextNode = typeof edges === "number" ? {
|
|
1226
|
-
kind: "extend",
|
|
1227
|
-
top: edges,
|
|
1228
|
-
bottom: edges,
|
|
1229
|
-
left: edges,
|
|
1230
|
-
right: edges,
|
|
1231
|
-
background: { r: 0, g: 0, b: 0, a: 255 },
|
|
1232
|
-
extendWith: "background"
|
|
1233
|
-
} : {
|
|
1234
|
-
kind: "extend",
|
|
1235
|
-
top: edges.top ?? 0,
|
|
1236
|
-
bottom: edges.bottom ?? 0,
|
|
1237
|
-
left: edges.left ?? 0,
|
|
1238
|
-
right: edges.right ?? 0,
|
|
1239
|
-
background: parseColor(edges.background, 255),
|
|
1240
|
-
extendWith: edges.extendWith ?? "background"
|
|
1241
|
-
};
|
|
1242
|
-
const existingIdx = this.nodes.findIndex((n) => n.kind === "extend");
|
|
1243
|
-
if (existingIdx !== -1) {
|
|
1244
|
-
this.nodes[existingIdx] = nextNode;
|
|
1245
|
-
} else {
|
|
1246
|
-
this.nodes.push(nextNode);
|
|
1247
|
-
}
|
|
1248
|
-
return this;
|
|
1249
|
-
}
|
|
1250
|
-
composite(images) {
|
|
1251
|
-
if (!Array.isArray(images)) {
|
|
1252
|
-
throw new Error("Expected array for images to composite");
|
|
1253
|
-
}
|
|
1254
|
-
const validBlends = [
|
|
1255
|
-
"clear",
|
|
1256
|
-
"source",
|
|
1257
|
-
"over",
|
|
1258
|
-
"in",
|
|
1259
|
-
"out",
|
|
1260
|
-
"atop",
|
|
1261
|
-
"dest",
|
|
1262
|
-
"dest-over",
|
|
1263
|
-
"dest-in",
|
|
1264
|
-
"dest-out",
|
|
1265
|
-
"dest-atop",
|
|
1266
|
-
"xor",
|
|
1267
|
-
"add",
|
|
1268
|
-
"saturate",
|
|
1269
|
-
"multiply",
|
|
1270
|
-
"screen",
|
|
1271
|
-
"overlay",
|
|
1272
|
-
"darken",
|
|
1273
|
-
"lighten",
|
|
1274
|
-
"colour-dodge",
|
|
1275
|
-
"color-dodge",
|
|
1276
|
-
"colour-burn",
|
|
1277
|
-
"color-burn",
|
|
1278
|
-
"hard-light",
|
|
1279
|
-
"soft-light",
|
|
1280
|
-
"difference",
|
|
1281
|
-
"exclusion"
|
|
1282
|
-
];
|
|
1283
|
-
const validGravities = [
|
|
1284
|
-
"center",
|
|
1285
|
-
"centre",
|
|
1286
|
-
"north",
|
|
1287
|
-
"east",
|
|
1288
|
-
"south",
|
|
1289
|
-
"west",
|
|
1290
|
-
"northeast",
|
|
1291
|
-
"southeast",
|
|
1292
|
-
"southwest",
|
|
1293
|
-
"northwest"
|
|
1294
|
-
];
|
|
1295
|
-
for (const img of images) {
|
|
1296
|
-
if (!img || typeof img !== "object") {
|
|
1297
|
-
throw new Error("Expected object for image to composite");
|
|
1298
|
-
}
|
|
1299
|
-
if (img.input === void 0) {
|
|
1300
|
-
throw new Error(`Unsupported input '${img.input}' of type ${typeof img.input}`);
|
|
1301
|
-
}
|
|
1302
|
-
validateInputOptions(img);
|
|
1303
|
-
if (img.blend !== void 0 && !validBlends.includes(img.blend)) {
|
|
1304
|
-
throw new Error(`Expected valid blend name for blend but received ${img.blend} of type ${typeof img.blend}`);
|
|
1305
|
-
}
|
|
1306
|
-
if (img.tile !== void 0 && typeof img.tile !== "boolean") {
|
|
1307
|
-
throw new Error(`Expected boolean for tile but received ${img.tile} of type ${typeof img.tile}`);
|
|
1308
|
-
}
|
|
1309
|
-
if (img.premultiplied !== void 0 && typeof img.premultiplied !== "boolean") {
|
|
1310
|
-
throw new Error(`Expected boolean for premultiplied but received ${img.premultiplied} of type ${typeof img.premultiplied}`);
|
|
1311
|
-
}
|
|
1312
|
-
if (img.gravity !== void 0) {
|
|
1313
|
-
const validG = typeof img.gravity === "string" ? validGravities.includes(img.gravity) : typeof img.gravity === "number" && Number.isInteger(img.gravity) && img.gravity >= 0 && img.gravity <= 8;
|
|
1314
|
-
if (!validG) {
|
|
1315
|
-
throw new Error(`Expected valid gravity for gravity but received ${img.gravity} of type ${typeof img.gravity}`);
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
if (img.top !== void 0 !== (img.left !== void 0)) {
|
|
1319
|
-
throw new Error("Expected both left and top to be set");
|
|
1320
|
-
}
|
|
1321
|
-
if (img.top !== void 0 && !Number.isInteger(img.top)) {
|
|
1322
|
-
throw new Error(`Expected integer for top but received ${img.top}`);
|
|
1323
|
-
}
|
|
1324
|
-
if (img.left !== void 0 && !Number.isInteger(img.left)) {
|
|
1325
|
-
throw new Error(`Expected integer for left but received ${img.left}`);
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
const existingIdx = this.nodes.findIndex((n) => n.kind === "composite");
|
|
1329
|
-
if (existingIdx !== -1) {
|
|
1330
|
-
this.nodes[existingIdx] = { kind: "composite", layers: [...images] };
|
|
1331
|
-
} else {
|
|
1332
|
-
this.nodes.push({ kind: "composite", layers: [...images] });
|
|
1333
|
-
}
|
|
1334
|
-
return this;
|
|
1335
|
-
}
|
|
1336
|
-
grayscale(grayscale = true) {
|
|
1337
|
-
if (grayscale === false) {
|
|
1338
|
-
const idx = this.nodes.findIndex((n) => n.kind === "grayscale");
|
|
1339
|
-
if (idx !== -1) this.nodes.splice(idx, 1);
|
|
1340
|
-
return this;
|
|
1341
|
-
}
|
|
1342
|
-
this.upsertNode({ kind: "grayscale" });
|
|
1343
|
-
return this;
|
|
1344
|
-
}
|
|
1345
|
-
greyscale(greyscale = true) {
|
|
1346
|
-
return this.grayscale(greyscale);
|
|
1347
|
-
}
|
|
1348
|
-
flatten(options) {
|
|
1349
|
-
if (options === false) {
|
|
1350
|
-
const idx = this.nodes.findIndex((n) => n.kind === "flatten");
|
|
1351
|
-
if (idx !== -1) this.nodes.splice(idx, 1);
|
|
1352
|
-
return this;
|
|
1353
|
-
}
|
|
1354
|
-
const bg = typeof options === "object" ? options?.background : void 0;
|
|
1355
|
-
this.upsertNode({
|
|
1356
|
-
kind: "flatten",
|
|
1357
|
-
background: parseColor(bg ?? "#000000", 255)
|
|
1358
|
-
});
|
|
1359
|
-
return this;
|
|
1360
|
-
}
|
|
1361
|
-
unflatten() {
|
|
1362
|
-
this.upsertNode({ kind: "unflatten" }, true);
|
|
1363
|
-
return this;
|
|
1364
|
-
}
|
|
1365
|
-
negate(options) {
|
|
1366
|
-
if (options === false) {
|
|
1367
|
-
const idx = this.nodes.findIndex((n) => n.kind === "negate");
|
|
1368
|
-
if (idx !== -1) this.nodes.splice(idx, 1);
|
|
1369
|
-
return this;
|
|
1370
|
-
}
|
|
1371
|
-
if (typeof options === "object" && options !== null && options.alpha !== void 0 && typeof options.alpha !== "boolean") {
|
|
1372
|
-
throw new Error(`Expected should be boolean value for alpha but received ${options.alpha} of type ${typeof options.alpha}`);
|
|
1373
|
-
}
|
|
1374
|
-
const alpha = typeof options === "object" ? options.alpha ?? true : true;
|
|
1375
|
-
this.upsertNode({ kind: "negate", alpha });
|
|
1376
|
-
return this;
|
|
1377
|
-
}
|
|
1378
|
-
modulate(options) {
|
|
1379
|
-
if (!options || typeof options !== "object") {
|
|
1380
|
-
throw new Error(`Expected plain object for modulate options but received ${options}`);
|
|
1381
|
-
}
|
|
1382
|
-
if (options.brightness !== void 0 && (typeof options.brightness !== "number" || Number.isNaN(options.brightness) || options.brightness < 0)) {
|
|
1383
|
-
throw new Error(`Expected number above zero for brightness but received ${options.brightness} of type ${typeof options.brightness}`);
|
|
1384
|
-
}
|
|
1385
|
-
if (options.saturation !== void 0 && (typeof options.saturation !== "number" || Number.isNaN(options.saturation) || options.saturation < 0)) {
|
|
1386
|
-
throw new Error(`Expected number above zero for saturation but received ${options.saturation} of type ${typeof options.saturation}`);
|
|
1387
|
-
}
|
|
1388
|
-
if (options.hue !== void 0 && (typeof options.hue !== "number" || Number.isNaN(options.hue))) {
|
|
1389
|
-
throw new Error(`Expected number for hue but received ${options.hue} of type ${typeof options.hue}`);
|
|
1390
|
-
}
|
|
1391
|
-
if (options.lightness !== void 0 && (typeof options.lightness !== "number" || Number.isNaN(options.lightness))) {
|
|
1392
|
-
throw new Error(`Expected number for lightness but received ${options.lightness} of type ${typeof options.lightness}`);
|
|
1393
|
-
}
|
|
1394
|
-
const idx = this.nodes.findIndex((n) => n.kind === "modulate");
|
|
1395
|
-
if (idx !== -1) {
|
|
1396
|
-
const prev = this.nodes[idx];
|
|
1397
|
-
this.nodes[idx] = {
|
|
1398
|
-
kind: "modulate",
|
|
1399
|
-
brightness: options.brightness ?? prev.brightness,
|
|
1400
|
-
saturation: options.saturation ?? prev.saturation,
|
|
1401
|
-
hue: options.hue ?? prev.hue,
|
|
1402
|
-
lightness: options.lightness ?? prev.lightness
|
|
1403
|
-
};
|
|
1404
|
-
return this;
|
|
1405
|
-
}
|
|
1406
|
-
this.nodes.push({
|
|
1407
|
-
kind: "modulate",
|
|
1408
|
-
brightness: options.brightness ?? 1,
|
|
1409
|
-
saturation: options.saturation ?? 1,
|
|
1410
|
-
hue: options.hue ?? 0,
|
|
1411
|
-
lightness: options.lightness ?? 0
|
|
1412
|
-
});
|
|
1413
|
-
return this;
|
|
1414
|
-
}
|
|
1415
|
-
tint(rgb2) {
|
|
1416
|
-
this.upsertNode({ kind: "tint", color: parseColor(rgb2, 255) }, true);
|
|
1417
|
-
return this;
|
|
1418
|
-
}
|
|
1419
|
-
gamma(gamma = 2.2, gammaOut = gamma) {
|
|
1420
|
-
if (typeof gamma !== "number" || Number.isNaN(gamma) || gamma < 1 || gamma > 3) {
|
|
1421
|
-
throw new Error(`Expected number between 1.0 and 3.0 for gamma but received ${gamma}`);
|
|
1422
|
-
}
|
|
1423
|
-
if (typeof gammaOut !== "number" || Number.isNaN(gammaOut) || gammaOut < 1 || gammaOut > 3) {
|
|
1424
|
-
throw new Error(`Expected number between 1.0 and 3.0 for gammaOut but received ${gammaOut}`);
|
|
1425
|
-
}
|
|
1426
|
-
this.upsertNode({ kind: "gamma", gamma, gammaOut });
|
|
1427
|
-
return this;
|
|
1428
|
-
}
|
|
1429
|
-
linear(a, b) {
|
|
1430
|
-
if (a == null && b == null) {
|
|
1431
|
-
const idx = this.nodes.findIndex((n) => n.kind === "linear");
|
|
1432
|
-
if (idx !== -1) this.nodes.splice(idx, 1);
|
|
1433
|
-
return this;
|
|
1434
|
-
}
|
|
1435
|
-
let effA = a;
|
|
1436
|
-
let effB = b;
|
|
1437
|
-
if (effA == null && typeof effB === "number") {
|
|
1438
|
-
effA = 1;
|
|
1439
|
-
} else if (typeof effA === "number" && effB == null) {
|
|
1440
|
-
effB = 0;
|
|
1441
|
-
}
|
|
1442
|
-
const aArr = effA == null ? [] : typeof effA === "number" ? [effA] : Array.isArray(effA) ? [...effA] : [];
|
|
1443
|
-
const bArr = effB == null ? [] : typeof effB === "number" ? [effB] : Array.isArray(effB) ? [...effB] : [];
|
|
1444
|
-
if (aArr.length !== bArr.length) {
|
|
1445
|
-
throw new Error("Expected a and b to be arrays of the same length");
|
|
1446
|
-
}
|
|
1447
|
-
this.upsertNode({ kind: "linear", a: aArr, b: bArr });
|
|
1448
|
-
return this;
|
|
1449
|
-
}
|
|
1450
|
-
normalize(lowerOrOptions, upperArg) {
|
|
1451
|
-
if (lowerOrOptions === false) {
|
|
1452
|
-
const idx = this.nodes.findIndex((n) => n.kind === "normalize");
|
|
1453
|
-
if (idx !== -1) this.nodes.splice(idx, 1);
|
|
1454
|
-
return this;
|
|
1455
|
-
}
|
|
1456
|
-
if (lowerOrOptions === true) {
|
|
1457
|
-
this.upsertNode({ kind: "normalize", lower: 1, upper: 99 });
|
|
1458
|
-
return this;
|
|
1459
|
-
}
|
|
1460
|
-
const lower = typeof lowerOrOptions === "number" ? lowerOrOptions : lowerOrOptions?.lower ?? 1;
|
|
1461
|
-
const upper = typeof lowerOrOptions === "number" ? upperArg ?? 99 : lowerOrOptions?.upper ?? 99;
|
|
1462
|
-
if (typeof lower !== "number" || Number.isNaN(lower) || lower < 0 || lower > 99) {
|
|
1463
|
-
throw new Error(`Expected number between 0 and 99 for lower but received ${lower} of type ${typeof lower}`);
|
|
1464
|
-
}
|
|
1465
|
-
if (typeof upper !== "number" || Number.isNaN(upper) || upper < 1 || upper > 100) {
|
|
1466
|
-
throw new Error(`Expected number between 1 and 100 for upper but received ${upper} of type ${typeof upper}`);
|
|
1467
|
-
}
|
|
1468
|
-
if (lower >= upper) {
|
|
1469
|
-
throw new Error(`Expected lower to be less than upper for range but received ${lower} >= ${upper} of type string`);
|
|
1470
|
-
}
|
|
1471
|
-
this.upsertNode({ kind: "normalize", lower, upper });
|
|
1472
|
-
return this;
|
|
1473
|
-
}
|
|
1474
|
-
normalise(lowerOrOptions, upperArg) {
|
|
1475
|
-
return this.normalize(lowerOrOptions, upperArg);
|
|
1476
|
-
}
|
|
1477
|
-
threshold(threshold = 128, options) {
|
|
1478
|
-
if (threshold === false || threshold === 0) {
|
|
1479
|
-
const idx = this.nodes.findIndex((n) => n.kind === "threshold");
|
|
1480
|
-
if (idx !== -1) this.nodes.splice(idx, 1);
|
|
1481
|
-
return this;
|
|
1482
|
-
}
|
|
1483
|
-
if (typeof threshold === "number" && (!Number.isInteger(threshold) || threshold < 0 || threshold > 255)) {
|
|
1484
|
-
throw new Error(`Expected integer between 0 and 255 for threshold but received ${threshold}`);
|
|
1485
|
-
}
|
|
1486
|
-
const val = typeof threshold === "number" ? threshold : 128;
|
|
1487
|
-
const gs = options?.grayscale ?? options?.greyscale ?? true;
|
|
1488
|
-
this.upsertNode({ kind: "threshold", value: val, grayscale: gs });
|
|
1489
|
-
return this;
|
|
1490
|
-
}
|
|
1491
|
-
blur(options) {
|
|
1492
|
-
if (options === false) {
|
|
1493
|
-
const idx = this.nodes.findIndex((n) => n.kind === "blur");
|
|
1494
|
-
if (idx !== -1) this.nodes.splice(idx, 1);
|
|
1495
|
-
return this;
|
|
1496
|
-
}
|
|
1497
|
-
let sigma;
|
|
1498
|
-
let precision;
|
|
1499
|
-
let minAmplitude;
|
|
1500
|
-
if (typeof options === "number") {
|
|
1501
|
-
sigma = options;
|
|
1502
|
-
} else if (options !== null && typeof options === "object" && !Array.isArray(options)) {
|
|
1503
|
-
if (typeof options.sigma !== "number" || Number.isNaN(options.sigma)) {
|
|
1504
|
-
throw new Error(
|
|
1505
|
-
`Expected number between 0.3 and 1000 for options.sigma but received ${options.sigma} of type ${typeof options.sigma}`
|
|
1506
|
-
);
|
|
1507
|
-
}
|
|
1508
|
-
sigma = options.sigma;
|
|
1509
|
-
if ("precision" in options && options.precision !== void 0) {
|
|
1510
|
-
if (options.precision !== "integer" && options.precision !== "float" && options.precision !== "approximate") {
|
|
1511
|
-
throw new Error(
|
|
1512
|
-
`Expected one of: integer, float, approximate for precision but received ${options.precision} of type ${typeof options.precision}`
|
|
1513
|
-
);
|
|
1514
|
-
}
|
|
1515
|
-
precision = options.precision;
|
|
1516
|
-
}
|
|
1517
|
-
if ("minAmplitude" in options && options.minAmplitude !== void 0) {
|
|
1518
|
-
if (typeof options.minAmplitude !== "number" || Number.isNaN(options.minAmplitude) || options.minAmplitude < 1e-3 || options.minAmplitude > 1) {
|
|
1519
|
-
throw new Error(
|
|
1520
|
-
`Expected number between 0.001 and 1 for minAmplitude but received ${options.minAmplitude} of type ${typeof options.minAmplitude}`
|
|
1521
|
-
);
|
|
1522
|
-
}
|
|
1523
|
-
minAmplitude = options.minAmplitude;
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
if (options === void 0 || options === true) {
|
|
1527
|
-
this.upsertNode({ kind: "blur", sigma: -1 });
|
|
1528
|
-
return this;
|
|
1529
|
-
}
|
|
1530
|
-
if (typeof sigma !== "number" || Number.isNaN(sigma) || sigma < 0.3 || sigma > 1e3) {
|
|
1531
|
-
throw new Error(
|
|
1532
|
-
`Expected number between 0.3 and 1000 for sigma but received ${sigma} of type ${typeof sigma}`
|
|
1533
|
-
);
|
|
1534
|
-
}
|
|
1535
|
-
this.upsertNode({
|
|
1536
|
-
kind: "blur",
|
|
1537
|
-
sigma,
|
|
1538
|
-
...precision ? { precision } : {},
|
|
1539
|
-
...minAmplitude !== void 0 ? { minAmplitude } : {}
|
|
1540
|
-
});
|
|
1541
|
-
return this;
|
|
1542
|
-
}
|
|
1543
|
-
sharpen(options, flat, jagged) {
|
|
1544
|
-
if (options === false) {
|
|
1545
|
-
const idx = this.nodes.findIndex((n) => n.kind === "sharpen");
|
|
1546
|
-
if (idx !== -1) this.nodes.splice(idx, 1);
|
|
1547
|
-
return this;
|
|
1548
|
-
}
|
|
1549
|
-
if (options === void 0 || options === true) {
|
|
1550
|
-
this.upsertNode({ kind: "sharpen", sigma: -1, m1: 1, m2: 2, x1: 2, y2: 10, y3: 20 });
|
|
1551
|
-
return this;
|
|
1552
|
-
}
|
|
1553
|
-
if (typeof options === "number") {
|
|
1554
|
-
if (Number.isNaN(options) || options < 0.01 || options > 1e4) {
|
|
1555
|
-
throw new Error(`Expected number between 0.01 and 10000 for sigma but received ${options}`);
|
|
1556
|
-
}
|
|
1557
|
-
this.upsertNode({
|
|
1558
|
-
kind: "sharpen",
|
|
1559
|
-
sigma: options,
|
|
1560
|
-
m1: flat ?? 1,
|
|
1561
|
-
m2: jagged ?? 2,
|
|
1562
|
-
x1: 2,
|
|
1563
|
-
y2: 10,
|
|
1564
|
-
y3: 20
|
|
1565
|
-
});
|
|
1566
|
-
return this;
|
|
1567
|
-
}
|
|
1568
|
-
if (options.sigma !== void 0 && (typeof options.sigma !== "number" || Number.isNaN(options.sigma) || options.sigma < 1e-6 || options.sigma > 10)) {
|
|
1569
|
-
throw new Error(`Expected number between 0.000001 and 10 for options.sigma but received ${options.sigma}`);
|
|
1570
|
-
}
|
|
1571
|
-
this.upsertNode({
|
|
1572
|
-
kind: "sharpen",
|
|
1573
|
-
sigma: options.sigma ?? -1,
|
|
1574
|
-
m1: options.m1 ?? 1,
|
|
1575
|
-
m2: options.m2 ?? 2,
|
|
1576
|
-
x1: options.x1 ?? 2,
|
|
1577
|
-
y2: options.y2 ?? 10,
|
|
1578
|
-
y3: options.y3 ?? 20
|
|
1579
|
-
});
|
|
1580
|
-
return this;
|
|
1581
|
-
}
|
|
1582
|
-
median(size = 3) {
|
|
1583
|
-
if (size === false) {
|
|
1584
|
-
const idx = this.nodes.findIndex((n) => n.kind === "median");
|
|
1585
|
-
if (idx !== -1) this.nodes.splice(idx, 1);
|
|
1586
|
-
return this;
|
|
1587
|
-
}
|
|
1588
|
-
const effSize = size === true ? 3 : size;
|
|
1589
|
-
if (!Number.isInteger(effSize) || effSize < 1 || effSize > 1e3) {
|
|
1590
|
-
throw new Error(`Expected integer between 1 and 1000 for size but received ${size}`);
|
|
1591
|
-
}
|
|
1592
|
-
this.upsertNode({ kind: "median", size: effSize });
|
|
1593
|
-
return this;
|
|
1594
|
-
}
|
|
1595
|
-
dilate(width = 1) {
|
|
1596
|
-
if (!Number.isInteger(width) || width <= 0) {
|
|
1597
|
-
throw new Error(`Expected positive integer for dilate but received ${width}`);
|
|
1598
|
-
}
|
|
1599
|
-
this.upsertNode({ kind: "dilate", width });
|
|
1600
|
-
return this;
|
|
1601
|
-
}
|
|
1602
|
-
erode(width = 1) {
|
|
1603
|
-
if (!Number.isInteger(width) || width <= 0) {
|
|
1604
|
-
throw new Error(`Expected positive integer for erode but received ${width}`);
|
|
1605
|
-
}
|
|
1606
|
-
this.upsertNode({ kind: "erode", width });
|
|
1607
|
-
return this;
|
|
1608
|
-
}
|
|
1609
|
-
convolve(kernelSpec) {
|
|
1610
|
-
if (!kernelSpec || typeof kernelSpec !== "object" || !Array.isArray(kernelSpec.kernel) || !Number.isInteger(kernelSpec.width) || !Number.isInteger(kernelSpec.height) || kernelSpec.width < 3 || kernelSpec.width > 1001 || kernelSpec.height < 3 || kernelSpec.height > 1001 || kernelSpec.width * kernelSpec.height !== kernelSpec.kernel.length) {
|
|
1611
|
-
throw new Error("Invalid convolution kernel");
|
|
1612
|
-
}
|
|
1613
|
-
const defaultScale = kernelSpec.kernel.reduce((s, v) => s + v, 0) || 1;
|
|
1614
|
-
this.upsertNode({
|
|
1615
|
-
kind: "convolve",
|
|
1616
|
-
width: kernelSpec.width,
|
|
1617
|
-
height: kernelSpec.height,
|
|
1618
|
-
kernel: [...kernelSpec.kernel],
|
|
1619
|
-
scale: kernelSpec.scale ?? defaultScale,
|
|
1620
|
-
offset: kernelSpec.offset ?? 0
|
|
1621
|
-
});
|
|
1622
|
-
return this;
|
|
1623
|
-
}
|
|
1624
|
-
ensureAlpha(alpha = 1) {
|
|
1625
|
-
if (typeof alpha !== "number" || Number.isNaN(alpha) || alpha < 0 || alpha > 1) {
|
|
1626
|
-
throw new Error(`Expected number between 0 and 1 for alpha but received ${alpha}`);
|
|
1627
|
-
}
|
|
1628
|
-
this.upsertNode({ kind: "ensureAlpha", alpha }, true);
|
|
1629
|
-
return this;
|
|
1630
|
-
}
|
|
1631
|
-
removeAlpha() {
|
|
1632
|
-
this.upsertNode({ kind: "removeAlpha" }, true);
|
|
1633
|
-
return this;
|
|
1634
|
-
}
|
|
1635
|
-
extractChannel(channel) {
|
|
1636
|
-
const ch = channel === "red" ? 0 : channel === "green" ? 1 : channel === "blue" ? 2 : channel === "alpha" ? 3 : channel;
|
|
1637
|
-
if (!Number.isInteger(ch) || ch < 0 || ch > 3) {
|
|
1638
|
-
throw new Error(`Expected integer or one of: red, green, blue, alpha for channel but received ${channel}`);
|
|
1639
|
-
}
|
|
1640
|
-
this.upsertNode({ kind: "extractChannel", channel: ch });
|
|
1641
|
-
return this;
|
|
1642
|
-
}
|
|
1643
|
-
recomb(matrix) {
|
|
1644
|
-
if (!Array.isArray(matrix) || matrix.length !== 3 && matrix.length !== 4) {
|
|
1645
|
-
throw new Error(`Expected 3x3 or 4x4 array for inputMatrix but received ${matrix?.length}`);
|
|
1646
|
-
}
|
|
1647
|
-
const flatLen = matrix.reduce((acc, row) => acc + (Array.isArray(row) ? row.length : 0), 0);
|
|
1648
|
-
if (flatLen !== 9 && flatLen !== 16) {
|
|
1649
|
-
throw new Error(`Expected 3x3 or 4x4 array with cardinality of 9 or 16 for inputMatrix`);
|
|
1650
|
-
}
|
|
1651
|
-
this.upsertNode({
|
|
1652
|
-
kind: "recomb",
|
|
1653
|
-
matrix: matrix.map((row) => [...row])
|
|
1654
|
-
});
|
|
1655
|
-
return this;
|
|
1656
|
-
}
|
|
1657
|
-
toColorspace(colorspace) {
|
|
1658
|
-
if (typeof colorspace !== "string") {
|
|
1659
|
-
throw new Error(`Expected string for colourspace but received ${colorspace}`);
|
|
1660
|
-
}
|
|
1661
|
-
const norm = colorspace.toLowerCase();
|
|
1662
|
-
const space = norm === "grey16" ? "grey16" : norm === "rgb16" ? "rgb16" : norm === "b-w" || norm === "bw" || norm === "gray" ? "b-w" : norm === "cmyk" ? "cmyk" : "srgb";
|
|
1663
|
-
if (space === "srgb" && this.nodes.some((n) => n.kind === "grayscale")) {
|
|
1664
|
-
const idx = this.nodes.findIndex((n) => n.kind === "toColorspace");
|
|
1665
|
-
if (idx !== -1) this.nodes.splice(idx, 1);
|
|
1666
|
-
return this;
|
|
1667
|
-
}
|
|
1668
|
-
this.upsertNode({ kind: "toColorspace", space });
|
|
1669
|
-
return this;
|
|
1670
|
-
}
|
|
1671
|
-
toColourspace(colourspace) {
|
|
1672
|
-
return this.toColorspace(colourspace);
|
|
1673
|
-
}
|
|
1674
|
-
pipelineColorspace(colorspace) {
|
|
1675
|
-
return this.toColorspace(colorspace);
|
|
1676
|
-
}
|
|
1677
|
-
pipelineColourspace(colourspace) {
|
|
1678
|
-
return this.toColorspace(colourspace);
|
|
1679
|
-
}
|
|
1680
|
-
bandbool(boolOp) {
|
|
1681
|
-
if (boolOp !== "and" && boolOp !== "or" && boolOp !== "eor") {
|
|
1682
|
-
throw new Error(`Expected one of: and, or, eor for boolOp but received ${boolOp}`);
|
|
1683
|
-
}
|
|
1684
|
-
this.upsertNode({ kind: "bandbool", op: boolOp });
|
|
1685
|
-
return this;
|
|
1686
|
-
}
|
|
1687
|
-
boolean(operand, op, options) {
|
|
1688
|
-
if (op !== "and" && op !== "or" && op !== "eor") {
|
|
1689
|
-
throw new Error(`Expected one of: and, or, eor for operator but received ${op}`);
|
|
1690
|
-
}
|
|
1691
|
-
const data = this.operationInput(operand);
|
|
1692
|
-
if (data) {
|
|
1693
|
-
this.nodes.push({
|
|
1694
|
-
kind: "boolean",
|
|
1695
|
-
operand: data,
|
|
1696
|
-
op,
|
|
1697
|
-
...options?.raw !== void 0 ? { options: { raw: options.raw } } : {}
|
|
1698
|
-
});
|
|
1699
|
-
}
|
|
1700
|
-
return this;
|
|
1701
|
-
}
|
|
1702
|
-
joinChannel(images, options) {
|
|
1703
|
-
const list = Array.isArray(images) ? images : [images];
|
|
1704
|
-
this.nodes.push({
|
|
1705
|
-
kind: "joinChannel",
|
|
1706
|
-
inputs: list.map((buf) => {
|
|
1707
|
-
const data = this.operationInput(buf);
|
|
1708
|
-
if (!data) {
|
|
1709
|
-
throw new Error(`Unsupported joinChannel input: ${typeof buf}`);
|
|
1710
|
-
}
|
|
1711
|
-
return {
|
|
1712
|
-
data,
|
|
1713
|
-
...options !== void 0 ? { options } : {}
|
|
1714
|
-
};
|
|
1715
|
-
})
|
|
1716
|
-
});
|
|
1717
|
-
return this;
|
|
1718
|
-
}
|
|
1719
|
-
clahe(options) {
|
|
1720
|
-
if (!options || typeof options !== "object") {
|
|
1721
|
-
throw new Error("Expected plain object for clahe options");
|
|
1722
|
-
}
|
|
1723
|
-
if (!Number.isInteger(options.width) || options.width <= 0) {
|
|
1724
|
-
throw new Error(`Expected integer greater than zero for width but received ${options.width}`);
|
|
1725
|
-
}
|
|
1726
|
-
if (!Number.isInteger(options.height) || options.height <= 0) {
|
|
1727
|
-
throw new Error(`Expected integer greater than zero for height but received ${options.height}`);
|
|
1728
|
-
}
|
|
1729
|
-
if (options.maxSlope !== void 0 && (!Number.isInteger(options.maxSlope) || options.maxSlope < 0 || options.maxSlope > 100)) {
|
|
1730
|
-
throw new Error(`Expected integer between 0 and 100 for maxSlope but received ${options.maxSlope}`);
|
|
1731
|
-
}
|
|
1732
|
-
this.upsertNode({
|
|
1733
|
-
kind: "clahe",
|
|
1734
|
-
width: options.width,
|
|
1735
|
-
height: options.height,
|
|
1736
|
-
maxSlope: options.maxSlope ?? 3
|
|
1737
|
-
});
|
|
1738
|
-
return this;
|
|
1739
|
-
}
|
|
1740
|
-
affine(matrix, options) {
|
|
1741
|
-
const rawFlat = Array.isArray(matrix) ? Array.isArray(matrix[0]) ? [...matrix[0], ...matrix[1] ?? []] : [...matrix] : [];
|
|
1742
|
-
if (rawFlat.length !== 4 || rawFlat.some((v) => typeof v !== "number" || Number.isNaN(v))) {
|
|
1743
|
-
throw new Error(`Expected 1x4 or 2x2 array for matrix but received ${matrix} of type ${typeof matrix}`);
|
|
1744
|
-
}
|
|
1745
|
-
if (options?.interpolator !== void 0 && !["nearest", "bilinear", "bicubic", "lbb", "nohalo", "vsqbs"].includes(options.interpolator)) {
|
|
1746
|
-
throw new Error(
|
|
1747
|
-
`Expected valid interpolator name for options.interpolator but received ${options.interpolator} of type ${typeof options.interpolator}`
|
|
1748
|
-
);
|
|
1749
|
-
}
|
|
1750
|
-
for (const key of ["idx", "idy", "odx", "ody"]) {
|
|
1751
|
-
const val = options?.[key];
|
|
1752
|
-
if (val !== void 0 && (typeof val !== "number" || Number.isNaN(val))) {
|
|
1753
|
-
throw new Error(`Expected number for options.${key} but received ${val} of type ${typeof val}`);
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
const flat = [rawFlat[0], rawFlat[1], rawFlat[2], rawFlat[3]];
|
|
1757
|
-
this.upsertNode({
|
|
1758
|
-
kind: "affine",
|
|
1759
|
-
matrix: flat,
|
|
1760
|
-
background: parseColor(options?.background ?? "#000000", 255),
|
|
1761
|
-
idx: options?.idx ?? 0,
|
|
1762
|
-
idy: options?.idy ?? 0,
|
|
1763
|
-
odx: options?.odx ?? 0,
|
|
1764
|
-
ody: options?.ody ?? 0,
|
|
1765
|
-
...options?.interpolator !== void 0 ? { interpolator: options.interpolator } : {}
|
|
1766
|
-
});
|
|
1767
|
-
return this;
|
|
1768
|
-
}
|
|
1769
|
-
withMetadata(options) {
|
|
1770
|
-
if (options && typeof options === "object") {
|
|
1771
|
-
if (options.orientation !== void 0 && (!Number.isInteger(options.orientation) || options.orientation < 1 || options.orientation > 8)) {
|
|
1772
|
-
throw new Error(`Expected integer between 1 and 8 for orientation but received ${options.orientation}`);
|
|
1773
|
-
}
|
|
1774
|
-
if (options.density !== void 0 && (typeof options.density !== "number" || Number.isNaN(options.density) || options.density <= 0)) {
|
|
1775
|
-
throw new Error(`Expected positive number for density but received ${options.density}`);
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
const existingIdx = this.nodes.findIndex((n) => n.kind === "withMetadata");
|
|
1779
|
-
const prev = existingIdx !== -1 ? this.nodes[existingIdx] : void 0;
|
|
1780
|
-
const density = options?.density ?? prev?.density;
|
|
1781
|
-
const orientation = options?.orientation ?? prev?.orientation;
|
|
1782
|
-
this.upsertNode({
|
|
1783
|
-
kind: "withMetadata",
|
|
1784
|
-
...density !== void 0 ? { density } : {},
|
|
1785
|
-
...orientation !== void 0 ? { orientation } : {}
|
|
1786
|
-
});
|
|
1787
|
-
this.outputOptions = {
|
|
1788
|
-
...this.outputOptions,
|
|
1789
|
-
...density !== void 0 ? { density } : {},
|
|
1790
|
-
...orientation !== void 0 ? { orientation } : {}
|
|
1791
|
-
};
|
|
1792
|
-
return this;
|
|
1793
|
-
}
|
|
1794
|
-
keepExif() {
|
|
1795
|
-
return this.withMetadata();
|
|
1796
|
-
}
|
|
1797
|
-
withExif(exif) {
|
|
1798
|
-
if (!exif || typeof exif !== "object" || Array.isArray(exif)) {
|
|
1799
|
-
throw new Error(`Expected object for exif but received ${exif}`);
|
|
1800
|
-
}
|
|
1801
|
-
const orientStr = exif?.IFD0?.Orientation;
|
|
1802
|
-
const orientNum = orientStr !== void 0 ? Number(orientStr) : void 0;
|
|
1803
|
-
return this.withMetadata(orientNum !== void 0 && Number.isFinite(orientNum) ? { orientation: orientNum } : void 0);
|
|
1804
|
-
}
|
|
1805
|
-
withExifMerge(exif) {
|
|
1806
|
-
return this.withExif(exif);
|
|
1807
|
-
}
|
|
1808
|
-
keepIccProfile() {
|
|
1809
|
-
return this;
|
|
1810
|
-
}
|
|
1811
|
-
withIccProfile(profile, _options) {
|
|
1812
|
-
if (typeof profile !== "string") {
|
|
1813
|
-
throw new Error(`Expected string for icc but received ${profile}`);
|
|
1814
|
-
}
|
|
1815
|
-
return this;
|
|
1816
|
-
}
|
|
1817
|
-
timeout(options) {
|
|
1818
|
-
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
1819
|
-
throw new Error(`Expected object for options but received ${options}`);
|
|
1820
|
-
}
|
|
1821
|
-
if (!Number.isInteger(options.seconds) || options.seconds < 0 || options.seconds > 3600) {
|
|
1822
|
-
throw new Error(`Expected integer between 0 and 3600 for seconds but received ${options.seconds}`);
|
|
1823
|
-
}
|
|
1824
|
-
return this;
|
|
1825
|
-
}
|
|
1826
|
-
keepXmp() {
|
|
1827
|
-
return this;
|
|
1828
|
-
}
|
|
1829
|
-
withXmp(xmp) {
|
|
1830
|
-
if (typeof xmp !== "string" || xmp.length === 0) {
|
|
1831
|
-
throw new Error(`Expected non-empty string for xmp but received ${xmp}`);
|
|
1832
|
-
}
|
|
1833
|
-
return this;
|
|
1834
|
-
}
|
|
1835
|
-
keepMetadata() {
|
|
1836
|
-
return this.withMetadata();
|
|
1837
|
-
}
|
|
1838
|
-
validateQuality(q) {
|
|
1839
|
-
if (q !== void 0 && (!Number.isInteger(q) || q < 1 || q > 100)) {
|
|
1840
|
-
throw new Error(`Expected integer between 1 and 100 for quality but received ${q}`);
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
validateCompressionLevel(level) {
|
|
1844
|
-
if (level !== void 0 && (!Number.isInteger(level) || level < 0 || level > 9)) {
|
|
1845
|
-
throw new Error(`Expected integer between 0 and 9 for compressionLevel but received ${level}`);
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
jp2(options) {
|
|
1849
|
-
this.validateQuality(options?.quality);
|
|
1850
|
-
return this.png(options);
|
|
1851
|
-
}
|
|
1852
|
-
jxl(options) {
|
|
1853
|
-
this.validateQuality(options?.quality);
|
|
1854
|
-
return this.png(options);
|
|
1855
|
-
}
|
|
1856
|
-
tile(_options) {
|
|
1857
|
-
return this;
|
|
1858
|
-
}
|
|
1859
|
-
png(options) {
|
|
1860
|
-
this.validateCompressionLevel(options?.compressionLevel);
|
|
1861
|
-
this.validateQuality(options?.quality);
|
|
1862
|
-
const anyOpts = options;
|
|
1863
|
-
for (const [k, label] of [
|
|
1864
|
-
["progressive", "pngProgressive"],
|
|
1865
|
-
["adaptiveFiltering", "pngAdaptiveFiltering"],
|
|
1866
|
-
["palette", "pngPalette"]
|
|
1867
|
-
]) {
|
|
1868
|
-
if (anyOpts?.[k] !== void 0 && typeof anyOpts[k] !== "boolean") {
|
|
1869
|
-
throw new Error(`Expected boolean for ${label} but received ${anyOpts[k]} of type ${typeof anyOpts[k]}`);
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
if (anyOpts?.effort !== void 0 && (!Number.isInteger(anyOpts.effort) || anyOpts.effort < 1 || anyOpts.effort > 10)) {
|
|
1873
|
-
throw new Error(`Expected integer between 1 and 10 for effort but received ${anyOpts.effort} of type ${typeof anyOpts.effort}`);
|
|
1874
|
-
}
|
|
1875
|
-
const colours = anyOpts?.colours ?? anyOpts?.colors;
|
|
1876
|
-
if (colours !== void 0 && (!Number.isInteger(colours) || colours < 2 || colours > 256)) {
|
|
1877
|
-
throw new Error(`Expected integer between 2 and 256 for colours but received ${colours} of type ${typeof colours}`);
|
|
1878
|
-
}
|
|
1879
|
-
if (anyOpts?.dither !== void 0 && (typeof anyOpts.dither !== "number" || Number.isNaN(anyOpts.dither) || anyOpts.dither < 0 || anyOpts.dither > 1)) {
|
|
1880
|
-
throw new Error(`Expected number between 0.0 and 1.0 for dither but received ${anyOpts.dither} of type ${typeof anyOpts.dither}`);
|
|
1881
|
-
}
|
|
1882
|
-
if (anyOpts?.bitdepth !== void 0 && ![1, 2, 4, 8, 16].includes(anyOpts.bitdepth)) {
|
|
1883
|
-
throw new Error(`Expected 1, 2, 4, 8 or 16 for bitdepth but received ${anyOpts.bitdepth} of type ${typeof anyOpts.bitdepth}`);
|
|
1884
|
-
}
|
|
1885
|
-
this.outputOptions = {
|
|
1886
|
-
...this.outputOptions,
|
|
1887
|
-
...options?.force === false ? {} : { format: "png" },
|
|
1888
|
-
...options?.compressionLevel !== void 0 ? { compressionLevel: options.compressionLevel } : {},
|
|
1889
|
-
...options?.palette !== void 0 ? { palette: options.palette } : {}
|
|
1890
|
-
};
|
|
1891
|
-
return this;
|
|
1892
|
-
}
|
|
1893
|
-
jpeg(options) {
|
|
1894
|
-
this.validateQuality(options?.quality);
|
|
1895
|
-
const anyOpts = options;
|
|
1896
|
-
for (const [k, label] of [
|
|
1897
|
-
["progressive", "jpegProgressive"],
|
|
1898
|
-
["trellisQuantisation", "jpegTrellisQuantisation"],
|
|
1899
|
-
["overshootDeringing", "jpegOvershootDeringing"],
|
|
1900
|
-
["optimiseScans", "jpegOptimiseScans"],
|
|
1901
|
-
["optimiseCoding", "jpegOptimiseCoding"],
|
|
1902
|
-
["mozjpeg", "mozjpeg"]
|
|
1903
|
-
]) {
|
|
1904
|
-
if (anyOpts?.[k] !== void 0 && typeof anyOpts[k] !== "boolean") {
|
|
1905
|
-
throw new Error(`Expected boolean for ${label} but received ${anyOpts[k]} of type ${typeof anyOpts[k]}`);
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
if (anyOpts?.chromaSubsampling !== void 0 && typeof anyOpts.chromaSubsampling !== "string") {
|
|
1909
|
-
throw new Error(`Expected one of: 4:2:0, 4:4:4 for chromaSubsampling but received ${anyOpts.chromaSubsampling} of type ${typeof anyOpts.chromaSubsampling}`);
|
|
1910
|
-
}
|
|
1911
|
-
const qTable = anyOpts?.quantisationTable ?? anyOpts?.quantizationTable;
|
|
1912
|
-
if (qTable !== void 0 && (!Number.isInteger(qTable) || qTable < 0 || qTable > 8)) {
|
|
1913
|
-
throw new Error(`Expected integer between 0 and 8 for quantisationTable but received ${qTable} of type ${typeof qTable}`);
|
|
1914
|
-
}
|
|
1915
|
-
this.outputOptions = {
|
|
1916
|
-
...this.outputOptions,
|
|
1917
|
-
...options?.force === false ? {} : { format: "jpeg" },
|
|
1918
|
-
...options?.quality !== void 0 ? { quality: options.quality } : {}
|
|
1919
|
-
};
|
|
1920
|
-
return this;
|
|
1921
|
-
}
|
|
1922
|
-
webp(options) {
|
|
1923
|
-
this.validateQuality(options?.quality);
|
|
1924
|
-
const anyOpts = options;
|
|
1925
|
-
for (const [k, label] of [
|
|
1926
|
-
["lossless", "webpLossless"],
|
|
1927
|
-
["nearLossless", "webpNearLossless"],
|
|
1928
|
-
["smartSubsample", "webpSmartSubsample"],
|
|
1929
|
-
["smartDeblock", "webpSmartDeblock"],
|
|
1930
|
-
["minSize", "webpMinSize"],
|
|
1931
|
-
["mixed", "webpMixed"]
|
|
1932
|
-
]) {
|
|
1933
|
-
if (anyOpts?.[k] !== void 0 && typeof anyOpts[k] !== "boolean") {
|
|
1934
|
-
throw new Error(`Expected boolean for ${label} but received ${anyOpts[k]} of type ${typeof anyOpts[k]}`);
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
if (anyOpts?.alphaQuality !== void 0 && (!Number.isInteger(anyOpts.alphaQuality) || anyOpts.alphaQuality < 0 || anyOpts.alphaQuality > 100)) {
|
|
1938
|
-
throw new Error(
|
|
1939
|
-
`Expected integer between 0 and 100 for alphaQuality but received ${anyOpts.alphaQuality} of type ${typeof anyOpts.alphaQuality}`
|
|
1940
|
-
);
|
|
1941
|
-
}
|
|
1942
|
-
if (anyOpts?.effort !== void 0 && (!Number.isInteger(anyOpts.effort) || anyOpts.effort < 0 || anyOpts.effort > 6)) {
|
|
1943
|
-
throw new Error(`Expected integer between 0 and 6 for effort but received ${anyOpts.effort} of type ${typeof anyOpts.effort}`);
|
|
1944
|
-
}
|
|
1945
|
-
if (anyOpts?.preset !== void 0 && !["default", "photo", "picture", "drawing", "icon", "text"].includes(anyOpts.preset)) {
|
|
1946
|
-
throw new Error(
|
|
1947
|
-
`Expected one of: default, photo, picture, drawing, icon, text for preset but received ${anyOpts.preset} of type ${typeof anyOpts.preset}`
|
|
1948
|
-
);
|
|
1949
|
-
}
|
|
1950
|
-
this.outputOptions = {
|
|
1951
|
-
...this.outputOptions,
|
|
1952
|
-
...options?.force === false ? {} : { format: "webp" },
|
|
1953
|
-
...options?.quality !== void 0 ? { quality: options.quality } : {},
|
|
1954
|
-
...options?.lossless !== void 0 ? { lossless: options.lossless } : {}
|
|
1955
|
-
};
|
|
1956
|
-
return this;
|
|
1957
|
-
}
|
|
1958
|
-
heif(options) {
|
|
1959
|
-
this.validateQuality(options?.quality);
|
|
1960
|
-
if (options?.compression !== void 0 && !["av1", "hevc"].includes(options.compression)) {
|
|
1961
|
-
throw new Error(`Expected one of: av1, hevc for compression but received ${options.compression} of type ${typeof options.compression}`);
|
|
1962
|
-
}
|
|
1963
|
-
const anyOpts = options;
|
|
1964
|
-
if (anyOpts?.lossless !== void 0 && typeof anyOpts.lossless !== "boolean") {
|
|
1965
|
-
throw new Error(`Expected boolean for lossless but received ${anyOpts.lossless} of type ${typeof anyOpts.lossless}`);
|
|
1966
|
-
}
|
|
1967
|
-
if (anyOpts?.chromaSubsampling !== void 0 && typeof anyOpts.chromaSubsampling !== "string") {
|
|
1968
|
-
throw new Error(`Expected one of: 4:2:0, 4:4:4 for chromaSubsampling but received ${anyOpts.chromaSubsampling} of type ${typeof anyOpts.chromaSubsampling}`);
|
|
1969
|
-
}
|
|
1970
|
-
if (anyOpts?.bitdepth !== void 0 && ![8, 10, 12].includes(anyOpts.bitdepth)) {
|
|
1971
|
-
throw new Error(`Expected 8, 10 or 12 for bitdepth but received ${anyOpts.bitdepth} of type ${typeof anyOpts.bitdepth}`);
|
|
1972
|
-
}
|
|
1973
|
-
if (anyOpts?.effort !== void 0 && (!Number.isInteger(anyOpts.effort) || anyOpts.effort < 0 || anyOpts.effort > 9)) {
|
|
1974
|
-
throw new Error(`Expected integer between 0 and 9 for effort but received ${anyOpts.effort} of type ${typeof anyOpts.effort}`);
|
|
1975
|
-
}
|
|
1976
|
-
this.outputOptions = {
|
|
1977
|
-
...this.outputOptions,
|
|
1978
|
-
...options?.force === false ? {} : { format: "heif" },
|
|
1979
|
-
...options?.quality !== void 0 ? { quality: options.quality } : {},
|
|
1980
|
-
...options?.compression !== void 0 ? { compression: options.compression } : {},
|
|
1981
|
-
...options?.lossless !== void 0 ? { lossless: options.lossless } : {}
|
|
1982
|
-
};
|
|
1983
|
-
return this;
|
|
1984
|
-
}
|
|
1985
|
-
heic(options) {
|
|
1986
|
-
this.validateQuality(options?.quality);
|
|
1987
|
-
this.outputOptions = {
|
|
1988
|
-
...this.outputOptions,
|
|
1989
|
-
...options?.force === false ? {} : { format: "heic" },
|
|
1990
|
-
compression: options?.compression ?? "hevc",
|
|
1991
|
-
...options?.quality !== void 0 ? { quality: options.quality } : {},
|
|
1992
|
-
...options?.lossless !== void 0 ? { lossless: options.lossless } : {}
|
|
1993
|
-
};
|
|
1994
|
-
return this;
|
|
1995
|
-
}
|
|
1996
|
-
avif(options) {
|
|
1997
|
-
this.validateQuality(options?.quality);
|
|
1998
|
-
const anyOpts = options;
|
|
1999
|
-
if (anyOpts?.lossless !== void 0 && typeof anyOpts.lossless !== "boolean") {
|
|
2000
|
-
throw new Error(`Expected boolean for lossless but received ${anyOpts.lossless} of type ${typeof anyOpts.lossless}`);
|
|
2001
|
-
}
|
|
2002
|
-
if (anyOpts?.chromaSubsampling !== void 0 && typeof anyOpts.chromaSubsampling !== "string") {
|
|
2003
|
-
throw new Error(`Expected one of: 4:2:0, 4:4:4 for chromaSubsampling but received ${anyOpts.chromaSubsampling} of type ${typeof anyOpts.chromaSubsampling}`);
|
|
2004
|
-
}
|
|
2005
|
-
if (anyOpts?.bitdepth !== void 0 && ![8, 10, 12].includes(anyOpts.bitdepth)) {
|
|
2006
|
-
throw new Error(`Expected 8, 10 or 12 for bitdepth but received ${anyOpts.bitdepth} of type ${typeof anyOpts.bitdepth}`);
|
|
2007
|
-
}
|
|
2008
|
-
if (anyOpts?.effort !== void 0 && (!Number.isInteger(anyOpts.effort) || anyOpts.effort < 0 || anyOpts.effort > 9)) {
|
|
2009
|
-
throw new Error(`Expected integer between 0 and 9 for effort but received ${anyOpts.effort} of type ${typeof anyOpts.effort}`);
|
|
2010
|
-
}
|
|
2011
|
-
this.outputOptions = {
|
|
2012
|
-
...this.outputOptions,
|
|
2013
|
-
...options?.force === false ? {} : { format: "avif" },
|
|
2014
|
-
compression: "av1",
|
|
2015
|
-
...options?.quality !== void 0 ? { quality: options.quality } : {},
|
|
2016
|
-
...options?.lossless !== void 0 ? { lossless: options.lossless } : {}
|
|
2017
|
-
};
|
|
2018
|
-
return this;
|
|
2019
|
-
}
|
|
2020
|
-
gif(options) {
|
|
2021
|
-
const anyOpts = options;
|
|
2022
|
-
if (anyOpts?.reuse !== void 0 && typeof anyOpts.reuse !== "boolean") {
|
|
2023
|
-
throw new Error(`Expected boolean for gifReuse but received ${anyOpts.reuse} of type ${typeof anyOpts.reuse}`);
|
|
2024
|
-
}
|
|
2025
|
-
const prog = anyOpts?.progressive;
|
|
2026
|
-
if (prog !== void 0 && typeof prog !== "boolean") {
|
|
2027
|
-
throw new Error(`Expected boolean for gifProgressive but received ${prog} of type ${typeof prog}`);
|
|
2028
|
-
}
|
|
2029
|
-
const colours = anyOpts?.colours ?? anyOpts?.colors;
|
|
2030
|
-
if (colours !== void 0 && (!Number.isInteger(colours) || colours < 2 || colours > 256)) {
|
|
2031
|
-
throw new Error(`Expected integer between 2 and 256 for colours but received ${colours} of type ${typeof colours}`);
|
|
2032
|
-
}
|
|
2033
|
-
if (anyOpts?.effort !== void 0 && (!Number.isInteger(anyOpts.effort) || anyOpts.effort < 1 || anyOpts.effort > 10)) {
|
|
2034
|
-
throw new Error(`Expected integer between 1 and 10 for effort but received ${anyOpts.effort} of type ${typeof anyOpts.effort}`);
|
|
2035
|
-
}
|
|
2036
|
-
if (anyOpts?.dither !== void 0 && (typeof anyOpts.dither !== "number" || Number.isNaN(anyOpts.dither) || anyOpts.dither < 0 || anyOpts.dither > 1)) {
|
|
2037
|
-
throw new Error(`Expected number between 0.0 and 1.0 for dither but received ${anyOpts.dither} of type ${typeof anyOpts.dither}`);
|
|
2038
|
-
}
|
|
2039
|
-
if (anyOpts?.interFrameMaxError !== void 0 && (typeof anyOpts.interFrameMaxError !== "number" || Number.isNaN(anyOpts.interFrameMaxError) || anyOpts.interFrameMaxError < 0 || anyOpts.interFrameMaxError > 32)) {
|
|
2040
|
-
throw new Error(`Expected number between 0.0 and 32.0 for interFrameMaxError but received ${anyOpts.interFrameMaxError} of type ${typeof anyOpts.interFrameMaxError}`);
|
|
2041
|
-
}
|
|
2042
|
-
if (anyOpts?.interPaletteMaxError !== void 0 && (typeof anyOpts.interPaletteMaxError !== "number" || Number.isNaN(anyOpts.interPaletteMaxError) || anyOpts.interPaletteMaxError < 0 || anyOpts.interPaletteMaxError > 256)) {
|
|
2043
|
-
throw new Error(`Expected number between 0.0 and 256.0 for interPaletteMaxError but received ${anyOpts.interPaletteMaxError} of type ${typeof anyOpts.interPaletteMaxError}`);
|
|
2044
|
-
}
|
|
2045
|
-
if (options?.loop !== void 0 && (!Number.isInteger(options.loop) || options.loop < 0 || options.loop > 65535)) {
|
|
2046
|
-
throw new Error(`Expected integer between 0 and 65535 for loop but received ${options.loop} of type ${typeof options.loop}`);
|
|
2047
|
-
}
|
|
2048
|
-
if (options?.delay !== void 0) {
|
|
2049
|
-
const isValidDelay = Number.isInteger(options.delay) && options.delay >= 0 && options.delay <= 65535 || Array.isArray(options.delay) && options.delay.every((d) => Number.isInteger(d) && d >= 0 && d <= 65535);
|
|
2050
|
-
if (!isValidDelay) {
|
|
2051
|
-
throw new Error(
|
|
2052
|
-
`Expected integer or an array of integers between 0 and 65535 for delay but received ${options.delay} of type ${typeof options.delay}`
|
|
2053
|
-
);
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
this.outputOptions = {
|
|
2057
|
-
...this.outputOptions,
|
|
2058
|
-
...options?.force === false ? {} : { format: "gif" },
|
|
2059
|
-
...options?.pageHeight !== void 0 ? { pageHeight: options.pageHeight } : {},
|
|
2060
|
-
...options?.delay !== void 0 ? { delay: options.delay } : {},
|
|
2061
|
-
...options?.loop !== void 0 ? { loop: options.loop } : {}
|
|
2062
|
-
};
|
|
2063
|
-
return this;
|
|
2064
|
-
}
|
|
2065
|
-
ppm() {
|
|
2066
|
-
this.outputOptions = { ...this.outputOptions, format: "ppm" };
|
|
2067
|
-
return this;
|
|
2068
|
-
}
|
|
2069
|
-
pgm() {
|
|
2070
|
-
this.outputOptions = { ...this.outputOptions, format: "pgm" };
|
|
2071
|
-
return this;
|
|
2072
|
-
}
|
|
2073
|
-
pbm() {
|
|
2074
|
-
this.outputOptions = { ...this.outputOptions, format: "pbm" };
|
|
2075
|
-
return this;
|
|
2076
|
-
}
|
|
2077
|
-
bmp() {
|
|
2078
|
-
this.outputOptions = { ...this.outputOptions, format: "bmp" };
|
|
2079
|
-
return this;
|
|
2080
|
-
}
|
|
2081
|
-
tiff(options) {
|
|
2082
|
-
this.validateQuality(options?.quality);
|
|
2083
|
-
const anyOpts = options;
|
|
2084
|
-
if (anyOpts?.predictor !== void 0 && !["none", "horizontal", "float"].includes(anyOpts.predictor)) {
|
|
2085
|
-
throw new Error(`Expected one of: none, horizontal, float for predictor but received ${anyOpts.predictor} of type ${typeof anyOpts.predictor}`);
|
|
2086
|
-
}
|
|
2087
|
-
for (const [k, label] of [
|
|
2088
|
-
["pyramid", "tiffPyramid"],
|
|
2089
|
-
["tile", "tiffTile"],
|
|
2090
|
-
["miniswhite", "tiffMiniswhite"]
|
|
2091
|
-
]) {
|
|
2092
|
-
if (anyOpts?.[k] !== void 0 && typeof anyOpts[k] !== "boolean") {
|
|
2093
|
-
throw new Error(`Expected boolean for ${label} but received ${anyOpts[k]} of type ${typeof anyOpts[k]}`);
|
|
2094
|
-
}
|
|
2095
|
-
}
|
|
2096
|
-
if (anyOpts?.tileWidth !== void 0 && (!Number.isInteger(anyOpts.tileWidth) || anyOpts.tileWidth <= 0)) {
|
|
2097
|
-
throw new Error(`Expected integer greater than zero for tileWidth but received ${anyOpts.tileWidth} of type ${typeof anyOpts.tileWidth}`);
|
|
2098
|
-
}
|
|
2099
|
-
if (anyOpts?.tileHeight !== void 0 && (!Number.isInteger(anyOpts.tileHeight) || anyOpts.tileHeight <= 0)) {
|
|
2100
|
-
throw new Error(`Expected integer greater than zero for tileHeight but received ${anyOpts.tileHeight} of type ${typeof anyOpts.tileHeight}`);
|
|
2101
|
-
}
|
|
2102
|
-
if (anyOpts?.xres !== void 0 && (typeof anyOpts.xres !== "number" || Number.isNaN(anyOpts.xres) || anyOpts.xres <= 0)) {
|
|
2103
|
-
throw new Error(`Expected number greater than zero for xres but received ${anyOpts.xres} of type ${typeof anyOpts.xres}`);
|
|
2104
|
-
}
|
|
2105
|
-
if (anyOpts?.yres !== void 0 && (typeof anyOpts.yres !== "number" || Number.isNaN(anyOpts.yres) || anyOpts.yres <= 0)) {
|
|
2106
|
-
throw new Error(`Expected number greater than zero for yres but received ${anyOpts.yres} of type ${typeof anyOpts.yres}`);
|
|
2107
|
-
}
|
|
2108
|
-
if (anyOpts?.resolutionUnit !== void 0 && !["inch", "cm"].includes(anyOpts.resolutionUnit)) {
|
|
2109
|
-
throw new Error(`Expected one of: inch, cm for resolutionUnit but received ${anyOpts.resolutionUnit} of type ${typeof anyOpts.resolutionUnit}`);
|
|
2110
|
-
}
|
|
2111
|
-
if (anyOpts?.compression !== void 0 && !["none", "jpeg", "deflate", "packbits", "ccittfax4", "lzw", "webp", "zstd", "jp2k"].includes(anyOpts.compression)) {
|
|
2112
|
-
throw new Error(
|
|
2113
|
-
`Expected one of: none, jpeg, deflate, packbits, ccittfax4, lzw, webp, zstd, jp2k for compression but received ${anyOpts.compression} of type ${typeof anyOpts.compression}`
|
|
2114
|
-
);
|
|
2115
|
-
}
|
|
2116
|
-
if (anyOpts?.bitdepth !== void 0 && ![1, 2, 4, 8].includes(anyOpts.bitdepth)) {
|
|
2117
|
-
throw new Error(`Expected 1, 2, 4 or 8 for bitdepth but received ${anyOpts.bitdepth} of type ${typeof anyOpts.bitdepth}`);
|
|
2118
|
-
}
|
|
2119
|
-
this.outputOptions = {
|
|
2120
|
-
...this.outputOptions,
|
|
2121
|
-
...options?.force === false ? {} : { format: "tiff" },
|
|
2122
|
-
...options?.quality !== void 0 ? { quality: options.quality } : {}
|
|
2123
|
-
};
|
|
2124
|
-
return this;
|
|
2125
|
-
}
|
|
2126
|
-
raw(options) {
|
|
2127
|
-
if (options?.depth !== void 0 && !["char", "uchar", "short", "ushort", "int", "uint", "float", "complex", "double", "dpcomplex"].includes(options.depth)) {
|
|
2128
|
-
throw new Error(
|
|
2129
|
-
`Expected one of: char, uchar, short, ushort, int, uint, float, complex, double, dpcomplex for depth but received ${options.depth} of type ${typeof options.depth}`
|
|
2130
|
-
);
|
|
2131
|
-
}
|
|
2132
|
-
this.outputOptions = {
|
|
2133
|
-
...this.outputOptions,
|
|
2134
|
-
format: "raw",
|
|
2135
|
-
...options?.depth !== void 0 ? { rawDepth: options.depth } : {}
|
|
2136
|
-
};
|
|
2137
|
-
return this;
|
|
2138
|
-
}
|
|
2139
|
-
toFormat(format, options) {
|
|
2140
|
-
const rawFmt = typeof format === "object" && format !== null ? format.id : String(format);
|
|
2141
|
-
const lower = rawFmt.toLowerCase();
|
|
2142
|
-
const norm = lower === "jpg" || lower === "jpe" ? "jpeg" : lower === "tif" ? "tiff" : lower;
|
|
2143
|
-
const validFormats = [
|
|
2144
|
-
"jpeg",
|
|
2145
|
-
"png",
|
|
2146
|
-
"webp",
|
|
2147
|
-
"tiff",
|
|
2148
|
-
"heif",
|
|
2149
|
-
"heic",
|
|
2150
|
-
"avif",
|
|
2151
|
-
"gif",
|
|
2152
|
-
"svg",
|
|
2153
|
-
"pdf",
|
|
2154
|
-
"ppm",
|
|
2155
|
-
"pgm",
|
|
2156
|
-
"pbm",
|
|
2157
|
-
"bmp",
|
|
2158
|
-
"raw",
|
|
2159
|
-
"jp2",
|
|
2160
|
-
"jxl"
|
|
2161
|
-
];
|
|
2162
|
-
if (!validFormats.includes(norm)) {
|
|
2163
|
-
throw new Error(`Expected one of: ${validFormats.join(", ")} for format but received ${rawFmt}`);
|
|
2164
|
-
}
|
|
2165
|
-
this.validateQuality(options?.quality);
|
|
2166
|
-
this.validateCompressionLevel(options?.compressionLevel);
|
|
2167
|
-
this.outputOptions = {
|
|
2168
|
-
...this.outputOptions,
|
|
2169
|
-
...options?.force === false ? {} : { format: norm },
|
|
2170
|
-
...options?.quality !== void 0 ? { quality: options.quality } : {},
|
|
2171
|
-
...options?.compression !== void 0 ? { compression: options.compression } : {},
|
|
2172
|
-
...options?.compressionLevel !== void 0 ? { compressionLevel: options.compressionLevel } : {},
|
|
2173
|
-
...options?.lossless !== void 0 ? { lossless: options.lossless } : {}
|
|
2174
|
-
};
|
|
2175
|
-
return this;
|
|
2176
|
-
}
|
|
2177
|
-
toBufferWithObjectSync() {
|
|
2178
|
-
let img = this.evaluateImage();
|
|
2179
|
-
if (this.outputOptions.format === "raw" && (img.channels === 2 || img.channels === 1 && this.nodes.some((n) => n.kind === "removeAlpha" || n.kind === "flatten")) && !this.nodes.some(
|
|
2180
|
-
(n) => n.kind === "toColorspace" && n.space === "b-w" || n.kind === "grayscale" || n.kind === "joinChannel" || n.kind === "extractChannel"
|
|
2181
|
-
)) {
|
|
2182
|
-
img = { ...img, space: "srgb", channels: img.hasAlpha ? 4 : 3 };
|
|
2183
|
-
}
|
|
2184
|
-
const encoded2 = encodeImage(img, this.outputOptions);
|
|
2185
|
-
const outBuf = outputBytes(encoded2.data);
|
|
2186
|
-
return {
|
|
2187
|
-
data: outBuf,
|
|
2188
|
-
info: {
|
|
2189
|
-
format: encoded2.format,
|
|
2190
|
-
width: img.width,
|
|
2191
|
-
height: img.height,
|
|
2192
|
-
channels: encoded2.channels,
|
|
2193
|
-
...encoded2.format === "raw" ? { depth: this.outputOptions.rawDepth ?? img.depth } : {},
|
|
2194
|
-
premultiplied: Boolean(img.wasPremultiplied),
|
|
2195
|
-
...img.pageHeight !== void 0 ? { pageHeight: img.pageHeight } : {},
|
|
2196
|
-
...img.pageHeight !== void 0 && (img.sourcePages ?? img.pages) !== void 0 ? { pages: img.sourcePages ?? img.pages } : {},
|
|
2197
|
-
...img.trimOffsetLeft !== void 0 ? { trimOffsetLeft: img.trimOffsetLeft } : {},
|
|
2198
|
-
...img.trimOffsetTop !== void 0 ? { trimOffsetTop: img.trimOffsetTop } : {},
|
|
2199
|
-
...img.textAutofitDpi !== void 0 ? { textAutofitDpi: img.textAutofitDpi } : {},
|
|
2200
|
-
size: encoded2.data.byteLength
|
|
2201
|
-
}
|
|
2202
|
-
};
|
|
2203
|
-
}
|
|
2204
|
-
toBufferSync() {
|
|
2205
|
-
return this.toBufferWithObjectSync().data;
|
|
2206
|
-
}
|
|
2207
|
-
async toFile(fileOut, callback) {
|
|
2208
|
-
try {
|
|
2209
|
-
if (!fileOut || typeof fileOut !== "string") {
|
|
2210
|
-
throw new Error("Missing output file path");
|
|
2211
|
-
}
|
|
2212
|
-
if (this.inputFilePath && normalizePath(fileOut) === normalizePath(this.inputFilePath)) {
|
|
2213
|
-
throw new Error("Cannot use same file for input and output");
|
|
2214
|
-
}
|
|
2215
|
-
const filesystem = this.inputOptions?.filesystem;
|
|
2216
|
-
if (!filesystem) throw new Error("File outputs require an explicit filesystem");
|
|
2217
|
-
const prevFormat = this.outputOptions.format;
|
|
2218
|
-
const inferred = prevFormat ?? inferFormatFromPath(fileOut);
|
|
2219
|
-
if (!prevFormat && inferred) {
|
|
2220
|
-
this.outputOptions = { ...this.outputOptions, format: inferred };
|
|
2221
|
-
}
|
|
2222
|
-
try {
|
|
2223
|
-
await this.waitForStreamInput();
|
|
2224
|
-
const res = this.toBufferWithObjectSync();
|
|
2225
|
-
await filesystem.writeFile(fileOut, res.data);
|
|
2226
|
-
if (callback) callback(null, res.info);
|
|
2227
|
-
return res.info;
|
|
2228
|
-
} finally {
|
|
2229
|
-
if (!prevFormat && inferred) {
|
|
2230
|
-
const { format: _omit, ...rest } = this.outputOptions;
|
|
2231
|
-
this.outputOptions = rest;
|
|
2232
|
-
}
|
|
2233
|
-
}
|
|
2234
|
-
} catch (err) {
|
|
2235
|
-
if (callback) callback(err);
|
|
2236
|
-
throw err;
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
async toBuffer(optionsOrCallback) {
|
|
2240
|
-
const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : void 0;
|
|
2241
|
-
const options = typeof optionsOrCallback === "object" && optionsOrCallback !== null ? optionsOrCallback : void 0;
|
|
2242
|
-
try {
|
|
2243
|
-
await this.waitForStreamInput();
|
|
2244
|
-
const res = this.toBufferWithObjectSync();
|
|
2245
|
-
if (cb) cb(null, res.data, res.info);
|
|
2246
|
-
if (options?.resolveWithObject) {
|
|
2247
|
-
return res;
|
|
2248
|
-
}
|
|
2249
|
-
return res.data;
|
|
2250
|
-
} catch (err) {
|
|
2251
|
-
if (cb) cb(err);
|
|
2252
|
-
throw err;
|
|
2253
|
-
}
|
|
2254
|
-
}
|
|
2255
|
-
};
|
|
2256
|
-
function sharp(input, options) {
|
|
2257
|
-
return new SharpInstance(input, options);
|
|
2258
|
-
}
|
|
2259
|
-
Object.assign(sharp, {
|
|
2260
|
-
align: {
|
|
2261
|
-
left: "low",
|
|
2262
|
-
top: "low",
|
|
2263
|
-
low: "low",
|
|
2264
|
-
center: "centre",
|
|
2265
|
-
centre: "centre",
|
|
2266
|
-
right: "high",
|
|
2267
|
-
bottom: "high",
|
|
2268
|
-
high: "high"
|
|
2269
|
-
},
|
|
2270
|
-
position: {
|
|
2271
|
-
top: 1,
|
|
2272
|
-
right: 2,
|
|
2273
|
-
bottom: 3,
|
|
2274
|
-
left: 4,
|
|
2275
|
-
"right top": 5,
|
|
2276
|
-
"right bottom": 6,
|
|
2277
|
-
"left bottom": 7,
|
|
2278
|
-
"left top": 8
|
|
2279
|
-
},
|
|
2280
|
-
blend: {
|
|
2281
|
-
clear: "clear",
|
|
2282
|
-
source: "source",
|
|
2283
|
-
over: "over",
|
|
2284
|
-
in: "in",
|
|
2285
|
-
out: "out",
|
|
2286
|
-
atop: "atop",
|
|
2287
|
-
dest: "dest",
|
|
2288
|
-
"dest-over": "dest-over",
|
|
2289
|
-
"dest-in": "dest-in",
|
|
2290
|
-
"dest-out": "dest-out",
|
|
2291
|
-
"dest-atop": "dest-atop",
|
|
2292
|
-
xor: "xor",
|
|
2293
|
-
add: "add",
|
|
2294
|
-
saturate: "saturate",
|
|
2295
|
-
multiply: "multiply",
|
|
2296
|
-
screen: "screen",
|
|
2297
|
-
overlay: "overlay",
|
|
2298
|
-
darken: "darken",
|
|
2299
|
-
lighten: "lighten",
|
|
2300
|
-
"colour-dodge": "colour-dodge",
|
|
2301
|
-
"color-dodge": "colour-dodge",
|
|
2302
|
-
"colour-burn": "colour-burn",
|
|
2303
|
-
"color-burn": "colour-burn",
|
|
2304
|
-
"hard-light": "hard-light",
|
|
2305
|
-
"soft-light": "soft-light",
|
|
2306
|
-
difference: "difference",
|
|
2307
|
-
exclusion: "exclusion"
|
|
2308
|
-
},
|
|
2309
|
-
queue: new EventEmitter(),
|
|
2310
|
-
gravity: {
|
|
2311
|
-
center: 0,
|
|
2312
|
-
centre: 0,
|
|
2313
|
-
north: 1,
|
|
2314
|
-
east: 2,
|
|
2315
|
-
south: 3,
|
|
2316
|
-
west: 4,
|
|
2317
|
-
northeast: 5,
|
|
2318
|
-
southeast: 6,
|
|
2319
|
-
southwest: 7,
|
|
2320
|
-
northwest: 8
|
|
2321
|
-
},
|
|
2322
|
-
fit: {
|
|
2323
|
-
contain: "contain",
|
|
2324
|
-
cover: "cover",
|
|
2325
|
-
fill: "fill",
|
|
2326
|
-
inside: "inside",
|
|
2327
|
-
outside: "outside"
|
|
2328
|
-
},
|
|
2329
|
-
kernel: {
|
|
2330
|
-
nearest: "nearest",
|
|
2331
|
-
linear: "linear",
|
|
2332
|
-
cubic: "cubic",
|
|
2333
|
-
mitchell: "mitchell",
|
|
2334
|
-
lanczos2: "lanczos2",
|
|
2335
|
-
lanczos3: "lanczos3",
|
|
2336
|
-
mks2013: "mks2013",
|
|
2337
|
-
mks2021: "mks2021"
|
|
2338
|
-
},
|
|
2339
|
-
bool: {
|
|
2340
|
-
and: "and",
|
|
2341
|
-
or: "or",
|
|
2342
|
-
eor: "eor"
|
|
2343
|
-
},
|
|
2344
|
-
strategy: {
|
|
2345
|
-
entropy: 16,
|
|
2346
|
-
attention: 17
|
|
2347
|
-
},
|
|
2348
|
-
colourspace: {
|
|
2349
|
-
multiband: "multiband",
|
|
2350
|
-
"b-w": "b-w",
|
|
2351
|
-
bw: "b-w",
|
|
2352
|
-
cmyk: "cmyk",
|
|
2353
|
-
srgb: "srgb"
|
|
2354
|
-
},
|
|
2355
|
-
colorspace: {
|
|
2356
|
-
multiband: "multiband",
|
|
2357
|
-
"b-w": "b-w",
|
|
2358
|
-
bw: "b-w",
|
|
2359
|
-
cmyk: "cmyk",
|
|
2360
|
-
srgb: "srgb"
|
|
2361
|
-
},
|
|
2362
|
-
interpolators: {
|
|
2363
|
-
nearest: "nearest",
|
|
2364
|
-
bilinear: "bilinear",
|
|
2365
|
-
bicubic: "bicubic",
|
|
2366
|
-
locallyBoundedBicubic: "lbb",
|
|
2367
|
-
nohalo: "nohalo",
|
|
2368
|
-
vertexSplitQuadraticBasisSpline: "vsqbs"
|
|
2369
|
-
},
|
|
2370
|
-
format: Object.fromEntries(
|
|
2371
|
-
["jpeg", "png", "webp", "tiff", "heif", "heic", "avif", "gif", "svg", "pdf", "ppm", "pgm", "pbm", "bmp", "raw"].map(
|
|
2372
|
-
(id) => [
|
|
2373
|
-
id,
|
|
2374
|
-
{
|
|
2375
|
-
id,
|
|
2376
|
-
input: { file: true, buffer: true, stream: true },
|
|
2377
|
-
output: { file: true, buffer: true, stream: true }
|
|
2378
|
-
}
|
|
2379
|
-
]
|
|
2380
|
-
)
|
|
2381
|
-
),
|
|
2382
|
-
cache: /* @__PURE__ */ (() => {
|
|
2383
|
-
let memMax = 50;
|
|
2384
|
-
let filesMax = 20;
|
|
2385
|
-
let itemsMax = 100;
|
|
2386
|
-
return (options) => {
|
|
2387
|
-
if (options === false) {
|
|
2388
|
-
memMax = 0;
|
|
2389
|
-
filesMax = 0;
|
|
2390
|
-
itemsMax = 0;
|
|
2391
|
-
} else if (options === true) {
|
|
2392
|
-
memMax = 50;
|
|
2393
|
-
filesMax = 20;
|
|
2394
|
-
itemsMax = 100;
|
|
2395
|
-
} else if (options && typeof options === "object") {
|
|
2396
|
-
if (typeof options.memory === "number") memMax = options.memory;
|
|
2397
|
-
if (typeof options.files === "number") filesMax = options.files;
|
|
2398
|
-
if (typeof options.items === "number") itemsMax = options.items;
|
|
2399
|
-
}
|
|
2400
|
-
return {
|
|
2401
|
-
memory: { current: 0, high: 0, max: memMax },
|
|
2402
|
-
files: { current: 0, max: filesMax },
|
|
2403
|
-
items: { current: 0, max: itemsMax }
|
|
2404
|
-
};
|
|
2405
|
-
};
|
|
2406
|
-
})(),
|
|
2407
|
-
concurrency: /* @__PURE__ */ (() => {
|
|
2408
|
-
let threads = 4;
|
|
2409
|
-
return (n) => {
|
|
2410
|
-
if (typeof n === "number" && n > 0) threads = Math.floor(n);
|
|
2411
|
-
return threads;
|
|
2412
|
-
};
|
|
2413
|
-
})(),
|
|
2414
|
-
counters: () => ({ queue: 0, process: 0 }),
|
|
2415
|
-
simd: /* @__PURE__ */ (() => {
|
|
2416
|
-
let enabled = true;
|
|
2417
|
-
return (enable) => {
|
|
2418
|
-
if (typeof enable === "boolean") enabled = enable;
|
|
2419
|
-
return enabled;
|
|
2420
|
-
};
|
|
2421
|
-
})(),
|
|
2422
|
-
block: (_options) => {
|
|
2423
|
-
},
|
|
2424
|
-
unblock: (_options) => {
|
|
2425
|
-
},
|
|
2426
|
-
versions: {
|
|
2427
|
-
vips: "8.16.1",
|
|
2428
|
-
sharp: "0.34.5"
|
|
2429
|
-
}
|
|
2430
|
-
});
|
|
2431
|
-
|
|
2432
8
|
// packages/pdf/src/errors.ts
|
|
2433
9
|
init_buffer();
|
|
2434
10
|
var PdfError = class extends Error {
|