@unicom-cloud/utils 0.1.11 → 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/date/index.js +22 -0
- package/date.js +9 -0
- package/filesize/src/constants.js +22 -22
- package/filesize/src/filesize.js +32 -33
- package/index.js +56 -54
- package/lunar/index.js +36 -0
- package/lunar/lib/Holiday.js +42 -0
- package/lunar/lib/HolidayUtil.js +128 -0
- package/lunar/lib/I18n.js +1005 -0
- package/lunar/lib/JieQi.js +40 -0
- package/lunar/lib/Lunar.js +1035 -0
- package/lunar/lib/LunarMonth.js +150 -0
- package/lunar/lib/LunarTime.js +138 -0
- package/lunar/lib/LunarUtil.js +1752 -0
- package/lunar/lib/LunarYear.js +616 -0
- package/lunar/lib/ShouXingUtil.js +6915 -0
- package/lunar/lib/Solar.js +311 -0
- package/lunar/lib/SolarHalfYear.js +45 -0
- package/lunar/lib/SolarMonth.js +55 -0
- package/lunar/lib/SolarSeason.js +42 -0
- package/lunar/lib/SolarUtil.js +256 -0
- package/lunar/lib/SolarWeek.js +153 -0
- package/lunar/lib/SolarYear.js +35 -0
- package/lunar/lib/index.js +35 -0
- package/lunar.js +36 -0
- package/package.json +1 -1
- package/snapdom/src/api/preCache.js +27 -37
- package/snapdom/src/api/snapdom.js +75 -58
- package/snapdom/src/core/cache.js +19 -8
- package/snapdom/src/core/capture.js +49 -48
- package/snapdom/src/core/clone.js +96 -31
- package/snapdom/src/core/prepare.js +43 -37
- package/snapdom/src/modules/background.js +29 -20
- package/snapdom/src/modules/fonts.js +94 -104
- package/snapdom/src/modules/iconFonts.js +28 -0
- package/snapdom/src/modules/images.js +6 -6
- package/snapdom/src/modules/pseudo.js +52 -50
- package/snapdom/src/modules/styles.js +26 -6
- package/snapdom/src/modules/svgDefs.js +26 -0
- package/snapdom/src/utils/cssTools.js +41 -41
- package/snapdom/src/utils/helpers.js +128 -84
- package/tinycolor/index.js +46 -0
- package/tinycolor/src/conversion.js +143 -0
- package/tinycolor/src/css-color-names.js +153 -0
- package/tinycolor/src/format-input.js +77 -0
- package/tinycolor/src/from-ratio.js +21 -0
- package/tinycolor/src/index.js +404 -0
- package/tinycolor/src/random.js +221 -0
- package/tinycolor/src/readability.js +37 -0
- package/tinycolor/src/to-ms-filter.js +15 -0
- package/tinycolor/src/util.js +32 -0
- package/tinycolor.js +46 -0
- package/tree/index.js +10 -8
- package/tree/search/index.js +90 -0
- package/tree.js +9 -7
- package/types/date/index.d.ts +4 -0
- package/types/filesize/src/constants.d.ts +12 -12
- package/types/filesize/src/filesize.d.ts +63 -22
- package/types/index.d.ts +4 -3
- package/types/lunar/index.d.ts +3 -0
- package/types/lunar/lib/Holiday.d.ts +17 -0
- package/types/lunar/lib/HolidayUtil.d.ts +23 -0
- package/types/lunar/lib/I18n.d.ts +23 -0
- package/types/lunar/lib/JieQi.d.ts +15 -0
- package/types/lunar/lib/Lunar.d.ts +245 -0
- package/types/lunar/lib/LunarMonth.d.ts +35 -0
- package/types/lunar/lib/LunarTime.d.ts +40 -0
- package/types/lunar/lib/LunarUtil.d.ts +128 -0
- package/types/lunar/lib/LunarYear.d.ts +61 -0
- package/types/lunar/lib/ShouXingUtil.d.ts +38 -0
- package/types/lunar/lib/Solar.d.ts +51 -0
- package/types/lunar/lib/SolarHalfYear.d.ts +15 -0
- package/types/lunar/lib/SolarMonth.d.ts +16 -0
- package/types/lunar/lib/SolarSeason.d.ts +15 -0
- package/types/lunar/lib/SolarUtil.d.ts +20 -0
- package/types/lunar/lib/SolarWeek.d.ts +23 -0
- package/types/lunar/lib/SolarYear.d.ts +12 -0
- package/types/lunar/lib/index.d.ts +17 -0
- 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/fonts.d.ts +1 -3
- package/types/snapdom/src/modules/iconFonts.d.ts +2 -0
- package/types/snapdom/src/modules/pseudo.d.ts +1 -3
- package/types/snapdom/src/modules/styles.d.ts +1 -10
- package/types/snapdom/src/modules/svgDefs.d.ts +19 -0
- package/types/snapdom/src/utils/cssTools.d.ts +1 -2
- package/types/snapdom/src/utils/helpers.d.ts +1 -1
- package/types/tinycolor/index.d.ts +2 -0
- package/types/tinycolor/src/conversion.d.ts +79 -0
- package/types/tinycolor/src/css-color-names.d.ts +4 -0
- package/types/tinycolor/src/format-input.d.ts +38 -0
- package/types/tinycolor/src/from-ratio.d.ts +14 -0
- package/types/tinycolor/src/index.d.ts +214 -0
- package/types/tinycolor/src/interfaces.d.ts +57 -0
- package/types/tinycolor/src/public_api.d.ts +10 -0
- package/types/tinycolor/src/random.d.ts +24 -0
- package/types/tinycolor/src/readability.d.ts +46 -0
- package/types/tinycolor/src/to-ms-filter.d.ts +5 -0
- package/types/tinycolor/src/umd_api.d.ts +22 -0
- package/types/tinycolor/src/util.d.ts +36 -0
- package/types/tree/index.d.ts +1 -0
- package/types/tree/search/index.d.ts +80 -0
- package/types/ui-color/compareColorByRange.d.ts +2 -0
- package/types/ui-color/index.d.ts +208 -0
- package/ui-color/compareColorByRange.js +9 -0
- package/ui-color/index.js +162 -0
- package/uiColor.js +29 -0
- package/convertTime.js +0 -4
- package/dayjs/index.js +0 -15
- package/dayjs.js +0 -5
- package/lunar-converter/index.js +0 -641
- package/lunarConverter.js +0 -4
- package/search-tree/index.js +0 -54
- package/searchTree.js +0 -4
- package/types/dayjs/index.d.ts +0 -1
- package/types/lunar-converter/index.d.ts +0 -113
- package/types/search-tree/index.d.ts +0 -20
- /package/{convert-time/index.js → date/convertTime.js} +0 -0
- /package/types/{convert-time/index.d.ts → date/convertTime.d.ts} +0 -0
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { cache as c } from "../core/cache.js";
|
|
2
|
+
import { getStyle as y, splitBackgroundImage as h, inlineSingleBackgroundEntry as b } from "../utils/helpers.js";
|
|
3
|
+
async function w(u, d, k = {}) {
|
|
4
|
+
const t = [[u, d]], p = [
|
|
5
|
+
"background-image",
|
|
6
|
+
"mask",
|
|
7
|
+
"mask-image",
|
|
8
|
+
"-webkit-mask-image",
|
|
9
|
+
"mask-source",
|
|
10
|
+
"mask-box-image-source",
|
|
11
|
+
"mask-border-source",
|
|
12
|
+
"-webkit-mask-box-image-source"
|
|
13
|
+
];
|
|
14
|
+
for (; t.length; ) {
|
|
15
|
+
const [o, s] = t.shift(), a = c.preStyle.get(o) || y(o);
|
|
16
|
+
c.preStyle.has(o) || c.preStyle.set(o, a);
|
|
17
|
+
for (const e of p) {
|
|
18
|
+
const i = a.getPropertyValue(e);
|
|
19
|
+
if (!i || i === "none") continue;
|
|
20
|
+
const f = h(i), g = await Promise.all(
|
|
21
|
+
f.map((r) => b(r, k))
|
|
22
|
+
);
|
|
23
|
+
g.some((r) => r && r !== "none" && !/^url\(undefined/.test(r)) && s.style.setProperty(e, g.join(", "));
|
|
13
24
|
}
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
for (let n = 0; n < Math.min(g.length, d.length); n++)
|
|
20
|
-
r.push([g[n], d[n]]);
|
|
25
|
+
const n = a.getPropertyValue("background-color");
|
|
26
|
+
n && n !== "transparent" && n !== "rgba(0, 0, 0, 0)" && (s.style.backgroundColor = n);
|
|
27
|
+
const l = Array.from(o.children), m = Array.from(s.children);
|
|
28
|
+
for (let e = 0; e < Math.min(l.length, m.length); e++)
|
|
29
|
+
t.push([l[e], m[e]]);
|
|
21
30
|
}
|
|
22
31
|
}
|
|
23
32
|
export {
|
|
24
|
-
|
|
33
|
+
w as inlineBackgroundImages
|
|
25
34
|
};
|
|
@@ -1,125 +1,120 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isIconFont as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
u.
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { cache as o } from "../core/cache.js";
|
|
2
|
+
import { isIconFont as y } from "./iconFonts.js";
|
|
3
|
+
import { extractURL as L } from "../utils/helpers.js";
|
|
4
|
+
async function E(u, i, a, p = 32, m = "#000") {
|
|
5
|
+
i = i.replace(/^['"]+|['"]+$/g, "");
|
|
6
|
+
const t = window.devicePixelRatio || 1, s = document.createElement("canvas").getContext("2d");
|
|
7
|
+
s.font = a ? `${a} ${p}px "${i}"` : `${p}px "${i}"`;
|
|
8
|
+
const c = s.measureText(u), l = c.actualBoundingBoxAscent || p * 0.8, f = c.actualBoundingBoxDescent || p * 0.2, d = l + f, w = c.width, e = document.createElement("canvas");
|
|
9
|
+
e.width = Math.ceil(w * t), e.height = Math.ceil(d * t);
|
|
10
|
+
const h = e.getContext("2d");
|
|
11
|
+
return h.scale(t, t), h.font = s.font, h.textAlign = "left", h.textBaseline = "alphabetic", h.fillStyle = m, h.fillText(u, 0, l), e.toDataURL();
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
-
return Array.from(document.styleSheets).some((
|
|
13
|
+
function $(u) {
|
|
14
|
+
return Array.from(document.styleSheets).some((i) => i.href === u);
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
return new Promise((
|
|
17
|
-
if (
|
|
18
|
-
const
|
|
19
|
-
|
|
16
|
+
function P(u) {
|
|
17
|
+
return new Promise((i) => {
|
|
18
|
+
if ($(u)) return i(null);
|
|
19
|
+
const a = document.createElement("link");
|
|
20
|
+
a.rel = "stylesheet", a.href = u, a.setAttribute("data-snapdom", "injected-import"), a.onload = () => i(a), a.onerror = () => i(null), document.head.appendChild(a);
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
|
-
async function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} = {}) {
|
|
26
|
-
if (c.has("fonts-embed-css")) {
|
|
27
|
-
if (a) {
|
|
23
|
+
async function T({ preCached: u = !1 } = {}) {
|
|
24
|
+
if (o.resource.has("fonts-embed-css")) {
|
|
25
|
+
if (u) {
|
|
28
26
|
const t = document.createElement("style");
|
|
29
|
-
t.setAttribute("data-snapdom", "embedFonts"), t.textContent =
|
|
27
|
+
t.setAttribute("data-snapdom", "embedFonts"), t.textContent = o.resource.get("fonts-embed-css"), document.head.appendChild(t);
|
|
30
28
|
}
|
|
31
|
-
return
|
|
29
|
+
return o.resource.get("fonts-embed-css");
|
|
32
30
|
}
|
|
33
|
-
const
|
|
31
|
+
const i = /@import\s+url\(["']?([^"')]+)["']?\)/g, a = [];
|
|
34
32
|
for (const t of document.querySelectorAll("style")) {
|
|
35
|
-
const n = t.textContent || "",
|
|
36
|
-
for (const
|
|
37
|
-
const
|
|
38
|
-
|
|
33
|
+
const n = t.textContent || "", s = Array.from(n.matchAll(i));
|
|
34
|
+
for (const c of s) {
|
|
35
|
+
const l = c[1];
|
|
36
|
+
y(l) || $(l) || a.push(l);
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
|
-
await Promise.all(
|
|
42
|
-
const
|
|
39
|
+
await Promise.all(a.map(P));
|
|
40
|
+
const p = Array.from(
|
|
43
41
|
document.querySelectorAll('link[rel="stylesheet"]')
|
|
44
42
|
).filter((t) => t.href);
|
|
45
|
-
let
|
|
46
|
-
for (const t of
|
|
43
|
+
let m = "";
|
|
44
|
+
for (const t of p)
|
|
47
45
|
try {
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
inlined: `url(${c.get(e)})`
|
|
46
|
+
const s = await (await fetch(t.href)).text();
|
|
47
|
+
if (y(t.href) || y(s)) continue;
|
|
48
|
+
const c = /url\((["']?)([^"')]+)\1\)/g, l = await Promise.all(
|
|
49
|
+
Array.from(s.matchAll(c)).map(async (d) => {
|
|
50
|
+
let w = L(d[0]);
|
|
51
|
+
if (!w) return null;
|
|
52
|
+
let e = w;
|
|
53
|
+
if (!e.startsWith("http") && !e.startsWith("data:") && (e = new URL(e, t.href).href), y(e)) return null;
|
|
54
|
+
if (o.resource.has(e))
|
|
55
|
+
return o.font.add(e), {
|
|
56
|
+
original: d[0],
|
|
57
|
+
inlined: `url(${o.resource.get(e)})`
|
|
61
58
|
};
|
|
62
|
-
if (
|
|
59
|
+
if (o.font.has(e)) return null;
|
|
63
60
|
try {
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
|
|
61
|
+
const g = await (await fetch(e)).blob(), b = await new Promise((r) => {
|
|
62
|
+
const x = new FileReader();
|
|
63
|
+
x.onload = () => r(x.result), x.readAsDataURL(g);
|
|
67
64
|
});
|
|
68
|
-
return
|
|
65
|
+
return o.resource.set(e, b), o.font.add(e), { original: d[0], inlined: `url(${b})` };
|
|
69
66
|
} catch {
|
|
70
67
|
return console.warn("[snapdom] Failed to fetch font resource:", e), null;
|
|
71
68
|
}
|
|
72
69
|
})
|
|
73
70
|
);
|
|
74
|
-
let
|
|
75
|
-
for (const
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
let f = s;
|
|
72
|
+
for (const d of l)
|
|
73
|
+
d && (f = f.replace(d.original, d.inlined));
|
|
74
|
+
m += f + `
|
|
78
75
|
`;
|
|
79
76
|
} catch {
|
|
80
77
|
console.warn("[snapdom] Failed to fetch CSS:", t.href);
|
|
81
78
|
}
|
|
82
79
|
for (const t of document.styleSheets)
|
|
83
80
|
try {
|
|
84
|
-
if (!t.href ||
|
|
81
|
+
if (!t.href || p.every((n) => n.href !== t.href)) {
|
|
85
82
|
for (const n of t.cssRules)
|
|
86
83
|
if (n.type === CSSRule.FONT_FACE_RULE) {
|
|
87
|
-
const
|
|
88
|
-
if (!
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
84
|
+
const s = n.style.getPropertyValue("src"), c = n.style.getPropertyValue("font-family");
|
|
85
|
+
if (!s || y(c)) continue;
|
|
86
|
+
const l = /url\((["']?)([^"')]+)\1\)/g, f = /local\((["']?)[^)]+?\1\)/g, d = l.test(s), w = f.test(s);
|
|
87
|
+
if (!d && w) {
|
|
88
|
+
m += `@font-face{font-family:${c};src:${s};font-style:${n.style.getPropertyValue("font-style") || "normal"};font-weight:${n.style.getPropertyValue("font-weight") || "normal"};}`;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
let e = s;
|
|
92
|
+
const h = Array.from(s.matchAll(l));
|
|
93
|
+
for (const g of h) {
|
|
94
|
+
let b = g[2].trim();
|
|
95
|
+
if (!b) continue;
|
|
96
|
+
let r = b;
|
|
97
|
+
if (!r.startsWith("http") && !r.startsWith("data:") && (r = new URL(r, t.href || location.href).href), !y(r)) {
|
|
98
|
+
if (o.resource.has(r)) {
|
|
99
|
+
o.font.add(r), e = e.replace(
|
|
100
|
+
g[0],
|
|
101
|
+
`url(${o.resource.get(r)})`
|
|
101
102
|
);
|
|
102
103
|
continue;
|
|
103
104
|
}
|
|
104
|
-
if (!
|
|
105
|
+
if (!o.font.has(r))
|
|
105
106
|
try {
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
107
|
+
const A = await (await fetch(r)).blob(), S = await new Promise((C) => {
|
|
108
|
+
const R = new FileReader();
|
|
109
|
+
R.onload = () => C(R.result), R.readAsDataURL(A);
|
|
109
110
|
});
|
|
110
|
-
|
|
111
|
+
o.resource.set(r, S), o.font.add(r), e = e.replace(g[0], `url(${S})`);
|
|
111
112
|
} catch {
|
|
112
|
-
console.warn("[snapdom] Failed to fetch font URL:",
|
|
113
|
+
console.warn("[snapdom] Failed to fetch font URL:", r);
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
-
font-family: ${n.style.getPropertyValue("font-family")};
|
|
118
|
-
src: ${s};
|
|
119
|
-
font-style: ${n.style.getPropertyValue("font-style") || "normal"};
|
|
120
|
-
font-weight: ${n.style.getPropertyValue("font-weight") || "normal"};
|
|
121
|
-
}
|
|
122
|
-
`;
|
|
117
|
+
m += `@font-face{font-family:${c};src:${e};font-style:${n.style.getPropertyValue("font-style") || "normal"};font-weight:${n.style.getPropertyValue("font-weight") || "normal"};}`;
|
|
123
118
|
}
|
|
124
119
|
}
|
|
125
120
|
} catch (n) {
|
|
@@ -127,17 +122,18 @@ async function P({
|
|
|
127
122
|
}
|
|
128
123
|
for (const t of document.fonts)
|
|
129
124
|
if (t.family && t.status === "loaded" && t._snapdomSrc) {
|
|
125
|
+
if (y(t.family)) continue;
|
|
130
126
|
let n = t._snapdomSrc;
|
|
131
127
|
if (!n.startsWith("data:")) {
|
|
132
|
-
if (
|
|
133
|
-
n =
|
|
134
|
-
else if (!
|
|
128
|
+
if (o.resource.has(t._snapdomSrc))
|
|
129
|
+
n = o.resource.get(t._snapdomSrc), o.font.add(t._snapdomSrc);
|
|
130
|
+
else if (!o.font.has(t._snapdomSrc))
|
|
135
131
|
try {
|
|
136
|
-
const
|
|
137
|
-
n = await new Promise((
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
}),
|
|
132
|
+
const c = await (await fetch(t._snapdomSrc)).blob();
|
|
133
|
+
n = await new Promise((l) => {
|
|
134
|
+
const f = new FileReader();
|
|
135
|
+
f.onload = () => l(f.result), f.readAsDataURL(c);
|
|
136
|
+
}), o.resource.set(t._snapdomSrc, n), o.font.add(t._snapdomSrc);
|
|
141
137
|
} catch {
|
|
142
138
|
console.warn(
|
|
143
139
|
"[snapdom] Failed to fetch dynamic font src:",
|
|
@@ -146,21 +142,15 @@ async function P({
|
|
|
146
142
|
continue;
|
|
147
143
|
}
|
|
148
144
|
}
|
|
149
|
-
|
|
150
|
-
font-family: '${t.family}';
|
|
151
|
-
src: url(${n});
|
|
152
|
-
font-style: ${t.style || "normal"};
|
|
153
|
-
font-weight: ${t.weight || "normal"};
|
|
154
|
-
}
|
|
155
|
-
`;
|
|
145
|
+
m += `@font-face{font-family:'${t.family}';src:url(${n});font-style:${t.style || "normal"};font-weight:${t.weight || "normal"};}`;
|
|
156
146
|
}
|
|
157
|
-
if (
|
|
147
|
+
if (m && (o.resource.set("fonts-embed-css", m), u)) {
|
|
158
148
|
const t = document.createElement("style");
|
|
159
|
-
t.setAttribute("data-snapdom", "embedFonts"), t.textContent =
|
|
149
|
+
t.setAttribute("data-snapdom", "embedFonts"), t.textContent = m, document.head.appendChild(t);
|
|
160
150
|
}
|
|
161
|
-
return
|
|
151
|
+
return m;
|
|
162
152
|
}
|
|
163
153
|
export {
|
|
164
|
-
|
|
165
|
-
|
|
154
|
+
T as embedCustomFonts,
|
|
155
|
+
E as iconToImage
|
|
166
156
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var s = [
|
|
2
|
+
// /uicons/i,
|
|
3
|
+
/font\s*awesome/i,
|
|
4
|
+
/material\s*icons/i,
|
|
5
|
+
/ionicons/i,
|
|
6
|
+
/glyphicons/i,
|
|
7
|
+
/feather/i,
|
|
8
|
+
/bootstrap\s*icons/i,
|
|
9
|
+
/remix\s*icons/i,
|
|
10
|
+
/heroicons/i,
|
|
11
|
+
/layui/i,
|
|
12
|
+
/lucide/i
|
|
13
|
+
], o = [];
|
|
14
|
+
function r(i) {
|
|
15
|
+
const e = Array.isArray(i) ? i : [i];
|
|
16
|
+
for (const t of e)
|
|
17
|
+
t instanceof RegExp ? o.push(t) : typeof t == "string" ? o.push(new RegExp(t, "i")) : console.warn("[snapdom] Ignored invalid iconFont value:", t);
|
|
18
|
+
}
|
|
19
|
+
function c(i) {
|
|
20
|
+
const e = typeof i == "string" ? i : "", t = [...s, ...o];
|
|
21
|
+
for (const n of t)
|
|
22
|
+
if (n instanceof RegExp && n.test(e)) return !0;
|
|
23
|
+
return !!(/icon/i.test(e) || /glyph/i.test(e) || /symbols/i.test(e) || /feather/i.test(e) || /fontawesome/i.test(e));
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
r as extendIconFonts,
|
|
27
|
+
c as isIconFont
|
|
28
|
+
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { fetchImage as
|
|
2
|
-
async function h(
|
|
3
|
-
const r = Array.from(
|
|
1
|
+
import { fetchImage as l } from "../utils/helpers.js";
|
|
2
|
+
async function h(n, a = {}) {
|
|
3
|
+
const r = Array.from(n.querySelectorAll("img")), i = async (t) => {
|
|
4
4
|
const c = t.src;
|
|
5
5
|
try {
|
|
6
|
-
const e =
|
|
7
|
-
t.src =
|
|
6
|
+
const e = await l(c, { useProxy: a.useProxy });
|
|
7
|
+
t.src = e, t.width || (t.width = t.naturalWidth || 100), t.height || (t.height = t.naturalHeight || 100);
|
|
8
8
|
} catch {
|
|
9
9
|
const e = document.createElement("div");
|
|
10
10
|
e.style = `width: ${t.width || 100}px; height: ${t.height || 100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${t.height || 100}px; color: #666; font-size: 12px;`, e.innerText = "img", t.replaceWith(e);
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
13
|
for (let t = 0; t < r.length; t += 4) {
|
|
14
|
-
const c = r.slice(t, t + 4).map(
|
|
14
|
+
const c = r.slice(t, t + 4).map(i);
|
|
15
15
|
await Promise.allSettled(c);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -1,90 +1,92 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { cache as I } from "../core/cache.js";
|
|
2
|
+
import { iconToImage as T } from "./fonts.js";
|
|
3
|
+
import { isIconFont as $ } from "./iconFonts.js";
|
|
4
|
+
import { getStyleKey as N } from "../utils/cssTools.js";
|
|
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) {
|
|
7
|
+
if (!(c instanceof Element) || !(r instanceof Element)) return;
|
|
6
8
|
for (const n of ["::before", "::after", "::first-letter"])
|
|
7
9
|
try {
|
|
8
|
-
const t =
|
|
10
|
+
const t = z(c, n);
|
|
9
11
|
if (!t || typeof t[Symbol.iterator] != "function") continue;
|
|
10
12
|
if (n === "::first-letter") {
|
|
11
|
-
const
|
|
12
|
-
if (!(t.color !==
|
|
13
|
-
const d = Array.from(
|
|
13
|
+
const l = getComputedStyle(c);
|
|
14
|
+
if (!(t.color !== l.color || t.fontSize !== l.fontSize || t.fontWeight !== l.fontWeight)) continue;
|
|
15
|
+
const d = Array.from(r.childNodes).find(
|
|
14
16
|
(e) => e.nodeType === Node.TEXT_NODE && e.textContent && e.textContent.trim().length > 0
|
|
15
17
|
);
|
|
16
18
|
if (!d) continue;
|
|
17
|
-
const
|
|
19
|
+
const g = d.textContent, f = g.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0], x = g.slice(f?.length || 0);
|
|
18
20
|
if (!f || /[\uD800-\uDFFF]/.test(f)) continue;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const s =
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
21
|
+
const a = document.createElement("span");
|
|
22
|
+
a.textContent = f, a.dataset.snapdomPseudo = "::first-letter";
|
|
23
|
+
const s = V(t), B = N(s, "span", h);
|
|
24
|
+
I.preStyleMap.set(a, B);
|
|
25
|
+
const E = document.createTextNode(x);
|
|
26
|
+
r.replaceChild(E, d), r.insertBefore(a, E);
|
|
25
27
|
continue;
|
|
26
28
|
}
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
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");
|
|
30
32
|
o.dataset.snapdomPseudo = n;
|
|
31
|
-
const f =
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
if (!w && r && s.length === 1) {
|
|
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) {
|
|
37
38
|
const e = document.createElement("img");
|
|
38
|
-
e.src = await
|
|
39
|
+
e.src = await T(
|
|
39
40
|
s,
|
|
40
|
-
|
|
41
|
+
l,
|
|
41
42
|
d,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
), e.style =
|
|
43
|
+
m,
|
|
44
|
+
g
|
|
45
|
+
), e.style = `width:${m}px;height:auto;object-fit:contain;`, o.appendChild(e);
|
|
45
46
|
} else if (s.startsWith("url(")) {
|
|
46
|
-
const e =
|
|
47
|
+
const e = W(s);
|
|
47
48
|
if (e && e.trim() !== "")
|
|
48
49
|
try {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const i = document.createElement("img"), P = await j(
|
|
51
|
+
A(e, { useProxy: S })
|
|
52
|
+
);
|
|
53
|
+
i.src = P, i.style = `width:${m}px;height:auto;object-fit:contain;`, o.appendChild(i);
|
|
54
|
+
} catch (i) {
|
|
52
55
|
console.error(
|
|
53
56
|
`[snapdom] Error in pseudo ${n} for`,
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
c,
|
|
58
|
+
i
|
|
56
59
|
);
|
|
57
60
|
}
|
|
58
|
-
} else !
|
|
59
|
-
if (
|
|
61
|
+
} else !a && s && s !== "none" && (o.textContent = s);
|
|
62
|
+
if (C)
|
|
60
63
|
try {
|
|
61
|
-
const e =
|
|
62
|
-
e.map((
|
|
64
|
+
const e = D(y), i = await Promise.all(
|
|
65
|
+
e.map((P) => L(P))
|
|
63
66
|
);
|
|
64
|
-
o.style.backgroundImage =
|
|
67
|
+
o.style.backgroundImage = i.join(", ");
|
|
65
68
|
} catch (e) {
|
|
66
69
|
console.warn(
|
|
67
70
|
`[snapdom] Failed to inline background-image for ${n}`,
|
|
68
71
|
e
|
|
69
72
|
);
|
|
70
73
|
}
|
|
71
|
-
if (
|
|
72
|
-
n === "::before" ?
|
|
74
|
+
if (b && (o.style.backgroundColor = p), !(o.childNodes.length > 0 || o.textContent && o.textContent.trim() !== "" || C || b)) continue;
|
|
75
|
+
n === "::before" ? r.insertBefore(o, r.firstChild) : r.appendChild(o);
|
|
73
76
|
}
|
|
74
77
|
} catch (t) {
|
|
75
|
-
console.warn(`[snapdom] Failed to capture ${n} for`,
|
|
78
|
+
console.warn(`[snapdom] Failed to capture ${n} for`, c, t);
|
|
76
79
|
}
|
|
77
|
-
const
|
|
80
|
+
const w = Array.from(c.children), k = Array.from(r.children).filter(
|
|
78
81
|
(n) => !n.dataset.snapdomPseudo
|
|
79
82
|
);
|
|
80
|
-
for (let n = 0; n < Math.min(
|
|
83
|
+
for (let n = 0; n < Math.min(w.length, k.length); n++)
|
|
81
84
|
await R(
|
|
82
|
-
|
|
85
|
+
w[n],
|
|
83
86
|
k[n],
|
|
84
|
-
g,
|
|
85
|
-
F,
|
|
86
87
|
h,
|
|
87
|
-
|
|
88
|
+
F,
|
|
89
|
+
S
|
|
88
90
|
);
|
|
89
91
|
}
|
|
90
92
|
export {
|
|
@@ -1,11 +1,31 @@
|
|
|
1
|
+
import { cache as e } from "../core/cache.js";
|
|
1
2
|
import { getStyleKey as y } from "../utils/cssTools.js";
|
|
2
|
-
import { getStyle as
|
|
3
|
-
function
|
|
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
|
+
}
|
|
11
|
+
return a;
|
|
12
|
+
}
|
|
13
|
+
function d(t, a, o) {
|
|
4
14
|
if (t.tagName === "STYLE") return;
|
|
5
|
-
e.has(t) || e.set(t,
|
|
6
|
-
const
|
|
7
|
-
|
|
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
|
+
}
|
|
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
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const h = t.tagName?.toLowerCase() || "div", i = y(n, h, o);
|
|
27
|
+
e.snapshotKey.set(l, i), e.preStyleMap.set(a, i);
|
|
8
28
|
}
|
|
9
29
|
export {
|
|
10
|
-
|
|
30
|
+
d as inlineAllStyles
|
|
11
31
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function l(s) {
|
|
2
|
+
if (!s) return;
|
|
3
|
+
const f = document.querySelectorAll("svg > defs");
|
|
4
|
+
f.length && s.querySelectorAll("svg").forEach((r) => {
|
|
5
|
+
const c = r.querySelectorAll("use");
|
|
6
|
+
if (!c.length) return;
|
|
7
|
+
const n = /* @__PURE__ */ new Set();
|
|
8
|
+
if (c.forEach((t) => {
|
|
9
|
+
const e = t.getAttribute("xlink:href") || t.getAttribute("href");
|
|
10
|
+
e && e.startsWith("#") && n.add(e.slice(1));
|
|
11
|
+
}), !n.size) return;
|
|
12
|
+
const o = document.createElementNS("http://www.w3.org/2000/svg", "defs");
|
|
13
|
+
for (const t of n)
|
|
14
|
+
for (const e of f) {
|
|
15
|
+
const i = e.querySelector(`#${CSS.escape(t)}`);
|
|
16
|
+
if (i) {
|
|
17
|
+
o.appendChild(i.cloneNode(!0));
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
o.childNodes.length && r.insertBefore(o, r.firstChild);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
l as inlineExternalDef
|
|
26
|
+
};
|