/** * Apply the plugin to Css object * * @param Stylecow\Css $css The css object */ public static function apply(Css $css) { foreach (VendorPrefixes::$vendorPrefixesFunctions as $fn) { $css->executeRecursive(function ($code) use($fn) { if (isset($fn['type']) && $fn['type'] === $code->selector->type) { foreach ($fn['fn'] as $func => $args) { VendorPrefixes::$func($code->selector, $args); } } if (isset($fn['selector']) && strpos((string) $code->selector, $fn['selector']) !== false) { foreach ($fn['fn'] as $func => $args) { VendorPrefixes::$func($code->selector, $fn['selector'], $args); } } if (isset($fn['properties'])) { foreach ($code->getProperties() as $property) { if (in_array($property->name, $fn['properties'])) { foreach ($fn['fn'] as $func => $args) { VendorPrefixes::$func($property, $args); } } } } if (isset($fn['value'])) { foreach ($code->getProperties() as $property) { if (strpos($property->value, $fn['value']) !== false) { foreach ($fn['fn'] as $func => $args) { VendorPrefixes::$func($property, $fn['value'], $args); } } } } }); } //Resolve and simplify the vendors $css->resolveVendors(); }
/** * Apply the plugin to Css object * * @param Stylecow\Css $css The css object */ public static function apply(Css $css) { //Properties names $css->executeRecursive(function ($code) { foreach ($code->getProperties() as $property) { if (isset(VendorPrefixes::$properties[$property->name])) { foreach (VendorPrefixes::$properties[$property->name] as $vendor) { $name = '-' . $vendor . '-' . $property->name; if (!$code->hasProperty($name)) { $newProperty = clone $property; $newProperty->name = $name; $newProperty->vendor = $vendor; $code->addProperty($newProperty, $property->getPositionInParent()); } } } if (isset(VendorPrefixes::$non_standard_properties[$property->name])) { foreach (VendorPrefixes::$non_standard_properties[$property->name] as $vendor => $name) { if (!$code->hasProperty($name)) { $newProperty = clone $property; $newProperty->name = $name; $newProperty->vendor = $vendor; $code->addProperty($newProperty, $property->getPositionInParent()); } } } } }); //Properties values $css->executeRecursive(function ($code) { foreach ($code->getProperties() as $property) { if (isset(VendorPrefixes::$values[$property->name])) { foreach (VendorPrefixes::$values[$property->name] as $value => $vendors) { if (strpos($property->value, $value) !== false) { foreach ($vendors as $vendor) { $newValue = preg_replace('/(^|[^\\w-])(' . preg_quote($value, '/') . ')([^\\w]|$)/', '\\1-' . $vendor . '-' . $value . '\\3', $property->value); if (!$code->hasProperty($property->name, $newValue)) { $newProperty = clone $property; $newProperty->value = $newValue; $newProperty->vendor = $vendor; $code->addProperty($newProperty, $property->getPositionInParent()); } } } } } if (isset(VendorPrefixes::$non_standard_values[$property->name])) { foreach (VendorPrefixes::$non_standard_values[$property->name] as $value => $prefixes) { if (strpos($property->value, $value) !== false) { foreach ($prefixes as $vendor => $fn) { $newValue = call_user_func(__NAMESPACE__ . '\\VendorPrefixes::' . $fn, $property->value); if (!$code->hasProperty($property->name, $newValue)) { $newProperty = clone $property; $newProperty->value = $newValue; $newProperty->vendor = $vendor; $code->addProperty($newProperty, $property->getPositionInParent()); } } } } } } }); //Selector $css->executeRecursive(function ($code) { foreach (VendorPrefixes::$selectors as $selector => $prefixes) { if (strpos((string) $code->selector, $selector) === false) { continue; } foreach ($prefixes as $vendor => $vendor_selector) { $newCode = clone $code; $newCode->selector->set(str_replace($selector, $vendor_selector, $code->selector->get())); $newCode->selector->vendor = $vendor; $code->parent->addChild($newCode, $code->getPositionInParent()); } } }); //Type $css->executeRecursive(function ($code) { if (!isset($code->selector->type) || !isset(VendorPrefixes::$types[$code->selector->type])) { return; } foreach (VendorPrefixes::$types[$code->selector->type] as $vendor => $type) { $newCode = clone $code; $newCode->selector->vendor = $vendor; $newCode->selector->type = $type; $code->parent->addChild($newCode, $code->getPositionInParent()); } }); //Resolve and simplify the vendors $css->resolveVendors(); }