@wordpress/style-engine 0.10.0 → 0.13.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 (52) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +34 -2
  3. package/build/styles/border/index.js +94 -0
  4. package/build/styles/border/index.js.map +1 -0
  5. package/build/styles/index.js +3 -1
  6. package/build/styles/index.js.map +1 -1
  7. package/build/styles/spacing/margin.js +4 -1
  8. package/build/styles/spacing/margin.js.map +1 -1
  9. package/build/styles/spacing/padding.js +4 -1
  10. package/build/styles/spacing/padding.js.map +1 -1
  11. package/build/styles/utils.js +26 -10
  12. package/build/styles/utils.js.map +1 -1
  13. package/build-module/styles/border/index.js +85 -0
  14. package/build-module/styles/border/index.js.map +1 -0
  15. package/build-module/styles/index.js +2 -1
  16. package/build-module/styles/index.js.map +1 -1
  17. package/build-module/styles/spacing/margin.js +4 -1
  18. package/build-module/styles/spacing/margin.js.map +1 -1
  19. package/build-module/styles/spacing/padding.js +4 -1
  20. package/build-module/styles/spacing/padding.js.map +1 -1
  21. package/build-module/styles/utils.js +25 -11
  22. package/build-module/styles/utils.js.map +1 -1
  23. package/build-types/styles/border/index.d.ts +10 -0
  24. package/build-types/styles/border/index.d.ts.map +1 -0
  25. package/build-types/styles/index.d.ts +3 -7
  26. package/build-types/styles/index.d.ts.map +1 -1
  27. package/build-types/styles/spacing/margin.d.ts.map +1 -1
  28. package/build-types/styles/spacing/padding.d.ts.map +1 -1
  29. package/build-types/styles/utils.d.ts +16 -7
  30. package/build-types/styles/utils.d.ts.map +1 -1
  31. package/build-types/types.d.ts +26 -1
  32. package/build-types/types.d.ts.map +1 -1
  33. package/class-wp-style-engine-css-declarations.php +143 -0
  34. package/class-wp-style-engine-css-rule.php +115 -0
  35. package/class-wp-style-engine-css-rules-store.php +94 -0
  36. package/class-wp-style-engine-processor.php +93 -0
  37. package/class-wp-style-engine.php +109 -99
  38. package/package.json +2 -2
  39. package/phpunit/class-wp-style-engine-css-declarations-test.php +154 -0
  40. package/phpunit/class-wp-style-engine-css-rule-test.php +96 -0
  41. package/phpunit/class-wp-style-engine-css-rules-store-test.php +115 -0
  42. package/phpunit/class-wp-style-engine-processor-test.php +127 -0
  43. package/phpunit/class-wp-style-engine-test.php +159 -23
  44. package/src/styles/border/index.ts +145 -0
  45. package/src/styles/index.ts +7 -1
  46. package/src/styles/spacing/margin.ts +4 -6
  47. package/src/styles/spacing/padding.ts +4 -6
  48. package/src/styles/utils.ts +36 -12
  49. package/src/test/index.js +92 -2
  50. package/src/test/utils.js +12 -0
  51. package/src/types.ts +33 -1
  52. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.13.0 (2022-07-27)
6
+
7
+ ## 0.12.0 (2022-07-13)
8
+
9
+ ## 0.11.0 (2022-06-29)
10
+
5
11
  ## 0.10.0 (2022-06-15)
6
12
 
7
13
  ## 0.9.0 (2022-06-01)
package/README.md CHANGED
@@ -16,17 +16,49 @@ _This package assumes that your code will run in an **ES2015+** environment. If
16
16
 
17
17
  This Package is considered experimental at the moment. The idea is to have a package used to generate styles based on a style object that is consistent between: backend, frontend, block style object and theme.json.
18
18
 
19
- Currently it's not a package that generates a wp.styleEngine global because it's not ready yet, it's still a bundled package but ultimately, we want it to be so, once the roadmap is finished:
19
+ Because this package is experimental and still in development it does not yet generate a `wp.styleEngine` global. To get there, the following tasks need to be completed:
20
20
 
21
21
  **TODO List:**
22
22
 
23
23
  - Add style definitions for all the currently supported styles in blocks and theme.json.
24
- - the CSS variable shortcuts for values (for presets...)
24
+ - The CSS variable shortcuts for values (for presets...)
25
25
  - Support generating styles in the frontend. (Ongoing)
26
26
  - Support generating styles in the backend (block supports and theme.json stylesheet). (Ongoing)
27
27
  - Refactor all block styles to use the style engine server side. (Ongoing)
28
+ - Consolidate global and block style rendering and enqueuing
28
29
  - Refactor all blocks to consistently use the "style" attribute for all customizations (get rid of the preset specific attributes).
29
30
 
31
+ See [Tracking: Add a Style Engine to manage rendering block styles #38167](https://github.com/WordPress/gutenberg/issues/38167)
32
+
33
+ ## Glossary
34
+
35
+ A guide to the terms and variable names referenced by the Style Engine package.
36
+
37
+ <dl>
38
+ <dt>Block style (Gutenberg internal)</dt>
39
+ <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>
40
+ <dt>Global styles (Gutenberg internal)</dt>
41
+ <dd>A merged block styles object containing values from a theme's theme.json and user styles settings.</dd>
42
+ <dt>CSS declaration or (CSS property declaration)</dt>
43
+ <dd>A CSS property paired with a CSS value. E.g., <code>color: pink</code> </dd>
44
+ <dt>CSS declarations block</dt>
45
+ <dd>A set of CSS declarations usually paired with a CSS selector to create a CSS rule.</dd>
46
+ <dt>CSS property</dt>
47
+ <dd>Identifiers that describe stylistic, modifiable features of an HTML element. E.g., <code>border</code>, <code>font-size</code>, <code>width</code>...</dd>
48
+ <dt>CSS rule</dt>
49
+ <dd>A CSS selector followed by a CSS declarations block inside a set of curly braces. Usually found in a CSS stylesheet.</dd>
50
+ <dt>CSS selector</dt>
51
+ <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>
52
+ <dt>CSS stylesheet</dt>
53
+ <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>
54
+ <dt>CSS value</dt>
55
+ <dd>The value of a CSS property. The value determines how the property is modified. E.g., the <code>10vw</code> in <code>height: 10vw</code>.</dd>
56
+ <dt>CSS variables (vars) or CSS custom properties</dt>
57
+ <dd>Properties, whose values can be reused in other CSS declarations. Set using custom property notation (e.g., <code>--wp--preset--olive: #808000;</code>) and accessed using the <code>var()</code> function (e.g., <code>color: var( --wp--preset--olive );</code>). See <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties" target="_blank">MDN article on CSS custom properties</a>.</dd>
58
+ <dt>Inline styles</dt>
59
+ <dd>Inline styles are CSS declarations that affect a single HTML element, contained within a style attribute</dd>
60
+ </dl>
61
+
30
62
  ## Usage
31
63
 
32
64
  <!-- START TOKEN(Autogenerated API docs) -->
@@ -0,0 +1,94 @@
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] : ['border', 'color'];
17
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'borderColor';
18
+ return (0, _utils.generateRule)(style, options, path, ruleKey);
19
+ }
20
+ };
21
+ const radius = {
22
+ name: 'radius',
23
+ generate: (style, options) => {
24
+ return (0, _utils.generateBoxRules)(style, options, ['border', 'radius'], {
25
+ default: 'borderRadius',
26
+ individual: 'border%sRadius'
27
+ }, ['topLeft', 'topRight', 'bottomLeft', 'bottomRight']);
28
+ }
29
+ };
30
+ const borderStyle = {
31
+ name: 'style',
32
+ generate: function (style, options) {
33
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['border', 'style'];
34
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'borderStyle';
35
+ return (0, _utils.generateRule)(style, options, path, ruleKey);
36
+ }
37
+ };
38
+ const width = {
39
+ name: 'width',
40
+ generate: function (style, options) {
41
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['border', 'width'];
42
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'borderWidth';
43
+ return (0, _utils.generateRule)(style, options, path, ruleKey);
44
+ }
45
+ };
46
+ const borderDefinitionsWithIndividualStyles = [color, borderStyle, width];
47
+ /**
48
+ * Returns a curried generator function with the individual border property ('top' | 'right' | 'bottom' | 'left') baked in.
49
+ *
50
+ * @param individualProperty Individual border property ('top' | 'right' | 'bottom' | 'left').
51
+ *
52
+ * @return StyleDefinition[ 'generate' ]
53
+ */
54
+
55
+ const createBorderGenerateFunction = individualProperty => (style, options) => {
56
+ var _style$border;
57
+
58
+ const styleValue = style === null || style === void 0 ? void 0 : (_style$border = style.border) === null || _style$border === void 0 ? void 0 : _style$border[individualProperty];
59
+
60
+ if (!styleValue) {
61
+ return [];
62
+ }
63
+
64
+ return borderDefinitionsWithIndividualStyles.reduce((acc, borderDefinition) => {
65
+ const key = borderDefinition.name;
66
+
67
+ if (styleValue.hasOwnProperty(key) && typeof borderDefinition.generate === 'function') {
68
+ const ruleKey = `border${(0, _utils.upperFirst)(individualProperty)}${(0, _utils.upperFirst)(key)}`;
69
+ acc.push(...borderDefinition.generate(style, options, ['border', individualProperty, key], ruleKey));
70
+ }
71
+
72
+ return acc;
73
+ }, []);
74
+ };
75
+
76
+ const borderTop = {
77
+ name: 'borderTop',
78
+ generate: createBorderGenerateFunction('top')
79
+ };
80
+ const borderRight = {
81
+ name: 'borderRight',
82
+ generate: createBorderGenerateFunction('right')
83
+ };
84
+ const borderBottom = {
85
+ name: 'borderBottom',
86
+ generate: createBorderGenerateFunction('bottom')
87
+ };
88
+ const borderLeft = {
89
+ name: 'borderLeft',
90
+ generate: createBorderGenerateFunction('left')
91
+ };
92
+ var _default = [...borderDefinitionsWithIndividualStyles, radius, borderTop, borderRight, borderBottom, borderLeft];
93
+ exports.default = _default;
94
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/border/index.ts"],"names":["color","name","generate","style","options","path","ruleKey","radius","default","individual","borderStyle","width","borderDefinitionsWithIndividualStyles","createBorderGenerateFunction","individualProperty","styleValue","border","reduce","acc","borderDefinition","key","hasOwnProperty","push","borderTop","borderRight","borderBottom","borderLeft"],"mappings":";;;;;;;AAWA;;AAXA;AACA;AACA;AAWA,MAAMA,KAAK,GAAG;AACbC,EAAAA,IAAI,EAAE,OADO;AAEbC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,QAAF,EAAY,OAAZ,CAEO;AAAA,QADxBC,OACwB,uEADN,aACM;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,CAAEC,KAAF,EAAgBC,OAAhB,KAA+D;AACxE,WAAO,6BACND,KADM,EAENC,OAFM,EAGN,CAAE,QAAF,EAAY,QAAZ,CAHM,EAIN;AACCI,MAAAA,OAAO,EAAE,cADV;AAECC,MAAAA,UAAU,EAAE;AAFb,KAJM,EAQN,CAAE,SAAF,EAAa,UAAb,EAAyB,YAAzB,EAAuC,aAAvC,CARM,CAAP;AAUA;AAba,CAAf;AAgBA,MAAMC,WAAW,GAAG;AACnBT,EAAAA,IAAI,EAAE,OADa;AAEnBC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,QAAF,EAAY,OAAZ,CAEO;AAAA,QADxBC,OACwB,uEADN,aACM;AACxB,WAAO,yBAAcH,KAAd,EAAqBC,OAArB,EAA8BC,IAA9B,EAAoCC,OAApC,CAAP;AACA;AATkB,CAApB;AAYA,MAAMK,KAAK,GAAG;AACbV,EAAAA,IAAI,EAAE,OADO;AAEbC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,QAA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E,aADa;AAEnBC,EAAAA,QAAQ,EAAEW,4BAA4B,CAAE,OAAF;AAFnB,CAApB;AAKA,MAAMY,YAAY,GAAG;AACpBxB,EAAAA,IAAI,EAAE,cADc;AAEpBC,EAAAA,QAAQ,EAAEW,4BAA4B,CAAE,QAAF;AAFlB,CAArB;AAKA,MAAMa,UAAU,GAAG;AAClBzB,EAAAA,IAAI,EAAE,YADY;AAElBC,EAAAA,QAAQ,EAAEW,4BAA4B,CAAE,MAAF;AAFpB,CAAnB;eAKe,CACd,GAAGD,qCADW,EAEdL,MAFc,EAGdgB,SAHc,EAIdC,WAJc,EAKdC,YALc,EAMdC,UANc,C","sourcesContent":["/**\n * Internal dependencies\n */\nimport type {\n\tBorderIndividualStyles,\n\tBorderIndividualProperty,\n\tGeneratedCSSRule,\n\tStyle,\n\tStyleDefinition,\n\tStyleOptions,\n} from '../../types';\nimport { generateRule, generateBoxRules, upperFirst } from '../utils';\n\nconst color = {\n\tname: 'color',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'border', 'color' ],\n\t\truleKey: string = 'borderColor'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nconst radius = {\n\tname: 'radius',\n\tgenerate: ( style: Style, options: StyleOptions ): GeneratedCSSRule[] => {\n\t\treturn generateBoxRules(\n\t\t\tstyle,\n\t\t\toptions,\n\t\t\t[ 'border', 'radius' ],\n\t\t\t{\n\t\t\t\tdefault: 'borderRadius',\n\t\t\t\tindividual: 'border%sRadius',\n\t\t\t},\n\t\t\t[ 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' ]\n\t\t);\n\t},\n};\n\nconst borderStyle = {\n\tname: 'style',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'border', 'style' ],\n\t\truleKey: string = 'borderStyle'\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[] = [ 'border', 'width' ],\n\t\truleKey: string = 'borderWidth'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nconst borderDefinitionsWithIndividualStyles: StyleDefinition[] = [\n\tcolor,\n\tborderStyle,\n\twidth,\n];\n\n/**\n * Returns a curried generator function with the individual border property ('top' | 'right' | 'bottom' | 'left') baked in.\n *\n * @param individualProperty Individual border property ('top' | 'right' | 'bottom' | 'left').\n *\n * @return StyleDefinition[ 'generate' ]\n */\nconst createBorderGenerateFunction =\n\t( individualProperty: BorderIndividualProperty ) =>\n\t( style: Style, options: StyleOptions ) => {\n\t\tconst styleValue:\n\t\t\t| BorderIndividualStyles< typeof individualProperty >\n\t\t\t| undefined = style?.border?.[ individualProperty ];\n\n\t\tif ( ! styleValue ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn borderDefinitionsWithIndividualStyles.reduce(\n\t\t\t(\n\t\t\t\tacc: GeneratedCSSRule[],\n\t\t\t\tborderDefinition: StyleDefinition\n\t\t\t): GeneratedCSSRule[] => {\n\t\t\t\tconst key = borderDefinition.name;\n\t\t\t\tif (\n\t\t\t\t\tstyleValue.hasOwnProperty( key ) &&\n\t\t\t\t\ttypeof borderDefinition.generate === 'function'\n\t\t\t\t) {\n\t\t\t\t\tconst ruleKey = `border${ upperFirst(\n\t\t\t\t\t\tindividualProperty\n\t\t\t\t\t) }${ upperFirst( key ) }`;\n\t\t\t\t\tacc.push(\n\t\t\t\t\t\t...borderDefinition.generate(\n\t\t\t\t\t\t\tstyle,\n\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\t[ 'border', individualProperty, key ],\n\t\t\t\t\t\t\truleKey\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t[]\n\t\t);\n\t};\n\nconst borderTop = {\n\tname: 'borderTop',\n\tgenerate: createBorderGenerateFunction( 'top' ),\n};\n\nconst borderRight = {\n\tname: 'borderRight',\n\tgenerate: createBorderGenerateFunction( 'right' ),\n};\n\nconst borderBottom = {\n\tname: 'borderBottom',\n\tgenerate: createBorderGenerateFunction( 'bottom' ),\n};\n\nconst borderLeft = {\n\tname: 'borderLeft',\n\tgenerate: createBorderGenerateFunction( 'left' ),\n};\n\nexport default [\n\t...borderDefinitionsWithIndividualStyles,\n\tradius,\n\tborderTop,\n\tborderRight,\n\tborderBottom,\n\tborderLeft,\n];\n"]}
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.styleDefinitions = void 0;
9
9
 
10
+ var _border = _interopRequireDefault(require("./border"));
11
+
10
12
  var _color = _interopRequireDefault(require("./color"));
11
13
 
12
14
  var _spacing = _interopRequireDefault(require("./spacing"));
@@ -16,6 +18,6 @@ var _typography = _interopRequireDefault(require("./typography"));
16
18
  /**
17
19
  * Internal dependencies
18
20
  */
19
- const styleDefinitions = [..._color.default, ..._spacing.default, ..._typography.default];
21
+ const styleDefinitions = [..._border.default, ..._color.default, ..._spacing.default, ..._typography.default];
20
22
  exports.styleDefinitions = styleDefinitions;
21
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/styles/index.ts"],"names":["styleDefinitions","color","spacing","typography"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAKO,MAAMA,gBAAgB,GAAG,CAAE,GAAGC,cAAL,EAAY,GAAGC,gBAAf,EAAwB,GAAGC,mBAA3B,CAAzB","sourcesContent":["/**\n * Internal dependencies\n */\nimport color from './color';\nimport spacing from './spacing';\nimport typography from './typography';\n\nexport const styleDefinitions = [ ...color, ...spacing, ...typography ];\n"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/index.ts"],"names":["styleDefinitions","border","color","spacing","typography"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;AAMO,MAAMA,gBAAgB,GAAG,CAC/B,GAAGC,eAD4B,EAE/B,GAAGC,cAF4B,EAG/B,GAAGC,gBAH4B,EAI/B,GAAGC,mBAJ4B,CAAzB","sourcesContent":["/**\n * Internal dependencies\n */\nimport border from './border';\nimport color from './color';\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];\n"]}
@@ -13,7 +13,10 @@ var _utils = require("../utils");
13
13
  const margin = {
14
14
  name: 'margin',
15
15
  generate: (style, options) => {
16
- return (0, _utils.generateBoxRules)(style, options, ['spacing', 'margin'], 'margin');
16
+ return (0, _utils.generateBoxRules)(style, options, ['spacing', 'margin'], {
17
+ default: 'margin',
18
+ individual: 'margin%s'
19
+ });
17
20
  }
18
21
  };
19
22
  var _default = margin;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/styles/spacing/margin.ts"],"names":["margin","name","generate","style","options"],"mappings":";;;;;;;AAIA;;AAJA;AACA;AACA;AAIA,MAAMA,MAAM,GAAG;AACdC,EAAAA,IAAI,EAAE,QADQ;AAEdC,EAAAA,QAAQ,EAAE,CAAEC,KAAF,EAAgBC,OAAhB,KAA2C;AACpD,WAAO,6BACND,KADM,EAENC,OAFM,EAGN,CAAE,SAAF,EAAa,QAAb,CAHM,EAIN,QAJM,CAAP;AAMA;AATa,CAAf;eAYeJ,M","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Style, StyleOptions } from '../../types';\nimport { generateBoxRules } from '../utils';\n\nconst margin = {\n\tname: 'margin',\n\tgenerate: ( style: Style, options: StyleOptions ) => {\n\t\treturn generateBoxRules(\n\t\t\tstyle,\n\t\t\toptions,\n\t\t\t[ 'spacing', 'margin' ],\n\t\t\t'margin'\n\t\t);\n\t},\n};\n\nexport default margin;\n"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/spacing/margin.ts"],"names":["margin","name","generate","style","options","default","individual"],"mappings":";;;;;;;AAIA;;AAJA;AACA;AACA;AAIA,MAAMA,MAAM,GAAG;AACdC,EAAAA,IAAI,EAAE,QADQ;AAEdC,EAAAA,QAAQ,EAAE,CAAEC,KAAF,EAAgBC,OAAhB,KAA2C;AACpD,WAAO,6BAAkBD,KAAlB,EAAyBC,OAAzB,EAAkC,CAAE,SAAF,EAAa,QAAb,CAAlC,EAA2D;AACjEC,MAAAA,OAAO,EAAE,QADwD;AAEjEC,MAAAA,UAAU,EAAE;AAFqD,KAA3D,CAAP;AAIA;AAPa,CAAf;eAUeN,M","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Style, StyleOptions } from '../../types';\nimport { generateBoxRules } from '../utils';\n\nconst margin = {\n\tname: 'margin',\n\tgenerate: ( style: Style, options: StyleOptions ) => {\n\t\treturn generateBoxRules( style, options, [ 'spacing', 'margin' ], {\n\t\t\tdefault: 'margin',\n\t\t\tindividual: 'margin%s',\n\t\t} );\n\t},\n};\n\nexport default margin;\n"]}
@@ -13,7 +13,10 @@ var _utils = require("../utils");
13
13
  const padding = {
14
14
  name: 'padding',
15
15
  generate: (style, options) => {
16
- return (0, _utils.generateBoxRules)(style, options, ['spacing', 'padding'], 'padding');
16
+ return (0, _utils.generateBoxRules)(style, options, ['spacing', 'padding'], {
17
+ default: 'padding',
18
+ individual: 'padding%s'
19
+ });
17
20
  }
18
21
  };
19
22
  var _default = padding;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/styles/spacing/padding.ts"],"names":["padding","name","generate","style","options"],"mappings":";;;;;;;AAIA;;AAJA;AACA;AACA;AAIA,MAAMA,OAAO,GAAG;AACfC,EAAAA,IAAI,EAAE,SADS;AAEfC,EAAAA,QAAQ,EAAE,CAAEC,KAAF,EAAgBC,OAAhB,KAA2C;AACpD,WAAO,6BACND,KADM,EAENC,OAFM,EAGN,CAAE,SAAF,EAAa,SAAb,CAHM,EAIN,SAJM,CAAP;AAMA;AATc,CAAhB;eAYeJ,O","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Style, StyleOptions } from '../../types';\nimport { generateBoxRules } from '../utils';\n\nconst padding = {\n\tname: 'padding',\n\tgenerate: ( style: Style, options: StyleOptions ) => {\n\t\treturn generateBoxRules(\n\t\t\tstyle,\n\t\t\toptions,\n\t\t\t[ 'spacing', 'padding' ],\n\t\t\t'padding'\n\t\t);\n\t},\n};\n\nexport default padding;\n"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/spacing/padding.ts"],"names":["padding","name","generate","style","options","default","individual"],"mappings":";;;;;;;AAIA;;AAJA;AACA;AACA;AAIA,MAAMA,OAAO,GAAG;AACfC,EAAAA,IAAI,EAAE,SADS;AAEfC,EAAAA,QAAQ,EAAE,CAAEC,KAAF,EAAgBC,OAAhB,KAA2C;AACpD,WAAO,6BAAkBD,KAAlB,EAAyBC,OAAzB,EAAkC,CAAE,SAAF,EAAa,SAAb,CAAlC,EAA4D;AAClEC,MAAAA,OAAO,EAAE,SADyD;AAElEC,MAAAA,UAAU,EAAE;AAFsD,KAA5D,CAAP;AAIA;AAPc,CAAhB;eAUeN,O","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Style, StyleOptions } from '../../types';\nimport { generateBoxRules } from '../utils';\n\nconst padding = {\n\tname: 'padding',\n\tgenerate: ( style: Style, options: StyleOptions ) => {\n\t\treturn generateBoxRules( style, options, [ 'spacing', 'padding' ], {\n\t\t\tdefault: 'padding',\n\t\t\tindividual: 'padding%s',\n\t\t} );\n\t},\n};\n\nexport default padding;\n"]}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.generateBoxRules = generateBoxRules;
7
7
  exports.generateRule = generateRule;
8
8
  exports.getCSSVarFromStyleValue = getCSSVarFromStyleValue;
9
+ exports.upperFirst = upperFirst;
9
10
 
10
11
  var _lodash = require("lodash");
11
12
 
@@ -36,16 +37,18 @@ function generateRule(style, options, path, ruleKey) {
36
37
  /**
37
38
  * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.
38
39
  *
39
- * @param style Style object.
40
- * @param options Options object with settings to adjust how the styles are generated.
41
- * @param path An array of strings representing the path to the style value in the style object.
42
- * @param ruleKey A CSS property key.
40
+ * @param style Style object.
41
+ * @param options Options object with settings to adjust how the styles are generated.
42
+ * @param path An array of strings representing the path to the style value in the style object.
43
+ * @param ruleKeys An array of CSS property keys and patterns.
44
+ * @param individualProperties The "sides" or individual properties for which to generate rules.
43
45
  *
44
- * @return GeneratedCSSRule[] CSS rules.
46
+ * @return GeneratedCSSRule[] CSS rules.
45
47
  */
46
48
 
47
49
 
48
- function generateBoxRules(style, options, path, ruleKey) {
50
+ function generateBoxRules(style, options, path, ruleKeys) {
51
+ let individualProperties = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : ['top', 'right', 'bottom', 'left'];
49
52
  const boxStyle = (0, _lodash.get)(style, path);
50
53
 
51
54
  if (!boxStyle) {
@@ -57,17 +60,17 @@ function generateBoxRules(style, options, path, ruleKey) {
57
60
  if (typeof boxStyle === 'string') {
58
61
  rules.push({
59
62
  selector: options === null || options === void 0 ? void 0 : options.selector,
60
- key: ruleKey,
63
+ key: ruleKeys.default,
61
64
  value: boxStyle
62
65
  });
63
66
  } else {
64
- const sideRules = ['top', 'right', 'bottom', 'left'].reduce((acc, side) => {
65
- const value = (0, _lodash.get)(boxStyle, [side]);
67
+ const sideRules = individualProperties.reduce((acc, side) => {
68
+ const value = getCSSVarFromStyleValue((0, _lodash.get)(boxStyle, [side]));
66
69
 
67
70
  if (value) {
68
71
  acc.push({
69
72
  selector: options === null || options === void 0 ? void 0 : options.selector,
70
- key: `${ruleKey}${(0, _lodash.upperFirst)(side)}`,
73
+ key: ruleKeys === null || ruleKeys === void 0 ? void 0 : ruleKeys.individual.replace('%s', upperFirst(side)),
71
74
  value
72
75
  });
73
76
  }
@@ -96,4 +99,17 @@ function getCSSVarFromStyleValue(styleValue) {
96
99
 
97
100
  return styleValue;
98
101
  }
102
+ /**
103
+ * Capitalizes the first letter in a string.
104
+ *
105
+ * @param {string} str The string whose first letter the function will capitalize.
106
+ *
107
+ * @return string A CSS var value.
108
+ */
109
+
110
+
111
+ function upperFirst(_ref) {
112
+ let [firstLetter, ...rest] = _ref;
113
+ return firstLetter.toUpperCase() + rest.join('');
114
+ }
99
115
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/styles/utils.ts"],"names":["generateRule","style","options","path","ruleKey","styleValue","selector","key","value","getCSSVarFromStyleValue","generateBoxRules","boxStyle","rules","push","sideRules","reduce","acc","side","startsWith","VARIABLE_REFERENCE_PREFIX","variable","slice","length","split","VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE","join","VARIABLE_PATH_SEPARATOR_TOKEN_STYLE"],"mappings":";;;;;;;;;AAGA;;AAMA;;AATA;AACA;AACA;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,CACNC,KADM,EAENC,OAFM,EAGNC,IAHM,EAINC,OAJM,EAKL;AACD,QAAMC,UAA8B,GAAG,iBAAKJ,KAAL,EAAYE,IAAZ,CAAvC;AAEA,SAAOE,UAAU,GACd,CACA;AACCC,IAAAA,QAAQ,EAAEJ,OAAF,aAAEA,OAAF,uBAAEA,OAAO,CAAEI,QADpB;AAECC,IAAAA,GAAG,EAAEH,OAFN;AAGCI,IAAAA,KAAK,EAAEC,uBAAuB,CAAEJ,UAAF;AAH/B,GADA,CADc,GAQd,EARH;AASA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASK,gBAAT,CACNT,KADM,EAENC,OAFM,EAGNC,IAHM,EAINC,OAJM,EAKe;AACrB,QAAMO,QAAkC,GAAG,iBAAKV,KAAL,EAAYE,IAAZ,CAA3C;;AACA,MAAK,CAAEQ,QAAP,EAAkB;AACjB,WAAO,EAAP;A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AAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get, upperFirst } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport type { GeneratedCSSRule, Style, Box, StyleOptions } from '../types';\nimport {\n\tVARIABLE_REFERENCE_PREFIX,\n\tVARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE,\n\tVARIABLE_PATH_SEPARATOR_TOKEN_STYLE,\n} from './constants';\n\n/**\n * Returns a JSON representation of the generated CSS rules.\n *\n * @param style Style object.\n * @param options Options object with settings to adjust how the styles are generated.\n * @param path An array of strings representing the path to the style value in the style object.\n * @param ruleKey A CSS property key.\n *\n * @return GeneratedCSSRule[] CSS rules.\n */\nexport function generateRule(\n\tstyle: Style,\n\toptions: StyleOptions,\n\tpath: string[],\n\truleKey: string\n) {\n\tconst styleValue: string | undefined = get( style, path );\n\n\treturn styleValue\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\tselector: options?.selector,\n\t\t\t\t\tkey: ruleKey,\n\t\t\t\t\tvalue: getCSSVarFromStyleValue( styleValue ),\n\t\t\t\t},\n\t\t ]\n\t\t: [];\n}\n\n/**\n * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.\n *\n * @param style Style object.\n * @param options Options object with settings to adjust how the styles are generated.\n * @param path An array of strings representing the path to the style value in the style object.\n * @param ruleKey A CSS property key.\n *\n * @return GeneratedCSSRule[] CSS rules.\n */\nexport function generateBoxRules(\n\tstyle: Style,\n\toptions: StyleOptions,\n\tpath: string[],\n\truleKey: string\n): GeneratedCSSRule[] {\n\tconst boxStyle: Box | string | undefined = get( style, path );\n\tif ( ! boxStyle ) {\n\t\treturn [];\n\t}\n\n\tconst rules: GeneratedCSSRule[] = [];\n\tif ( typeof boxStyle === 'string' ) {\n\t\trules.push( {\n\t\t\tselector: options?.selector,\n\t\t\tkey: ruleKey,\n\t\t\tvalue: boxStyle,\n\t\t} );\n\t} else {\n\t\tconst sideRules = [ 'top', 'right', 'bottom', 'left' ].reduce(\n\t\t\t( acc: GeneratedCSSRule[], side: string ) => {\n\t\t\t\tconst value: string | undefined = get( boxStyle, [ side ] );\n\t\t\t\tif ( value ) {\n\t\t\t\t\tacc.push( {\n\t\t\t\t\t\tselector: options?.selector,\n\t\t\t\t\t\tkey: `${ ruleKey }${ upperFirst( side ) }`,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t[]\n\t\t);\n\t\trules.push( ...sideRules );\n\t}\n\n\treturn rules;\n}\n\n/**\n * Returns a CSS var value from incoming style value following the pattern `var:description|context|slug`.\n *\n * @param styleValue A raw style value.\n *\n * @return string A CSS var value.\n */\nexport function getCSSVarFromStyleValue( styleValue: string ): string {\n\tif (\n\t\ttypeof styleValue === 'string' &&\n\t\tstyleValue.startsWith( VARIABLE_REFERENCE_PREFIX )\n\t) {\n\t\tconst variable = styleValue\n\t\t\t.slice( VARIABLE_REFERENCE_PREFIX.length )\n\t\t\t.split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )\n\t\t\t.join( VARIABLE_PATH_SEPARATOR_TOKEN_STYLE );\n\t\treturn `var(--wp--${ variable })`;\n\t}\n\treturn styleValue;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/utils.ts"],"names":["generateRule","style","options","path","ruleKey","styleValue","selector","key","value","getCSSVarFromStyleValue","generateBoxRules","ruleKeys","individualProperties","boxStyle","rules","push","default","sideRules","reduce","acc","side","individual","replace","upperFirst","startsWith","VARIABLE_REFERENCE_PREFIX","variable","slice","length","split","VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE","join","VARIABLE_PATH_SEPARATOR_TOKEN_STYLE","firstLetter","rest","toUpperCase"],"mappings":";;;;;;;;;;AAGA;;AAYA;;AAfA;AACA;AACA;;AAmBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,CACNC,KADM,EAENC,OAFM,EAGNC,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,OAAF,uBAAEA,OAAO,CAAEI,QADV;AAETC,UAAAA,GAAG,EAAEI,QAAF,aAAEA,QAAF,uBAAEA,QAAQ,CAAEU,UAAV,CAAqBC,OAArB,CACJ,IADI,EAEJC,UAAU,CAAEH,IAAF,CAFN,CAFI;AAMTZ,UAAAA;AANS,SAAV;AAQA;;AACD,aAAOW,GAAP;AACA,KAhBgB,EAiBjB,EAjBiB,CAAlB;AAmBAL,IAAAA,KAAK,CAACC,IAAN,CAAY,GAAGE,SAAf;AACA;;AAED,SAAOH,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASL,uBAAT,CAAkCJ,UAAlC,EAA+D;AACrE,MACC,OAAOA,UAAP,KAAsB,QAAtB,IACAA,UAAU,CAACmB,UAAX,CAAuBC,oCAAvB,CAFD,EAGE;AACD,UAAMC,QAAQ,GAAGrB,UAAU,CACzBsB,KADe,CACRF,qCAA0BG,MADlB,EAEfC,KAFe,CAERC,kDAFQ,EAGfC,IAHe,CAGTC,8CAHS,CAAjB;AAIA,WAAQ,aAAaN,QAAU,GAA/B;AACA;;AACD,SAAOrB,UAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASkB,UAAT,OAAwD;AAAA,MAAnC,CAAEU,WAAF,EAAe,GAAGC,IAAlB,CAAmC;AAC9D,SAAOD,WAAW,CAACE,WAAZ,KAA4BD,IAAI,CAACH,IAAL,CAAW,EAAX,CAAnC;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCssRulesKeys,\n\tGeneratedCSSRule,\n\tStyle,\n\tBox,\n\tStyleOptions,\n} from '../types';\nimport {\n\tVARIABLE_REFERENCE_PREFIX,\n\tVARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE,\n\tVARIABLE_PATH_SEPARATOR_TOKEN_STYLE,\n} from './constants';\n\n/**\n * Returns a JSON representation of the generated CSS rules.\n *\n * @param style Style object.\n * @param options Options object with settings to adjust how the styles are generated.\n * @param path An array of strings representing the path to the style value in the style object.\n * @param ruleKey A CSS property key.\n *\n * @return GeneratedCSSRule[] CSS rules.\n */\nexport function generateRule(\n\tstyle: Style,\n\toptions: StyleOptions,\n\tpath: string[],\n\truleKey: string\n) {\n\tconst styleValue: string | undefined = get( style, path );\n\n\treturn styleValue\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\tselector: options?.selector,\n\t\t\t\t\tkey: ruleKey,\n\t\t\t\t\tvalue: getCSSVarFromStyleValue( styleValue ),\n\t\t\t\t},\n\t\t ]\n\t\t: [];\n}\n\n/**\n * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.\n *\n * @param style Style object.\n * @param options Options object with settings to adjust how the styles are generated.\n * @param path An array of strings representing the path to the style value in the style object.\n * @param ruleKeys An array of CSS property keys and patterns.\n * @param individualProperties The \"sides\" or individual properties for which to generate rules.\n *\n * @return GeneratedCSSRule[] CSS rules.\n */\nexport function generateBoxRules(\n\tstyle: Style,\n\toptions: StyleOptions,\n\tpath: string[],\n\truleKeys: CssRulesKeys,\n\tindividualProperties: string[] = [ 'top', 'right', 'bottom', 'left' ]\n): GeneratedCSSRule[] {\n\tconst boxStyle: Box | string | undefined = get( style, path );\n\tif ( ! boxStyle ) {\n\t\treturn [];\n\t}\n\n\tconst rules: GeneratedCSSRule[] = [];\n\tif ( typeof boxStyle === 'string' ) {\n\t\trules.push( {\n\t\t\tselector: options?.selector,\n\t\t\tkey: ruleKeys.default,\n\t\t\tvalue: boxStyle,\n\t\t} );\n\t} else {\n\t\tconst sideRules = individualProperties.reduce(\n\t\t\t( acc: GeneratedCSSRule[], side: string ) => {\n\t\t\t\tconst value: string | undefined = getCSSVarFromStyleValue(\n\t\t\t\t\tget( boxStyle, [ side ] )\n\t\t\t\t);\n\t\t\t\tif ( value ) {\n\t\t\t\t\tacc.push( {\n\t\t\t\t\t\tselector: options?.selector,\n\t\t\t\t\t\tkey: ruleKeys?.individual.replace(\n\t\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t\tupperFirst( side )\n\t\t\t\t\t\t),\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t[]\n\t\t);\n\t\trules.push( ...sideRules );\n\t}\n\n\treturn rules;\n}\n\n/**\n * Returns a CSS var value from incoming style value following the pattern `var:description|context|slug`.\n *\n * @param styleValue A raw style value.\n *\n * @return string A CSS var value.\n */\nexport function getCSSVarFromStyleValue( styleValue: string ): string {\n\tif (\n\t\ttypeof styleValue === 'string' &&\n\t\tstyleValue.startsWith( VARIABLE_REFERENCE_PREFIX )\n\t) {\n\t\tconst variable = styleValue\n\t\t\t.slice( VARIABLE_REFERENCE_PREFIX.length )\n\t\t\t.split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )\n\t\t\t.join( VARIABLE_PATH_SEPARATOR_TOKEN_STYLE );\n\t\treturn `var(--wp--${ variable })`;\n\t}\n\treturn styleValue;\n}\n\n/**\n * Capitalizes the first letter in a string.\n *\n * @param {string} str The string whose first letter the function will capitalize.\n *\n * @return string A CSS var value.\n */\nexport function upperFirst( [ firstLetter, ...rest ]: string ) {\n\treturn firstLetter.toUpperCase() + rest.join( '' );\n}\n"]}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { generateRule, generateBoxRules, upperFirst } from '../utils';
5
+ const color = {
6
+ name: 'color',
7
+ generate: function (style, options) {
8
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['border', 'color'];
9
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'borderColor';
10
+ return generateRule(style, options, path, ruleKey);
11
+ }
12
+ };
13
+ const radius = {
14
+ name: 'radius',
15
+ generate: (style, options) => {
16
+ return generateBoxRules(style, options, ['border', 'radius'], {
17
+ default: 'borderRadius',
18
+ individual: 'border%sRadius'
19
+ }, ['topLeft', 'topRight', 'bottomLeft', 'bottomRight']);
20
+ }
21
+ };
22
+ const borderStyle = {
23
+ name: 'style',
24
+ generate: function (style, options) {
25
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['border', 'style'];
26
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'borderStyle';
27
+ return generateRule(style, options, path, ruleKey);
28
+ }
29
+ };
30
+ const width = {
31
+ name: 'width',
32
+ generate: function (style, options) {
33
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['border', 'width'];
34
+ let ruleKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'borderWidth';
35
+ return generateRule(style, options, path, ruleKey);
36
+ }
37
+ };
38
+ const borderDefinitionsWithIndividualStyles = [color, borderStyle, width];
39
+ /**
40
+ * Returns a curried generator function with the individual border property ('top' | 'right' | 'bottom' | 'left') baked in.
41
+ *
42
+ * @param individualProperty Individual border property ('top' | 'right' | 'bottom' | 'left').
43
+ *
44
+ * @return StyleDefinition[ 'generate' ]
45
+ */
46
+
47
+ const createBorderGenerateFunction = individualProperty => (style, options) => {
48
+ var _style$border;
49
+
50
+ const styleValue = style === null || style === void 0 ? void 0 : (_style$border = style.border) === null || _style$border === void 0 ? void 0 : _style$border[individualProperty];
51
+
52
+ if (!styleValue) {
53
+ return [];
54
+ }
55
+
56
+ return borderDefinitionsWithIndividualStyles.reduce((acc, borderDefinition) => {
57
+ const key = borderDefinition.name;
58
+
59
+ if (styleValue.hasOwnProperty(key) && typeof borderDefinition.generate === 'function') {
60
+ const ruleKey = `border${upperFirst(individualProperty)}${upperFirst(key)}`;
61
+ acc.push(...borderDefinition.generate(style, options, ['border', individualProperty, key], ruleKey));
62
+ }
63
+
64
+ return acc;
65
+ }, []);
66
+ };
67
+
68
+ const borderTop = {
69
+ name: 'borderTop',
70
+ generate: createBorderGenerateFunction('top')
71
+ };
72
+ const borderRight = {
73
+ name: 'borderRight',
74
+ generate: createBorderGenerateFunction('right')
75
+ };
76
+ const borderBottom = {
77
+ name: 'borderBottom',
78
+ generate: createBorderGenerateFunction('bottom')
79
+ };
80
+ const borderLeft = {
81
+ name: 'borderLeft',
82
+ generate: createBorderGenerateFunction('left')
83
+ };
84
+ export default [...borderDefinitionsWithIndividualStyles, radius, borderTop, borderRight, borderBottom, borderLeft];
85
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/border/index.ts"],"names":["generateRule","generateBoxRules","upperFirst","color","name","generate","style","options","path","ruleKey","radius","default","individual","borderStyle","width","borderDefinitionsWithIndividualStyles","createBorderGenerateFunction","individualProperty","styleValue","border","reduce","acc","borderDefinition","key","hasOwnProperty","push","borderTop","borderRight","borderBottom","borderLeft"],"mappings":"AAAA;AACA;AACA;AASA,SAASA,YAAT,EAAuBC,gBAAvB,EAAyCC,UAAzC,QAA2D,UAA3D;AAEA,MAAMC,KAAK,GAAG;AACbC,EAAAA,IAAI,EAAE,OADO;AAEbC,EAAAA,QAAQ,EAAE,UACTC,KADS,EAETC,OAFS,EAKe;AAAA,QAFxBC,IAEwB,uEAFP,CAAE,QAAF,EAAY,OAAZ,CAEO;AAAA,QADxBC,OACwB,uEADN,aACM;AACxB,WAAOT,YAAY,CAAEM,KAAF,EAASC,OAAT,EAAkBC,IAAlB,EAAwBC,OAAxB,CAAnB;AACA;AATY,CAAd;AAYA,MAAMC,MAAM,GAAG;AACdN,EAAAA,IAAI,EAAE,QADQ;AAEdC,EAAAA,QAAQ,EAAE,CAAEC,KAAF,EAAgBC,OAAhB,KAA+D;AACxE,WAAON,gBAAgB,CACtBK,KADsB,EAEtBC,OAFsB,EAGtB,CAAE,QAAF,EAAY,QAAZ,CAHsB,EAItB;AACCI,MAAAA,OAAO,EAAE,cADV;AAECC,MAAAA,UAAU,EAAE;AAFb,KAJsB,EAQtB,CAAE,SAAF,EAAa,UAAb,EAAyB,YAAzB,EAAuC,aAAvC,CARsB,CAAvB;AAUA;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AAU,CACnCe,kBADmC,CAEjC,GAAGf,UAAU,CAAEqB,GAAF,CAAS,EAFzB;AAGAF,MAAAA,GAAG,CAACI,IAAJ,CACC,GAAGH,gBAAgB,CAACjB,QAAjB,CACFC,KADE,EAEFC,OAFE,EAGF,CAAE,QAAF,EAAYU,kBAAZ,EAAgCM,GAAhC,CAHE,EAIFd,OAJE,CADJ;AAQA;;AACD,WAAOY,GAAP;AACA,GAvBK,EAwBN,EAxBM,CAAP;AA0BA,CArCF;;AAuCA,MAAMK,SAAS,GAAG;AACjBtB,EAAAA,IAAI,EAAE,WADW;AAEjBC,EAAAA,QAAQ,EAAEW,4BAA4B,CAAE,KAAF;AAFrB,CAAlB;AAKA,MAAMW,WAAW,GAAG;AACnBvB,EAAAA,IAAI,EAAE,aADa;AAEnBC,EAAAA,QAAQ,EAAEW,4BAA4B,CAAE,OAAF;AAFnB,CAApB;AAKA,MAAMY,YAAY,GAAG;AACpBxB,EAAAA,IAAI,EAAE,cADc;AAEpBC,EAAAA,QAAQ,EAAEW,4BAA4B,CAAE,QAAF;AAFlB,CAArB;AAKA,MAAMa,UAAU,GAAG;AAClBzB,EAAAA,IAAI,EAAE,YADY;AAElBC,EAAAA,QAAQ,EAAEW,4BAA4B,CAAE,MAAF;AAFpB,CAAnB;AAKA,eAAe,CACd,GAAGD,qCADW,EAEdL,MAFc,EAGdgB,SAHc,EAIdC,WAJc,EAKdC,YALc,EAMdC,UANc,CAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport type {\n\tBorderIndividualStyles,\n\tBorderIndividualProperty,\n\tGeneratedCSSRule,\n\tStyle,\n\tStyleDefinition,\n\tStyleOptions,\n} from '../../types';\nimport { generateRule, generateBoxRules, upperFirst } from '../utils';\n\nconst color = {\n\tname: 'color',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'border', 'color' ],\n\t\truleKey: string = 'borderColor'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nconst radius = {\n\tname: 'radius',\n\tgenerate: ( style: Style, options: StyleOptions ): GeneratedCSSRule[] => {\n\t\treturn generateBoxRules(\n\t\t\tstyle,\n\t\t\toptions,\n\t\t\t[ 'border', 'radius' ],\n\t\t\t{\n\t\t\t\tdefault: 'borderRadius',\n\t\t\t\tindividual: 'border%sRadius',\n\t\t\t},\n\t\t\t[ 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' ]\n\t\t);\n\t},\n};\n\nconst borderStyle = {\n\tname: 'style',\n\tgenerate: (\n\t\tstyle: Style,\n\t\toptions: StyleOptions,\n\t\tpath: string[] = [ 'border', 'style' ],\n\t\truleKey: string = 'borderStyle'\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[] = [ 'border', 'width' ],\n\t\truleKey: string = 'borderWidth'\n\t): GeneratedCSSRule[] => {\n\t\treturn generateRule( style, options, path, ruleKey );\n\t},\n};\n\nconst borderDefinitionsWithIndividualStyles: StyleDefinition[] = [\n\tcolor,\n\tborderStyle,\n\twidth,\n];\n\n/**\n * Returns a curried generator function with the individual border property ('top' | 'right' | 'bottom' | 'left') baked in.\n *\n * @param individualProperty Individual border property ('top' | 'right' | 'bottom' | 'left').\n *\n * @return StyleDefinition[ 'generate' ]\n */\nconst createBorderGenerateFunction =\n\t( individualProperty: BorderIndividualProperty ) =>\n\t( style: Style, options: StyleOptions ) => {\n\t\tconst styleValue:\n\t\t\t| BorderIndividualStyles< typeof individualProperty >\n\t\t\t| undefined = style?.border?.[ individualProperty ];\n\n\t\tif ( ! styleValue ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn borderDefinitionsWithIndividualStyles.reduce(\n\t\t\t(\n\t\t\t\tacc: GeneratedCSSRule[],\n\t\t\t\tborderDefinition: StyleDefinition\n\t\t\t): GeneratedCSSRule[] => {\n\t\t\t\tconst key = borderDefinition.name;\n\t\t\t\tif (\n\t\t\t\t\tstyleValue.hasOwnProperty( key ) &&\n\t\t\t\t\ttypeof borderDefinition.generate === 'function'\n\t\t\t\t) {\n\t\t\t\t\tconst ruleKey = `border${ upperFirst(\n\t\t\t\t\t\tindividualProperty\n\t\t\t\t\t) }${ upperFirst( key ) }`;\n\t\t\t\t\tacc.push(\n\t\t\t\t\t\t...borderDefinition.generate(\n\t\t\t\t\t\t\tstyle,\n\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\t[ 'border', individualProperty, key ],\n\t\t\t\t\t\t\truleKey\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t[]\n\t\t);\n\t};\n\nconst borderTop = {\n\tname: 'borderTop',\n\tgenerate: createBorderGenerateFunction( 'top' ),\n};\n\nconst borderRight = {\n\tname: 'borderRight',\n\tgenerate: createBorderGenerateFunction( 'right' ),\n};\n\nconst borderBottom = {\n\tname: 'borderBottom',\n\tgenerate: createBorderGenerateFunction( 'bottom' ),\n};\n\nconst borderLeft = {\n\tname: 'borderLeft',\n\tgenerate: createBorderGenerateFunction( 'left' ),\n};\n\nexport default [\n\t...borderDefinitionsWithIndividualStyles,\n\tradius,\n\tborderTop,\n\tborderRight,\n\tborderBottom,\n\tborderLeft,\n];\n"]}
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
+ import border from './border';
4
5
  import color from './color';
5
6
  import spacing from './spacing';
6
7
  import typography from './typography';
7
- export const styleDefinitions = [...color, ...spacing, ...typography];
8
+ export const styleDefinitions = [...border, ...color, ...spacing, ...typography];
8
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/styles/index.ts"],"names":["color","spacing","typography","styleDefinitions"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,SAAlB;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AAEA,OAAO,MAAMC,gBAAgB,GAAG,CAAE,GAAGH,KAAL,EAAY,GAAGC,OAAf,EAAwB,GAAGC,UAA3B,CAAzB","sourcesContent":["/**\n * Internal dependencies\n */\nimport color from './color';\nimport spacing from './spacing';\nimport typography from './typography';\n\nexport const styleDefinitions = [ ...color, ...spacing, ...typography ];\n"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/index.ts"],"names":["border","color","spacing","typography","styleDefinitions"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAP,MAAmB,UAAnB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AAEA,OAAO,MAAMC,gBAAgB,GAAG,CAC/B,GAAGJ,MAD4B,EAE/B,GAAGC,KAF4B,EAG/B,GAAGC,OAH4B,EAI/B,GAAGC,UAJ4B,CAAzB","sourcesContent":["/**\n * Internal dependencies\n */\nimport border from './border';\nimport color from './color';\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];\n"]}
@@ -5,7 +5,10 @@ import { generateBoxRules } from '../utils';
5
5
  const margin = {
6
6
  name: 'margin',
7
7
  generate: (style, options) => {
8
- return generateBoxRules(style, options, ['spacing', 'margin'], 'margin');
8
+ return generateBoxRules(style, options, ['spacing', 'margin'], {
9
+ default: 'margin',
10
+ individual: 'margin%s'
11
+ });
9
12
  }
10
13
  };
11
14
  export default margin;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/styles/spacing/margin.ts"],"names":["generateBoxRules","margin","name","generate","style","options"],"mappings":"AAAA;AACA;AACA;AAEA,SAASA,gBAAT,QAAiC,UAAjC;AAEA,MAAMC,MAAM,GAAG;AACdC,EAAAA,IAAI,EAAE,QADQ;AAEdC,EAAAA,QAAQ,EAAE,CAAEC,KAAF,EAAgBC,OAAhB,KAA2C;AACpD,WAAOL,gBAAgB,CACtBI,KADsB,EAEtBC,OAFsB,EAGtB,CAAE,SAAF,EAAa,QAAb,CAHsB,EAItB,QAJsB,CAAvB;AAMA;AATa,CAAf;AAYA,eAAeJ,MAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Style, StyleOptions } from '../../types';\nimport { generateBoxRules } from '../utils';\n\nconst margin = {\n\tname: 'margin',\n\tgenerate: ( style: Style, options: StyleOptions ) => {\n\t\treturn generateBoxRules(\n\t\t\tstyle,\n\t\t\toptions,\n\t\t\t[ 'spacing', 'margin' ],\n\t\t\t'margin'\n\t\t);\n\t},\n};\n\nexport default margin;\n"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/spacing/margin.ts"],"names":["generateBoxRules","margin","name","generate","style","options","default","individual"],"mappings":"AAAA;AACA;AACA;AAEA,SAASA,gBAAT,QAAiC,UAAjC;AAEA,MAAMC,MAAM,GAAG;AACdC,EAAAA,IAAI,EAAE,QADQ;AAEdC,EAAAA,QAAQ,EAAE,CAAEC,KAAF,EAAgBC,OAAhB,KAA2C;AACpD,WAAOL,gBAAgB,CAAEI,KAAF,EAASC,OAAT,EAAkB,CAAE,SAAF,EAAa,QAAb,CAAlB,EAA2C;AACjEC,MAAAA,OAAO,EAAE,QADwD;AAEjEC,MAAAA,UAAU,EAAE;AAFqD,KAA3C,CAAvB;AAIA;AAPa,CAAf;AAUA,eAAeN,MAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Style, StyleOptions } from '../../types';\nimport { generateBoxRules } from '../utils';\n\nconst margin = {\n\tname: 'margin',\n\tgenerate: ( style: Style, options: StyleOptions ) => {\n\t\treturn generateBoxRules( style, options, [ 'spacing', 'margin' ], {\n\t\t\tdefault: 'margin',\n\t\t\tindividual: 'margin%s',\n\t\t} );\n\t},\n};\n\nexport default margin;\n"]}
@@ -5,7 +5,10 @@ import { generateBoxRules } from '../utils';
5
5
  const padding = {
6
6
  name: 'padding',
7
7
  generate: (style, options) => {
8
- return generateBoxRules(style, options, ['spacing', 'padding'], 'padding');
8
+ return generateBoxRules(style, options, ['spacing', 'padding'], {
9
+ default: 'padding',
10
+ individual: 'padding%s'
11
+ });
9
12
  }
10
13
  };
11
14
  export default padding;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/styles/spacing/padding.ts"],"names":["generateBoxRules","padding","name","generate","style","options"],"mappings":"AAAA;AACA;AACA;AAEA,SAASA,gBAAT,QAAiC,UAAjC;AAEA,MAAMC,OAAO,GAAG;AACfC,EAAAA,IAAI,EAAE,SADS;AAEfC,EAAAA,QAAQ,EAAE,CAAEC,KAAF,EAAgBC,OAAhB,KAA2C;AACpD,WAAOL,gBAAgB,CACtBI,KADsB,EAEtBC,OAFsB,EAGtB,CAAE,SAAF,EAAa,SAAb,CAHsB,EAItB,SAJsB,CAAvB;AAMA;AATc,CAAhB;AAYA,eAAeJ,OAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Style, StyleOptions } from '../../types';\nimport { generateBoxRules } from '../utils';\n\nconst padding = {\n\tname: 'padding',\n\tgenerate: ( style: Style, options: StyleOptions ) => {\n\t\treturn generateBoxRules(\n\t\t\tstyle,\n\t\t\toptions,\n\t\t\t[ 'spacing', 'padding' ],\n\t\t\t'padding'\n\t\t);\n\t},\n};\n\nexport default padding;\n"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/spacing/padding.ts"],"names":["generateBoxRules","padding","name","generate","style","options","default","individual"],"mappings":"AAAA;AACA;AACA;AAEA,SAASA,gBAAT,QAAiC,UAAjC;AAEA,MAAMC,OAAO,GAAG;AACfC,EAAAA,IAAI,EAAE,SADS;AAEfC,EAAAA,QAAQ,EAAE,CAAEC,KAAF,EAAgBC,OAAhB,KAA2C;AACpD,WAAOL,gBAAgB,CAAEI,KAAF,EAASC,OAAT,EAAkB,CAAE,SAAF,EAAa,SAAb,CAAlB,EAA4C;AAClEC,MAAAA,OAAO,EAAE,SADyD;AAElEC,MAAAA,UAAU,EAAE;AAFsD,KAA5C,CAAvB;AAIA;AAPc,CAAhB;AAUA,eAAeN,OAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Style, StyleOptions } from '../../types';\nimport { generateBoxRules } from '../utils';\n\nconst padding = {\n\tname: 'padding',\n\tgenerate: ( style: Style, options: StyleOptions ) => {\n\t\treturn generateBoxRules( style, options, [ 'spacing', 'padding' ], {\n\t\t\tdefault: 'padding',\n\t\t\tindividual: 'padding%s',\n\t\t} );\n\t},\n};\n\nexport default padding;\n"]}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { get, upperFirst } from 'lodash';
4
+ import { get } from 'lodash';
5
5
  /**
6
6
  * Internal dependencies
7
7
  */
@@ -29,15 +29,17 @@ export function generateRule(style, options, path, ruleKey) {
29
29
  /**
30
30
  * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.
31
31
  *
32
- * @param style Style object.
33
- * @param options Options object with settings to adjust how the styles are generated.
34
- * @param path An array of strings representing the path to the style value in the style object.
35
- * @param ruleKey A CSS property key.
32
+ * @param style Style object.
33
+ * @param options Options object with settings to adjust how the styles are generated.
34
+ * @param path An array of strings representing the path to the style value in the style object.
35
+ * @param ruleKeys An array of CSS property keys and patterns.
36
+ * @param individualProperties The "sides" or individual properties for which to generate rules.
36
37
  *
37
- * @return GeneratedCSSRule[] CSS rules.
38
+ * @return GeneratedCSSRule[] CSS rules.
38
39
  */
39
40
 
40
- export function generateBoxRules(style, options, path, ruleKey) {
41
+ export function generateBoxRules(style, options, path, ruleKeys) {
42
+ let individualProperties = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : ['top', 'right', 'bottom', 'left'];
41
43
  const boxStyle = get(style, path);
42
44
 
43
45
  if (!boxStyle) {
@@ -49,17 +51,17 @@ export function generateBoxRules(style, options, path, ruleKey) {
49
51
  if (typeof boxStyle === 'string') {
50
52
  rules.push({
51
53
  selector: options === null || options === void 0 ? void 0 : options.selector,
52
- key: ruleKey,
54
+ key: ruleKeys.default,
53
55
  value: boxStyle
54
56
  });
55
57
  } else {
56
- const sideRules = ['top', 'right', 'bottom', 'left'].reduce((acc, side) => {
57
- const value = get(boxStyle, [side]);
58
+ const sideRules = individualProperties.reduce((acc, side) => {
59
+ const value = getCSSVarFromStyleValue(get(boxStyle, [side]));
58
60
 
59
61
  if (value) {
60
62
  acc.push({
61
63
  selector: options === null || options === void 0 ? void 0 : options.selector,
62
- key: `${ruleKey}${upperFirst(side)}`,
64
+ key: ruleKeys === null || ruleKeys === void 0 ? void 0 : ruleKeys.individual.replace('%s', upperFirst(side)),
63
65
  value
64
66
  });
65
67
  }
@@ -87,4 +89,16 @@ export function getCSSVarFromStyleValue(styleValue) {
87
89
 
88
90
  return styleValue;
89
91
  }
92
+ /**
93
+ * Capitalizes the first letter in a string.
94
+ *
95
+ * @param {string} str The string whose first letter the function will capitalize.
96
+ *
97
+ * @return string A CSS var value.
98
+ */
99
+
100
+ export function upperFirst(_ref) {
101
+ let [firstLetter, ...rest] = _ref;
102
+ return firstLetter.toUpperCase() + rest.join('');
103
+ }
90
104
  //# sourceMappingURL=utils.js.map