You are here

function lessc::funcToColor in Less CSS Preprocessor 6.3

1 call to lessc::funcToColor()
lessc::reduce in lessphp/lessc.inc.php

File

lessphp/lessc.inc.php, line 848

Class

lessc

Code

function funcToColor($func) {
  $fname = $func[1];
  if (!preg_match('/^(rgb|rgba)$/', $fname)) {
    return false;
  }
  if ($func[2][0] != 'list') {
    return false;
  }

  // need a list of arguments
  $components = array();
  $i = 1;
  foreach ($func[2][2] as $c) {
    $c = $this
      ->reduce($c);
    if ($i < 4) {
      if ($c[0] == '%') {
        $components[] = 255 * ($c[1] / 100);
      }
      else {
        $components[] = floatval($c[1]);
      }
    }
    elseif ($i == 4) {
      if ($c[0] == '%') {
        $components[] = 1.0 * ($c[1] / 100);
      }
      else {
        $components[] = floatval($c[1]);
      }
    }
    else {
      break;
    }
    $i++;
  }
  while (count($components) < 3) {
    $components[] = 0;
  }
  array_unshift($components, 'color');
  return $this
    ->fixColor($components);
}