Comparing version 2.2.2 to 2.2.3
@@ -1,37 +0,3 @@ | ||
/*global one*/ | ||
/** | ||
* @namespace one One.com global JavaScript namespace. | ||
* @exports one | ||
*/ | ||
if (typeof one === 'undefined') { | ||
one = { | ||
include: function () {} | ||
}; | ||
} | ||
/*global one*/ | ||
/** | ||
* @namespace one.color | ||
*/ | ||
/** | ||
* Parse a hex string, 24-bit integer or object representing a color. | ||
* If a one.color.(RGB|HSL|HSV|CMYK) object is provided, it will be returned | ||
* as-is, so in library code you can use {@link one.color} to be flexible | ||
* about how colors are provided to you: | ||
* <pre><code> | ||
function foo (myColor) { | ||
myColor = color(myColor); | ||
// Now we are sure that myColor is a one.color.(RGB|CMYK|HSL|HSV) object, even if it was provided as a hex string. | ||
} | ||
* </code></pre> | ||
* @param {String|Object} obj A hex string, integer value, or | ||
* object to parse. | ||
* @return {one.color.RGB|one.color.HSL|one.color.HSV|one.color.CMYK} Color object representing the | ||
* parsed color, or false if the input couldn't be parsed. | ||
*/ | ||
var installedColorSpaces = [], | ||
namedColors = {}, | ||
channelRegExp = /\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/, | ||
@@ -46,63 +12,62 @@ alphaChannelRegExp = /\s*(\.\d+|\d+(?:\.\d+)?)\s*/, | ||
"(?:," + alphaChannelRegExp.source + ")?" + | ||
"\\)$", "i"), | ||
ONECOLOR = one.color = function (obj) { | ||
if (Object.prototype.toString.apply(obj) === '[object Array]') { | ||
if (obj[0].length === 4) { | ||
// Assumed 4 element int RGB array from canvas with all channels [0;255] | ||
return new ONECOLOR.RGB(obj[0] / 255, obj[1] / 255, obj[2] / 255, obj[3] / 255); | ||
} else { | ||
// Assumed destringified array from one.color.JSON() | ||
return new ONECOLOR[obj[0]](obj.slice(1, obj.length)); | ||
"\\)$", "i"); | ||
function ONECOLOR (obj) { | ||
if (Object.prototype.toString.apply(obj) === '[object Array]') { | ||
if (obj[0].length === 4) { | ||
// Assumed 4 element int RGB array from canvas with all channels [0;255] | ||
return new ONECOLOR.RGB(obj[0] / 255, obj[1] / 255, obj[2] / 255, obj[3] / 255); | ||
} else { | ||
// Assumed destringified array from one.color.JSON() | ||
return new ONECOLOR[obj[0]](obj.slice(1, obj.length)); | ||
} | ||
} else if (obj.charCodeAt) { | ||
var lowerCased = obj.toLowerCase(); | ||
if (namedColors[lowerCased]) { | ||
obj = namedColors[lowerCased]; | ||
} | ||
// Test for CSS rgb(....) string | ||
var matchCssSyntax = obj.match(cssColorRegExp); | ||
if (matchCssSyntax) { | ||
var colorSpaceName = matchCssSyntax[1].toUpperCase(), | ||
alpha = typeof matchCssSyntax[8] === 'undefined' ? matchCssSyntax[8] : parseFloat(matchCssSyntax[8]), | ||
hasHue = colorSpaceName[0] === 'H', | ||
firstChannelDivisor = matchCssSyntax[3] ? 100 : (hasHue ? 360 : 255), | ||
secondChannelDivisor = (matchCssSyntax[5] || hasHue) ? 100 : 255, | ||
thirdChannelDivisor = (matchCssSyntax[7] || hasHue) ? 100 : 255; | ||
if (typeof ONECOLOR[colorSpaceName] === 'undefined') { | ||
throw new Error("one.color." + colorSpaceName + " is not installed."); | ||
} | ||
} else if (obj.charCodeAt) { | ||
if (ONECOLOR.namedColors) { | ||
var lowerCased = obj.toLowerCase(); | ||
if (ONECOLOR.namedColors[lowerCased]) { | ||
obj = ONECOLOR.namedColors[lowerCased]; | ||
} | ||
} | ||
// Test for CSS rgb(....) string | ||
var matchCssSyntax = obj.match(cssColorRegExp); | ||
if (matchCssSyntax) { | ||
var colorSpaceName = matchCssSyntax[1].toUpperCase(), | ||
alpha = typeof matchCssSyntax[8] === 'undefined' ? matchCssSyntax[8] : parseFloat(matchCssSyntax[8]), | ||
hasHue = colorSpaceName[0] === 'H', | ||
firstChannelDivisor = matchCssSyntax[3] ? 100 : (hasHue ? 360 : 255), | ||
secondChannelDivisor = (matchCssSyntax[5] || hasHue) ? 100 : 255, | ||
thirdChannelDivisor = (matchCssSyntax[7] || hasHue) ? 100 : 255; | ||
if (typeof ONECOLOR[colorSpaceName] === 'undefined') { | ||
throw new Error("one.color." + colorSpaceName + " is not installed."); | ||
} | ||
return new ONECOLOR[colorSpaceName]( | ||
parseFloat(matchCssSyntax[2]) / firstChannelDivisor, | ||
parseFloat(matchCssSyntax[4]) / secondChannelDivisor, | ||
parseFloat(matchCssSyntax[6]) / thirdChannelDivisor, | ||
alpha | ||
); | ||
} | ||
// Assume hex syntax | ||
if (obj.length < 6) { | ||
// Allow CSS shorthand | ||
obj = obj.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i, '$1$1$2$2$3$3'); | ||
} | ||
// Split obj into red, green, and blue components | ||
var hexMatch = obj.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i); | ||
if (hexMatch) { | ||
return new ONECOLOR.RGB( | ||
parseInt(hexMatch[1], 16) / 255, | ||
parseInt(hexMatch[2], 16) / 255, | ||
parseInt(hexMatch[3], 16) / 255 | ||
); | ||
} | ||
} else if (typeof obj === 'object' && obj.isColor) { | ||
return obj; | ||
} else if (!isNaN(obj)) { | ||
// Strange integer representation sometimes returned by document.queryCommandValue in some browser... | ||
return new ONECOLOR.RGB((obj & 0xFF) / 255, ((obj & 0xFF00) >> 8) / 255, ((obj & 0xFF0000) >> 16) / 255); | ||
return new ONECOLOR[colorSpaceName]( | ||
parseFloat(matchCssSyntax[2]) / firstChannelDivisor, | ||
parseFloat(matchCssSyntax[4]) / secondChannelDivisor, | ||
parseFloat(matchCssSyntax[6]) / thirdChannelDivisor, | ||
alpha | ||
); | ||
} | ||
return false; | ||
}; | ||
// Assume hex syntax | ||
if (obj.length < 6) { | ||
// Allow CSS shorthand | ||
obj = obj.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i, '$1$1$2$2$3$3'); | ||
} | ||
// Split obj into red, green, and blue components | ||
var hexMatch = obj.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i); | ||
if (hexMatch) { | ||
return new ONECOLOR.RGB( | ||
parseInt(hexMatch[1], 16) / 255, | ||
parseInt(hexMatch[2], 16) / 255, | ||
parseInt(hexMatch[3], 16) / 255 | ||
); | ||
} | ||
} else if (typeof obj === 'object' && obj.isColor) { | ||
return obj; | ||
} else if (!isNaN(obj)) { | ||
// Strange integer representation sometimes returned by document.queryCommandValue in some browser... | ||
return new ONECOLOR.RGB((obj & 0xFF) / 255, ((obj & 0xFF00) >> 8) / 255, ((obj & 0xFF0000) >> 16) / 255); | ||
} | ||
return false; | ||
}; | ||
/*jslint evil:true*/ | ||
ONECOLOR.installColorSpace = function (colorSpaceName, propertyNames, config) { | ||
function installColorSpace(colorSpaceName, propertyNames, config) { | ||
ONECOLOR[colorSpaceName] = new Function(propertyNames.join(","), | ||
@@ -119,3 +84,3 @@ // Allow passing an array to the constructor: | ||
return "isNaN(" + propertyName + ")"; | ||
}).join("||") + "){" + "throw new Error(\"[one.color." + colorSpaceName + "]: Invalid color: (\"+" + propertyNames.join("+\",\"+") + "+\")\");}" + | ||
}).join("||") + "){" + "throw new Error(\"[" + colorSpaceName + "]: Invalid color: (\"+" + propertyNames.join("+\",\"+") + "+\")\");}" + | ||
propertyNames.map(function (propertyName) { | ||
@@ -230,35 +195,3 @@ if (propertyName === 'hue') { | ||
/** | ||
* @name one.color.RGB | ||
* @class | ||
* <p>A color in the RGB colorspace with an optional alpha value.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects are designed to be | ||
* immutable; all the conversion, set, and adjust methods return new | ||
* objects.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects automatically get the set | ||
* and adjust methods from all other installed colorspaces, so | ||
* although you can use the explicit conversion methods ({@link | ||
* one.color.RGB#hsl}, {@link one.color.RGB#cmyk}...), the below | ||
* will work just fine:</p><pre><code> | ||
new one.color.RGB(.4, .3, .9). | ||
lightness(+.2, true). // Implicit conversion to HSL | ||
red(-.1). // Implicit conversion back to RGB | ||
hex(); // "#00a6f2" | ||
</code></pre> | ||
* | ||
* @constructor | ||
* Create a new one.color.RGB object. Values outside the supported | ||
* range, [0..1], will be adjusted automatically. | ||
* @param {Number} red The red component, range: [0..1] | ||
* @param {Number} green The green component, range: [0..1] | ||
* @param {Number} blue The blue component, range: [0..1] | ||
* @param {Number} [alpha] The alpha value, range: [0..1], | ||
* defaults to 1 | ||
*/ | ||
ONECOLOR.installColorSpace('RGB', ['red', 'green', 'blue', 'alpha'], { | ||
/** | ||
* Get the standard RGB hex representation of the color. | ||
* @return {String} The hex string, e.g. "#f681df" | ||
*/ | ||
installColorSpace('RGB', ['red', 'green', 'blue', 'alpha'], { | ||
hex: function () { | ||
@@ -269,7 +202,2 @@ var hexString = (Math.round(255 * this._red) * 0x10000 + Math.round(255 * this._green) * 0x100 + Math.round(255 * this._blue)).toString(16); | ||
/** | ||
* Get a valid CSS color representation of the color without an | ||
* alpha value. | ||
* @return {String} The CSS color string, e.g. "rgb(123, 2, 202)" | ||
*/ | ||
css: function () { | ||
@@ -279,7 +207,2 @@ return "rgb(" + Math.round(255 * this._red) + "," + Math.round(255 * this._green) + "," + Math.round(255 * this._blue) + ")"; | ||
/** | ||
* Get a valid CSS color representation of the color, including | ||
* the alpha value. | ||
* @return {String} The CSS color string, e.g. "rgba(123, 2, 202, 0.253)" | ||
*/ | ||
cssa: function () { | ||
@@ -290,223 +213,165 @@ return "rgba(" + Math.round(255 * this._red) + "," + Math.round(255 * this._green) + "," + Math.round(255 * this._blue) + "," + this._alpha + ")"; | ||
/** | ||
* @name one.color.RGB.prototype.red | ||
* @function | ||
* @param {Number} red The new red component, range: [0..1]. If not | ||
* provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.RGB} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
if (typeof module !== 'undefined') { | ||
// Node module export | ||
module.exports = ONECOLOR; | ||
} else { | ||
// Browser | ||
one = one || {}; | ||
one.color = ONECOLOR; | ||
} | ||
/** | ||
* @name one.color.RGB.prototype.green | ||
* @function | ||
* @param {Number} green The new green component, range: [0..1] | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.RGB} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/*global namedColors*/ | ||
namedColors = { | ||
aliceblue: '#f0f8ff', | ||
antiquewhite: '#faebd7', | ||
aqua: '#00ffff', | ||
aquamarine: '#7fffd4', | ||
azure: '#f0ffff', | ||
beige: '#f5f5dc', | ||
bisque: '#ffe4c4', | ||
black: '#000000', | ||
blanchedalmond: '#ffebcd', | ||
blue: '#0000ff', | ||
blueviolet: '#8a2be2', | ||
brown: '#a52a2a', | ||
burlywood: '#deb887', | ||
cadetblue: '#5f9ea0', | ||
chartreuse: '#7fff00', | ||
chocolate: '#d2691e', | ||
coral: '#ff7f50', | ||
cornflowerblue: '#6495ed', | ||
cornsilk: '#fff8dc', | ||
crimson: '#dc143c', | ||
cyan: '#00ffff', | ||
darkblue: '#00008b', | ||
darkcyan: '#008b8b', | ||
darkgoldenrod: '#b8860b', | ||
darkgray: '#a9a9a9', | ||
darkgrey: '#a9a9a9', | ||
darkgreen: '#006400', | ||
darkkhaki: '#bdb76b', | ||
darkmagenta: '#8b008b', | ||
darkolivegreen: '#556b2f', | ||
darkorange: '#ff8c00', | ||
darkorchid: '#9932cc', | ||
darkred: '#8b0000', | ||
darksalmon: '#e9967a', | ||
darkseagreen: '#8fbc8f', | ||
darkslateblue: '#483d8b', | ||
darkslategray: '#2f4f4f', | ||
darkslategrey: '#2f4f4f', | ||
darkturquoise: '#00ced1', | ||
darkviolet: '#9400d3', | ||
deeppink: '#ff1493', | ||
deepskyblue: '#00bfff', | ||
dimgray: '#696969', | ||
dimgrey: '#696969', | ||
dodgerblue: '#1e90ff', | ||
firebrick: '#b22222', | ||
floralwhite: '#fffaf0', | ||
forestgreen: '#228b22', | ||
fuchsia: '#ff00ff', | ||
gainsboro: '#dcdcdc', | ||
ghostwhite: '#f8f8ff', | ||
gold: '#ffd700', | ||
goldenrod: '#daa520', | ||
gray: '#808080', | ||
grey: '#808080', | ||
green: '#008000', | ||
greenyellow: '#adff2f', | ||
honeydew: '#f0fff0', | ||
hotpink: '#ff69b4', | ||
indianred: '#cd5c5c', | ||
indigo: '#4b0082', | ||
ivory: '#fffff0', | ||
khaki: '#f0e68c', | ||
lavender: '#e6e6fa', | ||
lavenderblush: '#fff0f5', | ||
lawngreen: '#7cfc00', | ||
lemonchiffon: '#fffacd', | ||
lightblue: '#add8e6', | ||
lightcoral: '#f08080', | ||
lightcyan: '#e0ffff', | ||
lightgoldenrodyellow: '#fafad2', | ||
lightgray: '#d3d3d3', | ||
lightgrey: '#d3d3d3', | ||
lightgreen: '#90ee90', | ||
lightpink: '#ffb6c1', | ||
lightsalmon: '#ffa07a', | ||
lightseagreen: '#20b2aa', | ||
lightskyblue: '#87cefa', | ||
lightslategray: '#778899', | ||
lightslategrey: '#778899', | ||
lightsteelblue: '#b0c4de', | ||
lightyellow: '#ffffe0', | ||
lime: '#00ff00', | ||
limegreen: '#32cd32', | ||
linen: '#faf0e6', | ||
magenta: '#ff00ff', | ||
maroon: '#800000', | ||
mediumaquamarine: '#66cdaa', | ||
mediumblue: '#0000cd', | ||
mediumorchid: '#ba55d3', | ||
mediumpurple: '#9370d8', | ||
mediumseagreen: '#3cb371', | ||
mediumslateblue: '#7b68ee', | ||
mediumspringgreen: '#00fa9a', | ||
mediumturquoise: '#48d1cc', | ||
mediumvioletred: '#c71585', | ||
midnightblue: '#191970', | ||
mintcream: '#f5fffa', | ||
mistyrose: '#ffe4e1', | ||
moccasin: '#ffe4b5', | ||
navajowhite: '#ffdead', | ||
navy: '#000080', | ||
oldlace: '#fdf5e6', | ||
olive: '#808000', | ||
olivedrab: '#6b8e23', | ||
orange: '#ffa500', | ||
orangered: '#ff4500', | ||
orchid: '#da70d6', | ||
palegoldenrod: '#eee8aa', | ||
palegreen: '#98fb98', | ||
paleturquoise: '#afeeee', | ||
palevioletred: '#d87093', | ||
papayawhip: '#ffefd5', | ||
peachpuff: '#ffdab9', | ||
peru: '#cd853f', | ||
pink: '#ffc0cb', | ||
plum: '#dda0dd', | ||
powderblue: '#b0e0e6', | ||
purple: '#800080', | ||
red: '#ff0000', | ||
rosybrown: '#bc8f8f', | ||
royalblue: '#4169e1', | ||
saddlebrown: '#8b4513', | ||
salmon: '#fa8072', | ||
sandybrown: '#f4a460', | ||
seagreen: '#2e8b57', | ||
seashell: '#fff5ee', | ||
sienna: '#a0522d', | ||
silver: '#c0c0c0', | ||
skyblue: '#87ceeb', | ||
slateblue: '#6a5acd', | ||
slategray: '#708090', | ||
slategrey: '#708090', | ||
snow: '#fffafa', | ||
springgreen: '#00ff7f', | ||
steelblue: '#4682b4', | ||
tan: '#d2b48c', | ||
teal: '#008080', | ||
thistle: '#d8bfd8', | ||
tomato: '#ff6347', | ||
turquoise: '#40e0d0', | ||
violet: '#ee82ee', | ||
wheat: '#f5deb3', | ||
white: '#ffffff', | ||
whitesmoke: '#f5f5f5', | ||
yellow: '#ffff00', | ||
yellowgreen: '#9acd32' | ||
}; | ||
/** | ||
* @name one.color.RGB.prototype.blue | ||
* @function | ||
* @param {Number} blue The new blue component, range: [0..1] | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.RGB} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.alpha | ||
* @function | ||
* @param {Number} alpha The new alpha value, range: [0..1] | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.RGB} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.toJSON | ||
* @description Convert the color to a JSON representation. | ||
* @function | ||
* @return {Array} | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.rgb | ||
* @description Convert the color to a {@link one.color.RGB} object, ie. return the | ||
* object itself. | ||
* @function | ||
* @return {one.color.RGB} | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.hsv | ||
* @description Convert the color to a {@link one.color.HSV} object. | ||
* @function | ||
* @requires one.color.HSV | ||
* @return {one.color.HSV} | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.hsl | ||
* @description Convert the color to a {@link one.color.HSL} object. | ||
* @function | ||
* @requires one.color.HSL | ||
* @return {one.color.HSL} | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.cmyk | ||
* @description Convert the color to a {@link one.color.CMYK} object. | ||
* @function | ||
* @requires one.color.CMYK | ||
* @return {one.color.CMYK} | ||
*/ | ||
/*global one*/ | ||
/** | ||
* @name one.color.HSV | ||
* @class | ||
* <p>A color in the HSV colorspace, with an optional alpha value.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects are designed to be | ||
* immutable; all the conversion, set, and adjust methods return new | ||
* objects.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects automatically get the set | ||
* and adjust methods from all other installed colorspaces, so | ||
* although you can use the explicit conversion methods ({@link | ||
* one.color.HSV#rgb}, {@link one.color.HSV#hsl}...), the below | ||
* will work just fine:</p><pre><code> | ||
new one.color.HSV(.9, .2, .4). | ||
blue(-.4, true). // Implicit conversion to RGB | ||
cyan(-.1). // Implicit conversion to CMYK | ||
hex(); // "#665200" | ||
</code></pre> | ||
* | ||
* @constructor | ||
* Create a new one.color.HSV object. Component values outside the | ||
* supported range, [0..1], will be adjusted automatically. | ||
* @param {Number} hue The hue component, range: [0..1] | ||
* @param {Number} saturation The saturation component, range: [0..1] | ||
* @param {Number} value The value component, range: [0..1] | ||
* @param {Number} [alpha] The alpha value, range: [0..1], | ||
* defaults to 1 | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.hue | ||
* @function | ||
* @param {Number} [hue] The new hue component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSV} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.saturation | ||
* @function | ||
* @param {Number} [saturation] The new saturation component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSV} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.value | ||
* @function | ||
* @param {Number} [value] The new value component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSV} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.alpha | ||
* @function | ||
* @param {Number} [alpha] The new alpha component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSV} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.toJSON | ||
* @description Convert the color to a JSON representation. | ||
* @function | ||
* @return {Array} | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.rgb | ||
* @description Convert the color to a {@link one.color.RGB} object. | ||
* @function | ||
* @return {one.color.RGB} | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.hsv | ||
* @description Convert the color to a {@link one.color.HSV} object, ie. return the object itself. | ||
* @function | ||
* @return {one.color.HSV} | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.hsl | ||
* @description Convert the color to a {@link one.color.HSL} object. | ||
* @function | ||
* @requires one.color.HSL | ||
* @return {one.color.HSL} | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.cmyk | ||
* @description Convert the color to a {@link one.color.CMYK} object. | ||
* @function | ||
* @include one.color.CMYK | ||
* @return {one.color.CMYK} | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.hex | ||
* @description Get the standard RGB hex representation of the color. | ||
* @function | ||
* @return {String} The hex string, e.g. "#f681df" | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.css | ||
* @description Get a valid CSS color representation of the color without an alpha value. | ||
* @function | ||
* @return {String} The CSS color string, e.g. "rgb(123, 2, 202)" | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.cssa | ||
* @description Get a valid CSS color representation of the color, including the alpha value. | ||
* @function | ||
* @return {String} The CSS color string, e.g. "rgba(123, 2, 202, 0.253)" | ||
*/ | ||
ONECOLOR.installColorSpace('HSV', ['hue', 'saturation', 'value', 'alpha'], { | ||
installColorSpace('HSV', ['hue', 'saturation', 'value', 'alpha'], { | ||
rgb: function () { | ||
@@ -606,32 +471,3 @@ var hue = this._hue, | ||
/** | ||
* @name one.color.HSL | ||
* @class | ||
* <p>A color in the HSL colorspace, with an optional alpha value.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects are designed to be | ||
* immutable; all the conversion, set, and adjust methods return new | ||
* objects.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects automatically get the set | ||
* and adjust methods from all other installed colorspaces, so | ||
* although you can use the explicit conversion methods ({@link | ||
* one.color.HSL#rgb}, {@link one.color.HSL#hsv}...), the below | ||
* will work just fine:</p><pre><code> | ||
new one.color.HSL(.4, .3, .9, .9). // HSL with alpha | ||
black(+.1, true). // Implicit conversion to CMYK (with alpha) | ||
green(-.1). // Implicit conversion to RGB (with alpha) | ||
cssa(); // "rgba(198,0,203,0.9)" | ||
</code></pre> | ||
* | ||
* @constructor | ||
* Create a new one.color.HSL object. Component values outside the | ||
* supported range, [0..1], will be adjusted automatically. | ||
* @param {Number} hue The hue component, range: [0..1] | ||
* @param {Number} saturation The saturation component, range: [0..1] | ||
* @param {Number} lightness The lightness component, range: [0..1] | ||
* @param {Number} [alpha] The alpha value, range: [0..1], | ||
* defaults to 1 | ||
*/ | ||
ONECOLOR.installColorSpace('HSL', ['hue', 'saturation', 'lightness', 'alpha'], { | ||
installColorSpace('HSL', ['hue', 'saturation', 'lightness', 'alpha'], { | ||
hsv: function () { | ||
@@ -662,260 +498,5 @@ // Algorithm adapted from http://wiki.secondlife.com/wiki/Color_conversion_scripts | ||
/** | ||
* @name one.color.HSL.prototype.hue | ||
* @function | ||
* @param {Number} [hue] The new hue component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSL} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.saturation | ||
* @function | ||
* @param {Number} [saturation] The new saturation component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSL} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.lightness | ||
* @function | ||
* @param {Number} [lightness] The new lightness component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSL} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.alpha | ||
* @function | ||
* @param {Number} [alpha] The new alpha component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSL} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.toJSON | ||
* @description Convert the color to a JSON representation. | ||
* @function | ||
* @return {Array} | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.rgb | ||
* @description Convert the color to a {@link one.color.RGB} object. | ||
* @function | ||
* @return {one.color.RGB} | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.hsv | ||
* @description Convert the color to a {@link one.color.HSV} object. | ||
* @function | ||
* @return {one.color.HSV} | ||
* @requires one.color.HSV | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.hsl | ||
* @description Convert the color to a {@link one.color.HSL} object, ie. return the object itself. | ||
* @function | ||
* @return {one.color.HSL} | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.cmyk | ||
* @description Convert the color to a {@link one.color.CMYK} object. | ||
* @function | ||
* @requires one.color.CMYK | ||
* @return {one.color.CMYK} | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.hex | ||
* @description Get the standard RGB hex representation of the color. | ||
* @function | ||
* @return {String} The hex string, e.g. "#f681df" | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.css | ||
* @description Get a valid CSS color representation of the color without an alpha value. | ||
* @function | ||
* @return {String} The CSS color string, e.g. "rgb(123, 2, 202)" | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.cssa | ||
* @description Get a valid CSS color representation of the color, including the alpha value. | ||
* @function | ||
* @return {String} The CSS color string, e.g. "rgba(123, 2, 202, 0.253)" | ||
*/ | ||
/*global one*/ | ||
/** | ||
* @name one.color.CMYK | ||
* @class | ||
* <p>A color in the CMYK colorspace, with an optional alpha value.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects are designed to be | ||
* immutable; all the conversion, set, and adjust methods return new | ||
* objects.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects automatically get the set | ||
* and adjust methods from all other installed colorspaces, so | ||
* although you can use the explicit conversion methods ({@link one.color.CMYK#rgb}, | ||
* {@link one.color.CMYK#hsl}...), the below | ||
* will work just fine:</p><pre><code> | ||
new one.color.CMYK(.4, .2, .4, .9, .2). // CMYK with alpha | ||
blue(.2). // Implicit conversion to RGB (with alpha) | ||
hue(-.1, true). // Implicit conversion to HSL(/HSV) (with alpha) | ||
cssa(); // "rgba(20,13,0,0.2)" | ||
</code></pre> | ||
* @static | ||
* | ||
* @constructor | ||
* Create a new one.color.CMYK object. Component values outside the | ||
* supported range, [0..1], will be adjusted automatically. | ||
* @param {Number} cyan The cyan component, range: [0..1] | ||
* @param {Number} magenta The magenta component, range: [0..1] | ||
* @param {Number} yellow The yellow component, range: [0..1] | ||
* @param {Number} black The black component, range: [0..1] | ||
* @param {Number} [alpha] The alpha value, range: [0..1], | ||
* defaults to 1 | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.cyan | ||
* @function | ||
* @param {Number} [cyan] The new cyan component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.CMYK} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.magenta | ||
* @function | ||
* @param {Number} [magenta] The new magenta component, range: | ||
* [0..1]. If not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.CMYK} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.yellow | ||
* @function | ||
* @param {Number} yellow The new yellow component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.CMYK} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.black | ||
* @function | ||
* @param {Number} black The new black component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.CMYK} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.alpha | ||
* @function | ||
* @param {Number} alpha The new alpha value, range: [0..1]. If not | ||
* provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.CMYK} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.toJSON | ||
* @description Convert the color to a JSON representation. | ||
* @function | ||
* @return {Array} | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.rgb | ||
* @description Convert the color to a {@link one.color.RGB} object. | ||
* @function | ||
* @return {one.color.RGB} | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.hsv | ||
* @description Convert the color to a {@link one.color.HSV} object. | ||
* @function | ||
* @requires one.color.HSV | ||
* @return {one.color.HSV} | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.hsl | ||
* @description Convert the color to a {@link one.color.HSL} object. | ||
* @function | ||
* @requires one.color.HSL | ||
* @return {one.color.HSL} | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.cmyk | ||
* @description Convert the color to a {@link one.color.CMYK} object, ie. return the object itself. | ||
* @function | ||
* @return {one.color.CMYK} | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.hex | ||
* @description Get the standard RGB hex representation of the color. | ||
* @function | ||
* @return {String} The hex string, e.g. "#f681df" | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.css | ||
* @description Get a valid CSS color representation of the color without an alpha value. | ||
* @function | ||
* @return {String} The CSS color string, e.g. "rgb(123, 2, 202)" | ||
*/ | ||
/** | ||
* @name one.color.CMYK.prototype.cssa | ||
* @description Get a valid CSS color representation of the color, including the alpha value. | ||
* @function | ||
* @return {String} The CSS color string, e.g. "rgba(123, 2, 202, 0.253)" | ||
*/ | ||
ONECOLOR.installColorSpace('CMYK', ['cyan', 'magenta', 'yellow', 'black', 'alpha'], { | ||
installColorSpace('CMYK', ['cyan', 'magenta', 'yellow', 'black', 'alpha'], { | ||
rgb: function () { | ||
@@ -949,155 +530,4 @@ return new ONECOLOR.RGB((1 - this._cyan * (1 - this._black) - this._black), | ||
ONECOLOR.namedColors = { | ||
aliceblue: '#f0f8ff', | ||
antiquewhite: '#faebd7', | ||
aqua: '#00ffff', | ||
aquamarine: '#7fffd4', | ||
azure: '#f0ffff', | ||
beige: '#f5f5dc', | ||
bisque: '#ffe4c4', | ||
black: '#000000', | ||
blanchedalmond: '#ffebcd', | ||
blue: '#0000ff', | ||
blueviolet: '#8a2be2', | ||
brown: '#a52a2a', | ||
burlywood: '#deb887', | ||
cadetblue: '#5f9ea0', | ||
chartreuse: '#7fff00', | ||
chocolate: '#d2691e', | ||
coral: '#ff7f50', | ||
cornflowerblue: '#6495ed', | ||
cornsilk: '#fff8dc', | ||
crimson: '#dc143c', | ||
cyan: '#00ffff', | ||
darkblue: '#00008b', | ||
darkcyan: '#008b8b', | ||
darkgoldenrod: '#b8860b', | ||
darkgray: '#a9a9a9', | ||
darkgrey: '#a9a9a9', | ||
darkgreen: '#006400', | ||
darkkhaki: '#bdb76b', | ||
darkmagenta: '#8b008b', | ||
darkolivegreen: '#556b2f', | ||
darkorange: '#ff8c00', | ||
darkorchid: '#9932cc', | ||
darkred: '#8b0000', | ||
darksalmon: '#e9967a', | ||
darkseagreen: '#8fbc8f', | ||
darkslateblue: '#483d8b', | ||
darkslategray: '#2f4f4f', | ||
darkslategrey: '#2f4f4f', | ||
darkturquoise: '#00ced1', | ||
darkviolet: '#9400d3', | ||
deeppink: '#ff1493', | ||
deepskyblue: '#00bfff', | ||
dimgray: '#696969', | ||
dimgrey: '#696969', | ||
dodgerblue: '#1e90ff', | ||
firebrick: '#b22222', | ||
floralwhite: '#fffaf0', | ||
forestgreen: '#228b22', | ||
fuchsia: '#ff00ff', | ||
gainsboro: '#dcdcdc', | ||
ghostwhite: '#f8f8ff', | ||
gold: '#ffd700', | ||
goldenrod: '#daa520', | ||
gray: '#808080', | ||
grey: '#808080', | ||
green: '#008000', | ||
greenyellow: '#adff2f', | ||
honeydew: '#f0fff0', | ||
hotpink: '#ff69b4', | ||
indianred: '#cd5c5c', | ||
indigo: '#4b0082', | ||
ivory: '#fffff0', | ||
khaki: '#f0e68c', | ||
lavender: '#e6e6fa', | ||
lavenderblush: '#fff0f5', | ||
lawngreen: '#7cfc00', | ||
lemonchiffon: '#fffacd', | ||
lightblue: '#add8e6', | ||
lightcoral: '#f08080', | ||
lightcyan: '#e0ffff', | ||
lightgoldenrodyellow: '#fafad2', | ||
lightgray: '#d3d3d3', | ||
lightgrey: '#d3d3d3', | ||
lightgreen: '#90ee90', | ||
lightpink: '#ffb6c1', | ||
lightsalmon: '#ffa07a', | ||
lightseagreen: '#20b2aa', | ||
lightskyblue: '#87cefa', | ||
lightslategray: '#778899', | ||
lightslategrey: '#778899', | ||
lightsteelblue: '#b0c4de', | ||
lightyellow: '#ffffe0', | ||
lime: '#00ff00', | ||
limegreen: '#32cd32', | ||
linen: '#faf0e6', | ||
magenta: '#ff00ff', | ||
maroon: '#800000', | ||
mediumaquamarine: '#66cdaa', | ||
mediumblue: '#0000cd', | ||
mediumorchid: '#ba55d3', | ||
mediumpurple: '#9370d8', | ||
mediumseagreen: '#3cb371', | ||
mediumslateblue: '#7b68ee', | ||
mediumspringgreen: '#00fa9a', | ||
mediumturquoise: '#48d1cc', | ||
mediumvioletred: '#c71585', | ||
midnightblue: '#191970', | ||
mintcream: '#f5fffa', | ||
mistyrose: '#ffe4e1', | ||
moccasin: '#ffe4b5', | ||
navajowhite: '#ffdead', | ||
navy: '#000080', | ||
oldlace: '#fdf5e6', | ||
olive: '#808000', | ||
olivedrab: '#6b8e23', | ||
orange: '#ffa500', | ||
orangered: '#ff4500', | ||
orchid: '#da70d6', | ||
palegoldenrod: '#eee8aa', | ||
palegreen: '#98fb98', | ||
paleturquoise: '#afeeee', | ||
palevioletred: '#d87093', | ||
papayawhip: '#ffefd5', | ||
peachpuff: '#ffdab9', | ||
peru: '#cd853f', | ||
pink: '#ffc0cb', | ||
plum: '#dda0dd', | ||
powderblue: '#b0e0e6', | ||
purple: '#800080', | ||
red: '#ff0000', | ||
rosybrown: '#bc8f8f', | ||
royalblue: '#4169e1', | ||
saddlebrown: '#8b4513', | ||
salmon: '#fa8072', | ||
sandybrown: '#f4a460', | ||
seagreen: '#2e8b57', | ||
seashell: '#fff5ee', | ||
sienna: '#a0522d', | ||
silver: '#c0c0c0', | ||
skyblue: '#87ceeb', | ||
slateblue: '#6a5acd', | ||
slategray: '#708090', | ||
slategrey: '#708090', | ||
snow: '#fffafa', | ||
springgreen: '#00ff7f', | ||
steelblue: '#4682b4', | ||
tan: '#d2b48c', | ||
teal: '#008080', | ||
thistle: '#d8bfd8', | ||
tomato: '#ff6347', | ||
turquoise: '#40e0d0', | ||
violet: '#ee82ee', | ||
wheat: '#f5deb3', | ||
white: '#ffffff', | ||
whitesmoke: '#f5f5f5', | ||
yellow: '#ffff00', | ||
yellowgreen: '#9acd32' | ||
}; | ||
ONECOLOR.installMethod('clearer', function (amount) { | ||
amount = isNaN(amount) ? 0.1 : amount; | ||
return this.alpha(-amount, true); | ||
return this.alpha(isNaN(amount) ? -0.1 : -amount, true); | ||
}); | ||
@@ -1107,4 +537,3 @@ | ||
ONECOLOR.installMethod('darken', function (amount) { | ||
amount = isNaN(amount) ? 0.1 : amount; | ||
return this.lightness(-amount, true); | ||
return this.lightness(isNaN(amount) ? -0.1 : -amount, true); | ||
}); | ||
@@ -1114,4 +543,3 @@ | ||
ONECOLOR.installMethod('saturate', function (amount) { | ||
amount = isNaN(amount) ? 0.1 : amount; | ||
return this.saturation(-amount, true); | ||
return this.saturation(isNaN(amount) ? -0.1 : -amount, true); | ||
}); | ||
@@ -1131,15 +559,14 @@ | ||
ONECOLOR.installMethod('lighten', function (amount) { | ||
amount = isNaN(amount) ? 0.1 : amount; | ||
return this.lightness(amount, true); | ||
return this.lightness(isNaN(amount) ? 0.1 : amount, true); | ||
}); | ||
ONECOLOR.installMethod('mix', function (otherColor, weight) { | ||
var otherColor = ONECOLOR(otherColor), | ||
weight = 1 - (weight || 0.5), | ||
w = weight * 2 - 1, | ||
otherColor = ONECOLOR(otherColor).rgb(); | ||
weight = 1 - (weight || 0.5); | ||
var w = weight * 2 - 1, | ||
a = this._alpha - otherColor._alpha, | ||
weight1 = (((w * a == -1) ? w : (w + a) / (1 + w * a)) + 1) / 2, | ||
weight1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2, | ||
weight2 = 1 - weight1, | ||
rgb = this.rgb(), | ||
otherColor = otherColor.rgb(); | ||
rgb = this.rgb(); | ||
@@ -1160,9 +587,7 @@ return new ONECOLOR.RGB( | ||
ONECOLOR.installMethod('opaquer', function (amount) { | ||
amount = isNaN(amount) ? 0.1 : amount; | ||
return this.alpha(amount, true); | ||
return this.alpha(isNaN(amount) ? 0.1 : amount, true); | ||
}); | ||
ONECOLOR.installMethod('rotate', function (degrees) { | ||
amount = (degrees || 0) / 360; | ||
return this.hue(amount, true); | ||
return this.hue((degrees || 0) / 360, true); | ||
}); | ||
@@ -1172,4 +597,3 @@ | ||
ONECOLOR.installMethod('saturate', function (amount) { | ||
amount = isNaN(amount) ? 0.1 : amount; | ||
return this.saturation(amount, true); | ||
return this.saturation(isNaN(amount) ? 0.1 : amount, true); | ||
}); | ||
@@ -1216,3 +640,3 @@ | ||
channels.foreach(function (channel) { | ||
channels.forEach(function (channel) { | ||
me[channel] = (me[channel] - other[channel]) / me._alpha + other[channel]; | ||
@@ -1225,2 +649,4 @@ }); | ||
/*global one*/ | ||
// This file is purely for the build system | ||
@@ -1230,6 +656,1 @@ | ||
// Node module export | ||
if (typeof module !== 'undefined') { | ||
module.exports = ONECOLOR; | ||
} | ||
@@ -1,1 +0,1 @@ | ||
(function(a,b,c,d,e,f,g){function m(){var a=this.rgb(),b=a._red*.3+a._green*.59+a._blue*.11;return new l.RGB(b,b,b,this._alpha)}typeof one=="undefined"&&(one={include:function(){}});var h=[],i=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,j=/\s*(\.\d+|\d+(?:\.\d+)?)\s*/,k=new RegExp("^(rgb|hsl|hsv)a?\\("+i.source+","+i.source+","+i.source+"(?:,"+j.source+")?"+"\\)$","i"),l=one.color=function(a){if(Object.prototype.toString.apply(a)==="[object Array]")return a[0].length===4?new l.RGB(a[0]/255,a[1]/255,a[2]/255,a[3]/255):new l[a[0]](a.slice(1,a.length));if(a.charCodeAt){if(l.namedColors){var e=a.toLowerCase();l.namedColors[e]&&(a=l.namedColors[e])}var f=a.match(k);if(f){var g=f[1].toUpperCase(),h=typeof f[8]=="undefined"?f[8]:b(f[8]),i=g[0]==="H",j=f[3]?100:i?360:255,m=f[5]||i?100:255,n=f[7]||i?100:255;if(typeof l[g]=="undefined")throw new Error("one.color."+g+" is not installed.");return new l[g](b(f[2])/j,b(f[4])/m,b(f[6])/n,h)}a.length<6&&(a=a.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3"));var o=a.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(o)return new l.RGB(c(o[1],16)/255,c(o[2],16)/255,c(o[3],16)/255)}else{if(typeof a=="object"&&a.isColor)return a;if(!d(a))return new l.RGB((a&255)/255,((a&65280)>>8)/255,((a&16711680)>>16)/255)}return!1};l.installColorSpace=function(b,c,d){function j(b,c){var d={};d[c.toLowerCase()]=new a("return this.rgb()."+c.toLowerCase()+"();"),l[c].propertyNames.forEach(function(b,e){d[b]=new a("value","isDelta","return this."+c.toLowerCase()+"()."+b+"(value, isDelta);")});for(var e in d)d.hasOwnProperty(e)&&l[b].prototype[e]===undefined&&(l[b].prototype[e]=d[e])}l[b]=new a(c.join(","),"if (Object.prototype.toString.apply("+c[0]+") === '[object Array]') {"+c.map(function(a,b){return a+"="+c[0]+"["+b+"];"}).reverse().join("")+"}"+"if ("+c.filter(function(a){return a!=="alpha"}).map(function(a){return"isNaN("+a+")"}).join("||")+"){"+'throw new Error("[one.color.'+b+']: Invalid color: ("+'+c.join('+","+')+'+")");}'+c.map(function(a){return a==="hue"?"this._hue=hue<0?hue-Math.floor(hue):hue%1":a==="alpha"?"this._alpha=(isNaN(alpha)||alpha>1)?1:(alpha<0?0:alpha);":"this._"+a+"="+a+"<0?0:("+a+">1?1:"+a+")"}).join(";")+";"),l[b].propertyNames=c;var f=l[b].prototype;["valueOf","hex","css","cssa"].forEach(function(c){f[c]=f[c]||(b==="RGB"?f.hex:new a("return this.rgb()."+c+"();"))}),f.isColor=!0,f.equals=function(a,d){typeof d=="undefined"&&(d=1e-10),a=a[b.toLowerCase()]();for(var f=0;f<c.length;f+=1)if(e.abs(this["_"+c[f]]-a["_"+c[f]])>d)return!1;return!0},f.toJSON=new a("return ['"+b+"', "+c.map(function(a){return"this._"+a},this).join(", ")+"];");for(var g in d)if(d.hasOwnProperty(g)){var i=g.match(/^from(.*)$/);i?l[i[1].toUpperCase()].prototype[b.toLowerCase()]=d[g]:f[g]=d[g]}f[b.toLowerCase()]=function(){return this},f.toString=new a('return "[one.color.'+b+':"+'+c.map(function(a,b){return'" '+c[b]+'="+this._'+a}).join("+")+'+"]";'),c.forEach(function(b,d){f[b]=new a("value","isDelta","if (typeof value === 'undefined') {return this._"+b+";"+"}"+"if (isDelta) {"+"return new this.constructor("+c.map(function(a,c){return"this._"+a+(b===a?"+value":"")}).join(", ")+");"+"}"+"return new this.constructor("+c.map(function(a,c){return b===a?"value":"this._"+a}).join(", ")+");")}),h.forEach(function(a){j(b,a),j(a,b)}),h.push(b)},l.installMethod=function(a,b){h.forEach(function(c){l[c].prototype[a]=b})},l.installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var a=(f(255*this._red)*65536+f(255*this._green)*256+f(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-a.length)+a},css:function(){return"rgb("+f(255*this._red)+","+f(255*this._green)+","+f(255*this._blue)+")"},cssa:function(){return"rgba("+f(255*this._red)+","+f(255*this._green)+","+f(255*this._blue)+","+this._alpha+")"}}),l.installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var a=this._hue,b=this._saturation,c=this._value,d=g(5,e.floor(a*6)),f=a*6-d,h=c*(1-b),i=c*(1-f*b),j=c*(1-(1-f)*b),k,m,n;switch(d){case 0:k=c,m=j,n=h;break;case 1:k=i,m=c,n=h;break;case 2:k=h,m=c,n=j;break;case 3:k=h,m=i,n=c;break;case 4:k=j,m=h,n=c;break;case 5:k=c,m=h,n=i}return new l.RGB(k,m,n,this._alpha)},hsl:function(){var a=(2-this._saturation)*this._value,b=this._saturation*this._value,c=a<=1?a:2-a,d;return c<1e-9?d=0:d=b/c,new l.HSL(this._hue,d,a/2,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,d=e.max(a,b,c),f=g(a,b,c),h=d-f,i,j=d===0?0:h/d,k=d;if(h===0)i=0;else switch(d){case a:i=(b-c)/h/6+(b<c?1:0);break;case b:i=(c-a)/h/6+1/3;break;case c:i=(a-b)/h/6+2/3}return new l.HSV(i,j,k,this._alpha)}}),l.installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var a=this._lightness*2,b=this._saturation*(a<=1?a:2-a),c;return a+b<1e-9?c=0:c=2*b/(a+b),new l.HSV(this._hue,c,(a+b)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}}),l.installColorSpace("CMYK",["cyan","magenta","yellow","black","alpha"],{rgb:function(){return new l.RGB(1-this._cyan*(1-this._black)-this._black,1-this._magenta*(1-this._black)-this._black,1-this._yellow*(1-this._black)-this._black,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,d=1-a,e=1-b,f=1-c,h=1;return a||b||c?(h=g(d,g(e,f)),d=(d-h)/(1-h),e=(e-h)/(1-h),f=(f-h)/(1-h)):h=1,new l.CMYK(d,e,f,h,this._alpha)}}),l.namedColors={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgrey:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},l.installMethod("clearer",function(a){return a=d(a)?.1:a,this.alpha(-a,!0)}),l.installMethod("darken",function(a){return a=d(a)?.1:a,this.lightness(-a,!0)}),l.installMethod("saturate",function(a){return a=d(a)?.1:a,this.saturation(-a,!0)}),l.installMethod("greyscale",m),l.installMethod("grayscale",m),l.installMethod("lighten",function(a){return a=d(a)?.1:a,this.lightness(a,!0)}),l.installMethod("mix",function(a,b){var a=l(a),b=1-(b||.5),c=b*2-1,d=this._alpha-a._alpha,e=((c*d==-1?c:(c+d)/(1+c*d))+1)/2,f=1-e,g=this.rgb(),a=a.rgb();return new l.RGB(this._red*e+a._red*f,this._green*e+a._green*f,this._blue*e+a._blue*f,this._alpha*b+a._alpha*(1-b))}),l.installMethod("negate",function(){var a=this.rgb();return new l.RGB(1-a._red,1-a._green,1-a._blue,this._alpha)}),l.installMethod("opaquer",function(a){return a=d(a)?.1:a,this.alpha(a,!0)}),l.installMethod("rotate",function(a){return amount=(a||0)/360,this.hue(amount,!0)}),l.installMethod("saturate",function(a){return a=d(a)?.1:a,this.saturation(a,!0)}),l.installMethod("toAlpha",function(a){var b=this.rgb(),c=l(a).rgb(),d=1e-10,e=new l.RGB(0,0,0,b._alpha),f=["_red","_green","_blue"];return f.forEach(function(a){b[a]<d?e[a]=b[a]:b[a]>c[a]?e[a]=(b[a]-c[a])/(1-c[a]):b[a]>c[a]?e[a]=(c[a]-b[a])/c[a]:e[a]=0}),e._red>e._green?e._red>e._blue?b._alpha=e._red:b._alpha=e._blue:e._green>e._blue?b._alpha=e._green:b._alpha=e._blue,b._alpha<d?b:(f.foreach(function(a){b[a]=(b[a]-c[a])/b._alpha+c[a]}),b._alpha*=e._alpha,b)}),typeof module!="undefined"&&(module.exports=l)})(Function,parseFloat,parseInt,isNaN,Math,Math.round,Math.min) | ||
(function(a,b,c,d,e,f,g){function m(a){if(Object.prototype.toString.apply(a)==="[object Array]")return a[0].length===4?new m.RGB(a[0]/255,a[1]/255,a[2]/255,a[3]/255):new m[a[0]](a.slice(1,a.length));if(a.charCodeAt){var e=a.toLowerCase();i[e]&&(a=i[e]);var f=a.match(l);if(f){var g=f[1].toUpperCase(),h=typeof f[8]=="undefined"?f[8]:b(f[8]),j=g[0]==="H",k=f[3]?100:j?360:255,n=f[5]||j?100:255,o=f[7]||j?100:255;if(typeof m[g]=="undefined")throw new Error("one.color."+g+" is not installed.");return new m[g](b(f[2])/k,b(f[4])/n,b(f[6])/o,h)}a.length<6&&(a=a.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3"));var p=a.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(p)return new m.RGB(c(p[1],16)/255,c(p[2],16)/255,c(p[3],16)/255)}else{if(typeof a=="object"&&a.isColor)return a;if(!d(a))return new m.RGB((a&255)/255,((a&65280)>>8)/255,((a&16711680)>>16)/255)}return!1}function n(b,c,d){function j(b,c){var d={};d[c.toLowerCase()]=new a("return this.rgb()."+c.toLowerCase()+"();"),m[c].propertyNames.forEach(function(b,e){d[b]=new a("value","isDelta","return this."+c.toLowerCase()+"()."+b+"(value, isDelta);")});for(var e in d)d.hasOwnProperty(e)&&m[b].prototype[e]===undefined&&(m[b].prototype[e]=d[e])}m[b]=new a(c.join(","),"if (Object.prototype.toString.apply("+c[0]+") === '[object Array]') {"+c.map(function(a,b){return a+"="+c[0]+"["+b+"];"}).reverse().join("")+"}"+"if ("+c.filter(function(a){return a!=="alpha"}).map(function(a){return"isNaN("+a+")"}).join("||")+"){"+'throw new Error("['+b+']: Invalid color: ("+'+c.join('+","+')+'+")");}'+c.map(function(a){return a==="hue"?"this._hue=hue<0?hue-Math.floor(hue):hue%1":a==="alpha"?"this._alpha=(isNaN(alpha)||alpha>1)?1:(alpha<0?0:alpha);":"this._"+a+"="+a+"<0?0:("+a+">1?1:"+a+")"}).join(";")+";"),m[b].propertyNames=c;var f=m[b].prototype;["valueOf","hex","css","cssa"].forEach(function(c){f[c]=f[c]||(b==="RGB"?f.hex:new a("return this.rgb()."+c+"();"))}),f.isColor=!0,f.equals=function(a,d){typeof d=="undefined"&&(d=1e-10),a=a[b.toLowerCase()]();for(var f=0;f<c.length;f+=1)if(e.abs(this["_"+c[f]]-a["_"+c[f]])>d)return!1;return!0},f.toJSON=new a("return ['"+b+"', "+c.map(function(a){return"this._"+a},this).join(", ")+"];");for(var g in d)if(d.hasOwnProperty(g)){var i=g.match(/^from(.*)$/);i?m[i[1].toUpperCase()].prototype[b.toLowerCase()]=d[g]:f[g]=d[g]}f[b.toLowerCase()]=function(){return this},f.toString=new a('return "[one.color.'+b+':"+'+c.map(function(a,b){return'" '+c[b]+'="+this._'+a}).join("+")+'+"]";'),c.forEach(function(b,d){f[b]=new a("value","isDelta","if (typeof value === 'undefined') {return this._"+b+";"+"}"+"if (isDelta) {"+"return new this.constructor("+c.map(function(a,c){return"this._"+a+(b===a?"+value":"")}).join(", ")+");"+"}"+"return new this.constructor("+c.map(function(a,c){return b===a?"value":"this._"+a}).join(", ")+");")}),h.forEach(function(a){j(b,a),j(a,b)}),h.push(b)}function o(){var a=this.rgb(),b=a._red*.3+a._green*.59+a._blue*.11;return new m.RGB(b,b,b,this._alpha)}var h=[],i={},j=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,k=/\s*(\.\d+|\d+(?:\.\d+)?)\s*/,l=new RegExp("^(rgb|hsl|hsv)a?\\("+j.source+","+j.source+","+j.source+"(?:,"+k.source+")?"+"\\)$","i");m.installMethod=function(a,b){h.forEach(function(c){m[c].prototype[a]=b})},n("RGB",["red","green","blue","alpha"],{hex:function(){var a=(f(255*this._red)*65536+f(255*this._green)*256+f(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-a.length)+a},css:function(){return"rgb("+f(255*this._red)+","+f(255*this._green)+","+f(255*this._blue)+")"},cssa:function(){return"rgba("+f(255*this._red)+","+f(255*this._green)+","+f(255*this._blue)+","+this._alpha+")"}}),typeof module!="undefined"?module.exports=m:(one=one||{},one.color=m),i={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgrey:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},n("HSV",["hue","saturation","value","alpha"],{rgb:function(){var a=this._hue,b=this._saturation,c=this._value,d=g(5,e.floor(a*6)),f=a*6-d,h=c*(1-b),i=c*(1-f*b),j=c*(1-(1-f)*b),k,l,n;switch(d){case 0:k=c,l=j,n=h;break;case 1:k=i,l=c,n=h;break;case 2:k=h,l=c,n=j;break;case 3:k=h,l=i,n=c;break;case 4:k=j,l=h,n=c;break;case 5:k=c,l=h,n=i}return new m.RGB(k,l,n,this._alpha)},hsl:function(){var a=(2-this._saturation)*this._value,b=this._saturation*this._value,c=a<=1?a:2-a,d;return c<1e-9?d=0:d=b/c,new m.HSL(this._hue,d,a/2,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,d=e.max(a,b,c),f=g(a,b,c),h=d-f,i,j=d===0?0:h/d,k=d;if(h===0)i=0;else switch(d){case a:i=(b-c)/h/6+(b<c?1:0);break;case b:i=(c-a)/h/6+1/3;break;case c:i=(a-b)/h/6+2/3}return new m.HSV(i,j,k,this._alpha)}}),n("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var a=this._lightness*2,b=this._saturation*(a<=1?a:2-a),c;return a+b<1e-9?c=0:c=2*b/(a+b),new m.HSV(this._hue,c,(a+b)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}}),n("CMYK",["cyan","magenta","yellow","black","alpha"],{rgb:function(){return new m.RGB(1-this._cyan*(1-this._black)-this._black,1-this._magenta*(1-this._black)-this._black,1-this._yellow*(1-this._black)-this._black,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,d=1-a,e=1-b,f=1-c,h=1;return a||b||c?(h=g(d,g(e,f)),d=(d-h)/(1-h),e=(e-h)/(1-h),f=(f-h)/(1-h)):h=1,new m.CMYK(d,e,f,h,this._alpha)}}),m.installMethod("clearer",function(a){return this.alpha(d(a)?-0.1:-a,!0)}),m.installMethod("darken",function(a){return this.lightness(d(a)?-0.1:-a,!0)}),m.installMethod("saturate",function(a){return this.saturation(d(a)?-0.1:-a,!0)}),m.installMethod("greyscale",o),m.installMethod("grayscale",o),m.installMethod("lighten",function(a){return this.lightness(d(a)?.1:a,!0)}),m.installMethod("mix",function(a,b){a=m(a).rgb(),b=1-(b||.5);var c=b*2-1,d=this._alpha-a._alpha,e=((c*d===-1?c:(c+d)/(1+c*d))+1)/2,f=1-e,g=this.rgb();return new m.RGB(this._red*e+a._red*f,this._green*e+a._green*f,this._blue*e+a._blue*f,this._alpha*b+a._alpha*(1-b))}),m.installMethod("negate",function(){var a=this.rgb();return new m.RGB(1-a._red,1-a._green,1-a._blue,this._alpha)}),m.installMethod("opaquer",function(a){return this.alpha(d(a)?.1:a,!0)}),m.installMethod("rotate",function(a){return this.hue((a||0)/360,!0)}),m.installMethod("saturate",function(a){return this.saturation(d(a)?.1:a,!0)}),m.installMethod("toAlpha",function(a){var b=this.rgb(),c=m(a).rgb(),d=1e-10,e=new m.RGB(0,0,0,b._alpha),f=["_red","_green","_blue"];return f.forEach(function(a){b[a]<d?e[a]=b[a]:b[a]>c[a]?e[a]=(b[a]-c[a])/(1-c[a]):b[a]>c[a]?e[a]=(c[a]-b[a])/c[a]:e[a]=0}),e._red>e._green?e._red>e._blue?b._alpha=e._red:b._alpha=e._blue:e._green>e._blue?b._alpha=e._green:b._alpha=e._blue,b._alpha<d?b:(f.forEach(function(a){b[a]=(b[a]-c[a])/b._alpha+c[a]}),b._alpha*=e._alpha,b)})})(Function,parseFloat,parseInt,isNaN,Math,Math.round,Math.min) |
@@ -1,37 +0,3 @@ | ||
/*global one*/ | ||
/** | ||
* @namespace one One.com global JavaScript namespace. | ||
* @exports one | ||
*/ | ||
if (typeof one === 'undefined') { | ||
one = { | ||
include: function () {} | ||
}; | ||
} | ||
/*global one*/ | ||
/** | ||
* @namespace one.color | ||
*/ | ||
/** | ||
* Parse a hex string, 24-bit integer or object representing a color. | ||
* If a one.color.(RGB|HSL|HSV|CMYK) object is provided, it will be returned | ||
* as-is, so in library code you can use {@link one.color} to be flexible | ||
* about how colors are provided to you: | ||
* <pre><code> | ||
function foo (myColor) { | ||
myColor = color(myColor); | ||
// Now we are sure that myColor is a one.color.(RGB|CMYK|HSL|HSV) object, even if it was provided as a hex string. | ||
} | ||
* </code></pre> | ||
* @param {String|Object} obj A hex string, integer value, or | ||
* object to parse. | ||
* @return {one.color.RGB|one.color.HSL|one.color.HSV|one.color.CMYK} Color object representing the | ||
* parsed color, or false if the input couldn't be parsed. | ||
*/ | ||
var installedColorSpaces = [], | ||
namedColors = {}, | ||
channelRegExp = /\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/, | ||
@@ -46,63 +12,62 @@ alphaChannelRegExp = /\s*(\.\d+|\d+(?:\.\d+)?)\s*/, | ||
"(?:," + alphaChannelRegExp.source + ")?" + | ||
"\\)$", "i"), | ||
ONECOLOR = one.color = function (obj) { | ||
if (Object.prototype.toString.apply(obj) === '[object Array]') { | ||
if (obj[0].length === 4) { | ||
// Assumed 4 element int RGB array from canvas with all channels [0;255] | ||
return new ONECOLOR.RGB(obj[0] / 255, obj[1] / 255, obj[2] / 255, obj[3] / 255); | ||
} else { | ||
// Assumed destringified array from one.color.JSON() | ||
return new ONECOLOR[obj[0]](obj.slice(1, obj.length)); | ||
"\\)$", "i"); | ||
function ONECOLOR (obj) { | ||
if (Object.prototype.toString.apply(obj) === '[object Array]') { | ||
if (obj[0].length === 4) { | ||
// Assumed 4 element int RGB array from canvas with all channels [0;255] | ||
return new ONECOLOR.RGB(obj[0] / 255, obj[1] / 255, obj[2] / 255, obj[3] / 255); | ||
} else { | ||
// Assumed destringified array from one.color.JSON() | ||
return new ONECOLOR[obj[0]](obj.slice(1, obj.length)); | ||
} | ||
} else if (obj.charCodeAt) { | ||
var lowerCased = obj.toLowerCase(); | ||
if (namedColors[lowerCased]) { | ||
obj = namedColors[lowerCased]; | ||
} | ||
// Test for CSS rgb(....) string | ||
var matchCssSyntax = obj.match(cssColorRegExp); | ||
if (matchCssSyntax) { | ||
var colorSpaceName = matchCssSyntax[1].toUpperCase(), | ||
alpha = typeof matchCssSyntax[8] === 'undefined' ? matchCssSyntax[8] : parseFloat(matchCssSyntax[8]), | ||
hasHue = colorSpaceName[0] === 'H', | ||
firstChannelDivisor = matchCssSyntax[3] ? 100 : (hasHue ? 360 : 255), | ||
secondChannelDivisor = (matchCssSyntax[5] || hasHue) ? 100 : 255, | ||
thirdChannelDivisor = (matchCssSyntax[7] || hasHue) ? 100 : 255; | ||
if (typeof ONECOLOR[colorSpaceName] === 'undefined') { | ||
throw new Error("one.color." + colorSpaceName + " is not installed."); | ||
} | ||
} else if (obj.charCodeAt) { | ||
if (ONECOLOR.namedColors) { | ||
var lowerCased = obj.toLowerCase(); | ||
if (ONECOLOR.namedColors[lowerCased]) { | ||
obj = ONECOLOR.namedColors[lowerCased]; | ||
} | ||
} | ||
// Test for CSS rgb(....) string | ||
var matchCssSyntax = obj.match(cssColorRegExp); | ||
if (matchCssSyntax) { | ||
var colorSpaceName = matchCssSyntax[1].toUpperCase(), | ||
alpha = typeof matchCssSyntax[8] === 'undefined' ? matchCssSyntax[8] : parseFloat(matchCssSyntax[8]), | ||
hasHue = colorSpaceName[0] === 'H', | ||
firstChannelDivisor = matchCssSyntax[3] ? 100 : (hasHue ? 360 : 255), | ||
secondChannelDivisor = (matchCssSyntax[5] || hasHue) ? 100 : 255, | ||
thirdChannelDivisor = (matchCssSyntax[7] || hasHue) ? 100 : 255; | ||
if (typeof ONECOLOR[colorSpaceName] === 'undefined') { | ||
throw new Error("one.color." + colorSpaceName + " is not installed."); | ||
} | ||
return new ONECOLOR[colorSpaceName]( | ||
parseFloat(matchCssSyntax[2]) / firstChannelDivisor, | ||
parseFloat(matchCssSyntax[4]) / secondChannelDivisor, | ||
parseFloat(matchCssSyntax[6]) / thirdChannelDivisor, | ||
alpha | ||
); | ||
} | ||
// Assume hex syntax | ||
if (obj.length < 6) { | ||
// Allow CSS shorthand | ||
obj = obj.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i, '$1$1$2$2$3$3'); | ||
} | ||
// Split obj into red, green, and blue components | ||
var hexMatch = obj.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i); | ||
if (hexMatch) { | ||
return new ONECOLOR.RGB( | ||
parseInt(hexMatch[1], 16) / 255, | ||
parseInt(hexMatch[2], 16) / 255, | ||
parseInt(hexMatch[3], 16) / 255 | ||
); | ||
} | ||
} else if (typeof obj === 'object' && obj.isColor) { | ||
return obj; | ||
} else if (!isNaN(obj)) { | ||
// Strange integer representation sometimes returned by document.queryCommandValue in some browser... | ||
return new ONECOLOR.RGB((obj & 0xFF) / 255, ((obj & 0xFF00) >> 8) / 255, ((obj & 0xFF0000) >> 16) / 255); | ||
return new ONECOLOR[colorSpaceName]( | ||
parseFloat(matchCssSyntax[2]) / firstChannelDivisor, | ||
parseFloat(matchCssSyntax[4]) / secondChannelDivisor, | ||
parseFloat(matchCssSyntax[6]) / thirdChannelDivisor, | ||
alpha | ||
); | ||
} | ||
return false; | ||
}; | ||
// Assume hex syntax | ||
if (obj.length < 6) { | ||
// Allow CSS shorthand | ||
obj = obj.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i, '$1$1$2$2$3$3'); | ||
} | ||
// Split obj into red, green, and blue components | ||
var hexMatch = obj.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i); | ||
if (hexMatch) { | ||
return new ONECOLOR.RGB( | ||
parseInt(hexMatch[1], 16) / 255, | ||
parseInt(hexMatch[2], 16) / 255, | ||
parseInt(hexMatch[3], 16) / 255 | ||
); | ||
} | ||
} else if (typeof obj === 'object' && obj.isColor) { | ||
return obj; | ||
} else if (!isNaN(obj)) { | ||
// Strange integer representation sometimes returned by document.queryCommandValue in some browser... | ||
return new ONECOLOR.RGB((obj & 0xFF) / 255, ((obj & 0xFF00) >> 8) / 255, ((obj & 0xFF0000) >> 16) / 255); | ||
} | ||
return false; | ||
}; | ||
/*jslint evil:true*/ | ||
ONECOLOR.installColorSpace = function (colorSpaceName, propertyNames, config) { | ||
function installColorSpace(colorSpaceName, propertyNames, config) { | ||
ONECOLOR[colorSpaceName] = new Function(propertyNames.join(","), | ||
@@ -119,3 +84,3 @@ // Allow passing an array to the constructor: | ||
return "isNaN(" + propertyName + ")"; | ||
}).join("||") + "){" + "throw new Error(\"[one.color." + colorSpaceName + "]: Invalid color: (\"+" + propertyNames.join("+\",\"+") + "+\")\");}" + | ||
}).join("||") + "){" + "throw new Error(\"[" + colorSpaceName + "]: Invalid color: (\"+" + propertyNames.join("+\",\"+") + "+\")\");}" + | ||
propertyNames.map(function (propertyName) { | ||
@@ -230,35 +195,3 @@ if (propertyName === 'hue') { | ||
/** | ||
* @name one.color.RGB | ||
* @class | ||
* <p>A color in the RGB colorspace with an optional alpha value.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects are designed to be | ||
* immutable; all the conversion, set, and adjust methods return new | ||
* objects.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects automatically get the set | ||
* and adjust methods from all other installed colorspaces, so | ||
* although you can use the explicit conversion methods ({@link | ||
* one.color.RGB#hsl}, {@link one.color.RGB#cmyk}...), the below | ||
* will work just fine:</p><pre><code> | ||
new one.color.RGB(.4, .3, .9). | ||
lightness(+.2, true). // Implicit conversion to HSL | ||
red(-.1). // Implicit conversion back to RGB | ||
hex(); // "#00a6f2" | ||
</code></pre> | ||
* | ||
* @constructor | ||
* Create a new one.color.RGB object. Values outside the supported | ||
* range, [0..1], will be adjusted automatically. | ||
* @param {Number} red The red component, range: [0..1] | ||
* @param {Number} green The green component, range: [0..1] | ||
* @param {Number} blue The blue component, range: [0..1] | ||
* @param {Number} [alpha] The alpha value, range: [0..1], | ||
* defaults to 1 | ||
*/ | ||
ONECOLOR.installColorSpace('RGB', ['red', 'green', 'blue', 'alpha'], { | ||
/** | ||
* Get the standard RGB hex representation of the color. | ||
* @return {String} The hex string, e.g. "#f681df" | ||
*/ | ||
installColorSpace('RGB', ['red', 'green', 'blue', 'alpha'], { | ||
hex: function () { | ||
@@ -269,7 +202,2 @@ var hexString = (Math.round(255 * this._red) * 0x10000 + Math.round(255 * this._green) * 0x100 + Math.round(255 * this._blue)).toString(16); | ||
/** | ||
* Get a valid CSS color representation of the color without an | ||
* alpha value. | ||
* @return {String} The CSS color string, e.g. "rgb(123, 2, 202)" | ||
*/ | ||
css: function () { | ||
@@ -279,7 +207,2 @@ return "rgb(" + Math.round(255 * this._red) + "," + Math.round(255 * this._green) + "," + Math.round(255 * this._blue) + ")"; | ||
/** | ||
* Get a valid CSS color representation of the color, including | ||
* the alpha value. | ||
* @return {String} The CSS color string, e.g. "rgba(123, 2, 202, 0.253)" | ||
*/ | ||
cssa: function () { | ||
@@ -290,223 +213,14 @@ return "rgba(" + Math.round(255 * this._red) + "," + Math.round(255 * this._green) + "," + Math.round(255 * this._blue) + "," + this._alpha + ")"; | ||
/** | ||
* @name one.color.RGB.prototype.red | ||
* @function | ||
* @param {Number} red The new red component, range: [0..1]. If not | ||
* provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.RGB} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
if (typeof module !== 'undefined') { | ||
// Node module export | ||
module.exports = ONECOLOR; | ||
} else { | ||
// Browser | ||
one = one || {}; | ||
one.color = ONECOLOR; | ||
} | ||
/** | ||
* @name one.color.RGB.prototype.green | ||
* @function | ||
* @param {Number} green The new green component, range: [0..1] | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.RGB} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.blue | ||
* @function | ||
* @param {Number} blue The new blue component, range: [0..1] | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.RGB} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.alpha | ||
* @function | ||
* @param {Number} alpha The new alpha value, range: [0..1] | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.RGB} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.toJSON | ||
* @description Convert the color to a JSON representation. | ||
* @function | ||
* @return {Array} | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.rgb | ||
* @description Convert the color to a {@link one.color.RGB} object, ie. return the | ||
* object itself. | ||
* @function | ||
* @return {one.color.RGB} | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.hsv | ||
* @description Convert the color to a {@link one.color.HSV} object. | ||
* @function | ||
* @requires one.color.HSV | ||
* @return {one.color.HSV} | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.hsl | ||
* @description Convert the color to a {@link one.color.HSL} object. | ||
* @function | ||
* @requires one.color.HSL | ||
* @return {one.color.HSL} | ||
*/ | ||
/** | ||
* @name one.color.RGB.prototype.cmyk | ||
* @description Convert the color to a {@link one.color.CMYK} object. | ||
* @function | ||
* @requires one.color.CMYK | ||
* @return {one.color.CMYK} | ||
*/ | ||
/*global one*/ | ||
/** | ||
* @name one.color.HSV | ||
* @class | ||
* <p>A color in the HSV colorspace, with an optional alpha value.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects are designed to be | ||
* immutable; all the conversion, set, and adjust methods return new | ||
* objects.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects automatically get the set | ||
* and adjust methods from all other installed colorspaces, so | ||
* although you can use the explicit conversion methods ({@link | ||
* one.color.HSV#rgb}, {@link one.color.HSV#hsl}...), the below | ||
* will work just fine:</p><pre><code> | ||
new one.color.HSV(.9, .2, .4). | ||
blue(-.4, true). // Implicit conversion to RGB | ||
cyan(-.1). // Implicit conversion to CMYK | ||
hex(); // "#665200" | ||
</code></pre> | ||
* | ||
* @constructor | ||
* Create a new one.color.HSV object. Component values outside the | ||
* supported range, [0..1], will be adjusted automatically. | ||
* @param {Number} hue The hue component, range: [0..1] | ||
* @param {Number} saturation The saturation component, range: [0..1] | ||
* @param {Number} value The value component, range: [0..1] | ||
* @param {Number} [alpha] The alpha value, range: [0..1], | ||
* defaults to 1 | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.hue | ||
* @function | ||
* @param {Number} [hue] The new hue component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSV} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.saturation | ||
* @function | ||
* @param {Number} [saturation] The new saturation component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSV} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.value | ||
* @function | ||
* @param {Number} [value] The new value component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSV} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.alpha | ||
* @function | ||
* @param {Number} [alpha] The new alpha component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSV} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.toJSON | ||
* @description Convert the color to a JSON representation. | ||
* @function | ||
* @return {Array} | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.rgb | ||
* @description Convert the color to a {@link one.color.RGB} object. | ||
* @function | ||
* @return {one.color.RGB} | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.hsv | ||
* @description Convert the color to a {@link one.color.HSV} object, ie. return the object itself. | ||
* @function | ||
* @return {one.color.HSV} | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.hsl | ||
* @description Convert the color to a {@link one.color.HSL} object. | ||
* @function | ||
* @requires one.color.HSL | ||
* @return {one.color.HSL} | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.cmyk | ||
* @description Convert the color to a {@link one.color.CMYK} object. | ||
* @function | ||
* @include one.color.CMYK | ||
* @return {one.color.CMYK} | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.hex | ||
* @description Get the standard RGB hex representation of the color. | ||
* @function | ||
* @return {String} The hex string, e.g. "#f681df" | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.css | ||
* @description Get a valid CSS color representation of the color without an alpha value. | ||
* @function | ||
* @return {String} The CSS color string, e.g. "rgb(123, 2, 202)" | ||
*/ | ||
/** | ||
* @name one.color.HSV.prototype.cssa | ||
* @description Get a valid CSS color representation of the color, including the alpha value. | ||
* @function | ||
* @return {String} The CSS color string, e.g. "rgba(123, 2, 202, 0.253)" | ||
*/ | ||
ONECOLOR.installColorSpace('HSV', ['hue', 'saturation', 'value', 'alpha'], { | ||
installColorSpace('HSV', ['hue', 'saturation', 'value', 'alpha'], { | ||
rgb: function () { | ||
@@ -606,32 +320,3 @@ var hue = this._hue, | ||
/** | ||
* @name one.color.HSL | ||
* @class | ||
* <p>A color in the HSL colorspace, with an optional alpha value.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects are designed to be | ||
* immutable; all the conversion, set, and adjust methods return new | ||
* objects.</p> | ||
* <p>one.color.(RGB|HSL|HSV|CMYK) objects automatically get the set | ||
* and adjust methods from all other installed colorspaces, so | ||
* although you can use the explicit conversion methods ({@link | ||
* one.color.HSL#rgb}, {@link one.color.HSL#hsv}...), the below | ||
* will work just fine:</p><pre><code> | ||
new one.color.HSL(.4, .3, .9, .9). // HSL with alpha | ||
black(+.1, true). // Implicit conversion to CMYK (with alpha) | ||
green(-.1). // Implicit conversion to RGB (with alpha) | ||
cssa(); // "rgba(198,0,203,0.9)" | ||
</code></pre> | ||
* | ||
* @constructor | ||
* Create a new one.color.HSL object. Component values outside the | ||
* supported range, [0..1], will be adjusted automatically. | ||
* @param {Number} hue The hue component, range: [0..1] | ||
* @param {Number} saturation The saturation component, range: [0..1] | ||
* @param {Number} lightness The lightness component, range: [0..1] | ||
* @param {Number} [alpha] The alpha value, range: [0..1], | ||
* defaults to 1 | ||
*/ | ||
ONECOLOR.installColorSpace('HSL', ['hue', 'saturation', 'lightness', 'alpha'], { | ||
installColorSpace('HSL', ['hue', 'saturation', 'lightness', 'alpha'], { | ||
hsv: function () { | ||
@@ -662,113 +347,5 @@ // Algorithm adapted from http://wiki.secondlife.com/wiki/Color_conversion_scripts | ||
/** | ||
* @name one.color.HSL.prototype.hue | ||
* @function | ||
* @param {Number} [hue] The new hue component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSL} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/*global one*/ | ||
/** | ||
* @name one.color.HSL.prototype.saturation | ||
* @function | ||
* @param {Number} [saturation] The new saturation component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSL} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.lightness | ||
* @function | ||
* @param {Number} [lightness] The new lightness component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSL} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.alpha | ||
* @function | ||
* @param {Number} [alpha] The new alpha component, range: [0..1]. If | ||
* not provided, the current value will be returned. | ||
* @param {Boolean} [isDelta] Whether the new value is relative to the | ||
* old value of the property. If the resulting value falls outside the | ||
* supported range, [0..1], it will be adjusted automatically. | ||
* @return {Number|one.color.HSL} The current value of the property, | ||
* or a new color object with the changed value. | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.toJSON | ||
* @description Convert the color to a JSON representation. | ||
* @function | ||
* @return {Array} | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.rgb | ||
* @description Convert the color to a {@link one.color.RGB} object. | ||
* @function | ||
* @return {one.color.RGB} | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.hsv | ||
* @description Convert the color to a {@link one.color.HSV} object. | ||
* @function | ||
* @return {one.color.HSV} | ||
* @requires one.color.HSV | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.hsl | ||
* @description Convert the color to a {@link one.color.HSL} object, ie. return the object itself. | ||
* @function | ||
* @return {one.color.HSL} | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.cmyk | ||
* @description Convert the color to a {@link one.color.CMYK} object. | ||
* @function | ||
* @requires one.color.CMYK | ||
* @return {one.color.CMYK} | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.hex | ||
* @description Get the standard RGB hex representation of the color. | ||
* @function | ||
* @return {String} The hex string, e.g. "#f681df" | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.css | ||
* @description Get a valid CSS color representation of the color without an alpha value. | ||
* @function | ||
* @return {String} The CSS color string, e.g. "rgb(123, 2, 202)" | ||
*/ | ||
/** | ||
* @name one.color.HSL.prototype.cssa | ||
* @description Get a valid CSS color representation of the color, including the alpha value. | ||
* @function | ||
* @return {String} The CSS color string, e.g. "rgba(123, 2, 202, 0.253)" | ||
*/ | ||
// This file is purely for the build system | ||
if (typeof module !== 'undefined') { | ||
module.exports = ONECOLOR; | ||
} | ||
@@ -1,1 +0,1 @@ | ||
(function(a,b,c,d,e,f){typeof one=="undefined"&&(one={include:function(){}});var g=[],h=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,i=/\s*(\.\d+|\d+(?:\.\d+)?)\s*/,j=new RegExp("^(rgb|hsl|hsv)a?\\("+h.source+","+h.source+","+h.source+"(?:,"+i.source+")?"+"\\)$","i"),k=one.color=function(a){if(Object.prototype.toString.apply(a)==="[object Array]")return a[0].length===4?new k.RGB(a[0]/255,a[1]/255,a[2]/255,a[3]/255):new k[a[0]](a.slice(1,a.length));if(a.charCodeAt){if(k.namedColors){var d=a.toLowerCase();k.namedColors[d]&&(a=k.namedColors[d])}var e=a.match(j);if(e){var f=e[1].toUpperCase(),g=typeof e[8]=="undefined"?e[8]:b(e[8]),h=f[0]==="H",i=e[3]?100:h?360:255,l=e[5]||h?100:255,m=e[7]||h?100:255;if(typeof k[f]=="undefined")throw new Error("one.color."+f+" is not installed.");return new k[f](b(e[2])/i,b(e[4])/l,b(e[6])/m,g)}a.length<6&&(a=a.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3"));var n=a.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(n)return new k.RGB(c(n[1],16)/255,c(n[2],16)/255,c(n[3],16)/255)}else{if(typeof a=="object"&&a.isColor)return a;if(!isNaN(a))return new k.RGB((a&255)/255,((a&65280)>>8)/255,((a&16711680)>>16)/255)}return!1};k.installColorSpace=function(b,c,e){function j(b,c){var d={};d[c.toLowerCase()]=new a("return this.rgb()."+c.toLowerCase()+"();"),k[c].propertyNames.forEach(function(b,e){d[b]=new a("value","isDelta","return this."+c.toLowerCase()+"()."+b+"(value, isDelta);")});for(var e in d)d.hasOwnProperty(e)&&k[b].prototype[e]===undefined&&(k[b].prototype[e]=d[e])}k[b]=new a(c.join(","),"if (Object.prototype.toString.apply("+c[0]+") === '[object Array]') {"+c.map(function(a,b){return a+"="+c[0]+"["+b+"];"}).reverse().join("")+"}"+"if ("+c.filter(function(a){return a!=="alpha"}).map(function(a){return"isNaN("+a+")"}).join("||")+"){"+'throw new Error("[one.color.'+b+']: Invalid color: ("+'+c.join('+","+')+'+")");}'+c.map(function(a){return a==="hue"?"this._hue=hue<0?hue-Math.floor(hue):hue%1":a==="alpha"?"this._alpha=(isNaN(alpha)||alpha>1)?1:(alpha<0?0:alpha);":"this._"+a+"="+a+"<0?0:("+a+">1?1:"+a+")"}).join(";")+";"),k[b].propertyNames=c;var f=k[b].prototype;["valueOf","hex","css","cssa"].forEach(function(c){f[c]=f[c]||(b==="RGB"?f.hex:new a("return this.rgb()."+c+"();"))}),f.isColor=!0,f.equals=function(a,e){typeof e=="undefined"&&(e=1e-10),a=a[b.toLowerCase()]();for(var f=0;f<c.length;f+=1)if(d.abs(this["_"+c[f]]-a["_"+c[f]])>e)return!1;return!0},f.toJSON=new a("return ['"+b+"', "+c.map(function(a){return"this._"+a},this).join(", ")+"];");for(var h in e)if(e.hasOwnProperty(h)){var i=h.match(/^from(.*)$/);i?k[i[1].toUpperCase()].prototype[b.toLowerCase()]=e[h]:f[h]=e[h]}f[b.toLowerCase()]=function(){return this},f.toString=new a('return "[one.color.'+b+':"+'+c.map(function(a,b){return'" '+c[b]+'="+this._'+a}).join("+")+'+"]";'),c.forEach(function(b,d){f[b]=new a("value","isDelta","if (typeof value === 'undefined') {return this._"+b+";"+"}"+"if (isDelta) {"+"return new this.constructor("+c.map(function(a,c){return"this._"+a+(b===a?"+value":"")}).join(", ")+");"+"}"+"return new this.constructor("+c.map(function(a,c){return b===a?"value":"this._"+a}).join(", ")+");")}),g.forEach(function(a){j(b,a),j(a,b)}),g.push(b)},k.installMethod=function(a,b){g.forEach(function(c){k[c].prototype[a]=b})},k.installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var a=(e(255*this._red)*65536+e(255*this._green)*256+e(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-a.length)+a},css:function(){return"rgb("+e(255*this._red)+","+e(255*this._green)+","+e(255*this._blue)+")"},cssa:function(){return"rgba("+e(255*this._red)+","+e(255*this._green)+","+e(255*this._blue)+","+this._alpha+")"}}),k.installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var a=this._hue,b=this._saturation,c=this._value,e=f(5,d.floor(a*6)),g=a*6-e,h=c*(1-b),i=c*(1-g*b),j=c*(1-(1-g)*b),l,m,n;switch(e){case 0:l=c,m=j,n=h;break;case 1:l=i,m=c,n=h;break;case 2:l=h,m=c,n=j;break;case 3:l=h,m=i,n=c;break;case 4:l=j,m=h,n=c;break;case 5:l=c,m=h,n=i}return new k.RGB(l,m,n,this._alpha)},hsl:function(){var a=(2-this._saturation)*this._value,b=this._saturation*this._value,c=a<=1?a:2-a,d;return c<1e-9?d=0:d=b/c,new k.HSL(this._hue,d,a/2,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,e=d.max(a,b,c),g=f(a,b,c),h=e-g,i,j=e===0?0:h/e,l=e;if(h===0)i=0;else switch(e){case a:i=(b-c)/h/6+(b<c?1:0);break;case b:i=(c-a)/h/6+1/3;break;case c:i=(a-b)/h/6+2/3}return new k.HSV(i,j,l,this._alpha)}}),k.installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var a=this._lightness*2,b=this._saturation*(a<=1?a:2-a),c;return a+b<1e-9?c=0:c=2*b/(a+b),new k.HSV(this._hue,c,(a+b)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}}),typeof module!="undefined"&&(module.exports=k)})(Function,parseFloat,parseInt,Math,Math.round,Math.min) | ||
(function(a,b,c,d,e,f){function l(a){if(Object.prototype.toString.apply(a)==="[object Array]")return a[0].length===4?new l.RGB(a[0]/255,a[1]/255,a[2]/255,a[3]/255):new l[a[0]](a.slice(1,a.length));if(a.charCodeAt){var d=a.toLowerCase();h[d]&&(a=h[d]);var e=a.match(k);if(e){var f=e[1].toUpperCase(),g=typeof e[8]=="undefined"?e[8]:b(e[8]),i=f[0]==="H",j=e[3]?100:i?360:255,m=e[5]||i?100:255,n=e[7]||i?100:255;if(typeof l[f]=="undefined")throw new Error("one.color."+f+" is not installed.");return new l[f](b(e[2])/j,b(e[4])/m,b(e[6])/n,g)}a.length<6&&(a=a.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3"));var o=a.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(o)return new l.RGB(c(o[1],16)/255,c(o[2],16)/255,c(o[3],16)/255)}else{if(typeof a=="object"&&a.isColor)return a;if(!isNaN(a))return new l.RGB((a&255)/255,((a&65280)>>8)/255,((a&16711680)>>16)/255)}return!1}function m(b,c,e){function j(b,c){var d={};d[c.toLowerCase()]=new a("return this.rgb()."+c.toLowerCase()+"();"),l[c].propertyNames.forEach(function(b,e){d[b]=new a("value","isDelta","return this."+c.toLowerCase()+"()."+b+"(value, isDelta);")});for(var e in d)d.hasOwnProperty(e)&&l[b].prototype[e]===undefined&&(l[b].prototype[e]=d[e])}l[b]=new a(c.join(","),"if (Object.prototype.toString.apply("+c[0]+") === '[object Array]') {"+c.map(function(a,b){return a+"="+c[0]+"["+b+"];"}).reverse().join("")+"}"+"if ("+c.filter(function(a){return a!=="alpha"}).map(function(a){return"isNaN("+a+")"}).join("||")+"){"+'throw new Error("['+b+']: Invalid color: ("+'+c.join('+","+')+'+")");}'+c.map(function(a){return a==="hue"?"this._hue=hue<0?hue-Math.floor(hue):hue%1":a==="alpha"?"this._alpha=(isNaN(alpha)||alpha>1)?1:(alpha<0?0:alpha);":"this._"+a+"="+a+"<0?0:("+a+">1?1:"+a+")"}).join(";")+";"),l[b].propertyNames=c;var f=l[b].prototype;["valueOf","hex","css","cssa"].forEach(function(c){f[c]=f[c]||(b==="RGB"?f.hex:new a("return this.rgb()."+c+"();"))}),f.isColor=!0,f.equals=function(a,e){typeof e=="undefined"&&(e=1e-10),a=a[b.toLowerCase()]();for(var f=0;f<c.length;f+=1)if(d.abs(this["_"+c[f]]-a["_"+c[f]])>e)return!1;return!0},f.toJSON=new a("return ['"+b+"', "+c.map(function(a){return"this._"+a},this).join(", ")+"];");for(var h in e)if(e.hasOwnProperty(h)){var i=h.match(/^from(.*)$/);i?l[i[1].toUpperCase()].prototype[b.toLowerCase()]=e[h]:f[h]=e[h]}f[b.toLowerCase()]=function(){return this},f.toString=new a('return "[one.color.'+b+':"+'+c.map(function(a,b){return'" '+c[b]+'="+this._'+a}).join("+")+'+"]";'),c.forEach(function(b,d){f[b]=new a("value","isDelta","if (typeof value === 'undefined') {return this._"+b+";"+"}"+"if (isDelta) {"+"return new this.constructor("+c.map(function(a,c){return"this._"+a+(b===a?"+value":"")}).join(", ")+");"+"}"+"return new this.constructor("+c.map(function(a,c){return b===a?"value":"this._"+a}).join(", ")+");")}),g.forEach(function(a){j(b,a),j(a,b)}),g.push(b)}var g=[],h={},i=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,j=/\s*(\.\d+|\d+(?:\.\d+)?)\s*/,k=new RegExp("^(rgb|hsl|hsv)a?\\("+i.source+","+i.source+","+i.source+"(?:,"+j.source+")?"+"\\)$","i");l.installMethod=function(a,b){g.forEach(function(c){l[c].prototype[a]=b})},m("RGB",["red","green","blue","alpha"],{hex:function(){var a=(e(255*this._red)*65536+e(255*this._green)*256+e(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-a.length)+a},css:function(){return"rgb("+e(255*this._red)+","+e(255*this._green)+","+e(255*this._blue)+")"},cssa:function(){return"rgba("+e(255*this._red)+","+e(255*this._green)+","+e(255*this._blue)+","+this._alpha+")"}}),typeof module!="undefined"?module.exports=l:(one=one||{},one.color=l),m("HSV",["hue","saturation","value","alpha"],{rgb:function(){var a=this._hue,b=this._saturation,c=this._value,e=f(5,d.floor(a*6)),g=a*6-e,h=c*(1-b),i=c*(1-g*b),j=c*(1-(1-g)*b),k,m,n;switch(e){case 0:k=c,m=j,n=h;break;case 1:k=i,m=c,n=h;break;case 2:k=h,m=c,n=j;break;case 3:k=h,m=i,n=c;break;case 4:k=j,m=h,n=c;break;case 5:k=c,m=h,n=i}return new l.RGB(k,m,n,this._alpha)},hsl:function(){var a=(2-this._saturation)*this._value,b=this._saturation*this._value,c=a<=1?a:2-a,d;return c<1e-9?d=0:d=b/c,new l.HSL(this._hue,d,a/2,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,e=d.max(a,b,c),g=f(a,b,c),h=e-g,i,j=e===0?0:h/e,k=e;if(h===0)i=0;else switch(e){case a:i=(b-c)/h/6+(b<c?1:0);break;case b:i=(c-a)/h/6+1/3;break;case c:i=(a-b)/h/6+2/3}return new l.HSV(i,j,k,this._alpha)}}),m("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var a=this._lightness*2,b=this._saturation*(a<=1?a:2-a),c;return a+b<1e-9?c=0:c=2*b/(a+b),new l.HSV(this._hue,c,(a+b)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}})})(Function,parseFloat,parseInt,Math,Math.round,Math.min) |
@@ -5,3 +5,3 @@ { | ||
"repository": "git@github.com:One-com/one-color.git", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"keywords": ["ender", "color", "colour"], | ||
@@ -36,4 +36,4 @@ "maintainers": [ | ||
"scripts": { | ||
"prepublish": "make && vows" | ||
"prepublish": "make clean && make && vows" | ||
} | ||
} |
@@ -55,3 +55,3 @@ one.color | ||
colorspaces (`red()`, `green()`, `blue()`, `hue()`, `saturation()`, `lightness()`, | ||
`value()`, `alpha()`). Thus you don't need to think about which colorspace | ||
`value()`, `alpha()`, etc.). Thus you don't need to think about which colorspace | ||
you're in. All the necessary conversions happen automatically: | ||
@@ -105,3 +105,3 @@ | ||
If you need to know if two colors represent the same 8 bit color, regardless | ||
If you need to know whether two colors represent the same 8 bit color, regardless | ||
of colorspace, compare their `hex()` values: | ||
@@ -112,3 +112,3 @@ | ||
Use the `equals` method to compare two color instances within a certain | ||
epsilon (defaults to `1e-9`): | ||
epsilon (defaults to `1e-9`). | ||
@@ -118,3 +118,7 @@ one.color('#e00').lightness(.00001, true).equals(one.color('#e00'), 1e-5) // false | ||
Before comparing the `equals` method converts the other color to the right colorspace, | ||
so you don't need to convert explicitly in this case either: | ||
one.color('#e00').hsv().equals(one.color('#e00')) // true | ||
API overview | ||
@@ -121,0 +125,0 @@ ============ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
275
2347410
72
5065