コード例 #1
0
ファイル: Attribute.php プロジェクト: poef/ariadne
 /**
  * Converts to CSS
  *
  * @param ILess_Environment $env
  * @return string
  */
 public function toCSS(ILess_Environment $env)
 {
     $value = self::methodExists($this->key, 'toCSS') ? $this->key->toCSS($env) : $this->key;
     if ($this->operator) {
         $value .= $this->operator;
         $value .= self::methodExists($this->value, 'toCSS') ? $this->value->toCSS($env) : $this->value;
     }
     return '[' . $value . ']';
 }
コード例 #2
0
ファイル: FunctionRegistry.php プロジェクト: poef/ariadne
 /**
  * Creates a SVG gradient
  *
  * @param ILess_Node $direction
  * @return ILess_Node_Url
  * @throws ILess_Exception_Compiler If the arguments are invalid
  */
 public function svggradient(ILess_Node $direction)
 {
     if (func_num_args() < 3) {
         throw new ILess_Exception_Compiler('svg-gradient expects direction, start_color [start_position], [color position,]..., end_color [end_position]');
     }
     $arguments = func_get_args();
     $stops = array_slice($arguments, 1);
     $gradientType = 'linear';
     $rectangleDimension = 'x="0" y="0" width="1" height="1"';
     $useBase64 = true;
     $renderEnv = new ILess_Environment();
     $directionValue = $direction->toCSS($renderEnv);
     switch ($directionValue) {
         case 'to bottom':
             $gradientDirectionSvg = 'x1="0%" y1="0%" x2="0%" y2="100%"';
             break;
         case 'to right':
             $gradientDirectionSvg = 'x1="0%" y1="0%" x2="100%" y2="0%"';
             break;
         case 'to bottom right':
             $gradientDirectionSvg = 'x1="0%" y1="0%" x2="100%" y2="100%"';
             break;
         case 'to top right':
             $gradientDirectionSvg = 'x1="0%" y1="100%" x2="100%" y2="0%"';
             break;
         case 'ellipse':
         case 'ellipse at center':
             $gradientType = 'radial';
             $gradientDirectionSvg = 'cx="50%" cy="50%" r="75%"';
             $rectangleDimension = 'x="-50" y="-50" width="101" height="101"';
             break;
         default:
             throw new ILess_Exception_Compiler("svg-gradient direction must be 'to bottom', 'to right', 'to bottom right', 'to top right' or 'ellipse at center'");
     }
     $returner = '<?xml version="1.0" ?>' . '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%" viewBox="0 0 1 1" preserveAspectRatio="none">' . '<' . $gradientType . 'Gradient id="gradient" gradientUnits="userSpaceOnUse" ' . $gradientDirectionSvg . '>';
     for ($i = 0; $i < count($stops); $i++) {
         if (ILess_Node::propertyExists($stops[$i], 'value') && $stops[$i]->value) {
             $color = $stops[$i]->value[0];
             $position = $stops[$i]->value[1];
         } else {
             $color = $stops[$i];
             $position = null;
         }
         if (!$color instanceof ILess_Node_Color || !(($i === 0 || $i + 1 === count($stops)) && $position === null) && !$position instanceof ILess_Node_Dimension) {
             throw new ILess_Exception_Compiler('svg-gradient expects direction, start_color [start_position], [color position,]..., end_color [end_position]');
         }
         if ($position) {
             $positionValue = $position->toCSS($renderEnv);
         } elseif ($i === 0) {
             $positionValue = '0%';
         } else {
             $positionValue = '100%';
         }
         $alpha = $color->getAlpha(true);
         $returner .= '<stop offset="' . $positionValue . '" stop-color="' . $color->getColor()->toString($this->env->compress, false) . '"' . ($alpha < 1 ? ' stop-opacity="' . $alpha . '"' : '') . '/>';
     }
     $returner .= '</' . $gradientType . 'Gradient><rect ' . $rectangleDimension . ' fill="url(#gradient)" /></svg>';
     if ($useBase64) {
         $returner = base64_encode($returner);
     }
     $returner = "'data:image/svg+xml" . ($useBase64 ? ";base64" : "") . "," . $returner . "'";
     return new ILess_Node_Url(new ILess_Node_Anonymous($returner));
 }
コード例 #3
0
ファイル: Ruleset.php プロジェクト: poef/ariadne
 /**
  * Finds a selector
  *
  * @param ILess_Node $selector
  * @param ILess_Node_Ruleset $self
  * @param ILess_Environment $env
  * @return array
  */
 public function find(ILess_Node $selector, ILess_Environment $env, ILess_Node_Ruleset $self = null)
 {
     $key = $selector->toCSS($env);
     if (!$self) {
         $self = $this;
     }
     if (!array_key_exists($key, $this->lookups)) {
         $this->lookups[$key] = array();
         foreach ($this->rules as $rule) {
             if ($rule === $self) {
                 continue;
             }
             if ($rule instanceof ILess_Node_Ruleset || $rule instanceof ILess_Node_MixinDefinition) {
                 foreach ($rule->selectors as $ruleSelector) {
                     $match = $selector->match($ruleSelector);
                     if ($match) {
                         if (count($selector->elements) > $match) {
                             $this->lookups[$key] = array_merge($this->lookups[$key], $rule->find(new ILess_Node_Selector(array_slice($selector->elements, $match)), $env, $self));
                         } else {
                             $this->lookups[$key][] = $rule;
                         }
                         break;
                     }
                 }
             }
         }
     }
     return $this->lookups[$key];
 }