simplify declaration of opacity fns

This commit is contained in:
ConnorSkees 2020-04-30 18:54:29 -04:00
parent 3e8b83d8ad
commit 11e0d523b2

View File

@ -1,15 +1,17 @@
use super::GlobalFunctionMap;
use super::Builtin;
use crate::args::CallArgs;
use crate::common::QuoteKind;
use crate::error::SassResult;
use crate::scope::Scope;
use crate::selector::Selector;
use crate::unit::Unit;
use crate::value::Number;
use crate::value::Value;
pub(crate) fn register(f: &mut GlobalFunctionMap) {
f.insert(
"alpha",
Builtin::new(|mut args, scope, super_selector| {
fn alpha(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
@ -19,11 +21,9 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
)
.into()),
}
}),
);
f.insert(
"opacity",
Builtin::new(|mut args, scope, super_selector| {
}
fn opacity(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
@ -37,11 +37,9 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
)
.into()),
}
}),
);
f.insert(
"opacify",
Builtin::new(|mut args, scope, super_selector| {
}
fn opacify(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
@ -67,11 +65,9 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
}
};
Ok(Value::Color(Box::new(color.fade_in(amount))))
}),
);
f.insert(
"fade-in",
Builtin::new(|mut args, scope, super_selector| {
}
fn fade_in(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
@ -97,11 +93,13 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
}
};
Ok(Value::Color(Box::new(color.fade_in(amount))))
}),
);
f.insert(
"transparentize",
Builtin::new(|mut args, scope, super_selector| {
}
fn transparentize(
mut args: CallArgs,
scope: &Scope,
super_selector: &Selector,
) -> SassResult<Value> {
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
@ -127,11 +125,9 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
}
};
Ok(Value::Color(Box::new(color.fade_out(amount))))
}),
);
f.insert(
"fade-out",
Builtin::new(|mut args, scope, super_selector| {
}
fn fade_out(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
@ -157,6 +153,12 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
}
};
Ok(Value::Color(Box::new(color.fade_out(amount))))
}),
);
}
f.insert("alpha", Builtin::new(alpha));
f.insert("opacity", Builtin::new(opacity));
f.insert("opacify", Builtin::new(opacify));
f.insert("fade-in", Builtin::new(fade_in));
f.insert("transparentize", Builtin::new(transparentize));
f.insert("fade-out", Builtin::new(fade_out));
}