Ejemplo n.º 1
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code, $settings) {
         if ($property = $code->getLastProperty(array('background', 'background-color'))) {
             $property->executeFunction('rgba', function ($params, $name, $property) {
                 $filter = IeBackgroundAlpha::getRGBAFilter($params);
                 if ($filterProperty = $property->parent->getLastProperty('filter')) {
                     $filterProperty->addValue($filter);
                     $filterProperty->vendor = 'ms';
                 } else {
                     $property->parent->addProperty(new Property('filter', $filter))->vendor = 'ms';
                 }
             });
             $property->executeFunction('hsla', function ($params, $name, $property) {
                 $filter = IeBackgroundAlpha::getHSLAFilter($params);
                 if ($filterProperty = $property->parent->getLastProperty('filter')) {
                     $filterProperty->addValue($filter);
                     $filterProperty->vendor = 'ms';
                 } else {
                     $property->parent->addProperty(new Property('filter', $filter))->vendor = 'ms';
                 }
             });
         }
     });
 }
Ejemplo n.º 2
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code, $settings) {
         if (($property = $code->getLastProperty('min-height')) && !$code->hasProperty(array('_height', '*height', 'height'))) {
             $code->addProperty(new Property('_height', $property->value))->vendor = 'ms';
         }
     });
 }
Ejemplo n.º 3
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         if (($property = $code->getLastProperty('float', array('right', 'left'))) && !$code->hasProperty(array('display', '_display', '*display'), 'inline')) {
             $code->addProperty(new Property('_display', 'inline'))->vendor = 'ms';
         }
     });
 }
Ejemplo n.º 4
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         if ($property = $code->getLastProperty('clip')) {
             $value = str_replace(',', ' ', str_replace(' ', '', $property->value));
             if (!$code->hasProperty(array('clip', '*clip'), $value)) {
                 $code->addProperty(new Property('*clip', $value))->vendor = 'ms';
             }
         }
     });
 }
Ejemplo n.º 5
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  * @param array $rootVariables Optional variables not defined in css code
  */
 public static function apply(Css $css, array $rootVariables = array())
 {
     foreach ($css->getChildren(array(':root', 'html', 'body')) as $child) {
         $rootVariables = self::getVariables($child, $rootVariables);
     }
     $css->executeRecursive(function ($code, &$contextVariables) {
         $contextVariables = Variables::getVariables($code, $contextVariables);
         foreach ($code->properties as $property) {
             $property->value = Variables::replaceVariables($property->value, $contextVariables);
         }
     }, $rootVariables);
 }
Ejemplo n.º 6
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         if ($property = $code->getLastProperty('display', 'inline-block')) {
             if (!$code->hasProperty(array('zoom', '*zoom'))) {
                 $code->addProperty(new Property('*zoom', 1))->vendor = 'ms';
             }
             if (!$code->hasProperty('*display')) {
                 $code->addProperty(new Property('*display', 'inline'))->vendor = 'ms';
             }
         }
     });
 }
Ejemplo n.º 7
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  * @param int $rem The default value for rem. This value can be overwritten for the font-face property in :root, html or body
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         foreach ($code->getProperties() as $property) {
             if ($property->value === 'initial') {
                 if (isset(Initial::$initials[$property->name])) {
                     $property->value = self::$initials[$property->name];
                 } else {
                     $property->value = 'inherit';
                 }
             }
         }
     });
 }
Ejemplo n.º 8
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         if ($property = $code->getLastProperty('opacity')) {
             $filter = 'alpha(opacity=' . $property->value * 100 . ')';
             if ($filterProperty = $code->getLastProperty('filter')) {
                 $filterProperty->addValue($filter);
                 $filterProperty->vendor = 'ms';
             } else {
                 $code->addProperty(new Property('filter', $filter))->vendor = 'ms';
             }
         }
     });
 }
Ejemplo n.º 9
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         while (strpos((string) $code->selector, ':matches(') !== false) {
             foreach ($code->selector->get() as $key => $selector) {
                 if (preg_match('/:matches\\(([^\\)]*)\\)/', $selector, $match)) {
                     $code->selector->delete($key);
                     foreach (Parser::explodeTrim(',', $match[1]) as $matchSelector) {
                         $code->selector->add(str_replace($match[0], $matchSelector, $selector));
                     }
                 }
             }
         }
     });
 }
Ejemplo n.º 10
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         if ($property = $code->getLastProperty(array('background', 'background-image'))) {
             $property->executeFunction('linear-gradient', function ($params, $name, $property) {
                 $filter = IeLinearGradient::getLinearGradientFilter($params);
                 if ($filterProperty = $property->parent->getLastProperty('filter')) {
                     $filterProperty->addValue($filter);
                     $filterProperty->vendor = 'ms';
                 } else {
                     $property->parent->addProperty(new Property('filter', $filter))->vendor = 'ms';
                 }
             });
         }
     });
 }
Ejemplo n.º 11
0
Archivo: Color.php Proyecto: jankal/mvc
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         foreach ($code->getProperties() as $property) {
             $property->executeFunction('color', function ($parameters) {
                 $rgba = Color::resolveColor(array_shift($parameters));
                 foreach ($parameters as $operation) {
                     if (strpos($operation, ':') === false) {
                         if (preg_match('/^[\\+\\-]?[0-9]+$/', $operation)) {
                             $function = 'tint';
                             $value = $operation;
                         } else {
                             if (preg_match('/^[\\+\\-]?[0-9\\.]+$/', $operation)) {
                                 $function = 'alpha';
                                 $value = $operation;
                             } else {
                                 continue;
                             }
                         }
                     } else {
                         list($function, $value) = Parser::explodeTrim(':', $operation, 2);
                     }
                     switch ($function) {
                         case 'hue':
                         case 'saturation':
                         case 'light':
                             $rgba = Color::HSLA_RGBA(Color::editChannel(Color::RGBA_HSLA($rgba), $function, $value));
                             break;
                         case 'red':
                         case 'green':
                         case 'blue':
                         case 'alpha':
                             $rgba = Color::editChannel($rgba, $function, $value);
                             break;
                         case 'tint':
                             $rgba = Color::editTint($rgba, $value);
                             break;
                     }
                 }
                 if ($rgba[3] < 1) {
                     return 'rgba(' . implode(', ', $rgba) . ')';
                 }
                 return '#' . Color::RGBA_HEX($rgba);
             });
         }
     });
 }
Ejemplo n.º 12
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  * @param int $rem The default value for rem. This value can be overwritten for the font-face property in :root, html or body
  */
 public static function apply(Css $css, array $browser = null)
 {
     if (!$browser) {
         return;
     }
     foreach ($css->getArrayCopy() as $child) {
         if ($child->selector->type !== '@media') {
             continue;
         }
         if (self::checkMediaQueries($child->selector->get(), $browser)) {
             foreach ($child->getChildren() as $k => $grandChild) {
                 $child->parent->addChild($grandChild, $child->getPositionInParent() + $k);
             }
         }
         $child->removeFromParent();
     }
 }
Ejemplo n.º 13
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  * @param int $rem The default value for rem. This value can be overwritten for the font-face property in :root, html or body
  */
 public static function apply(Css $css, $baseUrl)
 {
     $css->executeRecursive(function ($code) use($baseUrl) {
         foreach ($code->getProperties() as $property) {
             $property->executeFunction('url', function ($params) use($baseUrl) {
                 $url = $params[0];
                 if ($url[0] === "'" || $url[0] === '"') {
                     $url = substr($url, 1, -1);
                 }
                 if (parse_url($url, PHP_URL_SCHEME) || $url[0] === '/') {
                     return;
                 }
                 return 'url(\'' . $baseUrl . $url . '\')';
             });
         }
     });
 }
Ejemplo n.º 14
0
 /**
  * Add prefix to selectors.
  * @param Css $css The css object.
  * @param string $prefix Prefix to add.
  */
 public static function apply(Css $css, $prefix = '')
 {
     if (empty($prefix)) {
         return;
     }
     $css->executeRecursive(function ($code) use($prefix) {
         if (!$code->selector->type) {
             $selectors = $code->selector->get();
             if (!empty($selectors)) {
                 foreach ($selectors as &$v) {
                     $v = $prefix . ' ' . $v;
                 }
                 unset($v);
             }
             $code->selector->set($selectors);
         }
     });
 }
Ejemplo n.º 15
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         if (isset($code->parent) && isset($code->parent->parent) && !$code->parent->selector->type && ($parentSelectors = $code->parent->selector->get())) {
             $selectors = $code->selector->get();
             $code->selector->delete();
             foreach ($selectors as $selector) {
                 $selector = $selector[0] == '&' ? substr($selector, 1) : ' ' . $selector;
                 foreach ($parentSelectors as $parentSelector) {
                     $code->selector->add($parentSelector . $selector);
                 }
             }
             $position = $code->getPositionInParent() - 1;
             $parent = $code->parent;
             $code->removeFromParent();
             $parent->parent->addChild($code, $position);
         }
     });
 }
Ejemplo n.º 16
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         if ($property = $code->getLastProperty('transform')) {
             $property->executeFunction(null, function ($params, $name, $property) {
                 switch ($name) {
                     case 'rotate':
                         $filter = IeTransform::getRotateFilter($params);
                         break;
                     case 'scaleX':
                         if ($params[0] == '-1') {
                             $filter = 'flipH';
                         } else {
                             return null;
                         }
                         break;
                     case 'scaleY':
                         if ($params[0] == '-1') {
                             $filter = 'flipV';
                         } else {
                             return null;
                         }
                         break;
                     case 'scale':
                         if (isset($params[0], $params[1]) && $params[0] == '-1' && $params[1] == '-1') {
                             $filter = array('flipH', 'flipV');
                         } else {
                             return null;
                         }
                         break;
                     default:
                         return null;
                 }
                 if ($filterProperty = $property->parent->getLastProperty('filter')) {
                     $filterProperty->addValue($filter);
                     $filterProperty->vendor = 'ms';
                 } else {
                     $property->parent->addProperty(new Property('filter', $filter))->vendor = 'ms';
                 }
             });
         }
     });
 }
Ejemplo n.º 17
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         if (isset($code->parent->parent) && empty($code->parent->selector->type) && ($parentSelectors = $code->parent->selector->get())) {
             $selectors = $code->selector->get();
             $code->selector->delete();
             foreach ($selectors as $selector) {
                 $selector = $selector[0] == '&' ? substr($selector, 1) : ' ' . $selector;
                 foreach ($parentSelectors as $parentSelector) {
                     $code->selector->add($parentSelector . $selector);
                 }
             }
         }
         $firstParent = NestedRules::getRootParent($code);
         if ($firstParent) {
             $firstParent->addChild($code);
         }
     });
 }
Ejemplo n.º 18
0
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  * @param int $rem The default value for rem. This value can be overwritten for the font-face property in :root, html or body
  */
 public static function apply(Css $css, $rem = 16)
 {
     foreach ($css->getChildren(array(':root', 'html', 'body')) as $child) {
         foreach ($child->getProperties('font-size') as $property) {
             $rem = Rem::rootPixels($property->value);
         }
     }
     $css->executeRecursive(function ($code) use($rem) {
         foreach ($code->getProperties() as $property) {
             if (strpos($property->value, 'rem') === false) {
                 continue;
             }
             $value = preg_replace_callback('/([0-9\\.]+)rem/', function ($matches) use($rem) {
                 return Rem::toPixels($matches[1], $rem);
             }, $property->value);
             if ($property->value !== $value) {
                 $code->addProperty(new Property($property->name, $value), $property->getPositionInParent());
             }
         }
     });
 }
Ejemplo n.º 19
0
Archivo: Math.php Proyecto: jankal/mvc
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  */
 public static function apply(Css $css)
 {
     $css->executeRecursive(function ($code) {
         foreach ($code->getProperties() as $property) {
             $property->executeFunction('math', function ($parameters) {
                 $units = '';
                 $operations = $parameters[0];
                 if (strpos($operations, 'px')) {
                     $units = 'px';
                     $operations = str_replace('px', '', $operations);
                 } else {
                     if (strpos($operations, '%')) {
                         $units = '%';
                         $operations = str_replace('%', '', $operations);
                     } else {
                         if (strpos($operations, 'em')) {
                             $units = 'em';
                             $operations = str_replace('em', '', $operations);
                         } else {
                             if (strpos($operations, 'rem')) {
                                 $units = 'rem';
                                 $operations = str_replace('rem', '', $operations);
                             } else {
                                 if (strpos($operations, 'pt')) {
                                     $units = 'pt';
                                     $operations = str_replace('pt', '', $operations);
                                 }
                             }
                         }
                     }
                 }
                 if (preg_match('/^[\\+\\*\\/\\.\\(\\)0-9- ]*$/', $operations)) {
                     $calculate = create_function('', 'return(' . $operations . ');');
                     return round($calculate(), 2) . $units;
                 }
             });
         }
     });
 }
Ejemplo n.º 20
0
 /**
  * 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();
 }
Ejemplo n.º 21
0
 /**
  * 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();
 }
Ejemplo n.º 22
0
Archivo: Grid.php Proyecto: jankal/mvc
 /**
  * Search and return the css variables in an array. Removes also the css property
  *
  * @param array $properties The piece of the parsed css code with the properties
  *
  * @return array The transformed code
  */
 public static function getGrid(Css $css)
 {
     $grid = array();
     $gridChild = $css->getChildren('$grid');
     if (isset($gridChild[0])) {
         $gridChild[0]->removeFromParent();
         foreach ($gridChild[0]->getProperties(array('width', 'columns', 'gutter')) as $property) {
             $grid[$property->name] = $property->value;
         }
     }
     return $grid;
 }
Ejemplo n.º 23
0
 /**
  * Check @import in css and include it.
  * Extends Stylecow\Parser::parseImport
  * @param Stylecow\Css $css
  * @param string $file
  */
 protected function checkCssImport($css, $file)
 {
     $remove = array();
     foreach ($css as $c) {
         if ($c->selector->type == '@import' && !empty($c->selector->selectors[0])) {
             $impFile = trim(str_replace(array('\'', '"', 'url(', ')'), '', $c->selector->selectors[0]));
             $impFile = $this->getValidUrl($impFile, dirname($file));
             $import = $this->loadCss($impFile);
             if ($import) {
                 foreach ($import->getChildren() as $child) {
                     $css->addChild($child);
                 }
                 array_push($remove, $c);
             }
         }
     }
     foreach ($remove as $c) {
         $c->removeFromParent();
     }
 }