@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.
@@ -1,91 +1,91 @@
1
1
  import { captureDOM as v } from "../core/capture.js";
2
2
  import { isSafari as R } from "../utils/helpers.js";
3
- async function I(a, { dpr: t = 1, scale: n = 1 }) {
4
- const e = new Image();
5
- return e.src = a, await e.decode(), R ? (e.width = e.width * n, e.height = e.height * n) : (e.width = e.width / n, e.height = e.height / n), e;
3
+ async function x(e, { dpr: t = 1, scale: c = 1 }) {
4
+ const a = new Image();
5
+ return a.src = e, await a.decode(), R ? (a.width = a.width * c, a.height = a.height * c) : (a.width = a.width / c, a.height = a.height / c), a;
6
6
  }
7
- async function h(a, { dpr: t = 1, scale: n = 1 }) {
8
- const e = new Image();
9
- e.src = a, await e.decode();
10
- const c = document.createElement("canvas"), o = e.width * n * t, g = e.height * n * t;
11
- c.width = Math.ceil(o), c.height = Math.ceil(g);
12
- const s = c.getContext("2d");
13
- return s.scale(n * t, n * t), s.drawImage(e, 0, 0), c;
7
+ async function p(e, { dpr: t = 1, scale: c = 1 } = {}) {
8
+ const a = new Image();
9
+ a.src = e, await a.decode();
10
+ const n = document.createElement("canvas"), o = a.width * c, g = a.height * c;
11
+ n.width = Math.ceil(o * t), n.height = Math.ceil(g * t);
12
+ const s = n.getContext("2d");
13
+ return s.scale(t, t), s.drawImage(a, 0, 0, o, g), n.style.width = `${o}px`, n.style.height = `${g}px`, n;
14
14
  }
15
- async function p(a) {
16
- const t = decodeURIComponent(a.split(",")[1]);
15
+ async function u(e) {
16
+ const t = decodeURIComponent(e.split(",")[1]);
17
17
  return new Blob([t], { type: "image/svg+xml" });
18
18
  }
19
- async function m(a, { dpr: t = 1, scale: n = 1 }, e) {
20
- const c = await h(a, { dpr: t, scale: n });
21
- if (!e) return c;
19
+ async function l(e, { dpr: t = 1, scale: c = 1 }, a) {
20
+ const n = await p(e, { dpr: t, scale: c });
21
+ if (!a) return n;
22
22
  const o = document.createElement("canvas");
23
- o.width = c.width, o.height = c.height;
23
+ o.width = n.width, o.height = n.height;
24
24
  const g = o.getContext("2d");
25
- return g.fillStyle = e, g.fillRect(0, 0, o.width, o.height), g.drawImage(c, 0, 0), o;
25
+ return g.fillStyle = a, g.fillRect(0, 0, o.width, o.height), g.drawImage(n, 0, 0), o;
26
26
  }
27
- async function d(a, { dpr: t = 1, scale: n = 1, backgroundColor: e = "#fff", quality: c }, o = "png") {
28
- const g = await m(a, { dpr: t, scale: n }, e), s = new Image();
29
- return s.src = g.toDataURL(`image/${o}`, c), await s.decode(), s.style.width = `${g.width / t}px`, s.style.height = `${g.height / t}px`, s;
27
+ async function d(e, { dpr: t = 1, scale: c = 1, backgroundColor: a = "#fff", quality: n }, o = "png") {
28
+ const g = await l(e, { dpr: t, scale: c }, a), s = new Image();
29
+ return s.src = g.toDataURL(`image/${o}`, n), await s.decode(), s.style.width = `${g.width / t}px`, s.style.height = `${g.height / t}px`, s;
30
30
  }
31
- async function j(a, {
31
+ async function I(e, {
32
32
  dpr: t = 1,
33
- scale: n = 1,
34
- backgroundColor: e = "#fff",
35
- format: c = "png",
33
+ scale: c = 1,
34
+ backgroundColor: a = "#fff",
35
+ format: n = "png",
36
36
  filename: o = "capture"
37
37
  } = {}) {
38
- if (c === "svg") {
39
- const b = await p(a), u = URL.createObjectURL(b), w = document.createElement("a");
40
- w.href = u, w.download = `${o}.svg`, w.click(), URL.revokeObjectURL(u);
38
+ if (n === "svg") {
39
+ const b = await u(e), h = URL.createObjectURL(b), w = document.createElement("a");
40
+ w.href = h, w.download = `${o}.svg`, w.click(), URL.revokeObjectURL(h);
41
41
  return;
42
42
  }
43
- const g = ["jpg", "jpeg", "webp"].includes(c) ? "#fff" : void 0, l = await m(a, { dpr: t, scale: n }, e ?? g), f = {
43
+ const g = ["jpg", "jpeg", "webp"].includes(n) ? "#fff" : void 0, m = await l(e, { dpr: t, scale: c }, a ?? g), f = {
44
44
  jpg: "image/jpeg",
45
45
  jpeg: "image/jpeg",
46
46
  png: "image/png",
47
47
  webp: "image/webp"
48
- }[c] || "image/png", y = l.toDataURL(f), r = document.createElement("a");
49
- r.href = y, r.download = `${o}.${c}`, r.click();
48
+ }[n] || "image/png", y = m.toDataURL(f), r = document.createElement("a");
49
+ r.href = y, r.download = `${o}.${n}`, r.click();
50
50
  }
51
- async function i(a, t = {}) {
52
- if (t = { scale: 1, ...t }, !a) throw new Error("Element cannot be null or undefined");
53
- return await i.capture(a, t);
51
+ async function i(e, t = {}) {
52
+ if (t = { scale: 1, ...t }, !e) throw new Error("Element cannot be null or undefined");
53
+ return await i.capture(e, t);
54
54
  }
55
- i.capture = async (a, t = {}) => {
56
- const n = await v(a, t), e = window.devicePixelRatio || 1, c = t.scale || 1;
55
+ i.capture = async (e, t = {}) => {
56
+ const c = await v(e, t), a = window.devicePixelRatio || 1, n = t.scale || 1;
57
57
  return {
58
- url: n,
58
+ url: c,
59
59
  options: t,
60
- toRaw: () => n,
61
- toImg: () => I(n, { dpr: e, scale: c }),
62
- toCanvas: () => h(n, { dpr: e, scale: c }),
63
- toBlob: () => p(n),
64
- toPng: (o) => d(n, { dpr: e, scale: c, ...o }, "png"),
65
- toJpg: (o) => d(n, { dpr: e, scale: c, ...o }, "jpeg"),
66
- toWebp: (o) => d(n, { dpr: e, scale: c, ...o }, "webp"),
60
+ toRaw: () => c,
61
+ toImg: () => x(c, { dpr: a, scale: n }),
62
+ toCanvas: () => p(c, { dpr: a, scale: n }),
63
+ toBlob: () => u(c),
64
+ toPng: (o) => d(c, { dpr: a, scale: n, ...o }, "png"),
65
+ toJpg: (o) => d(c, { dpr: a, scale: n, ...o }, "jpeg"),
66
+ toWebp: (o) => d(c, { dpr: a, scale: n, ...o }, "webp"),
67
67
  download: ({
68
68
  format: o = "png",
69
69
  filename: g = "capture",
70
70
  backgroundColor: s
71
- } = {}) => j(n, { dpr: e, scale: c, backgroundColor: s, format: o, filename: g })
71
+ } = {}) => I(c, { dpr: a, scale: n, backgroundColor: s, format: o, filename: g })
72
72
  };
73
73
  };
74
- i.toRaw = async (a, t) => (await i.capture(a, t)).toRaw();
75
- i.toImg = async (a, t) => (await i.capture(a, t)).toImg();
76
- i.toCanvas = async (a, t) => (await i.capture(a, t)).toCanvas();
77
- i.toBlob = async (a, t) => (await i.capture(a, t)).toBlob();
78
- i.toPng = async (a, t) => (await i.capture(a, t)).toPng(t);
79
- i.toJpg = async (a, t) => (await i.capture(a, t)).toJpg(t);
80
- i.toWebp = async (a, t) => (await i.capture(a, t)).toWebp(t);
81
- i.download = async (a, t = {}) => {
74
+ i.toRaw = async (e, t) => (await i.capture(e, t)).toRaw();
75
+ i.toImg = async (e, t) => (await i.capture(e, t)).toImg();
76
+ i.toCanvas = async (e, t) => (await i.capture(e, t)).toCanvas();
77
+ i.toBlob = async (e, t) => (await i.capture(e, t)).toBlob();
78
+ i.toPng = async (e, t) => (await i.capture(e, t)).toPng(t);
79
+ i.toJpg = async (e, t) => (await i.capture(e, t)).toJpg(t);
80
+ i.toWebp = async (e, t) => (await i.capture(e, t)).toWebp(t);
81
+ i.download = async (e, t = {}) => {
82
82
  const {
83
- format: n = "png",
84
- filename: e = "capture",
85
- backgroundColor: c,
83
+ format: c = "png",
84
+ filename: a = "capture",
85
+ backgroundColor: n,
86
86
  ...o
87
87
  } = t;
88
- return await (await i.capture(a, o)).download({ format: n, filename: e, backgroundColor: c });
88
+ return await (await i.capture(e, o)).download({ format: c, filename: a, backgroundColor: n });
89
89
  };
90
90
  export {
91
91
  i as snapdom
@@ -1,9 +1,10 @@
1
- const e = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new WeakMap();
1
+ const e = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new Set();
2
2
  export {
3
3
  t as baseCSSCache,
4
4
  a as bgCache,
5
- o as computedStyleCache,
5
+ s as computedStyleCache,
6
6
  n as defaultStylesCache,
7
7
  e as imageCache,
8
+ o as processedFontURLs,
8
9
  c as resourceCache
9
10
  };
@@ -1,72 +1,72 @@
1
+ import { baseCSSCache as w } from "./cache.js";
1
2
  import { inlineBackgroundImages as $ } from "../modules/background.js";
2
3
  import { embedCustomFonts as B } from "../modules/fonts.js";
3
4
  import { inlineImages as E } from "../modules/images.js";
4
5
  import { collectUsedTagNames as F, generateDedupedBaseCSS as I } from "../utils/cssTools.js";
5
6
  import { idle as i, isSafari as P } from "../utils/helpers.js";
6
- import { baseCSSCache as g } from "./cache.js";
7
7
  import { prepareClone as z } from "./prepare.js";
8
- async function L(a, y = {}) {
8
+ async function L(a, l = {}) {
9
9
  if (!a) throw new Error("Element cannot be null or undefined");
10
10
  const {
11
- compress: w = !0,
12
- embedFonts: l = !1,
13
- fast: s = !0,
14
- scale: d = 1
15
- } = y;
16
- let t, f, p, h = "", r = "", u, S;
17
- if ({ clone: t, classCSS: f, styleCache: p } = await z(
11
+ compress: d = !0,
12
+ embedFonts: m = !1,
13
+ fast: o = !0,
14
+ scale: f = 1
15
+ } = l;
16
+ let t, h, p, u = "", r = "", S, v;
17
+ if ({ clone: t, classCSS: h, styleCache: p } = await z(
18
18
  a,
19
- w,
20
- l
19
+ d,
20
+ m
21
21
  ), await new Promise((e) => {
22
22
  i(
23
23
  async () => {
24
- await E(t), e();
24
+ await E(t, l), e();
25
25
  },
26
- { fast: s }
26
+ { fast: o }
27
27
  );
28
28
  }), await new Promise((e) => {
29
29
  i(
30
30
  async () => {
31
- await $(a, t, p), e();
31
+ await $(a, t, p, l), e();
32
32
  },
33
- { fast: s }
33
+ { fast: o }
34
34
  );
35
- }), l && await new Promise((e) => {
35
+ }), m && await new Promise((e) => {
36
36
  i(
37
37
  async () => {
38
- h = await B({ ignoreIconFonts: !l }), e();
38
+ u = await B({ ignoreIconFonts: !m }), e();
39
39
  },
40
- { fast: s }
40
+ { fast: o }
41
41
  );
42
- }), w) {
43
- const e = F(t).sort(), o = e.join(",");
44
- g.has(o) ? r = g.get(o) : await new Promise((c) => {
42
+ }), d) {
43
+ const e = F(t).sort(), s = e.join(",");
44
+ w.has(s) ? r = w.get(s) : await new Promise((c) => {
45
45
  i(
46
46
  () => {
47
- r = I(e), g.set(o, r), c();
47
+ r = I(e), w.set(s, r), c();
48
48
  },
49
- { fast: s }
49
+ { fast: o }
50
50
  );
51
51
  });
52
52
  }
53
53
  await new Promise((e) => {
54
54
  i(
55
55
  () => {
56
- const o = a.getBoundingClientRect(), c = Math.ceil(o.width), v = Math.ceil(o.height);
57
- t.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), t.style.transformOrigin = "top left", d !== 1 && P() && (t.style.scale = `${d}`);
58
- const C = "http://www.w3.org/2000/svg", n = document.createElementNS(C, "foreignObject");
56
+ const s = a.getBoundingClientRect(), c = Math.ceil(s.width), C = Math.ceil(s.height);
57
+ t.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), t.style.transformOrigin = "top left", f !== 1 && P() && (t.style.scale = `${f}`);
58
+ const b = "http://www.w3.org/2000/svg", n = document.createElementNS(b, "foreignObject");
59
59
  n.setAttribute("width", "100%"), n.setAttribute("height", "100%");
60
- const b = document.createElement("style");
61
- b.textContent = r + h + "svg{overflow:visible;}" + f, n.appendChild(b), n.appendChild(t);
60
+ const y = document.createElement("style");
61
+ y.textContent = r + u + "svg{overflow:visible;}" + h, n.appendChild(y), n.appendChild(t);
62
62
  const x = new XMLSerializer().serializeToString(n);
63
- S = `<svg xmlns="${C}" width="${c}" height="${v}" viewBox="0 0 ${c} ${v}">` + x + "</svg>", u = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(S)}`, e();
63
+ v = `<svg xmlns="${b}" width="${c}" height="${C}" viewBox="0 0 ${c} ${C}">` + x + "</svg>", S = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(v)}`, e();
64
64
  },
65
- { fast: s }
65
+ { fast: o }
66
66
  );
67
67
  });
68
- const m = document.getElementById("snapdom-sandbox");
69
- return m && m.style.position === "absolute" && m.remove(), u;
68
+ const g = document.getElementById("snapdom-sandbox");
69
+ return g && g.style.position === "absolute" && g.remove(), S;
70
70
  }
71
71
  export {
72
72
  L as captureDOM
@@ -1,50 +1,51 @@
1
- import { inlineAllStyles as h } from "../modules/styles.js";
2
- function f(t, a, l, c, o) {
3
- var s;
4
- if (t.nodeType === Node.ELEMENT_NODE && t.getAttribute("data-capture") === "exclude") {
5
- const i = document.createElement("div"), e = t.getBoundingClientRect();
6
- return i.style.cssText = `display: inline-block; width: ${e.width}px; height: ${e.height}px; visibility: hidden;`, i;
1
+ import { inlineAllStyles as f } from "../modules/styles.js";
2
+ function h(e, c, r, n, s) {
3
+ if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "exclude") {
4
+ const t = document.createElement("div"), i = e.getBoundingClientRect();
5
+ return t.style.cssText = `display: inline-block; width: ${i.width}px; height: ${i.height}px; visibility: hidden;`, t;
7
6
  }
8
- if (t.tagName === "IFRAME") {
9
- const i = document.createElement("div");
10
- return i.textContent = "", i.style.cssText = `width: ${t.offsetWidth}px; height: ${t.offsetHeight}px; background: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`, i;
7
+ if (e.tagName === "IFRAME") {
8
+ const t = document.createElement("div");
9
+ return t.textContent = "", t.style.cssText = `width: ${e.offsetWidth}px; height: ${e.offsetHeight}px; background-image: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`, t;
11
10
  }
12
- if (t.nodeType === Node.ELEMENT_NODE && t.getAttribute("data-capture") === "placeholder") {
13
- const i = t.cloneNode(!1);
14
- c.set(i, t), h(t, i, a, l, o);
15
- const e = document.createElement("div");
16
- return e.textContent = t.getAttribute("data-placeholder-text") || "", e.style.cssText = "color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;", i.appendChild(e), i;
11
+ if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "placeholder") {
12
+ const t = e.cloneNode(!1);
13
+ n.set(t, e), f(e, t, c, r, s);
14
+ const i = document.createElement("div");
15
+ return i.textContent = e.getAttribute("data-placeholder-text") || "", i.style.cssText = "color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;", t.appendChild(i), t;
17
16
  }
18
- if (t.tagName === "CANVAS") {
19
- const i = t.toDataURL(), e = document.createElement("img");
20
- return e.src = i, e.width = t.width, e.height = t.height, e.style.display = "inline-block", e.style.width = `${t.width}px`, e.style.height = `${t.height}px`, e;
17
+ if (e.tagName === "CANVAS") {
18
+ const t = e.toDataURL(), i = document.createElement("img");
19
+ return i.src = t, i.width = e.width, i.height = e.height, i.style.display = "inline-block", i.style.width = `${e.width}px`, i.style.height = `${e.height}px`, i;
21
20
  }
22
- if (t.nodeType === Node.TEXT_NODE) {
23
- if ((s = t.parentElement) != null && s.shadowRoot) {
24
- const i = t.parentElement.tagName.toLowerCase();
25
- if (customElements.get(i)) return null;
21
+ if (e.nodeType === Node.TEXT_NODE) {
22
+ if (e.parentElement?.shadowRoot) {
23
+ const t = e.parentElement.tagName.toLowerCase();
24
+ if (customElements.get(t)) return null;
26
25
  }
27
- return t.cloneNode(!0);
26
+ return e.cloneNode(!0);
28
27
  }
29
- if (t.nodeType !== Node.ELEMENT_NODE) return t.cloneNode(!0);
30
- const r = t.cloneNode(!1);
31
- c.set(r, t), h(t, r, a, l, o);
32
- const d = document.createDocumentFragment();
33
- if (t.childNodes.forEach((i) => {
34
- const e = f(
35
- i,
36
- a,
37
- l,
28
+ if (e.nodeType !== Node.ELEMENT_NODE) return e.cloneNode(!0);
29
+ const l = e.cloneNode(!1);
30
+ n.set(l, e), e instanceof HTMLInputElement ? (l.value = e.value, l.setAttribute("value", e.value), e.checked !== void 0 && (l.checked = e.checked, e.checked && l.setAttribute("checked", ""))) : e instanceof HTMLTextAreaElement ? (l.value = e.value, l.textContent = e.value) : e instanceof HTMLSelectElement && (l.value = e.value, Array.from(l.options).forEach((t) => {
31
+ t.value === e.value ? t.setAttribute("selected", "") : t.removeAttribute("selected");
32
+ })), f(e, l, c, r, s);
33
+ const o = document.createDocumentFragment();
34
+ if (e.childNodes.forEach((t) => {
35
+ const i = h(
36
+ t,
38
37
  c,
39
- o
38
+ r,
39
+ n,
40
+ s
40
41
  );
41
- e && d.appendChild(e);
42
- }), r.appendChild(d), t.shadowRoot) {
43
- const i = Array.from(t.shadowRoot.children).filter((n) => n.tagName !== "STYLE").map((n) => f(n, a, l, c)).filter(Boolean), e = document.createDocumentFragment();
44
- i.forEach((n) => e.appendChild(n)), r.appendChild(e);
42
+ i && o.appendChild(i);
43
+ }), l.appendChild(o), e.shadowRoot) {
44
+ const t = Array.from(e.shadowRoot.children).filter((a) => a.tagName !== "STYLE").map((a) => h(a, c, r, n)).filter(Boolean), i = document.createDocumentFragment();
45
+ t.forEach((a) => i.appendChild(a)), l.appendChild(i);
45
46
  }
46
- return r;
47
+ return l;
47
48
  }
48
49
  export {
49
- f as deepClone
50
+ h as deepClone
50
51
  };
@@ -1,36 +1,35 @@
1
- import { inlinePseudoElements as h } from "../modules/pseudo.js";
2
- import { generateCSSClasses as g } from "../utils/cssTools.js";
3
- import { deepClone as C } from "./clone.js";
4
- async function b(f, r = !1, m = !1) {
5
- var p;
1
+ import { inlinePseudoElements as m } from "../modules/pseudo.js";
2
+ import { generateCSSClasses as h } from "../utils/cssTools.js";
3
+ import { deepClone as g } from "./clone.js";
4
+ async function S(f, r = !1, p = !1) {
6
5
  const l = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new Map();
7
6
  let c;
8
7
  try {
9
- c = C(f, l, i, d, r);
8
+ c = g(f, l, i, d, r);
10
9
  } catch (e) {
11
10
  throw console.warn("deepClone failed:", e), e;
12
11
  }
13
12
  try {
14
- await h(
13
+ await m(
15
14
  f,
16
15
  c,
17
16
  l,
18
17
  i,
19
18
  r,
20
- m
19
+ p
21
20
  );
22
21
  } catch (e) {
23
22
  console.warn("inlinePseudoElements failed:", e);
24
23
  }
25
24
  let y = "";
26
25
  if (r) {
27
- const e = g(l);
26
+ const e = h(l);
28
27
  y = Array.from(e.entries()).map(([t, n]) => `.${n}{${t}}`).join("");
29
28
  for (const [t, n] of l.entries()) {
30
29
  if (t.tagName === "STYLE") continue;
31
30
  const s = e.get(n);
32
31
  s && t.classList.add(s);
33
- const a = (p = t.style) == null ? void 0 : p.backgroundImage;
32
+ const a = t.style?.backgroundImage;
34
33
  t.removeAttribute("style"), a && a !== "none" && (t.style.backgroundImage = a);
35
34
  }
36
35
  } else
@@ -49,5 +48,5 @@ async function b(f, r = !1, m = !1) {
49
48
  return { clone: c, classCSS: y, styleCache: i };
50
49
  }
51
50
  export {
52
- b as prepareClone
51
+ S as prepareClone
53
52
  };
@@ -1,27 +1,50 @@
1
- import { bgCache as a } from "../core/cache.js";
2
- import { getStyle as f, fetchImage as m } from "../utils/helpers.js";
3
- async function p(u, d, o) {
4
- const c = [[u, d]];
5
- for (; c.length; ) {
6
- const [t, l] = c.shift(), i = o.get(t) || f(t);
7
- o.has(t) || o.set(t, i);
8
- const s = i.getPropertyValue("background-image");
9
- if (s && s.includes("url(")) {
10
- const e = s.match(/url\(["']?([^"')]+)["']?\)/);
11
- if (e != null && e[1])
12
- try {
13
- const n = e[1];
14
- let r;
15
- a.has(n) ? r = a.get(n) : (r = await m(n), a.set(n, r)), l.style.backgroundImage = `url(${r})`;
16
- } catch {
17
- l.style.backgroundImage = "none";
18
- }
1
+ import { bgCache as u } from "../core/cache.js";
2
+ import { getStyle as C, extractURL as A, fetchImage as B } from "../utils/helpers.js";
3
+ async function O(k, w, c, h = {}) {
4
+ const o = [[k, w]];
5
+ for (; o.length; ) {
6
+ const [e, i] = o.shift(), l = c.get(e) || C(e);
7
+ c.has(e) || c.set(e, l);
8
+ const g = l.getPropertyValue("background-image"), s = l.getPropertyValue("background-color");
9
+ if (!g || g === "none") {
10
+ const r = Array.from(e.children), a = Array.from(i.children);
11
+ for (let t = 0; t < Math.min(r.length, a.length); t++)
12
+ o.push([r[t], a[t]]);
13
+ continue;
19
14
  }
20
- const g = Array.from(t.children), h = Array.from(l.children);
21
- for (let e = 0; e < Math.min(g.length, h.length); e++)
22
- c.push([g[e], h[e]]);
15
+ const U = g.split(/,(?=(?:[^()]*\([^()]*\))*[^()]*$)/).map((r) => r.trim()), m = await Promise.all(
16
+ U.map(async (r) => {
17
+ const a = r.startsWith("url("), t = /^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(r);
18
+ if (a) {
19
+ const d = A(r);
20
+ if (!d) return r;
21
+ try {
22
+ const n = encodeURI(d);
23
+ if (u.has(n))
24
+ return `url(${u.get(n)})`;
25
+ {
26
+ const y = h.crossOrigin ? h.crossOrigin(n) : "anonymous", b = await B(n, 3e3, y);
27
+ return u.set(n, b), `url(${b})`;
28
+ }
29
+ } catch (n) {
30
+ return console.warn(
31
+ "[snapdom] Failed to inline background-image:",
32
+ d,
33
+ n
34
+ ), r;
35
+ }
36
+ }
37
+ return r;
38
+ })
39
+ );
40
+ m.some(
41
+ (r) => r && r !== "none" && !/^url\(undefined\)/.test(r)
42
+ ) && (i.style.backgroundImage = m.join(", ")), s && s !== "transparent" && s !== "rgba(0, 0, 0, 0)" && (i.style.backgroundColor = s);
43
+ const f = Array.from(e.children), p = Array.from(i.children);
44
+ for (let r = 0; r < Math.min(f.length, p.length); r++)
45
+ o.push([f[r], p[r]]);
23
46
  }
24
47
  }
25
48
  export {
26
- p as inlineBackgroundImages
49
+ O as inlineBackgroundImages
27
50
  };