public static function SassScriptFunctions::rgba in Sassy 7.3
Same name and namespace in other branches
- 7 phamlp/sass/script/SassScriptFunctions.php \SassScriptFunctions::rgba()
Creates a SassColour object from red, green, and blue values and alpha channel (opacity). There are two overloads:
- rgba(red, green, blue, alpha)
Parameters
SassNumber the red component.: A number between 0 and 255 inclusive, or between 0% and 100% inclusive
SassNumber the green component.: A number between 0 and 255 inclusive, or between 0% and 100% inclusive
SassNumber the blue component.: A number between 0 and 255 inclusive, or between 0% and 100% inclusive
SassNumber The alpha channel. A number between 0 and 1.:
- rgba(colour, alpha)
SassColour a SassColour object:
SassNumber The alpha channel. A number between 0 and 1.:
Return value
new SassColour SassColour object
Throws
SassScriptFunctionException if any of the red, green, or blue colour components are out of bounds, or or the colour is not a colour, or alpha is out of bounds
1 call to SassScriptFunctions::rgba()
- SassScriptFunctions::rgb in phpsass/
script/ SassScriptFunctions.php - Creates a SassColour object from red, green, and blue values.
File
- phpsass/
script/ SassScriptFunctions.php, line 84
Class
- SassScriptFunctions
- SassScript functions class. A collection of functions for use in SassSCript. @package PHamlP @subpackage Sass.script
Code
public static function rgba() {
switch (func_num_args()) {
case 2:
$colour = func_get_arg(0);
$alpha = func_get_arg(1);
SassLiteral::assertType($colour, 'SassColour');
SassLiteral::assertType($alpha, 'SassNumber');
SassLiteral::assertInRange($alpha, 0, 1);
return $colour
->with(array(
'alpha' => $alpha->value,
));
break;
case 4:
$rgba = array();
$components = func_get_args();
$alpha = array_pop($components);
foreach ($components as $component) {
SassLiteral::assertType($component, 'SassNumber');
if ($component->units == '%') {
SassLiteral::assertInRange($component, 0, 100, '%');
$rgba[] = $component->value * 2.55;
}
else {
SassLiteral::assertInRange($component, 0, 255);
$rgba[] = $component->value;
}
}
SassLiteral::assertType($alpha, 'SassNumber');
SassLiteral::assertInRange($alpha, 0, 1);
$rgba[] = $alpha->value;
return new SassColour($rgba);
break;
default:
throw new SassScriptFunctionException('Incorrect argument count for ' . __METHOD__ . '; expected 2 or 4, received ' . func_num_args(), SassScriptParser::$context->node);
}
}