@zumer/snapdom 1.8.0 → 1.9.3-next-dev.0

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,15 +1,15 @@
1
- (()=>{var Rt=Object.defineProperty;var Y=Object.getOwnPropertySymbols;var at=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable;var ot=(t,e,o)=>e in t?Rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,_=(t,e)=>{for(var o in e||(e={}))at.call(e,o)&&ot(t,o,e[o]);if(Y)for(var o of Y(e))rt.call(e,o)&&ot(t,o,e[o]);return t};var st=(t,e)=>{var o={};for(var l in t)at.call(t,l)&&e.indexOf(l)<0&&(o[l]=t[l]);if(t!=null&&Y)for(var l of Y(t))e.indexOf(l)<0&&rt.call(t,l)&&(o[l]=t[l]);return o};var m=(t,e,o)=>new Promise((l,c)=>{var n=s=>{try{i(o.next(s))}catch(r){c(r)}},a=s=>{try{i(o.throw(s))}catch(r){c(r)}},i=s=>s.done?l(s.value):Promise.resolve(s.value).then(n,a);i((o=o.apply(t,e)).next())});var N=new Map,B=new Map,$=new Map,F=new Map,M=new Map,Q=new WeakMap,T=new Set;var At=["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 it(){for(let t of At)ct(t)}function ct(t){if(F.has(t))return F.get(t);if(new Set(["script","style","meta","link","noscript","template"]).has(t)){let a={};return F.set(t,a),a}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 l=document.createElement(t);l.style.all="initial",o.appendChild(l);let c=getComputedStyle(l),n={};for(let a of c)n[a]=c.getPropertyValue(a);return o.removeChild(l),F.set(t,n),n}function V(t,e,o=!1){let l=[],c=ct(e);for(let[n,a]of Object.entries(t))if(!o)a&&l.push(`${n}:${a}`);else{let i=c[n];a&&a!==i&&l.push(`${n}:${a}`)}return l.sort().join(";")}function lt(t){let e=new Set;return t.nodeType!==Node.ELEMENT_NODE&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(t.tagName&&e.add(t.tagName.toLowerCase()),typeof t.querySelectorAll=="function"&&t.querySelectorAll("*").forEach(o=>e.add(o.tagName.toLowerCase())),Array.from(e))}function dt(t){let e=new Map;for(let l of t){let c=F.get(l);if(!c)continue;let n=Object.entries(c).map(([a,i])=>`${a}:${i};`).sort().join("");e.has(n)||e.set(n,[]),e.get(n).push(l)}let o="";for(let[l,c]of e.entries())o+=`${c.join(",")} { ${l} }
2
- `;return o}function ft(t){let e=new Set(t.values()),o=new Map,l=1;for(let c of e)o.set(c,`c${l++}`);return o}function O(o){return m(this,arguments,function*(t,e={}){let l=t.startsWith("url("),c=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t);if(l){let n=q(t);if(!n)return t;let a=Z(n);if(B.has(a))return e.skipInline?void 0:`url(${B.get(a)})`;{let i=e.crossOrigin?e.crossOrigin(a):"anonymous",s=yield U(a,3e3,i);return B.set(a,s),e.skipInline?void 0:`url(${s})`}}return t})}function D(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function L(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let o=Q.get(t);if(o||(o=new Map,Q.set(t,o)),!o.has(e)){let l=window.getComputedStyle(t,e);o.set(e,l)}return o.get(e)}function mt(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch(o){return e}return e}function q(t){let e=t.indexOf("url(");if(e===-1)return null;let o=t.slice(e+4).trim();return o.endsWith(")")&&(o=o.slice(0,-1).trim()),(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))&&(o=o.slice(1,-1)),o}function z(t){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,/lucide/i].some(o=>o.test(t))}function U(t,e=3e3,o="anonymous"){return N.has(t)?Promise.resolve(N.get(t)):new Promise((l,c)=>{let n=setTimeout(()=>{c(new Error("Image load timed out"))},e),a=new Image;a.crossOrigin=o,a.onload=()=>m(null,null,function*(){clearTimeout(n);try{yield a.decode();let i=document.createElement("canvas");i.width=a.width,i.height=a.height,i.getContext("2d").drawImage(a,0,0,i.width,i.height);try{let r=i.toDataURL("image/png");N.set(t,r),l(r)}catch(r){c(new Error("CORS restrictions prevented image capture"))}}catch(i){c(i)}}),a.onerror=i=>{clearTimeout(n),c(new Error("Failed to load image: "+(i.message||"Unknown error")))},a.src=t})}function H(t){let e={};for(let o of t)e[o]=t.getPropertyValue(o);return e}function X(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function ht(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(o,l)=>{let c=l.split(",").map(n=>n.trim());return c.length!==6?`matrix(${l})`:(c[4]="0",c[5]="0",`matrix(${c.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(o,l)=>{let c=l.split(",").map(n=>n.trim());return c.length!==16?`matrix3d(${l})`:(c[12]="0",c[13]="0",`matrix3d(${c.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function Z(t){try{let e=decodeURI(t);return encodeURI(e)}catch(e){return t}}function W(t){let e=[],o=0,l=0;for(let c=0;c<t.length;c++){let n=t[c];n==="("&&o++,n===")"&&o--,n===","&&o===0&&(e.push(t.slice(l,c).trim()),l=c+1)}return e.push(t.slice(l).trim()),e}function tt(t,e,o,l,c){var r;if(t.tagName==="STYLE")return;l.has(t)||l.set(t,L(t));let n=l.get(t),a=H(n),i=((r=t.tagName)==null?void 0:r.toLowerCase())||"div",s=V(a,i,c);o.set(e,s)}function K(t,e,o,l,c){var i;if(t.nodeType===Node.ELEMENT_NODE&&t.getAttribute("data-capture")==="exclude"){let s=document.createElement("div"),r=t.getBoundingClientRect();return s.style.cssText=`display: inline-block; width: ${r.width}px; height: ${r.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-image: 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);l.set(s,t),tt(t,s,e,o,c);let r=document.createElement("div");return r.textContent=t.getAttribute("data-placeholder-text")||"",r.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",s.appendChild(r),s}if(t.tagName==="CANVAS"){let s=t.toDataURL(),r=document.createElement("img");return r.src=s,r.width=t.width,r.height=t.height,r.style.display="inline-block",r.style.width=t.style.width||`${t.width}px`,r.style.height=t.style.height||`${t.height}px`,r}if(t.nodeType===Node.TEXT_NODE){if((i=t.parentElement)!=null&&i.shadowRoot){let s=t.parentElement.tagName.toLowerCase();if(customElements.get(s))return null}return t.cloneNode(!0)}if(t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);let n=t.cloneNode(!1);l.set(n,t),t instanceof HTMLInputElement?(n.value=t.value,n.setAttribute("value",t.value),t.checked!==void 0&&(n.checked=t.checked,t.checked&&n.setAttribute("checked",""))):t instanceof HTMLTextAreaElement?(n.value=t.value,n.textContent=t.value):t instanceof HTMLSelectElement&&(n.value=t.value,Array.from(n.options).forEach(s=>{s.value===t.value?s.setAttribute("selected",""):s.removeAttribute("selected")})),tt(t,n,e,o,c);let a=document.createDocumentFragment();if(t.childNodes.forEach(s=>{let r=K(s,e,o,l,c);r&&a.appendChild(r)}),n.appendChild(a),t.shadowRoot){let s=Array.from(t.shadowRoot.children).filter(f=>f.tagName!=="STYLE").map(f=>K(f,e,o,l)).filter(Boolean),r=document.createDocumentFragment();s.forEach(f=>r.appendChild(f)),n.appendChild(r)}return n}function ut(t,e,o,l=32,c="#000"){return m(this,null,function*(){e=e.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,i=document.createElement("canvas").getContext("2d");i.font=o?`${o} ${l}px "${e}"`:`${l}px "${e}"`;let s=i.measureText(t),r=s.actualBoundingBoxAscent||l*.8,f=s.actualBoundingBoxDescent||l*.2,h=r+f,u=s.width,w=document.createElement("canvas");w.width=Math.ceil(u*n),w.height=Math.ceil(h*n);let d=w.getContext("2d");return d.scale(n,n),d.font=i.font,d.textAlign="left",d.textBaseline="alphabetic",d.fillStyle=c,d.fillText(t,0,r),w.toDataURL()})}function pt(t){return Array.from(document.styleSheets).some(e=>e.href===t)}function Nt(t){return new Promise(e=>{if(pt(t))return e(null);let o=document.createElement("link");o.rel="stylesheet",o.href=t,o.setAttribute("data-snapdom","injected-import"),o.onload=()=>e(o),o.onerror=()=>e(null),document.head.appendChild(o)})}function J(){return m(this,arguments,function*({ignoreIconFonts:t=!0,preCached:e=!1}={}){if($.has("fonts-embed-css")){if(e){let a=document.createElement("style");a.setAttribute("data-snapdom","embedFonts"),a.textContent=$.get("fonts-embed-css"),document.head.appendChild(a)}return $.get("fonts-embed-css")}let o=/@import\s+url\(["']?([^"')]+)["']?\)/g,l=[];for(let a of document.querySelectorAll("style")){let i=a.textContent||"",s=Array.from(i.matchAll(o));for(let r of s){let f=r[1];pt(f)||l.push(f)}}yield Promise.all(l.map(Nt));let c=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(a=>a.href),n="";for(let a of c)try{let s=yield(yield fetch(a.href)).text();if(t&&(z(a.href)||z(s)))continue;let r=/url\((["']?)([^"')]+)\1\)/g,f=yield Promise.all(Array.from(s.matchAll(r)).map(u=>m(null,null,function*(){let w=q(u[0]);if(!w)return null;let d=w;if(!d.startsWith("http")&&!d.startsWith("data:")&&(d=new URL(d,a.href).href),t&&z(d))return null;if($.has(d))return T.add(d),{original:u[0],inlined:`url(${$.get(d)})`};if(T.has(d))return null;try{let g=yield(yield fetch(d)).blob(),C=yield new Promise(p=>{let S=new FileReader;S.onload=()=>p(S.result),S.readAsDataURL(g)});return $.set(d,C),T.add(d),{original:u[0],inlined:`url(${C})`}}catch(x){return console.warn("[snapdom] Failed to fetch font resource:",d),null}}))),h=s;for(let u of f)u&&(h=h.replace(u.original,u.inlined));n+=h+`
3
- `}catch(i){console.warn("[snapdom] Failed to fetch CSS:",a.href)}for(let a of document.styleSheets)try{if(!a.href||c.every(i=>i.href!==a.href)){for(let i of a.cssRules)if(i.type===CSSRule.FONT_FACE_RULE){let s=i.style.getPropertyValue("src");if(!s)continue;let r=/url\((["']?)([^"')]+)\1\)/g,f=s,h=Array.from(s.matchAll(r));for(let u of h){let w=u[2].trim();if(!w)continue;let d=w;if(!d.startsWith("http")&&!d.startsWith("data:")&&(d=new URL(d,a.href||location.href).href),!(t&&z(d))){if($.has(d)){T.add(d),f=f.replace(u[0],`url(${$.get(d)})`);continue}if(!T.has(d))try{let g=yield(yield fetch(d)).blob(),C=yield new Promise(p=>{let S=new FileReader;S.onload=()=>p(S.result),S.readAsDataURL(g)});$.set(d,C),T.add(d),f=f.replace(u[0],`url(${C})`)}catch(x){console.warn("[snapdom] Failed to fetch font URL:",d)}}}n+=`@font-face {
4
- font-family: ${i.style.getPropertyValue("font-family")};
5
- src: ${f};
6
- font-style: ${i.style.getPropertyValue("font-style")||"normal"};
7
- font-weight: ${i.style.getPropertyValue("font-weight")||"normal"};
1
+ (()=>{var Ft=Object.defineProperty;var X=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var ct=(t,e,o)=>e in t?Ft(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,D=(t,e)=>{for(var o in e||(e={}))lt.call(e,o)&&ct(t,o,e[o]);if(X)for(var o of X(e))ft.call(e,o)&&ct(t,o,e[o]);return t};var dt=(t,e)=>{var o={};for(var i in t)lt.call(t,i)&&e.indexOf(i)<0&&(o[i]=t[i]);if(t!=null&&X)for(var i of X(t))e.indexOf(i)<0&&ft.call(t,i)&&(o[i]=t[i]);return o};var p=(t,e,o)=>new Promise((i,r)=>{var n=a=>{try{c(o.next(a))}catch(d){r(d)}},f=a=>{try{c(o.throw(a))}catch(d){r(d)}},c=a=>a.done?i(a.value):Promise.resolve(a.value).then(n,f);c((o=o.apply(t,e)).next())});var R=new Map,M=new Map,$=new Map,O=new Map,W=new Map,Z=new WeakMap,A=new Set;var Bt=["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 ht(){for(let t of Bt)mt(t)}function mt(t){if(O.has(t))return O.get(t);if(new Set(["script","style","meta","link","noscript","template"]).has(t)){let f={};return O.set(t,f),f}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 i=document.createElement(t);i.style.all="initial",o.appendChild(i);let r=getComputedStyle(i),n={};for(let f of r)n[f]=r.getPropertyValue(f);return o.removeChild(i),O.set(t,n),n}function z(t,e,o=!1){let i=[],r=mt(e);for(let[n,f]of Object.entries(t))if(!o)f&&i.push(`${n}:${f}`);else{let c=r[n];f&&f!==c&&i.push(`${n}:${f}`)}return i.sort().join(";")}function ut(t){let e=new Set;return t.nodeType!==Node.ELEMENT_NODE&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(t.tagName&&e.add(t.tagName.toLowerCase()),typeof t.querySelectorAll=="function"&&t.querySelectorAll("*").forEach(o=>e.add(o.tagName.toLowerCase())),Array.from(e))}function pt(t){let e=new Map;for(let i of t){let r=O.get(i);if(!r)continue;let n=Object.entries(r).map(([f,c])=>`${f}:${c};`).sort().join("");e.has(n)||e.set(n,[]),e.get(n).push(i)}let o="";for(let[i,r]of e.entries())o+=`${r.join(",")} { ${i} }
2
+ `;return o}function gt(t){let e=new Set(t.values()),o=new Map,i=1;for(let r of e)o.set(r,`c${i++}`);return o}function j(o){return p(this,arguments,function*(t,e={}){let i=t.match(/url\(["']?(.*?)["']?\)/),r=i==null?void 0:i[1],n=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t);if(r){let f=G(r);if(M.has(f))return e.skipInline?void 0:`url(${M.get(f)})`;{let c=yield F(f,{useProxy:e.useProxy});return M.set(f,c),e.skipInline?void 0:`url("${c}")`}}return t})}function V(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function U(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let o=Z.get(t);if(o||(o=new Map,Z.set(t,o)),!o.has(e)){let i=window.getComputedStyle(t,e);o.set(e,i)}return o.get(e)}function yt(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch(o){return e}return e}function Y(t){let e=t.indexOf("url(");if(e===-1)return null;let o=t.slice(e+4).trim();return o.endsWith(")")&&(o=o.slice(0,-1).trim()),(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))&&(o=o.slice(1,-1)),o}function F(t,{timeout:e=3e3,useProxy:o=""}={}){function i(a){try{return new URL(a,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch(d){return"anonymous"}}function r(a){return p(this,null,function*(){let d=l=>fetch(l,{mode:"cors",credentials:i(l)==="use-credentials"?"include":"omit"}).then(s=>s.blob()).then(s=>new Promise((h,m)=>{let u=new FileReader;u.onloadend=()=>{let g=u.result;if(typeof g!="string"||!g.startsWith("data:image/")){m(new Error("Invalid image data URL"));return}h(g)},u.onerror=()=>m(new Error("FileReader error")),u.readAsDataURL(s)}));try{return yield d(a)}catch(l){if(o&&typeof o=="string"){let s=o.replace(/\/$/,"")+G(a);try{return yield d(s)}catch(h){throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${a}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${a}`),new Error("Fetch fallback failed and no proxy provided")}})}let n=i(t);return console.log(`[SnapDOM - fetchImage] Start loading image: ${t} with crossOrigin=${n}`),R.has(t)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${t}`),Promise.resolve(R.get(t))):t.startsWith("data:image/")?(R.set(t,t),Promise.resolve(t)):/\.svg(\?.*)?$/i.test(t)?p(null,null,function*(){try{let d=yield(yield fetch(t,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),l=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(d)}`;return R.set(t,l),l}catch(a){return r(t)}}):new Promise((a,d)=>{let l=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${e}ms for image: ${t}`),d(new Error("Image load timed out"))},e),s=new Image;s.crossOrigin=n,s.onload=()=>p(null,null,function*(){clearTimeout(l);try{yield s.decode();let h=document.createElement("canvas");h.width=s.width,h.height=s.height,h.getContext("2d").drawImage(s,0,0,h.width,h.height);let u=h.toDataURL("image/png");R.set(t,u),a(u)}catch(h){try{let m=yield r(t);R.set(t,m),a(m)}catch(m){d(m)}}}),s.onerror=()=>p(null,null,function*(){clearTimeout(l),console.error(`[SnapDOM - fetchImage] Image failed to load: ${t}`);try{let h=yield r(t);R.set(t,h),a(h)}catch(h){d(h)}}),s.src=t})}function tt(t){let e={};for(let o of t)e[o]=t.getPropertyValue(o);return e}function K(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function wt(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(o,i)=>{let r=i.split(",").map(n=>n.trim());return r.length!==6?`matrix(${i})`:(r[4]="0",r[5]="0",`matrix(${r.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(o,i)=>{let r=i.split(",").map(n=>n.trim());return r.length!==16?`matrix3d(${i})`:(r[12]="0",r[13]="0",`matrix3d(${r.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function G(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch(e){return t}}function _(t){let e=[],o=0,i=0;for(let r=0;r<t.length;r++){let n=t[r];n==="("&&o++,n===")"&&o--,n===","&&o===0&&(e.push(t.slice(i,r).trim()),i=r+1)}return e.push(t.slice(i).trim()),e}var et=new WeakMap,nt=new Map;function Dt(t){let e={};for(let o=0;o<t.length;o++){let i=t[o],r=t.getPropertyValue(i);(i==="background-image"||i==="content")&&r.includes("url(")&&!r.includes("data:")&&(r="none"),e[i]=r}return e}function ot(t,e,o,i,r){var l;if(t.tagName==="STYLE")return;i.has(t)||i.set(t,U(t));let n=i.get(t);if(!et.has(t)){let s=Dt(n);et.set(t,s)}let f=et.get(t),c=Object.entries(f).sort(([s],[h])=>s.localeCompare(h)).map(([s,h])=>`${s}:${h}`).join(";");if(nt.has(c)){o.set(e,nt.get(c));return}let a=((l=t.tagName)==null?void 0:l.toLowerCase())||"div",d=z(f,a,r);nt.set(c,d),o.set(e,d)}function Mt(t){return t.nodeType===Node.ELEMENT_NODE&&t.tagName==="SLOT"}function H(t,e,o,i,r,n={},f){var a,d;if(t.nodeType===Node.TEXT_NODE||t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);if(t.getAttribute("data-capture")==="exclude"){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}if(n.exclude&&Array.isArray(n.exclude))for(let l of n.exclude)try{if((a=t.matches)!=null&&a.call(t,l)){let s=document.createElement("div"),h=t.getBoundingClientRect();return s.style.cssText=`display: inline-block; width: ${h.width}px; height: ${h.height}px; visibility: hidden;`,s}}catch(s){console.warn(`Invalid selector in exclude option: ${l}`,s)}if(typeof n.filter=="function")try{if(!n.filter(t,f||t)){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}}catch(l){console.warn("Error in filter function:",l)}if(t.tagName==="IFRAME"){let l=document.createElement("div");return l.textContent="",l.style.cssText=`width: ${t.offsetWidth}px; height: ${t.offsetHeight}px; background-image: 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;`,l}if(t.getAttribute("data-capture")==="placeholder"){let l=t.cloneNode(!1);i.set(l,t),ot(t,l,e,o,r);let s=document.createElement("div");return s.textContent=t.getAttribute("data-placeholder-text")||"",s.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",l.appendChild(s),l}if(t.tagName==="CANVAS"){let l=t.toDataURL(),s=document.createElement("img");return s.src=l,s.width=t.width,s.height=t.height,s.style.display="inline-block",s.style.width=t.style.width||`${t.width}px`,s.style.height=t.style.height||`${t.height}px`,s}let c=t.cloneNode(!1);if(i.set(c,t),t instanceof HTMLInputElement)c.value=t.value,c.setAttribute("value",t.value),t.checked!==void 0&&(c.checked=t.checked,t.checked&&c.setAttribute("checked",""));else if(t instanceof HTMLTextAreaElement){let l=t.getBoundingClientRect();c.textContent=t.value,c.style.width=`${l.width}px`,c.style.height=`${l.height}px`}else t instanceof HTMLSelectElement&&(c.value=t.value,Array.from(c.options).forEach(l=>{l.value===t.value?l.setAttribute("selected",""):l.removeAttribute("selected")}));if(ot(t,c,e,o,r),Mt(t)){let l=((d=t.assignedNodes)==null?void 0:d.call(t,{flatten:!0}))||[],s=l.length>0?l:Array.from(t.childNodes),h=document.createDocumentFragment();for(let m of s){let u=H(m,e,o,i,r,n,f||t);u&&h.appendChild(u)}return h}else if(!(t instanceof HTMLTextAreaElement)){let l=t.shadowRoot?t.shadowRoot.childNodes:t.childNodes;for(let s of l){let h=H(s,e,o,i,r,n,f||t);h&&c.appendChild(h)}if(t.shadowRoot&&t.childNodes.length>0&&!t.shadowRoot.querySelector("slot")){let s=document.createDocumentFragment();for(let h of t.childNodes){let m=H(h,e,o,i,r,n,f||t);m&&s.appendChild(m)}c.appendChild(s)}}return c}var Ot=[/font\s*awesome/i,/material\s*icons/i,/ionicons/i,/glyphicons/i,/feather/i,/bootstrap\s*icons/i,/remix\s*icons/i,/heroicons/i,/layui/i,/lucide/i],at=[];function xt(t){let e=Array.isArray(t)?t:[t];for(let o of e)o instanceof RegExp?at.push(o):typeof o=="string"?at.push(new RegExp(o,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",o)}function T(t){let e=typeof t=="string"?t:"",o=[...Ot,...at];for(let i of o)if(i instanceof RegExp&&i.test(e))return!0;return!!(/icon/i.test(e)||/glyph/i.test(e)||/symbols/i.test(e)||/feather/i.test(e)||/fontawesome/i.test(e))}function bt(t,e,o,i=32,r="#000"){return p(this,null,function*(){e=e.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,c=document.createElement("canvas").getContext("2d");c.font=o?`${o} ${i}px "${e}"`:`${i}px "${e}"`;let a=c.measureText(t),d=a.actualBoundingBoxAscent||i*.8,l=a.actualBoundingBoxDescent||i*.2,s=d+l,h=a.width,m=document.createElement("canvas");m.width=Math.ceil(h*n),m.height=Math.ceil(s*n);let u=m.getContext("2d");return u.scale(n,n),u.font=c.font,u.textAlign="left",u.textBaseline="alphabetic",u.fillStyle=r,u.fillText(t,0,d),m.toDataURL()})}function Ct(t){return Array.from(document.styleSheets).some(e=>e.href===t)}function Wt(t){return new Promise(e=>{if(Ct(t))return e(null);let o=document.createElement("link");o.rel="stylesheet",o.href=t,o.setAttribute("data-snapdom","injected-import"),o.onload=()=>e(o),o.onerror=()=>e(null),document.head.appendChild(o)})}function J(){return p(this,arguments,function*({preCached:t=!1}={}){if($.has("fonts-embed-css")){if(t){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=$.get("fonts-embed-css"),document.head.appendChild(n)}return $.get("fonts-embed-css")}let e=/@import\s+url\(["']?([^"')]+)["']?\)/g,o=[];for(let n of document.querySelectorAll("style")){let f=n.textContent||"",c=Array.from(f.matchAll(e));for(let a of c){let d=a[1];T(d)||Ct(d)||o.push(d)}}yield Promise.all(o.map(Wt));let i=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),r="";for(let n of i)try{let c=yield(yield fetch(n.href)).text();if(T(n.href)||T(c))continue;let a=/url\((["']?)([^"')]+)\1\)/g,d=yield Promise.all(Array.from(c.matchAll(a)).map(s=>p(null,null,function*(){let h=Y(s[0]);if(!h)return null;let m=h;if(!m.startsWith("http")&&!m.startsWith("data:")&&(m=new URL(m,n.href).href),T(m))return null;if($.has(m))return A.add(m),{original:s[0],inlined:`url(${$.get(m)})`};if(A.has(m))return null;try{let g=yield(yield fetch(m)).blob(),y=yield new Promise(b=>{let w=new FileReader;w.onload=()=>b(w.result),w.readAsDataURL(g)});return $.set(m,y),A.add(m),{original:s[0],inlined:`url(${y})`}}catch(u){return console.warn("[snapdom] Failed to fetch font resource:",m),null}}))),l=c;for(let s of d)s&&(l=l.replace(s.original,s.inlined));r+=l+`
3
+ `}catch(f){console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||i.every(f=>f.href!==n.href)){for(let f of n.cssRules)if(f.type===CSSRule.FONT_FACE_RULE){let c=f.style.getPropertyValue("src"),a=f.style.getPropertyValue("font-family");if(!c||T(a))continue;let d=/url\((["']?)([^"')]+)\1\)/g,l=c,s=Array.from(c.matchAll(d));for(let h of s){let m=h[2].trim();if(!m)continue;let u=m;if(!u.startsWith("http")&&!u.startsWith("data:")&&(u=new URL(u,n.href||location.href).href),!T(u)){if($.has(u)){A.add(u),l=l.replace(h[0],`url(${$.get(u)})`);continue}if(!A.has(u))try{let y=yield(yield fetch(u)).blob(),b=yield new Promise(w=>{let x=new FileReader;x.onload=()=>w(x.result),x.readAsDataURL(y)});$.set(u,b),A.add(u),l=l.replace(h[0],`url(${b})`)}catch(g){console.warn("[snapdom] Failed to fetch font URL:",u)}}}r+=`@font-face {
4
+ font-family: ${a};
5
+ src: ${l};
6
+ font-style: ${f.style.getPropertyValue("font-style")||"normal"};
7
+ font-weight: ${f.style.getPropertyValue("font-weight")||"normal"};
8
8
  }
9
- `}}}catch(i){console.warn("[snapdom] Cannot access stylesheet",a.href,i)}for(let a of document.fonts)if(a.family&&a.status==="loaded"&&a._snapdomSrc){let i=a._snapdomSrc;if(!i.startsWith("data:")){if($.has(a._snapdomSrc))i=$.get(a._snapdomSrc),T.add(a._snapdomSrc);else if(!T.has(a._snapdomSrc))try{let r=yield(yield fetch(a._snapdomSrc)).blob();i=yield new Promise(f=>{let h=new FileReader;h.onload=()=>f(h.result),h.readAsDataURL(r)}),$.set(a._snapdomSrc,i),T.add(a._snapdomSrc)}catch(s){console.warn("[snapdom] Failed to fetch dynamic font src:",a._snapdomSrc);continue}}n+=`@font-face {
10
- font-family: '${a.family}';
11
- src: url(${i});
12
- font-style: ${a.style||"normal"};
13
- font-weight: ${a.weight||"normal"};
9
+ `}}}catch(f){console.warn("[snapdom] Cannot access stylesheet",n.href,f)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(T(n.family))continue;let f=n._snapdomSrc;if(!f.startsWith("data:")){if($.has(n._snapdomSrc))f=$.get(n._snapdomSrc),A.add(n._snapdomSrc);else if(!A.has(n._snapdomSrc))try{let a=yield(yield fetch(n._snapdomSrc)).blob();f=yield new Promise(d=>{let l=new FileReader;l.onload=()=>d(l.result),l.readAsDataURL(a)}),$.set(n._snapdomSrc,f),A.add(n._snapdomSrc)}catch(c){console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}r+=`@font-face {
10
+ font-family: '${n.family}';
11
+ src: url(${f});
12
+ font-style: ${n.style||"normal"};
13
+ font-weight: ${n.weight||"normal"};
14
14
  }
15
- `}if(n&&($.set("fonts-embed-css",n),e)){let a=document.createElement("style");a.setAttribute("data-snapdom","embedFonts"),a.textContent=n,document.head.appendChild(a)}return n})}function et(t,e,o,l,c,n=!1){return m(this,null,function*(){if(!(t instanceof Element)||!(e instanceof Element))return;for(let s of["::before","::after","::first-letter"])try{let r=L(t,s);if(!r||typeof r[Symbol.iterator]!="function")continue;if(s==="::first-letter"){let g=getComputedStyle(t);if(!(r.color!==g.color||r.fontSize!==g.fontSize||r.fontWeight!==g.fontWeight))continue;let p=Array.from(e.childNodes).find(E=>E.nodeType===Node.TEXT_NODE&&E.textContent&&E.textContent.trim().length>0);if(!p)continue;let S=p.textContent,y=S.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),k=y==null?void 0:y[0],P=S.slice((k==null?void 0:k.length)||0);if(!k||/[\uD800-\uDFFF]/.test(k))continue;let v=document.createElement("span");v.textContent=k,v.dataset.snapdomPseudo="::first-letter";let I=H(r),G=V(I,"span",c);o.set(v,G);let j=document.createTextNode(P);e.replaceChild(j,p),e.insertBefore(v,j);continue}let f=r.getPropertyValue("content"),h=r.getPropertyValue("background-image"),u=r.getPropertyValue("background-color"),w=f!=="none",d=h&&h!=="none",x=u&&u!=="transparent"&&u!=="rgba(0, 0, 0, 0)";if(w||d||x){let g=r.getPropertyValue("font-family"),C=parseInt(r.getPropertyValue("font-size"))||32,p=parseInt(r.getPropertyValue("font-weight"))||!1,S=r.getPropertyValue("color")||"#000",y=document.createElement("span");y.dataset.snapdomPseudo=s;let k=H(r),P=V(k,"span",c);o.set(y,P);let v=g&&/font.*awesome|material|bootstrap|glyphicons|ionicons|remixicon|simple-line-icons|octicons|feather|typicons|weathericons|lucide/i.test(g),I=mt(f);if(!n&&v&&I.length===1){let E=document.createElement("img");E.src=yield ut(I,g,p,C,S),E.style="display:block;width:100%;height:100%;object-fit:contain;",y.appendChild(E)}else if(I.startsWith("url(")){let E=q(I);if(E&&E.trim()!=="")try{let R=document.createElement("img"),A=yield U(Z(E));R.src=A,R.style="display:block;width:100%;height:100%;object-fit:contain;",y.appendChild(R)}catch(R){console.error(`[snapdom] Error in pseudo ${s} for`,t,R)}}else!v&&I&&I!=="none"&&(y.textContent=I);if(d)try{let E=W(h),R=yield Promise.all(E.map(A=>O(A)));y.style.backgroundImage=R.join(", ")}catch(E){console.warn(`[snapdom] Failed to inline background-image for ${s}`,E)}if(x&&(y.style.backgroundColor=u),!(y.childNodes.length>0||y.textContent&&y.textContent.trim()!==""||d||x))continue;s==="::before"?e.insertBefore(y,e.firstChild):e.appendChild(y)}}catch(r){console.warn(`[snapdom] Failed to capture ${s} for`,t,r)}let a=Array.from(t.children),i=Array.from(e.children).filter(s=>!s.dataset.snapdomPseudo);for(let s=0;s<Math.min(a.length,i.length);s++)yield et(a[s],i[s],o,l,c,n)})}function gt(t,e=!1,o=!1){return m(this,null,function*(){var s;let l=new Map,c=new WeakMap,n=new Map,a;try{a=K(t,l,c,n,e)}catch(r){throw console.warn("deepClone failed:",r),r}try{yield et(t,a,l,c,e,o)}catch(r){console.warn("inlinePseudoElements failed:",r)}let i="";if(e){let r=ft(l);i=Array.from(r.entries()).map(([f,h])=>`.${h}{${f}}`).join("");for(let[f,h]of l.entries()){if(f.tagName==="STYLE")continue;let u=r.get(h);u&&f.classList.add(u);let w=(s=f.style)==null?void 0:s.backgroundImage;f.removeAttribute("style"),w&&w!=="none"&&(f.style.backgroundImage=w)}}else for(let[r,f]of l.entries())r.tagName!=="STYLE"&&r.setAttribute("style",f.replace(/;/g,"; "));for(let[r,f]of n.entries()){let h=f.scrollLeft,u=f.scrollTop;if((h||u)&&r instanceof HTMLElement){r.style.overflow="hidden",r.style.scrollbarWidth="none",r.style.msOverflowStyle="none";let d=document.createElement("div");for(d.style.transform=`translate(${-h}px, ${-u}px)`,d.style.willChange="transform",d.style.display="inline-block",d.style.width="100%";r.firstChild;)d.appendChild(r.firstChild);r.appendChild(d)}}if(t===n.get(a)){let r=c.get(t)||window.getComputedStyle(t);c.set(t,r);let f=ht(r.transform);a.style.margin="0",a.style.position="static",a.style.top="auto",a.style.left="auto",a.style.right="auto",a.style.bottom="auto",a.style.zIndex="auto",a.style.float="none",a.style.clear="none",a.style.transform=f||""}return{clone:a,classCSS:i,styleCache:c}})}function yt(o){return m(this,arguments,function*(t,e={}){let l=Array.from(t.querySelectorAll("img")),c=n=>m(null,null,function*(){let a=n.src;try{let i=e.crossOrigin?e.crossOrigin(a):"anonymous",s=yield U(a,3e3,i);n.src=s,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch(i){let s=document.createElement("div");s.style=`width: ${n.width||100}px; height: ${n.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${n.height||100}px; color: #666; font-size: 12px;`,s.innerText="img",n.replaceWith(s)}});for(let n=0;n<l.length;n+=4){let a=l.slice(n,n+4).map(c);yield Promise.allSettled(a)}})}function wt(c,n,a){return m(this,arguments,function*(t,e,o,l={}){let i=[[t,e]];for(;i.length;){let[s,r]=i.shift(),f=o.get(s)||L(s);o.has(s)||o.set(s,f);let h=f.getPropertyValue("background-image"),u=f.getPropertyValue("background-color");if(!h||h==="none"){let p=Array.from(s.children),S=Array.from(r.children);for(let y=0;y<Math.min(p.length,S.length);y++)i.push([p[y],S[y]]);continue}let w=W(h),d=yield Promise.all(w.map(p=>O(p,l)));d.some(p=>p&&p!=="none"&&!/^url\(undefined\)/.test(p))&&(r.style.backgroundImage=d.join(", ")),u&&u!=="transparent"&&u!=="rgba(0, 0, 0, 0)"&&(r.style.backgroundColor=u);let g=Array.from(s.children),C=Array.from(r.children);for(let p=0;p<Math.min(g.length,C.length);p++)i.push([g[p],C[p]])}})}function xt(o){return m(this,arguments,function*(t,e={}){if(!t)throw new Error("Element cannot be null or undefined");if(!(t instanceof Element))throw new Error("captureDOM: Only Element nodes are supported");let{compress:l=!0,embedFonts:c=!1,fast:n=!0,scale:a=1}=e,i,s,r,f="",h="",u,w;if({clone:i,classCSS:s,styleCache:r}=yield gt(t,l,c),yield new Promise(x=>{D(()=>m(null,null,function*(){yield yt(i,e),x()}),{fast:n})}),yield new Promise(x=>{D(()=>m(null,null,function*(){yield wt(t,i,r,e),x()}),{fast:n})}),c&&(yield new Promise(x=>{D(()=>m(null,null,function*(){f=yield J({ignoreIconFonts:!c}),x()}),{fast:n})})),l){let x=lt(i).sort(),g=x.join(",");M.has(g)?h=M.get(g):yield new Promise(C=>{D(()=>{h=dt(x),M.set(g,h),C()},{fast:n})})}yield new Promise(x=>{D(()=>{let g=t.getBoundingClientRect(),C=g.width,p=g.height,S=Number.isFinite(e.width),y=Number.isFinite(e.height),k=typeof a=="number"&&a!==1;if(!k){let A=g.width/g.height;S&&y?(C=e.width,p=e.height):S?(C=e.width,p=C/A):y&&(p=e.height,C=p*A)}if(C=Math.ceil(C),p=Math.ceil(p),i.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),i.style.transformOrigin="top left",!k&&(S||y)){let A=g.width,$t=g.height,vt=C/A,kt=p/$t,It=i.style.transform||"",Tt=`scale(${vt}, ${kt})`;i.style.transform=`${Tt} ${It}`.trim()}else k&&X()&&(i.style.scale=`${a}`);let P="http://www.w3.org/2000/svg",v=document.createElementNS(P,"foreignObject");v.setAttribute("width","100%"),v.setAttribute("height","100%");let I=document.createElement("style");I.textContent=h+f+"svg{overflow:visible;}"+s,v.appendChild(I),v.appendChild(i);let j=new XMLSerializer().serializeToString(v);w=`<svg xmlns="${P}" width="${C}" height="${p}" viewBox="0 0 ${C} ${p}">`+j+"</svg>",u=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(w)}`,x()},{fast:n})});let d=document.getElementById("snapdom-sandbox");return d&&d.style.position==="absolute"&&d.remove(),u})}function Lt(l,c){return m(this,arguments,function*(t,{dpr:e=1,scale:o=1}){let n=new Image;return n.src=t,yield n.decode(),X?(n.width=n.width*o,n.height=n.height*o):(n.width=n.width/o,n.height=n.height/o),n})}function Ct(l){return m(this,arguments,function*(t,{dpr:e=1,scale:o=1}={}){let c=new Image;c.src=t,yield c.decode();let n=document.createElement("canvas"),a=c.width*o,i=c.height*o;n.width=Math.ceil(a*e),n.height=Math.ceil(i*e);let s=n.getContext("2d");return s.scale(e,e),s.drawImage(c,0,0,a,i),n.style.width=`${a}px`,n.style.height=`${i}px`,n})}function bt(t){return m(this,null,function*(){let e=decodeURIComponent(t.split(",")[1]);return new Blob([e],{type:"image/svg+xml"})})}function St(c,n,a){return m(this,arguments,function*(t,{dpr:e=1,scale:o=1},l){let i=yield Ct(t,{dpr:e,scale:o});if(!l)return i;let s=document.createElement("canvas");s.width=i.width,s.height=i.height;let r=s.getContext("2d");return r.fillStyle=l,r.fillRect(0,0,s.width,s.height),r.drawImage(i,0,0),s})}function nt(a,i){return m(this,arguments,function*(t,{dpr:e=1,scale:o=1,backgroundColor:l="#fff",quality:c},n="png"){let s=yield St(t,{dpr:e,scale:o},l),r=new Image;return r.src=s.toDataURL(`image/${n}`,c),yield r.decode(),r.style.width=`${s.width/e}px`,r.style.height=`${s.height/e}px`,r})}function Ut(a){return m(this,arguments,function*(t,{dpr:e=1,scale:o=1,backgroundColor:l="#fff",format:c="png",filename:n="capture"}={}){if(c==="svg"){let w=yield bt(t),d=URL.createObjectURL(w),x=document.createElement("a");x.href=d,x.download=`${n}.svg`,x.click(),URL.revokeObjectURL(d);return}let i=["jpg","jpeg","webp"].includes(c)?"#fff":void 0,s=l!=null?l:i,r=yield St(t,{dpr:e,scale:o},s),f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[c]||"image/png",h=r.toDataURL(f),u=document.createElement("a");u.href=h,u.download=`${n}.${c}`,u.click()})}function b(o){return m(this,arguments,function*(t,e={}){if(e=_({scale:1},e),!t)throw new Error("Element cannot be null or undefined");return yield b.capture(t,e)})}b.capture=(o,...l)=>m(null,[o,...l],function*(t,e={}){let c=yield xt(t,e),n=window.devicePixelRatio||1,a=e.scale||1;return{url:c,options:e,toRaw:()=>c,toImg:()=>Lt(c,{dpr:n,scale:a}),toCanvas:()=>Ct(c,{dpr:n,scale:a}),toBlob:()=>bt(c),toPng:i=>nt(c,_({dpr:n,scale:a},i),"png"),toJpg:i=>nt(c,_({dpr:n,scale:a},i),"jpeg"),toWebp:i=>nt(c,_({dpr:n,scale:a},i),"webp"),download:({format:i="png",filename:s="capture",backgroundColor:r}={})=>Ut(c,{dpr:n,scale:a,backgroundColor:r,format:i,filename:s})}});b.toRaw=(t,e)=>m(null,null,function*(){return(yield b.capture(t,e)).toRaw()});b.toImg=(t,e)=>m(null,null,function*(){return(yield b.capture(t,e)).toImg()});b.toCanvas=(t,e)=>m(null,null,function*(){return(yield b.capture(t,e)).toCanvas()});b.toBlob=(t,e)=>m(null,null,function*(){return(yield b.capture(t,e)).toBlob()});b.toPng=(t,e)=>m(null,null,function*(){return(yield b.capture(t,e)).toPng(e)});b.toJpg=(t,e)=>m(null,null,function*(){return(yield b.capture(t,e)).toJpg(e)});b.toWebp=(t,e)=>m(null,null,function*(){return(yield b.capture(t,e)).toWebp(e)});b.download=(o,...l)=>m(null,[o,...l],function*(t,e={}){let r=e,{format:c="png",filename:n="capture",backgroundColor:a}=r,i=st(r,["format","filename","backgroundColor"]);return yield(yield b.capture(t,i)).download({format:c,filename:n,backgroundColor:a})});function Et(){return m(this,arguments,function*(t=document,e={}){let{embedFonts:o=!0,reset:l=!1,crossOrigin:c}=e;if(l){N.clear(),B.clear(),$.clear(),M.clear();return}yield document.fonts.ready,it();let n=[],a=[];t!=null&&t.querySelectorAll&&(n=Array.from(t.querySelectorAll("img[src]")),a=Array.from(t.querySelectorAll("*")));let i=[];for(let s of n){let r=s.src;if(!N.has(r)){let f=c?c(r):"anonymous";i.push(U(r,3e3,f).then(h=>N.set(r,h)).catch(()=>{}))}}for(let s of a){let r=L(s).backgroundImage;if(r&&r!=="none"){let f=W(r);for(let h of f)h.startsWith("url(")&&i.push(O(h,{crossOrigin:c,skipInline:!0}).catch(()=>{}))}}o&&(yield J({ignoreIconFonts:!o,preCached:!0})),yield Promise.all(i)})}window.snapdom=b;window.preCache=Et;})();
15
+ `}if(r&&($.set("fonts-embed-css",r),t)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=r,document.head.appendChild(n)}return r})}function rt(t,e,o,i,r,n=!1,f){return p(this,null,function*(){if(!(t instanceof Element)||!(e instanceof Element))return;for(let d of["::before","::after","::first-letter"])try{let l=U(t,d);if(!l||typeof l[Symbol.iterator]!="function")continue;if(d==="::first-letter"){let b=getComputedStyle(t);if(!(l.color!==b.color||l.fontSize!==b.fontSize||l.fontWeight!==b.fontWeight))continue;let x=Array.from(e.childNodes).find(E=>E.nodeType===Node.TEXT_NODE&&E.textContent&&E.textContent.trim().length>0);if(!x)continue;let N=x.textContent,C=N.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),k=C==null?void 0:C[0],B=N.slice((k==null?void 0:k.length)||0);if(!k||/[\uD800-\uDFFF]/.test(k))continue;let v=document.createElement("span");v.textContent=k,v.dataset.snapdomPseudo="::first-letter";let I=tt(l),Q=z(I,"span",r);o.set(v,Q);let q=document.createTextNode(B);e.replaceChild(q,x),e.insertBefore(v,q);continue}let s=l.getPropertyValue("content"),h=l.getPropertyValue("background-image"),m=l.getPropertyValue("background-color"),u=s!=="none",g=h&&h!=="none",y=m&&m!=="transparent"&&m!=="rgba(0, 0, 0, 0)";if(u||g||y){let b=l.getPropertyValue("font-family"),w=parseInt(l.getPropertyValue("font-size"))||32,x=parseInt(l.getPropertyValue("font-weight"))||!1,N=l.getPropertyValue("color")||"#000",C=document.createElement("span");C.dataset.snapdomPseudo=d;let k=tt(l),B=z(k,"span",r);o.set(C,B);let v=T(b),I=yt(s);if(v&&I.length===1){let E=document.createElement("img");E.src=yield bt(I,b,x,w,N),E.style=`width:${w}px;height:auto;object-fit:contain;`,C.appendChild(E)}else if(I.startsWith("url(")){let E=Y(I);if(E&&E.trim()!=="")try{let P=document.createElement("img"),L=yield F(G(E,{useProxy:f}));P.src=L,P.style=`width:${w}px;height:auto;object-fit:contain;`,C.appendChild(P)}catch(P){console.error(`[snapdom] Error in pseudo ${d} for`,t,P)}}else!v&&I&&I!=="none"&&(C.textContent=I);if(g)try{let E=_(h),P=yield Promise.all(E.map(L=>j(L)));C.style.backgroundImage=P.join(", ")}catch(E){console.warn(`[snapdom] Failed to inline background-image for ${d}`,E)}if(y&&(C.style.backgroundColor=m),!(C.childNodes.length>0||C.textContent&&C.textContent.trim()!==""||g||y))continue;d==="::before"?e.insertBefore(C,e.firstChild):e.appendChild(C)}}catch(l){console.warn(`[snapdom] Failed to capture ${d} for`,t,l)}let c=Array.from(t.children),a=Array.from(e.children).filter(d=>!d.dataset.snapdomPseudo);for(let d=0;d<Math.min(c.length,a.length);d++)yield rt(c[d],a[d],o,i,r,n,f)})}function St(t){if(!t)return;let e=document.querySelectorAll("svg > defs");e.length&&t.querySelectorAll("svg").forEach(o=>{let i=o.querySelectorAll("use");if(!i.length)return;let r=new Set;if(i.forEach(f=>{let c=f.getAttribute("xlink:href")||f.getAttribute("href");c&&c.startsWith("#")&&r.add(c.slice(1))}),!r.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let f of r)for(let c of e){let a=c.querySelector(`#${CSS.escape(f)}`);if(a){n.appendChild(a.cloneNode(!0));break}}n.childNodes.length&&o.insertBefore(n,o.firstChild)})}function Et(r){return p(this,arguments,function*(t,e=!1,o=!1,i={}){var l;let n=new Map,f=new WeakMap,c=new Map,a;try{a=H(t,n,f,c,e,i,t)}catch(s){throw console.warn("deepClone failed:",s),s}try{yield rt(t,a,n,f,e,o,i.useProxy)}catch(s){console.warn("inlinePseudoElements failed:",s)}try{St(a)}catch(s){console.warn("inlineExternalDef failed:",s)}let d="";if(e){let s=gt(n);d=Array.from(s.entries()).map(([h,m])=>`.${m}{${h}}`).join("");for(let[h,m]of n.entries()){if(h.tagName==="STYLE")continue;let u=s.get(m);u&&h.classList.add(u);let g=(l=h.style)==null?void 0:l.backgroundImage;h.removeAttribute("style"),g&&g!=="none"&&(h.style.backgroundImage=g)}}else for(let[s,h]of n.entries())s.tagName!=="STYLE"&&s.setAttribute("style",h.replace(/;/g,"; "));for(let[s,h]of c.entries()){let m=h.scrollLeft,u=h.scrollTop;if((m||u)&&s instanceof HTMLElement){s.style.overflow="hidden",s.style.scrollbarWidth="none",s.style.msOverflowStyle="none";let y=document.createElement("div");for(y.style.transform=`translate(${-m}px, ${-u}px)`,y.style.willChange="transform",y.style.display="inline-block",y.style.width="100%";s.firstChild;)y.appendChild(s.firstChild);s.appendChild(y)}}if(t===c.get(a)){let s=f.get(t)||window.getComputedStyle(t);f.set(t,s);let h=wt(s.transform);a.style.margin="0",a.style.position="static",a.style.top="auto",a.style.left="auto",a.style.right="auto",a.style.bottom="auto",a.style.zIndex="auto",a.style.float="none",a.style.clear="none",a.style.transform=h||""}for(let[s,h]of c.entries())h.tagName==="PRE"&&(s.style.marginTop="0",s.style.marginBlockStart="0");return{clone:a,classCSS:d,styleCache:f}})}function $t(o){return p(this,arguments,function*(t,e={}){let i=Array.from(t.querySelectorAll("img")),r=n=>p(null,null,function*(){let f=n.src;try{let c=yield F(f,{useProxy:e.useProxy});n.src=c,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch(c){let a=document.createElement("div");a.style=`width: ${n.width||100}px; height: ${n.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${n.height||100}px; color: #666; font-size: 12px;`,a.innerText="img",n.replaceWith(a)}});for(let n=0;n<i.length;n+=4){let f=i.slice(n,n+4).map(r);yield Promise.allSettled(f)}})}function vt(r,n,f){return p(this,arguments,function*(t,e,o,i={}){let c=[[t,e]],a=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source"];for(;c.length;){let[d,l]=c.shift(),s=o.get(d)||U(d);o.has(d)||o.set(d,s);for(let g of a){let y=s.getPropertyValue(g);if(!y||y==="none")continue;let b=_(y),w=yield Promise.all(b.map(x=>j(x,i)));w.some(x=>x&&x!=="none"&&!/^url\(undefined/.test(x))&&l.style.setProperty(g,w.join(", "))}let h=s.getPropertyValue("background-color");h&&h!=="transparent"&&h!=="rgba(0, 0, 0, 0)"&&(l.style.backgroundColor=h);let m=Array.from(d.children),u=Array.from(l.children);for(let g=0;g<Math.min(m.length,u.length);g++)c.push([m[g],u[g]])}})}function kt(o){return p(this,arguments,function*(t,e={}){if(!t)throw new Error("Element cannot be null or undefined");let{compress:i=!0,embedFonts:r=!1,fast:n=!0,scale:f=1,useProxy:c=""}=e,a,d,l,s="",h="",m,u;if({clone:a,classCSS:d,styleCache:l}=yield Et(t,i,r,e),yield new Promise(y=>{V(()=>p(null,null,function*(){yield $t(a,e),y()}),{fast:n})}),yield new Promise(y=>{V(()=>p(null,null,function*(){yield vt(t,a,l,e),y()}),{fast:n})}),r&&(yield new Promise(y=>{V(()=>p(null,null,function*(){s=yield J(),y()}),{fast:n})})),i){let y=ut(a).sort(),b=y.join(",");W.has(b)?h=W.get(b):yield new Promise(w=>{V(()=>{h=pt(y),W.set(b,h),w()},{fast:n})})}yield new Promise(y=>{V(()=>{let b=t.getBoundingClientRect(),w=b.width,x=b.height,N=Number.isFinite(e.width),C=Number.isFinite(e.height),k=typeof f=="number"&&f!==1;if(!k){let L=b.width/b.height;N&&C?(w=e.width,x=e.height):N?(w=e.width,x=w/L):C&&(x=e.height,w=x*L)}if(w=Math.ceil(w),x=Math.ceil(x),a.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),a.style.transformOrigin="top left",!k&&(N||C)){let L=b.width,Tt=b.height,Nt=w/L,Pt=x/Tt,Lt=a.style.transform||"",Ut=`scale(${Nt}, ${Pt})`;a.style.transform=`${Ut} ${Lt}`.trim()}else k&&K()&&(a.style.scale=`${f}`);let B="http://www.w3.org/2000/svg",v=document.createElementNS(B,"foreignObject");v.setAttribute("width","100%"),v.setAttribute("height","100%");let I=document.createElement("style");I.textContent=h+s+"svg{overflow:visible;}"+d,v.appendChild(I),v.appendChild(a);let q=new XMLSerializer().serializeToString(v);u=`<svg xmlns="${B}" width="${w}" height="${x}" viewBox="0 0 ${w} ${x}">`+q+"</svg>",m=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`,y()},{fast:n})});let g=document.getElementById("snapdom-sandbox");return g&&g.style.position==="absolute"&&g.remove(),m})}function jt(i,r){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1}){let n=new Image;return n.src=t,yield n.decode(),K?(n.width=n.width*o,n.height=n.height*o):(n.width=n.width/o,n.height=n.height/o),n})}function It(i){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1}={}){let r=new Image;r.src=t,yield r.decode();let n=document.createElement("canvas"),f=r.width*o,c=r.height*o;n.width=Math.ceil(f*e),n.height=Math.ceil(c*e);let a=n.getContext("2d");return a.scale(e,e),a.drawImage(r,0,0,f,c),n.style.width=`${f}px`,n.style.height=`${c}px`,n})}function Rt(n){return p(this,arguments,function*(t,{type:e="svg",scale:o=1,backgroundColor:i="#fff",quality:r}={}){let f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[e]||"image/png";if(e==="svg"){let a=decodeURIComponent(t.split(",")[1]);return new Blob([a],{type:"image/svg+xml"})}let c=yield it(t,{dpr:1,scale:o},i);return new Promise(a=>{c.toBlob(d=>a(d),`${f}`,r)})})}function it(r,n,f){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1},i){let c=yield It(t,{dpr:e,scale:o});if(!i)return c;let a=document.createElement("canvas");a.width=c.width,a.height=c.height;let d=a.getContext("2d");return d.fillStyle=i,d.fillRect(0,0,a.width,a.height),d.drawImage(c,0,0),a})}function st(f,c){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1,backgroundColor:i="#fff",quality:r},n="png"){let a=yield it(t,{dpr:e,scale:o},i),d=new Image;return d.src=a.toDataURL(`image/${n}`,r),yield d.decode(),d.style.width=`${a.width/e}px`,d.style.height=`${a.height/e}px`,d})}function Vt(f){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1,backgroundColor:i="#fff",format:r="png",filename:n="capture"}={}){if(r==="svg"){let m=yield Rt(t),u=URL.createObjectURL(m),g=document.createElement("a");g.href=u,g.download=`${n}.svg`,g.click(),URL.revokeObjectURL(u);return}let c=["jpg","jpeg","webp"].includes(r)?"#fff":void 0,a=i!=null?i:c,d=yield it(t,{dpr:e,scale:o},a),l={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[r]||"image/png",s=d.toDataURL(l),h=document.createElement("a");h.href=s,h.download=`${n}.${r}`,h.click()})}function S(o){return p(this,arguments,function*(t,e={}){if(e=D({scale:1},e),!t)throw new Error("Element cannot be null or undefined");return e.iconFonts&&xt(e.iconFonts),yield S.capture(t,e)})}S.capture=(o,...i)=>p(null,[o,...i],function*(t,e={}){let r=yield kt(t,e),n=window.devicePixelRatio||1,f=e.scale||1;return{url:r,options:e,toRaw:()=>r,toImg:()=>jt(r,{dpr:n,scale:f}),toCanvas:()=>It(r,{dpr:n,scale:f}),toBlob:c=>Rt(r,D({dpr:n,scale:f},c)),toPng:c=>st(r,D({dpr:n,scale:f},c),"png"),toJpg:c=>st(r,D({dpr:n,scale:f},c),"jpeg"),toWebp:c=>st(r,D({dpr:n,scale:f},c),"webp"),download:({format:c="png",filename:a="capture",backgroundColor:d}={})=>Vt(r,{dpr:n,scale:f,backgroundColor:d,format:c,filename:a})}});S.toRaw=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toRaw()});S.toImg=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toImg()});S.toCanvas=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toCanvas()});S.toBlob=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toBlob(e)});S.toPng=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toPng(e)});S.toJpg=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toJpg(e)});S.toWebp=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toWebp(e)});S.download=(o,...i)=>p(null,[o,...i],function*(t,e={}){let d=e,{format:r="png",filename:n="capture",backgroundColor:f}=d,c=dt(d,["format","filename","backgroundColor"]);return yield(yield S.capture(t,c)).download({format:r,filename:n,backgroundColor:f})});function At(){return p(this,arguments,function*(t=document,e={}){let{embedFonts:o=!0,reset:i=!1}=e;if(i){R.clear(),M.clear(),$.clear(),W.clear();return}yield document.fonts.ready,ht();let r=[],n=[];t!=null&&t.querySelectorAll&&(r=Array.from(t.querySelectorAll("img[src]")),n=Array.from(t.querySelectorAll("*")));let f=[];for(let c of r){let a=c.src;R.has(a)||f.push(F(a,{useProxy:e.useProxy}).then(d=>R.set(a,d)).catch(()=>{}))}for(let c of n){let a=U(c).backgroundImage;if(a&&a!=="none"){let d=_(a);for(let l of d)l.startsWith("url(")&&f.push(j(l,e).catch(()=>{}))}}o&&(yield J({preCached:!0})),yield Promise.all(f)})}window.snapdom=S;window.preCache=At;})();
@@ -1,15 +1,15 @@
1
- var A=new Map,U=new Map,S=new Map,P=new Map,B=new Map,K=new WeakMap,I=new Set;var Ct=["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 tt(){for(let t of Ct)et(t)}function et(t){if(P.has(t))return P.get(t);if(new Set(["script","style","meta","link","noscript","template"]).has(t)){let n={};return P.set(t,n),n}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 s=document.createElement(t);s.style.all="initial",o.appendChild(s);let r=getComputedStyle(s),a={};for(let n of r)a[n]=r.getPropertyValue(n);return o.removeChild(s),P.set(t,a),a}function W(t,e,o=!1){let s=[],r=et(e);for(let[a,n]of Object.entries(t))if(!o)n&&s.push(`${a}:${n}`);else{let i=r[a];n&&n!==i&&s.push(`${a}:${n}`)}return s.sort().join(";")}function nt(t){let e=new Set;return t.nodeType!==Node.ELEMENT_NODE&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(t.tagName&&e.add(t.tagName.toLowerCase()),typeof t.querySelectorAll=="function"&&t.querySelectorAll("*").forEach(o=>e.add(o.tagName.toLowerCase())),Array.from(e))}function ot(t){let e=new Map;for(let s of t){let r=P.get(s);if(!r)continue;let a=Object.entries(r).map(([n,i])=>`${n}:${i};`).sort().join("");e.has(a)||e.set(a,[]),e.get(a).push(s)}let o="";for(let[s,r]of e.entries())o+=`${r.join(",")} { ${s} }
2
- `;return o}function rt(t){let e=new Set(t.values()),o=new Map,s=1;for(let r of e)o.set(r,`c${s++}`);return o}async function F(t,e={}){let o=t.startsWith("url("),s=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t);if(o){let r=j(t);if(!r)return t;let a=J(r);if(U.has(a))return e.skipInline?void 0:`url(${U.get(a)})`;{let n=e.crossOrigin?e.crossOrigin(a):"anonymous",i=await L(a,3e3,n);return U.set(a,i),e.skipInline?void 0:`url(${i})`}}return t}function M(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function N(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let o=K.get(t);if(o||(o=new Map,K.set(t,o)),!o.has(e)){let s=window.getComputedStyle(t,e);o.set(e,s)}return o.get(e)}function at(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch{return e}return e}function j(t){let e=t.indexOf("url(");if(e===-1)return null;let o=t.slice(e+4).trim();return o.endsWith(")")&&(o=o.slice(0,-1).trim()),(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))&&(o=o.slice(1,-1)),o}function _(t){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,/lucide/i].some(o=>o.test(t))}function L(t,e=3e3,o="anonymous"){return A.has(t)?Promise.resolve(A.get(t)):new Promise((s,r)=>{let a=setTimeout(()=>{r(new Error("Image load timed out"))},e),n=new Image;n.crossOrigin=o,n.onload=async()=>{clearTimeout(a);try{await n.decode();let i=document.createElement("canvas");i.width=n.width,i.height=n.height,i.getContext("2d").drawImage(n,0,0,i.width,i.height);try{let l=i.toDataURL("image/png");A.set(t,l),s(l)}catch{r(new Error("CORS restrictions prevented image capture"))}}catch(i){r(i)}},n.onerror=i=>{clearTimeout(a),r(new Error("Failed to load image: "+(i.message||"Unknown error")))},n.src=t})}function V(t){let e={};for(let o of t)e[o]=t.getPropertyValue(o);return e}function H(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function st(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(o,s)=>{let r=s.split(",").map(a=>a.trim());return r.length!==6?`matrix(${s})`:(r[4]="0",r[5]="0",`matrix(${r.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(o,s)=>{let r=s.split(",").map(a=>a.trim());return r.length!==16?`matrix3d(${s})`:(r[12]="0",r[13]="0",`matrix3d(${r.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function J(t){try{let e=decodeURI(t);return encodeURI(e)}catch{return t}}function O(t){let e=[],o=0,s=0;for(let r=0;r<t.length;r++){let a=t[r];a==="("&&o++,a===")"&&o--,a===","&&o===0&&(e.push(t.slice(s,r).trim()),s=r+1)}return e.push(t.slice(s).trim()),e}function G(t,e,o,s,r){if(t.tagName==="STYLE")return;s.has(t)||s.set(t,N(t));let a=s.get(t),n=V(a),i=t.tagName?.toLowerCase()||"div",c=W(n,i,r);o.set(e,c)}function Y(t,e,o,s,r){if(t.nodeType===Node.ELEMENT_NODE&&t.getAttribute("data-capture")==="exclude"){let i=document.createElement("div"),c=t.getBoundingClientRect();return i.style.cssText=`display: inline-block; width: ${c.width}px; height: ${c.height}px; visibility: hidden;`,i}if(t.tagName==="IFRAME"){let i=document.createElement("div");return i.textContent="",i.style.cssText=`width: ${t.offsetWidth}px; height: ${t.offsetHeight}px; background-image: 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;`,i}if(t.nodeType===Node.ELEMENT_NODE&&t.getAttribute("data-capture")==="placeholder"){let i=t.cloneNode(!1);s.set(i,t),G(t,i,e,o,r);let c=document.createElement("div");return c.textContent=t.getAttribute("data-placeholder-text")||"",c.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",i.appendChild(c),i}if(t.tagName==="CANVAS"){let i=t.toDataURL(),c=document.createElement("img");return c.src=i,c.width=t.width,c.height=t.height,c.style.display="inline-block",c.style.width=t.style.width||`${t.width}px`,c.style.height=t.style.height||`${t.height}px`,c}if(t.nodeType===Node.TEXT_NODE){if(t.parentElement?.shadowRoot){let i=t.parentElement.tagName.toLowerCase();if(customElements.get(i))return null}return t.cloneNode(!0)}if(t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);let a=t.cloneNode(!1);s.set(a,t),t instanceof HTMLInputElement?(a.value=t.value,a.setAttribute("value",t.value),t.checked!==void 0&&(a.checked=t.checked,t.checked&&a.setAttribute("checked",""))):t instanceof HTMLTextAreaElement?(a.value=t.value,a.textContent=t.value):t instanceof HTMLSelectElement&&(a.value=t.value,Array.from(a.options).forEach(i=>{i.value===t.value?i.setAttribute("selected",""):i.removeAttribute("selected")})),G(t,a,e,o,r);let n=document.createDocumentFragment();if(t.childNodes.forEach(i=>{let c=Y(i,e,o,s,r);c&&n.appendChild(c)}),a.appendChild(n),t.shadowRoot){let i=Array.from(t.shadowRoot.children).filter(l=>l.tagName!=="STYLE").map(l=>Y(l,e,o,s)).filter(Boolean),c=document.createDocumentFragment();i.forEach(l=>c.appendChild(l)),a.appendChild(c)}return a}async function it(t,e,o,s=32,r="#000"){e=e.replace(/^['"]+|['"]+$/g,"");let a=window.devicePixelRatio||1,i=document.createElement("canvas").getContext("2d");i.font=o?`${o} ${s}px "${e}"`:`${s}px "${e}"`;let c=i.measureText(t),l=c.actualBoundingBoxAscent||s*.8,f=c.actualBoundingBoxDescent||s*.2,m=l+f,h=c.width,p=document.createElement("canvas");p.width=Math.ceil(h*a),p.height=Math.ceil(m*a);let d=p.getContext("2d");return d.scale(a,a),d.font=i.font,d.textAlign="left",d.textBaseline="alphabetic",d.fillStyle=r,d.fillText(t,0,l),p.toDataURL()}function ct(t){return Array.from(document.styleSheets).some(e=>e.href===t)}function bt(t){return new Promise(e=>{if(ct(t))return e(null);let o=document.createElement("link");o.rel="stylesheet",o.href=t,o.setAttribute("data-snapdom","injected-import"),o.onload=()=>e(o),o.onerror=()=>e(null),document.head.appendChild(o)})}async function X({ignoreIconFonts:t=!0,preCached:e=!1}={}){if(S.has("fonts-embed-css")){if(e){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=S.get("fonts-embed-css"),document.head.appendChild(n)}return S.get("fonts-embed-css")}let o=/@import\s+url\(["']?([^"')]+)["']?\)/g,s=[];for(let n of document.querySelectorAll("style")){let i=n.textContent||"",c=Array.from(i.matchAll(o));for(let l of c){let f=l[1];ct(f)||s.push(f)}}await Promise.all(s.map(bt));let r=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),a="";for(let n of r)try{let c=await(await fetch(n.href)).text();if(t&&(_(n.href)||_(c)))continue;let l=/url\((["']?)([^"')]+)\1\)/g,f=await Promise.all(Array.from(c.matchAll(l)).map(async h=>{let p=j(h[0]);if(!p)return null;let d=p;if(!d.startsWith("http")&&!d.startsWith("data:")&&(d=new URL(d,n.href).href),t&&_(d))return null;if(S.has(d))return I.add(d),{original:h[0],inlined:`url(${S.get(d)})`};if(I.has(d))return null;try{let g=await(await fetch(d)).blob(),y=await new Promise(E=>{let C=new FileReader;C.onload=()=>E(C.result),C.readAsDataURL(g)});return S.set(d,y),I.add(d),{original:h[0],inlined:`url(${y})`}}catch{return console.warn("[snapdom] Failed to fetch font resource:",d),null}})),m=c;for(let h of f)h&&(m=m.replace(h.original,h.inlined));a+=m+`
3
- `}catch{console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||r.every(i=>i.href!==n.href)){for(let i of n.cssRules)if(i.type===CSSRule.FONT_FACE_RULE){let c=i.style.getPropertyValue("src");if(!c)continue;let l=/url\((["']?)([^"')]+)\1\)/g,f=c,m=Array.from(c.matchAll(l));for(let h of m){let p=h[2].trim();if(!p)continue;let d=p;if(!d.startsWith("http")&&!d.startsWith("data:")&&(d=new URL(d,n.href||location.href).href),!(t&&_(d))){if(S.has(d)){I.add(d),f=f.replace(h[0],`url(${S.get(d)})`);continue}if(!I.has(d))try{let g=await(await fetch(d)).blob(),y=await new Promise(E=>{let C=new FileReader;C.onload=()=>E(C.result),C.readAsDataURL(g)});S.set(d,y),I.add(d),f=f.replace(h[0],`url(${y})`)}catch{console.warn("[snapdom] Failed to fetch font URL:",d)}}}a+=`@font-face {
4
- font-family: ${i.style.getPropertyValue("font-family")};
1
+ var v=new Map,F=new Map,S=new Map,B=new Map,D=new Map,G=new WeakMap,R=new Set;var kt=["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 rt(){for(let t of kt)st(t)}function st(t){if(B.has(t))return B.get(t);if(new Set(["script","style","meta","link","noscript","template"]).has(t)){let c={};return B.set(t,c),c}let n=document.getElementById("snapdom-sandbox");n||(n=document.createElement("div"),n.id="snapdom-sandbox",n.style.position="absolute",n.style.left="-9999px",n.style.top="-9999px",n.style.width="0",n.style.height="0",n.style.overflow="hidden",document.body.appendChild(n));let r=document.createElement(t);r.style.all="initial",n.appendChild(r);let a=getComputedStyle(r),o={};for(let c of a)o[c]=a.getPropertyValue(c);return n.removeChild(r),B.set(t,o),o}function V(t,e,n=!1){let r=[],a=st(e);for(let[o,c]of Object.entries(t))if(!n)c&&r.push(`${o}:${c}`);else{let i=a[o];c&&c!==i&&r.push(`${o}:${c}`)}return r.sort().join(";")}function it(t){let e=new Set;return t.nodeType!==Node.ELEMENT_NODE&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(t.tagName&&e.add(t.tagName.toLowerCase()),typeof t.querySelectorAll=="function"&&t.querySelectorAll("*").forEach(n=>e.add(n.tagName.toLowerCase())),Array.from(e))}function ct(t){let e=new Map;for(let r of t){let a=B.get(r);if(!a)continue;let o=Object.entries(a).map(([c,i])=>`${c}:${i};`).sort().join("");e.has(o)||e.set(o,[]),e.get(o).push(r)}let n="";for(let[r,a]of e.entries())n+=`${a.join(",")} { ${r} }
2
+ `;return n}function lt(t){let e=new Set(t.values()),n=new Map,r=1;for(let a of e)n.set(a,`c${r++}`);return n}async function M(t,e={}){let r=t.match(/url\(["']?(.*?)["']?\)/)?.[1],a=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t);if(r){let o=Y(r);if(F.has(o))return e.skipInline?void 0:`url(${F.get(o)})`;{let c=await U(o,{useProxy:e.useProxy});return F.set(o,c),e.skipInline?void 0:`url("${c}")`}}return t}function O(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function L(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let n=G.get(t);if(n||(n=new Map,G.set(t,n)),!n.has(e)){let r=window.getComputedStyle(t,e);n.set(e,r)}return n.get(e)}function ft(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch{return e}return e}function H(t){let e=t.indexOf("url(");if(e===-1)return null;let n=t.slice(e+4).trim();return n.endsWith(")")&&(n=n.slice(0,-1).trim()),(n.startsWith('"')&&n.endsWith('"')||n.startsWith("'")&&n.endsWith("'"))&&(n=n.slice(1,-1)),n}function U(t,{timeout:e=3e3,useProxy:n=""}={}){function r(l){try{return new URL(l,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch{return"anonymous"}}async function a(l){let s=f=>fetch(f,{mode:"cors",credentials:r(f)==="use-credentials"?"include":"omit"}).then(d=>d.blob()).then(d=>new Promise((h,u)=>{let m=new FileReader;m.onloadend=()=>{let g=m.result;if(typeof g!="string"||!g.startsWith("data:image/")){u(new Error("Invalid image data URL"));return}h(g)},m.onerror=()=>u(new Error("FileReader error")),m.readAsDataURL(d)}));try{return await s(l)}catch{if(n&&typeof n=="string"){let d=n.replace(/\/$/,"")+Y(l);try{return await s(d)}catch{throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${l}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${l}`),new Error("Fetch fallback failed and no proxy provided")}}let o=r(t);return console.log(`[SnapDOM - fetchImage] Start loading image: ${t} with crossOrigin=${o}`),v.has(t)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${t}`),Promise.resolve(v.get(t))):t.startsWith("data:image/")?(v.set(t,t),Promise.resolve(t)):/\.svg(\?.*)?$/i.test(t)?(async()=>{try{let s=await(await fetch(t,{mode:"cors",credentials:o==="use-credentials"?"include":"omit"})).text(),f=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(s)}`;return v.set(t,f),f}catch{return a(t)}})():new Promise((l,s)=>{let f=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${e}ms for image: ${t}`),s(new Error("Image load timed out"))},e),d=new Image;d.crossOrigin=o,d.onload=async()=>{clearTimeout(f);try{await d.decode();let h=document.createElement("canvas");h.width=d.width,h.height=d.height,h.getContext("2d").drawImage(d,0,0,h.width,h.height);let m=h.toDataURL("image/png");v.set(t,m),l(m)}catch{try{let h=await a(t);v.set(t,h),l(h)}catch(h){s(h)}}},d.onerror=async()=>{clearTimeout(f),console.error(`[SnapDOM - fetchImage] Image failed to load: ${t}`);try{let h=await a(t);v.set(t,h),l(h)}catch(h){s(h)}},d.src=t})}function J(t){let e={};for(let n of t)e[n]=t.getPropertyValue(n);return e}function X(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function dt(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(n,r)=>{let a=r.split(",").map(o=>o.trim());return a.length!==6?`matrix(${r})`:(a[4]="0",a[5]="0",`matrix(${a.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(n,r)=>{let a=r.split(",").map(o=>o.trim());return a.length!==16?`matrix3d(${r})`:(a[12]="0",a[13]="0",`matrix3d(${a.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function Y(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function W(t){let e=[],n=0,r=0;for(let a=0;a<t.length;a++){let o=t[a];o==="("&&n++,o===")"&&n--,o===","&&n===0&&(e.push(t.slice(r,a).trim()),r=a+1)}return e.push(t.slice(r).trim()),e}var Q=new WeakMap,Z=new Map;function It(t){let e={};for(let n=0;n<t.length;n++){let r=t[n],a=t.getPropertyValue(r);(r==="background-image"||r==="content")&&a.includes("url(")&&!a.includes("data:")&&(a="none"),e[r]=a}return e}function tt(t,e,n,r,a){if(t.tagName==="STYLE")return;r.has(t)||r.set(t,L(t));let o=r.get(t);if(!Q.has(t)){let f=It(o);Q.set(t,f)}let c=Q.get(t),i=Object.entries(c).sort(([f],[d])=>f.localeCompare(d)).map(([f,d])=>`${f}:${d}`).join(";");if(Z.has(i)){n.set(e,Z.get(i));return}let l=t.tagName?.toLowerCase()||"div",s=V(c,l,a);Z.set(i,s),n.set(e,s)}function Rt(t){return t.nodeType===Node.ELEMENT_NODE&&t.tagName==="SLOT"}function _(t,e,n,r,a,o={},c){if(t.nodeType===Node.TEXT_NODE||t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);if(t.getAttribute("data-capture")==="exclude"){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}if(o.exclude&&Array.isArray(o.exclude))for(let l of o.exclude)try{if(t.matches?.(l)){let s=document.createElement("div"),f=t.getBoundingClientRect();return s.style.cssText=`display: inline-block; width: ${f.width}px; height: ${f.height}px; visibility: hidden;`,s}}catch(s){console.warn(`Invalid selector in exclude option: ${l}`,s)}if(typeof o.filter=="function")try{if(!o.filter(t,c||t)){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}}catch(l){console.warn("Error in filter function:",l)}if(t.tagName==="IFRAME"){let l=document.createElement("div");return l.textContent="",l.style.cssText=`width: ${t.offsetWidth}px; height: ${t.offsetHeight}px; background-image: 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;`,l}if(t.getAttribute("data-capture")==="placeholder"){let l=t.cloneNode(!1);r.set(l,t),tt(t,l,e,n,a);let s=document.createElement("div");return s.textContent=t.getAttribute("data-placeholder-text")||"",s.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",l.appendChild(s),l}if(t.tagName==="CANVAS"){let l=t.toDataURL(),s=document.createElement("img");return s.src=l,s.width=t.width,s.height=t.height,s.style.display="inline-block",s.style.width=t.style.width||`${t.width}px`,s.style.height=t.style.height||`${t.height}px`,s}let i=t.cloneNode(!1);if(r.set(i,t),t instanceof HTMLInputElement)i.value=t.value,i.setAttribute("value",t.value),t.checked!==void 0&&(i.checked=t.checked,t.checked&&i.setAttribute("checked",""));else if(t instanceof HTMLTextAreaElement){let l=t.getBoundingClientRect();i.textContent=t.value,i.style.width=`${l.width}px`,i.style.height=`${l.height}px`}else t instanceof HTMLSelectElement&&(i.value=t.value,Array.from(i.options).forEach(l=>{l.value===t.value?l.setAttribute("selected",""):l.removeAttribute("selected")}));if(tt(t,i,e,n,a),Rt(t)){let l=t.assignedNodes?.({flatten:!0})||[],s=l.length>0?l:Array.from(t.childNodes),f=document.createDocumentFragment();for(let d of s){let h=_(d,e,n,r,a,o,c||t);h&&f.appendChild(h)}return f}else if(!(t instanceof HTMLTextAreaElement)){let l=t.shadowRoot?t.shadowRoot.childNodes:t.childNodes;for(let s of l){let f=_(s,e,n,r,a,o,c||t);f&&i.appendChild(f)}if(t.shadowRoot&&t.childNodes.length>0&&!t.shadowRoot.querySelector("slot")){let s=document.createDocumentFragment();for(let f of t.childNodes){let d=_(f,e,n,r,a,o,c||t);d&&s.appendChild(d)}i.appendChild(s)}}return i}var At=[/font\s*awesome/i,/material\s*icons/i,/ionicons/i,/glyphicons/i,/feather/i,/bootstrap\s*icons/i,/remix\s*icons/i,/heroicons/i,/layui/i,/lucide/i],et=[];function ht(t){let e=Array.isArray(t)?t:[t];for(let n of e)n instanceof RegExp?et.push(n):typeof n=="string"?et.push(new RegExp(n,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",n)}function A(t){let e=typeof t=="string"?t:"",n=[...At,...et];for(let r of n)if(r instanceof RegExp&&r.test(e))return!0;return!!(/icon/i.test(e)||/glyph/i.test(e)||/symbols/i.test(e)||/feather/i.test(e)||/fontawesome/i.test(e))}async function mt(t,e,n,r=32,a="#000"){e=e.replace(/^['"]+|['"]+$/g,"");let o=window.devicePixelRatio||1,i=document.createElement("canvas").getContext("2d");i.font=n?`${n} ${r}px "${e}"`:`${r}px "${e}"`;let l=i.measureText(t),s=l.actualBoundingBoxAscent||r*.8,f=l.actualBoundingBoxDescent||r*.2,d=s+f,h=l.width,u=document.createElement("canvas");u.width=Math.ceil(h*o),u.height=Math.ceil(d*o);let m=u.getContext("2d");return m.scale(o,o),m.font=i.font,m.textAlign="left",m.textBaseline="alphabetic",m.fillStyle=a,m.fillText(t,0,s),u.toDataURL()}function ut(t){return Array.from(document.styleSheets).some(e=>e.href===t)}function Tt(t){return new Promise(e=>{if(ut(t))return e(null);let n=document.createElement("link");n.rel="stylesheet",n.href=t,n.setAttribute("data-snapdom","injected-import"),n.onload=()=>e(n),n.onerror=()=>e(null),document.head.appendChild(n)})}async function K({preCached:t=!1}={}){if(S.has("fonts-embed-css")){if(t){let o=document.createElement("style");o.setAttribute("data-snapdom","embedFonts"),o.textContent=S.get("fonts-embed-css"),document.head.appendChild(o)}return S.get("fonts-embed-css")}let e=/@import\s+url\(["']?([^"')]+)["']?\)/g,n=[];for(let o of document.querySelectorAll("style")){let c=o.textContent||"",i=Array.from(c.matchAll(e));for(let l of i){let s=l[1];A(s)||ut(s)||n.push(s)}}await Promise.all(n.map(Tt));let r=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(o=>o.href),a="";for(let o of r)try{let i=await(await fetch(o.href)).text();if(A(o.href)||A(i))continue;let l=/url\((["']?)([^"')]+)\1\)/g,s=await Promise.all(Array.from(i.matchAll(l)).map(async d=>{let h=H(d[0]);if(!h)return null;let u=h;if(!u.startsWith("http")&&!u.startsWith("data:")&&(u=new URL(u,o.href).href),A(u))return null;if(S.has(u))return R.add(u),{original:d[0],inlined:`url(${S.get(u)})`};if(R.has(u))return null;try{let g=await(await fetch(u)).blob(),p=await new Promise(y=>{let w=new FileReader;w.onload=()=>y(w.result),w.readAsDataURL(g)});return S.set(u,p),R.add(u),{original:d[0],inlined:`url(${p})`}}catch{return console.warn("[snapdom] Failed to fetch font resource:",u),null}})),f=i;for(let d of s)d&&(f=f.replace(d.original,d.inlined));a+=f+`
3
+ `}catch{console.warn("[snapdom] Failed to fetch CSS:",o.href)}for(let o of document.styleSheets)try{if(!o.href||r.every(c=>c.href!==o.href)){for(let c of o.cssRules)if(c.type===CSSRule.FONT_FACE_RULE){let i=c.style.getPropertyValue("src"),l=c.style.getPropertyValue("font-family");if(!i||A(l))continue;let s=/url\((["']?)([^"')]+)\1\)/g,f=i,d=Array.from(i.matchAll(s));for(let h of d){let u=h[2].trim();if(!u)continue;let m=u;if(!m.startsWith("http")&&!m.startsWith("data:")&&(m=new URL(m,o.href||location.href).href),!A(m)){if(S.has(m)){R.add(m),f=f.replace(h[0],`url(${S.get(m)})`);continue}if(!R.has(m))try{let p=await(await fetch(m)).blob(),y=await new Promise(w=>{let E=new FileReader;E.onload=()=>w(E.result),E.readAsDataURL(p)});S.set(m,y),R.add(m),f=f.replace(h[0],`url(${y})`)}catch{console.warn("[snapdom] Failed to fetch font URL:",m)}}}a+=`@font-face {
4
+ font-family: ${l};
5
5
  src: ${f};
6
- font-style: ${i.style.getPropertyValue("font-style")||"normal"};
7
- font-weight: ${i.style.getPropertyValue("font-weight")||"normal"};
6
+ font-style: ${c.style.getPropertyValue("font-style")||"normal"};
7
+ font-weight: ${c.style.getPropertyValue("font-weight")||"normal"};
8
8
  }
9
- `}}}catch(i){console.warn("[snapdom] Cannot access stylesheet",n.href,i)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){let i=n._snapdomSrc;if(!i.startsWith("data:")){if(S.has(n._snapdomSrc))i=S.get(n._snapdomSrc),I.add(n._snapdomSrc);else if(!I.has(n._snapdomSrc))try{let l=await(await fetch(n._snapdomSrc)).blob();i=await new Promise(f=>{let m=new FileReader;m.onload=()=>f(m.result),m.readAsDataURL(l)}),S.set(n._snapdomSrc,i),I.add(n._snapdomSrc)}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}a+=`@font-face {
10
- font-family: '${n.family}';
11
- src: url(${i});
12
- font-style: ${n.style||"normal"};
13
- font-weight: ${n.weight||"normal"};
9
+ `}}}catch(c){console.warn("[snapdom] Cannot access stylesheet",o.href,c)}for(let o of document.fonts)if(o.family&&o.status==="loaded"&&o._snapdomSrc){if(A(o.family))continue;let c=o._snapdomSrc;if(!c.startsWith("data:")){if(S.has(o._snapdomSrc))c=S.get(o._snapdomSrc),R.add(o._snapdomSrc);else if(!R.has(o._snapdomSrc))try{let l=await(await fetch(o._snapdomSrc)).blob();c=await new Promise(s=>{let f=new FileReader;f.onload=()=>s(f.result),f.readAsDataURL(l)}),S.set(o._snapdomSrc,c),R.add(o._snapdomSrc)}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",o._snapdomSrc);continue}}a+=`@font-face {
10
+ font-family: '${o.family}';
11
+ src: url(${c});
12
+ font-style: ${o.style||"normal"};
13
+ font-weight: ${o.weight||"normal"};
14
14
  }
15
- `}if(a&&(S.set("fonts-embed-css",a),e)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=a,document.head.appendChild(n)}return a}async function Q(t,e,o,s,r,a=!1){if(!(t instanceof Element)||!(e instanceof Element))return;for(let c of["::before","::after","::first-letter"])try{let l=N(t,c);if(!l||typeof l[Symbol.iterator]!="function")continue;if(c==="::first-letter"){let g=getComputedStyle(t);if(!(l.color!==g.color||l.fontSize!==g.fontSize||l.fontWeight!==g.fontWeight))continue;let E=Array.from(e.childNodes).find(b=>b.nodeType===Node.TEXT_NODE&&b.textContent&&b.textContent.trim().length>0);if(!E)continue;let C=E.textContent,T=C.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],R=C.slice(T?.length||0);if(!T||/[\uD800-\uDFFF]/.test(T))continue;let k=document.createElement("span");k.textContent=T,k.dataset.snapdomPseudo="::first-letter";let v=V(l),q=W(v,"span",r);o.set(k,q);let z=document.createTextNode(R);e.replaceChild(z,E),e.insertBefore(k,z);continue}let f=l.getPropertyValue("content"),m=l.getPropertyValue("background-image"),h=l.getPropertyValue("background-color"),p=f!=="none",d=m&&m!=="none",u=h&&h!=="transparent"&&h!=="rgba(0, 0, 0, 0)";if(p||d||u){let g=l.getPropertyValue("font-family"),y=parseInt(l.getPropertyValue("font-size"))||32,E=parseInt(l.getPropertyValue("font-weight"))||!1,C=l.getPropertyValue("color")||"#000",x=document.createElement("span");x.dataset.snapdomPseudo=c;let T=V(l),R=W(T,"span",r);o.set(x,R);let k=g&&/font.*awesome|material|bootstrap|glyphicons|ionicons|remixicon|simple-line-icons|octicons|feather|typicons|weathericons|lucide/i.test(g),v=at(f);if(!a&&k&&v.length===1){let b=document.createElement("img");b.src=await it(v,g,E,y,C),b.style="display:block;width:100%;height:100%;object-fit:contain;",x.appendChild(b)}else if(v.startsWith("url(")){let b=j(v);if(b&&b.trim()!=="")try{let $=document.createElement("img"),D=await L(J(b));$.src=D,$.style="display:block;width:100%;height:100%;object-fit:contain;",x.appendChild($)}catch($){console.error(`[snapdom] Error in pseudo ${c} for`,t,$)}}else!k&&v&&v!=="none"&&(x.textContent=v);if(d)try{let b=O(m),$=await Promise.all(b.map(D=>F(D)));x.style.backgroundImage=$.join(", ")}catch(b){console.warn(`[snapdom] Failed to inline background-image for ${c}`,b)}if(u&&(x.style.backgroundColor=h),!(x.childNodes.length>0||x.textContent&&x.textContent.trim()!==""||d||u))continue;c==="::before"?e.insertBefore(x,e.firstChild):e.appendChild(x)}}catch(l){console.warn(`[snapdom] Failed to capture ${c} for`,t,l)}let n=Array.from(t.children),i=Array.from(e.children).filter(c=>!c.dataset.snapdomPseudo);for(let c=0;c<Math.min(n.length,i.length);c++)await Q(n[c],i[c],o,s,r,a)}async function lt(t,e=!1,o=!1){let s=new Map,r=new WeakMap,a=new Map,n;try{n=Y(t,s,r,a,e)}catch(c){throw console.warn("deepClone failed:",c),c}try{await Q(t,n,s,r,e,o)}catch(c){console.warn("inlinePseudoElements failed:",c)}let i="";if(e){let c=rt(s);i=Array.from(c.entries()).map(([l,f])=>`.${f}{${l}}`).join("");for(let[l,f]of s.entries()){if(l.tagName==="STYLE")continue;let m=c.get(f);m&&l.classList.add(m);let h=l.style?.backgroundImage;l.removeAttribute("style"),h&&h!=="none"&&(l.style.backgroundImage=h)}}else for(let[c,l]of s.entries())c.tagName!=="STYLE"&&c.setAttribute("style",l.replace(/;/g,"; "));for(let[c,l]of a.entries()){let f=l.scrollLeft,m=l.scrollTop;if((f||m)&&c instanceof HTMLElement){c.style.overflow="hidden",c.style.scrollbarWidth="none",c.style.msOverflowStyle="none";let p=document.createElement("div");for(p.style.transform=`translate(${-f}px, ${-m}px)`,p.style.willChange="transform",p.style.display="inline-block",p.style.width="100%";c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p)}}if(t===a.get(n)){let c=r.get(t)||window.getComputedStyle(t);r.set(t,c);let l=st(c.transform);n.style.margin="0",n.style.position="static",n.style.top="auto",n.style.left="auto",n.style.right="auto",n.style.bottom="auto",n.style.zIndex="auto",n.style.float="none",n.style.clear="none",n.style.transform=l||""}return{clone:n,classCSS:i,styleCache:r}}async function dt(t,e={}){let o=Array.from(t.querySelectorAll("img")),s=async r=>{let a=r.src;try{let n=e.crossOrigin?e.crossOrigin(a):"anonymous",i=await L(a,3e3,n);r.src=i,r.width||(r.width=r.naturalWidth||100),r.height||(r.height=r.naturalHeight||100)}catch{let n=document.createElement("div");n.style=`width: ${r.width||100}px; height: ${r.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${r.height||100}px; color: #666; font-size: 12px;`,n.innerText="img",r.replaceWith(n)}};for(let r=0;r<o.length;r+=4){let a=o.slice(r,r+4).map(s);await Promise.allSettled(a)}}async function ft(t,e,o,s={}){let r=[[t,e]];for(;r.length;){let[a,n]=r.shift(),i=o.get(a)||N(a);o.has(a)||o.set(a,i);let c=i.getPropertyValue("background-image"),l=i.getPropertyValue("background-color");if(!c||c==="none"){let u=Array.from(a.children),g=Array.from(n.children);for(let y=0;y<Math.min(u.length,g.length);y++)r.push([u[y],g[y]]);continue}let f=O(c),m=await Promise.all(f.map(u=>F(u,s)));m.some(u=>u&&u!=="none"&&!/^url\(undefined\)/.test(u))&&(n.style.backgroundImage=m.join(", ")),l&&l!=="transparent"&&l!=="rgba(0, 0, 0, 0)"&&(n.style.backgroundColor=l);let p=Array.from(a.children),d=Array.from(n.children);for(let u=0;u<Math.min(p.length,d.length);u++)r.push([p[u],d[u]])}}async function mt(t,e={}){if(!t)throw new Error("Element cannot be null or undefined");if(!(t instanceof Element))throw new Error("captureDOM: Only Element nodes are supported");let{compress:o=!0,embedFonts:s=!1,fast:r=!0,scale:a=1}=e,n,i,c,l="",f="",m,h;if({clone:n,classCSS:i,styleCache:c}=await lt(t,o,s),await new Promise(d=>{M(async()=>{await dt(n,e),d()},{fast:r})}),await new Promise(d=>{M(async()=>{await ft(t,n,c,e),d()},{fast:r})}),s&&await new Promise(d=>{M(async()=>{l=await X({ignoreIconFonts:!s}),d()},{fast:r})}),o){let d=nt(n).sort(),u=d.join(",");B.has(u)?f=B.get(u):await new Promise(g=>{M(()=>{f=ot(d),B.set(u,f),g()},{fast:r})})}await new Promise(d=>{M(()=>{let u=t.getBoundingClientRect(),g=u.width,y=u.height,E=Number.isFinite(e.width),C=Number.isFinite(e.height),x=typeof a=="number"&&a!==1;if(!x){let $=u.width/u.height;E&&C?(g=e.width,y=e.height):E?(g=e.width,y=g/$):C&&(y=e.height,g=y*$)}if(g=Math.ceil(g),y=Math.ceil(y),n.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),n.style.transformOrigin="top left",!x&&(E||C)){let $=u.width,D=u.height,gt=g/$,yt=y/D,wt=n.style.transform||"",xt=`scale(${gt}, ${yt})`;n.style.transform=`${xt} ${wt}`.trim()}else x&&H()&&(n.style.scale=`${a}`);let T="http://www.w3.org/2000/svg",R=document.createElementNS(T,"foreignObject");R.setAttribute("width","100%"),R.setAttribute("height","100%");let k=document.createElement("style");k.textContent=f+l+"svg{overflow:visible;}"+i,R.appendChild(k),R.appendChild(n);let q=new XMLSerializer().serializeToString(R);h=`<svg xmlns="${T}" width="${g}" height="${y}" viewBox="0 0 ${g} ${y}">`+q+"</svg>",m=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(h)}`,d()},{fast:r})});let p=document.getElementById("snapdom-sandbox");return p&&p.style.position==="absolute"&&p.remove(),m}async function St(t,{dpr:e=1,scale:o=1}){let s=new Image;return s.src=t,await s.decode(),H?(s.width=s.width*o,s.height=s.height*o):(s.width=s.width/o,s.height=s.height/o),s}async function ut(t,{dpr:e=1,scale:o=1}={}){let s=new Image;s.src=t,await s.decode();let r=document.createElement("canvas"),a=s.width*o,n=s.height*o;r.width=Math.ceil(a*e),r.height=Math.ceil(n*e);let i=r.getContext("2d");return i.scale(e,e),i.drawImage(s,0,0,a,n),r.style.width=`${a}px`,r.style.height=`${n}px`,r}async function ht(t){let e=decodeURIComponent(t.split(",")[1]);return new Blob([e],{type:"image/svg+xml"})}async function pt(t,{dpr:e=1,scale:o=1},s){let r=await ut(t,{dpr:e,scale:o});if(!s)return r;let a=document.createElement("canvas");a.width=r.width,a.height=r.height;let n=a.getContext("2d");return n.fillStyle=s,n.fillRect(0,0,a.width,a.height),n.drawImage(r,0,0),a}async function Z(t,{dpr:e=1,scale:o=1,backgroundColor:s="#fff",quality:r},a="png"){let n=await pt(t,{dpr:e,scale:o},s),i=new Image;return i.src=n.toDataURL(`image/${a}`,r),await i.decode(),i.style.width=`${n.width/e}px`,i.style.height=`${n.height/e}px`,i}async function Et(t,{dpr:e=1,scale:o=1,backgroundColor:s="#fff",format:r="png",filename:a="capture"}={}){if(r==="svg"){let h=await ht(t),p=URL.createObjectURL(h),d=document.createElement("a");d.href=p,d.download=`${a}.svg`,d.click(),URL.revokeObjectURL(p);return}let n=["jpg","jpeg","webp"].includes(r)?"#fff":void 0,c=await pt(t,{dpr:e,scale:o},s??n),l={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[r]||"image/png",f=c.toDataURL(l),m=document.createElement("a");m.href=f,m.download=`${a}.${r}`,m.click()}async function w(t,e={}){if(e={scale:1,...e},!t)throw new Error("Element cannot be null or undefined");return await w.capture(t,e)}w.capture=async(t,e={})=>{let o=await mt(t,e),s=window.devicePixelRatio||1,r=e.scale||1;return{url:o,options:e,toRaw:()=>o,toImg:()=>St(o,{dpr:s,scale:r}),toCanvas:()=>ut(o,{dpr:s,scale:r}),toBlob:()=>ht(o),toPng:a=>Z(o,{dpr:s,scale:r,...a},"png"),toJpg:a=>Z(o,{dpr:s,scale:r,...a},"jpeg"),toWebp:a=>Z(o,{dpr:s,scale:r,...a},"webp"),download:({format:a="png",filename:n="capture",backgroundColor:i}={})=>Et(o,{dpr:s,scale:r,backgroundColor:i,format:a,filename:n})}};w.toRaw=async(t,e)=>(await w.capture(t,e)).toRaw();w.toImg=async(t,e)=>(await w.capture(t,e)).toImg();w.toCanvas=async(t,e)=>(await w.capture(t,e)).toCanvas();w.toBlob=async(t,e)=>(await w.capture(t,e)).toBlob();w.toPng=async(t,e)=>(await w.capture(t,e)).toPng(e);w.toJpg=async(t,e)=>(await w.capture(t,e)).toJpg(e);w.toWebp=async(t,e)=>(await w.capture(t,e)).toWebp(e);w.download=async(t,e={})=>{let{format:o="png",filename:s="capture",backgroundColor:r,...a}=e;return await(await w.capture(t,a)).download({format:o,filename:s,backgroundColor:r})};async function $t(t=document,e={}){let{embedFonts:o=!0,reset:s=!1,crossOrigin:r}=e;if(s){A.clear(),U.clear(),S.clear(),B.clear();return}await document.fonts.ready,tt();let a=[],n=[];t?.querySelectorAll&&(a=Array.from(t.querySelectorAll("img[src]")),n=Array.from(t.querySelectorAll("*")));let i=[];for(let c of a){let l=c.src;if(!A.has(l)){let f=r?r(l):"anonymous";i.push(L(l,3e3,f).then(m=>A.set(l,m)).catch(()=>{}))}}for(let c of n){let l=N(c).backgroundImage;if(l&&l!=="none"){let f=O(l);for(let m of f)m.startsWith("url(")&&i.push(F(m,{crossOrigin:r,skipInline:!0}).catch(()=>{}))}}o&&await X({ignoreIconFonts:!o,preCached:!0}),await Promise.all(i)}export{$t as preCache,w as snapdom};
15
+ `}if(a&&(S.set("fonts-embed-css",a),t)){let o=document.createElement("style");o.setAttribute("data-snapdom","embedFonts"),o.textContent=a,document.head.appendChild(o)}return a}async function nt(t,e,n,r,a,o=!1,c){if(!(t instanceof Element)||!(e instanceof Element))return;for(let s of["::before","::after","::first-letter"])try{let f=L(t,s);if(!f||typeof f[Symbol.iterator]!="function")continue;if(s==="::first-letter"){let y=getComputedStyle(t);if(!(f.color!==y.color||f.fontSize!==y.fontSize||f.fontWeight!==y.fontWeight))continue;let E=Array.from(e.childNodes).find(C=>C.nodeType===Node.TEXT_NODE&&C.textContent&&C.textContent.trim().length>0);if(!E)continue;let P=E.textContent,T=P.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],N=P.slice(T?.length||0);if(!T||/[\uD800-\uDFFF]/.test(T))continue;let k=document.createElement("span");k.textContent=T,k.dataset.snapdomPseudo="::first-letter";let I=J(f),q=V(I,"span",a);n.set(k,q);let z=document.createTextNode(N);e.replaceChild(z,E),e.insertBefore(k,z);continue}let d=f.getPropertyValue("content"),h=f.getPropertyValue("background-image"),u=f.getPropertyValue("background-color"),m=d!=="none",g=h&&h!=="none",p=u&&u!=="transparent"&&u!=="rgba(0, 0, 0, 0)";if(m||g||p){let y=f.getPropertyValue("font-family"),w=parseInt(f.getPropertyValue("font-size"))||32,E=parseInt(f.getPropertyValue("font-weight"))||!1,P=f.getPropertyValue("color")||"#000",b=document.createElement("span");b.dataset.snapdomPseudo=s;let T=J(f),N=V(T,"span",a);n.set(b,N);let k=A(y),I=ft(d);if(k&&I.length===1){let C=document.createElement("img");C.src=await mt(I,y,E,w,P),C.style=`width:${w}px;height:auto;object-fit:contain;`,b.appendChild(C)}else if(I.startsWith("url(")){let C=H(I);if(C&&C.trim()!=="")try{let $=document.createElement("img"),j=await U(Y(C,{useProxy:c}));$.src=j,$.style=`width:${w}px;height:auto;object-fit:contain;`,b.appendChild($)}catch($){console.error(`[snapdom] Error in pseudo ${s} for`,t,$)}}else!k&&I&&I!=="none"&&(b.textContent=I);if(g)try{let C=W(h),$=await Promise.all(C.map(j=>M(j)));b.style.backgroundImage=$.join(", ")}catch(C){console.warn(`[snapdom] Failed to inline background-image for ${s}`,C)}if(p&&(b.style.backgroundColor=u),!(b.childNodes.length>0||b.textContent&&b.textContent.trim()!==""||g||p))continue;s==="::before"?e.insertBefore(b,e.firstChild):e.appendChild(b)}}catch(f){console.warn(`[snapdom] Failed to capture ${s} for`,t,f)}let i=Array.from(t.children),l=Array.from(e.children).filter(s=>!s.dataset.snapdomPseudo);for(let s=0;s<Math.min(i.length,l.length);s++)await nt(i[s],l[s],n,r,a,o,c)}function gt(t){if(!t)return;let e=document.querySelectorAll("svg > defs");e.length&&t.querySelectorAll("svg").forEach(n=>{let r=n.querySelectorAll("use");if(!r.length)return;let a=new Set;if(r.forEach(c=>{let i=c.getAttribute("xlink:href")||c.getAttribute("href");i&&i.startsWith("#")&&a.add(i.slice(1))}),!a.size)return;let o=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let c of a)for(let i of e){let l=i.querySelector(`#${CSS.escape(c)}`);if(l){o.appendChild(l.cloneNode(!0));break}}o.childNodes.length&&n.insertBefore(o,n.firstChild)})}async function pt(t,e=!1,n=!1,r={}){let a=new Map,o=new WeakMap,c=new Map,i;try{i=_(t,a,o,c,e,r,t)}catch(s){throw console.warn("deepClone failed:",s),s}try{await nt(t,i,a,o,e,n,r.useProxy)}catch(s){console.warn("inlinePseudoElements failed:",s)}try{gt(i)}catch(s){console.warn("inlineExternalDef failed:",s)}let l="";if(e){let s=lt(a);l=Array.from(s.entries()).map(([f,d])=>`.${d}{${f}}`).join("");for(let[f,d]of a.entries()){if(f.tagName==="STYLE")continue;let h=s.get(d);h&&f.classList.add(h);let u=f.style?.backgroundImage;f.removeAttribute("style"),u&&u!=="none"&&(f.style.backgroundImage=u)}}else for(let[s,f]of a.entries())s.tagName!=="STYLE"&&s.setAttribute("style",f.replace(/;/g,"; "));for(let[s,f]of c.entries()){let d=f.scrollLeft,h=f.scrollTop;if((d||h)&&s instanceof HTMLElement){s.style.overflow="hidden",s.style.scrollbarWidth="none",s.style.msOverflowStyle="none";let m=document.createElement("div");for(m.style.transform=`translate(${-d}px, ${-h}px)`,m.style.willChange="transform",m.style.display="inline-block",m.style.width="100%";s.firstChild;)m.appendChild(s.firstChild);s.appendChild(m)}}if(t===c.get(i)){let s=o.get(t)||window.getComputedStyle(t);o.set(t,s);let f=dt(s.transform);i.style.margin="0",i.style.position="static",i.style.top="auto",i.style.left="auto",i.style.right="auto",i.style.bottom="auto",i.style.zIndex="auto",i.style.float="none",i.style.clear="none",i.style.transform=f||""}for(let[s,f]of c.entries())f.tagName==="PRE"&&(s.style.marginTop="0",s.style.marginBlockStart="0");return{clone:i,classCSS:l,styleCache:o}}async function yt(t,e={}){let n=Array.from(t.querySelectorAll("img")),r=async a=>{let o=a.src;try{let c=await U(o,{useProxy:e.useProxy});a.src=c,a.width||(a.width=a.naturalWidth||100),a.height||(a.height=a.naturalHeight||100)}catch{let c=document.createElement("div");c.style=`width: ${a.width||100}px; height: ${a.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${a.height||100}px; color: #666; font-size: 12px;`,c.innerText="img",a.replaceWith(c)}};for(let a=0;a<n.length;a+=4){let o=n.slice(a,a+4).map(r);await Promise.allSettled(o)}}async function wt(t,e,n,r={}){let a=[[t,e]],o=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source"];for(;a.length;){let[c,i]=a.shift(),l=n.get(c)||L(c);n.has(c)||n.set(c,l);for(let h of o){let u=l.getPropertyValue(h);if(!u||u==="none")continue;let m=W(u),g=await Promise.all(m.map(p=>M(p,r)));g.some(p=>p&&p!=="none"&&!/^url\(undefined/.test(p))&&i.style.setProperty(h,g.join(", "))}let s=l.getPropertyValue("background-color");s&&s!=="transparent"&&s!=="rgba(0, 0, 0, 0)"&&(i.style.backgroundColor=s);let f=Array.from(c.children),d=Array.from(i.children);for(let h=0;h<Math.min(f.length,d.length);h++)a.push([f[h],d[h]])}}async function xt(t,e={}){if(!t)throw new Error("Element cannot be null or undefined");let{compress:n=!0,embedFonts:r=!1,fast:a=!0,scale:o=1,useProxy:c=""}=e,i,l,s,f="",d="",h,u;if({clone:i,classCSS:l,styleCache:s}=await pt(t,n,r,e),await new Promise(g=>{O(async()=>{await yt(i,e),g()},{fast:a})}),await new Promise(g=>{O(async()=>{await wt(t,i,s,e),g()},{fast:a})}),r&&await new Promise(g=>{O(async()=>{f=await K(),g()},{fast:a})}),n){let g=it(i).sort(),p=g.join(",");D.has(p)?d=D.get(p):await new Promise(y=>{O(()=>{d=ct(g),D.set(p,d),y()},{fast:a})})}await new Promise(g=>{O(()=>{let p=t.getBoundingClientRect(),y=p.width,w=p.height,E=Number.isFinite(e.width),P=Number.isFinite(e.height),b=typeof o=="number"&&o!==1;if(!b){let $=p.width/p.height;E&&P?(y=e.width,w=e.height):E?(y=e.width,w=y/$):P&&(w=e.height,y=w*$)}if(y=Math.ceil(y),w=Math.ceil(w),i.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),i.style.transformOrigin="top left",!b&&(E||P)){let $=p.width,j=p.height,St=y/$,Et=w/j,$t=i.style.transform||"",vt=`scale(${St}, ${Et})`;i.style.transform=`${vt} ${$t}`.trim()}else b&&X()&&(i.style.scale=`${o}`);let T="http://www.w3.org/2000/svg",N=document.createElementNS(T,"foreignObject");N.setAttribute("width","100%"),N.setAttribute("height","100%");let k=document.createElement("style");k.textContent=d+f+"svg{overflow:visible;}"+l,N.appendChild(k),N.appendChild(i);let q=new XMLSerializer().serializeToString(N);u=`<svg xmlns="${T}" width="${y}" height="${w}" viewBox="0 0 ${y} ${w}">`+q+"</svg>",h=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`,g()},{fast:a})});let m=document.getElementById("snapdom-sandbox");return m&&m.style.position==="absolute"&&m.remove(),h}async function Nt(t,{dpr:e=1,scale:n=1}){let r=new Image;return r.src=t,await r.decode(),X?(r.width=r.width*n,r.height=r.height*n):(r.width=r.width/n,r.height=r.height/n),r}async function bt(t,{dpr:e=1,scale:n=1}={}){let r=new Image;r.src=t,await r.decode();let a=document.createElement("canvas"),o=r.width*n,c=r.height*n;a.width=Math.ceil(o*e),a.height=Math.ceil(c*e);let i=a.getContext("2d");return i.scale(e,e),i.drawImage(r,0,0,o,c),a.style.width=`${o}px`,a.style.height=`${c}px`,a}async function Ct(t,{type:e="svg",scale:n=1,backgroundColor:r="#fff",quality:a}={}){let o={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[e]||"image/png";if(e==="svg"){let i=decodeURIComponent(t.split(",")[1]);return new Blob([i],{type:"image/svg+xml"})}let c=await at(t,{dpr:1,scale:n},r);return new Promise(i=>{c.toBlob(l=>i(l),`${o}`,a)})}async function at(t,{dpr:e=1,scale:n=1},r){let a=await bt(t,{dpr:e,scale:n});if(!r)return a;let o=document.createElement("canvas");o.width=a.width,o.height=a.height;let c=o.getContext("2d");return c.fillStyle=r,c.fillRect(0,0,o.width,o.height),c.drawImage(a,0,0),o}async function ot(t,{dpr:e=1,scale:n=1,backgroundColor:r="#fff",quality:a},o="png"){let c=await at(t,{dpr:e,scale:n},r),i=new Image;return i.src=c.toDataURL(`image/${o}`,a),await i.decode(),i.style.width=`${c.width/e}px`,i.style.height=`${c.height/e}px`,i}async function Pt(t,{dpr:e=1,scale:n=1,backgroundColor:r="#fff",format:a="png",filename:o="capture"}={}){if(a==="svg"){let h=await Ct(t),u=URL.createObjectURL(h),m=document.createElement("a");m.href=u,m.download=`${o}.svg`,m.click(),URL.revokeObjectURL(u);return}let c=["jpg","jpeg","webp"].includes(a)?"#fff":void 0,l=await at(t,{dpr:e,scale:n},r??c),s={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[a]||"image/png",f=l.toDataURL(s),d=document.createElement("a");d.href=f,d.download=`${o}.${a}`,d.click()}async function x(t,e={}){if(e={scale:1,...e},!t)throw new Error("Element cannot be null or undefined");return e.iconFonts&&ht(e.iconFonts),await x.capture(t,e)}x.capture=async(t,e={})=>{let n=await xt(t,e),r=window.devicePixelRatio||1,a=e.scale||1;return{url:n,options:e,toRaw:()=>n,toImg:()=>Nt(n,{dpr:r,scale:a}),toCanvas:()=>bt(n,{dpr:r,scale:a}),toBlob:o=>Ct(n,{dpr:r,scale:a,...o}),toPng:o=>ot(n,{dpr:r,scale:a,...o},"png"),toJpg:o=>ot(n,{dpr:r,scale:a,...o},"jpeg"),toWebp:o=>ot(n,{dpr:r,scale:a,...o},"webp"),download:({format:o="png",filename:c="capture",backgroundColor:i}={})=>Pt(n,{dpr:r,scale:a,backgroundColor:i,format:o,filename:c})}};x.toRaw=async(t,e)=>(await x.capture(t,e)).toRaw();x.toImg=async(t,e)=>(await x.capture(t,e)).toImg();x.toCanvas=async(t,e)=>(await x.capture(t,e)).toCanvas();x.toBlob=async(t,e)=>(await x.capture(t,e)).toBlob(e);x.toPng=async(t,e)=>(await x.capture(t,e)).toPng(e);x.toJpg=async(t,e)=>(await x.capture(t,e)).toJpg(e);x.toWebp=async(t,e)=>(await x.capture(t,e)).toWebp(e);x.download=async(t,e={})=>{let{format:n="png",filename:r="capture",backgroundColor:a,...o}=e;return await(await x.capture(t,o)).download({format:n,filename:r,backgroundColor:a})};async function Lt(t=document,e={}){let{embedFonts:n=!0,reset:r=!1}=e;if(r){v.clear(),F.clear(),S.clear(),D.clear();return}await document.fonts.ready,rt();let a=[],o=[];t?.querySelectorAll&&(a=Array.from(t.querySelectorAll("img[src]")),o=Array.from(t.querySelectorAll("*")));let c=[];for(let i of a){let l=i.src;v.has(l)||c.push(U(l,{useProxy:e.useProxy}).then(s=>v.set(l,s)).catch(()=>{}))}for(let i of o){let l=L(i).backgroundImage;if(l&&l!=="none"){let s=W(l);for(let f of s)f.startsWith("url(")&&c.push(M(f,e).catch(()=>{}))}}n&&await K({preCached:!0}),await Promise.all(c)}export{Lt as preCache,x as snapdom};