@unicom-cloud/utils 0.1.15 → 0.1.17

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 (90) hide show
  1. package/class-name/index.js +5 -5
  2. package/constant/index.js +24 -2
  3. package/constant/platform.js +13 -12
  4. package/constant.js +24 -2
  5. package/content-disposition/index.js +3 -3
  6. package/date/convertTime.js +4 -4
  7. package/event-emitter/index.js +2 -4
  8. package/filesize/types/constants.d.ts +81 -0
  9. package/filesize/types/filesize.d.ts +97 -0
  10. package/index.js +66 -60
  11. package/js-cookie/index.d.ts +116 -0
  12. package/js-cookie/index.js +4 -0
  13. package/js-cookie/src/api.js +56 -0
  14. package/js-cookie/src/assign.js +11 -0
  15. package/js-cookie/src/converter.js +14 -0
  16. package/jsCookie.js +4 -0
  17. package/lunar/lib/Holiday.js +2 -6
  18. package/lunar/lib/HolidayUtil.js +113 -100
  19. package/lunar/lib/I18n.js +395 -975
  20. package/lunar/lib/JieQi.js +12 -16
  21. package/lunar/lib/Lunar.js +224 -672
  22. package/lunar/lib/LunarMonth.js +35 -98
  23. package/lunar/lib/LunarTime.js +24 -103
  24. package/lunar/lib/LunarUtil.js +426 -1728
  25. package/lunar/lib/LunarYear.js +473 -566
  26. package/lunar/lib/ShouXingUtil.js +6714 -6690
  27. package/lunar/lib/Solar.js +24 -49
  28. package/lunar/lib/SolarHalfYear.js +0 -2
  29. package/lunar/lib/SolarMonth.js +4 -6
  30. package/lunar/lib/SolarSeason.js +0 -2
  31. package/lunar/lib/SolarUtil.js +238 -226
  32. package/lunar/lib/SolarWeek.js +7 -11
  33. package/lunar/lib/SolarYear.js +0 -1
  34. package/nzh/nzh.d.ts +74 -0
  35. package/package.json +1 -1
  36. package/query-string/base.d.ts +717 -0
  37. package/query-string/base.js +268 -0
  38. package/query-string/index.d.ts +16 -0
  39. package/query-string/index.js +4 -0
  40. package/query-string/splitOnFirst.js +14 -0
  41. package/queryString.js +4 -0
  42. package/random/index.js +56 -35
  43. package/snapdom/src/api/preCache.js +51 -28
  44. package/snapdom/src/core/cache.js +1 -4
  45. package/snapdom/src/core/capture.js +45 -44
  46. package/snapdom/src/core/clone.js +82 -66
  47. package/snapdom/src/core/prepare.js +168 -46
  48. package/snapdom/src/modules/background.js +29 -19
  49. package/snapdom/src/modules/fonts.js +146 -91
  50. package/snapdom/src/modules/images.js +14 -9
  51. package/snapdom/src/modules/pseudo.js +55 -58
  52. package/snapdom/src/modules/styles.js +22 -22
  53. package/snapdom/src/modules/svgDefs.js +39 -20
  54. package/snapdom/src/utils/cssTools.js +58 -51
  55. package/snapdom/src/utils/helpers.js +197 -140
  56. package/snapdom/types/snapdom.d.ts +101 -0
  57. package/tinycolor/src/conversion.js +1 -1
  58. package/tinycolor/src/index.js +2 -19
  59. package/turbo-stream/src/encode.js +5 -8
  60. package/turbo-stream/src/shared.js +117 -119
  61. package/types/constant/index.d.ts +11 -0
  62. package/types/constant/platform.d.ts +1 -0
  63. package/types/index.d.ts +3 -0
  64. package/types/js-cookie/index.d.ts +1 -0
  65. package/types/js-cookie/src/api.d.mts +2 -0
  66. package/types/js-cookie/src/assign.d.mts +1 -0
  67. package/types/js-cookie/src/converter.d.mts +5 -0
  68. package/types/lunar/lib/Lunar.d.ts +0 -98
  69. package/types/lunar/lib/LunarMonth.d.ts +0 -12
  70. package/types/lunar/lib/LunarTime.d.ts +0 -22
  71. package/types/lunar/lib/LunarUtil.d.ts +0 -90
  72. package/types/lunar/lib/LunarYear.d.ts +0 -30
  73. package/types/lunar/lib/Solar.d.ts +0 -5
  74. package/types/query-string/base.d.ts +11 -0
  75. package/types/query-string/index.d.ts +2 -0
  76. package/types/query-string/splitOnFirst.d.ts +1 -0
  77. package/types/random/index.d.ts +14 -23
  78. package/types/snapdom/src/api/preCache.d.ts +2 -5
  79. package/types/snapdom/src/core/cache.d.ts +0 -3
  80. package/types/snapdom/src/core/clone.d.ts +1 -1
  81. package/types/snapdom/src/modules/background.d.ts +16 -6
  82. package/types/snapdom/src/modules/fonts.d.ts +5 -1
  83. package/types/snapdom/src/modules/pseudo.d.ts +1 -1
  84. package/types/snapdom/src/modules/styles.d.ts +1 -1
  85. package/types/snapdom/src/modules/svgDefs.d.ts +13 -13
  86. package/types/snapdom/src/utils/cssTools.d.ts +2 -10
  87. package/types/snapdom/src/utils/helpers.d.ts +13 -7
  88. package/types/tinycolor/src/conversion.d.ts +1 -1
  89. package/types/turbo-stream/src/shared.d.ts +3 -3
  90. package/url-toolkit/src/url-toolkit.d.ts +22 -0
@@ -1,120 +1,155 @@
1
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") {
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();
2
+ import { isIconFont as $ } from "./iconFonts.js";
3
+ import { fetchResource as A, extractURL as v } from "../utils/helpers.js";
4
+ async function H(h, d, c, y = 32, C = "#000") {
5
+ d = d.replace(/^['"]+|['"]+$/g, "");
6
+ const p = window.devicePixelRatio || 1;
7
+ await document.fonts.ready;
8
+ const i = document.createElement("span");
9
+ i.textContent = h, i.style.position = "absolute", i.style.visibility = "hidden", i.style.fontFamily = `"${d}"`, i.style.fontWeight = c || "normal", i.style.fontSize = `${y}px`, i.style.lineHeight = "1", i.style.whiteSpace = "nowrap", i.style.padding = "0", i.style.margin = "0", document.body.appendChild(i);
10
+ const m = i.getBoundingClientRect(), t = Math.ceil(m.width), n = Math.ceil(m.height);
11
+ document.body.removeChild(i);
12
+ const e = document.createElement("canvas");
13
+ e.width = t * p, e.height = n * p;
14
+ const a = e.getContext("2d");
15
+ return a.scale(p, p), a.font = c ? `${c} ${y}px "${d}"` : `${y}px "${d}"`, a.textAlign = "left", a.textBaseline = "top", a.fillStyle = C, a.fillText(h, 0, 0), {
16
+ dataUrl: e.toDataURL(),
17
+ width: t,
18
+ height: n
19
+ };
12
20
  }
13
- function $(m) {
14
- return Array.from(document.styleSheets).some((i) => i.href === m);
21
+ function T(h) {
22
+ return Array.from(document.styleSheets).some((d) => d.href === h);
15
23
  }
16
- function P(m) {
17
- 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);
24
+ function I(h) {
25
+ return new Promise((d) => {
26
+ if (T(h)) return d(null);
27
+ const c = document.createElement("link");
28
+ c.rel = "stylesheet", c.href = h, c.setAttribute("data-snapdom", "injected-import"), c.onload = () => d(c), c.onerror = () => d(null), document.head.appendChild(c);
21
29
  });
22
30
  }
23
- async function T({ preCached: m = !1 } = {}) {
31
+ async function N({
32
+ preCached: h = !1,
33
+ localFonts: d = [],
34
+ useProxy: c = ""
35
+ } = {}) {
24
36
  if (o.resource.has("fonts-embed-css")) {
25
- if (m) {
37
+ if (h) {
26
38
  const t = document.createElement("style");
27
39
  t.setAttribute("data-snapdom", "embedFonts"), t.textContent = o.resource.get("fonts-embed-css"), document.head.appendChild(t);
28
40
  }
29
41
  return o.resource.get("fonts-embed-css");
30
42
  }
31
- const i = /@import\s+url\(["']?([^"')]+)["']?\)/g, a = [];
43
+ const y = /* @__PURE__ */ new Set();
44
+ try {
45
+ for (const t of document.fonts)
46
+ t.status === "loaded" && y.add(
47
+ `${t.family}__${t.weight || "normal"}__${t.style || "normal"}`
48
+ );
49
+ } catch {
50
+ }
51
+ const C = /@import\s+url\(["']?([^"')]+)["']?\)/g, p = [];
32
52
  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);
53
+ const n = t.textContent || "", e = Array.from(n.matchAll(C));
54
+ for (const a of e) {
55
+ const r = a[1];
56
+ $(r) || T(r) || p.push(r);
37
57
  }
38
58
  }
39
- await Promise.all(a.map(P));
40
- const p = Array.from(
59
+ await Promise.all(p.map(I));
60
+ const i = Array.from(
41
61
  document.querySelectorAll('link[rel="stylesheet"]')
42
62
  ).filter((t) => t.href);
43
- let u = "";
44
- for (const t of p)
63
+ let m = "";
64
+ for (const t of i)
45
65
  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)})`
58
- };
59
- if (o.font.has(e)) return null;
60
- 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);
64
- });
65
- return o.resource.set(e, b), o.font.add(e), { original: d[0], inlined: `url(${b})` };
66
- } catch {
67
- return console.warn("[snapdom] Failed to fetch font resource:", e), null;
66
+ const e = await (await A(t.href, { useProxy: c })).text();
67
+ if ($(t.href) || $(e)) continue;
68
+ const a = /@font-face[^{}]*{[^}]*}/g;
69
+ let r = e;
70
+ for (const s of e.match(a) || []) {
71
+ const b = s.match(/font-family:\s*([^;]+);/i);
72
+ if (!b) continue;
73
+ const R = b[1].replace(/['"]/g, "").trim(), S = s.match(/font-weight:\s*([^;]+);/i), u = s.match(/font-style:\s*([^;]+);/i), F = S ? S[1].trim() : "normal", w = u ? u[1].trim() : "normal", k = `${R}__${F}__${w}`, x = /url\((["']?)([^"')]+)\1\)/g, L = /url\(/i.test(s), f = /local\(/i.test(s);
74
+ if (!L && f)
75
+ continue;
76
+ if (!y.has(k)) {
77
+ r = r.replace(s, "");
78
+ continue;
79
+ }
80
+ let g = s;
81
+ const E = Array.from(s.matchAll(x));
82
+ for (const _ of E) {
83
+ let U = v(_[0]);
84
+ if (!U) continue;
85
+ let l = U;
86
+ if (!l.startsWith("http") && !l.startsWith("data:") && (l = new URL(l, t.href).href), !$(l)) {
87
+ if (o.resource.has(l)) {
88
+ o.font.add(l), g = g.replace(
89
+ _[0],
90
+ `url(${o.resource.get(l)})`
91
+ );
92
+ continue;
93
+ }
94
+ if (!o.font.has(l))
95
+ try {
96
+ const D = await (await A(l, { useProxy: c })).blob(), M = await new Promise((W) => {
97
+ const P = new FileReader();
98
+ P.onload = () => W(P.result), P.readAsDataURL(D);
99
+ });
100
+ o.resource.set(l, M), o.font.add(l), g = g.replace(_[0], `url(${M})`);
101
+ } catch {
102
+ console.warn("[snapdom] Failed to fetch font resource:", l);
103
+ }
68
104
  }
69
- })
70
- );
71
- let f = s;
72
- for (const d of l)
73
- d && (f = f.replace(d.original, d.inlined));
74
- u += f + `
105
+ }
106
+ r = r.replace(s, g);
107
+ }
108
+ m += r + `
75
109
  `;
76
110
  } catch {
77
111
  console.warn("[snapdom] Failed to fetch CSS:", t.href);
78
112
  }
79
113
  for (const t of document.styleSheets)
80
114
  try {
81
- if (!t.href || p.every((n) => n.href !== t.href)) {
115
+ if (!t.href || i.every((n) => n.href !== t.href)) {
82
116
  for (const n of t.cssRules)
83
117
  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"};}`;
118
+ const e = n.style.getPropertyValue("src"), a = n.style.getPropertyValue("font-family");
119
+ if (!e || $(a)) continue;
120
+ const r = n.style.getPropertyValue("font-weight") || "normal", s = n.style.getPropertyValue("font-style") || "normal", b = `${a}__${r}__${s}`, R = /url\((["']?)([^"')]+)\1\)/g, S = /local\((["']?)[^)]+?\1\)/g, u = !!e.match(R), F = !!e.match(S);
121
+ if (!u && F) {
122
+ m += `@font-face{font-family:${a};src:${e};font-style:${s};font-weight:${r};}`;
89
123
  continue;
90
124
  }
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)})`
125
+ if (!y.has(b)) continue;
126
+ let w = e;
127
+ const k = Array.from(e.matchAll(R));
128
+ for (const x of k) {
129
+ let L = x[2].trim();
130
+ if (!L) continue;
131
+ let f = L;
132
+ if (!f.startsWith("http") && !f.startsWith("data:") && (f = new URL(f, t.href || location.href).href), !$(f)) {
133
+ if (o.resource.has(f)) {
134
+ o.font.add(f), w = w.replace(
135
+ x[0],
136
+ `url(${o.resource.get(f)})`
102
137
  );
103
138
  continue;
104
139
  }
105
- if (!o.font.has(r))
140
+ if (!o.font.has(f))
106
141
  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);
142
+ const E = await (await A(f, { useProxy: c })).blob(), _ = await new Promise((U) => {
143
+ const l = new FileReader();
144
+ l.onload = () => U(l.result), l.readAsDataURL(E);
110
145
  });
111
- o.resource.set(r, S), o.font.add(r), e = e.replace(g[0], `url(${S})`);
146
+ o.resource.set(f, _), o.font.add(f), w = w.replace(x[0], `url(${_})`);
112
147
  } catch {
113
- console.warn("[snapdom] Failed to fetch font URL:", r);
148
+ console.warn("[snapdom] Failed to fetch font URL:", f);
114
149
  }
115
150
  }
116
151
  }
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"};}`;
152
+ m += `@font-face{font-family:${a};src:${w};font-style:${s};font-weight:${r};}`;
118
153
  }
119
154
  }
120
155
  } catch (n) {
@@ -122,17 +157,17 @@ async function T({ preCached: m = !1 } = {}) {
122
157
  }
123
158
  for (const t of document.fonts)
124
159
  if (t.family && t.status === "loaded" && t._snapdomSrc) {
125
- if (y(t.family)) continue;
160
+ if ($(t.family)) continue;
126
161
  let n = t._snapdomSrc;
127
162
  if (!n.startsWith("data:")) {
128
163
  if (o.resource.has(t._snapdomSrc))
129
164
  n = o.resource.get(t._snapdomSrc), o.font.add(t._snapdomSrc);
130
165
  else if (!o.font.has(t._snapdomSrc))
131
166
  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);
167
+ const a = await (await A(t._snapdomSrc, { useProxy: c })).blob();
168
+ n = await new Promise((r) => {
169
+ const s = new FileReader();
170
+ s.onload = () => r(s.result), s.readAsDataURL(a);
136
171
  }), o.resource.set(t._snapdomSrc, n), o.font.add(t._snapdomSrc);
137
172
  } catch {
138
173
  console.warn(
@@ -142,15 +177,35 @@ async function T({ preCached: m = !1 } = {}) {
142
177
  continue;
143
178
  }
144
179
  }
145
- u += `@font-face{font-family:'${t.family}';src:url(${n});font-style:${t.style || "normal"};font-weight:${t.weight || "normal"};}`;
180
+ m += `@font-face{font-family:'${t.family}';src:url(${n});font-style:${t.style || "normal"};font-weight:${t.weight || "normal"};}`;
146
181
  }
147
- if (u && (o.resource.set("fonts-embed-css", u), m)) {
182
+ for (const t of d) {
183
+ if (!t || typeof t != "object") continue;
184
+ const { family: n, src: e, weight: a = "normal", style: r = "normal" } = t;
185
+ if (!n || !e) continue;
186
+ let s = e;
187
+ if (s.startsWith("data:"))
188
+ o.resource.set(e, s), o.font.add(e);
189
+ else
190
+ try {
191
+ const R = await (await A(e, { useProxy: c })).blob();
192
+ s = await new Promise((S) => {
193
+ const u = new FileReader();
194
+ u.onload = () => S(u.result), u.readAsDataURL(R);
195
+ }), o.resource.set(e, s), o.font.add(e);
196
+ } catch {
197
+ console.warn("[snapdom] Failed to load local font:", e);
198
+ continue;
199
+ }
200
+ m += `@font-face{font-family:'${n}';src:url(${s});font-style:${r};font-weight:${a};}`;
201
+ }
202
+ if (m && (o.resource.set("fonts-embed-css", m), h)) {
148
203
  const t = document.createElement("style");
149
- t.setAttribute("data-snapdom", "embedFonts"), t.textContent = u, document.head.appendChild(t);
204
+ t.setAttribute("data-snapdom", "embedFonts"), t.textContent = m, document.head.appendChild(t);
150
205
  }
151
- return u;
206
+ return m;
152
207
  }
153
208
  export {
154
- T as embedCustomFonts,
155
- E as iconToImage
209
+ N as embedCustomFonts,
210
+ H as iconToImage
156
211
  };
@@ -1,20 +1,25 @@
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
- const c = t.src;
1
+ import { fetchImage as a } from "../utils/helpers.js";
2
+ async function l(s, n = {}) {
3
+ const c = Array.from(s.querySelectorAll("img")), o = async (t) => {
4
+ if (!t.getAttribute("src")) {
5
+ const e = t.currentSrc || t.src || "";
6
+ e && t.setAttribute("src", e);
7
+ }
8
+ t.removeAttribute("srcset"), t.removeAttribute("sizes");
9
+ const r = t.src;
5
10
  try {
6
- const e = await l(c, { useProxy: a.useProxy });
11
+ const e = await a(r, { useProxy: n.useProxy });
7
12
  t.src = e, t.width || (t.width = t.naturalWidth || 100), t.height || (t.height = t.naturalHeight || 100);
8
13
  } catch {
9
14
  const e = document.createElement("div");
10
15
  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
16
  }
12
17
  };
13
- for (let t = 0; t < r.length; t += 4) {
14
- const c = r.slice(t, t + 4).map(i);
15
- await Promise.allSettled(c);
18
+ for (let t = 0; t < c.length; t += 4) {
19
+ const r = c.slice(t, t + 4).map(o);
20
+ await Promise.allSettled(r);
16
21
  }
17
22
  }
18
23
  export {
19
- h as inlineImages
24
+ l as inlineImages
20
25
  };
@@ -1,86 +1,83 @@
1
- import { cache as M } from "../core/cache.js";
2
- import { iconToImage as v } from "./fonts.js";
3
- import { isIconFont as G } from "./iconFonts.js";
1
+ import { iconToImage as X } from "./fonts.js";
2
+ import { isIconFont as _ } from "./iconFonts.js";
4
3
  import { getStyleKey as $ } from "../utils/cssTools.js";
5
- import { getStyle as H, snapshotComputedStyle as z, parseContent as J, extractURL as Q, fetchImage as Y, safeEncodeURI as Z, splitBackgroundImage as tt, inlineSingleBackgroundEntry as nt } from "../utils/helpers.js";
6
- async function et(a, s, m, R = !1, b) {
7
- if (!(a instanceof Element) || !(s instanceof Element)) return;
4
+ import { getStyle as q, snapshotComputedStyle as U, parseContent as G, extractURL as J, fetchImage as Q, safeEncodeURI as Y, splitBackgroundImage as Z, inlineSingleBackgroundEntry as tt } from "../utils/helpers.js";
5
+ async function nt(a, r, g, z, d) {
6
+ if (!(a instanceof Element) || !(r instanceof Element)) return;
8
7
  for (const n of ["::before", "::after", "::first-letter"])
9
8
  try {
10
- const t = H(a, n);
9
+ const t = q(a, n);
11
10
  if (!t || typeof t[Symbol.iterator] != "function" || t.content === "none" && t.backgroundImage === "none" && t.backgroundColor === "transparent" && (t.borderStyle === "none" || parseFloat(t.borderWidth) === 0) && (!t.transform || t.transform === "none") && t.display === "inline") continue;
12
11
  if (n === "::first-letter") {
13
- const e = getComputedStyle(a);
14
- if (!(t.color !== e.color || t.fontSize !== e.fontSize || t.fontWeight !== e.fontWeight)) continue;
15
- const c = Array.from(s.childNodes).find(
12
+ const o = getComputedStyle(a);
13
+ if (!(t.color !== o.color || t.fontSize !== o.fontSize || t.fontWeight !== o.fontWeight)) continue;
14
+ const i = Array.from(r.childNodes).find(
16
15
  (T) => T.nodeType === Node.TEXT_NODE && T.textContent?.trim().length > 0
17
16
  );
18
- if (!c) continue;
19
- const W = c.textContent, d = W.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0], X = W.slice(d?.length || 0);
20
- if (!d || /[\uD800-\uDFFF]/.test(d)) continue;
21
- const f = document.createElement("span");
22
- f.textContent = d, f.dataset.snapdomPseudo = "::first-letter";
23
- const _ = z(t), q = $(_, "span", m);
24
- M.preStyleMap.set(f, q);
25
- const P = document.createTextNode(X);
26
- s.replaceChild(P, c), s.insertBefore(f, P);
17
+ if (!i) continue;
18
+ const l = i.textContent, h = l.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0], K = l.slice(h?.length || 0);
19
+ if (!h || /[\uD800-\uDFFF]/.test(h)) continue;
20
+ const p = document.createElement("span");
21
+ p.textContent = h, p.dataset.snapdomPseudo = "::first-letter";
22
+ const M = U(t), O = $(M, "span", d);
23
+ g.set(p, O);
24
+ const W = document.createTextNode(K);
25
+ r.replaceChild(W, i), r.insertBefore(p, W);
27
26
  continue;
28
27
  }
29
- const h = t.content, i = /counter\s*\(|counters\s*\(/.test(h) ? "- " : J(h), p = t.backgroundImage, l = t.backgroundColor, S = t.fontFamily, g = parseInt(t.fontSize) || 32, U = parseInt(t.fontWeight) || !1, j = t.color || "#000", A = t.display, D = parseFloat(t.width), L = parseFloat(t.height), x = t.borderStyle, V = parseFloat(t.borderWidth), F = t.transform, w = G(S), k = h !== "none" && i !== "", u = p && p !== "none", y = l && l !== "transparent" && l !== "rgba(0, 0, 0, 0)", B = A !== "inline" && (D > 0 || L > 0), I = x && x !== "none" && V > 0, N = F && F !== "none";
30
- if (!(k || u || y || B || I || N)) continue;
31
- const o = document.createElement("span");
32
- o.dataset.snapdomPseudo = n;
33
- const K = z(t), O = $(K, "span", m);
34
- if (M.preStyleMap.set(o, O), w && i.length === 1) {
35
- const e = document.createElement("img");
36
- e.src = await v(
37
- i,
28
+ const u = t.content, c = /counter\s*\(|counters\s*\(/.test(u) ? "- " : G(u), y = t.backgroundImage, f = t.backgroundColor, S = t.fontFamily, m = parseInt(t.fontSize) || 32, A = parseInt(t.fontWeight) || !1, R = t.color || "#000", j = t.display, D = parseFloat(t.width), L = parseFloat(t.height), w = t.borderStyle, V = parseFloat(t.borderWidth), F = t.transform, I = _(S), k = u !== "none" && c !== "", b = y && y !== "none", C = f && f !== "transparent" && f !== "rgba(0, 0, 0, 0)", B = j !== "inline" && (D > 0 || L > 0), N = w && w !== "none" && V > 0, P = F && F !== "none";
29
+ if (!(k || b || C || B || N || P)) continue;
30
+ const e = document.createElement("span");
31
+ e.dataset.snapdomPseudo = n, e.style.verticalAlign = "middle";
32
+ const v = U(t), H = $(v, "span", d);
33
+ if (g.set(e, H), I && c.length === 1) {
34
+ const { dataUrl: o, width: s, height: i } = await X(
35
+ c,
38
36
  S,
39
- U,
40
- g,
41
- j
42
- ), e.style = `width:${g}px;height:auto;object-fit:contain;`, o.appendChild(e);
43
- } else if (i.startsWith("url(")) {
44
- const e = Q(i);
45
- if (e?.trim())
37
+ A,
38
+ m,
39
+ R
40
+ ), l = document.createElement("img");
41
+ l.src = o, l.style = `height:${m}px;width:${s / i * m}px;object-fit:contain;`, e.appendChild(l), r.dataset.snapdomHasIcon = "true";
42
+ } else if (c.startsWith("url(")) {
43
+ const o = J(c);
44
+ if (o?.trim())
46
45
  try {
47
- const r = document.createElement("img"), c = await Y(
48
- Z(e, { useProxy: b })
49
- );
50
- r.src = c, r.style = `width:${g}px;height:auto;object-fit:contain;`, o.appendChild(r);
51
- } catch (r) {
52
- console.error(`[snapdom] Error in pseudo ${n} for`, a, r);
46
+ const s = document.createElement("img"), i = await Q(Y(o), d);
47
+ s.src = i, s.style = `width:${m}px;height:auto;object-fit:contain;`, e.appendChild(s);
48
+ } catch (s) {
49
+ console.error(`[snapdom] Error in pseudo ${n} for`, a, s);
53
50
  }
54
- } else !w && k && (o.textContent = i);
55
- if (u)
51
+ } else !I && k && (e.textContent = c);
52
+ if (b)
56
53
  try {
57
- const e = tt(p), r = await Promise.all(
58
- e.map(nt)
54
+ const o = Z(y), s = await Promise.all(
55
+ o.map(tt)
59
56
  );
60
- o.style.backgroundImage = r.join(", ");
61
- } catch (e) {
57
+ e.style.backgroundImage = s.join(", ");
58
+ } catch (o) {
62
59
  console.warn(
63
60
  `[snapdom] Failed to inline background-image for ${n}`,
64
- e
61
+ o
65
62
  );
66
63
  }
67
- if (y && (o.style.backgroundColor = l), !(o.childNodes.length > 0 || o.textContent?.trim() !== "" || u || y || B || I || N)) continue;
68
- n === "::before" ? s.insertBefore(o, s.firstChild) : s.appendChild(o);
64
+ if (C && (e.style.backgroundColor = f), !(e.childNodes.length > 0 || e.textContent?.trim() !== "" || b || C || B || N || P)) continue;
65
+ n === "::before" ? r.insertBefore(e, r.firstChild) : r.appendChild(e);
69
66
  } catch (t) {
70
67
  console.warn(`[snapdom] Failed to capture ${n} for`, a, t);
71
68
  }
72
- const C = Array.from(a.children), E = Array.from(s.children).filter(
69
+ const E = Array.from(a.children), x = Array.from(r.children).filter(
73
70
  (n) => !n.dataset.snapdomPseudo
74
71
  );
75
- for (let n = 0; n < Math.min(C.length, E.length); n++)
76
- await et(
77
- C[n],
72
+ for (let n = 0; n < Math.min(E.length, x.length); n++)
73
+ await nt(
78
74
  E[n],
79
- m,
80
- R,
81
- b
75
+ x[n],
76
+ g,
77
+ z,
78
+ d
82
79
  );
83
80
  }
84
81
  export {
85
- et as inlinePseudoElements
82
+ nt as inlinePseudoElements
86
83
  };
@@ -1,31 +1,31 @@
1
- import { cache as e } from "../core/cache.js";
2
- import { getStyleKey as y } from "../utils/cssTools.js";
3
- import { getStyle as m } from "../utils/helpers.js";
4
- function g(t) {
5
- const a = {};
6
- for (let o = 0; o < t.length; o++) {
7
- const s = t[o];
8
- let n = t.getPropertyValue(s);
9
- (s === "background-image" || s === "content") && n.includes("url(") && !n.includes("data:") && (n = "none"), a[s] = n;
1
+ import { getStyleKey as c } from "../utils/cssTools.js";
2
+ import { getStyle as d } from "../utils/helpers.js";
3
+ const r = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new Map();
4
+ function y(t) {
5
+ const n = {}, s = t.getPropertyValue("visibility");
6
+ for (let e = 0; e < t.length; e++) {
7
+ const o = t[e];
8
+ let a = t.getPropertyValue(o);
9
+ (o === "background-image" || o === "content") && a.includes("url(") && !a.includes("data:") && (a = "none"), n[o] = a;
10
10
  }
11
- return a;
11
+ return s === "hidden" && (n.opacity = "0"), n;
12
12
  }
13
- function d(t, a, o) {
13
+ function S(t, n, s, e, o) {
14
14
  if (t.tagName === "STYLE") return;
15
- e.preStyle.has(t) || e.preStyle.set(t, m(t));
16
- const s = e.preStyle.get(t);
17
- if (!e.snapshot.has(t)) {
18
- const p = g(s);
19
- e.snapshot.set(t, p);
15
+ e.has(t) || e.set(t, d(t));
16
+ const a = e.get(t);
17
+ if (!r.has(t)) {
18
+ const i = y(a);
19
+ r.set(t, i);
20
20
  }
21
- const n = e.snapshot.get(t), l = Object.entries(n).sort(([p], [r]) => p.localeCompare(r)).map(([p, r]) => `${p}:${r}`).join(";");
22
- if (e.snapshotKey.has(l)) {
23
- e.preStyleMap.set(a, e.snapshotKey.get(l));
21
+ const h = r.get(t), l = Object.entries(h).sort(([i], [p]) => i.localeCompare(p)).map(([i, p]) => `${i}:${p}`).join(";");
22
+ if (g.has(l)) {
23
+ s.set(n, g.get(l));
24
24
  return;
25
25
  }
26
- const h = t.tagName?.toLowerCase() || "div", i = y(n, h, o);
27
- e.snapshotKey.set(l, i), e.preStyleMap.set(a, i);
26
+ const f = t.tagName?.toLowerCase() || "div", m = c(h, f, o);
27
+ g.set(l, m), s.set(n, m);
28
28
  }
29
29
  export {
30
- d as inlineAllStyles
30
+ S as inlineAllStyles
31
31
  };
@@ -1,26 +1,45 @@
1
- function l(s) {
1
+ function u(s) {
2
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
- }
3
+ const o = /* @__PURE__ */ new Set();
4
+ if (s.querySelectorAll("use").forEach((e) => {
5
+ const r = e.getAttribute("xlink:href") || e.getAttribute("href");
6
+ r && r.startsWith("#") && o.add(r.slice(1));
7
+ }), !o.size) return;
8
+ const d = Array.from(
9
+ document.querySelectorAll("svg > symbol, svg > defs")
10
+ ), f = d.filter(
11
+ (e) => e.tagName.toLowerCase() === "symbol"
12
+ ), c = d.filter(
13
+ (e) => e.tagName.toLowerCase() === "defs"
14
+ );
15
+ let t = s.querySelector("svg.inline-defs-container");
16
+ t || (t = document.createElementNS("http://www.w3.org/2000/svg", "svg"), t.setAttribute("aria-hidden", "true"), t.setAttribute(
17
+ "style",
18
+ "position: absolute; width: 0; height: 0; overflow: hidden;"
19
+ ), t.classList.add("inline-defs-container"), s.insertBefore(t, s.firstChild));
20
+ const i = /* @__PURE__ */ new Set();
21
+ s.querySelectorAll("symbol[id], defs > *[id]").forEach((e) => {
22
+ i.add(e.id);
23
+ }), o.forEach((e) => {
24
+ if (i.has(e)) return;
25
+ const r = f.find((l) => l.id === e);
26
+ if (r) {
27
+ t.appendChild(r.cloneNode(!0)), i.add(e);
28
+ return;
29
+ }
30
+ for (const l of c) {
31
+ const a = l.querySelector(`#${CSS.escape(e)}`);
32
+ if (a) {
33
+ let n = t.querySelector("defs");
34
+ n || (n = document.createElementNS(
35
+ "http://www.w3.org/2000/svg",
36
+ "defs"
37
+ ), t.appendChild(n)), n.appendChild(a.cloneNode(!0)), i.add(e);
38
+ break;
20
39
  }
21
- o.childNodes.length && r.insertBefore(o, r.firstChild);
40
+ }
22
41
  });
23
42
  }
24
43
  export {
25
- l as inlineExternalDef
44
+ u as inlineExternalDefsAndSymbols
26
45
  };