Пример #1
0
 /**
  * Creates the variable. Detects the type.
  *
  * @param string $name The name of the variable
  * @param mixed $value The value of the variable
  * @return ILess_Variable
  */
 public static function create($name, $value)
 {
     $important = false;
     // name is marked as !name
     if (strpos($name, '!') === 0) {
         $important = true;
         $name = substr($name, 1);
     }
     // Color
     if (ILess_Color::isNamedColor($value) || strtolower($value) === 'transparent' || strpos($value, '#') === 0) {
         $value = new ILess_Node_Color(new ILess_Color($value));
     } elseif (preg_match(self::RGBA_COLOR_REGEXP, $value, $matches)) {
         // RGB(A) colors
         $value = new ILess_Node_Color(new ILess_Color(array($matches[1], $matches[2], $matches[3]), isset($matches[4]) ? $matches[4] : 1));
     } elseif (preg_match(self::QUOTED_REGEXP, $value, $matches)) {
         $value = new ILess_Node_Quoted($matches[0], $matches[0][0] == '"' ? $matches[1] : $matches[2]);
     } elseif (strpos($value, 'http://') === 0 || strpos($value, 'https://') === 0) {
         $value = new ILess_Node_Anonymous($value);
     } elseif (preg_match(self::DIMENSION_REGEXP, $value, $matches)) {
         $value = new ILess_Node_Dimension($matches[1], isset($matches[2]) ? $matches[2] : null);
     } else {
         $value = new ILess_Node_Anonymous($value);
     }
     return new ILess_Variable($name, $value, $important);
 }
Пример #2
0
 /**
  * Return a color 10% points *darker*
  *
  * @param ILess_Node $color
  * @param ILess_Node
  * @return string
  * @throws InvalidArgumentException If the node is invalid
  */
 public function darken(ILess_Node $color, ILess_Node_Dimension $percentage = null)
 {
     // this is a keyword
     if ($color instanceof ILess_Node_Keyword && ILess_Color::isNamedColor($color->value)) {
         $color = new ILess_Node_Color(ILess_Color::color($color->value));
     }
     if (!$color instanceof ILess_Node_Color) {
         throw new InvalidArgumentException('Cannot darken the color. Invalid color given.');
     }
     $percentage = $percentage ? $percentage->value / 100 : 10;
     $lightness = $this->clamp($color->getLightness(true) - $percentage);
     return $this->hsla($color->getHue(true), $color->getSaturation(true), $lightness, $color->getAlpha(true));
 }