Throw a more descriptive error for invalid colors in ops. Fixes #309

This commit is contained in:
Tom MacWright 2013-10-23 19:45:19 -04:00
parent 15140e49ee
commit cb177b7a24
3 changed files with 15 additions and 0 deletions

View File

@ -54,18 +54,23 @@ tree.functions = {
}
},
hue: function (color) {
if (!('toHSL' in color)) return null;
return new tree.Dimension(Math.round(color.toHSL().h));
},
saturation: function (color) {
if (!('toHSL' in color)) return null;
return new tree.Dimension(Math.round(color.toHSL().s * 100), '%');
},
lightness: function (color) {
if (!('toHSL' in color)) return null;
return new tree.Dimension(Math.round(color.toHSL().l * 100), '%');
},
alpha: function (color) {
if (!('toHSL' in color)) return null;
return new tree.Dimension(color.toHSL().a);
},
saturate: function (color, amount) {
if (!('toHSL' in color)) return null;
var hsl = color.toHSL();
hsl.s += amount.value / 100;
@ -73,6 +78,7 @@ tree.functions = {
return hsla(hsl);
},
desaturate: function (color, amount) {
if (!('toHSL' in color)) return null;
var hsl = color.toHSL();
hsl.s -= amount.value / 100;
@ -80,6 +86,7 @@ tree.functions = {
return hsla(hsl);
},
lighten: function (color, amount) {
if (!('toHSL' in color)) return null;
var hsl = color.toHSL();
hsl.l += amount.value / 100;
@ -87,6 +94,7 @@ tree.functions = {
return hsla(hsl);
},
darken: function (color, amount) {
if (!('toHSL' in color)) return null;
var hsl = color.toHSL();
hsl.l -= amount.value / 100;
@ -94,6 +102,7 @@ tree.functions = {
return hsla(hsl);
},
fadein: function (color, amount) {
if (!('toHSL' in color)) return null;
var hsl = color.toHSL();
hsl.a += amount.value / 100;
@ -101,6 +110,7 @@ tree.functions = {
return hsla(hsl);
},
fadeout: function (color, amount) {
if (!('toHSL' in color)) return null;
var hsl = color.toHSL();
hsl.a -= amount.value / 100;
@ -108,6 +118,7 @@ tree.functions = {
return hsla(hsl);
},
spin: function (color, amount) {
if (!('toHSL' in color)) return null;
var hsl = color.toHSL();
var hue = (hsl.h + amount.value) % 360;

View File

@ -0,0 +1,3 @@
#world {
polygon-fill: spin(#f00f00f, 10);
}

View File

@ -0,0 +1 @@
invalid_color_in_fn.mss:2:34 incorrect arguments given to spin()