-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
css_table.go
312 lines (273 loc) · 9.85 KB
/
css_table.go
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
package compat
import (
"github.com/evanw/esbuild/internal/css_ast"
)
type CSSFeature uint8
const (
HexRGBA CSSFeature = 1 << iota
InlineStyle
RebeccaPurple
// This feature includes all of the following:
// - Allow floats in rgb() and rgba()
// - hsl() can accept alpha values
// - rgb() can accept alpha values
// - Space-separated functional color notations
Modern_RGB_HSL
InsetProperty
Nesting
IsPseudoClass
)
var StringToCSSFeature = map[string]CSSFeature{
"hex-rgba": HexRGBA,
"inline-style": InlineStyle,
"rebecca-purple": RebeccaPurple,
"modern-rgb-hsl": Modern_RGB_HSL,
"inset-property": InsetProperty,
"nesting": Nesting,
"is-pseudo-class": IsPseudoClass,
}
func (features CSSFeature) Has(feature CSSFeature) bool {
return (features & feature) != 0
}
func (features CSSFeature) ApplyOverrides(overrides CSSFeature, mask CSSFeature) CSSFeature {
return (features & ^mask) | (overrides & mask)
}
var cssTable = map[CSSFeature]map[Engine][]versionRange{
// Data from: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
HexRGBA: {
Chrome: {{start: v{62, 0, 0}}},
Edge: {{start: v{79, 0, 0}}},
Firefox: {{start: v{49, 0, 0}}},
IOS: {{start: v{9, 3, 0}}},
Opera: {{start: v{49, 0, 0}}},
Safari: {{start: v{9, 1, 0}}},
},
RebeccaPurple: {
Chrome: {{start: v{38, 0, 0}}},
Edge: {{start: v{12, 0, 0}}},
Firefox: {{start: v{33, 0, 0}}},
IE: {{start: v{11, 0, 0}}},
IOS: {{start: v{8, 0, 0}}},
Opera: {{start: v{25, 0, 0}}},
Safari: {{start: v{9, 0, 0}}},
},
Modern_RGB_HSL: {
Chrome: {{start: v{66, 0, 0}}},
Edge: {{start: v{79, 0, 0}}},
Firefox: {{start: v{52, 0, 0}}},
IOS: {{start: v{12, 2, 0}}},
Opera: {{start: v{53, 0, 0}}},
Safari: {{start: v{12, 1, 0}}},
},
// Data from: https://developer.mozilla.org/en-US/docs/Web/CSS/inset
InsetProperty: {
Chrome: {{start: v{87, 0, 0}}},
Edge: {{start: v{87, 0, 0}}},
Firefox: {{start: v{66, 0, 0}}},
IOS: {{start: v{14, 5, 0}}},
Opera: {{start: v{73, 0, 0}}},
Safari: {{start: v{14, 1, 0}}},
},
// Data from: https://caniuse.com/css-nesting
Nesting: {
Chrome: {{start: v{112, 0, 0}}},
},
// Data from: https://caniuse.com/css-matches-pseudo
IsPseudoClass: {
Chrome: {{start: v{88, 0, 0}}},
Edge: {{start: v{88, 0, 0}}},
Firefox: {{start: v{78, 0, 0}}},
IOS: {{start: v{14, 0, 0}}},
Opera: {{start: v{75, 0, 0}}},
Safari: {{start: v{14, 0, 0}}},
},
}
// Return all features that are not available in at least one environment
func UnsupportedCSSFeatures(constraints map[Engine][]int) (unsupported CSSFeature) {
for feature, engines := range cssTable {
if feature == InlineStyle {
continue // This is purely user-specified
}
for engine, version := range constraints {
if !engine.IsBrowser() {
// Specifying "--target=es2020" shouldn't affect CSS
continue
}
if versionRanges, ok := engines[engine]; !ok || !isVersionSupported(versionRanges, version) {
unsupported |= feature
}
}
}
return
}
type CSSPrefix uint8
const (
WebkitPrefix CSSPrefix = 1 << iota
MozPrefix
MsPrefix
OPrefix
NoPrefix CSSPrefix = 0
)
type prefixData struct {
// Note: In some cases, earlier versions did not require a prefix but later
// ones do. This is the case for Microsoft Edge for example, which switched
// the underlying browser engine from a custom one to the one from Chrome.
// However, we assume that users specifying a browser version for CSS mean
// "works in this version or newer", so we still add a prefix when a target
// is an old Edge version.
withoutPrefix v
prefix CSSPrefix
}
var cssMaskPrefixTable = map[Engine]prefixData{
Chrome: {prefix: WebkitPrefix},
Edge: {prefix: WebkitPrefix},
IOS: {prefix: WebkitPrefix, withoutPrefix: v{15, 4, 0}},
Opera: {prefix: WebkitPrefix},
Safari: {prefix: WebkitPrefix, withoutPrefix: v{15, 4, 0}},
}
var cssTextEmphasisTable = map[Engine]prefixData{
Chrome: {prefix: WebkitPrefix, withoutPrefix: v{99, 0, 0}},
Edge: {prefix: WebkitPrefix, withoutPrefix: v{99, 0, 0}},
Opera: {prefix: WebkitPrefix, withoutPrefix: v{85, 0, 0}},
}
var cssPrefixTable = map[css_ast.D]map[Engine]prefixData{
// https://caniuse.com/css-appearance
css_ast.DAppearance: {
Chrome: {prefix: WebkitPrefix, withoutPrefix: v{84, 0, 0}},
Edge: {prefix: WebkitPrefix, withoutPrefix: v{84, 0, 0}},
Firefox: {prefix: MozPrefix, withoutPrefix: v{80, 4, 0}},
IOS: {prefix: WebkitPrefix, withoutPrefix: v{15, 4, 0}},
Opera: {prefix: WebkitPrefix, withoutPrefix: v{73, 4, 0}},
Safari: {prefix: WebkitPrefix, withoutPrefix: v{15, 4, 0}},
},
// https://caniuse.com/css-backdrop-filter
css_ast.DBackdropFilter: {
IOS: {prefix: WebkitPrefix},
Safari: {prefix: WebkitPrefix},
},
// https://caniuse.com/background-clip-text (Note: only for "background-clip: text")
css_ast.DBackgroundClip: {
Chrome: {prefix: WebkitPrefix},
Edge: {prefix: WebkitPrefix},
IOS: {prefix: WebkitPrefix, withoutPrefix: v{14, 0, 0}},
Opera: {prefix: WebkitPrefix},
Safari: {prefix: WebkitPrefix, withoutPrefix: v{14, 0, 0}},
},
// https://caniuse.com/css-boxdecorationbreak
css_ast.DBoxDecorationBreak: {
Chrome: {prefix: WebkitPrefix},
Edge: {prefix: WebkitPrefix},
IOS: {prefix: WebkitPrefix},
Opera: {prefix: WebkitPrefix},
Safari: {prefix: WebkitPrefix},
},
// https://caniuse.com/css-clip-path
css_ast.DClipPath: {
Chrome: {prefix: WebkitPrefix, withoutPrefix: v{55, 0, 0}},
IOS: {prefix: WebkitPrefix, withoutPrefix: v{13, 0, 0}},
Opera: {prefix: WebkitPrefix, withoutPrefix: v{42, 0, 0}},
Safari: {prefix: WebkitPrefix, withoutPrefix: v{13, 1, 0}},
},
// https://caniuse.com/font-kerning
css_ast.DFontKerning: {
Chrome: {prefix: WebkitPrefix, withoutPrefix: v{33, 0, 0}},
IOS: {prefix: WebkitPrefix, withoutPrefix: v{12, 0, 0}},
Opera: {prefix: WebkitPrefix, withoutPrefix: v{20, 0, 0}},
Safari: {prefix: WebkitPrefix, withoutPrefix: v{9, 1, 0}},
},
// https://caniuse.com/css-hyphens
css_ast.DHyphens: {
Edge: {prefix: MsPrefix, withoutPrefix: v{79, 0, 0}},
Firefox: {prefix: MozPrefix, withoutPrefix: v{43, 0, 0}},
IE: {prefix: MsPrefix},
IOS: {prefix: WebkitPrefix},
Safari: {prefix: WebkitPrefix},
},
// https://caniuse.com/css-initial-letter
css_ast.DInitialLetter: {
IOS: {prefix: WebkitPrefix},
Safari: {prefix: WebkitPrefix},
},
css_ast.DMaskImage: cssMaskPrefixTable, // https://caniuse.com/mdn-css_properties_mask-image
css_ast.DMaskOrigin: cssMaskPrefixTable, // https://caniuse.com/mdn-css_properties_mask-origin
css_ast.DMaskPosition: cssMaskPrefixTable, // https://caniuse.com/mdn-css_properties_mask-position
css_ast.DMaskRepeat: cssMaskPrefixTable, // https://caniuse.com/mdn-css_properties_mask-repeat
css_ast.DMaskSize: cssMaskPrefixTable, // https://caniuse.com/mdn-css_properties_mask-size
// https://caniuse.com/css-sticky
css_ast.DPosition: {
IOS: {prefix: WebkitPrefix, withoutPrefix: v{13, 0, 0}},
Safari: {prefix: WebkitPrefix, withoutPrefix: v{13, 0, 0}},
},
// https://caniuse.com/css-color-adjust
css_ast.DPrintColorAdjust: {
Chrome: {prefix: WebkitPrefix},
Edge: {prefix: WebkitPrefix},
Opera: {prefix: WebkitPrefix},
Safari: {prefix: WebkitPrefix, withoutPrefix: v{15, 4, 0}},
},
// https://caniuse.com/css3-tabsize
css_ast.DTabSize: {
Firefox: {prefix: MozPrefix, withoutPrefix: v{91, 0, 0}},
Opera: {prefix: OPrefix, withoutPrefix: v{15, 0, 0}},
},
// https://caniuse.com/mdn-css_properties_text-decoration-color
css_ast.DTextDecorationColor: {
Firefox: {prefix: MozPrefix, withoutPrefix: v{36, 0, 0}},
IOS: {prefix: WebkitPrefix, withoutPrefix: v{12, 2, 0}},
Safari: {prefix: WebkitPrefix, withoutPrefix: v{12, 1, 0}},
},
// https://caniuse.com/mdn-css_properties_text-decoration-line
css_ast.DTextDecorationLine: {
Firefox: {prefix: MozPrefix, withoutPrefix: v{36, 0, 0}},
IOS: {prefix: WebkitPrefix, withoutPrefix: v{12, 2, 0}},
Safari: {prefix: WebkitPrefix, withoutPrefix: v{12, 1, 0}},
},
// https://caniuse.com/mdn-css_properties_text-decoration-skip
css_ast.DTextDecorationSkip: {
IOS: {prefix: WebkitPrefix, withoutPrefix: v{12, 2, 0}},
Safari: {prefix: WebkitPrefix, withoutPrefix: v{12, 1, 0}},
},
css_ast.DTextEmphasisColor: cssTextEmphasisTable, // https://caniuse.com/mdn-css_properties_text-emphasis-color
css_ast.DTextEmphasisPosition: cssTextEmphasisTable, // https://caniuse.com/mdn-css_properties_text-emphasis-position
css_ast.DTextEmphasisStyle: cssTextEmphasisTable, // https://caniuse.com/mdn-css_properties_text-emphasis-style
// https://caniuse.com/css-text-orientation
css_ast.DTextOrientation: {
Safari: {prefix: WebkitPrefix, withoutPrefix: v{14, 0, 0}},
},
// https://caniuse.com/text-size-adjust
css_ast.DTextSizeAdjust: {
Edge: {prefix: MsPrefix, withoutPrefix: v{79, 0, 0}},
IOS: {prefix: WebkitPrefix},
},
// https://caniuse.com/mdn-css_properties_user-select
css_ast.DUserSelect: {
Chrome: {prefix: WebkitPrefix, withoutPrefix: v{54, 0, 0}},
Edge: {prefix: MsPrefix, withoutPrefix: v{79, 0, 0}},
Firefox: {prefix: MozPrefix, withoutPrefix: v{69, 0, 0}},
IOS: {prefix: WebkitPrefix},
Opera: {prefix: WebkitPrefix, withoutPrefix: v{41, 0, 0}},
Safari: {prefix: WebkitPrefix},
IE: {prefix: MsPrefix},
},
}
func CSSPrefixData(constraints map[Engine][]int) (entries map[css_ast.D]CSSPrefix) {
for property, engines := range cssPrefixTable {
prefixes := NoPrefix
for engine, version := range constraints {
if !engine.IsBrowser() {
// Specifying "--target=es2020" shouldn't affect CSS
continue
}
if data, ok := engines[engine]; ok && (data.withoutPrefix == v{} || compareVersions(data.withoutPrefix, version) > 0) {
prefixes |= data.prefix
}
}
if prefixes != NoPrefix {
if entries == nil {
entries = make(map[css_ast.D]CSSPrefix)
}
entries[property] = prefixes
}
}
return
}