@zumer/snapdom 0.9.1 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,3 @@
1
- (()=>{function b(){let t=document.createElement("div");document.body.appendChild(t);let a=window.getComputedStyle(t),r={};for(let e of a)r[e]=a.getPropertyValue(e);return document.body.removeChild(t),r}function S(t,a){let r=[];for(let e of Array.from(t)){let i=t.getPropertyValue(e);i&&i!==a[e]&&r.push(`${e}:${i}`)}return r.sort().join(";")}function E(t){let a=new Set(t.values()),r=new Map,e=1;for(let i of a)r.set(i,`c${e++}`);return r}function w(t,a,r,e,i){if(t.tagName==="STYLE")return;i.has(t)||i.set(t,window.getComputedStyle(t));let o=i.get(t),c=S(o,e);r.set(a,c)}function y(t,a,r,e,i){if(t.nodeType===Node.ELEMENT_NODE&&t.getAttribute("data-capture")==="exclude"){let s=document.createElement("div"),n=t.getBoundingClientRect();return s.style.cssText=`display: inline-block; width: ${n.width}px; height: ${n.height}px; visibility: hidden;`,s}if(t.tagName==="IFRAME"){let s=document.createElement("div");return s.textContent="",s.style.cssText=`width: ${t.offsetWidth}px; height: ${t.offsetHeight}px; background: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,s}if(t.nodeType===Node.ELEMENT_NODE&&t.getAttribute("data-capture")==="placeholder"){let s=t.cloneNode(!1);i.set(s,t),w(t,s,a,r,e);let n=document.createElement("div");return n.textContent=t.getAttribute("data-placeholder-text")||"",n.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",s.appendChild(n),s}if(t.tagName==="CANVAS"){let s=t.toDataURL(),n=document.createElement("img");return n.src=s,n.width=t.width,n.height=t.height,n}if(t.nodeType===Node.TEXT_NODE){if(!t.textContent.trim())return null;if(t.parentElement?.shadowRoot){let n=t.parentElement.tagName.toLowerCase();if(customElements.get(n))return null}return t.cloneNode(!0)}if(t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);let o=t.cloneNode(!1);i.set(o,t),w(t,o,a,r,e);let c=document.createDocumentFragment();if(t.childNodes.forEach(s=>{let n=y(s,a,r,e,i);n&&c.appendChild(n)}),o.appendChild(c),t.shadowRoot){let s=Array.from(t.shadowRoot.children).filter(d=>d.tagName!=="STYLE").map(d=>y(d,a,r,e,i)).filter(Boolean),n=document.createDocumentFragment();s.forEach(d=>n.appendChild(d)),o.appendChild(n)}return o.querySelectorAll("style").forEach(s=>s.removeAttribute("style")),o.tagName==="STYLE"&&o.removeAttribute("style"),o}function h(t,a=3e3){return new Promise((r,e)=>{let i=setTimeout(()=>{e(new Error("Image load timed out"))},a),o=new Image;o.crossOrigin="anonymous",o.onload=async()=>{clearTimeout(i);try{await o.decode();let c=document.createElement("canvas");c.width=o.width,c.height=o.height,c.getContext("2d").drawImage(o,0,0);try{let n=c.toDataURL("image/png");r(n)}catch{e(new Error("CORS restrictions prevented image capture"))}}catch(c){e(c)}},o.onerror=c=>{clearTimeout(i),e(new Error("Failed to load image: "+(c.message||"Unknown error")))},o.src=t})}function u(t=0){return new Promise(a=>setTimeout(a,t))}async function v(t){let a=Array.from(t.querySelectorAll("img")),r=async e=>{let i=e.src;try{let o=await h(i);e.src=o,e.width||(e.width=e.naturalWidth||100),e.height||(e.height=e.naturalHeight||100)}catch{let o=document.createElement("div");o.style=`width: ${e.width||100}px; height: ${e.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${e.height||100}px; color: #666; font-size: 12px;`,o.innerText="img",e.replaceWith(o)}};for(let e=0;e<a.length;e+=4){let i=a.slice(e,e+4).map(r);await Promise.allSettled(i),await u(1)}}async function A(t,a,r){let e=[[t,a]];for(;e.length;){let[i,o]=e.shift(),c=r.get(i)||window.getComputedStyle(i);r.has(i)||r.set(i,c);let s=c.getPropertyValue("background-image");if(s&&s.includes("url(")){let l=s.match(/url\(["']?([^"')]+)["']?\)/);if(l?.[1])try{let m=await h(l[1]);o.style.backgroundImage=`url(${m})`}catch{o.style.backgroundImage="none"}}let n=Array.from(i.children),d=Array.from(o.children);for(let l=0;l<Math.min(n.length,d.length);l++)e.push([n[l],d[l]]);await u(1)}}async function x(t,a){let r=["position","top","right","bottom","left","z-index","width","height","min-width","max-width","min-height","max-height","margin","padding","border","border-radius","background","background-color","background-image","color","font","font-family","font-size","font-weight","text-align","text-decoration","line-height","letter-spacing","display","visibility","opacity","overflow","box-shadow","transform","transition","flex","grid"];for(let o of["::before","::after"])try{let c=window.getComputedStyle(t,o),s=c.getPropertyValue("content");if(s&&s!=="none"&&s!=='""'&&s!=="''"){let n=document.createElement("span");n.className=`snapdom-pseudo-${o.replace("::","")}`;let d=s.replace(/^\"|\"$/g,"");if(d.startsWith("url(")){let l=d.match(/url\(["']?([^"')]+)["']?\)/);if(l?.[1])try{let m=document.createElement("img"),f=await h(l[1]);m.src=f,m.style="display:block;width:100%;height:100%;object-fit:contain;",n.appendChild(m)}catch{}}else n.textContent=d;for(let l of r){let m=c.getPropertyValue(l);m&&(n.style[l]=m)}n.style.position||(n.style.position="absolute"),o==="::before"?a.insertBefore(n,a.firstChild):a.appendChild(n)}}catch{}let e=Array.from(t.children),i=Array.from(a.children).filter(o=>!o.classList.contains("snapdom-pseudo-before")&&!o.classList.contains("snapdom-pseudo-after"));for(let o=0;o<Math.min(e.length,i.length);o++)await x(e[o],i[o]),o%5===0&&await u(1)}function C(t){return t.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}function g(t){return{normal:"400",bold:"700",italic:"italic",oblique:"italic","ultra-condensed":"50","extra-condensed":"62",condensed:"75","semi-condensed":"87",expanded:"125","semi-expanded":"112","extra-expanded":"150","ultra-expanded":"200"}[t]||t.replace(/%/g,"")}async function $(t=new WeakMap){await document.fonts.ready;let a=[];Array.from(document.styleSheets).forEach(o=>{try{Array.from(o.cssRules).forEach(c=>{c instanceof CSSFontFaceRule&&a.push(c.cssText)})}catch(c){console.warn("Could not access stylesheet rules:",c)}});let r=new Map;document.querySelectorAll("*").forEach(o=>{let c=t.get(o)||window.getComputedStyle(o);t.has(o)||t.set(o,c);let s=c.fontFamily?.split(",")[0]?.trim().replace(/["']/g,"");if(!s)return;let n=g(c.fontWeight||"400"),d=g(c.fontStyle||"normal"),l=g(c.fontStretch||"normal");r.has(s)||r.set(s,new Set),r.get(s).add(`${n}_${d}_${l}`)});let i=[...a];for(let[o,c]of r){let s=C(o);for(let n of c){let[d,l,m]=n.split("_"),f=`fg-f-${s}-w${d}-${l}-s${m}`,R=[`font-family:"${o}",sans-serif`,`font-weight:${d}`,`font-style:${l}`,`font-stretch:${m}%`].filter(Boolean).join(";");i.push(`.${f}{${R}}`)}}return i.push("*{font-family:inherit;font-weight:inherit;font-style:inherit;}"),i.join("")}function N(t,a,r){let e=r.get(a)||window.getComputedStyle(a),i=e.fontFamily?.split(",")[0]?.trim().replace(/["']/g,"");if(!i)return;let o=g(e.fontWeight||"400"),c=g(e.fontStyle||"normal"),s=g(e.fontStretch||"normal"),n=C(i);t.classList.add(`fg-f-${n}-w${o}-${c}-s${s}`)}async function I(t){let a=new Map,r=new WeakMap,e=new WeakMap,i;try{i=b()}catch(n){console.warn("getDefaultStyles failed:",n),i={}}let o;try{o=y(t,a,i,r,e)}catch(n){throw console.warn("deepCloneWithShadow failed:",n),n}try{await v(o)}catch(n){console.warn("inlineImages failed:",n)}try{await A(t,o,r)}catch(n){console.warn("inlineBackgroundImages failed:",n)}try{await x(t,o)}catch(n){console.warn("inlinePseudoElements failed:",n)}let c=E(a),s=Array.from(c.entries()).map(([n,d])=>`.${d}{${n}}`).join("");for(let[n,d]of a.entries()){if(n.tagName==="STYLE")continue;let l=c.get(d);if(l){n.classList.add(l);try{N(n,e.get(n),r)}catch(f){console.warn("applyFontClasses failed for node:",n,f)}}let m=n.style?.backgroundImage;n.removeAttribute("style"),m&&m!=="none"&&(n.style.backgroundImage=m)}return{clone:o,classCSS:s,styleCache:r}}function k(t){return t.replace(/>\s+</g,"><").replace(/\s{2,}/g," ").replace(/\n/g,"").trim()}async function L(t,a=1){let r,e,i;try{({clone:r,classCSS:e,styleCache:i}=await I(t))}catch(f){throw console.error("prepareClone failed:",f),f}let o=t.offsetWidth*a,c=t.offsetHeight*a,s="";try{s=await $(i)}catch(f){console.warn("inlineFonts failed:",f)}let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",o),n.setAttribute("height",c),n.setAttribute("viewBox",`0 0 ${o} ${c}`);let d=document.createElementNS("http://www.w3.org/2000/svg","foreignObject");d.setAttribute("width","100%"),d.setAttribute("height","100%");let l=document.createElement("div");l.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),l.setAttribute("style",`width:${o}px;height:${c}px;`);let m=document.createElement("style");m.textContent=s+"svg{overflow:visible}"+e,l.appendChild(m),l.appendChild(r),d.appendChild(l),n.appendChild(d);try{let f=new XMLSerializer().serializeToString(n);return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(k(f))}`}catch(f){throw console.error("SVG serialization failed:",f),f}}async function p(t,a=1){return await L(t,a)}p.toImg=async function(t,a=1){let r=await p(t,a),e=new Image;return e.src=r,await e.decode(),e};p.toCanvas=async function(t,a=1){let r=await p.toImg(t,a),e=document.createElement("canvas");return e.width=r.width,e.height=r.height,e.getContext("2d").drawImage(r,0,0),e};p.toPng=async function(t,a=1){let r=await p.toCanvas(t,a),e=new Image;return e.src=r.toDataURL("image/png"),await e.decode(),e};p.toJpg=async function(t,a=1,r=.92){let e=await p.toCanvas(t,a),i=new Image;return i.src=e.toDataURL("image/jpeg",r),await i.decode(),i};p.toWebp=async function(t,a=1,r=.92){let e=await p.toCanvas(t,a),i=new Image;return i.src=e.toDataURL("image/webp",r),await i.decode(),i};p.toBlob=async function(t,a=1){let r=await p(t,a),e=decodeURIComponent(r.split(",")[1]);return new Blob([e],{type:"image/svg+xml"})};})();
1
+ (()=>{var S=new Map,E=new Map,k=new Map,T=new Map,v=new Map,P=new WeakMap;var te=["div","span","p","a","img","ul","li","button","input","select","textarea","label","section","article","header","footer","nav","main","aside","h1","h2","h3","h4","h5","h6","svg","path","circle","rect","line","g","table","thead","tbody","tr","td","th"];function K(){for(let e of te)H(e)}function H(e){if(T.has(e))return T.get(e);if(new Set(["script","style","meta","link","noscript","template"]).has(e)){let r={};return T.set(e,r),r}let o=document.getElementById("snapdom-sandbox");o||(o=document.createElement("div"),o.id="snapdom-sandbox",o.style.position="absolute",o.style.left="-9999px",o.style.top="-9999px",o.style.width="0",o.style.height="0",o.style.overflow="hidden",document.body.appendChild(o));let t=document.createElement(e);t.style.all="initial",o.appendChild(t);let s=getComputedStyle(t),a={};for(let r of s)a[r]=s.getPropertyValue(r);return o.removeChild(t),T.set(e,a),a}function F(e,n,o=!1){let t=[],s=H(n);for(let[a,r]of Object.entries(e))if(!o)r&&t.push(`${a}:${r}`);else{let c=s[a];r&&r!==c&&t.push(`${a}:${r}`)}return t.sort().join(";")}function B(e){let n=new Set;return e.tagName&&n.add(e.tagName.toLowerCase()),e.querySelectorAll("*").forEach(o=>{n.add(o.tagName.toLowerCase())}),Array.from(n)}function D(e){let n=new Map;for(let t of e){let s=T.get(t);if(!s)continue;let a=Object.entries(s).map(([r,c])=>`${r}:${c};`).sort().join("");n.has(a)||n.set(a,[]),n.get(a).push(t)}let o="";for(let[t,s]of n.entries())o+=`${s.join(",")} { ${t} }
2
+ `;return o}function _(e){let n=new Set(e.values()),o=new Map,t=1;for(let s of n)o.set(s,`c${t++}`);return o}function N(e,{fast:n=!1}={}){if(n)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function A(e,n=null){if(!(e instanceof Element))return window.getComputedStyle(e,n);let o=P.get(e);if(o||(o=new Map,P.set(e,o)),!o.has(n)){let t=window.getComputedStyle(e,n);o.set(n,t)}return o.get(n)}function Y(e){let n=e.replace(/^['"]|['"]$/g,"");if(n.startsWith("\\"))try{return String.fromCharCode(parseInt(n.replace("\\",""),16))}catch{return n}return n}function X(e){let n=e.match(/url\(["']?([^"')]+)["']?\)/);return n?n[1]:null}function M(e){return[/font\s*awesome/i,/material\s*icons/i,/ionicons/i,/glyphicons/i,/feather/i,/bootstrap\s*icons/i,/remix\s*icons/i,/heroicons/i].some(o=>o.test(e))}function C(e,n=3e3){return S.has(e)?Promise.resolve(S.get(e)):new Promise((o,t)=>{let s=setTimeout(()=>{t(new Error("Image load timed out"))},n),a=new Image;a.crossOrigin="anonymous",a.onload=async()=>{clearTimeout(s);try{await a.decode();let r=document.createElement("canvas");r.width=a.width,r.height=a.height,r.getContext("2d").drawImage(a,0,0);try{let i=r.toDataURL("image/png");S.set(e,i),o(i)}catch{t(new Error("CORS restrictions prevented image capture"))}}catch(r){t(r)}},a.onerror=r=>{clearTimeout(s),t(new Error("Failed to load image: "+(r.message||"Unknown error")))},a.src=e})}function W(e){let n={};for(let o of e)n[o]=e.getPropertyValue(o);return n}function V(e,n,o,t,s){if(e.tagName==="STYLE")return;t.has(e)||t.set(e,A(e));let a=t.get(e),r=W(a),c=e.tagName?.toLowerCase()||"div",i=F(r,c,s);o.set(n,i)}function O(e,n,o,t,s){if(e.nodeType===Node.ELEMENT_NODE&&e.getAttribute("data-capture")==="exclude"){let c=document.createElement("div"),i=e.getBoundingClientRect();return c.style.cssText=`display: inline-block; width: ${i.width}px; height: ${i.height}px; visibility: hidden;`,c}if(e.tagName==="IFRAME"){let c=document.createElement("div");return c.textContent="",c.style.cssText=`width: ${e.offsetWidth}px; height: ${e.offsetHeight}px; background: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,c}if(e.nodeType===Node.ELEMENT_NODE&&e.getAttribute("data-capture")==="placeholder"){let c=e.cloneNode(!1);t.set(c,e),V(e,c,n,o,s);let i=document.createElement("div");return i.textContent=e.getAttribute("data-placeholder-text")||"",i.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",c.appendChild(i),c}if(e.tagName==="CANVAS"){let c=e.toDataURL(),i=document.createElement("img");return i.src=c,i.width=e.width,i.height=e.height,i}if(e.nodeType===Node.TEXT_NODE){if(!e.textContent.trim())return null;if(e.parentElement?.shadowRoot){let i=e.parentElement.tagName.toLowerCase();if(customElements.get(i))return null}return e.cloneNode(!0)}if(e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);let a=e.cloneNode(!1);t.set(a,e),V(e,a,n,o,s);let r=document.createDocumentFragment();if(e.childNodes.forEach(c=>{let i=O(c,n,o,t,s);i&&r.appendChild(i)}),a.appendChild(r),e.shadowRoot){let c=Array.from(e.shadowRoot.children).filter(m=>m.tagName!=="STYLE").map(m=>O(m,n,o,t)).filter(Boolean),i=document.createDocumentFragment();c.forEach(m=>i.appendChild(m)),a.appendChild(i)}return a}async function J(e,n,o,t=32,s="#000"){n=n.replace(/^['"]+|['"]+$/g,""),await document.fonts.ready,await document.fonts.load(`${t}px "${n}"`);let a=document.createElement("canvas");a.width=t,a.height=t;let r=a.getContext("2d");return r.font=o?`${o} ${t}px "${n}"`:` ${t}px "${n}"`,r.textAlign="center",r.textBaseline="middle",r.fillStyle=s,r.fillText(e,a.width/2,a.height/2),a.toDataURL()}async function j({ignoreIconFonts:e=!0,preCached:n=!1}){let o=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(s=>s.href),t="";for(let s of o)try{let r=await(await fetch(s.href)).text();if(e&&(M(s.href)||M(r))){console.log("\u23ED\uFE0F Ignorando icon font CSS:",s.href);continue}let c=/url\(([^)]+)\)/g,i=await Promise.all(Array.from(r.matchAll(c)).map(async l=>{let d=l[1].replace(/["']/g,"");if(d.startsWith("http")||(d=new URL(d,s.href).href),e&&M(d))return console.log("\u23ED\uFE0F Ignorando icon font URL:",d),null;if(k.has(d))return{original:l[0],inlined:`url(${k.get(d)})`};try{let y=await(await fetch(d)).blob(),f=await new Promise(g=>{let u=new FileReader;u.onload=()=>g(u.result),u.readAsDataURL(y)});return k.set(d,f),{original:l[0],inlined:`url(${f})`}}catch{return console.warn("\u274C No pude fetch font",d),null}})),m=r;for(let l of i)l&&(m=m.replace(l.original,l.inlined));t+=m+`
3
+ `}catch{console.warn("\u274C No pude fetch CSS",s.href)}if(t&&n){let s=document.createElement("style");s.setAttribute("data-snapdom","embedFonts"),s.textContent=t,document.head.appendChild(s)}return t}async function R(e,n,o,t,s){if(!(e instanceof Element)||!(n instanceof Element))return;for(let c of["::before","::after"])try{let i=A(e,c);if(!i)continue;let m=i.getPropertyValue("content"),l=i.getPropertyValue("background-image"),d=m&&m!=="none"&&m!=='""'&&m!=="''",h=l&&l.startsWith("url(");if(d||h){let y=i.getPropertyValue("font-family"),f=parseInt(i.getPropertyValue("font-size"))||32,g=parseInt(i.getPropertyValue("font-weight"))||!1,u=i.getPropertyValue("color")||"#000",w=document.createElement("span");w.dataset.snapdomPseudo=c;let L=W(i),I=F(L,"span",s);o.set(w,I);let U=y&&/font.*awesome|material|bootstrap|glyphicons|ionicons|remixicon|simple-line-icons|octicons|feather|typicons|weathericons/i.test(y),x=Y(m);if(U&&x.length===1){let b=document.createElement("img");b.src=await J(x,y,g,f,u),b.style="display:block;width:100%;height:100%;object-fit:contain;",w.appendChild(b)}else if(x.startsWith("url(")){let b=x.match(/url\(["']?([^"')]+)["']?\)/);if(b?.[1])try{let $=document.createElement("img"),z=await C(b[1]);$.src=z,$.style="display:block;width:100%;height:100%;object-fit:contain;",w.appendChild($)}catch($){console.error(`[snapdom] Error in pseudo ${c} for`,e,$)}}else x&&x!=="none"&&(w.textContent=x);c==="::before"?n.insertBefore(w,n.firstChild):n.appendChild(w)}}catch(i){console.warn(`[snapdom] Failed to capture ${c} for`,e,i)}let a=Array.from(e.children),r=Array.from(n.children).filter(c=>!c.dataset.snapdomPseudo);for(let c=0;c<Math.min(a.length,r.length);c++)await R(a[c],r[c],o,t,s)}async function q(e,n=!1){let o=new Map,t=new WeakMap,s=new WeakMap,a;try{a=O(e,o,t,s,n)}catch(i){throw console.warn("deepClone failed:",i),i}try{await R(e,a,o,t,n)}catch(i){console.warn("inlinePseudoElements failed:",i)}let r=_(o),c=Array.from(r.entries()).map(([i,m])=>`.${m}{${i}}`).join("");for(let[i,m]of o.entries()){if(i.tagName==="STYLE")continue;let l=r.get(m);l&&i.classList.add(l);let d=i.style?.backgroundImage;i.removeAttribute("style"),d&&d!=="none"&&(i.style.backgroundImage=d)}return{clone:a,classCSS:c,styleCache:t}}async function G(e){let n=Array.from(e.querySelectorAll("img")),o=async t=>{let s=t.src;try{let a=await C(s);t.src=a,t.width||(t.width=t.naturalWidth||100),t.height||(t.height=t.naturalHeight||100)}catch{let a=document.createElement("div");a.style=`width: ${t.width||100}px; height: ${t.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${t.height||100}px; color: #666; font-size: 12px;`,a.innerText="img",t.replaceWith(a)}};for(let t=0;t<n.length;t+=4){let s=n.slice(t,t+4).map(o);await Promise.allSettled(s)}}async function Q(e,n,o){let t=[[e,n]];for(;t.length;){let[s,a]=t.shift(),r=o.get(s)||A(s);o.has(s)||o.set(s,r);let c=r.getPropertyValue("background-image");if(c&&c.includes("url(")){let l=c.match(/url\(["']?([^"')]+)["']?\)/);if(l?.[1])try{let d=l[1],h;E.has(d)?h=E.get(d):(h=await C(d),E.set(d,h)),a.style.backgroundImage=`url(${h})`}catch{a.style.backgroundImage="none"}}let i=Array.from(s.children),m=Array.from(a.children);for(let l=0;l<Math.min(i.length,m.length);l++)t.push([i[l],m[l]])}}async function Z(e,n={}){if(!e)throw new Error("Element cannot be null or undefined");let{compress:o=!0,embedFonts:t=!1,fast:s=!0,scale:a=1}=n,r,c,i,m="",l="",d,h;if({clone:r,classCSS:c,styleCache:i}=await q(e,o),await new Promise(f=>{N(async()=>{await G(r),f()},{fast:s})}),await new Promise(f=>{N(async()=>{await Q(e,r,i),f()},{fast:s})}),t&&await new Promise(f=>{N(async()=>{m=await j({ignoreIconFonts:!0}),f()},{fast:s})}),o){let f=B(r).sort(),g=f.join(",");v.has(g)?l=v.get(g):await new Promise(u=>{N(()=>{l=D(f),v.set(g,l),u()},{fast:s})})}await new Promise(f=>{N(()=>{let g=e.getBoundingClientRect(),u=g.width*a,w=g.height*a;a!==1&&(r.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),r.style.transform=`scale(${a})`,r.style.transformOrigin="top left",r.style.width=`${g.width}px`,r.style.height=`${g.height}px`);let L="http://www.w3.org/2000/svg",I=document.createElementNS(L,"foreignObject");I.setAttribute("width","100%"),I.setAttribute("height","100%");let U=document.createElement("style");U.textContent=l+m+"svg{overflow:visible;}"+c,I.appendChild(U),I.appendChild(r);let b=new XMLSerializer().serializeToString(I);h=`<svg xmlns="${L}" width="${u}" height="${w}" viewBox="0 0 ${u} ${w}">`+b+"</svg>";let ee=new Blob([h],{type:"image/svg+xml;charset=utf-8"});d=URL.createObjectURL(ee),f()},{fast:s})});let y=document.getElementById("snapdom-sandbox");return y&&y.style.position==="absolute"&&y.remove(),n.dataURL?`data:image/svg+xml;charset=utf-8,${encodeURIComponent(h)}`:d}async function p(e,n={}){if(!e)throw new Error("Element cannot be null or undefined");return await Z(e,n)}p.toImg=async(e,n={})=>{let o=await p(e,n),t=new Image;return t.src=o,await t.decode(),t};p.toCanvas=async(e,n={})=>{let o=await p.toImg(e,n),t=document.createElement("canvas");return t.width=o.width,t.height=o.height,t.getContext("2d").drawImage(o,0,0),t};p.toPng=async(e,n={})=>{let o=await p.toCanvas(e,n),t=new Image;return t.src=o.toDataURL("image/png"),await t.decode(),t};p.toJpg=async(e,n={})=>{let{backgroundColor:o="#fff",quality:t=1}=n,s=await p.toCanvas(e,n),a=document.createElement("canvas");a.width=s.width,a.height=s.height;let r=a.getContext("2d");r.fillStyle=o,r.fillRect(0,0,a.width,a.height),r.drawImage(s,0,0);let c=new Image;return c.src=a.toDataURL("image/jpeg",t),await c.decode(),c};p.toWebp=async(e,n={})=>{let{backgroundColor:o="#fff",quality:t=1}=n,s=await p.toCanvas(e,n),a=document.createElement("canvas");a.width=s.width,a.height=s.height;let r=a.getContext("2d");r.fillStyle=o,r.fillRect(0,0,a.width,a.height),r.drawImage(s,0,0);let c=new Image;return c.src=a.toDataURL("image/webp",t),await c.decode(),c};p.toBlob=async(e,n={})=>{let o=await p(e,n),t=decodeURIComponent(o.split(",")[1]);return new Blob([t],{type:"image/svg+xml"})};async function ne(e=document,n={}){let{embedFonts:o=!0,reset:t=!1,preWarm:s=!0}=n;if(t){S.clear(),E.clear(),k.clear(),v.clear(),P.clear();return}await document.fonts.ready,K();let a=[],r=[];e?.querySelectorAll&&(a=Array.from(e.querySelectorAll("img[src]")),r=Array.from(e.querySelectorAll("*")));let c=[];for(let i of a){let m=i.src;S.has(m)||c.push(C(m).then(l=>S.set(m,l)).catch(()=>{}))}for(let i of r){let m=getComputedStyle(i).backgroundImage,l=X(m);l&&!E.has(l)&&c.push(C(l).then(d=>E.set(l,d)).catch(()=>{}))}if(o&&await j({ignoreIconFonts:!0,preCached:!0}),await Promise.all(c),s){let i=B(e).sort(),m=i.join(",");if(!v.has(m)){let d=D(i);v.set(m,d)}let l=e.cloneNode(!1);await R(e,l,new Map,new WeakMap,!1)}if(s)try{await q(e,n.preWarm)}catch{}}})();
@@ -1 +1,3 @@
1
- function b(){let t=document.createElement("div");document.body.appendChild(t);let a=window.getComputedStyle(t),r={};for(let e of a)r[e]=a.getPropertyValue(e);return document.body.removeChild(t),r}function S(t,a){let r=[];for(let e of Array.from(t)){let i=t.getPropertyValue(e);i&&i!==a[e]&&r.push(`${e}:${i}`)}return r.sort().join(";")}function E(t){let a=new Set(t.values()),r=new Map,e=1;for(let i of a)r.set(i,`c${e++}`);return r}function w(t,a,r,e,i){if(t.tagName==="STYLE")return;i.has(t)||i.set(t,window.getComputedStyle(t));let o=i.get(t),c=S(o,e);r.set(a,c)}function y(t,a,r,e,i){if(t.nodeType===Node.ELEMENT_NODE&&t.getAttribute("data-capture")==="exclude"){let s=document.createElement("div"),n=t.getBoundingClientRect();return s.style.cssText=`display: inline-block; width: ${n.width}px; height: ${n.height}px; visibility: hidden;`,s}if(t.tagName==="IFRAME"){let s=document.createElement("div");return s.textContent="",s.style.cssText=`width: ${t.offsetWidth}px; height: ${t.offsetHeight}px; background: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,s}if(t.nodeType===Node.ELEMENT_NODE&&t.getAttribute("data-capture")==="placeholder"){let s=t.cloneNode(!1);i.set(s,t),w(t,s,a,r,e);let n=document.createElement("div");return n.textContent=t.getAttribute("data-placeholder-text")||"",n.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",s.appendChild(n),s}if(t.tagName==="CANVAS"){let s=t.toDataURL(),n=document.createElement("img");return n.src=s,n.width=t.width,n.height=t.height,n}if(t.nodeType===Node.TEXT_NODE){if(!t.textContent.trim())return null;if(t.parentElement?.shadowRoot){let n=t.parentElement.tagName.toLowerCase();if(customElements.get(n))return null}return t.cloneNode(!0)}if(t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);let o=t.cloneNode(!1);i.set(o,t),w(t,o,a,r,e);let c=document.createDocumentFragment();if(t.childNodes.forEach(s=>{let n=y(s,a,r,e,i);n&&c.appendChild(n)}),o.appendChild(c),t.shadowRoot){let s=Array.from(t.shadowRoot.children).filter(d=>d.tagName!=="STYLE").map(d=>y(d,a,r,e,i)).filter(Boolean),n=document.createDocumentFragment();s.forEach(d=>n.appendChild(d)),o.appendChild(n)}return o.querySelectorAll("style").forEach(s=>s.removeAttribute("style")),o.tagName==="STYLE"&&o.removeAttribute("style"),o}function h(t,a=3e3){return new Promise((r,e)=>{let i=setTimeout(()=>{e(new Error("Image load timed out"))},a),o=new Image;o.crossOrigin="anonymous",o.onload=async()=>{clearTimeout(i);try{await o.decode();let c=document.createElement("canvas");c.width=o.width,c.height=o.height,c.getContext("2d").drawImage(o,0,0);try{let n=c.toDataURL("image/png");r(n)}catch{e(new Error("CORS restrictions prevented image capture"))}}catch(c){e(c)}},o.onerror=c=>{clearTimeout(i),e(new Error("Failed to load image: "+(c.message||"Unknown error")))},o.src=t})}function u(t=0){return new Promise(a=>setTimeout(a,t))}async function v(t){let a=Array.from(t.querySelectorAll("img")),r=async e=>{let i=e.src;try{let o=await h(i);e.src=o,e.width||(e.width=e.naturalWidth||100),e.height||(e.height=e.naturalHeight||100)}catch{let o=document.createElement("div");o.style=`width: ${e.width||100}px; height: ${e.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${e.height||100}px; color: #666; font-size: 12px;`,o.innerText="img",e.replaceWith(o)}};for(let e=0;e<a.length;e+=4){let i=a.slice(e,e+4).map(r);await Promise.allSettled(i),await u(1)}}async function A(t,a,r){let e=[[t,a]];for(;e.length;){let[i,o]=e.shift(),c=r.get(i)||window.getComputedStyle(i);r.has(i)||r.set(i,c);let s=c.getPropertyValue("background-image");if(s&&s.includes("url(")){let l=s.match(/url\(["']?([^"')]+)["']?\)/);if(l?.[1])try{let m=await h(l[1]);o.style.backgroundImage=`url(${m})`}catch{o.style.backgroundImage="none"}}let n=Array.from(i.children),d=Array.from(o.children);for(let l=0;l<Math.min(n.length,d.length);l++)e.push([n[l],d[l]]);await u(1)}}async function x(t,a){let r=["position","top","right","bottom","left","z-index","width","height","min-width","max-width","min-height","max-height","margin","padding","border","border-radius","background","background-color","background-image","color","font","font-family","font-size","font-weight","text-align","text-decoration","line-height","letter-spacing","display","visibility","opacity","overflow","box-shadow","transform","transition","flex","grid"];for(let o of["::before","::after"])try{let c=window.getComputedStyle(t,o),s=c.getPropertyValue("content");if(s&&s!=="none"&&s!=='""'&&s!=="''"){let n=document.createElement("span");n.className=`snapdom-pseudo-${o.replace("::","")}`;let d=s.replace(/^\"|\"$/g,"");if(d.startsWith("url(")){let l=d.match(/url\(["']?([^"')]+)["']?\)/);if(l?.[1])try{let m=document.createElement("img"),f=await h(l[1]);m.src=f,m.style="display:block;width:100%;height:100%;object-fit:contain;",n.appendChild(m)}catch{}}else n.textContent=d;for(let l of r){let m=c.getPropertyValue(l);m&&(n.style[l]=m)}n.style.position||(n.style.position="absolute"),o==="::before"?a.insertBefore(n,a.firstChild):a.appendChild(n)}}catch{}let e=Array.from(t.children),i=Array.from(a.children).filter(o=>!o.classList.contains("snapdom-pseudo-before")&&!o.classList.contains("snapdom-pseudo-after"));for(let o=0;o<Math.min(e.length,i.length);o++)await x(e[o],i[o]),o%5===0&&await u(1)}function C(t){return t.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}function g(t){return{normal:"400",bold:"700",italic:"italic",oblique:"italic","ultra-condensed":"50","extra-condensed":"62",condensed:"75","semi-condensed":"87",expanded:"125","semi-expanded":"112","extra-expanded":"150","ultra-expanded":"200"}[t]||t.replace(/%/g,"")}async function $(t=new WeakMap){await document.fonts.ready;let a=[];Array.from(document.styleSheets).forEach(o=>{try{Array.from(o.cssRules).forEach(c=>{c instanceof CSSFontFaceRule&&a.push(c.cssText)})}catch(c){console.warn("Could not access stylesheet rules:",c)}});let r=new Map;document.querySelectorAll("*").forEach(o=>{let c=t.get(o)||window.getComputedStyle(o);t.has(o)||t.set(o,c);let s=c.fontFamily?.split(",")[0]?.trim().replace(/["']/g,"");if(!s)return;let n=g(c.fontWeight||"400"),d=g(c.fontStyle||"normal"),l=g(c.fontStretch||"normal");r.has(s)||r.set(s,new Set),r.get(s).add(`${n}_${d}_${l}`)});let i=[...a];for(let[o,c]of r){let s=C(o);for(let n of c){let[d,l,m]=n.split("_"),f=`fg-f-${s}-w${d}-${l}-s${m}`,R=[`font-family:"${o}",sans-serif`,`font-weight:${d}`,`font-style:${l}`,`font-stretch:${m}%`].filter(Boolean).join(";");i.push(`.${f}{${R}}`)}}return i.push("*{font-family:inherit;font-weight:inherit;font-style:inherit;}"),i.join("")}function N(t,a,r){let e=r.get(a)||window.getComputedStyle(a),i=e.fontFamily?.split(",")[0]?.trim().replace(/["']/g,"");if(!i)return;let o=g(e.fontWeight||"400"),c=g(e.fontStyle||"normal"),s=g(e.fontStretch||"normal"),n=C(i);t.classList.add(`fg-f-${n}-w${o}-${c}-s${s}`)}async function I(t){let a=new Map,r=new WeakMap,e=new WeakMap,i;try{i=b()}catch(n){console.warn("getDefaultStyles failed:",n),i={}}let o;try{o=y(t,a,i,r,e)}catch(n){throw console.warn("deepCloneWithShadow failed:",n),n}try{await v(o)}catch(n){console.warn("inlineImages failed:",n)}try{await A(t,o,r)}catch(n){console.warn("inlineBackgroundImages failed:",n)}try{await x(t,o)}catch(n){console.warn("inlinePseudoElements failed:",n)}let c=E(a),s=Array.from(c.entries()).map(([n,d])=>`.${d}{${n}}`).join("");for(let[n,d]of a.entries()){if(n.tagName==="STYLE")continue;let l=c.get(d);if(l){n.classList.add(l);try{N(n,e.get(n),r)}catch(f){console.warn("applyFontClasses failed for node:",n,f)}}let m=n.style?.backgroundImage;n.removeAttribute("style"),m&&m!=="none"&&(n.style.backgroundImage=m)}return{clone:o,classCSS:s,styleCache:r}}function k(t){return t.replace(/>\s+</g,"><").replace(/\s{2,}/g," ").replace(/\n/g,"").trim()}async function L(t,a=1){let r,e,i;try{({clone:r,classCSS:e,styleCache:i}=await I(t))}catch(f){throw console.error("prepareClone failed:",f),f}let o=t.offsetWidth*a,c=t.offsetHeight*a,s="";try{s=await $(i)}catch(f){console.warn("inlineFonts failed:",f)}let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width",o),n.setAttribute("height",c),n.setAttribute("viewBox",`0 0 ${o} ${c}`);let d=document.createElementNS("http://www.w3.org/2000/svg","foreignObject");d.setAttribute("width","100%"),d.setAttribute("height","100%");let l=document.createElement("div");l.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),l.setAttribute("style",`width:${o}px;height:${c}px;`);let m=document.createElement("style");m.textContent=s+"svg{overflow:visible}"+e,l.appendChild(m),l.appendChild(r),d.appendChild(l),n.appendChild(d);try{let f=new XMLSerializer().serializeToString(n);return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(k(f))}`}catch(f){throw console.error("SVG serialization failed:",f),f}}async function p(t,a=1){return await L(t,a)}p.toImg=async function(t,a=1){let r=await p(t,a),e=new Image;return e.src=r,await e.decode(),e};p.toCanvas=async function(t,a=1){let r=await p.toImg(t,a),e=document.createElement("canvas");return e.width=r.width,e.height=r.height,e.getContext("2d").drawImage(r,0,0),e};p.toPng=async function(t,a=1){let r=await p.toCanvas(t,a),e=new Image;return e.src=r.toDataURL("image/png"),await e.decode(),e};p.toJpg=async function(t,a=1,r=.92){let e=await p.toCanvas(t,a),i=new Image;return i.src=e.toDataURL("image/jpeg",r),await i.decode(),i};p.toWebp=async function(t,a=1,r=.92){let e=await p.toCanvas(t,a),i=new Image;return i.src=e.toDataURL("image/webp",r),await i.decode(),i};p.toBlob=async function(t,a=1){let r=await p(t,a),e=decodeURIComponent(r.split(",")[1]);return new Blob([e],{type:"image/svg+xml"})};export{p as snapdom};
1
+ var S=new Map,E=new Map,k=new Map,T=new Map,v=new Map,P=new WeakMap;var te=["div","span","p","a","img","ul","li","button","input","select","textarea","label","section","article","header","footer","nav","main","aside","h1","h2","h3","h4","h5","h6","svg","path","circle","rect","line","g","table","thead","tbody","tr","td","th"];function K(){for(let e of te)H(e)}function H(e){if(T.has(e))return T.get(e);if(new Set(["script","style","meta","link","noscript","template"]).has(e)){let r={};return T.set(e,r),r}let o=document.getElementById("snapdom-sandbox");o||(o=document.createElement("div"),o.id="snapdom-sandbox",o.style.position="absolute",o.style.left="-9999px",o.style.top="-9999px",o.style.width="0",o.style.height="0",o.style.overflow="hidden",document.body.appendChild(o));let t=document.createElement(e);t.style.all="initial",o.appendChild(t);let s=getComputedStyle(t),a={};for(let r of s)a[r]=s.getPropertyValue(r);return o.removeChild(t),T.set(e,a),a}function F(e,n,o=!1){let t=[],s=H(n);for(let[a,r]of Object.entries(e))if(!o)r&&t.push(`${a}:${r}`);else{let c=s[a];r&&r!==c&&t.push(`${a}:${r}`)}return t.sort().join(";")}function B(e){let n=new Set;return e.tagName&&n.add(e.tagName.toLowerCase()),e.querySelectorAll("*").forEach(o=>{n.add(o.tagName.toLowerCase())}),Array.from(n)}function D(e){let n=new Map;for(let t of e){let s=T.get(t);if(!s)continue;let a=Object.entries(s).map(([r,c])=>`${r}:${c};`).sort().join("");n.has(a)||n.set(a,[]),n.get(a).push(t)}let o="";for(let[t,s]of n.entries())o+=`${s.join(",")} { ${t} }
2
+ `;return o}function _(e){let n=new Set(e.values()),o=new Map,t=1;for(let s of n)o.set(s,`c${t++}`);return o}function N(e,{fast:n=!1}={}){if(n)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function A(e,n=null){if(!(e instanceof Element))return window.getComputedStyle(e,n);let o=P.get(e);if(o||(o=new Map,P.set(e,o)),!o.has(n)){let t=window.getComputedStyle(e,n);o.set(n,t)}return o.get(n)}function Y(e){let n=e.replace(/^['"]|['"]$/g,"");if(n.startsWith("\\"))try{return String.fromCharCode(parseInt(n.replace("\\",""),16))}catch{return n}return n}function X(e){let n=e.match(/url\(["']?([^"')]+)["']?\)/);return n?n[1]:null}function M(e){return[/font\s*awesome/i,/material\s*icons/i,/ionicons/i,/glyphicons/i,/feather/i,/bootstrap\s*icons/i,/remix\s*icons/i,/heroicons/i].some(o=>o.test(e))}function C(e,n=3e3){return S.has(e)?Promise.resolve(S.get(e)):new Promise((o,t)=>{let s=setTimeout(()=>{t(new Error("Image load timed out"))},n),a=new Image;a.crossOrigin="anonymous",a.onload=async()=>{clearTimeout(s);try{await a.decode();let r=document.createElement("canvas");r.width=a.width,r.height=a.height,r.getContext("2d").drawImage(a,0,0);try{let i=r.toDataURL("image/png");S.set(e,i),o(i)}catch{t(new Error("CORS restrictions prevented image capture"))}}catch(r){t(r)}},a.onerror=r=>{clearTimeout(s),t(new Error("Failed to load image: "+(r.message||"Unknown error")))},a.src=e})}function W(e){let n={};for(let o of e)n[o]=e.getPropertyValue(o);return n}function V(e,n,o,t,s){if(e.tagName==="STYLE")return;t.has(e)||t.set(e,A(e));let a=t.get(e),r=W(a),c=e.tagName?.toLowerCase()||"div",i=F(r,c,s);o.set(n,i)}function O(e,n,o,t,s){if(e.nodeType===Node.ELEMENT_NODE&&e.getAttribute("data-capture")==="exclude"){let c=document.createElement("div"),i=e.getBoundingClientRect();return c.style.cssText=`display: inline-block; width: ${i.width}px; height: ${i.height}px; visibility: hidden;`,c}if(e.tagName==="IFRAME"){let c=document.createElement("div");return c.textContent="",c.style.cssText=`width: ${e.offsetWidth}px; height: ${e.offsetHeight}px; background: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,c}if(e.nodeType===Node.ELEMENT_NODE&&e.getAttribute("data-capture")==="placeholder"){let c=e.cloneNode(!1);t.set(c,e),V(e,c,n,o,s);let i=document.createElement("div");return i.textContent=e.getAttribute("data-placeholder-text")||"",i.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",c.appendChild(i),c}if(e.tagName==="CANVAS"){let c=e.toDataURL(),i=document.createElement("img");return i.src=c,i.width=e.width,i.height=e.height,i}if(e.nodeType===Node.TEXT_NODE){if(!e.textContent.trim())return null;if(e.parentElement?.shadowRoot){let i=e.parentElement.tagName.toLowerCase();if(customElements.get(i))return null}return e.cloneNode(!0)}if(e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);let a=e.cloneNode(!1);t.set(a,e),V(e,a,n,o,s);let r=document.createDocumentFragment();if(e.childNodes.forEach(c=>{let i=O(c,n,o,t,s);i&&r.appendChild(i)}),a.appendChild(r),e.shadowRoot){let c=Array.from(e.shadowRoot.children).filter(m=>m.tagName!=="STYLE").map(m=>O(m,n,o,t)).filter(Boolean),i=document.createDocumentFragment();c.forEach(m=>i.appendChild(m)),a.appendChild(i)}return a}async function J(e,n,o,t=32,s="#000"){n=n.replace(/^['"]+|['"]+$/g,""),await document.fonts.ready,await document.fonts.load(`${t}px "${n}"`);let a=document.createElement("canvas");a.width=t,a.height=t;let r=a.getContext("2d");return r.font=o?`${o} ${t}px "${n}"`:` ${t}px "${n}"`,r.textAlign="center",r.textBaseline="middle",r.fillStyle=s,r.fillText(e,a.width/2,a.height/2),a.toDataURL()}async function j({ignoreIconFonts:e=!0,preCached:n=!1}){let o=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(s=>s.href),t="";for(let s of o)try{let r=await(await fetch(s.href)).text();if(e&&(M(s.href)||M(r))){console.log("\u23ED\uFE0F Ignorando icon font CSS:",s.href);continue}let c=/url\(([^)]+)\)/g,i=await Promise.all(Array.from(r.matchAll(c)).map(async l=>{let d=l[1].replace(/["']/g,"");if(d.startsWith("http")||(d=new URL(d,s.href).href),e&&M(d))return console.log("\u23ED\uFE0F Ignorando icon font URL:",d),null;if(k.has(d))return{original:l[0],inlined:`url(${k.get(d)})`};try{let y=await(await fetch(d)).blob(),f=await new Promise(g=>{let u=new FileReader;u.onload=()=>g(u.result),u.readAsDataURL(y)});return k.set(d,f),{original:l[0],inlined:`url(${f})`}}catch{return console.warn("\u274C No pude fetch font",d),null}})),m=r;for(let l of i)l&&(m=m.replace(l.original,l.inlined));t+=m+`
3
+ `}catch{console.warn("\u274C No pude fetch CSS",s.href)}if(t&&n){let s=document.createElement("style");s.setAttribute("data-snapdom","embedFonts"),s.textContent=t,document.head.appendChild(s)}return t}async function R(e,n,o,t,s){if(!(e instanceof Element)||!(n instanceof Element))return;for(let c of["::before","::after"])try{let i=A(e,c);if(!i)continue;let m=i.getPropertyValue("content"),l=i.getPropertyValue("background-image"),d=m&&m!=="none"&&m!=='""'&&m!=="''",h=l&&l.startsWith("url(");if(d||h){let y=i.getPropertyValue("font-family"),f=parseInt(i.getPropertyValue("font-size"))||32,g=parseInt(i.getPropertyValue("font-weight"))||!1,u=i.getPropertyValue("color")||"#000",w=document.createElement("span");w.dataset.snapdomPseudo=c;let L=W(i),I=F(L,"span",s);o.set(w,I);let U=y&&/font.*awesome|material|bootstrap|glyphicons|ionicons|remixicon|simple-line-icons|octicons|feather|typicons|weathericons/i.test(y),x=Y(m);if(U&&x.length===1){let b=document.createElement("img");b.src=await J(x,y,g,f,u),b.style="display:block;width:100%;height:100%;object-fit:contain;",w.appendChild(b)}else if(x.startsWith("url(")){let b=x.match(/url\(["']?([^"')]+)["']?\)/);if(b?.[1])try{let $=document.createElement("img"),z=await C(b[1]);$.src=z,$.style="display:block;width:100%;height:100%;object-fit:contain;",w.appendChild($)}catch($){console.error(`[snapdom] Error in pseudo ${c} for`,e,$)}}else x&&x!=="none"&&(w.textContent=x);c==="::before"?n.insertBefore(w,n.firstChild):n.appendChild(w)}}catch(i){console.warn(`[snapdom] Failed to capture ${c} for`,e,i)}let a=Array.from(e.children),r=Array.from(n.children).filter(c=>!c.dataset.snapdomPseudo);for(let c=0;c<Math.min(a.length,r.length);c++)await R(a[c],r[c],o,t,s)}async function q(e,n=!1){let o=new Map,t=new WeakMap,s=new WeakMap,a;try{a=O(e,o,t,s,n)}catch(i){throw console.warn("deepClone failed:",i),i}try{await R(e,a,o,t,n)}catch(i){console.warn("inlinePseudoElements failed:",i)}let r=_(o),c=Array.from(r.entries()).map(([i,m])=>`.${m}{${i}}`).join("");for(let[i,m]of o.entries()){if(i.tagName==="STYLE")continue;let l=r.get(m);l&&i.classList.add(l);let d=i.style?.backgroundImage;i.removeAttribute("style"),d&&d!=="none"&&(i.style.backgroundImage=d)}return{clone:a,classCSS:c,styleCache:t}}async function G(e){let n=Array.from(e.querySelectorAll("img")),o=async t=>{let s=t.src;try{let a=await C(s);t.src=a,t.width||(t.width=t.naturalWidth||100),t.height||(t.height=t.naturalHeight||100)}catch{let a=document.createElement("div");a.style=`width: ${t.width||100}px; height: ${t.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${t.height||100}px; color: #666; font-size: 12px;`,a.innerText="img",t.replaceWith(a)}};for(let t=0;t<n.length;t+=4){let s=n.slice(t,t+4).map(o);await Promise.allSettled(s)}}async function Q(e,n,o){let t=[[e,n]];for(;t.length;){let[s,a]=t.shift(),r=o.get(s)||A(s);o.has(s)||o.set(s,r);let c=r.getPropertyValue("background-image");if(c&&c.includes("url(")){let l=c.match(/url\(["']?([^"')]+)["']?\)/);if(l?.[1])try{let d=l[1],h;E.has(d)?h=E.get(d):(h=await C(d),E.set(d,h)),a.style.backgroundImage=`url(${h})`}catch{a.style.backgroundImage="none"}}let i=Array.from(s.children),m=Array.from(a.children);for(let l=0;l<Math.min(i.length,m.length);l++)t.push([i[l],m[l]])}}async function Z(e,n={}){if(!e)throw new Error("Element cannot be null or undefined");let{compress:o=!0,embedFonts:t=!1,fast:s=!0,scale:a=1}=n,r,c,i,m="",l="",d,h;if({clone:r,classCSS:c,styleCache:i}=await q(e,o),await new Promise(f=>{N(async()=>{await G(r),f()},{fast:s})}),await new Promise(f=>{N(async()=>{await Q(e,r,i),f()},{fast:s})}),t&&await new Promise(f=>{N(async()=>{m=await j({ignoreIconFonts:!0}),f()},{fast:s})}),o){let f=B(r).sort(),g=f.join(",");v.has(g)?l=v.get(g):await new Promise(u=>{N(()=>{l=D(f),v.set(g,l),u()},{fast:s})})}await new Promise(f=>{N(()=>{let g=e.getBoundingClientRect(),u=g.width*a,w=g.height*a;a!==1&&(r.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),r.style.transform=`scale(${a})`,r.style.transformOrigin="top left",r.style.width=`${g.width}px`,r.style.height=`${g.height}px`);let L="http://www.w3.org/2000/svg",I=document.createElementNS(L,"foreignObject");I.setAttribute("width","100%"),I.setAttribute("height","100%");let U=document.createElement("style");U.textContent=l+m+"svg{overflow:visible;}"+c,I.appendChild(U),I.appendChild(r);let b=new XMLSerializer().serializeToString(I);h=`<svg xmlns="${L}" width="${u}" height="${w}" viewBox="0 0 ${u} ${w}">`+b+"</svg>";let ee=new Blob([h],{type:"image/svg+xml;charset=utf-8"});d=URL.createObjectURL(ee),f()},{fast:s})});let y=document.getElementById("snapdom-sandbox");return y&&y.style.position==="absolute"&&y.remove(),n.dataURL?`data:image/svg+xml;charset=utf-8,${encodeURIComponent(h)}`:d}async function p(e,n={}){if(!e)throw new Error("Element cannot be null or undefined");return await Z(e,n)}p.toImg=async(e,n={})=>{let o=await p(e,n),t=new Image;return t.src=o,await t.decode(),t};p.toCanvas=async(e,n={})=>{let o=await p.toImg(e,n),t=document.createElement("canvas");return t.width=o.width,t.height=o.height,t.getContext("2d").drawImage(o,0,0),t};p.toPng=async(e,n={})=>{let o=await p.toCanvas(e,n),t=new Image;return t.src=o.toDataURL("image/png"),await t.decode(),t};p.toJpg=async(e,n={})=>{let{backgroundColor:o="#fff",quality:t=1}=n,s=await p.toCanvas(e,n),a=document.createElement("canvas");a.width=s.width,a.height=s.height;let r=a.getContext("2d");r.fillStyle=o,r.fillRect(0,0,a.width,a.height),r.drawImage(s,0,0);let c=new Image;return c.src=a.toDataURL("image/jpeg",t),await c.decode(),c};p.toWebp=async(e,n={})=>{let{backgroundColor:o="#fff",quality:t=1}=n,s=await p.toCanvas(e,n),a=document.createElement("canvas");a.width=s.width,a.height=s.height;let r=a.getContext("2d");r.fillStyle=o,r.fillRect(0,0,a.width,a.height),r.drawImage(s,0,0);let c=new Image;return c.src=a.toDataURL("image/webp",t),await c.decode(),c};p.toBlob=async(e,n={})=>{let o=await p(e,n),t=decodeURIComponent(o.split(",")[1]);return new Blob([t],{type:"image/svg+xml"})};async function ne(e=document,n={}){let{embedFonts:o=!0,reset:t=!1,preWarm:s=!0}=n;if(t){S.clear(),E.clear(),k.clear(),v.clear(),P.clear();return}await document.fonts.ready,K();let a=[],r=[];e?.querySelectorAll&&(a=Array.from(e.querySelectorAll("img[src]")),r=Array.from(e.querySelectorAll("*")));let c=[];for(let i of a){let m=i.src;S.has(m)||c.push(C(m).then(l=>S.set(m,l)).catch(()=>{}))}for(let i of r){let m=getComputedStyle(i).backgroundImage,l=X(m);l&&!E.has(l)&&c.push(C(l).then(d=>E.set(l,d)).catch(()=>{}))}if(o&&await j({ignoreIconFonts:!0,preCached:!0}),await Promise.all(c),s){let i=B(e).sort(),m=i.join(",");if(!v.has(m)){let d=D(i);v.set(m,d)}let l=e.cloneNode(!1);await R(e,l,new Map,new WeakMap,!1)}if(s)try{await q(e,n.preWarm)}catch{}}export{ne as preCache,p as snapdom};