-
Notifications
You must be signed in to change notification settings - Fork 324
/
compatibility.js
141 lines (127 loc) · 3.55 KB
/
compatibility.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
136
137
138
139
140
141
var util = require('util');
var DEFAULTS = {
'*': {
colors: {
opacity: true // rgba / hsla
},
properties: {
backgroundSizeMerging: false, // background-size to shorthand
colors: true, // any kind of color transformations, like `#ff00ff` to `#f0f` or `#fff` into `red`
iePrefixHack: false, // underscore / asterisk prefix hacks on IE
ieSuffixHack: false, // \9 suffix hacks on IE
merging: true, // merging properties into one
spaceAfterClosingBrace: true, // 'url() no-repeat' to 'url()no-repeat'
urlQuotes: false, // whether to wrap content of `url()` into quotes or not
zeroUnits: true // 0[unit] -> 0
},
selectors: {
adjacentSpace: false, // div+ nav Android stock browser hack
ie7Hack: false, // *+html hack
special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:dir\([a-z-]*\)|:first(?![a-z-])|:fullscreen|:left|:read-only|:read-write|:right)/ // special selectors which prevent merging
},
units: {
ch: true,
rem: true,
vh: true,
vm: true, // vm is vmin on IE9+ see https://developer.mozilla.org/en-US/docs/Web/CSS/length
vmax: true,
vmin: true,
vw: true
}
},
'ie8': {
colors: {
opacity: false
},
properties: {
backgroundSizeMerging: false,
colors: true,
iePrefixHack: true,
ieSuffixHack: true,
merging: false,
spaceAfterClosingBrace: true,
urlQuotes: false,
zeroUnits: true
},
selectors: {
adjacentSpace: false,
ie7Hack: false,
special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:root|:nth|:first\-of|:last|:only|:empty|:target|:checked|::selection|:enabled|:disabled|:not)/
},
units: {
ch: false,
rem: false,
vh: false,
vm: false,
vmax: false,
vmin: false,
vw: false
}
},
'ie7': {
colors: {
opacity: false
},
properties: {
backgroundSizeMerging: false,
colors: true,
iePrefixHack: true,
ieSuffixHack: true,
merging: false,
spaceAfterClosingBrace: true,
urlQuotes: false,
zeroUnits: true
},
selectors: {
adjacentSpace: false,
ie7Hack: true,
special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:focus|:before|:after|:root|:nth|:first\-of|:last|:only|:empty|:target|:checked|::selection|:enabled|:disabled|:not)/
},
units: {
ch: false,
rem: false,
vh: false,
vm: false,
vmax: false,
vmin: false,
vw: false,
}
}
};
function Compatibility(source) {
this.source = source || {};
}
function merge(source, target) {
for (var key in source) {
var value = source[key];
if (typeof value === 'object' && !util.isRegExp(value))
target[key] = merge(value, target[key] || {});
else
target[key] = key in target ? target[key] : value;
}
return target;
}
function calculateSource(source) {
if (typeof source == 'object')
return source;
if (!/[,\+\-]/.test(source))
return DEFAULTS[source] || DEFAULTS['*'];
var parts = source.split(',');
var template = parts[0] in DEFAULTS ?
DEFAULTS[parts.shift()] :
DEFAULTS['*'];
source = {};
parts.forEach(function (part) {
var isAdd = part[0] == '+';
var key = part.substring(1).split('.');
var group = key[0];
var option = key[1];
source[group] = source[group] || {};
source[group][option] = isAdd;
});
return merge(template, source);
}
Compatibility.prototype.toOptions = function () {
return merge(DEFAULTS['*'], calculateSource(this.source));
};
module.exports = Compatibility;