@unicom-cloud/utils 0.1.12 → 0.1.14
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 +67 -63
- package/snapdom/src/core/cache.js +19 -8
- package/snapdom/src/core/capture.js +46 -45
- package/snapdom/src/core/clone.js +94 -31
- package/snapdom/src/core/prepare.js +35 -38
- package/snapdom/src/modules/background.js +29 -20
- package/snapdom/src/modules/fonts.js +93 -101
- package/snapdom/src/modules/pseudo.js +70 -75
- 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,94 +1,89 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { cache as M } from "../core/cache.js";
|
|
2
|
+
import { iconToImage as q } from "./fonts.js";
|
|
3
|
+
import { isIconFont as v } from "./iconFonts.js";
|
|
4
|
+
import { getStyleKey as $ } from "../utils/cssTools.js";
|
|
5
|
+
import { getStyle as G, snapshotComputedStyle as z, parseContent as H, extractURL as J, fetchImage as Q, safeEncodeURI as Y, splitBackgroundImage as Z, inlineSingleBackgroundEntry as tt } from "../utils/helpers.js";
|
|
6
|
+
async function et(c, s, p, R = !1, b) {
|
|
7
|
+
if (!(c instanceof Element) || !(s instanceof Element)) return;
|
|
7
8
|
for (const n of ["::before", "::after", "::first-letter"])
|
|
8
9
|
try {
|
|
9
|
-
const t =
|
|
10
|
+
const t = G(c, n);
|
|
10
11
|
if (!t || typeof t[Symbol.iterator] != "function") continue;
|
|
11
12
|
if (n === "::first-letter") {
|
|
12
|
-
const
|
|
13
|
-
if (!(t.color !==
|
|
14
|
-
const
|
|
15
|
-
(
|
|
13
|
+
const e = getComputedStyle(c);
|
|
14
|
+
if (!(t.color !== e.color || t.fontSize !== e.fontSize || t.fontWeight !== e.fontWeight)) continue;
|
|
15
|
+
const i = Array.from(s.childNodes).find(
|
|
16
|
+
(C) => C.nodeType === Node.TEXT_NODE && C.textContent && C.textContent.trim().length > 0
|
|
16
17
|
);
|
|
17
|
-
if (!
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
18
|
+
if (!i) continue;
|
|
19
|
+
const N = i.textContent, d = N.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0], O = N.slice(d?.length || 0);
|
|
20
|
+
if (!d || /[\uD800-\uDFFF]/.test(d)) continue;
|
|
21
|
+
const f = document.createElement("span");
|
|
22
|
+
f.textContent = d, f.dataset.snapdomPseudo = "::first-letter";
|
|
23
|
+
const X = z(t), _ = $(X, "span", p);
|
|
24
|
+
M.preStyleMap.set(f, _);
|
|
25
|
+
const T = document.createTextNode(O);
|
|
26
|
+
s.replaceChild(T, i), s.insertBefore(f, T);
|
|
26
27
|
continue;
|
|
27
28
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const i = document.createElement("img"), P = await D(
|
|
49
|
-
L(e, { useProxy: w })
|
|
50
|
-
);
|
|
51
|
-
i.src = P, i.style = `width:${p}px;height:auto;object-fit:contain;`, o.appendChild(i);
|
|
52
|
-
} catch (i) {
|
|
53
|
-
console.error(
|
|
54
|
-
`[snapdom] Error in pseudo ${n} for`,
|
|
55
|
-
c,
|
|
56
|
-
i
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
} else !a && s && s !== "none" && (o.textContent = s);
|
|
60
|
-
if (C)
|
|
29
|
+
const h = t.getPropertyValue("content"), m = t.getPropertyValue("background-image"), l = t.getPropertyValue("background-color"), E = t.getPropertyValue("font-family"), g = parseInt(t.getPropertyValue("font-size")) || 32, U = parseInt(t.getPropertyValue("font-weight")) || !1, W = t.getPropertyValue("color") || "#000", j = t.getPropertyValue("display"), A = parseFloat(t.getPropertyValue("width")), D = parseFloat(t.getPropertyValue("height")), V = t.getPropertyValue("border-style"), w = t.getPropertyValue("transform"), S = v(E);
|
|
30
|
+
let r;
|
|
31
|
+
/counter\s*\(|counters\s*\(/.test(h) ? r = "- " : r = H(h);
|
|
32
|
+
const B = h !== "none" && r !== "", u = m && m !== "none", y = l && l !== "transparent" && l !== "rgba(0, 0, 0, 0)", F = j !== "inline" && (A > 0 || D > 0), k = V && V !== "none", I = w && w !== "none";
|
|
33
|
+
if (!(B || u || y || F || k || I)) continue;
|
|
34
|
+
const o = document.createElement("span");
|
|
35
|
+
o.dataset.snapdomPseudo = n;
|
|
36
|
+
const L = z(t), K = $(L, "span", p);
|
|
37
|
+
if (M.preStyleMap.set(o, K), S && r.length === 1) {
|
|
38
|
+
const e = document.createElement("img");
|
|
39
|
+
e.src = await q(
|
|
40
|
+
r,
|
|
41
|
+
E,
|
|
42
|
+
U,
|
|
43
|
+
g,
|
|
44
|
+
W
|
|
45
|
+
), e.style = `width:${g}px;height:auto;object-fit:contain;`, o.appendChild(e);
|
|
46
|
+
} else if (r.startsWith("url(")) {
|
|
47
|
+
const e = J(r);
|
|
48
|
+
if (e && e.trim() !== "")
|
|
61
49
|
try {
|
|
62
|
-
const
|
|
63
|
-
e
|
|
64
|
-
);
|
|
65
|
-
o.style.backgroundImage = i.join(", ");
|
|
66
|
-
} catch (e) {
|
|
67
|
-
console.warn(
|
|
68
|
-
`[snapdom] Failed to inline background-image for ${n}`,
|
|
69
|
-
e
|
|
50
|
+
const a = document.createElement("img"), i = await Q(
|
|
51
|
+
Y(e, { useProxy: b })
|
|
70
52
|
);
|
|
53
|
+
a.src = i, a.style = `width:${g}px;height:auto;object-fit:contain;`, o.appendChild(a);
|
|
54
|
+
} catch (a) {
|
|
55
|
+
console.error(`[snapdom] Error in pseudo ${n} for`, c, a);
|
|
71
56
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
57
|
+
} else !S && B && (o.textContent = r);
|
|
58
|
+
if (u)
|
|
59
|
+
try {
|
|
60
|
+
const e = Z(m), a = await Promise.all(
|
|
61
|
+
e.map((i) => tt(i))
|
|
62
|
+
);
|
|
63
|
+
o.style.backgroundImage = a.join(", ");
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.warn(
|
|
66
|
+
`[snapdom] Failed to inline background-image for ${n}`,
|
|
67
|
+
e
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
if (y && (o.style.backgroundColor = l), !(o.childNodes.length > 0 || o.textContent && o.textContent.trim() !== "" || u || y || F || k || I)) continue;
|
|
71
|
+
n === "::before" ? s.insertBefore(o, s.firstChild) : s.appendChild(o);
|
|
75
72
|
} catch (t) {
|
|
76
73
|
console.warn(`[snapdom] Failed to capture ${n} for`, c, t);
|
|
77
74
|
}
|
|
78
|
-
const
|
|
75
|
+
const x = Array.from(c.children), P = Array.from(s.children).filter(
|
|
79
76
|
(n) => !n.dataset.snapdomPseudo
|
|
80
77
|
);
|
|
81
|
-
for (let n = 0; n < Math.min(
|
|
82
|
-
await
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
T,
|
|
89
|
-
w
|
|
78
|
+
for (let n = 0; n < Math.min(x.length, P.length); n++)
|
|
79
|
+
await et(
|
|
80
|
+
x[n],
|
|
81
|
+
P[n],
|
|
82
|
+
p,
|
|
83
|
+
R,
|
|
84
|
+
b
|
|
90
85
|
);
|
|
91
86
|
}
|
|
92
87
|
export {
|
|
93
|
-
|
|
88
|
+
et as inlinePseudoElements
|
|
94
89
|
};
|
|
@@ -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,
|