You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var normalizedWeight = weightScale * 2 - 1;
var alphaDistance = color1.alpha - color2.alpha;
var combinedWeight1 = normalizedWeight * alphaDistance == -1
? normalizedWeight
: (normalizedWeight + alphaDistance) /
(1 + normalizedWeight * alphaDistance);
var weight1 = (combinedWeight1 + 1) / 2;
var weight2 = 1 - weight1;
polished:
// The formula is copied from the original Sass implementation:
// http://sass-lang.com/documentation/Sass/Script/Functions.html#mix-instance_method
const alphaDelta = color1.alpha - color2.alpha
const x = parseFloat(weight) * 2 - 1
const y = x * alphaDelta === -1 ? x : x + alphaDelta
const z = 1 + x * alphaDelta
const weight1 = (y / z + 1) / 2.0
const weight2 = 1 - weight1
Converting the dart-sass implementation to polished variable names looks like this:
var alphaDelta = color1.alpha - color2.alpha;
var x = weightScale * 2 - 1;
var z = 1 + x * alphaDelta;
var y = x * alphaDelta == -1 ? x : (x + alphaDelta) / z;
var weight1 = (y + 1) / 2;
var weight2 = 1 - weight1;
What You Expected To See
The code of polished is wrong:
const y = x * alphaDelta === -1 ? x : x + alphaDelta
const z = 1 + x * alphaDelta
const weight1 = (y / z + 1) / 2.0
Here's the correct code:
const z = 1 + x * alphaDelta
const y = x * alphaDelta === -1 ? x : (x + alphaDelta) / z
const weight1 = (y + 1) / 2.0
Do not divide by z when x * alphaDelta === -1.
Notes
Furthermore, there is also the following problem. #613
polished
version: v4.3.1JSS-in_CSS
library and version: unknownWhat You Are Seeing
I was looking into the implementation of the mix colors function.
Among them I found
polished
anddart-sass
implementations.However, upon closer inspection, I found a bug in the
polished
implementation.dart-sass:
polished:
Converting the
dart-sass
implementation topolished
variable names looks like this:What You Expected To See
The code of
polished
is wrong:Here's the correct code:
Do not divide by z when
x * alphaDelta === -1
.Notes
Furthermore, there is also the following problem. #613
dart-sass:
polished:
Math.round
should be used instead ofMath.floor
.The text was updated successfully, but these errors were encountered: