Comparing version 0.1.0 to 0.1.1
67
color.js
@@ -36,14 +36,21 @@ /* MIT license */ | ||
var maxes = { | ||
"rgb": [255, 255, 255], | ||
"hsl": [360, 100, 100], | ||
"hsv": [360, 100, 100], | ||
"cmyk": [100, 100, 100, 100], | ||
} | ||
var alpha; | ||
if (vals.length) { | ||
// [10, 10, 10] | ||
values[space] = vals.slice(0, space.length); | ||
values.alpha = vals[space.length]; | ||
alpha = vals[space.length]; | ||
} | ||
else if (vals[space[0]] !== undefined) { | ||
// {r: 10, g: 10, b: 10} | ||
values[space] = []; | ||
for (var i = 0; i < space.length; i++) { | ||
values[space].push(vals[space[i]]); | ||
values[space][i] = vals[space[i]]; | ||
} | ||
values.alpha = vals.a; | ||
alpha = vals.a; | ||
} | ||
@@ -53,15 +60,18 @@ else if (vals[spaces[space][0]] !== undefined) { | ||
var chans = spaces[space]; | ||
values[space] = []; | ||
for (var i = 0; i < space.length; i++) { | ||
values[space].push(vals[chans[i]]); | ||
values[space][i] = vals[chans[i]]; | ||
} | ||
values.alpha = vals.alpha; | ||
alpha = vals.alpha; | ||
} | ||
values.alpha = values.alpha || 1; | ||
values.alpha = alpha || values.alpha || 1; | ||
// convert to all the other color spaces | ||
for (var spaceName in spaces) { | ||
if (spaceName != space) { | ||
values[spaceName] = convert[space][spaceName](values[space]) | ||
for (var sname in spaces) { | ||
if (sname != space) { | ||
values[sname] = convert[space][sname](values[space]) | ||
} | ||
// cap values | ||
for (var i = 0; i < sname.length; i++) { | ||
values[sname][i] = Math.min(maxes[sname][i], values[sname][i]); | ||
} | ||
} | ||
@@ -135,6 +145,14 @@ } | ||
rgbArray: function() { return values.rgb; }, | ||
hslArray: function() { return values.hsl; }, | ||
hsvArray: function() { return values.hsv; }, | ||
cmykArray: function() { return values.cmyk; }, | ||
rgbArray: function() { | ||
return values.rgb; | ||
}, | ||
hslArray: function() { | ||
return values.hsl; | ||
}, | ||
hsvArray: function() { | ||
return values.hsv; | ||
}, | ||
cmykArray: function() { | ||
return values.cmyk; | ||
}, | ||
@@ -159,4 +177,3 @@ alpha: function(val) { | ||
hue: function(val) { | ||
setChannel("hsl", 0, val); | ||
return setChannel("hsv", 0, val); | ||
return setChannel("hsl", 0, val); | ||
}, | ||
@@ -191,23 +208,17 @@ saturation: function(val) { | ||
}, | ||
rgbString: function() { | ||
return string.rgbString(values.rgb, values.alpha); | ||
}, | ||
rgbaString: function() { | ||
return string.rgbaString(values.rgb, values.alpha); | ||
}, | ||
percentString: function() { | ||
return string.percentString(values.rgb, values.alpha); | ||
}, | ||
hslString: function() { | ||
return string.hslString(values.hsl, values.alpha); | ||
}, | ||
hslaString: function() { | ||
return string.hslaString(values.hsl, values.alpha); | ||
}, | ||
keyword: function() { | ||
@@ -245,3 +256,13 @@ return string.keyword(values.rgb, values.alpha); | ||
}, | ||
clearer: function(ratio) { | ||
values.alpha -= values.alpha * ratio; | ||
return color; | ||
}, | ||
opaquer: function(ratio) { | ||
values.alpha += values.alpha * ratio; | ||
return color; | ||
}, | ||
toJSON: function() { | ||
@@ -248,0 +269,0 @@ return rgb(); |
{ | ||
"name": "color", | ||
"description": "Color conversion and manipulation with CSS string support", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"author": "Heather Arthur <fayearthur@gmail.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -1,3 +0,3 @@ | ||
# css-color | ||
css-color is a library for color conversion and manipulation with support for CSS color strings. | ||
# color | ||
`color` is a library for color conversion and manipulation with support for CSS color strings. | ||
@@ -14,3 +14,6 @@ ```javascript | ||
#### node | ||
### browser | ||
Download the latest [color.js](http://github.com/harthur/color/downloads). The `Color` object is exported. | ||
### node | ||
For [node](http://nodejs.org) with [npm](http://npmjs.org): | ||
@@ -20,6 +23,4 @@ | ||
#### browser | ||
Download the latest [color.js](http://github.com/harthur/color/downloads). The `Color` object is exported. | ||
And use with `var Color = require("color")` | ||
# API | ||
@@ -77,7 +78,16 @@ | ||
```javascript | ||
color.greyscale() // #5CBF54 -> #969696 | ||
color.negate() // rgb(0, 100, 255) -> rgb(255, 155, 0) | ||
color.lighten(0.5) // hsl(100, 50%, 50%) -> hsl(100, 50%, 75%) | ||
color.darken(0.5) // hsl(100, 50%, 50%) -> hsl(100, 50%, 25%) | ||
color.negate() // rgb(0, 100, 255) -> rgb(255, 155, 0) | ||
color.lighten(0.5) // hsl(100, 50%, 50%) -> hsl(100, 50%, 75%) | ||
color.darken(0.5) // hsl(100, 50%, 50%) -> hsl(100, 50%, 25%) | ||
color.saturate(0.5) | ||
color.desaturate(0.5) // #5CBF54 -> #969696 | ||
color.greyscale() // #5CBF54 -> #969696 | ||
color.clearer(0.5) | ||
color.opaquer(0.5) | ||
color.mix(Color("blue")) // | ||
// chaining | ||
@@ -88,1 +98,6 @@ color.green(100).greyscale().lighten(0.6) | ||
And more to come... | ||
## Propers | ||
@@ -34,2 +34,5 @@ var Color = require("../color"), | ||
// retain alpha | ||
assert.equal(Color().rgb([10, 30, 25, 0.4]).rgb([10, 30, 25]).alpha(), 0.4); | ||
assert.deepEqual(Color().hsl([360, 10, 10]).hsl(), {h: 360, s: 10, l: 10}); | ||
@@ -36,0 +39,0 @@ assert.deepEqual(Color().hsv([360, 10, 10]).hsv(), {h: 360, s: 10, v: 10}); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
100218
9
2125
100
6
1