@unicom-cloud/utils 0.1.12 → 0.1.13

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.
Files changed (35) hide show
  1. package/filesize/src/constants.js +22 -22
  2. package/filesize/src/filesize.js +32 -33
  3. package/package.json +1 -1
  4. package/snapdom/src/api/preCache.js +23 -23
  5. package/snapdom/src/api/snapdom.js +42 -42
  6. package/snapdom/src/core/cache.js +19 -8
  7. package/snapdom/src/core/capture.js +60 -59
  8. package/snapdom/src/core/clone.js +96 -31
  9. package/snapdom/src/core/prepare.js +35 -38
  10. package/snapdom/src/modules/background.js +29 -20
  11. package/snapdom/src/modules/fonts.js +97 -105
  12. package/snapdom/src/modules/pseudo.js +32 -32
  13. package/snapdom/src/modules/styles.js +22 -22
  14. package/snapdom/src/utils/cssTools.js +41 -41
  15. package/snapdom/src/utils/helpers.js +143 -146
  16. package/tree/index.js +1 -1
  17. package/tree/search/index.js +90 -0
  18. package/tree.js +1 -1
  19. package/types/filesize/src/constants.d.ts +12 -12
  20. package/types/filesize/src/filesize.d.ts +63 -22
  21. package/types/snapdom/src/core/cache.d.ts +17 -11
  22. package/types/snapdom/src/core/capture.d.ts +4 -0
  23. package/types/snapdom/src/core/clone.d.ts +4 -5
  24. package/types/snapdom/src/core/prepare.d.ts +8 -1
  25. package/types/snapdom/src/modules/background.d.ts +1 -2
  26. package/types/snapdom/src/modules/pseudo.d.ts +1 -3
  27. package/types/snapdom/src/modules/styles.d.ts +1 -1
  28. package/types/snapdom/src/utils/cssTools.d.ts +1 -2
  29. package/types/tree/index.d.ts +1 -1
  30. package/types/tree/search/index.d.ts +80 -0
  31. package/types/ui-color/index.d.ts +28 -3
  32. package/ui-color/index.js +70 -63
  33. package/uiColor.js +19 -18
  34. package/tree/searchTree.js +0 -54
  35. package/types/tree/searchTree.d.ts +0 -20
@@ -1,51 +1,116 @@
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") {
1
+ import { cache as r } from "./cache.js";
2
+ import { inlineAllStyles as f } from "../modules/styles.js";
3
+ function u(e, n, a = {}, o) {
4
+ if (!e) throw new Error("Invalid node");
5
+ const p = /* @__PURE__ */ new Set();
6
+ let d = null;
7
+ if (e.nodeType === Node.TEXT_NODE || e.nodeType !== Node.ELEMENT_NODE)
8
+ return e.cloneNode(!0);
9
+ if (e.getAttribute("data-capture") === "exclude") {
4
10
  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;
11
+ return t.style.cssText = `display:inline-block;width:${i.width}px;height:${i.height}px;visibility:hidden;`, t;
6
12
  }
13
+ if (a.exclude && Array.isArray(a.exclude))
14
+ for (const t of a.exclude)
15
+ try {
16
+ if (e.matches?.(t)) {
17
+ const i = document.createElement("div"), l = e.getBoundingClientRect();
18
+ return i.style.cssText = `display:inline-block;width:${l.width}px;height:${l.height}px;visibility:hidden;`, i;
19
+ }
20
+ } catch (i) {
21
+ console.warn(`Invalid selector in exclude option: ${t}`, i);
22
+ }
23
+ if (typeof a.filter == "function")
24
+ try {
25
+ if (!a.filter(e, o || e)) {
26
+ const t = document.createElement("div"), i = e.getBoundingClientRect();
27
+ return t.style.cssText = `display:inline-block;width:${i.width}px;height:${i.height}px;visibility:hidden;`, t;
28
+ }
29
+ } catch (t) {
30
+ console.warn("Error in filter function:", t);
31
+ }
7
32
  if (e.tagName === "IFRAME") {
8
33
  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;
34
+ return 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;
10
35
  }
11
- if (e.nodeType === Node.ELEMENT_NODE && e.getAttribute("data-capture") === "placeholder") {
36
+ if (e.getAttribute("data-capture") === "placeholder") {
12
37
  const t = e.cloneNode(!1);
13
- n.set(t, e), o(e, t, c, r, s);
38
+ r.preNodeMap.set(t, e), f(e, t, n);
14
39
  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;
40
+ 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
41
  }
17
42
  if (e.tagName === "CANVAS") {
18
43
  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;
44
+ return i.src = t, i.width = e.width, i.height = e.height, r.preNodeMap.set(i, e), f(e, i, n), i;
45
+ }
46
+ let c;
47
+ try {
48
+ c = e.cloneNode(!1), r.preNodeMap.set(c, e);
49
+ } catch (t) {
50
+ throw console.error("[Snapdom] Failed to clone node:", e, t), t;
51
+ }
52
+ if (e instanceof HTMLTextAreaElement) {
53
+ c.textContent = e.value, c.value = e.value;
54
+ const t = e.getBoundingClientRect();
55
+ return c.style.width = `${t.width}px`, c.style.height = `${t.height}px`, c;
20
56
  }
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;
57
+ if (e instanceof HTMLInputElement)
58
+ return c.value = e.value, c.setAttribute("value", e.value), e.checked !== void 0 && (c.checked = e.checked, e.checked && c.setAttribute("checked", ""), e.indeterminate && (c.indeterminate = e.indeterminate)), c;
59
+ if (e instanceof HTMLSelectElement && (d = e.value), f(e, c, n), e.shadowRoot)
60
+ if (Array.from(e.shadowRoot.querySelectorAll("slot")).length > 0) {
61
+ for (const i of e.shadowRoot.childNodes)
62
+ if (i.nodeType === Node.ELEMENT_NODE && i.tagName === "STYLE") {
63
+ const l = i.textContent || "";
64
+ l.trim() && n && (r.preStyle || (r.preStyle = /* @__PURE__ */ new WeakMap()), r.preStyle.set(i, l));
65
+ }
66
+ } else {
67
+ const i = document.createDocumentFragment();
68
+ for (const l of e.shadowRoot.childNodes) {
69
+ if (l.nodeType === Node.ELEMENT_NODE && l.tagName === "STYLE") {
70
+ const s = l.textContent || "";
71
+ s.trim() && n && (r.preStyle || (r.preStyle = /* @__PURE__ */ new WeakMap()), r.preStyle.set(l, s));
72
+ continue;
73
+ }
74
+ const h = u(
75
+ l,
76
+ n,
77
+ a,
78
+ o || e
79
+ );
80
+ h && i.appendChild(h);
81
+ }
82
+ c.appendChild(i);
25
83
  }
26
- return e.cloneNode(!0);
84
+ if (e.tagName === "SLOT") {
85
+ const t = e.assignedNodes?.({ flatten: !0 }) || [], i = t.length > 0 ? t : Array.from(e.childNodes), l = document.createDocumentFragment();
86
+ for (const h of i) {
87
+ const s = u(
88
+ h,
89
+ n,
90
+ a,
91
+ o || e
92
+ );
93
+ s && l.appendChild(s);
94
+ }
95
+ return l;
27
96
  }
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(
97
+ for (const t of e.childNodes) {
98
+ if (p.has(t)) continue;
99
+ const i = u(
36
100
  t,
37
- c,
38
- r,
39
101
  n,
40
- s
102
+ a,
103
+ o || e
41
104
  );
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);
105
+ i && c.appendChild(i);
106
+ }
107
+ if (d !== null && c instanceof HTMLSelectElement) {
108
+ c.value = d;
109
+ for (const t of c.options)
110
+ t.value === d ? t.setAttribute("selected", "") : t.removeAttribute("selected");
46
111
  }
47
- return l;
112
+ return c;
48
113
  }
49
114
  export {
50
- f as deepClone
115
+ u as deepClone
51
116
  };
@@ -1,68 +1,65 @@
1
- import { inlinePseudoElements as g } from "../modules/pseudo.js";
2
- import { inlineExternalDef as u } from "../modules/svgDefs.js";
3
- import { generateCSSClasses as h } from "../utils/cssTools.js";
4
- import { stripTranslate as w } from "../utils/helpers.js";
5
- import { deepClone as C } from "./clone.js";
6
- async function T(n, y = !1, m = !1, p = "") {
7
- const a = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new Map();
8
- let o;
1
+ import { cache as n } from "./cache.js";
2
+ import { inlinePseudoElements as p } from "../modules/pseudo.js";
3
+ import { inlineExternalDef as m } from "../modules/svgDefs.js";
4
+ import { generateCSSClasses as g } from "../utils/cssTools.js";
5
+ import { stripTranslate as u } from "../utils/helpers.js";
6
+ import { deepClone as h } from "./clone.js";
7
+ async function k(l, c = !1, d = !1, f = {}) {
8
+ let o, y = "";
9
9
  try {
10
- o = C(n, a, r, c, y);
10
+ o = h(l, c, f, l);
11
11
  } catch (e) {
12
12
  throw console.warn("deepClone failed:", e), e;
13
13
  }
14
14
  try {
15
- await g(
16
- n,
15
+ await p(
16
+ l,
17
17
  o,
18
- a,
19
- r,
20
- y,
21
- m,
22
- p
18
+ c,
19
+ d,
20
+ f.useProxy
23
21
  );
24
22
  } catch (e) {
25
23
  console.warn("inlinePseudoElements failed:", e);
26
24
  }
27
25
  try {
28
- u(o);
26
+ m(o);
29
27
  } catch (e) {
30
28
  console.warn("inlineExternalDef failed:", e);
31
29
  }
32
- let d = "";
33
- if (y) {
34
- const e = h(a);
35
- d = Array.from(e.entries()).map(([t, l]) => `.${l}{${t}}`).join("");
36
- for (const [t, l] of a.entries()) {
30
+ if (c) {
31
+ const e = g();
32
+ y = Array.from(e.entries()).map(([t, r]) => `.${r}{${t}}`).join("");
33
+ for (const [t, r] of n.preStyleMap.entries()) {
37
34
  if (t.tagName === "STYLE") continue;
38
- const i = e.get(l);
39
- i && t.classList.add(i);
40
- const f = t.style?.backgroundImage;
41
- t.removeAttribute("style"), f && f !== "none" && (t.style.backgroundImage = f);
35
+ const a = e.get(r);
36
+ a && t.classList.add(a);
37
+ const i = t.style?.backgroundImage;
38
+ t.removeAttribute("style"), i && i !== "none" && (t.style.backgroundImage = i);
42
39
  }
43
40
  } else
44
- for (const [e, t] of a.entries())
41
+ for (const [e, t] of n.preStyleMap.entries())
45
42
  e.tagName !== "STYLE" && e.setAttribute("style", t.replace(/;/g, "; "));
46
- for (const [e, t] of c.entries()) {
47
- const l = t.scrollLeft, i = t.scrollTop;
48
- if ((l || i) && e instanceof HTMLElement) {
43
+ for (const [e, t] of n.preNodeMap.entries()) {
44
+ const r = t.scrollLeft, a = t.scrollTop;
45
+ if ((r || a) && e instanceof HTMLElement) {
49
46
  e.style.overflow = "hidden", e.style.scrollbarWidth = "none", e.style.msOverflowStyle = "none";
50
47
  const s = document.createElement("div");
51
- for (s.style.transform = `translate(${-l}px, ${-i}px)`, s.style.willChange = "transform", s.style.display = "inline-block", s.style.width = "100%"; e.firstChild; )
48
+ for (s.style.transform = `translate(${-r}px, ${-a}px)`, s.style.willChange = "transform", s.style.display = "inline-block", s.style.width = "100%"; e.firstChild; )
52
49
  s.appendChild(e.firstChild);
53
50
  e.appendChild(s);
54
51
  }
55
52
  }
56
- if (n === c.get(o)) {
57
- const e = r.get(n) || window.getComputedStyle(n);
58
- r.set(n, e);
59
- const t = w(e.transform);
53
+ if (l === n.preNodeMap.get(o)) {
54
+ const e = n.preStyle.get(l) || window.getComputedStyle(l);
55
+ n.preStyle.set(l, e);
56
+ const t = u(e.transform);
60
57
  o.style.margin = "0", o.style.position = "static", o.style.top = "auto", o.style.left = "auto", o.style.right = "auto", o.style.bottom = "auto", o.style.zIndex = "auto", o.style.float = "none", o.style.clear = "none", o.style.transform = t || "";
61
58
  }
62
- for (const [e, t] of c.entries())
59
+ for (const [e, t] of n.preNodeMap.entries())
63
60
  t.tagName === "PRE" && (e.style.marginTop = "0", e.style.marginBlockStart = "0");
64
- return { clone: o, classCSS: d, styleCache: r };
61
+ return { clone: o, classCSS: y };
65
62
  }
66
63
  export {
67
- T as prepareClone
64
+ k as prepareClone
68
65
  };
@@ -1,25 +1,34 @@
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;
1
+ import { cache as c } from "../core/cache.js";
2
+ import { getStyle as y, splitBackgroundImage as h, inlineSingleBackgroundEntry as b } from "../utils/helpers.js";
3
+ async function w(u, d, k = {}) {
4
+ const t = [[u, d]], p = [
5
+ "background-image",
6
+ "mask",
7
+ "mask-image",
8
+ "-webkit-mask-image",
9
+ "mask-source",
10
+ "mask-box-image-source",
11
+ "mask-border-source",
12
+ "-webkit-mask-box-image-source"
13
+ ];
14
+ for (; t.length; ) {
15
+ const [o, s] = t.shift(), a = c.preStyle.get(o) || y(o);
16
+ c.preStyle.has(o) || c.preStyle.set(o, a);
17
+ for (const e of p) {
18
+ const i = a.getPropertyValue(e);
19
+ if (!i || i === "none") continue;
20
+ const f = h(i), g = await Promise.all(
21
+ f.map((r) => b(r, k))
22
+ );
23
+ g.some((r) => r && r !== "none" && !/^url\(undefined/.test(r)) && s.style.setProperty(e, g.join(", "));
13
24
  }
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]]);
25
+ const n = a.getPropertyValue("background-color");
26
+ n && n !== "transparent" && n !== "rgba(0, 0, 0, 0)" && (s.style.backgroundColor = n);
27
+ const l = Array.from(o.children), m = Array.from(s.children);
28
+ for (let e = 0; e < Math.min(l.length, m.length); e++)
29
+ t.push([l[e], m[e]]);
21
30
  }
22
31
  }
23
32
  export {
24
- B as inlineBackgroundImages
33
+ w as inlineBackgroundImages
25
34
  };
@@ -1,141 +1,139 @@
1
- import { resourceCache as c, processedFontURLs as h } from "../core/cache.js";
2
- import { isIconFont as w } from "./iconFonts.js";
3
- import { extractURL as $ } from "../utils/helpers.js";
4
- async function _(m, l, r, y = 32, u = "#000") {
5
- l = l.replace(/^['"]+|['"]+$/g, "");
1
+ import { cache as o } from "../core/cache.js";
2
+ import { isIconFont as y } from "./iconFonts.js";
3
+ import { extractURL as L } from "../utils/helpers.js";
4
+ async function E(u, i, a, p = 32, m = "#000") {
5
+ i = i.replace(/^['"]+|['"]+$/g, "");
6
6
  const t = window.devicePixelRatio || 1, s = document.createElement("canvas").getContext("2d");
7
- s.font = r ? `${r} ${y}px "${l}"` : `${y}px "${l}"`;
8
- const i = s.measureText(m), f = i.actualBoundingBoxAscent || y * 0.8, a = i.actualBoundingBoxDescent || y * 0.2, d = f + a, p = i.width, n = document.createElement("canvas");
9
- n.width = Math.ceil(p * t), n.height = Math.ceil(d * t);
10
- const e = n.getContext("2d");
11
- return e.scale(t, t), e.font = s.font, e.textAlign = "left", e.textBaseline = "alphabetic", e.fillStyle = u, e.fillText(m, 0, f), n.toDataURL();
7
+ s.font = a ? `${a} ${p}px "${i}"` : `${p}px "${i}"`;
8
+ const c = s.measureText(u), l = c.actualBoundingBoxAscent || p * 0.8, f = c.actualBoundingBoxDescent || p * 0.2, d = l + f, w = c.width, e = document.createElement("canvas");
9
+ e.width = Math.ceil(w * t), e.height = Math.ceil(d * t);
10
+ const h = e.getContext("2d");
11
+ return h.scale(t, t), h.font = s.font, h.textAlign = "left", h.textBaseline = "alphabetic", h.fillStyle = m, h.fillText(u, 0, l), e.toDataURL();
12
12
  }
13
- function A(m) {
14
- return Array.from(document.styleSheets).some((l) => l.href === m);
13
+ function $(u) {
14
+ return Array.from(document.styleSheets).some((i) => i.href === u);
15
15
  }
16
- function C(m) {
17
- return new Promise((l) => {
18
- if (A(m)) return l(null);
19
- const r = document.createElement("link");
20
- r.rel = "stylesheet", r.href = m, r.setAttribute("data-snapdom", "injected-import"), r.onload = () => l(r), r.onerror = () => l(null), document.head.appendChild(r);
16
+ function P(u) {
17
+ return new Promise((i) => {
18
+ if ($(u)) return i(null);
19
+ const a = document.createElement("link");
20
+ a.rel = "stylesheet", a.href = u, a.setAttribute("data-snapdom", "injected-import"), a.onload = () => i(a), a.onerror = () => i(null), document.head.appendChild(a);
21
21
  });
22
22
  }
23
- async function P({ preCached: m = !1 } = {}) {
24
- if (c.has("fonts-embed-css")) {
25
- if (m) {
23
+ async function T({ preCached: u = !1 } = {}) {
24
+ if (o.resource.has("fonts-embed-css")) {
25
+ if (u) {
26
26
  const t = document.createElement("style");
27
- t.setAttribute("data-snapdom", "embedFonts"), t.textContent = c.get("fonts-embed-css"), document.head.appendChild(t);
27
+ t.setAttribute("data-snapdom", "embedFonts"), t.textContent = o.resource.get("fonts-embed-css"), document.head.appendChild(t);
28
28
  }
29
- return c.get("fonts-embed-css");
29
+ return o.resource.get("fonts-embed-css");
30
30
  }
31
- const l = /@import\s+url\(["']?([^"')]+)["']?\)/g, r = [];
31
+ const i = /@import\s+url\(["']?([^"')]+)["']?\)/g, a = [];
32
32
  for (const t of document.querySelectorAll("style")) {
33
- const o = t.textContent || "", s = Array.from(o.matchAll(l));
34
- for (const i of s) {
35
- const f = i[1];
36
- w(f) || A(f) || r.push(f);
33
+ const n = t.textContent || "", s = Array.from(n.matchAll(i));
34
+ for (const c of s) {
35
+ const l = c[1];
36
+ y(l) || $(l) || a.push(l);
37
37
  }
38
38
  }
39
- await Promise.all(r.map(C));
40
- const y = Array.from(
39
+ await Promise.all(a.map(P));
40
+ const p = Array.from(
41
41
  document.querySelectorAll('link[rel="stylesheet"]')
42
42
  ).filter((t) => t.href);
43
- let u = "";
44
- for (const t of y)
43
+ let m = "";
44
+ for (const t of p)
45
45
  try {
46
46
  const s = await (await fetch(t.href)).text();
47
- if (w(t.href) || w(s)) continue;
48
- const i = /url\((["']?)([^"')]+)\1\)/g, f = await Promise.all(
49
- Array.from(s.matchAll(i)).map(async (d) => {
50
- let p = $(d[0]);
51
- if (!p) return null;
52
- let n = p;
53
- if (!n.startsWith("http") && !n.startsWith("data:") && (n = new URL(n, t.href).href), w(n)) return null;
54
- if (c.has(n))
55
- return h.add(n), {
47
+ if (y(t.href) || y(s)) continue;
48
+ const c = /url\((["']?)([^"')]+)\1\)/g, l = await Promise.all(
49
+ Array.from(s.matchAll(c)).map(async (d) => {
50
+ let w = L(d[0]);
51
+ if (!w) return null;
52
+ let e = w;
53
+ if (!e.startsWith("http") && !e.startsWith("data:") && (e = new URL(e, t.href).href), y(e)) return null;
54
+ if (o.resource.has(e))
55
+ return o.font.add(e), {
56
56
  original: d[0],
57
- inlined: `url(${c.get(n)})`
57
+ inlined: `url(${o.resource.get(e)})`
58
58
  };
59
- if (h.has(n)) return null;
59
+ if (o.font.has(e)) return null;
60
60
  try {
61
- const S = await (await fetch(n)).blob(), b = await new Promise((x) => {
62
- const g = new FileReader();
63
- g.onload = () => x(g.result), g.readAsDataURL(S);
61
+ const g = await (await fetch(e)).blob(), b = await new Promise((r) => {
62
+ const x = new FileReader();
63
+ x.onload = () => r(x.result), x.readAsDataURL(g);
64
64
  });
65
- return c.set(n, b), h.add(n), { original: d[0], inlined: `url(${b})` };
65
+ return o.resource.set(e, b), o.font.add(e), { original: d[0], inlined: `url(${b})` };
66
66
  } catch {
67
- return console.warn("[snapdom] Failed to fetch font resource:", n), null;
67
+ return console.warn("[snapdom] Failed to fetch font resource:", e), null;
68
68
  }
69
69
  })
70
70
  );
71
- let a = s;
72
- for (const d of f)
73
- d && (a = a.replace(d.original, d.inlined));
74
- u += a + `
71
+ let f = s;
72
+ for (const d of l)
73
+ d && (f = f.replace(d.original, d.inlined));
74
+ m += f + `
75
75
  `;
76
76
  } catch {
77
77
  console.warn("[snapdom] Failed to fetch CSS:", t.href);
78
78
  }
79
79
  for (const t of document.styleSheets)
80
80
  try {
81
- if (!t.href || y.every((o) => o.href !== t.href)) {
82
- for (const o of t.cssRules)
83
- if (o.type === CSSRule.FONT_FACE_RULE) {
84
- const s = o.style.getPropertyValue("src"), i = o.style.getPropertyValue("font-family");
85
- if (!s || w(i)) continue;
86
- const f = /url\((["']?)([^"')]+)\1\)/g;
87
- let a = s;
88
- const d = Array.from(s.matchAll(f));
89
- for (const p of d) {
90
- let n = p[2].trim();
91
- if (!n) continue;
92
- let e = n;
93
- if (!e.startsWith("http") && !e.startsWith("data:") && (e = new URL(e, t.href || location.href).href), !w(e)) {
94
- if (c.has(e)) {
95
- h.add(e), a = a.replace(
96
- p[0],
97
- `url(${c.get(e)})`
81
+ if (!t.href || p.every((n) => n.href !== t.href)) {
82
+ for (const n of t.cssRules)
83
+ if (n.type === CSSRule.FONT_FACE_RULE) {
84
+ const s = n.style.getPropertyValue("src"), c = n.style.getPropertyValue("font-family");
85
+ if (!s || y(c)) continue;
86
+ const l = /url\((["']?)([^"')]+)\1\)/g, f = /local\((["']?)[^)]+?\1\)/g, d = l.test(s), w = f.test(s);
87
+ if (!d && w) {
88
+ m += `@font-face{font-family:${c};src:${s};font-style:${n.style.getPropertyValue("font-style") || "normal"};font-weight:${n.style.getPropertyValue("font-weight") || "normal"};}`;
89
+ continue;
90
+ }
91
+ let e = s;
92
+ const h = Array.from(s.matchAll(l));
93
+ for (const g of h) {
94
+ let b = g[2].trim();
95
+ if (!b) continue;
96
+ let r = b;
97
+ if (!r.startsWith("http") && !r.startsWith("data:") && (r = new URL(r, t.href || location.href).href), !y(r)) {
98
+ if (o.resource.has(r)) {
99
+ o.font.add(r), e = e.replace(
100
+ g[0],
101
+ `url(${o.resource.get(r)})`
98
102
  );
99
103
  continue;
100
104
  }
101
- if (!h.has(e))
105
+ if (!o.font.has(r))
102
106
  try {
103
- const b = await (await fetch(e)).blob(), x = await new Promise((g) => {
107
+ const A = await (await fetch(r)).blob(), S = await new Promise((C) => {
104
108
  const R = new FileReader();
105
- R.onload = () => g(R.result), R.readAsDataURL(b);
109
+ R.onload = () => C(R.result), R.readAsDataURL(A);
106
110
  });
107
- c.set(e, x), h.add(e), a = a.replace(p[0], `url(${x})`);
111
+ o.resource.set(r, S), o.font.add(r), e = e.replace(g[0], `url(${S})`);
108
112
  } catch {
109
- console.warn("[snapdom] Failed to fetch font URL:", e);
113
+ console.warn("[snapdom] Failed to fetch font URL:", r);
110
114
  }
111
115
  }
112
116
  }
113
- u += `@font-face {
114
- font-family: ${i};
115
- src: ${a};
116
- font-style: ${o.style.getPropertyValue("font-style") || "normal"};
117
- font-weight: ${o.style.getPropertyValue("font-weight") || "normal"};
118
- }
119
- `;
117
+ m += `@font-face{font-family:${c};src:${e};font-style:${n.style.getPropertyValue("font-style") || "normal"};font-weight:${n.style.getPropertyValue("font-weight") || "normal"};}`;
120
118
  }
121
119
  }
122
- } catch (o) {
123
- console.warn("[snapdom] Cannot access stylesheet", t.href, o);
120
+ } catch (n) {
121
+ console.warn("[snapdom] Cannot access stylesheet", t.href, n);
124
122
  }
125
123
  for (const t of document.fonts)
126
124
  if (t.family && t.status === "loaded" && t._snapdomSrc) {
127
- if (w(t.family)) continue;
128
- let o = t._snapdomSrc;
129
- if (!o.startsWith("data:")) {
130
- if (c.has(t._snapdomSrc))
131
- o = c.get(t._snapdomSrc), h.add(t._snapdomSrc);
132
- else if (!h.has(t._snapdomSrc))
125
+ if (y(t.family)) continue;
126
+ let n = t._snapdomSrc;
127
+ if (!n.startsWith("data:")) {
128
+ if (o.resource.has(t._snapdomSrc))
129
+ n = o.resource.get(t._snapdomSrc), o.font.add(t._snapdomSrc);
130
+ else if (!o.font.has(t._snapdomSrc))
133
131
  try {
134
- const i = await (await fetch(t._snapdomSrc)).blob();
135
- o = await new Promise((f) => {
136
- const a = new FileReader();
137
- a.onload = () => f(a.result), a.readAsDataURL(i);
138
- }), c.set(t._snapdomSrc, o), h.add(t._snapdomSrc);
132
+ const c = await (await fetch(t._snapdomSrc)).blob();
133
+ n = await new Promise((l) => {
134
+ const f = new FileReader();
135
+ f.onload = () => l(f.result), f.readAsDataURL(c);
136
+ }), o.resource.set(t._snapdomSrc, n), o.font.add(t._snapdomSrc);
139
137
  } catch {
140
138
  console.warn(
141
139
  "[snapdom] Failed to fetch dynamic font src:",
@@ -144,21 +142,15 @@ async function P({ preCached: m = !1 } = {}) {
144
142
  continue;
145
143
  }
146
144
  }
147
- u += `@font-face {
148
- font-family: '${t.family}';
149
- src: url(${o});
150
- font-style: ${t.style || "normal"};
151
- font-weight: ${t.weight || "normal"};
152
- }
153
- `;
145
+ m += `@font-face{font-family:'${t.family}';src:url(${n});font-style:${t.style || "normal"};font-weight:${t.weight || "normal"};}`;
154
146
  }
155
- if (u && (c.set("fonts-embed-css", u), m)) {
147
+ if (m && (o.resource.set("fonts-embed-css", m), u)) {
156
148
  const t = document.createElement("style");
157
- t.setAttribute("data-snapdom", "embedFonts"), t.textContent = u, document.head.appendChild(t);
149
+ t.setAttribute("data-snapdom", "embedFonts"), t.textContent = m, document.head.appendChild(t);
158
150
  }
159
- return u;
151
+ return m;
160
152
  }
161
153
  export {
162
- P as embedCustomFonts,
163
- _ as iconToImage
154
+ T as embedCustomFonts,
155
+ E as iconToImage
164
156
  };