@unicom-cloud/utils 0.1.3 → 0.1.5
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 -6
- package/constant/keyboardCode.js +41 -40
- package/constant/platform.js +14 -16
- package/cookie/src/index.js +46 -46
- package/dayjs/index.js +15 -0
- package/decimal/decimal.js +56 -56
- package/event-emitter/index.js +14 -23
- package/file/fileToURL.js +8 -9
- package/file/saveAs.js +1 -1
- package/mock/MockWebSocket.js +67 -90
- package/mock/MockXMLHttpRequest.js +51 -61
- package/package.json +1 -1
- package/random/address.js +10 -10
- package/screenfull/index.js +43 -43
- package/snapdom/src/api/preCache.js +34 -24
- package/snapdom/src/api/snapdom.js +56 -56
- package/snapdom/src/core/cache.js +3 -2
- package/snapdom/src/core/capture.js +32 -32
- package/snapdom/src/core/clone.js +39 -38
- package/snapdom/src/core/prepare.js +10 -11
- package/snapdom/src/modules/background.js +45 -22
- package/snapdom/src/modules/fonts.js +148 -45
- package/snapdom/src/modules/images.js +7 -7
- package/snapdom/src/modules/pseudo.js +75 -45
- package/snapdom/src/modules/styles.js +7 -8
- package/snapdom/src/utils/helpers.js +56 -53
- package/tree/index.js +31 -32
- package/turbo-stream/src/encode.js +149 -152
- package/turbo-stream/src/shared.js +155 -173
|
@@ -1,63 +1,166 @@
|
|
|
1
|
-
import { resourceCache as
|
|
2
|
-
import { isIconFont as
|
|
3
|
-
async function
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
return
|
|
1
|
+
import { resourceCache as c, processedFontURLs as h } from "../core/cache.js";
|
|
2
|
+
import { isIconFont as b, extractURL as $ } from "../utils/helpers.js";
|
|
3
|
+
async function _(f, a, l, p = 32, g = "#000") {
|
|
4
|
+
a = a.replace(/^['"]+|['"]+$/g, "");
|
|
5
|
+
const i = window.devicePixelRatio || 1, n = document.createElement("canvas").getContext("2d");
|
|
6
|
+
n.font = l ? `${l} ${p}px "${a}"` : `${p}px "${a}"`;
|
|
7
|
+
const o = n.measureText(f), m = o.actualBoundingBoxAscent || p * 0.8, s = o.actualBoundingBoxDescent || p * 0.2, d = m + s, r = o.width, u = document.createElement("canvas");
|
|
8
|
+
u.width = Math.ceil(r * i), u.height = Math.ceil(d * i);
|
|
9
|
+
const e = u.getContext("2d");
|
|
10
|
+
return e.scale(i, i), e.font = n.font, e.textAlign = "left", e.textBaseline = "alphabetic", e.fillStyle = g, e.fillText(f, 0, m), u.toDataURL();
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
function A(f) {
|
|
13
|
+
return Array.from(document.styleSheets).some((a) => a.href === f);
|
|
14
|
+
}
|
|
15
|
+
function C(f) {
|
|
16
|
+
return new Promise((a) => {
|
|
17
|
+
if (A(f)) return a(null);
|
|
18
|
+
const l = document.createElement("link");
|
|
19
|
+
l.rel = "stylesheet", l.href = f, l.setAttribute("data-snapdom", "injected-import"), l.onload = () => a(l), l.onerror = () => a(null), document.head.appendChild(l);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async function P({
|
|
23
|
+
ignoreIconFonts: f = !0,
|
|
24
|
+
preCached: a = !1
|
|
25
|
+
} = {}) {
|
|
26
|
+
if (c.has("fonts-embed-css")) {
|
|
27
|
+
if (a) {
|
|
28
|
+
const t = document.createElement("style");
|
|
29
|
+
t.setAttribute("data-snapdom", "embedFonts"), t.textContent = c.get("fonts-embed-css"), document.head.appendChild(t);
|
|
30
|
+
}
|
|
31
|
+
return c.get("fonts-embed-css");
|
|
32
|
+
}
|
|
33
|
+
const l = /@import\s+url\(["']?([^"')]+)["']?\)/g, p = [];
|
|
34
|
+
for (const t of document.querySelectorAll("style")) {
|
|
35
|
+
const n = t.textContent || "", o = Array.from(n.matchAll(l));
|
|
36
|
+
for (const m of o) {
|
|
37
|
+
const s = m[1];
|
|
38
|
+
A(s) || p.push(s);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
await Promise.all(p.map(C));
|
|
42
|
+
const g = Array.from(
|
|
17
43
|
document.querySelectorAll('link[rel="stylesheet"]')
|
|
18
|
-
).filter((
|
|
19
|
-
let
|
|
20
|
-
for (const
|
|
44
|
+
).filter((t) => t.href);
|
|
45
|
+
let i = "";
|
|
46
|
+
for (const t of g)
|
|
21
47
|
try {
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
48
|
+
const o = await (await fetch(t.href)).text();
|
|
49
|
+
if (f && (b(t.href) || b(o)))
|
|
24
50
|
continue;
|
|
25
|
-
const
|
|
26
|
-
Array.from(
|
|
27
|
-
let
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
51
|
+
const m = /url\((["']?)([^"')]+)\1\)/g, s = await Promise.all(
|
|
52
|
+
Array.from(o.matchAll(m)).map(async (r) => {
|
|
53
|
+
let u = $(r[0]);
|
|
54
|
+
if (!u) return null;
|
|
55
|
+
let e = u;
|
|
56
|
+
if (!e.startsWith("http") && !e.startsWith("data:") && (e = new URL(e, t.href).href), f && b(e)) return null;
|
|
57
|
+
if (c.has(e))
|
|
58
|
+
return h.add(e), {
|
|
59
|
+
original: r[0],
|
|
60
|
+
inlined: `url(${c.get(e)})`
|
|
34
61
|
};
|
|
62
|
+
if (h.has(e)) return null;
|
|
35
63
|
try {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
64
|
+
const S = await (await fetch(e)).blob(), w = await new Promise((R) => {
|
|
65
|
+
const y = new FileReader();
|
|
66
|
+
y.onload = () => R(y.result), y.readAsDataURL(S);
|
|
39
67
|
});
|
|
40
|
-
return
|
|
68
|
+
return c.set(e, w), h.add(e), { original: r[0], inlined: `url(${w})` };
|
|
41
69
|
} catch {
|
|
42
|
-
return console.warn("
|
|
70
|
+
return console.warn("[snapdom] Failed to fetch font resource:", e), null;
|
|
43
71
|
}
|
|
44
72
|
})
|
|
45
73
|
);
|
|
46
|
-
let
|
|
47
|
-
for (const
|
|
48
|
-
|
|
49
|
-
|
|
74
|
+
let d = o;
|
|
75
|
+
for (const r of s)
|
|
76
|
+
r && (d = d.replace(r.original, r.inlined));
|
|
77
|
+
i += d + `
|
|
50
78
|
`;
|
|
51
79
|
} catch {
|
|
52
|
-
console.warn("
|
|
80
|
+
console.warn("[snapdom] Failed to fetch CSS:", t.href);
|
|
81
|
+
}
|
|
82
|
+
for (const t of document.styleSheets)
|
|
83
|
+
try {
|
|
84
|
+
if (!t.href || g.every((n) => n.href !== t.href)) {
|
|
85
|
+
for (const n of t.cssRules)
|
|
86
|
+
if (n.type === CSSRule.FONT_FACE_RULE) {
|
|
87
|
+
const o = n.style.getPropertyValue("src");
|
|
88
|
+
if (!o) continue;
|
|
89
|
+
const m = /url\((["']?)([^"')]+)\1\)/g;
|
|
90
|
+
let s = o;
|
|
91
|
+
const d = Array.from(o.matchAll(m));
|
|
92
|
+
for (const r of d) {
|
|
93
|
+
let u = r[2].trim();
|
|
94
|
+
if (!u) continue;
|
|
95
|
+
let e = u;
|
|
96
|
+
if (!e.startsWith("http") && !e.startsWith("data:") && (e = new URL(e, t.href || location.href).href), !(f && b(e))) {
|
|
97
|
+
if (c.has(e)) {
|
|
98
|
+
h.add(e), s = s.replace(
|
|
99
|
+
r[0],
|
|
100
|
+
`url(${c.get(e)})`
|
|
101
|
+
);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (!h.has(e))
|
|
105
|
+
try {
|
|
106
|
+
const S = await (await fetch(e)).blob(), w = await new Promise((R) => {
|
|
107
|
+
const y = new FileReader();
|
|
108
|
+
y.onload = () => R(y.result), y.readAsDataURL(S);
|
|
109
|
+
});
|
|
110
|
+
c.set(e, w), h.add(e), s = s.replace(r[0], `url(${w})`);
|
|
111
|
+
} catch {
|
|
112
|
+
console.warn("[snapdom] Failed to fetch font URL:", e);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
i += `@font-face {
|
|
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
|
+
`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} catch (n) {
|
|
126
|
+
console.warn("[snapdom] Cannot access stylesheet", t.href, n);
|
|
127
|
+
}
|
|
128
|
+
for (const t of document.fonts)
|
|
129
|
+
if (t.family && t.status === "loaded" && t._snapdomSrc) {
|
|
130
|
+
let n = t._snapdomSrc;
|
|
131
|
+
if (!n.startsWith("data:")) {
|
|
132
|
+
if (c.has(t._snapdomSrc))
|
|
133
|
+
n = c.get(t._snapdomSrc), h.add(t._snapdomSrc);
|
|
134
|
+
else if (!h.has(t._snapdomSrc))
|
|
135
|
+
try {
|
|
136
|
+
const m = await (await fetch(t._snapdomSrc)).blob();
|
|
137
|
+
n = await new Promise((s) => {
|
|
138
|
+
const d = new FileReader();
|
|
139
|
+
d.onload = () => s(d.result), d.readAsDataURL(m);
|
|
140
|
+
}), c.set(t._snapdomSrc, n), h.add(t._snapdomSrc);
|
|
141
|
+
} catch {
|
|
142
|
+
console.warn(
|
|
143
|
+
"[snapdom] Failed to fetch dynamic font src:",
|
|
144
|
+
t._snapdomSrc
|
|
145
|
+
);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
i += `@font-face {
|
|
150
|
+
font-family: '${t.family}';
|
|
151
|
+
src: url(${n});
|
|
152
|
+
font-style: ${t.style || "normal"};
|
|
153
|
+
font-weight: ${t.weight || "normal"};
|
|
154
|
+
}
|
|
155
|
+
`;
|
|
53
156
|
}
|
|
54
|
-
if (
|
|
55
|
-
const
|
|
56
|
-
|
|
157
|
+
if (i && (c.set("fonts-embed-css", i), a)) {
|
|
158
|
+
const t = document.createElement("style");
|
|
159
|
+
t.setAttribute("data-snapdom", "embedFonts"), t.textContent = i, document.head.appendChild(t);
|
|
57
160
|
}
|
|
58
|
-
return
|
|
161
|
+
return i;
|
|
59
162
|
}
|
|
60
163
|
export {
|
|
61
|
-
|
|
62
|
-
|
|
164
|
+
P as embedCustomFonts,
|
|
165
|
+
_ as iconToImage
|
|
63
166
|
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { fetchImage as
|
|
2
|
-
async function h(
|
|
3
|
-
const
|
|
1
|
+
import { fetchImage as o } from "../utils/helpers.js";
|
|
2
|
+
async function h(i, n = {}) {
|
|
3
|
+
const r = Array.from(i.querySelectorAll("img")), s = async (t) => {
|
|
4
4
|
const c = t.src;
|
|
5
5
|
try {
|
|
6
|
-
const e = await
|
|
7
|
-
t.src =
|
|
6
|
+
const e = n.crossOrigin ? n.crossOrigin(c) : "anonymous", a = await o(c, 3e3, e);
|
|
7
|
+
t.src = a, 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
|
-
for (let t = 0; t <
|
|
14
|
-
const c =
|
|
13
|
+
for (let t = 0; t < r.length; t += 4) {
|
|
14
|
+
const c = r.slice(t, t + 4).map(s);
|
|
15
15
|
await Promise.allSettled(c);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -1,63 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
async function
|
|
5
|
-
if (!(
|
|
6
|
-
for (const
|
|
1
|
+
import { iconToImage as $ } from "./fonts.js";
|
|
2
|
+
import { getStyleKey as I } from "../utils/cssTools.js";
|
|
3
|
+
import { getStyle as A, snapshotComputedStyle as U, parseContent as D, extractURL as B, fetchImage as S } from "../utils/helpers.js";
|
|
4
|
+
async function L(l, r, p, F, g, b = !1) {
|
|
5
|
+
if (!(l instanceof Element) || !(r instanceof Element)) return;
|
|
6
|
+
for (const n of ["::before", "::after", "::first-letter"])
|
|
7
7
|
try {
|
|
8
|
-
const e =
|
|
8
|
+
const e = A(l, n);
|
|
9
9
|
if (!e) continue;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
f.set(o, V);
|
|
16
|
-
const I = l && /font.*awesome|material|bootstrap|glyphicons|ionicons|remixicon|simple-line-icons|octicons|feather|typicons|weathericons/i.test(
|
|
17
|
-
l
|
|
10
|
+
if (n === "::first-letter") {
|
|
11
|
+
const a = getComputedStyle(l);
|
|
12
|
+
if (!(e.color !== a.color || e.fontSize !== a.fontSize || e.fontWeight !== a.fontWeight)) continue;
|
|
13
|
+
const h = Array.from(r.childNodes).find(
|
|
14
|
+
(t) => t.nodeType === Node.TEXT_NODE && t.textContent && t.textContent.trim().length > 0
|
|
18
15
|
);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
if (!h) continue;
|
|
17
|
+
const m = h.textContent, f = m.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0], y = m.slice(f?.length || 0);
|
|
18
|
+
if (!f || /[\uD800-\uDFFF]/.test(f)) continue;
|
|
19
|
+
const c = document.createElement("span");
|
|
20
|
+
c.textContent = f, c.dataset.snapdomPseudo = "::first-letter";
|
|
21
|
+
const i = U(e), k = I(i, "span", g);
|
|
22
|
+
p.set(c, k);
|
|
23
|
+
const C = document.createTextNode(y);
|
|
24
|
+
r.replaceChild(C, h), r.insertBefore(c, C);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const E = e.getPropertyValue("content"), d = e.getPropertyValue("background-image"), u = e.getPropertyValue("background-color"), W = E !== "none", P = d && d !== "none", N = u && u !== "transparent" && u !== "rgba(0, 0, 0, 0)", T = typeof d == "string" && d.trim().startsWith("url(");
|
|
28
|
+
if (W || P || N) {
|
|
29
|
+
const a = e.getPropertyValue("font-family"), V = parseInt(e.getPropertyValue("font-size")) || 32, h = parseInt(e.getPropertyValue("font-weight")) || !1, m = e.getPropertyValue("color") || "#000", o = document.createElement("span");
|
|
30
|
+
o.dataset.snapdomPseudo = n;
|
|
31
|
+
const f = U(e), y = I(f, "span", g);
|
|
32
|
+
p.set(o, y);
|
|
33
|
+
const c = a && /font.*awesome|material|bootstrap|glyphicons|ionicons|remixicon|simple-line-icons|octicons|feather|typicons|weathericons|lucide/i.test(
|
|
34
|
+
a
|
|
35
|
+
), i = D(E);
|
|
36
|
+
if (!b && c && i.length === 1) {
|
|
37
|
+
const t = document.createElement("img");
|
|
38
|
+
t.src = await $(
|
|
23
39
|
i,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
),
|
|
40
|
+
a,
|
|
41
|
+
h,
|
|
42
|
+
V,
|
|
43
|
+
m
|
|
44
|
+
), t.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(t);
|
|
29
45
|
} else if (i.startsWith("url(")) {
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
46
|
+
const t = B(i);
|
|
47
|
+
if (t && t.trim() !== "")
|
|
32
48
|
try {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
} catch (
|
|
49
|
+
const s = document.createElement("img"), z = await S(encodeURI(t));
|
|
50
|
+
s.src = z, s.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(s);
|
|
51
|
+
} catch (s) {
|
|
36
52
|
console.error(
|
|
37
|
-
`[snapdom] Error in pseudo ${
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
`[snapdom] Error in pseudo ${n} for`,
|
|
54
|
+
l,
|
|
55
|
+
s
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
} else !c && i && i !== "none" && (o.textContent = i);
|
|
59
|
+
if (T) {
|
|
60
|
+
const t = B(d);
|
|
61
|
+
if (t && t.trim() !== "")
|
|
62
|
+
try {
|
|
63
|
+
let s;
|
|
64
|
+
t.startsWith("data:") ? s = t : s = await S(encodeURI(t)), o.style.backgroundImage = `url(${s})`;
|
|
65
|
+
} catch (s) {
|
|
66
|
+
console.warn(
|
|
67
|
+
`[snapdom] Failed to inline background-image for ${n}`,
|
|
68
|
+
s
|
|
40
69
|
);
|
|
41
70
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
71
|
+
}
|
|
72
|
+
if (!(o.childNodes.length > 0 || o.textContent && o.textContent.trim() !== "" || P || N)) continue;
|
|
73
|
+
n === "::before" ? r.insertBefore(o, r.firstChild) : r.appendChild(o);
|
|
44
74
|
}
|
|
45
75
|
} catch (e) {
|
|
46
|
-
console.warn(`[snapdom] Failed to capture ${
|
|
76
|
+
console.warn(`[snapdom] Failed to capture ${n} for`, l, e);
|
|
47
77
|
}
|
|
48
|
-
const
|
|
49
|
-
(
|
|
78
|
+
const x = Array.from(l.children), w = Array.from(r.children).filter(
|
|
79
|
+
(n) => !n.dataset.snapdomPseudo
|
|
50
80
|
);
|
|
51
|
-
for (let
|
|
52
|
-
await
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
f,
|
|
56
|
-
y,
|
|
81
|
+
for (let n = 0; n < Math.min(x.length, w.length); n++)
|
|
82
|
+
await L(
|
|
83
|
+
x[n],
|
|
84
|
+
w[n],
|
|
57
85
|
p,
|
|
58
|
-
|
|
86
|
+
F,
|
|
87
|
+
g,
|
|
88
|
+
b
|
|
59
89
|
);
|
|
60
90
|
}
|
|
61
91
|
export {
|
|
62
|
-
|
|
92
|
+
L as inlinePseudoElements
|
|
63
93
|
};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { getStyleKey as
|
|
2
|
-
import { getStyle as
|
|
3
|
-
function
|
|
4
|
-
var n;
|
|
1
|
+
import { getStyleKey as y } from "../utils/cssTools.js";
|
|
2
|
+
import { getStyle as g, snapshotComputedStyle as p } from "../utils/helpers.js";
|
|
3
|
+
function r(t, n, o, e, s) {
|
|
5
4
|
if (t.tagName === "STYLE") return;
|
|
6
|
-
e.has(t) || e.set(t,
|
|
7
|
-
const
|
|
8
|
-
|
|
5
|
+
e.has(t) || e.set(t, g(t));
|
|
6
|
+
const a = e.get(t), i = p(a), l = t.tagName?.toLowerCase() || "div", m = y(i, l, s);
|
|
7
|
+
o.set(n, m);
|
|
9
8
|
}
|
|
10
9
|
export {
|
|
11
|
-
|
|
10
|
+
r as inlineAllStyles
|
|
12
11
|
};
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import { imageCache as
|
|
2
|
-
function
|
|
3
|
-
if (
|
|
1
|
+
import { imageCache as c, computedStyleCache as l } from "../core/cache.js";
|
|
2
|
+
function h(t, { fast: n = !1 } = {}) {
|
|
3
|
+
if (n) return t();
|
|
4
4
|
"requestIdleCallback" in window ? requestIdleCallback(t, { timeout: 50 }) : setTimeout(t, 1);
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function f(t, n = null) {
|
|
7
7
|
if (!(t instanceof Element))
|
|
8
|
-
return window.getComputedStyle(t,
|
|
9
|
-
let
|
|
10
|
-
if (
|
|
11
|
-
const
|
|
12
|
-
|
|
8
|
+
return window.getComputedStyle(t, n);
|
|
9
|
+
let e = l.get(t);
|
|
10
|
+
if (e || (e = /* @__PURE__ */ new Map(), l.set(t, e)), !e.has(n)) {
|
|
11
|
+
const a = window.getComputedStyle(t, n);
|
|
12
|
+
e.set(n, a);
|
|
13
13
|
}
|
|
14
|
-
return
|
|
14
|
+
return e.get(n);
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
let
|
|
18
|
-
if (
|
|
16
|
+
function g(t) {
|
|
17
|
+
let n = t.replace(/^['"]|['"]$/g, "");
|
|
18
|
+
if (n.startsWith("\\"))
|
|
19
19
|
try {
|
|
20
|
-
return String.fromCharCode(parseInt(
|
|
20
|
+
return String.fromCharCode(parseInt(n.replace("\\", ""), 16));
|
|
21
21
|
} catch {
|
|
22
|
-
return
|
|
22
|
+
return n;
|
|
23
23
|
}
|
|
24
|
-
return
|
|
24
|
+
return n;
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
const
|
|
28
|
-
|
|
26
|
+
function w(t) {
|
|
27
|
+
const n = t.indexOf("url(");
|
|
28
|
+
if (n === -1) return null;
|
|
29
|
+
let e = t.slice(n + 4).trim();
|
|
30
|
+
return e.endsWith(")") && (e = e.slice(0, -1).trim()), (e.startsWith('"') && e.endsWith('"') || e.startsWith("'") && e.endsWith("'")) && (e = e.slice(1, -1)), e;
|
|
29
31
|
}
|
|
30
32
|
function p(t) {
|
|
31
33
|
return [
|
|
@@ -36,52 +38,53 @@ function p(t) {
|
|
|
36
38
|
/feather/i,
|
|
37
39
|
/bootstrap\s*icons/i,
|
|
38
40
|
/remix\s*icons/i,
|
|
39
|
-
/heroicons/i
|
|
40
|
-
|
|
41
|
+
/heroicons/i,
|
|
42
|
+
/lucide/i
|
|
43
|
+
].some((e) => e.test(t));
|
|
41
44
|
}
|
|
42
|
-
function
|
|
43
|
-
return
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
clearTimeout(
|
|
45
|
+
function C(t, n = 3e3, e = "anonymous") {
|
|
46
|
+
return c.has(t) ? Promise.resolve(c.get(t)) : new Promise((a, o) => {
|
|
47
|
+
const u = setTimeout(() => {
|
|
48
|
+
o(new Error("Image load timed out"));
|
|
49
|
+
}, n), r = new Image();
|
|
50
|
+
r.crossOrigin = e, r.onload = async () => {
|
|
51
|
+
clearTimeout(u);
|
|
49
52
|
try {
|
|
50
|
-
await
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
+
await r.decode();
|
|
54
|
+
const i = document.createElement("canvas");
|
|
55
|
+
i.width = r.width, i.height = r.height, i.getContext("2d").drawImage(r, 0, 0, i.width, i.height);
|
|
53
56
|
try {
|
|
54
|
-
const
|
|
55
|
-
|
|
57
|
+
const s = i.toDataURL("image/png");
|
|
58
|
+
c.set(t, s), a(s);
|
|
56
59
|
} catch {
|
|
57
|
-
|
|
60
|
+
o(new Error("CORS restrictions prevented image capture"));
|
|
58
61
|
}
|
|
59
|
-
} catch (
|
|
60
|
-
i
|
|
62
|
+
} catch (i) {
|
|
63
|
+
o(i);
|
|
61
64
|
}
|
|
62
|
-
},
|
|
63
|
-
clearTimeout(
|
|
64
|
-
new Error("Failed to load image: " + (
|
|
65
|
+
}, r.onerror = (i) => {
|
|
66
|
+
clearTimeout(u), o(
|
|
67
|
+
new Error("Failed to load image: " + (i.message || "Unknown error"))
|
|
65
68
|
);
|
|
66
|
-
},
|
|
69
|
+
}, r.src = t;
|
|
67
70
|
});
|
|
68
71
|
}
|
|
69
|
-
function
|
|
70
|
-
const
|
|
71
|
-
for (let
|
|
72
|
-
e
|
|
73
|
-
return
|
|
72
|
+
function y(t) {
|
|
73
|
+
const n = {};
|
|
74
|
+
for (let e of t)
|
|
75
|
+
n[e] = t.getPropertyValue(e);
|
|
76
|
+
return n;
|
|
74
77
|
}
|
|
75
|
-
function
|
|
78
|
+
function I() {
|
|
76
79
|
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
77
80
|
}
|
|
78
81
|
export {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
w as extractURL,
|
|
83
|
+
C as fetchImage,
|
|
84
|
+
f as getStyle,
|
|
85
|
+
h as idle,
|
|
83
86
|
p as isIconFont,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
I as isSafari,
|
|
88
|
+
g as parseContent,
|
|
89
|
+
y as snapshotComputedStyle
|
|
87
90
|
};
|
package/tree/index.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
function a(e,
|
|
1
|
+
function a(e, r, f, l = "children") {
|
|
2
2
|
if (Array.isArray(e) && (e = {
|
|
3
3
|
[l]: e
|
|
4
4
|
}), !(e && typeof e == "object")) return null;
|
|
5
|
-
if (
|
|
5
|
+
if (r in e && e[r] === f)
|
|
6
6
|
return e;
|
|
7
|
-
const
|
|
8
|
-
if (Array.isArray(
|
|
9
|
-
for (let i of
|
|
10
|
-
const n = a(i,
|
|
7
|
+
const t = e[l] ?? e.items ?? e.list;
|
|
8
|
+
if (Array.isArray(t))
|
|
9
|
+
for (let i of t) {
|
|
10
|
+
const n = a(i, r, f, l);
|
|
11
11
|
if (n)
|
|
12
12
|
return n;
|
|
13
13
|
}
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
|
-
function y(e,
|
|
16
|
+
function y(e, r, f, l = "children") {
|
|
17
17
|
if (!e) return;
|
|
18
|
-
let
|
|
19
|
-
e: for (;
|
|
20
|
-
let i =
|
|
18
|
+
let t = Array.isArray(e) ? [...e] : [e];
|
|
19
|
+
e: for (; t.length; ) {
|
|
20
|
+
let i = t.shift();
|
|
21
21
|
if (!i) continue e;
|
|
22
22
|
if (!Array.isArray(i)) {
|
|
23
|
-
if (i[
|
|
23
|
+
if (i[r] === f)
|
|
24
24
|
return i;
|
|
25
25
|
let n = i[l] ?? i.items ?? i.list;
|
|
26
26
|
if (n === void 0)
|
|
27
27
|
continue e;
|
|
28
28
|
i = n;
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
t = t.concat(i);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
const d = a;
|
|
34
|
-
function A(e,
|
|
34
|
+
function A(e, r, f, l = "children") {
|
|
35
35
|
if (!e) return;
|
|
36
|
-
const
|
|
37
|
-
e: for (;
|
|
38
|
-
let i =
|
|
36
|
+
const t = Array.isArray(e) ? [...e] : [e];
|
|
37
|
+
e: for (; t.length; ) {
|
|
38
|
+
let i = t.pop();
|
|
39
39
|
if (!i) continue e;
|
|
40
40
|
if (!Array.isArray(i)) {
|
|
41
|
-
if (i[
|
|
41
|
+
if (i[r] === f)
|
|
42
42
|
return i;
|
|
43
43
|
let n = i[l] ?? i.items ?? i.list;
|
|
44
44
|
if (n === void 0)
|
|
@@ -47,33 +47,32 @@ function A(e, t, f, l = "children") {
|
|
|
47
47
|
}
|
|
48
48
|
if (Array.isArray(i))
|
|
49
49
|
for (let n = 0, u = i.length; n < u; n++)
|
|
50
|
-
|
|
50
|
+
t.push(i[u - 1 - n]);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
function h(e,
|
|
54
|
-
return y(e, "id",
|
|
53
|
+
function h(e, r) {
|
|
54
|
+
return y(e, "id", r);
|
|
55
55
|
}
|
|
56
|
-
function g(e,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return !l && f && (l = t), l;
|
|
56
|
+
function g(e, r, f = !0) {
|
|
57
|
+
let l = y(e, "value", r)?.label;
|
|
58
|
+
return !l && f && (l = r), l;
|
|
60
59
|
}
|
|
61
|
-
function m(e,
|
|
60
|
+
function m(e, r, f, l = "children") {
|
|
62
61
|
if (!e) return;
|
|
63
|
-
let
|
|
62
|
+
let t = null;
|
|
64
63
|
function i(n) {
|
|
65
64
|
if (!n) return;
|
|
66
65
|
let u = Array.isArray(n) ? n : n[l] ?? n.items ?? n.list ?? [];
|
|
67
|
-
for (let
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
|
|
66
|
+
for (let s = 0; s < u.length; s++) {
|
|
67
|
+
const c = u[s];
|
|
68
|
+
if (c?.[r] === f) {
|
|
69
|
+
t = { item: c, parent: n, index: s };
|
|
71
70
|
return;
|
|
72
71
|
}
|
|
73
|
-
i(
|
|
72
|
+
i(c);
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
|
-
return i(e),
|
|
75
|
+
return i(e), t;
|
|
77
76
|
}
|
|
78
77
|
export {
|
|
79
78
|
y as default,
|