unocss-preset-magicolor 0.2.0 → 0.3.0

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.
@@ -0,0 +1,59 @@
1
+ import { mc as f } from "magic-color";
2
+ function r(t) {
3
+ return t && Number.parseFloat(t.toString()) || 0;
4
+ }
5
+ function g(t) {
6
+ if (!t)
7
+ return;
8
+ if (t.type === "oklch")
9
+ return t.components[0].toString().includes("%") && (t.components[0] = r(t.components[0]) / 100), t.components = t.components.map(r), t;
10
+ const n = f(
11
+ t.type === "hex" ? t.components[0].toString() : t.components,
12
+ t.type
13
+ ).toOklch().values;
14
+ if (n)
15
+ return {
16
+ type: "oklch",
17
+ components: [n[0] / 100, n[1], n[2]],
18
+ alpha: t.alpha
19
+ };
20
+ }
21
+ function u(t) {
22
+ return Math.round(t * 1e3) / 1e3;
23
+ }
24
+ const m = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
25
+ function b(t) {
26
+ let n = Number(t);
27
+ n = n <= 50 ? 50 : n, n = n >= 950 ? 950 : n;
28
+ let o = Math.floor(n / 100) * 100;
29
+ o = o <= 50 ? 50 : o;
30
+ let e = Math.floor((n + 100) / 100) * 100;
31
+ return e = e >= 950 ? 950 : e, { originDepth: n, beforeDepth: o, afterDepth: e };
32
+ }
33
+ function N(t) {
34
+ return !t || !Number.isNaN(Number(t)) ? (console.error(`[unocss-preset-margicolor] The color '${t}' is invalid.`), !0) : !1;
35
+ }
36
+ function $(t) {
37
+ const { originDepth: n, beforeDepth: o, beforeComponents: e, afterComponents: i } = t, a = (n - o) / (n < 100 || n > 900 ? 50 : 100);
38
+ return `oklch(${Array.from({ length: 3 }).map((l, c) => {
39
+ const p = r(e[c]) + (r(i[c]) - r(e[c])) * a;
40
+ return u(p);
41
+ }).join(" ")})`;
42
+ }
43
+ function k(t, n) {
44
+ const o = {};
45
+ for (const e of m)
46
+ if (n[e]) {
47
+ const i = n[e].components;
48
+ o[`--mc-${t}-${e}-l`] = u(r(i[0])), o[`--mc-${t}-${e}-c`] = u(r(i[1])), o[`--mc-${t}-${e}-h`] = u(r(i[2]));
49
+ }
50
+ return o;
51
+ }
52
+ export {
53
+ g as a,
54
+ $ as c,
55
+ k as g,
56
+ N as i,
57
+ b as r,
58
+ m as t
59
+ };
package/dist/helper.js CHANGED
@@ -1,42 +1,40 @@
1
- import { formatHex as C } from "culori";
2
1
  import { mc as m } from "magic-color";
3
- import { i as d, a as u, t as g, c as b, p as y, r as D } from "./common-BKEe-sBl.js";
4
- function O(p) {
5
- const { name: n, color: a, dom: i } = p;
2
+ import { i as h, t as C, a as g, c as d, g as u, r as b } from "./common-Dv0krm1V.js";
3
+ function M(p) {
4
+ const { name: c, color: a, dom: i } = p;
6
5
  if (!i)
7
6
  return;
8
- const c = a?.split(/-\d+-?/)[0];
9
- if (d(c))
7
+ const s = a?.split(/-\d+-?/)[0];
8
+ if (h(s))
10
9
  return;
11
- const t = {}, e = {};
10
+ const e = {}, t = {};
12
11
  try {
13
- const o = C(c) || c;
14
- if (o && m.valid(o)) {
15
- t[`--mc-${n}-color`] = o;
16
- const r = m.theme(o);
17
- for (const s of u) {
18
- const h = g({ type: "hex", components: [r[s]], alpha: 1 });
19
- e[s] = h;
12
+ if (m.valid(s)) {
13
+ e[`--mc-${c}-color`] = s;
14
+ const o = m.theme(s, { type: "hex" });
15
+ for (const r of C) {
16
+ const n = g({ type: "hex", components: [o[r]], alpha: 1 });
17
+ t[r] = n;
20
18
  }
21
19
  }
22
20
  } catch (o) {
23
- console.error(`[updateMagicColor] get ${c} theme fail, please use another color.`), console.error(o);
21
+ console.error(`[updateMagicColor] get ${s} theme fail, please use another color.`), console.error(o);
24
22
  }
25
23
  const l = a.match(/.*-(\d+)/)?.[1];
26
24
  if (l) {
27
- const { originDepth: o, beforeDepth: r, afterDepth: s } = D(l);
28
- e[r] && e[s] && (t[`--mc-${n}-color`] = b({
25
+ const { originDepth: o, beforeDepth: r, afterDepth: n } = b(l);
26
+ t[r] && t[n] && (e[`--mc-${c}-color`] = d({
29
27
  originDepth: o,
30
28
  beforeDepth: r,
31
- beforeComponents: e[r].components,
32
- afterComponents: e[s].components
29
+ beforeComponents: t[r].components,
30
+ afterComponents: t[n].components
33
31
  }));
34
32
  }
35
- const f = y(n, e);
36
- Object.assign(t, f);
37
- for (const o in t)
38
- t[o] && i.style.setProperty(o, t[o].toString());
33
+ const f = u(c, t);
34
+ Object.assign(e, f);
35
+ for (const o in e)
36
+ e[o] && i.style.setProperty(o, e[o].toString());
39
37
  }
40
38
  export {
41
- O as updateMagicColor
39
+ M as updateMagicColor
42
40
  };
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
- import { colorCSSGenerator as I, parseColor as f, defineProperty as m, generateThemeVariable as N, themeTracking as z, detectThemeValue as B, h as b, SpecialColorKey as E, numberResolver as M, hyphenate as x } from "@unocss/preset-wind4/utils";
2
- import { formatHex as L } from "culori";
3
- import { mc as C } from "magic-color";
4
- import { i as P, r as V, t as v, c as H, a as y, p as G } from "./common-BKEe-sBl.js";
1
+ import { colorCSSGenerator as R, parseColor as f, defineProperty as m, generateThemeVariable as B, themeTracking as z, detectThemeValue as E, h, SpecialColorKey as G, numberResolver as M, hyphenate as C } from "@unocss/preset-wind4/utils";
2
+ import { mc as y } from "magic-color";
3
+ import { r as V, t as v, i as L, a as x, c as P, g as H } from "./common-Dv0krm1V.js";
5
4
  import { notNull as U } from "unocss";
6
5
  import { notLastChildSelectorVariant as q } from "@unocss/preset-wind4/rules";
7
6
  function A(e, o) {
@@ -18,54 +17,58 @@ function A(e, o) {
18
17
  alpha: a && `${a}%`,
19
18
  keys: void 0,
20
19
  cssColor: void 0
21
- }, P(n) || !c)
20
+ }, L(n) || !c)
22
21
  return r;
23
- const { originDepth: l, beforeDepth: i, afterDepth: p } = V(c);
24
- let $ = f(`${n}-${i}`, o)?.cssColor, d = f(`${n}-${p}`, o)?.cssColor;
22
+ const { originDepth: i, beforeDepth: l, afterDepth: p } = V(c);
23
+ let $ = f(`${n}-${l}`, o)?.cssColor, d = f(`${n}-${p}`, o)?.cssColor;
25
24
  if (!$ || !d)
26
25
  try {
27
- const h = f(n, o)?.color, g = h ? L(h) : void 0;
28
- if (g && C.valid(g)) {
29
- const O = C.theme(g);
30
- $ || ($ = v({ type: "hex", components: [O[i]], alpha: 1 })), d || (d = v({ type: "hex", components: [O[p]], alpha: 1 }));
26
+ const g = f(n, o);
27
+ if (g?.color && y.valid(g.color)) {
28
+ const b = y.theme(g.color, { type: "hex" });
29
+ $ || ($ = { type: "hex", components: [b[l]], alpha: 1 }), d || (d = { type: "hex", components: [b[p]], alpha: 1 });
31
30
  }
32
- } catch (h) {
33
- console.error(`[unocss-preset-margicolor] Error parsing ${e}: get ${n} theme fail, please use another color.`), console.error(h);
31
+ } catch (g) {
32
+ console.error(`[unocss-preset-margicolor] Error parsing ${e}: get ${n} theme fail, please use another color.`), console.error(g);
34
33
  }
35
- return $ = v($), d = v(d), !$ || !d || (r.color = H({
36
- originDepth: l,
37
- beforeDepth: i,
34
+ return $ = x($), d = x(d), !$ || !d || (r.color = P({
35
+ originDepth: i,
36
+ beforeDepth: l,
38
37
  beforeComponents: $.components,
39
38
  afterComponents: d.components
40
39
  })), r;
41
40
  }
42
41
  function F(e) {
43
- const o = {};
42
+ const o = [];
44
43
  if (!e || e.color)
45
- return { colorData: e, cssVariable: o };
44
+ return { colorData: e, cssVariables: o };
46
45
  const { name: r, no: t } = e;
47
46
  if (!t)
48
- return e.color = `var(--mc-${r}-color)`, { colorData: e, cssVariable: o };
49
- const { originDepth: a, beforeDepth: s, afterDepth: c } = V(t), n = `--mc-${r}-${a}-l`, l = `--mc-${r}-${a}-c`, i = `--mc-${r}-${a}-h`;
50
- if (!y.includes(a)) {
51
- const p = (a - s) / (a < 100 || a > 900 ? 50 : 100), [$, d, h] = ["l", "c", "h"].map((g) => `calc(var(--mc-${r}-${s}-${g}) + ${p} * (var(--mc-${r}-${c}-${g}) - var(--mc-${r}-${s}-${g})))`);
52
- Object.assign(o, { [n]: $, [l]: d, [i]: h });
47
+ return e.color = `var(--mc-${r}-color)`, { colorData: e, cssVariables: o };
48
+ const { originDepth: a, beforeDepth: s, afterDepth: c } = V(t), n = `--mc-${r}-${a}-l`, i = `--mc-${r}-${a}-c`, l = `--mc-${r}-${a}-h`;
49
+ if (!v.includes(a)) {
50
+ const p = (a - s) / (a < 100 || a > 900 ? 50 : 100), [$, d, g] = ["l", "c", "h"].map((b) => {
51
+ const O = `var(--mc-${r}-${s}-${b})`, N = `var(--mc-${r}-${c}-${b})`;
52
+ return `calc(${O} + ${p} * (${N} - ${O}))`;
53
+ });
54
+ o.push({ [n]: $, [i]: d, [l]: g });
53
55
  }
54
- return e.color = `oklch(var(${n}) var(${l}) var(${i}))`, { colorData: e, cssVariable: o };
56
+ return e.color = `oklch(var(${n}) var(${i}) var(${l}))`, { colorData: e, cssVariables: o };
55
57
  }
56
58
  function w(e, o) {
57
- const r = A(e, o);
58
- return F(r);
59
+ return F(
60
+ A(e, o)
61
+ );
59
62
  }
60
63
  function u(e, o) {
61
64
  return ([, r], t) => {
62
- const { colorData: a, cssVariable: s } = w(r ?? "", t.theme);
65
+ const { colorData: a, cssVariables: s } = w(r ?? "", t.theme);
63
66
  if (a?.color) {
64
- const c = I(a, e, o, t);
65
- return c && c.push({
66
- [t.symbols.selector]: (n) => n,
67
- ...s
68
- }), c;
67
+ const c = R(a, e, o, t);
68
+ return c && s.length && c.push(...s.map((n) => ({
69
+ [t.symbols.selector]: (i) => i,
70
+ ...n
71
+ }))), c;
69
72
  }
70
73
  };
71
74
  }
@@ -86,21 +89,21 @@ const J = {
86
89
  };
87
90
  function W() {
88
91
  return function* ([, e, o], { theme: r, symbols: t }) {
89
- const a = {}, { colorData: s, cssVariable: c } = w(o, r);
92
+ const a = {}, { colorData: s, cssVariables: c } = w(o, r);
90
93
  if (s) {
91
- const { color: n, keys: l, alpha: i } = s;
94
+ const { color: n, keys: i, alpha: l } = s;
92
95
  if (n) {
93
96
  if (Object.values(J).includes(n))
94
97
  a[`--un-gradient-${e}`] = n;
95
98
  else {
96
- a[`--un-${e}-opacity`] = i;
97
- const p = l ? N("colors", l) : n;
99
+ a[`--un-${e}-opacity`] = l;
100
+ const p = i ? B("colors", i) : n;
98
101
  a[`--un-gradient-${e}`] = `color-mix(in oklab, ${p} var(--un-${e}-opacity), transparent)`, yield m(`--un-${e}-opacity`, { syntax: "<percentage>", initialValue: "100%" });
99
102
  }
100
- l && z("colors", l), r && B(n, r);
103
+ i && z("colors", i), r && E(n, r);
101
104
  }
102
105
  } else
103
- a[`--un-gradient-${e}`] = b.bracket.cssvar(o);
106
+ a[`--un-gradient-${e}`] = h.bracket.cssvar(o);
104
107
  if (a[`--un-gradient-${e}`]) {
105
108
  switch (e) {
106
109
  case "from":
@@ -128,10 +131,11 @@ function W() {
128
131
  }
129
132
  for (const n of Object.values(Q))
130
133
  yield n;
131
- yield {
132
- [t.selector]: (n) => n,
133
- ...c
134
- };
134
+ for (const n of c)
135
+ yield {
136
+ [t.selector]: (i) => i,
137
+ ...n
138
+ };
135
139
  }
136
140
  };
137
141
  }
@@ -156,26 +160,26 @@ const S = {
156
160
  };
157
161
  function k([, e = "", o], r) {
158
162
  if (e in S) {
159
- const { colorData: t, cssVariable: a } = w(o ?? "", r.theme);
163
+ const { colorData: t, cssVariables: a } = w(o ?? "", r.theme);
160
164
  if (t) {
161
165
  const s = S[e].map((c) => X(c)(t, r)).filter(U);
162
166
  return [
163
167
  s.map((c) => c[0]).reduce((c, n) => (Object.assign(c, n), c), {}),
164
168
  ...s.flatMap((c) => c.slice(1)),
165
- {
166
- [r.symbols.selector]: (c) => c,
167
- ...a
168
- }
169
+ ...a.map((c) => ({
170
+ [r.symbols.selector]: (n) => n,
171
+ ...c
172
+ }))
169
173
  ];
170
174
  }
171
175
  }
172
176
  }
173
177
  function X(e) {
174
178
  return (o, r) => {
175
- const t = I(o, `border${e}-color`, `border${e}`, r);
179
+ const t = R(o, `border${e}-color`, `border${e}`, r);
176
180
  if (t) {
177
181
  const a = t[0];
178
- return o?.color && !Object.values(E).includes(o.color) && !o.alpha && e && e !== "" && (a[`--un-border${e}-opacity`] = "var(--un-border-opacity)"), t;
182
+ return o?.color && !Object.values(G).includes(o.color) && !o.alpha && e && e !== "" && (a[`--un-border${e}-opacity`] = "var(--un-border-opacity)"), t;
179
183
  }
180
184
  };
181
185
  }
@@ -190,26 +194,26 @@ const Y = {
190
194
  x: ["left", "right"],
191
195
  y: ["top", "bottom"]
192
196
  }, D = "linear-gradient(#fff, #fff)";
193
- function R([e, o = "", r, t], a) {
197
+ function T([e, o = "", r, t], a) {
194
198
  const s = { ...Y }, c = [];
195
199
  if (c.push(...["linear", "radial", "conic"].map((n) => m(`--un-mask-${n}`, { initialValue: D }))), o in j) {
196
200
  s["--un-mask-linear"] = "var(--un-mask-left), var(--un-mask-right), var(--un-mask-bottom), var(--un-mask-top)";
197
201
  for (const n of j[o]) {
198
- s[`--un-mask-${n}`] = `linear-gradient(to ${n}, var(--un-mask-${n}-from-color) var(--un-mask-${n}-from-position), var(--un-mask-${n}-to-color) var(--un-mask-${n}-to-position))`, M(t) != null ? (z("spacing"), s[`--un-mask-${n}-${r}-position`] = `calc(var(--spacing) * ${b.bracket.cssvar.fraction.number(t)})`) : s[`--un-mask-${n}-${r}-position`] = b.bracket.cssvar.fraction.rem(t);
199
- const l = u(`--un-mask-${n}-${r}-color`, x("colors"))([e, t], a);
200
- if (l) {
201
- const [i, ...p] = l;
202
- Object.assign(s, i), c.push(...p);
202
+ s[`--un-mask-${n}`] = `linear-gradient(to ${n}, var(--un-mask-${n}-from-color) var(--un-mask-${n}-from-position), var(--un-mask-${n}-to-color) var(--un-mask-${n}-to-position))`, M(t) != null ? (z("spacing"), s[`--un-mask-${n}-${r}-position`] = `calc(var(--spacing) * ${h.bracket.cssvar.fraction.number(t)})`) : s[`--un-mask-${n}-${r}-position`] = h.bracket.cssvar.fraction.rem(t);
203
+ const i = u(`--un-mask-${n}-${r}-color`, C("colors"))([e, t], a);
204
+ if (i) {
205
+ const [l, ...p] = i;
206
+ Object.assign(s, l), c.push(...p);
203
207
  }
204
- c.push(...["from", "to"].flatMap((i) => [
205
- m(`--un-mask-${n}-${i}-position`, { syntax: "<length-percentage>", initialValue: i === "from" ? "0%" : "100%" }),
206
- m(`--un-mask-${n}-${i}-color`, { syntax: "<color>", initialValue: i === "from" ? "black" : "transparent" })
208
+ c.push(...["from", "to"].flatMap((l) => [
209
+ m(`--un-mask-${n}-${l}-position`, { syntax: "<length-percentage>", initialValue: l === "from" ? "0%" : "100%" }),
210
+ m(`--un-mask-${n}-${l}-color`, { syntax: "<color>", initialValue: l === "from" ? "black" : "transparent" })
207
211
  ]));
208
212
  }
209
213
  c.push(...["top", "right", "bottom", "left"].map((n) => m(`--un-mask-${n}`, { initialValue: D })));
210
214
  } else {
211
215
  if (r == null)
212
- o === "radial" ? (s["--un-mask-radial"] = "radial-gradient(var(--un-mask-radial-stops, var(--un-mask-radial-size)))", s["--un-mask-radial-size"] = b.bracket.cssvar.rem(t)) : (s[`--un-mask-${o}`] = `${o}-gradient(var(--un-mask-${o}-stops, var(--un-mask-${o}-position)))`, s[`--un-mask-${o}-position`] = M(t) ? `calc(1deg * ${b.bracket.cssvar.number(t)})` : b.bracket.cssvar.fraction(t));
216
+ o === "radial" ? (s["--un-mask-radial"] = "radial-gradient(var(--un-mask-radial-stops, var(--un-mask-radial-size)))", s["--un-mask-radial-size"] = h.bracket.cssvar.rem(t)) : (s[`--un-mask-${o}`] = `${o}-gradient(var(--un-mask-${o}-stops, var(--un-mask-${o}-position)))`, s[`--un-mask-${o}-position`] = M(t) ? `calc(1deg * ${h.bracket.cssvar.number(t)})` : h.bracket.cssvar.fraction(t));
213
217
  else {
214
218
  const n = {
215
219
  linear: "",
@@ -217,10 +221,10 @@ function R([e, o = "", r, t], a) {
217
221
  conic: "from "
218
222
  };
219
223
  s[`--un-mask-${o}-stops`] = `${n[o]}var(--un-mask-${o}-position), var(--un-mask-${o}-from-color) var(--un-mask-${o}-from-position), var(--un-mask-${o}-to-color) var(--un-mask-${o}-to-position)`, s[`--un-mask-${o}`] = `${o}-gradient(var(--un-mask-${o}-stops))`;
220
- const l = u(`--un-mask-${o}-${r}-color`, x("colors"))([e, t], a);
221
- if (l) {
222
- const [i, ...p] = l;
223
- Object.assign(s, i), c.push(...p);
224
+ const i = u(`--un-mask-${o}-${r}-color`, C("colors"))([e, t], a);
225
+ if (i) {
226
+ const [l, ...p] = i;
227
+ Object.assign(s, l), c.push(...p);
224
228
  }
225
229
  }
226
230
  o === "radial" && c.push(m("--un-mask-radial-shape", { initialValue: "ellipse" }), m("--un-mask-radial-size", { initialValue: "farthest-corner" })), c.push(...["from", "to"].flatMap((n) => [
@@ -231,38 +235,35 @@ function R([e, o = "", r, t], a) {
231
235
  }
232
236
  return [s, ...c];
233
237
  }
234
- function T(e) {
238
+ function I(e) {
235
239
  return (o, r) => {
236
- const t = x(e);
240
+ const t = C(e);
237
241
  return u(`--un-${t}-color`, t)(o, r);
238
242
  };
239
243
  }
240
244
  function Z(e, o) {
241
245
  const r = e?.split(/-\d+-?/)[0];
242
- if (P(r))
246
+ if (L(r))
243
247
  return;
244
248
  const t = {};
245
249
  let a = !1;
246
- for (const s of y) {
250
+ for (const s of v) {
247
251
  const c = f(`${r}-${s}`, o)?.cssColor;
248
252
  c ? t[s] = c : a = !0;
249
253
  }
250
254
  if (a)
251
255
  try {
252
- const s = f(r, o)?.color || f(`[${r}]`, o)?.color, c = s ? L(s) : void 0;
253
- if (c && C.valid(c)) {
254
- const n = C.theme(c);
255
- for (const l of y)
256
- if (!t[l]) {
257
- const i = v({ type: "hex", components: [n[l]], alpha: 1 });
258
- t[l] = i;
259
- }
256
+ let s = f(r, o);
257
+ if (s?.color || (s = f(`[${r}]`, o)), s?.color && y.valid(s.color)) {
258
+ const c = y.theme(s.color, { type: "hex" });
259
+ for (const n of v)
260
+ t[n] || (t[n] = { type: "hex", components: [c[n]], alpha: 1 });
260
261
  }
261
262
  } catch (s) {
262
263
  console.error(`[unocss-preset-margicolor] get ${r} theme fail, please use another color.`), console.error(s);
263
264
  }
264
- for (const s of y)
265
- t[s] = v(t[s]);
265
+ for (const s of v)
266
+ t[s] = x(t[s]);
266
267
  return t;
267
268
  }
268
269
  function _(e, o, r, t) {
@@ -271,15 +272,15 @@ function _(e, o, r, t) {
271
272
  if (!c && !a && (c = f(`[${o}]`, t)?.color), c)
272
273
  s[`--mc-${e}-color`] = c;
273
274
  else if (a) {
274
- const { originDepth: l, beforeDepth: i, afterDepth: p } = V(a);
275
- r[i] && r[p] && (s[`--mc-${e}-color`] = H({
276
- originDepth: l,
277
- beforeDepth: i,
278
- beforeComponents: r[i].components,
275
+ const { originDepth: i, beforeDepth: l, afterDepth: p } = V(a);
276
+ r[l] && r[p] && (s[`--mc-${e}-color`] = P({
277
+ originDepth: i,
278
+ beforeDepth: l,
279
+ beforeComponents: r[l].components,
279
280
  afterComponents: r[p].components
280
281
  }));
281
282
  }
282
- const n = G(e, r);
283
+ const n = H(e, r);
283
284
  return Object.assign(s, n);
284
285
  }
285
286
  function K(e, o, r = {}) {
@@ -335,14 +336,14 @@ const ro = [
335
336
  [/^ring-mc-(.+)$/, u("--un-ring-color", "ring"), { autocomplete: "ring-mc-$colors" }],
336
337
  [/^inset-ring-mc-(.+)$/, u("--un-inset-ring-color", "inset-ring"), { autocomplete: "inset-ring-mc-$colors" }],
337
338
  [/^ring-offset-mc-(.+)$/, u("--un-ring-offset-color", "ring-offset"), { autocomplete: "ring-offset-mc-$colors" }],
338
- [/^shadow-mc-(.+)$/, T("shadow"), { autocomplete: ["shadow-$colors", "shadow-mc-$shadow"] }],
339
- [/^inset-shadow-mc(.+)$/, T("insetShadow"), { autocomplete: ["inset-shadow-mc-$colors", "inset-shadow-mc-$insetShadow"] }],
339
+ [/^shadow-mc-(.+)$/, I("shadow"), { autocomplete: ["shadow-$colors", "shadow-mc-$shadow"] }],
340
+ [/^inset-shadow-mc(.+)$/, I("insetShadow"), { autocomplete: ["inset-shadow-mc-$colors", "inset-shadow-mc-$insetShadow"] }],
340
341
  [/^fill-mc-(.+)$/, u("fill", "fill"), { autocomplete: "fill-mc-$colors" }],
341
342
  [/^stroke-mc-(.+)$/, u("stroke", "stroke"), { autocomplete: "stroke-mc-$colors" }],
342
343
  [/^text-stroke-mc-(.+)$/, u("-webkit-text-stroke-color", "text-stroke"), { autocomplete: "text-stroke-mc-$colors" }],
343
344
  [/^text-shadow-(?:color-)?mc-(.+)$/, u("--un-text-shadow-color", "text-shadow"), { autocomplete: ["text-shadow(-color)?-mc-$colors"] }],
344
- [/^mask-(linear|radial|conic)-(from|to)-mc-(.+)$/, R, { autocomplete: ["mask-(linear|radial|conic)-(from|to)-mc-$colors"] }],
345
- [/^mask-([trblxy])-(from|to)-mc-(.+)$/, R, { autocomplete: ["mask-(x|y|t|b|l|r)-(from|to)-mc-$colors"] }],
345
+ [/^mask-(linear|radial|conic)-(from|to)-mc-(.+)$/, T, { autocomplete: ["mask-(linear|radial|conic)-(from|to)-mc-$colors"] }],
346
+ [/^mask-([trblxy])-(from|to)-mc-(.+)$/, T, { autocomplete: ["mask-(x|y|t|b|l|r)-(from|to)-mc-$colors"] }],
346
347
  // border style colors
347
348
  [/^(?:border|b)-()(?:color-)?mc-(.+)$/, k, { autocomplete: ["(border|b)-mc-$colors", "(border|b)-<directions>-mc-$colors"] }],
348
349
  [/^(?:border|b)-([xy])-(?:color-)?mc-(.+)$/, k],
@@ -362,7 +363,7 @@ const no = [
362
363
  ro,
363
364
  eo
364
365
  ].flat();
365
- function mo(e = {}) {
366
+ function uo(e = {}) {
366
367
  return {
367
368
  name: "unocss-preset-magicolor",
368
369
  layer: "unocss-preset-magicolor",
@@ -372,6 +373,6 @@ function mo(e = {}) {
372
373
  };
373
374
  }
374
375
  export {
375
- mo as default,
376
- mo as presetMagicolor
376
+ uo as default,
377
+ uo as presetMagicolor
377
378
  };
@@ -1,2 +1,3 @@
1
+ import { Theme } from '@unocss/preset-wind4';
1
2
  import { Rule } from 'unocss';
2
- export declare const colorStyle: Rule[];
3
+ export declare const colorStyle: Rule<Theme>[];
@@ -1,3 +1,3 @@
1
1
  import { Theme } from '@unocss/preset-wind4';
2
2
  import { CSSEntries, CSSValueInput, RuleContext } from 'unocss';
3
- export declare function mcBorderColorResolver([, a, b]: string[], ctx: RuleContext<Theme>): CSSEntries | (CSSValueInput | string)[] | undefined;
3
+ export declare function handlerBorderColor([, a, b]: string[], ctx: RuleContext<Theme>): CSSEntries | (CSSValueInput | string)[] | undefined;
@@ -7,4 +7,4 @@ import { CSSObject } from 'unocss';
7
7
  * @param theme unocss theme
8
8
  * @returns css variables
9
9
  */
10
- export declare function resolveColorVariable(name: string, hue: string, theme?: Theme): CSSObject | undefined;
10
+ export declare function resolveThemeColorVariable(name: string, hue: string, theme?: Theme): CSSObject | undefined;
@@ -11,6 +11,6 @@ export declare function parseMagicColor(body: string, theme: Theme): {
11
11
  keys: string[] | undefined;
12
12
  readonly cssColor: import('@unocss/preset-wind4/utils').CSSColorValue | undefined;
13
13
  } | undefined;
14
- cssVariable: CSSObject;
14
+ cssVariables: CSSObject[];
15
15
  };
16
16
  export declare function mcColorResolver(property: string, varName: string): ([, body]: string[], ctx: RuleContext<Theme>) => (CSSValueInput | string)[] | undefined;
@@ -17,4 +17,4 @@ export declare function countDiffColor(params: {
17
17
  beforeComponents: (string | number)[];
18
18
  afterComponents: (string | number)[];
19
19
  }): string;
20
- export declare function parseOklchVariable(name: string, themeMetaColors: Partial<Record<ThemeKey, CSSColorValue>>): CSSObject;
20
+ export declare function generateOklchVariable(name: string, themeMetaColors: Partial<Record<ThemeKey, CSSColorValue>>): CSSObject;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unocss-preset-magicolor",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "description": "Unocss预设",
6
6
  "author": "nxy",
7
7
  "license": "MIT",
@@ -26,12 +26,10 @@
26
26
  "dist"
27
27
  ],
28
28
  "dependencies": {
29
- "@unocss/preset-wind4": "~66.5.5",
30
- "culori": "^4.0.2",
31
- "magic-color": "^2.1.0"
29
+ "@unocss/preset-wind4": "~66.5.9",
30
+ "magic-color": "^2.2.3"
32
31
  },
33
32
  "devDependencies": {
34
- "@types/culori": "^4.0.1",
35
- "unocss": "^66.5.5"
33
+ "unocss": "^66.5.9"
36
34
  }
37
35
  }
@@ -1,57 +0,0 @@
1
- import { converter as f } from "culori";
2
- const h = f("oklch");
3
- function r(t) {
4
- return t && Number.parseFloat(t.toString()) || 0;
5
- }
6
- function b(t) {
7
- if (!t)
8
- return;
9
- if (t.type === "oklch")
10
- return t.components[0].toString().includes("%") && (t.components[0] = r(t.components[0]) / 100), t.components = t.components.map(r), t;
11
- const n = t.components.join(" "), e = h(t.type === "hex" ? n : `${t.type}(${n})`);
12
- if (e)
13
- return {
14
- type: "oklch",
15
- components: [e.l, e.c, e.h ?? 0],
16
- alpha: t.alpha
17
- };
18
- }
19
- function i(t) {
20
- return Math.round(t * 1e3) / 1e3;
21
- }
22
- const m = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
23
- function k(t) {
24
- let n = Number(t);
25
- n = n <= 50 ? 50 : n, n = n >= 950 ? 950 : n;
26
- let e = Math.floor(n / 100) * 100;
27
- e = e <= 50 ? 50 : e;
28
- let o = Math.floor((n + 100) / 100) * 100;
29
- return o = o >= 950 ? 950 : o, { originDepth: n, beforeDepth: e, afterDepth: o };
30
- }
31
- function N(t) {
32
- return !t || !Number.isNaN(Number(t)) ? (console.error(`[unocss-preset-margicolor] The color '${t}' is invalid.`), !0) : !1;
33
- }
34
- function D(t) {
35
- const { originDepth: n, beforeDepth: e, beforeComponents: o, afterComponents: c } = t, p = (n - e) / (n < 100 || n > 900 ? 50 : 100);
36
- return `oklch(${Array.from({ length: 3 }).map((s, u) => {
37
- const a = r(o[u]) + (r(c[u]) - r(o[u])) * p;
38
- return i(a);
39
- }).join(" ")})`;
40
- }
41
- function d(t, n) {
42
- const e = {};
43
- for (const o of m)
44
- if (n[o]) {
45
- const c = n[o].components;
46
- e[`--mc-${t}-${o}-l`] = i(r(c[0])), e[`--mc-${t}-${o}-c`] = i(r(c[1])), e[`--mc-${t}-${o}-h`] = i(r(c[2]));
47
- }
48
- return e;
49
- }
50
- export {
51
- m as a,
52
- D as c,
53
- N as i,
54
- d as p,
55
- k as r,
56
- b as t
57
- };