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