@unicom-cloud/utils 0.1.12 → 0.1.13
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/filesize/src/constants.js +22 -22
- package/filesize/src/filesize.js +32 -33
- package/package.json +1 -1
- package/snapdom/src/api/preCache.js +23 -23
- package/snapdom/src/api/snapdom.js +42 -42
- package/snapdom/src/core/cache.js +19 -8
- package/snapdom/src/core/capture.js +60 -59
- package/snapdom/src/core/clone.js +96 -31
- package/snapdom/src/core/prepare.js +35 -38
- package/snapdom/src/modules/background.js +29 -20
- package/snapdom/src/modules/fonts.js +97 -105
- package/snapdom/src/modules/pseudo.js +32 -32
- package/snapdom/src/modules/styles.js +22 -22
- package/snapdom/src/utils/cssTools.js +41 -41
- package/snapdom/src/utils/helpers.js +143 -146
- package/tree/index.js +1 -1
- package/tree/search/index.js +90 -0
- package/tree.js +1 -1
- package/types/filesize/src/constants.d.ts +12 -12
- package/types/filesize/src/filesize.d.ts +63 -22
- package/types/snapdom/src/core/cache.d.ts +17 -11
- package/types/snapdom/src/core/capture.d.ts +4 -0
- package/types/snapdom/src/core/clone.d.ts +4 -5
- package/types/snapdom/src/core/prepare.d.ts +8 -1
- package/types/snapdom/src/modules/background.d.ts +1 -2
- package/types/snapdom/src/modules/pseudo.d.ts +1 -3
- package/types/snapdom/src/modules/styles.d.ts +1 -1
- package/types/snapdom/src/utils/cssTools.d.ts +1 -2
- package/types/tree/index.d.ts +1 -1
- package/types/tree/search/index.d.ts +80 -0
- package/types/ui-color/index.d.ts +28 -3
- package/ui-color/index.js +70 -63
- package/uiColor.js +19 -18
- package/tree/searchTree.js +0 -54
- package/types/tree/searchTree.d.ts +0 -20
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { cache as I } from "../core/cache.js";
|
|
2
|
+
import { iconToImage as T } from "./fonts.js";
|
|
3
|
+
import { isIconFont as $ } from "./iconFonts.js";
|
|
3
4
|
import { getStyleKey as N } from "../utils/cssTools.js";
|
|
4
|
-
import { getStyle as
|
|
5
|
-
async function
|
|
5
|
+
import { getStyle as z, snapshotComputedStyle as V, parseContent as U, extractURL as W, fetchImage as j, safeEncodeURI as A, splitBackgroundImage as D, inlineSingleBackgroundEntry as L } from "../utils/helpers.js";
|
|
6
|
+
async function R(c, r, h, F = !1, S) {
|
|
6
7
|
if (!(c instanceof Element) || !(r instanceof Element)) return;
|
|
7
8
|
for (const n of ["::before", "::after", "::first-letter"])
|
|
8
9
|
try {
|
|
9
|
-
const t =
|
|
10
|
+
const t = z(c, n);
|
|
10
11
|
if (!t || typeof t[Symbol.iterator] != "function") continue;
|
|
11
12
|
if (n === "::first-letter") {
|
|
12
13
|
const l = getComputedStyle(c);
|
|
@@ -19,36 +20,37 @@ async function M(c, r, h, F, u, T = !1, w) {
|
|
|
19
20
|
if (!f || /[\uD800-\uDFFF]/.test(f)) continue;
|
|
20
21
|
const a = document.createElement("span");
|
|
21
22
|
a.textContent = f, a.dataset.snapdomPseudo = "::first-letter";
|
|
22
|
-
const s = V(t),
|
|
23
|
-
|
|
23
|
+
const s = V(t), B = N(s, "span", h);
|
|
24
|
+
I.preStyleMap.set(a, B);
|
|
24
25
|
const E = document.createTextNode(x);
|
|
25
26
|
r.replaceChild(E, d), r.insertBefore(a, E);
|
|
26
27
|
continue;
|
|
27
28
|
}
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
const l = t.getPropertyValue("font-family"),
|
|
29
|
+
const u = t.getPropertyValue("content"), y = t.getPropertyValue("background-image"), p = t.getPropertyValue("background-color"), M = u !== "none", C = y && y !== "none", b = p && p !== "transparent" && p !== "rgba(0, 0, 0, 0)";
|
|
30
|
+
if (M || C || b) {
|
|
31
|
+
const l = t.getPropertyValue("font-family"), m = parseInt(t.getPropertyValue("font-size")) || 32, d = parseInt(t.getPropertyValue("font-weight")) || !1, g = t.getPropertyValue("color") || "#000", o = document.createElement("span");
|
|
31
32
|
o.dataset.snapdomPseudo = n;
|
|
32
|
-
const f = V(t), x = N(f, "span",
|
|
33
|
-
|
|
34
|
-
const a =
|
|
35
|
-
|
|
33
|
+
const f = V(t), x = N(f, "span", h);
|
|
34
|
+
I.preStyleMap.set(o, x);
|
|
35
|
+
const a = $(l);
|
|
36
|
+
let s;
|
|
37
|
+
if (/counter\s*\(|counters\s*\(/.test(u) ? s = "- " : s = U(u), a && s.length === 1) {
|
|
36
38
|
const e = document.createElement("img");
|
|
37
|
-
e.src = await
|
|
39
|
+
e.src = await T(
|
|
38
40
|
s,
|
|
39
41
|
l,
|
|
40
42
|
d,
|
|
41
|
-
|
|
43
|
+
m,
|
|
42
44
|
g
|
|
43
|
-
), e.style = `width:${
|
|
45
|
+
), e.style = `width:${m}px;height:auto;object-fit:contain;`, o.appendChild(e);
|
|
44
46
|
} else if (s.startsWith("url(")) {
|
|
45
|
-
const e =
|
|
47
|
+
const e = W(s);
|
|
46
48
|
if (e && e.trim() !== "")
|
|
47
49
|
try {
|
|
48
|
-
const i = document.createElement("img"), P = await
|
|
49
|
-
|
|
50
|
+
const i = document.createElement("img"), P = await j(
|
|
51
|
+
A(e, { useProxy: S })
|
|
50
52
|
);
|
|
51
|
-
i.src = P, i.style = `width:${
|
|
53
|
+
i.src = P, i.style = `width:${m}px;height:auto;object-fit:contain;`, o.appendChild(i);
|
|
52
54
|
} catch (i) {
|
|
53
55
|
console.error(
|
|
54
56
|
`[snapdom] Error in pseudo ${n} for`,
|
|
@@ -59,8 +61,8 @@ async function M(c, r, h, F, u, T = !1, w) {
|
|
|
59
61
|
} else !a && s && s !== "none" && (o.textContent = s);
|
|
60
62
|
if (C)
|
|
61
63
|
try {
|
|
62
|
-
const e =
|
|
63
|
-
e.map((P) =>
|
|
64
|
+
const e = D(y), i = await Promise.all(
|
|
65
|
+
e.map((P) => L(P))
|
|
64
66
|
);
|
|
65
67
|
o.style.backgroundImage = i.join(", ");
|
|
66
68
|
} catch (e) {
|
|
@@ -69,26 +71,24 @@ async function M(c, r, h, F, u, T = !1, w) {
|
|
|
69
71
|
e
|
|
70
72
|
);
|
|
71
73
|
}
|
|
72
|
-
if (b && (o.style.backgroundColor =
|
|
74
|
+
if (b && (o.style.backgroundColor = p), !(o.childNodes.length > 0 || o.textContent && o.textContent.trim() !== "" || C || b)) continue;
|
|
73
75
|
n === "::before" ? r.insertBefore(o, r.firstChild) : r.appendChild(o);
|
|
74
76
|
}
|
|
75
77
|
} catch (t) {
|
|
76
78
|
console.warn(`[snapdom] Failed to capture ${n} for`, c, t);
|
|
77
79
|
}
|
|
78
|
-
const
|
|
80
|
+
const w = Array.from(c.children), k = Array.from(r.children).filter(
|
|
79
81
|
(n) => !n.dataset.snapdomPseudo
|
|
80
82
|
);
|
|
81
|
-
for (let n = 0; n < Math.min(
|
|
82
|
-
await
|
|
83
|
-
|
|
83
|
+
for (let n = 0; n < Math.min(w.length, k.length); n++)
|
|
84
|
+
await R(
|
|
85
|
+
w[n],
|
|
84
86
|
k[n],
|
|
85
87
|
h,
|
|
86
88
|
F,
|
|
87
|
-
|
|
88
|
-
T,
|
|
89
|
-
w
|
|
89
|
+
S
|
|
90
90
|
);
|
|
91
91
|
}
|
|
92
92
|
export {
|
|
93
|
-
|
|
93
|
+
R as inlinePseudoElements
|
|
94
94
|
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
for (let
|
|
7
|
-
const
|
|
8
|
-
let
|
|
9
|
-
(
|
|
1
|
+
import { cache as e } from "../core/cache.js";
|
|
2
|
+
import { getStyleKey as y } from "../utils/cssTools.js";
|
|
3
|
+
import { getStyle as m } from "../utils/helpers.js";
|
|
4
|
+
function g(t) {
|
|
5
|
+
const a = {};
|
|
6
|
+
for (let o = 0; o < t.length; o++) {
|
|
7
|
+
const s = t[o];
|
|
8
|
+
let n = t.getPropertyValue(s);
|
|
9
|
+
(s === "background-image" || s === "content") && n.includes("url(") && !n.includes("data:") && (n = "none"), a[s] = n;
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return a;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function d(t, a, o) {
|
|
14
14
|
if (t.tagName === "STYLE") return;
|
|
15
|
-
e.has(t) || e.set(t,
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
18
|
-
const
|
|
19
|
-
|
|
15
|
+
e.preStyle.has(t) || e.preStyle.set(t, m(t));
|
|
16
|
+
const s = e.preStyle.get(t);
|
|
17
|
+
if (!e.snapshot.has(t)) {
|
|
18
|
+
const p = g(s);
|
|
19
|
+
e.snapshot.set(t, p);
|
|
20
20
|
}
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
-
|
|
21
|
+
const n = e.snapshot.get(t), l = Object.entries(n).sort(([p], [r]) => p.localeCompare(r)).map(([p, r]) => `${p}:${r}`).join(";");
|
|
22
|
+
if (e.snapshotKey.has(l)) {
|
|
23
|
+
e.preStyleMap.set(a, e.snapshotKey.get(l));
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
26
|
+
const h = t.tagName?.toLowerCase() || "div", i = y(n, h, o);
|
|
27
|
+
e.snapshotKey.set(l, i), e.preStyleMap.set(a, i);
|
|
28
28
|
}
|
|
29
29
|
export {
|
|
30
|
-
|
|
30
|
+
d as inlineAllStyles
|
|
31
31
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cache as r } from "../core/cache.js";
|
|
2
2
|
const d = [
|
|
3
3
|
"div",
|
|
4
4
|
"span",
|
|
@@ -39,12 +39,12 @@ const d = [
|
|
|
39
39
|
"th"
|
|
40
40
|
];
|
|
41
41
|
function u() {
|
|
42
|
-
for (let
|
|
43
|
-
c(
|
|
42
|
+
for (let e of d)
|
|
43
|
+
c(e);
|
|
44
44
|
}
|
|
45
|
-
function c(
|
|
46
|
-
if (r.has(
|
|
47
|
-
return r.get(
|
|
45
|
+
function c(e) {
|
|
46
|
+
if (r.defaultStyle.has(e))
|
|
47
|
+
return r.defaultStyle.get(e);
|
|
48
48
|
if ((/* @__PURE__ */ new Set([
|
|
49
49
|
"script",
|
|
50
50
|
"style",
|
|
@@ -52,54 +52,54 @@ function c(t) {
|
|
|
52
52
|
"link",
|
|
53
53
|
"noscript",
|
|
54
54
|
"template"
|
|
55
|
-
])).has(
|
|
55
|
+
])).has(e)) {
|
|
56
56
|
const o = {};
|
|
57
|
-
return r.set(
|
|
57
|
+
return r.defaultStyle.set(e, o), o;
|
|
58
58
|
}
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
const n = document.createElement(
|
|
62
|
-
n.style.all = "initial",
|
|
63
|
-
const
|
|
64
|
-
for (let o of
|
|
65
|
-
|
|
66
|
-
return
|
|
59
|
+
let t = document.getElementById("snapdom-sandbox");
|
|
60
|
+
t || (t = document.createElement("div"), t.id = "snapdom-sandbox", t.style.position = "absolute", t.style.left = "-9999px", t.style.top = "-9999px", t.style.width = "0", t.style.height = "0", t.style.overflow = "hidden", document.body.appendChild(t));
|
|
61
|
+
const n = document.createElement(e);
|
|
62
|
+
n.style.all = "initial", t.appendChild(n);
|
|
63
|
+
const a = getComputedStyle(n), l = {};
|
|
64
|
+
for (let o of a)
|
|
65
|
+
l[o] = a.getPropertyValue(o);
|
|
66
|
+
return t.removeChild(n), r.defaultStyle.set(e, l), l;
|
|
67
67
|
}
|
|
68
|
-
function p(
|
|
69
|
-
const n = [],
|
|
70
|
-
for (let [
|
|
71
|
-
if (!
|
|
72
|
-
o && n.push(`${
|
|
68
|
+
function p(e, s, t = !1) {
|
|
69
|
+
const n = [], a = c(s);
|
|
70
|
+
for (let [l, o] of Object.entries(e))
|
|
71
|
+
if (!t)
|
|
72
|
+
o && n.push(`${l}:${o}`);
|
|
73
73
|
else {
|
|
74
|
-
const i = l
|
|
75
|
-
o && o !== i && n.push(`${
|
|
74
|
+
const i = a[l];
|
|
75
|
+
o && o !== i && n.push(`${l}:${o}`);
|
|
76
76
|
}
|
|
77
77
|
return n.sort().join(";");
|
|
78
78
|
}
|
|
79
|
-
function y(
|
|
79
|
+
function y(e) {
|
|
80
80
|
const s = /* @__PURE__ */ new Set();
|
|
81
|
-
return
|
|
81
|
+
return e.nodeType !== Node.ELEMENT_NODE && e.nodeType !== Node.DOCUMENT_FRAGMENT_NODE ? [] : (e.tagName && s.add(e.tagName.toLowerCase()), typeof e.querySelectorAll == "function" && e.querySelectorAll("*").forEach((t) => s.add(t.tagName.toLowerCase())), Array.from(s));
|
|
82
82
|
}
|
|
83
|
-
function h(
|
|
83
|
+
function h(e) {
|
|
84
84
|
const s = /* @__PURE__ */ new Map();
|
|
85
|
-
for (let n of
|
|
86
|
-
const
|
|
87
|
-
if (!
|
|
88
|
-
const
|
|
89
|
-
s.has(
|
|
85
|
+
for (let n of e) {
|
|
86
|
+
const a = r.defaultStyle.get(n);
|
|
87
|
+
if (!a) continue;
|
|
88
|
+
const l = Object.entries(a).map(([o, i]) => `${o}:${i};`).sort().join("");
|
|
89
|
+
s.has(l) || s.set(l, []), s.get(l).push(n);
|
|
90
90
|
}
|
|
91
|
-
let
|
|
92
|
-
for (let [n,
|
|
93
|
-
|
|
91
|
+
let t = "";
|
|
92
|
+
for (let [n, a] of s.entries())
|
|
93
|
+
t += `${a.join(",")} { ${n} }
|
|
94
94
|
`;
|
|
95
|
-
return
|
|
95
|
+
return t;
|
|
96
96
|
}
|
|
97
|
-
function m(
|
|
98
|
-
const
|
|
99
|
-
let
|
|
100
|
-
for (const
|
|
101
|
-
|
|
102
|
-
return
|
|
97
|
+
function m() {
|
|
98
|
+
const e = new Set(r.preStyleMap.values()), s = /* @__PURE__ */ new Map();
|
|
99
|
+
let t = 1;
|
|
100
|
+
for (const n of e)
|
|
101
|
+
s.set(n, `c${t++}`);
|
|
102
|
+
return s;
|
|
103
103
|
}
|
|
104
104
|
export {
|
|
105
105
|
y as collectUsedTagNames,
|
|
@@ -1,186 +1,183 @@
|
|
|
1
|
-
import {
|
|
2
|
-
async function
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
import { cache as s } from "../core/cache.js";
|
|
2
|
+
async function R(t, e = {}) {
|
|
3
|
+
const n = p(t), i = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(
|
|
4
|
+
t
|
|
5
5
|
);
|
|
6
|
-
if (
|
|
7
|
-
const
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
if (m.has(a))
|
|
11
|
-
return t.skipInline ? void 0 : `url(${m.get(a)})`;
|
|
6
|
+
if (n) {
|
|
7
|
+
const a = h(n);
|
|
8
|
+
if (s.background.has(a))
|
|
9
|
+
return e.skipInline ? void 0 : `url(${s.background.get(a)})`;
|
|
12
10
|
{
|
|
13
|
-
const
|
|
14
|
-
useProxy:
|
|
11
|
+
const c = await w(a, {
|
|
12
|
+
useProxy: e.useProxy
|
|
15
13
|
});
|
|
16
|
-
return
|
|
14
|
+
return s.background.set(a, c), e.skipInline ? void 0 : `url("${c}")`;
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
|
-
return
|
|
17
|
+
return t;
|
|
20
18
|
}
|
|
21
|
-
function
|
|
22
|
-
if (
|
|
23
|
-
"requestIdleCallback" in window ? requestIdleCallback(
|
|
19
|
+
function S(t, { fast: e = !1 } = {}) {
|
|
20
|
+
if (e) return t();
|
|
21
|
+
"requestIdleCallback" in window ? requestIdleCallback(t, { timeout: 50 }) : setTimeout(t, 1);
|
|
24
22
|
}
|
|
25
|
-
function
|
|
26
|
-
if (!(
|
|
27
|
-
return window.getComputedStyle(
|
|
28
|
-
let
|
|
29
|
-
if (
|
|
30
|
-
const i = window.getComputedStyle(
|
|
31
|
-
|
|
23
|
+
function U(t, e = null) {
|
|
24
|
+
if (!(t instanceof Element))
|
|
25
|
+
return window.getComputedStyle(t, e);
|
|
26
|
+
let n = s.computedStyle.get(t);
|
|
27
|
+
if (n || (n = /* @__PURE__ */ new Map(), s.computedStyle.set(t, n)), !n.has(e)) {
|
|
28
|
+
const i = window.getComputedStyle(t, e);
|
|
29
|
+
n.set(e, i);
|
|
32
30
|
}
|
|
33
|
-
return
|
|
31
|
+
return n.get(e);
|
|
34
32
|
}
|
|
35
|
-
function
|
|
36
|
-
let
|
|
37
|
-
if (
|
|
33
|
+
function k(t) {
|
|
34
|
+
let e = t.replace(/^['"]|['"]$/g, "");
|
|
35
|
+
if (e.startsWith("\\"))
|
|
38
36
|
try {
|
|
39
|
-
return String.fromCharCode(parseInt(
|
|
37
|
+
return String.fromCharCode(parseInt(e.replace("\\", ""), 16));
|
|
40
38
|
} catch {
|
|
41
|
-
return
|
|
39
|
+
return e;
|
|
42
40
|
}
|
|
43
|
-
return
|
|
41
|
+
return e;
|
|
44
42
|
}
|
|
45
|
-
function
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
return
|
|
43
|
+
function p(t) {
|
|
44
|
+
const e = t.match(/url\((['"]?)(.*?)(\1)\)/);
|
|
45
|
+
if (!e) return null;
|
|
46
|
+
const n = e[2].trim();
|
|
47
|
+
return n.startsWith("#") ? null : n;
|
|
50
48
|
}
|
|
51
|
-
function
|
|
52
|
-
function i(
|
|
49
|
+
function w(t, { timeout: e = 3e3, useProxy: n = "" } = {}) {
|
|
50
|
+
function i(l) {
|
|
53
51
|
try {
|
|
54
|
-
return new URL(
|
|
52
|
+
return new URL(l, window.location.href).origin === window.location.origin ? "use-credentials" : "anonymous";
|
|
55
53
|
} catch {
|
|
56
54
|
return "anonymous";
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
credentials: n === "use-credentials" ? "include" : "omit"
|
|
71
|
-
}).then((o) => (console.log(
|
|
72
|
-
`[SnapDOM - fetchImage] Fetch response received for: ${e}`
|
|
73
|
-
), o.blob())).then((o) => {
|
|
74
|
-
const d = new FileReader();
|
|
75
|
-
d.onloadend = () => {
|
|
76
|
-
const c = d.result;
|
|
77
|
-
if (typeof c == "string" && c.startsWith("data:application/octet-stream")) {
|
|
78
|
-
s(new Error("Image response was empty or blocked"));
|
|
57
|
+
async function a(l) {
|
|
58
|
+
const u = (d) => fetch(d, {
|
|
59
|
+
mode: "cors",
|
|
60
|
+
credentials: i(d) === "use-credentials" ? "include" : "omit"
|
|
61
|
+
}).then((o) => o.blob()).then(
|
|
62
|
+
(o) => new Promise((r, g) => {
|
|
63
|
+
const m = new FileReader();
|
|
64
|
+
m.onloadend = () => {
|
|
65
|
+
const f = m.result;
|
|
66
|
+
if (typeof f != "string" || !f.startsWith("data:image/")) {
|
|
67
|
+
g(new Error("Invalid image data URL"));
|
|
79
68
|
return;
|
|
80
69
|
}
|
|
81
|
-
f
|
|
82
|
-
},
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
), fetch(o).then((d) => d.blob()).then((d) => {
|
|
91
|
-
const c = new FileReader();
|
|
92
|
-
c.onloadend = () => {
|
|
93
|
-
const u = c.result;
|
|
94
|
-
if (typeof u == "string" && u.startsWith("data:application/octet-stream")) {
|
|
95
|
-
s(new Error("Image response was empty or blocked"));
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
f.set(e, u), a(u);
|
|
99
|
-
}, c.readAsDataURL(d);
|
|
100
|
-
}).catch(() => {
|
|
101
|
-
console.error(
|
|
102
|
-
`[SnapDOM - fetchImage] Proxy fallback failed for: ${e}`
|
|
103
|
-
), s(
|
|
104
|
-
new Error(
|
|
105
|
-
"CORS restrictions prevented image capture (even via proxy)"
|
|
106
|
-
)
|
|
107
|
-
);
|
|
108
|
-
})) : console.error(
|
|
109
|
-
`[SnapDOM - fetchImage] Provide a valid proxy url: ${e}`
|
|
110
|
-
);
|
|
111
|
-
} else
|
|
112
|
-
console.error(
|
|
113
|
-
'[SnapDOM - fetchImage] You may try add a proxy "useProxy: url" '
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
}, l = new Image();
|
|
117
|
-
l.crossOrigin = n, l.onload = async () => {
|
|
118
|
-
clearTimeout(h);
|
|
119
|
-
try {
|
|
120
|
-
await l.decode();
|
|
121
|
-
const o = document.createElement("canvas");
|
|
122
|
-
o.width = l.width, o.height = l.height, o.getContext("2d").drawImage(l, 0, 0, o.width, o.height);
|
|
70
|
+
r(f);
|
|
71
|
+
}, m.onerror = () => g(new Error("FileReader error")), m.readAsDataURL(o);
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
try {
|
|
75
|
+
return await u(l);
|
|
76
|
+
} catch {
|
|
77
|
+
if (n && typeof n == "string") {
|
|
78
|
+
const o = n.replace(/\/$/, "") + h(l);
|
|
123
79
|
try {
|
|
124
|
-
|
|
125
|
-
f.set(e, c), a(c);
|
|
80
|
+
return await u(o);
|
|
126
81
|
} catch {
|
|
127
|
-
|
|
82
|
+
throw new Error(
|
|
83
|
+
"[SnapDOM - fetchImage] CORS restrictions prevented image capture (even via proxy)"
|
|
84
|
+
);
|
|
128
85
|
}
|
|
86
|
+
} else
|
|
87
|
+
throw new Error(
|
|
88
|
+
"[SnapDOM - fetchImage] Fetch fallback failed and no proxy provided"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const c = i(t);
|
|
93
|
+
return s.image.has(t) ? Promise.resolve(s.image.get(t)) : t.startsWith("data:image/") ? (s.image.set(t, t), Promise.resolve(t)) : /\.svg(\?.*)?$/i.test(t) ? (async () => {
|
|
94
|
+
try {
|
|
95
|
+
const u = await (await fetch(t, {
|
|
96
|
+
mode: "cors",
|
|
97
|
+
credentials: c === "use-credentials" ? "include" : "omit"
|
|
98
|
+
})).text(), d = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`;
|
|
99
|
+
return s.image.set(t, d), d;
|
|
100
|
+
} catch {
|
|
101
|
+
return a(t);
|
|
102
|
+
}
|
|
103
|
+
})() : new Promise((l, u) => {
|
|
104
|
+
const d = setTimeout(() => {
|
|
105
|
+
u(new Error("[SnapDOM - fetchImage] Image load timed out"));
|
|
106
|
+
}, e), o = new Image();
|
|
107
|
+
o.crossOrigin = c, o.onload = async () => {
|
|
108
|
+
clearTimeout(d);
|
|
109
|
+
try {
|
|
110
|
+
await o.decode();
|
|
111
|
+
const r = document.createElement("canvas");
|
|
112
|
+
r.width = o.width, r.height = o.height, r.getContext("2d").drawImage(o, 0, 0, r.width, r.height);
|
|
113
|
+
const m = r.toDataURL("image/png");
|
|
114
|
+
s.image.set(t, m), l(m);
|
|
129
115
|
} catch {
|
|
130
|
-
|
|
116
|
+
try {
|
|
117
|
+
const r = await a(t);
|
|
118
|
+
s.image.set(t, r), l(r);
|
|
119
|
+
} catch (r) {
|
|
120
|
+
u(r);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}, o.onerror = async () => {
|
|
124
|
+
clearTimeout(d), console.error(`[SnapDOM - fetchImage] Image failed to load: ${t}`);
|
|
125
|
+
try {
|
|
126
|
+
const r = await a(t);
|
|
127
|
+
s.image.set(t, r), l(r);
|
|
128
|
+
} catch (r) {
|
|
129
|
+
u(r);
|
|
131
130
|
}
|
|
132
|
-
},
|
|
133
|
-
clearTimeout(h), console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`, o), g();
|
|
134
|
-
}, l.src = e;
|
|
131
|
+
}, o.src = t;
|
|
135
132
|
});
|
|
136
133
|
}
|
|
137
|
-
function
|
|
138
|
-
const
|
|
139
|
-
for (let
|
|
140
|
-
|
|
141
|
-
return
|
|
134
|
+
function C(t) {
|
|
135
|
+
const e = {};
|
|
136
|
+
for (let n of t)
|
|
137
|
+
e[n] = t.getPropertyValue(n);
|
|
138
|
+
return e;
|
|
142
139
|
}
|
|
143
|
-
function
|
|
140
|
+
function v() {
|
|
144
141
|
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
145
142
|
}
|
|
146
|
-
function
|
|
147
|
-
if (!
|
|
148
|
-
let
|
|
149
|
-
return
|
|
150
|
-
const
|
|
151
|
-
return
|
|
152
|
-
}),
|
|
153
|
-
const
|
|
154
|
-
return
|
|
155
|
-
}),
|
|
143
|
+
function D(t) {
|
|
144
|
+
if (!t || t === "none") return "";
|
|
145
|
+
let e = t.replace(/translate[XY]?\([^)]*\)/g, "");
|
|
146
|
+
return e = e.replace(/matrix\(([^)]+)\)/g, (n, i) => {
|
|
147
|
+
const a = i.split(",").map((c) => c.trim());
|
|
148
|
+
return a.length !== 6 ? `matrix(${i})` : (a[4] = "0", a[5] = "0", `matrix(${a.join(", ")})`);
|
|
149
|
+
}), e = e.replace(/matrix3d\(([^)]+)\)/g, (n, i) => {
|
|
150
|
+
const a = i.split(",").map((c) => c.trim());
|
|
151
|
+
return a.length !== 16 ? `matrix3d(${i})` : (a[12] = "0", a[13] = "0", `matrix3d(${a.join(", ")})`);
|
|
152
|
+
}), e.trim().replace(/\s{2,}/g, " ");
|
|
156
153
|
}
|
|
157
|
-
function
|
|
158
|
-
if (/%[0-9A-Fa-f]{2}/.test(
|
|
154
|
+
function h(t) {
|
|
155
|
+
if (/%[0-9A-Fa-f]{2}/.test(t)) return t;
|
|
159
156
|
try {
|
|
160
|
-
return encodeURI(
|
|
157
|
+
return encodeURI(t);
|
|
161
158
|
} catch {
|
|
162
|
-
return
|
|
159
|
+
return t;
|
|
163
160
|
}
|
|
164
161
|
}
|
|
165
|
-
function
|
|
166
|
-
const
|
|
167
|
-
let
|
|
168
|
-
for (let
|
|
169
|
-
const
|
|
170
|
-
|
|
162
|
+
function $(t) {
|
|
163
|
+
const e = [];
|
|
164
|
+
let n = 0, i = 0;
|
|
165
|
+
for (let a = 0; a < t.length; a++) {
|
|
166
|
+
const c = t[a];
|
|
167
|
+
c === "(" && n++, c === ")" && n--, c === "," && n === 0 && (e.push(t.slice(i, a).trim()), i = a + 1);
|
|
171
168
|
}
|
|
172
|
-
return
|
|
169
|
+
return e.push(t.slice(i).trim()), e;
|
|
173
170
|
}
|
|
174
171
|
export {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
172
|
+
p as extractURL,
|
|
173
|
+
w as fetchImage,
|
|
174
|
+
U as getStyle,
|
|
175
|
+
S as idle,
|
|
176
|
+
R as inlineSingleBackgroundEntry,
|
|
177
|
+
v as isSafari,
|
|
178
|
+
k as parseContent,
|
|
179
|
+
h as safeEncodeURI,
|
|
180
|
+
C as snapshotComputedStyle,
|
|
181
|
+
$ as splitBackgroundImage,
|
|
182
|
+
D as stripTranslate
|
|
186
183
|
};
|
package/tree/index.js
CHANGED