@wordpress/style-engine 1.33.1 → 1.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/styles/background/index.js +7 -2
- package/build/styles/background/index.js.map +1 -1
- package/build/styles/border/index.js +1 -2
- package/build/styles/border/index.js.map +1 -1
- package/build/styles/color/background.js +1 -2
- package/build/styles/color/background.js.map +1 -1
- package/build/styles/color/gradient.js +1 -2
- package/build/styles/color/gradient.js.map +1 -1
- package/build/styles/color/index.js +1 -2
- package/build/styles/color/index.js.map +1 -1
- package/build/styles/color/text.js +1 -2
- package/build/styles/color/text.js.map +1 -1
- package/build/styles/constants.js +3 -6
- package/build/styles/constants.js.map +1 -1
- package/build/styles/dimensions/index.js +1 -2
- package/build/styles/dimensions/index.js.map +1 -1
- package/build/styles/index.js +1 -2
- package/build/styles/index.js.map +1 -1
- package/build/styles/outline/index.js +1 -2
- package/build/styles/outline/index.js.map +1 -1
- package/build/styles/shadow/index.js +1 -2
- package/build/styles/shadow/index.js.map +1 -1
- package/build/styles/spacing/index.js +1 -2
- package/build/styles/spacing/index.js.map +1 -1
- package/build/styles/spacing/margin.js +1 -2
- package/build/styles/spacing/margin.js.map +1 -1
- package/build/styles/spacing/padding.js +1 -2
- package/build/styles/spacing/padding.js.map +1 -1
- package/build/styles/typography/index.js +1 -2
- package/build/styles/typography/index.js.map +1 -1
- package/build-module/styles/background/index.js +7 -1
- package/build-module/styles/background/index.js.map +1 -1
- package/build-types/styles/background/index.d.ts.map +1 -1
- package/class-wp-style-engine-css-declarations.php +135 -136
- package/class-wp-style-engine-css-rule.php +140 -100
- package/class-wp-style-engine-css-rules-store.php +127 -119
- package/class-wp-style-engine-processor.php +140 -124
- package/class-wp-style-engine.php +571 -572
- package/package.json +2 -2
- package/src/styles/background/index.ts +18 -1
- package/src/test/index.js +6 -0
- package/style-engine.php +5 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -7,163 +7,162 @@
|
|
|
7
7
|
* @package Gutenberg
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
if ( class_exists( 'WP_Style_Engine_CSS_Declarations' ) ) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
10
|
+
if ( ! class_exists( 'WP_Style_Engine_CSS_Declarations' ) ) {
|
|
13
11
|
|
|
14
|
-
/**
|
|
15
|
-
* Holds, sanitizes, processes and prints CSS declarations for the Style Engine.
|
|
16
|
-
*
|
|
17
|
-
* @access private
|
|
18
|
-
*/
|
|
19
|
-
class WP_Style_Engine_CSS_Declarations {
|
|
20
12
|
/**
|
|
21
|
-
*
|
|
13
|
+
* Holds, sanitizes, processes and prints CSS declarations for the Style Engine.
|
|
22
14
|
*
|
|
23
|
-
* @
|
|
15
|
+
* @access private
|
|
24
16
|
*/
|
|
25
|
-
|
|
17
|
+
class WP_Style_Engine_CSS_Declarations {
|
|
18
|
+
/**
|
|
19
|
+
* An array of CSS declarations (property => value pairs).
|
|
20
|
+
*
|
|
21
|
+
* @var array
|
|
22
|
+
*/
|
|
23
|
+
protected $declarations = array();
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Constructor for this object.
|
|
27
|
+
*
|
|
28
|
+
* If a `$declarations` array is passed, it will be used to populate
|
|
29
|
+
* the initial $declarations prop of the object by calling add_declarations().
|
|
30
|
+
*
|
|
31
|
+
* @param string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
|
|
32
|
+
*/
|
|
33
|
+
public function __construct( $declarations = array() ) {
|
|
34
|
+
$this->add_declarations( $declarations );
|
|
35
|
+
}
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Adds a single declaration.
|
|
39
|
+
*
|
|
40
|
+
* @param string $property The CSS property.
|
|
41
|
+
* @param string $value The CSS value.
|
|
42
|
+
*
|
|
43
|
+
* @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
|
|
44
|
+
*/
|
|
45
|
+
public function add_declaration( $property, $value ) {
|
|
46
|
+
// Sanitizes the property.
|
|
47
|
+
$property = $this->sanitize_property( $property );
|
|
48
|
+
// Bails early if the property is empty.
|
|
49
|
+
if ( empty( $property ) ) {
|
|
50
|
+
return $this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Trims the value. If empty, bail early.
|
|
54
|
+
$value = trim( $value );
|
|
55
|
+
if ( '' === $value ) {
|
|
56
|
+
return $this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Adds the declaration property/value pair.
|
|
60
|
+
$this->declarations[ $property ] = $value;
|
|
38
61
|
|
|
39
|
-
/**
|
|
40
|
-
* Adds a single declaration.
|
|
41
|
-
*
|
|
42
|
-
* @param string $property The CSS property.
|
|
43
|
-
* @param string $value The CSS value.
|
|
44
|
-
*
|
|
45
|
-
* @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
|
|
46
|
-
*/
|
|
47
|
-
public function add_declaration( $property, $value ) {
|
|
48
|
-
// Sanitizes the property.
|
|
49
|
-
$property = $this->sanitize_property( $property );
|
|
50
|
-
// Bails early if the property is empty.
|
|
51
|
-
if ( empty( $property ) ) {
|
|
52
62
|
return $this;
|
|
53
63
|
}
|
|
54
64
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Removes a single declaration.
|
|
67
|
+
*
|
|
68
|
+
* @param string $property The CSS property.
|
|
69
|
+
*
|
|
70
|
+
* @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
|
|
71
|
+
*/
|
|
72
|
+
public function remove_declaration( $property ) {
|
|
73
|
+
unset( $this->declarations[ $property ] );
|
|
58
74
|
return $this;
|
|
59
75
|
}
|
|
60
76
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
*/
|
|
74
|
-
public function remove_declaration( $property ) {
|
|
75
|
-
unset( $this->declarations[ $property ] );
|
|
76
|
-
return $this;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Adds multiple declarations.
|
|
81
|
-
*
|
|
82
|
-
* @param array $declarations An array of declarations.
|
|
83
|
-
*
|
|
84
|
-
* @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
|
|
85
|
-
*/
|
|
86
|
-
public function add_declarations( $declarations ) {
|
|
87
|
-
foreach ( $declarations as $property => $value ) {
|
|
88
|
-
$this->add_declaration( $property, $value );
|
|
77
|
+
/**
|
|
78
|
+
* Adds multiple declarations.
|
|
79
|
+
*
|
|
80
|
+
* @param array $declarations An array of declarations.
|
|
81
|
+
*
|
|
82
|
+
* @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
|
|
83
|
+
*/
|
|
84
|
+
public function add_declarations( $declarations ) {
|
|
85
|
+
foreach ( $declarations as $property => $value ) {
|
|
86
|
+
$this->add_declaration( $property, $value );
|
|
87
|
+
}
|
|
88
|
+
return $this;
|
|
89
89
|
}
|
|
90
|
-
return $this;
|
|
91
|
-
}
|
|
92
90
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Removes multiple declarations.
|
|
93
|
+
*
|
|
94
|
+
* @param array $properties An array of properties.
|
|
95
|
+
*
|
|
96
|
+
* @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
|
|
97
|
+
*/
|
|
98
|
+
public function remove_declarations( $properties = array() ) {
|
|
99
|
+
foreach ( $properties as $property ) {
|
|
100
|
+
$this->remove_declaration( $property );
|
|
101
|
+
}
|
|
102
|
+
return $this;
|
|
103
103
|
}
|
|
104
|
-
return $this;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Gets the declarations array.
|
|
109
|
-
*
|
|
110
|
-
* @return array
|
|
111
|
-
*/
|
|
112
|
-
public function get_declarations() {
|
|
113
|
-
return $this->declarations;
|
|
114
|
-
}
|
|
115
104
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
*/
|
|
125
|
-
protected static function filter_declaration( $property, $value, $spacer = '' ) {
|
|
126
|
-
$filtered_value = wp_strip_all_tags( $value, true );
|
|
105
|
+
/**
|
|
106
|
+
* Gets the declarations array.
|
|
107
|
+
*
|
|
108
|
+
* @return array
|
|
109
|
+
*/
|
|
110
|
+
public function get_declarations() {
|
|
111
|
+
return $this->declarations;
|
|
112
|
+
}
|
|
127
113
|
|
|
128
|
-
|
|
129
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Filters a CSS property + value pair.
|
|
116
|
+
*
|
|
117
|
+
* @param string $property The CSS property.
|
|
118
|
+
* @param string $value The value to be filtered.
|
|
119
|
+
* @param string $spacer The spacer between the colon and the value. Defaults to an empty string.
|
|
120
|
+
*
|
|
121
|
+
* @return string The filtered declaration or an empty string.
|
|
122
|
+
*/
|
|
123
|
+
protected static function filter_declaration( $property, $value, $spacer = '' ) {
|
|
124
|
+
$filtered_value = wp_strip_all_tags( $value, true );
|
|
125
|
+
|
|
126
|
+
if ( '' !== $filtered_value ) {
|
|
127
|
+
return safecss_filter_attr( "{$property}:{$spacer}{$filtered_value}" );
|
|
128
|
+
}
|
|
129
|
+
return '';
|
|
130
130
|
}
|
|
131
|
-
return '';
|
|
132
|
-
}
|
|
133
131
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Filters and compiles the CSS declarations.
|
|
134
|
+
*
|
|
135
|
+
* @param bool $should_prettify Whether to add spacing, new lines and indents.
|
|
136
|
+
* @param number $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`.
|
|
137
|
+
*
|
|
138
|
+
* @return string The CSS declarations.
|
|
139
|
+
*/
|
|
140
|
+
public function get_declarations_string( $should_prettify = false, $indent_count = 0 ) {
|
|
141
|
+
$declarations_array = $this->get_declarations();
|
|
142
|
+
$declarations_output = '';
|
|
143
|
+
$indent = $should_prettify ? str_repeat( "\t", $indent_count ) : '';
|
|
144
|
+
$suffix = $should_prettify ? ' ' : '';
|
|
145
|
+
$suffix = $should_prettify && $indent_count > 0 ? "\n" : $suffix;
|
|
146
|
+
$spacer = $should_prettify ? ' ' : '';
|
|
147
|
+
|
|
148
|
+
foreach ( $declarations_array as $property => $value ) {
|
|
149
|
+
$filtered_declaration = static::filter_declaration( $property, $value, $spacer );
|
|
150
|
+
if ( $filtered_declaration ) {
|
|
151
|
+
$declarations_output .= "{$indent}{$filtered_declaration};$suffix";
|
|
152
|
+
}
|
|
154
153
|
}
|
|
154
|
+
return rtrim( $declarations_output );
|
|
155
155
|
}
|
|
156
|
-
return rtrim( $declarations_output );
|
|
157
|
-
}
|
|
158
156
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Sanitizes property names.
|
|
159
|
+
*
|
|
160
|
+
* @param string $property The CSS property.
|
|
161
|
+
*
|
|
162
|
+
* @return string The sanitized property name.
|
|
163
|
+
*/
|
|
164
|
+
protected function sanitize_property( $property ) {
|
|
165
|
+
return sanitize_key( $property );
|
|
166
|
+
}
|
|
168
167
|
}
|
|
169
168
|
}
|
|
@@ -7,121 +7,161 @@
|
|
|
7
7
|
* @package Gutenberg
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
if ( class_exists( 'WP_Style_Engine_CSS_Rule' ) ) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Holds, sanitizes, processes and prints CSS declarations for the Style Engine.
|
|
16
|
-
*
|
|
17
|
-
* @access private
|
|
18
|
-
*/
|
|
19
|
-
class WP_Style_Engine_CSS_Rule {
|
|
10
|
+
if ( ! class_exists( 'WP_Style_Engine_CSS_Rule' ) ) {
|
|
20
11
|
|
|
21
12
|
/**
|
|
22
|
-
*
|
|
13
|
+
* Holds, sanitizes, processes and prints CSS declarations for the Style Engine.
|
|
23
14
|
*
|
|
24
|
-
* @
|
|
15
|
+
* @access private
|
|
25
16
|
*/
|
|
26
|
-
|
|
17
|
+
class WP_Style_Engine_CSS_Rule {
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*/
|
|
35
|
-
protected $declarations;
|
|
19
|
+
/**
|
|
20
|
+
* The selector.
|
|
21
|
+
*
|
|
22
|
+
* @var string
|
|
23
|
+
*/
|
|
24
|
+
protected $selector;
|
|
36
25
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
$this->set_selector( $selector );
|
|
46
|
-
$this->add_declarations( $declarations );
|
|
47
|
-
}
|
|
26
|
+
/**
|
|
27
|
+
* The selector declarations.
|
|
28
|
+
*
|
|
29
|
+
* Contains a WP_Style_Engine_CSS_Declarations object.
|
|
30
|
+
*
|
|
31
|
+
* @var WP_Style_Engine_CSS_Declarations
|
|
32
|
+
*/
|
|
33
|
+
protected $declarations;
|
|
48
34
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*/
|
|
56
|
-
public function set_selector( $selector ) {
|
|
57
|
-
$this->selector = $selector;
|
|
58
|
-
return $this;
|
|
59
|
-
}
|
|
35
|
+
/**
|
|
36
|
+
* The CSS nested @rule, such as `@media (min-width: 80rem)` or `@layer module`.
|
|
37
|
+
*
|
|
38
|
+
* @var string
|
|
39
|
+
*/
|
|
40
|
+
protected $at_rule;
|
|
60
41
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
$
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Constructor
|
|
45
|
+
*
|
|
46
|
+
* @param string $selector The CSS selector.
|
|
47
|
+
* @param string[]|WP_Style_Engine_CSS_Declarations $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ),
|
|
48
|
+
* or a WP_Style_Engine_CSS_Declarations object.
|
|
49
|
+
* @param string $at_rule A CSS nested @rule, such as `@media (min-width: 80rem)` or `@layer module`.
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
public function __construct( $selector = '', $declarations = array(), $at_rule = '' ) {
|
|
53
|
+
$this->set_selector( $selector );
|
|
54
|
+
$this->add_declarations( $declarations );
|
|
55
|
+
$this->set_at_rule( $at_rule );
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Sets the selector.
|
|
60
|
+
*
|
|
61
|
+
* @param string $selector The CSS selector.
|
|
62
|
+
*
|
|
63
|
+
* @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods.
|
|
64
|
+
*/
|
|
65
|
+
public function set_selector( $selector ) {
|
|
66
|
+
$this->selector = $selector;
|
|
67
|
+
return $this;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Sets the declarations.
|
|
72
|
+
*
|
|
73
|
+
* @param array|WP_Style_Engine_CSS_Declarations $declarations An array of declarations (property => value pairs),
|
|
74
|
+
* or a WP_Style_Engine_CSS_Declarations object.
|
|
75
|
+
*
|
|
76
|
+
* @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods.
|
|
77
|
+
*/
|
|
78
|
+
public function add_declarations( $declarations ) {
|
|
79
|
+
$is_declarations_object = ! is_array( $declarations );
|
|
80
|
+
$declarations_array = $is_declarations_object ? $declarations->get_declarations() : $declarations;
|
|
81
|
+
|
|
82
|
+
if ( null === $this->declarations ) {
|
|
83
|
+
if ( $is_declarations_object ) {
|
|
84
|
+
$this->declarations = $declarations;
|
|
85
|
+
return $this;
|
|
86
|
+
}
|
|
87
|
+
$this->declarations = new WP_Style_Engine_CSS_Declarations( $declarations_array );
|
|
77
88
|
}
|
|
78
|
-
$this->declarations
|
|
89
|
+
$this->declarations->add_declarations( $declarations_array );
|
|
90
|
+
|
|
91
|
+
return $this;
|
|
79
92
|
}
|
|
80
|
-
$this->declarations->add_declarations( $declarations_array );
|
|
81
93
|
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Sets the at_rule.
|
|
96
|
+
*
|
|
97
|
+
* @param string $at_rule A CSS nested @rule, such as `@media (min-width: 80rem)` or `@layer module`.
|
|
98
|
+
*
|
|
99
|
+
* @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods.
|
|
100
|
+
*/
|
|
101
|
+
public function set_at_rule( $at_rule ) {
|
|
102
|
+
$this->at_rule = $at_rule;
|
|
103
|
+
return $this;
|
|
104
|
+
}
|
|
84
105
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Gets the declarations object.
|
|
108
|
+
*
|
|
109
|
+
* @return WP_Style_Engine_CSS_Declarations The declarations object.
|
|
110
|
+
*/
|
|
111
|
+
public function get_declarations() {
|
|
112
|
+
return $this->declarations;
|
|
113
|
+
}
|
|
93
114
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Gets the full selector.
|
|
117
|
+
*
|
|
118
|
+
* @return string
|
|
119
|
+
*/
|
|
120
|
+
public function get_selector() {
|
|
121
|
+
return $this->selector;
|
|
122
|
+
}
|
|
102
123
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*/
|
|
111
|
-
public function get_css( $should_prettify = false, $indent_count = 0 ) {
|
|
112
|
-
$rule_indent = $should_prettify ? str_repeat( "\t", $indent_count ) : '';
|
|
113
|
-
$declarations_indent = $should_prettify ? $indent_count + 1 : 0;
|
|
114
|
-
$suffix = $should_prettify ? "\n" : '';
|
|
115
|
-
$spacer = $should_prettify ? ' ' : '';
|
|
116
|
-
// Trims any multiple selectors strings.
|
|
117
|
-
$selector = $should_prettify ? implode( ',', array_map( 'trim', explode( ',', $this->get_selector() ) ) ) : $this->get_selector();
|
|
118
|
-
$selector = $should_prettify ? str_replace( array( ',' ), ",\n", $selector ) : $selector;
|
|
119
|
-
$css_declarations = $this->declarations->get_declarations_string( $should_prettify, $declarations_indent );
|
|
120
|
-
|
|
121
|
-
if ( empty( $css_declarations ) ) {
|
|
122
|
-
return '';
|
|
124
|
+
/**
|
|
125
|
+
* Gets the at_rule.
|
|
126
|
+
*
|
|
127
|
+
* @return string
|
|
128
|
+
*/
|
|
129
|
+
public function get_at_rule() {
|
|
130
|
+
return $this->at_rule;
|
|
123
131
|
}
|
|
124
132
|
|
|
125
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Gets the CSS.
|
|
135
|
+
*
|
|
136
|
+
* @param bool $should_prettify Whether to add spacing, new lines and indents.
|
|
137
|
+
* @param number $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`.
|
|
138
|
+
*
|
|
139
|
+
* @return string
|
|
140
|
+
*/
|
|
141
|
+
public function get_css( $should_prettify = false, $indent_count = 0 ) {
|
|
142
|
+
$rule_indent = $should_prettify ? str_repeat( "\t", $indent_count ) : '';
|
|
143
|
+
$nested_rule_indent = $should_prettify ? str_repeat( "\t", $indent_count + 1 ) : '';
|
|
144
|
+
$declarations_indent = $should_prettify ? $indent_count + 1 : 0;
|
|
145
|
+
$nested_declarations_indent = $should_prettify ? $indent_count + 2 : 0;
|
|
146
|
+
$suffix = $should_prettify ? "\n" : '';
|
|
147
|
+
$spacer = $should_prettify ? ' ' : '';
|
|
148
|
+
// Trims any multiple selectors strings.
|
|
149
|
+
$selector = $should_prettify ? implode( ',', array_map( 'trim', explode( ',', $this->get_selector() ) ) ) : $this->get_selector();
|
|
150
|
+
$selector = $should_prettify ? str_replace( array( ',' ), ",\n", $selector ) : $selector;
|
|
151
|
+
$at_rule = $this->get_at_rule();
|
|
152
|
+
$has_at_rule = ! empty( $at_rule );
|
|
153
|
+
$css_declarations = $this->declarations->get_declarations_string( $should_prettify, $has_at_rule ? $nested_declarations_indent : $declarations_indent );
|
|
154
|
+
|
|
155
|
+
if ( empty( $css_declarations ) ) {
|
|
156
|
+
return '';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if ( $has_at_rule ) {
|
|
160
|
+
$selector = "{$rule_indent}{$at_rule}{$spacer}{{$suffix}{$nested_rule_indent}{$selector}{$spacer}{{$suffix}{$css_declarations}{$suffix}{$nested_rule_indent}}{$suffix}{$rule_indent}}";
|
|
161
|
+
return $selector;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return "{$rule_indent}{$selector}{$spacer}{{$suffix}{$css_declarations}{$suffix}{$rule_indent}}";
|
|
165
|
+
}
|
|
126
166
|
}
|
|
127
167
|
}
|