-
Notifications
You must be signed in to change notification settings - Fork 0
/
uno.config.js
182 lines (171 loc) · 3.87 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
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
import { defineConfig, presetMini } from "unocss"
import extractorSvelte from "@unocss/extractor-svelte"
import { breakpoint, space, color } from "./src/css/tokens.json"
const rules = [
[
/^grid-(.*)-?(.*)?$/,
([, c]) => {
const [cols, gap] = c.split("-")
return {
display: "grid",
"grid-template-columns": `repeat(${cols || 12}, 1fr)`,
"grid-gap": `var(--space-${gap || "gap"})`,
}
},
],
[
/^gradient-(.*)$/,
([, c]) => {
return {
background: `var(--gradient-linear-${c || "90"})`,
}
},
],
[
/^col-(.*)$/,
([, c]) => {
return {
"grid-column": c.replace(/\[|\]|\-/g, " "),
}
},
],
[
/^row-(.*)$/,
([, c]) => {
return {
"grid-row": c.replace(/\[|\]|\-/g, " "),
}
},
],
[
/^gap-?(.*)?$/,
([, c]) => {
return {
gap: `var(--space-${c || "gap"})`,
}
},
],
[
/^(p|m)-(.*)?-?(.*)?-?(.*)?-?(.*)?$/,
(match) => {
let [, PaddingOrMargin, t, r, b, l] = match
const isPadding = PaddingOrMargin === "m" ? false : true
const List = []
for (const e of [t, r, b, l].filter(Boolean)) {
if (!e || e === "auto") {
List.push("auto")
} else List.push(`var(--space-${e})`)
}
return isPadding
? { padding: List.join(" ") }
: { margin: List.join(" ") }
},
{ autocomplete: "p|m-<var>-<var>-<var>-<var>" },
],
[
/^(p|m)(t|r|b|l)-(.*)$/,
(match) => {
let [, PaddingOrMargin, dir, val] = match
const positions = {
t: "top",
r: "right",
b: "bottom",
l: "left",
}
let pos = positions[dir]
const isPadding = PaddingOrMargin === "m" ? false : true
return isPadding
? { [`padding-${pos}`]: `var(--space-${val})` }
: { [`margin-${pos}`]: `var(--space-${val})` }
},
{ autocomplete: "p|m(t|r|b|l)-<var>" },
],
[
/^ratio-(.*)$/,
([, c]) => ({
"aspect-ratio": c.replace(/\[|\]|\-/g, " "),
}),
],
[
/^(px|py|mx|my)-(.*)-?(.*)?$/,
(match) => {
const [, direction, s, optional] = match
const combination = {
px: "padding-inline",
py: "padding-block",
mx: "margin-inline",
my: "margin-block",
}
const returndirection = combination[direction]
let value = `var(--space-${s})`
value += optional ? ` var(--space-${optional})` : ""
return { [returndirection]: value }
},
{ autocomplete: "px|py|mx|my-<var>-<var>" },
],
[
/^flex-(row|col|start|center|end|btw)-?(start|center|end|btw|stretch)?-?(start|center|end|btw|stretch)?$/,
(match) => {
const [, directionOrJustify, justifyOrAlign, align] = match
let directionValue = directionOrJustify
let justifyValue = justifyOrAlign
let alignValue = align
if (directionOrJustify !== "row" && directionOrJustify !== "col") {
directionValue = "row"
justifyValue = directionOrJustify
alignValue = justifyOrAlign
}
const columORrow = directionValue === "row" ? "row" : "column"
const values = {
start: "flex-start",
center: "center",
end: "flex-end",
btw: "space-between",
stretch: "stretch",
}
return {
display: "flex",
"flex-direction": columORrow,
"justify-content": values[justifyValue],
"align-items": values[alignValue],
}
},
{ autocomplete: "flex-(row|col|start|center|end|btw)" },
],
[
/^scrollbar-hide$/,
([_]) => {
return `.scrollbar-hide::-webkit-scrollbar{display:none} .scrollbar-hide{scrollbar-width:0px}`
},
],
[
/^scrollbar-default$/,
([_]) => {
return `.scrollbar-default::-webkit-scrollbar{display:block} .scrollbar-default{scrollbar-width:auto}`
},
],
]
export default defineConfig({
theme: {
colors: color,
breakpoints: breakpoint,
},
rules: rules,
presets: [
presetMini({
dark: false,
arbitraryVariants: false,
preflight: false,
}),
],
shortcuts: [
{
grid: "grid-12-gap",
},
],
extractors: [extractorSvelte()],
safelist: [
...Array.from({ length: 12 }, (_, i) => `grid-${i + 1}`),
...Object.keys(space).map((e) => `pb-${e}`),
],
})