/** * Minified by jsDelivr using Terser v5.37.0. * Original file: /npm/11ty-dither@0.0.8/.eleventy.js * * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files */ const dither=require("dither-me-this"),path=require("path"),{JSDOM:JSDOM}=require("jsdom"),fetch=require("node-fetch"),sh=require("shorthash"),sharp=require("sharp"),fs=require("fs"),imageTypes=["png","webp","avif"],defaultOptions={inputDirectory:"./src",outputDirectory:"./_site",imageFolder:"/images",sizes:[1800,1024,720,600],formats:["png","webp","avif"],ditheringOptions:{palette:["#000","#FFF"]}},pluginTypes={ditherShortcodes(e,t){e.addPairedNunjucksAsyncShortcode("dither",(async(e,i,r,a)=>await processImageFromShortcode(e,i,r,a,t)))}},processImageFromShortcode=async(e,t,i,r,a)=>{const s=shortcodeToDitherObject(t,i,e,r);return await processImage(s,a)},shortcodeToDitherObject=(e,t,i,r)=>({src:e,alt:t||"",caption:i||"",options:r||"default"}),getImageOptions=(e,t)=>{const i="string"==typeof t.options?t.options:null,r=e.presets||{},a=i&&r[i]?r[i]:{},s=a.ditheringOptions||{},o=e.default||{},n=o.ditheringOptions||{},p="string"!=typeof t.options?t.options.ditheringOptions:{},c={...defaultOptions.ditheringOptions,...n,...s,...p};return{...defaultOptions,...o,...a,...t,ditheringOptions:c}},processImage=async(e,t)=>{const i=getImageOptions(t,e),r=sh.unique(e.src),a=i.sizes.map((e=>i.formats.map((t=>{const a=createHashedFilename(r,e,t);return{format:t,size:e,hashedFilename:a,outputFilePath:path.join(i.outputDirectory,i.imageFolder,a),imageFolder:i.outputDirectory+i.imageFolder,src:path.join(i.imageFolder,a)}})))).flat();return await getImage(e.src,i).then((async e=>await Promise.all(i.sizes.map((t=>resizeImage(e,t)))).then((async e=>await ResizedImagesToDither(e,i.ditheringOptions))).then((async e=>await Promise.all(a.map((async t=>{const i=e.find((e=>e.width===t.size));return imageToFile(i.buffer,t.format,t.outputFilePath,t.imageFolder)}))))))),createPictureElement(a,e)},imageToFile=async(e,t,i,r)=>(fs.existsSync(r)||fs.mkdir(r,{recursive:!0},(e=>{if(e)throw e})),"webp"===t?sharp(e).webp({lossless:!0}).toFile(i):"avif"===t?sharp(e).avif({lossless:!0}).toFile(i):sharp(e).png().toFile(i)),createHashedFilename=(e,t,i)=>`${e}-${t}.${i}`,ResizedImagesToDither=async(e,t)=>(console.log(t),Promise.all(e.map((async e=>({buffer:await dither(e.data,t),width:e.info.width,height:e.info.height}))))),resizeImage=async(e,t)=>await sharp(e).png().resize({width:t}).toBuffer({resolveWithObject:!0}),getImage=async(e,t)=>imageIsExternal(e)?await downloadImage(e):await getImageFromFile(e,t),downloadImage=async e=>{try{return await fetch(e).then((t=>{if(200==t.status)return t;throw new Error(`File "${e}" not found`)})).then((e=>e.buffer()))}catch(e){console.log(e)}},getImageFromFile=async(e,t)=>await sharp(`${t.inputDirectory}/${e}`).toBuffer(),createPictureElement=(e,t)=>{const i=["avif","webp","png"];let r=e.sort(((e,t)=>i.indexOf(e.format)-i.indexOf(t.format))),a=r.map(((e,t)=>{const i=!r[t+1]||r[t+1].format!==e.format;return{...e,lastOfType:i}})),s=[];a.forEach((e=>{let t="";e.lastOfType||(t=`media="(min-width: ${e.size}px)"`);let i=`type="image/${e.format}"`,r=``;s.push(r)}));return`
\n \n ${s.join("")}\n ${t.alt}\n \n
\n ${t.caption}\n
\n
`.replace(/\s+/g," ").replace(/[\n\r]/g,"")},fileNameFromPath=e=>{const t=e.split("/");return t[t.length-1].split("?")[0]},imageIsExternal=e=>e.includes("https://")||e.includes("http://");module.exports=pluginTypes; //# sourceMappingURL=/sm/fa0d7c966c7cbe23fa6563d6bdc23b48e87b76556446d35560fc53fdc08886b9.map