-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathfixtures.js
135 lines (125 loc) · 5.1 KB
/
fixtures.js
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
import {getSupport, detectBrowser, getVersionIndex} from 'caniuse-support'
import autoprefixer from 'autoprefixer'
import data from 'autoprefixer/data/prefixes'
import postcssJs from 'postcss-js'
const currentBrowser = detectBrowser(window.navigator.userAgent)
const browserQuery = `${currentBrowser.id} ${getVersionIndex(currentBrowser)}`
const ap = autoprefixer({overrideBrowserslist: browserQuery})
const prefixer = postcssJs.sync([ap])
const skipProperties = [
// Caniuse doesn't cover this property and spec might drop this: https://www.w3.org/TR/css-fonts-3/.
'font-language-override',
// Caniuse doesn't cover those properties.
'grid-row-align',
'grid-column-align',
// Lack of caniuse data. See https://github.com/Fyrd/caniuse/issues/2116.
'font-variant-ligatures'
]
const notDescribedCanIUseProps = ['css3-cursors-grab', 'css-text-spacing']
const gridProps = [
'grid-template-columns',
'grid-template-rows',
'grid-row-start',
'grid-column-start',
'grid-row-end',
'grid-column-end',
'grid-row',
'grid-column',
'grid-area',
'grid-template',
'grid-template-areas'
]
const flexOldUnsupported = ['flex-shrink', 'flex-basis', 'flex-wrap', 'align-self', 'align-content']
const flexOldFFUnsupported = ['flex-wrap', 'flex-flow', 'align-content']
const msSnapPointsUnsupported = ['scroll-snap-coordinate', 'scroll-snap-destination']
const breakProps = ['break-before', 'break-inside', 'break-after']
// In caniuse db, no supported value/prop means spec does not support it, but
// no support in css-vendor implies no browser support at all for the
// particular property. Therefore we cannot test the caniuse data for these cases.
const isExcluded = o =>
o.level === 'none' ||
// https://caniuse.com/#search=object-fit
o.property === 'object-position' ||
// https://caniuse.com/#search=multicolumn
// https://bugzilla.mozilla.org/show_bug.cgi?id=616436
(o.property === 'column-span' && currentBrowser.id === 'firefox') ||
o.property === 'column-fill' ||
// https://caniuse.com/#search=css-masks
/^mask-/.test(o.property) ||
// https://caniuse.com/#search=text-decoration
o.property === 'text-decoration' ||
o.property === 'text-decoration-skip' ||
o.property === 'text-decoration-style' ||
o.property === 'text-decoration-skip-ink' ||
// https://caniuse.com/#search=css-crisp-edges
o.property === 'image-rendering' ||
// https://caniuse.com/#search=css-logical-props
/^(border|margin|padding)-(block|inline)-(start|end)/.test(o.property) ||
// https://caniuse.com/#search=flexbox
flexOldUnsupported.indexOf(o.property) > -1 ||
flexOldFFUnsupported.indexOf(o.property) > -1 ||
skipProperties.indexOf(o.property) > -1 ||
// https://caniuse.com/#search=grid
gridProps.indexOf(o.property) > -1 ||
// css-vendor will prefix writing-mode anyway
o.property === 'writing-mode' ||
// https://caniuse.com/#search=css-snappoints
msSnapPointsUnsupported.indexOf(o.property) > -1 ||
// https://caniuse.com/#search=css-regions
o.property === 'region-fragment' ||
// We do not detect browser version or platform. We can't support
// font-kerning, clip-path, becayse they have different prefix rules for
// same browsers family (like Webkit) on different platforms.
// https://caniuse.com/#search=font-kerning
// https://caniuse.com/#search=clip-path
o.property === 'font-kerning' ||
o.property === 'clip-path' ||
// Something similar happened for a filter. Prefix rules for this
// property changed within the time (Chrome)
// https://caniuse.com/#search=filter
o.property === 'filter' ||
o.property === 'place-self' ||
// Skipping because we still prefixing user-select for Firefox,
// but Firefox >= 69 not require prefix for this property.
// https://caniuse.com/#search=user-select
(o.property === 'user-select' && currentBrowser.id === 'firefox') ||
breakProps.indexOf(o.property) > -1
// Some properties need a certain value, so autoprefixer will prefix them.
const propertyValue = p => (/^grid-(column|row)-end/.test(p) ? 'span 3' : '')
const dashify = str =>
str
.replace(/([A-Z])/g, '-$1')
.replace(/^ms-/, '-ms-')
.toLowerCase()
function generateFixture() {
const fixture = {}
Object.keys(data)
// Filters autoprefixer data to include only property prefix related entries.
.filter(
s =>
/^[^:@].*$/.test(s) &&
data[s].props === undefined &&
notDescribedCanIUseProps.indexOf(data[s].feature) < 0
)
// Add data from caniuse-db.
.map(s => ({
property: s,
feature: data[s].feature,
...getSupport(data[s].feature, currentBrowser)
}))
// Exclude unnecessary properties.
.filter(o => !isExcluded(o))
.forEach(o => {
// Current properties.
let properties = Object.keys(
prefixer({
[o.property]: propertyValue(o.property)
})
).map(dashify)
// Remove unprefixed prop (last in array) when prefix is needed.
properties = properties.length > 1 ? properties.slice(0, properties.length - 1) : properties
fixture[o.property] = properties.length === 1 ? properties[0] : properties
})
return fixture
}
export default generateFixture()