@zumer/snapdom 1.9.3 → 1.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -151,6 +151,9 @@ All capture methods accept an `options` object:
151
151
  | `backgroundColor` | string | `"#fff"` | Fallback color for JPG/WebP |
152
152
  | `quality` | number | `1` | Quality for JPG/WebP (0 to 1) |
153
153
  | `useProxy` | string | '' | Specify a proxy for handling CORS images as fallback|
154
+ | `type` | string | `svg` | Select `png`, `jpg`, `webp` Blob type|
155
+ | `exclude` | string[] | - | CSS selectors for elements to exclude |
156
+ | `filter` | function | - | Custom filter function ie `(el) => !el.classList.contains('hidden')` |
154
157
 
155
158
  ### Setting custom dimensions with width and height options
156
159
 
@@ -256,55 +259,51 @@ import { snapdom, preCache } from './snapdom.mjs';
256
259
 
257
260
  ## ⚡ Performance Benchmarks
258
261
 
259
- Snapdom has received **major performance improvements** since version `v1.8.0`. Below are benchmark results comparing:
262
+ Snapdom has received **significant performance improvements** since version `v1.8.0`. The following benchmarks compare:
260
263
 
261
- * 🔷 **Snapdom (current)**
262
- * 🔸 **Snapdom v1.8.0**
263
- * 🟥 `html2canvas`
264
- * 🟨 `modern-screenshot`
264
+ * **Snapdom (current)**
265
+ * **Snapdom v1.8.0**
266
+ * `html2canvas`
267
+ * `html-to-image`
265
268
 
266
- Each benchmark shows the **fastest observed time** (lower is better), measured in **milliseconds (ms)**.
267
-
268
- ---
269
269
 
270
270
  ### Simple elements
271
271
 
272
- | Scenario | Snapdom (current) | Snapdom v1.8.0 | html2canvas | modern-screenshot |
273
- | ------------------------ | ----------------- | -------------- | ----------- | ----------------- |
274
- | Small (200×100) | **0.4 ms** | 1.2 ms | 70.3 ms | 11.9 ms |
275
- | Modal (400×300) | **0.4 ms** | 1.1 ms | 68.8 ms | 14.1 ms |
276
- | Page View (1200×800) | **0.4 ms** | 1.0 ms | 100.5 ms | 34.2 ms |
277
- | Large Scroll (2000×1500) | **0.4 ms** | 1.0 ms | 153.1 ms | 77.8 ms |
278
- | Very Large (4000×2000) | **0.4 ms** | 1.0 ms | 278.9 ms | 194.7 ms |
272
+ | Scenario | Snapdom (current) | Snapdom v1.8.0 | html2canvas | html-to-image |
273
+ | ------------------------ | ----------------- | -------------- | ----------- | ------------- |
274
+ | Small (200×100) | **0.4 ms** | 1.2 ms | 70.3 ms | 3.6 ms |
275
+ | Modal (400×300) | **0.4 ms** | 1.1 ms | 68.8 ms | 3.6 ms |
276
+ | Page View (1200×800) | **0.4 ms** | 1.0 ms | 100.5 ms | 3.4 ms |
277
+ | Large Scroll (2000×1500) | **0.4 ms** | 1.0 ms | 153.1 ms | 3.4 ms |
278
+ | Very Large (4000×2000) | **0.4 ms** | 1.0 ms | 278.9 ms | 4.3 ms |
279
+
279
280
 
280
- ---
281
281
 
282
282
  ### Complex elements
283
283
 
284
- | Scenario | Snapdom (current) | Snapdom v1.8.0 | html2canvas | modern-screenshot |
285
- | ------------------------ | ----------------- | -------------- | ----------- | ----------------- |
286
- | Small (200×100) | **1.1 ms** | 3.2 ms | 72.5 ms | 16.1 ms |
287
- | Modal (400×300) | **4.5 ms** | 14.0 ms | 90.1 ms | 34.6 ms |
288
- | Page View (1200×800) | **32.9 ms** | 113.6 ms | 196.1 ms | 181.1 ms |
289
- | Large Scroll (2000×1500) | **133.9 ms** | 387.4 ms | 446.6 ms | 635.9 ms |
290
- | Very Large (4000×2000) | **364.0 ms** | 1,200.4 ms | 1,275.4 ms | 1,685.6 ms |
284
+ | Scenario | Snapdom (current) | Snapdom v1.8.0 | html2canvas | html-to-image |
285
+ | ------------------------ | ----------------- | -------------- | ----------- | ------------- |
286
+ | Small (200×100) | **1.1 ms** | 3.2 ms | 76.0 ms | 15.3 ms |
287
+ | Modal (400×300) | **4.5 ms** | 14.0 ms | 133.2 ms | 55.4 ms |
288
+ | Page View (1200×800) | **32.9 ms** | 113.6 ms | 303.4 ms | 369.1 ms |
289
+ | Large Scroll (2000×1500) | **133.9 ms** | 387.4 ms | 594.4 ms | 1,163.0 ms |
290
+ | Very Large (4000×2000) | **364.0 ms** | 1,200.4 ms | 1,380.8 ms | 3,023.9 ms |
291
+
291
292
 
292
- ---
293
293
 
294
294
  ### Summary
295
295
 
296
- * Snapdom (current) is consistently **2×–4× faster** than `v1.8.0`
297
- * Up to **500× faster** than `html2canvas`
298
- * Also significantly faster than `modern-screenshot`, especially for large DOMs
296
+ * Snapdom (current) is **2×–6× faster** than `v1.8.0`
297
+ * Up to **150× faster** than `html2canvas`
298
+ * Up to **8× faster** than `html-to-image` in large scenarios
299
299
 
300
- <sub>All benchmarks were run in Chromium using Vitest.<br>
301
- Tests were performed on a 2018 MacBook Air.<br>
302
- ⚠️ Performance can be even better on more modern hardware.</sub>
300
+ <sub>Benchmarks run in Chromium using Vitest.<br>
301
+ Hardware: MacBook Air 2018.<br>
302
+ ⚠️ Performance may vary depending on device.</sub>
303
303
 
304
304
 
305
- ### Run the benchmarks
306
305
 
307
- To run these benchmarks yourself:
306
+ ### Run the benchmarks
308
307
 
309
308
  ```sh
310
309
  git clone https://github.com/zumerlab/snapdom.git
@@ -313,8 +312,6 @@ npm install
313
312
  npm run test:benchmark
314
313
  ```
315
314
 
316
- They execute in **headless Chromium** using real DOM nodes.
317
-
318
315
  ## Development
319
316
 
320
317
  To contribute or build snapDOM locally:
@@ -324,6 +321,9 @@ To contribute or build snapDOM locally:
324
321
  git clone https://github.com/zumerlab/snapdom.git
325
322
  cd snapdom
326
323
 
324
+ # Switch to dev branch
325
+ git checkout dev
326
+
327
327
  # Install dependencies
328
328
  npm install
329
329
 
@@ -347,12 +347,14 @@ For detailed contribution guidelines, please see [CONTRIBUTING](https://github.c
347
347
  <!-- CONTRIBUTORS:START -->
348
348
  <p>
349
349
  <a href="https://github.com/tinchox5" title="tinchox5"><img src="https://avatars.githubusercontent.com/u/11557901?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="tinchox5"/></a>
350
+ <a href="https://github.com/tarwin" title="tarwin"><img src="https://avatars.githubusercontent.com/u/646149?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="tarwin"/></a>
350
351
  <a href="https://github.com/17biubiu" title="17biubiu"><img src="https://avatars.githubusercontent.com/u/13295895?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="17biubiu"/></a>
351
352
  <a href="https://github.com/pedrocateexte" title="pedrocateexte"><img src="https://avatars.githubusercontent.com/u/207524750?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="pedrocateexte"/></a>
352
353
  <a href="https://github.com/domialex" title="domialex"><img src="https://avatars.githubusercontent.com/u/4694217?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="domialex"/></a>
353
354
  <a href="https://github.com/elliots" title="elliots"><img src="https://avatars.githubusercontent.com/u/622455?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="elliots"/></a>
354
355
  <a href="https://github.com/jswhisperer" title="jswhisperer"><img src="https://avatars.githubusercontent.com/u/1177690?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="jswhisperer"/></a>
355
356
  <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>
357
+ <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>
356
358
  <a href="https://github.com/jhbae200" title="jhbae200"><img src="https://avatars.githubusercontent.com/u/20170610?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="jhbae200"/></a>
357
359
  </p>
358
360
  <!-- CONTRIBUTORS:END -->
package/dist/snapdom.js CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  /*
3
3
  * snapdom
4
- * v.1.9.3
4
+ * v.1.9.5
5
5
  * Author Juan Martin Muda
6
6
  * License MIT
7
7
  **/
@@ -205,11 +205,10 @@
205
205
  // src/utils/helpers.js
206
206
  function inlineSingleBackgroundEntry(_0) {
207
207
  return __async(this, arguments, function* (entry, options = {}) {
208
- const isUrl = entry.startsWith("url(");
208
+ const match = entry.match(/url\(["']?(.*?)["']?\)/);
209
+ const rawUrl = match == null ? void 0 : match[1];
209
210
  const isGradient = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(entry);
210
- if (isUrl) {
211
- const rawUrl = extractURL(entry);
212
- if (!rawUrl) return entry;
211
+ if (rawUrl) {
213
212
  const encodedUrl = safeEncodeURI(rawUrl);
214
213
  if (bgCache.has(encodedUrl)) {
215
214
  return options.skipInline ? void 0 : `url(${bgCache.get(encodedUrl)})`;
@@ -478,13 +477,12 @@
478
477
  }
479
478
 
480
479
  // src/core/clone.js
480
+ function isSlotElement(node) {
481
+ return node.nodeType === Node.ELEMENT_NODE && node.tagName === "SLOT";
482
+ }
481
483
  function deepClone(node, styleMap, styleCache, nodeMap, compress, options = {}, originalRoot) {
482
- var _a;
484
+ var _a, _b;
483
485
  if (node.nodeType === Node.TEXT_NODE) {
484
- if ((_a = node.parentElement) == null ? void 0 : _a.shadowRoot) {
485
- const tag = node.parentElement.tagName.toLowerCase();
486
- if (customElements.get(tag)) return null;
487
- }
488
486
  return node.cloneNode(true);
489
487
  }
490
488
  if (node.nodeType !== Node.ELEMENT_NODE) return node.cloneNode(true);
@@ -494,10 +492,10 @@
494
492
  spacer.style.cssText = `display: inline-block; width: ${rect.width}px; height: ${rect.height}px; visibility: hidden;`;
495
493
  return spacer;
496
494
  }
497
- if (options.exclude && Array.isArray(options.exclude) && options.exclude.length > 0) {
495
+ if (options.exclude && Array.isArray(options.exclude)) {
498
496
  for (const selector of options.exclude) {
499
497
  try {
500
- if (node.matches && node.matches(selector)) {
498
+ if ((_a = node.matches) == null ? void 0 : _a.call(node, selector)) {
501
499
  const spacer = document.createElement("div");
502
500
  const rect = node.getBoundingClientRect();
503
501
  spacer.style.cssText = `display: inline-block; width: ${rect.width}px; height: ${rect.height}px; visibility: hidden;`;
@@ -557,8 +555,10 @@
557
555
  if (node.checked) clone.setAttribute("checked", "");
558
556
  }
559
557
  } else if (node instanceof HTMLTextAreaElement) {
560
- clone.value = node.value;
558
+ const rect = node.getBoundingClientRect();
561
559
  clone.textContent = node.value;
560
+ clone.style.width = `${rect.width}px`;
561
+ clone.style.height = `${rect.height}px`;
562
562
  } else if (node instanceof HTMLSelectElement) {
563
563
  clone.value = node.value;
564
564
  Array.from(clone.options).forEach((opt) => {
@@ -570,18 +570,30 @@
570
570
  });
571
571
  }
572
572
  inlineAllStyles(node, clone, styleMap, styleCache, compress);
573
- const frag = document.createDocumentFragment();
574
- const rootElement = originalRoot || node;
575
- node.childNodes.forEach((child) => {
576
- const clonedChild = deepClone(child, styleMap, styleCache, nodeMap, compress, options, rootElement);
577
- if (clonedChild) frag.appendChild(clonedChild);
578
- });
579
- clone.appendChild(frag);
580
- if (node.shadowRoot) {
581
- const shadowContent = Array.from(node.shadowRoot.children).filter((el) => el.tagName !== "STYLE").map((el) => deepClone(el, styleMap, styleCache, nodeMap, compress, options, rootElement)).filter(Boolean);
582
- const shadowFrag = document.createDocumentFragment();
583
- shadowContent.forEach((child) => shadowFrag.appendChild(child));
584
- clone.appendChild(shadowFrag);
573
+ if (isSlotElement(node)) {
574
+ const assigned = ((_b = node.assignedNodes) == null ? void 0 : _b.call(node, { flatten: true })) || [];
575
+ const nodesToClone = assigned.length > 0 ? assigned : Array.from(node.childNodes);
576
+ const fragment = document.createDocumentFragment();
577
+ for (const child of nodesToClone) {
578
+ const clonedChild = deepClone(child, styleMap, styleCache, nodeMap, compress, options, originalRoot || node);
579
+ if (clonedChild) fragment.appendChild(clonedChild);
580
+ }
581
+ return fragment;
582
+ } else if (node instanceof HTMLTextAreaElement) {
583
+ } else {
584
+ const baseChildren = node.shadowRoot ? node.shadowRoot.childNodes : node.childNodes;
585
+ for (const child of baseChildren) {
586
+ const clonedChild = deepClone(child, styleMap, styleCache, nodeMap, compress, options, originalRoot || node);
587
+ if (clonedChild) clone.appendChild(clonedChild);
588
+ }
589
+ if (node.shadowRoot && node.childNodes.length > 0 && !node.shadowRoot.querySelector("slot")) {
590
+ const lightDomContent = document.createDocumentFragment();
591
+ for (const child of node.childNodes) {
592
+ const clonedChild = deepClone(child, styleMap, styleCache, nodeMap, compress, options, originalRoot || node);
593
+ if (clonedChild) lightDomContent.appendChild(clonedChild);
594
+ }
595
+ clone.appendChild(lightDomContent);
596
+ }
585
597
  }
586
598
  return clone;
587
599
  }
@@ -1091,27 +1103,32 @@
1091
1103
  function inlineBackgroundImages(_0, _1, _2) {
1092
1104
  return __async(this, arguments, function* (source, clone, styleCache, options = {}) {
1093
1105
  const queue = [[source, clone]];
1106
+ const imageProps = [
1107
+ "background-image",
1108
+ "mask",
1109
+ "mask-image",
1110
+ "-webkit-mask-image",
1111
+ "mask-source",
1112
+ "mask-box-image-source",
1113
+ "mask-border-source",
1114
+ "-webkit-mask-box-image-source"
1115
+ ];
1094
1116
  while (queue.length) {
1095
1117
  const [srcNode, cloneNode] = queue.shift();
1096
1118
  const style = styleCache.get(srcNode) || getStyle(srcNode);
1097
1119
  if (!styleCache.has(srcNode)) styleCache.set(srcNode, style);
1098
- const bg = style.getPropertyValue("background-image");
1099
- const bgColor = style.getPropertyValue("background-color");
1100
- if (!bg || bg === "none") {
1101
- const sChildren2 = Array.from(srcNode.children);
1102
- const cChildren2 = Array.from(cloneNode.children);
1103
- for (let i = 0; i < Math.min(sChildren2.length, cChildren2.length); i++) {
1104
- queue.push([sChildren2[i], cChildren2[i]]);
1120
+ for (const prop of imageProps) {
1121
+ const val = style.getPropertyValue(prop);
1122
+ if (!val || val === "none") continue;
1123
+ const splits = splitBackgroundImage(val);
1124
+ const inlined = yield Promise.all(
1125
+ splits.map((entry) => inlineSingleBackgroundEntry(entry, options))
1126
+ );
1127
+ if (inlined.some((p) => p && p !== "none" && !/^url\(undefined/.test(p))) {
1128
+ cloneNode.style.setProperty(prop, inlined.join(", "));
1105
1129
  }
1106
- continue;
1107
- }
1108
- const bgSplits = splitBackgroundImage(bg);
1109
- const newBgParts = yield Promise.all(
1110
- bgSplits.map((entry) => inlineSingleBackgroundEntry(entry, options))
1111
- );
1112
- if (newBgParts.some((p) => p && p !== "none" && !/^url\(undefined\)/.test(p))) {
1113
- cloneNode.style.backgroundImage = newBgParts.join(", ");
1114
1130
  }
1131
+ const bgColor = style.getPropertyValue("background-color");
1115
1132
  if (bgColor && bgColor !== "transparent" && bgColor !== "rgba(0, 0, 0, 0)") {
1116
1133
  cloneNode.style.backgroundColor = bgColor;
1117
1134
  }
@@ -1,15 +1,15 @@
1
- (()=>{var Fe=Object.defineProperty;var Y=Object.getOwnPropertySymbols;var le=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var ce=(e,t,o)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,D=(e,t)=>{for(var o in t||(t={}))le.call(t,o)&&ce(e,o,t[o]);if(Y)for(var o of Y(t))fe.call(t,o)&&ce(e,o,t[o]);return e};var de=(e,t)=>{var o={};for(var i in e)le.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(e!=null&&Y)for(var i of Y(e))t.indexOf(i)<0&&fe.call(e,i)&&(o[i]=e[i]);return o};var p=(e,t,o)=>new Promise((i,s)=>{var n=a=>{try{c(o.next(a))}catch(d){s(d)}},f=a=>{try{c(o.throw(a))}catch(d){s(d)}},c=a=>a.done?i(a.value):Promise.resolve(a.value).then(n,f);c((o=o.apply(e,t)).next())});var R=new Map,M=new Map,v=new Map,W=new Map,j=new Map,Z=new WeakMap,A=new Set;var Be=["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","svg","path","circle","rect","line","g","table","thead","tbody","tr","td","th"];function he(){for(let e of Be)ue(e)}function ue(e){if(W.has(e))return W.get(e);if(new Set(["script","style","meta","link","noscript","template"]).has(e)){let f={};return W.set(e,f),f}let o=document.getElementById("snapdom-sandbox");o||(o=document.createElement("div"),o.id="snapdom-sandbox",o.style.position="absolute",o.style.left="-9999px",o.style.top="-9999px",o.style.width="0",o.style.height="0",o.style.overflow="hidden",document.body.appendChild(o));let i=document.createElement(e);i.style.all="initial",o.appendChild(i);let s=getComputedStyle(i),n={};for(let f of s)n[f]=s.getPropertyValue(f);return o.removeChild(i),W.set(e,n),n}function z(e,t,o=!1){let i=[],s=ue(t);for(let[n,f]of Object.entries(e))if(!o)f&&i.push(`${n}:${f}`);else{let c=s[n];f&&f!==c&&i.push(`${n}:${f}`)}return i.sort().join(";")}function me(e){let t=new Set;return e.nodeType!==Node.ELEMENT_NODE&&e.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(e.tagName&&t.add(e.tagName.toLowerCase()),typeof e.querySelectorAll=="function"&&e.querySelectorAll("*").forEach(o=>t.add(o.tagName.toLowerCase())),Array.from(t))}function pe(e){let t=new Map;for(let i of e){let s=W.get(i);if(!s)continue;let n=Object.entries(s).map(([f,c])=>`${f}:${c};`).sort().join("");t.has(n)||t.set(n,[]),t.get(n).push(i)}let o="";for(let[i,s]of t.entries())o+=`${s.join(",")} { ${i} }
2
- `;return o}function ge(e){let t=new Set(e.values()),o=new Map,i=1;for(let s of t)o.set(s,`c${i++}`);return o}function O(o){return p(this,arguments,function*(e,t={}){let i=e.startsWith("url("),s=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(i){let n=H(e);if(!n)return e;let f=K(n);if(M.has(f))return t.skipInline?void 0:`url(${M.get(f)})`;{let c=yield F(f,{useProxy:t.useProxy});return M.set(f,c),t.skipInline?void 0:`url("${c}")`}}return e})}function V(e,{fast:t=!1}={}){if(t)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function N(e,t=null){if(!(e instanceof Element))return window.getComputedStyle(e,t);let o=Z.get(e);if(o||(o=new Map,Z.set(e,o)),!o.has(t)){let i=window.getComputedStyle(e,t);o.set(t,i)}return o.get(t)}function ye(e){let t=e.replace(/^['"]|['"]$/g,"");if(t.startsWith("\\"))try{return String.fromCharCode(parseInt(t.replace("\\",""),16))}catch(o){return t}return t}function H(e){let t=e.indexOf("url(");if(t===-1)return null;let o=e.slice(t+4).trim();return o.endsWith(")")&&(o=o.slice(0,-1).trim()),(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))&&(o=o.slice(1,-1)),o}function F(e,{timeout:t=3e3,useProxy:o=""}={}){function i(a){try{return new URL(a,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch(d){return"anonymous"}}function s(a){return p(this,null,function*(){let d=h=>fetch(h,{mode:"cors",credentials:i(h)==="use-credentials"?"include":"omit"}).then(r=>r.blob()).then(r=>new Promise((l,u)=>{let m=new FileReader;m.onloadend=()=>{let w=m.result;if(typeof w!="string"||!w.startsWith("data:image/")){u(new Error("Invalid image data URL"));return}l(w)},m.onerror=()=>u(new Error("FileReader error")),m.readAsDataURL(r)}));try{return yield d(a)}catch(h){if(o&&typeof o=="string"){let r=o.replace(/\/$/,"")+K(a);try{return yield d(r)}catch(l){throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${a}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${a}`),new Error("Fetch fallback failed and no proxy provided")}})}let n=i(e);return console.log(`[SnapDOM - fetchImage] Start loading image: ${e} with crossOrigin=${n}`),R.has(e)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${e}`),Promise.resolve(R.get(e))):e.startsWith("data:image/")?(R.set(e,e),Promise.resolve(e)):/\.svg(\?.*)?$/i.test(e)?p(null,null,function*(){try{let d=yield(yield fetch(e,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),h=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(d)}`;return R.set(e,h),h}catch(a){return s(e)}}):new Promise((a,d)=>{let h=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${t}ms for image: ${e}`),d(new Error("Image load timed out"))},t),r=new Image;r.crossOrigin=n,r.onload=()=>p(null,null,function*(){clearTimeout(h);try{yield r.decode();let l=document.createElement("canvas");l.width=r.width,l.height=r.height,l.getContext("2d").drawImage(r,0,0,l.width,l.height);let m=l.toDataURL("image/png");R.set(e,m),a(m)}catch(l){try{let u=yield s(e);R.set(e,u),a(u)}catch(u){d(u)}}}),r.onerror=()=>p(null,null,function*(){clearTimeout(h),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let l=yield s(e);R.set(e,l),a(l)}catch(l){d(l)}}),r.src=e})}function ee(e){let t={};for(let o of e)t[o]=e.getPropertyValue(o);return t}function X(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function we(e){if(!e||e==="none")return"";let t=e.replace(/translate[XY]?\([^)]*\)/g,"");return t=t.replace(/matrix\(([^)]+)\)/g,(o,i)=>{let s=i.split(",").map(n=>n.trim());return s.length!==6?`matrix(${i})`:(s[4]="0",s[5]="0",`matrix(${s.join(", ")})`)}),t=t.replace(/matrix3d\(([^)]+)\)/g,(o,i)=>{let s=i.split(",").map(n=>n.trim());return s.length!==16?`matrix3d(${i})`:(s[12]="0",s[13]="0",`matrix3d(${s.join(", ")})`)}),t.trim().replace(/\s{2,}/g," ")}function K(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch(t){return e}}function _(e){let t=[],o=0,i=0;for(let s=0;s<e.length;s++){let n=e[s];n==="("&&o++,n===")"&&o--,n===","&&o===0&&(t.push(e.slice(i,s).trim()),i=s+1)}return t.push(e.slice(i).trim()),t}var te=new WeakMap,ne=new Map;function De(e){let t={};for(let o=0;o<e.length;o++){let i=e[o],s=e.getPropertyValue(i);(i==="background-image"||i==="content")&&s.includes("url(")&&!s.includes("data:")&&(s="none"),t[i]=s}return t}function oe(e,t,o,i,s){var h;if(e.tagName==="STYLE")return;i.has(e)||i.set(e,N(e));let n=i.get(e);if(!te.has(e)){let r=De(n);te.set(e,r)}let f=te.get(e),c=Object.entries(f).sort(([r],[l])=>r.localeCompare(l)).map(([r,l])=>`${r}:${l}`).join(";");if(ne.has(c)){o.set(t,ne.get(c));return}let a=((h=e.tagName)==null?void 0:h.toLowerCase())||"div",d=z(f,a,s);ne.set(c,d),o.set(t,d)}function G(e,t,o,i,s,n={},f){var h;if(e.nodeType===Node.TEXT_NODE){if((h=e.parentElement)!=null&&h.shadowRoot){let r=e.parentElement.tagName.toLowerCase();if(customElements.get(r))return null}return e.cloneNode(!0)}if(e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let r=document.createElement("div"),l=e.getBoundingClientRect();return r.style.cssText=`display: inline-block; width: ${l.width}px; height: ${l.height}px; visibility: hidden;`,r}if(n.exclude&&Array.isArray(n.exclude)&&n.exclude.length>0)for(let r of n.exclude)try{if(e.matches&&e.matches(r)){let l=document.createElement("div"),u=e.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${u.width}px; height: ${u.height}px; visibility: hidden;`,l}}catch(l){console.warn(`Invalid selector in exclude option: ${r}`,l)}if(typeof n.filter=="function")try{if(!n.filter(e,f||e)){let r=document.createElement("div"),l=e.getBoundingClientRect();return r.style.cssText=`display: inline-block; width: ${l.width}px; height: ${l.height}px; visibility: hidden;`,r}}catch(r){console.warn("Error in filter function:",r)}if(e.tagName==="IFRAME"){let r=document.createElement("div");return r.textContent="",r.style.cssText=`width: ${e.offsetWidth}px; height: ${e.offsetHeight}px; background-image: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,r}if(e.getAttribute("data-capture")==="placeholder"){let r=e.cloneNode(!1);i.set(r,e),oe(e,r,t,o,s);let l=document.createElement("div");return l.textContent=e.getAttribute("data-placeholder-text")||"",l.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",r.appendChild(l),r}if(e.tagName==="CANVAS"){let r=e.toDataURL(),l=document.createElement("img");return l.src=r,l.width=e.width,l.height=e.height,l.style.display="inline-block",l.style.width=e.style.width||`${e.width}px`,l.style.height=e.style.height||`${e.height}px`,l}let c=e.cloneNode(!1);i.set(c,e),e instanceof HTMLInputElement?(c.value=e.value,c.setAttribute("value",e.value),e.checked!==void 0&&(c.checked=e.checked,e.checked&&c.setAttribute("checked",""))):e instanceof HTMLTextAreaElement?(c.value=e.value,c.textContent=e.value):e instanceof HTMLSelectElement&&(c.value=e.value,Array.from(c.options).forEach(r=>{r.value===e.value?r.setAttribute("selected",""):r.removeAttribute("selected")})),oe(e,c,t,o,s);let a=document.createDocumentFragment(),d=f||e;if(e.childNodes.forEach(r=>{let l=G(r,t,o,i,s,n,d);l&&a.appendChild(l)}),c.appendChild(a),e.shadowRoot){let r=Array.from(e.shadowRoot.children).filter(u=>u.tagName!=="STYLE").map(u=>G(u,t,o,i,s,n,d)).filter(Boolean),l=document.createDocumentFragment();r.forEach(u=>l.appendChild(u)),c.appendChild(l)}return c}var Me=[/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=[];function xe(e){let t=Array.isArray(e)?e:[e];for(let o of t)o instanceof RegExp?ae.push(o):typeof o=="string"?ae.push(new RegExp(o,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",o)}function T(e){let t=typeof e=="string"?e:"",o=[...Me,...ae];for(let i of o)if(i instanceof RegExp&&i.test(t))return!0;return!!(/icon/i.test(t)||/glyph/i.test(t)||/symbols/i.test(t)||/feather/i.test(t)||/fontawesome/i.test(t))}function be(e,t,o,i=32,s="#000"){return p(this,null,function*(){t=t.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,c=document.createElement("canvas").getContext("2d");c.font=o?`${o} ${i}px "${t}"`:`${i}px "${t}"`;let a=c.measureText(e),d=a.actualBoundingBoxAscent||i*.8,h=a.actualBoundingBoxDescent||i*.2,r=d+h,l=a.width,u=document.createElement("canvas");u.width=Math.ceil(l*n),u.height=Math.ceil(r*n);let m=u.getContext("2d");return m.scale(n,n),m.font=c.font,m.textAlign="left",m.textBaseline="alphabetic",m.fillStyle=s,m.fillText(e,0,d),u.toDataURL()})}function Ce(e){return Array.from(document.styleSheets).some(t=>t.href===e)}function We(e){return new Promise(t=>{if(Ce(e))return t(null);let o=document.createElement("link");o.rel="stylesheet",o.href=e,o.setAttribute("data-snapdom","injected-import"),o.onload=()=>t(o),o.onerror=()=>t(null),document.head.appendChild(o)})}function J(){return p(this,arguments,function*({preCached:e=!1}={}){if(v.has("fonts-embed-css")){if(e){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=v.get("fonts-embed-css"),document.head.appendChild(n)}return v.get("fonts-embed-css")}let t=/@import\s+url\(["']?([^"')]+)["']?\)/g,o=[];for(let n of document.querySelectorAll("style")){let f=n.textContent||"",c=Array.from(f.matchAll(t));for(let a of c){let d=a[1];T(d)||Ce(d)||o.push(d)}}yield Promise.all(o.map(We));let i=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),s="";for(let n of i)try{let c=yield(yield fetch(n.href)).text();if(T(n.href)||T(c))continue;let a=/url\((["']?)([^"')]+)\1\)/g,d=yield Promise.all(Array.from(c.matchAll(a)).map(r=>p(null,null,function*(){let l=H(r[0]);if(!l)return null;let u=l;if(!u.startsWith("http")&&!u.startsWith("data:")&&(u=new URL(u,n.href).href),T(u))return null;if(v.has(u))return A.add(u),{original:r[0],inlined:`url(${v.get(u)})`};if(A.has(u))return null;try{let w=yield(yield fetch(u)).blob(),y=yield new Promise(g=>{let x=new FileReader;x.onload=()=>g(x.result),x.readAsDataURL(w)});return v.set(u,y),A.add(u),{original:r[0],inlined:`url(${y})`}}catch(m){return console.warn("[snapdom] Failed to fetch font resource:",u),null}}))),h=c;for(let r of d)r&&(h=h.replace(r.original,r.inlined));s+=h+`
3
- `}catch(f){console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||i.every(f=>f.href!==n.href)){for(let f of n.cssRules)if(f.type===CSSRule.FONT_FACE_RULE){let c=f.style.getPropertyValue("src"),a=f.style.getPropertyValue("font-family");if(!c||T(a))continue;let d=/url\((["']?)([^"')]+)\1\)/g,h=c,r=Array.from(c.matchAll(d));for(let l of r){let u=l[2].trim();if(!u)continue;let m=u;if(!m.startsWith("http")&&!m.startsWith("data:")&&(m=new URL(m,n.href||location.href).href),!T(m)){if(v.has(m)){A.add(m),h=h.replace(l[0],`url(${v.get(m)})`);continue}if(!A.has(m))try{let y=yield(yield fetch(m)).blob(),g=yield new Promise(x=>{let b=new FileReader;b.onload=()=>x(b.result),b.readAsDataURL(y)});v.set(m,g),A.add(m),h=h.replace(l[0],`url(${g})`)}catch(w){console.warn("[snapdom] Failed to fetch font URL:",m)}}}s+=`@font-face {
1
+ (()=>{var Ft=Object.defineProperty;var X=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var ct=(t,e,o)=>e in t?Ft(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,D=(t,e)=>{for(var o in e||(e={}))lt.call(e,o)&&ct(t,o,e[o]);if(X)for(var o of X(e))ft.call(e,o)&&ct(t,o,e[o]);return t};var dt=(t,e)=>{var o={};for(var i in t)lt.call(t,i)&&e.indexOf(i)<0&&(o[i]=t[i]);if(t!=null&&X)for(var i of X(t))e.indexOf(i)<0&&ft.call(t,i)&&(o[i]=t[i]);return o};var p=(t,e,o)=>new Promise((i,r)=>{var n=a=>{try{c(o.next(a))}catch(d){r(d)}},f=a=>{try{c(o.throw(a))}catch(d){r(d)}},c=a=>a.done?i(a.value):Promise.resolve(a.value).then(n,f);c((o=o.apply(t,e)).next())});var R=new Map,M=new Map,$=new Map,O=new Map,W=new Map,Z=new WeakMap,A=new Set;var Bt=["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","svg","path","circle","rect","line","g","table","thead","tbody","tr","td","th"];function ht(){for(let t of Bt)mt(t)}function mt(t){if(O.has(t))return O.get(t);if(new Set(["script","style","meta","link","noscript","template"]).has(t)){let f={};return O.set(t,f),f}let o=document.getElementById("snapdom-sandbox");o||(o=document.createElement("div"),o.id="snapdom-sandbox",o.style.position="absolute",o.style.left="-9999px",o.style.top="-9999px",o.style.width="0",o.style.height="0",o.style.overflow="hidden",document.body.appendChild(o));let i=document.createElement(t);i.style.all="initial",o.appendChild(i);let r=getComputedStyle(i),n={};for(let f of r)n[f]=r.getPropertyValue(f);return o.removeChild(i),O.set(t,n),n}function z(t,e,o=!1){let i=[],r=mt(e);for(let[n,f]of Object.entries(t))if(!o)f&&i.push(`${n}:${f}`);else{let c=r[n];f&&f!==c&&i.push(`${n}:${f}`)}return i.sort().join(";")}function ut(t){let e=new Set;return t.nodeType!==Node.ELEMENT_NODE&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(t.tagName&&e.add(t.tagName.toLowerCase()),typeof t.querySelectorAll=="function"&&t.querySelectorAll("*").forEach(o=>e.add(o.tagName.toLowerCase())),Array.from(e))}function pt(t){let e=new Map;for(let i of t){let r=O.get(i);if(!r)continue;let n=Object.entries(r).map(([f,c])=>`${f}:${c};`).sort().join("");e.has(n)||e.set(n,[]),e.get(n).push(i)}let o="";for(let[i,r]of e.entries())o+=`${r.join(",")} { ${i} }
2
+ `;return o}function gt(t){let e=new Set(t.values()),o=new Map,i=1;for(let r of e)o.set(r,`c${i++}`);return o}function j(o){return p(this,arguments,function*(t,e={}){let i=t.match(/url\(["']?(.*?)["']?\)/),r=i==null?void 0:i[1],n=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t);if(r){let f=G(r);if(M.has(f))return e.skipInline?void 0:`url(${M.get(f)})`;{let c=yield F(f,{useProxy:e.useProxy});return M.set(f,c),e.skipInline?void 0:`url("${c}")`}}return t})}function V(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function U(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let o=Z.get(t);if(o||(o=new Map,Z.set(t,o)),!o.has(e)){let i=window.getComputedStyle(t,e);o.set(e,i)}return o.get(e)}function yt(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch(o){return e}return e}function Y(t){let e=t.indexOf("url(");if(e===-1)return null;let o=t.slice(e+4).trim();return o.endsWith(")")&&(o=o.slice(0,-1).trim()),(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))&&(o=o.slice(1,-1)),o}function F(t,{timeout:e=3e3,useProxy:o=""}={}){function i(a){try{return new URL(a,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch(d){return"anonymous"}}function r(a){return p(this,null,function*(){let d=l=>fetch(l,{mode:"cors",credentials:i(l)==="use-credentials"?"include":"omit"}).then(s=>s.blob()).then(s=>new Promise((h,m)=>{let u=new FileReader;u.onloadend=()=>{let g=u.result;if(typeof g!="string"||!g.startsWith("data:image/")){m(new Error("Invalid image data URL"));return}h(g)},u.onerror=()=>m(new Error("FileReader error")),u.readAsDataURL(s)}));try{return yield d(a)}catch(l){if(o&&typeof o=="string"){let s=o.replace(/\/$/,"")+G(a);try{return yield d(s)}catch(h){throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${a}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${a}`),new Error("Fetch fallback failed and no proxy provided")}})}let n=i(t);return console.log(`[SnapDOM - fetchImage] Start loading image: ${t} with crossOrigin=${n}`),R.has(t)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${t}`),Promise.resolve(R.get(t))):t.startsWith("data:image/")?(R.set(t,t),Promise.resolve(t)):/\.svg(\?.*)?$/i.test(t)?p(null,null,function*(){try{let d=yield(yield fetch(t,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),l=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(d)}`;return R.set(t,l),l}catch(a){return r(t)}}):new Promise((a,d)=>{let l=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${e}ms for image: ${t}`),d(new Error("Image load timed out"))},e),s=new Image;s.crossOrigin=n,s.onload=()=>p(null,null,function*(){clearTimeout(l);try{yield s.decode();let h=document.createElement("canvas");h.width=s.width,h.height=s.height,h.getContext("2d").drawImage(s,0,0,h.width,h.height);let u=h.toDataURL("image/png");R.set(t,u),a(u)}catch(h){try{let m=yield r(t);R.set(t,m),a(m)}catch(m){d(m)}}}),s.onerror=()=>p(null,null,function*(){clearTimeout(l),console.error(`[SnapDOM - fetchImage] Image failed to load: ${t}`);try{let h=yield r(t);R.set(t,h),a(h)}catch(h){d(h)}}),s.src=t})}function tt(t){let e={};for(let o of t)e[o]=t.getPropertyValue(o);return e}function K(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function wt(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(o,i)=>{let r=i.split(",").map(n=>n.trim());return r.length!==6?`matrix(${i})`:(r[4]="0",r[5]="0",`matrix(${r.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(o,i)=>{let r=i.split(",").map(n=>n.trim());return r.length!==16?`matrix3d(${i})`:(r[12]="0",r[13]="0",`matrix3d(${r.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function G(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch(e){return t}}function _(t){let e=[],o=0,i=0;for(let r=0;r<t.length;r++){let n=t[r];n==="("&&o++,n===")"&&o--,n===","&&o===0&&(e.push(t.slice(i,r).trim()),i=r+1)}return e.push(t.slice(i).trim()),e}var et=new WeakMap,nt=new Map;function Dt(t){let e={};for(let o=0;o<t.length;o++){let i=t[o],r=t.getPropertyValue(i);(i==="background-image"||i==="content")&&r.includes("url(")&&!r.includes("data:")&&(r="none"),e[i]=r}return e}function ot(t,e,o,i,r){var l;if(t.tagName==="STYLE")return;i.has(t)||i.set(t,U(t));let n=i.get(t);if(!et.has(t)){let s=Dt(n);et.set(t,s)}let f=et.get(t),c=Object.entries(f).sort(([s],[h])=>s.localeCompare(h)).map(([s,h])=>`${s}:${h}`).join(";");if(nt.has(c)){o.set(e,nt.get(c));return}let a=((l=t.tagName)==null?void 0:l.toLowerCase())||"div",d=z(f,a,r);nt.set(c,d),o.set(e,d)}function Mt(t){return t.nodeType===Node.ELEMENT_NODE&&t.tagName==="SLOT"}function H(t,e,o,i,r,n={},f){var a,d;if(t.nodeType===Node.TEXT_NODE||t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);if(t.getAttribute("data-capture")==="exclude"){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}if(n.exclude&&Array.isArray(n.exclude))for(let l of n.exclude)try{if((a=t.matches)!=null&&a.call(t,l)){let s=document.createElement("div"),h=t.getBoundingClientRect();return s.style.cssText=`display: inline-block; width: ${h.width}px; height: ${h.height}px; visibility: hidden;`,s}}catch(s){console.warn(`Invalid selector in exclude option: ${l}`,s)}if(typeof n.filter=="function")try{if(!n.filter(t,f||t)){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}}catch(l){console.warn("Error in filter function:",l)}if(t.tagName==="IFRAME"){let l=document.createElement("div");return l.textContent="",l.style.cssText=`width: ${t.offsetWidth}px; height: ${t.offsetHeight}px; background-image: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,l}if(t.getAttribute("data-capture")==="placeholder"){let l=t.cloneNode(!1);i.set(l,t),ot(t,l,e,o,r);let s=document.createElement("div");return s.textContent=t.getAttribute("data-placeholder-text")||"",s.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",l.appendChild(s),l}if(t.tagName==="CANVAS"){let l=t.toDataURL(),s=document.createElement("img");return s.src=l,s.width=t.width,s.height=t.height,s.style.display="inline-block",s.style.width=t.style.width||`${t.width}px`,s.style.height=t.style.height||`${t.height}px`,s}let c=t.cloneNode(!1);if(i.set(c,t),t instanceof HTMLInputElement)c.value=t.value,c.setAttribute("value",t.value),t.checked!==void 0&&(c.checked=t.checked,t.checked&&c.setAttribute("checked",""));else if(t instanceof HTMLTextAreaElement){let l=t.getBoundingClientRect();c.textContent=t.value,c.style.width=`${l.width}px`,c.style.height=`${l.height}px`}else t instanceof HTMLSelectElement&&(c.value=t.value,Array.from(c.options).forEach(l=>{l.value===t.value?l.setAttribute("selected",""):l.removeAttribute("selected")}));if(ot(t,c,e,o,r),Mt(t)){let l=((d=t.assignedNodes)==null?void 0:d.call(t,{flatten:!0}))||[],s=l.length>0?l:Array.from(t.childNodes),h=document.createDocumentFragment();for(let m of s){let u=H(m,e,o,i,r,n,f||t);u&&h.appendChild(u)}return h}else if(!(t instanceof HTMLTextAreaElement)){let l=t.shadowRoot?t.shadowRoot.childNodes:t.childNodes;for(let s of l){let h=H(s,e,o,i,r,n,f||t);h&&c.appendChild(h)}if(t.shadowRoot&&t.childNodes.length>0&&!t.shadowRoot.querySelector("slot")){let s=document.createDocumentFragment();for(let h of t.childNodes){let m=H(h,e,o,i,r,n,f||t);m&&s.appendChild(m)}c.appendChild(s)}}return c}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],at=[];function xt(t){let e=Array.isArray(t)?t:[t];for(let o of e)o instanceof RegExp?at.push(o):typeof o=="string"?at.push(new RegExp(o,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",o)}function T(t){let e=typeof t=="string"?t:"",o=[...Ot,...at];for(let i of o)if(i instanceof RegExp&&i.test(e))return!0;return!!(/icon/i.test(e)||/glyph/i.test(e)||/symbols/i.test(e)||/feather/i.test(e)||/fontawesome/i.test(e))}function bt(t,e,o,i=32,r="#000"){return p(this,null,function*(){e=e.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,c=document.createElement("canvas").getContext("2d");c.font=o?`${o} ${i}px "${e}"`:`${i}px "${e}"`;let a=c.measureText(t),d=a.actualBoundingBoxAscent||i*.8,l=a.actualBoundingBoxDescent||i*.2,s=d+l,h=a.width,m=document.createElement("canvas");m.width=Math.ceil(h*n),m.height=Math.ceil(s*n);let u=m.getContext("2d");return u.scale(n,n),u.font=c.font,u.textAlign="left",u.textBaseline="alphabetic",u.fillStyle=r,u.fillText(t,0,d),m.toDataURL()})}function Ct(t){return Array.from(document.styleSheets).some(e=>e.href===t)}function Wt(t){return new Promise(e=>{if(Ct(t))return e(null);let o=document.createElement("link");o.rel="stylesheet",o.href=t,o.setAttribute("data-snapdom","injected-import"),o.onload=()=>e(o),o.onerror=()=>e(null),document.head.appendChild(o)})}function J(){return p(this,arguments,function*({preCached:t=!1}={}){if($.has("fonts-embed-css")){if(t){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=$.get("fonts-embed-css"),document.head.appendChild(n)}return $.get("fonts-embed-css")}let e=/@import\s+url\(["']?([^"')]+)["']?\)/g,o=[];for(let n of document.querySelectorAll("style")){let f=n.textContent||"",c=Array.from(f.matchAll(e));for(let a of c){let d=a[1];T(d)||Ct(d)||o.push(d)}}yield Promise.all(o.map(Wt));let i=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),r="";for(let n of i)try{let c=yield(yield fetch(n.href)).text();if(T(n.href)||T(c))continue;let a=/url\((["']?)([^"')]+)\1\)/g,d=yield Promise.all(Array.from(c.matchAll(a)).map(s=>p(null,null,function*(){let h=Y(s[0]);if(!h)return null;let m=h;if(!m.startsWith("http")&&!m.startsWith("data:")&&(m=new URL(m,n.href).href),T(m))return null;if($.has(m))return A.add(m),{original:s[0],inlined:`url(${$.get(m)})`};if(A.has(m))return null;try{let g=yield(yield fetch(m)).blob(),y=yield new Promise(b=>{let w=new FileReader;w.onload=()=>b(w.result),w.readAsDataURL(g)});return $.set(m,y),A.add(m),{original:s[0],inlined:`url(${y})`}}catch(u){return console.warn("[snapdom] Failed to fetch font resource:",m),null}}))),l=c;for(let s of d)s&&(l=l.replace(s.original,s.inlined));r+=l+`
3
+ `}catch(f){console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||i.every(f=>f.href!==n.href)){for(let f of n.cssRules)if(f.type===CSSRule.FONT_FACE_RULE){let c=f.style.getPropertyValue("src"),a=f.style.getPropertyValue("font-family");if(!c||T(a))continue;let d=/url\((["']?)([^"')]+)\1\)/g,l=c,s=Array.from(c.matchAll(d));for(let h of s){let m=h[2].trim();if(!m)continue;let u=m;if(!u.startsWith("http")&&!u.startsWith("data:")&&(u=new URL(u,n.href||location.href).href),!T(u)){if($.has(u)){A.add(u),l=l.replace(h[0],`url(${$.get(u)})`);continue}if(!A.has(u))try{let y=yield(yield fetch(u)).blob(),b=yield new Promise(w=>{let x=new FileReader;x.onload=()=>w(x.result),x.readAsDataURL(y)});$.set(u,b),A.add(u),l=l.replace(h[0],`url(${b})`)}catch(g){console.warn("[snapdom] Failed to fetch font URL:",u)}}}r+=`@font-face {
4
4
  font-family: ${a};
5
- src: ${h};
5
+ src: ${l};
6
6
  font-style: ${f.style.getPropertyValue("font-style")||"normal"};
7
7
  font-weight: ${f.style.getPropertyValue("font-weight")||"normal"};
8
8
  }
9
- `}}}catch(f){console.warn("[snapdom] Cannot access stylesheet",n.href,f)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(T(n.family))continue;let f=n._snapdomSrc;if(!f.startsWith("data:")){if(v.has(n._snapdomSrc))f=v.get(n._snapdomSrc),A.add(n._snapdomSrc);else if(!A.has(n._snapdomSrc))try{let a=yield(yield fetch(n._snapdomSrc)).blob();f=yield new Promise(d=>{let h=new FileReader;h.onload=()=>d(h.result),h.readAsDataURL(a)}),v.set(n._snapdomSrc,f),A.add(n._snapdomSrc)}catch(c){console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}s+=`@font-face {
9
+ `}}}catch(f){console.warn("[snapdom] Cannot access stylesheet",n.href,f)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(T(n.family))continue;let f=n._snapdomSrc;if(!f.startsWith("data:")){if($.has(n._snapdomSrc))f=$.get(n._snapdomSrc),A.add(n._snapdomSrc);else if(!A.has(n._snapdomSrc))try{let a=yield(yield fetch(n._snapdomSrc)).blob();f=yield new Promise(d=>{let l=new FileReader;l.onload=()=>d(l.result),l.readAsDataURL(a)}),$.set(n._snapdomSrc,f),A.add(n._snapdomSrc)}catch(c){console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}r+=`@font-face {
10
10
  font-family: '${n.family}';
11
11
  src: url(${f});
12
12
  font-style: ${n.style||"normal"};
13
13
  font-weight: ${n.weight||"normal"};
14
14
  }
15
- `}if(s&&(v.set("fonts-embed-css",s),e)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=s,document.head.appendChild(n)}return s})}function re(e,t,o,i,s,n=!1,f){return p(this,null,function*(){if(!(e instanceof Element)||!(t instanceof Element))return;for(let d of["::before","::after","::first-letter"])try{let h=N(e,d);if(!h||typeof h[Symbol.iterator]!="function")continue;if(d==="::first-letter"){let g=getComputedStyle(e);if(!(h.color!==g.color||h.fontSize!==g.fontSize||h.fontWeight!==g.fontWeight))continue;let b=Array.from(t.childNodes).find(E=>E.nodeType===Node.TEXT_NODE&&E.textContent&&E.textContent.trim().length>0);if(!b)continue;let P=b.textContent,C=P.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),I=C==null?void 0:C[0],B=P.slice((I==null?void 0:I.length)||0);if(!I||/[\uD800-\uDFFF]/.test(I))continue;let $=document.createElement("span");$.textContent=I,$.dataset.snapdomPseudo="::first-letter";let k=ee(h),Q=z(k,"span",s);o.set($,Q);let q=document.createTextNode(B);t.replaceChild(q,b),t.insertBefore($,q);continue}let r=h.getPropertyValue("content"),l=h.getPropertyValue("background-image"),u=h.getPropertyValue("background-color"),m=r!=="none",w=l&&l!=="none",y=u&&u!=="transparent"&&u!=="rgba(0, 0, 0, 0)";if(m||w||y){let g=h.getPropertyValue("font-family"),x=parseInt(h.getPropertyValue("font-size"))||32,b=parseInt(h.getPropertyValue("font-weight"))||!1,P=h.getPropertyValue("color")||"#000",C=document.createElement("span");C.dataset.snapdomPseudo=d;let I=ee(h),B=z(I,"span",s);o.set(C,B);let $=T(g),k=ye(r);if($&&k.length===1){let E=document.createElement("img");E.src=yield be(k,g,b,x,P),E.style=`width:${x}px;height:auto;object-fit:contain;`,C.appendChild(E)}else if(k.startsWith("url(")){let E=H(k);if(E&&E.trim()!=="")try{let L=document.createElement("img"),U=yield F(K(E,{useProxy:f}));L.src=U,L.style=`width:${x}px;height:auto;object-fit:contain;`,C.appendChild(L)}catch(L){console.error(`[snapdom] Error in pseudo ${d} for`,e,L)}}else!$&&k&&k!=="none"&&(C.textContent=k);if(w)try{let E=_(l),L=yield Promise.all(E.map(U=>O(U)));C.style.backgroundImage=L.join(", ")}catch(E){console.warn(`[snapdom] Failed to inline background-image for ${d}`,E)}if(y&&(C.style.backgroundColor=u),!(C.childNodes.length>0||C.textContent&&C.textContent.trim()!==""||w||y))continue;d==="::before"?t.insertBefore(C,t.firstChild):t.appendChild(C)}}catch(h){console.warn(`[snapdom] Failed to capture ${d} for`,e,h)}let c=Array.from(e.children),a=Array.from(t.children).filter(d=>!d.dataset.snapdomPseudo);for(let d=0;d<Math.min(c.length,a.length);d++)yield re(c[d],a[d],o,i,s,n,f)})}function Se(e){if(!e)return;let t=document.querySelectorAll("svg > defs");t.length&&e.querySelectorAll("svg").forEach(o=>{let i=o.querySelectorAll("use");if(!i.length)return;let s=new Set;if(i.forEach(f=>{let c=f.getAttribute("xlink:href")||f.getAttribute("href");c&&c.startsWith("#")&&s.add(c.slice(1))}),!s.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let f of s)for(let c of t){let a=c.querySelector(`#${CSS.escape(f)}`);if(a){n.appendChild(a.cloneNode(!0));break}}n.childNodes.length&&o.insertBefore(n,o.firstChild)})}function Ee(s){return p(this,arguments,function*(e,t=!1,o=!1,i={}){var h;let n=new Map,f=new WeakMap,c=new Map,a;try{a=G(e,n,f,c,t,i,e)}catch(r){throw console.warn("deepClone failed:",r),r}try{yield re(e,a,n,f,t,o,i.useProxy)}catch(r){console.warn("inlinePseudoElements failed:",r)}try{Se(a)}catch(r){console.warn("inlineExternalDef failed:",r)}let d="";if(t){let r=ge(n);d=Array.from(r.entries()).map(([l,u])=>`.${u}{${l}}`).join("");for(let[l,u]of n.entries()){if(l.tagName==="STYLE")continue;let m=r.get(u);m&&l.classList.add(m);let w=(h=l.style)==null?void 0:h.backgroundImage;l.removeAttribute("style"),w&&w!=="none"&&(l.style.backgroundImage=w)}}else for(let[r,l]of n.entries())r.tagName!=="STYLE"&&r.setAttribute("style",l.replace(/;/g,"; "));for(let[r,l]of c.entries()){let u=l.scrollLeft,m=l.scrollTop;if((u||m)&&r instanceof HTMLElement){r.style.overflow="hidden",r.style.scrollbarWidth="none",r.style.msOverflowStyle="none";let y=document.createElement("div");for(y.style.transform=`translate(${-u}px, ${-m}px)`,y.style.willChange="transform",y.style.display="inline-block",y.style.width="100%";r.firstChild;)y.appendChild(r.firstChild);r.appendChild(y)}}if(e===c.get(a)){let r=f.get(e)||window.getComputedStyle(e);f.set(e,r);let l=we(r.transform);a.style.margin="0",a.style.position="static",a.style.top="auto",a.style.left="auto",a.style.right="auto",a.style.bottom="auto",a.style.zIndex="auto",a.style.float="none",a.style.clear="none",a.style.transform=l||""}for(let[r,l]of c.entries())l.tagName==="PRE"&&(r.style.marginTop="0",r.style.marginBlockStart="0");return{clone:a,classCSS:d,styleCache:f}})}function ve(o){return p(this,arguments,function*(e,t={}){let i=Array.from(e.querySelectorAll("img")),s=n=>p(null,null,function*(){let f=n.src;try{let c=yield F(f,{useProxy:t.useProxy});n.src=c,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch(c){let a=document.createElement("div");a.style=`width: ${n.width||100}px; height: ${n.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${n.height||100}px; color: #666; font-size: 12px;`,a.innerText="img",n.replaceWith(a)}});for(let n=0;n<i.length;n+=4){let f=i.slice(n,n+4).map(s);yield Promise.allSettled(f)}})}function $e(s,n,f){return p(this,arguments,function*(e,t,o,i={}){let c=[[e,t]];for(;c.length;){let[a,d]=c.shift(),h=o.get(a)||N(a);o.has(a)||o.set(a,h);let r=h.getPropertyValue("background-image"),l=h.getPropertyValue("background-color");if(!r||r==="none"){let g=Array.from(a.children),x=Array.from(d.children);for(let b=0;b<Math.min(g.length,x.length);b++)c.push([g[b],x[b]]);continue}let u=_(r),m=yield Promise.all(u.map(g=>O(g,i)));m.some(g=>g&&g!=="none"&&!/^url\(undefined\)/.test(g))&&(d.style.backgroundImage=m.join(", ")),l&&l!=="transparent"&&l!=="rgba(0, 0, 0, 0)"&&(d.style.backgroundColor=l);let w=Array.from(a.children),y=Array.from(d.children);for(let g=0;g<Math.min(w.length,y.length);g++)c.push([w[g],y[g]])}})}function Ie(o){return p(this,arguments,function*(e,t={}){if(!e)throw new Error("Element cannot be null or undefined");let{compress:i=!0,embedFonts:s=!1,fast:n=!0,scale:f=1,useProxy:c=""}=t,a,d,h,r="",l="",u,m;if({clone:a,classCSS:d,styleCache:h}=yield Ee(e,i,s,t),yield new Promise(y=>{V(()=>p(null,null,function*(){yield ve(a,t),y()}),{fast:n})}),yield new Promise(y=>{V(()=>p(null,null,function*(){yield $e(e,a,h,t),y()}),{fast:n})}),s&&(yield new Promise(y=>{V(()=>p(null,null,function*(){r=yield J(),y()}),{fast:n})})),i){let y=me(a).sort(),g=y.join(",");j.has(g)?l=j.get(g):yield new Promise(x=>{V(()=>{l=pe(y),j.set(g,l),x()},{fast:n})})}yield new Promise(y=>{V(()=>{let g=e.getBoundingClientRect(),x=g.width,b=g.height,P=Number.isFinite(t.width),C=Number.isFinite(t.height),I=typeof f=="number"&&f!==1;if(!I){let U=g.width/g.height;P&&C?(x=t.width,b=t.height):P?(x=t.width,b=x/U):C&&(b=t.height,x=b*U)}if(x=Math.ceil(x),b=Math.ceil(b),a.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),a.style.transformOrigin="top left",!I&&(P||C)){let U=g.width,Te=g.height,Pe=x/U,Le=b/Te,Ue=a.style.transform||"",Ne=`scale(${Pe}, ${Le})`;a.style.transform=`${Ne} ${Ue}`.trim()}else I&&X()&&(a.style.scale=`${f}`);let B="http://www.w3.org/2000/svg",$=document.createElementNS(B,"foreignObject");$.setAttribute("width","100%"),$.setAttribute("height","100%");let k=document.createElement("style");k.textContent=l+r+"svg{overflow:visible;}"+d,$.appendChild(k),$.appendChild(a);let q=new XMLSerializer().serializeToString($);m=`<svg xmlns="${B}" width="${x}" height="${b}" viewBox="0 0 ${x} ${b}">`+q+"</svg>",u=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(m)}`,y()},{fast:n})});let w=document.getElementById("snapdom-sandbox");return w&&w.style.position==="absolute"&&w.remove(),u})}function je(i,s){return p(this,arguments,function*(e,{dpr:t=1,scale:o=1}){let n=new Image;return n.src=e,yield n.decode(),X?(n.width=n.width*o,n.height=n.height*o):(n.width=n.width/o,n.height=n.height/o),n})}function ke(i){return p(this,arguments,function*(e,{dpr:t=1,scale:o=1}={}){let s=new Image;s.src=e,yield s.decode();let n=document.createElement("canvas"),f=s.width*o,c=s.height*o;n.width=Math.ceil(f*t),n.height=Math.ceil(c*t);let a=n.getContext("2d");return a.scale(t,t),a.drawImage(s,0,0,f,c),n.style.width=`${f}px`,n.style.height=`${c}px`,n})}function Re(n){return p(this,arguments,function*(e,{type:t="svg",scale:o=1,backgroundColor:i="#fff",quality:s}={}){let f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[t]||"image/png";if(t==="svg"){let a=decodeURIComponent(e.split(",")[1]);return new Blob([a],{type:"image/svg+xml"})}let c=yield ie(e,{dpr:1,scale:o},i);return new Promise(a=>{c.toBlob(d=>a(d),`${f}`,s)})})}function ie(s,n,f){return p(this,arguments,function*(e,{dpr:t=1,scale:o=1},i){let c=yield ke(e,{dpr:t,scale:o});if(!i)return c;let a=document.createElement("canvas");a.width=c.width,a.height=c.height;let d=a.getContext("2d");return d.fillStyle=i,d.fillRect(0,0,a.width,a.height),d.drawImage(c,0,0),a})}function se(f,c){return p(this,arguments,function*(e,{dpr:t=1,scale:o=1,backgroundColor:i="#fff",quality:s},n="png"){let a=yield ie(e,{dpr:t,scale:o},i),d=new Image;return d.src=a.toDataURL(`image/${n}`,s),yield d.decode(),d.style.width=`${a.width/t}px`,d.style.height=`${a.height/t}px`,d})}function Oe(f){return p(this,arguments,function*(e,{dpr:t=1,scale:o=1,backgroundColor:i="#fff",format:s="png",filename:n="capture"}={}){if(s==="svg"){let u=yield Re(e),m=URL.createObjectURL(u),w=document.createElement("a");w.href=m,w.download=`${n}.svg`,w.click(),URL.revokeObjectURL(m);return}let c=["jpg","jpeg","webp"].includes(s)?"#fff":void 0,a=i!=null?i:c,d=yield ie(e,{dpr:t,scale:o},a),h={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[s]||"image/png",r=d.toDataURL(h),l=document.createElement("a");l.href=r,l.download=`${n}.${s}`,l.click()})}function S(o){return p(this,arguments,function*(e,t={}){if(t=D({scale:1},t),!e)throw new Error("Element cannot be null or undefined");return t.iconFonts&&xe(t.iconFonts),yield S.capture(e,t)})}S.capture=(o,...i)=>p(null,[o,...i],function*(e,t={}){let s=yield Ie(e,t),n=window.devicePixelRatio||1,f=t.scale||1;return{url:s,options:t,toRaw:()=>s,toImg:()=>je(s,{dpr:n,scale:f}),toCanvas:()=>ke(s,{dpr:n,scale:f}),toBlob:c=>Re(s,D({dpr:n,scale:f},c)),toPng:c=>se(s,D({dpr:n,scale:f},c),"png"),toJpg:c=>se(s,D({dpr:n,scale:f},c),"jpeg"),toWebp:c=>se(s,D({dpr:n,scale:f},c),"webp"),download:({format:c="png",filename:a="capture",backgroundColor:d}={})=>Oe(s,{dpr:n,scale:f,backgroundColor:d,format:c,filename:a})}});S.toRaw=(e,t)=>p(null,null,function*(){return(yield S.capture(e,t)).toRaw()});S.toImg=(e,t)=>p(null,null,function*(){return(yield S.capture(e,t)).toImg()});S.toCanvas=(e,t)=>p(null,null,function*(){return(yield S.capture(e,t)).toCanvas()});S.toBlob=(e,t)=>p(null,null,function*(){return(yield S.capture(e,t)).toBlob(t)});S.toPng=(e,t)=>p(null,null,function*(){return(yield S.capture(e,t)).toPng(t)});S.toJpg=(e,t)=>p(null,null,function*(){return(yield S.capture(e,t)).toJpg(t)});S.toWebp=(e,t)=>p(null,null,function*(){return(yield S.capture(e,t)).toWebp(t)});S.download=(o,...i)=>p(null,[o,...i],function*(e,t={}){let d=t,{format:s="png",filename:n="capture",backgroundColor:f}=d,c=de(d,["format","filename","backgroundColor"]);return yield(yield S.capture(e,c)).download({format:s,filename:n,backgroundColor:f})});function Ae(){return p(this,arguments,function*(e=document,t={}){let{embedFonts:o=!0,reset:i=!1}=t;if(i){R.clear(),M.clear(),v.clear(),j.clear();return}yield document.fonts.ready,he();let s=[],n=[];e!=null&&e.querySelectorAll&&(s=Array.from(e.querySelectorAll("img[src]")),n=Array.from(e.querySelectorAll("*")));let f=[];for(let c of s){let a=c.src;R.has(a)||f.push(F(a,{useProxy:t.useProxy}).then(d=>R.set(a,d)).catch(()=>{}))}for(let c of n){let a=N(c).backgroundImage;if(a&&a!=="none"){let d=_(a);for(let h of d)h.startsWith("url(")&&f.push(O(h,t).catch(()=>{}))}}o&&(yield J({preCached:!0})),yield Promise.all(f)})}window.snapdom=S;window.preCache=Ae;})();
15
+ `}if(r&&($.set("fonts-embed-css",r),t)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=r,document.head.appendChild(n)}return r})}function rt(t,e,o,i,r,n=!1,f){return p(this,null,function*(){if(!(t instanceof Element)||!(e instanceof Element))return;for(let d of["::before","::after","::first-letter"])try{let l=U(t,d);if(!l||typeof l[Symbol.iterator]!="function")continue;if(d==="::first-letter"){let b=getComputedStyle(t);if(!(l.color!==b.color||l.fontSize!==b.fontSize||l.fontWeight!==b.fontWeight))continue;let x=Array.from(e.childNodes).find(E=>E.nodeType===Node.TEXT_NODE&&E.textContent&&E.textContent.trim().length>0);if(!x)continue;let N=x.textContent,C=N.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),k=C==null?void 0:C[0],B=N.slice((k==null?void 0:k.length)||0);if(!k||/[\uD800-\uDFFF]/.test(k))continue;let v=document.createElement("span");v.textContent=k,v.dataset.snapdomPseudo="::first-letter";let I=tt(l),Q=z(I,"span",r);o.set(v,Q);let q=document.createTextNode(B);e.replaceChild(q,x),e.insertBefore(v,q);continue}let s=l.getPropertyValue("content"),h=l.getPropertyValue("background-image"),m=l.getPropertyValue("background-color"),u=s!=="none",g=h&&h!=="none",y=m&&m!=="transparent"&&m!=="rgba(0, 0, 0, 0)";if(u||g||y){let b=l.getPropertyValue("font-family"),w=parseInt(l.getPropertyValue("font-size"))||32,x=parseInt(l.getPropertyValue("font-weight"))||!1,N=l.getPropertyValue("color")||"#000",C=document.createElement("span");C.dataset.snapdomPseudo=d;let k=tt(l),B=z(k,"span",r);o.set(C,B);let v=T(b),I=yt(s);if(v&&I.length===1){let E=document.createElement("img");E.src=yield bt(I,b,x,w,N),E.style=`width:${w}px;height:auto;object-fit:contain;`,C.appendChild(E)}else if(I.startsWith("url(")){let E=Y(I);if(E&&E.trim()!=="")try{let P=document.createElement("img"),L=yield F(G(E,{useProxy:f}));P.src=L,P.style=`width:${w}px;height:auto;object-fit:contain;`,C.appendChild(P)}catch(P){console.error(`[snapdom] Error in pseudo ${d} for`,t,P)}}else!v&&I&&I!=="none"&&(C.textContent=I);if(g)try{let E=_(h),P=yield Promise.all(E.map(L=>j(L)));C.style.backgroundImage=P.join(", ")}catch(E){console.warn(`[snapdom] Failed to inline background-image for ${d}`,E)}if(y&&(C.style.backgroundColor=m),!(C.childNodes.length>0||C.textContent&&C.textContent.trim()!==""||g||y))continue;d==="::before"?e.insertBefore(C,e.firstChild):e.appendChild(C)}}catch(l){console.warn(`[snapdom] Failed to capture ${d} for`,t,l)}let c=Array.from(t.children),a=Array.from(e.children).filter(d=>!d.dataset.snapdomPseudo);for(let d=0;d<Math.min(c.length,a.length);d++)yield rt(c[d],a[d],o,i,r,n,f)})}function St(t){if(!t)return;let e=document.querySelectorAll("svg > defs");e.length&&t.querySelectorAll("svg").forEach(o=>{let i=o.querySelectorAll("use");if(!i.length)return;let r=new Set;if(i.forEach(f=>{let c=f.getAttribute("xlink:href")||f.getAttribute("href");c&&c.startsWith("#")&&r.add(c.slice(1))}),!r.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let f of r)for(let c of e){let a=c.querySelector(`#${CSS.escape(f)}`);if(a){n.appendChild(a.cloneNode(!0));break}}n.childNodes.length&&o.insertBefore(n,o.firstChild)})}function Et(r){return p(this,arguments,function*(t,e=!1,o=!1,i={}){var l;let n=new Map,f=new WeakMap,c=new Map,a;try{a=H(t,n,f,c,e,i,t)}catch(s){throw console.warn("deepClone failed:",s),s}try{yield rt(t,a,n,f,e,o,i.useProxy)}catch(s){console.warn("inlinePseudoElements failed:",s)}try{St(a)}catch(s){console.warn("inlineExternalDef failed:",s)}let d="";if(e){let s=gt(n);d=Array.from(s.entries()).map(([h,m])=>`.${m}{${h}}`).join("");for(let[h,m]of n.entries()){if(h.tagName==="STYLE")continue;let u=s.get(m);u&&h.classList.add(u);let g=(l=h.style)==null?void 0:l.backgroundImage;h.removeAttribute("style"),g&&g!=="none"&&(h.style.backgroundImage=g)}}else for(let[s,h]of n.entries())s.tagName!=="STYLE"&&s.setAttribute("style",h.replace(/;/g,"; "));for(let[s,h]of c.entries()){let m=h.scrollLeft,u=h.scrollTop;if((m||u)&&s instanceof HTMLElement){s.style.overflow="hidden",s.style.scrollbarWidth="none",s.style.msOverflowStyle="none";let y=document.createElement("div");for(y.style.transform=`translate(${-m}px, ${-u}px)`,y.style.willChange="transform",y.style.display="inline-block",y.style.width="100%";s.firstChild;)y.appendChild(s.firstChild);s.appendChild(y)}}if(t===c.get(a)){let s=f.get(t)||window.getComputedStyle(t);f.set(t,s);let h=wt(s.transform);a.style.margin="0",a.style.position="static",a.style.top="auto",a.style.left="auto",a.style.right="auto",a.style.bottom="auto",a.style.zIndex="auto",a.style.float="none",a.style.clear="none",a.style.transform=h||""}for(let[s,h]of c.entries())h.tagName==="PRE"&&(s.style.marginTop="0",s.style.marginBlockStart="0");return{clone:a,classCSS:d,styleCache:f}})}function $t(o){return p(this,arguments,function*(t,e={}){let i=Array.from(t.querySelectorAll("img")),r=n=>p(null,null,function*(){let f=n.src;try{let c=yield F(f,{useProxy:e.useProxy});n.src=c,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch(c){let a=document.createElement("div");a.style=`width: ${n.width||100}px; height: ${n.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${n.height||100}px; color: #666; font-size: 12px;`,a.innerText="img",n.replaceWith(a)}});for(let n=0;n<i.length;n+=4){let f=i.slice(n,n+4).map(r);yield Promise.allSettled(f)}})}function vt(r,n,f){return p(this,arguments,function*(t,e,o,i={}){let c=[[t,e]],a=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source"];for(;c.length;){let[d,l]=c.shift(),s=o.get(d)||U(d);o.has(d)||o.set(d,s);for(let g of a){let y=s.getPropertyValue(g);if(!y||y==="none")continue;let b=_(y),w=yield Promise.all(b.map(x=>j(x,i)));w.some(x=>x&&x!=="none"&&!/^url\(undefined/.test(x))&&l.style.setProperty(g,w.join(", "))}let h=s.getPropertyValue("background-color");h&&h!=="transparent"&&h!=="rgba(0, 0, 0, 0)"&&(l.style.backgroundColor=h);let m=Array.from(d.children),u=Array.from(l.children);for(let g=0;g<Math.min(m.length,u.length);g++)c.push([m[g],u[g]])}})}function kt(o){return p(this,arguments,function*(t,e={}){if(!t)throw new Error("Element cannot be null or undefined");let{compress:i=!0,embedFonts:r=!1,fast:n=!0,scale:f=1,useProxy:c=""}=e,a,d,l,s="",h="",m,u;if({clone:a,classCSS:d,styleCache:l}=yield Et(t,i,r,e),yield new Promise(y=>{V(()=>p(null,null,function*(){yield $t(a,e),y()}),{fast:n})}),yield new Promise(y=>{V(()=>p(null,null,function*(){yield vt(t,a,l,e),y()}),{fast:n})}),r&&(yield new Promise(y=>{V(()=>p(null,null,function*(){s=yield J(),y()}),{fast:n})})),i){let y=ut(a).sort(),b=y.join(",");W.has(b)?h=W.get(b):yield new Promise(w=>{V(()=>{h=pt(y),W.set(b,h),w()},{fast:n})})}yield new Promise(y=>{V(()=>{let b=t.getBoundingClientRect(),w=b.width,x=b.height,N=Number.isFinite(e.width),C=Number.isFinite(e.height),k=typeof f=="number"&&f!==1;if(!k){let L=b.width/b.height;N&&C?(w=e.width,x=e.height):N?(w=e.width,x=w/L):C&&(x=e.height,w=x*L)}if(w=Math.ceil(w),x=Math.ceil(x),a.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),a.style.transformOrigin="top left",!k&&(N||C)){let L=b.width,Tt=b.height,Nt=w/L,Pt=x/Tt,Lt=a.style.transform||"",Ut=`scale(${Nt}, ${Pt})`;a.style.transform=`${Ut} ${Lt}`.trim()}else k&&K()&&(a.style.scale=`${f}`);let B="http://www.w3.org/2000/svg",v=document.createElementNS(B,"foreignObject");v.setAttribute("width","100%"),v.setAttribute("height","100%");let I=document.createElement("style");I.textContent=h+s+"svg{overflow:visible;}"+d,v.appendChild(I),v.appendChild(a);let q=new XMLSerializer().serializeToString(v);u=`<svg xmlns="${B}" width="${w}" height="${x}" viewBox="0 0 ${w} ${x}">`+q+"</svg>",m=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`,y()},{fast:n})});let g=document.getElementById("snapdom-sandbox");return g&&g.style.position==="absolute"&&g.remove(),m})}function jt(i,r){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1}){let n=new Image;return n.src=t,yield n.decode(),K?(n.width=n.width*o,n.height=n.height*o):(n.width=n.width/o,n.height=n.height/o),n})}function It(i){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1}={}){let r=new Image;r.src=t,yield r.decode();let n=document.createElement("canvas"),f=r.width*o,c=r.height*o;n.width=Math.ceil(f*e),n.height=Math.ceil(c*e);let a=n.getContext("2d");return a.scale(e,e),a.drawImage(r,0,0,f,c),n.style.width=`${f}px`,n.style.height=`${c}px`,n})}function Rt(n){return p(this,arguments,function*(t,{type:e="svg",scale:o=1,backgroundColor:i="#fff",quality:r}={}){let f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[e]||"image/png";if(e==="svg"){let a=decodeURIComponent(t.split(",")[1]);return new Blob([a],{type:"image/svg+xml"})}let c=yield it(t,{dpr:1,scale:o},i);return new Promise(a=>{c.toBlob(d=>a(d),`${f}`,r)})})}function it(r,n,f){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1},i){let c=yield It(t,{dpr:e,scale:o});if(!i)return c;let a=document.createElement("canvas");a.width=c.width,a.height=c.height;let d=a.getContext("2d");return d.fillStyle=i,d.fillRect(0,0,a.width,a.height),d.drawImage(c,0,0),a})}function st(f,c){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1,backgroundColor:i="#fff",quality:r},n="png"){let a=yield it(t,{dpr:e,scale:o},i),d=new Image;return d.src=a.toDataURL(`image/${n}`,r),yield d.decode(),d.style.width=`${a.width/e}px`,d.style.height=`${a.height/e}px`,d})}function Vt(f){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1,backgroundColor:i="#fff",format:r="png",filename:n="capture"}={}){if(r==="svg"){let m=yield Rt(t),u=URL.createObjectURL(m),g=document.createElement("a");g.href=u,g.download=`${n}.svg`,g.click(),URL.revokeObjectURL(u);return}let c=["jpg","jpeg","webp"].includes(r)?"#fff":void 0,a=i!=null?i:c,d=yield it(t,{dpr:e,scale:o},a),l={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[r]||"image/png",s=d.toDataURL(l),h=document.createElement("a");h.href=s,h.download=`${n}.${r}`,h.click()})}function S(o){return p(this,arguments,function*(t,e={}){if(e=D({scale:1},e),!t)throw new Error("Element cannot be null or undefined");return e.iconFonts&&xt(e.iconFonts),yield S.capture(t,e)})}S.capture=(o,...i)=>p(null,[o,...i],function*(t,e={}){let r=yield kt(t,e),n=window.devicePixelRatio||1,f=e.scale||1;return{url:r,options:e,toRaw:()=>r,toImg:()=>jt(r,{dpr:n,scale:f}),toCanvas:()=>It(r,{dpr:n,scale:f}),toBlob:c=>Rt(r,D({dpr:n,scale:f},c)),toPng:c=>st(r,D({dpr:n,scale:f},c),"png"),toJpg:c=>st(r,D({dpr:n,scale:f},c),"jpeg"),toWebp:c=>st(r,D({dpr:n,scale:f},c),"webp"),download:({format:c="png",filename:a="capture",backgroundColor:d}={})=>Vt(r,{dpr:n,scale:f,backgroundColor:d,format:c,filename:a})}});S.toRaw=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toRaw()});S.toImg=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toImg()});S.toCanvas=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toCanvas()});S.toBlob=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toBlob(e)});S.toPng=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toPng(e)});S.toJpg=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toJpg(e)});S.toWebp=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toWebp(e)});S.download=(o,...i)=>p(null,[o,...i],function*(t,e={}){let d=e,{format:r="png",filename:n="capture",backgroundColor:f}=d,c=dt(d,["format","filename","backgroundColor"]);return yield(yield S.capture(t,c)).download({format:r,filename:n,backgroundColor:f})});function At(){return p(this,arguments,function*(t=document,e={}){let{embedFonts:o=!0,reset:i=!1}=e;if(i){R.clear(),M.clear(),$.clear(),W.clear();return}yield document.fonts.ready,ht();let r=[],n=[];t!=null&&t.querySelectorAll&&(r=Array.from(t.querySelectorAll("img[src]")),n=Array.from(t.querySelectorAll("*")));let f=[];for(let c of r){let a=c.src;R.has(a)||f.push(F(a,{useProxy:e.useProxy}).then(d=>R.set(a,d)).catch(()=>{}))}for(let c of n){let a=U(c).backgroundImage;if(a&&a!=="none"){let d=_(a);for(let l of d)l.startsWith("url(")&&f.push(j(l,e).catch(()=>{}))}}o&&(yield J({preCached:!0})),yield Promise.all(f)})}window.snapdom=S;window.preCache=At;})();
@@ -1,15 +1,15 @@
1
- var $=new Map,F=new Map,S=new Map,B=new Map,D=new Map,G=new WeakMap,R=new Set;var It=["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","svg","path","circle","rect","line","g","table","thead","tbody","tr","td","th"];function rt(){for(let t of It)st(t)}function st(t){if(B.has(t))return B.get(t);if(new Set(["script","style","meta","link","noscript","template"]).has(t)){let c={};return B.set(t,c),c}let o=document.getElementById("snapdom-sandbox");o||(o=document.createElement("div"),o.id="snapdom-sandbox",o.style.position="absolute",o.style.left="-9999px",o.style.top="-9999px",o.style.width="0",o.style.height="0",o.style.overflow="hidden",document.body.appendChild(o));let r=document.createElement(t);r.style.all="initial",o.appendChild(r);let a=getComputedStyle(r),n={};for(let c of a)n[c]=a.getPropertyValue(c);return o.removeChild(r),B.set(t,n),n}function V(t,e,o=!1){let r=[],a=st(e);for(let[n,c]of Object.entries(t))if(!o)c&&r.push(`${n}:${c}`);else{let i=a[n];c&&c!==i&&r.push(`${n}:${c}`)}return r.sort().join(";")}function it(t){let e=new Set;return t.nodeType!==Node.ELEMENT_NODE&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(t.tagName&&e.add(t.tagName.toLowerCase()),typeof t.querySelectorAll=="function"&&t.querySelectorAll("*").forEach(o=>e.add(o.tagName.toLowerCase())),Array.from(e))}function ct(t){let e=new Map;for(let r of t){let a=B.get(r);if(!a)continue;let n=Object.entries(a).map(([c,i])=>`${c}:${i};`).sort().join("");e.has(n)||e.set(n,[]),e.get(n).push(r)}let o="";for(let[r,a]of e.entries())o+=`${a.join(",")} { ${r} }
2
- `;return o}function lt(t){let e=new Set(t.values()),o=new Map,r=1;for(let a of e)o.set(a,`c${r++}`);return o}async function M(t,e={}){let o=t.startsWith("url("),r=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t);if(o){let a=_(t);if(!a)return t;let n=Y(a);if(F.has(n))return e.skipInline?void 0:`url(${F.get(n)})`;{let c=await N(n,{useProxy:e.useProxy});return F.set(n,c),e.skipInline?void 0:`url("${c}")`}}return t}function W(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function U(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let o=G.get(t);if(o||(o=new Map,G.set(t,o)),!o.has(e)){let r=window.getComputedStyle(t,e);o.set(e,r)}return o.get(e)}function ft(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch{return e}return e}function _(t){let e=t.indexOf("url(");if(e===-1)return null;let o=t.slice(e+4).trim();return o.endsWith(")")&&(o=o.slice(0,-1).trim()),(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))&&(o=o.slice(1,-1)),o}function N(t,{timeout:e=3e3,useProxy:o=""}={}){function r(h){try{return new URL(h,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch{return"anonymous"}}async function a(h){let l=s=>fetch(s,{mode:"cors",credentials:r(s)==="use-credentials"?"include":"omit"}).then(f=>f.blob()).then(f=>new Promise((u,m)=>{let d=new FileReader;d.onloadend=()=>{let g=d.result;if(typeof g!="string"||!g.startsWith("data:image/")){m(new Error("Invalid image data URL"));return}u(g)},d.onerror=()=>m(new Error("FileReader error")),d.readAsDataURL(f)}));try{return await l(h)}catch{if(o&&typeof o=="string"){let f=o.replace(/\/$/,"")+Y(h);try{return await l(f)}catch{throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${h}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${h}`),new Error("Fetch fallback failed and no proxy provided")}}let n=r(t);return console.log(`[SnapDOM - fetchImage] Start loading image: ${t} with crossOrigin=${n}`),$.has(t)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${t}`),Promise.resolve($.get(t))):t.startsWith("data:image/")?($.set(t,t),Promise.resolve(t)):/\.svg(\?.*)?$/i.test(t)?(async()=>{try{let l=await(await fetch(t,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),s=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(l)}`;return $.set(t,s),s}catch{return a(t)}})():new Promise((h,l)=>{let s=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${e}ms for image: ${t}`),l(new Error("Image load timed out"))},e),f=new Image;f.crossOrigin=n,f.onload=async()=>{clearTimeout(s);try{await f.decode();let u=document.createElement("canvas");u.width=f.width,u.height=f.height,u.getContext("2d").drawImage(f,0,0,u.width,u.height);let d=u.toDataURL("image/png");$.set(t,d),h(d)}catch{try{let u=await a(t);$.set(t,u),h(u)}catch(u){l(u)}}},f.onerror=async()=>{clearTimeout(s),console.error(`[SnapDOM - fetchImage] Image failed to load: ${t}`);try{let u=await a(t);$.set(t,u),h(u)}catch(u){l(u)}},f.src=t})}function J(t){let e={};for(let o of t)e[o]=t.getPropertyValue(o);return e}function H(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function dt(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(o,r)=>{let a=r.split(",").map(n=>n.trim());return a.length!==6?`matrix(${r})`:(a[4]="0",a[5]="0",`matrix(${a.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(o,r)=>{let a=r.split(",").map(n=>n.trim());return a.length!==16?`matrix3d(${r})`:(a[12]="0",a[13]="0",`matrix3d(${a.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function Y(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function j(t){let e=[],o=0,r=0;for(let a=0;a<t.length;a++){let n=t[a];n==="("&&o++,n===")"&&o--,n===","&&o===0&&(e.push(t.slice(r,a).trim()),r=a+1)}return e.push(t.slice(r).trim()),e}var Q=new WeakMap,Z=new Map;function kt(t){let e={};for(let o=0;o<t.length;o++){let r=t[o],a=t.getPropertyValue(r);(r==="background-image"||r==="content")&&a.includes("url(")&&!a.includes("data:")&&(a="none"),e[r]=a}return e}function tt(t,e,o,r,a){if(t.tagName==="STYLE")return;r.has(t)||r.set(t,U(t));let n=r.get(t);if(!Q.has(t)){let s=kt(n);Q.set(t,s)}let c=Q.get(t),i=Object.entries(c).sort(([s],[f])=>s.localeCompare(f)).map(([s,f])=>`${s}:${f}`).join(";");if(Z.has(i)){o.set(e,Z.get(i));return}let h=t.tagName?.toLowerCase()||"div",l=V(c,h,a);Z.set(i,l),o.set(e,l)}function X(t,e,o,r,a,n={},c){if(t.nodeType===Node.TEXT_NODE){if(t.parentElement?.shadowRoot){let s=t.parentElement.tagName.toLowerCase();if(customElements.get(s))return null}return t.cloneNode(!0)}if(t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);if(t.getAttribute("data-capture")==="exclude"){let s=document.createElement("div"),f=t.getBoundingClientRect();return s.style.cssText=`display: inline-block; width: ${f.width}px; height: ${f.height}px; visibility: hidden;`,s}if(n.exclude&&Array.isArray(n.exclude)&&n.exclude.length>0)for(let s of n.exclude)try{if(t.matches&&t.matches(s)){let f=document.createElement("div"),u=t.getBoundingClientRect();return f.style.cssText=`display: inline-block; width: ${u.width}px; height: ${u.height}px; visibility: hidden;`,f}}catch(f){console.warn(`Invalid selector in exclude option: ${s}`,f)}if(typeof n.filter=="function")try{if(!n.filter(t,c||t)){let s=document.createElement("div"),f=t.getBoundingClientRect();return s.style.cssText=`display: inline-block; width: ${f.width}px; height: ${f.height}px; visibility: hidden;`,s}}catch(s){console.warn("Error in filter function:",s)}if(t.tagName==="IFRAME"){let s=document.createElement("div");return s.textContent="",s.style.cssText=`width: ${t.offsetWidth}px; height: ${t.offsetHeight}px; background-image: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,s}if(t.getAttribute("data-capture")==="placeholder"){let s=t.cloneNode(!1);r.set(s,t),tt(t,s,e,o,a);let f=document.createElement("div");return f.textContent=t.getAttribute("data-placeholder-text")||"",f.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",s.appendChild(f),s}if(t.tagName==="CANVAS"){let s=t.toDataURL(),f=document.createElement("img");return f.src=s,f.width=t.width,f.height=t.height,f.style.display="inline-block",f.style.width=t.style.width||`${t.width}px`,f.style.height=t.style.height||`${t.height}px`,f}let i=t.cloneNode(!1);r.set(i,t),t instanceof HTMLInputElement?(i.value=t.value,i.setAttribute("value",t.value),t.checked!==void 0&&(i.checked=t.checked,t.checked&&i.setAttribute("checked",""))):t instanceof HTMLTextAreaElement?(i.value=t.value,i.textContent=t.value):t instanceof HTMLSelectElement&&(i.value=t.value,Array.from(i.options).forEach(s=>{s.value===t.value?s.setAttribute("selected",""):s.removeAttribute("selected")})),tt(t,i,e,o,a);let h=document.createDocumentFragment(),l=c||t;if(t.childNodes.forEach(s=>{let f=X(s,e,o,r,a,n,l);f&&h.appendChild(f)}),i.appendChild(h),t.shadowRoot){let s=Array.from(t.shadowRoot.children).filter(u=>u.tagName!=="STYLE").map(u=>X(u,e,o,r,a,n,l)).filter(Boolean),f=document.createDocumentFragment();s.forEach(u=>f.appendChild(u)),i.appendChild(f)}return i}var Rt=[/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],et=[];function ht(t){let e=Array.isArray(t)?t:[t];for(let o of e)o instanceof RegExp?et.push(o):typeof o=="string"?et.push(new RegExp(o,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",o)}function A(t){let e=typeof t=="string"?t:"",o=[...Rt,...et];for(let r of o)if(r instanceof RegExp&&r.test(e))return!0;return!!(/icon/i.test(e)||/glyph/i.test(e)||/symbols/i.test(e)||/feather/i.test(e)||/fontawesome/i.test(e))}async function ut(t,e,o,r=32,a="#000"){e=e.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,i=document.createElement("canvas").getContext("2d");i.font=o?`${o} ${r}px "${e}"`:`${r}px "${e}"`;let h=i.measureText(t),l=h.actualBoundingBoxAscent||r*.8,s=h.actualBoundingBoxDescent||r*.2,f=l+s,u=h.width,m=document.createElement("canvas");m.width=Math.ceil(u*n),m.height=Math.ceil(f*n);let d=m.getContext("2d");return d.scale(n,n),d.font=i.font,d.textAlign="left",d.textBaseline="alphabetic",d.fillStyle=a,d.fillText(t,0,l),m.toDataURL()}function mt(t){return Array.from(document.styleSheets).some(e=>e.href===t)}function At(t){return new Promise(e=>{if(mt(t))return e(null);let o=document.createElement("link");o.rel="stylesheet",o.href=t,o.setAttribute("data-snapdom","injected-import"),o.onload=()=>e(o),o.onerror=()=>e(null),document.head.appendChild(o)})}async function K({preCached:t=!1}={}){if(S.has("fonts-embed-css")){if(t){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=S.get("fonts-embed-css"),document.head.appendChild(n)}return S.get("fonts-embed-css")}let e=/@import\s+url\(["']?([^"')]+)["']?\)/g,o=[];for(let n of document.querySelectorAll("style")){let c=n.textContent||"",i=Array.from(c.matchAll(e));for(let h of i){let l=h[1];A(l)||mt(l)||o.push(l)}}await Promise.all(o.map(At));let r=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),a="";for(let n of r)try{let i=await(await fetch(n.href)).text();if(A(n.href)||A(i))continue;let h=/url\((["']?)([^"')]+)\1\)/g,l=await Promise.all(Array.from(i.matchAll(h)).map(async f=>{let u=_(f[0]);if(!u)return null;let m=u;if(!m.startsWith("http")&&!m.startsWith("data:")&&(m=new URL(m,n.href).href),A(m))return null;if(S.has(m))return R.add(m),{original:f[0],inlined:`url(${S.get(m)})`};if(R.has(m))return null;try{let g=await(await fetch(m)).blob(),p=await new Promise(y=>{let w=new FileReader;w.onload=()=>y(w.result),w.readAsDataURL(g)});return S.set(m,p),R.add(m),{original:f[0],inlined:`url(${p})`}}catch{return console.warn("[snapdom] Failed to fetch font resource:",m),null}})),s=i;for(let f of l)f&&(s=s.replace(f.original,f.inlined));a+=s+`
3
- `}catch{console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||r.every(c=>c.href!==n.href)){for(let c of n.cssRules)if(c.type===CSSRule.FONT_FACE_RULE){let i=c.style.getPropertyValue("src"),h=c.style.getPropertyValue("font-family");if(!i||A(h))continue;let l=/url\((["']?)([^"')]+)\1\)/g,s=i,f=Array.from(i.matchAll(l));for(let u of f){let m=u[2].trim();if(!m)continue;let d=m;if(!d.startsWith("http")&&!d.startsWith("data:")&&(d=new URL(d,n.href||location.href).href),!A(d)){if(S.has(d)){R.add(d),s=s.replace(u[0],`url(${S.get(d)})`);continue}if(!R.has(d))try{let p=await(await fetch(d)).blob(),y=await new Promise(w=>{let E=new FileReader;E.onload=()=>w(E.result),E.readAsDataURL(p)});S.set(d,y),R.add(d),s=s.replace(u[0],`url(${y})`)}catch{console.warn("[snapdom] Failed to fetch font URL:",d)}}}a+=`@font-face {
4
- font-family: ${h};
5
- src: ${s};
1
+ var v=new Map,F=new Map,S=new Map,B=new Map,D=new Map,G=new WeakMap,R=new Set;var kt=["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","svg","path","circle","rect","line","g","table","thead","tbody","tr","td","th"];function rt(){for(let t of kt)st(t)}function st(t){if(B.has(t))return B.get(t);if(new Set(["script","style","meta","link","noscript","template"]).has(t)){let c={};return B.set(t,c),c}let n=document.getElementById("snapdom-sandbox");n||(n=document.createElement("div"),n.id="snapdom-sandbox",n.style.position="absolute",n.style.left="-9999px",n.style.top="-9999px",n.style.width="0",n.style.height="0",n.style.overflow="hidden",document.body.appendChild(n));let r=document.createElement(t);r.style.all="initial",n.appendChild(r);let a=getComputedStyle(r),o={};for(let c of a)o[c]=a.getPropertyValue(c);return n.removeChild(r),B.set(t,o),o}function V(t,e,n=!1){let r=[],a=st(e);for(let[o,c]of Object.entries(t))if(!n)c&&r.push(`${o}:${c}`);else{let i=a[o];c&&c!==i&&r.push(`${o}:${c}`)}return r.sort().join(";")}function it(t){let e=new Set;return t.nodeType!==Node.ELEMENT_NODE&&t.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(t.tagName&&e.add(t.tagName.toLowerCase()),typeof t.querySelectorAll=="function"&&t.querySelectorAll("*").forEach(n=>e.add(n.tagName.toLowerCase())),Array.from(e))}function ct(t){let e=new Map;for(let r of t){let a=B.get(r);if(!a)continue;let o=Object.entries(a).map(([c,i])=>`${c}:${i};`).sort().join("");e.has(o)||e.set(o,[]),e.get(o).push(r)}let n="";for(let[r,a]of e.entries())n+=`${a.join(",")} { ${r} }
2
+ `;return n}function lt(t){let e=new Set(t.values()),n=new Map,r=1;for(let a of e)n.set(a,`c${r++}`);return n}async function M(t,e={}){let r=t.match(/url\(["']?(.*?)["']?\)/)?.[1],a=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t);if(r){let o=Y(r);if(F.has(o))return e.skipInline?void 0:`url(${F.get(o)})`;{let c=await U(o,{useProxy:e.useProxy});return F.set(o,c),e.skipInline?void 0:`url("${c}")`}}return t}function O(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function L(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let n=G.get(t);if(n||(n=new Map,G.set(t,n)),!n.has(e)){let r=window.getComputedStyle(t,e);n.set(e,r)}return n.get(e)}function ft(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch{return e}return e}function H(t){let e=t.indexOf("url(");if(e===-1)return null;let n=t.slice(e+4).trim();return n.endsWith(")")&&(n=n.slice(0,-1).trim()),(n.startsWith('"')&&n.endsWith('"')||n.startsWith("'")&&n.endsWith("'"))&&(n=n.slice(1,-1)),n}function U(t,{timeout:e=3e3,useProxy:n=""}={}){function r(l){try{return new URL(l,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch{return"anonymous"}}async function a(l){let s=f=>fetch(f,{mode:"cors",credentials:r(f)==="use-credentials"?"include":"omit"}).then(d=>d.blob()).then(d=>new Promise((h,u)=>{let m=new FileReader;m.onloadend=()=>{let g=m.result;if(typeof g!="string"||!g.startsWith("data:image/")){u(new Error("Invalid image data URL"));return}h(g)},m.onerror=()=>u(new Error("FileReader error")),m.readAsDataURL(d)}));try{return await s(l)}catch{if(n&&typeof n=="string"){let d=n.replace(/\/$/,"")+Y(l);try{return await s(d)}catch{throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${l}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${l}`),new Error("Fetch fallback failed and no proxy provided")}}let o=r(t);return console.log(`[SnapDOM - fetchImage] Start loading image: ${t} with crossOrigin=${o}`),v.has(t)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${t}`),Promise.resolve(v.get(t))):t.startsWith("data:image/")?(v.set(t,t),Promise.resolve(t)):/\.svg(\?.*)?$/i.test(t)?(async()=>{try{let s=await(await fetch(t,{mode:"cors",credentials:o==="use-credentials"?"include":"omit"})).text(),f=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(s)}`;return v.set(t,f),f}catch{return a(t)}})():new Promise((l,s)=>{let f=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${e}ms for image: ${t}`),s(new Error("Image load timed out"))},e),d=new Image;d.crossOrigin=o,d.onload=async()=>{clearTimeout(f);try{await d.decode();let h=document.createElement("canvas");h.width=d.width,h.height=d.height,h.getContext("2d").drawImage(d,0,0,h.width,h.height);let m=h.toDataURL("image/png");v.set(t,m),l(m)}catch{try{let h=await a(t);v.set(t,h),l(h)}catch(h){s(h)}}},d.onerror=async()=>{clearTimeout(f),console.error(`[SnapDOM - fetchImage] Image failed to load: ${t}`);try{let h=await a(t);v.set(t,h),l(h)}catch(h){s(h)}},d.src=t})}function J(t){let e={};for(let n of t)e[n]=t.getPropertyValue(n);return e}function X(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function dt(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(n,r)=>{let a=r.split(",").map(o=>o.trim());return a.length!==6?`matrix(${r})`:(a[4]="0",a[5]="0",`matrix(${a.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(n,r)=>{let a=r.split(",").map(o=>o.trim());return a.length!==16?`matrix3d(${r})`:(a[12]="0",a[13]="0",`matrix3d(${a.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function Y(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function W(t){let e=[],n=0,r=0;for(let a=0;a<t.length;a++){let o=t[a];o==="("&&n++,o===")"&&n--,o===","&&n===0&&(e.push(t.slice(r,a).trim()),r=a+1)}return e.push(t.slice(r).trim()),e}var Q=new WeakMap,Z=new Map;function It(t){let e={};for(let n=0;n<t.length;n++){let r=t[n],a=t.getPropertyValue(r);(r==="background-image"||r==="content")&&a.includes("url(")&&!a.includes("data:")&&(a="none"),e[r]=a}return e}function tt(t,e,n,r,a){if(t.tagName==="STYLE")return;r.has(t)||r.set(t,L(t));let o=r.get(t);if(!Q.has(t)){let f=It(o);Q.set(t,f)}let c=Q.get(t),i=Object.entries(c).sort(([f],[d])=>f.localeCompare(d)).map(([f,d])=>`${f}:${d}`).join(";");if(Z.has(i)){n.set(e,Z.get(i));return}let l=t.tagName?.toLowerCase()||"div",s=V(c,l,a);Z.set(i,s),n.set(e,s)}function Rt(t){return t.nodeType===Node.ELEMENT_NODE&&t.tagName==="SLOT"}function _(t,e,n,r,a,o={},c){if(t.nodeType===Node.TEXT_NODE||t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);if(t.getAttribute("data-capture")==="exclude"){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}if(o.exclude&&Array.isArray(o.exclude))for(let l of o.exclude)try{if(t.matches?.(l)){let s=document.createElement("div"),f=t.getBoundingClientRect();return s.style.cssText=`display: inline-block; width: ${f.width}px; height: ${f.height}px; visibility: hidden;`,s}}catch(s){console.warn(`Invalid selector in exclude option: ${l}`,s)}if(typeof o.filter=="function")try{if(!o.filter(t,c||t)){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}}catch(l){console.warn("Error in filter function:",l)}if(t.tagName==="IFRAME"){let l=document.createElement("div");return l.textContent="",l.style.cssText=`width: ${t.offsetWidth}px; height: ${t.offsetHeight}px; background-image: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,l}if(t.getAttribute("data-capture")==="placeholder"){let l=t.cloneNode(!1);r.set(l,t),tt(t,l,e,n,a);let s=document.createElement("div");return s.textContent=t.getAttribute("data-placeholder-text")||"",s.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",l.appendChild(s),l}if(t.tagName==="CANVAS"){let l=t.toDataURL(),s=document.createElement("img");return s.src=l,s.width=t.width,s.height=t.height,s.style.display="inline-block",s.style.width=t.style.width||`${t.width}px`,s.style.height=t.style.height||`${t.height}px`,s}let i=t.cloneNode(!1);if(r.set(i,t),t instanceof HTMLInputElement)i.value=t.value,i.setAttribute("value",t.value),t.checked!==void 0&&(i.checked=t.checked,t.checked&&i.setAttribute("checked",""));else if(t instanceof HTMLTextAreaElement){let l=t.getBoundingClientRect();i.textContent=t.value,i.style.width=`${l.width}px`,i.style.height=`${l.height}px`}else t instanceof HTMLSelectElement&&(i.value=t.value,Array.from(i.options).forEach(l=>{l.value===t.value?l.setAttribute("selected",""):l.removeAttribute("selected")}));if(tt(t,i,e,n,a),Rt(t)){let l=t.assignedNodes?.({flatten:!0})||[],s=l.length>0?l:Array.from(t.childNodes),f=document.createDocumentFragment();for(let d of s){let h=_(d,e,n,r,a,o,c||t);h&&f.appendChild(h)}return f}else if(!(t instanceof HTMLTextAreaElement)){let l=t.shadowRoot?t.shadowRoot.childNodes:t.childNodes;for(let s of l){let f=_(s,e,n,r,a,o,c||t);f&&i.appendChild(f)}if(t.shadowRoot&&t.childNodes.length>0&&!t.shadowRoot.querySelector("slot")){let s=document.createDocumentFragment();for(let f of t.childNodes){let d=_(f,e,n,r,a,o,c||t);d&&s.appendChild(d)}i.appendChild(s)}}return i}var At=[/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],et=[];function ht(t){let e=Array.isArray(t)?t:[t];for(let n of e)n instanceof RegExp?et.push(n):typeof n=="string"?et.push(new RegExp(n,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",n)}function A(t){let e=typeof t=="string"?t:"",n=[...At,...et];for(let r of n)if(r instanceof RegExp&&r.test(e))return!0;return!!(/icon/i.test(e)||/glyph/i.test(e)||/symbols/i.test(e)||/feather/i.test(e)||/fontawesome/i.test(e))}async function mt(t,e,n,r=32,a="#000"){e=e.replace(/^['"]+|['"]+$/g,"");let o=window.devicePixelRatio||1,i=document.createElement("canvas").getContext("2d");i.font=n?`${n} ${r}px "${e}"`:`${r}px "${e}"`;let l=i.measureText(t),s=l.actualBoundingBoxAscent||r*.8,f=l.actualBoundingBoxDescent||r*.2,d=s+f,h=l.width,u=document.createElement("canvas");u.width=Math.ceil(h*o),u.height=Math.ceil(d*o);let m=u.getContext("2d");return m.scale(o,o),m.font=i.font,m.textAlign="left",m.textBaseline="alphabetic",m.fillStyle=a,m.fillText(t,0,s),u.toDataURL()}function ut(t){return Array.from(document.styleSheets).some(e=>e.href===t)}function Tt(t){return new Promise(e=>{if(ut(t))return e(null);let n=document.createElement("link");n.rel="stylesheet",n.href=t,n.setAttribute("data-snapdom","injected-import"),n.onload=()=>e(n),n.onerror=()=>e(null),document.head.appendChild(n)})}async function K({preCached:t=!1}={}){if(S.has("fonts-embed-css")){if(t){let o=document.createElement("style");o.setAttribute("data-snapdom","embedFonts"),o.textContent=S.get("fonts-embed-css"),document.head.appendChild(o)}return S.get("fonts-embed-css")}let e=/@import\s+url\(["']?([^"')]+)["']?\)/g,n=[];for(let o of document.querySelectorAll("style")){let c=o.textContent||"",i=Array.from(c.matchAll(e));for(let l of i){let s=l[1];A(s)||ut(s)||n.push(s)}}await Promise.all(n.map(Tt));let r=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(o=>o.href),a="";for(let o of r)try{let i=await(await fetch(o.href)).text();if(A(o.href)||A(i))continue;let l=/url\((["']?)([^"')]+)\1\)/g,s=await Promise.all(Array.from(i.matchAll(l)).map(async d=>{let h=H(d[0]);if(!h)return null;let u=h;if(!u.startsWith("http")&&!u.startsWith("data:")&&(u=new URL(u,o.href).href),A(u))return null;if(S.has(u))return R.add(u),{original:d[0],inlined:`url(${S.get(u)})`};if(R.has(u))return null;try{let g=await(await fetch(u)).blob(),p=await new Promise(y=>{let w=new FileReader;w.onload=()=>y(w.result),w.readAsDataURL(g)});return S.set(u,p),R.add(u),{original:d[0],inlined:`url(${p})`}}catch{return console.warn("[snapdom] Failed to fetch font resource:",u),null}})),f=i;for(let d of s)d&&(f=f.replace(d.original,d.inlined));a+=f+`
3
+ `}catch{console.warn("[snapdom] Failed to fetch CSS:",o.href)}for(let o of document.styleSheets)try{if(!o.href||r.every(c=>c.href!==o.href)){for(let c of o.cssRules)if(c.type===CSSRule.FONT_FACE_RULE){let i=c.style.getPropertyValue("src"),l=c.style.getPropertyValue("font-family");if(!i||A(l))continue;let s=/url\((["']?)([^"')]+)\1\)/g,f=i,d=Array.from(i.matchAll(s));for(let h of d){let u=h[2].trim();if(!u)continue;let m=u;if(!m.startsWith("http")&&!m.startsWith("data:")&&(m=new URL(m,o.href||location.href).href),!A(m)){if(S.has(m)){R.add(m),f=f.replace(h[0],`url(${S.get(m)})`);continue}if(!R.has(m))try{let p=await(await fetch(m)).blob(),y=await new Promise(w=>{let E=new FileReader;E.onload=()=>w(E.result),E.readAsDataURL(p)});S.set(m,y),R.add(m),f=f.replace(h[0],`url(${y})`)}catch{console.warn("[snapdom] Failed to fetch font URL:",m)}}}a+=`@font-face {
4
+ font-family: ${l};
5
+ src: ${f};
6
6
  font-style: ${c.style.getPropertyValue("font-style")||"normal"};
7
7
  font-weight: ${c.style.getPropertyValue("font-weight")||"normal"};
8
8
  }
9
- `}}}catch(c){console.warn("[snapdom] Cannot access stylesheet",n.href,c)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(A(n.family))continue;let c=n._snapdomSrc;if(!c.startsWith("data:")){if(S.has(n._snapdomSrc))c=S.get(n._snapdomSrc),R.add(n._snapdomSrc);else if(!R.has(n._snapdomSrc))try{let h=await(await fetch(n._snapdomSrc)).blob();c=await new Promise(l=>{let s=new FileReader;s.onload=()=>l(s.result),s.readAsDataURL(h)}),S.set(n._snapdomSrc,c),R.add(n._snapdomSrc)}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}a+=`@font-face {
10
- font-family: '${n.family}';
9
+ `}}}catch(c){console.warn("[snapdom] Cannot access stylesheet",o.href,c)}for(let o of document.fonts)if(o.family&&o.status==="loaded"&&o._snapdomSrc){if(A(o.family))continue;let c=o._snapdomSrc;if(!c.startsWith("data:")){if(S.has(o._snapdomSrc))c=S.get(o._snapdomSrc),R.add(o._snapdomSrc);else if(!R.has(o._snapdomSrc))try{let l=await(await fetch(o._snapdomSrc)).blob();c=await new Promise(s=>{let f=new FileReader;f.onload=()=>s(f.result),f.readAsDataURL(l)}),S.set(o._snapdomSrc,c),R.add(o._snapdomSrc)}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",o._snapdomSrc);continue}}a+=`@font-face {
10
+ font-family: '${o.family}';
11
11
  src: url(${c});
12
- font-style: ${n.style||"normal"};
13
- font-weight: ${n.weight||"normal"};
12
+ font-style: ${o.style||"normal"};
13
+ font-weight: ${o.weight||"normal"};
14
14
  }
15
- `}if(a&&(S.set("fonts-embed-css",a),t)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=a,document.head.appendChild(n)}return a}async function nt(t,e,o,r,a,n=!1,c){if(!(t instanceof Element)||!(e instanceof Element))return;for(let l of["::before","::after","::first-letter"])try{let s=U(t,l);if(!s||typeof s[Symbol.iterator]!="function")continue;if(l==="::first-letter"){let y=getComputedStyle(t);if(!(s.color!==y.color||s.fontSize!==y.fontSize||s.fontWeight!==y.fontWeight))continue;let E=Array.from(e.childNodes).find(C=>C.nodeType===Node.TEXT_NODE&&C.textContent&&C.textContent.trim().length>0);if(!E)continue;let L=E.textContent,T=L.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],P=L.slice(T?.length||0);if(!T||/[\uD800-\uDFFF]/.test(T))continue;let I=document.createElement("span");I.textContent=T,I.dataset.snapdomPseudo="::first-letter";let k=J(s),q=V(k,"span",a);o.set(I,q);let z=document.createTextNode(P);e.replaceChild(z,E),e.insertBefore(I,z);continue}let f=s.getPropertyValue("content"),u=s.getPropertyValue("background-image"),m=s.getPropertyValue("background-color"),d=f!=="none",g=u&&u!=="none",p=m&&m!=="transparent"&&m!=="rgba(0, 0, 0, 0)";if(d||g||p){let y=s.getPropertyValue("font-family"),w=parseInt(s.getPropertyValue("font-size"))||32,E=parseInt(s.getPropertyValue("font-weight"))||!1,L=s.getPropertyValue("color")||"#000",b=document.createElement("span");b.dataset.snapdomPseudo=l;let T=J(s),P=V(T,"span",a);o.set(b,P);let I=A(y),k=ft(f);if(I&&k.length===1){let C=document.createElement("img");C.src=await ut(k,y,E,w,L),C.style=`width:${w}px;height:auto;object-fit:contain;`,b.appendChild(C)}else if(k.startsWith("url(")){let C=_(k);if(C&&C.trim()!=="")try{let v=document.createElement("img"),O=await N(Y(C,{useProxy:c}));v.src=O,v.style=`width:${w}px;height:auto;object-fit:contain;`,b.appendChild(v)}catch(v){console.error(`[snapdom] Error in pseudo ${l} for`,t,v)}}else!I&&k&&k!=="none"&&(b.textContent=k);if(g)try{let C=j(u),v=await Promise.all(C.map(O=>M(O)));b.style.backgroundImage=v.join(", ")}catch(C){console.warn(`[snapdom] Failed to inline background-image for ${l}`,C)}if(p&&(b.style.backgroundColor=m),!(b.childNodes.length>0||b.textContent&&b.textContent.trim()!==""||g||p))continue;l==="::before"?e.insertBefore(b,e.firstChild):e.appendChild(b)}}catch(s){console.warn(`[snapdom] Failed to capture ${l} for`,t,s)}let i=Array.from(t.children),h=Array.from(e.children).filter(l=>!l.dataset.snapdomPseudo);for(let l=0;l<Math.min(i.length,h.length);l++)await nt(i[l],h[l],o,r,a,n,c)}function gt(t){if(!t)return;let e=document.querySelectorAll("svg > defs");e.length&&t.querySelectorAll("svg").forEach(o=>{let r=o.querySelectorAll("use");if(!r.length)return;let a=new Set;if(r.forEach(c=>{let i=c.getAttribute("xlink:href")||c.getAttribute("href");i&&i.startsWith("#")&&a.add(i.slice(1))}),!a.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let c of a)for(let i of e){let h=i.querySelector(`#${CSS.escape(c)}`);if(h){n.appendChild(h.cloneNode(!0));break}}n.childNodes.length&&o.insertBefore(n,o.firstChild)})}async function pt(t,e=!1,o=!1,r={}){let a=new Map,n=new WeakMap,c=new Map,i;try{i=X(t,a,n,c,e,r,t)}catch(l){throw console.warn("deepClone failed:",l),l}try{await nt(t,i,a,n,e,o,r.useProxy)}catch(l){console.warn("inlinePseudoElements failed:",l)}try{gt(i)}catch(l){console.warn("inlineExternalDef failed:",l)}let h="";if(e){let l=lt(a);h=Array.from(l.entries()).map(([s,f])=>`.${f}{${s}}`).join("");for(let[s,f]of a.entries()){if(s.tagName==="STYLE")continue;let u=l.get(f);u&&s.classList.add(u);let m=s.style?.backgroundImage;s.removeAttribute("style"),m&&m!=="none"&&(s.style.backgroundImage=m)}}else for(let[l,s]of a.entries())l.tagName!=="STYLE"&&l.setAttribute("style",s.replace(/;/g,"; "));for(let[l,s]of c.entries()){let f=s.scrollLeft,u=s.scrollTop;if((f||u)&&l instanceof HTMLElement){l.style.overflow="hidden",l.style.scrollbarWidth="none",l.style.msOverflowStyle="none";let d=document.createElement("div");for(d.style.transform=`translate(${-f}px, ${-u}px)`,d.style.willChange="transform",d.style.display="inline-block",d.style.width="100%";l.firstChild;)d.appendChild(l.firstChild);l.appendChild(d)}}if(t===c.get(i)){let l=n.get(t)||window.getComputedStyle(t);n.set(t,l);let s=dt(l.transform);i.style.margin="0",i.style.position="static",i.style.top="auto",i.style.left="auto",i.style.right="auto",i.style.bottom="auto",i.style.zIndex="auto",i.style.float="none",i.style.clear="none",i.style.transform=s||""}for(let[l,s]of c.entries())s.tagName==="PRE"&&(l.style.marginTop="0",l.style.marginBlockStart="0");return{clone:i,classCSS:h,styleCache:n}}async function yt(t,e={}){let o=Array.from(t.querySelectorAll("img")),r=async a=>{let n=a.src;try{let c=await N(n,{useProxy:e.useProxy});a.src=c,a.width||(a.width=a.naturalWidth||100),a.height||(a.height=a.naturalHeight||100)}catch{let c=document.createElement("div");c.style=`width: ${a.width||100}px; height: ${a.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${a.height||100}px; color: #666; font-size: 12px;`,c.innerText="img",a.replaceWith(c)}};for(let a=0;a<o.length;a+=4){let n=o.slice(a,a+4).map(r);await Promise.allSettled(n)}}async function wt(t,e,o,r={}){let a=[[t,e]];for(;a.length;){let[n,c]=a.shift(),i=o.get(n)||U(n);o.has(n)||o.set(n,i);let h=i.getPropertyValue("background-image"),l=i.getPropertyValue("background-color");if(!h||h==="none"){let d=Array.from(n.children),g=Array.from(c.children);for(let p=0;p<Math.min(d.length,g.length);p++)a.push([d[p],g[p]]);continue}let s=j(h),f=await Promise.all(s.map(d=>M(d,r)));f.some(d=>d&&d!=="none"&&!/^url\(undefined\)/.test(d))&&(c.style.backgroundImage=f.join(", ")),l&&l!=="transparent"&&l!=="rgba(0, 0, 0, 0)"&&(c.style.backgroundColor=l);let u=Array.from(n.children),m=Array.from(c.children);for(let d=0;d<Math.min(u.length,m.length);d++)a.push([u[d],m[d]])}}async function xt(t,e={}){if(!t)throw new Error("Element cannot be null or undefined");let{compress:o=!0,embedFonts:r=!1,fast:a=!0,scale:n=1,useProxy:c=""}=e,i,h,l,s="",f="",u,m;if({clone:i,classCSS:h,styleCache:l}=await pt(t,o,r,e),await new Promise(g=>{W(async()=>{await yt(i,e),g()},{fast:a})}),await new Promise(g=>{W(async()=>{await wt(t,i,l,e),g()},{fast:a})}),r&&await new Promise(g=>{W(async()=>{s=await K(),g()},{fast:a})}),o){let g=it(i).sort(),p=g.join(",");D.has(p)?f=D.get(p):await new Promise(y=>{W(()=>{f=ct(g),D.set(p,f),y()},{fast:a})})}await new Promise(g=>{W(()=>{let p=t.getBoundingClientRect(),y=p.width,w=p.height,E=Number.isFinite(e.width),L=Number.isFinite(e.height),b=typeof n=="number"&&n!==1;if(!b){let v=p.width/p.height;E&&L?(y=e.width,w=e.height):E?(y=e.width,w=y/v):L&&(w=e.height,y=w*v)}if(y=Math.ceil(y),w=Math.ceil(w),i.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),i.style.transformOrigin="top left",!b&&(E||L)){let v=p.width,O=p.height,St=y/v,Et=w/O,vt=i.style.transform||"",$t=`scale(${St}, ${Et})`;i.style.transform=`${$t} ${vt}`.trim()}else b&&H()&&(i.style.scale=`${n}`);let T="http://www.w3.org/2000/svg",P=document.createElementNS(T,"foreignObject");P.setAttribute("width","100%"),P.setAttribute("height","100%");let I=document.createElement("style");I.textContent=f+s+"svg{overflow:visible;}"+h,P.appendChild(I),P.appendChild(i);let q=new XMLSerializer().serializeToString(P);m=`<svg xmlns="${T}" width="${y}" height="${w}" viewBox="0 0 ${y} ${w}">`+q+"</svg>",u=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(m)}`,g()},{fast:a})});let d=document.getElementById("snapdom-sandbox");return d&&d.style.position==="absolute"&&d.remove(),u}async function Tt(t,{dpr:e=1,scale:o=1}){let r=new Image;return r.src=t,await r.decode(),H?(r.width=r.width*o,r.height=r.height*o):(r.width=r.width/o,r.height=r.height/o),r}async function bt(t,{dpr:e=1,scale:o=1}={}){let r=new Image;r.src=t,await r.decode();let a=document.createElement("canvas"),n=r.width*o,c=r.height*o;a.width=Math.ceil(n*e),a.height=Math.ceil(c*e);let i=a.getContext("2d");return i.scale(e,e),i.drawImage(r,0,0,n,c),a.style.width=`${n}px`,a.style.height=`${c}px`,a}async function Ct(t,{type:e="svg",scale:o=1,backgroundColor:r="#fff",quality:a}={}){let n={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[e]||"image/png";if(e==="svg"){let i=decodeURIComponent(t.split(",")[1]);return new Blob([i],{type:"image/svg+xml"})}let c=await at(t,{dpr:1,scale:o},r);return new Promise(i=>{c.toBlob(h=>i(h),`${n}`,a)})}async function at(t,{dpr:e=1,scale:o=1},r){let a=await bt(t,{dpr:e,scale:o});if(!r)return a;let n=document.createElement("canvas");n.width=a.width,n.height=a.height;let c=n.getContext("2d");return c.fillStyle=r,c.fillRect(0,0,n.width,n.height),c.drawImage(a,0,0),n}async function ot(t,{dpr:e=1,scale:o=1,backgroundColor:r="#fff",quality:a},n="png"){let c=await at(t,{dpr:e,scale:o},r),i=new Image;return i.src=c.toDataURL(`image/${n}`,a),await i.decode(),i.style.width=`${c.width/e}px`,i.style.height=`${c.height/e}px`,i}async function Pt(t,{dpr:e=1,scale:o=1,backgroundColor:r="#fff",format:a="png",filename:n="capture"}={}){if(a==="svg"){let u=await Ct(t),m=URL.createObjectURL(u),d=document.createElement("a");d.href=m,d.download=`${n}.svg`,d.click(),URL.revokeObjectURL(m);return}let c=["jpg","jpeg","webp"].includes(a)?"#fff":void 0,h=await at(t,{dpr:e,scale:o},r??c),l={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[a]||"image/png",s=h.toDataURL(l),f=document.createElement("a");f.href=s,f.download=`${n}.${a}`,f.click()}async function x(t,e={}){if(e={scale:1,...e},!t)throw new Error("Element cannot be null or undefined");return e.iconFonts&&ht(e.iconFonts),await x.capture(t,e)}x.capture=async(t,e={})=>{let o=await xt(t,e),r=window.devicePixelRatio||1,a=e.scale||1;return{url:o,options:e,toRaw:()=>o,toImg:()=>Tt(o,{dpr:r,scale:a}),toCanvas:()=>bt(o,{dpr:r,scale:a}),toBlob:n=>Ct(o,{dpr:r,scale:a,...n}),toPng:n=>ot(o,{dpr:r,scale:a,...n},"png"),toJpg:n=>ot(o,{dpr:r,scale:a,...n},"jpeg"),toWebp:n=>ot(o,{dpr:r,scale:a,...n},"webp"),download:({format:n="png",filename:c="capture",backgroundColor:i}={})=>Pt(o,{dpr:r,scale:a,backgroundColor:i,format:n,filename:c})}};x.toRaw=async(t,e)=>(await x.capture(t,e)).toRaw();x.toImg=async(t,e)=>(await x.capture(t,e)).toImg();x.toCanvas=async(t,e)=>(await x.capture(t,e)).toCanvas();x.toBlob=async(t,e)=>(await x.capture(t,e)).toBlob(e);x.toPng=async(t,e)=>(await x.capture(t,e)).toPng(e);x.toJpg=async(t,e)=>(await x.capture(t,e)).toJpg(e);x.toWebp=async(t,e)=>(await x.capture(t,e)).toWebp(e);x.download=async(t,e={})=>{let{format:o="png",filename:r="capture",backgroundColor:a,...n}=e;return await(await x.capture(t,n)).download({format:o,filename:r,backgroundColor:a})};async function Lt(t=document,e={}){let{embedFonts:o=!0,reset:r=!1}=e;if(r){$.clear(),F.clear(),S.clear(),D.clear();return}await document.fonts.ready,rt();let a=[],n=[];t?.querySelectorAll&&(a=Array.from(t.querySelectorAll("img[src]")),n=Array.from(t.querySelectorAll("*")));let c=[];for(let i of a){let h=i.src;$.has(h)||c.push(N(h,{useProxy:e.useProxy}).then(l=>$.set(h,l)).catch(()=>{}))}for(let i of n){let h=U(i).backgroundImage;if(h&&h!=="none"){let l=j(h);for(let s of l)s.startsWith("url(")&&c.push(M(s,e).catch(()=>{}))}}o&&await K({preCached:!0}),await Promise.all(c)}export{Lt as preCache,x as snapdom};
15
+ `}if(a&&(S.set("fonts-embed-css",a),t)){let o=document.createElement("style");o.setAttribute("data-snapdom","embedFonts"),o.textContent=a,document.head.appendChild(o)}return a}async function nt(t,e,n,r,a,o=!1,c){if(!(t instanceof Element)||!(e instanceof Element))return;for(let s of["::before","::after","::first-letter"])try{let f=L(t,s);if(!f||typeof f[Symbol.iterator]!="function")continue;if(s==="::first-letter"){let y=getComputedStyle(t);if(!(f.color!==y.color||f.fontSize!==y.fontSize||f.fontWeight!==y.fontWeight))continue;let E=Array.from(e.childNodes).find(C=>C.nodeType===Node.TEXT_NODE&&C.textContent&&C.textContent.trim().length>0);if(!E)continue;let P=E.textContent,T=P.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],N=P.slice(T?.length||0);if(!T||/[\uD800-\uDFFF]/.test(T))continue;let k=document.createElement("span");k.textContent=T,k.dataset.snapdomPseudo="::first-letter";let I=J(f),q=V(I,"span",a);n.set(k,q);let z=document.createTextNode(N);e.replaceChild(z,E),e.insertBefore(k,z);continue}let d=f.getPropertyValue("content"),h=f.getPropertyValue("background-image"),u=f.getPropertyValue("background-color"),m=d!=="none",g=h&&h!=="none",p=u&&u!=="transparent"&&u!=="rgba(0, 0, 0, 0)";if(m||g||p){let y=f.getPropertyValue("font-family"),w=parseInt(f.getPropertyValue("font-size"))||32,E=parseInt(f.getPropertyValue("font-weight"))||!1,P=f.getPropertyValue("color")||"#000",b=document.createElement("span");b.dataset.snapdomPseudo=s;let T=J(f),N=V(T,"span",a);n.set(b,N);let k=A(y),I=ft(d);if(k&&I.length===1){let C=document.createElement("img");C.src=await mt(I,y,E,w,P),C.style=`width:${w}px;height:auto;object-fit:contain;`,b.appendChild(C)}else if(I.startsWith("url(")){let C=H(I);if(C&&C.trim()!=="")try{let $=document.createElement("img"),j=await U(Y(C,{useProxy:c}));$.src=j,$.style=`width:${w}px;height:auto;object-fit:contain;`,b.appendChild($)}catch($){console.error(`[snapdom] Error in pseudo ${s} for`,t,$)}}else!k&&I&&I!=="none"&&(b.textContent=I);if(g)try{let C=W(h),$=await Promise.all(C.map(j=>M(j)));b.style.backgroundImage=$.join(", ")}catch(C){console.warn(`[snapdom] Failed to inline background-image for ${s}`,C)}if(p&&(b.style.backgroundColor=u),!(b.childNodes.length>0||b.textContent&&b.textContent.trim()!==""||g||p))continue;s==="::before"?e.insertBefore(b,e.firstChild):e.appendChild(b)}}catch(f){console.warn(`[snapdom] Failed to capture ${s} for`,t,f)}let i=Array.from(t.children),l=Array.from(e.children).filter(s=>!s.dataset.snapdomPseudo);for(let s=0;s<Math.min(i.length,l.length);s++)await nt(i[s],l[s],n,r,a,o,c)}function gt(t){if(!t)return;let e=document.querySelectorAll("svg > defs");e.length&&t.querySelectorAll("svg").forEach(n=>{let r=n.querySelectorAll("use");if(!r.length)return;let a=new Set;if(r.forEach(c=>{let i=c.getAttribute("xlink:href")||c.getAttribute("href");i&&i.startsWith("#")&&a.add(i.slice(1))}),!a.size)return;let o=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let c of a)for(let i of e){let l=i.querySelector(`#${CSS.escape(c)}`);if(l){o.appendChild(l.cloneNode(!0));break}}o.childNodes.length&&n.insertBefore(o,n.firstChild)})}async function pt(t,e=!1,n=!1,r={}){let a=new Map,o=new WeakMap,c=new Map,i;try{i=_(t,a,o,c,e,r,t)}catch(s){throw console.warn("deepClone failed:",s),s}try{await nt(t,i,a,o,e,n,r.useProxy)}catch(s){console.warn("inlinePseudoElements failed:",s)}try{gt(i)}catch(s){console.warn("inlineExternalDef failed:",s)}let l="";if(e){let s=lt(a);l=Array.from(s.entries()).map(([f,d])=>`.${d}{${f}}`).join("");for(let[f,d]of a.entries()){if(f.tagName==="STYLE")continue;let h=s.get(d);h&&f.classList.add(h);let u=f.style?.backgroundImage;f.removeAttribute("style"),u&&u!=="none"&&(f.style.backgroundImage=u)}}else for(let[s,f]of a.entries())s.tagName!=="STYLE"&&s.setAttribute("style",f.replace(/;/g,"; "));for(let[s,f]of c.entries()){let d=f.scrollLeft,h=f.scrollTop;if((d||h)&&s instanceof HTMLElement){s.style.overflow="hidden",s.style.scrollbarWidth="none",s.style.msOverflowStyle="none";let m=document.createElement("div");for(m.style.transform=`translate(${-d}px, ${-h}px)`,m.style.willChange="transform",m.style.display="inline-block",m.style.width="100%";s.firstChild;)m.appendChild(s.firstChild);s.appendChild(m)}}if(t===c.get(i)){let s=o.get(t)||window.getComputedStyle(t);o.set(t,s);let f=dt(s.transform);i.style.margin="0",i.style.position="static",i.style.top="auto",i.style.left="auto",i.style.right="auto",i.style.bottom="auto",i.style.zIndex="auto",i.style.float="none",i.style.clear="none",i.style.transform=f||""}for(let[s,f]of c.entries())f.tagName==="PRE"&&(s.style.marginTop="0",s.style.marginBlockStart="0");return{clone:i,classCSS:l,styleCache:o}}async function yt(t,e={}){let n=Array.from(t.querySelectorAll("img")),r=async a=>{let o=a.src;try{let c=await U(o,{useProxy:e.useProxy});a.src=c,a.width||(a.width=a.naturalWidth||100),a.height||(a.height=a.naturalHeight||100)}catch{let c=document.createElement("div");c.style=`width: ${a.width||100}px; height: ${a.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${a.height||100}px; color: #666; font-size: 12px;`,c.innerText="img",a.replaceWith(c)}};for(let a=0;a<n.length;a+=4){let o=n.slice(a,a+4).map(r);await Promise.allSettled(o)}}async function wt(t,e,n,r={}){let a=[[t,e]],o=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source"];for(;a.length;){let[c,i]=a.shift(),l=n.get(c)||L(c);n.has(c)||n.set(c,l);for(let h of o){let u=l.getPropertyValue(h);if(!u||u==="none")continue;let m=W(u),g=await Promise.all(m.map(p=>M(p,r)));g.some(p=>p&&p!=="none"&&!/^url\(undefined/.test(p))&&i.style.setProperty(h,g.join(", "))}let s=l.getPropertyValue("background-color");s&&s!=="transparent"&&s!=="rgba(0, 0, 0, 0)"&&(i.style.backgroundColor=s);let f=Array.from(c.children),d=Array.from(i.children);for(let h=0;h<Math.min(f.length,d.length);h++)a.push([f[h],d[h]])}}async function xt(t,e={}){if(!t)throw new Error("Element cannot be null or undefined");let{compress:n=!0,embedFonts:r=!1,fast:a=!0,scale:o=1,useProxy:c=""}=e,i,l,s,f="",d="",h,u;if({clone:i,classCSS:l,styleCache:s}=await pt(t,n,r,e),await new Promise(g=>{O(async()=>{await yt(i,e),g()},{fast:a})}),await new Promise(g=>{O(async()=>{await wt(t,i,s,e),g()},{fast:a})}),r&&await new Promise(g=>{O(async()=>{f=await K(),g()},{fast:a})}),n){let g=it(i).sort(),p=g.join(",");D.has(p)?d=D.get(p):await new Promise(y=>{O(()=>{d=ct(g),D.set(p,d),y()},{fast:a})})}await new Promise(g=>{O(()=>{let p=t.getBoundingClientRect(),y=p.width,w=p.height,E=Number.isFinite(e.width),P=Number.isFinite(e.height),b=typeof o=="number"&&o!==1;if(!b){let $=p.width/p.height;E&&P?(y=e.width,w=e.height):E?(y=e.width,w=y/$):P&&(w=e.height,y=w*$)}if(y=Math.ceil(y),w=Math.ceil(w),i.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),i.style.transformOrigin="top left",!b&&(E||P)){let $=p.width,j=p.height,St=y/$,Et=w/j,$t=i.style.transform||"",vt=`scale(${St}, ${Et})`;i.style.transform=`${vt} ${$t}`.trim()}else b&&X()&&(i.style.scale=`${o}`);let T="http://www.w3.org/2000/svg",N=document.createElementNS(T,"foreignObject");N.setAttribute("width","100%"),N.setAttribute("height","100%");let k=document.createElement("style");k.textContent=d+f+"svg{overflow:visible;}"+l,N.appendChild(k),N.appendChild(i);let q=new XMLSerializer().serializeToString(N);u=`<svg xmlns="${T}" width="${y}" height="${w}" viewBox="0 0 ${y} ${w}">`+q+"</svg>",h=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`,g()},{fast:a})});let m=document.getElementById("snapdom-sandbox");return m&&m.style.position==="absolute"&&m.remove(),h}async function Nt(t,{dpr:e=1,scale:n=1}){let r=new Image;return r.src=t,await r.decode(),X?(r.width=r.width*n,r.height=r.height*n):(r.width=r.width/n,r.height=r.height/n),r}async function bt(t,{dpr:e=1,scale:n=1}={}){let r=new Image;r.src=t,await r.decode();let a=document.createElement("canvas"),o=r.width*n,c=r.height*n;a.width=Math.ceil(o*e),a.height=Math.ceil(c*e);let i=a.getContext("2d");return i.scale(e,e),i.drawImage(r,0,0,o,c),a.style.width=`${o}px`,a.style.height=`${c}px`,a}async function Ct(t,{type:e="svg",scale:n=1,backgroundColor:r="#fff",quality:a}={}){let o={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[e]||"image/png";if(e==="svg"){let i=decodeURIComponent(t.split(",")[1]);return new Blob([i],{type:"image/svg+xml"})}let c=await at(t,{dpr:1,scale:n},r);return new Promise(i=>{c.toBlob(l=>i(l),`${o}`,a)})}async function at(t,{dpr:e=1,scale:n=1},r){let a=await bt(t,{dpr:e,scale:n});if(!r)return a;let o=document.createElement("canvas");o.width=a.width,o.height=a.height;let c=o.getContext("2d");return c.fillStyle=r,c.fillRect(0,0,o.width,o.height),c.drawImage(a,0,0),o}async function ot(t,{dpr:e=1,scale:n=1,backgroundColor:r="#fff",quality:a},o="png"){let c=await at(t,{dpr:e,scale:n},r),i=new Image;return i.src=c.toDataURL(`image/${o}`,a),await i.decode(),i.style.width=`${c.width/e}px`,i.style.height=`${c.height/e}px`,i}async function Pt(t,{dpr:e=1,scale:n=1,backgroundColor:r="#fff",format:a="png",filename:o="capture"}={}){if(a==="svg"){let h=await Ct(t),u=URL.createObjectURL(h),m=document.createElement("a");m.href=u,m.download=`${o}.svg`,m.click(),URL.revokeObjectURL(u);return}let c=["jpg","jpeg","webp"].includes(a)?"#fff":void 0,l=await at(t,{dpr:e,scale:n},r??c),s={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[a]||"image/png",f=l.toDataURL(s),d=document.createElement("a");d.href=f,d.download=`${o}.${a}`,d.click()}async function x(t,e={}){if(e={scale:1,...e},!t)throw new Error("Element cannot be null or undefined");return e.iconFonts&&ht(e.iconFonts),await x.capture(t,e)}x.capture=async(t,e={})=>{let n=await xt(t,e),r=window.devicePixelRatio||1,a=e.scale||1;return{url:n,options:e,toRaw:()=>n,toImg:()=>Nt(n,{dpr:r,scale:a}),toCanvas:()=>bt(n,{dpr:r,scale:a}),toBlob:o=>Ct(n,{dpr:r,scale:a,...o}),toPng:o=>ot(n,{dpr:r,scale:a,...o},"png"),toJpg:o=>ot(n,{dpr:r,scale:a,...o},"jpeg"),toWebp:o=>ot(n,{dpr:r,scale:a,...o},"webp"),download:({format:o="png",filename:c="capture",backgroundColor:i}={})=>Pt(n,{dpr:r,scale:a,backgroundColor:i,format:o,filename:c})}};x.toRaw=async(t,e)=>(await x.capture(t,e)).toRaw();x.toImg=async(t,e)=>(await x.capture(t,e)).toImg();x.toCanvas=async(t,e)=>(await x.capture(t,e)).toCanvas();x.toBlob=async(t,e)=>(await x.capture(t,e)).toBlob(e);x.toPng=async(t,e)=>(await x.capture(t,e)).toPng(e);x.toJpg=async(t,e)=>(await x.capture(t,e)).toJpg(e);x.toWebp=async(t,e)=>(await x.capture(t,e)).toWebp(e);x.download=async(t,e={})=>{let{format:n="png",filename:r="capture",backgroundColor:a,...o}=e;return await(await x.capture(t,o)).download({format:n,filename:r,backgroundColor:a})};async function Lt(t=document,e={}){let{embedFonts:n=!0,reset:r=!1}=e;if(r){v.clear(),F.clear(),S.clear(),D.clear();return}await document.fonts.ready,rt();let a=[],o=[];t?.querySelectorAll&&(a=Array.from(t.querySelectorAll("img[src]")),o=Array.from(t.querySelectorAll("*")));let c=[];for(let i of a){let l=i.src;v.has(l)||c.push(U(l,{useProxy:e.useProxy}).then(s=>v.set(l,s)).catch(()=>{}))}for(let i of o){let l=L(i).backgroundImage;if(l&&l!=="none"){let s=W(l);for(let f of s)f.startsWith("url(")&&c.push(M(f,e).catch(()=>{}))}}n&&await K({preCached:!0}),await Promise.all(c)}export{Lt as preCache,x as snapdom};
package/dist/snapdom.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  /*
3
3
  * snapdom
4
- * v.1.9.3
4
+ * v.1.9.5
5
5
  * Author Juan Martin Muda
6
6
  * License MIT
7
7
  **/
@@ -155,11 +155,10 @@ function generateCSSClasses(styleMap) {
155
155
 
156
156
  // src/utils/helpers.js
157
157
  async function inlineSingleBackgroundEntry(entry, options = {}) {
158
- const isUrl = entry.startsWith("url(");
158
+ const match = entry.match(/url\(["']?(.*?)["']?\)/);
159
+ const rawUrl = match?.[1];
159
160
  const isGradient = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(entry);
160
- if (isUrl) {
161
- const rawUrl = extractURL(entry);
162
- if (!rawUrl) return entry;
161
+ if (rawUrl) {
163
162
  const encodedUrl = safeEncodeURI(rawUrl);
164
163
  if (bgCache.has(encodedUrl)) {
165
164
  return options.skipInline ? void 0 : `url(${bgCache.get(encodedUrl)})`;
@@ -424,12 +423,11 @@ function inlineAllStyles(source, clone, styleMap, cache, compress) {
424
423
  }
425
424
 
426
425
  // src/core/clone.js
426
+ function isSlotElement(node) {
427
+ return node.nodeType === Node.ELEMENT_NODE && node.tagName === "SLOT";
428
+ }
427
429
  function deepClone(node, styleMap, styleCache, nodeMap, compress, options = {}, originalRoot) {
428
430
  if (node.nodeType === Node.TEXT_NODE) {
429
- if (node.parentElement?.shadowRoot) {
430
- const tag = node.parentElement.tagName.toLowerCase();
431
- if (customElements.get(tag)) return null;
432
- }
433
431
  return node.cloneNode(true);
434
432
  }
435
433
  if (node.nodeType !== Node.ELEMENT_NODE) return node.cloneNode(true);
@@ -439,10 +437,10 @@ function deepClone(node, styleMap, styleCache, nodeMap, compress, options = {},
439
437
  spacer.style.cssText = `display: inline-block; width: ${rect.width}px; height: ${rect.height}px; visibility: hidden;`;
440
438
  return spacer;
441
439
  }
442
- if (options.exclude && Array.isArray(options.exclude) && options.exclude.length > 0) {
440
+ if (options.exclude && Array.isArray(options.exclude)) {
443
441
  for (const selector of options.exclude) {
444
442
  try {
445
- if (node.matches && node.matches(selector)) {
443
+ if (node.matches?.(selector)) {
446
444
  const spacer = document.createElement("div");
447
445
  const rect = node.getBoundingClientRect();
448
446
  spacer.style.cssText = `display: inline-block; width: ${rect.width}px; height: ${rect.height}px; visibility: hidden;`;
@@ -502,8 +500,10 @@ function deepClone(node, styleMap, styleCache, nodeMap, compress, options = {},
502
500
  if (node.checked) clone.setAttribute("checked", "");
503
501
  }
504
502
  } else if (node instanceof HTMLTextAreaElement) {
505
- clone.value = node.value;
503
+ const rect = node.getBoundingClientRect();
506
504
  clone.textContent = node.value;
505
+ clone.style.width = `${rect.width}px`;
506
+ clone.style.height = `${rect.height}px`;
507
507
  } else if (node instanceof HTMLSelectElement) {
508
508
  clone.value = node.value;
509
509
  Array.from(clone.options).forEach((opt) => {
@@ -515,18 +515,30 @@ function deepClone(node, styleMap, styleCache, nodeMap, compress, options = {},
515
515
  });
516
516
  }
517
517
  inlineAllStyles(node, clone, styleMap, styleCache, compress);
518
- const frag = document.createDocumentFragment();
519
- const rootElement = originalRoot || node;
520
- node.childNodes.forEach((child) => {
521
- const clonedChild = deepClone(child, styleMap, styleCache, nodeMap, compress, options, rootElement);
522
- if (clonedChild) frag.appendChild(clonedChild);
523
- });
524
- clone.appendChild(frag);
525
- if (node.shadowRoot) {
526
- const shadowContent = Array.from(node.shadowRoot.children).filter((el) => el.tagName !== "STYLE").map((el) => deepClone(el, styleMap, styleCache, nodeMap, compress, options, rootElement)).filter(Boolean);
527
- const shadowFrag = document.createDocumentFragment();
528
- shadowContent.forEach((child) => shadowFrag.appendChild(child));
529
- clone.appendChild(shadowFrag);
518
+ if (isSlotElement(node)) {
519
+ const assigned = node.assignedNodes?.({ flatten: true }) || [];
520
+ const nodesToClone = assigned.length > 0 ? assigned : Array.from(node.childNodes);
521
+ const fragment = document.createDocumentFragment();
522
+ for (const child of nodesToClone) {
523
+ const clonedChild = deepClone(child, styleMap, styleCache, nodeMap, compress, options, originalRoot || node);
524
+ if (clonedChild) fragment.appendChild(clonedChild);
525
+ }
526
+ return fragment;
527
+ } else if (node instanceof HTMLTextAreaElement) {
528
+ } else {
529
+ const baseChildren = node.shadowRoot ? node.shadowRoot.childNodes : node.childNodes;
530
+ for (const child of baseChildren) {
531
+ const clonedChild = deepClone(child, styleMap, styleCache, nodeMap, compress, options, originalRoot || node);
532
+ if (clonedChild) clone.appendChild(clonedChild);
533
+ }
534
+ if (node.shadowRoot && node.childNodes.length > 0 && !node.shadowRoot.querySelector("slot")) {
535
+ const lightDomContent = document.createDocumentFragment();
536
+ for (const child of node.childNodes) {
537
+ const clonedChild = deepClone(child, styleMap, styleCache, nodeMap, compress, options, originalRoot || node);
538
+ if (clonedChild) lightDomContent.appendChild(clonedChild);
539
+ }
540
+ clone.appendChild(lightDomContent);
541
+ }
530
542
  }
531
543
  return clone;
532
544
  }
@@ -1024,27 +1036,32 @@ async function inlineImages(clone, options = {}) {
1024
1036
  // src/modules/background.js
1025
1037
  async function inlineBackgroundImages(source, clone, styleCache, options = {}) {
1026
1038
  const queue = [[source, clone]];
1039
+ const imageProps = [
1040
+ "background-image",
1041
+ "mask",
1042
+ "mask-image",
1043
+ "-webkit-mask-image",
1044
+ "mask-source",
1045
+ "mask-box-image-source",
1046
+ "mask-border-source",
1047
+ "-webkit-mask-box-image-source"
1048
+ ];
1027
1049
  while (queue.length) {
1028
1050
  const [srcNode, cloneNode] = queue.shift();
1029
1051
  const style = styleCache.get(srcNode) || getStyle(srcNode);
1030
1052
  if (!styleCache.has(srcNode)) styleCache.set(srcNode, style);
1031
- const bg = style.getPropertyValue("background-image");
1032
- const bgColor = style.getPropertyValue("background-color");
1033
- if (!bg || bg === "none") {
1034
- const sChildren2 = Array.from(srcNode.children);
1035
- const cChildren2 = Array.from(cloneNode.children);
1036
- for (let i = 0; i < Math.min(sChildren2.length, cChildren2.length); i++) {
1037
- queue.push([sChildren2[i], cChildren2[i]]);
1053
+ for (const prop of imageProps) {
1054
+ const val = style.getPropertyValue(prop);
1055
+ if (!val || val === "none") continue;
1056
+ const splits = splitBackgroundImage(val);
1057
+ const inlined = await Promise.all(
1058
+ splits.map((entry) => inlineSingleBackgroundEntry(entry, options))
1059
+ );
1060
+ if (inlined.some((p) => p && p !== "none" && !/^url\(undefined/.test(p))) {
1061
+ cloneNode.style.setProperty(prop, inlined.join(", "));
1038
1062
  }
1039
- continue;
1040
- }
1041
- const bgSplits = splitBackgroundImage(bg);
1042
- const newBgParts = await Promise.all(
1043
- bgSplits.map((entry) => inlineSingleBackgroundEntry(entry, options))
1044
- );
1045
- if (newBgParts.some((p) => p && p !== "none" && !/^url\(undefined\)/.test(p))) {
1046
- cloneNode.style.backgroundImage = newBgParts.join(", ");
1047
1063
  }
1064
+ const bgColor = style.getPropertyValue("background-color");
1048
1065
  if (bgColor && bgColor !== "transparent" && bgColor !== "rgba(0, 0, 0, 0)") {
1049
1066
  cloneNode.style.backgroundColor = bgColor;
1050
1067
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zumer/snapdom",
3
- "version": "1.9.3",
3
+ "version": "1.9.5",
4
4
  "description": "snapDOM captures HTML elements to images with exceptional speed and accuracy.",
5
5
  "main": "dist/snapdom.js",
6
6
  "module": "dist/snapdom.mjs",
@@ -8,6 +8,7 @@ declare module "@zumer/snapdom" {
8
8
  height?: number;
9
9
  backgroundColor?: string;
10
10
  format?: "png" | "jpeg" | "jpg" | "webp" | "svg";
11
+ type?: "png" | "jpeg" | "jpg" | "webp" | "svg";
11
12
  filename?: string;
12
13
  dpr?: number;
13
14
  quality?: number;