- // remove zeroes where they make no sense in calc: e.g. calc(100px - 0)
- // the 0 doesn't have any effect, and this isn't even valid without unit
- // strip all `+ 0` or `- 0` occurrences: calc(10% + 0) -> calc(10%)
- // looped because there may be multiple 0s inside 1 group of parentheses
- do {
- $previous = $content;
- $content = preg_replace('/\(([^\(\)]+) [\+\-] 0( [^\(\)]+)?\)/', '(\\1\\2)', $content);
- } while ($content !== $previous);
- // strip all `0 +` occurrences: calc(0 + 10%) -> calc(10%)
- $content = preg_replace('/\(0 \+ ([^\(\)]+)\)/', '(\\1)', $content);
- // strip all `0 -` occurrences: calc(0 - 10%) -> calc(-10%)
- $content = preg_replace('/\(0 \- ([^\(\)]+)\)/', '(-\\1)', $content);
- // I'm not going to attempt to optimize away `x * 0` instances:
- // it's dumb enough code already that it likely won't occur, and it's
- // too complex to do right (order of operations would have to be
- // respected etc)
- // what I cared about most here was fixing incorrectly truncated units
-
- // IE doesn't seem to understand a unitless flex-basis value, so let's
- // add it in again (make it `%`, which is only 1 char: 0%, 0px, 0
- // anything, it's all just the same)
- $content = preg_replace('/flex:([^ ]+ [^ ]+ )0([;\}])/', 'flex:${1}0%${2}', $content);
+ // IE doesn't seem to understand a unitless flex-basis value (correct -
+ // it goes against the spec), so let's add it in again (make it `%`,
+ // which is only 1 char: 0%, 0px, 0 anything, it's all just the same)
+ // @see https://developer.mozilla.org/nl/docs/Web/CSS/flex
+ $content = preg_replace('/flex:([0-9]+\s[0-9]+\s)0([;\}])/', 'flex:${1}0%${2}', $content);