/** * @param string $op */ public function operate($op, $other) { $value = Less_Functions::operate($op, $this->value, $other->value); $unit = clone $this->unit; if ($op === '+' || $op === '-') { if (!$unit->numerator && !$unit->denominator) { $unit->numerator = $other->unit->numerator; $unit->denominator = $other->unit->denominator; } elseif (!$other->unit->numerator && !$other->unit->denominator) { // do nothing } else { $other = $other->convertTo($this->unit->usedUnits()); if (Less_Parser::$options['strictUnits'] && $other->unit->toString() !== $unit->toCSS()) { throw new Less_Exception_Compiler("Incompatible units. Change the units or use the unit function. Bad units: '" . $unit->toString() . "' and " . $other->unit->toString() + "'."); } $value = Less_Functions::operate($op, $this->value, $other->value); } } elseif ($op === '*') { $unit->numerator = array_merge($unit->numerator, $other->unit->numerator); $unit->denominator = array_merge($unit->denominator, $other->unit->denominator); sort($unit->numerator); sort($unit->denominator); $unit->cancel(); } elseif ($op === '/') { $unit->numerator = array_merge($unit->numerator, $other->unit->denominator); $unit->denominator = array_merge($unit->denominator, $other->unit->numerator); sort($unit->numerator); sort($unit->denominator); $unit->cancel(); } return new Less_Tree_Dimension($value, $unit); }
public function contrast($color, $dark = null, $light = null, $threshold = null) { // filter: contrast(3.2); // should be kept as is, so check for color if (!$color instanceof Less_Tree_Color) { return null; } if (!$light) { $light = $this->rgba(255, 255, 255, 1.0); } if (!$dark) { $dark = $this->rgba(0, 0, 0, 1.0); } if (!$dark instanceof Less_Tree_Color) { throw new Less_Exception_Compiler('The second argument to contrast must be a color' . ($dark instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '')); } if (!$light instanceof Less_Tree_Color) { throw new Less_Exception_Compiler('The third argument to contrast must be a color' . ($light instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '')); } //Figure out which is actually light and dark! if ($dark->luma() > $light->luma()) { $t = $light; $light = $dark; $dark = $t; } if (!$threshold) { $threshold = 0.43; } else { $threshold = Less_Functions::number($threshold); } if ($color->luma() < $threshold) { return $light; } else { return $dark; } }
function toHex($v) { $ret = '#'; foreach ($v as $c) { $c = Less_Functions::clamp(Less_Parser::round($c), 255); if ($c < 16) { $ret .= '0'; } $ret .= dechex($c); } return $ret; }
/** * Generates the CSS * * @return string */ public function generateCSS() { $output = new Less_Output_Mapped($this->contentsMap, $this); // catch the output $this->root->genCSS($output); $sourceMapUrl = $this->getOption('sourceMapURL'); $sourceMapFilename = $this->getOption('sourceMapFilename'); $sourceMapContent = $this->generateJson(); $sourceMapWriteTo = $this->getOption('sourceMapWriteTo'); if (!$sourceMapUrl && $sourceMapFilename) { $sourceMapUrl = $this->normalizeFilename($sourceMapFilename); } // write map to a file if ($sourceMapWriteTo) { $this->saveMap($sourceMapWriteTo, $sourceMapContent); } // inline the map if (!$sourceMapUrl) { $sourceMapUrl = sprintf('data:application/json,%s', Less_Functions::encodeURIComponent($sourceMapContent)); } if ($sourceMapUrl) { $output->add(sprintf('/*# sourceMappingURL=%s */', $sourceMapUrl)); } return $output->toString(); }
public function contrast($color, $dark = null, $light = null, $threshold = null) { // filter: contrast(3.2); // should be kept as is, so check for color if (!property_exists($color, 'rgb')) { return null; } if (!$light) { $light = $this->rgba(255, 255, 255, 1.0); } if (!$dark) { $dark = $this->rgba(0, 0, 0, 1.0); } //Figure out which is actually light and dark! if ($dark->luma() > $light->luma()) { $t = $light; $light = $dark; $dark = $t; } if (!$threshold) { $threshold = 0.43; } else { $threshold = Less_Functions::number($threshold); } if ($color->luma() < $threshold) { return $light; } else { return $dark; } }
/** * The PHP LESS parser dies trying to dynamically generate * the tab SVG CSS, so process it manually instead. * @param string $light * @param string $dark * @return string */ protected static function makeTabSvg($light, $dark) { /* * Desaturate and darken the dark color */ $dark = substr($dark, 1); // Remove the # $func = new \Less_Functions(null); $value = new \Less_Tree_Dimension('14.5', '%'); $color = new \Less_Tree_Color($dark); $color = $func->desaturate($color, $value); $value = new \Less_Tree_Dimension('5', '%'); $black = new \Less_Tree_Color('000000'); $color = $func->mix($black, $color, $value); $dark = $color->toRGB(); /* * SVG Definition */ $svg = ''; $svg .= '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="100px" height="110px" viewBox="0 0 100 110" enable-background="new 0 0 100 110" xml:space="preserve">'; $svg .= '<path d="M0,30C5,30,10,0,20,0c5,0,60,0,65,0c10,0,10,30,15,30"/>'; $svg .= '<path fill="' . $light . '" d="M0,70c5,0,10-30,20-30c0,10,0,15,0,15v15"/>'; $svg .= '<path fill="' . $light . '" d="M100,70c-5,0-10-30-20-30c0,10,0,15,0,15v15"/>'; $svg .= '<path fill="' . $dark . '" d="M0,110c5,0,10-30,20-30c0,10,0,15,0,15v15"/>'; $svg .= '<path fill="' . $dark . '" d="M100,110c-5,0-10-30-20-30c0,10,0,15,0,15v15"/>'; $svg .= '</svg>'; /* * Escape CSS */ $revert = ['%21' => '!', '%2A' => '*', '%27' => "'", '%3F' => '?', '%26' => '&', '%2C' => ',', '%2F' => '/', '%40' => '@', '%2B' => '+', '%24' => '$']; $svg = strtr(rawurlencode($svg), $revert); /* * Add header */ $svg = 'data:image/svg+xml;charset=UTF-8,' . $svg; /* * Compile CSS */ $css = ''; $css .= '.fancy-layout .control-tabs.master-tabs > div > div.tabs-container > ul.nav-tabs > li a > span.title:before,'; $css .= '.fancy-layout.control-tabs.master-tabs > div > div.tabs-container > ul.nav-tabs > li a > span.title:before,'; $css .= '.fancy-layout .control-tabs.master-tabs > div > div.tabs-container > ul.nav-tabs > li a > span.title:after,'; $css .= '.fancy-layout.control-tabs.master-tabs > div > div.tabs-container > ul.nav-tabs > li a > span.title:after {'; $css .= "background-image: url('" . $svg . "')}"; return $css; }
public function jmdarken($color, $amount) { if ($color instanceof Less_Tree_Color) { $hsl = $color->toHSL(); $hsl['l'] -= $hsl['l'] * $amount->value / 100; $hsl['l'] = self::clamp($hsl['l']); return $this->hsla($hsl['h'], $hsl['s'], $hsl['l'], $hsl['a']); } Less_Functions::Expected('color', $color); }
public function ConfigurableEmailTheme() { $env = new Less_Environment($this->lessEnvOptions()); $less = new Less_Functions($env); $panelColor = trim((string) $this->owner->PrimaryColor, '#'); if (!$panelColor) { $panelColor = '666'; } $btnColor = trim((string) $this->owner->CtaColor, '#'); if (!$btnColor) { $btnColor = $panelColor; } $headerColor = trim((string) $this->owner->SecondaryColor, '#'); if (!$headerColor) { $headerColor = $panelColor; } return array('header_color' => '#' . $headerColor, 'header_font_color' => $less->contrast(new Less_Tree_Color($headerColor), new Less_Tree_Color('000000'), new Less_Tree_Color('ffffff'), new Less_Tree_Dimension(0.6))->toRGB(), 'footer_color' => '#' . $panelColor, 'footer_font_color' => $less->contrast(new Less_Tree_Color($panelColor), new Less_Tree_Color('000000'), new Less_Tree_Color('ffffff'), new Less_Tree_Dimension(0.6))->toRGB(), 'panel_color' => '#' . $panelColor, 'panel_border_color' => $less->darken(new Less_Tree_Color($panelColor), new Less_Tree_Dimension(15))->toRGB(), 'panel_font_color' => $less->contrast(new Less_Tree_Color($panelColor), new Less_Tree_Color('000000'), new Less_Tree_Color('ffffff'), new Less_Tree_Dimension(0.6))->toRGB(), 'btn_color' => '#' . $btnColor, 'btn_border_color' => $less->darken(new Less_Tree_Color($btnColor), new Less_Tree_Dimension(15))->toRGB(), 'btn_font_color' => $less->contrast(new Less_Tree_Color($btnColor), new Less_Tree_Color('000000'), new Less_Tree_Color('ffffff'), new Less_Tree_Dimension(0.6))->toRGB()); }
/** * @param string $op */ public function operate($op, $other) { $rgb = array(); $alpha = $this->alpha * (1 - $other->alpha) + $other->alpha; for ($c = 0; $c < 3; $c++) { $rgb[$c] = Less_Functions::operate($op, $this->rgb[$c], $other->rgb[$c]); } return new Less_Tree_Color($rgb, $alpha); }