Pelago\Emogrifier
CssInliner::removeUnmatchablePseudoComponents() private WC 1.0
Removes pseudo-elements and dynamic pseudo-classes from a CSS selector, replacing them with "*" if necessary. If such a pseudo-component is within the argument of :not, the entire :not component is removed or replaced.
{} It's a method of the class: CssInliner{}
No Hooks.
Return
String. Selector which will match the relevant DOM elements if the pseudo-classes are assumed to apply, or in the case of pseudo-elements will match their originating element.
Usage
// private - for code of main (parent) class only $result = $this->removeUnmatchablePseudoComponents( $selector );
- $selector(string) (required)
- -
Code of CssInliner::removeUnmatchablePseudoComponents() CssInliner::removeUnmatchablePseudoComponents WC 5.0.0
private function removeUnmatchablePseudoComponents($selector)
{
// The regex allows nested brackets via `(?2)`.
// A space is temporarily prepended because the callback can't determine if the match was at the very start.
$selectorWithoutNots = \ltrim(\preg_replace_callback(
'/(\\s?+):not(\\([^()]*+(?:(?2)[^()]*+)*+\\))/i',
[$this, 'replaceUnmatchableNotComponent'],
' ' . $selector
));
$pseudoComponentMatcher = ':(?!' . self::PSEUDO_CLASS_MATCHER . '):?+[\\w\\-]++(?:\\([^\\)]*+\\))?+';
return \preg_replace(
['/(\\s|^)' . $pseudoComponentMatcher . '/i', '/' . $pseudoComponentMatcher . '/i'],
['$1*', ''],
$selectorWithoutNots
);
}