Handle numbers passed to saturate
This commit is contained in:
parent
d4dd360682
commit
3e89a0a057
@ -108,14 +108,15 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
});
|
||||
decl!(f "saturate", |args, _| {
|
||||
max_args!(args, 2);
|
||||
let color = match arg!(args, 0, "color").eval() {
|
||||
Value::Color(c) => c,
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
};
|
||||
let amount = match arg!(args, 1, "amount").eval() {
|
||||
Value::Dimension(n, u) => bound!("amount", n, u, 0, 100) / Number::from(100),
|
||||
v => return Err(format!("$amount: {} is not a number.", v).into())
|
||||
};
|
||||
let color = match arg!(args, 0, "color").eval() {
|
||||
Value::Color(c) => c,
|
||||
Value::Dimension(n, u) => return Ok(Value::Ident(format!("saturate({}{})", n, u), QuoteKind::None)),
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
};
|
||||
Ok(Value::Color(color.saturate(amount)))
|
||||
});
|
||||
decl!(f "desaturate", |args, _| {
|
||||
|
@ -188,7 +188,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
};
|
||||
|
||||
let weight = match arg!(args, 2, "weight"=Value::Dimension(Number::from(50), Unit::None)) {
|
||||
Value::Dimension(n, _) => n / 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()),
|
||||
};
|
||||
Ok(Value::Color(color1.mix(color2, weight)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user