@unicom-cloud/utils 0.1.11 → 0.1.13

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