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