@zumer/snapdom 1.9.9 → 1.9.10-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -84
- package/dist/snapdom.js +1511 -805
- package/dist/snapdom.min.js +5 -3
- package/dist/snapdom.min.mjs +5 -3
- package/dist/snapdom.mjs +1484 -759
- package/package.json +1 -1
- package/types/snapdom.d.ts +171 -60
package/dist/snapdom.min.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
(()=>{var
|
|
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
|
+
(()=>{var ke=Object.defineProperty,Fe=Object.defineProperties;var ve=Object.getOwnPropertyDescriptors;var ee=Object.getOwnPropertySymbols;var Le=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable;var ne=(t,e,n)=>e in t?ke(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,H=(t,e)=>{for(var n in e||(e={}))Le.call(e,n)&&ne(t,n,e[n]);if(ee)for(var n of ee(e))Re.call(e,n)&&ne(t,n,e[n]);return t},X=(t,e)=>Fe(t,ve(e));var C=(t,e,n)=>new Promise((o,r)=>{var s=i=>{try{l(n.next(i))}catch(u){r(u)}},a=i=>{try{l(n.throw(i))}catch(u){r(u)}},l=i=>i.done?o(i.value):Promise.resolve(i.value).then(s,a);l((n=n.apply(t,e)).next())});var m={image:new Map,background:new Map,resource:new Map,defaultStyle:new Map,baseStyle:new Map,computedStyle:new WeakMap,font:new Set,session:{styleMap:new Map,styleCache:new WeakMap,nodeMap:new Map}};function At(t="soft"){switch(t){case"auto":{m.session.styleMap=new Map,m.session.nodeMap=new Map;return}case"soft":{m.session.styleMap=new Map,m.session.nodeMap=new Map,m.session.styleCache=new WeakMap;return}case"full":return;case"disabled":{m.session.styleMap=new Map,m.session.nodeMap=new Map,m.session.styleCache=new WeakMap,m.image.clear(),m.background.clear(),m.resource.clear(),m.font.clear();return}default:{m.session.styleMap=new Map,m.session.nodeMap=new Map,m.session.styleCache=new WeakMap;return}}}function at(t){let e=t.match(/url\((['"]?)(.*?)(\1)\)/);if(!e)return null;let n=e[2].trim();return n.startsWith("#")?null:n}function Wt(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(n,o)=>{let r=o.split(",").map(s=>s.trim());return r.length!==6?`matrix(${o})`:(r[4]="0",r[5]="0",`matrix(${r.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(n,o)=>{let r=o.split(",").map(s=>s.trim());return r.length!==16?`matrix3d(${o})`:(r[12]="0",r[13]="0",`matrix3d(${r.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function yt(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch(e){return t}}function Me(t="[snapDOM]",{ttlMs:e=5*6e4,maxEntries:n=12}={}){let o=new Map,r=0;function s(a,l,i){if(r>=n)return;let u=Date.now();(o.get(l)||0)>u||(o.set(l,u+e),r++,a==="warn"&&console&&console.warn?console.warn(`${t} ${i}`):console&&console.error&&console.error(`${t} ${i}`))}return{warnOnce(a,l){s("warn",a,l)},errorOnce(a,l){s("error",a,l)},reset(){o.clear(),r=0}}}var oe=Me("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),qt=new Map,$t=new Map;function Ne(t){return/^data:|^blob:|^about:blank$/.test(t)}function Te(t,e){if(!e||Ne(t))return!1;try{let n=typeof location!="undefined"&&location.href?location.href:"http://localhost/",o=new URL(t,n);return typeof location!="undefined"?o.origin!==location.origin:!0}catch(n){return!!e}}function Ie(t,e){if(!e)return t;if(e.includes("{url}"))return e.replace("{url}",encodeURIComponent(t));let n=e.endsWith("?")?"":e.includes("?")?"&":"?";return`${e}${n}url=${encodeURIComponent(t)}`}function _e(t){return new Promise((e,n)=>{let o=new FileReader;o.onload=()=>e(String(o.result||"")),o.onerror=()=>n(new Error("read_failed")),o.readAsDataURL(t)})}function Pe(t,e){var n,o;return[e.as||"blob",(n=e.timeout)!=null?n:3e3,e.useProxy||"",(o=e.errorTTL)!=null?o:8e3,t].join("|")}function D(n){return C(this,arguments,function*(t,e={}){var _,I,R;let o=(_=e.as)!=null?_:"blob",r=(I=e.timeout)!=null?I:3e3,s=e.useProxy||"",a=(R=e.errorTTL)!=null?R:8e3,l=e.headers||{},i=!!e.silent,u=Pe(t,{as:o,timeout:r,useProxy:s,errorTTL:a}),f=$t.get(u);if(f&&f.until>Date.now())return X(H({},f.result),{fromCache:!0});f&&$t.delete(u);let c=qt.get(u);if(c)return c;let h=Te(t,s)?Ie(t,s):t,S=e.credentials;if(!S)try{let W=typeof location!="undefined"&&location.href?location.href:"http://localhost/",P=new URL(t,W);S=typeof location!="undefined"&&P.origin===location.origin?"include":"omit"}catch(W){S="omit"}let $=new AbortController,w=setTimeout(()=>$.abort("timeout"),r),v=C(null,null,function*(){var W,P;try{let F=yield fetch(h,{signal:$.signal,credentials:S,headers:l});if(!F.ok){let z={ok:!1,data:null,status:F.status,url:h,fromCache:!1,reason:"http_error"};if($t.set(u,{until:Date.now()+a,result:z}),!i){let G=`${F.status} ${F.statusText||""}`.trim();oe.warnOnce(`http:${F.status}:${o}:${new URL(t,(W=location==null?void 0:location.href)!=null?W:"http://localhost/").origin}`,`HTTP error ${G} while fetching ${o} ${t}`)}return e.onError&&e.onError(z),z}if(o==="text")return{ok:!0,data:yield F.text(),status:F.status,url:h,fromCache:!1};let q=yield F.blob(),j=q.type||F.headers.get("content-type")||"";return o==="dataURL"?{ok:!0,data:yield _e(q),status:F.status,url:h,fromCache:!1,mime:j}:{ok:!0,data:q,status:F.status,url:h,fromCache:!1,mime:j}}catch(F){let q=F&&typeof F=="object"&&"name"in F&&F.name==="AbortError"?String(F.message||"").includes("timeout")?"timeout":"abort":"network",j={ok:!1,data:null,status:0,url:h,fromCache:!1,reason:q};if($t.set(u,{until:Date.now()+a,result:j}),!i){let z=`${q}:${o}:${new URL(t,(P=location==null?void 0:location.href)!=null?P:"http://localhost/").origin}`,G=q==="timeout"?`Timeout after ${r}ms. Consider increasing timeout or using a proxy for ${t}`:q==="abort"?`Request aborted while fetching ${o} ${t}`:`Network/CORS issue while fetching ${o} ${t}. A proxy may be required`;oe.errorOnce(z,G)}return e.onError&&e.onError(j),j}finally{clearTimeout(w),qt.delete(u)}});return qt.set(u,v),v})}function it(t,e){if(!e||!t.width||!t.height)return t;let n=document.createElement("canvas");n.width=t.width,n.height=t.height;let o=n.getContext("2d");return o.fillStyle=e,o.fillRect(0,0,n.width,n.height),o.drawImage(t,0,0),n}function ct(n){return C(this,arguments,function*(t,e={}){if(/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t)||t.trim()==="none")return t;let r=at(t);if(!r)return t;let s=yt(r);if(m.background.has(s)){let a=m.background.get(s);return a?`url("${a}")`:"none"}try{let a=yield D(s,{as:"dataURL",useProxy:e.useProxy});return a.ok?(m.background.set(s,a.data),`url("${a.data}")`):(m.background.set(s,null),"none")}catch(a){return m.background.set(s,null),"none"}})}var Et=new Set(["meta","script","noscript","title","link","template"]),ht=new Set(["meta","link","style","title","noscript","script","template","svg","g","defs","use","marker","mask","clipPath","pattern","path","polygon","polyline","line","circle","ellipse","rect","filter","lineargradient","radialgradient","stop"]),Ue=["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","table","thead","tbody","tr","td","th"];function Dt(){for(let t of Ue){let e=String(t).toLowerCase();Et.has(e)||ht.has(e)||jt(e)}}function jt(t){if(t=String(t).toLowerCase(),ht.has(t)){let s={};return m.defaultStyle.set(t,s),s}if(m.defaultStyle.has(t))return m.defaultStyle.get(t);let e=document.getElementById("snapdom-sandbox");e||(e=document.createElement("div"),e.id="snapdom-sandbox",e.setAttribute("data-snapdom-sandbox","true"),e.setAttribute("aria-hidden","true"),e.style.position="absolute",e.style.left="-9999px",e.style.top="-9999px",e.style.width="0px",e.style.height="0px",e.style.overflow="hidden",document.body.appendChild(e));let n=document.createElement(t);n.style.all="initial",e.appendChild(n);let o=getComputedStyle(n),r={};for(let s of o){if(re(s))continue;let a=o.getPropertyValue(s);r[s]=a}return e.removeChild(n),m.defaultStyle.set(t,r),r}var Be=/(?:^|-)(animation|transition)(?:-|$)/i,Oe=/^(--|view-timeline|scroll-timeline|animation-trigger|offset-|position-try|app-region|interactivity|overlay|view-transition|-webkit-locale|-webkit-user-(?:drag|modify)|-webkit-tap-highlight-color|-webkit-text-security)$/i,We=new Set(["cursor","pointer-events","touch-action","user-select","print-color-adjust","speak","reading-flow","reading-order","anchor-name","anchor-scope","container-name","container-type","timeline-scope"]);function re(t){let e=String(t).toLowerCase();return!!(We.has(e)||Oe.test(e)||Be.test(e))}function pt(t,e){if(e=String(e||"").toLowerCase(),ht.has(e))return"";let n=[],o=jt(e);for(let[r,s]of Object.entries(t)){if(re(r))continue;let a=o[r];s&&s!==a&&n.push(`${r}:${s}`)}return n.sort(),n.join(";")}function zt(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 Vt(t){let e=new Map;for(let o of t){let r=m.defaultStyle.get(o);if(!r)continue;let s=Object.entries(r).map(([a,l])=>`${a}:${l};`).sort().join("");s&&(e.has(s)||e.set(s,[]),e.get(s).push(o))}let n="";for(let[o,r]of e.entries())n+=`${r.join(",")} { ${o} }
|
|
2
|
+
`;return n}function Ht(t){let e=Array.from(new Set(t.values())).filter(Boolean).sort(),n=new Map,o=1;for(let r of e)n.set(r,`c${o++}`);return n}function lt(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let n=m.computedStyle.get(t);if(n||(n=new Map,m.computedStyle.set(t,n)),!n.has(e)){let o=window.getComputedStyle(t,e);n.set(e,o)}return n.get(e)}function Gt(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch(n){return e}return e}function kt(t){let e={};for(let n of t)e[n]=t.getPropertyValue(n);return e}function ft(t){let e=[],n=0,o=0;for(let r=0;r<t.length;r++){let s=t[r];s==="("&&n++,s===")"&&n--,s===","&&n===0&&(e.push(t.slice(o,r).trim()),o=r+1)}return e.push(t.slice(o).trim()),e}function ut(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function tt(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}var se=new WeakMap,ae=new Map,Kt=0;function Ft(){Kt++}var ie=!1;function qe(t=document.documentElement){var e,n;if(!ie){ie=!0;try{new MutationObserver(()=>Ft()).observe(t,{subtree:!0,childList:!0,characterData:!0,attributes:!0})}catch(o){}try{new MutationObserver(()=>Ft()).observe(document.head,{subtree:!0,childList:!0,characterData:!0,attributes:!0})}catch(o){}try{let o=document.fonts;o&&((e=o.addEventListener)==null||e.call(o,"loadingdone",Ft),(n=o.ready)==null||n.then(()=>Ft()).catch(()=>{}))}catch(o){}}}function De(t){let e={},n=t.getPropertyValue("visibility");for(let o=0;o<t.length;o++){let r=t[o],s=t.getPropertyValue(r);(r==="background-image"||r==="content")&&s.includes("url(")&&!s.includes("data:")&&(s="none"),e[r]=s}return n==="hidden"&&(e.opacity="0"),e}var ce=new WeakMap;function je(t){let e=ce.get(t);return e||(e=Object.entries(t).sort((o,r)=>o[0]<r[0]?-1:o[0]>r[0]?1:0).map(([o,r])=>`${o}:${r}`).join(";"),ce.set(t,e),e)}function ze(t,e=null){let n=se.get(t);if(n&&n.epoch===Kt)return n.snapshot;let o=e||getComputedStyle(t),r=De(o);return se.set(t,{epoch:Kt,snapshot:r}),r}function Ve(t,e){return t&&t.session&&t.persist?t:t&&(t.styleMap||t.styleCache||t.nodeMap)?{session:t,persist:{snapshotKeyCache:ae,defaultStyle:m.defaultStyle,baseStyle:m.baseStyle,image:m.image,resource:m.resource,background:m.background,font:m.font},options:e||{}}:{session:m.session,persist:{snapshotKeyCache:ae,defaultStyle:m.defaultStyle,baseStyle:m.baseStyle,image:m.image,resource:m.resource,background:m.background,font:m.font},options:t||e||{}}}function vt(t,e,n,o){return C(this,null,function*(){var h,S,$;if(t.tagName==="STYLE")return;let r=Ve(n,o);if((r.options&&r.options.cache||"auto")!=="disabled"&&qe(document.documentElement),ht.has((h=t.tagName)==null?void 0:h.toLowerCase())){let w=(S=t.getAttribute)==null?void 0:S.call(t,"style");w&&e.setAttribute("style",w)}let{session:a,persist:l}=r;a.styleCache.has(t)||a.styleCache.set(t,getComputedStyle(t));let i=a.styleCache.get(t),u=ze(t,i),f=je(u),c=l.snapshotKeyCache.get(f);if(!c){let w=(($=t.tagName)==null?void 0:$.toLowerCase())||"div";c=pt(u,w),l.snapshotKeyCache.set(f,c)}a.styleMap.set(e,c)})}function He(t){return t=t.trim(),!t||/\:not\(\s*\[data-sd-slotted\]\s*\)\s*$/.test(t)?t:`${t}:not([data-sd-slotted])`}function Ge(t,e,n=!0){return t.split(",").map(o=>o.trim()).filter(Boolean).map(o=>{if(o.startsWith(":where(")||o.startsWith("@"))return o;let r=n?He(o):o;return`:where(${e} ${r})`}).join(", ")}function Ke(t,e){return t?(t=t.replace(/:host\(([^)]+)\)/g,(n,o)=>`:where(${e}:is(${o.trim()}))`),t=t.replace(/:host\b/g,`:where(${e})`),t=t.replace(/:host-context\(([^)]+)\)/g,(n,o)=>`:where(:where(${o.trim()}) ${e})`),t=t.replace(/::slotted\(([^)]+)\)/g,(n,o)=>`:where(${e} ${o.trim()})`),t=t.replace(/(^|})(\s*)([^@}{]+){/g,(n,o,r,s)=>{let a=Ge(s,e,!0);return`${o}${r}${a}{`}),t):""}function Xe(t){return t.shadowScopeSeq=(t.shadowScopeSeq||0)+1,`s${t.shadowScopeSeq}`}function Ye(t){let e="";try{t.querySelectorAll("style").forEach(o=>{e+=(o.textContent||"")+`
|
|
3
|
+
`});let n=t.adoptedStyleSheets||[];for(let o of n)try{if(o&&o.cssRules)for(let r of o.cssRules)e+=r.cssText+`
|
|
4
|
+
`}catch(r){}}catch(n){}return e}function Je(t,e,n){if(!e)return;let o=document.createElement("style");o.setAttribute("data-sd",n),o.textContent=e,t.insertBefore(o,t.firstChild||null)}function Ze(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(n){}}function Qe(t){let e=new Set;if(!t)return e;let n=/var\(\s*(--[A-Za-z0-9_-]+)\b/g,o;for(;o=n.exec(t);)e.add(o[1]);return e}function tn(t,e){try{let o=getComputedStyle(t).getPropertyValue(e).trim();if(o)return o}catch(n){}try{let o=getComputedStyle(document.documentElement).getPropertyValue(e).trim();if(o)return o}catch(n){}return""}function en(t,e,n){let o=[];for(let r of e){let s=tn(t,r);s&&o.push(`${r}: ${s};`)}return o.length?`${n}{${o.join("")}}
|
|
5
|
+
`:""}function nn(t){t&&(t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-sd-slotted",""),t.querySelectorAll&&t.querySelectorAll("*").forEach(e=>e.setAttribute("data-sd-slotted","")))}function wt(t,e,n){var a,l,i,u,f;if(!t)throw new Error("Invalid node");let o=new Set,r=null;if(t.nodeType===Node.ELEMENT_NODE){let c=(t.localName||t.tagName||"").toLowerCase();if(t.id==="snapdom-sandbox"||t.hasAttribute("data-snapdom-sandbox")||Et.has(c))return null}if(t.nodeType===Node.TEXT_NODE||t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);if(t.getAttribute("data-capture")==="exclude"){let c=document.createElement("div"),h=t.getBoundingClientRect();return c.style.cssText=`display:inline-block;width:${h.width}px;height:${h.height}px;visibility:hidden;`,c}if(n.exclude&&Array.isArray(n.exclude))for(let c of n.exclude)try{if((a=t.matches)!=null&&a.call(t,c)){let h=document.createElement("div"),S=t.getBoundingClientRect();return h.style.cssText=`display:inline-block;width:${S.width}px;height:${S.height}px;visibility:hidden;`,h}}catch(h){console.warn(`Invalid selector in exclude option: ${c}`,h)}if(typeof n.filter=="function")try{if(!n.filter(t)){let c=document.createElement("div"),h=t.getBoundingClientRect();return c.style.cssText=`display:inline-block;width:${h.width}px;height:${h.height}px;visibility:hidden;`,c}}catch(c){console.warn("Error in filter function:",c)}if(t.tagName==="IFRAME"){let c=document.createElement("div");return c.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;`,c}if(t.getAttribute("data-capture")==="placeholder"){let c=t.cloneNode(!1);e.nodeMap.set(c,t),vt(t,c,e,n);let h=document.createElement("div");return h.textContent=t.getAttribute("data-placeholder-text")||"",h.style.cssText="color:#666;font-size:12px;text-align:center;line-height:1.4;padding:0.5em;box-sizing:border-box;",c.appendChild(h),c}if(t.tagName==="CANVAS"){let c=t.toDataURL(),h=document.createElement("img");return h.src=c,h.width=t.width,h.height=t.height,e.nodeMap.set(h,t),vt(t,h,e,n),h}let s;try{s=t.cloneNode(!1),e.nodeMap.set(s,t),t.tagName==="IMG"&&Ze(t,s)}catch(c){throw console.error("[Snapdom] Failed to clone node:",t,c),c}if(t instanceof HTMLTextAreaElement){s.textContent=t.value,s.value=t.value;let c=t.getBoundingClientRect();return s.style.width=`${c.width}px`,s.style.height=`${c.height}px`,s}if(t instanceof HTMLInputElement&&(s.value=t.value,s.setAttribute("value",t.value),t.checked!==void 0&&(s.checked=t.checked,t.checked&&s.setAttribute("checked",""),t.indeterminate&&(s.indeterminate=t.indeterminate))),t instanceof HTMLSelectElement&&(r=t.value),vt(t,s,e,n),t.shadowRoot){try{let I=t.shadowRoot.querySelectorAll("slot");for(let R of I){let W=[];try{W=((l=R.assignedNodes)==null?void 0:l.call(R,{flatten:!0}))||((i=R.assignedNodes)==null?void 0:i.call(R))||[]}catch(P){W=((u=R.assignedNodes)==null?void 0:u.call(R))||[]}for(let P of W)o.add(P)}}catch(I){}let c=Xe(e),h=`[data-sd="${c}"]`;try{s.setAttribute("data-sd",c)}catch(I){}let S=Ye(t.shadowRoot),$=Ke(S,h),w=Qe(S),v=en(t,w,h);Je(s,v+$,c);let _=document.createDocumentFragment();for(let I of t.shadowRoot.childNodes){if(I.nodeType===Node.ELEMENT_NODE&&I.tagName==="STYLE")continue;let R=wt(I,e,n);R&&_.appendChild(R)}s.appendChild(_)}if(t.tagName==="SLOT"){let c=((f=t.assignedNodes)==null?void 0:f.call(t,{flatten:!0}))||[],h=c.length>0?c:Array.from(t.childNodes),S=document.createDocumentFragment();for(let $ of h){let w=wt($,e,n);w&&(nn(w),S.appendChild(w))}return S}for(let c of t.childNodes){if(o.has(c))continue;let h=wt(c,e,n);h&&s.appendChild(h)}if(r!==null&&s instanceof HTMLSelectElement){s.value=r;for(let c of s.options)c.value===r?c.setAttribute("selected",""):c.removeAttribute("selected")}return s}var on=[/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],Xt=[];function le(t){let e=Array.isArray(t)?t:[t];for(let n of e)n instanceof RegExp?Xt.push(n):typeof n=="string"?Xt.push(new RegExp(n,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",n)}function Y(t){let e=typeof t=="string"?t:"",n=[...on,...Xt];for(let o of n)if(o instanceof RegExp&&o.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 fe(t,e,n,o=32,r="#000"){return C(this,null,function*(){e=e.replace(/^['"]+|['"]+$/g,"");let s=window.devicePixelRatio||1;yield 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=`${o}px`,a.style.lineHeight="1",a.style.whiteSpace="nowrap",a.style.padding="0",a.style.margin="0",document.body.appendChild(a);let l=a.getBoundingClientRect(),i=Math.ceil(l.width),u=Math.ceil(l.height);document.body.removeChild(a);let f=document.createElement("canvas");f.width=i*s,f.height=u*s;let c=f.getContext("2d");return c.scale(s,s),c.font=n?`${n} ${o}px "${e}"`:`${o}px "${e}"`,c.textAlign="left",c.textBaseline="top",c.fillStyle=r,c.fillText(t,0,0),{dataUrl:f.toDataURL(),width:i,height:u}})}var rn=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]);function Lt(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!rn.has(n.toLowerCase()))return n}return""}function Rt(t){let e=String(t!=null?t:"400").trim().toLowerCase();if(e==="normal")return 400;if(e==="bold")return 700;let n=parseInt(e,10);return Number.isFinite(n)?Math.min(900,Math.max(100,n)):400}function Yt(t){let e=String(t!=null?t:"normal").trim().toLowerCase();return e.startsWith("italic")?"italic":e.startsWith("oblique")?"oblique":"normal"}function sn(t){let e=String(t!=null?t:"100%").match(/(\d+(?:\.\d+)?)\s*%/);return e?Math.max(50,Math.min(200,parseFloat(e[1]))):100}function an(t){let e=String(t||"400").trim(),n=e.match(/^(\d{2,3})\s+(\d{2,3})$/);if(n){let r=Rt(n[1]),s=Rt(n[2]);return{min:Math.min(r,s),max:Math.max(r,s)}}let o=Rt(e);return{min:o,max:o}}function cn(t){let e=String(t||"normal").trim().toLowerCase();return e==="italic"?{kind:"italic"}:e.startsWith("oblique")?{kind:"oblique"}:{kind:"normal"}}function ln(t){let e=String(t||"100%").trim(),n=e.match(/(\d+(?:\.\d+)?)\s*%\s+(\d+(?:\.\d+)?)\s*%/);if(n){let s=parseFloat(n[1]),a=parseFloat(n[2]);return{min:Math.min(s,a),max:Math.max(s,a)}}let o=e.match(/(\d+(?:\.\d+)?)\s*%/),r=o?parseFloat(o[1]):100;return{min:r,max:r}}function fn(t,e){if(!t)return!1;try{let n=new URL(t,location.href);if(n.origin===location.origin)return!0;let r=n.host.toLowerCase();if(["fonts.googleapis.com","fonts.gstatic.com","use.typekit.net","p.typekit.net","kit.fontawesome.com","use.fontawesome.com"].some(l=>r.endsWith(l)))return!0;let a=(n.pathname+n.search).toLowerCase();if(/\bfont(s)?\b/.test(a)||/\.woff2?(\b|$)/.test(a))return!0;for(let l of e){let i=l.toLowerCase().replace(/\s+/g,"+"),u=l.toLowerCase().replace(/\s+/g,"-");if(a.includes(i)||a.includes(u))return!0}return!1}catch(n){return!1}}function un(t){var n;let e=new Set;for(let o of t||[]){let r=(n=String(o).split("__")[0])==null?void 0:n.trim();r&&e.add(r)}return e}function Mt(){return C(this,arguments,function*({required:t,usedCodepoints:e,exclude:n=void 0,localFonts:o=[],useProxy:r=""}={}){var j,z,G,K,nt,ot,rt,gt,B,xt,Ct,Bt,Ot,O,V,J,Q,dt;t instanceof Set||(t=new Set),e instanceof Set||(e=new Set);let s=new Map;for(let d of t){let[y,g,x,p]=String(d).split("__");if(!y)continue;let b=s.get(y)||[];b.push({w:parseInt(g,10),s:x,st:parseInt(p,10)}),s.set(y,b)}let a=/@import\s+url\(["']?([^"')]+)["']?\)/g,l=/url\((["']?)([^"')]+)\1\)/g,i=/@font-face[^{}]*\{[^}]*\}/g;function u(d,y,g,x){if(!s.has(d))return!1;let p=s.get(d),b=an(g),A=cn(y),E=ln(x),k=b.min!==b.max,M=b.min,L=T=>A.kind==="normal"&&T==="normal"||A.kind!=="normal"&&(T==="italic"||T==="oblique"),N=!1;for(let T of p){let Z=k?T.w>=b.min&&T.w<=b.max:T.w===M,st=L(Yt(T.s)),mt=T.st>=E.min&&T.st<=E.max;if(Z&&st&&mt){N=!0;break}}if(N)return!0;if(!k)for(let T of p){let Z=L(Yt(T.s)),st=T.st>=E.min&&T.st<=E.max;if(Math.abs(M-T.w)<=300&&Z&&st)return!0}return!1}function f(d){if(!d)return[];let y=[],g=d.split(",").map(x=>x.trim()).filter(Boolean);for(let x of g){let p=x.match(/^U\+([0-9A-Fa-f?]+)(?:-([0-9A-Fa-f?]+))?$/);if(!p)continue;let b=p[1],A=p[2],E=k=>{if(!k.includes("?"))return parseInt(k,16);let M=parseInt(k.replace(/\?/g,"0"),16),L=parseInt(k.replace(/\?/g,"F"),16);return[M,L]};if(A){let k=E(b),M=E(A),L=Array.isArray(k)?k[0]:k,N=Array.isArray(M)?M[1]:M;y.push([Math.min(L,N),Math.max(L,N)])}else{let k=E(b);Array.isArray(k)?y.push([k[0],k[1]]):y.push([k,k])}}return y}function c(d,y){if(!y.length||!d||d.size===0)return!0;for(let g of d)for(let[x,p]of y)if(g>=x&&g<=p)return!0;return!1}function h(d,y){let g=[];if(!d)return g;for(let x of d.matchAll(l)){let p=(x[2]||"").trim();if(!(!p||p.startsWith("data:"))){if(!/^https?:/i.test(p))try{p=new URL(p,y||location.href).href}catch(b){}g.push(p)}}return g}function S(d,y){return C(this,null,function*(){var x,p,b,A,E;let g=d;for(let k of d.matchAll(l)){let M=at(k[0]);if(!M)continue;let L=M;if(!L.startsWith("http")&&!L.startsWith("data:"))try{L=new URL(L,y||location.href).href}catch(N){}if(!Y(L)){if((x=m.resource)!=null&&x.has(L)){(p=m.font)==null||p.add(L),g=g.replace(k[0],`url(${m.resource.get(L)})`);continue}if(!((b=m.font)!=null&&b.has(L)))try{let N=yield D(L,{as:"dataURL",useProxy:r,silent:!0});if(N.ok&&typeof N.data=="string"){let T=N.data;(A=m.resource)==null||A.set(L,T),(E=m.font)==null||E.add(L),g=g.replace(k[0],`url(${T})`)}}catch(N){console.warn("[snapDOM] Failed to fetch font resource:",L)}}}return g})}function $(d){if(!d.length)return null;let y=(E,k)=>d.some(([M,L])=>!(L<E||M>k)),g=y(0,255)||y(305,305),x=y(256,591)||y(7680,7935),p=y(880,1023),b=y(1024,1279);return y(7840,7929)||y(258,259)||y(416,417)||y(431,432)?"vietnamese":b?"cyrillic":p?"greek":x?"latin-ext":g?"latin":null}function w(d={}){let y=new Set((d.families||[]).map(p=>String(p).toLowerCase())),g=new Set((d.domains||[]).map(p=>String(p).toLowerCase())),x=new Set((d.subsets||[]).map(p=>String(p).toLowerCase()));return(p,b)=>{if(y.size&&y.has(p.family.toLowerCase()))return!0;if(g.size)for(let A of p.srcUrls)try{if(g.has(new URL(A).host.toLowerCase()))return!0}catch(E){}if(x.size){let A=$(b);if(A&&x.has(A))return!0}return!1}}let v=w(n);function _(d){var b,A,E,k,M,L;if(!d)return d;let y=/@font-face[^{}]*\{[^}]*\}/gi,g=new Set,x=[];for(let N of d.match(y)||[]){let T=((b=N.match(/font-family:\s*([^;]+);/i))==null?void 0:b[1])||"",Z=Lt(T),st=(((A=N.match(/font-weight:\s*([^;]+);/i))==null?void 0:A[1])||"400").trim(),mt=(((E=N.match(/font-style:\s*([^;]+);/i))==null?void 0:E[1])||"normal").trim(),Ce=(((k=N.match(/font-stretch:\s*([^;]+);/i))==null?void 0:k[1])||"100%").trim(),Ae=(((M=N.match(/unicode-range:\s*([^;]+);/i))==null?void 0:M[1])||"").trim(),Zt=(((L=N.match(/src\s*:\s*([^;]+);/i))==null?void 0:L[1])||"").trim(),Qt=h(Zt,location.href),$e=Qt.length?Qt.map(Ee=>String(Ee).toLowerCase()).sort().join("|"):Zt.toLowerCase(),te=[String(Z||"").toLowerCase(),st,mt,Ce,Ae.toLowerCase(),$e].join("|");g.has(te)||(g.add(te),x.push(N))}if(x.length===0)return d;let p=0;return d.replace(y,()=>x[p++]||"")}function I(){let d=Array.from(t||[]).sort().join("|"),y=n?JSON.stringify({families:(n.families||[]).map(p=>String(p).toLowerCase()).sort(),domains:(n.domains||[]).map(p=>String(p).toLowerCase()).sort(),subsets:(n.subsets||[]).map(p=>String(p).toLowerCase()).sort()}):"",g=(o||[]).map(p=>`${(p.family||"").toLowerCase()}::${p.weight||"normal"}::${p.style||"normal"}::${p.src||""}`).sort().join("|");return`fonts-embed-css::req=${d}::ex=${y}::lf=${g}::px=${r||""}`}let R=I();if((j=m.resource)!=null&&j.has(R))return m.resource.get(R);let W=un(t),P=[];for(let d of document.querySelectorAll("style")){let y=d.textContent||"";for(let g of y.matchAll(a)){let x=g[1];if(!x||Y(x))continue;!!document.querySelector(`link[rel="stylesheet"][href="${x}"]`)||P.push(x)}}P.length&&(yield Promise.all(P.map(d=>new Promise(y=>{if(document.querySelector(`link[rel="stylesheet"][href="${d}"]`))return y(null);let g=document.createElement("link");g.rel="stylesheet",g.href=d,g.setAttribute("data-snapdom","injected-import"),g.onload=()=>y(g),g.onerror=()=>y(null),document.head.appendChild(g)}))));let F="",q=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(d=>!!d.href);for(let d of q)try{if(Y(d.href))continue;let y="",g=!1;try{g=new URL(d.href,location.href).origin===location.origin}catch(p){}if(!g&&!fn(d.href,W))continue;if(g){let p=Array.from(document.styleSheets).find(b=>b.href===d.href);if(p)try{let b=p.cssRules||[];y=Array.from(b).map(A=>A.cssText).join("")}catch(b){}}if(!y&&(y=(yield D(d.href,{as:"text",useProxy:r})).data,Y(d.href)))continue;let x="";for(let p of y.match(i)||[]){let b=(((z=p.match(/font-family:\s*([^;]+);/i))==null?void 0:z[1])||"").trim(),A=Lt(b);if(!A||Y(A))continue;let E=(((G=p.match(/font-weight:\s*([^;]+);/i))==null?void 0:G[1])||"400").trim(),k=(((K=p.match(/font-style:\s*([^;]+);/i))==null?void 0:K[1])||"normal").trim(),M=(((nt=p.match(/font-stretch:\s*([^;]+);/i))==null?void 0:nt[1])||"100%").trim(),L=(((ot=p.match(/unicode-range:\s*([^;]+);/i))==null?void 0:ot[1])||"").trim(),N=(((rt=p.match(/src\s*:\s*([^;]+);/i))==null?void 0:rt[1])||"").trim(),T=h(N,d.href);if(!u(A,k,E,M))continue;let Z=f(L);if(!c(e,Z))continue;let st={family:A,weightSpec:E,styleSpec:k,stretchSpec:M,unicodeRange:L,srcRaw:N,srcUrls:T,href:d.href};if(n&&v(st,Z))continue;let mt=/url\(/i.test(N)?yield S(p,d.href):p;x+=mt+""}x.trim()&&(F+=x+"")}catch(y){console.warn("[snapdom] Failed to process stylesheet:",d.href)}for(let d of document.styleSheets)try{if(d.href&&q.some(g=>g.href===d.href))continue;let y=d.cssRules||[];for(let g of y){if(g.type!==CSSRule.FONT_FACE_RULE)continue;let x=(g.style.getPropertyValue("font-family")||"").trim(),p=Lt(x);if(!p||Y(p))continue;let b=(g.style.getPropertyValue("font-weight")||"400").trim(),A=(g.style.getPropertyValue("font-style")||"normal").trim(),E=(g.style.getPropertyValue("font-stretch")||"100%").trim(),k=(g.style.getPropertyValue("src")||"").trim(),M=(g.style.getPropertyValue("unicode-range")||"").trim(),L=h(k,d.href||location.href);if(!u(p,A,b,E))continue;let N=f(M);if(!c(e,N))continue;let T={family:p,weightSpec:b,styleSpec:A,stretchSpec:E,unicodeRange:M,srcRaw:k,srcUrls:L,href:d.href||location.href};if(!(n&&v(T,N)))if(/url\(/i.test(k)){let Z=yield S(k,d.href||location.href);F+=`@font-face{font-family:${p};src:${Z};font-style:${A};font-weight:${b};font-stretch:${E};${M?`unicode-range:${M};`:""}}`}else F+=`@font-face{font-family:${p};src:${k};font-style:${A};font-weight:${b};font-stretch:${E};${M?`unicode-range:${M};`:""}}`}}catch(y){}try{for(let d of document.fonts||[]){if(!d||!d.family||d.status!=="loaded"||!d._snapdomSrc)continue;let y=String(d.family).replace(/^['"]+|['"]+$/g,"");if(Y(y)||!s.has(y)||n!=null&&n.families&&n.families.some(x=>String(x).toLowerCase()===y.toLowerCase()))continue;let g=d._snapdomSrc;if(!String(g).startsWith("data:")){if((gt=m.resource)!=null&>.has(d._snapdomSrc))g=m.resource.get(d._snapdomSrc),(B=m.font)==null||B.add(d._snapdomSrc);else if(!((xt=m.font)!=null&&xt.has(d._snapdomSrc)))try{let x=yield D(d._snapdomSrc,{as:"dataURL",useProxy:r,silent:!0});if(x.ok&&typeof x.data=="string")g=x.data,(Ct=m.resource)==null||Ct.set(d._snapdomSrc,g),(Bt=m.font)==null||Bt.add(d._snapdomSrc);else continue}catch(x){console.warn("[snapdom] Failed to fetch dynamic font src:",d._snapdomSrc);continue}}F+=`@font-face{font-family:'${y}';src:url(${g});font-style:${d.style||"normal"};font-weight:${d.weight||"normal"};}`}}catch(d){}for(let d of o){if(!d||typeof d!="object")continue;let y=String(d.family||"").replace(/^['"]+|['"]+$/g,"");if(!y||Y(y)||!s.has(y)||n!=null&&n.families&&n.families.some(E=>String(E).toLowerCase()===y.toLowerCase()))continue;let g=d.weight!=null?String(d.weight):"normal",x=d.style!=null?String(d.style):"normal",p=d.stretchPct!=null?`${d.stretchPct}%`:"100%",b=String(d.src||""),A=b;if(!A.startsWith("data:")){if((Ot=m.resource)!=null&&Ot.has(b))A=m.resource.get(b),(O=m.font)==null||O.add(b);else if(!((V=m.font)!=null&&V.has(b)))try{let E=yield D(b,{as:"dataURL",useProxy:r,silent:!0});if(E.ok&&typeof E.data=="string")A=E.data,(J=m.resource)==null||J.set(b,A),(Q=m.font)==null||Q.add(b);else continue}catch(E){console.warn("[snapdom] Failed to fetch localFonts src:",b);continue}}F+=`@font-face{font-family:'${y}';src:url(${A});font-style:${x};font-weight:${g};font-stretch:${p};}`}return F&&(F=_(F),(dt=m.resource)==null||dt.set(R,F)),F})}function Nt(t){let e=new Set;if(!t)return e;let n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null),o=a=>{let l=Lt(a.fontFamily);if(!l)return;let i=(u,f,c)=>`${l}__${Rt(u)}__${Yt(f)}__${sn(c)}`;e.add(i(a.fontWeight,a.fontStyle,a.fontStretch))};o(getComputedStyle(t));let r=getComputedStyle(t,"::before");r&&r.content&&r.content!=="none"&&o(r);let s=getComputedStyle(t,"::after");for(s&&s.content&&s.content!=="none"&&o(s);n.nextNode();){let a=n.currentNode,l=getComputedStyle(a);o(l);let i=getComputedStyle(a,"::before");i&&i.content&&i.content!=="none"&&o(i);let u=getComputedStyle(a,"::after");u&&u.content&&u.content!=="none"&&o(u)}return e}function Tt(t){let e=new Set,n=r=>{if(r)for(let s of r)e.add(s.codePointAt(0))},o=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,null);for(;o.nextNode();){let r=o.currentNode;if(r.nodeType===Node.TEXT_NODE)n(r.nodeValue||"");else if(r.nodeType===Node.ELEMENT_NODE){let s=r;for(let a of["::before","::after"]){let l=getComputedStyle(s,a),i=l==null?void 0:l.getPropertyValue("content");if(!(!i||i==="none"))if(/^"/.test(i)||/^'/.test(i))n(i.slice(1,-1));else{let u=i.match(/\\[0-9A-Fa-f]{1,6}/g);if(u)for(let f of u)try{e.add(parseInt(f.slice(1),16))}catch(c){}}}}}return e}function It(t,e=1){return C(this,null,function*(){try{yield document.fonts.ready}catch(r){}let n=Array.from(t||[]).filter(Boolean);if(n.length===0)return;let o=()=>{let r=document.createElement("div");r.style.cssText="position: absolute !important;left: -9999px !important;top: 0 !important;opacity: 0 !important;pointer-events: none !important;contain: layout size style;";for(let s of n){let a=document.createElement("span");a.textContent="AaBbGg1234\xC1\xC9\xCD\xD3\xDA\xE7\xF1\u2014\u221E",a.style.fontFamily=`"${s}"`,a.style.fontWeight="700",a.style.fontStyle="italic",a.style.fontSize="32px",a.style.lineHeight="1",a.style.whiteSpace="nowrap",a.style.margin="0",a.style.padding="0",r.appendChild(a)}document.body.appendChild(r),r.offsetWidth,document.body.removeChild(r)};for(let r=0;r<Math.max(1,e);r++)o(),yield new Promise(s=>requestAnimationFrame(()=>requestAnimationFrame(s)))})}function Jt(t,e,n,o){return C(this,null,function*(){var a;if(!(t instanceof Element)||!(e instanceof Element))return;for(let l of["::before","::after","::first-letter"])try{let i=lt(t,l);if(!i||typeof i[Symbol.iterator]!="function"||i.content==="none"&&i.backgroundImage==="none"&&i.backgroundColor==="transparent"&&(i.borderStyle==="none"||parseFloat(i.borderWidth)===0)&&(!i.transform||i.transform==="none")&&i.display==="inline")continue;if(l==="::first-letter"){let O=getComputedStyle(t);if(!(i.color!==O.color||i.fontSize!==O.fontSize||i.fontWeight!==O.fontWeight))continue;let J=Array.from(e.childNodes).find(A=>{var E;return A.nodeType===Node.TEXT_NODE&&((E=A.textContent)==null?void 0:E.trim().length)>0});if(!J)continue;let Q=J.textContent,dt=Q.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),d=dt==null?void 0:dt[0],y=Q.slice((d==null?void 0:d.length)||0);if(!d||/[\uD800-\uDFFF]/.test(d))continue;let g=document.createElement("span");g.textContent=d,g.dataset.snapdomPseudo="::first-letter";let x=kt(i),p=pt(x,"span");n.styleMap.set(g,p);let b=document.createTextNode(y);e.replaceChild(b,J),e.insertBefore(g,b);continue}let f=i.content,c=/counter\s*\(|counters\s*\(/.test(f)?"- ":Gt(f),h=i.backgroundImage,S=i.backgroundColor,$=i.fontFamily,w=parseInt(i.fontSize)||32,v=parseInt(i.fontWeight)||!1,_=i.color||"#000",I=i.display,R=parseFloat(i.width),W=parseFloat(i.height),P=i.borderStyle,F=parseFloat(i.borderWidth),q=i.transform,j=Y($),z=f!=="none"&&c!=="",G=h&&h!=="none",K=S&&S!=="transparent"&&S!=="rgba(0, 0, 0, 0)",nt=I!=="inline"&&(R>0||W>0),ot=P&&P!=="none"&&F>0,rt=q&&q!=="none";if(!(z||G||K||nt||ot||rt))continue;let B=document.createElement("span");B.dataset.snapdomPseudo=l,B.style.verticalAlign="middle";let xt=kt(i),Ct=pt(xt,"span");if(n.styleMap.set(B,Ct),j&&c.length===1){let{dataUrl:O,width:V,height:J}=yield fe(c,$,v,w,_),Q=document.createElement("img");Q.src=O,Q.style=`height:${w}px;width:${V/J*w}px;object-fit:contain;`,B.appendChild(Q),e.dataset.snapdomHasIcon="true"}else if(c.startsWith("url(")){let O=at(c);if(O!=null&&O.trim())try{let V=document.createElement("img"),J=yield D(yt(O),{as:"dataURL",useProxy:o.useProxy});V.src=J.data,V.style=`width:${w}px;height:auto;object-fit:contain;`,B.appendChild(V)}catch(V){console.error(`[snapdom] Error in pseudo ${l} for`,t,V)}}else!j&&z&&(B.textContent=c);if(G)try{let O=ft(h),V=yield Promise.all(O.map(ct));B.style.backgroundImage=V.join(", ")}catch(O){console.warn(`[snapdom] Failed to inline background-image for ${l}`,O)}if(K&&(B.style.backgroundColor=S),!(B.childNodes.length>0||((a=B.textContent)==null?void 0:a.trim())!==""||G||K||nt||ot||rt))continue;l==="::before"?e.insertBefore(B,e.firstChild):e.appendChild(B)}catch(i){console.warn(`[snapdom] Failed to capture ${l} for`,t,i)}let r=Array.from(t.children),s=Array.from(e.children).filter(l=>!l.dataset.snapdomPseudo);for(let l=0;l<Math.min(r.length,s.length);l++)yield Jt(r[l],s[l],n,o)})}function ue(t){if(!t)return;let e=new Set;if(t.querySelectorAll("use").forEach(l=>{let i=l.getAttribute("xlink:href")||l.getAttribute("href");i&&i.startsWith("#")&&e.add(i.slice(1))}),!e.size)return;let n=Array.from(document.querySelectorAll("svg > symbol, svg > defs")),o=n.filter(l=>l.tagName.toLowerCase()==="symbol"),r=n.filter(l=>l.tagName.toLowerCase()==="defs"),s=t.querySelector("svg.inline-defs-container");s||(s=document.createElementNS("http://www.w3.org/2000/svg","svg"),s.setAttribute("aria-hidden","true"),s.setAttribute("style","position: absolute; width: 0; height: 0; overflow: hidden;"),s.classList.add("inline-defs-container"),t.insertBefore(s,t.firstChild));let a=new Set;t.querySelectorAll("symbol[id], defs > *[id]").forEach(l=>{a.add(l.id)}),e.forEach(l=>{if(a.has(l))return;let i=o.find(u=>u.id===l);if(i){s.appendChild(i.cloneNode(!0)),a.add(l);return}for(let u of r){let f=u.querySelector(`#${CSS.escape(l)}`);if(f){let c=s.querySelector("defs");c||(c=document.createElementNS("http://www.w3.org/2000/svg","defs"),s.appendChild(c)),c.appendChild(f.cloneNode(!0)),a.add(l);break}}})}function me(n){return C(this,arguments,function*(t,e={}){var i,u;let o={styleMap:m.session.styleMap,styleCache:m.session.styleCache,nodeMap:m.session.nodeMap},r,s="",a="";dn(t);try{ue(t)}catch(f){console.warn("inlineExternal defs or symbol failed:",f)}try{r=wt(t,o,e,t)}catch(f){throw console.warn("deepClone failed:",f),f}try{yield Jt(t,r,o,e)}catch(f){console.warn("inlinePseudoElements failed:",f)}yield gn(r);try{let f=r.querySelectorAll("style[data-sd]");for(let c of f)a+=c.textContent||"",c.remove()}catch(f){}let l=Ht(o.styleMap);s=Array.from(l.entries()).map(([f,c])=>`.${c}{${f}}`).join(""),s=a+s;for(let[f,c]of o.styleMap.entries()){if(f.tagName==="STYLE")continue;if(f.getRootNode&&f.getRootNode()instanceof ShadowRoot){f.setAttribute("style",c.replace(/;/g,"; "));continue}let h=l.get(c);h&&f.classList.add(h);let S=(i=f.style)==null?void 0:i.backgroundImage,$=(u=f.dataset)==null?void 0:u.snapdomHasIcon;S&&S!=="none"&&(f.style.backgroundImage=S),$&&(f.style.verticalAlign="middle",f.style.display="inline")}for(let[f,c]of o.nodeMap.entries()){let h=c.scrollLeft,S=c.scrollTop;if((h||S)&&f instanceof HTMLElement){f.style.overflow="hidden",f.style.scrollbarWidth="none",f.style.msOverflowStyle="none";let w=document.createElement("div");for(w.style.transform=`translate(${-h}px, ${-S}px)`,w.style.willChange="transform",w.style.display="inline-block",w.style.width="100%";f.firstChild;)w.appendChild(f.firstChild);f.appendChild(w)}}if(t===o.nodeMap.get(r)){let f=o.styleCache.get(t)||window.getComputedStyle(t);o.styleCache.set(t,f);let c=Wt(f.transform);r.style.margin="0",r.style.position="static",r.style.top="auto",r.style.left="auto",r.style.right="auto",r.style.bottom="auto",r.style.zIndex="auto",r.style.float="none",r.style.clear="none",r.style.transform=c||""}for(let[f,c]of o.nodeMap.entries())c.tagName==="PRE"&&(f.style.marginTop="0",f.style.marginBlockStart="0");return{clone:r,classCSS:s,styleCache:o.styleCache}})}function dn(t){let e=getComputedStyle(t),n=e.outlineStyle,o=e.outlineWidth,r=e.borderStyle,s=e.borderWidth,a=n!=="none"&&parseFloat(o)>0,l=r==="none"||parseFloat(s)===0;a&&l&&(t.style.border=`${o} solid transparent`)}var St=new Map;function bt(t){return C(this,null,function*(){var n;if((n=m.resource)!=null&&n.has(t))return m.resource.get(t);if(St.has(t))return St.get(t);let e=C(null,null,function*(){var r;let o=yield D(t,{as:"dataURL",silent:!0});if(!o.ok||typeof o.data!="string")throw new Error(`[snapDOM] Failed to read blob URL: ${t}`);return(r=m.resource)==null||r.set(t,o.data),o.data});St.set(t,e);try{let o=yield e;return St.set(t,o),o}catch(o){throw St.delete(t),o}})}var mn=/\bblob:[^)"'\s]+/g;function de(t){return C(this,null,function*(){if(!t||t.indexOf("blob:")===-1)return t;let e=Array.from(new Set(t.match(mn)||[]));if(e.length===0)return t;let n=t;for(let o of e)try{let r=yield bt(o);n=n.split(o).join(r)}catch(r){}return n})}function _t(t){return typeof t=="string"&&t.startsWith("blob:")}function hn(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 pn(t){return t.map(e=>e.desc?`${e.url} ${e.desc.trim()}`:e.url).join(", ")}function gn(t){return C(this,null,function*(){var a,l;if(!t)return;let e=t.querySelectorAll?t.querySelectorAll("img"):[];for(let i of e)try{let f=i.getAttribute("src")||i.currentSrc||"";if(_t(f)){let h=yield bt(f);i.setAttribute("src",h)}let c=i.getAttribute("srcset");if(c&&c.includes("blob:")){let h=hn(c),S=!1;for(let $ of h)if(_t($.url))try{$.url=yield bt($.url),S=!0}catch(w){}S&&i.setAttribute("srcset",pn(h))}}catch(u){}let n=t.querySelectorAll?t.querySelectorAll("image"):[];for(let i of n)try{let u="http://www.w3.org/1999/xlink",f=i.getAttribute("href")||((a=i.getAttributeNS)==null?void 0:a.call(i,u,"href"));if(_t(f)){let c=yield bt(f);i.setAttribute("href",c),(l=i.removeAttributeNS)==null||l.call(i,u,"href")}}catch(u){}let o=t.querySelectorAll?t.querySelectorAll("[style*='blob:']"):[];for(let i of o)try{let u=i.getAttribute("style");if(u&&u.includes("blob:")){let f=yield de(u);i.setAttribute("style",f)}}catch(u){}let r=t.querySelectorAll?t.querySelectorAll("style"):[];for(let i of r)try{let u=i.textContent||"";u.includes("blob:")&&(i.textContent=yield de(u))}catch(u){}let s=["poster"];for(let i of s){let u=t.querySelectorAll?t.querySelectorAll(`[${i}^='blob:']`):[];for(let f of u)try{let c=f.getAttribute(i);_t(c)&&f.setAttribute(i,yield bt(c))}catch(c){}}})}function he(n){return C(this,arguments,function*(t,e={}){let o=Array.from(t.querySelectorAll("img")),r=s=>C(null,null,function*(){if(!s.getAttribute("src")){let c=s.currentSrc||s.src||"";c&&s.setAttribute("src",c)}s.removeAttribute("srcset"),s.removeAttribute("sizes");let a=s.src||"";if(!a)return;let l=yield D(a,{as:"dataURL",useProxy:e.useProxy});if(l.ok&&typeof l.data=="string"&&l.data.startsWith("data:")){s.src=l.data,s.width||(s.width=s.naturalWidth||100),s.height||(s.height=s.naturalHeight||100);return}let i=s.width||s.naturalWidth||100,u=s.height||s.naturalHeight||100,f=document.createElement("div");f.style.cssText=[`width:${i}px`,`height:${u}px`,"background:#ccc","display:inline-block","text-align:center",`line-height:${u}px`,"color:#666","font-size:12px","overflow:hidden"].join(";"),f.textContent="img",s.replaceWith(f)});for(let s=0;s<o.length;s+=4){let a=o.slice(s,s+4).map(r);yield Promise.allSettled(a)}})}function Pt(r,s,a){return C(this,arguments,function*(t,e,n,o={}){let l=[[t,e]],i=["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(;l.length;){let[u,f]=l.shift(),c=n.get(u)||lt(u);n.has(u)||n.set(u,c);let h=(()=>{let w=c.getPropertyValue("border-image"),v=c.getPropertyValue("border-image-source");return w&&w!=="none"||v&&v!=="none"})();for(let w of i){if(["border-image-slice","border-image-width","border-image-outset","border-image-repeat"].includes(w)&&!h)continue;let v=c.getPropertyValue(w);if(!v||v==="none")continue;let _=ft(v),I=yield Promise.all(_.map(R=>ct(R,o)));I.some(R=>R&&R!=="none"&&!/^url\(undefined/.test(R))&&f.style.setProperty(w,I.join(", "))}let S=Array.from(u.children),$=Array.from(f.children);for(let w=0;w<Math.min(S.length,$.length);w++)l.push([S[w],$[w]])}})}function pe(t,e){return C(this,null,function*(){if(!t)throw new Error("Element cannot be null or undefined");At(e.cache);let n=e.fast,o,r,s,a="",l="",i,u;({clone:o,classCSS:r,styleCache:s}=yield me(t,e)),yield new Promise(S=>{ut(()=>C(null,null,function*(){yield he(o,e),S()}),{fast:n})}),yield new Promise(S=>{ut(()=>C(null,null,function*(){yield Pt(t,o,s,e),S()}),{fast:n})}),e.embedFonts&&(yield new Promise(S=>{ut(()=>C(null,null,function*(){let $=Nt(t),w=Tt(t);if(tt){let v=new Set(Array.from($).map(_=>String(_).split("__")[0]).filter(Boolean));yield It(v,2)}a=yield Mt({required:$,usedCodepoints:w,preCached:!1,exclude:e.excludeFonts,useProxy:e.useProxy}),S()}),{fast:n})}));let f=zt(o).sort(),c=f.join(",");m.baseStyle.has(c)?l=m.baseStyle.get(c):yield new Promise(S=>{ut(()=>{l=Vt(f),m.baseStyle.set(c,l),S()},{fast:n})}),yield new Promise(S=>{ut(()=>{let $=t.getBoundingClientRect(),w=$.width,v=$.height,_=Number.isFinite(e.width),I=Number.isFinite(e.height),R=typeof scale=="number"&&scale!==1;if(!R){let K=$.width/$.height;_&&I?(w=e.width,v=e.height):_?(w=e.width,v=w/K):I&&(v=e.height,w=v*K)}if(w=Math.ceil(w),v=Math.ceil(v),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="top left",!R&&(_||I)){let K=$.width,nt=$.height,ot=w/K,rt=v/nt,gt=o.style.transform||"",B=`scale(${ot}, ${rt})`;o.style.transform=`${B} ${gt}`.trim()}let W="http://www.w3.org/2000/svg",P=document.createElementNS(W,"foreignObject");P.setAttribute("width","100%"),P.setAttribute("height","100%");let F=document.createElement("style");F.textContent=l+a+"svg{overflow:visible;}"+r,P.appendChild(F),P.appendChild(o);let j=new XMLSerializer().serializeToString(P);u=`<svg xmlns="${W}" width="${w}" height="${v}" viewBox="0 0 ${w} ${v}">`+j+"</svg>",i=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`,S()},{fast:n})});let h=document.getElementById("snapdom-sandbox");return h&&h.style.position==="absolute"&&h.remove(),i})}function yn(t){if(t===!0)return"soft";if(t===!1)return"disabled";if(typeof t=="string"){let e=t.toLowerCase().trim();if(e==="disabled"||e==="full"||e==="auto"||e==="soft")return e}return"soft"}function ge(t={}){var o,r,s,a,l,i,u,f,c,h,S,$,w,v,_;let e=(o=t.format)!=null?o:"png",n=yn(t.cache);return{debug:(r=t.debug)!=null?r:!1,fast:(s=t.fast)!=null?s:!0,scale:(a=t.scale)!=null?a:1,exclude:(l=t.exclude)!=null?l:[],filter:(i=t.filter)!=null?i:null,embedFonts:(u=t.embedFonts)!=null?u:!1,iconFonts:Array.isArray(t.iconFonts)?t.iconFonts:t.iconFonts?[t.iconFonts]:[],localFonts:Array.isArray(t.localFonts)?t.localFonts:[],excludeFonts:(f=t.excludeFonts)!=null?f:void 0,cache:n,useProxy:typeof t.useProxy=="string"?t.useProxy:"",width:(c=t.width)!=null?c:null,height:(h=t.height)!=null?h:null,format:e,type:(S=t.type)!=null?S:"svg",quality:($=t.quality)!=null?$:.92,dpr:(w=t.dpr)!=null?w:window.devicePixelRatio||1,backgroundColor:(v=t.backgroundColor)!=null?v:["jpg","jpeg","webp"].includes(e)?"#ffffff":null,filename:(_=t.filename)!=null?_:"snapDOM"}}function ye(t,e){return C(this,null,function*(){let n=new Image;return n.src=t,yield n.decode(),e.scale!==1&&(n.style.width=`${n.naturalWidth*e.scale}px`,n.style.height=`${n.naturalHeight*e.scale}px`),n})}function et(t,e){return C(this,null,function*(){let n=new Image;n.crossOrigin="anonymous",n.loading="eager",n.decoding="sync",n.src=t;let o=tt(),r=!1;o&&(document.body.appendChild(n),r=!0),yield n.decode(),o&&(yield new Promise(f=>setTimeout(f,100)));let s=n.naturalWidth*e.scale,a=n.naturalHeight*e.scale,l=document.createElement("canvas"),i=e.dpr;l.width=Math.ceil(s*i),l.height=Math.ceil(a*i),l.style.width=`${s}px`,l.style.height=`${a}px`;let u=l.getContext("2d");return u.scale(i,i),u.drawImage(n,0,0,s,a),r&&n.remove(),l})}function Ut(t,e){return C(this,null,function*(){let n=e.type;if(n==="svg"){let s=decodeURIComponent(t.split(",")[1]);return new Blob([s],{type:"image/svg+xml"})}let o=yield et(t,e),r=e.backgroundColor?it(o,e.backgroundColor):o;return new Promise(s=>r.toBlob(a=>s(a),`image/${n}`,e.quality))})}function we(t,e){return C(this,null,function*(){let n=yield et(t,e),o=e.backgroundColor?it(n,e.backgroundColor):n,r=new Image;return r.src=o.toDataURL(`image/${e.format}`,e.quality),yield r.decode(),r.style.width=`${o.width/e.dpr}px`,r.style.height=`${o.height/e.dpr}px`,r})}function Se(t,e){return C(this,null,function*(){if(e.format==="svg"){let s=yield Ut(t,X(H({},e),{type:"svg"})),a=URL.createObjectURL(s),l=document.createElement("a");l.href=a,l.download=e.filename,l.click(),URL.revokeObjectURL(a);return}let n=yield et(t,e),o=e.backgroundColor?it(n,e.backgroundColor):n,r=document.createElement("a");r.href=o.toDataURL(`image/${e.format}`,e.quality),r.download=e.filename,r.click()})}var be=Symbol("snapdom.internal");function U(t,e){return C(this,null,function*(){if(!t)throw new Error("Element cannot be null or undefined");let n=ge(e);return n.iconFonts&&n.iconFonts.length>0&&le(n.iconFonts),U.capture(t,n,be)})}U.capture=(t,e,n)=>C(null,null,function*(){if(n!==be)throw new Error("[snapdom.capture] is internal. Use snapdom(...) instead.");let o=yield pe(t,e),r=a=>H(H({},e),a||{}),s=a=>l=>we(o,r(X(H({},l||{}),{format:a})));return{url:o,toRaw:()=>o,toImg:a=>ye(o,r(a)),toCanvas:a=>et(o,r(a)),toBlob:a=>Ut(o,r(a)),toPng:s("png"),toJpg:s("jpeg"),toWebp:s("webp"),download:a=>Se(o,r(a))}});U.toRaw=(t,e)=>U(t,e).then(n=>n.toRaw());U.toImg=(t,e)=>U(t,e).then(n=>n.toImg());U.toCanvas=(t,e)=>U(t,e).then(n=>n.toCanvas());U.toBlob=(t,e)=>U(t,e).then(n=>n.toBlob());U.toPng=(t,e)=>U(t,X(H({},e),{format:"png"})).then(n=>n.toPng());U.toJpg=(t,e)=>U(t,X(H({},e),{format:"jpeg"})).then(n=>n.toJpg());U.toWebp=(t,e)=>U(t,X(H({},e),{format:"webp"})).then(n=>n.toWebp());U.download=(t,e)=>U(t,e).then(n=>n.download());function xe(){return C(this,arguments,function*(t=document,e={}){var i;let{embedFonts:n=!0,cacheOpt:o="full",useProxy:r=""}=e;At(o);try{yield document.fonts.ready}catch(u){}Dt(),m.session=m.session||{},m.session.styleCache||(m.session.styleCache=new WeakMap);try{yield Pt(t,void 0,m.session.styleCache,{useProxy:r})}catch(u){}let s=[],a=[];try{t!=null&&t.querySelectorAll&&(s=Array.from(t.querySelectorAll("img[src]")),a=Array.from(t.querySelectorAll("*")))}catch(u){}let l=[];for(let u of s){let f=u==null?void 0:u.src;if(f&&!m.image.has(f)){let c=Promise.resolve().then(()=>D(f,{as:"dataURL",useProxy:r})).then(h=>{m.image.set(f,h)}).catch(()=>{});l.push(c)}}for(let u of a){let f="";try{f=lt(u).backgroundImage}catch(c){}if(f&&f!=="none"){let c=ft(f);for(let h of c)if(h.startsWith("url(")){let S=Promise.resolve().then(()=>ct(h,X(H({},e),{useProxy:r}))).catch(()=>{});l.push(S)}}}if(n)try{let u=Nt(t),f=Tt(t);if(typeof tt=="function"?tt():tt){let c=new Set(Array.from(u).map(h=>String(h).split("__")[0]).filter(Boolean));yield It(c,2)}yield Mt({required:u,usedCodepoints:f,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:(i=e.useProxy)!=null?i:r})}catch(u){}yield Promise.allSettled(l)})}typeof window!="undefined"&&(window.snapdom=U,window.preCache=xe);})();
|
package/dist/snapdom.min.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
var
|
|
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};
|
|
1
|
+
var f={image:new Map,background:new Map,resource:new Map,defaultStyle:new Map,baseStyle:new Map,computedStyle:new WeakMap,font:new Set,session:{styleMap:new Map,styleCache:new WeakMap,nodeMap:new Map}};function at(t="soft"){switch(t){case"auto":{f.session.styleMap=new Map,f.session.nodeMap=new Map;return}case"soft":{f.session.styleMap=new Map,f.session.nodeMap=new Map,f.session.styleCache=new WeakMap;return}case"full":return;case"disabled":{f.session.styleMap=new Map,f.session.nodeMap=new Map,f.session.styleCache=new WeakMap,f.image.clear(),f.background.clear(),f.resource.clear(),f.font.clear();return}default:{f.session.styleMap=new Map,f.session.nodeMap=new Map,f.session.styleCache=new WeakMap;return}}}function V(t){let e=t.match(/url\((['"]?)(.*?)(\1)\)/);if(!e)return null;let n=e[2].trim();return n.startsWith("#")?null:n}function xt(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(n,o)=>{let s=o.split(",").map(i=>i.trim());return s.length!==6?`matrix(${o})`:(s[4]="0",s[5]="0",`matrix(${s.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(n,o)=>{let s=o.split(",").map(i=>i.trim());return s.length!==16?`matrix3d(${o})`:(s[12]="0",s[13]="0",`matrix3d(${s.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function tt(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function oe(t="[snapDOM]",{ttlMs:e=5*6e4,maxEntries:n=12}={}){let o=new Map,s=0;function i(r,a,c){if(s>=n)return;let u=Date.now();(o.get(a)||0)>u||(o.set(a,u+e),s++,r==="warn"&&console&&console.warn?console.warn(`${t} ${c}`):console&&console.error&&console.error(`${t} ${c}`))}return{warnOnce(r,a){i("warn",r,a)},errorOnce(r,a){i("error",r,a)},reset(){o.clear(),s=0}}}var Pt=oe("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),Ct=new Map,it=new Map;function re(t){return/^data:|^blob:|^about:blank$/.test(t)}function se(t,e){if(!e||re(t))return!1;try{let n=typeof location<"u"&&location.href?location.href:"http://localhost/",o=new URL(t,n);return typeof location<"u"?o.origin!==location.origin:!0}catch{return!!e}}function ae(t,e){if(!e)return t;if(e.includes("{url}"))return e.replace("{url}",encodeURIComponent(t));let n=e.endsWith("?")?"":e.includes("?")?"&":"?";return`${e}${n}url=${encodeURIComponent(t)}`}function ie(t){return new Promise((e,n)=>{let o=new FileReader;o.onload=()=>e(String(o.result||"")),o.onerror=()=>n(new Error("read_failed")),o.readAsDataURL(t)})}function ce(t,e){return[e.as||"blob",e.timeout??3e3,e.useProxy||"",e.errorTTL??8e3,t].join("|")}async function B(t,e={}){let n=e.as??"blob",o=e.timeout??3e3,s=e.useProxy||"",i=e.errorTTL??8e3,r=e.headers||{},a=!!e.silent,c=ce(t,{as:n,timeout:o,useProxy:s,errorTTL:i}),u=it.get(c);if(u&&u.until>Date.now())return{...u.result,fromCache:!0};u&&it.delete(c);let p=Ct.get(c);if(p)return p;let y=se(t,s)?ae(t,s):t,S=e.credentials;if(!S)try{let b=typeof location<"u"&&location.href?location.href:"http://localhost/",R=new URL(t,b);S=typeof location<"u"&&R.origin===location.origin?"include":"omit"}catch{S="omit"}let E=new AbortController,k=setTimeout(()=>E.abort("timeout"),o),F=(async()=>{try{let b=await fetch(y,{signal:E.signal,credentials:S,headers:r});if(!b.ok){let T={ok:!1,data:null,status:b.status,url:y,fromCache:!1,reason:"http_error"};if(it.set(c,{until:Date.now()+i,result:T}),!a){let W=`${b.status} ${b.statusText||""}`.trim();Pt.warnOnce(`http:${b.status}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,`HTTP error ${W} while fetching ${n} ${t}`)}return e.onError&&e.onError(T),T}if(n==="text")return{ok:!0,data:await b.text(),status:b.status,url:y,fromCache:!1};let R=await b.blob(),_=R.type||b.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await ie(R),status:b.status,url:y,fromCache:!1,mime:_}:{ok:!0,data:R,status:b.status,url:y,fromCache:!1,mime:_}}catch(b){let R=b&&typeof b=="object"&&"name"in b&&b.name==="AbortError"?String(b.message||"").includes("timeout")?"timeout":"abort":"network",_={ok:!1,data:null,status:0,url:y,fromCache:!1,reason:R};if(it.set(c,{until:Date.now()+i,result:_}),!a){let T=`${R}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,W=R==="timeout"?`Timeout after ${o}ms. Consider increasing timeout or using a proxy for ${t}`:R==="abort"?`Request aborted while fetching ${n} ${t}`:`Network/CORS issue while fetching ${n} ${t}. A proxy may be required`;Pt.errorOnce(T,W)}return e.onError&&e.onError(_),_}finally{clearTimeout(k),Ct.delete(c)}})();return Ct.set(c,F),F}function H(t,e){if(!e||!t.width||!t.height)return t;let n=document.createElement("canvas");n.width=t.width,n.height=t.height;let o=n.getContext("2d");return o.fillStyle=e,o.fillRect(0,0,n.width,n.height),o.drawImage(t,0,0),n}async function G(t,e={}){if(/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t)||t.trim()==="none")return t;let o=V(t);if(!o)return t;let s=tt(o);if(f.background.has(s)){let i=f.background.get(s);return i?`url("${i}")`:"none"}try{let i=await B(s,{as:"dataURL",useProxy:e.useProxy});return i.ok?(f.background.set(s,i.data),`url("${i.data}")`):(f.background.set(s,null),"none")}catch{return f.background.set(s,null),"none"}}var ct=new Set(["meta","script","noscript","title","link","template"]),Z=new Set(["meta","link","style","title","noscript","script","template","svg","g","defs","use","marker","mask","clipPath","pattern","path","polygon","polyline","line","circle","ellipse","rect","filter","lineargradient","radialgradient","stop"]),le=["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","table","thead","tbody","tr","td","th"];function At(){for(let t of le){let e=String(t).toLowerCase();ct.has(e)||Z.has(e)||$t(e)}}function $t(t){if(t=String(t).toLowerCase(),Z.has(t)){let i={};return f.defaultStyle.set(t,i),i}if(f.defaultStyle.has(t))return f.defaultStyle.get(t);let e=document.getElementById("snapdom-sandbox");e||(e=document.createElement("div"),e.id="snapdom-sandbox",e.setAttribute("data-snapdom-sandbox","true"),e.setAttribute("aria-hidden","true"),e.style.position="absolute",e.style.left="-9999px",e.style.top="-9999px",e.style.width="0px",e.style.height="0px",e.style.overflow="hidden",document.body.appendChild(e));let n=document.createElement(t);n.style.all="initial",e.appendChild(n);let o=getComputedStyle(n),s={};for(let i of o){if(Ut(i))continue;let r=o.getPropertyValue(i);s[i]=r}return e.removeChild(n),f.defaultStyle.set(t,s),s}var fe=/(?:^|-)(animation|transition)(?:-|$)/i,ue=/^(--|view-timeline|scroll-timeline|animation-trigger|offset-|position-try|app-region|interactivity|overlay|view-transition|-webkit-locale|-webkit-user-(?:drag|modify)|-webkit-tap-highlight-color|-webkit-text-security)$/i,de=new Set(["cursor","pointer-events","touch-action","user-select","print-color-adjust","speak","reading-flow","reading-order","anchor-name","anchor-scope","container-name","container-type","timeline-scope"]);function Ut(t){let e=String(t).toLowerCase();return!!(de.has(e)||ue.test(e)||fe.test(e))}function Q(t,e){if(e=String(e||"").toLowerCase(),Z.has(e))return"";let n=[],o=$t(e);for(let[s,i]of Object.entries(t)){if(Ut(s))continue;let r=o[s];i&&i!==r&&n.push(`${s}:${i}`)}return n.sort(),n.join(";")}function Et(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 kt(t){let e=new Map;for(let o of t){let s=f.defaultStyle.get(o);if(!s)continue;let i=Object.entries(s).map(([r,a])=>`${r}:${a};`).sort().join("");i&&(e.has(i)||e.set(i,[]),e.get(i).push(o))}let n="";for(let[o,s]of e.entries())n+=`${s.join(",")} { ${o} }
|
|
2
|
+
`;return n}function Ft(t){let e=Array.from(new Set(t.values())).filter(Boolean).sort(),n=new Map,o=1;for(let s of e)n.set(s,`c${o++}`);return n}function K(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let n=f.computedStyle.get(t);if(n||(n=new Map,f.computedStyle.set(t,n)),!n.has(e)){let o=window.getComputedStyle(t,e);n.set(e,o)}return n.get(e)}function vt(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch{return e}return e}function lt(t){let e={};for(let n of t)e[n]=t.getPropertyValue(n);return e}function X(t){let e=[],n=0,o=0;for(let s=0;s<t.length;s++){let i=t[s];i==="("&&n++,i===")"&&n--,i===","&&n===0&&(e.push(t.slice(o,s).trim()),o=s+1)}return e.push(t.slice(o).trim()),e}function Y(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function j(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}var Bt=new WeakMap,Ot=new Map,Lt=0;function ft(){Lt++}var Wt=!1;function me(t=document.documentElement){if(!Wt){Wt=!0;try{new MutationObserver(()=>ft()).observe(t,{subtree:!0,childList:!0,characterData:!0,attributes:!0})}catch{}try{new MutationObserver(()=>ft()).observe(document.head,{subtree:!0,childList:!0,characterData:!0,attributes:!0})}catch{}try{let e=document.fonts;e&&(e.addEventListener?.("loadingdone",ft),e.ready?.then(()=>ft()).catch(()=>{}))}catch{}}}function he(t){let e={},n=t.getPropertyValue("visibility");for(let o=0;o<t.length;o++){let s=t[o],i=t.getPropertyValue(s);(s==="background-image"||s==="content")&&i.includes("url(")&&!i.includes("data:")&&(i="none"),e[s]=i}return n==="hidden"&&(e.opacity="0"),e}var qt=new WeakMap;function pe(t){let e=qt.get(t);return e||(e=Object.entries(t).sort((o,s)=>o[0]<s[0]?-1:o[0]>s[0]?1:0).map(([o,s])=>`${o}:${s}`).join(";"),qt.set(t,e),e)}function ge(t,e=null){let n=Bt.get(t);if(n&&n.epoch===Lt)return n.snapshot;let o=e||getComputedStyle(t),s=he(o);return Bt.set(t,{epoch:Lt,snapshot:s}),s}function ye(t,e){return t&&t.session&&t.persist?t:t&&(t.styleMap||t.styleCache||t.nodeMap)?{session:t,persist:{snapshotKeyCache:Ot,defaultStyle:f.defaultStyle,baseStyle:f.baseStyle,image:f.image,resource:f.resource,background:f.background,font:f.font},options:e||{}}:{session:f.session,persist:{snapshotKeyCache:Ot,defaultStyle:f.defaultStyle,baseStyle:f.baseStyle,image:f.image,resource:f.resource,background:f.background,font:f.font},options:t||e||{}}}async function ut(t,e,n,o){if(t.tagName==="STYLE")return;let s=ye(n,o);if((s.options&&s.options.cache||"auto")!=="disabled"&&me(document.documentElement),Z.has(t.tagName?.toLowerCase())){let S=t.getAttribute?.("style");S&&e.setAttribute("style",S)}let{session:r,persist:a}=s;r.styleCache.has(t)||r.styleCache.set(t,getComputedStyle(t));let c=r.styleCache.get(t),u=ge(t,c),p=pe(u),y=a.snapshotKeyCache.get(p);if(!y){let S=t.tagName?.toLowerCase()||"div";y=Q(u,S),a.snapshotKeyCache.set(p,y)}r.styleMap.set(e,y)}function we(t){return t=t.trim(),!t||/\:not\(\s*\[data-sd-slotted\]\s*\)\s*$/.test(t)?t:`${t}:not([data-sd-slotted])`}function Se(t,e,n=!0){return t.split(",").map(o=>o.trim()).filter(Boolean).map(o=>{if(o.startsWith(":where(")||o.startsWith("@"))return o;let s=n?we(o):o;return`:where(${e} ${s})`}).join(", ")}function be(t,e){return t?(t=t.replace(/:host\(([^)]+)\)/g,(n,o)=>`:where(${e}:is(${o.trim()}))`),t=t.replace(/:host\b/g,`:where(${e})`),t=t.replace(/:host-context\(([^)]+)\)/g,(n,o)=>`:where(:where(${o.trim()}) ${e})`),t=t.replace(/::slotted\(([^)]+)\)/g,(n,o)=>`:where(${e} ${o.trim()})`),t=t.replace(/(^|})(\s*)([^@}{]+){/g,(n,o,s,i)=>{let r=Se(i,e,!0);return`${o}${s}${r}{`}),t):""}function xe(t){return t.shadowScopeSeq=(t.shadowScopeSeq||0)+1,`s${t.shadowScopeSeq}`}function Ce(t){let e="";try{t.querySelectorAll("style").forEach(o=>{e+=(o.textContent||"")+`
|
|
3
|
+
`});let n=t.adoptedStyleSheets||[];for(let o of n)try{if(o&&o.cssRules)for(let s of o.cssRules)e+=s.cssText+`
|
|
4
|
+
`}catch{}}catch{}return e}function Ae(t,e,n){if(!e)return;let o=document.createElement("style");o.setAttribute("data-sd",n),o.textContent=e,t.insertBefore(o,t.firstChild||null)}function $e(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 Ee(t){let e=new Set;if(!t)return e;let n=/var\(\s*(--[A-Za-z0-9_-]+)\b/g,o;for(;o=n.exec(t);)e.add(o[1]);return e}function ke(t,e){try{let o=getComputedStyle(t).getPropertyValue(e).trim();if(o)return o}catch{}try{let o=getComputedStyle(document.documentElement).getPropertyValue(e).trim();if(o)return o}catch{}return""}function Fe(t,e,n){let o=[];for(let s of e){let i=ke(t,s);i&&o.push(`${s}: ${i};`)}return o.length?`${n}{${o.join("")}}
|
|
5
|
+
`:""}function ve(t){t&&(t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-sd-slotted",""),t.querySelectorAll&&t.querySelectorAll("*").forEach(e=>e.setAttribute("data-sd-slotted","")))}function et(t,e,n){if(!t)throw new Error("Invalid node");let o=new Set,s=null;if(t.nodeType===Node.ELEMENT_NODE){let r=(t.localName||t.tagName||"").toLowerCase();if(t.id==="snapdom-sandbox"||t.hasAttribute("data-snapdom-sandbox")||ct.has(r))return null}if(t.nodeType===Node.TEXT_NODE||t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);if(t.getAttribute("data-capture")==="exclude"){let r=document.createElement("div"),a=t.getBoundingClientRect();return r.style.cssText=`display:inline-block;width:${a.width}px;height:${a.height}px;visibility:hidden;`,r}if(n.exclude&&Array.isArray(n.exclude))for(let r of n.exclude)try{if(t.matches?.(r)){let a=document.createElement("div"),c=t.getBoundingClientRect();return a.style.cssText=`display:inline-block;width:${c.width}px;height:${c.height}px;visibility:hidden;`,a}}catch(a){console.warn(`Invalid selector in exclude option: ${r}`,a)}if(typeof n.filter=="function")try{if(!n.filter(t)){let r=document.createElement("div"),a=t.getBoundingClientRect();return r.style.cssText=`display:inline-block;width:${a.width}px;height:${a.height}px;visibility:hidden;`,r}}catch(r){console.warn("Error in filter function:",r)}if(t.tagName==="IFRAME"){let r=document.createElement("div");return r.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;`,r}if(t.getAttribute("data-capture")==="placeholder"){let r=t.cloneNode(!1);e.nodeMap.set(r,t),ut(t,r,e,n);let a=document.createElement("div");return a.textContent=t.getAttribute("data-placeholder-text")||"",a.style.cssText="color:#666;font-size:12px;text-align:center;line-height:1.4;padding:0.5em;box-sizing:border-box;",r.appendChild(a),r}if(t.tagName==="CANVAS"){let r=t.toDataURL(),a=document.createElement("img");return a.src=r,a.width=t.width,a.height=t.height,e.nodeMap.set(a,t),ut(t,a,e,n),a}let i;try{i=t.cloneNode(!1),e.nodeMap.set(i,t),t.tagName==="IMG"&&$e(t,i)}catch(r){throw console.error("[Snapdom] Failed to clone node:",t,r),r}if(t instanceof HTMLTextAreaElement){i.textContent=t.value,i.value=t.value;let r=t.getBoundingClientRect();return i.style.width=`${r.width}px`,i.style.height=`${r.height}px`,i}if(t instanceof HTMLInputElement&&(i.value=t.value,i.setAttribute("value",t.value),t.checked!==void 0&&(i.checked=t.checked,t.checked&&i.setAttribute("checked",""),t.indeterminate&&(i.indeterminate=t.indeterminate))),t instanceof HTMLSelectElement&&(s=t.value),ut(t,i,e,n),t.shadowRoot){try{let E=t.shadowRoot.querySelectorAll("slot");for(let k of E){let F=[];try{F=k.assignedNodes?.({flatten:!0})||k.assignedNodes?.()||[]}catch{F=k.assignedNodes?.()||[]}for(let b of F)o.add(b)}}catch{}let r=xe(e),a=`[data-sd="${r}"]`;try{i.setAttribute("data-sd",r)}catch{}let c=Ce(t.shadowRoot),u=be(c,a),p=Ee(c),y=Fe(t,p,a);Ae(i,y+u,r);let S=document.createDocumentFragment();for(let E of t.shadowRoot.childNodes){if(E.nodeType===Node.ELEMENT_NODE&&E.tagName==="STYLE")continue;let k=et(E,e,n);k&&S.appendChild(k)}i.appendChild(S)}if(t.tagName==="SLOT"){let r=t.assignedNodes?.({flatten:!0})||[],a=r.length>0?r:Array.from(t.childNodes),c=document.createDocumentFragment();for(let u of a){let p=et(u,e,n);p&&(ve(p),c.appendChild(p))}return c}for(let r of t.childNodes){if(o.has(r))continue;let a=et(r,e,n);a&&i.appendChild(a)}if(s!==null&&i instanceof HTMLSelectElement){i.value=s;for(let r of i.options)r.value===s?r.setAttribute("selected",""):r.removeAttribute("selected")}return i}var Le=[/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],Rt=[];function Dt(t){let e=Array.isArray(t)?t:[t];for(let n of e)n instanceof RegExp?Rt.push(n):typeof n=="string"?Rt.push(new RegExp(n,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",n)}function D(t){let e=typeof t=="string"?t:"",n=[...Le,...Rt];for(let o of n)if(o instanceof RegExp&&o.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 jt(t,e,n,o=32,s="#000"){e=e.replace(/^['"]+|['"]+$/g,"");let i=window.devicePixelRatio||1;await document.fonts.ready;let r=document.createElement("span");r.textContent=t,r.style.position="absolute",r.style.visibility="hidden",r.style.fontFamily=`"${e}"`,r.style.fontWeight=n||"normal",r.style.fontSize=`${o}px`,r.style.lineHeight="1",r.style.whiteSpace="nowrap",r.style.padding="0",r.style.margin="0",document.body.appendChild(r);let a=r.getBoundingClientRect(),c=Math.ceil(a.width),u=Math.ceil(a.height);document.body.removeChild(r);let p=document.createElement("canvas");p.width=c*i,p.height=u*i;let y=p.getContext("2d");return y.scale(i,i),y.font=n?`${n} ${o}px "${e}"`:`${o}px "${e}"`,y.textAlign="left",y.textBaseline="top",y.fillStyle=s,y.fillText(t,0,0),{dataUrl:p.toDataURL(),width:c,height:u}}var Re=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]);function dt(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!Re.has(n.toLowerCase()))return n}return""}function mt(t){let e=String(t??"400").trim().toLowerCase();if(e==="normal")return 400;if(e==="bold")return 700;let n=parseInt(e,10);return Number.isFinite(n)?Math.min(900,Math.max(100,n)):400}function Mt(t){let e=String(t??"normal").trim().toLowerCase();return e.startsWith("italic")?"italic":e.startsWith("oblique")?"oblique":"normal"}function Me(t){let e=String(t??"100%").match(/(\d+(?:\.\d+)?)\s*%/);return e?Math.max(50,Math.min(200,parseFloat(e[1]))):100}function Ne(t){let e=String(t||"400").trim(),n=e.match(/^(\d{2,3})\s+(\d{2,3})$/);if(n){let s=mt(n[1]),i=mt(n[2]);return{min:Math.min(s,i),max:Math.max(s,i)}}let o=mt(e);return{min:o,max:o}}function Te(t){let e=String(t||"normal").trim().toLowerCase();return e==="italic"?{kind:"italic"}:e.startsWith("oblique")?{kind:"oblique"}:{kind:"normal"}}function Ie(t){let e=String(t||"100%").trim(),n=e.match(/(\d+(?:\.\d+)?)\s*%\s+(\d+(?:\.\d+)?)\s*%/);if(n){let i=parseFloat(n[1]),r=parseFloat(n[2]);return{min:Math.min(i,r),max:Math.max(i,r)}}let o=e.match(/(\d+(?:\.\d+)?)\s*%/),s=o?parseFloat(o[1]):100;return{min:s,max:s}}function _e(t,e){if(!t)return!1;try{let n=new URL(t,location.href);if(n.origin===location.origin)return!0;let s=n.host.toLowerCase();if(["fonts.googleapis.com","fonts.gstatic.com","use.typekit.net","p.typekit.net","kit.fontawesome.com","use.fontawesome.com"].some(a=>s.endsWith(a)))return!0;let r=(n.pathname+n.search).toLowerCase();if(/\bfont(s)?\b/.test(r)||/\.woff2?(\b|$)/.test(r))return!0;for(let a of e){let c=a.toLowerCase().replace(/\s+/g,"+"),u=a.toLowerCase().replace(/\s+/g,"-");if(r.includes(c)||r.includes(u))return!0}return!1}catch{return!1}}function Pe(t){let e=new Set;for(let n of t||[]){let o=String(n).split("__")[0]?.trim();o&&e.add(o)}return e}async function ht({required:t,usedCodepoints:e,exclude:n=void 0,localFonts:o=[],useProxy:s=""}={}){t instanceof Set||(t=new Set),e instanceof Set||(e=new Set);let i=new Map;for(let l of t){let[m,h,w,d]=String(l).split("__");if(!m)continue;let g=i.get(m)||[];g.push({w:parseInt(h,10),s:w,st:parseInt(d,10)}),i.set(m,g)}let r=/@import\s+url\(["']?([^"')]+)["']?\)/g,a=/url\((["']?)([^"')]+)\1\)/g,c=/@font-face[^{}]*\{[^}]*\}/g;function u(l,m,h,w){if(!i.has(l))return!1;let d=i.get(l),g=Ne(h),C=Te(m),x=Ie(w),$=g.min!==g.max,v=g.min,N=A=>C.kind==="normal"&&A==="normal"||C.kind!=="normal"&&(A==="italic"||A==="oblique"),P=!1;for(let A of d){let L=$?A.w>=g.min&&A.w<=g.max:A.w===v,U=N(Mt(A.s)),O=A.st>=x.min&&A.st<=x.max;if(L&&U&&O){P=!0;break}}if(P)return!0;if(!$)for(let A of d){let L=N(Mt(A.s)),U=A.st>=x.min&&A.st<=x.max;if(Math.abs(v-A.w)<=300&&L&&U)return!0}return!1}function p(l){if(!l)return[];let m=[],h=l.split(",").map(w=>w.trim()).filter(Boolean);for(let w of h){let d=w.match(/^U\+([0-9A-Fa-f?]+)(?:-([0-9A-Fa-f?]+))?$/);if(!d)continue;let g=d[1],C=d[2],x=$=>{if(!$.includes("?"))return parseInt($,16);let v=parseInt($.replace(/\?/g,"0"),16),N=parseInt($.replace(/\?/g,"F"),16);return[v,N]};if(C){let $=x(g),v=x(C),N=Array.isArray($)?$[0]:$,P=Array.isArray(v)?v[1]:v;m.push([Math.min(N,P),Math.max(N,P)])}else{let $=x(g);Array.isArray($)?m.push([$[0],$[1]]):m.push([$,$])}}return m}function y(l,m){if(!m.length||!l||l.size===0)return!0;for(let h of l)for(let[w,d]of m)if(h>=w&&h<=d)return!0;return!1}function S(l,m){let h=[];if(!l)return h;for(let w of l.matchAll(a)){let d=(w[2]||"").trim();if(!(!d||d.startsWith("data:"))){if(!/^https?:/i.test(d))try{d=new URL(d,m||location.href).href}catch{}h.push(d)}}return h}async function E(l,m){let h=l;for(let w of l.matchAll(a)){let d=V(w[0]);if(!d)continue;let g=d;if(!g.startsWith("http")&&!g.startsWith("data:"))try{g=new URL(g,m||location.href).href}catch{}if(!D(g)){if(f.resource?.has(g)){f.font?.add(g),h=h.replace(w[0],`url(${f.resource.get(g)})`);continue}if(!f.font?.has(g))try{let C=await B(g,{as:"dataURL",useProxy:s,silent:!0});if(C.ok&&typeof C.data=="string"){let x=C.data;f.resource?.set(g,x),f.font?.add(g),h=h.replace(w[0],`url(${x})`)}}catch{console.warn("[snapDOM] Failed to fetch font resource:",g)}}}return h}function k(l){if(!l.length)return null;let m=(x,$)=>l.some(([v,N])=>!(N<x||v>$)),h=m(0,255)||m(305,305),w=m(256,591)||m(7680,7935),d=m(880,1023),g=m(1024,1279);return m(7840,7929)||m(258,259)||m(416,417)||m(431,432)?"vietnamese":g?"cyrillic":d?"greek":w?"latin-ext":h?"latin":null}function F(l={}){let m=new Set((l.families||[]).map(d=>String(d).toLowerCase())),h=new Set((l.domains||[]).map(d=>String(d).toLowerCase())),w=new Set((l.subsets||[]).map(d=>String(d).toLowerCase()));return(d,g)=>{if(m.size&&m.has(d.family.toLowerCase()))return!0;if(h.size)for(let C of d.srcUrls)try{if(h.has(new URL(C).host.toLowerCase()))return!0}catch{}if(w.size){let C=k(g);if(C&&w.has(C))return!0}return!1}}let b=F(n);function R(l){if(!l)return l;let m=/@font-face[^{}]*\{[^}]*\}/gi,h=new Set,w=[];for(let g of l.match(m)||[]){let C=g.match(/font-family:\s*([^;]+);/i)?.[1]||"",x=dt(C),$=(g.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),v=(g.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),N=(g.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),P=(g.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),A=(g.match(/src\s*:\s*([^;]+);/i)?.[1]||"").trim(),L=S(A,location.href),U=L.length?L.map(Tt=>String(Tt).toLowerCase()).sort().join("|"):A.toLowerCase(),O=[String(x||"").toLowerCase(),$,v,N,P.toLowerCase(),U].join("|");h.has(O)||(h.add(O),w.push(g))}if(w.length===0)return l;let d=0;return l.replace(m,()=>w[d++]||"")}function _(){let l=Array.from(t||[]).sort().join("|"),m=n?JSON.stringify({families:(n.families||[]).map(d=>String(d).toLowerCase()).sort(),domains:(n.domains||[]).map(d=>String(d).toLowerCase()).sort(),subsets:(n.subsets||[]).map(d=>String(d).toLowerCase()).sort()}):"",h=(o||[]).map(d=>`${(d.family||"").toLowerCase()}::${d.weight||"normal"}::${d.style||"normal"}::${d.src||""}`).sort().join("|");return`fonts-embed-css::req=${l}::ex=${m}::lf=${h}::px=${s||""}`}let T=_();if(f.resource?.has(T))return f.resource.get(T);let W=Pe(t),q=[];for(let l of document.querySelectorAll("style")){let m=l.textContent||"";for(let h of m.matchAll(r)){let w=h[1];if(!w||D(w))continue;!!document.querySelector(`link[rel="stylesheet"][href="${w}"]`)||q.push(w)}}q.length&&await Promise.all(q.map(l=>new Promise(m=>{if(document.querySelector(`link[rel="stylesheet"][href="${l}"]`))return m(null);let h=document.createElement("link");h.rel="stylesheet",h.href=l,h.setAttribute("data-snapdom","injected-import"),h.onload=()=>m(h),h.onerror=()=>m(null),document.head.appendChild(h)})));let I="",J=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(l=>!!l.href);for(let l of J)try{if(D(l.href))continue;let m="",h=!1;try{h=new URL(l.href,location.href).origin===location.origin}catch{}if(!h&&!_e(l.href,W))continue;if(h){let d=Array.from(document.styleSheets).find(g=>g.href===l.href);if(d)try{let g=d.cssRules||[];m=Array.from(g).map(C=>C.cssText).join("")}catch{}}if(!m&&(m=(await B(l.href,{as:"text",useProxy:s})).data,D(l.href)))continue;let w="";for(let d of m.match(c)||[]){let g=(d.match(/font-family:\s*([^;]+);/i)?.[1]||"").trim(),C=dt(g);if(!C||D(C))continue;let x=(d.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),$=(d.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),v=(d.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),N=(d.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),P=(d.match(/src\s*:\s*([^;]+);/i)?.[1]||"").trim(),A=S(P,l.href);if(!u(C,$,x,v))continue;let L=p(N);if(!y(e,L))continue;let U={family:C,weightSpec:x,styleSpec:$,stretchSpec:v,unicodeRange:N,srcRaw:P,srcUrls:A,href:l.href};if(n&&b(U,L))continue;let O=/url\(/i.test(P)?await E(d,l.href):d;w+=O+""}w.trim()&&(I+=w+"")}catch{console.warn("[snapdom] Failed to process stylesheet:",l.href)}for(let l of document.styleSheets)try{if(l.href&&J.some(h=>h.href===l.href))continue;let m=l.cssRules||[];for(let h of m){if(h.type!==CSSRule.FONT_FACE_RULE)continue;let w=(h.style.getPropertyValue("font-family")||"").trim(),d=dt(w);if(!d||D(d))continue;let g=(h.style.getPropertyValue("font-weight")||"400").trim(),C=(h.style.getPropertyValue("font-style")||"normal").trim(),x=(h.style.getPropertyValue("font-stretch")||"100%").trim(),$=(h.style.getPropertyValue("src")||"").trim(),v=(h.style.getPropertyValue("unicode-range")||"").trim(),N=S($,l.href||location.href);if(!u(d,C,g,x))continue;let P=p(v);if(!y(e,P))continue;let A={family:d,weightSpec:g,styleSpec:C,stretchSpec:x,unicodeRange:v,srcRaw:$,srcUrls:N,href:l.href||location.href};if(!(n&&b(A,P)))if(/url\(/i.test($)){let L=await E($,l.href||location.href);I+=`@font-face{font-family:${d};src:${L};font-style:${C};font-weight:${g};font-stretch:${x};${v?`unicode-range:${v};`:""}}`}else I+=`@font-face{font-family:${d};src:${$};font-style:${C};font-weight:${g};font-stretch:${x};${v?`unicode-range:${v};`:""}}`}}catch{}try{for(let l of document.fonts||[]){if(!l||!l.family||l.status!=="loaded"||!l._snapdomSrc)continue;let m=String(l.family).replace(/^['"]+|['"]+$/g,"");if(D(m)||!i.has(m)||n?.families&&n.families.some(w=>String(w).toLowerCase()===m.toLowerCase()))continue;let h=l._snapdomSrc;if(!String(h).startsWith("data:")){if(f.resource?.has(l._snapdomSrc))h=f.resource.get(l._snapdomSrc),f.font?.add(l._snapdomSrc);else if(!f.font?.has(l._snapdomSrc))try{let w=await B(l._snapdomSrc,{as:"dataURL",useProxy:s,silent:!0});if(w.ok&&typeof w.data=="string")h=w.data,f.resource?.set(l._snapdomSrc,h),f.font?.add(l._snapdomSrc);else continue}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",l._snapdomSrc);continue}}I+=`@font-face{font-family:'${m}';src:url(${h});font-style:${l.style||"normal"};font-weight:${l.weight||"normal"};}`}}catch{}for(let l of o){if(!l||typeof l!="object")continue;let m=String(l.family||"").replace(/^['"]+|['"]+$/g,"");if(!m||D(m)||!i.has(m)||n?.families&&n.families.some(x=>String(x).toLowerCase()===m.toLowerCase()))continue;let h=l.weight!=null?String(l.weight):"normal",w=l.style!=null?String(l.style):"normal",d=l.stretchPct!=null?`${l.stretchPct}%`:"100%",g=String(l.src||""),C=g;if(!C.startsWith("data:")){if(f.resource?.has(g))C=f.resource.get(g),f.font?.add(g);else if(!f.font?.has(g))try{let x=await B(g,{as:"dataURL",useProxy:s,silent:!0});if(x.ok&&typeof x.data=="string")C=x.data,f.resource?.set(g,C),f.font?.add(g);else continue}catch{console.warn("[snapdom] Failed to fetch localFonts src:",g);continue}}I+=`@font-face{font-family:'${m}';src:url(${C});font-style:${w};font-weight:${h};font-stretch:${d};}`}return I&&(I=R(I),f.resource?.set(T,I)),I}function pt(t){let e=new Set;if(!t)return e;let n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null),o=r=>{let a=dt(r.fontFamily);if(!a)return;let c=(u,p,y)=>`${a}__${mt(u)}__${Mt(p)}__${Me(y)}`;e.add(c(r.fontWeight,r.fontStyle,r.fontStretch))};o(getComputedStyle(t));let s=getComputedStyle(t,"::before");s&&s.content&&s.content!=="none"&&o(s);let i=getComputedStyle(t,"::after");for(i&&i.content&&i.content!=="none"&&o(i);n.nextNode();){let r=n.currentNode,a=getComputedStyle(r);o(a);let c=getComputedStyle(r,"::before");c&&c.content&&c.content!=="none"&&o(c);let u=getComputedStyle(r,"::after");u&&u.content&&u.content!=="none"&&o(u)}return e}function gt(t){let e=new Set,n=s=>{if(s)for(let i of s)e.add(i.codePointAt(0))},o=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,null);for(;o.nextNode();){let s=o.currentNode;if(s.nodeType===Node.TEXT_NODE)n(s.nodeValue||"");else if(s.nodeType===Node.ELEMENT_NODE){let i=s;for(let r of["::before","::after"]){let c=getComputedStyle(i,r)?.getPropertyValue("content");if(!(!c||c==="none"))if(/^"/.test(c)||/^'/.test(c))n(c.slice(1,-1));else{let u=c.match(/\\[0-9A-Fa-f]{1,6}/g);if(u)for(let p of u)try{e.add(parseInt(p.slice(1),16))}catch{}}}}}return e}async function yt(t,e=1){try{await document.fonts.ready}catch{}let n=Array.from(t||[]).filter(Boolean);if(n.length===0)return;let o=()=>{let s=document.createElement("div");s.style.cssText="position: absolute !important;left: -9999px !important;top: 0 !important;opacity: 0 !important;pointer-events: none !important;contain: layout size style;";for(let i of n){let r=document.createElement("span");r.textContent="AaBbGg1234\xC1\xC9\xCD\xD3\xDA\xE7\xF1\u2014\u221E",r.style.fontFamily=`"${i}"`,r.style.fontWeight="700",r.style.fontStyle="italic",r.style.fontSize="32px",r.style.lineHeight="1",r.style.whiteSpace="nowrap",r.style.margin="0",r.style.padding="0",s.appendChild(r)}document.body.appendChild(s),s.offsetWidth,document.body.removeChild(s)};for(let s=0;s<Math.max(1,e);s++)o(),await new Promise(i=>requestAnimationFrame(()=>requestAnimationFrame(i)))}async function Nt(t,e,n,o){if(!(t instanceof Element)||!(e instanceof Element))return;for(let r of["::before","::after","::first-letter"])try{let a=K(t,r);if(!a||typeof a[Symbol.iterator]!="function"||a.content==="none"&&a.backgroundImage==="none"&&a.backgroundColor==="transparent"&&(a.borderStyle==="none"||parseFloat(a.borderWidth)===0)&&(!a.transform||a.transform==="none")&&a.display==="inline")continue;if(r==="::first-letter"){let A=getComputedStyle(t);if(!(a.color!==A.color||a.fontSize!==A.fontSize||a.fontWeight!==A.fontWeight))continue;let U=Array.from(e.childNodes).find(_t=>_t.nodeType===Node.TEXT_NODE&&_t.textContent?.trim().length>0);if(!U)continue;let O=U.textContent,rt=O.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],te=O.slice(rt?.length||0);if(!rt||/[\uD800-\uDFFF]/.test(rt))continue;let st=document.createElement("span");st.textContent=rt,st.dataset.snapdomPseudo="::first-letter";let ee=lt(a),ne=Q(ee,"span");n.styleMap.set(st,ne);let It=document.createTextNode(te);e.replaceChild(It,U),e.insertBefore(st,It);continue}let u=a.content,p=/counter\s*\(|counters\s*\(/.test(u)?"- ":vt(u),y=a.backgroundImage,S=a.backgroundColor,E=a.fontFamily,k=parseInt(a.fontSize)||32,F=parseInt(a.fontWeight)||!1,b=a.color||"#000",R=a.display,_=parseFloat(a.width),T=parseFloat(a.height),W=a.borderStyle,q=parseFloat(a.borderWidth),I=a.transform,J=D(E),l=u!=="none"&&p!=="",m=y&&y!=="none",h=S&&S!=="transparent"&&S!=="rgba(0, 0, 0, 0)",w=R!=="inline"&&(_>0||T>0),d=W&&W!=="none"&&q>0,g=I&&I!=="none";if(!(l||m||h||w||d||g))continue;let x=document.createElement("span");x.dataset.snapdomPseudo=r,x.style.verticalAlign="middle";let $=lt(a),v=Q($,"span");if(n.styleMap.set(x,v),J&&p.length===1){let{dataUrl:A,width:L,height:U}=await jt(p,E,F,k,b),O=document.createElement("img");O.src=A,O.style=`height:${k}px;width:${L/U*k}px;object-fit:contain;`,x.appendChild(O),e.dataset.snapdomHasIcon="true"}else if(p.startsWith("url(")){let A=V(p);if(A?.trim())try{let L=document.createElement("img"),U=await B(tt(A),{as:"dataURL",useProxy:o.useProxy});L.src=U.data,L.style=`width:${k}px;height:auto;object-fit:contain;`,x.appendChild(L)}catch(L){console.error(`[snapdom] Error in pseudo ${r} for`,t,L)}}else!J&&l&&(x.textContent=p);if(m)try{let A=X(y),L=await Promise.all(A.map(G));x.style.backgroundImage=L.join(", ")}catch(A){console.warn(`[snapdom] Failed to inline background-image for ${r}`,A)}if(h&&(x.style.backgroundColor=S),!(x.childNodes.length>0||x.textContent?.trim()!==""||m||h||w||d||g))continue;r==="::before"?e.insertBefore(x,e.firstChild):e.appendChild(x)}catch(a){console.warn(`[snapdom] Failed to capture ${r} for`,t,a)}let s=Array.from(t.children),i=Array.from(e.children).filter(r=>!r.dataset.snapdomPseudo);for(let r=0;r<Math.min(s.length,i.length);r++)await Nt(s[r],i[r],n,o)}function zt(t){if(!t)return;let e=new Set;if(t.querySelectorAll("use").forEach(a=>{let c=a.getAttribute("xlink:href")||a.getAttribute("href");c&&c.startsWith("#")&&e.add(c.slice(1))}),!e.size)return;let n=Array.from(document.querySelectorAll("svg > symbol, svg > defs")),o=n.filter(a=>a.tagName.toLowerCase()==="symbol"),s=n.filter(a=>a.tagName.toLowerCase()==="defs"),i=t.querySelector("svg.inline-defs-container");i||(i=document.createElementNS("http://www.w3.org/2000/svg","svg"),i.setAttribute("aria-hidden","true"),i.setAttribute("style","position: absolute; width: 0; height: 0; overflow: hidden;"),i.classList.add("inline-defs-container"),t.insertBefore(i,t.firstChild));let r=new Set;t.querySelectorAll("symbol[id], defs > *[id]").forEach(a=>{r.add(a.id)}),e.forEach(a=>{if(r.has(a))return;let c=o.find(u=>u.id===a);if(c){i.appendChild(c.cloneNode(!0)),r.add(a);return}for(let u of s){let p=u.querySelector(`#${CSS.escape(a)}`);if(p){let y=i.querySelector("defs");y||(y=document.createElementNS("http://www.w3.org/2000/svg","defs"),i.appendChild(y)),y.appendChild(p.cloneNode(!0)),r.add(a);break}}})}async function Ht(t,e={}){let n={styleMap:f.session.styleMap,styleCache:f.session.styleCache,nodeMap:f.session.nodeMap},o,s="",i="";Ue(t);try{zt(t)}catch(a){console.warn("inlineExternal defs or symbol failed:",a)}try{o=et(t,n,e,t)}catch(a){throw console.warn("deepClone failed:",a),a}try{await Nt(t,o,n,e)}catch(a){console.warn("inlinePseudoElements failed:",a)}await qe(o);try{let a=o.querySelectorAll("style[data-sd]");for(let c of a)i+=c.textContent||"",c.remove()}catch{}let r=Ft(n.styleMap);s=Array.from(r.entries()).map(([a,c])=>`.${c}{${a}}`).join(""),s=i+s;for(let[a,c]of n.styleMap.entries()){if(a.tagName==="STYLE")continue;if(a.getRootNode&&a.getRootNode()instanceof ShadowRoot){a.setAttribute("style",c.replace(/;/g,"; "));continue}let u=r.get(c);u&&a.classList.add(u);let p=a.style?.backgroundImage,y=a.dataset?.snapdomHasIcon;p&&p!=="none"&&(a.style.backgroundImage=p),y&&(a.style.verticalAlign="middle",a.style.display="inline")}for(let[a,c]of n.nodeMap.entries()){let u=c.scrollLeft,p=c.scrollTop;if((u||p)&&a instanceof HTMLElement){a.style.overflow="hidden",a.style.scrollbarWidth="none",a.style.msOverflowStyle="none";let S=document.createElement("div");for(S.style.transform=`translate(${-u}px, ${-p}px)`,S.style.willChange="transform",S.style.display="inline-block",S.style.width="100%";a.firstChild;)S.appendChild(a.firstChild);a.appendChild(S)}}if(t===n.nodeMap.get(o)){let a=n.styleCache.get(t)||window.getComputedStyle(t);n.styleCache.set(t,a);let c=xt(a.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=c||""}for(let[a,c]of n.nodeMap.entries())c.tagName==="PRE"&&(a.style.marginTop="0",a.style.marginBlockStart="0");return{clone:o,classCSS:s,styleCache:n.styleCache}}function Ue(t){let e=getComputedStyle(t),n=e.outlineStyle,o=e.outlineWidth,s=e.borderStyle,i=e.borderWidth,r=n!=="none"&&parseFloat(o)>0,a=s==="none"||parseFloat(i)===0;r&&a&&(t.style.border=`${o} solid transparent`)}var nt=new Map;async function ot(t){if(f.resource?.has(t))return f.resource.get(t);if(nt.has(t))return nt.get(t);let e=(async()=>{let n=await B(t,{as:"dataURL",silent:!0});if(!n.ok||typeof n.data!="string")throw new Error(`[snapDOM] Failed to read blob URL: ${t}`);return f.resource?.set(t,n.data),n.data})();nt.set(t,e);try{let n=await e;return nt.set(t,n),n}catch(n){throw nt.delete(t),n}}var Be=/\bblob:[^)"'\s]+/g;async function Vt(t){if(!t||t.indexOf("blob:")===-1)return t;let e=Array.from(new Set(t.match(Be)||[]));if(e.length===0)return t;let n=t;for(let o of e)try{let s=await ot(o);n=n.split(o).join(s)}catch{}return n}function wt(t){return typeof t=="string"&&t.startsWith("blob:")}function Oe(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 We(t){return t.map(e=>e.desc?`${e.url} ${e.desc.trim()}`:e.url).join(", ")}async function qe(t){if(!t)return;let e=t.querySelectorAll?t.querySelectorAll("img"):[];for(let r of e)try{let c=r.getAttribute("src")||r.currentSrc||"";if(wt(c)){let p=await ot(c);r.setAttribute("src",p)}let u=r.getAttribute("srcset");if(u&&u.includes("blob:")){let p=Oe(u),y=!1;for(let S of p)if(wt(S.url))try{S.url=await ot(S.url),y=!0}catch{}y&&r.setAttribute("srcset",We(p))}}catch{}let n=t.querySelectorAll?t.querySelectorAll("image"):[];for(let r of n)try{let a="http://www.w3.org/1999/xlink",c=r.getAttribute("href")||r.getAttributeNS?.(a,"href");if(wt(c)){let u=await ot(c);r.setAttribute("href",u),r.removeAttributeNS?.(a,"href")}}catch{}let o=t.querySelectorAll?t.querySelectorAll("[style*='blob:']"):[];for(let r of o)try{let a=r.getAttribute("style");if(a&&a.includes("blob:")){let c=await Vt(a);r.setAttribute("style",c)}}catch{}let s=t.querySelectorAll?t.querySelectorAll("style"):[];for(let r of s)try{let a=r.textContent||"";a.includes("blob:")&&(r.textContent=await Vt(a))}catch{}let i=["poster"];for(let r of i){let a=t.querySelectorAll?t.querySelectorAll(`[${r}^='blob:']`):[];for(let c of a)try{let u=c.getAttribute(r);wt(u)&&c.setAttribute(r,await ot(u))}catch{}}}async function Gt(t,e={}){let n=Array.from(t.querySelectorAll("img")),o=async s=>{if(!s.getAttribute("src")){let p=s.currentSrc||s.src||"";p&&s.setAttribute("src",p)}s.removeAttribute("srcset"),s.removeAttribute("sizes");let i=s.src||"";if(!i)return;let r=await B(i,{as:"dataURL",useProxy:e.useProxy});if(r.ok&&typeof r.data=="string"&&r.data.startsWith("data:")){s.src=r.data,s.width||(s.width=s.naturalWidth||100),s.height||(s.height=s.naturalHeight||100);return}let a=s.width||s.naturalWidth||100,c=s.height||s.naturalHeight||100,u=document.createElement("div");u.style.cssText=[`width:${a}px`,`height:${c}px`,"background:#ccc","display:inline-block","text-align:center",`line-height:${c}px`,"color:#666","font-size:12px","overflow:hidden"].join(";"),u.textContent="img",s.replaceWith(u)};for(let s=0;s<n.length;s+=4){let i=n.slice(s,s+4).map(o);await Promise.allSettled(i)}}async function St(t,e,n,o={}){let s=[[t,e]],i=["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(;s.length;){let[r,a]=s.shift(),c=n.get(r)||K(r);n.has(r)||n.set(r,c);let u=(()=>{let S=c.getPropertyValue("border-image"),E=c.getPropertyValue("border-image-source");return S&&S!=="none"||E&&E!=="none"})();for(let S of i){if(["border-image-slice","border-image-width","border-image-outset","border-image-repeat"].includes(S)&&!u)continue;let E=c.getPropertyValue(S);if(!E||E==="none")continue;let k=X(E),F=await Promise.all(k.map(b=>G(b,o)));F.some(b=>b&&b!=="none"&&!/^url\(undefined/.test(b))&&a.style.setProperty(S,F.join(", "))}let p=Array.from(r.children),y=Array.from(a.children);for(let S=0;S<Math.min(p.length,y.length);S++)s.push([p[S],y[S]])}}async function Kt(t,e){if(!t)throw new Error("Element cannot be null or undefined");at(e.cache);let n=e.fast,o,s,i,r="",a="",c,u;({clone:o,classCSS:s,styleCache:i}=await Ht(t,e)),await new Promise(E=>{Y(async()=>{await Gt(o,e),E()},{fast:n})}),await new Promise(E=>{Y(async()=>{await St(t,o,i,e),E()},{fast:n})}),e.embedFonts&&await new Promise(E=>{Y(async()=>{let k=pt(t),F=gt(t);if(j){let b=new Set(Array.from(k).map(R=>String(R).split("__")[0]).filter(Boolean));await yt(b,2)}r=await ht({required:k,usedCodepoints:F,preCached:!1,exclude:e.excludeFonts,useProxy:e.useProxy}),E()},{fast:n})});let p=Et(o).sort(),y=p.join(",");f.baseStyle.has(y)?a=f.baseStyle.get(y):await new Promise(E=>{Y(()=>{a=kt(p),f.baseStyle.set(y,a),E()},{fast:n})}),await new Promise(E=>{Y(()=>{let k=t.getBoundingClientRect(),F=k.width,b=k.height,R=Number.isFinite(e.width),_=Number.isFinite(e.height),T=typeof scale=="number"&&scale!==1;if(!T){let w=k.width/k.height;R&&_?(F=e.width,b=e.height):R?(F=e.width,b=F/w):_&&(b=e.height,F=b*w)}if(F=Math.ceil(F),b=Math.ceil(b),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="top left",!T&&(R||_)){let w=k.width,d=k.height,g=F/w,C=b/d,x=o.style.transform||"",$=`scale(${g}, ${C})`;o.style.transform=`${$} ${x}`.trim()}let W="http://www.w3.org/2000/svg",q=document.createElementNS(W,"foreignObject");q.setAttribute("width","100%"),q.setAttribute("height","100%");let I=document.createElement("style");I.textContent=a+r+"svg{overflow:visible;}"+s,q.appendChild(I),q.appendChild(o);let l=new XMLSerializer().serializeToString(q);u=`<svg xmlns="${W}" width="${F}" height="${b}" viewBox="0 0 ${F} ${b}">`+l+"</svg>",c=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`,E()},{fast:n})});let S=document.getElementById("snapdom-sandbox");return S&&S.style.position==="absolute"&&S.remove(),c}function De(t){if(t===!0)return"soft";if(t===!1)return"disabled";if(typeof t=="string"){let e=t.toLowerCase().trim();if(e==="disabled"||e==="full"||e==="auto"||e==="soft")return e}return"soft"}function Xt(t={}){let e=t.format??"png",n=De(t.cache);return{debug:t.debug??!1,fast:t.fast??!0,scale:t.scale??1,exclude:t.exclude??[],filter:t.filter??null,embedFonts:t.embedFonts??!1,iconFonts:Array.isArray(t.iconFonts)?t.iconFonts:t.iconFonts?[t.iconFonts]:[],localFonts:Array.isArray(t.localFonts)?t.localFonts:[],excludeFonts:t.excludeFonts??void 0,cache:n,useProxy:typeof t.useProxy=="string"?t.useProxy:"",width:t.width??null,height:t.height??null,format:e,type:t.type??"svg",quality:t.quality??.92,dpr:t.dpr??(window.devicePixelRatio||1),backgroundColor:t.backgroundColor??(["jpg","jpeg","webp"].includes(e)?"#ffffff":null),filename:t.filename??"snapDOM"}}async function Yt(t,e){let n=new Image;return n.src=t,await n.decode(),e.scale!==1&&(n.style.width=`${n.naturalWidth*e.scale}px`,n.style.height=`${n.naturalHeight*e.scale}px`),n}async function z(t,e){let n=new Image;n.crossOrigin="anonymous",n.loading="eager",n.decoding="sync",n.src=t;let o=j(),s=!1;o&&(document.body.appendChild(n),s=!0),await n.decode(),o&&await new Promise(p=>setTimeout(p,100));let i=n.naturalWidth*e.scale,r=n.naturalHeight*e.scale,a=document.createElement("canvas"),c=e.dpr;a.width=Math.ceil(i*c),a.height=Math.ceil(r*c),a.style.width=`${i}px`,a.style.height=`${r}px`;let u=a.getContext("2d");return u.scale(c,c),u.drawImage(n,0,0,i,r),s&&n.remove(),a}async function bt(t,e){let n=e.type;if(n==="svg"){let i=decodeURIComponent(t.split(",")[1]);return new Blob([i],{type:"image/svg+xml"})}let o=await z(t,e),s=e.backgroundColor?H(o,e.backgroundColor):o;return new Promise(i=>s.toBlob(r=>i(r),`image/${n}`,e.quality))}async function Jt(t,e){let n=await z(t,e),o=e.backgroundColor?H(n,e.backgroundColor):n,s=new Image;return s.src=o.toDataURL(`image/${e.format}`,e.quality),await s.decode(),s.style.width=`${o.width/e.dpr}px`,s.style.height=`${o.height/e.dpr}px`,s}async function Zt(t,e){if(e.format==="svg"){let i=await bt(t,{...e,type:"svg"}),r=URL.createObjectURL(i),a=document.createElement("a");a.href=r,a.download=e.filename,a.click(),URL.revokeObjectURL(r);return}let n=await z(t,e),o=e.backgroundColor?H(n,e.backgroundColor):n,s=document.createElement("a");s.href=o.toDataURL(`image/${e.format}`,e.quality),s.download=e.filename,s.click()}var Qt=Symbol("snapdom.internal");async function M(t,e){if(!t)throw new Error("Element cannot be null or undefined");let n=Xt(e);return n.iconFonts&&n.iconFonts.length>0&&Dt(n.iconFonts),M.capture(t,n,Qt)}M.capture=async(t,e,n)=>{if(n!==Qt)throw new Error("[snapdom.capture] is internal. Use snapdom(...) instead.");let o=await Kt(t,e),s=r=>({...e,...r||{}}),i=r=>a=>Jt(o,s({...a||{},format:r}));return{url:o,toRaw:()=>o,toImg:r=>Yt(o,s(r)),toCanvas:r=>z(o,s(r)),toBlob:r=>bt(o,s(r)),toPng:i("png"),toJpg:i("jpeg"),toWebp:i("webp"),download:r=>Zt(o,s(r))}};M.toRaw=(t,e)=>M(t,e).then(n=>n.toRaw());M.toImg=(t,e)=>M(t,e).then(n=>n.toImg());M.toCanvas=(t,e)=>M(t,e).then(n=>n.toCanvas());M.toBlob=(t,e)=>M(t,e).then(n=>n.toBlob());M.toPng=(t,e)=>M(t,{...e,format:"png"}).then(n=>n.toPng());M.toJpg=(t,e)=>M(t,{...e,format:"jpeg"}).then(n=>n.toJpg());M.toWebp=(t,e)=>M(t,{...e,format:"webp"}).then(n=>n.toWebp());M.download=(t,e)=>M(t,e).then(n=>n.download());async function je(t=document,e={}){let{embedFonts:n=!0,cacheOpt:o="full",useProxy:s=""}=e;at(o);try{await document.fonts.ready}catch{}At(),f.session=f.session||{},f.session.styleCache||(f.session.styleCache=new WeakMap);try{await St(t,void 0,f.session.styleCache,{useProxy:s})}catch{}let i=[],r=[];try{t?.querySelectorAll&&(i=Array.from(t.querySelectorAll("img[src]")),r=Array.from(t.querySelectorAll("*")))}catch{}let a=[];for(let c of i){let u=c?.src;if(u&&!f.image.has(u)){let p=Promise.resolve().then(()=>B(u,{as:"dataURL",useProxy:s})).then(y=>{f.image.set(u,y)}).catch(()=>{});a.push(p)}}for(let c of r){let u="";try{u=K(c).backgroundImage}catch{}if(u&&u!=="none"){let p=X(u);for(let y of p)if(y.startsWith("url(")){let S=Promise.resolve().then(()=>G(y,{...e,useProxy:s})).catch(()=>{});a.push(S)}}}if(n)try{let c=pt(t),u=gt(t);if(typeof j=="function"?j():j){let p=new Set(Array.from(c).map(y=>String(y).split("__")[0]).filter(Boolean));await yt(p,2)}await ht({required:c,usedCodepoints:u,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:e.useProxy??s})}catch{}await Promise.allSettled(a)}export{je as preCache,M as snapdom};
|