@zumer/snapdom 1.9.7 → 1.9.9

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,3 +1,3 @@
1
- (()=>{var De=Object.defineProperty;var K=Object.getOwnPropertySymbols;var ue=Object.prototype.hasOwnProperty,me=Object.prototype.propertyIsEnumerable;var pe=(e,t,a)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,U=(e,t)=>{for(var a in t||(t={}))ue.call(t,a)&&pe(e,a,t[a]);if(K)for(var a of K(t))me.call(t,a)&&pe(e,a,t[a]);return e};var he=(e,t)=>{var a={};for(var c in e)ue.call(e,c)&&t.indexOf(c)<0&&(a[c]=e[c]);if(e!=null&&K)for(var c of K(e))t.indexOf(c)<0&&me.call(e,c)&&(a[c]=e[c]);return a};var h=(e,t,a)=>new Promise((c,s)=>{var n=o=>{try{l(a.next(o))}catch(r){s(r)}},i=o=>{try{l(a.throw(o))}catch(r){s(r)}},l=o=>o.done?c(o.value):Promise.resolve(o.value).then(n,i);l((a=a.apply(e,t)).next())});var f={image:new Map,background:new Map,resource:new Map,defaultStyle:new Map,baseStyle:new Map,computedStyle:new WeakMap,font:new Set,snapshot:new WeakMap,snapshotKey:new Map,preStyleMap:new Map,preStyle:new WeakMap,preNodeMap:new Map,reset:je};function je(){f.computedStyle=new WeakMap,f.snapshot=new WeakMap,f.snapshotKey.clear(),f.preStyleMap.clear(),f.preStyle=new WeakMap,f.preNodeMap.clear()}var We=["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 ge(){for(let e of We)ye(e)}function ye(e){if(f.defaultStyle.has(e))return f.defaultStyle.get(e);if(new Set(["script","style","meta","link","noscript","template"]).has(e)){let i={};return f.defaultStyle.set(e,i),i}let a=document.getElementById("snapdom-sandbox");a||(a=document.createElement("div"),a.id="snapdom-sandbox",a.style.position="absolute",a.style.left="-9999px",a.style.top="-9999px",a.style.width="0",a.style.height="0",a.style.overflow="hidden",document.body.appendChild(a));let c=document.createElement(e);c.style.all="initial",a.appendChild(c);let s=getComputedStyle(c),n={};for(let i of s)n[i]=s.getPropertyValue(i);return a.removeChild(c),f.defaultStyle.set(e,n),n}function O(e,t,a=!1){let c=[],s=ye(t);for(let[n,i]of Object.entries(e))if(!a)i&&c.push(`${n}:${i}`);else{let l=s[n];i&&i!==l&&c.push(`${n}:${i}`)}return c.sort().join(";")}function we(e){let t=new Set;return e.nodeType!==Node.ELEMENT_NODE&&e.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(e.tagName&&t.add(e.tagName.toLowerCase()),typeof e.querySelectorAll=="function"&&e.querySelectorAll("*").forEach(a=>t.add(a.tagName.toLowerCase())),Array.from(t))}function xe(e){let t=new Map;for(let c of e){let s=f.defaultStyle.get(c);if(!s)continue;let n=Object.entries(s).map(([i,l])=>`${i}:${l};`).sort().join("");t.has(n)||t.set(n,[]),t.get(n).push(c)}let a="";for(let[c,s]of t.entries())a+=`${s.join(",")} { ${c} }
2
- `;return a}function Se(){let e=new Set(f.preStyleMap.values()),t=new Map,a=1;for(let c of e)t.set(c,`c${a++}`);return t}function B(a){return h(this,arguments,function*(e,t={}){let c=_(e),s=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(c){let n=Y(c);if(f.background.has(n))return t.skipInline?void 0:`url(${f.background.get(n)})`;{let i=yield P(n,{useProxy:t.useProxy});return f.background.set(n,i),t.skipInline?void 0:`url("${i}")`}}return e})}function D(e,{fast:t=!1}={}){if(t)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function N(e,t=null){if(!(e instanceof Element))return window.getComputedStyle(e,t);let a=f.computedStyle.get(e);if(a||(a=new Map,f.computedStyle.set(e,a)),!a.has(t)){let c=window.getComputedStyle(e,t);a.set(t,c)}return a.get(t)}function be(e){let t=e.replace(/^['"]|['"]$/g,"");if(t.startsWith("\\"))try{return String.fromCharCode(parseInt(t.replace("\\",""),16))}catch(a){return t}return t}function _(e){let t=e.match(/url\((['"]?)(.*?)(\1)\)/);if(!t)return null;let a=t[2].trim();return a.startsWith("#")?null:a}function P(e,{timeout:t=3e3,useProxy:a=""}={}){function c(o){try{return new URL(o,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch(r){return"anonymous"}}function s(o){return h(this,null,function*(){let r=d=>fetch(d,{mode:"cors",credentials:c(d)==="use-credentials"?"include":"omit"}).then(p=>p.blob()).then(p=>new Promise((m,u)=>{let y=new FileReader;y.onloadend=()=>{let w=y.result;if(typeof w!="string"||!w.startsWith("data:image/")){u(new Error("Invalid image data URL"));return}m(w)},y.onerror=()=>u(new Error("FileReader error")),y.readAsDataURL(p)}));try{return yield r(o)}catch(d){if(a&&typeof a=="string"){let p=a.replace(/\/$/,"")+Y(o);try{return yield r(p)}catch(m){throw new Error("[SnapDOM - fetchImage] CORS restrictions prevented image capture (even via proxy)")}}else throw new Error("[SnapDOM - fetchImage] Fetch fallback failed and no proxy provided")}})}let n=c(e);return f.image.has(e)?Promise.resolve(f.image.get(e)):e.startsWith("data:image/")?(f.image.set(e,e),Promise.resolve(e)):/\.svg(\?.*)?$/i.test(e)?h(null,null,function*(){try{let r=yield(yield fetch(e,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),d=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r)}`;return f.image.set(e,d),d}catch(o){return s(e)}}):new Promise((o,r)=>{let d=setTimeout(()=>{r(new Error("[SnapDOM - fetchImage] Image load timed out"))},t),p=new Image;p.crossOrigin=n,p.onload=()=>h(null,null,function*(){clearTimeout(d);try{yield p.decode();let m=document.createElement("canvas");m.width=p.width,m.height=p.height,m.getContext("2d").drawImage(p,0,0,m.width,m.height);let y=m.toDataURL("image/png");f.image.set(e,y),o(y)}catch(m){try{let u=yield s(e);f.image.set(e,u),o(u)}catch(u){r(u)}}}),p.onerror=()=>h(null,null,function*(){clearTimeout(d),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let m=yield s(e);f.image.set(e,m),o(m)}catch(m){r(m)}}),p.src=e})}function oe(e){let t={};for(let a of e)t[a]=e.getPropertyValue(a);return t}function Ce(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Ee(e){if(!e||e==="none")return"";let t=e.replace(/translate[XY]?\([^)]*\)/g,"");return t=t.replace(/matrix\(([^)]+)\)/g,(a,c)=>{let s=c.split(",").map(n=>n.trim());return s.length!==6?`matrix(${c})`:(s[4]="0",s[5]="0",`matrix(${s.join(", ")})`)}),t=t.replace(/matrix3d\(([^)]+)\)/g,(a,c)=>{let s=c.split(",").map(n=>n.trim());return s.length!==16?`matrix3d(${c})`:(s[12]="0",s[13]="0",`matrix3d(${s.join(", ")})`)}),t.trim().replace(/\s{2,}/g," ")}function Y(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch(t){return e}}function j(e){let t=[],a=0,c=0;for(let s=0;s<e.length;s++){let n=e[s];n==="("&&a++,n===")"&&a--,n===","&&a===0&&(t.push(e.slice(c,s).trim()),c=s+1)}return t.push(e.slice(c).trim()),t}function Ve(e){let t={};for(let a=0;a<e.length;a++){let c=e[a],s=e.getPropertyValue(c);(c==="background-image"||c==="content")&&s.includes("url(")&&!s.includes("data:")&&(s="none"),t[c]=s}return t}function X(e,t,a){var o;if(e.tagName==="STYLE")return;f.preStyle.has(e)||f.preStyle.set(e,N(e));let c=f.preStyle.get(e);if(!f.snapshot.has(e)){let r=Ve(c);f.snapshot.set(e,r)}let s=f.snapshot.get(e),n=Object.entries(s).sort(([r],[d])=>r.localeCompare(d)).map(([r,d])=>`${r}:${d}`).join(";");if(f.snapshotKey.has(n)){f.preStyleMap.set(t,f.snapshotKey.get(n));return}let i=((o=e.tagName)==null?void 0:o.toLowerCase())||"div",l=O(s,i,a);f.snapshotKey.set(n,l),f.preStyleMap.set(t,l)}function q(e,t,a={},c){var l,o;if(!e)throw new Error("Invalid node");let s=new Set,n=null;if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let r=document.createElement("div"),d=e.getBoundingClientRect();return r.style.cssText=`display:inline-block;width:${d.width}px;height:${d.height}px;visibility:hidden;`,r}if(a.exclude&&Array.isArray(a.exclude))for(let r of a.exclude)try{if((l=e.matches)!=null&&l.call(e,r)){let d=document.createElement("div"),p=e.getBoundingClientRect();return d.style.cssText=`display:inline-block;width:${p.width}px;height:${p.height}px;visibility:hidden;`,d}}catch(d){console.warn(`Invalid selector in exclude option: ${r}`,d)}if(typeof a.filter=="function")try{if(!a.filter(e,c||e)){let r=document.createElement("div"),d=e.getBoundingClientRect();return r.style.cssText=`display:inline-block;width:${d.width}px;height:${d.height}px;visibility:hidden;`,r}}catch(r){console.warn("Error in filter function:",r)}if(e.tagName==="IFRAME"){let r=document.createElement("div");return r.style.cssText=`width:${e.offsetWidth}px;height:${e.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;`,r}if(e.getAttribute("data-capture")==="placeholder"){let r=e.cloneNode(!1);f.preNodeMap.set(r,e),X(e,r,t);let d=document.createElement("div");return d.textContent=e.getAttribute("data-placeholder-text")||"",d.style.cssText="color:#666;font-size:12px;text-align:center;line-height:1.4;padding:0.5em;box-sizing:border-box;",r.appendChild(d),r}if(e.tagName==="CANVAS"){let r=e.toDataURL(),d=document.createElement("img");return d.src=r,d.width=e.width,d.height=e.height,f.preNodeMap.set(d,e),X(e,d,t),d}let i;try{i=e.cloneNode(!1),f.preNodeMap.set(i,e)}catch(r){throw console.error("[Snapdom] Failed to clone node:",e,r),r}if(e instanceof HTMLTextAreaElement){i.textContent=e.value,i.value=e.value;let r=e.getBoundingClientRect();return i.style.width=`${r.width}px`,i.style.height=`${r.height}px`,i}if(e instanceof HTMLInputElement&&(i.value=e.value,i.setAttribute("value",e.value),e.checked!==void 0&&(i.checked=e.checked,e.checked&&i.setAttribute("checked",""),e.indeterminate&&(i.indeterminate=e.indeterminate))),e instanceof HTMLSelectElement&&(n=e.value),X(e,i,t),e.shadowRoot)if(Array.from(e.shadowRoot.querySelectorAll("slot")).length>0){for(let d of e.shadowRoot.childNodes)if(d.nodeType===Node.ELEMENT_NODE&&d.tagName==="STYLE"){let p=d.textContent||"";p.trim()&&t&&(f.preStyle||(f.preStyle=new WeakMap),f.preStyle.set(d,p))}}else{let d=document.createDocumentFragment();for(let p of e.shadowRoot.childNodes){if(p.nodeType===Node.ELEMENT_NODE&&p.tagName==="STYLE"){let u=p.textContent||"";u.trim()&&t&&(f.preStyle||(f.preStyle=new WeakMap),f.preStyle.set(p,u));continue}let m=q(p,t,a,c||e);m&&d.appendChild(m)}i.appendChild(d)}if(e.tagName==="SLOT"){let r=((o=e.assignedNodes)==null?void 0:o.call(e,{flatten:!0}))||[],d=r.length>0?r:Array.from(e.childNodes),p=document.createDocumentFragment();for(let m of d){let u=q(m,t,a,c||e);u&&p.appendChild(u)}return p}for(let r of e.childNodes){if(s.has(r))continue;let d=q(r,t,a,c||e);d&&i.appendChild(d)}if(n!==null&&i instanceof HTMLSelectElement){i.value=n;for(let r of i.options)r.value===n?r.setAttribute("selected",""):r.removeAttribute("selected")}return i}var Oe=[/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],ae=[];function ve(e){let t=Array.isArray(e)?e:[e];for(let a of t)a instanceof RegExp?ae.push(a):typeof a=="string"?ae.push(new RegExp(a,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",a)}function $(e){let t=typeof e=="string"?e:"",a=[...Oe,...ae];for(let c of a)if(c instanceof RegExp&&c.test(t))return!0;return!!(/icon/i.test(t)||/glyph/i.test(t)||/symbols/i.test(t)||/feather/i.test(t)||/fontawesome/i.test(t))}function $e(e,t,a,c=32,s="#000"){return h(this,null,function*(){t=t.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,l=document.createElement("canvas").getContext("2d");l.font=a?`${a} ${c}px "${t}"`:`${c}px "${t}"`;let o=l.measureText(e),r=o.actualBoundingBoxAscent||c*.8,d=o.actualBoundingBoxDescent||c*.2,p=r+d,m=o.width,u=document.createElement("canvas");u.width=Math.ceil(m*n),u.height=Math.ceil(p*n);let y=u.getContext("2d");return y.scale(n,n),y.font=l.font,y.textAlign="left",y.textBaseline="alphabetic",y.fillStyle=s,y.fillText(e,0,r),u.toDataURL()})}function ke(e){return Array.from(document.styleSheets).some(t=>t.href===e)}function _e(e){return new Promise(t=>{if(ke(e))return t(null);let a=document.createElement("link");a.rel="stylesheet",a.href=e,a.setAttribute("data-snapdom","injected-import"),a.onload=()=>t(a),a.onerror=()=>t(null),document.head.appendChild(a)})}function G(){return h(this,arguments,function*({preCached:e=!1}={}){if(f.resource.has("fonts-embed-css")){if(e){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=f.resource.get("fonts-embed-css"),document.head.appendChild(n)}return f.resource.get("fonts-embed-css")}let t=/@import\s+url\(["']?([^"')]+)["']?\)/g,a=[];for(let n of document.querySelectorAll("style")){let i=n.textContent||"",l=Array.from(i.matchAll(t));for(let o of l){let r=o[1];$(r)||ke(r)||a.push(r)}}yield Promise.all(a.map(_e));let c=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),s="";for(let n of c)try{let l=yield(yield fetch(n.href)).text();if($(n.href)||$(l))continue;let o=/url\((["']?)([^"')]+)\1\)/g,r=yield Promise.all(Array.from(l.matchAll(o)).map(p=>h(null,null,function*(){let m=_(p[0]);if(!m)return null;let u=m;if(!u.startsWith("http")&&!u.startsWith("data:")&&(u=new URL(u,n.href).href),$(u))return null;if(f.resource.has(u))return f.font.add(u),{original:p[0],inlined:`url(${f.resource.get(u)})`};if(f.font.has(u))return null;try{let w=yield(yield fetch(u)).blob(),x=yield new Promise(g=>{let b=new FileReader;b.onload=()=>g(b.result),b.readAsDataURL(w)});return f.resource.set(u,x),f.font.add(u),{original:p[0],inlined:`url(${x})`}}catch(y){return console.warn("[snapdom] Failed to fetch font resource:",u),null}}))),d=l;for(let p of r)p&&(d=d.replace(p.original,p.inlined));s+=d+`
3
- `}catch(i){console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||c.every(i=>i.href!==n.href)){for(let i of n.cssRules)if(i.type===CSSRule.FONT_FACE_RULE){let l=i.style.getPropertyValue("src"),o=i.style.getPropertyValue("font-family");if(!l||$(o))continue;let r=/url\((["']?)([^"')]+)\1\)/g,d=/local\((["']?)[^)]+?\1\)/g,p=!!l.match(r),m=!!l.match(d);if(!p&&m){s+=`@font-face{font-family:${o};src:${l};font-style:${i.style.getPropertyValue("font-style")||"normal"};font-weight:${i.style.getPropertyValue("font-weight")||"normal"};}`;continue}let u=l,y=Array.from(l.matchAll(r));for(let w of y){let x=w[2].trim();if(!x)continue;let g=x;if(!g.startsWith("http")&&!g.startsWith("data:")&&(g=new URL(g,n.href||location.href).href),!$(g)){if(f.resource.has(g)){f.font.add(g),u=u.replace(w[0],`url(${f.resource.get(g)})`);continue}if(!f.font.has(g))try{let I=yield(yield fetch(g)).blob(),k=yield new Promise(T=>{let C=new FileReader;C.onload=()=>T(C.result),C.readAsDataURL(I)});f.resource.set(g,k),f.font.add(g),u=u.replace(w[0],`url(${k})`)}catch(b){console.warn("[snapdom] Failed to fetch font URL:",g)}}}s+=`@font-face{font-family:${o};src:${u};font-style:${i.style.getPropertyValue("font-style")||"normal"};font-weight:${i.style.getPropertyValue("font-weight")||"normal"};}`}}}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){if($(n.family))continue;let i=n._snapdomSrc;if(!i.startsWith("data:")){if(f.resource.has(n._snapdomSrc))i=f.resource.get(n._snapdomSrc),f.font.add(n._snapdomSrc);else if(!f.font.has(n._snapdomSrc))try{let o=yield(yield fetch(n._snapdomSrc)).blob();i=yield new Promise(r=>{let d=new FileReader;d.onload=()=>r(d.result),d.readAsDataURL(o)}),f.resource.set(n._snapdomSrc,i),f.font.add(n._snapdomSrc)}catch(l){console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}s+=`@font-face{font-family:'${n.family}';src:url(${i});font-style:${n.style||"normal"};font-weight:${n.weight||"normal"};}`}if(s&&(f.resource.set("fonts-embed-css",s),e)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=s,document.head.appendChild(n)}return s})}function re(e,t,a,c=!1,s){return h(this,null,function*(){if(!(e instanceof Element)||!(t instanceof Element))return;for(let l of["::before","::after","::first-letter"])try{let o=N(e,l);if(!o||typeof o[Symbol.iterator]!="function")continue;if(l==="::first-letter"){let E=getComputedStyle(e);if(!(o.color!==E.color||o.fontSize!==E.fontSize||o.fontWeight!==E.fontWeight))continue;let M=Array.from(t.childNodes).find(ne=>ne.nodeType===Node.TEXT_NODE&&ne.textContent&&ne.textContent.trim().length>0);if(!M)continue;let fe=M.textContent,te=fe.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),F=te==null?void 0:te[0],Fe=fe.slice((F==null?void 0:F.length)||0);if(!F||/[\uD800-\uDFFF]/.test(F))continue;let H=document.createElement("span");H.textContent=F,H.dataset.snapdomPseudo="::first-letter";let Ue=oe(o),Be=O(Ue,"span",a);f.preStyleMap.set(H,Be);let de=document.createTextNode(Fe);t.replaceChild(de,M),t.insertBefore(H,de);continue}let r=o.getPropertyValue("content"),d=o.getPropertyValue("background-image"),p=o.getPropertyValue("background-color"),m=o.getPropertyValue("font-family"),u=parseInt(o.getPropertyValue("font-size"))||32,y=parseInt(o.getPropertyValue("font-weight"))||!1,w=o.getPropertyValue("color")||"#000",x=o.getPropertyValue("display"),g=parseFloat(o.getPropertyValue("width")),b=parseFloat(o.getPropertyValue("height")),I=o.getPropertyValue("border-style"),k=o.getPropertyValue("transform"),T=$(m),C;/counter\s*\(|counters\s*\(/.test(r)?C="- ":C=be(r);let W=r!=="none"&&C!=="",z=d&&d!=="none",V=p&&p!=="transparent"&&p!=="rgba(0, 0, 0, 0)",J=x!=="inline"&&(g>0||b>0),Q=I&&I!=="none",A=k&&k!=="none";if(!(W||z||V||J||Q||A))continue;let v=document.createElement("span");v.dataset.snapdomPseudo=l;let Z=oe(o),ee=O(Z,"span",a);if(f.preStyleMap.set(v,ee),T&&C.length===1){let E=document.createElement("img");E.src=yield $e(C,m,y,u,w),E.style=`width:${u}px;height:auto;object-fit:contain;`,v.appendChild(E)}else if(C.startsWith("url(")){let E=_(C);if(E&&E.trim()!=="")try{let R=document.createElement("img"),M=yield P(Y(E,{useProxy:s}));R.src=M,R.style=`width:${u}px;height:auto;object-fit:contain;`,v.appendChild(R)}catch(R){console.error(`[snapdom] Error in pseudo ${l} for`,e,R)}}else!T&&W&&(v.textContent=C);if(z)try{let E=j(d),R=yield Promise.all(E.map(M=>B(M)));v.style.backgroundImage=R.join(", ")}catch(E){console.warn(`[snapdom] Failed to inline background-image for ${l}`,E)}if(V&&(v.style.backgroundColor=p),!(v.childNodes.length>0||v.textContent&&v.textContent.trim()!==""||z||V||J||Q||A))continue;l==="::before"?t.insertBefore(v,t.firstChild):t.appendChild(v)}catch(o){console.warn(`[snapdom] Failed to capture ${l} for`,e,o)}let n=Array.from(e.children),i=Array.from(t.children).filter(l=>!l.dataset.snapdomPseudo);for(let l=0;l<Math.min(n.length,i.length);l++)yield re(n[l],i[l],a,c,s)})}function Ie(e){if(!e)return;let t=document.querySelectorAll("svg > defs");t.length&&e.querySelectorAll("svg").forEach(a=>{let c=a.querySelectorAll("use");if(!c.length)return;let s=new Set;if(c.forEach(i=>{let l=i.getAttribute("xlink:href")||i.getAttribute("href");l&&l.startsWith("#")&&s.add(l.slice(1))}),!s.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let i of s)for(let l of t){let o=l.querySelector(`#${CSS.escape(i)}`);if(o){n.appendChild(o.cloneNode(!0));break}}n.childNodes.length&&a.insertBefore(n,a.firstChild)})}function Re(s){return h(this,arguments,function*(e,t=!1,a=!1,c={}){var l;let n,i="";try{n=q(e,t,c,e)}catch(o){throw console.warn("deepClone failed:",o),o}try{yield re(e,n,t,a,c.useProxy)}catch(o){console.warn("inlinePseudoElements failed:",o)}try{Ie(n)}catch(o){console.warn("inlineExternalDef failed:",o)}if(t){let o=Se();i=Array.from(o.entries()).map(([r,d])=>`.${d}{${r}}`).join("");for(let[r,d]of f.preStyleMap.entries()){if(r.tagName==="STYLE")continue;let p=o.get(d);p&&r.classList.add(p);let m=(l=r.style)==null?void 0:l.backgroundImage;r.removeAttribute("style"),m&&m!=="none"&&(r.style.backgroundImage=m)}}else for(let[o,r]of f.preStyleMap.entries())o.tagName!=="STYLE"&&o.setAttribute("style",r.replace(/;/g,"; "));for(let[o,r]of f.preNodeMap.entries()){let d=r.scrollLeft,p=r.scrollTop;if((d||p)&&o instanceof HTMLElement){o.style.overflow="hidden",o.style.scrollbarWidth="none",o.style.msOverflowStyle="none";let u=document.createElement("div");for(u.style.transform=`translate(${-d}px, ${-p}px)`,u.style.willChange="transform",u.style.display="inline-block",u.style.width="100%";o.firstChild;)u.appendChild(o.firstChild);o.appendChild(u)}}if(e===f.preNodeMap.get(n)){let o=f.preStyle.get(e)||window.getComputedStyle(e);f.preStyle.set(e,o);let r=Ee(o.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=r||""}for(let[o,r]of f.preNodeMap.entries())r.tagName==="PRE"&&(o.style.marginTop="0",o.style.marginBlockStart="0");return{clone:n,classCSS:i}})}function Ne(a){return h(this,arguments,function*(e,t={}){let c=Array.from(e.querySelectorAll("img")),s=n=>h(null,null,function*(){let i=n.src;try{let l=yield P(i,{useProxy:t.useProxy});n.src=l,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch(l){let o=document.createElement("div");o.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;`,o.innerText="img",n.replaceWith(o)}});for(let n=0;n<c.length;n+=4){let i=c.slice(n,n+4).map(s);yield Promise.allSettled(i)}})}function Te(c,s){return h(this,arguments,function*(e,t,a={}){let n=[[e,t]],i=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source"];for(;n.length;){let[l,o]=n.shift(),r=f.preStyle.get(l)||N(l);f.preStyle.has(l)||f.preStyle.set(l,r);for(let u of i){let y=r.getPropertyValue(u);if(!y||y==="none")continue;let w=j(y),x=yield Promise.all(w.map(g=>B(g,a)));x.some(g=>g&&g!=="none"&&!/^url\(undefined/.test(g))&&o.style.setProperty(u,x.join(", "))}let d=r.getPropertyValue("background-color");d&&d!=="transparent"&&d!=="rgba(0, 0, 0, 0)"&&(o.style.backgroundColor=d);let p=Array.from(l.children),m=Array.from(o.children);for(let u=0;u<Math.min(p.length,m.length);u++)n.push([p[u],m[u]])}})}function Ae(a){return h(this,arguments,function*(e,t={}){if(!e)throw new Error("Element cannot be null or undefined");f.reset();let{compress:c=!0,embedFonts:s=!1,fast:n=!0,scale:i=1,useProxy:l=""}=t,o,r,d="",p="",m,u;if({clone:o,classCSS:r}=yield Re(e,c,s,t),yield new Promise(w=>{D(()=>h(null,null,function*(){yield Ne(o,t),w()}),{fast:n})}),yield new Promise(w=>{D(()=>h(null,null,function*(){yield Te(e,o,t),w()}),{fast:n})}),s&&(yield new Promise(w=>{D(()=>h(null,null,function*(){d=yield G(),w()}),{fast:n})})),c){let w=we(o).sort(),x=w.join(",");f.baseStyle.has(x)?p=f.baseStyle.get(x):yield new Promise(g=>{D(()=>{p=xe(w),f.baseStyle.set(x,p),g()},{fast:n})})}yield new Promise(w=>{D(()=>{let x=e.getBoundingClientRect(),g=x.width,b=x.height,I=Number.isFinite(t.width),k=Number.isFinite(t.height),T=typeof i=="number"&&i!==1;if(!T){let A=x.width/x.height;I&&k?(g=t.width,b=t.height):I?(g=t.width,b=g/A):k&&(b=t.height,g=b*A)}if(g=Math.ceil(g),b=Math.ceil(b),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="top left",!T&&(I||k)){let A=x.width,ce=x.height,v=g/A,Z=b/ce,ee=o.style.transform||"",le=`scale(${v}, ${Z})`;o.style.transform=`${le} ${ee}`.trim()}let C="http://www.w3.org/2000/svg",L=document.createElementNS(C,"foreignObject");L.setAttribute("width","100%"),L.setAttribute("height","100%");let W=document.createElement("style");W.textContent=p+d+"svg{overflow:visible;}"+r,L.appendChild(W),L.appendChild(o);let V=new XMLSerializer().serializeToString(L);u=`<svg xmlns="${C}" width="${g}" height="${b}" viewBox="0 0 ${g} ${b}">`+V+"</svg>",m=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`,w()},{fast:n})});let y=document.getElementById("snapdom-sandbox");return y&&y.style.position==="absolute"&&y.remove(),m})}function qe(c,s){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1}){let n=new Image;return n.src=e,yield n.decode(),n.width=n.width*a,n.height=n.height*a,n})}function Me(c){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1}={}){let s=new Image;s.src=e,s.crossOrigin="anonymous",s.loading="eager",s.decoding="sync";let n=Ce(),i=!1;if(n&&(document.body.appendChild(s),i=!0),yield s.decode(),n&&(yield new Promise(p=>setTimeout(p,100))),s.width===0||s.height===0)throw i&&s.remove(),new Error("Image failed to load or has no dimensions");let l=s.width*a,o=s.height*a,r=document.createElement("canvas");r.width=Math.ceil(l*t),r.height=Math.ceil(o*t),r.style.width=`${l}px`,r.style.height=`${o}px`;let d=r.getContext("2d");return d.scale(t,t),d.drawImage(s,0,0,l,o),i&&s.remove(),r})}function Pe(n){return h(this,arguments,function*(e,{type:t="svg",scale:a=1,backgroundColor:c="#fff",quality:s}={}){let i={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[t]||"image/png";if(t==="svg"){let o=decodeURIComponent(e.split(",")[1]);return new Blob([o],{type:"image/svg+xml"})}let l=yield ie(e,{dpr:1,scale:a},c);return new Promise(o=>{l.toBlob(r=>o(r),`${i}`,s)})})}function ie(s,n,i){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1},c){let l=yield Me(e,{dpr:t,scale:a});if(!c)return l;let o=document.createElement("canvas");o.width=l.width,o.height=l.height;let r=o.getContext("2d");return r.fillStyle=c,r.fillRect(0,0,o.width,o.height),r.drawImage(l,0,0),o})}function se(i,l){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1,backgroundColor:c,quality:s},n="png"){let o=["jpg","jpeg","webp"].includes(n)?"#fff":void 0,r=c!=null?c:o,d=yield ie(e,{dpr:t,scale:a},r),p=new Image;return p.src=d.toDataURL(`image/${n}`,s),yield p.decode(),p.style.width=`${d.width/t}px`,p.style.height=`${d.height/t}px`,p})}function ze(i){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1,backgroundColor:c,format:s="png",filename:n="snapDOM"}={}){if(s==="svg"){let u=yield Pe(e),y=URL.createObjectURL(u),w=document.createElement("a");w.href=y,w.download=`${n}.svg`,w.click(),URL.revokeObjectURL(y);return}let l=["jpg","jpeg","webp"].includes(s)?"#fff":void 0,o=c!=null?c:l,r=yield ie(e,{dpr:t,scale:a},o),d={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[s]||"image/png",p=r.toDataURL(d),m=document.createElement("a");m.href=p,m.download=`${n}.${s}`,m.click()})}function S(a){return h(this,arguments,function*(e,t={}){if(t=U({scale:1},t),!e)throw new Error("Element cannot be null or undefined");return t.iconFonts&&ve(t.iconFonts),yield S.capture(e,t)})}S.capture=(a,...c)=>h(null,[a,...c],function*(e,t={}){let s=yield Ae(e,t),n=window.devicePixelRatio||1,i=t.scale||1;return{url:s,options:t,toRaw:()=>s,toImg:()=>qe(s,{dpr:n,scale:i}),toCanvas:()=>Me(s,{dpr:n,scale:i}),toBlob:l=>Pe(s,U({dpr:n,scale:i},l)),toPng:l=>se(s,U({dpr:n,scale:i},l),"png"),toJpg:l=>se(s,U({dpr:n,scale:i},l),"jpeg"),toWebp:l=>se(s,U({dpr:n,scale:i},l),"webp"),download:({format:l="png",filename:o="capture",backgroundColor:r}={})=>ze(s,{dpr:n,scale:i,backgroundColor:r,format:l,filename:o})}});S.toRaw=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toRaw()});S.toImg=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toImg()});S.toCanvas=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toCanvas()});S.toBlob=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toBlob(t)});S.toPng=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toPng(t)});S.toJpg=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toJpg(t)});S.toWebp=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toWebp(t)});S.download=(a,...c)=>h(null,[a,...c],function*(e,t={}){let r=t,{format:s="png",filename:n="capture",backgroundColor:i}=r,l=he(r,["format","filename","backgroundColor"]);return yield(yield S.capture(e,l)).download({format:s,filename:n,backgroundColor:i})});function Le(){return h(this,arguments,function*(e=document,t={}){let{embedFonts:a=!0,reset:c=!1}=t;if(c){f.reset();return}yield document.fonts.ready,ge();let s=[],n=[];e!=null&&e.querySelectorAll&&(s=Array.from(e.querySelectorAll("img[src]")),n=Array.from(e.querySelectorAll("*")));let i=[];for(let l of s){let o=l.src;f.image.has(o)||i.push(P(o,{useProxy:t.useProxy}).then(r=>f.image.set(o,r)).catch(()=>{}))}for(let l of n){let o=N(l).backgroundImage;if(o&&o!=="none"){let r=j(o);for(let d of r)d.startsWith("url(")&&i.push(B(d,t).catch(()=>{}))}}a&&(yield G({preCached:!0})),yield Promise.all(i)})}typeof window!="undefined"&&(window.snapdom=S,window.preCache=Le);})();
1
+ (()=>{var Jt=Object.defineProperty,Qt=Object.defineProperties;var Zt=Object.getOwnPropertyDescriptors;var ot=Object.getOwnPropertySymbols;var At=Object.prototype.hasOwnProperty,$t=Object.prototype.propertyIsEnumerable;var Et=(t,e,r)=>e in t?Jt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,L=(t,e)=>{for(var r in e||(e={}))At.call(e,r)&&Et(t,r,e[r]);if(ot)for(var r of ot(e))$t.call(e,r)&&Et(t,r,e[r]);return t},kt=(t,e)=>Qt(t,Zt(e));var ft=(t,e)=>{var r={};for(var i in t)At.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(t!=null&&ot)for(var i of ot(t))e.indexOf(i)<0&&$t.call(t,i)&&(r[i]=t[i]);return r};var w=(t,e,r)=>new Promise((i,c)=>{var a=n=>{try{d(r.next(n))}catch(o){c(o)}},f=n=>{try{d(r.throw(n))}catch(o){c(o)}},d=n=>n.done?i(n.value):Promise.resolve(n.value).then(a,f);d((r=r.apply(t,e)).next())});var p={image:new Map,background:new Map,resource:new Map,defaultStyle:new Map,baseStyle:new Map,computedStyle:new WeakMap,font:new Set,snapshot:new WeakMap,snapshotKey:new Map,reset:te};function te(){p.computedStyle=new WeakMap}var ee=["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 ee)Rt(t)}function Rt(t){if(p.defaultStyle.has(t))return p.defaultStyle.get(t);if(new Set(["script","style","meta","link","noscript","template","defs","symbol","title","metadata","desc"]).has(t)){let f={};return p.defaultStyle.set(t,f),f}let r=document.getElementById("snapdom-sandbox");r||(r=document.createElement("div"),r.id="snapdom-sandbox",r.style.position="absolute",r.style.left="-9999px",r.style.top="-9999px",r.style.width="0",r.style.height="0",r.style.overflow="hidden",document.body.appendChild(r));let i=document.createElement(t);i.style.all="initial",r.appendChild(i);let c=getComputedStyle(i),a={};for(let f of c)a[f]=c.getPropertyValue(f);return r.removeChild(i),p.defaultStyle.set(t,a),a}var ne=new Set(["-webkit-locale"]);function G(t,e,r=!1){let i=[],c=Rt(e);for(let[a,f]of Object.entries(t))if(!ne.has(a))if(!r)f&&i.push(`${a}:${f}`);else{let d=c[a];f&&f!==d&&i.push(`${a}:${f}`)}return i.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(r=>e.add(r.tagName.toLowerCase())),Array.from(e))}function Tt(t){let e=new Map;for(let i of t){let c=p.defaultStyle.get(i);if(!c)continue;let a=Object.entries(c).map(([f,d])=>`${f}:${d};`).sort().join("");e.has(a)||e.set(a,[]),e.get(a).push(i)}let r="";for(let[i,c]of e.entries())r+=`${c.join(",")} { ${i} }
2
+ `;return r}function Ft(t){let e=new Set(t.values()),r=new Map,i=1;for(let c of e)c.trim()&&r.set(c,`c${i++}`);return r}function V(r){return w(this,arguments,function*(t,e={}){let i=J(t),c=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t);if(i){let a=Q(i);if(p.background.has(a))return e.skipInline?void 0:`url(${p.background.get(a)})`;{let f=yield _(a,{useProxy:e.useProxy});return p.background.set(a,f),e.skipInline?void 0:`url("${f}")`}}return t})}function H(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function D(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let r=p.computedStyle.get(t);if(r||(r=new Map,p.computedStyle.set(t,r)),!r.has(e)){let i=window.getComputedStyle(t,e);r.set(e,i)}return r.get(e)}function Lt(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch(r){return e}return e}function J(t){let e=t.match(/url\((['"]?)(.*?)(\1)\)/);if(!e)return null;let r=e[2].trim();return r.startsWith("#")?null:r}function z(r){return w(this,arguments,function*(t,{useProxy:e=""}={}){function i(c){return w(this,null,function*(){let a=yield fetch(c);if(!a.ok)throw new Error(`[snapdom] Failed to fetch resource: ${c}`);return a})}try{return yield i(t)}catch(c){if(e&&typeof e=="string"){let a=e.replace(/\/$/,"")+Q(t);return i(a)}throw c}})}var q=new Map,dt=new Map;function _(t,{timeout:e=3e3,useProxy:r="",errorTTL:i=8e3}={}){function c(s){try{return new URL(s,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch(h){return"anonymous"}}let a=s=>({ok:!0,data:s}),f=s=>({ok:!1,error:s instanceof Error?s:new Error(String(s))});function d(s){try{return fetch(s,{mode:"cors",credentials:c(s)==="use-credentials"?"include":"omit"}).then(h=>h.ok?h.blob().then(b=>new Promise(g=>{let y=new FileReader;y.onloadend=()=>{let C=y.result;typeof C!="string"||!C.startsWith("data:image/")?g(f(new Error("Invalid image data URL"))):g(a(C))},y.onerror=()=>g(f(new Error("FileReader error"))),y.readAsDataURL(b)})):f(new Error("HTTP "+h.status))).catch(h=>f(h))}catch(h){return Promise.resolve(f(h))}}function n(s){return d(s).then(h=>{if(h.ok)return h;if(r&&typeof r=="string"){let b=r.replace(/\/$/,"")+Q(s);return d(b).then(g=>g.ok?g:f(new Error("[SnapDOM - fetchImage] Fetch failed and no proxy provided")))}return f(new Error("[SnapDOM - fetchImage] Fetch failed and no proxy provided"))})}let o=Date.now(),m=dt.get(t);if(m&&m>o){let s=Promise.reject(new Error("[SnapDOM - fetchImage] Recently failed (cooldown)."));return s.catch(()=>{}),s}if(q.has(t))return q.get(t);let u=c(t);if(p.image.has(t))return Promise.resolve(p.image.get(t));if(t.startsWith("data:image/"))return p.image.set(t,t),Promise.resolve(t);if(/\.svg(\?.*)?$/i.test(t)){let s=w(null,null,function*(){let h=yield w(null,null,function*(){try{let g=yield fetch(t,{mode:"cors",credentials:u==="use-credentials"?"include":"omit"});if(!g.ok)return f(new Error("HTTP "+g.status));let y=yield g.text();return a(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(y)}`)}catch(g){return f(g)}});if(h.ok)return p.image.set(t,h.data),h.data;let b=yield n(t);return b.ok?(p.image.set(t,b.data),b.data):(dt.set(t,o+i),Promise.reject(b.error))});return q.set(t,s),s.finally(()=>q.delete(t)),s.catch(()=>{}),s}let l=new Promise((s,h)=>{let b=!1,g=new Image,y=S=>k=>{b||(b=!0,clearTimeout(v),g.onload=g.onerror=null,S(k))},C=S=>{p.image.set(t,S),s(S)},x=S=>{dt.set(t,Date.now()+i),h(S)},v=setTimeout(y(()=>{n(t).then(S=>{S.ok?C(S.data):x(new Error("Image load timed out"))})}),e);g.crossOrigin=u,g.onload=y(()=>{Promise.resolve(g.decode()).then(()=>{try{let S=document.createElement("canvas");S.width=g.naturalWidth||g.width,S.height=g.naturalHeight||g.height,S.getContext("2d").drawImage(g,0,0,S.width,S.height),C(S.toDataURL("image/png"))}catch(S){n(t).then(k=>{k.ok?C(k.data):x(k.error)})}}).catch(()=>{n(t).then(S=>{S.ok?C(S.data):x(S.error)})})}),g.onerror=y(()=>{n(t).then(S=>{S.ok?C(S.data):x(S.error)})}),g.src=t});return q.set(t,l),l.finally(()=>q.delete(t)),l.catch(()=>{}),l}function ut(t){let e={};for(let r of t)e[r]=t.getPropertyValue(r);return e}function Pt(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Bt(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(r,i)=>{let c=i.split(",").map(a=>a.trim());return c.length!==6?`matrix(${i})`:(c[4]="0",c[5]="0",`matrix(${c.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(r,i)=>{let c=i.split(",").map(a=>a.trim());return c.length!==16?`matrix3d(${i})`:(c[12]="0",c[13]="0",`matrix3d(${c.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function Q(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch(e){return t}}function Y(t){let e=[],r=0,i=0;for(let c=0;c<t.length;c++){let a=t[c];a==="("&&r++,a===")"&&r--,a===","&&r===0&&(e.push(t.slice(i,c).trim()),i=c+1)}return e.push(t.slice(i).trim()),e}var mt=new WeakMap,ht=new Map;function oe(t){let e={},r=t.getPropertyValue("visibility");for(let i=0;i<t.length;i++){let c=t[i],a=t.getPropertyValue(c);(c==="background-image"||c==="content")&&a.includes("url(")&&!a.includes("data:")&&(a="none"),e[c]=a}return r==="hidden"&&(e.opacity="0"),e}function rt(t,e,r,i,c){var m;if(t.tagName==="STYLE")return;i.has(t)||i.set(t,D(t));let a=i.get(t);if(!mt.has(t)){let u=oe(a);mt.set(t,u)}let f=mt.get(t),d=Object.entries(f).sort(([u],[l])=>u.localeCompare(l)).map(([u,l])=>`${u}:${l}`).join(";");if(ht.has(d)){r.set(e,ht.get(d));return}let n=((m=t.tagName)==null?void 0:m.toLowerCase())||"div",o=G(f,n,c);ht.set(d,o),r.set(e,o)}function re(t,e){try{let r=t.currentSrc||t.src||"";if(!r)return;e.setAttribute("src",r),e.removeAttribute("srcset"),e.removeAttribute("sizes"),e.loading="eager",e.decoding="sync"}catch(r){}}function Z(t,e,r,i,c,a={},f){var m,u;if(!t)throw new Error("Invalid node");let d=new Set,n=null;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(a.exclude&&Array.isArray(a.exclude))for(let l of a.exclude)try{if((m=t.matches)!=null&&m.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 a.filter=="function")try{if(!a.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.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),rt(t,l,e,r,c);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,i.set(s,t),rt(t,s,e,r,c),s}let o;try{o=t.cloneNode(!1),i.set(o,t),t.tagName==="IMG"&&re(t,o)}catch(l){throw console.error("[Snapdom] Failed to clone node:",t,l),l}if(t instanceof HTMLTextAreaElement){o.textContent=t.value,o.value=t.value;let l=t.getBoundingClientRect();return o.style.width=`${l.width}px`,o.style.height=`${l.height}px`,o}if(t instanceof HTMLInputElement&&(o.value=t.value,o.setAttribute("value",t.value),t.checked!==void 0&&(o.checked=t.checked,t.checked&&o.setAttribute("checked",""),t.indeterminate&&(o.indeterminate=t.indeterminate))),t instanceof HTMLSelectElement&&(n=t.value),rt(t,o,e,r,c),t.shadowRoot)if(Array.from(t.shadowRoot.querySelectorAll("slot")).length>0){for(let s of t.shadowRoot.childNodes)if(s.nodeType===Node.ELEMENT_NODE&&s.tagName==="STYLE"){let h=s.textContent||"";h.trim()&&c&&r.set(s,h)}}else{let s=document.createDocumentFragment();for(let h of t.shadowRoot.childNodes){if(h.nodeType===Node.ELEMENT_NODE&&h.tagName==="STYLE"){let g=h.textContent||"";g.trim()&&c&&r.set(h,g);continue}let b=Z(h,e,r,i,c,a,f||t);b&&s.appendChild(b)}o.appendChild(s)}if(t.tagName==="SLOT"){let l=((u=t.assignedNodes)==null?void 0:u.call(t,{flatten:!0}))||[],s=l.length>0?l:Array.from(t.childNodes),h=document.createDocumentFragment();for(let b of s){let g=Z(b,e,r,i,c,a,f||t);g&&h.appendChild(g)}return h}for(let l of t.childNodes){if(d.has(l))continue;let s=Z(l,e,r,i,c,a,f||t);s&&o.appendChild(s)}if(n!==null&&o instanceof HTMLSelectElement){o.value=n;for(let l of o.options)l.value===n?l.setAttribute("selected",""):l.removeAttribute("selected")}return o}var ae=[/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],gt=[];function Ut(t){let e=Array.isArray(t)?t:[t];for(let r of e)r instanceof RegExp?gt.push(r):typeof r=="string"?gt.push(new RegExp(r,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",r)}function U(t){let e=typeof t=="string"?t:"",r=[...ae,...gt];for(let i of r)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 Mt(t,e,r,i=32,c="#000"){return w(this,null,function*(){e=e.replace(/^['"]+|['"]+$/g,"");let a=window.devicePixelRatio||1;yield document.fonts.ready;let f=document.createElement("span");f.textContent=t,f.style.position="absolute",f.style.visibility="hidden",f.style.fontFamily=`"${e}"`,f.style.fontWeight=r||"normal",f.style.fontSize=`${i}px`,f.style.lineHeight="1",f.style.whiteSpace="nowrap",f.style.padding="0",f.style.margin="0",document.body.appendChild(f);let d=f.getBoundingClientRect(),n=Math.ceil(d.width),o=Math.ceil(d.height);document.body.removeChild(f);let m=document.createElement("canvas");m.width=n*a,m.height=o*a;let u=m.getContext("2d");return u.scale(a,a),u.font=r?`${r} ${i}px "${e}"`:`${i}px "${e}"`,u.textAlign="left",u.textBaseline="top",u.fillStyle=c,u.fillText(t,0,0),{dataUrl:m.toDataURL(),width:n,height:o}})}function Dt(t){return Array.from(document.styleSheets).some(e=>e.href===t)}function se(t){return new Promise(e=>{if(Dt(t))return e(null);let r=document.createElement("link");r.rel="stylesheet",r.href=t,r.setAttribute("data-snapdom","injected-import"),r.onload=()=>e(r),r.onerror=()=>e(null),document.head.appendChild(r)})}function at(){return w(this,arguments,function*({preCached:t=!1,localFonts:e=[],useProxy:r=""}={}){if(p.resource.has("fonts-embed-css")){if(t){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=p.resource.get("fonts-embed-css"),document.head.appendChild(n)}return p.resource.get("fonts-embed-css")}let i=new Set;try{for(let n of document.fonts)n.status==="loaded"&&i.add(`${n.family}__${n.weight||"normal"}__${n.style||"normal"}`)}catch(n){}let c=/@import\s+url\(["']?([^"')]+)["']?\)/g,a=[];for(let n of document.querySelectorAll("style")){let o=n.textContent||"",m=Array.from(o.matchAll(c));for(let u of m){let l=u[1];U(l)||Dt(l)||a.push(l)}}yield Promise.all(a.map(se));let f=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),d="";for(let n of f)try{let m=yield(yield z(n.href,{useProxy:r})).text();if(U(n.href)||U(m))continue;let u=/@font-face[^{}]*{[^}]*}/g,l=m;for(let s of m.match(u)||[]){let h=s.match(/font-family:\s*([^;]+);/i);if(!h)continue;let b=h[1].replace(/['"]/g,"").trim(),g=s.match(/font-weight:\s*([^;]+);/i),y=s.match(/font-style:\s*([^;]+);/i),C=g?g[1].trim():"normal",x=y?y[1].trim():"normal",v=`${b}__${C}__${x}`,S=/url\((["']?)([^"')]+)\1\)/g,k=/url\(/i.test(s),A=/local\(/i.test(s);if(!k&&A)continue;if(!i.has(v)){l=l.replace(s,"");continue}let N=s,T=Array.from(s.matchAll(S));for(let F of T){let M=J(F[0]);if(!M)continue;let E=M;if(!E.startsWith("http")&&!E.startsWith("data:")&&(E=new URL(E,n.href).href),!U(E)){if(p.resource.has(E)){p.font.add(E),N=N.replace(F[0],`url(${p.resource.get(E)})`);continue}if(!p.font.has(E))try{let X=yield(yield z(E,{useProxy:r})).blob(),P=yield new Promise(et=>{let I=new FileReader;I.onload=()=>et(I.result),I.readAsDataURL(X)});p.resource.set(E,P),p.font.add(E),N=N.replace(F[0],`url(${P})`)}catch(K){console.warn("[snapdom] Failed to fetch font resource:",E)}}}l=l.replace(s,N)}d+=l+`
3
+ `}catch(o){console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||f.every(o=>o.href!==n.href)){for(let o of n.cssRules)if(o.type===CSSRule.FONT_FACE_RULE){let m=o.style.getPropertyValue("src"),u=o.style.getPropertyValue("font-family");if(!m||U(u))continue;let l=o.style.getPropertyValue("font-weight")||"normal",s=o.style.getPropertyValue("font-style")||"normal",h=`${u}__${l}__${s}`,b=/url\((["']?)([^"')]+)\1\)/g,g=/local\((["']?)[^)]+?\1\)/g,y=!!m.match(b),C=!!m.match(g);if(!y&&C){d+=`@font-face{font-family:${u};src:${m};font-style:${s};font-weight:${l};}`;continue}if(!i.has(h))continue;let x=m,v=Array.from(m.matchAll(b));for(let S of v){let k=S[2].trim();if(!k)continue;let A=k;if(!A.startsWith("http")&&!A.startsWith("data:")&&(A=new URL(A,n.href||location.href).href),!U(A)){if(p.resource.has(A)){p.font.add(A),x=x.replace(S[0],`url(${p.resource.get(A)})`);continue}if(!p.font.has(A))try{let T=yield(yield z(A,{useProxy:r})).blob(),F=yield new Promise(M=>{let E=new FileReader;E.onload=()=>M(E.result),E.readAsDataURL(T)});p.resource.set(A,F),p.font.add(A),x=x.replace(S[0],`url(${F})`)}catch(N){console.warn("[snapdom] Failed to fetch font URL:",A)}}}d+=`@font-face{font-family:${u};src:${x};font-style:${s};font-weight:${l};}`}}}catch(o){console.warn("[snapdom] Cannot access stylesheet",n.href,o)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(U(n.family))continue;let o=n._snapdomSrc;if(!o.startsWith("data:")){if(p.resource.has(n._snapdomSrc))o=p.resource.get(n._snapdomSrc),p.font.add(n._snapdomSrc);else if(!p.font.has(n._snapdomSrc))try{let u=yield(yield z(n._snapdomSrc,{useProxy:r})).blob();o=yield new Promise(l=>{let s=new FileReader;s.onload=()=>l(s.result),s.readAsDataURL(u)}),p.resource.set(n._snapdomSrc,o),p.font.add(n._snapdomSrc)}catch(m){console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}d+=`@font-face{font-family:'${n.family}';src:url(${o});font-style:${n.style||"normal"};font-weight:${n.weight||"normal"};}`}for(let n of e){if(!n||typeof n!="object")continue;let{family:o,src:m,weight:u="normal",style:l="normal"}=n;if(!o||!m)continue;let s=m;if(s.startsWith("data:"))p.resource.set(m,s),p.font.add(m);else try{let b=yield(yield z(m,{useProxy:r})).blob();s=yield new Promise(g=>{let y=new FileReader;y.onload=()=>g(y.result),y.readAsDataURL(b)}),p.resource.set(m,s),p.font.add(m)}catch(h){console.warn("[snapdom] Failed to load local font:",m);continue}d+=`@font-face{font-family:'${o}';src:url(${s});font-style:${l};font-weight:${u};}`}if(d&&(p.resource.set("fonts-embed-css",d),t)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=d,document.head.appendChild(n)}return d})}function pt(t,e,r,i,c){return w(this,null,function*(){var d;if(!(t instanceof Element)||!(e instanceof Element))return;for(let n of["::before","::after","::first-letter"])try{let o=D(t,n);if(!o||typeof o[Symbol.iterator]!="function"||o.content==="none"&&o.backgroundImage==="none"&&o.backgroundColor==="transparent"&&(o.borderStyle==="none"||parseFloat(o.borderWidth)===0)&&(!o.transform||o.transform==="none")&&o.display==="inline")continue;if(n==="::first-letter"){let R=getComputedStyle(t);if(!(o.color!==R.color||o.fontSize!==R.fontSize||o.fontWeight!==R.fontWeight))continue;let W=Array.from(e.childNodes).find(Ct=>{var vt;return Ct.nodeType===Node.TEXT_NODE&&((vt=Ct.textContent)==null?void 0:vt.trim().length)>0});if(!W)continue;let j=W.textContent,lt=j.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),O=lt==null?void 0:lt[0],Kt=j.slice((O==null?void 0:O.length)||0);if(!O||/[\uD800-\uDFFF]/.test(O))continue;let nt=document.createElement("span");nt.textContent=O,nt.dataset.snapdomPseudo="::first-letter";let Xt=ut(o),Gt=G(Xt,"span",c);r.set(nt,Gt);let xt=document.createTextNode(Kt);e.replaceChild(xt,W),e.insertBefore(nt,xt);continue}let u=o.content,l=/counter\s*\(|counters\s*\(/.test(u)?"- ":Lt(u),s=o.backgroundImage,h=o.backgroundColor,b=o.fontFamily,g=parseInt(o.fontSize)||32,y=parseInt(o.fontWeight)||!1,C=o.color||"#000",x=o.display,v=parseFloat(o.width),S=parseFloat(o.height),k=o.borderStyle,A=parseFloat(o.borderWidth),N=o.transform,T=U(b),F=u!=="none"&&l!=="",M=s&&s!=="none",E=h&&h!=="transparent"&&h!=="rgba(0, 0, 0, 0)",K=x!=="inline"&&(v>0||S>0),X=k&&k!=="none"&&A>0,P=N&&N!=="none";if(!(F||M||E||K||X||P))continue;let I=document.createElement("span");I.dataset.snapdomPseudo=n,I.style.verticalAlign="middle";let it=ut(o),ct=G(it,"span",c);if(r.set(I,ct),T&&l.length===1){let{dataUrl:R,width:B,height:W}=yield Mt(l,b,y,g,C),j=document.createElement("img");j.src=R,j.style=`height:${g}px;width:${B/W*g}px;object-fit:contain;`,I.appendChild(j),e.dataset.snapdomHasIcon="true"}else if(l.startsWith("url(")){let R=J(l);if(R!=null&&R.trim())try{let B=document.createElement("img"),W=yield _(Q(R),c);B.src=W,B.style=`width:${g}px;height:auto;object-fit:contain;`,I.appendChild(B)}catch(B){console.error(`[snapdom] Error in pseudo ${n} for`,t,B)}}else!T&&F&&(I.textContent=l);if(M)try{let R=Y(s),B=yield Promise.all(R.map(V));I.style.backgroundImage=B.join(", ")}catch(R){console.warn(`[snapdom] Failed to inline background-image for ${n}`,R)}if(E&&(I.style.backgroundColor=h),!(I.childNodes.length>0||((d=I.textContent)==null?void 0:d.trim())!==""||M||E||K||X||P))continue;n==="::before"?e.insertBefore(I,e.firstChild):e.appendChild(I)}catch(o){console.warn(`[snapdom] Failed to capture ${n} for`,t,o)}let a=Array.from(t.children),f=Array.from(e.children).filter(n=>!n.dataset.snapdomPseudo);for(let n=0;n<Math.min(a.length,f.length);n++)yield pt(a[n],f[n],r,i,c)})}function Wt(t){if(!t)return;let e=new Set;if(t.querySelectorAll("use").forEach(d=>{let n=d.getAttribute("xlink:href")||d.getAttribute("href");n&&n.startsWith("#")&&e.add(n.slice(1))}),!e.size)return;let r=Array.from(document.querySelectorAll("svg > symbol, svg > defs")),i=r.filter(d=>d.tagName.toLowerCase()==="symbol"),c=r.filter(d=>d.tagName.toLowerCase()==="defs"),a=t.querySelector("svg.inline-defs-container");a||(a=document.createElementNS("http://www.w3.org/2000/svg","svg"),a.setAttribute("aria-hidden","true"),a.setAttribute("style","position: absolute; width: 0; height: 0; overflow: hidden;"),a.classList.add("inline-defs-container"),t.insertBefore(a,t.firstChild));let f=new Set;t.querySelectorAll("symbol[id], defs > *[id]").forEach(d=>{f.add(d.id)}),e.forEach(d=>{if(f.has(d))return;let n=i.find(o=>o.id===d);if(n){a.appendChild(n.cloneNode(!0)),f.add(d);return}for(let o of c){let m=o.querySelector(`#${CSS.escape(d)}`);if(m){let u=a.querySelector("defs");u||(u=document.createElementNS("http://www.w3.org/2000/svg","defs"),a.appendChild(u)),u.appendChild(m.cloneNode(!0)),f.add(d);break}}})}function jt(c){return w(this,arguments,function*(t,e=!1,r=!1,i={}){var m,u;let a=new Map,f=new WeakMap,d=new Map,n,o="";ie(t);try{Wt(t)}catch(l){console.warn("inlineExternal defs or symbol failed:",l)}try{n=Z(t,a,f,d,e,i,t)}catch(l){throw console.warn("deepClone failed:",l),l}try{yield pt(t,n,a,f,e,r,i.useProxy)}catch(l){console.warn("inlinePseudoElements failed:",l)}if(yield de(n),e){let l=Ft(a);o=Array.from(l.entries()).map(([s,h])=>`.${h}{${s}}`).join("");for(let[s,h]of a.entries()){if(s.tagName==="STYLE")continue;if(s.getRootNode&&s.getRootNode()instanceof ShadowRoot){s.setAttribute("style",h.replace(/;/g,"; "));continue}let b=l.get(h);b&&s.classList.add(b);let g=(m=s.style)==null?void 0:m.backgroundImage,y=(u=s.dataset)==null?void 0:u.snapdomHasIcon;g&&g!=="none"&&(s.style.backgroundImage=g),y&&(s.style.verticalAlign="middle",s.style.display="inline")}}else for(let[l,s]of a.entries())l.tagName!=="STYLE"&&l.setAttribute("style",s.replace(/;/g,"; "));for(let[l,s]of d.entries()){let h=s.scrollLeft,b=s.scrollTop;if((h||b)&&l instanceof HTMLElement){l.style.overflow="hidden",l.style.scrollbarWidth="none",l.style.msOverflowStyle="none";let y=document.createElement("div");for(y.style.transform=`translate(${-h}px, ${-b}px)`,y.style.willChange="transform",y.style.display="inline-block",y.style.width="100%";l.firstChild;)y.appendChild(l.firstChild);l.appendChild(y)}}if(t===d.get(n)){let l=f.get(t)||window.getComputedStyle(t);f.set(t,l);let s=Bt(l.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=s||""}for(let[l,s]of d.entries())s.tagName==="PRE"&&(l.style.marginTop="0",l.style.marginBlockStart="0");return{clone:n,classCSS:o,styleCache:f}})}function ie(t){let e=getComputedStyle(t),r=e.outlineStyle,i=e.outlineWidth,c=e.borderStyle,a=e.borderWidth,f=r!=="none"&&parseFloat(i)>0,d=c==="none"||parseFloat(a)===0;f&&d&&(t.style.border=`${i} solid transparent`)}var yt=new Map;function tt(t){return w(this,null,function*(){if(yt.has(t))return yt.get(t);let e=yield fetch(t);if(!e.ok)throw new Error(`[SnapDOM] HTTP ${e.status} on blob fetch (${t})`);let r=yield e.blob(),i=yield new Promise((c,a)=>{let f=new FileReader;f.onloadend=()=>{let d=f.result;typeof d=="string"&&d.startsWith("data:")?c(d):a(new Error("[SnapDOM] Invalid data URL from blob"))},f.onerror=()=>a(new Error("[SnapDOM] FileReader error")),f.readAsDataURL(r)});return yt.set(t,i),i})}var ce=/\bblob:[^)"'\s]+/g;function _t(t){return w(this,null,function*(){if(!t||t.indexOf("blob:")===-1)return t;let e=Array.from(new Set(t.match(ce)||[]));if(e.length===0)return t;let r=t;for(let i of e)try{let c=yield tt(i);r=r.split(i).join(c)}catch(c){}return r})}function st(t){return typeof t=="string"&&t.startsWith("blob:")}function le(t){return(t||"").split(",").map(e=>e.trim()).filter(Boolean).map(e=>{let r=e.match(/^(\S+)(\s+.+)?$/);return r?{url:r[1],desc:r[2]||""}:null}).filter(Boolean)}function fe(t){return t.map(e=>e.desc?`${e.url} ${e.desc.trim()}`:e.url).join(", ")}function de(t){return w(this,null,function*(){var f,d;if(!t)return;let e=t.querySelectorAll?t.querySelectorAll("img"):[];for(let n of e)try{let m=n.getAttribute("src")||n.currentSrc||"";if(st(m)){let l=yield tt(m);n.setAttribute("src",l)}let u=n.getAttribute("srcset");if(u&&u.includes("blob:")){let l=le(u),s=!1;for(let h of l)if(st(h.url))try{h.url=yield tt(h.url),s=!0}catch(b){}s&&n.setAttribute("srcset",fe(l))}}catch(o){}let r=t.querySelectorAll?t.querySelectorAll("image"):[];for(let n of r)try{let o="http://www.w3.org/1999/xlink",m=n.getAttribute("href")||((f=n.getAttributeNS)==null?void 0:f.call(n,o,"href"));if(st(m)){let u=yield tt(m);n.setAttribute("href",u),(d=n.removeAttributeNS)==null||d.call(n,o,"href")}}catch(o){}let i=t.querySelectorAll?t.querySelectorAll("[style*='blob:']"):[];for(let n of i)try{let o=n.getAttribute("style");if(o&&o.includes("blob:")){let m=yield _t(o);n.setAttribute("style",m)}}catch(o){}let c=t.querySelectorAll?t.querySelectorAll("style"):[];for(let n of c)try{let o=n.textContent||"";o.includes("blob:")&&(n.textContent=yield _t(o))}catch(o){}let a=["poster"];for(let n of a){let o=t.querySelectorAll?t.querySelectorAll(`[${n}^='blob:']`):[];for(let m of o)try{let u=m.getAttribute(n);st(u)&&m.setAttribute(n,yield tt(u))}catch(u){}}})}function Ot(r){return w(this,arguments,function*(t,e={}){let i=Array.from(t.querySelectorAll("img")),c=a=>w(null,null,function*(){if(!a.getAttribute("src")){let d=a.currentSrc||a.src||"";d&&a.setAttribute("src",d)}a.removeAttribute("srcset"),a.removeAttribute("sizes");let f=a.src;try{let d=yield _(f,{useProxy:e.useProxy});a.src=d,a.width||(a.width=a.naturalWidth||100),a.height||(a.height=a.naturalHeight||100)}catch(d){let n=document.createElement("div");n.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;`,n.innerText="img",a.replaceWith(n)}});for(let a=0;a<i.length;a+=4){let f=i.slice(a,a+4).map(c);yield Promise.allSettled(f)}})}function qt(c,a,f){return w(this,arguments,function*(t,e,r,i={}){let d=[[t,e]],n=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source","border-image","border-image-source","border-image-slice","border-image-width","border-image-outset","border-image-repeat"];for(;d.length;){let[o,m]=d.shift(),u=r.get(o)||D(o);r.has(o)||r.set(o,u);let l=(()=>{let g=u.getPropertyValue("border-image"),y=u.getPropertyValue("border-image-source");return g&&g!=="none"||y&&y!=="none"})();for(let g of n){if(["border-image-slice","border-image-width","border-image-outset","border-image-repeat"].includes(g)&&!l)continue;let y=u.getPropertyValue(g);if(!y||y==="none")continue;let C=Y(y),x=yield Promise.all(C.map(v=>V(v,i)));x.some(v=>v&&v!=="none"&&!/^url\(undefined/.test(v))&&m.style.setProperty(g,x.join(", "))}let s=u.getPropertyValue("background-color");s&&s!=="transparent"&&s!=="rgba(0, 0, 0, 0)"&&(m.style.backgroundColor=s);let h=Array.from(o.children),b=Array.from(m.children);for(let g=0;g<Math.min(h.length,b.length);g++)d.push([h[g],b[g]])}})}function Vt(r){return w(this,arguments,function*(t,e={}){if(!t)throw new Error("Element cannot be null or undefined");p.reset();let{compress:i=!0,embedFonts:c=!1,fast:a=!0,scale:f=1,useProxy:d="",localFonts:n=[]}=e,o,m,u,l="",s="",h,b;if({clone:o,classCSS:m,styleCache:u}=yield jt(t,i,c,e),yield new Promise(y=>{H(()=>w(null,null,function*(){yield Ot(o,e),y()}),{fast:a})}),yield new Promise(y=>{H(()=>w(null,null,function*(){yield qt(t,o,u,e),y()}),{fast:a})}),c&&(yield new Promise(y=>{H(()=>w(null,null,function*(){l=yield at({localFonts:n,useProxy:d}),y()}),{fast:a})})),i){let y=Nt(o).sort(),C=y.join(",");p.baseStyle.has(C)?s=p.baseStyle.get(C):yield new Promise(x=>{H(()=>{s=Tt(y),p.baseStyle.set(C,s),x()},{fast:a})})}yield new Promise(y=>{H(()=>{let C=t.getBoundingClientRect(),x=C.width,v=C.height,S=Number.isFinite(e.width),k=Number.isFinite(e.height),A=typeof f=="number"&&f!==1;if(!A){let P=C.width/C.height;S&&k?(x=e.width,v=e.height):S?(x=e.width,v=x/P):k&&(v=e.height,x=v*P)}if(x=Math.ceil(x),v=Math.ceil(v),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="top left",!A&&(S||k)){let P=C.width,et=C.height,I=x/P,it=v/et,ct=o.style.transform||"",St=`scale(${I}, ${it})`;o.style.transform=`${St} ${ct}`.trim()}let N="http://www.w3.org/2000/svg",T=document.createElementNS(N,"foreignObject");T.setAttribute("width","100%"),T.setAttribute("height","100%");let F=document.createElement("style");F.textContent=s+l+"svg{overflow:visible;}"+m,T.appendChild(F),T.appendChild(o);let E=new XMLSerializer().serializeToString(T);b=`<svg xmlns="${N}" width="${x}" height="${v}" viewBox="0 0 ${x} ${v}">`+E+"</svg>",h=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(b)}`,y()},{fast:a})});let g=document.getElementById("snapdom-sandbox");return g&&g.style.position==="absolute"&&g.remove(),h})}function ue(r){return w(this,arguments,function*(t,{scale:e=1}={}){let i=new Image;return i.src=t,yield i.decode(),e!==1&&(i.style.width=`${i.naturalWidth*e}px`,i.style.height=`${i.naturalHeight*e}px`),i})}function Ht(i){return w(this,arguments,function*(t,{dpr:e=1,scale:r=1}={}){let c=new Image;c.src=t,c.crossOrigin="anonymous",c.loading="eager",c.decoding="sync";let a=Pt(),f=!1;if(a&&(document.body.appendChild(c),f=!0),yield c.decode(),a&&(yield new Promise(u=>setTimeout(u,100))),c.width===0||c.height===0)throw f&&c.remove(),new Error("Image failed to load or has no dimensions");let d=c.naturalWidth*r,n=c.naturalHeight*r,o=document.createElement("canvas");o.width=Math.ceil(d*e),o.height=Math.ceil(n*e),o.style.width=`${d}px`,o.style.height=`${n}px`;let m=o.getContext("2d");return m.scale(e,e),m.drawImage(c,0,0,d,n),f&&c.remove(),o})}function zt(a){return w(this,arguments,function*(t,{type:e="svg",scale:r=1,backgroundColor:i="#fff",quality:c}={}){let f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[e]||"image/png";if(e==="svg"){let n=decodeURIComponent(t.split(",")[1]);return new Blob([n],{type:"image/svg+xml"})}let d=yield bt(t,{dpr:1,scale:r},i);return new Promise(n=>{d.toBlob(o=>n(o),`${f}`,c)})})}function bt(c,a,f){return w(this,arguments,function*(t,{dpr:e=1,scale:r=1},i){let d=yield Ht(t,{dpr:e,scale:r});if(!i)return d;let n=document.createElement("canvas");n.width=d.width,n.height=d.height;let o=n.getContext("2d");return o.fillStyle=i,o.fillRect(0,0,n.width,n.height),o.drawImage(d,0,0),n})}function wt(f,d){return w(this,arguments,function*(t,{dpr:e=1,scale:r=1,backgroundColor:i,quality:c},a="png"){let n=["jpg","jpeg","webp"].includes(a)?"#fff":void 0,o=i!=null?i:n,m=yield bt(t,{dpr:e,scale:r},o),u=new Image;return u.src=m.toDataURL(`image/${a}`,c),yield u.decode(),u.style.width=`${m.width/e}px`,u.style.height=`${m.height/e}px`,u})}function me(f){return w(this,arguments,function*(t,{dpr:e=1,scale:r=1,backgroundColor:i,format:c="png",filename:a="snapDOM"}={}){if(c==="svg"){let s=yield zt(t),h=URL.createObjectURL(s),b=document.createElement("a");b.href=h,b.download=`${a}.svg`,b.click(),URL.revokeObjectURL(h);return}let d=["jpg","jpeg","webp"].includes(c)?"#fff":void 0,n=i!=null?i:d,o=yield bt(t,{dpr:e,scale:r},n),m={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[c]||"image/png",u=o.toDataURL(m),l=document.createElement("a");l.href=u,l.download=`${a}.${c}`,l.click()})}function $(r){return w(this,arguments,function*(t,e={}){if(e=L({scale:1},e),!t)throw new Error("Element cannot be null or undefined");return e.iconFonts&&Ut(e.iconFonts),yield $.capture(t,e)})}$.capture=(r,...i)=>w(null,[r,...i],function*(t,e={}){var d;let c=yield Vt(t,e),a=(d=e.dpr)!=null?d:window.devicePixelRatio||1,f=e.scale||1;return{url:c,options:e,toRaw:()=>c,toImg:(n={})=>ue(c,L({dpr:a,scale:f},n)),toCanvas:(n={})=>Ht(c,L({dpr:a,scale:f},n)),toBlob:(n={})=>zt(c,L({dpr:a,scale:f},n)),toPng:(n={})=>wt(c,L({dpr:a,scale:f},n),"png"),toJpg:(n={})=>wt(c,L({dpr:a,scale:f},n),"jpeg"),toWebp:(n={})=>wt(c,L({dpr:a,scale:f},n),"webp"),download:(l={})=>{var s=l,{format:n="png",filename:o="snapDOM",backgroundColor:m}=s,u=ft(s,["format","filename","backgroundColor"]);return me(c,L({dpr:a,scale:f,format:n,filename:o,backgroundColor:m},u))}}});$.toRaw=(t,e)=>w(null,null,function*(){return(yield $.capture(t,e)).toRaw()});$.toImg=(t,e)=>w(null,null,function*(){return(yield $.capture(t,e)).toImg()});$.toCanvas=(t,e)=>w(null,null,function*(){return(yield $.capture(t,e)).toCanvas()});$.toBlob=(t,e)=>w(null,null,function*(){return(yield $.capture(t,e)).toBlob(e)});$.toPng=(t,e)=>w(null,null,function*(){return(yield $.capture(t,e)).toPng(e)});$.toJpg=(t,e)=>w(null,null,function*(){return(yield $.capture(t,e)).toJpg(e)});$.toWebp=(t,e)=>w(null,null,function*(){return(yield $.capture(t,e)).toWebp(e)});$.download=(r,...i)=>w(null,[r,...i],function*(t,e={}){let o=e,{format:c="png",filename:a="capture",backgroundColor:f}=o,d=ft(o,["format","filename","backgroundColor"]);return yield(yield $.capture(t,d)).download({format:c,filename:a,backgroundColor:f})});function Yt(){return w(this,arguments,function*(t=document,e={}){let{embedFonts:r=!0,reset:i=!1,useProxy:c}=e;if(i){p.image.clear(),p.background.clear(),p.resource.clear(),p.defaultStyle.clear(),p.baseStyle.clear(),p.font.clear(),p.computedStyle=new WeakMap;return}try{yield document.fonts.ready}catch(n){}It();let a=[],f=[];t!=null&&t.querySelectorAll&&(a=Array.from(t.querySelectorAll("img[src]")),f=Array.from(t.querySelectorAll("*")));let d=[];for(let n of a){let o=n==null?void 0:n.src;if(o&&!p.image.has(o)){let m=Promise.resolve().then(()=>_(o,{useProxy:c})).then(u=>{p.image.set(o,u)}).catch(()=>{});d.push(m)}}for(let n of f){let o="";try{o=D(n).backgroundImage}catch(m){}if(o&&o!=="none"){let m=Y(o);for(let u of m)if(u.startsWith("url(")){let l=Promise.resolve().then(()=>V(u,kt(L({},e),{useProxy:c}))).catch(()=>{});d.push(l)}}}if(r)try{yield at({preCached:!0,localFonts:e.localFonts,useProxy:e.useProxy})}catch(n){}yield Promise.allSettled(d)})}typeof window!="undefined"&&(window.snapdom=$,window.preCache=Yt);})();
@@ -1,3 +1,3 @@
1
- var l={image:new Map,background:new Map,resource:new Map,defaultStyle:new Map,baseStyle:new Map,computedStyle:new WeakMap,font:new Set,snapshot:new WeakMap,snapshotKey:new Map,preStyleMap:new Map,preStyle:new WeakMap,preNodeMap:new Map,reset:Re};function Re(){l.computedStyle=new WeakMap,l.snapshot=new WeakMap,l.snapshotKey.clear(),l.preStyleMap.clear(),l.preStyle=new WeakMap,l.preNodeMap.clear()}var Ne=["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 ie(){for(let e of Ne)ce(e)}function ce(e){if(l.defaultStyle.has(e))return l.defaultStyle.get(e);if(new Set(["script","style","meta","link","noscript","template"]).has(e)){let i={};return l.defaultStyle.set(e,i),i}let r=document.getElementById("snapdom-sandbox");r||(r=document.createElement("div"),r.id="snapdom-sandbox",r.style.position="absolute",r.style.left="-9999px",r.style.top="-9999px",r.style.width="0",r.style.height="0",r.style.overflow="hidden",document.body.appendChild(r));let c=document.createElement(e);c.style.all="initial",r.appendChild(c);let o=getComputedStyle(c),n={};for(let i of o)n[i]=o.getPropertyValue(i);return r.removeChild(c),l.defaultStyle.set(e,n),n}function U(e,t,r=!1){let c=[],o=ce(t);for(let[n,i]of Object.entries(e))if(!r)i&&c.push(`${n}:${i}`);else{let a=o[n];i&&i!==a&&c.push(`${n}:${i}`)}return c.sort().join(";")}function le(e){let t=new Set;return e.nodeType!==Node.ELEMENT_NODE&&e.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(e.tagName&&t.add(e.tagName.toLowerCase()),typeof e.querySelectorAll=="function"&&e.querySelectorAll("*").forEach(r=>t.add(r.tagName.toLowerCase())),Array.from(t))}function fe(e){let t=new Map;for(let c of e){let o=l.defaultStyle.get(c);if(!o)continue;let n=Object.entries(o).map(([i,a])=>`${i}:${a};`).sort().join("");t.has(n)||t.set(n,[]),t.get(n).push(c)}let r="";for(let[c,o]of t.entries())r+=`${o.join(",")} { ${c} }
2
- `;return r}function de(){let e=new Set(l.preStyleMap.values()),t=new Map,r=1;for(let c of e)t.set(c,`c${r++}`);return t}async function P(e,t={}){let r=D(e),c=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(r){let o=q(r);if(l.background.has(o))return t.skipInline?void 0:`url(${l.background.get(o)})`;{let n=await M(o,{useProxy:t.useProxy});return l.background.set(o,n),t.skipInline?void 0:`url("${n}")`}}return e}function L(e,{fast:t=!1}={}){if(t)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function R(e,t=null){if(!(e instanceof Element))return window.getComputedStyle(e,t);let r=l.computedStyle.get(e);if(r||(r=new Map,l.computedStyle.set(e,r)),!r.has(t)){let c=window.getComputedStyle(e,t);r.set(t,c)}return r.get(t)}function ue(e){let t=e.replace(/^['"]|['"]$/g,"");if(t.startsWith("\\"))try{return String.fromCharCode(parseInt(t.replace("\\",""),16))}catch{return t}return t}function D(e){let t=e.match(/url\((['"]?)(.*?)(\1)\)/);if(!t)return null;let r=t[2].trim();return r.startsWith("#")?null:r}function M(e,{timeout:t=3e3,useProxy:r=""}={}){function c(s){try{return new URL(s,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch{return"anonymous"}}async function o(s){let f=u=>fetch(u,{mode:"cors",credentials:c(u)==="use-credentials"?"include":"omit"}).then(d=>d.blob()).then(d=>new Promise((h,p)=>{let m=new FileReader;m.onloadend=()=>{let g=m.result;if(typeof g!="string"||!g.startsWith("data:image/")){p(new Error("Invalid image data URL"));return}h(g)},m.onerror=()=>p(new Error("FileReader error")),m.readAsDataURL(d)}));try{return await f(s)}catch{if(r&&typeof r=="string"){let d=r.replace(/\/$/,"")+q(s);try{return await f(d)}catch{throw new Error("[SnapDOM - fetchImage] CORS restrictions prevented image capture (even via proxy)")}}else throw new Error("[SnapDOM - fetchImage] Fetch fallback failed and no proxy provided")}}let n=c(e);return l.image.has(e)?Promise.resolve(l.image.get(e)):e.startsWith("data:image/")?(l.image.set(e,e),Promise.resolve(e)):/\.svg(\?.*)?$/i.test(e)?(async()=>{try{let f=await(await fetch(e,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),u=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(f)}`;return l.image.set(e,u),u}catch{return o(e)}})():new Promise((s,f)=>{let u=setTimeout(()=>{f(new Error("[SnapDOM - fetchImage] Image load timed out"))},t),d=new Image;d.crossOrigin=n,d.onload=async()=>{clearTimeout(u);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");l.image.set(e,m),s(m)}catch{try{let h=await o(e);l.image.set(e,h),s(h)}catch(h){f(h)}}},d.onerror=async()=>{clearTimeout(u),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let h=await o(e);l.image.set(e,h),s(h)}catch(h){f(h)}},d.src=e})}function Z(e){let t={};for(let r of e)t[r]=e.getPropertyValue(r);return t}function pe(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function me(e){if(!e||e==="none")return"";let t=e.replace(/translate[XY]?\([^)]*\)/g,"");return t=t.replace(/matrix\(([^)]+)\)/g,(r,c)=>{let o=c.split(",").map(n=>n.trim());return o.length!==6?`matrix(${c})`:(o[4]="0",o[5]="0",`matrix(${o.join(", ")})`)}),t=t.replace(/matrix3d\(([^)]+)\)/g,(r,c)=>{let o=c.split(",").map(n=>n.trim());return o.length!==16?`matrix3d(${c})`:(o[12]="0",o[13]="0",`matrix3d(${o.join(", ")})`)}),t.trim().replace(/\s{2,}/g," ")}function q(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch{return e}}function F(e){let t=[],r=0,c=0;for(let o=0;o<e.length;o++){let n=e[o];n==="("&&r++,n===")"&&r--,n===","&&r===0&&(t.push(e.slice(c,o).trim()),c=o+1)}return t.push(e.slice(c).trim()),t}function Te(e){let t={};for(let r=0;r<e.length;r++){let c=e[r],o=e.getPropertyValue(c);(c==="background-image"||c==="content")&&o.includes("url(")&&!o.includes("data:")&&(o="none"),t[c]=o}return t}function z(e,t,r){if(e.tagName==="STYLE")return;l.preStyle.has(e)||l.preStyle.set(e,R(e));let c=l.preStyle.get(e);if(!l.snapshot.has(e)){let s=Te(c);l.snapshot.set(e,s)}let o=l.snapshot.get(e),n=Object.entries(o).sort(([s],[f])=>s.localeCompare(f)).map(([s,f])=>`${s}:${f}`).join(";");if(l.snapshotKey.has(n)){l.preStyleMap.set(t,l.snapshotKey.get(n));return}let i=e.tagName?.toLowerCase()||"div",a=U(o,i,r);l.snapshotKey.set(n,a),l.preStyleMap.set(t,a)}function j(e,t,r={},c){if(!e)throw new Error("Invalid node");let o=new Set,n=null;if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let a=document.createElement("div"),s=e.getBoundingClientRect();return a.style.cssText=`display:inline-block;width:${s.width}px;height:${s.height}px;visibility:hidden;`,a}if(r.exclude&&Array.isArray(r.exclude))for(let a of r.exclude)try{if(e.matches?.(a)){let s=document.createElement("div"),f=e.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: ${a}`,s)}if(typeof r.filter=="function")try{if(!r.filter(e,c||e)){let a=document.createElement("div"),s=e.getBoundingClientRect();return a.style.cssText=`display:inline-block;width:${s.width}px;height:${s.height}px;visibility:hidden;`,a}}catch(a){console.warn("Error in filter function:",a)}if(e.tagName==="IFRAME"){let a=document.createElement("div");return a.style.cssText=`width:${e.offsetWidth}px;height:${e.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;`,a}if(e.getAttribute("data-capture")==="placeholder"){let a=e.cloneNode(!1);l.preNodeMap.set(a,e),z(e,a,t);let s=document.createElement("div");return s.textContent=e.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;",a.appendChild(s),a}if(e.tagName==="CANVAS"){let a=e.toDataURL(),s=document.createElement("img");return s.src=a,s.width=e.width,s.height=e.height,l.preNodeMap.set(s,e),z(e,s,t),s}let i;try{i=e.cloneNode(!1),l.preNodeMap.set(i,e)}catch(a){throw console.error("[Snapdom] Failed to clone node:",e,a),a}if(e instanceof HTMLTextAreaElement){i.textContent=e.value,i.value=e.value;let a=e.getBoundingClientRect();return i.style.width=`${a.width}px`,i.style.height=`${a.height}px`,i}if(e instanceof HTMLInputElement&&(i.value=e.value,i.setAttribute("value",e.value),e.checked!==void 0&&(i.checked=e.checked,e.checked&&i.setAttribute("checked",""),e.indeterminate&&(i.indeterminate=e.indeterminate))),e instanceof HTMLSelectElement&&(n=e.value),z(e,i,t),e.shadowRoot)if(Array.from(e.shadowRoot.querySelectorAll("slot")).length>0){for(let s of e.shadowRoot.childNodes)if(s.nodeType===Node.ELEMENT_NODE&&s.tagName==="STYLE"){let f=s.textContent||"";f.trim()&&t&&(l.preStyle||(l.preStyle=new WeakMap),l.preStyle.set(s,f))}}else{let s=document.createDocumentFragment();for(let f of e.shadowRoot.childNodes){if(f.nodeType===Node.ELEMENT_NODE&&f.tagName==="STYLE"){let d=f.textContent||"";d.trim()&&t&&(l.preStyle||(l.preStyle=new WeakMap),l.preStyle.set(f,d));continue}let u=j(f,t,r,c||e);u&&s.appendChild(u)}i.appendChild(s)}if(e.tagName==="SLOT"){let a=e.assignedNodes?.({flatten:!0})||[],s=a.length>0?a:Array.from(e.childNodes),f=document.createDocumentFragment();for(let u of s){let d=j(u,t,r,c||e);d&&f.appendChild(d)}return f}for(let a of e.childNodes){if(o.has(a))continue;let s=j(a,t,r,c||e);s&&i.appendChild(s)}if(n!==null&&i instanceof HTMLSelectElement){i.value=n;for(let a of i.options)a.value===n?a.setAttribute("selected",""):a.removeAttribute("selected")}return i}var Ae=[/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],ee=[];function he(e){let t=Array.isArray(e)?e:[e];for(let r of t)r instanceof RegExp?ee.push(r):typeof r=="string"?ee.push(new RegExp(r,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",r)}function v(e){let t=typeof e=="string"?e:"",r=[...Ae,...ee];for(let c of r)if(c instanceof RegExp&&c.test(t))return!0;return!!(/icon/i.test(t)||/glyph/i.test(t)||/symbols/i.test(t)||/feather/i.test(t)||/fontawesome/i.test(t))}async function ge(e,t,r,c=32,o="#000"){t=t.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,a=document.createElement("canvas").getContext("2d");a.font=r?`${r} ${c}px "${t}"`:`${c}px "${t}"`;let s=a.measureText(e),f=s.actualBoundingBoxAscent||c*.8,u=s.actualBoundingBoxDescent||c*.2,d=f+u,h=s.width,p=document.createElement("canvas");p.width=Math.ceil(h*n),p.height=Math.ceil(d*n);let m=p.getContext("2d");return m.scale(n,n),m.font=a.font,m.textAlign="left",m.textBaseline="alphabetic",m.fillStyle=o,m.fillText(e,0,f),p.toDataURL()}function ye(e){return Array.from(document.styleSheets).some(t=>t.href===e)}function Me(e){return new Promise(t=>{if(ye(e))return t(null);let r=document.createElement("link");r.rel="stylesheet",r.href=e,r.setAttribute("data-snapdom","injected-import"),r.onload=()=>t(r),r.onerror=()=>t(null),document.head.appendChild(r)})}async function H({preCached:e=!1}={}){if(l.resource.has("fonts-embed-css")){if(e){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=l.resource.get("fonts-embed-css"),document.head.appendChild(n)}return l.resource.get("fonts-embed-css")}let t=/@import\s+url\(["']?([^"')]+)["']?\)/g,r=[];for(let n of document.querySelectorAll("style")){let i=n.textContent||"",a=Array.from(i.matchAll(t));for(let s of a){let f=s[1];v(f)||ye(f)||r.push(f)}}await Promise.all(r.map(Me));let c=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),o="";for(let n of c)try{let a=await(await fetch(n.href)).text();if(v(n.href)||v(a))continue;let s=/url\((["']?)([^"')]+)\1\)/g,f=await Promise.all(Array.from(a.matchAll(s)).map(async d=>{let h=D(d[0]);if(!h)return null;let p=h;if(!p.startsWith("http")&&!p.startsWith("data:")&&(p=new URL(p,n.href).href),v(p))return null;if(l.resource.has(p))return l.font.add(p),{original:d[0],inlined:`url(${l.resource.get(p)})`};if(l.font.has(p))return null;try{let g=await(await fetch(p)).blob(),w=await new Promise(y=>{let E=new FileReader;E.onload=()=>y(E.result),E.readAsDataURL(g)});return l.resource.set(p,w),l.font.add(p),{original:d[0],inlined:`url(${w})`}}catch{return console.warn("[snapdom] Failed to fetch font resource:",p),null}})),u=a;for(let d of f)d&&(u=u.replace(d.original,d.inlined));o+=u+`
3
- `}catch{console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||c.every(i=>i.href!==n.href)){for(let i of n.cssRules)if(i.type===CSSRule.FONT_FACE_RULE){let a=i.style.getPropertyValue("src"),s=i.style.getPropertyValue("font-family");if(!a||v(s))continue;let f=/url\((["']?)([^"')]+)\1\)/g,u=/local\((["']?)[^)]+?\1\)/g,d=!!a.match(f),h=!!a.match(u);if(!d&&h){o+=`@font-face{font-family:${s};src:${a};font-style:${i.style.getPropertyValue("font-style")||"normal"};font-weight:${i.style.getPropertyValue("font-weight")||"normal"};}`;continue}let p=a,m=Array.from(a.matchAll(f));for(let g of m){let w=g[2].trim();if(!w)continue;let y=w;if(!y.startsWith("http")&&!y.startsWith("data:")&&(y=new URL(y,n.href||location.href).href),!v(y)){if(l.resource.has(y)){l.font.add(y),p=p.replace(g[0],`url(${l.resource.get(y)})`);continue}if(!l.font.has(y))try{let k=await(await fetch(y)).blob(),$=await new Promise(N=>{let S=new FileReader;S.onload=()=>N(S.result),S.readAsDataURL(k)});l.resource.set(y,$),l.font.add(y),p=p.replace(g[0],`url(${$})`)}catch{console.warn("[snapdom] Failed to fetch font URL:",y)}}}o+=`@font-face{font-family:${s};src:${p};font-style:${i.style.getPropertyValue("font-style")||"normal"};font-weight:${i.style.getPropertyValue("font-weight")||"normal"};}`}}}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){if(v(n.family))continue;let i=n._snapdomSrc;if(!i.startsWith("data:")){if(l.resource.has(n._snapdomSrc))i=l.resource.get(n._snapdomSrc),l.font.add(n._snapdomSrc);else if(!l.font.has(n._snapdomSrc))try{let s=await(await fetch(n._snapdomSrc)).blob();i=await new Promise(f=>{let u=new FileReader;u.onload=()=>f(u.result),u.readAsDataURL(s)}),l.resource.set(n._snapdomSrc,i),l.font.add(n._snapdomSrc)}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}o+=`@font-face{font-family:'${n.family}';src:url(${i});font-style:${n.style||"normal"};font-weight:${n.weight||"normal"};}`}if(o&&(l.resource.set("fonts-embed-css",o),e)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=o,document.head.appendChild(n)}return o}async function te(e,t,r,c=!1,o){if(!(e instanceof Element)||!(t instanceof Element))return;for(let a of["::before","::after","::first-letter"])try{let s=R(e,a);if(!s||typeof s[Symbol.iterator]!="function")continue;if(a==="::first-letter"){let b=getComputedStyle(e);if(!(s.color!==b.color||s.fontSize!==b.fontSize||s.fontWeight!==b.fontWeight))continue;let A=Array.from(t.childNodes).find(Q=>Q.nodeType===Node.TEXT_NODE&&Q.textContent&&Q.textContent.trim().length>0);if(!A)continue;let re=A.textContent,O=re.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],ke=re.slice(O?.length||0);if(!O||/[\uD800-\uDFFF]/.test(O))continue;let _=document.createElement("span");_.textContent=O,_.dataset.snapdomPseudo="::first-letter";let $e=Z(s),Ie=U($e,"span",r);l.preStyleMap.set(_,Ie);let se=document.createTextNode(ke);t.replaceChild(se,A),t.insertBefore(_,se);continue}let f=s.getPropertyValue("content"),u=s.getPropertyValue("background-image"),d=s.getPropertyValue("background-color"),h=s.getPropertyValue("font-family"),p=parseInt(s.getPropertyValue("font-size"))||32,m=parseInt(s.getPropertyValue("font-weight"))||!1,g=s.getPropertyValue("color")||"#000",w=s.getPropertyValue("display"),y=parseFloat(s.getPropertyValue("width")),E=parseFloat(s.getPropertyValue("height")),k=s.getPropertyValue("border-style"),$=s.getPropertyValue("transform"),N=v(h),S;/counter\s*\(|counters\s*\(/.test(f)?S="- ":S=ue(f);let Y=f!=="none"&&S!=="",B=u&&u!=="none",W=d&&d!=="transparent"&&d!=="rgba(0, 0, 0, 0)",X=w!=="inline"&&(y>0||E>0),T=k&&k!=="none",V=$&&$!=="none";if(!(Y||B||W||X||T||V))continue;let C=document.createElement("span");C.dataset.snapdomPseudo=a;let G=Z(s),J=U(G,"span",r);if(l.preStyleMap.set(C,J),N&&S.length===1){let b=document.createElement("img");b.src=await ge(S,h,m,p,g),b.style=`width:${p}px;height:auto;object-fit:contain;`,C.appendChild(b)}else if(S.startsWith("url(")){let b=D(S);if(b&&b.trim()!=="")try{let I=document.createElement("img"),A=await M(q(b,{useProxy:o}));I.src=A,I.style=`width:${p}px;height:auto;object-fit:contain;`,C.appendChild(I)}catch(I){console.error(`[snapdom] Error in pseudo ${a} for`,e,I)}}else!N&&Y&&(C.textContent=S);if(B)try{let b=F(u),I=await Promise.all(b.map(A=>P(A)));C.style.backgroundImage=I.join(", ")}catch(b){console.warn(`[snapdom] Failed to inline background-image for ${a}`,b)}if(W&&(C.style.backgroundColor=d),!(C.childNodes.length>0||C.textContent&&C.textContent.trim()!==""||B||W||X||T||V))continue;a==="::before"?t.insertBefore(C,t.firstChild):t.appendChild(C)}catch(s){console.warn(`[snapdom] Failed to capture ${a} for`,e,s)}let n=Array.from(e.children),i=Array.from(t.children).filter(a=>!a.dataset.snapdomPseudo);for(let a=0;a<Math.min(n.length,i.length);a++)await te(n[a],i[a],r,c,o)}function we(e){if(!e)return;let t=document.querySelectorAll("svg > defs");t.length&&e.querySelectorAll("svg").forEach(r=>{let c=r.querySelectorAll("use");if(!c.length)return;let o=new Set;if(c.forEach(i=>{let a=i.getAttribute("xlink:href")||i.getAttribute("href");a&&a.startsWith("#")&&o.add(a.slice(1))}),!o.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let i of o)for(let a of t){let s=a.querySelector(`#${CSS.escape(i)}`);if(s){n.appendChild(s.cloneNode(!0));break}}n.childNodes.length&&r.insertBefore(n,r.firstChild)})}async function xe(e,t=!1,r=!1,c={}){let o,n="";try{o=j(e,t,c,e)}catch(i){throw console.warn("deepClone failed:",i),i}try{await te(e,o,t,r,c.useProxy)}catch(i){console.warn("inlinePseudoElements failed:",i)}try{we(o)}catch(i){console.warn("inlineExternalDef failed:",i)}if(t){let i=de();n=Array.from(i.entries()).map(([a,s])=>`.${s}{${a}}`).join("");for(let[a,s]of l.preStyleMap.entries()){if(a.tagName==="STYLE")continue;let f=i.get(s);f&&a.classList.add(f);let u=a.style?.backgroundImage;a.removeAttribute("style"),u&&u!=="none"&&(a.style.backgroundImage=u)}}else for(let[i,a]of l.preStyleMap.entries())i.tagName!=="STYLE"&&i.setAttribute("style",a.replace(/;/g,"; "));for(let[i,a]of l.preNodeMap.entries()){let s=a.scrollLeft,f=a.scrollTop;if((s||f)&&i instanceof HTMLElement){i.style.overflow="hidden",i.style.scrollbarWidth="none",i.style.msOverflowStyle="none";let d=document.createElement("div");for(d.style.transform=`translate(${-s}px, ${-f}px)`,d.style.willChange="transform",d.style.display="inline-block",d.style.width="100%";i.firstChild;)d.appendChild(i.firstChild);i.appendChild(d)}}if(e===l.preNodeMap.get(o)){let i=l.preStyle.get(e)||window.getComputedStyle(e);l.preStyle.set(e,i);let a=me(i.transform);o.style.margin="0",o.style.position="static",o.style.top="auto",o.style.left="auto",o.style.right="auto",o.style.bottom="auto",o.style.zIndex="auto",o.style.float="none",o.style.clear="none",o.style.transform=a||""}for(let[i,a]of l.preNodeMap.entries())a.tagName==="PRE"&&(i.style.marginTop="0",i.style.marginBlockStart="0");return{clone:o,classCSS:n}}async function Se(e,t={}){let r=Array.from(e.querySelectorAll("img")),c=async o=>{let n=o.src;try{let i=await M(n,{useProxy:t.useProxy});o.src=i,o.width||(o.width=o.naturalWidth||100),o.height||(o.height=o.naturalHeight||100)}catch{let i=document.createElement("div");i.style=`width: ${o.width||100}px; height: ${o.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${o.height||100}px; color: #666; font-size: 12px;`,i.innerText="img",o.replaceWith(i)}};for(let o=0;o<r.length;o+=4){let n=r.slice(o,o+4).map(c);await Promise.allSettled(n)}}async function be(e,t,r={}){let c=[[e,t]],o=["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[n,i]=c.shift(),a=l.preStyle.get(n)||R(n);l.preStyle.has(n)||l.preStyle.set(n,a);for(let d of o){let h=a.getPropertyValue(d);if(!h||h==="none")continue;let p=F(h),m=await Promise.all(p.map(g=>P(g,r)));m.some(g=>g&&g!=="none"&&!/^url\(undefined/.test(g))&&i.style.setProperty(d,m.join(", "))}let s=a.getPropertyValue("background-color");s&&s!=="transparent"&&s!=="rgba(0, 0, 0, 0)"&&(i.style.backgroundColor=s);let f=Array.from(n.children),u=Array.from(i.children);for(let d=0;d<Math.min(f.length,u.length);d++)c.push([f[d],u[d]])}}async function Ce(e,t={}){if(!e)throw new Error("Element cannot be null or undefined");l.reset();let{compress:r=!0,embedFonts:c=!1,fast:o=!0,scale:n=1,useProxy:i=""}=t,a,s,f="",u="",d,h;if({clone:a,classCSS:s}=await xe(e,r,c,t),await new Promise(m=>{L(async()=>{await Se(a,t),m()},{fast:o})}),await new Promise(m=>{L(async()=>{await be(e,a,t),m()},{fast:o})}),c&&await new Promise(m=>{L(async()=>{f=await H(),m()},{fast:o})}),r){let m=le(a).sort(),g=m.join(",");l.baseStyle.has(g)?u=l.baseStyle.get(g):await new Promise(w=>{L(()=>{u=fe(m),l.baseStyle.set(g,u),w()},{fast:o})})}await new Promise(m=>{L(()=>{let g=e.getBoundingClientRect(),w=g.width,y=g.height,E=Number.isFinite(t.width),k=Number.isFinite(t.height),$=typeof n=="number"&&n!==1;if(!$){let T=g.width/g.height;E&&k?(w=t.width,y=t.height):E?(w=t.width,y=w/T):k&&(y=t.height,w=y*T)}if(w=Math.ceil(w),y=Math.ceil(y),a.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),a.style.transformOrigin="top left",!$&&(E||k)){let T=g.width,V=g.height,ae=w/T,C=y/V,G=a.style.transform||"",J=`scale(${ae}, ${C})`;a.style.transform=`${J} ${G}`.trim()}let N="http://www.w3.org/2000/svg",S=document.createElementNS(N,"foreignObject");S.setAttribute("width","100%"),S.setAttribute("height","100%");let K=document.createElement("style");K.textContent=u+f+"svg{overflow:visible;}"+s,S.appendChild(K),S.appendChild(a);let B=new XMLSerializer().serializeToString(S);h=`<svg xmlns="${N}" width="${w}" height="${y}" viewBox="0 0 ${w} ${y}">`+B+"</svg>",d=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(h)}`,m()},{fast:o})});let p=document.getElementById("snapdom-sandbox");return p&&p.style.position==="absolute"&&p.remove(),d}async function Pe(e,{dpr:t=1,scale:r=1}){let c=new Image;return c.src=e,await c.decode(),c.width=c.width*r,c.height=c.height*r,c}async function Ee(e,{dpr:t=1,scale:r=1}={}){let c=new Image;c.src=e,c.crossOrigin="anonymous",c.loading="eager",c.decoding="sync";let o=pe(),n=!1;if(o&&(document.body.appendChild(c),n=!0),await c.decode(),o&&await new Promise(u=>setTimeout(u,100)),c.width===0||c.height===0)throw n&&c.remove(),new Error("Image failed to load or has no dimensions");let i=c.width*r,a=c.height*r,s=document.createElement("canvas");s.width=Math.ceil(i*t),s.height=Math.ceil(a*t),s.style.width=`${i}px`,s.style.height=`${a}px`;let f=s.getContext("2d");return f.scale(t,t),f.drawImage(c,0,0,i,a),n&&c.remove(),s}async function ve(e,{type:t="svg",scale:r=1,backgroundColor:c="#fff",quality:o}={}){let n={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[t]||"image/png";if(t==="svg"){let a=decodeURIComponent(e.split(",")[1]);return new Blob([a],{type:"image/svg+xml"})}let i=await oe(e,{dpr:1,scale:r},c);return new Promise(a=>{i.toBlob(s=>a(s),`${n}`,o)})}async function oe(e,{dpr:t=1,scale:r=1},c){let o=await Ee(e,{dpr:t,scale:r});if(!c)return o;let n=document.createElement("canvas");n.width=o.width,n.height=o.height;let i=n.getContext("2d");return i.fillStyle=c,i.fillRect(0,0,n.width,n.height),i.drawImage(o,0,0),n}async function ne(e,{dpr:t=1,scale:r=1,backgroundColor:c,quality:o},n="png"){let i=["jpg","jpeg","webp"].includes(n)?"#fff":void 0,s=await oe(e,{dpr:t,scale:r},c??i),f=new Image;return f.src=s.toDataURL(`image/${n}`,o),await f.decode(),f.style.width=`${s.width/t}px`,f.style.height=`${s.height/t}px`,f}async function Le(e,{dpr:t=1,scale:r=1,backgroundColor:c,format:o="png",filename:n="snapDOM"}={}){if(o==="svg"){let h=await ve(e),p=URL.createObjectURL(h),m=document.createElement("a");m.href=p,m.download=`${n}.svg`,m.click(),URL.revokeObjectURL(p);return}let i=["jpg","jpeg","webp"].includes(o)?"#fff":void 0,s=await oe(e,{dpr:t,scale:r},c??i),f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[o]||"image/png",u=s.toDataURL(f),d=document.createElement("a");d.href=u,d.download=`${n}.${o}`,d.click()}async function x(e,t={}){if(t={scale:1,...t},!e)throw new Error("Element cannot be null or undefined");return t.iconFonts&&he(t.iconFonts),await x.capture(e,t)}x.capture=async(e,t={})=>{let r=await Ce(e,t),c=window.devicePixelRatio||1,o=t.scale||1;return{url:r,options:t,toRaw:()=>r,toImg:()=>Pe(r,{dpr:c,scale:o}),toCanvas:()=>Ee(r,{dpr:c,scale:o}),toBlob:n=>ve(r,{dpr:c,scale:o,...n}),toPng:n=>ne(r,{dpr:c,scale:o,...n},"png"),toJpg:n=>ne(r,{dpr:c,scale:o,...n},"jpeg"),toWebp:n=>ne(r,{dpr:c,scale:o,...n},"webp"),download:({format:n="png",filename:i="capture",backgroundColor:a}={})=>Le(r,{dpr:c,scale:o,backgroundColor:a,format:n,filename:i})}};x.toRaw=async(e,t)=>(await x.capture(e,t)).toRaw();x.toImg=async(e,t)=>(await x.capture(e,t)).toImg();x.toCanvas=async(e,t)=>(await x.capture(e,t)).toCanvas();x.toBlob=async(e,t)=>(await x.capture(e,t)).toBlob(t);x.toPng=async(e,t)=>(await x.capture(e,t)).toPng(t);x.toJpg=async(e,t)=>(await x.capture(e,t)).toJpg(t);x.toWebp=async(e,t)=>(await x.capture(e,t)).toWebp(t);x.download=async(e,t={})=>{let{format:r="png",filename:c="capture",backgroundColor:o,...n}=t;return await(await x.capture(e,n)).download({format:r,filename:c,backgroundColor:o})};async function Fe(e=document,t={}){let{embedFonts:r=!0,reset:c=!1}=t;if(c){l.reset();return}await document.fonts.ready,ie();let o=[],n=[];e?.querySelectorAll&&(o=Array.from(e.querySelectorAll("img[src]")),n=Array.from(e.querySelectorAll("*")));let i=[];for(let a of o){let s=a.src;l.image.has(s)||i.push(M(s,{useProxy:t.useProxy}).then(f=>l.image.set(s,f)).catch(()=>{}))}for(let a of n){let s=R(a).backgroundImage;if(s&&s!=="none"){let f=F(s);for(let u of f)u.startsWith("url(")&&i.push(P(u,t).catch(()=>{}))}}r&&await H({preCached:!0}),await Promise.all(i)}export{Fe as preCache,x as snapdom};
1
+ var h={image:new Map,background:new Map,resource:new Map,defaultStyle:new Map,baseStyle:new Map,computedStyle:new WeakMap,font:new Set,snapshot:new WeakMap,snapshotKey:new Map,reset:Wt};function Wt(){h.computedStyle=new WeakMap}var _t=["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 yt(){for(let t of _t)wt(t)}function wt(t){if(h.defaultStyle.has(t))return h.defaultStyle.get(t);if(new Set(["script","style","meta","link","noscript","template","defs","symbol","title","metadata","desc"]).has(t)){let a={};return h.defaultStyle.set(t,a),a}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 i=document.createElement(t);i.style.all="initial",n.appendChild(i);let r=getComputedStyle(i),c={};for(let a of r)c[a]=r.getPropertyValue(a);return n.removeChild(i),h.defaultStyle.set(t,c),c}var jt=new Set(["-webkit-locale"]);function K(t,e,n=!1){let i=[],r=wt(e);for(let[c,a]of Object.entries(t))if(!jt.has(c))if(!n)a&&i.push(`${c}:${a}`);else{let f=r[c];a&&a!==f&&i.push(`${c}:${a}`)}return i.sort().join(";")}function bt(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 St(t){let e=new Map;for(let i of t){let r=h.defaultStyle.get(i);if(!r)continue;let c=Object.entries(r).map(([a,f])=>`${a}:${f};`).sort().join("");e.has(c)||e.set(c,[]),e.get(c).push(i)}let n="";for(let[i,r]of e.entries())n+=`${r.join(",")} { ${i} }
2
+ `;return n}function xt(t){let e=new Set(t.values()),n=new Map,i=1;for(let r of e)r.trim()&&n.set(r,`c${i++}`);return n}async function O(t,e={}){let n=X(t),i=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t);if(n){let r=G(n);if(h.background.has(r))return e.skipInline?void 0:`url(${h.background.get(r)})`;{let c=await W(r,{useProxy:e.useProxy});return h.background.set(r,c),e.skipInline?void 0:`url("${c}")`}}return t}function q(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 n=h.computedStyle.get(t);if(n||(n=new Map,h.computedStyle.set(t,n)),!n.has(e)){let i=window.getComputedStyle(t,e);n.set(e,i)}return n.get(e)}function Ct(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch{return e}return e}function X(t){let e=t.match(/url\((['"]?)(.*?)(\1)\)/);if(!e)return null;let n=e[2].trim();return n.startsWith("#")?null:n}async function V(t,{useProxy:e=""}={}){async function n(i){let r=await fetch(i);if(!r.ok)throw new Error(`[snapdom] Failed to fetch resource: ${i}`);return r}try{return await n(t)}catch(i){if(e&&typeof e=="string"){let r=e.replace(/\/$/,"")+G(t);return n(r)}throw i}}var j=new Map,at=new Map;function W(t,{timeout:e=3e3,useProxy:n="",errorTTL:i=8e3}={}){function r(u){try{return new URL(u,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch{return"anonymous"}}let c=u=>({ok:!0,data:u}),a=u=>({ok:!1,error:u instanceof Error?u:new Error(String(u))});function f(u){try{return fetch(u,{mode:"cors",credentials:r(u)==="use-credentials"?"include":"omit"}).then(g=>g.ok?g.blob().then(b=>new Promise(p=>{let w=new FileReader;w.onloadend=()=>{let S=w.result;typeof S!="string"||!S.startsWith("data:image/")?p(a(new Error("Invalid image data URL"))):p(c(S))},w.onerror=()=>p(a(new Error("FileReader error"))),w.readAsDataURL(b)})):a(new Error("HTTP "+g.status))).catch(g=>a(g))}catch(g){return Promise.resolve(a(g))}}function o(u){return f(u).then(g=>{if(g.ok)return g;if(n&&typeof n=="string"){let b=n.replace(/\/$/,"")+G(u);return f(b).then(p=>p.ok?p:a(new Error("[SnapDOM - fetchImage] Fetch failed and no proxy provided")))}return a(new Error("[SnapDOM - fetchImage] Fetch failed and no proxy provided"))})}let l=Date.now(),s=at.get(t);if(s&&s>l){let u=Promise.reject(new Error("[SnapDOM - fetchImage] Recently failed (cooldown)."));return u.catch(()=>{}),u}if(j.has(t))return j.get(t);let d=r(t);if(h.image.has(t))return Promise.resolve(h.image.get(t));if(t.startsWith("data:image/"))return h.image.set(t,t),Promise.resolve(t);if(/\.svg(\?.*)?$/i.test(t)){let u=(async()=>{let g=await(async()=>{try{let p=await fetch(t,{mode:"cors",credentials:d==="use-credentials"?"include":"omit"});if(!p.ok)return a(new Error("HTTP "+p.status));let w=await p.text();return c(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(w)}`)}catch(p){return a(p)}})();if(g.ok)return h.image.set(t,g.data),g.data;let b=await o(t);return b.ok?(h.image.set(t,b.data),b.data):(at.set(t,l+i),Promise.reject(b.error))})();return j.set(t,u),u.finally(()=>j.delete(t)),u.catch(()=>{}),u}let m=new Promise((u,g)=>{let b=!1,p=new Image,w=y=>k=>{b||(b=!0,clearTimeout(R),p.onload=p.onerror=null,y(k))},S=y=>{h.image.set(t,y),u(y)},x=y=>{at.set(t,Date.now()+i),g(y)},R=setTimeout(w(()=>{o(t).then(y=>{y.ok?S(y.data):x(new Error("Image load timed out"))})}),e);p.crossOrigin=d,p.onload=w(()=>{Promise.resolve(p.decode()).then(()=>{try{let y=document.createElement("canvas");y.width=p.naturalWidth||p.width,y.height=p.naturalHeight||p.height,y.getContext("2d").drawImage(p,0,0,y.width,y.height),S(y.toDataURL("image/png"))}catch{o(t).then(y=>{y.ok?S(y.data):x(y.error)})}}).catch(()=>{o(t).then(y=>{y.ok?S(y.data):x(y.error)})})}),p.onerror=w(()=>{o(t).then(y=>{y.ok?S(y.data):x(y.error)})}),p.src=t});return j.set(t,m),m.finally(()=>j.delete(t)),m.catch(()=>{}),m}function st(t){let e={};for(let n of t)e[n]=t.getPropertyValue(n);return e}function vt(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Et(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(n,i)=>{let r=i.split(",").map(c=>c.trim());return r.length!==6?`matrix(${i})`:(r[4]="0",r[5]="0",`matrix(${r.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(n,i)=>{let r=i.split(",").map(c=>c.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{return t}}function H(t){let e=[],n=0,i=0;for(let r=0;r<t.length;r++){let c=t[r];c==="("&&n++,c===")"&&n--,c===","&&n===0&&(e.push(t.slice(i,r).trim()),i=r+1)}return e.push(t.slice(i).trim()),e}var it=new WeakMap,ct=new Map;function Ot(t){let e={},n=t.getPropertyValue("visibility");for(let i=0;i<t.length;i++){let r=t[i],c=t.getPropertyValue(r);(r==="background-image"||r==="content")&&c.includes("url(")&&!c.includes("data:")&&(c="none"),e[r]=c}return n==="hidden"&&(e.opacity="0"),e}function et(t,e,n,i,r){if(t.tagName==="STYLE")return;i.has(t)||i.set(t,U(t));let c=i.get(t);if(!it.has(t)){let s=Ot(c);it.set(t,s)}let a=it.get(t),f=Object.entries(a).sort(([s],[d])=>s.localeCompare(d)).map(([s,d])=>`${s}:${d}`).join(";");if(ct.has(f)){n.set(e,ct.get(f));return}let o=t.tagName?.toLowerCase()||"div",l=K(a,o,r);ct.set(f,l),n.set(e,l)}function qt(t,e){try{let n=t.currentSrc||t.src||"";if(!n)return;e.setAttribute("src",n),e.removeAttribute("srcset"),e.removeAttribute("sizes"),e.loading="eager",e.decoding="sync"}catch{}}function J(t,e,n,i,r,c={},a){if(!t)throw new Error("Invalid node");let f=new Set,o=null;if(t.nodeType===Node.TEXT_NODE||t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);if(t.getAttribute("data-capture")==="exclude"){let s=document.createElement("div"),d=t.getBoundingClientRect();return s.style.cssText=`display:inline-block;width:${d.width}px;height:${d.height}px;visibility:hidden;`,s}if(c.exclude&&Array.isArray(c.exclude))for(let s of c.exclude)try{if(t.matches?.(s)){let d=document.createElement("div"),m=t.getBoundingClientRect();return d.style.cssText=`display:inline-block;width:${m.width}px;height:${m.height}px;visibility:hidden;`,d}}catch(d){console.warn(`Invalid selector in exclude option: ${s}`,d)}if(typeof c.filter=="function")try{if(!c.filter(t,a||t)){let s=document.createElement("div"),d=t.getBoundingClientRect();return s.style.cssText=`display:inline-block;width:${d.width}px;height:${d.height}px;visibility:hidden;`,s}}catch(s){console.warn("Error in filter function:",s)}if(t.tagName==="IFRAME"){let s=document.createElement("div");return 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.getAttribute("data-capture")==="placeholder"){let s=t.cloneNode(!1);i.set(s,t),et(t,s,e,n,r);let d=document.createElement("div");return d.textContent=t.getAttribute("data-placeholder-text")||"",d.style.cssText="color:#666;font-size:12px;text-align:center;line-height:1.4;padding:0.5em;box-sizing:border-box;",s.appendChild(d),s}if(t.tagName==="CANVAS"){let s=t.toDataURL(),d=document.createElement("img");return d.src=s,d.width=t.width,d.height=t.height,i.set(d,t),et(t,d,e,n,r),d}let l;try{l=t.cloneNode(!1),i.set(l,t),t.tagName==="IMG"&&qt(t,l)}catch(s){throw console.error("[Snapdom] Failed to clone node:",t,s),s}if(t instanceof HTMLTextAreaElement){l.textContent=t.value,l.value=t.value;let s=t.getBoundingClientRect();return l.style.width=`${s.width}px`,l.style.height=`${s.height}px`,l}if(t instanceof HTMLInputElement&&(l.value=t.value,l.setAttribute("value",t.value),t.checked!==void 0&&(l.checked=t.checked,t.checked&&l.setAttribute("checked",""),t.indeterminate&&(l.indeterminate=t.indeterminate))),t instanceof HTMLSelectElement&&(o=t.value),et(t,l,e,n,r),t.shadowRoot)if(Array.from(t.shadowRoot.querySelectorAll("slot")).length>0){for(let d of t.shadowRoot.childNodes)if(d.nodeType===Node.ELEMENT_NODE&&d.tagName==="STYLE"){let m=d.textContent||"";m.trim()&&r&&n.set(d,m)}}else{let d=document.createDocumentFragment();for(let m of t.shadowRoot.childNodes){if(m.nodeType===Node.ELEMENT_NODE&&m.tagName==="STYLE"){let g=m.textContent||"";g.trim()&&r&&n.set(m,g);continue}let u=J(m,e,n,i,r,c,a||t);u&&d.appendChild(u)}l.appendChild(d)}if(t.tagName==="SLOT"){let s=t.assignedNodes?.({flatten:!0})||[],d=s.length>0?s:Array.from(t.childNodes),m=document.createDocumentFragment();for(let u of d){let g=J(u,e,n,i,r,c,a||t);g&&m.appendChild(g)}return m}for(let s of t.childNodes){if(f.has(s))continue;let d=J(s,e,n,i,r,c,a||t);d&&l.appendChild(d)}if(o!==null&&l instanceof HTMLSelectElement){l.value=o;for(let s of l.options)s.value===o?s.setAttribute("selected",""):s.removeAttribute("selected")}return l}var Vt=[/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],lt=[];function At(t){let e=Array.isArray(t)?t:[t];for(let n of e)n instanceof RegExp?lt.push(n):typeof n=="string"?lt.push(new RegExp(n,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",n)}function L(t){let e=typeof t=="string"?t:"",n=[...Vt,...lt];for(let i of n)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))}async function $t(t,e,n,i=32,r="#000"){e=e.replace(/^['"]+|['"]+$/g,"");let c=window.devicePixelRatio||1;await document.fonts.ready;let a=document.createElement("span");a.textContent=t,a.style.position="absolute",a.style.visibility="hidden",a.style.fontFamily=`"${e}"`,a.style.fontWeight=n||"normal",a.style.fontSize=`${i}px`,a.style.lineHeight="1",a.style.whiteSpace="nowrap",a.style.padding="0",a.style.margin="0",document.body.appendChild(a);let f=a.getBoundingClientRect(),o=Math.ceil(f.width),l=Math.ceil(f.height);document.body.removeChild(a);let s=document.createElement("canvas");s.width=o*c,s.height=l*c;let d=s.getContext("2d");return d.scale(c,c),d.font=n?`${n} ${i}px "${e}"`:`${i}px "${e}"`,d.textAlign="left",d.textBaseline="top",d.fillStyle=r,d.fillText(t,0,0),{dataUrl:s.toDataURL(),width:o,height:l}}function kt(t){return Array.from(document.styleSheets).some(e=>e.href===t)}function Ht(t){return new Promise(e=>{if(kt(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 nt({preCached:t=!1,localFonts:e=[],useProxy:n=""}={}){if(h.resource.has("fonts-embed-css")){if(t){let o=document.createElement("style");o.setAttribute("data-snapdom","embedFonts"),o.textContent=h.resource.get("fonts-embed-css"),document.head.appendChild(o)}return h.resource.get("fonts-embed-css")}let i=new Set;try{for(let o of document.fonts)o.status==="loaded"&&i.add(`${o.family}__${o.weight||"normal"}__${o.style||"normal"}`)}catch{}let r=/@import\s+url\(["']?([^"')]+)["']?\)/g,c=[];for(let o of document.querySelectorAll("style")){let l=o.textContent||"",s=Array.from(l.matchAll(r));for(let d of s){let m=d[1];L(m)||kt(m)||c.push(m)}}await Promise.all(c.map(Ht));let a=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(o=>o.href),f="";for(let o of a)try{let s=await(await V(o.href,{useProxy:n})).text();if(L(o.href)||L(s))continue;let d=/@font-face[^{}]*{[^}]*}/g,m=s;for(let u of s.match(d)||[]){let g=u.match(/font-family:\s*([^;]+);/i);if(!g)continue;let b=g[1].replace(/['"]/g,"").trim(),p=u.match(/font-weight:\s*([^;]+);/i),w=u.match(/font-style:\s*([^;]+);/i),S=p?p[1].trim():"normal",x=w?w[1].trim():"normal",R=`${b}__${S}__${x}`,y=/url\((["']?)([^"')]+)\1\)/g,k=/url\(/i.test(u),C=/local\(/i.test(u);if(!k&&C)continue;if(!i.has(R)){m=m.replace(u,"");continue}let A=u,P=Array.from(u.matchAll(y));for(let N of P){let T=X(N[0]);if(!T)continue;let v=T;if(!v.startsWith("http")&&!v.startsWith("data:")&&(v=new URL(v,o.href).href),!L(v)){if(h.resource.has(v)){h.font.add(v),A=A.replace(N[0],`url(${h.resource.get(v)})`);continue}if(!h.font.has(v))try{let B=await(await V(v,{useProxy:n})).blob(),Y=await new Promise($=>{let M=new FileReader;M.onload=()=>$(M.result),M.readAsDataURL(B)});h.resource.set(v,Y),h.font.add(v),A=A.replace(N[0],`url(${Y})`)}catch{console.warn("[snapdom] Failed to fetch font resource:",v)}}}m=m.replace(u,A)}f+=m+`
3
+ `}catch{console.warn("[snapdom] Failed to fetch CSS:",o.href)}for(let o of document.styleSheets)try{if(!o.href||a.every(l=>l.href!==o.href)){for(let l of o.cssRules)if(l.type===CSSRule.FONT_FACE_RULE){let s=l.style.getPropertyValue("src"),d=l.style.getPropertyValue("font-family");if(!s||L(d))continue;let m=l.style.getPropertyValue("font-weight")||"normal",u=l.style.getPropertyValue("font-style")||"normal",g=`${d}__${m}__${u}`,b=/url\((["']?)([^"')]+)\1\)/g,p=/local\((["']?)[^)]+?\1\)/g,w=!!s.match(b),S=!!s.match(p);if(!w&&S){f+=`@font-face{font-family:${d};src:${s};font-style:${u};font-weight:${m};}`;continue}if(!i.has(g))continue;let x=s,R=Array.from(s.matchAll(b));for(let y of R){let k=y[2].trim();if(!k)continue;let C=k;if(!C.startsWith("http")&&!C.startsWith("data:")&&(C=new URL(C,o.href||location.href).href),!L(C)){if(h.resource.has(C)){h.font.add(C),x=x.replace(y[0],`url(${h.resource.get(C)})`);continue}if(!h.font.has(C))try{let P=await(await V(C,{useProxy:n})).blob(),N=await new Promise(T=>{let v=new FileReader;v.onload=()=>T(v.result),v.readAsDataURL(P)});h.resource.set(C,N),h.font.add(C),x=x.replace(y[0],`url(${N})`)}catch{console.warn("[snapdom] Failed to fetch font URL:",C)}}}f+=`@font-face{font-family:${d};src:${x};font-style:${u};font-weight:${m};}`}}}catch(l){console.warn("[snapdom] Cannot access stylesheet",o.href,l)}for(let o of document.fonts)if(o.family&&o.status==="loaded"&&o._snapdomSrc){if(L(o.family))continue;let l=o._snapdomSrc;if(!l.startsWith("data:")){if(h.resource.has(o._snapdomSrc))l=h.resource.get(o._snapdomSrc),h.font.add(o._snapdomSrc);else if(!h.font.has(o._snapdomSrc))try{let d=await(await V(o._snapdomSrc,{useProxy:n})).blob();l=await new Promise(m=>{let u=new FileReader;u.onload=()=>m(u.result),u.readAsDataURL(d)}),h.resource.set(o._snapdomSrc,l),h.font.add(o._snapdomSrc)}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",o._snapdomSrc);continue}}f+=`@font-face{font-family:'${o.family}';src:url(${l});font-style:${o.style||"normal"};font-weight:${o.weight||"normal"};}`}for(let o of e){if(!o||typeof o!="object")continue;let{family:l,src:s,weight:d="normal",style:m="normal"}=o;if(!l||!s)continue;let u=s;if(u.startsWith("data:"))h.resource.set(s,u),h.font.add(s);else try{let b=await(await V(s,{useProxy:n})).blob();u=await new Promise(p=>{let w=new FileReader;w.onload=()=>p(w.result),w.readAsDataURL(b)}),h.resource.set(s,u),h.font.add(s)}catch{console.warn("[snapdom] Failed to load local font:",s);continue}f+=`@font-face{font-family:'${l}';src:url(${u});font-style:${m};font-weight:${d};}`}if(f&&(h.resource.set("fonts-embed-css",f),t)){let o=document.createElement("style");o.setAttribute("data-snapdom","embedFonts"),o.textContent=f,document.head.appendChild(o)}return f}async function ft(t,e,n,i,r){if(!(t instanceof Element)||!(e instanceof Element))return;for(let f of["::before","::after","::first-letter"])try{let o=U(t,f);if(!o||typeof o[Symbol.iterator]!="function"||o.content==="none"&&o.backgroundImage==="none"&&o.backgroundColor==="transparent"&&(o.borderStyle==="none"||parseFloat(o.borderWidth)===0)&&(!o.transform||o.transform==="none")&&o.display==="inline")continue;if(f==="::first-letter"){let I=getComputedStyle(t);if(!(o.color!==I.color||o.fontSize!==I.fontSize||o.fontWeight!==I.fontWeight))continue;let D=Array.from(e.childNodes).find(pt=>pt.nodeType===Node.TEXT_NODE&&pt.textContent?.trim().length>0);if(!D)continue;let _=D.textContent,Z=_.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],Ut=_.slice(Z?.length||0);if(!Z||/[\uD800-\uDFFF]/.test(Z))continue;let tt=document.createElement("span");tt.textContent=Z,tt.dataset.snapdomPseudo="::first-letter";let Mt=st(o),Dt=K(Mt,"span",r);n.set(tt,Dt);let gt=document.createTextNode(Ut);e.replaceChild(gt,D),e.insertBefore(tt,gt);continue}let s=o.content,d=/counter\s*\(|counters\s*\(/.test(s)?"- ":Ct(s),m=o.backgroundImage,u=o.backgroundColor,g=o.fontFamily,b=parseInt(o.fontSize)||32,p=parseInt(o.fontWeight)||!1,w=o.color||"#000",S=o.display,x=parseFloat(o.width),R=parseFloat(o.height),y=o.borderStyle,k=parseFloat(o.borderWidth),C=o.transform,A=L(g),P=s!=="none"&&d!=="",N=m&&m!=="none",T=u&&u!=="transparent"&&u!=="rgba(0, 0, 0, 0)",v=S!=="inline"&&(x>0||R>0),z=y&&y!=="none"&&k>0,B=C&&C!=="none";if(!(P||N||T||v||z||B))continue;let $=document.createElement("span");$.dataset.snapdomPseudo=f,$.style.verticalAlign="middle";let M=st(o),rt=K(M,"span",r);if(n.set($,rt),A&&d.length===1){let{dataUrl:I,width:F,height:D}=await $t(d,g,p,b,w),_=document.createElement("img");_.src=I,_.style=`height:${b}px;width:${F/D*b}px;object-fit:contain;`,$.appendChild(_),e.dataset.snapdomHasIcon="true"}else if(d.startsWith("url(")){let I=X(d);if(I?.trim())try{let F=document.createElement("img"),D=await W(G(I),r);F.src=D,F.style=`width:${b}px;height:auto;object-fit:contain;`,$.appendChild(F)}catch(F){console.error(`[snapdom] Error in pseudo ${f} for`,t,F)}}else!A&&P&&($.textContent=d);if(N)try{let I=H(m),F=await Promise.all(I.map(O));$.style.backgroundImage=F.join(", ")}catch(I){console.warn(`[snapdom] Failed to inline background-image for ${f}`,I)}if(T&&($.style.backgroundColor=u),!($.childNodes.length>0||$.textContent?.trim()!==""||N||T||v||z||B))continue;f==="::before"?e.insertBefore($,e.firstChild):e.appendChild($)}catch(o){console.warn(`[snapdom] Failed to capture ${f} for`,t,o)}let c=Array.from(t.children),a=Array.from(e.children).filter(f=>!f.dataset.snapdomPseudo);for(let f=0;f<Math.min(c.length,a.length);f++)await ft(c[f],a[f],n,i,r)}function It(t){if(!t)return;let e=new Set;if(t.querySelectorAll("use").forEach(f=>{let o=f.getAttribute("xlink:href")||f.getAttribute("href");o&&o.startsWith("#")&&e.add(o.slice(1))}),!e.size)return;let n=Array.from(document.querySelectorAll("svg > symbol, svg > defs")),i=n.filter(f=>f.tagName.toLowerCase()==="symbol"),r=n.filter(f=>f.tagName.toLowerCase()==="defs"),c=t.querySelector("svg.inline-defs-container");c||(c=document.createElementNS("http://www.w3.org/2000/svg","svg"),c.setAttribute("aria-hidden","true"),c.setAttribute("style","position: absolute; width: 0; height: 0; overflow: hidden;"),c.classList.add("inline-defs-container"),t.insertBefore(c,t.firstChild));let a=new Set;t.querySelectorAll("symbol[id], defs > *[id]").forEach(f=>{a.add(f.id)}),e.forEach(f=>{if(a.has(f))return;let o=i.find(l=>l.id===f);if(o){c.appendChild(o.cloneNode(!0)),a.add(f);return}for(let l of r){let s=l.querySelector(`#${CSS.escape(f)}`);if(s){let d=c.querySelector("defs");d||(d=document.createElementNS("http://www.w3.org/2000/svg","defs"),c.appendChild(d)),d.appendChild(s.cloneNode(!0)),a.add(f);break}}})}async function Nt(t,e=!1,n=!1,i={}){let r=new Map,c=new WeakMap,a=new Map,f,o="";zt(t);try{It(t)}catch(l){console.warn("inlineExternal defs or symbol failed:",l)}try{f=J(t,r,c,a,e,i,t)}catch(l){throw console.warn("deepClone failed:",l),l}try{await ft(t,f,r,c,e,n,i.useProxy)}catch(l){console.warn("inlinePseudoElements failed:",l)}if(await Gt(f),e){let l=xt(r);o=Array.from(l.entries()).map(([s,d])=>`.${d}{${s}}`).join("");for(let[s,d]of r.entries()){if(s.tagName==="STYLE")continue;if(s.getRootNode&&s.getRootNode()instanceof ShadowRoot){s.setAttribute("style",d.replace(/;/g,"; "));continue}let m=l.get(d);m&&s.classList.add(m);let u=s.style?.backgroundImage,g=s.dataset?.snapdomHasIcon;u&&u!=="none"&&(s.style.backgroundImage=u),g&&(s.style.verticalAlign="middle",s.style.display="inline")}}else for(let[l,s]of r.entries())l.tagName!=="STYLE"&&l.setAttribute("style",s.replace(/;/g,"; "));for(let[l,s]of a.entries()){let d=s.scrollLeft,m=s.scrollTop;if((d||m)&&l instanceof HTMLElement){l.style.overflow="hidden",l.style.scrollbarWidth="none",l.style.msOverflowStyle="none";let g=document.createElement("div");for(g.style.transform=`translate(${-d}px, ${-m}px)`,g.style.willChange="transform",g.style.display="inline-block",g.style.width="100%";l.firstChild;)g.appendChild(l.firstChild);l.appendChild(g)}}if(t===a.get(f)){let l=c.get(t)||window.getComputedStyle(t);c.set(t,l);let s=Et(l.transform);f.style.margin="0",f.style.position="static",f.style.top="auto",f.style.left="auto",f.style.right="auto",f.style.bottom="auto",f.style.zIndex="auto",f.style.float="none",f.style.clear="none",f.style.transform=s||""}for(let[l,s]of a.entries())s.tagName==="PRE"&&(l.style.marginTop="0",l.style.marginBlockStart="0");return{clone:f,classCSS:o,styleCache:c}}function zt(t){let e=getComputedStyle(t),n=e.outlineStyle,i=e.outlineWidth,r=e.borderStyle,c=e.borderWidth,a=n!=="none"&&parseFloat(i)>0,f=r==="none"||parseFloat(c)===0;a&&f&&(t.style.border=`${i} solid transparent`)}var dt=new Map;async function Q(t){if(dt.has(t))return dt.get(t);let e=await fetch(t);if(!e.ok)throw new Error(`[SnapDOM] HTTP ${e.status} on blob fetch (${t})`);let n=await e.blob(),i=await new Promise((r,c)=>{let a=new FileReader;a.onloadend=()=>{let f=a.result;typeof f=="string"&&f.startsWith("data:")?r(f):c(new Error("[SnapDOM] Invalid data URL from blob"))},a.onerror=()=>c(new Error("[SnapDOM] FileReader error")),a.readAsDataURL(n)});return dt.set(t,i),i}var Yt=/\bblob:[^)"'\s]+/g;async function Rt(t){if(!t||t.indexOf("blob:")===-1)return t;let e=Array.from(new Set(t.match(Yt)||[]));if(e.length===0)return t;let n=t;for(let i of e)try{let r=await Q(i);n=n.split(i).join(r)}catch{}return n}function ot(t){return typeof t=="string"&&t.startsWith("blob:")}function Kt(t){return(t||"").split(",").map(e=>e.trim()).filter(Boolean).map(e=>{let n=e.match(/^(\S+)(\s+.+)?$/);return n?{url:n[1],desc:n[2]||""}:null}).filter(Boolean)}function Xt(t){return t.map(e=>e.desc?`${e.url} ${e.desc.trim()}`:e.url).join(", ")}async function Gt(t){if(!t)return;let e=t.querySelectorAll?t.querySelectorAll("img"):[];for(let a of e)try{let o=a.getAttribute("src")||a.currentSrc||"";if(ot(o)){let s=await Q(o);a.setAttribute("src",s)}let l=a.getAttribute("srcset");if(l&&l.includes("blob:")){let s=Kt(l),d=!1;for(let m of s)if(ot(m.url))try{m.url=await Q(m.url),d=!0}catch{}d&&a.setAttribute("srcset",Xt(s))}}catch{}let n=t.querySelectorAll?t.querySelectorAll("image"):[];for(let a of n)try{let f="http://www.w3.org/1999/xlink",o=a.getAttribute("href")||a.getAttributeNS?.(f,"href");if(ot(o)){let l=await Q(o);a.setAttribute("href",l),a.removeAttributeNS?.(f,"href")}}catch{}let i=t.querySelectorAll?t.querySelectorAll("[style*='blob:']"):[];for(let a of i)try{let f=a.getAttribute("style");if(f&&f.includes("blob:")){let o=await Rt(f);a.setAttribute("style",o)}}catch{}let r=t.querySelectorAll?t.querySelectorAll("style"):[];for(let a of r)try{let f=a.textContent||"";f.includes("blob:")&&(a.textContent=await Rt(f))}catch{}let c=["poster"];for(let a of c){let f=t.querySelectorAll?t.querySelectorAll(`[${a}^='blob:']`):[];for(let o of f)try{let l=o.getAttribute(a);ot(l)&&o.setAttribute(a,await Q(l))}catch{}}}async function Tt(t,e={}){let n=Array.from(t.querySelectorAll("img")),i=async r=>{if(!r.getAttribute("src")){let a=r.currentSrc||r.src||"";a&&r.setAttribute("src",a)}r.removeAttribute("srcset"),r.removeAttribute("sizes");let c=r.src;try{let a=await W(c,{useProxy:e.useProxy});r.src=a,r.width||(r.width=r.naturalWidth||100),r.height||(r.height=r.naturalHeight||100)}catch{let a=document.createElement("div");a.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;`,a.innerText="img",r.replaceWith(a)}};for(let r=0;r<n.length;r+=4){let c=n.slice(r,r+4).map(i);await Promise.allSettled(c)}}async function Ft(t,e,n,i={}){let r=[[t,e]],c=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source","border-image","border-image-source","border-image-slice","border-image-width","border-image-outset","border-image-repeat"];for(;r.length;){let[a,f]=r.shift(),o=n.get(a)||U(a);n.has(a)||n.set(a,o);let l=(()=>{let u=o.getPropertyValue("border-image"),g=o.getPropertyValue("border-image-source");return u&&u!=="none"||g&&g!=="none"})();for(let u of c){if(["border-image-slice","border-image-width","border-image-outset","border-image-repeat"].includes(u)&&!l)continue;let g=o.getPropertyValue(u);if(!g||g==="none")continue;let b=H(g),p=await Promise.all(b.map(w=>O(w,i)));p.some(w=>w&&w!=="none"&&!/^url\(undefined/.test(w))&&f.style.setProperty(u,p.join(", "))}let s=o.getPropertyValue("background-color");s&&s!=="transparent"&&s!=="rgba(0, 0, 0, 0)"&&(f.style.backgroundColor=s);let d=Array.from(a.children),m=Array.from(f.children);for(let u=0;u<Math.min(d.length,m.length);u++)r.push([d[u],m[u]])}}async function Lt(t,e={}){if(!t)throw new Error("Element cannot be null or undefined");h.reset();let{compress:n=!0,embedFonts:i=!1,fast:r=!0,scale:c=1,useProxy:a="",localFonts:f=[]}=e,o,l,s,d="",m="",u,g;if({clone:o,classCSS:l,styleCache:s}=await Nt(t,n,i,e),await new Promise(p=>{q(async()=>{await Tt(o,e),p()},{fast:r})}),await new Promise(p=>{q(async()=>{await Ft(t,o,s,e),p()},{fast:r})}),i&&await new Promise(p=>{q(async()=>{d=await nt({localFonts:f,useProxy:a}),p()},{fast:r})}),n){let p=bt(o).sort(),w=p.join(",");h.baseStyle.has(w)?m=h.baseStyle.get(w):await new Promise(S=>{q(()=>{m=St(p),h.baseStyle.set(w,m),S()},{fast:r})})}await new Promise(p=>{q(()=>{let w=t.getBoundingClientRect(),S=w.width,x=w.height,R=Number.isFinite(e.width),y=Number.isFinite(e.height),k=typeof c=="number"&&c!==1;if(!k){let B=w.width/w.height;R&&y?(S=e.width,x=e.height):R?(S=e.width,x=S/B):y&&(x=e.height,S=x*B)}if(S=Math.ceil(S),x=Math.ceil(x),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="top left",!k&&(R||y)){let B=w.width,Y=w.height,$=S/B,M=x/Y,rt=o.style.transform||"",ht=`scale(${$}, ${M})`;o.style.transform=`${ht} ${rt}`.trim()}let C="http://www.w3.org/2000/svg",A=document.createElementNS(C,"foreignObject");A.setAttribute("width","100%"),A.setAttribute("height","100%");let P=document.createElement("style");P.textContent=m+d+"svg{overflow:visible;}"+l,A.appendChild(P),A.appendChild(o);let T=new XMLSerializer().serializeToString(A);g=`<svg xmlns="${C}" width="${S}" height="${x}" viewBox="0 0 ${S} ${x}">`+T+"</svg>",u=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(g)}`,p()},{fast:r})});let b=document.getElementById("snapdom-sandbox");return b&&b.style.position==="absolute"&&b.remove(),u}async function Jt(t,{scale:e=1}={}){let n=new Image;return n.src=t,await n.decode(),e!==1&&(n.style.width=`${n.naturalWidth*e}px`,n.style.height=`${n.naturalHeight*e}px`),n}async function Pt(t,{dpr:e=1,scale:n=1}={}){let i=new Image;i.src=t,i.crossOrigin="anonymous",i.loading="eager",i.decoding="sync";let r=vt(),c=!1;if(r&&(document.body.appendChild(i),c=!0),await i.decode(),r&&await new Promise(s=>setTimeout(s,100)),i.width===0||i.height===0)throw c&&i.remove(),new Error("Image failed to load or has no dimensions");let a=i.naturalWidth*n,f=i.naturalHeight*n,o=document.createElement("canvas");o.width=Math.ceil(a*e),o.height=Math.ceil(f*e),o.style.width=`${a}px`,o.style.height=`${f}px`;let l=o.getContext("2d");return l.scale(e,e),l.drawImage(i,0,0,a,f),c&&i.remove(),o}async function Bt(t,{type:e="svg",scale:n=1,backgroundColor:i="#fff",quality:r}={}){let c={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[e]||"image/png";if(e==="svg"){let f=decodeURIComponent(t.split(",")[1]);return new Blob([f],{type:"image/svg+xml"})}let a=await mt(t,{dpr:1,scale:n},i);return new Promise(f=>{a.toBlob(o=>f(o),`${c}`,r)})}async function mt(t,{dpr:e=1,scale:n=1},i){let r=await Pt(t,{dpr:e,scale:n});if(!i)return r;let c=document.createElement("canvas");c.width=r.width,c.height=r.height;let a=c.getContext("2d");return a.fillStyle=i,a.fillRect(0,0,c.width,c.height),a.drawImage(r,0,0),c}async function ut(t,{dpr:e=1,scale:n=1,backgroundColor:i,quality:r},c="png"){let a=["jpg","jpeg","webp"].includes(c)?"#fff":void 0,o=await mt(t,{dpr:e,scale:n},i??a),l=new Image;return l.src=o.toDataURL(`image/${c}`,r),await l.decode(),l.style.width=`${o.width/e}px`,l.style.height=`${o.height/e}px`,l}async function Qt(t,{dpr:e=1,scale:n=1,backgroundColor:i,format:r="png",filename:c="snapDOM"}={}){if(r==="svg"){let m=await Bt(t),u=URL.createObjectURL(m),g=document.createElement("a");g.href=u,g.download=`${c}.svg`,g.click(),URL.revokeObjectURL(u);return}let a=["jpg","jpeg","webp"].includes(r)?"#fff":void 0,o=await mt(t,{dpr:e,scale:n},i??a),l={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[r]||"image/png",s=o.toDataURL(l),d=document.createElement("a");d.href=s,d.download=`${c}.${r}`,d.click()}async function E(t,e={}){if(e={scale:1,...e},!t)throw new Error("Element cannot be null or undefined");return e.iconFonts&&At(e.iconFonts),await E.capture(t,e)}E.capture=async(t,e={})=>{let n=await Lt(t,e),i=e.dpr??(window.devicePixelRatio||1),r=e.scale||1;return{url:n,options:e,toRaw:()=>n,toImg:(c={})=>Jt(n,{dpr:i,scale:r,...c}),toCanvas:(c={})=>Pt(n,{dpr:i,scale:r,...c}),toBlob:(c={})=>Bt(n,{dpr:i,scale:r,...c}),toPng:(c={})=>ut(n,{dpr:i,scale:r,...c},"png"),toJpg:(c={})=>ut(n,{dpr:i,scale:r,...c},"jpeg"),toWebp:(c={})=>ut(n,{dpr:i,scale:r,...c},"webp"),download:({format:c="png",filename:a="snapDOM",backgroundColor:f,...o}={})=>Qt(n,{dpr:i,scale:r,format:c,filename:a,backgroundColor:f,...o})}};E.toRaw=async(t,e)=>(await E.capture(t,e)).toRaw();E.toImg=async(t,e)=>(await E.capture(t,e)).toImg();E.toCanvas=async(t,e)=>(await E.capture(t,e)).toCanvas();E.toBlob=async(t,e)=>(await E.capture(t,e)).toBlob(e);E.toPng=async(t,e)=>(await E.capture(t,e)).toPng(e);E.toJpg=async(t,e)=>(await E.capture(t,e)).toJpg(e);E.toWebp=async(t,e)=>(await E.capture(t,e)).toWebp(e);E.download=async(t,e={})=>{let{format:n="png",filename:i="capture",backgroundColor:r,...c}=e;return await(await E.capture(t,c)).download({format:n,filename:i,backgroundColor:r})};async function Zt(t=document,e={}){let{embedFonts:n=!0,reset:i=!1,useProxy:r}=e;if(i){h.image.clear(),h.background.clear(),h.resource.clear(),h.defaultStyle.clear(),h.baseStyle.clear(),h.font.clear(),h.computedStyle=new WeakMap;return}try{await document.fonts.ready}catch{}yt();let c=[],a=[];t?.querySelectorAll&&(c=Array.from(t.querySelectorAll("img[src]")),a=Array.from(t.querySelectorAll("*")));let f=[];for(let o of c){let l=o?.src;if(l&&!h.image.has(l)){let s=Promise.resolve().then(()=>W(l,{useProxy:r})).then(d=>{h.image.set(l,d)}).catch(()=>{});f.push(s)}}for(let o of a){let l="";try{l=U(o).backgroundImage}catch{}if(l&&l!=="none"){let s=H(l);for(let d of s)if(d.startsWith("url(")){let m=Promise.resolve().then(()=>O(d,{...e,useProxy:r})).catch(()=>{});f.push(m)}}}if(n)try{await nt({preCached:!0,localFonts:e.localFonts,useProxy:e.useProxy})}catch{}await Promise.allSettled(f)}export{Zt as preCache,E as snapdom};