@unicom-cloud/utils 0.1.4 → 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.
@@ -1,63 +1,166 @@
1
- import { resourceCache as x } from "../core/cache.js";
2
- import { isIconFont as w } from "../utils/helpers.js";
3
- async function y(i, r, u, n = 32, e = "#000") {
4
- r = r.replace(/^['"]+|['"]+$/g, "");
5
- const c = window.devicePixelRatio || 1, d = document.createElement("canvas").getContext("2d");
6
- d.font = u ? `${u} ${n}px "${r}"` : `${n}px "${r}"`;
7
- const f = d.measureText(i), s = f.actualBoundingBoxAscent || n * 0.8, a = f.actualBoundingBoxDescent || n * 0.2, t = s + a, m = f.width, l = document.createElement("canvas");
8
- l.width = Math.ceil(m * c), l.height = Math.ceil(t * c);
9
- const o = l.getContext("2d");
10
- return o.scale(c, c), o.font = d.font, o.textAlign = "left", o.textBaseline = "alphabetic", o.fillStyle = e, o.fillText(i, 0, s), l.toDataURL();
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
- async function A({
13
- ignoreIconFonts: i = !0,
14
- preCached: r = !1
15
- }) {
16
- const u = Array.from(
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((e) => e.href);
19
- let n = "";
20
- for (const e of u)
44
+ ).filter((t) => t.href);
45
+ let i = "";
46
+ for (const t of g)
21
47
  try {
22
- const h = await (await fetch(e.href)).text();
23
- if (i && (w(e.href) || w(h)))
48
+ const o = await (await fetch(t.href)).text();
49
+ if (f && (b(t.href) || b(o)))
24
50
  continue;
25
- const d = /url\(([^)]+)\)/g, f = await Promise.all(
26
- Array.from(h.matchAll(d)).map(async (a) => {
27
- let t = a[1].replace(/["']/g, "");
28
- if (t.startsWith("http") || (t = new URL(t, e.href).href), i && w(t))
29
- return null;
30
- if (x.has(t))
31
- return {
32
- original: a[0],
33
- inlined: `url(${x.get(t)})`
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 l = await (await fetch(t)).blob(), o = await new Promise((g) => {
37
- const p = new FileReader();
38
- p.onload = () => g(p.result), p.readAsDataURL(l);
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 x.set(t, o), { original: a[0], inlined: `url(${o})` };
68
+ return c.set(e, w), h.add(e), { original: r[0], inlined: `url(${w})` };
41
69
  } catch {
42
- return console.warn(" Failed to fetch font:", t), null;
70
+ return console.warn("[snapdom] Failed to fetch font resource:", e), null;
43
71
  }
44
72
  })
45
73
  );
46
- let s = h;
47
- for (const a of f)
48
- a && (s = s.replace(a.original, a.inlined));
49
- n += s + `
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(" Failed to fetch CSS:", e.href);
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 (n && r) {
55
- const e = document.createElement("style");
56
- e.setAttribute("data-snapdom", "embedFonts"), e.textContent = n, document.head.appendChild(e);
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 n;
161
+ return i;
59
162
  }
60
163
  export {
61
- A as embedCustomFonts,
62
- y as iconToImage
164
+ P as embedCustomFonts,
165
+ _ as iconToImage
63
166
  };
@@ -1,17 +1,17 @@
1
- import { fetchImage as i } from "../utils/helpers.js";
2
- async function h(a) {
3
- const n = Array.from(a.querySelectorAll("img")), r = async (t) => {
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 i(c);
7
- t.src = e, t.width || (t.width = t.naturalWidth || 100), t.height || (t.height = t.naturalHeight || 100);
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 < n.length; t += 4) {
14
- const c = n.slice(t, t + 4).map(r);
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 { getStyleKey as S } from "../utils/cssTools.js";
2
- import { getStyle as x, snapshotComputedStyle as W, parseContent as j, fetchImage as z } from "../utils/helpers.js";
3
- import { iconToImage as A } from "./fonts.js";
4
- async function B(s, a, f, y, p, m = !1) {
5
- if (!(s instanceof Element) || !(a instanceof Element)) return;
6
- for (const t of ["::before", "::after"])
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 = x(s, t);
8
+ const e = A(l, n);
9
9
  if (!e) continue;
10
- const r = e.getPropertyValue("content"), g = e.getPropertyValue("background-image"), u = r && r !== "none" && r !== '""' && r !== "''", C = g && g.startsWith("url(");
11
- if (u || C) {
12
- const l = e.getPropertyValue("font-family"), E = parseInt(e.getPropertyValue("font-size")) || 32, w = parseInt(e.getPropertyValue("font-weight")) || !1, P = e.getPropertyValue("color") || "#000", o = document.createElement("span");
13
- o.dataset.snapdomPseudo = t;
14
- const b = W(e), V = S(b, "span", p);
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
- let i = j(r);
20
- if (!m && I && i.length === 1) {
21
- const n = document.createElement("img");
22
- n.src = await A(
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
- l,
25
- w,
26
- E,
27
- P
28
- ), n.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(n);
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 n = i.match(/url\(["']?([^"')]+)["']?\)/);
31
- if (n != null && n[1])
46
+ const t = B(i);
47
+ if (t && t.trim() !== "")
32
48
  try {
33
- const c = document.createElement("img"), k = await z(n[1]);
34
- c.src = k, c.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(c);
35
- } catch (c) {
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 ${t} for`,
38
- s,
39
- c
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
- } else i && i !== "none" && (o.textContent = i);
43
- t === "::before" ? a.insertBefore(o, a.firstChild) : a.appendChild(o);
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 ${t} for`, s, e);
76
+ console.warn(`[snapdom] Failed to capture ${n} for`, l, e);
47
77
  }
48
- const d = Array.from(s.children), h = Array.from(a.children).filter(
49
- (t) => !t.dataset.snapdomPseudo
78
+ const x = Array.from(l.children), w = Array.from(r.children).filter(
79
+ (n) => !n.dataset.snapdomPseudo
50
80
  );
51
- for (let t = 0; t < Math.min(d.length, h.length); t++)
52
- await B(
53
- d[t],
54
- h[t],
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
- m
86
+ F,
87
+ g,
88
+ b
59
89
  );
60
90
  }
61
91
  export {
62
- B as inlinePseudoElements
92
+ L as inlinePseudoElements
63
93
  };
@@ -1,12 +1,11 @@
1
- import { getStyleKey as g } from "../utils/cssTools.js";
2
- import { getStyle as p, snapshotComputedStyle as f } from "../utils/helpers.js";
3
- function N(t, o, s, e, a) {
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, p(t));
7
- const i = e.get(t), l = f(i), m = ((n = t.tagName) == null ? void 0 : n.toLowerCase()) || "div", y = g(l, m, a);
8
- s.set(o, y);
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
- N as inlineAllStyles
10
+ r as inlineAllStyles
12
11
  };
@@ -1,31 +1,33 @@
1
- import { imageCache as s, computedStyleCache as m } from "../core/cache.js";
2
- function g(t, { fast: e = !1 } = {}) {
3
- if (e) return t();
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 d(t, e = null) {
6
+ function f(t, n = null) {
7
7
  if (!(t instanceof Element))
8
- return window.getComputedStyle(t, e);
9
- let n = m.get(t);
10
- if (n || (n = /* @__PURE__ */ new Map(), m.set(t, n)), !n.has(e)) {
11
- const i = window.getComputedStyle(t, e);
12
- n.set(e, i);
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 n.get(e);
14
+ return e.get(n);
15
15
  }
16
- function f(t) {
17
- let e = t.replace(/^['"]|['"]$/g, "");
18
- if (e.startsWith("\\"))
16
+ function g(t) {
17
+ let n = t.replace(/^['"]|['"]$/g, "");
18
+ if (n.startsWith("\\"))
19
19
  try {
20
- return String.fromCharCode(parseInt(e.replace("\\", ""), 16));
20
+ return String.fromCharCode(parseInt(n.replace("\\", ""), 16));
21
21
  } catch {
22
- return e;
22
+ return n;
23
23
  }
24
- return e;
24
+ return n;
25
25
  }
26
- function h(t) {
27
- const e = t.match(/url\(["']?([^"')]+)["']?\)/);
28
- return e ? e[1] : null;
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
- ].some((n) => n.test(t));
41
+ /heroicons/i,
42
+ /lucide/i
43
+ ].some((e) => e.test(t));
41
44
  }
42
- function w(t, e = 3e3) {
43
- return s.has(t) ? Promise.resolve(s.get(t)) : new Promise((n, i) => {
44
- const c = setTimeout(() => {
45
- i(new Error("Image load timed out"));
46
- }, e), o = new Image();
47
- o.crossOrigin = "anonymous", o.onload = async () => {
48
- clearTimeout(c);
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 o.decode();
51
- const r = document.createElement("canvas");
52
- r.width = o.width, r.height = o.height, r.getContext("2d").drawImage(o, 0, 0);
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 a = r.toDataURL("image/png");
55
- s.set(t, a), n(a);
57
+ const s = i.toDataURL("image/png");
58
+ c.set(t, s), a(s);
56
59
  } catch {
57
- i(new Error("CORS restrictions prevented image capture"));
60
+ o(new Error("CORS restrictions prevented image capture"));
58
61
  }
59
- } catch (r) {
60
- i(r);
62
+ } catch (i) {
63
+ o(i);
61
64
  }
62
- }, o.onerror = (r) => {
63
- clearTimeout(c), i(
64
- new Error("Failed to load image: " + (r.message || "Unknown error"))
65
+ }, r.onerror = (i) => {
66
+ clearTimeout(u), o(
67
+ new Error("Failed to load image: " + (i.message || "Unknown error"))
65
68
  );
66
- }, o.src = t;
69
+ }, r.src = t;
67
70
  });
68
71
  }
69
- function C(t) {
70
- const e = {};
71
- for (let n of t)
72
- e[n] = t.getPropertyValue(n);
73
- return e;
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 y() {
78
+ function I() {
76
79
  return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
77
80
  }
78
81
  export {
79
- h as extractUrl,
80
- w as fetchImage,
81
- d as getStyle,
82
- g as idle,
82
+ w as extractURL,
83
+ C as fetchImage,
84
+ f as getStyle,
85
+ h as idle,
83
86
  p as isIconFont,
84
- y as isSafari,
85
- f as parseContent,
86
- C as snapshotComputedStyle
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, t, f, l = "children") {
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 (t in e && e[t] === f)
5
+ if (r in e && e[r] === f)
6
6
  return e;
7
- const r = e[l] ?? e.items ?? e.list;
8
- if (Array.isArray(r))
9
- for (let i of r) {
10
- const n = a(i, t, f, l);
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, t, f, l = "children") {
16
+ function y(e, r, f, l = "children") {
17
17
  if (!e) return;
18
- let r = Array.isArray(e) ? [...e] : [e];
19
- e: for (; r.length; ) {
20
- let i = r.shift();
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[t] === f)
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
- r = r.concat(i);
30
+ t = t.concat(i);
31
31
  }
32
32
  }
33
33
  const d = a;
34
- function A(e, t, f, l = "children") {
34
+ function A(e, r, f, l = "children") {
35
35
  if (!e) return;
36
- const r = Array.isArray(e) ? [...e] : [e];
37
- e: for (; r.length; ) {
38
- let i = r.pop();
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[t] === f)
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
- r.push(i[u - 1 - n]);
50
+ t.push(i[u - 1 - n]);
51
51
  }
52
52
  }
53
- function h(e, t) {
54
- return y(e, "id", t);
53
+ function h(e, r) {
54
+ return y(e, "id", r);
55
55
  }
56
- function g(e, t, f = !0) {
57
- var r;
58
- let l = (r = y(e, "value", t)) == null ? void 0 : r.label;
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, t, f, l = "children") {
60
+ function m(e, r, f, l = "children") {
62
61
  if (!e) return;
63
- let r = null;
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 c = 0; c < u.length; c++) {
68
- const s = u[c];
69
- if ((s == null ? void 0 : s[t]) === f) {
70
- r = { item: s, parent: n, index: c };
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(s);
72
+ i(c);
74
73
  }
75
74
  }
76
- return i(e), r;
75
+ return i(e), t;
77
76
  }
78
77
  export {
79
78
  y as default,