-
-
Notifications
You must be signed in to change notification settings - Fork 700
/
getDefaultStyleValue.js
47 lines (44 loc) · 1.29 KB
/
getDefaultStyleValue.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
/* eslint-disable no-plusplus */
const DIRECTIONAL_FALLBACKS = {
Top: ['Vertical', ''],
Bottom: ['Vertical', ''],
Vertical: [''],
Left: ['Horizontal', ''],
Right: ['Horizontal', ''],
Horizontal: [''],
};
const DIRECTIONAL_SUFFICES = Object.keys(DIRECTIONAL_FALLBACKS);
export default function getDefaultStyleValue(key, flatStyle) {
if (key === 'backgroundColor') {
return 'rgba(0,0,0,0)';
}
if (key === 'color' || key.indexOf('Color') !== -1) {
return 'rgba(0,0,0,1)';
}
if (key.indexOf('rotate') === 0 || key.indexOf('skew') === 0) {
return '0deg';
}
if (key === 'opacity' || key.indexOf('scale') === 0) {
return 1;
}
if (key === 'fontSize') {
return 14;
}
if (key.indexOf('margin') === 0 || key.indexOf('padding') === 0) {
for (let suffix, i = 0; i < DIRECTIONAL_SUFFICES.length; i++) {
suffix = DIRECTIONAL_SUFFICES[i];
if (key.substr(-suffix.length) === suffix) {
const prefix = key.substr(0, key.length - suffix.length);
const fallbacks = DIRECTIONAL_FALLBACKS[suffix];
for (let fallback, j = 0; j < fallbacks.length; j++) {
fallback = prefix + fallbacks[j];
if (fallback in flatStyle) {
return flatStyle[fallback];
}
}
break;
}
}
}
return 0;
}