@wordpress/style-engine 0.11.0 → 0.14.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 +162 -4
- package/build/styles/utils.js +1 -1
- package/build/styles/utils.js.map +1 -1
- package/build-module/styles/utils.js +1 -1
- package/build-module/styles/utils.js.map +1 -1
- package/class-wp-style-engine-css-declarations.php +167 -0
- package/class-wp-style-engine-css-rule.php +129 -0
- package/class-wp-style-engine-css-rules-store.php +143 -0
- package/class-wp-style-engine-processor.php +135 -0
- package/class-wp-style-engine.php +290 -152
- package/package.json +2 -2
- package/phpunit/class-wp-style-engine-css-declarations-test.php +232 -0
- package/phpunit/class-wp-style-engine-css-rule-test.php +127 -0
- package/phpunit/class-wp-style-engine-css-rules-store-test.php +157 -0
- package/phpunit/class-wp-style-engine-processor-test.php +266 -0
- package/phpunit/class-wp-style-engine-test.php +360 -27
- package/src/styles/utils.ts +3 -1
- package/src/test/index.js +41 -2
- package/build-types/index.d.ts +0 -23
- package/build-types/index.d.ts.map +0 -1
- package/build-types/styles/border/index.d.ts +0 -10
- package/build-types/styles/border/index.d.ts.map +0 -1
- package/build-types/styles/color/background.d.ts +0 -14
- package/build-types/styles/color/background.d.ts.map +0 -1
- package/build-types/styles/color/gradient.d.ts +0 -14
- package/build-types/styles/color/gradient.d.ts.map +0 -1
- package/build-types/styles/color/index.d.ts +0 -10
- package/build-types/styles/color/index.d.ts.map +0 -1
- package/build-types/styles/color/text.d.ts +0 -14
- package/build-types/styles/color/text.d.ts.map +0 -1
- package/build-types/styles/constants.d.ts +0 -4
- package/build-types/styles/constants.d.ts.map +0 -1
- package/build-types/styles/index.d.ts +0 -5
- package/build-types/styles/index.d.ts.map +0 -1
- package/build-types/styles/spacing/index.d.ts +0 -6
- package/build-types/styles/spacing/index.d.ts.map +0 -1
- package/build-types/styles/spacing/margin.d.ts +0 -10
- package/build-types/styles/spacing/margin.d.ts.map +0 -1
- package/build-types/styles/spacing/padding.d.ts +0 -10
- package/build-types/styles/spacing/padding.d.ts.map +0 -1
- package/build-types/styles/typography/index.d.ts +0 -14
- package/build-types/styles/typography/index.d.ts.map +0 -1
- package/build-types/styles/utils.d.ts +0 -48
- package/build-types/styles/utils.d.ts.map +0 -1
- package/build-types/types.d.ts +0 -86
- package/build-types/types.d.ts.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
* @subpackage style-engine
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
require __DIR__ . '/../class-wp-style-engine-processor.php';
|
|
10
|
+
require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
|
|
11
|
+
require __DIR__ . '/../class-wp-style-engine-css-rule.php';
|
|
12
|
+
require __DIR__ . '/../class-wp-style-engine-css-rules-store.php';
|
|
9
13
|
require __DIR__ . '/../class-wp-style-engine.php';
|
|
10
14
|
|
|
11
15
|
/**
|
|
@@ -13,32 +17,44 @@ require __DIR__ . '/../class-wp-style-engine.php';
|
|
|
13
17
|
*/
|
|
14
18
|
class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
15
19
|
/**
|
|
16
|
-
*
|
|
20
|
+
* Tear down after each test.
|
|
21
|
+
*/
|
|
22
|
+
public function tear_down() {
|
|
23
|
+
parent::tear_down();
|
|
24
|
+
WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Tests generating block styles and classnames based on various manifestations of the $block_styles argument.
|
|
17
29
|
*
|
|
18
|
-
* @dataProvider
|
|
30
|
+
* @dataProvider data_get_styles_fixtures
|
|
31
|
+
*
|
|
32
|
+
* @param array $block_styles The incoming block styles object.
|
|
33
|
+
* @param array $options Style engine options.
|
|
34
|
+
* @param string $expected_output The expected output.
|
|
19
35
|
*/
|
|
20
|
-
function
|
|
21
|
-
$generated_styles =
|
|
36
|
+
public function test_generate_get_styles( $block_styles, $options, $expected_output ) {
|
|
37
|
+
$generated_styles = wp_style_engine_get_styles( $block_styles, $options );
|
|
22
38
|
$this->assertSame( $expected_output, $generated_styles );
|
|
23
39
|
}
|
|
24
40
|
|
|
25
41
|
/**
|
|
26
|
-
* Data provider.
|
|
42
|
+
* Data provider for test_generate_get_styles().
|
|
27
43
|
*
|
|
28
44
|
* @return array
|
|
29
45
|
*/
|
|
30
|
-
public function
|
|
46
|
+
public function data_get_styles_fixtures() {
|
|
31
47
|
return array(
|
|
32
48
|
'default_return_value' => array(
|
|
33
49
|
'block_styles' => array(),
|
|
34
50
|
'options' => null,
|
|
35
|
-
'expected_output' =>
|
|
51
|
+
'expected_output' => array(),
|
|
36
52
|
),
|
|
37
53
|
|
|
38
54
|
'inline_invalid_block_styles_empty' => array(
|
|
39
55
|
'block_styles' => 'hello world!',
|
|
40
56
|
'options' => null,
|
|
41
|
-
'expected_output' =>
|
|
57
|
+
'expected_output' => array(),
|
|
42
58
|
),
|
|
43
59
|
|
|
44
60
|
'inline_invalid_block_styles_unknown_style' => array(
|
|
@@ -67,7 +83,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
67
83
|
'expected_output' => array(),
|
|
68
84
|
),
|
|
69
85
|
|
|
70
|
-
'
|
|
86
|
+
'valid_inline_css_and_classnames_as_default_context' => array(
|
|
71
87
|
'block_styles' => array(
|
|
72
88
|
'color' => array(
|
|
73
89
|
'text' => 'var:preset|color|texas-flood',
|
|
@@ -82,13 +98,57 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
82
98
|
'style' => 'dotted',
|
|
83
99
|
),
|
|
84
100
|
),
|
|
85
|
-
'options' => array(),
|
|
101
|
+
'options' => array( 'convert_vars_to_classnames' => true ),
|
|
102
|
+
'expected_output' => array(
|
|
103
|
+
'css' => 'border-style:dotted;border-width:2rem;padding:0;margin:111px;',
|
|
104
|
+
'declarations' => array(
|
|
105
|
+
'border-style' => 'dotted',
|
|
106
|
+
'border-width' => '2rem',
|
|
107
|
+
'padding' => '0',
|
|
108
|
+
'margin' => '111px',
|
|
109
|
+
),
|
|
110
|
+
'classnames' => 'has-text-color has-texas-flood-color has-border-color has-cool-caramel-border-color',
|
|
111
|
+
),
|
|
112
|
+
),
|
|
113
|
+
|
|
114
|
+
'valid_inline_css_and_classnames_with_context' => array(
|
|
115
|
+
'block_styles' => array(
|
|
116
|
+
'color' => array(
|
|
117
|
+
'text' => 'var:preset|color|little-lamb',
|
|
118
|
+
),
|
|
119
|
+
'spacing' => array(
|
|
120
|
+
'margin' => '20px',
|
|
121
|
+
),
|
|
122
|
+
),
|
|
123
|
+
'options' => array(
|
|
124
|
+
'convert_vars_to_classnames' => true,
|
|
125
|
+
'context' => 'block-supports',
|
|
126
|
+
),
|
|
86
127
|
'expected_output' => array(
|
|
87
|
-
'css'
|
|
88
|
-
'
|
|
128
|
+
'css' => 'margin:20px;',
|
|
129
|
+
'declarations' => array(
|
|
130
|
+
'margin' => '20px',
|
|
131
|
+
),
|
|
132
|
+
'classnames' => 'has-text-color has-little-lamb-color',
|
|
89
133
|
),
|
|
90
134
|
),
|
|
91
135
|
|
|
136
|
+
'invalid_context' => array(
|
|
137
|
+
'block_styles' => array(
|
|
138
|
+
'color' => array(
|
|
139
|
+
'text' => 'var:preset|color|sugar',
|
|
140
|
+
),
|
|
141
|
+
'spacing' => array(
|
|
142
|
+
'padding' => '20000px',
|
|
143
|
+
),
|
|
144
|
+
),
|
|
145
|
+
'options' => array(
|
|
146
|
+
'convert_vars_to_classnames' => true,
|
|
147
|
+
'context' => 'i-love-doughnuts',
|
|
148
|
+
),
|
|
149
|
+
'expected_output' => array(),
|
|
150
|
+
),
|
|
151
|
+
|
|
92
152
|
'inline_valid_box_model_style' => array(
|
|
93
153
|
'block_styles' => array(
|
|
94
154
|
'spacing' => array(
|
|
@@ -116,7 +176,21 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
116
176
|
),
|
|
117
177
|
'options' => null,
|
|
118
178
|
'expected_output' => array(
|
|
119
|
-
'css'
|
|
179
|
+
'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;',
|
|
180
|
+
'declarations' => array(
|
|
181
|
+
'border-top-left-radius' => '99px',
|
|
182
|
+
'border-top-right-radius' => '98px',
|
|
183
|
+
'border-bottom-left-radius' => '97px',
|
|
184
|
+
'border-bottom-right-radius' => '96px',
|
|
185
|
+
'padding-top' => '42px',
|
|
186
|
+
'padding-left' => '2%',
|
|
187
|
+
'padding-bottom' => '44px',
|
|
188
|
+
'padding-right' => '5rem',
|
|
189
|
+
'margin-top' => '12rem',
|
|
190
|
+
'margin-left' => '2vh',
|
|
191
|
+
'margin-bottom' => '2px',
|
|
192
|
+
'margin-right' => '10em',
|
|
193
|
+
),
|
|
120
194
|
),
|
|
121
195
|
),
|
|
122
196
|
|
|
@@ -135,7 +209,17 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
135
209
|
),
|
|
136
210
|
'options' => null,
|
|
137
211
|
'expected_output' => array(
|
|
138
|
-
'css'
|
|
212
|
+
'css' => 'font-size:clamp(2em, 2vw, 4em);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;',
|
|
213
|
+
'declarations' => array(
|
|
214
|
+
'font-size' => 'clamp(2em, 2vw, 4em)',
|
|
215
|
+
'font-family' => 'Roboto,Oxygen-Sans,Ubuntu,sans-serif',
|
|
216
|
+
'font-style' => 'italic',
|
|
217
|
+
'font-weight' => '800',
|
|
218
|
+
'line-height' => '1.3',
|
|
219
|
+
'text-decoration' => 'underline',
|
|
220
|
+
'text-transform' => 'uppercase',
|
|
221
|
+
'letter-spacing' => '2',
|
|
222
|
+
),
|
|
139
223
|
),
|
|
140
224
|
),
|
|
141
225
|
|
|
@@ -152,7 +236,13 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
152
236
|
),
|
|
153
237
|
'options' => array( 'selector' => '.wp-selector > p' ),
|
|
154
238
|
'expected_output' => array(
|
|
155
|
-
'css'
|
|
239
|
+
'css' => '.wp-selector > p{padding-top:42px;padding-left:2%;padding-bottom:44px;padding-right:5rem;}',
|
|
240
|
+
'declarations' => array(
|
|
241
|
+
'padding-top' => '42px',
|
|
242
|
+
'padding-left' => '2%',
|
|
243
|
+
'padding-bottom' => '44px',
|
|
244
|
+
'padding-right' => '5rem',
|
|
245
|
+
),
|
|
156
246
|
),
|
|
157
247
|
),
|
|
158
248
|
|
|
@@ -164,11 +254,13 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
164
254
|
),
|
|
165
255
|
'options' => array(
|
|
166
256
|
'selector' => '.wp-selector',
|
|
167
|
-
'css_vars' => true,
|
|
168
257
|
),
|
|
169
258
|
'expected_output' => array(
|
|
170
|
-
'css'
|
|
171
|
-
'
|
|
259
|
+
'css' => '.wp-selector{color:var(--wp--preset--color--my-little-pony);}',
|
|
260
|
+
'declarations' => array(
|
|
261
|
+
'color' => 'var(--wp--preset--color--my-little-pony)',
|
|
262
|
+
),
|
|
263
|
+
'classnames' => 'has-text-color has-my-little-pony-color',
|
|
172
264
|
),
|
|
173
265
|
),
|
|
174
266
|
|
|
@@ -196,7 +288,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
196
288
|
'fontFamily' => 'var:preset|font-family|totally-awesome',
|
|
197
289
|
),
|
|
198
290
|
),
|
|
199
|
-
'options' => array(),
|
|
291
|
+
'options' => array( 'convert_vars_to_classnames' => true ),
|
|
200
292
|
'expected_output' => array(
|
|
201
293
|
'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',
|
|
202
294
|
),
|
|
@@ -208,10 +300,13 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
208
300
|
'text' => 'var:preset|color|teal-independents',
|
|
209
301
|
),
|
|
210
302
|
),
|
|
211
|
-
'options' => array(
|
|
303
|
+
'options' => array(),
|
|
212
304
|
'expected_output' => array(
|
|
213
|
-
'css'
|
|
214
|
-
'
|
|
305
|
+
'css' => 'color:var(--wp--preset--color--teal-independents);',
|
|
306
|
+
'declarations' => array(
|
|
307
|
+
'color' => 'var(--wp--preset--color--teal-independents)',
|
|
308
|
+
),
|
|
309
|
+
'classnames' => 'has-text-color has-teal-independents-color',
|
|
215
310
|
),
|
|
216
311
|
),
|
|
217
312
|
|
|
@@ -224,8 +319,11 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
224
319
|
),
|
|
225
320
|
'options' => array(),
|
|
226
321
|
'expected_output' => array(
|
|
227
|
-
'css'
|
|
228
|
-
'
|
|
322
|
+
'css' => 'color:#fff;',
|
|
323
|
+
'declarations' => array(
|
|
324
|
+
'color' => '#fff',
|
|
325
|
+
),
|
|
326
|
+
'classnames' => 'has-text-color',
|
|
229
327
|
),
|
|
230
328
|
),
|
|
231
329
|
|
|
@@ -240,12 +338,83 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
240
338
|
'padding' => 'var:preset|spacing|padding',
|
|
241
339
|
),
|
|
242
340
|
),
|
|
243
|
-
'options' => array(),
|
|
341
|
+
'options' => array( 'convert_vars_to_classnames' => true ),
|
|
244
342
|
'expected_output' => array(
|
|
245
343
|
'classnames' => 'has-text-color has-background',
|
|
246
344
|
),
|
|
247
345
|
),
|
|
248
346
|
|
|
347
|
+
'valid_spacing_single_preset_values' => array(
|
|
348
|
+
'block_styles' => array(
|
|
349
|
+
'spacing' => array(
|
|
350
|
+
'margin' => 'var:preset|spacing|10',
|
|
351
|
+
'padding' => 'var:preset|spacing|20',
|
|
352
|
+
),
|
|
353
|
+
),
|
|
354
|
+
'options' => array(),
|
|
355
|
+
'expected_output' => array(
|
|
356
|
+
'css' => 'padding:var(--wp--preset--spacing--20);margin:var(--wp--preset--spacing--10);',
|
|
357
|
+
'declarations' => array(
|
|
358
|
+
'padding' => 'var(--wp--preset--spacing--20)',
|
|
359
|
+
'margin' => 'var(--wp--preset--spacing--10)',
|
|
360
|
+
),
|
|
361
|
+
),
|
|
362
|
+
),
|
|
363
|
+
|
|
364
|
+
'valid_spacing_multi_preset_values' => array(
|
|
365
|
+
'block_styles' => array(
|
|
366
|
+
'spacing' => array(
|
|
367
|
+
'margin' => array(
|
|
368
|
+
'left' => 'var:preset|spacing|10',
|
|
369
|
+
'right' => 'var:preset|spacing|20',
|
|
370
|
+
'top' => '1rem',
|
|
371
|
+
'bottom' => '1rem',
|
|
372
|
+
),
|
|
373
|
+
'padding' => array(
|
|
374
|
+
'left' => 'var:preset|spacing|30',
|
|
375
|
+
'right' => 'var:preset|spacing|40',
|
|
376
|
+
'top' => '14px',
|
|
377
|
+
'bottom' => '14px',
|
|
378
|
+
),
|
|
379
|
+
),
|
|
380
|
+
),
|
|
381
|
+
'options' => array(),
|
|
382
|
+
'expected_output' => array(
|
|
383
|
+
'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;',
|
|
384
|
+
'declarations' => array(
|
|
385
|
+
'padding-left' => 'var(--wp--preset--spacing--30)',
|
|
386
|
+
'padding-right' => 'var(--wp--preset--spacing--40)',
|
|
387
|
+
'padding-top' => '14px',
|
|
388
|
+
'padding-bottom' => '14px',
|
|
389
|
+
'margin-left' => 'var(--wp--preset--spacing--10)',
|
|
390
|
+
'margin-right' => 'var(--wp--preset--spacing--20)',
|
|
391
|
+
'margin-top' => '1rem',
|
|
392
|
+
'margin-bottom' => '1rem',
|
|
393
|
+
),
|
|
394
|
+
),
|
|
395
|
+
),
|
|
396
|
+
|
|
397
|
+
'invalid_spacing_multi_preset_values' => array(
|
|
398
|
+
'block_styles' => array(
|
|
399
|
+
'spacing' => array(
|
|
400
|
+
'margin' => array(
|
|
401
|
+
'left' => 'var:preset|spaceman|10',
|
|
402
|
+
'right' => 'var:preset|spaceman|20',
|
|
403
|
+
'top' => '1rem',
|
|
404
|
+
'bottom' => '0',
|
|
405
|
+
),
|
|
406
|
+
),
|
|
407
|
+
),
|
|
408
|
+
'options' => array(),
|
|
409
|
+
'expected_output' => array(
|
|
410
|
+
'css' => 'margin-top:1rem;margin-bottom:0;',
|
|
411
|
+
'declarations' => array(
|
|
412
|
+
'margin-top' => '1rem',
|
|
413
|
+
'margin-bottom' => '0',
|
|
414
|
+
),
|
|
415
|
+
),
|
|
416
|
+
),
|
|
417
|
+
|
|
249
418
|
'invalid_classnames_options' => array(
|
|
250
419
|
'block_styles' => array(
|
|
251
420
|
'typography' => array(
|
|
@@ -287,7 +456,20 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
287
456
|
),
|
|
288
457
|
'options' => array(),
|
|
289
458
|
'expected_output' => array(
|
|
290
|
-
'css'
|
|
459
|
+
'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;',
|
|
460
|
+
'declarations' => array(
|
|
461
|
+
'border-top-color' => '#fe1',
|
|
462
|
+
'border-top-width' => '1.5rem',
|
|
463
|
+
'border-top-style' => 'dashed',
|
|
464
|
+
'border-right-color' => '#fe2',
|
|
465
|
+
'border-right-width' => '1.4rem',
|
|
466
|
+
'border-right-style' => 'solid',
|
|
467
|
+
'border-bottom-color' => '#fe3',
|
|
468
|
+
'border-bottom-width' => '1.3rem',
|
|
469
|
+
'border-left-color' => 'var(--wp--preset--color--swampy-yellow)',
|
|
470
|
+
'border-left-width' => '0.5rem',
|
|
471
|
+
'border-left-style' => 'dotted',
|
|
472
|
+
),
|
|
291
473
|
),
|
|
292
474
|
),
|
|
293
475
|
|
|
@@ -317,9 +499,160 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
|
|
|
317
499
|
),
|
|
318
500
|
'options' => array(),
|
|
319
501
|
'expected_output' => array(
|
|
320
|
-
'css'
|
|
502
|
+
'css' => 'border-bottom-color:var(--wp--preset--color--terrible-lizard);',
|
|
503
|
+
'declarations' => array(
|
|
504
|
+
'border-bottom-color' => 'var(--wp--preset--color--terrible-lizard)',
|
|
505
|
+
),
|
|
506
|
+
),
|
|
507
|
+
),
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Tests adding rules to a store and retrieving a generated stylesheet.
|
|
513
|
+
*/
|
|
514
|
+
public function test_enqueue_block_styles_store() {
|
|
515
|
+
$block_styles = array(
|
|
516
|
+
'spacing' => array(
|
|
517
|
+
'padding' => array(
|
|
518
|
+
'top' => '42px',
|
|
519
|
+
'left' => '2%',
|
|
520
|
+
'bottom' => '44px',
|
|
521
|
+
'right' => '5rem',
|
|
321
522
|
),
|
|
322
523
|
),
|
|
323
524
|
);
|
|
525
|
+
|
|
526
|
+
$generated_styles = wp_style_engine_get_styles(
|
|
527
|
+
$block_styles,
|
|
528
|
+
array(
|
|
529
|
+
'enqueue' => true,
|
|
530
|
+
'context' => 'block-supports',
|
|
531
|
+
'selector' => 'article',
|
|
532
|
+
)
|
|
533
|
+
);
|
|
534
|
+
$store = WP_Style_Engine::get_store( 'block-supports' );
|
|
535
|
+
$rule = $store->get_all_rules()['article'];
|
|
536
|
+
$this->assertSame( $generated_styles['css'], $rule->get_css() );
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Tests adding rules to a store and retrieving a generated stylesheet.
|
|
541
|
+
*/
|
|
542
|
+
public function test_add_to_store() {
|
|
543
|
+
$css_rules = array(
|
|
544
|
+
array(
|
|
545
|
+
'selector' => '.frodo',
|
|
546
|
+
'declarations' => array(
|
|
547
|
+
'color' => 'brown',
|
|
548
|
+
'height' => '10px',
|
|
549
|
+
'width' => '30px',
|
|
550
|
+
'border-style' => 'dotted',
|
|
551
|
+
),
|
|
552
|
+
),
|
|
553
|
+
array(
|
|
554
|
+
'selector' => '.samwise',
|
|
555
|
+
'declarations' => array(
|
|
556
|
+
'color' => 'brown',
|
|
557
|
+
'height' => '20px',
|
|
558
|
+
'width' => '50px',
|
|
559
|
+
'border-style' => 'solid',
|
|
560
|
+
),
|
|
561
|
+
),
|
|
562
|
+
);
|
|
563
|
+
$compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules(
|
|
564
|
+
$css_rules,
|
|
565
|
+
array(
|
|
566
|
+
'context' => 'test-store',
|
|
567
|
+
'enqueue' => true,
|
|
568
|
+
)
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
// Check that the style engine knows about the store.
|
|
572
|
+
$stored_store = WP_Style_Engine::get_store( 'test-store' );
|
|
573
|
+
$this->assertInstanceOf( 'WP_Style_Engine_CSS_Rules_Store', $stored_store );
|
|
574
|
+
$this->assertSame( $compiled_stylesheet, WP_Style_Engine::compile_stylesheet_from_css_rules( $stored_store->get_all_rules() ) );
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Tests retrieving a generated stylesheet from any rules.
|
|
579
|
+
*/
|
|
580
|
+
public function test_get_stylesheet_from_css_rules() {
|
|
581
|
+
$css_rules = array(
|
|
582
|
+
array(
|
|
583
|
+
'selector' => '.saruman',
|
|
584
|
+
'declarations' => array(
|
|
585
|
+
'color' => 'white',
|
|
586
|
+
'height' => '100px',
|
|
587
|
+
'border-style' => 'solid',
|
|
588
|
+
'align-self' => 'unset',
|
|
589
|
+
),
|
|
590
|
+
),
|
|
591
|
+
array(
|
|
592
|
+
'selector' => '.gandalf',
|
|
593
|
+
'declarations' => array(
|
|
594
|
+
'color' => 'grey',
|
|
595
|
+
'height' => '90px',
|
|
596
|
+
'border-style' => 'dotted',
|
|
597
|
+
'align-self' => 'safe center',
|
|
598
|
+
),
|
|
599
|
+
),
|
|
600
|
+
array(
|
|
601
|
+
'selector' => '.radagast',
|
|
602
|
+
'declarations' => array(
|
|
603
|
+
'color' => 'brown',
|
|
604
|
+
'height' => '60px',
|
|
605
|
+
'border-style' => 'dashed',
|
|
606
|
+
'align-self' => 'stretch',
|
|
607
|
+
),
|
|
608
|
+
),
|
|
609
|
+
);
|
|
610
|
+
|
|
611
|
+
$compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules( $css_rules );
|
|
612
|
+
$this->assertSame( '.saruman{color:white;height:100px;border-style:solid;align-self:unset;}.gandalf{color:grey;height:90px;border-style:dotted;align-self:safe center;}.radagast{color:brown;height:60px;border-style:dashed;align-self:stretch;}', $compiled_stylesheet );
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Tests that incoming styles are deduped and merged.
|
|
617
|
+
*/
|
|
618
|
+
public function test_get_deduped_and_merged_stylesheet() {
|
|
619
|
+
$css_rules = array(
|
|
620
|
+
array(
|
|
621
|
+
'selector' => '.gandalf',
|
|
622
|
+
'declarations' => array(
|
|
623
|
+
'color' => 'grey',
|
|
624
|
+
'height' => '90px',
|
|
625
|
+
'border-style' => 'dotted',
|
|
626
|
+
),
|
|
627
|
+
),
|
|
628
|
+
array(
|
|
629
|
+
'selector' => '.gandalf',
|
|
630
|
+
'declarations' => array(
|
|
631
|
+
'color' => 'white',
|
|
632
|
+
'height' => '190px',
|
|
633
|
+
'padding' => '10px',
|
|
634
|
+
'margin-bottom' => '100px',
|
|
635
|
+
),
|
|
636
|
+
),
|
|
637
|
+
array(
|
|
638
|
+
'selector' => '.dumbledore',
|
|
639
|
+
'declarations' => array(
|
|
640
|
+
'color' => 'grey',
|
|
641
|
+
'height' => '90px',
|
|
642
|
+
'border-style' => 'dotted',
|
|
643
|
+
),
|
|
644
|
+
),
|
|
645
|
+
array(
|
|
646
|
+
'selector' => '.rincewind',
|
|
647
|
+
'declarations' => array(
|
|
648
|
+
'color' => 'grey',
|
|
649
|
+
'height' => '90px',
|
|
650
|
+
'border-style' => 'dotted',
|
|
651
|
+
),
|
|
652
|
+
),
|
|
653
|
+
);
|
|
654
|
+
|
|
655
|
+
$compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules( $css_rules );
|
|
656
|
+
$this->assertSame( '.gandalf{color:white;height:190px;border-style:dotted;padding:10px;margin-bottom:100px;}.dumbledore,.rincewind{color:grey;height:90px;border-style:dotted;}', $compiled_stylesheet );
|
|
324
657
|
}
|
|
325
658
|
}
|
package/src/styles/utils.ts
CHANGED
|
@@ -81,7 +81,9 @@ export function generateBoxRules(
|
|
|
81
81
|
} else {
|
|
82
82
|
const sideRules = individualProperties.reduce(
|
|
83
83
|
( acc: GeneratedCSSRule[], side: string ) => {
|
|
84
|
-
const value: string | undefined =
|
|
84
|
+
const value: string | undefined = getCSSVarFromStyleValue(
|
|
85
|
+
get( boxStyle, [ side ] )
|
|
86
|
+
);
|
|
85
87
|
if ( value ) {
|
|
86
88
|
acc.push( {
|
|
87
89
|
selector: options?.selector,
|
package/src/test/index.js
CHANGED
|
@@ -8,6 +8,15 @@ describe( 'generate', () => {
|
|
|
8
8
|
expect( generate( {}, '.some-selector' ) ).toEqual( '' );
|
|
9
9
|
} );
|
|
10
10
|
|
|
11
|
+
it( 'should generate empty style with empty keys', () => {
|
|
12
|
+
expect(
|
|
13
|
+
generate( {
|
|
14
|
+
spacing: undefined,
|
|
15
|
+
color: undefined,
|
|
16
|
+
} )
|
|
17
|
+
).toEqual( '' );
|
|
18
|
+
} );
|
|
19
|
+
|
|
11
20
|
it( 'should generate inline styles where there is no selector', () => {
|
|
12
21
|
expect(
|
|
13
22
|
generate( {
|
|
@@ -72,14 +81,17 @@ describe( 'generate', () => {
|
|
|
72
81
|
);
|
|
73
82
|
} );
|
|
74
83
|
|
|
75
|
-
it( 'should parse preset values
|
|
84
|
+
it( 'should parse preset values', () => {
|
|
76
85
|
expect(
|
|
77
86
|
generate( {
|
|
78
87
|
color: {
|
|
79
88
|
text: 'var:preset|color|ham-sandwich',
|
|
80
89
|
},
|
|
90
|
+
spacing: { margin: '3px' },
|
|
81
91
|
} )
|
|
82
|
-
).toEqual(
|
|
92
|
+
).toEqual(
|
|
93
|
+
'color: var(--wp--preset--color--ham-sandwich); margin: 3px;'
|
|
94
|
+
);
|
|
83
95
|
} );
|
|
84
96
|
|
|
85
97
|
it( 'should parse border rules', () => {
|
|
@@ -278,4 +290,31 @@ describe( 'getCSSRules', () => {
|
|
|
278
290
|
},
|
|
279
291
|
] );
|
|
280
292
|
} );
|
|
293
|
+
|
|
294
|
+
it( 'should handle styles with CSS vars', () => {
|
|
295
|
+
expect(
|
|
296
|
+
getCSSRules(
|
|
297
|
+
{
|
|
298
|
+
color: {
|
|
299
|
+
text: 'var:preset|color|bomba-picante',
|
|
300
|
+
},
|
|
301
|
+
spacing: { padding: '11px' },
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
selector: '.some-selector a',
|
|
305
|
+
}
|
|
306
|
+
)
|
|
307
|
+
).toEqual( [
|
|
308
|
+
{
|
|
309
|
+
selector: '.some-selector a',
|
|
310
|
+
key: 'color',
|
|
311
|
+
value: 'var(--wp--preset--color--bomba-picante)',
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
selector: '.some-selector a',
|
|
315
|
+
key: 'padding',
|
|
316
|
+
value: '11px',
|
|
317
|
+
},
|
|
318
|
+
] );
|
|
319
|
+
} );
|
|
281
320
|
} );
|
package/build-types/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Style, StyleOptions, GeneratedCSSRule } from './types';
|
|
5
|
-
/**
|
|
6
|
-
* Generates a stylesheet for a given style object and selector.
|
|
7
|
-
*
|
|
8
|
-
* @param style Style object.
|
|
9
|
-
* @param options Options object with settings to adjust how the styles are generated.
|
|
10
|
-
*
|
|
11
|
-
* @return generated stylesheet.
|
|
12
|
-
*/
|
|
13
|
-
export declare function generate(style: Style, options: StyleOptions): string;
|
|
14
|
-
/**
|
|
15
|
-
* Returns a JSON representation of the generated CSS rules.
|
|
16
|
-
*
|
|
17
|
-
* @param style Style object.
|
|
18
|
-
* @param options Options object with settings to adjust how the styles are generated.
|
|
19
|
-
*
|
|
20
|
-
* @return generated styles.
|
|
21
|
-
*/
|
|
22
|
-
export declare function getCSSRules(style: Style, options: StyleOptions): GeneratedCSSRule[];
|
|
23
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EACX,KAAK,EACL,YAAY,EACZ,gBAAgB,EAEhB,MAAM,SAAS,CAAC;AAGjB;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,GAAI,MAAM,CA6BtE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,GACnB,gBAAgB,EAAE,CASpB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { GeneratedCSSRule, Style, StyleDefinition, StyleOptions } from '../../types';
|
|
5
|
-
declare const _default: (StyleDefinition | {
|
|
6
|
-
name: string;
|
|
7
|
-
generate: (style: Style, options: StyleOptions) => GeneratedCSSRule[];
|
|
8
|
-
})[];
|
|
9
|
-
export default _default;
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/border/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAGX,gBAAgB,EAChB,KAAK,EACL,eAAe,EACf,YAAY,EACZ,MAAM,aAAa,CAAC;;;;;AA+HrB,wBAOE"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Style, StyleOptions } from '../../types';
|
|
5
|
-
declare const background: {
|
|
6
|
-
name: string;
|
|
7
|
-
generate: (style: Style, options: StyleOptions) => {
|
|
8
|
-
selector: string;
|
|
9
|
-
key: string;
|
|
10
|
-
value: string;
|
|
11
|
-
}[];
|
|
12
|
-
};
|
|
13
|
-
export default background;
|
|
14
|
-
//# sourceMappingURL=background.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../../src/styles/color/background.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,UAAU;;sBAEI,KAAK,WAAW,YAAY;;;;;CAQ/C,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Style, StyleOptions } from '../../types';
|
|
5
|
-
declare const gradient: {
|
|
6
|
-
name: string;
|
|
7
|
-
generate: (style: Style, options: StyleOptions) => {
|
|
8
|
-
selector: string;
|
|
9
|
-
key: string;
|
|
10
|
-
value: string;
|
|
11
|
-
}[];
|
|
12
|
-
};
|
|
13
|
-
export default gradient;
|
|
14
|
-
//# sourceMappingURL=gradient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gradient.d.ts","sourceRoot":"","sources":["../../../src/styles/color/gradient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,QAAQ;;sBAEM,KAAK,WAAW,YAAY;;;;;CAQ/C,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|