Skip to content

Commit 13006e9

Browse files
authored
Clamp saturation and lightness rather than throwing errors (#521)
This matches Ruby Sass's behavior.
1 parent 4520b8b commit 13006e9

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
command-line interface, Dart API, and JS API. These load paths are checked
1111
just after the load paths explicitly passed by the user.
1212

13+
* Allow saturation and lightness values outside of the `0%` to `100%` range in
14+
the `hsl()` and `hsla()` functions. They're now clamped to be within that
15+
range rather than producing an error if they're outside it.
16+
1317
* Properly compile selectors that end in escaped whitespace.
1418

1519
[content-args]: https://github.com/sass/language/blob/master/accepted/content-args.md

lib/src/functions.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ final List<BuiltInCallable> coreFunctions = new UnmodifiableListView([
174174
var saturation = arguments[1].assertNumber("saturation");
175175
var lightness = arguments[2].assertNumber("lightness");
176176

177-
return new SassColor.hsl(hue.value, saturation.value, lightness.value);
177+
return new SassColor.hsl(hue.value, saturation.value.clamp(0, 100),
178+
lightness.value.clamp(0, 100));
178179
},
179180
r"$hue, $saturation": (arguments) {
180181
// hsl(123, var(--foo)) is valid CSS because --foo might be `10%, 20%` and
@@ -208,7 +209,10 @@ final List<BuiltInCallable> coreFunctions = new UnmodifiableListView([
208209
var lightness = arguments[2].assertNumber("lightness");
209210
var alpha = arguments[3].assertNumber("alpha");
210211

211-
return new SassColor.hsl(hue.value, saturation.value, lightness.value,
212+
return new SassColor.hsl(
213+
hue.value,
214+
saturation.value.clamp(0, 100),
215+
lightness.value.clamp(0, 100),
212216
_percentageOrUnitless(alpha, 1, "alpha"));
213217
},
214218
r"$hue, $saturation, $lightness": (arguments) {

0 commit comments

Comments
 (0)