1 | 'use strict';
|
2 |
|
3 | var push = Array.prototype.push, reduce = Array.prototype.reduce, abs = Math.abs
|
4 | , colors, match, result, i;
|
5 |
|
6 | colors = require('./xterm-colors').map(function (color) {
|
7 | return {
|
8 | r: parseInt(color.slice(0, 2), 16),
|
9 | g: parseInt(color.slice(2, 4), 16),
|
10 | b: parseInt(color.slice(4), 16)
|
11 | };
|
12 | });
|
13 |
|
14 | match = colors.slice(0, 16);
|
15 |
|
16 | module.exports = result = [];
|
17 |
|
18 | i = 0;
|
19 | while (i < 8) {
|
20 | result.push(30 + i++);
|
21 | }
|
22 | i = 0;
|
23 | while (i < 8) {
|
24 | result.push(90 + i++);
|
25 | }
|
26 | push.apply(result, colors.slice(16).map(function (data) {
|
27 | var index, diff = Infinity;
|
28 | match.every(function (match, i) {
|
29 | var ndiff = reduce.call('rgb', function (diff, channel) {
|
30 | diff += abs(match[channel] - data[channel]);
|
31 | return diff;
|
32 | }, 0);
|
33 | if (ndiff < diff) {
|
34 | index = i;
|
35 | diff = ndiff;
|
36 | }
|
37 | return ndiff;
|
38 | });
|
39 | return result[index];
|
40 | }));
|