@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,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,73 +1,84 @@
1
- import { inlineBackgroundImages as $ } from "../modules/background.js";
2
- import { embedCustomFonts as B } from "../modules/fonts.js";
3
- import { inlineImages as E } from "../modules/images.js";
4
- import { collectUsedTagNames as F, generateDedupedBaseCSS as I } from "../utils/cssTools.js";
5
- import { idle as i, isSafari as P } from "../utils/helpers.js";
6
- import { baseCSSCache as g } from "./cache.js";
7
- import { prepareClone as z } from "./prepare.js";
8
- async function L(a, y = {}) {
9
- if (!a) throw new Error("Element cannot be null or undefined");
1
+ import { baseCSSCache as S } from "./cache.js";
2
+ import { inlineBackgroundImages as P } from "../modules/background.js";
3
+ import { embedCustomFonts as z } from "../modules/fonts.js";
4
+ import { inlineImages as H } from "../modules/images.js";
5
+ import { collectUsedTagNames as A, generateDedupedBaseCSS as D } from "../utils/cssTools.js";
6
+ import { idle as l, isSafari as R } from "../utils/helpers.js";
7
+ import { prepareClone as U } from "./prepare.js";
8
+ async function Q(r, n = {}) {
9
+ if (!r) throw new Error("Element cannot be null or undefined");
10
+ if (!(r instanceof Element))
11
+ throw new Error("captureDOM: Only Element nodes are supported");
10
12
  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(
18
- a,
19
- w,
20
- l
21
- ), await new Promise((e) => {
22
- i(
13
+ compress: b = !0,
14
+ embedFonts: h = !1,
15
+ fast: o = !0,
16
+ scale: f = 1
17
+ } = n;
18
+ let t, y, v, C = "", m = "", $, x;
19
+ if ({ clone: t, classCSS: y, styleCache: v } = await U(
20
+ r,
21
+ b,
22
+ h
23
+ ), await new Promise((s) => {
24
+ l(
23
25
  async () => {
24
- await E(t), e();
26
+ await H(t, n), s();
25
27
  },
26
- { fast: s }
28
+ { fast: o }
27
29
  );
28
- }), await new Promise((e) => {
29
- i(
30
+ }), await new Promise((s) => {
31
+ l(
30
32
  async () => {
31
- await $(a, t, p), e();
33
+ await P(r, t, v, n), s();
32
34
  },
33
- { fast: s }
35
+ { fast: o }
34
36
  );
35
- }), l && await new Promise((e) => {
36
- i(
37
+ }), h && await new Promise((s) => {
38
+ l(
37
39
  async () => {
38
- h = await B({ ignoreIconFonts: !l }), e();
40
+ C = await z({ ignoreIconFonts: !h }), s();
39
41
  },
40
- { fast: s }
42
+ { fast: o }
41
43
  );
42
- }), w) {
43
- const e = F(t).sort(), o = e.join(",");
44
- g.has(o) ? r = g.get(o) : await new Promise((c) => {
45
- i(
44
+ }), b) {
45
+ const s = A(t).sort(), i = s.join(",");
46
+ S.has(i) ? m = S.get(i) : await new Promise((e) => {
47
+ l(
46
48
  () => {
47
- r = I(e), g.set(o, r), c();
49
+ m = D(s), S.set(i, m), e();
48
50
  },
49
- { fast: s }
51
+ { fast: o }
50
52
  );
51
53
  });
52
54
  }
53
- await new Promise((e) => {
54
- i(
55
+ await new Promise((s) => {
56
+ l(
55
57
  () => {
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");
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);
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();
58
+ const i = r.getBoundingClientRect();
59
+ let e = i.width, a = i.height;
60
+ const d = Number.isFinite(n.width), u = Number.isFinite(n.height), p = typeof f == "number" && f !== 1;
61
+ if (!p) {
62
+ const g = i.width / i.height;
63
+ d && u ? (e = n.width, a = n.height) : d ? (e = n.width, a = e / g) : u && (a = n.height, e = a * g);
64
+ }
65
+ if (e = Math.ceil(e), a = Math.ceil(a), t.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), t.style.transformOrigin = "top left", !p && (d || u)) {
66
+ const g = i.width, B = i.height, I = e / g, M = a / B, N = t.style.transform || "", O = `scale(${I}, ${M})`;
67
+ t.style.transform = `${O} ${N}`.trim();
68
+ } else p && R() && (t.style.scale = `${f}`);
69
+ const E = "http://www.w3.org/2000/svg", c = document.createElementNS(E, "foreignObject");
70
+ c.setAttribute("width", "100%"), c.setAttribute("height", "100%");
71
+ const F = document.createElement("style");
72
+ F.textContent = m + C + "svg{overflow:visible;}" + y, c.appendChild(F), c.appendChild(t);
73
+ const T = new XMLSerializer().serializeToString(c);
74
+ x = `<svg xmlns="${E}" width="${e}" height="${a}" viewBox="0 0 ${e} ${a}">` + T + "</svg>", $ = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(x)}`, s();
64
75
  },
65
- { fast: s }
76
+ { fast: o }
66
77
  );
67
78
  });
68
- const m = document.getElementById("snapdom-sandbox");
69
- return m && m.style.position === "absolute" && m.remove(), u;
79
+ const w = document.getElementById("snapdom-sandbox");
80
+ return w && w.style.position === "absolute" && w.remove(), $;
70
81
  }
71
82
  export {
72
- L as captureDOM
83
+ Q as captureDOM
73
84
  };
@@ -1,49 +1,50 @@
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 o } from "../modules/styles.js";
2
+ function f(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), o(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.style.width || `${e.width}px`, i.style.height = e.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
+ })), o(e, l, c, r, s);
33
+ const h = document.createDocumentFragment();
34
+ if (e.childNodes.forEach((t) => {
35
+ const i = f(
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 && h.appendChild(i);
43
+ }), l.appendChild(h), e.shadowRoot) {
44
+ const t = Array.from(e.shadowRoot.children).filter((a) => a.tagName !== "STYLE").map((a) => f(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
50
  f as deepClone
@@ -1,53 +1,59 @@
1
- import { inlinePseudoElements as h } from "../modules/pseudo.js";
1
+ import { inlinePseudoElements as m } from "../modules/pseudo.js";
2
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;
6
- const l = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new Map();
7
- let c;
3
+ import { stripTranslate as u } from "../utils/helpers.js";
4
+ import { deepClone as h } from "./clone.js";
5
+ async function k(s, f = !1, p = !1) {
6
+ const a = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new Map();
7
+ let t;
8
8
  try {
9
- c = C(f, l, i, d, r);
9
+ t = h(s, a, r, y, f);
10
10
  } catch (e) {
11
11
  throw console.warn("deepClone failed:", e), e;
12
12
  }
13
13
  try {
14
- await h(
15
- f,
16
- c,
17
- l,
18
- i,
14
+ await m(
15
+ s,
16
+ t,
17
+ a,
19
18
  r,
20
- m
19
+ f,
20
+ p
21
21
  );
22
22
  } catch (e) {
23
23
  console.warn("inlinePseudoElements failed:", e);
24
24
  }
25
- let y = "";
26
- if (r) {
27
- const e = g(l);
28
- y = Array.from(e.entries()).map(([t, n]) => `.${n}{${t}}`).join("");
29
- for (const [t, n] of l.entries()) {
30
- if (t.tagName === "STYLE") continue;
31
- const s = e.get(n);
32
- s && t.classList.add(s);
33
- const a = (p = t.style) == null ? void 0 : p.backgroundImage;
34
- t.removeAttribute("style"), a && a !== "none" && (t.style.backgroundImage = a);
25
+ let d = "";
26
+ if (f) {
27
+ const e = g(a);
28
+ d = Array.from(e.entries()).map(([o, n]) => `.${n}{${o}}`).join("");
29
+ for (const [o, n] of a.entries()) {
30
+ if (o.tagName === "STYLE") continue;
31
+ const i = e.get(n);
32
+ i && o.classList.add(i);
33
+ const c = o.style?.backgroundImage;
34
+ o.removeAttribute("style"), c && c !== "none" && (o.style.backgroundImage = c);
35
35
  }
36
36
  } else
37
- for (const [e, t] of l.entries())
38
- e.tagName !== "STYLE" && e.setAttribute("style", t.replace(/;/g, "; "));
39
- for (const [e, t] of d.entries()) {
40
- const n = t.scrollLeft, s = t.scrollTop;
41
- if ((n || s) && e instanceof HTMLElement) {
37
+ for (const [e, o] of a.entries())
38
+ e.tagName !== "STYLE" && e.setAttribute("style", o.replace(/;/g, "; "));
39
+ for (const [e, o] of y.entries()) {
40
+ const n = o.scrollLeft, i = o.scrollTop;
41
+ if ((n || i) && e instanceof HTMLElement) {
42
42
  e.style.overflow = "hidden", e.style.scrollbarWidth = "none", e.style.msOverflowStyle = "none";
43
- const o = document.createElement("div");
44
- for (o.style.transform = `translate(${-n}px, ${-s}px)`, o.style.willChange = "transform", o.style.display = "inline-block", o.style.width = "100%"; e.firstChild; )
45
- o.appendChild(e.firstChild);
46
- e.appendChild(o);
43
+ const l = document.createElement("div");
44
+ for (l.style.transform = `translate(${-n}px, ${-i}px)`, l.style.willChange = "transform", l.style.display = "inline-block", l.style.width = "100%"; e.firstChild; )
45
+ l.appendChild(e.firstChild);
46
+ e.appendChild(l);
47
47
  }
48
48
  }
49
- return { clone: c, classCSS: y, styleCache: i };
49
+ if (s === y.get(t)) {
50
+ const e = r.get(s) || window.getComputedStyle(s);
51
+ r.set(s, e);
52
+ const o = u(e.transform);
53
+ t.style.margin = "0", t.style.position = "static", t.style.top = "auto", t.style.left = "auto", t.style.right = "auto", t.style.bottom = "auto", t.style.zIndex = "auto", t.style.float = "none", t.style.clear = "none", t.style.transform = o || "";
54
+ }
55
+ return { clone: t, classCSS: d, styleCache: r };
50
56
  }
51
57
  export {
52
- b as prepareClone
58
+ k as prepareClone
53
59
  };
@@ -1,27 +1,25 @@
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 { getStyle as b, splitBackgroundImage as p, inlineSingleBackgroundEntry as k } from "../utils/helpers.js";
2
+ async function B(u, m, l, f = {}) {
3
+ const r = [[u, m]];
4
+ for (; r.length; ) {
5
+ const [e, o] = r.shift(), s = l.get(e) || b(e);
6
+ l.has(e) || l.set(e, s);
7
+ const c = s.getPropertyValue("background-image"), t = s.getPropertyValue("background-color");
8
+ if (!c || c === "none") {
9
+ const n = Array.from(e.children), h = Array.from(o.children);
10
+ for (let i = 0; i < Math.min(n.length, h.length); i++)
11
+ r.push([n[i], h[i]]);
12
+ continue;
19
13
  }
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]]);
14
+ const y = p(c), a = await Promise.all(
15
+ y.map((n) => k(n, f))
16
+ );
17
+ a.some((n) => n && n !== "none" && !/^url\(undefined\)/.test(n)) && (o.style.backgroundImage = a.join(", ")), t && t !== "transparent" && t !== "rgba(0, 0, 0, 0)" && (o.style.backgroundColor = t);
18
+ const g = Array.from(e.children), d = Array.from(o.children);
19
+ for (let n = 0; n < Math.min(g.length, d.length); n++)
20
+ r.push([g[n], d[n]]);
23
21
  }
24
22
  }
25
23
  export {
26
- p as inlineBackgroundImages
24
+ B as inlineBackgroundImages
27
25
  };