color-convert
Advanced tools
Comparing version 2.0.1 to 3.0.0
/* MIT license */ | ||
/* eslint-disable no-mixed-operators */ | ||
const cssKeywords = require('color-name'); | ||
import cssKeywords from 'color-name'; | ||
@@ -29,7 +29,10 @@ // NOTE: conversions should only return primitive values (i.e. arrays, or | ||
apple: {channels: 3, labels: ['r16', 'g16', 'b16']}, | ||
gray: {channels: 1, labels: ['gray']} | ||
gray: {channels: 1, labels: ['gray']}, | ||
}; | ||
module.exports = convert; | ||
export default convert; | ||
// LAB f(t) constant | ||
const LAB_FT = (6 / 29) ** 3; | ||
// Hide .channels and .labels properties | ||
@@ -66,10 +69,27 @@ for (const model of Object.keys(convert)) { | ||
if (max === min) { | ||
h = 0; | ||
} else if (r === max) { | ||
h = (g - b) / delta; | ||
} else if (g === max) { | ||
h = 2 + (b - r) / delta; | ||
} else if (b === max) { | ||
h = 4 + (r - g) / delta; | ||
switch (max) { | ||
case min: { | ||
h = 0; | ||
break; | ||
} | ||
case r: { | ||
h = (g - b) / delta; | ||
break; | ||
} | ||
case g: { | ||
h = 2 + (b - r) / delta; | ||
break; | ||
} | ||
case b: { | ||
h = 4 + (r - g) / delta; | ||
break; | ||
} | ||
// No default | ||
} | ||
@@ -121,8 +141,21 @@ | ||
if (r === v) { | ||
h = bdif - gdif; | ||
} else if (g === v) { | ||
h = (1 / 3) + rdif - bdif; | ||
} else if (b === v) { | ||
h = (2 / 3) + gdif - rdif; | ||
switch (v) { | ||
case r: { | ||
h = bdif - gdif; | ||
break; | ||
} | ||
case g: { | ||
h = (1 / 3) + rdif - bdif; | ||
break; | ||
} | ||
case b: { | ||
h = (2 / 3) + gdif - rdif; | ||
break; | ||
} | ||
// No default | ||
} | ||
@@ -140,3 +173,3 @@ | ||
s * 100, | ||
v * 100 | ||
v * 100, | ||
]; | ||
@@ -187,3 +220,3 @@ }; | ||
let currentClosestDistance = Infinity; | ||
let currentClosestDistance = Number.POSITIVE_INFINITY; | ||
let currentClosestKeyword; | ||
@@ -217,9 +250,9 @@ | ||
// Assume sRGB | ||
r = r > 0.04045 ? (((r + 0.055) / 1.055) ** 2.4) : (r / 12.92); | ||
g = g > 0.04045 ? (((g + 0.055) / 1.055) ** 2.4) : (g / 12.92); | ||
b = b > 0.04045 ? (((b + 0.055) / 1.055) ** 2.4) : (b / 12.92); | ||
r = r > 0.040_45 ? (((r + 0.055) / 1.055) ** 2.4) : (r / 12.92); | ||
g = g > 0.040_45 ? (((g + 0.055) / 1.055) ** 2.4) : (g / 12.92); | ||
b = b > 0.040_45 ? (((b + 0.055) / 1.055) ** 2.4) : (b / 12.92); | ||
const x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805); | ||
const y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722); | ||
const z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505); | ||
const x = (r * 0.412_456_4) + (g * 0.357_576_1) + (b * 0.180_437_5); | ||
const y = (r * 0.212_672_9) + (g * 0.715_152_2) + (b * 0.072_175); | ||
const z = (r * 0.019_333_9) + (g * 0.119_192) + (b * 0.950_304_1); | ||
@@ -239,5 +272,5 @@ return [x * 100, y * 100, z * 100]; | ||
x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116); | ||
y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116); | ||
z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116); | ||
x = x > LAB_FT ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116); | ||
y = y > LAB_FT ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116); | ||
z = z > LAB_FT ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116); | ||
@@ -255,16 +288,11 @@ const l = (116 * y) - 16; | ||
const l = hsl[2] / 100; | ||
let t2; | ||
let t3; | ||
let val; | ||
let value; | ||
if (s === 0) { | ||
val = l * 255; | ||
return [val, val, val]; | ||
value = l * 255; | ||
return [value, value, value]; | ||
} | ||
if (l < 0.5) { | ||
t2 = l * (1 + s); | ||
} else { | ||
t2 = l + s - l * s; | ||
} | ||
const t2 = l < 0.5 ? l * (1 + s) : l + s - l * s; | ||
@@ -285,12 +313,12 @@ const t1 = 2 * l - t2; | ||
if (6 * t3 < 1) { | ||
val = t1 + (t2 - t1) * 6 * t3; | ||
value = t1 + (t2 - t1) * 6 * t3; | ||
} else if (2 * t3 < 1) { | ||
val = t2; | ||
value = t2; | ||
} else if (3 * t3 < 2) { | ||
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6; | ||
value = t1 + (t2 - t1) * (2 / 3 - t3) * 6; | ||
} else { | ||
val = t1; | ||
value = t1; | ||
} | ||
rgb[i] = val * 255; | ||
rgb[i] = value * 255; | ||
} | ||
@@ -330,14 +358,25 @@ | ||
switch (hi) { | ||
case 0: | ||
case 0: { | ||
return [v, t, p]; | ||
case 1: | ||
} | ||
case 1: { | ||
return [q, v, p]; | ||
case 2: | ||
} | ||
case 2: { | ||
return [p, v, t]; | ||
case 3: | ||
} | ||
case 3: { | ||
return [p, q, v]; | ||
case 4: | ||
} | ||
case 4: { | ||
return [t, p, v]; | ||
case 5: | ||
} | ||
case 5: { | ||
return [v, p, q]; | ||
} | ||
} | ||
@@ -382,2 +421,3 @@ }; | ||
// eslint-disable-next-line no-bitwise | ||
if ((i & 0x01) !== 0) { | ||
@@ -392,14 +432,25 @@ f = 1 - f; | ||
let b; | ||
/* eslint-disable max-statements-per-line,no-multi-spaces */ | ||
/* eslint-disable max-statements-per-line,no-multi-spaces, default-case-last */ | ||
switch (i) { | ||
default: | ||
case 6: | ||
case 0: r = v; g = n; b = wh; break; | ||
case 1: r = n; g = v; b = wh; break; | ||
case 2: r = wh; g = v; b = n; break; | ||
case 3: r = wh; g = n; b = v; break; | ||
case 4: r = n; g = wh; b = v; break; | ||
case 5: r = v; g = wh; b = n; break; | ||
case 0: { r = v; g = n; b = wh; break; | ||
} | ||
case 1: { r = n; g = v; b = wh; break; | ||
} | ||
case 2: { r = wh; g = v; b = n; break; | ||
} | ||
case 3: { r = wh; g = n; b = v; break; | ||
} | ||
case 4: { r = n; g = wh; b = v; break; | ||
} | ||
case 5: { r = v; g = wh; b = n; break; | ||
} | ||
} | ||
/* eslint-enable max-statements-per-line,no-multi-spaces */ | ||
/* eslint-enable max-statements-per-line,no-multi-spaces, default-case-last */ | ||
@@ -430,17 +481,17 @@ return [r * 255, g * 255, b * 255]; | ||
r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986); | ||
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415); | ||
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570); | ||
r = (x * 3.240_454_2) + (y * -1.537_138_5) + (z * -0.498_531_4); | ||
g = (x * -0.969_266) + (y * 1.876_010_8) + (z * 0.041_556); | ||
b = (x * 0.055_643_4) + (y * -0.204_025_9) + (z * 1.057_225_2); | ||
// Assume sRGB | ||
r = r > 0.0031308 | ||
? ((1.055 * (r ** (1.0 / 2.4))) - 0.055) | ||
r = r > 0.003_130_8 | ||
? ((1.055 * (r ** (1 / 2.4))) - 0.055) | ||
: r * 12.92; | ||
g = g > 0.0031308 | ||
? ((1.055 * (g ** (1.0 / 2.4))) - 0.055) | ||
g = g > 0.003_130_8 | ||
? ((1.055 * (g ** (1 / 2.4))) - 0.055) | ||
: g * 12.92; | ||
b = b > 0.0031308 | ||
? ((1.055 * (b ** (1.0 / 2.4))) - 0.055) | ||
b = b > 0.003_130_8 | ||
? ((1.055 * (b ** (1 / 2.4))) - 0.055) | ||
: b * 12.92; | ||
@@ -464,5 +515,5 @@ | ||
x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116); | ||
y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116); | ||
z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116); | ||
x = x > LAB_FT ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116); | ||
y = y > LAB_FT ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116); | ||
z = z > LAB_FT ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116); | ||
@@ -491,6 +542,8 @@ const l = (116 * y) - 16; | ||
const z2 = z ** 3; | ||
y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787; | ||
x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787; | ||
z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787; | ||
y = y2 > LAB_FT ? y2 : (y - 16 / 116) / 7.787; | ||
x = x2 > LAB_FT ? x2 : (x - 16 / 116) / 7.787; | ||
z = z2 > LAB_FT ? z2 : (z - 16 / 116) / 7.787; | ||
// Illuminant D65 XYZ Tristrimulus Values | ||
// https://en.wikipedia.org/wiki/CIE_1931_color_space | ||
x *= 95.047; | ||
@@ -544,5 +597,7 @@ y *= 100; | ||
let ansi = 30 | ||
/* eslint-disable no-bitwise */ | ||
+ ((Math.round(b / 255) << 2) | ||
| (Math.round(g / 255) << 1) | ||
| Math.round(r / 255)); | ||
/* eslint-enable no-bitwise */ | ||
@@ -569,3 +624,4 @@ if (value === 2) { | ||
// black and white. normal palette only has 4 greyscale shades. | ||
if (r === g && g === b) { | ||
// eslint-disable-next-line no-bitwise | ||
if (r >> 4 === g >> 4 && g >> 4 === b >> 4) { | ||
if (r < 8) { | ||
@@ -591,2 +647,4 @@ return 16; | ||
convert.ansi16.rgb = function (args) { | ||
args = args[0]; | ||
let color = args % 10; | ||
@@ -605,6 +663,8 @@ | ||
const mult = (~~(args > 50) + 1) * 0.5; | ||
const mult = (Math.trunc(args > 50) + 1) * 0.5; | ||
/* eslint-disable no-bitwise */ | ||
const r = ((color & 1) * mult) * 255; | ||
const g = (((color >> 1) & 1) * mult) * 255; | ||
const b = (((color >> 2) & 1) * mult) * 255; | ||
/* eslint-enable no-bitwise */ | ||
@@ -615,2 +675,4 @@ return [r, g, b]; | ||
convert.ansi256.rgb = function (args) { | ||
args = args[0]; | ||
// Handle greyscale | ||
@@ -633,12 +695,14 @@ if (args >= 232) { | ||
convert.rgb.hex = function (args) { | ||
/* eslint-disable no-bitwise */ | ||
const integer = ((Math.round(args[0]) & 0xFF) << 16) | ||
+ ((Math.round(args[1]) & 0xFF) << 8) | ||
+ (Math.round(args[2]) & 0xFF); | ||
/* eslint-enable no-bitwise */ | ||
const string = integer.toString(16).toUpperCase(); | ||
return '000000'.substring(string.length) + string; | ||
return '000000'.slice(string.length) + string; | ||
}; | ||
convert.hex.rgb = function (args) { | ||
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i); | ||
const match = args.toString(16).match(/[a-f\d]{6}|[a-f\d]{3}/i); | ||
if (!match) { | ||
@@ -651,11 +715,11 @@ return [0, 0, 0]; | ||
if (match[0].length === 3) { | ||
colorString = colorString.split('').map(char => { | ||
return char + char; | ||
}).join(''); | ||
colorString = [...colorString].map(char => char + char).join(''); | ||
} | ||
const integer = parseInt(colorString, 16); | ||
const integer = Number.parseInt(colorString, 16); | ||
/* eslint-disable no-bitwise */ | ||
const r = (integer >> 16) & 0xFF; | ||
const g = (integer >> 8) & 0xFF; | ||
const b = integer & 0xFF; | ||
/* eslint-enable no-bitwise */ | ||
@@ -672,18 +736,11 @@ return [r, g, b]; | ||
const chroma = (max - min); | ||
let grayscale; | ||
let hue; | ||
if (chroma < 1) { | ||
grayscale = min / (1 - chroma); | ||
} else { | ||
grayscale = 0; | ||
} | ||
const grayscale = chroma < 1 ? min / (1 - chroma) : 0; | ||
if (chroma <= 0) { | ||
hue = 0; | ||
} else | ||
if (max === r) { | ||
} else if (max === r) { | ||
hue = ((g - b) / chroma) % 6; | ||
} else | ||
if (max === g) { | ||
} else if (max === g) { | ||
hue = 2 + (b - r) / chroma; | ||
@@ -704,7 +761,7 @@ } else { | ||
const c = l < 0.5 ? (2.0 * s * l) : (2.0 * s * (1.0 - l)); | ||
const c = l < 0.5 ? (2 * s * l) : (2 * s * (1 - l)); | ||
let f = 0; | ||
if (c < 1.0) { | ||
f = (l - 0.5 * c) / (1.0 - c); | ||
if (c < 1) { | ||
f = (l - 0.5 * c) / (1 - c); | ||
} | ||
@@ -722,3 +779,3 @@ | ||
if (c < 1.0) { | ||
if (c < 1) { | ||
f = (v - c) / (1 - c); | ||
@@ -735,3 +792,3 @@ } | ||
if (c === 0.0) { | ||
if (c === 0) { | ||
return [g * 255, g * 255, g * 255]; | ||
@@ -748,18 +805,29 @@ } | ||
switch (Math.floor(hi)) { | ||
case 0: | ||
case 0: { | ||
pure[0] = 1; pure[1] = v; pure[2] = 0; break; | ||
case 1: | ||
} | ||
case 1: { | ||
pure[0] = w; pure[1] = 1; pure[2] = 0; break; | ||
case 2: | ||
} | ||
case 2: { | ||
pure[0] = 0; pure[1] = 1; pure[2] = v; break; | ||
case 3: | ||
} | ||
case 3: { | ||
pure[0] = 0; pure[1] = w; pure[2] = 1; break; | ||
case 4: | ||
} | ||
case 4: { | ||
pure[0] = v; pure[1] = 0; pure[2] = 1; break; | ||
default: | ||
} | ||
default: { | ||
pure[0] = 1; pure[1] = 0; pure[2] = w; | ||
} | ||
} | ||
/* eslint-enable max-statements-per-line */ | ||
mg = (1.0 - c) * g; | ||
mg = (1 - c) * g; | ||
@@ -769,3 +837,3 @@ return [ | ||
(c * pure[1] + mg) * 255, | ||
(c * pure[2] + mg) * 255 | ||
(c * pure[2] + mg) * 255, | ||
]; | ||
@@ -778,6 +846,6 @@ }; | ||
const v = c + g * (1.0 - c); | ||
const v = c + g * (1 - c); | ||
let f = 0; | ||
if (v > 0.0) { | ||
if (v > 0) { | ||
f = c / v; | ||
@@ -793,9 +861,8 @@ } | ||
const l = g * (1.0 - c) + 0.5 * c; | ||
const l = g * (1 - c) + 0.5 * c; | ||
let s = 0; | ||
if (l > 0.0 && l < 0.5) { | ||
if (l > 0 && l < 0.5) { | ||
s = c / (2 * l); | ||
} else | ||
if (l >= 0.5 && l < 1.0) { | ||
} else if (l >= 0.5 && l < 1) { | ||
s = c / (2 * (1 - l)); | ||
@@ -810,3 +877,3 @@ } | ||
const g = hcg[2] / 100; | ||
const v = c + g * (1.0 - c); | ||
const v = c + g * (1 - c); | ||
return [hcg[0], (v - c) * 100, (1 - v) * 100]; | ||
@@ -830,7 +897,7 @@ }; | ||
convert.apple.rgb = function (apple) { | ||
return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255]; | ||
return [(apple[0] / 65_535) * 255, (apple[1] / 65_535) * 255, (apple[2] / 65_535) * 255]; | ||
}; | ||
convert.rgb.apple = function (rgb) { | ||
return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535]; | ||
return [(rgb[0] / 255) * 65_535, (rgb[1] / 255) * 65_535, (rgb[2] / 255) * 65_535]; | ||
}; | ||
@@ -861,12 +928,14 @@ | ||
convert.gray.hex = function (gray) { | ||
const val = Math.round(gray[0] / 100 * 255) & 0xFF; | ||
const integer = (val << 16) + (val << 8) + val; | ||
/* eslint-disable no-bitwise */ | ||
const value = Math.round(gray[0] / 100 * 255) & 0xFF; | ||
const integer = (value << 16) + (value << 8) + value; | ||
/* eslint-enable no-bitwise */ | ||
const string = integer.toString(16).toUpperCase(); | ||
return '000000'.substring(string.length) + string; | ||
return '000000'.slice(string.length) + string; | ||
}; | ||
convert.rgb.gray = function (rgb) { | ||
const val = (rgb[0] + rgb[1] + rgb[2]) / 3; | ||
return [val / 255 * 100]; | ||
const value = (rgb[0] + rgb[1] + rgb[2]) / 3; | ||
return [value / 255 * 100]; | ||
}; |
16
index.js
@@ -1,3 +0,3 @@ | ||
const conversions = require('./conversions'); | ||
const route = require('./route'); | ||
import conversions from './conversions.js'; | ||
import route from './route.js'; | ||
@@ -48,3 +48,3 @@ const convert = {}; | ||
if (typeof result === 'object') { | ||
for (let len = result.length, i = 0; i < len; i++) { | ||
for (let {length} = result, i = 0; i < length; i++) { | ||
result[i] = Math.round(result[i]); | ||
@@ -65,3 +65,3 @@ } | ||
models.forEach(fromModel => { | ||
for (const fromModel of models) { | ||
convert[fromModel] = {}; | ||
@@ -75,3 +75,3 @@ | ||
routeModels.forEach(toModel => { | ||
for (const toModel of routeModels) { | ||
const fn = routes[toModel]; | ||
@@ -81,5 +81,5 @@ | ||
convert[fromModel][toModel].raw = wrapRaw(fn); | ||
}); | ||
}); | ||
} | ||
} | ||
module.exports = convert; | ||
export default convert; |
{ | ||
"name": "color-convert", | ||
"description": "Plain color conversion functions", | ||
"version": "2.0.1", | ||
"author": "Heather Arthur <fayearthur@gmail.com>", | ||
"version": "3.0.0", | ||
"author": "Josh Junon <josh@junon.me>", | ||
"contributors": [ | ||
"Heather Arthur <fayearthur@gmail.com>" | ||
], | ||
"license": "MIT", | ||
"repository": "Qix-/color-convert", | ||
"type": "module", | ||
"exports": "./index.js", | ||
"types": "./index.d.ts", | ||
"engines": { | ||
"node": ">=14.6" | ||
}, | ||
"scripts": { | ||
"pretest": "xo", | ||
"test": "node test/basic.js" | ||
"test": "xo && tsd && node test/basic.js" | ||
}, | ||
"engines": { | ||
"node": ">=7.0.0" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"conversions.js", | ||
"route.js" | ||
], | ||
"keywords": [ | ||
@@ -29,7 +40,2 @@ "color", | ||
], | ||
"files": [ | ||
"index.js", | ||
"conversions.js", | ||
"route.js" | ||
], | ||
"xo": { | ||
@@ -39,12 +45,16 @@ "rules": { | ||
"no-inline-comments": 0, | ||
"operator-linebreak": 0 | ||
"operator-linebreak": 0, | ||
"unicorn/prefer-exponentiation-operator": 0, | ||
"@typescript-eslint/naming-convention": 0 | ||
} | ||
}, | ||
"devDependencies": { | ||
"chalk": "^2.4.2", | ||
"xo": "^0.24.0" | ||
"chalk": "^5.2.0", | ||
"jimp": "^0.22.8", | ||
"tsd": "^0.28.1", | ||
"xo": "^0.54.2" | ||
}, | ||
"dependencies": { | ||
"color-name": "~1.1.4" | ||
"color-name": "^2.0.0" | ||
} | ||
} |
# color-convert | ||
[](https://travis-ci.org/Qix-/color-convert) | ||
Color-convert is a color conversion library for JavaScript and node. | ||
@@ -9,3 +7,3 @@ It converts all ways between `rgb`, `hsl`, `hsv`, `hwb`, `cmyk`, `ansi`, `ansi16`, `hex` strings, and CSS `keyword`s (will round to closest): | ||
```js | ||
var convert = require('color-convert'); | ||
import convert from 'color-convert'; | ||
@@ -15,5 +13,5 @@ convert.rgb.hsl(140, 200, 100); // [96, 48, 59] | ||
var rgbChannels = convert.rgb.channels; // 3 | ||
var cmykChannels = convert.cmyk.channels; // 4 | ||
var ansiChannels = convert.ansi16.channels; // 1 | ||
const rgbChannels = convert.rgb.channels; // 3 | ||
const cmykChannels = convert.cmyk.channels; // 4 | ||
const ansiChannels = convert.ansi16.channels; // 1 | ||
``` | ||
@@ -23,4 +21,4 @@ | ||
```console | ||
$ npm install color-convert | ||
```sh | ||
npm install color-convert | ||
``` | ||
@@ -37,3 +35,3 @@ | ||
```js | ||
var convert = require('color-convert'); | ||
import convert from 'color-convert'; | ||
@@ -55,3 +53,3 @@ // Hex to LAB | ||
```js | ||
var convert = require('color-convert'); | ||
import convert from 'color-convert'; | ||
@@ -68,2 +66,63 @@ convert.rgb.hex(123, 45, 67); // '7B2D43' | ||
## Color Space Scales | ||
Conversions rely on an agreed upon 'full-scale' value for each of the channels. Listed here are those values for the most common color spaces | ||
### rgb | ||
channel | full-scale value | ||
---|--- | ||
r | 255 | ||
g | 255 | ||
b | 255 | ||
### hsl | ||
channel | full-scale value | ||
---|--- | ||
h | 360 | ||
s | 100 | ||
l | 100 | ||
### hsv | ||
channel | full-scale value | ||
---|--- | ||
h | 360 | ||
s | 100 | ||
v | 100 | ||
### hwb | ||
channel | full-scale value | ||
---|--- | ||
h | 360 | ||
w | 100 | ||
b | 100 | ||
### cmyk | ||
channel | full-scale value | ||
---|--- | ||
c | 100 | ||
m | 100 | ||
y | 100 | ||
k | 100 | ||
### hex | ||
channel | full-scale value | ||
---|--- | ||
hex | ```0xffffff``` | ||
### keyword | ||
channel | value | ||
---|--- | ||
name | any key from [color-name](https://github.com/colorjs/color-name/blob/master/index.js) | ||
### apple | ||
channel | full-scale value | ||
---|--- | ||
0 | 65535 | ||
1 | 65535 | ||
2 | 65535 | ||
### gray | ||
channel | full-scale value | ||
---|--- | ||
gray | 100 | ||
# Contribute | ||
@@ -74,2 +133,5 @@ | ||
# License | ||
Copyright © 2011-2016, Heather Arthur and Josh Junon. Licensed under the [MIT License](LICENSE). | ||
Copyright © 2011-2016, Heather Arthur. | ||
Copyright © 2016-2021, Josh Junon. | ||
Licensed under the [MIT License](LICENSE). |
17
route.js
@@ -1,2 +0,2 @@ | ||
const conversions = require('./conversions'); | ||
import conversions from './conversions.js'; | ||
@@ -19,3 +19,3 @@ /* | ||
for (let len = models.length, i = 0; i < len; i++) { | ||
for (let {length} = models, i = 0; i < length; i++) { | ||
graph[models[i]] = { | ||
@@ -25,3 +25,3 @@ // http://jsperf.com/1-vs-infinity | ||
distance: -1, | ||
parent: null | ||
parent: null, | ||
}; | ||
@@ -40,7 +40,7 @@ } | ||
while (queue.length) { | ||
while (queue.length > 0) { | ||
const current = queue.pop(); | ||
const adjacents = Object.keys(conversions[current]); | ||
for (let len = adjacents.length, i = 0; i < len; i++) { | ||
for (let {length} = adjacents, i = 0; i < length; i++) { | ||
const adjacent = adjacents[i]; | ||
@@ -81,3 +81,3 @@ const node = graph[adjacent]; | ||
module.exports = function (fromModel) { | ||
function route(fromModel) { | ||
const graph = deriveBFS(fromModel); | ||
@@ -87,3 +87,3 @@ const conversion = {}; | ||
const models = Object.keys(graph); | ||
for (let len = models.length, i = 0; i < len; i++) { | ||
for (let {length} = models, i = 0; i < length; i++) { | ||
const toModel = models[i]; | ||
@@ -101,3 +101,4 @@ const node = graph[toModel]; | ||
return conversion; | ||
}; | ||
} | ||
export default route; |
Sorry, the diff of this file is not supported yet
32344
1095
131
Yes
4
+ Addedcolor-name@2.0.0(transitive)
- Removedcolor-name@1.1.4(transitive)
Updatedcolor-name@^2.0.0