import{rasterize as g}from"./rasterize-34PCWURX-BS6l0Rtf.js";import{l as p}from"./index-CgQG7qql.js";import"./toCanvas-7_PhvHvY.js";async function y(i,o){let{scale:s=1,width:n,height:l,meta:e={}}=o,d=Number.isFinite(n),m=Number.isFinite(l),u=Number.isFinite(s)&&s!==1||d||m;if(p()&&u)return await g(i,{...o,format:"png",quality:1,meta:e});let t=new Image;if(t.decoding="sync",t.loading="eager",t.src=i,await t.decode(),d&&m)t.style.width=`${n}px`,t.style.height=`${l}px`;else if(d){let a=Number.isFinite(e.w0)?e.w0:t.naturalWidth,h=Number.isFinite(e.h0)?e.h0:t.naturalHeight,r=n/Math.max(1,a);t.style.width=`${n}px`,t.style.height=`${Math.round(h*r)}px`}else if(m){let a=Number.isFinite(e.w0)?e.w0:t.naturalWidth,h=Number.isFinite(e.h0)?e.h0:t.naturalHeight,r=l/Math.max(1,h);t.style.height=`${l}px`,t.style.width=`${Math.round(a*r)}px`}else{let a=Math.round(t.naturalWidth*s),h=Math.round(t.naturalHeight*s);if(t.style.width=`${a}px`,t.style.height=`${h}px`,typeof i=="string"&&i.startsWith("data:image/svg+xml"))try{let r=decodeURIComponent(i.split(",")[1]).replace(/width="[^"]*"/,`width="${a}"`).replace(/height="[^"]*"/,`height="${h}"`);i=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r)}`,t.src=i}catch{}}return t}export{y as toImg,y as toSvg};
