import{d as c}from"./chunk-4CLCTAJ7.js";function w(n,r){return c(this,null,function*(){let t=d(n);if(!t)return null;let{width:e,height:s,sized:a}=t,i=r/Math.max(e,s),o=Math.max(1,Math.round(e*i)),g=Math.max(1,Math.round(s*i)),l=yield b(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(a(o,g))}`),m=document.createElement("canvas");m.width=o,m.height=g;let u=m.getContext("2d");return u&&(u.imageSmoothingQuality="high",u.drawImage(l,0,0,o,g)),{canvas:m,width:e,height:s}})}function d(n){let r=new DOMParser().parseFromString(n,"image/svg+xml"),t=r.documentElement;if(!t||t.localName!=="svg"||r.getElementsByTagName("parsererror").length>0)return null;let e=(t.getAttribute("viewBox")??"").split(/[\s,]+/).map(Number).filter(o=>Number.isFinite(o)),s=e.length===4&&e[2]>0&&e[3]>0,a=h(t.getAttribute("width"))||(s?e[2]:0),i=h(t.getAttribute("height"))||(s?e[3]:0);return(!a||!i)&&(a=a||512,i=i||512),s||t.setAttribute("viewBox",`0 0 ${a} ${i}`),t.setAttribute("preserveAspectRatio","xMidYMid meet"),{width:a,height:i,sized:(o,g)=>(t.setAttribute("width",String(o)),t.setAttribute("height",String(g)),new XMLSerializer().serializeToString(t))}}function h(n){if(!n||n.includes("%"))return 0;let r=Number.parseFloat(n);return Number.isFinite(r)&&r>0?r:0}function b(n){return new Promise((r,t)=>{let e=new Image;e.onload=()=>r(e),e.onerror=()=>t(new Error("could not rasterise SVG")),e.src=n})}export{w as rasteriseSvgText};
