hsla doesn't care about units
This commit is contained in:
parent
cc372f4e65
commit
6d0686866e
@ -8,20 +8,16 @@ use crate::value::{Number, Value};
|
||||
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
decl!(f "hsl", |args, _| {
|
||||
let hue = match arg!(args, 0, "hue").eval() {
|
||||
Value::Dimension(n, Unit::None)
|
||||
| Value::Dimension(n, Unit::Percent)
|
||||
| Value::Dimension(n, Unit::Deg) => n,
|
||||
_ => todo!("expected either unitless or % number for alpha"),
|
||||
Value::Dimension(n, _) => n,
|
||||
_ => todo!("$hue: ____ is not a number."),
|
||||
};
|
||||
let saturation = match arg!(args, 1, "saturation").eval() {
|
||||
Value::Dimension(n, Unit::None)
|
||||
| Value::Dimension(n, Unit::Percent) => n / Number::from(100),
|
||||
_ => todo!("expected either unitless or % number for alpha"),
|
||||
Value::Dimension(n, _) => n / Number::from(100),
|
||||
_ => todo!("$saturation: ____ is not a number."),
|
||||
};
|
||||
let luminance = match arg!(args, 2, "luminance").eval() {
|
||||
Value::Dimension(n, Unit::None)
|
||||
| Value::Dimension(n, Unit::Percent) => n / Number::from(100),
|
||||
_ => todo!("expected either unitless or % number for alpha"),
|
||||
Value::Dimension(n, _) => n / Number::from(100),
|
||||
_ => todo!("$luminance: ____ is not a number."),
|
||||
};
|
||||
let alpha = match arg!(args, 3, "alpha"=Value::Dimension(Number::from(1), Unit::None)) {
|
||||
Value::Dimension(n, Unit::None) => n,
|
||||
@ -32,25 +28,21 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
});
|
||||
decl!(f "hsla", |args, _| {
|
||||
let hue = match arg!(args, 0, "hue").eval() {
|
||||
Value::Dimension(n, Unit::None)
|
||||
| Value::Dimension(n, Unit::Percent)
|
||||
| Value::Dimension(n, Unit::Deg) => n,
|
||||
_ => todo!("expected either unitless or % number for alpha"),
|
||||
Value::Dimension(n, _) => n,
|
||||
_ => todo!("$hue: ____ is not a number."),
|
||||
};
|
||||
let saturation = match arg!(args, 1, "saturation").eval() {
|
||||
Value::Dimension(n, Unit::None)
|
||||
| Value::Dimension(n, Unit::Percent) => n / Number::from(100),
|
||||
_ => todo!("expected either unitless or % number for alpha"),
|
||||
Value::Dimension(n, _) => n / Number::from(100),
|
||||
_ => todo!("$saturation: ____ is not a number."),
|
||||
};
|
||||
let luminance = match arg!(args, 2, "luminance").eval() {
|
||||
Value::Dimension(n, Unit::None)
|
||||
| Value::Dimension(n, Unit::Percent) => n / Number::from(100),
|
||||
_ => todo!("expected either unitless or % number for alpha"),
|
||||
Value::Dimension(n, _) => n / Number::from(100),
|
||||
_ => todo!("$luminance: ____ is not a number."),
|
||||
};
|
||||
let alpha = match arg!(args, 3, "alpha").eval() {
|
||||
Value::Dimension(n, Unit::None) => n,
|
||||
Value::Dimension(n, Unit::Percent) => n / Number::from(100),
|
||||
_ => todo!("expected either unitless or % number for alpha"),
|
||||
_ => todo!("$alpha: Expected ____ to have no units or \"%\"."),
|
||||
};
|
||||
Ok(Value::Color(Color::from_hsla(hue, saturation, luminance, alpha)))
|
||||
});
|
||||
|
@ -133,6 +133,11 @@ test!(
|
||||
"a {\n color: hsla(193, 67%, 99, .6);\n}\n",
|
||||
"a {\n color: rgba(251, 253, 254, 0.6);\n}\n"
|
||||
);
|
||||
test!(
|
||||
hsl_doesnt_care_about_units,
|
||||
"a {\n color: hsl(193deg, 67foo, 99%);\n}\n",
|
||||
"a {\n color: #fbfdfe;\n}\n"
|
||||
);
|
||||
test!(
|
||||
hsl_named,
|
||||
"a {\n color: hsl($hue: 193, $saturation: 67%, $luminance: 99);\n}\n",
|
||||
|
Loading…
x
Reference in New Issue
Block a user