if contrast first argument does not match, pass it through. Fixes #1090

This commit is contained in:
Luke Page
2012-12-30 08:35:09 +00:00
parent 4f475456d5
commit ba99755f6b
4 changed files with 19 additions and 6 deletions

View File

@@ -173,6 +173,11 @@ tree.functions = {
return this.desaturate(color, new(tree.Dimension)(100));
},
contrast: function (color, dark, light, threshold) {
// filter: contrast(3.2);
// should be kept as is, so check for color
if (!color.rgb) {
return null;
}
if (typeof light === 'undefined') {
light = this.rgba(255, 255, 255, 1.0);
}

View File

@@ -14,7 +14,8 @@ tree.Call.prototype = {
// When evaluating a function call,
// we either find the function in `tree.functions` [1],
// in which case we call it, passing the evaluated arguments,
// or we simply print it out as it appeared originally [2].
// if this returns null or we cannot find the function, we
// simply print it out as it appeared originally [2].
//
// The *functions.js* file contains the built-in functions.
//
@@ -23,21 +24,26 @@ tree.Call.prototype = {
// The function should receive the value, not the variable.
//
eval: function (env) {
var args = this.args.map(function (a) { return a.eval(env) });
var args = this.args.map(function (a) { return a.eval(env) }),
result;
if (this.name in tree.functions) { // 1.
try {
return tree.functions[this.name].apply(tree.functions, args);
result = tree.functions[this.name].apply(tree.functions, args);
if (result != null) {
return result;
}
} catch (e) {
throw { type: e.type || "Runtime",
message: "error evaluating function `" + this.name + "`" +
(e.message ? ': ' + e.message : ''),
index: this.index, filename: this.filename };
}
} else { // 2.
return new(tree.Anonymous)(this.name +
"(" + args.map(function (a) { return a.toCSS(env) }).join(', ') + ")");
}
// 2.
return new(tree.Anonymous)(this.name +
"(" + args.map(function (a) { return a.toCSS(env) }).join(', ') + ")");
},
toCSS: function (env) {

View File

@@ -24,6 +24,7 @@
luma-yellow: 93%;
luma-cyan: 79%;
luma-white-alpha: 50%;
contrast-filter: contrast(30%);
contrast-white: #000000;
contrast-black: #ffffff;
contrast-red: #ffffff;

View File

@@ -28,6 +28,7 @@
luma-yellow: luma(#ffff00);
luma-cyan: luma(#00ffff);
luma-white-alpha: luma(rgba(255,255,255,0.5));
contrast-filter: contrast(30%);
contrast-white: contrast(#fff);
contrast-black: contrast(#000);
contrast-red: contrast(#ff0000);