-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
129 lines (114 loc) · 4.4 KB
/
index.js
File metadata and controls
129 lines (114 loc) · 4.4 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
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
const _ = require('lodash');
const Color = require('color');
module.exports = function() {
return ({ theme, e, addComponents }) => {
const defaultBgColors = {};
const pulseBgColors = theme('pulse.colors', defaultBgColors);
function returnColorPair([modifier, value]) {
const rgb = Color(value).rgb().array();
const pulseModifier = modifier.replace(/^\./, '');
return [
`${modifier}`,
{
boxShadow: "0 0 0 0 rgba(" + rgb[0] + ", " + rgb[1] +", " + rgb[2] + ", 1)",
transform: "scale(1)",
animation: `${pulseModifier} 2s infinite`
}
];
}
function returnKeyFrames([modifier, value]) {
const rgb = Color(value).rgb().array();
const pulseModifier = modifier.replace(/^\./, '');
return [
`@keyframes ${pulseModifier}`,
{
"0%": {
transform: "scale(0.95)",
boxShadow: "0 0 0 0 rgba(" + rgb[0] + ", " + rgb[1] +", " + rgb[2] + ", 0.7)"
},
"70%": {
transform: "scale(1)",
boxShadow: "0 0 0 10px rgba(" + rgb[0] + ", " + rgb[1] +", " + rgb[2] + ", 0)"
},
"100%": {
transform: "scale(0.95)",
boxShadow: "0 0 0 0 rgba(" + rgb[0] + ", " + rgb[1] +", " + rgb[2] + ", 0)"
}
}
];
}
function returnShadowColorPair([modifier, value]) {
const rgb = Color(value).rgb().array();
const shadowModifier = modifier.replace(/^\./, '');
return [
`${modifier}`,
{
filter: "drop-shadow(0 0 0 rgba(" + rgb[0] + ", " + rgb[1] +", " + rgb[2] + ", .4))",
animation: `${shadowModifier} 2s infinite`
}
];
}
function returnShadowKeyFrames([modifier, value]) {
const rgb = Color(value).rgb().array();
const shadowModifier = modifier.replace(/^\./, '');
return [
`@keyframes ${shadowModifier}`,
{
"0%": {
filter: "drop-shadow(0 0 0 rgba(" + rgb[0] + ", " + rgb[1] +", " + rgb[2] + ", 0.6))"
},
"50%": {
filter: "drop-shadow(0 0 .75rem rgba(" + rgb[0] + ", " + rgb[1] +", " + rgb[2] + ", 0.8))"
}
}
];
}
const allTheColors = _(pulseBgColors)
.flatMap((value, modifier) => {
if (typeof value == 'object') {
return _.map(value, (v, m) => {
return [`.${e(`pulse-${modifier}-${m}`)}`, v];
});
}
try {
Color(value)
} catch (err) {
return [];
}
return [[`.${e(`pulse-${modifier}`)}`, value]];
})
.value();
const allTheShadowColors = _(pulseBgColors)
.flatMap((value, modifier) => {
if (typeof value == 'object') {
return _.map(value, (v, m) => {
return [`.${e(`shadow-pulse-${modifier}-${m}`)}`, v];
});
}
try {
Color(value)
} catch (err) {
return [];
}
return [[`.${e(`shadow-pulse-${modifier}`)}`, value]];
})
.value();
const components = _.fromPairs(
_.concat(
_.map(allTheColors, (color, index) => {
return returnColorPair(color);
}),
_.map(allTheColors, (color, index) => {
return returnKeyFrames(color);
}),
_.map(allTheShadowColors, (color, index) => {
return returnShadowColorPair(color);
}),
_.map(allTheShadowColors, (color, index) => {
return returnShadowKeyFrames(color);
})
)
);
addComponents(components);
};
};