Skip to content
Permalink
Browse files

Merge pull request #312 from Tofandel/patch-2

Invalid transition and keyframes fix
  • Loading branch information...
tml committed May 22, 2019
2 parents 958491d + 820fdc7 commit cf0497e53fffe4ddbd50e71518c40e0c07d120de
Showing with 20 additions and 3 deletions.
  1. +20 −3 src/com/yahoo/platform/yui/compressor/CssCompressor.java
@@ -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)");
@@ -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");

0 comments on commit cf0497e

Please sign in to comment.
You can’t perform that action at this time.