/** * 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()); } }
/** * Duplicate a property with different values * * @param Stylecow\Property $property The property object * @param array $names List of prefixes and new names (for example array('moz' => '@-moz-document')) */ public static function addRenamedValue($property, $value, $names) { foreach ($names as $vendor => $name) { $newValue = preg_replace('/(^|[^\\w-])(' . preg_quote($value, '/') . ')([^\\w]|$)/', "\\1{$name}\\3", $property->value); if (!$property->parent->hasProperty($property->name, $newValue)) { $newProperty = clone $property; $newProperty->value = $newValue; $newProperty->vendor = $vendor; $property->parent->addProperty($newProperty, $property->getPositionInParent()); } } }