@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
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Tests the Style Engine Renderer class.
|
|
4
|
+
*
|
|
5
|
+
* @package Gutenberg
|
|
6
|
+
* @subpackage style-engine
|
|
7
|
+
*/
|
|
8
|
+
require __DIR__ . '/../class-wp-style-engine-css-rules-store.php';
|
|
9
|
+
require __DIR__ . '/../class-wp-style-engine-css-rule.php';
|
|
10
|
+
require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
|
|
11
|
+
require __DIR__ . '/../class-wp-style-engine-processor.php';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Tests for compiling and rendering styles from a store of CSS rules.
|
|
15
|
+
*/
|
|
16
|
+
class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
|
|
17
|
+
/**
|
|
18
|
+
* Should compile CSS rules.
|
|
19
|
+
*/
|
|
20
|
+
public function test_return_rules_as_css() {
|
|
21
|
+
$a_nice_css_rule = new WP_Style_Engine_CSS_Rule( '.a-nice-rule' );
|
|
22
|
+
$a_nice_css_rule->add_declarations(
|
|
23
|
+
array(
|
|
24
|
+
'color' => 'var(--nice-color)',
|
|
25
|
+
'background-color' => 'purple',
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
$a_nicer_css_rule = new WP_Style_Engine_CSS_Rule( '.a-nicer-rule' );
|
|
29
|
+
$a_nicer_css_rule->add_declarations(
|
|
30
|
+
array(
|
|
31
|
+
'font-family' => 'Nice sans',
|
|
32
|
+
'font-size' => '1em',
|
|
33
|
+
'background-color' => 'purple',
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
$a_nice_processor = new WP_Style_Engine_Processor();
|
|
37
|
+
$a_nice_processor->add_rules( array( $a_nice_css_rule, $a_nicer_css_rule ) );
|
|
38
|
+
$this->assertEquals(
|
|
39
|
+
'.a-nice-rule{color:var(--nice-color);background-color:purple;}.a-nicer-rule{font-family:Nice sans;font-size:1em;background-color:purple;}',
|
|
40
|
+
$a_nice_processor->get_css()
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Should compile CSS rules.
|
|
46
|
+
*/
|
|
47
|
+
public function test_return_prettified_rules_as_css() {
|
|
48
|
+
$a_wonderful_css_rule = new WP_Style_Engine_CSS_Rule( '.a-wonderful-rule' );
|
|
49
|
+
$a_wonderful_css_rule->add_declarations(
|
|
50
|
+
array(
|
|
51
|
+
'color' => 'var(--wonderful-color)',
|
|
52
|
+
'background-color' => 'orange',
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
$a_very_wonderful_css_rule = new WP_Style_Engine_CSS_Rule( '.a-very_wonderful-rule' );
|
|
56
|
+
$a_very_wonderful_css_rule->add_declarations(
|
|
57
|
+
array(
|
|
58
|
+
'color' => 'var(--wonderful-color)',
|
|
59
|
+
'background-color' => 'orange',
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
$a_more_wonderful_css_rule = new WP_Style_Engine_CSS_Rule( '.a-more-wonderful-rule' );
|
|
63
|
+
$a_more_wonderful_css_rule->add_declarations(
|
|
64
|
+
array(
|
|
65
|
+
'font-family' => 'Wonderful sans',
|
|
66
|
+
'font-size' => '1em',
|
|
67
|
+
'background-color' => 'orange',
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
$a_wonderful_processor = new WP_Style_Engine_Processor();
|
|
71
|
+
$a_wonderful_processor->add_rules( array( $a_wonderful_css_rule, $a_very_wonderful_css_rule, $a_more_wonderful_css_rule ) );
|
|
72
|
+
|
|
73
|
+
$expected = '.a-more-wonderful-rule {
|
|
74
|
+
font-family: Wonderful sans;
|
|
75
|
+
font-size: 1em;
|
|
76
|
+
background-color: orange;
|
|
77
|
+
}
|
|
78
|
+
.a-wonderful-rule,
|
|
79
|
+
.a-very_wonderful-rule {
|
|
80
|
+
color: var(--wonderful-color);
|
|
81
|
+
background-color: orange;
|
|
82
|
+
}
|
|
83
|
+
';
|
|
84
|
+
$this->assertEquals(
|
|
85
|
+
$expected,
|
|
86
|
+
$a_wonderful_processor->get_css( array( 'prettify' => true ) )
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Should compile CSS rules from the store.
|
|
92
|
+
*/
|
|
93
|
+
public function test_return_store_rules_as_css() {
|
|
94
|
+
$a_nice_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'nice' );
|
|
95
|
+
$a_nice_store->add_rule( '.a-nice-rule' )->add_declarations(
|
|
96
|
+
array(
|
|
97
|
+
'color' => 'var(--nice-color)',
|
|
98
|
+
'background-color' => 'purple',
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
$a_nice_store->add_rule( '.a-nicer-rule' )->add_declarations(
|
|
102
|
+
array(
|
|
103
|
+
'font-family' => 'Nice sans',
|
|
104
|
+
'font-size' => '1em',
|
|
105
|
+
'background-color' => 'purple',
|
|
106
|
+
)
|
|
107
|
+
);
|
|
108
|
+
$a_nice_renderer = new WP_Style_Engine_Processor();
|
|
109
|
+
$a_nice_renderer->add_store( $a_nice_store );
|
|
110
|
+
$this->assertEquals(
|
|
111
|
+
'.a-nice-rule{color:var(--nice-color);background-color:purple;}.a-nicer-rule{font-family:Nice sans;font-size:1em;background-color:purple;}',
|
|
112
|
+
$a_nice_renderer->get_css()
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Should merge CSS declarations.
|
|
118
|
+
*/
|
|
119
|
+
public function test_dedupe_and_merge_css_declarations() {
|
|
120
|
+
$an_excellent_rule = new WP_Style_Engine_CSS_Rule( '.an-excellent-rule' );
|
|
121
|
+
$an_excellent_processor = new WP_Style_Engine_Processor();
|
|
122
|
+
$an_excellent_rule->add_declarations(
|
|
123
|
+
array(
|
|
124
|
+
'color' => 'var(--excellent-color)',
|
|
125
|
+
'border-style' => 'dotted',
|
|
126
|
+
)
|
|
127
|
+
);
|
|
128
|
+
$an_excellent_processor->add_rules( $an_excellent_rule );
|
|
129
|
+
|
|
130
|
+
$another_excellent_rule = new WP_Style_Engine_CSS_Rule( '.an-excellent-rule' );
|
|
131
|
+
$another_excellent_rule->add_declarations(
|
|
132
|
+
array(
|
|
133
|
+
'color' => 'var(--excellent-color)',
|
|
134
|
+
'border-style' => 'dotted',
|
|
135
|
+
'border-color' => 'brown',
|
|
136
|
+
)
|
|
137
|
+
);
|
|
138
|
+
$an_excellent_processor->add_rules( $another_excellent_rule );
|
|
139
|
+
$this->assertEquals(
|
|
140
|
+
'.an-excellent-rule{color:var(--excellent-color);border-style:dotted;border-color:brown;}',
|
|
141
|
+
$an_excellent_processor->get_css()
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
$yet_another_excellent_rule = new WP_Style_Engine_CSS_Rule( '.an-excellent-rule' );
|
|
145
|
+
$yet_another_excellent_rule->add_declarations(
|
|
146
|
+
array(
|
|
147
|
+
'color' => 'var(--excellent-color)',
|
|
148
|
+
'border-style' => 'dashed',
|
|
149
|
+
'border-width' => '2px',
|
|
150
|
+
)
|
|
151
|
+
);
|
|
152
|
+
$an_excellent_processor->add_rules( $yet_another_excellent_rule );
|
|
153
|
+
$this->assertEquals(
|
|
154
|
+
'.an-excellent-rule{color:var(--excellent-color);border-style:dashed;border-color:brown;border-width:2px;}',
|
|
155
|
+
$an_excellent_processor->get_css()
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Should print out uncombined selectors duplicate CSS rules.
|
|
161
|
+
*/
|
|
162
|
+
public function test_output_verbose_css_rules() {
|
|
163
|
+
$a_sweet_rule = new WP_Style_Engine_CSS_Rule(
|
|
164
|
+
'.a-sweet-rule',
|
|
165
|
+
array(
|
|
166
|
+
'color' => 'var(--sweet-color)',
|
|
167
|
+
'background-color' => 'purple',
|
|
168
|
+
)
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
$a_sweeter_rule = new WP_Style_Engine_CSS_Rule(
|
|
172
|
+
'#an-even-sweeter-rule > marquee',
|
|
173
|
+
array(
|
|
174
|
+
'color' => 'var(--sweet-color)',
|
|
175
|
+
'background-color' => 'purple',
|
|
176
|
+
)
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
$the_sweetest_rule = new WP_Style_Engine_CSS_Rule(
|
|
180
|
+
'.the-sweetest-rule-of-all a',
|
|
181
|
+
array(
|
|
182
|
+
'color' => 'var(--sweet-color)',
|
|
183
|
+
'background-color' => 'purple',
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
$a_sweet_processor = new WP_Style_Engine_Processor();
|
|
188
|
+
$a_sweet_processor->add_rules( array( $a_sweet_rule, $a_sweeter_rule, $the_sweetest_rule ) );
|
|
189
|
+
|
|
190
|
+
$this->assertEquals(
|
|
191
|
+
'.a-sweet-rule{color:var(--sweet-color);background-color:purple;}#an-even-sweeter-rule > marquee{color:var(--sweet-color);background-color:purple;}.the-sweetest-rule-of-all a{color:var(--sweet-color);background-color:purple;}',
|
|
192
|
+
$a_sweet_processor->get_css( array( 'optimize' => false ) )
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Should combine duplicate CSS rules.
|
|
198
|
+
*/
|
|
199
|
+
public function test_combine_css_rules() {
|
|
200
|
+
$a_sweet_rule = new WP_Style_Engine_CSS_Rule(
|
|
201
|
+
'.a-sweet-rule',
|
|
202
|
+
array(
|
|
203
|
+
'color' => 'var(--sweet-color)',
|
|
204
|
+
'background-color' => 'purple',
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
$a_sweeter_rule = new WP_Style_Engine_CSS_Rule(
|
|
209
|
+
'#an-even-sweeter-rule > marquee',
|
|
210
|
+
array(
|
|
211
|
+
'color' => 'var(--sweet-color)',
|
|
212
|
+
'background-color' => 'purple',
|
|
213
|
+
)
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
$a_sweet_processor = new WP_Style_Engine_Processor();
|
|
217
|
+
$a_sweet_processor->add_rules( array( $a_sweet_rule, $a_sweeter_rule ) );
|
|
218
|
+
|
|
219
|
+
$this->assertEquals(
|
|
220
|
+
'.a-sweet-rule,#an-even-sweeter-rule > marquee{color:var(--sweet-color);background-color:purple;}',
|
|
221
|
+
$a_sweet_processor->get_css()
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Should combine and store CSS rules.
|
|
226
|
+
*/
|
|
227
|
+
public function test_combine_previously_added_css_rules() {
|
|
228
|
+
$a_lovely_processor = new WP_Style_Engine_Processor();
|
|
229
|
+
$a_lovely_rule = new WP_Style_Engine_CSS_Rule(
|
|
230
|
+
'.a-lovely-rule',
|
|
231
|
+
array(
|
|
232
|
+
'border-color' => 'purple',
|
|
233
|
+
)
|
|
234
|
+
);
|
|
235
|
+
$a_lovely_processor->add_rules( $a_lovely_rule );
|
|
236
|
+
$a_lovelier_rule = new WP_Style_Engine_CSS_Rule(
|
|
237
|
+
'.a-lovelier-rule',
|
|
238
|
+
array(
|
|
239
|
+
'border-color' => 'purple',
|
|
240
|
+
)
|
|
241
|
+
);
|
|
242
|
+
$a_lovely_processor->add_rules( $a_lovelier_rule );
|
|
243
|
+
$this->assertEquals( '.a-lovely-rule,.a-lovelier-rule{border-color:purple;}', $a_lovely_processor->get_css() );
|
|
244
|
+
|
|
245
|
+
$a_most_lovely_rule = new WP_Style_Engine_CSS_Rule(
|
|
246
|
+
'.a-most-lovely-rule',
|
|
247
|
+
array(
|
|
248
|
+
'border-color' => 'purple',
|
|
249
|
+
)
|
|
250
|
+
);
|
|
251
|
+
$a_lovely_processor->add_rules( $a_most_lovely_rule );
|
|
252
|
+
|
|
253
|
+
$a_perfectly_lovely_rule = new WP_Style_Engine_CSS_Rule(
|
|
254
|
+
'.a-perfectly-lovely-rule',
|
|
255
|
+
array(
|
|
256
|
+
'border-color' => 'purple',
|
|
257
|
+
)
|
|
258
|
+
);
|
|
259
|
+
$a_lovely_processor->add_rules( $a_perfectly_lovely_rule );
|
|
260
|
+
|
|
261
|
+
$this->assertEquals(
|
|
262
|
+
'.a-lovely-rule,.a-lovelier-rule,.a-most-lovely-rule,.a-perfectly-lovely-rule{border-color:purple;}',
|
|
263
|
+
$a_lovely_processor->get_css()
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
}
|