2016-08-27 11:06:15 +02:00
|
|
|
// Copyright 2016 Google Inc. Use of this source code is governed by an
|
|
|
|
// MIT-style license that can be found in the LICENSE file or at
|
|
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
2016-08-28 01:12:17 +02:00
|
|
|
import 'ast/sass.dart';
|
2016-08-27 11:06:15 +02:00
|
|
|
import 'callable.dart';
|
|
|
|
import 'environment.dart';
|
2016-09-20 23:59:53 +02:00
|
|
|
import 'exception.dart';
|
2016-08-27 11:06:15 +02:00
|
|
|
import 'value.dart';
|
|
|
|
|
|
|
|
void defineCoreFunctions(Environment environment) {
|
2016-09-20 23:59:53 +02:00
|
|
|
environment.setFunction(new BuiltInCallable(
|
|
|
|
"rgb",
|
|
|
|
new ArgumentDeclaration(
|
|
|
|
[new Argument("red"), new Argument("green"), new Argument("blue")]),
|
|
|
|
(arguments) {
|
|
|
|
var red = arguments[0].assertNumber("red");
|
|
|
|
var green = arguments[1].assertNumber("green");
|
|
|
|
var blue = arguments[2].assertNumber("blue");
|
|
|
|
|
|
|
|
return new SassColor.rgb(
|
|
|
|
_percentageOrUnitless(red, 255, "red"),
|
|
|
|
_percentageOrUnitless(green, 255, "green"),
|
|
|
|
_percentageOrUnitless(blue, 255, "blue"));
|
|
|
|
}));
|
|
|
|
|
2016-08-29 00:04:48 +02:00
|
|
|
environment.setFunction(new BuiltInCallable(
|
|
|
|
"inspect",
|
2016-08-27 11:06:15 +02:00
|
|
|
new ArgumentDeclaration([new Argument("value")]),
|
2016-09-19 18:07:29 +02:00
|
|
|
(arguments) => new SassString(arguments.single.toString())));
|
2016-08-27 11:06:15 +02:00
|
|
|
}
|
2016-09-20 23:59:53 +02:00
|
|
|
|
|
|
|
int _percentageOrUnitless(SassNumber number, int max, String name) {
|
|
|
|
num value;
|
|
|
|
if (!number.hasUnits) {
|
|
|
|
value = number.value;
|
|
|
|
} else if (number.hasUnit("%")) {
|
|
|
|
value = max * number.value / 100;
|
|
|
|
} else {
|
|
|
|
throw new InternalException(
|
|
|
|
'\$$name: Expected $number to have no units or "%".');
|
|
|
|
}
|
|
|
|
|
|
|
|
return value.clamp(0, max).round();
|
|
|
|
}
|