Skip to content

Commit c273c45

Browse files
authored
Track missing alpha channels in colors (#2051)
See sass/sass#2831
1 parent 5a5097b commit c273c45

File tree

3 files changed

+106
-63
lines changed

3 files changed

+106
-63
lines changed

lib/src/functions/color.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ Value _invert(List<Value> arguments, {bool global = false}) {
578578
var rgb = color.toSpace(ColorSpace.rgb);
579579
return _mixLegacy(
580580
SassColor.rgb(255.0 - rgb.channel0, 255.0 - rgb.channel1,
581-
255.0 - rgb.channel2, color.alpha),
581+
255.0 - rgb.channel2, color.alphaOrNull),
582582
color,
583583
weightNumber);
584584
}

lib/src/js/value/color.dart

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import '../utils.dart';
1212
final JSClass colorClass = () {
1313
var jsClass = createJSClass('sass.SassColor', (Object self, _Channels color) {
1414
if (color.red != null) {
15-
return SassColor.rgb(color.red!, color.green!, color.blue!, color.alpha);
15+
return SassColor.rgb(color.red!, color.green!, color.blue!,
16+
_handleUndefinedAlpha(color.alpha));
1617
} else if (color.saturation != null) {
1718
return SassColor.hsl(color.hue!, color.saturation!, color.lightness!,
18-
_handleNullAlpha(color.alpha));
19+
_handleUndefinedAlpha(color.alpha));
1920
} else {
2021
return SassColor.hwb(color.hue!, color.whiteness!, color.blackness!,
21-
_handleNullAlpha(color.alpha));
22+
_handleUndefinedAlpha(color.alpha));
2223
}
2324
});
2425

@@ -69,9 +70,9 @@ final JSClass colorClass = () {
6970

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

7677
@JS()
7778
@anonymous

0 commit comments

Comments
 (0)