@zumer/snapdom 2.18.0 → 2.23.0
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 +30 -2
- package/dist/plugins.mjs +1 -1
- package/dist/preCache.mjs +5 -5
- package/dist/snapdom.js +7 -7
- package/dist/snapdom.mjs +7 -7
- package/package.json +7 -4
- package/types/snapdom.d.ts +45 -12
package/README.md
CHANGED
|
@@ -191,6 +191,29 @@ const blob = await snapdom.toBlob(el);
|
|
|
191
191
|
document.body.appendChild(png);
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
+
## CORS & External Resources
|
|
195
|
+
|
|
196
|
+
When capturing elements that reference **external stylesheets** (e.g., Google Fonts, Font Awesome, or any CDN‑hosted CSS), you **must** ensure that the resources are served with proper CORS headers. Otherwise, the captured image may lack the expected fonts or icons, even though they render correctly in the browser.
|
|
197
|
+
|
|
198
|
+
### Why is this needed?
|
|
199
|
+
|
|
200
|
+
- Browsers block JavaScript (including SnapDOM) from reading the binary data of cross‑origin fonts or images unless the server explicitly allows it via `Access-Control-Allow-Origin`.
|
|
201
|
+
- SnapDOM relies on Canvas, which enforces strict CORS policies — unlike the browser's rendering engine, which is more permissive for on‑screen display.
|
|
202
|
+
|
|
203
|
+
### How to fix it
|
|
204
|
+
|
|
205
|
+
Add the `crossorigin="anonymous"` attribute to the `<link>` tag when loading external stylesheets:
|
|
206
|
+
|
|
207
|
+
```html
|
|
208
|
+
<link
|
|
209
|
+
rel="stylesheet"
|
|
210
|
+
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css"
|
|
211
|
+
crossorigin="anonymous"
|
|
212
|
+
/>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
> **Note**: If you are hosting the fonts or assets **on the same origin** as your page (e.g., using a local server like `http://localhost`), you **do not** need to add `crossorigin` – the browser treats them as same‑origin and allows full access.
|
|
216
|
+
|
|
194
217
|
## Documentation
|
|
195
218
|
|
|
196
219
|
The full reference lives on **[snapdom.dev/docs](https://snapdom.dev/docs/)** — kept there so it stays in sync and searchable:
|
|
@@ -243,6 +266,9 @@ All options are optional and can be passed to `snapdom(el, options)` or any shor
|
|
|
243
266
|
| `outerTransforms` | `boolean` | `true` | Keep root translate/rotate in the output |
|
|
244
267
|
| `outerShadows` | `boolean` | `false` | Expand bounds to include root shadows/blur/outline |
|
|
245
268
|
| `fast` | `boolean` | `true` | Skip idle delays for faster capture |
|
|
269
|
+
| `reconcile` | `boolean` | `false` | Measure the clone against the live DOM and pin any diverging box to its real size. Fixes rare text re-wrap/layout drift at the cost of roughly doubling capture time — snapdom warns once (`console.warn`) if it detects a capture that could benefit from it |
|
|
270
|
+
| `burst` | `boolean` | `false` | Memoizes repeated captures of this element via a scoped MutationObserver — an unchanged repeat skips the pipeline entirely. Without it, snapdom warns once if the same element is captured 3+ times within 2s |
|
|
271
|
+
| `invalidate` | `boolean` | `false` | With `burst: true`, forces a fresh capture for changes automatic tracking can't see (canvas draws, programmatic CSSOM edits) |
|
|
246
272
|
| `plugins` | `array` | — | Per-capture plugins (override globals by name) |
|
|
247
273
|
|
|
248
274
|
📖 **[Full API & every option, explained with examples → snapdom.dev/docs](https://snapdom.dev/docs/)**
|
|
@@ -346,13 +372,13 @@ For detailed guidelines, see [CONTRIBUTING](https://github.com/zumerlab/snapdom/
|
|
|
346
372
|
<a href="https://github.com/stypr" title="stypr"><img src="https://avatars.githubusercontent.com/u/6625978?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="stypr"/></a>
|
|
347
373
|
<a href="https://github.com/mon-jai" title="mon-jai"><img src="https://avatars.githubusercontent.com/u/91261297?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="mon-jai"/></a>
|
|
348
374
|
<a href="https://github.com/puneetdixit200" title="puneetdixit200"><img src="https://avatars.githubusercontent.com/u/236133619?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="puneetdixit200"/></a>
|
|
375
|
+
<a href="https://github.com/RexSkz" title="RexSkz"><img src="https://avatars.githubusercontent.com/u/27483702?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="RexSkz"/></a>
|
|
349
376
|
<a href="https://github.com/RinZ27" title="RinZ27"><img src="https://avatars.githubusercontent.com/u/222222878?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="RinZ27"/></a>
|
|
350
377
|
<a href="https://github.com/sharuzzaman" title="sharuzzaman"><img src="https://avatars.githubusercontent.com/u/7421941?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="sharuzzaman"/></a>
|
|
351
378
|
<a href="https://github.com/simon1uo" title="simon1uo"><img src="https://avatars.githubusercontent.com/u/60037549?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="simon1uo"/></a>
|
|
352
379
|
<a href="https://github.com/titoBouzout" title="titoBouzout"><img src="https://avatars.githubusercontent.com/u/64156?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="titoBouzout"/></a>
|
|
353
380
|
<a href="https://github.com/ZiuChen" title="ZiuChen"><img src="https://avatars.githubusercontent.com/u/64892985?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="ZiuChen"/></a>
|
|
354
381
|
<a href="https://github.com/adajoy" title="adajoy"><img src="https://avatars.githubusercontent.com/u/26210079?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="adajoy"/></a>
|
|
355
|
-
<a href="https://github.com/harshasiddartha" title="harshasiddartha"><img src="https://avatars.githubusercontent.com/u/147021873?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="harshasiddartha"/></a>
|
|
356
382
|
</p>
|
|
357
383
|
<!-- CONTRIBUTORS:END -->
|
|
358
384
|
|
|
@@ -376,7 +402,7 @@ Shipping something built with SnapDOM? Add the badge to your README:
|
|
|
376
402
|
|
|
377
403
|
### Projects using SnapDOM
|
|
378
404
|
|
|
379
|
-
SnapDOM runs in production across
|
|
405
|
+
SnapDOM runs in production across 250+ public repositories ([GitHub dependents graph](https://github.com/zumerlab/snapdom/network/dependents)). A few notable ones, each verified from its own `package.json`:
|
|
380
406
|
|
|
381
407
|
- [LobeHub](https://github.com/lobehub/lobehub) — platform for operating AI agents
|
|
382
408
|
- [Trilium Notes](https://github.com/TriliumNext/Trilium) — hierarchical personal knowledge base
|
|
@@ -387,6 +413,8 @@ SnapDOM runs in production across 290+ public repositories ([GitHub dependents g
|
|
|
387
413
|
- [Rabby Wallet](https://github.com/RabbyHub/Rabby) — browser wallet for EVM chains
|
|
388
414
|
- [uMap](https://github.com/umap-project/umap) — OpenStreetMap map builder
|
|
389
415
|
- [ListenBrainz](https://github.com/metabrainz/listenbrainz-server) — music tracker by MetaBrainz
|
|
416
|
+
- [Mind Elixir](https://github.com/SSShooter/mind-elixir-core) — mind-map core; recommends SnapDOM for image export
|
|
417
|
+
- [Kong UI Components](https://github.com/Kong/public-ui-components) — Kong's dashboard renderer exports PDFs with SnapDOM
|
|
390
418
|
- [SnapDIFF](https://zumerlab.com/snapdiff/) — in-browser visual regression testing *(by Zumerlab)*
|
|
391
419
|
|
|
392
420
|
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.
|
package/dist/plugins.mjs
CHANGED
package/dist/preCache.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* SnapDOM
|
|
3
|
-
* v2.
|
|
3
|
+
* v2.23.0
|
|
4
4
|
* Author: Juan Martin Muda
|
|
5
5
|
* License: MIT
|
|
6
6
|
*/
|
|
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)}},u={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(u.session.__counterEpoch=(u.session.__counterEpoch||0)+1,t){case"auto":{u.session.styleMap=new Map,u.session.nodeMap=new Map;return}case"soft":{u.session.styleMap=new Map,u.session.nodeMap=new Map,u.session.styleCache=new WeakMap;return}case"full":return;case"disabled":{u.session.styleMap=new Map,u.session.nodeMap=new Map,u.session.styleCache=new WeakMap,u.computedStyle=new WeakMap,u.measureHints=new WeakMap,u.baseStyle=new L(50),u.defaultStyle=new L(30),u.image=new L(100),u.background=new L(100),u.resource=new L(150),u.font=new Set;return}default:{u.session.styleMap=new Map,u.session.nodeMap=new Map,u.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 kt(t="[snapDOM]",{ttlMs:e=5*6e4,maxEntries:n=12}={}){let o=new Map,i=0;function r(s,a,l){if(i>=n)return;let f=Date.now();(o.get(a)||0)>f||(o.set(a,f+e),i++,s==="warn"&&console&&console.warn?console.warn(`${t} ${l}`):console&&console.error&&console.error(`${t} ${l}`))}return{warnOnce(s,a){r("warn",s,a)},errorOnce(s,a){r("error",s,a)},reset(){o.clear(),i=0}}}var ot=kt("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),H=new Map,j=new Map;function At(t){return/^data:|^blob:|^about:blank$/i.test(t)}function Rt(t,e){try{let n=typeof location<"u"&&location.href?location.href:"http://localhost/",o=e.includes("{url}")?e.split("{url}")[0]:e,i=new URL(o||".",n),r=new URL(t,n);if(r.origin===i.origin)return!0;let s=r.searchParams;if(s&&(s.has("url")||s.has("target")))return!0}catch{}return!1}function $t(t,e){if(!e||At(t)||Rt(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 Lt(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 Mt(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,i=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[,m="",h=""]=String(t).match(/^data:([^,]*),(.*)$/)||[],g=/;base64/i.test(m)?atob(h):decodeURIComponent(h),y=new Uint8Array([...g].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 h=await m.blob(),c=h.type||m.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await rt(h),status:m.status,url:t,fromCache:!1,mime:c}:n==="text"?{ok:!0,data:await h.text(),status:m.status,url:t,fromCache:!1,mime:c}:{ok:!0,data:h,status:m.status,url:t,fromCache:!1,mime:c}}catch{return{ok:!1,data:null,status:0,url:t,fromCache:!1,reason:"network"}}if(/^about:blank$/i.test(t))return n==="dataURL"?{ok:!0,data:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==",status:200,url:t,fromCache:!1,mime:"image/png"}:{ok:!0,data:n==="text"?"":new Blob([]),status:200,url:t,fromCache:!1};let l=Mt(t,{as:n,timeout:o,useProxy:i,errorTTL:r}),f=j.get(l);if(f&&f.until>Date.now())return{...f.result,fromCache:!0};f&&j.delete(l);let d=H.get(l);if(d)return d;let p=$t(t,i)?Lt(t,i):t,w=e.credentials;if(!w)try{let m=typeof location<"u"&&location.href?location.href:"http://localhost/",h=new URL(t,m);w=typeof location<"u"&&h.origin===location.origin?"include":"omit"}catch{w="omit"}let k=new AbortController,A=setTimeout(()=>k.abort("timeout"),o),b=(async()=>{try{let m=await fetch(p,{signal:k.signal,credentials:w,headers:s});if(!m.ok){let g={ok:!1,data:null,status:m.status,url:p,fromCache:!1,reason:"http_error"};if(r>0&&j.set(l,{until:Date.now()+r,result:g}),!a){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(g),g}if(n==="text")return{ok:!0,data:await m.text(),status:m.status,url:p,fromCache:!1};let h=await m.blob(),c=h.type||m.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await rt(h),status:m.status,url:p,fromCache:!1,mime:c}:{ok:!0,data:h,status:m.status,url:p,fromCache:!1,mime:c}}catch(m){let h=m&&typeof m=="object"&&"name"in m&&m.name==="AbortError"?String(m.message||"").includes("timeout")?"timeout":"abort":"network",c={ok:!1,data:null,status:0,url:p,fromCache:!1,reason:h};if(!/^blob:/i.test(t)&&r>0&&j.set(l,{until:Date.now()+r,result:c}),!a){let g=`${h}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,y=h==="timeout"?`Timeout after ${o}ms. Consider increasing timeout or using a proxy for ${t}`:h==="abort"?`Request aborted while fetching ${n} ${t}`:`Network/CORS issue while fetching ${n} ${t}. A proxy may be required`;ot.errorOnce(g,y)}return e.onError&&e.onError(c),c}finally{clearTimeout(A),H.delete(l)}})();return H.set(l,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 i=nt(o),r=v(i),s=(e.useProxy||"")+"|"+r;if(u.background.has(s)){let a=u.background.get(s);return a?`url("${a}")`:"none"}try{let a=await _(r,{as:"dataURL",useProxy:e.useProxy});return a.ok?(u.background.set(s,a.data),`url("${a.data}")`):(u.background.set(s,null),"none")}catch{return u.background.set(s,null),"none"}}var it=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"]),Et=["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 Et){let e=String(t).toLowerCase();it.has(e)||Y.has(e)||at(e)}}function at(t){if(t=String(t).toLowerCase(),Y.has(t)){let r={};return u.defaultStyle.set(t,r),r}if(u.defaultStyle.has(t))return u.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),i={};for(let r of o){if(ct(r))continue;let s=o.getPropertyValue(r);i[r]=s}return e.removeChild(n),u.defaultStyle.set(t,i),i}var _t=/(?:^|-)(animation|transition)(?:-|$)/i,Ft=/^(--.+|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,Ut=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"]),st=new Map;function ct(t){let e=st.get(t);if(e===void 0){let n=String(t).toLowerCase();e=Ut.has(n)||Ft.test(n)||_t.test(n),st.set(t,e)}return e}function It(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 r={length:0,getPropertyValue:()=>"",item:()=>""};return r[Symbol.iterator]=function*(){},r};if(!(t instanceof Element)){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=u.computedStyle.get(t);o||(o=new Map,u.computedStyle.set(t,o));let i=o.get(e);if(!i){let r=It(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{}i=s||n(),o.set(e,i)}return i}function z(t){let e=[],n=0,o=0;for(let i=0;i<t.length;i++){let r=t[i];r==="("&&n++,r===")"&&n--,r===","&&n===0&&(e.push(t.slice(o,i).trim()),o=i+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),i=/mobile/i.test(t),r=!/safari/i.test(t),s=o&&i&&r,a=/(micromessenger|wxwork|wecom|windowswechat|macwechat)/i.test(t),l=/(baiduboxapp|baidubrowser|baidusearch|baiduboxlite)/i.test(e),f=/ipad|iphone|ipod/.test(e)&&o;return n||s||a||l||f}var Tt=[/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],xe=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__||{}),Ot=[];function U(t){let e=typeof t=="string"?t:"",n=[...Tt,...Ot];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 mt=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]),Pt=["katex","mathjax","mathml"];function Z(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!mt.has(n.toLowerCase()))return n}return""}function vt(t){if(!t)return[];let e=[];for(let n of t.split(",")){let o=n.trim().replace(/^['"]+|['"]+$/g,"");o&&(mt.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 Nt(t){let e=String(t??"100%").match(/(\d+(?:\.\d+)?)\s*%/);return e?Math.max(50,Math.min(200,parseFloat(e[1]))):100}function Dt(t){let e=String(t||"400").trim(),n=e.match(/^(\d{2,3})\s+(\d{2,3})$/);if(n){let i=G(n[1]),r=G(n[2]);return{min:Math.min(i,r),max:Math.max(i,r)}}let o=G(e);return{min:o,max:o}}function Wt(t){let e=String(t||"normal").trim().toLowerCase();return e==="italic"?{kind:"italic"}:e.startsWith("oblique")?{kind:"oblique"}:{kind:"normal"}}function Bt(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*%/),i=o?parseFloat(o[1]):100;return{min:i,max:i}}function qt(t){return!t||typeof t!="string"?"":t.replace(/\s+(variable|vf|v[0-9]+)$/i,"").trim().toLowerCase().replace(/\s+/g,"-")}function Vt(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(l=>r.endsWith(l))||n.some(l=>r===l.toLowerCase()||r.endsWith("."+l.toLowerCase())))return!0;let a=(o.pathname+o.search).toLowerCase();if(/\bfont(s)?\b/.test(a)||/\.woff2?(\b|$)/.test(a)||Pt.some(l=>a.includes(l)))return!0;for(let l of e){let f=l.toLowerCase().replace(/\s+/g,"+"),d=l.toLowerCase().replace(/\s+/g,"-"),p=qt(l);if(a.includes(f)||a.includes(d)||p&&a.includes(p))return!0}return!1}catch{return!1}}function jt(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,i)=>{let r=(i||"").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 J=/@import\s+(?:url\(\s*(['"]?)([^)"']+)\1\s*\)|(['"])([^"']+)\3)([^;]*);/g,K=4;async function zt(t,e,n){if(!t)return t;let o=new Set;function i(a,l){try{return new URL(a,l||location.href).href}catch{return a}}async function r(a,l,f=0){if(f>K)return console.warn(`[snapDOM] @import depth exceeded (${K}) at ${l}`),a;let d="",p=0,w;for(;w=J.exec(a);){d+=a.slice(p,w.index),p=J.lastIndex;let k=(w[2]||w[4]||"").trim(),A=i(k,l);if(o.has(A)){console.warn(`[snapDOM] Skipping circular @import: ${A}`);continue}o.add(A);let b="";try{let m=await _(A,{as:"text",useProxy:n,silent:!0});m.ok&&typeof m.data=="string"&&(b=m.data)}catch{}b?(b=lt(b,A),b=await r(b,A,f+1),d+=`
|
|
8
|
-
/* inlined: ${
|
|
9
|
-
${
|
|
10
|
-
`):d+=w[0]}return d+=a.slice(p),d}let s=lt(t,e||location.href);return s=await r(s,e||location.href,0),s}var dt=/url\((["']?)([^"')]+)\1\)/g,Gt=/@font-face[^{}]*\{[^}]*\}/g;function pt(t){if(!t)return[];let e=[],n=t.split(",").map(o=>o.trim()).filter(Boolean);for(let o of n){let i=o.match(/^U\+([0-9A-Fa-f?]+)(?:-([0-9A-Fa-f?]+))?$/);if(!i)continue;let r=i[1],s=i[2],a=l=>{if(!l.includes("?"))return parseInt(l,16);let f=parseInt(l.replace(/\?/g,"0"),16),d=parseInt(l.replace(/\?/g,"F"),16);return[f,d]};if(s){let l=a(r),f=a(s),d=Array.isArray(l)?l[0]:l,p=Array.isArray(f)?f[1]:f;e.push([Math.min(d,p),Math.max(d,p)])}else{let l=a(r);Array.isArray(l)?e.push([l[0],l[1]]):e.push([l,l])}}return e}function ht(t,e){if(!e.length||!t||t.size===0)return!0;for(let n of t)for(let[o,i]of e)if(n>=o&&n<=i)return!0;return!1}function tt(t,e){let n=[];if(!t)return n;for(let o of t.matchAll(dt)){let i=(o[2]||"").trim();if(!(!i||i.startsWith("data:"))){if(!/^https?:/i.test(i))try{i=new URL(i,e||location.href).href}catch{}n.push(i)}}return n}async function gt(t,e,n=""){let o=t;for(let i of t.matchAll(dt)){let r=V(i[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(!U(s)){if(u.resource?.has(s)){u.font?.add(s),o=o.replace(i[0],`url(${u.resource.get(s)})`);continue}try{let a=await _(s,{as:"dataURL",useProxy:n,silent:!0});if(a.ok&&typeof a.data=="string"){let l=a.data;u.resource?.set(s,l),u.font?.add(s),o=o.replace(i[0],`url(${l})`)}}catch{console.warn("[snapDOM] Failed to fetch font resource:",s)}}}return o}function Xt(t){if(!t.length)return null;let e=(a,l)=>t.some(([f,d])=>!(d<a||f>l)),n=e(0,255)||e(305,305),o=e(256,591)||e(7680,7935),i=e(880,1023),r=e(1024,1279);return e(7840,7929)||e(258,259)||e(416,417)||e(431,432)?"vietnamese":r?"cyrillic":i?"greek":o?"latin-ext":n?"latin":null}function ft(t={}){let e=new Set((t.families||[]).map(i=>String(i).toLowerCase())),n=new Set((t.domains||[]).map(i=>String(i).toLowerCase())),o=new Set((t.subsets||[]).map(i=>String(i).toLowerCase()));return(i,r)=>{if(e.size&&e.has(i.family.toLowerCase()))return!0;if(n.size)for(let s of i.srcUrls)try{if(n.has(new URL(s).host.toLowerCase()))return!0}catch{}if(o.size){let s=Xt(r);if(s&&o.has(s))return!0}return!1}}function Kt(t){if(!t)return t;let e=/@font-face[^{}]*\{[^}]*\}/gi,n=new Set,o=[];for(let r of t.match(e)||[]){let s=r.match(/font-family:\s*([^;]+);/i)?.[1]||"",a=Z(s),l=(r.match(/font-weight:\s*([^;]+);/i)?.[1]||"400").trim(),f=(r.match(/font-style:\s*([^;]+);/i)?.[1]||"normal").trim(),d=(r.match(/font-stretch:\s*([^;]+);/i)?.[1]||"100%").trim(),p=(r.match(/unicode-range:\s*([^;]+);/i)?.[1]||"").trim(),w=(r.match(/src\s*:\s*([^;}]+)[;}]/i)?.[1]||"").trim(),k=tt(w,location.href),A=k.length?k.map(m=>String(m).toLowerCase()).sort().join("|"):w.toLowerCase(),b=[String(a||"").toLowerCase(),l,f,d,p.toLowerCase(),A].join("|");n.has(b)||(n.add(b),o.push(r))}if(o.length===0)return t;let i=0;return t.replace(e,()=>o[i++]||"")}var ut=new WeakMap,Ht=0;function Yt(t){let e=ut.get(t);return e===void 0&&(e=Ht++,ut.set(t,e)),e}function Qt(t,e,n,o,i,r){let s=Array.from(t||[]).sort().join("|"),a=e?JSON.stringify({families:(e.families||[]).map(w=>String(w).toLowerCase()).sort(),domains:(e.domains||[]).map(w=>String(w).toLowerCase()).sort(),subsets:(e.subsets||[]).map(w=>String(w).toLowerCase()).sort()}):"",l=(n||[]).map(w=>`${(w.family||"").toLowerCase()}::${w.weight||"normal"}::${w.style||"normal"}::${w.src||""}`).sort().join("|"),f=o||"",d=(i||[]).map(w=>String(w).toLowerCase()).sort().join("|"),p=Yt(r||document);return`fonts-embed-css::req=${s}::ex=${a}::lf=${l}::px=${f}::fd=${d}::doc=${p}`}async function yt(t,e,n,o){let i;try{i=t.cssRules||[]}catch{return}let r=(s,a)=>{try{return new URL(s,a||location.href).href}catch{return s}};for(let s of i){if(s.type===CSSRule.IMPORT_RULE&&s.styleSheet){let a=s.href?r(s.href,e):e;if(o.depth>=K){console.warn(`[snapDOM] CSSOM import depth exceeded (${K}) at ${a}`);continue}if(a&&o.visitedSheets.has(a)){console.warn(`[snapDOM] Skipping circular CSSOM import: ${a}`);continue}a&&o.visitedSheets.add(a);let l={...o,depth:(o.depth||0)+1};await yt(s.styleSheet,a,n,l);continue}if(s.type===CSSRule.FONT_FACE_RULE){let a=(s.style.getPropertyValue("font-family")||"").trim(),l=Z(a);if(!l||U(l))continue;let f=(s.style.getPropertyValue("font-weight")||"400").trim(),d=(s.style.getPropertyValue("font-style")||"normal").trim(),p=(s.style.getPropertyValue("font-stretch")||"100%").trim(),w=(s.style.getPropertyValue("src")||"").trim(),k=(s.style.getPropertyValue("unicode-range")||"").trim();if(!o.faceMatchesRequired(l,d,f,p))continue;let A=pt(k);if(!ht(o.usedCodepoints,A))continue;let b={family:l,weightSpec:f,styleSpec:d,stretchSpec:p,unicodeRange:k,srcRaw:w,srcUrls:tt(w,e||location.href),href:e||location.href};if(o.simpleExcluder&&o.simpleExcluder(b,A))continue;if(/url\(/i.test(w)){let m=await gt(w,e||location.href,o.useProxy);await n(`@font-face{font-family:${l};src:${m};font-style:${d};font-weight:${f};font-stretch:${p};${k?`unicode-range:${k};`:""}}`)}else await n(`@font-face{font-family:${l};src:${w};font-style:${d};font-weight:${f};font-stretch:${p};${k?`unicode-range:${k};`:""}}`)}}}async function wt({required:t,usedCodepoints:e,exclude:n=void 0,localFonts:o=[],useProxy:i="",fontStylesheetDomains:r=[],doc:s=document}={}){t instanceof Set||(t=new Set),e instanceof Set||(e=new Set);let a=new Map;for(let c of t){let[g,y,C,S]=String(c).split("__");if(!g)continue;let x=g.toLowerCase(),R=a.get(x)||[];R.push({w:parseInt(y,10),s:C,st:parseInt(S,10)}),a.set(x,R)}function l(c,g,y,C){let S=String(c).toLowerCase();if(!a.has(S))return!1;let x=a.get(S),R=Dt(y),M=Wt(g),F=Bt(C),T=R.min!==R.max,O=R.min,P=$=>M.kind==="normal"&&$==="normal"||M.kind!=="normal"&&($==="italic"||$==="oblique"),B=!1;for(let $ of x){let E=T?$.w>=R.min&&$.w<=R.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 f=ft(n),d=Qt(t,n,o,i,r,s);if(u.resource?.has(d))return u.resource.get(d);let p=jt(t),w=[],k=J;for(let c of s.querySelectorAll("style")){let g=c.textContent||"";for(let y of g.matchAll(k)){let C=(y[2]||y[4]||"").trim();if(!C||U(C))continue;s.querySelector(`link[rel="stylesheet"][href="${C}"]`)||w.push(C)}}let A=[];w.length&&await Promise.all(w.map(c=>new Promise(g=>{if(s.querySelector(`link[rel="stylesheet"][href="${c}"]`))return g(null);let y=s.createElement("link");y.rel="stylesheet",y.href=c,y.setAttribute("data-snapdom","injected-import"),y.onload=()=>g(y),y.onerror=()=>g(null),s.head.appendChild(y),A.push(y)})));let b="",m=Array.from(s.querySelectorAll('link[rel="stylesheet"]')).filter(c=>!!c.href);for(let c of A)try{c.remove()}catch{}for(let c of m)try{if(U(c.href))continue;let g="",y=!1;try{y=new URL(c.href,location.href).origin===location.origin}catch{}if(!y){let S=Array.isArray(r)?r:[];if(!Vt(c.href,p,S))continue}if(y){let S=Array.from(s.styleSheets).find(x=>x.href===c.href);if(S)try{let x=S.cssRules||[];g=Array.from(x).map(R=>R.cssText).join("")}catch{}}if(!g){let S=await _(c.href,{as:"text",useProxy:i});if(S?.ok&&typeof S.data=="string"&&(g=S.data),U(c.href))continue}g=await zt(g,c.href,i);let C="";for(let S of g.match(Gt)||[]){let x=(S.match(/font-family:\s*([^;]+);/i)?.[1]||"").trim(),R=Z(x);if(!R||U(R))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,c.href);if(!l(R,F,M,T))continue;let $=pt(O);if(!ht(e,$))continue;let E={family:R,weightSpec:M,styleSpec:F,stretchSpec:T,unicodeRange:O,srcRaw:P,srcUrls:B,href:c.href};if(n&&f(E,$))continue;let I=/url\(/i.test(P)?await gt(S,c.href,i):S;C+=I}C.trim()&&(b+=C)}catch{console.warn("[snapDOM] Failed to process stylesheet:",c.href)}let h={requiredIndex:a,usedCodepoints:e,faceMatchesRequired:l,simpleExcluder:n?ft(n):null,useProxy:i,visitedSheets:new Set,depth:0};for(let c of s.styleSheets)if(!(c.href&&m.some(g=>g.href===c.href)))try{let g=c.href||location.origin+"/";g&&h.visitedSheets.add(g),await yt(c,g,async y=>{b+=y},h)}catch{}try{for(let c of s.fonts||[]){if(!c||!c.family||c.status!=="loaded"||!c._snapdomSrc)continue;let g=String(c.family).replace(/^['"]+|['"]+$/g,"");if(U(g)||!a.has(g.toLowerCase())||n?.families&&n.families.some(C=>String(C).toLowerCase()===g.toLowerCase()))continue;let y=c._snapdomSrc;if(!String(y).startsWith("data:")){if(u.resource?.has(c._snapdomSrc))y=u.resource.get(c._snapdomSrc),u.font?.add(c._snapdomSrc);else if(!u.font?.has(c._snapdomSrc))try{let C=await _(c._snapdomSrc,{as:"dataURL",useProxy:i,silent:!0});if(C.ok&&typeof C.data=="string")y=C.data,u.resource?.set(c._snapdomSrc,y),u.font?.add(c._snapdomSrc);else continue}catch{console.warn("[snapDOM] Failed to fetch dynamic font src:",c._snapdomSrc);continue}}b+=`@font-face{font-family:'${g}';src:url(${y});font-style:${c.style||"normal"};font-weight:${c.weight||"normal"};}`}}catch{}for(let c of o){if(!c||typeof c!="object")continue;let g=String(c.family||"").replace(/^['"]+|['"]+$/g,"");if(!g||U(g)||!a.has(g.toLowerCase())||n?.families&&n.families.some(M=>String(M).toLowerCase()===g.toLowerCase()))continue;let y=c.weight!=null?String(c.weight):"normal",C=c.style!=null?String(c.style):"normal",S=c.stretchPct!=null?`${c.stretchPct}%`:"100%",x=String(c.src||""),R=x;if(!R.startsWith("data:")){if(u.resource?.has(x))R=u.resource.get(x),u.font?.add(x);else if(!u.font?.has(x))try{let M=await _(x,{as:"dataURL",useProxy:i,silent:!0});if(M.ok&&typeof M.data=="string")R=M.data,u.resource?.set(x,R),u.font?.add(x);else continue}catch{console.warn("[snapDOM] Failed to fetch localFonts src:",x);continue}}b+=`@font-face{font-family:'${g}';src:url(${R});font-style:${C};font-weight:${y};font-stretch:${S};}`}return b&&(b=Kt(b),u.resource?.set(d,b)),b}function St(t,e){let n=new Set;if(!t)return n;let o=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,null),i=a=>{let l=vt(a.fontFamily);if(l.length)for(let f of l){let d=(p,w,k)=>`${f}__${G(p)}__${X(w)}__${Nt(k)}`;n.add(d(a.fontWeight,a.fontStyle,a.fontStretch))}};i(getComputedStyle(t));let r=getComputedStyle(t,"::before");r&&r.content&&r.content!=="none"&&i(r);let s=getComputedStyle(t,"::after");for(s&&s.content&&s.content!=="none"&&i(s);o.nextNode();){let a=o.currentNode;if(e&&!e(a))continue;let l=getComputedStyle(a);i(l);let f=getComputedStyle(a,"::before");f&&f.content&&f.content!=="none"&&i(f);let d=getComputedStyle(a,"::after");d&&d.content&&d.content!=="none"&&i(d)}return n}function bt(t,e){let n=new Set,o=r=>{if(r)for(let s of r)n.add(s.codePointAt(0))},i=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,null);for(;i.nextNode();){let r=i.currentNode;if(r.nodeType===Node.TEXT_NODE){if(e&&r.parentElement&&!e(r.parentElement))continue;o(r.nodeValue||"")}else if(r.nodeType===Node.ELEMENT_NODE){let s=r;if(e&&!e(s))continue;for(let a of["::before","::after"]){let f=getComputedStyle(s,a)?.getPropertyValue("content");if(!(!f||f==="none"))if(/^"/.test(f)||/^'/.test(f))o(f.slice(1,-1));else{let d=f.match(/\\[0-9A-Fa-f]{1,6}/g);if(d)for(let p of d)try{n.add(parseInt(p.slice(1),16))}catch{}}}}}return n}async function Ct(t,e=2,n=document){try{await n.fonts.ready}catch{}let o=Array.from(t||[]).filter(Boolean);if(o.length===0)return;let i=()=>{let r=n.createElement("div");r.style.cssText="position:absolute!important;left:-9999px!important;top:0!important;opacity:0!important;pointer-events:none!important;contain:layout size style;";for(let 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++)i(),await new Promise(s=>requestAnimationFrame(()=>requestAnimationFrame(s)))}async function xt(t,e,n,o={}){let i=[[t,e]],r=["background-image","mask","mask-image","-webkit-mask","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source","border-image","border-image-source"],s=["mask-position","mask-size","mask-repeat","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"],a=["background-position","background-position-x","background-position-y","background-size","background-repeat","background-origin","background-clip","background-attachment","background-blend-mode"],l=["border-image-slice","border-image-width","border-image-outset","border-image-repeat"];for(;i.length;){let[f,d]=i.shift();if(!d)continue;let p=n.get(f)||D(f);n.has(f)||n.set(f,p);let w=(()=>{let m=p.getPropertyValue("border-image"),h=p.getPropertyValue("border-image-source");return m&&m!=="none"||h&&h!=="none"})(),k=p.getPropertyValue("background-image"),A=p.getPropertyValue("background-color");if(k&&k!=="none"||A&&A!=="rgba(0, 0, 0, 0)"&&A!=="transparent"||/url\s*\(|gradient\s*\(/i.test(p.getPropertyValue("background")||""))for(let m of a){let h=p.getPropertyValue(m);h&&d.style.setProperty(m,h)}for(let m of r){let h=p.getPropertyValue(m);if(m==="background-image"&&(!h||h==="none")){let y=p.getPropertyValue("background");y&&/url\s*\(/.test(y)&&(h=z(y).filter(C=>/url\s*\(/.test(C)).join(", ")||h)}if(!h||h==="none")continue;let c=z(h),g=await Promise.all(c.map(y=>N(y,o)));g.some(y=>y&&y!=="none"&&!/^url\(undefined/.test(y))&&d.style.setProperty(m,g.join(", "))}for(let m of s){let h=p.getPropertyValue(m);!h||h==="initial"||d.style.setProperty(m,h)}if(w)for(let m of l){let h=p.getPropertyValue(m);!h||h==="initial"||d.style.setProperty(m,h)}if(f.shadowRoot){let m=Array.from(f.shadowRoot.children).filter(c=>c.tagName!=="STYLE"),h=Array.from(d.children).filter(c=>!c.dataset?.snapdomPseudo&&!(c.tagName==="STYLE"&&c.dataset?.sd));for(let c=0;c<Math.min(m.length,h.length);c++)i.push([m[c],h[c]])}else{let m=u.session.nodeMap;for(let h of d.children){let c=m.get(h);c&&i.push([c,h])}}}}async function ve(t=document,e={}){let{embedFonts:n=!0,useProxy:o=""}=e,i=e.cache??e.cacheOpt??"full";et(i);try{await document.fonts?.ready}catch{}try{Q()}catch{}u.session=u.session||{},u.session.styleCache||(u.session.styleCache=new WeakMap),u.image=u.image||new L(100),u.background=u.background||new L(100);try{await xt(t,void 0,u.session.styleCache,{useProxy:o})}catch{}let r=[],s=[];try{if(t&&t.nodeType===1){let l=t.querySelectorAll?Array.from(t.querySelectorAll("*")):[];s=[t,...l],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 l of r){let f=l?.currentSrc||l?.src;if(f&&!u.image.has(f)){let d=Promise.resolve().then(async()=>{let p=await _(f,{as:"dataURL",useProxy:o});p?.ok&&typeof p.data=="string"&&u.image.set(f,p.data)}).catch(()=>{});a.push(d)}}for(let l of s){let f="";try{f=l?.style?.backgroundImage||"",(!f||f==="none")&&(f=D(l).backgroundImage)}catch{}if(f&&f!=="none"){let d=f.match(/url\((?:[^()"']+|"(?:[^"]*)"|'(?:[^']*)')\)/gi)||[];for(let p of d){let w=Promise.resolve().then(()=>N(p,{...e,useProxy:o})).catch(()=>{});a.push(w)}}}if(n)try{let l=St(t),f=bt(t);if(typeof W=="function"?W():!!W){let p=new Set(Array.from(l).map(w=>String(w).split("__")[0]).filter(Boolean));await Ct(p,3)}await wt({required:l,usedCodepoints:f,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:e.useProxy??o,fontStylesheetDomains:e.fontStylesheetDomains})}catch{}await Promise.allSettled(a)}export{ve as preCache};
|
|
7
|
+
var R=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 R(100),background:new R(100),resource:new R(150),defaultStyle:new R(30),baseStyle:new R(50),compress:new R(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 et(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 R(50),f.defaultStyle=new R(30),f.image=new R(100),f.background=new R(100),f.resource=new R(150),f.compress=new R(50),f.font=new Set;return}default:{f.session.styleMap=new Map,f.session.nodeMap=new Map,f.session.styleCache=new WeakMap;return}}}function j(t){let e=t.match(/url\((['"]?)(.*?)(\1)\)/);if(!e)return null;let n=e[2].trim();return n.startsWith("#")?null:n}var kt=/^image\/(jpeg|jpg|png|gif|webp|avif|apng|svg\+xml|bmp|x-icon|vnd\.microsoft\.icon)\s*(;|$)/i;function nt(t,e=1){let n=t.match(/^\s*-?(?:webkit-)?image-set\(([\s\S]*)\)\s*$/i);if(!n)return null;let o=[];for(let s of n[1].split(",")){let r=s.match(/url\((['"]?)(.*?)(\1)\)/);if(!r)continue;let a=s.match(/type\(\s*["']([^"']+)["']\s*\)/i);if(a&&!kt.test(a[1].trim()))continue;let i=s.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:r[2].trim(),dppx:u})}return o.length?(o.sort((s,r)=>s.dppx-r.dppx),(o.find(s=>s.dppx>=e)||o[o.length-1]).url):null}function W(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function ot(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 At(t="[snapDOM]",{ttlMs:e=5*6e4,maxEntries:n=12}={}){let o=new Map,c=0;function s(r,a,i){if(c>=n)return;let u=Date.now();(o.get(a)||0)>u||(o.set(a,u+e),c++,r==="warn"&&console&&console.warn?console.warn(`${t} ${i}`):console&&console.error&&console.error(`${t} ${i}`))}return{warnOnce(r,a){s("warn",r,a)},errorOnce(r,a){s("error",r,a)},reset(){o.clear(),c=0}}}var rt=At("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),K=new Map,V=new Map;function $t(t){return/^data:|^blob:|^about:blank$/i.test(t)}function Mt(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),s=new URL(t,n);if(s.origin===c.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||$t(t)||Mt(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 Lt(t,e){if(!e)return t;if(e.includes("{url}"))return e.replace("{urlRaw}",W(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}${W(t)}`;let n=e.includes("?")?"&":"?";return`${e}${n}url=${encodeURIComponent(t)}`}function st(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 F(t,e={}){let n=e.as??"blob",o=e.timeout??3e3,c=e.useProxy||"",s=e.errorTTL??8e3,r=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[,g="",k=""]=String(t).match(/^data:([^,]*),(.*)$/)||[],d=/;base64/i.test(g)?atob(k):decodeURIComponent(k),y=new Uint8Array([...d].map(w=>w.charCodeAt(0))),b=new Blob([y],{type:(g||"").split(";")[0]||""});return{ok:!0,data:b,status:200,url:t,fromCache:!1,mime:b.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 k=await g.blob(),l=k.type||g.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await st(k),status:g.status,url:t,fromCache:!1,mime:l}:n==="text"?{ok:!0,data:await k.text(),status:g.status,url:t,fromCache:!1,mime:l}:{ok:!0,data:k,status:g.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=_t(t,{as:n,timeout:o,useProxy:c,errorTTL:s}),u=V.get(i);if(u&&u.until>Date.now())return{...u.result,fromCache:!0};u&&V.delete(i);let m=K.get(i);if(m)return m;let p=Rt(t,c)?Lt(t,c):t,h=e.credentials;if(!h)try{let g=typeof location<"u"&&location.href?location.href:"http://localhost/",k=new URL(t,g);h=typeof location<"u"&&k.origin===location.origin?"include":"omit"}catch{h="omit"}let C=new AbortController,$=setTimeout(()=>C.abort("timeout"),o),S=(async()=>{try{let g=await fetch(p,{signal:C.signal,credentials:h,headers:r});if(!g.ok){let d={ok:!1,data:null,status:g.status,url:p,fromCache:!1,reason:"http_error"};if(s>0&&V.set(i,{until:Date.now()+s,result:d}),!a){let y=`${g.status} ${g.statusText||""}`.trim();rt.warnOnce(`http:${g.status}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,`HTTP error ${y} 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:p,fromCache:!1};let k=await g.blob(),l=k.type||g.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await st(k),status:g.status,url:p,fromCache:!1,mime:l}:{ok:!0,data:k,status:g.status,url:p,fromCache:!1,mime:l}}catch(g){let k=g&&typeof g=="object"&&"name"in g&&g.name==="AbortError"?String(g.message||"").includes("timeout")?"timeout":"abort":"network",l={ok:!1,data:null,status:0,url:p,fromCache:!1,reason:k};if(!/^blob:/i.test(t)&&s>0&&V.set(i,{until:Date.now()+s,result:l}),!a){let d=`${k}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,y=k==="timeout"?`Timeout after ${o}ms. Consider increasing timeout or using a proxy for ${t}`:k==="abort"?`Request aborted while fetching ${n} ${t}`:`Network/CORS issue while fetching ${n} ${t}. A proxy may be required`;rt.errorOnce(d,y)}return e.onError&&e.onError(l),l}finally{clearTimeout($),K.delete(i)}})();return K.set(i,S),S}async function H(t,e={}){if(/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t)||t.trim()==="none")return t;let o=nt(t,typeof devicePixelRatio<"u"&&devicePixelRatio||1)??j(t);if(!o)return t;let c=ot(o),s=W(c),r=(e.useProxy||"")+"|"+s;if(f.background.has(r)){let a=f.background.get(r);return a?`url("${a}")`:"none"}try{let a=await F(s,{as:"dataURL",useProxy:e.useProxy});return a.ok?(f.background.set(r,a.data),`url("${a.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"]),Et=["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 Et){let e=String(t).toLowerCase();at.has(e)||Y.has(e)||ct(e)}}function ct(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),c={};for(let s of o){if(lt(s))continue;let r=o.getPropertyValue(s);c[s]=r}return e.removeChild(n),f.defaultStyle.set(t,c),c}var Ft=/(?:^|-)(animation|transition)(?:-|$)/i,Ut=/^(--.+|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,It=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"]),it=new Map;function lt(t){let e=it.get(t);if(e===void 0){let n=String(t).toLowerCase();e=It.has(n)||Ut.test(n)||Ft.test(n),it.set(t,e)}return e}function Tt(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?.nodeType!==1){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 c=o.get(e);if(!c){let s=Tt(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{}c=r||n(),o.set(e,c)}return c}function B(){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),s=!/safari/i.test(t),r=o&&c&&s,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||r||a||i||u}var Ot=[/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],Ae=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__||{}),vt=[];function I(t){let e=typeof t=="string"?t:"",n=[...Ot,...vt];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 dt=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]),Pt=["katex","mathjax","mathml"];function Z(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!dt.has(n.toLowerCase()))return n}return""}function Dt(t){if(!t)return[];let e=[];for(let n of t.split(",")){let o=n.trim().replace(/^['"]+|['"]+$/g,"");o&&(dt.has(o.toLowerCase())||e.push(o))}return e}function X(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 z(t){let e=String(t??"normal").trim().toLowerCase();return e.startsWith("italic")?"italic":e.startsWith("oblique")?"oblique":"normal"}function Wt(t){let e=String(t??"100%").match(/(\d+(?:\.\d+)?)\s*%/);return e?Math.max(50,Math.min(200,parseFloat(e[1]))):100}function Bt(t){let e=String(t||"400").trim(),n=e.match(/^(\d{2,3})\s+(\d{2,3})$/);if(n){let c=X(n[1]),s=X(n[2]);return{min:Math.min(c,s),max:Math.max(c,s)}}let o=X(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 qt(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*%/),c=o?parseFloat(o[1]):100;return{min:c,max:c}}function jt(t){return!t||typeof t!="string"?"":t.replace(/\s+(variable|vf|v[0-9]+)$/i,"").trim().toLowerCase().replace(/\s+/g,"-")}function Vt(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 a=(o.pathname+o.search).toLowerCase();if(/\bfont(s)?\b/.test(a)||/\.woff2?(\b|$)/.test(a)||Pt.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,"-"),p=jt(i);if(a.includes(u)||a.includes(m)||p&&a.includes(p))return!0}return!1}catch{return!1}}function Xt(t){let e=new Set;for(let n of t||[]){let o=String(n).split("__")[0]?.trim();o&&e.add(o)}return e}function ft(t,e){return t&&t.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/g,(n,o,c)=>{let s=(c||"").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,G=4;async function zt(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 s(a,i,u=0){if(u>G)return console.warn(`[snapDOM] @import depth exceeded (${G}) at ${i}`),a;let m="",p=0,h;for(;h=J.exec(a);){m+=a.slice(p,h.index),p=J.lastIndex;let C=(h[2]||h[4]||"").trim(),$=c(C,i);if(o.has($)){console.warn(`[snapDOM] Skipping circular @import: ${$}`);continue}o.add($);let S="";try{let g=await F($,{as:"text",useProxy:n,silent:!0});g.ok&&typeof g.data=="string"&&(S=g.data)}catch{}S?(S=ft(S,$),S=await s(S,$,u+1),m+=`
|
|
8
|
+
/* inlined: ${$} */
|
|
9
|
+
${S}
|
|
10
|
+
`):m+=h[0]}return m+=a.slice(p),m}let r=ft(t,e||location.href);return r=await s(r,e||location.href,0),r}var pt=/url\((["']?)([^"')]+)\1\)/g,Gt=/@font-face[^{}]*\{[^}]*\}/g;function _(t,e,n=""){return(t.match(new RegExp(`${e}\\s*:\\s*([^;}]+)[;}]`,"i"))?.[1]||n).trim()}function ht(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 s=c[1],r=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(r){let i=a(s),u=a(r),m=Array.isArray(i)?i[0]:i,p=Array.isArray(u)?u[1]:u;e.push([Math.min(m,p),Math.max(m,p)])}else{let i=a(s);Array.isArray(i)?e.push([i[0],i[1]]):e.push([i,i])}}return e}function gt(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 tt(t,e){let n=[];if(!t)return n;for(let o of t.matchAll(pt)){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 yt(t,e,n=""){let o=t;for(let c of t.matchAll(pt)){let s=j(c[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(!I(r)){if(f.resource?.has(r)){f.font?.add(r),o=o.replace(c[0],`url(${f.resource.get(r)})`);continue}try{let a=await F(r,{as:"dataURL",useProxy:n,silent:!0});if(a.ok&&typeof a.data=="string"){let i=a.data;f.resource?.set(r,i),f.font?.add(r),o=o.replace(c[0],`url(${i})`)}}catch{console.warn("[snapDOM] Failed to fetch font resource:",r)}}}return o}function Kt(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),s=e(1024,1279);return e(7840,7929)||e(258,259)||e(416,417)||e(431,432)?"vietnamese":s?"cyrillic":c?"greek":o?"latin-ext":n?"latin":null}function ut(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,s)=>{if(e.size&&e.has(c.family.toLowerCase()))return!0;if(n.size)for(let r of c.srcUrls)try{if(n.has(new URL(r).host.toLowerCase()))return!0}catch{}if(o.size){let r=Kt(s);if(r&&o.has(r))return!0}return!1}}function Ht(t){if(!t)return t;let e=/@font-face[^{}]*\{[^}]*\}/gi,n=new Set,o=[];for(let s of t.match(e)||[]){let r=_(s,"font-family"),a=Z(r),i=_(s,"font-weight","400"),u=_(s,"font-style","normal"),m=_(s,"font-stretch","100%"),p=_(s,"unicode-range"),h=_(s,"src"),C=tt(h,location.href),$=C.length?C.map(g=>String(g).toLowerCase()).sort().join("|"):h.toLowerCase(),S=[String(a||"").toLowerCase(),i,u,m,p.toLowerCase(),$].join("|");n.has(S)||(n.add(S),o.push(s))}if(o.length===0)return t;let c=0;return t.replace(e,()=>o[c++]||"")}var mt=new WeakMap,Yt=0;function Qt(t){let e=mt.get(t);return e===void 0&&(e=Yt++,mt.set(t,e)),e}function Jt(t,e,n,o,c,s){let r=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("|"),p=Qt(s||document);return`fonts-embed-css::req=${r}::ex=${a}::lf=${i}::px=${u}::fd=${m}::doc=${p}`}async function wt(t,e,n,o){let c;try{c=t.cssRules||[]}catch{return}let s=(r,a)=>{try{return new URL(r,a||location.href).href}catch{return r}};for(let r of c){if(r.type===CSSRule.IMPORT_RULE&&r.styleSheet){let a=r.href?s(r.href,e):e;if(o.depth>=G){console.warn(`[snapDOM] CSSOM import depth exceeded (${G}) 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 wt(r.styleSheet,a,n,i);continue}if(r.type===CSSRule.FONT_FACE_RULE){let a=(r.style.getPropertyValue("font-family")||"").trim(),i=Z(a);if(!i||I(i))continue;let u=(r.style.getPropertyValue("font-weight")||"400").trim(),m=(r.style.getPropertyValue("font-style")||"normal").trim(),p=(r.style.getPropertyValue("font-stretch")||"100%").trim(),h=(r.style.getPropertyValue("src")||"").trim(),C=(r.style.getPropertyValue("unicode-range")||"").trim();if(!o.faceMatchesRequired(i,m,u,p))continue;let $=ht(C);if(!gt(o.usedCodepoints,$))continue;let S={family:i,weightSpec:u,styleSpec:m,stretchSpec:p,unicodeRange:C,srcRaw:h,srcUrls:tt(h,e||location.href),href:e||location.href};if(o.simpleExcluder&&o.simpleExcluder(S,$))continue;if(/url\(/i.test(h)){let g=await yt(h,e||location.href,o.useProxy);await n(`@font-face{font-family:${i};src:${g};font-style:${m};font-weight:${u};font-stretch:${p};${C?`unicode-range:${C};`:""}}`)}else await n(`@font-face{font-family:${i};src:${h};font-style:${m};font-weight:${u};font-stretch:${p};${C?`unicode-range:${C};`:""}}`)}}}async function St({required:t,usedCodepoints:e,exclude:n=void 0,localFonts:o=[],useProxy:c="",fontStylesheetDomains:s=[],doc:r=document}={}){t instanceof Set||(t=new Set),e instanceof Set||(e=new Set);let a=new Map;for(let l of t){let[d,y,b,w]=String(l).split("__");if(!d)continue;let x=d.toLowerCase(),A=a.get(x)||[];A.push({w:parseInt(y,10),s:b,st:parseInt(w,10)}),a.set(x,A)}function i(l,d,y,b){let w=String(l).toLowerCase();if(!a.has(w))return!1;let x=a.get(w),A=Bt(y),L=Nt(d),U=qt(b),O=A.min!==A.max,v=A.min,P=M=>L.kind==="normal"&&M==="normal"||L.kind!=="normal"&&(M==="italic"||M==="oblique"),N=!1;for(let M of x){let E=O?M.w>=A.min&&M.w<=A.max:M.w===v,T=P(z(M.s)),q=M.st>=U.min&&M.st<=U.max;if(E&&T&&q){N=!0;break}}if(N)return!0;if(!O)for(let M of x){let E=P(z(M.s)),T=M.st>=U.min&&M.st<=U.max;if(Math.abs(v-M.w)<=300&&E&&T)return!0}if(!O&&L.kind==="normal"&&x.some(E=>z(E.s)!=="normal"))for(let E of x){let T=Math.abs(v-E.w)<=300,q=E.st>=U.min&&E.st<=U.max;if(T&&q)return!0}return!1}let u=ut(n),m=Jt(t,n,o,c,s,r);if(f.resource?.has(m))return f.resource.get(m);let p=Xt(t),h=[],C=J;for(let l of r.querySelectorAll("style")){let d=l.textContent||"";for(let y of d.matchAll(C)){let b=(y[2]||y[4]||"").trim();if(!b||I(b))continue;r.querySelector(`link[rel="stylesheet"][href="${b}"]`)||h.push(b)}}let $=[];h.length&&await Promise.all(h.map(l=>new Promise(d=>{if(r.querySelector(`link[rel="stylesheet"][href="${l}"]`))return d(null);let y=r.createElement("link");y.rel="stylesheet",y.href=l,y.setAttribute("data-snapdom","injected-import"),y.onload=()=>d(y),y.onerror=()=>d(null),r.head.appendChild(y),$.push(y)})));let S="",g=Array.from(r.querySelectorAll('link[rel="stylesheet"]')).filter(l=>!!l.href);for(let l of $)try{l.remove()}catch{}for(let l of g)try{if(I(l.href))continue;let d="",y=!1;try{y=new URL(l.href,location.href).origin===location.origin}catch{}if(!y){let w=Array.isArray(s)?s:[];if(!Vt(l.href,p,w))continue}if(y){let w=Array.from(r.styleSheets).find(x=>x.href===l.href);if(w)try{let x=w.cssRules||[];d=Array.from(x).map(A=>A.cssText).join("")}catch{}}if(!d){let w=await F(l.href,{as:"text",useProxy:c});if(w?.ok&&typeof w.data=="string"&&(d=w.data),I(l.href))continue}d=await zt(d,l.href,c);let b="";for(let w of d.match(Gt)||[]){let x=_(w,"font-family"),A=Z(x);if(!A||I(A))continue;let L=_(w,"font-weight","400"),U=_(w,"font-style","normal"),O=_(w,"font-stretch","100%"),v=_(w,"unicode-range"),P=_(w,"src"),N=tt(P,l.href);if(!i(A,U,L,O))continue;let M=ht(v);if(!gt(e,M))continue;let E={family:A,weightSpec:L,styleSpec:U,stretchSpec:O,unicodeRange:v,srcRaw:P,srcUrls:N,href:l.href};if(n&&u(E,M))continue;let T=/url\(/i.test(P)?await yt(w,l.href,c):w;b+=T}b.trim()&&(S+=b)}catch{console.warn("[snapDOM] Failed to process stylesheet:",l.href)}let k={requiredIndex:a,usedCodepoints:e,faceMatchesRequired:i,simpleExcluder:n?ut(n):null,useProxy:c,visitedSheets:new Set,depth:0};for(let l of r.styleSheets)if(!(l.href&&g.some(d=>d.href===l.href)))try{let d=l.href||location.origin+"/";d&&k.visitedSheets.add(d),await wt(l,d,async y=>{S+=y},k)}catch{}try{for(let l of r.fonts||[]){if(!l||!l.family||l.status!=="loaded"||!l._snapdomSrc)continue;let d=String(l.family).replace(/^['"]+|['"]+$/g,"");if(I(d)||!a.has(d.toLowerCase())||n?.families&&n.families.some(b=>String(b).toLowerCase()===d.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 b=await F(l._snapdomSrc,{as:"dataURL",useProxy:c,silent:!0});if(b.ok&&typeof b.data=="string")y=b.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}}S+=`@font-face{font-family:'${d}';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 d=String(l.family||"").replace(/^['"]+|['"]+$/g,"");if(!d||I(d)||!a.has(d.toLowerCase())||n?.families&&n.families.some(L=>String(L).toLowerCase()===d.toLowerCase()))continue;let y=l.weight!=null?String(l.weight):"normal",b=l.style!=null?String(l.style):"normal",w=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 L=await F(x,{as:"dataURL",useProxy:c,silent:!0});if(L.ok&&typeof L.data=="string")A=L.data,f.resource?.set(x,A),f.font?.add(x);else continue}catch{console.warn("[snapDOM] Failed to fetch localFonts src:",x);continue}}S+=`@font-face{font-family:'${d}';src:url(${A});font-style:${b};font-weight:${y};font-stretch:${w};}`}return S&&(S=Ht(S),f.resource?.set(m,S)),S}function bt(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))},s=i=>{let u=Dt(i.fontFamily);if(u.length)for(let m of u)n.add(`${m}__${X(i.fontWeight)}__${z(i.fontStyle)}__${Wt(i.fontStretch)}`)},r=i=>{s(D(i));for(let u of["::before","::after"]){let m=D(i,u),p=m&&m.content;if(!(!p||p==="none"||p==="normal"))if(s(m),/^["']/.test(p))c(p.slice(1,-1));else{let h=p.match(/\\[0-9A-Fa-f]{1,6}/g);if(h)for(let C of h)try{o.add(parseInt(C.slice(1),16))}catch{}}}};r(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;r(i)}}return{required:n,usedCodepoints:o}}async function xt(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 s=n.createElement("div");s.setAttribute("data-snapdom-internal",""),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 a=n.createElement("span");a.textContent="AaBbGg1234\xC1\xC9\xCD\xD3\xDA\xE7\xF1\u2014\u221E",a.style.fontFamily=`"${r}"`,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",s.appendChild(a)}n.body.appendChild(s),s.offsetWidth,n.body.removeChild(s)};for(let s=0;s<Math.max(1,e);s++)c(),await new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r)))}var Ct=["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 De(t=document,e={}){let{embedFonts:n=!0,useProxy:o=""}=e,c=e.cache??e.cacheOpt??"full";et(c);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 R(100),f.background=f.background||new R(100);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 a=[];for(let i of s){let u=i?.currentSrc||i?.src;if(u&&!f.image.has(u)){let m=Promise.resolve().then(async()=>{let p=await F(u,{as:"dataURL",useProxy:o});p?.ok&&typeof p.data=="string"&&f.image.set(u,p.data)}).catch(()=>{});a.push(m)}}for(let i of r){let u=new Set;for(let m of Ct){let p="";try{p=m==="background-image"&&i?.style?.backgroundImage||D(i).getPropertyValue(m)||""}catch{}if(!p||p==="none")continue;let h=p.match(/url\((?:[^()"']+|"(?:[^"]*)"|'(?:[^']*)')\)/gi)||[];for(let C of h){if(u.has(C))continue;u.add(C);let $=Promise.resolve().then(()=>H(C,{...e,useProxy:o})).catch(()=>{});a.push($)}}}if(n)try{let{required:i,usedCodepoints:u}=bt(t);if(typeof B=="function"?B():!!B){let p=new Set(Array.from(i).map(h=>String(h).split("__")[0]).filter(Boolean));await xt(p,3)}await St({required:i,usedCodepoints:u,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:e.useProxy??o,fontStylesheetDomains:e.fontStylesheetDomains})}catch{}await Promise.allSettled(a)}export{De as preCache};
|