diff --git a/src/color/mod.rs b/src/color/mod.rs index ebd23ac..6c17fd7 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -246,7 +246,11 @@ impl Color { /// Create RGBA representation from HSLA values pub fn from_hsla(hue: Number, saturation: Number, luminance: Number, alpha: Number) -> Self { - let mut hue = clamp!(hue, 0, 360); + let mut hue = if hue < Number::from(0) { + Number::from(360) + clamp!(hue, -360, 360) + } else { + clamp!(hue, -360, 360) + }; let saturation = clamp!(saturation, 0, 1); let luminance = clamp!(luminance, 0, 1); let alpha = clamp!(alpha, 0, 1); diff --git a/tests/color.rs b/tests/color.rs index e9c3430..abda8fc 100644 --- a/tests/color.rs +++ b/tests/color.rs @@ -128,6 +128,11 @@ test!( "a {\n color: hsl($hue: 193, $saturation: 67%, $luminance: 99);\n}\n", "a {\n color: #fbfdfe;\n}\n" ); +test!( + hsl_negative_hue, + "a {\n color: hsl(-60deg, 100%, 50%);\n}\n", + "a {\n color: fuchsia;\n}\n" +); test!( hsla_named, "a {\n color: hsla($hue: 193, $saturation: 67%, $luminance: 99, $alpha: .6);\n}\n",