@unicom-cloud/utils 0.1.11 → 0.1.12

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 (107) hide show
  1. package/date/index.js +22 -0
  2. package/date.js +9 -0
  3. package/index.js +56 -54
  4. package/lunar/index.js +36 -0
  5. package/lunar/lib/Holiday.js +42 -0
  6. package/lunar/lib/HolidayUtil.js +128 -0
  7. package/lunar/lib/I18n.js +1005 -0
  8. package/lunar/lib/JieQi.js +40 -0
  9. package/lunar/lib/Lunar.js +1035 -0
  10. package/lunar/lib/LunarMonth.js +150 -0
  11. package/lunar/lib/LunarTime.js +138 -0
  12. package/lunar/lib/LunarUtil.js +1752 -0
  13. package/lunar/lib/LunarYear.js +616 -0
  14. package/lunar/lib/ShouXingUtil.js +6915 -0
  15. package/lunar/lib/Solar.js +311 -0
  16. package/lunar/lib/SolarHalfYear.js +45 -0
  17. package/lunar/lib/SolarMonth.js +55 -0
  18. package/lunar/lib/SolarSeason.js +42 -0
  19. package/lunar/lib/SolarUtil.js +256 -0
  20. package/lunar/lib/SolarWeek.js +153 -0
  21. package/lunar/lib/SolarYear.js +35 -0
  22. package/lunar/lib/index.js +35 -0
  23. package/lunar.js +36 -0
  24. package/package.json +1 -1
  25. package/snapdom/src/api/preCache.js +26 -36
  26. package/snapdom/src/api/snapdom.js +78 -61
  27. package/snapdom/src/core/capture.js +54 -54
  28. package/snapdom/src/core/prepare.js +46 -37
  29. package/snapdom/src/modules/fonts.js +90 -92
  30. package/snapdom/src/modules/iconFonts.js +28 -0
  31. package/snapdom/src/modules/images.js +6 -6
  32. package/snapdom/src/modules/pseudo.js +51 -49
  33. package/snapdom/src/modules/styles.js +27 -7
  34. package/snapdom/src/modules/svgDefs.js +26 -0
  35. package/snapdom/src/utils/helpers.js +150 -103
  36. package/tinycolor/index.js +46 -0
  37. package/tinycolor/src/conversion.js +143 -0
  38. package/tinycolor/src/css-color-names.js +153 -0
  39. package/tinycolor/src/format-input.js +77 -0
  40. package/tinycolor/src/from-ratio.js +21 -0
  41. package/tinycolor/src/index.js +404 -0
  42. package/tinycolor/src/random.js +221 -0
  43. package/tinycolor/src/readability.js +37 -0
  44. package/tinycolor/src/to-ms-filter.js +15 -0
  45. package/tinycolor/src/util.js +32 -0
  46. package/tinycolor.js +46 -0
  47. package/tree/index.js +10 -8
  48. package/tree.js +9 -7
  49. package/types/date/index.d.ts +4 -0
  50. package/types/index.d.ts +4 -3
  51. package/types/lunar/index.d.ts +3 -0
  52. package/types/lunar/lib/Holiday.d.ts +17 -0
  53. package/types/lunar/lib/HolidayUtil.d.ts +23 -0
  54. package/types/lunar/lib/I18n.d.ts +23 -0
  55. package/types/lunar/lib/JieQi.d.ts +15 -0
  56. package/types/lunar/lib/Lunar.d.ts +245 -0
  57. package/types/lunar/lib/LunarMonth.d.ts +35 -0
  58. package/types/lunar/lib/LunarTime.d.ts +40 -0
  59. package/types/lunar/lib/LunarUtil.d.ts +128 -0
  60. package/types/lunar/lib/LunarYear.d.ts +61 -0
  61. package/types/lunar/lib/ShouXingUtil.d.ts +38 -0
  62. package/types/lunar/lib/Solar.d.ts +51 -0
  63. package/types/lunar/lib/SolarHalfYear.d.ts +15 -0
  64. package/types/lunar/lib/SolarMonth.d.ts +16 -0
  65. package/types/lunar/lib/SolarSeason.d.ts +15 -0
  66. package/types/lunar/lib/SolarUtil.d.ts +20 -0
  67. package/types/lunar/lib/SolarWeek.d.ts +23 -0
  68. package/types/lunar/lib/SolarYear.d.ts +12 -0
  69. package/types/lunar/lib/index.d.ts +17 -0
  70. package/types/snapdom/src/core/prepare.d.ts +1 -1
  71. package/types/snapdom/src/modules/fonts.d.ts +1 -3
  72. package/types/snapdom/src/modules/iconFonts.d.ts +2 -0
  73. package/types/snapdom/src/modules/pseudo.d.ts +1 -1
  74. package/types/snapdom/src/modules/styles.d.ts +1 -10
  75. package/types/snapdom/src/modules/svgDefs.d.ts +19 -0
  76. package/types/snapdom/src/utils/helpers.d.ts +1 -1
  77. package/types/tinycolor/index.d.ts +2 -0
  78. package/types/tinycolor/src/conversion.d.ts +79 -0
  79. package/types/tinycolor/src/css-color-names.d.ts +4 -0
  80. package/types/tinycolor/src/format-input.d.ts +38 -0
  81. package/types/tinycolor/src/from-ratio.d.ts +14 -0
  82. package/types/tinycolor/src/index.d.ts +214 -0
  83. package/types/tinycolor/src/interfaces.d.ts +57 -0
  84. package/types/tinycolor/src/public_api.d.ts +10 -0
  85. package/types/tinycolor/src/random.d.ts +24 -0
  86. package/types/tinycolor/src/readability.d.ts +46 -0
  87. package/types/tinycolor/src/to-ms-filter.d.ts +5 -0
  88. package/types/tinycolor/src/umd_api.d.ts +22 -0
  89. package/types/tinycolor/src/util.d.ts +36 -0
  90. package/types/tree/index.d.ts +1 -0
  91. package/types/ui-color/compareColorByRange.d.ts +2 -0
  92. package/types/ui-color/index.d.ts +183 -0
  93. package/ui-color/compareColorByRange.js +9 -0
  94. package/ui-color/index.js +155 -0
  95. package/uiColor.js +28 -0
  96. package/convertTime.js +0 -4
  97. package/dayjs/index.js +0 -15
  98. package/dayjs.js +0 -5
  99. package/lunar-converter/index.js +0 -641
  100. package/lunarConverter.js +0 -4
  101. package/searchTree.js +0 -4
  102. package/types/dayjs/index.d.ts +0 -1
  103. package/types/lunar-converter/index.d.ts +0 -113
  104. /package/{convert-time/index.js → date/convertTime.js} +0 -0
  105. /package/{search-tree/index.js → tree/searchTree.js} +0 -0
  106. /package/types/{convert-time/index.d.ts → date/convertTime.d.ts} +0 -0
  107. /package/types/{search-tree/index.d.ts → tree/searchTree.d.ts} +0 -0
@@ -1,143 +1,141 @@
1
1
  import { resourceCache as c, processedFontURLs as h } from "../core/cache.js";
2
- import { isIconFont as b, extractURL as $ } from "../utils/helpers.js";
3
- async function _(f, a, l, p = 32, g = "#000") {
4
- a = a.replace(/^['"]+|['"]+$/g, "");
5
- const i = window.devicePixelRatio || 1, n = document.createElement("canvas").getContext("2d");
6
- n.font = l ? `${l} ${p}px "${a}"` : `${p}px "${a}"`;
7
- const o = n.measureText(f), m = o.actualBoundingBoxAscent || p * 0.8, s = o.actualBoundingBoxDescent || p * 0.2, d = m + s, r = o.width, u = document.createElement("canvas");
8
- u.width = Math.ceil(r * i), u.height = Math.ceil(d * i);
9
- const e = u.getContext("2d");
10
- return e.scale(i, i), e.font = n.font, e.textAlign = "left", e.textBaseline = "alphabetic", e.fillStyle = g, e.fillText(f, 0, m), u.toDataURL();
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, "");
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();
11
12
  }
12
- function A(f) {
13
- return Array.from(document.styleSheets).some((a) => a.href === f);
13
+ function A(m) {
14
+ return Array.from(document.styleSheets).some((l) => l.href === m);
14
15
  }
15
- function C(f) {
16
- return new Promise((a) => {
17
- if (A(f)) return a(null);
18
- const l = document.createElement("link");
19
- l.rel = "stylesheet", l.href = f, l.setAttribute("data-snapdom", "injected-import"), l.onload = () => a(l), l.onerror = () => a(null), document.head.appendChild(l);
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);
20
21
  });
21
22
  }
22
- async function P({
23
- ignoreIconFonts: f = !0,
24
- preCached: a = !1
25
- } = {}) {
23
+ async function P({ preCached: m = !1 } = {}) {
26
24
  if (c.has("fonts-embed-css")) {
27
- if (a) {
25
+ if (m) {
28
26
  const t = document.createElement("style");
29
27
  t.setAttribute("data-snapdom", "embedFonts"), t.textContent = c.get("fonts-embed-css"), document.head.appendChild(t);
30
28
  }
31
29
  return c.get("fonts-embed-css");
32
30
  }
33
- const l = /@import\s+url\(["']?([^"')]+)["']?\)/g, p = [];
31
+ const l = /@import\s+url\(["']?([^"')]+)["']?\)/g, r = [];
34
32
  for (const t of document.querySelectorAll("style")) {
35
- const n = t.textContent || "", o = Array.from(n.matchAll(l));
36
- for (const m of o) {
37
- const s = m[1];
38
- A(s) || p.push(s);
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);
39
37
  }
40
38
  }
41
- await Promise.all(p.map(C));
42
- const g = Array.from(
39
+ await Promise.all(r.map(C));
40
+ const y = Array.from(
43
41
  document.querySelectorAll('link[rel="stylesheet"]')
44
42
  ).filter((t) => t.href);
45
- let i = "";
46
- for (const t of g)
43
+ let u = "";
44
+ for (const t of y)
47
45
  try {
48
- const o = await (await fetch(t.href)).text();
49
- if (f && (b(t.href) || b(o)))
50
- continue;
51
- const m = /url\((["']?)([^"')]+)\1\)/g, s = await Promise.all(
52
- Array.from(o.matchAll(m)).map(async (r) => {
53
- let u = $(r[0]);
54
- if (!u) return null;
55
- let e = u;
56
- if (!e.startsWith("http") && !e.startsWith("data:") && (e = new URL(e, t.href).href), f && b(e)) return null;
57
- if (c.has(e))
58
- return h.add(e), {
59
- original: r[0],
60
- inlined: `url(${c.get(e)})`
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), {
56
+ original: d[0],
57
+ inlined: `url(${c.get(n)})`
61
58
  };
62
- if (h.has(e)) return null;
59
+ if (h.has(n)) return null;
63
60
  try {
64
- const S = await (await fetch(e)).blob(), w = await new Promise((R) => {
65
- const y = new FileReader();
66
- y.onload = () => R(y.result), y.readAsDataURL(S);
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);
67
64
  });
68
- return c.set(e, w), h.add(e), { original: r[0], inlined: `url(${w})` };
65
+ return c.set(n, b), h.add(n), { original: d[0], inlined: `url(${b})` };
69
66
  } catch {
70
- return console.warn("[snapdom] Failed to fetch font resource:", e), null;
67
+ return console.warn("[snapdom] Failed to fetch font resource:", n), null;
71
68
  }
72
69
  })
73
70
  );
74
- let d = o;
75
- for (const r of s)
76
- r && (d = d.replace(r.original, r.inlined));
77
- i += d + `
71
+ let a = s;
72
+ for (const d of f)
73
+ d && (a = a.replace(d.original, d.inlined));
74
+ u += a + `
78
75
  `;
79
76
  } catch {
80
77
  console.warn("[snapdom] Failed to fetch CSS:", t.href);
81
78
  }
82
79
  for (const t of document.styleSheets)
83
80
  try {
84
- if (!t.href || g.every((n) => n.href !== t.href)) {
85
- for (const n of t.cssRules)
86
- if (n.type === CSSRule.FONT_FACE_RULE) {
87
- const o = n.style.getPropertyValue("src");
88
- if (!o) continue;
89
- const m = /url\((["']?)([^"')]+)\1\)/g;
90
- let s = o;
91
- const d = Array.from(o.matchAll(m));
92
- for (const r of d) {
93
- let u = r[2].trim();
94
- if (!u) continue;
95
- let e = u;
96
- if (!e.startsWith("http") && !e.startsWith("data:") && (e = new URL(e, t.href || location.href).href), !(f && b(e))) {
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)) {
97
94
  if (c.has(e)) {
98
- h.add(e), s = s.replace(
99
- r[0],
95
+ h.add(e), a = a.replace(
96
+ p[0],
100
97
  `url(${c.get(e)})`
101
98
  );
102
99
  continue;
103
100
  }
104
101
  if (!h.has(e))
105
102
  try {
106
- const S = await (await fetch(e)).blob(), w = await new Promise((R) => {
107
- const y = new FileReader();
108
- y.onload = () => R(y.result), y.readAsDataURL(S);
103
+ const b = await (await fetch(e)).blob(), x = await new Promise((g) => {
104
+ const R = new FileReader();
105
+ R.onload = () => g(R.result), R.readAsDataURL(b);
109
106
  });
110
- c.set(e, w), h.add(e), s = s.replace(r[0], `url(${w})`);
107
+ c.set(e, x), h.add(e), a = a.replace(p[0], `url(${x})`);
111
108
  } catch {
112
109
  console.warn("[snapdom] Failed to fetch font URL:", e);
113
110
  }
114
111
  }
115
112
  }
116
- i += `@font-face {
117
- font-family: ${n.style.getPropertyValue("font-family")};
118
- src: ${s};
119
- font-style: ${n.style.getPropertyValue("font-style") || "normal"};
120
- font-weight: ${n.style.getPropertyValue("font-weight") || "normal"};
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"};
121
118
  }
122
119
  `;
123
120
  }
124
121
  }
125
- } catch (n) {
126
- console.warn("[snapdom] Cannot access stylesheet", t.href, n);
122
+ } catch (o) {
123
+ console.warn("[snapdom] Cannot access stylesheet", t.href, o);
127
124
  }
128
125
  for (const t of document.fonts)
129
126
  if (t.family && t.status === "loaded" && t._snapdomSrc) {
130
- let n = t._snapdomSrc;
131
- if (!n.startsWith("data:")) {
127
+ if (w(t.family)) continue;
128
+ let o = t._snapdomSrc;
129
+ if (!o.startsWith("data:")) {
132
130
  if (c.has(t._snapdomSrc))
133
- n = c.get(t._snapdomSrc), h.add(t._snapdomSrc);
131
+ o = c.get(t._snapdomSrc), h.add(t._snapdomSrc);
134
132
  else if (!h.has(t._snapdomSrc))
135
133
  try {
136
- const m = await (await fetch(t._snapdomSrc)).blob();
137
- n = await new Promise((s) => {
138
- const d = new FileReader();
139
- d.onload = () => s(d.result), d.readAsDataURL(m);
140
- }), c.set(t._snapdomSrc, n), h.add(t._snapdomSrc);
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);
141
139
  } catch {
142
140
  console.warn(
143
141
  "[snapdom] Failed to fetch dynamic font src:",
@@ -146,19 +144,19 @@ async function P({
146
144
  continue;
147
145
  }
148
146
  }
149
- i += `@font-face {
147
+ u += `@font-face {
150
148
  font-family: '${t.family}';
151
- src: url(${n});
149
+ src: url(${o});
152
150
  font-style: ${t.style || "normal"};
153
151
  font-weight: ${t.weight || "normal"};
154
152
  }
155
153
  `;
156
154
  }
157
- if (i && (c.set("fonts-embed-css", i), a)) {
155
+ if (u && (c.set("fonts-embed-css", u), m)) {
158
156
  const t = document.createElement("style");
159
- t.setAttribute("data-snapdom", "embedFonts"), t.textContent = i, document.head.appendChild(t);
157
+ t.setAttribute("data-snapdom", "embedFonts"), t.textContent = u, document.head.appendChild(t);
160
158
  }
161
- return i;
159
+ return u;
162
160
  }
163
161
  export {
164
162
  P as embedCustomFonts,
@@ -0,0 +1,28 @@
1
+ var s = [
2
+ // /uicons/i,
3
+ /font\s*awesome/i,
4
+ /material\s*icons/i,
5
+ /ionicons/i,
6
+ /glyphicons/i,
7
+ /feather/i,
8
+ /bootstrap\s*icons/i,
9
+ /remix\s*icons/i,
10
+ /heroicons/i,
11
+ /layui/i,
12
+ /lucide/i
13
+ ], o = [];
14
+ function r(i) {
15
+ const e = Array.isArray(i) ? i : [i];
16
+ for (const t of e)
17
+ t instanceof RegExp ? o.push(t) : typeof t == "string" ? o.push(new RegExp(t, "i")) : console.warn("[snapdom] Ignored invalid iconFont value:", t);
18
+ }
19
+ function c(i) {
20
+ const e = typeof i == "string" ? i : "", t = [...s, ...o];
21
+ for (const n of t)
22
+ if (n instanceof RegExp && n.test(e)) return !0;
23
+ return !!(/icon/i.test(e) || /glyph/i.test(e) || /symbols/i.test(e) || /feather/i.test(e) || /fontawesome/i.test(e));
24
+ }
25
+ export {
26
+ r as extendIconFonts,
27
+ c as isIconFont
28
+ };
@@ -1,17 +1,17 @@
1
- import { fetchImage as o } from "../utils/helpers.js";
2
- async function h(i, n = {}) {
3
- const r = Array.from(i.querySelectorAll("img")), s = async (t) => {
1
+ import { fetchImage as l } from "../utils/helpers.js";
2
+ async function h(n, a = {}) {
3
+ const r = Array.from(n.querySelectorAll("img")), i = async (t) => {
4
4
  const c = t.src;
5
5
  try {
6
- const e = n.crossOrigin ? n.crossOrigin(c) : "anonymous", a = await o(c, 3e3, e);
7
- t.src = a, t.width || (t.width = t.naturalWidth || 100), t.height || (t.height = t.naturalHeight || 100);
6
+ const e = await l(c, { useProxy: a.useProxy });
7
+ t.src = e, t.width || (t.width = t.naturalWidth || 100), t.height || (t.height = t.naturalHeight || 100);
8
8
  } catch {
9
9
  const e = document.createElement("div");
10
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
11
  }
12
12
  };
13
13
  for (let t = 0; t < r.length; t += 4) {
14
- const c = r.slice(t, t + 4).map(s);
14
+ const c = r.slice(t, t + 4).map(i);
15
15
  await Promise.allSettled(c);
16
16
  }
17
17
  }
@@ -1,92 +1,94 @@
1
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;
2
+ import { isIconFont as U } from "./iconFonts.js";
3
+ import { getStyleKey as N } from "../utils/cssTools.js";
4
+ import { getStyle as W, snapshotComputedStyle as V, parseContent as j, extractURL as A, fetchImage as D, safeEncodeURI as L, splitBackgroundImage as R, inlineSingleBackgroundEntry as K } from "../utils/helpers.js";
5
+ async function M(c, r, h, F, u, T = !1, w) {
6
+ if (!(c instanceof Element) || !(r instanceof Element)) return;
6
7
  for (const n of ["::before", "::after", "::first-letter"])
7
8
  try {
8
- const t = U(l, n);
9
+ const t = W(c, n);
9
10
  if (!t || typeof t[Symbol.iterator] != "function") continue;
10
11
  if (n === "::first-letter") {
11
- const a = getComputedStyle(l);
12
- if (!(t.color !== a.color || t.fontSize !== a.fontSize || t.fontWeight !== a.fontWeight)) continue;
13
- const d = Array.from(i.childNodes).find(
12
+ const l = getComputedStyle(c);
13
+ if (!(t.color !== l.color || t.fontSize !== l.fontSize || t.fontWeight !== l.fontWeight)) continue;
14
+ const d = Array.from(r.childNodes).find(
14
15
  (e) => e.nodeType === Node.TEXT_NODE && e.textContent && e.textContent.trim().length > 0
15
16
  );
16
17
  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
+ const g = d.textContent, f = g.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0], x = g.slice(f?.length || 0);
18
19
  if (!f || /[\uD800-\uDFFF]/.test(f)) continue;
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);
20
+ const a = document.createElement("span");
21
+ a.textContent = f, a.dataset.snapdomPseudo = "::first-letter";
22
+ const s = V(t), I = N(s, "span", u);
23
+ h.set(a, I);
24
+ const E = document.createTextNode(x);
25
+ r.replaceChild(E, d), r.insertBefore(a, E);
25
26
  continue;
26
27
  }
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");
28
+ const B = t.getPropertyValue("content"), y = t.getPropertyValue("background-image"), m = t.getPropertyValue("background-color"), $ = B !== "none", C = y && y !== "none", b = m && m !== "transparent" && m !== "rgba(0, 0, 0, 0)";
29
+ if ($ || C || b) {
30
+ const l = t.getPropertyValue("font-family"), p = parseInt(t.getPropertyValue("font-size")) || 32, d = parseInt(t.getPropertyValue("font-weight")) || !1, g = t.getPropertyValue("color") || "#000", o = document.createElement("span");
30
31
  o.dataset.snapdomPseudo = n;
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
- a
35
- ), s = W(S);
36
- if (!w && r && s.length === 1) {
32
+ const f = V(t), x = N(f, "span", u);
33
+ h.set(o, x);
34
+ const a = U(l), s = j(B);
35
+ if (a && s.length === 1) {
37
36
  const e = document.createElement("img");
38
37
  e.src = await z(
39
38
  s,
40
- a,
39
+ l,
41
40
  d,
42
- B,
43
- p
44
- ), e.style = "display:block;width:100%;height:100%;object-fit:contain;", o.appendChild(e);
41
+ p,
42
+ g
43
+ ), e.style = `width:${p}px;height:auto;object-fit:contain;`, o.appendChild(e);
45
44
  } else if (s.startsWith("url(")) {
46
- const e = j(s);
45
+ const e = A(s);
47
46
  if (e && e.trim() !== "")
48
47
  try {
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) {
48
+ const i = document.createElement("img"), P = await D(
49
+ L(e, { useProxy: w })
50
+ );
51
+ i.src = P, i.style = `width:${p}px;height:auto;object-fit:contain;`, o.appendChild(i);
52
+ } catch (i) {
52
53
  console.error(
53
54
  `[snapdom] Error in pseudo ${n} for`,
54
- l,
55
- c
55
+ c,
56
+ i
56
57
  );
57
58
  }
58
- } else !r && s && s !== "none" && (o.textContent = s);
59
- if (y)
59
+ } else !a && s && s !== "none" && (o.textContent = s);
60
+ if (C)
60
61
  try {
61
- const e = L(u), c = await Promise.all(
62
- e.map((E) => $(E))
62
+ const e = R(y), i = await Promise.all(
63
+ e.map((P) => K(P))
63
64
  );
64
- o.style.backgroundImage = c.join(", ");
65
+ o.style.backgroundImage = i.join(", ");
65
66
  } catch (e) {
66
67
  console.warn(
67
68
  `[snapdom] Failed to inline background-image for ${n}`,
68
69
  e
69
70
  );
70
71
  }
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);
72
+ if (b && (o.style.backgroundColor = m), !(o.childNodes.length > 0 || o.textContent && o.textContent.trim() !== "" || C || b)) continue;
73
+ n === "::before" ? r.insertBefore(o, r.firstChild) : r.appendChild(o);
73
74
  }
74
75
  } catch (t) {
75
- console.warn(`[snapdom] Failed to capture ${n} for`, l, t);
76
+ console.warn(`[snapdom] Failed to capture ${n} for`, c, t);
76
77
  }
77
- const P = Array.from(l.children), k = Array.from(i.children).filter(
78
+ const S = Array.from(c.children), k = Array.from(r.children).filter(
78
79
  (n) => !n.dataset.snapdomPseudo
79
80
  );
80
- for (let n = 0; n < Math.min(P.length, k.length); n++)
81
- await R(
82
- P[n],
81
+ for (let n = 0; n < Math.min(S.length, k.length); n++)
82
+ await M(
83
+ S[n],
83
84
  k[n],
84
- g,
85
- F,
86
85
  h,
86
+ F,
87
+ u,
88
+ T,
87
89
  w
88
90
  );
89
91
  }
90
92
  export {
91
- R as inlinePseudoElements
93
+ M as inlinePseudoElements
92
94
  };
@@ -1,11 +1,31 @@
1
- import { getStyleKey as y } from "../utils/cssTools.js";
2
- import { getStyle as g, snapshotComputedStyle as p } from "../utils/helpers.js";
3
- function r(t, n, o, e, s) {
1
+ import { getStyleKey as c } from "../utils/cssTools.js";
2
+ import { getStyle as d } from "../utils/helpers.js";
3
+ const p = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new Map();
4
+ function y(t) {
5
+ const o = {};
6
+ for (let n = 0; n < t.length; n++) {
7
+ const e = t[n];
8
+ let a = t.getPropertyValue(e);
9
+ (e === "background-image" || e === "content") && a.includes("url(") && !a.includes("data:") && (a = "none"), o[e] = a;
10
+ }
11
+ return o;
12
+ }
13
+ function S(t, o, n, e, a) {
4
14
  if (t.tagName === "STYLE") return;
5
- e.has(t) || e.set(t, g(t));
6
- const a = e.get(t), i = p(a), l = t.tagName?.toLowerCase() || "div", m = y(i, l, s);
7
- o.set(n, m);
15
+ e.has(t) || e.set(t, d(t));
16
+ const m = e.get(t);
17
+ if (!p.has(t)) {
18
+ const s = y(m);
19
+ p.set(t, s);
20
+ }
21
+ const g = p.get(t), i = Object.entries(g).sort(([s], [l]) => s.localeCompare(l)).map(([s, l]) => `${s}:${l}`).join(";");
22
+ if (r.has(i)) {
23
+ n.set(o, r.get(i));
24
+ return;
25
+ }
26
+ const f = t.tagName?.toLowerCase() || "div", h = c(g, f, a);
27
+ r.set(i, h), n.set(o, h);
8
28
  }
9
29
  export {
10
- r as inlineAllStyles
30
+ S as inlineAllStyles
11
31
  };
@@ -0,0 +1,26 @@
1
+ function l(s) {
2
+ if (!s) return;
3
+ const f = document.querySelectorAll("svg > defs");
4
+ f.length && s.querySelectorAll("svg").forEach((r) => {
5
+ const c = r.querySelectorAll("use");
6
+ if (!c.length) return;
7
+ const n = /* @__PURE__ */ new Set();
8
+ if (c.forEach((t) => {
9
+ const e = t.getAttribute("xlink:href") || t.getAttribute("href");
10
+ e && e.startsWith("#") && n.add(e.slice(1));
11
+ }), !n.size) return;
12
+ const o = document.createElementNS("http://www.w3.org/2000/svg", "defs");
13
+ for (const t of n)
14
+ for (const e of f) {
15
+ const i = e.querySelector(`#${CSS.escape(t)}`);
16
+ if (i) {
17
+ o.appendChild(i.cloneNode(!0));
18
+ break;
19
+ }
20
+ }
21
+ o.childNodes.length && r.insertBefore(o, r.firstChild);
22
+ });
23
+ }
24
+ export {
25
+ l as inlineExternalDef
26
+ };