From dbf7c5c30c80f583eeaa6874504690bbd1b83cd5 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Thu, 25 Feb 2010 17:54:59 -0500 Subject: [PATCH] per channel color operations. Color can also take an RGB array --- lib/less/node/color.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/less/node/color.js b/lib/less/node/color.js index b4ed6f69..a2fc9f3a 100644 --- a/lib/less/node/color.js +++ b/lib/less/node/color.js @@ -2,7 +2,9 @@ // RGB Colors - #ff0014, #eee // node.Color = function Color(val) { - if (val.length == 6) { + if (Array.isArray(val)) { + this.value = val; + } else if (val.length == 6) { this.value = val.match(/.{2}/g).map(function (c) { return parseInt(c, 16); }); @@ -20,20 +22,32 @@ node.Color.prototype = { }).join(''); }, '+': function (other) { - return new(node.Color) - (this.value + other.value, this.unit); + var result = []; + for (var c = 0; c < 3; c++) { + result[c] = this.value[c] + other.value[c]; + } + return new(node.Color)(result); }, '-': function (other) { - return new(node.Color) - (this.value - other.value, this.unit); + var result = []; + for (var c = 0; c < 3; c++) { + result[c] = this.value[c] - other.value[c]; + } + return new(node.Color)(result); }, '*': function (other) { - return new(node.Color) - (this.value * other.value, this.unit); + var result = []; + for (var c = 0; c < 3; c++) { + result[c] = this.value[c] * other.value[c]; + } + return new(node.Color)(result); }, '/': function (other) { - return new(node.Color) - (this.value / other.value, this.unit); + var result = []; + for (var c = 0; c < 3; c++) { + result[c] = this.value[c] / other.value[c]; + } + return new(node.Color)(result); } };