@unicom-cloud/utils 0.1.5 → 0.1.10
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/content-disposition/index.js +56 -0
- package/index.js +42 -37
- package/package.json +1 -1
- package/snapdom/src/api/preCache.js +31 -27
- package/snapdom/src/core/capture.js +55 -44
- package/snapdom/src/core/clone.js +11 -11
- package/snapdom/src/core/prepare.js +38 -31
- package/snapdom/src/modules/background.js +18 -43
- package/snapdom/src/modules/pseudo.js +66 -67
- package/snapdom/src/utils/helpers.js +105 -56
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function m(t) {
|
|
2
|
+
if (!t) return null;
|
|
3
|
+
const e = {
|
|
4
|
+
type: "",
|
|
5
|
+
parameters: {}
|
|
6
|
+
}, o = t.match(/^([^;]+)/);
|
|
7
|
+
o && (e.type = o[1].trim());
|
|
8
|
+
const s = t.matchAll(
|
|
9
|
+
/;\s*([^=]+)=(?:"([^"]*)"|([^;]*))/g
|
|
10
|
+
);
|
|
11
|
+
for (const r of s) {
|
|
12
|
+
const n = r[1].trim().toLowerCase(), i = r[2] || r[3];
|
|
13
|
+
if (n.endsWith("*")) {
|
|
14
|
+
const a = p(i);
|
|
15
|
+
e.parameters[n] = a;
|
|
16
|
+
const c = n.slice(0, -1);
|
|
17
|
+
e.parameters[c] || (e.parameters[c] = a);
|
|
18
|
+
} else e.parameters[n] || (e.parameters[n] = i);
|
|
19
|
+
}
|
|
20
|
+
return e;
|
|
21
|
+
}
|
|
22
|
+
function p(t) {
|
|
23
|
+
const e = t.match(/^([^']*)'[^']*'(.*)$/);
|
|
24
|
+
if (!e) return t;
|
|
25
|
+
const [o, s, r] = e;
|
|
26
|
+
try {
|
|
27
|
+
const n = r.replace(
|
|
28
|
+
/%([0-9A-Fa-f]{2})/g,
|
|
29
|
+
(i, a) => String.fromCharCode(parseInt(a, 16))
|
|
30
|
+
);
|
|
31
|
+
return s && s.toLowerCase() !== "utf-8", n;
|
|
32
|
+
} catch (n) {
|
|
33
|
+
return console.warn("Failed to decode RFC 5987 value:", t, n), t;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function f(t) {
|
|
37
|
+
let e = t?.["content-disposition"];
|
|
38
|
+
if (e)
|
|
39
|
+
return m(e);
|
|
40
|
+
}
|
|
41
|
+
function d(t) {
|
|
42
|
+
const e = f(t);
|
|
43
|
+
if (e)
|
|
44
|
+
return e.parameters;
|
|
45
|
+
}
|
|
46
|
+
function l(t) {
|
|
47
|
+
const e = d(t);
|
|
48
|
+
if (e)
|
|
49
|
+
return e["filename*"] || e.filename;
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
m as default,
|
|
53
|
+
f as getContentDispositionFromHeader,
|
|
54
|
+
l as getContentDispositionParametersFilenameFromHeader,
|
|
55
|
+
d as getContentDispositionParametersFromHeader
|
|
56
|
+
};
|
package/index.js
CHANGED
|
@@ -1,47 +1,52 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
1
|
+
import * as e from "./is/index.js";
|
|
2
|
+
import * as o from "./math/index.js";
|
|
3
|
+
import * as t from "./tree/index.js";
|
|
4
|
+
import * as r from "./turbo-stream/index.js";
|
|
5
5
|
import * as a from "./url-toolkit/index.js";
|
|
6
6
|
import { default as p } from "./case-name/index.js";
|
|
7
7
|
import { default as l } from "./class-name/index.js";
|
|
8
|
-
import { default as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { default as
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
8
|
+
import { default as d } from "./clipboard-copy/index.js";
|
|
9
|
+
import { default as c, getContentDispositionFromHeader as C, getContentDispositionParametersFilenameFromHeader as _, getContentDispositionParametersFromHeader as b } from "./content-disposition/index.js";
|
|
10
|
+
import { splitCookiesString as h } from "./cookie/index.js";
|
|
11
|
+
import { default as z } from "./decimal/decimal.js";
|
|
12
|
+
import { default as F } from "./event-emitter/index.js";
|
|
13
|
+
import { fileToURL as v } from "./file/fileToURL.js";
|
|
14
|
+
import { saveAs as T } from "./file/saveAs.js";
|
|
14
15
|
import * as s from "./filesize/src/constants.js";
|
|
15
|
-
import { filesize as
|
|
16
|
-
import { default as
|
|
17
|
-
import { default as
|
|
18
|
-
import { default as
|
|
19
|
-
import { default as
|
|
20
|
-
import { default as
|
|
21
|
-
import { default as
|
|
22
|
-
import * as
|
|
16
|
+
import { filesize as N, partial as P } from "./filesize/src/filesize.js";
|
|
17
|
+
import { default as A } from "./invariant/index.js";
|
|
18
|
+
import { default as K } from "./md5/index.js";
|
|
19
|
+
import { default as R } from "./normalize-wheel/index.js";
|
|
20
|
+
import { default as W } from "./nzh/nzh.js";
|
|
21
|
+
import { default as w } from "./objectKeysSort.js";
|
|
22
|
+
import { default as G } from "./screenfull/index.js";
|
|
23
|
+
import * as i from "./cookie/src/index.js";
|
|
23
24
|
export {
|
|
24
25
|
p as caseName,
|
|
25
26
|
l as className,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
d as clipboardCopy,
|
|
28
|
+
c as contentDisposition,
|
|
29
|
+
i as cookie,
|
|
30
|
+
z as decimal,
|
|
31
|
+
F as eventEmitter,
|
|
32
|
+
v as fileToURL,
|
|
33
|
+
N as filesize,
|
|
32
34
|
s as filesizeConstants,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
C as getContentDispositionFromHeader,
|
|
36
|
+
_ as getContentDispositionParametersFilenameFromHeader,
|
|
37
|
+
b as getContentDispositionParametersFromHeader,
|
|
38
|
+
A as invariant,
|
|
39
|
+
e as is,
|
|
40
|
+
o as math,
|
|
41
|
+
K as md5,
|
|
42
|
+
R as normalizeWheel,
|
|
43
|
+
W as nzh,
|
|
44
|
+
w as objectKeysSort,
|
|
45
|
+
P as partial,
|
|
46
|
+
T as saveAs,
|
|
47
|
+
G as screenfull,
|
|
48
|
+
h as splitCookiesString,
|
|
49
|
+
t as tree,
|
|
50
|
+
r as turboStream,
|
|
46
51
|
a as urlToolkit
|
|
47
52
|
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@unicom-cloud/utils","version":"0.1.
|
|
1
|
+
{"name":"@unicom-cloud/utils","version":"0.1.10","dependencies":{},"peerDependencies":{"lodash":"^4.17.21"},"main":"./index.js","type":"module","types":"types/*","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
|
|
@@ -1,43 +1,47 @@
|
|
|
1
|
-
import { imageCache as
|
|
2
|
-
import { embedCustomFonts as
|
|
3
|
-
import { precacheCommonTags as
|
|
4
|
-
import { fetchImage as
|
|
5
|
-
async function
|
|
1
|
+
import { imageCache as i, bgCache as u, resourceCache as h, baseCSSCache as p } from "../core/cache.js";
|
|
2
|
+
import { embedCustomFonts as y } from "../modules/fonts.js";
|
|
3
|
+
import { precacheCommonTags as d } from "../utils/cssTools.js";
|
|
4
|
+
import { fetchImage as C, getStyle as S, splitBackgroundImage as b, inlineSingleBackgroundEntry as A } from "../utils/helpers.js";
|
|
5
|
+
async function w(o = document, f = {}) {
|
|
6
6
|
const {
|
|
7
|
-
embedFonts:
|
|
7
|
+
embedFonts: a = !0,
|
|
8
8
|
reset: g = !1,
|
|
9
|
-
crossOrigin:
|
|
10
|
-
} =
|
|
9
|
+
crossOrigin: s
|
|
10
|
+
} = f;
|
|
11
11
|
if (g) {
|
|
12
|
-
|
|
12
|
+
i.clear(), u.clear(), h.clear(), p.clear();
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
await document.fonts.ready,
|
|
16
|
-
let l = [],
|
|
17
|
-
|
|
15
|
+
await document.fonts.ready, d();
|
|
16
|
+
let l = [], m = [];
|
|
17
|
+
o?.querySelectorAll && (l = Array.from(o.querySelectorAll("img[src]")), m = Array.from(o.querySelectorAll("*")));
|
|
18
18
|
const t = [];
|
|
19
|
-
for (const
|
|
20
|
-
const r =
|
|
21
|
-
if (!
|
|
22
|
-
const
|
|
19
|
+
for (const c of l) {
|
|
20
|
+
const r = c.src;
|
|
21
|
+
if (!i.has(r)) {
|
|
22
|
+
const n = s ? s(r) : "anonymous";
|
|
23
23
|
t.push(
|
|
24
|
-
|
|
24
|
+
C(r, 3e3, n).then((e) => i.set(r, e)).catch(() => {
|
|
25
25
|
})
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
for (const
|
|
30
|
-
const r =
|
|
31
|
-
if (
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
for (const c of m) {
|
|
30
|
+
const r = S(c).backgroundImage;
|
|
31
|
+
if (r && r !== "none") {
|
|
32
|
+
const n = b(r);
|
|
33
|
+
for (const e of n)
|
|
34
|
+
e.startsWith("url(") && t.push(
|
|
35
|
+
A(e, {
|
|
36
|
+
crossOrigin: s,
|
|
37
|
+
skipInline: !0
|
|
38
|
+
}).catch(() => {
|
|
39
|
+
})
|
|
40
|
+
);
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
|
-
|
|
43
|
+
a && await y({ ignoreIconFonts: !a, preCached: !0 }), await Promise.all(t);
|
|
40
44
|
}
|
|
41
45
|
export {
|
|
42
|
-
|
|
46
|
+
w as preCache
|
|
43
47
|
};
|
|
@@ -1,73 +1,84 @@
|
|
|
1
|
-
import { baseCSSCache as
|
|
2
|
-
import { inlineBackgroundImages as
|
|
3
|
-
import { embedCustomFonts as
|
|
4
|
-
import { inlineImages as
|
|
5
|
-
import { collectUsedTagNames as
|
|
6
|
-
import { idle as
|
|
7
|
-
import { prepareClone as
|
|
8
|
-
async function
|
|
9
|
-
if (!
|
|
1
|
+
import { baseCSSCache as S } from "./cache.js";
|
|
2
|
+
import { inlineBackgroundImages as P } from "../modules/background.js";
|
|
3
|
+
import { embedCustomFonts as z } from "../modules/fonts.js";
|
|
4
|
+
import { inlineImages as H } from "../modules/images.js";
|
|
5
|
+
import { collectUsedTagNames as A, generateDedupedBaseCSS as D } from "../utils/cssTools.js";
|
|
6
|
+
import { idle as l, isSafari as R } from "../utils/helpers.js";
|
|
7
|
+
import { prepareClone as U } from "./prepare.js";
|
|
8
|
+
async function Q(r, n = {}) {
|
|
9
|
+
if (!r) throw new Error("Element cannot be null or undefined");
|
|
10
|
+
if (!(r instanceof Element))
|
|
11
|
+
throw new Error("captureDOM: Only Element nodes are supported");
|
|
10
12
|
const {
|
|
11
|
-
compress:
|
|
12
|
-
embedFonts:
|
|
13
|
+
compress: b = !0,
|
|
14
|
+
embedFonts: h = !1,
|
|
13
15
|
fast: o = !0,
|
|
14
16
|
scale: f = 1
|
|
15
|
-
} =
|
|
16
|
-
let t,
|
|
17
|
-
if ({ clone: t, classCSS:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
), await new Promise((
|
|
22
|
-
|
|
17
|
+
} = n;
|
|
18
|
+
let t, y, v, C = "", m = "", $, x;
|
|
19
|
+
if ({ clone: t, classCSS: y, styleCache: v } = await U(
|
|
20
|
+
r,
|
|
21
|
+
b,
|
|
22
|
+
h
|
|
23
|
+
), await new Promise((s) => {
|
|
24
|
+
l(
|
|
23
25
|
async () => {
|
|
24
|
-
await
|
|
26
|
+
await H(t, n), s();
|
|
25
27
|
},
|
|
26
28
|
{ fast: o }
|
|
27
29
|
);
|
|
28
|
-
}), await new Promise((
|
|
29
|
-
|
|
30
|
+
}), await new Promise((s) => {
|
|
31
|
+
l(
|
|
30
32
|
async () => {
|
|
31
|
-
await
|
|
33
|
+
await P(r, t, v, n), s();
|
|
32
34
|
},
|
|
33
35
|
{ fast: o }
|
|
34
36
|
);
|
|
35
|
-
}),
|
|
36
|
-
|
|
37
|
+
}), h && await new Promise((s) => {
|
|
38
|
+
l(
|
|
37
39
|
async () => {
|
|
38
|
-
|
|
40
|
+
C = await z({ ignoreIconFonts: !h }), s();
|
|
39
41
|
},
|
|
40
42
|
{ fast: o }
|
|
41
43
|
);
|
|
42
|
-
}),
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
}), b) {
|
|
45
|
+
const s = A(t).sort(), i = s.join(",");
|
|
46
|
+
S.has(i) ? m = S.get(i) : await new Promise((e) => {
|
|
47
|
+
l(
|
|
46
48
|
() => {
|
|
47
|
-
|
|
49
|
+
m = D(s), S.set(i, m), e();
|
|
48
50
|
},
|
|
49
51
|
{ fast: o }
|
|
50
52
|
);
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
|
-
await new Promise((
|
|
54
|
-
|
|
55
|
+
await new Promise((s) => {
|
|
56
|
+
l(
|
|
55
57
|
() => {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
const i = r.getBoundingClientRect();
|
|
59
|
+
let e = i.width, a = i.height;
|
|
60
|
+
const d = Number.isFinite(n.width), u = Number.isFinite(n.height), p = typeof f == "number" && f !== 1;
|
|
61
|
+
if (!p) {
|
|
62
|
+
const g = i.width / i.height;
|
|
63
|
+
d && u ? (e = n.width, a = n.height) : d ? (e = n.width, a = e / g) : u && (a = n.height, e = a * g);
|
|
64
|
+
}
|
|
65
|
+
if (e = Math.ceil(e), a = Math.ceil(a), t.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), t.style.transformOrigin = "top left", !p && (d || u)) {
|
|
66
|
+
const g = i.width, B = i.height, I = e / g, M = a / B, N = t.style.transform || "", O = `scale(${I}, ${M})`;
|
|
67
|
+
t.style.transform = `${O} ${N}`.trim();
|
|
68
|
+
} else p && R() && (t.style.scale = `${f}`);
|
|
69
|
+
const E = "http://www.w3.org/2000/svg", c = document.createElementNS(E, "foreignObject");
|
|
70
|
+
c.setAttribute("width", "100%"), c.setAttribute("height", "100%");
|
|
71
|
+
const F = document.createElement("style");
|
|
72
|
+
F.textContent = m + C + "svg{overflow:visible;}" + y, c.appendChild(F), c.appendChild(t);
|
|
73
|
+
const T = new XMLSerializer().serializeToString(c);
|
|
74
|
+
x = `<svg xmlns="${E}" width="${e}" height="${a}" viewBox="0 0 ${e} ${a}">` + T + "</svg>", $ = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(x)}`, s();
|
|
64
75
|
},
|
|
65
76
|
{ fast: o }
|
|
66
77
|
);
|
|
67
78
|
});
|
|
68
|
-
const
|
|
69
|
-
return
|
|
79
|
+
const w = document.getElementById("snapdom-sandbox");
|
|
80
|
+
return w && w.style.position === "absolute" && w.remove(), $;
|
|
70
81
|
}
|
|
71
82
|
export {
|
|
72
|
-
|
|
83
|
+
Q as captureDOM
|
|
73
84
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { inlineAllStyles as
|
|
2
|
-
function
|
|
1
|
+
import { inlineAllStyles as o } from "../modules/styles.js";
|
|
2
|
+
function f(e, c, r, n, s) {
|
|
3
3
|
if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "exclude") {
|
|
4
4
|
const t = document.createElement("div"), i = e.getBoundingClientRect();
|
|
5
5
|
return t.style.cssText = `display: inline-block; width: ${i.width}px; height: ${i.height}px; visibility: hidden;`, t;
|
|
@@ -10,13 +10,13 @@ function h(e, c, r, n, s) {
|
|
|
10
10
|
}
|
|
11
11
|
if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "placeholder") {
|
|
12
12
|
const t = e.cloneNode(!1);
|
|
13
|
-
n.set(t, e),
|
|
13
|
+
n.set(t, e), o(e, t, c, r, s);
|
|
14
14
|
const i = document.createElement("div");
|
|
15
15
|
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;", t.appendChild(i), t;
|
|
16
16
|
}
|
|
17
17
|
if (e.tagName === "CANVAS") {
|
|
18
18
|
const t = e.toDataURL(), i = document.createElement("img");
|
|
19
|
-
return i.src = t, i.width = e.width, i.height = e.height, i.style.display = "inline-block", i.style.width = `${e.width}px`, i.style.height = `${e.height}px`, i;
|
|
19
|
+
return i.src = t, i.width = e.width, i.height = e.height, i.style.display = "inline-block", i.style.width = e.style.width || `${e.width}px`, i.style.height = e.style.height || `${e.height}px`, i;
|
|
20
20
|
}
|
|
21
21
|
if (e.nodeType === Node.TEXT_NODE) {
|
|
22
22
|
if (e.parentElement?.shadowRoot) {
|
|
@@ -29,23 +29,23 @@ function h(e, c, r, n, s) {
|
|
|
29
29
|
const l = e.cloneNode(!1);
|
|
30
30
|
n.set(l, e), e instanceof HTMLInputElement ? (l.value = e.value, l.setAttribute("value", e.value), e.checked !== void 0 && (l.checked = e.checked, e.checked && l.setAttribute("checked", ""))) : e instanceof HTMLTextAreaElement ? (l.value = e.value, l.textContent = e.value) : e instanceof HTMLSelectElement && (l.value = e.value, Array.from(l.options).forEach((t) => {
|
|
31
31
|
t.value === e.value ? t.setAttribute("selected", "") : t.removeAttribute("selected");
|
|
32
|
-
})),
|
|
33
|
-
const
|
|
32
|
+
})), o(e, l, c, r, s);
|
|
33
|
+
const h = document.createDocumentFragment();
|
|
34
34
|
if (e.childNodes.forEach((t) => {
|
|
35
|
-
const i =
|
|
35
|
+
const i = f(
|
|
36
36
|
t,
|
|
37
37
|
c,
|
|
38
38
|
r,
|
|
39
39
|
n,
|
|
40
40
|
s
|
|
41
41
|
);
|
|
42
|
-
i &&
|
|
43
|
-
}), l.appendChild(
|
|
44
|
-
const t = Array.from(e.shadowRoot.children).filter((a) => a.tagName !== "STYLE").map((a) =>
|
|
42
|
+
i && h.appendChild(i);
|
|
43
|
+
}), l.appendChild(h), e.shadowRoot) {
|
|
44
|
+
const t = Array.from(e.shadowRoot.children).filter((a) => a.tagName !== "STYLE").map((a) => f(a, c, r, n)).filter(Boolean), i = document.createDocumentFragment();
|
|
45
45
|
t.forEach((a) => i.appendChild(a)), l.appendChild(i);
|
|
46
46
|
}
|
|
47
47
|
return l;
|
|
48
48
|
}
|
|
49
49
|
export {
|
|
50
|
-
|
|
50
|
+
f as deepClone
|
|
51
51
|
};
|
|
@@ -1,52 +1,59 @@
|
|
|
1
1
|
import { inlinePseudoElements as m } from "../modules/pseudo.js";
|
|
2
|
-
import { generateCSSClasses as
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { generateCSSClasses as g } from "../utils/cssTools.js";
|
|
3
|
+
import { stripTranslate as u } from "../utils/helpers.js";
|
|
4
|
+
import { deepClone as h } from "./clone.js";
|
|
5
|
+
async function k(s, f = !1, p = !1) {
|
|
6
|
+
const a = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new Map();
|
|
7
|
+
let t;
|
|
7
8
|
try {
|
|
8
|
-
|
|
9
|
+
t = h(s, a, r, y, f);
|
|
9
10
|
} catch (e) {
|
|
10
11
|
throw console.warn("deepClone failed:", e), e;
|
|
11
12
|
}
|
|
12
13
|
try {
|
|
13
14
|
await m(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
i,
|
|
15
|
+
s,
|
|
16
|
+
t,
|
|
17
|
+
a,
|
|
18
18
|
r,
|
|
19
|
+
f,
|
|
19
20
|
p
|
|
20
21
|
);
|
|
21
22
|
} catch (e) {
|
|
22
23
|
console.warn("inlinePseudoElements failed:", e);
|
|
23
24
|
}
|
|
24
|
-
let
|
|
25
|
-
if (
|
|
26
|
-
const e =
|
|
27
|
-
|
|
28
|
-
for (const [
|
|
29
|
-
if (
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
25
|
+
let d = "";
|
|
26
|
+
if (f) {
|
|
27
|
+
const e = g(a);
|
|
28
|
+
d = Array.from(e.entries()).map(([o, n]) => `.${n}{${o}}`).join("");
|
|
29
|
+
for (const [o, n] of a.entries()) {
|
|
30
|
+
if (o.tagName === "STYLE") continue;
|
|
31
|
+
const i = e.get(n);
|
|
32
|
+
i && o.classList.add(i);
|
|
33
|
+
const c = o.style?.backgroundImage;
|
|
34
|
+
o.removeAttribute("style"), c && c !== "none" && (o.style.backgroundImage = c);
|
|
34
35
|
}
|
|
35
36
|
} else
|
|
36
|
-
for (const [e,
|
|
37
|
-
e.tagName !== "STYLE" && e.setAttribute("style",
|
|
38
|
-
for (const [e,
|
|
39
|
-
const n =
|
|
40
|
-
if ((n ||
|
|
37
|
+
for (const [e, o] of a.entries())
|
|
38
|
+
e.tagName !== "STYLE" && e.setAttribute("style", o.replace(/;/g, "; "));
|
|
39
|
+
for (const [e, o] of y.entries()) {
|
|
40
|
+
const n = o.scrollLeft, i = o.scrollTop;
|
|
41
|
+
if ((n || i) && e instanceof HTMLElement) {
|
|
41
42
|
e.style.overflow = "hidden", e.style.scrollbarWidth = "none", e.style.msOverflowStyle = "none";
|
|
42
|
-
const
|
|
43
|
-
for (
|
|
44
|
-
|
|
45
|
-
e.appendChild(
|
|
43
|
+
const l = document.createElement("div");
|
|
44
|
+
for (l.style.transform = `translate(${-n}px, ${-i}px)`, l.style.willChange = "transform", l.style.display = "inline-block", l.style.width = "100%"; e.firstChild; )
|
|
45
|
+
l.appendChild(e.firstChild);
|
|
46
|
+
e.appendChild(l);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
+
if (s === y.get(t)) {
|
|
50
|
+
const e = r.get(s) || window.getComputedStyle(s);
|
|
51
|
+
r.set(s, e);
|
|
52
|
+
const o = u(e.transform);
|
|
53
|
+
t.style.margin = "0", t.style.position = "static", t.style.top = "auto", t.style.left = "auto", t.style.right = "auto", t.style.bottom = "auto", t.style.zIndex = "auto", t.style.float = "none", t.style.clear = "none", t.style.transform = o || "";
|
|
54
|
+
}
|
|
55
|
+
return { clone: t, classCSS: d, styleCache: r };
|
|
49
56
|
}
|
|
50
57
|
export {
|
|
51
|
-
|
|
58
|
+
k as prepareClone
|
|
52
59
|
};
|
|
@@ -1,50 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
c.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
o.push([r[t], a[t]]);
|
|
1
|
+
import { getStyle as b, splitBackgroundImage as p, inlineSingleBackgroundEntry as k } from "../utils/helpers.js";
|
|
2
|
+
async function B(u, m, l, f = {}) {
|
|
3
|
+
const r = [[u, m]];
|
|
4
|
+
for (; r.length; ) {
|
|
5
|
+
const [e, o] = r.shift(), s = l.get(e) || b(e);
|
|
6
|
+
l.has(e) || l.set(e, s);
|
|
7
|
+
const c = s.getPropertyValue("background-image"), t = s.getPropertyValue("background-color");
|
|
8
|
+
if (!c || c === "none") {
|
|
9
|
+
const n = Array.from(e.children), h = Array.from(o.children);
|
|
10
|
+
for (let i = 0; i < Math.min(n.length, h.length); i++)
|
|
11
|
+
r.push([n[i], h[i]]);
|
|
13
12
|
continue;
|
|
14
13
|
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const a = r.startsWith("url("), t = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(r);
|
|
18
|
-
if (a) {
|
|
19
|
-
const d = A(r);
|
|
20
|
-
if (!d) return r;
|
|
21
|
-
try {
|
|
22
|
-
const n = encodeURI(d);
|
|
23
|
-
if (u.has(n))
|
|
24
|
-
return `url(${u.get(n)})`;
|
|
25
|
-
{
|
|
26
|
-
const y = h.crossOrigin ? h.crossOrigin(n) : "anonymous", b = await B(n, 3e3, y);
|
|
27
|
-
return u.set(n, b), `url(${b})`;
|
|
28
|
-
}
|
|
29
|
-
} catch (n) {
|
|
30
|
-
return console.warn(
|
|
31
|
-
"[snapdom] Failed to inline background-image:",
|
|
32
|
-
d,
|
|
33
|
-
n
|
|
34
|
-
), r;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return r;
|
|
38
|
-
})
|
|
14
|
+
const y = p(c), a = await Promise.all(
|
|
15
|
+
y.map((n) => k(n, f))
|
|
39
16
|
);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
for (let r = 0; r < Math.min(f.length, p.length); r++)
|
|
45
|
-
o.push([f[r], p[r]]);
|
|
17
|
+
a.some((n) => n && n !== "none" && !/^url\(undefined\)/.test(n)) && (o.style.backgroundImage = a.join(", ")), t && t !== "transparent" && t !== "rgba(0, 0, 0, 0)" && (o.style.backgroundColor = t);
|
|
18
|
+
const g = Array.from(e.children), d = Array.from(o.children);
|
|
19
|
+
for (let n = 0; n < Math.min(g.length, d.length); n++)
|
|
20
|
+
r.push([g[n], d[n]]);
|
|
46
21
|
}
|
|
47
22
|
}
|
|
48
23
|
export {
|
|
49
|
-
|
|
24
|
+
B as inlineBackgroundImages
|
|
50
25
|
};
|
|
@@ -1,93 +1,92 @@
|
|
|
1
|
-
import { iconToImage as
|
|
2
|
-
import { getStyleKey as
|
|
3
|
-
import { getStyle as
|
|
4
|
-
async function
|
|
5
|
-
if (!(l instanceof Element) || !(
|
|
1
|
+
import { iconToImage as z } from "./fonts.js";
|
|
2
|
+
import { getStyleKey as V } from "../utils/cssTools.js";
|
|
3
|
+
import { getStyle as U, snapshotComputedStyle as I, parseContent as W, extractURL as j, fetchImage as A, safeEncodeURI as D, splitBackgroundImage as L, inlineSingleBackgroundEntry as $ } from "../utils/helpers.js";
|
|
4
|
+
async function R(l, i, g, F, h, w = !1) {
|
|
5
|
+
if (!(l instanceof Element) || !(i instanceof Element)) return;
|
|
6
6
|
for (const n of ["::before", "::after", "::first-letter"])
|
|
7
7
|
try {
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
8
|
+
const t = U(l, n);
|
|
9
|
+
if (!t || typeof t[Symbol.iterator] != "function") continue;
|
|
10
10
|
if (n === "::first-letter") {
|
|
11
11
|
const a = getComputedStyle(l);
|
|
12
|
-
if (!(
|
|
13
|
-
const
|
|
14
|
-
(
|
|
12
|
+
if (!(t.color !== a.color || t.fontSize !== a.fontSize || t.fontWeight !== a.fontWeight)) continue;
|
|
13
|
+
const d = Array.from(i.childNodes).find(
|
|
14
|
+
(e) => e.nodeType === Node.TEXT_NODE && e.textContent && e.textContent.trim().length > 0
|
|
15
15
|
);
|
|
16
|
-
if (!
|
|
17
|
-
const
|
|
16
|
+
if (!d) continue;
|
|
17
|
+
const p = d.textContent, f = p.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0], b = p.slice(f?.length || 0);
|
|
18
18
|
if (!f || /[\uD800-\uDFFF]/.test(f)) continue;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
19
|
+
const r = document.createElement("span");
|
|
20
|
+
r.textContent = f, r.dataset.snapdomPseudo = "::first-letter";
|
|
21
|
+
const s = I(t), N = V(s, "span", h);
|
|
22
|
+
g.set(r, N);
|
|
23
|
+
const x = document.createTextNode(b);
|
|
24
|
+
i.replaceChild(x, d), i.insertBefore(r, x);
|
|
25
25
|
continue;
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
const a =
|
|
27
|
+
const S = t.getPropertyValue("content"), u = t.getPropertyValue("background-image"), m = t.getPropertyValue("background-color"), T = S !== "none", y = u && u !== "none", C = m && m !== "transparent" && m !== "rgba(0, 0, 0, 0)";
|
|
28
|
+
if (T || y || C) {
|
|
29
|
+
const a = t.getPropertyValue("font-family"), B = parseInt(t.getPropertyValue("font-size")) || 32, d = parseInt(t.getPropertyValue("font-weight")) || !1, p = t.getPropertyValue("color") || "#000", o = document.createElement("span");
|
|
30
30
|
o.dataset.snapdomPseudo = n;
|
|
31
|
-
const f =
|
|
32
|
-
|
|
33
|
-
const
|
|
31
|
+
const f = I(t), b = V(f, "span", h);
|
|
32
|
+
g.set(o, b);
|
|
33
|
+
const r = a && /font.*awesome|material|bootstrap|glyphicons|ionicons|remixicon|simple-line-icons|octicons|feather|typicons|weathericons|lucide/i.test(
|
|
34
34
|
a
|
|
35
|
-
),
|
|
36
|
-
if (!
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
), s = W(S);
|
|
36
|
+
if (!w && r && s.length === 1) {
|
|
37
|
+
const e = document.createElement("img");
|
|
38
|
+
e.src = await z(
|
|
39
|
+
s,
|
|
40
40
|
a,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
),
|
|
45
|
-
} else if (
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
41
|
+
d,
|
|
42
|
+
B,
|
|
43
|
+
p
|
|
44
|
+
), e.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(e);
|
|
45
|
+
} else if (s.startsWith("url(")) {
|
|
46
|
+
const e = j(s);
|
|
47
|
+
if (e && e.trim() !== "")
|
|
48
48
|
try {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
} catch (
|
|
49
|
+
const c = document.createElement("img"), E = await A(D(e));
|
|
50
|
+
c.src = E, c.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(c);
|
|
51
|
+
} catch (c) {
|
|
52
52
|
console.error(
|
|
53
53
|
`[snapdom] Error in pseudo ${n} for`,
|
|
54
54
|
l,
|
|
55
|
-
|
|
55
|
+
c
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
|
-
} else !
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
n === "::before" ? r.insertBefore(o, r.firstChild) : r.appendChild(o);
|
|
58
|
+
} else !r && s && s !== "none" && (o.textContent = s);
|
|
59
|
+
if (y)
|
|
60
|
+
try {
|
|
61
|
+
const e = L(u), c = await Promise.all(
|
|
62
|
+
e.map((E) => $(E))
|
|
63
|
+
);
|
|
64
|
+
o.style.backgroundImage = c.join(", ");
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.warn(
|
|
67
|
+
`[snapdom] Failed to inline background-image for ${n}`,
|
|
68
|
+
e
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (C && (o.style.backgroundColor = m), !(o.childNodes.length > 0 || o.textContent && o.textContent.trim() !== "" || y || C)) continue;
|
|
72
|
+
n === "::before" ? i.insertBefore(o, i.firstChild) : i.appendChild(o);
|
|
74
73
|
}
|
|
75
|
-
} catch (
|
|
76
|
-
console.warn(`[snapdom] Failed to capture ${n} for`, l,
|
|
74
|
+
} catch (t) {
|
|
75
|
+
console.warn(`[snapdom] Failed to capture ${n} for`, l, t);
|
|
77
76
|
}
|
|
78
|
-
const
|
|
77
|
+
const P = Array.from(l.children), k = Array.from(i.children).filter(
|
|
79
78
|
(n) => !n.dataset.snapdomPseudo
|
|
80
79
|
);
|
|
81
|
-
for (let n = 0; n < Math.min(
|
|
82
|
-
await
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
p,
|
|
86
|
-
F,
|
|
80
|
+
for (let n = 0; n < Math.min(P.length, k.length); n++)
|
|
81
|
+
await R(
|
|
82
|
+
P[n],
|
|
83
|
+
k[n],
|
|
87
84
|
g,
|
|
88
|
-
|
|
85
|
+
F,
|
|
86
|
+
h,
|
|
87
|
+
w
|
|
89
88
|
);
|
|
90
89
|
}
|
|
91
90
|
export {
|
|
92
|
-
|
|
91
|
+
R as inlinePseudoElements
|
|
93
92
|
};
|
|
@@ -1,35 +1,52 @@
|
|
|
1
|
-
import { imageCache as
|
|
2
|
-
function
|
|
3
|
-
|
|
1
|
+
import { imageCache as l, computedStyleCache as m, bgCache as u } from "../core/cache.js";
|
|
2
|
+
async function w(t, e = {}) {
|
|
3
|
+
const n = t.startsWith("url("), a = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(
|
|
4
|
+
t
|
|
5
|
+
);
|
|
6
|
+
if (n) {
|
|
7
|
+
const r = d(t);
|
|
8
|
+
if (!r) return t;
|
|
9
|
+
const i = g(r);
|
|
10
|
+
if (u.has(i))
|
|
11
|
+
return e.skipInline ? void 0 : `url(${u.get(i)})`;
|
|
12
|
+
{
|
|
13
|
+
const s = e.crossOrigin ? e.crossOrigin(i) : "anonymous", o = await f(i, 3e3, s);
|
|
14
|
+
return u.set(i, o), e.skipInline ? void 0 : `url(${o})`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return t;
|
|
18
|
+
}
|
|
19
|
+
function I(t, { fast: e = !1 } = {}) {
|
|
20
|
+
if (e) return t();
|
|
4
21
|
"requestIdleCallback" in window ? requestIdleCallback(t, { timeout: 50 }) : setTimeout(t, 1);
|
|
5
22
|
}
|
|
6
|
-
function
|
|
23
|
+
function x(t, e = null) {
|
|
7
24
|
if (!(t instanceof Element))
|
|
8
|
-
return window.getComputedStyle(t,
|
|
9
|
-
let
|
|
10
|
-
if (
|
|
11
|
-
const a = window.getComputedStyle(t,
|
|
12
|
-
|
|
25
|
+
return window.getComputedStyle(t, e);
|
|
26
|
+
let n = m.get(t);
|
|
27
|
+
if (n || (n = /* @__PURE__ */ new Map(), m.set(t, n)), !n.has(e)) {
|
|
28
|
+
const a = window.getComputedStyle(t, e);
|
|
29
|
+
n.set(e, a);
|
|
13
30
|
}
|
|
14
|
-
return
|
|
31
|
+
return n.get(e);
|
|
15
32
|
}
|
|
16
|
-
function
|
|
17
|
-
let
|
|
18
|
-
if (
|
|
33
|
+
function C(t) {
|
|
34
|
+
let e = t.replace(/^['"]|['"]$/g, "");
|
|
35
|
+
if (e.startsWith("\\"))
|
|
19
36
|
try {
|
|
20
|
-
return String.fromCharCode(parseInt(
|
|
37
|
+
return String.fromCharCode(parseInt(e.replace("\\", ""), 16));
|
|
21
38
|
} catch {
|
|
22
|
-
return
|
|
39
|
+
return e;
|
|
23
40
|
}
|
|
24
|
-
return
|
|
41
|
+
return e;
|
|
25
42
|
}
|
|
26
|
-
function
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
let
|
|
30
|
-
return
|
|
43
|
+
function d(t) {
|
|
44
|
+
const e = t.indexOf("url(");
|
|
45
|
+
if (e === -1) return null;
|
|
46
|
+
let n = t.slice(e + 4).trim();
|
|
47
|
+
return n.endsWith(")") && (n = n.slice(0, -1).trim()), (n.startsWith('"') && n.endsWith('"') || n.startsWith("'") && n.endsWith("'")) && (n = n.slice(1, -1)), n;
|
|
31
48
|
}
|
|
32
|
-
function
|
|
49
|
+
function S(t) {
|
|
33
50
|
return [
|
|
34
51
|
/font\s*awesome/i,
|
|
35
52
|
/material\s*icons/i,
|
|
@@ -40,51 +57,83 @@ function p(t) {
|
|
|
40
57
|
/remix\s*icons/i,
|
|
41
58
|
/heroicons/i,
|
|
42
59
|
/lucide/i
|
|
43
|
-
].some((
|
|
60
|
+
].some((n) => n.test(t));
|
|
44
61
|
}
|
|
45
|
-
function
|
|
46
|
-
return
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
clearTimeout(
|
|
62
|
+
function f(t, e = 3e3, n = "anonymous") {
|
|
63
|
+
return l.has(t) ? Promise.resolve(l.get(t)) : new Promise((a, r) => {
|
|
64
|
+
const i = setTimeout(() => {
|
|
65
|
+
r(new Error("Image load timed out"));
|
|
66
|
+
}, e), s = new Image();
|
|
67
|
+
s.crossOrigin = n, s.onload = async () => {
|
|
68
|
+
clearTimeout(i);
|
|
52
69
|
try {
|
|
53
|
-
await
|
|
54
|
-
const
|
|
55
|
-
|
|
70
|
+
await s.decode();
|
|
71
|
+
const o = document.createElement("canvas");
|
|
72
|
+
o.width = s.width, o.height = s.height, o.getContext("2d").drawImage(s, 0, 0, o.width, o.height);
|
|
56
73
|
try {
|
|
57
|
-
const
|
|
58
|
-
|
|
74
|
+
const c = o.toDataURL("image/png");
|
|
75
|
+
l.set(t, c), a(c);
|
|
59
76
|
} catch {
|
|
60
|
-
|
|
77
|
+
r(new Error("CORS restrictions prevented image capture"));
|
|
61
78
|
}
|
|
62
|
-
} catch (
|
|
63
|
-
o
|
|
79
|
+
} catch (o) {
|
|
80
|
+
r(o);
|
|
64
81
|
}
|
|
65
|
-
},
|
|
66
|
-
clearTimeout(
|
|
67
|
-
new Error("Failed to load image: " + (
|
|
82
|
+
}, s.onerror = (o) => {
|
|
83
|
+
clearTimeout(i), r(
|
|
84
|
+
new Error("Failed to load image: " + (o.message || "Unknown error"))
|
|
68
85
|
);
|
|
69
|
-
},
|
|
86
|
+
}, s.src = t;
|
|
70
87
|
});
|
|
71
88
|
}
|
|
72
|
-
function
|
|
73
|
-
const
|
|
74
|
-
for (let
|
|
75
|
-
n
|
|
76
|
-
return
|
|
89
|
+
function U(t) {
|
|
90
|
+
const e = {};
|
|
91
|
+
for (let n of t)
|
|
92
|
+
e[n] = t.getPropertyValue(n);
|
|
93
|
+
return e;
|
|
77
94
|
}
|
|
78
|
-
function
|
|
95
|
+
function y() {
|
|
79
96
|
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
80
97
|
}
|
|
98
|
+
function k(t) {
|
|
99
|
+
if (!t || t === "none") return "";
|
|
100
|
+
let e = t.replace(/translate[XY]?\([^)]*\)/g, "");
|
|
101
|
+
return e = e.replace(/matrix\(([^)]+)\)/g, (n, a) => {
|
|
102
|
+
const r = a.split(",").map((i) => i.trim());
|
|
103
|
+
return r.length !== 6 ? `matrix(${a})` : (r[4] = "0", r[5] = "0", `matrix(${r.join(", ")})`);
|
|
104
|
+
}), e = e.replace(/matrix3d\(([^)]+)\)/g, (n, a) => {
|
|
105
|
+
const r = a.split(",").map((i) => i.trim());
|
|
106
|
+
return r.length !== 16 ? `matrix3d(${a})` : (r[12] = "0", r[13] = "0", `matrix3d(${r.join(", ")})`);
|
|
107
|
+
}), e.trim().replace(/\s{2,}/g, " ");
|
|
108
|
+
}
|
|
109
|
+
function g(t) {
|
|
110
|
+
if (/%[0-9A-Fa-f]{2}/.test(t)) return t;
|
|
111
|
+
try {
|
|
112
|
+
return encodeURI(t);
|
|
113
|
+
} catch {
|
|
114
|
+
return t;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function E(t) {
|
|
118
|
+
const e = [];
|
|
119
|
+
let n = 0, a = 0;
|
|
120
|
+
for (let r = 0; r < t.length; r++) {
|
|
121
|
+
const i = t[r];
|
|
122
|
+
i === "(" && n++, i === ")" && n--, i === "," && n === 0 && (e.push(t.slice(a, r).trim()), a = r + 1);
|
|
123
|
+
}
|
|
124
|
+
return e.push(t.slice(a).trim()), e;
|
|
125
|
+
}
|
|
81
126
|
export {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
127
|
+
d as extractURL,
|
|
128
|
+
f as fetchImage,
|
|
129
|
+
x as getStyle,
|
|
130
|
+
I as idle,
|
|
131
|
+
w as inlineSingleBackgroundEntry,
|
|
132
|
+
S as isIconFont,
|
|
133
|
+
y as isSafari,
|
|
134
|
+
C as parseContent,
|
|
135
|
+
g as safeEncodeURI,
|
|
136
|
+
U as snapshotComputedStyle,
|
|
137
|
+
E as splitBackgroundImage,
|
|
138
|
+
k as stripTranslate
|
|
90
139
|
};
|