Allow alpha in hsl()
This commit is contained in:
parent
a35fa119e0
commit
46e4ccd5f9
@ -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() {
|
||||||
|
@ -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",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user