-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathuno.config.ts
209 lines (192 loc) · 6.92 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import type { Preset, UserConfig, UserShortcuts, VariantObject } from '@unocss/core'
import type { Theme } from '@unocss/preset-uno'
import { objectKeys, objectPick } from '@antfu/utils'
import { presetAttributify } from '@unocss/preset-attributify'
import { presetIcons } from '@unocss/preset-icons'
import { presetUno } from '@unocss/preset-uno'
import { parseCssColor, variantGetParameter } from '@unocss/rule-utils'
import transformerDirectives from '@unocss/transformer-directives'
import transformerVariantGroup from '@unocss/transformer-variant-group'
import { resolve } from 'node:path'
import * as svgo from 'svgo'
import unocssPresetAnimations from 'unocss-preset-animations'
import { FileSystemIconLoader } from 'unplugin-icons/loaders'
export const SVGO_CONFIG = {
plugins: [{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
minifyStyles: false,
},
},
},
],
} satisfies svgo.Config
export const BREAKPOINTS = {
'sm': '640px',
'md': '768px',
'lg': '1024px',
'xl': '1280px',
'2xl': '1536px',
} satisfies Theme['breakpoints']
export const COLORS = {
light: {
default: ['#ffffff', '#09090b'],
card: ['#f7f7f7', '#09090b'],
popover: ['#f9f9f9', '#09090b'],
primary: ['#990000', '#ffffff'],
secondary: ['#f4f4f5', '#18181b'],
muted: ['#f4f4f5', '#71717a'],
accent: ['#60a5fa', '#18181b'],
destructive: ['#ef4444', '#fafafa'],
border: '#e4e4e7',
input: '#e4e4e7',
ring: '#60a5fa',
},
dark: {
default: ['#09090b', '#eeeeee'],
card: ['#09090b', '#eeeeee'],
popover: ['#09090b', '#eeeeee'],
primary: ['#990000', '#eeeeee'],
secondary: ['#27272a', '#eeeeee'],
muted: ['#27272a', '#a1a1aa'],
accent: ['#2f517a', '#eeeeee'],
destructive: ['#7f1d1d', '#eeeeee'],
border: '#27272a',
input: '#27272a',
ring: '#990000',
},
} as const
export const ICON_COLLECTIONS = {
ao3e: FileSystemIconLoader(resolve(__dirname, './src/icons')),
}
export const ICON_TRANSFORM = (svg: string) => svgo.optimize(svg, SVGO_CONFIG).data
const THEME_COLOR: Record<string, string> = {}
const COLOR_SHORTCUTS: [string, string][] = []
const COLOR_CSS: Record<keyof typeof COLORS, string[]> = { light: [], dark: [] }
function addColor(name: string, value: { light: string, dark: string }) {
THEME_COLOR[name] = `rgb(var(--color-${name}) / %alpha)`
for (const type of objectKeys(COLOR_CSS)) {
const [r, g, b] = parseCssColor(value[type])!.components
COLOR_CSS[type].push(`--color-${name}: ${r} ${g} ${b};\n`)
}
}
for (const name of objectKeys(COLORS.light)) {
if (Array.isArray(COLORS.light[name])) {
addColor(name, { light: COLORS.light[name][0], dark: COLORS.dark[name][0] })
addColor(`${name}-fg`, { light: COLORS.light[name][1], dark: COLORS.dark[name][1] })
COLOR_SHORTCUTS.push([name, `bg-${name} text-${name}-fg`])
COLOR_SHORTCUTS.push([`on-${name}`, `bg-${name}-fg text-${name}`])
}
else {
addColor(name, { light: COLORS.light[name] as string, dark: COLORS.dark[name] as string })
}
}
const THEME = {
breakpoints: BREAKPOINTS,
container: {
center: false,
padding: '0',
maxWidth: objectPick(BREAKPOINTS, ['sm', 'md']),
},
colors: THEME_COLOR,
fontFamily: {
sans: '"Lucida Grande", "Lucida Sans Unicode", "GNU Unifont", Verdana, Helvetica, sans-serif',
serif: 'ui-serif, Georgia, Cambria, "Times New Roman", Times, serif',
},
animation: {
keyframes: {
'collapsible-down': '{from {height:0} to {height:var(--radix-collapsible-content-height)}}',
'collapsible-up': '{from {height:var(--radix-collapsible-content-height)} to {height:0}}',
},
},
} satisfies Theme
const STATE_VARIANT: VariantObject = {
name: 'state',
match(matcher, ctx) {
const variant = variantGetParameter('state-', matcher, ctx.generator.config.separators)
if (variant) {
const [match, rest] = variant
return {
matcher: rest,
selector: s => `${s}[data-state="${match}"]`,
}
}
},
}
const ANIMATION_SHORTCUTS: UserShortcuts<Theme> = [
['animate-tooltip', [
...s('animate-name-una-in animate-duration-100ms animate-ease-in fade-in-0 will-change-opacity '),
]],
['animate-collapsible', [
...s('will-change-height transition-height animate-duration-300ms'),
...vg('state-open', 'animate-name-collapsible-down animate-ease-out'),
...vg('state-closed', 'animate-name-collapsible-up animate-ease-in'),
]],
['animate-overlay', [
...s('animate-duration-200ms will-change-opacity'),
...vg('state-open', 'animate-name-una-in animate-ease-in fade-in-0'),
...vg('state-closed', 'animate-name-una-out animate-ease-out fade-out-0'),
]],
['animate-dialog', [
...s('animate-duration-200ms will-change-opacity will-change-transform'),
...vg('state-open', 'animate-name-una-in animate-ease-in fade-in-0 zoom-in-95 slide-in-from-left-1/2 slide-in-from-top-48%'),
...vg('state-closed', 'animate-name-una-out animate-ease-out fade-out-0 zoom-out-95 slide-out-to-left-1/2 slide-out-to-top-48%'),
]],
['animate-popover', [
...s('animate-name-una-in animate-duration-200ms animate-ease-in fade-in-0 zoom-in-95 will-change-opacity will-change-transform'),
...vg('state-closed', 'animate-name-una-out fade-out-0 zoom-out-95'),
'data-[side=bottom]:slide-in-from-top-2',
'data-[side=left]:slide-in-from-right-2',
'data-[side=right]:slide-in-from-left-2',
'data-[side=top]:slide-in-from-bottom-2',
]],
]
const OTHER_SHORTCUTS: UserShortcuts<Theme> = {
'input-ring-visible': 'ring-ring/50 ring-3',
'input-ring': 'outline-none focus-visible:input-ring-visible',
'btn': 'input-ring flex-inline items-center justify-center hover:bg-input cursor-pointer rounded-md',
'link': 'input-ring color-inherit underline underline-accent hover:no-underline',
}
function presetAnimations(): Preset {
const { shortcuts: _, ...rest } = unocssPresetAnimations()
return rest
}
export default {
shortcuts: [
...COLOR_SHORTCUTS,
...ANIMATION_SHORTCUTS,
OTHER_SHORTCUTS,
],
safelist: ['keyframes-una-in', 'keyframes-una-out', 'keyframes-collapsible-down', 'keyframes-collapsible-up', 'sr-only'],
presets: [
presetUno(),
presetAttributify({ strict: false }),
presetAnimations(),
presetIcons({
prefix: 'i-',
collections: ICON_COLLECTIONS,
customizations: { transform: ICON_TRANSFORM },
extraProperties: {
'display': 'inline-block',
'vertical-align': 'middle',
},
}),
],
transformers: [
transformerDirectives(),
transformerVariantGroup({ separators: [':'] }),
],
theme: THEME,
preflights: [
{ getCSS: () => Object.entries(COLOR_CSS).map(([type, colors]) => `.${type} {${colors.join('')} }`).join('\n') },
],
variants: [STATE_VARIANT],
} satisfies UserConfig
function s(utilities: string): string[] {
return utilities.split(' ')
}
function vg(variant: string, utilities: string): string[] {
return s(utilities).map(utility => `${variant}:${utility}`)
}