const h=5242880;const m=["image/jpeg","image/webp","image/heic","image/heif"];function u(e){return new Promise((r,o)=>{const t=URL.createObjectURL(e),n=new Image;n.onload=()=>{URL.revokeObjectURL(t),r(n)},n.onerror=()=>{URL.revokeObjectURL(t),o(new Error("Bild konnte nicht gelesen werden."))},n.src=t})}async function d(e,{maxDimension:r=2400,quality:o=.85}={}){if(!e||!m.includes(e.type))return e;let t;try{t=await u(e)}catch{return e}const n=Math.min(1,r/Math.max(t.naturalWidth,t.naturalHeight));if(n===1&&e.size<=5242880*.8)return e;const a=document.createElement("canvas");a.width=Math.round(t.naturalWidth*n),a.height=Math.round(t.naturalHeight*n),a.getContext("2d").drawImage(t,0,0,a.width,a.height);const i=e.type==="image/webp"?"image/webp":"image/jpeg",c=await new Promise(g=>a.toBlob(g,i,o));if(!c||c.size>=e.size)return e;const s=e.name.replace(/\.[^.]+$/,"")+(i==="image/webp"?".webp":".jpg");return new File([c],s,{type:i,lastModified:Date.now()})}function w(e){return e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1).replace(".",",")} MB`}export{h as M,w as f,d as r};