!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.htmlToImg=t()}(this,function(){const e=async e=>{let t=await fetch(e,{mode:"cors"}),i=await t.blob();return await new Promise(e=>{let t=new FileReader;t.onload=(i=>{e(t.result)}),t.readAsDataURL(i)})},t=({img:e,clientWidth:t,clientHeight:i,dpr:a,type:n})=>{let r,l=document.createElement("canvas"),d=t*a,o=i*a;switch(l.width=d,l.height=o,l.getContext("2d").drawImage(e,0,0,d,o),n){case"jpg":case"jpeg":r=l.toDataURL("image/jpeg",1);default:r=l.toDataURL(n)}return r},i=async(t,a,n)=>{let r,{dpr:l}=n,d=getComputedStyle(t);if("img"==t.tagName.toLowerCase()){let i=t.src,n=await e(i),l=document.createElement("div");l.innerHTML=`<div style="width:100%;height:100%;background-image:url(${n});background-size:100% 100%;"></div>`,a.parentNode.insertBefore(l,a),a.parentNode.removeChild(a),a=l,r=1}let o=[];Array.from(d).forEach(t=>{let i=d[t];"background-image"==t&&"none"!==i?o.push((async()=>{let n=i.match(/^url\((.+)\)$/)[1].replace(/"/g,""),r=await e(n);a.style[t]=`url(${r})`})()):(1!==l&&/px/.test(i)&&(i=i.replace(/([\d\.]+)?px/g,(e,t)=>t*l+"px")),a.style[t]=i)}),r&&(a.style.display="inline-block"),o.length&&await Promise.all(o);let g=Array.from(t.children),h=Array.from(a.children),s=[];g.forEach((e,t)=>{s.push(i(e,h[t],n))}),s.length&&await Promise.all(s)};return(e,a)=>new Promise((n,r)=>{let l={type:"jpg",quality:1,outType:"base64",width:"",height:""};Object.assign(l,a);let{clientWidth:d,clientHeight:o}=e;l.width&&l.height&&(d=l.width,o=l.height);let g=window.devicePixelRatio||1,h=e.cloneNode(!0);i(e,h,{dpr:g}).then(()=>{"none"==getComputedStyle(e).display&&(h.style.display="block");let i=`\n        <svg xmlns="http://www.w3.org/2000/svg">\n            <foreignObject width="${d*g}" height="${o*g}">\n                <body xmlns="http://www.w3.org/1999/xhtml" style="margin:0;padding:0;">\n                    ${h.outerHTML}\n                </body>\n            </foreignObject>\n        </svg>`,a=new Image;if(navigator.userAgent.includes("Firefox")&&g>1?(a.width=d,a.height=o):(a.width=d*g,a.height=o*g),a.setAttribute("crossOrigin","Anonymous"),"img"==l.outType)return a.setAttribute("src","data:image/svg+xml;charset=utf-8,"+i.replace(/\n/g,"").replace(/ +/g," ")),void n(a);a.addEventListener("load",e=>{let i=t({img:a,clientWidth:d,clientHeight:o,dpr:g,type:l.type});if(l.maxWidth||l.maxHeight){let e=o,a=d;d>l.maxWidth&&(e=o/d*l.maxWidth,a=l.maxWidth),e>l.maxHeight&&(a=l.maxHeight*a/e,e=l.maxHeight);let r=new Image;return r.width=a,r.height=e,r.onload=(()=>{i=t({img:r,clientWidth:a,clientHeight:e,dpr:g,type:l.type}),n(i)}),void(r.src=i)}n(i)}),a.setAttribute("src","data:image/svg+xml;charset=utf-8,"+i.replace(/\n/g,"").replace(/ +/g," "))})})});