Skip to content

Commit

Permalink
Fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
tubalmartin committed Sep 17, 2014
1 parent 96ab44c commit ce9a074
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cssmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private function minify($css, $linebreak_pos)
$css = preg_replace('/([^\\\\]\:|\s)0(?:em|ex|ch|rem|vw|vh|vm|vmin|cm|mm|in|px|pt|pc|%)/iS', '${1}0', $css);

// 0% step in a keyframe? restore the % unit
$css = preg_replace_callback('/(@[a-z\-]*?keyframes[^\{]*?\{)(.*?\}\s*\})/iS', array($this, 'replace_keyframe_zero'), $css);
$css = preg_replace_callback('/(@[a-z\-]*?keyframes[^\{]+\{)(.*?)(\}\})/iS', array($this, 'replace_keyframe_zero'), $css);

// Replace 0 0; or 0 0 0; or 0 0 0 0; with 0.
$css = preg_replace('/\:0(?: 0){1,3}(;|\}| \!)/', ':0$1', $css);
Expand Down Expand Up @@ -598,7 +598,7 @@ private function preserve_old_IE_specific_matrix_definition($matches)

private function replace_keyframe_zero($matches)
{
return $matches[1] . preg_replace('/0\s*,/', '0%,', preg_replace('/\s*0\s*\{/', '0%{', $matches[2]));
return $matches[1] . preg_replace('/0(\{|,[^\{]+\{)/', '0%$1', $matches[2]) . $matches[3];
}

private function rgb_to_hex($matches)
Expand Down
3 changes: 3 additions & 0 deletions tests/mine/keyframes.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
@keyframes test3 {
50% { opacity: 50 }
100%, 0% { opacity: 0; }
}
@-webkit-keyframes test4{
0% { transform: rotate3d(0,0,1,30deg); }
}
2 changes: 1 addition & 1 deletion tests/mine/keyframes.css.min
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@keyframes anim{0%{opacity:0}100%{opacity:1}}@-o-keyframes anim{0%{opacity:0}100%{opacity:1}}@keyframes test{0%,100%{opacity:0}}@keyframes test2{0%,100%{opacity:0}}@keyframes test3{50%{opacity:50}100%,0%{opacity:0}}
@keyframes anim{0%{opacity:0}100%{opacity:1}}@-o-keyframes anim{0%{opacity:0}100%{opacity:1}}@keyframes test{0%,100%{opacity:0}}@keyframes test2{0%,100%{opacity:0}}@keyframes test3{50%{opacity:50}100%,0%{opacity:0}}@-webkit-keyframes test4{0%{transform:rotate3d(0,0,1,30deg)}}
1 change: 1 addition & 0 deletions tests/mine/zeros.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ a{
padding: +0000% 0.0% 0in 00.000;
margin:-.0em .000pc +0px -00.0000%;
transition-duration: 0s;
left: -20.0px;
}
b{
leading: 0050% -0010.5% 001.004in -0.45vw;
Expand Down
2 changes: 1 addition & 1 deletion tests/mine/zeros.css.min
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a{padding:0;margin:0;transition-duration:0s}b{leading:50% -10.5% 1.004in -.45vw;trailing:5000% .5px 1.2001em .405;transition-duration:0ms;transform:rotate3d(0grad,0rad,0deg);pitch:0KHZ;pitch:0hz}body{margin:9px 9.8px 0 .9em;height:9.9;width:.5;z-index:.09;font-size:9;top:0;bottom:0}:lang(de)>p.lang\:0\.234500{height:.2em}#\:34\:0500{width:10.01%}.mg0px .lang\:0em{height:20%}
a{padding:0;margin:0;transition-duration:0s;left:-20px}b{leading:50% -10.5% 1.004in -.45vw;trailing:5000% .5px 1.2001em .405;transition-duration:0ms;transform:rotate3d(0grad,0rad,0deg);pitch:0KHZ;pitch:0hz}body{margin:9px 9.8px 0 .9em;height:9.9;width:.5;z-index:.09;font-size:9;top:0;bottom:0}:lang(de)>p.lang\:0\.234500{height:.2em}#\:34\:0500{width:10.01%}.mg0px .lang\:0em{height:20%}

0 comments on commit ce9a074

Please sign in to comment.