Comparing version 0.8.0 to 0.9.0
@@ -0,1 +1,6 @@ | ||
# 0.9.0 - 2015-06-21 | ||
- Fixed: `mix()` implementation is now the same as in Sass | ||
([#60](https://github.com/harthur/color/pull/60)) | ||
# 0.8.0 - 2015-03-03 | ||
@@ -2,0 +7,0 @@ |
40
index.js
@@ -294,25 +294,25 @@ /* MIT license */ | ||
mix: function(color2, weight) { | ||
weight = 1 - (weight == null ? 0.5 : weight); | ||
/** | ||
* Ported from sass implementation in C | ||
* https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209 | ||
*/ | ||
mix: function(mixinColor, weight) { | ||
var color1 = this; | ||
var color2 = mixinColor; | ||
var weight = weight || 50; | ||
// algorithm from Sass's mix(). Ratio of first color in mix is | ||
// determined by the alphas of both colors and the weight | ||
var t1 = weight * 2 - 1, | ||
d = this.alpha() - color2.alpha(); | ||
var p = weight / 100; | ||
var w = 2 * p - 1; | ||
var a = color1.alpha() - color2.alpha(); | ||
var weight1 = (((t1 * d == -1) ? t1 : (t1 + d) / (1 + t1 * d)) + 1) / 2; | ||
var weight2 = 1 - weight1; | ||
var w1 = (((w * a == -1) ? w : (w + a)/(1 + w*a)) + 1) / 2.0; | ||
var w2 = 1 - w1; | ||
var rgb = this.rgbArray(); | ||
var rgb2 = color2.rgbArray(); | ||
for (var i = 0; i < rgb.length; i++) { | ||
rgb[i] = rgb[i] * weight1 + rgb2[i] * weight2; | ||
} | ||
this.setValues("rgb", rgb); | ||
var alpha = this.alpha() * weight + color2.alpha() * (1 - weight); | ||
this.setValues("alpha", alpha); | ||
return this; | ||
return this | ||
.rgb( | ||
w1 * color1.red() + w2 * color2.red(), | ||
w1 * color1.green() + w2 * color2.green(), | ||
w1 * color1.blue() + w2 * color2.blue() | ||
) | ||
.alpha(color1.alpha() * p + color2.alpha() * (1 - p)); | ||
}, | ||
@@ -319,0 +319,0 @@ |
{ | ||
"name": "color", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "Color conversion and manipulation with CSS string support", | ||
@@ -25,8 +25,11 @@ "keywords": [ | ||
"scripts": { | ||
"test": "node test" | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"color-convert": "^0.5.0", | ||
"color-convert": "^0.5.3", | ||
"color-string": "^0.3.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.2.5" | ||
} | ||
} |
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
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
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
17222
392
0
1
Updatedcolor-convert@^0.5.3