32 public static function process($css, $options = array())
35 return $obj->_process($css);
58 private function __construct($options) {
59 $this->_options = $options;
71 $css = str_replace(
"\r\n",
"\n", $css);
75 $css = preg_replace(
'@>/\\*\\s*\\*/@',
'>/*keep*/', $css);
79 $css = preg_replace(
'@/\\*\\s*\\*/\\s*:@',
'/*keep*/:', $css);
80 $css = preg_replace(
'@:\\s*/\\*\\s*\\*/@',
':/*keep*/', $css);
83 $css = preg_replace_callback(
'@\\s*/\\*([\\s\\S]*?)\\*/\\s*@'
84 ,array($this,
'_commentCB'), $css);
87 $css = preg_replace(
'/\\s*{\\s*/',
'{', $css);
88 $css = preg_replace(
'/;?\\s*}\\s*/',
'}', $css);
91 $css = preg_replace(
'/\\s*;\\s*/',
';', $css);
94 $css = preg_replace(
'/
97 ([^\\)]+?) # 1 = the URL (really just a bunch of non right parenthesis)
100 /x',
'url($1)', $css);
103 $css = preg_replace(
'/
105 ([{;]) # 1 = beginning of block or rule separator
107 ([\\*_]?[\\w\\-]+) # 2 = property (and maybe IE filter)
111 (\\b|[#\'"]) # 3 = first character of a value
112 /x',
'$1$2:$3', $css);
115 $css = preg_replace_callback(
'/
118 [^~>+,\\s]+ # selector part
123 [^~>+,\\s]+ # selector part
124 { # open declaration block
126 ,array($this,
'_selectorsCB'), $css);
129 $css = preg_replace(
'/([^=])#([a-f\\d])\\2([a-f\\d])\\3([a-f\\d])\\4([\\s;\\}])/i'
130 ,
'$1#$2$3$4$5', $css);
133 $css = preg_replace_callback(
'/font-family:([^;}]+)([;}])/'
134 ,array($this,
'_fontFamilyCB'), $css);
136 $css = preg_replace(
'/@import\\s+url/',
'@import url', $css);
139 $css = preg_replace(
'/[ \\t]*\\n+\\s*/',
"\n", $css);
142 $css = preg_replace(
'/([\\w#\\.\\*]+)\\s+([\\w#\\.\\*]+){/',
"$1\n$2{", $css);
145 $css = preg_replace(
'/
146 ((?:padding|margin|border|outline):\\d+(?:px|em)?) # 1 = prop : 1st numeric value
152 $css = preg_replace(
'/:first-l(etter|ine)\\{/',
':first-l$1 {', $css);
167 return preg_replace(
'/\\s*([,>+~])\\s*/',
'$1', $m[0]);
179 $hasSurroundingWs = (trim($m[0]) !== $m[1]);
190 if (preg_match(
'@";\\}\\s*\\}/\\*\\s+@', $m)) {
192 return '/*";}}/* */';
194 if ($this->_inHack) {
197 ^/ # comment started like /*/
199 (\\S[\\s\\S]+?) # has at least some non-ws content
201 /\\* # ends like /*/ or /**/
204 $this->_inHack =
false;
205 return "/*/{$n[1]}/**/";
208 if (substr($m, -1) ===
'\\') {
210 $this->_inHack =
true;
213 if ($m !==
'' && $m[0] ===
'/') {
215 $this->_inHack =
true;
218 if ($this->_inHack) {
220 $this->_inHack =
false;
225 return $hasSurroundingWs
239 $m[1] = preg_replace(
'/
242 "[^"]+" # 1 = family in double qutoes
243 |\'[^\']+\' # or 1 = family in single quotes
244 |[\\w\\-]+ # or 1 = unquoted family
248 return 'font-family:' . $m[1] . $m[2];