@zumer/snapdom 2.24.15 → 2.24.16
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 +15 -2
- package/dist/plugins.mjs +1 -1
- package/dist/preCache.mjs +3 -3
- package/dist/snapdom.js +6 -6
- package/dist/snapdom.mjs +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,6 +89,7 @@ await result.download({ format: 'jpg', filename: 'card.jpg' });
|
|
|
89
89
|
- [Contributors](#contributors)
|
|
90
90
|
- [Sponsors](#sponsors)
|
|
91
91
|
- [Show your support](#show-your-support)
|
|
92
|
+
- [Acknowledgments](#acknowledgments)
|
|
92
93
|
- [License](#license)
|
|
93
94
|
|
|
94
95
|
## Installation
|
|
@@ -102,14 +103,22 @@ yarn add @zumer/snapdom
|
|
|
102
103
|
|
|
103
104
|
### NPM / Yarn (dev builds)
|
|
104
105
|
|
|
105
|
-
|
|
106
|
+
The `@dev` tag is independent of `@latest` and can point to an older build.
|
|
107
|
+
Check the published versions before choosing a development build:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npm view @zumer/snapdom dist-tags
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Install `@dev` only when its listed version is the one you intend to test:
|
|
106
114
|
|
|
107
115
|
```bash
|
|
108
116
|
npm i @zumer/snapdom@dev
|
|
109
117
|
yarn add @zumer/snapdom@dev
|
|
110
118
|
```
|
|
111
119
|
|
|
112
|
-
|
|
120
|
+
`@dev` does not identify the v3 beta. Until v3 is published, use its local checkout;
|
|
121
|
+
when a beta is available, install its explicit version or announced tag.
|
|
113
122
|
|
|
114
123
|
|
|
115
124
|
### CDN (stable)
|
|
@@ -428,6 +437,10 @@ SnapDOM runs in production across 250+ public repositories ([GitHub dependents g
|
|
|
428
437
|
|
|
429
438
|
See the full gallery at **[snapdom.dev/made-with](https://snapdom.dev/made-with/)**. Shipping SnapDOM? [Open a PR](https://github.com/zumerlab/snapdom/pulls) to add your project. Real, verifiable projects only.
|
|
430
439
|
|
|
440
|
+
## Acknowledgments
|
|
441
|
+
|
|
442
|
+
Thanks to [Anthropic](https://claude.com/contact-sales/claude-for-oss) and [OpenAI](https://openai.com/form/codex-for-oss/) for supporting my open-source work by providing premium access to Claude and ChatGPT.
|
|
443
|
+
|
|
431
444
|
## License
|
|
432
445
|
|
|
433
446
|
MIT © Zumerlab
|
package/dist/plugins.mjs
CHANGED
package/dist/preCache.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* SnapDOM
|
|
3
|
-
* v2.24.
|
|
3
|
+
* v2.24.16
|
|
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)}},f={image:new _(100),background:new _(100),resource:new _(150),defaultStyle:new _(30),baseStyle:new _(50),compress:new _(50),computedStyle:new WeakMap,measureHints:new WeakMap,burstAdvice:new WeakMap,warnedReconcile:!1,font:new Set,session:{styleMap:new Map,styleCache:new WeakMap,nodeMap:new Map}};function st(t="soft"){switch(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 _(50),f.defaultStyle=new _(30),f.image=new _(100),f.background=new _(100),f.resource=new _(150),f.compress=new _(50),f.font=new Set;return}default:{f.session.styleMap=new Map,f.session.nodeMap=new Map,f.session.styleCache=new WeakMap;return}}}function z(t){let e=t.match(/url\((['"]?)(.*?)(\1)\)/);if(!e)return null;let n=e[2].trim();return n.startsWith("#")?null:n}var Rt=/^image\/(jpeg|jpg|png|gif|webp|avif|apng|svg\+xml|bmp|x-icon|vnd\.microsoft\.icon)\s*(;|$)/i;function it(t,e=1){let n=t.match(/^\s*-?(?:webkit-)?image-set\(([\s\S]*)\)\s*$/i);if(!n)return null;let o=[];for(let r of n[1].split(",")){let s=r.match(/url\((['"]?)(.*?)(\1)\)/);if(!s)continue;let a=r.match(/type\(\s*["']([^"']+)["']\s*\)/i);if(a&&!Rt.test(a[1].trim()))continue;let i=r.match(/(\d+(?:\.\d+)?)\s*(x|dpi|dppx)/i),u=1;if(i){let m=parseFloat(i[1]);u=/dpi/i.test(i[2])?m/96:m}o.push({url:s[2].trim(),dppx:u})}return o.length?(o.sort((r,s)=>r.dppx-s.dppx),(o.find(r=>r.dppx>=e)||o[o.length-1]).url):null}function q(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function at(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 $t(t="[snapDOM]",{ttlMs:e=5*6e4,maxEntries:n=12}={}){let o=new Map,c=0;function r(s,a,i){if(c>=n)return;let u=Date.now();(o.get(a)||0)>u||(o.set(a,u+e),c++,s==="warn"&&console&&console.warn?console.warn(`${t} ${i}`):console&&console.error&&console.error(`${t} ${i}`))}return{warnOnce(s,a){r("warn",s,a)},errorOnce(s,a){r("error",s,a)},reset(){o.clear(),c=0}}}var ct=$t("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),Y=new Map,X=new Map;function Mt(t){return/^data:|^blob:|^about:blank$/i.test(t)}function _t(t,e){try{let n=typeof location<"u"&&location.href?location.href:"http://localhost/",o=e.includes("{url}")?e.split("{url}")[0]:e,c=new URL(o||".",n),r=new URL(t,n);if(r.origin===c.origin)return!0;let s=r.searchParams;if(s&&(s.has("url")||s.has("target")))return!0}catch{}return!1}function Ft(t,e){if(!e||Mt(t)||_t(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 Et(t,e){if(!e)return t;if(e.includes("{url}"))return e.replace("{urlRaw}",q(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}${q(t)}`;let n=e.includes("?")?"&":"?";return`${e}${n}url=${encodeURIComponent(t)}`}function lt(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 It(t,e){return[e.as||"blob",e.timeout??3e3,e.useProxy||"",e.errorTTL??8e3,t].join("|")}async function U(t,e={}){let n=e.as??"blob",o=e.timeout??3e3,c=e.useProxy||"",r=e.errorTTL??8e3,s=e.headers||{},a=!!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[,p="",b=""]=String(t).match(/^data:([^,]*),(.*)$/)||[],M=/;base64/i.test(p)?atob(b):decodeURIComponent(b),l=new Uint8Array([...M].map(y=>y.charCodeAt(0))),g=new Blob([l],{type:(p||"").split(";")[0]||""});return{ok:!0,data:g,status:200,url:t,fromCache:!1,mime:g.type||""}}catch{return{ok:!1,data:null,status:0,url:t,fromCache:!1,reason:"special_url_error"}}if(/^blob:/i.test(t))try{let p=await fetch(t);if(!p.ok)return{ok:!1,data:null,status:p.status,url:t,fromCache:!1,reason:"http_error"};let b=await p.blob(),R=b.type||p.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await lt(b),status:p.status,url:t,fromCache:!1,mime:R}:n==="text"?{ok:!0,data:await b.text(),status:p.status,url:t,fromCache:!1,mime:R}:{ok:!0,data:b,status:p.status,url:t,fromCache:!1,mime:R}}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=It(t,{as:n,timeout:o,useProxy:c,errorTTL:r}),u=X.get(i);if(u&&u.until>Date.now())return{...u.result,fromCache:!0};u&&X.delete(i);let m=Y.get(i);if(m)return m;let d=Ft(t,c)?Et(t,c):t,h=e.credentials;if(!h)try{let p=typeof location<"u"&&location.href?location.href:"http://localhost/",b=new URL(t,p);h=typeof location<"u"&&b.origin===location.origin?"include":"omit"}catch{h="omit"}let C=new AbortController,A=setTimeout(()=>C.abort("timeout"),o),w=(async()=>{try{let p=await fetch(d,{signal:C.signal,credentials:h,headers:s});if(!p.ok){let M={ok:!1,data:null,status:p.status,url:d,fromCache:!1,reason:"http_error"};if(r>0&&X.set(i,{until:Date.now()+r,result:M}),!a){let l=`${p.status} ${p.statusText||""}`.trim();ct.warnOnce(`http:${p.status}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,`HTTP error ${l} while fetching ${n} ${t}`)}return e.onError&&e.onError(M),M}if(n==="text")return{ok:!0,data:await p.text(),status:p.status,url:d,fromCache:!1};let b=await p.blob(),R=b.type||p.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await lt(b),status:p.status,url:d,fromCache:!1,mime:R}:{ok:!0,data:b,status:p.status,url:d,fromCache:!1,mime:R}}catch(p){let b=p&&typeof p=="object"&&"name"in p&&p.name==="AbortError"?String(p.message||"").includes("timeout")?"timeout":"abort":"network",R={ok:!1,data:null,status:0,url:d,fromCache:!1,reason:b};if(!/^blob:/i.test(t)&&r>0&&X.set(i,{until:Date.now()+r,result:R}),!a){let M=`${b}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,l=b==="timeout"?`Timeout after ${o}ms. Consider increasing timeout or using a proxy for ${t}`:b==="abort"?`Request aborted while fetching ${n} ${t}`:`Network/CORS issue while fetching ${n} ${t}. A proxy may be required`;ct.errorOnce(M,l)}return e.onError&&e.onError(R),R}finally{clearTimeout(A),Y.delete(i)}})();return Y.set(i,w),w}async function Q(t,e={}){if(/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t)||t.trim()==="none")return t;let o=it(t,typeof devicePixelRatio<"u"&&devicePixelRatio||1)??z(t);if(!o)return t;let c=at(o),r=q(c),s=(e.useProxy||"")+"|"+r;if(f.background.has(s)){let a=f.background.get(s);return a?`url("${a}")`:"none"}try{let a=await U(r,{as:"dataURL",useProxy:e.useProxy});return a.ok?(f.background.set(s,a.data),`url("${a.data}")`):(f.background.set(s,null),"none")}catch{return f.background.set(s,null),"none"}}var ut=new Set(["meta","script","noscript","title","link","template"]),J=new Set(["meta","link","style","title","noscript","script","template","g","defs","use","marker","mask","clipPath","pattern","symbol","path","polygon","polyline","line","circle","ellipse","rect","filter","lineargradient","radialgradient","stop"]),Ut=["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 Z(){for(let t of Ut){let e=String(t).toLowerCase();ut.has(e)||J.has(e)||mt(e)}}function mt(t){if(t=String(t).toLowerCase(),J.has(t)){let r={};return f.defaultStyle.set(t,r),r}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),c={};for(let r of o){if(dt(r))continue;let s=o.getPropertyValue(r);c[r]=s}return e.removeChild(n),f.defaultStyle.set(t,c),c}var Tt=/(?:^|-)(animation|transition)(?:-|$)/i,vt=/^(--.+|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,Ot=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","stroke-color"]),ft=new Map;function dt(t){let e=ft.get(t);if(e===void 0){let n=String(t).toLowerCase();e=Ot.has(n)||vt.test(n)||Tt.test(n),ft.set(t,e)}return e}function Pt(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 r={length:0,getPropertyValue:()=>"",item:()=>""};return r[Symbol.iterator]=function*(){},r};if(t?.nodeType!==1){let r=typeof window<"u"?window:null;if(r&&typeof r.getComputedStyle=="function")try{return r.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 c=o.get(e);if(!c){let r=Pt(t),s=null;try{s=r&&typeof r.getComputedStyle=="function"?r.getComputedStyle(t,e):null}catch{}if(!s&&typeof window<"u"&&typeof window.getComputedStyle=="function")try{t.ownerDocument===document&&(s=window.getComputedStyle(t,e))}catch{}c=s||n(),o.set(e,c)}return c}function tt(t=1e3){return typeof requestAnimationFrame!="function"||typeof document<"u"&&document.visibilityState==="hidden"?Promise.resolve():new Promise(e=>{let n=!1,o=()=>{n||(n=!0,e())};try{requestAnimationFrame(o)}catch{o();return}setTimeout(o,t)})}function V(){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),c=/mobile/i.test(t),r=!/safari/i.test(t),s=o&&c&&r,a=/(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||s||a||i||u}var Wt=[/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],Me=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__||{}),Dt=[];function v(t){let e=typeof t=="string"?t:"",n=[...Wt,...Dt];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 yt=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]),Bt=["katex","mathjax","mathml"];function ot(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!yt.has(n.toLowerCase()))return n}return""}function Nt(t){if(!t)return[];let e=[];for(let n of t.split(",")){let o=n.trim().replace(/^['"]+|['"]+$/g,"");o&&(yt.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 K(t){let e=String(t??"normal").trim().toLowerCase();return e.startsWith("italic")?"italic":e.startsWith("oblique")?"oblique":"normal"}function qt(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 c=G(n[1]),r=G(n[2]);return{min:Math.min(c,r),max:Math.max(c,r)}}let o=G(e);return{min:o,max:o}}function jt(t){let e=String(t||"normal").trim().toLowerCase();return e==="italic"?{kind:"italic"}:e.startsWith("oblique")?{kind:"oblique"}:{kind:"normal"}}function zt(t){let e=String(t||"100%").trim(),n=e.match(/(\d+(?:\.\d+)?)\s*%\s+(\d+(?:\.\d+)?)\s*%/);if(n){let r=parseFloat(n[1]),s=parseFloat(n[2]);return{min:Math.min(r,s),max:Math.max(r,s)}}let o=e.match(/(\d+(?:\.\d+)?)\s*%/),c=o?parseFloat(o[1]):100;return{min:c,max:c}}function Xt(t){return!t||typeof t!="string"?"":t.replace(/\s+(variable|vf|v[0-9]+)$/i,"").trim().toLowerCase().replace(/\s+/g,"-")}function Gt(t,e,n=[]){if(!t)return!1;try{let o=new URL(t,location.href);if(o.origin===location.origin)return!0;let r=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=>r.endsWith(i))||n.some(i=>r===i.toLowerCase()||r.endsWith("."+i.toLowerCase())))return!0;let a=(o.pathname+o.search).toLowerCase();if(/\bfont(s)?\b/.test(a)||/\.woff2?(\b|$)/.test(a)||Bt.some(i=>a.includes(i)))return!0;for(let i of e){let u=i.toLowerCase().replace(/\s+/g,"+"),m=i.toLowerCase().replace(/\s+/g,"-"),d=Xt(i);if(a.includes(u)||a.includes(m)||d&&a.includes(d))return!0}return!1}catch{return!1}}function Kt(t){let e=new Set;for(let n of t||[]){let o=String(n).split("__")[0]?.trim();o&&e.add(o)}return e}function pt(t,e){return t&&t.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/g,(n,o,c)=>{let r=(c||"").trim();if(!r||/^data:|^blob:|^https?:|^file:|^about:/i.test(r))return n;let s=r;try{s=new URL(r,e||location.href).href}catch{}return`url("${s}")`})}var et=/@import\s+(?:url\(\s*(['"]?)([^)"']+)\1\s*\)|(['"])([^"']+)\3)([^;]*);/g,H=4;async function Ht(t,e,n){if(!t)return t;let o=new Set;function c(a,i){try{return new URL(a,i||location.href).href}catch{return a}}async function r(a,i,u=0){if(u>H)return console.warn(`[snapDOM] @import depth exceeded (${H}) at ${i}`),a;let m="",d=0,h;for(;h=et.exec(a);){m+=a.slice(d,h.index),d=et.lastIndex;let C=(h[2]||h[4]||"").trim(),A=c(C,i);if(o.has(A)){console.warn(`[snapDOM] Skipping circular @import: ${A}`);continue}o.add(A);let w="";try{let p=await U(A,{as:"text",useProxy:n,silent:!0});p.ok&&typeof p.data=="string"&&(w=p.data)}catch{}w?(w=pt(w,A),w=await r(w,A,u+1),m+=`
|
|
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)}},f={image:new _(100),background:new _(100),resource:new _(150),defaultStyle:new _(30),baseStyle:new _(50),compress:new _(50),computedStyle:new WeakMap,measureHints:new WeakMap,burstAdvice:new WeakMap,warnedReconcile:!1,font:new Set,session:{styleMap:new Map,styleCache:new WeakMap,nodeMap:new Map}};function it(t="soft"){switch(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 _(50),f.defaultStyle=new _(30),f.image=new _(100),f.background=new _(100),f.resource=new _(150),f.compress=new _(50),f.font=new Set;return}default:{f.session.styleMap=new Map,f.session.nodeMap=new Map,f.session.styleCache=new WeakMap;return}}}function z(t){let e=t.match(/url\((['"]?)(.*?)(\1)\)/);if(!e)return null;let n=e[2].trim();return n.startsWith("#")?null:n}var $t=/^image\/(jpeg|jpg|png|gif|webp|avif|apng|svg\+xml|bmp|x-icon|vnd\.microsoft\.icon)\s*(;|$)/i;function at(t,e=1){let n=t.match(/^\s*-?(?:webkit-)?image-set\(([\s\S]*)\)\s*$/i);if(!n)return null;let o=[];for(let r of n[1].split(",")){let s=r.match(/url\((['"]?)(.*?)(\1)\)/);if(!s)continue;let a=r.match(/type\(\s*["']([^"']+)["']\s*\)/i);if(a&&!$t.test(a[1].trim()))continue;let i=r.match(/(\d+(?:\.\d+)?)\s*(x|dpi|dppx)/i),u=1;if(i){let m=parseFloat(i[1]);u=/dpi/i.test(i[2])?m/96:m}o.push({url:s[2].trim(),dppx:u})}return o.length?(o.sort((r,s)=>r.dppx-s.dppx),(o.find(r=>r.dppx>=e)||o[o.length-1]).url):null}function q(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function ct(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 Mt(t="[snapDOM]",{ttlMs:e=5*6e4,maxEntries:n=12}={}){let o=new Map,c=0;function r(s,a,i){if(c>=n)return;let u=Date.now();(o.get(a)||0)>u||(o.set(a,u+e),c++,s==="warn"&&console&&console.warn?console.warn(`${t} ${i}`):console&&console.error&&console.error(`${t} ${i}`))}return{warnOnce(s,a){r("warn",s,a)},errorOnce(s,a){r("error",s,a)},reset(){o.clear(),c=0}}}var lt=Mt("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),Y=new Map,X=new Map;function _t(t){return/^data:|^blob:|^about:blank$/i.test(t)}function Ft(t,e){try{let n=typeof location<"u"&&location.href?location.href:"http://localhost/",o=e.includes("{url}")?e.split("{url}")[0]:e,c=new URL(o||".",n),r=new URL(t,n);if(r.origin===c.origin)return!0;let s=r.searchParams;if(s&&(s.has("url")||s.has("target")))return!0}catch{}return!1}function Et(t,e){if(!e||_t(t)||Ft(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 It(t,e){if(!e)return t;if(e.includes("{url}"))return e.replace("{urlRaw}",q(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}${q(t)}`;let n=e.includes("?")?"&":"?";return`${e}${n}url=${encodeURIComponent(t)}`}function ft(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 Ut(t,e){return[e.as||"blob",e.timeout??3e3,e.useProxy||"",e.errorTTL??8e3,t].join("|")}async function U(t,e={}){let n=e.as??"blob",o=e.timeout??3e3,c=e.useProxy||"",r=e.errorTTL??8e3,s=e.headers||{},a=!!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[,p="",b=""]=String(t).match(/^data:([^,]*),(.*)$/)||[],M=/;base64/i.test(p)?atob(b):decodeURIComponent(b),l=new Uint8Array([...M].map(y=>y.charCodeAt(0))),g=new Blob([l],{type:(p||"").split(";")[0]||""});return{ok:!0,data:g,status:200,url:t,fromCache:!1,mime:g.type||""}}catch{return{ok:!1,data:null,status:0,url:t,fromCache:!1,reason:"special_url_error"}}if(/^blob:/i.test(t))try{let p=await fetch(t);if(!p.ok)return{ok:!1,data:null,status:p.status,url:t,fromCache:!1,reason:"http_error"};let b=await p.blob(),R=b.type||p.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await ft(b),status:p.status,url:t,fromCache:!1,mime:R}:n==="text"?{ok:!0,data:await b.text(),status:p.status,url:t,fromCache:!1,mime:R}:{ok:!0,data:b,status:p.status,url:t,fromCache:!1,mime:R}}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=Ut(t,{as:n,timeout:o,useProxy:c,errorTTL:r}),u=X.get(i);if(u&&u.until>Date.now())return{...u.result,fromCache:!0};u&&X.delete(i);let m=Y.get(i);if(m)return m;let d=Et(t,c)?It(t,c):t,h=e.credentials;if(!h)try{let p=typeof location<"u"&&location.href?location.href:"http://localhost/",b=new URL(t,p);h=typeof location<"u"&&b.origin===location.origin?"include":"omit"}catch{h="omit"}let C=new AbortController,A=setTimeout(()=>C.abort("timeout"),o),w=(async()=>{try{let p=await fetch(d,{signal:C.signal,credentials:h,headers:s});if(!p.ok){let M={ok:!1,data:null,status:p.status,url:d,fromCache:!1,reason:"http_error"};if(r>0&&X.set(i,{until:Date.now()+r,result:M}),!a){let l=`${p.status} ${p.statusText||""}`.trim();lt.warnOnce(`http:${p.status}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,`HTTP error ${l} while fetching ${n} ${t}`)}return e.onError&&e.onError(M),M}if(n==="text")return{ok:!0,data:await p.text(),status:p.status,url:d,fromCache:!1};let b=await p.blob(),R=b.type||p.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await ft(b),status:p.status,url:d,fromCache:!1,mime:R}:{ok:!0,data:b,status:p.status,url:d,fromCache:!1,mime:R}}catch(p){let b=p&&typeof p=="object"&&"name"in p&&p.name==="AbortError"?String(p.message||"").includes("timeout")?"timeout":"abort":"network",R={ok:!1,data:null,status:0,url:d,fromCache:!1,reason:b};if(!/^blob:/i.test(t)&&r>0&&X.set(i,{until:Date.now()+r,result:R}),!a){let M=`${b}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,l=b==="timeout"?`Timeout after ${o}ms. Consider increasing timeout or using a proxy for ${t}`:b==="abort"?`Request aborted while fetching ${n} ${t}`:`Network/CORS issue while fetching ${n} ${t}. A proxy may be required`;lt.errorOnce(M,l)}return e.onError&&e.onError(R),R}finally{clearTimeout(A),Y.delete(i)}})();return Y.set(i,w),w}async function Q(t,e={}){if(/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t)||t.trim()==="none")return t;let o=at(t,typeof devicePixelRatio<"u"&&devicePixelRatio||1)??z(t);if(!o)return t;let c=ct(o),r=q(c),s=(e.useProxy||"")+"|"+r;if(f.background.has(s)){let a=f.background.get(s);return a?`url("${a}")`:"none"}try{let a=await U(r,{as:"dataURL",useProxy:e.useProxy});return a.ok?(f.background.set(s,a.data),`url("${a.data}")`):(f.background.set(s,null),"none")}catch{return f.background.set(s,null),"none"}}var mt=new Set(["meta","script","noscript","title","link","template"]),J=new Set(["meta","link","style","title","noscript","script","template","g","defs","use","marker","mask","clipPath","pattern","symbol","path","polygon","polyline","line","circle","ellipse","rect","filter","lineargradient","radialgradient","stop"]),vt=["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 Z(){for(let t of vt){let e=String(t).toLowerCase();mt.has(e)||J.has(e)||dt(e)}}function dt(t){if(t=String(t).toLowerCase(),J.has(t)){let r={};return f.defaultStyle.set(t,r),r}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),c={};for(let r of o){if(pt(r))continue;let s=o.getPropertyValue(r);c[r]=s}return e.removeChild(n),f.defaultStyle.set(t,c),c}var Tt=/(?:^|-)(animation|transition)(?:-|$)/i,Ot=/^(--.+|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,Pt=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","stroke-color"]),ut=new Map;function pt(t){let e=ut.get(t);if(e===void 0){let n=String(t).toLowerCase();e=Pt.has(n)||Ot.test(n)||Tt.test(n),ut.set(t,e)}return e}function Wt(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 r={length:0,getPropertyValue:()=>"",item:()=>""};return r[Symbol.iterator]=function*(){},r};if(t?.nodeType!==1){let r=typeof window<"u"?window:null;if(r&&typeof r.getComputedStyle=="function")try{return r.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 c=o.get(e);if(!c){let r=Wt(t),s=null;try{s=r&&typeof r.getComputedStyle=="function"?r.getComputedStyle(t,e):null}catch{}if(!s&&typeof window<"u"&&typeof window.getComputedStyle=="function")try{t.ownerDocument===document&&(s=window.getComputedStyle(t,e))}catch{}c=s||n(),o.set(e,c)}return c}function tt(t=1e3){return typeof requestAnimationFrame!="function"||typeof document<"u"&&document.visibilityState==="hidden"?Promise.resolve():new Promise(e=>{let n=!1,o=()=>{n||(n=!0,e())};try{requestAnimationFrame(o)}catch{o();return}setTimeout(o,t)})}function V(){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),c=/mobile/i.test(t),r=!/safari/i.test(t),s=o&&c&&r,a=/(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||s||a||i||u}var Dt=[/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],_e=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__||{}),Bt=[];function T(t){let e=typeof t=="string"?t:"",n=[...Dt,...Bt];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))}function et(t){if(typeof t!="string"||!t)return!1;let e;try{e=new URL(t,typeof location<"u"?location.href:void 0)}catch{return T(t)}let n=e.searchParams.getAll("family").flatMap(o=>o.split("|")).map(o=>o.split(":")[0].trim()).filter(Boolean);return n.length?n.every(o=>T(o)):T(t)}var wt=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]),Nt=["katex","mathjax","mathml"];function rt(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!wt.has(n.toLowerCase()))return n}return""}function qt(t){if(!t)return[];let e=[];for(let n of t.split(",")){let o=n.trim().replace(/^['"]+|['"]+$/g,"");o&&(wt.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 K(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 jt(t){let e=String(t||"400").trim(),n=e.match(/^(\d{2,3})\s+(\d{2,3})$/);if(n){let c=G(n[1]),r=G(n[2]);return{min:Math.min(c,r),max:Math.max(c,r)}}let o=G(e);return{min:o,max:o}}function zt(t){let e=String(t||"normal").trim().toLowerCase();return e==="italic"?{kind:"italic"}:e.startsWith("oblique")?{kind:"oblique"}:{kind:"normal"}}function Xt(t){let e=String(t||"100%").trim(),n=e.match(/(\d+(?:\.\d+)?)\s*%\s+(\d+(?:\.\d+)?)\s*%/);if(n){let r=parseFloat(n[1]),s=parseFloat(n[2]);return{min:Math.min(r,s),max:Math.max(r,s)}}let o=e.match(/(\d+(?:\.\d+)?)\s*%/),c=o?parseFloat(o[1]):100;return{min:c,max:c}}function Gt(t){return!t||typeof t!="string"?"":t.replace(/\s+(variable|vf|v[0-9]+)$/i,"").trim().toLowerCase().replace(/\s+/g,"-")}function Kt(t,e,n=[]){if(!t)return!1;try{let o=new URL(t,location.href);if(o.origin===location.origin)return!0;let r=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=>r.endsWith(i))||n.some(i=>r===i.toLowerCase()||r.endsWith("."+i.toLowerCase())))return!0;let a=(o.pathname+o.search).toLowerCase();if(/\bfont(s)?\b/.test(a)||/\.woff2?(\b|$)/.test(a)||Nt.some(i=>a.includes(i)))return!0;for(let i of e){let u=i.toLowerCase().replace(/\s+/g,"+"),m=i.toLowerCase().replace(/\s+/g,"-"),d=Gt(i);if(a.includes(u)||a.includes(m)||d&&a.includes(d))return!0}return!1}catch{return!1}}function Ht(t){let e=new Set;for(let n of t||[]){let o=String(n).split("__")[0]?.trim();o&&e.add(o)}return e}function ht(t,e){return t&&t.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/g,(n,o,c)=>{let r=(c||"").trim();if(!r||/^data:|^blob:|^https?:|^file:|^about:/i.test(r))return n;let s=r;try{s=new URL(r,e||location.href).href}catch{}return`url("${s}")`})}var nt=/@import\s+(?:url\(\s*(['"]?)([^)"']+)\1\s*\)|(['"])([^"']+)\3)([^;]*);/g,H=4;async function Yt(t,e,n){if(!t)return t;let o=new Set;function c(a,i){try{return new URL(a,i||location.href).href}catch{return a}}async function r(a,i,u=0){if(u>H)return console.warn(`[snapDOM] @import depth exceeded (${H}) at ${i}`),a;let m="",d=0,h;for(;h=nt.exec(a);){m+=a.slice(d,h.index),d=nt.lastIndex;let C=(h[2]||h[4]||"").trim(),A=c(C,i);if(o.has(A)){console.warn(`[snapDOM] Skipping circular @import: ${A}`);continue}o.add(A);let w="";try{let p=await U(A,{as:"text",useProxy:n,silent:!0});p.ok&&typeof p.data=="string"&&(w=p.data)}catch{}w?(w=ht(w,A),w=await r(w,A,u+1),m+=`
|
|
8
8
|
/* inlined: ${A} */
|
|
9
9
|
${w}
|
|
10
|
-
`):m+=h[0]}return m+=a.slice(d),m}let s=pt(t,e||location.href);return s=await r(s,e||location.href,0),s}var wt=/url\((["']?)([^"')]+)\1\)/g,Yt=/@font-face[^{}]*\{[^}]*\}/g;function I(t,e,n=""){return(t.match(new RegExp(`${e}\\s*:\\s*([^;}]+)[;}]`,"i"))?.[1]||n).trim()}function St(t){if(!t)return[];let e=[],n=t.split(",").map(o=>o.trim()).filter(Boolean);for(let o of n){let c=o.match(/^U\+([0-9A-Fa-f?]+)(?:-([0-9A-Fa-f?]+))?$/);if(!c)continue;let r=c[1],s=c[2],a=i=>{if(!i.includes("?"))return parseInt(i,16);let u=parseInt(i.replace(/\?/g,"0"),16),m=parseInt(i.replace(/\?/g,"F"),16);return[u,m]};if(s){let i=a(r),u=a(s),m=Array.isArray(i)?i[0]:i,d=Array.isArray(u)?u[1]:u;e.push([Math.min(m,d),Math.max(m,d)])}else{let i=a(r);Array.isArray(i)?e.push([i[0],i[1]]):e.push([i,i])}}return e}function bt(t,e){if(!e.length||!t||t.size===0)return!0;for(let n of t)for(let[o,c]of e)if(n>=o&&n<=c)return!0;return!1}function rt(t,e){let n=[];if(!t)return n;for(let o of t.matchAll(wt)){let c=(o[2]||"").trim();if(!(!c||c.startsWith("data:"))){if(!/^https?:/i.test(c))try{c=new URL(c,e||location.href).href}catch{}n.push(c)}}return n}async function nt(t,e,n=""){let o=t;for(let c of t.matchAll(wt)){let r=z(c[0]);if(!r)continue;let s=r;if(!s.startsWith("http")&&!s.startsWith("data:"))try{s=new URL(s,e||location.href).href}catch{}if(!v(s)){if(f.resource?.has(s)){f.font?.add(s),o=o.replace(c[0],`url(${f.resource.get(s)})`);continue}try{let a=await U(s,{as:"dataURL",useProxy:n,silent:!0});if(a.ok&&typeof a.data=="string"){let i=a.data;f.resource?.set(s,i),f.font?.add(s),o=o.replace(c[0],`url(${i})`)}}catch{console.warn("[snapDOM] Failed to fetch font resource:",s)}}}return o}function Qt(t){if(!t.length)return null;let e=(a,i)=>t.some(([u,m])=>!(m<a||u>i)),n=e(0,255)||e(305,305),o=e(256,591)||e(7680,7935),c=e(880,1023),r=e(1024,1279);return e(7840,7929)||e(258,259)||e(416,417)||e(431,432)?"vietnamese":r?"cyrillic":c?"greek":o?"latin-ext":n?"latin":null}function ht(t={}){let e=new Set((t.families||[]).map(c=>String(c).toLowerCase())),n=new Set((t.domains||[]).map(c=>String(c).toLowerCase())),o=new Set((t.subsets||[]).map(c=>String(c).toLowerCase()));return(c,r)=>{if(e.size&&e.has(c.family.toLowerCase()))return!0;if(n.size)for(let s of c.srcUrls)try{if(n.has(new URL(s).host.toLowerCase()))return!0}catch{}if(o.size){let s=Qt(r);if(s&&o.has(s))return!0}return!1}}function Jt(t){if(!t)return t;let e=/@font-face[^{}]*\{[^}]*\}/gi,n=new Set,o=[];for(let r of t.match(e)||[]){let s=I(r,"font-family"),a=ot(s),i=I(r,"font-weight","400"),u=I(r,"font-style","normal"),m=I(r,"font-stretch","100%"),d=I(r,"unicode-range"),h=I(r,"src"),C=rt(h,location.href),A=C.length?C.map(p=>String(p).toLowerCase()).sort().join("|"):h.toLowerCase(),w=[String(a||"").toLowerCase(),i,u,m,d.toLowerCase(),A].join("|");n.has(w)||(n.add(w),o.push(r))}if(o.length===0)return t;let c=0;return t.replace(e,()=>o[c++]||"")}var gt=new WeakMap,Zt=0;function te(t){let e=gt.get(t);return e===void 0&&(e=Zt++,gt.set(t,e)),e}function ee(t,e,n,o,c,r){let s=Array.from(t||[]).sort().join("|"),a=e?JSON.stringify({families:(e.families||[]).map(h=>String(h).toLowerCase()).sort(),domains:(e.domains||[]).map(h=>String(h).toLowerCase()).sort(),subsets:(e.subsets||[]).map(h=>String(h).toLowerCase()).sort()}):"",i=(n||[]).map(h=>`${(h.family||"").toLowerCase()}::${h.weight||"normal"}::${h.style||"normal"}::${h.src||""}`).sort().join("|"),u=o||"",m=(c||[]).map(h=>String(h).toLowerCase()).sort().join("|"),d=te(r||document);return`fonts-embed-css::req=${s}::ex=${a}::lf=${i}::px=${u}::fd=${m}::doc=${d}`}async function xt(t,e,n,o){let c;try{c=t.cssRules||[]}catch{return}let r=(s,a)=>{try{return new URL(s,a||location.href).href}catch{return s}};for(let s of c){if(s.type===CSSRule.IMPORT_RULE&&s.styleSheet){let a=s.href?r(s.href,e):e;if(o.depth>=H){console.warn(`[snapDOM] CSSOM import depth exceeded (${H}) at ${a}`);continue}if(a&&o.visitedSheets.has(a)){console.warn(`[snapDOM] Skipping circular CSSOM import: ${a}`);continue}a&&o.visitedSheets.add(a);let i={...o,depth:(o.depth||0)+1};await xt(s.styleSheet,a,n,i);continue}if(s.type===CSSRule.FONT_FACE_RULE){let a=(s.style.getPropertyValue("font-family")||"").trim(),i=ot(a);if(!i||v(i))continue;let u=(s.style.getPropertyValue("font-weight")||"").trim(),m=(s.style.getPropertyValue("font-style")||"").trim(),d=(s.style.getPropertyValue("font-stretch")||"").trim(),h=(s.style.getPropertyValue("font-variation-settings")||"").trim(),C=(s.style.getPropertyValue("src")||"").trim(),A=(s.style.getPropertyValue("unicode-range")||"").trim(),w=u||"400",p=m||"normal",b=d||"100%",R=(m?`font-style:${m};`:"")+(u?`font-weight:${u};`:"")+(d?`font-stretch:${d};`:"")+(h?`font-variation-settings:${h};`:"")+(A?`unicode-range:${A};`:""),M=o.faceMatchesRequired(i,p,w,b);if(!M&&!o.requiredIndex.has(i.toLowerCase()))continue;let l=St(A);if(!bt(o.usedCodepoints,l))continue;let g={family:i,weightSpec:w,styleSpec:p,stretchSpec:b,unicodeRange:A,srcRaw:C,srcUrls:rt(C,e||location.href),href:e||location.href};if(o.simpleExcluder&&o.simpleExcluder(g,l))continue;if(!M){o.provisionalFaces.push({family:i.toLowerCase(),block:`@font-face{font-family:${i};src:${C};${R}}`,srcRaw:C,baseHref:e||location.href});continue}if(o.coveredFamilies.add(i.toLowerCase()),/url\(/i.test(C)){let y=await nt(C,e||location.href,o.useProxy);await n(`@font-face{font-family:${i};src:${y};${R}}`)}else await n(`@font-face{font-family:${i};src:${C};${R}}`)}}}async function Ct({required:t,usedCodepoints:e,exclude:n=void 0,localFonts:o=[],useProxy:c="",fontStylesheetDomains:r=[],doc:s=document}={}){t instanceof Set||(t=new Set),e instanceof Set||(e=new Set);let a=new Map;for(let l of t){let[g,y,L,S]=String(l).split("__");if(!g)continue;let k=g.toLowerCase(),x=a.get(k)||[];x.push({w:parseInt(y,10),s:L,st:parseInt(S,10)}),a.set(k,x)}function i(l,g,y,L){let S=String(l).toLowerCase();if(!a.has(S))return!1;let k=a.get(S),x=Vt(y),F=jt(g),T=zt(L),W=x.min!==x.max,D=x.min,O=$=>F.kind==="normal"&&$==="normal"||F.kind!=="normal"&&($==="italic"||$==="oblique"),j=!1;for(let $ of k){let E=W?$.w>=x.min&&$.w<=x.max:$.w===D,P=O(K($.s)),B=$.st>=T.min&&$.st<=T.max;if(E&&P&&B){j=!0;break}}if(j)return!0;if(!W)for(let $ of k){let E=O(K($.s)),P=$.st>=T.min&&$.st<=T.max;if(Math.abs(D-$.w)<=300&&E&&P)return!0}if(!W&&F.kind==="normal"&&k.some(E=>K(E.s)!=="normal"))for(let E of k){let P=Math.abs(D-E.w)<=300,B=E.st>=T.min&&E.st<=T.max;if(P&&B)return!0}return!1}let u=ht(n),m=ee(t,n,o,c,r,s);if(f.resource?.has(m))return f.resource.get(m);let d=Kt(t),h=[],C=et;for(let l of s.querySelectorAll("style")){let g=l.textContent||"";for(let y of g.matchAll(C)){let L=(y[2]||y[4]||"").trim();if(!L||v(L))continue;s.querySelector(`link[rel="stylesheet"][href="${L}"]`)||h.push(L)}}let A=[];h.length&&await Promise.all(h.map(l=>new Promise(g=>{if(s.querySelector(`link[rel="stylesheet"][href="${l}"]`))return g(null);let y=s.createElement("link");y.rel="stylesheet",y.href=l,y.setAttribute("data-snapdom","injected-import"),y.onload=()=>g(y),y.onerror=()=>g(null),s.head.appendChild(y),A.push(y)})));let w="",p=new Set,b=[],R=Array.from(s.querySelectorAll('link[rel="stylesheet"]')).filter(l=>!!l.href);for(let l of A)try{l.remove()}catch{}for(let l of R)try{if(v(l.href))continue;let g="",y=!1;try{y=new URL(l.href,location.href).origin===location.origin}catch{}if(!y){let S=Array.isArray(r)?r:[];if(!Gt(l.href,d,S))continue}if(y){let S=Array.from(s.styleSheets).find(k=>k.href===l.href);if(S)try{let k=S.cssRules||[];g=Array.from(k).map(x=>x.cssText).join("")}catch{}}if(!g){let S=await U(l.href,{as:"text",useProxy:c});if(S?.ok&&typeof S.data=="string"&&(g=S.data),v(l.href))continue}g=await Ht(g,l.href,c);let L="";for(let S of g.match(Yt)||[]){let k=I(S,"font-family"),x=ot(k);if(!x||v(x))continue;let F=I(S,"font-weight","400"),T=I(S,"font-style","normal"),W=I(S,"font-stretch","100%"),D=I(S,"unicode-range"),O=I(S,"src"),j=rt(O,l.href),$=i(x,T,F,W);if(!$&&!a.has(x.toLowerCase()))continue;let E=St(D);if(!bt(e,E))continue;let P={family:x,weightSpec:F,styleSpec:T,stretchSpec:W,unicodeRange:D,srcRaw:O,srcUrls:j,href:l.href};if(n&&u(P,E))continue;if(!$){b.push({family:x.toLowerCase(),block:S,srcRaw:O,baseHref:l.href});continue}p.add(x.toLowerCase());let B=/url\(/i.test(O)?await nt(S,l.href,c):S;L+=B}L.trim()&&(w+=L)}catch{console.warn("[snapDOM] Failed to process stylesheet:",l.href)}let M={requiredIndex:a,usedCodepoints:e,faceMatchesRequired:i,coveredFamilies:p,provisionalFaces:b,simpleExcluder:n?ht(n):null,useProxy:c,visitedSheets:new Set,depth:0};for(let l of s.styleSheets)if(!(l.href&&R.some(g=>g.href===l.href)))try{let g=l.href||location.origin+"/";g&&M.visitedSheets.add(g),await xt(l,g,async y=>{w+=y},M)}catch{}for(let l of b)p.has(l.family)||(w+=/url\(/i.test(l.srcRaw)?await nt(l.block,l.baseHref,c):l.block);try{for(let l of s.fonts||[]){if(!l||!l.family||l.status!=="loaded"||!l._snapdomSrc)continue;let g=String(l.family).replace(/^['"]+|['"]+$/g,"");if(v(g)||!a.has(g.toLowerCase())||n?.families&&n.families.some(L=>String(L).toLowerCase()===g.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 L=await U(l._snapdomSrc,{as:"dataURL",useProxy:c,silent:!0});if(L.ok&&typeof L.data=="string")y=L.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}}w+=`@font-face{font-family:'${g}';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 g=String(l.family||"").replace(/^['"]+|['"]+$/g,"");if(!g||v(g)||!a.has(g.toLowerCase())||n?.families&&n.families.some(F=>String(F).toLowerCase()===g.toLowerCase()))continue;let y=l.weight!=null?String(l.weight):"normal",L=l.style!=null?String(l.style):"normal",S=l.stretchPct!=null?`${l.stretchPct}%`:"100%",k=String(l.src||""),x=k;if(!x.startsWith("data:")){if(f.resource?.has(k))x=f.resource.get(k),f.font?.add(k);else if(!f.font?.has(k))try{let F=await U(k,{as:"dataURL",useProxy:c,silent:!0});if(F.ok&&typeof F.data=="string")x=F.data,f.resource?.set(k,x),f.font?.add(k);else continue}catch{console.warn("[snapDOM] Failed to fetch localFonts src:",k);continue}}w+=`@font-face{font-family:'${g}';src:url(${x});font-style:${L};font-weight:${y};font-stretch:${S};}`}return w&&(w=Jt(w),f.resource?.set(m,w)),w}function kt(t,e){let n=new Set,o=new Set;if(!t)return{required:n,usedCodepoints:o};let c=i=>{if(i)for(let u of i)o.add(u.codePointAt(0))},r=i=>{let u=Nt(i.fontFamily);if(u.length)for(let m of u)n.add(`${m}__${G(i.fontWeight)}__${K(i.fontStyle)}__${qt(i.fontStretch)}`)},s=i=>{r(N(i));for(let u of["::before","::after"]){let m=N(i,u),d=m&&m.content;if(!(!d||d==="none"||d==="normal"))if(r(m),/^["']/.test(d))c(d.slice(1,-1));else{let h=d.match(/\\[0-9A-Fa-f]{1,6}/g);if(h)for(let C of h)try{o.add(parseInt(C.slice(1),16))}catch{}}}};s(t);let a=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,null);for(;a.nextNode();){let i=a.currentNode;if(i.nodeType===Node.TEXT_NODE){if(e&&i.parentElement&&!e(i.parentElement))continue;c(i.nodeValue||"")}else{if(e&&!e(i))continue;s(i)}}return{required:n,usedCodepoints:o}}async function At(t,e=2,n=document){try{await n.fonts.ready}catch{}let o=Array.from(t||[]).filter(Boolean);if(o.length===0)return;let c=()=>{let r=n.createElement("div");r.setAttribute("data-snapdom-internal",""),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 s of o){let a=n.createElement("span");a.textContent="AaBbGg1234\xC1\xC9\xCD\xD3\xDA\xE7\xF1\u2014\u221E",a.style.fontFamily=`"${s}"`,a.style.fontWeight="700",a.style.fontStyle="italic",a.style.fontSize="32px",a.style.lineHeight="1",a.style.whiteSpace="nowrap",a.style.margin="0",a.style.padding="0",r.appendChild(a)}n.body.appendChild(r),r.offsetWidth,n.body.removeChild(r)};for(let r=0;r<Math.max(1,e);r++)c(),await tt(),await tt()}var Lt=["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"];async function Ve(t=document,e={}){let{embedFonts:n=!0,useProxy:o=""}=e,c=e.cache??e.cacheOpt??"full";st(c);try{await document.fonts?.ready}catch{}try{Z()}catch{}f.session=f.session||{},f.session.styleCache||(f.session.styleCache=new WeakMap),f.image=f.image||new _(100),f.background=f.background||new _(100);let r=[],s=[];try{if(t&&t.nodeType===1){let i=t.querySelectorAll?Array.from(t.querySelectorAll("*")):[];s=[t,...i],r=[],t.tagName==="IMG"&&t.getAttribute("src")&&r.push(t),r.push(...Array.from(t.querySelectorAll?.("img[src]")||[]))}else t?.querySelectorAll&&(r=Array.from(t.querySelectorAll("img[src]")),s=Array.from(t.querySelectorAll("*")))}catch{}let a=[];for(let i of r){let u=i?.currentSrc||i?.src;if(u&&!f.image.has(u)){let m=Promise.resolve().then(async()=>{let d=await U(u,{as:"dataURL",useProxy:o});d?.ok&&typeof d.data=="string"&&f.image.set(u,d.data)}).catch(()=>{});a.push(m)}}for(let i of s){let u=new Set;for(let m of Lt){let d="";try{d=m==="background-image"&&i?.style?.backgroundImage||N(i).getPropertyValue(m)||""}catch{}if(!d||d==="none")continue;let h=d.match(/url\((?:[^()"']+|"(?:[^"]*)"|'(?:[^']*)')\)/gi)||[];for(let C of h){if(u.has(C))continue;u.add(C);let A=Promise.resolve().then(()=>Q(C,{...e,useProxy:o})).catch(()=>{});a.push(A)}}}if(n)try{let{required:i,usedCodepoints:u}=kt(t);if(typeof V=="function"?V():!!V){let d=new Set(Array.from(i).map(h=>String(h).split("__")[0]).filter(Boolean));await At(d,3)}await Ct({required:i,usedCodepoints:u,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:e.useProxy??o,fontStylesheetDomains:e.fontStylesheetDomains})}catch{}await Promise.allSettled(a)}export{Ve as preCache};
|
|
10
|
+
`):m+=h[0]}return m+=a.slice(d),m}let s=ht(t,e||location.href);return s=await r(s,e||location.href,0),s}var St=/url\((["']?)([^"')]+)\1\)/g,Qt=/@font-face[^{}]*\{[^}]*\}/g;function I(t,e,n=""){return(t.match(new RegExp(`${e}\\s*:\\s*([^;}]+)[;}]`,"i"))?.[1]||n).trim()}function bt(t){if(!t)return[];let e=[],n=t.split(",").map(o=>o.trim()).filter(Boolean);for(let o of n){let c=o.match(/^U\+([0-9A-Fa-f?]+)(?:-([0-9A-Fa-f?]+))?$/);if(!c)continue;let r=c[1],s=c[2],a=i=>{if(!i.includes("?"))return parseInt(i,16);let u=parseInt(i.replace(/\?/g,"0"),16),m=parseInt(i.replace(/\?/g,"F"),16);return[u,m]};if(s){let i=a(r),u=a(s),m=Array.isArray(i)?i[0]:i,d=Array.isArray(u)?u[1]:u;e.push([Math.min(m,d),Math.max(m,d)])}else{let i=a(r);Array.isArray(i)?e.push([i[0],i[1]]):e.push([i,i])}}return e}function xt(t,e){if(!e.length||!t||t.size===0)return!0;for(let n of t)for(let[o,c]of e)if(n>=o&&n<=c)return!0;return!1}function st(t,e){let n=[];if(!t)return n;for(let o of t.matchAll(St)){let c=(o[2]||"").trim();if(!(!c||c.startsWith("data:"))){if(!/^https?:/i.test(c))try{c=new URL(c,e||location.href).href}catch{}n.push(c)}}return n}async function ot(t,e,n=""){let o=t;for(let c of t.matchAll(St)){let r=z(c[0]);if(!r)continue;let s=r;if(!s.startsWith("http")&&!s.startsWith("data:"))try{s=new URL(s,e||location.href).href}catch{}if(!T(s)){if(f.resource?.has(s)){f.font?.add(s),o=o.replace(c[0],`url(${f.resource.get(s)})`);continue}try{let a=await U(s,{as:"dataURL",useProxy:n,silent:!0});if(a.ok&&typeof a.data=="string"){let i=a.data;f.resource?.set(s,i),f.font?.add(s),o=o.replace(c[0],`url(${i})`)}}catch{console.warn("[snapDOM] Failed to fetch font resource:",s)}}}return o}function Jt(t){if(!t.length)return null;let e=(a,i)=>t.some(([u,m])=>!(m<a||u>i)),n=e(0,255)||e(305,305),o=e(256,591)||e(7680,7935),c=e(880,1023),r=e(1024,1279);return e(7840,7929)||e(258,259)||e(416,417)||e(431,432)?"vietnamese":r?"cyrillic":c?"greek":o?"latin-ext":n?"latin":null}function gt(t={}){let e=new Set((t.families||[]).map(c=>String(c).toLowerCase())),n=new Set((t.domains||[]).map(c=>String(c).toLowerCase())),o=new Set((t.subsets||[]).map(c=>String(c).toLowerCase()));return(c,r)=>{if(e.size&&e.has(c.family.toLowerCase()))return!0;if(n.size)for(let s of c.srcUrls)try{if(n.has(new URL(s).host.toLowerCase()))return!0}catch{}if(o.size){let s=Jt(r);if(s&&o.has(s))return!0}return!1}}function Zt(t){if(!t)return t;let e=/@font-face[^{}]*\{[^}]*\}/gi,n=new Set,o=[];for(let r of t.match(e)||[]){let s=I(r,"font-family"),a=rt(s),i=I(r,"font-weight","400"),u=I(r,"font-style","normal"),m=I(r,"font-stretch","100%"),d=I(r,"unicode-range"),h=I(r,"src"),C=st(h,location.href),A=C.length?C.map(p=>String(p).toLowerCase()).sort().join("|"):h.toLowerCase(),w=[String(a||"").toLowerCase(),i,u,m,d.toLowerCase(),A].join("|");n.has(w)||(n.add(w),o.push(r))}if(o.length===0)return t;let c=0;return t.replace(e,()=>o[c++]||"")}var yt=new WeakMap,te=0;function ee(t){let e=yt.get(t);return e===void 0&&(e=te++,yt.set(t,e)),e}function ne(t,e,n,o,c,r){let s=Array.from(t||[]).sort().join("|"),a=e?JSON.stringify({families:(e.families||[]).map(h=>String(h).toLowerCase()).sort(),domains:(e.domains||[]).map(h=>String(h).toLowerCase()).sort(),subsets:(e.subsets||[]).map(h=>String(h).toLowerCase()).sort()}):"",i=(n||[]).map(h=>`${(h.family||"").toLowerCase()}::${h.weight||"normal"}::${h.style||"normal"}::${h.src||""}`).sort().join("|"),u=o||"",m=(c||[]).map(h=>String(h).toLowerCase()).sort().join("|"),d=ee(r||document);return`fonts-embed-css::req=${s}::ex=${a}::lf=${i}::px=${u}::fd=${m}::doc=${d}`}async function Ct(t,e,n,o){let c;try{c=t.cssRules||[]}catch{return}let r=(s,a)=>{try{return new URL(s,a||location.href).href}catch{return s}};for(let s of c){if(s.type===CSSRule.IMPORT_RULE&&s.styleSheet){let a=s.href?r(s.href,e):e;if(o.depth>=H){console.warn(`[snapDOM] CSSOM import depth exceeded (${H}) at ${a}`);continue}if(a&&o.visitedSheets.has(a)){console.warn(`[snapDOM] Skipping circular CSSOM import: ${a}`);continue}a&&o.visitedSheets.add(a);let i={...o,depth:(o.depth||0)+1};await Ct(s.styleSheet,a,n,i);continue}if(s.type===CSSRule.FONT_FACE_RULE){let a=(s.style.getPropertyValue("font-family")||"").trim(),i=rt(a);if(!i||T(i))continue;let u=(s.style.getPropertyValue("font-weight")||"").trim(),m=(s.style.getPropertyValue("font-style")||"").trim(),d=(s.style.getPropertyValue("font-stretch")||"").trim(),h=(s.style.getPropertyValue("font-variation-settings")||"").trim(),C=(s.style.getPropertyValue("src")||"").trim(),A=(s.style.getPropertyValue("unicode-range")||"").trim(),w=u||"400",p=m||"normal",b=d||"100%",R=(m?`font-style:${m};`:"")+(u?`font-weight:${u};`:"")+(d?`font-stretch:${d};`:"")+(h?`font-variation-settings:${h};`:"")+(A?`unicode-range:${A};`:""),M=o.faceMatchesRequired(i,p,w,b);if(!M&&!o.requiredIndex.has(i.toLowerCase()))continue;let l=bt(A);if(!xt(o.usedCodepoints,l))continue;let g={family:i,weightSpec:w,styleSpec:p,stretchSpec:b,unicodeRange:A,srcRaw:C,srcUrls:st(C,e||location.href),href:e||location.href};if(o.simpleExcluder&&o.simpleExcluder(g,l))continue;if(!M){o.provisionalFaces.push({family:i.toLowerCase(),block:`@font-face{font-family:${i};src:${C};${R}}`,srcRaw:C,baseHref:e||location.href});continue}if(o.coveredFamilies.add(i.toLowerCase()),/url\(/i.test(C)){let y=await ot(C,e||location.href,o.useProxy);await n(`@font-face{font-family:${i};src:${y};${R}}`)}else await n(`@font-face{font-family:${i};src:${C};${R}}`)}}}async function kt({required:t,usedCodepoints:e,exclude:n=void 0,localFonts:o=[],useProxy:c="",fontStylesheetDomains:r=[],doc:s=document}={}){t instanceof Set||(t=new Set),e instanceof Set||(e=new Set);let a=new Map;for(let l of t){let[g,y,L,S]=String(l).split("__");if(!g)continue;let k=g.toLowerCase(),x=a.get(k)||[];x.push({w:parseInt(y,10),s:L,st:parseInt(S,10)}),a.set(k,x)}function i(l,g,y,L){let S=String(l).toLowerCase();if(!a.has(S))return!1;let k=a.get(S),x=jt(y),F=zt(g),v=Xt(L),W=x.min!==x.max,D=x.min,O=$=>F.kind==="normal"&&$==="normal"||F.kind!=="normal"&&($==="italic"||$==="oblique"),j=!1;for(let $ of k){let E=W?$.w>=x.min&&$.w<=x.max:$.w===D,P=O(K($.s)),B=$.st>=v.min&&$.st<=v.max;if(E&&P&&B){j=!0;break}}if(j)return!0;if(!W)for(let $ of k){let E=O(K($.s)),P=$.st>=v.min&&$.st<=v.max;if(Math.abs(D-$.w)<=300&&E&&P)return!0}if(!W&&F.kind==="normal"&&k.some(E=>K(E.s)!=="normal"))for(let E of k){let P=Math.abs(D-E.w)<=300,B=E.st>=v.min&&E.st<=v.max;if(P&&B)return!0}return!1}let u=gt(n),m=ne(t,n,o,c,r,s);if(f.resource?.has(m))return f.resource.get(m);let d=Ht(t),h=[],C=nt;for(let l of s.querySelectorAll("style")){let g=l.textContent||"";for(let y of g.matchAll(C)){let L=(y[2]||y[4]||"").trim();if(!L||et(L))continue;s.querySelector(`link[rel="stylesheet"][href="${L}"]`)||h.push(L)}}let A=[];h.length&&await Promise.all(h.map(l=>new Promise(g=>{if(s.querySelector(`link[rel="stylesheet"][href="${l}"]`))return g(null);let y=s.createElement("link");y.rel="stylesheet",y.href=l,y.setAttribute("data-snapdom","injected-import"),y.onload=()=>g(y),y.onerror=()=>g(null),s.head.appendChild(y),A.push(y)})));let w="",p=new Set,b=[],R=Array.from(s.querySelectorAll('link[rel="stylesheet"]')).filter(l=>!!l.href);for(let l of A)try{l.remove()}catch{}for(let l of R)try{if(et(l.href))continue;let g="",y=!1;try{y=new URL(l.href,location.href).origin===location.origin}catch{}if(!y){let S=Array.isArray(r)?r:[];if(!Kt(l.href,d,S))continue}if(y){let S=Array.from(s.styleSheets).find(k=>k.href===l.href);if(S)try{let k=S.cssRules||[];g=Array.from(k).map(x=>x.cssText).join("")}catch{}}if(!g){let S=await U(l.href,{as:"text",useProxy:c});S?.ok&&typeof S.data=="string"&&(g=S.data)}g=await Yt(g,l.href,c);let L="";for(let S of g.match(Qt)||[]){let k=I(S,"font-family"),x=rt(k);if(!x||T(x))continue;let F=I(S,"font-weight","400"),v=I(S,"font-style","normal"),W=I(S,"font-stretch","100%"),D=I(S,"unicode-range"),O=I(S,"src"),j=st(O,l.href),$=i(x,v,F,W);if(!$&&!a.has(x.toLowerCase()))continue;let E=bt(D);if(!xt(e,E))continue;let P={family:x,weightSpec:F,styleSpec:v,stretchSpec:W,unicodeRange:D,srcRaw:O,srcUrls:j,href:l.href};if(n&&u(P,E))continue;if(!$){b.push({family:x.toLowerCase(),block:S,srcRaw:O,baseHref:l.href});continue}p.add(x.toLowerCase());let B=/url\(/i.test(O)?await ot(S,l.href,c):S;L+=B}L.trim()&&(w+=L)}catch{console.warn("[snapDOM] Failed to process stylesheet:",l.href)}let M={requiredIndex:a,usedCodepoints:e,faceMatchesRequired:i,coveredFamilies:p,provisionalFaces:b,simpleExcluder:n?gt(n):null,useProxy:c,visitedSheets:new Set,depth:0};for(let l of s.styleSheets)if(!(l.href&&R.some(g=>g.href===l.href)))try{let g=l.href||location.origin+"/";g&&M.visitedSheets.add(g),await Ct(l,g,async y=>{w+=y},M)}catch{}for(let l of b)p.has(l.family)||(w+=/url\(/i.test(l.srcRaw)?await ot(l.block,l.baseHref,c):l.block);try{for(let l of s.fonts||[]){if(!l||!l.family||l.status!=="loaded"||!l._snapdomSrc)continue;let g=String(l.family).replace(/^['"]+|['"]+$/g,"");if(T(g)||!a.has(g.toLowerCase())||n?.families&&n.families.some(L=>String(L).toLowerCase()===g.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 L=await U(l._snapdomSrc,{as:"dataURL",useProxy:c,silent:!0});if(L.ok&&typeof L.data=="string")y=L.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}}w+=`@font-face{font-family:'${g}';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 g=String(l.family||"").replace(/^['"]+|['"]+$/g,"");if(!g||T(g)||!a.has(g.toLowerCase())||n?.families&&n.families.some(F=>String(F).toLowerCase()===g.toLowerCase()))continue;let y=l.weight!=null?String(l.weight):"normal",L=l.style!=null?String(l.style):"normal",S=l.stretchPct!=null?`${l.stretchPct}%`:"100%",k=String(l.src||""),x=k;if(!x.startsWith("data:")){if(f.resource?.has(k))x=f.resource.get(k),f.font?.add(k);else if(!f.font?.has(k))try{let F=await U(k,{as:"dataURL",useProxy:c,silent:!0});if(F.ok&&typeof F.data=="string")x=F.data,f.resource?.set(k,x),f.font?.add(k);else continue}catch{console.warn("[snapDOM] Failed to fetch localFonts src:",k);continue}}w+=`@font-face{font-family:'${g}';src:url(${x});font-style:${L};font-weight:${y};font-stretch:${S};}`}return w&&(w=Zt(w),f.resource?.set(m,w)),w}function At(t,e){let n=new Set,o=new Set;if(!t)return{required:n,usedCodepoints:o};let c=i=>{if(i)for(let u of i)o.add(u.codePointAt(0))},r=i=>{let u=qt(i.fontFamily);if(u.length)for(let m of u)n.add(`${m}__${G(i.fontWeight)}__${K(i.fontStyle)}__${Vt(i.fontStretch)}`)},s=i=>{r(N(i));for(let u of["::before","::after"]){let m=N(i,u),d=m&&m.content;if(!(!d||d==="none"||d==="normal"))if(r(m),/^["']/.test(d))c(d.slice(1,-1));else{let h=d.match(/\\[0-9A-Fa-f]{1,6}/g);if(h)for(let C of h)try{o.add(parseInt(C.slice(1),16))}catch{}}}};s(t);let a=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,null);for(;a.nextNode();){let i=a.currentNode;if(i.nodeType===Node.TEXT_NODE){if(e&&i.parentElement&&!e(i.parentElement))continue;c(i.nodeValue||"")}else{if(e&&!e(i))continue;s(i)}}return{required:n,usedCodepoints:o}}async function Lt(t,e=2,n=document){try{await n.fonts.ready}catch{}let o=Array.from(t||[]).filter(Boolean);if(o.length===0)return;let c=()=>{let r=n.createElement("div");r.setAttribute("data-snapdom-internal",""),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 s of o){let a=n.createElement("span");a.textContent="AaBbGg1234\xC1\xC9\xCD\xD3\xDA\xE7\xF1\u2014\u221E",a.style.fontFamily=`"${s}"`,a.style.fontWeight="700",a.style.fontStyle="italic",a.style.fontSize="32px",a.style.lineHeight="1",a.style.whiteSpace="nowrap",a.style.margin="0",a.style.padding="0",r.appendChild(a)}n.body.appendChild(r),r.offsetWidth,n.body.removeChild(r)};for(let r=0;r<Math.max(1,e);r++)c(),await tt(),await tt()}var Rt=["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"];async function je(t=document,e={}){let{embedFonts:n=!0,useProxy:o=""}=e,c=e.cache??e.cacheOpt??"full";it(c);try{await document.fonts?.ready}catch{}try{Z()}catch{}f.session=f.session||{},f.session.styleCache||(f.session.styleCache=new WeakMap),f.image=f.image||new _(100),f.background=f.background||new _(100);let r=[],s=[];try{if(t&&t.nodeType===1){let i=t.querySelectorAll?Array.from(t.querySelectorAll("*")):[];s=[t,...i],r=[],t.tagName==="IMG"&&t.getAttribute("src")&&r.push(t),r.push(...Array.from(t.querySelectorAll?.("img[src]")||[]))}else t?.querySelectorAll&&(r=Array.from(t.querySelectorAll("img[src]")),s=Array.from(t.querySelectorAll("*")))}catch{}let a=[];for(let i of r){let u=i?.currentSrc||i?.src;if(u&&!f.image.has(u)){let m=Promise.resolve().then(async()=>{let d=await U(u,{as:"dataURL",useProxy:o});d?.ok&&typeof d.data=="string"&&f.image.set(u,d.data)}).catch(()=>{});a.push(m)}}for(let i of s){let u=new Set;for(let m of Rt){let d="";try{d=m==="background-image"&&i?.style?.backgroundImage||N(i).getPropertyValue(m)||""}catch{}if(!d||d==="none")continue;let h=d.match(/url\((?:[^()"']+|"(?:[^"]*)"|'(?:[^']*)')\)/gi)||[];for(let C of h){if(u.has(C))continue;u.add(C);let A=Promise.resolve().then(()=>Q(C,{...e,useProxy:o})).catch(()=>{});a.push(A)}}}if(n)try{let{required:i,usedCodepoints:u}=At(t);if(typeof V=="function"?V():!!V){let d=new Set(Array.from(i).map(h=>String(h).split("__")[0]).filter(Boolean));await Lt(d,3)}await kt({required:i,usedCodepoints:u,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:e.useProxy??o,fontStylesheetDomains:e.fontStylesheetDomains})}catch{}await Promise.allSettled(a)}export{je as preCache};
|