@unicom-cloud/utils 0.1.2 → 0.1.3

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,41 +1,35 @@
1
1
  import "../is/index.js";
2
2
  import r from "lodash/isString";
3
- function n() {
4
- return new DOMException("The request is not allowed", "NotAllowedError");
5
- }
6
- async function i(e) {
7
- if (!navigator.clipboard)
8
- throw n();
9
- return navigator.clipboard.writeText(e);
10
- }
11
- async function l(e) {
12
- const o = document.createElement("span");
13
- o.textContent = e, o.style.whiteSpace = "pre", o.style.webkitUserSelect = "auto", o.style.userSelect = "all", document.body.appendChild(o);
14
- const t = window.getSelection(), a = window.document.createRange();
15
- t.removeAllRanges(), a.selectNode(o), t.addRange(a);
16
- let c = !1;
3
+ async function a(o) {
4
+ const e = document.createElement("span");
5
+ e.textContent = o, e.style.whiteSpace = "pre", e.style.webkitUserSelect = "auto", e.style.userSelect = "all", document.body.appendChild(e);
6
+ const n = window.getSelection(), t = window.document.createRange();
7
+ n.removeAllRanges(), t.selectNode(e), n.addRange(t);
17
8
  try {
18
- c = window.document.execCommand("copy");
9
+ return window.document.execCommand("copy");
10
+ } catch (c) {
11
+ console.error(c);
19
12
  } finally {
20
- t.removeAllRanges(), window.document.body.removeChild(o);
13
+ n.removeAllRanges(), window.document.body.removeChild(e);
21
14
  }
22
- if (!c) throw n();
23
15
  }
24
- async function p(e) {
25
- try {
26
- r(e) || (e = JSON.stringify(e) ?? e);
27
- } catch {
16
+ async function s(o) {
17
+ if (!r(o)) try {
18
+ o = JSON.stringify(o);
19
+ } catch (e) {
20
+ console.error(e);
28
21
  }
29
22
  try {
30
- await i(e);
31
- } catch (o) {
23
+ await window.navigator.clipboard.writeText(o);
24
+ } catch (e) {
25
+ console.error(e);
32
26
  try {
33
- await l(e);
34
- } catch (t) {
35
- throw t || o || n();
27
+ await a(o);
28
+ } catch (n) {
29
+ console.error(n);
36
30
  }
37
31
  }
38
32
  }
39
33
  export {
40
- p as default
34
+ s as default
41
35
  };
package/math/index.js CHANGED
@@ -1,34 +1,26 @@
1
- import { Decimal as e } from "../decimal/decimal.js";
2
- function u(t, n) {
3
- return new e(t).plus(n).toNumber();
1
+ import { Decimal as t } from "../decimal/decimal.js";
2
+ function u(n, e) {
3
+ return new t(n).plus(e).toNumber();
4
4
  }
5
- function i(t, n) {
6
- return new e(t).minus(n).toNumber();
5
+ function r(n, e) {
6
+ return new t(n).minus(e).toNumber();
7
7
  }
8
- function o(t, n) {
9
- return new e(t).times(n).toNumber();
8
+ function i(n, e) {
9
+ return new t(n).times(e).toNumber();
10
10
  }
11
- function r(t, n) {
12
- return new e(t).div(n).toNumber();
11
+ function o(n, e) {
12
+ return new t(n).div(e).toNumber();
13
13
  }
14
- const s = u, m = i, c = o, d = r, l = {
14
+ const s = {
15
15
  plus: u,
16
- minus: i,
17
- times: o,
18
- div: r,
19
- add: s,
20
- subtract: m,
21
- multiply: c,
22
- divide: d
16
+ minus: r,
17
+ times: i,
18
+ div: o
23
19
  };
24
20
  export {
25
- s as add,
26
- l as default,
27
- r as div,
28
- d as divide,
29
- i as minus,
30
- c as multiply,
21
+ s as default,
22
+ o as div,
23
+ r as minus,
31
24
  u as plus,
32
- m as subtract,
33
- o as times
25
+ i as times
34
26
  };
@@ -84,7 +84,7 @@ const I = class I extends EventTarget {
84
84
  ) && e(this, d).push(a);
85
85
  const f = (h = e(this, l)) == null ? void 0 : h.template;
86
86
  if (e(this, d).length)
87
- e(this, d).forEach((m) => {
87
+ e(this, d).forEach((m, A, K) => {
88
88
  var T;
89
89
  let N = new MessageEvent("message", {
90
90
  data: (f == null ? void 0 : f({ ...m, sendCount: e(this, p) })) ?? f
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@unicom-cloud/utils","version":"0.1.2","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.3","dependencies":{},"peerDependencies":{"lodash":"^4.17.21"},"main":"./index.js","type":"module","types":"types/*","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
@@ -0,0 +1,6 @@
1
+ import { preCache as e } from "./src/api/preCache.js";
2
+ import { snapdom as m } from "./src/api/snapdom.js";
3
+ export {
4
+ e as preCache,
5
+ m as snapdom
6
+ };
@@ -0,0 +1,33 @@
1
+ import { imageCache as s, bgCache as o, resourceCache as p, baseCSSCache as g, computedStyleCache as C } from "../core/cache.js";
2
+ import { embedCustomFonts as d } from "../modules/fonts.js";
3
+ import { precacheCommonTags as y } from "../utils/cssTools.js";
4
+ import { fetchImage as i, extractUrl as S } from "../utils/helpers.js";
5
+ async function I(r = document, f = {}) {
6
+ const { embedFonts: m = !0, reset: u = !1, preWarm: b = !0 } = f;
7
+ if (u) {
8
+ s.clear(), o.clear(), p.clear(), g.clear(), C.clear();
9
+ return;
10
+ }
11
+ await document.fonts.ready, y();
12
+ let l = [], n = [];
13
+ r != null && r.querySelectorAll && (l = Array.from(r.querySelectorAll("img[src]")), n = Array.from(r.querySelectorAll("*")));
14
+ const t = [];
15
+ for (const a of l) {
16
+ const c = a.src;
17
+ s.has(c) || t.push(
18
+ i(c).then((e) => s.set(c, e)).catch(() => {
19
+ })
20
+ );
21
+ }
22
+ for (const a of n) {
23
+ const c = getComputedStyle(a).backgroundImage, e = S(c);
24
+ e && !o.has(e) && t.push(
25
+ i(e).then((h) => o.set(e, h)).catch(() => {
26
+ })
27
+ );
28
+ }
29
+ m && await d({ ignoreIconFonts: !m, preCached: !0 }), await Promise.all(t);
30
+ }
31
+ export {
32
+ I as preCache
33
+ };
@@ -0,0 +1,92 @@
1
+ import { captureDOM as v } from "../core/capture.js";
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;
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;
14
+ }
15
+ async function p(a) {
16
+ const t = decodeURIComponent(a.split(",")[1]);
17
+ return new Blob([t], { type: "image/svg+xml" });
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;
22
+ const o = document.createElement("canvas");
23
+ o.width = c.width, o.height = c.height;
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;
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;
30
+ }
31
+ async function j(a, {
32
+ dpr: t = 1,
33
+ scale: n = 1,
34
+ backgroundColor: e = "#fff",
35
+ format: c = "png",
36
+ filename: o = "capture"
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);
41
+ return;
42
+ }
43
+ const g = ["jpg", "jpeg", "webp"].includes(c) ? "#fff" : void 0, l = await m(a, { dpr: t, scale: n }, e ?? g), f = {
44
+ jpg: "image/jpeg",
45
+ jpeg: "image/jpeg",
46
+ png: "image/png",
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();
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);
54
+ }
55
+ i.capture = async (a, t = {}) => {
56
+ const n = await v(a, t), e = window.devicePixelRatio || 1, c = t.scale || 1;
57
+ return {
58
+ url: n,
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"),
67
+ download: ({
68
+ format: o = "png",
69
+ filename: g = "capture",
70
+ backgroundColor: s
71
+ } = {}) => j(n, { dpr: e, scale: c, backgroundColor: s, format: o, filename: g })
72
+ };
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 = {}) => {
82
+ const {
83
+ format: n = "png",
84
+ filename: e = "capture",
85
+ backgroundColor: c,
86
+ ...o
87
+ } = t;
88
+ return await (await i.capture(a, o)).download({ format: n, filename: e, backgroundColor: c });
89
+ };
90
+ export {
91
+ i as snapdom
92
+ };
@@ -0,0 +1,9 @@
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();
2
+ export {
3
+ t as baseCSSCache,
4
+ a as bgCache,
5
+ o as computedStyleCache,
6
+ n as defaultStylesCache,
7
+ e as imageCache,
8
+ c as resourceCache
9
+ };
@@ -0,0 +1,73 @@
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");
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(
18
+ a,
19
+ w,
20
+ l
21
+ ), await new Promise((e) => {
22
+ i(
23
+ async () => {
24
+ await E(t), e();
25
+ },
26
+ { fast: s }
27
+ );
28
+ }), await new Promise((e) => {
29
+ i(
30
+ async () => {
31
+ await $(a, t, p), e();
32
+ },
33
+ { fast: s }
34
+ );
35
+ }), l && await new Promise((e) => {
36
+ i(
37
+ async () => {
38
+ h = await B({ ignoreIconFonts: !l }), e();
39
+ },
40
+ { fast: s }
41
+ );
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(
46
+ () => {
47
+ r = I(e), g.set(o, r), c();
48
+ },
49
+ { fast: s }
50
+ );
51
+ });
52
+ }
53
+ await new Promise((e) => {
54
+ i(
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");
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();
64
+ },
65
+ { fast: s }
66
+ );
67
+ });
68
+ const m = document.getElementById("snapdom-sandbox");
69
+ return m && m.style.position === "absolute" && m.remove(), u;
70
+ }
71
+ export {
72
+ L as captureDOM
73
+ };
@@ -0,0 +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;
7
+ }
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;
11
+ }
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;
17
+ }
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;
21
+ }
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;
26
+ }
27
+ return t.cloneNode(!0);
28
+ }
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,
38
+ c,
39
+ o
40
+ );
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);
45
+ }
46
+ return r;
47
+ }
48
+ export {
49
+ f as deepClone
50
+ };
@@ -0,0 +1,53 @@
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;
6
+ const l = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new Map();
7
+ let c;
8
+ try {
9
+ c = C(f, l, i, d, r);
10
+ } catch (e) {
11
+ throw console.warn("deepClone failed:", e), e;
12
+ }
13
+ try {
14
+ await h(
15
+ f,
16
+ c,
17
+ l,
18
+ i,
19
+ r,
20
+ m
21
+ );
22
+ } catch (e) {
23
+ console.warn("inlinePseudoElements failed:", e);
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);
35
+ }
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) {
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);
47
+ }
48
+ }
49
+ return { clone: c, classCSS: y, styleCache: i };
50
+ }
51
+ export {
52
+ b as prepareClone
53
+ };
@@ -0,0 +1,27 @@
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
+ }
19
+ }
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]]);
23
+ }
24
+ }
25
+ export {
26
+ p as inlineBackgroundImages
27
+ };
@@ -0,0 +1,63 @@
1
+ import { resourceCache as x } from "../core/cache.js";
2
+ import { isIconFont as w } from "../utils/helpers.js";
3
+ async function y(i, r, u, n = 32, e = "#000") {
4
+ r = r.replace(/^['"]+|['"]+$/g, "");
5
+ const c = window.devicePixelRatio || 1, d = document.createElement("canvas").getContext("2d");
6
+ d.font = u ? `${u} ${n}px "${r}"` : `${n}px "${r}"`;
7
+ const f = d.measureText(i), s = f.actualBoundingBoxAscent || n * 0.8, a = f.actualBoundingBoxDescent || n * 0.2, t = s + a, m = f.width, l = document.createElement("canvas");
8
+ l.width = Math.ceil(m * c), l.height = Math.ceil(t * c);
9
+ const o = l.getContext("2d");
10
+ return o.scale(c, c), o.font = d.font, o.textAlign = "left", o.textBaseline = "alphabetic", o.fillStyle = e, o.fillText(i, 0, s), l.toDataURL();
11
+ }
12
+ async function A({
13
+ ignoreIconFonts: i = !0,
14
+ preCached: r = !1
15
+ }) {
16
+ const u = Array.from(
17
+ document.querySelectorAll('link[rel="stylesheet"]')
18
+ ).filter((e) => e.href);
19
+ let n = "";
20
+ for (const e of u)
21
+ try {
22
+ const h = await (await fetch(e.href)).text();
23
+ if (i && (w(e.href) || w(h)))
24
+ continue;
25
+ const d = /url\(([^)]+)\)/g, f = await Promise.all(
26
+ Array.from(h.matchAll(d)).map(async (a) => {
27
+ let t = a[1].replace(/["']/g, "");
28
+ if (t.startsWith("http") || (t = new URL(t, e.href).href), i && w(t))
29
+ return null;
30
+ if (x.has(t))
31
+ return {
32
+ original: a[0],
33
+ inlined: `url(${x.get(t)})`
34
+ };
35
+ try {
36
+ const l = await (await fetch(t)).blob(), o = await new Promise((g) => {
37
+ const p = new FileReader();
38
+ p.onload = () => g(p.result), p.readAsDataURL(l);
39
+ });
40
+ return x.set(t, o), { original: a[0], inlined: `url(${o})` };
41
+ } catch {
42
+ return console.warn("❌ Failed to fetch font:", t), null;
43
+ }
44
+ })
45
+ );
46
+ let s = h;
47
+ for (const a of f)
48
+ a && (s = s.replace(a.original, a.inlined));
49
+ n += s + `
50
+ `;
51
+ } catch {
52
+ console.warn("❌ Failed to fetch CSS:", e.href);
53
+ }
54
+ if (n && r) {
55
+ const e = document.createElement("style");
56
+ e.setAttribute("data-snapdom", "embedFonts"), e.textContent = n, document.head.appendChild(e);
57
+ }
58
+ return n;
59
+ }
60
+ export {
61
+ A as embedCustomFonts,
62
+ y as iconToImage
63
+ };
@@ -0,0 +1,20 @@
1
+ import { fetchImage as i } from "../utils/helpers.js";
2
+ async function h(a) {
3
+ const n = Array.from(a.querySelectorAll("img")), r = async (t) => {
4
+ const c = t.src;
5
+ try {
6
+ const e = await i(c);
7
+ t.src = e, t.width || (t.width = t.naturalWidth || 100), t.height || (t.height = t.naturalHeight || 100);
8
+ } catch {
9
+ const e = document.createElement("div");
10
+ e.style = `width: ${t.width || 100}px; height: ${t.height || 100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${t.height || 100}px; color: #666; font-size: 12px;`, e.innerText = "img", t.replaceWith(e);
11
+ }
12
+ };
13
+ for (let t = 0; t < n.length; t += 4) {
14
+ const c = n.slice(t, t + 4).map(r);
15
+ await Promise.allSettled(c);
16
+ }
17
+ }
18
+ export {
19
+ h as inlineImages
20
+ };
@@ -0,0 +1,63 @@
1
+ import { getStyleKey as S } from "../utils/cssTools.js";
2
+ import { getStyle as x, snapshotComputedStyle as W, parseContent as j, fetchImage as z } from "../utils/helpers.js";
3
+ import { iconToImage as A } from "./fonts.js";
4
+ async function B(s, a, f, y, p, m = !1) {
5
+ if (!(s instanceof Element) || !(a instanceof Element)) return;
6
+ for (const t of ["::before", "::after"])
7
+ try {
8
+ const e = x(s, t);
9
+ if (!e) continue;
10
+ const r = e.getPropertyValue("content"), g = e.getPropertyValue("background-image"), u = r && r !== "none" && r !== '""' && r !== "''", C = g && g.startsWith("url(");
11
+ if (u || C) {
12
+ const l = e.getPropertyValue("font-family"), E = parseInt(e.getPropertyValue("font-size")) || 32, w = parseInt(e.getPropertyValue("font-weight")) || !1, P = e.getPropertyValue("color") || "#000", o = document.createElement("span");
13
+ o.dataset.snapdomPseudo = t;
14
+ const b = W(e), V = S(b, "span", p);
15
+ f.set(o, V);
16
+ const I = l && /font.*awesome|material|bootstrap|glyphicons|ionicons|remixicon|simple-line-icons|octicons|feather|typicons|weathericons/i.test(
17
+ l
18
+ );
19
+ let i = j(r);
20
+ if (!m && I && i.length === 1) {
21
+ const n = document.createElement("img");
22
+ n.src = await A(
23
+ i,
24
+ l,
25
+ w,
26
+ E,
27
+ P
28
+ ), n.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(n);
29
+ } else if (i.startsWith("url(")) {
30
+ const n = i.match(/url\(["']?([^"')]+)["']?\)/);
31
+ if (n != null && n[1])
32
+ try {
33
+ const c = document.createElement("img"), k = await z(n[1]);
34
+ c.src = k, c.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(c);
35
+ } catch (c) {
36
+ console.error(
37
+ `[snapdom] Error in pseudo ${t} for`,
38
+ s,
39
+ c
40
+ );
41
+ }
42
+ } else i && i !== "none" && (o.textContent = i);
43
+ t === "::before" ? a.insertBefore(o, a.firstChild) : a.appendChild(o);
44
+ }
45
+ } catch (e) {
46
+ console.warn(`[snapdom] Failed to capture ${t} for`, s, e);
47
+ }
48
+ const d = Array.from(s.children), h = Array.from(a.children).filter(
49
+ (t) => !t.dataset.snapdomPseudo
50
+ );
51
+ for (let t = 0; t < Math.min(d.length, h.length); t++)
52
+ await B(
53
+ d[t],
54
+ h[t],
55
+ f,
56
+ y,
57
+ p,
58
+ m
59
+ );
60
+ }
61
+ export {
62
+ B as inlinePseudoElements
63
+ };
@@ -0,0 +1,12 @@
1
+ import { getStyleKey as g } from "../utils/cssTools.js";
2
+ import { getStyle as p, snapshotComputedStyle as f } from "../utils/helpers.js";
3
+ function N(t, o, s, e, a) {
4
+ var n;
5
+ if (t.tagName === "STYLE") return;
6
+ e.has(t) || e.set(t, p(t));
7
+ const i = e.get(t), l = f(i), m = ((n = t.tagName) == null ? void 0 : n.toLowerCase()) || "div", y = g(l, m, a);
8
+ s.set(o, y);
9
+ }
10
+ export {
11
+ N as inlineAllStyles
12
+ };
@@ -0,0 +1,111 @@
1
+ import { defaultStylesCache as r } from "../core/cache.js";
2
+ const d = [
3
+ "div",
4
+ "span",
5
+ "p",
6
+ "a",
7
+ "img",
8
+ "ul",
9
+ "li",
10
+ "button",
11
+ "input",
12
+ "select",
13
+ "textarea",
14
+ "label",
15
+ "section",
16
+ "article",
17
+ "header",
18
+ "footer",
19
+ "nav",
20
+ "main",
21
+ "aside",
22
+ "h1",
23
+ "h2",
24
+ "h3",
25
+ "h4",
26
+ "h5",
27
+ "h6",
28
+ "svg",
29
+ "path",
30
+ "circle",
31
+ "rect",
32
+ "line",
33
+ "g",
34
+ "table",
35
+ "thead",
36
+ "tbody",
37
+ "tr",
38
+ "td",
39
+ "th"
40
+ ];
41
+ function u() {
42
+ for (let t of d)
43
+ c(t);
44
+ }
45
+ function c(t) {
46
+ if (r.has(t))
47
+ return r.get(t);
48
+ if ((/* @__PURE__ */ new Set([
49
+ "script",
50
+ "style",
51
+ "meta",
52
+ "link",
53
+ "noscript",
54
+ "template"
55
+ ])).has(t)) {
56
+ const o = {};
57
+ return r.set(t, o), o;
58
+ }
59
+ let e = document.getElementById("snapdom-sandbox");
60
+ e || (e = document.createElement("div"), e.id = "snapdom-sandbox", e.style.position = "absolute", e.style.left = "-9999px", e.style.top = "-9999px", e.style.width = "0", e.style.height = "0", e.style.overflow = "hidden", document.body.appendChild(e));
61
+ const n = document.createElement(t);
62
+ n.style.all = "initial", e.appendChild(n);
63
+ const l = getComputedStyle(n), a = {};
64
+ for (let o of l)
65
+ a[o] = l.getPropertyValue(o);
66
+ return e.removeChild(n), r.set(t, a), a;
67
+ }
68
+ function p(t, s, e = !1) {
69
+ const n = [], l = c(s);
70
+ for (let [a, o] of Object.entries(t))
71
+ if (!e)
72
+ o && n.push(`${a}:${o}`);
73
+ else {
74
+ const i = l[a];
75
+ o && o !== i && n.push(`${a}:${o}`);
76
+ }
77
+ return n.sort().join(";");
78
+ }
79
+ function y(t) {
80
+ const s = /* @__PURE__ */ new Set();
81
+ return t.nodeType !== Node.ELEMENT_NODE && t.nodeType !== Node.DOCUMENT_FRAGMENT_NODE ? [] : (t.tagName && s.add(t.tagName.toLowerCase()), typeof t.querySelectorAll == "function" && t.querySelectorAll("*").forEach((e) => s.add(e.tagName.toLowerCase())), Array.from(s));
82
+ }
83
+ function h(t) {
84
+ const s = /* @__PURE__ */ new Map();
85
+ for (let n of t) {
86
+ const l = r.get(n);
87
+ if (!l) continue;
88
+ const a = Object.entries(l).map(([o, i]) => `${o}:${i};`).sort().join("");
89
+ s.has(a) || s.set(a, []), s.get(a).push(n);
90
+ }
91
+ let e = "";
92
+ for (let [n, l] of s.entries())
93
+ e += `${l.join(",")} { ${n} }
94
+ `;
95
+ return e;
96
+ }
97
+ function m(t) {
98
+ const s = new Set(t.values()), e = /* @__PURE__ */ new Map();
99
+ let n = 1;
100
+ for (const l of s)
101
+ e.set(l, `c${n++}`);
102
+ return e;
103
+ }
104
+ export {
105
+ y as collectUsedTagNames,
106
+ m as generateCSSClasses,
107
+ h as generateDedupedBaseCSS,
108
+ c as getDefaultStyleForTag,
109
+ p as getStyleKey,
110
+ u as precacheCommonTags
111
+ };
@@ -0,0 +1,87 @@
1
+ import { imageCache as s, computedStyleCache as m } from "../core/cache.js";
2
+ function g(t, { fast: e = !1 } = {}) {
3
+ if (e) return t();
4
+ "requestIdleCallback" in window ? requestIdleCallback(t, { timeout: 50 }) : setTimeout(t, 1);
5
+ }
6
+ function d(t, e = null) {
7
+ if (!(t instanceof Element))
8
+ return window.getComputedStyle(t, e);
9
+ let n = m.get(t);
10
+ if (n || (n = /* @__PURE__ */ new Map(), m.set(t, n)), !n.has(e)) {
11
+ const i = window.getComputedStyle(t, e);
12
+ n.set(e, i);
13
+ }
14
+ return n.get(e);
15
+ }
16
+ function f(t) {
17
+ let e = t.replace(/^['"]|['"]$/g, "");
18
+ if (e.startsWith("\\"))
19
+ try {
20
+ return String.fromCharCode(parseInt(e.replace("\\", ""), 16));
21
+ } catch {
22
+ return e;
23
+ }
24
+ return e;
25
+ }
26
+ function h(t) {
27
+ const e = t.match(/url\(["']?([^"')]+)["']?\)/);
28
+ return e ? e[1] : null;
29
+ }
30
+ function p(t) {
31
+ return [
32
+ /font\s*awesome/i,
33
+ /material\s*icons/i,
34
+ /ionicons/i,
35
+ /glyphicons/i,
36
+ /feather/i,
37
+ /bootstrap\s*icons/i,
38
+ /remix\s*icons/i,
39
+ /heroicons/i
40
+ ].some((n) => n.test(t));
41
+ }
42
+ function w(t, e = 3e3) {
43
+ return s.has(t) ? Promise.resolve(s.get(t)) : new Promise((n, i) => {
44
+ const c = setTimeout(() => {
45
+ i(new Error("Image load timed out"));
46
+ }, e), o = new Image();
47
+ o.crossOrigin = "anonymous", o.onload = async () => {
48
+ clearTimeout(c);
49
+ try {
50
+ await o.decode();
51
+ const r = document.createElement("canvas");
52
+ r.width = o.width, r.height = o.height, r.getContext("2d").drawImage(o, 0, 0);
53
+ try {
54
+ const a = r.toDataURL("image/png");
55
+ s.set(t, a), n(a);
56
+ } catch {
57
+ i(new Error("CORS restrictions prevented image capture"));
58
+ }
59
+ } catch (r) {
60
+ i(r);
61
+ }
62
+ }, o.onerror = (r) => {
63
+ clearTimeout(c), i(
64
+ new Error("Failed to load image: " + (r.message || "Unknown error"))
65
+ );
66
+ }, o.src = t;
67
+ });
68
+ }
69
+ function C(t) {
70
+ const e = {};
71
+ for (let n of t)
72
+ e[n] = t.getPropertyValue(n);
73
+ return e;
74
+ }
75
+ function y() {
76
+ return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
77
+ }
78
+ export {
79
+ h as extractUrl,
80
+ w as fetchImage,
81
+ d as getStyle,
82
+ g as idle,
83
+ p as isIconFont,
84
+ y as isSafari,
85
+ f as parseContent,
86
+ C as snapshotComputedStyle
87
+ };