@unicom-cloud/utils 0.1.16 → 0.1.18
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/class-name/index.js +5 -5
- package/constant/index.js +24 -2
- package/constant/platform.js +13 -12
- package/constant.js +24 -2
- package/content-disposition/index.js +3 -3
- package/date/convertTime.js +4 -4
- package/diff/index.js +7 -0
- package/diff/src/diff.d.ts +21 -0
- package/diff/src/diff.js +381 -0
- package/diff.js +7 -0
- package/filesize/types/constants.d.ts +81 -0
- package/filesize/types/filesize.d.ts +97 -0
- package/index.js +68 -58
- package/js-cookie/index.d.ts +116 -0
- package/js-cookie/index.js +4 -0
- package/js-cookie/src/api.js +56 -0
- package/js-cookie/src/assign.js +11 -0
- package/js-cookie/src/converter.js +14 -0
- package/jsCookie.js +4 -0
- package/lunar/lib/HolidayUtil.js +48 -49
- package/mitt/index.js +4 -0
- package/mitt/src/index.js +37 -0
- package/mitt.js +4 -0
- package/nzh/nzh.d.ts +74 -0
- package/package.json +1 -1
- package/pinyin/index.js +4 -0
- package/pinyin/simplified.js +4 -0
- package/pinyin/src/core.js +143 -0
- package/pinyin/src/simplified.js +8 -0
- package/pinyin/src/simplified_dict.js +410 -0
- package/pinyin/src/traditional.js +8 -0
- package/pinyin/src/traditional_dict.js +403 -0
- package/pinyin/traditional.js +4 -0
- package/pinyin.js +4 -0
- package/query-string/base.d.ts +717 -0
- package/query-string/base.js +268 -0
- package/query-string/index.d.ts +16 -0
- package/query-string/index.js +4 -0
- package/query-string/splitOnFirst.js +14 -0
- package/queryString.js +4 -0
- package/random/index.js +56 -35
- package/snapdom/src/api/preCache.js +51 -28
- package/snapdom/src/core/cache.js +1 -4
- package/snapdom/src/core/capture.js +45 -44
- package/snapdom/src/core/clone.js +82 -66
- package/snapdom/src/core/prepare.js +167 -45
- package/snapdom/src/modules/background.js +29 -19
- package/snapdom/src/modules/fonts.js +158 -111
- package/snapdom/src/modules/images.js +14 -9
- package/snapdom/src/modules/pseudo.js +52 -47
- package/snapdom/src/modules/styles.js +22 -22
- package/snapdom/src/modules/svgDefs.js +39 -20
- package/snapdom/src/utils/cssTools.js +58 -51
- package/snapdom/src/utils/helpers.js +197 -140
- package/snapdom/types/snapdom.d.ts +101 -0
- package/types/constant/index.d.ts +11 -0
- package/types/constant/platform.d.ts +1 -0
- package/types/diff/index.d.ts +2 -0
- package/types/diff/src/diff.d.ts +40 -0
- package/types/index.d.ts +6 -1
- package/types/js-cookie/index.d.ts +1 -0
- package/types/js-cookie/src/api.d.mts +2 -0
- package/types/js-cookie/src/assign.d.mts +1 -0
- package/types/js-cookie/src/converter.d.mts +5 -0
- package/types/mitt/index.d.ts +2 -0
- package/types/mitt/src/index.d.ts +29 -0
- package/types/pinyin/index.d.ts +1 -0
- package/types/pinyin/simplified.d.ts +1 -0
- package/types/pinyin/src/core.d.ts +3 -0
- package/types/pinyin/src/simplified.d.ts +4 -0
- package/types/pinyin/src/simplified_dict.d.ts +408 -0
- package/types/pinyin/src/traditional.d.ts +4 -0
- package/types/pinyin/src/traditional_dict.d.ts +401 -0
- package/types/pinyin/traditional.d.ts +1 -0
- package/types/query-string/base.d.ts +11 -0
- package/types/query-string/index.d.ts +2 -0
- package/types/query-string/splitOnFirst.d.ts +1 -0
- package/types/random/index.d.ts +14 -23
- package/types/snapdom/src/api/preCache.d.ts +2 -5
- package/types/snapdom/src/core/cache.d.ts +0 -3
- package/types/snapdom/src/core/clone.d.ts +1 -1
- package/types/snapdom/src/modules/background.d.ts +16 -6
- package/types/snapdom/src/modules/fonts.d.ts +5 -1
- package/types/snapdom/src/modules/pseudo.d.ts +1 -1
- package/types/snapdom/src/modules/styles.d.ts +1 -1
- package/types/snapdom/src/modules/svgDefs.d.ts +13 -13
- package/types/snapdom/src/utils/cssTools.d.ts +2 -10
- package/types/snapdom/src/utils/helpers.d.ts +13 -7
- package/types/turbo-stream/src/shared.d.ts +3 -3
- package/url-toolkit/src/url-toolkit.d.ts +22 -0
- package/event-emitter/index.js +0 -48
- package/eventEmitter.js +0 -4
- package/types/event-emitter/index.d.ts +0 -17
|
@@ -1,147 +1,174 @@
|
|
|
1
|
-
import { cache as
|
|
2
|
-
import { isIconFont as
|
|
3
|
-
import { extractURL as
|
|
4
|
-
async function
|
|
5
|
-
|
|
6
|
-
const
|
|
1
|
+
import { cache as o } from "../core/cache.js";
|
|
2
|
+
import { isIconFont as $ } from "./iconFonts.js";
|
|
3
|
+
import { fetchResource as A, extractURL as v } from "../utils/helpers.js";
|
|
4
|
+
async function H(h, d, c, y = 32, C = "#000") {
|
|
5
|
+
d = d.replace(/^['"]+|['"]+$/g, "");
|
|
6
|
+
const p = window.devicePixelRatio || 1;
|
|
7
7
|
await document.fonts.ready;
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
document.body.removeChild(
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
return
|
|
16
|
-
dataUrl:
|
|
17
|
-
width:
|
|
18
|
-
height:
|
|
8
|
+
const i = document.createElement("span");
|
|
9
|
+
i.textContent = h, i.style.position = "absolute", i.style.visibility = "hidden", i.style.fontFamily = `"${d}"`, i.style.fontWeight = c || "normal", i.style.fontSize = `${y}px`, i.style.lineHeight = "1", i.style.whiteSpace = "nowrap", i.style.padding = "0", i.style.margin = "0", document.body.appendChild(i);
|
|
10
|
+
const m = i.getBoundingClientRect(), t = Math.ceil(m.width), n = Math.ceil(m.height);
|
|
11
|
+
document.body.removeChild(i);
|
|
12
|
+
const e = document.createElement("canvas");
|
|
13
|
+
e.width = t * p, e.height = n * p;
|
|
14
|
+
const a = e.getContext("2d");
|
|
15
|
+
return a.scale(p, p), a.font = c ? `${c} ${y}px "${d}"` : `${y}px "${d}"`, a.textAlign = "left", a.textBaseline = "top", a.fillStyle = C, a.fillText(h, 0, 0), {
|
|
16
|
+
dataUrl: e.toDataURL(),
|
|
17
|
+
width: t,
|
|
18
|
+
height: n
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
return Array.from(document.styleSheets).some((
|
|
21
|
+
function T(h) {
|
|
22
|
+
return Array.from(document.styleSheets).some((d) => d.href === h);
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
return new Promise((
|
|
26
|
-
if (
|
|
27
|
-
const
|
|
28
|
-
|
|
24
|
+
function I(h) {
|
|
25
|
+
return new Promise((d) => {
|
|
26
|
+
if (T(h)) return d(null);
|
|
27
|
+
const c = document.createElement("link");
|
|
28
|
+
c.rel = "stylesheet", c.href = h, c.setAttribute("data-snapdom", "injected-import"), c.onload = () => d(c), c.onerror = () => d(null), document.head.appendChild(c);
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
async function
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
async function N({
|
|
32
|
+
preCached: h = !1,
|
|
33
|
+
localFonts: d = [],
|
|
34
|
+
useProxy: c = ""
|
|
35
|
+
} = {}) {
|
|
36
|
+
if (o.resource.has("fonts-embed-css")) {
|
|
37
|
+
if (h) {
|
|
34
38
|
const t = document.createElement("style");
|
|
35
|
-
t.setAttribute("data-snapdom", "embedFonts"), t.textContent =
|
|
39
|
+
t.setAttribute("data-snapdom", "embedFonts"), t.textContent = o.resource.get("fonts-embed-css"), document.head.appendChild(t);
|
|
36
40
|
}
|
|
37
|
-
return
|
|
41
|
+
return o.resource.get("fonts-embed-css");
|
|
38
42
|
}
|
|
39
|
-
const
|
|
43
|
+
const y = /* @__PURE__ */ new Set();
|
|
44
|
+
try {
|
|
45
|
+
for (const t of document.fonts)
|
|
46
|
+
t.status === "loaded" && y.add(
|
|
47
|
+
`${t.family}__${t.weight || "normal"}__${t.style || "normal"}`
|
|
48
|
+
);
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
const C = /@import\s+url\(["']?([^"')]+)["']?\)/g, p = [];
|
|
40
52
|
for (const t of document.querySelectorAll("style")) {
|
|
41
|
-
const
|
|
42
|
-
for (const
|
|
43
|
-
const
|
|
44
|
-
|
|
53
|
+
const n = t.textContent || "", e = Array.from(n.matchAll(C));
|
|
54
|
+
for (const a of e) {
|
|
55
|
+
const r = a[1];
|
|
56
|
+
$(r) || T(r) || p.push(r);
|
|
45
57
|
}
|
|
46
58
|
}
|
|
47
|
-
await Promise.all(
|
|
48
|
-
const
|
|
59
|
+
await Promise.all(p.map(I));
|
|
60
|
+
const i = Array.from(
|
|
49
61
|
document.querySelectorAll('link[rel="stylesheet"]')
|
|
50
62
|
).filter((t) => t.href);
|
|
51
|
-
let
|
|
52
|
-
for (const t of
|
|
63
|
+
let m = "";
|
|
64
|
+
for (const t of i)
|
|
53
65
|
try {
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
const e = await (await A(t.href, { useProxy: c })).text();
|
|
67
|
+
if ($(t.href) || $(e)) continue;
|
|
68
|
+
const a = /@font-face[^{}]*{[^}]*}/g;
|
|
69
|
+
let r = e;
|
|
70
|
+
for (const s of e.match(a) || []) {
|
|
71
|
+
const b = s.match(/font-family:\s*([^;]+);/i);
|
|
72
|
+
if (!b) continue;
|
|
73
|
+
const R = b[1].replace(/['"]/g, "").trim(), S = s.match(/font-weight:\s*([^;]+);/i), u = s.match(/font-style:\s*([^;]+);/i), F = S ? S[1].trim() : "normal", w = u ? u[1].trim() : "normal", k = `${R}__${F}__${w}`, x = /url\((["']?)([^"')]+)\1\)/g, L = /url\(/i.test(s), f = /local\(/i.test(s);
|
|
74
|
+
if (!L && f)
|
|
75
|
+
continue;
|
|
76
|
+
if (!y.has(k)) {
|
|
77
|
+
r = r.replace(s, "");
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
let g = s;
|
|
81
|
+
const E = Array.from(s.matchAll(x));
|
|
82
|
+
for (const _ of E) {
|
|
83
|
+
let U = v(_[0]);
|
|
84
|
+
if (!U) continue;
|
|
85
|
+
let l = U;
|
|
86
|
+
if (!l.startsWith("http") && !l.startsWith("data:") && (l = new URL(l, t.href).href), !$(l)) {
|
|
87
|
+
if (o.resource.has(l)) {
|
|
88
|
+
o.font.add(l), g = g.replace(
|
|
89
|
+
_[0],
|
|
90
|
+
`url(${o.resource.get(l)})`
|
|
91
|
+
);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (!o.font.has(l))
|
|
95
|
+
try {
|
|
96
|
+
const D = await (await A(l, { useProxy: c })).blob(), M = await new Promise((W) => {
|
|
97
|
+
const P = new FileReader();
|
|
98
|
+
P.onload = () => W(P.result), P.readAsDataURL(D);
|
|
99
|
+
});
|
|
100
|
+
o.resource.set(l, M), o.font.add(l), g = g.replace(_[0], `url(${M})`);
|
|
101
|
+
} catch {
|
|
102
|
+
console.warn("[snapdom] Failed to fetch font resource:", l);
|
|
103
|
+
}
|
|
76
104
|
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
s && (c = c.replace(s.original, s.inlined));
|
|
82
|
-
u += c + `
|
|
105
|
+
}
|
|
106
|
+
r = r.replace(s, g);
|
|
107
|
+
}
|
|
108
|
+
m += r + `
|
|
83
109
|
`;
|
|
84
110
|
} catch {
|
|
85
111
|
console.warn("[snapdom] Failed to fetch CSS:", t.href);
|
|
86
112
|
}
|
|
87
113
|
for (const t of document.styleSheets)
|
|
88
114
|
try {
|
|
89
|
-
if (!t.href ||
|
|
90
|
-
for (const
|
|
91
|
-
if (
|
|
92
|
-
const
|
|
93
|
-
if (!
|
|
94
|
-
const
|
|
95
|
-
if (!
|
|
96
|
-
|
|
115
|
+
if (!t.href || i.every((n) => n.href !== t.href)) {
|
|
116
|
+
for (const n of t.cssRules)
|
|
117
|
+
if (n.type === CSSRule.FONT_FACE_RULE) {
|
|
118
|
+
const e = n.style.getPropertyValue("src"), a = n.style.getPropertyValue("font-family");
|
|
119
|
+
if (!e || $(a)) continue;
|
|
120
|
+
const r = n.style.getPropertyValue("font-weight") || "normal", s = n.style.getPropertyValue("font-style") || "normal", b = `${a}__${r}__${s}`, R = /url\((["']?)([^"')]+)\1\)/g, S = /local\((["']?)[^)]+?\1\)/g, u = !!e.match(R), F = !!e.match(S);
|
|
121
|
+
if (!u && F) {
|
|
122
|
+
m += `@font-face{font-family:${a};src:${e};font-style:${s};font-weight:${r};}`;
|
|
97
123
|
continue;
|
|
98
124
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
125
|
+
if (!y.has(b)) continue;
|
|
126
|
+
let w = e;
|
|
127
|
+
const k = Array.from(e.matchAll(R));
|
|
128
|
+
for (const x of k) {
|
|
129
|
+
let L = x[2].trim();
|
|
130
|
+
if (!L) continue;
|
|
131
|
+
let f = L;
|
|
132
|
+
if (!f.startsWith("http") && !f.startsWith("data:") && (f = new URL(f, t.href || location.href).href), !$(f)) {
|
|
133
|
+
if (o.resource.has(f)) {
|
|
134
|
+
o.font.add(f), w = w.replace(
|
|
135
|
+
x[0],
|
|
136
|
+
`url(${o.resource.get(f)})`
|
|
110
137
|
);
|
|
111
138
|
continue;
|
|
112
139
|
}
|
|
113
|
-
if (!
|
|
140
|
+
if (!o.font.has(f))
|
|
114
141
|
try {
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
|
|
142
|
+
const E = await (await A(f, { useProxy: c })).blob(), _ = await new Promise((U) => {
|
|
143
|
+
const l = new FileReader();
|
|
144
|
+
l.onload = () => U(l.result), l.readAsDataURL(E);
|
|
118
145
|
});
|
|
119
|
-
|
|
146
|
+
o.resource.set(f, _), o.font.add(f), w = w.replace(x[0], `url(${_})`);
|
|
120
147
|
} catch {
|
|
121
|
-
console.warn("[snapdom] Failed to fetch font URL:",
|
|
148
|
+
console.warn("[snapdom] Failed to fetch font URL:", f);
|
|
122
149
|
}
|
|
123
150
|
}
|
|
124
151
|
}
|
|
125
|
-
|
|
152
|
+
m += `@font-face{font-family:${a};src:${w};font-style:${s};font-weight:${r};}`;
|
|
126
153
|
}
|
|
127
154
|
}
|
|
128
|
-
} catch (
|
|
129
|
-
console.warn("[snapdom] Cannot access stylesheet", t.href,
|
|
155
|
+
} catch (n) {
|
|
156
|
+
console.warn("[snapdom] Cannot access stylesheet", t.href, n);
|
|
130
157
|
}
|
|
131
158
|
for (const t of document.fonts)
|
|
132
159
|
if (t.family && t.status === "loaded" && t._snapdomSrc) {
|
|
133
|
-
if (
|
|
134
|
-
let
|
|
135
|
-
if (!
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
else if (!
|
|
160
|
+
if ($(t.family)) continue;
|
|
161
|
+
let n = t._snapdomSrc;
|
|
162
|
+
if (!n.startsWith("data:")) {
|
|
163
|
+
if (o.resource.has(t._snapdomSrc))
|
|
164
|
+
n = o.resource.get(t._snapdomSrc), o.font.add(t._snapdomSrc);
|
|
165
|
+
else if (!o.font.has(t._snapdomSrc))
|
|
139
166
|
try {
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
}),
|
|
167
|
+
const a = await (await A(t._snapdomSrc, { useProxy: c })).blob();
|
|
168
|
+
n = await new Promise((r) => {
|
|
169
|
+
const s = new FileReader();
|
|
170
|
+
s.onload = () => r(s.result), s.readAsDataURL(a);
|
|
171
|
+
}), o.resource.set(t._snapdomSrc, n), o.font.add(t._snapdomSrc);
|
|
145
172
|
} catch {
|
|
146
173
|
console.warn(
|
|
147
174
|
"[snapdom] Failed to fetch dynamic font src:",
|
|
@@ -150,15 +177,35 @@ async function k({ preCached: m = !1 } = {}) {
|
|
|
150
177
|
continue;
|
|
151
178
|
}
|
|
152
179
|
}
|
|
153
|
-
|
|
180
|
+
m += `@font-face{font-family:'${t.family}';src:url(${n});font-style:${t.style || "normal"};font-weight:${t.weight || "normal"};}`;
|
|
154
181
|
}
|
|
155
|
-
|
|
182
|
+
for (const t of d) {
|
|
183
|
+
if (!t || typeof t != "object") continue;
|
|
184
|
+
const { family: n, src: e, weight: a = "normal", style: r = "normal" } = t;
|
|
185
|
+
if (!n || !e) continue;
|
|
186
|
+
let s = e;
|
|
187
|
+
if (s.startsWith("data:"))
|
|
188
|
+
o.resource.set(e, s), o.font.add(e);
|
|
189
|
+
else
|
|
190
|
+
try {
|
|
191
|
+
const R = await (await A(e, { useProxy: c })).blob();
|
|
192
|
+
s = await new Promise((S) => {
|
|
193
|
+
const u = new FileReader();
|
|
194
|
+
u.onload = () => S(u.result), u.readAsDataURL(R);
|
|
195
|
+
}), o.resource.set(e, s), o.font.add(e);
|
|
196
|
+
} catch {
|
|
197
|
+
console.warn("[snapdom] Failed to load local font:", e);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
m += `@font-face{font-family:'${n}';src:url(${s});font-style:${r};font-weight:${a};}`;
|
|
201
|
+
}
|
|
202
|
+
if (m && (o.resource.set("fonts-embed-css", m), h)) {
|
|
156
203
|
const t = document.createElement("style");
|
|
157
|
-
t.setAttribute("data-snapdom", "embedFonts"), t.textContent =
|
|
204
|
+
t.setAttribute("data-snapdom", "embedFonts"), t.textContent = m, document.head.appendChild(t);
|
|
158
205
|
}
|
|
159
|
-
return
|
|
206
|
+
return m;
|
|
160
207
|
}
|
|
161
208
|
export {
|
|
162
|
-
|
|
163
|
-
|
|
209
|
+
N as embedCustomFonts,
|
|
210
|
+
H as iconToImage
|
|
164
211
|
};
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import { fetchImage as
|
|
2
|
-
async function
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
import { fetchImage as a } from "../utils/helpers.js";
|
|
2
|
+
async function l(s, n = {}) {
|
|
3
|
+
const c = Array.from(s.querySelectorAll("img")), o = async (t) => {
|
|
4
|
+
if (!t.getAttribute("src")) {
|
|
5
|
+
const e = t.currentSrc || t.src || "";
|
|
6
|
+
e && t.setAttribute("src", e);
|
|
7
|
+
}
|
|
8
|
+
t.removeAttribute("srcset"), t.removeAttribute("sizes");
|
|
9
|
+
const r = t.src;
|
|
5
10
|
try {
|
|
6
|
-
const e = await
|
|
11
|
+
const e = await a(r, { useProxy: n.useProxy });
|
|
7
12
|
t.src = e, t.width || (t.width = t.naturalWidth || 100), t.height || (t.height = t.naturalHeight || 100);
|
|
8
13
|
} catch {
|
|
9
14
|
const e = document.createElement("div");
|
|
10
15
|
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
16
|
}
|
|
12
17
|
};
|
|
13
|
-
for (let t = 0; t <
|
|
14
|
-
const
|
|
15
|
-
await Promise.allSettled(
|
|
18
|
+
for (let t = 0; t < c.length; t += 4) {
|
|
19
|
+
const r = c.slice(t, t + 4).map(o);
|
|
20
|
+
await Promise.allSettled(r);
|
|
16
21
|
}
|
|
17
22
|
}
|
|
18
23
|
export {
|
|
19
|
-
|
|
24
|
+
l as inlineImages
|
|
20
25
|
};
|
|
@@ -1,78 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isIconFont as X } from "./iconFonts.js";
|
|
1
|
+
import { iconToImage as X } from "./fonts.js";
|
|
2
|
+
import { isIconFont as _ } from "./iconFonts.js";
|
|
4
3
|
import { getStyleKey as $ } from "../utils/cssTools.js";
|
|
5
|
-
import { getStyle as
|
|
6
|
-
async function
|
|
7
|
-
if (!(
|
|
8
|
-
for (const
|
|
4
|
+
import { getStyle as q, snapshotComputedStyle as U, parseContent as G, extractURL as J, fetchImage as Q, safeEncodeURI as Y, splitBackgroundImage as Z, inlineSingleBackgroundEntry as tt } from "../utils/helpers.js";
|
|
5
|
+
async function nt(a, r, g, z, d) {
|
|
6
|
+
if (!(a instanceof Element) || !(r instanceof Element)) return;
|
|
7
|
+
for (const n of ["::before", "::after", "::first-letter"])
|
|
9
8
|
try {
|
|
10
|
-
const t =
|
|
9
|
+
const t = q(a, n);
|
|
11
10
|
if (!t || typeof t[Symbol.iterator] != "function" || t.content === "none" && t.backgroundImage === "none" && t.backgroundColor === "transparent" && (t.borderStyle === "none" || parseFloat(t.borderWidth) === 0) && (!t.transform || t.transform === "none") && t.display === "inline") continue;
|
|
12
|
-
if (
|
|
13
|
-
const o = getComputedStyle(
|
|
11
|
+
if (n === "::first-letter") {
|
|
12
|
+
const o = getComputedStyle(a);
|
|
14
13
|
if (!(t.color !== o.color || t.fontSize !== o.fontSize || t.fontWeight !== o.fontWeight)) continue;
|
|
15
|
-
const
|
|
16
|
-
(
|
|
14
|
+
const i = Array.from(r.childNodes).find(
|
|
15
|
+
(T) => T.nodeType === Node.TEXT_NODE && T.textContent?.trim().length > 0
|
|
17
16
|
);
|
|
18
|
-
if (!
|
|
19
|
-
const l =
|
|
17
|
+
if (!i) continue;
|
|
18
|
+
const l = i.textContent, h = l.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0], K = l.slice(h?.length || 0);
|
|
20
19
|
if (!h || /[\uD800-\uDFFF]/.test(h)) continue;
|
|
21
20
|
const p = document.createElement("span");
|
|
22
21
|
p.textContent = h, p.dataset.snapdomPseudo = "::first-letter";
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
r.replaceChild(
|
|
22
|
+
const M = U(t), O = $(M, "span", d);
|
|
23
|
+
g.set(p, O);
|
|
24
|
+
const W = document.createTextNode(K);
|
|
25
|
+
r.replaceChild(W, i), r.insertBefore(p, W);
|
|
27
26
|
continue;
|
|
28
27
|
}
|
|
29
|
-
const
|
|
30
|
-
if (!(
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
const { dataUrl: o, width: s, height:
|
|
28
|
+
const u = t.content, c = /counter\s*\(|counters\s*\(/.test(u) ? "- " : G(u), y = t.backgroundImage, f = t.backgroundColor, S = t.fontFamily, m = parseInt(t.fontSize) || 32, A = parseInt(t.fontWeight) || !1, R = t.color || "#000", j = t.display, D = parseFloat(t.width), L = parseFloat(t.height), w = t.borderStyle, V = parseFloat(t.borderWidth), F = t.transform, I = _(S), k = u !== "none" && c !== "", b = y && y !== "none", C = f && f !== "transparent" && f !== "rgba(0, 0, 0, 0)", B = j !== "inline" && (D > 0 || L > 0), N = w && w !== "none" && V > 0, P = F && F !== "none";
|
|
29
|
+
if (!(k || b || C || B || N || P)) continue;
|
|
30
|
+
const e = document.createElement("span");
|
|
31
|
+
e.dataset.snapdomPseudo = n, e.style.verticalAlign = "middle";
|
|
32
|
+
const v = U(t), H = $(v, "span", d);
|
|
33
|
+
if (g.set(e, H), I && c.length === 1) {
|
|
34
|
+
const { dataUrl: o, width: s, height: i } = await X(
|
|
36
35
|
c,
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
S,
|
|
37
|
+
A,
|
|
39
38
|
m,
|
|
40
|
-
|
|
39
|
+
R
|
|
41
40
|
), l = document.createElement("img");
|
|
42
|
-
l.src = o, l.style = `height:${m}px;width:${s /
|
|
41
|
+
l.src = o, l.style = `height:${m}px;width:${s / i * m}px;object-fit:contain;`, e.appendChild(l), r.dataset.snapdomHasIcon = "true";
|
|
43
42
|
} else if (c.startsWith("url(")) {
|
|
44
|
-
const o =
|
|
43
|
+
const o = J(c);
|
|
45
44
|
if (o?.trim())
|
|
46
45
|
try {
|
|
47
|
-
const s = document.createElement("img"),
|
|
48
|
-
s.src =
|
|
46
|
+
const s = document.createElement("img"), i = await Q(Y(o), d);
|
|
47
|
+
s.src = i, s.style = `width:${m}px;height:auto;object-fit:contain;`, e.appendChild(s);
|
|
49
48
|
} catch (s) {
|
|
50
|
-
console.error(`[snapdom] Error in pseudo ${
|
|
49
|
+
console.error(`[snapdom] Error in pseudo ${n} for`, a, s);
|
|
51
50
|
}
|
|
52
|
-
} else !
|
|
53
|
-
if (
|
|
51
|
+
} else !I && k && (e.textContent = c);
|
|
52
|
+
if (b)
|
|
54
53
|
try {
|
|
55
|
-
const o =
|
|
56
|
-
o.map(
|
|
54
|
+
const o = Z(y), s = await Promise.all(
|
|
55
|
+
o.map(tt)
|
|
57
56
|
);
|
|
58
|
-
|
|
57
|
+
e.style.backgroundImage = s.join(", ");
|
|
59
58
|
} catch (o) {
|
|
60
59
|
console.warn(
|
|
61
|
-
`[snapdom] Failed to inline background-image for ${
|
|
60
|
+
`[snapdom] Failed to inline background-image for ${n}`,
|
|
62
61
|
o
|
|
63
62
|
);
|
|
64
63
|
}
|
|
65
|
-
if (
|
|
66
|
-
|
|
64
|
+
if (C && (e.style.backgroundColor = f), !(e.childNodes.length > 0 || e.textContent?.trim() !== "" || b || C || B || N || P)) continue;
|
|
65
|
+
n === "::before" ? r.insertBefore(e, r.firstChild) : r.appendChild(e);
|
|
67
66
|
} catch (t) {
|
|
68
|
-
console.warn(`[snapdom] Failed to capture ${
|
|
67
|
+
console.warn(`[snapdom] Failed to capture ${n} for`, a, t);
|
|
69
68
|
}
|
|
70
|
-
const
|
|
71
|
-
(
|
|
69
|
+
const E = Array.from(a.children), x = Array.from(r.children).filter(
|
|
70
|
+
(n) => !n.dataset.snapdomPseudo
|
|
72
71
|
);
|
|
73
|
-
for (let
|
|
74
|
-
await
|
|
72
|
+
for (let n = 0; n < Math.min(E.length, x.length); n++)
|
|
73
|
+
await nt(
|
|
74
|
+
E[n],
|
|
75
|
+
x[n],
|
|
76
|
+
g,
|
|
77
|
+
z,
|
|
78
|
+
d
|
|
79
|
+
);
|
|
75
80
|
}
|
|
76
81
|
export {
|
|
77
|
-
|
|
82
|
+
nt as inlinePseudoElements
|
|
78
83
|
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
for (let
|
|
7
|
-
const
|
|
8
|
-
let
|
|
9
|
-
(
|
|
1
|
+
import { getStyleKey as c } from "../utils/cssTools.js";
|
|
2
|
+
import { getStyle as d } from "../utils/helpers.js";
|
|
3
|
+
const r = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new Map();
|
|
4
|
+
function y(t) {
|
|
5
|
+
const n = {}, s = t.getPropertyValue("visibility");
|
|
6
|
+
for (let e = 0; e < t.length; e++) {
|
|
7
|
+
const o = t[e];
|
|
8
|
+
let a = t.getPropertyValue(o);
|
|
9
|
+
(o === "background-image" || o === "content") && a.includes("url(") && !a.includes("data:") && (a = "none"), n[o] = a;
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return s === "hidden" && (n.opacity = "0"), n;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function S(t, n, s, e, o) {
|
|
14
14
|
if (t.tagName === "STYLE") return;
|
|
15
|
-
e.
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
18
|
-
const
|
|
19
|
-
|
|
15
|
+
e.has(t) || e.set(t, d(t));
|
|
16
|
+
const a = e.get(t);
|
|
17
|
+
if (!r.has(t)) {
|
|
18
|
+
const i = y(a);
|
|
19
|
+
r.set(t, i);
|
|
20
20
|
}
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
-
|
|
21
|
+
const h = r.get(t), l = Object.entries(h).sort(([i], [p]) => i.localeCompare(p)).map(([i, p]) => `${i}:${p}`).join(";");
|
|
22
|
+
if (g.has(l)) {
|
|
23
|
+
s.set(n, g.get(l));
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
26
|
+
const f = t.tagName?.toLowerCase() || "div", m = c(h, f, o);
|
|
27
|
+
g.set(l, m), s.set(n, m);
|
|
28
28
|
}
|
|
29
29
|
export {
|
|
30
|
-
|
|
30
|
+
S as inlineAllStyles
|
|
31
31
|
};
|
|
@@ -1,26 +1,45 @@
|
|
|
1
|
-
function
|
|
1
|
+
function u(s) {
|
|
2
2
|
if (!s) return;
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
const o = /* @__PURE__ */ new Set();
|
|
4
|
+
if (s.querySelectorAll("use").forEach((e) => {
|
|
5
|
+
const r = e.getAttribute("xlink:href") || e.getAttribute("href");
|
|
6
|
+
r && r.startsWith("#") && o.add(r.slice(1));
|
|
7
|
+
}), !o.size) return;
|
|
8
|
+
const d = Array.from(
|
|
9
|
+
document.querySelectorAll("svg > symbol, svg > defs")
|
|
10
|
+
), f = d.filter(
|
|
11
|
+
(e) => e.tagName.toLowerCase() === "symbol"
|
|
12
|
+
), c = d.filter(
|
|
13
|
+
(e) => e.tagName.toLowerCase() === "defs"
|
|
14
|
+
);
|
|
15
|
+
let t = s.querySelector("svg.inline-defs-container");
|
|
16
|
+
t || (t = document.createElementNS("http://www.w3.org/2000/svg", "svg"), t.setAttribute("aria-hidden", "true"), t.setAttribute(
|
|
17
|
+
"style",
|
|
18
|
+
"position: absolute; width: 0; height: 0; overflow: hidden;"
|
|
19
|
+
), t.classList.add("inline-defs-container"), s.insertBefore(t, s.firstChild));
|
|
20
|
+
const i = /* @__PURE__ */ new Set();
|
|
21
|
+
s.querySelectorAll("symbol[id], defs > *[id]").forEach((e) => {
|
|
22
|
+
i.add(e.id);
|
|
23
|
+
}), o.forEach((e) => {
|
|
24
|
+
if (i.has(e)) return;
|
|
25
|
+
const r = f.find((l) => l.id === e);
|
|
26
|
+
if (r) {
|
|
27
|
+
t.appendChild(r.cloneNode(!0)), i.add(e);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
for (const l of c) {
|
|
31
|
+
const a = l.querySelector(`#${CSS.escape(e)}`);
|
|
32
|
+
if (a) {
|
|
33
|
+
let n = t.querySelector("defs");
|
|
34
|
+
n || (n = document.createElementNS(
|
|
35
|
+
"http://www.w3.org/2000/svg",
|
|
36
|
+
"defs"
|
|
37
|
+
), t.appendChild(n)), n.appendChild(a.cloneNode(!0)), i.add(e);
|
|
38
|
+
break;
|
|
20
39
|
}
|
|
21
|
-
|
|
40
|
+
}
|
|
22
41
|
});
|
|
23
42
|
}
|
|
24
43
|
export {
|
|
25
|
-
|
|
44
|
+
u as inlineExternalDefsAndSymbols
|
|
26
45
|
};
|