@wordpress/style-engine 1.33.0 → 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 +7 -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/types.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-module/styles/dimensions/index.js +7 -1
- package/build-module/styles/dimensions/index.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-types/styles/background/index.d.ts.map +1 -1
- package/build-types/styles/dimensions/index.d.ts.map +1 -1
- package/build-types/types.d.ts +1 -0
- package/build-types/types.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 -563
- package/package.json +2 -2
- package/src/styles/background/index.ts +18 -1
- package/src/styles/dimensions/index.ts +13 -1
- package/src/test/index.js +6 -0
- package/src/types.ts +1 -0
- package/style-engine.php +5 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -7,649 +7,657 @@
|
|
|
7
7
|
* @package Gutenberg
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
if ( class_exists( 'WP_Style_Engine' ) ) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
10
|
+
if ( ! class_exists( 'WP_Style_Engine' ) ) {
|
|
13
11
|
|
|
14
|
-
/**
|
|
15
|
-
* Class WP_Style_Engine.
|
|
16
|
-
*
|
|
17
|
-
* The Style Engine aims to provide a consistent API for rendering styling for blocks across both client-side and server-side applications.
|
|
18
|
-
*
|
|
19
|
-
* This class is for internal Core usage and is not supposed to be used by extenders (plugins and/or themes).
|
|
20
|
-
* This class is final and should not be extended.
|
|
21
|
-
* This is a low-level API that may need to do breaking changes. Please, use wp_style_engine_get_styles instead.
|
|
22
|
-
*
|
|
23
|
-
* @access private
|
|
24
|
-
*/
|
|
25
|
-
final class WP_Style_Engine {
|
|
26
12
|
/**
|
|
27
|
-
*
|
|
13
|
+
* Class WP_Style_Engine.
|
|
28
14
|
*
|
|
29
|
-
*
|
|
15
|
+
* The Style Engine aims to provide a consistent API for rendering styling for blocks across both client-side and server-side applications.
|
|
30
16
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* - css_vars => (array) an array of key value pairs used to generate CSS var values.
|
|
35
|
-
* The key should be the CSS property name that matches the second element of the preset string value,
|
|
36
|
-
* i.e., "color" in var:preset|color|somePresetSlug. The value is a CSS var pattern (e.g. `--wp--preset--color--$slug`),
|
|
37
|
-
* whose `$slug` fragment will be replaced with the preset slug, which is the third element of the preset string value,
|
|
38
|
-
* i.e., `somePresetSlug` in var:preset|color|somePresetSlug.
|
|
39
|
-
* - property_keys => (array) array of keys whose values represent a valid CSS property, e.g., "margin" or "border".
|
|
40
|
-
* - path => (array) a path that accesses the corresponding style value in the block style object.
|
|
41
|
-
* - value_func => (string) the name of a function to generate a CSS definition array for a particular style object. The output of this function should be `array( "$property" => "$value", ... )`.
|
|
17
|
+
* This class is for internal Core usage and is not supposed to be used by extenders (plugins and/or themes).
|
|
18
|
+
* This class is final and should not be extended.
|
|
19
|
+
* This is a low-level API that may need to do breaking changes. Please, use wp_style_engine_get_styles instead.
|
|
42
20
|
*
|
|
43
|
-
* @
|
|
21
|
+
* @access private
|
|
44
22
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
'backgroundSize' => array(
|
|
67
|
-
'property_keys' => array(
|
|
68
|
-
'default' => 'background-size',
|
|
69
|
-
),
|
|
70
|
-
'path' => array( 'background', 'backgroundSize' ),
|
|
71
|
-
),
|
|
72
|
-
),
|
|
73
|
-
'color' => array(
|
|
74
|
-
'text' => array(
|
|
75
|
-
'property_keys' => array(
|
|
76
|
-
'default' => 'color',
|
|
77
|
-
),
|
|
78
|
-
'path' => array( 'color', 'text' ),
|
|
79
|
-
'css_vars' => array(
|
|
80
|
-
'color' => '--wp--preset--color--$slug',
|
|
81
|
-
),
|
|
82
|
-
'classnames' => array(
|
|
83
|
-
'has-text-color' => true,
|
|
84
|
-
'has-$slug-color' => 'color',
|
|
85
|
-
),
|
|
86
|
-
),
|
|
23
|
+
final class WP_Style_Engine {
|
|
24
|
+
/**
|
|
25
|
+
* Style definitions that contain the instructions to parse/output valid Gutenberg styles from a block's attributes.
|
|
26
|
+
*
|
|
27
|
+
* For every style definition, the following properties are valid:
|
|
28
|
+
*
|
|
29
|
+
* - classnames => (array) an array of classnames to be returned for block styles. The key is a classname or pattern.
|
|
30
|
+
* A value of `true` means the classname should be applied always. Otherwise, a valid CSS property (string)
|
|
31
|
+
* to match the incoming value, e.g., "color" to match var:preset|color|somePresetSlug.
|
|
32
|
+
* - css_vars => (array) an array of key value pairs used to generate CSS var values.
|
|
33
|
+
* The key should be the CSS property name that matches the second element of the preset string value,
|
|
34
|
+
* i.e., "color" in var:preset|color|somePresetSlug. The value is a CSS var pattern (e.g. `--wp--preset--color--$slug`),
|
|
35
|
+
* whose `$slug` fragment will be replaced with the preset slug, which is the third element of the preset string value,
|
|
36
|
+
* i.e., `somePresetSlug` in var:preset|color|somePresetSlug.
|
|
37
|
+
* - property_keys => (array) array of keys whose values represent a valid CSS property, e.g., "margin" or "border".
|
|
38
|
+
* - path => (array) a path that accesses the corresponding style value in the block style object.
|
|
39
|
+
* - value_func => (string) the name of a function to generate a CSS definition array for a particular style object. The output of this function should be `array( "$property" => "$value", ... )`.
|
|
40
|
+
*
|
|
41
|
+
* @var array
|
|
42
|
+
*/
|
|
43
|
+
const BLOCK_STYLE_DEFINITIONS_METADATA = array(
|
|
87
44
|
'background' => array(
|
|
88
|
-
'
|
|
89
|
-
'
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
'
|
|
94
|
-
),
|
|
95
|
-
'
|
|
96
|
-
'
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
'
|
|
102
|
-
'
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
'
|
|
106
|
-
),
|
|
107
|
-
'
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
),
|
|
113
|
-
),
|
|
114
|
-
'border' => array(
|
|
115
|
-
'color' => array(
|
|
116
|
-
'property_keys' => array(
|
|
117
|
-
'default' => 'border-color',
|
|
118
|
-
'individual' => 'border-%s-color',
|
|
119
|
-
),
|
|
120
|
-
'path' => array( 'border', 'color' ),
|
|
121
|
-
'classnames' => array(
|
|
122
|
-
'has-border-color' => true,
|
|
123
|
-
'has-$slug-border-color' => 'color',
|
|
124
|
-
),
|
|
125
|
-
),
|
|
126
|
-
'radius' => array(
|
|
127
|
-
'property_keys' => array(
|
|
128
|
-
'default' => 'border-radius',
|
|
129
|
-
'individual' => 'border-%s-radius',
|
|
130
|
-
),
|
|
131
|
-
'path' => array( 'border', 'radius' ),
|
|
132
|
-
),
|
|
133
|
-
'style' => array(
|
|
134
|
-
'property_keys' => array(
|
|
135
|
-
'default' => 'border-style',
|
|
136
|
-
'individual' => 'border-%s-style',
|
|
137
|
-
),
|
|
138
|
-
'path' => array( 'border', 'style' ),
|
|
139
|
-
),
|
|
140
|
-
'width' => array(
|
|
141
|
-
'property_keys' => array(
|
|
142
|
-
'default' => 'border-width',
|
|
143
|
-
'individual' => 'border-%s-width',
|
|
144
|
-
),
|
|
145
|
-
'path' => array( 'border', 'width' ),
|
|
146
|
-
),
|
|
147
|
-
'top' => array(
|
|
148
|
-
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
|
|
149
|
-
'path' => array( 'border', 'top' ),
|
|
150
|
-
'css_vars' => array(
|
|
151
|
-
'color' => '--wp--preset--color--$slug',
|
|
152
|
-
),
|
|
153
|
-
),
|
|
154
|
-
'right' => array(
|
|
155
|
-
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
|
|
156
|
-
'path' => array( 'border', 'right' ),
|
|
157
|
-
'css_vars' => array(
|
|
158
|
-
'color' => '--wp--preset--color--$slug',
|
|
159
|
-
),
|
|
160
|
-
),
|
|
161
|
-
'bottom' => array(
|
|
162
|
-
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
|
|
163
|
-
'path' => array( 'border', 'bottom' ),
|
|
164
|
-
'css_vars' => array(
|
|
165
|
-
'color' => '--wp--preset--color--$slug',
|
|
166
|
-
),
|
|
167
|
-
),
|
|
168
|
-
'left' => array(
|
|
169
|
-
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
|
|
170
|
-
'path' => array( 'border', 'left' ),
|
|
171
|
-
'css_vars' => array(
|
|
172
|
-
'color' => '--wp--preset--color--$slug',
|
|
173
|
-
),
|
|
174
|
-
),
|
|
175
|
-
),
|
|
176
|
-
'shadow' => array(
|
|
177
|
-
'shadow' => array(
|
|
178
|
-
'property_keys' => array(
|
|
179
|
-
'default' => 'box-shadow',
|
|
180
|
-
),
|
|
181
|
-
'path' => array( 'shadow' ),
|
|
182
|
-
'css_vars' => array(
|
|
183
|
-
'shadow' => '--wp--preset--shadow--$slug',
|
|
184
|
-
),
|
|
185
|
-
),
|
|
186
|
-
),
|
|
187
|
-
'dimensions' => array(
|
|
188
|
-
'minHeight' => array(
|
|
189
|
-
'property_keys' => array(
|
|
190
|
-
'default' => 'min-height',
|
|
191
|
-
),
|
|
192
|
-
'path' => array( 'dimensions', 'minHeight' ),
|
|
193
|
-
'css_vars' => array(
|
|
194
|
-
'spacing' => '--wp--preset--spacing--$slug',
|
|
45
|
+
'backgroundImage' => array(
|
|
46
|
+
'property_keys' => array(
|
|
47
|
+
'default' => 'background-image',
|
|
48
|
+
),
|
|
49
|
+
'value_func' => array( self::class, 'get_url_or_value_css_declaration' ),
|
|
50
|
+
'path' => array( 'background', 'backgroundImage' ),
|
|
51
|
+
),
|
|
52
|
+
'backgroundPosition' => array(
|
|
53
|
+
'property_keys' => array(
|
|
54
|
+
'default' => 'background-position',
|
|
55
|
+
),
|
|
56
|
+
'path' => array( 'background', 'backgroundPosition' ),
|
|
57
|
+
),
|
|
58
|
+
'backgroundRepeat' => array(
|
|
59
|
+
'property_keys' => array(
|
|
60
|
+
'default' => 'background-repeat',
|
|
61
|
+
),
|
|
62
|
+
'path' => array( 'background', 'backgroundRepeat' ),
|
|
63
|
+
),
|
|
64
|
+
'backgroundSize' => array(
|
|
65
|
+
'property_keys' => array(
|
|
66
|
+
'default' => 'background-size',
|
|
67
|
+
),
|
|
68
|
+
'path' => array( 'background', 'backgroundSize' ),
|
|
195
69
|
),
|
|
196
70
|
),
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
'
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
'
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
'
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
'
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
),
|
|
237
|
-
'css_vars' => array(
|
|
238
|
-
'font-family' => '--wp--preset--font-family--$slug',
|
|
239
|
-
),
|
|
240
|
-
'path' => array( 'typography', 'fontFamily' ),
|
|
241
|
-
'classnames' => array(
|
|
242
|
-
'has-$slug-font-family' => 'font-family',
|
|
71
|
+
'color' => array(
|
|
72
|
+
'text' => array(
|
|
73
|
+
'property_keys' => array(
|
|
74
|
+
'default' => 'color',
|
|
75
|
+
),
|
|
76
|
+
'path' => array( 'color', 'text' ),
|
|
77
|
+
'css_vars' => array(
|
|
78
|
+
'color' => '--wp--preset--color--$slug',
|
|
79
|
+
),
|
|
80
|
+
'classnames' => array(
|
|
81
|
+
'has-text-color' => true,
|
|
82
|
+
'has-$slug-color' => 'color',
|
|
83
|
+
),
|
|
84
|
+
),
|
|
85
|
+
'background' => array(
|
|
86
|
+
'property_keys' => array(
|
|
87
|
+
'default' => 'background-color',
|
|
88
|
+
),
|
|
89
|
+
'path' => array( 'color', 'background' ),
|
|
90
|
+
'css_vars' => array(
|
|
91
|
+
'color' => '--wp--preset--color--$slug',
|
|
92
|
+
),
|
|
93
|
+
'classnames' => array(
|
|
94
|
+
'has-background' => true,
|
|
95
|
+
'has-$slug-background-color' => 'color',
|
|
96
|
+
),
|
|
97
|
+
),
|
|
98
|
+
'gradient' => array(
|
|
99
|
+
'property_keys' => array(
|
|
100
|
+
'default' => 'background',
|
|
101
|
+
),
|
|
102
|
+
'css_vars' => array(
|
|
103
|
+
'gradient' => '--wp--preset--gradient--$slug',
|
|
104
|
+
),
|
|
105
|
+
'path' => array( 'color', 'gradient' ),
|
|
106
|
+
'classnames' => array(
|
|
107
|
+
'has-background' => true,
|
|
108
|
+
'has-$slug-gradient-background' => 'gradient',
|
|
109
|
+
),
|
|
243
110
|
),
|
|
244
111
|
),
|
|
245
|
-
'
|
|
246
|
-
'
|
|
247
|
-
'
|
|
112
|
+
'border' => array(
|
|
113
|
+
'color' => array(
|
|
114
|
+
'property_keys' => array(
|
|
115
|
+
'default' => 'border-color',
|
|
116
|
+
'individual' => 'border-%s-color',
|
|
117
|
+
),
|
|
118
|
+
'path' => array( 'border', 'color' ),
|
|
119
|
+
'classnames' => array(
|
|
120
|
+
'has-border-color' => true,
|
|
121
|
+
'has-$slug-border-color' => 'color',
|
|
122
|
+
),
|
|
123
|
+
),
|
|
124
|
+
'radius' => array(
|
|
125
|
+
'property_keys' => array(
|
|
126
|
+
'default' => 'border-radius',
|
|
127
|
+
'individual' => 'border-%s-radius',
|
|
128
|
+
),
|
|
129
|
+
'path' => array( 'border', 'radius' ),
|
|
130
|
+
),
|
|
131
|
+
'style' => array(
|
|
132
|
+
'property_keys' => array(
|
|
133
|
+
'default' => 'border-style',
|
|
134
|
+
'individual' => 'border-%s-style',
|
|
135
|
+
),
|
|
136
|
+
'path' => array( 'border', 'style' ),
|
|
137
|
+
),
|
|
138
|
+
'width' => array(
|
|
139
|
+
'property_keys' => array(
|
|
140
|
+
'default' => 'border-width',
|
|
141
|
+
'individual' => 'border-%s-width',
|
|
142
|
+
),
|
|
143
|
+
'path' => array( 'border', 'width' ),
|
|
144
|
+
),
|
|
145
|
+
'top' => array(
|
|
146
|
+
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
|
|
147
|
+
'path' => array( 'border', 'top' ),
|
|
148
|
+
'css_vars' => array(
|
|
149
|
+
'color' => '--wp--preset--color--$slug',
|
|
150
|
+
),
|
|
151
|
+
),
|
|
152
|
+
'right' => array(
|
|
153
|
+
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
|
|
154
|
+
'path' => array( 'border', 'right' ),
|
|
155
|
+
'css_vars' => array(
|
|
156
|
+
'color' => '--wp--preset--color--$slug',
|
|
157
|
+
),
|
|
158
|
+
),
|
|
159
|
+
'bottom' => array(
|
|
160
|
+
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
|
|
161
|
+
'path' => array( 'border', 'bottom' ),
|
|
162
|
+
'css_vars' => array(
|
|
163
|
+
'color' => '--wp--preset--color--$slug',
|
|
164
|
+
),
|
|
165
|
+
),
|
|
166
|
+
'left' => array(
|
|
167
|
+
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
|
|
168
|
+
'path' => array( 'border', 'left' ),
|
|
169
|
+
'css_vars' => array(
|
|
170
|
+
'color' => '--wp--preset--color--$slug',
|
|
171
|
+
),
|
|
248
172
|
),
|
|
249
|
-
'path' => array( 'typography', 'fontStyle' ),
|
|
250
173
|
),
|
|
251
|
-
'
|
|
252
|
-
'
|
|
253
|
-
'
|
|
174
|
+
'shadow' => array(
|
|
175
|
+
'shadow' => array(
|
|
176
|
+
'property_keys' => array(
|
|
177
|
+
'default' => 'box-shadow',
|
|
178
|
+
),
|
|
179
|
+
'path' => array( 'shadow' ),
|
|
180
|
+
'css_vars' => array(
|
|
181
|
+
'shadow' => '--wp--preset--shadow--$slug',
|
|
182
|
+
),
|
|
254
183
|
),
|
|
255
|
-
'path' => array( 'typography', 'fontWeight' ),
|
|
256
184
|
),
|
|
257
|
-
'
|
|
258
|
-
'
|
|
259
|
-
'
|
|
185
|
+
'dimensions' => array(
|
|
186
|
+
'aspectRatio' => array(
|
|
187
|
+
'property_keys' => array(
|
|
188
|
+
'default' => 'aspect-ratio',
|
|
189
|
+
),
|
|
190
|
+
'path' => array( 'dimensions', 'aspectRatio' ),
|
|
191
|
+
'classnames' => array(
|
|
192
|
+
'has-aspect-ratio' => true,
|
|
193
|
+
),
|
|
194
|
+
),
|
|
195
|
+
'minHeight' => array(
|
|
196
|
+
'property_keys' => array(
|
|
197
|
+
'default' => 'min-height',
|
|
198
|
+
),
|
|
199
|
+
'path' => array( 'dimensions', 'minHeight' ),
|
|
200
|
+
'css_vars' => array(
|
|
201
|
+
'spacing' => '--wp--preset--spacing--$slug',
|
|
202
|
+
),
|
|
260
203
|
),
|
|
261
|
-
'path' => array( 'typography', 'lineHeight' ),
|
|
262
204
|
),
|
|
263
|
-
'
|
|
264
|
-
'
|
|
265
|
-
'
|
|
205
|
+
'spacing' => array(
|
|
206
|
+
'padding' => array(
|
|
207
|
+
'property_keys' => array(
|
|
208
|
+
'default' => 'padding',
|
|
209
|
+
'individual' => 'padding-%s',
|
|
210
|
+
),
|
|
211
|
+
'path' => array( 'spacing', 'padding' ),
|
|
212
|
+
'css_vars' => array(
|
|
213
|
+
'spacing' => '--wp--preset--spacing--$slug',
|
|
214
|
+
),
|
|
215
|
+
),
|
|
216
|
+
'margin' => array(
|
|
217
|
+
'property_keys' => array(
|
|
218
|
+
'default' => 'margin',
|
|
219
|
+
'individual' => 'margin-%s',
|
|
220
|
+
),
|
|
221
|
+
'path' => array( 'spacing', 'margin' ),
|
|
222
|
+
'css_vars' => array(
|
|
223
|
+
'spacing' => '--wp--preset--spacing--$slug',
|
|
224
|
+
),
|
|
266
225
|
),
|
|
267
|
-
'path' => array( 'typography', 'textColumns' ),
|
|
268
226
|
),
|
|
269
|
-
'
|
|
270
|
-
'
|
|
271
|
-
'
|
|
227
|
+
'typography' => array(
|
|
228
|
+
'fontSize' => array(
|
|
229
|
+
'property_keys' => array(
|
|
230
|
+
'default' => 'font-size',
|
|
231
|
+
),
|
|
232
|
+
'css_vars' => array(
|
|
233
|
+
'font-size' => '--wp--preset--font-size--$slug',
|
|
234
|
+
),
|
|
235
|
+
'path' => array( 'typography', 'fontSize' ),
|
|
236
|
+
'classnames' => array(
|
|
237
|
+
'has-$slug-font-size' => 'font-size',
|
|
238
|
+
),
|
|
239
|
+
),
|
|
240
|
+
'fontFamily' => array(
|
|
241
|
+
'property_keys' => array(
|
|
242
|
+
'default' => 'font-family',
|
|
243
|
+
),
|
|
244
|
+
'css_vars' => array(
|
|
245
|
+
'font-family' => '--wp--preset--font-family--$slug',
|
|
246
|
+
),
|
|
247
|
+
'path' => array( 'typography', 'fontFamily' ),
|
|
248
|
+
'classnames' => array(
|
|
249
|
+
'has-$slug-font-family' => 'font-family',
|
|
250
|
+
),
|
|
251
|
+
),
|
|
252
|
+
'fontStyle' => array(
|
|
253
|
+
'property_keys' => array(
|
|
254
|
+
'default' => 'font-style',
|
|
255
|
+
),
|
|
256
|
+
'path' => array( 'typography', 'fontStyle' ),
|
|
257
|
+
),
|
|
258
|
+
'fontWeight' => array(
|
|
259
|
+
'property_keys' => array(
|
|
260
|
+
'default' => 'font-weight',
|
|
261
|
+
),
|
|
262
|
+
'path' => array( 'typography', 'fontWeight' ),
|
|
263
|
+
),
|
|
264
|
+
'lineHeight' => array(
|
|
265
|
+
'property_keys' => array(
|
|
266
|
+
'default' => 'line-height',
|
|
267
|
+
),
|
|
268
|
+
'path' => array( 'typography', 'lineHeight' ),
|
|
269
|
+
),
|
|
270
|
+
'textColumns' => array(
|
|
271
|
+
'property_keys' => array(
|
|
272
|
+
'default' => 'column-count',
|
|
273
|
+
),
|
|
274
|
+
'path' => array( 'typography', 'textColumns' ),
|
|
275
|
+
),
|
|
276
|
+
'textDecoration' => array(
|
|
277
|
+
'property_keys' => array(
|
|
278
|
+
'default' => 'text-decoration',
|
|
279
|
+
),
|
|
280
|
+
'path' => array( 'typography', 'textDecoration' ),
|
|
281
|
+
),
|
|
282
|
+
'textTransform' => array(
|
|
283
|
+
'property_keys' => array(
|
|
284
|
+
'default' => 'text-transform',
|
|
285
|
+
),
|
|
286
|
+
'path' => array( 'typography', 'textTransform' ),
|
|
287
|
+
),
|
|
288
|
+
'letterSpacing' => array(
|
|
289
|
+
'property_keys' => array(
|
|
290
|
+
'default' => 'letter-spacing',
|
|
291
|
+
),
|
|
292
|
+
'path' => array( 'typography', 'letterSpacing' ),
|
|
293
|
+
),
|
|
294
|
+
'writingMode' => array(
|
|
295
|
+
'property_keys' => array(
|
|
296
|
+
'default' => 'writing-mode',
|
|
297
|
+
),
|
|
298
|
+
'path' => array( 'typography', 'writingMode' ),
|
|
272
299
|
),
|
|
273
|
-
'path' => array( 'typography', 'textDecoration' ),
|
|
274
300
|
),
|
|
275
|
-
|
|
276
|
-
'property_keys' => array(
|
|
277
|
-
'default' => 'text-transform',
|
|
278
|
-
),
|
|
279
|
-
'path' => array( 'typography', 'textTransform' ),
|
|
280
|
-
),
|
|
281
|
-
'letterSpacing' => array(
|
|
282
|
-
'property_keys' => array(
|
|
283
|
-
'default' => 'letter-spacing',
|
|
284
|
-
),
|
|
285
|
-
'path' => array( 'typography', 'letterSpacing' ),
|
|
286
|
-
),
|
|
287
|
-
'writingMode' => array(
|
|
288
|
-
'property_keys' => array(
|
|
289
|
-
'default' => 'writing-mode',
|
|
290
|
-
),
|
|
291
|
-
'path' => array( 'typography', 'writingMode' ),
|
|
292
|
-
),
|
|
293
|
-
),
|
|
294
|
-
);
|
|
301
|
+
);
|
|
295
302
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
303
|
+
/**
|
|
304
|
+
* Util: Extracts the slug in kebab case from a preset string, e.g., "heavenly-blue" from 'var:preset|color|heavenlyBlue'.
|
|
305
|
+
*
|
|
306
|
+
* @param string $style_value A single CSS preset value.
|
|
307
|
+
* @param string $property_key The CSS property that is the second element of the preset string. Used for matching.
|
|
308
|
+
*
|
|
309
|
+
* @return string The slug, or empty string if not found.
|
|
310
|
+
*/
|
|
311
|
+
protected static function get_slug_from_preset_value( $style_value, $property_key ) {
|
|
312
|
+
if ( is_string( $style_value ) && is_string( $property_key ) && str_contains( $style_value, "var:preset|{$property_key}|" ) ) {
|
|
313
|
+
$index_to_splice = strrpos( $style_value, '|' ) + 1;
|
|
314
|
+
return _wp_to_kebab_case( substr( $style_value, $index_to_splice ) );
|
|
315
|
+
}
|
|
316
|
+
return '';
|
|
308
317
|
}
|
|
309
|
-
return '';
|
|
310
|
-
}
|
|
311
318
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Util: Generates a CSS var string, e.g., var(--wp--preset--color--background) from a preset string such as `var:preset|space|50`.
|
|
321
|
+
*
|
|
322
|
+
* @param string $style_value A single CSS preset value.
|
|
323
|
+
* @param string[] $css_vars An associate array of CSS var patterns used to generate the var string.
|
|
324
|
+
*
|
|
325
|
+
* @return string The css var, or an empty string if no match for slug found.
|
|
326
|
+
*/
|
|
327
|
+
protected static function get_css_var_value( $style_value, $css_vars ) {
|
|
328
|
+
foreach ( $css_vars as $property_key => $css_var_pattern ) {
|
|
329
|
+
$slug = static::get_slug_from_preset_value( $style_value, $property_key );
|
|
330
|
+
if ( static::is_valid_style_value( $slug ) ) {
|
|
331
|
+
$var = strtr(
|
|
332
|
+
$css_var_pattern,
|
|
333
|
+
array( '$slug' => $slug )
|
|
334
|
+
);
|
|
335
|
+
return "var($var)";
|
|
336
|
+
}
|
|
329
337
|
}
|
|
338
|
+
return '';
|
|
330
339
|
}
|
|
331
|
-
return '';
|
|
332
|
-
}
|
|
333
340
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Stores a CSS rule using the provided CSS selector and CSS declarations.
|
|
347
|
-
*
|
|
348
|
-
* @param string $store_name A valid store key.
|
|
349
|
-
* @param string $css_selector When a selector is passed, the function will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
|
|
350
|
-
* @param string[] $css_declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
|
|
351
|
-
*
|
|
352
|
-
* @return void.
|
|
353
|
-
*/
|
|
354
|
-
public static function store_css_rule( $store_name, $css_selector, $css_declarations ) {
|
|
355
|
-
if ( empty( $store_name ) || empty( $css_selector ) || empty( $css_declarations ) ) {
|
|
356
|
-
return;
|
|
341
|
+
/**
|
|
342
|
+
* Util: Checks whether an incoming block style value is valid.
|
|
343
|
+
*
|
|
344
|
+
* @param string? $style_value A single css preset value.
|
|
345
|
+
*
|
|
346
|
+
* @return bool
|
|
347
|
+
*/
|
|
348
|
+
protected static function is_valid_style_value( $style_value ) {
|
|
349
|
+
return '0' === $style_value || ! empty( $style_value );
|
|
357
350
|
}
|
|
358
|
-
static::get_store( $store_name )->add_rule( $css_selector )->add_declarations( $css_declarations );
|
|
359
|
-
}
|
|
360
351
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
352
|
+
/**
|
|
353
|
+
* Stores a CSS rule using the provided CSS selector and CSS declarations.
|
|
354
|
+
*
|
|
355
|
+
* @param string $store_name A valid store key.
|
|
356
|
+
* @param string $css_selector When a selector is passed, the function will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
|
|
357
|
+
* @param string[] $css_declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
|
|
358
|
+
*
|
|
359
|
+
* @return void.
|
|
360
|
+
*/
|
|
361
|
+
public static function store_css_rule( $store_name, $css_selector, $css_declarations, $css_at_rule = '' ) {
|
|
362
|
+
if ( empty( $store_name ) || empty( $css_selector ) || empty( $css_declarations ) ) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
static::get_store( $store_name )->add_rule( $css_selector, $css_at_rule )->add_declarations( $css_declarations );
|
|
366
|
+
}
|
|
371
367
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
*
|
|
382
|
-
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
|
|
383
|
-
* @type string $selector Optional. When a selector is passed, the value of `$css` in the return value will comprise a full CSS rule `$selector { ...$css_declarations }`,
|
|
384
|
-
* otherwise, the value will be a concatenated string of CSS declarations.
|
|
385
|
-
* }
|
|
386
|
-
*
|
|
387
|
-
* @return array {
|
|
388
|
-
* @type string $classnames Classnames separated by a space.
|
|
389
|
-
* @type string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
|
|
390
|
-
* }
|
|
391
|
-
*/
|
|
392
|
-
public static function parse_block_styles( $block_styles, $options ) {
|
|
393
|
-
$parsed_styles = array(
|
|
394
|
-
'classnames' => array(),
|
|
395
|
-
'declarations' => array(),
|
|
396
|
-
);
|
|
397
|
-
if ( empty( $block_styles ) || ! is_array( $block_styles ) ) {
|
|
398
|
-
return $parsed_styles;
|
|
368
|
+
/**
|
|
369
|
+
* Returns a store by store key.
|
|
370
|
+
*
|
|
371
|
+
* @param string $store_name A store key.
|
|
372
|
+
*
|
|
373
|
+
* @return WP_Style_Engine_CSS_Rules_Store
|
|
374
|
+
*/
|
|
375
|
+
public static function get_store( $store_name ) {
|
|
376
|
+
return WP_Style_Engine_CSS_Rules_Store::get_store( $store_name );
|
|
399
377
|
}
|
|
400
378
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
379
|
+
/**
|
|
380
|
+
* Returns classnames and CSS based on the values in a styles object.
|
|
381
|
+
* Return values are parsed based on the instructions in BLOCK_STYLE_DEFINITIONS_METADATA.
|
|
382
|
+
*
|
|
383
|
+
* @since 6.1.0
|
|
384
|
+
*
|
|
385
|
+
* @param array $block_styles The style object.
|
|
386
|
+
* @param array $options {
|
|
387
|
+
* Optional. An array of options. Default empty array.
|
|
388
|
+
*
|
|
389
|
+
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
|
|
390
|
+
* @type string $selector Optional. When a selector is passed, the value of `$css` in the return value will comprise a full CSS rule `$selector { ...$css_declarations }`,
|
|
391
|
+
* otherwise, the value will be a concatenated string of CSS declarations.
|
|
392
|
+
* }
|
|
393
|
+
*
|
|
394
|
+
* @return array {
|
|
395
|
+
* @type string $classnames Classnames separated by a space.
|
|
396
|
+
* @type string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
|
|
397
|
+
* }
|
|
398
|
+
*/
|
|
399
|
+
public static function parse_block_styles( $block_styles, $options ) {
|
|
400
|
+
$parsed_styles = array(
|
|
401
|
+
'classnames' => array(),
|
|
402
|
+
'declarations' => array(),
|
|
403
|
+
);
|
|
404
|
+
if ( empty( $block_styles ) || ! is_array( $block_styles ) ) {
|
|
405
|
+
return $parsed_styles;
|
|
405
406
|
}
|
|
406
|
-
foreach ( $definition_group_style as $style_definition ) {
|
|
407
|
-
$style_value = _wp_array_get( $block_styles, $style_definition['path'], null );
|
|
408
407
|
|
|
409
|
-
|
|
408
|
+
// Collect CSS and classnames.
|
|
409
|
+
foreach ( static::BLOCK_STYLE_DEFINITIONS_METADATA as $definition_group_key => $definition_group_style ) {
|
|
410
|
+
if ( empty( $block_styles[ $definition_group_key ] ) ) {
|
|
410
411
|
continue;
|
|
411
412
|
}
|
|
413
|
+
foreach ( $definition_group_style as $style_definition ) {
|
|
414
|
+
$style_value = _wp_array_get( $block_styles, $style_definition['path'], null );
|
|
412
415
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}
|
|
416
|
+
if ( ! static::is_valid_style_value( $style_value ) ) {
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
417
419
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
+
$parsed_styles['classnames'] = array_merge( $parsed_styles['classnames'], static::get_classnames( $style_value, $style_definition ) );
|
|
421
|
+
$parsed_styles['declarations'] = array_merge( $parsed_styles['declarations'], static::get_css_declarations( $style_value, $style_definition, $options ) );
|
|
422
|
+
}
|
|
423
|
+
}
|
|
420
424
|
|
|
421
|
-
|
|
422
|
-
* Returns classnames, and generates classname(s) from a CSS preset property pattern, e.g., '`var:preset|<PRESET_TYPE>|<PRESET_SLUG>`'.
|
|
423
|
-
*
|
|
424
|
-
* @param array $style_value A single raw style value or css preset property from the $block_styles array.
|
|
425
|
-
* @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
|
|
426
|
-
*
|
|
427
|
-
* @return array|string[] An array of CSS classnames, or empty array.
|
|
428
|
-
*/
|
|
429
|
-
protected static function get_classnames( $style_value, $style_definition ) {
|
|
430
|
-
if ( empty( $style_value ) ) {
|
|
431
|
-
return array();
|
|
425
|
+
return $parsed_styles;
|
|
432
426
|
}
|
|
433
427
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
428
|
+
/**
|
|
429
|
+
* Returns classnames, and generates classname(s) from a CSS preset property pattern, e.g., '`var:preset|<PRESET_TYPE>|<PRESET_SLUG>`'.
|
|
430
|
+
*
|
|
431
|
+
* @param array $style_value A single raw style value or css preset property from the $block_styles array.
|
|
432
|
+
* @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
|
|
433
|
+
*
|
|
434
|
+
* @return array|string[] An array of CSS classnames, or empty array.
|
|
435
|
+
*/
|
|
436
|
+
protected static function get_classnames( $style_value, $style_definition ) {
|
|
437
|
+
if ( empty( $style_value ) ) {
|
|
438
|
+
return array();
|
|
439
|
+
}
|
|
442
440
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
$
|
|
441
|
+
$classnames = array();
|
|
442
|
+
if ( ! empty( $style_definition['classnames'] ) ) {
|
|
443
|
+
foreach ( $style_definition['classnames'] as $classname => $property_key ) {
|
|
444
|
+
if ( true === $property_key ) {
|
|
445
|
+
$classnames[] = $classname;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
$slug = static::get_slug_from_preset_value( $style_value, $property_key );
|
|
449
|
+
|
|
450
|
+
if ( $slug ) {
|
|
451
|
+
/*
|
|
452
|
+
* Right now we expect a classname pattern to be stored in BLOCK_STYLE_DEFINITIONS_METADATA.
|
|
453
|
+
* One day, if there are no stored schemata, we could allow custom patterns or
|
|
454
|
+
* generate classnames based on other properties
|
|
455
|
+
* such as a path or a value or a prefix passed in options.
|
|
456
|
+
*/
|
|
457
|
+
$classnames[] = strtr( $classname, array( '$slug' => $slug ) );
|
|
458
|
+
}
|
|
451
459
|
}
|
|
452
460
|
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return $classnames;
|
|
456
|
-
}
|
|
457
461
|
|
|
458
|
-
|
|
459
|
-
* Returns an array of CSS declarations based on valid block style values.
|
|
460
|
-
*
|
|
461
|
-
* @since 6.1.0
|
|
462
|
-
*
|
|
463
|
-
* @param array $style_value A single raw style value from $block_styles array.
|
|
464
|
-
* @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
|
|
465
|
-
* @param array $options {
|
|
466
|
-
* Optional. An array of options. Default empty array.
|
|
467
|
-
*
|
|
468
|
-
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
|
|
469
|
-
* }
|
|
470
|
-
*
|
|
471
|
-
* @return string[] An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
|
|
472
|
-
*/
|
|
473
|
-
protected static function get_css_declarations( $style_value, $style_definition, $options = array() ) {
|
|
474
|
-
if ( isset( $style_definition['value_func'] ) && is_callable( $style_definition['value_func'] ) ) {
|
|
475
|
-
return call_user_func( $style_definition['value_func'], $style_value, $style_definition, $options );
|
|
462
|
+
return $classnames;
|
|
476
463
|
}
|
|
477
464
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
*
|
|
484
|
-
*
|
|
465
|
+
/**
|
|
466
|
+
* Returns an array of CSS declarations based on valid block style values.
|
|
467
|
+
*
|
|
468
|
+
* @since 6.1.0
|
|
469
|
+
*
|
|
470
|
+
* @param array $style_value A single raw style value from $block_styles array.
|
|
471
|
+
* @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
|
|
472
|
+
* @param array $options {
|
|
473
|
+
* Optional. An array of options. Default empty array.
|
|
474
|
+
*
|
|
475
|
+
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
|
|
476
|
+
* }
|
|
477
|
+
*
|
|
478
|
+
* @return string[] An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
|
|
485
479
|
*/
|
|
486
|
-
|
|
487
|
-
if (
|
|
488
|
-
|
|
489
|
-
if ( static::is_valid_style_value( $css_var ) ) {
|
|
490
|
-
$css_declarations[ $style_property_keys['default'] ] = $css_var;
|
|
491
|
-
}
|
|
480
|
+
protected static function get_css_declarations( $style_value, $style_definition, $options = array() ) {
|
|
481
|
+
if ( isset( $style_definition['value_func'] ) && is_callable( $style_definition['value_func'] ) ) {
|
|
482
|
+
return call_user_func( $style_definition['value_func'], $style_value, $style_definition, $options );
|
|
492
483
|
}
|
|
493
|
-
return $css_declarations;
|
|
494
|
-
}
|
|
495
484
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
485
|
+
$css_declarations = array();
|
|
486
|
+
$style_property_keys = $style_definition['property_keys'];
|
|
487
|
+
$should_skip_css_vars = isset( $options['convert_vars_to_classnames'] ) && true === $options['convert_vars_to_classnames'];
|
|
488
|
+
|
|
489
|
+
/*
|
|
490
|
+
* Build CSS var values from `var:preset|<PRESET_TYPE>|<PRESET_SLUG>` values, e.g, `var(--wp--css--rule-slug )`.
|
|
491
|
+
* Check if the value is a CSS preset and there's a corresponding css_var pattern in the style definition.
|
|
492
|
+
*/
|
|
493
|
+
if ( is_string( $style_value ) && str_contains( $style_value, 'var:' ) ) {
|
|
494
|
+
if ( ! $should_skip_css_vars && ! empty( $style_definition['css_vars'] ) ) {
|
|
495
|
+
$css_var = static::get_css_var_value( $style_value, $style_definition['css_vars'] );
|
|
496
|
+
if ( static::is_valid_style_value( $css_var ) ) {
|
|
497
|
+
$css_declarations[ $style_property_keys['default'] ] = $css_var;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
504
500
|
return $css_declarations;
|
|
505
501
|
}
|
|
506
502
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
503
|
+
/*
|
|
504
|
+
* Default rule builder.
|
|
505
|
+
* If the input contains an array, assume box model-like properties
|
|
506
|
+
* for styles such as margins and padding.
|
|
507
|
+
*/
|
|
508
|
+
if ( is_array( $style_value ) ) {
|
|
509
|
+
// Bail out early if the `'individual'` property is not defined.
|
|
510
|
+
if ( ! isset( $style_property_keys['individual'] ) ) {
|
|
511
|
+
return $css_declarations;
|
|
510
512
|
}
|
|
511
513
|
|
|
512
|
-
|
|
514
|
+
foreach ( $style_value as $key => $value ) {
|
|
515
|
+
if ( is_string( $value ) && str_contains( $value, 'var:' ) && ! $should_skip_css_vars && ! empty( $style_definition['css_vars'] ) ) {
|
|
516
|
+
$value = static::get_css_var_value( $value, $style_definition['css_vars'] );
|
|
517
|
+
}
|
|
513
518
|
|
|
514
|
-
|
|
515
|
-
|
|
519
|
+
$individual_property = sprintf( $style_property_keys['individual'], _wp_to_kebab_case( $key ) );
|
|
520
|
+
|
|
521
|
+
if ( $individual_property && static::is_valid_style_value( $value ) ) {
|
|
522
|
+
$css_declarations[ $individual_property ] = $value;
|
|
523
|
+
}
|
|
516
524
|
}
|
|
525
|
+
|
|
526
|
+
return $css_declarations;
|
|
517
527
|
}
|
|
518
528
|
|
|
529
|
+
$css_declarations[ $style_property_keys['default'] ] = $style_value;
|
|
519
530
|
return $css_declarations;
|
|
520
531
|
}
|
|
521
532
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
|
|
539
|
-
* }
|
|
540
|
-
*
|
|
541
|
-
* @return string[] An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
|
|
542
|
-
*/
|
|
543
|
-
protected static function get_individual_property_css_declarations( $style_value, $individual_property_definition, $options = array() ) {
|
|
544
|
-
if ( ! is_array( $style_value ) || empty( $style_value ) || empty( $individual_property_definition['path'] ) ) {
|
|
545
|
-
return array();
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
/*
|
|
549
|
-
* The first item in $individual_property_definition['path'] array tells us the style property, e.g., "border".
|
|
550
|
-
* We use this to get a corresponding CSS style definition such as "color" or "width" from the same group.
|
|
551
|
-
* The second item in $individual_property_definition['path'] array refers to the individual property marker, e.g., "top".
|
|
533
|
+
/**
|
|
534
|
+
* Style value parser that returns a CSS definition array comprising style properties
|
|
535
|
+
* that have keys representing individual style properties, otherwise known as longhand CSS properties.
|
|
536
|
+
* e.g., "$style_property-$individual_feature: $value;", which could represent the following:
|
|
537
|
+
* "border-{top|right|bottom|left}-{color|width|style}: {value};" or,
|
|
538
|
+
* "border-image-{outset|source|width|repeat|slice}: {value};"
|
|
539
|
+
*
|
|
540
|
+
* @param array $style_value A single raw style value from $block_styles array.
|
|
541
|
+
* @param array $individual_property_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA representing an individual property of a CSS property, e.g., 'top' in 'border-top'.
|
|
542
|
+
* @param array $options {
|
|
543
|
+
* Optional. An array of options. Default empty array.
|
|
544
|
+
*
|
|
545
|
+
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
|
|
546
|
+
* }
|
|
547
|
+
*
|
|
548
|
+
* @return string[] An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
|
|
552
549
|
*/
|
|
553
|
-
$
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
$css_declarations = array();
|
|
557
|
-
|
|
558
|
-
foreach ( $style_value as $css_property => $value ) {
|
|
559
|
-
if ( empty( $value ) ) {
|
|
560
|
-
continue;
|
|
550
|
+
protected static function get_individual_property_css_declarations( $style_value, $individual_property_definition, $options = array() ) {
|
|
551
|
+
if ( ! is_array( $style_value ) || empty( $style_value ) || empty( $individual_property_definition['path'] ) ) {
|
|
552
|
+
return array();
|
|
561
553
|
}
|
|
562
554
|
|
|
563
|
-
|
|
564
|
-
$
|
|
565
|
-
|
|
555
|
+
/*
|
|
556
|
+
* The first item in $individual_property_definition['path'] array tells us the style property, e.g., "border".
|
|
557
|
+
* We use this to get a corresponding CSS style definition such as "color" or "width" from the same group.
|
|
558
|
+
* The second item in $individual_property_definition['path'] array refers to the individual property marker, e.g., "top".
|
|
559
|
+
*/
|
|
560
|
+
$definition_group_key = $individual_property_definition['path'][0];
|
|
561
|
+
$individual_property_key = $individual_property_definition['path'][1];
|
|
562
|
+
$should_skip_css_vars = isset( $options['convert_vars_to_classnames'] ) && true === $options['convert_vars_to_classnames'];
|
|
563
|
+
$css_declarations = array();
|
|
564
|
+
|
|
565
|
+
foreach ( $style_value as $css_property => $value ) {
|
|
566
|
+
if ( empty( $value ) ) {
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
566
569
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
570
|
+
// Build a path to the individual rules in definitions.
|
|
571
|
+
$style_definition_path = array( $definition_group_key, $css_property );
|
|
572
|
+
$style_definition = _wp_array_get( static::BLOCK_STYLE_DEFINITIONS_METADATA, $style_definition_path, null );
|
|
573
|
+
|
|
574
|
+
if ( $style_definition && isset( $style_definition['property_keys']['individual'] ) ) {
|
|
575
|
+
// Set a CSS var if there is a valid preset value.
|
|
576
|
+
if ( is_string( $value ) && str_contains( $value, 'var:' ) && ! $should_skip_css_vars && ! empty( $individual_property_definition['css_vars'] ) ) {
|
|
577
|
+
$value = static::get_css_var_value( $value, $individual_property_definition['css_vars'] );
|
|
578
|
+
}
|
|
579
|
+
$individual_css_property = sprintf( $style_definition['property_keys']['individual'], $individual_property_key );
|
|
580
|
+
$css_declarations[ $individual_css_property ] = $value;
|
|
571
581
|
}
|
|
572
|
-
$individual_css_property = sprintf( $style_definition['property_keys']['individual'], $individual_property_key );
|
|
573
|
-
$css_declarations[ $individual_css_property ] = $value;
|
|
574
582
|
}
|
|
583
|
+
return $css_declarations;
|
|
575
584
|
}
|
|
576
|
-
return $css_declarations;
|
|
577
|
-
}
|
|
578
585
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
586
|
+
/**
|
|
587
|
+
* Style value parser that constructs a CSS definition array comprising a single CSS property and value.
|
|
588
|
+
* If the provided value is an array containing a `url` property, the function will return a CSS definition array
|
|
589
|
+
* with a single property and value, with `url` escaped and injected into a CSS `url()` function,
|
|
590
|
+
* e.g., array( 'background-image' => "url( '...' )" ).
|
|
591
|
+
*
|
|
592
|
+
* @param array $style_value A single raw style value from $block_styles array.
|
|
593
|
+
* @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
|
|
594
|
+
*
|
|
595
|
+
* @return string[] An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
|
|
596
|
+
*/
|
|
597
|
+
protected static function get_url_or_value_css_declaration( $style_value, $style_definition ) {
|
|
598
|
+
if ( empty( $style_value ) ) {
|
|
599
|
+
return array();
|
|
600
|
+
}
|
|
594
601
|
|
|
595
|
-
|
|
602
|
+
$css_declarations = array();
|
|
596
603
|
|
|
597
|
-
|
|
598
|
-
|
|
604
|
+
if ( isset( $style_definition['property_keys']['default'] ) ) {
|
|
605
|
+
$value = null;
|
|
599
606
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
607
|
+
if ( ! empty( $style_value['url'] ) ) {
|
|
608
|
+
$value = "url('" . $style_value['url'] . "')";
|
|
609
|
+
} elseif ( is_string( $style_value ) ) {
|
|
610
|
+
$value = $style_value;
|
|
611
|
+
}
|
|
605
612
|
|
|
606
|
-
|
|
607
|
-
|
|
613
|
+
if ( null !== $value ) {
|
|
614
|
+
$css_declarations[ $style_definition['property_keys']['default'] ] = $value;
|
|
615
|
+
}
|
|
608
616
|
}
|
|
617
|
+
|
|
618
|
+
return $css_declarations;
|
|
609
619
|
}
|
|
610
620
|
|
|
611
|
-
|
|
612
|
-
|
|
621
|
+
/**
|
|
622
|
+
* Returns compiled CSS from css_declarations.
|
|
623
|
+
*
|
|
624
|
+
* @param string[] $css_declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
|
|
625
|
+
* @param string $css_selector When a selector is passed, the function will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values.
|
|
626
|
+
*
|
|
627
|
+
* @return string A compiled CSS string.
|
|
628
|
+
*/
|
|
629
|
+
public static function compile_css( $css_declarations, $css_selector ) {
|
|
630
|
+
if ( empty( $css_declarations ) || ! is_array( $css_declarations ) ) {
|
|
631
|
+
return '';
|
|
632
|
+
}
|
|
613
633
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
*
|
|
620
|
-
* @return string A compiled CSS string.
|
|
621
|
-
*/
|
|
622
|
-
public static function compile_css( $css_declarations, $css_selector ) {
|
|
623
|
-
if ( empty( $css_declarations ) || ! is_array( $css_declarations ) ) {
|
|
624
|
-
return '';
|
|
625
|
-
}
|
|
634
|
+
// Return an entire rule if there is a selector.
|
|
635
|
+
if ( $css_selector ) {
|
|
636
|
+
$css_rule = new WP_Style_Engine_CSS_Rule( $css_selector, $css_declarations );
|
|
637
|
+
return $css_rule->get_css();
|
|
638
|
+
}
|
|
626
639
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
$css_rule = new WP_Style_Engine_CSS_Rule( $css_selector, $css_declarations );
|
|
630
|
-
return $css_rule->get_css();
|
|
640
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $css_declarations );
|
|
641
|
+
return $css_declarations->get_declarations_string();
|
|
631
642
|
}
|
|
632
643
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
$processor = new WP_Style_Engine_Processor();
|
|
652
|
-
$processor->add_rules( $css_rules );
|
|
653
|
-
return $processor->get_css( $options );
|
|
644
|
+
/**
|
|
645
|
+
* Returns a compiled stylesheet from stored CSS rules.
|
|
646
|
+
*
|
|
647
|
+
* @param WP_Style_Engine_CSS_Rule[] $css_rules An array of WP_Style_Engine_CSS_Rule objects from a store or otherwise.
|
|
648
|
+
* @param array $options {
|
|
649
|
+
* Optional. An array of options. Default empty array.
|
|
650
|
+
*
|
|
651
|
+
* @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
|
|
652
|
+
* @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined.
|
|
653
|
+
* }
|
|
654
|
+
*
|
|
655
|
+
* @return string A compiled stylesheet from stored CSS rules.
|
|
656
|
+
*/
|
|
657
|
+
public static function compile_stylesheet_from_css_rules( $css_rules, $options = array() ) {
|
|
658
|
+
$processor = new WP_Style_Engine_Processor();
|
|
659
|
+
$processor->add_rules( $css_rules );
|
|
660
|
+
return $processor->get_css( $options );
|
|
661
|
+
}
|
|
654
662
|
}
|
|
655
663
|
}
|