diff --git a/lib/less/node/color.js b/lib/less/node/color.js index ad18cba..42ee22c 100644 --- a/lib/less/node/color.js +++ b/lib/less/node/color.js @@ -21,31 +21,14 @@ node.Color.prototype = { return Math.round(i).toString(16); }).join(''); }, - '+': function (other) { + operate: function (op, other) { var result = []; - for (var c = 0; c < 3; c++) { - result[c] = this.value[c] + other.value[c]; - } - return new(node.Color)(result); - }, - '-': function (other) { - var result = []; - for (var c = 0; c < 3; c++) { - result[c] = this.value[c] - other.value[c]; + if (! (other instanceof node.Color)) { + other = other.toColor(); } - return new(node.Color)(result); - }, - '*': function (other) { - var result = []; - for (var c = 0; c < 3; c++) { - result[c] = this.value[c] * other.value[c]; - } - return new(node.Color)(result); - }, - '/': function (other) { - var result = []; + for (var c = 0; c < 3; c++) { - result[c] = this.value[c] / other.value[c]; + result[c] = node.operate(op, this.value[c], other.value[c]); } return new(node.Color)(result); } diff --git a/lib/less/node/dimension.js b/lib/less/node/dimension.js index 501c18f..80049b3 100644 --- a/lib/less/node/dimension.js +++ b/lib/less/node/dimension.js @@ -6,25 +6,17 @@ node.Dimension = function Dimension(value, unit) { node.Dimension.prototype = { eval: function () { return this }, + toColor: function () { + return new(node.Color)([this.value, this.value, this.value]); + }, toCSS: function () { var css = this.value + this.unit; return css; }, - '+': function (other) { - return new(node.Dimension) - (this.value + other.value, this.unit); - }, - '-': function (other) { - return new(node.Dimension) - (this.value - other.value, this.unit); - }, - '*': function (other) { - return new(node.Dimension) - (this.value * other.value, this.unit); - }, - '/': function (other) { + operate: function (op, other) { return new(node.Dimension) - (this.value / other.value, this.unit); + (node.operate(op, this.value, other.value), + this.unit); } };