lint lib/colors.js
This commit is contained in:
parent
052ebaf6d1
commit
6e1d7e6126
|
@ -11,25 +11,29 @@ exports.match = function(r1, g1, b1) {
|
|||
return -1;
|
||||
}
|
||||
hex = exports.hexToRGB(hex);
|
||||
r1 = hex[0], g1 = hex[1], b1 = hex[2];
|
||||
r1 = hex[0];
|
||||
g1 = hex[1];
|
||||
b1 = hex[2];
|
||||
} else if (Array.isArray(r1)) {
|
||||
b1 = r1[2], g1 = r1[1], r1 = r1[0];
|
||||
b1 = r1[2];
|
||||
g1 = r1[1];
|
||||
r1 = r1[0];
|
||||
}
|
||||
|
||||
var hash = (r1 << 16) | (g1 << 8) | b1;
|
||||
|
||||
if (exports._cache[hash] != null) {
|
||||
if (exports._cache[hash] !== null) {
|
||||
return exports._cache[hash];
|
||||
}
|
||||
|
||||
var ldiff = Infinity
|
||||
, li = -1
|
||||
, i = 0
|
||||
, c
|
||||
, r2
|
||||
, g2
|
||||
, b2
|
||||
, diff;
|
||||
var ldiff = Infinity,
|
||||
li = -1,
|
||||
i = 0,
|
||||
c,
|
||||
r2,
|
||||
g2,
|
||||
b2,
|
||||
diff;
|
||||
|
||||
for (; i < exports.vcolors.length; i++) {
|
||||
c = exports.vcolors[i];
|
||||
|
@ -50,12 +54,15 @@ exports.match = function(r1, g1, b1) {
|
|||
}
|
||||
}
|
||||
|
||||
return exports._cache[hash] = li;
|
||||
exports._cache[hash] = li;
|
||||
return exports._cache[hash];
|
||||
};
|
||||
|
||||
exports.RGBToHex = function(r, g, b) {
|
||||
if (Array.isArray(r)) {
|
||||
b = r[2], g = r[1], r = r[0];
|
||||
b = r[2];
|
||||
g = r[1];
|
||||
r = r[0];
|
||||
}
|
||||
|
||||
function hex(n) {
|
||||
|
@ -69,16 +76,10 @@ exports.RGBToHex = function(r, g, b) {
|
|||
|
||||
exports.hexToRGB = function(hex) {
|
||||
if (hex.length === 4) {
|
||||
hex = hex[0]
|
||||
+ hex[1] + hex[1]
|
||||
+ hex[2] + hex[2]
|
||||
+ hex[3] + hex[3];
|
||||
hex = hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
|
||||
}
|
||||
|
||||
var col = parseInt(hex.substring(1), 16)
|
||||
, r = (col >> 16) & 0xff
|
||||
, g = (col >> 8) & 0xff
|
||||
, b = col & 0xff;
|
||||
var col = parseInt(hex.substring(1), 16), r = (col >> 16) & 0xff, g = (col >> 8) & 0xff, b = col & 0xff;
|
||||
|
||||
return [r, g, b];
|
||||
};
|
||||
|
@ -90,9 +91,7 @@ exports.hexToRGB = function(hex) {
|
|||
// [1] http://stackoverflow.com/questions/1633828
|
||||
|
||||
function colorDistance(r1, g1, b1, r2, g2, b2) {
|
||||
return Math.pow(30 * (r1 - r2), 2)
|
||||
+ Math.pow(59 * (g1 - g2), 2)
|
||||
+ Math.pow(11 * (b1 - b2), 2);
|
||||
return Math.pow(30 * (r1 - r2), 2) + Math.pow(59 * (g1 - g2), 2) + Math.pow(11 * (b1 - b2), 2);
|
||||
}
|
||||
|
||||
// This might work well enough for a terminal's colors: treat RGB as XYZ in a
|
||||
|
@ -102,7 +101,7 @@ exports.mixColors = function(c1, c2, alpha) {
|
|||
// if (c2 === 0x1ff) return c1;
|
||||
if (c1 === 0x1ff) c1 = 0;
|
||||
if (c2 === 0x1ff) c2 = 0;
|
||||
if (alpha == null) alpha = 0.5;
|
||||
if (alpha === null) alpha = 0.5;
|
||||
|
||||
c1 = exports.vcolors[c1];
|
||||
var r1 = c1[0];
|
||||
|
@ -125,13 +124,13 @@ exports.blend = function blend(attr, attr2, alpha) {
|
|||
var name, i, c, nc;
|
||||
|
||||
var bg = attr & 0x1ff;
|
||||
if (attr2 != null) {
|
||||
if (attr2 !== null) {
|
||||
var bg2 = attr2 & 0x1ff;
|
||||
if (bg === 0x1ff) bg = 0;
|
||||
if (bg2 === 0x1ff) bg2 = 0;
|
||||
bg = exports.mixColors(bg, bg2, alpha);
|
||||
} else {
|
||||
if (blend._cache[bg] != null) {
|
||||
if (blend._cache[bg] !== null) {
|
||||
bg = blend._cache[bg];
|
||||
// } else if (bg < 8) {
|
||||
// bg += 8;
|
||||
|
@ -159,7 +158,7 @@ exports.blend = function blend(attr, attr2, alpha) {
|
|||
attr |= bg;
|
||||
|
||||
var fg = (attr >> 9) & 0x1ff;
|
||||
if (attr2 != null) {
|
||||
if (attr2 !== null) {
|
||||
var fg2 = (attr2 >> 9) & 0x1ff;
|
||||
// 0, 7, 188, 231, 251
|
||||
if (fg === 0x1ff) {
|
||||
|
@ -171,7 +170,7 @@ exports.blend = function blend(attr, attr2, alpha) {
|
|||
fg = exports.mixColors(fg, fg2, alpha);
|
||||
}
|
||||
} else {
|
||||
if (blend._cache[fg] != null) {
|
||||
if (blend._cache[fg] !== null) {
|
||||
fg = blend._cache[fg];
|
||||
// } else if (fg < 8) {
|
||||
// fg += 8;
|
||||
|
@ -242,13 +241,7 @@ exports.xterm = [
|
|||
// Seed all 256 colors. Assume xterm defaults.
|
||||
// Ported from the xterm color generation script.
|
||||
exports.colors = (function() {
|
||||
var cols = exports.colors = []
|
||||
, _cols = exports.vcolors = []
|
||||
, r
|
||||
, g
|
||||
, b
|
||||
, i
|
||||
, l;
|
||||
var cols = exports.colors = [], _cols = exports.vcolors = [], r, g, b, i, l;
|
||||
|
||||
function hex(n) {
|
||||
n = n.toString(16);
|
||||
|
@ -293,9 +286,7 @@ exports.colors = (function() {
|
|||
// Map higher colors to the first 8 colors.
|
||||
// This allows translation of high colors to low colors on 8-color terminals.
|
||||
exports.ccolors = (function() {
|
||||
var _cols = exports.vcolors.slice()
|
||||
, cols = exports.colors.slice()
|
||||
, out;
|
||||
var _cols = exports.vcolors.slice(), cols = exports.colors.slice(), out;
|
||||
|
||||
exports.vcolors = exports.vcolors.slice(0, 8);
|
||||
exports.colors = exports.colors.slice(0, 8);
|
||||
|
@ -353,10 +344,9 @@ var colorNames = exports.colorNames = {
|
|||
|
||||
exports.convert = function(color) {
|
||||
if (typeof color === 'number') {
|
||||
;
|
||||
} else if (typeof color === 'string') {
|
||||
color = color.replace(/[\- ]/g, '');
|
||||
if (colorNames[color] != null) {
|
||||
if (colorNames[color] !== null) {
|
||||
color = colorNames[color];
|
||||
} else {
|
||||
color = exports.match(color);
|
||||
|
|
Loading…
Reference in New Issue