@wordpress/style-engine 0.9.0 → 0.12.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 +6 -0
- package/README.md +38 -6
- package/build/styles/border/index.js +94 -0
- package/build/styles/border/index.js.map +1 -0
- package/build/styles/index.js +3 -1
- package/build/styles/index.js.map +1 -1
- package/build/styles/spacing/margin.js +4 -1
- package/build/styles/spacing/margin.js.map +1 -1
- package/build/styles/spacing/padding.js +4 -1
- package/build/styles/spacing/padding.js.map +1 -1
- package/build/styles/utils.js +26 -10
- package/build/styles/utils.js.map +1 -1
- package/build-module/styles/border/index.js +85 -0
- package/build-module/styles/border/index.js.map +1 -0
- package/build-module/styles/index.js +2 -1
- package/build-module/styles/index.js.map +1 -1
- package/build-module/styles/spacing/margin.js +4 -1
- package/build-module/styles/spacing/margin.js.map +1 -1
- package/build-module/styles/spacing/padding.js +4 -1
- package/build-module/styles/spacing/padding.js.map +1 -1
- package/build-module/styles/utils.js +25 -11
- package/build-module/styles/utils.js.map +1 -1
- package/build-types/styles/border/index.d.ts +10 -0
- package/build-types/styles/border/index.d.ts.map +1 -0
- package/build-types/styles/index.d.ts +3 -7
- package/build-types/styles/index.d.ts.map +1 -1
- package/build-types/styles/spacing/margin.d.ts.map +1 -1
- package/build-types/styles/spacing/padding.d.ts.map +1 -1
- package/build-types/styles/utils.d.ts +16 -7
- package/build-types/styles/utils.d.ts.map +1 -1
- package/build-types/types.d.ts +26 -1
- package/build-types/types.d.ts.map +1 -1
- package/class-wp-style-engine-css-declarations.php +119 -0
- package/class-wp-style-engine.php +322 -108
- package/package.json +2 -2
- package/phpunit/class-wp-style-engine-css-declarations-test.php +108 -0
- package/phpunit/class-wp-style-engine-test.php +296 -12
- package/src/styles/border/index.ts +145 -0
- package/src/styles/index.ts +7 -1
- package/src/styles/spacing/margin.ts +4 -6
- package/src/styles/spacing/padding.ts +4 -6
- package/src/styles/utils.ts +36 -12
- package/src/test/index.js +51 -0
- package/src/test/utils.js +12 -0
- package/src/types.ts +33 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Tests the Style Engine CSS declarations class.
|
|
4
|
+
*
|
|
5
|
+
* @package Gutenberg
|
|
6
|
+
* @subpackage style-engine
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Tests for registering, storing and generating CSS declarations.
|
|
13
|
+
*/
|
|
14
|
+
class WP_Style_Engine_CSS_Declarations_Test extends WP_UnitTestCase {
|
|
15
|
+
/**
|
|
16
|
+
* Should set declarations on instantiation.
|
|
17
|
+
*/
|
|
18
|
+
public function test_instantiate_with_declarations() {
|
|
19
|
+
$input_declarations = array(
|
|
20
|
+
'margin-top' => '10px',
|
|
21
|
+
'font-size' => '2rem',
|
|
22
|
+
);
|
|
23
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
24
|
+
$this->assertSame( $input_declarations, $css_declarations->get_declarations() );
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Should add declarations.
|
|
29
|
+
*/
|
|
30
|
+
public function test_add_declarations() {
|
|
31
|
+
$input_declarations = array(
|
|
32
|
+
'padding' => '20px',
|
|
33
|
+
'color' => 'var(--wp--preset--elbow-patches)',
|
|
34
|
+
);
|
|
35
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations();
|
|
36
|
+
$css_declarations->add_declarations( $input_declarations );
|
|
37
|
+
$this->assertSame( $input_declarations, $css_declarations->get_declarations() );
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Should add declarations.
|
|
42
|
+
*/
|
|
43
|
+
public function test_add_a_single_declaration() {
|
|
44
|
+
$input_declarations = array(
|
|
45
|
+
'border-width' => '1%',
|
|
46
|
+
'background-color' => 'var(--wp--preset--english-mustard)',
|
|
47
|
+
);
|
|
48
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
49
|
+
$extra_declaration = array(
|
|
50
|
+
'letter-spacing' => '1.5px',
|
|
51
|
+
);
|
|
52
|
+
$css_declarations->add_declarations( $extra_declaration );
|
|
53
|
+
$this->assertSame( array_merge( $input_declarations, $extra_declaration ), $css_declarations->get_declarations() );
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Should sanitize properties before storing.
|
|
58
|
+
*/
|
|
59
|
+
public function test_sanitize_properties() {
|
|
60
|
+
$input_declarations = array(
|
|
61
|
+
'^--wp--style--sleepy-potato$' => '40px',
|
|
62
|
+
'<background-//color>' => 'var(--wp--preset--english-mustard)',
|
|
63
|
+
);
|
|
64
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
65
|
+
|
|
66
|
+
$this->assertSame(
|
|
67
|
+
array(
|
|
68
|
+
'--wp--style--sleepy-potato' => '40px',
|
|
69
|
+
'background-color' => 'var(--wp--preset--english-mustard)',
|
|
70
|
+
),
|
|
71
|
+
$css_declarations->get_declarations()
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Should compile css declarations into a css declarations block string.
|
|
77
|
+
*/
|
|
78
|
+
public function test_generate_css_declarations_string() {
|
|
79
|
+
$input_declarations = array(
|
|
80
|
+
'color' => 'red',
|
|
81
|
+
'border-top-left-radius' => '99px',
|
|
82
|
+
'text-decoration' => 'underline',
|
|
83
|
+
);
|
|
84
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
85
|
+
|
|
86
|
+
$this->assertSame(
|
|
87
|
+
'color: red; border-top-left-radius: 99px; text-decoration: underline;',
|
|
88
|
+
$css_declarations->get_declarations_string()
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Should escape values and run the CSS through safecss_filter_attr.
|
|
94
|
+
*/
|
|
95
|
+
public function test_remove_unsafe_properties_and_values() {
|
|
96
|
+
$input_declarations = array(
|
|
97
|
+
'color' => '<red/>',
|
|
98
|
+
'margin-right' => '10em',
|
|
99
|
+
'potato' => 'uppercase',
|
|
100
|
+
);
|
|
101
|
+
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );
|
|
102
|
+
|
|
103
|
+
$this->assertSame(
|
|
104
|
+
'color: <red/>; margin-right: 10em;',
|
|
105
|
+
$css_declarations->get_declarations_string()
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @subpackage style-engine
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
|
|
9
10
|
require __DIR__ . '/../class-wp-style-engine.php';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -13,12 +14,16 @@ require __DIR__ . '/../class-wp-style-engine.php';
|
|
|
13
14
|
*/
|
|
14
15
|
class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
15
16
|
/**
|
|
16
|
-
* Tests generating styles and classnames based on various manifestations of the $block_styles argument.
|
|
17
|
+
* Tests generating block styles and classnames based on various manifestations of the $block_styles argument.
|
|
17
18
|
*
|
|
18
|
-
* @dataProvider
|
|
19
|
+
* @dataProvider data_generate_block_supports_styles_fixtures
|
|
20
|
+
*
|
|
21
|
+
* @param array $block_styles The incoming block styles object.
|
|
22
|
+
* @param array $options Style engine options.
|
|
23
|
+
* @param string $expected_output The expected output.
|
|
19
24
|
*/
|
|
20
|
-
function
|
|
21
|
-
$generated_styles =
|
|
25
|
+
public function test_generate_block_supports_styles( $block_styles, $options, $expected_output ) {
|
|
26
|
+
$generated_styles = wp_style_engine_get_block_supports_styles( $block_styles, $options );
|
|
22
27
|
$this->assertSame( $expected_output, $generated_styles );
|
|
23
28
|
}
|
|
24
29
|
|
|
@@ -27,15 +32,17 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
27
32
|
*
|
|
28
33
|
* @return array
|
|
29
34
|
*/
|
|
30
|
-
public function
|
|
35
|
+
public function data_generate_block_supports_styles_fixtures() {
|
|
31
36
|
return array(
|
|
32
37
|
'default_return_value' => array(
|
|
33
38
|
'block_styles' => array(),
|
|
39
|
+
'options' => null,
|
|
34
40
|
'expected_output' => null,
|
|
35
41
|
),
|
|
36
42
|
|
|
37
43
|
'inline_invalid_block_styles_empty' => array(
|
|
38
44
|
'block_styles' => 'hello world!',
|
|
45
|
+
'options' => null,
|
|
39
46
|
'expected_output' => null,
|
|
40
47
|
),
|
|
41
48
|
|
|
@@ -43,6 +50,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
43
50
|
'block_styles' => array(
|
|
44
51
|
'pageBreakAfter' => 'verso',
|
|
45
52
|
),
|
|
53
|
+
'options' => null,
|
|
46
54
|
'expected_output' => array(),
|
|
47
55
|
),
|
|
48
56
|
|
|
@@ -50,6 +58,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
50
58
|
'block_styles' => array(
|
|
51
59
|
'pageBreakAfter' => 'verso',
|
|
52
60
|
),
|
|
61
|
+
'options' => null,
|
|
53
62
|
'expected_output' => array(),
|
|
54
63
|
),
|
|
55
64
|
|
|
@@ -59,6 +68,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
59
68
|
'gap' => '1000vw',
|
|
60
69
|
),
|
|
61
70
|
),
|
|
71
|
+
'options' => null,
|
|
62
72
|
'expected_output' => array(),
|
|
63
73
|
),
|
|
64
74
|
|
|
@@ -68,12 +78,25 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
68
78
|
'text' => 'var:preset|color|texas-flood',
|
|
69
79
|
),
|
|
70
80
|
'spacing' => array(
|
|
71
|
-
'margin'
|
|
81
|
+
'margin' => '111px',
|
|
82
|
+
'padding' => '0',
|
|
83
|
+
),
|
|
84
|
+
'border' => array(
|
|
85
|
+
'color' => 'var:preset|color|cool-caramel',
|
|
86
|
+
'width' => '2rem',
|
|
87
|
+
'style' => 'dotted',
|
|
72
88
|
),
|
|
73
89
|
),
|
|
90
|
+
'options' => array( 'convert_vars_to_classnames' => true ),
|
|
74
91
|
'expected_output' => array(
|
|
75
|
-
'css'
|
|
76
|
-
'
|
|
92
|
+
'css' => 'border-style: dotted; border-width: 2rem; padding: 0; margin: 111px;',
|
|
93
|
+
'declarations' => array(
|
|
94
|
+
'border-style' => 'dotted',
|
|
95
|
+
'border-width' => '2rem',
|
|
96
|
+
'padding' => '0',
|
|
97
|
+
'margin' => '111px',
|
|
98
|
+
),
|
|
99
|
+
'classnames' => 'has-text-color has-texas-flood-color has-border-color has-cool-caramel-border-color',
|
|
77
100
|
),
|
|
78
101
|
),
|
|
79
102
|
|
|
@@ -93,9 +116,32 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
93
116
|
'right' => '10em',
|
|
94
117
|
),
|
|
95
118
|
),
|
|
119
|
+
'border' => array(
|
|
120
|
+
'radius' => array(
|
|
121
|
+
'topLeft' => '99px',
|
|
122
|
+
'topRight' => '98px',
|
|
123
|
+
'bottomLeft' => '97px',
|
|
124
|
+
'bottomRight' => '96px',
|
|
125
|
+
),
|
|
126
|
+
),
|
|
96
127
|
),
|
|
128
|
+
'options' => null,
|
|
97
129
|
'expected_output' => array(
|
|
98
|
-
'css'
|
|
130
|
+
'css' => 'border-top-left-radius: 99px; border-top-right-radius: 98px; border-bottom-left-radius: 97px; border-bottom-right-radius: 96px; padding-top: 42px; padding-left: 2%; padding-bottom: 44px; padding-right: 5rem; margin-top: 12rem; margin-left: 2vh; margin-bottom: 2px; margin-right: 10em;',
|
|
131
|
+
'declarations' => array(
|
|
132
|
+
'border-top-left-radius' => '99px',
|
|
133
|
+
'border-top-right-radius' => '98px',
|
|
134
|
+
'border-bottom-left-radius' => '97px',
|
|
135
|
+
'border-bottom-right-radius' => '96px',
|
|
136
|
+
'padding-top' => '42px',
|
|
137
|
+
'padding-left' => '2%',
|
|
138
|
+
'padding-bottom' => '44px',
|
|
139
|
+
'padding-right' => '5rem',
|
|
140
|
+
'margin-top' => '12rem',
|
|
141
|
+
'margin-left' => '2vh',
|
|
142
|
+
'margin-bottom' => '2px',
|
|
143
|
+
'margin-right' => '10em',
|
|
144
|
+
),
|
|
99
145
|
),
|
|
100
146
|
),
|
|
101
147
|
|
|
@@ -112,10 +158,75 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
112
158
|
'letterSpacing' => '2',
|
|
113
159
|
),
|
|
114
160
|
),
|
|
161
|
+
'options' => null,
|
|
162
|
+
'expected_output' => array(
|
|
163
|
+
'css' => 'font-family: Roboto,Oxygen-Sans,Ubuntu,sans-serif; font-style: italic; font-weight: 800; line-height: 1.3; text-decoration: underline; text-transform: uppercase; letter-spacing: 2;',
|
|
164
|
+
'declarations' => array(
|
|
165
|
+
'font-size' => 'clamp(2em, 2vw, 4em)',
|
|
166
|
+
'font-family' => 'Roboto,Oxygen-Sans,Ubuntu,sans-serif',
|
|
167
|
+
'font-style' => 'italic',
|
|
168
|
+
'font-weight' => '800',
|
|
169
|
+
'line-height' => '1.3',
|
|
170
|
+
'text-decoration' => 'underline',
|
|
171
|
+
'text-transform' => 'uppercase',
|
|
172
|
+
'letter-spacing' => '2',
|
|
173
|
+
),
|
|
174
|
+
),
|
|
175
|
+
),
|
|
176
|
+
|
|
177
|
+
'style_block_with_selector' => array(
|
|
178
|
+
'block_styles' => array(
|
|
179
|
+
'spacing' => array(
|
|
180
|
+
'padding' => array(
|
|
181
|
+
'top' => '42px',
|
|
182
|
+
'left' => '2%',
|
|
183
|
+
'bottom' => '44px',
|
|
184
|
+
'right' => '5rem',
|
|
185
|
+
),
|
|
186
|
+
),
|
|
187
|
+
),
|
|
188
|
+
'options' => array( 'selector' => '.wp-selector > p' ),
|
|
189
|
+
'expected_output' => array(
|
|
190
|
+
'css' => '.wp-selector > p { padding-top: 42px; padding-left: 2%; padding-bottom: 44px; padding-right: 5rem; }',
|
|
191
|
+
'declarations' => array(
|
|
192
|
+
'padding-top' => '42px',
|
|
193
|
+
'padding-left' => '2%',
|
|
194
|
+
'padding-bottom' => '44px',
|
|
195
|
+
'padding-right' => '5rem',
|
|
196
|
+
),
|
|
197
|
+
),
|
|
198
|
+
),
|
|
199
|
+
|
|
200
|
+
'elements_with_css_var_value' => array(
|
|
201
|
+
'block_styles' => array(
|
|
202
|
+
'color' => array(
|
|
203
|
+
'text' => 'var:preset|color|my-little-pony',
|
|
204
|
+
),
|
|
205
|
+
),
|
|
206
|
+
'options' => array(
|
|
207
|
+
'selector' => '.wp-selector',
|
|
208
|
+
),
|
|
209
|
+
'expected_output' => array(
|
|
210
|
+
'css' => '.wp-selector { color: var(--wp--preset--color--my-little-pony); }',
|
|
211
|
+
'declarations' => array(
|
|
212
|
+
'color' => 'var(--wp--preset--color--my-little-pony)',
|
|
213
|
+
),
|
|
214
|
+
'classnames' => 'has-text-color has-my-little-pony-color',
|
|
215
|
+
),
|
|
216
|
+
),
|
|
217
|
+
|
|
218
|
+
'elements_with_invalid_preset_style_property' => array(
|
|
219
|
+
'block_styles' => array(
|
|
220
|
+
'color' => array(
|
|
221
|
+
'text' => 'var:preset|invalid_property|my-little-pony',
|
|
222
|
+
),
|
|
223
|
+
),
|
|
224
|
+
'options' => array( 'selector' => '.wp-selector' ),
|
|
115
225
|
'expected_output' => array(
|
|
116
|
-
'
|
|
226
|
+
'classnames' => 'has-text-color',
|
|
117
227
|
),
|
|
118
228
|
),
|
|
229
|
+
|
|
119
230
|
'valid_classnames_deduped' => array(
|
|
120
231
|
'block_styles' => array(
|
|
121
232
|
'color' => array(
|
|
@@ -128,10 +239,28 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
128
239
|
'fontFamily' => 'var:preset|font-family|totally-awesome',
|
|
129
240
|
),
|
|
130
241
|
),
|
|
242
|
+
'options' => array( 'convert_vars_to_classnames' => true ),
|
|
131
243
|
'expected_output' => array(
|
|
132
244
|
'classnames' => 'has-text-color has-copper-socks-color has-background has-splendid-carrot-background-color has-like-wow-dude-gradient-background has-fantastic-font-size has-totally-awesome-font-family',
|
|
133
245
|
),
|
|
134
246
|
),
|
|
247
|
+
|
|
248
|
+
'valid_classnames_and_css_vars' => array(
|
|
249
|
+
'block_styles' => array(
|
|
250
|
+
'color' => array(
|
|
251
|
+
'text' => 'var:preset|color|teal-independents',
|
|
252
|
+
),
|
|
253
|
+
),
|
|
254
|
+
'options' => array(),
|
|
255
|
+
'expected_output' => array(
|
|
256
|
+
'css' => 'color: var(--wp--preset--color--teal-independents);',
|
|
257
|
+
'declarations' => array(
|
|
258
|
+
'color' => 'var(--wp--preset--color--teal-independents)',
|
|
259
|
+
),
|
|
260
|
+
'classnames' => 'has-text-color has-teal-independents-color',
|
|
261
|
+
),
|
|
262
|
+
),
|
|
263
|
+
|
|
135
264
|
'valid_classnames_with_null_style_values' => array(
|
|
136
265
|
'block_styles' => array(
|
|
137
266
|
'color' => array(
|
|
@@ -139,11 +268,16 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
139
268
|
'background' => null,
|
|
140
269
|
),
|
|
141
270
|
),
|
|
271
|
+
'options' => array(),
|
|
142
272
|
'expected_output' => array(
|
|
143
|
-
'css'
|
|
144
|
-
'
|
|
273
|
+
'css' => 'color: #fff;',
|
|
274
|
+
'declarations' => array(
|
|
275
|
+
'color' => '#fff',
|
|
276
|
+
),
|
|
277
|
+
'classnames' => 'has-text-color',
|
|
145
278
|
),
|
|
146
279
|
),
|
|
280
|
+
|
|
147
281
|
'invalid_classnames_preset_value' => array(
|
|
148
282
|
'block_styles' => array(
|
|
149
283
|
'color' => array(
|
|
@@ -155,10 +289,83 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
155
289
|
'padding' => 'var:preset|spacing|padding',
|
|
156
290
|
),
|
|
157
291
|
),
|
|
292
|
+
'options' => array( 'convert_vars_to_classnames' => true ),
|
|
158
293
|
'expected_output' => array(
|
|
159
294
|
'classnames' => 'has-text-color has-background',
|
|
160
295
|
),
|
|
161
296
|
),
|
|
297
|
+
|
|
298
|
+
'valid_spacing_single_preset_values' => array(
|
|
299
|
+
'block_styles' => array(
|
|
300
|
+
'spacing' => array(
|
|
301
|
+
'margin' => 'var:preset|spacing|10',
|
|
302
|
+
'padding' => 'var:preset|spacing|20',
|
|
303
|
+
),
|
|
304
|
+
),
|
|
305
|
+
'options' => array(),
|
|
306
|
+
'expected_output' => array(
|
|
307
|
+
'css' => 'padding: var(--wp--preset--spacing--20); margin: var(--wp--preset--spacing--10);',
|
|
308
|
+
'declarations' => array(
|
|
309
|
+
'padding' => 'var(--wp--preset--spacing--20)',
|
|
310
|
+
'margin' => 'var(--wp--preset--spacing--10)',
|
|
311
|
+
),
|
|
312
|
+
),
|
|
313
|
+
),
|
|
314
|
+
|
|
315
|
+
'valid_spacing_multi_preset_values' => array(
|
|
316
|
+
'block_styles' => array(
|
|
317
|
+
'spacing' => array(
|
|
318
|
+
'margin' => array(
|
|
319
|
+
'left' => 'var:preset|spacing|10',
|
|
320
|
+
'right' => 'var:preset|spacing|20',
|
|
321
|
+
'top' => '1rem',
|
|
322
|
+
'bottom' => '1rem',
|
|
323
|
+
),
|
|
324
|
+
'padding' => array(
|
|
325
|
+
'left' => 'var:preset|spacing|30',
|
|
326
|
+
'right' => 'var:preset|spacing|40',
|
|
327
|
+
'top' => '14px',
|
|
328
|
+
'bottom' => '14px',
|
|
329
|
+
),
|
|
330
|
+
),
|
|
331
|
+
),
|
|
332
|
+
'options' => array(),
|
|
333
|
+
'expected_output' => array(
|
|
334
|
+
'css' => 'padding-left: var(--wp--preset--spacing--30); padding-right: var(--wp--preset--spacing--40); padding-top: 14px; padding-bottom: 14px; margin-left: var(--wp--preset--spacing--10); margin-right: var(--wp--preset--spacing--20); margin-top: 1rem; margin-bottom: 1rem;',
|
|
335
|
+
'declarations' => array(
|
|
336
|
+
'padding-left' => 'var(--wp--preset--spacing--30)',
|
|
337
|
+
'padding-right' => 'var(--wp--preset--spacing--40)',
|
|
338
|
+
'padding-top' => '14px',
|
|
339
|
+
'padding-bottom' => '14px',
|
|
340
|
+
'margin-left' => 'var(--wp--preset--spacing--10)',
|
|
341
|
+
'margin-right' => 'var(--wp--preset--spacing--20)',
|
|
342
|
+
'margin-top' => '1rem',
|
|
343
|
+
'margin-bottom' => '1rem',
|
|
344
|
+
),
|
|
345
|
+
),
|
|
346
|
+
),
|
|
347
|
+
|
|
348
|
+
'invalid_spacing_multi_preset_values' => array(
|
|
349
|
+
'block_styles' => array(
|
|
350
|
+
'spacing' => array(
|
|
351
|
+
'margin' => array(
|
|
352
|
+
'left' => 'var:preset|spaceman|10',
|
|
353
|
+
'right' => 'var:preset|spaceman|20',
|
|
354
|
+
'top' => '1rem',
|
|
355
|
+
'bottom' => '0',
|
|
356
|
+
),
|
|
357
|
+
),
|
|
358
|
+
),
|
|
359
|
+
'options' => array(),
|
|
360
|
+
'expected_output' => array(
|
|
361
|
+
'css' => 'margin-top: 1rem; margin-bottom: 0;',
|
|
362
|
+
'declarations' => array(
|
|
363
|
+
'margin-top' => '1rem',
|
|
364
|
+
'margin-bottom' => '0',
|
|
365
|
+
),
|
|
366
|
+
),
|
|
367
|
+
),
|
|
368
|
+
|
|
162
369
|
'invalid_classnames_options' => array(
|
|
163
370
|
'block_styles' => array(
|
|
164
371
|
'typography' => array(
|
|
@@ -170,8 +377,85 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
170
377
|
),
|
|
171
378
|
),
|
|
172
379
|
),
|
|
380
|
+
'options' => array(),
|
|
173
381
|
'expected_output' => array(),
|
|
174
382
|
),
|
|
383
|
+
|
|
384
|
+
'inline_valid_box_model_style_with_sides' => array(
|
|
385
|
+
'block_styles' => array(
|
|
386
|
+
'border' => array(
|
|
387
|
+
'top' => array(
|
|
388
|
+
'color' => '#fe1',
|
|
389
|
+
'width' => '1.5rem',
|
|
390
|
+
'style' => 'dashed',
|
|
391
|
+
),
|
|
392
|
+
'right' => array(
|
|
393
|
+
'color' => '#fe2',
|
|
394
|
+
'width' => '1.4rem',
|
|
395
|
+
'style' => 'solid',
|
|
396
|
+
),
|
|
397
|
+
'bottom' => array(
|
|
398
|
+
'color' => '#fe3',
|
|
399
|
+
'width' => '1.3rem',
|
|
400
|
+
),
|
|
401
|
+
'left' => array(
|
|
402
|
+
'color' => 'var:preset|color|swampy-yellow',
|
|
403
|
+
'width' => '0.5rem',
|
|
404
|
+
'style' => 'dotted',
|
|
405
|
+
),
|
|
406
|
+
),
|
|
407
|
+
),
|
|
408
|
+
'options' => array(),
|
|
409
|
+
'expected_output' => array(
|
|
410
|
+
'css' => 'border-top-color: #fe1; border-top-width: 1.5rem; border-top-style: dashed; border-right-color: #fe2; border-right-width: 1.4rem; border-right-style: solid; border-bottom-color: #fe3; border-bottom-width: 1.3rem; border-left-color: var(--wp--preset--color--swampy-yellow); border-left-width: 0.5rem; border-left-style: dotted;',
|
|
411
|
+
'declarations' => array(
|
|
412
|
+
'border-top-color' => '#fe1',
|
|
413
|
+
'border-top-width' => '1.5rem',
|
|
414
|
+
'border-top-style' => 'dashed',
|
|
415
|
+
'border-right-color' => '#fe2',
|
|
416
|
+
'border-right-width' => '1.4rem',
|
|
417
|
+
'border-right-style' => 'solid',
|
|
418
|
+
'border-bottom-color' => '#fe3',
|
|
419
|
+
'border-bottom-width' => '1.3rem',
|
|
420
|
+
'border-left-color' => 'var(--wp--preset--color--swampy-yellow)',
|
|
421
|
+
'border-left-width' => '0.5rem',
|
|
422
|
+
'border-left-style' => 'dotted',
|
|
423
|
+
),
|
|
424
|
+
),
|
|
425
|
+
),
|
|
426
|
+
|
|
427
|
+
'inline_invalid_box_model_style_with_sides' => array(
|
|
428
|
+
'block_styles' => array(
|
|
429
|
+
'border' => array(
|
|
430
|
+
'top' => array(
|
|
431
|
+
'top' => '#fe1',
|
|
432
|
+
'right' => '1.5rem',
|
|
433
|
+
'cheese' => 'dashed',
|
|
434
|
+
),
|
|
435
|
+
'right' => array(
|
|
436
|
+
'right' => '#fe2',
|
|
437
|
+
'top' => '1.4rem',
|
|
438
|
+
'bacon' => 'solid',
|
|
439
|
+
),
|
|
440
|
+
'bottom' => array(
|
|
441
|
+
'color' => 'var:preset|color|terrible-lizard',
|
|
442
|
+
'bottom' => '1.3rem',
|
|
443
|
+
),
|
|
444
|
+
'left' => array(
|
|
445
|
+
'left' => null,
|
|
446
|
+
'width' => null,
|
|
447
|
+
'top' => 'dotted',
|
|
448
|
+
),
|
|
449
|
+
),
|
|
450
|
+
),
|
|
451
|
+
'options' => array(),
|
|
452
|
+
'expected_output' => array(
|
|
453
|
+
'css' => 'border-bottom-color: var(--wp--preset--color--terrible-lizard);',
|
|
454
|
+
'declarations' => array(
|
|
455
|
+
'border-bottom-color' => 'var(--wp--preset--color--terrible-lizard)',
|
|
456
|
+
),
|
|
457
|
+
),
|
|
458
|
+
),
|
|
175
459
|
);
|
|
176
460
|
}
|
|
177
461
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type {
|
|
5
|
+
BorderIndividualStyles,
|
|
6
|
+
BorderIndividualProperty,
|
|
7
|
+
GeneratedCSSRule,
|
|
8
|
+
Style,
|
|
9
|
+
StyleDefinition,
|
|
10
|
+
StyleOptions,
|
|
11
|
+
} from '../../types';
|
|
12
|
+
import { generateRule, generateBoxRules, upperFirst } from '../utils';
|
|
13
|
+
|
|
14
|
+
const color = {
|
|
15
|
+
name: 'color',
|
|
16
|
+
generate: (
|
|
17
|
+
style: Style,
|
|
18
|
+
options: StyleOptions,
|
|
19
|
+
path: string[] = [ 'border', 'color' ],
|
|
20
|
+
ruleKey: string = 'borderColor'
|
|
21
|
+
): GeneratedCSSRule[] => {
|
|
22
|
+
return generateRule( style, options, path, ruleKey );
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const radius = {
|
|
27
|
+
name: 'radius',
|
|
28
|
+
generate: ( style: Style, options: StyleOptions ): GeneratedCSSRule[] => {
|
|
29
|
+
return generateBoxRules(
|
|
30
|
+
style,
|
|
31
|
+
options,
|
|
32
|
+
[ 'border', 'radius' ],
|
|
33
|
+
{
|
|
34
|
+
default: 'borderRadius',
|
|
35
|
+
individual: 'border%sRadius',
|
|
36
|
+
},
|
|
37
|
+
[ 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' ]
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const borderStyle = {
|
|
43
|
+
name: 'style',
|
|
44
|
+
generate: (
|
|
45
|
+
style: Style,
|
|
46
|
+
options: StyleOptions,
|
|
47
|
+
path: string[] = [ 'border', 'style' ],
|
|
48
|
+
ruleKey: string = 'borderStyle'
|
|
49
|
+
): GeneratedCSSRule[] => {
|
|
50
|
+
return generateRule( style, options, path, ruleKey );
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const width = {
|
|
55
|
+
name: 'width',
|
|
56
|
+
generate: (
|
|
57
|
+
style: Style,
|
|
58
|
+
options: StyleOptions,
|
|
59
|
+
path: string[] = [ 'border', 'width' ],
|
|
60
|
+
ruleKey: string = 'borderWidth'
|
|
61
|
+
): GeneratedCSSRule[] => {
|
|
62
|
+
return generateRule( style, options, path, ruleKey );
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const borderDefinitionsWithIndividualStyles: StyleDefinition[] = [
|
|
67
|
+
color,
|
|
68
|
+
borderStyle,
|
|
69
|
+
width,
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Returns a curried generator function with the individual border property ('top' | 'right' | 'bottom' | 'left') baked in.
|
|
74
|
+
*
|
|
75
|
+
* @param individualProperty Individual border property ('top' | 'right' | 'bottom' | 'left').
|
|
76
|
+
*
|
|
77
|
+
* @return StyleDefinition[ 'generate' ]
|
|
78
|
+
*/
|
|
79
|
+
const createBorderGenerateFunction =
|
|
80
|
+
( individualProperty: BorderIndividualProperty ) =>
|
|
81
|
+
( style: Style, options: StyleOptions ) => {
|
|
82
|
+
const styleValue:
|
|
83
|
+
| BorderIndividualStyles< typeof individualProperty >
|
|
84
|
+
| undefined = style?.border?.[ individualProperty ];
|
|
85
|
+
|
|
86
|
+
if ( ! styleValue ) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return borderDefinitionsWithIndividualStyles.reduce(
|
|
91
|
+
(
|
|
92
|
+
acc: GeneratedCSSRule[],
|
|
93
|
+
borderDefinition: StyleDefinition
|
|
94
|
+
): GeneratedCSSRule[] => {
|
|
95
|
+
const key = borderDefinition.name;
|
|
96
|
+
if (
|
|
97
|
+
styleValue.hasOwnProperty( key ) &&
|
|
98
|
+
typeof borderDefinition.generate === 'function'
|
|
99
|
+
) {
|
|
100
|
+
const ruleKey = `border${ upperFirst(
|
|
101
|
+
individualProperty
|
|
102
|
+
) }${ upperFirst( key ) }`;
|
|
103
|
+
acc.push(
|
|
104
|
+
...borderDefinition.generate(
|
|
105
|
+
style,
|
|
106
|
+
options,
|
|
107
|
+
[ 'border', individualProperty, key ],
|
|
108
|
+
ruleKey
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
return acc;
|
|
113
|
+
},
|
|
114
|
+
[]
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const borderTop = {
|
|
119
|
+
name: 'borderTop',
|
|
120
|
+
generate: createBorderGenerateFunction( 'top' ),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const borderRight = {
|
|
124
|
+
name: 'borderRight',
|
|
125
|
+
generate: createBorderGenerateFunction( 'right' ),
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const borderBottom = {
|
|
129
|
+
name: 'borderBottom',
|
|
130
|
+
generate: createBorderGenerateFunction( 'bottom' ),
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const borderLeft = {
|
|
134
|
+
name: 'borderLeft',
|
|
135
|
+
generate: createBorderGenerateFunction( 'left' ),
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export default [
|
|
139
|
+
...borderDefinitionsWithIndividualStyles,
|
|
140
|
+
radius,
|
|
141
|
+
borderTop,
|
|
142
|
+
borderRight,
|
|
143
|
+
borderBottom,
|
|
144
|
+
borderLeft,
|
|
145
|
+
];
|
package/src/styles/index.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
+
import border from './border';
|
|
4
5
|
import color from './color';
|
|
5
6
|
import spacing from './spacing';
|
|
6
7
|
import typography from './typography';
|
|
7
8
|
|
|
8
|
-
export const styleDefinitions = [
|
|
9
|
+
export const styleDefinitions = [
|
|
10
|
+
...border,
|
|
11
|
+
...color,
|
|
12
|
+
...spacing,
|
|
13
|
+
...typography,
|
|
14
|
+
];
|