示例#1
0
文件: Grid.php 项目: 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, &$contextGrid) {
         $contextGrid = array_replace($contextGrid, Grid::getGrid($code));
         $arguments = array();
         $grid = $contextGrid;
         foreach ($code->getProperties('$grid') as $property) {
             $property->executeAllFunctions(function ($params, $name) use(&$grid, &$arguments) {
                 switch ($name) {
                     case 'cols':
                     case 'right':
                     case 'cols-width':
                     case 'left':
                     case 'in-cols':
                     case 'background':
                         $arguments[$name] = $params;
                         break;
                     case 'columns':
                     case 'width':
                     case 'gutter':
                         $grid = intval($params[0]);
                         break;
                 }
             });
             if ($arguments) {
                 foreach (Grid::getStyles($grid, $arguments) as $name => $value) {
                     if (!$code->hasProperty($name)) {
                         $code->addProperty(new Property($name, $value));
                     }
                 }
             }
         }
     }, array());
 }
示例#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(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';
                 }
             });
         }
     });
 }
示例#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';
         }
     });
 }
示例#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, $settings) {
         if (($property = $code->getLastProperty('min-height')) && !$code->hasProperty(array('_height', '*height', 'height'))) {
             $code->addProperty(new Property('_height', $property->value))->vendor = 'ms';
         }
     });
 }
示例#5
0
文件: IeClip.php 项目: 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) {
         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';
             }
         }
     });
 }
示例#6
0
文件: Variables.php 项目: jankal/mvc
 /**
  * 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);
 }
示例#7
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';
             }
         }
     });
 }
示例#8
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';
                 }
             }
         }
     });
 }
示例#9
0
文件: IeOpacity.php 项目: 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) {
         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';
             }
         }
     });
 }
示例#10
0
文件: Matches.php 项目: 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) {
         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));
                     }
                 }
             }
         }
     });
 }
示例#11
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';
                 }
             });
         }
     });
 }
示例#12
0
文件: Color.php 项目: 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);
             });
         }
     });
 }
示例#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 . '\')';
             });
         }
     });
 }
示例#14
0
文件: AddPrefix.php 项目: debuger/gsp
 /**
  * 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);
         }
     });
 }
示例#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->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);
         }
     });
 }
示例#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';
                 }
             });
         }
     });
 }
示例#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) && 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);
         }
     });
 }
示例#18
0
文件: Rem.php 项目: rrmodi88/stylecow
 /**
  * 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());
             }
         }
     });
 }
示例#19
0
文件: Math.php 项目: 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;
                 }
             });
         }
     });
 }
示例#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();
 }
示例#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();
 }