-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathgeneratePrefixMap.js
More file actions
93 lines (79 loc) · 2.11 KB
/
generatePrefixMap.js
File metadata and controls
93 lines (79 loc) · 2.11 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
/* @flow */
import { getSupport } from 'caniuse-api'
import propertyMap from './maps/propertyMap'
const prefixBrowserMap = {
chrome: 'Webkit',
safari: 'Webkit',
firefox: 'Moz',
opera: 'Webkit',
ie: 'ms',
edge: 'ms',
ios_saf: 'Webkit',
android: 'Webkit',
and_chr: 'Webkit',
and_uc: 'Webkit',
op_mini: 'Webkit',
ie_mob: 'ms',
}
// remove flexprops from IE
const flexPropsIE = [
'alignContent',
'alignSelf',
'alignItems',
'justifyContent',
'order',
'flexGrow',
'flexShrink',
'flexBasis',
]
function filterAndRemoveIfEmpty(
map: Object,
property: string,
filter: Function
): void {
if (map[property]) {
map[property] = map[property].filter(filter)
if (map[property].length === 0) {
delete map[property]
}
}
}
export default function generatePrefixMap(browserList: Object): Object {
const prefixMap = {}
for (const browser in prefixBrowserMap) {
const prefix = prefixBrowserMap[browser]
for (const keyword in propertyMap) {
const keywordProperties = [].concat(propertyMap[keyword])
const versions = getSupport(keyword)
for (let i = 0, len = keywordProperties.length; i < len; ++i) {
if (versions[browser].x >= browserList[browser]) {
const property = keywordProperties[i]
if (!prefixMap[property]) {
prefixMap[property] = []
}
if (prefixMap[property].indexOf(prefix) === -1) {
prefixMap[property].push(prefix)
}
}
}
}
}
// remove flexProps from IE and Firefox due to alternative syntax
for (let i = 0, len = flexPropsIE.length; i < len; ++i) {
filterAndRemoveIfEmpty(
prefixMap,
flexPropsIE[i],
prefix => prefix !== 'ms' && prefix !== 'Moz'
)
}
// remove transition from Moz and Webkit as they are handled
// specially by the transition plugins
filterAndRemoveIfEmpty(
prefixMap,
'transition',
prefix => prefix !== 'Moz' && prefix !== 'Webkit'
)
// remove WebkitFlexDirection as it does not exist
filterAndRemoveIfEmpty(prefixMap, 'flexDirection', prefix => prefix !== 'Moz')
return prefixMap
}