2010-03-13 16:34:48 +08:00
|
|
|
if (typeof(require) !== 'undefined') { var tree = require('less/tree') }
|
2010-02-24 02:39:05 +08:00
|
|
|
|
2010-03-24 06:33:17 +08:00
|
|
|
//
|
|
|
|
// A number with a unit
|
|
|
|
//
|
2010-03-02 04:32:21 +08:00
|
|
|
tree.Dimension = function Dimension(value, unit) {
|
2010-02-24 02:39:05 +08:00
|
|
|
this.value = parseFloat(value);
|
|
|
|
this.unit = unit || null;
|
|
|
|
};
|
|
|
|
|
2010-03-02 04:32:21 +08:00
|
|
|
tree.Dimension.prototype = {
|
2010-02-24 02:39:05 +08:00
|
|
|
eval: function () { return this },
|
2010-02-27 11:30:30 +08:00
|
|
|
toColor: function () {
|
2010-03-02 04:32:21 +08:00
|
|
|
return new(tree.Color)([this.value, this.value, this.value]);
|
2010-02-27 11:30:30 +08:00
|
|
|
},
|
2010-02-24 02:39:05 +08:00
|
|
|
toCSS: function () {
|
|
|
|
var css = this.value + this.unit;
|
|
|
|
return css;
|
|
|
|
},
|
2010-03-24 06:33:17 +08:00
|
|
|
|
|
|
|
// In an operation between two Dimensions,
|
|
|
|
// we default to the first Dimension's unit,
|
|
|
|
// so `1px + 2em` will yield `3px`.
|
|
|
|
// In the future, we could implement some unit
|
|
|
|
// conversions such that `100cm + 10mm` would yield
|
|
|
|
// `101cm`.
|
2010-02-27 11:30:30 +08:00
|
|
|
operate: function (op, other) {
|
2010-03-02 04:32:21 +08:00
|
|
|
return new(tree.Dimension)
|
|
|
|
(tree.operate(op, this.value, other.value),
|
2010-03-06 02:36:24 +08:00
|
|
|
this.unit || other.unit);
|
2010-02-24 02:39:05 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|