simplify declaration of opacity fns
This commit is contained in:
parent
3e8b83d8ad
commit
11e0d523b2
@ -1,15 +1,17 @@
|
|||||||
use super::GlobalFunctionMap;
|
use super::GlobalFunctionMap;
|
||||||
|
|
||||||
use super::Builtin;
|
use super::Builtin;
|
||||||
|
use crate::args::CallArgs;
|
||||||
use crate::common::QuoteKind;
|
use crate::common::QuoteKind;
|
||||||
|
use crate::error::SassResult;
|
||||||
|
use crate::scope::Scope;
|
||||||
|
use crate::selector::Selector;
|
||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
use crate::value::Number;
|
use crate::value::Number;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
||||||
f.insert(
|
fn alpha(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
|
||||||
"alpha",
|
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
||||||
@ -19,11 +21,9 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
|||||||
)
|
)
|
||||||
.into()),
|
.into()),
|
||||||
}
|
}
|
||||||
}),
|
}
|
||||||
);
|
|
||||||
f.insert(
|
fn opacity(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
|
||||||
"opacity",
|
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
||||||
@ -37,11 +37,9 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
|||||||
)
|
)
|
||||||
.into()),
|
.into()),
|
||||||
}
|
}
|
||||||
}),
|
}
|
||||||
);
|
|
||||||
f.insert(
|
fn opacify(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
|
||||||
"opacify",
|
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -67,11 +65,9 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(Value::Color(Box::new(color.fade_in(amount))))
|
Ok(Value::Color(Box::new(color.fade_in(amount))))
|
||||||
}),
|
}
|
||||||
);
|
|
||||||
f.insert(
|
fn fade_in(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
|
||||||
"fade-in",
|
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -97,11 +93,13 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(Value::Color(Box::new(color.fade_in(amount))))
|
Ok(Value::Color(Box::new(color.fade_in(amount))))
|
||||||
}),
|
}
|
||||||
);
|
|
||||||
f.insert(
|
fn transparentize(
|
||||||
"transparentize",
|
mut args: CallArgs,
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
scope: &Scope,
|
||||||
|
super_selector: &Selector,
|
||||||
|
) -> SassResult<Value> {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -127,11 +125,9 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(Value::Color(Box::new(color.fade_out(amount))))
|
Ok(Value::Color(Box::new(color.fade_out(amount))))
|
||||||
}),
|
}
|
||||||
);
|
|
||||||
f.insert(
|
fn fade_out(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
|
||||||
"fade-out",
|
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -157,6 +153,12 @@ pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(Value::Color(Box::new(color.fade_out(amount))))
|
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));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user