4 rgb: function (r, g, b) {
5 return this.rgba(r, g, b, 1.0);
7 rgba: function (r, g, b, a) {
8 var rgb = [r, g, b].map(function (c) { return number(c) }),
10 return new(tree.Color)(rgb, a);
12 hsl: function (h, s, l) {
13 return this.hsla(h, s, l, 1.0);
15 hsla: function (h, s, l, a) {
16 h = (number(h) % 360) / 360;
17 s = number(s); l = number(l); a = number(a);
19 var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
22 return this.rgba(hue(h + 1/3) * 255,
28 h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
29 if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
30 else if (h * 2 < 1) return m2;
31 else if (h * 3 < 2) return m1 + (m2 - m1) * (2/3 - h) * 6;
35 hue: function (color) {
36 return new(tree.Dimension)(Math.round(color.toHSL().h));
38 saturation: function (color) {
39 return new(tree.Dimension)(Math.round(color.toHSL().s * 100), '%');
41 lightness: function (color) {
42 return new(tree.Dimension)(Math.round(color.toHSL().l * 100), '%');
44 alpha: function (color) {
45 return new(tree.Dimension)(color.toHSL().a);
47 saturate: function (color, amount) {
48 var hsl = color.toHSL();
50 hsl.s += amount.value / 100;
54 desaturate: function (color, amount) {
55 var hsl = color.toHSL();
57 hsl.s -= amount.value / 100;
61 lighten: function (color, amount) {
62 var hsl = color.toHSL();
64 hsl.l += amount.value / 100;
68 darken: function (color, amount) {
69 var hsl = color.toHSL();
71 hsl.l -= amount.value / 100;
75 fadein: function (color, amount) {
76 var hsl = color.toHSL();
78 hsl.a += amount.value / 100;
82 fadeout: function (color, amount) {
83 var hsl = color.toHSL();
85 hsl.a -= amount.value / 100;
89 fade: function (color, amount) {
90 var hsl = color.toHSL();
92 hsl.a = amount.value / 100;
96 spin: function (color, amount) {
97 var hsl = color.toHSL();
98 var hue = (hsl.h + amount.value) % 360;
100 hsl.h = hue < 0 ? 360 + hue : hue;
105 // Copyright (c) 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein
106 // http://sass-lang.com
108 mix: function (color1, color2, weight) {
109 var p = weight.value / 100.0;
111 var a = color1.toHSL().a - color2.toHSL().a;
113 var w1 = (((w * a == -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
116 var rgb = [color1.rgb[0] * w1 + color2.rgb[0] * w2,
117 color1.rgb[1] * w1 + color2.rgb[1] * w2,
118 color1.rgb[2] * w1 + color2.rgb[2] * w2];
120 var alpha = color1.alpha * p + color2.alpha * (1 - p);
122 return new(tree.Color)(rgb, alpha);
124 greyscale: function (color) {
125 return this.desaturate(color, new(tree.Dimension)(100));
128 return new(tree.Anonymous)(str instanceof tree.JavaScript ? str.evaluated : str);
130 escape: function (str) {
131 return new(tree.Anonymous)(encodeURI(str.value).replace(/=/g, "%3D").replace(/:/g, "%3A").replace(/#/g, "%23").replace(/;/g, "%3B").replace(/\(/g, "%28").replace(/\)/g, "%29"));
133 '%': function (quoted /* arg, arg, ...*/) {
134 var args = Array.prototype.slice.call(arguments, 1),
137 for (var i = 0; i < args.length; i++) {
138 str = str.replace(/%[sda]/i, function(token) {
139 var value = token.match(/s/i) ? args[i].value : args[i].toCSS();
140 return token.match(/[A-Z]$/) ? encodeURIComponent(value) : value;
143 str = str.replace(/%%/g, '%');
144 return new(tree.Quoted)('"' + str + '"', str);
146 round: function (n) {
147 if (n instanceof tree.Dimension) {
148 return new(tree.Dimension)(Math.round(number(n)), n.unit);
149 } else if (typeof(n) === 'number') {
150 return Math.round(n);
153 error: "RuntimeError",
154 message: "math functions take numbers as parameters"
158 argb: function (color) {
159 return new(tree.Anonymous)(color.toARGB());
164 function hsla(hsla) {
165 return tree.functions.hsla(hsla.h, hsla.s, hsla.l, hsla.a);
169 if (n instanceof tree.Dimension) {
170 return parseFloat(n.unit == '%' ? n.value / 100 : n.value);
171 } else if (typeof(n) === 'number') {
175 error: "RuntimeError",
176 message: "color functions take numbers as parameters"
181 function clamp(val) {
182 return Math.min(1, Math.max(0, val));
185 })(require('less/tree'));