From 8b8f6bfbeebf500294332ab0f73f4ef7580c9ea2 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 21 Sep 2016 13:56:23 -0700 Subject: [PATCH] Add opacify() et al --- lib/src/functions.dart | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/src/functions.dart b/lib/src/functions.dart index d8a399ef..44c9cefa 100644 --- a/lib/src/functions.dart +++ b/lib/src/functions.dart @@ -222,6 +222,13 @@ void defineCoreFunctions(Environment environment) { return new SassNumber(color.alpha); })); + environment.setFunction(new BuiltInCallable("opacify", r"$color", _opacify)); + environment.setFunction(new BuiltInCallable("fade-in", r"$color", _opacify)); + environment.setFunction( + new BuiltInCallable("transparentize", r"$color", _transparentize)); + environment + .setFunction(new BuiltInCallable("fade-out", r"$color", _transparentize)); + // ## Introspection environment.setFunction(new BuiltInCallable("inspect", r"$value", @@ -280,3 +287,17 @@ SassColor _mix(SassColor color1, SassColor color2, SassNumber weight) { (color1.blue * weight1 + color2.blue * weight2).round(), color1.alpha * weightScale + color2.alpha * (1 - weightScale)); } + +SassColor _opacify(List arguments) { + var color = arguments[0].assertColor("color"); + var amount = arguments[1].assertNumber("amount"); + + return color.changeAlpha(color.alpha + amount.valueInRange(0, 1, "amount")); +} + +SassColor _transparentize(List arguments) { + var color = arguments[0].assertColor("color"); + var amount = arguments[1].assertNumber("amount"); + + return color.changeAlpha(color.alpha - amount.valueInRange(0, 1, "amount")); +}