mirror of
https://github.com/less/less.js.git
synced 2026-01-23 14:18:00 -05:00
improved alpha channel handling for math ops, removed 'can't substract or divide a color from a number' constraint
This commit is contained in:
@@ -70,16 +70,12 @@ tree.Color.prototype = {
|
||||
// we create a new Color node to hold the result.
|
||||
//
|
||||
operate: function (env, op, other) {
|
||||
var result = [];
|
||||
|
||||
if (! (other instanceof tree.Color)) {
|
||||
other = other.toColor();
|
||||
}
|
||||
|
||||
var rgb = [];
|
||||
var alpha = this.alpha * (1 - other.alpha) + other.alpha;
|
||||
for (var c = 0; c < 3; c++) {
|
||||
result[c] = tree.operate(env, op, this.rgb[c], other.rgb[c]);
|
||||
rgb[c] = tree.operate(env, op, this.rgb[c], other.rgb[c]);
|
||||
}
|
||||
return new(tree.Color)(result, this.alpha + other.alpha);
|
||||
return new(tree.Color)(rgb, alpha);
|
||||
},
|
||||
|
||||
toRGB: function () {
|
||||
|
||||
@@ -12,17 +12,14 @@ tree.Operation.prototype = {
|
||||
},
|
||||
eval: function (env) {
|
||||
var a = this.operands[0].eval(env),
|
||||
b = this.operands[1].eval(env),
|
||||
temp;
|
||||
b = this.operands[1].eval(env);
|
||||
|
||||
if (env.isMathOn()) {
|
||||
if (a instanceof tree.Dimension && b instanceof tree.Color) {
|
||||
if (this.op === '*' || this.op === '+') {
|
||||
temp = b, b = a, a = temp;
|
||||
} else {
|
||||
throw { type: "Operation",
|
||||
message: "Can't substract or divide a color from a number" };
|
||||
}
|
||||
a = a.toColor();
|
||||
}
|
||||
if (b instanceof tree.Dimension && a instanceof tree.Color) {
|
||||
b = b.toColor();
|
||||
}
|
||||
if (!a.operate) {
|
||||
throw { type: "Operation",
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
.a {
|
||||
prop: (3 / #fff);
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
OperationError: Can't substract or divide a color from a number in {path}color-operation-error.less on line null, column 0:
|
||||
1 prop: (3 / #fff);
|
||||
Reference in New Issue
Block a user