Skip to content

Commit

Permalink
Fix some bugs in color.complement() and .mix() (#1845)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Jan 31, 2023
1 parent ed1a6b0 commit e5aa642
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
11 changes: 8 additions & 3 deletions lib/src/functions/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ final _mix = _function("mix", r"$color1, $color2, $weight: 50%, $method: null",
"color1");
} else if (!color2.isLegacy) {
throw SassScriptException(
"To use color.mix() with non-legacy color $color1, you must provide a "
"To use color.mix() with non-legacy color $color2, you must provide a "
"\$method.",
"color1");
"color2");
}

return _mixLegacy(color1, color2, weight);
Expand All @@ -524,12 +524,17 @@ final _mix = _function("mix", r"$color1, $color2, $weight: 50%, $method: null",
final _complement =
_function("complement", r"$color, $space: null", (arguments) {
var color = arguments[0].assertColor("color");
var space = arguments[1] == sassNull
var space = color.isLegacy && arguments[1] == sassNull
? ColorSpace.hsl
: ColorSpace.fromName(
(arguments[1].assertString("space")..assertUnquoted("space")).text,
"space");

if (!space.isPolar) {
throw SassScriptException(
"Color space $space doesn't have a hue channel.", 'space');
}

var inSpace = color.toSpace(space);
return inSpace.changeChannels({'hue': inSpace.channel('hue') + 180}).toSpace(
color.space);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/value/color/interpolation_method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class InterpolationMethod {
throw SassScriptException(
'Expected unquoted string "hue" at the end of $value, was ${list[2]}.',
name);
} else if (list.length > 2) {
} else if (list.length > 3) {
throw SassScriptException(
'Expected nothing after "hue" in $value.', name);
} else if (!space.isPolar) {
Expand Down
1 change: 0 additions & 1 deletion lib/src/value/color/space.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ abstract class ColorSpace {
/// https://www.w3.org/TR/css-color-4/#ok-lab
static const ColorSpace oklab = OklabColorSpace();


/// The Oklch color space.
///
/// https://www.w3.org/TR/css-color-4/#ok-lab
Expand Down

0 comments on commit e5aa642

Please sign in to comment.