@zumer/snapdom 1.9.11 → 1.9.12-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 +7 -3
- package/dist/snapdom.js +201 -61
- package/dist/snapdom.min.js +4 -4
- package/dist/snapdom.min.mjs +4 -4
- package/dist/snapdom.mjs +185 -46
- package/package.json +1 -1
- package/types/snapdom.d.ts +15 -0
package/dist/snapdom.min.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
`;return n}function
|
|
1
|
+
var d={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 lt(t="soft"){switch(t){case"auto":{d.session.styleMap=new Map,d.session.nodeMap=new Map;return}case"soft":{d.session.styleMap=new Map,d.session.nodeMap=new Map,d.session.styleCache=new WeakMap;return}case"full":return;case"disabled":{d.session.styleMap=new Map,d.session.nodeMap=new Map,d.session.styleCache=new WeakMap,d.computedStyle=new WeakMap,d.baseStyle=new Map,d.defaultStyle=new Map,d.image=new Map,d.background=new Map,d.resource=new Map,d.font=new Set;return}default:{d.session.styleMap=new Map,d.session.nodeMap=new Map,d.session.styleCache=new WeakMap;return}}}function Y(t){let e=t.match(/url\((['"]?)(.*?)(\1)\)/);if(!e)return null;let n=e[2].trim();return n.startsWith("#")?null:n}function At(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(i=>i.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(i=>i.trim());return r.length!==16?`matrix3d(${o})`:(r[12]="0",r[13]="0",`matrix3d(${r.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function K(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function ce(t="[snapDOM]",{ttlMs:e=5*6e4,maxEntries:n=12}={}){let o=new Map,r=0;function i(a,s,f){if(r>=n)return;let c=Date.now();(o.get(s)||0)>c||(o.set(s,c+e),r++,a==="warn"&&console&&console.warn?console.warn(`${t} ${f}`):console&&console.error&&console.error(`${t} ${f}`))}return{warnOnce(a,s){i("warn",a,s)},errorOnce(a,s){i("error",a,s)},reset(){o.clear(),r=0}}}var qt=ce("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),kt=new Map,ft=new Map;function le(t){return/^data:|^blob:|^about:blank$/i.test(t)}function fe(t,e){try{let n=typeof location<"u"&&location.href?location.href:"http://localhost/",o=e.includes("{url}")?e.split("{url}")[0]:e,r=new URL(o||".",n),i=new URL(t,n);if(i.origin===r.origin)return!0;let a=i.searchParams;if(a&&(a.has("url")||a.has("target")))return!0}catch{}return!1}function ue(t,e){if(!e||le(t)||fe(t,e))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 de(t,e){if(!e)return t;if(e.includes("{url}"))return e.replace("{urlRaw}",K(t)).replace("{url}",encodeURIComponent(t));if(/[?&]url=?$/.test(e))return`${e}${encodeURIComponent(t)}`;if(e.endsWith("?"))return`${e}url=${encodeURIComponent(t)}`;if(e.endsWith("/"))return`${e}${K(t)}`;let n=e.includes("?")?"&":"?";return`${e}${n}url=${encodeURIComponent(t)}`}function Ht(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 me(t,e){return[e.as||"blob",e.timeout??3e3,e.useProxy||"",e.errorTTL??8e3,t].join("|")}async function O(t,e={}){let n=e.as??"blob",o=e.timeout??3e3,r=e.useProxy||"",i=e.errorTTL??8e3,a=e.headers||{},s=!!e.silent;if(/^data:/i.test(t))try{if(n==="text")return{ok:!0,data:String(t),status:200,url:t,fromCache:!1};if(n==="dataURL")return{ok:!0,data:String(t),status:200,url:t,fromCache:!1,mime:String(t).slice(5).split(";")[0]||""};let[,w="",k=""]=String(t).match(/^data:([^,]*),(.*)$/)||[],F=/;base64/i.test(w)?atob(k):decodeURIComponent(k),U=new Uint8Array([...F].map(P=>P.charCodeAt(0))),D=new Blob([U],{type:(w||"").split(";")[0]||""});return{ok:!0,data:D,status:200,url:t,fromCache:!1,mime:D.type||""}}catch{return{ok:!1,data:null,status:0,url:t,fromCache:!1,reason:"special_url_error"}}if(/^blob:/i.test(t))try{let w=await fetch(t);if(!w.ok)return{ok:!1,data:null,status:w.status,url:t,fromCache:!1,reason:"http_error"};let k=await w.blob(),$=k.type||w.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await Ht(k),status:w.status,url:t,fromCache:!1,mime:$}:n==="text"?{ok:!0,data:await k.text(),status:w.status,url:t,fromCache:!1,mime:$}:{ok:!0,data:k,status:w.status,url:t,fromCache:!1,mime:$}}catch{return{ok:!1,data:null,status:0,url:t,fromCache:!1,reason:"network"}}if(/^about:blank$/i.test(t))return n==="dataURL"?{ok:!0,data:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==",status:200,url:t,fromCache:!1,mime:"image/png"}:{ok:!0,data:n==="text"?"":new Blob([]),status:200,url:t,fromCache:!1};let f=me(t,{as:n,timeout:o,useProxy:r,errorTTL:i}),c=ft.get(f);if(c&&c.until>Date.now())return{...c.result,fromCache:!0};c&&ft.delete(f);let l=kt.get(f);if(l)return l;let m=ue(t,r)?de(t,r):t,x=e.credentials;if(!x)try{let w=typeof location<"u"&&location.href?location.href:"http://localhost/",k=new URL(t,w);x=typeof location<"u"&&k.origin===location.origin?"include":"omit"}catch{x="omit"}let T=new AbortController,C=setTimeout(()=>T.abort("timeout"),o),A=(async()=>{try{let w=await fetch(m,{signal:T.signal,credentials:x,headers:a});if(!w.ok){let F={ok:!1,data:null,status:w.status,url:m,fromCache:!1,reason:"http_error"};if(i>0&&ft.set(f,{until:Date.now()+i,result:F}),!s){let U=`${w.status} ${w.statusText||""}`.trim();qt.warnOnce(`http:${w.status}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,`HTTP error ${U} while fetching ${n} ${t}`)}return e.onError&&e.onError(F),F}if(n==="text")return{ok:!0,data:await w.text(),status:w.status,url:m,fromCache:!1};let k=await w.blob(),$=k.type||w.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await Ht(k),status:w.status,url:m,fromCache:!1,mime:$}:{ok:!0,data:k,status:w.status,url:m,fromCache:!1,mime:$}}catch(w){let k=w&&typeof w=="object"&&"name"in w&&w.name==="AbortError"?String(w.message||"").includes("timeout")?"timeout":"abort":"network",$={ok:!1,data:null,status:0,url:m,fromCache:!1,reason:k};if(!/^blob:/i.test(t)&&i>0&&ft.set(f,{until:Date.now()+i,result:$}),!s){let F=`${k}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,U=k==="timeout"?`Timeout after ${o}ms. Consider increasing timeout or using a proxy for ${t}`:k==="abort"?`Request aborted while fetching ${n} ${t}`:`Network/CORS issue while fetching ${n} ${t}. A proxy may be required`;qt.errorOnce(F,U)}return e.onError&&e.onError($),$}finally{clearTimeout(C),kt.delete(f)}})();return kt.set(f,A),A}function J(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 Q(t,e={}){if(/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t)||t.trim()==="none")return t;let o=Y(t);if(!o)return t;let r=K(o);if(d.background.has(r)){let i=d.background.get(r);return i?`url("${i}")`:"none"}try{let i=await O(r,{as:"dataURL",useProxy:e.useProxy});return i.ok?(d.background.set(r,i.data),`url("${i.data}")`):(d.background.set(r,null),"none")}catch{return d.background.set(r,null),"none"}}var ut=new Set(["meta","script","noscript","title","link","template"]),ot=new Set(["meta","link","style","title","noscript","script","template","g","defs","use","marker","mask","clipPath","pattern","path","polygon","polyline","line","circle","ellipse","rect","filter","lineargradient","radialgradient","stop"]),he=["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 $t(){for(let t of he){let e=String(t).toLowerCase();ut.has(e)||ot.has(e)||Et(e)}}function Et(t){if(t=String(t).toLowerCase(),ot.has(t)){let i={};return d.defaultStyle.set(t,i),i}if(d.defaultStyle.has(t))return d.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 i of o){if(jt(i))continue;let a=o.getPropertyValue(i);r[i]=a}return e.removeChild(n),d.defaultStyle.set(t,r),r}var pe=/(?:^|-)(animation|transition)(?:-|$)/i,ge=/^(--|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,ye=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 jt(t){let e=String(t).toLowerCase();return!!(ye.has(e)||ge.test(e)||pe.test(e))}function rt(t,e){if(e=String(e||"").toLowerCase(),ot.has(e))return"";let n=[],o=Et(e);for(let[r,i]of Object.entries(t)){if(jt(r))continue;let a=o[r];i&&i!==a&&n.push(`${r}:${i}`)}return n.sort(),n.join(";")}function Mt(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=d.defaultStyle.get(o);if(!r)continue;let i=Object.entries(r).map(([a,s])=>`${a}:${s};`).sort().join("");i&&(e.has(i)||e.set(i,[]),e.get(i).push(o))}let n="";for(let[o,r]of e.entries())n+=`${r.join(",")} { ${o} }
|
|
2
|
+
`;return n}function Rt(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 Z(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let n=d.computedStyle.get(t);if(n||(n=new Map,d.computedStyle.set(t,n)),!n.has(e)){let o=window.getComputedStyle(t,e);n.set(e,o)}return n.get(e)}function Ft(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch{return e}return e}function dt(t){let e={};for(let n of t)e[n]=t.getPropertyValue(n);return e}function tt(t){let e=[],n=0,o=0;for(let r=0;r<t.length;r++){let i=t[r];i==="("&&n++,i===")"&&n--,i===","&&n===0&&(e.push(t.slice(o,r).trim()),o=r+1)}return e.push(t.slice(o).trim()),e}function V(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function G(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}var zt=new WeakMap,Lt=new Map,Tt=0;function at(){Tt++}var Vt=!1;function we(t=document.documentElement){if(!Vt){Vt=!0;try{new MutationObserver(()=>at()).observe(t,{subtree:!0,childList:!0,characterData:!0,attributes:!0})}catch{}try{new MutationObserver(()=>at()).observe(document.head,{subtree:!0,childList:!0,characterData:!0,attributes:!0})}catch{}try{let e=document.fonts;e&&(e.addEventListener?.("loadingdone",at),e.ready?.then(()=>at()).catch(()=>{}))}catch{}}}function be(t){let e={},n=t.getPropertyValue("visibility");for(let o=0;o<t.length;o++){let r=t[o],i=t.getPropertyValue(r);(r==="background-image"||r==="content")&&i.includes("url(")&&!i.includes("data:")&&(i="none"),e[r]=i}return n==="hidden"&&(e.opacity="0"),e}var Gt=new WeakMap;function Se(t){let e=Gt.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(";"),Gt.set(t,e),e)}function xe(t,e=null){let n=zt.get(t);if(n&&n.epoch===Tt)return n.snapshot;let o=e||getComputedStyle(t),r=be(o);return zt.set(t,{epoch:Tt,snapshot:r}),r}function Ce(t,e){return t&&t.session&&t.persist?t:t&&(t.styleMap||t.styleCache||t.nodeMap)?{session:t,persist:{snapshotKeyCache:Lt,defaultStyle:d.defaultStyle,baseStyle:d.baseStyle,image:d.image,resource:d.resource,background:d.background,font:d.font},options:e||{}}:{session:d.session,persist:{snapshotKeyCache:Lt,defaultStyle:d.defaultStyle,baseStyle:d.baseStyle,image:d.image,resource:d.resource,background:d.background,font:d.font},options:t||e||{}}}async function et(t,e,n,o){if(t.tagName==="STYLE")return;let r=Ce(n,o),i=r.options&&r.options.cache||"auto";if(i!=="disabled"&&we(document.documentElement),i==="disabled"&&!r.session.__bumpedForDisabled&&(at(),Lt.clear(),r.session.__bumpedForDisabled=!0),ot.has(t.tagName?.toLowerCase())){let x=t.getAttribute?.("style");x&&e.setAttribute("style",x)}let{session:a,persist:s}=r;a.styleCache.has(t)||a.styleCache.set(t,getComputedStyle(t));let f=a.styleCache.get(t),c=xe(t,f),l=Se(c),m=s.snapshotKeyCache.get(l);if(!m){let x=t.tagName?.toLowerCase()||"div";m=rt(c,x),s.snapshotKeyCache.set(l,m)}a.styleMap.set(e,m)}function It(t,e,n){return Promise.all(t.map(o=>new Promise(r=>{function i(){V(a=>{(a&&typeof a.timeRemaining=="function"?a.timeRemaining()>0:!0)?e(o,r):i()},{fast:n})}i()})))}function Ae(t){return t=t.trim(),!t||/\:not\(\s*\[data-sd-slotted\]\s*\)\s*$/.test(t)?t:`${t}:not([data-sd-slotted])`}function ke(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?Ae(o):o;return`:where(${e} ${r})`}).join(", ")}function $e(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,i)=>{let a=ke(i,e,!0);return`${o}${r}${a}{`}),t):""}function Ee(t){return t.shadowScopeSeq=(t.shadowScopeSeq||0)+1,`s${t.shadowScopeSeq}`}function Me(t){let e="";try{t.querySelectorAll("style").forEach(o=>{e+=(o.textContent||"")+`
|
|
3
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{}}catch{}return e}function
|
|
5
|
-
`:""}function Re(t){t&&(t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-sd-slotted",""),t.querySelectorAll&&t.querySelectorAll("*").forEach(e=>e.setAttribute("data-sd-slotted","")))}async function Te(t,e=3){let n=()=>{try{return t.contentDocument||t.contentWindow?.document||null}catch{return null}},o=n(),r=0;for(;r<e&&(!o||!o.body&&!o.documentElement);)await new Promise(i=>setTimeout(i,0)),o=n(),r++;return o&&(o.body||o.documentElement)?o:null}function Ne(t){let e=t.getBoundingClientRect(),n=0,o=0,r=0,i=0;try{let f=getComputedStyle(t);n=parseFloat(f.borderLeftWidth)||0,o=parseFloat(f.borderRightWidth)||0,r=parseFloat(f.borderTopWidth)||0,i=parseFloat(f.borderBottomWidth)||0}catch{}let s=Math.max(0,Math.round(e.width-(n+o))),a=Math.max(0,Math.round(e.height-(r+i)));return{contentWidth:s,contentHeight:a,rect:e}}function Ie(t,e,n){let o=t.createElement("style");return o.setAttribute("data-sd-iframe-pin",""),o.textContent=`html, body {margin: 0 !important;padding: 0 !important;width: ${e}px !important;height: ${n}px !important;min-width: ${e}px !important;min-height: ${n}px !important;box-sizing: border-box !important;overflow: hidden !important;background-clip: border-box !important;}`,(t.head||t.documentElement).appendChild(o),()=>{try{o.remove()}catch{}}}async function Pe(t,e,n){let o=await Te(t,3);if(!o)throw new Error("iframe document not accessible/ready");let{contentWidth:r,contentHeight:i,rect:s}=Ne(t),a=n?.snap;if(!a||typeof a.toPng!="function")throw new Error("snapdom.toPng not available in iframe or window");let f={...n,scale:1},c=Ie(o,r,i),l;try{l=await a.toPng(o.documentElement,f)}finally{c()}l.style.display="block",l.style.width=`${r}px`,l.style.height=`${i}px`;let d=document.createElement("div");return e.nodeMap.set(d,t),tt(t,d,e,n),d.style.overflow="hidden",d.style.display="block",d.style.width||(d.style.width=`${Math.round(s.width)}px`),d.style.height||(d.style.height=`${Math.round(s.height)}px`),d.appendChild(l),d}async function at(t,e,n){if(!t)throw new Error("Invalid node");let o=new Set,r=null,i=null;if(t.nodeType===Node.ELEMENT_NODE){let c=(t.localName||t.tagName||"").toLowerCase();if(t.id==="snapdom-sandbox"||t.hasAttribute("data-snapdom-sandbox")||ut.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"),l=t.getBoundingClientRect();return c.style.cssText=`display:inline-block;width:${l.width}px;height:${l.height}px;visibility:hidden;`,c}if(n.exclude&&Array.isArray(n.exclude))for(let c of n.exclude)try{if(t.matches?.(c)){let l=document.createElement("div"),d=t.getBoundingClientRect();return l.style.cssText=`display:inline-block;width:${d.width}px;height:${d.height}px;visibility:hidden;`,l}}catch(l){console.warn(`Invalid selector in exclude option: ${c}`,l)}if(typeof n.filter=="function")try{if(!n.filter(t)){let c=document.createElement("div"),l=t.getBoundingClientRect();return c.style.cssText=`display:inline-block;width:${l.width}px;height:${l.height}px;visibility:hidden;`,c}}catch(c){console.warn("Error in filter function:",c)}if(t.tagName==="IFRAME"){let c=!1;try{c=!!(t.contentDocument||t.contentWindow?.document)}catch{c=!1}if(c)try{return await Pe(t,e,n)}catch(l){console.warn("[SnapDOM] iframe rasterization failed, fallback:",l)}if(n.placeholders){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;`,tt(t,l,e,n),l}else{let l=t.getBoundingClientRect(),d=document.createElement("div");return d.style.cssText=`display:inline-block;width:${l.width}px;height:${l.height}px;visibility:hidden;`,tt(t,d,e,n),d}}if(t.getAttribute("data-capture")==="placeholder"){let c=t.cloneNode(!1);e.nodeMap.set(c,t),tt(t,c,e,n);let l=document.createElement("div");return l.textContent=t.getAttribute("data-placeholder-text")||"",l.style.cssText="color:#666;font-size:12px;text-align:center;line-height:1.4;padding:0.5em;box-sizing:border-box;",c.appendChild(l),c}if(t.tagName==="CANVAS"){let c=t.toDataURL(),l=document.createElement("img");return l.src=c,l.width=t.width,l.height=t.height,e.nodeMap.set(l,t),tt(t,l,e,n),l}let s;try{if(s=t.cloneNode(!1),e.nodeMap.set(s,t),t.tagName==="IMG"){Me(t,s);try{let c=t.getBoundingClientRect(),l=Math.round(c.width||0),d=Math.round(c.height||0);if(!l||!d){let x=window.getComputedStyle(t),R=parseFloat(x.width)||0,C=parseFloat(x.height)||0,k=parseInt(t.getAttribute("width")||"",10)||0,w=parseInt(t.getAttribute("height")||"",10)||0,F=t.width||t.naturalWidth||0,M=t.height||t.naturalHeight||0;l=Math.round(l||R||k||F||0),d=Math.round(d||C||w||M||0)}l&&(s.dataset.snapdomWidth=String(l)),d&&(s.dataset.snapdomHeight=String(d))}catch{}}}catch(c){throw console.error("[Snapdom] Failed to clone node:",t,c),c}if(t instanceof HTMLTextAreaElement){let c=t.getBoundingClientRect();s.style.width=`${c.width}px`,s.style.height=`${c.height}px`}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),t instanceof HTMLTextAreaElement&&(i=t.value),tt(t,s,e,n),t.shadowRoot){let w=function(M,T){if(M.nodeType===Node.ELEMENT_NODE&&M.tagName==="STYLE")return T(null);at(M,e,n).then(_=>{T(_||null)}).catch(_=>{T(null)})};try{let M=t.shadowRoot.querySelectorAll("slot");for(let T of M){let _=[];try{_=T.assignedNodes?.({flatten:!0})||T.assignedNodes?.()||[]}catch{_=T.assignedNodes?.()||[]}for(let q of _)o.add(q)}}catch{}let c=Ae(e),l=`[data-sd="${c}"]`;try{s.setAttribute("data-sd",c)}catch{}let d=$e(t.shadowRoot),x=ke(d,l),R=ve(d),C=Le(t,R,l);Ee(s,C+x,c);let k=document.createDocumentFragment(),F=await Nt(Array.from(t.shadowRoot.childNodes),w,n.fast);k.append(...F.filter(M=>!!M)),s.appendChild(k)}if(t.tagName==="SLOT"){let x=function(C,k){at(C,e,n).then(w=>{w&&Re(w),k(w||null)}).catch(w=>{k(null)})},c=t.assignedNodes?.({flatten:!0})||[],l=c.length>0?c:Array.from(t.childNodes),d=document.createDocumentFragment(),R=await Nt(Array.from(l),x,n.fast);return d.append(...R.filter(C=>!!C)),d}function a(c,l){if(o.has(c))return l(null);at(c,e,n).then(d=>{l(d||null)}).catch(d=>{l(null)})}let f=await Nt(Array.from(t.childNodes),a,n.fast);if(s.append(...f.filter(c=>!!c)),r!==null&&s instanceof HTMLSelectElement){s.value=r;for(let c of s.options)c.value===r?c.setAttribute("selected",""):c.removeAttribute("selected")}return i!==null&&s instanceof HTMLTextAreaElement&&(s.textContent=i),s}var _e=[/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],It=[];function zt(t){let e=Array.isArray(t)?t:[t];for(let n of e)n instanceof RegExp?It.push(n):typeof n=="string"?It.push(new RegExp(n,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",n)}function H(t){let e=typeof t=="string"?t:"",n=[..._e,...It];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 Vt(t,e,n,o=32,r="#000"){e=e.replace(/^['"]+|['"]+$/g,"");let i=window.devicePixelRatio||1;await document.fonts.ready;let s=document.createElement("span");s.textContent=t,s.style.position="absolute",s.style.visibility="hidden",s.style.fontFamily=`"${e}"`,s.style.fontWeight=n||"normal",s.style.fontSize=`${o}px`,s.style.lineHeight="1",s.style.whiteSpace="nowrap",s.style.padding="0",s.style.margin="0",document.body.appendChild(s);let a=s.getBoundingClientRect(),f=Math.ceil(a.width),c=Math.ceil(a.height);document.body.removeChild(s);let l=document.createElement("canvas");l.width=f*i,l.height=c*i;let d=l.getContext("2d");return d.scale(i,i),d.font=n?`${n} ${o}px "${e}"`:`${o}px "${e}"`,d.textAlign="left",d.textBaseline="top",d.fillStyle=r,d.fillText(t,0,0),{dataUrl:l.toDataURL(),width:f,height:c}}var Ue=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]);function ht(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!Ue.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 Pt(t){let e=String(t??"normal").trim().toLowerCase();return e.startsWith("italic")?"italic":e.startsWith("oblique")?"oblique":"normal"}function We(t){let e=String(t??"100%").match(/(\d+(?:\.\d+)?)\s*%/);return e?Math.max(50,Math.min(200,parseFloat(e[1]))):100}function Be(t){let e=String(t||"400").trim(),n=e.match(/^(\d{2,3})\s+(\d{2,3})$/);if(n){let r=mt(n[1]),i=mt(n[2]);return{min:Math.min(r,i),max:Math.max(r,i)}}let o=mt(e);return{min:o,max:o}}function Oe(t){let e=String(t||"normal").trim().toLowerCase();return e==="italic"?{kind:"italic"}:e.startsWith("oblique")?{kind:"oblique"}:{kind:"normal"}}function De(t){let e=String(t||"100%").trim(),n=e.match(/(\d+(?:\.\d+)?)\s*%\s+(\d+(?:\.\d+)?)\s*%/);if(n){let i=parseFloat(n[1]),s=parseFloat(n[2]);return{min:Math.min(i,s),max:Math.max(i,s)}}let o=e.match(/(\d+(?:\.\d+)?)\s*%/),r=o?parseFloat(o[1]):100;return{min:r,max:r}}function qe(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(a=>r.endsWith(a)))return!0;let s=(n.pathname+n.search).toLowerCase();if(/\bfont(s)?\b/.test(s)||/\.woff2?(\b|$)/.test(s))return!0;for(let a of e){let f=a.toLowerCase().replace(/\s+/g,"+"),c=a.toLowerCase().replace(/\s+/g,"-");if(s.includes(f)||s.includes(c))return!0}return!1}catch{return!1}}function je(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 pt({required:t,usedCodepoints:e,exclude:n=void 0,localFonts:o=[],useProxy:r=""}={}){t instanceof Set||(t=new Set),e instanceof Set||(e=new Set);let i=new Map;for(let u of t){let[p,g,b,m]=String(u).split("__");if(!p)continue;let y=i.get(p)||[];y.push({w:parseInt(g,10),s:b,st:parseInt(m,10)}),i.set(p,y)}let s=/@import\s+url\(["']?([^"')]+)["']?\)/g,a=/url\((["']?)([^"')]+)\1\)/g,f=/@font-face[^{}]*\{[^}]*\}/g;function c(u,p,g,b){if(!i.has(u))return!1;let m=i.get(u),y=Be(g),A=Oe(p),S=De(b),E=y.min!==y.max,v=y.min,N=$=>A.kind==="normal"&&$==="normal"||A.kind!=="normal"&&($==="italic"||$==="oblique"),W=!1;for(let $ of m){let I=E?$.w>=y.min&&$.w<=y.max:$.w===v,B=N(Pt($.s)),L=$.st>=S.min&&$.st<=S.max;if(I&&B&&L){W=!0;break}}if(W)return!0;if(!E)for(let $ of m){let I=N(Pt($.s)),B=$.st>=S.min&&$.st<=S.max;if(Math.abs(v-$.w)<=300&&I&&B)return!0}return!1}function l(u){if(!u)return[];let p=[],g=u.split(",").map(b=>b.trim()).filter(Boolean);for(let b of g){let m=b.match(/^U\+([0-9A-Fa-f?]+)(?:-([0-9A-Fa-f?]+))?$/);if(!m)continue;let y=m[1],A=m[2],S=E=>{if(!E.includes("?"))return parseInt(E,16);let v=parseInt(E.replace(/\?/g,"0"),16),N=parseInt(E.replace(/\?/g,"F"),16);return[v,N]};if(A){let E=S(y),v=S(A),N=Array.isArray(E)?E[0]:E,W=Array.isArray(v)?v[1]:v;p.push([Math.min(N,W),Math.max(N,W)])}else{let E=S(y);Array.isArray(E)?p.push([E[0],E[1]]):p.push([E,E])}}return p}function d(u,p){if(!p.length||!u||u.size===0)return!0;for(let g of u)for(let[b,m]of p)if(g>=b&&g<=m)return!0;return!1}function x(u,p){let g=[];if(!u)return g;for(let b of u.matchAll(a)){let m=(b[2]||"").trim();if(!(!m||m.startsWith("data:"))){if(!/^https?:/i.test(m))try{m=new URL(m,p||location.href).href}catch{}g.push(m)}}return g}async function R(u,p){let g=u;for(let b of u.matchAll(a)){let m=G(b[0]);if(!m)continue;let y=m;if(!y.startsWith("http")&&!y.startsWith("data:"))try{y=new URL(y,p||location.href).href}catch{}if(!H(y)){if(h.resource?.has(y)){h.font?.add(y),g=g.replace(b[0],`url(${h.resource.get(y)})`);continue}if(!h.font?.has(y))try{let A=await O(y,{as:"dataURL",useProxy:r,silent:!0});if(A.ok&&typeof A.data=="string"){let S=A.data;h.resource?.set(y,S),h.font?.add(y),g=g.replace(b[0],`url(${S})`)}}catch{console.warn("[snapDOM] Failed to fetch font resource:",y)}}}return g}function C(u){if(!u.length)return null;let p=(S,E)=>u.some(([v,N])=>!(N<S||v>E)),g=p(0,255)||p(305,305),b=p(256,591)||p(7680,7935),m=p(880,1023),y=p(1024,1279);return p(7840,7929)||p(258,259)||p(416,417)||p(431,432)?"vietnamese":y?"cyrillic":m?"greek":b?"latin-ext":g?"latin":null}function k(u={}){let p=new Set((u.families||[]).map(m=>String(m).toLowerCase())),g=new Set((u.domains||[]).map(m=>String(m).toLowerCase())),b=new Set((u.subsets||[]).map(m=>String(m).toLowerCase()));return(m,y)=>{if(p.size&&p.has(m.family.toLowerCase()))return!0;if(g.size)for(let A of m.srcUrls)try{if(g.has(new URL(A).host.toLowerCase()))return!0}catch{}if(b.size){let A=C(y);if(A&&b.has(A))return!0}return!1}}let w=k(n);function F(u){if(!u)return u;let p=/@font-face[^{}]*\{[^}]*\}/gi,g=new Set,b=[];for(let y of u.match(p)||[]){let A=y.match(/font-family:\s*([^;]+);/i)?.[1]||"",S=ht(A),E=(y.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),v=(y.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),N=(y.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),W=(y.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),$=(y.match(/src\s*:\s*([^;]+);/i)?.[1]||"").trim(),I=x($,location.href),B=I.length?I.map(j=>String(j).toLowerCase()).sort().join("|"):$.toLowerCase(),L=[String(S||"").toLowerCase(),E,v,N,W.toLowerCase(),B].join("|");g.has(L)||(g.add(L),b.push(y))}if(b.length===0)return u;let m=0;return u.replace(p,()=>b[m++]||"")}function M(){let u=Array.from(t||[]).sort().join("|"),p=n?JSON.stringify({families:(n.families||[]).map(m=>String(m).toLowerCase()).sort(),domains:(n.domains||[]).map(m=>String(m).toLowerCase()).sort(),subsets:(n.subsets||[]).map(m=>String(m).toLowerCase()).sort()}):"",g=(o||[]).map(m=>`${(m.family||"").toLowerCase()}::${m.weight||"normal"}::${m.style||"normal"}::${m.src||""}`).sort().join("|");return`fonts-embed-css::req=${u}::ex=${p}::lf=${g}::px=${r||""}`}let T=M();if(h.resource?.has(T))return h.resource.get(T);let _=je(t),q=[];for(let u of document.querySelectorAll("style")){let p=u.textContent||"";for(let g of p.matchAll(s)){let b=g[1];if(!b||H(b))continue;!!document.querySelector(`link[rel="stylesheet"][href="${b}"]`)||q.push(b)}}q.length&&await Promise.all(q.map(u=>new Promise(p=>{if(document.querySelector(`link[rel="stylesheet"][href="${u}"]`))return p(null);let g=document.createElement("link");g.rel="stylesheet",g.href=u,g.setAttribute("data-snapdom","injected-import"),g.onload=()=>p(g),g.onerror=()=>p(null),document.head.appendChild(g)})));let U="",D=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(u=>!!u.href);for(let u of D)try{if(H(u.href))continue;let p="",g=!1;try{g=new URL(u.href,location.href).origin===location.origin}catch{}if(!g&&!qe(u.href,_))continue;if(g){let m=Array.from(document.styleSheets).find(y=>y.href===u.href);if(m)try{let y=m.cssRules||[];p=Array.from(y).map(A=>A.cssText).join("")}catch{}}if(!p&&(p=(await O(u.href,{as:"text",useProxy:r})).data,H(u.href)))continue;let b="";for(let m of p.match(f)||[]){let y=(m.match(/font-family:\s*([^;]+);/i)?.[1]||"").trim(),A=ht(y);if(!A||H(A))continue;let S=(m.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),E=(m.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),v=(m.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),N=(m.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),W=(m.match(/src\s*:\s*([^;]+);/i)?.[1]||"").trim(),$=x(W,u.href);if(!c(A,E,S,v))continue;let I=l(N);if(!d(e,I))continue;let B={family:A,weightSpec:S,styleSpec:E,stretchSpec:v,unicodeRange:N,srcRaw:W,srcUrls:$,href:u.href};if(n&&w(B,I))continue;let L=/url\(/i.test(W)?await R(m,u.href):m;b+=L+""}b.trim()&&(U+=b+"")}catch{console.warn("[snapdom] Failed to process stylesheet:",u.href)}for(let u of document.styleSheets)try{if(u.href&&D.some(g=>g.href===u.href))continue;let p=u.cssRules||[];for(let g of p){if(g.type!==CSSRule.FONT_FACE_RULE)continue;let b=(g.style.getPropertyValue("font-family")||"").trim(),m=ht(b);if(!m||H(m))continue;let y=(g.style.getPropertyValue("font-weight")||"400").trim(),A=(g.style.getPropertyValue("font-style")||"normal").trim(),S=(g.style.getPropertyValue("font-stretch")||"100%").trim(),E=(g.style.getPropertyValue("src")||"").trim(),v=(g.style.getPropertyValue("unicode-range")||"").trim(),N=x(E,u.href||location.href);if(!c(m,A,y,S))continue;let W=l(v);if(!d(e,W))continue;let $={family:m,weightSpec:y,styleSpec:A,stretchSpec:S,unicodeRange:v,srcRaw:E,srcUrls:N,href:u.href||location.href};if(!(n&&w($,W)))if(/url\(/i.test(E)){let I=await R(E,u.href||location.href);U+=`@font-face{font-family:${m};src:${I};font-style:${A};font-weight:${y};font-stretch:${S};${v?`unicode-range:${v};`:""}}`}else U+=`@font-face{font-family:${m};src:${E};font-style:${A};font-weight:${y};font-stretch:${S};${v?`unicode-range:${v};`:""}}`}}catch{}try{for(let u of document.fonts||[]){if(!u||!u.family||u.status!=="loaded"||!u._snapdomSrc)continue;let p=String(u.family).replace(/^['"]+|['"]+$/g,"");if(H(p)||!i.has(p)||n?.families&&n.families.some(b=>String(b).toLowerCase()===p.toLowerCase()))continue;let g=u._snapdomSrc;if(!String(g).startsWith("data:")){if(h.resource?.has(u._snapdomSrc))g=h.resource.get(u._snapdomSrc),h.font?.add(u._snapdomSrc);else if(!h.font?.has(u._snapdomSrc))try{let b=await O(u._snapdomSrc,{as:"dataURL",useProxy:r,silent:!0});if(b.ok&&typeof b.data=="string")g=b.data,h.resource?.set(u._snapdomSrc,g),h.font?.add(u._snapdomSrc);else continue}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",u._snapdomSrc);continue}}U+=`@font-face{font-family:'${p}';src:url(${g});font-style:${u.style||"normal"};font-weight:${u.weight||"normal"};}`}}catch{}for(let u of o){if(!u||typeof u!="object")continue;let p=String(u.family||"").replace(/^['"]+|['"]+$/g,"");if(!p||H(p)||!i.has(p)||n?.families&&n.families.some(S=>String(S).toLowerCase()===p.toLowerCase()))continue;let g=u.weight!=null?String(u.weight):"normal",b=u.style!=null?String(u.style):"normal",m=u.stretchPct!=null?`${u.stretchPct}%`:"100%",y=String(u.src||""),A=y;if(!A.startsWith("data:")){if(h.resource?.has(y))A=h.resource.get(y),h.font?.add(y);else if(!h.font?.has(y))try{let S=await O(y,{as:"dataURL",useProxy:r,silent:!0});if(S.ok&&typeof S.data=="string")A=S.data,h.resource?.set(y,A),h.font?.add(y);else continue}catch{console.warn("[snapdom] Failed to fetch localFonts src:",y);continue}}U+=`@font-face{font-family:'${p}';src:url(${A});font-style:${b};font-weight:${g};font-stretch:${m};}`}return U&&(U=F(U),h.resource?.set(T,U)),U}function gt(t){let e=new Set;if(!t)return e;let n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null),o=s=>{let a=ht(s.fontFamily);if(!a)return;let f=(c,l,d)=>`${a}__${mt(c)}__${Pt(l)}__${We(d)}`;e.add(f(s.fontWeight,s.fontStyle,s.fontStretch))};o(getComputedStyle(t));let r=getComputedStyle(t,"::before");r&&r.content&&r.content!=="none"&&o(r);let i=getComputedStyle(t,"::after");for(i&&i.content&&i.content!=="none"&&o(i);n.nextNode();){let s=n.currentNode,a=getComputedStyle(s);o(a);let f=getComputedStyle(s,"::before");f&&f.content&&f.content!=="none"&&o(f);let c=getComputedStyle(s,"::after");c&&c.content&&c.content!=="none"&&o(c)}return e}function yt(t){let e=new Set,n=r=>{if(r)for(let i of r)e.add(i.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 i=r;for(let s of["::before","::after"]){let f=getComputedStyle(i,s)?.getPropertyValue("content");if(!(!f||f==="none"))if(/^"/.test(f)||/^'/.test(f))n(f.slice(1,-1));else{let c=f.match(/\\[0-9A-Fa-f]{1,6}/g);if(c)for(let l of c)try{e.add(parseInt(l.slice(1),16))}catch{}}}}}return e}async function wt(t,e=2){try{await document.fonts.ready}catch{}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 i of n){let s=document.createElement("span");s.textContent="AaBbGg1234\xC1\xC9\xCD\xD3\xDA\xE7\xF1\u2014\u221E",s.style.fontFamily=`"${i}"`,s.style.fontWeight="700",s.style.fontStyle="italic",s.style.fontSize="32px",s.style.lineHeight="1",s.style.whiteSpace="nowrap",s.style.margin="0",s.style.padding="0",r.appendChild(s)}document.body.appendChild(r),r.offsetWidth,document.body.removeChild(r)};for(let r=0;r<Math.max(1,e);r++)o(),await new Promise(i=>requestAnimationFrame(()=>requestAnimationFrame(i)))}async function _t(t,e,n,o){if(!(t instanceof Element)||!(e instanceof Element))return;for(let s of["::before","::after","::first-letter"])try{let a=Z(t,s);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(s==="::first-letter"){let $=getComputedStyle(t);if(!(a.color!==$.color||a.fontSize!==$.fontSize||a.fontWeight!==$.fontWeight))continue;let B=Array.from(e.childNodes).find(Bt=>Bt.nodeType===Node.TEXT_NODE&&Bt.textContent?.trim().length>0);if(!B)continue;let L=B.textContent,et=L.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],Ct=L.slice(et?.length||0);if(!et||/[\uD800-\uDFFF]/.test(et))continue;let z=document.createElement("span");z.textContent=et,z.dataset.snapdomPseudo="::first-letter";let re=dt(a),se=ot(re,"span");n.styleMap.set(z,se);let Wt=document.createTextNode(Ct);e.replaceChild(Wt,B),e.insertBefore(z,Wt);continue}let c=a.content,l=/counter\s*\(|counters\s*\(/.test(c)?"- ":Lt(c),d=a.backgroundImage,x=a.backgroundColor,R=a.fontFamily,C=parseInt(a.fontSize)||32,k=parseInt(a.fontWeight)||!1,w=a.color||"#000",F=a.display,M=parseFloat(a.width),T=parseFloat(a.height),_=a.borderStyle,q=parseFloat(a.borderWidth),U=a.transform,D=H(R),u=c!=="none"&&l!=="",p=d&&d!=="none",g=x&&x!=="transparent"&&x!=="rgba(0, 0, 0, 0)",b=F!=="inline"&&(M>0||T>0),m=_&&_!=="none"&&q>0,y=U&&U!=="none";if(!(u||p||g||b||m||y))continue;let S=document.createElement("span");S.dataset.snapdomPseudo=s,S.style.verticalAlign="middle";let E=dt(a),v=ot(E,"span");if(n.styleMap.set(S,v),D&&l.length===1){let{dataUrl:$,width:I,height:B}=await Vt(l,R,k,C,w),L=document.createElement("img");L.src=$,L.style=`height:${C}px;width:${I/B*C}px;object-fit:contain;`,S.appendChild(L),e.dataset.snapdomHasIcon="true"}else if(l.startsWith("url(")){let $=G(l);if($?.trim())try{let I=document.createElement("img"),B=await O(rt($),{as:"dataURL",useProxy:o.useProxy});I.src=B.data,I.style=`width:${C}px;height:auto;object-fit:contain;`,S.appendChild(I)}catch(I){console.error(`[snapdom] Error in pseudo ${s} for`,t,I)}}else!D&&u&&(S.textContent=l);if(p)try{let $=Q(d),I=await Promise.all($.map(J));S.style.backgroundImage=I.join(", ")}catch($){console.warn(`[snapdom] Failed to inline background-image for ${s}`,$)}if(g&&(S.style.backgroundColor=x),!(S.childNodes.length>0||S.textContent?.trim()!==""||p||g||b||m||y))continue;s==="::before"?e.insertBefore(S,e.firstChild):e.appendChild(S)}catch(a){console.warn(`[snapdom] Failed to capture ${s} for`,t,a)}let r=Array.from(t.children),i=Array.from(e.children).filter(s=>!s.dataset.snapdomPseudo);for(let s=0;s<Math.min(r.length,i.length);s++)await _t(r[s],i[s],n,o)}function Xt(t){if(!t)return;let e=new Set;if(t.querySelectorAll("use").forEach(a=>{let f=a.getAttribute("xlink:href")||a.getAttribute("href");f&&f.startsWith("#")&&e.add(f.slice(1))}),!e.size)return;let n=Array.from(document.querySelectorAll("svg > symbol, svg > defs")),o=n.filter(a=>a.tagName.toLowerCase()==="symbol"),r=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 s=new Set;t.querySelectorAll("symbol[id], defs > *[id]").forEach(a=>{s.add(a.id)}),e.forEach(a=>{if(s.has(a))return;let f=o.find(c=>c.id===a);if(f){i.appendChild(f.cloneNode(!0)),s.add(a);return}for(let c of r){let l=c.querySelector(`#${CSS.escape(a)}`);if(l){let d=i.querySelector("defs");d||(d=document.createElementNS("http://www.w3.org/2000/svg","defs"),i.appendChild(d)),d.appendChild(l.cloneNode(!0)),s.add(a);break}}})}async function Gt(t,e={}){let n={styleMap:h.session.styleMap,styleCache:h.session.styleCache,nodeMap:h.session.nodeMap},o,r="",i="";He(t);try{Xt(t)}catch(a){console.warn("inlineExternal defs or symbol failed:",a)}try{o=await at(t,n,e,t)}catch(a){throw console.warn("deepClone failed:",a),a}try{await _t(t,o,n,e)}catch(a){console.warn("inlinePseudoElements failed:",a)}await Ke(o);try{let a=o.querySelectorAll("style[data-sd]");for(let f of a)i+=f.textContent||"",f.remove()}catch{}let s=Ft(n.styleMap);r=Array.from(s.entries()).map(([a,f])=>`.${f}{${a}}`).join(""),r=i+r;for(let[a,f]of n.styleMap.entries()){if(a.tagName==="STYLE")continue;if(a.getRootNode&&a.getRootNode()instanceof ShadowRoot){a.setAttribute("style",f.replace(/;/g,"; "));continue}let c=s.get(f);c&&a.classList.add(c);let l=a.style?.backgroundImage,d=a.dataset?.snapdomHasIcon;l&&l!=="none"&&(a.style.backgroundImage=l),d&&(a.style.verticalAlign="middle",a.style.display="inline")}for(let[a,f]of n.nodeMap.entries()){let c=f.scrollLeft,l=f.scrollTop;if((c||l)&&a instanceof HTMLElement){a.style.overflow="hidden",a.style.scrollbarWidth="none",a.style.msOverflowStyle="none";let x=document.createElement("div");for(x.style.transform=`translate(${-c}px, ${-l}px)`,x.style.willChange="transform",x.style.display="inline-block",x.style.width="100%";a.firstChild;)x.appendChild(a.firstChild);a.appendChild(x)}}if(t===n.nodeMap.get(o)){let a=n.styleCache.get(t)||window.getComputedStyle(t);n.styleCache.set(t,a);let f=kt(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=f||""}for(let[a,f]of n.nodeMap.entries())f.tagName==="PRE"&&(a.style.marginTop="0",a.style.marginBlockStart="0");return{clone:o,classCSS:r,styleCache:n.styleCache}}function He(t){let e=getComputedStyle(t),n=e.outlineStyle,o=e.outlineWidth,r=e.borderStyle,i=e.borderWidth,s=n!=="none"&&parseFloat(o)>0,a=r==="none"||parseFloat(i)===0;s&&a&&(t.style.border=`${o} solid transparent`)}var it=new Map;async function ct(t){if(h.resource?.has(t))return h.resource.get(t);if(it.has(t))return it.get(t);let e=(async()=>{let n=await O(t,{as:"dataURL",silent:!0});if(!n.ok||typeof n.data!="string")throw new Error(`[snapDOM] Failed to read blob URL: ${t}`);return h.resource?.set(t,n.data),n.data})();it.set(t,e);try{let n=await e;return it.set(t,n),n}catch(n){throw it.delete(t),n}}var ze=/\bblob:[^)"'\s]+/g;async function Kt(t){if(!t||t.indexOf("blob:")===-1)return t;let e=Array.from(new Set(t.match(ze)||[]));if(e.length===0)return t;let n=t;for(let o of e)try{let r=await ct(o);n=n.split(o).join(r)}catch{}return n}function bt(t){return typeof t=="string"&&t.startsWith("blob:")}function Ve(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 Xe(t){return t.map(e=>e.desc?`${e.url} ${e.desc.trim()}`:e.url).join(", ")}async function Ke(t){if(!t)return;let e=t.querySelectorAll?t.querySelectorAll("img"):[];for(let s of e)try{let f=s.getAttribute("src")||s.currentSrc||"";if(bt(f)){let l=await ct(f);s.setAttribute("src",l)}let c=s.getAttribute("srcset");if(c&&c.includes("blob:")){let l=Ve(c),d=!1;for(let x of l)if(bt(x.url))try{x.url=await ct(x.url),d=!0}catch{}d&&s.setAttribute("srcset",Xe(l))}}catch{}let n=t.querySelectorAll?t.querySelectorAll("image"):[];for(let s of n)try{let a="http://www.w3.org/1999/xlink",f=s.getAttribute("href")||s.getAttributeNS?.(a,"href");if(bt(f)){let c=await ct(f);s.setAttribute("href",c),s.removeAttributeNS?.(a,"href")}}catch{}let o=t.querySelectorAll?t.querySelectorAll("[style*='blob:']"):[];for(let s of o)try{let a=s.getAttribute("style");if(a&&a.includes("blob:")){let f=await Kt(a);s.setAttribute("style",f)}}catch{}let r=t.querySelectorAll?t.querySelectorAll("style"):[];for(let s of r)try{let a=s.textContent||"";a.includes("blob:")&&(s.textContent=await Kt(a))}catch{}let i=["poster"];for(let s of i){let a=t.querySelectorAll?t.querySelectorAll(`[${s}^='blob:']`):[];for(let f of a)try{let c=f.getAttribute(s);bt(c)&&f.setAttribute(s,await ct(c))}catch{}}}async function Yt(t,e={}){let n=Array.from(t.querySelectorAll("img")),o=async r=>{if(!r.getAttribute("src")){let l=r.currentSrc||r.src||"";l&&r.setAttribute("src",l)}r.removeAttribute("srcset"),r.removeAttribute("sizes");let i=r.src||"";if(!i)return;let s=await O(i,{as:"dataURL",useProxy:e.useProxy});if(s.ok&&typeof s.data=="string"&&s.data.startsWith("data:")){r.src=s.data,r.width||(r.width=r.naturalWidth||100),r.height||(r.height=r.naturalHeight||100);return}let{defaultImageUrl:a}=e||{};if(a)try{let l=parseInt(r.dataset?.snapdomWidth||"",10)||0,d=parseInt(r.dataset?.snapdomHeight||"",10)||0,x=parseInt(r.getAttribute("width")||"",10)||0,R=parseInt(r.getAttribute("height")||"",10)||0,C=parseFloat(r.style?.width||"")||0,k=parseFloat(r.style?.height||"")||0,w=l||C||x||r.width||void 0,F=d||k||R||r.height||void 0,M=typeof a=="function"?await a({width:w,height:F,src:i,element:r}):a;if(M){let T=await O(M,{as:"dataURL",useProxy:e.useProxy});r.src=T.data,!r.width&&w&&(r.width=w),!r.height&&F&&(r.height=F),r.width||(r.width=r.naturalWidth||100),r.height||(r.height=r.naturalHeight||100);return}}catch{}let f=r.width||r.naturalWidth||100,c=r.height||r.naturalHeight||100;if(e.placeholders!==!1){let l=document.createElement("div");l.style.cssText=[`width:${f}px`,`height:${c}px`,"background:#ccc","display:inline-block","text-align:center",`line-height:${c}px`,"color:#666","font-size:12px","overflow:hidden"].join(";"),l.textContent="img",r.replaceWith(l)}else{let l=document.createElement("div");l.style.cssText=`display:inline-block;width:${f}px;height:${c}px;visibility:hidden;`,r.replaceWith(l)}};for(let r=0;r<n.length;r+=4){let i=n.slice(r,r+4).map(o);await Promise.allSettled(i)}}async function St(t,e,n,o={}){let r=[[t,e]],i=["background-image","mask","mask-image","-webkit-mask","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source","border-image","border-image-source"],s=["mask-position","mask-size","mask-repeat","-webkit-mask-position","-webkit-mask-size","-webkit-mask-repeat","mask-origin","mask-clip","-webkit-mask-origin","-webkit-mask-clip","-webkit-mask-position-x","-webkit-mask-position-y"],a=["border-image-slice","border-image-width","border-image-outset","border-image-repeat"];for(;r.length;){let[f,c]=r.shift(),l=n.get(f)||Z(f);n.has(f)||n.set(f,l);let d=(()=>{let C=l.getPropertyValue("border-image"),k=l.getPropertyValue("border-image-source");return C&&C!=="none"||k&&k!=="none"})();for(let C of i){let k=l.getPropertyValue(C);if(!k||k==="none")continue;let w=Q(k),F=await Promise.all(w.map(M=>J(M,o)));F.some(M=>M&&M!=="none"&&!/^url\(undefined/.test(M))&&c.style.setProperty(C,F.join(", "))}for(let C of s){let k=l.getPropertyValue(C);!k||k==="initial"||c.style.setProperty(C,k)}if(d)for(let C of a){let k=l.getPropertyValue(C);!k||k==="initial"||c.style.setProperty(C,k)}let x=Array.from(f.children),R=Array.from(c.children);for(let C=0;C<Math.min(x.length,R.length);C++)r.push([x[C],R[C]])}}async function Zt(t,e){if(!t)throw new Error("Element cannot be null or undefined");lt(e.cache);let n=e.fast,o,r,i,s="",a="",f,c;({clone:o,classCSS:r,styleCache:i}=await Gt(t,e)),await new Promise(R=>{V(async()=>{await Yt(o,e),R()},{fast:n})}),await new Promise(R=>{V(async()=>{await St(t,o,i,e),R()},{fast:n})}),e.embedFonts&&await new Promise(R=>{V(async()=>{let C=gt(t),k=yt(t);if(X){let w=new Set(Array.from(C).map(F=>String(F).split("__")[0]).filter(Boolean));await wt(w,5)}s=await pt({required:C,usedCodepoints:k,preCached:!1,exclude:e.excludeFonts,useProxy:e.useProxy}),R()},{fast:n})});let l=Mt(o).sort(),d=l.join(",");h.baseStyle.has(d)?a=h.baseStyle.get(d):await new Promise(R=>{V(()=>{a=vt(l),h.baseStyle.set(d,a),R()},{fast:n})}),await new Promise(R=>{V(()=>{let C=Ge(t),k=C.width,w=C.height,F=Number.isFinite(e.width),M=Number.isFinite(e.height),T=e.scale??1,_=typeof T=="number"&&T!==1;if(!_){let L=C.width/C.height;F&&M?(k=e.width,w=e.height):F?(k=e.width,w=k/L):M&&(w=e.height,k=w*L)}k=Math.max(1,Math.ceil(k)),w=Math.max(1,Math.ceil(w));let q=getComputedStyle(t),U=q.transform&&q.transform!=="none"?q.transform:"",D=Ze(t),u,p,g,b,m=0,y=0;if(Qe(t)){let L=nn({baseTransform:U,rotate:D.rotate||"0deg",scale:D.scale,translate:D.translate}),j=L.e??L.m41??0,et=L.f??L.m42??0;m=-j,y=-et;let Ct=L.is2D?Jt(L):Jt(new DOMMatrix(L.toString())),z=Je(k,w,Ct);u=Math.max(1,Math.ceil(z.width)),p=Math.max(1,Math.ceil(z.height)),g=-z.minX,b=-z.minY}else{let L=t.getBoundingClientRect(),j=tn(L,{top:0,right:0,bottom:0,left:0});u=Math.max(1,j.width),p=Math.max(1,j.height),g=-(j.x-Math.floor(L.left)),b=-(j.y-Math.floor(L.top))}let A="http://www.w3.org/2000/svg",S=document.createElementNS(A,"foreignObject");S.setAttribute("width","100%"),S.setAttribute("height","100%"),S.setAttribute("x",String(g)),S.setAttribute("y",String(b)),S.style.overflow="visible";let E=document.createElement("style");E.textContent=a+s+"svg{overflow:visible;} foreignObject{overflow:visible;}"+r,S.appendChild(E);let v=document.createElement("div");v.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),v.style.width=`${k}px`,v.style.height=`${w}px`,v.style.overflow="visible",v.style.transformOrigin="0 0";let N=[];if((m||y)&&N.push(`translate(${m}px, ${y}px)`),!_&&(F||M)){let L=C.width?k/C.width:1,j=C.height?w/C.height:1;N.push(`scale(${L}, ${j})`)}else _&&N.push(`scale(${T})`);N.length&&(v.style.transform=N.join(" ")),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="0 0",o.style.position="static",o.style.left="0",o.style.top="0",U&&(o.style.transform=U),o.style.rotate=D.rotate||"0deg",o.style.scale=D.scale||"1",o.style.translate=D.translate||"0 0",v.appendChild(o),S.appendChild(v);let $=new XMLSerializer().serializeToString(S);c=`<svg xmlns="${A}" width="${u}" height="${p}" viewBox="0 0 ${u} ${p}">`+$+"</svg>",f=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(c)}`,R()},{fast:n})});let x=document.getElementById("snapdom-sandbox");return x&&x.style.position==="absolute"&&x.remove(),f}function Ge(t){let e=getComputedStyle(t),n=i=>parseFloat(i)||0,o=n(e.width),r=n(e.height);return e.boxSizing==="content-box"&&(o+=n(e.paddingLeft)+n(e.paddingRight)+n(e.borderLeftWidth)+n(e.borderRightWidth),r+=n(e.paddingTop)+n(e.paddingBottom)+n(e.borderTopWidth)+n(e.borderBottomWidth)),{width:o,height:r}}function Ye(t){let e=getComputedStyle(t).transform;if(!e||e==="none")return new DOMMatrix;try{return new DOMMatrix(e)}catch{return new WebKitCSSMatrix(e)}}function Jt(t){return new DOMMatrix([t.a,t.b,t.c,t.d,0,0])}function Je(t,e,n){let r=[{x:0,y:0},{x:t,y:0},{x:0,y:e},{x:t,y:e}].map(c=>({x:n.a*c.x+n.c*c.y,y:n.b*c.x+n.d*c.y})),i=Math.min(...r.map(c=>c.x)),s=Math.max(...r.map(c=>c.x)),a=Math.min(...r.map(c=>c.y)),f=Math.max(...r.map(c=>c.y));return{minX:i,minY:a,width:s-i,height:f-a}}function Ze(t){let e={rotate:"0deg",scale:null,translate:null},n=t.computedStyleMap?.();if(n){let r=n.get("rotate");if(r){let a=r.angle??r;a&&"unit"in a?e.rotate=a.unit==="rad"?a.value*180/Math.PI+"deg":a.value+a.unit:e.rotate=String(r)}let i=n.get("scale");if(i&&i.length){let a=i[0]?.value??1,f=i[1]?.value??a;e.scale=`${a} ${f}`}let s=n.get("translate");if(s&&s.length){let a=s[0]?.value??0,f=s[1]?.value??0,c=s[0]?.unit??"px",l=s[1]?.unit??"px";e.translate=`${a}${c} ${f}${l}`}return e}let o=getComputedStyle(t);return e.rotate=o.rotate&&o.rotate!=="none"?o.rotate:"0deg",e.scale=o.scale&&o.scale!=="none"?o.scale:null,e.translate=o.translate&&o.translate!=="none"?o.translate:null,e}function Qe(t){let e=getComputedStyle(t).transform||"none";return!(e==="none"||e==="matrix(1, 0, 0, 1, 0, 0)"||/^matrix\(\s*1\s*,\s*0\s*,\s*0\s*,\s*1\s*,/i.test(e))}function tn(t,e){let n=Math.floor(t.left-e.left),o=Math.floor(t.top-e.top),r=Math.ceil(t.width+e.left+e.right),i=Math.ceil(t.height+e.top+e.bottom);return{x:n,y:o,width:r,height:i}}var Ut=null;function en(){if(Ut)return Ut;let t=document.createElement("div");return t.id="snapdom-measure-slot",t.setAttribute("aria-hidden","true"),Object.assign(t.style,{position:"absolute",left:"-99999px",top:"0px",width:"0px",height:"0px",overflow:"hidden",opacity:"0",pointerEvents:"none",contain:"size layout style"}),document.documentElement.appendChild(t),Ut=t,t}function nn(t){let e=en(),n=document.createElement("div");n.style.transformOrigin="0 0",t.baseTransform&&(n.style.transform=t.baseTransform),t.rotate&&(n.style.rotate=t.rotate),t.scale&&(n.style.scale=t.scale),t.translate&&(n.style.translate=t.translate),e.appendChild(n);let o=Ye(n);return e.removeChild(n),o}function on(t){if(typeof t=="string"){let e=t.toLowerCase().trim();if(e==="disabled"||e==="full"||e==="auto"||e==="soft")return e}return"soft"}function Qt(t={}){let e=t.format??"png",n=on(t.cache);return{debug:t.debug??!1,fast:t.fast??!0,scale:t.scale??1,exclude:t.exclude??[],filter:t.filter??null,placeholders:t.placeholders!==!1,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,defaultImageUrl:t.defaultImageUrl??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 te(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 K(t,e){let{scale:n,dpr:o}=e,r=X(),i=new Image;i.crossOrigin="anonymous",i.loading="eager",i.decoding="sync",i.src=t;let s=null;r&&(s=document.createElement("div"),s.setAttribute("aria-hidden","true"),s.style.cssText="position:absolute;left:-99999px;top:0;width:0;height:0;overflow:hidden;opacity:0;pointer-events:none;contain:size layout style;",document.body.appendChild(s),s.appendChild(i)),await i.decode(),r&&await new Promise(d=>setTimeout(d,100));let a=i.naturalWidth*n,f=i.naturalHeight*n,c=document.createElement("canvas");c.width=Math.ceil(a*o),c.height=Math.ceil(f*o),c.style.width=`${a}px`,c.style.height=`${f}px`;let l=c.getContext("2d");if(o!==1&&l.scale(o,o),l.drawImage(i,0,0,a,f),s&&s.parentNode)try{s.parentNode.removeChild(s)}catch{}return c}async function xt(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 K(t,e),r=e.backgroundColor?Y(o,e.backgroundColor):o;return new Promise(i=>r.toBlob(s=>i(s),`image/${n}`,e.quality))}async function ee(t,e){let n=await K(t,e),o=e.backgroundColor?Y(n,e.backgroundColor):n,r=new Image;return r.src=o.toDataURL(`image/${e.format}`,e.quality),await r.decode(),r.style.width=`${o.width/e.dpr}px`,r.style.height=`${o.height/e.dpr}px`,r}async function ne(t,e){if(e.format==="svg"){let i=await xt(t,{...e,type:"svg"}),s=URL.createObjectURL(i),a=document.createElement("a");a.href=s,a.download=e.filename,a.click(),URL.revokeObjectURL(s);return}let n=await K(t,e),o=e.backgroundColor?Y(n,e.backgroundColor):n,r=document.createElement("a");r.href=o.toDataURL(`image/${e.format}`,e.quality),r.download=e.filename,r.click()}var oe=Symbol("snapdom.internal");async function P(t,e){if(!t)throw new Error("Element cannot be null or undefined");let n=Qt(e);return n.iconFonts&&n.iconFonts.length>0&&zt(n.iconFonts),n.snap||(n.snap={toPng:(o,r)=>P.toPng(o,r),toImg:(o,r)=>P.toImg(o,r)}),P.capture(t,n,oe)}P.capture=async(t,e,n)=>{if(n!==oe)throw new Error("[snapdom.capture] is internal. Use snapdom(...) instead.");let o=await Zt(t,e),r=s=>({...e,...s||{}}),i=s=>a=>{let f=r({...a||{},format:s}),c=s==="jpeg"||s==="jpg",l=f.backgroundColor==null||f.backgroundColor==="transparent";return c&&l&&(f.backgroundColor="#ffffff"),ee(o,f)};return{url:o,toRaw:()=>o,toImg:s=>te(o,r(s)),toCanvas:s=>K(o,r(s)),toBlob:s=>xt(o,r(s)),toPng:i("png"),toJpg:i("jpeg"),toWebp:i("webp"),download:s=>ne(o,r(s))}};P.toRaw=(t,e)=>P(t,e).then(n=>n.toRaw());P.toImg=(t,e)=>P(t,e).then(n=>n.toImg());P.toCanvas=(t,e)=>P(t,e).then(n=>n.toCanvas());P.toBlob=(t,e)=>P(t,e).then(n=>n.toBlob());P.toPng=(t,e)=>P(t,{...e,format:"png"}).then(n=>n.toPng());P.toJpg=(t,e)=>P(t,{...e,format:"jpeg"}).then(n=>n.toJpg());P.toWebp=(t,e)=>P(t,{...e,format:"webp"}).then(n=>n.toWebp());P.download=(t,e)=>P(t,e).then(n=>n.download());async function rn(t=document,e={}){let{embedFonts:n=!0,cacheOpt:o="full",useProxy:r=""}=e;lt(o);try{await document.fonts.ready}catch{}$t(),h.session=h.session||{},h.session.styleCache||(h.session.styleCache=new WeakMap);try{await St(t,void 0,h.session.styleCache,{useProxy:r})}catch{}let i=[],s=[];try{t?.querySelectorAll&&(i=Array.from(t.querySelectorAll("img[src]")),s=Array.from(t.querySelectorAll("*")))}catch{}let a=[];for(let f of i){let c=f?.src;if(c&&!h.image.has(c)){let l=Promise.resolve().then(()=>O(c,{as:"dataURL",useProxy:r})).then(d=>{h.image.set(c,d)}).catch(()=>{});a.push(l)}}for(let f of s){let c="";try{c=Z(f).backgroundImage}catch{}if(c&&c!=="none"){let l=Q(c);for(let d of l)if(d.startsWith("url(")){let x=Promise.resolve().then(()=>J(d,{...e,useProxy:r})).catch(()=>{});a.push(x)}}}if(n)try{let f=gt(t),c=yt(t);if(typeof X=="function"?X():X){let l=new Set(Array.from(f).map(d=>String(d).split("__")[0]).filter(Boolean));await wt(l,2)}await pt({required:f,usedCodepoints:c,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:e.useProxy??r})}catch{}await Promise.allSettled(a)}export{rn as preCache,P as snapdom};
|
|
4
|
+
`}catch{}}catch{}return e}function ve(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 Re(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 Fe(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 Le(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 Te(t,e,n){let o=[];for(let r of e){let i=Le(t,r);i&&o.push(`${r}: ${i};`)}return o.length?`${n}{${o.join("")}}
|
|
5
|
+
`:""}function Ie(t){t&&(t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-sd-slotted",""),t.querySelectorAll&&t.querySelectorAll("*").forEach(e=>e.setAttribute("data-sd-slotted","")))}async function Ne(t,e=3){let n=()=>{try{return t.contentDocument||t.contentWindow?.document||null}catch{return null}},o=n(),r=0;for(;r<e&&(!o||!o.body&&!o.documentElement);)await new Promise(i=>setTimeout(i,0)),o=n(),r++;return o&&(o.body||o.documentElement)?o:null}function Ue(t){let e=t.getBoundingClientRect(),n=0,o=0,r=0,i=0;try{let f=getComputedStyle(t);n=parseFloat(f.borderLeftWidth)||0,o=parseFloat(f.borderRightWidth)||0,r=parseFloat(f.borderTopWidth)||0,i=parseFloat(f.borderBottomWidth)||0}catch{}let a=Math.max(0,Math.round(e.width-(n+o))),s=Math.max(0,Math.round(e.height-(r+i)));return{contentWidth:a,contentHeight:s,rect:e}}function _e(t,e,n){let o=t.createElement("style");return o.setAttribute("data-sd-iframe-pin",""),o.textContent=`html, body {margin: 0 !important;padding: 0 !important;width: ${e}px !important;height: ${n}px !important;min-width: ${e}px !important;min-height: ${n}px !important;box-sizing: border-box !important;overflow: hidden !important;background-clip: border-box !important;}`,(t.head||t.documentElement).appendChild(o),()=>{try{o.remove()}catch{}}}async function Pe(t,e,n){let o=await Ne(t,3);if(!o)throw new Error("iframe document not accessible/ready");let{contentWidth:r,contentHeight:i,rect:a}=Ue(t),s=n?.snap;if(!s||typeof s.toPng!="function")throw new Error("snapdom.toPng not available in iframe or window");let f={...n,scale:1},c=_e(o,r,i),l;try{l=await s.toPng(o.documentElement,f)}finally{c()}l.style.display="block",l.style.width=`${r}px`,l.style.height=`${i}px`;let m=document.createElement("div");return e.nodeMap.set(m,t),et(t,m,e,n),m.style.overflow="hidden",m.style.display="block",m.style.width||(m.style.width=`${Math.round(a.width)}px`),m.style.height||(m.style.height=`${Math.round(a.height)}px`),m.appendChild(l),m}async function st(t,e,n){if(!t)throw new Error("Invalid node");let o=new Set,r=null,i=null;if(t.nodeType===Node.ELEMENT_NODE){let c=(t.localName||t.tagName||"").toLowerCase();if(t.id==="snapdom-sandbox"||t.hasAttribute("data-snapdom-sandbox")||ut.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"){if(n.excludeMode==="visuallyHide"){let c=document.createElement("div"),l=t.getBoundingClientRect();return c.style.cssText=`display:inline-block;width:${l.width}px;height:${l.height}px;visibility:hidden;`,c}else if(n.excludeMode==="remove")return null}if(n.exclude&&Array.isArray(n.exclude))for(let c of n.exclude)try{if(t.matches?.(c)){if(n.excludeMode==="visuallyHide"){let l=document.createElement("div"),m=t.getBoundingClientRect();return l.style.cssText=`display:inline-block;width:${m.width}px;height:${m.height}px;visibility:hidden;`,l}else if(n.excludeMode==="remove")return null}}catch(l){console.warn(`Invalid selector in exclude option: ${c}`,l)}if(typeof n.filter=="function")try{if(!n.filter(t)){if(n.filterMode==="visuallyHide"){let c=document.createElement("div"),l=t.getBoundingClientRect();return c.style.cssText=`display:inline-block;width:${l.width}px;height:${l.height}px;visibility:hidden;`,c}else if(n.filterMode==="remove")return null}}catch(c){console.warn("Error in filter function:",c)}if(t.tagName==="IFRAME"){let c=!1;try{c=!!(t.contentDocument||t.contentWindow?.document)}catch{c=!1}if(c)try{return await Pe(t,e,n)}catch(l){console.warn("[SnapDOM] iframe rasterization failed, fallback:",l)}if(n.placeholders){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;`,et(t,l,e,n),l}else{let l=t.getBoundingClientRect(),m=document.createElement("div");return m.style.cssText=`display:inline-block;width:${l.width}px;height:${l.height}px;visibility:hidden;`,et(t,m,e,n),m}}if(t.getAttribute("data-capture")==="placeholder"){let c=t.cloneNode(!1);e.nodeMap.set(c,t),et(t,c,e,n);let l=document.createElement("div");return l.textContent=t.getAttribute("data-placeholder-text")||"",l.style.cssText="color:#666;font-size:12px;text-align:center;line-height:1.4;padding:0.5em;box-sizing:border-box;",c.appendChild(l),c}if(t.tagName==="CANVAS"){let c=t.toDataURL(),l=document.createElement("img");return l.src=c,l.width=t.width,l.height=t.height,e.nodeMap.set(l,t),et(t,l,e,n),l}let a;try{if(a=t.cloneNode(!1),e.nodeMap.set(a,t),t.tagName==="IMG"){Re(t,a);try{let c=t.getBoundingClientRect(),l=Math.round(c.width||0),m=Math.round(c.height||0);if(!l||!m){let x=window.getComputedStyle(t),T=parseFloat(x.width)||0,C=parseFloat(x.height)||0,A=parseInt(t.getAttribute("width")||"",10)||0,w=parseInt(t.getAttribute("height")||"",10)||0,k=t.width||t.naturalWidth||0,$=t.height||t.naturalHeight||0;l=Math.round(l||T||A||k||0),m=Math.round(m||C||w||$||0)}l&&(a.dataset.snapdomWidth=String(l)),m&&(a.dataset.snapdomHeight=String(m))}catch{}}}catch(c){throw console.error("[Snapdom] Failed to clone node:",t,c),c}if(t instanceof HTMLTextAreaElement){let c=t.getBoundingClientRect();a.style.width=`${c.width}px`,a.style.height=`${c.height}px`}if(t instanceof HTMLInputElement&&(a.value=t.value,a.setAttribute("value",t.value),t.checked!==void 0&&(a.checked=t.checked,t.checked&&a.setAttribute("checked",""),t.indeterminate&&(a.indeterminate=t.indeterminate))),t instanceof HTMLSelectElement&&(r=t.value),t instanceof HTMLTextAreaElement&&(i=t.value),et(t,a,e,n),t.shadowRoot){let w=function($,F){if($.nodeType===Node.ELEMENT_NODE&&$.tagName==="STYLE")return F(null);st($,e,n).then(U=>{F(U||null)}).catch(U=>{F(null)})};try{let $=t.shadowRoot.querySelectorAll("slot");for(let F of $){let U=[];try{U=F.assignedNodes?.({flatten:!0})||F.assignedNodes?.()||[]}catch{U=F.assignedNodes?.()||[]}for(let D of U)o.add(D)}}catch{}let c=Ee(e),l=`[data-sd="${c}"]`;try{a.setAttribute("data-sd",c)}catch{}let m=Me(t.shadowRoot),x=$e(m,l),T=Fe(m),C=Te(t,T,l);ve(a,C+x,c);let A=document.createDocumentFragment(),k=await It(Array.from(t.shadowRoot.childNodes),w,n.fast);A.append(...k.filter($=>!!$)),a.appendChild(A)}if(t.tagName==="SLOT"){let x=function(C,A){st(C,e,n).then(w=>{w&&Ie(w),A(w||null)}).catch(w=>{A(null)})},c=t.assignedNodes?.({flatten:!0})||[],l=c.length>0?c:Array.from(t.childNodes),m=document.createDocumentFragment(),T=await It(Array.from(l),x,n.fast);return m.append(...T.filter(C=>!!C)),m}function s(c,l){if(o.has(c))return l(null);st(c,e,n).then(m=>{l(m||null)}).catch(m=>{l(null)})}let f=await It(Array.from(t.childNodes),s,n.fast);if(a.append(...f.filter(c=>!!c)),r!==null&&a instanceof HTMLSelectElement){a.value=r;for(let c of a.options)c.value===r?c.setAttribute("selected",""):c.removeAttribute("selected")}return i!==null&&a instanceof HTMLTextAreaElement&&(a.textContent=i),a}var Be=[/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],Nt=[];function Kt(t){let e=Array.isArray(t)?t:[t];for(let n of e)n instanceof RegExp?Nt.push(n):typeof n=="string"?Nt.push(new RegExp(n,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",n)}function j(t){let e=typeof t=="string"?t:"",n=[...Be,...Nt];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 Xt(t,e,n,o=32,r="#000"){e=e.replace(/^['"]+|['"]+$/g,"");let i=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=`${o}px`,a.style.lineHeight="1",a.style.whiteSpace="nowrap",a.style.padding="0",a.style.margin="0",document.body.appendChild(a);let s=a.getBoundingClientRect(),f=Math.ceil(s.width),c=Math.ceil(s.height);document.body.removeChild(a);let l=document.createElement("canvas");l.width=f*i,l.height=c*i;let m=l.getContext("2d");return m.scale(i,i),m.font=n?`${n} ${o}px "${e}"`:`${o}px "${e}"`,m.textAlign="left",m.textBaseline="top",m.fillStyle=r,m.fillText(t,0,0),{dataUrl:l.toDataURL(),width:f,height:c}}var We=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]);function mt(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!We.has(n.toLowerCase()))return n}return""}function ht(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 Ut(t){let e=String(t??"normal").trim().toLowerCase();return e.startsWith("italic")?"italic":e.startsWith("oblique")?"oblique":"normal"}function Oe(t){let e=String(t??"100%").match(/(\d+(?:\.\d+)?)\s*%/);return e?Math.max(50,Math.min(200,parseFloat(e[1]))):100}function De(t){let e=String(t||"400").trim(),n=e.match(/^(\d{2,3})\s+(\d{2,3})$/);if(n){let r=ht(n[1]),i=ht(n[2]);return{min:Math.min(r,i),max:Math.max(r,i)}}let o=ht(e);return{min:o,max:o}}function qe(t){let e=String(t||"normal").trim().toLowerCase();return e==="italic"?{kind:"italic"}:e.startsWith("oblique")?{kind:"oblique"}:{kind:"normal"}}function He(t){let e=String(t||"100%").trim(),n=e.match(/(\d+(?:\.\d+)?)\s*%\s+(\d+(?:\.\d+)?)\s*%/);if(n){let i=parseFloat(n[1]),a=parseFloat(n[2]);return{min:Math.min(i,a),max:Math.max(i,a)}}let o=e.match(/(\d+(?:\.\d+)?)\s*%/),r=o?parseFloat(o[1]):100;return{min:r,max:r}}function je(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(s=>r.endsWith(s)))return!0;let a=(n.pathname+n.search).toLowerCase();if(/\bfont(s)?\b/.test(a)||/\.woff2?(\b|$)/.test(a))return!0;for(let s of e){let f=s.toLowerCase().replace(/\s+/g,"+"),c=s.toLowerCase().replace(/\s+/g,"-");if(a.includes(f)||a.includes(c))return!0}return!1}catch{return!1}}function ze(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 pt({required:t,usedCodepoints:e,exclude:n=void 0,localFonts:o=[],useProxy:r=""}={}){t instanceof Set||(t=new Set),e instanceof Set||(e=new Set);let i=new Map;for(let u of t){let[p,g,b,h]=String(u).split("__");if(!p)continue;let y=i.get(p)||[];y.push({w:parseInt(g,10),s:b,st:parseInt(h,10)}),i.set(p,y)}let a=/@import\s+url\(["']?([^"')]+)["']?\)/g,s=/url\((["']?)([^"')]+)\1\)/g,f=/@font-face[^{}]*\{[^}]*\}/g;function c(u,p,g,b){if(!i.has(u))return!1;let h=i.get(u),y=De(g),E=qe(p),S=He(b),v=y.min!==y.max,R=y.min,I=M=>E.kind==="normal"&&M==="normal"||E.kind!=="normal"&&(M==="italic"||M==="oblique"),B=!1;for(let M of h){let N=v?M.w>=y.min&&M.w<=y.max:M.w===R,W=I(Ut(M.s)),L=M.st>=S.min&&M.st<=S.max;if(N&&W&&L){B=!0;break}}if(B)return!0;if(!v)for(let M of h){let N=I(Ut(M.s)),W=M.st>=S.min&&M.st<=S.max;if(Math.abs(R-M.w)<=300&&N&&W)return!0}return!1}function l(u){if(!u)return[];let p=[],g=u.split(",").map(b=>b.trim()).filter(Boolean);for(let b of g){let h=b.match(/^U\+([0-9A-Fa-f?]+)(?:-([0-9A-Fa-f?]+))?$/);if(!h)continue;let y=h[1],E=h[2],S=v=>{if(!v.includes("?"))return parseInt(v,16);let R=parseInt(v.replace(/\?/g,"0"),16),I=parseInt(v.replace(/\?/g,"F"),16);return[R,I]};if(E){let v=S(y),R=S(E),I=Array.isArray(v)?v[0]:v,B=Array.isArray(R)?R[1]:R;p.push([Math.min(I,B),Math.max(I,B)])}else{let v=S(y);Array.isArray(v)?p.push([v[0],v[1]]):p.push([v,v])}}return p}function m(u,p){if(!p.length||!u||u.size===0)return!0;for(let g of u)for(let[b,h]of p)if(g>=b&&g<=h)return!0;return!1}function x(u,p){let g=[];if(!u)return g;for(let b of u.matchAll(s)){let h=(b[2]||"").trim();if(!(!h||h.startsWith("data:"))){if(!/^https?:/i.test(h))try{h=new URL(h,p||location.href).href}catch{}g.push(h)}}return g}async function T(u,p){let g=u;for(let b of u.matchAll(s)){let h=Y(b[0]);if(!h)continue;let y=h;if(!y.startsWith("http")&&!y.startsWith("data:"))try{y=new URL(y,p||location.href).href}catch{}if(!j(y)){if(d.resource?.has(y)){d.font?.add(y),g=g.replace(b[0],`url(${d.resource.get(y)})`);continue}if(!d.font?.has(y))try{let E=await O(y,{as:"dataURL",useProxy:r,silent:!0});if(E.ok&&typeof E.data=="string"){let S=E.data;d.resource?.set(y,S),d.font?.add(y),g=g.replace(b[0],`url(${S})`)}}catch{console.warn("[snapDOM] Failed to fetch font resource:",y)}}}return g}function C(u){if(!u.length)return null;let p=(S,v)=>u.some(([R,I])=>!(I<S||R>v)),g=p(0,255)||p(305,305),b=p(256,591)||p(7680,7935),h=p(880,1023),y=p(1024,1279);return p(7840,7929)||p(258,259)||p(416,417)||p(431,432)?"vietnamese":y?"cyrillic":h?"greek":b?"latin-ext":g?"latin":null}function A(u={}){let p=new Set((u.families||[]).map(h=>String(h).toLowerCase())),g=new Set((u.domains||[]).map(h=>String(h).toLowerCase())),b=new Set((u.subsets||[]).map(h=>String(h).toLowerCase()));return(h,y)=>{if(p.size&&p.has(h.family.toLowerCase()))return!0;if(g.size)for(let E of h.srcUrls)try{if(g.has(new URL(E).host.toLowerCase()))return!0}catch{}if(b.size){let E=C(y);if(E&&b.has(E))return!0}return!1}}let w=A(n);function k(u){if(!u)return u;let p=/@font-face[^{}]*\{[^}]*\}/gi,g=new Set,b=[];for(let y of u.match(p)||[]){let E=y.match(/font-family:\s*([^;]+);/i)?.[1]||"",S=mt(E),v=(y.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),R=(y.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),I=(y.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),B=(y.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),M=(y.match(/src\s*:\s*([^;]+);/i)?.[1]||"").trim(),N=x(M,location.href),W=N.length?N.map(H=>String(H).toLowerCase()).sort().join("|"):M.toLowerCase(),L=[String(S||"").toLowerCase(),v,R,I,B.toLowerCase(),W].join("|");g.has(L)||(g.add(L),b.push(y))}if(b.length===0)return u;let h=0;return u.replace(p,()=>b[h++]||"")}function $(){let u=Array.from(t||[]).sort().join("|"),p=n?JSON.stringify({families:(n.families||[]).map(h=>String(h).toLowerCase()).sort(),domains:(n.domains||[]).map(h=>String(h).toLowerCase()).sort(),subsets:(n.subsets||[]).map(h=>String(h).toLowerCase()).sort()}):"",g=(o||[]).map(h=>`${(h.family||"").toLowerCase()}::${h.weight||"normal"}::${h.style||"normal"}::${h.src||""}`).sort().join("|");return`fonts-embed-css::req=${u}::ex=${p}::lf=${g}::px=${r||""}`}let F=$();if(d.resource?.has(F))return d.resource.get(F);let U=ze(t),D=[];for(let u of document.querySelectorAll("style")){let p=u.textContent||"";for(let g of p.matchAll(a)){let b=g[1];if(!b||j(b))continue;!!document.querySelector(`link[rel="stylesheet"][href="${b}"]`)||D.push(b)}}D.length&&await Promise.all(D.map(u=>new Promise(p=>{if(document.querySelector(`link[rel="stylesheet"][href="${u}"]`))return p(null);let g=document.createElement("link");g.rel="stylesheet",g.href=u,g.setAttribute("data-snapdom","injected-import"),g.onload=()=>p(g),g.onerror=()=>p(null),document.head.appendChild(g)})));let P="",q=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(u=>!!u.href);for(let u of q)try{if(j(u.href))continue;let p="",g=!1;try{g=new URL(u.href,location.href).origin===location.origin}catch{}if(!g&&!je(u.href,U))continue;if(g){let h=Array.from(document.styleSheets).find(y=>y.href===u.href);if(h)try{let y=h.cssRules||[];p=Array.from(y).map(E=>E.cssText).join("")}catch{}}if(!p&&(p=(await O(u.href,{as:"text",useProxy:r})).data,j(u.href)))continue;let b="";for(let h of p.match(f)||[]){let y=(h.match(/font-family:\s*([^;]+);/i)?.[1]||"").trim(),E=mt(y);if(!E||j(E))continue;let S=(h.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),v=(h.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),R=(h.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),I=(h.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),B=(h.match(/src\s*:\s*([^;]+);/i)?.[1]||"").trim(),M=x(B,u.href);if(!c(E,v,S,R))continue;let N=l(I);if(!m(e,N))continue;let W={family:E,weightSpec:S,styleSpec:v,stretchSpec:R,unicodeRange:I,srcRaw:B,srcUrls:M,href:u.href};if(n&&w(W,N))continue;let L=/url\(/i.test(B)?await T(h,u.href):h;b+=L+""}b.trim()&&(P+=b+"")}catch{console.warn("[snapdom] Failed to process stylesheet:",u.href)}for(let u of document.styleSheets)try{if(u.href&&q.some(g=>g.href===u.href))continue;let p=u.cssRules||[];for(let g of p){if(g.type!==CSSRule.FONT_FACE_RULE)continue;let b=(g.style.getPropertyValue("font-family")||"").trim(),h=mt(b);if(!h||j(h))continue;let y=(g.style.getPropertyValue("font-weight")||"400").trim(),E=(g.style.getPropertyValue("font-style")||"normal").trim(),S=(g.style.getPropertyValue("font-stretch")||"100%").trim(),v=(g.style.getPropertyValue("src")||"").trim(),R=(g.style.getPropertyValue("unicode-range")||"").trim(),I=x(v,u.href||location.href);if(!c(h,E,y,S))continue;let B=l(R);if(!m(e,B))continue;let M={family:h,weightSpec:y,styleSpec:E,stretchSpec:S,unicodeRange:R,srcRaw:v,srcUrls:I,href:u.href||location.href};if(!(n&&w(M,B)))if(/url\(/i.test(v)){let N=await T(v,u.href||location.href);P+=`@font-face{font-family:${h};src:${N};font-style:${E};font-weight:${y};font-stretch:${S};${R?`unicode-range:${R};`:""}}`}else P+=`@font-face{font-family:${h};src:${v};font-style:${E};font-weight:${y};font-stretch:${S};${R?`unicode-range:${R};`:""}}`}}catch{}try{for(let u of document.fonts||[]){if(!u||!u.family||u.status!=="loaded"||!u._snapdomSrc)continue;let p=String(u.family).replace(/^['"]+|['"]+$/g,"");if(j(p)||!i.has(p)||n?.families&&n.families.some(b=>String(b).toLowerCase()===p.toLowerCase()))continue;let g=u._snapdomSrc;if(!String(g).startsWith("data:")){if(d.resource?.has(u._snapdomSrc))g=d.resource.get(u._snapdomSrc),d.font?.add(u._snapdomSrc);else if(!d.font?.has(u._snapdomSrc))try{let b=await O(u._snapdomSrc,{as:"dataURL",useProxy:r,silent:!0});if(b.ok&&typeof b.data=="string")g=b.data,d.resource?.set(u._snapdomSrc,g),d.font?.add(u._snapdomSrc);else continue}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",u._snapdomSrc);continue}}P+=`@font-face{font-family:'${p}';src:url(${g});font-style:${u.style||"normal"};font-weight:${u.weight||"normal"};}`}}catch{}for(let u of o){if(!u||typeof u!="object")continue;let p=String(u.family||"").replace(/^['"]+|['"]+$/g,"");if(!p||j(p)||!i.has(p)||n?.families&&n.families.some(S=>String(S).toLowerCase()===p.toLowerCase()))continue;let g=u.weight!=null?String(u.weight):"normal",b=u.style!=null?String(u.style):"normal",h=u.stretchPct!=null?`${u.stretchPct}%`:"100%",y=String(u.src||""),E=y;if(!E.startsWith("data:")){if(d.resource?.has(y))E=d.resource.get(y),d.font?.add(y);else if(!d.font?.has(y))try{let S=await O(y,{as:"dataURL",useProxy:r,silent:!0});if(S.ok&&typeof S.data=="string")E=S.data,d.resource?.set(y,E),d.font?.add(y);else continue}catch{console.warn("[snapdom] Failed to fetch localFonts src:",y);continue}}P+=`@font-face{font-family:'${p}';src:url(${E});font-style:${b};font-weight:${g};font-stretch:${h};}`}return P&&(P=k(P),d.resource?.set(F,P)),P}function gt(t){let e=new Set;if(!t)return e;let n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null),o=a=>{let s=mt(a.fontFamily);if(!s)return;let f=(c,l,m)=>`${s}__${ht(c)}__${Ut(l)}__${Oe(m)}`;e.add(f(a.fontWeight,a.fontStyle,a.fontStretch))};o(getComputedStyle(t));let r=getComputedStyle(t,"::before");r&&r.content&&r.content!=="none"&&o(r);let i=getComputedStyle(t,"::after");for(i&&i.content&&i.content!=="none"&&o(i);n.nextNode();){let a=n.currentNode,s=getComputedStyle(a);o(s);let f=getComputedStyle(a,"::before");f&&f.content&&f.content!=="none"&&o(f);let c=getComputedStyle(a,"::after");c&&c.content&&c.content!=="none"&&o(c)}return e}function yt(t){let e=new Set,n=r=>{if(r)for(let i of r)e.add(i.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 i=r;for(let a of["::before","::after"]){let f=getComputedStyle(i,a)?.getPropertyValue("content");if(!(!f||f==="none"))if(/^"/.test(f)||/^'/.test(f))n(f.slice(1,-1));else{let c=f.match(/\\[0-9A-Fa-f]{1,6}/g);if(c)for(let l of c)try{e.add(parseInt(l.slice(1),16))}catch{}}}}}return e}async function wt(t,e=2){try{await document.fonts.ready}catch{}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 i of n){let a=document.createElement("span");a.textContent="AaBbGg1234\xC1\xC9\xCD\xD3\xDA\xE7\xF1\u2014\u221E",a.style.fontFamily=`"${i}"`,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(),await new Promise(i=>requestAnimationFrame(()=>requestAnimationFrame(i)))}async function _t(t,e,n,o){if(!(t instanceof Element)||!(e instanceof Element))return;for(let a of["::before","::after","::first-letter"])try{let s=Z(t,a);if(!s||typeof s[Symbol.iterator]!="function"||s.content==="none"&&s.backgroundImage==="none"&&s.backgroundColor==="transparent"&&(s.borderStyle==="none"||parseFloat(s.borderWidth)===0)&&(!s.transform||s.transform==="none")&&s.display==="inline")continue;if(a==="::first-letter"){let M=getComputedStyle(t);if(!(s.color!==M.color||s.fontSize!==M.fontSize||s.fontWeight!==M.fontWeight))continue;let W=Array.from(e.childNodes).find(Dt=>Dt.nodeType===Node.TEXT_NODE&&Dt.textContent?.trim().length>0);if(!W)continue;let L=W.textContent,nt=L.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],Ct=L.slice(nt?.length||0);if(!nt||/[\uD800-\uDFFF]/.test(nt))continue;let z=document.createElement("span");z.textContent=nt,z.dataset.snapdomPseudo="::first-letter";let se=dt(s),ie=rt(se,"span");n.styleMap.set(z,ie);let Ot=document.createTextNode(Ct);e.replaceChild(Ot,W),e.insertBefore(z,Ot);continue}let c=s.content,l=/counter\s*\(|counters\s*\(/.test(c)?"- ":Ft(c),m=s.backgroundImage,x=s.backgroundColor,T=s.fontFamily,C=parseInt(s.fontSize)||32,A=parseInt(s.fontWeight)||!1,w=s.color||"#000",k=s.display,$=parseFloat(s.width),F=parseFloat(s.height),U=s.borderStyle,D=parseFloat(s.borderWidth),P=s.transform,q=j(T),u=c!=="none"&&l!=="",p=m&&m!=="none",g=x&&x!=="transparent"&&x!=="rgba(0, 0, 0, 0)",b=k!=="inline"&&($>0||F>0),h=U&&U!=="none"&&D>0,y=P&&P!=="none";if(!(u||p||g||b||h||y))continue;let S=document.createElement("span");S.dataset.snapdomPseudo=a,S.style.verticalAlign="middle";let v=dt(s),R=rt(v,"span");if(n.styleMap.set(S,R),q&&l.length===1){let{dataUrl:M,width:N,height:W}=await Xt(l,T,A,C,w),L=document.createElement("img");L.src=M,L.style=`height:${C}px;width:${N/W*C}px;object-fit:contain;`,S.appendChild(L),e.dataset.snapdomHasIcon="true"}else if(l.startsWith("url(")){let M=Y(l);if(M?.trim())try{let N=document.createElement("img"),W=await O(K(M),{as:"dataURL",useProxy:o.useProxy});N.src=W.data,N.style=`width:${C}px;height:auto;object-fit:contain;`,S.appendChild(N)}catch(N){console.error(`[snapdom] Error in pseudo ${a} for`,t,N)}}else!q&&u&&(S.textContent=l);if(p)try{let M=tt(m),N=await Promise.all(M.map(Q));S.style.backgroundImage=N.join(", ")}catch(M){console.warn(`[snapdom] Failed to inline background-image for ${a}`,M)}if(g&&(S.style.backgroundColor=x),!(S.childNodes.length>0||S.textContent?.trim()!==""||p||g||b||h||y))continue;a==="::before"?e.insertBefore(S,e.firstChild):e.appendChild(S)}catch(s){console.warn(`[snapdom] Failed to capture ${a} for`,t,s)}let r=Array.from(t.children),i=Array.from(e.children).filter(a=>!a.dataset.snapdomPseudo);for(let a=0;a<Math.min(r.length,i.length);a++)await _t(r[a],i[a],n,o)}function Yt(t){if(!t)return;let e=new Set;if(t.querySelectorAll("use").forEach(s=>{let f=s.getAttribute("xlink:href")||s.getAttribute("href");f&&f.startsWith("#")&&e.add(f.slice(1))}),!e.size)return;let n=Array.from(document.querySelectorAll("svg > symbol, svg > defs")),o=n.filter(s=>s.tagName.toLowerCase()==="symbol"),r=n.filter(s=>s.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 a=new Set;t.querySelectorAll("symbol[id], defs > *[id]").forEach(s=>{a.add(s.id)}),e.forEach(s=>{if(a.has(s))return;let f=o.find(c=>c.id===s);if(f){i.appendChild(f.cloneNode(!0)),a.add(s);return}for(let c of r){let l=c.querySelector(`#${CSS.escape(s)}`);if(l){let m=i.querySelector("defs");m||(m=document.createElementNS("http://www.w3.org/2000/svg","defs"),i.appendChild(m)),m.appendChild(l.cloneNode(!0)),a.add(s);break}}})}async function Qt(t,e={}){let n={styleMap:d.session.styleMap,styleCache:d.session.styleCache,nodeMap:d.session.nodeMap},o,r="",i="";Ve(t);try{Yt(t)}catch(s){console.warn("inlineExternal defs or symbol failed:",s)}try{o=await st(t,n,e,t)}catch(s){throw console.warn("deepClone failed:",s),s}try{await _t(t,o,n,e)}catch(s){console.warn("inlinePseudoElements failed:",s)}await Ye(o);try{let s=o.querySelectorAll("style[data-sd]");for(let f of s)i+=f.textContent||"",f.remove()}catch{}let a=Rt(n.styleMap);r=Array.from(a.entries()).map(([s,f])=>`.${f}{${s}}`).join(""),r=i+r;for(let[s,f]of n.styleMap.entries()){if(s.tagName==="STYLE")continue;if(s.getRootNode&&s.getRootNode()instanceof ShadowRoot){s.setAttribute("style",f.replace(/;/g,"; "));continue}let c=a.get(f);c&&s.classList.add(c);let l=s.style?.backgroundImage,m=s.dataset?.snapdomHasIcon;l&&l!=="none"&&(s.style.backgroundImage=l),m&&(s.style.verticalAlign="middle",s.style.display="inline")}for(let[s,f]of n.nodeMap.entries()){let c=f.scrollLeft,l=f.scrollTop;if((c||l)&&s instanceof HTMLElement){s.style.overflow="hidden",s.style.scrollbarWidth="none",s.style.msOverflowStyle="none";let x=document.createElement("div");for(x.style.transform=`translate(${-c}px, ${-l}px)`,x.style.willChange="transform",x.style.display="inline-block",x.style.width="100%";s.firstChild;)x.appendChild(s.firstChild);s.appendChild(x)}}if(t===n.nodeMap.get(o)){let s=n.styleCache.get(t)||window.getComputedStyle(t);n.styleCache.set(t,s);let f=At(s.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=f||""}for(let[s,f]of n.nodeMap.entries())f.tagName==="PRE"&&(s.style.marginTop="0",s.style.marginBlockStart="0");return{clone:o,classCSS:r,styleCache:n.styleCache}}function Ve(t){let e=getComputedStyle(t),n=e.outlineStyle,o=e.outlineWidth,r=e.borderStyle,i=e.borderWidth,a=n!=="none"&&parseFloat(o)>0,s=r==="none"||parseFloat(i)===0;a&&s&&(t.style.border=`${o} solid transparent`)}var it=new Map;async function ct(t){if(d.resource?.has(t))return d.resource.get(t);if(it.has(t))return it.get(t);let e=(async()=>{let n=await O(t,{as:"dataURL",silent:!0});if(!n.ok||typeof n.data!="string")throw new Error(`[snapDOM] Failed to read blob URL: ${t}`);return d.resource?.set(t,n.data),n.data})();it.set(t,e);try{let n=await e;return it.set(t,n),n}catch(n){throw it.delete(t),n}}var Ge=/\bblob:[^)"'\s]+/g;async function Jt(t){if(!t||t.indexOf("blob:")===-1)return t;let e=Array.from(new Set(t.match(Ge)||[]));if(e.length===0)return t;let n=t;for(let o of e)try{let r=await ct(o);n=n.split(o).join(r)}catch{}return n}function bt(t){return typeof t=="string"&&t.startsWith("blob:")}function Ke(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 Xe(t){return t.map(e=>e.desc?`${e.url} ${e.desc.trim()}`:e.url).join(", ")}async function Ye(t){if(!t)return;let e=t.querySelectorAll?t.querySelectorAll("img"):[];for(let a of e)try{let f=a.getAttribute("src")||a.currentSrc||"";if(bt(f)){let l=await ct(f);a.setAttribute("src",l)}let c=a.getAttribute("srcset");if(c&&c.includes("blob:")){let l=Ke(c),m=!1;for(let x of l)if(bt(x.url))try{x.url=await ct(x.url),m=!0}catch{}m&&a.setAttribute("srcset",Xe(l))}}catch{}let n=t.querySelectorAll?t.querySelectorAll("image"):[];for(let a of n)try{let s="http://www.w3.org/1999/xlink",f=a.getAttribute("href")||a.getAttributeNS?.(s,"href");if(bt(f)){let c=await ct(f);a.setAttribute("href",c),a.removeAttributeNS?.(s,"href")}}catch{}let o=t.querySelectorAll?t.querySelectorAll("[style*='blob:']"):[];for(let a of o)try{let s=a.getAttribute("style");if(s&&s.includes("blob:")){let f=await Jt(s);a.setAttribute("style",f)}}catch{}let r=t.querySelectorAll?t.querySelectorAll("style"):[];for(let a of r)try{let s=a.textContent||"";s.includes("blob:")&&(a.textContent=await Jt(s))}catch{}let i=["poster"];for(let a of i){let s=t.querySelectorAll?t.querySelectorAll(`[${a}^='blob:']`):[];for(let f of s)try{let c=f.getAttribute(a);bt(c)&&f.setAttribute(a,await ct(c))}catch{}}}async function Zt(t,e={}){let n=Array.from(t.querySelectorAll("img")),o=async r=>{if(!r.getAttribute("src")){let l=r.currentSrc||r.src||"";l&&r.setAttribute("src",l)}r.removeAttribute("srcset"),r.removeAttribute("sizes");let i=r.src||"";if(!i)return;let a=await O(i,{as:"dataURL",useProxy:e.useProxy});if(a.ok&&typeof a.data=="string"&&a.data.startsWith("data:")){r.src=a.data,r.width||(r.width=r.naturalWidth||100),r.height||(r.height=r.naturalHeight||100);return}let{defaultImageUrl:s}=e||{};if(s)try{let l=parseInt(r.dataset?.snapdomWidth||"",10)||0,m=parseInt(r.dataset?.snapdomHeight||"",10)||0,x=parseInt(r.getAttribute("width")||"",10)||0,T=parseInt(r.getAttribute("height")||"",10)||0,C=parseFloat(r.style?.width||"")||0,A=parseFloat(r.style?.height||"")||0,w=l||C||x||r.width||void 0,k=m||A||T||r.height||void 0,$=typeof s=="function"?await s({width:w,height:k,src:i,element:r}):s;if($){let F=await O($,{as:"dataURL",useProxy:e.useProxy});r.src=F.data,!r.width&&w&&(r.width=w),!r.height&&k&&(r.height=k),r.width||(r.width=r.naturalWidth||100),r.height||(r.height=r.naturalHeight||100);return}}catch{}let f=r.width||r.naturalWidth||100,c=r.height||r.naturalHeight||100;if(e.placeholders!==!1){let l=document.createElement("div");l.style.cssText=[`width:${f}px`,`height:${c}px`,"background:#ccc","display:inline-block","text-align:center",`line-height:${c}px`,"color:#666","font-size:12px","overflow:hidden"].join(";"),l.textContent="img",r.replaceWith(l)}else{let l=document.createElement("div");l.style.cssText=`display:inline-block;width:${f}px;height:${c}px;visibility:hidden;`,r.replaceWith(l)}};for(let r=0;r<n.length;r+=4){let i=n.slice(r,r+4).map(o);await Promise.allSettled(i)}}async function St(t,e,n,o={}){let r=[[t,e]],i=["background-image","mask","mask-image","-webkit-mask","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source","border-image","border-image-source"],a=["mask-position","mask-size","mask-repeat","-webkit-mask-position","-webkit-mask-size","-webkit-mask-repeat","mask-origin","mask-clip","-webkit-mask-origin","-webkit-mask-clip","-webkit-mask-position-x","-webkit-mask-position-y"],s=["border-image-slice","border-image-width","border-image-outset","border-image-repeat"];for(;r.length;){let[f,c]=r.shift(),l=n.get(f)||Z(f);n.has(f)||n.set(f,l);let m=(()=>{let C=l.getPropertyValue("border-image"),A=l.getPropertyValue("border-image-source");return C&&C!=="none"||A&&A!=="none"})();for(let C of i){let A=l.getPropertyValue(C);if(!A||A==="none")continue;let w=tt(A),k=await Promise.all(w.map($=>Q($,o)));k.some($=>$&&$!=="none"&&!/^url\(undefined/.test($))&&c.style.setProperty(C,k.join(", "))}for(let C of a){let A=l.getPropertyValue(C);!A||A==="initial"||c.style.setProperty(C,A)}if(m)for(let C of s){let A=l.getPropertyValue(C);!A||A==="initial"||c.style.setProperty(C,A)}let x=Array.from(f.children),T=Array.from(c.children);for(let C=0;C<Math.min(x.length,T.length);C++)r.push([x[C],T[C]])}}async function Bt(t,e){if(!t)throw new Error("Element cannot be null or undefined");lt(e.cache);let n=e.fast,o,r,i,a="",s="",f,c;({clone:o,classCSS:r,styleCache:i}=await Qt(t,e)),await new Promise(T=>{V(async()=>{await Zt(o,e),T()},{fast:n})}),await new Promise(T=>{V(async()=>{await St(t,o,i,e),T()},{fast:n})}),e.embedFonts&&await new Promise(T=>{V(async()=>{let C=gt(t),A=yt(t);if(G){let w=new Set(Array.from(C).map(k=>String(k).split("__")[0]).filter(Boolean));await wt(w,2)}a=await pt({required:C,usedCodepoints:A,preCached:!1,exclude:e.excludeFonts,useProxy:e.useProxy}),T()},{fast:n})});let l=Mt(o).sort(),m=l.join(",");d.baseStyle.has(m)?s=d.baseStyle.get(m):await new Promise(T=>{V(()=>{s=vt(l),d.baseStyle.set(m,s),T()},{fast:n})}),await new Promise(T=>{V(()=>{let C=Je(t),A=C.width,w=C.height,k=Number.isFinite(e.width),$=Number.isFinite(e.height),F=e.scale??1,U=typeof F=="number"&&F!==1;if(!U){let L=C.width/C.height;k&&$?(A=e.width,w=e.height):k?(A=e.width,w=A/L):$&&(w=e.height,A=w*L)}A=Math.max(1,Math.ceil(A)),w=Math.max(1,Math.ceil(w));let D=getComputedStyle(t),P=D.transform&&D.transform!=="none"?D.transform:"",q=tn(t),u,p,g,b,h=0,y=0;if(en(t)){let L=rn({baseTransform:P,rotate:q.rotate||"0deg",scale:q.scale,translate:q.translate}),H=L.e??L.m41??0,nt=L.f??L.m42??0;h=-H,y=-nt;let Ct=L.is2D?te(L):te(new DOMMatrix(L.toString())),z=Ze(A,w,Ct);u=Math.max(1,Math.ceil(z.width)),p=Math.max(1,Math.ceil(z.height)),g=-z.minX,b=-z.minY}else{let L=t.getBoundingClientRect(),H=nn(L,{top:0,right:0,bottom:0,left:0});u=Math.max(1,H.width),p=Math.max(1,H.height),g=-(H.x-Math.floor(L.left)),b=-(H.y-Math.floor(L.top))}let E="http://www.w3.org/2000/svg",S=document.createElementNS(E,"foreignObject");S.setAttribute("width","100%"),S.setAttribute("height","100%"),S.setAttribute("x",String(g)),S.setAttribute("y",String(b)),S.style.overflow="visible";let v=document.createElement("style");v.textContent=s+a+"svg{overflow:visible;} foreignObject{overflow:visible;}"+r,S.appendChild(v);let R=document.createElement("div");R.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),R.style.width=`${A}px`,R.style.height=`${w}px`,R.style.overflow="visible",R.style.transformOrigin="0 0";let I=[];if((h||y)&&I.push(`translate(${h}px, ${y}px)`),!U&&(k||$)){let L=C.width?A/C.width:1,H=C.height?w/C.height:1;I.push(`scale(${L}, ${H})`)}else U&&I.push(`scale(${F})`);I.length&&(R.style.transform=I.join(" ")),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="0 0",o.style.position="static",o.style.left="0",o.style.top="0",P&&(o.style.transform=P),o.style.rotate=q.rotate||"0deg",o.style.scale=q.scale||"1",o.style.translate=q.translate||"0 0",R.appendChild(o),S.appendChild(R);let M=new XMLSerializer().serializeToString(S);c=`<svg xmlns="${E}" width="${u}" height="${p}" viewBox="0 0 ${u} ${p}">`+M+"</svg>",f=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(c)}`,T()},{fast:n})});let x=document.getElementById("snapdom-sandbox");return x&&x.style.position==="absolute"&&x.remove(),f}function Je(t){let e=getComputedStyle(t),n=i=>parseFloat(i)||0,o=n(e.width),r=n(e.height);return e.boxSizing==="content-box"&&(o+=n(e.paddingLeft)+n(e.paddingRight)+n(e.borderLeftWidth)+n(e.borderRightWidth),r+=n(e.paddingTop)+n(e.paddingBottom)+n(e.borderTopWidth)+n(e.borderBottomWidth)),{width:o,height:r}}function Qe(t){let e=getComputedStyle(t).transform;if(!e||e==="none")return new DOMMatrix;try{return new DOMMatrix(e)}catch{return new WebKitCSSMatrix(e)}}function te(t){return new DOMMatrix([t.a,t.b,t.c,t.d,0,0])}function Ze(t,e,n){let r=[{x:0,y:0},{x:t,y:0},{x:0,y:e},{x:t,y:e}].map(c=>({x:n.a*c.x+n.c*c.y,y:n.b*c.x+n.d*c.y})),i=Math.min(...r.map(c=>c.x)),a=Math.max(...r.map(c=>c.x)),s=Math.min(...r.map(c=>c.y)),f=Math.max(...r.map(c=>c.y));return{minX:i,minY:s,width:a-i,height:f-s}}function tn(t){let e={rotate:"0deg",scale:null,translate:null},n=t.computedStyleMap?.();if(n){let r=n.get("rotate");if(r){let s=r.angle??r;s&&"unit"in s?e.rotate=s.unit==="rad"?s.value*180/Math.PI+"deg":s.value+s.unit:e.rotate=String(r)}let i=n.get("scale");if(i&&i.length){let s=i[0]?.value??1,f=i[1]?.value??s;e.scale=`${s} ${f}`}let a=n.get("translate");if(a&&a.length){let s=a[0]?.value??0,f=a[1]?.value??0,c=a[0]?.unit??"px",l=a[1]?.unit??"px";e.translate=`${s}${c} ${f}${l}`}return e}let o=getComputedStyle(t);return e.rotate=o.rotate&&o.rotate!=="none"?o.rotate:"0deg",e.scale=o.scale&&o.scale!=="none"?o.scale:null,e.translate=o.translate&&o.translate!=="none"?o.translate:null,e}function en(t){let e=getComputedStyle(t).transform||"none";return!(e==="none"||e==="matrix(1, 0, 0, 1, 0, 0)"||/^matrix\(\s*1\s*,\s*0\s*,\s*0\s*,\s*1\s*,/i.test(e))}function nn(t,e){let n=Math.floor(t.left-e.left),o=Math.floor(t.top-e.top),r=Math.ceil(t.width+e.left+e.right),i=Math.ceil(t.height+e.top+e.bottom);return{x:n,y:o,width:r,height:i}}var Pt=null;function on(){if(Pt)return Pt;let t=document.createElement("div");return t.id="snapdom-measure-slot",t.setAttribute("aria-hidden","true"),Object.assign(t.style,{position:"absolute",left:"-99999px",top:"0px",width:"0px",height:"0px",overflow:"hidden",opacity:"0",pointerEvents:"none",contain:"size layout style"}),document.documentElement.appendChild(t),Pt=t,t}function rn(t){let e=on(),n=document.createElement("div");n.style.transformOrigin="0 0",t.baseTransform&&(n.style.transform=t.baseTransform),t.rotate&&(n.style.rotate=t.rotate),t.scale&&(n.style.scale=t.scale),t.translate&&(n.style.translate=t.translate),e.appendChild(n);let o=Qe(n);return e.removeChild(n),o}function an(t){if(typeof t=="string"){let e=t.toLowerCase().trim();if(e==="disabled"||e==="full"||e==="auto"||e==="soft")return e}return"soft"}function ee(t={}){let e=t.format??"png",n=an(t.cache);return{debug:t.debug??!1,fast:t.fast??!0,scale:t.scale??1,exclude:t.exclude??[],excludeMode:t.excludeMode??"visuallyHide",filter:t.filter??null,filterMode:t.filterMode??"visuallyHide",placeholders:t.placeholders!==!1,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,defaultImageUrl:t.defaultImageUrl??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 ne(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 X(t,e){let{scale:n,dpr:o}=e,r=new Image;r.crossOrigin="anonymous",r.loading="eager",r.decoding="sync",r.src=t,await r.decode();let i=r.naturalWidth*n,a=r.naturalHeight*n,s=document.createElement("canvas");s.width=Math.ceil(i*o),s.height=Math.ceil(a*o),s.style.width=`${i}px`,s.style.height=`${a}px`;let f=s.getContext("2d");return o!==1&&f.scale(o,o),f.drawImage(r,0,0,i,a),s}async function xt(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 X(t,e),r=e.backgroundColor?J(o,e.backgroundColor):o;return new Promise(i=>r.toBlob(a=>i(a),`image/${n}`,e.quality))}async function oe(t,e){let n=await X(t,e),o=e.backgroundColor?J(n,e.backgroundColor):n,r=new Image;return r.src=o.toDataURL(`image/${e.format}`,e.quality),await r.decode(),r.style.width=`${o.width/e.dpr}px`,r.style.height=`${o.height/e.dpr}px`,r}async function re(t,e){if(e.format==="svg"){let i=await xt(t,{...e,type:"svg"}),a=URL.createObjectURL(i),s=document.createElement("a");s.href=a,s.download=e.filename,s.click(),URL.revokeObjectURL(a);return}let n=await X(t,e),o=e.backgroundColor?J(n,e.backgroundColor):n,r=document.createElement("a");r.href=o.toDataURL(`image/${e.format}`,e.quality),r.download=e.filename,r.click()}var ae=Symbol("snapdom.internal"),Wt=!1;async function _(t,e){if(!t)throw new Error("Element cannot be null or undefined");if(G())for(let o=0;o<3;o++)try{await sn(t,e),console.log("Iteraci\xF3n n\xFAmero:",o),Wt=!1}catch{}let n=ee(e);return n.iconFonts&&n.iconFonts.length>0&&Kt(n.iconFonts),n.snap||(n.snap={toPng:(o,r)=>_.toPng(o,r),toImg:(o,r)=>_.toImg(o,r)}),_.capture(t,n,ae)}_.capture=async(t,e,n)=>{if(n!==ae)throw new Error("[snapdom.capture] is internal. Use snapdom(...) instead.");let o=await Bt(t,e),r=a=>({...e,...a||{}}),i=a=>s=>{let f=r({...s||{},format:a}),c=a==="jpeg"||a==="jpg",l=f.backgroundColor==null||f.backgroundColor==="transparent";return c&&l&&(f.backgroundColor="#ffffff"),oe(o,f)};return{url:o,toRaw:()=>o,toImg:a=>ne(o,r(a)),toCanvas:a=>X(o,r(a)),toBlob:a=>xt(o,r(a)),toPng:i("png"),toJpg:i("jpeg"),toWebp:i("webp"),download:a=>re(o,r(a))}};_.toRaw=(t,e)=>_(t,e).then(n=>n.toRaw());_.toImg=(t,e)=>_(t,e).then(n=>n.toImg());_.toCanvas=(t,e)=>_(t,e).then(n=>n.toCanvas());_.toBlob=(t,e)=>_(t,e).then(n=>n.toBlob());_.toPng=(t,e)=>_(t,{...e,format:"png"}).then(n=>n.toPng());_.toJpg=(t,e)=>_(t,{...e,format:"jpeg"}).then(n=>n.toJpg());_.toWebp=(t,e)=>_(t,{...e,format:"webp"}).then(n=>n.toWebp());_.download=(t,e)=>_(t,e).then(n=>n.download());async function sn(t,e){if(Wt)return;let n={...e,fast:!0,embedFonts:!0,scale:.2},o;try{o=await Bt(t,n)}catch{return}await new Promise(r=>{let i=new Image;i.decoding="sync",i.loading="eager",i.style.position="fixed",i.style.left=0,i.style.top=0,i.style.width="10px",i.style.height="10px",i.style.opacity="0.01",i.style.transform="translateZ(10px)",i.style.willChange="transform,opacity;",i.src=o;let a=async()=>{await new Promise(s=>setTimeout(s,100)),i&&i.parentNode&&i.parentNode.removeChild(i),Wt=!0,r()};document.body.appendChild(i),a()})}async function cn(t=document,e={}){let{embedFonts:n=!0,useProxy:o=""}=e,r=e.cache??e.cacheOpt??"full";lt(r);try{await document.fonts?.ready}catch{}try{$t()}catch{}d.session=d.session||{},d.session.styleCache||(d.session.styleCache=new WeakMap),d.image=d.image||new Map;try{await St(t,void 0,d.session.styleCache,{useProxy:o})}catch{}let i=[],a=[];try{t?.querySelectorAll&&(i=Array.from(t.querySelectorAll("img[src]")),a=Array.from(t.querySelectorAll("*")))}catch{}let s=[];for(let f of i){let c=f?.currentSrc||f?.src;if(c&&!d.image.has(c)){let l=Promise.resolve().then(async()=>{let m=await O(c,{as:"dataURL",useProxy:o});m?.ok&&typeof m.data=="string"&&d.image.set(c,m.data)}).catch(()=>{});s.push(l)}}for(let f of a){let c="";try{c=Z(f).backgroundImage}catch{}if(c&&c!=="none"){let l=tt(c);for(let m of l)if(m.startsWith("url(")){let x=Promise.resolve().then(()=>Q(m,{...e,useProxy:o})).catch(()=>{});s.push(x)}}}if(n)try{let f=gt(t),c=yt(t);if(typeof G=="function"?G():!!G){let m=new Set(Array.from(f).map(x=>String(x).split("__")[0]).filter(Boolean));await wt(m,2)}await pt({required:f,usedCodepoints:c,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:e.useProxy??o})}catch{}await Promise.allSettled(s)}export{cn as preCache,_ as snapdom};
|