[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | exports.addon = function (renderer, config) {
|
---|
| 4 | if (process.env.NODE_ENV !== 'production') {
|
---|
| 5 | require('./__dev__/warnOnMissingDependencies')('keyframes', renderer, ['putRaw', 'put']);
|
---|
| 6 | }
|
---|
| 7 |
|
---|
| 8 | config = renderer.assign({
|
---|
| 9 | prefixes: ['-webkit-', '-moz-', '-o-', ''],
|
---|
| 10 | }, config || {});
|
---|
| 11 |
|
---|
| 12 | var prefixes = config.prefixes;
|
---|
| 13 |
|
---|
| 14 | if (renderer.client) {
|
---|
| 15 | // Craete @keyframe Stylesheet `ksh`.
|
---|
| 16 | document.head.appendChild(renderer.ksh = document.createElement('style'));
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | var putAt = renderer.putAt;
|
---|
| 20 |
|
---|
| 21 | renderer.putAt = function (__, keyframes, prelude) {
|
---|
| 22 | // @keyframes
|
---|
| 23 | if (prelude[1] === 'k') {
|
---|
| 24 | var str = '';
|
---|
| 25 |
|
---|
| 26 | for (var keyframe in keyframes) {
|
---|
| 27 | var decls = keyframes[keyframe];
|
---|
| 28 | var strDecls = '';
|
---|
| 29 |
|
---|
| 30 | for (var prop in decls)
|
---|
| 31 | strDecls += renderer.decl(prop, decls[prop]);
|
---|
| 32 |
|
---|
| 33 | str += keyframe + '{' + strDecls + '}';
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | for (var i = 0; i < prefixes.length; i++) {
|
---|
| 37 | var prefix = prefixes[i];
|
---|
| 38 | var rawKeyframes = prelude.replace('@keyframes', '@' + prefix + 'keyframes') + '{' + str + '}';
|
---|
| 39 |
|
---|
| 40 | if (renderer.client) {
|
---|
| 41 | renderer.ksh.appendChild(document.createTextNode(rawKeyframes));
|
---|
| 42 | } else {
|
---|
| 43 | renderer.putRaw(rawKeyframes);
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | return;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | putAt(__, keyframes, prelude);
|
---|
| 51 | };
|
---|
| 52 |
|
---|
| 53 | renderer.keyframes = function (keyframes, block) {
|
---|
| 54 | if (!block) block = renderer.hash(keyframes);
|
---|
| 55 | block = renderer.pfx + block;
|
---|
| 56 |
|
---|
| 57 | renderer.putAt('', keyframes, '@keyframes ' + block);
|
---|
| 58 |
|
---|
| 59 | return block;
|
---|
| 60 | };
|
---|
| 61 | };
|
---|