-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathconfig.d.ts
325 lines (303 loc) · 10.7 KB
/
config.d.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
import type { CorePluginList } from './generated/corePluginList'
import type { DefaultColors } from './generated/colors'
// Helpers
type Expand<T> = T extends object
? T extends infer O
? { [K in keyof O]: Expand<O[K]> }
: never
: T
type KeyValuePair<K extends keyof any = string, V = string> = Record<K, V>
interface RecursiveKeyValuePair<K extends keyof any = string, V = string> {
[key: string]: V | RecursiveKeyValuePair<K, V>
}
type ResolvableTo<T> = T | ((utils: PluginUtils) => T)
interface PluginUtils {
colors: DefaultColors
theme(path: string, defaultValue?: unknown): any
breakpoints<I = Record<string, unknown>, O = I>(arg: I): O
rgb(arg: string): (arg: Partial<{ opacityVariable: string; opacityValue: number }>) => string
hsl(arg: string): (arg: Partial<{ opacityVariable: string; opacityValue: number }>) => string
}
// Content related config
type FilePath = string
type RawFile = { raw: string; extension?: string }
type ExtractorFn = (content: string) => string[]
type TransformerFn = (content: string) => string
type ContentConfig =
| (FilePath | RawFile)[]
| {
files: (FilePath | RawFile)[]
extract?: ExtractorFn | { [extension: string]: ExtractorFn }
transform?: TransformerFn | { [extension: string]: TransformerFn }
}
// Important related config
type ImportantConfig = boolean | string
// Prefix related config
type PrefixConfig = string
// Separator related config
type SeparatorConfig = string
// Safelist related config
type SafelistConfig =
| string[]
| {
pattern: RegExp
variants: string[]
}[]
// Presets related config
type PresetsConfig = Config[]
// Future related config
type FutureConfigValues = never // Replace with 'future-feature-1' | 'future-feature-2'
type FutureConfig = Expand<'all' | Partial<Record<FutureConfigValues, boolean>>> | []
// Experimental related config
type ExperimentalConfigValues = 'optimizeUniversalDefaults' // Replace with 'experimental-feature-1' | 'experimental-feature-2'
type ExperimentalConfig = Expand<'all' | Partial<Record<ExperimentalConfigValues, boolean>>> | []
// DarkMode related config
type DarkModeConfig =
// Use the `media` query strategy.
| 'media'
// Use the `class` stategy, which requires a `.dark` class on the `html`.
| 'class'
// Use the `class` stategy with a custom class instead of `.dark`.
| ['class', string]
type Screen = { raw: string } | { min: string } | { max: string } | { min: string; max: string }
type ScreensConfig = string[] | KeyValuePair<string, string | Screen | Screen[]>
// Theme related config
interface ThemeConfig {
// Responsiveness
screens: ResolvableTo<ScreensConfig>
// Reusable base configs
colors: ResolvableTo<RecursiveKeyValuePair>
spacing: ResolvableTo<KeyValuePair>
// Components
container: ResolvableTo<
Partial<{
screens: ScreensConfig
center: boolean
padding: string | Record<string, string>
}>
>
// Utilities
inset: ThemeConfig['spacing']
zIndex: ResolvableTo<KeyValuePair>
order: ResolvableTo<KeyValuePair>
gridColumn: ResolvableTo<KeyValuePair>
gridColumnStart: ResolvableTo<KeyValuePair>
gridColumnEnd: ResolvableTo<KeyValuePair>
gridRow: ResolvableTo<KeyValuePair>
gridRowStart: ResolvableTo<KeyValuePair>
gridRowEnd: ResolvableTo<KeyValuePair>
margin: ThemeConfig['spacing']
aspectRatio: ResolvableTo<KeyValuePair>
height: ThemeConfig['spacing']
maxHeight: ThemeConfig['spacing']
minHeight: ResolvableTo<KeyValuePair>
width: ThemeConfig['spacing']
maxWidth: ResolvableTo<KeyValuePair>
minWidth: ResolvableTo<KeyValuePair>
flex: ResolvableTo<KeyValuePair>
flexShrink: ResolvableTo<KeyValuePair>
flexGrow: ResolvableTo<KeyValuePair>
flexBasis: ThemeConfig['spacing']
borderSpacing: ThemeConfig['spacing']
transformOrigin: ResolvableTo<KeyValuePair>
translate: ThemeConfig['spacing']
rotate: ResolvableTo<KeyValuePair>
skew: ResolvableTo<KeyValuePair>
scale: ResolvableTo<KeyValuePair>
animation: ResolvableTo<KeyValuePair>
keyframes: ResolvableTo<KeyValuePair<string, KeyValuePair<string, KeyValuePair>>>
cursor: ResolvableTo<KeyValuePair>
scrollMargin: ThemeConfig['spacing']
scrollPadding: ThemeConfig['spacing']
listStyleType: ResolvableTo<KeyValuePair>
columns: ResolvableTo<KeyValuePair>
gridAutoColumns: ResolvableTo<KeyValuePair>
gridAutoRows: ResolvableTo<KeyValuePair>
gridTemplateColumns: ResolvableTo<KeyValuePair>
gridTemplateRows: ResolvableTo<KeyValuePair>
gap: ThemeConfig['spacing']
space: ThemeConfig['spacing']
divideWidth: ThemeConfig['borderWidth']
divideColor: ThemeConfig['borderColor']
divideOpacity: ThemeConfig['borderOpacity']
borderRadius: ResolvableTo<KeyValuePair>
borderWidth: ResolvableTo<KeyValuePair>
borderColor: ThemeConfig['colors']
borderOpacity: ThemeConfig['opacity']
backgroundColor: ThemeConfig['colors']
backgroundOpacity: ThemeConfig['opacity']
backgroundImage: ResolvableTo<KeyValuePair>
gradientColorStops: ThemeConfig['colors']
backgroundSize: ResolvableTo<KeyValuePair>
backgroundPosition: ResolvableTo<KeyValuePair>
fill: ThemeConfig['colors']
stroke: ThemeConfig['colors']
strokeWidth: ResolvableTo<KeyValuePair>
objectPosition: ResolvableTo<KeyValuePair>
padding: ThemeConfig['spacing']
textIndent: ThemeConfig['spacing']
fontFamily: ResolvableTo<KeyValuePair<string, string[]>>
fontSize: ResolvableTo<
KeyValuePair<
string,
| string
| [fontSize: string, lineHeight: string]
| [
fontSize: string,
configuration: Partial<{
lineHeight: string
letterSpacing: string
}>
]
>
>
fontWeight: ResolvableTo<KeyValuePair>
lineHeight: ResolvableTo<KeyValuePair>
letterSpacing: ResolvableTo<KeyValuePair>
textColor: ThemeConfig['colors']
textOpacity: ThemeConfig['opacity']
textDecorationColor: ThemeConfig['colors']
textDecorationThickness: ResolvableTo<KeyValuePair>
textUnderlineOffset: ResolvableTo<KeyValuePair>
placeholderColor: ThemeConfig['colors']
placeholderOpacity: ThemeConfig['opacity']
caretColor: ThemeConfig['colors']
accentColor: ThemeConfig['colors']
opacity: ResolvableTo<KeyValuePair>
boxShadow: ResolvableTo<KeyValuePair>
boxShadowColor: ThemeConfig['colors']
outlineWidth: ResolvableTo<KeyValuePair>
outlineOffset: ResolvableTo<KeyValuePair>
outlineColor: ThemeConfig['colors']
ringWidth: ResolvableTo<KeyValuePair>
ringColor: ThemeConfig['colors']
ringOpacity: ThemeConfig['opacity']
ringOffsetWidth: ResolvableTo<KeyValuePair>
ringOffsetColor: ThemeConfig['colors']
blur: ResolvableTo<KeyValuePair>
brightness: ResolvableTo<KeyValuePair>
contrast: ResolvableTo<KeyValuePair>
dropShadow: ResolvableTo<KeyValuePair>
grayscale: ResolvableTo<KeyValuePair>
hueRotate: ResolvableTo<KeyValuePair>
invert: ResolvableTo<KeyValuePair>
saturate: ResolvableTo<KeyValuePair>
sepia: ResolvableTo<KeyValuePair>
backdropBlur: ThemeConfig['blur']
backdropBrightness: ThemeConfig['brightness']
backdropContrast: ThemeConfig['contrast']
backdropGrayscale: ThemeConfig['grayscale']
backdropHueRotate: ThemeConfig['hueRotate']
backdropInvert: ThemeConfig['invert']
backdropOpacity: ThemeConfig['opacity']
backdropSaturate: ThemeConfig['saturate']
backdropSepia: ThemeConfig['sepia']
transitionProperty: ResolvableTo<KeyValuePair>
transitionTimingFunction: ResolvableTo<KeyValuePair>
transitionDelay: ResolvableTo<KeyValuePair>
transitionDuration: ResolvableTo<KeyValuePair>
willChange: ResolvableTo<KeyValuePair>
content: ResolvableTo<KeyValuePair>
// Custom
[key: string]: any
}
// Core plugins related config
type CorePluginsConfig = CorePluginList[] | Expand<Partial<Record<CorePluginList, boolean>>>
// Plugins related config
type ValueType =
| 'any'
| 'color'
| 'url'
| 'image'
| 'length'
| 'percentage'
| 'position'
| 'lookup'
| 'generic-name'
| 'family-name'
| 'number'
| 'line-width'
| 'absolute-size'
| 'relative-size'
| 'shadow'
export interface PluginAPI {
// for registering new static utility styles
addUtilities(
utilities: RecursiveKeyValuePair | RecursiveKeyValuePair[],
options?: Partial<{
respectPrefix: boolean
respectImportant: boolean
}>
): void
// for registering new dynamic utility styles
matchUtilities<T>(
utilities: KeyValuePair<string, (value: T) => RecursiveKeyValuePair>,
options?: Partial<{
respectPrefix: boolean
respectImportant: boolean
type: ValueType | ValueType[]
values: KeyValuePair<string, T>
supportsNegativeValues: boolean
}>
): void
// for registering new static component styles
addComponents(
components: RecursiveKeyValuePair | RecursiveKeyValuePair[],
options?: Partial<{
respectPrefix: boolean
respectImportant: boolean
}>
): void
// for registering new dynamic component styles
matchComponents<T>(
components: KeyValuePair<string, (value: T) => RecursiveKeyValuePair>,
options?: Partial<{
respectPrefix: boolean
respectImportant: boolean
type: ValueType | ValueType[]
values: KeyValuePair<string, T>
supportsNegativeValues: boolean
}>
): void
// for registering new base styles
addBase(base: RecursiveKeyValuePair | RecursiveKeyValuePair[]): void
// for registering custom variants
addVariant(name: string, definition: string | string[] | (() => string) | (() => string)[]): void
// for looking up values in the user’s theme configuration
theme: <TDefaultValue = Config['theme']>(
path?: string,
defaultValue?: TDefaultValue
) => TDefaultValue
// for looking up values in the user’s Tailwind configuration
config: <TDefaultValue = Config>(path?: string, defaultValue?: TDefaultValue) => TDefaultValue
// for checking if a core plugin is enabled
corePlugins(path: string): boolean
// for manually escaping strings meant to be used in class names
e: (className: string) => string
}
export type PluginCreator = (api: PluginAPI) => void
export type PluginsConfig = (
| PluginCreator
| { handler: PluginCreator; config?: Config }
| { (options: any): { handler: PluginCreator; config?: Config }; __isOptionsFunction: true }
)[]
// Top level config related
interface RequiredConfig {
content: ContentConfig
}
interface OptionalConfig {
important: Partial<ImportantConfig>
prefix: Partial<PrefixConfig>
separator: Partial<SeparatorConfig>
safelist: Partial<SafelistConfig>
presets: Partial<PresetsConfig>
future: Partial<FutureConfig>
experimental: Partial<ExperimentalConfig>
darkMode: Partial<DarkModeConfig>
theme: Partial<ThemeConfig & { extend: Partial<ThemeConfig> }>
corePlugins: Partial<CorePluginsConfig>
plugins: Partial<PluginsConfig>
// Custom
[key: string]: any
}
export type Config = RequiredConfig & Partial<OptionalConfig>