@wordpress/style-engine 0.13.0 → 0.15.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +206 -42
  3. package/build/index.js +7 -5
  4. package/build/index.js.map +1 -1
  5. package/build/styles/typography/index.js +7 -1
  6. package/build/styles/typography/index.js.map +1 -1
  7. package/build/styles/utils.js +5 -5
  8. package/build/styles/utils.js.map +1 -1
  9. package/build-module/index.js +6 -4
  10. package/build-module/index.js.map +1 -1
  11. package/build-module/styles/typography/index.js +7 -1
  12. package/build-module/styles/typography/index.js.map +1 -1
  13. package/build-module/styles/utils.js +5 -5
  14. package/build-module/styles/utils.js.map +1 -1
  15. package/build-types/index.d.ts +4 -4
  16. package/build-types/index.d.ts.map +1 -1
  17. package/build-types/styles/color/background.d.ts +1 -1
  18. package/build-types/styles/color/gradient.d.ts +1 -1
  19. package/build-types/styles/color/index.d.ts +1 -1
  20. package/build-types/styles/color/text.d.ts +1 -1
  21. package/build-types/styles/typography/index.d.ts +1 -1
  22. package/build-types/styles/typography/index.d.ts.map +1 -1
  23. package/build-types/styles/utils.d.ts +6 -6
  24. package/build-types/types.d.ts +3 -4
  25. package/build-types/types.d.ts.map +1 -1
  26. package/class-wp-style-engine-css-declarations.php +42 -15
  27. package/class-wp-style-engine-css-rule.php +20 -10
  28. package/class-wp-style-engine-css-rules-store.php +53 -3
  29. package/class-wp-style-engine-processor.php +76 -26
  30. package/class-wp-style-engine.php +260 -140
  31. package/package.json +2 -2
  32. package/phpunit/class-wp-style-engine-css-declarations-test.php +87 -7
  33. package/phpunit/class-wp-style-engine-css-rule-test.php +38 -7
  34. package/phpunit/class-wp-style-engine-css-rules-store-test.php +58 -2
  35. package/phpunit/class-wp-style-engine-processor-test.php +170 -31
  36. package/phpunit/class-wp-style-engine-test.php +223 -22
  37. package/src/index.ts +4 -4
  38. package/src/styles/typography/index.ts +13 -0
  39. package/src/styles/utils.ts +5 -5
  40. package/src/test/index.js +24 -10
  41. package/src/types.ts +3 -4
  42. package/tsconfig.tsbuildinfo +1 -1
@@ -6,44 +6,55 @@
6
6
  * @subpackage style-engine
7
7
  */
8
8
 
9
+ require __DIR__ . '/../class-wp-style-engine-processor.php';
9
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';
10
13
  require __DIR__ . '/../class-wp-style-engine.php';
11
14
 
12
15
  /**
13
16
  * Tests for registering, storing and generating styles.
14
17
  */
15
18
  class WP_Style_Engine_Test extends WP_UnitTestCase {
19
+ /**
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
+
16
27
  /**
17
28
  * Tests generating block styles and classnames based on various manifestations of the $block_styles argument.
18
29
  *
19
- * @dataProvider data_generate_block_supports_styles_fixtures
30
+ * @dataProvider data_get_styles_fixtures
20
31
  *
21
- * @param array $block_styles The incoming block styles object.
22
- * @param array $options Style engine options.
32
+ * @param array $block_styles The incoming block styles object.
33
+ * @param array $options Style engine options.
23
34
  * @param string $expected_output The expected output.
24
35
  */
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 );
36
+ public function test_generate_get_styles( $block_styles, $options, $expected_output ) {
37
+ $generated_styles = wp_style_engine_get_styles( $block_styles, $options );
27
38
  $this->assertSame( $expected_output, $generated_styles );
28
39
  }
29
40
 
30
41
  /**
31
- * Data provider.
42
+ * Data provider for test_generate_get_styles().
32
43
  *
33
44
  * @return array
34
45
  */
35
- public function data_generate_block_supports_styles_fixtures() {
46
+ public function data_get_styles_fixtures() {
36
47
  return array(
37
48
  'default_return_value' => array(
38
49
  'block_styles' => array(),
39
50
  'options' => null,
40
- 'expected_output' => null,
51
+ 'expected_output' => array(),
41
52
  ),
42
53
 
43
54
  'inline_invalid_block_styles_empty' => array(
44
55
  'block_styles' => 'hello world!',
45
56
  'options' => null,
46
- 'expected_output' => null,
57
+ 'expected_output' => array(),
47
58
  ),
48
59
 
49
60
  'inline_invalid_block_styles_unknown_style' => array(
@@ -72,7 +83,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
72
83
  'expected_output' => array(),
73
84
  ),
74
85
 
75
- 'valid_inline_css_and_classnames' => array(
86
+ 'valid_inline_css_and_classnames_as_default_context' => array(
76
87
  'block_styles' => array(
77
88
  'color' => array(
78
89
  'text' => 'var:preset|color|texas-flood',
@@ -89,7 +100,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
89
100
  ),
90
101
  'options' => array( 'convert_vars_to_classnames' => true ),
91
102
  'expected_output' => array(
92
- 'css' => 'border-style: dotted; border-width: 2rem; padding: 0; margin: 111px;',
103
+ 'css' => 'border-style:dotted;border-width:2rem;padding:0;margin:111px;',
93
104
  'declarations' => array(
94
105
  'border-style' => 'dotted',
95
106
  'border-width' => '2rem',
@@ -100,6 +111,28 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
100
111
  ),
101
112
  ),
102
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
+ ),
127
+ 'expected_output' => array(
128
+ 'css' => 'margin:20px;',
129
+ 'declarations' => array(
130
+ 'margin' => '20px',
131
+ ),
132
+ 'classnames' => 'has-text-color has-little-lamb-color',
133
+ ),
134
+ ),
135
+
103
136
  'inline_valid_box_model_style' => array(
104
137
  'block_styles' => array(
105
138
  'spacing' => array(
@@ -127,7 +160,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
127
160
  ),
128
161
  'options' => null,
129
162
  'expected_output' => array(
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;',
163
+ '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
164
  'declarations' => array(
132
165
  'border-top-left-radius' => '99px',
133
166
  'border-top-right-radius' => '98px',
@@ -160,7 +193,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
160
193
  ),
161
194
  'options' => null,
162
195
  '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;',
196
+ '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;',
164
197
  'declarations' => array(
165
198
  'font-size' => 'clamp(2em, 2vw, 4em)',
166
199
  'font-family' => 'Roboto,Oxygen-Sans,Ubuntu,sans-serif',
@@ -187,7 +220,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
187
220
  ),
188
221
  'options' => array( 'selector' => '.wp-selector > p' ),
189
222
  'expected_output' => array(
190
- 'css' => '.wp-selector > p { padding-top: 42px; padding-left: 2%; padding-bottom: 44px; padding-right: 5rem; }',
223
+ 'css' => '.wp-selector > p{padding-top:42px;padding-left:2%;padding-bottom:44px;padding-right:5rem;}',
191
224
  'declarations' => array(
192
225
  'padding-top' => '42px',
193
226
  'padding-left' => '2%',
@@ -207,7 +240,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
207
240
  'selector' => '.wp-selector',
208
241
  ),
209
242
  'expected_output' => array(
210
- 'css' => '.wp-selector { color: var(--wp--preset--color--my-little-pony); }',
243
+ 'css' => '.wp-selector{color:var(--wp--preset--color--my-little-pony);}',
211
244
  'declarations' => array(
212
245
  'color' => 'var(--wp--preset--color--my-little-pony)',
213
246
  ),
@@ -253,7 +286,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
253
286
  ),
254
287
  'options' => array(),
255
288
  'expected_output' => array(
256
- 'css' => 'color: var(--wp--preset--color--teal-independents);',
289
+ 'css' => 'color:var(--wp--preset--color--teal-independents);',
257
290
  'declarations' => array(
258
291
  'color' => 'var(--wp--preset--color--teal-independents)',
259
292
  ),
@@ -270,7 +303,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
270
303
  ),
271
304
  'options' => array(),
272
305
  'expected_output' => array(
273
- 'css' => 'color: #fff;',
306
+ 'css' => 'color:#fff;',
274
307
  'declarations' => array(
275
308
  'color' => '#fff',
276
309
  ),
@@ -304,7 +337,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
304
337
  ),
305
338
  'options' => array(),
306
339
  'expected_output' => array(
307
- 'css' => 'padding: var(--wp--preset--spacing--20); margin: var(--wp--preset--spacing--10);',
340
+ 'css' => 'padding:var(--wp--preset--spacing--20);margin:var(--wp--preset--spacing--10);',
308
341
  'declarations' => array(
309
342
  'padding' => 'var(--wp--preset--spacing--20)',
310
343
  'margin' => 'var(--wp--preset--spacing--10)',
@@ -331,7 +364,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
331
364
  ),
332
365
  'options' => array(),
333
366
  '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;',
367
+ '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
368
  'declarations' => array(
336
369
  'padding-left' => 'var(--wp--preset--spacing--30)',
337
370
  'padding-right' => 'var(--wp--preset--spacing--40)',
@@ -358,7 +391,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
358
391
  ),
359
392
  'options' => array(),
360
393
  'expected_output' => array(
361
- 'css' => 'margin-top: 1rem; margin-bottom: 0;',
394
+ 'css' => 'margin-top:1rem;margin-bottom:0;',
362
395
  'declarations' => array(
363
396
  'margin-top' => '1rem',
364
397
  'margin-bottom' => '0',
@@ -407,7 +440,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
407
440
  ),
408
441
  'options' => array(),
409
442
  '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;',
443
+ '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
444
  'declarations' => array(
412
445
  'border-top-color' => '#fe1',
413
446
  'border-top-width' => '1.5rem',
@@ -450,7 +483,7 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
450
483
  ),
451
484
  'options' => array(),
452
485
  'expected_output' => array(
453
- 'css' => 'border-bottom-color: var(--wp--preset--color--terrible-lizard);',
486
+ 'css' => 'border-bottom-color:var(--wp--preset--color--terrible-lizard);',
454
487
  'declarations' => array(
455
488
  'border-bottom-color' => 'var(--wp--preset--color--terrible-lizard)',
456
489
  ),
@@ -458,4 +491,172 @@ class WP_Style_Engine_Test extends WP_UnitTestCase {
458
491
  ),
459
492
  );
460
493
  }
494
+
495
+ /**
496
+ * Tests adding rules to a store and retrieving a generated stylesheet.
497
+ */
498
+ public function test_store_block_styles_using_context() {
499
+ $block_styles = array(
500
+ 'spacing' => array(
501
+ 'padding' => array(
502
+ 'top' => '42px',
503
+ 'left' => '2%',
504
+ 'bottom' => '44px',
505
+ 'right' => '5rem',
506
+ ),
507
+ ),
508
+ );
509
+
510
+ $generated_styles = wp_style_engine_get_styles(
511
+ $block_styles,
512
+ array(
513
+ 'context' => 'block-supports',
514
+ 'selector' => 'article',
515
+ )
516
+ );
517
+ $store = WP_Style_Engine::get_store( 'block-supports' );
518
+ $rule = $store->get_all_rules()['article'];
519
+ $this->assertSame( $generated_styles['css'], $rule->get_css() );
520
+ }
521
+
522
+ /**
523
+ * Tests adding rules to a store and retrieving a generated stylesheet.
524
+ */
525
+ public function test_does_not_store_block_styles_without_context() {
526
+ $block_styles = array(
527
+ 'typography' => array(
528
+ 'fontSize' => '999px',
529
+ ),
530
+ );
531
+
532
+ wp_style_engine_get_styles(
533
+ $block_styles,
534
+ array(
535
+ 'selector' => '#font-size-rulez',
536
+ )
537
+ );
538
+
539
+ $all_stores = WP_Style_Engine_CSS_Rules_Store_Gutenberg::get_stores();
540
+
541
+ $this->assertEmpty( $all_stores );
542
+ }
543
+
544
+ /**
545
+ * Tests adding rules to a store and retrieving a generated stylesheet.
546
+ */
547
+ public function test_add_to_store() {
548
+ $css_rules = array(
549
+ array(
550
+ 'selector' => '.frodo',
551
+ 'declarations' => array(
552
+ 'color' => 'brown',
553
+ 'height' => '10px',
554
+ 'width' => '30px',
555
+ 'border-style' => 'dotted',
556
+ ),
557
+ ),
558
+ array(
559
+ 'selector' => '.samwise',
560
+ 'declarations' => array(
561
+ 'color' => 'brown',
562
+ 'height' => '20px',
563
+ 'width' => '50px',
564
+ 'border-style' => 'solid',
565
+ ),
566
+ ),
567
+ );
568
+ $compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules(
569
+ $css_rules,
570
+ array(
571
+ 'context' => 'test-store',
572
+ )
573
+ );
574
+
575
+ // Check that the style engine knows about the store.
576
+ $stored_store = WP_Style_Engine::get_store( 'test-store' );
577
+ $this->assertInstanceOf( 'WP_Style_Engine_CSS_Rules_Store', $stored_store );
578
+ $this->assertSame( $compiled_stylesheet, WP_Style_Engine::compile_stylesheet_from_css_rules( $stored_store->get_all_rules() ) );
579
+ }
580
+
581
+ /**
582
+ * Tests retrieving a generated stylesheet from any rules.
583
+ */
584
+ public function test_get_stylesheet_from_css_rules() {
585
+ $css_rules = array(
586
+ array(
587
+ 'selector' => '.saruman',
588
+ 'declarations' => array(
589
+ 'color' => 'white',
590
+ 'height' => '100px',
591
+ 'border-style' => 'solid',
592
+ 'align-self' => 'unset',
593
+ ),
594
+ ),
595
+ array(
596
+ 'selector' => '.gandalf',
597
+ 'declarations' => array(
598
+ 'color' => 'grey',
599
+ 'height' => '90px',
600
+ 'border-style' => 'dotted',
601
+ 'align-self' => 'safe center',
602
+ ),
603
+ ),
604
+ array(
605
+ 'selector' => '.radagast',
606
+ 'declarations' => array(
607
+ 'color' => 'brown',
608
+ 'height' => '60px',
609
+ 'border-style' => 'dashed',
610
+ 'align-self' => 'stretch',
611
+ ),
612
+ ),
613
+ );
614
+
615
+ $compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules( $css_rules );
616
+ $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 );
617
+ }
618
+
619
+ /**
620
+ * Tests that incoming styles are deduped and merged.
621
+ */
622
+ public function test_get_deduped_and_merged_stylesheet() {
623
+ $css_rules = array(
624
+ array(
625
+ 'selector' => '.gandalf',
626
+ 'declarations' => array(
627
+ 'color' => 'grey',
628
+ 'height' => '90px',
629
+ 'border-style' => 'dotted',
630
+ ),
631
+ ),
632
+ array(
633
+ 'selector' => '.gandalf',
634
+ 'declarations' => array(
635
+ 'color' => 'white',
636
+ 'height' => '190px',
637
+ 'padding' => '10px',
638
+ 'margin-bottom' => '100px',
639
+ ),
640
+ ),
641
+ array(
642
+ 'selector' => '.dumbledore',
643
+ 'declarations' => array(
644
+ 'color' => 'grey',
645
+ 'height' => '90px',
646
+ 'border-style' => 'dotted',
647
+ ),
648
+ ),
649
+ array(
650
+ 'selector' => '.rincewind',
651
+ 'declarations' => array(
652
+ 'color' => 'grey',
653
+ 'height' => '90px',
654
+ 'border-style' => 'dotted',
655
+ ),
656
+ ),
657
+ );
658
+
659
+ $compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules( $css_rules );
660
+ $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 );
661
+ }
461
662
  }
package/src/index.ts CHANGED
@@ -17,12 +17,12 @@ import { styleDefinitions } from './styles';
17
17
  /**
18
18
  * Generates a stylesheet for a given style object and selector.
19
19
  *
20
- * @param style Style object.
20
+ * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
21
21
  * @param options Options object with settings to adjust how the styles are generated.
22
22
  *
23
23
  * @return generated stylesheet.
24
24
  */
25
- export function generate( style: Style, options: StyleOptions ): string {
25
+ export function compileCSS( style: Style, options: StyleOptions = {} ): string {
26
26
  const rules = getCSSRules( style, options );
27
27
 
28
28
  // If no selector is provided, treat generated rules as inline styles to be returned as a single string.
@@ -56,14 +56,14 @@ export function generate( style: Style, options: StyleOptions ): string {
56
56
  /**
57
57
  * Returns a JSON representation of the generated CSS rules.
58
58
  *
59
- * @param style Style object.
59
+ * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
60
60
  * @param options Options object with settings to adjust how the styles are generated.
61
61
  *
62
62
  * @return generated styles.
63
63
  */
64
64
  export function getCSSRules(
65
65
  style: Style,
66
- options: StyleOptions
66
+ options: StyleOptions = {}
67
67
  ): GeneratedCSSRule[] {
68
68
  const rules: GeneratedCSSRule[] = [];
69
69
  styleDefinitions.forEach( ( definition: StyleDefinition ) => {
@@ -40,6 +40,18 @@ const fontWeight = {
40
40
  },
41
41
  };
42
42
 
43
+ const fontFamily = {
44
+ name: 'fontFamily',
45
+ generate: ( style: Style, options: StyleOptions ) => {
46
+ return generateRule(
47
+ style,
48
+ options,
49
+ [ 'typography', 'fontFamily' ],
50
+ 'fontFamily'
51
+ );
52
+ },
53
+ };
54
+
43
55
  const letterSpacing = {
44
56
  name: 'letterSpacing',
45
57
  generate: ( style: Style, options: StyleOptions ) => {
@@ -89,6 +101,7 @@ const textTransform = {
89
101
  };
90
102
 
91
103
  export default [
104
+ fontFamily,
92
105
  fontSize,
93
106
  fontStyle,
94
107
  fontWeight,
@@ -51,11 +51,11 @@ export function generateRule(
51
51
  /**
52
52
  * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.
53
53
  *
54
- * @param style Style object.
55
- * @param options Options object with settings to adjust how the styles are generated.
56
- * @param path An array of strings representing the path to the style value in the style object.
57
- * @param ruleKeys An array of CSS property keys and patterns.
58
- * @param individualProperties The "sides" or individual properties for which to generate rules.
54
+ * @param style Style object.
55
+ * @param options Options object with settings to adjust how the styles are generated.
56
+ * @param path An array of strings representing the path to the style value in the style object.
57
+ * @param ruleKeys An array of CSS property keys and patterns.
58
+ * @param individualProperties The "sides" or individual properties for which to generate rules.
59
59
  *
60
60
  * @return GeneratedCSSRule[] CSS rules.
61
61
  */
package/src/test/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { getCSSRules, generate } from '../index';
4
+ import { getCSSRules, compileCSS } from '../index';
5
5
 
6
6
  describe( 'generate', () => {
7
7
  it( 'should generate empty style', () => {
8
- expect( generate( {}, '.some-selector' ) ).toEqual( '' );
8
+ expect( compileCSS( {}, '.some-selector' ) ).toEqual( '' );
9
9
  } );
10
10
 
11
11
  it( 'should generate empty style with empty keys', () => {
12
12
  expect(
13
- generate( {
13
+ compileCSS( {
14
14
  spacing: undefined,
15
15
  color: undefined,
16
16
  } )
@@ -19,7 +19,7 @@ describe( 'generate', () => {
19
19
 
20
20
  it( 'should generate inline styles where there is no selector', () => {
21
21
  expect(
22
- generate( {
22
+ compileCSS( {
23
23
  spacing: { padding: '10px', margin: '12px' },
24
24
  color: {
25
25
  text: '#f1f1f1',
@@ -35,7 +35,7 @@ describe( 'generate', () => {
35
35
 
36
36
  it( 'should generate styles with an optional selector', () => {
37
37
  expect(
38
- generate(
38
+ compileCSS(
39
39
  {
40
40
  spacing: { padding: '10px', margin: '12px' },
41
41
  },
@@ -46,11 +46,13 @@ describe( 'generate', () => {
46
46
  ).toEqual( '.some-selector { margin: 12px; padding: 10px; }' );
47
47
 
48
48
  expect(
49
- generate(
49
+ compileCSS(
50
50
  {
51
51
  color: {
52
52
  text: '#cccccc',
53
53
  background: '#111111',
54
+ gradient:
55
+ 'linear-gradient(135deg,rgb(255,203,112) 0%,rgb(33,32,33) 42%,rgb(65,88,208) 100%)',
54
56
  },
55
57
  spacing: {
56
58
  padding: { top: '10px', bottom: '5px' },
@@ -77,13 +79,13 @@ describe( 'generate', () => {
77
79
  }
78
80
  )
79
81
  ).toEqual(
80
- '.some-selector { color: #cccccc; background-color: #111111; margin-top: 11px; margin-right: 12px; margin-bottom: 13px; margin-left: 14px; padding-top: 10px; padding-bottom: 5px; font-size: 2.2rem; font-style: italic; font-weight: 800; letter-spacing: 12px; line-height: 3.3; text-decoration: line-through; text-transform: uppercase; }'
82
+ ".some-selector { color: #cccccc; background: linear-gradient(135deg,rgb(255,203,112) 0%,rgb(33,32,33) 42%,rgb(65,88,208) 100%); background-color: #111111; margin-top: 11px; margin-right: 12px; margin-bottom: 13px; margin-left: 14px; padding-top: 10px; padding-bottom: 5px; font-family: 'Helvetica Neue',sans-serif; font-size: 2.2rem; font-style: italic; font-weight: 800; letter-spacing: 12px; line-height: 3.3; text-decoration: line-through; text-transform: uppercase; }"
81
83
  );
82
84
  } );
83
85
 
84
86
  it( 'should parse preset values', () => {
85
87
  expect(
86
- generate( {
88
+ compileCSS( {
87
89
  color: {
88
90
  text: 'var:preset|color|ham-sandwich',
89
91
  },
@@ -96,7 +98,7 @@ describe( 'generate', () => {
96
98
 
97
99
  it( 'should parse border rules', () => {
98
100
  expect(
99
- generate( {
101
+ compileCSS( {
100
102
  border: {
101
103
  color: 'var:preset|color|perky-peppermint',
102
104
  width: '0.5em',
@@ -111,7 +113,7 @@ describe( 'generate', () => {
111
113
 
112
114
  it( 'should parse individual border rules', () => {
113
115
  expect(
114
- generate( {
116
+ compileCSS( {
115
117
  border: {
116
118
  top: {
117
119
  color: 'var:preset|color|sandy-beach',
@@ -202,6 +204,8 @@ describe( 'getCSSRules', () => {
202
204
  color: {
203
205
  text: '#dddddd',
204
206
  background: '#555555',
207
+ gradient:
208
+ 'linear-gradient(135deg,rgb(255,203,112) 0%,rgb(33,32,33) 42%,rgb(65,88,208) 100%)',
205
209
  },
206
210
  spacing: {
207
211
  padding: { top: '10px', bottom: '5px' },
@@ -228,6 +232,11 @@ describe( 'getCSSRules', () => {
228
232
  key: 'color',
229
233
  value: '#dddddd',
230
234
  },
235
+ {
236
+ selector: '.some-selector',
237
+ key: 'background',
238
+ value: 'linear-gradient(135deg,rgb(255,203,112) 0%,rgb(33,32,33) 42%,rgb(65,88,208) 100%)',
239
+ },
231
240
  {
232
241
  selector: '.some-selector',
233
242
  key: 'backgroundColor',
@@ -253,6 +262,11 @@ describe( 'getCSSRules', () => {
253
262
  key: 'paddingBottom',
254
263
  value: '5px',
255
264
  },
265
+ {
266
+ key: 'fontFamily',
267
+ selector: '.some-selector',
268
+ value: "'Helvetica Neue',sans-serif",
269
+ },
256
270
  {
257
271
  key: 'fontSize',
258
272
  selector: '.some-selector',
package/src/types.ts CHANGED
@@ -71,11 +71,11 @@ export type StyleOptions = {
71
71
  /**
72
72
  * CSS selector for the generated style.
73
73
  */
74
- selector: string;
74
+ selector?: string;
75
75
  };
76
76
 
77
77
  export type GeneratedCSSRule = {
78
- selector: string;
78
+ selector?: string;
79
79
  value: string;
80
80
  /**
81
81
  * The CSS key in JS style attribute format, compatible with React.
@@ -88,9 +88,8 @@ export interface StyleDefinition {
88
88
  name: string;
89
89
  generate?: (
90
90
  style: Style,
91
- options: StyleOptions,
91
+ options: StyleOptions | {},
92
92
  path?: string[],
93
93
  ruleKey?: string
94
94
  ) => GeneratedCSSRule[];
95
- getClassNames?: ( style: Style ) => string[];
96
95
  }