Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #253, additionally added keyframe shortening #214

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/com/yahoo/platform/yui/compressor/CssCompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/background-gradient.css
Original file line number Diff line number Diff line change
@@ -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 );
}
1 change: 1 addition & 0 deletions tests/background-gradient.css.min
Original file line number Diff line number Diff line change
@@ -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)}
2 changes: 1 addition & 1 deletion tests/issue151.css.min
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@keyframes fadeIn{0%{opacity:0}100%{opacity:1}}
@keyframes fadeIn{0%{opacity:0}to{opacity:1}}
86 changes: 86 additions & 0 deletions tests/keyframes.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* /(?<!keyframes)\s+/ -> ''
* /\/\*.*?\*\// -> ''
* ';}' -> '}'
* '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;
}
}
1 change: 1 addition & 0 deletions tests/keyframes.css.min
Original file line number Diff line number Diff line change
@@ -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}}