Comparing version 0.4.1 to 0.4.2
63
color.js
@@ -16,8 +16,8 @@ /* MIT license */ | ||
alpha: 1 | ||
} | ||
} | ||
// parse Color() argument | ||
if (typeof cssString == "string") { | ||
var vals = string.getRgba(cssString); | ||
if (vals) { | ||
if (vals) { | ||
this.setValues("rgb", vals); | ||
@@ -59,3 +59,3 @@ } | ||
}, | ||
rgbArray: function() { | ||
@@ -83,3 +83,3 @@ return this.values.rgb; | ||
}, | ||
alpha: function(val) { | ||
@@ -98,3 +98,3 @@ if (val === undefined) { | ||
return this.setChannel("rgb", 1, val); | ||
}, | ||
}, | ||
blue: function(val) { | ||
@@ -144,3 +144,3 @@ return this.setChannel("rgb", 2, val); | ||
hslString: function() { | ||
return string.hslString(this.values.hsl, this.values.alpha); | ||
return string.hslString(this.values.hsl, this.values.alpha); | ||
}, | ||
@@ -153,14 +153,15 @@ hslaString: function() { | ||
}, | ||
luminosity: function() { | ||
// http://www.w3.org/TR/WCAG20/#relativeluminancedef | ||
var rgb = this.values.rgb; | ||
var lum = []; | ||
for (var i = 0; i < rgb.length; i++) { | ||
var chan = rgb[i] / 255; | ||
rgb[i] = (chan <= 0.03928) ? chan / 12.92 | ||
lum[i] = (chan <= 0.03928) ? chan / 12.92 | ||
: Math.pow(((chan + 0.055) / 1.055), 2.4) | ||
} | ||
return 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]; | ||
return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2]; | ||
}, | ||
contrast: function(color2) { | ||
@@ -175,3 +176,3 @@ // http://www.w3.org/TR/WCAG20/#contrast-ratiodef | ||
}, | ||
dark: function() { | ||
@@ -183,7 +184,7 @@ // YIQ equation from http://24ways.org/2010/calculating-color-contrast | ||
}, | ||
light: function() { | ||
return !this.dark(); | ||
}, | ||
negate: function() { | ||
@@ -207,5 +208,5 @@ var rgb = [] | ||
this.setValues("hsl", this.values.hsl); | ||
return this; | ||
return this; | ||
}, | ||
saturate: function(ratio) { | ||
@@ -220,4 +221,4 @@ this.values.hsl[1] += this.values.hsl[1] * ratio; | ||
this.setValues("hsl", this.values.hsl); | ||
return this; | ||
}, | ||
return this; | ||
}, | ||
@@ -250,6 +251,6 @@ greyscale: function() { | ||
}, | ||
mix: function(color2, weight) { | ||
weight = 1 - (weight || 0.5); | ||
weight = 1 - (weight == null ? 0.5 : weight); | ||
// algorithm from Sass's mix(). Ratio of first color in mix is | ||
@@ -262,3 +263,3 @@ // determined by the alphas of both colors and the weight | ||
var weight2 = 1 - weight1; | ||
var rgb = this.rgbArray(); | ||
@@ -271,6 +272,6 @@ var rgb2 = color2.rgbArray(); | ||
this.setValues("rgb", rgb); | ||
var alpha = this.alpha() * weight + color2.alpha() * (1 - weight); | ||
this.setValues("alpha", alpha); | ||
return this; | ||
@@ -296,3 +297,3 @@ }, | ||
} | ||
Color.prototype.setValues = function(space, vals) { | ||
@@ -305,3 +306,3 @@ var spaces = { | ||
}; | ||
var maxes = { | ||
@@ -313,3 +314,3 @@ "rgb": [255, 255, 255], | ||
}; | ||
var alpha = 1; | ||
@@ -339,3 +340,3 @@ if (space == "alpha") { | ||
} | ||
this.values.alpha = Math.max(0, Math.min(1, alpha || this.values.alpha)); | ||
this.values.alpha = Math.max(0, Math.min(1, (alpha !== undefined ? alpha : this.values.alpha) )); | ||
if (space == "alpha") { | ||
@@ -350,3 +351,3 @@ return; | ||
} | ||
// cap values | ||
@@ -369,3 +370,3 @@ for (var i = 0; i < sname.length; i++) { | ||
if (typeof vals == "number") { | ||
vals = Array.prototype.slice.call(args); | ||
vals = Array.prototype.slice.call(args); | ||
} | ||
@@ -384,3 +385,3 @@ this.setValues(space, vals); | ||
this.setValues(space, this.values[space]); | ||
return this; | ||
return this; | ||
} |
{ | ||
"name": "color", | ||
"description": "Color conversion and manipulation with CSS string support", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"author": "Heather Arthur <fayearthur@gmail.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
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
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
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
23115
0
0
6
480