- Timestamp:
- 05/03/2024 04:45:20 AM (7 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/style-engine/class-wp-style-engine-css-rule.php
r55819 r58089 37 37 38 38 /** 39 * A parent CSS selector in the case of nested CSS, or a CSS nested @rule, 40 * such as `@media (min-width: 80rem)` or `@layer module`. 41 * 42 * @since 6.6.0 43 * @var string 44 */ 45 protected $rules_group; 46 47 /** 39 48 * Constructor. 40 49 * 41 50 * @since 6.1.0 51 * @since 6.6.0 Added the `$rules_group` parameter. 42 52 * 43 53 * @param string $selector Optional. The CSS selector. Default empty string. … … 46 56 * or a WP_Style_Engine_CSS_Declarations object. 47 57 * Default empty array. 58 * @param string $rules_group A parent CSS selector in the case of nested CSS, or a CSS nested @rule, 59 * such as `@media (min-width: 80rem)` or `@layer module`. 48 60 */ 49 public function __construct( $selector = '', $declarations = array() ) {61 public function __construct( $selector = '', $declarations = array(), $rules_group = '' ) { 50 62 $this->set_selector( $selector ); 51 63 $this->add_declarations( $declarations ); 64 $this->set_rules_group( $rules_group ); 52 65 } 53 66 … … 91 104 92 105 /** 106 * Sets the rules group. 107 * 108 * @since 6.6.0 109 * 110 * @param string $rules_group A parent CSS selector in the case of nested CSS, or a CSS nested @rule, 111 * such as `@media (min-width: 80rem)` or `@layer module`. 112 * @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods. 113 */ 114 public function set_rules_group( $rules_group ) { 115 $this->rules_group = $rules_group; 116 return $this; 117 } 118 119 /** 120 * Gets the rules group. 121 * 122 * @since 6.6.0 123 * 124 * @return string 125 */ 126 public function get_rules_group() { 127 return $this->rules_group; 128 } 129 130 /** 93 131 * Gets the declarations object. 94 132 * … … 116 154 * 117 155 * @since 6.1.0 156 * @since 6.6.0 Added support for nested CSS with rules groups. 118 157 * 119 158 * @param bool $should_prettify Optional. Whether to add spacing, new lines and indents. … … 124 163 */ 125 164 public function get_css( $should_prettify = false, $indent_count = 0 ) { 126 $rule_indent = $should_prettify ? str_repeat( "\t", $indent_count ) : ''; 127 $declarations_indent = $should_prettify ? $indent_count + 1 : 0; 128 $suffix = $should_prettify ? "\n" : ''; 129 $spacer = $should_prettify ? ' ' : ''; 130 $selector = $should_prettify ? str_replace( ',', ",\n", $this->get_selector() ) : $this->get_selector(); 131 $css_declarations = $this->declarations->get_declarations_string( $should_prettify, $declarations_indent ); 165 $rule_indent = $should_prettify ? str_repeat( "\t", $indent_count ) : ''; 166 $nested_rule_indent = $should_prettify ? str_repeat( "\t", $indent_count + 1 ) : ''; 167 $declarations_indent = $should_prettify ? $indent_count + 1 : 0; 168 $nested_declarations_indent = $should_prettify ? $indent_count + 2 : 0; 169 $suffix = $should_prettify ? "\n" : ''; 170 $spacer = $should_prettify ? ' ' : ''; 171 // Trims any multiple selectors strings. 172 $selector = $should_prettify ? implode( ',', array_map( 'trim', explode( ',', $this->get_selector() ) ) ) : $this->get_selector(); 173 $selector = $should_prettify ? str_replace( array( ',' ), ",\n", $selector ) : $selector; 174 $rules_group = $this->get_rules_group(); 175 $has_rules_group = ! empty( $rules_group ); 176 $css_declarations = $this->declarations->get_declarations_string( $should_prettify, $has_rules_group ? $nested_declarations_indent : $declarations_indent ); 132 177 133 178 if ( empty( $css_declarations ) ) { … … 135 180 } 136 181 182 if ( $has_rules_group ) { 183 $selector = "{$rule_indent}{$rules_group}{$spacer}{{$suffix}{$nested_rule_indent}{$selector}{$spacer}{{$suffix}{$css_declarations}{$suffix}{$nested_rule_indent}}{$suffix}{$rule_indent}}"; 184 return $selector; 185 } 186 137 187 return "{$rule_indent}{$selector}{$spacer}{{$suffix}{$css_declarations}{$suffix}{$rule_indent}}"; 138 188 }
Note: See TracChangeset
for help on using the changeset viewer.