diff --git a/src/com/yahoo/platform/yui/compressor/CssCompressor.java b/src/com/yahoo/platform/yui/compressor/CssCompressor.java index 8a5cfe93..2e08ec61 100644 --- a/src/com/yahoo/platform/yui/compressor/CssCompressor.java +++ b/src/com/yahoo/platform/yui/compressor/CssCompressor.java @@ -338,7 +338,7 @@ public void compress(Writer out, int linebreakpos) } while (!(css.equals(oldCss))); // Replace 0(px,em,%) with 0 inside groups (e.g. -MOZ-RADIAL-GRADIENT(CENTER 45DEG, CIRCLE CLOSEST-SIDE, ORANGE 0%, RED 100%)) - p = Pattern.compile("(?i)\\( ?((?:[0-9a-z-.]+[ ,])*)?(?:0?\\.)?0(?:px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz)"); + p = Pattern.compile("(?i)\\( ?((?:[#0-9a-z-.]+[ ,])*)?(?:0?\\.)?0(?:px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz)"); do { oldCss = css; m = p.matcher(css); @@ -353,6 +353,12 @@ public void compress(Writer out, int linebreakpos) css = css.replaceAll(":0 0 0(;|})", ":0$1"); css = css.replaceAll(":0 0(;|})", ":0$1"); + // Replace "from" with "0%" in keyframes + css = css.replaceAll("([{},])from([{,])", "$10%$2"); + + // Replace "100%" with "to" in keyframes + css = css.replaceAll("([{},])100%([{,])", "$1to$2"); + // Replace background-position:0; with background-position:0 0; // same for transform-origin diff --git a/tests/background-gradient.css b/tests/background-gradient.css new file mode 100644 index 00000000..adf28e17 --- /dev/null +++ b/tests/background-gradient.css @@ -0,0 +1,10 @@ +.gradient { + background: #ffffff; + background: -moz-linear-gradient(top, #ffffff 0%, #f1f1f1 50%, #e1e1e1 51%, #f6f6f6 100%); + background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(50%,#f1f1f1), color-stop(51%,#e1e1e1), color-stop(100%,#f6f6f6)); + background: -webkit-linear-gradient(top, #ffffff 0%,#f1f1f1 50%,#e1e1e1 51%,#f6f6f6 100%); + background: -o-linear-gradient(top, #ffffff 0%,#f1f1f1 50%,#e1e1e1 51%,#f6f6f6 100%); + background: -ms-linear-gradient(top, #ffffff 0%,#f1f1f1 50%,#e1e1e1 51%,#f6f6f6 100%); + background: linear-gradient(to bottom, #ffffff 0%,#f1f1f1 50%,#e1e1e1 51%,#f6f6f6 100%); + filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#f6f6f6',GradientType=0 ); +} \ No newline at end of file diff --git a/tests/background-gradient.css.min b/tests/background-gradient.css.min new file mode 100644 index 00000000..2dcb3380 --- /dev/null +++ b/tests/background-gradient.css.min @@ -0,0 +1 @@ +.gradient{background:#fff;background:-moz-linear-gradient(top,#fff 0,#f1f1f1 50%,#e1e1e1 51%,#f6f6f6 100%);background:-webkit-gradient(linear,left top,left bottom,color-stop(0,#fff),color-stop(50%,#f1f1f1),color-stop(51%,#e1e1e1),color-stop(100%,#f6f6f6));background:-webkit-linear-gradient(top,#fff 0,#f1f1f1 50%,#e1e1e1 51%,#f6f6f6 100%);background:-o-linear-gradient(top,#fff 0,#f1f1f1 50%,#e1e1e1 51%,#f6f6f6 100%);background:-ms-linear-gradient(top,#fff 0,#f1f1f1 50%,#e1e1e1 51%,#f6f6f6 100%);background:linear-gradient(to bottom,#fff 0,#f1f1f1 50%,#e1e1e1 51%,#f6f6f6 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff',endColorstr='#f6f6f6',GradientType=0)} \ No newline at end of file diff --git a/tests/issue151.css.min b/tests/issue151.css.min index 00f934fb..de0e10c8 100644 --- a/tests/issue151.css.min +++ b/tests/issue151.css.min @@ -1 +1 @@ -@keyframes fadeIn{0%{opacity:0}100%{opacity:1}} +@keyframes fadeIn{0%{opacity:0}to{opacity:1}} diff --git a/tests/keyframes.css b/tests/keyframes.css new file mode 100644 index 00000000..a2dfc218 --- /dev/null +++ b/tests/keyframes.css @@ -0,0 +1,86 @@ +/* + * /(? '' + * /\/\*.*?\*\// -> '' + * ';}' -> '}' + * 'from' -> '0%' + * '100%' -> 'to' + */ + +/* steps defined by strings */ +@keyframes test1-1 { + from { + opacity: 1; + } + to { + opacity: 0; + } +} +@keyframes test1-2 { + to { + opacity: 0; + } + from { + opacity: 1; + } +} + +/* steps defined by percentage */ +@keyframes test2 { + 0% { + opacity: 1; + } + 50% { + opacity: 0.9; + } +} + +/* steps defined by percentage and strings */ +@keyframes test3 { + from { + opacity: 1; + } + 50% { + opacity: 0.9; + } + to { + opacity: 0.5; + } +} + +/* same value for multiple steps */ +@keyframes test4-1 { + 50%, 0%, to { + opacity: 0; + } + 25%, 75% { + opacity: 1; + } +} +@keyframes test4-2 { + 50%, from, to { + opacity: 0; + } + 25%, 75% { + opacity: 1; + } +} + +/* percent only steps, mixed order */ +@keyframes test5 { + 100% { + opacity: 0; + } + 0% { + opacity: 1; + } +} + +/* vendor prefixed */ +@-webkit-keyframes test6 { + 0%, 50% { + opacity: 1; + } + 100% { + opacity: 0; + } +} \ No newline at end of file diff --git a/tests/keyframes.css.min b/tests/keyframes.css.min new file mode 100644 index 00000000..b17a3209 --- /dev/null +++ b/tests/keyframes.css.min @@ -0,0 +1 @@ +@keyframes test1-1{0%{opacity:1}to{opacity:0}}@keyframes test1-2{to{opacity:0}0%{opacity:1}}@keyframes test2{0%{opacity:1}50%{opacity:.9}}@keyframes test3{0%{opacity:1}50%{opacity:.9}to{opacity:.5}}@keyframes test4-1{50%,0%,to{opacity:0}25%,75%{opacity:1}}@keyframes test4-2{50%,0%,to{opacity:0}25%,75%{opacity:1}}@keyframes test5{to{opacity:0}0%{opacity:1}}@-webkit-keyframes test6{0%,50%{opacity:1}to{opacity:0}} \ No newline at end of file