-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.ts
200 lines (179 loc) · 5.54 KB
/
types.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
export type EsmaVersion =
| "es2015"
| "es2016"
| "es2017"
| "es2018"
| "es2019"
| "es2020"
| "es2021"
| "es2022";
export type TransformOptions = {
alephPkgUri?: string;
lang?: "ts" | "tsx" | "js" | "jsx";
target?: EsmaVersion;
importMap?: string;
globalVersion?: string;
graphVersions?: Record<string, string>;
resolveRemoteModule?: boolean;
stripDataExport?: boolean;
isDev?: boolean;
reactRefresh?: boolean;
sourceMap?: boolean;
jsx?: "automatic" | "classic" | "preserve";
jsxPragma?: string;
jsxPragmaFrag?: string;
jsxImportSource?: string;
minify?: { compress: boolean };
};
export type TransformResult = {
readonly code: string;
readonly map?: string;
readonly deps?: DependencyDescriptor[];
};
export type DependencyDescriptor = {
readonly specifier: string;
readonly importUrl: string;
readonly loc?: { start: number; end: number; ctxt: number };
readonly dynamic?: boolean;
};
export interface Targets {
android?: number;
chrome?: number;
edge?: number;
firefox?: number;
ie?: number;
ios_saf?: number;
opera?: number;
safari?: number;
samsung?: number;
}
export interface DependencyOptions {
removeImports: boolean;
}
export interface TransformCSSOptions {
/** Whether to enable minification. */
minify?: boolean;
/** Whether to output a source map. */
sourceMap?: boolean;
/** The browser targets for the generated code. */
targets?: Targets;
/** Whether to enable various draft syntax. */
drafts?: Drafts;
/** Whether to compile this file as a CSS module. */
cssModules?: boolean | CSSModulesConfig;
/**
* Whether to analyze dependencies (e.g. `@import` and `url()`).
* When enabled, `@import` rules are removed, and `url()` dependencies
* are replaced with hashed placeholders that can be replaced with the final
* urls later (after bundling). Dependencies are returned as part of the result.
*/
analyzeDependencies?: DependencyOptions;
/**
* Replaces user action pseudo classes with class names that can be applied from JavaScript.
* This is useful for polyfills, for example.
*/
pseudoClasses?: PseudoClasses;
/**
* A list of class names, ids, and custom identifiers (e.g. @keyframes) that are known
* to be unused. These will be removed during minification. Note that these are not
* selectors but individual names (without any . or # prefixes).
*/
unusedSymbols?: string[];
}
export interface Drafts {
/** Whether to enable CSS nesting. */
nesting?: boolean;
/** Whether to enable @custom-media rules. */
customMedia?: boolean;
}
export interface PseudoClasses {
hover?: string;
active?: string;
focus?: string;
focusVisible?: string;
focusWithin?: string;
}
export interface TransformCSSResult {
/** The transformed code. */
readonly code: string;
/** The generated source map, if enabled. */
readonly map?: string;
/** CSS module exports, if enabled. */
readonly exports?: CSSModuleExports;
/** `@import` and `url()` dependencies, if enabled. */
readonly dependencies?: Dependency[];
}
export interface CSSModulesConfig {
/** The pattern to use when renaming class names and other identifiers. Default is `[hash]_[local]`. */
pattern?: string;
/** Whether to rename dashed identifiers, e.g. custom properties. */
dashedIdents?: boolean;
}
export type CSSModuleExports = {
/** Maps exported (i.e. original) names to local names. */
readonly [name: string]: CSSModuleExport;
};
export interface CSSModuleExport {
/** The local (compiled) name for this export. */
readonly name: string;
/** Whether the export is referenced in this file. */
readonly isReferenced: boolean;
/** Other names that are composed by this export. */
readonly composes: CSSModuleReference[];
}
export type CSSModuleReference =
| LocalCSSModuleReference
| GlobalCSSModuleReference
| DependencyCSSModuleReference;
export interface LocalCSSModuleReference {
readonly type: "local";
/** The local (compiled) name for the reference. */
readonly name: string;
}
export interface GlobalCSSModuleReference {
readonly type: "global";
/** The referenced global name. */
readonly name: string;
}
export interface DependencyCSSModuleReference {
readonly type: "dependency";
/** The name to reference within the dependency. */
readonly name: string;
/** The dependency specifier for the referenced file. */
readonly specifier: string;
}
export type Dependency = ImportDependency | UrlDependency;
export interface ImportDependency {
readonly type: "import";
/** The url of the `@import` dependency. */
readonly url: string;
/** The media query for the `@import` rule. */
readonly media: string | null;
/** The `supports()` query for the `@import` rule. */
readonly supports: string | null;
/** The source location where the `@import` rule was found. */
readonly loc: SourceLocation;
}
export interface UrlDependency {
readonly type: "url";
/** The url of the dependency. */
readonly url: string;
/** The source location where the `url()` was found. */
readonly loc: SourceLocation;
/** The placeholder that the url was replaced with. */
readonly placeholder: string;
}
export interface SourceLocation {
/** The file path in which the dependency exists. */
readonly filePath: string;
/** The start location of the dependency. */
readonly start: Location;
/** The end location (inclusive) of the dependency. */
readonly end: Location;
}
export interface Location {
/** The line number (1-based). */
readonly line: number;
/** The column number (0-based). */
readonly column: number;
}