Special case builtin function opacity(number)
This commit is contained in:
parent
bf98382b0b
commit
2a6ec38fd4
@ -6,6 +6,7 @@ use num_rational::BigRational;
|
|||||||
|
|
||||||
use super::Builtin;
|
use super::Builtin;
|
||||||
use crate::color::Color;
|
use crate::color::Color;
|
||||||
|
use crate::common::QuoteKind;
|
||||||
use crate::units::Unit;
|
use crate::units::Unit;
|
||||||
use crate::value::{Number, Value};
|
use crate::value::{Number, Value};
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
decl!(f "opacity", |args, _| {
|
decl!(f "opacity", |args, _| {
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Some(Value::Dimension(Number::new(BigRational::new(BigInt::from(c.alpha()), BigInt::from(255))), Unit::None)),
|
Value::Color(c) => Some(Value::Dimension(Number::new(BigRational::new(BigInt::from(c.alpha()), BigInt::from(255))), Unit::None)),
|
||||||
|
Value::Dimension(num, unit) => Some(Value::Ident(format!("opacity({}{})", num , unit), QuoteKind::None)),
|
||||||
_ => todo!("non-color given to builtin function `opacity()`")
|
_ => todo!("non-color given to builtin function `opacity()`")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -56,3 +56,11 @@ test!(
|
|||||||
"a {\n color: alpha(red);\n}\n",
|
"a {\n color: alpha(red);\n}\n",
|
||||||
"a {\n color: 1;\n}\n"
|
"a {\n color: 1;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
opacity_function_number,
|
||||||
|
"a {\n color: opacity(1);\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
opacity_function_number_unit,
|
||||||
|
"a {\n color: opacity(1px);\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user