@unicom-cloud/utils 0.1.16 → 0.1.18

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 (93) 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/diff/index.js +7 -0
  8. package/diff/src/diff.d.ts +21 -0
  9. package/diff/src/diff.js +381 -0
  10. package/diff.js +7 -0
  11. package/filesize/types/constants.d.ts +81 -0
  12. package/filesize/types/filesize.d.ts +97 -0
  13. package/index.js +68 -58
  14. package/js-cookie/index.d.ts +116 -0
  15. package/js-cookie/index.js +4 -0
  16. package/js-cookie/src/api.js +56 -0
  17. package/js-cookie/src/assign.js +11 -0
  18. package/js-cookie/src/converter.js +14 -0
  19. package/jsCookie.js +4 -0
  20. package/lunar/lib/HolidayUtil.js +48 -49
  21. package/mitt/index.js +4 -0
  22. package/mitt/src/index.js +37 -0
  23. package/mitt.js +4 -0
  24. package/nzh/nzh.d.ts +74 -0
  25. package/package.json +1 -1
  26. package/pinyin/index.js +4 -0
  27. package/pinyin/simplified.js +4 -0
  28. package/pinyin/src/core.js +143 -0
  29. package/pinyin/src/simplified.js +8 -0
  30. package/pinyin/src/simplified_dict.js +410 -0
  31. package/pinyin/src/traditional.js +8 -0
  32. package/pinyin/src/traditional_dict.js +403 -0
  33. package/pinyin/traditional.js +4 -0
  34. package/pinyin.js +4 -0
  35. package/query-string/base.d.ts +717 -0
  36. package/query-string/base.js +268 -0
  37. package/query-string/index.d.ts +16 -0
  38. package/query-string/index.js +4 -0
  39. package/query-string/splitOnFirst.js +14 -0
  40. package/queryString.js +4 -0
  41. package/random/index.js +56 -35
  42. package/snapdom/src/api/preCache.js +51 -28
  43. package/snapdom/src/core/cache.js +1 -4
  44. package/snapdom/src/core/capture.js +45 -44
  45. package/snapdom/src/core/clone.js +82 -66
  46. package/snapdom/src/core/prepare.js +167 -45
  47. package/snapdom/src/modules/background.js +29 -19
  48. package/snapdom/src/modules/fonts.js +158 -111
  49. package/snapdom/src/modules/images.js +14 -9
  50. package/snapdom/src/modules/pseudo.js +52 -47
  51. package/snapdom/src/modules/styles.js +22 -22
  52. package/snapdom/src/modules/svgDefs.js +39 -20
  53. package/snapdom/src/utils/cssTools.js +58 -51
  54. package/snapdom/src/utils/helpers.js +197 -140
  55. package/snapdom/types/snapdom.d.ts +101 -0
  56. package/types/constant/index.d.ts +11 -0
  57. package/types/constant/platform.d.ts +1 -0
  58. package/types/diff/index.d.ts +2 -0
  59. package/types/diff/src/diff.d.ts +40 -0
  60. package/types/index.d.ts +6 -1
  61. package/types/js-cookie/index.d.ts +1 -0
  62. package/types/js-cookie/src/api.d.mts +2 -0
  63. package/types/js-cookie/src/assign.d.mts +1 -0
  64. package/types/js-cookie/src/converter.d.mts +5 -0
  65. package/types/mitt/index.d.ts +2 -0
  66. package/types/mitt/src/index.d.ts +29 -0
  67. package/types/pinyin/index.d.ts +1 -0
  68. package/types/pinyin/simplified.d.ts +1 -0
  69. package/types/pinyin/src/core.d.ts +3 -0
  70. package/types/pinyin/src/simplified.d.ts +4 -0
  71. package/types/pinyin/src/simplified_dict.d.ts +408 -0
  72. package/types/pinyin/src/traditional.d.ts +4 -0
  73. package/types/pinyin/src/traditional_dict.d.ts +401 -0
  74. package/types/pinyin/traditional.d.ts +1 -0
  75. package/types/query-string/base.d.ts +11 -0
  76. package/types/query-string/index.d.ts +2 -0
  77. package/types/query-string/splitOnFirst.d.ts +1 -0
  78. package/types/random/index.d.ts +14 -23
  79. package/types/snapdom/src/api/preCache.d.ts +2 -5
  80. package/types/snapdom/src/core/cache.d.ts +0 -3
  81. package/types/snapdom/src/core/clone.d.ts +1 -1
  82. package/types/snapdom/src/modules/background.d.ts +16 -6
  83. package/types/snapdom/src/modules/fonts.d.ts +5 -1
  84. package/types/snapdom/src/modules/pseudo.d.ts +1 -1
  85. package/types/snapdom/src/modules/styles.d.ts +1 -1
  86. package/types/snapdom/src/modules/svgDefs.d.ts +13 -13
  87. package/types/snapdom/src/utils/cssTools.d.ts +2 -10
  88. package/types/snapdom/src/utils/helpers.d.ts +13 -7
  89. package/types/turbo-stream/src/shared.d.ts +3 -3
  90. package/url-toolkit/src/url-toolkit.d.ts +22 -0
  91. package/event-emitter/index.js +0 -48
  92. package/eventEmitter.js +0 -4
  93. package/types/event-emitter/index.d.ts +0 -17
@@ -1,147 +1,174 @@
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
- i = i.replace(/^['"]+|['"]+$/g, "");
6
- const t = window.devicePixelRatio || 1;
1
+ import { cache as o } from "../core/cache.js";
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
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
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
19
  };
20
20
  }
21
- function x(m) {
22
- 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);
23
23
  }
24
- function L(m) {
25
- return new Promise((i) => {
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);
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);
29
29
  });
30
30
  }
31
- async function k({ preCached: m = !1 } = {}) {
32
- if (n.resource.has("fonts-embed-css")) {
33
- if (m) {
31
+ async function N({
32
+ preCached: h = !1,
33
+ localFonts: d = [],
34
+ useProxy: c = ""
35
+ } = {}) {
36
+ if (o.resource.has("fonts-embed-css")) {
37
+ if (h) {
34
38
  const t = document.createElement("style");
35
- t.setAttribute("data-snapdom", "embedFonts"), t.textContent = n.resource.get("fonts-embed-css"), document.head.appendChild(t);
39
+ t.setAttribute("data-snapdom", "embedFonts"), t.textContent = o.resource.get("fonts-embed-css"), document.head.appendChild(t);
36
40
  }
37
- return n.resource.get("fonts-embed-css");
41
+ return o.resource.get("fonts-embed-css");
38
42
  }
39
- const i = /@import\s+url\(["']?([^"')]+)["']?\)/g, l = [];
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 = [];
40
52
  for (const t of document.querySelectorAll("style")) {
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);
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);
45
57
  }
46
58
  }
47
- await Promise.all(l.map(L));
48
- const y = Array.from(
59
+ await Promise.all(p.map(I));
60
+ const i = Array.from(
49
61
  document.querySelectorAll('link[rel="stylesheet"]')
50
62
  ).filter((t) => t.href);
51
- let u = "";
52
- for (const t of y)
63
+ let m = "";
64
+ for (const t of i)
53
65
  try {
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)})`
66
- };
67
- if (n.font.has(o)) return null;
68
- try {
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);
72
- });
73
- return n.resource.set(o, w), n.font.add(o), { original: s[0], inlined: `url(${w})` };
74
- } catch {
75
- return console.warn("[snapdom] Failed to fetch font resource:", o), 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
+ }
76
104
  }
77
- })
78
- );
79
- let c = r;
80
- for (const s of f)
81
- s && (c = c.replace(s.original, s.inlined));
82
- u += c + `
105
+ }
106
+ r = r.replace(s, g);
107
+ }
108
+ m += r + `
83
109
  `;
84
110
  } catch {
85
111
  console.warn("[snapdom] Failed to fetch CSS:", t.href);
86
112
  }
87
113
  for (const t of document.styleSheets)
88
114
  try {
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"};}`;
115
+ if (!t.href || i.every((n) => n.href !== t.href)) {
116
+ for (const n of t.cssRules)
117
+ if (n.type === CSSRule.FONT_FACE_RULE) {
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};}`;
97
123
  continue;
98
124
  }
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)})`
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)})`
110
137
  );
111
138
  continue;
112
139
  }
113
- if (!n.font.has(a))
140
+ if (!o.font.has(f))
114
141
  try {
115
- const A = await (await fetch(a)).blob(), R = await new Promise((C) => {
116
- const $ = new FileReader();
117
- $.onload = () => C($.result), $.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);
118
145
  });
119
- n.resource.set(a, R), n.font.add(a), o = o.replace(p[0], `url(${R})`);
146
+ o.resource.set(f, _), o.font.add(f), w = w.replace(x[0], `url(${_})`);
120
147
  } catch {
121
- console.warn("[snapdom] Failed to fetch font URL:", a);
148
+ console.warn("[snapdom] Failed to fetch font URL:", f);
122
149
  }
123
150
  }
124
151
  }
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"};}`;
152
+ m += `@font-face{font-family:${a};src:${w};font-style:${s};font-weight:${r};}`;
126
153
  }
127
154
  }
128
- } catch (e) {
129
- console.warn("[snapdom] Cannot access stylesheet", t.href, e);
155
+ } catch (n) {
156
+ console.warn("[snapdom] Cannot access stylesheet", t.href, n);
130
157
  }
131
158
  for (const t of document.fonts)
132
159
  if (t.family && t.status === "loaded" && 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))
160
+ if ($(t.family)) continue;
161
+ let n = t._snapdomSrc;
162
+ if (!n.startsWith("data:")) {
163
+ if (o.resource.has(t._snapdomSrc))
164
+ n = o.resource.get(t._snapdomSrc), o.font.add(t._snapdomSrc);
165
+ else if (!o.font.has(t._snapdomSrc))
139
166
  try {
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);
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);
171
+ }), o.resource.set(t._snapdomSrc, n), o.font.add(t._snapdomSrc);
145
172
  } catch {
146
173
  console.warn(
147
174
  "[snapdom] Failed to fetch dynamic font src:",
@@ -150,15 +177,35 @@ async function k({ preCached: m = !1 } = {}) {
150
177
  continue;
151
178
  }
152
179
  }
153
- u += `@font-face{font-family:'${t.family}';src:url(${e});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"};}`;
154
181
  }
155
- if (u && (n.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)) {
156
203
  const t = document.createElement("style");
157
- 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);
158
205
  }
159
- return u;
206
+ return m;
160
207
  }
161
208
  export {
162
- k as embedCustomFonts,
163
- E as iconToImage
209
+ N as embedCustomFonts,
210
+ H as iconToImage
164
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,78 +1,83 @@
1
- import { cache as T } from "../core/cache.js";
2
- import { iconToImage as O } from "./fonts.js";
3
- import { isIconFont as X } 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 _, snapshotComputedStyle as M, parseContent as q, extractURL as G, fetchImage as J, safeEncodeURI as Q, splitBackgroundImage as Y, inlineSingleBackgroundEntry as Z } from "../utils/helpers.js";
6
- async function tt(i, r, d) {
7
- if (!(i instanceof Element) || !(r instanceof Element)) return;
8
- for (const e of ["::before", "::after", "::first-letter"])
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;
7
+ for (const n of ["::before", "::after", "::first-letter"])
9
8
  try {
10
- const t = _(i, e);
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
- if (e === "::first-letter") {
13
- const o = getComputedStyle(i);
11
+ if (n === "::first-letter") {
12
+ const o = getComputedStyle(a);
14
13
  if (!(t.color !== o.color || t.fontSize !== o.fontSize || t.fontWeight !== o.fontWeight)) continue;
15
- const a = Array.from(r.childNodes).find(
16
- (W) => W.nodeType === Node.TEXT_NODE && W.textContent?.trim().length > 0
14
+ const i = Array.from(r.childNodes).find(
15
+ (T) => T.nodeType === Node.TEXT_NODE && T.textContent?.trim().length > 0
17
16
  );
18
- if (!a) continue;
19
- const l = a.textContent, h = l.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0], v = l.slice(h?.length || 0);
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);
20
19
  if (!h || /[\uD800-\uDFFF]/.test(h)) continue;
21
20
  const p = document.createElement("span");
22
21
  p.textContent = h, p.dataset.snapdomPseudo = "::first-letter";
23
- const H = M(t), K = $(H, "span", d);
24
- T.preStyleMap.set(p, K);
25
- const P = document.createTextNode(v);
26
- r.replaceChild(P, a), r.insertBefore(p, P);
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 g = t.content, c = /counter\s*\(|counters\s*\(/.test(g) ? "- " : q(g), u = t.backgroundImage, f = t.backgroundColor, x = t.fontFamily, m = parseInt(t.fontSize) || 32, U = parseInt(t.fontWeight) || !1, z = t.color || "#000", A = t.display, R = parseFloat(t.width), j = parseFloat(t.height), S = t.borderStyle, D = parseFloat(t.borderWidth), w = t.transform, F = X(x), I = g !== "none" && c !== "", y = u && u !== "none", b = f && f !== "transparent" && f !== "rgba(0, 0, 0, 0)", k = A !== "inline" && (R > 0 || j > 0), B = S && S !== "none" && D > 0, N = w && w !== "none";
30
- if (!(I || y || b || k || B || N)) continue;
31
- const n = document.createElement("span");
32
- n.dataset.snapdomPseudo = e, n.style.verticalAlign = "middle";
33
- const L = M(t), V = $(L, "span", d);
34
- if (T.preStyleMap.set(n, V), F && c.length === 1) {
35
- const { dataUrl: o, width: s, height: a } = await O(
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(
36
35
  c,
37
- x,
38
- U,
36
+ S,
37
+ A,
39
38
  m,
40
- z
39
+ R
41
40
  ), l = document.createElement("img");
42
- l.src = o, l.style = `height:${m}px;width:${s / a * m}px;object-fit:contain;`, n.appendChild(l), r.dataset.snapdomHasIcon = "true";
41
+ l.src = o, l.style = `height:${m}px;width:${s / i * m}px;object-fit:contain;`, e.appendChild(l), r.dataset.snapdomHasIcon = "true";
43
42
  } else if (c.startsWith("url(")) {
44
- const o = G(c);
43
+ const o = J(c);
45
44
  if (o?.trim())
46
45
  try {
47
- const s = document.createElement("img"), a = await J(Q(o), d);
48
- s.src = a, s.style = `width:${m}px;height:auto;object-fit:contain;`, n.appendChild(s);
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);
49
48
  } catch (s) {
50
- console.error(`[snapdom] Error in pseudo ${e} for`, i, s);
49
+ console.error(`[snapdom] Error in pseudo ${n} for`, a, s);
51
50
  }
52
- } else !F && I && (n.textContent = c);
53
- if (y)
51
+ } else !I && k && (e.textContent = c);
52
+ if (b)
54
53
  try {
55
- const o = Y(u), s = await Promise.all(
56
- o.map(Z)
54
+ const o = Z(y), s = await Promise.all(
55
+ o.map(tt)
57
56
  );
58
- n.style.backgroundImage = s.join(", ");
57
+ e.style.backgroundImage = s.join(", ");
59
58
  } catch (o) {
60
59
  console.warn(
61
- `[snapdom] Failed to inline background-image for ${e}`,
60
+ `[snapdom] Failed to inline background-image for ${n}`,
62
61
  o
63
62
  );
64
63
  }
65
- if (b && (n.style.backgroundColor = f), !(n.childNodes.length > 0 || n.textContent?.trim() !== "" || y || b || k || B || N)) continue;
66
- e === "::before" ? r.insertBefore(n, r.firstChild) : r.appendChild(n);
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);
67
66
  } catch (t) {
68
- console.warn(`[snapdom] Failed to capture ${e} for`, i, t);
67
+ console.warn(`[snapdom] Failed to capture ${n} for`, a, t);
69
68
  }
70
- const C = Array.from(i.children), E = Array.from(r.children).filter(
71
- (e) => !e.dataset.snapdomPseudo
69
+ const E = Array.from(a.children), x = Array.from(r.children).filter(
70
+ (n) => !n.dataset.snapdomPseudo
72
71
  );
73
- for (let e = 0; e < Math.min(C.length, E.length); e++)
74
- await tt(C[e], E[e], d);
72
+ for (let n = 0; n < Math.min(E.length, x.length); n++)
73
+ await nt(
74
+ E[n],
75
+ x[n],
76
+ g,
77
+ z,
78
+ d
79
+ );
75
80
  }
76
81
  export {
77
- tt as inlinePseudoElements
82
+ nt as inlinePseudoElements
78
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
  };