@wordpress/style-engine 0.15.1-next.957ca95e4c.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +18 -30
  2. package/README.md +36 -32
  3. package/build/index.js +6 -2
  4. package/build/index.js.map +1 -1
  5. package/build/styles/index.js +3 -1
  6. package/build/styles/index.js.map +1 -1
  7. package/build/styles/outline/index.js +47 -0
  8. package/build/styles/outline/index.js.map +1 -0
  9. package/build-module/index.js +6 -2
  10. package/build-module/index.js.map +1 -1
  11. package/build-module/styles/index.js +2 -1
  12. package/build-module/styles/index.js.map +1 -1
  13. package/build-module/styles/outline/index.js +38 -0
  14. package/build-module/styles/outline/index.js.map +1 -0
  15. package/build-types/index.d.ts +6 -2
  16. package/build-types/index.d.ts.map +1 -1
  17. package/build-types/styles/index.d.ts +1 -1
  18. package/build-types/styles/index.d.ts.map +1 -1
  19. package/build-types/styles/outline/index.d.ts +10 -0
  20. package/build-types/styles/outline/index.d.ts.map +1 -0
  21. package/class-wp-style-engine-css-declarations.php +14 -15
  22. package/class-wp-style-engine-css-rule.php +14 -14
  23. package/class-wp-style-engine-css-rules-store.php +7 -7
  24. package/class-wp-style-engine-processor.php +18 -6
  25. package/class-wp-style-engine.php +82 -185
  26. package/docs/using-the-style-engine-with-block-supports.md +151 -0
  27. package/package.json +4 -3
  28. package/phpunit/class-wp-style-engine-css-declarations-test.php +142 -95
  29. package/phpunit/class-wp-style-engine-css-rule-test.php +50 -21
  30. package/phpunit/class-wp-style-engine-css-rules-store-test.php +75 -58
  31. package/phpunit/class-wp-style-engine-processor-test.php +85 -37
  32. package/phpunit/{class-wp-style-engine-test.php → style-engine-test.php} +76 -50
  33. package/src/index.ts +6 -2
  34. package/src/styles/index.ts +2 -0
  35. package/src/styles/outline/index.ts +55 -0
  36. package/style-engine.php +154 -0
  37. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -2,34 +2,22 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- ## 0.15.0 (2022-08-24)
6
-
7
- ## 0.14.0 (2022-08-10)
8
-
9
- ## 0.13.0 (2022-07-27)
10
-
11
- ## 0.12.0 (2022-07-13)
12
-
13
- ## 0.11.0 (2022-06-29)
14
-
15
- ## 0.10.0 (2022-06-15)
16
-
17
- ## 0.9.0 (2022-06-01)
18
-
19
- ## 0.8.0 (2022-05-18)
20
-
21
- ## 0.7.0 (2022-05-04)
22
-
23
- ## 0.6.0 (2022-04-21)
24
-
25
- ## 0.5.0 (2022-04-08)
26
-
27
- ## 0.4.0 (2022-03-23)
28
-
29
- ## 0.3.0 (2022-03-11)
30
-
31
- ## 0.2.0 (2022-02-23)
32
-
33
- ### New Feature
34
-
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)).
35
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,12 +129,12 @@ $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
- ### wp_style_engine_get_stylesheet_from_store()
135
+ ### wp_style_engine_get_stylesheet_from_context()
139
136
 
140
- Returns compiled CSS from a store, if found.
137
+ Returns compiled CSS from a stored context, if found.
141
138
 
142
139
  _Parameters_
143
140
 
@@ -167,8 +164,8 @@ $stylesheet = wp_style_engine_get_stylesheet_from_css_rules(
167
164
  )
168
165
  );
169
166
 
170
- // Later, fetch compiled rules from store.
171
- $stylesheet = gutenberg_style_engine_get_stylesheet_from_store( 'fruit-styles' );
167
+ // Later, fetch compiled rules from context store.
168
+ $stylesheet = gutenberg_style_engine_get_stylesheet_from_context( 'fruit-styles' );
172
169
  print_r( $stylesheet ); // .wp-apple{color:green;}
173
170
  if ( ! empty( $stylesheet ) ) {
174
171
  wp_register_style( 'my-stylesheet', false, array(), true, true );
@@ -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
 
@@ -229,6 +231,8 @@ A guide to the terms and variable names referenced by the Style Engine package.
229
231
  <dl>
230
232
  <dt>Block style (Gutenberg internal)</dt>
231
233
  <dd>An object comprising a block's style attribute that contains a block's style values. E.g., <code>{ spacing: { margin: '10px' }, color: { ... }, ... }</code></dd>
234
+ <dt>Context</dt>
235
+ <dd>An identifier for a group of styles that share a common origin or purpose, e.g., 'block-supports' or 'global-styles'. The context is also used as a key to fetch CSS rules from the store.</dd>
232
236
  <dt>CSS declaration or (CSS property declaration)</dt>
233
237
  <dd>A CSS property paired with a CSS value. E.g., <code>color: pink</code> </dd>
234
238
  <dt>CSS declarations block</dt>
@@ -237,8 +241,8 @@ A guide to the terms and variable names referenced by the Style Engine package.
237
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>
238
242
  <dt>CSS rule</dt>
239
243
  <dd>A CSS selector followed by a CSS declarations block inside a set of curly braces. Usually found in a CSS stylesheet.</dd>
240
- <dt>CSS selector</dt>
241
- <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>
242
246
  <dt>CSS stylesheet</dt>
243
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>
244
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"]}
@@ -13,6 +13,8 @@ var _color = _interopRequireDefault(require("./color"));
13
13
 
14
14
  var _shadow = _interopRequireDefault(require("./shadow"));
15
15
 
16
+ var _outline = _interopRequireDefault(require("./outline"));
17
+
16
18
  var _spacing = _interopRequireDefault(require("./spacing"));
17
19
 
18
20
  var _typography = _interopRequireDefault(require("./typography"));
@@ -20,6 +22,6 @@ var _typography = _interopRequireDefault(require("./typography"));
20
22
  /**
21
23
  * Internal dependencies
22
24
  */
23
- const styleDefinitions = [..._border.default, ..._color.default, ..._spacing.default, ..._typography.default, ..._shadow.default];
25
+ const styleDefinitions = [..._border.default, ..._color.default, ..._outline.default, ..._spacing.default, ..._typography.default, ..._shadow.default];
24
26
  exports.styleDefinitions = styleDefinitions;
25
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/styles/index.ts"],"names":["styleDefinitions","border","color","spacing","typography","shadow"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAPA;AACA;AACA;AAOO,MAAMA,gBAAgB,GAAG,CAC/B,GAAGC,eAD4B,EAE/B,GAAGC,cAF4B,EAG/B,GAAGC,gBAH4B,EAI/B,GAAGC,mBAJ4B,EAK/B,GAAGC,eAL4B,CAAzB","sourcesContent":["/**\n * Internal dependencies\n */\nimport border from './border';\nimport color from './color';\nimport shadow from './shadow';\nimport spacing from './spacing';\nimport typography from './typography';\n\nexport const styleDefinitions = [\n\t...border,\n\t...color,\n\t...spacing,\n\t...typography,\n\t...shadow,\n];\n"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/index.ts"],"names":["styleDefinitions","border","color","outline","spacing","typography","shadow"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AARA;AACA;AACA;AAQO,MAAMA,gBAAgB,GAAG,CAC/B,GAAGC,eAD4B,EAE/B,GAAGC,cAF4B,EAG/B,GAAGC,gBAH4B,EAI/B,GAAGC,gBAJ4B,EAK/B,GAAGC,mBAL4B,EAM/B,GAAGC,eAN4B,CAAzB","sourcesContent":["/**\n * Internal dependencies\n */\nimport border from './border';\nimport color from './color';\nimport shadow from './shadow';\nimport outline from './outline';\nimport spacing from './spacing';\nimport typography from './typography';\n\nexport const styleDefinitions = [\n\t...border,\n\t...color,\n\t...outline,\n\t...spacing,\n\t...typography,\n\t...shadow,\n];\n"]}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _utils = require("../utils");
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ const color = {
14
+ name: 'color',
15
+ generate: function (style, options) {
16
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'color'];
17
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineColor';
18
+ return (0, _utils.generateRule)(style, options, path, ruleKey);
19
+ }
20
+ };
21
+ const offset = {
22
+ name: 'offset',
23
+ generate: function (style, options) {
24
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'offset'];
25
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineColor';
26
+ return (0, _utils.generateRule)(style, options, path, ruleKey);
27
+ }
28
+ };
29
+ const outlineStyle = {
30
+ name: 'style',
31
+ generate: function (style, options) {
32
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'style'];
33
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineStyle';
34
+ return (0, _utils.generateRule)(style, options, path, ruleKey);
35
+ }
36
+ };
37
+ const width = {
38
+ name: 'width',
39
+ generate: function (style, options) {
40
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'width'];
41
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineWidth';
42
+ return (0, _utils.generateRule)(style, options, path, ruleKey);
43
+ }
44
+ };
45
+ var _default = [color, outlineStyle, offset, width];
46
+ exports.default = _default;
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/outline/index.ts"],"names":["color","name","generate","style","options","path","ruleKey","offset","outlineStyle","width"],"mappings":";;;;;;;AAIA;;AAJA;AACA;AACA;AAIA,MAAMA,KAAK,GAAG;AACbC,EAAAA,IAAI,EAAE,OADO;AAEbC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,SAAF,EAAa,OAAb,CAEO;AAAA,QADxBC,OACwB,uEADN,cACM;AACxB,WAAO,yBAAcH,KAAd,EAAqBC,OAArB,EAA8BC,IAA9B,EAAoCC,OAApC,CAAP;AACA;AATY,CAAd;AAYA,MAAMC,MAAM,GAAG;AACdN,EAAAA,IAAI,EAAE,QADQ;AAEdC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,SAAF,EAAa,QAAb,CAEO;AAAA,QADxBC,OACwB,uEADN,cACM;AACxB,WAAO,yBAAcH,KAAd,EAAqBC,OAArB,EAA8BC,IAA9B,EAAoCC,OAApC,CAAP;AACA;AATa,CAAf;AAYA,MAAME,YAAY,GAAG;AACpBP,EAAAA,IAAI,EAAE,OADc;AAEpBC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,SAAF,EAAa,OAAb,CAEO;AAAA,QADxBC,OACwB,uEADN,cACM;AACxB,WAAO,yBAAcH,KAAd,EAAqBC,OAArB,EAA8BC,IAA9B,EAAoCC,OAApC,CAAP;AACA;AATmB,CAArB;AAYA,MAAMG,KAAK,GAAG;AACbR,EAAAA,IAAI,EAAE,OADO;AAEbC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,SAAF,EAAa,OAAb,CAEO;AAAA,QADxBC,OACwB,uEADN,cACM;AACxB,WAAO,yBAAcH,KAAd,EAAqBC,OAArB,EAA8BC,IAA9B,EAAoCC,OAApC,CAAP;AACA;AATY,CAAd;eAYe,CAAEN,KAAF,EAASQ,YAAT,EAAuBD,MAAvB,EAA+BE,KAA/B,C","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { GeneratedCSSRule, Style, StyleOptions } from '../../types';\nimport { generateRule } from '../utils';\n\nconst color = {\n\tname: 'color',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'outline', 'color' ],\n\t\truleKey: string = 'outlineColor'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nconst offset = {\n\tname: 'offset',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'outline', 'offset' ],\n\t\truleKey: string = 'outlineColor'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nconst outlineStyle = {\n\tname: 'style',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'outline', 'style' ],\n\t\truleKey: string = 'outlineStyle'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nconst width = {\n\tname: 'width',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'outline', 'width' ],\n\t\truleKey: string = 'outlineWidth'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nexport default [ color, outlineStyle, offset, width ];\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"]}
@@ -4,7 +4,8 @@
4
4
  import border from './border';
5
5
  import color from './color';
6
6
  import shadow from './shadow';
7
+ import outline from './outline';
7
8
  import spacing from './spacing';
8
9
  import typography from './typography';
9
- export const styleDefinitions = [...border, ...color, ...spacing, ...typography, ...shadow];
10
+ export const styleDefinitions = [...border, ...color, ...outline, ...spacing, ...typography, ...shadow];
10
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/styles/index.ts"],"names":["border","color","shadow","spacing","typography","styleDefinitions"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAP,MAAmB,UAAnB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AAEA,OAAO,MAAMC,gBAAgB,GAAG,CAC/B,GAAGL,MAD4B,EAE/B,GAAGC,KAF4B,EAG/B,GAAGE,OAH4B,EAI/B,GAAGC,UAJ4B,EAK/B,GAAGF,MAL4B,CAAzB","sourcesContent":["/**\n * Internal dependencies\n */\nimport border from './border';\nimport color from './color';\nimport shadow from './shadow';\nimport spacing from './spacing';\nimport typography from './typography';\n\nexport const styleDefinitions = [\n\t...border,\n\t...color,\n\t...spacing,\n\t...typography,\n\t...shadow,\n];\n"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/index.ts"],"names":["border","color","shadow","outline","spacing","typography","styleDefinitions"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAP,MAAmB,UAAnB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AAEA,OAAO,MAAMC,gBAAgB,GAAG,CAC/B,GAAGN,MAD4B,EAE/B,GAAGC,KAF4B,EAG/B,GAAGE,OAH4B,EAI/B,GAAGC,OAJ4B,EAK/B,GAAGC,UAL4B,EAM/B,GAAGH,MAN4B,CAAzB","sourcesContent":["/**\n * Internal dependencies\n */\nimport border from './border';\nimport color from './color';\nimport shadow from './shadow';\nimport outline from './outline';\nimport spacing from './spacing';\nimport typography from './typography';\n\nexport const styleDefinitions = [\n\t...border,\n\t...color,\n\t...outline,\n\t...spacing,\n\t...typography,\n\t...shadow,\n];\n"]}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { generateRule } from '../utils';
5
+ const color = {
6
+ name: 'color',
7
+ generate: function (style, options) {
8
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'color'];
9
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineColor';
10
+ return generateRule(style, options, path, ruleKey);
11
+ }
12
+ };
13
+ const offset = {
14
+ name: 'offset',
15
+ generate: function (style, options) {
16
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'offset'];
17
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineColor';
18
+ return generateRule(style, options, path, ruleKey);
19
+ }
20
+ };
21
+ const outlineStyle = {
22
+ name: 'style',
23
+ generate: function (style, options) {
24
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'style'];
25
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineStyle';
26
+ return generateRule(style, options, path, ruleKey);
27
+ }
28
+ };
29
+ const width = {
30
+ name: 'width',
31
+ generate: function (style, options) {
32
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['outline', 'width'];
33
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'outlineWidth';
34
+ return generateRule(style, options, path, ruleKey);
35
+ }
36
+ };
37
+ export default [color, outlineStyle, offset, width];
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/outline/index.ts"],"names":["generateRule","color","name","generate","style","options","path","ruleKey","offset","outlineStyle","width"],"mappings":"AAAA;AACA;AACA;AAEA,SAASA,YAAT,QAA6B,UAA7B;AAEA,MAAMC,KAAK,GAAG;AACbC,EAAAA,IAAI,EAAE,OADO;AAEbC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,SAAF,EAAa,OAAb,CAEO;AAAA,QADxBC,OACwB,uEADN,cACM;AACxB,WAAOP,YAAY,CAAEI,KAAF,EAASC,OAAT,EAAkBC,IAAlB,EAAwBC,OAAxB,CAAnB;AACA;AATY,CAAd;AAYA,MAAMC,MAAM,GAAG;AACdN,EAAAA,IAAI,EAAE,QADQ;AAEdC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,SAAF,EAAa,QAAb,CAEO;AAAA,QADxBC,OACwB,uEADN,cACM;AACxB,WAAOP,YAAY,CAAEI,KAAF,EAASC,OAAT,EAAkBC,IAAlB,EAAwBC,OAAxB,CAAnB;AACA;AATa,CAAf;AAYA,MAAME,YAAY,GAAG;AACpBP,EAAAA,IAAI,EAAE,OADc;AAEpBC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,SAAF,EAAa,OAAb,CAEO;AAAA,QADxBC,OACwB,uEADN,cACM;AACxB,WAAOP,YAAY,CAAEI,KAAF,EAASC,OAAT,EAAkBC,IAAlB,EAAwBC,OAAxB,CAAnB;AACA;AATmB,CAArB;AAYA,MAAMG,KAAK,GAAG;AACbR,EAAAA,IAAI,EAAE,OADO;AAEbC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,SAAF,EAAa,OAAb,CAEO;AAAA,QADxBC,OACwB,uEADN,cACM;AACxB,WAAOP,YAAY,CAAEI,KAAF,EAASC,OAAT,EAAkBC,IAAlB,EAAwBC,OAAxB,CAAnB;AACA;AATY,CAAd;AAYA,eAAe,CAAEN,KAAF,EAASQ,YAAT,EAAuBD,MAAvB,EAA+BE,KAA/B,CAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { GeneratedCSSRule, Style, StyleOptions } from '../../types';\nimport { generateRule } from '../utils';\n\nconst color = {\n\tname: 'color',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'outline', 'color' ],\n\t\truleKey: string = 'outlineColor'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nconst offset = {\n\tname: 'offset',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'outline', 'offset' ],\n\t\truleKey: string = 'outlineColor'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nconst outlineStyle = {\n\tname: 'style',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'outline', 'style' ],\n\t\truleKey: string = 'outlineStyle'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nconst width = {\n\tname: 'width',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'outline', 'width' ],\n\t\truleKey: string = 'outlineWidth'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nexport default [ color, outlineStyle, offset, width ];\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"}
@@ -1,5 +1,5 @@
1
1
  export declare const styleDefinitions: (import("../types").StyleDefinition | {
2
2
  name: string;
3
- generate: (style: import("../types").Style, options: import("../types").StyleOptions) => import("../types").GeneratedCSSRule[];
3
+ generate: (style: import("../types").Style, options: import("../types").StyleOptions, path?: string[], ruleKey?: string) => import("../types").GeneratedCSSRule[];
4
4
  })[];
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,gBAAgB;;;IAM5B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,gBAAgB;;;IAO5B,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { GeneratedCSSRule, Style, StyleOptions } from '../../types';
5
+ declare const _default: {
6
+ name: string;
7
+ generate: (style: Style, options: StyleOptions, path?: string[], ruleKey?: string) => GeneratedCSSRule[];
8
+ }[];
9
+ export default _default;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/outline/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;;;;;AAmDzE,wBAAsD"}
@@ -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
  *