@unicom-cloud/utils 0.1.4 → 0.1.10

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,92 @@
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 z } from "./fonts.js";
2
+ import { getStyleKey as V } from "../utils/cssTools.js";
3
+ import { getStyle as U, snapshotComputedStyle as I, parseContent as W, extractURL as j, fetchImage as A, safeEncodeURI as D, splitBackgroundImage as L, inlineSingleBackgroundEntry as $ } from "../utils/helpers.js";
4
+ async function R(l, i, g, F, h, w = !1) {
5
+ if (!(l instanceof Element) || !(i instanceof Element)) return;
6
+ for (const n of ["::before", "::after", "::first-letter"])
7
7
  try {
8
- const e = x(s, t);
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
8
+ const t = U(l, n);
9
+ if (!t || typeof t[Symbol.iterator] != "function") continue;
10
+ if (n === "::first-letter") {
11
+ const a = getComputedStyle(l);
12
+ if (!(t.color !== a.color || t.fontSize !== a.fontSize || t.fontWeight !== a.fontWeight)) continue;
13
+ const d = Array.from(i.childNodes).find(
14
+ (e) => e.nodeType === Node.TEXT_NODE && e.textContent && e.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(
23
- i,
24
- l,
25
- w,
26
- E,
27
- P
28
- ), n.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(n);
29
- } else if (i.startsWith("url(")) {
30
- const n = i.match(/url\(["']?([^"')]+)["']?\)/);
31
- if (n != null && n[1])
16
+ if (!d) continue;
17
+ const p = d.textContent, f = p.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0], b = p.slice(f?.length || 0);
18
+ if (!f || /[\uD800-\uDFFF]/.test(f)) continue;
19
+ const r = document.createElement("span");
20
+ r.textContent = f, r.dataset.snapdomPseudo = "::first-letter";
21
+ const s = I(t), N = V(s, "span", h);
22
+ g.set(r, N);
23
+ const x = document.createTextNode(b);
24
+ i.replaceChild(x, d), i.insertBefore(r, x);
25
+ continue;
26
+ }
27
+ const S = t.getPropertyValue("content"), u = t.getPropertyValue("background-image"), m = t.getPropertyValue("background-color"), T = S !== "none", y = u && u !== "none", C = m && m !== "transparent" && m !== "rgba(0, 0, 0, 0)";
28
+ if (T || y || C) {
29
+ const a = t.getPropertyValue("font-family"), B = parseInt(t.getPropertyValue("font-size")) || 32, d = parseInt(t.getPropertyValue("font-weight")) || !1, p = t.getPropertyValue("color") || "#000", o = document.createElement("span");
30
+ o.dataset.snapdomPseudo = n;
31
+ const f = I(t), b = V(f, "span", h);
32
+ g.set(o, b);
33
+ const r = a && /font.*awesome|material|bootstrap|glyphicons|ionicons|remixicon|simple-line-icons|octicons|feather|typicons|weathericons|lucide/i.test(
34
+ a
35
+ ), s = W(S);
36
+ if (!w && r && s.length === 1) {
37
+ const e = document.createElement("img");
38
+ e.src = await z(
39
+ s,
40
+ a,
41
+ d,
42
+ B,
43
+ p
44
+ ), e.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(e);
45
+ } else if (s.startsWith("url(")) {
46
+ const e = j(s);
47
+ if (e && e.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);
49
+ const c = document.createElement("img"), E = await A(D(e));
50
+ c.src = E, c.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(c);
35
51
  } catch (c) {
36
52
  console.error(
37
- `[snapdom] Error in pseudo ${t} for`,
38
- s,
53
+ `[snapdom] Error in pseudo ${n} for`,
54
+ l,
39
55
  c
40
56
  );
41
57
  }
42
- } else i && i !== "none" && (o.textContent = i);
43
- t === "::before" ? a.insertBefore(o, a.firstChild) : a.appendChild(o);
58
+ } else !r && s && s !== "none" && (o.textContent = s);
59
+ if (y)
60
+ try {
61
+ const e = L(u), c = await Promise.all(
62
+ e.map((E) => $(E))
63
+ );
64
+ o.style.backgroundImage = c.join(", ");
65
+ } catch (e) {
66
+ console.warn(
67
+ `[snapdom] Failed to inline background-image for ${n}`,
68
+ e
69
+ );
70
+ }
71
+ if (C && (o.style.backgroundColor = m), !(o.childNodes.length > 0 || o.textContent && o.textContent.trim() !== "" || y || C)) continue;
72
+ n === "::before" ? i.insertBefore(o, i.firstChild) : i.appendChild(o);
44
73
  }
45
- } catch (e) {
46
- console.warn(`[snapdom] Failed to capture ${t} for`, s, e);
74
+ } catch (t) {
75
+ console.warn(`[snapdom] Failed to capture ${n} for`, l, t);
47
76
  }
48
- const d = Array.from(s.children), h = Array.from(a.children).filter(
49
- (t) => !t.dataset.snapdomPseudo
77
+ const P = Array.from(l.children), k = Array.from(i.children).filter(
78
+ (n) => !n.dataset.snapdomPseudo
50
79
  );
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,
57
- p,
58
- m
80
+ for (let n = 0; n < Math.min(P.length, k.length); n++)
81
+ await R(
82
+ P[n],
83
+ k[n],
84
+ g,
85
+ F,
86
+ h,
87
+ w
59
88
  );
60
89
  }
61
90
  export {
62
- B as inlinePseudoElements
91
+ R as inlinePseudoElements
63
92
  };
@@ -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,19 +1,36 @@
1
- import { imageCache as s, computedStyleCache as m } from "../core/cache.js";
2
- function g(t, { fast: e = !1 } = {}) {
1
+ import { imageCache as l, computedStyleCache as m, bgCache as u } from "../core/cache.js";
2
+ async function w(t, e = {}) {
3
+ const n = t.startsWith("url("), a = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(
4
+ t
5
+ );
6
+ if (n) {
7
+ const r = d(t);
8
+ if (!r) return t;
9
+ const i = g(r);
10
+ if (u.has(i))
11
+ return e.skipInline ? void 0 : `url(${u.get(i)})`;
12
+ {
13
+ const s = e.crossOrigin ? e.crossOrigin(i) : "anonymous", o = await f(i, 3e3, s);
14
+ return u.set(i, o), e.skipInline ? void 0 : `url(${o})`;
15
+ }
16
+ }
17
+ return t;
18
+ }
19
+ function I(t, { fast: e = !1 } = {}) {
3
20
  if (e) return t();
4
21
  "requestIdleCallback" in window ? requestIdleCallback(t, { timeout: 50 }) : setTimeout(t, 1);
5
22
  }
6
- function d(t, e = null) {
23
+ function x(t, e = null) {
7
24
  if (!(t instanceof Element))
8
25
  return window.getComputedStyle(t, e);
9
26
  let n = m.get(t);
10
27
  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);
28
+ const a = window.getComputedStyle(t, e);
29
+ n.set(e, a);
13
30
  }
14
31
  return n.get(e);
15
32
  }
16
- function f(t) {
33
+ function C(t) {
17
34
  let e = t.replace(/^['"]|['"]$/g, "");
18
35
  if (e.startsWith("\\"))
19
36
  try {
@@ -23,11 +40,13 @@ function f(t) {
23
40
  }
24
41
  return e;
25
42
  }
26
- function h(t) {
27
- const e = t.match(/url\(["']?([^"')]+)["']?\)/);
28
- return e ? e[1] : null;
43
+ function d(t) {
44
+ const e = t.indexOf("url(");
45
+ if (e === -1) return null;
46
+ let n = t.slice(e + 4).trim();
47
+ return n.endsWith(")") && (n = n.slice(0, -1).trim()), (n.startsWith('"') && n.endsWith('"') || n.startsWith("'") && n.endsWith("'")) && (n = n.slice(1, -1)), n;
29
48
  }
30
- function p(t) {
49
+ function S(t) {
31
50
  return [
32
51
  /font\s*awesome/i,
33
52
  /material\s*icons/i,
@@ -36,37 +55,38 @@ function p(t) {
36
55
  /feather/i,
37
56
  /bootstrap\s*icons/i,
38
57
  /remix\s*icons/i,
39
- /heroicons/i
58
+ /heroicons/i,
59
+ /lucide/i
40
60
  ].some((n) => n.test(t));
41
61
  }
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);
62
+ function f(t, e = 3e3, n = "anonymous") {
63
+ return l.has(t) ? Promise.resolve(l.get(t)) : new Promise((a, r) => {
64
+ const i = setTimeout(() => {
65
+ r(new Error("Image load timed out"));
66
+ }, e), s = new Image();
67
+ s.crossOrigin = n, s.onload = async () => {
68
+ clearTimeout(i);
49
69
  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);
70
+ await s.decode();
71
+ const o = document.createElement("canvas");
72
+ o.width = s.width, o.height = s.height, o.getContext("2d").drawImage(s, 0, 0, o.width, o.height);
53
73
  try {
54
- const a = r.toDataURL("image/png");
55
- s.set(t, a), n(a);
74
+ const c = o.toDataURL("image/png");
75
+ l.set(t, c), a(c);
56
76
  } catch {
57
- i(new Error("CORS restrictions prevented image capture"));
77
+ r(new Error("CORS restrictions prevented image capture"));
58
78
  }
59
- } catch (r) {
60
- i(r);
79
+ } catch (o) {
80
+ r(o);
61
81
  }
62
- }, o.onerror = (r) => {
63
- clearTimeout(c), i(
64
- new Error("Failed to load image: " + (r.message || "Unknown error"))
82
+ }, s.onerror = (o) => {
83
+ clearTimeout(i), r(
84
+ new Error("Failed to load image: " + (o.message || "Unknown error"))
65
85
  );
66
- }, o.src = t;
86
+ }, s.src = t;
67
87
  });
68
88
  }
69
- function C(t) {
89
+ function U(t) {
70
90
  const e = {};
71
91
  for (let n of t)
72
92
  e[n] = t.getPropertyValue(n);
@@ -75,13 +95,45 @@ function C(t) {
75
95
  function y() {
76
96
  return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
77
97
  }
98
+ function k(t) {
99
+ if (!t || t === "none") return "";
100
+ let e = t.replace(/translate[XY]?\([^)]*\)/g, "");
101
+ return e = e.replace(/matrix\(([^)]+)\)/g, (n, a) => {
102
+ const r = a.split(",").map((i) => i.trim());
103
+ return r.length !== 6 ? `matrix(${a})` : (r[4] = "0", r[5] = "0", `matrix(${r.join(", ")})`);
104
+ }), e = e.replace(/matrix3d\(([^)]+)\)/g, (n, a) => {
105
+ const r = a.split(",").map((i) => i.trim());
106
+ return r.length !== 16 ? `matrix3d(${a})` : (r[12] = "0", r[13] = "0", `matrix3d(${r.join(", ")})`);
107
+ }), e.trim().replace(/\s{2,}/g, " ");
108
+ }
109
+ function g(t) {
110
+ if (/%[0-9A-Fa-f]{2}/.test(t)) return t;
111
+ try {
112
+ return encodeURI(t);
113
+ } catch {
114
+ return t;
115
+ }
116
+ }
117
+ function E(t) {
118
+ const e = [];
119
+ let n = 0, a = 0;
120
+ for (let r = 0; r < t.length; r++) {
121
+ const i = t[r];
122
+ i === "(" && n++, i === ")" && n--, i === "," && n === 0 && (e.push(t.slice(a, r).trim()), a = r + 1);
123
+ }
124
+ return e.push(t.slice(a).trim()), e;
125
+ }
78
126
  export {
79
- h as extractUrl,
80
- w as fetchImage,
81
- d as getStyle,
82
- g as idle,
83
- p as isIconFont,
127
+ d as extractURL,
128
+ f as fetchImage,
129
+ x as getStyle,
130
+ I as idle,
131
+ w as inlineSingleBackgroundEntry,
132
+ S as isIconFont,
84
133
  y as isSafari,
85
- f as parseContent,
86
- C as snapshotComputedStyle
134
+ C as parseContent,
135
+ g as safeEncodeURI,
136
+ U as snapshotComputedStyle,
137
+ E as splitBackgroundImage,
138
+ k as stripTranslate
87
139
  };