-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
58 lines (48 loc) · 1.04 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
/**
* Module dependencies.
*/
var visit = require('rework-visit');
/**
* Provide property reference support.
*
* button {
* width: 50px;
* height: @width;
* line-height: @height;
* }
*
* yields:
*
* button {
* width: 50px;
* height: 50px;
* line-height: 50px;
* }
*
*/
module.exports = function() {
return function(style){
visit(style, substitute);
}
};
/**
* Substitute easing functions.
*
* @api private
*/
function substitute(declarations) {
var map = {};
for (var i = 0, len = declarations.length; i < len; ++i) {
var decl = declarations[i];
var key = decl.property;
var val = decl.value;
if ('comment' == decl.type) continue;
decl.value = val.replace(/@([-\w]+)/g, function(_, name){
// TODO: fix this problem for real with visionmedia/css-value
if ('2x' == name) return '@' + name;
if (null == map[name]) throw new Error('@' + name + ' is not defined in this scope');
return map[name];
});
map[key] = decl.value;
}
}