Allow optional alpha
argument in rgb()
This commit is contained in:
parent
d6ed0391db
commit
2f54de15c5
@ -25,7 +25,12 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
Value::Dimension(n, Unit::Percent) => (n / Number::from(100)) * Number::from(255),
|
||||
_ => todo!("expected either unitless or % number for alpha"),
|
||||
};
|
||||
Some(Value::Color(Color::from_rgba(red, green, blue, 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_rgba(red, green, blue, alpha)))
|
||||
} else {
|
||||
todo!("channels variable in `rgb`")
|
||||
}
|
||||
@ -154,7 +159,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
let weight = match arg!(args, 1, "weight"=Value::Dimension(Number::from(100), Unit::Percent)) {
|
||||
Value::Dimension(n, Unit::None)
|
||||
| Value::Dimension(n, Unit::Percent) => n / Number::from(100),
|
||||
_ => todo!("non-number weight in given to builtin function `invert()`")
|
||||
_ => todo!("non-number weight given to builtin function `invert()`")
|
||||
};
|
||||
match arg!(args, 0, "color") {
|
||||
Value::Color(c) => Some(Value::Color(c.invert(weight))),
|
||||
|
@ -86,6 +86,11 @@ test!(
|
||||
"a {\n color: rgba(1, 2, 3, 3);\n}\n",
|
||||
"a {\n color: #010203;\n}\n"
|
||||
);
|
||||
test!(
|
||||
rgba_negative_alpha,
|
||||
"a {\n color: rgba(1, 2, 3, -10%);\n}\n",
|
||||
"a {\n color: rgba(1, 2, 3, 0);\n}\n"
|
||||
);
|
||||
test!(
|
||||
rgba_opacity_decimal,
|
||||
"a {\n color: rgba(1, 2, 3, .6);\n}\n",
|
||||
|
Loading…
x
Reference in New Issue
Block a user