Пример #1
0
 /**
  * @see Less_Tree::genCSS
  */
 public function genCSS($output)
 {
     if (Less_Parser::$options['strictUnits'] && !$this->unit->isSingular()) {
         throw new Less_Exception_Compiler("Multiple units in dimension. Correct the units or use the unit function. Bad unit: " . $this->unit->toString());
     }
     $value = Less_Functions::fround($this->value);
     $strValue = (string) $value;
     if ($value !== 0 && $value < 1.0E-6 && $value > -1.0E-6) {
         // would be output 1e-6 etc.
         $strValue = number_format($strValue, 10);
         $strValue = preg_replace('/\\.?0+$/', '', $strValue);
     }
     if (Less_Parser::$options['compress']) {
         // Zero values doesn't need a unit
         if ($value === 0 && $this->unit->isLength()) {
             $output->add($strValue);
             return $strValue;
         }
         // Float values doesn't need a leading zero
         if ($value > 0 && $value < 1 && $strValue[0] === '0') {
             $strValue = substr($strValue, 1);
         }
     }
     $output->add($strValue);
     $this->unit->genCSS($output);
 }
Пример #2
0
 public function toCSS($doNotCompress = false)
 {
     $compress = Less_Parser::$options['compress'] && !$doNotCompress;
     $alpha = Less_Functions::fround($this->alpha);
     //
     // If we have some transparency, the only way to represent it
     // is via `rgba`. Otherwise, we use the hex representation,
     // which has better compatibility with older browsers.
     // Values are capped between `0` and `255`, rounded and zero-padded.
     //
     if ($alpha < 1) {
         if ($alpha === 0 && isset($this->isTransparentKeyword) && $this->isTransparentKeyword) {
             return 'transparent';
         }
         $values = array();
         foreach ($this->rgb as $c) {
             $values[] = Less_Functions::clamp(round($c), 255);
         }
         $values[] = $alpha;
         $glue = $compress ? ',' : ', ';
         return "rgba(" . implode($glue, $values) . ")";
     } else {
         $color = $this->toRGB();
         if ($compress) {
             // Convert color to short format
             if ($color[1] === $color[2] && $color[3] === $color[4] && $color[5] === $color[6]) {
                 $color = '#' . $color[1] . $color[3] . $color[5];
             }
         }
         return $color;
     }
 }