unocss-preset-magicolor 0.1.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.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/helper.js +5 -0
- package/dist/index.js +386 -0
- package/dist/types/helper.d.ts +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/rules/color-style.d.ts +2 -0
- package/dist/types/rules/color-variable.d.ts +2 -0
- package/dist/types/rules/index.d.ts +2 -0
- package/dist/types/types.d.ts +3 -0
- package/dist/types/typing.d.ts +2 -0
- package/dist/types/utils/bg-gradient.d.ts +3 -0
- package/dist/types/utils/border.d.ts +3 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/mask.d.ts +3 -0
- package/dist/types/utils/shadow.d.ts +3 -0
- package/dist/types/utils/transforms.d.ts +5 -0
- package/dist/types/utils/utilities.d.ts +23 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 TodayDrizzle
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/helper.js
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { notLastChildSelectorVariant as A } from "@unocss/preset-wind4/rules";
|
|
2
|
+
import { colorCSSGenerator as H, parseColor as y, defineProperty as f, generateThemeVariable as B, themeTracking as I, detectThemeValue as G, h as x, SpecialColorKey as F, numberResolver as R, hyphenate as D } from "@unocss/preset-wind4/utils";
|
|
3
|
+
import { converter as q, formatHex as K } from "culori";
|
|
4
|
+
import { mc as N } from "magic-color";
|
|
5
|
+
import { notNull as J } from "unocss";
|
|
6
|
+
const Q = q("oklch");
|
|
7
|
+
function h(r) {
|
|
8
|
+
return r && Number.parseFloat(r.toString()) || 0;
|
|
9
|
+
}
|
|
10
|
+
function C(r) {
|
|
11
|
+
if (!r)
|
|
12
|
+
return;
|
|
13
|
+
if (r.type === "oklch")
|
|
14
|
+
return r.components[0].toString().includes("%") && (r.components[0] = h(r.components[0]) / 100), r.components = r.components.map(h), r;
|
|
15
|
+
const o = r.components.join(" "), e = Q(r.type === "hex" ? o : `${r.type}(${o})`);
|
|
16
|
+
if (e)
|
|
17
|
+
return {
|
|
18
|
+
type: "oklch",
|
|
19
|
+
components: [e.l, e.c, e.h ?? 0],
|
|
20
|
+
alpha: r.alpha
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const M = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
24
|
+
function O(r) {
|
|
25
|
+
let o = Number(r);
|
|
26
|
+
o = o <= 50 ? 50 : o, o = o >= 950 ? 950 : o;
|
|
27
|
+
let e = Math.floor(o / 100) * 100;
|
|
28
|
+
e = e <= 50 ? 50 : e;
|
|
29
|
+
let n = Math.floor((o + 100) / 100) * 100;
|
|
30
|
+
return n = n >= 950 ? 950 : n, { originDepth: o, beforeDepth: e, afterDepth: n };
|
|
31
|
+
}
|
|
32
|
+
function U(r, o) {
|
|
33
|
+
let e = y(r, o);
|
|
34
|
+
if (e?.color)
|
|
35
|
+
return e;
|
|
36
|
+
const [n, a, c] = r.split(/[:/]/), s = n.match(/.*-(\d+)/)?.[1], t = n?.split(/-\d+-?/)[0];
|
|
37
|
+
if (e = {
|
|
38
|
+
opacity: a,
|
|
39
|
+
modifier: c,
|
|
40
|
+
name: t,
|
|
41
|
+
no: s,
|
|
42
|
+
color: "",
|
|
43
|
+
alpha: a && `${a}%`,
|
|
44
|
+
keys: void 0,
|
|
45
|
+
cssColor: void 0
|
|
46
|
+
}, !t || !Number.isNaN(Number(t)))
|
|
47
|
+
return console.error(`[unocss-preset-margicolor][mc-${r}] The color '${t}' is invalid.`), e;
|
|
48
|
+
if (!s)
|
|
49
|
+
return e;
|
|
50
|
+
const { originDepth: i, beforeDepth: u, afterDepth: $ } = O(s);
|
|
51
|
+
let l = y(`${t}-${u}`, o)?.cssColor, m = y(`${t}-${$}`, o)?.cssColor;
|
|
52
|
+
if (!l || !m)
|
|
53
|
+
try {
|
|
54
|
+
const g = y(t, o)?.color, k = g ? K(g) : void 0;
|
|
55
|
+
if (k && N.valid(k)) {
|
|
56
|
+
const v = N.theme(k);
|
|
57
|
+
l || (l = C({ type: "hex", components: [v[u]], alpha: 1 })), m || (m = C({ type: "hex", components: [v[$]], alpha: 1 }));
|
|
58
|
+
}
|
|
59
|
+
} catch (g) {
|
|
60
|
+
console.error(`[unocss-preset-margicolor] Error parsing ${r}: get ${t} theme fail, please use another color.`), console.error(g);
|
|
61
|
+
}
|
|
62
|
+
if (l = C(l), m = C(m), !l || !m)
|
|
63
|
+
return e;
|
|
64
|
+
const b = (i - u) / (i < 100 || i > 950 ? 50 : 100), d = Array.from({ length: 3 }).map((g, k) => {
|
|
65
|
+
const v = l.components, w = m.components, S = h(v[k]) + (h(w[k]) - h(v[k])) * b;
|
|
66
|
+
return `${Math.round(S * 1e3) / 1e3}`;
|
|
67
|
+
});
|
|
68
|
+
return e.color = `oklch(${d.join(" ")})`, e;
|
|
69
|
+
}
|
|
70
|
+
function W(r) {
|
|
71
|
+
const o = {};
|
|
72
|
+
if (!r || r.color)
|
|
73
|
+
return { colorData: r, cssVariable: o };
|
|
74
|
+
const { name: e, no: n } = r;
|
|
75
|
+
if (!n)
|
|
76
|
+
return r.color = `var(--mc-${e}-color)`, { colorData: r, cssVariable: o };
|
|
77
|
+
const { originDepth: a, beforeDepth: c, afterDepth: s } = O(n), t = `--mc-${e}-${a}-l`, i = `--mc-${e}-${a}-c`, u = `--mc-${e}-${a}-h`;
|
|
78
|
+
if (!M.includes(a)) {
|
|
79
|
+
const $ = (a - c) / (a < 100 || a > 950 ? 50 : 100), [l, m, b] = ["l", "c", "h"].map((d) => `calc(var(--mc-${e}-${c}-${d}) + ${$} * (var(--mc-${e}-${s}-${d}) - var(--mc-${e}-${c}-${d})))`);
|
|
80
|
+
Object.assign(o, { [t]: l, [i]: m, [u]: b });
|
|
81
|
+
}
|
|
82
|
+
return r.color = `oklch(var(${t}) var(${i}) var(${u}))`, { colorData: r, cssVariable: o };
|
|
83
|
+
}
|
|
84
|
+
function j(r, o) {
|
|
85
|
+
const e = U(r, o);
|
|
86
|
+
return W(e);
|
|
87
|
+
}
|
|
88
|
+
function p(r, o) {
|
|
89
|
+
return ([, e], n) => {
|
|
90
|
+
const { colorData: a, cssVariable: c } = j(e ?? "", n.theme);
|
|
91
|
+
if (a?.color) {
|
|
92
|
+
const s = H(a, r, o, n);
|
|
93
|
+
return s && s.push({
|
|
94
|
+
[n.symbols.selector]: (t) => t,
|
|
95
|
+
...c
|
|
96
|
+
}), s;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const X = {
|
|
101
|
+
transparent: "transparent",
|
|
102
|
+
current: "currentColor",
|
|
103
|
+
inherit: "inherit"
|
|
104
|
+
}, Y = {
|
|
105
|
+
"gradient-position": f("--un-gradient-position"),
|
|
106
|
+
"gradient-from": f("--un-gradient-from", { syntax: "<color>", initialValue: "#0000" }),
|
|
107
|
+
"gradient-via": f("--un-gradient-via", { syntax: "<color>", initialValue: "#0000" }),
|
|
108
|
+
"gradient-to": f("--un-gradient-to", { syntax: "<color>", initialValue: "#0000" }),
|
|
109
|
+
"gradient-stops": f("--un-gradient-stops"),
|
|
110
|
+
"gradient-via-stops": f("--un-gradient-via-stops"),
|
|
111
|
+
"gradient-from-position": f("--un-gradient-from-position", { syntax: "<length-percentage>", initialValue: "0%" }),
|
|
112
|
+
"gradient-via-position": f("--un-gradient-via-position", { syntax: "<length-percentage>", initialValue: "50%" }),
|
|
113
|
+
"gradient-to-position": f("--un-gradient-to-position", { syntax: "<length-percentage>", initialValue: "100%" })
|
|
114
|
+
};
|
|
115
|
+
function Z() {
|
|
116
|
+
return function* ([, r, o], { theme: e, symbols: n }) {
|
|
117
|
+
const a = {}, { colorData: c, cssVariable: s } = j(o, e);
|
|
118
|
+
if (c) {
|
|
119
|
+
const { color: t, keys: i, alpha: u } = c;
|
|
120
|
+
if (t) {
|
|
121
|
+
if (Object.values(X).includes(t))
|
|
122
|
+
a[`--un-gradient-${r}`] = t;
|
|
123
|
+
else {
|
|
124
|
+
a[`--un-${r}-opacity`] = u;
|
|
125
|
+
const $ = i ? B("colors", i) : t;
|
|
126
|
+
a[`--un-gradient-${r}`] = `color-mix(in oklab, ${$} var(--un-${r}-opacity), transparent)`, yield f(`--un-${r}-opacity`, { syntax: "<percentage>", initialValue: "100%" });
|
|
127
|
+
}
|
|
128
|
+
i && I("colors", i), e && G(t, e);
|
|
129
|
+
}
|
|
130
|
+
} else
|
|
131
|
+
a[`--un-gradient-${r}`] = x.bracket.cssvar(o);
|
|
132
|
+
if (a[`--un-gradient-${r}`]) {
|
|
133
|
+
switch (r) {
|
|
134
|
+
case "from":
|
|
135
|
+
yield {
|
|
136
|
+
...a,
|
|
137
|
+
"--un-gradient-stops": "var(--un-gradient-via-stops, var(--un-gradient-position), var(--un-gradient-from) var(--un-gradient-from-position), var(--un-gradient-to) var(--un-gradient-to-position))"
|
|
138
|
+
};
|
|
139
|
+
break;
|
|
140
|
+
case "via":
|
|
141
|
+
yield {
|
|
142
|
+
...a,
|
|
143
|
+
"--un-gradient-via-stops": "var(--un-gradient-position), var(--un-gradient-from) var(--un-gradient-from-position), var(--un-gradient-via) var(--un-gradient-via-position), var(--un-gradient-to) var(--un-gradient-to-position)",
|
|
144
|
+
"--un-gradient-stops": "var(--un-gradient-via-stops)"
|
|
145
|
+
};
|
|
146
|
+
break;
|
|
147
|
+
case "to":
|
|
148
|
+
yield {
|
|
149
|
+
...a,
|
|
150
|
+
"--un-gradient-stops": "var(--un-gradient-via-stops, var(--un-gradient-position), var(--un-gradient-from) var(--un-gradient-from-position), var(--un-gradient-to) var(--un-gradient-to-position))"
|
|
151
|
+
};
|
|
152
|
+
break;
|
|
153
|
+
case "stops":
|
|
154
|
+
yield { ...a };
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
for (const t of Object.values(Y))
|
|
158
|
+
yield t;
|
|
159
|
+
yield {
|
|
160
|
+
[n.selector]: (t) => t,
|
|
161
|
+
...s
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const T = {
|
|
167
|
+
l: ["-left"],
|
|
168
|
+
r: ["-right"],
|
|
169
|
+
t: ["-top"],
|
|
170
|
+
b: ["-bottom"],
|
|
171
|
+
s: ["-inline-start"],
|
|
172
|
+
e: ["-inline-end"],
|
|
173
|
+
// 'x': ['-left', '-right'],
|
|
174
|
+
// 'y': ['-top', '-bottom'],
|
|
175
|
+
x: ["-inline"],
|
|
176
|
+
y: ["-block"],
|
|
177
|
+
"": [""],
|
|
178
|
+
bs: ["-block-start"],
|
|
179
|
+
be: ["-block-end"],
|
|
180
|
+
is: ["-inline-start"],
|
|
181
|
+
ie: ["-inline-end"],
|
|
182
|
+
block: ["-block-start", "-block-end"],
|
|
183
|
+
inline: ["-inline-start", "-inline-end"]
|
|
184
|
+
};
|
|
185
|
+
function V([, r = "", o], e) {
|
|
186
|
+
if (r in T) {
|
|
187
|
+
const { colorData: n, cssVariable: a } = j(o ?? "", e.theme);
|
|
188
|
+
if (n) {
|
|
189
|
+
const c = T[r].map((s) => oo(s)(n, e)).filter(J);
|
|
190
|
+
return [
|
|
191
|
+
c.map((s) => s[0]).reduce((s, t) => (Object.assign(s, t), s), {}),
|
|
192
|
+
...c.flatMap((s) => s.slice(1)),
|
|
193
|
+
{
|
|
194
|
+
[e.symbols.selector]: (s) => s,
|
|
195
|
+
...a
|
|
196
|
+
}
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function oo(r) {
|
|
202
|
+
return (o, e) => {
|
|
203
|
+
const n = H(o, `border${r}-color`, `border${r}`, e);
|
|
204
|
+
if (n) {
|
|
205
|
+
const a = n[0];
|
|
206
|
+
return o?.color && !Object.values(F).includes(o.color) && !o.alpha && r && r !== "" && (a[`--un-border${r}-opacity`] = "var(--un-border-opacity)"), n;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const ro = {
|
|
211
|
+
"mask-image": "var(--un-mask-linear), var(--un-mask-radial), var(--un-mask-conic)",
|
|
212
|
+
"mask-composite": "intersect"
|
|
213
|
+
}, z = {
|
|
214
|
+
t: ["top"],
|
|
215
|
+
b: ["bottom"],
|
|
216
|
+
l: ["left"],
|
|
217
|
+
r: ["right"],
|
|
218
|
+
x: ["left", "right"],
|
|
219
|
+
y: ["top", "bottom"]
|
|
220
|
+
}, L = "linear-gradient(#fff, #fff)";
|
|
221
|
+
function P([r, o = "", e, n], a) {
|
|
222
|
+
const c = { ...ro }, s = [];
|
|
223
|
+
if (s.push(...["linear", "radial", "conic"].map((t) => f(`--un-mask-${t}`, { initialValue: L }))), o in z) {
|
|
224
|
+
c["--un-mask-linear"] = "var(--un-mask-left), var(--un-mask-right), var(--un-mask-bottom), var(--un-mask-top)";
|
|
225
|
+
for (const t of z[o]) {
|
|
226
|
+
c[`--un-mask-${t}`] = `linear-gradient(to ${t}, var(--un-mask-${t}-from-color) var(--un-mask-${t}-from-position), var(--un-mask-${t}-to-color) var(--un-mask-${t}-to-position))`, R(n) != null ? (I("spacing"), c[`--un-mask-${t}-${e}-position`] = `calc(var(--spacing) * ${x.bracket.cssvar.fraction.number(n)})`) : c[`--un-mask-${t}-${e}-position`] = x.bracket.cssvar.fraction.rem(n);
|
|
227
|
+
const i = p(`--un-mask-${t}-${e}-color`, D("colors"))([r, n], a);
|
|
228
|
+
if (i) {
|
|
229
|
+
const [u, ...$] = i;
|
|
230
|
+
Object.assign(c, u), s.push(...$);
|
|
231
|
+
}
|
|
232
|
+
s.push(...["from", "to"].flatMap((u) => [
|
|
233
|
+
f(`--un-mask-${t}-${u}-position`, { syntax: "<length-percentage>", initialValue: u === "from" ? "0%" : "100%" }),
|
|
234
|
+
f(`--un-mask-${t}-${u}-color`, { syntax: "<color>", initialValue: u === "from" ? "black" : "transparent" })
|
|
235
|
+
]));
|
|
236
|
+
}
|
|
237
|
+
s.push(...["top", "right", "bottom", "left"].map((t) => f(`--un-mask-${t}`, { initialValue: L })));
|
|
238
|
+
} else {
|
|
239
|
+
if (e == null)
|
|
240
|
+
o === "radial" ? (c["--un-mask-radial"] = "radial-gradient(var(--un-mask-radial-stops, var(--un-mask-radial-size)))", c["--un-mask-radial-size"] = x.bracket.cssvar.rem(n)) : (c[`--un-mask-${o}`] = `${o}-gradient(var(--un-mask-${o}-stops, var(--un-mask-${o}-position)))`, c[`--un-mask-${o}-position`] = R(n) ? `calc(1deg * ${x.bracket.cssvar.number(n)})` : x.bracket.cssvar.fraction(n));
|
|
241
|
+
else {
|
|
242
|
+
const t = {
|
|
243
|
+
linear: "",
|
|
244
|
+
radial: "var(--un-mask-radial-shape) var(--un-mask-radial-size) at ",
|
|
245
|
+
conic: "from "
|
|
246
|
+
};
|
|
247
|
+
c[`--un-mask-${o}-stops`] = `${t[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)`, c[`--un-mask-${o}`] = `${o}-gradient(var(--un-mask-${o}-stops))`;
|
|
248
|
+
const i = p(`--un-mask-${o}-${e}-color`, D("colors"))([r, n], a);
|
|
249
|
+
if (i) {
|
|
250
|
+
const [u, ...$] = i;
|
|
251
|
+
Object.assign(c, u), s.push(...$);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
o === "radial" && s.push(f("--un-mask-radial-shape", { initialValue: "ellipse" }), f("--un-mask-radial-size", { initialValue: "farthest-corner" })), s.push(...["from", "to"].flatMap((t) => [
|
|
255
|
+
f(`--un-mask-${o}-position`, { initialValue: o === "radial" ? "center" : "0deg" }),
|
|
256
|
+
f(`--un-mask-${o}-${t}-position`, { syntax: "<length-percentage>", initialValue: t === "from" ? "0%" : "100%" }),
|
|
257
|
+
f(`--un-mask-${o}-${t}-color`, { syntax: "<color>", initialValue: t === "from" ? "black" : "transparent" })
|
|
258
|
+
]));
|
|
259
|
+
}
|
|
260
|
+
return [c, ...s];
|
|
261
|
+
}
|
|
262
|
+
function E(r) {
|
|
263
|
+
return (o, e) => {
|
|
264
|
+
const n = D(r);
|
|
265
|
+
return p(`--un-${n}-color`, n)(o, e);
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const eo = [
|
|
269
|
+
// common style colors
|
|
270
|
+
[/^(?:color|c)-mc-(.+)$/, p("color", "text"), { autocomplete: "(color|c)-mc-$colors" }],
|
|
271
|
+
[/^text-(?:color-)?mc-(.+)$/, p("color", "text"), { autocomplete: "(text|text-color)-mc-$colors" }],
|
|
272
|
+
[/^outline-(?:color-)?mc-(.+)$/, p("outline-color", "outline"), { autocomplete: "(outline|outline-color)-mc-$colors" }],
|
|
273
|
+
[/^accent-mc-(.+)$/, p("accent-color", "accent"), { autocomplete: "accent-mc-$colors" }],
|
|
274
|
+
[/^caret-mc-(.+)$/, p("caret-color", "caret"), { autocomplete: "caret-mc-$colors" }],
|
|
275
|
+
[/^bg-mc-(.+)$/, p("background-color", "bg"), { autocomplete: "bg-mc-$colors" }],
|
|
276
|
+
// from https://github.com/unocss/unocss/blob/main/packages-presets/preset-wind4/src/rules/decoration.ts
|
|
277
|
+
[/^(?:underline|decoration)-mc-(.+)$/, (r, o) => {
|
|
278
|
+
const e = p("text-decoration-color", "line")(r, o);
|
|
279
|
+
if (e) {
|
|
280
|
+
const n = e[0];
|
|
281
|
+
return n["-webkit-text-decoration-color"] = n["text-decoration-color"], e;
|
|
282
|
+
}
|
|
283
|
+
}, { autocomplete: "(underline|decoration)-mc-$colors" }],
|
|
284
|
+
// from https://github.com/unocss/unocss/blob/main/packages-presets/preset-wind4/src/rules/divide.ts
|
|
285
|
+
[/^divide-mc-(.+)$/, function* (r, o) {
|
|
286
|
+
const e = p("border-color", "divide")(r, o);
|
|
287
|
+
e && (yield {
|
|
288
|
+
[o.symbols.variants]: [A(r[0])],
|
|
289
|
+
...e[0]
|
|
290
|
+
}, yield e[1]);
|
|
291
|
+
}, { autocomplete: "divide-mc-$colors" }],
|
|
292
|
+
[/^(?:filter-)?drop-shadow-color-mc-(.+)$/, p("--un-drop-shadow-color", "drop-shadow"), { autocomplete: "divide-mc-$colors" }],
|
|
293
|
+
[/^\$ placeholder-mc-(.+)$/, p("color", "placeholder"), { autocomplete: "placeholder-mc-$colors" }],
|
|
294
|
+
[/^ring-mc-(.+)$/, p("--un-ring-color", "ring"), { autocomplete: "ring-mc-$colors" }],
|
|
295
|
+
[/^inset-ring-mc-(.+)$/, p("--un-inset-ring-color", "inset-ring"), { autocomplete: "inset-ring-mc-$colors" }],
|
|
296
|
+
[/^ring-offset-mc-(.+)$/, p("--un-ring-offset-color", "ring-offset"), { autocomplete: "ring-offset-mc-$colors" }],
|
|
297
|
+
[/^shadow-mc-(.+)$/, E("shadow"), { autocomplete: ["shadow-$colors", "shadow-mc-$shadow"] }],
|
|
298
|
+
[/^inset-shadow-mc(.+)$/, E("insetShadow"), { autocomplete: ["inset-shadow-mc-$colors", "inset-shadow-mc-$insetShadow"] }],
|
|
299
|
+
[/^fill-mc-(.+)$/, p("fill", "fill"), { autocomplete: "fill-mc-$colors" }],
|
|
300
|
+
[/^stroke-mc-(.+)$/, p("stroke", "stroke"), { autocomplete: "stroke-mc-$colors" }],
|
|
301
|
+
[/^text-stroke-mc-(.+)$/, p("-webkit-text-stroke-color", "text-stroke"), { autocomplete: "text-stroke-mc-$colors" }],
|
|
302
|
+
[/^text-shadow-(?:color-)?mc-(.+)$/, p("--un-text-shadow-color", "text-shadow"), { autocomplete: ["text-shadow(-color)?-mc-$colors"] }],
|
|
303
|
+
[/^mask-(linear|radial|conic)-(from|to)-mc-(.+)$/, P, { autocomplete: ["mask-(linear|radial|conic)-(from|to)-mc-$colors"] }],
|
|
304
|
+
[/^mask-([trblxy])-(from|to)-mc-(.+)$/, P, { autocomplete: ["mask-(x|y|t|b|l|r)-(from|to)-mc-$colors"] }],
|
|
305
|
+
// border style colors
|
|
306
|
+
[/^(?:border|b)-()(?:color-)?mc-(.+)$/, V, { autocomplete: ["(border|b)-mc-$colors", "(border|b)-<directions>-mc-$colors"] }],
|
|
307
|
+
[/^(?:border|b)-([xy])-(?:color-)?mc-(.+)$/, V],
|
|
308
|
+
[/^(?:border|b)-([rltbse])-(?:color-)?mc-(.+)$/, V],
|
|
309
|
+
[/^(?:border|b)-(block|inline)-(?:color-)?mc-(.+)$/, V],
|
|
310
|
+
[/^(?:border|b)-([bi][se])-(?:color-)?mc-(.+)$/, V],
|
|
311
|
+
// bg gradient color
|
|
312
|
+
[/^(from|via|to|stops)-mc-(.+)$/, Z()]
|
|
313
|
+
], to = [
|
|
314
|
+
[/^mc-(.+)$/, no]
|
|
315
|
+
];
|
|
316
|
+
function no([, r], { theme: o }) {
|
|
317
|
+
const e = {}, [n, a] = r.split("_");
|
|
318
|
+
if (!a)
|
|
319
|
+
return;
|
|
320
|
+
if (y(n, o)?.color) {
|
|
321
|
+
console.error(`[unocss-preset-margicolor][mc-${r}] The color name '${n}' has been configured in the theme, please use the another name.`);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const [c] = a.split(/[:/]/), s = c.match(/.*-(\d+)/)?.[1], t = c?.split(/-\d+-?/)[0];
|
|
325
|
+
if (!t || !Number.isNaN(Number(t))) {
|
|
326
|
+
console.error(`[unocss-preset-margicolor][mc-${r}] The color '${t}' is invalid.`);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
const i = {};
|
|
330
|
+
let u = !1;
|
|
331
|
+
for (const l of M) {
|
|
332
|
+
const m = y(`${t}-${l}`, o)?.cssColor;
|
|
333
|
+
m ? i[l] = m : u = !0;
|
|
334
|
+
}
|
|
335
|
+
if (u)
|
|
336
|
+
try {
|
|
337
|
+
const l = y(t, o)?.color, m = l ? K(l) : void 0;
|
|
338
|
+
if (m && N.valid(m)) {
|
|
339
|
+
const b = N.theme(m);
|
|
340
|
+
for (const d of M)
|
|
341
|
+
if (!i[d]) {
|
|
342
|
+
const g = C({ type: "hex", components: [b[d]], alpha: 1 });
|
|
343
|
+
i[d] = g;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} catch (l) {
|
|
347
|
+
console.error(`[unocss-preset-margicolor] Error parsing ${r}: get ${t} theme fail, please use another color.`), console.error(l);
|
|
348
|
+
}
|
|
349
|
+
for (const l of M)
|
|
350
|
+
i[l] = C(i[l]);
|
|
351
|
+
const $ = y(c, o);
|
|
352
|
+
if ($?.color)
|
|
353
|
+
e[`--mc-${n}-color`] = $.color;
|
|
354
|
+
else if (s) {
|
|
355
|
+
const { originDepth: l, beforeDepth: m, afterDepth: b } = O(s);
|
|
356
|
+
if (i[m] && i[b]) {
|
|
357
|
+
const d = (l - m) / 100, g = Array.from({ length: 3 }).map((k, v) => {
|
|
358
|
+
const w = i[m].components, S = i[b].components, _ = h(w[v]) + (h(S[v]) - h(w[v])) * d;
|
|
359
|
+
return `${Math.round(_ * 1e3) / 1e3}`;
|
|
360
|
+
});
|
|
361
|
+
e[`--mc-${n}-color`] = `oklch(${g.join(" ")})`;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
for (const l of M)
|
|
365
|
+
if (i[l]) {
|
|
366
|
+
const m = i[l].components;
|
|
367
|
+
e[`--mc-${n}-${l}-l`] = Math.round(h(m[0]) * 1e3) / 1e3, e[`--mc-${n}-${l}-c`] = Math.round(h(m[1]) * 1e3) / 1e3, e[`--mc-${n}-${l}-h`] = Math.round(h(m[2]) * 1e3) / 1e3;
|
|
368
|
+
}
|
|
369
|
+
return e;
|
|
370
|
+
}
|
|
371
|
+
const ao = [
|
|
372
|
+
eo,
|
|
373
|
+
to
|
|
374
|
+
].flat();
|
|
375
|
+
function uo(r) {
|
|
376
|
+
return {
|
|
377
|
+
name: "unocss-preset-magicolor",
|
|
378
|
+
layer: "unocss-preset-magicolor",
|
|
379
|
+
layers: { "unocss-preset-magicolor": -100 },
|
|
380
|
+
rules: ao
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
export {
|
|
384
|
+
uo as default,
|
|
385
|
+
uo as presetMagicolor
|
|
386
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function updateMagicColor(): void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Theme } from '@unocss/preset-wind4';
|
|
2
|
+
import { CSSObject, RuleContext } from 'unocss';
|
|
3
|
+
export declare function handleImage([_, gradient, direction, val]: string[], ctx: RuleContext<Theme>): (string | CSSObject | Partial<import('unocss').ControlSymbolsValue> | import('unocss').CSSEntriesInput)[];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Theme } from '@unocss/preset-wind4';
|
|
2
|
+
import { CSSObject, CSSValueInput, RuleContext } from 'unocss';
|
|
3
|
+
export declare function handleShadow(themeKey: 'shadow' | 'insetShadow'): (match: RegExpMatchArray, ctx: RuleContext<Theme>) => CSSObject | (CSSValueInput | string)[] | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Theme } from '@unocss/preset-wind4';
|
|
2
|
+
import { CSSObject, CSSValueInput, RuleContext } from 'unocss';
|
|
3
|
+
import { ThemeKey } from '../typing';
|
|
4
|
+
export declare const themeMetaList: ThemeKey[];
|
|
5
|
+
export declare function resolveDepth(no: string): {
|
|
6
|
+
originDepth: number;
|
|
7
|
+
beforeDepth: number;
|
|
8
|
+
afterDepth: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function parseMagicColor(body: string, theme: Theme): {
|
|
11
|
+
colorData: {
|
|
12
|
+
opacity: string | undefined;
|
|
13
|
+
modifier: string | undefined;
|
|
14
|
+
name: string;
|
|
15
|
+
no: string | undefined;
|
|
16
|
+
color: string;
|
|
17
|
+
alpha: string | undefined;
|
|
18
|
+
keys: string[] | undefined;
|
|
19
|
+
readonly cssColor: import('@unocss/preset-wind4/utils').CSSColorValue | undefined;
|
|
20
|
+
} | undefined;
|
|
21
|
+
cssVariable: CSSObject;
|
|
22
|
+
};
|
|
23
|
+
export declare function mcColorResolver(property: string, varName: string): ([, body]: string[], ctx: RuleContext<Theme>) => (CSSValueInput | string)[] | undefined;
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "unocss-preset-magicolor",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Unocss预设",
|
|
6
|
+
"author": "nxy",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/nixwai/unocss-preset-magicolor"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/types/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./helper": {
|
|
18
|
+
"types": "./dist/types/helper.d.ts",
|
|
19
|
+
"import": "./dist/helper.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"module": "dist/index.js",
|
|
24
|
+
"types": "dist/types/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@unocss/preset-wind4": "66.5.4",
|
|
30
|
+
"culori": "^4.0.2",
|
|
31
|
+
"magic-color": "^2.1.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/culori": "^4.0.1",
|
|
35
|
+
"unocss": "^66.5.4"
|
|
36
|
+
}
|
|
37
|
+
}
|