Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet

DeclarationBlock::expandListStyleShorthandpublicWC 1.0

Deprecated since since 8.7.0, will be removed without substitution in version 9.0 in #511. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.

Method of the class: DeclarationBlock{}

No Hooks.

Returns

null. Nothing (null).

Usage

$DeclarationBlock = new DeclarationBlock();
$DeclarationBlock->expandListStyleShorthand();

Changelog

Deprecated Since 8.7.0 , will be removed without substitution in version 9.0 in #511

DeclarationBlock::expandListStyleShorthand() code WC 10.8.1

public function expandListStyleShorthand()
{
    $aListProperties = [
        'list-style-type' => 'disc',
        'list-style-position' => 'outside',
        'list-style-image' => 'none',
    ];
    $aListStyleTypes = [
        'none',
        'disc',
        'circle',
        'square',
        'decimal-leading-zero',
        'decimal',
        'lower-roman',
        'upper-roman',
        'lower-greek',
        'lower-alpha',
        'lower-latin',
        'upper-alpha',
        'upper-latin',
        'hebrew',
        'armenian',
        'georgian',
        'cjk-ideographic',
        'hiragana',
        'hira-gana-iroha',
        'katakana-iroha',
        'katakana',
    ];
    $aListStylePositions = [
        'inside',
        'outside',
    ];
    $aRules = $this->getRulesAssoc();
    if (!isset($aRules['list-style'])) {
        return;
    }
    $oRule = $aRules['list-style'];
    $mRuleValue = $oRule->getValue();
    $aValues = [];
    if (!$mRuleValue instanceof RuleValueList) {
        $aValues[] = $mRuleValue;
    } else {
        $aValues = $mRuleValue->getListComponents();
    }
    if (count($aValues) == 1 && $aValues[0] == 'inherit') {
        foreach ($aListProperties as $sProperty => $mValue) {
            $oNewRule = new Rule($sProperty, $oRule->getLineNo(), $oRule->getColNo());
            $oNewRule->addValue('inherit');
            $oNewRule->setIsImportant($oRule->getIsImportant());
            $this->addRule($oNewRule);
        }
        $this->removeRule('list-style');
        return;
    }
    foreach ($aValues as $mValue) {
        if (!$mValue instanceof Value) {
            $mValue = mb_strtolower($mValue);
        }
        if ($mValue instanceof Url) {
            $aListProperties['list-style-image'] = $mValue;
        } elseif (in_array($mValue, $aListStyleTypes)) {
            $aListProperties['list-style-types'] = $mValue;
        } elseif (in_array($mValue, $aListStylePositions)) {
            $aListProperties['list-style-position'] = $mValue;
        }
    }
    foreach ($aListProperties as $sProperty => $mValue) {
        $oNewRule = new Rule($sProperty, $oRule->getLineNo(), $oRule->getColNo());
        $oNewRule->setIsImportant($oRule->getIsImportant());
        $oNewRule->addValue($mValue);
        $this->addRule($oNewRule);
    }
    $this->removeRule('list-style');
}