-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathcompiler.types.ts
More file actions
374 lines (327 loc) · 8.8 KB
/
compiler.types.ts
File metadata and controls
374 lines (327 loc) · 8.8 KB
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/* eslint-disable */
import type {
AnimationDirection,
AnimationFillMode,
AnimationPlayState,
MediaFeatureNameFor_MediaFeatureId,
} from "lightningcss";
import { VAR_SYMBOL } from "../runtime/native/reactivity";
export interface CompilerOptions {
inlineRem?: number | false;
grouping?: (string | RegExp)[];
selectorPrefix?: string;
stylesheetOrder?: number;
features?: FeatureFlagRecord;
logger?: (message: string) => void;
/** Strip unused variables declarations. Defaults: false */
stripUnusedVariables?: boolean;
/** @internal */
ignorePropertyWarningRegex?: (string | RegExp)[];
}
/**
* A `react-native-css` StyleSheet
*/
export type ReactNativeCssStyleSheet = ReactNativeCssStyleSheet_V2;
export interface ReactNativeCssStyleSheet_V2 {
/** Feature flags */
f?: FeatureFlagRecord;
/** rem */
r?: number;
/** StyleRuleSets */
s?: [string, StyleRuleSet][];
/** KeyFrames */
k?: Animation_V2[];
/** Root Variables */
vr?: [string, LightDarkVariable][];
/** Universal Variables */
vu?: [string, LightDarkVariable][];
}
/******************************** Styles ********************************/
/**
* The JS representation of a style object
*
* This CSS rule is a single StyleRuleSet, made up of multiple StyleRules
*
* ```css
* .my-class {
* color: red;
* }
* ```
* Properties are split into normal and important properties, and then split
* into different StyleRules depending on their specificity, conditions, etc
*/
export type StyleRuleSet = StyleRule[];
export interface StyleRule {
/** Specificity */
s: SpecificityArray;
/** Declarations */
d?: StyleDeclaration[];
/** Variables */
v?: VariableDescriptor[];
/** Named Containers */
c?: string[];
/** Declarations use variables */
dv?: number;
// Target override
target?: string | string[] | false;
/**
* Conditionals
*/
/** MediaQuery */
m?: MediaCondition[];
/** PseudoClassesQuery */
p?: PseudoClassesQuery;
/** Container Query */
cq?: ContainerQuery[];
/** Attribute Conditions */
aq?: AttributeQuery[];
/**
* Animations and Transitions
*/
/** Animations */
a?: boolean;
}
export type StyleDeclaration =
/** This is a static style object */
| Record<string, StyleDescriptor>
/** A style that needs to be set */
| [StyleDescriptor, string | string[]]
/** A value that can only be computed at runtime */
| [StyleFunction, string | string[]]
/** A value that can only be computed at runtime, and only after styles have been calculated */
| [StyleFunction, string | string[], 1];
export type StyleDescriptor =
| string
| number
| boolean
| undefined
| StyleFunction
| StyleDescriptor[];
export type StyleFunction =
| [
Record<never, never>,
string, // string
]
| [
Record<never, never>,
string, // string
undefined | StyleDescriptor[], // arguments
]
| [
Record<never, never>,
string, // string
undefined | StyleDescriptor[], // arguments
1, // Should process after styles have been calculated
];
/****************************** Variables *******************************/
export type VariableDescriptor = [string, StyleDescriptor];
export type VariableRecord = Record<string, LightDarkVariable>;
export type LightDarkVariable =
| [StyleDescriptor]
| [StyleDescriptor, StyleDescriptor];
export type InlineVariable = {
[VAR_SYMBOL]: "inline";
[key: string]: StyleDescriptor | undefined;
};
/****************************** Animations V1 ******************************/
/**
* An animation with a fallback style value
*/
export type AnimationWithDefault_V1 =
| [AnimationRule_V1]
| [AnimationRule_V1, StyleFunction];
/**
* A CSS Animation rule
*/
export interface AnimationRule_V1 {
/**
* The animation delay.
*/
de?: number[];
/**
* The direction of the animation.
*/
di?: AnimationDirection[];
/**
* The animation duration.
*/
du?: number[];
/**
* The animation fill mode.
*/
f?: AnimationFillMode[];
/**
* The number of times the animation will run.
*/
i?: number[];
/**
* The animation name.
*/
n?: string[];
/**
* The current play state of the animation.
*/
p?: AnimationPlayState[];
/**
* The animation timeline.
*/
t?: never[];
/**
* The easing function for the animation.
*/
e?: EasingFunction[];
}
export type AnimationKeyframes_V1 =
| [AnimationInterpolation_V1[]]
| [AnimationInterpolation_V1[], AnimationEasing[]];
export type AnimationEasing = number | [number, EasingFunction];
export type AnimationInterpolation_V1 =
| [string, number[], StyleDescriptor[]]
| [string, number[], StyleDescriptor[], number]
| [string, number[], StyleDescriptor[], number, AnimationInterpolationType];
export type AnimationInterpolationType = "color" | "%" | undefined;
export type EasingFunction =
| "linear"
| "ease"
| "ease-in"
| "ease-out"
| "ease-in-out"
| {
type: "cubic-bezier";
/**
* The x-position of the first point in the curve.
*/
x1: number;
/**
* The x-position of the second point in the curve.
*/
x2: number;
/**
* The y-position of the first point in the curve.
*/
y1: number;
/**
* The y-position of the second point in the curve.
*/
y2: number;
}
| {
type: "steps";
/**
* The number of intervals in the function.
*/
c: number;
/**
* The step position.
*/
p?: "start" | "end" | "jump-none" | "jump-both";
};
/****************************** Animations V2 ******************************/
export type Animation_V2 = [string, AnimationKeyframes_V2[]];
export type AnimationKeyframes_V2 = [string | number, StyleDeclaration[]];
/****************************** Transitions *****************************/
export type TransitionRule = {
/**
* Delay before the transition starts in milliseconds.
*/
de?: number[];
/**
* Duration of the transition in milliseconds.
*/
du?: number[];
/**
* Property to transition.
*/
p?: string[];
/**
* Easing function for the transition.
*/
e?: EasingFunction[];
};
/****************************** Conditions ******************************/
export type MediaCondition =
// Boolean
| ["!!", MediaFeatureNameFor_MediaFeatureId]
// Not
| ["!", MediaCondition]
// And
| ["&", MediaCondition[]]
// Or
| ["|", MediaCondition[]]
// Comparison
| [
MediaFeatureComparison,
MediaFeatureNameFor_MediaFeatureId | MediaFeatureNameFor_MediaFeatureId,
StyleDescriptor,
]
// [Start, End]
| [
"[]",
MediaFeatureNameFor_MediaFeatureId,
StyleDescriptor, // Start
MediaFeatureComparison, // Start comparison
StyleDescriptor, // End
MediaFeatureComparison, // End comparison
];
export type MediaFeatureComparison = "=" | ">" | ">=" | "<" | "<=";
export interface PseudoClassesQuery {
/** Hover */
h?: 1;
/** Active */
a?: 1;
/** Focus */
f?: 1;
}
type AttributeQueryType =
| "a" // Attribute
| "d"; // Data-Attribute
export type AttributeQuery =
| [AttributeQueryType, string] // Exists
| [AttributeQueryType, string, "!"] // Falsy
| [AttributeQueryType, string, AttrSelectorOperator, string] // Use operator
| [AttributeQueryType, string, AttrSelectorOperator, string, "i" | "s"]; // Case sensitivity
export type AttrSelectorOperator = "=" | "~=" | "|=" | "^=" | "$=" | "*=";
/****************************** Containers *****************************/
export interface ContainerQuery {
/** Name */
n?: string | null;
m?: MediaCondition;
p?: PseudoClassesQuery;
a?: AttributeQuery[];
}
/****************************** Specificity *****************************/
/**
* https://drafts.csswg.org/selectors/#specificity-rules
*
* This array is sorted by most common values when parsing a StyleSheet
*/
export type SpecificityArray = SpecificityValue[];
export type SpecificityValue = number | undefined;
/****************************** Compiler ********************************/
type FeatureFlags = never;
export type FeatureFlagRecord = Partial<Record<FeatureFlags, boolean>>;
/** @internal */
export type PathTokens = string | string[];
/** @internal */
export type StyleRuleMapping = Record<string, PathTokens | undefined>;
/**
* @internal
*/
export type LoggerOptions = {
logger: (message: string) => void;
};
/**
* @internal
*/
export interface CompilerCollection extends CompilerOptions {
features: FeatureFlagRecord;
rules: Map<string, StyleRule[]>;
keyframes: Map<string, AnimationKeyframes_V1 | AnimationKeyframes_V2[]>;
darkMode?: string | null;
rootVariables: VariableRecord;
universalVariables: VariableRecord;
selectorPrefix?: string;
appearanceOrder: number;
rem?: number | boolean;
varUsageCount: Map<string, number>;
}