Skip to content

Commit 07b33ce

Browse files
authored
[Color 4] Fix color.invert() behavior to match the spec (#2237)
1 parent 2c92c89 commit 07b33ce

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/src/functions/color.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,11 @@ Value _invert(List<Value> arguments, {bool global = false}) {
630630
_checkPercent(weightNumber, "weight");
631631
var rgb = color.toSpace(ColorSpace.rgb);
632632
return _mixLegacy(
633-
SassColor.rgb(255.0 - rgb.channel0, 255.0 - rgb.channel1,
634-
255.0 - rgb.channel2, color.alphaOrNull),
635-
color,
636-
weightNumber);
633+
SassColor.rgb(255.0 - rgb.channel0, 255.0 - rgb.channel1,
634+
255.0 - rgb.channel2, color.alphaOrNull),
635+
color,
636+
weightNumber)
637+
.toSpace(color.space);
637638
}
638639

639640
var space = ColorSpace.fromName(
@@ -668,7 +669,7 @@ Value _invert(List<Value> arguments, {bool global = false}) {
668669
_ => throw UnsupportedError("Unknown color space $space.")
669670
};
670671

671-
if (fuzzyEquals(weight, 1)) return inverted;
672+
if (fuzzyEquals(weight, 1)) return inverted.toSpace(color.space);
672673
return color.interpolate(inverted, InterpolationMethod(space),
673674
weight: 1 - weight);
674675
}
@@ -1144,10 +1145,10 @@ SassColor _mixLegacy(SassColor color1, SassColor color2, SassNumber weight) {
11441145
var weight2 = 1 - weight1;
11451146

11461147
return SassColor.rgb(
1147-
fuzzyRound(rgb1.channel0 * weight1 + rgb2.channel0 * weight2),
1148-
fuzzyRound(color1.green * weight1 + color2.green * weight2),
1149-
fuzzyRound(color1.blue * weight1 + color2.blue * weight2),
1150-
color1.alpha * weightScale + color2.alpha * (1 - weightScale));
1148+
rgb1.channel0 * weight1 + rgb2.channel0 * weight2,
1149+
rgb1.channel1 * weight1 + rgb2.channel1 * weight2,
1150+
rgb1.channel2 * weight1 + rgb2.channel2 * weight2,
1151+
rgb1.alpha * weightScale + rgb2.alpha * (1 - weightScale));
11511152
}
11521153

11531154
/// The definition of the `opacify()` and `fade-in()` functions.

0 commit comments

Comments
 (0)