forked from FormidableLabs/radium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
keyframes.js
38 lines (35 loc) · 1.01 KB
/
keyframes.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
/* @flow */
import cssRuleSetToString from './css-rule-set-to-string';
import hash from './hash';
import {getPrefixedKeyframes} from './prefixer';
export type Keyframes = {
__radiumKeyframes: boolean,
__process(userAgent?: string): {animationName: string, css: string}
};
export default function keyframes(
keyframeRules: {[percentage: string]: {[key: string]: string | number}},
name?: string
): Keyframes {
return {
__radiumKeyframes: true,
__process(userAgent) {
const keyframesPrefixed = getPrefixedKeyframes(userAgent);
const rules = Object.keys(keyframeRules)
.map(percentage =>
cssRuleSetToString(percentage, keyframeRules[percentage], userAgent)
)
.join('\n');
const animationName =
(name ? name + '-' : '') + 'radium-animation-' + hash(rules);
const css =
'@' +
keyframesPrefixed +
' ' +
animationName +
' {\n' +
rules +
'\n}\n';
return {css, animationName};
}
};
}