postcss-gtk
Version:
Processes GTK+ CSS into browser CSS
97 lines (85 loc) • 2.83 kB
JavaScript
// Generated by CoffeeScript 1.9.1
(function() {
var add_css_function, colorTransformers, convert, current_node, debug, fn, fn_name, lerp, parse, parseColor, rgba;
parseColor = require("color-parser");
convert = require("color-convert");
add_css_function = require("./add-css-function");
debug = function() {};
current_node = null;
parse = function(value) {
var e, ref;
try {
return (function() {
if ((ref = parseColor(value)) != null) {
return ref;
} else {
throw new Error("Failed to parse color value " + value);
}
})();
} catch (_error) {
e = _error;
if (current_node) {
console.error(e.stack);
throw current_node.error(e.message);
} else {
console.error("Error parsing color (with no associated CSS node)");
throw e;
}
}
};
lerp = function(a, b, x) {
return a + (b - a) * x;
};
rgba = function(r, g, b, a) {
if (isNaN(a) || a === 1) {
return "rgb(" + (~~r) + ", " + (~~g) + ", " + (~~b) + ")";
} else {
return "rgba(" + (~~r) + ", " + (~~g) + ", " + (~~b) + ", " + a + ")";
}
};
colorTransformers = {
mix: function(colorA, colorB, x) {
var a, b, l;
debug("MIX COLORS " + colorA + " AND " + colorB + " BY LERPY AMOUNT " + x);
a = parse(colorA);
b = parse(colorB);
debug("-", colorA, a);
debug("-", colorB, b);
debug("-", x);
l = function(p) {
return lerp(a[p], b[p], x);
};
return rgba(l("r"), l("g"), l("b"), l("a"));
},
shade: function(color, value) {
var a, b, g, h, l, r, ref, ref1, ref2, ref3, s;
if (isNaN(value)) {
ref = [value, color], color = ref[0], value = ref[1];
}
debug("SHADE COLOR " + color + " BY VALUE " + value);
ref1 = parse(color), r = ref1.r, g = ref1.g, b = ref1.b, a = ref1.a;
ref2 = convert.rgb2hslRaw(r, g, b), h = ref2[0], s = ref2[1], l = ref2[2];
debug("- OLD LIGHTNESS: " + l);
l *= value;
debug("- NEW LIGHTNESS: " + l + " (AFTER APPLYING " + value + ")");
ref3 = convert.hsl2rgb(h, s, l), r = ref3[0], g = ref3[1], b = ref3[2];
return rgba(r, g, b, a);
},
alpha: function(color, factor) {
var a, b, g, r, ref, ref1;
if (isNaN(factor)) {
ref = [factor, color], color = ref[0], factor = ref[1];
}
debug("MULTIPLY ALPHA OF COLOR " + color + " BY FACTOR " + factor);
ref1 = parse(color), r = ref1.r, g = ref1.g, b = ref1.b, a = ref1.a;
debug("- OLD", rgba(r, g, b, a));
a *= factor;
debug("- NEW", rgba(r, g, b, a));
return rgba(r, g, b, a);
}
};
for (fn_name in colorTransformers) {
fn = colorTransformers[fn_name];
add_css_function(fn_name, fn);
}
}).call(this);