color-space
Advanced tools
Comparing version 1.16.0 to 2.0.0
@@ -8,8 +8,6 @@ /** | ||
*/ | ||
'use strict' | ||
import xyz from './xyz.js'; | ||
var xyz = require('./xyz'); | ||
var cam = module.exports = { | ||
var cam = { | ||
name: 'cam', | ||
@@ -30,1 +28,4 @@ | ||
} | ||
export default cam; |
/** | ||
* @module color-space/cmy | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
var cmy = module.exports = { | ||
var cmy = { | ||
name: 'cmy', | ||
@@ -55,1 +53,3 @@ min: [0,0,0], | ||
}; | ||
export default cmy |
/** | ||
* @module color-space/cmyk | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
module.exports = { | ||
const cmyk = { | ||
name: 'cmyk', | ||
@@ -43,1 +41,3 @@ min: [0,0,0,0], | ||
}; | ||
export default cmyk |
@@ -9,8 +9,6 @@ | ||
*/ | ||
'use strict' | ||
import xyy from './xyy.js'; | ||
import xyz from './xyz.js'; | ||
var xyy = require('./xyy'); | ||
var xyz = require('./xyz'); | ||
/** | ||
@@ -278,3 +276,3 @@ * Main color space object | ||
module.exports = coloroid; | ||
export default coloroid; | ||
@@ -281,0 +279,0 @@ |
@@ -6,9 +6,7 @@ /** | ||
*/ | ||
'use strict' | ||
var rgb = require('./rgb'); | ||
var clamp = require('mumath/clamp'); | ||
import rgb from './rgb.js'; | ||
var cubehelix = module.exports = { | ||
var cubehelix = { | ||
name: 'cubehelix', | ||
@@ -62,5 +60,5 @@ channel: ['fraction'], | ||
r = clamp(r, 0, 1); | ||
g = clamp(g, 0, 1); | ||
b = clamp(b, 0, 1); | ||
r = Math.max(1, Math.min(r, 0)); | ||
g = Math.max(1, Math.min(g, 0)); | ||
b = Math.max(1, Math.min(b, 0)); | ||
@@ -81,1 +79,4 @@ return [r * 255, g * 255, b * 255]; | ||
}; | ||
export default cubehelix; |
21
hcg.js
/** | ||
* @module color-space/hcg | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
import hsl from './hsl.js'; | ||
import hsv from './hsv.js'; | ||
import hwb from './hwb.js'; | ||
var rgb = require('./rgb'); | ||
var hsl = require('./hsl'); | ||
var hsv = require('./hsv'); | ||
var hwb = require('./hwb'); | ||
var mod = require('mumath/mod'); | ||
module.exports = { | ||
export default { | ||
name: 'hcg', | ||
@@ -27,4 +24,4 @@ min: [0,0,0], | ||
} | ||
var hi = mod(h, 1) * 6; | ||
var v = mod(hi, 1); | ||
var hi = (h % 1) * 6; | ||
var v = (hi % 1); | ||
var pure = [0, 0, 0]; | ||
@@ -110,3 +107,3 @@ var w = 1 - v; | ||
if (max === r) { | ||
hue = mod((g - b) / chroma, 6); | ||
hue = ((g - b) / chroma % 6); | ||
} else | ||
@@ -119,3 +116,3 @@ if (max === g) { | ||
hue /= 6; | ||
hue = mod(hue, 1); | ||
hue = (hue % 1); | ||
} else { | ||
@@ -122,0 +119,0 @@ hue = 0; |
18
hcy.js
@@ -7,11 +7,5 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
var loop = require('mumath/mod'); | ||
var clamp = require('mumath/clamp'); | ||
var hcy = module.exports = { | ||
var hcy = { | ||
name: 'hcy', | ||
@@ -24,3 +18,5 @@ min: [0,0,0], | ||
export default hcy; | ||
/** | ||
@@ -34,5 +30,5 @@ * HCY to RGB | ||
hcy.rgb = function (hcy) { | ||
var h = loop(hcy[0], 0, 360) * Math.PI / 180; | ||
var s = clamp(hcy[1], 0, 100) / 100; | ||
var i = clamp(hcy[2], 0, 255) / 255; | ||
var h = (hcy[0] < 0 ? (hcy[0] % 360) + 360 : (hcy[0] % 360)) * Math.PI / 180; | ||
var s = Math.max(0, Math.min(hcy[1], 100)) / 100; | ||
var i = Math.max(0, Math.min(hcy[2], 255)) / 255; | ||
@@ -39,0 +35,0 @@ var pi3 = Math.PI / 3; |
11
hpluv.js
@@ -7,9 +7,7 @@ /** | ||
*/ | ||
'use strict' | ||
import xyz from './xyz.js'; | ||
import lchuv from './lchuv.js'; | ||
import hsluv, {_hsluv} from './hsluv.js'; | ||
var xyz = require('./xyz'); | ||
var lchuv = require('./lchuv'); | ||
var _hsluv = require('hsluv'); | ||
module.exports = { | ||
export default { | ||
name: 'hpluv', | ||
@@ -28,3 +26,2 @@ min: [0,0,0], | ||
} | ||
}; | ||
@@ -31,0 +28,0 @@ |
18
hsi.js
@@ -7,11 +7,5 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
var loop = require('mumath/mod'); | ||
var clamp = require('mumath/clamp'); | ||
var hsi = module.exports = { | ||
var hsi = { | ||
name: 'hsi', | ||
@@ -24,3 +18,5 @@ min: [0,0,0], | ||
export default hsi | ||
/** | ||
@@ -34,5 +30,5 @@ * HSI to RGB | ||
hsi.rgb = function (hsi) { | ||
var h = loop(hsi[0], 0, 360) * Math.PI / 180; | ||
var s = clamp(hsi[1], 0, 100) / 100; | ||
var i = clamp(hsi[2], 0, 255) / 255; | ||
var h = (hsi[0] < 0 ? (hsi[0] % 360) + 360 : (hsi[0] % 360)) * Math.PI / 180; | ||
var s = Math.max(0, Math.min(hsi[1], 100)) / 100; | ||
var i = Math.max(0, Math.min(hsi[2], 255)) / 255; | ||
@@ -39,0 +35,0 @@ var pi3 = Math.PI / 3; |
/** | ||
* @module color-space/hsl | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
module.exports = { | ||
export default { | ||
name: 'hsl', | ||
@@ -10,0 +8,0 @@ min: [0,0,0], |
43
hsluv.js
@@ -7,10 +7,36 @@ /** | ||
*/ | ||
'use strict' | ||
import xyz from './xyz.js'; | ||
import lchuv from './lchuv.js'; | ||
import rgb from './rgb.js'; | ||
var xyz = require('./xyz'); | ||
var lchuv = require('./lchuv'); | ||
var _hsluv = require('hsluv'); | ||
// unwrapped https://github.com/hsluv/hsluv/blob/master/javascript/dist/hsluv-0.1.0.min.js | ||
// FIXME: it has redundant functions like rgbToXyz - can be reused from color-space itself | ||
function f(a){var c=[],b=Math.pow(a+16,3)/1560896;b=b>g?b:a/k;for(var d=0;3>d;){var e=d++,h=l[e][0],w=l[e][1];e=l[e][2];for(var x=0;2>x;){var y=x++,z=(632260*e-126452*w)*b+126452*y;c.push({b:(284517*h-94839*e)*b/z,a:((838422*e+769860*w+731718*h)*a*b-769860*y*a)/z})}}return c}function m(a){a=f(a);for(var c=Infinity,b=0;b<a.length;){var d=a[b];++b;c=Math.min(c,Math.abs(d.a)/Math.sqrt(Math.pow(d.b,2)+1))}return c} | ||
function n(a,c){c=c/360*Math.PI*2;a=f(a);for(var b=Infinity,d=0;d<a.length;){var e=a[d];++d;e=e.a/(Math.sin(c)-e.b*Math.cos(c));0<=e&&(b=Math.min(b,e))}return b}function p(a,c){for(var b=0,d=0,e=a.length;d<e;){var h=d++;b+=a[h]*c[h]}return b}function q(a){return.0031308>=a?12.92*a:1.055*Math.pow(a,.4166666666666667)-.055}function r(a){return.04045<a?Math.pow((a+.055)/1.055,2.4):a/12.92}function t(a){return[q(p(l[0],a)),q(p(l[1],a)),q(p(l[2],a))]} | ||
function u(a){a=[r(a[0]),r(a[1]),r(a[2])];return[p(v[0],a),p(v[1],a),p(v[2],a)]}function A(a){var c=a[0],b=a[1];a=c+15*b+3*a[2];0!=a?(c=4*c/a,a=9*b/a):a=c=NaN;b=b<=g?b/B*k:116*Math.pow(b/B,.3333333333333333)-16;return 0==b?[0,0,0]:[b,13*b*(c-C),13*b*(a-D)]}function E(a){var c=a[0];if(0==c)return[0,0,0];var b=a[1]/(13*c)+C;a=a[2]/(13*c)+D;c=8>=c?B*c/k:B*Math.pow((c+16)/116,3);b=0-9*c*b/((b-4)*a-b*a);return[b,c,(9*c-15*a*c-a*b)/(3*a)]} | ||
function F(a){var c=a[0],b=a[1],d=a[2];a=Math.sqrt(b*b+d*d);1E-8>a?b=0:(b=180*Math.atan2(d,b)/Math.PI,0>b&&(b=360+b));return[c,a,b]}function G(a){var c=a[1],b=a[2]/360*2*Math.PI;return[a[0],Math.cos(b)*c,Math.sin(b)*c]}function H(a){var c=a[0],b=a[1];a=a[2];if(99.9999999<a)return[100,0,c];if(1E-8>a)return[0,0,c];b=n(a,c)/100*b;return[a,b,c]}function I(a){var c=a[0],b=a[1];a=a[2];if(99.9999999<c)return[a,0,100];if(1E-8>c)return[a,0,0];var d=n(c,a);return[a,b/d*100,c]} | ||
function J(a){var c=a[0],b=a[1];a=a[2];if(99.9999999<a)return[100,0,c];if(1E-8>a)return[0,0,c];b=m(a)/100*b;return[a,b,c]}function K(a){var c=a[0],b=a[1];a=a[2];if(99.9999999<c)return[a,0,100];if(1E-8>c)return[a,0,0];var d=m(c);return[a,b/d*100,c]}function L(a){for(var c="#",b=0;3>b;){var d=b++;d=Math.round(255*a[d]);var e=d%16;c+=M.charAt((d-e)/16|0)+M.charAt(e)}return c} | ||
function N(a){a=a.toLowerCase();for(var c=[],b=0;3>b;){var d=b++;c.push((16*M.indexOf(a.charAt(2*d+1))+M.indexOf(a.charAt(2*d+2)))/255)}return c}function O(a){return t(E(G(a)))}function P(a){return F(A(u(a)))}function Q(a){return O(H(a))}function R(a){return I(P(a))}function S(a){return O(J(a))}function T(a){return K(P(a))} | ||
var l=[[3.240969941904521,-1.537383177570093,-.498610760293],[-.96924363628087,1.87596750150772,.041555057407175],[.055630079696993,-.20397695888897,1.056971514242878]],v=[[.41239079926595,.35758433938387,.18048078840183],[.21263900587151,.71516867876775,.072192315360733],[.019330818715591,.11919477979462,.95053215224966]],B=1,C=.19783000664283,D=.46831999493879,k=903.2962962,g=.0088564516,M="0123456789abcdef"; | ||
export const _hsluv = { | ||
hsluvToRgb:Q, | ||
hsluvToLch:H, | ||
rgbToHsluv:R, | ||
rgbToHpluv:T, | ||
rgbToXyz:u, | ||
rgbToLch:P, | ||
hpluvToRgb:S, | ||
hpluvToLch:J, | ||
lchToHpluv:K, | ||
lchToHsluv:I, | ||
lchToLuv:G, | ||
lchToRgb:O, | ||
luvToLch:F, | ||
luvToXyz:E, | ||
xyzToLuv:A, | ||
xyzToRgb:t, | ||
}; | ||
module.exports = { | ||
export default { | ||
name: 'hsluv', | ||
@@ -31,3 +57,6 @@ min: [0,0,0], | ||
return _hsluv.lchToHpluv( _hsluv.hsluvToLch(arg)); | ||
} | ||
}, | ||
// export internal math | ||
_hsluv | ||
}; | ||
@@ -40,1 +69,3 @@ | ||
}; | ||
rgb.hsluv = _hsluv.rgbToHsluv |
/** | ||
* @module color-space/hsp | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js' | ||
var rgb = require('./rgb'), | ||
Pr = 0.299, | ||
const Pr = 0.299, | ||
Pg = 0.587, | ||
Pb = 0.114; | ||
module.exports = { | ||
export default { | ||
name: 'hsp', | ||
@@ -13,0 +12,0 @@ min: [0, 0, 0], |
/** | ||
* @module color-space/hsv | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
import hsl from './hsl.js'; | ||
var rgb = require('./rgb'); | ||
var hsl = require('./hsl'); | ||
module.exports = { | ||
export default { | ||
name: 'hsv', | ||
@@ -11,0 +9,0 @@ min: [0,0,0], |
12
hwb.js
/** | ||
* @module color-space/hwb | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
import hsv from './hsv.js'; | ||
import hsl from './hsl.js'; | ||
var rgb = require('./rgb'); | ||
var hsv = require('./hsv'); | ||
var hsl = require('./hsl'); | ||
var hwb = module.exports = { | ||
var hwb = { | ||
name: 'hwb', | ||
@@ -85,3 +83,5 @@ min: [0,0,0], | ||
export default hwb; | ||
//extend rgb | ||
@@ -88,0 +88,0 @@ rgb.hwb = function(val) { |
125
index.js
@@ -7,83 +7,64 @@ /** | ||
*/ | ||
'use strict'; | ||
import rgb from './rgb.js' | ||
import hsl from './hsl.js' | ||
import hsv from './hsv.js' | ||
import hsi from './hsi.js' | ||
import hwb from './hwb.js' | ||
import cmyk from './cmyk.js' | ||
import cmy from './cmy.js' | ||
import xyz from './xyz.js' | ||
import xyy from './xyy.js' | ||
import yiq from './yiq.js' | ||
import yuv from './yuv.js' | ||
import ydbdr from './ydbdr.js' | ||
import ycgco from './ycgco.js' | ||
import ypbpr from './ypbpr.js' | ||
import ycbcr from './ycbcr.js' | ||
import xvycc from './xvycc.js' | ||
import yccbccrc from './yccbccrc.js' | ||
import ucs from './ucs.js' | ||
import uvw from './uvw.js' | ||
import jpeg from './jpeg.js' | ||
import lab from './lab.js' | ||
import labh from './labh.js' | ||
import lms from './lms.js' | ||
import lchab from './lchab.js' | ||
import luv from './luv.js' | ||
import lchuv from './lchuv.js' | ||
import hsluv from './hsluv.js' | ||
import hpluv from './hpluv.js' | ||
import cubehelix from './cubehelix.js' | ||
import coloroid from './coloroid.js' | ||
import hcg from './hcg.js' | ||
import hcy from './hcy.js' | ||
import tsl from './tsl.js' | ||
import yes from './yes.js' | ||
import osaucs from './osaucs.js' | ||
import hsp from './hsp.js' | ||
const spaces = {}; | ||
export default spaces; | ||
/** Exported spaces */ | ||
var spaces = { | ||
rgb: require('./rgb'), | ||
hsl: require('./hsl'), | ||
hsv: require('./hsv'), | ||
hsi: require('./hsi'), | ||
hwb: require('./hwb'), | ||
cmyk: require('./cmyk'), | ||
cmy: require('./cmy'), | ||
xyz: require('./xyz'), | ||
xyy: require('./xyy'), | ||
yiq: require('./yiq'), | ||
yuv: require('./yuv'), | ||
ydbdr: require('./ydbdr'), | ||
ycgco: require('./ycgco'), | ||
ypbpr: require('./ypbpr'), | ||
ycbcr: require('./ycbcr'), | ||
xvycc: require('./xvycc'), | ||
yccbccrc: require('./yccbccrc'), | ||
ucs: require('./ucs'), | ||
uvw: require('./uvw'), | ||
jpeg: require('./jpeg'), | ||
lab: require('./lab'), | ||
labh: require('./labh'), | ||
lms: require('./lms'), | ||
lchab: require('./lchab'), | ||
luv: require('./luv'), | ||
lchuv: require('./lchuv'), | ||
hsluv: require('./hsluv'), | ||
hpluv: require('./hpluv'), | ||
cubehelix: require('./cubehelix'), | ||
coloroid: require('./coloroid'), | ||
hcg: require('./hcg'), | ||
hcy: require('./hcy'), | ||
tsl: require('./tsl'), | ||
yes: require('./yes'), | ||
osaucs: require('./osaucs'), | ||
hsp: require('./hsp') | ||
}; | ||
export function register (newSpace) { | ||
const newSpaceName = newSpace.name | ||
for (var existingSpaceName in spaces) { | ||
if (!newSpace[existingSpaceName]) newSpace[existingSpaceName] = createConverter(newSpace, existingSpaceName); | ||
//build absent convertors from each to every space | ||
var fromSpace; | ||
for (var fromSpaceName in spaces) { | ||
fromSpace = spaces[fromSpaceName]; | ||
for (var toSpaceName in spaces) { | ||
if (!fromSpace[toSpaceName]) fromSpace[toSpaceName] = getConvertor(fromSpaceName, toSpaceName); | ||
const existingSpace = spaces[existingSpaceName] | ||
if (!existingSpace[newSpaceName]) existingSpace[newSpaceName] = createConverter(existingSpace, newSpaceName); | ||
} | ||
spaces[newSpaceName] = newSpace | ||
} | ||
function createConverter (fromSpace, toSpaceName) { | ||
//create xyz converter, if available | ||
if (fromSpace.xyz && spaces.xyz[toSpaceName]) | ||
return (arg) => spaces.xyz[toSpaceName](fromSpace.xyz(arg)); | ||
/** return converter through xyz/rgb space */ | ||
function getConvertor(fromSpaceName, toSpaceName){ | ||
var fromSpace = spaces[fromSpaceName]; | ||
//create straight converter | ||
if (fromSpaceName === toSpaceName) { | ||
return function (a) { | ||
return a; | ||
}; | ||
} | ||
//create xyz converter, if available | ||
else if (fromSpace.xyz && spaces.xyz[toSpaceName]) { | ||
return function(arg){ | ||
return spaces.xyz[toSpaceName](fromSpace.xyz(arg)); | ||
}; | ||
} | ||
//create rgb converter | ||
else if (fromSpace.rgb && spaces.rgb[toSpaceName]) { | ||
return function(arg){ | ||
return spaces.rgb[toSpaceName](fromSpace.rgb(arg)); | ||
}; | ||
} | ||
if (fromSpace.rgb && spaces.rgb[toSpaceName]) | ||
return (arg) => spaces.rgb[toSpaceName](fromSpace.rgb(arg)); | ||
} | ||
module.exports = spaces; | ||
// register all spaces by default | ||
[rgb, xyz, hsl, hsv, hsi, hwb, cmyk, cmy, xyy, yiq, yuv, ydbdr, ycgco, ypbpr, ycbcr, xvycc, yccbccrc, ucs, uvw, jpeg, lab, labh, lms, lchab, luv, lchuv, hsluv, hpluv, cubehelix, coloroid, hcg, hcy, tsl, yes, osaucs, hsp].map(register) |
@@ -8,7 +8,5 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
var jpeg = module.exports = { | ||
var jpeg = { | ||
name: 'jpeg', | ||
@@ -21,3 +19,5 @@ min: [0, 0, 0], | ||
export default jpeg; | ||
/** | ||
@@ -24,0 +24,0 @@ * JPEG to RGB |
@@ -6,7 +6,6 @@ /** | ||
*/ | ||
'use strict' | ||
var xyz = require('./xyz'); | ||
import xyz from './xyz.js'; | ||
module.exports = { | ||
export default { | ||
name: 'lab', | ||
@@ -13,0 +12,0 @@ min: [0,-100,-100], |
12
labh.js
@@ -6,7 +6,6 @@ /** | ||
*/ | ||
'use strict' | ||
var xyz = require('./xyz'); | ||
import xyz from './xyz.js'; | ||
module.exports = { | ||
export default { | ||
name: 'labh', | ||
@@ -40,7 +39,8 @@ | ||
var x = xyz[0], y = xyz[1], z = xyz[2]; | ||
var l = 10 * Math.sqrt( y ); | ||
var a = y === 0 ? 0 : 17.5 * ((( 1.02 * x ) - y ) / Math.sqrt( y ) ); | ||
var b = y === 0 ? 0 : 7 * ( ( y - ( 0.847 * z ) ) / Math.sqrt( y ) ); | ||
var _y12 = Math.sqrt(y); | ||
var l = 10 * _y12; | ||
var a = y === 0 ? 0 : 17.5 * ((( 1.02 * x ) - y ) / _y12 ); | ||
var b = y === 0 ? 0 : 7 * ( ( y - ( 0.847 * z ) ) / _y12 ); | ||
return [l, a, b]; | ||
}; |
11
lchab.js
@@ -6,10 +6,8 @@ /** | ||
*/ | ||
'use strict' | ||
import xyz from './xyz.js'; | ||
import lab from './lab.js'; | ||
var xyz = require('./xyz'); | ||
var lab = require('./lab'); | ||
//cylindrical lab | ||
var lchab = module.exports = { | ||
var lchab = { | ||
name: 'lchab', | ||
@@ -58,1 +56,4 @@ min: [0,0,0], | ||
}; | ||
export default lchab; |
10
lchuv.js
@@ -6,9 +6,7 @@ /** | ||
*/ | ||
'use strict' | ||
import luv from './luv.js'; | ||
import xyz from './xyz.js'; | ||
var luv = require('./luv'); | ||
var xyz = require('./xyz'); | ||
//cylindrical luv | ||
var lchuv = module.exports = { | ||
var lchuv = { | ||
name: 'lchuv', | ||
@@ -37,2 +35,4 @@ channel: ['lightness', 'chroma', 'hue'], | ||
export default lchuv; | ||
luv.lchuv = function(luv){ | ||
@@ -39,0 +39,0 @@ var l = luv[0], u = luv[1], v = luv[2]; |
@@ -13,7 +13,5 @@ /** | ||
*/ | ||
'use strict' | ||
import xyz from './xyz.js'; | ||
var xyz = require('./xyz'); | ||
var lms = module.exports = { | ||
var lms = { | ||
name: 'lms', | ||
@@ -54,2 +52,3 @@ min: [0,0,0], | ||
export default lms; | ||
@@ -56,0 +55,0 @@ lms.xyz = function(arg, matrix){ |
@@ -6,7 +6,5 @@ /** | ||
*/ | ||
'use strict' | ||
import xyz from './xyz.js'; | ||
var xyz = require('./xyz'); | ||
module.exports = { | ||
export default { | ||
name: 'luv', | ||
@@ -13,0 +11,0 @@ //NOTE: luv has no rigidly defined limits |
/** | ||
* @module color-space/munsell | ||
*/ | ||
'use strict' | ||
var munsell = { | ||
@@ -31,2 +29,2 @@ name: 'munsell', | ||
module.exports = munsell; | ||
export default munsell; |
@@ -6,5 +6,4 @@ /** | ||
*/ | ||
'use strict' | ||
var xyz = require('./xyz'); | ||
import xyz from './xyz.js'; | ||
@@ -78,2 +77,2 @@ | ||
module.exports = osaucs; | ||
export default osaucs; |
{ | ||
"name": "color-space", | ||
"description": "Color space conversions and data", | ||
"version": "1.16.0", | ||
"author": "Deema Yvanow <dfcreative@gmail.com>", | ||
"description": "Collection of color space conversions", | ||
"version": "2.0.0", | ||
"author": "Dmitry Ivanov <df.creative@gmail.com>", | ||
"type": "module", | ||
"keywords": [ | ||
@@ -41,19 +42,13 @@ "color", | ||
"main": "./index.js", | ||
"dependencies": { | ||
"hsluv": "^0.0.3", | ||
"mumath": "^3.3.4" | ||
}, | ||
"devDependencies": { | ||
"almost-equal": "^1.1.0", | ||
"closurecompiler": "^1.x", | ||
"gzip-size": "^3.0.0", | ||
"mocha": "latest", | ||
"queried": "^1.4.1" | ||
"rollup": "^2.66.0", | ||
"terser": "^5.10.0", | ||
"uvu": "^0.5.3" | ||
}, | ||
"scripts": { | ||
"test": "mocha", | ||
"build": "browserify --standalone colorSpace ./index.js > dist/color-space.js", | ||
"min": "ccjs dist/color-space.js --language_in=ECMASCRIPT5 > dist/color-space.min.js && cat dist/color-space.min.js | gzip-size | pretty-bytes", | ||
"watch": "watchify -r ./index:../index -r hsluv -r assert -r mumath -r queried -d -o test/bundle.js" | ||
"test": "node test", | ||
"build": "rollup ./index.js --file dist/color-space.js --format esm", | ||
"minify": "terser ./dist/color-space.js -o ./dist/color-space.min.js --module -c passes=3 -m" | ||
} | ||
} |
112
README.md
@@ -1,14 +0,14 @@ | ||
# Color-space [![Build Status](https://travis-ci.org/colorjs/color-space.svg?branch=master)](https://travis-ci.org/colorjs/color-space) [![stable](https://img.shields.io/badge/stability-stable-brightgreen.svg)](http://github.com/badges/stability-badges) [![OpenCollective](https://opencollective.com/color-space/backers/badge.svg)](#backers) [![OpenCollective](https://opencollective.com/color-space/sponsors/badge.svg)](#sponsors) | ||
# Color-space [![test](https://github.com/colorjs/color-space/actions/workflows/test.yml/badge.svg)](https://github.com/colorjs/color-space/actions/workflows/test.yml) [![stable](https://img.shields.io/badge/stability-stable-brightgreen.svg)](http://github.com/badges/stability-badges) [![npm](https://img.shields.io/npm/v/color-space)](https://npmjs.org/color-space) [![size](https://img.shields.io/bundlephobia/minzip/color-space/latest)](https://bundlephobia.com/package/color-space) | ||
<img src="https://raw.githubusercontent.com/colorjs/color-space/gh-pages/logo.png" width="100%" height="150"/> | ||
Conversions and data for color spaces. [Demo](http://colorjs.github.io/color-space). | ||
Collection of color spaces conversions & data. | ||
[Demo](http://colorjs.github.io/color-space). | ||
## Usage | ||
[![npm install color-space](https://nodei.co/npm/color-space.png?mini=true)](https://npmjs.org/package/color-space/) | ||
```js | ||
var space = require('color-space'); | ||
import space from 'color-space'; | ||
@@ -19,7 +19,7 @@ //convert lab to lch | ||
You can require a separate space to reduce size significantly: | ||
Spaces can be imported separately: | ||
```js | ||
var rgb = require('color-space/rgb'); | ||
var hsl = require('color-space/hsl'); | ||
import rgb from 'color-space/rgb.js'; | ||
import hsl from 'color-space/hsl.js'; | ||
@@ -29,7 +29,12 @@ //convert rgb to hsl | ||
``` | ||
<!-- | ||
New space can be registered as: | ||
```js | ||
import space, {register} from 'color-space'; | ||
register(spaceDefiniton) | ||
``` --> | ||
## API | ||
```js | ||
@@ -103,3 +108,3 @@ <fromSpace>.<toSpace>(array); | ||
Please fork, add color space with basic _conversions_ to/from XYZ or RGB and _tests_. | ||
The goal of project is to provide the most complete set of color spaces with maximally minimal uniform API. | ||
The goal of the project is the most complete set of color spaces with minimal uniform API. | ||
@@ -109,87 +114,7 @@ | ||
Thanks to all the color scientists, who devoted their lives to color research and delivered their knowledge to us, for now we can trust them and use their formulas and their code. | ||
Thanks to all scientists, who devoted their time to color research and conveyed their knowledge, for now we can use their formulas and code. | ||
### Backers | ||
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/color-space#backer)] | ||
## Alternatives | ||
<a href="https://opencollective.com/color-space/backer/0/website" target="_blank"><img src="https://opencollective.com/color-space/backer/0/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/1/website" target="_blank"><img src="https://opencollective.com/color-space/backer/1/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/2/website" target="_blank"><img src="https://opencollective.com/color-space/backer/2/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/3/website" target="_blank"><img src="https://opencollective.com/color-space/backer/3/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/4/website" target="_blank"><img src="https://opencollective.com/color-space/backer/4/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/5/website" target="_blank"><img src="https://opencollective.com/color-space/backer/5/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/6/website" target="_blank"><img src="https://opencollective.com/color-space/backer/6/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/7/website" target="_blank"><img src="https://opencollective.com/color-space/backer/7/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/8/website" target="_blank"><img src="https://opencollective.com/color-space/backer/8/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/9/website" target="_blank"><img src="https://opencollective.com/color-space/backer/9/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/10/website" target="_blank"><img src="https://opencollective.com/color-space/backer/10/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/11/website" target="_blank"><img src="https://opencollective.com/color-space/backer/11/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/12/website" target="_blank"><img src="https://opencollective.com/color-space/backer/12/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/13/website" target="_blank"><img src="https://opencollective.com/color-space/backer/13/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/14/website" target="_blank"><img src="https://opencollective.com/color-space/backer/14/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/15/website" target="_blank"><img src="https://opencollective.com/color-space/backer/15/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/16/website" target="_blank"><img src="https://opencollective.com/color-space/backer/16/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/17/website" target="_blank"><img src="https://opencollective.com/color-space/backer/17/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/18/website" target="_blank"><img src="https://opencollective.com/color-space/backer/18/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/19/website" target="_blank"><img src="https://opencollective.com/color-space/backer/19/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/20/website" target="_blank"><img src="https://opencollective.com/color-space/backer/20/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/21/website" target="_blank"><img src="https://opencollective.com/color-space/backer/21/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/22/website" target="_blank"><img src="https://opencollective.com/color-space/backer/22/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/23/website" target="_blank"><img src="https://opencollective.com/color-space/backer/23/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/24/website" target="_blank"><img src="https://opencollective.com/color-space/backer/24/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/25/website" target="_blank"><img src="https://opencollective.com/color-space/backer/25/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/26/website" target="_blank"><img src="https://opencollective.com/color-space/backer/26/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/27/website" target="_blank"><img src="https://opencollective.com/color-space/backer/27/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/28/website" target="_blank"><img src="https://opencollective.com/color-space/backer/28/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/backer/29/website" target="_blank"><img src="https://opencollective.com/color-space/backer/29/avatar.svg"></a> | ||
### Sponsors | ||
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/color-space#sponsor)] | ||
<a href="https://opencollective.com/color-space/sponsor/0/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/0/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/1/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/1/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/2/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/2/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/3/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/3/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/4/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/4/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/5/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/5/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/6/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/6/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/7/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/7/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/8/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/8/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/9/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/9/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/10/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/10/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/11/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/11/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/12/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/12/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/13/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/13/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/14/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/14/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/15/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/15/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/16/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/16/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/17/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/17/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/18/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/18/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/19/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/19/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/20/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/20/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/21/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/21/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/22/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/22/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/23/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/23/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/24/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/24/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/25/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/25/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/26/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/26/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/27/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/27/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/28/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/28/avatar.svg"></a> | ||
<a href="https://opencollective.com/color-space/sponsor/29/website" target="_blank"><img src="https://opencollective.com/color-space/sponsor/29/avatar.svg"></a> | ||
## Related | ||
* [colormap](https://github.com/bpostlethwaite/colormap) — collection of colormaps to map colors of images/data. A replacement for visualising spaces like cubehelix. | ||
* [color-spectrum](https://www.npmjs.com/package/color-spectrum) — convert spectrum to a color. | ||
* [color-interpolate](https://www.npmjs.com/package/color-interpolate) — interpolate between color values. | ||
* [color-tool](https://www.npmjs.com/package/color-tool) — color picker based on color-space. | ||
## Similar projects | ||
* [color-convert](https://github.com/harthur/color-convert) | ||
@@ -200,1 +125,4 @@ * [chromatist](https://github.com/jrus/chromatist) | ||
## See also | ||
* [color-api](https://github.com/LeaVerou/color-api) - color API proposal by Lea Verou |
@@ -6,5 +6,4 @@ /** | ||
*/ | ||
'use strict' | ||
module.exports = { | ||
export default { | ||
name: 'rgb', | ||
@@ -11,0 +10,0 @@ min: [0,0,0], |
@@ -9,7 +9,5 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
var tsl = module.exports = { | ||
var tsl = { | ||
name: 'tsl', | ||
@@ -21,2 +19,3 @@ min: [0,0,0], | ||
export default tsl; | ||
@@ -23,0 +22,0 @@ /** |
@@ -8,7 +8,5 @@ /** | ||
*/ | ||
'use strict' | ||
import xyz from './xyz.js'; | ||
var xyz = require('./xyz'); | ||
var ucs = module.exports = { | ||
var ucs = { | ||
name: 'ucs', | ||
@@ -21,2 +19,3 @@ min: [0,0,0], | ||
export default ucs; | ||
@@ -23,0 +22,0 @@ /** |
@@ -8,8 +8,6 @@ /** | ||
*/ | ||
'use strict' | ||
import ucs from './ucs.js'; | ||
import xyz from './xyz.js'; | ||
var ucs = require('./ucs'); | ||
var xyz = require('./xyz'); | ||
var uvw = module.exports = { | ||
var uvw = { | ||
name: 'uvw', | ||
@@ -22,2 +20,3 @@ min: [-134, -140, 0], | ||
export default uvw; | ||
@@ -24,0 +23,0 @@ /** |
@@ -18,8 +18,6 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
import ypbpr from './ypbpr.js'; | ||
var rgb = require('./rgb'); | ||
var ypbpr = require('./ypbpr'); | ||
var xvycc = module.exports = { | ||
var xvycc = { | ||
name: 'xvycc', | ||
@@ -32,2 +30,3 @@ min: [0, 0, 0], | ||
export default xvycc; | ||
@@ -34,0 +33,0 @@ /** |
@@ -6,6 +6,4 @@ /** | ||
*/ | ||
'use strict' | ||
import xyz from './xyz.js'; | ||
var xyz = require('./xyz'); | ||
var xyy = { | ||
@@ -40,2 +38,2 @@ name: 'xyy', | ||
module.exports = xyy; | ||
export default xyy; |
@@ -6,6 +6,4 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
var xyz = { | ||
@@ -145,2 +143,2 @@ name: 'xyz', | ||
module.exports = xyz; | ||
export default xyz; |
11
ycbcr.js
@@ -9,8 +9,6 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js' | ||
import ypbpr from './ypbpr.js' | ||
var rgb = require('./rgb'); | ||
var ypbpr = require('./ypbpr'); | ||
var ycbcr = module.exports = { | ||
var ycbcr = { | ||
name: 'ycbcr', | ||
@@ -80,1 +78,4 @@ min: [16, 16, 16], | ||
}; | ||
export default ycbcr; |
@@ -6,8 +6,6 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
import ypbpr from './ypbpr.js'; | ||
var rgb = require('./rgb'); | ||
var ypbpr = require('./ypbpr'); | ||
var yccbccrc = module.exports = { | ||
var yccbccrc = { | ||
name: 'yccbccrc', | ||
@@ -43,1 +41,4 @@ min: [0, -0.5, -0.5], | ||
}; | ||
export default yccbccrc; |
@@ -6,7 +6,5 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
var ycgco = module.exports = { | ||
var ycgco = { | ||
name: 'ycgco', | ||
@@ -58,1 +56,4 @@ min: [0, -0.5, -0.5], | ||
}; | ||
export default ycgco; |
10
ydbdr.js
@@ -6,8 +6,7 @@ /** | ||
*/ | ||
'use strict' | ||
var rgb = require('./rgb'); | ||
var yuv = require('./yuv'); | ||
import rgb from './rgb.js'; | ||
import yuv from './yuv.js'; | ||
var ydbdr = module.exports = { | ||
var ydbdr = { | ||
name: 'ydbdr', | ||
@@ -73,1 +72,4 @@ min: [0,-1.333,-1.333], | ||
}; | ||
export default ydbdr; |
@@ -7,7 +7,6 @@ /** | ||
*/ | ||
'use strict' | ||
var rgb = require('./rgb'); | ||
import rgb from './rgb.js'; | ||
var yes = module.exports = { | ||
var yes = { | ||
name: 'yes', | ||
@@ -51,1 +50,4 @@ min: [0,0,0], | ||
}; | ||
export default yes; |
@@ -6,7 +6,5 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
var yiq = module.exports = { | ||
var yiq = { | ||
name: 'yiq', | ||
@@ -52,1 +50,4 @@ min: [0,-0.5957,-0.5226], | ||
}; | ||
export default yiq; |
@@ -11,7 +11,5 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
var ypbpr = module.exports = { | ||
var ypbpr = { | ||
name: 'ypbpr', | ||
@@ -67,1 +65,4 @@ min: [0,-0.5,-0.5], | ||
}; | ||
export default ypbpr; |
10
yuv.js
@@ -6,7 +6,5 @@ /** | ||
*/ | ||
'use strict' | ||
import rgb from './rgb.js'; | ||
var rgb = require('./rgb'); | ||
var yuv = module.exports = { | ||
var yuv = { | ||
name: 'yuv', | ||
@@ -17,3 +15,2 @@ min: [0,-0.5,-0.5], | ||
alias: ['YUV', 'EBU'], | ||
}; | ||
@@ -51,1 +48,4 @@ | ||
}; | ||
export default yuv; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
167585
0
4
44
4835
Yes
124
1
- Removedhsluv@^0.0.3
- Removedmumath@^3.3.4
- Removedalmost-equal@1.1.0(transitive)
- Removedhsluv@0.0.3(transitive)
- Removedmumath@3.3.4(transitive)