Handle numbers passed to saturate

This commit is contained in:
ConnorSkees 2020-02-16 17:13:17 -05:00
parent d4dd360682
commit 3e89a0a057
2 changed files with 6 additions and 5 deletions

View File

@ -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, _| {

View File

@ -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)))