-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathcompiler.types.ts
More file actions
268 lines (230 loc) · 6.64 KB
/
compiler.types.ts
File metadata and controls
268 lines (230 loc) · 6.64 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
/* eslint-disable */
import type { Debugger } from "debug";
import type { MediaFeatureNameFor_MediaFeatureId } from "lightningcss";
import { VAR_SYMBOL } from "../runtime/native/reactivity";
export interface CompilerOptions {
filename?: string;
projectRoot?: string;
inlineRem?: number | false;
selectorPrefix?: string;
stylesheetOrder?: number;
features?: FeatureFlagRecord;
logger?: (message: string) => void | Debugger;
/** Strip unused variables declarations. Defaults: false */
stripUnusedVariables?: boolean;
/** @internal */
ignorePropertyWarningRegex?: (string | RegExp)[];
preserveVariables?: boolean;
hexColors?: boolean;
colorPrecision?: number;
}
/**
* A `react-native-css` StyleSheet
*/
export type ReactNativeCssStyleSheet = ReactNativeCssStyleSheet_V2;
export interface ReactNativeCssStyleSheet_V2 {
/** Feature flags */
f?: FeatureFlagRecord;
/** rem */
r?: number;
/** StyleRuleSets */
s?: (readonly [string, StyleRuleSet])[];
/** KeyFrames */
k?: Animation_V2[];
/** Root Variables */
vr?: RootVariables;
/** Universal Variables */
vu?: RootVariables;
}
/******************************** 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, and only after styles have been calculated */
| [StyleDescriptor, string | string[], 1];
export type StyleDescriptor =
| string
| number
| boolean
| undefined
| StyleFunction
| StyleDescriptor[];
export type StyleFunction =
| [
Record<never, never>,
string, // string
]
| readonly [
Record<never, never>,
string, // string
]
| [
Record<never, never>,
string, // string
StyleDescriptor, // arguments
]
| readonly [
Record<never, never>,
string, // string
StyleDescriptor, // arguments
]
| [
Record<never, never>,
string, // string
StyleDescriptor, // arguments
1, // Should process after styles have been calculated
]
| readonly [
Record<never, never>,
string, // string
StyleDescriptor, // arguments
1, // Should process after styles have been calculated
];
/****************************** Variables *******************************/
export type VariableDescriptor = [string, StyleDescriptor];
export type VariableRecord = Record<string, VariableValue[]>;
export type VariableValue =
| [StyleDescriptor]
| [StyleDescriptor, MediaCondition[]];
export type RootVariables = [string, VariableValue[]][];
export type InlineVariable = {
[VAR_SYMBOL]: "inline";
[key: string]: unknown | undefined;
};
/****************************** Animations V2 ******************************/
export type Animation_V2 = [string, AnimationKeyframes_V2[]];
export type AnimationRecord = Record<string, AnimationKeyframes_V2[]>;
export type AnimationKeyframes_V2 = [string | number, StyleDeclaration[]];
/****************************** Conditions ******************************/
export type MediaCondition =
// Boolean
| ["!!", MediaFeatureNameFor_MediaFeatureId]
// Not
| ["!", MediaCondition]
// And
| ["&", MediaCondition[]]
// Or
| ["|", MediaCondition[]]
// Comparison
| [
MediaFeatureComparison,
MediaFeatureNameFor_MediaFeatureId | "dir",
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>;
/**
* @internal
*/
export type LoggerOptions = {
logger: (message: string) => void;
};
/**
* @internal
*/
export interface CompilerCollection extends CompilerOptions {
features: FeatureFlagRecord;
rules: Map<string, StyleRule[]>;
keyframes: Map<string, AnimationKeyframes_V2[]>;
darkMode?: string | null;
rootVariables: VariableRecord;
universalVariables: VariableRecord;
selectorPrefix?: string;
appearanceOrder: number;
rem?: number | boolean;
varUsageCount: Map<string, number>;
}