Allow alpha in hsl()

This commit is contained in:
ConnorSkees 2020-02-15 06:55:20 -05:00
parent a35fa119e0
commit 46e4ccd5f9
2 changed files with 11 additions and 1 deletions

View File

@ -23,7 +23,12 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
| Value::Dimension(n, Unit::Percent) => n / Number::from(100), | Value::Dimension(n, Unit::Percent) => n / Number::from(100),
_ => todo!("expected either unitless or % number for alpha"), _ => todo!("expected either unitless or % number for alpha"),
}; };
Some(Value::Color(Color::from_hsla(hue, saturation, luminance, Number::from(1)))) let alpha = match arg!(args, 3, "alpha"=Value::Dimension(Number::from(1), Unit::None)) {
Value::Dimension(n, Unit::None) => n,
Value::Dimension(n, Unit::Percent) => n / Number::from(100),
_ => todo!("non-number alpha given to builtin function `rgb()`")
};
Some(Value::Color(Color::from_hsla(hue, saturation, luminance, alpha)))
}); });
decl!(f "hsla", |args, _| { decl!(f "hsla", |args, _| {
let hue = match arg!(args, 0, "hue").eval() { let hue = match arg!(args, 0, "hue").eval() {

View File

@ -128,6 +128,11 @@ test!(
"a {\n color: hsl($hue: 193, $saturation: 67%, $luminance: 99);\n}\n", "a {\n color: hsl($hue: 193, $saturation: 67%, $luminance: 99);\n}\n",
"a {\n color: #fbfdfe;\n}\n" "a {\n color: #fbfdfe;\n}\n"
); );
test!(
hsl_four_args,
"a {\n color: hsl(0, 0, 0, 0.456);\n}\n",
"a {\n color: rgba(0, 0, 0, 0.456);\n}\n"
);
test!( test!(
hsl_negative_hue, hsl_negative_hue,
"a {\n color: hsl(-60deg, 100%, 50%);\n}\n", "a {\n color: hsl(-60deg, 100%, 50%);\n}\n",