@unicom-cloud/utils 0.1.10 → 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 (206) hide show
  1. package/caseName.js +11 -0
  2. package/className.js +5 -0
  3. package/clipboardCopy.js +6 -0
  4. package/constant.js +4 -0
  5. package/contentDisposition.js +7 -0
  6. package/cookie.js +7 -0
  7. package/date/convertTime.js +61 -0
  8. package/date/index.js +22 -0
  9. package/date.js +9 -0
  10. package/decimal.js +5 -0
  11. package/eventEmitter.js +4 -0
  12. package/file.js +6 -0
  13. package/filesize.js +8 -0
  14. package/index.js +56 -46
  15. package/invariant.js +4 -0
  16. package/is.js +92 -0
  17. package/lunar/index.js +36 -0
  18. package/lunar/lib/Holiday.js +42 -0
  19. package/lunar/lib/HolidayUtil.js +128 -0
  20. package/lunar/lib/I18n.js +1005 -0
  21. package/lunar/lib/JieQi.js +40 -0
  22. package/lunar/lib/Lunar.js +1035 -0
  23. package/lunar/lib/LunarMonth.js +150 -0
  24. package/lunar/lib/LunarTime.js +138 -0
  25. package/lunar/lib/LunarUtil.js +1752 -0
  26. package/lunar/lib/LunarYear.js +616 -0
  27. package/lunar/lib/ShouXingUtil.js +6915 -0
  28. package/lunar/lib/Solar.js +311 -0
  29. package/lunar/lib/SolarHalfYear.js +45 -0
  30. package/lunar/lib/SolarMonth.js +55 -0
  31. package/lunar/lib/SolarSeason.js +42 -0
  32. package/lunar/lib/SolarUtil.js +256 -0
  33. package/lunar/lib/SolarWeek.js +153 -0
  34. package/lunar/lib/SolarYear.js +35 -0
  35. package/lunar/lib/index.js +35 -0
  36. package/lunar.js +36 -0
  37. package/math.js +9 -0
  38. package/md5.js +4 -0
  39. package/mock.js +8 -0
  40. package/normalizeWheel.js +6 -0
  41. package/number-to-chinese/index.js +72 -0
  42. package/numberToChinese.js +4 -0
  43. package/nzh.js +4 -0
  44. package/object-keys-sort/index.js +7 -0
  45. package/objectKeysSort.js +2 -5
  46. package/package.json +1 -1
  47. package/random.js +15 -0
  48. package/screenfull.js +4 -0
  49. package/snapdom/src/api/preCache.js +26 -36
  50. package/snapdom/src/api/snapdom.js +78 -61
  51. package/snapdom/src/core/capture.js +54 -54
  52. package/snapdom/src/core/prepare.js +46 -37
  53. package/snapdom/src/modules/fonts.js +90 -92
  54. package/snapdom/src/modules/iconFonts.js +28 -0
  55. package/snapdom/src/modules/images.js +6 -6
  56. package/snapdom/src/modules/pseudo.js +51 -49
  57. package/snapdom/src/modules/styles.js +27 -7
  58. package/snapdom/src/modules/svgDefs.js +26 -0
  59. package/snapdom/src/utils/helpers.js +150 -103
  60. package/snapdom.js +6 -0
  61. package/tinycolor/index.js +46 -0
  62. package/tinycolor/src/conversion.js +143 -0
  63. package/tinycolor/src/css-color-names.js +153 -0
  64. package/tinycolor/src/format-input.js +77 -0
  65. package/tinycolor/src/from-ratio.js +21 -0
  66. package/tinycolor/src/index.js +404 -0
  67. package/tinycolor/src/random.js +221 -0
  68. package/tinycolor/src/readability.js +37 -0
  69. package/tinycolor/src/to-ms-filter.js +15 -0
  70. package/tinycolor/src/util.js +32 -0
  71. package/tinycolor.js +46 -0
  72. package/tree/index.js +10 -8
  73. package/tree/searchTree.js +54 -0
  74. package/tree.js +13 -0
  75. package/turboStream.js +6 -0
  76. package/types/case-name/index.d.ts +11 -0
  77. package/types/class-name/index.d.ts +2 -0
  78. package/types/clipboard-copy/index.d.ts +2 -0
  79. package/types/constant/address.d.ts +14 -0
  80. package/types/constant/chineseCharacters.d.ts +2 -0
  81. package/types/constant/constellations.d.ts +2 -0
  82. package/types/constant/domain.d.ts +2 -0
  83. package/types/constant/identity.d.ts +2 -0
  84. package/types/constant/index.d.ts +1 -0
  85. package/types/constant/keyboardCode.d.ts +158 -0
  86. package/types/constant/licensePlate.d.ts +2 -0
  87. package/types/constant/name.d.ts +4 -0
  88. package/types/constant/platform.d.ts +11 -0
  89. package/types/constant/protocol.d.ts +2 -0
  90. package/types/constant/ui.d.ts +14 -0
  91. package/types/content-disposition/index.d.ts +10 -0
  92. package/types/cookie/index.d.ts +4 -0
  93. package/types/cookie/src/index.d.ts +114 -0
  94. package/types/date/convertTime.d.ts +32 -0
  95. package/types/date/index.d.ts +4 -0
  96. package/types/decimal/decimal.d.ts +4 -0
  97. package/types/decimal/index.d.ts +1 -0
  98. package/types/event-emitter/index.d.ts +17 -0
  99. package/types/file/fileToURL.d.ts +2 -0
  100. package/types/file/index.d.ts +3 -0
  101. package/types/file/saveAs.d.ts +2 -0
  102. package/types/filesize/index.d.ts +2 -0
  103. package/types/filesize/src/constants.d.ts +42 -0
  104. package/types/filesize/src/filesize.d.ts +47 -0
  105. package/types/index.d.ts +25 -0
  106. package/types/invariant/index.d.ts +2 -0
  107. package/types/is/index.d.ts +53 -0
  108. package/types/lunar/index.d.ts +3 -0
  109. package/types/lunar/lib/Holiday.d.ts +17 -0
  110. package/types/lunar/lib/HolidayUtil.d.ts +23 -0
  111. package/types/lunar/lib/I18n.d.ts +23 -0
  112. package/types/lunar/lib/JieQi.d.ts +15 -0
  113. package/types/lunar/lib/Lunar.d.ts +245 -0
  114. package/types/lunar/lib/LunarMonth.d.ts +35 -0
  115. package/types/lunar/lib/LunarTime.d.ts +40 -0
  116. package/types/lunar/lib/LunarUtil.d.ts +128 -0
  117. package/types/lunar/lib/LunarYear.d.ts +61 -0
  118. package/types/lunar/lib/ShouXingUtil.d.ts +38 -0
  119. package/types/lunar/lib/Solar.d.ts +51 -0
  120. package/types/lunar/lib/SolarHalfYear.d.ts +15 -0
  121. package/types/lunar/lib/SolarMonth.d.ts +16 -0
  122. package/types/lunar/lib/SolarSeason.d.ts +15 -0
  123. package/types/lunar/lib/SolarUtil.d.ts +20 -0
  124. package/types/lunar/lib/SolarWeek.d.ts +23 -0
  125. package/types/lunar/lib/SolarYear.d.ts +12 -0
  126. package/types/lunar/lib/index.d.ts +17 -0
  127. package/types/math/index.d.ts +11 -0
  128. package/types/md5/index.d.ts +2 -0
  129. package/types/mock/MockWebSocket.d.ts +17 -0
  130. package/types/mock/MockXMLHttpRequest.d.ts +17 -0
  131. package/types/mock/index.d.ts +2 -0
  132. package/types/normalize-wheel/ExecutionEnvironment.d.ts +9 -0
  133. package/types/normalize-wheel/UserAgent_DEPRECATED.d.ts +86 -0
  134. package/types/normalize-wheel/index.d.ts +115 -0
  135. package/types/normalize-wheel/isEventSupported.d.ts +16 -0
  136. package/types/number-to-chinese/index.d.ts +11 -0
  137. package/types/nzh/cn.d.ts +8 -0
  138. package/types/nzh/hk.d.ts +8 -0
  139. package/types/nzh/index.d.ts +1 -0
  140. package/types/nzh/nzh.d.ts +36 -0
  141. package/types/nzh/src/autoGet.d.ts +8 -0
  142. package/types/nzh/src/index.d.ts +34 -0
  143. package/types/nzh/src/langs/cn_b.d.ts +10 -0
  144. package/types/nzh/src/langs/cn_s.d.ts +7 -0
  145. package/types/nzh/src/langs/hk_b.d.ts +10 -0
  146. package/types/nzh/src/langs/hk_s.d.ts +7 -0
  147. package/types/nzh/src/utils.d.ts +65 -0
  148. package/types/object-keys-sort/index.d.ts +4 -0
  149. package/types/random/address.d.ts +8 -0
  150. package/types/random/constellation.d.ts +2 -0
  151. package/types/random/image.d.ts +5 -0
  152. package/types/random/index.d.ts +40 -0
  153. package/types/random/licensePlate.d.ts +2 -0
  154. package/types/random/name.d.ts +9 -0
  155. package/types/random/number.d.ts +6 -0
  156. package/types/random/text.d.ts +13 -0
  157. package/types/random/time.d.ts +2 -0
  158. package/types/random/web.d.ts +11 -0
  159. package/types/screenfull/index.d.ts +10 -0
  160. package/types/snapdom/index.d.ts +1 -0
  161. package/types/snapdom/src/api/preCache.d.ts +8 -0
  162. package/types/snapdom/src/api/snapdom.d.ts +26 -0
  163. package/types/snapdom/src/core/cache.d.ts +11 -0
  164. package/types/snapdom/src/core/capture.d.ts +17 -0
  165. package/types/snapdom/src/core/clone.d.ts +11 -0
  166. package/types/snapdom/src/core/prepare.d.ts +8 -0
  167. package/types/snapdom/src/index.browser.d.ts +1 -0
  168. package/types/snapdom/src/index.d.ts +2 -0
  169. package/types/snapdom/src/modules/background.d.ts +10 -0
  170. package/types/snapdom/src/modules/fonts.d.ts +23 -0
  171. package/types/snapdom/src/modules/iconFonts.d.ts +2 -0
  172. package/types/snapdom/src/modules/images.d.ts +8 -0
  173. package/types/snapdom/src/modules/pseudo.d.ts +12 -0
  174. package/types/snapdom/src/modules/styles.d.ts +1 -0
  175. package/types/snapdom/src/modules/svgDefs.d.ts +19 -0
  176. package/types/snapdom/src/utils/cssTools.d.ts +38 -0
  177. package/types/snapdom/src/utils/helpers.d.ts +71 -0
  178. package/types/tinycolor/index.d.ts +2 -0
  179. package/types/tinycolor/src/conversion.d.ts +79 -0
  180. package/types/tinycolor/src/css-color-names.d.ts +4 -0
  181. package/types/tinycolor/src/format-input.d.ts +38 -0
  182. package/types/tinycolor/src/from-ratio.d.ts +14 -0
  183. package/types/tinycolor/src/index.d.ts +214 -0
  184. package/types/tinycolor/src/interfaces.d.ts +57 -0
  185. package/types/tinycolor/src/public_api.d.ts +10 -0
  186. package/types/tinycolor/src/random.d.ts +24 -0
  187. package/types/tinycolor/src/readability.d.ts +46 -0
  188. package/types/tinycolor/src/to-ms-filter.d.ts +5 -0
  189. package/types/tinycolor/src/umd_api.d.ts +22 -0
  190. package/types/tinycolor/src/util.d.ts +36 -0
  191. package/types/tree/index.d.ts +9 -0
  192. package/types/tree/searchTree.d.ts +20 -0
  193. package/types/turbo-stream/index.d.ts +1 -0
  194. package/types/turbo-stream/src/decode.d.ts +7 -0
  195. package/types/turbo-stream/src/encode.d.ts +27 -0
  196. package/types/turbo-stream/src/shared.d.ts +107 -0
  197. package/types/turbo-stream/src/turbo-stream.d.ts +4 -0
  198. package/types/ui-color/compareColorByRange.d.ts +2 -0
  199. package/types/ui-color/index.d.ts +183 -0
  200. package/types/url-toolkit/index.d.ts +2 -0
  201. package/types/url-toolkit/src/url-toolkit.d.ts +18 -0
  202. package/ui-color/compareColorByRange.js +9 -0
  203. package/ui-color/index.js +155 -0
  204. package/uiColor.js +28 -0
  205. package/urlToolkit.js +8 -0
  206. package/dayjs/index.js +0 -15
@@ -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
+ };