@unicom-cloud/utils 0.1.14 → 0.1.16

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 (40) hide show
  1. package/content-disposition/index.js +34 -31
  2. package/contentDisposition.js +7 -5
  3. package/file/saveAs.js +13 -14
  4. package/lunar/lib/Holiday.js +2 -6
  5. package/lunar/lib/HolidayUtil.js +113 -99
  6. package/lunar/lib/I18n.js +395 -975
  7. package/lunar/lib/JieQi.js +12 -16
  8. package/lunar/lib/Lunar.js +224 -672
  9. package/lunar/lib/LunarMonth.js +35 -98
  10. package/lunar/lib/LunarTime.js +24 -103
  11. package/lunar/lib/LunarUtil.js +426 -1728
  12. package/lunar/lib/LunarYear.js +473 -566
  13. package/lunar/lib/ShouXingUtil.js +6714 -6690
  14. package/lunar/lib/Solar.js +24 -49
  15. package/lunar/lib/SolarHalfYear.js +0 -2
  16. package/lunar/lib/SolarMonth.js +4 -6
  17. package/lunar/lib/SolarSeason.js +0 -2
  18. package/lunar/lib/SolarUtil.js +238 -226
  19. package/lunar/lib/SolarWeek.js +7 -11
  20. package/lunar/lib/SolarYear.js +0 -1
  21. package/mock/MockWebSocket.js +2 -2
  22. package/package.json +1 -1
  23. package/snapdom/src/api/snapdom.js +72 -71
  24. package/snapdom/src/core/prepare.js +21 -21
  25. package/snapdom/src/modules/background.js +23 -17
  26. package/snapdom/src/modules/fonts.js +99 -91
  27. package/snapdom/src/modules/pseudo.js +59 -70
  28. package/tinycolor/src/conversion.js +1 -1
  29. package/tinycolor/src/index.js +2 -19
  30. package/turbo-stream/src/encode.js +5 -8
  31. package/turbo-stream/src/shared.js +117 -119
  32. package/types/file/saveAs.d.ts +1 -1
  33. package/types/lunar/lib/Lunar.d.ts +0 -98
  34. package/types/lunar/lib/LunarMonth.d.ts +0 -12
  35. package/types/lunar/lib/LunarTime.d.ts +0 -22
  36. package/types/lunar/lib/LunarUtil.d.ts +0 -90
  37. package/types/lunar/lib/LunarYear.d.ts +0 -30
  38. package/types/lunar/lib/Solar.d.ts +0 -5
  39. package/types/snapdom/src/modules/pseudo.d.ts +1 -1
  40. package/types/tinycolor/src/conversion.d.ts +1 -1
@@ -1,112 +1,113 @@
1
1
  import { captureDOM as v } from "../core/capture.js";
2
2
  import { extendIconFonts as j } from "../modules/iconFonts.js";
3
- import { isSafari as R } from "../utils/helpers.js";
4
- async function B(a, { dpr: t = 1, scale: o = 1 }) {
5
- const e = new Image();
6
- return e.src = a, await e.decode(), e.width = e.width * o, e.height = e.height * o, e;
3
+ import { isSafari as x } from "../utils/helpers.js";
4
+ async function R(e, { scale: t = 1 } = {}) {
5
+ const n = new Image();
6
+ return n.src = e, await n.decode(), t !== 1 && (n.style.width = `${n.naturalWidth * t}px`, n.style.height = `${n.naturalHeight * t}px`), n;
7
7
  }
8
- async function f(a, { dpr: t = 1, scale: o = 1 } = {}) {
9
- const e = new Image();
10
- e.src = a, e.crossOrigin = "anonymous", e.loading = "eager", e.decoding = "sync";
11
- const c = R();
12
- let n = !1;
13
- if (c && (document.body.appendChild(e), n = !0), await e.decode(), c && await new Promise((w) => setTimeout(w, 100)), e.width === 0 || e.height === 0)
14
- throw n && e.remove(), new Error("Image failed to load or has no dimensions");
15
- const s = e.width * o, r = e.height * o, g = document.createElement("canvas");
8
+ async function h(e, { dpr: t = 1, scale: n = 1 } = {}) {
9
+ const c = new Image();
10
+ c.src = e, c.crossOrigin = "anonymous", c.loading = "eager", c.decoding = "sync";
11
+ const o = x();
12
+ let a = !1;
13
+ if (o && (document.body.appendChild(c), a = !0), await c.decode(), o && await new Promise((w) => setTimeout(w, 100)), c.width === 0 || c.height === 0)
14
+ throw a && c.remove(), new Error("Image failed to load or has no dimensions");
15
+ const s = c.naturalWidth * n, r = c.naturalHeight * n, g = document.createElement("canvas");
16
16
  g.width = Math.ceil(s * t), g.height = Math.ceil(r * t), g.style.width = `${s}px`, g.style.height = `${r}px`;
17
17
  const d = g.getContext("2d");
18
- return d.scale(t, t), d.drawImage(e, 0, 0, s, r), n && e.remove(), g;
18
+ return d.scale(t, t), d.drawImage(c, 0, 0, s, r), a && c.remove(), g;
19
19
  }
20
- async function b(a, { type: t = "svg", scale: o = 1, backgroundColor: e = "#fff", quality: c } = {}) {
21
- const n = {
20
+ async function y(e, { type: t = "svg", scale: n = 1, backgroundColor: c = "#fff", quality: o } = {}) {
21
+ const a = {
22
22
  jpg: "image/jpeg",
23
23
  jpeg: "image/jpeg",
24
24
  png: "image/png",
25
25
  webp: "image/webp"
26
26
  }[t] || "image/png";
27
27
  if (t === "svg") {
28
- const r = decodeURIComponent(a.split(",")[1]);
28
+ const r = decodeURIComponent(e.split(",")[1]);
29
29
  return new Blob([r], { type: "image/svg+xml" });
30
30
  }
31
31
  const s = await u(
32
- a,
33
- { dpr: 1, scale: o },
34
- e
32
+ e,
33
+ { dpr: 1, scale: n },
34
+ c
35
35
  );
36
36
  return new Promise((r) => {
37
- s.toBlob((g) => r(g), `${n}`, c);
37
+ s.toBlob((g) => r(g), `${a}`, o);
38
38
  });
39
39
  }
40
- async function u(a, { dpr: t = 1, scale: o = 1 }, e) {
41
- const c = await f(a, { dpr: t, scale: o });
42
- if (!e) return c;
43
- const n = document.createElement("canvas");
44
- n.width = c.width, n.height = c.height;
45
- const s = n.getContext("2d");
46
- return s.fillStyle = e, s.fillRect(0, 0, n.width, n.height), s.drawImage(c, 0, 0), n;
40
+ async function u(e, { dpr: t = 1, scale: n = 1 }, c) {
41
+ const o = await h(e, { dpr: t, scale: n });
42
+ if (!c) return o;
43
+ const a = document.createElement("canvas");
44
+ a.width = o.width, a.height = o.height;
45
+ const s = a.getContext("2d");
46
+ return s.fillStyle = c, s.fillRect(0, 0, a.width, a.height), s.drawImage(o, 0, 0), a;
47
47
  }
48
- async function l(a, { dpr: t = 1, scale: o = 1, backgroundColor: e, quality: c }, n = "png") {
49
- const s = ["jpg", "jpeg", "webp"].includes(n) ? "#fff" : void 0, g = await u(a, { dpr: t, scale: o }, e ?? s), d = new Image();
50
- return d.src = g.toDataURL(`image/${n}`, c), await d.decode(), d.style.width = `${g.width / t}px`, d.style.height = `${g.height / t}px`, d;
48
+ async function m(e, { dpr: t = 1, scale: n = 1, backgroundColor: c, quality: o }, a = "png") {
49
+ const s = ["jpg", "jpeg", "webp"].includes(a) ? "#fff" : void 0, g = await u(e, { dpr: t, scale: n }, c ?? s), d = new Image();
50
+ return d.src = g.toDataURL(`image/${a}`, o), await d.decode(), d.style.width = `${g.width / t}px`, d.style.height = `${g.height / t}px`, d;
51
51
  }
52
- async function x(a, {
52
+ async function B(e, {
53
53
  dpr: t = 1,
54
- scale: o = 1,
55
- backgroundColor: e,
56
- format: c = "png",
57
- filename: n = "snapDOM"
54
+ scale: n = 1,
55
+ backgroundColor: c,
56
+ format: o = "png",
57
+ filename: a = "snapDOM"
58
58
  } = {}) {
59
- if (c === "svg") {
60
- const y = await b(a), h = URL.createObjectURL(y), m = document.createElement("a");
61
- m.href = h, m.download = `${n}.svg`, m.click(), URL.revokeObjectURL(h);
59
+ if (o === "svg") {
60
+ const b = await y(e), f = URL.createObjectURL(b), l = document.createElement("a");
61
+ l.href = f, l.download = `${a}.svg`, l.click(), URL.revokeObjectURL(f);
62
62
  return;
63
63
  }
64
- const s = ["jpg", "jpeg", "webp"].includes(c) ? "#fff" : void 0, g = await u(a, { dpr: t, scale: o }, e ?? s), d = {
64
+ const s = ["jpg", "jpeg", "webp"].includes(o) ? "#fff" : void 0, g = await u(e, { dpr: t, scale: n }, c ?? s), d = {
65
65
  jpg: "image/jpeg",
66
66
  jpeg: "image/jpeg",
67
67
  png: "image/png",
68
68
  webp: "image/webp"
69
- }[c] || "image/png", w = g.toDataURL(d), p = document.createElement("a");
70
- p.href = w, p.download = `${n}.${c}`, p.click();
69
+ }[o] || "image/png", w = g.toDataURL(d), p = document.createElement("a");
70
+ p.href = w, p.download = `${a}.${o}`, p.click();
71
71
  }
72
- async function i(a, t = {}) {
73
- if (t = { scale: 1, ...t }, !a) throw new Error("Element cannot be null or undefined");
74
- return t.iconFonts && j(t.iconFonts), await i.capture(a, t);
72
+ async function i(e, t = {}) {
73
+ if (t = { scale: 1, ...t }, !e) throw new Error("Element cannot be null or undefined");
74
+ return t.iconFonts && j(t.iconFonts), await i.capture(e, t);
75
75
  }
76
- i.capture = async (a, t = {}) => {
77
- const o = await v(a, t), e = window.devicePixelRatio || 1, c = t.scale || 1;
76
+ i.capture = async (e, t = {}) => {
77
+ const n = await v(e, t), c = t.dpr ?? (window.devicePixelRatio || 1), o = t.scale || 1;
78
78
  return {
79
- url: o,
79
+ url: n,
80
80
  options: t,
81
- toRaw: () => o,
82
- toImg: () => B(o, { dpr: e, scale: c }),
83
- toCanvas: () => f(o, { dpr: e, scale: c }),
84
- toBlob: (n) => b(o, { scale: c, ...n }),
85
- toPng: (n) => l(o, { dpr: e, scale: c, ...n }, "png"),
86
- toJpg: (n) => l(o, { dpr: e, scale: c, ...n }, "jpeg"),
87
- toWebp: (n) => l(o, { dpr: e, scale: c, ...n }, "webp"),
81
+ toRaw: () => n,
82
+ toImg: (a = {}) => R(n, { scale: o, ...a }),
83
+ toCanvas: (a = {}) => h(n, { dpr: c, scale: o, ...a }),
84
+ toBlob: (a = {}) => y(n, { scale: o, ...a }),
85
+ toPng: (a = {}) => m(n, { dpr: c, scale: o, ...a }, "png"),
86
+ toJpg: (a = {}) => m(n, { dpr: c, scale: o, ...a }, "jpeg"),
87
+ toWebp: (a = {}) => m(n, { dpr: c, scale: o, ...a }, "webp"),
88
88
  download: ({
89
- format: n = "png",
90
- filename: s = "capture",
91
- backgroundColor: r
92
- } = {}) => x(o, { dpr: e, scale: c, backgroundColor: r, format: n, filename: s })
89
+ format: a = "png",
90
+ filename: s = "snapDOM",
91
+ backgroundColor: r,
92
+ ...g
93
+ } = {}) => B(n, { dpr: c, scale: o, format: a, filename: s, backgroundColor: r, ...g })
93
94
  };
94
95
  };
95
- i.toRaw = async (a, t) => (await i.capture(a, t)).toRaw();
96
- i.toImg = async (a, t) => (await i.capture(a, t)).toImg();
97
- i.toCanvas = async (a, t) => (await i.capture(a, t)).toCanvas();
98
- i.toBlob = async (a, t) => (await i.capture(a, t)).toBlob(t);
99
- i.toPng = async (a, t) => (await i.capture(a, t)).toPng(t);
100
- i.toJpg = async (a, t) => (await i.capture(a, t)).toJpg(t);
101
- i.toWebp = async (a, t) => (await i.capture(a, t)).toWebp(t);
102
- i.download = async (a, t = {}) => {
96
+ i.toRaw = async (e, t) => (await i.capture(e, t)).toRaw();
97
+ i.toImg = async (e, t) => (await i.capture(e, t)).toImg();
98
+ i.toCanvas = async (e, t) => (await i.capture(e, t)).toCanvas();
99
+ i.toBlob = async (e, t) => (await i.capture(e, t)).toBlob(t);
100
+ i.toPng = async (e, t) => (await i.capture(e, t)).toPng(t);
101
+ i.toJpg = async (e, t) => (await i.capture(e, t)).toJpg(t);
102
+ i.toWebp = async (e, t) => (await i.capture(e, t)).toWebp(t);
103
+ i.download = async (e, t = {}) => {
103
104
  const {
104
- format: o = "png",
105
- filename: e = "capture",
106
- backgroundColor: c,
107
- ...n
105
+ format: n = "png",
106
+ filename: c = "capture",
107
+ backgroundColor: o,
108
+ ...a
108
109
  } = t;
109
- return await (await i.capture(a, n)).download({ format: o, filename: e, backgroundColor: c });
110
+ return await (await i.capture(e, a)).download({ format: n, filename: c, backgroundColor: o });
110
111
  };
111
112
  export {
112
113
  i as snapdom
@@ -1,22 +1,22 @@
1
- import { cache as n } from "./cache.js";
1
+ import { cache as s } from "./cache.js";
2
2
  import { inlinePseudoElements as p } from "../modules/pseudo.js";
3
3
  import { inlineExternalDef as m } from "../modules/svgDefs.js";
4
4
  import { generateCSSClasses as g } from "../utils/cssTools.js";
5
5
  import { stripTranslate as u } from "../utils/helpers.js";
6
6
  import { deepClone as h } from "./clone.js";
7
- async function k(l, c = !1, d = !1, f = {}) {
8
- let o, y = "";
7
+ async function k(n, c = !1, y = !1, f = {}) {
8
+ let o, d = "";
9
9
  try {
10
- o = h(l, c, f, l);
10
+ o = h(n, c, f, n);
11
11
  } catch (e) {
12
12
  throw console.warn("deepClone failed:", e), e;
13
13
  }
14
14
  try {
15
15
  await p(
16
- l,
16
+ n,
17
17
  o,
18
18
  c,
19
- d,
19
+ y,
20
20
  f.useProxy
21
21
  );
22
22
  } catch (e) {
@@ -29,36 +29,36 @@ async function k(l, c = !1, d = !1, f = {}) {
29
29
  }
30
30
  if (c) {
31
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()) {
32
+ d = Array.from(e.entries()).map(([t, r]) => `.${r}{${t}}`).join("");
33
+ for (const [t, r] of s.preStyleMap.entries()) {
34
34
  if (t.tagName === "STYLE") continue;
35
35
  const a = e.get(r);
36
36
  a && t.classList.add(a);
37
- const i = t.style?.backgroundImage;
38
- t.removeAttribute("style"), i && i !== "none" && (t.style.backgroundImage = i);
37
+ const i = t.style?.backgroundImage, l = t.dataset?.snapdomHasIcon;
38
+ t.removeAttribute("style"), i && i !== "none" && (t.style.backgroundImage = i), l && (t.style.verticalAlign = "middle", t.style.display = "inline");
39
39
  }
40
40
  } else
41
- for (const [e, t] of n.preStyleMap.entries())
41
+ for (const [e, t] of s.preStyleMap.entries())
42
42
  e.tagName !== "STYLE" && e.setAttribute("style", t.replace(/;/g, "; "));
43
- for (const [e, t] of n.preNodeMap.entries()) {
43
+ for (const [e, t] of s.preNodeMap.entries()) {
44
44
  const r = t.scrollLeft, a = t.scrollTop;
45
45
  if ((r || a) && e instanceof HTMLElement) {
46
46
  e.style.overflow = "hidden", e.style.scrollbarWidth = "none", e.style.msOverflowStyle = "none";
47
- const s = document.createElement("div");
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; )
49
- s.appendChild(e.firstChild);
50
- e.appendChild(s);
47
+ const l = document.createElement("div");
48
+ for (l.style.transform = `translate(${-r}px, ${-a}px)`, l.style.willChange = "transform", l.style.display = "inline-block", l.style.width = "100%"; e.firstChild; )
49
+ l.appendChild(e.firstChild);
50
+ e.appendChild(l);
51
51
  }
52
52
  }
53
- if (l === n.preNodeMap.get(o)) {
54
- const e = n.preStyle.get(l) || window.getComputedStyle(l);
55
- n.preStyle.set(l, e);
53
+ if (n === s.preNodeMap.get(o)) {
54
+ const e = s.preStyle.get(n) || window.getComputedStyle(n);
55
+ s.preStyle.set(n, e);
56
56
  const t = u(e.transform);
57
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 || "";
58
58
  }
59
- for (const [e, t] of n.preNodeMap.entries())
59
+ for (const [e, t] of s.preNodeMap.entries())
60
60
  t.tagName === "PRE" && (e.style.marginTop = "0", e.style.marginBlockStart = "0");
61
- return { clone: o, classCSS: y };
61
+ return { clone: o, classCSS: d };
62
62
  }
63
63
  export {
64
64
  k as prepareClone
@@ -1,7 +1,7 @@
1
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 = [
2
+ import { getStyle as f, splitBackgroundImage as h, inlineSingleBackgroundEntry as y } from "../utils/helpers.js";
3
+ async function S(d, u, b = {}) {
4
+ const n = [[d, u]], p = [
5
5
  "background-image",
6
6
  "mask",
7
7
  "mask-image",
@@ -9,26 +9,32 @@ async function w(u, d, k = {}) {
9
9
  "mask-source",
10
10
  "mask-box-image-source",
11
11
  "mask-border-source",
12
- "-webkit-mask-box-image-source"
12
+ "-webkit-mask-box-image-source",
13
+ "border-image",
14
+ "border-image-source",
15
+ "border-image-slice",
16
+ "border-image-width",
17
+ "border-image-outset",
18
+ "border-image-repeat"
13
19
  ];
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);
20
+ for (; n.length; ) {
21
+ const [r, i] = n.shift(), s = c.preStyle.get(r) || f(r);
22
+ c.preStyle.has(r) || c.preStyle.set(r, s);
17
23
  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))
24
+ const a = s.getPropertyValue(e);
25
+ if (!a || a === "none") continue;
26
+ const k = h(a), g = await Promise.all(
27
+ k.map((o) => y(o, b))
22
28
  );
23
- g.some((r) => r && r !== "none" && !/^url\(undefined/.test(r)) && s.style.setProperty(e, g.join(", "));
29
+ g.some((o) => o && o !== "none" && !/^url\(undefined/.test(o)) && i.style.setProperty(e, g.join(", "));
24
30
  }
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);
31
+ const t = s.getPropertyValue("background-color");
32
+ t && t !== "transparent" && t !== "rgba(0, 0, 0, 0)" && (i.style.backgroundColor = t);
33
+ const l = Array.from(r.children), m = Array.from(i.children);
28
34
  for (let e = 0; e < Math.min(l.length, m.length); e++)
29
- t.push([l[e], m[e]]);
35
+ n.push([l[e], m[e]]);
30
36
  }
31
37
  }
32
38
  export {
33
- w as inlineBackgroundImages
39
+ S as inlineBackgroundImages
34
40
  };
@@ -1,139 +1,147 @@
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(m, i, a, p = 32, u = "#000") {
1
+ import { cache as n } from "../core/cache.js";
2
+ import { isIconFont as h } from "./iconFonts.js";
3
+ import { extractURL as U } from "../utils/helpers.js";
4
+ async function E(m, i, l, y = 32, u = "#000") {
5
5
  i = i.replace(/^['"]+|['"]+$/g, "");
6
- const t = window.devicePixelRatio || 1, s = document.createElement("canvas").getContext("2d");
7
- s.font = a ? `${a} ${p}px "${i}"` : `${p}px "${i}"`;
8
- const c = s.measureText(m), 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 = u, h.fillText(m, 0, l), e.toDataURL();
6
+ const t = window.devicePixelRatio || 1;
7
+ await document.fonts.ready;
8
+ const e = document.createElement("span");
9
+ e.textContent = m, e.style.position = "absolute", e.style.visibility = "hidden", e.style.fontFamily = `"${i}"`, e.style.fontWeight = l || "normal", e.style.fontSize = `${y}px`, e.style.lineHeight = "1", e.style.whiteSpace = "nowrap", e.style.padding = "0", e.style.margin = "0", document.body.appendChild(e);
10
+ const r = e.getBoundingClientRect(), d = Math.ceil(r.width), f = Math.ceil(r.height);
11
+ document.body.removeChild(e);
12
+ const c = document.createElement("canvas");
13
+ c.width = d * t, c.height = f * t;
14
+ const s = c.getContext("2d");
15
+ return s.scale(t, t), s.font = l ? `${l} ${y}px "${i}"` : `${y}px "${i}"`, s.textAlign = "left", s.textBaseline = "top", s.fillStyle = u, s.fillText(m, 0, 0), {
16
+ dataUrl: c.toDataURL(),
17
+ width: d,
18
+ height: f
19
+ };
12
20
  }
13
- function $(m) {
21
+ function x(m) {
14
22
  return Array.from(document.styleSheets).some((i) => i.href === m);
15
23
  }
16
- function P(m) {
24
+ function L(m) {
17
25
  return new Promise((i) => {
18
- if ($(m)) return i(null);
19
- const a = document.createElement("link");
20
- a.rel = "stylesheet", a.href = m, a.setAttribute("data-snapdom", "injected-import"), a.onload = () => i(a), a.onerror = () => i(null), document.head.appendChild(a);
26
+ if (x(m)) return i(null);
27
+ const l = document.createElement("link");
28
+ l.rel = "stylesheet", l.href = m, l.setAttribute("data-snapdom", "injected-import"), l.onload = () => i(l), l.onerror = () => i(null), document.head.appendChild(l);
21
29
  });
22
30
  }
23
- async function T({ preCached: m = !1 } = {}) {
24
- if (o.resource.has("fonts-embed-css")) {
31
+ async function k({ preCached: m = !1 } = {}) {
32
+ if (n.resource.has("fonts-embed-css")) {
25
33
  if (m) {
26
34
  const t = document.createElement("style");
27
- t.setAttribute("data-snapdom", "embedFonts"), t.textContent = o.resource.get("fonts-embed-css"), document.head.appendChild(t);
35
+ t.setAttribute("data-snapdom", "embedFonts"), t.textContent = n.resource.get("fonts-embed-css"), document.head.appendChild(t);
28
36
  }
29
- return o.resource.get("fonts-embed-css");
37
+ return n.resource.get("fonts-embed-css");
30
38
  }
31
- const i = /@import\s+url\(["']?([^"')]+)["']?\)/g, a = [];
39
+ const i = /@import\s+url\(["']?([^"')]+)["']?\)/g, l = [];
32
40
  for (const t of document.querySelectorAll("style")) {
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);
41
+ const e = t.textContent || "", r = Array.from(e.matchAll(i));
42
+ for (const d of r) {
43
+ const f = d[1];
44
+ h(f) || x(f) || l.push(f);
37
45
  }
38
46
  }
39
- await Promise.all(a.map(P));
40
- const p = Array.from(
47
+ await Promise.all(l.map(L));
48
+ const y = Array.from(
41
49
  document.querySelectorAll('link[rel="stylesheet"]')
42
50
  ).filter((t) => t.href);
43
51
  let u = "";
44
- for (const t of p)
52
+ for (const t of y)
45
53
  try {
46
- const s = await (await fetch(t.href)).text();
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
- original: d[0],
57
- inlined: `url(${o.resource.get(e)})`
54
+ const r = await (await fetch(t.href)).text();
55
+ if (h(t.href) || h(r)) continue;
56
+ const d = /url\((["']?)([^"')]+)\1\)/g, f = await Promise.all(
57
+ Array.from(r.matchAll(d)).map(async (s) => {
58
+ let b = U(s[0]);
59
+ if (!b) return null;
60
+ let o = b;
61
+ if (!o.startsWith("http") && !o.startsWith("data:") && (o = new URL(o, t.href).href), h(o)) return null;
62
+ if (n.resource.has(o))
63
+ return n.font.add(o), {
64
+ original: s[0],
65
+ inlined: `url(${n.resource.get(o)})`
58
66
  };
59
- if (o.font.has(e)) return null;
67
+ if (n.font.has(o)) return null;
60
68
  try {
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);
69
+ const p = await (await fetch(o)).blob(), w = await new Promise((a) => {
70
+ const g = new FileReader();
71
+ g.onload = () => a(g.result), g.readAsDataURL(p);
64
72
  });
65
- return o.resource.set(e, b), o.font.add(e), { original: d[0], inlined: `url(${b})` };
73
+ return n.resource.set(o, w), n.font.add(o), { original: s[0], inlined: `url(${w})` };
66
74
  } catch {
67
- return console.warn("[snapdom] Failed to fetch font resource:", e), null;
75
+ return console.warn("[snapdom] Failed to fetch font resource:", o), null;
68
76
  }
69
77
  })
70
78
  );
71
- let f = s;
72
- for (const d of l)
73
- d && (f = f.replace(d.original, d.inlined));
74
- u += f + `
79
+ let c = r;
80
+ for (const s of f)
81
+ s && (c = c.replace(s.original, s.inlined));
82
+ u += c + `
75
83
  `;
76
84
  } catch {
77
85
  console.warn("[snapdom] Failed to fetch CSS:", t.href);
78
86
  }
79
87
  for (const t of document.styleSheets)
80
88
  try {
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 = !!s.match(l), w = !!s.match(f);
87
- if (!d && w) {
88
- u += `@font-face{font-family:${c};src:${s};font-style:${n.style.getPropertyValue("font-style") || "normal"};font-weight:${n.style.getPropertyValue("font-weight") || "normal"};}`;
89
+ if (!t.href || y.every((e) => e.href !== t.href)) {
90
+ for (const e of t.cssRules)
91
+ if (e.type === CSSRule.FONT_FACE_RULE) {
92
+ const r = e.style.getPropertyValue("src"), d = e.style.getPropertyValue("font-family");
93
+ if (!r || h(d)) continue;
94
+ const f = /url\((["']?)([^"')]+)\1\)/g, c = /local\((["']?)[^)]+?\1\)/g, s = !!r.match(f), b = !!r.match(c);
95
+ if (!s && b) {
96
+ u += `@font-face{font-family:${d};src:${r};font-style:${e.style.getPropertyValue("font-style") || "normal"};font-weight:${e.style.getPropertyValue("font-weight") || "normal"};}`;
89
97
  continue;
90
98
  }
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)})`
99
+ let o = r;
100
+ const S = Array.from(r.matchAll(f));
101
+ for (const p of S) {
102
+ let w = p[2].trim();
103
+ if (!w) continue;
104
+ let a = w;
105
+ if (!a.startsWith("http") && !a.startsWith("data:") && (a = new URL(a, t.href || location.href).href), !h(a)) {
106
+ if (n.resource.has(a)) {
107
+ n.font.add(a), o = o.replace(
108
+ p[0],
109
+ `url(${n.resource.get(a)})`
102
110
  );
103
111
  continue;
104
112
  }
105
- if (!o.font.has(r))
113
+ if (!n.font.has(a))
106
114
  try {
107
- const A = await (await fetch(r)).blob(), S = await new Promise((C) => {
108
- const R = new FileReader();
109
- R.onload = () => C(R.result), R.readAsDataURL(A);
115
+ const A = await (await fetch(a)).blob(), R = await new Promise((C) => {
116
+ const $ = new FileReader();
117
+ $.onload = () => C($.result), $.readAsDataURL(A);
110
118
  });
111
- o.resource.set(r, S), o.font.add(r), e = e.replace(g[0], `url(${S})`);
119
+ n.resource.set(a, R), n.font.add(a), o = o.replace(p[0], `url(${R})`);
112
120
  } catch {
113
- console.warn("[snapdom] Failed to fetch font URL:", r);
121
+ console.warn("[snapdom] Failed to fetch font URL:", a);
114
122
  }
115
123
  }
116
124
  }
117
- u += `@font-face{font-family:${c};src:${e};font-style:${n.style.getPropertyValue("font-style") || "normal"};font-weight:${n.style.getPropertyValue("font-weight") || "normal"};}`;
125
+ u += `@font-face{font-family:${d};src:${o};font-style:${e.style.getPropertyValue("font-style") || "normal"};font-weight:${e.style.getPropertyValue("font-weight") || "normal"};}`;
118
126
  }
119
127
  }
120
- } catch (n) {
121
- console.warn("[snapdom] Cannot access stylesheet", t.href, n);
128
+ } catch (e) {
129
+ console.warn("[snapdom] Cannot access stylesheet", t.href, e);
122
130
  }
123
131
  for (const t of document.fonts)
124
132
  if (t.family && t.status === "loaded" && 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
+ if (h(t.family)) continue;
134
+ let e = t._snapdomSrc;
135
+ if (!e.startsWith("data:")) {
136
+ if (n.resource.has(t._snapdomSrc))
137
+ e = n.resource.get(t._snapdomSrc), n.font.add(t._snapdomSrc);
138
+ else if (!n.font.has(t._snapdomSrc))
131
139
  try {
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);
140
+ const d = await (await fetch(t._snapdomSrc)).blob();
141
+ e = await new Promise((f) => {
142
+ const c = new FileReader();
143
+ c.onload = () => f(c.result), c.readAsDataURL(d);
144
+ }), n.resource.set(t._snapdomSrc, e), n.font.add(t._snapdomSrc);
137
145
  } catch {
138
146
  console.warn(
139
147
  "[snapdom] Failed to fetch dynamic font src:",
@@ -142,15 +150,15 @@ async function T({ preCached: m = !1 } = {}) {
142
150
  continue;
143
151
  }
144
152
  }
145
- u += `@font-face{font-family:'${t.family}';src:url(${n});font-style:${t.style || "normal"};font-weight:${t.weight || "normal"};}`;
153
+ u += `@font-face{font-family:'${t.family}';src:url(${e});font-style:${t.style || "normal"};font-weight:${t.weight || "normal"};}`;
146
154
  }
147
- if (u && (o.resource.set("fonts-embed-css", u), m)) {
155
+ if (u && (n.resource.set("fonts-embed-css", u), m)) {
148
156
  const t = document.createElement("style");
149
157
  t.setAttribute("data-snapdom", "embedFonts"), t.textContent = u, document.head.appendChild(t);
150
158
  }
151
159
  return u;
152
160
  }
153
161
  export {
154
- T as embedCustomFonts,
162
+ k as embedCustomFonts,
155
163
  E as iconToImage
156
164
  };