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 f95ee29
Show file tree
Hide file tree
Showing 3 changed files with 8 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 (earnolmartin@gmail.com)
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
3 changes: 2 additions & 1 deletion src/test/resources/calc.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.test-calc {
top: calc(-100vw + 4em) !important;
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{top:calc(-100vw + 4em) !important;left:calc(50% - (100px * 2));width:calc(25% + 10px);right:calc(((100% - 1200px) / 2) + 16px);height:calc(50% + 4px)}

0 comments on commit f95ee29

Please sign in to comment.