Handle number passed to invert()
This commit is contained in:
parent
948c489785
commit
d4dd360682
@ -150,11 +150,13 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
decl!(f "invert", |args, _| {
|
decl!(f "invert", |args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let weight = match arg!(args, 1, "weight"=Value::Dimension(Number::from(100), Unit::Percent)) {
|
let weight = match arg!(args, 1, "weight"=Value::Dimension(Number::from(100), Unit::Percent)) {
|
||||||
Value::Dimension(n, u) => bound!("amount", n, u, 0, 100) / Number::from(100),
|
Value::Dimension(n, u) => bound!("weight", n, u, 0, 100) / Number::from(100),
|
||||||
v => return Err(format!("$weight: {} is not a number.", v).into()),
|
v => return Err(format!("$weight: {} is not a number.", v).into()),
|
||||||
};
|
};
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Color(c.invert(weight))),
|
Value::Color(c) => Ok(Value::Color(c.invert(weight))),
|
||||||
|
Value::Dimension(n, Unit::Percent) => Ok(Value::Ident(format!("invert({}%)", n), QuoteKind::None)),
|
||||||
|
Value::Dimension(..) => return Err("Only one argument may be passed to the plain-CSS invert() function.".into()),
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -258,6 +258,14 @@ test!(
|
|||||||
"a {\n color: invert(white);\n}\n",
|
"a {\n color: invert(white);\n}\n",
|
||||||
"a {\n color: black;\n}\n"
|
"a {\n color: black;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
invert_number,
|
||||||
|
"a {\n color: invert(10%);\n}\n"
|
||||||
|
);
|
||||||
|
// test!(
|
||||||
|
// invert_number_casing,
|
||||||
|
// "a {\n color: iNveRt(10%);\n}\n"
|
||||||
|
// );
|
||||||
test!(
|
test!(
|
||||||
invert_weight_percent,
|
invert_weight_percent,
|
||||||
"a {\n color: invert(white, 20%);\n}\n",
|
"a {\n color: invert(white, 20%);\n}\n",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user