Skip to content

Commit

Permalink
Fix #75: CSS issue compressing complex calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jun 25, 2022
1 parent c630c3a commit d6edcc8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,15 @@ public void compress(Writer out, int linebreakpos) throws IOException {
// https://developer.mozilla.org/en-US/docs/Web/CSS/calc
// Added by Eric Arnol-Martin ([email protected])
sb = new StringBuilder();
p = Pattern.compile("calc\\([^\\)]*\\)");
p = Pattern.compile("calc\\([^;]*\\)");
m = p.matcher(css);
while (m.find()) {
String s = m.group();
s = s.replaceAll("\\s+", "");
s = s.replaceAll("(?<=[-|%|px|em|rem|vw|\\d])\\+", " + ");
s = s.replaceAll("(?<=[-|%|px|em|rem|vw|\\d])\\-", " - ");
s = s.replaceAll("(?<=[-|%|px|em|rem|vw|\\d])\\*", " * ");
s = s.replaceAll("(?<=[-|%|px|em|rem|vw|\\d])\\/", " / ");
s = s.replaceAll("(?<=[-|%|)|px|em|rem|vw|\\d])\\+", " + ");
s = s.replaceAll("(?<=[-|%|)|px|em|rem|vw|\\d])\\-", " - ");
s = s.replaceAll("(?<=[-|%|)|px|em|rem|vw|\\d])\\*", " * ");
s = s.replaceAll("(?<=[-|%|)|px|em|rem|vw|\\d])\\/", " / ");

m.appendReplacement(sb, s);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/calc.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.test-calc {
left:calc(50%-(100px * 2));
width: calc( 25% +10px);
/*right: calc(((100% - 1200px) /2) + 16px); https://github.com/primefaces-extensions/resources-optimizer-maven-plugin/issues/75 */
right: calc(((100% - 1200px) /2) + 16px);
height:calc(50% + 4px)
}
2 changes: 1 addition & 1 deletion src/test/resources/calc.css.min
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.test-calc{left:calc(50% - (100px * 2));width:calc(25% + 10px);height:calc(50% + 4px)}
.test-calc{left:calc(50% - (100px * 2));width:calc(25% + 10px);right:calc(((100% - 1200px) / 2) + 16px);height:calc(50% + 4px)}

0 comments on commit d6edcc8

Please sign in to comment.