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