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

Track missing alpha channels in colors #2051

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/src/functions/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ Value _invert(List<Value> arguments, {bool global = false}) {
var rgb = color.toSpace(ColorSpace.rgb);
return _mixLegacy(
SassColor.rgb(255.0 - rgb.channel0, 255.0 - rgb.channel1,
255.0 - rgb.channel2, color.alpha),
255.0 - rgb.channel2, color.alphaOrNull),
color,
weightNumber);
}
Expand Down
13 changes: 7 additions & 6 deletions lib/src/js/value/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import '../utils.dart';
final JSClass colorClass = () {
var jsClass = createJSClass('sass.SassColor', (Object self, _Channels color) {
if (color.red != null) {
return SassColor.rgb(color.red!, color.green!, color.blue!, color.alpha);
return SassColor.rgb(color.red!, color.green!, color.blue!,
_handleUndefinedAlpha(color.alpha));
} else if (color.saturation != null) {
return SassColor.hsl(color.hue!, color.saturation!, color.lightness!,
_handleNullAlpha(color.alpha));
_handleUndefinedAlpha(color.alpha));
} else {
return SassColor.hwb(color.hue!, color.whiteness!, color.blackness!,
_handleNullAlpha(color.alpha));
_handleUndefinedAlpha(color.alpha));
}
});

Expand Down Expand Up @@ -69,9 +70,9 @@ final JSClass colorClass = () {

/// Converts an undefined [alpha] to 1.
///
/// This ensures that an explicitly null alpha will produce a deprecation
/// warning when passed to the Dart API.
num? _handleNullAlpha(num? alpha) => isUndefined(alpha) ? 1 : alpha;
/// This ensures that an explicitly null alpha will be treated as a missing
/// component.
num? _handleUndefinedAlpha(num? alpha) => isUndefined(alpha) ? 1 : alpha;

@JS()
@anonymous
Expand Down
Loading