Socket
Socket
Sign inDemoInstall

color-space

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-space - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

dist/color-space.js

0

ciecam.js

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

52

hsl.js

@@ -19,3 +19,3 @@ /**

if (s == 0) {
if (s === 0) {
val = l * 255;

@@ -25,6 +25,8 @@ return [val, val, val];

if (l < 0.5)
if (l < 0.5) {
t2 = l * (1 + s);
else
}
else {
t2 = l + s - l * s;
}
t1 = 2 * l - t2;

@@ -35,13 +37,21 @@

t3 = h + 1 / 3 * - (i - 1);
t3 < 0 && t3++;
t3 > 1 && t3--;
if (t3 < 0) {
t3++;
}
else if (t3 > 1) {
t3--;
}
if (6 * t3 < 1)
if (6 * t3 < 1) {
val = t1 + (t2 - t1) * 6 * t3;
else if (2 * t3 < 1)
}
else if (2 * t3 < 1) {
val = t2;
else if (3 * t3 < 2)
}
else if (3 * t3 < 2) {
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
else
}
else {
val = t1;
}

@@ -66,26 +76,34 @@ rgb[i] = val * 255;

if (max == min)
if (max === min) {
h = 0;
else if (r == max)
}
else if (r === max) {
h = (g - b) / delta;
else if (g == max)
}
else if (g === max) {
h = 2 + (b - r) / delta;
else if (b == max)
}
else if (b === max) {
h = 4 + (r - g)/ delta;
}
h = Math.min(h * 60, 360);
if (h < 0)
if (h < 0) {
h += 360;
}
l = (min + max) / 2;
if (max == min)
if (max === min) {
s = 0;
else if (l <= 0.5)
}
else if (l <= 0.5) {
s = delta / (max + min);
else
}
else {
s = delta / (2 - max - min);
}
return [h, s * 100, l * 100];
};

@@ -24,4 +24,4 @@ /**

q = 255 * v * (1 - (s * f)),
t = 255 * v * (1 - (s * (1 - f))),
v = 255 * v;
t = 255 * v * (1 - (s * (1 - f)));
v *= 255;

@@ -55,2 +55,3 @@ switch(hi) {

l /= 2;
return [h, sl * 100, l * 100];

@@ -71,20 +72,27 @@ }

if (max === 0)
if (max === 0) {
s = 0;
else
}
else {
s = (delta/max * 1000)/10;
}
if (max == min)
if (max === min) {
h = 0;
else if (r == max)
}
else if (r === max) {
h = (g - b) / delta;
else if (g == max)
}
else if (g === max) {
h = 2 + (b - r) / delta;
else if (b == max)
}
else if (b === max) {
h = 4 + (r - g) / delta;
}
h = Math.min(h * 60, 360);
if (h < 0)
if (h < 0) {
h += 360;
}

@@ -108,3 +116,4 @@ v = ((max / 255) * 1000) / 10;

sv = (2 * s) / (l + s) || 0;
return [h, sv * 100, v * 100];
};

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -19,6 +19,6 @@ /**

var h = hwb[0] / 360,
wh = hwb[1] / 100,
bl = hwb[2] / 100,
ratio = wh + bl,
i, v, f, n;
wh = hwb[1] / 100,
bl = hwb[2] / 100,
ratio = wh + bl,
i, v, f, n;

@@ -36,5 +36,8 @@ var r, g, b;

f = 6 * h - i;
if ((i & 0x01) != 0) {
//if it is even
if ((i & 0x01) !== 0) {
f = 1 - f;
}
n = wh + f * (v - wh); // linear interpolation

@@ -89,3 +92,4 @@

h = rgb.hsl(val)[0],
w = 1/255 * Math.min(r, Math.min(g, b)),
w = 1/255 * Math.min(r, Math.min(g, b));
b = 1 - 1/255 * Math.max(r, Math.max(g, b));

@@ -92,0 +96,0 @@

/**
* @module color-space
*
* @todo to-source method, preparing the code for webworker
* @todo implement all side spaces from http://en.wikipedia.org/wiki/Category:Color_space yuv, yiq etc.
* @todo here are additional spaces http://www.jentronics.com/color.html ITU, REC709, SMTPE, NTSC, GREY
*
* @todo implement asm-js way to convert spaces (promises to be times faster)
*
*/
var addConvertor = require('./add-convertor');
var addConvertor = require('./util/add-convertor');

@@ -27,32 +32,3 @@

/**
* Add a new space to the set
*/
Object.defineProperty(spaces, 'add', {
value: function (space) {
var spaceName = space.name;
//ignore existing space
if (this[spaceName]) return;
//add convertors to every existing space
var otherSpace;
for (var otherSpaceName in this) {
otherSpace = this[otherSpaceName];
addConvertor(space, otherSpace);
addConvertor(otherSpace, space);
}
//save a new space
this[spaceName] = space;
return space;
}
});
//you can add other spaces manually
//via `spaces.add(require('color-space/ciecam'))`
//build absent convertors from each to every space

@@ -59,0 +35,0 @@ var fromSpace, toSpace;

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -7,3 +7,3 @@ /**

*
* @todo xyz→lms
* @todo xyz -> lms
* @todo tests

@@ -26,25 +26,25 @@ *

rlab: [
.38971, .68898, -.07868,
-.22981, 1.18340, .04641,
.00000, .00000, 1.00000],
0.38971, 0.68898,-0.07868,
-0.22981, 1.18340, 0.04641,
0.00000, 0.00000, 1.00000],
rlabD65: [
.4002, .7076, -.0808,
-.2263, 1.1653, .0457,
.00000, .00000, .9182],
0.4002, 0.7076, -0.0808,
-0.2263, 1.1653, 0.0457,
0.00000,0.00000, 0.9182],
cmccat97: [
.8951, .2664, -.1614,
-.7502, 1.7135, .0367,
.0389, -.0686, 1.0296],
0.8951, 0.2664,-0.1614,
-0.7502, 1.7135, 0.0367,
0.0389,-0.0686, 1.0296],
cat97: [
.8562, .3372, -.1934,
-.8360, 1.8327, .0033,
.0357, -.00469, 1.0112],
0.8562, 0.3372,-0.1934,
-0.8360, 1.8327, 0.0033,
0.0357,-0.00469,1.0112],
cat00: [
.7982, .3389, -.1371,
-.5918, 1.5512, .0406,
.0008, .0239, .9753],
0.7982, 0.3389,-0.1371,
-0.5918, 1.5512, 0.0406,
0.0008, 0.0239, 0.9753],
cat02: [
.7328, .4296, -.1624,
-.7036, 1.6975, .0061,
.0030, .0136, .9834]
0.7328, 0.4296,-0.1624,
-0.7036, 1.6975, 0.0061,
0.0030, 0.0136, 0.9834]
},

@@ -54,5 +54,7 @@

xyz: function(arg, m){
x = arg[0], y = arg[1], z = arg[2];
var x = arg[0], y = arg[1], z = arg[2];
if (!m) m = lms.transform[cat02];
if (!m) {
m = lms.transform[cat02];
}

@@ -59,0 +61,0 @@ return [

@@ -0,0 +0,0 @@ /**

{
"name": "color-space",
"description": "Math & data behind color spaces and color conversions.",
"version": "1.0.4",
"description": "Convert color from/to any color space or get space data. Spaces can be required selectively.",
"version": "1.1.0",
"author": "Deema Yvanow <dfcreative@gmail.com>",

@@ -29,3 +29,4 @@ "repository": {

"ciecam.js",
"add-convertor.js"
"util",
"dist"
],

@@ -51,2 +52,3 @@ "main": "./index.js",

"luv",
"lch",
"cie",

@@ -63,5 +65,5 @@ "husl",

"test": "mocha",
"build": "browserify --standalone colorSpace ./index.js > color-space.js",
"min": "ccjs color-space.js --language_in=ECMASCRIPT5 > color-space.min.js && cat color-space.min.js | gzip-size | pretty-bytes",
"build-test": "browserify -r ./index:../index -r ./xyy:../xyy -r ./labh:../labh -r ./cmy:../cmy -r husl -r assert -r mumath -r query-relative > test/test.bundle.js"
"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",
"build-test": "browserify -r ./util/add-space:../util/add-space -r ./index:../index -r ./xyy:../xyy -r ./labh:../labh -r ./cmy:../cmy -r husl -r assert -r mumath -r query-relative > test/test.bundle.js"
},

@@ -68,0 +70,0 @@ "dependencies": {

@@ -1,39 +0,55 @@

# Color-space [![Build Status](https://travis-ci.org/dfcreative/color-space.svg?branch=master)](https://travis-ci.org/dfcreative/color-space)
# Color-space [![Build Status](https://travis-ci.org/dfcreative/color-space.svg?branch=master)](https://travis-ci.org/dfcreative/color-space) [![Code Climate](https://codeclimate.com/github/dfcreative/color-space/badges/gpa.svg)](https://codeclimate.com/github/dfcreative/color-space) <a href="http://unlicense.org/UNLICENSE"><img src="http://upload.wikimedia.org/wikipedia/commons/6/62/PD-icon.svg" width="20"/></a>
[![NPM](https://nodei.co/npm/color-space.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/color-space/)
<img src="https://raw.githubusercontent.com/dfcreative/color-space/gh-pages/logo.png" width="100%" height="150"/>
Math and data behind color spaces and color conversions. _Color-space_ provides a uniform interface to the following color spaces: RGB, HSl, HSV (HSB), [HWB](http://dev.w3.org/csswg/css-color/#the-hwb-notation), CMYK, CMY, [XYZ](http://en.wikipedia.org/wiki/CIE_1931_color_space), XYY (YXY), [LAB](http://en.wikipedia.org/wiki/Lab_color_space), LCH<sub>ab</sub>, [LUV](http://en.wikipedia.org/wiki/CIELUV), [LCH<sub>uv</sub>](http://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation), [H<sub>u</sub>SL](http://www.boronine.com/husl/), [H<sub>u</sub>SL<sub>p</sub>](http://www.boronine.com/husl/), [LAB<sub>Hunter</sub>](http://en.wikipedia.org/wiki/Lab_color_space#Hunter_Lab), [LMS](http://en.wikipedia.org/wiki/LMS_color_space).
_Color-space_ provides conversions and data for the following color spaces: RGB, HSl, HSV (HSB), [HWB](http://dev.w3.org/csswg/css-color/#the-hwb-notation), CMYK, CMY, [XYZ](http://en.wikipedia.org/wiki/CIE_1931_color_space), XYY (YXY), [LAB](http://en.wikipedia.org/wiki/Lab_color_space), LCH<sub>ab</sub>, [LUV](http://en.wikipedia.org/wiki/CIELUV), [LCH<sub>uv</sub>](http://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation), [H<sub>u</sub>SL](http://www.boronine.com/husl/), [H<sub>u</sub>SL<sub>p</sub>](http://www.boronine.com/husl/), [LAB<sub>Hunter</sub>](http://en.wikipedia.org/wiki/Lab_color_space#Hunter_Lab), [LMS](http://en.wikipedia.org/wiki/LMS_color_space).
#### [Converter & tests](https://cdn.rawgit.com/dfcreative/color-space/master/test/index.html)
* _Color-space_ has the most complete list of color convertions so far, comparing to [color-convert](https://github.com/harthur/color-convert), [chromatist](https://github.com/jrus/chromatist), [spectra](https://github.com/avp/spectra), [colorspaces.js](https://github.com/boronine/colorspaces.js) and others.
* It can be used both in browser and node.
* Each space can be required selectively.
#### [Color converter & tests](https://cdn.rawgit.com/dfcreative/color-space/master/test/index.html)
# Use
## In browser:
### In browser:
Attach `color-space.js` and use global `colorSpace` object:
Include [color-space.js](https://raw.githubusercontent.com/dfcreative/color-space/master/dist/color-space.js) or [color-space.min.js](https://raw.githubusercontent.com/dfcreative/color-space/master/dist/color-space.min.js) on the page (before you’ll use it):
```html
<script src="js/color-space.js"></script>
<script src="path-to/color-space.js"></script>
```
```js
var rgb = colorSpace.rgb;
Alternately you can include a [CDN version](https://cdn.rawgit.com/dfcreative/color-space/master/dist/color-space.min.js):
//convert rgb to hsl
rgb.hsl([255,0,0]);
```html
<script src="https://cdn.rawgit.com/dfcreative/color-space/master/dist/color-space.min.js"></script>
```
Also you can use [browserify](https://github.com/substack/node-browserify) to get your own build.
Now you have a `window.colorSpace` object, so you can play around with it:
```html
<script>
var rgb = colorSpace.rgb;
## In node:
//convert rgb to hsl
var hslColor = rgb.hsl([255,0,0]);
</script>
```
`$ npm install color-space`
If you aware of final size, you can get your own build via [browserify](https://github.com/substack/node-browserify), including only needed target spaces. See how to include spaces separately below.
Include all spaces:
### In node:
First install color-space as a local module:
`$ npm install --save color-space`
Then include `color-space`:
```js

@@ -43,8 +59,7 @@ var colorSpace = require('color-space');

//convert lab to lch
colorSpace.lab.lch([80,50,60]);
var result = colorSpace.lab.lch([80,50,60]);
```
Each space can also be required separately as `require('color-space/<space>')`:
Include only needed spaces (to get a subset or to shrink final size):
```js

@@ -58,21 +73,23 @@ var rgb = require('color-space/rgb');

Note that in case of requiring specific spaces you might need to add absent conversions via `color-space/util/add-convertor`.
# API
Convert one space to another:
API of color-space is straightforward.
You can convert one space to another:
```js
var fromSpace = 'rgb', toSpace = 'hsl';
colorSpace[fromSpace][toSpace](array);
<fromSpace>.<toSpace>(array);
```
Space data:
Also you can get space data:
```js
space.name //space name
space.min //channel minimums
space.max //channel maximums
space.channel //channel names
space.alias //alias space names, if any
<space>.name //space name
<space>.min //channel minimums
<space>.max //channel maximums
<space>.channel //channel names
<space>.alias //alias space names, if any
xyz.whitepoint //list of whitepoint references

@@ -82,10 +99,8 @@ lms.transform //list of transform matrices

For other details see source code or `console.log(space)`.
# Contribute
Please fork, add color space with basic conversions (to/from XYZ or RGB), tests. _Color-space_ is supposed to be a basic library to work with color conversions, an enhanced replacement for [color-convert](https://github.com/harthur/color-convert).
Please fork, add color space with basic conversions to/from XYZ or RGB and tests. _Color-space_ is supposed to be a basic library to work with color conversions, an enhanced replacement for [color-convert](https://github.com/harthur/color-convert).
<a href="http://unlicense.org/UNLICENSE"><img src="http://upload.wikimedia.org/wikipedia/commons/6/62/PD-icon.svg" width="40"/></a>
[![NPM](https://nodei.co/npm/color-space.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/color-space/)

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc