/
isAutoprefixable.mjs
370 lines (356 loc) · 8.12 KB
/
isAutoprefixable.mjs
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
import vendor from './vendor.mjs';
/**
* Extract each list using the internal API of Autoprefixer 10.2.5.
*
* @see https://github.com/postcss/autoprefixer/tree/10.2.5
*
* @example
* const autoprefixer = require('autoprefixer');
* const Browsers = require('autoprefixer/lib/browsers');
* const Prefixes = require('autoprefixer/lib/prefixes');
* const utils = require('autoprefixer/lib/utils');
*
* const prefixes = new Prefixes(autoprefixer.data.prefixes, new Browsers(autoprefixer.data.browsers, []));
*/
/**
* @example
* Object.keys(prefixes.remove).filter((s) => s.startsWith('@'));
*/
const AT_RULES = new Set([
'@-khtml-keyframes',
'@-moz-keyframes',
'@-ms-keyframes',
'@-ms-viewport',
'@-o-keyframes',
'@-o-viewport',
'@-webkit-keyframes',
'@resolution',
]);
/**
* @example
* prefixes.remove.selectors.map((s) => s.prefixed);
*/
const SELECTORS = new Set([
':-moz-any-link',
':-moz-full-screen',
':-moz-placeholder',
':-moz-placeholder-shown',
':-moz-read-only',
':-moz-read-write',
':-ms-fullscreen',
':-ms-input-placeholder',
':-webkit-any-link',
':-webkit-full-screen',
'::-moz-placeholder',
'::-moz-selection',
'::-ms-input-placeholder',
'::-webkit-backdrop',
'::-webkit-input-placeholder',
]);
/**
* @example
* Object.entries(autoprefixer.data.prefixes)
* .filter(([key, value]) => !value.selector && !value.props && !key.startsWith('@'))
* .map(([key, value]) => key);
*/
const PROPERTIES = new Set([
'align-content',
'align-items',
'align-self',
'animation',
'animation-delay',
'animation-direction',
'animation-duration',
'animation-fill-mode',
'animation-iteration-count',
'animation-name',
'animation-play-state',
'animation-timing-function',
'appearance',
'backdrop-filter',
'backface-visibility',
'background-clip',
'background-origin',
'background-size',
'border-block-end',
'border-block-start',
'border-bottom-left-radius',
'border-bottom-right-radius',
'border-image',
'border-inline-end',
'border-inline-start',
'border-radius',
'border-top-left-radius',
'border-top-right-radius',
'box-decoration-break',
'box-shadow',
'box-sizing',
'break-after',
'break-before',
'break-inside',
'clip-path',
'color-adjust',
'column-count',
'column-fill',
'column-gap',
'column-rule',
'column-rule-color',
'column-rule-style',
'column-rule-width',
'column-span',
'column-width',
'columns',
'filter',
'flex',
'flex-basis',
'flex-direction',
'flex-flow',
'flex-grow',
'flex-shrink',
'flex-wrap',
'flow-from',
'flow-into',
'font-feature-settings',
'font-kerning',
'font-language-override',
'font-variant-ligatures',
'grid-area',
'grid-column',
'grid-column-align',
'grid-column-end',
'grid-column-start',
'grid-row',
'grid-row-align',
'grid-row-end',
'grid-row-start',
'grid-template',
'grid-template-areas',
'grid-template-columns',
'grid-template-rows',
'hyphens',
'image-rendering',
'justify-content',
'margin-block-end',
'margin-block-start',
'margin-inline-end',
'margin-inline-start',
'mask',
'mask-border',
'mask-border-outset',
'mask-border-repeat',
'mask-border-slice',
'mask-border-source',
'mask-border-width',
'mask-clip',
'mask-composite',
'mask-image',
'mask-origin',
'mask-position',
'mask-repeat',
'mask-size',
'object-fit',
'object-position',
'order',
'overscroll-behavior',
'padding-block-end',
'padding-block-start',
'padding-inline-end',
'padding-inline-start',
'perspective',
'perspective-origin',
'place-self',
'region-fragment',
'scroll-snap-coordinate',
'scroll-snap-destination',
'scroll-snap-points-x',
'scroll-snap-points-y',
'scroll-snap-type',
'shape-image-threshold',
'shape-margin',
'shape-outside',
'tab-size',
'text-align-last',
'text-decoration',
'text-decoration-color',
'text-decoration-line',
'text-decoration-skip',
'text-decoration-skip-ink',
'text-decoration-style',
'text-emphasis',
'text-emphasis-color',
'text-emphasis-position',
'text-emphasis-style',
'text-orientation',
'text-overflow',
'text-size-adjust',
'text-spacing',
'touch-action',
'transform',
'transform-origin',
'transform-style',
'transition',
'transition-delay',
'transition-duration',
'transition-property',
'transition-timing-function',
'user-select',
'writing-mode',
]);
/**
* This list is currently being used to compile all the prefixed values that can safely be unprefixed.
* i.e. value-no-vendor-prefix autofix ought to be able to handle it appropriately
* It was initially populated using the following example:
* @example
* Object.values(prefixes.remove)
* .filter((p) => Array.isArray(p.values))
* .flatMap((p) => p.values)
* .map((p) => utils.removeNote(p.prefixed)) // normalize '-webkit- old'
* .filter((p) => !p.endsWith('-')); // remove '-webkit-' only
*
* @see https://github.com/stylelint/stylelint/pull/5312/files#r636018013
*/
const PROPERTY_VALUES = new Set([
'-moz-all',
'-moz-calc',
'-moz-crisp-edges',
'-moz-element',
'-moz-fit-content',
'-moz-grab',
'-moz-grabbing',
'-moz-initial',
'-moz-isolate',
'-moz-isolate-override',
'-moz-linear-gradient',
'-moz-max-content',
'-moz-min-content',
'-moz-pre-wrap',
'-moz-plaintext',
'-moz-radial-gradient',
'-moz-repeating-linear-gradient',
'-moz-repeating-radial-gradient',
'-moz-zoom-in',
'-moz-zoom-out',
'-ms-flexbox',
'-ms-grid',
'-ms-inline-grid',
'-ms-linear-gradient',
'-ms-radial-gradient',
'-ms-repeating-linear-gradient',
'-ms-repeating-radial-gradient',
'-o-crisp-edges',
'-o-linear-gradient',
'-o-pre-wrap',
'-o-radial-gradient',
'-o-repeating-linear-gradient',
'-o-repeating-radial-gradient',
'-webkit-calc',
'-webkit-cross-fade',
'-webkit-filter',
'-webkit-fit-content',
'-webkit-flex',
'-webkit-grab',
'-webkit-grabbing',
'-webkit-image-set',
'-webkit-inline-flex',
'-webkit-isolate',
'-webkit-linear-gradient',
'-webkit-max-content',
'-webkit-min-content',
'-webkit-plaintext',
'-webkit-radial-gradient',
'-webkit-repeating-linear-gradient',
'-webkit-repeating-radial-gradient',
'-webkit-sticky',
'-webkit-zoom-in',
'-webkit-zoom-out',
'-xv-digits',
'-xv-literal-punctuation',
'-xv-no-punctuation',
// Firefox does not support
// ethiopic-halehame, ethiopic-halehame-am, ethiopic-halehame-ti-er and ethiopic-halehame-ti-et
// without a -moz- prefix
// see https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type
'-moz-arabic-indic',
'-moz-bengali',
'-moz-cjk-earthly-branch',
'-moz-cjk-heavenly-stem',
'-moz-devanagari',
'-moz-ethiopic-numeric',
'-moz-gujarati',
'-moz-gurmukhi',
'-moz-hangul',
'-moz-hangul-consonant',
'-moz-japanese-formal',
'-moz-japanese-informal',
'-moz-kannada',
'-moz-khmer',
'-moz-lao',
'-moz-malayalam',
'-moz-myanmar',
'-moz-oriya',
'-moz-persian',
'-moz-simp-chinese-formal',
'-moz-simp-chinese-informal',
'-moz-tamil',
'-moz-telugu',
'-moz-thai',
'-moz-trad-chinese-formal',
'-moz-trad-chinese-informal',
]);
/**
* Most identifier types have to be looked up in a unique way,
* so we're exposing special functions for each.
*/
export default {
/**
* @param {string} identifier
* @returns {boolean}
*/
atRuleName(identifier) {
return AT_RULES.has(`@${identifier.toLowerCase()}`);
},
/**
* @param {string} identifier
* @returns {boolean}
*/
selector(identifier) {
return SELECTORS.has(identifier.toLowerCase());
},
/**
* @param {string} identifier
* @returns {boolean}
*/
mediaFeatureName(identifier) {
return identifier.toLowerCase().includes('device-pixel-ratio');
},
/**
* @param {string} identifier
* @returns {boolean}
*/
property(identifier) {
const ident = identifier.toLowerCase();
// HACK: `interpolation-mode` does not exist. This is an IE extension for `image-rendering`.
// See <https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering#examples>
if (ident === '-ms-interpolation-mode') {
return true;
}
if (vendor.prefix(ident).length === 0) {
return false;
}
return PROPERTIES.has(vendor.unprefixed(ident));
},
/**
* @param {string} value
* @returns {boolean}
*/
propertyValue(value) {
return PROPERTY_VALUES.has(value.toLowerCase());
},
/**
* @param {string} value
* @returns {string}
*/
unprefix(value) {
return value.replace(/-\w+-/, '');
},
};