1 |
|
2 |
|
3 | import cssRuleSetToString from './css-rule-set-to-string';
|
4 | import hash from './hash';
|
5 | import {getPrefixedKeyframes} from './prefixer';
|
6 |
|
7 | export type Keyframes = {
|
8 | __radiumKeyframes: boolean,
|
9 | __process(userAgent?: string): {animationName: string, css: string},
|
10 | };
|
11 |
|
12 | export default function keyframes(
|
13 | keyframeRules: {[percentage: string]: {[key: string]: string | number}},
|
14 | name?: string,
|
15 | ): Keyframes {
|
16 | return {
|
17 | __radiumKeyframes: true,
|
18 | __process(userAgent) {
|
19 | const keyframesPrefixed = getPrefixedKeyframes(userAgent);
|
20 | const rules = Object.keys(keyframeRules)
|
21 | .map(percentage =>
|
22 | cssRuleSetToString(percentage, keyframeRules[percentage], userAgent))
|
23 | .join('\n');
|
24 | const animationName = (name ? name + '-' : '') +
|
25 | 'radium-animation-' +
|
26 | hash(rules);
|
27 | const css = '@' +
|
28 | keyframesPrefixed +
|
29 | ' ' +
|
30 | animationName +
|
31 | ' {\n' +
|
32 | rules +
|
33 | '\n}\n';
|
34 | return {css, animationName};
|
35 | },
|
36 | };
|
37 | }
|