@unicom-cloud/utils 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constant/keyboardCode.js +41 -40
- package/constant/platform.js +14 -16
- package/cookie/src/index.js +46 -46
- package/dayjs/index.js +15 -0
- package/decimal/decimal.js +56 -56
- package/event-emitter/index.js +14 -23
- package/file/fileToURL.js +8 -9
- package/file/saveAs.js +1 -1
- package/mock/MockWebSocket.js +67 -90
- package/mock/MockXMLHttpRequest.js +51 -61
- package/package.json +1 -1
- package/random/address.js +10 -10
- package/screenfull/index.js +43 -43
- package/snapdom/src/api/preCache.js +34 -24
- package/snapdom/src/api/snapdom.js +56 -56
- package/snapdom/src/core/cache.js +3 -2
- package/snapdom/src/core/capture.js +32 -32
- package/snapdom/src/core/clone.js +39 -38
- package/snapdom/src/core/prepare.js +10 -11
- package/snapdom/src/modules/background.js +45 -22
- package/snapdom/src/modules/fonts.js +148 -45
- package/snapdom/src/modules/images.js +7 -7
- package/snapdom/src/modules/pseudo.js +75 -45
- package/snapdom/src/modules/styles.js +7 -8
- package/snapdom/src/utils/helpers.js +56 -53
- package/tree/index.js +31 -32
- package/turbo-stream/src/encode.js +149 -152
- package/turbo-stream/src/shared.js +155 -173
|
@@ -1,91 +1,91 @@
|
|
|
1
1
|
import { captureDOM as v } from "../core/capture.js";
|
|
2
2
|
import { isSafari as R } from "../utils/helpers.js";
|
|
3
|
-
async function
|
|
4
|
-
const
|
|
5
|
-
return
|
|
3
|
+
async function x(e, { dpr: t = 1, scale: c = 1 }) {
|
|
4
|
+
const a = new Image();
|
|
5
|
+
return a.src = e, await a.decode(), R ? (a.width = a.width * c, a.height = a.height * c) : (a.width = a.width / c, a.height = a.height / c), a;
|
|
6
6
|
}
|
|
7
|
-
async function
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const s =
|
|
13
|
-
return s.scale(
|
|
7
|
+
async function p(e, { dpr: t = 1, scale: c = 1 } = {}) {
|
|
8
|
+
const a = new Image();
|
|
9
|
+
a.src = e, await a.decode();
|
|
10
|
+
const n = document.createElement("canvas"), o = a.width * c, g = a.height * c;
|
|
11
|
+
n.width = Math.ceil(o * t), n.height = Math.ceil(g * t);
|
|
12
|
+
const s = n.getContext("2d");
|
|
13
|
+
return s.scale(t, t), s.drawImage(a, 0, 0, o, g), n.style.width = `${o}px`, n.style.height = `${g}px`, n;
|
|
14
14
|
}
|
|
15
|
-
async function
|
|
16
|
-
const t = decodeURIComponent(
|
|
15
|
+
async function u(e) {
|
|
16
|
+
const t = decodeURIComponent(e.split(",")[1]);
|
|
17
17
|
return new Blob([t], { type: "image/svg+xml" });
|
|
18
18
|
}
|
|
19
|
-
async function
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
19
|
+
async function l(e, { dpr: t = 1, scale: c = 1 }, a) {
|
|
20
|
+
const n = await p(e, { dpr: t, scale: c });
|
|
21
|
+
if (!a) return n;
|
|
22
22
|
const o = document.createElement("canvas");
|
|
23
|
-
o.width =
|
|
23
|
+
o.width = n.width, o.height = n.height;
|
|
24
24
|
const g = o.getContext("2d");
|
|
25
|
-
return g.fillStyle =
|
|
25
|
+
return g.fillStyle = a, g.fillRect(0, 0, o.width, o.height), g.drawImage(n, 0, 0), o;
|
|
26
26
|
}
|
|
27
|
-
async function d(
|
|
28
|
-
const g = await
|
|
29
|
-
return s.src = g.toDataURL(`image/${o}`,
|
|
27
|
+
async function d(e, { dpr: t = 1, scale: c = 1, backgroundColor: a = "#fff", quality: n }, o = "png") {
|
|
28
|
+
const g = await l(e, { dpr: t, scale: c }, a), s = new Image();
|
|
29
|
+
return s.src = g.toDataURL(`image/${o}`, n), await s.decode(), s.style.width = `${g.width / t}px`, s.style.height = `${g.height / t}px`, s;
|
|
30
30
|
}
|
|
31
|
-
async function
|
|
31
|
+
async function I(e, {
|
|
32
32
|
dpr: t = 1,
|
|
33
|
-
scale:
|
|
34
|
-
backgroundColor:
|
|
35
|
-
format:
|
|
33
|
+
scale: c = 1,
|
|
34
|
+
backgroundColor: a = "#fff",
|
|
35
|
+
format: n = "png",
|
|
36
36
|
filename: o = "capture"
|
|
37
37
|
} = {}) {
|
|
38
|
-
if (
|
|
39
|
-
const b = await
|
|
40
|
-
w.href =
|
|
38
|
+
if (n === "svg") {
|
|
39
|
+
const b = await u(e), h = URL.createObjectURL(b), w = document.createElement("a");
|
|
40
|
+
w.href = h, w.download = `${o}.svg`, w.click(), URL.revokeObjectURL(h);
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
const g = ["jpg", "jpeg", "webp"].includes(
|
|
43
|
+
const g = ["jpg", "jpeg", "webp"].includes(n) ? "#fff" : void 0, m = await l(e, { dpr: t, scale: c }, a ?? g), f = {
|
|
44
44
|
jpg: "image/jpeg",
|
|
45
45
|
jpeg: "image/jpeg",
|
|
46
46
|
png: "image/png",
|
|
47
47
|
webp: "image/webp"
|
|
48
|
-
}[
|
|
49
|
-
r.href = y, r.download = `${o}.${
|
|
48
|
+
}[n] || "image/png", y = m.toDataURL(f), r = document.createElement("a");
|
|
49
|
+
r.href = y, r.download = `${o}.${n}`, r.click();
|
|
50
50
|
}
|
|
51
|
-
async function i(
|
|
52
|
-
if (t = { scale: 1, ...t }, !
|
|
53
|
-
return await i.capture(
|
|
51
|
+
async function i(e, t = {}) {
|
|
52
|
+
if (t = { scale: 1, ...t }, !e) throw new Error("Element cannot be null or undefined");
|
|
53
|
+
return await i.capture(e, t);
|
|
54
54
|
}
|
|
55
|
-
i.capture = async (
|
|
56
|
-
const
|
|
55
|
+
i.capture = async (e, t = {}) => {
|
|
56
|
+
const c = await v(e, t), a = window.devicePixelRatio || 1, n = t.scale || 1;
|
|
57
57
|
return {
|
|
58
|
-
url:
|
|
58
|
+
url: c,
|
|
59
59
|
options: t,
|
|
60
|
-
toRaw: () =>
|
|
61
|
-
toImg: () =>
|
|
62
|
-
toCanvas: () =>
|
|
63
|
-
toBlob: () =>
|
|
64
|
-
toPng: (o) => d(
|
|
65
|
-
toJpg: (o) => d(
|
|
66
|
-
toWebp: (o) => d(
|
|
60
|
+
toRaw: () => c,
|
|
61
|
+
toImg: () => x(c, { dpr: a, scale: n }),
|
|
62
|
+
toCanvas: () => p(c, { dpr: a, scale: n }),
|
|
63
|
+
toBlob: () => u(c),
|
|
64
|
+
toPng: (o) => d(c, { dpr: a, scale: n, ...o }, "png"),
|
|
65
|
+
toJpg: (o) => d(c, { dpr: a, scale: n, ...o }, "jpeg"),
|
|
66
|
+
toWebp: (o) => d(c, { dpr: a, scale: n, ...o }, "webp"),
|
|
67
67
|
download: ({
|
|
68
68
|
format: o = "png",
|
|
69
69
|
filename: g = "capture",
|
|
70
70
|
backgroundColor: s
|
|
71
|
-
} = {}) =>
|
|
71
|
+
} = {}) => I(c, { dpr: a, scale: n, backgroundColor: s, format: o, filename: g })
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
|
-
i.toRaw = async (
|
|
75
|
-
i.toImg = async (
|
|
76
|
-
i.toCanvas = async (
|
|
77
|
-
i.toBlob = async (
|
|
78
|
-
i.toPng = async (
|
|
79
|
-
i.toJpg = async (
|
|
80
|
-
i.toWebp = async (
|
|
81
|
-
i.download = async (
|
|
74
|
+
i.toRaw = async (e, t) => (await i.capture(e, t)).toRaw();
|
|
75
|
+
i.toImg = async (e, t) => (await i.capture(e, t)).toImg();
|
|
76
|
+
i.toCanvas = async (e, t) => (await i.capture(e, t)).toCanvas();
|
|
77
|
+
i.toBlob = async (e, t) => (await i.capture(e, t)).toBlob();
|
|
78
|
+
i.toPng = async (e, t) => (await i.capture(e, t)).toPng(t);
|
|
79
|
+
i.toJpg = async (e, t) => (await i.capture(e, t)).toJpg(t);
|
|
80
|
+
i.toWebp = async (e, t) => (await i.capture(e, t)).toWebp(t);
|
|
81
|
+
i.download = async (e, t = {}) => {
|
|
82
82
|
const {
|
|
83
|
-
format:
|
|
84
|
-
filename:
|
|
85
|
-
backgroundColor:
|
|
83
|
+
format: c = "png",
|
|
84
|
+
filename: a = "capture",
|
|
85
|
+
backgroundColor: n,
|
|
86
86
|
...o
|
|
87
87
|
} = t;
|
|
88
|
-
return await (await i.capture(
|
|
88
|
+
return await (await i.capture(e, o)).download({ format: c, filename: a, backgroundColor: n });
|
|
89
89
|
};
|
|
90
90
|
export {
|
|
91
91
|
i as snapdom
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
const e = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(),
|
|
1
|
+
const e = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new Set();
|
|
2
2
|
export {
|
|
3
3
|
t as baseCSSCache,
|
|
4
4
|
a as bgCache,
|
|
5
|
-
|
|
5
|
+
s as computedStyleCache,
|
|
6
6
|
n as defaultStylesCache,
|
|
7
7
|
e as imageCache,
|
|
8
|
+
o as processedFontURLs,
|
|
8
9
|
c as resourceCache
|
|
9
10
|
};
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
+
import { baseCSSCache as w } from "./cache.js";
|
|
1
2
|
import { inlineBackgroundImages as $ } from "../modules/background.js";
|
|
2
3
|
import { embedCustomFonts as B } from "../modules/fonts.js";
|
|
3
4
|
import { inlineImages as E } from "../modules/images.js";
|
|
4
5
|
import { collectUsedTagNames as F, generateDedupedBaseCSS as I } from "../utils/cssTools.js";
|
|
5
6
|
import { idle as i, isSafari as P } from "../utils/helpers.js";
|
|
6
|
-
import { baseCSSCache as g } from "./cache.js";
|
|
7
7
|
import { prepareClone as z } from "./prepare.js";
|
|
8
|
-
async function L(a,
|
|
8
|
+
async function L(a, l = {}) {
|
|
9
9
|
if (!a) throw new Error("Element cannot be null or undefined");
|
|
10
10
|
const {
|
|
11
|
-
compress:
|
|
12
|
-
embedFonts:
|
|
13
|
-
fast:
|
|
14
|
-
scale:
|
|
15
|
-
} =
|
|
16
|
-
let t,
|
|
17
|
-
if ({ clone: t, classCSS:
|
|
11
|
+
compress: d = !0,
|
|
12
|
+
embedFonts: m = !1,
|
|
13
|
+
fast: o = !0,
|
|
14
|
+
scale: f = 1
|
|
15
|
+
} = l;
|
|
16
|
+
let t, h, p, u = "", r = "", S, v;
|
|
17
|
+
if ({ clone: t, classCSS: h, styleCache: p } = await z(
|
|
18
18
|
a,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
d,
|
|
20
|
+
m
|
|
21
21
|
), await new Promise((e) => {
|
|
22
22
|
i(
|
|
23
23
|
async () => {
|
|
24
|
-
await E(t), e();
|
|
24
|
+
await E(t, l), e();
|
|
25
25
|
},
|
|
26
|
-
{ fast:
|
|
26
|
+
{ fast: o }
|
|
27
27
|
);
|
|
28
28
|
}), await new Promise((e) => {
|
|
29
29
|
i(
|
|
30
30
|
async () => {
|
|
31
|
-
await $(a, t, p), e();
|
|
31
|
+
await $(a, t, p, l), e();
|
|
32
32
|
},
|
|
33
|
-
{ fast:
|
|
33
|
+
{ fast: o }
|
|
34
34
|
);
|
|
35
|
-
}),
|
|
35
|
+
}), m && await new Promise((e) => {
|
|
36
36
|
i(
|
|
37
37
|
async () => {
|
|
38
|
-
|
|
38
|
+
u = await B({ ignoreIconFonts: !m }), e();
|
|
39
39
|
},
|
|
40
|
-
{ fast:
|
|
40
|
+
{ fast: o }
|
|
41
41
|
);
|
|
42
|
-
}),
|
|
43
|
-
const e = F(t).sort(),
|
|
44
|
-
|
|
42
|
+
}), d) {
|
|
43
|
+
const e = F(t).sort(), s = e.join(",");
|
|
44
|
+
w.has(s) ? r = w.get(s) : await new Promise((c) => {
|
|
45
45
|
i(
|
|
46
46
|
() => {
|
|
47
|
-
r = I(e),
|
|
47
|
+
r = I(e), w.set(s, r), c();
|
|
48
48
|
},
|
|
49
|
-
{ fast:
|
|
49
|
+
{ fast: o }
|
|
50
50
|
);
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
await new Promise((e) => {
|
|
54
54
|
i(
|
|
55
55
|
() => {
|
|
56
|
-
const
|
|
57
|
-
t.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), t.style.transformOrigin = "top left",
|
|
58
|
-
const
|
|
56
|
+
const s = a.getBoundingClientRect(), c = Math.ceil(s.width), C = Math.ceil(s.height);
|
|
57
|
+
t.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), t.style.transformOrigin = "top left", f !== 1 && P() && (t.style.scale = `${f}`);
|
|
58
|
+
const b = "http://www.w3.org/2000/svg", n = document.createElementNS(b, "foreignObject");
|
|
59
59
|
n.setAttribute("width", "100%"), n.setAttribute("height", "100%");
|
|
60
|
-
const
|
|
61
|
-
|
|
60
|
+
const y = document.createElement("style");
|
|
61
|
+
y.textContent = r + u + "svg{overflow:visible;}" + h, n.appendChild(y), n.appendChild(t);
|
|
62
62
|
const x = new XMLSerializer().serializeToString(n);
|
|
63
|
-
|
|
63
|
+
v = `<svg xmlns="${b}" width="${c}" height="${C}" viewBox="0 0 ${c} ${C}">` + x + "</svg>", S = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(v)}`, e();
|
|
64
64
|
},
|
|
65
|
-
{ fast:
|
|
65
|
+
{ fast: o }
|
|
66
66
|
);
|
|
67
67
|
});
|
|
68
|
-
const
|
|
69
|
-
return
|
|
68
|
+
const g = document.getElementById("snapdom-sandbox");
|
|
69
|
+
return g && g.style.position === "absolute" && g.remove(), S;
|
|
70
70
|
}
|
|
71
71
|
export {
|
|
72
72
|
L as captureDOM
|
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
import { inlineAllStyles as
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return i.style.cssText = `display: inline-block; width: ${e.width}px; height: ${e.height}px; visibility: hidden;`, i;
|
|
1
|
+
import { inlineAllStyles as f } from "../modules/styles.js";
|
|
2
|
+
function h(e, c, r, n, s) {
|
|
3
|
+
if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "exclude") {
|
|
4
|
+
const t = document.createElement("div"), i = e.getBoundingClientRect();
|
|
5
|
+
return t.style.cssText = `display: inline-block; width: ${i.width}px; height: ${i.height}px; visibility: hidden;`, t;
|
|
7
6
|
}
|
|
8
|
-
if (
|
|
9
|
-
const
|
|
10
|
-
return
|
|
7
|
+
if (e.tagName === "IFRAME") {
|
|
8
|
+
const t = document.createElement("div");
|
|
9
|
+
return t.textContent = "", t.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;`, t;
|
|
11
10
|
}
|
|
12
|
-
if (
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
return
|
|
11
|
+
if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "placeholder") {
|
|
12
|
+
const t = e.cloneNode(!1);
|
|
13
|
+
n.set(t, e), f(e, t, c, r, s);
|
|
14
|
+
const i = document.createElement("div");
|
|
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;
|
|
17
16
|
}
|
|
18
|
-
if (
|
|
19
|
-
const
|
|
20
|
-
return
|
|
17
|
+
if (e.tagName === "CANVAS") {
|
|
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;
|
|
21
20
|
}
|
|
22
|
-
if (
|
|
23
|
-
if (
|
|
24
|
-
const
|
|
25
|
-
if (customElements.get(
|
|
21
|
+
if (e.nodeType === Node.TEXT_NODE) {
|
|
22
|
+
if (e.parentElement?.shadowRoot) {
|
|
23
|
+
const t = e.parentElement.tagName.toLowerCase();
|
|
24
|
+
if (customElements.get(t)) return null;
|
|
26
25
|
}
|
|
27
|
-
return
|
|
26
|
+
return e.cloneNode(!0);
|
|
28
27
|
}
|
|
29
|
-
if (
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
if (e.nodeType !== Node.ELEMENT_NODE) return e.cloneNode(!0);
|
|
29
|
+
const l = e.cloneNode(!1);
|
|
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
|
+
t.value === e.value ? t.setAttribute("selected", "") : t.removeAttribute("selected");
|
|
32
|
+
})), f(e, l, c, r, s);
|
|
33
|
+
const o = document.createDocumentFragment();
|
|
34
|
+
if (e.childNodes.forEach((t) => {
|
|
35
|
+
const i = h(
|
|
36
|
+
t,
|
|
38
37
|
c,
|
|
39
|
-
|
|
38
|
+
r,
|
|
39
|
+
n,
|
|
40
|
+
s
|
|
40
41
|
);
|
|
41
|
-
|
|
42
|
-
}),
|
|
43
|
-
const
|
|
44
|
-
|
|
42
|
+
i && o.appendChild(i);
|
|
43
|
+
}), l.appendChild(o), e.shadowRoot) {
|
|
44
|
+
const t = Array.from(e.shadowRoot.children).filter((a) => a.tagName !== "STYLE").map((a) => h(a, c, r, n)).filter(Boolean), i = document.createDocumentFragment();
|
|
45
|
+
t.forEach((a) => i.appendChild(a)), l.appendChild(i);
|
|
45
46
|
}
|
|
46
|
-
return
|
|
47
|
+
return l;
|
|
47
48
|
}
|
|
48
49
|
export {
|
|
49
|
-
|
|
50
|
+
h as deepClone
|
|
50
51
|
};
|
|
@@ -1,36 +1,35 @@
|
|
|
1
|
-
import { inlinePseudoElements as
|
|
2
|
-
import { generateCSSClasses as
|
|
3
|
-
import { deepClone as
|
|
4
|
-
async function
|
|
5
|
-
var p;
|
|
1
|
+
import { inlinePseudoElements as m } from "../modules/pseudo.js";
|
|
2
|
+
import { generateCSSClasses as h } from "../utils/cssTools.js";
|
|
3
|
+
import { deepClone as g } from "./clone.js";
|
|
4
|
+
async function S(f, r = !1, p = !1) {
|
|
6
5
|
const l = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new Map();
|
|
7
6
|
let c;
|
|
8
7
|
try {
|
|
9
|
-
c =
|
|
8
|
+
c = g(f, l, i, d, r);
|
|
10
9
|
} catch (e) {
|
|
11
10
|
throw console.warn("deepClone failed:", e), e;
|
|
12
11
|
}
|
|
13
12
|
try {
|
|
14
|
-
await
|
|
13
|
+
await m(
|
|
15
14
|
f,
|
|
16
15
|
c,
|
|
17
16
|
l,
|
|
18
17
|
i,
|
|
19
18
|
r,
|
|
20
|
-
|
|
19
|
+
p
|
|
21
20
|
);
|
|
22
21
|
} catch (e) {
|
|
23
22
|
console.warn("inlinePseudoElements failed:", e);
|
|
24
23
|
}
|
|
25
24
|
let y = "";
|
|
26
25
|
if (r) {
|
|
27
|
-
const e =
|
|
26
|
+
const e = h(l);
|
|
28
27
|
y = Array.from(e.entries()).map(([t, n]) => `.${n}{${t}}`).join("");
|
|
29
28
|
for (const [t, n] of l.entries()) {
|
|
30
29
|
if (t.tagName === "STYLE") continue;
|
|
31
30
|
const s = e.get(n);
|
|
32
31
|
s && t.classList.add(s);
|
|
33
|
-
const a =
|
|
32
|
+
const a = t.style?.backgroundImage;
|
|
34
33
|
t.removeAttribute("style"), a && a !== "none" && (t.style.backgroundImage = a);
|
|
35
34
|
}
|
|
36
35
|
} else
|
|
@@ -49,5 +48,5 @@ async function b(f, r = !1, m = !1) {
|
|
|
49
48
|
return { clone: c, classCSS: y, styleCache: i };
|
|
50
49
|
}
|
|
51
50
|
export {
|
|
52
|
-
|
|
51
|
+
S as prepareClone
|
|
53
52
|
};
|
|
@@ -1,27 +1,50 @@
|
|
|
1
|
-
import { bgCache as
|
|
2
|
-
import { getStyle as
|
|
3
|
-
async function
|
|
4
|
-
const
|
|
5
|
-
for (;
|
|
6
|
-
const [
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
const e =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let r;
|
|
15
|
-
a.has(n) ? r = a.get(n) : (r = await m(n), a.set(n, r)), l.style.backgroundImage = `url(${r})`;
|
|
16
|
-
} catch {
|
|
17
|
-
l.style.backgroundImage = "none";
|
|
18
|
-
}
|
|
1
|
+
import { bgCache as u } from "../core/cache.js";
|
|
2
|
+
import { getStyle as C, extractURL as A, fetchImage as B } from "../utils/helpers.js";
|
|
3
|
+
async function O(k, w, c, h = {}) {
|
|
4
|
+
const o = [[k, w]];
|
|
5
|
+
for (; o.length; ) {
|
|
6
|
+
const [e, i] = o.shift(), l = c.get(e) || C(e);
|
|
7
|
+
c.has(e) || c.set(e, l);
|
|
8
|
+
const g = l.getPropertyValue("background-image"), s = l.getPropertyValue("background-color");
|
|
9
|
+
if (!g || g === "none") {
|
|
10
|
+
const r = Array.from(e.children), a = Array.from(i.children);
|
|
11
|
+
for (let t = 0; t < Math.min(r.length, a.length); t++)
|
|
12
|
+
o.push([r[t], a[t]]);
|
|
13
|
+
continue;
|
|
19
14
|
}
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
const U = g.split(/,(?=(?:[^()]*\([^()]*\))*[^()]*$)/).map((r) => r.trim()), m = await Promise.all(
|
|
16
|
+
U.map(async (r) => {
|
|
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
|
+
})
|
|
39
|
+
);
|
|
40
|
+
m.some(
|
|
41
|
+
(r) => r && r !== "none" && !/^url\(undefined\)/.test(r)
|
|
42
|
+
) && (i.style.backgroundImage = m.join(", ")), s && s !== "transparent" && s !== "rgba(0, 0, 0, 0)" && (i.style.backgroundColor = s);
|
|
43
|
+
const f = Array.from(e.children), p = Array.from(i.children);
|
|
44
|
+
for (let r = 0; r < Math.min(f.length, p.length); r++)
|
|
45
|
+
o.push([f[r], p[r]]);
|
|
23
46
|
}
|
|
24
47
|
}
|
|
25
48
|
export {
|
|
26
|
-
|
|
49
|
+
O as inlineBackgroundImages
|
|
27
50
|
};
|