tailwindcss 4.0.0-alpha.2 → 4.0.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib.d.ts CHANGED
@@ -1,3 +1,104 @@
1
+ type Rule = {
2
+ kind: 'rule';
3
+ selector: string;
4
+ nodes: AstNode[];
5
+ };
6
+ type Declaration = {
7
+ kind: 'declaration';
8
+ property: string;
9
+ value: string | undefined;
10
+ important: boolean;
11
+ };
12
+ type Comment = {
13
+ kind: 'comment';
14
+ value: string;
15
+ };
16
+ type AstNode = Rule | Declaration | Comment;
17
+
18
+ declare class Theme {
19
+ #private;
20
+ private values;
21
+ constructor(values?: Map<string, {
22
+ value: string;
23
+ isReference: boolean;
24
+ isInline: boolean;
25
+ }>);
26
+ add(key: string, value: string, { isReference, isInline }?: {
27
+ isReference?: boolean | undefined;
28
+ isInline?: boolean | undefined;
29
+ }): void;
30
+ keysInNamespaces(themeKeys: ThemeKey[]): string[];
31
+ get(themeKeys: (ThemeKey | `${ThemeKey}-${string}`)[]): string | null;
32
+ entries(): IterableIterator<[string, {
33
+ value: string;
34
+ isReference: boolean;
35
+ isInline: boolean;
36
+ }]>;
37
+ resolve(candidateValue: string | null, themeKeys: ThemeKey[]): string | null;
38
+ resolveValue(candidateValue: string | null, themeKeys: ThemeKey[]): string | null;
39
+ resolveWith(candidateValue: string, themeKeys: ThemeKey[], nestedKeys?: `--${string}`[]): [string, Record<string, string>] | null;
40
+ namespace(namespace: string): Map<string | null, string>;
41
+ }
42
+ type ThemeKey = '--accent-color' | '--animate' | '--aspect-ratio' | '--backdrop-blur' | '--backdrop-brightness' | '--backdrop-contrast' | '--backdrop-grayscale' | '--backdrop-hue-rotate' | '--backdrop-invert' | '--backdrop-opacity' | '--backdrop-saturate' | '--backdrop-sepia' | '--background-color' | '--background-image' | '--blur' | '--border-color' | '--border-spacing' | '--border-width' | '--box-shadow-color' | '--breakpoint' | '--brightness' | '--caret-color' | '--color' | '--columns' | '--contrast' | '--cursor' | '--default-border-width' | '--default-ring-color' | '--default-ring-width' | '--default-transition-timing-function' | '--default-transition-duration' | '--divide-width' | '--divide-color' | '--drop-shadow' | '--fill' | '--flex-basis' | '--font-family' | '--font-size' | '--font-weight' | '--gap' | '--gradient-color-stop-positions' | '--grayscale' | '--grid-auto-columns' | '--grid-auto-rows' | '--grid-column' | '--grid-column-end' | '--grid-column-start' | '--grid-row' | '--grid-row-end' | '--grid-row-start' | '--grid-template-columns' | '--grid-template-rows' | '--height' | '--hue-rotate' | '--inset' | '--inset-shadow' | '--invert' | '--letter-spacing' | '--line-height' | '--line-clamp' | '--list-style-image' | '--list-style-type' | '--margin' | '--max-height' | '--max-width' | '--min-height' | '--min-width' | '--object-position' | '--opacity' | '--order' | '--outline-color' | '--outline-width' | '--outline-offset' | '--padding' | '--placeholder-color' | '--perspective' | '--perspective-origin' | '--radius' | '--ring-color' | '--ring-offset-color' | '--ring-offset-width' | '--ring-width' | '--rotate' | '--saturate' | '--scale' | '--scroll-margin' | '--scroll-padding' | '--sepia' | '--shadow' | '--size' | '--skew' | '--space' | '--spacing' | '--stroke' | '--stroke-width' | '--text-color' | '--text-decoration-color' | '--text-decoration-thickness' | '--text-indent' | '--text-underline-offset' | '--transform-origin' | '--transition-delay' | '--transition-duration' | '--transition-property' | '--transition-timing-function' | '--translate' | '--width' | '--z-index' | `--default-${string}`;
43
+
44
+ type VariantFn<T extends Variant['kind']> = (rule: Rule, variant: Extract<Variant, {
45
+ kind: T;
46
+ }>) => null | void;
47
+ type CompareFn = (a: Variant, z: Variant) => number;
48
+ declare class Variants {
49
+ private compareFns;
50
+ private variants;
51
+ private completions;
52
+ /**
53
+ * Registering a group of variants should result in the same sort number for
54
+ * all the variants. This is to ensure that the variants are applied in the
55
+ * correct order.
56
+ */
57
+ private groupOrder;
58
+ /**
59
+ * Keep track of the last sort order instead of using the size of the map to
60
+ * avoid unnecessarily skipping order numbers.
61
+ */
62
+ private lastOrder;
63
+ static(name: string, applyFn: VariantFn<'static'>, { compounds }?: {
64
+ compounds?: boolean;
65
+ }): void;
66
+ fromAst(name: string, ast: AstNode[]): void;
67
+ functional(name: string, applyFn: VariantFn<'functional'>, { compounds }?: {
68
+ compounds?: boolean;
69
+ }): void;
70
+ compound(name: string, applyFn: VariantFn<'compound'>, { compounds }?: {
71
+ compounds?: boolean;
72
+ }): void;
73
+ group(fn: () => void, compareFn?: CompareFn): void;
74
+ has(name: string): boolean;
75
+ get(name: string): {
76
+ kind: Variant["kind"];
77
+ order: number;
78
+ applyFn: VariantFn<any>;
79
+ compounds: boolean;
80
+ } | undefined;
81
+ kind(name: string): "static" | "arbitrary" | "functional" | "compound";
82
+ compounds(name: string): boolean;
83
+ suggest(name: string, suggestions: () => string[]): void;
84
+ getCompletions(name: string): string[];
85
+ compare(a: Variant | null, z: Variant | null): number;
86
+ keys(): IterableIterator<string>;
87
+ entries(): IterableIterator<[string, {
88
+ kind: Variant["kind"];
89
+ order: number;
90
+ applyFn: VariantFn<any>;
91
+ compounds: boolean;
92
+ }]>;
93
+ private set;
94
+ private nextOrder;
95
+ }
96
+
97
+ declare function compileAstNodes(candidate: Candidate, designSystem: DesignSystem): {
98
+ node: AstNode;
99
+ propertySort: number[];
100
+ }[];
101
+
1
102
  interface ClassMetadata {
2
103
  modifiers: string[];
3
104
  }
@@ -14,37 +115,47 @@ interface VariantEntry {
14
115
  selectors: (options: SelectorOptions) => string[];
15
116
  }
16
117
 
17
- declare class Theme {
18
- private values;
19
- constructor(values?: Map<string, string>);
20
- add(key: string, value: string): void;
21
- keysInNamespaces(themeKeys: ThemeKey[]): string[];
22
- get(themeKeys: ThemeKey[]): string | null;
23
- entries(): IterableIterator<[string, string]>;
24
- clearNamespace(namespace: string): void;
25
- resolveKey(candidateValue: string, themeKeys: ThemeKey[]): string | null;
26
- resolve(candidateValue: string, themeKeys: ThemeKey[]): string | null;
27
- resolveWith(candidateValue: string, themeKeys: ThemeKey[], nestedKeys?: `--${string}`[]): [string, Record<string, string>] | null;
28
- namespace(namespace: string): Map<string | null, string>;
118
+ type CompileFn<T extends Candidate['kind']> = (value: Extract<Candidate, {
119
+ kind: T;
120
+ }>) => AstNode[] | undefined | null;
121
+ interface SuggestionGroup {
122
+ supportsNegative?: boolean;
123
+ values: (string | null)[];
124
+ modifiers: string[];
29
125
  }
30
- type ThemeKey = '--accent-color' | '--animate' | '--aspect-ratio' | '--backdrop-blur' | '--backdrop-brightness' | '--backdrop-contrast' | '--backdrop-grayscale' | '--backdrop-hue-rotate' | '--backdrop-invert' | '--backdrop-opacity' | '--backdrop-saturate' | '--backdrop-sepia' | '--background-color' | '--background-image' | '--blur' | '--border-color' | '--border-spacing' | '--border-width' | '--box-shadow-color' | '--breakpoint' | '--brightness' | '--caret-color' | '--color' | '--columns' | '--contrast' | '--cursor' | '--default-border-width' | '--default-ring-color' | '--default-ring-width' | '--divide-width' | '--divide-color' | '--drop-shadow' | '--fill' | '--flex-basis' | '--font-family' | '--font-size' | '--font-weight' | '--gap' | '--gradient-color-stop-positions' | '--grayscale' | '--grid-auto-columns' | '--grid-auto-rows' | '--grid-column' | '--grid-column-end' | '--grid-column-start' | '--grid-row' | '--grid-row-end' | '--grid-row-start' | '--grid-template-columns' | '--grid-template-rows' | '--height' | '--hue-rotate' | '--inset' | '--inset-shadow' | '--invert' | '--letter-spacing' | '--line-height' | '--line-clamp' | '--list-style-image' | '--list-style-type' | '--margin' | '--max-height' | '--max-width' | '--min-height' | '--min-width' | '--object-position' | '--opacity' | '--order' | '--outline-color' | '--outline-width' | '--outline-offset' | '--padding' | '--placeholder-color' | '--radius' | '--ring-color' | '--ring-offset-color' | '--ring-offset-width' | '--ring-width' | '--rotate' | '--saturate' | '--scale' | '--scroll-margin' | '--scroll-padding' | '--sepia' | '--shadow' | '--size' | '--skew' | '--space' | '--spacing' | '--stroke' | '--stroke-width' | '--text-color' | '--text-decoration-color' | '--text-decoration-thickness' | '--text-indent' | '--text-underline-offset' | '--transform-origin' | '--transition-delay' | '--transition-duration' | '--transition-property' | '--transition-timing-function' | '--translate' | '--width' | '--z-index';
31
-
32
- type Rule = {
33
- kind: 'rule';
34
- selector: string;
35
- nodes: AstNode[];
126
+ type UtilityOptions = {
127
+ types: string[];
36
128
  };
37
- type Declaration = {
38
- kind: 'declaration';
39
- property: string;
40
- value: string;
41
- important: boolean;
129
+ type Utility = {
130
+ kind: 'static' | 'functional';
131
+ compileFn: CompileFn<any>;
132
+ options?: UtilityOptions;
42
133
  };
43
- type Comment = {
44
- kind: 'comment';
45
- value: string;
134
+ declare class Utilities {
135
+ private utilities;
136
+ private completions;
137
+ static(name: string, compileFn: CompileFn<'static'>): void;
138
+ functional(name: string, compileFn: CompileFn<'functional'>, options?: UtilityOptions): void;
139
+ has(name: string, kind: 'static' | 'functional'): boolean;
140
+ get(name: string): Utility[];
141
+ getCompletions(name: string): SuggestionGroup[];
142
+ suggest(name: string, groups: () => SuggestionGroup[]): void;
143
+ keys(kind: 'static' | 'functional'): string[];
144
+ }
145
+
146
+ type DesignSystem = {
147
+ theme: Theme;
148
+ utilities: Utilities;
149
+ variants: Variants;
150
+ candidatesToCss(classes: string[]): (string | null)[];
151
+ getClassOrder(classes: string[]): [string, bigint | null][];
152
+ getClassList(): ClassEntry[];
153
+ getVariants(): VariantEntry[];
154
+ parseCandidate(candidate: string): Candidate[];
155
+ parseVariant(variant: string): ReturnType<typeof parseVariant>;
156
+ compileAstNodes(candidate: Candidate): ReturnType<typeof compileAstNodes>;
157
+ getUsedVariants(): ReturnType<typeof parseVariant>[];
46
158
  };
47
- type AstNode = Rule | Declaration | Comment;
48
159
 
49
160
  type ArbitraryUtilityValue = {
50
161
  kind: 'arbitrary';
@@ -122,6 +233,7 @@ type Variant =
122
233
  kind: 'arbitrary';
123
234
  selector: string;
124
235
  compounds: boolean;
236
+ relative: boolean;
125
237
  }
126
238
  /**
127
239
  * Static variants are variants that don't take any arguments.
@@ -186,6 +298,7 @@ type Candidate =
186
298
  modifier: ArbitraryModifier | NamedModifier | null;
187
299
  variants: Variant[];
188
300
  important: boolean;
301
+ raw: string;
189
302
  }
190
303
  /**
191
304
  * Static candidates are candidates that don't take any arguments.
@@ -201,6 +314,7 @@ type Candidate =
201
314
  variants: Variant[];
202
315
  negative: boolean;
203
316
  important: boolean;
317
+ raw: string;
204
318
  }
205
319
  /**
206
320
  * Functional candidates are candidates that can take an argument.
@@ -219,106 +333,89 @@ type Candidate =
219
333
  variants: Variant[];
220
334
  negative: boolean;
221
335
  important: boolean;
336
+ raw: string;
222
337
  };
338
+ declare function parseVariant(variant: string, designSystem: DesignSystem): Variant | null;
223
339
 
224
- type CompileFn<T extends Candidate['kind']> = (value: Extract<Candidate, {
225
- kind: T;
226
- }>) => AstNode[] | undefined;
227
- interface SuggestionGroup {
228
- supportsNegative?: boolean;
229
- values: (string | null)[];
230
- modifiers: string[];
231
- }
232
- declare class Utilities {
233
- private utilities;
234
- private completions;
235
- static(name: string, compileFn: CompileFn<'static'>): void;
236
- functional(name: string, compileFn: CompileFn<'functional'>): void;
237
- arbitrary(compileFn: CompileFn<'arbitrary'>): void;
238
- has(name: string): boolean;
239
- get(name: string | symbol): {
240
- kind: "arbitrary" | "static" | "functional";
241
- compileFn: CompileFn<any>;
242
- } | undefined;
243
- kind(name: string): "arbitrary" | "static" | "functional";
244
- getCompletions(name: string): SuggestionGroup[];
245
- suggest(name: string, groups: () => SuggestionGroup[]): void;
246
- keys(): IterableIterator<string | symbol>;
247
- entries(): IterableIterator<[string | symbol, {
248
- kind: "arbitrary" | "static" | "functional";
249
- compileFn: CompileFn<any>;
250
- }]>;
251
- getArbitrary(): CompileFn<any>;
252
- private set;
340
+ interface PluginUtils {
341
+ theme(keypath: string, defaultValue?: any): any;
253
342
  }
254
343
 
255
- type VariantFn<T extends Variant['kind']> = (rule: Rule, variant: Extract<Variant, {
256
- kind: T;
257
- }>) => null | void;
258
- type CompareFn = (a: Variant, z: Variant) => number;
259
- declare class Variants {
260
- private compareFns;
261
- private variants;
262
- private completions;
263
- /**
264
- * Registering a group of variants should result in the same sort number for
265
- * all the variants. This is to ensure that the variants are applied in the
266
- * correct order.
267
- */
268
- private groupOrder;
269
- /**
270
- * Keep track of the last sort order instead of using the size of the map to
271
- * avoid unnecessarily skipping order numbers.
272
- */
273
- private lastOrder;
274
- static(name: string, applyFn: VariantFn<'static'>, { compounds }?: {
275
- compounds?: boolean;
276
- }): void;
277
- functional(name: string, applyFn: VariantFn<'functional'>, { compounds }?: {
278
- compounds?: boolean;
279
- }): void;
280
- compound(name: string, applyFn: VariantFn<'compound'>, { compounds }?: {
281
- compounds?: boolean;
282
- }): void;
283
- group(fn: () => void, compareFn?: CompareFn): void;
284
- has(name: string): boolean;
285
- get(name: string): {
286
- kind: "arbitrary" | "static" | "functional" | "compound";
287
- order: number;
288
- applyFn: VariantFn<any>;
289
- compounds: boolean;
290
- } | undefined;
291
- kind(name: string): "arbitrary" | "static" | "functional" | "compound";
292
- compounds(name: string): boolean;
293
- suggest(name: string, suggestions: () => string[]): void;
294
- getCompletions(name: string): string[];
295
- compare(a: Variant | null, z: Variant | null): number;
296
- keys(): IterableIterator<string>;
297
- entries(): IterableIterator<[string, {
298
- kind: "arbitrary" | "static" | "functional" | "compound";
299
- order: number;
300
- applyFn: VariantFn<any>;
301
- compounds: boolean;
302
- }]>;
303
- private set;
304
- private nextOrder;
305
- }
344
+ type PluginFn = (api: PluginAPI) => void;
345
+ type PluginWithConfig = {
346
+ handler: PluginFn;
347
+ config?: UserConfig;
348
+ };
349
+ type PluginWithOptions<T> = {
350
+ (options?: T): PluginWithConfig;
351
+ __isOptionsFunction: true;
352
+ };
353
+ type Plugin = PluginFn | PluginWithConfig | PluginWithOptions<any>;
354
+ type PluginAPI = {
355
+ addBase(base: CssInJs): void;
356
+ addVariant(name: string, variant: string | string[] | CssInJs): void;
357
+ addUtilities(utilities: Record<string, CssInJs | CssInJs[]> | Record<string, CssInJs | CssInJs[]>[], options?: {}): void;
358
+ matchUtilities(utilities: Record<string, (value: string, extra: {
359
+ modifier: string | null;
360
+ }) => CssInJs | CssInJs[]>, options?: Partial<{
361
+ type: string | string[];
362
+ supportsNegativeValues: boolean;
363
+ values: Record<string, string> & {
364
+ __BARE_VALUE__?: (value: NamedUtilityValue) => string | undefined;
365
+ };
366
+ modifiers: 'any' | Record<string, string>;
367
+ }>): void;
368
+ addComponents(utilities: Record<string, CssInJs> | Record<string, CssInJs>[], options?: {}): void;
369
+ matchComponents(utilities: Record<string, (value: string, extra: {
370
+ modifier: string | null;
371
+ }) => CssInJs>, options?: Partial<{
372
+ type: string | string[];
373
+ supportsNegativeValues: boolean;
374
+ values: Record<string, string> & {
375
+ __BARE_VALUE__?: (value: NamedUtilityValue) => string | undefined;
376
+ };
377
+ modifiers: 'any' | Record<string, string>;
378
+ }>): void;
379
+ theme(path: string, defaultValue?: any): any;
380
+ config(path: string, defaultValue?: any): any;
381
+ prefix(className: string): string;
382
+ };
383
+ type CssInJs = {
384
+ [key: string]: string | string[] | CssInJs | CssInJs[];
385
+ };
306
386
 
307
- type DesignSystem = {
308
- theme: Theme;
309
- utilities: Utilities;
310
- variants: Variants;
311
- candidatesToCss(classes: string[]): (string | null)[];
312
- getClassOrder(classes: string[]): [string, bigint | null][];
313
- getClassList(): ClassEntry[];
314
- getVariants(): VariantEntry[];
387
+ type ResolvableTo<T> = T | ((utils: PluginUtils) => T);
388
+ type ThemeValue = ResolvableTo<Record<string, unknown>> | null | undefined;
389
+ type ThemeConfig = Record<string, ThemeValue> & {
390
+ extend?: Record<string, ThemeValue>;
391
+ };
392
+ type ContentFile = string | {
393
+ raw: string;
394
+ extension?: string;
315
395
  };
396
+ type DarkModeStrategy = false | 'media' | 'class' | ['class', string] | 'selector' | ['selector', string] | ['variant', string | string[]];
397
+ interface UserConfig {
398
+ presets?: UserConfig[];
399
+ theme?: ThemeConfig;
400
+ plugins?: Plugin[];
401
+ }
402
+ interface UserConfig {
403
+ content?: ContentFile[] | {
404
+ files: ContentFile[];
405
+ };
406
+ }
407
+ interface UserConfig {
408
+ darkMode?: DarkModeStrategy;
409
+ }
316
410
 
317
- declare function compile(css: string, rawCandidates: string[]): string;
318
- declare function optimizeCss(input: string, { file, minify }?: {
319
- file?: string;
320
- minify?: boolean;
321
- }): string;
322
- declare function __unstable__loadDesignSystem(css: string): DesignSystem;
411
+ type CompileOptions = {
412
+ loadPlugin?: (path: string) => Promise<Plugin>;
413
+ loadConfig?: (path: string) => Promise<UserConfig>;
414
+ };
415
+ declare function compile(css: string, opts?: CompileOptions): Promise<{
416
+ globs: string[];
417
+ build(candidates: string[]): string;
418
+ }>;
419
+ declare function __unstable__loadDesignSystem(css: string, opts?: CompileOptions): Promise<DesignSystem>;
323
420
 
324
- export { __unstable__loadDesignSystem, compile, optimizeCss };
421
+ export { __unstable__loadDesignSystem, compile };