mirror of
https://github.com/matthiasmullie/minify.git
synced 2025-02-22 12:22:51 +01:00
parent
8931f76af2
commit
26da9bbfc8
20
src/CSS.php
20
src/CSS.php
@ -308,6 +308,7 @@ class CSS extends Minify
|
||||
$this->extractStrings();
|
||||
$this->stripComments();
|
||||
$this->extractMath();
|
||||
$this->extractCustomProperties();
|
||||
$css = $this->replace($css);
|
||||
|
||||
$css = $this->stripWhitespace($css);
|
||||
@ -721,6 +722,25 @@ class CSS extends Minify
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace custom properties, whose values may be used in scenarios where
|
||||
* we wouldn't want them to be minified (e.g. inside calc)
|
||||
*/
|
||||
protected function extractCustomProperties()
|
||||
{
|
||||
// PHP only supports $this inside anonymous functions since 5.4
|
||||
$minifier = $this;
|
||||
$this->registerPattern(
|
||||
'/(?<=^|[;}])(--[^:;{}"\'\s]+)\s*:([^;{}]+)/m',
|
||||
function ($match) use ($minifier) {
|
||||
$placeholder = '--custom-'. count($minifier->extracted) . ':0';
|
||||
$minifier->extracted[$placeholder] = $match[1] .':'. trim($match[2]);
|
||||
return $placeholder;
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if file is small enough to be imported.
|
||||
*
|
||||
|
@ -806,6 +806,13 @@ body{font-family:sans-serif}',
|
||||
'clamp(2.5rem, 1rem + 4vw, 4rem)',
|
||||
);
|
||||
|
||||
// https://github.com/matthiasmullie/minify/issues/342
|
||||
$tests[] = array(
|
||||
'--headlineFontSize: 16px + var(--multiplicator);
|
||||
font-size: calc(var(--headlineFontSize));',
|
||||
'--headlineFontSize:16px + var(--multiplicator);font-size:calc(var(--headlineFontSize));',
|
||||
);
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user