Implement builtin function grayscale()

This commit is contained in:
ConnorSkees 2020-02-14 12:11:08 -05:00
parent 08bfa8f145
commit af8bd516b2
2 changed files with 17 additions and 0 deletions

View File

@ -314,4 +314,11 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
};
Some(Value::Color(color.fade_out(amount)))
});
decl!(f "grayscale", |args, _| {
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
_ => todo!("non-color given to builtin function `grayscale()`")
};
Some(Value::Color(color.desaturate(Number::from(1))))
});
}

View File

@ -341,3 +341,13 @@ test!(
"a {\n color: opacify(rgba(0, 0, 17, 0.8), 0.2);\n}\n",
"a {\n color: #000011;\n}\n"
);
test!(
grayscale_1,
"a {\n color: grayscale(plum);\n}\n",
"a {\n color: #bfbfbf;\n}\n"
);
test!(
grayscale_2,
"a {\n color: grayscale(red);\n}\n",
"a {\n color: gray;\n}\n"
);