Flip rules like left: , padding-right: , etc.
@param $css string
@return string
490523
private static function fixLeftAndRight($css) {
		$css = preg_replace(self::$patterns['left'], self::$patterns['tmpToken'], $css);
		$css = preg_replace(self::$patterns['right'], 'left', $css);
		$css = str_replace(self::$patterns['tmpToken'], 'right', $css);

		return $css;
	}
292723
public function parseStylesheet($stylesheet)
    {
        $parsed = array();
        $stylesheet = $this->_stripStylesheet($stylesheet);
        $stylesheet = trim(trim($stylesheet), "}");
        foreach(explode("}", $stylesheet) as $rule) {
            //Don't parse empty rules
        	if(!trim($rule))continue;
        	list($selector, $style) = explode("{", $rule, 2);
            foreach (explode(',', $selector) as $sel) {
                $parsed[] = array(trim($sel), trim(trim($style), ";"));
            }
        }

        return $parsed;
    }
744598
public function getCustomCSSPrefix()
    {
        if ($parent = $this->getParent()) {
            return sprintf('%s %s', $parent->CSSID, $this->CSSID);
        }
        
        return $this->CSSID;
    }
643534
public function rules($styles)
	{
		// Remove comments.
		$comment = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $styles);

		// Make it into one long line.
		$lineCss = str_replace(["\n", "\r"], '', $comment);

		// Replace all multiple spaces by one space.
		$spaces  = preg_replace('!\s+!', ' ', $lineCss);

		// Replace some unneeded spaces, modify as needed.
		$rules   = [' {', ' }', '{ ', '} ', '; ', ';}', ': ', ', ', ' 0.', '.0%', '-0.', '.0rem', '.0em', '.0px', ':0.'];
		$replace = ['{' , '}' , '{' , '}' , ';' , '}' , ':' , ',' , ' .' , '%'  , '-.' , 'rem'  , 'em'  , 'px'  , ':.' ];

		// Output processed styles.
		$output  = str_replace($rules, $replace, $spaces);
		return $output;
	}
960209
public function setCss($css)
    {
        if (is_array($css))
            $css = implode(' ', $css);

        $this->css = $css;

        return $this;
    }
1335252
public function split($css = null, $part = 1, $maxSelectors = self::MAX_SELECTORS_DEFAULT)
	{
		if (empty($css) && empty($this->css)) {
			return null;
		}

		if (!empty($css) && $this->css !== $css) {
			$this->css = $css;
		}

		$charset = $this->extractCharset($this->css);
		isset($charset) && $this->css = str_replace($charset, '', $this->css);
		if (empty($this->css)) {
			return null;
		}

		$this->parsedCss = $this->splitIntoBlocks($this->css);
		if (empty($this->parsedCss)) {
			return null;
		}

		$output    = $charset ? : '';
		$count     = 0;
		$partCount = 1;
		foreach ($this->parsedCss as $block) {
			$appliedMedia = false;
			foreach ($block['rules'] as $rule) {
				$tmpCount = $rule['count'];

				// we have a new part so let's reset and increase
				if (($count + $tmpCount) > $maxSelectors) {
					$partCount++;
					$count = 0;
				}

				$count += $tmpCount;
				if ($partCount < $part) {
					continue;
				}
				if ($partCount > $part) {
					break;
				}

				if (!$appliedMedia && isset($block['at-rule'])) {
					$output .= $block['at-rule'] . ' {';
					$appliedMedia = true;
				}
				$output .= $rule['rule'];
			}
			$appliedMedia && $output .= '}';
		}

		return $output;
	}
479670
public function convertToRadius($css)
    {
        // explode the value
        $css = explode(' ', $css);

        foreach ($css as $k => $v) {
            $v = trim($v);
            if ($v) {
                $v = $this->convertToMM($v, 0);
                if ($v!==null) {
                    $css[$k] = $v;
                } else {
                    unset($css[$k]);
                }
            } else {
                unset($css[$k]);
            }
        }

        return array_values($css);
    }
1105788
public static function css_to_string($css){
    if ( \is_string($css) ){
      return ' style="'.bbn\str::escape_dquotes($css).'"';
    }
    else if ( \is_array($css) && \count($css) > 0 ){
      $st = '';
      foreach ( $css as $prop => $val ){
        $st .= $prop.':'.$val.';';
      }
      return ' style="'.bbn\str::escape_dquotes($st).'"';
    }
  }
29655
protected function parseCssClasses($classes)
    {
        if (is_string($classes)) {
            $classes = explode(' ', $classes);
        }

        if (!is_array($classes)) {
            throw new InvalidArgumentException('CSS Class(es) must be a space-delimited string or an array');
        }

        return array_filter($classes, 'strlen');
    }
325890
private function extractMediaQueriesFromCss($css)
    {
        preg_match_all('/@media\\b[^{]*({((?:[^{}]+|(?1))*)})/', $css, $rawMediaQueries, PREG_SET_ORDER);
        $parsedQueries = [];

        /** @var string[][] $rawMediaQueries */
        foreach ($rawMediaQueries as $mediaQuery) {
            if ($mediaQuery[2] !== '') {
                $parsedQueries[] = [
                    'css' => $mediaQuery[2],
                    'query' => $mediaQuery[0],
                ];
            }
        }

        return $parsedQueries;
    }
628896
public function getRules($css, $existingRules = array())
    {
        $css = $this->doCleanup($css);
        $rulesProcessor = new RuleProcessor();
        $rules = $rulesProcessor->splitIntoSeparateRules($css);

        return $rulesProcessor->convertArrayToObjects($rules, $existingRules);
    }
781010
public function run($css = '', $linebreak_pos = FALSE)
    {
        if (empty($css)) {
            return '';
        }

        if ($this->raise_php_limits) {
            $this->do_raise_php_limits();
        }

        $this->comments = array();
        $this->preserved_tokens = array();

        $start_index = 0;
        $length = strlen($css);

        $css = $this->extract_data_urls($css);

        // collect all comment blocks...
        while (($start_index = $this->index_of($css, '/*', $start_index)) >= 0) {
            $end_index = $this->index_of($css, '*/', $start_index + 2);
            if ($end_index < 0) {
                $end_index = $length;
            }
            $comment_found = $this->str_slice($css, $start_index + 2, $end_index);
            $this->comments[] = $comment_found;
            $comment_preserve_string = self::COMMENT . (count($this->comments) - 1) . '___';
            $css = $this->str_slice($css, 0, $start_index + 2) . $comment_preserve_string . $this->str_slice($css, $end_index);
            // Set correct start_index: Fixes issue #2528130
            $start_index = $end_index + 2 + strlen($comment_preserve_string) - strlen($comment_found);
        }

        // preserve strings so their content doesn't get accidentally minified
        $css = preg_replace_callback('/(?:"(?:[^\\\\"]|\\\\.|\\\\)*")|'."(?:'(?:[^\\\\']|\\\\.|\\\\)*')/S", array($this, 'replace_string'), $css);

        // Let's divide css code in chunks of 25.000 chars aprox.
        // Reason: PHP's PCRE functions like preg_replace have a "backtrack limit"
        // of 100.000 chars by default (php < 5.3.7) so if we're dealing with really
        // long strings and a (sub)pattern matches a number of chars greater than
        // the backtrack limit number (i.e. /(.*)/s) PCRE functions may fail silently
        // returning NULL and $css would be empty.
        $charset = '';
        $charset_regexp = '/@charset [^;]+;/i';
        $css_chunks = array();
        $css_chunk_length = 25000; // aprox size, not exact
        $start_index = 0;
        $i = $css_chunk_length; // save initial iterations
        $l = strlen($css);


        // if the number of characters is 25000 or less, do not chunk
        if ($l <= $css_chunk_length) {
            $css_chunks[] = $css;
        } else {
            // chunk css code securely
            while ($i < $l) {
                $i += 50; // save iterations. 500 checks for a closing curly brace }
                if ($l - $start_index <= $css_chunk_length || $i >= $l) {
                    $css_chunks[] = $this->str_slice($css, $start_index);
                    break;
                }
                if ($css[$i - 1] === '}' && $i - $start_index > $css_chunk_length) {
                    // If there are two ending curly braces }} separated or not by spaces,
                    // join them in the same chunk (i.e. @media blocks)
                    $next_chunk = substr($css, $i);
                    if (preg_match('/^\s*\}/', $next_chunk)) {
                        $i = $i + $this->index_of($next_chunk, '}') + 1;
                    }

                    $css_chunks[] = $this->str_slice($css, $start_index, $i);
                    $start_index = $i;
                }
            }
        }

        // Minify each chunk
        for ($i = 0, $n = count($css_chunks); $i < $n; $i++) {
            $css_chunks[$i] = $this->minify($css_chunks[$i], $linebreak_pos);
            // Keep the first @charset at-rule found
            if (empty($charset) && preg_match($charset_regexp, $css_chunks[$i], $matches)) {
                $charset = $matches[0];
            }
            // Delete all @charset at-rules
            $css_chunks[$i] = preg_replace($charset_regexp, '', $css_chunks[$i]);
        }

        // Update the first chunk and push the charset to the top of the file.
        $css_chunks[0] = $charset . $css_chunks[0];

        return implode('', $css_chunks);
    }
713040
public function extract_first($css, $rules)
    {
        $nodes = $this->_document->getQuery()->css($css);

        if ($nodes) {
            return (new static($this->_document, $nodes->item(0)))->extract($rules);
        } else {
            return [];
        }
    }
765225
public static function parse_css($styles='') {
		ref\cast::string($styles, true);

		// Remove comments.
		while (false !== ($start = mb::strpos($styles, '/*'))) {
			if (false !== ($end = mb::strpos($styles, '*/'))) {
				$styles = \str_replace(
					mb::substr($styles, $start, ($end - $start + 2)),
					'',
					$styles
				);
			}
			else {
				$styles = mb::substr($styles, 0, $start);
			}
		}

		// A few more types of comment wrappers we might see.
		$styles = \str_replace(
			array('<!--', '//-->', '-->', '//<![CDATA[', '//]]>', '<![CDATA[', ']]>'),
			'',
			$styles
		);

		// Standardize quoting.
		ref\sanitize::quotes($styles);
		$styles = \str_replace("'", '"', $styles);

		// Whitespace.
		ref\sanitize::whitespace($styles, 0);

		// Early bail.
		if (! $styles) {
			return array();
		}

		// Substitute brackets for unlikely characters to make parsing easier
		// hopefully nobody's using braille in their stylesheets...
		$styles = \preg_replace('/\{(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)/u', '⠁', $styles);
		$styles = \preg_replace('/\}(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)/u', '⠈', $styles);

		// Put spaces behind and after parentheses.
		$styles = \preg_replace(
			'/\s*(\()\s*(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)/u',
			' (',
			$styles
		);
		$styles = \preg_replace(
			'/\s*(\))\s*(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)/u',
			') ',
			$styles
		);

		// Make sure {} have no whitespace on either end.
		$styles = \preg_replace('/\s*(⠁|⠈|@)\s*/u', '$1', $styles);

		// Push @ rules to their own lines.
		$styles = \str_replace('@', "\n@", $styles);
		$styles = \explode("\n", $styles);
		$styles = \array_map('trim', $styles);

		// Push all rulesets to their own lines (leaving @media-type ones on their own for now).
		foreach ($styles as $k=>$v) {
			// @rule.
			if (0 === \strpos($styles[$k], '@')) {
				// Nested, like @media.
				if (false !== \strpos($styles[$k], '⠈⠈')) {
					$styles[$k] = \preg_replace('/(⠈{2,})/u', "$1\n", $styles[$k]);
				}
				// Not nested, but has properties, like @font-face.
				elseif (false !== \strpos($styles[$k], '⠈')) {
					$styles[$k] = \str_replace('⠈', "⠈\n", $styles[$k]);
				}
				// Just a line, like @import.
				elseif (\preg_match('/;(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)/', $styles[$k])) {
					$styles[$k] = \preg_replace(
						'/;(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)/u',
						";\n",
						$styles[$k],
						1
					);
				}

				$tmp = \explode("\n", $styles[$k]);
				$length = \count($tmp);
				for ($x = 1; $x < $length; ++$x) {
					$tmp[$x] = \str_replace('⠈', "⠈\n", $tmp[$x]);
				}
				$styles[$k] = \implode("\n", $tmp);
			}// end @.
			else {
				$styles[$k] = \str_replace('⠈', "⠈\n", $styles[$k]);
			}
		}
		$styles = \implode("\n", $styles);

		// One more quick formatting thing, we can get rid of spaces
		// between closing) and punctuation.
		$styles = \preg_replace(
			'/\)\s(,|;)(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)/u',
			')$1',
			$styles
		);

		// And between RGB/URL stuff.
		$styles = \preg_replace('/(url|rgba?)\s+\(/', '$1(', $styles);

		$styles = \explode("\n", $styles);
		$styles = \array_filter($styles, 'strlen');

		$out = array();

		// One more time around!
		foreach ($styles as $k=>$v) {
			$styles[$k] = \trim($styles[$k]);

			// Nested rule.
			if (
				(0 === \strpos($styles[$k], '@')) &&
				(false !== \strpos($styles[$k], '⠈⠈'))
			) {
				$tmp = constants::CSS_NESTED;

				// What kind of @ is this?
				\preg_match_all('/^@([a-z\-]+)/ui', $styles[$k], $matches);
				$tmp['@'] = mb::strtolower($matches[1][0]);

				// Find the outermost bit.
				if (false === ($start = mb::strpos($styles[$k], '⠁'))) {
					continue;
				}

				$tmp['selector'] = mb::strtolower(
					\trim(
						mb::substr($styles[$k], 0, $start)
					),
					false,
					true
				);
				$chunk = mb::substr($styles[$k], $start + 1, -1);
				$chunk = \str_replace(array('⠁', '⠈'), array('{', '}'), $chunk);
				$tmp['nest'] = static::parse_css($chunk);

				// And build the raw.
				$tmp['raw'] = $tmp['selector'] . '{';
				foreach ($tmp['nest'] as $n) {
					$tmp['raw'] .= $n['raw'];
				}
				$tmp['raw'] .= '}';
			}// end @.
			else {
				$tmp = constants::CSS_FLAT;

				if (0 === \strpos($styles[$k], '@')) {
					// What kind of @ is this?
					\preg_match_all('/^@([a-z\-]+)/ui', $styles[$k], $matches);
					$tmp['@'] = mb::strtolower($matches[1][0], false);
				}

				// A normal {k:v, k:v}.
				\preg_match_all('/^([^⠁]+)⠁([^⠈]*)⠈/u', $styles[$k], $matches);
				if (\count($matches[0])) {
					// Sorting out selectors is easy.
					$tmp['selectors'] = \explode(',', $matches[1][0]);
					$tmp['selectors'] = \array_map('trim', $tmp['selectors']);

					// Rules a little trickier.
					$rules = \explode(';', $matches[2][0]);
					$rules = \array_map('trim', $rules);
					$rules = \array_filter($rules, 'strlen');
					if (! \count($rules)) {
						continue;
					}

					foreach ($rules as $k2=>$v2) {
						$rules[$k2] = \rtrim($rules[$k2], ';') . ';';
						if (\preg_match(
							'/:(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)/',
							$rules[$k2]
						)) {
							$rules[$k2] = \preg_replace(
								'/:(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)/u',
								"\n",
								$rules[$k2],
								1
							);
							list($key, $value) = \explode("\n", $rules[$k2]);
							$key = mb::strtolower(\trim($key), false);
							$value = \trim($value);
							$tmp['rules'][$key] = $value;
						}
						else {
							$tmp['rules']['__NONE__'] = $value;
						}
					}

					// Build the raw.
					$tmp['raw'] = \implode(',', $tmp['selectors']) . '{';
					foreach ($tmp['rules'] as $k=>$v) {
						if ('__NONE__' === $k) {
							$tmp['raw'] .= $v;
						}
						else {
							$tmp['raw'] .= "$k:$v";
						}
					}
					$tmp['raw'] .= '}';
				}
				// Who knows?
				else {
					$styles[$k] = \str_replace(array('⠁', '⠈'), array('{', '}'), $styles[$k]);
					$styles[$k] = \trim(\rtrim(\trim($styles[$k]), ';'));
					if (\substr($styles[$k], -1) !== '}') {
						$styles[$k] .= ';';
					}
					$tmp['rules'][] = $styles[$k];
					$tmp['raw'] = $styles[$k];
				}
			}

			$out[] = $tmp;
		}

		return $out;
	}
891479
public function css($css)
    {
        if ($css === '') {
            return clone $this;
        }

        $query = $this->_document->getQuery();
        $nodes = [];
        foreach ($this->_nodes as $node) {
            /**
             * @var \DOMNode $node2
             */
            foreach ($query->css($css, $node) as $node2) {
                $nodes[$node2->getNodePath()] = $node2;
            }
        }

        return new SelectorList($this, array_values($nodes));
    }
1330172
public static function baseCss($css = null)
    {
        if (!is_null($css)) {
            return static::$baseCss = $css;
        }

        $skin = config('admin.skin', 'skin-blue-light');

        array_unshift(static::$baseCss, "vendor/laravel-admin/AdminLTE/dist/css/skins/{$skin}.min.css");

        return static::$baseCss;
    }
707451
public function escapeCss($css)
    {
        $css = $this->toUtf8($css);

        if ($css === '' || ctype_digit($css)) {
            return $css;
        }

        $result = preg_replace_callback('/[^a-z0-9]/iSu', $this->cssMatcher, $css);

        return $this->fromUtf8($result);
    }