@unicom-cloud/utils 0.1.11 → 0.1.12
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/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 +26 -36
- package/snapdom/src/api/snapdom.js +78 -61
- package/snapdom/src/core/capture.js +54 -54
- package/snapdom/src/core/prepare.js +46 -37
- package/snapdom/src/modules/fonts.js +90 -92
- package/snapdom/src/modules/iconFonts.js +28 -0
- package/snapdom/src/modules/images.js +6 -6
- package/snapdom/src/modules/pseudo.js +51 -49
- package/snapdom/src/modules/styles.js +27 -7
- package/snapdom/src/modules/svgDefs.js +26 -0
- package/snapdom/src/utils/helpers.js +150 -103
- 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.js +9 -7
- package/types/date/index.d.ts +4 -0
- 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/prepare.d.ts +1 -1
- 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 -1
- 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/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/ui-color/compareColorByRange.d.ts +2 -0
- package/types/ui-color/index.d.ts +183 -0
- package/ui-color/compareColorByRange.js +9 -0
- package/ui-color/index.js +155 -0
- package/uiColor.js +28 -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/searchTree.js +0 -4
- package/types/dayjs/index.d.ts +0 -1
- package/types/lunar-converter/index.d.ts +0 -113
- /package/{convert-time/index.js → date/convertTime.js} +0 -0
- /package/{search-tree/index.js → tree/searchTree.js} +0 -0
- /package/types/{convert-time/index.d.ts → date/convertTime.d.ts} +0 -0
- /package/types/{search-tree/index.d.ts → tree/searchTree.d.ts} +0 -0
|
@@ -1,143 +1,141 @@
|
|
|
1
1
|
import { resourceCache as c, processedFontURLs as h } from "../core/cache.js";
|
|
2
|
-
import { isIconFont as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { isIconFont as w } from "./iconFonts.js";
|
|
3
|
+
import { extractURL as $ } from "../utils/helpers.js";
|
|
4
|
+
async function _(m, l, r, y = 32, u = "#000") {
|
|
5
|
+
l = l.replace(/^['"]+|['"]+$/g, "");
|
|
6
|
+
const t = window.devicePixelRatio || 1, s = document.createElement("canvas").getContext("2d");
|
|
7
|
+
s.font = r ? `${r} ${y}px "${l}"` : `${y}px "${l}"`;
|
|
8
|
+
const i = s.measureText(m), f = i.actualBoundingBoxAscent || y * 0.8, a = i.actualBoundingBoxDescent || y * 0.2, d = f + a, p = i.width, n = document.createElement("canvas");
|
|
9
|
+
n.width = Math.ceil(p * t), n.height = Math.ceil(d * t);
|
|
10
|
+
const e = n.getContext("2d");
|
|
11
|
+
return e.scale(t, t), e.font = s.font, e.textAlign = "left", e.textBaseline = "alphabetic", e.fillStyle = u, e.fillText(m, 0, f), n.toDataURL();
|
|
11
12
|
}
|
|
12
|
-
function A(
|
|
13
|
-
return Array.from(document.styleSheets).some((
|
|
13
|
+
function A(m) {
|
|
14
|
+
return Array.from(document.styleSheets).some((l) => l.href === m);
|
|
14
15
|
}
|
|
15
|
-
function C(
|
|
16
|
-
return new Promise((
|
|
17
|
-
if (A(
|
|
18
|
-
const
|
|
19
|
-
|
|
16
|
+
function C(m) {
|
|
17
|
+
return new Promise((l) => {
|
|
18
|
+
if (A(m)) return l(null);
|
|
19
|
+
const r = document.createElement("link");
|
|
20
|
+
r.rel = "stylesheet", r.href = m, r.setAttribute("data-snapdom", "injected-import"), r.onload = () => l(r), r.onerror = () => l(null), document.head.appendChild(r);
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
|
-
async function P({
|
|
23
|
-
ignoreIconFonts: f = !0,
|
|
24
|
-
preCached: a = !1
|
|
25
|
-
} = {}) {
|
|
23
|
+
async function P({ preCached: m = !1 } = {}) {
|
|
26
24
|
if (c.has("fonts-embed-css")) {
|
|
27
|
-
if (
|
|
25
|
+
if (m) {
|
|
28
26
|
const t = document.createElement("style");
|
|
29
27
|
t.setAttribute("data-snapdom", "embedFonts"), t.textContent = c.get("fonts-embed-css"), document.head.appendChild(t);
|
|
30
28
|
}
|
|
31
29
|
return c.get("fonts-embed-css");
|
|
32
30
|
}
|
|
33
|
-
const l = /@import\s+url\(["']?([^"')]+)["']?\)/g,
|
|
31
|
+
const l = /@import\s+url\(["']?([^"')]+)["']?\)/g, r = [];
|
|
34
32
|
for (const t of document.querySelectorAll("style")) {
|
|
35
|
-
const
|
|
36
|
-
for (const
|
|
37
|
-
const
|
|
38
|
-
A(
|
|
33
|
+
const o = t.textContent || "", s = Array.from(o.matchAll(l));
|
|
34
|
+
for (const i of s) {
|
|
35
|
+
const f = i[1];
|
|
36
|
+
w(f) || A(f) || r.push(f);
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
|
-
await Promise.all(
|
|
42
|
-
const
|
|
39
|
+
await Promise.all(r.map(C));
|
|
40
|
+
const y = Array.from(
|
|
43
41
|
document.querySelectorAll('link[rel="stylesheet"]')
|
|
44
42
|
).filter((t) => t.href);
|
|
45
|
-
let
|
|
46
|
-
for (const t of
|
|
43
|
+
let u = "";
|
|
44
|
+
for (const t of y)
|
|
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 (w(t.href) || w(s)) continue;
|
|
48
|
+
const i = /url\((["']?)([^"')]+)\1\)/g, f = await Promise.all(
|
|
49
|
+
Array.from(s.matchAll(i)).map(async (d) => {
|
|
50
|
+
let p = $(d[0]);
|
|
51
|
+
if (!p) return null;
|
|
52
|
+
let n = p;
|
|
53
|
+
if (!n.startsWith("http") && !n.startsWith("data:") && (n = new URL(n, t.href).href), w(n)) return null;
|
|
54
|
+
if (c.has(n))
|
|
55
|
+
return h.add(n), {
|
|
56
|
+
original: d[0],
|
|
57
|
+
inlined: `url(${c.get(n)})`
|
|
61
58
|
};
|
|
62
|
-
if (h.has(
|
|
59
|
+
if (h.has(n)) return null;
|
|
63
60
|
try {
|
|
64
|
-
const S = await (await fetch(
|
|
65
|
-
const
|
|
66
|
-
|
|
61
|
+
const S = await (await fetch(n)).blob(), b = await new Promise((x) => {
|
|
62
|
+
const g = new FileReader();
|
|
63
|
+
g.onload = () => x(g.result), g.readAsDataURL(S);
|
|
67
64
|
});
|
|
68
|
-
return c.set(
|
|
65
|
+
return c.set(n, b), h.add(n), { original: d[0], inlined: `url(${b})` };
|
|
69
66
|
} catch {
|
|
70
|
-
return console.warn("[snapdom] Failed to fetch font resource:",
|
|
67
|
+
return console.warn("[snapdom] Failed to fetch font resource:", n), null;
|
|
71
68
|
}
|
|
72
69
|
})
|
|
73
70
|
);
|
|
74
|
-
let
|
|
75
|
-
for (const
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
let a = s;
|
|
72
|
+
for (const d of f)
|
|
73
|
+
d && (a = a.replace(d.original, d.inlined));
|
|
74
|
+
u += a + `
|
|
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 ||
|
|
85
|
-
for (const
|
|
86
|
-
if (
|
|
87
|
-
const
|
|
88
|
-
if (!
|
|
89
|
-
const
|
|
90
|
-
let
|
|
91
|
-
const d = Array.from(
|
|
92
|
-
for (const
|
|
93
|
-
let
|
|
94
|
-
if (!
|
|
95
|
-
let e =
|
|
96
|
-
if (!e.startsWith("http") && !e.startsWith("data:") && (e = new URL(e, t.href || location.href).href), !(
|
|
81
|
+
if (!t.href || y.every((o) => o.href !== t.href)) {
|
|
82
|
+
for (const o of t.cssRules)
|
|
83
|
+
if (o.type === CSSRule.FONT_FACE_RULE) {
|
|
84
|
+
const s = o.style.getPropertyValue("src"), i = o.style.getPropertyValue("font-family");
|
|
85
|
+
if (!s || w(i)) continue;
|
|
86
|
+
const f = /url\((["']?)([^"')]+)\1\)/g;
|
|
87
|
+
let a = s;
|
|
88
|
+
const d = Array.from(s.matchAll(f));
|
|
89
|
+
for (const p of d) {
|
|
90
|
+
let n = p[2].trim();
|
|
91
|
+
if (!n) continue;
|
|
92
|
+
let e = n;
|
|
93
|
+
if (!e.startsWith("http") && !e.startsWith("data:") && (e = new URL(e, t.href || location.href).href), !w(e)) {
|
|
97
94
|
if (c.has(e)) {
|
|
98
|
-
h.add(e),
|
|
99
|
-
|
|
95
|
+
h.add(e), a = a.replace(
|
|
96
|
+
p[0],
|
|
100
97
|
`url(${c.get(e)})`
|
|
101
98
|
);
|
|
102
99
|
continue;
|
|
103
100
|
}
|
|
104
101
|
if (!h.has(e))
|
|
105
102
|
try {
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
103
|
+
const b = await (await fetch(e)).blob(), x = await new Promise((g) => {
|
|
104
|
+
const R = new FileReader();
|
|
105
|
+
R.onload = () => g(R.result), R.readAsDataURL(b);
|
|
109
106
|
});
|
|
110
|
-
c.set(e,
|
|
107
|
+
c.set(e, x), h.add(e), a = a.replace(p[0], `url(${x})`);
|
|
111
108
|
} catch {
|
|
112
109
|
console.warn("[snapdom] Failed to fetch font URL:", e);
|
|
113
110
|
}
|
|
114
111
|
}
|
|
115
112
|
}
|
|
116
|
-
|
|
117
|
-
font-family: ${
|
|
118
|
-
src: ${
|
|
119
|
-
font-style: ${
|
|
120
|
-
font-weight: ${
|
|
113
|
+
u += `@font-face {
|
|
114
|
+
font-family: ${i};
|
|
115
|
+
src: ${a};
|
|
116
|
+
font-style: ${o.style.getPropertyValue("font-style") || "normal"};
|
|
117
|
+
font-weight: ${o.style.getPropertyValue("font-weight") || "normal"};
|
|
121
118
|
}
|
|
122
119
|
`;
|
|
123
120
|
}
|
|
124
121
|
}
|
|
125
|
-
} catch (
|
|
126
|
-
console.warn("[snapdom] Cannot access stylesheet", t.href,
|
|
122
|
+
} catch (o) {
|
|
123
|
+
console.warn("[snapdom] Cannot access stylesheet", t.href, o);
|
|
127
124
|
}
|
|
128
125
|
for (const t of document.fonts)
|
|
129
126
|
if (t.family && t.status === "loaded" && t._snapdomSrc) {
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
if (w(t.family)) continue;
|
|
128
|
+
let o = t._snapdomSrc;
|
|
129
|
+
if (!o.startsWith("data:")) {
|
|
132
130
|
if (c.has(t._snapdomSrc))
|
|
133
|
-
|
|
131
|
+
o = c.get(t._snapdomSrc), h.add(t._snapdomSrc);
|
|
134
132
|
else if (!h.has(t._snapdomSrc))
|
|
135
133
|
try {
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
}), c.set(t._snapdomSrc,
|
|
134
|
+
const i = await (await fetch(t._snapdomSrc)).blob();
|
|
135
|
+
o = await new Promise((f) => {
|
|
136
|
+
const a = new FileReader();
|
|
137
|
+
a.onload = () => f(a.result), a.readAsDataURL(i);
|
|
138
|
+
}), c.set(t._snapdomSrc, o), h.add(t._snapdomSrc);
|
|
141
139
|
} catch {
|
|
142
140
|
console.warn(
|
|
143
141
|
"[snapdom] Failed to fetch dynamic font src:",
|
|
@@ -146,19 +144,19 @@ async function P({
|
|
|
146
144
|
continue;
|
|
147
145
|
}
|
|
148
146
|
}
|
|
149
|
-
|
|
147
|
+
u += `@font-face {
|
|
150
148
|
font-family: '${t.family}';
|
|
151
|
-
src: url(${
|
|
149
|
+
src: url(${o});
|
|
152
150
|
font-style: ${t.style || "normal"};
|
|
153
151
|
font-weight: ${t.weight || "normal"};
|
|
154
152
|
}
|
|
155
153
|
`;
|
|
156
154
|
}
|
|
157
|
-
if (
|
|
155
|
+
if (u && (c.set("fonts-embed-css", u), m)) {
|
|
158
156
|
const t = document.createElement("style");
|
|
159
|
-
t.setAttribute("data-snapdom", "embedFonts"), t.textContent =
|
|
157
|
+
t.setAttribute("data-snapdom", "embedFonts"), t.textContent = u, document.head.appendChild(t);
|
|
160
158
|
}
|
|
161
|
-
return
|
|
159
|
+
return u;
|
|
162
160
|
}
|
|
163
161
|
export {
|
|
164
162
|
P as embedCustomFonts,
|
|
@@ -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,92 +1,94 @@
|
|
|
1
1
|
import { iconToImage as z } from "./fonts.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { isIconFont as U } from "./iconFonts.js";
|
|
3
|
+
import { getStyleKey as N } from "../utils/cssTools.js";
|
|
4
|
+
import { getStyle as W, snapshotComputedStyle as V, parseContent as j, extractURL as A, fetchImage as D, safeEncodeURI as L, splitBackgroundImage as R, inlineSingleBackgroundEntry as K } from "../utils/helpers.js";
|
|
5
|
+
async function M(c, r, h, F, u, T = !1, w) {
|
|
6
|
+
if (!(c instanceof Element) || !(r instanceof Element)) return;
|
|
6
7
|
for (const n of ["::before", "::after", "::first-letter"])
|
|
7
8
|
try {
|
|
8
|
-
const t =
|
|
9
|
+
const t = W(c, n);
|
|
9
10
|
if (!t || typeof t[Symbol.iterator] != "function") continue;
|
|
10
11
|
if (n === "::first-letter") {
|
|
11
|
-
const
|
|
12
|
-
if (!(t.color !==
|
|
13
|
-
const d = Array.from(
|
|
12
|
+
const l = getComputedStyle(c);
|
|
13
|
+
if (!(t.color !== l.color || t.fontSize !== l.fontSize || t.fontWeight !== l.fontWeight)) continue;
|
|
14
|
+
const d = Array.from(r.childNodes).find(
|
|
14
15
|
(e) => e.nodeType === Node.TEXT_NODE && e.textContent && e.textContent.trim().length > 0
|
|
15
16
|
);
|
|
16
17
|
if (!d) continue;
|
|
17
|
-
const
|
|
18
|
+
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
19
|
if (!f || /[\uD800-\uDFFF]/.test(f)) continue;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const s =
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
20
|
+
const a = document.createElement("span");
|
|
21
|
+
a.textContent = f, a.dataset.snapdomPseudo = "::first-letter";
|
|
22
|
+
const s = V(t), I = N(s, "span", u);
|
|
23
|
+
h.set(a, I);
|
|
24
|
+
const E = document.createTextNode(x);
|
|
25
|
+
r.replaceChild(E, d), r.insertBefore(a, E);
|
|
25
26
|
continue;
|
|
26
27
|
}
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
28
|
+
const B = t.getPropertyValue("content"), y = t.getPropertyValue("background-image"), m = t.getPropertyValue("background-color"), $ = B !== "none", C = y && y !== "none", b = m && m !== "transparent" && m !== "rgba(0, 0, 0, 0)";
|
|
29
|
+
if ($ || C || b) {
|
|
30
|
+
const l = t.getPropertyValue("font-family"), p = parseInt(t.getPropertyValue("font-size")) || 32, d = parseInt(t.getPropertyValue("font-weight")) || !1, g = t.getPropertyValue("color") || "#000", o = document.createElement("span");
|
|
30
31
|
o.dataset.snapdomPseudo = n;
|
|
31
|
-
const f =
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
), s = W(S);
|
|
36
|
-
if (!w && r && s.length === 1) {
|
|
32
|
+
const f = V(t), x = N(f, "span", u);
|
|
33
|
+
h.set(o, x);
|
|
34
|
+
const a = U(l), s = j(B);
|
|
35
|
+
if (a && s.length === 1) {
|
|
37
36
|
const e = document.createElement("img");
|
|
38
37
|
e.src = await z(
|
|
39
38
|
s,
|
|
40
|
-
|
|
39
|
+
l,
|
|
41
40
|
d,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
), e.style =
|
|
41
|
+
p,
|
|
42
|
+
g
|
|
43
|
+
), e.style = `width:${p}px;height:auto;object-fit:contain;`, o.appendChild(e);
|
|
45
44
|
} else if (s.startsWith("url(")) {
|
|
46
|
-
const e =
|
|
45
|
+
const e = A(s);
|
|
47
46
|
if (e && e.trim() !== "")
|
|
48
47
|
try {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
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) {
|
|
52
53
|
console.error(
|
|
53
54
|
`[snapdom] Error in pseudo ${n} for`,
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
c,
|
|
56
|
+
i
|
|
56
57
|
);
|
|
57
58
|
}
|
|
58
|
-
} else !
|
|
59
|
-
if (
|
|
59
|
+
} else !a && s && s !== "none" && (o.textContent = s);
|
|
60
|
+
if (C)
|
|
60
61
|
try {
|
|
61
|
-
const e =
|
|
62
|
-
e.map((
|
|
62
|
+
const e = R(y), i = await Promise.all(
|
|
63
|
+
e.map((P) => K(P))
|
|
63
64
|
);
|
|
64
|
-
o.style.backgroundImage =
|
|
65
|
+
o.style.backgroundImage = i.join(", ");
|
|
65
66
|
} catch (e) {
|
|
66
67
|
console.warn(
|
|
67
68
|
`[snapdom] Failed to inline background-image for ${n}`,
|
|
68
69
|
e
|
|
69
70
|
);
|
|
70
71
|
}
|
|
71
|
-
if (
|
|
72
|
-
n === "::before" ?
|
|
72
|
+
if (b && (o.style.backgroundColor = m), !(o.childNodes.length > 0 || o.textContent && o.textContent.trim() !== "" || C || b)) continue;
|
|
73
|
+
n === "::before" ? r.insertBefore(o, r.firstChild) : r.appendChild(o);
|
|
73
74
|
}
|
|
74
75
|
} catch (t) {
|
|
75
|
-
console.warn(`[snapdom] Failed to capture ${n} for`,
|
|
76
|
+
console.warn(`[snapdom] Failed to capture ${n} for`, c, t);
|
|
76
77
|
}
|
|
77
|
-
const
|
|
78
|
+
const S = Array.from(c.children), k = Array.from(r.children).filter(
|
|
78
79
|
(n) => !n.dataset.snapdomPseudo
|
|
79
80
|
);
|
|
80
|
-
for (let n = 0; n < Math.min(
|
|
81
|
-
await
|
|
82
|
-
|
|
81
|
+
for (let n = 0; n < Math.min(S.length, k.length); n++)
|
|
82
|
+
await M(
|
|
83
|
+
S[n],
|
|
83
84
|
k[n],
|
|
84
|
-
g,
|
|
85
|
-
F,
|
|
86
85
|
h,
|
|
86
|
+
F,
|
|
87
|
+
u,
|
|
88
|
+
T,
|
|
87
89
|
w
|
|
88
90
|
);
|
|
89
91
|
}
|
|
90
92
|
export {
|
|
91
|
-
|
|
93
|
+
M as inlinePseudoElements
|
|
92
94
|
};
|
|
@@ -1,11 +1,31 @@
|
|
|
1
|
-
import { getStyleKey as
|
|
2
|
-
import { getStyle as
|
|
3
|
-
|
|
1
|
+
import { getStyleKey as c } from "../utils/cssTools.js";
|
|
2
|
+
import { getStyle as d } from "../utils/helpers.js";
|
|
3
|
+
const p = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new Map();
|
|
4
|
+
function y(t) {
|
|
5
|
+
const o = {};
|
|
6
|
+
for (let n = 0; n < t.length; n++) {
|
|
7
|
+
const e = t[n];
|
|
8
|
+
let a = t.getPropertyValue(e);
|
|
9
|
+
(e === "background-image" || e === "content") && a.includes("url(") && !a.includes("data:") && (a = "none"), o[e] = a;
|
|
10
|
+
}
|
|
11
|
+
return o;
|
|
12
|
+
}
|
|
13
|
+
function S(t, o, n, e, a) {
|
|
4
14
|
if (t.tagName === "STYLE") return;
|
|
5
|
-
e.has(t) || e.set(t,
|
|
6
|
-
const
|
|
7
|
-
|
|
15
|
+
e.has(t) || e.set(t, d(t));
|
|
16
|
+
const m = e.get(t);
|
|
17
|
+
if (!p.has(t)) {
|
|
18
|
+
const s = y(m);
|
|
19
|
+
p.set(t, s);
|
|
20
|
+
}
|
|
21
|
+
const g = p.get(t), i = Object.entries(g).sort(([s], [l]) => s.localeCompare(l)).map(([s, l]) => `${s}:${l}`).join(";");
|
|
22
|
+
if (r.has(i)) {
|
|
23
|
+
n.set(o, r.get(i));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const f = t.tagName?.toLowerCase() || "div", h = c(g, f, a);
|
|
27
|
+
r.set(i, h), n.set(o, h);
|
|
8
28
|
}
|
|
9
29
|
export {
|
|
10
|
-
|
|
30
|
+
S 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
|
+
};
|