Automattic\WooCommerce\Vendor\Pelago\Emogrifier

CssInliner::removeImportantAnnotationFromNodeInlineStyle │ private │ WC 1.0

Removes the "!important" annotations out of the inline style declarations, eventually by rearranging declarations. Rearranging needed when !important shorthand properties are followed by some of their not !important expanded-version properties. For example "font: 12px serif !important; font-size: 13px;" must be reordered to "font-size: 13px; font: 12px serif;" in order to remain correct.

Method of the class: CssInliner{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->removeImportantAnnotationFromNodeInlineStyle( $node ): void;
$node(DOMElement) (required)
.

CssInliner::removeImportantAnnotationFromNodeInlineStyle() code WC 11.1.2

private function removeImportantAnnotationFromNodeInlineStyle(\DOMElement $node): void
{
    $style = $node->getAttribute('style');
    $inlineStyleDeclarations = (new DeclarationBlockParser())->parse((bool) $style ? $style : '');
    /** @var array<string, string> $regularStyleDeclarations */
    $regularStyleDeclarations = [];
    /** @var array<string, string> $importantStyleDeclarations */
    $importantStyleDeclarations = [];
    foreach ($inlineStyleDeclarations as $property => $value) {
        if ($this->attributeValueIsImportant($value)) {
            $importantStyleDeclarations[$property]
                = (new Preg())->throwExceptions($this->debug)->replace('/\\s*+!\\s*+important$/i', '', $value);
        } else {
            $regularStyleDeclarations[$property] = $value;
        }
    }
    $inlineStyleDeclarationsInNewOrder = \array_merge($regularStyleDeclarations, $importantStyleDeclarations);
    $node->setAttribute(
        'style',
        $this->generateStyleStringFromSingleDeclarationsArray($inlineStyleDeclarationsInNewOrder)
    );
}