-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
75 lines (65 loc) · 1.61 KB
/
index.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
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
/**
* Module dependencies.
*/
var whitespace = require('css-whitespace');
var mixins = require('rework-mixins');
var rework = require('rework');
var props = rework.properties;
/**
* Expose `Style`.
*/
module.exports = Style;
/**
* Initialize a new Style with the given css `str`.
*
* Options:
*
* - `whitespace` utilize css whitespace transformations
* - `compress` enable output compression
*
* @param {String} str
* @param {Object} options
* @api public
*/
function Style(str, options) {
if (!(this instanceof Style)) return new Style(str, options);
options = options || {};
if (options.whitespace) str = whitespace(str);
this.str = str;
this.compress = options.compress;
this.rework = rework(str);
this.delegate(['vendors', 'use']);
this.vendors(['-ms-', '-moz-', '-webkit-']);
}
/**
* Delegate `methods` to rework.
*
* @param {Array} methods
* @api private
*/
Style.prototype.delegate = function(methods){
var self = this;
methods.forEach(function(method){
self[method] = self.rework[method].bind(self.rework);
});
};
/**
* Return the compiled CSS.
*
* @return {String}
* @api public
*/
Style.prototype.toString = function(){
this.use(rework.mixin(mixins));
this.use(rework.keyframes());
this.use(rework.ease());
this.use(rework.prefixValue('linear-gradient'));
this.use(rework.prefixValue('radial-gradient'));
this.use(rework.prefixValue('transform'));
this.use(rework.prefix(props));
this.use(rework.colors());
this.use(rework.references());
this.use(rework.at2x());
this.use(rework.extend());
return this.rework.toString({ compress: this.compress });
};