Shortens all zero values for a set of safe properties e.g. padding: 0px 1px; -> padding:0 1px e.g. padding: 0px 0rem 0em 0.0pc; -> padding:0

Parameters

string $css:

Return value

string

1 call to CSSmin::shortenZeroValues()
CSSmin::minify in advagg_css_compress/yui/CSSMin.inc
Minifies the given input CSS string

File

advagg_css_compress/yui/CSSMin.inc, line 644

Class

CSSmin

Code

private function shortenZeroValues($css) {
    $unitsGroupReg = $this->unitsGroupRegex;
    $numOrPosReg = '(' . $this->numRegex . '|top|left|bottom|right|center)';
    $oneZeroSafeProperties = array(
        '(?:line-)?height',
        '(?:(?:min|max)-)?width',
        'top',
        'left',
        'background-position',
        'bottom',
        'right',
        'border(?:-(?:top|left|bottom|right))?(?:-width)?',
        'border-(?:(?:top|bottom)-(?:left|right)-)?radius',
        'column-(?:gap|width)',
        'margin(?:-(?:top|left|bottom|right))?',
        'outline-width',
        'padding(?:-(?:top|left|bottom|right))?',
    );
    $nZeroSafeProperties = array(
        'margin',
        'padding',
        'background-position',
    );
    $regStart = '/(;|\\{)';
    $regEnd = '/i';
    // First zero regex start
    $oneZeroRegStart = $regStart . '(' . implode('|', $oneZeroSafeProperties) . '):';
    // Multiple zeros regex start
    $nZerosRegStart = $regStart . '(' . implode('|', $nZeroSafeProperties) . '):';
    $css = preg_replace(array(
        $oneZeroRegStart . '0' . $unitsGroupReg . $regEnd,
        $nZerosRegStart . $numOrPosReg . ' 0' . $unitsGroupReg . $regEnd,
        $nZerosRegStart . $numOrPosReg . ' ' . $numOrPosReg . ' 0' . $unitsGroupReg . $regEnd,
        $nZerosRegStart . $numOrPosReg . ' ' . $numOrPosReg . ' ' . $numOrPosReg . ' 0' . $unitsGroupReg . $regEnd,
    ), array(
        '$1$2:0',
        '$1$2:$3 0',
        '$1$2:$3 $4 0',
        '$1$2:$3 $4 $5 0',
    ), $css);
    // Remove background-position
    array_pop($nZeroSafeProperties);
    // Replace 0 0; or 0 0 0; or 0 0 0 0; with 0 for safe properties only.
    $css = preg_replace('/(' . implode('|', $nZeroSafeProperties) . '):0(?: 0){1,3}(;|\\}| !)' . $regEnd, '$1:0$2', $css);
    // Replace 0 0 0; or 0 0 0 0; with 0 0 for background-position property.
    $css = preg_replace('/(background-position):0(?: 0){2,3}(;|\\}| !)' . $regEnd, '$1:0 0$2', $css);
    return $css;
}