Skip to content

Commit

Permalink
Track missing alpha channels in colors (#2051)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Aug 22, 2023
1 parent 5a5097b commit c273c45
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 63 deletions.
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

0 comments on commit c273c45

Please sign in to comment.