@zumer/snapdom 1.9.10-dev.2 → 1.9.10
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 +62 -40
- package/dist/snapdom.js +49 -15
- package/dist/snapdom.min.js +3 -3
- package/dist/snapdom.min.mjs +4 -4
- package/dist/snapdom.mjs +49 -15
- package/package.json +1 -1
- package/types/snapdom.d.ts +100 -56
package/dist/snapdom.min.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var h={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":{h.session.styleMap=new Map,h.session.nodeMap=new Map;return}case"soft":{h.session.styleMap=new Map,h.session.nodeMap=new Map,h.session.styleCache=new WeakMap;return}case"full":return;case"disabled":{h.session.styleMap=new Map,h.session.nodeMap=new Map,h.session.styleCache=new WeakMap,h.computedStyle=new WeakMap,h.baseStyle=new Map,h.defaultStyle=new Map,h.image=new Map,h.background=new Map,h.resource=new Map,h.font=new Set;return}default:{h.session.styleMap=new Map,h.session.nodeMap=new Map,h.session.styleCache=new WeakMap;return}}}function
|
|
2
|
-
`;return n}function Ft(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=h.computedStyle.get(t);if(n||(n=new Map,h.computedStyle.set(t,n)),!n.has(e)){let o=window.getComputedStyle(t,e);n.set(e,o)}return n.get(e)}function Lt(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 Q(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 X(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}var qt=new WeakMap,Rt=new Map,Tt=0;function
|
|
1
|
+
var h={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":{h.session.styleMap=new Map,h.session.nodeMap=new Map;return}case"soft":{h.session.styleMap=new Map,h.session.nodeMap=new Map,h.session.styleCache=new WeakMap;return}case"full":return;case"disabled":{h.session.styleMap=new Map,h.session.nodeMap=new Map,h.session.styleCache=new WeakMap,h.computedStyle=new WeakMap,h.baseStyle=new Map,h.defaultStyle=new Map,h.image=new Map,h.background=new Map,h.resource=new Map,h.font=new Set;return}default:{h.session.styleMap=new Map,h.session.nodeMap=new Map,h.session.styleCache=new WeakMap;return}}}function G(t){let e=t.match(/url\((['"]?)(.*?)(\1)\)/);if(!e)return null;let n=e[2].trim();return n.startsWith("#")?null:n}function kt(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 rt(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function ae(t="[snapDOM]",{ttlMs:e=5*6e4,maxEntries:n=12}={}){let o=new Map,r=0;function i(s,a,f){if(r>=n)return;let c=Date.now();(o.get(a)||0)>c||(o.set(a,c+e),r++,s==="warn"&&console&&console.warn?console.warn(`${t} ${f}`):console&&console.error&&console.error(`${t} ${f}`))}return{warnOnce(s,a){i("warn",s,a)},errorOnce(s,a){i("error",s,a)},reset(){o.clear(),r=0}}}var Bt=ae("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),At=new Map,ft=new Map;function ie(t){return/^data:|^blob:|^about:blank$/.test(t)}function ce(t,e){if(!e||ie(t))return!1;try{let n=typeof location<"u"&&location.href?location.href:"http://localhost/",o=new URL(t,n);return typeof location<"u"?o.origin!==location.origin:!0}catch{return!!e}}function le(t,e){if(!e)return t;if(e.includes("{url}"))return e.replace("{url}",encodeURIComponent(t));let n=e.endsWith("?")?"":e.includes("?")?"&":"?";return`${e}${n}url=${encodeURIComponent(t)}`}function fe(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 ue(t,e){return[e.as||"blob",e.timeout??3e3,e.useProxy||"",e.errorTTL??8e3,t].join("|")}async function B(t,e={}){let n=e.as??"blob",o=e.timeout??3e3,r=e.useProxy||"",i=e.errorTTL??8e3,s=e.headers||{},a=!!e.silent,f=ue(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=At.get(f);if(l)return l;let d=ce(t,r)?le(t,r):t,x=e.credentials;if(!x)try{let w=typeof location<"u"&&location.href?location.href:"http://localhost/",F=new URL(t,w);x=typeof location<"u"&&F.origin===location.origin?"include":"omit"}catch{x="omit"}let R=new AbortController,C=setTimeout(()=>R.abort("timeout"),o),k=(async()=>{try{let w=await fetch(d,{signal:R.signal,credentials:x,headers:s});if(!w.ok){let T={ok:!1,data:null,status:w.status,url:d,fromCache:!1,reason:"http_error"};if(ft.set(f,{until:Date.now()+i,result:T}),!a){let _=`${w.status} ${w.statusText||""}`.trim();Bt.warnOnce(`http:${w.status}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,`HTTP error ${_} while fetching ${n} ${t}`)}return e.onError&&e.onError(T),T}if(n==="text")return{ok:!0,data:await w.text(),status:w.status,url:d,fromCache:!1};let F=await w.blob(),M=F.type||w.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await fe(F),status:w.status,url:d,fromCache:!1,mime:M}:{ok:!0,data:F,status:w.status,url:d,fromCache:!1,mime:M}}catch(w){let F=w&&typeof w=="object"&&"name"in w&&w.name==="AbortError"?String(w.message||"").includes("timeout")?"timeout":"abort":"network",M={ok:!1,data:null,status:0,url:d,fromCache:!1,reason:F};if(ft.set(f,{until:Date.now()+i,result:M}),!a){let T=`${F}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,_=F==="timeout"?`Timeout after ${o}ms. Consider increasing timeout or using a proxy for ${t}`:F==="abort"?`Request aborted while fetching ${n} ${t}`:`Network/CORS issue while fetching ${n} ${t}. A proxy may be required`;Bt.errorOnce(T,_)}return e.onError&&e.onError(M),M}finally{clearTimeout(C),At.delete(f)}})();return At.set(f,k),k}function Y(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 J(t,e={}){if(/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t)||t.trim()==="none")return t;let o=G(t);if(!o)return t;let r=rt(o);if(h.background.has(r)){let i=h.background.get(r);return i?`url("${i}")`:"none"}try{let i=await B(r,{as:"dataURL",useProxy:e.useProxy});return i.ok?(h.background.set(r,i.data),`url("${i.data}")`):(h.background.set(r,null),"none")}catch{return h.background.set(r,null),"none"}}var ut=new Set(["meta","script","noscript","title","link","template"]),nt=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"]),de=["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 de){let e=String(t).toLowerCase();ut.has(e)||nt.has(e)||Et(e)}}function Et(t){if(t=String(t).toLowerCase(),nt.has(t)){let i={};return h.defaultStyle.set(t,i),i}if(h.defaultStyle.has(t))return h.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(Dt(i))continue;let s=o.getPropertyValue(i);r[i]=s}return e.removeChild(n),h.defaultStyle.set(t,r),r}var he=/(?:^|-)(animation|transition)(?:-|$)/i,me=/^(--|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,pe=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 Dt(t){let e=String(t).toLowerCase();return!!(pe.has(e)||me.test(e)||he.test(e))}function ot(t,e){if(e=String(e||"").toLowerCase(),nt.has(e))return"";let n=[],o=Et(e);for(let[r,i]of Object.entries(t)){if(Dt(r))continue;let s=o[r];i&&i!==s&&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=h.defaultStyle.get(o);if(!r)continue;let i=Object.entries(r).map(([s,a])=>`${s}:${a};`).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 Ft(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=h.computedStyle.get(t);if(n||(n=new Map,h.computedStyle.set(t,n)),!n.has(e)){let o=window.getComputedStyle(t,e);n.set(e,o)}return n.get(e)}function Lt(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 Q(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 X(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}var qt=new WeakMap,Rt=new Map,Tt=0;function st(){Tt++}var jt=!1;function ge(t=document.documentElement){if(!jt){jt=!0;try{new MutationObserver(()=>st()).observe(t,{subtree:!0,childList:!0,characterData:!0,attributes:!0})}catch{}try{new MutationObserver(()=>st()).observe(document.head,{subtree:!0,childList:!0,characterData:!0,attributes:!0})}catch{}try{let e=document.fonts;e&&(e.addEventListener?.("loadingdone",st),e.ready?.then(()=>st()).catch(()=>{}))}catch{}}}function ye(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 Ht=new WeakMap;function we(t){let e=Ht.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(";"),Ht.set(t,e),e)}function be(t,e=null){let n=qt.get(t);if(n&&n.epoch===Tt)return n.snapshot;let o=e||getComputedStyle(t),r=ye(o);return qt.set(t,{epoch:Tt,snapshot:r}),r}function Se(t,e){return t&&t.session&&t.persist?t:t&&(t.styleMap||t.styleCache||t.nodeMap)?{session:t,persist:{snapshotKeyCache:Rt,defaultStyle:h.defaultStyle,baseStyle:h.baseStyle,image:h.image,resource:h.resource,background:h.background,font:h.font},options:e||{}}:{session:h.session,persist:{snapshotKeyCache:Rt,defaultStyle:h.defaultStyle,baseStyle:h.baseStyle,image:h.image,resource:h.resource,background:h.background,font:h.font},options:t||e||{}}}async function tt(t,e,n,o){if(t.tagName==="STYLE")return;let r=Se(n,o),i=r.options&&r.options.cache||"auto";if(i!=="disabled"&&ge(document.documentElement),i==="disabled"&&!r.session.__bumpedForDisabled&&(st(),Rt.clear(),r.session.__bumpedForDisabled=!0),nt.has(t.tagName?.toLowerCase())){let x=t.getAttribute?.("style");x&&e.setAttribute("style",x)}let{session:s,persist:a}=r;s.styleCache.has(t)||s.styleCache.set(t,getComputedStyle(t));let f=s.styleCache.get(t),c=be(t,f),l=we(c),d=a.snapshotKeyCache.get(l);if(!d){let x=t.tagName?.toLowerCase()||"div";d=ot(c,x),a.snapshotKeyCache.set(l,d)}s.styleMap.set(e,d)}function Nt(t,e,n){return Promise.all(t.map(o=>new Promise(r=>{function i(){V(s=>{s instanceof IdleDeadline?s.timeRemaining()?e(o,r):i():e(o,r)},{fast:n})}i()})))}function xe(t){return t=t.trim(),!t||/\:not\(\s*\[data-sd-slotted\]\s*\)\s*$/.test(t)?t:`${t}:not([data-sd-slotted])`}function Ce(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?xe(o):o;return`:where(${e} ${r})`}).join(", ")}function ke(t,e){return t?(t=t.replace(/:host\(([^)]+)\)/g,(n,o)=>`:where(${e}:is(${o.trim()}))`),t=t.replace(/:host\b/g,`:where(${e})`),t=t.replace(/:host-context\(([^)]+)\)/g,(n,o)=>`:where(:where(${o.trim()}) ${e})`),t=t.replace(/::slotted\(([^)]+)\)/g,(n,o)=>`:where(${e} ${o.trim()})`),t=t.replace(/(^|})(\s*)([^@}{]+){/g,(n,o,r,i)=>{let s=Ce(i,e,!0);return`${o}${r}${s}{`}),t):""}function Ae(t){return t.shadowScopeSeq=(t.shadowScopeSeq||0)+1,`s${t.shadowScopeSeq}`}function $e(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 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 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:a}=Ne(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=Ie(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 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(a.width)}px`),d.style.height||(d.style.height=`${Math.round(a.height)}px`),d.appendChild(l),d}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"){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 a;try{if(a=t.cloneNode(!1),e.nodeMap.set(a,t),t.tagName==="IMG"){Me(t,a);try{let c=t.getBoundingClientRect(),l=Math.round(c.width||0),d=Math.round(c.height||0);if(!l||!d){let w=window.getComputedStyle(t),E=parseFloat(w.width)||0,M=parseFloat(w.height)||0,v=parseInt(t.getAttribute("width")||"",10)||0,b=parseInt(t.getAttribute("height")||"",10)||0,L=t.width||t.naturalWidth||0,R=t.height||t.naturalHeight||0;l=Math.round(l||E||v||L||0),d=Math.round(d||M||b||R||0)}l&&(a.dataset.snapdomWidth=String(l)),d&&(a.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();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),tt(t,a,e,n),t.shadowRoot){let b=function(R,T){if(R.nodeType===Node.ELEMENT_NODE&&R.tagName==="STYLE")return T(null);st(R,e,n).then(_=>{T(_||null)}).catch(_=>{T(null)})};try{let R=t.shadowRoot.querySelectorAll("slot");for(let T of R){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{a.setAttribute("data-sd",c)}catch{}let d=Ee(t.shadowRoot),w=$e(d,l),E=ve(d),M=Le(t,E,l);ke(a,M+w,c);let v=document.createDocumentFragment(),L=await Nt(Array.from(t.shadowRoot.childNodes),b,n.fast);v.append(...L.filter(R=>!!R)),a.appendChild(v)}if(t.tagName==="SLOT"){let w=function(M,v){st(M,e,n).then(b=>{b&&Re(b),v(b||null)}).catch(b=>{v(null)})},c=t.assignedNodes?.({flatten:!0})||[],l=c.length>0?c:Array.from(t.childNodes),d=document.createDocumentFragment(),E=await Nt(Array.from(l),w,n.fast);return d.append(...E.filter(M=>!!M)),d}function s(c,l){if(o.has(c))return l(null);st(c,e,n).then(d=>{l(d||null)}).catch(d=>{l(null)})}let f=await Nt(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 _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 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 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 We=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&&!We.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 Ue(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]),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 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(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 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,S,m]=String(u).split("__");if(!p)continue;let y=i.get(p)||[];y.push({w:parseInt(g,10),s:S,st:parseInt(m,10)}),i.set(p,y)}let a=/@import\s+url\(["']?([^"')]+)["']?\)/g,s=/url\((["']?)([^"')]+)\1\)/g,f=/@font-face[^{}]*\{[^}]*\}/g;function c(u,p,g,S){if(!i.has(u))return!1;let m=i.get(u),y=Be(g),C=Oe(p),x=De(S),A=y.min!==y.max,k=y.min,N=$=>C.kind==="normal"&&$==="normal"||C.kind!=="normal"&&($==="italic"||$==="oblique"),U=!1;for(let $ of m){let I=A?$.w>=y.min&&$.w<=y.max:$.w===k,B=N(Pt($.s)),F=$.st>=x.min&&$.st<=x.max;if(I&&B&&F){U=!0;break}}if(U)return!0;if(!A)for(let $ of m){let I=N(Pt($.s)),B=$.st>=x.min&&$.st<=x.max;if(Math.abs(k-$.w)<=300&&I&&B)return!0}return!1}function l(u){if(!u)return[];let p=[],g=u.split(",").map(S=>S.trim()).filter(Boolean);for(let S of g){let m=S.match(/^U\+([0-9A-Fa-f?]+)(?:-([0-9A-Fa-f?]+))?$/);if(!m)continue;let y=m[1],C=m[2],x=A=>{if(!A.includes("?"))return parseInt(A,16);let k=parseInt(A.replace(/\?/g,"0"),16),N=parseInt(A.replace(/\?/g,"F"),16);return[k,N]};if(C){let A=x(y),k=x(C),N=Array.isArray(A)?A[0]:A,U=Array.isArray(k)?k[1]:k;p.push([Math.min(N,U),Math.max(N,U)])}else{let A=x(y);Array.isArray(A)?p.push([A[0],A[1]]):p.push([A,A])}}return p}function d(u,p){if(!p.length||!u||u.size===0)return!0;for(let g of u)for(let[S,m]of p)if(g>=S&&g<=m)return!0;return!1}function w(u,p){let g=[];if(!u)return g;for(let S of u.matchAll(s)){let m=(S[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 E(u,p){let g=u;for(let S of u.matchAll(s)){let m=K(S[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(S[0],`url(${h.resource.get(y)})`);continue}if(!h.font?.has(y))try{let C=await O(y,{as:"dataURL",useProxy:r,silent:!0});if(C.ok&&typeof C.data=="string"){let x=C.data;h.resource?.set(y,x),h.font?.add(y),g=g.replace(S[0],`url(${x})`)}}catch{console.warn("[snapDOM] Failed to fetch font resource:",y)}}}return g}function M(u){if(!u.length)return null;let p=(x,A)=>u.some(([k,N])=>!(N<x||k>A)),g=p(0,255)||p(305,305),S=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":S?"latin-ext":g?"latin":null}function v(u={}){let p=new Set((u.families||[]).map(m=>String(m).toLowerCase())),g=new Set((u.domains||[]).map(m=>String(m).toLowerCase())),S=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 C of m.srcUrls)try{if(g.has(new URL(C).host.toLowerCase()))return!0}catch{}if(S.size){let C=M(y);if(C&&S.has(C))return!0}return!1}}let b=v(n);function L(u){if(!u)return u;let p=/@font-face[^{}]*\{[^}]*\}/gi,g=new Set,S=[];for(let y of u.match(p)||[]){let C=y.match(/font-family:\s*([^;]+);/i)?.[1]||"",x=ht(C),A=(y.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),k=(y.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),N=(y.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),U=(y.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),$=(y.match(/src\s*:\s*([^;]+);/i)?.[1]||"").trim(),I=w($,location.href),B=I.length?I.map(j=>String(j).toLowerCase()).sort().join("|"):$.toLowerCase(),F=[String(x||"").toLowerCase(),A,k,N,U.toLowerCase(),B].join("|");g.has(F)||(g.add(F),S.push(y))}if(S.length===0)return u;let m=0;return u.replace(p,()=>S[m++]||"")}function R(){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=R();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(a)){let S=g[1];if(!S||H(S))continue;!!document.querySelector(`link[rel="stylesheet"][href="${S}"]`)||q.push(S)}}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 W="",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(C=>C.cssText).join("")}catch{}}if(!p&&(p=(await O(u.href,{as:"text",useProxy:r})).data,H(u.href)))continue;let S="";for(let m of p.match(f)||[]){let y=(m.match(/font-family:\s*([^;]+);/i)?.[1]||"").trim(),C=ht(y);if(!C||H(C))continue;let x=(m.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),A=(m.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),k=(m.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),N=(m.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),U=(m.match(/src\s*:\s*([^;]+);/i)?.[1]||"").trim(),$=w(U,u.href);if(!c(C,A,x,k))continue;let I=l(N);if(!d(e,I))continue;let B={family:C,weightSpec:x,styleSpec:A,stretchSpec:k,unicodeRange:N,srcRaw:U,srcUrls:$,href:u.href};if(n&&b(B,I))continue;let F=/url\(/i.test(U)?await E(m,u.href):m;S+=F+""}S.trim()&&(W+=S+"")}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 S=(g.style.getPropertyValue("font-family")||"").trim(),m=ht(S);if(!m||H(m))continue;let y=(g.style.getPropertyValue("font-weight")||"400").trim(),C=(g.style.getPropertyValue("font-style")||"normal").trim(),x=(g.style.getPropertyValue("font-stretch")||"100%").trim(),A=(g.style.getPropertyValue("src")||"").trim(),k=(g.style.getPropertyValue("unicode-range")||"").trim(),N=w(A,u.href||location.href);if(!c(m,C,y,x))continue;let U=l(k);if(!d(e,U))continue;let $={family:m,weightSpec:y,styleSpec:C,stretchSpec:x,unicodeRange:k,srcRaw:A,srcUrls:N,href:u.href||location.href};if(!(n&&b($,U)))if(/url\(/i.test(A)){let I=await E(A,u.href||location.href);W+=`@font-face{font-family:${m};src:${I};font-style:${C};font-weight:${y};font-stretch:${x};${k?`unicode-range:${k};`:""}}`}else W+=`@font-face{font-family:${m};src:${A};font-style:${C};font-weight:${y};font-stretch:${x};${k?`unicode-range:${k};`:""}}`}}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(S=>String(S).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 S=await O(u._snapdomSrc,{as:"dataURL",useProxy:r,silent:!0});if(S.ok&&typeof S.data=="string")g=S.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}}W+=`@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(x=>String(x).toLowerCase()===p.toLowerCase()))continue;let g=u.weight!=null?String(u.weight):"normal",S=u.style!=null?String(u.style):"normal",m=u.stretchPct!=null?`${u.stretchPct}%`:"100%",y=String(u.src||""),C=y;if(!C.startsWith("data:")){if(h.resource?.has(y))C=h.resource.get(y),h.font?.add(y);else if(!h.font?.has(y))try{let x=await O(y,{as:"dataURL",useProxy:r,silent:!0});if(x.ok&&typeof x.data=="string")C=x.data,h.resource?.set(y,C),h.font?.add(y);else continue}catch{console.warn("[snapdom] Failed to fetch localFonts src:",y);continue}}W+=`@font-face{font-family:'${p}';src:url(${C});font-style:${S};font-weight:${g};font-stretch:${m};}`}return W&&(W=L(W),h.resource?.set(T,W)),W}function gt(t){let e=new Set;if(!t)return e;let n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null),o=a=>{let s=ht(a.fontFamily);if(!s)return;let f=(c,l,d)=>`${s}__${mt(c)}__${Pt(l)}__${Ue(d)}`;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=1){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 $=getComputedStyle(t);if(!(s.color!==$.color||s.fontSize!==$.fontSize||s.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 F=B.textContent,et=F.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],Ct=F.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(s),ae=ot(re,"span");n.styleMap.set(z,ae);let Ut=document.createTextNode(Ct);e.replaceChild(Ut,B),e.insertBefore(z,Ut);continue}let c=s.content,l=/counter\s*\(|counters\s*\(/.test(c)?"- ":Lt(c),d=s.backgroundImage,w=s.backgroundColor,E=s.fontFamily,M=parseInt(s.fontSize)||32,v=parseInt(s.fontWeight)||!1,b=s.color||"#000",L=s.display,R=parseFloat(s.width),T=parseFloat(s.height),_=s.borderStyle,q=parseFloat(s.borderWidth),W=s.transform,D=H(E),u=c!=="none"&&l!=="",p=d&&d!=="none",g=w&&w!=="transparent"&&w!=="rgba(0, 0, 0, 0)",S=L!=="inline"&&(R>0||T>0),m=_&&_!=="none"&&q>0,y=W&&W!=="none";if(!(u||p||g||S||m||y))continue;let x=document.createElement("span");x.dataset.snapdomPseudo=a,x.style.verticalAlign="middle";let A=dt(s),k=ot(A,"span");if(n.styleMap.set(x,k),D&&l.length===1){let{dataUrl:$,width:I,height:B}=await Vt(l,E,v,M,b),F=document.createElement("img");F.src=$,F.style=`height:${M}px;width:${I/B*M}px;object-fit:contain;`,x.appendChild(F),e.dataset.snapdomHasIcon="true"}else if(l.startsWith("url(")){let $=K(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:${M}px;height:auto;object-fit:contain;`,x.appendChild(I)}catch(I){console.error(`[snapdom] Error in pseudo ${a} for`,t,I)}}else!D&&u&&(x.textContent=l);if(p)try{let $=Q(d),I=await Promise.all($.map(J));x.style.backgroundImage=I.join(", ")}catch($){console.warn(`[snapdom] Failed to inline background-image for ${a}`,$)}if(g&&(x.style.backgroundColor=w),!(x.childNodes.length>0||x.textContent?.trim()!==""||p||g||S||m||y))continue;a==="::before"?e.insertBefore(x,e.firstChild):e.appendChild(x)}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 Xt(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 d=i.querySelector("defs");d||(d=document.createElementNS("http://www.w3.org/2000/svg","defs"),i.appendChild(d)),d.appendChild(l.cloneNode(!0)),a.add(s);break}}})}async function Kt(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(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 Ge(o);try{let s=o.querySelectorAll("style[data-sd]");for(let f of s)i+=f.textContent||"",f.remove()}catch{}let a=Ft(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,d=s.dataset?.snapdomHasIcon;l&&l!=="none"&&(s.style.backgroundImage=l),d&&(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 w=document.createElement("div");for(w.style.transform=`translate(${-c}px, ${-l}px)`,w.style.willChange="transform",w.style.display="inline-block",w.style.width="100%";s.firstChild;)w.appendChild(s.firstChild);s.appendChild(w)}}if(t===n.nodeMap.get(o)){let s=n.styleCache.get(t)||window.getComputedStyle(t);n.styleCache.set(t,s);let f=$t(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 He(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(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 Gt(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 Ge(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=Ve(c),d=!1;for(let w of l)if(bt(w.url))try{w.url=await ct(w.url),d=!0}catch{}d&&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 Gt(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 Gt(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 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 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,d=parseInt(r.dataset?.snapdomHeight||"",10)||0,w=parseInt(r.getAttribute("width")||"",10)||0,E=parseInt(r.getAttribute("height")||"",10)||0,M=parseFloat(r.style?.width||"")||0,v=parseFloat(r.style?.height||"")||0,b=l||M||w||r.width||void 0,L=d||v||E||r.height||void 0,R=typeof s=="function"?await s({width:b,height:L,src:i,element:r}):s;if(R){let T=await O(R,{as:"dataURL",useProxy:e.useProxy});r.src=T.data,!r.width&&b&&(r.width=b),!r.height&&L&&(r.height=L),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-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source","border-image","border-image-source","border-image-slice","border-image-width","border-image-outset","border-image-repeat"];for(;r.length;){let[a,s]=r.shift(),f=n.get(a)||Z(a);n.has(a)||n.set(a,f);let c=(()=>{let w=f.getPropertyValue("border-image"),E=f.getPropertyValue("border-image-source");return w&&w!=="none"||E&&E!=="none"})();for(let w of i){if(["border-image-slice","border-image-width","border-image-outset","border-image-repeat"].includes(w)&&!c)continue;let E=f.getPropertyValue(w);if(!E||E==="none")continue;let M=Q(E),v=await Promise.all(M.map(b=>J(b,o)));v.some(b=>b&&b!=="none"&&!/^url\(undefined/.test(b))&&s.style.setProperty(w,v.join(", "))}let l=Array.from(a.children),d=Array.from(s.children);for(let w=0;w<Math.min(l.length,d.length);w++)r.push([l[w],d[w]])}}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,a="",s="",f,c;({clone:o,classCSS:r,styleCache:i}=await Kt(t,e)),await new Promise(E=>{V(async()=>{await Yt(o,e),E()},{fast:n})}),await new Promise(E=>{V(async()=>{await St(t,o,i,e),E()},{fast:n})}),e.embedFonts&&await new Promise(E=>{V(async()=>{let M=gt(t),v=yt(t);if(X){let b=new Set(Array.from(M).map(L=>String(L).split("__")[0]).filter(Boolean));await wt(b,2)}a=await pt({required:M,usedCodepoints:v,preCached:!1,exclude:e.excludeFonts,useProxy:e.useProxy}),E()},{fast:n})});let l=Mt(o).sort(),d=l.join(",");h.baseStyle.has(d)?s=h.baseStyle.get(d):await new Promise(E=>{V(()=>{s=vt(l),h.baseStyle.set(d,s),E()},{fast:n})}),await new Promise(E=>{V(()=>{let M=Ke(t),v=M.width,b=M.height,L=Number.isFinite(e.width),R=Number.isFinite(e.height),T=e.scale??1,_=typeof T=="number"&&T!==1;if(!_){let F=M.width/M.height;L&&R?(v=e.width,b=e.height):L?(v=e.width,b=v/F):R&&(b=e.height,v=b*F)}v=Math.max(1,Math.ceil(v)),b=Math.max(1,Math.ceil(b));let q=getComputedStyle(t),W=q.transform&&q.transform!=="none"?q.transform:"",D=Ze(t),u,p,g,S,m=0,y=0;if(Qe(t)){let F=nn({baseTransform:W,rotate:D.rotate||"0deg",scale:D.scale,translate:D.translate}),j=F.e??F.m41??0,et=F.f??F.m42??0;m=-j,y=-et;let Ct=F.is2D?Jt(F):Jt(new DOMMatrix(F.toString())),z=Je(v,b,Ct);u=Math.max(1,Math.ceil(z.width)),p=Math.max(1,Math.ceil(z.height)),g=-z.minX,S=-z.minY}else{let F=t.getBoundingClientRect(),j=tn(F,{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(F.left)),S=-(j.y-Math.floor(F.top))}let C="http://www.w3.org/2000/svg",x=document.createElementNS(C,"foreignObject");x.setAttribute("width","100%"),x.setAttribute("height","100%"),x.setAttribute("x",String(g)),x.setAttribute("y",String(S)),x.style.overflow="visible";let A=document.createElement("style");A.textContent=s+a+"svg{overflow:visible;} foreignObject{overflow:visible;}"+r,x.appendChild(A);let k=document.createElement("div");k.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),k.style.width=`${v}px`,k.style.height=`${b}px`,k.style.overflow="visible",k.style.transformOrigin="0 0";let N=[];if((m||y)&&N.push(`translate(${m}px, ${y}px)`),!_&&(L||R)){let F=M.width?v/M.width:1,j=M.height?b/M.height:1;N.push(`scale(${F}, ${j})`)}else _&&N.push(`scale(${T})`);N.length&&(k.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",W&&(o.style.transform=W),o.style.rotate=D.rotate||"0deg",o.style.scale=D.scale||"1",o.style.translate=D.translate||"0 0",k.appendChild(o),x.appendChild(k);let $=new XMLSerializer().serializeToString(x);c=`<svg xmlns="${C}" width="${u}" height="${p}" viewBox="0 0 ${u} ${p}">`+$+"</svg>",f=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(c)}`,E()},{fast:n})});let w=document.getElementById("snapdom-sandbox");return w&&w.style.position==="absolute"&&w.remove(),f}function Ke(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)),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 Ze(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 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 Wt=null;function en(){if(Wt)return Wt;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),Wt=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(t===!0)return"soft";if(t===!1)return"disabled";if(typeof t=="string"){let e=t.toLowerCase().trim();if(e==="disabled"||e==="full"||e==="auto"||e==="soft")return e}return"soft"}function 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 G(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 a=null;r&&(a=document.createElement("div"),a.setAttribute("aria-hidden","true"),a.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(a),a.appendChild(i)),await i.decode(),r&&await new Promise(d=>setTimeout(d,100));let s=i.naturalWidth*n,f=i.naturalHeight*n,c=document.createElement("canvas");c.width=Math.ceil(s*o),c.height=Math.ceil(f*o),c.style.width=`${s}px`,c.style.height=`${f}px`;let l=c.getContext("2d");if(o!==1&&l.scale(o,o),l.drawImage(i,0,0,s,f),a&&a.parentNode)try{a.parentNode.removeChild(a)}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 G(t,e),r=e.backgroundColor?Y(o,e.backgroundColor):o;return new Promise(i=>r.toBlob(a=>i(a),`image/${n}`,e.quality))}async function ee(t,e){let n=await G(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"}),a=URL.createObjectURL(i),s=document.createElement("a");s.href=a,s.download=e.filename,s.click(),URL.revokeObjectURL(a);return}let n=await G(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=a=>({...e,...a||{}}),i=a=>s=>ee(o,r({...s||{},format:a}));return{url:o,toRaw:()=>o,toImg:a=>te(o,r(a)),toCanvas:a=>G(o,r(a)),toBlob:a=>xt(o,r(a)),toPng:i("png"),toJpg:i("jpeg"),toWebp:i("webp"),download:a=>ne(o,r(a))}};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{}Et(),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=[],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?.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(()=>{});s.push(l)}}for(let f of a){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 w=Promise.resolve().then(()=>J(d,{...e,useProxy:r})).catch(()=>{});s.push(w)}}}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(s)}export{rn as preCache,P as snapdom};
|
|
4
|
+
`}catch{}}catch{}return e}function Ee(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 Me(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 ve(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 Fe(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 Le(t,e,n){let o=[];for(let r of e){let i=Fe(t,r);i&&o.push(`${r}: ${i};`)}return o.length?`${n}{${o.join("")}}
|
|
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 Oe(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 Be(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=Oe(g),A=Be(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,O=N(Pt($.s)),L=$.st>=S.min&&$.st<=S.max;if(I&&O&&L){W=!0;break}}if(W)return!0;if(!E)for(let $ of m){let I=N(Pt($.s)),O=$.st>=S.min&&$.st<=S.max;if(Math.abs(v-$.w)<=300&&I&&O)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 B(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),O=I.length?I.map(j=>String(j).toLowerCase()).sort().join("|"):$.toLowerCase(),L=[String(S||"").toLowerCase(),E,v,N,W.toLowerCase(),O].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 B(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 O={family:A,weightSpec:S,styleSpec:E,stretchSpec:v,unicodeRange:N,srcRaw:W,srcUrls:$,href:u.href};if(n&&w(O,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 B(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 B(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=1){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 O=Array.from(e.childNodes).find(Ot=>Ot.nodeType===Node.TEXT_NODE&&Ot.textContent?.trim().length>0);if(!O)continue;let L=O.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,O),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:O}=await Vt(l,R,k,C,w),L=document.createElement("img");L.src=$,L.style=`height:${C}px;width:${I/O*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"),O=await B(rt($),{as:"dataURL",useProxy:o.useProxy});I.src=O.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 B(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 B(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 B(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,2)}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(()=>B(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};
|
package/dist/snapdom.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
/*
|
|
3
3
|
* snapdom
|
|
4
|
-
* v.1.9.10
|
|
4
|
+
* v.1.9.10
|
|
5
5
|
* Author Juan Martin Muda
|
|
6
6
|
* License MIT
|
|
7
7
|
**/
|
|
@@ -2282,17 +2282,40 @@ async function inlineImages(clone, options = {}) {
|
|
|
2282
2282
|
// src/modules/background.js
|
|
2283
2283
|
async function inlineBackgroundImages(source, clone, styleCache, options = {}) {
|
|
2284
2284
|
const queue = [[source, clone]];
|
|
2285
|
-
const
|
|
2285
|
+
const URL_PROPS = [
|
|
2286
2286
|
"background-image",
|
|
2287
|
+
// Mask shorthands & images (both standard and WebKit)
|
|
2287
2288
|
"mask",
|
|
2288
2289
|
"mask-image",
|
|
2290
|
+
"-webkit-mask",
|
|
2289
2291
|
"-webkit-mask-image",
|
|
2292
|
+
// Mask sources (rare, but keep)
|
|
2290
2293
|
"mask-source",
|
|
2291
2294
|
"mask-box-image-source",
|
|
2292
2295
|
"mask-border-source",
|
|
2293
2296
|
"-webkit-mask-box-image-source",
|
|
2297
|
+
// Border image
|
|
2294
2298
|
"border-image",
|
|
2295
|
-
"border-image-source"
|
|
2299
|
+
"border-image-source"
|
|
2300
|
+
];
|
|
2301
|
+
const MASK_LAYOUT_PROPS = [
|
|
2302
|
+
"mask-position",
|
|
2303
|
+
"mask-size",
|
|
2304
|
+
"mask-repeat",
|
|
2305
|
+
// WebKit variants
|
|
2306
|
+
"-webkit-mask-position",
|
|
2307
|
+
"-webkit-mask-size",
|
|
2308
|
+
"-webkit-mask-repeat",
|
|
2309
|
+
// Extra (optional but helpful across engines)
|
|
2310
|
+
"mask-origin",
|
|
2311
|
+
"mask-clip",
|
|
2312
|
+
"-webkit-mask-origin",
|
|
2313
|
+
"-webkit-mask-clip",
|
|
2314
|
+
// Some engines expose X/Y position separately:
|
|
2315
|
+
"-webkit-mask-position-x",
|
|
2316
|
+
"-webkit-mask-position-y"
|
|
2317
|
+
];
|
|
2318
|
+
const BORDER_AUX_PROPS = [
|
|
2296
2319
|
"border-image-slice",
|
|
2297
2320
|
"border-image-width",
|
|
2298
2321
|
"border-image-outset",
|
|
@@ -2307,10 +2330,7 @@ async function inlineBackgroundImages(source, clone, styleCache, options = {}) {
|
|
|
2307
2330
|
const bis = style.getPropertyValue("border-image-source");
|
|
2308
2331
|
return bi && bi !== "none" || bis && bis !== "none";
|
|
2309
2332
|
})();
|
|
2310
|
-
for (const prop of
|
|
2311
|
-
if (["border-image-slice", "border-image-width", "border-image-outset", "border-image-repeat"].includes(prop) && !hasBorderImage) {
|
|
2312
|
-
continue;
|
|
2313
|
-
}
|
|
2333
|
+
for (const prop of URL_PROPS) {
|
|
2314
2334
|
const val = style.getPropertyValue(prop);
|
|
2315
2335
|
if (!val || val === "none") continue;
|
|
2316
2336
|
const splits = splitBackgroundImage(val);
|
|
@@ -2321,6 +2341,18 @@ async function inlineBackgroundImages(source, clone, styleCache, options = {}) {
|
|
|
2321
2341
|
cloneNode.style.setProperty(prop, inlined.join(", "));
|
|
2322
2342
|
}
|
|
2323
2343
|
}
|
|
2344
|
+
for (const prop of MASK_LAYOUT_PROPS) {
|
|
2345
|
+
const val = style.getPropertyValue(prop);
|
|
2346
|
+
if (!val || val === "initial") continue;
|
|
2347
|
+
cloneNode.style.setProperty(prop, val);
|
|
2348
|
+
}
|
|
2349
|
+
if (hasBorderImage) {
|
|
2350
|
+
for (const prop of BORDER_AUX_PROPS) {
|
|
2351
|
+
const val = style.getPropertyValue(prop);
|
|
2352
|
+
if (!val || val === "initial") continue;
|
|
2353
|
+
cloneNode.style.setProperty(prop, val);
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2324
2356
|
const sChildren = Array.from(srcNode.children);
|
|
2325
2357
|
const cChildren = Array.from(cloneNode.children);
|
|
2326
2358
|
for (let i = 0; i < Math.min(sChildren.length, cChildren.length); i++) {
|
|
@@ -2617,8 +2649,6 @@ function readTotalTransformMatrix(t) {
|
|
|
2617
2649
|
|
|
2618
2650
|
// src/core/context.js
|
|
2619
2651
|
function normalizeCachePolicy(v) {
|
|
2620
|
-
if (v === true) return "soft";
|
|
2621
|
-
if (v === false) return "disabled";
|
|
2622
2652
|
if (typeof v === "string") {
|
|
2623
2653
|
const s = v.toLowerCase().trim();
|
|
2624
2654
|
if (s === "disabled" || s === "full" || s === "auto" || s === "soft") return (
|
|
@@ -2776,21 +2806,25 @@ async function snapdom(element, userOptions) {
|
|
|
2776
2806
|
if (context.iconFonts && context.iconFonts.length > 0) extendIconFonts(context.iconFonts);
|
|
2777
2807
|
if (!context.snap) {
|
|
2778
2808
|
context.snap = {
|
|
2779
|
-
/** Delegates to this module’s PNG path (tu build devuelve <img>). */
|
|
2780
2809
|
toPng: (el, opts) => snapdom.toPng(el, opts),
|
|
2781
|
-
/** Útil si en algún flujo necesitás vector o <img> directo. */
|
|
2782
2810
|
toImg: (el, opts) => snapdom.toImg(el, opts)
|
|
2783
2811
|
};
|
|
2784
2812
|
}
|
|
2785
2813
|
return snapdom.capture(element, context, INTERNAL_TOKEN);
|
|
2786
2814
|
}
|
|
2787
2815
|
snapdom.capture = async (el, context, _token) => {
|
|
2788
|
-
if (_token !== INTERNAL_TOKEN)
|
|
2789
|
-
throw new Error("[snapdom.capture] is internal. Use snapdom(...) instead.");
|
|
2790
|
-
}
|
|
2816
|
+
if (_token !== INTERNAL_TOKEN) throw new Error("[snapdom.capture] is internal. Use snapdom(...) instead.");
|
|
2791
2817
|
const url = await captureDOM(el, context);
|
|
2792
2818
|
const ensureContext = (opts) => ({ ...context, ...opts || {} });
|
|
2793
|
-
const withFormat = (format) => (opts) =>
|
|
2819
|
+
const withFormat = (format) => (opts) => {
|
|
2820
|
+
const next = ensureContext({ ...opts || {}, format });
|
|
2821
|
+
const wantsJpeg = format === "jpeg" || format === "jpg";
|
|
2822
|
+
const noBg = next.backgroundColor == null || next.backgroundColor === "transparent";
|
|
2823
|
+
if (wantsJpeg && noBg) {
|
|
2824
|
+
next.backgroundColor = "#ffffff";
|
|
2825
|
+
}
|
|
2826
|
+
return rasterize(url, next);
|
|
2827
|
+
};
|
|
2794
2828
|
return {
|
|
2795
2829
|
url,
|
|
2796
2830
|
toRaw: () => url,
|
package/package.json
CHANGED