|
|
|
|
@ -56,9 +56,9 @@
|
|
|
|
|
return value < min ? min: (value > max ? max: value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
o.r = clamp(0, parseInt(o.r), 255);
|
|
|
|
|
o.g = clamp(0, parseInt(o.g), 255);
|
|
|
|
|
o.b = clamp(0, parseInt(o.b), 255);
|
|
|
|
|
o.r = clamp(0, parseInt(o.r, 10), 255);
|
|
|
|
|
o.g = clamp(0, parseInt(o.g, 10), 255);
|
|
|
|
|
o.b = clamp(0, parseInt(o.b, 10), 255);
|
|
|
|
|
o.a = clamp(0, o.a, 1);
|
|
|
|
|
return o;
|
|
|
|
|
};
|
|
|
|
|
@ -68,7 +68,7 @@
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return o.normalize();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// extract CSS color property from element, going up in the DOM
|
|
|
|
|
// if it's "transparent"
|
|
|
|
|
@ -78,7 +78,7 @@
|
|
|
|
|
c = elem.css(css).toLowerCase();
|
|
|
|
|
// keep going until we find an element that has color, or
|
|
|
|
|
// we hit the body
|
|
|
|
|
if (c != '' && c != 'transparent')
|
|
|
|
|
if (c !== '' && c != 'transparent')
|
|
|
|
|
break;
|
|
|
|
|
elem = elem.parent();
|
|
|
|
|
} while (!$.nodeName(elem.get(0), "body"));
|
|
|
|
|
@ -88,7 +88,7 @@
|
|
|
|
|
c = "transparent";
|
|
|
|
|
|
|
|
|
|
return $.color.parse(c);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// parse CSS color string (like "rgb(10, 32, 43)" or "#fff"),
|
|
|
|
|
// returns color object, if parsing failed, you get black (0, 0,
|
|
|
|
|
@ -97,27 +97,33 @@
|
|
|
|
|
var res, m = $.color.make;
|
|
|
|
|
|
|
|
|
|
// Look for rgb(num,num,num)
|
|
|
|
|
if (res = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(str))
|
|
|
|
|
res = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(str);
|
|
|
|
|
if (res)
|
|
|
|
|
return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10));
|
|
|
|
|
|
|
|
|
|
// Look for rgba(num,num,num,num)
|
|
|
|
|
if (res = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str))
|
|
|
|
|
res = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str);
|
|
|
|
|
if (res)
|
|
|
|
|
return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10), parseFloat(res[4]));
|
|
|
|
|
|
|
|
|
|
// Look for rgb(num%,num%,num%)
|
|
|
|
|
if (res = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(str))
|
|
|
|
|
res = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(str);
|
|
|
|
|
if (res)
|
|
|
|
|
return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55);
|
|
|
|
|
|
|
|
|
|
// Look for rgba(num%,num%,num%,num)
|
|
|
|
|
if (res = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str))
|
|
|
|
|
res = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str);
|
|
|
|
|
if (res)
|
|
|
|
|
return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55, parseFloat(res[4]));
|
|
|
|
|
|
|
|
|
|
// Look for #a0b1c2
|
|
|
|
|
if (res = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(str))
|
|
|
|
|
res = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(str);
|
|
|
|
|
if (res)
|
|
|
|
|
return m(parseInt(res[1], 16), parseInt(res[2], 16), parseInt(res[3], 16));
|
|
|
|
|
|
|
|
|
|
// Look for #fff
|
|
|
|
|
if (res = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(str))
|
|
|
|
|
res = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(str);
|
|
|
|
|
if (res)
|
|
|
|
|
return m(parseInt(res[1]+res[1], 16), parseInt(res[2]+res[2], 16), parseInt(res[3]+res[3], 16));
|
|
|
|
|
|
|
|
|
|
// Otherwise, we're most likely dealing with a named color
|
|
|
|
|
@ -129,7 +135,7 @@
|
|
|
|
|
res = lookupColors[name] || [0, 0, 0];
|
|
|
|
|
return m(res[0], res[1], res[2]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var lookupColors = {
|
|
|
|
|
aqua:[0,255,255],
|
|
|
|
|
|