Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Color 4] Fix color.invert() behavior to match the spec #2237

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/src/functions/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,11 @@ Value _invert(List<Value> arguments, {bool global = false}) {
_checkPercent(weightNumber, "weight");
var rgb = color.toSpace(ColorSpace.rgb);
return _mixLegacy(
SassColor.rgb(255.0 - rgb.channel0, 255.0 - rgb.channel1,
255.0 - rgb.channel2, color.alphaOrNull),
color,
weightNumber);
SassColor.rgb(255.0 - rgb.channel0, 255.0 - rgb.channel1,
255.0 - rgb.channel2, color.alphaOrNull),
color,
weightNumber)
.toSpace(color.space);
}

var space = ColorSpace.fromName(
Expand Down Expand Up @@ -642,7 +643,7 @@ Value _invert(List<Value> arguments, {bool global = false}) {
_ => throw UnsupportedError("Unknown color space $space.")
};

if (fuzzyEquals(weight, 1)) return inverted;
if (fuzzyEquals(weight, 1)) return inverted.toSpace(color.space);
return color.interpolate(inverted, InterpolationMethod(space),
weight: 1 - weight);
}
Expand Down Expand Up @@ -1118,10 +1119,10 @@ SassColor _mixLegacy(SassColor color1, SassColor color2, SassNumber weight) {
var weight2 = 1 - weight1;

return SassColor.rgb(
fuzzyRound(rgb1.channel0 * weight1 + rgb2.channel0 * weight2),
fuzzyRound(color1.green * weight1 + color2.green * weight2),
fuzzyRound(color1.blue * weight1 + color2.blue * weight2),
color1.alpha * weightScale + color2.alpha * (1 - weightScale));
rgb1.channel0 * weight1 + rgb2.channel0 * weight2,
rgb1.channel1 * weight1 + rgb2.channel1 * weight2,
rgb1.channel2 * weight1 + rgb2.channel2 * weight2,
rgb1.alpha * weightScale + rgb2.alpha * (1 - weightScale));
}

/// The definition of the `opacify()` and `fade-in()` functions.
Expand Down
Loading