Socket
Socket
Sign inDemoInstall

onecolor

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onecolor - npm Package Compare versions

Comparing version 3.1.0 to 4.0.0

one-color-all.js.map

44

index.js
module.exports = require('./lib/color')
.use(require('./lib/XYZ'))
.use(require('./lib/LAB'))
.use(require('./lib/HSV'))
.use(require('./lib/HSL'))
.use(require('./lib/CMYK'))
.use(require('./lib/XYZ'))
.use(require('./lib/LAB'))
.use(require('./lib/HSV'))
.use(require('./lib/HSL'))
.use(require('./lib/CMYK'))
// Convenience functions
.use(require('./lib/plugins/namedColors'))
.use(require('./lib/plugins/clearer.js'))
.use(require('./lib/plugins/contrast.js'))
.use(require('./lib/plugins/darken.js'))
.use(require('./lib/plugins/desaturate.js'))
.use(require('./lib/plugins/grayscale.js'))
.use(require('./lib/plugins/isDark.js'))
.use(require('./lib/plugins/isLight.js'))
.use(require('./lib/plugins/lighten.js'))
.use(require('./lib/plugins/luminance.js'))
.use(require('./lib/plugins/mix.js'))
.use(require('./lib/plugins/negate.js'))
.use(require('./lib/plugins/opaquer.js'))
.use(require('./lib/plugins/rotate.js'))
.use(require('./lib/plugins/saturate.js'))
.use(require('./lib/plugins/toAlpha.js'));
// Convenience functions
.use(require('./lib/plugins/namedColors'))
.use(require('./lib/plugins/clearer.js'))
.use(require('./lib/plugins/contrast.js'))
.use(require('./lib/plugins/darken.js'))
.use(require('./lib/plugins/desaturate.js'))
.use(require('./lib/plugins/grayscale.js'))
.use(require('./lib/plugins/isDark.js'))
.use(require('./lib/plugins/isLight.js'))
.use(require('./lib/plugins/lighten.js'))
.use(require('./lib/plugins/luminance.js'))
.use(require('./lib/plugins/mix.js'))
.use(require('./lib/plugins/negate.js'))
.use(require('./lib/plugins/opaquer.js'))
.use(require('./lib/plugins/rotate.js'))
.use(require('./lib/plugins/saturate.js'))
.use(require('./lib/plugins/toAlpha.js'));
module.exports = function CMYK(color) {
color.installColorSpace('CMYK', ['cyan', 'magenta', 'yellow', 'black', 'alpha'], {
rgb: function () {
return new color.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);
},
color.installColorSpace(
'CMYK',
['cyan', 'magenta', 'yellow', 'black', 'alpha'],
{
rgb: function () {
return new color.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 () { // Becomes one.color.RGB.prototype.cmyk
// Adapted from http://www.javascripter.net/faq/rgb2cmyk.htm
var red = this._red,
green = this._green,
blue = this._blue,
cyan = 1 - red,
magenta = 1 - green,
yellow = 1 - blue,
black = 1;
if (red || green || blue) {
black = Math.min(cyan, Math.min(magenta, yellow));
cyan = (cyan - black) / (1 - black);
magenta = (magenta - black) / (1 - black);
yellow = (yellow - black) / (1 - black);
} else {
black = 1;
}
return new color.CMYK(cyan, magenta, yellow, black, this._alpha);
fromRgb: function () {
// Becomes one.color.RGB.prototype.cmyk
// Adapted from http://www.javascripter.net/faq/rgb2cmyk.htm
var red = this._red;
var green = this._green;
var blue = this._blue;
var cyan = 1 - red;
var magenta = 1 - green;
var yellow = 1 - blue;
var black = 1;
if (red || green || blue) {
black = Math.min(cyan, Math.min(magenta, yellow));
cyan = (cyan - black) / (1 - black);
magenta = (magenta - black) / (1 - black);
yellow = (yellow - black) / (1 - black);
} else {
black = 1;
}
});
return new color.CMYK(cyan, magenta, yellow, black, this._alpha);
},
}
);
};

@@ -1,91 +0,123 @@

var installedColorSpaces = [],
undef = function (obj) {
return typeof obj === 'undefined';
},
channelRegExp = /\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,
percentageChannelRegExp = /\s*(\.\d+|100|\d?\d(?:\.\d+)?)%\s*/,
alphaChannelRegExp = /\s*(\.\d+|\d+(?:\.\d+)?)\s*/,
cssColorRegExp = new RegExp(
'^(rgb|hsl|hsv)a?' +
'\\(' +
channelRegExp.source + ',' +
channelRegExp.source + ',' +
channelRegExp.source +
'(?:,' + alphaChannelRegExp.source + ')?' +
'\\)$', 'i');
var installedColorSpaces = [];
var undef = function (obj) {
return typeof obj === 'undefined';
};
var channelRegExp = /\s*(\.\d+|\d+(?:\.\d+)?)(%|deg)?\s*/;
var percentageChannelRegExp = /\s*(\.\d+|100|\d?\d(?:\.\d+)?)%\s*/;
var cssColorRegExp = new RegExp(
'^(rgb|hsl|hsv)a?' +
'\\(' +
channelRegExp.source +
'[, ]' +
channelRegExp.source +
'[, ]' +
channelRegExp.source +
'(?:[,/]' +
channelRegExp.source +
')?' +
'\\)$',
'i'
);
function divisor(unit, channelNumber, hasHue) {
if (unit === '%') {
return 100;
} else if (unit === 'deg' || (hasHue && channelNumber === 0)) {
return 360;
} else if (!unit) {
return 255;
}
}
function color(obj) {
if (Array.isArray(obj)) {
if (typeof obj[0] === 'string' && typeof color[obj[0]] === 'function') {
// Assumed array from .toJSON()
return new color[obj[0]](obj.slice(1, obj.length));
} else if (obj.length === 4) {
// Assumed 4 element int RGB array from canvas with all channels [0;255]
return new color.RGB(obj[0] / 255, obj[1] / 255, obj[2] / 255, obj[3] / 255);
}
} else if (typeof obj === 'string') {
var lowerCased = obj.toLowerCase();
if (color.namedColors[lowerCased]) {
obj = '#' + color.namedColors[lowerCased];
}
if (lowerCased === 'transparent') {
obj = 'rgba(0,0,0,0)';
}
// Test for CSS rgb(....) string
var matchCssSyntax = obj.match(cssColorRegExp);
if (matchCssSyntax) {
var colorSpaceName = matchCssSyntax[1].toUpperCase(),
alpha = undef(matchCssSyntax[8]) ? 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 (undef(color[colorSpaceName])) {
throw new Error('color.' + colorSpaceName + ' is not installed.');
}
return new color[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 color.RGB(
parseInt(hexMatch[1], 16) / 255,
parseInt(hexMatch[2], 16) / 255,
parseInt(hexMatch[3], 16) / 255
);
}
if (Array.isArray(obj)) {
if (typeof obj[0] === 'string' && typeof color[obj[0]] === 'function') {
// Assumed array from .toJSON()
return new color[obj[0]](obj.slice(1, obj.length));
} else if (obj.length === 4) {
// Assumed 4 element int RGB array from canvas with all channels [0;255]
return new color.RGB(
obj[0] / 255,
obj[1] / 255,
obj[2] / 255,
obj[3] / 255
);
}
} else if (typeof obj === 'string') {
var lowerCased = obj.toLowerCase();
if (color.namedColors[lowerCased]) {
obj = '#' + color.namedColors[lowerCased];
}
if (lowerCased === 'transparent') {
obj = 'rgba(0,0,0,0)';
}
// Test for CSS rgb(....) string
var matchCssSyntax = obj.match(cssColorRegExp);
if (matchCssSyntax) {
var colorSpaceName = matchCssSyntax[1].toUpperCase();
var hasHue = colorSpaceName[0] === 'H';
if (undef(color[colorSpaceName])) {
throw new Error('color.' + colorSpaceName + ' is not installed.');
}
return new color[colorSpaceName](
parseFloat(matchCssSyntax[2]) / divisor(matchCssSyntax[3], 0, hasHue),
parseFloat(matchCssSyntax[4]) / divisor(matchCssSyntax[5], 1, hasHue),
parseFloat(matchCssSyntax[6]) / divisor(matchCssSyntax[7], 2, hasHue),
undef(matchCssSyntax[8])
? matchCssSyntax[8]
: parseFloat(matchCssSyntax[8]) / (matchCssSyntax[9] ? 100 : 255)
);
}
// Assume hex syntax
if (obj.length < 6) {
// Allow CSS shorthand
obj = obj.replace(
/^#?([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i,
'$1$1$2$2$3$3$4$4'
);
}
// Split obj into the red, green, blue, and optionally alpha component
var hexMatch = obj.match(
/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])?$/i
);
// No match so far. Lets try the less likely ones
if (color.CMYK) {
var cmykMatch = obj.match(new RegExp(
'^cmyk' +
'\\(' +
percentageChannelRegExp.source + ',' +
percentageChannelRegExp.source + ',' +
percentageChannelRegExp.source + ',' +
percentageChannelRegExp.source +
'\\)$', 'i'));
if (cmykMatch) {
return new color.CMYK(
parseFloat(cmykMatch[1]) / 100,
parseFloat(cmykMatch[2]) / 100,
parseFloat(cmykMatch[3]) / 100,
parseFloat(cmykMatch[4]) / 100
);
}
}
} else if (typeof obj === 'object' && obj.isColor) {
return obj;
if (hexMatch) {
return new color.RGB(
parseInt(hexMatch[1], 16) / 255,
parseInt(hexMatch[2], 16) / 255,
parseInt(hexMatch[3], 16) / 255,
hexMatch[4] ? parseInt(hexMatch[4], 16) / 255 : 1
);
}
return false;
// No match so far. Lets try the less likely ones
if (color.CMYK) {
var cmykMatch = obj.match(
new RegExp(
'^cmyk' +
'\\(' +
percentageChannelRegExp.source +
',' +
percentageChannelRegExp.source +
',' +
percentageChannelRegExp.source +
',' +
percentageChannelRegExp.source +
'\\)$',
'i'
)
);
if (cmykMatch) {
return new color.CMYK(
parseFloat(cmykMatch[1]) / 100,
parseFloat(cmykMatch[2]) / 100,
parseFloat(cmykMatch[3]) / 100,
parseFloat(cmykMatch[4]) / 100
);
}
}
} else if (typeof obj === 'object' && obj.isColor) {
return obj;
}
return false;
}

@@ -96,121 +128,172 @@

color.installColorSpace = function (colorSpaceName, propertyNames, config) {
color[colorSpaceName] = function (a1) { // ...
var args = Array.isArray(a1) ? a1 : arguments;
propertyNames.forEach(function (propertyName, i) {
var propertyValue = args[i];
if (propertyName === 'alpha') {
this._alpha = (isNaN(propertyValue) || propertyValue > 1) ? 1 : (propertyValue < 0 ? 0 : propertyValue);
} else {
if (isNaN(propertyValue)) {
throw new Error('[' + colorSpaceName + ']: Invalid color: (' + propertyNames.join(',') + ')');
}
if (propertyName === 'hue') {
this._hue = propertyValue < 0 ? propertyValue - Math.floor(propertyValue) : propertyValue % 1;
} else {
this['_' + propertyName] = propertyValue < 0 ? 0 : (propertyValue > 1 ? 1 : propertyValue);
}
}
}, this);
};
color[colorSpaceName].propertyNames = propertyNames;
color[colorSpaceName] = function (a1) {
// ...
var args = Array.isArray(a1) ? a1 : arguments;
propertyNames.forEach(function (propertyName, i) {
var propertyValue = args[i];
if (propertyName === 'alpha') {
this._alpha =
isNaN(propertyValue) || propertyValue > 1
? 1
: propertyValue < 0
? 0
: propertyValue;
} else {
if (isNaN(propertyValue)) {
throw new Error(
'[' +
colorSpaceName +
']: Invalid color: (' +
propertyNames.join(',') +
')'
);
}
if (propertyName === 'hue') {
this._hue =
propertyValue < 0
? propertyValue - Math.floor(propertyValue)
: propertyValue % 1;
} else {
this['_' + propertyName] =
propertyValue < 0 ? 0 : propertyValue > 1 ? 1 : propertyValue;
}
}
}, this);
};
color[colorSpaceName].propertyNames = propertyNames;
var prototype = color[colorSpaceName].prototype;
var prototype = color[colorSpaceName].prototype;
['valueOf', 'hex', 'hexa', 'css', 'cssa'].forEach(function (methodName) {
prototype[methodName] = prototype[methodName] || (colorSpaceName === 'RGB' ? prototype.hex : function () {
['valueOf', 'hex', 'hexa', 'css', 'cssa'].forEach(function (methodName) {
prototype[methodName] =
prototype[methodName] ||
(colorSpaceName === 'RGB'
? prototype.hex
: function () {
return this.rgb()[methodName]();
});
});
});
});
prototype.isColor = true;
prototype.isColor = true;
prototype.equals = function (otherColor, epsilon) {
if (undef(epsilon)) {
epsilon = 1e-10;
}
prototype.equals = function (otherColor, epsilon) {
if (undef(epsilon)) {
epsilon = 1e-10;
}
otherColor = otherColor[colorSpaceName.toLowerCase()]();
otherColor = otherColor[colorSpaceName.toLowerCase()]();
for (var i = 0; i < propertyNames.length; i = i + 1) {
if (Math.abs(this['_' + propertyNames[i]] - otherColor['_' + propertyNames[i]]) > epsilon) {
return false;
}
}
for (var i = 0; i < propertyNames.length; i = i + 1) {
if (
Math.abs(
this['_' + propertyNames[i]] - otherColor['_' + propertyNames[i]]
) > epsilon
) {
return false;
}
}
return true;
};
return true;
};
prototype.toJSON = function () {
return [colorSpaceName].concat(propertyNames.map(function (propertyName) {
return this['_' + propertyName];
}, this));
};
prototype.toJSON = function () {
return [colorSpaceName].concat(
propertyNames.map(function (propertyName) {
return this['_' + propertyName];
}, this)
);
};
for (var propertyName in config) {
if (config.hasOwnProperty(propertyName)) {
var matchFromColorSpace = propertyName.match(/^from(.*)$/);
if (matchFromColorSpace) {
color[matchFromColorSpace[1].toUpperCase()].prototype[colorSpaceName.toLowerCase()] = config[propertyName];
} else {
prototype[propertyName] = config[propertyName];
}
}
for (var propertyName in config) {
if (Object.prototype.hasOwnProperty.call(config, propertyName)) {
var matchFromColorSpace = propertyName.match(/^from(.*)$/);
if (matchFromColorSpace) {
color[matchFromColorSpace[1].toUpperCase()].prototype[
colorSpaceName.toLowerCase()
] = config[propertyName];
} else {
prototype[propertyName] = config[propertyName];
}
}
}
// It is pretty easy to implement the conversion to the same color space:
prototype[colorSpaceName.toLowerCase()] = function () {
return this;
// It is pretty easy to implement the conversion to the same color space:
prototype[colorSpaceName.toLowerCase()] = function () {
return this;
};
prototype.toString = function () {
return (
'[' +
colorSpaceName +
' ' +
propertyNames
.map(function (propertyName) {
return this['_' + propertyName];
}, this)
.join(', ') +
']'
);
};
// Generate getters and setters
propertyNames.forEach(function (propertyName) {
var shortName = propertyName === 'black' ? 'k' : propertyName.charAt(0);
prototype[propertyName] = prototype[shortName] = function (value, isDelta) {
// Simple getter mode: color.red()
if (typeof value === 'undefined') {
return this['_' + propertyName];
} else if (isDelta) {
// Adjuster: color.red(+.2, true)
return new this.constructor(
propertyNames.map(function (otherPropertyName) {
return (
this['_' + otherPropertyName] +
(propertyName === otherPropertyName ? value : 0)
);
}, this)
);
} else {
// Setter: color.red(.2);
return new this.constructor(
propertyNames.map(function (otherPropertyName) {
return propertyName === otherPropertyName
? value
: this['_' + otherPropertyName];
}, this)
);
}
};
prototype.toString = function () {
return '[' + colorSpaceName + ' ' + propertyNames.map(function (propertyName) {
return this['_' + propertyName];
}, this).join(', ') + ']';
});
function installForeignMethods(targetColorSpaceName, sourceColorSpaceName) {
var obj = {};
obj[sourceColorSpaceName.toLowerCase()] = function () {
return this.rgb()[sourceColorSpaceName.toLowerCase()]();
};
// Generate getters and setters
propertyNames.forEach(function (propertyName) {
var shortName = propertyName === 'black' ? 'k' : propertyName.charAt(0);
prototype[propertyName] = prototype[shortName] = function (value, isDelta) {
// Simple getter mode: color.red()
if (typeof value === 'undefined') {
return this['_' + propertyName];
} else if (isDelta) {
// Adjuster: color.red(+.2, true)
return new this.constructor(propertyNames.map(function (otherPropertyName) {
return this['_' + otherPropertyName] + (propertyName === otherPropertyName ? value : 0);
}, this));
} else {
// Setter: color.red(.2);
return new this.constructor(propertyNames.map(function (otherPropertyName) {
return (propertyName === otherPropertyName) ? value : this['_' + otherPropertyName];
}, this));
}
};
color[sourceColorSpaceName].propertyNames.forEach(function (propertyName) {
var shortName = propertyName === 'black' ? 'k' : propertyName.charAt(0);
obj[propertyName] = obj[shortName] = function (value, isDelta) {
return this[sourceColorSpaceName.toLowerCase()]()[propertyName](
value,
isDelta
);
};
});
function installForeignMethods(targetColorSpaceName, sourceColorSpaceName) {
var obj = {};
obj[sourceColorSpaceName.toLowerCase()] = function () {
return this.rgb()[sourceColorSpaceName.toLowerCase()]();
};
color[sourceColorSpaceName].propertyNames.forEach(function (propertyName) {
var shortName = propertyName === 'black' ? 'k' : propertyName.charAt(0);
obj[propertyName] = obj[shortName] = function (value, isDelta) {
return this[sourceColorSpaceName.toLowerCase()]()[propertyName](value, isDelta);
};
});
for (var prop in obj) {
if (obj.hasOwnProperty(prop) && color[targetColorSpaceName].prototype[prop] === undefined) {
color[targetColorSpaceName].prototype[prop] = obj[prop];
}
}
for (var prop in obj) {
if (
Object.prototype.hasOwnProperty.call(obj, prop) &&
color[targetColorSpaceName].prototype[prop] === undefined
) {
color[targetColorSpaceName].prototype[prop] = obj[prop];
}
}
}
installedColorSpaces.forEach(function (otherColorSpaceName) {
installForeignMethods(colorSpaceName, otherColorSpaceName);
installForeignMethods(otherColorSpaceName, colorSpaceName);
});
installedColorSpaces.forEach(function (otherColorSpaceName) {
installForeignMethods(colorSpaceName, otherColorSpaceName);
installForeignMethods(otherColorSpaceName, colorSpaceName);
});
installedColorSpaces.push(colorSpaceName);
return color;
installedColorSpaces.push(colorSpaceName);
return color;
};

@@ -221,36 +304,58 @@

color.use = function (plugin) {
if (color.pluginList.indexOf(plugin) === -1) {
this.pluginList.push(plugin);
plugin(color);
}
return color;
if (color.pluginList.indexOf(plugin) === -1) {
this.pluginList.push(plugin);
plugin(color);
}
return color;
};
color.installMethod = function (name, fn) {
installedColorSpaces.forEach(function (colorSpace) {
color[colorSpace].prototype[name] = fn;
});
return this;
installedColorSpaces.forEach(function (colorSpace) {
color[colorSpace].prototype[name] = fn;
});
return this;
};
color.installColorSpace('RGB', ['red', 'green', 'blue', 'alpha'], {
hex: function () {
var hexString = (Math.round(255 * this._red) * 0x10000 + Math.round(255 * this._green) * 0x100 + Math.round(255 * this._blue)).toString(16);
return '#' + ('00000'.substr(0, 6 - hexString.length)) + hexString;
},
hex: function () {
var hexString = (
Math.round(255 * this._red) * 0x10000 +
Math.round(255 * this._green) * 0x100 +
Math.round(255 * this._blue)
).toString(16);
return '#' + '00000'.substr(0, 6 - hexString.length) + hexString;
},
hexa: function () {
var alphaString = Math.round(this._alpha * 255).toString(16);
return '#' + '00'.substr(0, 2 - alphaString.length) + alphaString + this.hex().substr(1, 6);
},
hexa: function () {
var alphaString = Math.round(this._alpha * 255).toString(16);
return this.hex() + '00'.substr(0, 2 - alphaString.length) + alphaString;
},
css: function () {
return 'rgb(' + Math.round(255 * this._red) + ',' + Math.round(255 * this._green) + ',' + Math.round(255 * this._blue) + ')';
},
css: function () {
return (
'rgb(' +
Math.round(255 * this._red) +
',' +
Math.round(255 * this._green) +
',' +
Math.round(255 * this._blue) +
')'
);
},
cssa: function () {
return 'rgba(' + Math.round(255 * this._red) + ',' + Math.round(255 * this._green) + ',' + Math.round(255 * this._blue) + ',' + this._alpha + ')';
}
cssa: function () {
return (
'rgba(' +
Math.round(255 * this._red) +
',' +
Math.round(255 * this._green) +
',' +
Math.round(255 * this._blue) +
',' +
this._alpha +
')'
);
},
});
module.exports = color;
module.exports = function HSL(color) {
color.use(require('./HSV'));
color.use(require('./HSV'));
color.installColorSpace('HSL', ['hue', 'saturation', 'lightness', 'alpha'], {
hsv: function () {
// Algorithm adapted from http://wiki.secondlife.com/wiki/Color_conversion_scripts
var l = this._lightness * 2,
s = this._saturation * ((l <= 1) ? l : 2 - l),
saturation;
color.installColorSpace('HSL', ['hue', 'saturation', 'lightness', 'alpha'], {
hsv: function () {
// Algorithm adapted from http://wiki.secondlife.com/wiki/Color_conversion_scripts
var l = this._lightness * 2;
var s = this._saturation * (l <= 1 ? l : 2 - l);
var saturation;
// Avoid division by zero when l + s is very small (approaching black):
if (l + s < 1e-9) {
saturation = 0;
} else {
saturation = (2 * s) / (l + s);
}
// Avoid division by zero when l + s is very small (approaching black):
if (l + s < 1e-9) {
saturation = 0;
} else {
saturation = (2 * s) / (l + s);
}
return new color.HSV(this._hue, saturation, (l + s) / 2, this._alpha);
},
return new color.HSV(this._hue, saturation, (l + s) / 2, this._alpha);
},
rgb: function () {
return this.hsv().rgb();
},
rgb: function () {
return this.hsv().rgb();
},
fromRgb: function () { // Becomes one.color.RGB.prototype.hsv
return this.hsv().hsl();
}
});
fromRgb: function () {
// Becomes one.color.RGB.prototype.hsv
return this.hsv().hsl();
},
});
};
module.exports = function HSV(color) {
color.installColorSpace('HSV', ['hue', 'saturation', 'value', 'alpha'], {
rgb: function () {
var hue = this._hue,
saturation = this._saturation,
value = this._value,
i = Math.min(5, Math.floor(hue * 6)),
f = hue * 6 - i,
p = value * (1 - saturation),
q = value * (1 - f * saturation),
t = value * (1 - (1 - f) * saturation),
red,
green,
blue;
switch (i) {
case 0:
red = value;
green = t;
blue = p;
break;
case 1:
red = q;
green = value;
blue = p;
break;
case 2:
red = p;
green = value;
blue = t;
break;
case 3:
red = p;
green = q;
blue = value;
break;
case 4:
red = t;
green = p;
blue = value;
break;
case 5:
red = value;
green = p;
blue = q;
break;
}
return new color.RGB(red, green, blue, this._alpha);
},
color.installColorSpace('HSV', ['hue', 'saturation', 'value', 'alpha'], {
rgb: function () {
var hue = this._hue;
var saturation = this._saturation;
var value = this._value;
var i = Math.min(5, Math.floor(hue * 6));
var f = hue * 6 - i;
var p = value * (1 - saturation);
var q = value * (1 - f * saturation);
var t = value * (1 - (1 - f) * saturation);
var red;
var green;
var blue;
switch (i) {
case 0:
red = value;
green = t;
blue = p;
break;
case 1:
red = q;
green = value;
blue = p;
break;
case 2:
red = p;
green = value;
blue = t;
break;
case 3:
red = p;
green = q;
blue = value;
break;
case 4:
red = t;
green = p;
blue = value;
break;
case 5:
red = value;
green = p;
blue = q;
break;
}
return new color.RGB(red, green, blue, this._alpha);
},
hsl: function () {
var l = (2 - this._saturation) * this._value,
sv = this._saturation * this._value,
svDivisor = l <= 1 ? l : (2 - l),
saturation;
hsl: function () {
var l = (2 - this._saturation) * this._value;
var sv = this._saturation * this._value;
var svDivisor = l <= 1 ? l : 2 - l;
var saturation;
// Avoid division by zero when lightness approaches zero:
if (svDivisor < 1e-9) {
saturation = 0;
} else {
saturation = sv / svDivisor;
}
return new color.HSL(this._hue, saturation, l / 2, this._alpha);
},
// Avoid division by zero when lightness approaches zero:
if (svDivisor < 1e-9) {
saturation = 0;
} else {
saturation = sv / svDivisor;
}
return new color.HSL(this._hue, saturation, l / 2, this._alpha);
},
fromRgb: function () { // Becomes one.color.RGB.prototype.hsv
var red = this._red,
green = this._green,
blue = this._blue,
max = Math.max(red, green, blue),
min = Math.min(red, green, blue),
delta = max - min,
hue,
saturation = (max === 0) ? 0 : (delta / max),
value = max;
if (delta === 0) {
hue = 0;
} else {
switch (max) {
case red:
hue = (green - blue) / delta / 6 + (green < blue ? 1 : 0);
break;
case green:
hue = (blue - red) / delta / 6 + 1 / 3;
break;
case blue:
hue = (red - green) / delta / 6 + 2 / 3;
break;
}
}
return new color.HSV(hue, saturation, value, this._alpha);
fromRgb: function () {
// Becomes one.color.RGB.prototype.hsv
var red = this._red;
var green = this._green;
var blue = this._blue;
var max = Math.max(red, green, blue);
var min = Math.min(red, green, blue);
var delta = max - min;
var hue;
var saturation = max === 0 ? 0 : delta / max;
var value = max;
if (delta === 0) {
hue = 0;
} else {
switch (max) {
case red:
hue = (green - blue) / delta / 6 + (green < blue ? 1 : 0);
break;
case green:
hue = (blue - red) / delta / 6 + 1 / 3;
break;
case blue:
hue = (red - green) / delta / 6 + 2 / 3;
break;
}
});
}
return new color.HSV(hue, saturation, value, this._alpha);
},
});
};
module.exports = function LAB(color) {
color.use(require('./XYZ.js'));
color.use(require('./XYZ.js'));
color.installColorSpace('LAB', ['l', 'a', 'b', 'alpha'], {
fromRgb: function () {
return this.xyz().lab();
},
color.installColorSpace('LAB', ['l', 'a', 'b', 'alpha'], {
fromRgb: function () {
return this.xyz().lab();
},
rgb: function () {
return this.xyz().rgb();
},
rgb: function () {
return this.xyz().rgb();
},
xyz: function () {
// http://www.easyrgb.com/index.php?X=MATH&H=08#text8
var convert = function (channel) {
var pow = Math.pow(channel, 3);
return pow > 0.008856 ?
pow :
(channel - 16 / 116) / 7.87;
},
y = (this._l + 16) / 116,
x = this._a / 500 + y,
z = y - this._b / 200;
xyz: function () {
// http://www.easyrgb.com/index.php?X=MATH&H=08#text8
var convert = function (channel) {
var pow = Math.pow(channel, 3);
return pow > 0.008856 ? pow : (channel - 16 / 116) / 7.87;
};
var y = (this._l + 16) / 116;
var x = this._a / 500 + y;
var z = y - this._b / 200;
return new color.XYZ(
convert(x) * 95.047,
convert(y) * 100.000,
convert(z) * 108.883,
this._alpha
);
}
});
return new color.XYZ(
convert(x) * 95.047,
convert(y) * 100.0,
convert(z) * 108.883,
this._alpha
);
},
});
};
module.exports = function clearer(color) {
color.installMethod('clearer', function (amount) {
return this.alpha(isNaN(amount) ? -0.1 : -amount, true);
});
color.installMethod('clearer', function (amount) {
return this.alpha(isNaN(amount) ? -0.1 : -amount, true);
});
};
module.exports = function darken(color) {
color.use(require('../HSL'));
color.use(require('../HSL'));
color.installMethod('darken', function (amount) {
return this.lightness(isNaN(amount) ? -0.1 : -amount, true);
});
color.installMethod('darken', function (amount) {
return this.lightness(isNaN(amount) ? -0.1 : -amount, true);
});
};
module.exports = function desaturate(color) {
color.use(require('../HSL'));
color.use(require('../HSL'));
color.installMethod('desaturate', function (amount) {
return this.saturation(isNaN(amount) ? -0.1 : -amount, true);
});
color.installMethod('desaturate', function (amount) {
return this.saturation(isNaN(amount) ? -0.1 : -amount, true);
});
};
module.exports = function grayscale(color) {
function gs () {
/*jslint strict:false*/
var rgb = this.rgb(),
val = rgb._red * 0.3 + rgb._green * 0.59 + rgb._blue * 0.11;
function gs() {
/* jslint strict:false */
var rgb = this.rgb();
var val = rgb._red * 0.3 + rgb._green * 0.59 + rgb._blue * 0.11;
return new color.RGB(val, val, val, rgb._alpha);
}
return new color.RGB(val, val, val, rgb._alpha);
}
color.installMethod('greyscale', gs).installMethod('grayscale', gs);
color.installMethod('greyscale', gs).installMethod('grayscale', gs);
};
module.exports = function isDark(color) {
color.installMethod('isDark', function () {

@@ -7,5 +6,7 @@ var rgb = this.rgb();

// YIQ equation from http://24ways.org/2010/calculating-color-contrast
var yiq = (rgb._red * 255 * 299 + rgb._green * 255 * 587 + rgb._blue * 255 * 114) / 1000;
var yiq =
(rgb._red * 255 * 299 + rgb._green * 255 * 587 + rgb._blue * 255 * 114) /
1000;
return yiq < 128;
});
};
module.exports = function isLight(color) {
color.use(require('./isDark'));

@@ -4,0 +3,0 @@

module.exports = function lighten(color) {
color.use(require('../HSL'));
color.use(require('../HSL'));
color.installMethod('lighten', function (amount) {
return this.lightness(isNaN(amount) ? 0.1 : amount, true);
});
color.installMethod('lighten', function (amount) {
return this.lightness(isNaN(amount) ? 0.1 : amount, true);
});
};

@@ -5,3 +5,5 @@ module.exports = function luminance(color) {

function channelLuminance(value) {
return (value <= 0.03928) ? value / 12.92 : Math.pow(((value + 0.055) / 1.055), 2.4);
return value <= 0.03928
? value / 12.92
: Math.pow((value + 0.055) / 1.055, 2.4);
}

@@ -11,4 +13,8 @@

var rgb = this.rgb();
return 0.2126 * channelLuminance(rgb._red) + 0.7152 * channelLuminance(rgb._green) + 0.0722 * channelLuminance(rgb._blue);
return (
0.2126 * channelLuminance(rgb._red) +
0.7152 * channelLuminance(rgb._green) +
0.0722 * channelLuminance(rgb._blue)
);
});
};
module.exports = function mix(color) {
color.installMethod('mix', function (otherColor, weight) {
otherColor = color(otherColor).rgb();
weight = 1 - (isNaN(weight) ? 0.5 : weight);
color.installMethod('mix', function (otherColor, weight) {
otherColor = color(otherColor).rgb();
weight = 1 - (isNaN(weight) ? 0.5 : weight);
var w = weight * 2 - 1,
a = this._alpha - otherColor._alpha,
weight1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2,
weight2 = 1 - weight1,
rgb = this.rgb();
var w = weight * 2 - 1;
var a = this._alpha - otherColor._alpha;
var weight1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2;
var weight2 = 1 - weight1;
var rgb = this.rgb();
return new color.RGB(
rgb._red * weight1 + otherColor._red * weight2,
rgb._green * weight1 + otherColor._green * weight2,
rgb._blue * weight1 + otherColor._blue * weight2,
rgb._alpha * weight + otherColor._alpha * (1 - weight)
);
});
return new color.RGB(
rgb._red * weight1 + otherColor._red * weight2,
rgb._green * weight1 + otherColor._green * weight2,
rgb._blue * weight1 + otherColor._blue * weight2,
rgb._alpha * weight + otherColor._alpha * (1 - weight)
);
});
};
module.exports = function namedColors(color) {
color.namedColors = {
aliceblue: 'f0f8ff',
antiquewhite: 'faebd7',
aqua: '0ff',
aquamarine: '7fffd4',
azure: 'f0ffff',
beige: 'f5f5dc',
bisque: 'ffe4c4',
black: '000',
blanchedalmond: 'ffebcd',
blue: '00f',
blueviolet: '8a2be2',
brown: 'a52a2a',
burlywood: 'deb887',
cadetblue: '5f9ea0',
chartreuse: '7fff00',
chocolate: 'd2691e',
coral: 'ff7f50',
cornflowerblue: '6495ed',
cornsilk: 'fff8dc',
crimson: 'dc143c',
cyan: '0ff',
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: 'f0f',
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: '789',
lightslategrey: '789',
lightsteelblue: 'b0c4de',
lightyellow: 'ffffe0',
lime: '0f0',
limegreen: '32cd32',
linen: 'faf0e6',
magenta: 'f0f',
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',
rebeccapurple: '639',
red: 'f00',
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: 'fff',
whitesmoke: 'f5f5f5',
yellow: 'ff0',
yellowgreen: '9acd32'
};
color.namedColors = {
aliceblue: 'f0f8ff',
antiquewhite: 'faebd7',
aqua: '0ff',
aquamarine: '7fffd4',
azure: 'f0ffff',
beige: 'f5f5dc',
bisque: 'ffe4c4',
black: '000',
blanchedalmond: 'ffebcd',
blue: '00f',
blueviolet: '8a2be2',
brown: 'a52a2a',
burlywood: 'deb887',
cadetblue: '5f9ea0',
chartreuse: '7fff00',
chocolate: 'd2691e',
coral: 'ff7f50',
cornflowerblue: '6495ed',
cornsilk: 'fff8dc',
crimson: 'dc143c',
cyan: '0ff',
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: 'f0f',
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: '789',
lightslategrey: '789',
lightsteelblue: 'b0c4de',
lightyellow: 'ffffe0',
lime: '0f0',
limegreen: '32cd32',
linen: 'faf0e6',
magenta: 'f0f',
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',
rebeccapurple: '639',
red: 'f00',
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: 'fff',
whitesmoke: 'f5f5f5',
yellow: 'ff0',
yellowgreen: '9acd32',
};
};
module.exports = function negate(color) {
color.installMethod('negate', function () {
var rgb = this.rgb();
return new color.RGB(1 - rgb._red, 1 - rgb._green, 1 - rgb._blue, this._alpha);
});
color.installMethod('negate', function () {
var rgb = this.rgb();
return new color.RGB(
1 - rgb._red,
1 - rgb._green,
1 - rgb._blue,
this._alpha
);
});
};
module.exports = function opaquer(color) {
color.installMethod('opaquer', function (amount) {
return this.alpha(isNaN(amount) ? 0.1 : amount, true);
});
color.installMethod('opaquer', function (amount) {
return this.alpha(isNaN(amount) ? 0.1 : amount, true);
});
};
module.exports = function rotate(color) {
color.use(require('../HSL'));
color.use(require('../HSL'));
color.installMethod('rotate', function (degrees) {
return this.hue((degrees || 0) / 360, true);
});
color.installMethod('rotate', function (degrees) {
return this.hue((degrees || 0) / 360, true);
});
};
module.exports = function saturate(color) {
color.use(require('../HSL'));
color.use(require('../HSL'));
color.installMethod('saturate', function (amount) {
return this.saturation(isNaN(amount) ? 0.1 : amount, true);
});
color.installMethod('saturate', function (amount) {
return this.saturation(isNaN(amount) ? 0.1 : amount, true);
});
};
// Adapted from http://gimp.sourcearchive.com/documentation/2.6.6-1ubuntu1/color-to-alpha_8c-source.html
// toAlpha returns a color where the values of the argument have been converted to alpha
module.exports = function toAlpha(color) {
color.installMethod('toAlpha', function (color) {
var me = this.rgb(),
other = color(color).rgb(),
epsilon = 1e-10,
a = new color.RGB(0, 0, 0, me._alpha),
channels = ['_red', '_green', '_blue'];
color.installMethod('toAlpha', function (color) {
var me = this.rgb();
var other = color(color).rgb();
var epsilon = 1e-10;
var a = new color.RGB(0, 0, 0, me._alpha);
var channels = ['_red', '_green', '_blue'];
channels.forEach(function (channel) {
if (me[channel] < epsilon) {
a[channel] = me[channel];
} else if (me[channel] > other[channel]) {
a[channel] = (me[channel] - other[channel]) / (1 - other[channel]);
} else if (me[channel] > other[channel]) {
a[channel] = (other[channel] - me[channel]) / other[channel];
} else {
a[channel] = 0;
}
});
channels.forEach(function (channel) {
if (me[channel] < epsilon) {
a[channel] = me[channel];
} else if (me[channel] > other[channel]) {
a[channel] = (me[channel] - other[channel]) / (1 - other[channel]);
} else if (me[channel] > other[channel]) {
a[channel] = (other[channel] - me[channel]) / other[channel];
} else {
a[channel] = 0;
}
});
if (a._red > a._green) {
if (a._red > a._blue) {
me._alpha = a._red;
} else {
me._alpha = a._blue;
}
} else if (a._green > a._blue) {
me._alpha = a._green;
} else {
me._alpha = a._blue;
}
if (a._red > a._green) {
if (a._red > a._blue) {
me._alpha = a._red;
} else {
me._alpha = a._blue;
}
} else if (a._green > a._blue) {
me._alpha = a._green;
} else {
me._alpha = a._blue;
}
if (me._alpha < epsilon) {
return me;
}
if (me._alpha < epsilon) {
return me;
}
channels.forEach(function (channel) {
me[channel] = (me[channel] - other[channel]) / me._alpha + other[channel];
});
me._alpha *= a._alpha;
channels.forEach(function (channel) {
me[channel] = (me[channel] - other[channel]) / me._alpha + other[channel];
});
me._alpha *= a._alpha;
return me;
});
return me;
});
};
module.exports = function XYZ(color) {
color.installColorSpace('XYZ', ['x', 'y', 'z', 'alpha'], {
fromRgb: function () {
// http://www.easyrgb.com/index.php?X=MATH&H=02#text2
var convert = function (channel) {
return channel > 0.04045 ?
Math.pow((channel + 0.055) / 1.055, 2.4) :
channel / 12.92;
},
r = convert(this._red),
g = convert(this._green),
b = convert(this._blue);
color.installColorSpace('XYZ', ['x', 'y', 'z', 'alpha'], {
fromRgb: function () {
// http://www.easyrgb.com/index.php?X=MATH&H=02#text2
var convert = function (channel) {
return channel > 0.04045
? Math.pow((channel + 0.055) / 1.055, 2.4)
: channel / 12.92;
};
var r = convert(this._red);
var g = convert(this._green);
var b = convert(this._blue);
// Reference white point sRGB D65:
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
return new color.XYZ(
r * 0.4124564 + g * 0.3575761 + b * 0.1804375,
r * 0.2126729 + g * 0.7151522 + b * 0.0721750,
r * 0.0193339 + g * 0.1191920 + b * 0.9503041,
this._alpha
);
},
// Reference white point sRGB D65:
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
return new color.XYZ(
r * 0.4124564 + g * 0.3575761 + b * 0.1804375,
r * 0.2126729 + g * 0.7151522 + b * 0.072175,
r * 0.0193339 + g * 0.119192 + b * 0.9503041,
this._alpha
);
},
rgb: function () {
// http://www.easyrgb.com/index.php?X=MATH&H=01#text1
var x = this._x,
y = this._y,
z = this._z,
convert = function (channel) {
return channel > 0.0031308 ?
1.055 * Math.pow(channel, 1 / 2.4) - 0.055 :
12.92 * channel;
};
rgb: function () {
// http://www.easyrgb.com/index.php?X=MATH&H=01#text1
var x = this._x;
var y = this._y;
var z = this._z;
var convert = function (channel) {
return channel > 0.0031308
? 1.055 * Math.pow(channel, 1 / 2.4) - 0.055
: 12.92 * channel;
};
// Reference white point sRGB D65:
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
return new color.RGB(
convert(x * 3.2404542 + y * -1.5371385 + z * -0.4985314),
convert(x * -0.9692660 + y * 1.8760108 + z * 0.0415560),
convert(x * 0.0556434 + y * -0.2040259 + z * 1.0572252),
this._alpha
);
},
// Reference white point sRGB D65:
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
return new color.RGB(
convert(x * 3.2404542 + y * -1.5371385 + z * -0.4985314),
convert(x * -0.969266 + y * 1.8760108 + z * 0.041556),
convert(x * 0.0556434 + y * -0.2040259 + z * 1.0572252),
this._alpha
);
},
lab: function () {
// http://www.easyrgb.com/index.php?X=MATH&H=07#text7
var convert = function (channel) {
return channel > 0.008856 ?
Math.pow(channel, 1 / 3) :
7.787037 * channel + 4 / 29;
},
x = convert(this._x / 95.047),
y = convert(this._y / 100.000),
z = convert(this._z / 108.883);
lab: function () {
// http://www.easyrgb.com/index.php?X=MATH&H=07#text7
var convert = function (channel) {
return channel > 0.008856
? Math.pow(channel, 1 / 3)
: 7.787037 * channel + 4 / 29;
};
var x = convert(this._x / 95.047);
var y = convert(this._y / 100.0);
var z = convert(this._z / 108.883);
return new color.LAB(
(116 * y) - 16,
500 * (x - y),
200 * (y - z),
this._alpha
);
}
});
return new color.LAB(
116 * y - 16,
500 * (x - y),
200 * (y - z),
this._alpha
);
},
});
};
module.exports = require('./lib/color')
.use(require('./lib/HSV'))
.use(require('./lib/HSL'));
.use(require('./lib/HSV'))
.use(require('./lib/HSL'));

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e.one=e.one||{},e.one.color=t())}(this,function(){"use strict";function e(t){if(Array.isArray(t)){if("string"==typeof t[0]&&"function"==typeof e[t[0]])return new e[t[0]](t.slice(1,t.length));if(4===t.length)return new e.RGB(t[0]/255,t[1]/255,t[2]/255,t[3]/255)}else if("string"==typeof t){var r=t.toLowerCase();e.namedColors[r]&&(t="#"+e.namedColors[r]),"transparent"===r&&(t="rgba(0,0,0,0)");var o=t.match(i);if(o){var s=o[1].toUpperCase(),f=a(o[8])?o[8]:parseFloat(o[8]),u="H"===s[0],l=o[3]?100:u?360:255,h=o[5]||u?100:255,c=o[7]||u?100:255;if(a(e[s]))throw new Error("color."+s+" is not installed.");return new e[s](parseFloat(o[2])/l,parseFloat(o[4])/h,parseFloat(o[6])/c,f)}t.length<6&&(t=t.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3"));var d=t.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(d)return new e.RGB(parseInt(d[1],16)/255,parseInt(d[2],16)/255,parseInt(d[3],16)/255);if(e.CMYK){var b=t.match(new RegExp("^cmyk\\("+n.source+","+n.source+","+n.source+","+n.source+"\\)$","i"));if(b)return new e.CMYK(parseFloat(b[1])/100,parseFloat(b[2])/100,parseFloat(b[3])/100,parseFloat(b[4])/100)}}else if("object"==typeof t&&t.isColor)return t;return!1}var t=[],a=function(e){return void 0===e},r=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,n=/\s*(\.\d+|100|\d?\d(?:\.\d+)?)%\s*/,i=new RegExp("^(rgb|hsl|hsv)a?\\("+r.source+","+r.source+","+r.source+"(?:,"+/\s*(\.\d+|\d+(?:\.\d+)?)\s*/.source+")?\\)$","i");e.namedColors={},e.installColorSpace=function(r,n,i){function o(t,a){var r={};r[a.toLowerCase()]=function(){return this.rgb()[a.toLowerCase()]()},e[a].propertyNames.forEach(function(e){var t="black"===e?"k":e.charAt(0);r[e]=r[t]=function(t,r){return this[a.toLowerCase()]()[e](t,r)}});for(var n in r)r.hasOwnProperty(n)&&void 0===e[t].prototype[n]&&(e[t].prototype[n]=r[n])}e[r]=function(e){var t=Array.isArray(e)?e:arguments;n.forEach(function(e,a){var i=t[a];if("alpha"===e)this._alpha=isNaN(i)||i>1?1:i<0?0:i;else{if(isNaN(i))throw new Error("["+r+"]: Invalid color: ("+n.join(",")+")");"hue"===e?this._hue=i<0?i-Math.floor(i):i%1:this["_"+e]=i<0?0:i>1?1:i}},this)},e[r].propertyNames=n;var s=e[r].prototype;["valueOf","hex","hexa","css","cssa"].forEach(function(e){s[e]=s[e]||("RGB"===r?s.hex:function(){return this.rgb()[e]()})}),s.isColor=!0,s.equals=function(e,t){a(t)&&(t=1e-10),e=e[r.toLowerCase()]();for(var i=0;i<n.length;i+=1)if(Math.abs(this["_"+n[i]]-e["_"+n[i]])>t)return!1;return!0},s.toJSON=function(){return[r].concat(n.map(function(e){return this["_"+e]},this))};for(var f in i)if(i.hasOwnProperty(f)){var u=f.match(/^from(.*)$/);u?e[u[1].toUpperCase()].prototype[r.toLowerCase()]=i[f]:s[f]=i[f]}return s[r.toLowerCase()]=function(){return this},s.toString=function(){return"["+r+" "+n.map(function(e){return this["_"+e]},this).join(", ")+"]"},n.forEach(function(e){var t="black"===e?"k":e.charAt(0);s[e]=s[t]=function(t,a){return void 0===t?this["_"+e]:a?new this.constructor(n.map(function(a){return this["_"+a]+(e===a?t:0)},this)):new this.constructor(n.map(function(a){return e===a?t:this["_"+a]},this))}}),t.forEach(function(e){o(r,e),o(e,r)}),t.push(r),e},e.pluginList=[],e.use=function(t){return-1===e.pluginList.indexOf(t)&&(this.pluginList.push(t),t(e)),e},e.installMethod=function(a,r){return t.forEach(function(t){e[t].prototype[a]=r}),this},e.installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var e=(65536*Math.round(255*this._red)+256*Math.round(255*this._green)+Math.round(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-e.length)+e},hexa:function(){var e=Math.round(255*this._alpha).toString(16);return"#"+"00".substr(0,2-e.length)+e+this.hex().substr(1,6)},css:function(){return"rgb("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+")"},cssa:function(){return"rgba("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+","+this._alpha+")"}});var o=e,s=function(e){e.installColorSpace("XYZ",["x","y","z","alpha"],{fromRgb:function(){var t=function(e){return e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92},a=t(this._red),r=t(this._green),n=t(this._blue);return new e.XYZ(.4124564*a+.3575761*r+.1804375*n,.2126729*a+.7151522*r+.072175*n,.0193339*a+.119192*r+.9503041*n,this._alpha)},rgb:function(){var t=this._x,a=this._y,r=this._z,n=function(e){return e>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e};return new e.RGB(n(3.2404542*t+-1.5371385*a+-.4985314*r),n(-.969266*t+1.8760108*a+.041556*r),n(.0556434*t+-.2040259*a+1.0572252*r),this._alpha)},lab:function(){var t=function(e){return e>.008856?Math.pow(e,1/3):7.787037*e+4/29},a=t(this._x/95.047),r=t(this._y/100),n=t(this._z/108.883);return new e.LAB(116*r-16,500*(a-r),200*(r-n),this._alpha)}})},f=function(e){e.use(s),e.installColorSpace("LAB",["l","a","b","alpha"],{fromRgb:function(){return this.xyz().lab()},rgb:function(){return this.xyz().rgb()},xyz:function(){var t=function(e){var t=Math.pow(e,3);return t>.008856?t:(e-16/116)/7.87},a=(this._l+16)/116,r=this._a/500+a,n=a-this._b/200;return new e.XYZ(95.047*t(r),100*t(a),108.883*t(n),this._alpha)}})},u=function(e){e.installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var t,a,r,n=this._hue,i=this._saturation,o=this._value,s=Math.min(5,Math.floor(6*n)),f=6*n-s,u=o*(1-i),l=o*(1-f*i),h=o*(1-(1-f)*i);switch(s){case 0:t=o,a=h,r=u;break;case 1:t=l,a=o,r=u;break;case 2:t=u,a=o,r=h;break;case 3:t=u,a=l,r=o;break;case 4:t=h,a=u,r=o;break;case 5:t=o,a=u,r=l}return new e.RGB(t,a,r,this._alpha)},hsl:function(){var t,a=(2-this._saturation)*this._value,r=this._saturation*this._value,n=a<=1?a:2-a;return t=n<1e-9?0:r/n,new e.HSL(this._hue,t,a/2,this._alpha)},fromRgb:function(){var t,a=this._red,r=this._green,n=this._blue,i=Math.max(a,r,n),o=Math.min(a,r,n),s=i-o,f=0===i?0:s/i,u=i;if(0===s)t=0;else switch(i){case a:t=(r-n)/s/6+(r<n?1:0);break;case r:t=(n-a)/s/6+1/3;break;case n:t=(a-r)/s/6+2/3}return new e.HSV(t,f,u,this._alpha)}})},l=function(e){e.use(u),e.installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var t,a=2*this._lightness,r=this._saturation*(a<=1?a:2-a);return t=a+r<1e-9?0:2*r/(a+r),new e.HSV(this._hue,t,(a+r)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}})},h=function(e){e.installColorSpace("CMYK",["cyan","magenta","yellow","black","alpha"],{rgb:function(){return new e.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 t=this._red,a=this._green,r=this._blue,n=1-t,i=1-a,o=1-r,s=1;return t||a||r?(s=Math.min(n,Math.min(i,o)),n=(n-s)/(1-s),i=(i-s)/(1-s),o=(o-s)/(1-s)):s=1,new e.CMYK(n,i,o,s,this._alpha)}})},c=function(e){e.namedColors={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",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:"f0f",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:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",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",rebeccapurple:"639",red:"f00",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:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"}},d=function(e){e.installMethod("clearer",function(e){return this.alpha(isNaN(e)?-.1:-e,!0)})},b=function(e){function t(e){return e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}e.installMethod("luminance",function(){var e=this.rgb();return.2126*t(e._red)+.7152*t(e._green)+.0722*t(e._blue)})},g=function(e){e.use(b),e.installMethod("contrast",function(e){var t=this.luminance(),a=e.luminance();return t>a?(t+.05)/(a+.05):(a+.05)/(t+.05)})},p=function(e){e.use(l),e.installMethod("darken",function(e){return this.lightness(isNaN(e)?-.1:-e,!0)})},_=function(e){e.use(l),e.installMethod("desaturate",function(e){return this.saturation(isNaN(e)?-.1:-e,!0)})},m=function(e){function t(){var t=this.rgb(),a=.3*t._red+.59*t._green+.11*t._blue;return new e.RGB(a,a,a,t._alpha)}e.installMethod("greyscale",t).installMethod("grayscale",t)},w=function(e){e.installMethod("isDark",function(){var e=this.rgb();return(255*e._red*299+255*e._green*587+255*e._blue*114)/1e3<128})},y=function(e){e.use(w),e.installMethod("isLight",function(){return!this.isDark()})},v=function(e){e.use(l),e.installMethod("lighten",function(e){return this.lightness(isNaN(e)?.1:e,!0)})},k=function(e){e.installMethod("mix",function(t,a){t=e(t).rgb(),a=1-(isNaN(a)?.5:a);var r=2*a-1,n=this._alpha-t._alpha,i=((r*n==-1?r:(r+n)/(1+r*n))+1)/2,o=1-i,s=this.rgb();return new e.RGB(s._red*i+t._red*o,s._green*i+t._green*o,s._blue*i+t._blue*o,s._alpha*a+t._alpha*(1-a))})},M=function(e){e.installMethod("negate",function(){var t=this.rgb();return new e.RGB(1-t._red,1-t._green,1-t._blue,this._alpha)})},C=function(e){e.installMethod("opaquer",function(e){return this.alpha(isNaN(e)?.1:e,!0)})},N=function(e){e.use(l),e.installMethod("rotate",function(e){return this.hue((e||0)/360,!0)})},x=function(e){e.use(l),e.installMethod("saturate",function(e){return this.saturation(isNaN(e)?.1:e,!0)})},R=function(e){e.installMethod("toAlpha",function(e){var t=this.rgb(),a=e(e).rgb(),r=new e.RGB(0,0,0,t._alpha),n=["_red","_green","_blue"];return n.forEach(function(e){t[e]<1e-10?r[e]=t[e]:t[e]>a[e]?r[e]=(t[e]-a[e])/(1-a[e]):t[e]>a[e]?r[e]=(a[e]-t[e])/a[e]:r[e]=0}),r._red>r._green?r._red>r._blue?t._alpha=r._red:t._alpha=r._blue:r._green>r._blue?t._alpha=r._green:t._alpha=r._blue,t._alpha<1e-10?t:(n.forEach(function(e){t[e]=(t[e]-a[e])/t._alpha+a[e]}),t._alpha*=r._alpha,t)})};return o.use(s).use(f).use(u).use(l).use(h).use(c).use(d).use(g).use(p).use(_).use(m).use(w).use(y).use(v).use(b).use(k).use(M).use(C).use(N).use(x).use(R)});
//# sourceMappingURL=one-color-all.map
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).one=e.one||{},e.one.color=t())}(this,(function(){"use strict";var e=[],t=function(e){return void 0===e},a=/\s*(\.\d+|\d+(?:\.\d+)?)(%|deg)?\s*/,r=/\s*(\.\d+|100|\d?\d(?:\.\d+)?)%\s*/,n=new RegExp("^(rgb|hsl|hsv)a?\\("+a.source+"[, ]"+a.source+"[, ]"+a.source+"(?:[,/]"+a.source+")?\\)$","i");function i(e,t,a){return"%"===e?100:"deg"===e||a&&0===t?360:e?void 0:255}function o(e){if(Array.isArray(e)){if("string"==typeof e[0]&&"function"==typeof o[e[0]])return new o[e[0]](e.slice(1,e.length));if(4===e.length)return new o.RGB(e[0]/255,e[1]/255,e[2]/255,e[3]/255)}else if("string"==typeof e){var a=e.toLowerCase();o.namedColors[a]&&(e="#"+o.namedColors[a]),"transparent"===a&&(e="rgba(0,0,0,0)");var s=e.match(n);if(s){var f=s[1].toUpperCase(),u="H"===f[0];if(t(o[f]))throw new Error("color."+f+" is not installed.");return new o[f](parseFloat(s[2])/i(s[3],0,u),parseFloat(s[4])/i(s[5],1,u),parseFloat(s[6])/i(s[7],2,u),t(s[8])?s[8]:parseFloat(s[8])/(s[9]?100:255))}e.length<6&&(e=e.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i,"$1$1$2$2$3$3$4$4"));var l=e.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])?$/i);if(l)return new o.RGB(parseInt(l[1],16)/255,parseInt(l[2],16)/255,parseInt(l[3],16)/255,l[4]?parseInt(l[4],16)/255:1);if(o.CMYK){var h=e.match(new RegExp("^cmyk\\("+r.source+","+r.source+","+r.source+","+r.source+"\\)$","i"));if(h)return new o.CMYK(parseFloat(h[1])/100,parseFloat(h[2])/100,parseFloat(h[3])/100,parseFloat(h[4])/100)}}else if("object"==typeof e&&e.isColor)return e;return!1}o.namedColors={},o.installColorSpace=function(a,r,n){o[a]=function(e){var t=Array.isArray(e)?e:arguments;r.forEach((function(e,n){var i=t[n];if("alpha"===e)this._alpha=isNaN(i)||i>1?1:i<0?0:i;else{if(isNaN(i))throw new Error("["+a+"]: Invalid color: ("+r.join(",")+")");"hue"===e?this._hue=i<0?i-Math.floor(i):i%1:this["_"+e]=i<0?0:i>1?1:i}}),this)},o[a].propertyNames=r;var i=o[a].prototype;for(var s in["valueOf","hex","hexa","css","cssa"].forEach((function(e){i[e]=i[e]||("RGB"===a?i.hex:function(){return this.rgb()[e]()})})),i.isColor=!0,i.equals=function(e,n){t(n)&&(n=1e-10),e=e[a.toLowerCase()]();for(var i=0;i<r.length;i+=1)if(Math.abs(this["_"+r[i]]-e["_"+r[i]])>n)return!1;return!0},i.toJSON=function(){return[a].concat(r.map((function(e){return this["_"+e]}),this))},n)if(Object.prototype.hasOwnProperty.call(n,s)){var f=s.match(/^from(.*)$/);f?o[f[1].toUpperCase()].prototype[a.toLowerCase()]=n[s]:i[s]=n[s]}function u(e,t){var a={};for(var r in a[t.toLowerCase()]=function(){return this.rgb()[t.toLowerCase()]()},o[t].propertyNames.forEach((function(e){var r="black"===e?"k":e.charAt(0);a[e]=a[r]=function(a,r){return this[t.toLowerCase()]()[e](a,r)}})),a)Object.prototype.hasOwnProperty.call(a,r)&&void 0===o[e].prototype[r]&&(o[e].prototype[r]=a[r])}return i[a.toLowerCase()]=function(){return this},i.toString=function(){return"["+a+" "+r.map((function(e){return this["_"+e]}),this).join(", ")+"]"},r.forEach((function(e){var t="black"===e?"k":e.charAt(0);i[e]=i[t]=function(t,a){return void 0===t?this["_"+e]:a?new this.constructor(r.map((function(a){return this["_"+a]+(e===a?t:0)}),this)):new this.constructor(r.map((function(a){return e===a?t:this["_"+a]}),this))}})),e.forEach((function(e){u(a,e),u(e,a)})),e.push(a),o},o.pluginList=[],o.use=function(e){return-1===o.pluginList.indexOf(e)&&(this.pluginList.push(e),e(o)),o},o.installMethod=function(t,a){return e.forEach((function(e){o[e].prototype[t]=a})),this},o.installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var e=(65536*Math.round(255*this._red)+256*Math.round(255*this._green)+Math.round(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-e.length)+e},hexa:function(){var e=Math.round(255*this._alpha).toString(16);return this.hex()+"00".substr(0,2-e.length)+e},css:function(){return"rgb("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+")"},cssa:function(){return"rgba("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+","+this._alpha+")"}});var s=function(e){e.installColorSpace("XYZ",["x","y","z","alpha"],{fromRgb:function(){var t=function(e){return e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92},a=t(this._red),r=t(this._green),n=t(this._blue);return new e.XYZ(.4124564*a+.3575761*r+.1804375*n,.2126729*a+.7151522*r+.072175*n,.0193339*a+.119192*r+.9503041*n,this._alpha)},rgb:function(){var t=this._x,a=this._y,r=this._z,n=function(e){return e>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e};return new e.RGB(n(3.2404542*t+-1.5371385*a+-.4985314*r),n(-.969266*t+1.8760108*a+.041556*r),n(.0556434*t+-.2040259*a+1.0572252*r),this._alpha)},lab:function(){var t=function(e){return e>.008856?Math.pow(e,1/3):7.787037*e+4/29},a=t(this._x/95.047),r=t(this._y/100),n=t(this._z/108.883);return new e.LAB(116*r-16,500*(a-r),200*(r-n),this._alpha)}})},f=function(e){e.installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var t,a,r,n=this._hue,i=this._saturation,o=this._value,s=Math.min(5,Math.floor(6*n)),f=6*n-s,u=o*(1-i),l=o*(1-f*i),h=o*(1-(1-f)*i);switch(s){case 0:t=o,a=h,r=u;break;case 1:t=l,a=o,r=u;break;case 2:t=u,a=o,r=h;break;case 3:t=u,a=l,r=o;break;case 4:t=h,a=u,r=o;break;case 5:t=o,a=u,r=l}return new e.RGB(t,a,r,this._alpha)},hsl:function(){var t,a=(2-this._saturation)*this._value,r=this._saturation*this._value,n=a<=1?a:2-a;return t=n<1e-9?0:r/n,new e.HSL(this._hue,t,a/2,this._alpha)},fromRgb:function(){var t,a=this._red,r=this._green,n=this._blue,i=Math.max(a,r,n),o=i-Math.min(a,r,n),s=0===i?0:o/i,f=i;if(0===o)t=0;else switch(i){case a:t=(r-n)/o/6+(r<n?1:0);break;case r:t=(n-a)/o/6+1/3;break;case n:t=(a-r)/o/6+2/3}return new e.HSV(t,s,f,this._alpha)}})},u=function(e){e.use(f),e.installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var t,a=2*this._lightness,r=this._saturation*(a<=1?a:2-a);return t=a+r<1e-9?0:2*r/(a+r),new e.HSV(this._hue,t,(a+r)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}})},l=function(e){function t(e){return e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}e.installMethod("luminance",(function(){var e=this.rgb();return.2126*t(e._red)+.7152*t(e._green)+.0722*t(e._blue)}))},h=function(e){e.installMethod("isDark",(function(){var e=this.rgb();return(255*e._red*299+255*e._green*587+255*e._blue*114)/1e3<128}))};return o.use(s).use((function(e){e.use(s),e.installColorSpace("LAB",["l","a","b","alpha"],{fromRgb:function(){return this.xyz().lab()},rgb:function(){return this.xyz().rgb()},xyz:function(){var t=function(e){var t=Math.pow(e,3);return t>.008856?t:(e-16/116)/7.87},a=(this._l+16)/116,r=this._a/500+a,n=a-this._b/200;return new e.XYZ(95.047*t(r),100*t(a),108.883*t(n),this._alpha)}})})).use(f).use(u).use((function(e){e.installColorSpace("CMYK",["cyan","magenta","yellow","black","alpha"],{rgb:function(){return new e.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 t=this._red,a=this._green,r=this._blue,n=1-t,i=1-a,o=1-r,s=1;return t||a||r?(n=(n-(s=Math.min(n,Math.min(i,o))))/(1-s),i=(i-s)/(1-s),o=(o-s)/(1-s)):s=1,new e.CMYK(n,i,o,s,this._alpha)}})})).use((function(e){e.namedColors={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",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:"f0f",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:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",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",rebeccapurple:"639",red:"f00",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:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"}})).use((function(e){e.installMethod("clearer",(function(e){return this.alpha(isNaN(e)?-.1:-e,!0)}))})).use((function(e){e.use(l),e.installMethod("contrast",(function(e){var t=this.luminance(),a=e.luminance();return t>a?(t+.05)/(a+.05):(a+.05)/(t+.05)}))})).use((function(e){e.use(u),e.installMethod("darken",(function(e){return this.lightness(isNaN(e)?-.1:-e,!0)}))})).use((function(e){e.use(u),e.installMethod("desaturate",(function(e){return this.saturation(isNaN(e)?-.1:-e,!0)}))})).use((function(e){function t(){var t=this.rgb(),a=.3*t._red+.59*t._green+.11*t._blue;return new e.RGB(a,a,a,t._alpha)}e.installMethod("greyscale",t).installMethod("grayscale",t)})).use(h).use((function(e){e.use(h),e.installMethod("isLight",(function(){return!this.isDark()}))})).use((function(e){e.use(u),e.installMethod("lighten",(function(e){return this.lightness(isNaN(e)?.1:e,!0)}))})).use(l).use((function(e){e.installMethod("mix",(function(t,a){t=e(t).rgb();var r=2*(a=1-(isNaN(a)?.5:a))-1,n=this._alpha-t._alpha,i=((r*n==-1?r:(r+n)/(1+r*n))+1)/2,o=1-i,s=this.rgb();return new e.RGB(s._red*i+t._red*o,s._green*i+t._green*o,s._blue*i+t._blue*o,s._alpha*a+t._alpha*(1-a))}))})).use((function(e){e.installMethod("negate",(function(){var t=this.rgb();return new e.RGB(1-t._red,1-t._green,1-t._blue,this._alpha)}))})).use((function(e){e.installMethod("opaquer",(function(e){return this.alpha(isNaN(e)?.1:e,!0)}))})).use((function(e){e.use(u),e.installMethod("rotate",(function(e){return this.hue((e||0)/360,!0)}))})).use((function(e){e.use(u),e.installMethod("saturate",(function(e){return this.saturation(isNaN(e)?.1:e,!0)}))})).use((function(e){e.installMethod("toAlpha",(function(e){var t=this.rgb(),a=e(e).rgb(),r=new e.RGB(0,0,0,t._alpha),n=["_red","_green","_blue"];return n.forEach((function(e){t[e]<1e-10?r[e]=t[e]:t[e]>a[e]?r[e]=(t[e]-a[e])/(1-a[e]):t[e]>a[e]?r[e]=(a[e]-t[e])/a[e]:r[e]=0})),r._red>r._green?r._red>r._blue?t._alpha=r._red:t._alpha=r._blue:r._green>r._blue?t._alpha=r._green:t._alpha=r._blue,t._alpha<1e-10||(n.forEach((function(e){t[e]=(t[e]-a[e])/t._alpha+a[e]})),t._alpha*=r._alpha),t}))}))}));
//# sourceMappingURL=one-color-all.js.map

@@ -1,2 +0,2 @@

!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t.one=t.one||{},t.one.color=r())}(this,function(){"use strict";function t(r){if(Array.isArray(r)){if("string"==typeof r[0]&&"function"==typeof t[r[0]])return new t[r[0]](r.slice(1,r.length));if(4===r.length)return new t.RGB(r[0]/255,r[1]/255,r[2]/255,r[3]/255)}else if("string"==typeof r){var n=r.toLowerCase();t.namedColors[n]&&(r="#"+t.namedColors[n]),"transparent"===n&&(r="rgba(0,0,0,0)");var s=r.match(o);if(s){var i=s[1].toUpperCase(),u=e(s[8])?s[8]:parseFloat(s[8]),h="H"===i[0],c=s[3]?100:h?360:255,f=s[5]||h?100:255,l=s[7]||h?100:255;if(e(t[i]))throw new Error("color."+i+" is not installed.");return new t[i](parseFloat(s[2])/c,parseFloat(s[4])/f,parseFloat(s[6])/l,u)}r.length<6&&(r=r.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3"));var p=r.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(p)return new t.RGB(parseInt(p[1],16)/255,parseInt(p[2],16)/255,parseInt(p[3],16)/255);if(t.CMYK){var d=r.match(new RegExp("^cmyk\\("+a.source+","+a.source+","+a.source+","+a.source+"\\)$","i"));if(d)return new t.CMYK(parseFloat(d[1])/100,parseFloat(d[2])/100,parseFloat(d[3])/100,parseFloat(d[4])/100)}}else if("object"==typeof r&&r.isColor)return r;return!1}var r=[],e=function(t){return void 0===t},n=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,a=/\s*(\.\d+|100|\d?\d(?:\.\d+)?)%\s*/,o=new RegExp("^(rgb|hsl|hsv)a?\\("+n.source+","+n.source+","+n.source+"(?:,"+/\s*(\.\d+|\d+(?:\.\d+)?)\s*/.source+")?\\)$","i");t.namedColors={},t.installColorSpace=function(n,a,o){function s(r,e){var n={};n[e.toLowerCase()]=function(){return this.rgb()[e.toLowerCase()]()},t[e].propertyNames.forEach(function(t){var r="black"===t?"k":t.charAt(0);n[t]=n[r]=function(r,n){return this[e.toLowerCase()]()[t](r,n)}});for(var a in n)n.hasOwnProperty(a)&&void 0===t[r].prototype[a]&&(t[r].prototype[a]=n[a])}t[n]=function(t){var r=Array.isArray(t)?t:arguments;a.forEach(function(t,e){var o=r[e];if("alpha"===t)this._alpha=isNaN(o)||o>1?1:o<0?0:o;else{if(isNaN(o))throw new Error("["+n+"]: Invalid color: ("+a.join(",")+")");"hue"===t?this._hue=o<0?o-Math.floor(o):o%1:this["_"+t]=o<0?0:o>1?1:o}},this)},t[n].propertyNames=a;var i=t[n].prototype;["valueOf","hex","hexa","css","cssa"].forEach(function(t){i[t]=i[t]||("RGB"===n?i.hex:function(){return this.rgb()[t]()})}),i.isColor=!0,i.equals=function(t,r){e(r)&&(r=1e-10),t=t[n.toLowerCase()]();for(var o=0;o<a.length;o+=1)if(Math.abs(this["_"+a[o]]-t["_"+a[o]])>r)return!1;return!0},i.toJSON=function(){return[n].concat(a.map(function(t){return this["_"+t]},this))};for(var u in o)if(o.hasOwnProperty(u)){var h=u.match(/^from(.*)$/);h?t[h[1].toUpperCase()].prototype[n.toLowerCase()]=o[u]:i[u]=o[u]}return i[n.toLowerCase()]=function(){return this},i.toString=function(){return"["+n+" "+a.map(function(t){return this["_"+t]},this).join(", ")+"]"},a.forEach(function(t){var r="black"===t?"k":t.charAt(0);i[t]=i[r]=function(r,e){return void 0===r?this["_"+t]:e?new this.constructor(a.map(function(e){return this["_"+e]+(t===e?r:0)},this)):new this.constructor(a.map(function(e){return t===e?r:this["_"+e]},this))}}),r.forEach(function(t){s(n,t),s(t,n)}),r.push(n),t},t.pluginList=[],t.use=function(r){return-1===t.pluginList.indexOf(r)&&(this.pluginList.push(r),r(t)),t},t.installMethod=function(e,n){return r.forEach(function(r){t[r].prototype[e]=n}),this},t.installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var t=(65536*Math.round(255*this._red)+256*Math.round(255*this._green)+Math.round(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-t.length)+t},hexa:function(){var t=Math.round(255*this._alpha).toString(16);return"#"+"00".substr(0,2-t.length)+t+this.hex().substr(1,6)},css:function(){return"rgb("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+")"},cssa:function(){return"rgba("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+","+this._alpha+")"}});var s=t,i=function(t){t.installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var r,e,n,a=this._hue,o=this._saturation,s=this._value,i=Math.min(5,Math.floor(6*a)),u=6*a-i,h=s*(1-o),c=s*(1-u*o),f=s*(1-(1-u)*o);switch(i){case 0:r=s,e=f,n=h;break;case 1:r=c,e=s,n=h;break;case 2:r=h,e=s,n=f;break;case 3:r=h,e=c,n=s;break;case 4:r=f,e=h,n=s;break;case 5:r=s,e=h,n=c}return new t.RGB(r,e,n,this._alpha)},hsl:function(){var r,e=(2-this._saturation)*this._value,n=this._saturation*this._value,a=e<=1?e:2-e;return r=a<1e-9?0:n/a,new t.HSL(this._hue,r,e/2,this._alpha)},fromRgb:function(){var r,e=this._red,n=this._green,a=this._blue,o=Math.max(e,n,a),s=Math.min(e,n,a),i=o-s,u=0===o?0:i/o,h=o;if(0===i)r=0;else switch(o){case e:r=(n-a)/i/6+(n<a?1:0);break;case n:r=(a-e)/i/6+1/3;break;case a:r=(e-n)/i/6+2/3}return new t.HSV(r,u,h,this._alpha)}})},u=function(t){t.use(i),t.installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var r,e=2*this._lightness,n=this._saturation*(e<=1?e:2-e);return r=e+n<1e-9?0:2*n/(e+n),new t.HSV(this._hue,r,(e+n)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}})};return s.use(i).use(u)});
//# sourceMappingURL=one-color.map
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):((t="undefined"!=typeof globalThis?globalThis:t||self).one=t.one||{},t.one.color=r())}(this,(function(){"use strict";var t=[],r=function(t){return void 0===t},e=/\s*(\.\d+|\d+(?:\.\d+)?)(%|deg)?\s*/,n=/\s*(\.\d+|100|\d?\d(?:\.\d+)?)%\s*/,a=new RegExp("^(rgb|hsl|hsv)a?\\("+e.source+"[, ]"+e.source+"[, ]"+e.source+"(?:[,/]"+e.source+")?\\)$","i");function o(t,r,e){return"%"===t?100:"deg"===t||e&&0===r?360:t?void 0:255}function s(t){if(Array.isArray(t)){if("string"==typeof t[0]&&"function"==typeof s[t[0]])return new s[t[0]](t.slice(1,t.length));if(4===t.length)return new s.RGB(t[0]/255,t[1]/255,t[2]/255,t[3]/255)}else if("string"==typeof t){var e=t.toLowerCase();s.namedColors[e]&&(t="#"+s.namedColors[e]),"transparent"===e&&(t="rgba(0,0,0,0)");var i=t.match(a);if(i){var u=i[1].toUpperCase(),h="H"===u[0];if(r(s[u]))throw new Error("color."+u+" is not installed.");return new s[u](parseFloat(i[2])/o(i[3],0,h),parseFloat(i[4])/o(i[5],1,h),parseFloat(i[6])/o(i[7],2,h),r(i[8])?i[8]:parseFloat(i[8])/(i[9]?100:255))}t.length<6&&(t=t.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i,"$1$1$2$2$3$3$4$4"));var c=t.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])?$/i);if(c)return new s.RGB(parseInt(c[1],16)/255,parseInt(c[2],16)/255,parseInt(c[3],16)/255,c[4]?parseInt(c[4],16)/255:1);if(s.CMYK){var f=t.match(new RegExp("^cmyk\\("+n.source+","+n.source+","+n.source+","+n.source+"\\)$","i"));if(f)return new s.CMYK(parseFloat(f[1])/100,parseFloat(f[2])/100,parseFloat(f[3])/100,parseFloat(f[4])/100)}}else if("object"==typeof t&&t.isColor)return t;return!1}s.namedColors={},s.installColorSpace=function(e,n,a){s[e]=function(t){var r=Array.isArray(t)?t:arguments;n.forEach((function(t,a){var o=r[a];if("alpha"===t)this._alpha=isNaN(o)||o>1?1:o<0?0:o;else{if(isNaN(o))throw new Error("["+e+"]: Invalid color: ("+n.join(",")+")");"hue"===t?this._hue=o<0?o-Math.floor(o):o%1:this["_"+t]=o<0?0:o>1?1:o}}),this)},s[e].propertyNames=n;var o=s[e].prototype;for(var i in["valueOf","hex","hexa","css","cssa"].forEach((function(t){o[t]=o[t]||("RGB"===e?o.hex:function(){return this.rgb()[t]()})})),o.isColor=!0,o.equals=function(t,a){r(a)&&(a=1e-10),t=t[e.toLowerCase()]();for(var o=0;o<n.length;o+=1)if(Math.abs(this["_"+n[o]]-t["_"+n[o]])>a)return!1;return!0},o.toJSON=function(){return[e].concat(n.map((function(t){return this["_"+t]}),this))},a)if(Object.prototype.hasOwnProperty.call(a,i)){var u=i.match(/^from(.*)$/);u?s[u[1].toUpperCase()].prototype[e.toLowerCase()]=a[i]:o[i]=a[i]}function h(t,r){var e={};for(var n in e[r.toLowerCase()]=function(){return this.rgb()[r.toLowerCase()]()},s[r].propertyNames.forEach((function(t){var n="black"===t?"k":t.charAt(0);e[t]=e[n]=function(e,n){return this[r.toLowerCase()]()[t](e,n)}})),e)Object.prototype.hasOwnProperty.call(e,n)&&void 0===s[t].prototype[n]&&(s[t].prototype[n]=e[n])}return o[e.toLowerCase()]=function(){return this},o.toString=function(){return"["+e+" "+n.map((function(t){return this["_"+t]}),this).join(", ")+"]"},n.forEach((function(t){var r="black"===t?"k":t.charAt(0);o[t]=o[r]=function(r,e){return void 0===r?this["_"+t]:e?new this.constructor(n.map((function(e){return this["_"+e]+(t===e?r:0)}),this)):new this.constructor(n.map((function(e){return t===e?r:this["_"+e]}),this))}})),t.forEach((function(t){h(e,t),h(t,e)})),t.push(e),s},s.pluginList=[],s.use=function(t){return-1===s.pluginList.indexOf(t)&&(this.pluginList.push(t),t(s)),s},s.installMethod=function(r,e){return t.forEach((function(t){s[t].prototype[r]=e})),this},s.installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var t=(65536*Math.round(255*this._red)+256*Math.round(255*this._green)+Math.round(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-t.length)+t},hexa:function(){var t=Math.round(255*this._alpha).toString(16);return this.hex()+"00".substr(0,2-t.length)+t},css:function(){return"rgb("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+")"},cssa:function(){return"rgba("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+","+this._alpha+")"}});var i=function(t){t.installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var r,e,n,a=this._hue,o=this._saturation,s=this._value,i=Math.min(5,Math.floor(6*a)),u=6*a-i,h=s*(1-o),c=s*(1-u*o),f=s*(1-(1-u)*o);switch(i){case 0:r=s,e=f,n=h;break;case 1:r=c,e=s,n=h;break;case 2:r=h,e=s,n=f;break;case 3:r=h,e=c,n=s;break;case 4:r=f,e=h,n=s;break;case 5:r=s,e=h,n=c}return new t.RGB(r,e,n,this._alpha)},hsl:function(){var r,e=(2-this._saturation)*this._value,n=this._saturation*this._value,a=e<=1?e:2-e;return r=a<1e-9?0:n/a,new t.HSL(this._hue,r,e/2,this._alpha)},fromRgb:function(){var r,e=this._red,n=this._green,a=this._blue,o=Math.max(e,n,a),s=o-Math.min(e,n,a),i=0===o?0:s/o,u=o;if(0===s)r=0;else switch(o){case e:r=(n-a)/s/6+(n<a?1:0);break;case n:r=(a-e)/s/6+1/3;break;case a:r=(e-n)/s/6+2/3}return new t.HSV(r,i,u,this._alpha)}})};return s.use(i).use((function(t){t.use(i),t.installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var r,e=2*this._lightness,n=this._saturation*(e<=1?e:2-e);return r=e+n<1e-9?0:2*n/(e+n),new t.HSV(this._hue,r,(e+n)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}})}))}));
//# sourceMappingURL=one-color.js.map

@@ -5,3 +5,3 @@ {

"repository": "git@github.com:One-com/one-color.git",
"version": "3.1.0",
"version": "4.0.0",
"license": "BSD-2-Clause",

@@ -28,10 +28,20 @@ "keywords": [

"devDependencies": {
"@rollup/plugin-commonjs": "^14.0.0",
"coveralls": "2.11.9",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-mocha": "^7.0.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"evaldown": "^1.2.2",
"istanbul": "0.4.2",
"jshint": "^2.9.1",
"mocha": "2.4.5",
"mocha-lcov-reporter": "1.2.0",
"rollup": "0.41.6",
"rollup-plugin-commonjs": "8.0.2",
"uglify-js": "2.8.21",
"onecolor": "file:./",
"prettier": "~2.8.0",
"rollup": "^2.21.0",
"rollup-plugin-terser": "^6.1.0",
"unexpected": "10.11.1"

@@ -44,5 +54,5 @@ },

"one-color.js",
"one-color.map",
"one-color.js.map",
"one-color-all.js",
"one-color-all.map",
"one-color-all.js.map",
"index.js",

@@ -53,10 +63,11 @@ "minimal.js",

"scripts": {
"one-color-all": "rollup -c rollup.config.js index.js && uglifyjs --compress --mangle --in-source-map OUT.js.map --source-map one-color-all.map OUT.js > one-color-all.js; rm OUT.*",
"one-color": "rollup -c rollup.config.js minimal.js && uglifyjs --compress --mangle --in-source-map OUT.js.map --source-map one-color.map OUT.js > one-color.js; rm OUT.*",
"one-color-all": "rollup -c rollup.config.js index.js -o one-color-all.js",
"one-color": "rollup -c rollup.config.js minimal.js -o one-color.js",
"build": "npm run one-color && npm run one-color-all",
"preversion": "npm run lint && npm run build && TEST_BUNDLES=true npm test && bash -c 'git add one-color{-all,}.{js,map}'",
"lint": "jshint .",
"preversion": "npm run lint && npm run build && TEST_BUNDLES=true npm test && bash -c 'git add one-color{-all,}.js{,.map}'",
"lint": "eslint . && prettier --check '**/*.{js,md}'",
"test": "npm run lint && mocha",
"test:documentation": "evaldown --validate --capture=console ./README.md",
"coverage": "istanbul cover _mocha -- --reporter dot",
"travis": "npm run lint && npm run build && TEST_BUNDLES=true npm run coverage"
"ci:test": "TEST_BUNDLES=true npm run coverage"
},

@@ -63,0 +74,0 @@ "jspm": {

@@ -1,3 +0,3 @@

one.color
=========
# onecolor
[![NPM version](https://badge.fury.io/js/onecolor.svg)](http://badge.fury.io/js/onecolor)

@@ -11,28 +11,30 @@ [![Build Status](https://travis-ci.org/One-com/one-color.svg?branch=master)](https://travis-ci.org/One-com/one-color)

Features:
* RGB, HSV, HSL, and CMYK colorspace support (experimental implementations of LAB and XYZ)
* Legal values for all channels are 0..1
* Instances are immutable -- a new object is created for each manipulation
* All internal calculations are done using floating point, so very little precision is lost due to rounding errors when converting between colorspaces
* Alpha channel support
* Extensible architecture -- implement your own colorspaces easily
* Chainable color manipulation
* Seamless conversion between colorspaces
* Outputs as hex, `rgb(...)`, or `rgba(...)`.
- RGB, HSV, HSL, and CMYK colorspace support (experimental implementations of LAB and XYZ)
- Legal values for all channels are 0..1
- Instances are immutable -- a new object is created for each manipulation
- All internal calculations are done using floating point, so very little precision is lost due to rounding errors when converting between colorspaces
- Alpha channel support
- Extensible architecture -- implement your own colorspaces easily
- Chainable color manipulation
- Seamless conversion between colorspaces
- Outputs as hex, `rgb(...)`, or `rgba(...)`.
Module support:
* CommonJS / Node
* AMD / RequireJS
* Vanilla JS (installs itself on one.color)
- CommonJS / Node
- AMD / RequireJS
- Vanilla JS (installs itself on one.color)
Package managers:
* npm: `npm install onecolor`
* bower: `bower install color`
- npm: `npm install onecolor`
- bower: `bower install color`
Small sizes:
* one-color.js ![](http://img.badgesize.io/One-com/one-color/master/one-color.js.svg?label=size) ![](http://img.badgesize.io/One-com/one-color/master/one-color.js.svg?label=gzip&compression=gzip) (Basic RGB, HSV, HSL)
* one-color-all.js ![](http://img.badgesize.io/One-com/one-color/master/one-color-all.js.svg?label=size) ![](http://img.badgesize.io/One-com/one-color/master/one-color-all.js.svg?label=gzip&compression=gzip) (Full RGB, HSV, HSL, CMYK, XYZ, LAB, named colors, [helper functions](https://github.com/One-com/one-color/tree/master/lib/plugins))
- one-color.js ![](http://img.badgesize.io/One-com/one-color/master/one-color.js.svg?label=size) ![](http://img.badgesize.io/One-com/one-color/master/one-color.js.svg?label=gzip&compression=gzip) (Basic RGB, HSV, HSL)
- one-color-all.js ![](http://img.badgesize.io/One-com/one-color/master/one-color-all.js.svg?label=size) ![](http://img.badgesize.io/One-com/one-color/master/one-color-all.js.svg?label=gzip&compression=gzip) (Full RGB, HSV, HSL, CMYK, XYZ, LAB, named colors, [helper functions](https://github.com/One-com/one-color/tree/master/lib/plugins))
Usage
-----
## Usage

@@ -43,23 +45,30 @@ In the browser (change <a href="//raw.github.com/One-com/one-color/master/one-color.js">one-color.js</a> to <a href="//raw.github.com/One-com/one-color/master/one-color-all.js">one-color-all.js</a> to gain

```html
<script src='one-color.js'></script>
<script src="one-color.js"></script>
<script>
alert('Hello, ' + one.color('#650042').lightness(.3).green(.4).hex() + ' world!');
alert(
'Hello, ' + one.color('#650042').lightness(0.3).green(0.4).hex() + ' world!'
);
</script>
```
In node.js (after `npm install onecolor`):
In the browser, the parser is exposed as a global named `onecolor`.
In node.js, it is returned directly with a require of the module
(after `npm install onecolor`):
```javascript
var color = require('onecolor');
console.warn(color('rgba(100%, 0%, 0%, .5)').alpha(.4).cssa()); // 'rgba(255,0,0,0.4)'
console.warn(color('rgba(100%, 0%, 0%, .5)').alpha(0.4).cssa());
```
`one.color` is the parser. All of the above return color instances in
the relevant color space with the channel values (0..1) as instance
variables:
```output
rgba(255,0,0,0.4)
```
All of the above return color instances in the relevant color space
with the channel values (0..1) as instance variables:
```javascript
var myColor = one.color('#a9d91d');
myColor instanceof one.color.RGB; // true
myColor.red() // 0.6627450980392157
var myColor = color('#a9d91d');
myColor instanceof color.RGB; // true
myColor.red(); // 0.6627450980392157
```

@@ -72,3 +81,3 @@

```javascript
one.color('maroon').lightness(.3).hex() // '#990000'
color('maroon').lightness(0.3).hex(); // '#990000'
```

@@ -80,4 +89,4 @@

```javascript
one.color('rgb(124, 96, 200)').hex() // '#7c60c8'
one.color('#bb7b81').cssa() // 'rgba(187,123,129,1)'
color('rgb(124, 96, 200)').hex(); // '#7c60c8'
color('#bb7b81').cssa(); // 'rgba(187,123,129,1)'
```

@@ -91,6 +100,6 @@

```javascript
one.color('#ff0000') // Red in RGB
.green(1) // Set green to the max value, producing yellow (still RGB)
.hue(.5, true) // Add 180 degrees to the hue, implicitly converting to HSV
.hex() // Dump as RGB hex syntax: '#2222ff'
color('#ff0000') // Red in RGB
.green(1) // Set green to the max value, producing yellow (still RGB)
.hue(0.5, true) // Add 180 degrees to the hue, implicitly converting to HSV
.hex(); // Dump as RGB hex syntax: '#2222ff'
```

@@ -102,4 +111,4 @@

```javascript
one.color('#09ffdd').green() // 1
one.color('#09ffdd').saturation() // 0.9647058823529412
color('#09ffdd').green(); // 1
color('#09ffdd').saturation(); // 0.9647058823529412
```

@@ -111,7 +120,7 @@

```javascript
var myColor = one.color('#00ddff');
myColor.red(.5).red() // .5
var myColor = color('#00ddff');
myColor.red(0.5).red(); // .5
// ... but as the objects are immutable, the original object retains its value:
myColor.red() // 0
myColor.red(); // 0
```

@@ -124,9 +133,8 @@

```javascript
one.color('#ff0000') // Red
.red(-.1, true) // Adjust red channel by -0.1
.hex() // '#e60000'
color('#ff0000') // Red
.red(-0.1, true) // Adjust red channel by -0.1
.hex(); // '#e60000'
```
Alpha channel
-------------
## Alpha channel

@@ -139,10 +147,6 @@ All color instances have an alpha channel (0..1), defaulting to 1

```javascript
one.color('rgba(10, 20, 30, .8)')
.green(.4)
.saturation(.2)
.alpha() // 0.8
color('rgba(10, 20, 30, .8)').green(0.4).saturation(0.2).alpha(); // 0.8
```
Comparing color objects
-----------------------
## Comparing color objects

@@ -153,3 +157,3 @@ If you need to know whether two colors represent the same 8 bit color, regardless

```javascript
one.color('#f00').hex() === one.color('#e00').red(1).hex() // true
color('#f00').hex() === color('#e00').red(1).hex(); // true
```

@@ -161,4 +165,4 @@

```javascript
one.color('#e00').lightness(.00001, true).equals(one.color('#e00'), 1e-5) // false
one.color('#e00').lightness(.000001, true).equals(one.color('#e00'), 1e-5) // true
color('#e00').lightness(0.00001, true).equals(color('#e00'), 1e-5); // false
color('#e00').lightness(0.000001, true).equals(color('#e00'), 1e-5); // true
```

@@ -170,7 +174,6 @@

```javascript
one.color('#e00').hsv().equals(one.color('#e00')) // true
color('#e00').hsv().equals(color('#e00')); // true
```
API overview
============
# API overview

@@ -180,14 +183,14 @@ Color parser function, the recommended way to create a color instance:

```javascript
one.color('#a9d91d') // Regular hex syntax
one.color('a9d91d') // hex syntax, # is optional
one.color('#eee') // Short hex syntax
one.color('rgb(124, 96, 200)') // CSS rgb syntax
one.color('rgb(99%, 40%, 0%)') // CSS rgb syntax with percentages
one.color('rgba(124, 96, 200, .4)') // CSS rgba syntax
one.color('hsl(120, 75%, 75%)') // CSS hsl syntax
one.color('hsla(120, 75%, 75%, .1)') // CSS hsla syntax
one.color('hsv(220, 47%, 12%)') // CSS hsv syntax (non-standard)
one.color('hsva(120, 75%, 75%, 0)') // CSS hsva syntax (non-standard)
one.color([0, 4, 255, 120]) // CanvasPixelArray entry, RGBA
one.color(["RGB", .5, .1, .6, .9]) // The output format of color.toJSON()
color('#a9d91d'); // Regular hex syntax
color('a9d91d'); // hex syntax, # is optional
color('#eee'); // Short hex syntax
color('rgb(124, 96, 200)'); // CSS rgb syntax
color('rgb(99%, 40%, 0%)'); // CSS rgb syntax with percentages
color('rgba(124, 96, 200, .4)'); // CSS rgba syntax
color('hsl(120, 75%, 75%)'); // CSS hsl syntax
color('hsla(120, 75%, 75%, .1)'); // CSS hsla syntax
color('hsv(220, 47%, 12%)'); // CSS hsv syntax (non-standard)
color('hsva(120, 75%, 75%, 0)'); // CSS hsva syntax (non-standard)
color([0, 4, 255, 120]); // CanvasPixelArray entry, RGBA
color(['RGB', 0.5, 0.1, 0.6, 0.9]); // The output format of color.toJSON()
```

@@ -199,11 +202,11 @@

```javascript
one.color('maroon')
one.color('darkolivegreen')
color('maroon');
color('darkolivegreen');
```
Existing one.color instances pass through unchanged, which is useful
Existing onecolor instances pass through unchanged, which is useful
in APIs where you want to accept either a string or a color instance:
```javascript
one.color(one.color('#fff')) // Same as one.color('#fff')
color(color('#fff')); // Same as color('#fff')
```

@@ -214,7 +217,9 @@

```javascript
color.hex() // 6-digit hex string: '#bda65b'
color.css() // CSS rgb syntax: 'rgb(10,128,220)'
color.cssa() // CSS rgba syntax: 'rgba(10,128,220,0.8)'
color.toString() // For debugging: '[one.color.RGB: Red=0.3 Green=0.8 Blue=0 Alpha=1]'
color.toJSON() // ["RGB"|"HSV"|"HSL", <number>, <number>, <number>, <number>]
var myColor = color('#bda65b');
myColor.hex(); // 6-digit hex string: '#bda65b'
myColor.css(); // CSS rgb syntax: 'rgb(10,128,220)'
myColor.cssa(); // CSS rgba syntax: 'rgba(10,128,220,0.8)'
myColor.toString(); // For debugging: '[onecolor.RGB: Red=0.3 Green=0.8 Blue=0 Alpha=1]'
myColor.toJSON(); // ["RGB"|"HSV"|"HSL", <number>, <number>, <number>, <number>]
```

@@ -225,14 +230,16 @@

```javascript
color.red()
color.green()
color.blue()
color.hue()
color.saturation()
color.value()
color.lightness()
color.alpha()
color.cyan() // one-color-all.js and node.js only
color.magenta() // one-color-all.js and node.js only
color.yellow() // one-color-all.js and node.js only
color.black() // one-color-all.js and node.js only
var myColor = color('#bda65b');
myColor.red();
myColor.green();
myColor.blue();
myColor.hue();
myColor.saturation();
myColor.value();
myColor.lightness();
myColor.alpha();
myColor.cyan(); // one-color-all.js and node.js only
myColor.magenta(); // one-color-all.js and node.js only
myColor.yellow(); // one-color-all.js and node.js only
myColor.black(); // one-color-all.js and node.js only
```

@@ -242,2 +249,4 @@

<!-- evaldown evaluate:false -->
```javascript

@@ -261,2 +270,4 @@ color.red(<number>)

<!-- evaldown evaluate:false -->
```javascript

@@ -276,4 +287,7 @@ color.red(<number>, true)

```
Comparison with other color objects, returns `true` or `false` (epsilon defaults to `1e-9`):
<!-- evaldown evaluate:false -->
```javascript

@@ -283,4 +297,3 @@ color.equals(otherColor[, <epsilon>])

Mostly for internal (and plugin) use:
-------------------------------------
## Mostly for internal (and plugin) use:

@@ -290,10 +303,11 @@ "Low level" constructors, accept 3 or 4 numerical arguments (0..1):

```javascript
new one.color.RGB(<red>, <green>, <blue>[, <alpha>])
new one.color.HSL(<hue>, <saturation>, <lightness>[, <alpha>])
new one.color.HSV(<hue>, <saturation>, <value>[, <alpha>])
new onecolor.RGB(<red>, <green>, <blue>[, <alpha>])
new onecolor.HSL(<hue>, <saturation>, <lightness>[, <alpha>])
new onecolor.HSV(<hue>, <saturation>, <value>[, <alpha>])
```
The <a href="//raw.github.com/One-com/one-color/master/one-color-all.js">one-color-all.js</a> build includes CMYK support:
```javascript
new one.color.CMYK(<cyan>, <magenta>, <yellow>, <black>[, <alpha>])
new onecolor.CMYK(<cyan>, <magenta>, <yellow>, <black>[, <alpha>])
```

@@ -311,10 +325,13 @@

```javascript
var myColor = one.color('#0620ff').lightness(+.3).rgb();
// Alerts '0 0.06265060240963878 0.5999999999999999':
alert(myColor.red() + ' ' + myColor.green() + ' ' + myColor.blue());
var myColor = color('#0620ff').lightness(+0.3).rgb();
console.log(myColor.red() + ' ' + myColor.green() + ' ' + myColor.blue());
```
Building
========
```output
0 0.06265060240963878 0.5999999999999999
```
# Building
```

@@ -330,8 +347,7 @@ git clone https://github.com/One-com/one-color.git

* Basic library: <a href="//raw.github.com/One-com/one-color/master/one-color.js">one-color.js</a>
* Full library including named color support: <a href="//raw.github.com/One-com/one-color/master/one-color-all.js">one-color-all.js</a>
- Basic library: <a href="//raw.github.com/One-com/one-color/master/one-color.js">one-color.js</a>
- Full library including named color support: <a href="//raw.github.com/One-com/one-color/master/one-color-all.js">one-color-all.js</a>
License
=======
# License
one.color is licensed under a standard 2-clause BSD license -- see the `LICENSE` file for details.
onecolor is licensed under a standard 2-clause BSD license -- see the `LICENSE` file for details.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc