var e=[`image/jpeg`,`image/png`,`image/webp`],t=[`image/avif`,`image/jxl`],n=[`application/pdf`],r={"image/jpeg":`jpg`,"image/png":`png`,"image/webp":`webp`,"image/avif":`avif`,"image/jxl":`jxl`,"application/pdf":`pdf`},i={"image/jpeg":`JPG`,"image/png":`PNG`,"image/webp":`WebP`,"image/avif":`AVIF`,"image/jxl":`JXL`,"application/pdf":`PDF`};function a(e){return e===`image/jpeg`||e===`image/webp`||e===`image/avif`||e===`image/jxl`}function o(e){return e===`image/jpeg`}function s(e){return t.includes(e)||n.includes(e)}function c(e){return n.includes(e)}function l(e){return r[e]}function u(e){return i[e]}function d(t){return e.includes(t)}function f(e,t,n){let r=t.replace(/\.[^./\\]+$/,``)||`image`,i=e.replace(/\{name\}/g,r).replace(/\{ext\}/g,l(n)).replace(/\{format\}/g,u(n));return i.includes(`.`)?i:`${i}.${l(n)}`}var p=32767,m=268435456;function h(e,t){if(e<=0||t<=0)return{width:Math.max(1,e|0),height:Math.max(1,t|0),scaled:!1};let n=1;return n=Math.min(n,p/e,p/t),e*n*(t*n)>268435456&&(n=Math.min(n,Math.sqrt(m/(e*t)))),n>=1?{width:e,height:t,scaled:!1}:{width:Math.max(1,Math.floor(e*n)),height:Math.max(1,Math.floor(t*n)),scaled:!0}}var g=class extends Error{code;constructor(e,t){super(e),this.code=t,this.name=`TranscodeError`}};async function _(e,t){let n;try{n=await createImageBitmap(e,{imageOrientation:t.keepExif?`from-image`:`none`})}catch(e){throw new g(`decode failed: ${e.message}`,`decode`)}try{let e=h(n.width,n.height),r=new OffscreenCanvas(e.width,e.height),i=r.getContext(`2d`);if(!i)throw new g(`no 2d context`,`context`);o(t.target)&&(i.fillStyle=t.matte||`#ffffff`,i.fillRect(0,0,e.width,e.height)),i.drawImage(n,0,0,e.width,e.height);let s=await r.convertToBlob(a(t.target)?{type:t.target,quality:v(t.quality)}:{type:t.target});return{blob:s,mime:s.type,width:e.width,height:e.height,scaled:e.scaled}}finally{n.close()}}function v(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):.92}export{e as a,a as c,d,u as f,t as i,c as l,h as n,o,f as p,n as r,l as s,_ as t,s as u};