@unicom-cloud/utils 0.1.5 → 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.
@@ -0,0 +1,56 @@
1
+ function m(t) {
2
+ if (!t) return null;
3
+ const e = {
4
+ type: "",
5
+ parameters: {}
6
+ }, o = t.match(/^([^;]+)/);
7
+ o && (e.type = o[1].trim());
8
+ const s = t.matchAll(
9
+ /;\s*([^=]+)=(?:"([^"]*)"|([^;]*))/g
10
+ );
11
+ for (const r of s) {
12
+ const n = r[1].trim().toLowerCase(), i = r[2] || r[3];
13
+ if (n.endsWith("*")) {
14
+ const a = p(i);
15
+ e.parameters[n] = a;
16
+ const c = n.slice(0, -1);
17
+ e.parameters[c] || (e.parameters[c] = a);
18
+ } else e.parameters[n] || (e.parameters[n] = i);
19
+ }
20
+ return e;
21
+ }
22
+ function p(t) {
23
+ const e = t.match(/^([^']*)'[^']*'(.*)$/);
24
+ if (!e) return t;
25
+ const [o, s, r] = e;
26
+ try {
27
+ const n = r.replace(
28
+ /%([0-9A-Fa-f]{2})/g,
29
+ (i, a) => String.fromCharCode(parseInt(a, 16))
30
+ );
31
+ return s && s.toLowerCase() !== "utf-8", n;
32
+ } catch (n) {
33
+ return console.warn("Failed to decode RFC 5987 value:", t, n), t;
34
+ }
35
+ }
36
+ function f(t) {
37
+ let e = t?.["content-disposition"];
38
+ if (e)
39
+ return m(e);
40
+ }
41
+ function d(t) {
42
+ const e = f(t);
43
+ if (e)
44
+ return e.parameters;
45
+ }
46
+ function l(t) {
47
+ const e = d(t);
48
+ if (e)
49
+ return e["filename*"] || e.filename;
50
+ }
51
+ export {
52
+ m as default,
53
+ f as getContentDispositionFromHeader,
54
+ l as getContentDispositionParametersFilenameFromHeader,
55
+ d as getContentDispositionParametersFromHeader
56
+ };
package/index.js CHANGED
@@ -1,47 +1,52 @@
1
- import * as o from "./is/index.js";
2
- import * as e from "./math/index.js";
3
- import * as r from "./tree/index.js";
4
- import * as t from "./turbo-stream/index.js";
1
+ import * as e from "./is/index.js";
2
+ import * as o from "./math/index.js";
3
+ import * as t from "./tree/index.js";
4
+ import * as r from "./turbo-stream/index.js";
5
5
  import * as a from "./url-toolkit/index.js";
6
6
  import { default as p } from "./case-name/index.js";
7
7
  import { default as l } from "./class-name/index.js";
8
- import { default as n } from "./clipboard-copy/index.js";
9
- import { splitCookiesString as c } from "./cookie/index.js";
10
- import { default as b } from "./decimal/decimal.js";
11
- import { default as k } from "./event-emitter/index.js";
12
- import { fileToURL as S } from "./file/fileToURL.js";
13
- import { saveAs as C } from "./file/saveAs.js";
8
+ import { default as d } from "./clipboard-copy/index.js";
9
+ import { default as c, getContentDispositionFromHeader as C, getContentDispositionParametersFilenameFromHeader as _, getContentDispositionParametersFromHeader as b } from "./content-disposition/index.js";
10
+ import { splitCookiesString as h } from "./cookie/index.js";
11
+ import { default as z } from "./decimal/decimal.js";
12
+ import { default as F } from "./event-emitter/index.js";
13
+ import { fileToURL as v } from "./file/fileToURL.js";
14
+ import { saveAs as T } from "./file/saveAs.js";
14
15
  import * as s from "./filesize/src/constants.js";
15
- import { filesize as y, partial as N } from "./filesize/src/filesize.js";
16
- import { default as j } from "./invariant/index.js";
17
- import { default as E } from "./md5/index.js";
18
- import { default as L } from "./normalize-wheel/index.js";
19
- import { default as U } from "./nzh/nzh.js";
20
- import { default as q } from "./objectKeysSort.js";
21
- import { default as B } from "./screenfull/index.js";
22
- import * as m from "./cookie/src/index.js";
16
+ import { filesize as N, partial as P } from "./filesize/src/filesize.js";
17
+ import { default as A } from "./invariant/index.js";
18
+ import { default as K } from "./md5/index.js";
19
+ import { default as R } from "./normalize-wheel/index.js";
20
+ import { default as W } from "./nzh/nzh.js";
21
+ import { default as w } from "./objectKeysSort.js";
22
+ import { default as G } from "./screenfull/index.js";
23
+ import * as i from "./cookie/src/index.js";
23
24
  export {
24
25
  p as caseName,
25
26
  l as className,
26
- n as clipboardCopy,
27
- m as cookie,
28
- b as decimal,
29
- k as eventEmitter,
30
- S as fileToURL,
31
- y as filesize,
27
+ d as clipboardCopy,
28
+ c as contentDisposition,
29
+ i as cookie,
30
+ z as decimal,
31
+ F as eventEmitter,
32
+ v as fileToURL,
33
+ N as filesize,
32
34
  s as filesizeConstants,
33
- j as invariant,
34
- o as is,
35
- e as math,
36
- E as md5,
37
- L as normalizeWheel,
38
- U as nzh,
39
- q as objectKeysSort,
40
- N as partial,
41
- C as saveAs,
42
- B as screenfull,
43
- c as splitCookiesString,
44
- r as tree,
45
- t as turboStream,
35
+ C as getContentDispositionFromHeader,
36
+ _ as getContentDispositionParametersFilenameFromHeader,
37
+ b as getContentDispositionParametersFromHeader,
38
+ A as invariant,
39
+ e as is,
40
+ o as math,
41
+ K as md5,
42
+ R as normalizeWheel,
43
+ W as nzh,
44
+ w as objectKeysSort,
45
+ P as partial,
46
+ T as saveAs,
47
+ G as screenfull,
48
+ h as splitCookiesString,
49
+ t as tree,
50
+ r as turboStream,
46
51
  a as urlToolkit
47
52
  };
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@unicom-cloud/utils","version":"0.1.5","dependencies":{},"peerDependencies":{"lodash":"^4.17.21"},"main":"./index.js","type":"module","types":"types/*","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
1
+ {"name":"@unicom-cloud/utils","version":"0.1.10","dependencies":{},"peerDependencies":{"lodash":"^4.17.21"},"main":"./index.js","type":"module","types":"types/*","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
@@ -1,43 +1,47 @@
1
- import { imageCache as n, bgCache as m, resourceCache as y, baseCSSCache as C, computedStyleCache as d } from "../core/cache.js";
2
- import { embedCustomFonts as S } from "../modules/fonts.js";
3
- import { precacheCommonTags as b } from "../utils/cssTools.js";
4
- import { fetchImage as u, extractURL as A } from "../utils/helpers.js";
5
- async function I(c = document, h = {}) {
1
+ import { imageCache as i, bgCache as u, resourceCache as h, baseCSSCache as p } from "../core/cache.js";
2
+ import { embedCustomFonts as y } from "../modules/fonts.js";
3
+ import { precacheCommonTags as d } from "../utils/cssTools.js";
4
+ import { fetchImage as C, getStyle as S, splitBackgroundImage as b, inlineSingleBackgroundEntry as A } from "../utils/helpers.js";
5
+ async function w(o = document, f = {}) {
6
6
  const {
7
- embedFonts: i = !0,
7
+ embedFonts: a = !0,
8
8
  reset: g = !1,
9
- crossOrigin: o
10
- } = h;
9
+ crossOrigin: s
10
+ } = f;
11
11
  if (g) {
12
- n.clear(), m.clear(), y.clear(), C.clear(), d.clear();
12
+ i.clear(), u.clear(), h.clear(), p.clear();
13
13
  return;
14
14
  }
15
- await document.fonts.ready, b();
16
- let l = [], f = [];
17
- c?.querySelectorAll && (l = Array.from(c.querySelectorAll("img[src]")), f = Array.from(c.querySelectorAll("*")));
15
+ await document.fonts.ready, d();
16
+ let l = [], m = [];
17
+ o?.querySelectorAll && (l = Array.from(o.querySelectorAll("img[src]")), m = Array.from(o.querySelectorAll("*")));
18
18
  const t = [];
19
- for (const s of l) {
20
- const r = s.src;
21
- if (!n.has(r)) {
22
- const e = o ? o(r) : "anonymous";
19
+ for (const c of l) {
20
+ const r = c.src;
21
+ if (!i.has(r)) {
22
+ const n = s ? s(r) : "anonymous";
23
23
  t.push(
24
- u(r, 3e3, e).then((a) => n.set(r, a)).catch(() => {
24
+ C(r, 3e3, n).then((e) => i.set(r, e)).catch(() => {
25
25
  })
26
26
  );
27
27
  }
28
28
  }
29
- for (const s of f) {
30
- const r = getComputedStyle(s).backgroundImage, e = A(r);
31
- if (e && !m.has(e)) {
32
- const a = o ? o(e) : "anonymous";
33
- t.push(
34
- u(e, 3e3, a).then((p) => m.set(e, p)).catch(() => {
35
- })
36
- );
29
+ for (const c of m) {
30
+ const r = S(c).backgroundImage;
31
+ if (r && r !== "none") {
32
+ const n = b(r);
33
+ for (const e of n)
34
+ e.startsWith("url(") && t.push(
35
+ A(e, {
36
+ crossOrigin: s,
37
+ skipInline: !0
38
+ }).catch(() => {
39
+ })
40
+ );
37
41
  }
38
42
  }
39
- i && await S({ ignoreIconFonts: !i, preCached: !0 }), await Promise.all(t);
43
+ a && await y({ ignoreIconFonts: !a, preCached: !0 }), await Promise.all(t);
40
44
  }
41
45
  export {
42
- I as preCache
46
+ w as preCache
43
47
  };
@@ -1,73 +1,84 @@
1
- import { baseCSSCache as w } from "./cache.js";
2
- import { inlineBackgroundImages as $ } from "../modules/background.js";
3
- import { embedCustomFonts as B } from "../modules/fonts.js";
4
- import { inlineImages as E } from "../modules/images.js";
5
- import { collectUsedTagNames as F, generateDedupedBaseCSS as I } from "../utils/cssTools.js";
6
- import { idle as i, isSafari as P } from "../utils/helpers.js";
7
- import { prepareClone as z } from "./prepare.js";
8
- async function L(a, l = {}) {
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: d = !0,
12
- embedFonts: m = !1,
13
+ compress: b = !0,
14
+ embedFonts: h = !1,
13
15
  fast: o = !0,
14
16
  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
- a,
19
- d,
20
- m
21
- ), await new Promise((e) => {
22
- i(
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, l), e();
26
+ await H(t, n), s();
25
27
  },
26
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, l), e();
33
+ await P(r, t, v, n), s();
32
34
  },
33
35
  { fast: o }
34
36
  );
35
- }), m && await new Promise((e) => {
36
- i(
37
+ }), h && await new Promise((s) => {
38
+ l(
37
39
  async () => {
38
- u = await B({ ignoreIconFonts: !m }), e();
40
+ C = await z({ ignoreIconFonts: !h }), s();
39
41
  },
40
42
  { fast: o }
41
43
  );
42
- }), d) {
43
- const e = F(t).sort(), s = e.join(",");
44
- w.has(s) ? r = w.get(s) : 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), w.set(s, r), c();
49
+ m = D(s), S.set(i, m), e();
48
50
  },
49
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 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
- n.setAttribute("width", "100%"), n.setAttribute("height", "100%");
60
- const y = document.createElement("style");
61
- y.textContent = r + u + "svg{overflow:visible;}" + h, n.appendChild(y), n.appendChild(t);
62
- const x = new XMLSerializer().serializeToString(n);
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();
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
76
  { fast: o }
66
77
  );
67
78
  });
68
- const g = document.getElementById("snapdom-sandbox");
69
- return g && g.style.position === "absolute" && g.remove(), S;
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,5 +1,5 @@
1
- import { inlineAllStyles as f } from "../modules/styles.js";
2
- function h(e, c, r, n, s) {
1
+ import { inlineAllStyles as o } from "../modules/styles.js";
2
+ function f(e, c, r, n, s) {
3
3
  if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "exclude") {
4
4
  const t = document.createElement("div"), i = e.getBoundingClientRect();
5
5
  return t.style.cssText = `display: inline-block; width: ${i.width}px; height: ${i.height}px; visibility: hidden;`, t;
@@ -10,13 +10,13 @@ function h(e, c, r, n, s) {
10
10
  }
11
11
  if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "placeholder") {
12
12
  const t = e.cloneNode(!1);
13
- n.set(t, e), f(e, t, c, r, s);
13
+ n.set(t, e), o(e, t, c, r, s);
14
14
  const i = document.createElement("div");
15
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;
16
16
  }
17
17
  if (e.tagName === "CANVAS") {
18
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;
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;
20
20
  }
21
21
  if (e.nodeType === Node.TEXT_NODE) {
22
22
  if (e.parentElement?.shadowRoot) {
@@ -29,23 +29,23 @@ function h(e, c, r, n, s) {
29
29
  const l = e.cloneNode(!1);
30
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
31
  t.value === e.value ? t.setAttribute("selected", "") : t.removeAttribute("selected");
32
- })), f(e, l, c, r, s);
33
- const o = document.createDocumentFragment();
32
+ })), o(e, l, c, r, s);
33
+ const h = document.createDocumentFragment();
34
34
  if (e.childNodes.forEach((t) => {
35
- const i = h(
35
+ const i = f(
36
36
  t,
37
37
  c,
38
38
  r,
39
39
  n,
40
40
  s
41
41
  );
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();
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
45
  t.forEach((a) => i.appendChild(a)), l.appendChild(i);
46
46
  }
47
47
  return l;
48
48
  }
49
49
  export {
50
- h as deepClone
50
+ f as deepClone
51
51
  };
@@ -1,52 +1,59 @@
1
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) {
5
- const l = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new Map();
6
- let c;
2
+ import { generateCSSClasses as g } from "../utils/cssTools.js";
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;
7
8
  try {
8
- c = g(f, l, i, d, r);
9
+ t = h(s, a, r, y, f);
9
10
  } catch (e) {
10
11
  throw console.warn("deepClone failed:", e), e;
11
12
  }
12
13
  try {
13
14
  await m(
14
- f,
15
- c,
16
- l,
17
- i,
15
+ s,
16
+ t,
17
+ a,
18
18
  r,
19
+ f,
19
20
  p
20
21
  );
21
22
  } catch (e) {
22
23
  console.warn("inlinePseudoElements failed:", e);
23
24
  }
24
- let y = "";
25
- if (r) {
26
- const e = h(l);
27
- y = Array.from(e.entries()).map(([t, n]) => `.${n}{${t}}`).join("");
28
- for (const [t, n] of l.entries()) {
29
- if (t.tagName === "STYLE") continue;
30
- const s = e.get(n);
31
- s && t.classList.add(s);
32
- const a = t.style?.backgroundImage;
33
- 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);
34
35
  }
35
36
  } else
36
- for (const [e, t] of l.entries())
37
- e.tagName !== "STYLE" && e.setAttribute("style", t.replace(/;/g, "; "));
38
- for (const [e, t] of d.entries()) {
39
- const n = t.scrollLeft, s = t.scrollTop;
40
- 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) {
41
42
  e.style.overflow = "hidden", e.style.scrollbarWidth = "none", e.style.msOverflowStyle = "none";
42
- const o = document.createElement("div");
43
- for (o.style.transform = `translate(${-n}px, ${-s}px)`, o.style.willChange = "transform", o.style.display = "inline-block", o.style.width = "100%"; e.firstChild; )
44
- o.appendChild(e.firstChild);
45
- 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);
46
47
  }
47
48
  }
48
- 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 };
49
56
  }
50
57
  export {
51
- S as prepareClone
58
+ k as prepareClone
52
59
  };
@@ -1,50 +1,25 @@
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]]);
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]]);
13
12
  continue;
14
13
  }
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
- })
14
+ const y = p(c), a = await Promise.all(
15
+ y.map((n) => k(n, f))
39
16
  );
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]]);
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]]);
46
21
  }
47
22
  }
48
23
  export {
49
- O as inlineBackgroundImages
24
+ B as inlineBackgroundImages
50
25
  };
@@ -1,93 +1,92 @@
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;
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
6
  for (const n of ["::before", "::after", "::first-letter"])
7
7
  try {
8
- const e = A(l, n);
9
- if (!e) continue;
8
+ const t = U(l, n);
9
+ if (!t || typeof t[Symbol.iterator] != "function") continue;
10
10
  if (n === "::first-letter") {
11
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
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
15
15
  );
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);
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
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);
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
25
  continue;
26
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");
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
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(
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
34
  a
35
- ), i = D(E);
36
- if (!b && c && i.length === 1) {
37
- const t = document.createElement("img");
38
- t.src = await $(
39
- i,
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
40
  a,
41
- h,
42
- V,
43
- m
44
- ), t.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(t);
45
- } else if (i.startsWith("url(")) {
46
- const t = B(i);
47
- if (t && t.trim() !== "")
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() !== "")
48
48
  try {
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) {
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);
51
+ } catch (c) {
52
52
  console.error(
53
53
  `[snapdom] Error in pseudo ${n} for`,
54
54
  l,
55
- s
55
+ c
56
56
  );
57
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
69
- );
70
- }
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);
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);
74
73
  }
75
- } catch (e) {
76
- console.warn(`[snapdom] Failed to capture ${n} for`, l, e);
74
+ } catch (t) {
75
+ console.warn(`[snapdom] Failed to capture ${n} for`, l, t);
77
76
  }
78
- const x = Array.from(l.children), w = Array.from(r.children).filter(
77
+ const P = Array.from(l.children), k = Array.from(i.children).filter(
79
78
  (n) => !n.dataset.snapdomPseudo
80
79
  );
81
- for (let n = 0; n < Math.min(x.length, w.length); n++)
82
- await L(
83
- x[n],
84
- w[n],
85
- p,
86
- F,
80
+ for (let n = 0; n < Math.min(P.length, k.length); n++)
81
+ await R(
82
+ P[n],
83
+ k[n],
87
84
  g,
88
- b
85
+ F,
86
+ h,
87
+ w
89
88
  );
90
89
  }
91
90
  export {
92
- L as inlinePseudoElements
91
+ R as inlinePseudoElements
93
92
  };
@@ -1,35 +1,52 @@
1
- import { imageCache as c, computedStyleCache as l } from "../core/cache.js";
2
- function h(t, { fast: n = !1 } = {}) {
3
- if (n) return t();
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 } = {}) {
20
+ if (e) return t();
4
21
  "requestIdleCallback" in window ? requestIdleCallback(t, { timeout: 50 }) : setTimeout(t, 1);
5
22
  }
6
- function f(t, n = null) {
23
+ function x(t, e = null) {
7
24
  if (!(t instanceof Element))
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);
25
+ return window.getComputedStyle(t, e);
26
+ let n = m.get(t);
27
+ if (n || (n = /* @__PURE__ */ new Map(), m.set(t, n)), !n.has(e)) {
28
+ const a = window.getComputedStyle(t, e);
29
+ n.set(e, a);
13
30
  }
14
- return e.get(n);
31
+ return n.get(e);
15
32
  }
16
- function g(t) {
17
- let n = t.replace(/^['"]|['"]$/g, "");
18
- if (n.startsWith("\\"))
33
+ function C(t) {
34
+ let e = t.replace(/^['"]|['"]$/g, "");
35
+ if (e.startsWith("\\"))
19
36
  try {
20
- return String.fromCharCode(parseInt(n.replace("\\", ""), 16));
37
+ return String.fromCharCode(parseInt(e.replace("\\", ""), 16));
21
38
  } catch {
22
- return n;
39
+ return e;
23
40
  }
24
- return n;
41
+ return e;
25
42
  }
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;
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;
31
48
  }
32
- function p(t) {
49
+ function S(t) {
33
50
  return [
34
51
  /font\s*awesome/i,
35
52
  /material\s*icons/i,
@@ -40,51 +57,83 @@ function p(t) {
40
57
  /remix\s*icons/i,
41
58
  /heroicons/i,
42
59
  /lucide/i
43
- ].some((e) => e.test(t));
60
+ ].some((n) => n.test(t));
44
61
  }
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);
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);
52
69
  try {
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);
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);
56
73
  try {
57
- const s = i.toDataURL("image/png");
58
- c.set(t, s), a(s);
74
+ const c = o.toDataURL("image/png");
75
+ l.set(t, c), a(c);
59
76
  } catch {
60
- o(new Error("CORS restrictions prevented image capture"));
77
+ r(new Error("CORS restrictions prevented image capture"));
61
78
  }
62
- } catch (i) {
63
- o(i);
79
+ } catch (o) {
80
+ r(o);
64
81
  }
65
- }, r.onerror = (i) => {
66
- clearTimeout(u), o(
67
- new Error("Failed to load image: " + (i.message || "Unknown error"))
82
+ }, s.onerror = (o) => {
83
+ clearTimeout(i), r(
84
+ new Error("Failed to load image: " + (o.message || "Unknown error"))
68
85
  );
69
- }, r.src = t;
86
+ }, s.src = t;
70
87
  });
71
88
  }
72
- function y(t) {
73
- const n = {};
74
- for (let e of t)
75
- n[e] = t.getPropertyValue(e);
76
- return n;
89
+ function U(t) {
90
+ const e = {};
91
+ for (let n of t)
92
+ e[n] = t.getPropertyValue(n);
93
+ return e;
77
94
  }
78
- function I() {
95
+ function y() {
79
96
  return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
80
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
+ }
81
126
  export {
82
- w as extractURL,
83
- C as fetchImage,
84
- f as getStyle,
85
- h as idle,
86
- p as isIconFont,
87
- I as isSafari,
88
- g as parseContent,
89
- y as snapshotComputedStyle
127
+ d as extractURL,
128
+ f as fetchImage,
129
+ x as getStyle,
130
+ I as idle,
131
+ w as inlineSingleBackgroundEntry,
132
+ S as isIconFont,
133
+ y as isSafari,
134
+ C as parseContent,
135
+ g as safeEncodeURI,
136
+ U as snapshotComputedStyle,
137
+ E as splitBackgroundImage,
138
+ k as stripTranslate
90
139
  };