var e=1920,t=.85;async function n(n){let a=await createImageBitmap(n),{width:o,height:s}=a;if(o<=e&&s<=e)return a.close(),{file:n,dimensions:`${o}x${s}`};let c=e/Math.max(o,s),l=Math.round(o*c),u=Math.round(s*c),d=document.createElement(`canvas`);d.width=l,d.height=u;let f=d.getContext(`2d`);if(!f)throw a.close(),Error(`Canvas 2D context unavailable`);f.drawImage(a,0,0,l,u),a.close();let[p,m]=await Promise.all([r(d,`image/jpeg`,t),r(d,`image/png`)]),h=p.size<=m.size?{blob:p,ext:`.jpg`,mime:`image/jpeg`}:{blob:m,ext:`.png`,mime:`image/png`};return{file:new File([h.blob],i(n.name,h.ext),{type:h.mime}),dimensions:`${l}x${u}`}}function r(e,t,n){return new Promise((r,i)=>{e.toBlob(e=>e?r(e):i(Error(`Failed to encode ${t}`)),t,n)})}function i(e,t){let n=e.lastIndexOf(`.`);return(n>0?e.slice(0,n):e)+t}export{n as t};