/** * Fix the different syntaxis for the linear-gradient * * @param string $value The value of the property * * @return array The linear-gradient code */ public static function webkitLinearGradient($value) { return Parser::executeFunctions($value, 'linear-gradient', function ($params) { $point = 'top'; if (preg_match('/(top|bottom|left|right|deg)/', $params[0])) { $point = array_shift($params); } switch ($point) { case 'center top': case 'top': $start = 'left top'; $end = 'left bottom'; break; case 'center bottom': case 'bottom': $start = 'left bottom'; $end = 'left top'; break; case 'left top': case 'left': $start = 'left top'; $end = 'right top'; break; case 'right top': case 'right': $start = 'right top'; $end = 'left top'; break; default: $radius = intval($point); } $color_stops = array(); $tk = count($params) - 1; foreach ($params as $k => $param) { $param = Parser::explode(' ', trim($param)); $color = $param[0]; $stop = isset($param[1]) ? $param[1] : null; if ($k === 0) { $text = 'from'; } else { if ($k === $tk) { $text = 'to'; } else { $text = 'color-stop'; } } if ($stop) { $color_stops[] = $text . '(' . $stop . ', ' . $color . ')'; } else { $color_stops[] = $text . '(' . $color . ')'; } } if (isset($radius)) { return '-webkit-gradient(linear, ' . $radius . 'deg, ' . implode(', ', $color_stops) . ')'; } else { return '-webkit-gradient(linear, ' . $start . ', ' . $end . ', ' . implode(', ', $color_stops) . ')'; } }); }
/** * Generate the old webkit syntax for the linear-gradient * * @param Stylecow\Property $property The property object with the standard syntax */ public static function webkitLinearGradient(Property $property) { $newProperty = clone $property; $newProperty->executeFunction('linear-gradient', function ($params) { $point = 'top'; if (preg_match('/(top|bottom|left|right|deg)/', $params[0])) { $point = array_shift($params); } switch ($point) { case 'to bottom': $start = 'left top'; $end = 'left bottom'; break; case 'to top': $start = 'left bottom'; $end = 'left top'; break; case 'to right': $start = 'left top'; $end = 'right top'; break; case 'to left': $start = 'right top'; $end = 'left top'; break; default: if (preg_match('/^\\ddeg$/', $point)) { $radius = intval($point); } else { $start = 'left top'; $end = 'left bottom'; } } $color_stops = array(); $tk = count($params) - 1; foreach ($params as $k => $param) { $param = Parser::explode(' ', trim($param)); $color = $param[0]; $stop = isset($param[1]) ? $param[1] : null; if ($k === 0) { $text = 'from'; } else { if ($k === $tk) { $text = 'to'; } else { $text = 'color-stop'; } } if ($stop) { $color_stops[] = $text . '(' . $stop . ', ' . $color . ')'; } else { $color_stops[] = $text . '(' . $color . ')'; } } if (isset($radius)) { return '-webkit-gradient(linear, ' . $radius . 'deg, ' . implode(', ', $color_stops) . ')'; } else { return '-webkit-gradient(linear, ' . $start . ', ' . $end . ', ' . implode(', ', $color_stops) . ')'; } }); if ($property->value !== $newProperty->value) { $newProperty->vendor = 'webkit'; $property->parent->addProperty($newProperty, $property->getPositionInParent()); } }
/** * Append a value to current value. Useful for properties with multiple values (such background, shadows, etc) * * @param string $value The new value or values separated by comma */ public function addValue($value) { if ($this->value) { if (strpos($this->value, $value) === false) { $this->value .= ', ' . $value; } else { $values = Parser::explode(',', $this->value); if (!in_array($value, $values)) { $this->value .= ', ' . $value; } } } else { $this->value = $value; } }