Example #1
0
 /**
  * Convert the given node to color node
  *
  * @param Node $node The node
  * @param null $exceptionMessage ILess\Exception\Exception message if the node could not be converted to color node
  * @return ColorNode
  * @throws InvalidArgumentException If the node could not be converted to color
  */
 protected function getColorNode(Node $node, $exceptionMessage = null)
 {
     if ($node instanceof ColorNode) {
         return $node;
     }
     // this is a keyword
     if ($node instanceof KeywordNode && Color::isNamedColor($node->value)) {
         $node = new ColorNode(Color::color($node->value));
     } elseif ($node instanceof ToColorConvertibleInterface) {
         $node = $node->toColor();
     }
     if (!$node instanceof ColorNode) {
         throw new InvalidArgumentException($exceptionMessage ? $exceptionMessage : 'Cannot convert node to color');
     }
     return $node;
 }
Example #2
0
File: Color.php Project: jxav/iless
 /**
  * Creates new color from the keyword
  *
  * @param string $keyword
  * @return Color
  */
 public static function fromKeyword($keyword)
 {
     $color = null;
     // is this named color?
     if (self::isNamedColor($keyword)) {
         $color = new Color(substr(Color::color($keyword), 1));
         $color->keyword = $keyword;
     } elseif ($keyword === 'transparent') {
         $color = new Color([255, 255, 255], 0);
         $color->isTransparentKeyword = true;
     }
     return $color;
 }