async function e(e,{maxDim:n=1600,quality:r=.72,maxBytes:i=1048576}={}){if(!e||!e.type?.startsWith(`image/`))return e;let a=await new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result),r.onerror=n,r.readAsDataURL(e)}),o=await new Promise((e,t)=>{let n=new Image;n.onload=()=>e(n),n.onerror=t,n.src=a}),{width:s,height:c}=o;if(s>n||c>n){let e=n/Math.max(s,c);s=Math.round(s*e),c=Math.round(c*e)}let l=r,u=await t(o,s,c,l);for(let e=0;u&&u.size>i&&e<8;e++){if(l>.4)l=Math.max(.4,l-.12);else if(s=Math.round(s*.82),c=Math.round(c*.82),s<320||c<320)break;u=await t(o,s,c,l)}if(!u||u.size>=e.size&&e.size<=i)return e;let d=(e.name||`photo`).replace(/\.[^.]+$/,``)+`.jpg`;return new File([u],d,{type:`image/jpeg`})}function t(e,t,n,r){let i=document.createElement(`canvas`);i.width=t,i.height=n;let a=i.getContext(`2d`);return a.fillStyle=`#FFFFFF`,a.fillRect(0,0,t,n),a.drawImage(e,0,0,t,n),new Promise(e=>i.toBlob(e,`image/jpeg`,r))}export{e as t};