32 public static function process($css, $options = array())
35 return $obj->_process($css);
56 private function __construct($options) {
57 $this->_options = $options;
69 if ($this->_options[
'do_compress']) {
70 $css = str_replace(
"\r\n",
"\n", $css);
74 $css = preg_replace(
'@>/\\*\\s*\\*/@',
'>/*keep*/', $css);
78 $css = preg_replace(
'@/\\*\\s*\\*/\\s*:@',
'/*keep*/:', $css);
79 $css = preg_replace(
'@:\\s*/\\*\\s*\\*/@',
':/*keep*/', $css);
82 $css = preg_replace_callback(
'@\\s*/\\*([\\s\\S]*?)\\*/\\s*@'
83 ,array($this,
'_commentCB'), $css);
85 if ($this->_options[
'do_compress']) {
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);
130 $css = preg_replace(
'/([^=])#([a-f\\d])\\2([a-f\\d])\\3([a-f\\d])\\4([\\s;\\}])/i'
131 ,
'$1#$2$3$4$5', $css);
134 $css = preg_replace_callback(
'/font-family:([^;}]+)([;}])/'
135 ,array($this,
'_fontFamilyCB'), $css);
137 $css = preg_replace(
'/@import\\s+url/',
'@import url', $css);
140 $css = preg_replace(
'/[ \\t]*\\n+\\s*/',
"\n", $css);
143 $css = preg_replace(
'/([\\w#\\.\\*]+)\\s+([\\w#\\.\\*]+){/',
"$1\n$2{", $css);
146 $css = preg_replace(
'/
147 ((?:padding|margin|border|outline):\\d+(?:px|em)?) # 1 = prop : 1st numeric value
153 $css = preg_replace(
'/:first-l(etter|ine)\\{/',
':first-l$1 {', $css);
168 return preg_replace(
'/\\s*([,>+~])\\s*/',
'$1', $m[0]);
180 $hasSurroundingWs = (trim($m[0]) !== $m[1]);
191 if (preg_match(
'@";\\}\\s*\\}/\\*\\s+@', $m)) {
193 return '/*";}}/* */';
195 if ($this->_inHack) {
198 ^/ # comment started like /*/
200 (\\S[\\s\\S]+?) # has at least some non-ws content
202 /\\* # ends like /*/ or /**/
205 $this->_inHack =
false;
206 return "/*/{$n[1]}/**/";
209 if (substr($m, -1) ===
'\\') {
211 $this->_inHack =
true;
214 if ($m !==
'' && $m[0] ===
'/') {
216 $this->_inHack =
true;
219 if ($this->_inHack) {
221 $this->_inHack =
false;
226 return $hasSurroundingWs
241 $pieces = preg_split(
'/(\'[^\']+\'|"[^"]+")/', $m[1], null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
242 $out =
'font-family:';
243 while (null !== ($piece = array_shift($pieces))) {
244 if ($piece[0] !==
'"' && $piece[0] !==
"'") {
245 $piece = preg_replace(
'/\\s+/',
' ', $piece);
246 $piece = preg_replace(
'/\\s?,\\s?/',
',', $piece);
_fontFamilyCB($m)
Process a font-family listing and return a replacement.
_selectorsCB($m)
Replace what looks like a set of selectors.
static process($css, $options=array())
Minify a CSS string.
_process($css)
Minify a CSS string.
_commentCB($m)
Process a comment and return a replacement.