Skip to content

Commit

Permalink
Merge pull request yui#312 from Tofandel/patch-2
Browse files Browse the repository at this point in the history
Invalid transition and keyframes fix
  • Loading branch information
tml authored May 22, 2019
2 parents 958491d + 820fdc7 commit cf0497e
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/com/yahoo/platform/yui/compressor/CssCompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,31 @@ public void compress(Writer out, int linebreakpos)
// remove unnecessary semicolons
css = css.replaceAll(";+}", "}");

// Replace 0(px,em,%) with 0.
// Replace 0(px,em) with 0. (don't replace seconds are they are needed for transitions to be valid)
String oldCss;
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|k?hz)");
do {
oldCss = css;
m = p.matcher(css);
css = m.replaceAll("$1$20");
} while (!(css.equals(oldCss)));

// We do the same with % but don't replace the 0% in keyframes
String oldCss;
p = Pattern.compile("(?i)(: ?)((?:[0-9a-z-.]+ )*?)?(?:0?\\.)?0(?:%)");
do {
oldCss = css;
m = p.matcher(css);
css = m.replaceAll("$1$20");
} while (!(css.equals(oldCss)));

//Replace the keyframe 100% step with 'to' which is shorter
p = Pattern.compile("(?i)(^|,|{) ?(?:100% ?{)");
do {
oldCss = css;
m = p.matcher(css);
css = m.replaceAll("$1to{");
} 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)");
Expand All @@ -346,7 +363,7 @@ public void compress(Writer out, int linebreakpos)
} while (!(css.equals(oldCss)));

// Replace x.0(px,em,%) with x(px,em,%).
css = css.replaceAll("([0-9])\\.0(px|em|%|in|cm|mm|pc|pt|ex|deg|g?rad|m?s|k?hz| |;)", "$1$2");
css = css.replaceAll("([0-9])\\.0(px|em|%|in|cm|mm|pc|pt|ex|deg|m?s|g?rad|k?hz| |;)", "$1$2");

// Replace 0 0 0 0; with 0.
css = css.replaceAll(":0 0 0 0(;|})", ":0$1");
Expand Down

0 comments on commit cf0497e

Please sign in to comment.