@wordpress/style-engine 0.16.0 → 1.0.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 CHANGED
@@ -2,36 +2,22 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- ## 0.16.0 (2022-09-13)
6
-
7
- ## 0.15.0 (2022-08-24)
8
-
9
- ## 0.14.0 (2022-08-10)
10
-
11
- ## 0.13.0 (2022-07-27)
12
-
13
- ## 0.12.0 (2022-07-13)
14
-
15
- ## 0.11.0 (2022-06-29)
16
-
17
- ## 0.10.0 (2022-06-15)
18
-
19
- ## 0.9.0 (2022-06-01)
20
-
21
- ## 0.8.0 (2022-05-18)
22
-
23
- ## 0.7.0 (2022-05-04)
24
-
25
- ## 0.6.0 (2022-04-21)
26
-
27
- ## 0.5.0 (2022-04-08)
28
-
29
- ## 0.4.0 (2022-03-23)
30
-
31
- ## 0.3.0 (2022-03-11)
32
-
33
- ## 0.2.0 (2022-02-23)
34
-
35
- ### New Feature
36
-
5
+ ### Enhancement
6
+ - Allow for prettified output ([#42909](https://github.com/WordPress/gutenberg/pull/42909)).
7
+ - Enqueue block supports styles in Gutenberg ([#42880](https://github.com/WordPress/gutenberg/pull/42880)).
8
+
9
+ ### Internal
10
+ - Move backend scripts to package ([#39736](https://github.com/WordPress/gutenberg/pull/39736)).
11
+ - Updating docs, formatting, and separating global functions from the main class file ([#43840](https://github.com/WordPress/gutenberg/pull/43840)).
12
+
13
+ ### New Features
14
+ - Add a WP_Style_Engine_Processor object ([#42463](https://github.com/WordPress/gutenberg/pull/42463)).
15
+ - Add a WP_Style_Engine_CSS_Declarations object ([#42043](https://github.com/WordPress/gutenberg/pull/42043)).
16
+ - Add Rules and Store objects ([#42222](https://github.com/WordPress/gutenberg/pull/42222)).
17
+ - Add elements styles support ([#41732](https://github.com/WordPress/gutenberg/pull/41732)) and ([#40987](https://github.com/WordPress/gutenberg/pull/40987)).
18
+ - Add typography and color support ([#40665](https://github.com/WordPress/gutenberg/pull/40987)) and ([#40332](https://github.com/WordPress/gutenberg/pull/40332)).
19
+ - Add border support ([#41803](https://github.com/WordPress/gutenberg/pull/40332)) and ([#40531](https://github.com/WordPress/gutenberg/pull/40531)).
20
+ - Add margin support to frontend ([#39790](https://github.com/WordPress/gutenberg/pull/39790)).
21
+ - Add basic block supports to backend ([#39446](https://github.com/WordPress/gutenberg/pull/39446)).
37
22
  - Added initial version of the style engine ([#37978](https://github.com/WordPress/gutenberg/pull/37978)).
23
+ - Include `@wordpress/style-engine` on the list of external dependencies to allow using `wp.styleEngine` global with WordPress 6.1 and beyond ([#43840](https://github.com/WordPress/gutenberg/pull/43840)).
package/README.md CHANGED
@@ -1,27 +1,23 @@
1
1
  # Style Engine
2
2
 
3
- The Style Engine powering global styles and block customizations.
3
+ The Style Engine aims to provide a consistent API for rendering styling for blocks across both client-side and server-side applications.
4
4
 
5
- ## Important
5
+ Initially, it will offer a single, centralized agent responsible for generating block styles, and, in later phases, it will also assume the responsibility of processing and rendering optimized frontend CSS.
6
6
 
7
- This Package is considered experimental at the moment. The idea is to have a package used to generate styles based on a
8
- style object that is consistent between: backend, frontend, block style object and theme.json.
7
+ ## Important
9
8
 
10
- Because this package is experimental and still in development it does not yet generate a `wp.styleEngine` global. To get
11
- there, the following tasks need to be completed:
9
+ This package is new as of WordPress 6.1 and therefore in its infancy.
12
10
 
13
- **TODO List:**
11
+ Upcoming tasks on the roadmap include, but are not limited to, the following:
14
12
 
15
- - Add style definitions for all the currently supported styles in blocks and theme.json.
16
- - The CSS variable shortcuts for values (for presets...)
17
- - Support generating styles in the frontend. (Ongoing)
18
- - Support generating styles in the backend (block supports and theme.json stylesheet). (Ongoing)
19
- - Refactor all block styles to use the style engine server side. (Ongoing)
20
- - Consolidate global and block style rendering and enqueuing
21
- - Refactor all blocks to consistently use the "style" attribute for all customizations (get rid of the preset specific
22
- attributes).
13
+ - Consolidate global and block style rendering and enqueuing (ongoing)
14
+ - Explore pre-render CSS rule processing with the intention of deduplicating other common and/or repetitive block styles. (ongoing)
15
+ - Extend the scope of semantic class names and/or design token expression, and encapsulate rules into stable utility classes.
16
+ - Explore pre-render CSS rule processing with the intention of deduplicating other common and/or repetitive block styles.
17
+ - Propose a way to control hierarchy and specificity, and make the style hierarchy cascade accessible and predictable. This might include preparing for CSS cascade layers until they become more widely supported, and allowing for opt-in support in Gutenberg via theme.json.
18
+ - Refactor all blocks to consistently use the "style" attribute for all customizations, that is, deprecate preset-specific attributes such as `attributes.fontSize`.
23
19
 
24
- See [Tracking: Add a Style Engine to manage rendering block styles #38167](https://github.com/WordPress/gutenberg/issues/38167)
20
+ For more information about the roadmap, please refer to [Block editor styles: initiatives and goals](https://make.wordpress.org/core/2022/06/24/block-editor-styles-initiatives-and-goals/) and the [Github project board](https://github.com/orgs/WordPress/projects/19).
25
21
 
26
22
  ## Backend API
27
23
 
@@ -30,8 +26,9 @@ See [Tracking: Add a Style Engine to manage rendering block styles #38167](https
30
26
  Global public function to generate styles from a single style object, e.g., the value of
31
27
  a [block's attributes.style object](https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/theme-json-living/#styles)
32
28
  or
33
- the [top level styles in theme.json](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/)
34
- .
29
+ the [top level styles in theme.json](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/).
30
+
31
+ See also [Using the Style Engine to generate block supports styles](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/using-the-style-engine-with-block-supports).
35
32
 
36
33
  _Parameters_
37
34
 
@@ -82,7 +79,7 @@ print_r( $styles );
82
79
 
83
80
  /*
84
81
  array(
85
- 'css' => '.a-selector{padding:10px}'
82
+ 'css' => '.a-selector{padding:100px}'
86
83
  'declarations' => array( 'padding' => '100px' )
87
84
  )
88
85
  */
@@ -132,7 +129,7 @@ $stylesheet = wp_style_engine_get_stylesheet_from_css_rules(
132
129
  'context' => 'block-supports', // Indicates that these styles should be stored with block supports CSS.
133
130
  )
134
131
  );
135
- print_r( $stylesheet ); // .wp-pumpkin, .wp-kumquat {color:orange}.wp-tomato{color:red;padding:100px}
132
+ print_r( $stylesheet ); // .wp-pumpkin,.wp-kumquat{color:orange}.wp-tomato{color:red;padding:100px}
136
133
  ```
137
134
 
138
135
  ### wp_style_engine_get_stylesheet_from_context()
@@ -185,10 +182,7 @@ Install the module
185
182
  npm install @wordpress/style-engine --save
186
183
  ```
187
184
 
188
- _This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has
189
- limited or no support for such language features and APIs, you should
190
- include [the polyfill shipped in `@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill)
191
- in your code._
185
+ _This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for such language features and APIs, you should include [the polyfill shipped in `@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill) in your code._
192
186
 
193
187
  ## Usage
194
188
 
@@ -205,7 +199,11 @@ _Parameters_
205
199
 
206
200
  _Returns_
207
201
 
208
- - `string`: generated stylesheet.
202
+ - `string`: A generated stylesheet or inline style declarations.
203
+
204
+ _Changelog_
205
+
206
+ `6.1.0` Introduced in WordPress core.
209
207
 
210
208
  ### getCSSRules
211
209
 
@@ -218,7 +216,11 @@ _Parameters_
218
216
 
219
217
  _Returns_
220
218
 
221
- - `GeneratedCSSRule[]`: generated styles.
219
+ - `GeneratedCSSRule[]`: A collection of objects containing the selector, if any, the CSS property key (camelcase) and parsed CSS value.
220
+
221
+ _Changelog_
222
+
223
+ `6.1.0` Introduced in WordPress core.
222
224
 
223
225
  <!-- END TOKEN(Autogenerated API docs) -->
224
226
 
@@ -239,8 +241,8 @@ A guide to the terms and variable names referenced by the Style Engine package.
239
241
  <dd>Identifiers that describe stylistic, modifiable features of an HTML element. E.g., <code>border</code>, <code>font-size</code>, <code>width</code>...</dd>
240
242
  <dt>CSS rule</dt>
241
243
  <dd>A CSS selector followed by a CSS declarations block inside a set of curly braces. Usually found in a CSS stylesheet.</dd>
242
- <dt>CSS selector</dt>
243
- <dd>The first component of a CSS rule, a CSS selector is a pattern of elements, classnames or other terms that define the element to which the rule&rsquo;s CSS definitions apply. E.g., <code>p.my-cool-classname > span</code>. See <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors" target="_blank">MDN CSS selectors article</a>.</dd>
244
+ <dt>CSS selector (or CSS class selector)</dt>
245
+ <dd>The first component of a CSS rule, a CSS selector is a pattern of elements, classnames or other terms that define the element to which the rule&rsquo;s CSS definitions apply. E.g., <code>p.my-cool-classname > span</code>. A CSS selector matches HTML elements based on the contents of the "class" attribute. See <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors" target="_blank">MDN CSS selectors article</a>.</dd>
244
246
  <dt>CSS stylesheet</dt>
245
247
  <dd>A collection of CSS rules contained within a file or within an <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style" target="_blank">HTML style tag</a>.</dd>
246
248
  <dt>CSS value</dt>
package/build/index.js CHANGED
@@ -17,10 +17,12 @@ var _styles = require("./styles");
17
17
  /**
18
18
  * Generates a stylesheet for a given style object and selector.
19
19
  *
20
+ * @since 6.1.0 Introduced in WordPress core.
21
+ *
20
22
  * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
21
23
  * @param options Options object with settings to adjust how the styles are generated.
22
24
  *
23
- * @return generated stylesheet.
25
+ * @return A generated stylesheet or inline style declarations.
24
26
  */
25
27
  function compileCSS(style) {
26
28
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -44,10 +46,12 @@ function compileCSS(style) {
44
46
  /**
45
47
  * Returns a JSON representation of the generated CSS rules.
46
48
  *
49
+ * @since 6.1.0 Introduced in WordPress core.
50
+ *
47
51
  * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
48
52
  * @param options Options object with settings to adjust how the styles are generated.
49
53
  *
50
- * @return generated styles.
54
+ * @return A collection of objects containing the selector, if any, the CSS property key (camelcase) and parsed CSS value.
51
55
  */
52
56
 
53
57
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/index.ts"],"names":["compileCSS","style","options","rules","getCSSRules","selector","inlineRules","forEach","rule","push","key","value","join","groupedRules","selectorRules","Object","keys","reduce","acc","subSelector","map","styleDefinitions","definition","generate"],"mappings":";;;;;;;;AAGA;;AAWA;;AAdA;AACA;AACA;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAT,CAAqBC,KAArB,EAAwE;AAAA,MAArCC,OAAqC,uEAAb,EAAa;AAC9E,QAAMC,KAAK,GAAGC,WAAW,CAAEH,KAAF,EAASC,OAAT,CAAzB,CAD8E,CAG9E;;AACA,MAAK,EAAEA,OAAF,aAAEA,OAAF,eAAEA,OAAO,CAAEG,QAAX,CAAL,EAA2B;AAC1B,UAAMC,WAAqB,GAAG,EAA9B;AACAH,IAAAA,KAAK,CAACI,OAAN,CAAiBC,IAAF,IAAY;AAC1BF,MAAAA,WAAW,CAACG,IAAZ,CAAmB,GAAG,uBAAWD,IAAI,CAACE,GAAhB,CAAuB,KAAKF,IAAI,CAACG,KAAO,GAA9D;AACA,KAFD;AAGA,WAAOL,WAAW,CAACM,IAAZ,CAAkB,GAAlB,CAAP;AACA;;AAED,QAAMC,YAAY,GAAG,qBAASV,KAAT,EAAgB,UAAhB,CAArB;AACA,QAAMW,aAAa,GAAGC,MAAM,CAACC,IAAP,CAAaH,YAAb,EAA4BI,MAA5B,CACrB,CAAEC,GAAF,EAAiBC,WAAjB,KAA0C;AACzCD,IAAAA,GAAG,CAACT,IAAJ,CACE,GAAGU,WAAa,MAAMN,YAAY,CAAEM,WAAF,CAAZ,CACrBC,GADqB,CAEnBZ,IAAF,IACE,GAAG,uBAAWA,IAAI,CAACE,GAAhB,CAAuB,KAAKF,IAAI,CAACG,KAAO,GAHxB,EAKrBC,IALqB,CAKf,GALe,CAKR,IANhB;AAQA,WAAOM,GAAP;AACA,GAXoB,EAYrB,EAZqB,CAAtB;AAeA,SAAOJ,aAAa,CAACF,IAAd,CAAoB,IAApB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASR,WAAT,CACNH,KADM,EAGe;AAAA,MADrBC,OACqB,uEADG,EACH;AACrB,QAAMC,KAAyB,GAAG,EAAlC;;AACAkB,2BAAiBd,OAAjB,CAA4Be,UAAF,IAAmC;AAC5D,QAAK,OAAOA,UAAU,CAACC,QAAlB,KAA+B,UAApC,EAAiD;AAChDpB,MAAAA,KAAK,CAACM,IAAN,CAAY,GAAGa,UAAU,CAACC,QAAX,CAAqBtB,KAArB,EAA4BC,OAA5B,CAAf;AACA;AACD,GAJD;;AAMA,SAAOC,KAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { groupBy, kebabCase } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tStyle,\n\tStyleOptions,\n\tGeneratedCSSRule,\n\tStyleDefinition,\n} from './types';\nimport { styleDefinitions } from './styles';\n\n/**\n * Generates a stylesheet for a given style object and selector.\n *\n * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json\n * @param options Options object with settings to adjust how the styles are generated.\n *\n * @return generated stylesheet.\n */\nexport function compileCSS( style: Style, options: StyleOptions = {} ): string {\n\tconst rules = getCSSRules( style, options );\n\n\t// If no selector is provided, treat generated rules as inline styles to be returned as a single string.\n\tif ( ! options?.selector ) {\n\t\tconst inlineRules: string[] = [];\n\t\trules.forEach( ( rule ) => {\n\t\t\tinlineRules.push( `${ kebabCase( rule.key ) }: ${ rule.value };` );\n\t\t} );\n\t\treturn inlineRules.join( ' ' );\n\t}\n\n\tconst groupedRules = groupBy( rules, 'selector' );\n\tconst selectorRules = Object.keys( groupedRules ).reduce(\n\t\t( acc: string[], subSelector: string ) => {\n\t\t\tacc.push(\n\t\t\t\t`${ subSelector } { ${ groupedRules[ subSelector ]\n\t\t\t\t\t.map(\n\t\t\t\t\t\t( rule: GeneratedCSSRule ) =>\n\t\t\t\t\t\t\t`${ kebabCase( rule.key ) }: ${ rule.value };`\n\t\t\t\t\t)\n\t\t\t\t\t.join( ' ' ) } }`\n\t\t\t);\n\t\t\treturn acc;\n\t\t},\n\t\t[]\n\t);\n\n\treturn selectorRules.join( '\\n' );\n}\n\n/**\n * Returns a JSON representation of the generated CSS rules.\n *\n * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json\n * @param options Options object with settings to adjust how the styles are generated.\n *\n * @return generated styles.\n */\nexport function getCSSRules(\n\tstyle: Style,\n\toptions: StyleOptions = {}\n): GeneratedCSSRule[] {\n\tconst rules: GeneratedCSSRule[] = [];\n\tstyleDefinitions.forEach( ( definition: StyleDefinition ) => {\n\t\tif ( typeof definition.generate === 'function' ) {\n\t\t\trules.push( ...definition.generate( style, options ) );\n\t\t}\n\t} );\n\n\treturn rules;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/index.ts"],"names":["compileCSS","style","options","rules","getCSSRules","selector","inlineRules","forEach","rule","push","key","value","join","groupedRules","selectorRules","Object","keys","reduce","acc","subSelector","map","styleDefinitions","definition","generate"],"mappings":";;;;;;;;AAGA;;AAWA;;AAdA;AACA;AACA;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAT,CAAqBC,KAArB,EAAwE;AAAA,MAArCC,OAAqC,uEAAb,EAAa;AAC9E,QAAMC,KAAK,GAAGC,WAAW,CAAEH,KAAF,EAASC,OAAT,CAAzB,CAD8E,CAG9E;;AACA,MAAK,EAAEA,OAAF,aAAEA,OAAF,eAAEA,OAAO,CAAEG,QAAX,CAAL,EAA2B;AAC1B,UAAMC,WAAqB,GAAG,EAA9B;AACAH,IAAAA,KAAK,CAACI,OAAN,CAAiBC,IAAF,IAAY;AAC1BF,MAAAA,WAAW,CAACG,IAAZ,CAAmB,GAAG,uBAAWD,IAAI,CAACE,GAAhB,CAAuB,KAAKF,IAAI,CAACG,KAAO,GAA9D;AACA,KAFD;AAGA,WAAOL,WAAW,CAACM,IAAZ,CAAkB,GAAlB,CAAP;AACA;;AAED,QAAMC,YAAY,GAAG,qBAASV,KAAT,EAAgB,UAAhB,CAArB;AACA,QAAMW,aAAa,GAAGC,MAAM,CAACC,IAAP,CAAaH,YAAb,EAA4BI,MAA5B,CACrB,CAAEC,GAAF,EAAiBC,WAAjB,KAA0C;AACzCD,IAAAA,GAAG,CAACT,IAAJ,CACE,GAAGU,WAAa,MAAMN,YAAY,CAAEM,WAAF,CAAZ,CACrBC,GADqB,CAEnBZ,IAAF,IACE,GAAG,uBAAWA,IAAI,CAACE,GAAhB,CAAuB,KAAKF,IAAI,CAACG,KAAO,GAHxB,EAKrBC,IALqB,CAKf,GALe,CAKR,IANhB;AAQA,WAAOM,GAAP;AACA,GAXoB,EAYrB,EAZqB,CAAtB;AAeA,SAAOJ,aAAa,CAACF,IAAd,CAAoB,IAApB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASR,WAAT,CACNH,KADM,EAGe;AAAA,MADrBC,OACqB,uEADG,EACH;AACrB,QAAMC,KAAyB,GAAG,EAAlC;;AACAkB,2BAAiBd,OAAjB,CAA4Be,UAAF,IAAmC;AAC5D,QAAK,OAAOA,UAAU,CAACC,QAAlB,KAA+B,UAApC,EAAiD;AAChDpB,MAAAA,KAAK,CAACM,IAAN,CAAY,GAAGa,UAAU,CAACC,QAAX,CAAqBtB,KAArB,EAA4BC,OAA5B,CAAf;AACA;AACD,GAJD;;AAMA,SAAOC,KAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { groupBy, kebabCase } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tStyle,\n\tStyleOptions,\n\tGeneratedCSSRule,\n\tStyleDefinition,\n} from './types';\nimport { styleDefinitions } from './styles';\n\n/**\n * Generates a stylesheet for a given style object and selector.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json\n * @param options Options object with settings to adjust how the styles are generated.\n *\n * @return A generated stylesheet or inline style declarations.\n */\nexport function compileCSS( style: Style, options: StyleOptions = {} ): string {\n\tconst rules = getCSSRules( style, options );\n\n\t// If no selector is provided, treat generated rules as inline styles to be returned as a single string.\n\tif ( ! options?.selector ) {\n\t\tconst inlineRules: string[] = [];\n\t\trules.forEach( ( rule ) => {\n\t\t\tinlineRules.push( `${ kebabCase( rule.key ) }: ${ rule.value };` );\n\t\t} );\n\t\treturn inlineRules.join( ' ' );\n\t}\n\n\tconst groupedRules = groupBy( rules, 'selector' );\n\tconst selectorRules = Object.keys( groupedRules ).reduce(\n\t\t( acc: string[], subSelector: string ) => {\n\t\t\tacc.push(\n\t\t\t\t`${ subSelector } { ${ groupedRules[ subSelector ]\n\t\t\t\t\t.map(\n\t\t\t\t\t\t( rule: GeneratedCSSRule ) =>\n\t\t\t\t\t\t\t`${ kebabCase( rule.key ) }: ${ rule.value };`\n\t\t\t\t\t)\n\t\t\t\t\t.join( ' ' ) } }`\n\t\t\t);\n\t\t\treturn acc;\n\t\t},\n\t\t[]\n\t);\n\n\treturn selectorRules.join( '\\n' );\n}\n\n/**\n * Returns a JSON representation of the generated CSS rules.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json\n * @param options Options object with settings to adjust how the styles are generated.\n *\n * @return A collection of objects containing the selector, if any, the CSS property key (camelcase) and parsed CSS value.\n */\nexport function getCSSRules(\n\tstyle: Style,\n\toptions: StyleOptions = {}\n): GeneratedCSSRule[] {\n\tconst rules: GeneratedCSSRule[] = [];\n\tstyleDefinitions.forEach( ( definition: StyleDefinition ) => {\n\t\tif ( typeof definition.generate === 'function' ) {\n\t\t\trules.push( ...definition.generate( style, options ) );\n\t\t}\n\t} );\n\n\treturn rules;\n}\n"]}
@@ -10,10 +10,12 @@ import { styleDefinitions } from './styles';
10
10
  /**
11
11
  * Generates a stylesheet for a given style object and selector.
12
12
  *
13
+ * @since 6.1.0 Introduced in WordPress core.
14
+ *
13
15
  * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
14
16
  * @param options Options object with settings to adjust how the styles are generated.
15
17
  *
16
- * @return generated stylesheet.
18
+ * @return A generated stylesheet or inline style declarations.
17
19
  */
18
20
 
19
21
  export function compileCSS(style) {
@@ -38,10 +40,12 @@ export function compileCSS(style) {
38
40
  /**
39
41
  * Returns a JSON representation of the generated CSS rules.
40
42
  *
43
+ * @since 6.1.0 Introduced in WordPress core.
44
+ *
41
45
  * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
42
46
  * @param options Options object with settings to adjust how the styles are generated.
43
47
  *
44
- * @return generated styles.
48
+ * @return A collection of objects containing the selector, if any, the CSS property key (camelcase) and parsed CSS value.
45
49
  */
46
50
 
47
51
  export function getCSSRules(style) {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/index.ts"],"names":["groupBy","kebabCase","styleDefinitions","compileCSS","style","options","rules","getCSSRules","selector","inlineRules","forEach","rule","push","key","value","join","groupedRules","selectorRules","Object","keys","reduce","acc","subSelector","map","definition","generate"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,SAAlB,QAAmC,QAAnC;AAEA;AACA;AACA;;AAOA,SAASC,gBAAT,QAAiC,UAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CAAqBC,KAArB,EAAwE;AAAA,MAArCC,OAAqC,uEAAb,EAAa;AAC9E,QAAMC,KAAK,GAAGC,WAAW,CAAEH,KAAF,EAASC,OAAT,CAAzB,CAD8E,CAG9E;;AACA,MAAK,EAAEA,OAAF,aAAEA,OAAF,eAAEA,OAAO,CAAEG,QAAX,CAAL,EAA2B;AAC1B,UAAMC,WAAqB,GAAG,EAA9B;AACAH,IAAAA,KAAK,CAACI,OAAN,CAAiBC,IAAF,IAAY;AAC1BF,MAAAA,WAAW,CAACG,IAAZ,CAAmB,GAAGX,SAAS,CAAEU,IAAI,CAACE,GAAP,CAAc,KAAKF,IAAI,CAACG,KAAO,GAA9D;AACA,KAFD;AAGA,WAAOL,WAAW,CAACM,IAAZ,CAAkB,GAAlB,CAAP;AACA;;AAED,QAAMC,YAAY,GAAGhB,OAAO,CAAEM,KAAF,EAAS,UAAT,CAA5B;AACA,QAAMW,aAAa,GAAGC,MAAM,CAACC,IAAP,CAAaH,YAAb,EAA4BI,MAA5B,CACrB,CAAEC,GAAF,EAAiBC,WAAjB,KAA0C;AACzCD,IAAAA,GAAG,CAACT,IAAJ,CACE,GAAGU,WAAa,MAAMN,YAAY,CAAEM,WAAF,CAAZ,CACrBC,GADqB,CAEnBZ,IAAF,IACE,GAAGV,SAAS,CAAEU,IAAI,CAACE,GAAP,CAAc,KAAKF,IAAI,CAACG,KAAO,GAHxB,EAKrBC,IALqB,CAKf,GALe,CAKR,IANhB;AAQA,WAAOM,GAAP;AACA,GAXoB,EAYrB,EAZqB,CAAtB;AAeA,SAAOJ,aAAa,CAACF,IAAd,CAAoB,IAApB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASR,WAAT,CACNH,KADM,EAGe;AAAA,MADrBC,OACqB,uEADG,EACH;AACrB,QAAMC,KAAyB,GAAG,EAAlC;AACAJ,EAAAA,gBAAgB,CAACQ,OAAjB,CAA4Bc,UAAF,IAAmC;AAC5D,QAAK,OAAOA,UAAU,CAACC,QAAlB,KAA+B,UAApC,EAAiD;AAChDnB,MAAAA,KAAK,CAACM,IAAN,CAAY,GAAGY,UAAU,CAACC,QAAX,CAAqBrB,KAArB,EAA4BC,OAA5B,CAAf;AACA;AACD,GAJD;AAMA,SAAOC,KAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { groupBy, kebabCase } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tStyle,\n\tStyleOptions,\n\tGeneratedCSSRule,\n\tStyleDefinition,\n} from './types';\nimport { styleDefinitions } from './styles';\n\n/**\n * Generates a stylesheet for a given style object and selector.\n *\n * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json\n * @param options Options object with settings to adjust how the styles are generated.\n *\n * @return generated stylesheet.\n */\nexport function compileCSS( style: Style, options: StyleOptions = {} ): string {\n\tconst rules = getCSSRules( style, options );\n\n\t// If no selector is provided, treat generated rules as inline styles to be returned as a single string.\n\tif ( ! options?.selector ) {\n\t\tconst inlineRules: string[] = [];\n\t\trules.forEach( ( rule ) => {\n\t\t\tinlineRules.push( `${ kebabCase( rule.key ) }: ${ rule.value };` );\n\t\t} );\n\t\treturn inlineRules.join( ' ' );\n\t}\n\n\tconst groupedRules = groupBy( rules, 'selector' );\n\tconst selectorRules = Object.keys( groupedRules ).reduce(\n\t\t( acc: string[], subSelector: string ) => {\n\t\t\tacc.push(\n\t\t\t\t`${ subSelector } { ${ groupedRules[ subSelector ]\n\t\t\t\t\t.map(\n\t\t\t\t\t\t( rule: GeneratedCSSRule ) =>\n\t\t\t\t\t\t\t`${ kebabCase( rule.key ) }: ${ rule.value };`\n\t\t\t\t\t)\n\t\t\t\t\t.join( ' ' ) } }`\n\t\t\t);\n\t\t\treturn acc;\n\t\t},\n\t\t[]\n\t);\n\n\treturn selectorRules.join( '\\n' );\n}\n\n/**\n * Returns a JSON representation of the generated CSS rules.\n *\n * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json\n * @param options Options object with settings to adjust how the styles are generated.\n *\n * @return generated styles.\n */\nexport function getCSSRules(\n\tstyle: Style,\n\toptions: StyleOptions = {}\n): GeneratedCSSRule[] {\n\tconst rules: GeneratedCSSRule[] = [];\n\tstyleDefinitions.forEach( ( definition: StyleDefinition ) => {\n\t\tif ( typeof definition.generate === 'function' ) {\n\t\t\trules.push( ...definition.generate( style, options ) );\n\t\t}\n\t} );\n\n\treturn rules;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/index.ts"],"names":["groupBy","kebabCase","styleDefinitions","compileCSS","style","options","rules","getCSSRules","selector","inlineRules","forEach","rule","push","key","value","join","groupedRules","selectorRules","Object","keys","reduce","acc","subSelector","map","definition","generate"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,SAAlB,QAAmC,QAAnC;AAEA;AACA;AACA;;AAOA,SAASC,gBAAT,QAAiC,UAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CAAqBC,KAArB,EAAwE;AAAA,MAArCC,OAAqC,uEAAb,EAAa;AAC9E,QAAMC,KAAK,GAAGC,WAAW,CAAEH,KAAF,EAASC,OAAT,CAAzB,CAD8E,CAG9E;;AACA,MAAK,EAAEA,OAAF,aAAEA,OAAF,eAAEA,OAAO,CAAEG,QAAX,CAAL,EAA2B;AAC1B,UAAMC,WAAqB,GAAG,EAA9B;AACAH,IAAAA,KAAK,CAACI,OAAN,CAAiBC,IAAF,IAAY;AAC1BF,MAAAA,WAAW,CAACG,IAAZ,CAAmB,GAAGX,SAAS,CAAEU,IAAI,CAACE,GAAP,CAAc,KAAKF,IAAI,CAACG,KAAO,GAA9D;AACA,KAFD;AAGA,WAAOL,WAAW,CAACM,IAAZ,CAAkB,GAAlB,CAAP;AACA;;AAED,QAAMC,YAAY,GAAGhB,OAAO,CAAEM,KAAF,EAAS,UAAT,CAA5B;AACA,QAAMW,aAAa,GAAGC,MAAM,CAACC,IAAP,CAAaH,YAAb,EAA4BI,MAA5B,CACrB,CAAEC,GAAF,EAAiBC,WAAjB,KAA0C;AACzCD,IAAAA,GAAG,CAACT,IAAJ,CACE,GAAGU,WAAa,MAAMN,YAAY,CAAEM,WAAF,CAAZ,CACrBC,GADqB,CAEnBZ,IAAF,IACE,GAAGV,SAAS,CAAEU,IAAI,CAACE,GAAP,CAAc,KAAKF,IAAI,CAACG,KAAO,GAHxB,EAKrBC,IALqB,CAKf,GALe,CAKR,IANhB;AAQA,WAAOM,GAAP;AACA,GAXoB,EAYrB,EAZqB,CAAtB;AAeA,SAAOJ,aAAa,CAACF,IAAd,CAAoB,IAApB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASR,WAAT,CACNH,KADM,EAGe;AAAA,MADrBC,OACqB,uEADG,EACH;AACrB,QAAMC,KAAyB,GAAG,EAAlC;AACAJ,EAAAA,gBAAgB,CAACQ,OAAjB,CAA4Bc,UAAF,IAAmC;AAC5D,QAAK,OAAOA,UAAU,CAACC,QAAlB,KAA+B,UAApC,EAAiD;AAChDnB,MAAAA,KAAK,CAACM,IAAN,CAAY,GAAGY,UAAU,CAACC,QAAX,CAAqBrB,KAArB,EAA4BC,OAA5B,CAAf;AACA;AACD,GAJD;AAMA,SAAOC,KAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { groupBy, kebabCase } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tStyle,\n\tStyleOptions,\n\tGeneratedCSSRule,\n\tStyleDefinition,\n} from './types';\nimport { styleDefinitions } from './styles';\n\n/**\n * Generates a stylesheet for a given style object and selector.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json\n * @param options Options object with settings to adjust how the styles are generated.\n *\n * @return A generated stylesheet or inline style declarations.\n */\nexport function compileCSS( style: Style, options: StyleOptions = {} ): string {\n\tconst rules = getCSSRules( style, options );\n\n\t// If no selector is provided, treat generated rules as inline styles to be returned as a single string.\n\tif ( ! options?.selector ) {\n\t\tconst inlineRules: string[] = [];\n\t\trules.forEach( ( rule ) => {\n\t\t\tinlineRules.push( `${ kebabCase( rule.key ) }: ${ rule.value };` );\n\t\t} );\n\t\treturn inlineRules.join( ' ' );\n\t}\n\n\tconst groupedRules = groupBy( rules, 'selector' );\n\tconst selectorRules = Object.keys( groupedRules ).reduce(\n\t\t( acc: string[], subSelector: string ) => {\n\t\t\tacc.push(\n\t\t\t\t`${ subSelector } { ${ groupedRules[ subSelector ]\n\t\t\t\t\t.map(\n\t\t\t\t\t\t( rule: GeneratedCSSRule ) =>\n\t\t\t\t\t\t\t`${ kebabCase( rule.key ) }: ${ rule.value };`\n\t\t\t\t\t)\n\t\t\t\t\t.join( ' ' ) } }`\n\t\t\t);\n\t\t\treturn acc;\n\t\t},\n\t\t[]\n\t);\n\n\treturn selectorRules.join( '\\n' );\n}\n\n/**\n * Returns a JSON representation of the generated CSS rules.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json\n * @param options Options object with settings to adjust how the styles are generated.\n *\n * @return A collection of objects containing the selector, if any, the CSS property key (camelcase) and parsed CSS value.\n */\nexport function getCSSRules(\n\tstyle: Style,\n\toptions: StyleOptions = {}\n): GeneratedCSSRule[] {\n\tconst rules: GeneratedCSSRule[] = [];\n\tstyleDefinitions.forEach( ( definition: StyleDefinition ) => {\n\t\tif ( typeof definition.generate === 'function' ) {\n\t\t\trules.push( ...definition.generate( style, options ) );\n\t\t}\n\t} );\n\n\treturn rules;\n}\n"]}
@@ -5,19 +5,23 @@ import type { Style, StyleOptions, GeneratedCSSRule } from './types';
5
5
  /**
6
6
  * Generates a stylesheet for a given style object and selector.
7
7
  *
8
+ * @since 6.1.0 Introduced in WordPress core.
9
+ *
8
10
  * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
9
11
  * @param options Options object with settings to adjust how the styles are generated.
10
12
  *
11
- * @return generated stylesheet.
13
+ * @return A generated stylesheet or inline style declarations.
12
14
  */
13
15
  export declare function compileCSS(style: Style, options?: StyleOptions): string;
14
16
  /**
15
17
  * Returns a JSON representation of the generated CSS rules.
16
18
  *
19
+ * @since 6.1.0 Introduced in WordPress core.
20
+ *
17
21
  * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
18
22
  * @param options Options object with settings to adjust how the styles are generated.
19
23
  *
20
- * @return generated styles.
24
+ * @return A collection of objects containing the selector, if any, the CSS property key (camelcase) and parsed CSS value.
21
25
  */
22
26
  export declare function getCSSRules(style: Style, options?: StyleOptions): GeneratedCSSRule[];
23
27
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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,UAAU,CAAE,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,YAAiB,GAAI,MAAM,CA6B7E;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,KAAK,EACZ,OAAO,GAAE,YAAiB,GACxB,gBAAgB,EAAE,CASpB"}
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;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAE,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,YAAiB,GAAI,MAAM,CA6B7E;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,KAAK,EACZ,OAAO,GAAE,YAAiB,GACxB,gBAAgB,EAAE,CASpB"}
@@ -31,14 +31,14 @@ class WP_Style_Engine_CSS_Declarations {
31
31
  * If a `$declarations` array is passed, it will be used to populate
32
32
  * the initial $declarations prop of the object by calling add_declarations().
33
33
  *
34
- * @param array $declarations An array of declarations (property => value pairs).
34
+ * @param string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
35
35
  */
36
36
  public function __construct( $declarations = array() ) {
37
37
  $this->add_declarations( $declarations );
38
38
  }
39
39
 
40
40
  /**
41
- * Add a single declaration.
41
+ * Adds a single declaration.
42
42
  *
43
43
  * @param string $property The CSS property.
44
44
  * @param string $value The CSS value.
@@ -46,28 +46,27 @@ class WP_Style_Engine_CSS_Declarations {
46
46
  * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
47
47
  */
48
48
  public function add_declaration( $property, $value ) {
49
-
50
- // Sanitize the property.
49
+ // Sanitizes the property.
51
50
  $property = $this->sanitize_property( $property );
52
- // Bail early if the property is empty.
51
+ // Bails early if the property is empty.
53
52
  if ( empty( $property ) ) {
54
53
  return $this;
55
54
  }
56
55
 
57
- // Trim the value. If empty, bail early.
56
+ // Trims the value. If empty, bail early.
58
57
  $value = trim( $value );
59
58
  if ( '' === $value ) {
60
59
  return $this;
61
60
  }
62
61
 
63
- // Add the declaration property/value pair.
62
+ // Adds the declaration property/value pair.
64
63
  $this->declarations[ $property ] = $value;
65
64
 
66
65
  return $this;
67
66
  }
68
67
 
69
68
  /**
70
- * Remove a single declaration.
69
+ * Removes a single declaration.
71
70
  *
72
71
  * @param string $property The CSS property.
73
72
  *
@@ -79,7 +78,7 @@ class WP_Style_Engine_CSS_Declarations {
79
78
  }
80
79
 
81
80
  /**
82
- * Add multiple declarations.
81
+ * Adds multiple declarations.
83
82
  *
84
83
  * @param array $declarations An array of declarations.
85
84
  *
@@ -93,7 +92,7 @@ class WP_Style_Engine_CSS_Declarations {
93
92
  }
94
93
 
95
94
  /**
96
- * Remove multiple declarations.
95
+ * Removes multiple declarations.
97
96
  *
98
97
  * @param array $properties An array of properties.
99
98
  *
@@ -107,7 +106,7 @@ class WP_Style_Engine_CSS_Declarations {
107
106
  }
108
107
 
109
108
  /**
110
- * Get the declarations array.
109
+ * Gets the declarations array.
111
110
  *
112
111
  * @return array
113
112
  */
@@ -122,7 +121,7 @@ class WP_Style_Engine_CSS_Declarations {
122
121
  * @param string $value The value to be filtered.
123
122
  * @param string $spacer The spacer between the colon and the value. Defaults to an empty string.
124
123
  *
125
- * @return string The filtered declaration as a single string.
124
+ * @return string The filtered declaration or an empty string.
126
125
  */
127
126
  protected static function filter_declaration( $property, $value, $spacer = '' ) {
128
127
  $filtered_value = wp_strip_all_tags( $value, true );
@@ -135,8 +134,8 @@ class WP_Style_Engine_CSS_Declarations {
135
134
  /**
136
135
  * Filters and compiles the CSS declarations.
137
136
  *
138
- * @param boolean $should_prettify Whether to add spacing, new lines and indents.
139
- * @param number $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`.
137
+ * @param bool $should_prettify Whether to add spacing, new lines and indents.
138
+ * @param number $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`.
140
139
  *
141
140
  * @return string The CSS declarations.
142
141
  */
@@ -158,7 +157,7 @@ class WP_Style_Engine_CSS_Declarations {
158
157
  }
159
158
 
160
159
  /**
161
- * Sanitize property names.
160
+ * Sanitizes property names.
162
161
  *
163
162
  * @param string $property The CSS property.
164
163
  *
@@ -37,9 +37,9 @@ class WP_Style_Engine_CSS_Rule {
37
37
  /**
38
38
  * Constructor
39
39
  *
40
- * @param string $selector The CSS selector.
41
- * @param array|WP_Style_Engine_CSS_Declarations $declarations An array of declarations (property => value pairs),
42
- * or a WP_Style_Engine_CSS_Declarations object.
40
+ * @param string $selector The CSS selector.
41
+ * @param string[]|WP_Style_Engine_CSS_Declarations $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ),
42
+ * or a WP_Style_Engine_CSS_Declarations object.
43
43
  */
44
44
  public function __construct( $selector = '', $declarations = array() ) {
45
45
  $this->set_selector( $selector );
@@ -47,7 +47,7 @@ class WP_Style_Engine_CSS_Rule {
47
47
  }
48
48
 
49
49
  /**
50
- * Set the selector.
50
+ * Sets the selector.
51
51
  *
52
52
  * @param string $selector The CSS selector.
53
53
  *
@@ -59,7 +59,7 @@ class WP_Style_Engine_CSS_Rule {
59
59
  }
60
60
 
61
61
  /**
62
- * Set the declarations.
62
+ * Sets the declarations.
63
63
  *
64
64
  * @param array|WP_Style_Engine_CSS_Declarations $declarations An array of declarations (property => value pairs),
65
65
  * or a WP_Style_Engine_CSS_Declarations object.
@@ -83,16 +83,16 @@ class WP_Style_Engine_CSS_Rule {
83
83
  }
84
84
 
85
85
  /**
86
- * Get the declarations object.
86
+ * Gets the declarations object.
87
87
  *
88
- * @return WP_Style_Engine_CSS_Declarations
88
+ * @return WP_Style_Engine_CSS_Declarations The declarations object.
89
89
  */
90
90
  public function get_declarations() {
91
91
  return $this->declarations;
92
92
  }
93
93
 
94
94
  /**
95
- * Get the full selector.
95
+ * Gets the full selector.
96
96
  *
97
97
  * @return string
98
98
  */
@@ -101,18 +101,18 @@ class WP_Style_Engine_CSS_Rule {
101
101
  }
102
102
 
103
103
  /**
104
- * Get the CSS.
104
+ * Gets the CSS.
105
105
  *
106
- * @param boolean $should_prettify Whether to add spacing, new lines and indents.
107
- * @param number $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`.
106
+ * @param bool $should_prettify Whether to add spacing, new lines and indents.
107
+ * @param number $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`.
108
108
  *
109
109
  * @return string
110
110
  */
111
111
  public function get_css( $should_prettify = false, $indent_count = 0 ) {
112
112
  $rule_indent = $should_prettify ? str_repeat( "\t", $indent_count ) : '';
113
113
  $declarations_indent = $should_prettify ? $indent_count + 1 : 0;
114
- $new_line = $should_prettify ? "\n" : '';
115
- $space = $should_prettify ? ' ' : '';
114
+ $suffix = $should_prettify ? "\n" : '';
115
+ $spacer = $should_prettify ? ' ' : '';
116
116
  $selector = $should_prettify ? str_replace( ',', ",\n", $this->get_selector() ) : $this->get_selector();
117
117
  $css_declarations = $this->declarations->get_declarations_string( $should_prettify, $declarations_indent );
118
118
 
@@ -120,6 +120,6 @@ class WP_Style_Engine_CSS_Rule {
120
120
  return '';
121
121
  }
122
122
 
123
- return "{$rule_indent}{$selector}{$space}{{$new_line}{$css_declarations}{$new_line}{$rule_indent}}";
123
+ return "{$rule_indent}{$selector}{$spacer}{{$suffix}{$css_declarations}{$suffix}{$rule_indent}}";
124
124
  }
125
125
  }
@@ -42,7 +42,7 @@ class WP_Style_Engine_CSS_Rules_Store {
42
42
  protected $rules = array();
43
43
 
44
44
  /**
45
- * Get an instance of the store.
45
+ * Gets an instance of the store.
46
46
  *
47
47
  * @param string $store_name The name of the store.
48
48
  *
@@ -61,7 +61,7 @@ class WP_Style_Engine_CSS_Rules_Store {
61
61
  }
62
62
 
63
63
  /**
64
- * Get an array of all available stores.
64
+ * Gets an array of all available stores.
65
65
  *
66
66
  * @return WP_Style_Engine_CSS_Rules_Store[]
67
67
  */
@@ -79,7 +79,7 @@ class WP_Style_Engine_CSS_Rules_Store {
79
79
  }
80
80
 
81
81
  /**
82
- * Set the store name.
82
+ * Sets the store name.
83
83
  *
84
84
  * @param string $name The store name.
85
85
  *
@@ -90,7 +90,7 @@ class WP_Style_Engine_CSS_Rules_Store {
90
90
  }
91
91
 
92
92
  /**
93
- * Get the store name.
93
+ * Gets the store name.
94
94
  *
95
95
  * @return string
96
96
  */
@@ -99,7 +99,7 @@ class WP_Style_Engine_CSS_Rules_Store {
99
99
  }
100
100
 
101
101
  /**
102
- * Get an array of all rules.
102
+ * Gets an array of all rules.
103
103
  *
104
104
  * @return WP_Style_Engine_CSS_Rule[]
105
105
  */
@@ -108,7 +108,7 @@ class WP_Style_Engine_CSS_Rules_Store {
108
108
  }
109
109
 
110
110
  /**
111
- * Get a WP_Style_Engine_CSS_Rule object by its selector.
111
+ * Gets a WP_Style_Engine_CSS_Rule object by its selector.
112
112
  * If the rule does not exist, it will be created.
113
113
  *
114
114
  * @param string $selector The CSS selector.
@@ -132,7 +132,7 @@ class WP_Style_Engine_CSS_Rules_Store {
132
132
  }
133
133
 
134
134
  /**
135
- * Remove a selector from the store.
135
+ * Removes a selector from the store.
136
136
  *
137
137
  * @param string $selector The CSS selector.
138
138
  *
@@ -19,7 +19,7 @@ if ( class_exists( 'WP_Style_Engine_Processor' ) ) {
19
19
  class WP_Style_Engine_Processor {
20
20
 
21
21
  /**
22
- * The Style-Engine Store objects
22
+ * A collection of Style Engine Store objects.
23
23
  *
24
24
  * @var WP_Style_Engine_CSS_Rules_Store[]
25
25
  */
@@ -39,7 +39,16 @@ class WP_Style_Engine_Processor {
39
39
  *
40
40
  * @return WP_Style_Engine_Processor Returns the object to allow chaining methods.
41
41
  */
42
- public function add_store( WP_Style_Engine_CSS_Rules_Store $store ) {
42
+ public function add_store( $store ) {
43
+ if ( ! $store instanceof WP_Style_Engine_CSS_Rules_Store ) {
44
+ _doing_it_wrong(
45
+ __METHOD__,
46
+ __( '$store must be an instance of WP_Style_Engine_CSS_Rules_Store', 'default' ),
47
+ '6.1.0'
48
+ );
49
+ return $this;
50
+ }
51
+
43
52
  $this->stores[ $store->get_name() ] = $store;
44
53
 
45
54
  return $this;
@@ -56,6 +65,7 @@ class WP_Style_Engine_Processor {
56
65
  if ( ! is_array( $css_rules ) ) {
57
66
  $css_rules = array( $css_rules );
58
67
  }
68
+
59
69
  foreach ( $css_rules as $rule ) {
60
70
  $selector = $rule->get_selector();
61
71
  if ( isset( $this->css_rules[ $selector ] ) ) {
@@ -71,10 +81,12 @@ class WP_Style_Engine_Processor {
71
81
  /**
72
82
  * Get the CSS rules as a string.
73
83
  *
74
- * @param array $options array(
75
- * 'optimize' => (boolean) Whether to optimize the CSS output, e.g., combine rules.
76
- * 'prettify' => (boolean) Whether to add new lines to output.
77
- * );.
84
+ * @param array $options {
85
+ * Optional. An array of options. Default empty array.
86
+ *
87
+ * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
88
+ * @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined.
89
+ * }
78
90
  *
79
91
  * @return string The computed CSS.
80
92
  */