@wordpress/style-engine 0.13.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 +2 -0
- package/README.md +162 -4
- package/class-wp-style-engine-css-declarations.php +27 -3
- package/class-wp-style-engine-css-rule.php +17 -3
- package/class-wp-style-engine-css-rules-store.php +49 -0
- package/class-wp-style-engine-processor.php +68 -26
- package/class-wp-style-engine.php +236 -107
- package/package.json +2 -2
- package/phpunit/class-wp-style-engine-css-declarations-test.php +85 -7
- package/phpunit/class-wp-style-engine-css-rule-test.php +38 -7
- package/phpunit/class-wp-style-engine-css-rules-store-test.php +44 -2
- package/phpunit/class-wp-style-engine-processor-test.php +170 -31
- package/phpunit/class-wp-style-engine-test.php +219 -22
- 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
|
@@ -14,6 +14,13 @@ require __DIR__ . '/../class-wp-style-engine-css-declarations.php';
|
|
|
14
14
|
* Tests for registering, storing and retrieving CSS Rules.
|
|
15
15
|
*/
|
|
16
16
|
class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
|
|
17
|
+
/**
|
|
18
|
+
* Tear down after each test.
|
|
19
|
+
*/
|
|
20
|
+
public function tear_down() {
|
|
21
|
+
parent::tear_down();
|
|
22
|
+
WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
|
|
23
|
+
}
|
|
17
24
|
/**
|
|
18
25
|
* Should create a new store.
|
|
19
26
|
*/
|
|
@@ -36,6 +43,41 @@ class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
|
|
|
36
43
|
$this->assertEquals( $selector, $the_same_fish_store->add_rule( $selector )->get_selector() );
|
|
37
44
|
}
|
|
38
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Should return all previously created stores.
|
|
48
|
+
*/
|
|
49
|
+
public function test_get_stores() {
|
|
50
|
+
$burrito_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'burrito' );
|
|
51
|
+
$quesadilla_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'quesadilla' );
|
|
52
|
+
$this->assertEquals(
|
|
53
|
+
array(
|
|
54
|
+
'burrito' => $burrito_store,
|
|
55
|
+
'quesadilla' => $quesadilla_store,
|
|
56
|
+
),
|
|
57
|
+
WP_Style_Engine_CSS_Rules_Store::get_stores()
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Should delete all previously created stores.
|
|
63
|
+
*/
|
|
64
|
+
public function test_remove_all_stores() {
|
|
65
|
+
$dolmades_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'dolmades' );
|
|
66
|
+
$tzatziki_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'tzatziki' );
|
|
67
|
+
$this->assertEquals(
|
|
68
|
+
array(
|
|
69
|
+
'dolmades' => $dolmades_store,
|
|
70
|
+
'tzatziki' => $tzatziki_store,
|
|
71
|
+
),
|
|
72
|
+
WP_Style_Engine_CSS_Rules_Store::get_stores()
|
|
73
|
+
);
|
|
74
|
+
WP_Style_Engine_CSS_Rules_Store::remove_all_stores();
|
|
75
|
+
$this->assertEquals(
|
|
76
|
+
array(),
|
|
77
|
+
WP_Style_Engine_CSS_Rules_Store::get_stores()
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
39
81
|
/**
|
|
40
82
|
* Should return a stored rule.
|
|
41
83
|
*/
|
|
@@ -43,7 +85,7 @@ class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
|
|
|
43
85
|
$new_pie_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'meat-pie' );
|
|
44
86
|
$selector = '.wp-block-sauce a:hover';
|
|
45
87
|
$store_rule = $new_pie_store->add_rule( $selector );
|
|
46
|
-
$expected =
|
|
88
|
+
$expected = '';
|
|
47
89
|
$this->assertEquals( $expected, $store_rule->get_css() );
|
|
48
90
|
|
|
49
91
|
$pie_declarations = array(
|
|
@@ -55,7 +97,7 @@ class WP_Style_Engine_CSS_Rules_Store_Test extends WP_UnitTestCase {
|
|
|
55
97
|
$store_rule->add_declarations( $css_declarations );
|
|
56
98
|
|
|
57
99
|
$store_rule = $new_pie_store->add_rule( $selector );
|
|
58
|
-
$expected = "$selector
|
|
100
|
+
$expected = "$selector{{$css_declarations->get_declarations_string()}}";
|
|
59
101
|
$this->assertEquals( $expected, $store_rule->get_css() );
|
|
60
102
|
}
|
|
61
103
|
|
|
@@ -14,12 +14,84 @@ require __DIR__ . '/../class-wp-style-engine-processor.php';
|
|
|
14
14
|
* Tests for compiling and rendering styles from a store of CSS rules.
|
|
15
15
|
*/
|
|
16
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
|
+
|
|
17
90
|
/**
|
|
18
91
|
* Should compile CSS rules from the store.
|
|
19
92
|
*/
|
|
20
93
|
public function test_return_store_rules_as_css() {
|
|
21
|
-
$a_nice_store
|
|
22
|
-
$a_nice_renderer = new WP_Style_Engine_Processor_Gutenberg( $a_nice_store );
|
|
94
|
+
$a_nice_store = WP_Style_Engine_CSS_Rules_Store::get_store( 'nice' );
|
|
23
95
|
$a_nice_store->add_rule( '.a-nice-rule' )->add_declarations(
|
|
24
96
|
array(
|
|
25
97
|
'color' => 'var(--nice-color)',
|
|
@@ -33,95 +105,162 @@ class WP_Style_Engine_Processor_Test extends WP_UnitTestCase {
|
|
|
33
105
|
'background-color' => 'purple',
|
|
34
106
|
)
|
|
35
107
|
);
|
|
36
|
-
|
|
37
|
-
$
|
|
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
|
+
);
|
|
38
114
|
}
|
|
39
115
|
|
|
40
116
|
/**
|
|
41
117
|
* Should merge CSS declarations.
|
|
42
118
|
*/
|
|
43
119
|
public function test_dedupe_and_merge_css_declarations() {
|
|
44
|
-
$
|
|
45
|
-
$
|
|
46
|
-
$
|
|
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(
|
|
47
123
|
array(
|
|
48
124
|
'color' => 'var(--excellent-color)',
|
|
49
125
|
'border-style' => 'dotted',
|
|
50
126
|
)
|
|
51
127
|
);
|
|
52
|
-
$
|
|
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(
|
|
53
132
|
array(
|
|
54
133
|
'color' => 'var(--excellent-color)',
|
|
55
134
|
'border-style' => 'dotted',
|
|
56
135
|
'border-color' => 'brown',
|
|
57
136
|
)
|
|
58
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
|
+
);
|
|
59
143
|
|
|
60
|
-
$
|
|
61
|
-
|
|
62
|
-
$an_excellent_store->add_rule( '.an-excellent-rule' )->add_declarations(
|
|
144
|
+
$yet_another_excellent_rule = new WP_Style_Engine_CSS_Rule( '.an-excellent-rule' );
|
|
145
|
+
$yet_another_excellent_rule->add_declarations(
|
|
63
146
|
array(
|
|
64
147
|
'color' => 'var(--excellent-color)',
|
|
65
148
|
'border-style' => 'dashed',
|
|
66
149
|
'border-width' => '2px',
|
|
67
150
|
)
|
|
68
151
|
);
|
|
69
|
-
|
|
70
|
-
$this->assertEquals(
|
|
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
|
+
);
|
|
71
157
|
}
|
|
72
158
|
|
|
73
159
|
/**
|
|
74
|
-
* Should
|
|
160
|
+
* Should print out uncombined selectors duplicate CSS rules.
|
|
75
161
|
*/
|
|
76
|
-
public function
|
|
77
|
-
$
|
|
78
|
-
|
|
79
|
-
|
|
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',
|
|
80
173
|
array(
|
|
81
174
|
'color' => 'var(--sweet-color)',
|
|
82
175
|
'background-color' => 'purple',
|
|
83
176
|
)
|
|
84
177
|
);
|
|
85
|
-
|
|
178
|
+
|
|
179
|
+
$the_sweetest_rule = new WP_Style_Engine_CSS_Rule(
|
|
180
|
+
'.the-sweetest-rule-of-all a',
|
|
86
181
|
array(
|
|
87
182
|
'color' => 'var(--sweet-color)',
|
|
88
183
|
'background-color' => 'purple',
|
|
89
184
|
)
|
|
90
185
|
);
|
|
91
186
|
|
|
92
|
-
$
|
|
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
|
+
);
|
|
93
194
|
}
|
|
94
195
|
|
|
95
196
|
/**
|
|
96
|
-
* Should combine
|
|
197
|
+
* Should combine duplicate CSS rules.
|
|
97
198
|
*/
|
|
98
|
-
public function
|
|
99
|
-
$
|
|
100
|
-
|
|
101
|
-
|
|
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',
|
|
102
231
|
array(
|
|
103
232
|
'border-color' => 'purple',
|
|
104
233
|
)
|
|
105
234
|
);
|
|
106
|
-
$
|
|
235
|
+
$a_lovely_processor->add_rules( $a_lovely_rule );
|
|
236
|
+
$a_lovelier_rule = new WP_Style_Engine_CSS_Rule(
|
|
237
|
+
'.a-lovelier-rule',
|
|
107
238
|
array(
|
|
108
239
|
'border-color' => 'purple',
|
|
109
240
|
)
|
|
110
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() );
|
|
111
244
|
|
|
112
|
-
$
|
|
113
|
-
|
|
114
|
-
$a_lovely_store->add_rule( '.a-most-lovely-rule' )->add_declarations(
|
|
245
|
+
$a_most_lovely_rule = new WP_Style_Engine_CSS_Rule(
|
|
246
|
+
'.a-most-lovely-rule',
|
|
115
247
|
array(
|
|
116
248
|
'border-color' => 'purple',
|
|
117
249
|
)
|
|
118
250
|
);
|
|
119
|
-
$
|
|
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',
|
|
120
255
|
array(
|
|
121
256
|
'border-color' => 'purple',
|
|
122
257
|
)
|
|
123
258
|
);
|
|
259
|
+
$a_lovely_processor->add_rules( $a_perfectly_lovely_rule );
|
|
124
260
|
|
|
125
|
-
$this->assertEquals(
|
|
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
|
+
);
|
|
126
265
|
}
|
|
127
266
|
}
|