@zumer/snapdom 2.23.2 → 2.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -28
- package/dist/plugins.mjs +1 -1
- package/dist/preCache.mjs +4 -4
- package/dist/snapdom.js +7 -7
- package/dist/snapdom.mjs +7 -7
- package/package.json +1 -1
- package/types/snapdom.d.ts +54 -3
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ await result.download({ format: 'jpg', filename: 'card.jpg' });
|
|
|
82
82
|
- [Installation](#installation)
|
|
83
83
|
- [Build Outputs](#build-outputs)
|
|
84
84
|
- [Usage](#usage)
|
|
85
|
-
- [Documentation](#documentation)
|
|
85
|
+
- [Documentation](#documentation): full API, Options, Plugins & Cache reference on [snapdom.dev/docs](https://snapdom.dev/docs/)
|
|
86
86
|
- [Limitations](#limitations)
|
|
87
87
|
- [Performance Benchmarks](#performance-benchmarks)
|
|
88
88
|
- [Development](#development)
|
|
@@ -198,7 +198,7 @@ When capturing elements that reference **external stylesheets** (e.g., Google Fo
|
|
|
198
198
|
### Why is this needed?
|
|
199
199
|
|
|
200
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
|
|
201
|
+
- SnapDOM relies on Canvas, which enforces strict CORS policies. The browser's rendering engine is more permissive for on‑screen display.
|
|
202
202
|
|
|
203
203
|
### How to fix it
|
|
204
204
|
|
|
@@ -216,12 +216,14 @@ Add the `crossorigin="anonymous"` attribute to the `<link>` tag when loading ext
|
|
|
216
216
|
|
|
217
217
|
## Documentation
|
|
218
218
|
|
|
219
|
-
The full reference lives on **[snapdom.dev/docs](https://snapdom.dev/docs/)
|
|
219
|
+
The full reference lives on **[snapdom.dev/docs](https://snapdom.dev/docs/)**, kept there so it stays in sync and searchable:
|
|
220
220
|
|
|
221
|
-
- **[API reference](https://snapdom.dev/docs/api/)
|
|
222
|
-
- **[Options](https://snapdom.dev/docs/options/)
|
|
223
|
-
- **[Plugins](https://snapdom.dev/docs/plugins/)
|
|
224
|
-
- **[Cache & preCache](https://snapdom.dev/docs/cache/)
|
|
221
|
+
- **[API reference](https://snapdom.dev/docs/api/)**: the `snapdom()` reusable object, shortcut methods, and exporter-specific options.
|
|
222
|
+
- **[Options](https://snapdom.dev/docs/options/)**: every capture option (`scale`, `dpr`, `embedFonts`, `useProxy`, `exclude`/`filter`, `compress`, `outerTransforms`, `outerShadows`, `cache`…) explained with examples.
|
|
223
|
+
- **[Plugins](https://snapdom.dev/docs/plugins/)**: build, register and ship custom plugins and export formats. Browse community plugins on the [plugins page](https://snapdom.dev/plugins.html).
|
|
224
|
+
- **[Cache & preCache](https://snapdom.dev/docs/cache/)**: control caching between captures and preload resources.
|
|
225
|
+
|
|
226
|
+
Popular guides: **[capture before creating a PDF](https://snapdom.dev/how-to/capture-before-pdf/)** · **[SnapDOM vs modern-screenshot](https://snapdom.dev/compare/modern-screenshot/)** · **[how SnapDOM captures the DOM](https://snapdom.dev/blog/painting-without-canvas/)**
|
|
225
227
|
|
|
226
228
|
### API at a glance
|
|
227
229
|
|
|
@@ -254,22 +256,22 @@ All options are optional and can be passed to `snapdom(el, options)` or any shor
|
|
|
254
256
|
| `embedFonts` | `boolean` | `false` | Inline `@font-face` so text renders with your real fonts |
|
|
255
257
|
| `iconFonts` | `string \| RegExp \| array` | `[]` | Icon font families (always embedded) |
|
|
256
258
|
| `localFonts` | `array` | `[]` | Explicit fonts: `{ family, src, weight?, style? }` |
|
|
257
|
-
| `excludeFonts` | `object` |
|
|
259
|
+
| `excludeFonts` | `object` | none | Skip fonts by family / domain / subset |
|
|
258
260
|
| `exclude` | `string[]` | `[]` | CSS selectors to leave out of the capture |
|
|
259
261
|
| `filter` | `(el) => boolean` | `null` | Keep-predicate (return `false` to drop a node) |
|
|
260
262
|
| `excludeMode` / `filterMode` | `'hide' \| 'remove'` | `'hide'` | How excluded nodes are handled |
|
|
261
263
|
| `clip` | `'viewport' \| {x, y, width, height}` | `null` | Capture only a region; offscreen content is pruned |
|
|
262
264
|
| `compress` | `boolean` | `true` | Downsample inlined images to their visible resolution |
|
|
263
265
|
| `useProxy` | `string` | `''` | CORS proxy prefix for cross-origin images |
|
|
264
|
-
| `fallbackURL` | `string \| fn` |
|
|
266
|
+
| `fallbackURL` | `string \| fn` | none | Fallback image for broken `<img>` |
|
|
265
267
|
| `cache` | `'soft' \| 'auto' \| 'full' \| 'disabled'` | `'soft'` | Cache policy between captures |
|
|
266
268
|
| `outerTransforms` | `boolean` | `true` | Keep root translate/rotate in the output |
|
|
267
269
|
| `outerShadows` | `boolean` | `false` | Expand bounds to include root shadows/blur/outline |
|
|
268
270
|
| `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
|
|
270
|
-
| `burst` | `boolean` | `false` | Memoizes repeated captures of this element via a scoped MutationObserver
|
|
271
|
+
| `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 |
|
|
272
|
+
| `burst` | `boolean` | `false` | Memoizes repeated captures of this element via a scoped MutationObserver, so an unchanged repeat skips the pipeline entirely. Without it, snapdom warns once if the same element is captured 3+ times within 2s |
|
|
271
273
|
| `invalidate` | `boolean` | `false` | With `burst: true`, forces a fresh capture for changes automatic tracking can't see (canvas draws, programmatic CSSOM edits) |
|
|
272
|
-
| `plugins` | `array` |
|
|
274
|
+
| `plugins` | `array` | none | Per-capture plugins (override globals by name) |
|
|
273
275
|
|
|
274
276
|
📖 **[Full API & every option, explained with examples → snapdom.dev/docs](https://snapdom.dev/docs/)**
|
|
275
277
|
|
|
@@ -278,7 +280,7 @@ All options are optional and can be passed to `snapdom(el, options)` or any shor
|
|
|
278
280
|
* External images should be CORS-accessible (use `useProxy` option for handling CORS denied)
|
|
279
281
|
* When WebP format is used on Safari, it will fallback to PNG rendering.
|
|
280
282
|
* `@font-face` CSS rule is well supported, but if need to use JS `FontFace()`, see this workaround [`#43`](https://github.com/zumerlab/snapdom/issues/43)
|
|
281
|
-
* **Safari**: captures with `embedFonts` or background/mask images run slower due to [WebKit #219770](https://bugs.webkit.org/show_bug.cgi?id=219770) (font decode timing). SnapDOM
|
|
283
|
+
* **Safari**: captures with `embedFonts` or background/mask images run slower due to [WebKit #219770](https://bugs.webkit.org/show_bug.cgi?id=219770) (font decode timing). SnapDOM waits for the fonts the element actually uses and verifies the first canvas draw, so there is nothing to configure.
|
|
282
284
|
* **Custom scrollbar styles** (`::-webkit-scrollbar`): Applied only when the element has *not* been scrolled. When scrolled, the viewport content is captured without the scrollbar.
|
|
283
285
|
|
|
284
286
|
|
|
@@ -390,7 +392,7 @@ If you'd like to support this project too, you can [become a sponsor](https://gi
|
|
|
390
392
|
|
|
391
393
|
## Show your support
|
|
392
394
|
|
|
393
|
-
If SnapDOM saved you time, a ⭐ on GitHub helps other developers find it
|
|
395
|
+
If SnapDOM saved you time, a ⭐ on GitHub helps other developers find it. That's the whole ask.
|
|
394
396
|
|
|
395
397
|
Shipping something built with SnapDOM? Add the badge to your README:
|
|
396
398
|
|
|
@@ -404,20 +406,20 @@ Shipping something built with SnapDOM? Add the badge to your README:
|
|
|
404
406
|
|
|
405
407
|
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`:
|
|
406
408
|
|
|
407
|
-
- [LobeHub](https://github.com/lobehub/lobehub)
|
|
408
|
-
- [Trilium Notes](https://github.com/TriliumNext/Trilium)
|
|
409
|
-
- [Sealos](https://github.com/labring/sealos)
|
|
410
|
-
- [Tencent tmagic-editor](https://github.com/Tencent/tmagic-editor)
|
|
411
|
-
- [Playroom](https://github.com/seek-oss/playroom)
|
|
412
|
-
- [GPT-Vis](https://github.com/antvis/GPT-Vis)
|
|
413
|
-
- [Rabby Wallet](https://github.com/RabbyHub/Rabby)
|
|
414
|
-
- [uMap](https://github.com/umap-project/umap)
|
|
415
|
-
- [ListenBrainz](https://github.com/metabrainz/listenbrainz-server)
|
|
416
|
-
- [Mind Elixir](https://github.com/SSShooter/mind-elixir-core)
|
|
417
|
-
- [Kong UI Components](https://github.com/Kong/public-ui-components)
|
|
418
|
-
- [SnapDIFF](https://zumerlab.com/snapdiff/)
|
|
419
|
-
|
|
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
|
|
409
|
+
- [LobeHub](https://github.com/lobehub/lobehub): platform for operating AI agents
|
|
410
|
+
- [Trilium Notes](https://github.com/TriliumNext/Trilium): hierarchical personal knowledge base
|
|
411
|
+
- [Sealos](https://github.com/labring/sealos): AI-native cloud operating system
|
|
412
|
+
- [Tencent tmagic-editor](https://github.com/Tencent/tmagic-editor): low-code page editor
|
|
413
|
+
- [Playroom](https://github.com/seek-oss/playroom): JSX design tool by SEEK
|
|
414
|
+
- [GPT-Vis](https://github.com/antvis/GPT-Vis): AI-friendly data viz by Ant Group's AntV
|
|
415
|
+
- [Rabby Wallet](https://github.com/RabbyHub/Rabby): browser wallet for EVM chains
|
|
416
|
+
- [uMap](https://github.com/umap-project/umap): OpenStreetMap map builder
|
|
417
|
+
- [ListenBrainz](https://github.com/metabrainz/listenbrainz-server): music tracker by MetaBrainz
|
|
418
|
+
- [Mind Elixir](https://github.com/SSShooter/mind-elixir-core): mind-map core; recommends SnapDOM for image export
|
|
419
|
+
- [Kong UI Components](https://github.com/Kong/public-ui-components): Kong's dashboard renderer exports PDFs with SnapDOM
|
|
420
|
+
- [SnapDIFF](https://zumerlab.com/snapdiff/): in-browser visual regression testing *(by Zumerlab)*
|
|
421
|
+
|
|
422
|
+
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.
|
|
421
423
|
|
|
422
424
|
## License
|
|
423
425
|
|
package/dist/plugins.mjs
CHANGED
package/dist/preCache.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* SnapDOM
|
|
3
|
-
* v2.
|
|
3
|
+
* v2.24.1
|
|
4
4
|
* Author: Juan Martin Muda
|
|
5
5
|
* License: MIT
|
|
6
6
|
*/
|
|
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 rt(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 X(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 st(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&&!$t.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 q(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function it(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 Lt(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 at=Lt("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),Y=new Map,z=new Map;function Rt(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 _t(t,e){if(!e||Rt(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 Ft(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 ct(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 Et(t,e){return[e.as||"blob",e.timeout??3e3,e.useProxy||"",e.errorTTL??8e3,t].join("|")}async function I(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[,h="",x=""]=String(t).match(/^data:([^,]*),(.*)$/)||[],_=/;base64/i.test(h)?atob(x):decodeURIComponent(x),l=new Uint8Array([..._].map(y=>y.charCodeAt(0))),g=new Blob([l],{type:(h||"").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 h=await fetch(t);if(!h.ok)return{ok:!1,data:null,status:h.status,url:t,fromCache:!1,reason:"http_error"};let x=await h.blob(),M=x.type||h.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await ct(x),status:h.status,url:t,fromCache:!1,mime:M}:n==="text"?{ok:!0,data:await x.text(),status:h.status,url:t,fromCache:!1,mime:M}:{ok:!0,data:x,status:h.status,url:t,fromCache:!1,mime:M}}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=Et(t,{as:n,timeout:o,useProxy:c,errorTTL:s}),u=z.get(i);if(u&&u.until>Date.now())return{...u.result,fromCache:!0};u&&z.delete(i);let m=Y.get(i);if(m)return m;let d=_t(t,c)?Ft(t,c):t,p=e.credentials;if(!p)try{let h=typeof location<"u"&&location.href?location.href:"http://localhost/",x=new URL(t,h);p=typeof location<"u"&&x.origin===location.origin?"include":"omit"}catch{p="omit"}let b=new AbortController,$=setTimeout(()=>b.abort("timeout"),o),w=(async()=>{try{let h=await fetch(d,{signal:b.signal,credentials:p,headers:r});if(!h.ok){let _={ok:!1,data:null,status:h.status,url:d,fromCache:!1,reason:"http_error"};if(s>0&&z.set(i,{until:Date.now()+s,result:_}),!a){let l=`${h.status} ${h.statusText||""}`.trim();at.warnOnce(`http:${h.status}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,`HTTP error ${l} while fetching ${n} ${t}`)}return e.onError&&e.onError(_),_}if(n==="text")return{ok:!0,data:await h.text(),status:h.status,url:d,fromCache:!1};let x=await h.blob(),M=x.type||h.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await ct(x),status:h.status,url:d,fromCache:!1,mime:M}:{ok:!0,data:x,status:h.status,url:d,fromCache:!1,mime:M}}catch(h){let x=h&&typeof h=="object"&&"name"in h&&h.name==="AbortError"?String(h.message||"").includes("timeout")?"timeout":"abort":"network",M={ok:!1,data:null,status:0,url:d,fromCache:!1,reason:x};if(!/^blob:/i.test(t)&&s>0&&z.set(i,{until:Date.now()+s,result:M}),!a){let _=`${x}:${n}:${new URL(t,location?.href??"http://localhost/").origin}`,l=x==="timeout"?`Timeout after ${o}ms. Consider increasing timeout or using a proxy for ${t}`:x==="abort"?`Request aborted while fetching ${n} ${t}`:`Network/CORS issue while fetching ${n} ${t}. A proxy may be required`;at.errorOnce(_,l)}return e.onError&&e.onError(M),M}finally{clearTimeout($),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=st(t,typeof devicePixelRatio<"u"&&devicePixelRatio||1)??X(t);if(!o)return t;let c=it(o),s=q(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 I(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 ft=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","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();ft.has(e)||J.has(e)||ut(e)}}function ut(t){if(t=String(t).toLowerCase(),J.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(mt(s))continue;let r=o.getPropertyValue(s);c[s]=r}return e.removeChild(n),f.defaultStyle.set(t,c),c}var It=/(?:^|-)(animation|transition)(?:-|$)/i,Tt=/^(--.+|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,vt=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"]),lt=new Map;function mt(t){let e=lt.get(t);if(e===void 0){let n=String(t).toLowerCase();e=vt.has(n)||Tt.test(n)||It.test(n),lt.set(t,e)}return e}function Ot(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 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=Ot(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 j(){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 Pt=[/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],Le=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=[...Pt,...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 gt=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]),Wt=["katex","mathjax","mathml"];function nt(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!gt.has(n.toLowerCase()))return n}return""}function Bt(t){if(!t)return[];let e=[];for(let n of t.split(",")){let o=n.trim().replace(/^['"]+|['"]+$/g,"");o&&(gt.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 Nt(t){let e=String(t??"100%").match(/(\d+(?:\.\d+)?)\s*%/);return e?Math.max(50,Math.min(200,parseFloat(e[1]))):100}function qt(t){let e=String(t||"400").trim(),n=e.match(/^(\d{2,3})\s+(\d{2,3})$/);if(n){let c=G(n[1]),s=G(n[2]);return{min:Math.min(c,s),max:Math.max(c,s)}}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 Vt(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 Xt(t){return!t||typeof t!="string"?"":t.replace(/\s+(variable|vf|v[0-9]+)$/i,"").trim().toLowerCase().replace(/\s+/g,"-")}function zt(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)||Wt.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 Gt(t){let e=new Set;for(let n of t||[]){let o=String(n).split("__")[0]?.trim();o&&e.add(o)}return e}function dt(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 tt=/@import\s+(?:url\(\s*(['"]?)([^)"']+)\1\s*\)|(['"])([^"']+)\3)([^;]*);/g,H=4;async function Kt(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>H)return console.warn(`[snapDOM] @import depth exceeded (${H}) at ${i}`),a;let m="",d=0,p;for(;p=tt.exec(a);){m+=a.slice(d,p.index),d=tt.lastIndex;let b=(p[2]||p[4]||"").trim(),$=c(b,i);if(o.has($)){console.warn(`[snapDOM] Skipping circular @import: ${$}`);continue}o.add($);let w="";try{let h=await I($,{as:"text",useProxy:n,silent:!0});h.ok&&typeof h.data=="string"&&(w=h.data)}catch{}w?(w=dt(w,$),w=await s(w,$,u+1),m+=`
|
|
8
|
-
/* inlined: ${
|
|
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 rt(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 X(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 st(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&&!Rt.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 q(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function it(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 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 at=$t("[snapDOM]",{ttlMs:3*6e4,maxEntries:10}),Y=new Map,z=new Map;function Lt(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 _t(t,e){if(!e||Lt(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 Ft(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 ct(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 Et(t,e){return[e.as||"blob",e.timeout??3e3,e.useProxy||"",e.errorTTL??8e3,t].join("|")}async function I(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[,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(),$=b.type||p.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await ct(b),status:p.status,url:t,fromCache:!1,mime:$}:n==="text"?{ok:!0,data:await b.text(),status:p.status,url:t,fromCache:!1,mime:$}:{ok:!0,data:b,status:p.status,url:t,fromCache:!1,mime:$}}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=Et(t,{as:n,timeout:o,useProxy:c,errorTTL:s}),u=z.get(i);if(u&&u.until>Date.now())return{...u.result,fromCache:!0};u&&z.delete(i);let m=Y.get(i);if(m)return m;let d=_t(t,c)?Ft(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:r});if(!p.ok){let M={ok:!1,data:null,status:p.status,url:d,fromCache:!1,reason:"http_error"};if(s>0&&z.set(i,{until:Date.now()+s,result:M}),!a){let l=`${p.status} ${p.statusText||""}`.trim();at.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(),$=b.type||p.headers.get("content-type")||"";return n==="dataURL"?{ok:!0,data:await ct(b),status:p.status,url:d,fromCache:!1,mime:$}:{ok:!0,data:b,status:p.status,url:d,fromCache:!1,mime:$}}catch(p){let b=p&&typeof p=="object"&&"name"in p&&p.name==="AbortError"?String(p.message||"").includes("timeout")?"timeout":"abort":"network",$={ok:!1,data:null,status:0,url:d,fromCache:!1,reason:b};if(!/^blob:/i.test(t)&&s>0&&z.set(i,{until:Date.now()+s,result:$}),!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`;at.errorOnce(M,l)}return e.onError&&e.onError($),$}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=st(t,typeof devicePixelRatio<"u"&&devicePixelRatio||1)??X(t);if(!o)return t;let c=it(o),s=q(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 I(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 ft=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","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();ft.has(e)||J.has(e)||ut(e)}}function ut(t){if(t=String(t).toLowerCase(),J.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(mt(s))continue;let r=o.getPropertyValue(s);c[s]=r}return e.removeChild(n),f.defaultStyle.set(t,c),c}var It=/(?:^|-)(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,Tt=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"]),lt=new Map;function mt(t){let e=lt.get(t);if(e===void 0){let n=String(t).toLowerCase();e=Tt.has(n)||vt.test(n)||It.test(n),lt.set(t,e)}return e}function Ot(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 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=Ot(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 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),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 Pt=[/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__||{}),Dt=[];function T(t){let e=typeof t=="string"?t:"",n=[...Pt,...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 gt=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","emoji","math","fangsong","ui-serif","ui-sans-serif","ui-monospace","ui-rounded"]),Wt=["katex","mathjax","mathml"];function nt(t){if(!t)return"";for(let e of t.split(",")){let n=e.trim().replace(/^['"]+|['"]+$/g,"");if(n&&!gt.has(n.toLowerCase()))return n}return""}function Bt(t){if(!t)return[];let e=[];for(let n of t.split(",")){let o=n.trim().replace(/^['"]+|['"]+$/g,"");o&&(gt.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 Nt(t){let e=String(t??"100%").match(/(\d+(?:\.\d+)?)\s*%/);return e?Math.max(50,Math.min(200,parseFloat(e[1]))):100}function qt(t){let e=String(t||"400").trim(),n=e.match(/^(\d{2,3})\s+(\d{2,3})$/);if(n){let c=G(n[1]),s=G(n[2]);return{min:Math.min(c,s),max:Math.max(c,s)}}let o=G(e);return{min:o,max:o}}function Vt(t){let e=String(t||"normal").trim().toLowerCase();return e==="italic"?{kind:"italic"}:e.startsWith("oblique")?{kind:"oblique"}:{kind:"normal"}}function jt(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 Xt(t){return!t||typeof t!="string"?"":t.replace(/\s+(variable|vf|v[0-9]+)$/i,"").trim().toLowerCase().replace(/\s+/g,"-")}function zt(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)||Wt.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 Gt(t){let e=new Set;for(let n of t||[]){let o=String(n).split("__")[0]?.trim();o&&e.add(o)}return e}function dt(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 tt=/@import\s+(?:url\(\s*(['"]?)([^)"']+)\1\s*\)|(['"])([^"']+)\3)([^;]*);/g,H=4;async function Kt(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>H)return console.warn(`[snapDOM] @import depth exceeded (${H}) at ${i}`),a;let m="",d=0,h;for(;h=tt.exec(a);){m+=a.slice(d,h.index),d=tt.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 I(A,{as:"text",useProxy:n,silent:!0});p.ok&&typeof p.data=="string"&&(w=p.data)}catch{}w?(w=dt(w,A),w=await s(w,A,u+1),m+=`
|
|
8
|
+
/* inlined: ${A} */
|
|
9
9
|
${w}
|
|
10
|
-
`):m+=p[0]}return m+=a.slice(d),m}let r=dt(t,e||location.href);return r=await s(r,e||location.href,0),r}var yt=/url\((["']?)([^"')]+)\1\)/g,Ht=/@font-face[^{}]*\{[^}]*\}/g;function U(t,e,n=""){return(t.match(new RegExp(`${e}\\s*:\\s*([^;}]+)[;}]`,"i"))?.[1]||n).trim()}function wt(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,d=Array.isArray(u)?u[1]:u;e.push([Math.min(m,d),Math.max(m,d)])}else{let i=a(s);Array.isArray(i)?e.push([i[0],i[1]]):e.push([i,i])}}return e}function St(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 ot(t,e){let n=[];if(!t)return n;for(let o of t.matchAll(yt)){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 et(t,e,n=""){let o=t;for(let c of t.matchAll(yt)){let s=X(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(!v(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 I(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 Yt(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 pt(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=Yt(s);if(r&&o.has(r))return!0}return!1}}function Qt(t){if(!t)return t;let e=/@font-face[^{}]*\{[^}]*\}/gi,n=new Set,o=[];for(let s of t.match(e)||[]){let r=U(s,"font-family"),a=nt(r),i=U(s,"font-weight","400"),u=U(s,"font-style","normal"),m=U(s,"font-stretch","100%"),d=U(s,"unicode-range"),p=U(s,"src"),b=ot(p,location.href),$=b.length?b.map(h=>String(h).toLowerCase()).sort().join("|"):p.toLowerCase(),w=[String(a||"").toLowerCase(),i,u,m,d.toLowerCase(),$].join("|");n.has(w)||(n.add(w),o.push(s))}if(o.length===0)return t;let c=0;return t.replace(e,()=>o[c++]||"")}var ht=new WeakMap,Jt=0;function Zt(t){let e=ht.get(t);return e===void 0&&(e=Jt++,ht.set(t,e)),e}function te(t,e,n,o,c,s){let r=Array.from(t||[]).sort().join("|"),a=e?JSON.stringify({families:(e.families||[]).map(p=>String(p).toLowerCase()).sort(),domains:(e.domains||[]).map(p=>String(p).toLowerCase()).sort(),subsets:(e.subsets||[]).map(p=>String(p).toLowerCase()).sort()}):"",i=(n||[]).map(p=>`${(p.family||"").toLowerCase()}::${p.weight||"normal"}::${p.style||"normal"}::${p.src||""}`).sort().join("|"),u=o||"",m=(c||[]).map(p=>String(p).toLowerCase()).sort().join("|"),d=Zt(s||document);return`fonts-embed-css::req=${r}::ex=${a}::lf=${i}::px=${u}::fd=${m}::doc=${d}`}async function bt(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>=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 bt(r.styleSheet,a,n,i);continue}if(r.type===CSSRule.FONT_FACE_RULE){let a=(r.style.getPropertyValue("font-family")||"").trim(),i=nt(a);if(!i||v(i))continue;let u=(r.style.getPropertyValue("font-weight")||"400").trim(),m=(r.style.getPropertyValue("font-style")||"normal").trim(),d=(r.style.getPropertyValue("font-stretch")||"100%").trim(),p=(r.style.getPropertyValue("src")||"").trim(),b=(r.style.getPropertyValue("unicode-range")||"").trim(),$=o.faceMatchesRequired(i,m,u,d);if(!$&&!o.requiredIndex.has(i.toLowerCase()))continue;let w=wt(b);if(!St(o.usedCodepoints,w))continue;let h={family:i,weightSpec:u,styleSpec:m,stretchSpec:d,unicodeRange:b,srcRaw:p,srcUrls:ot(p,e||location.href),href:e||location.href};if(o.simpleExcluder&&o.simpleExcluder(h,w))continue;if(!$){o.provisionalFaces.push({family:i.toLowerCase(),block:`@font-face{font-family:${i};src:${p};font-style:${m};font-weight:${u};font-stretch:${d};${b?`unicode-range:${b};`:""}}`,srcRaw:p,baseHref:e||location.href});continue}if(o.coveredFamilies.add(i.toLowerCase()),/url\(/i.test(p)){let x=await et(p,e||location.href,o.useProxy);await n(`@font-face{font-family:${i};src:${x};font-style:${m};font-weight:${u};font-stretch:${d};${b?`unicode-range:${b};`:""}}`)}else await n(`@font-face{font-family:${i};src:${p};font-style:${m};font-weight:${u};font-stretch:${d};${b?`unicode-range:${b};`:""}}`)}}}async function xt({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[g,y,A,S]=String(l).split("__");if(!g)continue;let k=g.toLowerCase(),C=a.get(k)||[];C.push({w:parseInt(y,10),s:A,st:parseInt(S,10)}),a.set(k,C)}function i(l,g,y,A){let S=String(l).toLowerCase();if(!a.has(S))return!1;let k=a.get(S),C=qt(y),F=jt(g),T=Vt(A),D=C.min!==C.max,W=C.min,O=L=>F.kind==="normal"&&L==="normal"||F.kind!=="normal"&&(L==="italic"||L==="oblique"),V=!1;for(let L of k){let E=D?L.w>=C.min&&L.w<=C.max:L.w===W,P=O(K(L.s)),B=L.st>=T.min&&L.st<=T.max;if(E&&P&&B){V=!0;break}}if(V)return!0;if(!D)for(let L of k){let E=O(K(L.s)),P=L.st>=T.min&&L.st<=T.max;if(Math.abs(W-L.w)<=300&&E&&P)return!0}if(!D&&F.kind==="normal"&&k.some(E=>K(E.s)!=="normal"))for(let E of k){let P=Math.abs(W-E.w)<=300,B=E.st>=T.min&&E.st<=T.max;if(P&&B)return!0}return!1}let u=pt(n),m=te(t,n,o,c,s,r);if(f.resource?.has(m))return f.resource.get(m);let d=Gt(t),p=[],b=tt;for(let l of r.querySelectorAll("style")){let g=l.textContent||"";for(let y of g.matchAll(b)){let A=(y[2]||y[4]||"").trim();if(!A||v(A))continue;r.querySelector(`link[rel="stylesheet"][href="${A}"]`)||p.push(A)}}let $=[];p.length&&await Promise.all(p.map(l=>new Promise(g=>{if(r.querySelector(`link[rel="stylesheet"][href="${l}"]`))return g(null);let y=r.createElement("link");y.rel="stylesheet",y.href=l,y.setAttribute("data-snapdom","injected-import"),y.onload=()=>g(y),y.onerror=()=>g(null),r.head.appendChild(y),$.push(y)})));let w="",h=new Set,x=[],M=Array.from(r.querySelectorAll('link[rel="stylesheet"]')).filter(l=>!!l.href);for(let l of $)try{l.remove()}catch{}for(let l of M)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(s)?s:[];if(!zt(l.href,d,S))continue}if(y){let S=Array.from(r.styleSheets).find(k=>k.href===l.href);if(S)try{let k=S.cssRules||[];g=Array.from(k).map(C=>C.cssText).join("")}catch{}}if(!g){let S=await I(l.href,{as:"text",useProxy:c});if(S?.ok&&typeof S.data=="string"&&(g=S.data),v(l.href))continue}g=await Kt(g,l.href,c);let A="";for(let S of g.match(Ht)||[]){let k=U(S,"font-family"),C=nt(k);if(!C||v(C))continue;let F=U(S,"font-weight","400"),T=U(S,"font-style","normal"),D=U(S,"font-stretch","100%"),W=U(S,"unicode-range"),O=U(S,"src"),V=ot(O,l.href),L=i(C,T,F,D);if(!L&&!a.has(C.toLowerCase()))continue;let E=wt(W);if(!St(e,E))continue;let P={family:C,weightSpec:F,styleSpec:T,stretchSpec:D,unicodeRange:W,srcRaw:O,srcUrls:V,href:l.href};if(n&&u(P,E))continue;if(!L){x.push({family:C.toLowerCase(),block:S,srcRaw:O,baseHref:l.href});continue}h.add(C.toLowerCase());let B=/url\(/i.test(O)?await et(S,l.href,c):S;A+=B}A.trim()&&(w+=A)}catch{console.warn("[snapDOM] Failed to process stylesheet:",l.href)}let _={requiredIndex:a,usedCodepoints:e,faceMatchesRequired:i,coveredFamilies:h,provisionalFaces:x,simpleExcluder:n?pt(n):null,useProxy:c,visitedSheets:new Set,depth:0};for(let l of r.styleSheets)if(!(l.href&&M.some(g=>g.href===l.href)))try{let g=l.href||location.origin+"/";g&&_.visitedSheets.add(g),await bt(l,g,async y=>{w+=y},_)}catch{}for(let l of x)h.has(l.family)||(w+=/url\(/i.test(l.srcRaw)?await et(l.block,l.baseHref,c):l.block);try{for(let l of r.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(A=>String(A).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 A=await I(l._snapdomSrc,{as:"dataURL",useProxy:c,silent:!0});if(A.ok&&typeof A.data=="string")y=A.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",A=l.style!=null?String(l.style):"normal",S=l.stretchPct!=null?`${l.stretchPct}%`:"100%",k=String(l.src||""),C=k;if(!C.startsWith("data:")){if(f.resource?.has(k))C=f.resource.get(k),f.font?.add(k);else if(!f.font?.has(k))try{let F=await I(k,{as:"dataURL",useProxy:c,silent:!0});if(F.ok&&typeof F.data=="string")C=F.data,f.resource?.set(k,C),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(${C});font-style:${A};font-weight:${y};font-stretch:${S};}`}return w&&(w=Qt(w),f.resource?.set(m,w)),w}function Ct(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=Bt(i.fontFamily);if(u.length)for(let m of u)n.add(`${m}__${G(i.fontWeight)}__${K(i.fontStyle)}__${Nt(i.fontStretch)}`)},r=i=>{s(N(i));for(let u of["::before","::after"]){let m=N(i,u),d=m&&m.content;if(!(!d||d==="none"||d==="normal"))if(s(m),/^["']/.test(d))c(d.slice(1,-1));else{let p=d.match(/\\[0-9A-Fa-f]{1,6}/g);if(p)for(let b of p)try{o.add(parseInt(b.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 kt(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 At=["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 Be(t=document,e={}){let{embedFonts:n=!0,useProxy:o=""}=e,c=e.cache??e.cacheOpt??"full";rt(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 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 d=await I(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 r){let u=new Set;for(let m of At){let d="";try{d=m==="background-image"&&i?.style?.backgroundImage||N(i).getPropertyValue(m)||""}catch{}if(!d||d==="none")continue;let p=d.match(/url\((?:[^()"']+|"(?:[^"]*)"|'(?:[^']*)')\)/gi)||[];for(let b of p){if(u.has(b))continue;u.add(b);let $=Promise.resolve().then(()=>Q(b,{...e,useProxy:o})).catch(()=>{});a.push($)}}}if(n)try{let{required:i,usedCodepoints:u}=Ct(t);if(typeof j=="function"?j():!!j){let d=new Set(Array.from(i).map(p=>String(p).split("__")[0]).filter(Boolean));await kt(d,3)}await xt({required:i,usedCodepoints:u,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:e.useProxy??o,fontStylesheetDomains:e.fontStylesheetDomains})}catch{}await Promise.allSettled(a)}export{Be as preCache};
|
|
10
|
+
`):m+=h[0]}return m+=a.slice(d),m}let r=dt(t,e||location.href);return r=await s(r,e||location.href,0),r}var yt=/url\((["']?)([^"')]+)\1\)/g,Ht=/@font-face[^{}]*\{[^}]*\}/g;function U(t,e,n=""){return(t.match(new RegExp(`${e}\\s*:\\s*([^;}]+)[;}]`,"i"))?.[1]||n).trim()}function wt(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,d=Array.isArray(u)?u[1]:u;e.push([Math.min(m,d),Math.max(m,d)])}else{let i=a(s);Array.isArray(i)?e.push([i[0],i[1]]):e.push([i,i])}}return e}function St(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 ot(t,e){let n=[];if(!t)return n;for(let o of t.matchAll(yt)){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 et(t,e,n=""){let o=t;for(let c of t.matchAll(yt)){let s=X(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(!T(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 I(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 Yt(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 pt(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=Yt(s);if(r&&o.has(r))return!0}return!1}}function Qt(t){if(!t)return t;let e=/@font-face[^{}]*\{[^}]*\}/gi,n=new Set,o=[];for(let s of t.match(e)||[]){let r=U(s,"font-family"),a=nt(r),i=U(s,"font-weight","400"),u=U(s,"font-style","normal"),m=U(s,"font-stretch","100%"),d=U(s,"unicode-range"),h=U(s,"src"),C=ot(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(s))}if(o.length===0)return t;let c=0;return t.replace(e,()=>o[c++]||"")}var ht=new WeakMap,Jt=0;function Zt(t){let e=ht.get(t);return e===void 0&&(e=Jt++,ht.set(t,e)),e}function te(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("|"),d=Zt(s||document);return`fonts-embed-css::req=${r}::ex=${a}::lf=${i}::px=${u}::fd=${m}::doc=${d}`}async function bt(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>=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 bt(r.styleSheet,a,n,i);continue}if(r.type===CSSRule.FONT_FACE_RULE){let a=(r.style.getPropertyValue("font-family")||"").trim(),i=nt(a);if(!i||T(i))continue;let u=(r.style.getPropertyValue("font-weight")||"").trim(),m=(r.style.getPropertyValue("font-style")||"").trim(),d=(r.style.getPropertyValue("font-stretch")||"").trim(),h=(r.style.getPropertyValue("font-variation-settings")||"").trim(),C=(r.style.getPropertyValue("src")||"").trim(),A=(r.style.getPropertyValue("unicode-range")||"").trim(),w=u||"400",p=m||"normal",b=d||"100%",$=(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=wt(A);if(!St(o.usedCodepoints,l))continue;let g={family:i,weightSpec:w,styleSpec:p,stretchSpec:b,unicodeRange:A,srcRaw:C,srcUrls:ot(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};${$}}`,srcRaw:C,baseHref:e||location.href});continue}if(o.coveredFamilies.add(i.toLowerCase()),/url\(/i.test(C)){let y=await et(C,e||location.href,o.useProxy);await n(`@font-face{font-family:${i};src:${y};${$}}`)}else await n(`@font-face{font-family:${i};src:${C};${$}}`)}}}async function xt({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[g,y,R,S]=String(l).split("__");if(!g)continue;let k=g.toLowerCase(),x=a.get(k)||[];x.push({w:parseInt(y,10),s:R,st:parseInt(S,10)}),a.set(k,x)}function i(l,g,y,R){let S=String(l).toLowerCase();if(!a.has(S))return!1;let k=a.get(S),x=qt(y),F=Vt(g),v=jt(R),D=x.min!==x.max,W=x.min,O=L=>F.kind==="normal"&&L==="normal"||F.kind!=="normal"&&(L==="italic"||L==="oblique"),j=!1;for(let L of k){let E=D?L.w>=x.min&&L.w<=x.max:L.w===W,P=O(K(L.s)),B=L.st>=v.min&&L.st<=v.max;if(E&&P&&B){j=!0;break}}if(j)return!0;if(!D)for(let L of k){let E=O(K(L.s)),P=L.st>=v.min&&L.st<=v.max;if(Math.abs(W-L.w)<=300&&E&&P)return!0}if(!D&&F.kind==="normal"&&k.some(E=>K(E.s)!=="normal"))for(let E of k){let P=Math.abs(W-E.w)<=300,B=E.st>=v.min&&E.st<=v.max;if(P&&B)return!0}return!1}let u=pt(n),m=te(t,n,o,c,s,r);if(f.resource?.has(m))return f.resource.get(m);let d=Gt(t),h=[],C=tt;for(let l of r.querySelectorAll("style")){let g=l.textContent||"";for(let y of g.matchAll(C)){let R=(y[2]||y[4]||"").trim();if(!R||T(R))continue;r.querySelector(`link[rel="stylesheet"][href="${R}"]`)||h.push(R)}}let A=[];h.length&&await Promise.all(h.map(l=>new Promise(g=>{if(r.querySelector(`link[rel="stylesheet"][href="${l}"]`))return g(null);let y=r.createElement("link");y.rel="stylesheet",y.href=l,y.setAttribute("data-snapdom","injected-import"),y.onload=()=>g(y),y.onerror=()=>g(null),r.head.appendChild(y),A.push(y)})));let w="",p=new Set,b=[],$=Array.from(r.querySelectorAll('link[rel="stylesheet"]')).filter(l=>!!l.href);for(let l of A)try{l.remove()}catch{}for(let l of $)try{if(T(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(s)?s:[];if(!zt(l.href,d,S))continue}if(y){let S=Array.from(r.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 I(l.href,{as:"text",useProxy:c});if(S?.ok&&typeof S.data=="string"&&(g=S.data),T(l.href))continue}g=await Kt(g,l.href,c);let R="";for(let S of g.match(Ht)||[]){let k=U(S,"font-family"),x=nt(k);if(!x||T(x))continue;let F=U(S,"font-weight","400"),v=U(S,"font-style","normal"),D=U(S,"font-stretch","100%"),W=U(S,"unicode-range"),O=U(S,"src"),j=ot(O,l.href),L=i(x,v,F,D);if(!L&&!a.has(x.toLowerCase()))continue;let E=wt(W);if(!St(e,E))continue;let P={family:x,weightSpec:F,styleSpec:v,stretchSpec:D,unicodeRange:W,srcRaw:O,srcUrls:j,href:l.href};if(n&&u(P,E))continue;if(!L){b.push({family:x.toLowerCase(),block:S,srcRaw:O,baseHref:l.href});continue}p.add(x.toLowerCase());let B=/url\(/i.test(O)?await et(S,l.href,c):S;R+=B}R.trim()&&(w+=R)}catch{console.warn("[snapDOM] Failed to process stylesheet:",l.href)}let M={requiredIndex:a,usedCodepoints:e,faceMatchesRequired:i,coveredFamilies:p,provisionalFaces:b,simpleExcluder:n?pt(n):null,useProxy:c,visitedSheets:new Set,depth:0};for(let l of r.styleSheets)if(!(l.href&&$.some(g=>g.href===l.href)))try{let g=l.href||location.origin+"/";g&&M.visitedSheets.add(g),await bt(l,g,async y=>{w+=y},M)}catch{}for(let l of b)p.has(l.family)||(w+=/url\(/i.test(l.srcRaw)?await et(l.block,l.baseHref,c):l.block);try{for(let l of r.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(R=>String(R).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 R=await I(l._snapdomSrc,{as:"dataURL",useProxy:c,silent:!0});if(R.ok&&typeof R.data=="string")y=R.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",R=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 I(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:${R};font-weight:${y};font-stretch:${S};}`}return w&&(w=Qt(w),f.resource?.set(m,w)),w}function Ct(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=Bt(i.fontFamily);if(u.length)for(let m of u)n.add(`${m}__${G(i.fontWeight)}__${K(i.fontStyle)}__${Nt(i.fontStretch)}`)},r=i=>{s(N(i));for(let u of["::before","::after"]){let m=N(i,u),d=m&&m.content;if(!(!d||d==="none"||d==="normal"))if(s(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{}}}};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 kt(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 At=["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 Be(t=document,e={}){let{embedFonts:n=!0,useProxy:o=""}=e,c=e.cache??e.cacheOpt??"full";rt(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 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 d=await I(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 r){let u=new Set;for(let m of At){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}=Ct(t);if(typeof V=="function"?V():!!V){let d=new Set(Array.from(i).map(h=>String(h).split("__")[0]).filter(Boolean));await kt(d,3)}await xt({required:i,usedCodepoints:u,exclude:e.excludeFonts,localFonts:e.localFonts,useProxy:e.useProxy??o,fontStylesheetDomains:e.fontStylesheetDomains})}catch{}await Promise.allSettled(a)}export{Be as preCache};
|