-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuno.config.js
89 lines (80 loc) · 2.38 KB
/
uno.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {
defineConfig,
extractorSvelte,
transformerDirectives,
transformerVariantGroup
} from "unocss";
import { presetForms } from "@julr/unocss-preset-forms";
import { presetWebFonts } from "unocss/preset-web-fonts";
import { colors, presetWind } from "unocss/preset-wind";
import { presetIcons } from "unocss/preset-icons";
// to get the palette keys
const palette = {};
Object.keys(colors["blue"]).forEach((key) => {
palette[key] = `rgb(var(--primary-${key}))`;
});
const hexToRgb = (hex) => {
return hex
.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => "#" + r + r + g + g + b + b)
.substring(1)
.match(/.{2}/g)
.map((x) => parseInt(x, 16))
.join(", ");
};
export default defineConfig({
transformers: [transformerDirectives(), transformerVariantGroup()],
extractors: [extractorSvelte],
presets: [
presetWind(),
presetIcons({
extraProperties: {
display: "inline-block",
"vertical-align": "middle"
}
}),
presetForms()
],
theme: {
colors: {
primary: palette
}
},
safelist: ["bg-blue-500", "bg-red-500", "bg-cyan-500", "bg-gray-500", "bg-pink-500", "bg-purple-500", "bg-indigo-500"],
shortcuts: [[/^hw-(.*)$/, ([, c]) => `h-${c} w-${c}`],
{
"badge": "inline-block items-center text-sm bg-gray-200 dark:bg-gray-700 px-2 rounded-lg font-medium cursor-pointer select-none truncate"
},
[
/^badge-(.*)$/,
([, c]) => {
return `text-${c}-600 bg-${c}-100 dark:text-white dark:bg-${c}-600`;
},
]
],
preflights: [
{
getCSS: ({ theme }) => {
const css = [];
const colors = theme.colors;
const paletteConfig = {
":root": "blue",
'[data-palette="red"]': "red",
'[data-palette="cyan"]': "cyan",
'[data-palette="gray"]': "gray",
'[data-palette="pink"]': "pink",
'[data-palette="purple"]': "purple",
'[data-palette="indigo"]': "indigo",
};
Object.keys(paletteConfig).forEach((themeKey) => {
const themes = [];
const value = paletteConfig[themeKey];
Object.keys(colors[value]).forEach((colorKey) => {
themes.push(`--primary-${colorKey}: ${hexToRgb(colors[value][colorKey])};`);
});
css.push(`\n${themeKey} {\n${themes.join("")}}`);
});
return css.join("");
}
}
]
});