-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuno.config.ts
116 lines (100 loc) · 2.75 KB
/
uno.config.ts
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import {
defineConfig,
presetIcons,
presetUno,
transformerDirectives,
transformerVariantGroup
} from "unocss"
import { rgb } from "culori"
import { createRgbaVar, cssVar, shadcnVariables } from "./src/lib/utils"
import { mocha } from "./src/lib/presets"
const baseAsRGBA = Object.entries(mocha.colors).map(([key, value]) => {
const { r, g, b } = rgb(value)!
return [key, [r, g, b].map((i) => i * 255).join(",")] as const
})
export default defineConfig({
presets: [presetUno({ dark: "class" }), presetIcons()],
shortcuts: [],
transformers: [transformerDirectives(), transformerVariantGroup()],
theme: {
screens: {
"2xl": "1400px"
}
},
extendTheme: (theme) => ({
...theme,
fontWeight: {
normal: 400,
medium: 500,
bold: 800
},
fontFamily: {
// @ts-expect-error
...theme.fontFamily,
sans: "'M PLUS Rounded 1c', sans-serif",
// @ts-expect-error
mono: `var(--font-mono,${theme.fontFamily.mono} )`
},
colors: {
...createBaseClasses(),
...createShadcnClasses(),
activeColor: createRgbaVar("active-color"),
activeColorForeground: createRgbaVar("active-colorForeground"),
transparent: "transparent"
}
}),
preflights: [{ getCSS: createGlobalVariables, layer: "base" }],
content: {
pipeline: {
include: [
// the default
/\.(svelte|[jt]sx|mdx?|html)($|\?)/,
// include js/ts files
"(components|src)/**/*.{js,ts}"
]
}
}
})
function createGlobalVariables() {
// const base = baseAsRGBA.map(([key, value]) => `--${key}: ${value};`)
const neutrals = {
background: cssVar("base"),
popover: cssVar("base"),
card: cssVar("base"),
"muted-foreground": cssVar("overlay2"),
"card-foreground": cssVar("text"),
foreground: cssVar("text"),
"popover-foreground": cssVar("text"),
primary: cssVar("text"),
"secondary-foreground": cssVar("text"),
"accent-foreground": cssVar("text"),
"destructive-foreground": cssVar("text"),
border: cssVar("surface1"),
input: cssVar("surface2"),
accent: cssVar("surface1"),
muted: cssVar("surface0"),
secondary: cssVar("surface0"),
"primary-foreground": cssVar("mantle"),
destructive: cssVar("red"),
ring: cssVar("subtext1")
} satisfies Record<(typeof shadcnVariables)[number], string>
const root: string[] = []
for (const element of Object.entries(neutrals)) {
const [key, value] = element
root.push(`--${key}: ${value};`)
}
return `@layer base {
:root { ${root.join("\n")} }
}`
}
function createBaseClasses() {
const vars = baseAsRGBA
.map(([key]) => ({ [key]: `rgba(var(--${key}))` }))
.reduce((acc, curr) => ({ ...acc, ...curr }), {})
return vars
}
function createShadcnClasses() {
return shadcnVariables
.map((variable) => ({ [variable]: createRgbaVar(variable) }))
.reduce((acc, curr) => ({ ...acc, ...curr }), {})
}