@wordpress/style-engine 0.14.0 → 0.14.1-next.d6164808d3.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 (56) hide show
  1. package/README.md +64 -58
  2. package/build/index.js +7 -5
  3. package/build/index.js.map +1 -1
  4. package/build/styles/typography/index.js +7 -1
  5. package/build/styles/typography/index.js.map +1 -1
  6. package/build/styles/utils.js +5 -5
  7. package/build/styles/utils.js.map +1 -1
  8. package/build-module/index.js +6 -4
  9. package/build-module/index.js.map +1 -1
  10. package/build-module/styles/typography/index.js +7 -1
  11. package/build-module/styles/typography/index.js.map +1 -1
  12. package/build-module/styles/utils.js +5 -5
  13. package/build-module/styles/utils.js.map +1 -1
  14. package/build-types/index.d.ts +23 -0
  15. package/build-types/index.d.ts.map +1 -0
  16. package/build-types/styles/border/index.d.ts +10 -0
  17. package/build-types/styles/border/index.d.ts.map +1 -0
  18. package/build-types/styles/color/background.d.ts +14 -0
  19. package/build-types/styles/color/background.d.ts.map +1 -0
  20. package/build-types/styles/color/gradient.d.ts +14 -0
  21. package/build-types/styles/color/gradient.d.ts.map +1 -0
  22. package/build-types/styles/color/index.d.ts +10 -0
  23. package/build-types/styles/color/index.d.ts.map +1 -0
  24. package/build-types/styles/color/text.d.ts +14 -0
  25. package/build-types/styles/color/text.d.ts.map +1 -0
  26. package/build-types/styles/constants.d.ts +4 -0
  27. package/build-types/styles/constants.d.ts.map +1 -0
  28. package/build-types/styles/index.d.ts +5 -0
  29. package/build-types/styles/index.d.ts.map +1 -0
  30. package/build-types/styles/spacing/index.d.ts +6 -0
  31. package/build-types/styles/spacing/index.d.ts.map +1 -0
  32. package/build-types/styles/spacing/margin.d.ts +10 -0
  33. package/build-types/styles/spacing/margin.d.ts.map +1 -0
  34. package/build-types/styles/spacing/padding.d.ts +10 -0
  35. package/build-types/styles/spacing/padding.d.ts.map +1 -0
  36. package/build-types/styles/typography/index.d.ts +14 -0
  37. package/build-types/styles/typography/index.d.ts.map +1 -0
  38. package/build-types/styles/utils.d.ts +48 -0
  39. package/build-types/styles/utils.d.ts.map +1 -0
  40. package/build-types/types.d.ts +85 -0
  41. package/build-types/types.d.ts.map +1 -0
  42. package/class-wp-style-engine-css-declarations.php +18 -15
  43. package/class-wp-style-engine-css-rule.php +5 -9
  44. package/class-wp-style-engine-css-rules-store.php +5 -4
  45. package/class-wp-style-engine-processor.php +9 -1
  46. package/class-wp-style-engine.php +83 -92
  47. package/package.json +2 -2
  48. package/phpunit/class-wp-style-engine-css-declarations-test.php +2 -0
  49. package/phpunit/class-wp-style-engine-css-rules-store-test.php +14 -0
  50. package/phpunit/class-wp-style-engine-test.php +23 -19
  51. package/src/index.ts +4 -4
  52. package/src/styles/typography/index.ts +13 -0
  53. package/src/styles/utils.ts +5 -5
  54. package/src/test/index.js +24 -10
  55. package/src/types.ts +3 -4
  56. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/color/index.ts"],"names":[],"mappings":";;;;;;;;AAOA,wBAA8C"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { Style, StyleOptions } from '../../types';
5
+ declare const text: {
6
+ name: string;
7
+ generate: (style: Style, options: StyleOptions) => {
8
+ selector: string | undefined;
9
+ key: string;
10
+ value: string;
11
+ }[];
12
+ };
13
+ export default text;
14
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/styles/color/text.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,IAAI;;sBAEU,KAAK,WAAW,YAAY;;;;;CAG/C,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const VARIABLE_REFERENCE_PREFIX = "var:";
2
+ export declare const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = "|";
3
+ export declare const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = "--";
4
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/styles/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,SAAS,CAAC;AAChD,eAAO,MAAM,uCAAuC,MAAM,CAAC;AAC3D,eAAO,MAAM,mCAAmC,OAAO,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const styleDefinitions: (import("../types").StyleDefinition | {
2
+ name: string;
3
+ generate: (style: import("../types").Style, options: import("../types").StyleOptions) => import("../types").GeneratedCSSRule[];
4
+ })[];
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,gBAAgB;;;IAK5B,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ name: string;
3
+ generate: (style: import("../../types").Style, options: import("../../types").StyleOptions) => import("../../types").GeneratedCSSRule[];
4
+ }[];
5
+ export default _default;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/spacing/index.ts"],"names":[],"mappings":";;;;AAMA,wBAAmC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { Style, StyleOptions } from '../../types';
5
+ declare const margin: {
6
+ name: string;
7
+ generate: (style: Style, options: StyleOptions) => import("../../types").GeneratedCSSRule[];
8
+ };
9
+ export default margin;
10
+ //# sourceMappingURL=margin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"margin.d.ts","sourceRoot":"","sources":["../../../src/styles/spacing/margin.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,MAAM;;sBAEQ,KAAK,WAAW,YAAY;CAM/C,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { Style, StyleOptions } from '../../types';
5
+ declare const padding: {
6
+ name: string;
7
+ generate: (style: Style, options: StyleOptions) => import("../../types").GeneratedCSSRule[];
8
+ };
9
+ export default padding;
10
+ //# sourceMappingURL=padding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"padding.d.ts","sourceRoot":"","sources":["../../../src/styles/spacing/padding.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,OAAO;;sBAEO,KAAK,WAAW,YAAY;CAM/C,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { Style, StyleOptions } from '../../types';
5
+ declare const _default: {
6
+ name: string;
7
+ generate: (style: Style, options: StyleOptions) => {
8
+ selector: string | undefined;
9
+ key: string;
10
+ value: string;
11
+ }[];
12
+ }[];
13
+ export default _default;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/typography/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;;;;;;;;;AAmGvD,wBASE"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { CssRulesKeys, GeneratedCSSRule, Style, StyleOptions } from '../types';
5
+ /**
6
+ * Returns a JSON representation of the generated CSS rules.
7
+ *
8
+ * @param style Style object.
9
+ * @param options Options object with settings to adjust how the styles are generated.
10
+ * @param path An array of strings representing the path to the style value in the style object.
11
+ * @param ruleKey A CSS property key.
12
+ *
13
+ * @return GeneratedCSSRule[] CSS rules.
14
+ */
15
+ export declare function generateRule(style: Style, options: StyleOptions, path: string[], ruleKey: string): {
16
+ selector: string | undefined;
17
+ key: string;
18
+ value: string;
19
+ }[];
20
+ /**
21
+ * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.
22
+ *
23
+ * @param style Style object.
24
+ * @param options Options object with settings to adjust how the styles are generated.
25
+ * @param path An array of strings representing the path to the style value in the style object.
26
+ * @param ruleKeys An array of CSS property keys and patterns.
27
+ * @param individualProperties The "sides" or individual properties for which to generate rules.
28
+ *
29
+ * @return GeneratedCSSRule[] CSS rules.
30
+ */
31
+ export declare function generateBoxRules(style: Style, options: StyleOptions, path: string[], ruleKeys: CssRulesKeys, individualProperties?: string[]): GeneratedCSSRule[];
32
+ /**
33
+ * Returns a CSS var value from incoming style value following the pattern `var:description|context|slug`.
34
+ *
35
+ * @param styleValue A raw style value.
36
+ *
37
+ * @return string A CSS var value.
38
+ */
39
+ export declare function getCSSVarFromStyleValue(styleValue: string): string;
40
+ /**
41
+ * Capitalizes the first letter in a string.
42
+ *
43
+ * @param {string} str The string whose first letter the function will capitalize.
44
+ *
45
+ * @return string A CSS var value.
46
+ */
47
+ export declare function upperFirst([firstLetter, ...rest]: string): string;
48
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/styles/utils.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EACX,YAAY,EACZ,gBAAgB,EAChB,KAAK,EAEL,YAAY,EACZ,MAAM,UAAU,CAAC;AAOlB;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,MAAM;;;;IAaf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EAAE,EACd,QAAQ,EAAE,YAAY,EACtB,oBAAoB,GAAE,MAAM,EAAyC,GACnE,gBAAgB,EAAE,CAqCpB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAE,UAAU,EAAE,MAAM,GAAI,MAAM,CAYpE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAE,CAAE,WAAW,EAAE,GAAG,IAAI,CAAE,EAAE,MAAM,UAE3D"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type { CSSProperties } from 'react';
5
+ declare type BoxVariants = 'margin' | 'padding' | undefined;
6
+ export declare type Box<T extends BoxVariants = undefined> = {
7
+ top?: CSSProperties[T extends undefined ? 'top' : `${T}Top`];
8
+ right?: CSSProperties[T extends undefined ? 'right' : `${T}Right`];
9
+ bottom?: CSSProperties[T extends undefined ? 'bottom' : `${T}Bottom`];
10
+ left?: CSSProperties[T extends undefined ? 'left' : `${T}Left`];
11
+ };
12
+ export declare type BorderIndividualProperty = 'top' | 'right' | 'bottom' | 'left';
13
+ export declare type BorderIndividualStyles<T extends BorderIndividualProperty> = {
14
+ color?: CSSProperties[`border${Capitalize<string & T>}Color`];
15
+ style?: CSSProperties[`border${Capitalize<string & T>}Style`];
16
+ width?: CSSProperties[`border${Capitalize<string & T>}Width`];
17
+ };
18
+ export interface Style {
19
+ border?: {
20
+ color?: CSSProperties['borderColor'];
21
+ radius?: CSSProperties['borderRadius'] | {
22
+ topLeft?: CSSProperties['borderTopLeftRadius'];
23
+ topRight?: CSSProperties['borderTopRightRadius'];
24
+ bottomLeft?: CSSProperties['borderBottomLeftRadius'];
25
+ bottomRight?: CSSProperties['borderBottomLeftRadius'];
26
+ };
27
+ style?: CSSProperties['borderStyle'];
28
+ width?: CSSProperties['borderWidth'];
29
+ top?: BorderIndividualStyles<'top'>;
30
+ right?: BorderIndividualStyles<'right'>;
31
+ bottom?: BorderIndividualStyles<'bottom'>;
32
+ left?: BorderIndividualStyles<'left'>;
33
+ };
34
+ spacing?: {
35
+ margin?: CSSProperties['margin'] | Box<'margin'>;
36
+ padding?: CSSProperties['padding'] | Box<'padding'>;
37
+ };
38
+ typography?: {
39
+ fontSize?: CSSProperties['fontSize'];
40
+ fontFamily?: CSSProperties['fontFamily'];
41
+ fontWeight?: CSSProperties['fontWeight'];
42
+ fontStyle?: CSSProperties['fontStyle'];
43
+ letterSpacing?: CSSProperties['letterSpacing'];
44
+ lineHeight?: CSSProperties['lineHeight'];
45
+ textDecoration?: CSSProperties['textDecoration'];
46
+ textTransform?: CSSProperties['textTransform'];
47
+ };
48
+ color?: {
49
+ text?: CSSProperties['color'];
50
+ background?: CSSProperties['backgroundColor'];
51
+ gradient?: CSSProperties['background'];
52
+ };
53
+ elements?: {
54
+ link?: {
55
+ color?: {
56
+ text?: CSSProperties['color'];
57
+ };
58
+ };
59
+ };
60
+ }
61
+ export declare type CssRulesKeys = {
62
+ default: string;
63
+ individual: string;
64
+ };
65
+ export declare type StyleOptions = {
66
+ /**
67
+ * CSS selector for the generated style.
68
+ */
69
+ selector?: string;
70
+ };
71
+ export declare type GeneratedCSSRule = {
72
+ selector?: string;
73
+ value: string;
74
+ /**
75
+ * The CSS key in JS style attribute format, compatible with React.
76
+ * E.g. `paddingTop` instead of `padding-top`.
77
+ */
78
+ key: string;
79
+ };
80
+ export interface StyleDefinition {
81
+ name: string;
82
+ generate?: (style: Style, options: StyleOptions | {}, path?: string[], ruleKey?: string) => GeneratedCSSRule[];
83
+ }
84
+ export {};
85
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAA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C,EAAE,aAAa,CAAE,OAAO,CAAE,CAAC;QAChC,UAAU,CAAC,EAAE,aAAa,CAAE,iBAAiB,CAAE,CAAC;QAChD,QAAQ,CAAC,EAAE,aAAa,CAAE,YAAY,CAAE,CAAC;KACzC,CAAC;IACF,QAAQ,CAAC,EAAE;QACV,IAAI,CAAC,EAAE;YACN,KAAK,CAAC,EAAE;gBACP,IAAI,CAAC,EAAE,aAAa,CAAE,OAAO,CAAE,CAAC;aAChC,CAAC;SACF,CAAC;KACF,CAAC;CACF;AAED,oBAAY,YAAY,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,oBAAY,YAAY,GAAG;IAC1B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,CACV,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,GAAG,EAAE,EAC1B,IAAI,CAAC,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE,MAAM,KACZ,gBAAgB,EAAE,CAAC;CACxB"}
@@ -34,9 +34,6 @@ class WP_Style_Engine_CSS_Declarations {
34
34
  * @param array $declarations An array of declarations (property => value pairs).
35
35
  */
36
36
  public function __construct( $declarations = array() ) {
37
- if ( empty( $declarations ) ) {
38
- return;
39
- }
40
37
  $this->add_declarations( $declarations );
41
38
  }
42
39
 
@@ -46,7 +43,7 @@ class WP_Style_Engine_CSS_Declarations {
46
43
  * @param string $property The CSS property.
47
44
  * @param string $value The CSS value.
48
45
  *
49
- * @return void
46
+ * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
50
47
  */
51
48
  public function add_declaration( $property, $value ) {
52
49
 
@@ -54,17 +51,19 @@ class WP_Style_Engine_CSS_Declarations {
54
51
  $property = $this->sanitize_property( $property );
55
52
  // Bail early if the property is empty.
56
53
  if ( empty( $property ) ) {
57
- return;
54
+ return $this;
58
55
  }
59
56
 
60
57
  // Trim the value. If empty, bail early.
61
58
  $value = trim( $value );
62
59
  if ( '' === $value ) {
63
- return;
60
+ return $this;
64
61
  }
65
62
 
66
63
  // Add the declaration property/value pair.
67
64
  $this->declarations[ $property ] = $value;
65
+
66
+ return $this;
68
67
  }
69
68
 
70
69
  /**
@@ -72,10 +71,11 @@ class WP_Style_Engine_CSS_Declarations {
72
71
  *
73
72
  * @param string $property The CSS property.
74
73
  *
75
- * @return void
74
+ * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
76
75
  */
77
76
  public function remove_declaration( $property ) {
78
77
  unset( $this->declarations[ $property ] );
78
+ return $this;
79
79
  }
80
80
 
81
81
  /**
@@ -83,25 +83,27 @@ class WP_Style_Engine_CSS_Declarations {
83
83
  *
84
84
  * @param array $declarations An array of declarations.
85
85
  *
86
- * @return void
86
+ * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
87
87
  */
88
88
  public function add_declarations( $declarations ) {
89
89
  foreach ( $declarations as $property => $value ) {
90
90
  $this->add_declaration( $property, $value );
91
91
  }
92
+ return $this;
92
93
  }
93
94
 
94
95
  /**
95
96
  * Remove multiple declarations.
96
97
  *
97
- * @param array $declarations An array of properties.
98
+ * @param array $properties An array of properties.
98
99
  *
99
- * @return void
100
+ * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
100
101
  */
101
- public function remove_declarations( $declarations = array() ) {
102
- foreach ( $declarations as $property ) {
102
+ public function remove_declarations( $properties = array() ) {
103
+ foreach ( $properties as $property ) {
103
104
  $this->remove_declaration( $property );
104
105
  }
106
+ return $this;
105
107
  }
106
108
 
107
109
  /**
@@ -123,8 +125,9 @@ class WP_Style_Engine_CSS_Declarations {
123
125
  * @return string The filtered declaration as a single string.
124
126
  */
125
127
  protected static function filter_declaration( $property, $value, $spacer = '' ) {
126
- if ( isset( $property ) && isset( $value ) ) {
127
- return safecss_filter_attr( "{$property}:{$spacer}{$value}" );
128
+ $filtered_value = wp_strip_all_tags( $value, true );
129
+ if ( '' !== $filtered_value ) {
130
+ return safecss_filter_attr( "{$property}:{$spacer}{$filtered_value}" );
128
131
  }
129
132
  return '';
130
133
  }
@@ -143,9 +146,9 @@ class WP_Style_Engine_CSS_Declarations {
143
146
  $indent = $should_prettify ? str_repeat( "\t", $indent_count ) : '';
144
147
  $suffix = $should_prettify ? ' ' : '';
145
148
  $suffix = $should_prettify && $indent_count > 0 ? "\n" : $suffix;
149
+ $spacer = $should_prettify ? ' ' : '';
146
150
 
147
151
  foreach ( $declarations_array as $property => $value ) {
148
- $spacer = $should_prettify ? ' ' : '';
149
152
  $filtered_declaration = static::filter_declaration( $property, $value, $spacer );
150
153
  if ( $filtered_declaration ) {
151
154
  $declarations_output .= "{$indent}{$filtered_declaration};$suffix";
@@ -51,14 +51,10 @@ class WP_Style_Engine_CSS_Rule {
51
51
  *
52
52
  * @param string $selector The CSS selector.
53
53
  *
54
- * @return WP_Style_Engine_CSS_Rule|void Returns the object to allow chaining of methods.
54
+ * @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods.
55
55
  */
56
56
  public function set_selector( $selector ) {
57
- if ( empty( $selector ) ) {
58
- return;
59
- }
60
57
  $this->selector = $selector;
61
-
62
58
  return $this;
63
59
  }
64
60
 
@@ -74,11 +70,11 @@ class WP_Style_Engine_CSS_Rule {
74
70
  $is_declarations_object = ! is_array( $declarations );
75
71
  $declarations_array = $is_declarations_object ? $declarations->get_declarations() : $declarations;
76
72
 
77
- if ( null === $this->declarations && $is_declarations_object ) {
78
- $this->declarations = $declarations;
79
- return $this;
80
- }
81
73
  if ( null === $this->declarations ) {
74
+ if ( $is_declarations_object ) {
75
+ $this->declarations = $declarations;
76
+ return $this;
77
+ }
82
78
  $this->declarations = new WP_Style_Engine_CSS_Declarations( $declarations_array );
83
79
  }
84
80
  $this->declarations->add_declarations( $declarations_array );
@@ -27,7 +27,6 @@ class WP_Style_Engine_CSS_Rules_Store {
27
27
  */
28
28
  protected static $stores = array();
29
29
 
30
-
31
30
  /**
32
31
  * The store name.
33
32
  *
@@ -47,9 +46,12 @@ class WP_Style_Engine_CSS_Rules_Store {
47
46
  *
48
47
  * @param string $store_name The name of the store.
49
48
  *
50
- * @return WP_Style_Engine_CSS_Rules_Store
49
+ * @return WP_Style_Engine_CSS_Rules_Store|void
51
50
  */
52
51
  public static function get_store( $store_name = 'default' ) {
52
+ if ( ! is_string( $store_name ) || empty( $store_name ) ) {
53
+ return;
54
+ }
53
55
  if ( ! isset( static::$stores[ $store_name ] ) ) {
54
56
  static::$stores[ $store_name ] = new static();
55
57
  // Set the store name.
@@ -111,10 +113,9 @@ class WP_Style_Engine_CSS_Rules_Store {
111
113
  *
112
114
  * @param string $selector The CSS selector.
113
115
  *
114
- * @return WP_Style_Engine_CSS_Rule|null Returns a WP_Style_Engine_CSS_Rule object, or null if the selector is empty.
116
+ * @return WP_Style_Engine_CSS_Rule|void Returns a WP_Style_Engine_CSS_Rule object, or null if the selector is empty.
115
117
  */
116
118
  public function add_rule( $selector ) {
117
-
118
119
  $selector = trim( $selector );
119
120
 
120
121
  // Bail early if there is no selector.
@@ -36,15 +36,21 @@ class WP_Style_Engine_Processor {
36
36
  * Add a store to the processor.
37
37
  *
38
38
  * @param WP_Style_Engine_CSS_Rules_Store $store The store to add.
39
+ *
40
+ * @return WP_Style_Engine_Processor Returns the object to allow chaining methods.
39
41
  */
40
42
  public function add_store( WP_Style_Engine_CSS_Rules_Store $store ) {
41
43
  $this->stores[ $store->get_name() ] = $store;
44
+
45
+ return $this;
42
46
  }
43
47
 
44
48
  /**
45
49
  * Adds rules to be processed.
46
50
  *
47
51
  * @param WP_Style_Engine_CSS_Rule|WP_Style_Engine_CSS_Rule[] $css_rules A single, or an array of, WP_Style_Engine_CSS_Rule objects from a store or otherwise.
52
+ *
53
+ * @return WP_Style_Engine_Processor Returns the object to allow chaining methods.
48
54
  */
49
55
  public function add_rules( $css_rules ) {
50
56
  if ( ! is_array( $css_rules ) ) {
@@ -58,6 +64,8 @@ class WP_Style_Engine_Processor {
58
64
  }
59
65
  $this->css_rules[ $rule->get_selector() ] = $rule;
60
66
  }
67
+
68
+ return $this;
61
69
  }
62
70
 
63
71
  /**
@@ -73,7 +81,7 @@ class WP_Style_Engine_Processor {
73
81
  public function get_css( $options = array() ) {
74
82
  $defaults = array(
75
83
  'optimize' => true,
76
- 'prettify' => false,
84
+ 'prettify' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG,
77
85
  );
78
86
  $options = wp_parse_args( $options, $defaults );
79
87