@zumer/snapdom 2.15.0-dev.0 → 2.15.0-dev.1

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 CHANGED
@@ -944,12 +944,12 @@ For detailed guidelines, see [CONTRIBUTING](https://github.com/zumerlab/snapdom/
944
944
  <p>
945
945
  <a href="https://github.com/tinchox5" title="tinchox5"><img src="https://avatars.githubusercontent.com/u/11557901?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="tinchox5"/></a>
946
946
  <a href="https://github.com/pdufour" title="pdufour"><img src="https://avatars.githubusercontent.com/u/1239145?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="pdufour"/></a>
947
+ <a href="https://github.com/FlavioLimaMindera" title="FlavioLimaMindera"><img src="https://avatars.githubusercontent.com/u/96424442?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="FlavioLimaMindera"/></a>
947
948
  <a href="https://github.com/Jarvis2018" title="Jarvis2018"><img src="https://avatars.githubusercontent.com/u/36788851?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="Jarvis2018"/></a>
948
949
  <a href="https://github.com/tarwin" title="tarwin"><img src="https://avatars.githubusercontent.com/u/646149?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="tarwin"/></a>
949
950
  <a href="https://github.com/Amyuan23" title="Amyuan23"><img src="https://avatars.githubusercontent.com/u/25892910?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="Amyuan23"/></a>
950
951
  <a href="https://github.com/kohaiy" title="kohaiy"><img src="https://avatars.githubusercontent.com/u/15622127?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="kohaiy"/></a>
951
952
  <a href="https://github.com/airamhr9" title="airamhr9"><img src="https://avatars.githubusercontent.com/u/57371081?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="airamhr9"/></a>
952
- <a href="https://github.com/FlavioLimaMindera" title="FlavioLimaMindera"><img src="https://avatars.githubusercontent.com/u/96424442?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="FlavioLimaMindera"/></a>
953
953
  <a href="https://github.com/jswhisperer" title="jswhisperer"><img src="https://avatars.githubusercontent.com/u/1177690?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="jswhisperer"/></a>
954
954
  <a href="https://github.com/K1ender" title="K1ender"><img src="https://avatars.githubusercontent.com/u/146767945?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="K1ender"/></a>
955
955
  <a href="https://github.com/17biubiu" title="17biubiu"><img src="https://avatars.githubusercontent.com/u/13295895?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="17biubiu"/></a>
package/dist/plugins.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * SnapDOM
3
- * v2.15.0-dev.0
3
+ * v2.15.0-dev.1
4
4
  * Author: Juan Martin Muda
5
5
  * License: MIT
6
6
  */
package/dist/preCache.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  /*
2
2
  * SnapDOM
3
- * v2.15.0-dev.0
3
+ * v2.15.0-dev.1
4
4
  * Author: Juan Martin Muda
5
5
  * License: MIT
6
6
  */
7
- var $=class extends Map{constructor(e=100,...n){super(...n),this._maxSize=e}set(e,n){if(this.size>=this._maxSize&&!this.has(e)){let o=this.keys().next().value;o!==void 0&&this.delete(o)}return super.set(e,n)}},m={image:new $(100),background:new $(100),resource:new $(150),defaultStyle:new $(30),baseStyle:new $(50),computedStyle:new WeakMap,measureHints:new WeakMap,font:new Set,session:{styleMap:new Map,styleCache:new WeakMap,nodeMap:new Map}};function tt(t="soft"){switch(m.session.__counterEpoch=(m.session.__counterEpoch||0)+1,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.measureHints=new WeakMap,m.baseStyle=new $(50),m.defaultStyle=new $(30),m.image=new $(100),m.background=new $(100),m.resource=new $(150),m.font=new Set;return}default:{m.session.styleMap=new Map,m.session.nodeMap=new Map,m.session.styleCache=new WeakMap;return}}}function q(t){let e=t.match(/url\((['"]?)(.*?)(\1)\)/);if(!e)return null;let n=e[2].trim();return n.startsWith("#")?null:n}function P(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function et(t,e){if(!t||/^(data|blob|about|#)/i.test(t.trim()))return t;try{let n=e||typeof document<"u"&&(document.baseURI||document.location?.href)||"http://localhost/";return new URL(t,n).href}catch{return t}}function Ct(t="[snapDOM]",{ttlMs:e=5*6e4,maxEntries:n=12}={}){let o=new Map,s=0;function a(r,l,i){if(s>=n)return;let u=Date.now();(o.get(l)||0)>u||(o.set(l,u+e),s++,r==="warn"&&console&&console.warn?console.warn(`${t} ${i}`):console&&console.error&&console.error(`${t} ${i}`))}return{warnOnce(r,l){a("warn",r,l)},errorOnce(r,l){a("error",r,l)},reset(){o.clear(),s=0}}}var nt=Ct("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),K=new Map,V=new Map;function xt(t){return/^data:|^blob:|^about:blank$/i.test(t)}function kt(t,e){try{let n=typeof location<"u"&&location.href?location.href:"http://localhost/",o=e.includes("{url}")?e.split("{url}")[0]:e,s=new URL(o||".",n),a=new URL(t,n);if(a.origin===s.origin)return!0;let r=a.searchParams;if(r&&(r.has("url")||r.has("target")))return!0}catch{}return!1}function At(t,e){if(!e||xt(t)||kt(t,e))return!1;try{let n=typeof location<"u"&&location.href?location.href:"http://localhost/",o=new URL(t,n);return typeof location<"u"?o.origin!==location.origin:!0}catch{return!!e}}function Rt(t,e){if(!e)return t;if(e.includes("{url}"))return e.replace("{urlRaw}",P(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}${P(t)}`;let n=e.includes("?")?"&":"?";return`${e}${n}url=${encodeURIComponent(t)}`}function ot(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 $t(t,e){return[e.as||"blob",e.timeout??3e3,e.useProxy||"",e.errorTTL??8e3,t].join("|")}async function E(t,e={}){let n=e.as??"blob",o=e.timeout??3e3,s=e.useProxy||"",a=e.errorTTL??8e3,r=e.headers||{},l=!!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[,g="",c=""]=String(t).match(/^data:([^,]*),(.*)$/)||[],d=/;base64/i.test(g)?atob(c):decodeURIComponent(c),C=new Uint8Array([...d].map(y=>y.charCodeAt(0))),w=new Blob([C],{type:(g||"").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 g=await fetch(t);if(!g.ok)return{ok:!1,data:null,status:g.status,url:t,fromCache:!1,reason:"http_error"};let c=await g.blob(),f=c.type||g.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await ot(c),status:g.status,url:t,fromCache:!1,mime:f}:n==="text"?{ok:!0,data:await c.text(),status:g.status,url:t,fromCache:!1,mime:f}:{ok:!0,data:c,status:g.status,url:t,fromCache:!1,mime:f}}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 i=$t(t,{as:n,timeout:o,useProxy:s,errorTTL:a}),u=V.get(i);if(u&&u.until>Date.now())return{...u.result,fromCache:!0};u&&V.delete(i);let p=K.get(i);if(p)return p;let h=At(t,s)?Rt(t,s):t,S=e.credentials;if(!S)try{let g=typeof location<"u"&&location.href?location.href:"http://localhost/",c=new URL(t,g);S=typeof location<"u"&&c.origin===location.origin?"include":"omit"}catch{S="omit"}let k=new AbortController,b=setTimeout(()=>k.abort("timeout"),o),A=(async()=>{try{let g=await fetch(h,{signal:k.signal,credentials:S,headers:r});if(!g.ok){let d={ok:!1,data:null,status:g.status,url:h,fromCache:!1,reason:"http_error"};if(a>0&&V.set(i,{until:Date.now()+a,result:d}),!l){let C=`${g.status} ${g.statusText||""}`.trim();nt.warnOnce(`http:${g.status}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,`HTTP error ${C} while fetching ${n} ${t}`)}return e.onError&&e.onError(d),d}if(n==="text")return{ok:!0,data:await g.text(),status:g.status,url:h,fromCache:!1};let c=await g.blob(),f=c.type||g.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await ot(c),status:g.status,url:h,fromCache:!1,mime:f}:{ok:!0,data:c,status:g.status,url:h,fromCache:!1,mime:f}}catch(g){let c=g&&typeof g=="object"&&"name"in g&&g.name==="AbortError"?String(g.message||"").includes("timeout")?"timeout":"abort":"network",f={ok:!1,data:null,status:0,url:h,fromCache:!1,reason:c};if(!/^blob:/i.test(t)&&a>0&&V.set(i,{until:Date.now()+a,result:f}),!l){let d=`${c}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,C=c==="timeout"?`Timeout after ${o}ms. Consider increasing timeout or using a proxy for ${t}`:c==="abort"?`Request aborted while fetching ${n} ${t}`:`Network/CORS issue while fetching ${n} ${t}. A proxy may be required`;nt.errorOnce(d,C)}return e.onError&&e.onError(f),f}finally{clearTimeout(b),K.delete(i)}})();return K.set(i,A),A}async function v(t,e={}){if(/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t)||t.trim()==="none")return t;let o=q(t);if(!o)return t;let s=et(o),a=P(s),r=(e.useProxy||"")+"|"+a;if(m.background.has(r)){let l=m.background.get(r);return l?`url("${l}")`:"none"}try{let l=await E(a,{as:"dataURL",useProxy:e.useProxy});return l.ok?(m.background.set(r,l.data),`url("${l.data}")`):(m.background.set(r,null),"none")}catch{return m.background.set(r,null),"none"}}var st=new Set(["meta","script","noscript","title","link","template"]),H=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"]),Lt=["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 Y(){for(let t of Lt){let e=String(t).toLowerCase();st.has(e)||H.has(e)||at(e)}}function at(t){if(t=String(t).toLowerCase(),H.has(t)){let a={};return m.defaultStyle.set(t,a),a}if(m.defaultStyle.has(t))return m.defaultStyle.get(t);let e=document.getElementById("snapdom-sandbox");e||(e=document.createElement("div"),e.id="snapdom-sandbox",e.setAttribute("data-snapdom-sandbox","true"),e.setAttribute("aria-hidden","true"),e.style.position="absolute",e.style.left="-9999px",e.style.top="-9999px",e.style.width="0px",e.style.height="0px",e.style.overflow="hidden",document.body.appendChild(e));let n=document.createElement(t);n.style.all="initial",e.appendChild(n);let o=getComputedStyle(n),s={};for(let a of o){if(it(a))continue;let r=o.getPropertyValue(a);s[a]=r}return e.removeChild(n),m.defaultStyle.set(t,s),s}var Mt=/(?:^|-)(animation|transition)(?:-|$)/i,Et=/^(--.+|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,_t=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","zoom"]),rt=new Map;function it(t){let e=rt.get(t);if(e===void 0){let n=String(t).toLowerCase();e=_t.has(n)||Et.test(n)||Mt.test(n),rt.set(t,e)}return e}function Ft(t){try{let e=t?.ownerDocument;if(!e)return typeof window<"u"?window:null;let n=e.defaultView;if(n&&typeof n.getComputedStyle=="function")return n;if(typeof window<"u"&&window.frames)for(let o=0;o<window.frames.length;o++)try{if(window.frames[o]?.document===e)return window.frames[o]}catch{}}catch{}return typeof window<"u"?window:null}function N(t,e=null){let n=()=>{let a={length:0,getPropertyValue:()=>"",item:()=>""};return a[Symbol.iterator]=function*(){},a};if(!(t instanceof Element)){let a=typeof window<"u"?window:null;if(a&&typeof a.getComputedStyle=="function")try{return a.getComputedStyle(t,e)||n()}catch{return n()}return n()}let o=m.computedStyle.get(t);o||(o=new Map,m.computedStyle.set(t,o));let s=o.get(e);if(!s){let a=Ft(t),r=null;try{r=a&&typeof a.getComputedStyle=="function"?a.getComputedStyle(t,e):null}catch{}if(!r&&typeof window<"u"&&typeof window.getComputedStyle=="function")try{t.ownerDocument===document&&(r=window.getComputedStyle(t,e))}catch{}s=r||n(),o.set(e,s)}return s}function j(t){let e=[],n=0,o=0;for(let s=0;s<t.length;s++){let a=t[s];a==="("&&n++,a===")"&&n--,a===","&&n===0&&(e.push(t.slice(o,s).trim()),o=s+1)}return e.push(t.slice(o).trim()),e}function D(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||"",e=t.toLowerCase(),n=e.includes("safari")&&!e.includes("chrome")&&!e.includes("crios")&&!e.includes("fxios")&&!e.includes("android"),o=/applewebkit/i.test(t),s=/mobile/i.test(t),a=!/safari/i.test(t),r=o&&s&&a,l=/(micromessenger|wxwork|wecom|windowswechat|macwechat)/i.test(t),i=/(baiduboxapp|baidubrowser|baidusearch|baiduboxlite)/i.test(e),u=/ipad|iphone|ipod/.test(e)&&o;return n||r||l||i||u}var Ut=[/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],we=Object.assign({materialIconsFilled:"https://fonts.gstatic.com/s/materialicons/v48/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2",materialIconsOutlined:"https://fonts.gstatic.com/s/materialiconsoutlined/v110/gok-H7zzDkdnRel8-DQ6KAXJ69wP1tGnf4ZGhUcel5euIg.woff2",materialIconsRound:"https://fonts.gstatic.com/s/materialiconsround/v109/LDItaoyNOAY6Uewc665JcIzCKsKc_M9flwmPq_HTTw.woff2",materialIconsSharp:"https://fonts.gstatic.com/s/materialiconssharp/v110/oPWQ_lt5nv4pWNJpghLP75WiFR4kLh3kvmvRImcycg.woff2"},typeof window<"u"&&window.__SNAPDOM_ICON_FONTS__||{}),It=[];function F(t){let e=typeof t=="string"?t:"",n=[...Ut,...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))}var ft=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]),Tt=["katex","mathjax","mathml"];function J(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!ft.has(n.toLowerCase()))return n}return""}function Ot(t){if(!t)return[];let e=[];for(let n of t.split(",")){let o=n.trim().replace(/^['"]+|['"]+$/g,"");o&&(ft.has(o.toLowerCase())||e.push(o))}return e}function z(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 G(t){let e=String(t??"normal").trim().toLowerCase();return e.startsWith("italic")?"italic":e.startsWith("oblique")?"oblique":"normal"}function Pt(t){let e=String(t??"100%").match(/(\d+(?:\.\d+)?)\s*%/);return e?Math.max(50,Math.min(200,parseFloat(e[1]))):100}function vt(t){let e=String(t||"400").trim(),n=e.match(/^(\d{2,3})\s+(\d{2,3})$/);if(n){let s=z(n[1]),a=z(n[2]);return{min:Math.min(s,a),max:Math.max(s,a)}}let o=z(e);return{min:o,max:o}}function Nt(t){let e=String(t||"normal").trim().toLowerCase();return e==="italic"?{kind:"italic"}:e.startsWith("oblique")?{kind:"oblique"}:{kind:"normal"}}function Dt(t){let e=String(t||"100%").trim(),n=e.match(/(\d+(?:\.\d+)?)\s*%\s+(\d+(?:\.\d+)?)\s*%/);if(n){let a=parseFloat(n[1]),r=parseFloat(n[2]);return{min:Math.min(a,r),max:Math.max(a,r)}}let o=e.match(/(\d+(?:\.\d+)?)\s*%/),s=o?parseFloat(o[1]):100;return{min:s,max:s}}function Wt(t){return!t||typeof t!="string"?"":t.replace(/\s+(variable|vf|v[0-9]+)$/i,"").trim().toLowerCase().replace(/\s+/g,"-")}function Bt(t,e,n=[]){if(!t)return!1;try{let o=new URL(t,location.href);if(o.origin===location.origin)return!0;let a=o.host.toLowerCase();if(["fonts.googleapis.com","fonts.gstatic.com","use.typekit.net","p.typekit.net","kit.fontawesome.com","use.fontawesome.com","cdn.jsdelivr.net","unpkg.com","cdnjs.cloudflare.com","esm.sh"].some(i=>a.endsWith(i))||n.some(i=>a===i.toLowerCase()||a.endsWith("."+i.toLowerCase())))return!0;let l=(o.pathname+o.search).toLowerCase();if(/\bfont(s)?\b/.test(l)||/\.woff2?(\b|$)/.test(l)||Tt.some(i=>l.includes(i)))return!0;for(let i of e){let u=i.toLowerCase().replace(/\s+/g,"+"),p=i.toLowerCase().replace(/\s+/g,"-"),h=Wt(i);if(l.includes(u)||l.includes(p)||h&&l.includes(h))return!0}return!1}catch{return!1}}function qt(t){let e=new Set;for(let n of t||[]){let o=String(n).split("__")[0]?.trim();o&&e.add(o)}return e}function ct(t,e){return t&&t.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/g,(n,o,s)=>{let a=(s||"").trim();if(!a||/^data:|^blob:|^https?:|^file:|^about:/i.test(a))return n;let r=a;try{r=new URL(a,e||location.href).href}catch{}return`url("${r}")`})}var Q=/@import\s+(?:url\(\s*(['"]?)([^)"']+)\1\s*\)|(['"])([^"']+)\3)([^;]*);/g,X=4;async function Vt(t,e,n){if(!t)return t;let o=new Set;function s(l,i){try{return new URL(l,i||location.href).href}catch{return l}}async function a(l,i,u=0){if(u>X)return console.warn(`[snapDOM] @import depth exceeded (${X}) at ${i}`),l;let p="",h=0,S;for(;S=Q.exec(l);){p+=l.slice(h,S.index),h=Q.lastIndex;let k=(S[2]||S[4]||"").trim(),b=s(k,i);if(o.has(b)){console.warn(`[snapDOM] Skipping circular @import: ${b}`);continue}o.add(b);let A="";try{let g=await E(b,{as:"text",useProxy:n,silent:!0});g.ok&&typeof g.data=="string"&&(A=g.data)}catch{}A?(A=ct(A,b),A=await a(A,b,u+1),p+=`
8
- /* inlined: ${b} */
9
- ${A}
10
- `):p+=S[0]}return p+=l.slice(h),p}let r=ct(t,e||location.href);return r=await a(r,e||location.href,0),r}var ut=/url\((["']?)([^"')]+)\1\)/g,jt=/@font-face[^{}]*\{[^}]*\}/g;function mt(t){if(!t)return[];let e=[],n=t.split(",").map(o=>o.trim()).filter(Boolean);for(let o of n){let s=o.match(/^U\+([0-9A-Fa-f?]+)(?:-([0-9A-Fa-f?]+))?$/);if(!s)continue;let a=s[1],r=s[2],l=i=>{if(!i.includes("?"))return parseInt(i,16);let u=parseInt(i.replace(/\?/g,"0"),16),p=parseInt(i.replace(/\?/g,"F"),16);return[u,p]};if(r){let i=l(a),u=l(r),p=Array.isArray(i)?i[0]:i,h=Array.isArray(u)?u[1]:u;e.push([Math.min(p,h),Math.max(p,h)])}else{let i=l(a);Array.isArray(i)?e.push([i[0],i[1]]):e.push([i,i])}}return e}function dt(t,e){if(!e.length||!t||t.size===0)return!0;for(let n of t)for(let[o,s]of e)if(n>=o&&n<=s)return!0;return!1}function Z(t,e){let n=[];if(!t)return n;for(let o of t.matchAll(ut)){let s=(o[2]||"").trim();if(!(!s||s.startsWith("data:"))){if(!/^https?:/i.test(s))try{s=new URL(s,e||location.href).href}catch{}n.push(s)}}return n}async function pt(t,e,n=""){let o=t;for(let s of t.matchAll(ut)){let a=q(s[0]);if(!a)continue;let r=a;if(!r.startsWith("http")&&!r.startsWith("data:"))try{r=new URL(r,e||location.href).href}catch{}if(!F(r)){if(m.resource?.has(r)){m.font?.add(r),o=o.replace(s[0],`url(${m.resource.get(r)})`);continue}try{let l=await E(r,{as:"dataURL",useProxy:n,silent:!0});if(l.ok&&typeof l.data=="string"){let i=l.data;m.resource?.set(r,i),m.font?.add(r),o=o.replace(s[0],`url(${i})`)}}catch{console.warn("[snapDOM] Failed to fetch font resource:",r)}}}return o}function zt(t){if(!t.length)return null;let e=(l,i)=>t.some(([u,p])=>!(p<l||u>i)),n=e(0,255)||e(305,305),o=e(256,591)||e(7680,7935),s=e(880,1023),a=e(1024,1279);return e(7840,7929)||e(258,259)||e(416,417)||e(431,432)?"vietnamese":a?"cyrillic":s?"greek":o?"latin-ext":n?"latin":null}function lt(t={}){let e=new Set((t.families||[]).map(s=>String(s).toLowerCase())),n=new Set((t.domains||[]).map(s=>String(s).toLowerCase())),o=new Set((t.subsets||[]).map(s=>String(s).toLowerCase()));return(s,a)=>{if(e.size&&e.has(s.family.toLowerCase()))return!0;if(n.size)for(let r of s.srcUrls)try{if(n.has(new URL(r).host.toLowerCase()))return!0}catch{}if(o.size){let r=zt(a);if(r&&o.has(r))return!0}return!1}}function Gt(t){if(!t)return t;let e=/@font-face[^{}]*\{[^}]*\}/gi,n=new Set,o=[];for(let a of t.match(e)||[]){let r=a.match(/font-family:\s*([^;]+);/i)?.[1]||"",l=J(r),i=(a.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),u=(a.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),p=(a.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),h=(a.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),S=(a.match(/src\s*:\s*([^;}]+)[;}]/i)?.[1]||"").trim(),k=Z(S,location.href),b=k.length?k.map(g=>String(g).toLowerCase()).sort().join("|"):S.toLowerCase(),A=[String(l||"").toLowerCase(),i,u,p,h.toLowerCase(),b].join("|");n.has(A)||(n.add(A),o.push(a))}if(o.length===0)return t;let s=0;return t.replace(e,()=>o[s++]||"")}function Xt(t,e,n,o,s){let a=Array.from(t||[]).sort().join("|"),r=e?JSON.stringify({families:(e.families||[]).map(p=>String(p).toLowerCase()).sort(),domains:(e.domains||[]).map(p=>String(p).toLowerCase()).sort(),subsets:(e.subsets||[]).map(p=>String(p).toLowerCase()).sort()}):"",l=(n||[]).map(p=>`${(p.family||"").toLowerCase()}::${p.weight||"normal"}::${p.style||"normal"}::${p.src||""}`).sort().join("|"),i=o||"",u=(s||[]).map(p=>String(p).toLowerCase()).sort().join("|");return`fonts-embed-css::req=${a}::ex=${r}::lf=${l}::px=${i}::fd=${u}`}async function ht(t,e,n,o){let s;try{s=t.cssRules||[]}catch{return}let a=(r,l)=>{try{return new URL(r,l||location.href).href}catch{return r}};for(let r of s){if(r.type===CSSRule.IMPORT_RULE&&r.styleSheet){let l=r.href?a(r.href,e):e;if(o.depth>=X){console.warn(`[snapDOM] CSSOM import depth exceeded (${X}) at ${l}`);continue}if(l&&o.visitedSheets.has(l)){console.warn(`[snapDOM] Skipping circular CSSOM import: ${l}`);continue}l&&o.visitedSheets.add(l);let i={...o,depth:(o.depth||0)+1};await ht(r.styleSheet,l,n,i);continue}if(r.type===CSSRule.FONT_FACE_RULE){let l=(r.style.getPropertyValue("font-family")||"").trim(),i=J(l);if(!i||F(i))continue;let u=(r.style.getPropertyValue("font-weight")||"400").trim(),p=(r.style.getPropertyValue("font-style")||"normal").trim(),h=(r.style.getPropertyValue("font-stretch")||"100%").trim(),S=(r.style.getPropertyValue("src")||"").trim(),k=(r.style.getPropertyValue("unicode-range")||"").trim();if(!o.faceMatchesRequired(i,p,u,h))continue;let b=mt(k);if(!dt(o.usedCodepoints,b))continue;let A={family:i,weightSpec:u,styleSpec:p,stretchSpec:h,unicodeRange:k,srcRaw:S,srcUrls:Z(S,e||location.href),href:e||location.href};if(o.simpleExcluder&&o.simpleExcluder(A,b))continue;if(/url\(/i.test(S)){let g=await pt(S,e||location.href,o.useProxy);await n(`@font-face{font-family:${i};src:${g};font-style:${p};font-weight:${u};font-stretch:${h};${k?`unicode-range:${k};`:""}}`)}else await n(`@font-face{font-family:${i};src:${S};font-style:${p};font-weight:${u};font-stretch:${h};${k?`unicode-range:${k};`:""}}`)}}}async function gt({required:t,usedCodepoints:e,exclude:n=void 0,localFonts:o=[],useProxy:s="",fontStylesheetDomains:a=[]}={}){t instanceof Set||(t=new Set),e instanceof Set||(e=new Set);let r=new Map;for(let c of t){let[f,d,C,w]=String(c).split("__");if(!f)continue;let y=f.toLowerCase(),x=r.get(y)||[];x.push({w:parseInt(d,10),s:C,st:parseInt(w,10)}),r.set(y,x)}function l(c,f,d,C){let w=String(c).toLowerCase();if(!r.has(w))return!1;let y=r.get(w),x=vt(d),L=Nt(f),_=Dt(C),I=x.min!==x.max,T=x.min,O=R=>L.kind==="normal"&&R==="normal"||L.kind!=="normal"&&(R==="italic"||R==="oblique"),W=!1;for(let R of y){let M=I?R.w>=x.min&&R.w<=x.max:R.w===T,U=O(G(R.s)),B=R.st>=_.min&&R.st<=_.max;if(M&&U&&B){W=!0;break}}if(W)return!0;if(!I)for(let R of y){let M=O(G(R.s)),U=R.st>=_.min&&R.st<=_.max;if(Math.abs(T-R.w)<=300&&M&&U)return!0}if(!I&&L.kind==="normal"&&y.some(M=>G(M.s)!=="normal"))for(let M of y){let U=Math.abs(T-M.w)<=300,B=M.st>=_.min&&M.st<=_.max;if(U&&B)return!0}return!1}let i=lt(n),u=Xt(t,n,o,s,a);if(m.resource?.has(u))return m.resource.get(u);let p=qt(t),h=[],S=Q;for(let c of document.querySelectorAll("style")){let f=c.textContent||"";for(let d of f.matchAll(S)){let C=(d[2]||d[4]||"").trim();if(!C||F(C))continue;document.querySelector(`link[rel="stylesheet"][href="${C}"]`)||h.push(C)}}let k=[];h.length&&await Promise.all(h.map(c=>new Promise(f=>{if(document.querySelector(`link[rel="stylesheet"][href="${c}"]`))return f(null);let d=document.createElement("link");d.rel="stylesheet",d.href=c,d.setAttribute("data-snapdom","injected-import"),d.onload=()=>f(d),d.onerror=()=>f(null),document.head.appendChild(d),k.push(d)})));let b="",A=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(c=>!!c.href);for(let c of k)try{c.remove()}catch{}for(let c of A)try{if(F(c.href))continue;let f="",d=!1;try{d=new URL(c.href,location.href).origin===location.origin}catch{}if(!d){let w=Array.isArray(a)?a:[];if(!Bt(c.href,p,w))continue}if(d){let w=Array.from(document.styleSheets).find(y=>y.href===c.href);if(w)try{let y=w.cssRules||[];f=Array.from(y).map(x=>x.cssText).join("")}catch{}}if(!f){let w=await E(c.href,{as:"text",useProxy:s});if(w?.ok&&typeof w.data=="string"&&(f=w.data),F(c.href))continue}f=await Vt(f,c.href,s);let C="";for(let w of f.match(jt)||[]){let y=(w.match(/font-family:\s*([^;]+);/i)?.[1]||"").trim(),x=J(y);if(!x||F(x))continue;let L=(w.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),_=(w.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),I=(w.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),T=(w.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),O=(w.match(/src\s*:\s*([^;}]+)[;}]/i)?.[1]||"").trim(),W=Z(O,c.href);if(!l(x,_,L,I))continue;let R=mt(T);if(!dt(e,R))continue;let M={family:x,weightSpec:L,styleSpec:_,stretchSpec:I,unicodeRange:T,srcRaw:O,srcUrls:W,href:c.href};if(n&&i(M,R))continue;let U=/url\(/i.test(O)?await pt(w,c.href,s):w;C+=U}C.trim()&&(b+=C)}catch{console.warn("[snapDOM] Failed to process stylesheet:",c.href)}let g={requiredIndex:r,usedCodepoints:e,faceMatchesRequired:l,simpleExcluder:n?lt(n):null,useProxy:s,visitedSheets:new Set,depth:0};for(let c of document.styleSheets)if(!(c.href&&A.some(f=>f.href===c.href)))try{let f=c.href||location.origin+"/";f&&g.visitedSheets.add(f),await ht(c,f,async d=>{b+=d},g)}catch{}try{for(let c of document.fonts||[]){if(!c||!c.family||c.status!=="loaded"||!c._snapdomSrc)continue;let f=String(c.family).replace(/^['"]+|['"]+$/g,"");if(F(f)||!r.has(f.toLowerCase())||n?.families&&n.families.some(C=>String(C).toLowerCase()===f.toLowerCase()))continue;let d=c._snapdomSrc;if(!String(d).startsWith("data:")){if(m.resource?.has(c._snapdomSrc))d=m.resource.get(c._snapdomSrc),m.font?.add(c._snapdomSrc);else if(!m.font?.has(c._snapdomSrc))try{let C=await E(c._snapdomSrc,{as:"dataURL",useProxy:s,silent:!0});if(C.ok&&typeof C.data=="string")d=C.data,m.resource?.set(c._snapdomSrc,d),m.font?.add(c._snapdomSrc);else continue}catch{console.warn("[snapDOM] Failed to fetch dynamic font src:",c._snapdomSrc);continue}}b+=`@font-face{font-family:'${f}';src:url(${d});font-style:${c.style||"normal"};font-weight:${c.weight||"normal"};}`}}catch{}for(let c of o){if(!c||typeof c!="object")continue;let f=String(c.family||"").replace(/^['"]+|['"]+$/g,"");if(!f||F(f)||!r.has(f.toLowerCase())||n?.families&&n.families.some(L=>String(L).toLowerCase()===f.toLowerCase()))continue;let d=c.weight!=null?String(c.weight):"normal",C=c.style!=null?String(c.style):"normal",w=c.stretchPct!=null?`${c.stretchPct}%`:"100%",y=String(c.src||""),x=y;if(!x.startsWith("data:")){if(m.resource?.has(y))x=m.resource.get(y),m.font?.add(y);else if(!m.font?.has(y))try{let L=await E(y,{as:"dataURL",useProxy:s,silent:!0});if(L.ok&&typeof L.data=="string")x=L.data,m.resource?.set(y,x),m.font?.add(y);else continue}catch{console.warn("[snapDOM] Failed to fetch localFonts src:",y);continue}}b+=`@font-face{font-family:'${f}';src:url(${x});font-style:${C};font-weight:${d};font-stretch:${w};}`}return b&&(b=Gt(b),m.resource?.set(u,b)),b}function yt(t){let e=new Set;if(!t)return e;let n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null),o=r=>{let l=Ot(r.fontFamily);if(l.length)for(let i of l){let u=(p,h,S)=>`${i}__${z(p)}__${G(h)}__${Pt(S)}`;e.add(u(r.fontWeight,r.fontStyle,r.fontStretch))}};o(getComputedStyle(t));let s=getComputedStyle(t,"::before");s&&s.content&&s.content!=="none"&&o(s);let a=getComputedStyle(t,"::after");for(a&&a.content&&a.content!=="none"&&o(a);n.nextNode();){let r=n.currentNode,l=getComputedStyle(r);o(l);let i=getComputedStyle(r,"::before");i&&i.content&&i.content!=="none"&&o(i);let u=getComputedStyle(r,"::after");u&&u.content&&u.content!=="none"&&o(u)}return e}function wt(t){let e=new Set,n=s=>{if(s)for(let a of s)e.add(a.codePointAt(0))},o=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,null);for(;o.nextNode();){let s=o.currentNode;if(s.nodeType===Node.TEXT_NODE)n(s.nodeValue||"");else if(s.nodeType===Node.ELEMENT_NODE){let a=s;for(let r of["::before","::after"]){let i=getComputedStyle(a,r)?.getPropertyValue("content");if(!(!i||i==="none"))if(/^"/.test(i)||/^'/.test(i))n(i.slice(1,-1));else{let u=i.match(/\\[0-9A-Fa-f]{1,6}/g);if(u)for(let p of u)try{e.add(parseInt(p.slice(1),16))}catch{}}}}}return e}async function St(t,e=2){try{await document.fonts.ready}catch{}let n=Array.from(t||[]).filter(Boolean);if(n.length===0)return;let o=()=>{let s=document.createElement("div");s.style.cssText="position:absolute!important;left:-9999px!important;top:0!important;opacity:0!important;pointer-events:none!important;contain:layout size style;";for(let a of n){let r=document.createElement("span");r.textContent="AaBbGg1234\xC1\xC9\xCD\xD3\xDA\xE7\xF1\u2014\u221E",r.style.fontFamily=`"${a}"`,r.style.fontWeight="700",r.style.fontStyle="italic",r.style.fontSize="32px",r.style.lineHeight="1",r.style.whiteSpace="nowrap",r.style.margin="0",r.style.padding="0",s.appendChild(r)}document.body.appendChild(s),s.offsetWidth,document.body.removeChild(s)};for(let s=0;s<Math.max(1,e);s++)o(),await new Promise(a=>requestAnimationFrame(()=>requestAnimationFrame(a)))}async function bt(t,e,n,o={}){let s=[[t,e]],a=["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"],r=["mask-position","mask-size","mask-repeat","mask-mode","mask-composite","-webkit-mask-position","-webkit-mask-size","-webkit-mask-repeat","-webkit-mask-composite","mask-origin","mask-clip","-webkit-mask-origin","-webkit-mask-clip","-webkit-mask-position-x","-webkit-mask-position-y"],l=["background-position","background-position-x","background-position-y","background-size","background-repeat","background-origin","background-clip","background-attachment","background-blend-mode"],i=["border-image-slice","border-image-width","border-image-outset","border-image-repeat"];for(;s.length;){let[u,p]=s.shift();if(!p)continue;let h=n.get(u)||N(u);n.has(u)||n.set(u,h);let S=(()=>{let f=h.getPropertyValue("border-image"),d=h.getPropertyValue("border-image-source");return f&&f!=="none"||d&&d!=="none"})(),k=h.getPropertyValue("background-image"),b=h.getPropertyValue("background-color");if(k&&k!=="none"||b&&b!=="rgba(0, 0, 0, 0)"&&b!=="transparent"||/url\s*\(|gradient\s*\(/i.test(h.getPropertyValue("background")||""))for(let f of l){let d=h.getPropertyValue(f);d&&p.style.setProperty(f,d)}for(let f of a){let d=h.getPropertyValue(f);if(f==="background-image"&&(!d||d==="none")){let y=h.getPropertyValue("background");y&&/url\s*\(/.test(y)&&(d=j(y).filter(x=>/url\s*\(/.test(x)).join(", ")||d)}if(!d||d==="none")continue;let C=j(d),w=await Promise.all(C.map(y=>v(y,o)));w.some(y=>y&&y!=="none"&&!/^url\(undefined/.test(y))&&p.style.setProperty(f,w.join(", "))}for(let f of r){let d=h.getPropertyValue(f);!d||d==="initial"||p.style.setProperty(f,d)}if(S)for(let f of i){let d=h.getPropertyValue(f);!d||d==="initial"||p.style.setProperty(f,d)}let g=u.shadowRoot?Array.from(u.shadowRoot.children).filter(f=>f.tagName!=="STYLE"):Array.from(u.children),c=Array.from(p.children).filter(f=>!(f.dataset?.snapdomPseudo||f.tagName==="STYLE"&&f.dataset?.sd));for(let f=0;f<Math.min(g.length,c.length);f++)s.push([g[f],c[f]])}}async function Ue(t=document,e={}){let{embedFonts:n=!0,useProxy:o=""}=e,s=e.cache??e.cacheOpt??"full";tt(s);try{await document.fonts?.ready}catch{}try{Y()}catch{}m.session=m.session||{},m.session.styleCache||(m.session.styleCache=new WeakMap),m.image=m.image||new $(100),m.background=m.background||new $(100);try{await bt(t,void 0,m.session.styleCache,{useProxy:o})}catch{}let a=[],r=[];try{if(t&&t.nodeType===1){let i=t.querySelectorAll?Array.from(t.querySelectorAll("*")):[];r=[t,...i],a=[],t.tagName==="IMG"&&t.getAttribute("src")&&a.push(t),a.push(...Array.from(t.querySelectorAll?.("img[src]")||[]))}else t?.querySelectorAll&&(a=Array.from(t.querySelectorAll("img[src]")),r=Array.from(t.querySelectorAll("*")))}catch{}let l=[];for(let i of a){let u=i?.currentSrc||i?.src;if(u&&!m.image.has(u)){let p=Promise.resolve().then(async()=>{let h=await E(u,{as:"dataURL",useProxy:o});h?.ok&&typeof h.data=="string"&&m.image.set(u,h.data)}).catch(()=>{});l.push(p)}}for(let i of r){let u="";try{u=i?.style?.backgroundImage||"",(!u||u==="none")&&(u=N(i).backgroundImage)}catch{}if(u&&u!=="none"){let p=u.match(/url\((?:[^()"']+|"(?:[^"]*)"|'(?:[^']*)')\)/gi)||[];for(let h of p){let S=Promise.resolve().then(()=>v(h,{...e,useProxy:o})).catch(()=>{});l.push(S)}}}if(n)try{let i=yt(t),u=wt(t);if(typeof D=="function"?D():!!D){let h=new Set(Array.from(i).map(S=>String(S).split("__")[0]).filter(Boolean));await St(h,3)}await gt({required:i,usedCodepoints:u,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:e.useProxy??o,fontStylesheetDomains:e.fontStylesheetDomains})}catch{}await Promise.allSettled(l)}export{Ue as preCache};
7
+ var L=class extends Map{constructor(e=100,...n){super(...n),this._maxSize=e}set(e,n){if(this.size>=this._maxSize&&!this.has(e)){let o=this.keys().next().value;o!==void 0&&this.delete(o)}return super.set(e,n)}},f={image:new L(100),background:new L(100),resource:new L(150),defaultStyle:new L(30),baseStyle:new L(50),computedStyle:new WeakMap,measureHints:new WeakMap,font:new Set,session:{styleMap:new Map,styleCache:new WeakMap,nodeMap:new Map}};function et(t="soft"){switch(f.session.__counterEpoch=(f.session.__counterEpoch||0)+1,t){case"auto":{f.session.styleMap=new Map,f.session.nodeMap=new Map;return}case"soft":{f.session.styleMap=new Map,f.session.nodeMap=new Map,f.session.styleCache=new WeakMap;return}case"full":return;case"disabled":{f.session.styleMap=new Map,f.session.nodeMap=new Map,f.session.styleCache=new WeakMap,f.computedStyle=new WeakMap,f.measureHints=new WeakMap,f.baseStyle=new L(50),f.defaultStyle=new L(30),f.image=new L(100),f.background=new L(100),f.resource=new L(150),f.font=new Set;return}default:{f.session.styleMap=new Map,f.session.nodeMap=new Map,f.session.styleCache=new WeakMap;return}}}function V(t){let e=t.match(/url\((['"]?)(.*?)(\1)\)/);if(!e)return null;let n=e[2].trim();return n.startsWith("#")?null:n}function v(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function nt(t,e){if(!t||/^(data|blob|about|#)/i.test(t.trim()))return t;try{let n=e||typeof document<"u"&&(document.baseURI||document.location?.href)||"http://localhost/";return new URL(t,n).href}catch{return t}}function xt(t="[snapDOM]",{ttlMs:e=5*6e4,maxEntries:n=12}={}){let o=new Map,a=0;function s(r,c,i){if(a>=n)return;let u=Date.now();(o.get(c)||0)>u||(o.set(c,u+e),a++,r==="warn"&&console&&console.warn?console.warn(`${t} ${i}`):console&&console.error&&console.error(`${t} ${i}`))}return{warnOnce(r,c){s("warn",r,c)},errorOnce(r,c){s("error",r,c)},reset(){o.clear(),a=0}}}var ot=xt("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),H=new Map,j=new Map;function kt(t){return/^data:|^blob:|^about:blank$/i.test(t)}function At(t,e){try{let n=typeof location<"u"&&location.href?location.href:"http://localhost/",o=e.includes("{url}")?e.split("{url}")[0]:e,a=new URL(o||".",n),s=new URL(t,n);if(s.origin===a.origin)return!0;let r=s.searchParams;if(r&&(r.has("url")||r.has("target")))return!0}catch{}return!1}function Rt(t,e){if(!e||kt(t)||At(t,e))return!1;try{let n=typeof location<"u"&&location.href?location.href:"http://localhost/",o=new URL(t,n);return typeof location<"u"?o.origin!==location.origin:!0}catch{return!!e}}function $t(t,e){if(!e)return t;if(e.includes("{url}"))return e.replace("{urlRaw}",v(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}${v(t)}`;let n=e.includes("?")?"&":"?";return`${e}${n}url=${encodeURIComponent(t)}`}function rt(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 Lt(t,e){return[e.as||"blob",e.timeout??3e3,e.useProxy||"",e.errorTTL??8e3,t].join("|")}async function _(t,e={}){let n=e.as??"blob",o=e.timeout??3e3,a=e.useProxy||"",s=e.errorTTL??8e3,r=e.headers||{},c=!!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[,m="",p=""]=String(t).match(/^data:([^,]*),(.*)$/)||[],h=/;base64/i.test(m)?atob(p):decodeURIComponent(p),y=new Uint8Array([...h].map(S=>S.charCodeAt(0))),C=new Blob([y],{type:(m||"").split(";")[0]||""});return{ok:!0,data:C,status:200,url:t,fromCache:!1,mime:C.type||""}}catch{return{ok:!1,data:null,status:0,url:t,fromCache:!1,reason:"special_url_error"}}if(/^blob:/i.test(t))try{let m=await fetch(t);if(!m.ok)return{ok:!1,data:null,status:m.status,url:t,fromCache:!1,reason:"http_error"};let p=await m.blob(),l=p.type||m.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await rt(p),status:m.status,url:t,fromCache:!1,mime:l}:n==="text"?{ok:!0,data:await p.text(),status:m.status,url:t,fromCache:!1,mime:l}:{ok:!0,data:p,status:m.status,url:t,fromCache:!1,mime:l}}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 i=Lt(t,{as:n,timeout:o,useProxy:a,errorTTL:s}),u=j.get(i);if(u&&u.until>Date.now())return{...u.result,fromCache:!0};u&&j.delete(i);let d=H.get(i);if(d)return d;let g=Rt(t,a)?$t(t,a):t,w=e.credentials;if(!w)try{let m=typeof location<"u"&&location.href?location.href:"http://localhost/",p=new URL(t,m);w=typeof location<"u"&&p.origin===location.origin?"include":"omit"}catch{w="omit"}let R=new AbortController,k=setTimeout(()=>R.abort("timeout"),o),b=(async()=>{try{let m=await fetch(g,{signal:R.signal,credentials:w,headers:r});if(!m.ok){let h={ok:!1,data:null,status:m.status,url:g,fromCache:!1,reason:"http_error"};if(s>0&&j.set(i,{until:Date.now()+s,result:h}),!c){let y=`${m.status} ${m.statusText||""}`.trim();ot.warnOnce(`http:${m.status}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,`HTTP error ${y} while fetching ${n} ${t}`)}return e.onError&&e.onError(h),h}if(n==="text")return{ok:!0,data:await m.text(),status:m.status,url:g,fromCache:!1};let p=await m.blob(),l=p.type||m.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await rt(p),status:m.status,url:g,fromCache:!1,mime:l}:{ok:!0,data:p,status:m.status,url:g,fromCache:!1,mime:l}}catch(m){let p=m&&typeof m=="object"&&"name"in m&&m.name==="AbortError"?String(m.message||"").includes("timeout")?"timeout":"abort":"network",l={ok:!1,data:null,status:0,url:g,fromCache:!1,reason:p};if(!/^blob:/i.test(t)&&s>0&&j.set(i,{until:Date.now()+s,result:l}),!c){let h=`${p}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,y=p==="timeout"?`Timeout after ${o}ms. Consider increasing timeout or using a proxy for ${t}`:p==="abort"?`Request aborted while fetching ${n} ${t}`:`Network/CORS issue while fetching ${n} ${t}. A proxy may be required`;ot.errorOnce(h,y)}return e.onError&&e.onError(l),l}finally{clearTimeout(k),H.delete(i)}})();return H.set(i,b),b}async function N(t,e={}){if(/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t)||t.trim()==="none")return t;let o=V(t);if(!o)return t;let a=nt(o),s=v(a),r=(e.useProxy||"")+"|"+s;if(f.background.has(r)){let c=f.background.get(r);return c?`url("${c}")`:"none"}try{let c=await _(s,{as:"dataURL",useProxy:e.useProxy});return c.ok?(f.background.set(r,c.data),`url("${c.data}")`):(f.background.set(r,null),"none")}catch{return f.background.set(r,null),"none"}}var at=new Set(["meta","script","noscript","title","link","template"]),Y=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"]),Mt=["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 Q(){for(let t of Mt){let e=String(t).toLowerCase();at.has(e)||Y.has(e)||it(e)}}function it(t){if(t=String(t).toLowerCase(),Y.has(t)){let s={};return f.defaultStyle.set(t,s),s}if(f.defaultStyle.has(t))return f.defaultStyle.get(t);let e=document.getElementById("snapdom-sandbox");e||(e=document.createElement("div"),e.id="snapdom-sandbox",e.setAttribute("data-snapdom-sandbox","true"),e.setAttribute("aria-hidden","true"),e.style.position="absolute",e.style.left="-9999px",e.style.top="-9999px",e.style.width="0px",e.style.height="0px",e.style.overflow="hidden",document.body.appendChild(e));let n=document.createElement(t);n.style.all="initial",e.appendChild(n);let o=getComputedStyle(n),a={};for(let s of o){if(ct(s))continue;let r=o.getPropertyValue(s);a[s]=r}return e.removeChild(n),f.defaultStyle.set(t,a),a}var Et=/(?:^|-)(animation|transition)(?:-|$)/i,_t=/^(--.+|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,Ft=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","zoom"]),st=new Map;function ct(t){let e=st.get(t);if(e===void 0){let n=String(t).toLowerCase();e=Ft.has(n)||_t.test(n)||Et.test(n),st.set(t,e)}return e}function Ut(t){try{let e=t?.ownerDocument;if(!e)return typeof window<"u"?window:null;let n=e.defaultView;if(n&&typeof n.getComputedStyle=="function")return n;if(typeof window<"u"&&window.frames)for(let o=0;o<window.frames.length;o++)try{if(window.frames[o]?.document===e)return window.frames[o]}catch{}}catch{}return typeof window<"u"?window:null}function D(t,e=null){let n=()=>{let s={length:0,getPropertyValue:()=>"",item:()=>""};return s[Symbol.iterator]=function*(){},s};if(!(t instanceof Element)){let s=typeof window<"u"?window:null;if(s&&typeof s.getComputedStyle=="function")try{return s.getComputedStyle(t,e)||n()}catch{return n()}return n()}let o=f.computedStyle.get(t);o||(o=new Map,f.computedStyle.set(t,o));let a=o.get(e);if(!a){let s=Ut(t),r=null;try{r=s&&typeof s.getComputedStyle=="function"?s.getComputedStyle(t,e):null}catch{}if(!r&&typeof window<"u"&&typeof window.getComputedStyle=="function")try{t.ownerDocument===document&&(r=window.getComputedStyle(t,e))}catch{}a=r||n(),o.set(e,a)}return a}function z(t){let e=[],n=0,o=0;for(let a=0;a<t.length;a++){let s=t[a];s==="("&&n++,s===")"&&n--,s===","&&n===0&&(e.push(t.slice(o,a).trim()),o=a+1)}return e.push(t.slice(o).trim()),e}function W(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||"",e=t.toLowerCase(),n=e.includes("safari")&&!e.includes("chrome")&&!e.includes("crios")&&!e.includes("fxios")&&!e.includes("android"),o=/applewebkit/i.test(t),a=/mobile/i.test(t),s=!/safari/i.test(t),r=o&&a&&s,c=/(micromessenger|wxwork|wecom|windowswechat|macwechat)/i.test(t),i=/(baiduboxapp|baidubrowser|baidusearch|baiduboxlite)/i.test(e),u=/ipad|iphone|ipod/.test(e)&&o;return n||r||c||i||u}var It=[/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],Se=Object.assign({materialIconsFilled:"https://fonts.gstatic.com/s/materialicons/v48/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2",materialIconsOutlined:"https://fonts.gstatic.com/s/materialiconsoutlined/v110/gok-H7zzDkdnRel8-DQ6KAXJ69wP1tGnf4ZGhUcel5euIg.woff2",materialIconsRound:"https://fonts.gstatic.com/s/materialiconsround/v109/LDItaoyNOAY6Uewc665JcIzCKsKc_M9flwmPq_HTTw.woff2",materialIconsSharp:"https://fonts.gstatic.com/s/materialiconssharp/v110/oPWQ_lt5nv4pWNJpghLP75WiFR4kLh3kvmvRImcycg.woff2"},typeof window<"u"&&window.__SNAPDOM_ICON_FONTS__||{}),Tt=[];function U(t){let e=typeof t=="string"?t:"",n=[...It,...Tt];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))}var ut=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]),Ot=["katex","mathjax","mathml"];function Z(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!ut.has(n.toLowerCase()))return n}return""}function Pt(t){if(!t)return[];let e=[];for(let n of t.split(",")){let o=n.trim().replace(/^['"]+|['"]+$/g,"");o&&(ut.has(o.toLowerCase())||e.push(o))}return e}function G(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 X(t){let e=String(t??"normal").trim().toLowerCase();return e.startsWith("italic")?"italic":e.startsWith("oblique")?"oblique":"normal"}function vt(t){let e=String(t??"100%").match(/(\d+(?:\.\d+)?)\s*%/);return e?Math.max(50,Math.min(200,parseFloat(e[1]))):100}function Nt(t){let e=String(t||"400").trim(),n=e.match(/^(\d{2,3})\s+(\d{2,3})$/);if(n){let a=G(n[1]),s=G(n[2]);return{min:Math.min(a,s),max:Math.max(a,s)}}let o=G(e);return{min:o,max:o}}function Dt(t){let e=String(t||"normal").trim().toLowerCase();return e==="italic"?{kind:"italic"}:e.startsWith("oblique")?{kind:"oblique"}:{kind:"normal"}}function Wt(t){let e=String(t||"100%").trim(),n=e.match(/(\d+(?:\.\d+)?)\s*%\s+(\d+(?:\.\d+)?)\s*%/);if(n){let s=parseFloat(n[1]),r=parseFloat(n[2]);return{min:Math.min(s,r),max:Math.max(s,r)}}let o=e.match(/(\d+(?:\.\d+)?)\s*%/),a=o?parseFloat(o[1]):100;return{min:a,max:a}}function Bt(t){return!t||typeof t!="string"?"":t.replace(/\s+(variable|vf|v[0-9]+)$/i,"").trim().toLowerCase().replace(/\s+/g,"-")}function qt(t,e,n=[]){if(!t)return!1;try{let o=new URL(t,location.href);if(o.origin===location.origin)return!0;let s=o.host.toLowerCase();if(["fonts.googleapis.com","fonts.gstatic.com","use.typekit.net","p.typekit.net","kit.fontawesome.com","use.fontawesome.com","cdn.jsdelivr.net","unpkg.com","cdnjs.cloudflare.com","esm.sh"].some(i=>s.endsWith(i))||n.some(i=>s===i.toLowerCase()||s.endsWith("."+i.toLowerCase())))return!0;let c=(o.pathname+o.search).toLowerCase();if(/\bfont(s)?\b/.test(c)||/\.woff2?(\b|$)/.test(c)||Ot.some(i=>c.includes(i)))return!0;for(let i of e){let u=i.toLowerCase().replace(/\s+/g,"+"),d=i.toLowerCase().replace(/\s+/g,"-"),g=Bt(i);if(c.includes(u)||c.includes(d)||g&&c.includes(g))return!0}return!1}catch{return!1}}function Vt(t){let e=new Set;for(let n of t||[]){let o=String(n).split("__")[0]?.trim();o&&e.add(o)}return e}function lt(t,e){return t&&t.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/g,(n,o,a)=>{let s=(a||"").trim();if(!s||/^data:|^blob:|^https?:|^file:|^about:/i.test(s))return n;let r=s;try{r=new URL(s,e||location.href).href}catch{}return`url("${r}")`})}var J=/@import\s+(?:url\(\s*(['"]?)([^)"']+)\1\s*\)|(['"])([^"']+)\3)([^;]*);/g,K=4;async function jt(t,e,n){if(!t)return t;let o=new Set;function a(c,i){try{return new URL(c,i||location.href).href}catch{return c}}async function s(c,i,u=0){if(u>K)return console.warn(`[snapDOM] @import depth exceeded (${K}) at ${i}`),c;let d="",g=0,w;for(;w=J.exec(c);){d+=c.slice(g,w.index),g=J.lastIndex;let R=(w[2]||w[4]||"").trim(),k=a(R,i);if(o.has(k)){console.warn(`[snapDOM] Skipping circular @import: ${k}`);continue}o.add(k);let b="";try{let m=await _(k,{as:"text",useProxy:n,silent:!0});m.ok&&typeof m.data=="string"&&(b=m.data)}catch{}b?(b=lt(b,k),b=await s(b,k,u+1),d+=`
8
+ /* inlined: ${k} */
9
+ ${b}
10
+ `):d+=w[0]}return d+=c.slice(g),d}let r=lt(t,e||location.href);return r=await s(r,e||location.href,0),r}var mt=/url\((["']?)([^"')]+)\1\)/g,zt=/@font-face[^{}]*\{[^}]*\}/g;function dt(t){if(!t)return[];let e=[],n=t.split(",").map(o=>o.trim()).filter(Boolean);for(let o of n){let a=o.match(/^U\+([0-9A-Fa-f?]+)(?:-([0-9A-Fa-f?]+))?$/);if(!a)continue;let s=a[1],r=a[2],c=i=>{if(!i.includes("?"))return parseInt(i,16);let u=parseInt(i.replace(/\?/g,"0"),16),d=parseInt(i.replace(/\?/g,"F"),16);return[u,d]};if(r){let i=c(s),u=c(r),d=Array.isArray(i)?i[0]:i,g=Array.isArray(u)?u[1]:u;e.push([Math.min(d,g),Math.max(d,g)])}else{let i=c(s);Array.isArray(i)?e.push([i[0],i[1]]):e.push([i,i])}}return e}function pt(t,e){if(!e.length||!t||t.size===0)return!0;for(let n of t)for(let[o,a]of e)if(n>=o&&n<=a)return!0;return!1}function tt(t,e){let n=[];if(!t)return n;for(let o of t.matchAll(mt)){let a=(o[2]||"").trim();if(!(!a||a.startsWith("data:"))){if(!/^https?:/i.test(a))try{a=new URL(a,e||location.href).href}catch{}n.push(a)}}return n}async function ht(t,e,n=""){let o=t;for(let a of t.matchAll(mt)){let s=V(a[0]);if(!s)continue;let r=s;if(!r.startsWith("http")&&!r.startsWith("data:"))try{r=new URL(r,e||location.href).href}catch{}if(!U(r)){if(f.resource?.has(r)){f.font?.add(r),o=o.replace(a[0],`url(${f.resource.get(r)})`);continue}try{let c=await _(r,{as:"dataURL",useProxy:n,silent:!0});if(c.ok&&typeof c.data=="string"){let i=c.data;f.resource?.set(r,i),f.font?.add(r),o=o.replace(a[0],`url(${i})`)}}catch{console.warn("[snapDOM] Failed to fetch font resource:",r)}}}return o}function Gt(t){if(!t.length)return null;let e=(c,i)=>t.some(([u,d])=>!(d<c||u>i)),n=e(0,255)||e(305,305),o=e(256,591)||e(7680,7935),a=e(880,1023),s=e(1024,1279);return e(7840,7929)||e(258,259)||e(416,417)||e(431,432)?"vietnamese":s?"cyrillic":a?"greek":o?"latin-ext":n?"latin":null}function ft(t={}){let e=new Set((t.families||[]).map(a=>String(a).toLowerCase())),n=new Set((t.domains||[]).map(a=>String(a).toLowerCase())),o=new Set((t.subsets||[]).map(a=>String(a).toLowerCase()));return(a,s)=>{if(e.size&&e.has(a.family.toLowerCase()))return!0;if(n.size)for(let r of a.srcUrls)try{if(n.has(new URL(r).host.toLowerCase()))return!0}catch{}if(o.size){let r=Gt(s);if(r&&o.has(r))return!0}return!1}}function Xt(t){if(!t)return t;let e=/@font-face[^{}]*\{[^}]*\}/gi,n=new Set,o=[];for(let s of t.match(e)||[]){let r=s.match(/font-family:\s*([^;]+);/i)?.[1]||"",c=Z(r),i=(s.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),u=(s.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),d=(s.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),g=(s.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),w=(s.match(/src\s*:\s*([^;}]+)[;}]/i)?.[1]||"").trim(),R=tt(w,location.href),k=R.length?R.map(m=>String(m).toLowerCase()).sort().join("|"):w.toLowerCase(),b=[String(c||"").toLowerCase(),i,u,d,g.toLowerCase(),k].join("|");n.has(b)||(n.add(b),o.push(s))}if(o.length===0)return t;let a=0;return t.replace(e,()=>o[a++]||"")}function Kt(t,e,n,o,a){let s=Array.from(t||[]).sort().join("|"),r=e?JSON.stringify({families:(e.families||[]).map(d=>String(d).toLowerCase()).sort(),domains:(e.domains||[]).map(d=>String(d).toLowerCase()).sort(),subsets:(e.subsets||[]).map(d=>String(d).toLowerCase()).sort()}):"",c=(n||[]).map(d=>`${(d.family||"").toLowerCase()}::${d.weight||"normal"}::${d.style||"normal"}::${d.src||""}`).sort().join("|"),i=o||"",u=(a||[]).map(d=>String(d).toLowerCase()).sort().join("|");return`fonts-embed-css::req=${s}::ex=${r}::lf=${c}::px=${i}::fd=${u}`}async function gt(t,e,n,o){let a;try{a=t.cssRules||[]}catch{return}let s=(r,c)=>{try{return new URL(r,c||location.href).href}catch{return r}};for(let r of a){if(r.type===CSSRule.IMPORT_RULE&&r.styleSheet){let c=r.href?s(r.href,e):e;if(o.depth>=K){console.warn(`[snapDOM] CSSOM import depth exceeded (${K}) at ${c}`);continue}if(c&&o.visitedSheets.has(c)){console.warn(`[snapDOM] Skipping circular CSSOM import: ${c}`);continue}c&&o.visitedSheets.add(c);let i={...o,depth:(o.depth||0)+1};await gt(r.styleSheet,c,n,i);continue}if(r.type===CSSRule.FONT_FACE_RULE){let c=(r.style.getPropertyValue("font-family")||"").trim(),i=Z(c);if(!i||U(i))continue;let u=(r.style.getPropertyValue("font-weight")||"400").trim(),d=(r.style.getPropertyValue("font-style")||"normal").trim(),g=(r.style.getPropertyValue("font-stretch")||"100%").trim(),w=(r.style.getPropertyValue("src")||"").trim(),R=(r.style.getPropertyValue("unicode-range")||"").trim();if(!o.faceMatchesRequired(i,d,u,g))continue;let k=dt(R);if(!pt(o.usedCodepoints,k))continue;let b={family:i,weightSpec:u,styleSpec:d,stretchSpec:g,unicodeRange:R,srcRaw:w,srcUrls:tt(w,e||location.href),href:e||location.href};if(o.simpleExcluder&&o.simpleExcluder(b,k))continue;if(/url\(/i.test(w)){let m=await ht(w,e||location.href,o.useProxy);await n(`@font-face{font-family:${i};src:${m};font-style:${d};font-weight:${u};font-stretch:${g};${R?`unicode-range:${R};`:""}}`)}else await n(`@font-face{font-family:${i};src:${w};font-style:${d};font-weight:${u};font-stretch:${g};${R?`unicode-range:${R};`:""}}`)}}}async function yt({required:t,usedCodepoints:e,exclude:n=void 0,localFonts:o=[],useProxy:a="",fontStylesheetDomains:s=[],doc:r=document}={}){t instanceof Set||(t=new Set),e instanceof Set||(e=new Set);let c=new Map;for(let l of t){let[h,y,C,S]=String(l).split("__");if(!h)continue;let x=h.toLowerCase(),A=c.get(x)||[];A.push({w:parseInt(y,10),s:C,st:parseInt(S,10)}),c.set(x,A)}function i(l,h,y,C){let S=String(l).toLowerCase();if(!c.has(S))return!1;let x=c.get(S),A=Nt(y),M=Dt(h),F=Wt(C),T=A.min!==A.max,O=A.min,P=$=>M.kind==="normal"&&$==="normal"||M.kind!=="normal"&&($==="italic"||$==="oblique"),B=!1;for(let $ of x){let E=T?$.w>=A.min&&$.w<=A.max:$.w===O,I=P(X($.s)),q=$.st>=F.min&&$.st<=F.max;if(E&&I&&q){B=!0;break}}if(B)return!0;if(!T)for(let $ of x){let E=P(X($.s)),I=$.st>=F.min&&$.st<=F.max;if(Math.abs(O-$.w)<=300&&E&&I)return!0}if(!T&&M.kind==="normal"&&x.some(E=>X(E.s)!=="normal"))for(let E of x){let I=Math.abs(O-E.w)<=300,q=E.st>=F.min&&E.st<=F.max;if(I&&q)return!0}return!1}let u=ft(n),d=Kt(t,n,o,a,s);if(f.resource?.has(d))return f.resource.get(d);let g=Vt(t),w=[],R=J;for(let l of r.querySelectorAll("style")){let h=l.textContent||"";for(let y of h.matchAll(R)){let C=(y[2]||y[4]||"").trim();if(!C||U(C))continue;r.querySelector(`link[rel="stylesheet"][href="${C}"]`)||w.push(C)}}let k=[];w.length&&await Promise.all(w.map(l=>new Promise(h=>{if(r.querySelector(`link[rel="stylesheet"][href="${l}"]`))return h(null);let y=r.createElement("link");y.rel="stylesheet",y.href=l,y.setAttribute("data-snapdom","injected-import"),y.onload=()=>h(y),y.onerror=()=>h(null),r.head.appendChild(y),k.push(y)})));let b="",m=Array.from(r.querySelectorAll('link[rel="stylesheet"]')).filter(l=>!!l.href);for(let l of k)try{l.remove()}catch{}for(let l of m)try{if(U(l.href))continue;let h="",y=!1;try{y=new URL(l.href,location.href).origin===location.origin}catch{}if(!y){let S=Array.isArray(s)?s:[];if(!qt(l.href,g,S))continue}if(y){let S=Array.from(r.styleSheets).find(x=>x.href===l.href);if(S)try{let x=S.cssRules||[];h=Array.from(x).map(A=>A.cssText).join("")}catch{}}if(!h){let S=await _(l.href,{as:"text",useProxy:a});if(S?.ok&&typeof S.data=="string"&&(h=S.data),U(l.href))continue}h=await jt(h,l.href,a);let C="";for(let S of h.match(zt)||[]){let x=(S.match(/font-family:\s*([^;]+);/i)?.[1]||"").trim(),A=Z(x);if(!A||U(A))continue;let M=(S.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),F=(S.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),T=(S.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),O=(S.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),P=(S.match(/src\s*:\s*([^;}]+)[;}]/i)?.[1]||"").trim(),B=tt(P,l.href);if(!i(A,F,M,T))continue;let $=dt(O);if(!pt(e,$))continue;let E={family:A,weightSpec:M,styleSpec:F,stretchSpec:T,unicodeRange:O,srcRaw:P,srcUrls:B,href:l.href};if(n&&u(E,$))continue;let I=/url\(/i.test(P)?await ht(S,l.href,a):S;C+=I}C.trim()&&(b+=C)}catch{console.warn("[snapDOM] Failed to process stylesheet:",l.href)}let p={requiredIndex:c,usedCodepoints:e,faceMatchesRequired:i,simpleExcluder:n?ft(n):null,useProxy:a,visitedSheets:new Set,depth:0};for(let l of r.styleSheets)if(!(l.href&&m.some(h=>h.href===l.href)))try{let h=l.href||location.origin+"/";h&&p.visitedSheets.add(h),await gt(l,h,async y=>{b+=y},p)}catch{}try{for(let l of r.fonts||[]){if(!l||!l.family||l.status!=="loaded"||!l._snapdomSrc)continue;let h=String(l.family).replace(/^['"]+|['"]+$/g,"");if(U(h)||!c.has(h.toLowerCase())||n?.families&&n.families.some(C=>String(C).toLowerCase()===h.toLowerCase()))continue;let y=l._snapdomSrc;if(!String(y).startsWith("data:")){if(f.resource?.has(l._snapdomSrc))y=f.resource.get(l._snapdomSrc),f.font?.add(l._snapdomSrc);else if(!f.font?.has(l._snapdomSrc))try{let C=await _(l._snapdomSrc,{as:"dataURL",useProxy:a,silent:!0});if(C.ok&&typeof C.data=="string")y=C.data,f.resource?.set(l._snapdomSrc,y),f.font?.add(l._snapdomSrc);else continue}catch{console.warn("[snapDOM] Failed to fetch dynamic font src:",l._snapdomSrc);continue}}b+=`@font-face{font-family:'${h}';src:url(${y});font-style:${l.style||"normal"};font-weight:${l.weight||"normal"};}`}}catch{}for(let l of o){if(!l||typeof l!="object")continue;let h=String(l.family||"").replace(/^['"]+|['"]+$/g,"");if(!h||U(h)||!c.has(h.toLowerCase())||n?.families&&n.families.some(M=>String(M).toLowerCase()===h.toLowerCase()))continue;let y=l.weight!=null?String(l.weight):"normal",C=l.style!=null?String(l.style):"normal",S=l.stretchPct!=null?`${l.stretchPct}%`:"100%",x=String(l.src||""),A=x;if(!A.startsWith("data:")){if(f.resource?.has(x))A=f.resource.get(x),f.font?.add(x);else if(!f.font?.has(x))try{let M=await _(x,{as:"dataURL",useProxy:a,silent:!0});if(M.ok&&typeof M.data=="string")A=M.data,f.resource?.set(x,A),f.font?.add(x);else continue}catch{console.warn("[snapDOM] Failed to fetch localFonts src:",x);continue}}b+=`@font-face{font-family:'${h}';src:url(${A});font-style:${C};font-weight:${y};font-stretch:${S};}`}return b&&(b=Xt(b),f.resource?.set(d,b)),b}function wt(t){let e=new Set;if(!t)return e;let n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null),o=r=>{let c=Pt(r.fontFamily);if(c.length)for(let i of c){let u=(d,g,w)=>`${i}__${G(d)}__${X(g)}__${vt(w)}`;e.add(u(r.fontWeight,r.fontStyle,r.fontStretch))}};o(getComputedStyle(t));let a=getComputedStyle(t,"::before");a&&a.content&&a.content!=="none"&&o(a);let s=getComputedStyle(t,"::after");for(s&&s.content&&s.content!=="none"&&o(s);n.nextNode();){let r=n.currentNode,c=getComputedStyle(r);o(c);let i=getComputedStyle(r,"::before");i&&i.content&&i.content!=="none"&&o(i);let u=getComputedStyle(r,"::after");u&&u.content&&u.content!=="none"&&o(u)}return e}function St(t){let e=new Set,n=a=>{if(a)for(let s of a)e.add(s.codePointAt(0))},o=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,null);for(;o.nextNode();){let a=o.currentNode;if(a.nodeType===Node.TEXT_NODE)n(a.nodeValue||"");else if(a.nodeType===Node.ELEMENT_NODE){let s=a;for(let r of["::before","::after"]){let i=getComputedStyle(s,r)?.getPropertyValue("content");if(!(!i||i==="none"))if(/^"/.test(i)||/^'/.test(i))n(i.slice(1,-1));else{let u=i.match(/\\[0-9A-Fa-f]{1,6}/g);if(u)for(let d of u)try{e.add(parseInt(d.slice(1),16))}catch{}}}}}return e}async function bt(t,e=2,n=document){try{await n.fonts.ready}catch{}let o=Array.from(t||[]).filter(Boolean);if(o.length===0)return;let a=()=>{let s=n.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 r of o){let c=n.createElement("span");c.textContent="AaBbGg1234\xC1\xC9\xCD\xD3\xDA\xE7\xF1\u2014\u221E",c.style.fontFamily=`"${r}"`,c.style.fontWeight="700",c.style.fontStyle="italic",c.style.fontSize="32px",c.style.lineHeight="1",c.style.whiteSpace="nowrap",c.style.margin="0",c.style.padding="0",s.appendChild(c)}n.body.appendChild(s),s.offsetWidth,n.body.removeChild(s)};for(let s=0;s<Math.max(1,e);s++)a(),await new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r)))}async function Ct(t,e,n,o={}){let a=[[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"],r=["mask-position","mask-size","mask-repeat","mask-mode","mask-composite","-webkit-mask-position","-webkit-mask-size","-webkit-mask-repeat","-webkit-mask-composite","mask-origin","mask-clip","-webkit-mask-origin","-webkit-mask-clip","-webkit-mask-position-x","-webkit-mask-position-y"],c=["background-position","background-position-x","background-position-y","background-size","background-repeat","background-origin","background-clip","background-attachment","background-blend-mode"],i=["border-image-slice","border-image-width","border-image-outset","border-image-repeat"];for(;a.length;){let[u,d]=a.shift();if(!d)continue;let g=n.get(u)||D(u);n.has(u)||n.set(u,g);let w=(()=>{let m=g.getPropertyValue("border-image"),p=g.getPropertyValue("border-image-source");return m&&m!=="none"||p&&p!=="none"})(),R=g.getPropertyValue("background-image"),k=g.getPropertyValue("background-color");if(R&&R!=="none"||k&&k!=="rgba(0, 0, 0, 0)"&&k!=="transparent"||/url\s*\(|gradient\s*\(/i.test(g.getPropertyValue("background")||""))for(let m of c){let p=g.getPropertyValue(m);p&&d.style.setProperty(m,p)}for(let m of s){let p=g.getPropertyValue(m);if(m==="background-image"&&(!p||p==="none")){let y=g.getPropertyValue("background");y&&/url\s*\(/.test(y)&&(p=z(y).filter(C=>/url\s*\(/.test(C)).join(", ")||p)}if(!p||p==="none")continue;let l=z(p),h=await Promise.all(l.map(y=>N(y,o)));h.some(y=>y&&y!=="none"&&!/^url\(undefined/.test(y))&&d.style.setProperty(m,h.join(", "))}for(let m of r){let p=g.getPropertyValue(m);!p||p==="initial"||d.style.setProperty(m,p)}if(w)for(let m of i){let p=g.getPropertyValue(m);!p||p==="initial"||d.style.setProperty(m,p)}if(u.shadowRoot){let m=Array.from(u.shadowRoot.children).filter(l=>l.tagName!=="STYLE"),p=Array.from(d.children).filter(l=>!l.dataset?.snapdomPseudo&&!(l.tagName==="STYLE"&&l.dataset?.sd));for(let l=0;l<Math.min(m.length,p.length);l++)a.push([m[l],p[l]])}else{let m=f.session.nodeMap;for(let p of d.children){let l=m.get(p);l&&a.push([l,p])}}}}async function Te(t=document,e={}){let{embedFonts:n=!0,useProxy:o=""}=e,a=e.cache??e.cacheOpt??"full";et(a);try{await document.fonts?.ready}catch{}try{Q()}catch{}f.session=f.session||{},f.session.styleCache||(f.session.styleCache=new WeakMap),f.image=f.image||new L(100),f.background=f.background||new L(100);try{await Ct(t,void 0,f.session.styleCache,{useProxy:o})}catch{}let s=[],r=[];try{if(t&&t.nodeType===1){let i=t.querySelectorAll?Array.from(t.querySelectorAll("*")):[];r=[t,...i],s=[],t.tagName==="IMG"&&t.getAttribute("src")&&s.push(t),s.push(...Array.from(t.querySelectorAll?.("img[src]")||[]))}else t?.querySelectorAll&&(s=Array.from(t.querySelectorAll("img[src]")),r=Array.from(t.querySelectorAll("*")))}catch{}let c=[];for(let i of s){let u=i?.currentSrc||i?.src;if(u&&!f.image.has(u)){let d=Promise.resolve().then(async()=>{let g=await _(u,{as:"dataURL",useProxy:o});g?.ok&&typeof g.data=="string"&&f.image.set(u,g.data)}).catch(()=>{});c.push(d)}}for(let i of r){let u="";try{u=i?.style?.backgroundImage||"",(!u||u==="none")&&(u=D(i).backgroundImage)}catch{}if(u&&u!=="none"){let d=u.match(/url\((?:[^()"']+|"(?:[^"]*)"|'(?:[^']*)')\)/gi)||[];for(let g of d){let w=Promise.resolve().then(()=>N(g,{...e,useProxy:o})).catch(()=>{});c.push(w)}}}if(n)try{let i=wt(t),u=St(t);if(typeof W=="function"?W():!!W){let g=new Set(Array.from(i).map(w=>String(w).split("__")[0]).filter(Boolean));await bt(g,3)}await yt({required:i,usedCodepoints:u,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:e.useProxy??o,fontStylesheetDomains:e.fontStylesheetDomains})}catch{}await Promise.allSettled(c)}export{Te as preCache};