Add save svg-badge directly to gist

This adds the posibility of saving an SVG badge generated by the same
shields.io dirictly to the gist. Instead of prepering a JSON file to
be sent to their service, we use their library directly, which outputs
an SVG file that we can save to the user’s gist.

Filenames ending in `.svg` will use this library automatically.

Additionally there is a major refactoring where the older `node:http`
library has been swapped out for `fetch`.

Also swap from node 16 to node 20

fixes #24
This commit is contained in:
Rúnar Berg
2023-09-26 17:37:34 -07:00
parent b7809ee0af
commit a2d3829b14
63 changed files with 4632 additions and 137 deletions

1
node_modules/color-convert/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1 @@
language: node_js

4
node_modules/color-convert/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,4 @@
# 0.5.3 - 2015-06-02
- Fixed: hsl2hsv does not return `NaN` anymore when using `[0,0,0]`
([#15](https://github.com/harthur/color-convert/issues/15))

21
node_modules/color-convert/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
Copyright (c) 2011 Heather Arthur <fayearthur@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

57
node_modules/color-convert/README.md generated vendored Normal file
View File

@@ -0,0 +1,57 @@
# color-convert [![Build Status](https://travis-ci.org/harthur/color-convert.svg?branch=master)](https://travis-ci.org/harthur/color-convert)
Color-convert is a color conversion library for JavaScript and node. It converts all ways between `rgb`, `hsl`, `hsv`, `hwb`, `cmyk`, and CSS keywords:
```js
var converter = require("color-convert")();
converter.rgb(140, 200, 100).hsl() // [96, 48, 59]
converter.keyword("blue").rgb() // [0, 0, 255]
```
# Install
```console
npm install color-convert
```
# API
Color-convert exports a converter object with getter/setter methods for each color space. It caches conversions:
```js
var converter = require("color-convert")();
converter.rgb(140, 200, 100).hsl() // [96, 48, 59]
converter.rgb([140, 200, 100]) // args can be an array
```
### Plain functions
Get direct conversion functions with no fancy objects:
```js
require("color-convert").rgb2hsl([140, 200, 100]); // [96, 48, 59]
```
### Unrounded
To get the unrounded conversion, append `Raw` to the function name:
```js
convert.rgb2hslRaw([140, 200, 100]); // [95.99999999999999, 47.619047619047606, 58.82352941176471]
```
### Hash
There's also a hash of the conversion functions keyed first by the "from" color space, then by the "to" color space:
```js
convert["hsl"]["hsv"]([160, 0, 20]) == convert.hsl2hsv([160, 0, 20])
```
### Other spaces
There are some conversions from rgb (sRGB) to XYZ and LAB too, available as `rgb2xyz()`, `rgb2lab()`, `xyz2rgb()`, and `xyz2lab()`.
# Contribute
Please fork, add conversions, figure out color profile stuff for XYZ, LAB, etc. This is meant to be a basic library that can be used by other libraries to wrap color calculations in some cool way.

9
node_modules/color-convert/component.json generated vendored Normal file
View File

@@ -0,0 +1,9 @@
{
"name": "color-convert",
"description": "Plain color conversion functions",
"version": "0.5.3",
"author": "Heather Arthur <fayearthur@gmail.com>",
"repository": "harthur/color-convert",
"keywords": ["color", "colour", "rgb"],
"scripts": ["index.js", "conversions.js"]
}

698
node_modules/color-convert/conversions.js generated vendored Normal file
View File

@@ -0,0 +1,698 @@
/* MIT license */
module.exports = {
rgb2hsl: rgb2hsl,
rgb2hsv: rgb2hsv,
rgb2hwb: rgb2hwb,
rgb2cmyk: rgb2cmyk,
rgb2keyword: rgb2keyword,
rgb2xyz: rgb2xyz,
rgb2lab: rgb2lab,
rgb2lch: rgb2lch,
hsl2rgb: hsl2rgb,
hsl2hsv: hsl2hsv,
hsl2hwb: hsl2hwb,
hsl2cmyk: hsl2cmyk,
hsl2keyword: hsl2keyword,
hsv2rgb: hsv2rgb,
hsv2hsl: hsv2hsl,
hsv2hwb: hsv2hwb,
hsv2cmyk: hsv2cmyk,
hsv2keyword: hsv2keyword,
hwb2rgb: hwb2rgb,
hwb2hsl: hwb2hsl,
hwb2hsv: hwb2hsv,
hwb2cmyk: hwb2cmyk,
hwb2keyword: hwb2keyword,
cmyk2rgb: cmyk2rgb,
cmyk2hsl: cmyk2hsl,
cmyk2hsv: cmyk2hsv,
cmyk2hwb: cmyk2hwb,
cmyk2keyword: cmyk2keyword,
keyword2rgb: keyword2rgb,
keyword2hsl: keyword2hsl,
keyword2hsv: keyword2hsv,
keyword2hwb: keyword2hwb,
keyword2cmyk: keyword2cmyk,
keyword2lab: keyword2lab,
keyword2xyz: keyword2xyz,
xyz2rgb: xyz2rgb,
xyz2lab: xyz2lab,
xyz2lch: xyz2lch,
lab2xyz: lab2xyz,
lab2rgb: lab2rgb,
lab2lch: lab2lch,
lch2lab: lch2lab,
lch2xyz: lch2xyz,
lch2rgb: lch2rgb
}
function rgb2hsl(rgb) {
var r = rgb[0]/255,
g = rgb[1]/255,
b = rgb[2]/255,
min = Math.min(r, g, b),
max = Math.max(r, g, b),
delta = max - min,
h, s, l;
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;
h = Math.min(h * 60, 360);
if (h < 0)
h += 360;
l = (min + max) / 2;
if (max == min)
s = 0;
else if (l <= 0.5)
s = delta / (max + min);
else
s = delta / (2 - max - min);
return [h, s * 100, l * 100];
}
function rgb2hsv(rgb) {
var r = rgb[0],
g = rgb[1],
b = rgb[2],
min = Math.min(r, g, b),
max = Math.max(r, g, b),
delta = max - min,
h, s, v;
if (max == 0)
s = 0;
else
s = (delta/max * 1000)/10;
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;
h = Math.min(h * 60, 360);
if (h < 0)
h += 360;
v = ((max / 255) * 1000) / 10;
return [h, s, v];
}
function rgb2hwb(rgb) {
var r = rgb[0],
g = rgb[1],
b = rgb[2],
h = rgb2hsl(rgb)[0],
w = 1/255 * Math.min(r, Math.min(g, b)),
b = 1 - 1/255 * Math.max(r, Math.max(g, b));
return [h, w * 100, b * 100];
}
function rgb2cmyk(rgb) {
var r = rgb[0] / 255,
g = rgb[1] / 255,
b = rgb[2] / 255,
c, m, y, k;
k = Math.min(1 - r, 1 - g, 1 - b);
c = (1 - r - k) / (1 - k) || 0;
m = (1 - g - k) / (1 - k) || 0;
y = (1 - b - k) / (1 - k) || 0;
return [c * 100, m * 100, y * 100, k * 100];
}
function rgb2keyword(rgb) {
return reverseKeywords[JSON.stringify(rgb)];
}
function rgb2xyz(rgb) {
var r = rgb[0] / 255,
g = rgb[1] / 255,
b = rgb[2] / 255;
// assume sRGB
r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
return [x * 100, y *100, z * 100];
}
function rgb2lab(rgb) {
var xyz = rgb2xyz(rgb),
x = xyz[0],
y = xyz[1],
z = xyz[2],
l, a, b;
x /= 95.047;
y /= 100;
z /= 108.883;
x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
l = (116 * y) - 16;
a = 500 * (x - y);
b = 200 * (y - z);
return [l, a, b];
}
function rgb2lch(args) {
return lab2lch(rgb2lab(args));
}
function hsl2rgb(hsl) {
var h = hsl[0] / 360,
s = hsl[1] / 100,
l = hsl[2] / 100,
t1, t2, t3, rgb, val;
if (s == 0) {
val = l * 255;
return [val, val, val];
}
if (l < 0.5)
t2 = l * (1 + s);
else
t2 = l + s - l * s;
t1 = 2 * l - t2;
rgb = [0, 0, 0];
for (var i = 0; i < 3; i++) {
t3 = h + 1 / 3 * - (i - 1);
t3 < 0 && t3++;
t3 > 1 && t3--;
if (6 * t3 < 1)
val = t1 + (t2 - t1) * 6 * t3;
else if (2 * t3 < 1)
val = t2;
else if (3 * t3 < 2)
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
else
val = t1;
rgb[i] = val * 255;
}
return rgb;
}
function hsl2hsv(hsl) {
var h = hsl[0],
s = hsl[1] / 100,
l = hsl[2] / 100,
sv, v;
if(l === 0) {
// no need to do calc on black
// also avoids divide by 0 error
return [0, 0, 0];
}
l *= 2;
s *= (l <= 1) ? l : 2 - l;
v = (l + s) / 2;
sv = (2 * s) / (l + s);
return [h, sv * 100, v * 100];
}
function hsl2hwb(args) {
return rgb2hwb(hsl2rgb(args));
}
function hsl2cmyk(args) {
return rgb2cmyk(hsl2rgb(args));
}
function hsl2keyword(args) {
return rgb2keyword(hsl2rgb(args));
}
function hsv2rgb(hsv) {
var h = hsv[0] / 60,
s = hsv[1] / 100,
v = hsv[2] / 100,
hi = Math.floor(h) % 6;
var f = h - Math.floor(h),
p = 255 * v * (1 - s),
q = 255 * v * (1 - (s * f)),
t = 255 * v * (1 - (s * (1 - f))),
v = 255 * v;
switch(hi) {
case 0:
return [v, t, p];
case 1:
return [q, v, p];
case 2:
return [p, v, t];
case 3:
return [p, q, v];
case 4:
return [t, p, v];
case 5:
return [v, p, q];
}
}
function hsv2hsl(hsv) {
var h = hsv[0],
s = hsv[1] / 100,
v = hsv[2] / 100,
sl, l;
l = (2 - s) * v;
sl = s * v;
sl /= (l <= 1) ? l : 2 - l;
sl = sl || 0;
l /= 2;
return [h, sl * 100, l * 100];
}
function hsv2hwb(args) {
return rgb2hwb(hsv2rgb(args))
}
function hsv2cmyk(args) {
return rgb2cmyk(hsv2rgb(args));
}
function hsv2keyword(args) {
return rgb2keyword(hsv2rgb(args));
}
// http://dev.w3.org/csswg/css-color/#hwb-to-rgb
function hwb2rgb(hwb) {
var h = hwb[0] / 360,
wh = hwb[1] / 100,
bl = hwb[2] / 100,
ratio = wh + bl,
i, v, f, n;
// wh + bl cant be > 1
if (ratio > 1) {
wh /= ratio;
bl /= ratio;
}
i = Math.floor(6 * h);
v = 1 - bl;
f = 6 * h - i;
if ((i & 0x01) != 0) {
f = 1 - f;
}
n = wh + f * (v - wh); // linear interpolation
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;
}
return [r * 255, g * 255, b * 255];
}
function hwb2hsl(args) {
return rgb2hsl(hwb2rgb(args));
}
function hwb2hsv(args) {
return rgb2hsv(hwb2rgb(args));
}
function hwb2cmyk(args) {
return rgb2cmyk(hwb2rgb(args));
}
function hwb2keyword(args) {
return rgb2keyword(hwb2rgb(args));
}
function cmyk2rgb(cmyk) {
var c = cmyk[0] / 100,
m = cmyk[1] / 100,
y = cmyk[2] / 100,
k = cmyk[3] / 100,
r, g, b;
r = 1 - Math.min(1, c * (1 - k) + k);
g = 1 - Math.min(1, m * (1 - k) + k);
b = 1 - Math.min(1, y * (1 - k) + k);
return [r * 255, g * 255, b * 255];
}
function cmyk2hsl(args) {
return rgb2hsl(cmyk2rgb(args));
}
function cmyk2hsv(args) {
return rgb2hsv(cmyk2rgb(args));
}
function cmyk2hwb(args) {
return rgb2hwb(cmyk2rgb(args));
}
function cmyk2keyword(args) {
return rgb2keyword(cmyk2rgb(args));
}
function xyz2rgb(xyz) {
var x = xyz[0] / 100,
y = xyz[1] / 100,
z = xyz[2] / 100,
r, g, b;
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);
// assume sRGB
r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
: r = (r * 12.92);
g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
: g = (g * 12.92);
b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
: b = (b * 12.92);
r = Math.min(Math.max(0, r), 1);
g = Math.min(Math.max(0, g), 1);
b = Math.min(Math.max(0, b), 1);
return [r * 255, g * 255, b * 255];
}
function xyz2lab(xyz) {
var x = xyz[0],
y = xyz[1],
z = xyz[2],
l, a, b;
x /= 95.047;
y /= 100;
z /= 108.883;
x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
l = (116 * y) - 16;
a = 500 * (x - y);
b = 200 * (y - z);
return [l, a, b];
}
function xyz2lch(args) {
return lab2lch(xyz2lab(args));
}
function lab2xyz(lab) {
var l = lab[0],
a = lab[1],
b = lab[2],
x, y, z, y2;
if (l <= 8) {
y = (l * 100) / 903.3;
y2 = (7.787 * (y / 100)) + (16 / 116);
} else {
y = 100 * Math.pow((l + 16) / 116, 3);
y2 = Math.pow(y / 100, 1/3);
}
x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
return [x, y, z];
}
function lab2lch(lab) {
var l = lab[0],
a = lab[1],
b = lab[2],
hr, h, c;
hr = Math.atan2(b, a);
h = hr * 360 / 2 / Math.PI;
if (h < 0) {
h += 360;
}
c = Math.sqrt(a * a + b * b);
return [l, c, h];
}
function lab2rgb(args) {
return xyz2rgb(lab2xyz(args));
}
function lch2lab(lch) {
var l = lch[0],
c = lch[1],
h = lch[2],
a, b, hr;
hr = h / 360 * 2 * Math.PI;
a = c * Math.cos(hr);
b = c * Math.sin(hr);
return [l, a, b];
}
function lch2xyz(args) {
return lab2xyz(lch2lab(args));
}
function lch2rgb(args) {
return lab2rgb(lch2lab(args));
}
function keyword2rgb(keyword) {
return cssKeywords[keyword];
}
function keyword2hsl(args) {
return rgb2hsl(keyword2rgb(args));
}
function keyword2hsv(args) {
return rgb2hsv(keyword2rgb(args));
}
function keyword2hwb(args) {
return rgb2hwb(keyword2rgb(args));
}
function keyword2cmyk(args) {
return rgb2cmyk(keyword2rgb(args));
}
function keyword2lab(args) {
return rgb2lab(keyword2rgb(args));
}
function keyword2xyz(args) {
return rgb2xyz(keyword2rgb(args));
}
var cssKeywords = {
aliceblue: [240,248,255],
antiquewhite: [250,235,215],
aqua: [0,255,255],
aquamarine: [127,255,212],
azure: [240,255,255],
beige: [245,245,220],
bisque: [255,228,196],
black: [0,0,0],
blanchedalmond: [255,235,205],
blue: [0,0,255],
blueviolet: [138,43,226],
brown: [165,42,42],
burlywood: [222,184,135],
cadetblue: [95,158,160],
chartreuse: [127,255,0],
chocolate: [210,105,30],
coral: [255,127,80],
cornflowerblue: [100,149,237],
cornsilk: [255,248,220],
crimson: [220,20,60],
cyan: [0,255,255],
darkblue: [0,0,139],
darkcyan: [0,139,139],
darkgoldenrod: [184,134,11],
darkgray: [169,169,169],
darkgreen: [0,100,0],
darkgrey: [169,169,169],
darkkhaki: [189,183,107],
darkmagenta: [139,0,139],
darkolivegreen: [85,107,47],
darkorange: [255,140,0],
darkorchid: [153,50,204],
darkred: [139,0,0],
darksalmon: [233,150,122],
darkseagreen: [143,188,143],
darkslateblue: [72,61,139],
darkslategray: [47,79,79],
darkslategrey: [47,79,79],
darkturquoise: [0,206,209],
darkviolet: [148,0,211],
deeppink: [255,20,147],
deepskyblue: [0,191,255],
dimgray: [105,105,105],
dimgrey: [105,105,105],
dodgerblue: [30,144,255],
firebrick: [178,34,34],
floralwhite: [255,250,240],
forestgreen: [34,139,34],
fuchsia: [255,0,255],
gainsboro: [220,220,220],
ghostwhite: [248,248,255],
gold: [255,215,0],
goldenrod: [218,165,32],
gray: [128,128,128],
green: [0,128,0],
greenyellow: [173,255,47],
grey: [128,128,128],
honeydew: [240,255,240],
hotpink: [255,105,180],
indianred: [205,92,92],
indigo: [75,0,130],
ivory: [255,255,240],
khaki: [240,230,140],
lavender: [230,230,250],
lavenderblush: [255,240,245],
lawngreen: [124,252,0],
lemonchiffon: [255,250,205],
lightblue: [173,216,230],
lightcoral: [240,128,128],
lightcyan: [224,255,255],
lightgoldenrodyellow: [250,250,210],
lightgray: [211,211,211],
lightgreen: [144,238,144],
lightgrey: [211,211,211],
lightpink: [255,182,193],
lightsalmon: [255,160,122],
lightseagreen: [32,178,170],
lightskyblue: [135,206,250],
lightslategray: [119,136,153],
lightslategrey: [119,136,153],
lightsteelblue: [176,196,222],
lightyellow: [255,255,224],
lime: [0,255,0],
limegreen: [50,205,50],
linen: [250,240,230],
magenta: [255,0,255],
maroon: [128,0,0],
mediumaquamarine: [102,205,170],
mediumblue: [0,0,205],
mediumorchid: [186,85,211],
mediumpurple: [147,112,219],
mediumseagreen: [60,179,113],
mediumslateblue: [123,104,238],
mediumspringgreen: [0,250,154],
mediumturquoise: [72,209,204],
mediumvioletred: [199,21,133],
midnightblue: [25,25,112],
mintcream: [245,255,250],
mistyrose: [255,228,225],
moccasin: [255,228,181],
navajowhite: [255,222,173],
navy: [0,0,128],
oldlace: [253,245,230],
olive: [128,128,0],
olivedrab: [107,142,35],
orange: [255,165,0],
orangered: [255,69,0],
orchid: [218,112,214],
palegoldenrod: [238,232,170],
palegreen: [152,251,152],
paleturquoise: [175,238,238],
palevioletred: [219,112,147],
papayawhip: [255,239,213],
peachpuff: [255,218,185],
peru: [205,133,63],
pink: [255,192,203],
plum: [221,160,221],
powderblue: [176,224,230],
purple: [128,0,128],
rebeccapurple: [102, 51, 153],
red: [255,0,0],
rosybrown: [188,143,143],
royalblue: [65,105,225],
saddlebrown: [139,69,19],
salmon: [250,128,114],
sandybrown: [244,164,96],
seagreen: [46,139,87],
seashell: [255,245,238],
sienna: [160,82,45],
silver: [192,192,192],
skyblue: [135,206,235],
slateblue: [106,90,205],
slategray: [112,128,144],
slategrey: [112,128,144],
snow: [255,250,250],
springgreen: [0,255,127],
steelblue: [70,130,180],
tan: [210,180,140],
teal: [0,128,128],
thistle: [216,191,216],
tomato: [255,99,71],
turquoise: [64,224,208],
violet: [238,130,238],
wheat: [245,222,179],
white: [255,255,255],
whitesmoke: [245,245,245],
yellow: [255,255,0],
yellowgreen: [154,205,50]
};
var reverseKeywords = {};
for (var key in cssKeywords) {
reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
}

92
node_modules/color-convert/index.js generated vendored Normal file
View File

@@ -0,0 +1,92 @@
var conversions = require("./conversions");
var convert = function() {
return new Converter();
}
for (var func in conversions) {
// export Raw versions
convert[func + "Raw"] = (function(func) {
// accept array or plain args
return function(arg) {
if (typeof arg == "number")
arg = Array.prototype.slice.call(arguments);
return conversions[func](arg);
}
})(func);
var pair = /(\w+)2(\w+)/.exec(func),
from = pair[1],
to = pair[2];
// export rgb2hsl and ["rgb"]["hsl"]
convert[from] = convert[from] || {};
convert[from][to] = convert[func] = (function(func) {
return function(arg) {
if (typeof arg == "number")
arg = Array.prototype.slice.call(arguments);
var val = conversions[func](arg);
if (typeof val == "string" || val === undefined)
return val; // keyword
for (var i = 0; i < val.length; i++)
val[i] = Math.round(val[i]);
return val;
}
})(func);
}
/* Converter does lazy conversion and caching */
var Converter = function() {
this.convs = {};
};
/* Either get the values for a space or
set the values for a space, depending on args */
Converter.prototype.routeSpace = function(space, args) {
var values = args[0];
if (values === undefined) {
// color.rgb()
return this.getValues(space);
}
// color.rgb(10, 10, 10)
if (typeof values == "number") {
values = Array.prototype.slice.call(args);
}
return this.setValues(space, values);
};
/* Set the values for a space, invalidating cache */
Converter.prototype.setValues = function(space, values) {
this.space = space;
this.convs = {};
this.convs[space] = values;
return this;
};
/* Get the values for a space. If there's already
a conversion for the space, fetch it, otherwise
compute it */
Converter.prototype.getValues = function(space) {
var vals = this.convs[space];
if (!vals) {
var fspace = this.space,
from = this.convs[fspace];
vals = convert[fspace][space](from);
this.convs[space] = vals;
}
return vals;
};
["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function(space) {
Converter.prototype[space] = function(vals) {
return this.routeSpace(space, arguments);
}
});
module.exports = convert;

20
node_modules/color-convert/package.json generated vendored Normal file
View File

@@ -0,0 +1,20 @@
{
"name": "color-convert",
"description": "Plain color conversion functions",
"version": "0.5.3",
"author": "Heather Arthur <fayearthur@gmail.com>",
"repository": {
"type": "git",
"url": "http://github.com/harthur/color-convert.git"
},
"devDependencies": {
},
"scripts": {
"test": "node test/basic.js"
},
"keywords": [
"color",
"colour",
"rgb"
]
}

187
node_modules/color-convert/test/basic.js generated vendored Normal file
View File

@@ -0,0 +1,187 @@
var convert = require("../index"),
assert = require("assert");
assert.deepEqual(convert.rgb2hsl([140, 200, 100]), [96, 48, 59]);
assert.deepEqual(convert.rgb2hsv([140, 200, 100]), [96, 50, 78]);
assert.deepEqual(convert.rgb2hwb([140, 200, 100]), [96, 39, 22]);
assert.deepEqual(convert.rgb2cmyk([140, 200, 100]), [30, 0, 50, 22]);
assert.deepEqual(convert.rgb2cmyk([0,0,0,1]), [0,0,0,100]);
assert.deepEqual(convert.rgb2keyword([255, 228, 196]), "bisque");
assert.deepEqual(convert.rgb2xyz([92, 191, 84]), [25, 40, 15]);
assert.deepEqual(convert.rgb2lab([92, 191, 84]), [70, -50, 45]);
assert.deepEqual(convert.rgb2lch([92, 191, 84]), [70, 67, 138]);
assert.deepEqual(convert.hsl2rgb([96, 48, 59]), [140, 201, 100]);
assert.deepEqual(convert.hsl2hsv([96, 48, 59]), [96, 50, 79]); // colorpicker says [96,50,79]
assert.deepEqual(convert.hsl2hwb([96, 48, 59]), [96, 39, 21]); // computer round to 21, should be 22
assert.deepEqual(convert.hsl2cmyk([96, 48, 59]), [30, 0, 50, 21]);
assert.deepEqual(convert.hsl2keyword([240, 100, 50]), "blue");
assert.deepEqual(convert.hsv2rgb([96, 50, 78]), [139, 199, 99]);
assert.deepEqual(convert.hsv2hsl([96, 50, 78]), [96, 47, 59]);
assert.deepEqual(convert.hsv2hsl([0,0,0]), [0,0,0]);
assert.deepEqual(convert.hsv2hwb([96, 50, 78]), [96, 39, 22]);
assert.deepEqual(convert.hsv2cmyk([96, 50, 78]), [30, 0, 50, 22]);
assert.deepEqual(convert.hsv2keyword([240, 100, 100]), "blue");
assert.deepEqual(convert.cmyk2rgb([30, 0, 50, 22]), [139, 199, 99]);
assert.deepEqual(convert.cmyk2hsl([30, 0, 50, 22]), [96, 47, 59]);
assert.deepEqual(convert.cmyk2hsv([30, 0, 50, 22]), [96, 50, 78]);
assert.deepEqual(convert.cmyk2hwb([30, 0, 50, 22]), [96, 39, 22]);
assert.deepEqual(convert.cmyk2keyword([100, 100, 0, 0]), "blue");
assert.deepEqual(convert.keyword2rgb("blue"), [0, 0, 255]);
assert.deepEqual(convert.keyword2hsl("blue"), [240, 100, 50]);
assert.deepEqual(convert.keyword2hsv("blue"), [240, 100, 100]);
assert.deepEqual(convert.keyword2hwb("blue"), [240, 0, 0]);
assert.deepEqual(convert.keyword2cmyk("blue"), [100, 100, 0, 0]);
assert.deepEqual(convert.keyword2lab("blue"), [32, 79, -108]);
assert.deepEqual(convert.keyword2xyz("blue"), [18, 7, 95]);
assert.deepEqual(convert.xyz2rgb([25, 40, 15]), [97, 190, 85]);
assert.deepEqual(convert.xyz2rgb([50, 100, 100]), [0, 255, 241]);
assert.deepEqual(convert.xyz2lab([25, 40, 15]), [69, -48, 44]);
assert.deepEqual(convert.xyz2lch([25, 40, 15]), [69, 65, 137]);
assert.deepEqual(convert.lab2xyz([69, -48, 44]), [25, 39, 15]);
assert.deepEqual(convert.lab2rgb([75, 20, -30]), [194, 175, 240]);
assert.deepEqual(convert.lab2lch([69, -48, 44]), [69, 65, 137]);
assert.deepEqual(convert.lch2lab([69, 65, 137]), [69, -48, 44]);
assert.deepEqual(convert.lch2xyz([69, 65, 137]), [25, 39, 15]);
assert.deepEqual(convert.lch2rgb([69, 65, 137]), [98, 188, 83]);
// non-array arguments
assert.deepEqual(convert.hsl2rgb(96, 48, 59), [140, 201, 100]);
// raw functions
function round(vals) {
for (var i = 0; i < vals.length; i++)
vals[i] = vals[i].toFixed(1);
return vals;
}
assert.deepEqual(round(convert.hsl2rgbRaw([96, 48, 59])), [140.4, 200.6, 100.3]);
assert.deepEqual(round(convert.rgb2hslRaw([140, 200, 100])), [96, 47.6, 58.8]);
assert.deepEqual(round(convert.hsv2rgbRaw([96, 50, 78])), [139.2, 198.9, 99.5]);
assert.deepEqual(round(convert.rgb2hsvRaw([140, 200, 100])), [96, 50, 78.4]);
assert.deepEqual(round(convert.hwb2rgbRaw([96, 39, 22])), [139.2, 198.9, 99.5]);
assert.deepEqual(round(convert.rgb2hwbRaw([140, 200, 100])), [96, 39.2, 21.6]);
assert.deepEqual(round(convert.cmyk2rgbRaw([30, 0, 50, 22])), [139.2, 198.9, 99.5]);
assert.deepEqual(round(convert.rgb2cmykRaw([140, 200, 100])), [30, 0, 50, 21.6]);
assert.deepEqual(round(convert.keyword2rgbRaw("blue")), [0, 0, 255]);
assert.deepEqual(convert.rgb2keywordRaw([255, 228, 196]), "bisque");
assert.deepEqual(round(convert.hsv2hslRaw([96, 50, 78])), [96, 47, 58.5]);
assert.deepEqual(round(convert.hsl2hsvRaw([96, 48, 59])), [96, 50, 78.7]);
assert.deepEqual(round(convert.hsl2hsvRaw([96, 48, 59])), [96, 50, 78.7]);
assert.deepEqual(round(convert.xyz2rgbRaw([25, 40, 15])), [97.4, 189.9, 85]);
assert.deepEqual(round(convert.rgb2xyzRaw([92, 191, 84])), [24.6, 40.2, 14.8]);
assert.deepEqual(round(convert.rgb2labRaw([92, 191, 84])), [69.6, -50.1, 44.6]);
// hashed
var val = [140, 200, 100];
assert.deepEqual(convert["rgb"]["hsl"](val), convert.rgb2hsl(val));
assert.deepEqual(convert["rgb"]["hsv"](val), convert.rgb2hsv(val));
assert.deepEqual(convert["rgb"]["hwb"](val), convert.rgb2hwb(val));
assert.deepEqual(convert["rgb"]["cmyk"](val), convert.rgb2cmyk(val));
assert.deepEqual(convert["rgb"]["xyz"](val), convert.rgb2xyz(val));
assert.deepEqual(convert["rgb"]["lab"](val), convert.rgb2lab(val));
assert.deepEqual(convert["rgb"]["keyword"]([255, 228, 196]), "bisque");
val = [96, 48, 59];
assert.deepEqual(convert["hsl"]["rgb"](val), convert.hsl2rgb(val));
assert.deepEqual(convert["hsl"]["hsv"](val), convert.hsl2hsv(val));
assert.deepEqual(convert["hsl"]["hwb"](val), convert.hsl2hwb(val));
assert.deepEqual(convert["hsl"]["cmyk"](val), convert.hsl2cmyk(val));
assert.deepEqual(convert["hsl"]["keyword"](val), convert.hsl2keyword(val ));
val = [96, 50, 78];
assert.deepEqual(convert["hsv"]["rgb"](val), convert.hsv2rgb(val));
assert.deepEqual(convert["hsv"]["hsl"](val), convert.hsv2hsl(val));
assert.deepEqual(convert["hsv"]["hwb"](val), convert.hsv2hwb(val));
assert.deepEqual(convert["hsv"]["cmyk"](val), convert.hsv2cmyk(val));
assert.deepEqual(convert["hsv"]["keyword"](val), convert.hsv2keyword(val));
val = [30, 0, 50, 22];
assert.deepEqual(convert["cmyk"]["rgb"](val), convert.cmyk2rgb(val));
assert.deepEqual(convert["cmyk"]["hsl"](val), convert.cmyk2hsl(val));
assert.deepEqual(convert["cmyk"]["hsv"](val), convert.cmyk2hsv(val));
assert.deepEqual(convert["cmyk"]["hwb"](val), convert.cmyk2hwb(val));
assert.deepEqual(convert["cmyk"]["keyword"](val), convert.cmyk2keyword(val));
val = "blue";
assert.deepEqual(convert["keyword"]["rgb"](val), convert.keyword2rgb(val));
assert.deepEqual(convert["keyword"]["hsl"](val), convert.keyword2hsl(val));
assert.deepEqual(convert["keyword"]["hsv"](val), convert.keyword2hsv(val));
assert.deepEqual(convert["keyword"]["hwb"](val), convert.keyword2hwb(val));
assert.deepEqual(convert["keyword"]["cmyk"](val), convert.keyword2cmyk(val));
assert.deepEqual(convert["keyword"]["lab"](val), convert.keyword2lab(val));
assert.deepEqual(convert["keyword"]["xyz"](val), convert.keyword2xyz(val));
val = [25, 40, 15]
assert.deepEqual(convert["xyz"]["rgb"](val), convert.xyz2rgb(val));
assert.deepEqual(convert["xyz"]["lab"](val), convert.xyz2lab(val));
val = [69, -48, 44];
assert.deepEqual(convert["lab"]["xyz"](val), [25, 39, 15]);
// converter
var converter = convert();
var vals = [140, 200, 100];
converter.rgb(140, 200, 100);
assert.deepEqual(converter.hsl(), convert.rgb2hsl(vals));
assert.deepEqual(converter.hsv(), convert.rgb2hsv(vals));
assert.deepEqual(converter.cmyk(), convert.rgb2cmyk(vals));
assert.deepEqual(converter.rgb(), vals);
assert.deepEqual(converter.rgb([255, 228, 196]).keyword(), "bisque");
vals = [96, 48, 59];
converter.hsl(vals);
assert.deepEqual(converter.rgb(), convert.hsl2rgb(vals));
assert.deepEqual(converter.hsv(), convert.hsl2hsv(vals));
assert.deepEqual(converter.cmyk(), convert.hsl2cmyk(vals));
assert.deepEqual(converter.keyword(), convert.hsl2keyword(vals));
// hwb
// http://dev.w3.org/csswg/css-color/#hwb-examples
// all extrem value should give black, white or grey
for(var angle = 0; angle <= 360; angle ++) {
assert.deepEqual(convert.hwb2rgb([angle, 0, 100]), [0, 0, 0]);
assert.deepEqual(convert.hwb2rgb([angle, 100, 0]), [255, 255, 255]);
assert.deepEqual(convert.hwb2rgb([angle, 100, 100]), [128, 128, 128]);
}
assert.deepEqual(convert.hwb2rgb([0, 0, 0]), [255,0,0]);
assert.deepEqual(convert.hwb2rgb([0, 20, 40]), [153, 51, 51]);
assert.deepEqual(convert.hwb2rgb([0, 40, 40]), [153, 102, 102]);
assert.deepEqual(convert.hwb2rgb([0, 40, 20]), [204, 102, 102]);
assert.deepEqual(convert.hwb2rgb([120, 0, 0]), [0,255,0]);
assert.deepEqual(convert.hwb2rgb([120, 20, 40]), [51, 153, 51]);
assert.deepEqual(convert.hwb2rgb([120, 40, 40]), [102, 153, 102]);
assert.deepEqual(convert.hwb2rgb([120, 40, 20]), [102, 204, 102]);
assert.deepEqual(convert.hwb2rgb([240, 0, 0]), [0,0,255]);
assert.deepEqual(convert.hwb2rgb([240, 20, 40]), [51, 51, 153]);
assert.deepEqual(convert.hwb2rgb([240, 40, 40]), [102, 102, 153]);
assert.deepEqual(convert.hwb2rgb([240, 40, 20]), [102, 102, 204]);
// black should always stay black
val = [0, 0, 0];
assert.deepEqual(convert.hsl2hsv(val), val);
assert.deepEqual(convert.hsl2rgb(val), val);
assert.deepEqual(convert.hsl2hwb(val), [0, 0, 100]);
assert.deepEqual(convert.hsl2cmyk(val), [0, 0, 0, 100]);

23
node_modules/color-convert/test/speed.js generated vendored Normal file
View File

@@ -0,0 +1,23 @@
var convert = require("../index");
var converter = convert();
var times = 10000;
console.time("cached");
converter.rgb(10, 2, 30);
for(var i = 0; i < times; i++) {
converter.hsv();
converter.hsl();
converter.cmyk();
}
console.timeEnd("cached");
console.time("uncached");
for(var i = 0; i < times; i++) {
convert.rgb2hsl(10, 2, 30);
convert.rgb2hsv(10, 2, 30);
convert.rgb2cmyk(10, 2, 30);
}
console.timeEnd("uncached");