forked from kaelzhang/neuron.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss.js
More file actions
147 lines (112 loc) · 3.21 KB
/
css.js
File metadata and controls
147 lines (112 loc) · 3.21 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
var
Fx = require('./core'),
// atom
ATOM_ALREADY_COMPUTED = {},
makeArray = NR.makeArray,
PARSERS = {
Color: {
parse: function(value){
if (value.match(/^#[0-9a-f]{3,6}$/i)) return value.hexToRgb(true);
return ((value = value.match(/(\d+),\s*(\d+),\s*(\d+)/))) ? [value[1], value[2], value[3]] : false;
},
compute: function(from, to, progress){
return from.map(function(value, i){
return Math.round(Fx.compute(from[i], to[i], progress));
});
},
serve: function(value){
return value.map(Number);
}
},
Number: {
parse: parseFloat,
compute: Fx.compute,
serve: function(value, unit){
return (unit) ? value + unit : value;
}
},
String: {
parse: function(){
return false;
},
compute: function(zero, one){
return one;
},
serve: function(zero){
return zero;
}
}
},
/**
* @interface
* @private
* FxCSS could not be used alone. please implement it
*/
FxCSS = {
// prepares the base from/to object
_prepare: function(element, property, args){
var style, parsed;
// [100, 1000]
args = makeArray(args);
if (args[1] == null){
args[1] = args[0];
style = element.css(property);
args[0] = style === 'auto' ? 0 : style;
}
parsed = args.map(this._parse);
return {
from: parsed[0],
to: parsed[1]
};
},
// parses a value into an array
_parse: function(value){
value = String( NR.isFunction(value) ? value() : value );
var found,
parsers = PARSERS,
parser,
key,
parsed;
for(key in parsers){
parser = parsers[key];
parsed = parser.parse(value);
if (parsed || parsed === 0){
found = {
value: parsed,
parser: parser
};
break;
}
}
found = found || {
value: value,
parser: PARSERS.String
};
return found;
},
// computes by a from and to prepared objects, using their parsers.
_compute: function(from, to, progress){
return {
_: ATOM_ALREADY_COMPUTED,
value: from.parser.compute(from.value, to.value, progress),
parser: from.parser
};
},
// serves the value as settable
_serve: function(sprite, unit){
if (sprite._ !== ATOM_ALREADY_COMPUTED){
sprite = this._parse(sprite);
}
return sprite.parser.serve(sprite.value, unit);
},
// renders the change to an element
_render: function(element, property, value, unit){
element.css(property, this._serve(value, unit));
}
};
module.exports = FxCSS;
/**
change log:
2011-10-19 Kael:
- refractor Fx.CSS. Fx.CSS is now a extension of Fx.Tween or Fx.Morph
*/