-
Notifications
You must be signed in to change notification settings - Fork 0
/
unocss.config.ts
123 lines (122 loc) · 2.83 KB
/
unocss.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
import { defineConfig } from '@unocss/vite'
import { presetMini } from '@unocss/preset-mini'
import transformerVariantGroup from '@unocss/transformer-variant-group'
import presetIcons from '@unocss/preset-icons'
export default defineConfig({
shortcuts: [
{
ellipsis: 'text-ellipsis overflow-hidden [white-space:nowrap]',
},
],
presets: [
presetMini(),
presetIcons({
collections: {
'ant-design': async () => await import('@iconify-json/ant-design').then(i => i.icons),
},
extraProperties: {
display: 'inline-block',
'vertical-align': '-0.125em',
},
}) as any,
],
transformers: [transformerVariantGroup()],
variants: [
/**
* not[.*]:
*/
matcher => {
const prevReg = /^not\[(.*)\]:/
const match = matcher.match(prevReg)
if (!match) return matcher
return {
matcher: matcher.slice(match[0].length),
selector: s => `${s}:not(${match[1]})`,
}
},
/**
* where:
*/
matcher => {
const prev = 'where:'
if (!matcher.startsWith(prev)) {
return matcher
}
return {
matcher: matcher.slice(prev.length),
selector: s => `:where(${s})`,
}
},
/**
* 定义子级的样式
* child[.*]>?:
*/
matcher => {
const prevReg = /^child\[(.*)\](>?):/
const match = matcher.match(prevReg)
if (!match) return matcher
return {
matcher: matcher.slice(match[0].length),
selector: s => `${s}${match[2] ? '>' : ' '}${match[1] || '*'}`,
}
},
/**
* 父级 hover 的状态定义子级的样式
* p:hover-child[.*]:
*/
matcher => {
const prevReg = /^p:hover-child\[(.*)\]:/
const match = matcher.match(prevReg)
if (!match) return matcher
return {
matcher: matcher.slice(match[0].length),
selector: s => `${s}:hover ${match[1] || '*'}`,
}
},
/**
* 有父级 class 的时候才会生效
* p[.*]:
*/
matcher => {
const prevReg = /^p\[(.*)\]:/
const match = matcher.match(prevReg)
if (!match) return matcher
return {
matcher: matcher.slice(match[0].length),
selector: s => `${match[1] || '*'} ${s}`,
}
},
],
rules: [
[
/^keyframes-spin$/,
() => {
return `@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}`
},
],
[
/^keyframes-wave$/,
() => {
return `@keyframes wave {
from {
border-width: 0px;
inset: 0px;
opacity: 0.4;
}
to {
border-width: 6px;
inset: -6px;
opacity: 0.1;
}
}`
},
],
],
})