Comparing version 0.3.73 to 0.4.0
1337
build/culori.js
@@ -11,3 +11,3 @@ (function (global, factory) { | ||
var defineMode = function defineMode(definition) { | ||
var defineMode = function (definition) { | ||
converters[definition.mode] = Object.assign(converters[definition.mode] || {}, definition.output); | ||
@@ -21,17 +21,11 @@ Object.keys(definition.input || {}).forEach(function (k) { | ||
modes[definition.mode] = definition; | ||
(definition.parsers || []).forEach(function (parser) { | ||
return parsers.push(parser); | ||
}); | ||
(definition.parsers || []).forEach(function (parser) { return parsers.push(parser); }); | ||
}; | ||
var getModeDefinition = function getModeDefinition(mode) { | ||
return modes[mode]; | ||
}; | ||
var getModeDefinition = function (mode) { return modes[mode]; }; | ||
var parse = function parse(color) { | ||
var result = void 0, | ||
i = 0, | ||
len = parsers.length; | ||
var parse = function (color) { | ||
var result, i = 0, len = parsers.length; | ||
while (i < len) { | ||
if ((result = parsers[i++](color)) !== undefined) break; | ||
if ((result = parsers[i++](color)) !== undefined) { break; } | ||
} | ||
@@ -41,47 +35,31 @@ return result; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var prepare = function (color, mode) { return color === undefined ? | ||
undefined | ||
: typeof color !== 'object' ? | ||
parse(color) | ||
: color.mode === undefined ? | ||
Object.assign({}, color, {mode: mode}) | ||
: color; }; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
var converter = function (target_mode) { | ||
if ( target_mode === void 0 ) target_mode = 'rgb'; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var prepare = function prepare(color, mode) { | ||
return color === undefined ? undefined : (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color; | ||
}; | ||
var converter = function converter() { | ||
var target_mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'rgb'; | ||
return function (color) { | ||
return (color = prepare(color, target_mode)) !== undefined ? | ||
return function (color) { return (color = prepare(color, target_mode)) !== undefined ? | ||
// if the color's mode corresponds to our target mode | ||
color.mode === target_mode ? | ||
// then just return the color | ||
color | ||
// otherwise check to see if we have a dedicated | ||
// converter for the target mode | ||
: converters[color.mode][target_mode] ? | ||
// and return its result... | ||
converters[color.mode][target_mode](color) | ||
// ...otherwise pass through RGB as an intermediary step. | ||
// if the target mode is RGB... | ||
: target_mode === 'rgb' ? | ||
// just return the RGB | ||
converters[color.mode].rgb(color) | ||
// otherwise convert color.mode -> RGB -> target_mode | ||
: converters.rgb[target_mode](converters[color.mode].rgb(color)) : undefined; | ||
}; | ||
color.mode === target_mode ? | ||
// then just return the color | ||
color | ||
// otherwise check to see if we have a dedicated | ||
// converter for the target mode | ||
: converters[color.mode][target_mode] ? | ||
// and return its result... | ||
converters[color.mode][target_mode](color) | ||
// ...otherwise pass through RGB as an intermediary step. | ||
// if the target mode is RGB... | ||
: target_mode === 'rgb' ? | ||
// just return the RGB | ||
converters[color.mode].rgb(color) | ||
// otherwise convert color.mode -> RGB -> target_mode | ||
: converters.rgb[target_mode](converters[color.mode].rgb(color)) | ||
: undefined; }; | ||
}; | ||
@@ -91,24 +69,20 @@ | ||
var r = function r(value, precision) { | ||
return Math.round(value * (precision = Math.pow(10, precision))) / precision; | ||
}; | ||
var r = function (value, precision) { return Math.round(value * (precision = Math.pow(10, precision))) / precision; }; | ||
var round = (function () { | ||
var precision = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4; | ||
return function (value) { | ||
return typeof value === 'number' ? r(value, precision) : value; | ||
}; | ||
}); | ||
function round (precision) { | ||
if ( precision === void 0 ) precision = 4; | ||
var clamp = (function (value) { | ||
return Math.round(Math.max(0, Math.min(value, 1)) * 255); | ||
}); | ||
return function (value) { return typeof value === 'number' ? r(value, precision) : value; }; | ||
} | ||
var rgb = converter('rgb'), | ||
roundAlpha = round(2); | ||
function fixup (value) { return Math.round(Math.max(0, Math.min(value, 1)) * 255); } | ||
var formatter = (function () { | ||
var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'rgb'; | ||
return function (c) { | ||
var rgb = converter('rgb'); | ||
var roundAlpha = round(2); | ||
function formatter (format) { | ||
if ( format === void 0 ) format = 'rgb'; | ||
return function (c) { | ||
var color = rgb(c); | ||
@@ -120,5 +94,5 @@ | ||
var r = clamp(color.r); | ||
var b = clamp(color.b); | ||
var g = clamp(color.g); | ||
var r = fixup(color.r); | ||
var g = fixup(color.g); | ||
var b = fixup(color.b); | ||
@@ -132,15 +106,15 @@ if (format === 'hex') { | ||
// opaque color | ||
return 'rgb(' + r + ', ' + g + ', ' + b + ')'; | ||
return ("rgb(" + r + ", " + g + ", " + b + ")"); | ||
} else { | ||
// transparent color | ||
return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + roundAlpha(c.alpha) + ')'; | ||
return ("rgba(" + r + ", " + g + ", " + b + ", " + (roundAlpha(c.alpha)) + ")"); | ||
} | ||
} | ||
}; | ||
}); | ||
} | ||
var zip = (function (colors) { | ||
var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'rgb'; | ||
function zip (colors, mode) { | ||
if ( mode === void 0 ) mode = 'rgb'; | ||
var channels = getModeDefinition(mode).channels; | ||
@@ -150,18 +124,12 @@ var res = { | ||
}; | ||
var _loop = function _loop(i) { | ||
res[channels[i]] = colors.map(function (c) { | ||
return c[channels[i]]; | ||
}); | ||
var loop = function ( i ) { | ||
res[channels[i]] = colors.map(function (c) { return c[channels[i]]; }); | ||
}; | ||
for (var i = 0; i < channels.length; i++) { | ||
_loop(i); | ||
} | ||
for (var i = 0; i < channels.length; i++) loop( i ); | ||
return res; | ||
}); | ||
} | ||
var interpolate = (function (colors) { | ||
var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'rgb'; | ||
var interpolations = arguments[2]; | ||
function interpolate (colors, mode, interpolations) { | ||
if ( mode === void 0 ) mode = 'rgb'; | ||
@@ -174,4 +142,3 @@ var zipped = zip(colors.map(converter(mode)), mode); | ||
t = Math.min(Math.max(0, t), 1); | ||
var res = { mode: mode }, | ||
val = void 0; | ||
var res = { mode: mode }, val; | ||
for (var i = 0; i < keys.length; i++) { | ||
@@ -183,4 +150,4 @@ if ((val = interpolations[keys[i]](zipped[keys[i]], t)) !== undefined) { | ||
return res; | ||
}; | ||
}); | ||
} | ||
} | ||
@@ -199,9 +166,8 @@ /* | ||
var interpolateNumber = (function () { | ||
return function (values) { | ||
function interpolateNumber () { return function (values) { | ||
if (values.length === 2) { | ||
// Linear Number interpolation | ||
// --------------------------- | ||
// If both values are undefined, return undefined | ||
@@ -223,5 +189,10 @@ if (values[0] === undefined && values[1] === undefined) { | ||
// --------------------------- | ||
// If all values are undefined, return undefined | ||
if (values[0] === undefined && values[1] === undefined && values[2] === undefined && values[3] === undefined) { | ||
if ( | ||
values[0] === undefined && | ||
values[1] === undefined && | ||
values[2] === undefined && | ||
values[3] === undefined | ||
) { | ||
return undefined; | ||
@@ -245,4 +216,3 @@ } | ||
} | ||
}; | ||
}); | ||
}; } | ||
@@ -261,9 +231,9 @@ /* | ||
var interpolateAlpha = (function () { | ||
return function (values, t) { | ||
function interpolateAlpha () { return function (values, t) { | ||
if (values.length === 2) { | ||
// Linear Alpha interpolation | ||
// -------------------------- | ||
// If both alphas are undefined, | ||
@@ -273,7 +243,12 @@ // or if t is next to the undefined alpha, | ||
// about undefined alpha being 1. | ||
if (values[0] === undefined && values[1] === undefined || values[0] === undefined && t === 0 || values[1] === undefined && t === 1) return undefined; | ||
if ( | ||
(values[0] === undefined && values[1] === undefined) || | ||
(values[0] === undefined && t === 0) || | ||
(values[1] === undefined && t === 1) | ||
) { return undefined; } | ||
// If at least one alpha is defined, | ||
// assume alpha = 1 for any undefined values. | ||
return [values[0] === undefined ? 1 : values[0], values[1] === undefined ? 1 : values[1]]; | ||
return [ values[0] === undefined ? 1 : values[0], values[1] === undefined ? 1 : values[1]]; | ||
} else { | ||
@@ -285,3 +260,8 @@ | ||
// If all values are undefined, return undefined | ||
if (values[0] === undefined && values[1] === undefined && values[2] === undefined && values[3] === undefined) { | ||
if ( | ||
values[0] === undefined && | ||
values[1] === undefined && | ||
values[2] === undefined && | ||
values[3] === undefined | ||
) { | ||
return undefined; | ||
@@ -292,12 +272,7 @@ } | ||
// put alpha = 1 for any undefined values | ||
return values.map(function (v) { | ||
return v === undefined ? 1 : v; | ||
}); | ||
return values.map(function (v) { return v === undefined ? 1 : v; }); | ||
} | ||
}; | ||
}); | ||
}; } | ||
var normalizeHue = (function (hue) { | ||
return (hue = hue % 360) < 0 ? hue + 360 : hue; | ||
}); | ||
function normalizeHue (hue) { return (hue = hue % 360) < 0 ? hue + 360 : hue; } | ||
@@ -318,6 +293,7 @@ /* | ||
var interpolateHue = (function () { | ||
var shortPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
return function (values) { | ||
function interpolateHue (shortPath) { | ||
if ( shortPath === void 0 ) shortPath = true; | ||
return function (values) { | ||
if (values.length === 2) { | ||
@@ -332,3 +308,3 @@ | ||
} | ||
// if both hues are defined, interpolate between | ||
@@ -356,12 +332,15 @@ // the start hue and the end hue brought closest | ||
// ------------------------ | ||
// If all values are undefined, return undefined | ||
if (values[0] === undefined && values[1] === undefined && values[2] === undefined && values[3] === undefined) { | ||
if ( | ||
values[0] === undefined && | ||
values[1] === undefined && | ||
values[2] === undefined && | ||
values[3] === undefined | ||
) { | ||
return undefined; | ||
} | ||
if (shortPath) { | ||
return values.map(function (v) { | ||
return normalizeHue(v); | ||
}); | ||
return values.map(function (v) { return normalizeHue(v); }); | ||
} | ||
@@ -371,30 +350,31 @@ | ||
return values; | ||
} | ||
}; | ||
}); | ||
} | ||
// todo hue short vs. hue long | ||
// todo normalize hue before and after interpolateHue | ||
var identity = (function (d) { | ||
return d; | ||
}); | ||
function identity (d) { return d; } | ||
var interpolateFunctionLinear = (function () { | ||
var normalize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : identity; | ||
var γ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
return function (arr, t) { | ||
function interpolateFunctionLinear (normalize, γ) { | ||
if ( normalize === void 0 ) normalize = identity; | ||
if ( γ === void 0 ) γ = 1; | ||
return function (arr, t) { | ||
t = Math.pow(t, γ); | ||
var cls = t * (arr.length - 1), | ||
idx = Math.floor(cls), | ||
a = arr[idx], | ||
b = arr[idx + 1], | ||
t0 = cls - idx; | ||
var cls = t * (arr.length - 1), | ||
idx = Math.floor(cls), | ||
a = arr[idx], | ||
b = arr[idx + 1], | ||
t0 = cls - idx; | ||
var values = normalize([a, b], t0); | ||
return (typeof values === 'undefined' ? 'undefined' : _typeof(values)) === 'object' ? (a = values[0], b = values[1], a + t0 * (b - a)) : values; | ||
return typeof values === 'object' ? | ||
(a = values[0], b = values[1], a + t0 * (b - a)) : | ||
values; | ||
}; | ||
}); | ||
} | ||
@@ -427,10 +407,15 @@ /* | ||
var bspline = function bspline(Vim2, Vim1, Vi, Vip1, t) { | ||
var bspline = function (Vim2, Vim1, Vi, Vip1, t) { | ||
var t2 = t * t; | ||
var t3 = t2 * t; | ||
return ((1 - 3 * t + 3 * t2 - t3) * Vim2 + (4 - 6 * t2 + 3 * t3) * Vim1 + (1 + 3 * t + 3 * t2 - 3 * t3) * Vi + t3 * Vip1) / 6; | ||
return ( | ||
(1 - 3 * t + 3 * t2 - t3) * Vim2 + | ||
(4 - 6 * t2 + 3 * t3) * Vim1 + | ||
(1 + 3 * t + 3 * t2 - 3 * t3) * Vi + | ||
t3 * Vip1 | ||
) / 6; | ||
}; | ||
var solve = function solve(v) { | ||
var i; | ||
var solve = function (v) { | ||
var i; | ||
var n = v.length - 1; | ||
@@ -440,29 +425,30 @@ var c = new Array(n); | ||
var sol = new Array(n); | ||
c[1] = 1 / 4, _v[1] = (6 * v[1] - v[0]) / 4; | ||
c[1] = 1/4, _v[1] = (6 * v[1] - v[0])/4; | ||
for (i = 2; i < n; ++i) { | ||
c[i] = 1 / (4 - c[i - 1]); | ||
_v[i] = (6 * v[i] - (i == n - 1 ? v[n] : 0) - _v[i - 1]) * c[i]; | ||
c[i] = 1 / (4 - c[i-1]); | ||
_v[i] = (6 * v[i] - (i == n-1 ? v[n] : 0) - _v[i-1]) * c[i]; | ||
} | ||
sol[0] = v[0]; | ||
sol[n] = v[n]; | ||
if (n - 1 > 0) { | ||
sol[n - 1] = _v[n - 1]; | ||
sol[n-1] = _v[n-1]; | ||
} | ||
for (i = n - 2; i > 0; --i) { | ||
sol[i] = _v[i] - c[i] * sol[i + 1]; | ||
for (i = n-2; i > 0; --i) { | ||
sol[i] = _v[i] - c[i] * sol[i+1]; | ||
} | ||
return sol; | ||
}; | ||
var interpolateFunctionSpline = (function () { | ||
var normalize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : identity; | ||
var method = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'bspline'; | ||
var γ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; | ||
return function (arr, t) { | ||
function interpolateFunctionSpline (normalize, method, γ) { | ||
if ( normalize === void 0 ) normalize = identity; | ||
if ( method === void 0 ) method = 'bspline'; | ||
if ( γ === void 0 ) γ = 1; | ||
return function (arr, t) { | ||
t = Math.pow(t, γ); | ||
@@ -478,12 +464,14 @@ | ||
var Vim1 = arr[i]; | ||
var Vi = arr[i + 1]; | ||
var Vi = arr[i+1]; | ||
var Vim2 = i > 0 ? arr[i - 1] : 2 * Vim1 - Vi; | ||
var Vip1 = i < classes - 1 ? arr[i + 2] : 2 * Vi - Vim1; | ||
var Vim2 = i > 0 ? arr[i-1] : 2 * Vim1 - Vi; | ||
var Vip1 = i < classes - 1 ? arr[i+2] : 2 * Vi - Vim1; | ||
var v = normalize([Vim2, Vim1, Vi, Vip1]); | ||
return (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object' ? bspline(v[0], v[1], v[2], v[3], (t - i / classes) * classes) : v; | ||
return typeof v === 'object' ? | ||
bspline(v[0], v[1], v[2], v[3], (t - i / classes) * classes) | ||
: v; | ||
}; | ||
}); | ||
} | ||
@@ -495,28 +483,29 @@ /* | ||
var interpolateFunctionCosine = (function () { | ||
var normalize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : identity; | ||
var γ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
return function (arr, t) { | ||
function interpolateFunctionCosine (normalize, γ) { | ||
if ( normalize === void 0 ) normalize = identity; | ||
if ( γ === void 0 ) γ = 1; | ||
return function (arr, t) { | ||
t = Math.pow(t, γ); | ||
var cls = t * (arr.length - 1), | ||
idx = Math.floor(cls), | ||
a = arr[idx], | ||
b = arr[idx + 1], | ||
t0 = cls - idx; | ||
var cls = t * (arr.length - 1), | ||
idx = Math.floor(cls), | ||
a = arr[idx], | ||
b = arr[idx + 1], | ||
t0 = cls - idx; | ||
var values = normalize([a, b], t0); | ||
if ((typeof values === 'undefined' ? 'undefined' : _typeof(values)) === 'object') { | ||
if (typeof values === 'object') { | ||
a = values[0]; | ||
b = values[1]; | ||
var c = (1 - Math.cos(t0 * Math.PI)) / 2; | ||
return a * (1 - c) + b * c; | ||
return (a * (1 - c) + b * c); | ||
} else { | ||
return values; | ||
} | ||
} | ||
}; | ||
}); | ||
} | ||
var monotone = function monotone(v0, v1, v2, v3, h, t) { | ||
var monotone = function (v0, v1, v2, v3, h, t) { | ||
@@ -531,10 +520,16 @@ var h2 = h * h; | ||
return (s20 + s31 - 2 * s21) / h2 * t3 + (3 * s21 - 2 * s20 - s31) / h * t2 + s20 * t + v1; | ||
return ( | ||
(s20 + s31 - 2 * s21) / h2 * t3 + | ||
(3 * s21 - 2 * s20 - s31) / h * t2 + | ||
s20 * t + | ||
v1 | ||
); | ||
}; | ||
var interpolateFunctionMonotone = (function () { | ||
var normalize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : identity; | ||
var γ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
return function (arr, t) { | ||
function interpolateFunctionMonotone (normalize, γ) { | ||
if ( normalize === void 0 ) normalize = identity; | ||
if ( γ === void 0 ) γ = 1; | ||
return function (arr, t) { | ||
t = Math.pow(t, γ); | ||
@@ -544,3 +539,3 @@ | ||
var i = void 0; | ||
var i; | ||
if (t === 1) { | ||
@@ -560,9 +555,10 @@ i = n - 1; | ||
return (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object' ? monotone(v[0], v[1], v[2], v[3], 1 / n, t - i / n) : v; | ||
return typeof v === 'object' ? | ||
monotone(v[0], v[1], v[2], v[3], 1 / n, t - i / n) : v; | ||
}; | ||
}); | ||
} | ||
var samples = (function () { | ||
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2; | ||
var γ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
function samples (n, γ) { | ||
if ( n === void 0 ) n = 2; | ||
if ( γ === void 0 ) γ = 1; | ||
@@ -577,7 +573,84 @@ if (n < 2) { | ||
return res; | ||
}); | ||
} | ||
var differenceEuclidean = function differenceEuclidean() { | ||
var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'rgb'; | ||
var rgb$1 = converter('rgb'); | ||
function displayable (color) { | ||
var c = rgb$1(color); | ||
return ( | ||
c !== undefined && | ||
c.r >= 0 && c.r <= 1 && | ||
c.g >= 0 && c.g <= 1 && | ||
c.b >= 0 && c.b <= 1 | ||
); | ||
} | ||
var lch = converter('lch'); | ||
var rgb$2 = converter('rgb'); | ||
var prepare$1 = function (color) { return color === undefined ? | ||
undefined | ||
: typeof color !== 'object' ? | ||
parse(color) | ||
: color.mode === undefined ? | ||
undefined | ||
: color; }; | ||
var clamp_value = function (v) { return Math.max(0, Math.min(v, 1)); }; | ||
var clamp_rgb = function (color) { | ||
var c = rgb$2(color); | ||
c.r = clamp_value(c.r); | ||
c.g = clamp_value(c.g); | ||
c.b = clamp_value(c.b); | ||
return c; | ||
}; | ||
function clamp (method) { | ||
if ( method === void 0 ) method = 'rgb'; | ||
return function (color) { | ||
color = prepare$1(color); | ||
// if the color is undefined or displayable, return it directly | ||
if (color === undefined || displayable(color)) { return color; } | ||
// keep track of color's original mode | ||
var conv = converter(color.mode); | ||
if (method === 'rgb') { | ||
return conv(clamp_rgb(color)); | ||
} | ||
// convert to LCh for clamping | ||
color = lch(color); | ||
// try with chroma = 0 | ||
var clamped = Object.assign({}, color, {c: 0}); | ||
// if not even chroma = 0 is displayable | ||
// fall back to RGB clamping | ||
if (!displayable(clamped)) { | ||
return conv(clamp_rgb(clamped)); | ||
} | ||
// By this time we know chroma = 0 is displayable and our current chroma is not. | ||
// Find the displayable chroma through the bisection method. | ||
var start = 0, end = color.c, delta = 0.01; | ||
while (end - start > delta) { | ||
clamped.c = start + (end - start) * 0.5; | ||
if (displayable(clamped)) { | ||
start = clamped.c; | ||
} else { | ||
end = clamped.c; | ||
} | ||
} | ||
return conv(clamped); | ||
}; | ||
} | ||
var differenceEuclidean = function (mode) { | ||
if ( mode === void 0 ) mode = 'rgb'; | ||
var channels = getModeDefinition(mode).channels; | ||
@@ -588,22 +661,20 @@ var conv = converter(mode); | ||
var ConvSmp = conv(smp); | ||
return Math.sqrt(channels.reduce(function (delta, k) { | ||
return ( | ||
// ignore alpha channel in computing the euclidean distance | ||
delta + (k === 'alpha' ? 0 : Math.pow(ConvStd[k] - ConvSmp[k], 2)) | ||
); | ||
}, 0)); | ||
}; | ||
return Math.sqrt( | ||
channels.reduce( | ||
function (delta, k) { return delta + (k === 'alpha' ? 0 : Math.pow(ConvStd[k] - ConvSmp[k], 2)); }, | ||
0 | ||
) | ||
); | ||
} | ||
}; | ||
var differenceCie76 = function differenceCie76() { | ||
return differenceEuclidean('lab'); | ||
}; | ||
var differenceCie76 = function () { return differenceEuclidean('lab'); }; | ||
var differenceCie94 = function differenceCie94() { | ||
var kL = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var K1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.045; | ||
var K2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.015; | ||
var differenceCie94 = function (kL, K1, K2) { | ||
if ( kL === void 0 ) kL = 1; | ||
if ( K1 === void 0 ) K1 = 0.045; | ||
if ( K2 === void 0 ) K2 = 0.015; | ||
var lab = converter('lab'); | ||
return function (std, smp) { | ||
@@ -629,4 +700,8 @@ | ||
return Math.sqrt(dL2 / Math.pow(kL, 2) + dC2 / Math.pow(1 + K1 * cStd, 2) + dH2 / Math.pow(1 + K2 * cStd, 2)); | ||
}; | ||
return Math.sqrt( | ||
dL2 / Math.pow(kL, 2) + | ||
dC2 / Math.pow(1 + K1 * cStd, 2) + | ||
dH2 / Math.pow(1 + K2 * cStd, 2) | ||
); | ||
} | ||
}; | ||
@@ -641,6 +716,6 @@ | ||
var differenceCiede2000 = function differenceCiede2000() { | ||
var Kl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var Kc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
var Kh = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; | ||
var differenceCiede2000 = function (Kl, Kc, Kh) { | ||
if ( Kl === void 0 ) Kl = 1; | ||
if ( Kc === void 0 ) Kc = 1; | ||
if ( Kh === void 0 ) Kh = 1; | ||
@@ -663,3 +738,3 @@ var lab = converter('lab'); | ||
var cAvg = (cStd + cSmp) / 2; | ||
var G = 0.5 * (1 - Math.sqrt(Math.pow(cAvg, 7) / (Math.pow(cAvg, 7) + Math.pow(25, 7)))); | ||
@@ -669,18 +744,18 @@ | ||
var apSmp = aSmp * (1 + G); | ||
var cpStd = Math.sqrt(apStd * apStd + bStd * bStd); | ||
var cpSmp = Math.sqrt(apSmp * apSmp + bSmp * bSmp); | ||
var hpStd = Math.abs(apStd) + Math.abs(bStd) === 0 ? 0 : Math.atan2(bStd, apStd); | ||
hpStd += (hpStd < 0) * 2 * Math.PI; | ||
hpStd += (hpStd < 0) * 2 * Math.PI; | ||
var hpSmp = Math.abs(apSmp) + Math.abs(bSmp) === 0 ? 0 : Math.atan2(bSmp, apSmp); | ||
hpSmp += (hpSmp < 0) * 2 * Math.PI; | ||
hpSmp += (hpSmp < 0) * 2 * Math.PI; | ||
var dL = lSmp - lStd; | ||
var dC = cpSmp - cpStd; | ||
var dhp = cpStd * cpSmp === 0 ? 0 : hpSmp - hpStd; | ||
dhp -= (dhp > Math.PI) * 2 * Math.PI; | ||
dhp += (dhp < -Math.PI) * 2 * Math.PI; | ||
dhp -= (dhp > Math.PI) * 2 * Math.PI; | ||
dhp += (dhp < -Math.PI) * 2 * Math.PI; | ||
@@ -692,3 +767,3 @@ var dH = 2 * Math.sqrt(cpStd * cpSmp) * Math.sin(dhp / 2); | ||
var hp = void 0; | ||
var hp; | ||
if (cpStd * cpSmp === 0) { | ||
@@ -703,20 +778,31 @@ hp = hpStd + hpSmp; | ||
var Lpm50 = Math.pow(Lp - 50, 2); | ||
var T = 1 - 0.17 * Math.cos(hp - Math.PI / 6) + 0.24 * Math.cos(2 * hp) + 0.32 * Math.cos(3 * hp + Math.PI / 30) - 0.20 * Math.cos(4 * hp - 63 * Math.PI / 180); | ||
var Sl = 1 + 0.015 * Lpm50 / Math.sqrt(20 + Lpm50); | ||
var T = 1 - | ||
0.17 * Math.cos(hp - Math.PI / 6) + | ||
0.24 * Math.cos(2 * hp) + | ||
0.32 * Math.cos(3 * hp + Math.PI / 30) - | ||
0.20 * Math.cos(4 * hp - 63 * Math.PI / 180); | ||
var Sl = 1 + (0.015 * Lpm50) / Math.sqrt(20 + Lpm50); | ||
var Sc = 1 + 0.045 * Cp; | ||
var Sh = 1 + 0.015 * Cp * T; | ||
var deltaTheta = 30 * Math.PI / 180 * Math.exp(-1 * Math.pow((180 / Math.PI * hp - 275)/25, 2)); | ||
var Rc = 2 * Math.sqrt( | ||
Math.pow(Cp, 7) / (Math.pow(Cp, 7) + Math.pow(25, 7)) | ||
); | ||
var deltaTheta = 30 * Math.PI / 180 * Math.exp(-1 * Math.pow((180 / Math.PI * hp - 275) / 25, 2)); | ||
var Rc = 2 * Math.sqrt(Math.pow(Cp, 7) / (Math.pow(Cp, 7) + Math.pow(25, 7))); | ||
var Rt = -1 * Math.sin(2 * deltaTheta) * Rc; | ||
return Math.sqrt(Math.pow(dL / (Kl * Sl), 2) + Math.pow(dC / (Kc * Sc), 2) + Math.pow(dH / (Kh * Sh), 2) + Rt * dC / (Kc * Sc) * dH / (Kh * Sh)); | ||
}; | ||
return Math.sqrt( | ||
Math.pow(dL / (Kl * Sl), 2) + | ||
Math.pow(dC / (Kc * Sc), 2) + | ||
Math.pow(dH / (Kh * Sh), 2) + | ||
Rt * dC / (Kc * Sc) * dH / (Kh * Sh) | ||
); | ||
} | ||
}; | ||
var differenceCmc = function differenceCmc() { | ||
var l = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var c = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
var differenceCmc = function (l, c) { | ||
if ( l === void 0 ) l = 1; | ||
if ( c === void 0 ) c = 1; | ||
@@ -734,3 +820,3 @@ var lab = converter('lab'); | ||
var hStd = Math.atan2(bStd, aStd); | ||
hStd = hStd + 2 * Math.PI * (hStd < 0); | ||
hStd = hStd + 2 * Math.PI * (hStd < 0); | ||
@@ -747,12 +833,21 @@ var lSmp = LabSmp.l; | ||
var F = Math.sqrt(Math.pow(cStd, 4) / (Math.pow(cStd, 4) + 1900)); | ||
var T = hStd >= 164 / 180 * Math.PI && hStd <= 345 / 180 * Math.PI ? 0.56 + Math.abs(0.2 * Math.cos(hStd + 168 / 180 * Math.PI)) : 0.36 + Math.abs(0.4 * Math.cos(hStd + 35 / 180 * Math.PI)); | ||
var T = hStd >= (164 / 180 * Math.PI) && | ||
hStd <= (345 / 180 * Math.PI) ? | ||
0.56 + Math.abs(0.2 * Math.cos(hStd + 168 / 180 * Math.PI)) | ||
: 0.36 + Math.abs(0.4 * Math.cos(hStd + 35 / 180 * Math.PI)); | ||
var Sl = lStd < 16 ? 0.511 : 0.040975 * lStd / (1 + 0.01765 * lStd); | ||
var Sl = lStd < 16 ? 0.511 : ((0.040975 * lStd) / (1 + 0.01765 * lStd)); | ||
var Sc = 0.0638 * cStd / (1 + 0.0131 * cStd) + 0.638; | ||
var Sh = Sc * (F * T + 1 - F); | ||
return Math.sqrt(dL2 / Math.pow(l * Sl, 2), dC2 / Math.pow(c * Sc, 2), dH2 / Math.pow(Sh, 2)); | ||
return Math.sqrt( | ||
dL2 / Math.pow(l * Sl, 2), | ||
dC2 / Math.pow(c * Sc, 2), | ||
dH2 / Math.pow(Sh, 2) | ||
); | ||
}; | ||
}; | ||
var differenceDin99o = function () { return differenceEuclidean('dlab'); }; | ||
// selects the vantage point | ||
@@ -770,3 +865,3 @@ // currently does so randomly, but this could be optimized | ||
// const vptree = (colors, metric) => { | ||
// let color = select(colors); | ||
@@ -798,18 +893,14 @@ // let dist = median(color, colors, metric); | ||
// | ||
var identity$1 = function identity(d) { | ||
return d; | ||
}; | ||
var identity$1 = function (d) { return d; }; | ||
var nearest = (function (colors) { | ||
var metric = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : differenceEuclidean(); | ||
var accesor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : identity$1; | ||
function nearest (colors, metric, accesor) { | ||
if ( metric === void 0 ) metric = differenceEuclidean(); | ||
if ( accesor === void 0 ) accesor = identity$1; | ||
var arr = colors.map(function (c, idx) { | ||
return { color: accesor(c), i: idx }; | ||
}); | ||
return function (color) { | ||
var n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
var τ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity; | ||
var arr = colors.map(function (c, idx) { return ({ color: accesor(c), i: idx }); }); | ||
return function (color, n, τ) { | ||
if ( n === void 0 ) n = 1; | ||
if ( τ === void 0 ) τ = Infinity; | ||
if (isFinite(n)) { | ||
@@ -823,16 +914,10 @@ n = Math.max(1, Math.min(n, arr.length - 1)); | ||
return arr.sort(function (a, b) { | ||
return a.d - b.d; | ||
}).slice(0, n).filter(function (c) { | ||
return c.d < τ; | ||
}).map(function (c) { | ||
return c.color; | ||
}); | ||
}; | ||
}); | ||
return arr.sort(function (a, b) { return a.d - b.d; }).slice(0, n).filter(function (c) { return c.d < τ; }).map(function (c) { return c.color; }); | ||
} | ||
} | ||
var parseNumber = (function (color, len) { | ||
function parseNumber (color, len) { | ||
if (typeof color !== 'number') { return; } | ||
if (typeof color !== 'number') return; | ||
// hex3: #c93 -> #cc9933 | ||
@@ -842,5 +927,5 @@ if (len === 3) { | ||
mode: 'rgb', | ||
r: (color >> 8 & 0xF | color >> 4 & 0xF0) / 255, | ||
g: (color >> 4 & 0xF | color & 0xF0) / 255, | ||
b: (color & 0xF | color << 4 & 0xF0) / 255 | ||
r: ((color >> 8 & 0xF) | (color >> 4 & 0xF0)) / 255, | ||
g: ((color >> 4 & 0xF) | (color & 0xF0)) / 255, | ||
b: ((color & 0xF) | (color << 4 & 0xF0)) / 255 | ||
}; | ||
@@ -853,9 +938,9 @@ } | ||
mode: 'rgb', | ||
r: (color >> 12 & 0xF | color >> 8 & 0xF0) / 255, | ||
g: (color >> 8 & 0xF | color >> 4 & 0xF0) / 255, | ||
b: (color >> 4 & 0xF | color & 0xF0) / 255, | ||
alpha: (color & 0xF | color << 4 & 0xF0) / 255 | ||
r: ((color >> 12 & 0xF) | (color >> 8 & 0xF0)) / 255, | ||
g: ((color >> 8 & 0xF) | (color >> 4 & 0xF0)) / 255, | ||
b: ((color >> 4 & 0xF) | (color & 0xF0)) / 255, | ||
alpha: ((color & 0xF) | (color << 4 & 0xF0)) / 255 | ||
}; | ||
} | ||
// hex6: #f0f1f2 | ||
@@ -865,4 +950,4 @@ if (len === 6) { | ||
mode: 'rgb', | ||
r: (color >> 16 & 0xFF) / 255, | ||
g: (color >> 8 & 0xFF) / 255, | ||
r: (color >> 16 & 0xFF) / 255, | ||
g: (color >> 8 & 0xFF) / 255, | ||
b: (color & 0xFF) / 255 | ||
@@ -876,9 +961,9 @@ }; | ||
mode: 'rgb', | ||
r: (color >> 24 & 0xFF) / 255, | ||
g: (color >> 16 & 0xFF) / 255, | ||
b: (color >> 8 & 0xFF) / 255, | ||
r: (color >> 24 & 0xFF) / 255, | ||
g: (color >> 16 & 0xFF) / 255, | ||
b: (color >> 8 & 0xFF) / 255, | ||
alpha: (color & 0xFF) / 255 | ||
}; | ||
} | ||
}); | ||
} | ||
@@ -1006,3 +1091,3 @@ var named = { | ||
// Added in CSS Colors Level 4: https://drafts.csswg.org/css-color/#changes-from-3 | ||
rebeccapurple: 0x663399, | ||
rebeccapurple: 0x663399, | ||
red: 0xff0000, | ||
@@ -1040,5 +1125,5 @@ rosybrown: 0xbc8f8f, | ||
// https://drafts.csswg.org/css-color/#transparent-black | ||
var parseNamed = (function (color) { | ||
return typeof color === 'string' && parseNumber(named[color.toLowerCase()], 6) || undefined; | ||
}); | ||
function parseNamed (color) { | ||
return (typeof color === 'string' && parseNumber(named[color.toLowerCase()], 6)) || undefined; | ||
} | ||
@@ -1054,7 +1139,7 @@ /* | ||
var num = (/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/ + '').replace(/^\/|\/$/g, ''); // number | ||
var per = num + '%'; // percentage | ||
var alpha = '(?:' + num + '%|' + num + ')'; // alpha-value | ||
var hue = '(?:' + num + '(deg|grad|rad|turn)|' + num + ')'; // hue | ||
var c = '\\s*,\\s*'; // comma | ||
var s = '\\s+'; // space | ||
var per = num + "%"; // percentage | ||
var alpha = "(?:" + num + "%|" + num + ")"; // alpha-value | ||
var hue = "(?:" + num + "(deg|grad|rad|turn)|" + num + ")"; // hue | ||
var c = "\\s*,\\s*"; // comma | ||
var s = "\\s+"; // space | ||
@@ -1066,6 +1151,6 @@ | ||
*/ | ||
var rgb_num_old = new RegExp('^rgba?\\(\\s*' + num + c + num + c + num + '\\s*(?:,\\s*' + alpha + '\\s*)?\\)$'); | ||
var rgb_per_old = new RegExp('^rgba?\\(\\s*' + per + c + per + c + per + '\\s*(?:,\\s*' + alpha + '\\s*)?\\)$'); | ||
var rgb_num_new = new RegExp('^rgba?\\(\\s*' + num + s + num + s + num + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var rgb_per_new = new RegExp('^rgba?\\(\\s*' + per + s + per + s + per + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var rgb_num_old = new RegExp(("^rgba?\\(\\s*" + num + c + num + c + num + "\\s*(?:,\\s*" + alpha + "\\s*)?\\)$")); | ||
var rgb_per_old = new RegExp(("^rgba?\\(\\s*" + per + c + per + c + per + "\\s*(?:,\\s*" + alpha + "\\s*)?\\)$")); | ||
var rgb_num_new = new RegExp(("^rgba?\\(\\s*" + num + s + num + s + num + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
var rgb_per_new = new RegExp(("^rgba?\\(\\s*" + per + s + per + s + per + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
@@ -1076,4 +1161,4 @@ /* | ||
*/ | ||
var hsl_old = new RegExp('^hsla?\\(\\s*' + hue + c + per + c + per + '\\s*(?:,\\s*' + alpha + '\\s*)?\\)$'); | ||
var hsl_new = new RegExp('^hsla?\\(\\s*' + hue + s + per + s + per + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var hsl_old = new RegExp(("^hsla?\\(\\s*" + hue + c + per + c + per + "\\s*(?:,\\s*" + alpha + "\\s*)?\\)$")); | ||
var hsl_new = new RegExp(("^hsla?\\(\\s*" + hue + s + per + s + per + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
@@ -1089,3 +1174,3 @@ /* | ||
*/ | ||
var hwb = new RegExp('^hwb\\(\\s*' + hue + s + per + s + per + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var hwb = new RegExp(("^hwb\\(\\s*" + hue + s + per + s + per + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
@@ -1096,4 +1181,4 @@ /* | ||
*/ | ||
var lab = new RegExp('^lab\\(\\s*' + num + s + num + s + num + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var lch = new RegExp('^lch\\(\\s*' + num + s + num + s + hue + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var lab = new RegExp(("^lab\\(\\s*" + num + s + num + s + num + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
var lch$1 = new RegExp(("^lch\\(\\s*" + num + s + num + s + hue + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
@@ -1104,27 +1189,26 @@ /* | ||
*/ | ||
var gray = new RegExp('^gray\\(\\s*' + num + '()()\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var gray = new RegExp(("^gray\\(\\s*" + num + "()()\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
var parseHex = (function (color) { | ||
function parseHex (color) { | ||
var match; | ||
return (match = color.match(hex)) ? parseNumber(parseInt(match[1], 16), match[1].length) : undefined; | ||
}); | ||
} | ||
var parseRgb = (function (color) { | ||
function parseRgb (color) { | ||
var match, res; | ||
var match = void 0, | ||
res = void 0; | ||
if (match = color.match(rgb_num_old) || color.match(rgb_num_new)) { | ||
res = { | ||
res = { | ||
mode: 'rgb', | ||
r: match[1] / 255, | ||
g: match[2] / 255, | ||
b: match[3] / 255 | ||
r: match[1] / 255, | ||
g: match[2] / 255, | ||
b: match[3] / 255 | ||
}; | ||
} else if (match = color.match(rgb_per_old) || color.match(rgb_per_new)) { | ||
res = { | ||
res = { | ||
mode: 'rgb', | ||
r: match[1] / 100, | ||
g: match[2] / 100, | ||
b: match[3] / 100 | ||
r: match[1] / 100, | ||
g: match[2] / 100, | ||
b: match[3] / 100 | ||
}; | ||
@@ -1140,9 +1224,7 @@ } else { | ||
} | ||
return res; | ||
}); | ||
} | ||
var parseTransparent = (function (c) { | ||
return c === 'transparent' ? parseNumber(0x00000000, 8) : undefined; | ||
}); | ||
function parseTransparent (c) { return c === 'transparent' ? parseNumber(0x00000000, 8) : undefined; } | ||
@@ -1152,3 +1234,3 @@ var rgbDef = { | ||
channels: ['r', 'g', 'b', 'alpha'], | ||
parsers: [parseHex, parseRgb, parseNamed, parseTransparent], | ||
parsers: [ parseHex, parseRgb, parseNamed, parseTransparent ], | ||
interpolate: { | ||
@@ -1162,11 +1244,9 @@ r: interpolateFunctionLinear(interpolateNumber()), | ||
var fn = function fn(c) { | ||
return c < 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); | ||
}; | ||
var fn = function (c) { return c < 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); }; | ||
var convertRgbToLrgb = (function (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertRgbToLrgb (ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -1179,15 +1259,13 @@ var res = { | ||
}; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var fn$1 = function fn(c) { | ||
return c > 0.0031308 ? 1.055 * Math.pow(c, 1 / 2.4) - 0.055 : 12.92 * c; | ||
}; | ||
var fn$1 = function (c) { return c > 0.0031308 ? 1.055 * Math.pow(c, 1/2.4) - 0.055 : 12.92 * c; }; | ||
var convertLrgbToRgb = (function (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertLrgbToRgb (ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -1200,5 +1278,5 @@ var res = { | ||
}; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
@@ -1210,3 +1288,3 @@ var lrgbDef = { | ||
}, | ||
input: { | ||
input: { | ||
rgb: convertRgbToLrgb | ||
@@ -1225,30 +1303,23 @@ }, | ||
function convertHslToRgb (_ref) { | ||
var h = _ref.h, | ||
s = _ref.s, | ||
l = _ref.l, | ||
alpha = _ref.alpha; | ||
function convertHslToRgb(ref) { | ||
var h = ref.h; | ||
var s = ref.s; | ||
var l = ref.l; | ||
var alpha = ref.alpha; | ||
h = normalizeHue(h); | ||
var m1 = l + s * (l < 0.5 ? l : 1 - l); | ||
var m2 = m1 - (m1 - l) * 2 * Math.abs(h / 60 % 2 - 1); | ||
var res = void 0; | ||
switch (Math.floor(h / 60)) { | ||
case 0: | ||
res = { r: m1, g: m2, b: 2 * l - m1 };break; | ||
case 1: | ||
res = { r: m2, g: m1, b: 2 * l - m1 };break; | ||
case 2: | ||
res = { r: 2 * l - m1, g: m1, b: m2 };break; | ||
case 3: | ||
res = { r: 2 * l - m1, g: m2, b: m1 };break; | ||
case 4: | ||
res = { r: m2, g: 2 * l - m1, b: m1 };break; | ||
case 5: | ||
res = { r: m1, g: 2 * l - m1, b: m2 };break; | ||
default: | ||
res = { r: 2 * l - m1, g: 2 * l - m1, b: 2 * l - m1 }; | ||
var m2 = m1 - (m1 - l) * 2 * Math.abs(h/60 % 2 - 1); | ||
var res; | ||
switch (Math.floor(h/60)) { | ||
case 0: res = { r: m1, g: m2, b: 2 * l - m1 }; break; | ||
case 1: res = { r: m2, g: m1, b: 2 * l - m1 }; break; | ||
case 2: res = { r: 2 * l - m1, g: m1, b: m2 }; break; | ||
case 3: res = { r: 2 * l - m1, g: m2, b: m1 }; break; | ||
case 4: res = { r: m2, g: 2 * l - m1, b: m1 }; break; | ||
case 5: res = { r: m1, g: 2 * l - m1, b: m2 }; break; | ||
default: res = { r: 2 * l - m1, g: 2 * l - m1, b: 2 * l - m1 }; | ||
} | ||
res.mode = 'rgb'; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
@@ -1259,10 +1330,9 @@ } | ||
function convertRgbToHsl (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertRgbToHsl(ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
var M = Math.max(r, g, b), | ||
m = Math.min(r, g, b); | ||
var M = Math.max(r, g, b), m = Math.min(r, g, b); | ||
var res = { | ||
@@ -1273,24 +1343,20 @@ mode: 'hsl', | ||
}; | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (M - m !== 0) { res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
} | ||
var hue$1 = function hue(val, unit) { | ||
var hue$1 = function (val, unit) { | ||
switch (unit) { | ||
case 'deg': | ||
return +val; | ||
case 'rad': | ||
return val / Math.PI * 180; | ||
case 'grad': | ||
return val / 10 * 9; | ||
case 'turn': | ||
return val * 360; | ||
case 'deg': return +val; | ||
case 'rad': return val / Math.PI * 180; | ||
case 'grad': return val / 10 * 9; | ||
case 'turn': return val * 360; | ||
} | ||
}; | ||
var parseHsl = (function (color) { | ||
if (typeof color !== 'string') return; | ||
function parseHsl (color) { | ||
if (typeof color !== 'string') { return; } | ||
var match = color.match(hsl_old) || color.match(hsl_new); | ||
if (!match) return; | ||
if (!match) { return; } | ||
var res = { | ||
@@ -1308,8 +1374,8 @@ mode: 'hsl', | ||
return res; | ||
}); | ||
} | ||
var hslDef = { | ||
mode: 'hsl', | ||
output: { | ||
rgb: convertHslToRgb | ||
output: { | ||
rgb: convertHslToRgb | ||
}, | ||
@@ -1320,3 +1386,3 @@ input: { | ||
channels: ['h', 's', 'l', 'alpha'], | ||
parsers: [parseHsl], | ||
parsers: [ parseHsl ], | ||
interpolate: { | ||
@@ -1332,29 +1398,22 @@ h: interpolateFunctionLinear(interpolateHue()), | ||
function convertHsvToRgb (_ref) { | ||
var h = _ref.h, | ||
s = _ref.s, | ||
v = _ref.v, | ||
alpha = _ref.alpha; | ||
function convertHsvToRgb(ref) { | ||
var h = ref.h; | ||
var s = ref.s; | ||
var v = ref.v; | ||
var alpha = ref.alpha; | ||
h = normalizeHue(h); | ||
var f = Math.abs(h / 60 % 2 - 1); | ||
var res = void 0; | ||
switch (Math.floor(h / 60)) { | ||
case 0: | ||
res = { r: v, g: v * (1 - s * f), b: v * (1 - s) };break; | ||
case 1: | ||
res = { r: v * (1 - s * f), g: v, b: v * (1 - s) };break; | ||
case 2: | ||
res = { r: v * (1 - s), g: v, b: v * (1 - s * f) };break; | ||
case 3: | ||
res = { r: v * (1 - s), g: v * (1 - s * f), b: v };break; | ||
case 4: | ||
res = { r: v * (1 - s * f), g: v * (1 - s), b: v };break; | ||
case 5: | ||
res = { r: v, g: v * (1 - s), b: v * (1 - s * f) };break; | ||
default: | ||
res = { r: v * (1 - s), g: v * (1 - s), b: v * (1 - s) }; | ||
var f = Math.abs(h/60 % 2 - 1); | ||
var res; | ||
switch (Math.floor(h/60)) { | ||
case 0: res = { r: v, g: v * (1 - s * f), b: v * (1 - s) }; break; | ||
case 1: res = { r: v * (1 - s * f), g: v, b: v * (1 - s) }; break; | ||
case 2: res = { r: v * (1 - s), g: v, b: v * (1 - s * f) }; break; | ||
case 3: res = { r: v * (1 - s), g: v * (1 - s * f), b: v }; break; | ||
case 4: res = { r: v * (1 - s * f), g: v * (1 - s), b: v }; break; | ||
case 5: res = { r: v, g: v * (1 - s), b: v * (1 - s * f) }; break; | ||
default: res = { r: v * (1 - s), g: v * (1 - s), b: v * (1 - s) }; | ||
} | ||
res.mode = 'rgb'; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
@@ -1365,10 +1424,9 @@ } | ||
function convertRgbToHsv (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertRgbToHsv(ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
var M = Math.max(r, g, b), | ||
m = Math.min(r, g, b); | ||
var M = Math.max(r, g, b), m = Math.min(r, g, b); | ||
var res = { | ||
@@ -1379,4 +1437,4 @@ mode: 'hsv', | ||
}; | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (M - m !== 0) { res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
@@ -1387,4 +1445,4 @@ } | ||
mode: 'hsv', | ||
output: { | ||
rgb: convertHsvToRgb | ||
output: { | ||
rgb: convertHsvToRgb | ||
}, | ||
@@ -1405,51 +1463,51 @@ input: { | ||
function convertHsiToRgb (_ref) { | ||
var h = _ref.h, | ||
s = _ref.s, | ||
i = _ref.i, | ||
alpha = _ref.alpha; | ||
function convertHsiToRgb (ref) { | ||
var h = ref.h; | ||
var s = ref.s; | ||
var i = ref.i; | ||
var alpha = ref.alpha; | ||
h = normalizeHue(h); | ||
var f = Math.abs(h / 60 % 2 - 1); | ||
var res = void 0; | ||
switch (Math.floor(h / 60)) { | ||
case 0: | ||
var f = Math.abs(h/60 % 2 - 1); | ||
var res; | ||
switch (Math.floor(h/60)) { | ||
case 0: | ||
res = { | ||
r: i * (1 + s * (3 / (2 - f) - 1)), | ||
g: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
r: i * (1 + s * (3 / (2 - f) - 1)), | ||
g: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
b: i * (1 - s) | ||
}; | ||
break; | ||
case 1: | ||
case 1: | ||
res = { | ||
r: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
g: i * (1 + s * (3 / (2 - f) - 1)), | ||
r: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
g: i * (1 + s * (3 / (2 - f) - 1)), | ||
b: i * (1 - s) | ||
}; | ||
break; | ||
case 2: | ||
case 2: | ||
res = { | ||
r: i * (1 - s), | ||
g: i * (1 + s * (3 / (2 - f) - 1)), | ||
r: i * (1 - s), | ||
g: i * (1 + s * (3 / (2 - f) - 1)), | ||
b: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)) | ||
}; | ||
break; | ||
case 3: | ||
case 3: | ||
res = { | ||
r: i * (1 - s), | ||
g: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
r: i * (1 - s), | ||
g: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
b: i * (1 + s * (3 / (2 - f) - 1)) | ||
}; | ||
break; | ||
case 4: | ||
case 4: | ||
res = { | ||
r: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
g: i * (1 - s), | ||
r: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
g: i * (1 - s), | ||
b: i * (1 + s * (3 / (2 - f) - 1)) | ||
}; | ||
break; | ||
case 5: | ||
case 5: | ||
res = { | ||
r: i * (1 + s * (3 / (2 - f) - 1)), | ||
g: i * (1 - s), | ||
r: i * (1 + s * (3 / (2 - f) - 1)), | ||
g: i * (1 - s), | ||
b: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)) | ||
@@ -1463,3 +1521,3 @@ }; | ||
res.mode = 'rgb'; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
@@ -1470,10 +1528,9 @@ } | ||
function convertRgbToHsi (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertRgbToHsi(ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
var M = Math.max(r, g, b), | ||
m = Math.min(r, g, b); | ||
var M = Math.max(r, g, b), m = Math.min(r, g, b); | ||
var res = { | ||
@@ -1484,4 +1541,4 @@ mode: 'hsi', | ||
}; | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (M - m !== 0) { res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
@@ -1492,4 +1549,4 @@ } | ||
mode: 'hsi', | ||
output: { | ||
rgb: convertHsiToRgb | ||
output: { | ||
rgb: convertHsiToRgb | ||
}, | ||
@@ -1506,3 +1563,3 @@ input: { | ||
} | ||
}; | ||
} | ||
@@ -1519,7 +1576,7 @@ /* | ||
function convertHwbToRgb (_ref) { | ||
var h = _ref.h, | ||
w = _ref.w, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertHwbToRgb (ref) { | ||
var h = ref.h; | ||
var w = ref.w; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -1529,11 +1586,11 @@ // normalize w + b to 1 | ||
var s = w + b; | ||
w /= s; | ||
w /= s; | ||
b /= s; | ||
} | ||
return convertHsvToRgb({ | ||
h: h, | ||
s: b === 1 ? 1 : 1 - w / (1 - b), | ||
return convertHsvToRgb({ | ||
h: h, | ||
s: b === 1 ? 1 : 1 - w / (1 - b), | ||
v: 1 - b, | ||
alpha: alpha | ||
}); | ||
}); | ||
} | ||
@@ -1553,3 +1610,3 @@ | ||
var hsv = convertRgbToHsv(rgba); | ||
if (hsv === undefined) return undefined; | ||
if (hsv === undefined) { return undefined; } | ||
var res = { | ||
@@ -1560,11 +1617,11 @@ mode: 'hwb', | ||
}; | ||
if (hsv.h !== undefined) res.h = hsv.h; | ||
if (hsv.alpha !== undefined) res.alpha = hsv.alpha; | ||
if (hsv.h !== undefined) { res.h = hsv.h; } | ||
if (hsv.alpha !== undefined) { res.alpha = hsv.alpha; } | ||
return res; | ||
} | ||
var parseHwb = (function (color) { | ||
if (typeof color !== 'string') return undefined; | ||
function parseHwb (color) { | ||
if (typeof color !== 'string') { return undefined; } | ||
var match = color.match(hwb); | ||
if (!match) return undefined; | ||
if (!match) { return undefined; } | ||
var res = { | ||
@@ -1576,7 +1633,7 @@ mode: 'hwb', | ||
}; | ||
// normalize w + b to at most 1 | ||
if (res.w + res.b > 1) { | ||
var s = res.w + res.b; | ||
res.w /= s; | ||
res.w /= s; | ||
res.b /= s; | ||
@@ -1591,8 +1648,8 @@ } | ||
return res; | ||
}); | ||
} | ||
var hwbDef = { | ||
mode: 'hwb', | ||
output: { | ||
rgb: convertHwbToRgb | ||
output: { | ||
rgb: convertHwbToRgb | ||
}, | ||
@@ -1603,3 +1660,3 @@ input: { | ||
channels: ['h', 'w', 'b', 'alpha'], | ||
parsers: [parseHwb], | ||
parsers: [ parseHwb ], | ||
interpolate: { | ||
@@ -1622,19 +1679,17 @@ h: interpolateFunctionLinear(interpolateHue()), | ||
var Zn = 0.82521; | ||
var k = Math.pow(29, 3) / Math.pow(3, 3); | ||
var e = Math.pow(6, 3) / Math.pow(29, 3); | ||
var fn$2 = function fn(v) { | ||
return Math.pow(v, 3) > e ? Math.pow(v, 3) : (116 * v - 16) / k; | ||
}; | ||
var fn$2 = function (v) { return Math.pow(v, 3) > e ? Math.pow(v, 3) : (116 * v - 16) / k; }; | ||
var convertLabToXyz = (function (_ref) { | ||
var l = _ref.l, | ||
a = _ref.a, | ||
b = _ref.b; | ||
function convertLabToXyz (ref) { | ||
var l = ref.l; | ||
var a = ref.a; | ||
var b = ref.b; | ||
var fy = (l + 16) / 116; | ||
var fx = a / 500 + fy; | ||
var fz = fy - b / 200; | ||
var fx = a / 500 + fy; | ||
var fz = fy - b / 200; | ||
@@ -1646,3 +1701,3 @@ return { | ||
}; | ||
}); | ||
} | ||
@@ -1657,19 +1712,20 @@ /* | ||
var convertXyzToRgb = (function (_ref) { | ||
var x = _ref.x, | ||
y = _ref.y, | ||
z = _ref.z; | ||
function convertXyzToRgb (ref) { | ||
var x = ref.x; | ||
var y = ref.y; | ||
var z = ref.z; | ||
return convertLrgbToRgb({ | ||
r: x * 3.1338561 - y * 1.6168667 - 0.4906146 * z, | ||
g: x * -0.9787684 + y * 1.9161415 + 0.0334540 * z, | ||
b: x * 0.0719453 - y * 0.2289914 + 1.4052427 * z | ||
}); | ||
r: x * 3.1338561 - y * 1.6168667 - 0.4906146 * z, | ||
g: x * -0.9787684 + y * 1.9161415 + 0.0334540 * z, | ||
b: x * 0.0719453 - y * 0.2289914 + 1.4052427 * z | ||
}); | ||
} | ||
var convertLabToRgb = (function (lab) { | ||
function convertLabToRgb (lab) { | ||
var res = convertXyzToRgb(convertLabToXyz(lab)); | ||
res.mode = 'rgb'; | ||
if (lab.alpha !== undefined) res.alpha = lab.alpha; | ||
if (lab.alpha !== undefined) { res.alpha = lab.alpha; } | ||
return res; | ||
}); | ||
} | ||
@@ -1685,8 +1741,7 @@ /* | ||
var convertRgbToXyz = (function (rgb) { | ||
var _convertRgbToLrgb = convertRgbToLrgb(rgb), | ||
r = _convertRgbToLrgb.r, | ||
g = _convertRgbToLrgb.g, | ||
b = _convertRgbToLrgb.b; | ||
function convertRgbToXyz (rgb) { | ||
var ref = convertRgbToLrgb(rgb); | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
return { | ||
@@ -1697,29 +1752,27 @@ x: 0.4360747 * r + 0.3850649 * g + 0.1430804 * b, | ||
}; | ||
}); | ||
} | ||
var f = function f(value) { | ||
return value > e ? Math.cbrt(value) : (k * value + 16) / 116; | ||
}; | ||
var f = function (value) { return value > e ? Math.cbrt(value) : (k * value + 16) / 116; }; | ||
var convertXyzToLab = (function (_ref) { | ||
var x = _ref.x, | ||
y = _ref.y, | ||
z = _ref.z; | ||
function convertXyzToLab (ref) { | ||
var x = ref.x; | ||
var y = ref.y; | ||
var z = ref.z; | ||
var f0 = f(x / Xn); | ||
var f1 = f(y / Yn); | ||
var f2 = f(z / Zn); | ||
var f0 = f(x/Xn); | ||
var f1 = f(y/Yn); | ||
var f2 = f(z/Zn); | ||
return { | ||
mode: 'lab', | ||
l: 116 * f1 - 16, | ||
l: (116 * f1) - 16, | ||
a: 500 * (f0 - f1), | ||
b: 200 * (f1 - f2) | ||
}; | ||
}); | ||
} | ||
var convertRgbToLab = (function (rgb) { | ||
function convertRgbToLab (rgb) { | ||
var res = convertXyzToLab(convertRgbToXyz(rgb)); | ||
// Fixes achromatic RGB colors having a _slight_ chroma due to floating-point errors | ||
@@ -1731,11 +1784,10 @@ // and approximated computations in sRGB <-> CIELab. | ||
} | ||
if (rgb.alpha !== undefined) res.alpha = rgb.alpha; | ||
if (rgb.alpha !== undefined) { res.alpha = rgb.alpha; } | ||
return res; | ||
}); | ||
} | ||
var parseLab = (function (color) { | ||
if (typeof color !== 'string') return undefined; | ||
function parseLab (color) { | ||
if (typeof color !== 'string') { return undefined; } | ||
var match = void 0, | ||
res = void 0; | ||
var match, res; | ||
@@ -1767,8 +1819,8 @@ if (match = color.match(lab)) { | ||
return res; | ||
}); | ||
} | ||
var labDef = { | ||
mode: 'lab', | ||
output: { | ||
rgb: convertLabToRgb | ||
output: { | ||
rgb: convertLabToRgb | ||
}, | ||
@@ -1779,3 +1831,3 @@ input: { | ||
channels: ['l', 'a', 'b', 'alpha'], | ||
parsers: [parseLab], | ||
parsers: [ parseLab ], | ||
interpolate: { | ||
@@ -1794,7 +1846,7 @@ l: interpolateFunctionLinear(interpolateNumber()), | ||
*/ | ||
var convertLabToLch = (function (_ref) { | ||
var l = _ref.l, | ||
a = _ref.a, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertLabToLch (ref) { | ||
var l = ref.l; | ||
var a = ref.a; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -1807,6 +1859,6 @@ var c = Math.sqrt(a * a + b * b); | ||
}; | ||
if (c) res.h = normalizeHue(Math.atan2(b, a) * 180 / Math.PI); | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (c) { res.h = normalizeHue(Math.atan2(b, a) * 180 / Math.PI); } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
@@ -1818,7 +1870,7 @@ /* | ||
*/ | ||
var convertLchToLab = (function (_ref) { | ||
var l = _ref.l, | ||
c = _ref.c, | ||
h = _ref.h, | ||
alpha = _ref.alpha; | ||
function convertLchToLab (ref) { | ||
var l = ref.l; | ||
var c = ref.c; | ||
var h = ref.h; | ||
var alpha = ref.alpha; | ||
@@ -1828,23 +1880,19 @@ var res = { | ||
l: l, | ||
a: c === 0 ? 0 : c * Math.cos(h / 180 * Math.PI), | ||
b: c === 0 ? 0 : c * Math.sin(h / 180 * Math.PI) | ||
a: c === 0 ? 0 : c * Math.cos( h / 180 * Math.PI ), | ||
b: c === 0 ? 0 : c * Math.sin( h / 180 * Math.PI ) | ||
}; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var convertLchToRgb = (function (c) { | ||
return convertLabToRgb(convertLchToLab(c)); | ||
}); | ||
function convertLchToRgb (c) { return convertLabToRgb(convertLchToLab(c)); } | ||
var convertRgbToLch = (function (c) { | ||
return convertLabToLch(convertRgbToLab(c)); | ||
}); | ||
function convertRgbToLch (c) { return convertLabToLch(convertRgbToLab(c)); } | ||
var parseLch = (function (color) { | ||
function parseLch (color) { | ||
if (typeof color !== 'string') return undefined; | ||
var match = color.match(lch); | ||
if (typeof color !== 'string') { return undefined; } | ||
var match = color.match(lch$1); | ||
if (!match) { | ||
@@ -1866,5 +1914,5 @@ return undefined; | ||
} | ||
return res; | ||
}); | ||
} | ||
@@ -1877,3 +1925,3 @@ var lchDef = { | ||
}, | ||
input: { | ||
input: { | ||
rgb: convertRgbToLch, | ||
@@ -1883,3 +1931,3 @@ lch: convertLabToLch | ||
channels: ['l', 'c', 'h', 'alpha'], | ||
parsers: [parseLch], | ||
parsers: [ parseLch ], | ||
interpolate: { | ||
@@ -1893,3 +1941,7 @@ h: interpolateFunctionLinear(interpolateHue()), | ||
var M = [-0.14861, 1.78277, -0.29227, -0.90649, 1.97294, 0]; | ||
var M = [ | ||
-0.14861, 1.78277, | ||
-0.29227, -0.90649, | ||
1.97294, 0 | ||
]; | ||
@@ -1916,7 +1968,7 @@ var degToRad = Math.PI / 180; | ||
var convertRgbToCubehelix = (function (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertRgbToCubehelix (ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -1928,19 +1980,19 @@ | ||
var res = { | ||
var res = { | ||
mode: 'cubehelix', | ||
l: l, | ||
s: l === 0 || l === 1 ? undefined : Math.sqrt(x * x + y * y) / (M[4] * l * (1 - l)) | ||
s: (l === 0 || l === 1) ? undefined : Math.sqrt(x * x + y * y) / (M[4] * l * (1 - l)) | ||
}; | ||
if (res.s) res.h = Math.atan2(y, x) * radToDeg - 120; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (res.s) { res.h = Math.atan2(y, x) * radToDeg - 120; } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var convertCubehelixToRgb = (function (_ref) { | ||
var h = _ref.h, | ||
s = _ref.s, | ||
l = _ref.l, | ||
alpha = _ref.alpha; | ||
function convertCubehelixToRgb (ref) { | ||
var h = ref.h; | ||
var s = ref.s; | ||
var l = ref.l; | ||
var alpha = ref.alpha; | ||
@@ -1950,3 +2002,3 @@ var res = { mode: 'rgb' }; | ||
h = (h === undefined ? 0 : h + 120) * degToRad; | ||
var amp = s === undefined ? 0 : s * l * (1 - l); | ||
@@ -1961,5 +2013,5 @@ | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
@@ -2016,7 +2068,7 @@ /* | ||
var convertDlabToDlch = (function (_ref) { | ||
var l = _ref.l, | ||
a = _ref.a, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertDlabToDlch (ref) { | ||
var l = ref.l; | ||
var a = ref.a; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -2029,6 +2081,6 @@ var c = Math.sqrt(a * a + b * b); | ||
}; | ||
if (c) res.h = normalizeHue(Math.atan2(b, a) * 180 / Math.PI); | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (c) { res.h = normalizeHue(Math.atan2(b, a) * 180 / Math.PI); } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
@@ -2040,3 +2092,3 @@ var kE = 1; | ||
var sinθ = Math.sin(θ); | ||
var factor = 100 / Math.log(139 / 100); // ~ 303.67 | ||
var factor = 100/Math.log(139/100); // ~ 303.67 | ||
@@ -2048,7 +2100,7 @@ /* | ||
var convertDlchToLab = (function (_ref) { | ||
var l = _ref.l, | ||
c = _ref.c, | ||
h = _ref.h, | ||
alpha = _ref.alpha; | ||
function convertDlchToLab (ref) { | ||
var l = ref.l; | ||
var c = ref.c; | ||
var h = ref.h; | ||
var alpha = ref.alpha; | ||
@@ -2067,16 +2119,12 @@ | ||
var f = G * Math.sin(h / 180 * Math.PI - θ); | ||
res.a = e * cosθ - f / 0.83 * sinθ; | ||
res.b = e * sinθ + f / 0.83 * cosθ; | ||
res.a = e * cosθ - (f / 0.83) * sinθ; | ||
res.b = e * sinθ + (f / 0.83) * cosθ; | ||
} | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var convertDlabToLab = (function (c) { | ||
return convertDlchToLab(convertDlabToDlch(c)); | ||
}); | ||
function convertDlabToLab (c) { return convertDlchToLab(convertDlabToDlch(c)); } | ||
var convertDlabToRgb = (function (c) { | ||
return convertLabToRgb(convertDlabToLab(c)); | ||
}); | ||
function convertDlabToRgb (c) { return convertLabToRgb(convertDlabToLab(c)); } | ||
@@ -2087,7 +2135,7 @@ /* | ||
var convertLabToDlch = (function (_ref) { | ||
var l = _ref.l, | ||
a = _ref.a, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertLabToDlch (ref) { | ||
var l = ref.l; | ||
var a = ref.a; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -2107,11 +2155,11 @@ var e = a * cosθ + b * sinθ; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var convertDlchToDlab = (function (_ref) { | ||
var l = _ref.l, | ||
c = _ref.c, | ||
h = _ref.h, | ||
alpha = _ref.alpha; | ||
function convertDlchToDlab (ref) { | ||
var l = ref.l; | ||
var c = ref.c; | ||
var h = ref.h; | ||
var alpha = ref.alpha; | ||
@@ -2124,17 +2172,13 @@ var res = { | ||
}; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var convertLabToDlab = (function (c) { | ||
return convertDlchToDlab(convertLabToDlch(c)); | ||
}); | ||
function convertLabToDlab (c) { return convertDlchToDlab(convertLabToDlch(c)); } | ||
var convertRgbToDlab = (function (c) { | ||
return convertLabToDlab(convertRgbToLab(c)); | ||
}); | ||
function convertRgbToDlab (c) { return convertLabToDlab(convertRgbToLab(c)); } | ||
var dlabDef = { | ||
mode: 'dlab', | ||
output: { | ||
output: { | ||
lab: convertDlabToLab, | ||
@@ -2156,13 +2200,9 @@ rgb: convertDlabToRgb | ||
var convertDlchToRgb = (function (c) { | ||
return convertLabToRgb(convertDlchToLab(c)); | ||
}); | ||
function convertDlchToRgb (c) { return convertLabToRgb(convertDlchToLab(c)); } | ||
var convertRgbToDlch = (function (c) { | ||
return convertLabToDlch(convertRgbToLab(c)); | ||
}); | ||
function convertRgbToDlch (c) { return convertLabToDlch(convertRgbToLab(c)); } | ||
var dlchDef = { | ||
mode: 'dlch', | ||
output: { | ||
output: { | ||
lab: convertDlchToLab, | ||
@@ -2198,3 +2238,3 @@ dlab: convertDlchToDlab, | ||
var rgb$1 = converter('rgb'); | ||
var rgb$3 = converter('rgb'); | ||
var lrgb = converter('lrgb'); | ||
@@ -2206,3 +2246,3 @@ var hsl = converter('hsl'); | ||
var lab$1 = converter('lab'); | ||
var lch$1 = converter('lch'); | ||
var lch$2 = converter('lch'); | ||
var cubehelix = converter('cubehelix'); | ||
@@ -2212,3 +2252,3 @@ var dlab = converter('dlab'); | ||
var culori = rgb$1; | ||
var culori = rgb$3; | ||
@@ -2220,5 +2260,5 @@ var methods = /*#__PURE__*/Object.freeze({ | ||
hwb: hwb$1, | ||
rgb: rgb$1, | ||
rgb: rgb$3, | ||
lab: lab$1, | ||
lch: lch$1, | ||
lch: lch$2, | ||
lrgb: lrgb, | ||
@@ -2246,3 +2286,6 @@ cubehelix: cubehelix, | ||
differenceCmc: differenceCmc, | ||
differenceDin99o: differenceDin99o, | ||
nearest: nearest, | ||
displayable: displayable, | ||
clamp: clamp, | ||
defineMode: defineMode, | ||
@@ -2249,0 +2292,0 @@ getModeDefinition: getModeDefinition, |
@@ -1,1 +0,1 @@ | ||
!function(i,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):i.culori=o()}(this,function(){"use strict";var i={},o={},r=[],t=function(t){i[t.mode]=Object.assign(i[t.mode]||{},t.output),Object.keys(t.input||{}).forEach(function(o){i[o]||(i[o]={}),i[o][t.mode]=t.input[o]}),o[t.mode]=t,(t.parsers||[]).forEach(function(i){return r.push(i)})},n=function(i){return o[i]},e=function(i){for(var o=void 0,t=0,n=r.length;t<n&&void 0===(o=r[t++](i)););return o},a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(i){return typeof i}:function(i){return i&&"function"==typeof Symbol&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},d=Object.assign||function(i){for(var o=1;o<arguments.length;o++){var r=arguments[o];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(i[t]=r[t])}return i},v=function(){var o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"rgb";return function(r){return void 0!==(r=function(i,o){return void 0===i?void 0:"object"!==(void 0===i?"undefined":a(i))?e(i):void 0===i.mode?d({},i,{mode:o}):i}(r,o))?r.mode===o?r:i[r.mode][o]?i[r.mode][o](r):"rgb"===o?i[r.mode].rgb(r):i.rgb[o](i[r.mode].rgb(r)):void 0}},u=function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:4;return function(o){return"number"==typeof o?function(i,o){return Math.round(i*(o=Math.pow(10,o)))/o}(o,i):o}},h=function(i){return Math.round(255*Math.max(0,Math.min(i,1)))},l=v("rgb"),f=u(2),c=function(){return function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}},g=function(){return function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})}},s=function(i){return(i%=360)<0?i+360:i},p=function(){var i=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return function(o){if(2===o.length){if(void 0===o[0]&&void 0===o[1])return;if(void 0!==o[0]&&void 0!==o[1]){if(i){var r=s(o[0]),t=s(o[1]);return Math.abs(t-r)>180?[r,t-360*Math.sign(t-r)]:[r,t]}return o}return void 0===o[0]?o[1]:o[0]}if(void 0!==o[0]||void 0!==o[1]||void 0!==o[2]||void 0!==o[3])return i?o.map(function(i){return s(i)}):o}},b=function(i){return i},M=function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:b,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return function(r,t){var n=(t=Math.pow(t,o))*(r.length-1),e=Math.floor(n),d=r[e],v=r[e+1],u=n-e,h=i([d,v],u);return"object"===(void 0===h?"undefined":a(h))?(d=h[0])+u*((v=h[1])-d):h}},m=function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"rgb",o=n(i).channels,r=v(i);return function(i,t){var n=r(i),e=r(t);return Math.sqrt(o.reduce(function(i,o){return i+("alpha"===o?0:Math.pow(n[o]-e[o],2))},0))}},w=function(i){return i},y=function(i,o){if("number"==typeof i)return 3===o?{mode:"rgb",r:(i>>8&15|i>>4&240)/255,g:(i>>4&15|240&i)/255,b:(15&i|i<<4&240)/255}:4===o?{mode:"rgb",r:(i>>12&15|i>>8&240)/255,g:(i>>8&15|i>>4&240)/255,b:(i>>4&15|240&i)/255,alpha:(15&i|i<<4&240)/255}:6===o?{mode:"rgb",r:(i>>16&255)/255,g:(i>>8&255)/255,b:(255&i)/255}:8===o?{mode:"rgb",r:(i>>24&255)/255,g:(i>>16&255)/255,b:(i>>8&255)/255,alpha:(255&i)/255}:void 0},k={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},I=(/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/+"").replace(/^\/|\/$/g,""),P=I+"%",x="(?:"+I+"%|"+I+")",q="(?:"+I+"(deg|grad|rad|turn)|"+I+")",j="\\s*,\\s*",E="\\s+",$=new RegExp("^rgba?\\(\\s*"+I+j+I+j+I+"\\s*(?:,\\s*"+x+"\\s*)?\\)$"),R=new RegExp("^rgba?\\(\\s*"+P+j+P+j+P+"\\s*(?:,\\s*"+x+"\\s*)?\\)$"),O=new RegExp("^rgba?\\(\\s*"+I+E+I+E+I+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),S=new RegExp("^rgba?\\(\\s*"+P+E+P+E+P+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),z=new RegExp("^hsla?\\(\\s*"+q+j+P+j+P+"\\s*(?:,\\s*"+x+"\\s*)?\\)$"),C=new RegExp("^hsla?\\(\\s*"+q+E+P+E+P+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),F=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,A=new RegExp("^hwb\\(\\s*"+q+E+P+E+P+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),L=new RegExp("^lab\\(\\s*"+I+E+I+E+I+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),N=new RegExp("^lch\\(\\s*"+I+E+I+E+q+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),D=new RegExp("^gray\\(\\s*"+I+"()()\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),H={mode:"rgb",channels:["r","g","b","alpha"],parsers:[function(i){var o;return(o=i.match(F))?y(parseInt(o[1],16),o[1].length):void 0},function(i){var o=void 0,r=void 0;if(o=i.match($)||i.match(O))r={mode:"rgb",r:o[1]/255,g:o[2]/255,b:o[3]/255};else{if(!(o=i.match(R)||i.match(S)))return;r={mode:"rgb",r:o[1]/100,g:o[2]/100,b:o[3]/100}}return void 0!==o[4]?r.alpha=o[4]/100:void 0!==o[5]&&(r.alpha=+o[5]),r},function(i){return"string"==typeof i&&y(k[i.toLowerCase()],6)||void 0},function(i){return"transparent"===i?y(0,8):void 0}],interpolate:{r:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),g:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),b:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:M(function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}},B=function(i){return i<.04045?i/12.92:Math.pow((i+.055)/1.055,2.4)},G=function(i){var o=i.r,r=i.g,t=i.b,n=i.alpha,e={mode:"lrgb",r:B(o),g:B(r),b:B(t)};return void 0!==n&&(e.alpha=n),e},J=function(i){return i>.0031308?1.055*Math.pow(i,1/2.4)-.055:12.92*i},K=function(i){var o=i.r,r=i.g,t=i.b,n=i.alpha,e={mode:"rgb",r:J(o),g:J(r),b:J(t)};return void 0!==n&&(e.alpha=n),e},Q={mode:"lrgb",output:{rgb:K},input:{rgb:G},channels:["r","g","b","alpha"],interpolate:{r:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),g:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),b:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:M(function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};var T=function(i,o){switch(o){case"deg":return+i;case"rad":return i/Math.PI*180;case"grad":return i/10*9;case"turn":return 360*i}},U={mode:"hsl",output:{rgb:function(i){var o=i.h,r=i.s,t=i.l,n=i.alpha;o=s(o);var e=t+r*(t<.5?t:1-t),a=e-2*(e-t)*Math.abs(o/60%2-1),d=void 0;switch(Math.floor(o/60)){case 0:d={r:e,g:a,b:2*t-e};break;case 1:d={r:a,g:e,b:2*t-e};break;case 2:d={r:2*t-e,g:e,b:a};break;case 3:d={r:2*t-e,g:a,b:e};break;case 4:d={r:a,g:2*t-e,b:e};break;case 5:d={r:e,g:2*t-e,b:a};break;default:d={r:2*t-e,g:2*t-e,b:2*t-e}}return d.mode="rgb",void 0!==n&&(d.alpha=n),d}},input:{rgb:function(i){var o=i.r,r=i.g,t=i.b,n=i.alpha,e=Math.max(o,r,t),a=Math.min(o,r,t),d={mode:"hsl",s:e===a?0:(e-a)/(1-Math.abs(e+a-1)),l:.5*(e+a)};return e-a!=0&&(d.h=60*(e===o?(r-t)/(e-a)+6*(r<t):e===r?(t-o)/(e-a)+2:(o-r)/(e-a)+4)),void 0!==n&&(d.alpha=n),d}},channels:["h","s","l","alpha"],parsers:[function(i){if("string"==typeof i){var o=i.match(z)||i.match(C);if(o){var r={mode:"hsl",h:void 0===o[3]?T(o[1],o[2]):+o[3],s:Math.min(Math.max(0,o[4]/100),1),l:Math.min(Math.max(0,o[5]/100),1)};return void 0!==o[6]?r.alpha=o[6]/100:void 0!==o[7]&&(r.alpha=o[7]/255),r}}}],interpolate:{h:M(p()),s:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),l:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:M(function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};function V(i){var o=i.h,r=i.s,t=i.v,n=i.alpha;o=s(o);var e=Math.abs(o/60%2-1),a=void 0;switch(Math.floor(o/60)){case 0:a={r:t,g:t*(1-r*e),b:t*(1-r)};break;case 1:a={r:t*(1-r*e),g:t,b:t*(1-r)};break;case 2:a={r:t*(1-r),g:t,b:t*(1-r*e)};break;case 3:a={r:t*(1-r),g:t*(1-r*e),b:t};break;case 4:a={r:t*(1-r*e),g:t*(1-r),b:t};break;case 5:a={r:t,g:t*(1-r),b:t*(1-r*e)};break;default:a={r:t*(1-r),g:t*(1-r),b:t*(1-r)}}return a.mode="rgb",void 0!==n&&(a.alpha=n),a}function W(i){var o=i.r,r=i.g,t=i.b,n=i.alpha,e=Math.max(o,r,t),a=Math.min(o,r,t),d={mode:"hsv",s:0===e?0:1-a/e,v:e};return e-a!=0&&(d.h=60*(e===o?(r-t)/(e-a)+6*(r<t):e===r?(t-o)/(e-a)+2:(o-r)/(e-a)+4)),void 0!==n&&(d.alpha=n),d}var X={mode:"hsv",output:{rgb:V},input:{rgb:W},channels:["h","s","v","alpha"],interpolate:{h:M(p()),s:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),v:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:M(function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};var Y={mode:"hsi",output:{rgb:function(i){var o=i.h,r=i.s,t=i.i,n=i.alpha;o=s(o);var e=Math.abs(o/60%2-1),a=void 0;switch(Math.floor(o/60)){case 0:a={r:t*(1+r*(3/(2-e)-1)),g:t*(1+r*(3*(1-e)/(2-e)-1)),b:t*(1-r)};break;case 1:a={r:t*(1+r*(3*(1-e)/(2-e)-1)),g:t*(1+r*(3/(2-e)-1)),b:t*(1-r)};break;case 2:a={r:t*(1-r),g:t*(1+r*(3/(2-e)-1)),b:t*(1+r*(3*(1-e)/(2-e)-1))};break;case 3:a={r:t*(1-r),g:t*(1+r*(3*(1-e)/(2-e)-1)),b:t*(1+r*(3/(2-e)-1))};break;case 4:a={r:t*(1+r*(3*(1-e)/(2-e)-1)),g:t*(1-r),b:t*(1+r*(3/(2-e)-1))};break;case 5:a={r:t*(1+r*(3/(2-e)-1)),g:t*(1-r),b:t*(1+r*(3*(1-e)/(2-e)-1))};break;default:a={r:t*(1-r),g:t*(1-r),b:t*(1-r)}}return a.mode="rgb",void 0!==n&&(a.alpha=n),a}},input:{rgb:function(i){var o=i.r,r=i.g,t=i.b,n=i.alpha,e=Math.max(o,r,t),a=Math.min(o,r,t),d={mode:"hsi",s:o+r+t===0?0:1-3*a/(o+r+t),i:(o+r+t)/3};return e-a!=0&&(d.h=60*(e===o?(r-t)/(e-a)+6*(r<t):e===r?(t-o)/(e-a)+2:(o-r)/(e-a)+4)),void 0!==n&&(d.alpha=n),d}},channels:["h","s","i","alpha"],interpolate:{h:M(p()),s:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),i:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:M(function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};var Z={mode:"hwb",output:{rgb:function(i){var o=i.h,r=i.w,t=i.b,n=i.alpha;if(r+t>1){var e=r+t;r/=e,t/=e}return V({h:o,s:1===t?1:1-r/(1-t),v:1-t,alpha:n})}},input:{rgb:function(i){var o=W(i);if(void 0!==o){var r={mode:"hwb",w:(1-o.s)*o.v,b:1-o.v};return void 0!==o.h&&(r.h=o.h),void 0!==o.alpha&&(r.alpha=o.alpha),r}}},channels:["h","w","b","alpha"],parsers:[function(i){if("string"==typeof i){var o=i.match(A);if(o){var r={mode:"hwb",h:void 0===o[3]?T(o[1],o[2]):+o[3],w:o[4]/100,b:o[5]/100};if(r.w+r.b>1){var t=r.w+r.b;r.w/=t,r.b/=t}return void 0!==o[6]?r.alpha=o[6]/100:void 0!==o[7]&&(r.alpha=o[7]/255),r}}}],interpolate:{h:M(p()),w:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),b:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:M(function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}},_=Math.pow(29,3)/Math.pow(3,3),ii=Math.pow(6,3)/Math.pow(29,3),oi=function(i){return Math.pow(i,3)>ii?Math.pow(i,3):(116*i-16)/_},ri=function(i){var o,r,t,n,e,a=function(i){var o=i.x,r=i.y,t=i.z;return K({r:3.1338561*o-1.6168667*r-.4906146*t,g:-.9787684*o+1.9161415*r+.033454*t,b:.0719453*o-.2289914*r+1.4052427*t})}((r=(o=i).l,t=o.a,e=(n=(r+16)/116)-o.b/200,{x:.96422*oi(t/500+n),y:1*oi(n),z:.82521*oi(e)}));return a.mode="rgb",void 0!==i.alpha&&(a.alpha=i.alpha),a},ti=function(i){return i>ii?Math.cbrt(i):(_*i+16)/116},ni=function(i){var o,r,t,n,e,a,d=(o=function(i){var o=G(i),r=o.r,t=o.g,n=o.b;return{x:.4360747*r+.3850649*t+.1430804*n,y:.2225045*r+.7168786*t+.0606169*n,z:.0139322*r+.0971045*t+.7141733*n}}(i),r=o.x,t=o.y,n=o.z,e=ti(r/.96422),{mode:"lab",l:116*(a=ti(t/1))-16,a:500*(e-a),b:200*(a-ti(n/.82521))});return i.r===i.b===i.g&&(d.a=d.b=0),void 0!==i.alpha&&(d.alpha=i.alpha),d},ei={mode:"lab",output:{rgb:ri},input:{rgb:ni},channels:["l","a","b","alpha"],parsers:[function(i){if("string"==typeof i){var o=void 0,r=void 0;if(o=i.match(L))r={mode:"lab",l:+o[1],a:+o[2],b:+o[3]};else{if(!(o=i.match(D)))return;r={mode:"lab",l:+o[1],a:0,b:0}}return void 0!==o[4]?r.alpha=o[4]/100:void 0!==o[5]&&(r.alpha=+o[5]),r}}],interpolate:{l:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),a:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),b:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:M(function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}},ai=function(i){var o=i.l,r=i.a,t=i.b,n=i.alpha,e=Math.sqrt(r*r+t*t),a={mode:"lch",l:o,c:e};return e&&(a.h=s(180*Math.atan2(t,r)/Math.PI)),void 0!==n&&(a.alpha=n),a},di=function(i){var o=i.l,r=i.c,t=i.h,n=i.alpha,e={mode:"lab",l:o,a:0===r?0:r*Math.cos(t/180*Math.PI),b:0===r?0:r*Math.sin(t/180*Math.PI)};return void 0!==n&&(e.alpha=n),e},vi={mode:"lch",output:{lab:di,rgb:function(i){return ri(di(i))}},input:{rgb:function(i){return ai(ni(i))},lch:ai},channels:["l","c","h","alpha"],parsers:[function(i){if("string"==typeof i){var o=i.match(N);if(o){var r={mode:"lch",l:+o[1],c:Math.max(0,+o[2]),h:void 0===o[5]?T(o[3],o[4]):+o[5]};return void 0!==o[6]?r.alpha=o[6]/100:void 0!==o[7]&&(r.alpha=+o[7]),r}}}],interpolate:{h:M(p()),c:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),l:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:M(function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}},ui=[-.14861,1.78277,-.29227,-.90649,1.97294,0],hi=Math.PI/180,li=180/Math.PI,fi=ui[3]*ui[4],ci=ui[1]*ui[4],gi=ui[1]*ui[2]-ui[0]*ui[3],si={mode:"cubehelix",channels:["h","s","l","alpha"],input:{rgb:function(i){var o=i.r,r=i.g,t=i.b,n=i.alpha,e=(gi*t+o*fi-r*ci)/(gi+fi-ci),a=t-e,d=(ui[4]*(r-e)-ui[2]*a)/ui[3],v={mode:"cubehelix",l:e,s:0===e||1===e?void 0:Math.sqrt(a*a+d*d)/(ui[4]*e*(1-e))};return v.s&&(v.h=Math.atan2(d,a)*li-120),void 0!==n&&(v.alpha=n),v}},output:{rgb:function(i){var o=i.h,r=i.s,t=i.l,n=i.alpha,e={mode:"rgb"};o=(void 0===o?0:o+120)*hi;var a=void 0===r?0:r*t*(1-t),d=Math.cos(o),v=Math.sin(o);return e.r=t+a*(ui[0]*d+ui[1]*v),e.g=t+a*(ui[2]*d+ui[3]*v),e.b=t+a*(ui[4]*d+ui[5]*v),void 0!==n&&(e.alpha=n),e}},interpolate:{h:M(p()),s:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),l:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:M(function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}},pi=function(i){var o=i.l,r=i.a,t=i.b,n=i.alpha,e=Math.sqrt(r*r+t*t),a={mode:"dlch",l:o,c:e};return e&&(a.h=s(180*Math.atan2(t,r)/Math.PI)),void 0!==n&&(a.alpha=n),a},bi=26/180*Math.PI,Mi=Math.cos(bi),mi=Math.sin(bi),wi=100/Math.log(1.39),yi=function(i){var o=i.l,r=i.c,t=i.h,n=i.alpha,e={mode:"lab",l:(Math.exp(1*o/wi)-1)/.0039};if(void 0===t)e.a=e.b=0;else{var a=(Math.exp(.0435*r*1*1)-1)/.075,d=a*Math.cos(t/180*Math.PI-bi),v=a*Math.sin(t/180*Math.PI-bi);e.a=d*Mi-v/.83*mi,e.b=d*mi+v/.83*Mi}return void 0!==n&&(e.alpha=n),e},ki=function(i){return yi(pi(i))},Ii=function(i){var o=i.l,r=i.a,t=i.b,n=i.alpha,e=r*Mi+t*mi,a=.83*(t*Mi-r*mi),d=Math.sqrt(e*e+a*a),v={mode:"dlch",l:wi/1*Math.log(1+.0039*o),c:Math.log(1+.075*d)/.0435};return v.c&&(v.h=(Math.atan2(a,e)+bi)/Math.PI*180),void 0!==n&&(v.alpha=n),v},Pi=function(i){var o=i.l,r=i.c,t=i.h,n=i.alpha,e={mode:"dlab",l:o,a:0===r?0:r*Math.cos(t/180*Math.PI),b:0===r?0:r*Math.sin(t/180*Math.PI)};return void 0!==n&&(e.alpha=n),e},xi=function(i){return Pi(Ii(i))},qi={mode:"dlab",output:{lab:ki,rgb:function(i){return ri(ki(i))}},input:{lab:xi,rgb:function(i){return xi(ni(i))}},channels:["l","a","b","alpha"],interpolate:{l:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),a:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),b:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:M(function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}},ji={mode:"dlch",output:{lab:yi,dlab:Pi,rgb:function(i){return ri(yi(i))}},input:{lab:Ii,dlab:pi,rgb:function(i){return Ii(ni(i))}},channels:["l","c","h","alpha"],interpolate:{l:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),c:M(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),h:M(p()),alpha:M(function(i,o){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===o||void 0===i[1]&&1===o)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};t(H),t(Q),t(U),t(X),t(Y),t(Z),t(ei),t(vi),t(si),t(qi),t(ji);var Ei=v("rgb"),$i=v("lrgb"),Ri=v("hsl"),Oi=v("hsv"),Si=v("hsi"),zi=v("hwb"),Ci=v("lab"),Fi=v("lch"),Ai=v("cubehelix"),Li=v("dlab"),Ni=v("dlch"),Di=Ei,Hi=Object.freeze({hsl:Ri,hsv:Oi,hsi:Si,hwb:zi,rgb:Ei,lab:Ci,lch:Fi,lrgb:$i,cubehelix:Ai,dlab:Li,dlch:Ni,formatter:function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"rgb";return function(o){var r=l(o);if(void 0!==r){var t=h(r.r),n=h(r.b),e=h(r.g);return"hex"===i?"#"+(1<<24|t<<16|e<<8|n).toString(16).slice(1):"rgb"===i?void 0===o.alpha||1===o.alpha?"rgb("+t+", "+e+", "+n+")":"rgba("+t+", "+e+", "+n+", "+f(o.alpha)+")":void 0}}},converter:v,round:u,parse:e,interpolate:function(i){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb",r=arguments[2],t=function(i){for(var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb",r=n(o).channels,t={mode:o},e=function(o){t[r[o]]=i.map(function(i){return i[r[o]]})},a=0;a<r.length;a++)e(a);return t}(i.map(v(o)),o);r=Object.assign({},n(o).interpolate,r);var e=Object.keys(r);return function(i){i=Math.min(Math.max(0,i),1);for(var n={mode:o},a=void 0,d=0;d<e.length;d++)void 0!==(a=r[e[d]](t[e[d]],i))&&(n[e[d]]=a);return n}},interpolateNumber:c,interpolateAlpha:g,interpolateHue:p,interpolateFunctionLinear:M,interpolateFunctionSpline:function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:b,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"bspline",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return function(t,n){n=Math.pow(n,r);var e=t.length-1,d=1===n?e-1:Math.floor(n*e);"natural"===o&&(t=function(i){var o,r=i.length-1,t=new Array(r),n=new Array(r),e=new Array(r);for(t[1]=.25,n[1]=(6*i[1]-i[0])/4,o=2;o<r;++o)t[o]=1/(4-t[o-1]),n[o]=(6*i[o]-(o==r-1?i[r]:0)-n[o-1])*t[o];for(e[0]=i[0],e[r]=i[r],r-1>0&&(e[r-1]=n[r-1]),o=r-2;o>0;--o)e[o]=n[o]-t[o]*e[o+1];return e}(t));var v=t[d],u=t[d+1],h=d>0?t[d-1]:2*v-u,l=d<e-1?t[d+2]:2*u-v,f=i([h,v,u,l]);return"object"===(void 0===f?"undefined":a(f))?function(i,o,r,t,n){var e=n*n,a=e*n;return((1-3*n+3*e-a)*i+(4-6*e+3*a)*o+(1+3*n+3*e-3*a)*r+a*t)/6}(f[0],f[1],f[2],f[3],(n-d/e)*e):f}},interpolateFunctionCosine:function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:b,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return function(r,t){var n=(t=Math.pow(t,o))*(r.length-1),e=Math.floor(n),d=r[e],v=r[e+1],u=n-e,h=i([d,v],u);if("object"===(void 0===h?"undefined":a(h))){d=h[0],v=h[1];var l=(1-Math.cos(u*Math.PI))/2;return d*(1-l)+v*l}return h}},interpolateFunctionMonotone:function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:b,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return function(r,t){t=Math.pow(t,o);var n=r.length-1,e=void 0;1===t?(e=n-1,t=1):e=Math.floor(t*n);var d=r[e],v=r[e+1],u=e>0?r[e-1]:2*d-v,h=e<n-1?r[e+2]:2*v-d,l=i([u,d,v,h]);return"object"===(void 0===l?"undefined":a(l))?function(i,o,r,t,n,e){var a=e*e,d=(r-i)/(2*n),v=(t-o)/(2*n),u=(r-o)/n;return(d+v-2*u)/(n*n)*(a*e)+(3*u-2*d-v)/n*a+d*e+o}(l[0],l[1],l[2],l[3],1/n,t-e/n):l}},samples:function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(i<2)return i<1?[]:[Math.pow(.5,o)];for(var r=[],t=0;t<i;t++)r.push(Math.pow(t/(i-1),o));return r},differenceEuclidean:m,differenceCie76:function(){return m("lab")},differenceCie94:function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.045,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.015,t=v("lab");return function(n,e){var a=t(n),d=t(e),v=a.l,u=a.a,h=a.b,l=Math.sqrt(u*u+h*h),f=d.l,c=d.a,g=d.b,s=Math.sqrt(c*c+g*g),p=Math.pow(v-f,2),b=Math.pow(l-s,2),M=Math.pow(u-c,2)+Math.pow(h-g,2)-b;return Math.sqrt(p/Math.pow(i,2)+b/Math.pow(1+o*l,2)+M/Math.pow(1+r*l,2))}},differenceCiede2000:function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,t=v("lab");return function(n,e){var a=t(n),d=t(e),v=a.l,u=a.a,h=a.b,l=Math.sqrt(u*u+h*h),f=d.l,c=d.a,g=d.b,s=(l+Math.sqrt(c*c+g*g))/2,p=.5*(1-Math.sqrt(Math.pow(s,7)/(Math.pow(s,7)+Math.pow(25,7)))),b=u*(1+p),M=c*(1+p),m=Math.sqrt(b*b+h*h),w=Math.sqrt(M*M+g*g),y=Math.abs(b)+Math.abs(h)===0?0:Math.atan2(h,b);y+=2*(y<0)*Math.PI;var k=Math.abs(M)+Math.abs(g)===0?0:Math.atan2(g,M);k+=2*(k<0)*Math.PI;var I=f-v,P=w-m,x=m*w==0?0:k-y;x-=2*(x>Math.PI)*Math.PI,x+=2*(x<-Math.PI)*Math.PI;var q=2*Math.sqrt(m*w)*Math.sin(x/2),j=(v+f)/2,E=(m+w)/2,$=void 0;m*w==0?$=y+k:($=(y+k)/2,$-=(Math.abs(y-k)>Math.PI)*Math.PI,$+=2*($<0)*Math.PI);var R=Math.pow(j-50,2),O=1-.17*Math.cos($-Math.PI/6)+.24*Math.cos(2*$)+.32*Math.cos(3*$+Math.PI/30)-.2*Math.cos(4*$-63*Math.PI/180),S=1+.015*R/Math.sqrt(20+R),z=1+.045*E,C=1+.015*E*O,F=30*Math.PI/180*Math.exp(-1*Math.pow((180/Math.PI*$-275)/25,2)),A=2*Math.sqrt(Math.pow(E,7)/(Math.pow(E,7)+Math.pow(25,7))),L=-1*Math.sin(2*F)*A;return Math.sqrt(Math.pow(I/(i*S),2)+Math.pow(P/(o*z),2)+Math.pow(q/(r*C),2)+L*P/(o*z)*q/(r*C))}},differenceCmc:function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=v("lab");return function(t,n){var e=r(t),a=r(n),d=e.l,v=e.a,u=e.b,h=Math.sqrt(v*v+u*u),l=Math.atan2(u,v);l+=2*Math.PI*(l<0);var f=a.l,c=a.a,g=a.b,s=Math.sqrt(c*c+g*g),p=Math.pow(d-f,2),b=Math.pow(h-s,2),M=Math.pow(v-c,2)+Math.pow(u-g,2)-b,m=Math.sqrt(Math.pow(h,4)/(Math.pow(h,4)+1900)),w=l>=164/180*Math.PI&&l<=345/180*Math.PI?.56+Math.abs(.2*Math.cos(l+168/180*Math.PI)):.36+Math.abs(.4*Math.cos(l+35/180*Math.PI)),y=d<16?.511:.040975*d/(1+.01765*d),k=.0638*h/(1+.0131*h)+.638,I=k*(m*w+1-m);return Math.sqrt(p/Math.pow(i*y,2),b/Math.pow(o*k,2),M/Math.pow(I,2))}},nearest:function(i){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:m(),r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:w,t=i.map(function(i,o){return{color:r(i),i:o}});return function(i){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1/0;return isFinite(r)&&(r=Math.max(1,Math.min(r,t.length-1))),t.forEach(function(r){r.d=o(i,r.color)}),t.sort(function(i,o){return i.d-o.d}).slice(0,r).filter(function(i){return i.d<n}).map(function(i){return i.color})}},defineMode:t,getModeDefinition:n,colorsNamed:k,default:Di});return Object.assign(Di,Hi),Di}); | ||
!function(i,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):i.culori=r()}(this,function(){"use strict";var i={},r={},o=[],t=function(t){i[t.mode]=Object.assign(i[t.mode]||{},t.output),Object.keys(t.input||{}).forEach(function(r){i[r]||(i[r]={}),i[r][t.mode]=t.input[r]}),r[t.mode]=t,(t.parsers||[]).forEach(function(i){return o.push(i)})},n=function(i){return r[i]},e=function(i){for(var r,t=0,n=o.length;t<n&&void 0===(r=o[t++](i)););return r},a=function(r){return void 0===r&&(r="rgb"),function(o){return void 0!==(o=function(i,r){return void 0===i?void 0:"object"!=typeof i?e(i):void 0===i.mode?Object.assign({},i,{mode:r}):i}(o,r))?o.mode===r?o:i[o.mode][r]?i[o.mode][r](o):"rgb"===r?i[o.mode].rgb(o):i.rgb[r](i[o.mode].rgb(o)):void 0}},d=function(i,r){return Math.round(i*(r=Math.pow(10,r)))/r};function v(i){return void 0===i&&(i=4),function(r){return"number"==typeof r?d(r,i):r}}function u(i){return Math.round(255*Math.max(0,Math.min(i,1)))}var h=a("rgb"),l=v(2);function f(){return function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}}function c(){return function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})}}function s(i){return(i%=360)<0?i+360:i}function p(i){return void 0===i&&(i=!0),function(r){if(2===r.length){if(void 0===r[0]&&void 0===r[1])return;if(void 0!==r[0]&&void 0!==r[1]){if(i){var o=s(r[0]),t=s(r[1]);return Math.abs(t-o)>180?[o,t-360*Math.sign(t-o)]:[o,t]}return r}return void 0===r[0]?r[1]:r[0]}if(void 0!==r[0]||void 0!==r[1]||void 0!==r[2]||void 0!==r[3])return i?r.map(function(i){return s(i)}):r}}function b(i){return i}function g(i,r){return void 0===i&&(i=b),void 0===r&&(r=1),function(o,t){var n=(t=Math.pow(t,r))*(o.length-1),e=Math.floor(n),a=o[e],d=o[e+1],v=n-e,u=i([a,d],v);return"object"==typeof u?(a=u[0])+v*((d=u[1])-a):u}}var M=function(i,r,o,t,n){var e=n*n,a=e*n;return((1-3*n+3*e-a)*i+(4-6*e+3*a)*r+(1+3*n+3*e-3*a)*o+a*t)/6},m=function(i){var r,o=i.length-1,t=new Array(o),n=new Array(o),e=new Array(o);for(t[1]=.25,n[1]=(6*i[1]-i[0])/4,r=2;r<o;++r)t[r]=1/(4-t[r-1]),n[r]=(6*i[r]-(r==o-1?i[o]:0)-n[r-1])*t[r];for(e[0]=i[0],e[o]=i[o],o-1>0&&(e[o-1]=n[o-1]),r=o-2;r>0;--r)e[r]=n[r]-t[r]*e[r+1];return e};var w=function(i,r,o,t,n,e){var a=e*e,d=(o-i)/(2*n),v=(t-r)/(2*n),u=(o-r)/n;return(d+v-2*u)/(n*n)*(a*e)+(3*u-2*d-v)/n*a+d*e+r};var y=a("rgb");function k(i){var r=y(i);return void 0!==r&&r.r>=0&&r.r<=1&&r.g>=0&&r.g<=1&&r.b>=0&&r.b<=1}var x=a("lch"),I=a("rgb"),P=function(i){return void 0===i?void 0:"object"!=typeof i?e(i):void 0===i.mode?void 0:i},q=function(i){return Math.max(0,Math.min(i,1))},j=function(i){var r=I(i);return r.r=q(r.r),r.g=q(r.g),r.b=q(r.b),r};var E=function(i){void 0===i&&(i="rgb");var r=n(i).channels,o=a(i);return function(i,t){var n=o(i),e=o(t);return Math.sqrt(r.reduce(function(i,r){return i+("alpha"===r?0:Math.pow(n[r]-e[r],2))},0))}},$=function(i){return i};function R(i,r){if("number"==typeof i)return 3===r?{mode:"rgb",r:(i>>8&15|i>>4&240)/255,g:(i>>4&15|240&i)/255,b:(15&i|i<<4&240)/255}:4===r?{mode:"rgb",r:(i>>12&15|i>>8&240)/255,g:(i>>8&15|i>>4&240)/255,b:(i>>4&15|240&i)/255,alpha:(15&i|i<<4&240)/255}:6===r?{mode:"rgb",r:(i>>16&255)/255,g:(i>>8&255)/255,b:(255&i)/255}:8===r?{mode:"rgb",r:(i>>24&255)/255,g:(i>>16&255)/255,b:(i>>8&255)/255,alpha:(255&i)/255}:void 0}var O={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};var z=(/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/+"").replace(/^\/|\/$/g,""),C=z+"%",F="(?:"+z+"%|"+z+")",A="(?:"+z+"(deg|grad|rad|turn)|"+z+")",D="\\s*,\\s*",L="\\s+",N=new RegExp("^rgba?\\(\\s*"+z+D+z+D+z+"\\s*(?:,\\s*"+F+"\\s*)?\\)$"),S=new RegExp("^rgba?\\(\\s*"+C+D+C+D+C+"\\s*(?:,\\s*"+F+"\\s*)?\\)$"),H=new RegExp("^rgba?\\(\\s*"+z+L+z+L+z+"\\s*(?:\\/\\s*"+F+"\\s*)?\\)$"),B=new RegExp("^rgba?\\(\\s*"+C+L+C+L+C+"\\s*(?:\\/\\s*"+F+"\\s*)?\\)$"),G=new RegExp("^hsla?\\(\\s*"+A+D+C+D+C+"\\s*(?:,\\s*"+F+"\\s*)?\\)$"),J=new RegExp("^hsla?\\(\\s*"+A+L+C+L+C+"\\s*(?:\\/\\s*"+F+"\\s*)?\\)$"),K=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,Q=new RegExp("^hwb\\(\\s*"+A+L+C+L+C+"\\s*(?:\\/\\s*"+F+"\\s*)?\\)$"),T=new RegExp("^lab\\(\\s*"+z+L+z+L+z+"\\s*(?:\\/\\s*"+F+"\\s*)?\\)$"),U=new RegExp("^lch\\(\\s*"+z+L+z+L+A+"\\s*(?:\\/\\s*"+F+"\\s*)?\\)$"),V=new RegExp("^gray\\(\\s*"+z+"()()\\s*(?:\\/\\s*"+F+"\\s*)?\\)$");var W={mode:"rgb",channels:["r","g","b","alpha"],parsers:[function(i){var r;return(r=i.match(K))?R(parseInt(r[1],16),r[1].length):void 0},function(i){var r,o;if(r=i.match(N)||i.match(H))o={mode:"rgb",r:r[1]/255,g:r[2]/255,b:r[3]/255};else{if(!(r=i.match(S)||i.match(B)))return;o={mode:"rgb",r:r[1]/100,g:r[2]/100,b:r[3]/100}}return void 0!==r[4]?o.alpha=r[4]/100:void 0!==r[5]&&(o.alpha=+r[5]),o},function(i){return"string"==typeof i&&R(O[i.toLowerCase()],6)||void 0},function(i){return"transparent"===i?R(0,8):void 0}],interpolate:{r:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),g:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),b:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:g(function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}},X=function(i){return i<.04045?i/12.92:Math.pow((i+.055)/1.055,2.4)};function Y(i){var r=i.r,o=i.g,t=i.b,n=i.alpha,e={mode:"lrgb",r:X(r),g:X(o),b:X(t)};return void 0!==n&&(e.alpha=n),e}var Z=function(i){return i>.0031308?1.055*Math.pow(i,1/2.4)-.055:12.92*i};function _(i){var r=i.r,o=i.g,t=i.b,n=i.alpha,e={mode:"rgb",r:Z(r),g:Z(o),b:Z(t)};return void 0!==n&&(e.alpha=n),e}var ii={mode:"lrgb",output:{rgb:_},input:{rgb:Y},channels:["r","g","b","alpha"],interpolate:{r:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),g:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),b:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:g(function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};var ri=function(i,r){switch(r){case"deg":return+i;case"rad":return i/Math.PI*180;case"grad":return i/10*9;case"turn":return 360*i}};var oi={mode:"hsl",output:{rgb:function(i){var r=i.h,o=i.s,t=i.l,n=i.alpha;r=s(r);var e,a=t+o*(t<.5?t:1-t),d=a-2*(a-t)*Math.abs(r/60%2-1);switch(Math.floor(r/60)){case 0:e={r:a,g:d,b:2*t-a};break;case 1:e={r:d,g:a,b:2*t-a};break;case 2:e={r:2*t-a,g:a,b:d};break;case 3:e={r:2*t-a,g:d,b:a};break;case 4:e={r:d,g:2*t-a,b:a};break;case 5:e={r:a,g:2*t-a,b:d};break;default:e={r:2*t-a,g:2*t-a,b:2*t-a}}return e.mode="rgb",void 0!==n&&(e.alpha=n),e}},input:{rgb:function(i){var r=i.r,o=i.g,t=i.b,n=i.alpha,e=Math.max(r,o,t),a=Math.min(r,o,t),d={mode:"hsl",s:e===a?0:(e-a)/(1-Math.abs(e+a-1)),l:.5*(e+a)};return e-a!=0&&(d.h=60*(e===r?(o-t)/(e-a)+6*(o<t):e===o?(t-r)/(e-a)+2:(r-o)/(e-a)+4)),void 0!==n&&(d.alpha=n),d}},channels:["h","s","l","alpha"],parsers:[function(i){if("string"==typeof i){var r=i.match(G)||i.match(J);if(r){var o={mode:"hsl",h:void 0===r[3]?ri(r[1],r[2]):+r[3],s:Math.min(Math.max(0,r[4]/100),1),l:Math.min(Math.max(0,r[5]/100),1)};return void 0!==r[6]?o.alpha=r[6]/100:void 0!==r[7]&&(o.alpha=r[7]/255),o}}}],interpolate:{h:g(p()),s:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),l:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:g(function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};function ti(i){var r=i.h,o=i.s,t=i.v,n=i.alpha;r=s(r);var e,a=Math.abs(r/60%2-1);switch(Math.floor(r/60)){case 0:e={r:t,g:t*(1-o*a),b:t*(1-o)};break;case 1:e={r:t*(1-o*a),g:t,b:t*(1-o)};break;case 2:e={r:t*(1-o),g:t,b:t*(1-o*a)};break;case 3:e={r:t*(1-o),g:t*(1-o*a),b:t};break;case 4:e={r:t*(1-o*a),g:t*(1-o),b:t};break;case 5:e={r:t,g:t*(1-o),b:t*(1-o*a)};break;default:e={r:t*(1-o),g:t*(1-o),b:t*(1-o)}}return e.mode="rgb",void 0!==n&&(e.alpha=n),e}function ni(i){var r=i.r,o=i.g,t=i.b,n=i.alpha,e=Math.max(r,o,t),a=Math.min(r,o,t),d={mode:"hsv",s:0===e?0:1-a/e,v:e};return e-a!=0&&(d.h=60*(e===r?(o-t)/(e-a)+6*(o<t):e===o?(t-r)/(e-a)+2:(r-o)/(e-a)+4)),void 0!==n&&(d.alpha=n),d}var ei={mode:"hsv",output:{rgb:ti},input:{rgb:ni},channels:["h","s","v","alpha"],interpolate:{h:g(p()),s:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),v:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:g(function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};var ai={mode:"hsi",output:{rgb:function(i){var r=i.h,o=i.s,t=i.i,n=i.alpha;r=s(r);var e,a=Math.abs(r/60%2-1);switch(Math.floor(r/60)){case 0:e={r:t*(1+o*(3/(2-a)-1)),g:t*(1+o*(3*(1-a)/(2-a)-1)),b:t*(1-o)};break;case 1:e={r:t*(1+o*(3*(1-a)/(2-a)-1)),g:t*(1+o*(3/(2-a)-1)),b:t*(1-o)};break;case 2:e={r:t*(1-o),g:t*(1+o*(3/(2-a)-1)),b:t*(1+o*(3*(1-a)/(2-a)-1))};break;case 3:e={r:t*(1-o),g:t*(1+o*(3*(1-a)/(2-a)-1)),b:t*(1+o*(3/(2-a)-1))};break;case 4:e={r:t*(1+o*(3*(1-a)/(2-a)-1)),g:t*(1-o),b:t*(1+o*(3/(2-a)-1))};break;case 5:e={r:t*(1+o*(3/(2-a)-1)),g:t*(1-o),b:t*(1+o*(3*(1-a)/(2-a)-1))};break;default:e={r:t*(1-o),g:t*(1-o),b:t*(1-o)}}return e.mode="rgb",void 0!==n&&(e.alpha=n),e}},input:{rgb:function(i){var r=i.r,o=i.g,t=i.b,n=i.alpha,e=Math.max(r,o,t),a=Math.min(r,o,t),d={mode:"hsi",s:r+o+t===0?0:1-3*a/(r+o+t),i:(r+o+t)/3};return e-a!=0&&(d.h=60*(e===r?(o-t)/(e-a)+6*(o<t):e===o?(t-r)/(e-a)+2:(r-o)/(e-a)+4)),void 0!==n&&(d.alpha=n),d}},channels:["h","s","i","alpha"],interpolate:{h:g(p()),s:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),i:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:g(function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};var di={mode:"hwb",output:{rgb:function(i){var r=i.h,o=i.w,t=i.b,n=i.alpha;if(o+t>1){var e=o+t;o/=e,t/=e}return ti({h:r,s:1===t?1:1-o/(1-t),v:1-t,alpha:n})}},input:{rgb:function(i){var r=ni(i);if(void 0!==r){var o={mode:"hwb",w:(1-r.s)*r.v,b:1-r.v};return void 0!==r.h&&(o.h=r.h),void 0!==r.alpha&&(o.alpha=r.alpha),o}}},channels:["h","w","b","alpha"],parsers:[function(i){if("string"==typeof i){var r=i.match(Q);if(r){var o={mode:"hwb",h:void 0===r[3]?ri(r[1],r[2]):+r[3],w:r[4]/100,b:r[5]/100};if(o.w+o.b>1){var t=o.w+o.b;o.w/=t,o.b/=t}return void 0!==r[6]?o.alpha=r[6]/100:void 0!==r[7]&&(o.alpha=r[7]/255),o}}}],interpolate:{h:g(p()),w:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),b:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:g(function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}},vi=.96422,ui=1,hi=.82521,li=Math.pow(29,3)/Math.pow(3,3),fi=Math.pow(6,3)/Math.pow(29,3),ci=function(i){return Math.pow(i,3)>fi?Math.pow(i,3):(116*i-16)/li};function si(i){var r,o,t,n,e,a=function(i){var r=i.x,o=i.y,t=i.z;return _({r:3.1338561*r-1.6168667*o-.4906146*t,g:-.9787684*r+1.9161415*o+.033454*t,b:.0719453*r-.2289914*o+1.4052427*t})}((o=(r=i).l,t=r.a,e=(n=(o+16)/116)-r.b/200,{x:ci(t/500+n)*vi,y:ci(n)*ui,z:ci(e)*hi}));return a.mode="rgb",void 0!==i.alpha&&(a.alpha=i.alpha),a}var pi=function(i){return i>fi?Math.cbrt(i):(li*i+16)/116};function bi(i){var r,o,t,n,e,a,d=(r=function(i){var r=Y(i),o=r.r,t=r.g,n=r.b;return{x:.4360747*o+.3850649*t+.1430804*n,y:.2225045*o+.7168786*t+.0606169*n,z:.0139322*o+.0971045*t+.7141733*n}}(i),o=r.x,t=r.y,n=r.z,e=pi(o/vi),{mode:"lab",l:116*(a=pi(t/ui))-16,a:500*(e-a),b:200*(a-pi(n/hi))});return i.r===i.b===i.g&&(d.a=d.b=0),void 0!==i.alpha&&(d.alpha=i.alpha),d}var gi={mode:"lab",output:{rgb:si},input:{rgb:bi},channels:["l","a","b","alpha"],parsers:[function(i){if("string"==typeof i){var r,o;if(r=i.match(T))o={mode:"lab",l:+r[1],a:+r[2],b:+r[3]};else{if(!(r=i.match(V)))return;o={mode:"lab",l:+r[1],a:0,b:0}}return void 0!==r[4]?o.alpha=r[4]/100:void 0!==r[5]&&(o.alpha=+r[5]),o}}],interpolate:{l:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),a:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),b:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:g(function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};function Mi(i){var r=i.l,o=i.a,t=i.b,n=i.alpha,e=Math.sqrt(o*o+t*t),a={mode:"lch",l:r,c:e};return e&&(a.h=s(180*Math.atan2(t,o)/Math.PI)),void 0!==n&&(a.alpha=n),a}function mi(i){var r=i.l,o=i.c,t=i.h,n=i.alpha,e={mode:"lab",l:r,a:0===o?0:o*Math.cos(t/180*Math.PI),b:0===o?0:o*Math.sin(t/180*Math.PI)};return void 0!==n&&(e.alpha=n),e}var wi={mode:"lch",output:{lab:mi,rgb:function(i){return si(mi(i))}},input:{rgb:function(i){return Mi(bi(i))},lch:Mi},channels:["l","c","h","alpha"],parsers:[function(i){if("string"==typeof i){var r=i.match(U);if(r){var o={mode:"lch",l:+r[1],c:Math.max(0,+r[2]),h:void 0===r[5]?ri(r[3],r[4]):+r[5]};return void 0!==r[6]?o.alpha=r[6]/100:void 0!==r[7]&&(o.alpha=+r[7]),o}}}],interpolate:{h:g(p()),c:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),l:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:g(function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}},yi=[-.14861,1.78277,-.29227,-.90649,1.97294,0],ki=Math.PI/180,xi=180/Math.PI,Ii=yi[3]*yi[4],Pi=yi[1]*yi[4],qi=yi[1]*yi[2]-yi[0]*yi[3];var ji={mode:"cubehelix",channels:["h","s","l","alpha"],input:{rgb:function(i){var r=i.r,o=i.g,t=i.b,n=i.alpha,e=(qi*t+r*Ii-o*Pi)/(qi+Ii-Pi),a=t-e,d=(yi[4]*(o-e)-yi[2]*a)/yi[3],v={mode:"cubehelix",l:e,s:0===e||1===e?void 0:Math.sqrt(a*a+d*d)/(yi[4]*e*(1-e))};return v.s&&(v.h=Math.atan2(d,a)*xi-120),void 0!==n&&(v.alpha=n),v}},output:{rgb:function(i){var r=i.h,o=i.s,t=i.l,n=i.alpha,e={mode:"rgb"};r=(void 0===r?0:r+120)*ki;var a=void 0===o?0:o*t*(1-t),d=Math.cos(r),v=Math.sin(r);return e.r=t+a*(yi[0]*d+yi[1]*v),e.g=t+a*(yi[2]*d+yi[3]*v),e.b=t+a*(yi[4]*d+yi[5]*v),void 0!==n&&(e.alpha=n),e}},interpolate:{h:g(p()),s:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),l:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:g(function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};function Ei(i){var r=i.l,o=i.a,t=i.b,n=i.alpha,e=Math.sqrt(o*o+t*t),a={mode:"dlch",l:r,c:e};return e&&(a.h=s(180*Math.atan2(t,o)/Math.PI)),void 0!==n&&(a.alpha=n),a}var $i=1,Ri=1,Oi=26/180*Math.PI,zi=Math.cos(Oi),Ci=Math.sin(Oi),Fi=100/Math.log(1.39);function Ai(i){var r=i.l,o=i.c,t=i.h,n=i.alpha,e={mode:"lab",l:(Math.exp(r*$i/Fi)-1)/.0039};if(void 0===t)e.a=e.b=0;else{var a=(Math.exp(.0435*o*Ri*$i)-1)/.075,d=a*Math.cos(t/180*Math.PI-Oi),v=a*Math.sin(t/180*Math.PI-Oi);e.a=d*zi-v/.83*Ci,e.b=d*Ci+v/.83*zi}return void 0!==n&&(e.alpha=n),e}function Di(i){return Ai(Ei(i))}function Li(i){var r=i.l,o=i.a,t=i.b,n=i.alpha,e=o*zi+t*Ci,a=.83*(t*zi-o*Ci),d=Math.sqrt(e*e+a*a),v={mode:"dlch",l:Fi/$i*Math.log(1+.0039*r),c:Math.log(1+.075*d)/(.0435*Ri*$i)};return v.c&&(v.h=(Math.atan2(a,e)+Oi)/Math.PI*180),void 0!==n&&(v.alpha=n),v}function Ni(i){var r=i.l,o=i.c,t=i.h,n=i.alpha,e={mode:"dlab",l:r,a:0===o?0:o*Math.cos(t/180*Math.PI),b:0===o?0:o*Math.sin(t/180*Math.PI)};return void 0!==n&&(e.alpha=n),e}function Si(i){return Ni(Li(i))}var Hi={mode:"dlab",output:{lab:Di,rgb:function(i){return si(Di(i))}},input:{lab:Si,rgb:function(i){return Si(bi(i))}},channels:["l","a","b","alpha"],interpolate:{l:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),a:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),b:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),alpha:g(function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};var Bi={mode:"dlch",output:{lab:Ai,dlab:Ni,rgb:function(i){return si(Ai(i))}},input:{lab:Li,dlab:Ei,rgb:function(i){return Li(bi(i))}},channels:["l","c","h","alpha"],interpolate:{l:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),c:g(function(i){if(2===i.length){if(void 0===i[0]&&void 0===i[1])return;return void 0!==i[0]&&void 0!==i[1]?i:void 0===i[0]?i[1]:i[0]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i}),h:g(p()),alpha:g(function(i,r){if(2===i.length){if(void 0===i[0]&&void 0===i[1]||void 0===i[0]&&0===r||void 0===i[1]&&1===r)return;return[void 0===i[0]?1:i[0],void 0===i[1]?1:i[1]]}if(void 0!==i[0]||void 0!==i[1]||void 0!==i[2]||void 0!==i[3])return i.map(function(i){return void 0===i?1:i})})}};t(W),t(ii),t(oi),t(ei),t(ai),t(di),t(gi),t(wi),t(ji),t(Hi),t(Bi);var Gi=a("rgb"),Ji=a("lrgb"),Ki=a("hsl"),Qi=a("hsv"),Ti=a("hsi"),Ui=a("hwb"),Vi=a("lab"),Wi=a("lch"),Xi=a("cubehelix"),Yi=a("dlab"),Zi=a("dlch"),_i=Gi,ir=Object.freeze({hsl:Ki,hsv:Qi,hsi:Ti,hwb:Ui,rgb:Gi,lab:Vi,lch:Wi,lrgb:Ji,cubehelix:Xi,dlab:Yi,dlch:Zi,formatter:function(i){return void 0===i&&(i="rgb"),function(r){var o=h(r);if(void 0!==o){var t=u(o.r),n=u(o.g),e=u(o.b);return"hex"===i?"#"+(1<<24|t<<16|n<<8|e).toString(16).slice(1):"rgb"===i?void 0===r.alpha||1===r.alpha?"rgb("+t+", "+n+", "+e+")":"rgba("+t+", "+n+", "+e+", "+l(r.alpha)+")":void 0}}},converter:a,round:v,parse:e,interpolate:function(i,r,o){void 0===r&&(r="rgb");var t=function(i,r){void 0===r&&(r="rgb");for(var o=n(r).channels,t={mode:r},e=function(r){t[o[r]]=i.map(function(i){return i[o[r]]})},a=0;a<o.length;a++)e(a);return t}(i.map(a(r)),r);o=Object.assign({},n(r).interpolate,o);var e=Object.keys(o);return function(i){i=Math.min(Math.max(0,i),1);for(var n,a={mode:r},d=0;d<e.length;d++)void 0!==(n=o[e[d]](t[e[d]],i))&&(a[e[d]]=n);return a}},interpolateNumber:f,interpolateAlpha:c,interpolateHue:p,interpolateFunctionLinear:g,interpolateFunctionSpline:function(i,r,o){return void 0===i&&(i=b),void 0===r&&(r="bspline"),void 0===o&&(o=1),function(t,n){n=Math.pow(n,o);var e=t.length-1,a=1===n?e-1:Math.floor(n*e);"natural"===r&&(t=m(t));var d=t[a],v=t[a+1],u=a>0?t[a-1]:2*d-v,h=a<e-1?t[a+2]:2*v-d,l=i([u,d,v,h]);return"object"==typeof l?M(l[0],l[1],l[2],l[3],(n-a/e)*e):l}},interpolateFunctionCosine:function(i,r){return void 0===i&&(i=b),void 0===r&&(r=1),function(o,t){var n=(t=Math.pow(t,r))*(o.length-1),e=Math.floor(n),a=o[e],d=o[e+1],v=n-e,u=i([a,d],v);if("object"==typeof u){a=u[0],d=u[1];var h=(1-Math.cos(v*Math.PI))/2;return a*(1-h)+d*h}return u}},interpolateFunctionMonotone:function(i,r){return void 0===i&&(i=b),void 0===r&&(r=1),function(o,t){t=Math.pow(t,r);var n,e=o.length-1;1===t?(n=e-1,t=1):n=Math.floor(t*e);var a=o[n],d=o[n+1],v=n>0?o[n-1]:2*a-d,u=n<e-1?o[n+2]:2*d-a,h=i([v,a,d,u]);return"object"==typeof h?w(h[0],h[1],h[2],h[3],1/e,t-n/e):h}},samples:function(i,r){if(void 0===i&&(i=2),void 0===r&&(r=1),i<2)return i<1?[]:[Math.pow(.5,r)];for(var o=[],t=0;t<i;t++)o.push(Math.pow(t/(i-1),r));return o},differenceEuclidean:E,differenceCie76:function(){return E("lab")},differenceCie94:function(i,r,o){void 0===i&&(i=1),void 0===r&&(r=.045),void 0===o&&(o=.015);var t=a("lab");return function(n,e){var a=t(n),d=t(e),v=a.l,u=a.a,h=a.b,l=Math.sqrt(u*u+h*h),f=d.l,c=d.a,s=d.b,p=Math.sqrt(c*c+s*s),b=Math.pow(v-f,2),g=Math.pow(l-p,2),M=Math.pow(u-c,2)+Math.pow(h-s,2)-g;return Math.sqrt(b/Math.pow(i,2)+g/Math.pow(1+r*l,2)+M/Math.pow(1+o*l,2))}},differenceCiede2000:function(i,r,o){void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=1);var t=a("lab");return function(n,e){var a=t(n),d=t(e),v=a.l,u=a.a,h=a.b,l=Math.sqrt(u*u+h*h),f=d.l,c=d.a,s=d.b,p=(l+Math.sqrt(c*c+s*s))/2,b=.5*(1-Math.sqrt(Math.pow(p,7)/(Math.pow(p,7)+Math.pow(25,7)))),g=u*(1+b),M=c*(1+b),m=Math.sqrt(g*g+h*h),w=Math.sqrt(M*M+s*s),y=Math.abs(g)+Math.abs(h)===0?0:Math.atan2(h,g);y+=2*(y<0)*Math.PI;var k=Math.abs(M)+Math.abs(s)===0?0:Math.atan2(s,M);k+=2*(k<0)*Math.PI;var x=f-v,I=w-m,P=m*w==0?0:k-y;P-=2*(P>Math.PI)*Math.PI,P+=2*(P<-Math.PI)*Math.PI;var q,j=2*Math.sqrt(m*w)*Math.sin(P/2),E=(v+f)/2,$=(m+w)/2;m*w==0?q=y+k:(q=(y+k)/2,q-=(Math.abs(y-k)>Math.PI)*Math.PI,q+=2*(q<0)*Math.PI);var R=Math.pow(E-50,2),O=1-.17*Math.cos(q-Math.PI/6)+.24*Math.cos(2*q)+.32*Math.cos(3*q+Math.PI/30)-.2*Math.cos(4*q-63*Math.PI/180),z=1+.015*R/Math.sqrt(20+R),C=1+.045*$,F=1+.015*$*O,A=30*Math.PI/180*Math.exp(-1*Math.pow((180/Math.PI*q-275)/25,2)),D=2*Math.sqrt(Math.pow($,7)/(Math.pow($,7)+Math.pow(25,7))),L=-1*Math.sin(2*A)*D;return Math.sqrt(Math.pow(x/(i*z),2)+Math.pow(I/(r*C),2)+Math.pow(j/(o*F),2)+L*I/(r*C)*j/(o*F))}},differenceCmc:function(i,r){void 0===i&&(i=1),void 0===r&&(r=1);var o=a("lab");return function(t,n){var e=o(t),a=o(n),d=e.l,v=e.a,u=e.b,h=Math.sqrt(v*v+u*u),l=Math.atan2(u,v);l+=2*Math.PI*(l<0);var f=a.l,c=a.a,s=a.b,p=Math.sqrt(c*c+s*s),b=Math.pow(d-f,2),g=Math.pow(h-p,2),M=Math.pow(v-c,2)+Math.pow(u-s,2)-g,m=Math.sqrt(Math.pow(h,4)/(Math.pow(h,4)+1900)),w=l>=164/180*Math.PI&&l<=345/180*Math.PI?.56+Math.abs(.2*Math.cos(l+168/180*Math.PI)):.36+Math.abs(.4*Math.cos(l+35/180*Math.PI)),y=d<16?.511:.040975*d/(1+.01765*d),k=.0638*h/(1+.0131*h)+.638,x=k*(m*w+1-m);return Math.sqrt(b/Math.pow(i*y,2),g/Math.pow(r*k,2),M/Math.pow(x,2))}},differenceDin99o:function(){return E("dlab")},nearest:function(i,r,o){void 0===r&&(r=E()),void 0===o&&(o=$);var t=i.map(function(i,r){return{color:o(i),i:r}});return function(i,o,n){return void 0===o&&(o=1),void 0===n&&(n=1/0),isFinite(o)&&(o=Math.max(1,Math.min(o,t.length-1))),t.forEach(function(o){o.d=r(i,o.color)}),t.sort(function(i,r){return i.d-r.d}).slice(0,o).filter(function(i){return i.d<n}).map(function(i){return i.color})}},displayable:k,clamp:function(i){return void 0===i&&(i="rgb"),function(r){if(void 0===(r=P(r))||k(r))return r;var o=a(r.mode);if("rgb"===i)return o(j(r));r=x(r);var t=Object.assign({},r,{c:0});if(!k(t))return o(j(t));for(var n=0,e=r.c;e-n>.01;)t.c=n+.5*(e-n),k(t)?n=t.c:e=t.c;return o(t)}},defineMode:t,getModeDefinition:n,colorsNamed:O,default:_i});return Object.assign(_i,ir),_i}); |
1332
build/index.js
@@ -5,3 +5,3 @@ var converters = {}; | ||
var defineMode = function defineMode(definition) { | ||
var defineMode = function (definition) { | ||
converters[definition.mode] = Object.assign(converters[definition.mode] || {}, definition.output); | ||
@@ -15,17 +15,11 @@ Object.keys(definition.input || {}).forEach(function (k) { | ||
modes[definition.mode] = definition; | ||
(definition.parsers || []).forEach(function (parser) { | ||
return parsers.push(parser); | ||
}); | ||
(definition.parsers || []).forEach(function (parser) { return parsers.push(parser); }); | ||
}; | ||
var getModeDefinition = function getModeDefinition(mode) { | ||
return modes[mode]; | ||
}; | ||
var getModeDefinition = function (mode) { return modes[mode]; }; | ||
var parse = function parse(color) { | ||
var result = void 0, | ||
i = 0, | ||
len = parsers.length; | ||
var parse = function (color) { | ||
var result, i = 0, len = parsers.length; | ||
while (i < len) { | ||
if ((result = parsers[i++](color)) !== undefined) break; | ||
if ((result = parsers[i++](color)) !== undefined) { break; } | ||
} | ||
@@ -35,47 +29,31 @@ return result; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var prepare = function (color, mode) { return color === undefined ? | ||
undefined | ||
: typeof color !== 'object' ? | ||
parse(color) | ||
: color.mode === undefined ? | ||
Object.assign({}, color, {mode: mode}) | ||
: color; }; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
var converter = function (target_mode) { | ||
if ( target_mode === void 0 ) target_mode = 'rgb'; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var prepare = function prepare(color, mode) { | ||
return color === undefined ? undefined : (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color; | ||
}; | ||
var converter = function converter() { | ||
var target_mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'rgb'; | ||
return function (color) { | ||
return (color = prepare(color, target_mode)) !== undefined ? | ||
return function (color) { return (color = prepare(color, target_mode)) !== undefined ? | ||
// if the color's mode corresponds to our target mode | ||
color.mode === target_mode ? | ||
// then just return the color | ||
color | ||
// otherwise check to see if we have a dedicated | ||
// converter for the target mode | ||
: converters[color.mode][target_mode] ? | ||
// and return its result... | ||
converters[color.mode][target_mode](color) | ||
// ...otherwise pass through RGB as an intermediary step. | ||
// if the target mode is RGB... | ||
: target_mode === 'rgb' ? | ||
// just return the RGB | ||
converters[color.mode].rgb(color) | ||
// otherwise convert color.mode -> RGB -> target_mode | ||
: converters.rgb[target_mode](converters[color.mode].rgb(color)) : undefined; | ||
}; | ||
color.mode === target_mode ? | ||
// then just return the color | ||
color | ||
// otherwise check to see if we have a dedicated | ||
// converter for the target mode | ||
: converters[color.mode][target_mode] ? | ||
// and return its result... | ||
converters[color.mode][target_mode](color) | ||
// ...otherwise pass through RGB as an intermediary step. | ||
// if the target mode is RGB... | ||
: target_mode === 'rgb' ? | ||
// just return the RGB | ||
converters[color.mode].rgb(color) | ||
// otherwise convert color.mode -> RGB -> target_mode | ||
: converters.rgb[target_mode](converters[color.mode].rgb(color)) | ||
: undefined; }; | ||
}; | ||
@@ -85,24 +63,20 @@ | ||
var r = function r(value, precision) { | ||
return Math.round(value * (precision = Math.pow(10, precision))) / precision; | ||
}; | ||
var r = function (value, precision) { return Math.round(value * (precision = Math.pow(10, precision))) / precision; }; | ||
var round = (function () { | ||
var precision = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4; | ||
return function (value) { | ||
return typeof value === 'number' ? r(value, precision) : value; | ||
}; | ||
}); | ||
function round (precision) { | ||
if ( precision === void 0 ) precision = 4; | ||
var clamp = (function (value) { | ||
return Math.round(Math.max(0, Math.min(value, 1)) * 255); | ||
}); | ||
return function (value) { return typeof value === 'number' ? r(value, precision) : value; }; | ||
} | ||
var rgb = converter('rgb'), | ||
roundAlpha = round(2); | ||
function fixup (value) { return Math.round(Math.max(0, Math.min(value, 1)) * 255); } | ||
var formatter = (function () { | ||
var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'rgb'; | ||
return function (c) { | ||
var rgb = converter('rgb'); | ||
var roundAlpha = round(2); | ||
function formatter (format) { | ||
if ( format === void 0 ) format = 'rgb'; | ||
return function (c) { | ||
var color = rgb(c); | ||
@@ -114,5 +88,5 @@ | ||
var r = clamp(color.r); | ||
var b = clamp(color.b); | ||
var g = clamp(color.g); | ||
var r = fixup(color.r); | ||
var g = fixup(color.g); | ||
var b = fixup(color.b); | ||
@@ -126,15 +100,15 @@ if (format === 'hex') { | ||
// opaque color | ||
return 'rgb(' + r + ', ' + g + ', ' + b + ')'; | ||
return ("rgb(" + r + ", " + g + ", " + b + ")"); | ||
} else { | ||
// transparent color | ||
return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + roundAlpha(c.alpha) + ')'; | ||
return ("rgba(" + r + ", " + g + ", " + b + ", " + (roundAlpha(c.alpha)) + ")"); | ||
} | ||
} | ||
}; | ||
}); | ||
} | ||
var zip = (function (colors) { | ||
var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'rgb'; | ||
function zip (colors, mode) { | ||
if ( mode === void 0 ) mode = 'rgb'; | ||
var channels = getModeDefinition(mode).channels; | ||
@@ -144,18 +118,12 @@ var res = { | ||
}; | ||
var _loop = function _loop(i) { | ||
res[channels[i]] = colors.map(function (c) { | ||
return c[channels[i]]; | ||
}); | ||
var loop = function ( i ) { | ||
res[channels[i]] = colors.map(function (c) { return c[channels[i]]; }); | ||
}; | ||
for (var i = 0; i < channels.length; i++) { | ||
_loop(i); | ||
} | ||
for (var i = 0; i < channels.length; i++) loop( i ); | ||
return res; | ||
}); | ||
} | ||
var interpolate = (function (colors) { | ||
var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'rgb'; | ||
var interpolations = arguments[2]; | ||
function interpolate (colors, mode, interpolations) { | ||
if ( mode === void 0 ) mode = 'rgb'; | ||
@@ -168,4 +136,3 @@ var zipped = zip(colors.map(converter(mode)), mode); | ||
t = Math.min(Math.max(0, t), 1); | ||
var res = { mode: mode }, | ||
val = void 0; | ||
var res = { mode: mode }, val; | ||
for (var i = 0; i < keys.length; i++) { | ||
@@ -177,4 +144,4 @@ if ((val = interpolations[keys[i]](zipped[keys[i]], t)) !== undefined) { | ||
return res; | ||
}; | ||
}); | ||
} | ||
} | ||
@@ -193,9 +160,8 @@ /* | ||
var interpolateNumber = (function () { | ||
return function (values) { | ||
function interpolateNumber () { return function (values) { | ||
if (values.length === 2) { | ||
// Linear Number interpolation | ||
// --------------------------- | ||
// If both values are undefined, return undefined | ||
@@ -217,5 +183,10 @@ if (values[0] === undefined && values[1] === undefined) { | ||
// --------------------------- | ||
// If all values are undefined, return undefined | ||
if (values[0] === undefined && values[1] === undefined && values[2] === undefined && values[3] === undefined) { | ||
if ( | ||
values[0] === undefined && | ||
values[1] === undefined && | ||
values[2] === undefined && | ||
values[3] === undefined | ||
) { | ||
return undefined; | ||
@@ -239,4 +210,3 @@ } | ||
} | ||
}; | ||
}); | ||
}; } | ||
@@ -255,9 +225,9 @@ /* | ||
var interpolateAlpha = (function () { | ||
return function (values, t) { | ||
function interpolateAlpha () { return function (values, t) { | ||
if (values.length === 2) { | ||
// Linear Alpha interpolation | ||
// -------------------------- | ||
// If both alphas are undefined, | ||
@@ -267,7 +237,12 @@ // or if t is next to the undefined alpha, | ||
// about undefined alpha being 1. | ||
if (values[0] === undefined && values[1] === undefined || values[0] === undefined && t === 0 || values[1] === undefined && t === 1) return undefined; | ||
if ( | ||
(values[0] === undefined && values[1] === undefined) || | ||
(values[0] === undefined && t === 0) || | ||
(values[1] === undefined && t === 1) | ||
) { return undefined; } | ||
// If at least one alpha is defined, | ||
// assume alpha = 1 for any undefined values. | ||
return [values[0] === undefined ? 1 : values[0], values[1] === undefined ? 1 : values[1]]; | ||
return [ values[0] === undefined ? 1 : values[0], values[1] === undefined ? 1 : values[1]]; | ||
} else { | ||
@@ -279,3 +254,8 @@ | ||
// If all values are undefined, return undefined | ||
if (values[0] === undefined && values[1] === undefined && values[2] === undefined && values[3] === undefined) { | ||
if ( | ||
values[0] === undefined && | ||
values[1] === undefined && | ||
values[2] === undefined && | ||
values[3] === undefined | ||
) { | ||
return undefined; | ||
@@ -286,12 +266,7 @@ } | ||
// put alpha = 1 for any undefined values | ||
return values.map(function (v) { | ||
return v === undefined ? 1 : v; | ||
}); | ||
return values.map(function (v) { return v === undefined ? 1 : v; }); | ||
} | ||
}; | ||
}); | ||
}; } | ||
var normalizeHue = (function (hue) { | ||
return (hue = hue % 360) < 0 ? hue + 360 : hue; | ||
}); | ||
function normalizeHue (hue) { return (hue = hue % 360) < 0 ? hue + 360 : hue; } | ||
@@ -312,6 +287,7 @@ /* | ||
var interpolateHue = (function () { | ||
var shortPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
return function (values) { | ||
function interpolateHue (shortPath) { | ||
if ( shortPath === void 0 ) shortPath = true; | ||
return function (values) { | ||
if (values.length === 2) { | ||
@@ -326,3 +302,3 @@ | ||
} | ||
// if both hues are defined, interpolate between | ||
@@ -350,12 +326,15 @@ // the start hue and the end hue brought closest | ||
// ------------------------ | ||
// If all values are undefined, return undefined | ||
if (values[0] === undefined && values[1] === undefined && values[2] === undefined && values[3] === undefined) { | ||
if ( | ||
values[0] === undefined && | ||
values[1] === undefined && | ||
values[2] === undefined && | ||
values[3] === undefined | ||
) { | ||
return undefined; | ||
} | ||
if (shortPath) { | ||
return values.map(function (v) { | ||
return normalizeHue(v); | ||
}); | ||
return values.map(function (v) { return normalizeHue(v); }); | ||
} | ||
@@ -365,30 +344,31 @@ | ||
return values; | ||
} | ||
}; | ||
}); | ||
} | ||
// todo hue short vs. hue long | ||
// todo normalize hue before and after interpolateHue | ||
var identity = (function (d) { | ||
return d; | ||
}); | ||
function identity (d) { return d; } | ||
var interpolateFunctionLinear = (function () { | ||
var normalize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : identity; | ||
var γ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
return function (arr, t) { | ||
function interpolateFunctionLinear (normalize, γ) { | ||
if ( normalize === void 0 ) normalize = identity; | ||
if ( γ === void 0 ) γ = 1; | ||
return function (arr, t) { | ||
t = Math.pow(t, γ); | ||
var cls = t * (arr.length - 1), | ||
idx = Math.floor(cls), | ||
a = arr[idx], | ||
b = arr[idx + 1], | ||
t0 = cls - idx; | ||
var cls = t * (arr.length - 1), | ||
idx = Math.floor(cls), | ||
a = arr[idx], | ||
b = arr[idx + 1], | ||
t0 = cls - idx; | ||
var values = normalize([a, b], t0); | ||
return (typeof values === 'undefined' ? 'undefined' : _typeof(values)) === 'object' ? (a = values[0], b = values[1], a + t0 * (b - a)) : values; | ||
return typeof values === 'object' ? | ||
(a = values[0], b = values[1], a + t0 * (b - a)) : | ||
values; | ||
}; | ||
}); | ||
} | ||
@@ -421,10 +401,15 @@ /* | ||
var bspline = function bspline(Vim2, Vim1, Vi, Vip1, t) { | ||
var bspline = function (Vim2, Vim1, Vi, Vip1, t) { | ||
var t2 = t * t; | ||
var t3 = t2 * t; | ||
return ((1 - 3 * t + 3 * t2 - t3) * Vim2 + (4 - 6 * t2 + 3 * t3) * Vim1 + (1 + 3 * t + 3 * t2 - 3 * t3) * Vi + t3 * Vip1) / 6; | ||
return ( | ||
(1 - 3 * t + 3 * t2 - t3) * Vim2 + | ||
(4 - 6 * t2 + 3 * t3) * Vim1 + | ||
(1 + 3 * t + 3 * t2 - 3 * t3) * Vi + | ||
t3 * Vip1 | ||
) / 6; | ||
}; | ||
var solve = function solve(v) { | ||
var i; | ||
var solve = function (v) { | ||
var i; | ||
var n = v.length - 1; | ||
@@ -434,29 +419,30 @@ var c = new Array(n); | ||
var sol = new Array(n); | ||
c[1] = 1 / 4, _v[1] = (6 * v[1] - v[0]) / 4; | ||
c[1] = 1/4, _v[1] = (6 * v[1] - v[0])/4; | ||
for (i = 2; i < n; ++i) { | ||
c[i] = 1 / (4 - c[i - 1]); | ||
_v[i] = (6 * v[i] - (i == n - 1 ? v[n] : 0) - _v[i - 1]) * c[i]; | ||
c[i] = 1 / (4 - c[i-1]); | ||
_v[i] = (6 * v[i] - (i == n-1 ? v[n] : 0) - _v[i-1]) * c[i]; | ||
} | ||
sol[0] = v[0]; | ||
sol[n] = v[n]; | ||
if (n - 1 > 0) { | ||
sol[n - 1] = _v[n - 1]; | ||
sol[n-1] = _v[n-1]; | ||
} | ||
for (i = n - 2; i > 0; --i) { | ||
sol[i] = _v[i] - c[i] * sol[i + 1]; | ||
for (i = n-2; i > 0; --i) { | ||
sol[i] = _v[i] - c[i] * sol[i+1]; | ||
} | ||
return sol; | ||
}; | ||
var interpolateFunctionSpline = (function () { | ||
var normalize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : identity; | ||
var method = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'bspline'; | ||
var γ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; | ||
return function (arr, t) { | ||
function interpolateFunctionSpline (normalize, method, γ) { | ||
if ( normalize === void 0 ) normalize = identity; | ||
if ( method === void 0 ) method = 'bspline'; | ||
if ( γ === void 0 ) γ = 1; | ||
return function (arr, t) { | ||
t = Math.pow(t, γ); | ||
@@ -472,12 +458,14 @@ | ||
var Vim1 = arr[i]; | ||
var Vi = arr[i + 1]; | ||
var Vi = arr[i+1]; | ||
var Vim2 = i > 0 ? arr[i - 1] : 2 * Vim1 - Vi; | ||
var Vip1 = i < classes - 1 ? arr[i + 2] : 2 * Vi - Vim1; | ||
var Vim2 = i > 0 ? arr[i-1] : 2 * Vim1 - Vi; | ||
var Vip1 = i < classes - 1 ? arr[i+2] : 2 * Vi - Vim1; | ||
var v = normalize([Vim2, Vim1, Vi, Vip1]); | ||
return (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object' ? bspline(v[0], v[1], v[2], v[3], (t - i / classes) * classes) : v; | ||
return typeof v === 'object' ? | ||
bspline(v[0], v[1], v[2], v[3], (t - i / classes) * classes) | ||
: v; | ||
}; | ||
}); | ||
} | ||
@@ -489,28 +477,29 @@ /* | ||
var interpolateFunctionCosine = (function () { | ||
var normalize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : identity; | ||
var γ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
return function (arr, t) { | ||
function interpolateFunctionCosine (normalize, γ) { | ||
if ( normalize === void 0 ) normalize = identity; | ||
if ( γ === void 0 ) γ = 1; | ||
return function (arr, t) { | ||
t = Math.pow(t, γ); | ||
var cls = t * (arr.length - 1), | ||
idx = Math.floor(cls), | ||
a = arr[idx], | ||
b = arr[idx + 1], | ||
t0 = cls - idx; | ||
var cls = t * (arr.length - 1), | ||
idx = Math.floor(cls), | ||
a = arr[idx], | ||
b = arr[idx + 1], | ||
t0 = cls - idx; | ||
var values = normalize([a, b], t0); | ||
if ((typeof values === 'undefined' ? 'undefined' : _typeof(values)) === 'object') { | ||
if (typeof values === 'object') { | ||
a = values[0]; | ||
b = values[1]; | ||
var c = (1 - Math.cos(t0 * Math.PI)) / 2; | ||
return a * (1 - c) + b * c; | ||
return (a * (1 - c) + b * c); | ||
} else { | ||
return values; | ||
} | ||
} | ||
}; | ||
}); | ||
} | ||
var monotone = function monotone(v0, v1, v2, v3, h, t) { | ||
var monotone = function (v0, v1, v2, v3, h, t) { | ||
@@ -525,10 +514,16 @@ var h2 = h * h; | ||
return (s20 + s31 - 2 * s21) / h2 * t3 + (3 * s21 - 2 * s20 - s31) / h * t2 + s20 * t + v1; | ||
return ( | ||
(s20 + s31 - 2 * s21) / h2 * t3 + | ||
(3 * s21 - 2 * s20 - s31) / h * t2 + | ||
s20 * t + | ||
v1 | ||
); | ||
}; | ||
var interpolateFunctionMonotone = (function () { | ||
var normalize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : identity; | ||
var γ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
return function (arr, t) { | ||
function interpolateFunctionMonotone (normalize, γ) { | ||
if ( normalize === void 0 ) normalize = identity; | ||
if ( γ === void 0 ) γ = 1; | ||
return function (arr, t) { | ||
t = Math.pow(t, γ); | ||
@@ -538,3 +533,3 @@ | ||
var i = void 0; | ||
var i; | ||
if (t === 1) { | ||
@@ -554,9 +549,10 @@ i = n - 1; | ||
return (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object' ? monotone(v[0], v[1], v[2], v[3], 1 / n, t - i / n) : v; | ||
return typeof v === 'object' ? | ||
monotone(v[0], v[1], v[2], v[3], 1 / n, t - i / n) : v; | ||
}; | ||
}); | ||
} | ||
var samples = (function () { | ||
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2; | ||
var γ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
function samples (n, γ) { | ||
if ( n === void 0 ) n = 2; | ||
if ( γ === void 0 ) γ = 1; | ||
@@ -571,7 +567,84 @@ if (n < 2) { | ||
return res; | ||
}); | ||
} | ||
var differenceEuclidean = function differenceEuclidean() { | ||
var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'rgb'; | ||
var rgb$1 = converter('rgb'); | ||
function displayable (color) { | ||
var c = rgb$1(color); | ||
return ( | ||
c !== undefined && | ||
c.r >= 0 && c.r <= 1 && | ||
c.g >= 0 && c.g <= 1 && | ||
c.b >= 0 && c.b <= 1 | ||
); | ||
} | ||
var lch = converter('lch'); | ||
var rgb$2 = converter('rgb'); | ||
var prepare$1 = function (color) { return color === undefined ? | ||
undefined | ||
: typeof color !== 'object' ? | ||
parse(color) | ||
: color.mode === undefined ? | ||
undefined | ||
: color; }; | ||
var clamp_value = function (v) { return Math.max(0, Math.min(v, 1)); }; | ||
var clamp_rgb = function (color) { | ||
var c = rgb$2(color); | ||
c.r = clamp_value(c.r); | ||
c.g = clamp_value(c.g); | ||
c.b = clamp_value(c.b); | ||
return c; | ||
}; | ||
function clamp (method) { | ||
if ( method === void 0 ) method = 'rgb'; | ||
return function (color) { | ||
color = prepare$1(color); | ||
// if the color is undefined or displayable, return it directly | ||
if (color === undefined || displayable(color)) { return color; } | ||
// keep track of color's original mode | ||
var conv = converter(color.mode); | ||
if (method === 'rgb') { | ||
return conv(clamp_rgb(color)); | ||
} | ||
// convert to LCh for clamping | ||
color = lch(color); | ||
// try with chroma = 0 | ||
var clamped = Object.assign({}, color, {c: 0}); | ||
// if not even chroma = 0 is displayable | ||
// fall back to RGB clamping | ||
if (!displayable(clamped)) { | ||
return conv(clamp_rgb(clamped)); | ||
} | ||
// By this time we know chroma = 0 is displayable and our current chroma is not. | ||
// Find the displayable chroma through the bisection method. | ||
var start = 0, end = color.c, delta = 0.01; | ||
while (end - start > delta) { | ||
clamped.c = start + (end - start) * 0.5; | ||
if (displayable(clamped)) { | ||
start = clamped.c; | ||
} else { | ||
end = clamped.c; | ||
} | ||
} | ||
return conv(clamped); | ||
}; | ||
} | ||
var differenceEuclidean = function (mode) { | ||
if ( mode === void 0 ) mode = 'rgb'; | ||
var channels = getModeDefinition(mode).channels; | ||
@@ -582,22 +655,20 @@ var conv = converter(mode); | ||
var ConvSmp = conv(smp); | ||
return Math.sqrt(channels.reduce(function (delta, k) { | ||
return ( | ||
// ignore alpha channel in computing the euclidean distance | ||
delta + (k === 'alpha' ? 0 : Math.pow(ConvStd[k] - ConvSmp[k], 2)) | ||
); | ||
}, 0)); | ||
}; | ||
return Math.sqrt( | ||
channels.reduce( | ||
function (delta, k) { return delta + (k === 'alpha' ? 0 : Math.pow(ConvStd[k] - ConvSmp[k], 2)); }, | ||
0 | ||
) | ||
); | ||
} | ||
}; | ||
var differenceCie76 = function differenceCie76() { | ||
return differenceEuclidean('lab'); | ||
}; | ||
var differenceCie76 = function () { return differenceEuclidean('lab'); }; | ||
var differenceCie94 = function differenceCie94() { | ||
var kL = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var K1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.045; | ||
var K2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.015; | ||
var differenceCie94 = function (kL, K1, K2) { | ||
if ( kL === void 0 ) kL = 1; | ||
if ( K1 === void 0 ) K1 = 0.045; | ||
if ( K2 === void 0 ) K2 = 0.015; | ||
var lab = converter('lab'); | ||
return function (std, smp) { | ||
@@ -623,4 +694,8 @@ | ||
return Math.sqrt(dL2 / Math.pow(kL, 2) + dC2 / Math.pow(1 + K1 * cStd, 2) + dH2 / Math.pow(1 + K2 * cStd, 2)); | ||
}; | ||
return Math.sqrt( | ||
dL2 / Math.pow(kL, 2) + | ||
dC2 / Math.pow(1 + K1 * cStd, 2) + | ||
dH2 / Math.pow(1 + K2 * cStd, 2) | ||
); | ||
} | ||
}; | ||
@@ -635,6 +710,6 @@ | ||
var differenceCiede2000 = function differenceCiede2000() { | ||
var Kl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var Kc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
var Kh = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; | ||
var differenceCiede2000 = function (Kl, Kc, Kh) { | ||
if ( Kl === void 0 ) Kl = 1; | ||
if ( Kc === void 0 ) Kc = 1; | ||
if ( Kh === void 0 ) Kh = 1; | ||
@@ -657,3 +732,3 @@ var lab = converter('lab'); | ||
var cAvg = (cStd + cSmp) / 2; | ||
var G = 0.5 * (1 - Math.sqrt(Math.pow(cAvg, 7) / (Math.pow(cAvg, 7) + Math.pow(25, 7)))); | ||
@@ -663,18 +738,18 @@ | ||
var apSmp = aSmp * (1 + G); | ||
var cpStd = Math.sqrt(apStd * apStd + bStd * bStd); | ||
var cpSmp = Math.sqrt(apSmp * apSmp + bSmp * bSmp); | ||
var hpStd = Math.abs(apStd) + Math.abs(bStd) === 0 ? 0 : Math.atan2(bStd, apStd); | ||
hpStd += (hpStd < 0) * 2 * Math.PI; | ||
hpStd += (hpStd < 0) * 2 * Math.PI; | ||
var hpSmp = Math.abs(apSmp) + Math.abs(bSmp) === 0 ? 0 : Math.atan2(bSmp, apSmp); | ||
hpSmp += (hpSmp < 0) * 2 * Math.PI; | ||
hpSmp += (hpSmp < 0) * 2 * Math.PI; | ||
var dL = lSmp - lStd; | ||
var dC = cpSmp - cpStd; | ||
var dhp = cpStd * cpSmp === 0 ? 0 : hpSmp - hpStd; | ||
dhp -= (dhp > Math.PI) * 2 * Math.PI; | ||
dhp += (dhp < -Math.PI) * 2 * Math.PI; | ||
dhp -= (dhp > Math.PI) * 2 * Math.PI; | ||
dhp += (dhp < -Math.PI) * 2 * Math.PI; | ||
@@ -686,3 +761,3 @@ var dH = 2 * Math.sqrt(cpStd * cpSmp) * Math.sin(dhp / 2); | ||
var hp = void 0; | ||
var hp; | ||
if (cpStd * cpSmp === 0) { | ||
@@ -697,20 +772,31 @@ hp = hpStd + hpSmp; | ||
var Lpm50 = Math.pow(Lp - 50, 2); | ||
var T = 1 - 0.17 * Math.cos(hp - Math.PI / 6) + 0.24 * Math.cos(2 * hp) + 0.32 * Math.cos(3 * hp + Math.PI / 30) - 0.20 * Math.cos(4 * hp - 63 * Math.PI / 180); | ||
var Sl = 1 + 0.015 * Lpm50 / Math.sqrt(20 + Lpm50); | ||
var T = 1 - | ||
0.17 * Math.cos(hp - Math.PI / 6) + | ||
0.24 * Math.cos(2 * hp) + | ||
0.32 * Math.cos(3 * hp + Math.PI / 30) - | ||
0.20 * Math.cos(4 * hp - 63 * Math.PI / 180); | ||
var Sl = 1 + (0.015 * Lpm50) / Math.sqrt(20 + Lpm50); | ||
var Sc = 1 + 0.045 * Cp; | ||
var Sh = 1 + 0.015 * Cp * T; | ||
var deltaTheta = 30 * Math.PI / 180 * Math.exp(-1 * Math.pow((180 / Math.PI * hp - 275)/25, 2)); | ||
var Rc = 2 * Math.sqrt( | ||
Math.pow(Cp, 7) / (Math.pow(Cp, 7) + Math.pow(25, 7)) | ||
); | ||
var deltaTheta = 30 * Math.PI / 180 * Math.exp(-1 * Math.pow((180 / Math.PI * hp - 275) / 25, 2)); | ||
var Rc = 2 * Math.sqrt(Math.pow(Cp, 7) / (Math.pow(Cp, 7) + Math.pow(25, 7))); | ||
var Rt = -1 * Math.sin(2 * deltaTheta) * Rc; | ||
return Math.sqrt(Math.pow(dL / (Kl * Sl), 2) + Math.pow(dC / (Kc * Sc), 2) + Math.pow(dH / (Kh * Sh), 2) + Rt * dC / (Kc * Sc) * dH / (Kh * Sh)); | ||
}; | ||
return Math.sqrt( | ||
Math.pow(dL / (Kl * Sl), 2) + | ||
Math.pow(dC / (Kc * Sc), 2) + | ||
Math.pow(dH / (Kh * Sh), 2) + | ||
Rt * dC / (Kc * Sc) * dH / (Kh * Sh) | ||
); | ||
} | ||
}; | ||
var differenceCmc = function differenceCmc() { | ||
var l = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
var c = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
var differenceCmc = function (l, c) { | ||
if ( l === void 0 ) l = 1; | ||
if ( c === void 0 ) c = 1; | ||
@@ -728,3 +814,3 @@ var lab = converter('lab'); | ||
var hStd = Math.atan2(bStd, aStd); | ||
hStd = hStd + 2 * Math.PI * (hStd < 0); | ||
hStd = hStd + 2 * Math.PI * (hStd < 0); | ||
@@ -741,12 +827,21 @@ var lSmp = LabSmp.l; | ||
var F = Math.sqrt(Math.pow(cStd, 4) / (Math.pow(cStd, 4) + 1900)); | ||
var T = hStd >= 164 / 180 * Math.PI && hStd <= 345 / 180 * Math.PI ? 0.56 + Math.abs(0.2 * Math.cos(hStd + 168 / 180 * Math.PI)) : 0.36 + Math.abs(0.4 * Math.cos(hStd + 35 / 180 * Math.PI)); | ||
var T = hStd >= (164 / 180 * Math.PI) && | ||
hStd <= (345 / 180 * Math.PI) ? | ||
0.56 + Math.abs(0.2 * Math.cos(hStd + 168 / 180 * Math.PI)) | ||
: 0.36 + Math.abs(0.4 * Math.cos(hStd + 35 / 180 * Math.PI)); | ||
var Sl = lStd < 16 ? 0.511 : 0.040975 * lStd / (1 + 0.01765 * lStd); | ||
var Sl = lStd < 16 ? 0.511 : ((0.040975 * lStd) / (1 + 0.01765 * lStd)); | ||
var Sc = 0.0638 * cStd / (1 + 0.0131 * cStd) + 0.638; | ||
var Sh = Sc * (F * T + 1 - F); | ||
return Math.sqrt(dL2 / Math.pow(l * Sl, 2), dC2 / Math.pow(c * Sc, 2), dH2 / Math.pow(Sh, 2)); | ||
return Math.sqrt( | ||
dL2 / Math.pow(l * Sl, 2), | ||
dC2 / Math.pow(c * Sc, 2), | ||
dH2 / Math.pow(Sh, 2) | ||
); | ||
}; | ||
}; | ||
var differenceDin99o = function () { return differenceEuclidean('dlab'); }; | ||
// selects the vantage point | ||
@@ -764,3 +859,3 @@ // currently does so randomly, but this could be optimized | ||
// const vptree = (colors, metric) => { | ||
// let color = select(colors); | ||
@@ -792,18 +887,14 @@ // let dist = median(color, colors, metric); | ||
// | ||
var identity$1 = function identity(d) { | ||
return d; | ||
}; | ||
var identity$1 = function (d) { return d; }; | ||
var nearest = (function (colors) { | ||
var metric = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : differenceEuclidean(); | ||
var accesor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : identity$1; | ||
function nearest (colors, metric, accesor) { | ||
if ( metric === void 0 ) metric = differenceEuclidean(); | ||
if ( accesor === void 0 ) accesor = identity$1; | ||
var arr = colors.map(function (c, idx) { | ||
return { color: accesor(c), i: idx }; | ||
}); | ||
return function (color) { | ||
var n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
var τ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity; | ||
var arr = colors.map(function (c, idx) { return ({ color: accesor(c), i: idx }); }); | ||
return function (color, n, τ) { | ||
if ( n === void 0 ) n = 1; | ||
if ( τ === void 0 ) τ = Infinity; | ||
if (isFinite(n)) { | ||
@@ -817,16 +908,10 @@ n = Math.max(1, Math.min(n, arr.length - 1)); | ||
return arr.sort(function (a, b) { | ||
return a.d - b.d; | ||
}).slice(0, n).filter(function (c) { | ||
return c.d < τ; | ||
}).map(function (c) { | ||
return c.color; | ||
}); | ||
}; | ||
}); | ||
return arr.sort(function (a, b) { return a.d - b.d; }).slice(0, n).filter(function (c) { return c.d < τ; }).map(function (c) { return c.color; }); | ||
} | ||
} | ||
var parseNumber = (function (color, len) { | ||
function parseNumber (color, len) { | ||
if (typeof color !== 'number') { return; } | ||
if (typeof color !== 'number') return; | ||
// hex3: #c93 -> #cc9933 | ||
@@ -836,5 +921,5 @@ if (len === 3) { | ||
mode: 'rgb', | ||
r: (color >> 8 & 0xF | color >> 4 & 0xF0) / 255, | ||
g: (color >> 4 & 0xF | color & 0xF0) / 255, | ||
b: (color & 0xF | color << 4 & 0xF0) / 255 | ||
r: ((color >> 8 & 0xF) | (color >> 4 & 0xF0)) / 255, | ||
g: ((color >> 4 & 0xF) | (color & 0xF0)) / 255, | ||
b: ((color & 0xF) | (color << 4 & 0xF0)) / 255 | ||
}; | ||
@@ -847,9 +932,9 @@ } | ||
mode: 'rgb', | ||
r: (color >> 12 & 0xF | color >> 8 & 0xF0) / 255, | ||
g: (color >> 8 & 0xF | color >> 4 & 0xF0) / 255, | ||
b: (color >> 4 & 0xF | color & 0xF0) / 255, | ||
alpha: (color & 0xF | color << 4 & 0xF0) / 255 | ||
r: ((color >> 12 & 0xF) | (color >> 8 & 0xF0)) / 255, | ||
g: ((color >> 8 & 0xF) | (color >> 4 & 0xF0)) / 255, | ||
b: ((color >> 4 & 0xF) | (color & 0xF0)) / 255, | ||
alpha: ((color & 0xF) | (color << 4 & 0xF0)) / 255 | ||
}; | ||
} | ||
// hex6: #f0f1f2 | ||
@@ -859,4 +944,4 @@ if (len === 6) { | ||
mode: 'rgb', | ||
r: (color >> 16 & 0xFF) / 255, | ||
g: (color >> 8 & 0xFF) / 255, | ||
r: (color >> 16 & 0xFF) / 255, | ||
g: (color >> 8 & 0xFF) / 255, | ||
b: (color & 0xFF) / 255 | ||
@@ -870,9 +955,9 @@ }; | ||
mode: 'rgb', | ||
r: (color >> 24 & 0xFF) / 255, | ||
g: (color >> 16 & 0xFF) / 255, | ||
b: (color >> 8 & 0xFF) / 255, | ||
r: (color >> 24 & 0xFF) / 255, | ||
g: (color >> 16 & 0xFF) / 255, | ||
b: (color >> 8 & 0xFF) / 255, | ||
alpha: (color & 0xFF) / 255 | ||
}; | ||
} | ||
}); | ||
} | ||
@@ -1000,3 +1085,3 @@ var named = { | ||
// Added in CSS Colors Level 4: https://drafts.csswg.org/css-color/#changes-from-3 | ||
rebeccapurple: 0x663399, | ||
rebeccapurple: 0x663399, | ||
red: 0xff0000, | ||
@@ -1034,5 +1119,5 @@ rosybrown: 0xbc8f8f, | ||
// https://drafts.csswg.org/css-color/#transparent-black | ||
var parseNamed = (function (color) { | ||
return typeof color === 'string' && parseNumber(named[color.toLowerCase()], 6) || undefined; | ||
}); | ||
function parseNamed (color) { | ||
return (typeof color === 'string' && parseNumber(named[color.toLowerCase()], 6)) || undefined; | ||
} | ||
@@ -1048,7 +1133,7 @@ /* | ||
var num = (/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/ + '').replace(/^\/|\/$/g, ''); // number | ||
var per = num + '%'; // percentage | ||
var alpha = '(?:' + num + '%|' + num + ')'; // alpha-value | ||
var hue = '(?:' + num + '(deg|grad|rad|turn)|' + num + ')'; // hue | ||
var c = '\\s*,\\s*'; // comma | ||
var s = '\\s+'; // space | ||
var per = num + "%"; // percentage | ||
var alpha = "(?:" + num + "%|" + num + ")"; // alpha-value | ||
var hue = "(?:" + num + "(deg|grad|rad|turn)|" + num + ")"; // hue | ||
var c = "\\s*,\\s*"; // comma | ||
var s = "\\s+"; // space | ||
@@ -1060,6 +1145,6 @@ | ||
*/ | ||
var rgb_num_old = new RegExp('^rgba?\\(\\s*' + num + c + num + c + num + '\\s*(?:,\\s*' + alpha + '\\s*)?\\)$'); | ||
var rgb_per_old = new RegExp('^rgba?\\(\\s*' + per + c + per + c + per + '\\s*(?:,\\s*' + alpha + '\\s*)?\\)$'); | ||
var rgb_num_new = new RegExp('^rgba?\\(\\s*' + num + s + num + s + num + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var rgb_per_new = new RegExp('^rgba?\\(\\s*' + per + s + per + s + per + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var rgb_num_old = new RegExp(("^rgba?\\(\\s*" + num + c + num + c + num + "\\s*(?:,\\s*" + alpha + "\\s*)?\\)$")); | ||
var rgb_per_old = new RegExp(("^rgba?\\(\\s*" + per + c + per + c + per + "\\s*(?:,\\s*" + alpha + "\\s*)?\\)$")); | ||
var rgb_num_new = new RegExp(("^rgba?\\(\\s*" + num + s + num + s + num + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
var rgb_per_new = new RegExp(("^rgba?\\(\\s*" + per + s + per + s + per + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
@@ -1070,4 +1155,4 @@ /* | ||
*/ | ||
var hsl_old = new RegExp('^hsla?\\(\\s*' + hue + c + per + c + per + '\\s*(?:,\\s*' + alpha + '\\s*)?\\)$'); | ||
var hsl_new = new RegExp('^hsla?\\(\\s*' + hue + s + per + s + per + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var hsl_old = new RegExp(("^hsla?\\(\\s*" + hue + c + per + c + per + "\\s*(?:,\\s*" + alpha + "\\s*)?\\)$")); | ||
var hsl_new = new RegExp(("^hsla?\\(\\s*" + hue + s + per + s + per + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
@@ -1083,3 +1168,3 @@ /* | ||
*/ | ||
var hwb = new RegExp('^hwb\\(\\s*' + hue + s + per + s + per + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var hwb = new RegExp(("^hwb\\(\\s*" + hue + s + per + s + per + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
@@ -1090,4 +1175,4 @@ /* | ||
*/ | ||
var lab = new RegExp('^lab\\(\\s*' + num + s + num + s + num + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var lch = new RegExp('^lch\\(\\s*' + num + s + num + s + hue + '\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var lab = new RegExp(("^lab\\(\\s*" + num + s + num + s + num + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
var lch$1 = new RegExp(("^lch\\(\\s*" + num + s + num + s + hue + "\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
@@ -1098,27 +1183,26 @@ /* | ||
*/ | ||
var gray = new RegExp('^gray\\(\\s*' + num + '()()\\s*(?:\\/\\s*' + alpha + '\\s*)?\\)$'); | ||
var gray = new RegExp(("^gray\\(\\s*" + num + "()()\\s*(?:\\/\\s*" + alpha + "\\s*)?\\)$")); | ||
var parseHex = (function (color) { | ||
function parseHex (color) { | ||
var match; | ||
return (match = color.match(hex)) ? parseNumber(parseInt(match[1], 16), match[1].length) : undefined; | ||
}); | ||
} | ||
var parseRgb = (function (color) { | ||
function parseRgb (color) { | ||
var match, res; | ||
var match = void 0, | ||
res = void 0; | ||
if (match = color.match(rgb_num_old) || color.match(rgb_num_new)) { | ||
res = { | ||
res = { | ||
mode: 'rgb', | ||
r: match[1] / 255, | ||
g: match[2] / 255, | ||
b: match[3] / 255 | ||
r: match[1] / 255, | ||
g: match[2] / 255, | ||
b: match[3] / 255 | ||
}; | ||
} else if (match = color.match(rgb_per_old) || color.match(rgb_per_new)) { | ||
res = { | ||
res = { | ||
mode: 'rgb', | ||
r: match[1] / 100, | ||
g: match[2] / 100, | ||
b: match[3] / 100 | ||
r: match[1] / 100, | ||
g: match[2] / 100, | ||
b: match[3] / 100 | ||
}; | ||
@@ -1134,9 +1218,7 @@ } else { | ||
} | ||
return res; | ||
}); | ||
} | ||
var parseTransparent = (function (c) { | ||
return c === 'transparent' ? parseNumber(0x00000000, 8) : undefined; | ||
}); | ||
function parseTransparent (c) { return c === 'transparent' ? parseNumber(0x00000000, 8) : undefined; } | ||
@@ -1146,3 +1228,3 @@ var rgbDef = { | ||
channels: ['r', 'g', 'b', 'alpha'], | ||
parsers: [parseHex, parseRgb, parseNamed, parseTransparent], | ||
parsers: [ parseHex, parseRgb, parseNamed, parseTransparent ], | ||
interpolate: { | ||
@@ -1156,11 +1238,9 @@ r: interpolateFunctionLinear(interpolateNumber()), | ||
var fn = function fn(c) { | ||
return c < 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); | ||
}; | ||
var fn = function (c) { return c < 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); }; | ||
var convertRgbToLrgb = (function (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertRgbToLrgb (ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -1173,15 +1253,13 @@ var res = { | ||
}; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var fn$1 = function fn(c) { | ||
return c > 0.0031308 ? 1.055 * Math.pow(c, 1 / 2.4) - 0.055 : 12.92 * c; | ||
}; | ||
var fn$1 = function (c) { return c > 0.0031308 ? 1.055 * Math.pow(c, 1/2.4) - 0.055 : 12.92 * c; }; | ||
var convertLrgbToRgb = (function (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertLrgbToRgb (ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -1194,5 +1272,5 @@ var res = { | ||
}; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
@@ -1204,3 +1282,3 @@ var lrgbDef = { | ||
}, | ||
input: { | ||
input: { | ||
rgb: convertRgbToLrgb | ||
@@ -1219,30 +1297,23 @@ }, | ||
function convertHslToRgb (_ref) { | ||
var h = _ref.h, | ||
s = _ref.s, | ||
l = _ref.l, | ||
alpha = _ref.alpha; | ||
function convertHslToRgb(ref) { | ||
var h = ref.h; | ||
var s = ref.s; | ||
var l = ref.l; | ||
var alpha = ref.alpha; | ||
h = normalizeHue(h); | ||
var m1 = l + s * (l < 0.5 ? l : 1 - l); | ||
var m2 = m1 - (m1 - l) * 2 * Math.abs(h / 60 % 2 - 1); | ||
var res = void 0; | ||
switch (Math.floor(h / 60)) { | ||
case 0: | ||
res = { r: m1, g: m2, b: 2 * l - m1 };break; | ||
case 1: | ||
res = { r: m2, g: m1, b: 2 * l - m1 };break; | ||
case 2: | ||
res = { r: 2 * l - m1, g: m1, b: m2 };break; | ||
case 3: | ||
res = { r: 2 * l - m1, g: m2, b: m1 };break; | ||
case 4: | ||
res = { r: m2, g: 2 * l - m1, b: m1 };break; | ||
case 5: | ||
res = { r: m1, g: 2 * l - m1, b: m2 };break; | ||
default: | ||
res = { r: 2 * l - m1, g: 2 * l - m1, b: 2 * l - m1 }; | ||
var m2 = m1 - (m1 - l) * 2 * Math.abs(h/60 % 2 - 1); | ||
var res; | ||
switch (Math.floor(h/60)) { | ||
case 0: res = { r: m1, g: m2, b: 2 * l - m1 }; break; | ||
case 1: res = { r: m2, g: m1, b: 2 * l - m1 }; break; | ||
case 2: res = { r: 2 * l - m1, g: m1, b: m2 }; break; | ||
case 3: res = { r: 2 * l - m1, g: m2, b: m1 }; break; | ||
case 4: res = { r: m2, g: 2 * l - m1, b: m1 }; break; | ||
case 5: res = { r: m1, g: 2 * l - m1, b: m2 }; break; | ||
default: res = { r: 2 * l - m1, g: 2 * l - m1, b: 2 * l - m1 }; | ||
} | ||
res.mode = 'rgb'; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
@@ -1253,10 +1324,9 @@ } | ||
function convertRgbToHsl (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertRgbToHsl(ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
var M = Math.max(r, g, b), | ||
m = Math.min(r, g, b); | ||
var M = Math.max(r, g, b), m = Math.min(r, g, b); | ||
var res = { | ||
@@ -1267,24 +1337,20 @@ mode: 'hsl', | ||
}; | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (M - m !== 0) { res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
} | ||
var hue$1 = function hue(val, unit) { | ||
var hue$1 = function (val, unit) { | ||
switch (unit) { | ||
case 'deg': | ||
return +val; | ||
case 'rad': | ||
return val / Math.PI * 180; | ||
case 'grad': | ||
return val / 10 * 9; | ||
case 'turn': | ||
return val * 360; | ||
case 'deg': return +val; | ||
case 'rad': return val / Math.PI * 180; | ||
case 'grad': return val / 10 * 9; | ||
case 'turn': return val * 360; | ||
} | ||
}; | ||
var parseHsl = (function (color) { | ||
if (typeof color !== 'string') return; | ||
function parseHsl (color) { | ||
if (typeof color !== 'string') { return; } | ||
var match = color.match(hsl_old) || color.match(hsl_new); | ||
if (!match) return; | ||
if (!match) { return; } | ||
var res = { | ||
@@ -1302,8 +1368,8 @@ mode: 'hsl', | ||
return res; | ||
}); | ||
} | ||
var hslDef = { | ||
mode: 'hsl', | ||
output: { | ||
rgb: convertHslToRgb | ||
output: { | ||
rgb: convertHslToRgb | ||
}, | ||
@@ -1314,3 +1380,3 @@ input: { | ||
channels: ['h', 's', 'l', 'alpha'], | ||
parsers: [parseHsl], | ||
parsers: [ parseHsl ], | ||
interpolate: { | ||
@@ -1326,29 +1392,22 @@ h: interpolateFunctionLinear(interpolateHue()), | ||
function convertHsvToRgb (_ref) { | ||
var h = _ref.h, | ||
s = _ref.s, | ||
v = _ref.v, | ||
alpha = _ref.alpha; | ||
function convertHsvToRgb(ref) { | ||
var h = ref.h; | ||
var s = ref.s; | ||
var v = ref.v; | ||
var alpha = ref.alpha; | ||
h = normalizeHue(h); | ||
var f = Math.abs(h / 60 % 2 - 1); | ||
var res = void 0; | ||
switch (Math.floor(h / 60)) { | ||
case 0: | ||
res = { r: v, g: v * (1 - s * f), b: v * (1 - s) };break; | ||
case 1: | ||
res = { r: v * (1 - s * f), g: v, b: v * (1 - s) };break; | ||
case 2: | ||
res = { r: v * (1 - s), g: v, b: v * (1 - s * f) };break; | ||
case 3: | ||
res = { r: v * (1 - s), g: v * (1 - s * f), b: v };break; | ||
case 4: | ||
res = { r: v * (1 - s * f), g: v * (1 - s), b: v };break; | ||
case 5: | ||
res = { r: v, g: v * (1 - s), b: v * (1 - s * f) };break; | ||
default: | ||
res = { r: v * (1 - s), g: v * (1 - s), b: v * (1 - s) }; | ||
var f = Math.abs(h/60 % 2 - 1); | ||
var res; | ||
switch (Math.floor(h/60)) { | ||
case 0: res = { r: v, g: v * (1 - s * f), b: v * (1 - s) }; break; | ||
case 1: res = { r: v * (1 - s * f), g: v, b: v * (1 - s) }; break; | ||
case 2: res = { r: v * (1 - s), g: v, b: v * (1 - s * f) }; break; | ||
case 3: res = { r: v * (1 - s), g: v * (1 - s * f), b: v }; break; | ||
case 4: res = { r: v * (1 - s * f), g: v * (1 - s), b: v }; break; | ||
case 5: res = { r: v, g: v * (1 - s), b: v * (1 - s * f) }; break; | ||
default: res = { r: v * (1 - s), g: v * (1 - s), b: v * (1 - s) }; | ||
} | ||
res.mode = 'rgb'; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
@@ -1359,10 +1418,9 @@ } | ||
function convertRgbToHsv (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertRgbToHsv(ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
var M = Math.max(r, g, b), | ||
m = Math.min(r, g, b); | ||
var M = Math.max(r, g, b), m = Math.min(r, g, b); | ||
var res = { | ||
@@ -1373,4 +1431,4 @@ mode: 'hsv', | ||
}; | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (M - m !== 0) { res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
@@ -1381,4 +1439,4 @@ } | ||
mode: 'hsv', | ||
output: { | ||
rgb: convertHsvToRgb | ||
output: { | ||
rgb: convertHsvToRgb | ||
}, | ||
@@ -1399,51 +1457,51 @@ input: { | ||
function convertHsiToRgb (_ref) { | ||
var h = _ref.h, | ||
s = _ref.s, | ||
i = _ref.i, | ||
alpha = _ref.alpha; | ||
function convertHsiToRgb (ref) { | ||
var h = ref.h; | ||
var s = ref.s; | ||
var i = ref.i; | ||
var alpha = ref.alpha; | ||
h = normalizeHue(h); | ||
var f = Math.abs(h / 60 % 2 - 1); | ||
var res = void 0; | ||
switch (Math.floor(h / 60)) { | ||
case 0: | ||
var f = Math.abs(h/60 % 2 - 1); | ||
var res; | ||
switch (Math.floor(h/60)) { | ||
case 0: | ||
res = { | ||
r: i * (1 + s * (3 / (2 - f) - 1)), | ||
g: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
r: i * (1 + s * (3 / (2 - f) - 1)), | ||
g: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
b: i * (1 - s) | ||
}; | ||
break; | ||
case 1: | ||
case 1: | ||
res = { | ||
r: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
g: i * (1 + s * (3 / (2 - f) - 1)), | ||
r: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
g: i * (1 + s * (3 / (2 - f) - 1)), | ||
b: i * (1 - s) | ||
}; | ||
break; | ||
case 2: | ||
case 2: | ||
res = { | ||
r: i * (1 - s), | ||
g: i * (1 + s * (3 / (2 - f) - 1)), | ||
r: i * (1 - s), | ||
g: i * (1 + s * (3 / (2 - f) - 1)), | ||
b: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)) | ||
}; | ||
break; | ||
case 3: | ||
case 3: | ||
res = { | ||
r: i * (1 - s), | ||
g: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
r: i * (1 - s), | ||
g: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
b: i * (1 + s * (3 / (2 - f) - 1)) | ||
}; | ||
break; | ||
case 4: | ||
case 4: | ||
res = { | ||
r: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
g: i * (1 - s), | ||
r: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)), | ||
g: i * (1 - s), | ||
b: i * (1 + s * (3 / (2 - f) - 1)) | ||
}; | ||
break; | ||
case 5: | ||
case 5: | ||
res = { | ||
r: i * (1 + s * (3 / (2 - f) - 1)), | ||
g: i * (1 - s), | ||
r: i * (1 + s * (3 / (2 - f) - 1)), | ||
g: i * (1 - s), | ||
b: i * (1 + s * (3 * (1 - f) / (2 - f) - 1)) | ||
@@ -1457,3 +1515,3 @@ }; | ||
res.mode = 'rgb'; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
@@ -1464,10 +1522,9 @@ } | ||
function convertRgbToHsi (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertRgbToHsi(ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
var M = Math.max(r, g, b), | ||
m = Math.min(r, g, b); | ||
var M = Math.max(r, g, b), m = Math.min(r, g, b); | ||
var res = { | ||
@@ -1478,4 +1535,4 @@ mode: 'hsi', | ||
}; | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (M - m !== 0) { res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
@@ -1486,4 +1543,4 @@ } | ||
mode: 'hsi', | ||
output: { | ||
rgb: convertHsiToRgb | ||
output: { | ||
rgb: convertHsiToRgb | ||
}, | ||
@@ -1500,3 +1557,3 @@ input: { | ||
} | ||
}; | ||
} | ||
@@ -1513,7 +1570,7 @@ /* | ||
function convertHwbToRgb (_ref) { | ||
var h = _ref.h, | ||
w = _ref.w, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertHwbToRgb (ref) { | ||
var h = ref.h; | ||
var w = ref.w; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -1523,11 +1580,11 @@ // normalize w + b to 1 | ||
var s = w + b; | ||
w /= s; | ||
w /= s; | ||
b /= s; | ||
} | ||
return convertHsvToRgb({ | ||
h: h, | ||
s: b === 1 ? 1 : 1 - w / (1 - b), | ||
return convertHsvToRgb({ | ||
h: h, | ||
s: b === 1 ? 1 : 1 - w / (1 - b), | ||
v: 1 - b, | ||
alpha: alpha | ||
}); | ||
}); | ||
} | ||
@@ -1547,3 +1604,3 @@ | ||
var hsv = convertRgbToHsv(rgba); | ||
if (hsv === undefined) return undefined; | ||
if (hsv === undefined) { return undefined; } | ||
var res = { | ||
@@ -1554,11 +1611,11 @@ mode: 'hwb', | ||
}; | ||
if (hsv.h !== undefined) res.h = hsv.h; | ||
if (hsv.alpha !== undefined) res.alpha = hsv.alpha; | ||
if (hsv.h !== undefined) { res.h = hsv.h; } | ||
if (hsv.alpha !== undefined) { res.alpha = hsv.alpha; } | ||
return res; | ||
} | ||
var parseHwb = (function (color) { | ||
if (typeof color !== 'string') return undefined; | ||
function parseHwb (color) { | ||
if (typeof color !== 'string') { return undefined; } | ||
var match = color.match(hwb); | ||
if (!match) return undefined; | ||
if (!match) { return undefined; } | ||
var res = { | ||
@@ -1570,7 +1627,7 @@ mode: 'hwb', | ||
}; | ||
// normalize w + b to at most 1 | ||
if (res.w + res.b > 1) { | ||
var s = res.w + res.b; | ||
res.w /= s; | ||
res.w /= s; | ||
res.b /= s; | ||
@@ -1585,8 +1642,8 @@ } | ||
return res; | ||
}); | ||
} | ||
var hwbDef = { | ||
mode: 'hwb', | ||
output: { | ||
rgb: convertHwbToRgb | ||
output: { | ||
rgb: convertHwbToRgb | ||
}, | ||
@@ -1597,3 +1654,3 @@ input: { | ||
channels: ['h', 'w', 'b', 'alpha'], | ||
parsers: [parseHwb], | ||
parsers: [ parseHwb ], | ||
interpolate: { | ||
@@ -1616,19 +1673,17 @@ h: interpolateFunctionLinear(interpolateHue()), | ||
var Zn = 0.82521; | ||
var k = Math.pow(29, 3) / Math.pow(3, 3); | ||
var e = Math.pow(6, 3) / Math.pow(29, 3); | ||
var fn$2 = function fn(v) { | ||
return Math.pow(v, 3) > e ? Math.pow(v, 3) : (116 * v - 16) / k; | ||
}; | ||
var fn$2 = function (v) { return Math.pow(v, 3) > e ? Math.pow(v, 3) : (116 * v - 16) / k; }; | ||
var convertLabToXyz = (function (_ref) { | ||
var l = _ref.l, | ||
a = _ref.a, | ||
b = _ref.b; | ||
function convertLabToXyz (ref) { | ||
var l = ref.l; | ||
var a = ref.a; | ||
var b = ref.b; | ||
var fy = (l + 16) / 116; | ||
var fx = a / 500 + fy; | ||
var fz = fy - b / 200; | ||
var fx = a / 500 + fy; | ||
var fz = fy - b / 200; | ||
@@ -1640,3 +1695,3 @@ return { | ||
}; | ||
}); | ||
} | ||
@@ -1651,19 +1706,20 @@ /* | ||
var convertXyzToRgb = (function (_ref) { | ||
var x = _ref.x, | ||
y = _ref.y, | ||
z = _ref.z; | ||
function convertXyzToRgb (ref) { | ||
var x = ref.x; | ||
var y = ref.y; | ||
var z = ref.z; | ||
return convertLrgbToRgb({ | ||
r: x * 3.1338561 - y * 1.6168667 - 0.4906146 * z, | ||
g: x * -0.9787684 + y * 1.9161415 + 0.0334540 * z, | ||
b: x * 0.0719453 - y * 0.2289914 + 1.4052427 * z | ||
}); | ||
r: x * 3.1338561 - y * 1.6168667 - 0.4906146 * z, | ||
g: x * -0.9787684 + y * 1.9161415 + 0.0334540 * z, | ||
b: x * 0.0719453 - y * 0.2289914 + 1.4052427 * z | ||
}); | ||
} | ||
var convertLabToRgb = (function (lab) { | ||
function convertLabToRgb (lab) { | ||
var res = convertXyzToRgb(convertLabToXyz(lab)); | ||
res.mode = 'rgb'; | ||
if (lab.alpha !== undefined) res.alpha = lab.alpha; | ||
if (lab.alpha !== undefined) { res.alpha = lab.alpha; } | ||
return res; | ||
}); | ||
} | ||
@@ -1679,8 +1735,7 @@ /* | ||
var convertRgbToXyz = (function (rgb) { | ||
var _convertRgbToLrgb = convertRgbToLrgb(rgb), | ||
r = _convertRgbToLrgb.r, | ||
g = _convertRgbToLrgb.g, | ||
b = _convertRgbToLrgb.b; | ||
function convertRgbToXyz (rgb) { | ||
var ref = convertRgbToLrgb(rgb); | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
return { | ||
@@ -1691,29 +1746,27 @@ x: 0.4360747 * r + 0.3850649 * g + 0.1430804 * b, | ||
}; | ||
}); | ||
} | ||
var f = function f(value) { | ||
return value > e ? Math.cbrt(value) : (k * value + 16) / 116; | ||
}; | ||
var f = function (value) { return value > e ? Math.cbrt(value) : (k * value + 16) / 116; }; | ||
var convertXyzToLab = (function (_ref) { | ||
var x = _ref.x, | ||
y = _ref.y, | ||
z = _ref.z; | ||
function convertXyzToLab (ref) { | ||
var x = ref.x; | ||
var y = ref.y; | ||
var z = ref.z; | ||
var f0 = f(x / Xn); | ||
var f1 = f(y / Yn); | ||
var f2 = f(z / Zn); | ||
var f0 = f(x/Xn); | ||
var f1 = f(y/Yn); | ||
var f2 = f(z/Zn); | ||
return { | ||
mode: 'lab', | ||
l: 116 * f1 - 16, | ||
l: (116 * f1) - 16, | ||
a: 500 * (f0 - f1), | ||
b: 200 * (f1 - f2) | ||
}; | ||
}); | ||
} | ||
var convertRgbToLab = (function (rgb) { | ||
function convertRgbToLab (rgb) { | ||
var res = convertXyzToLab(convertRgbToXyz(rgb)); | ||
// Fixes achromatic RGB colors having a _slight_ chroma due to floating-point errors | ||
@@ -1725,11 +1778,10 @@ // and approximated computations in sRGB <-> CIELab. | ||
} | ||
if (rgb.alpha !== undefined) res.alpha = rgb.alpha; | ||
if (rgb.alpha !== undefined) { res.alpha = rgb.alpha; } | ||
return res; | ||
}); | ||
} | ||
var parseLab = (function (color) { | ||
if (typeof color !== 'string') return undefined; | ||
function parseLab (color) { | ||
if (typeof color !== 'string') { return undefined; } | ||
var match = void 0, | ||
res = void 0; | ||
var match, res; | ||
@@ -1761,8 +1813,8 @@ if (match = color.match(lab)) { | ||
return res; | ||
}); | ||
} | ||
var labDef = { | ||
mode: 'lab', | ||
output: { | ||
rgb: convertLabToRgb | ||
output: { | ||
rgb: convertLabToRgb | ||
}, | ||
@@ -1773,3 +1825,3 @@ input: { | ||
channels: ['l', 'a', 'b', 'alpha'], | ||
parsers: [parseLab], | ||
parsers: [ parseLab ], | ||
interpolate: { | ||
@@ -1788,7 +1840,7 @@ l: interpolateFunctionLinear(interpolateNumber()), | ||
*/ | ||
var convertLabToLch = (function (_ref) { | ||
var l = _ref.l, | ||
a = _ref.a, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertLabToLch (ref) { | ||
var l = ref.l; | ||
var a = ref.a; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -1801,6 +1853,6 @@ var c = Math.sqrt(a * a + b * b); | ||
}; | ||
if (c) res.h = normalizeHue(Math.atan2(b, a) * 180 / Math.PI); | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (c) { res.h = normalizeHue(Math.atan2(b, a) * 180 / Math.PI); } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
@@ -1812,7 +1864,7 @@ /* | ||
*/ | ||
var convertLchToLab = (function (_ref) { | ||
var l = _ref.l, | ||
c = _ref.c, | ||
h = _ref.h, | ||
alpha = _ref.alpha; | ||
function convertLchToLab (ref) { | ||
var l = ref.l; | ||
var c = ref.c; | ||
var h = ref.h; | ||
var alpha = ref.alpha; | ||
@@ -1822,23 +1874,19 @@ var res = { | ||
l: l, | ||
a: c === 0 ? 0 : c * Math.cos(h / 180 * Math.PI), | ||
b: c === 0 ? 0 : c * Math.sin(h / 180 * Math.PI) | ||
a: c === 0 ? 0 : c * Math.cos( h / 180 * Math.PI ), | ||
b: c === 0 ? 0 : c * Math.sin( h / 180 * Math.PI ) | ||
}; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var convertLchToRgb = (function (c) { | ||
return convertLabToRgb(convertLchToLab(c)); | ||
}); | ||
function convertLchToRgb (c) { return convertLabToRgb(convertLchToLab(c)); } | ||
var convertRgbToLch = (function (c) { | ||
return convertLabToLch(convertRgbToLab(c)); | ||
}); | ||
function convertRgbToLch (c) { return convertLabToLch(convertRgbToLab(c)); } | ||
var parseLch = (function (color) { | ||
function parseLch (color) { | ||
if (typeof color !== 'string') return undefined; | ||
var match = color.match(lch); | ||
if (typeof color !== 'string') { return undefined; } | ||
var match = color.match(lch$1); | ||
if (!match) { | ||
@@ -1860,5 +1908,5 @@ return undefined; | ||
} | ||
return res; | ||
}); | ||
} | ||
@@ -1871,3 +1919,3 @@ var lchDef = { | ||
}, | ||
input: { | ||
input: { | ||
rgb: convertRgbToLch, | ||
@@ -1877,3 +1925,3 @@ lch: convertLabToLch | ||
channels: ['l', 'c', 'h', 'alpha'], | ||
parsers: [parseLch], | ||
parsers: [ parseLch ], | ||
interpolate: { | ||
@@ -1887,3 +1935,7 @@ h: interpolateFunctionLinear(interpolateHue()), | ||
var M = [-0.14861, 1.78277, -0.29227, -0.90649, 1.97294, 0]; | ||
var M = [ | ||
-0.14861, 1.78277, | ||
-0.29227, -0.90649, | ||
1.97294, 0 | ||
]; | ||
@@ -1910,7 +1962,7 @@ var degToRad = Math.PI / 180; | ||
var convertRgbToCubehelix = (function (_ref) { | ||
var r = _ref.r, | ||
g = _ref.g, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertRgbToCubehelix (ref) { | ||
var r = ref.r; | ||
var g = ref.g; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -1922,19 +1974,19 @@ | ||
var res = { | ||
var res = { | ||
mode: 'cubehelix', | ||
l: l, | ||
s: l === 0 || l === 1 ? undefined : Math.sqrt(x * x + y * y) / (M[4] * l * (1 - l)) | ||
s: (l === 0 || l === 1) ? undefined : Math.sqrt(x * x + y * y) / (M[4] * l * (1 - l)) | ||
}; | ||
if (res.s) res.h = Math.atan2(y, x) * radToDeg - 120; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (res.s) { res.h = Math.atan2(y, x) * radToDeg - 120; } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var convertCubehelixToRgb = (function (_ref) { | ||
var h = _ref.h, | ||
s = _ref.s, | ||
l = _ref.l, | ||
alpha = _ref.alpha; | ||
function convertCubehelixToRgb (ref) { | ||
var h = ref.h; | ||
var s = ref.s; | ||
var l = ref.l; | ||
var alpha = ref.alpha; | ||
@@ -1944,3 +1996,3 @@ var res = { mode: 'rgb' }; | ||
h = (h === undefined ? 0 : h + 120) * degToRad; | ||
var amp = s === undefined ? 0 : s * l * (1 - l); | ||
@@ -1955,5 +2007,5 @@ | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
@@ -2010,7 +2062,7 @@ /* | ||
var convertDlabToDlch = (function (_ref) { | ||
var l = _ref.l, | ||
a = _ref.a, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertDlabToDlch (ref) { | ||
var l = ref.l; | ||
var a = ref.a; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -2023,6 +2075,6 @@ var c = Math.sqrt(a * a + b * b); | ||
}; | ||
if (c) res.h = normalizeHue(Math.atan2(b, a) * 180 / Math.PI); | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (c) { res.h = normalizeHue(Math.atan2(b, a) * 180 / Math.PI); } | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
@@ -2034,3 +2086,3 @@ var kE = 1; | ||
var sinθ = Math.sin(θ); | ||
var factor = 100 / Math.log(139 / 100); // ~ 303.67 | ||
var factor = 100/Math.log(139/100); // ~ 303.67 | ||
@@ -2042,7 +2094,7 @@ /* | ||
var convertDlchToLab = (function (_ref) { | ||
var l = _ref.l, | ||
c = _ref.c, | ||
h = _ref.h, | ||
alpha = _ref.alpha; | ||
function convertDlchToLab (ref) { | ||
var l = ref.l; | ||
var c = ref.c; | ||
var h = ref.h; | ||
var alpha = ref.alpha; | ||
@@ -2061,16 +2113,12 @@ | ||
var f = G * Math.sin(h / 180 * Math.PI - θ); | ||
res.a = e * cosθ - f / 0.83 * sinθ; | ||
res.b = e * sinθ + f / 0.83 * cosθ; | ||
res.a = e * cosθ - (f / 0.83) * sinθ; | ||
res.b = e * sinθ + (f / 0.83) * cosθ; | ||
} | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var convertDlabToLab = (function (c) { | ||
return convertDlchToLab(convertDlabToDlch(c)); | ||
}); | ||
function convertDlabToLab (c) { return convertDlchToLab(convertDlabToDlch(c)); } | ||
var convertDlabToRgb = (function (c) { | ||
return convertLabToRgb(convertDlabToLab(c)); | ||
}); | ||
function convertDlabToRgb (c) { return convertLabToRgb(convertDlabToLab(c)); } | ||
@@ -2081,7 +2129,7 @@ /* | ||
var convertLabToDlch = (function (_ref) { | ||
var l = _ref.l, | ||
a = _ref.a, | ||
b = _ref.b, | ||
alpha = _ref.alpha; | ||
function convertLabToDlch (ref) { | ||
var l = ref.l; | ||
var a = ref.a; | ||
var b = ref.b; | ||
var alpha = ref.alpha; | ||
@@ -2101,11 +2149,11 @@ var e = a * cosθ + b * sinθ; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var convertDlchToDlab = (function (_ref) { | ||
var l = _ref.l, | ||
c = _ref.c, | ||
h = _ref.h, | ||
alpha = _ref.alpha; | ||
function convertDlchToDlab (ref) { | ||
var l = ref.l; | ||
var c = ref.c; | ||
var h = ref.h; | ||
var alpha = ref.alpha; | ||
@@ -2118,17 +2166,13 @@ var res = { | ||
}; | ||
if (alpha !== undefined) res.alpha = alpha; | ||
if (alpha !== undefined) { res.alpha = alpha; } | ||
return res; | ||
}); | ||
} | ||
var convertLabToDlab = (function (c) { | ||
return convertDlchToDlab(convertLabToDlch(c)); | ||
}); | ||
function convertLabToDlab (c) { return convertDlchToDlab(convertLabToDlch(c)); } | ||
var convertRgbToDlab = (function (c) { | ||
return convertLabToDlab(convertRgbToLab(c)); | ||
}); | ||
function convertRgbToDlab (c) { return convertLabToDlab(convertRgbToLab(c)); } | ||
var dlabDef = { | ||
mode: 'dlab', | ||
output: { | ||
output: { | ||
lab: convertDlabToLab, | ||
@@ -2150,13 +2194,9 @@ rgb: convertDlabToRgb | ||
var convertDlchToRgb = (function (c) { | ||
return convertLabToRgb(convertDlchToLab(c)); | ||
}); | ||
function convertDlchToRgb (c) { return convertLabToRgb(convertDlchToLab(c)); } | ||
var convertRgbToDlch = (function (c) { | ||
return convertLabToDlch(convertRgbToLab(c)); | ||
}); | ||
function convertRgbToDlch (c) { return convertLabToDlch(convertRgbToLab(c)); } | ||
var dlchDef = { | ||
mode: 'dlch', | ||
output: { | ||
output: { | ||
lab: convertDlchToLab, | ||
@@ -2192,3 +2232,3 @@ dlab: convertDlchToDlab, | ||
var rgb$1 = converter('rgb'); | ||
var rgb$3 = converter('rgb'); | ||
var lrgb = converter('lrgb'); | ||
@@ -2200,3 +2240,3 @@ var hsl = converter('hsl'); | ||
var lab$1 = converter('lab'); | ||
var lch$1 = converter('lch'); | ||
var lch$2 = converter('lch'); | ||
var cubehelix = converter('cubehelix'); | ||
@@ -2206,5 +2246,5 @@ var dlab = converter('dlab'); | ||
var culori = rgb$1; | ||
var culori = rgb$3; | ||
export default culori; | ||
export { hsl, hsv, hsi, hwb$1 as hwb, rgb$1 as rgb, lab$1 as lab, lch$1 as lch, lrgb, cubehelix, dlab, dlch, formatter, converter, round, parse, interpolate, interpolateNumber, interpolateAlpha, interpolateHue, interpolateFunctionLinear, interpolateFunctionSpline, interpolateFunctionCosine, interpolateFunctionMonotone, samples, differenceEuclidean, differenceCie76, differenceCie94, differenceCiede2000, differenceCmc, nearest, defineMode, getModeDefinition, named as colorsNamed }; | ||
export { hsl, hsv, hsi, hwb$1 as hwb, rgb$3 as rgb, lab$1 as lab, lch$2 as lch, lrgb, cubehelix, dlab, dlch, formatter, converter, round, parse, interpolate, interpolateNumber, interpolateAlpha, interpolateHue, interpolateFunctionLinear, interpolateFunctionSpline, interpolateFunctionCosine, interpolateFunctionMonotone, samples, differenceEuclidean, differenceCie76, differenceCie94, differenceCiede2000, differenceCmc, differenceDin99o, nearest, displayable, clamp, defineMode, getModeDefinition, named as colorsNamed }; |
{ | ||
"name": "culori", | ||
"version": "0.3.73", | ||
"version": "0.4.0", | ||
"main": "build/culori.js", | ||
@@ -14,9 +14,5 @@ "module": "build/index.js", | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-es2015-rollup": "^3.0.0", | ||
"mathjs": "^4.0.1", | ||
"nyc": "^11.6.0", | ||
"rollup": "^0.57.1", | ||
"rollup-plugin-babel": "^3.0.3", | ||
"rollup-plugin-buble": "^0.19.2", | ||
"rollup-plugin-uglify": "^3.0.0", | ||
@@ -23,0 +19,0 @@ "tap-spec": "^4.1.1", |
331
README.md
@@ -0,41 +1,330 @@ | ||
# Culori | ||
<figure style='text-align: center'> | ||
<img src='./.github/man-rainbow.jpg' width='400'/> | ||
<figcaption style='font-size: 0.8em'>“Man before a rainbow” (ca. 1700) — <a href='https://www.rijksmuseum.nl/en/collection/RP-P-1896-A-19368-1803'>Rijksmuseum</a>, via <a href='https://publicdomainreview.org'>The Public Domain Review</a>.</figcaption> | ||
<img src='https://github.com/danburzo/culori/.github/man-rainbow.jpg' width='400'/> | ||
<figcaption style='font-size: 0.8em'>“Man before a rainbow” (ca. 1700) — <a href='https://www.rijksmuseum.nl/en/collection/RP-P-1896-A-19368-1803'>Rijksmuseum</a>, via <a href='https://publicdomainreview.org'>The Public Domain Review</a>.</figcaption> | ||
</figure> | ||
# Culori | ||
⚠ _Until __v1.0.0__ the API is a work-in-progress and will be changing quite a bit._ | ||
Culori is a general-purpose color library for JavaScript. It incorporates, and extends, ideas from Mike Bostock's [D3.js](https://github.com/d3) and Gregor Aisch's [chroma.js](https://github.com/gka/chroma.js). | ||
_(⚠ Until I realease __v1.0.0__ you can assume the API will be changing quite a bit, until I find an adequate expression.)_ | ||
__Color Spaces__. Culori supports all the formats defined in the [CSS Colors Level 4][css4-colors]: [Named colors][css4-named-colors], [Hex colors](https://drafts.csswg.org/css-color/#hex-notation) (3 to 8 digits), [RGB](https://drafts.csswg.org/css-color/#rgb-functions), [HSL](https://drafts.csswg.org/css-color/#the-hsl-notation), [HWB](https://drafts.csswg.org/css-color/#the-hwb-notation), [Lab and LCh](https://drafts.csswg.org/css-color/#lab-colors), and [Grays](https://drafts.csswg.org/css-color/#grays). Additionally, the [Linear RGB](https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_(%22gamma%22)), [HSV](https://en.wikipedia.org/wiki/HSL_and_HSV) (also known as HSB), [HSI](https://en.wikipedia.org/wiki/HSL_and_HSV), and [Cubehelix](https://www.mrao.cam.ac.uk/%7Edag/CUBEHELIX/) color spaces are supported. | ||
### Color Spaces | ||
__Color Differences__. Culori can compute [color differences](https://en.wikipedia.org/wiki/Color_difference) with either a simple Euclidean distance or the CIELAB Delta E* metric as formulated by CIE76, CIE94, CIEDE2000 and CMC l:c (1984). They're also available [as a D3 plugin](https://github.com/danburzo/d3-color-difference). It can also find the closest N colors from a set of colors based on any of these differences. | ||
Culori supports all the formats defined in the [CSS Colors Level 4][css4-colors]: [Named colors][css4-named-colors], [Hex colors](https://drafts.csswg.org/css-color/#hex-notation) (3 to 8 digits), [RGB](https://drafts.csswg.org/css-color/#rgb-functions), [HSL](https://drafts.csswg.org/css-color/#the-hsl-notation), [HWB](https://drafts.csswg.org/css-color/#the-hwb-notation), [Lab and LCh](https://drafts.csswg.org/css-color/#lab-colors), and [Grays](https://drafts.csswg.org/css-color/#grays). Additionally, the [Linear RGB](https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_(%22gamma%22)), [HSV](https://en.wikipedia.org/wiki/HSL_and_HSV) (also known as HSB), [HSI](https://en.wikipedia.org/wiki/HSL_and_HSV), and [Cubehelix](https://www.mrao.cam.ac.uk/%7Edag/CUBEHELIX/) color spaces are supported. | ||
## Foreword | ||
### Color Differences | ||
If you're thinking _Do we really need another JavaScript color library?_, I hear you. Reader, for the most part, we don't. Mike Bostock's [d3-color](https://github.com/d3/d3-color), and Gregor Aisch's [chroma.js](https://github.com/gka/chroma.js) are two robust libraries that provide most of what you need for working with colors on the web<sup>1</sup>. I'll admit Culori<sup>2</sup> is foremost a reflection of my own curiousity in understanding color spaces at a deeper level. But it also ended up a fairly fast, and fairly comprehensive, toolkit for manipulating colors — and with an implementation that has certain advantages. | ||
Culori can compute [color differences](https://en.wikipedia.org/wiki/Color_difference) with either a simple Euclidean distance or the CIELAB Delta E* metric as formulated by CIE76, CIE94, CIEDE2000 and CMC l:c (1984). They're also available [as a D3 plugin](https://github.com/danburzo/d3-color-difference). | ||
The _alpha_ channel which governs a color's opacity is treated differently than in other libaries, in that we don't equate an _undefined_ alpha with an alpha of 1. The hex string <kbd>#ff0000</kbd> _should_ eventually be interpreted as a fully-opaque red color, but at the color-manipulation level we want to draw the distinction between <kbd>#ff0000</kbd> and <kbd>#ff0000ff</kbd>, which has an explicit alpha channel. | ||
It can also find the closest N colors from a set of colors based on any of these differences. | ||
When developing the API, I tried to balance brevity, convenience and flexibility. It ended up a more-or-less functional API, i.e. a collection of functions you can pipe data through. It's not as readable as a fluent API where you chain methods, but it's much more flexible, I think. | ||
## Documentation | ||
--- | ||
* [Getting Started with Culori](./docs/tutorial.md) | ||
* [Culori Recipes](./docs/recipes.md) | ||
* [Extending Culori](./docs/extending.md) | ||
* [API Reference](./docs/api.md) | ||
* [Benchmarks](./docs/benchmarks.md) | ||
* [Further Reading](./docs/readings.md) | ||
<sup>1</sup> Other popular libraries you may want to look at are [TinyColor](https://github.com/bgrins/TinyColor) by [Brian Grinstead](http://briangrinstead.com), [color](https://github.com/Qix-/color) by Heather Arthur, [color.js](https://github.com/brehaut/color-js) by Andrew Brehaut et al, and [chromatist](https://github.com/jrus/chromatist) by [Jacob Rus](http://www.hcs.harvard.edu/~jrus/). | ||
## About the project | ||
<sup>2</sup> from the Romanian word for ‘colors’. | ||
Culori is written by [Dan Burzo](http://danburzo.ro) and is released under the [MIT License](./LICENSE). | ||
## Getting Started | ||
It builds upon the ideas of two thoroughly documented and time-tested projects: [d3-color](https://github.com/d3/d3-color) and [d3-interpolate](https://github.com/d3/d3-interpolate) by [Mike Bostock](https://bost.ocks.org/mike/), and [chroma.js](https://github.com/gka/chroma.js) by [Gregor Aisch](https://driven-by-data.net/). | ||
TODO | ||
You may also want to look at [TinyColor](https://github.com/bgrins/TinyColor) by [Brian Grinstead](http://briangrinstead.com), [color](https://github.com/Qix-/color) by [Heather Arthur](https://github.com/Qix-/), and [color.js](https://github.com/brehaut/color-js) by Andrew Brehaut et al. | ||
## API Reference | ||
* [Color representation](#color-representation) | ||
* [A note on the API](#a-note-on-the-api) | ||
* [Basics methods](#basic-methods) | ||
* [Interpolation](#interpolation) | ||
* [Difference](#difference) | ||
### Color representation | ||
Culori does not have a _Color_ class. Instead, it uses plain objects to represent colors: | ||
```js | ||
// A color in the RGB space | ||
{ | ||
mode: 'rgb', | ||
r: 0.1, | ||
g: 0.2, | ||
b: 1, | ||
alpha: 1 | ||
} | ||
``` | ||
The object needs to have a `mode` property that identifies the color space, and values for each channel in that particular color space. See the [Color Spaces](#color-spaces) section for the channels expected of each color space. Optionally, the `alpha` property is used for the color's alpha channel. | ||
### A note on the API | ||
TODO explain Functional style and its benefits. | ||
### Basic methods | ||
<a name="culoriParse" href="#culoriParse">#</a> culori.__parse__(_string_) → _color_ or _undefined_ [<>](https://github.com/danburzo/culori/blob/master/src/parse.js "Source") | ||
Parses a string and returns the corresponding _color_. The color will be in the matching color space, e.g. RGB for hex strings, HSL for `hsl(…, …, …)` strings, et cetera. If no built-in parsers can match the string, the function will return _undefined_. | ||
```js | ||
// named colors | ||
culori.parse('red'); // ⇒ { r: 1, g: 0, b: 0, mode: 'rgb' } | ||
// hex strings | ||
culori.parse('#ff0000'); // ⇒ { r: 1, g: 0, b: 0, mode: 'rgb' } | ||
// HSL color | ||
culori.parse('hsl(60 50% 10% / 100%)'); // ⇒ { h: 60, s: 0.5, b: 0.1, alpha: 1, mode: 'hsl' } | ||
// Lab color | ||
culori.parse('lab(100 -50 50)'); // ⇒ { l: 100, a: -50, b: 50, mode: 'lab' } | ||
``` | ||
<a name="culoriConverter" href="#culoriConverter">#</a> culori.__converter__(_mode = "rgb"_) → _function (color or String)_ [<>](https://github.com/danburzo/culori/blob/master/src/converter.js "Source") | ||
Returns a function that can then convert any color to the _mode_ color space: | ||
```js | ||
var rgb = culori.converter('rgb'); | ||
rgb('#f0f0f0'); // ⇒ { "mode": "rgb", "r": 0.4980392156862745, "g": 0.4980392156862745, "b": 0.4980392156862745 } | ||
``` | ||
Converters accept either strings (which will be parsed with `culori.parse`) or color objects. If the `mode` key is absent from the color, it's assumed to be in the converter's color space. | ||
The available modes (color spaces) are listed below. Each color space has a convenience method for converting to that color space. | ||
Mode | For | Shortcut | ||
---- | --- | -------- | ||
`rgb` | RGB color space | __culori__( _color_ ) and culori.__rgb__( _color_ ) | ||
`hsl` | HSL color space | culori.__hsl__(_color_) | ||
`hsv` | HSV color space | culori.__hsv__(_color_) | ||
`hsi` | HSI color space | culori.__hsi__(_color_) | ||
`hwb` | HWB color space | culori.__hwb__(_color_) | ||
`lab` | Lab color space | culori.__lab__(_color_) | ||
`lch` | LCh color space | culori.__lch__(_color_) | ||
`lrgb`| Linearized RGB color space | culori.__lrgb__(_color_) | ||
`cubehelix` | Cubehelix color space | culori.__cubehelix__(_color_) | ||
`dlab` | DIN99o Lab color space | culori.__dlab__(_color_) | ||
`dlch` | DIN99o LCh color space | culori.__dlch__(_color_) | ||
<a name="culoriFormatter" href="#culoriFormatter">#</a> culori.__formatter__(_format = 'rgb'_) → _function (color)_ [<>](https://github.com/danburzo/culori/blob/master/src/formatter.js "Source") | ||
Returns a formatter function that can transform colors to useful string representations. | ||
```js | ||
let hex = culori.formatter('hex'); | ||
hex('red'); // ⇒ "#ff0000" | ||
``` | ||
Available formats: | ||
Format | Description | ||
------ | ----------- | ||
`hex` | Returns the hex string for a color | ||
`rgb` | Returns the `rgb(…)` / `rgba(…)` string for a color | ||
<a name="culoriDisplayable" href="#culoriDisplayable">#</a> culori.__displayable__(_color_ or _String_) [<>](https://github.com/danburzo/culori/blob/master/src/displayable.js "Source") | ||
For some color spaces — particularly Lab and LCh — not all colors that can be expressed can be displayed on-screen. This function lets you check whether a particular color fits inside the sRGB gamut, i.e. that its `r`, `g`, and `b` channels are in the interval `[0, 1]`. | ||
```js | ||
culori.displayable('red'); // ⇒ true | ||
culori.displayable('rgb(300 255 255)'); // ⇒ false | ||
``` | ||
<a name="culoriClamp" href="#culoriClamp">#</a> culori.__clamp__(_method = 'rgb'_) → _function (color)_ [<>](https://github.com/danburzo/culori/blob/master/src/clamp.js "Source") | ||
Returns a function which you can then use to retreive a representation of any color that's displayable on the screen, i.e. fits within the sRGB gamut. There are two available methods: | ||
* `method = 'rgb'` clamps the `r`, `g`, `b` channel values of the color's RGB representation to the interval `[0, 1]`; | ||
* `method = 'lch'` converts the color to the LCh space and finds the largest Chroma channel value that's displayable for the given Lightness and Hue; if not even the achromatic version (Chroma = 0) of the LCh color is displayable, it falls back to the `rgb` method. | ||
```js | ||
culori.clamp('lch')('lch(50 120 5)'); // ⇒ { mode: 'lch', l: 50, c: 77.48291015625, h: 5 } | ||
``` | ||
<a name="culoriRound" href="#culoriRound">#</a> culori.__round__(_n = 8_) [<>](https://github.com/danburzo/culori/blob/master/src/round.js "Source") | ||
A (rather miscellaneous) utility that returns a function with which to round numbers to at most _n_ digits of precision. | ||
```js | ||
let approximate = culori.round(4); | ||
approximate(0.38393993); // => 0.3839 | ||
``` | ||
### Interpolation | ||
<a name="culoriInterpolate" href="#culoriInterpolate">#</a> culori.__interpolate__(_colors_, _mode = "rgb"_) [<>](https://github.com/danburzo/culori/blob/master/src/interpolate/interpolate.js "Source") | ||
Returns an interpolator between an array of colors in the _mode_ color space. | ||
<a name="culoriSamples" href="#culoriSamples">#</a> culori.__samples__(_n = 2_, _γ = 1_) [<>](https://github.com/danburzo/culori/blob/master/src/samples.js "Source") | ||
Returns an array of _n_ equally-spaced samples from the `[0, 1]` range, with `0` and `1` at the ends. The function also accepts a _γ_ (gamma) parameter which will map each value _t_ to _t_<sup>γ</sup>. | ||
```js | ||
culori.samples(3); // => [0, 0.5, 1] | ||
culori.samples(5); // => [0, 0.25, 0.5, 0.75, 1] | ||
``` | ||
The samples are useful for [culori.interpolate()](#culoriInterpolate) to generate color scales: | ||
```js | ||
let grays = culori.interpolate(['#fff', '#000']); | ||
samples(5).map(grays); | ||
``` | ||
#### Interpolation functions | ||
<a name="culoriInterpolateFunctionLinear" href="#culoriInterpolateFunctionLinear">#</a> culori.__interpolateFunctionLinear__ [<>](https://github.com/danburzo/culori/blob/master/src/interpolate/interpolateFunctionLinear.js "Source") | ||
<a name="culoriInterpolateFunctionSpline" href="#culoriInterpolateFunctionSpline">#</a> culori.__interpolateFunctionSpline__ [<>](https://github.com/danburzo/culori/blob/master/src/interpolate/interpolateFunctionSpline.js "Source") | ||
<a name="culoriInterpolateFunctionMonotone" href="#culoriInterpolateFunctionMonotone">#</a> culori.__interpolateFunctionMonotone__ [<>](https://github.com/danburzo/culori/blob/master/src/interpolate/interpolateFunctionMonotone.js "Source") | ||
<a name="culoriInterpolateFunctionCosine" href="#culoriInterpolateFunctionCosine">#</a> culori.__interpolateFunctionCosine__ [<>](https://github.com/danburzo/culori/blob/master/src/interpolate/interpolateFunctionCosine.js "Source") | ||
#### Interpolation modes | ||
<a name="culoriInterpolateNumber" href="#culoriInterpolateNumber">#</a> culori.__interpolateNumber__ [<>](https://github.com/danburzo/culori/blob/master/src/interpolate/interpolateNumber.js "Source") | ||
<a name="culoriInterpolateHue" href="#culoriInterpolateHue">#</a> culori.__interpolateHue__ [<>](https://github.com/danburzo/culori/blob/master/src/interpolate/interpolateHue.js "Source") | ||
<a name="culoriInterpolateNumber" href="#culoriInterpolateNumber">#</a> culori.__interpolateAlpha__ [<>](https://github.com/danburzo/culori/blob/master/src/interpolate/interpolateNumber.js "Source") | ||
### Difference | ||
These methods are concerned to finding the [distance between two colors](https://en.wikipedia.org/wiki/Color_difference) based on various formulas. Each of these formulas will return a _function (colorA, colorB)_ that lets you measure the distance between two colors. Also available as a separate [d3 plugin](https://github.com/danburzo/d3-color-difference). | ||
<a name="culoriDifferenceEuclidean" href="#culoriDifferenceEuclidean">#</a> culori.__differenceEuclidean__(_mode = 'rgb'_) [<>](https://github.com/danburzo/culori/blob/master/src/difference.js "Source") | ||
Returns a [Euclidean distance](https://en.wikipedia.org/wiki/Color_difference#Euclidean) function in a certain color space. | ||
<a name="culoriDifferenceCie76" href="#culoriDifferenceCie76">#</a> culori.__differenceCie76__() [<>](https://github.com/danburzo/culori/blob/master/src/difference.js "Source") | ||
Computes the [CIE76][CIE76] ΔE\*<sub>ab</sub> color difference between the colors _a_ and _b_. The computation is done in the Lab color space and it is analogous to [culori.differenceEuclidean('lab')](#culoriDifferenceEuclidean). | ||
<a name="culoriDifferenceCie94" href="#culoriDifferenceCie94">#</a> culori.__differenceCie94__(_kL = 1_, _K1 = 0.045_, _K2 = 0.015_) [<>](https://github.com/danburzo/culori/blob/master/src/difference.js "Source") | ||
Computes the [CIE94][CIE94] ΔE\*<sub>94</sub> color difference between the colors _a_ and _b_. The computation is done in the Lab color space. | ||
<a name="culoriDifferenceCiede2000" href="#culoriDifferenceCiede2000">#</a> culori.__differenceCiede2000__(_Kl = 1_, _Kc = 1_, _Kh = 1_) [<>](https://github.com/danburzo/culori/blob/master/src/difference.js "Source") | ||
Computes the [CIEDE2000][CIEDE2000] ΔE\*<sub>00</sub> color difference between the colors _a_ and _b_ as implemented by [G. Sharma](http://www2.ece.rochester.edu/~gsharma/ciede2000/). The computation is done in the Lab color space. | ||
Returns a [CIEDE2000](https://en.wikipedia.org/wiki/Color_difference#CIEDE2000) Delta E* function. | ||
<a name="culoriDifferenceCmc" href="#culoriDifferenceCmc">#</a> culori.__differenceCmc__() [<>](https://github.com/danburzo/culori/blob/master/src/difference.js "Source") | ||
Computes the [CMC l:c (1984)][CMC] ΔE\*<sub>CMC</sub> color difference between the colors _a_ and _b_. The computation is done in the Lab color space. | ||
_Note:_ ΔE\*<sub>CMC</sub> is not considered a metric since it's not symmetrical, i.e. the distance from _a_ to _b_ is not always equal to the distance from _b_ to _a_. Therefore it cannot be reliably used with [culori.nearest()](#culoriNearest). | ||
<a name="culoriDifferenceDin99o" href="#culoriDifferenceDin99o">#</a> culori.__differenceDin99o__() [<>](https://github.com/danburzo/culori/blob/master/src/difference.js "Source") | ||
Computes the [DIN99o][DIN99oDE] ΔE\*<sub>99o</sub> color difference between the colors _a_ and _b_. The computation is done in the [DIN99o][DIN99o] color space. | ||
#### Nearest color(s) | ||
<a name="culoriNearest" href="#culoriNearest">#</a> culori.__nearest__(_colors_, _metric = differenceEuclidean()_, _accessor = identity_) → _function(color, n = 1, τ = Infinity)_ [<>](https://github.com/danburzo/culori/blob/master/src/nearest.js "Source") | ||
For a given _metric_ color difference formula, and an array of _colors_, returns a function with which you can find _n_ colors nearest to _color_, with a maximum distance of _τ_. | ||
Pass _n = Infinity_ to get all colors in the array with a maximum distance of _τ_. | ||
## Color Spaces | ||
TODO | ||
### HSL | ||
The figure above shows a slice of the HSL color space for a particular hue: | ||
<img src='./.github/hsl-spectrum.png' width='200'/> | ||
### HSV | ||
The figure above shows a slice of the HSV color space for a particular hue: | ||
<img src='./.github/hsv-spectrum.png' width='200'/> | ||
### HSI | ||
The figure above shows a slice of the HSI color space for a particular hue: | ||
<img src='./.github/hsi-spectrum.png' width='200'/> | ||
## Culori Recipes | ||
#### Relative luminance of a color | ||
The [relative luminance](https://en.wikipedia.org/wiki/Relative_luminance) of a color is defined as: | ||
```js | ||
L = 0.2126 * R + 0.7152 * G + 0.0722 * B | ||
``` | ||
Where R, G, and B are the components from the LRGB color space. | ||
To compute it in Culori: | ||
```js | ||
function luminance(color) { | ||
let c = culori.lrgb(color); | ||
return 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b; | ||
} | ||
``` | ||
__Note:__ The WCAG defines the luminance using a [deprecated value](https://github.com/w3c/wcag/issues/236#issuecomment-379526596) for converting sRGB to LRGB. If you'd like a strict implementation, you'll need to write your own sRGB → LRGB conversion. | ||
#### Contrast ratio | ||
Using the `luminance()` function above, the `contrast()` ratio is simply the ratio between the luminances of two colors, with the values shifted by 0.05 to avoid division by zero when comparing against black. | ||
```js | ||
function contrast(colorA, colorB) { | ||
let L1 = luminance(colorA); | ||
let L2 = luminance(colorB); | ||
return (L1 + 0.05) / (L2 + 0.05); | ||
} | ||
``` | ||
## Extending Culori | ||
TODO | ||
## See also | ||
These libraries extend Culori: | ||
* [culori-scales](https://github.com/danburzo/culori-scales) — color scales (ColorBrewer, matplotlib, etc.) | ||
* [culori-names](https://github.com/danburzo/culori-names) — more color names | ||
## Further reading | ||
* [HSL and HSV](https://en.wikipedia.org/wiki/HSL_and_HSV) on Wikipedia | ||
* [CSS Color Module Level 4][css4-colors] | ||
* [CSSOM standard serialization](https://drafts.csswg.org/cssom/#serialize-a-css-component-value) | ||
## Colophon | ||
* _Author_ [Dan Burzo](http://danburzo.ro) | ||
* _License_ [MIT](./LICENSE) | ||
* _Inspired by_ [d3-color](https://github.com/d3/d3-color), [d3-interpolate](https://github.com/d3/d3-interpolate), [chroma.js](https://github.com/gka/chroma.js) | ||
* _Dependencies_ none | ||
* _Bundled with_ [rollup](https://github.com/rollup/rollup), [buble](https://github.com/Rich-Harris/buble) | ||
* _Tested with_ [tape](https://github.com/substack/tape) | ||
[css4-colors]: https://drafts.csswg.org/css-color/ | ||
[css4-named-colors]: https://drafts.csswg.org/css-color/#named-colors | ||
[css4-named-colors]: https://drafts.csswg.org/css-color/#named-colors | ||
[CIE76]: https://en.wikipedia.org/wiki/Color_difference#CIE76 | ||
[CIE94]: https://en.wikipedia.org/wiki/Color_difference#CIE94 | ||
[CIEDE2000]: https://en.wikipedia.org/wiki/Color_difference#CIEDE2000 | ||
[CMC]: https://en.wikipedia.org/wiki/Color_difference#CMC_l:c_(1984) | ||
[DIN99o]: https://de.wikipedia.org/wiki/DIN99-Farbraum | ||
[DIN99oDE]: https://de.wikipedia.org/wiki/DIN99-Farbraum#Farbabstandsformel |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157394
6
3712
330