@zumer/snapdom 1.9.6 → 1.9.7
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 +5 -3
- package/dist/snapdom.js +88 -70
- package/dist/snapdom.min.js +3 -3
- package/dist/snapdom.min.mjs +3 -3
- package/dist/snapdom.mjs +88 -70
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,8 +116,8 @@ Returns an object with reusable export methods:
|
|
|
116
116
|
toRaw(): string;
|
|
117
117
|
toImg(): Promise<HTMLImageElement>;
|
|
118
118
|
toCanvas(): Promise<HTMLCanvasElement>;
|
|
119
|
-
toBlob(): Promise<Blob>;
|
|
120
|
-
toPng(): Promise<HTMLImageElement>;
|
|
119
|
+
toBlob(options?): Promise<Blob>;
|
|
120
|
+
toPng(options?): Promise<HTMLImageElement>;
|
|
121
121
|
toJpg(options?): Promise<HTMLImageElement>;
|
|
122
122
|
toWebp(options?): Promise<HTMLImageElement>;
|
|
123
123
|
download(options?): Promise<void>;
|
|
@@ -236,7 +236,6 @@ import { snapdom, preCache } from './snapdom.mjs';
|
|
|
236
236
|
**Options for `preCache()`:**
|
|
237
237
|
|
|
238
238
|
* `embedFonts` *(boolean, default: true)* — Inlines non-icon fonts during preload.
|
|
239
|
-
* `reset` *(boolean, default: false)* — Clears all existing internal caches.
|
|
240
239
|
* `useProxy` *(string)* — Proxy for handling CORS images as fallback.
|
|
241
240
|
|
|
242
241
|
|
|
@@ -359,6 +358,9 @@ For detailed contribution guidelines, please see [CONTRIBUTING](https://github.c
|
|
|
359
358
|
<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>
|
|
360
359
|
<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>
|
|
361
360
|
<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>
|
|
361
|
+
<a href="https://github.com/miusuncle" title="miusuncle"><img src="https://avatars.githubusercontent.com/u/7549857?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="miusuncle"/></a>
|
|
362
|
+
<a href="https://github.com/rbbydotdev" title="rbbydotdev"><img src="https://avatars.githubusercontent.com/u/101137670?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="rbbydotdev"/></a>
|
|
363
|
+
<a href="https://github.com/kohaiy" title="kohaiy"><img src="https://avatars.githubusercontent.com/u/15622127?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="kohaiy"/></a>
|
|
362
364
|
</p>
|
|
363
365
|
<!-- CONTRIBUTORS:END -->
|
|
364
366
|
|
package/dist/snapdom.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
/*
|
|
3
3
|
* snapdom
|
|
4
|
-
* v.1.9.
|
|
4
|
+
* v.1.9.7
|
|
5
5
|
* Author Juan Martin Muda
|
|
6
6
|
* License MIT
|
|
7
7
|
**/
|
|
@@ -574,7 +574,6 @@
|
|
|
574
574
|
if (node.checked) clone.setAttribute("checked", "");
|
|
575
575
|
if (node.indeterminate) clone.indeterminate = node.indeterminate;
|
|
576
576
|
}
|
|
577
|
-
return clone;
|
|
578
577
|
}
|
|
579
578
|
if (node instanceof HTMLSelectElement) {
|
|
580
579
|
pendingSelectValue = node.value;
|
|
@@ -798,8 +797,8 @@
|
|
|
798
797
|
if (!src || isIconFont(family)) continue;
|
|
799
798
|
const urlRegex = /url\((["']?)([^"')]+)\1\)/g;
|
|
800
799
|
const localRegex = /local\((["']?)[^)]+?\1\)/g;
|
|
801
|
-
const hasURL =
|
|
802
|
-
const hasLocal =
|
|
800
|
+
const hasURL = !!src.match(urlRegex);
|
|
801
|
+
const hasLocal = !!src.match(localRegex);
|
|
803
802
|
if (!hasURL && hasLocal) {
|
|
804
803
|
finalCSS += `@font-face{font-family:${family};src:${src};font-style:${rule.style.getPropertyValue("font-style") || "normal"};font-weight:${rule.style.getPropertyValue("font-weight") || "normal"};}`;
|
|
805
804
|
continue;
|
|
@@ -908,9 +907,9 @@
|
|
|
908
907
|
const span = document.createElement("span");
|
|
909
908
|
span.textContent = first;
|
|
910
909
|
span.dataset.snapdomPseudo = "::first-letter";
|
|
911
|
-
const
|
|
912
|
-
const
|
|
913
|
-
cache.preStyleMap.set(span,
|
|
910
|
+
const snapshot2 = snapshotComputedStyle(style);
|
|
911
|
+
const key2 = getStyleKey(snapshot2, "span", compress);
|
|
912
|
+
cache.preStyleMap.set(span, key2);
|
|
914
913
|
const restNode = document.createTextNode(rest);
|
|
915
914
|
clone.replaceChild(restNode, textNode);
|
|
916
915
|
clone.insertBefore(span, restNode);
|
|
@@ -919,64 +918,73 @@
|
|
|
919
918
|
const content = style.getPropertyValue("content");
|
|
920
919
|
const bg = style.getPropertyValue("background-image");
|
|
921
920
|
const bgColor = style.getPropertyValue("background-color");
|
|
921
|
+
const fontFamily = style.getPropertyValue("font-family");
|
|
922
|
+
const fontSize = parseInt(style.getPropertyValue("font-size")) || 32;
|
|
923
|
+
const fontWeight = parseInt(style.getPropertyValue("font-weight")) || false;
|
|
924
|
+
const color = style.getPropertyValue("color") || "#000";
|
|
925
|
+
const display = style.getPropertyValue("display");
|
|
926
|
+
const width = parseFloat(style.getPropertyValue("width"));
|
|
927
|
+
const height = parseFloat(style.getPropertyValue("height"));
|
|
928
|
+
const borderStyle = style.getPropertyValue("border-style");
|
|
929
|
+
const transform = style.getPropertyValue("transform");
|
|
930
|
+
const isIconFont2 = isIconFont(fontFamily);
|
|
931
|
+
let cleanContent;
|
|
932
|
+
if (/counter\s*\(|counters\s*\(/.test(content)) {
|
|
933
|
+
cleanContent = "- ";
|
|
934
|
+
} else {
|
|
935
|
+
cleanContent = parseContent(content);
|
|
936
|
+
}
|
|
922
937
|
const hasContent = content !== "none";
|
|
938
|
+
const hasExplicitContent = hasContent && cleanContent !== "";
|
|
923
939
|
const hasBg = bg && bg !== "none";
|
|
924
940
|
const hasBgColor = bgColor && bgColor !== "transparent" && bgColor !== "rgba(0, 0, 0, 0)";
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
if (
|
|
943
|
-
const imgEl = document.createElement("img");
|
|
944
|
-
imgEl.src = yield iconToImage(cleanContent, fontFamily, fontWeight, fontSize, color);
|
|
945
|
-
imgEl.style = `width:${fontSize}px;height:auto;object-fit:contain;`;
|
|
946
|
-
pseudoEl.appendChild(imgEl);
|
|
947
|
-
} else if (cleanContent.startsWith("url(")) {
|
|
948
|
-
const rawUrl = extractURL(cleanContent);
|
|
949
|
-
if (rawUrl && rawUrl.trim() !== "") {
|
|
950
|
-
try {
|
|
951
|
-
const imgEl = document.createElement("img");
|
|
952
|
-
const dataUrl = yield fetchImage(safeEncodeURI(rawUrl, { useProxy }));
|
|
953
|
-
imgEl.src = dataUrl;
|
|
954
|
-
imgEl.style = `width:${fontSize}px;height:auto;object-fit:contain;`;
|
|
955
|
-
pseudoEl.appendChild(imgEl);
|
|
956
|
-
} catch (e) {
|
|
957
|
-
console.error(`[snapdom] Error in pseudo ${pseudo} for`, source, e);
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
} else if (!isIconFont2 && cleanContent && cleanContent !== "none") {
|
|
961
|
-
pseudoEl.textContent = cleanContent;
|
|
962
|
-
}
|
|
963
|
-
if (hasBg) {
|
|
941
|
+
const hasBox = display !== "inline" && (width > 0 || height > 0);
|
|
942
|
+
const hasBorder = borderStyle && borderStyle !== "none";
|
|
943
|
+
const hasTransform = transform && transform !== "none";
|
|
944
|
+
const shouldRender = hasExplicitContent || hasBg || hasBgColor || hasBox || hasBorder || hasTransform;
|
|
945
|
+
if (!shouldRender) continue;
|
|
946
|
+
const pseudoEl = document.createElement("span");
|
|
947
|
+
pseudoEl.dataset.snapdomPseudo = pseudo;
|
|
948
|
+
const snapshot = snapshotComputedStyle(style);
|
|
949
|
+
const key = getStyleKey(snapshot, "span", compress);
|
|
950
|
+
cache.preStyleMap.set(pseudoEl, key);
|
|
951
|
+
if (isIconFont2 && cleanContent.length === 1) {
|
|
952
|
+
const imgEl = document.createElement("img");
|
|
953
|
+
imgEl.src = yield iconToImage(cleanContent, fontFamily, fontWeight, fontSize, color);
|
|
954
|
+
imgEl.style = `width:${fontSize}px;height:auto;object-fit:contain;`;
|
|
955
|
+
pseudoEl.appendChild(imgEl);
|
|
956
|
+
} else if (cleanContent.startsWith("url(")) {
|
|
957
|
+
const rawUrl = extractURL(cleanContent);
|
|
958
|
+
if (rawUrl && rawUrl.trim() !== "") {
|
|
964
959
|
try {
|
|
965
|
-
const
|
|
966
|
-
const
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
pseudoEl.
|
|
960
|
+
const imgEl = document.createElement("img");
|
|
961
|
+
const dataUrl = yield fetchImage(safeEncodeURI(rawUrl, { useProxy }));
|
|
962
|
+
imgEl.src = dataUrl;
|
|
963
|
+
imgEl.style = `width:${fontSize}px;height:auto;object-fit:contain;`;
|
|
964
|
+
pseudoEl.appendChild(imgEl);
|
|
970
965
|
} catch (e) {
|
|
971
|
-
console.
|
|
966
|
+
console.error(`[snapdom] Error in pseudo ${pseudo} for`, source, e);
|
|
972
967
|
}
|
|
973
968
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
969
|
+
} else if (!isIconFont2 && hasExplicitContent) {
|
|
970
|
+
pseudoEl.textContent = cleanContent;
|
|
971
|
+
}
|
|
972
|
+
if (hasBg) {
|
|
973
|
+
try {
|
|
974
|
+
const bgSplits = splitBackgroundImage(bg);
|
|
975
|
+
const newBgParts = yield Promise.all(
|
|
976
|
+
bgSplits.map((entry) => inlineSingleBackgroundEntry(entry))
|
|
977
|
+
);
|
|
978
|
+
pseudoEl.style.backgroundImage = newBgParts.join(", ");
|
|
979
|
+
} catch (e) {
|
|
980
|
+
console.warn(`[snapdom] Failed to inline background-image for ${pseudo}`, e);
|
|
981
|
+
}
|
|
979
982
|
}
|
|
983
|
+
if (hasBgColor) pseudoEl.style.backgroundColor = bgColor;
|
|
984
|
+
const hasContent2 = pseudoEl.childNodes.length > 0 || pseudoEl.textContent && pseudoEl.textContent.trim() !== "";
|
|
985
|
+
const hasVisibleBox = hasContent2 || hasBg || hasBgColor || hasBox || hasBorder || hasTransform;
|
|
986
|
+
if (!hasVisibleBox) continue;
|
|
987
|
+
pseudo === "::before" ? clone.insertBefore(pseudoEl, clone.firstChild) : clone.appendChild(pseudoEl);
|
|
980
988
|
} catch (e) {
|
|
981
989
|
console.warn(`[snapdom] Failed to capture ${pseudo} for`, source, e);
|
|
982
990
|
}
|
|
@@ -1255,8 +1263,6 @@
|
|
|
1255
1263
|
const existingTransform = clone.style.transform || "";
|
|
1256
1264
|
const scaleTransform = `scale(${scaleX}, ${scaleY})`;
|
|
1257
1265
|
clone.style.transform = `${scaleTransform} ${existingTransform}`.trim();
|
|
1258
|
-
} else if (hasScale && isSafari()) {
|
|
1259
|
-
clone.style.scale = `${scale}`;
|
|
1260
1266
|
}
|
|
1261
1267
|
const svgNS = "http://www.w3.org/2000/svg";
|
|
1262
1268
|
const fo = document.createElementNS(svgNS, "foreignObject");
|
|
@@ -1287,13 +1293,8 @@
|
|
|
1287
1293
|
const img = new Image();
|
|
1288
1294
|
img.src = url;
|
|
1289
1295
|
yield img.decode();
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
img.height = img.height * scale;
|
|
1293
|
-
} else {
|
|
1294
|
-
img.width = img.width / scale;
|
|
1295
|
-
img.height = img.height / scale;
|
|
1296
|
-
}
|
|
1296
|
+
img.width = img.width * scale;
|
|
1297
|
+
img.height = img.height * scale;
|
|
1297
1298
|
return img;
|
|
1298
1299
|
});
|
|
1299
1300
|
}
|
|
@@ -1301,17 +1302,34 @@
|
|
|
1301
1302
|
return __async(this, arguments, function* (url, { dpr = 1, scale = 1 } = {}) {
|
|
1302
1303
|
const img = new Image();
|
|
1303
1304
|
img.src = url;
|
|
1305
|
+
img.crossOrigin = "anonymous";
|
|
1306
|
+
img.loading = "eager";
|
|
1307
|
+
img.decoding = "sync";
|
|
1308
|
+
const isSafariBrowser = isSafari();
|
|
1309
|
+
let appended = false;
|
|
1310
|
+
if (isSafariBrowser) {
|
|
1311
|
+
document.body.appendChild(img);
|
|
1312
|
+
appended = true;
|
|
1313
|
+
}
|
|
1304
1314
|
yield img.decode();
|
|
1305
|
-
|
|
1315
|
+
if (isSafariBrowser) {
|
|
1316
|
+
yield new Promise((resolve) => setTimeout(resolve, 100));
|
|
1317
|
+
}
|
|
1318
|
+
if (img.width === 0 || img.height === 0) {
|
|
1319
|
+
if (appended) img.remove();
|
|
1320
|
+
throw new Error("Image failed to load or has no dimensions");
|
|
1321
|
+
}
|
|
1306
1322
|
const width = img.width * scale;
|
|
1307
1323
|
const height = img.height * scale;
|
|
1324
|
+
const canvas = document.createElement("canvas");
|
|
1308
1325
|
canvas.width = Math.ceil(width * dpr);
|
|
1309
1326
|
canvas.height = Math.ceil(height * dpr);
|
|
1327
|
+
canvas.style.width = `${width}px`;
|
|
1328
|
+
canvas.style.height = `${height}px`;
|
|
1310
1329
|
const ctx = canvas.getContext("2d");
|
|
1311
1330
|
ctx.scale(dpr, dpr);
|
|
1312
1331
|
ctx.drawImage(img, 0, 0, width, height);
|
|
1313
|
-
|
|
1314
|
-
canvas.style.height = `${height}px`;
|
|
1332
|
+
if (appended) img.remove();
|
|
1315
1333
|
return canvas;
|
|
1316
1334
|
});
|
|
1317
1335
|
}
|
|
@@ -1366,7 +1384,7 @@
|
|
|
1366
1384
|
});
|
|
1367
1385
|
}
|
|
1368
1386
|
function download(_0) {
|
|
1369
|
-
return __async(this, arguments, function* (url, { dpr = 1, scale = 1, backgroundColor
|
|
1387
|
+
return __async(this, arguments, function* (url, { dpr = 1, scale = 1, backgroundColor, format = "png", filename = "snapDOM" } = {}) {
|
|
1370
1388
|
if (format === "svg") {
|
|
1371
1389
|
const blob = yield toBlob(url);
|
|
1372
1390
|
const objectURL = URL.createObjectURL(blob);
|
package/dist/snapdom.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(()=>{var
|
|
2
|
-
`;return a}function ie(){let e=new Set(f.preStyleMap.values()),t=new Map,a=1;for(let i of e)t.set(i,`c${a++}`);return t}function P(a){return h(this,arguments,function*(e,t={}){let i=D(e),c=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(i){let n=z(i);if(f.background.has(n))return t.skipInline?void 0:`url(${f.background.get(n)})`;{let s=yield T(n,{useProxy:t.useProxy});return f.background.set(n,s),t.skipInline?void 0:`url("${s}")`}}return e})}function L(e,{fast:t=!1}={}){if(t)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function A(e,t=null){if(!(e instanceof Element))return window.getComputedStyle(e,t);let a=f.computedStyle.get(e);if(a||(a=new Map,f.computedStyle.set(e,a)),!a.has(t)){let i=window.getComputedStyle(e,t);a.set(t,i)}return a.get(t)}function ce(e){let t=e.replace(/^['"]|['"]$/g,"");if(t.startsWith("\\"))try{return String.fromCharCode(parseInt(t.replace("\\",""),16))}catch(a){return t}return t}function D(e){let t=e.match(/url\((['"]?)(.*?)(\1)\)/);if(!t)return null;let a=t[2].trim();return a.startsWith("#")?null:a}function T(e,{timeout:t=3e3,useProxy:a=""}={}){function i(o){try{return new URL(o,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch(r){return"anonymous"}}function c(o){return h(this,null,function*(){let r=d=>fetch(d,{mode:"cors",credentials:i(d)==="use-credentials"?"include":"omit"}).then(u=>u.blob()).then(u=>new Promise((m,p)=>{let y=new FileReader;y.onloadend=()=>{let w=y.result;if(typeof w!="string"||!w.startsWith("data:image/")){p(new Error("Invalid image data URL"));return}m(w)},y.onerror=()=>p(new Error("FileReader error")),y.readAsDataURL(u)}));try{return yield r(o)}catch(d){if(a&&typeof a=="string"){let u=a.replace(/\/$/,"")+z(o);try{return yield r(u)}catch(m){throw new Error("[SnapDOM - fetchImage] CORS restrictions prevented image capture (even via proxy)")}}else throw new Error("[SnapDOM - fetchImage] Fetch fallback failed and no proxy provided")}})}let n=i(e);return f.image.has(e)?Promise.resolve(f.image.get(e)):e.startsWith("data:image/")?(f.image.set(e,e),Promise.resolve(e)):/\.svg(\?.*)?$/i.test(e)?h(null,null,function*(){try{let r=yield(yield fetch(e,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),d=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r)}`;return f.image.set(e,d),d}catch(o){return c(e)}}):new Promise((o,r)=>{let d=setTimeout(()=>{r(new Error("[SnapDOM - fetchImage] Image load timed out"))},t),u=new Image;u.crossOrigin=n,u.onload=()=>h(null,null,function*(){clearTimeout(d);try{yield u.decode();let m=document.createElement("canvas");m.width=u.width,m.height=u.height,m.getContext("2d").drawImage(u,0,0,m.width,m.height);let y=m.toDataURL("image/png");f.image.set(e,y),o(y)}catch(m){try{let p=yield c(e);f.image.set(e,p),o(p)}catch(p){r(p)}}}),u.onerror=()=>h(null,null,function*(){clearTimeout(d),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let m=yield c(e);f.image.set(e,m),o(m)}catch(m){r(m)}}),u.src=e})}function Y(e){let t={};for(let a of e)t[a]=e.getPropertyValue(a);return t}function q(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function le(e){if(!e||e==="none")return"";let t=e.replace(/translate[XY]?\([^)]*\)/g,"");return t=t.replace(/matrix\(([^)]+)\)/g,(a,i)=>{let c=i.split(",").map(n=>n.trim());return c.length!==6?`matrix(${i})`:(c[4]="0",c[5]="0",`matrix(${c.join(", ")})`)}),t=t.replace(/matrix3d\(([^)]+)\)/g,(a,i)=>{let c=i.split(",").map(n=>n.trim());return c.length!==16?`matrix3d(${i})`:(c[12]="0",c[13]="0",`matrix3d(${c.join(", ")})`)}),t.trim().replace(/\s{2,}/g," ")}function z(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch(t){return e}}function U(e){let t=[],a=0,i=0;for(let c=0;c<e.length;c++){let n=e[c];n==="("&&a++,n===")"&&a--,n===","&&a===0&&(t.push(e.slice(i,c).trim()),i=c+1)}return t.push(e.slice(i).trim()),t}function Re(e){let t={};for(let a=0;a<e.length;a++){let i=e[a],c=e.getPropertyValue(i);(i==="background-image"||i==="content")&&c.includes("url(")&&!c.includes("data:")&&(c="none"),t[i]=c}return t}function H(e,t,a){var o;if(e.tagName==="STYLE")return;f.preStyle.has(e)||f.preStyle.set(e,A(e));let i=f.preStyle.get(e);if(!f.snapshot.has(e)){let r=Re(i);f.snapshot.set(e,r)}let c=f.snapshot.get(e),n=Object.entries(c).sort(([r],[d])=>r.localeCompare(d)).map(([r,d])=>`${r}:${d}`).join(";");if(f.snapshotKey.has(n)){f.preStyleMap.set(t,f.snapshotKey.get(n));return}let s=((o=e.tagName)==null?void 0:o.toLowerCase())||"div",l=B(c,s,a);f.snapshotKey.set(n,l),f.preStyleMap.set(t,l)}function j(e,t,a={},i){var l,o;if(!e)throw new Error("Invalid node");let c=new Set,n=null;if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let r=document.createElement("div"),d=e.getBoundingClientRect();return r.style.cssText=`display:inline-block;width:${d.width}px;height:${d.height}px;visibility:hidden;`,r}if(a.exclude&&Array.isArray(a.exclude))for(let r of a.exclude)try{if((l=e.matches)!=null&&l.call(e,r)){let d=document.createElement("div"),u=e.getBoundingClientRect();return d.style.cssText=`display:inline-block;width:${u.width}px;height:${u.height}px;visibility:hidden;`,d}}catch(d){console.warn(`Invalid selector in exclude option: ${r}`,d)}if(typeof a.filter=="function")try{if(!a.filter(e,i||e)){let r=document.createElement("div"),d=e.getBoundingClientRect();return r.style.cssText=`display:inline-block;width:${d.width}px;height:${d.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.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);f.preNodeMap.set(r,e),H(e,r,t);let d=document.createElement("div");return d.textContent=e.getAttribute("data-placeholder-text")||"",d.style.cssText="color:#666;font-size:12px;text-align:center;line-height:1.4;padding:0.5em;box-sizing:border-box;",r.appendChild(d),r}if(e.tagName==="CANVAS"){let r=e.toDataURL(),d=document.createElement("img");return d.src=r,d.width=e.width,d.height=e.height,f.preNodeMap.set(d,e),H(e,d,t),d}let s;try{s=e.cloneNode(!1),f.preNodeMap.set(s,e)}catch(r){throw console.error("[Snapdom] Failed to clone node:",e,r),r}if(e instanceof HTMLTextAreaElement){s.textContent=e.value,s.value=e.value;let r=e.getBoundingClientRect();return s.style.width=`${r.width}px`,s.style.height=`${r.height}px`,s}if(e instanceof HTMLInputElement)return s.value=e.value,s.setAttribute("value",e.value),e.checked!==void 0&&(s.checked=e.checked,e.checked&&s.setAttribute("checked",""),e.indeterminate&&(s.indeterminate=e.indeterminate)),s;if(e instanceof HTMLSelectElement&&(n=e.value),H(e,s,t),e.shadowRoot)if(Array.from(e.shadowRoot.querySelectorAll("slot")).length>0){for(let d of e.shadowRoot.childNodes)if(d.nodeType===Node.ELEMENT_NODE&&d.tagName==="STYLE"){let u=d.textContent||"";u.trim()&&t&&(f.preStyle||(f.preStyle=new WeakMap),f.preStyle.set(d,u))}}else{let d=document.createDocumentFragment();for(let u of e.shadowRoot.childNodes){if(u.nodeType===Node.ELEMENT_NODE&&u.tagName==="STYLE"){let p=u.textContent||"";p.trim()&&t&&(f.preStyle||(f.preStyle=new WeakMap),f.preStyle.set(u,p));continue}let m=j(u,t,a,i||e);m&&d.appendChild(m)}s.appendChild(d)}if(e.tagName==="SLOT"){let r=((o=e.assignedNodes)==null?void 0:o.call(e,{flatten:!0}))||[],d=r.length>0?r:Array.from(e.childNodes),u=document.createDocumentFragment();for(let m of d){let p=j(m,t,a,i||e);p&&u.appendChild(p)}return u}for(let r of e.childNodes){if(c.has(r))continue;let d=j(r,t,a,i||e);d&&s.appendChild(d)}if(n!==null&&s instanceof HTMLSelectElement){s.value=n;for(let r of s.options)r.value===n?r.setAttribute("selected",""):r.removeAttribute("selected")}return s}var Ae=[/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],X=[];function fe(e){let t=Array.isArray(e)?e:[e];for(let a of t)a instanceof RegExp?X.push(a):typeof a=="string"?X.push(new RegExp(a,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",a)}function I(e){let t=typeof e=="string"?e:"",a=[...Ae,...X];for(let i of a)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 de(e,t,a,i=32,c="#000"){return h(this,null,function*(){t=t.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,l=document.createElement("canvas").getContext("2d");l.font=a?`${a} ${i}px "${t}"`:`${i}px "${t}"`;let o=l.measureText(e),r=o.actualBoundingBoxAscent||i*.8,d=o.actualBoundingBoxDescent||i*.2,u=r+d,m=o.width,p=document.createElement("canvas");p.width=Math.ceil(m*n),p.height=Math.ceil(u*n);let y=p.getContext("2d");return y.scale(n,n),y.font=l.font,y.textAlign="left",y.textBaseline="alphabetic",y.fillStyle=c,y.fillText(e,0,r),p.toDataURL()})}function ue(e){return Array.from(document.styleSheets).some(t=>t.href===e)}function Te(e){return new Promise(t=>{if(ue(e))return t(null);let a=document.createElement("link");a.rel="stylesheet",a.href=e,a.setAttribute("data-snapdom","injected-import"),a.onload=()=>t(a),a.onerror=()=>t(null),document.head.appendChild(a)})}function K(){return h(this,arguments,function*({preCached:e=!1}={}){if(f.resource.has("fonts-embed-css")){if(e){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=f.resource.get("fonts-embed-css"),document.head.appendChild(n)}return f.resource.get("fonts-embed-css")}let t=/@import\s+url\(["']?([^"')]+)["']?\)/g,a=[];for(let n of document.querySelectorAll("style")){let s=n.textContent||"",l=Array.from(s.matchAll(t));for(let o of l){let r=o[1];I(r)||ue(r)||a.push(r)}}yield Promise.all(a.map(Te));let i=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),c="";for(let n of i)try{let l=yield(yield fetch(n.href)).text();if(I(n.href)||I(l))continue;let o=/url\((["']?)([^"')]+)\1\)/g,r=yield Promise.all(Array.from(l.matchAll(o)).map(u=>h(null,null,function*(){let m=D(u[0]);if(!m)return null;let p=m;if(!p.startsWith("http")&&!p.startsWith("data:")&&(p=new URL(p,n.href).href),I(p))return null;if(f.resource.has(p))return f.font.add(p),{original:u[0],inlined:`url(${f.resource.get(p)})`};if(f.font.has(p))return null;try{let w=yield(yield fetch(p)).blob(),x=yield new Promise(g=>{let b=new FileReader;b.onload=()=>g(b.result),b.readAsDataURL(w)});return f.resource.set(p,x),f.font.add(p),{original:u[0],inlined:`url(${x})`}}catch(y){return console.warn("[snapdom] Failed to fetch font resource:",p),null}}))),d=l;for(let u of r)u&&(d=d.replace(u.original,u.inlined));c+=d+`
|
|
3
|
-
`}catch(s){console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||i.every(s=>s.href!==n.href)){for(let s of n.cssRules)if(s.type===CSSRule.FONT_FACE_RULE){let l=s.style.getPropertyValue("src"),o=s.style.getPropertyValue("font-family");if(!l||I(o))continue;let r=/url\((["']?)([^"')]+)\1\)/g,d=/local\((["']?)[^)]+?\1\)/g,u=r.test(l),m=d.test(l);if(!u&&m){c+=`@font-face{font-family:${o};src:${l};font-style:${s.style.getPropertyValue("font-style")||"normal"};font-weight:${s.style.getPropertyValue("font-weight")||"normal"};}`;continue}let p=l,y=Array.from(l.matchAll(r));for(let w of y){let x=w[2].trim();if(!x)continue;let g=x;if(!g.startsWith("http")&&!g.startsWith("data:")&&(g=new URL(g,n.href||location.href).href),!I(g)){if(f.resource.has(g)){f.font.add(g),p=p.replace(w[0],`url(${f.resource.get(g)})`);continue}if(!f.font.has(g))try{let S=yield(yield fetch(g)).blob(),$=yield new Promise(N=>{let k=new FileReader;k.onload=()=>N(k.result),k.readAsDataURL(S)});f.resource.set(g,$),f.font.add(g),p=p.replace(w[0],`url(${$})`)}catch(b){console.warn("[snapdom] Failed to fetch font URL:",g)}}}c+=`@font-face{font-family:${o};src:${p};font-style:${s.style.getPropertyValue("font-style")||"normal"};font-weight:${s.style.getPropertyValue("font-weight")||"normal"};}`}}}catch(s){console.warn("[snapdom] Cannot access stylesheet",n.href,s)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(I(n.family))continue;let s=n._snapdomSrc;if(!s.startsWith("data:")){if(f.resource.has(n._snapdomSrc))s=f.resource.get(n._snapdomSrc),f.font.add(n._snapdomSrc);else if(!f.font.has(n._snapdomSrc))try{let o=yield(yield fetch(n._snapdomSrc)).blob();s=yield new Promise(r=>{let d=new FileReader;d.onload=()=>r(d.result),d.readAsDataURL(o)}),f.resource.set(n._snapdomSrc,s),f.font.add(n._snapdomSrc)}catch(l){console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}c+=`@font-face{font-family:'${n.family}';src:url(${s});font-style:${n.style||"normal"};font-weight:${n.weight||"normal"};}`}if(c&&(f.resource.set("fonts-embed-css",c),e)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=c,document.head.appendChild(n)}return c})}function G(e,t,a,i=!1,c){return h(this,null,function*(){if(!(e instanceof Element)||!(t instanceof Element))return;for(let l of["::before","::after","::first-letter"])try{let o=A(e,l);if(!o||typeof o[Symbol.iterator]!="function")continue;if(l==="::first-letter"){let w=getComputedStyle(e);if(!(o.color!==w.color||o.fontSize!==w.fontSize||o.fontWeight!==w.fontWeight))continue;let g=Array.from(t.childNodes).find(v=>v.nodeType===Node.TEXT_NODE&&v.textContent&&v.textContent.trim().length>0);if(!g)continue;let b=g.textContent,S=b.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),$=S==null?void 0:S[0],N=b.slice(($==null?void 0:$.length)||0);if(!$||/[\uD800-\uDFFF]/.test($))continue;let k=document.createElement("span");k.textContent=$,k.dataset.snapdomPseudo="::first-letter";let E=Y(o),F=B(E,"span",a);f.preStyleMap.set(k,F);let W=document.createTextNode(N);t.replaceChild(W,g),t.insertBefore(k,W);continue}let r=o.getPropertyValue("content"),d=o.getPropertyValue("background-image"),u=o.getPropertyValue("background-color"),m=r!=="none",p=d&&d!=="none",y=u&&u!=="transparent"&&u!=="rgba(0, 0, 0, 0)";if(m||p||y){let w=o.getPropertyValue("font-family"),x=parseInt(o.getPropertyValue("font-size"))||32,g=parseInt(o.getPropertyValue("font-weight"))||!1,b=o.getPropertyValue("color")||"#000",S=document.createElement("span");S.dataset.snapdomPseudo=l;let $=Y(o),N=B($,"span",a);f.preStyleMap.set(S,N);let k=I(w),E;if(/counter\s*\(|counters\s*\(/.test(r)?E="- ":E=ce(r),k&&E.length===1){let v=document.createElement("img");v.src=yield de(E,w,g,x,b),v.style=`width:${x}px;height:auto;object-fit:contain;`,S.appendChild(v)}else if(E.startsWith("url(")){let v=D(E);if(v&&v.trim()!=="")try{let R=document.createElement("img"),O=yield T(z(v,{useProxy:c}));R.src=O,R.style=`width:${x}px;height:auto;object-fit:contain;`,S.appendChild(R)}catch(R){console.error(`[snapdom] Error in pseudo ${l} for`,e,R)}}else!k&&E&&E!=="none"&&(S.textContent=E);if(p)try{let v=U(d),R=yield Promise.all(v.map(O=>P(O)));S.style.backgroundImage=R.join(", ")}catch(v){console.warn(`[snapdom] Failed to inline background-image for ${l}`,v)}if(y&&(S.style.backgroundColor=u),!(S.childNodes.length>0||S.textContent&&S.textContent.trim()!==""||p||y))continue;l==="::before"?t.insertBefore(S,t.firstChild):t.appendChild(S)}}catch(o){console.warn(`[snapdom] Failed to capture ${l} for`,e,o)}let n=Array.from(e.children),s=Array.from(t.children).filter(l=>!l.dataset.snapdomPseudo);for(let l=0;l<Math.min(n.length,s.length);l++)yield G(n[l],s[l],a,i,c)})}function pe(e){if(!e)return;let t=document.querySelectorAll("svg > defs");t.length&&e.querySelectorAll("svg").forEach(a=>{let i=a.querySelectorAll("use");if(!i.length)return;let c=new Set;if(i.forEach(s=>{let l=s.getAttribute("xlink:href")||s.getAttribute("href");l&&l.startsWith("#")&&c.add(l.slice(1))}),!c.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let s of c)for(let l of t){let o=l.querySelector(`#${CSS.escape(s)}`);if(o){n.appendChild(o.cloneNode(!0));break}}n.childNodes.length&&a.insertBefore(n,a.firstChild)})}function me(c){return h(this,arguments,function*(e,t=!1,a=!1,i={}){var l;let n,s="";try{n=j(e,t,i,e)}catch(o){throw console.warn("deepClone failed:",o),o}try{yield G(e,n,t,a,i.useProxy)}catch(o){console.warn("inlinePseudoElements failed:",o)}try{pe(n)}catch(o){console.warn("inlineExternalDef failed:",o)}if(t){let o=ie();s=Array.from(o.entries()).map(([r,d])=>`.${d}{${r}}`).join("");for(let[r,d]of f.preStyleMap.entries()){if(r.tagName==="STYLE")continue;let u=o.get(d);u&&r.classList.add(u);let m=(l=r.style)==null?void 0:l.backgroundImage;r.removeAttribute("style"),m&&m!=="none"&&(r.style.backgroundImage=m)}}else for(let[o,r]of f.preStyleMap.entries())o.tagName!=="STYLE"&&o.setAttribute("style",r.replace(/;/g,"; "));for(let[o,r]of f.preNodeMap.entries()){let d=r.scrollLeft,u=r.scrollTop;if((d||u)&&o instanceof HTMLElement){o.style.overflow="hidden",o.style.scrollbarWidth="none",o.style.msOverflowStyle="none";let p=document.createElement("div");for(p.style.transform=`translate(${-d}px, ${-u}px)`,p.style.willChange="transform",p.style.display="inline-block",p.style.width="100%";o.firstChild;)p.appendChild(o.firstChild);o.appendChild(p)}}if(e===f.preNodeMap.get(n)){let o=f.preStyle.get(e)||window.getComputedStyle(e);f.preStyle.set(e,o);let r=le(o.transform);n.style.margin="0",n.style.position="static",n.style.top="auto",n.style.left="auto",n.style.right="auto",n.style.bottom="auto",n.style.zIndex="auto",n.style.float="none",n.style.clear="none",n.style.transform=r||""}for(let[o,r]of f.preNodeMap.entries())r.tagName==="PRE"&&(o.style.marginTop="0",o.style.marginBlockStart="0");return{clone:n,classCSS:s}})}function he(a){return h(this,arguments,function*(e,t={}){let i=Array.from(e.querySelectorAll("img")),c=n=>h(null,null,function*(){let s=n.src;try{let l=yield T(s,{useProxy:t.useProxy});n.src=l,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch(l){let o=document.createElement("div");o.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;`,o.innerText="img",n.replaceWith(o)}});for(let n=0;n<i.length;n+=4){let s=i.slice(n,n+4).map(c);yield Promise.allSettled(s)}})}function ge(i,c){return h(this,arguments,function*(e,t,a={}){let n=[[e,t]],s=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source"];for(;n.length;){let[l,o]=n.shift(),r=f.preStyle.get(l)||A(l);f.preStyle.has(l)||f.preStyle.set(l,r);for(let p of s){let y=r.getPropertyValue(p);if(!y||y==="none")continue;let w=U(y),x=yield Promise.all(w.map(g=>P(g,a)));x.some(g=>g&&g!=="none"&&!/^url\(undefined/.test(g))&&o.style.setProperty(p,x.join(", "))}let d=r.getPropertyValue("background-color");d&&d!=="transparent"&&d!=="rgba(0, 0, 0, 0)"&&(o.style.backgroundColor=d);let u=Array.from(l.children),m=Array.from(o.children);for(let p=0;p<Math.min(u.length,m.length);p++)n.push([u[p],m[p]])}})}function ye(a){return h(this,arguments,function*(e,t={}){if(!e)throw new Error("Element cannot be null or undefined");f.reset();let{compress:i=!0,embedFonts:c=!1,fast:n=!0,scale:s=1,useProxy:l=""}=t,o,r,d="",u="",m,p;if({clone:o,classCSS:r}=yield me(e,i,c,t),yield new Promise(w=>{L(()=>h(null,null,function*(){yield he(o,t),w()}),{fast:n})}),yield new Promise(w=>{L(()=>h(null,null,function*(){yield ge(e,o,t),w()}),{fast:n})}),c&&(yield new Promise(w=>{L(()=>h(null,null,function*(){d=yield K(),w()}),{fast:n})})),i){let w=re(o).sort(),x=w.join(",");f.baseStyle.has(x)?u=f.baseStyle.get(x):yield new Promise(g=>{L(()=>{u=se(w),f.baseStyle.set(x,u),g()},{fast:n})})}yield new Promise(w=>{L(()=>{let x=e.getBoundingClientRect(),g=x.width,b=x.height,S=Number.isFinite(t.width),$=Number.isFinite(t.height),N=typeof s=="number"&&s!==1;if(!N){let V=x.width/x.height;S&&$?(g=t.width,b=t.height):S?(g=t.width,b=g/V):$&&(b=t.height,g=b*V)}if(g=Math.ceil(g),b=Math.ceil(b),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="top left",!N&&(S||$)){let V=x.width,be=x.height,Ce=g/V,Ee=b/be,ve=o.style.transform||"",$e=`scale(${Ce}, ${Ee})`;o.style.transform=`${$e} ${ve}`.trim()}else N&&q()&&(o.style.scale=`${s}`);let k="http://www.w3.org/2000/svg",E=document.createElementNS(k,"foreignObject");E.setAttribute("width","100%"),E.setAttribute("height","100%");let F=document.createElement("style");F.textContent=u+d+"svg{overflow:visible;}"+r,E.appendChild(F),E.appendChild(o);let v=new XMLSerializer().serializeToString(E);p=`<svg xmlns="${k}" width="${g}" height="${b}" viewBox="0 0 ${g} ${b}">`+v+"</svg>",m=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(p)}`,w()},{fast:n})});let y=document.getElementById("snapdom-sandbox");return y&&y.style.position==="absolute"&&y.remove(),m})}function Me(i,c){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1}){let n=new Image;return n.src=e,yield n.decode(),q?(n.width=n.width*a,n.height=n.height*a):(n.width=n.width/a,n.height=n.height/a),n})}function we(i){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1}={}){let c=new Image;c.src=e,yield c.decode();let n=document.createElement("canvas"),s=c.width*a,l=c.height*a;n.width=Math.ceil(s*t),n.height=Math.ceil(l*t);let o=n.getContext("2d");return o.scale(t,t),o.drawImage(c,0,0,s,l),n.style.width=`${s}px`,n.style.height=`${l}px`,n})}function xe(n){return h(this,arguments,function*(e,{type:t="svg",scale:a=1,backgroundColor:i="#fff",quality:c}={}){let s={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[t]||"image/png";if(t==="svg"){let o=decodeURIComponent(e.split(",")[1]);return new Blob([o],{type:"image/svg+xml"})}let l=yield Q(e,{dpr:1,scale:a},i);return new Promise(o=>{l.toBlob(r=>o(r),`${s}`,c)})})}function Q(c,n,s){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1},i){let l=yield we(e,{dpr:t,scale:a});if(!i)return l;let o=document.createElement("canvas");o.width=l.width,o.height=l.height;let r=o.getContext("2d");return r.fillStyle=i,r.fillRect(0,0,o.width,o.height),r.drawImage(l,0,0),o})}function J(s,l){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1,backgroundColor:i,quality:c},n="png"){let o=["jpg","jpeg","webp"].includes(n)?"#fff":void 0,r=i!=null?i:o,d=yield Q(e,{dpr:t,scale:a},r),u=new Image;return u.src=d.toDataURL(`image/${n}`,c),yield u.decode(),u.style.width=`${d.width/t}px`,u.style.height=`${d.height/t}px`,u})}function Pe(s){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1,backgroundColor:i="#fff",format:c="png",filename:n="capture"}={}){if(c==="svg"){let p=yield xe(e),y=URL.createObjectURL(p),w=document.createElement("a");w.href=y,w.download=`${n}.svg`,w.click(),URL.revokeObjectURL(y);return}let l=["jpg","jpeg","webp"].includes(c)?"#fff":void 0,o=i!=null?i:l,r=yield Q(e,{dpr:t,scale:a},o),d={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[c]||"image/png",u=r.toDataURL(d),m=document.createElement("a");m.href=u,m.download=`${n}.${c}`,m.click()})}function C(a){return h(this,arguments,function*(e,t={}){if(t=M({scale:1},t),!e)throw new Error("Element cannot be null or undefined");return t.iconFonts&&fe(t.iconFonts),yield C.capture(e,t)})}C.capture=(a,...i)=>h(null,[a,...i],function*(e,t={}){let c=yield ye(e,t),n=window.devicePixelRatio||1,s=t.scale||1;return{url:c,options:t,toRaw:()=>c,toImg:()=>Me(c,{dpr:n,scale:s}),toCanvas:()=>we(c,{dpr:n,scale:s}),toBlob:l=>xe(c,M({dpr:n,scale:s},l)),toPng:l=>J(c,M({dpr:n,scale:s},l),"png"),toJpg:l=>J(c,M({dpr:n,scale:s},l),"jpeg"),toWebp:l=>J(c,M({dpr:n,scale:s},l),"webp"),download:({format:l="png",filename:o="capture",backgroundColor:r}={})=>Pe(c,{dpr:n,scale:s,backgroundColor:r,format:l,filename:o})}});C.toRaw=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toRaw()});C.toImg=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toImg()});C.toCanvas=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toCanvas()});C.toBlob=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toBlob(t)});C.toPng=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toPng(t)});C.toJpg=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toJpg(t)});C.toWebp=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toWebp(t)});C.download=(a,...i)=>h(null,[a,...i],function*(e,t={}){let r=t,{format:c="png",filename:n="capture",backgroundColor:s}=r,l=ne(r,["format","filename","backgroundColor"]);return yield(yield C.capture(e,l)).download({format:c,filename:n,backgroundColor:s})});function Se(){return h(this,arguments,function*(e=document,t={}){let{embedFonts:a=!0,reset:i=!1}=t;if(i){f.reset();return}yield document.fonts.ready,oe();let c=[],n=[];e!=null&&e.querySelectorAll&&(c=Array.from(e.querySelectorAll("img[src]")),n=Array.from(e.querySelectorAll("*")));let s=[];for(let l of c){let o=l.src;f.image.has(o)||s.push(T(o,{useProxy:t.useProxy}).then(r=>f.image.set(o,r)).catch(()=>{}))}for(let l of n){let o=A(l).backgroundImage;if(o&&o!=="none"){let r=U(o);for(let d of r)d.startsWith("url(")&&s.push(P(d,t).catch(()=>{}))}}a&&(yield K({preCached:!0})),yield Promise.all(s)})}typeof window!="undefined"&&(window.snapdom=C,window.preCache=Se);})();
|
|
1
|
+
(()=>{var De=Object.defineProperty;var K=Object.getOwnPropertySymbols;var ue=Object.prototype.hasOwnProperty,me=Object.prototype.propertyIsEnumerable;var pe=(e,t,a)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,U=(e,t)=>{for(var a in t||(t={}))ue.call(t,a)&&pe(e,a,t[a]);if(K)for(var a of K(t))me.call(t,a)&&pe(e,a,t[a]);return e};var he=(e,t)=>{var a={};for(var c in e)ue.call(e,c)&&t.indexOf(c)<0&&(a[c]=e[c]);if(e!=null&&K)for(var c of K(e))t.indexOf(c)<0&&me.call(e,c)&&(a[c]=e[c]);return a};var h=(e,t,a)=>new Promise((c,s)=>{var n=o=>{try{l(a.next(o))}catch(r){s(r)}},i=o=>{try{l(a.throw(o))}catch(r){s(r)}},l=o=>o.done?c(o.value):Promise.resolve(o.value).then(n,i);l((a=a.apply(e,t)).next())});var f={image:new Map,background:new Map,resource:new Map,defaultStyle:new Map,baseStyle:new Map,computedStyle:new WeakMap,font:new Set,snapshot:new WeakMap,snapshotKey:new Map,preStyleMap:new Map,preStyle:new WeakMap,preNodeMap:new Map,reset:je};function je(){f.computedStyle=new WeakMap,f.snapshot=new WeakMap,f.snapshotKey.clear(),f.preStyleMap.clear(),f.preStyle=new WeakMap,f.preNodeMap.clear()}var We=["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 ge(){for(let e of We)ye(e)}function ye(e){if(f.defaultStyle.has(e))return f.defaultStyle.get(e);if(new Set(["script","style","meta","link","noscript","template"]).has(e)){let i={};return f.defaultStyle.set(e,i),i}let a=document.getElementById("snapdom-sandbox");a||(a=document.createElement("div"),a.id="snapdom-sandbox",a.style.position="absolute",a.style.left="-9999px",a.style.top="-9999px",a.style.width="0",a.style.height="0",a.style.overflow="hidden",document.body.appendChild(a));let c=document.createElement(e);c.style.all="initial",a.appendChild(c);let s=getComputedStyle(c),n={};for(let i of s)n[i]=s.getPropertyValue(i);return a.removeChild(c),f.defaultStyle.set(e,n),n}function O(e,t,a=!1){let c=[],s=ye(t);for(let[n,i]of Object.entries(e))if(!a)i&&c.push(`${n}:${i}`);else{let l=s[n];i&&i!==l&&c.push(`${n}:${i}`)}return c.sort().join(";")}function we(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(a=>t.add(a.tagName.toLowerCase())),Array.from(t))}function xe(e){let t=new Map;for(let c of e){let s=f.defaultStyle.get(c);if(!s)continue;let n=Object.entries(s).map(([i,l])=>`${i}:${l};`).sort().join("");t.has(n)||t.set(n,[]),t.get(n).push(c)}let a="";for(let[c,s]of t.entries())a+=`${s.join(",")} { ${c} }
|
|
2
|
+
`;return a}function Se(){let e=new Set(f.preStyleMap.values()),t=new Map,a=1;for(let c of e)t.set(c,`c${a++}`);return t}function B(a){return h(this,arguments,function*(e,t={}){let c=_(e),s=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(c){let n=Y(c);if(f.background.has(n))return t.skipInline?void 0:`url(${f.background.get(n)})`;{let i=yield P(n,{useProxy:t.useProxy});return f.background.set(n,i),t.skipInline?void 0:`url("${i}")`}}return e})}function D(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 a=f.computedStyle.get(e);if(a||(a=new Map,f.computedStyle.set(e,a)),!a.has(t)){let c=window.getComputedStyle(e,t);a.set(t,c)}return a.get(t)}function be(e){let t=e.replace(/^['"]|['"]$/g,"");if(t.startsWith("\\"))try{return String.fromCharCode(parseInt(t.replace("\\",""),16))}catch(a){return t}return t}function _(e){let t=e.match(/url\((['"]?)(.*?)(\1)\)/);if(!t)return null;let a=t[2].trim();return a.startsWith("#")?null:a}function P(e,{timeout:t=3e3,useProxy:a=""}={}){function c(o){try{return new URL(o,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch(r){return"anonymous"}}function s(o){return h(this,null,function*(){let r=d=>fetch(d,{mode:"cors",credentials:c(d)==="use-credentials"?"include":"omit"}).then(p=>p.blob()).then(p=>new Promise((m,u)=>{let y=new FileReader;y.onloadend=()=>{let w=y.result;if(typeof w!="string"||!w.startsWith("data:image/")){u(new Error("Invalid image data URL"));return}m(w)},y.onerror=()=>u(new Error("FileReader error")),y.readAsDataURL(p)}));try{return yield r(o)}catch(d){if(a&&typeof a=="string"){let p=a.replace(/\/$/,"")+Y(o);try{return yield r(p)}catch(m){throw new Error("[SnapDOM - fetchImage] CORS restrictions prevented image capture (even via proxy)")}}else throw new Error("[SnapDOM - fetchImage] Fetch fallback failed and no proxy provided")}})}let n=c(e);return f.image.has(e)?Promise.resolve(f.image.get(e)):e.startsWith("data:image/")?(f.image.set(e,e),Promise.resolve(e)):/\.svg(\?.*)?$/i.test(e)?h(null,null,function*(){try{let r=yield(yield fetch(e,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),d=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r)}`;return f.image.set(e,d),d}catch(o){return s(e)}}):new Promise((o,r)=>{let d=setTimeout(()=>{r(new Error("[SnapDOM - fetchImage] Image load timed out"))},t),p=new Image;p.crossOrigin=n,p.onload=()=>h(null,null,function*(){clearTimeout(d);try{yield p.decode();let m=document.createElement("canvas");m.width=p.width,m.height=p.height,m.getContext("2d").drawImage(p,0,0,m.width,m.height);let y=m.toDataURL("image/png");f.image.set(e,y),o(y)}catch(m){try{let u=yield s(e);f.image.set(e,u),o(u)}catch(u){r(u)}}}),p.onerror=()=>h(null,null,function*(){clearTimeout(d),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let m=yield s(e);f.image.set(e,m),o(m)}catch(m){r(m)}}),p.src=e})}function oe(e){let t={};for(let a of e)t[a]=e.getPropertyValue(a);return t}function Ce(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Ee(e){if(!e||e==="none")return"";let t=e.replace(/translate[XY]?\([^)]*\)/g,"");return t=t.replace(/matrix\(([^)]+)\)/g,(a,c)=>{let s=c.split(",").map(n=>n.trim());return s.length!==6?`matrix(${c})`:(s[4]="0",s[5]="0",`matrix(${s.join(", ")})`)}),t=t.replace(/matrix3d\(([^)]+)\)/g,(a,c)=>{let s=c.split(",").map(n=>n.trim());return s.length!==16?`matrix3d(${c})`:(s[12]="0",s[13]="0",`matrix3d(${s.join(", ")})`)}),t.trim().replace(/\s{2,}/g," ")}function Y(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch(t){return e}}function j(e){let t=[],a=0,c=0;for(let s=0;s<e.length;s++){let n=e[s];n==="("&&a++,n===")"&&a--,n===","&&a===0&&(t.push(e.slice(c,s).trim()),c=s+1)}return t.push(e.slice(c).trim()),t}function Ve(e){let t={};for(let a=0;a<e.length;a++){let c=e[a],s=e.getPropertyValue(c);(c==="background-image"||c==="content")&&s.includes("url(")&&!s.includes("data:")&&(s="none"),t[c]=s}return t}function X(e,t,a){var o;if(e.tagName==="STYLE")return;f.preStyle.has(e)||f.preStyle.set(e,N(e));let c=f.preStyle.get(e);if(!f.snapshot.has(e)){let r=Ve(c);f.snapshot.set(e,r)}let s=f.snapshot.get(e),n=Object.entries(s).sort(([r],[d])=>r.localeCompare(d)).map(([r,d])=>`${r}:${d}`).join(";");if(f.snapshotKey.has(n)){f.preStyleMap.set(t,f.snapshotKey.get(n));return}let i=((o=e.tagName)==null?void 0:o.toLowerCase())||"div",l=O(s,i,a);f.snapshotKey.set(n,l),f.preStyleMap.set(t,l)}function q(e,t,a={},c){var l,o;if(!e)throw new Error("Invalid node");let s=new Set,n=null;if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let r=document.createElement("div"),d=e.getBoundingClientRect();return r.style.cssText=`display:inline-block;width:${d.width}px;height:${d.height}px;visibility:hidden;`,r}if(a.exclude&&Array.isArray(a.exclude))for(let r of a.exclude)try{if((l=e.matches)!=null&&l.call(e,r)){let d=document.createElement("div"),p=e.getBoundingClientRect();return d.style.cssText=`display:inline-block;width:${p.width}px;height:${p.height}px;visibility:hidden;`,d}}catch(d){console.warn(`Invalid selector in exclude option: ${r}`,d)}if(typeof a.filter=="function")try{if(!a.filter(e,c||e)){let r=document.createElement("div"),d=e.getBoundingClientRect();return r.style.cssText=`display:inline-block;width:${d.width}px;height:${d.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.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);f.preNodeMap.set(r,e),X(e,r,t);let d=document.createElement("div");return d.textContent=e.getAttribute("data-placeholder-text")||"",d.style.cssText="color:#666;font-size:12px;text-align:center;line-height:1.4;padding:0.5em;box-sizing:border-box;",r.appendChild(d),r}if(e.tagName==="CANVAS"){let r=e.toDataURL(),d=document.createElement("img");return d.src=r,d.width=e.width,d.height=e.height,f.preNodeMap.set(d,e),X(e,d,t),d}let i;try{i=e.cloneNode(!1),f.preNodeMap.set(i,e)}catch(r){throw console.error("[Snapdom] Failed to clone node:",e,r),r}if(e instanceof HTMLTextAreaElement){i.textContent=e.value,i.value=e.value;let r=e.getBoundingClientRect();return i.style.width=`${r.width}px`,i.style.height=`${r.height}px`,i}if(e instanceof HTMLInputElement&&(i.value=e.value,i.setAttribute("value",e.value),e.checked!==void 0&&(i.checked=e.checked,e.checked&&i.setAttribute("checked",""),e.indeterminate&&(i.indeterminate=e.indeterminate))),e instanceof HTMLSelectElement&&(n=e.value),X(e,i,t),e.shadowRoot)if(Array.from(e.shadowRoot.querySelectorAll("slot")).length>0){for(let d of e.shadowRoot.childNodes)if(d.nodeType===Node.ELEMENT_NODE&&d.tagName==="STYLE"){let p=d.textContent||"";p.trim()&&t&&(f.preStyle||(f.preStyle=new WeakMap),f.preStyle.set(d,p))}}else{let d=document.createDocumentFragment();for(let p of e.shadowRoot.childNodes){if(p.nodeType===Node.ELEMENT_NODE&&p.tagName==="STYLE"){let u=p.textContent||"";u.trim()&&t&&(f.preStyle||(f.preStyle=new WeakMap),f.preStyle.set(p,u));continue}let m=q(p,t,a,c||e);m&&d.appendChild(m)}i.appendChild(d)}if(e.tagName==="SLOT"){let r=((o=e.assignedNodes)==null?void 0:o.call(e,{flatten:!0}))||[],d=r.length>0?r:Array.from(e.childNodes),p=document.createDocumentFragment();for(let m of d){let u=q(m,t,a,c||e);u&&p.appendChild(u)}return p}for(let r of e.childNodes){if(s.has(r))continue;let d=q(r,t,a,c||e);d&&i.appendChild(d)}if(n!==null&&i instanceof HTMLSelectElement){i.value=n;for(let r of i.options)r.value===n?r.setAttribute("selected",""):r.removeAttribute("selected")}return i}var Oe=[/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 ve(e){let t=Array.isArray(e)?e:[e];for(let a of t)a instanceof RegExp?ae.push(a):typeof a=="string"?ae.push(new RegExp(a,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",a)}function $(e){let t=typeof e=="string"?e:"",a=[...Oe,...ae];for(let c of a)if(c instanceof RegExp&&c.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 $e(e,t,a,c=32,s="#000"){return h(this,null,function*(){t=t.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,l=document.createElement("canvas").getContext("2d");l.font=a?`${a} ${c}px "${t}"`:`${c}px "${t}"`;let o=l.measureText(e),r=o.actualBoundingBoxAscent||c*.8,d=o.actualBoundingBoxDescent||c*.2,p=r+d,m=o.width,u=document.createElement("canvas");u.width=Math.ceil(m*n),u.height=Math.ceil(p*n);let y=u.getContext("2d");return y.scale(n,n),y.font=l.font,y.textAlign="left",y.textBaseline="alphabetic",y.fillStyle=s,y.fillText(e,0,r),u.toDataURL()})}function ke(e){return Array.from(document.styleSheets).some(t=>t.href===e)}function _e(e){return new Promise(t=>{if(ke(e))return t(null);let a=document.createElement("link");a.rel="stylesheet",a.href=e,a.setAttribute("data-snapdom","injected-import"),a.onload=()=>t(a),a.onerror=()=>t(null),document.head.appendChild(a)})}function G(){return h(this,arguments,function*({preCached:e=!1}={}){if(f.resource.has("fonts-embed-css")){if(e){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=f.resource.get("fonts-embed-css"),document.head.appendChild(n)}return f.resource.get("fonts-embed-css")}let t=/@import\s+url\(["']?([^"')]+)["']?\)/g,a=[];for(let n of document.querySelectorAll("style")){let i=n.textContent||"",l=Array.from(i.matchAll(t));for(let o of l){let r=o[1];$(r)||ke(r)||a.push(r)}}yield Promise.all(a.map(_e));let c=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),s="";for(let n of c)try{let l=yield(yield fetch(n.href)).text();if($(n.href)||$(l))continue;let o=/url\((["']?)([^"')]+)\1\)/g,r=yield Promise.all(Array.from(l.matchAll(o)).map(p=>h(null,null,function*(){let m=_(p[0]);if(!m)return null;let u=m;if(!u.startsWith("http")&&!u.startsWith("data:")&&(u=new URL(u,n.href).href),$(u))return null;if(f.resource.has(u))return f.font.add(u),{original:p[0],inlined:`url(${f.resource.get(u)})`};if(f.font.has(u))return null;try{let w=yield(yield fetch(u)).blob(),x=yield new Promise(g=>{let b=new FileReader;b.onload=()=>g(b.result),b.readAsDataURL(w)});return f.resource.set(u,x),f.font.add(u),{original:p[0],inlined:`url(${x})`}}catch(y){return console.warn("[snapdom] Failed to fetch font resource:",u),null}}))),d=l;for(let p of r)p&&(d=d.replace(p.original,p.inlined));s+=d+`
|
|
3
|
+
`}catch(i){console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||c.every(i=>i.href!==n.href)){for(let i of n.cssRules)if(i.type===CSSRule.FONT_FACE_RULE){let l=i.style.getPropertyValue("src"),o=i.style.getPropertyValue("font-family");if(!l||$(o))continue;let r=/url\((["']?)([^"')]+)\1\)/g,d=/local\((["']?)[^)]+?\1\)/g,p=!!l.match(r),m=!!l.match(d);if(!p&&m){s+=`@font-face{font-family:${o};src:${l};font-style:${i.style.getPropertyValue("font-style")||"normal"};font-weight:${i.style.getPropertyValue("font-weight")||"normal"};}`;continue}let u=l,y=Array.from(l.matchAll(r));for(let w of y){let x=w[2].trim();if(!x)continue;let g=x;if(!g.startsWith("http")&&!g.startsWith("data:")&&(g=new URL(g,n.href||location.href).href),!$(g)){if(f.resource.has(g)){f.font.add(g),u=u.replace(w[0],`url(${f.resource.get(g)})`);continue}if(!f.font.has(g))try{let I=yield(yield fetch(g)).blob(),k=yield new Promise(T=>{let C=new FileReader;C.onload=()=>T(C.result),C.readAsDataURL(I)});f.resource.set(g,k),f.font.add(g),u=u.replace(w[0],`url(${k})`)}catch(b){console.warn("[snapdom] Failed to fetch font URL:",g)}}}s+=`@font-face{font-family:${o};src:${u};font-style:${i.style.getPropertyValue("font-style")||"normal"};font-weight:${i.style.getPropertyValue("font-weight")||"normal"};}`}}}catch(i){console.warn("[snapdom] Cannot access stylesheet",n.href,i)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if($(n.family))continue;let i=n._snapdomSrc;if(!i.startsWith("data:")){if(f.resource.has(n._snapdomSrc))i=f.resource.get(n._snapdomSrc),f.font.add(n._snapdomSrc);else if(!f.font.has(n._snapdomSrc))try{let o=yield(yield fetch(n._snapdomSrc)).blob();i=yield new Promise(r=>{let d=new FileReader;d.onload=()=>r(d.result),d.readAsDataURL(o)}),f.resource.set(n._snapdomSrc,i),f.font.add(n._snapdomSrc)}catch(l){console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}s+=`@font-face{font-family:'${n.family}';src:url(${i});font-style:${n.style||"normal"};font-weight:${n.weight||"normal"};}`}if(s&&(f.resource.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,a,c=!1,s){return h(this,null,function*(){if(!(e instanceof Element)||!(t instanceof Element))return;for(let l of["::before","::after","::first-letter"])try{let o=N(e,l);if(!o||typeof o[Symbol.iterator]!="function")continue;if(l==="::first-letter"){let E=getComputedStyle(e);if(!(o.color!==E.color||o.fontSize!==E.fontSize||o.fontWeight!==E.fontWeight))continue;let M=Array.from(t.childNodes).find(ne=>ne.nodeType===Node.TEXT_NODE&&ne.textContent&&ne.textContent.trim().length>0);if(!M)continue;let fe=M.textContent,te=fe.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),F=te==null?void 0:te[0],Fe=fe.slice((F==null?void 0:F.length)||0);if(!F||/[\uD800-\uDFFF]/.test(F))continue;let H=document.createElement("span");H.textContent=F,H.dataset.snapdomPseudo="::first-letter";let Ue=oe(o),Be=O(Ue,"span",a);f.preStyleMap.set(H,Be);let de=document.createTextNode(Fe);t.replaceChild(de,M),t.insertBefore(H,de);continue}let r=o.getPropertyValue("content"),d=o.getPropertyValue("background-image"),p=o.getPropertyValue("background-color"),m=o.getPropertyValue("font-family"),u=parseInt(o.getPropertyValue("font-size"))||32,y=parseInt(o.getPropertyValue("font-weight"))||!1,w=o.getPropertyValue("color")||"#000",x=o.getPropertyValue("display"),g=parseFloat(o.getPropertyValue("width")),b=parseFloat(o.getPropertyValue("height")),I=o.getPropertyValue("border-style"),k=o.getPropertyValue("transform"),T=$(m),C;/counter\s*\(|counters\s*\(/.test(r)?C="- ":C=be(r);let W=r!=="none"&&C!=="",z=d&&d!=="none",V=p&&p!=="transparent"&&p!=="rgba(0, 0, 0, 0)",J=x!=="inline"&&(g>0||b>0),Q=I&&I!=="none",A=k&&k!=="none";if(!(W||z||V||J||Q||A))continue;let v=document.createElement("span");v.dataset.snapdomPseudo=l;let Z=oe(o),ee=O(Z,"span",a);if(f.preStyleMap.set(v,ee),T&&C.length===1){let E=document.createElement("img");E.src=yield $e(C,m,y,u,w),E.style=`width:${u}px;height:auto;object-fit:contain;`,v.appendChild(E)}else if(C.startsWith("url(")){let E=_(C);if(E&&E.trim()!=="")try{let R=document.createElement("img"),M=yield P(Y(E,{useProxy:s}));R.src=M,R.style=`width:${u}px;height:auto;object-fit:contain;`,v.appendChild(R)}catch(R){console.error(`[snapdom] Error in pseudo ${l} for`,e,R)}}else!T&&W&&(v.textContent=C);if(z)try{let E=j(d),R=yield Promise.all(E.map(M=>B(M)));v.style.backgroundImage=R.join(", ")}catch(E){console.warn(`[snapdom] Failed to inline background-image for ${l}`,E)}if(V&&(v.style.backgroundColor=p),!(v.childNodes.length>0||v.textContent&&v.textContent.trim()!==""||z||V||J||Q||A))continue;l==="::before"?t.insertBefore(v,t.firstChild):t.appendChild(v)}catch(o){console.warn(`[snapdom] Failed to capture ${l} for`,e,o)}let n=Array.from(e.children),i=Array.from(t.children).filter(l=>!l.dataset.snapdomPseudo);for(let l=0;l<Math.min(n.length,i.length);l++)yield re(n[l],i[l],a,c,s)})}function Ie(e){if(!e)return;let t=document.querySelectorAll("svg > defs");t.length&&e.querySelectorAll("svg").forEach(a=>{let c=a.querySelectorAll("use");if(!c.length)return;let s=new Set;if(c.forEach(i=>{let l=i.getAttribute("xlink:href")||i.getAttribute("href");l&&l.startsWith("#")&&s.add(l.slice(1))}),!s.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let i of s)for(let l of t){let o=l.querySelector(`#${CSS.escape(i)}`);if(o){n.appendChild(o.cloneNode(!0));break}}n.childNodes.length&&a.insertBefore(n,a.firstChild)})}function Re(s){return h(this,arguments,function*(e,t=!1,a=!1,c={}){var l;let n,i="";try{n=q(e,t,c,e)}catch(o){throw console.warn("deepClone failed:",o),o}try{yield re(e,n,t,a,c.useProxy)}catch(o){console.warn("inlinePseudoElements failed:",o)}try{Ie(n)}catch(o){console.warn("inlineExternalDef failed:",o)}if(t){let o=Se();i=Array.from(o.entries()).map(([r,d])=>`.${d}{${r}}`).join("");for(let[r,d]of f.preStyleMap.entries()){if(r.tagName==="STYLE")continue;let p=o.get(d);p&&r.classList.add(p);let m=(l=r.style)==null?void 0:l.backgroundImage;r.removeAttribute("style"),m&&m!=="none"&&(r.style.backgroundImage=m)}}else for(let[o,r]of f.preStyleMap.entries())o.tagName!=="STYLE"&&o.setAttribute("style",r.replace(/;/g,"; "));for(let[o,r]of f.preNodeMap.entries()){let d=r.scrollLeft,p=r.scrollTop;if((d||p)&&o instanceof HTMLElement){o.style.overflow="hidden",o.style.scrollbarWidth="none",o.style.msOverflowStyle="none";let u=document.createElement("div");for(u.style.transform=`translate(${-d}px, ${-p}px)`,u.style.willChange="transform",u.style.display="inline-block",u.style.width="100%";o.firstChild;)u.appendChild(o.firstChild);o.appendChild(u)}}if(e===f.preNodeMap.get(n)){let o=f.preStyle.get(e)||window.getComputedStyle(e);f.preStyle.set(e,o);let r=Ee(o.transform);n.style.margin="0",n.style.position="static",n.style.top="auto",n.style.left="auto",n.style.right="auto",n.style.bottom="auto",n.style.zIndex="auto",n.style.float="none",n.style.clear="none",n.style.transform=r||""}for(let[o,r]of f.preNodeMap.entries())r.tagName==="PRE"&&(o.style.marginTop="0",o.style.marginBlockStart="0");return{clone:n,classCSS:i}})}function Ne(a){return h(this,arguments,function*(e,t={}){let c=Array.from(e.querySelectorAll("img")),s=n=>h(null,null,function*(){let i=n.src;try{let l=yield P(i,{useProxy:t.useProxy});n.src=l,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch(l){let o=document.createElement("div");o.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;`,o.innerText="img",n.replaceWith(o)}});for(let n=0;n<c.length;n+=4){let i=c.slice(n,n+4).map(s);yield Promise.allSettled(i)}})}function Te(c,s){return h(this,arguments,function*(e,t,a={}){let n=[[e,t]],i=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source"];for(;n.length;){let[l,o]=n.shift(),r=f.preStyle.get(l)||N(l);f.preStyle.has(l)||f.preStyle.set(l,r);for(let u of i){let y=r.getPropertyValue(u);if(!y||y==="none")continue;let w=j(y),x=yield Promise.all(w.map(g=>B(g,a)));x.some(g=>g&&g!=="none"&&!/^url\(undefined/.test(g))&&o.style.setProperty(u,x.join(", "))}let d=r.getPropertyValue("background-color");d&&d!=="transparent"&&d!=="rgba(0, 0, 0, 0)"&&(o.style.backgroundColor=d);let p=Array.from(l.children),m=Array.from(o.children);for(let u=0;u<Math.min(p.length,m.length);u++)n.push([p[u],m[u]])}})}function Ae(a){return h(this,arguments,function*(e,t={}){if(!e)throw new Error("Element cannot be null or undefined");f.reset();let{compress:c=!0,embedFonts:s=!1,fast:n=!0,scale:i=1,useProxy:l=""}=t,o,r,d="",p="",m,u;if({clone:o,classCSS:r}=yield Re(e,c,s,t),yield new Promise(w=>{D(()=>h(null,null,function*(){yield Ne(o,t),w()}),{fast:n})}),yield new Promise(w=>{D(()=>h(null,null,function*(){yield Te(e,o,t),w()}),{fast:n})}),s&&(yield new Promise(w=>{D(()=>h(null,null,function*(){d=yield G(),w()}),{fast:n})})),c){let w=we(o).sort(),x=w.join(",");f.baseStyle.has(x)?p=f.baseStyle.get(x):yield new Promise(g=>{D(()=>{p=xe(w),f.baseStyle.set(x,p),g()},{fast:n})})}yield new Promise(w=>{D(()=>{let x=e.getBoundingClientRect(),g=x.width,b=x.height,I=Number.isFinite(t.width),k=Number.isFinite(t.height),T=typeof i=="number"&&i!==1;if(!T){let A=x.width/x.height;I&&k?(g=t.width,b=t.height):I?(g=t.width,b=g/A):k&&(b=t.height,g=b*A)}if(g=Math.ceil(g),b=Math.ceil(b),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="top left",!T&&(I||k)){let A=x.width,ce=x.height,v=g/A,Z=b/ce,ee=o.style.transform||"",le=`scale(${v}, ${Z})`;o.style.transform=`${le} ${ee}`.trim()}let C="http://www.w3.org/2000/svg",L=document.createElementNS(C,"foreignObject");L.setAttribute("width","100%"),L.setAttribute("height","100%");let W=document.createElement("style");W.textContent=p+d+"svg{overflow:visible;}"+r,L.appendChild(W),L.appendChild(o);let V=new XMLSerializer().serializeToString(L);u=`<svg xmlns="${C}" width="${g}" height="${b}" viewBox="0 0 ${g} ${b}">`+V+"</svg>",m=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`,w()},{fast:n})});let y=document.getElementById("snapdom-sandbox");return y&&y.style.position==="absolute"&&y.remove(),m})}function qe(c,s){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1}){let n=new Image;return n.src=e,yield n.decode(),n.width=n.width*a,n.height=n.height*a,n})}function Me(c){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1}={}){let s=new Image;s.src=e,s.crossOrigin="anonymous",s.loading="eager",s.decoding="sync";let n=Ce(),i=!1;if(n&&(document.body.appendChild(s),i=!0),yield s.decode(),n&&(yield new Promise(p=>setTimeout(p,100))),s.width===0||s.height===0)throw i&&s.remove(),new Error("Image failed to load or has no dimensions");let l=s.width*a,o=s.height*a,r=document.createElement("canvas");r.width=Math.ceil(l*t),r.height=Math.ceil(o*t),r.style.width=`${l}px`,r.style.height=`${o}px`;let d=r.getContext("2d");return d.scale(t,t),d.drawImage(s,0,0,l,o),i&&s.remove(),r})}function Pe(n){return h(this,arguments,function*(e,{type:t="svg",scale:a=1,backgroundColor:c="#fff",quality:s}={}){let i={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[t]||"image/png";if(t==="svg"){let o=decodeURIComponent(e.split(",")[1]);return new Blob([o],{type:"image/svg+xml"})}let l=yield ie(e,{dpr:1,scale:a},c);return new Promise(o=>{l.toBlob(r=>o(r),`${i}`,s)})})}function ie(s,n,i){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1},c){let l=yield Me(e,{dpr:t,scale:a});if(!c)return l;let o=document.createElement("canvas");o.width=l.width,o.height=l.height;let r=o.getContext("2d");return r.fillStyle=c,r.fillRect(0,0,o.width,o.height),r.drawImage(l,0,0),o})}function se(i,l){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1,backgroundColor:c,quality:s},n="png"){let o=["jpg","jpeg","webp"].includes(n)?"#fff":void 0,r=c!=null?c:o,d=yield ie(e,{dpr:t,scale:a},r),p=new Image;return p.src=d.toDataURL(`image/${n}`,s),yield p.decode(),p.style.width=`${d.width/t}px`,p.style.height=`${d.height/t}px`,p})}function ze(i){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1,backgroundColor:c,format:s="png",filename:n="snapDOM"}={}){if(s==="svg"){let u=yield Pe(e),y=URL.createObjectURL(u),w=document.createElement("a");w.href=y,w.download=`${n}.svg`,w.click(),URL.revokeObjectURL(y);return}let l=["jpg","jpeg","webp"].includes(s)?"#fff":void 0,o=c!=null?c:l,r=yield ie(e,{dpr:t,scale:a},o),d={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[s]||"image/png",p=r.toDataURL(d),m=document.createElement("a");m.href=p,m.download=`${n}.${s}`,m.click()})}function S(a){return h(this,arguments,function*(e,t={}){if(t=U({scale:1},t),!e)throw new Error("Element cannot be null or undefined");return t.iconFonts&&ve(t.iconFonts),yield S.capture(e,t)})}S.capture=(a,...c)=>h(null,[a,...c],function*(e,t={}){let s=yield Ae(e,t),n=window.devicePixelRatio||1,i=t.scale||1;return{url:s,options:t,toRaw:()=>s,toImg:()=>qe(s,{dpr:n,scale:i}),toCanvas:()=>Me(s,{dpr:n,scale:i}),toBlob:l=>Pe(s,U({dpr:n,scale:i},l)),toPng:l=>se(s,U({dpr:n,scale:i},l),"png"),toJpg:l=>se(s,U({dpr:n,scale:i},l),"jpeg"),toWebp:l=>se(s,U({dpr:n,scale:i},l),"webp"),download:({format:l="png",filename:o="capture",backgroundColor:r}={})=>ze(s,{dpr:n,scale:i,backgroundColor:r,format:l,filename:o})}});S.toRaw=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toRaw()});S.toImg=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toImg()});S.toCanvas=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toCanvas()});S.toBlob=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toBlob(t)});S.toPng=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toPng(t)});S.toJpg=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toJpg(t)});S.toWebp=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toWebp(t)});S.download=(a,...c)=>h(null,[a,...c],function*(e,t={}){let r=t,{format:s="png",filename:n="capture",backgroundColor:i}=r,l=he(r,["format","filename","backgroundColor"]);return yield(yield S.capture(e,l)).download({format:s,filename:n,backgroundColor:i})});function Le(){return h(this,arguments,function*(e=document,t={}){let{embedFonts:a=!0,reset:c=!1}=t;if(c){f.reset();return}yield document.fonts.ready,ge();let s=[],n=[];e!=null&&e.querySelectorAll&&(s=Array.from(e.querySelectorAll("img[src]")),n=Array.from(e.querySelectorAll("*")));let i=[];for(let l of s){let o=l.src;f.image.has(o)||i.push(P(o,{useProxy:t.useProxy}).then(r=>f.image.set(o,r)).catch(()=>{}))}for(let l of n){let o=N(l).backgroundImage;if(o&&o!=="none"){let r=j(o);for(let d of r)d.startsWith("url(")&&i.push(B(d,t).catch(()=>{}))}}a&&(yield G({preCached:!0})),yield Promise.all(i)})}typeof window!="undefined"&&(window.snapdom=S,window.preCache=Le);})();
|
package/dist/snapdom.min.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var l={image:new Map,background:new Map,resource:new Map,defaultStyle:new Map,baseStyle:new Map,computedStyle:new WeakMap,font:new Set,snapshot:new WeakMap,snapshotKey:new Map,preStyleMap:new Map,preStyle:new WeakMap,preNodeMap:new Map,reset:
|
|
2
|
-
`;return a}function Z(){let e=new Set(l.preStyleMap.values()),t=new Map,a=1;for(let c of e)t.set(c,`c${a++}`);return t}async function M(e,t={}){let a=B(e),c=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(a){let n=W(a);if(l.background.has(n))return t.skipInline?void 0:`url(${l.background.get(n)})`;{let o=await T(n,{useProxy:t.useProxy});return l.background.set(n,o),t.skipInline?void 0:`url("${o}")`}}return e}function P(e,{fast:t=!1}={}){if(t)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function A(e,t=null){if(!(e instanceof Element))return window.getComputedStyle(e,t);let a=l.computedStyle.get(e);if(a||(a=new Map,l.computedStyle.set(e,a)),!a.has(t)){let c=window.getComputedStyle(e,t);a.set(t,c)}return a.get(t)}function ee(e){let t=e.replace(/^['"]|['"]$/g,"");if(t.startsWith("\\"))try{return String.fromCharCode(parseInt(t.replace("\\",""),16))}catch{return t}return t}function B(e){let t=e.match(/url\((['"]?)(.*?)(\1)\)/);if(!t)return null;let a=t[2].trim();return a.startsWith("#")?null:a}function T(e,{timeout:t=3e3,useProxy:a=""}={}){function c(i){try{return new URL(i,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch{return"anonymous"}}async function n(i){let f=u=>fetch(u,{mode:"cors",credentials:c(u)==="use-credentials"?"include":"omit"}).then(d=>d.blob()).then(d=>new Promise((h,p)=>{let m=new FileReader;m.onloadend=()=>{let g=m.result;if(typeof g!="string"||!g.startsWith("data:image/")){p(new Error("Invalid image data URL"));return}h(g)},m.onerror=()=>p(new Error("FileReader error")),m.readAsDataURL(d)}));try{return await f(i)}catch{if(a&&typeof a=="string"){let d=a.replace(/\/$/,"")+W(i);try{return await f(d)}catch{throw new Error("[SnapDOM - fetchImage] CORS restrictions prevented image capture (even via proxy)")}}else throw new Error("[SnapDOM - fetchImage] Fetch fallback failed and no proxy provided")}}let o=c(e);return l.image.has(e)?Promise.resolve(l.image.get(e)):e.startsWith("data:image/")?(l.image.set(e,e),Promise.resolve(e)):/\.svg(\?.*)?$/i.test(e)?(async()=>{try{let f=await(await fetch(e,{mode:"cors",credentials:o==="use-credentials"?"include":"omit"})).text(),u=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(f)}`;return l.image.set(e,u),u}catch{return n(e)}})():new Promise((i,f)=>{let u=setTimeout(()=>{f(new Error("[SnapDOM - fetchImage] Image load timed out"))},t),d=new Image;d.crossOrigin=o,d.onload=async()=>{clearTimeout(u);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");l.image.set(e,m),i(m)}catch{try{let h=await n(e);l.image.set(e,h),i(h)}catch(h){f(h)}}},d.onerror=async()=>{clearTimeout(u),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let h=await n(e);l.image.set(e,h),i(h)}catch(h){f(h)}},d.src=e})}function q(e){let t={};for(let a of e)t[a]=e.getPropertyValue(a);return t}function j(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function te(e){if(!e||e==="none")return"";let t=e.replace(/translate[XY]?\([^)]*\)/g,"");return t=t.replace(/matrix\(([^)]+)\)/g,(a,c)=>{let n=c.split(",").map(o=>o.trim());return n.length!==6?`matrix(${c})`:(n[4]="0",n[5]="0",`matrix(${n.join(", ")})`)}),t=t.replace(/matrix3d\(([^)]+)\)/g,(a,c)=>{let n=c.split(",").map(o=>o.trim());return n.length!==16?`matrix3d(${c})`:(n[12]="0",n[13]="0",`matrix3d(${n.join(", ")})`)}),t.trim().replace(/\s{2,}/g," ")}function W(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch{return e}}function L(e){let t=[],a=0,c=0;for(let n=0;n<e.length;n++){let o=e[n];o==="("&&a++,o===")"&&a--,o===","&&a===0&&(t.push(e.slice(c,n).trim()),c=n+1)}return t.push(e.slice(c).trim()),t}function xe(e){let t={};for(let a=0;a<e.length;a++){let c=e[a],n=e.getPropertyValue(c);(c==="background-image"||c==="content")&&n.includes("url(")&&!n.includes("data:")&&(n="none"),t[c]=n}return t}function O(e,t,a){if(e.tagName==="STYLE")return;l.preStyle.has(e)||l.preStyle.set(e,A(e));let c=l.preStyle.get(e);if(!l.snapshot.has(e)){let i=xe(c);l.snapshot.set(e,i)}let n=l.snapshot.get(e),o=Object.entries(n).sort(([i],[f])=>i.localeCompare(f)).map(([i,f])=>`${i}:${f}`).join(";");if(l.snapshotKey.has(o)){l.preStyleMap.set(t,l.snapshotKey.get(o));return}let s=e.tagName?.toLowerCase()||"div",r=F(n,s,a);l.snapshotKey.set(o,r),l.preStyleMap.set(t,r)}function D(e,t,a={},c){if(!e)throw new Error("Invalid node");let n=new Set,o=null;if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let r=document.createElement("div"),i=e.getBoundingClientRect();return r.style.cssText=`display:inline-block;width:${i.width}px;height:${i.height}px;visibility:hidden;`,r}if(a.exclude&&Array.isArray(a.exclude))for(let r of a.exclude)try{if(e.matches?.(r)){let i=document.createElement("div"),f=e.getBoundingClientRect();return i.style.cssText=`display:inline-block;width:${f.width}px;height:${f.height}px;visibility:hidden;`,i}}catch(i){console.warn(`Invalid selector in exclude option: ${r}`,i)}if(typeof a.filter=="function")try{if(!a.filter(e,c||e)){let r=document.createElement("div"),i=e.getBoundingClientRect();return r.style.cssText=`display:inline-block;width:${i.width}px;height:${i.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.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);l.preNodeMap.set(r,e),O(e,r,t);let i=document.createElement("div");return i.textContent=e.getAttribute("data-placeholder-text")||"",i.style.cssText="color:#666;font-size:12px;text-align:center;line-height:1.4;padding:0.5em;box-sizing:border-box;",r.appendChild(i),r}if(e.tagName==="CANVAS"){let r=e.toDataURL(),i=document.createElement("img");return i.src=r,i.width=e.width,i.height=e.height,l.preNodeMap.set(i,e),O(e,i,t),i}let s;try{s=e.cloneNode(!1),l.preNodeMap.set(s,e)}catch(r){throw console.error("[Snapdom] Failed to clone node:",e,r),r}if(e instanceof HTMLTextAreaElement){s.textContent=e.value,s.value=e.value;let r=e.getBoundingClientRect();return s.style.width=`${r.width}px`,s.style.height=`${r.height}px`,s}if(e instanceof HTMLInputElement)return s.value=e.value,s.setAttribute("value",e.value),e.checked!==void 0&&(s.checked=e.checked,e.checked&&s.setAttribute("checked",""),e.indeterminate&&(s.indeterminate=e.indeterminate)),s;if(e instanceof HTMLSelectElement&&(o=e.value),O(e,s,t),e.shadowRoot)if(Array.from(e.shadowRoot.querySelectorAll("slot")).length>0){for(let i of e.shadowRoot.childNodes)if(i.nodeType===Node.ELEMENT_NODE&&i.tagName==="STYLE"){let f=i.textContent||"";f.trim()&&t&&(l.preStyle||(l.preStyle=new WeakMap),l.preStyle.set(i,f))}}else{let i=document.createDocumentFragment();for(let f of e.shadowRoot.childNodes){if(f.nodeType===Node.ELEMENT_NODE&&f.tagName==="STYLE"){let d=f.textContent||"";d.trim()&&t&&(l.preStyle||(l.preStyle=new WeakMap),l.preStyle.set(f,d));continue}let u=D(f,t,a,c||e);u&&i.appendChild(u)}s.appendChild(i)}if(e.tagName==="SLOT"){let r=e.assignedNodes?.({flatten:!0})||[],i=r.length>0?r:Array.from(e.childNodes),f=document.createDocumentFragment();for(let u of i){let d=D(u,t,a,c||e);d&&f.appendChild(d)}return f}for(let r of e.childNodes){if(n.has(r))continue;let i=D(r,t,a,c||e);i&&s.appendChild(i)}if(o!==null&&s instanceof HTMLSelectElement){s.value=o;for(let r of s.options)r.value===o?r.setAttribute("selected",""):r.removeAttribute("selected")}return s}var Se=[/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],z=[];function ne(e){let t=Array.isArray(e)?e:[e];for(let a of t)a instanceof RegExp?z.push(a):typeof a=="string"?z.push(new RegExp(a,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",a)}function $(e){let t=typeof e=="string"?e:"",a=[...Se,...z];for(let c of a)if(c instanceof RegExp&&c.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))}async function oe(e,t,a,c=32,n="#000"){t=t.replace(/^['"]+|['"]+$/g,"");let o=window.devicePixelRatio||1,r=document.createElement("canvas").getContext("2d");r.font=a?`${a} ${c}px "${t}"`:`${c}px "${t}"`;let i=r.measureText(e),f=i.actualBoundingBoxAscent||c*.8,u=i.actualBoundingBoxDescent||c*.2,d=f+u,h=i.width,p=document.createElement("canvas");p.width=Math.ceil(h*o),p.height=Math.ceil(d*o);let m=p.getContext("2d");return m.scale(o,o),m.font=r.font,m.textAlign="left",m.textBaseline="alphabetic",m.fillStyle=n,m.fillText(e,0,f),p.toDataURL()}function ae(e){return Array.from(document.styleSheets).some(t=>t.href===e)}function be(e){return new Promise(t=>{if(ae(e))return t(null);let a=document.createElement("link");a.rel="stylesheet",a.href=e,a.setAttribute("data-snapdom","injected-import"),a.onload=()=>t(a),a.onerror=()=>t(null),document.head.appendChild(a)})}async function V({preCached:e=!1}={}){if(l.resource.has("fonts-embed-css")){if(e){let o=document.createElement("style");o.setAttribute("data-snapdom","embedFonts"),o.textContent=l.resource.get("fonts-embed-css"),document.head.appendChild(o)}return l.resource.get("fonts-embed-css")}let t=/@import\s+url\(["']?([^"')]+)["']?\)/g,a=[];for(let o of document.querySelectorAll("style")){let s=o.textContent||"",r=Array.from(s.matchAll(t));for(let i of r){let f=i[1];$(f)||ae(f)||a.push(f)}}await Promise.all(a.map(be));let c=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(o=>o.href),n="";for(let o of c)try{let r=await(await fetch(o.href)).text();if($(o.href)||$(r))continue;let i=/url\((["']?)([^"')]+)\1\)/g,f=await Promise.all(Array.from(r.matchAll(i)).map(async d=>{let h=B(d[0]);if(!h)return null;let p=h;if(!p.startsWith("http")&&!p.startsWith("data:")&&(p=new URL(p,o.href).href),$(p))return null;if(l.resource.has(p))return l.font.add(p),{original:d[0],inlined:`url(${l.resource.get(p)})`};if(l.font.has(p))return null;try{let g=await(await fetch(p)).blob(),w=await new Promise(y=>{let E=new FileReader;E.onload=()=>y(E.result),E.readAsDataURL(g)});return l.resource.set(p,w),l.font.add(p),{original:d[0],inlined:`url(${w})`}}catch{return console.warn("[snapdom] Failed to fetch font resource:",p),null}})),u=r;for(let d of f)d&&(u=u.replace(d.original,d.inlined));n+=u+`
|
|
3
|
-
`}catch{console.warn("[snapdom] Failed to fetch CSS:",o.href)}for(let o of document.styleSheets)try{if(!o.href||c.every(s=>s.href!==o.href)){for(let s of o.cssRules)if(s.type===CSSRule.FONT_FACE_RULE){let r=s.style.getPropertyValue("src"),i=s.style.getPropertyValue("font-family");if(!r||$(i))continue;let f=/url\((["']?)([^"')]+)\1\)/g,u=/local\((["']?)[^)]+?\1\)/g,d=f.test(r),h=u.test(r);if(!d&&h){n+=`@font-face{font-family:${i};src:${r};font-style:${s.style.getPropertyValue("font-style")||"normal"};font-weight:${s.style.getPropertyValue("font-weight")||"normal"};}`;continue}let p=r,m=Array.from(r.matchAll(f));for(let g of m){let w=g[2].trim();if(!w)continue;let y=w;if(!y.startsWith("http")&&!y.startsWith("data:")&&(y=new URL(y,o.href||location.href).href),!$(y)){if(l.resource.has(y)){l.font.add(y),p=p.replace(g[0],`url(${l.resource.get(y)})`);continue}if(!l.font.has(y))try{let x=await(await fetch(y)).blob(),k=await new Promise(I=>{let b=new FileReader;b.onload=()=>I(b.result),b.readAsDataURL(x)});l.resource.set(y,k),l.font.add(y),p=p.replace(g[0],`url(${k})`)}catch{console.warn("[snapdom] Failed to fetch font URL:",y)}}}n+=`@font-face{font-family:${i};src:${p};font-style:${s.style.getPropertyValue("font-style")||"normal"};font-weight:${s.style.getPropertyValue("font-weight")||"normal"};}`}}}catch(s){console.warn("[snapdom] Cannot access stylesheet",o.href,s)}for(let o of document.fonts)if(o.family&&o.status==="loaded"&&o._snapdomSrc){if($(o.family))continue;let s=o._snapdomSrc;if(!s.startsWith("data:")){if(l.resource.has(o._snapdomSrc))s=l.resource.get(o._snapdomSrc),l.font.add(o._snapdomSrc);else if(!l.font.has(o._snapdomSrc))try{let i=await(await fetch(o._snapdomSrc)).blob();s=await new Promise(f=>{let u=new FileReader;u.onload=()=>f(u.result),u.readAsDataURL(i)}),l.resource.set(o._snapdomSrc,s),l.font.add(o._snapdomSrc)}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",o._snapdomSrc);continue}}n+=`@font-face{font-family:'${o.family}';src:url(${s});font-style:${o.style||"normal"};font-weight:${o.weight||"normal"};}`}if(n&&(l.resource.set("fonts-embed-css",n),e)){let o=document.createElement("style");o.setAttribute("data-snapdom","embedFonts"),o.textContent=n,document.head.appendChild(o)}return n}async function H(e,t,a,c=!1,n){if(!(e instanceof Element)||!(t instanceof Element))return;for(let r of["::before","::after","::first-letter"])try{let i=A(e,r);if(!i||typeof i[Symbol.iterator]!="function")continue;if(r==="::first-letter"){let g=getComputedStyle(e);if(!(i.color!==g.color||i.fontSize!==g.fontSize||i.fontWeight!==g.fontWeight))continue;let y=Array.from(t.childNodes).find(C=>C.nodeType===Node.TEXT_NODE&&C.textContent&&C.textContent.trim().length>0);if(!y)continue;let E=y.textContent,k=E.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],I=E.slice(k?.length||0);if(!k||/[\uD800-\uDFFF]/.test(k))continue;let b=document.createElement("span");b.textContent=k,b.dataset.snapdomPseudo="::first-letter";let v=q(i),_=F(v,"span",a);l.preStyleMap.set(b,_);let U=document.createTextNode(I);t.replaceChild(U,y),t.insertBefore(b,U);continue}let f=i.getPropertyValue("content"),u=i.getPropertyValue("background-image"),d=i.getPropertyValue("background-color"),h=f!=="none",p=u&&u!=="none",m=d&&d!=="transparent"&&d!=="rgba(0, 0, 0, 0)";if(h||p||m){let g=i.getPropertyValue("font-family"),w=parseInt(i.getPropertyValue("font-size"))||32,y=parseInt(i.getPropertyValue("font-weight"))||!1,E=i.getPropertyValue("color")||"#000",x=document.createElement("span");x.dataset.snapdomPseudo=r;let k=q(i),I=F(k,"span",a);l.preStyleMap.set(x,I);let b=$(g),v;if(/counter\s*\(|counters\s*\(/.test(f)?v="- ":v=ee(f),b&&v.length===1){let C=document.createElement("img");C.src=await oe(v,g,y,w,E),C.style=`width:${w}px;height:auto;object-fit:contain;`,x.appendChild(C)}else if(v.startsWith("url(")){let C=B(v);if(C&&C.trim()!=="")try{let N=document.createElement("img"),R=await T(W(C,{useProxy:n}));N.src=R,N.style=`width:${w}px;height:auto;object-fit:contain;`,x.appendChild(N)}catch(N){console.error(`[snapdom] Error in pseudo ${r} for`,e,N)}}else!b&&v&&v!=="none"&&(x.textContent=v);if(p)try{let C=L(u),N=await Promise.all(C.map(R=>M(R)));x.style.backgroundImage=N.join(", ")}catch(C){console.warn(`[snapdom] Failed to inline background-image for ${r}`,C)}if(m&&(x.style.backgroundColor=d),!(x.childNodes.length>0||x.textContent&&x.textContent.trim()!==""||p||m))continue;r==="::before"?t.insertBefore(x,t.firstChild):t.appendChild(x)}}catch(i){console.warn(`[snapdom] Failed to capture ${r} for`,e,i)}let o=Array.from(e.children),s=Array.from(t.children).filter(r=>!r.dataset.snapdomPseudo);for(let r=0;r<Math.min(o.length,s.length);r++)await H(o[r],s[r],a,c,n)}function re(e){if(!e)return;let t=document.querySelectorAll("svg > defs");t.length&&e.querySelectorAll("svg").forEach(a=>{let c=a.querySelectorAll("use");if(!c.length)return;let n=new Set;if(c.forEach(s=>{let r=s.getAttribute("xlink:href")||s.getAttribute("href");r&&r.startsWith("#")&&n.add(r.slice(1))}),!n.size)return;let o=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let s of n)for(let r of t){let i=r.querySelector(`#${CSS.escape(s)}`);if(i){o.appendChild(i.cloneNode(!0));break}}o.childNodes.length&&a.insertBefore(o,a.firstChild)})}async function se(e,t=!1,a=!1,c={}){let n,o="";try{n=D(e,t,c,e)}catch(s){throw console.warn("deepClone failed:",s),s}try{await H(e,n,t,a,c.useProxy)}catch(s){console.warn("inlinePseudoElements failed:",s)}try{re(n)}catch(s){console.warn("inlineExternalDef failed:",s)}if(t){let s=Z();o=Array.from(s.entries()).map(([r,i])=>`.${i}{${r}}`).join("");for(let[r,i]of l.preStyleMap.entries()){if(r.tagName==="STYLE")continue;let f=s.get(i);f&&r.classList.add(f);let u=r.style?.backgroundImage;r.removeAttribute("style"),u&&u!=="none"&&(r.style.backgroundImage=u)}}else for(let[s,r]of l.preStyleMap.entries())s.tagName!=="STYLE"&&s.setAttribute("style",r.replace(/;/g,"; "));for(let[s,r]of l.preNodeMap.entries()){let i=r.scrollLeft,f=r.scrollTop;if((i||f)&&s instanceof HTMLElement){s.style.overflow="hidden",s.style.scrollbarWidth="none",s.style.msOverflowStyle="none";let d=document.createElement("div");for(d.style.transform=`translate(${-i}px, ${-f}px)`,d.style.willChange="transform",d.style.display="inline-block",d.style.width="100%";s.firstChild;)d.appendChild(s.firstChild);s.appendChild(d)}}if(e===l.preNodeMap.get(n)){let s=l.preStyle.get(e)||window.getComputedStyle(e);l.preStyle.set(e,s);let r=te(s.transform);n.style.margin="0",n.style.position="static",n.style.top="auto",n.style.left="auto",n.style.right="auto",n.style.bottom="auto",n.style.zIndex="auto",n.style.float="none",n.style.clear="none",n.style.transform=r||""}for(let[s,r]of l.preNodeMap.entries())r.tagName==="PRE"&&(s.style.marginTop="0",s.style.marginBlockStart="0");return{clone:n,classCSS:o}}async function ie(e,t={}){let a=Array.from(e.querySelectorAll("img")),c=async n=>{let o=n.src;try{let s=await T(o,{useProxy:t.useProxy});n.src=s,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch{let s=document.createElement("div");s.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;`,s.innerText="img",n.replaceWith(s)}};for(let n=0;n<a.length;n+=4){let o=a.slice(n,n+4).map(c);await Promise.allSettled(o)}}async function ce(e,t,a={}){let c=[[e,t]],n=["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[o,s]=c.shift(),r=l.preStyle.get(o)||A(o);l.preStyle.has(o)||l.preStyle.set(o,r);for(let d of n){let h=r.getPropertyValue(d);if(!h||h==="none")continue;let p=L(h),m=await Promise.all(p.map(g=>M(g,a)));m.some(g=>g&&g!=="none"&&!/^url\(undefined/.test(g))&&s.style.setProperty(d,m.join(", "))}let i=r.getPropertyValue("background-color");i&&i!=="transparent"&&i!=="rgba(0, 0, 0, 0)"&&(s.style.backgroundColor=i);let f=Array.from(o.children),u=Array.from(s.children);for(let d=0;d<Math.min(f.length,u.length);d++)c.push([f[d],u[d]])}}async function le(e,t={}){if(!e)throw new Error("Element cannot be null or undefined");l.reset();let{compress:a=!0,embedFonts:c=!1,fast:n=!0,scale:o=1,useProxy:s=""}=t,r,i,f="",u="",d,h;if({clone:r,classCSS:i}=await se(e,a,c,t),await new Promise(m=>{P(async()=>{await ie(r,t),m()},{fast:n})}),await new Promise(m=>{P(async()=>{await ce(e,r,t),m()},{fast:n})}),c&&await new Promise(m=>{P(async()=>{f=await V(),m()},{fast:n})}),a){let m=J(r).sort(),g=m.join(",");l.baseStyle.has(g)?u=l.baseStyle.get(g):await new Promise(w=>{P(()=>{u=Q(m),l.baseStyle.set(g,u),w()},{fast:n})})}await new Promise(m=>{P(()=>{let g=e.getBoundingClientRect(),w=g.width,y=g.height,E=Number.isFinite(t.width),x=Number.isFinite(t.height),k=typeof o=="number"&&o!==1;if(!k){let R=g.width/g.height;E&&x?(w=t.width,y=t.height):E?(w=t.width,y=w/R):x&&(y=t.height,w=y*R)}if(w=Math.ceil(w),y=Math.ceil(y),r.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),r.style.transformOrigin="top left",!k&&(E||x)){let R=g.width,ue=g.height,pe=w/R,me=y/ue,he=r.style.transform||"",ge=`scale(${pe}, ${me})`;r.style.transform=`${ge} ${he}`.trim()}else k&&j()&&(r.style.scale=`${o}`);let I="http://www.w3.org/2000/svg",b=document.createElementNS(I,"foreignObject");b.setAttribute("width","100%"),b.setAttribute("height","100%");let v=document.createElement("style");v.textContent=u+f+"svg{overflow:visible;}"+i,b.appendChild(v),b.appendChild(r);let U=new XMLSerializer().serializeToString(b);h=`<svg xmlns="${I}" width="${w}" height="${y}" viewBox="0 0 ${w} ${y}">`+U+"</svg>",d=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(h)}`,m()},{fast:n})});let p=document.getElementById("snapdom-sandbox");return p&&p.style.position==="absolute"&&p.remove(),d}async function Ce(e,{dpr:t=1,scale:a=1}){let c=new Image;return c.src=e,await c.decode(),j?(c.width=c.width*a,c.height=c.height*a):(c.width=c.width/a,c.height=c.height/a),c}async function fe(e,{dpr:t=1,scale:a=1}={}){let c=new Image;c.src=e,await c.decode();let n=document.createElement("canvas"),o=c.width*a,s=c.height*a;n.width=Math.ceil(o*t),n.height=Math.ceil(s*t);let r=n.getContext("2d");return r.scale(t,t),r.drawImage(c,0,0,o,s),n.style.width=`${o}px`,n.style.height=`${s}px`,n}async function de(e,{type:t="svg",scale:a=1,backgroundColor:c="#fff",quality:n}={}){let o={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[t]||"image/png";if(t==="svg"){let r=decodeURIComponent(e.split(",")[1]);return new Blob([r],{type:"image/svg+xml"})}let s=await Y(e,{dpr:1,scale:a},c);return new Promise(r=>{s.toBlob(i=>r(i),`${o}`,n)})}async function Y(e,{dpr:t=1,scale:a=1},c){let n=await fe(e,{dpr:t,scale:a});if(!c)return n;let o=document.createElement("canvas");o.width=n.width,o.height=n.height;let s=o.getContext("2d");return s.fillStyle=c,s.fillRect(0,0,o.width,o.height),s.drawImage(n,0,0),o}async function K(e,{dpr:t=1,scale:a=1,backgroundColor:c,quality:n},o="png"){let s=["jpg","jpeg","webp"].includes(o)?"#fff":void 0,i=await Y(e,{dpr:t,scale:a},c??s),f=new Image;return f.src=i.toDataURL(`image/${o}`,n),await f.decode(),f.style.width=`${i.width/t}px`,f.style.height=`${i.height/t}px`,f}async function Ee(e,{dpr:t=1,scale:a=1,backgroundColor:c="#fff",format:n="png",filename:o="capture"}={}){if(n==="svg"){let h=await de(e),p=URL.createObjectURL(h),m=document.createElement("a");m.href=p,m.download=`${o}.svg`,m.click(),URL.revokeObjectURL(p);return}let s=["jpg","jpeg","webp"].includes(n)?"#fff":void 0,i=await Y(e,{dpr:t,scale:a},c??s),f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[n]||"image/png",u=i.toDataURL(f),d=document.createElement("a");d.href=u,d.download=`${o}.${n}`,d.click()}async function S(e,t={}){if(t={scale:1,...t},!e)throw new Error("Element cannot be null or undefined");return t.iconFonts&&ne(t.iconFonts),await S.capture(e,t)}S.capture=async(e,t={})=>{let a=await le(e,t),c=window.devicePixelRatio||1,n=t.scale||1;return{url:a,options:t,toRaw:()=>a,toImg:()=>Ce(a,{dpr:c,scale:n}),toCanvas:()=>fe(a,{dpr:c,scale:n}),toBlob:o=>de(a,{dpr:c,scale:n,...o}),toPng:o=>K(a,{dpr:c,scale:n,...o},"png"),toJpg:o=>K(a,{dpr:c,scale:n,...o},"jpeg"),toWebp:o=>K(a,{dpr:c,scale:n,...o},"webp"),download:({format:o="png",filename:s="capture",backgroundColor:r}={})=>Ee(a,{dpr:c,scale:n,backgroundColor:r,format:o,filename:s})}};S.toRaw=async(e,t)=>(await S.capture(e,t)).toRaw();S.toImg=async(e,t)=>(await S.capture(e,t)).toImg();S.toCanvas=async(e,t)=>(await S.capture(e,t)).toCanvas();S.toBlob=async(e,t)=>(await S.capture(e,t)).toBlob(t);S.toPng=async(e,t)=>(await S.capture(e,t)).toPng(t);S.toJpg=async(e,t)=>(await S.capture(e,t)).toJpg(t);S.toWebp=async(e,t)=>(await S.capture(e,t)).toWebp(t);S.download=async(e,t={})=>{let{format:a="png",filename:c="capture",backgroundColor:n,...o}=t;return await(await S.capture(e,o)).download({format:a,filename:c,backgroundColor:n})};async function ve(e=document,t={}){let{embedFonts:a=!0,reset:c=!1}=t;if(c){l.reset();return}await document.fonts.ready,X();let n=[],o=[];e?.querySelectorAll&&(n=Array.from(e.querySelectorAll("img[src]")),o=Array.from(e.querySelectorAll("*")));let s=[];for(let r of n){let i=r.src;l.image.has(i)||s.push(T(i,{useProxy:t.useProxy}).then(f=>l.image.set(i,f)).catch(()=>{}))}for(let r of o){let i=A(r).backgroundImage;if(i&&i!=="none"){let f=L(i);for(let u of f)u.startsWith("url(")&&s.push(M(u,t).catch(()=>{}))}}a&&await V({preCached:!0}),await Promise.all(s)}export{ve as preCache,S as snapdom};
|
|
1
|
+
var l={image:new Map,background:new Map,resource:new Map,defaultStyle:new Map,baseStyle:new Map,computedStyle:new WeakMap,font:new Set,snapshot:new WeakMap,snapshotKey:new Map,preStyleMap:new Map,preStyle:new WeakMap,preNodeMap:new Map,reset:Re};function Re(){l.computedStyle=new WeakMap,l.snapshot=new WeakMap,l.snapshotKey.clear(),l.preStyleMap.clear(),l.preStyle=new WeakMap,l.preNodeMap.clear()}var Ne=["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 ie(){for(let e of Ne)ce(e)}function ce(e){if(l.defaultStyle.has(e))return l.defaultStyle.get(e);if(new Set(["script","style","meta","link","noscript","template"]).has(e)){let i={};return l.defaultStyle.set(e,i),i}let r=document.getElementById("snapdom-sandbox");r||(r=document.createElement("div"),r.id="snapdom-sandbox",r.style.position="absolute",r.style.left="-9999px",r.style.top="-9999px",r.style.width="0",r.style.height="0",r.style.overflow="hidden",document.body.appendChild(r));let c=document.createElement(e);c.style.all="initial",r.appendChild(c);let o=getComputedStyle(c),n={};for(let i of o)n[i]=o.getPropertyValue(i);return r.removeChild(c),l.defaultStyle.set(e,n),n}function U(e,t,r=!1){let c=[],o=ce(t);for(let[n,i]of Object.entries(e))if(!r)i&&c.push(`${n}:${i}`);else{let a=o[n];i&&i!==a&&c.push(`${n}:${i}`)}return c.sort().join(";")}function le(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(r=>t.add(r.tagName.toLowerCase())),Array.from(t))}function fe(e){let t=new Map;for(let c of e){let o=l.defaultStyle.get(c);if(!o)continue;let n=Object.entries(o).map(([i,a])=>`${i}:${a};`).sort().join("");t.has(n)||t.set(n,[]),t.get(n).push(c)}let r="";for(let[c,o]of t.entries())r+=`${o.join(",")} { ${c} }
|
|
2
|
+
`;return r}function de(){let e=new Set(l.preStyleMap.values()),t=new Map,r=1;for(let c of e)t.set(c,`c${r++}`);return t}async function P(e,t={}){let r=D(e),c=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(r){let o=q(r);if(l.background.has(o))return t.skipInline?void 0:`url(${l.background.get(o)})`;{let n=await M(o,{useProxy:t.useProxy});return l.background.set(o,n),t.skipInline?void 0:`url("${n}")`}}return e}function L(e,{fast:t=!1}={}){if(t)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function R(e,t=null){if(!(e instanceof Element))return window.getComputedStyle(e,t);let r=l.computedStyle.get(e);if(r||(r=new Map,l.computedStyle.set(e,r)),!r.has(t)){let c=window.getComputedStyle(e,t);r.set(t,c)}return r.get(t)}function ue(e){let t=e.replace(/^['"]|['"]$/g,"");if(t.startsWith("\\"))try{return String.fromCharCode(parseInt(t.replace("\\",""),16))}catch{return t}return t}function D(e){let t=e.match(/url\((['"]?)(.*?)(\1)\)/);if(!t)return null;let r=t[2].trim();return r.startsWith("#")?null:r}function M(e,{timeout:t=3e3,useProxy:r=""}={}){function c(s){try{return new URL(s,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch{return"anonymous"}}async function o(s){let f=u=>fetch(u,{mode:"cors",credentials:c(u)==="use-credentials"?"include":"omit"}).then(d=>d.blob()).then(d=>new Promise((h,p)=>{let m=new FileReader;m.onloadend=()=>{let g=m.result;if(typeof g!="string"||!g.startsWith("data:image/")){p(new Error("Invalid image data URL"));return}h(g)},m.onerror=()=>p(new Error("FileReader error")),m.readAsDataURL(d)}));try{return await f(s)}catch{if(r&&typeof r=="string"){let d=r.replace(/\/$/,"")+q(s);try{return await f(d)}catch{throw new Error("[SnapDOM - fetchImage] CORS restrictions prevented image capture (even via proxy)")}}else throw new Error("[SnapDOM - fetchImage] Fetch fallback failed and no proxy provided")}}let n=c(e);return l.image.has(e)?Promise.resolve(l.image.get(e)):e.startsWith("data:image/")?(l.image.set(e,e),Promise.resolve(e)):/\.svg(\?.*)?$/i.test(e)?(async()=>{try{let f=await(await fetch(e,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),u=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(f)}`;return l.image.set(e,u),u}catch{return o(e)}})():new Promise((s,f)=>{let u=setTimeout(()=>{f(new Error("[SnapDOM - fetchImage] Image load timed out"))},t),d=new Image;d.crossOrigin=n,d.onload=async()=>{clearTimeout(u);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");l.image.set(e,m),s(m)}catch{try{let h=await o(e);l.image.set(e,h),s(h)}catch(h){f(h)}}},d.onerror=async()=>{clearTimeout(u),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let h=await o(e);l.image.set(e,h),s(h)}catch(h){f(h)}},d.src=e})}function Z(e){let t={};for(let r of e)t[r]=e.getPropertyValue(r);return t}function pe(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function me(e){if(!e||e==="none")return"";let t=e.replace(/translate[XY]?\([^)]*\)/g,"");return t=t.replace(/matrix\(([^)]+)\)/g,(r,c)=>{let o=c.split(",").map(n=>n.trim());return o.length!==6?`matrix(${c})`:(o[4]="0",o[5]="0",`matrix(${o.join(", ")})`)}),t=t.replace(/matrix3d\(([^)]+)\)/g,(r,c)=>{let o=c.split(",").map(n=>n.trim());return o.length!==16?`matrix3d(${c})`:(o[12]="0",o[13]="0",`matrix3d(${o.join(", ")})`)}),t.trim().replace(/\s{2,}/g," ")}function q(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch{return e}}function F(e){let t=[],r=0,c=0;for(let o=0;o<e.length;o++){let n=e[o];n==="("&&r++,n===")"&&r--,n===","&&r===0&&(t.push(e.slice(c,o).trim()),c=o+1)}return t.push(e.slice(c).trim()),t}function Te(e){let t={};for(let r=0;r<e.length;r++){let c=e[r],o=e.getPropertyValue(c);(c==="background-image"||c==="content")&&o.includes("url(")&&!o.includes("data:")&&(o="none"),t[c]=o}return t}function z(e,t,r){if(e.tagName==="STYLE")return;l.preStyle.has(e)||l.preStyle.set(e,R(e));let c=l.preStyle.get(e);if(!l.snapshot.has(e)){let s=Te(c);l.snapshot.set(e,s)}let o=l.snapshot.get(e),n=Object.entries(o).sort(([s],[f])=>s.localeCompare(f)).map(([s,f])=>`${s}:${f}`).join(";");if(l.snapshotKey.has(n)){l.preStyleMap.set(t,l.snapshotKey.get(n));return}let i=e.tagName?.toLowerCase()||"div",a=U(o,i,r);l.snapshotKey.set(n,a),l.preStyleMap.set(t,a)}function j(e,t,r={},c){if(!e)throw new Error("Invalid node");let o=new Set,n=null;if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let a=document.createElement("div"),s=e.getBoundingClientRect();return a.style.cssText=`display:inline-block;width:${s.width}px;height:${s.height}px;visibility:hidden;`,a}if(r.exclude&&Array.isArray(r.exclude))for(let a of r.exclude)try{if(e.matches?.(a)){let s=document.createElement("div"),f=e.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: ${a}`,s)}if(typeof r.filter=="function")try{if(!r.filter(e,c||e)){let a=document.createElement("div"),s=e.getBoundingClientRect();return a.style.cssText=`display:inline-block;width:${s.width}px;height:${s.height}px;visibility:hidden;`,a}}catch(a){console.warn("Error in filter function:",a)}if(e.tagName==="IFRAME"){let a=document.createElement("div");return a.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;`,a}if(e.getAttribute("data-capture")==="placeholder"){let a=e.cloneNode(!1);l.preNodeMap.set(a,e),z(e,a,t);let s=document.createElement("div");return s.textContent=e.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;",a.appendChild(s),a}if(e.tagName==="CANVAS"){let a=e.toDataURL(),s=document.createElement("img");return s.src=a,s.width=e.width,s.height=e.height,l.preNodeMap.set(s,e),z(e,s,t),s}let i;try{i=e.cloneNode(!1),l.preNodeMap.set(i,e)}catch(a){throw console.error("[Snapdom] Failed to clone node:",e,a),a}if(e instanceof HTMLTextAreaElement){i.textContent=e.value,i.value=e.value;let a=e.getBoundingClientRect();return i.style.width=`${a.width}px`,i.style.height=`${a.height}px`,i}if(e instanceof HTMLInputElement&&(i.value=e.value,i.setAttribute("value",e.value),e.checked!==void 0&&(i.checked=e.checked,e.checked&&i.setAttribute("checked",""),e.indeterminate&&(i.indeterminate=e.indeterminate))),e instanceof HTMLSelectElement&&(n=e.value),z(e,i,t),e.shadowRoot)if(Array.from(e.shadowRoot.querySelectorAll("slot")).length>0){for(let s of e.shadowRoot.childNodes)if(s.nodeType===Node.ELEMENT_NODE&&s.tagName==="STYLE"){let f=s.textContent||"";f.trim()&&t&&(l.preStyle||(l.preStyle=new WeakMap),l.preStyle.set(s,f))}}else{let s=document.createDocumentFragment();for(let f of e.shadowRoot.childNodes){if(f.nodeType===Node.ELEMENT_NODE&&f.tagName==="STYLE"){let d=f.textContent||"";d.trim()&&t&&(l.preStyle||(l.preStyle=new WeakMap),l.preStyle.set(f,d));continue}let u=j(f,t,r,c||e);u&&s.appendChild(u)}i.appendChild(s)}if(e.tagName==="SLOT"){let a=e.assignedNodes?.({flatten:!0})||[],s=a.length>0?a:Array.from(e.childNodes),f=document.createDocumentFragment();for(let u of s){let d=j(u,t,r,c||e);d&&f.appendChild(d)}return f}for(let a of e.childNodes){if(o.has(a))continue;let s=j(a,t,r,c||e);s&&i.appendChild(s)}if(n!==null&&i instanceof HTMLSelectElement){i.value=n;for(let a of i.options)a.value===n?a.setAttribute("selected",""):a.removeAttribute("selected")}return i}var Ae=[/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],ee=[];function he(e){let t=Array.isArray(e)?e:[e];for(let r of t)r instanceof RegExp?ee.push(r):typeof r=="string"?ee.push(new RegExp(r,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",r)}function v(e){let t=typeof e=="string"?e:"",r=[...Ae,...ee];for(let c of r)if(c instanceof RegExp&&c.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))}async function ge(e,t,r,c=32,o="#000"){t=t.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,a=document.createElement("canvas").getContext("2d");a.font=r?`${r} ${c}px "${t}"`:`${c}px "${t}"`;let s=a.measureText(e),f=s.actualBoundingBoxAscent||c*.8,u=s.actualBoundingBoxDescent||c*.2,d=f+u,h=s.width,p=document.createElement("canvas");p.width=Math.ceil(h*n),p.height=Math.ceil(d*n);let m=p.getContext("2d");return m.scale(n,n),m.font=a.font,m.textAlign="left",m.textBaseline="alphabetic",m.fillStyle=o,m.fillText(e,0,f),p.toDataURL()}function ye(e){return Array.from(document.styleSheets).some(t=>t.href===e)}function Me(e){return new Promise(t=>{if(ye(e))return t(null);let r=document.createElement("link");r.rel="stylesheet",r.href=e,r.setAttribute("data-snapdom","injected-import"),r.onload=()=>t(r),r.onerror=()=>t(null),document.head.appendChild(r)})}async function H({preCached:e=!1}={}){if(l.resource.has("fonts-embed-css")){if(e){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=l.resource.get("fonts-embed-css"),document.head.appendChild(n)}return l.resource.get("fonts-embed-css")}let t=/@import\s+url\(["']?([^"')]+)["']?\)/g,r=[];for(let n of document.querySelectorAll("style")){let i=n.textContent||"",a=Array.from(i.matchAll(t));for(let s of a){let f=s[1];v(f)||ye(f)||r.push(f)}}await Promise.all(r.map(Me));let c=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),o="";for(let n of c)try{let a=await(await fetch(n.href)).text();if(v(n.href)||v(a))continue;let s=/url\((["']?)([^"')]+)\1\)/g,f=await Promise.all(Array.from(a.matchAll(s)).map(async d=>{let h=D(d[0]);if(!h)return null;let p=h;if(!p.startsWith("http")&&!p.startsWith("data:")&&(p=new URL(p,n.href).href),v(p))return null;if(l.resource.has(p))return l.font.add(p),{original:d[0],inlined:`url(${l.resource.get(p)})`};if(l.font.has(p))return null;try{let g=await(await fetch(p)).blob(),w=await new Promise(y=>{let E=new FileReader;E.onload=()=>y(E.result),E.readAsDataURL(g)});return l.resource.set(p,w),l.font.add(p),{original:d[0],inlined:`url(${w})`}}catch{return console.warn("[snapdom] Failed to fetch font resource:",p),null}})),u=a;for(let d of f)d&&(u=u.replace(d.original,d.inlined));o+=u+`
|
|
3
|
+
`}catch{console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||c.every(i=>i.href!==n.href)){for(let i of n.cssRules)if(i.type===CSSRule.FONT_FACE_RULE){let a=i.style.getPropertyValue("src"),s=i.style.getPropertyValue("font-family");if(!a||v(s))continue;let f=/url\((["']?)([^"')]+)\1\)/g,u=/local\((["']?)[^)]+?\1\)/g,d=!!a.match(f),h=!!a.match(u);if(!d&&h){o+=`@font-face{font-family:${s};src:${a};font-style:${i.style.getPropertyValue("font-style")||"normal"};font-weight:${i.style.getPropertyValue("font-weight")||"normal"};}`;continue}let p=a,m=Array.from(a.matchAll(f));for(let g of m){let w=g[2].trim();if(!w)continue;let y=w;if(!y.startsWith("http")&&!y.startsWith("data:")&&(y=new URL(y,n.href||location.href).href),!v(y)){if(l.resource.has(y)){l.font.add(y),p=p.replace(g[0],`url(${l.resource.get(y)})`);continue}if(!l.font.has(y))try{let k=await(await fetch(y)).blob(),$=await new Promise(N=>{let S=new FileReader;S.onload=()=>N(S.result),S.readAsDataURL(k)});l.resource.set(y,$),l.font.add(y),p=p.replace(g[0],`url(${$})`)}catch{console.warn("[snapdom] Failed to fetch font URL:",y)}}}o+=`@font-face{font-family:${s};src:${p};font-style:${i.style.getPropertyValue("font-style")||"normal"};font-weight:${i.style.getPropertyValue("font-weight")||"normal"};}`}}}catch(i){console.warn("[snapdom] Cannot access stylesheet",n.href,i)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(v(n.family))continue;let i=n._snapdomSrc;if(!i.startsWith("data:")){if(l.resource.has(n._snapdomSrc))i=l.resource.get(n._snapdomSrc),l.font.add(n._snapdomSrc);else if(!l.font.has(n._snapdomSrc))try{let s=await(await fetch(n._snapdomSrc)).blob();i=await new Promise(f=>{let u=new FileReader;u.onload=()=>f(u.result),u.readAsDataURL(s)}),l.resource.set(n._snapdomSrc,i),l.font.add(n._snapdomSrc)}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}o+=`@font-face{font-family:'${n.family}';src:url(${i});font-style:${n.style||"normal"};font-weight:${n.weight||"normal"};}`}if(o&&(l.resource.set("fonts-embed-css",o),e)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=o,document.head.appendChild(n)}return o}async function te(e,t,r,c=!1,o){if(!(e instanceof Element)||!(t instanceof Element))return;for(let a of["::before","::after","::first-letter"])try{let s=R(e,a);if(!s||typeof s[Symbol.iterator]!="function")continue;if(a==="::first-letter"){let b=getComputedStyle(e);if(!(s.color!==b.color||s.fontSize!==b.fontSize||s.fontWeight!==b.fontWeight))continue;let A=Array.from(t.childNodes).find(Q=>Q.nodeType===Node.TEXT_NODE&&Q.textContent&&Q.textContent.trim().length>0);if(!A)continue;let re=A.textContent,O=re.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],ke=re.slice(O?.length||0);if(!O||/[\uD800-\uDFFF]/.test(O))continue;let _=document.createElement("span");_.textContent=O,_.dataset.snapdomPseudo="::first-letter";let $e=Z(s),Ie=U($e,"span",r);l.preStyleMap.set(_,Ie);let se=document.createTextNode(ke);t.replaceChild(se,A),t.insertBefore(_,se);continue}let f=s.getPropertyValue("content"),u=s.getPropertyValue("background-image"),d=s.getPropertyValue("background-color"),h=s.getPropertyValue("font-family"),p=parseInt(s.getPropertyValue("font-size"))||32,m=parseInt(s.getPropertyValue("font-weight"))||!1,g=s.getPropertyValue("color")||"#000",w=s.getPropertyValue("display"),y=parseFloat(s.getPropertyValue("width")),E=parseFloat(s.getPropertyValue("height")),k=s.getPropertyValue("border-style"),$=s.getPropertyValue("transform"),N=v(h),S;/counter\s*\(|counters\s*\(/.test(f)?S="- ":S=ue(f);let Y=f!=="none"&&S!=="",B=u&&u!=="none",W=d&&d!=="transparent"&&d!=="rgba(0, 0, 0, 0)",X=w!=="inline"&&(y>0||E>0),T=k&&k!=="none",V=$&&$!=="none";if(!(Y||B||W||X||T||V))continue;let C=document.createElement("span");C.dataset.snapdomPseudo=a;let G=Z(s),J=U(G,"span",r);if(l.preStyleMap.set(C,J),N&&S.length===1){let b=document.createElement("img");b.src=await ge(S,h,m,p,g),b.style=`width:${p}px;height:auto;object-fit:contain;`,C.appendChild(b)}else if(S.startsWith("url(")){let b=D(S);if(b&&b.trim()!=="")try{let I=document.createElement("img"),A=await M(q(b,{useProxy:o}));I.src=A,I.style=`width:${p}px;height:auto;object-fit:contain;`,C.appendChild(I)}catch(I){console.error(`[snapdom] Error in pseudo ${a} for`,e,I)}}else!N&&Y&&(C.textContent=S);if(B)try{let b=F(u),I=await Promise.all(b.map(A=>P(A)));C.style.backgroundImage=I.join(", ")}catch(b){console.warn(`[snapdom] Failed to inline background-image for ${a}`,b)}if(W&&(C.style.backgroundColor=d),!(C.childNodes.length>0||C.textContent&&C.textContent.trim()!==""||B||W||X||T||V))continue;a==="::before"?t.insertBefore(C,t.firstChild):t.appendChild(C)}catch(s){console.warn(`[snapdom] Failed to capture ${a} for`,e,s)}let n=Array.from(e.children),i=Array.from(t.children).filter(a=>!a.dataset.snapdomPseudo);for(let a=0;a<Math.min(n.length,i.length);a++)await te(n[a],i[a],r,c,o)}function we(e){if(!e)return;let t=document.querySelectorAll("svg > defs");t.length&&e.querySelectorAll("svg").forEach(r=>{let c=r.querySelectorAll("use");if(!c.length)return;let o=new Set;if(c.forEach(i=>{let a=i.getAttribute("xlink:href")||i.getAttribute("href");a&&a.startsWith("#")&&o.add(a.slice(1))}),!o.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let i of o)for(let a of t){let s=a.querySelector(`#${CSS.escape(i)}`);if(s){n.appendChild(s.cloneNode(!0));break}}n.childNodes.length&&r.insertBefore(n,r.firstChild)})}async function xe(e,t=!1,r=!1,c={}){let o,n="";try{o=j(e,t,c,e)}catch(i){throw console.warn("deepClone failed:",i),i}try{await te(e,o,t,r,c.useProxy)}catch(i){console.warn("inlinePseudoElements failed:",i)}try{we(o)}catch(i){console.warn("inlineExternalDef failed:",i)}if(t){let i=de();n=Array.from(i.entries()).map(([a,s])=>`.${s}{${a}}`).join("");for(let[a,s]of l.preStyleMap.entries()){if(a.tagName==="STYLE")continue;let f=i.get(s);f&&a.classList.add(f);let u=a.style?.backgroundImage;a.removeAttribute("style"),u&&u!=="none"&&(a.style.backgroundImage=u)}}else for(let[i,a]of l.preStyleMap.entries())i.tagName!=="STYLE"&&i.setAttribute("style",a.replace(/;/g,"; "));for(let[i,a]of l.preNodeMap.entries()){let s=a.scrollLeft,f=a.scrollTop;if((s||f)&&i instanceof HTMLElement){i.style.overflow="hidden",i.style.scrollbarWidth="none",i.style.msOverflowStyle="none";let d=document.createElement("div");for(d.style.transform=`translate(${-s}px, ${-f}px)`,d.style.willChange="transform",d.style.display="inline-block",d.style.width="100%";i.firstChild;)d.appendChild(i.firstChild);i.appendChild(d)}}if(e===l.preNodeMap.get(o)){let i=l.preStyle.get(e)||window.getComputedStyle(e);l.preStyle.set(e,i);let a=me(i.transform);o.style.margin="0",o.style.position="static",o.style.top="auto",o.style.left="auto",o.style.right="auto",o.style.bottom="auto",o.style.zIndex="auto",o.style.float="none",o.style.clear="none",o.style.transform=a||""}for(let[i,a]of l.preNodeMap.entries())a.tagName==="PRE"&&(i.style.marginTop="0",i.style.marginBlockStart="0");return{clone:o,classCSS:n}}async function Se(e,t={}){let r=Array.from(e.querySelectorAll("img")),c=async o=>{let n=o.src;try{let i=await M(n,{useProxy:t.useProxy});o.src=i,o.width||(o.width=o.naturalWidth||100),o.height||(o.height=o.naturalHeight||100)}catch{let i=document.createElement("div");i.style=`width: ${o.width||100}px; height: ${o.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${o.height||100}px; color: #666; font-size: 12px;`,i.innerText="img",o.replaceWith(i)}};for(let o=0;o<r.length;o+=4){let n=r.slice(o,o+4).map(c);await Promise.allSettled(n)}}async function be(e,t,r={}){let c=[[e,t]],o=["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[n,i]=c.shift(),a=l.preStyle.get(n)||R(n);l.preStyle.has(n)||l.preStyle.set(n,a);for(let d of o){let h=a.getPropertyValue(d);if(!h||h==="none")continue;let p=F(h),m=await Promise.all(p.map(g=>P(g,r)));m.some(g=>g&&g!=="none"&&!/^url\(undefined/.test(g))&&i.style.setProperty(d,m.join(", "))}let s=a.getPropertyValue("background-color");s&&s!=="transparent"&&s!=="rgba(0, 0, 0, 0)"&&(i.style.backgroundColor=s);let f=Array.from(n.children),u=Array.from(i.children);for(let d=0;d<Math.min(f.length,u.length);d++)c.push([f[d],u[d]])}}async function Ce(e,t={}){if(!e)throw new Error("Element cannot be null or undefined");l.reset();let{compress:r=!0,embedFonts:c=!1,fast:o=!0,scale:n=1,useProxy:i=""}=t,a,s,f="",u="",d,h;if({clone:a,classCSS:s}=await xe(e,r,c,t),await new Promise(m=>{L(async()=>{await Se(a,t),m()},{fast:o})}),await new Promise(m=>{L(async()=>{await be(e,a,t),m()},{fast:o})}),c&&await new Promise(m=>{L(async()=>{f=await H(),m()},{fast:o})}),r){let m=le(a).sort(),g=m.join(",");l.baseStyle.has(g)?u=l.baseStyle.get(g):await new Promise(w=>{L(()=>{u=fe(m),l.baseStyle.set(g,u),w()},{fast:o})})}await new Promise(m=>{L(()=>{let g=e.getBoundingClientRect(),w=g.width,y=g.height,E=Number.isFinite(t.width),k=Number.isFinite(t.height),$=typeof n=="number"&&n!==1;if(!$){let T=g.width/g.height;E&&k?(w=t.width,y=t.height):E?(w=t.width,y=w/T):k&&(y=t.height,w=y*T)}if(w=Math.ceil(w),y=Math.ceil(y),a.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),a.style.transformOrigin="top left",!$&&(E||k)){let T=g.width,V=g.height,ae=w/T,C=y/V,G=a.style.transform||"",J=`scale(${ae}, ${C})`;a.style.transform=`${J} ${G}`.trim()}let N="http://www.w3.org/2000/svg",S=document.createElementNS(N,"foreignObject");S.setAttribute("width","100%"),S.setAttribute("height","100%");let K=document.createElement("style");K.textContent=u+f+"svg{overflow:visible;}"+s,S.appendChild(K),S.appendChild(a);let B=new XMLSerializer().serializeToString(S);h=`<svg xmlns="${N}" width="${w}" height="${y}" viewBox="0 0 ${w} ${y}">`+B+"</svg>",d=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(h)}`,m()},{fast:o})});let p=document.getElementById("snapdom-sandbox");return p&&p.style.position==="absolute"&&p.remove(),d}async function Pe(e,{dpr:t=1,scale:r=1}){let c=new Image;return c.src=e,await c.decode(),c.width=c.width*r,c.height=c.height*r,c}async function Ee(e,{dpr:t=1,scale:r=1}={}){let c=new Image;c.src=e,c.crossOrigin="anonymous",c.loading="eager",c.decoding="sync";let o=pe(),n=!1;if(o&&(document.body.appendChild(c),n=!0),await c.decode(),o&&await new Promise(u=>setTimeout(u,100)),c.width===0||c.height===0)throw n&&c.remove(),new Error("Image failed to load or has no dimensions");let i=c.width*r,a=c.height*r,s=document.createElement("canvas");s.width=Math.ceil(i*t),s.height=Math.ceil(a*t),s.style.width=`${i}px`,s.style.height=`${a}px`;let f=s.getContext("2d");return f.scale(t,t),f.drawImage(c,0,0,i,a),n&&c.remove(),s}async function ve(e,{type:t="svg",scale:r=1,backgroundColor:c="#fff",quality:o}={}){let n={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 i=await oe(e,{dpr:1,scale:r},c);return new Promise(a=>{i.toBlob(s=>a(s),`${n}`,o)})}async function oe(e,{dpr:t=1,scale:r=1},c){let o=await Ee(e,{dpr:t,scale:r});if(!c)return o;let n=document.createElement("canvas");n.width=o.width,n.height=o.height;let i=n.getContext("2d");return i.fillStyle=c,i.fillRect(0,0,n.width,n.height),i.drawImage(o,0,0),n}async function ne(e,{dpr:t=1,scale:r=1,backgroundColor:c,quality:o},n="png"){let i=["jpg","jpeg","webp"].includes(n)?"#fff":void 0,s=await oe(e,{dpr:t,scale:r},c??i),f=new Image;return f.src=s.toDataURL(`image/${n}`,o),await f.decode(),f.style.width=`${s.width/t}px`,f.style.height=`${s.height/t}px`,f}async function Le(e,{dpr:t=1,scale:r=1,backgroundColor:c,format:o="png",filename:n="snapDOM"}={}){if(o==="svg"){let h=await ve(e),p=URL.createObjectURL(h),m=document.createElement("a");m.href=p,m.download=`${n}.svg`,m.click(),URL.revokeObjectURL(p);return}let i=["jpg","jpeg","webp"].includes(o)?"#fff":void 0,s=await oe(e,{dpr:t,scale:r},c??i),f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[o]||"image/png",u=s.toDataURL(f),d=document.createElement("a");d.href=u,d.download=`${n}.${o}`,d.click()}async function x(e,t={}){if(t={scale:1,...t},!e)throw new Error("Element cannot be null or undefined");return t.iconFonts&&he(t.iconFonts),await x.capture(e,t)}x.capture=async(e,t={})=>{let r=await Ce(e,t),c=window.devicePixelRatio||1,o=t.scale||1;return{url:r,options:t,toRaw:()=>r,toImg:()=>Pe(r,{dpr:c,scale:o}),toCanvas:()=>Ee(r,{dpr:c,scale:o}),toBlob:n=>ve(r,{dpr:c,scale:o,...n}),toPng:n=>ne(r,{dpr:c,scale:o,...n},"png"),toJpg:n=>ne(r,{dpr:c,scale:o,...n},"jpeg"),toWebp:n=>ne(r,{dpr:c,scale:o,...n},"webp"),download:({format:n="png",filename:i="capture",backgroundColor:a}={})=>Le(r,{dpr:c,scale:o,backgroundColor:a,format:n,filename:i})}};x.toRaw=async(e,t)=>(await x.capture(e,t)).toRaw();x.toImg=async(e,t)=>(await x.capture(e,t)).toImg();x.toCanvas=async(e,t)=>(await x.capture(e,t)).toCanvas();x.toBlob=async(e,t)=>(await x.capture(e,t)).toBlob(t);x.toPng=async(e,t)=>(await x.capture(e,t)).toPng(t);x.toJpg=async(e,t)=>(await x.capture(e,t)).toJpg(t);x.toWebp=async(e,t)=>(await x.capture(e,t)).toWebp(t);x.download=async(e,t={})=>{let{format:r="png",filename:c="capture",backgroundColor:o,...n}=t;return await(await x.capture(e,n)).download({format:r,filename:c,backgroundColor:o})};async function Fe(e=document,t={}){let{embedFonts:r=!0,reset:c=!1}=t;if(c){l.reset();return}await document.fonts.ready,ie();let o=[],n=[];e?.querySelectorAll&&(o=Array.from(e.querySelectorAll("img[src]")),n=Array.from(e.querySelectorAll("*")));let i=[];for(let a of o){let s=a.src;l.image.has(s)||i.push(M(s,{useProxy:t.useProxy}).then(f=>l.image.set(s,f)).catch(()=>{}))}for(let a of n){let s=R(a).backgroundImage;if(s&&s!=="none"){let f=F(s);for(let u of f)u.startsWith("url(")&&i.push(P(u,t).catch(()=>{}))}}r&&await H({preCached:!0}),await Promise.all(i)}export{Fe 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.
|
|
4
|
+
* v.1.9.7
|
|
5
5
|
* Author Juan Martin Muda
|
|
6
6
|
* License MIT
|
|
7
7
|
**/
|
|
@@ -519,7 +519,6 @@ function deepClone(node, compress, options = {}, originalRoot) {
|
|
|
519
519
|
if (node.checked) clone.setAttribute("checked", "");
|
|
520
520
|
if (node.indeterminate) clone.indeterminate = node.indeterminate;
|
|
521
521
|
}
|
|
522
|
-
return clone;
|
|
523
522
|
}
|
|
524
523
|
if (node instanceof HTMLSelectElement) {
|
|
525
524
|
pendingSelectValue = node.value;
|
|
@@ -740,8 +739,8 @@ async function embedCustomFonts({ preCached = false } = {}) {
|
|
|
740
739
|
if (!src || isIconFont(family)) continue;
|
|
741
740
|
const urlRegex = /url\((["']?)([^"')]+)\1\)/g;
|
|
742
741
|
const localRegex = /local\((["']?)[^)]+?\1\)/g;
|
|
743
|
-
const hasURL =
|
|
744
|
-
const hasLocal =
|
|
742
|
+
const hasURL = !!src.match(urlRegex);
|
|
743
|
+
const hasLocal = !!src.match(localRegex);
|
|
745
744
|
if (!hasURL && hasLocal) {
|
|
746
745
|
finalCSS += `@font-face{font-family:${family};src:${src};font-style:${rule.style.getPropertyValue("font-style") || "normal"};font-weight:${rule.style.getPropertyValue("font-weight") || "normal"};}`;
|
|
747
746
|
continue;
|
|
@@ -848,9 +847,9 @@ async function inlinePseudoElements(source, clone, compress, embedFonts = false,
|
|
|
848
847
|
const span = document.createElement("span");
|
|
849
848
|
span.textContent = first;
|
|
850
849
|
span.dataset.snapdomPseudo = "::first-letter";
|
|
851
|
-
const
|
|
852
|
-
const
|
|
853
|
-
cache.preStyleMap.set(span,
|
|
850
|
+
const snapshot2 = snapshotComputedStyle(style);
|
|
851
|
+
const key2 = getStyleKey(snapshot2, "span", compress);
|
|
852
|
+
cache.preStyleMap.set(span, key2);
|
|
854
853
|
const restNode = document.createTextNode(rest);
|
|
855
854
|
clone.replaceChild(restNode, textNode);
|
|
856
855
|
clone.insertBefore(span, restNode);
|
|
@@ -859,64 +858,73 @@ async function inlinePseudoElements(source, clone, compress, embedFonts = false,
|
|
|
859
858
|
const content = style.getPropertyValue("content");
|
|
860
859
|
const bg = style.getPropertyValue("background-image");
|
|
861
860
|
const bgColor = style.getPropertyValue("background-color");
|
|
861
|
+
const fontFamily = style.getPropertyValue("font-family");
|
|
862
|
+
const fontSize = parseInt(style.getPropertyValue("font-size")) || 32;
|
|
863
|
+
const fontWeight = parseInt(style.getPropertyValue("font-weight")) || false;
|
|
864
|
+
const color = style.getPropertyValue("color") || "#000";
|
|
865
|
+
const display = style.getPropertyValue("display");
|
|
866
|
+
const width = parseFloat(style.getPropertyValue("width"));
|
|
867
|
+
const height = parseFloat(style.getPropertyValue("height"));
|
|
868
|
+
const borderStyle = style.getPropertyValue("border-style");
|
|
869
|
+
const transform = style.getPropertyValue("transform");
|
|
870
|
+
const isIconFont2 = isIconFont(fontFamily);
|
|
871
|
+
let cleanContent;
|
|
872
|
+
if (/counter\s*\(|counters\s*\(/.test(content)) {
|
|
873
|
+
cleanContent = "- ";
|
|
874
|
+
} else {
|
|
875
|
+
cleanContent = parseContent(content);
|
|
876
|
+
}
|
|
862
877
|
const hasContent = content !== "none";
|
|
878
|
+
const hasExplicitContent = hasContent && cleanContent !== "";
|
|
863
879
|
const hasBg = bg && bg !== "none";
|
|
864
880
|
const hasBgColor = bgColor && bgColor !== "transparent" && bgColor !== "rgba(0, 0, 0, 0)";
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
if (
|
|
883
|
-
const imgEl = document.createElement("img");
|
|
884
|
-
imgEl.src = await iconToImage(cleanContent, fontFamily, fontWeight, fontSize, color);
|
|
885
|
-
imgEl.style = `width:${fontSize}px;height:auto;object-fit:contain;`;
|
|
886
|
-
pseudoEl.appendChild(imgEl);
|
|
887
|
-
} else if (cleanContent.startsWith("url(")) {
|
|
888
|
-
const rawUrl = extractURL(cleanContent);
|
|
889
|
-
if (rawUrl && rawUrl.trim() !== "") {
|
|
890
|
-
try {
|
|
891
|
-
const imgEl = document.createElement("img");
|
|
892
|
-
const dataUrl = await fetchImage(safeEncodeURI(rawUrl, { useProxy }));
|
|
893
|
-
imgEl.src = dataUrl;
|
|
894
|
-
imgEl.style = `width:${fontSize}px;height:auto;object-fit:contain;`;
|
|
895
|
-
pseudoEl.appendChild(imgEl);
|
|
896
|
-
} catch (e) {
|
|
897
|
-
console.error(`[snapdom] Error in pseudo ${pseudo} for`, source, e);
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
} else if (!isIconFont2 && cleanContent && cleanContent !== "none") {
|
|
901
|
-
pseudoEl.textContent = cleanContent;
|
|
902
|
-
}
|
|
903
|
-
if (hasBg) {
|
|
881
|
+
const hasBox = display !== "inline" && (width > 0 || height > 0);
|
|
882
|
+
const hasBorder = borderStyle && borderStyle !== "none";
|
|
883
|
+
const hasTransform = transform && transform !== "none";
|
|
884
|
+
const shouldRender = hasExplicitContent || hasBg || hasBgColor || hasBox || hasBorder || hasTransform;
|
|
885
|
+
if (!shouldRender) continue;
|
|
886
|
+
const pseudoEl = document.createElement("span");
|
|
887
|
+
pseudoEl.dataset.snapdomPseudo = pseudo;
|
|
888
|
+
const snapshot = snapshotComputedStyle(style);
|
|
889
|
+
const key = getStyleKey(snapshot, "span", compress);
|
|
890
|
+
cache.preStyleMap.set(pseudoEl, key);
|
|
891
|
+
if (isIconFont2 && cleanContent.length === 1) {
|
|
892
|
+
const imgEl = document.createElement("img");
|
|
893
|
+
imgEl.src = await iconToImage(cleanContent, fontFamily, fontWeight, fontSize, color);
|
|
894
|
+
imgEl.style = `width:${fontSize}px;height:auto;object-fit:contain;`;
|
|
895
|
+
pseudoEl.appendChild(imgEl);
|
|
896
|
+
} else if (cleanContent.startsWith("url(")) {
|
|
897
|
+
const rawUrl = extractURL(cleanContent);
|
|
898
|
+
if (rawUrl && rawUrl.trim() !== "") {
|
|
904
899
|
try {
|
|
905
|
-
const
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
pseudoEl.
|
|
900
|
+
const imgEl = document.createElement("img");
|
|
901
|
+
const dataUrl = await fetchImage(safeEncodeURI(rawUrl, { useProxy }));
|
|
902
|
+
imgEl.src = dataUrl;
|
|
903
|
+
imgEl.style = `width:${fontSize}px;height:auto;object-fit:contain;`;
|
|
904
|
+
pseudoEl.appendChild(imgEl);
|
|
910
905
|
} catch (e) {
|
|
911
|
-
console.
|
|
906
|
+
console.error(`[snapdom] Error in pseudo ${pseudo} for`, source, e);
|
|
912
907
|
}
|
|
913
908
|
}
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
909
|
+
} else if (!isIconFont2 && hasExplicitContent) {
|
|
910
|
+
pseudoEl.textContent = cleanContent;
|
|
911
|
+
}
|
|
912
|
+
if (hasBg) {
|
|
913
|
+
try {
|
|
914
|
+
const bgSplits = splitBackgroundImage(bg);
|
|
915
|
+
const newBgParts = await Promise.all(
|
|
916
|
+
bgSplits.map((entry) => inlineSingleBackgroundEntry(entry))
|
|
917
|
+
);
|
|
918
|
+
pseudoEl.style.backgroundImage = newBgParts.join(", ");
|
|
919
|
+
} catch (e) {
|
|
920
|
+
console.warn(`[snapdom] Failed to inline background-image for ${pseudo}`, e);
|
|
921
|
+
}
|
|
919
922
|
}
|
|
923
|
+
if (hasBgColor) pseudoEl.style.backgroundColor = bgColor;
|
|
924
|
+
const hasContent2 = pseudoEl.childNodes.length > 0 || pseudoEl.textContent && pseudoEl.textContent.trim() !== "";
|
|
925
|
+
const hasVisibleBox = hasContent2 || hasBg || hasBgColor || hasBox || hasBorder || hasTransform;
|
|
926
|
+
if (!hasVisibleBox) continue;
|
|
927
|
+
pseudo === "::before" ? clone.insertBefore(pseudoEl, clone.firstChild) : clone.appendChild(pseudoEl);
|
|
920
928
|
} catch (e) {
|
|
921
929
|
console.warn(`[snapdom] Failed to capture ${pseudo} for`, source, e);
|
|
922
930
|
}
|
|
@@ -1186,8 +1194,6 @@ async function captureDOM(element, options = {}) {
|
|
|
1186
1194
|
const existingTransform = clone.style.transform || "";
|
|
1187
1195
|
const scaleTransform = `scale(${scaleX}, ${scaleY})`;
|
|
1188
1196
|
clone.style.transform = `${scaleTransform} ${existingTransform}`.trim();
|
|
1189
|
-
} else if (hasScale && isSafari()) {
|
|
1190
|
-
clone.style.scale = `${scale}`;
|
|
1191
1197
|
}
|
|
1192
1198
|
const svgNS = "http://www.w3.org/2000/svg";
|
|
1193
1199
|
const fo = document.createElementNS(svgNS, "foreignObject");
|
|
@@ -1216,29 +1222,41 @@ async function toImg(url, { dpr = 1, scale = 1 }) {
|
|
|
1216
1222
|
const img = new Image();
|
|
1217
1223
|
img.src = url;
|
|
1218
1224
|
await img.decode();
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
img.height = img.height * scale;
|
|
1222
|
-
} else {
|
|
1223
|
-
img.width = img.width / scale;
|
|
1224
|
-
img.height = img.height / scale;
|
|
1225
|
-
}
|
|
1225
|
+
img.width = img.width * scale;
|
|
1226
|
+
img.height = img.height * scale;
|
|
1226
1227
|
return img;
|
|
1227
1228
|
}
|
|
1228
1229
|
async function toCanvas(url, { dpr = 1, scale = 1 } = {}) {
|
|
1229
1230
|
const img = new Image();
|
|
1230
1231
|
img.src = url;
|
|
1232
|
+
img.crossOrigin = "anonymous";
|
|
1233
|
+
img.loading = "eager";
|
|
1234
|
+
img.decoding = "sync";
|
|
1235
|
+
const isSafariBrowser = isSafari();
|
|
1236
|
+
let appended = false;
|
|
1237
|
+
if (isSafariBrowser) {
|
|
1238
|
+
document.body.appendChild(img);
|
|
1239
|
+
appended = true;
|
|
1240
|
+
}
|
|
1231
1241
|
await img.decode();
|
|
1232
|
-
|
|
1242
|
+
if (isSafariBrowser) {
|
|
1243
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1244
|
+
}
|
|
1245
|
+
if (img.width === 0 || img.height === 0) {
|
|
1246
|
+
if (appended) img.remove();
|
|
1247
|
+
throw new Error("Image failed to load or has no dimensions");
|
|
1248
|
+
}
|
|
1233
1249
|
const width = img.width * scale;
|
|
1234
1250
|
const height = img.height * scale;
|
|
1251
|
+
const canvas = document.createElement("canvas");
|
|
1235
1252
|
canvas.width = Math.ceil(width * dpr);
|
|
1236
1253
|
canvas.height = Math.ceil(height * dpr);
|
|
1254
|
+
canvas.style.width = `${width}px`;
|
|
1255
|
+
canvas.style.height = `${height}px`;
|
|
1237
1256
|
const ctx = canvas.getContext("2d");
|
|
1238
1257
|
ctx.scale(dpr, dpr);
|
|
1239
1258
|
ctx.drawImage(img, 0, 0, width, height);
|
|
1240
|
-
|
|
1241
|
-
canvas.style.height = `${height}px`;
|
|
1259
|
+
if (appended) img.remove();
|
|
1242
1260
|
return canvas;
|
|
1243
1261
|
}
|
|
1244
1262
|
async function toBlob(url, {
|
|
@@ -1285,7 +1303,7 @@ async function toRasterImg(url, { dpr = 1, scale = 1, backgroundColor, quality }
|
|
|
1285
1303
|
img.style.height = `${canvas.height / dpr}px`;
|
|
1286
1304
|
return img;
|
|
1287
1305
|
}
|
|
1288
|
-
async function download(url, { dpr = 1, scale = 1, backgroundColor
|
|
1306
|
+
async function download(url, { dpr = 1, scale = 1, backgroundColor, format = "png", filename = "snapDOM" } = {}) {
|
|
1289
1307
|
if (format === "svg") {
|
|
1290
1308
|
const blob = await toBlob(url);
|
|
1291
1309
|
const objectURL = URL.createObjectURL(blob);
|