@wordpress/style-engine 0.12.0 → 0.14.1-next.d6164808d3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +206 -42
  3. package/build/index.js +7 -5
  4. package/build/index.js.map +1 -1
  5. package/build/styles/typography/index.js +7 -1
  6. package/build/styles/typography/index.js.map +1 -1
  7. package/build/styles/utils.js +5 -5
  8. package/build/styles/utils.js.map +1 -1
  9. package/build-module/index.js +6 -4
  10. package/build-module/index.js.map +1 -1
  11. package/build-module/styles/typography/index.js +7 -1
  12. package/build-module/styles/typography/index.js.map +1 -1
  13. package/build-module/styles/utils.js +5 -5
  14. package/build-module/styles/utils.js.map +1 -1
  15. package/build-types/index.d.ts +4 -4
  16. package/build-types/index.d.ts.map +1 -1
  17. package/build-types/styles/color/background.d.ts +1 -1
  18. package/build-types/styles/color/gradient.d.ts +1 -1
  19. package/build-types/styles/color/index.d.ts +1 -1
  20. package/build-types/styles/color/text.d.ts +1 -1
  21. package/build-types/styles/typography/index.d.ts +1 -1
  22. package/build-types/styles/typography/index.d.ts.map +1 -1
  23. package/build-types/styles/utils.d.ts +6 -6
  24. package/build-types/types.d.ts +3 -4
  25. package/build-types/types.d.ts.map +1 -1
  26. package/class-wp-style-engine-css-declarations.php +61 -10
  27. package/class-wp-style-engine-css-rule.php +125 -0
  28. package/class-wp-style-engine-css-rules-store.php +144 -0
  29. package/class-wp-style-engine-processor.php +143 -0
  30. package/class-wp-style-engine.php +265 -144
  31. package/package.json +2 -2
  32. package/phpunit/class-wp-style-engine-css-declarations-test.php +129 -3
  33. package/phpunit/class-wp-style-engine-css-rule-test.php +127 -0
  34. package/phpunit/class-wp-style-engine-css-rules-store-test.php +171 -0
  35. package/phpunit/class-wp-style-engine-processor-test.php +266 -0
  36. package/phpunit/class-wp-style-engine-test.php +223 -22
  37. package/src/index.ts +4 -4
  38. package/src/styles/typography/index.ts +13 -0
  39. package/src/styles/utils.ts +5 -5
  40. package/src/test/index.js +64 -11
  41. package/src/types.ts +3 -4
  42. package/tsconfig.tsbuildinfo +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/style-engine/src/styles/utils.ts"],"names":["get","VARIABLE_REFERENCE_PREFIX","VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE","VARIABLE_PATH_SEPARATOR_TOKEN_STYLE","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","slice","length","split","join","firstLetter","rest","toUpperCase"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AAQA,SACCC,yBADD,EAECC,uCAFD,EAGCC,mCAHD,QAIO,aAJP;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,CACNC,KADM,EAENC,OAFM,EAGNC,IAHM,EAINC,OAJM,EAKL;AACD,QAAMC,UAA8B,GAAGT,GAAG,CAAEK,KAAF,EAASE,IAAT,CAA1C;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;AACA;;AACA,OAAO,SAASK,gBAAT,CACNT,KADM,EAENC,OAFM,EAGNC,IAHM,EAINQ,QAJM,EAMe;AAAA,MADrBC,oBACqB,uEADY,CAAE,KAAF,EAAS,OAAT,EAAkB,QAAlB,EAA4B,MAA5B,CACZ;AACrB,QAAMC,QAAkC,GAAGjB,GAA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AAGpB,UAAU,CACzBqB,KADe,CACR7B,yBAAyB,CAAC8B,MADlB,EAEfC,KAFe,CAER9B,uCAFQ,EAGf+B,IAHe,CAGT9B,mCAHS,CAAjB;AAIA,WAAQ,aAAa0B,QAAU,GAA/B;AACA;;AACD,SAAOpB,UAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkB,UAAT,OAAwD;AAAA,MAAnC,CAAEO,WAAF,EAAe,GAAGC,IAAlB,CAAmC;AAC9D,SAAOD,WAAW,CAACE,WAAZ,KAA4BD,IAAI,CAACF,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"]}
1
+ {"version":3,"sources":["@wordpress/style-engine/src/styles/utils.ts"],"names":["get","VARIABLE_REFERENCE_PREFIX","VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE","VARIABLE_PATH_SEPARATOR_TOKEN_STYLE","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","slice","length","split","join","firstLetter","rest","toUpperCase"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AAQA,SACCC,yBADD,EAECC,uCAFD,EAGCC,mCAHD,QAIO,aAJP;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,CACNC,KADM,EAENC,OAFM,EAGNC,IAHM,EAINC,OAJM,EAKL;AACD,QAAMC,UAA8B,GAAGT,GAAG,CAAEK,KAAF,EAASE,IAAT,CAA1C;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;AACA;;AACA,OAAO,SAASK,gBA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A;AACA;AACA;;AACA,OAAO,SAASL,uBAAT,CAAkCJ,UAAlC,EAA+D;AACrE,MACC,OAAOA,UAAP,KAAsB,QAAtB,IACAA,UAAU,CAACmB,UAAX,CAAuB3B,yBAAvB,CAFD,EAGE;AACD,UAAM4B,QAAQ,GAAGpB,UAAU,CACzBqB,KADe,CACR7B,yBAAyB,CAAC8B,MADlB,EAEfC,KAFe,CAER9B,uCAFQ,EAGf+B,IAHe,CAGT9B,mCAHS,CAAjB;AAIA,WAAQ,aAAa0B,QAAU,GAA/B;AACA;;AACD,SAAOpB,UAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkB,UAAT,OAAwD;AAAA,MAAnC,CAAEO,WAAF,EAAe,GAAGC,IAAlB,CAAmC;AAC9D,SAAOD,WAAW,CAACE,WAAZ,KAA4BD,IAAI,CAACF,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"]}
@@ -5,19 +5,19 @@ import type { Style, StyleOptions, GeneratedCSSRule } from './types';
5
5
  /**
6
6
  * Generates a stylesheet for a given style object and selector.
7
7
  *
8
- * @param style Style object.
8
+ * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
9
9
  * @param options Options object with settings to adjust how the styles are generated.
10
10
  *
11
11
  * @return generated stylesheet.
12
12
  */
13
- export declare function generate(style: Style, options: StyleOptions): string;
13
+ export declare function compileCSS(style: Style, options?: StyleOptions): string;
14
14
  /**
15
15
  * Returns a JSON representation of the generated CSS rules.
16
16
  *
17
- * @param style Style object.
17
+ * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
18
18
  * @param options Options object with settings to adjust how the styles are generated.
19
19
  *
20
20
  * @return generated styles.
21
21
  */
22
- export declare function getCSSRules(style: Style, options: StyleOptions): GeneratedCSSRule[];
22
+ export declare function getCSSRules(style: Style, options?: StyleOptions): GeneratedCSSRule[];
23
23
  //# 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,QAAQ,CAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,GAAI,MAAM,CA6BtE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,GACnB,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;;;;;;;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"}
@@ -5,7 +5,7 @@ import type { Style, StyleOptions } from '../../types';
5
5
  declare const background: {
6
6
  name: string;
7
7
  generate: (style: Style, options: StyleOptions) => {
8
- selector: string;
8
+ selector: string | undefined;
9
9
  key: string;
10
10
  value: string;
11
11
  }[];
@@ -5,7 +5,7 @@ import type { Style, StyleOptions } from '../../types';
5
5
  declare const gradient: {
6
6
  name: string;
7
7
  generate: (style: Style, options: StyleOptions) => {
8
- selector: string;
8
+ selector: string | undefined;
9
9
  key: string;
10
10
  value: string;
11
11
  }[];
@@ -1,7 +1,7 @@
1
1
  declare const _default: {
2
2
  name: string;
3
3
  generate: (style: import("../../types").Style, options: import("../../types").StyleOptions) => {
4
- selector: string;
4
+ selector: string | undefined;
5
5
  key: string;
6
6
  value: string;
7
7
  }[];
@@ -5,7 +5,7 @@ import type { Style, StyleOptions } from '../../types';
5
5
  declare const text: {
6
6
  name: string;
7
7
  generate: (style: Style, options: StyleOptions) => {
8
- selector: string;
8
+ selector: string | undefined;
9
9
  key: string;
10
10
  value: string;
11
11
  }[];
@@ -5,7 +5,7 @@ import type { Style, StyleOptions } from '../../types';
5
5
  declare const _default: {
6
6
  name: string;
7
7
  generate: (style: Style, options: StyleOptions) => {
8
- selector: string;
8
+ selector: string | undefined;
9
9
  key: string;
10
10
  value: string;
11
11
  }[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/typography/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;;;;;;;;;AAuFvD,wBAQE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/typography/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;;;;;;;;;AAmGvD,wBASE"}
@@ -13,18 +13,18 @@ import type { CssRulesKeys, GeneratedCSSRule, Style, StyleOptions } from '../typ
13
13
  * @return GeneratedCSSRule[] CSS rules.
14
14
  */
15
15
  export declare function generateRule(style: Style, options: StyleOptions, path: string[], ruleKey: string): {
16
- selector: string;
16
+ selector: string | undefined;
17
17
  key: string;
18
18
  value: string;
19
19
  }[];
20
20
  /**
21
21
  * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.
22
22
  *
23
- * @param style Style object.
24
- * @param options Options object with settings to adjust how the styles are generated.
25
- * @param path An array of strings representing the path to the style value in the style object.
26
- * @param ruleKeys An array of CSS property keys and patterns.
27
- * @param individualProperties The "sides" or individual properties for which to generate rules.
23
+ * @param style Style object.
24
+ * @param options Options object with settings to adjust how the styles are generated.
25
+ * @param path An array of strings representing the path to the style value in the style object.
26
+ * @param ruleKeys An array of CSS property keys and patterns.
27
+ * @param individualProperties The "sides" or individual properties for which to generate rules.
28
28
  *
29
29
  * @return GeneratedCSSRule[] CSS rules.
30
30
  */
@@ -66,10 +66,10 @@ export declare type StyleOptions = {
66
66
  /**
67
67
  * CSS selector for the generated style.
68
68
  */
69
- selector: string;
69
+ selector?: string;
70
70
  };
71
71
  export declare type GeneratedCSSRule = {
72
- selector: string;
72
+ selector?: string;
73
73
  value: string;
74
74
  /**
75
75
  * The CSS key in JS style attribute format, compatible with React.
@@ -79,8 +79,7 @@ export declare type GeneratedCSSRule = {
79
79
  };
80
80
  export interface StyleDefinition {
81
81
  name: string;
82
- generate?: (style: Style, options: StyleOptions, path?: string[], ruleKey?: string) => GeneratedCSSRule[];
83
- getClassNames?: (style: Style) => string[];
82
+ generate?: (style: Style, options: StyleOptions | {}, path?: string[], ruleKey?: string) => GeneratedCSSRule[];
84
83
  }
85
84
  export {};
86
85
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,aAAK,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AACpD,oBAAY,GAAG,CAAE,CAAC,SAAS,WAAW,GAAG,SAAS,IAAK;IACtD,GAAG,CAAC,EAAE,aAAa,CAAE,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,GAAI,CAAE,KAAK,CAAE,CAAC;IACjE,KAAK,CAAC,EAAE,aAAa,CAAE,CAAC,SAAS,SAAS,GAAG,OAAO,GAAG,GAAI,CAAE,OAAO,CAAE,CAAC;IACvE,MAAM,CAAC,EAAE,aAAa,CAAE,CAAC,SAAS,SAAS,GAAG,QAAQ,GAAG,GAAI,CAAE,QAAQ,CAAE,CAAC;IAC1E,IAAI,CAAC,EAAE,aAAa,CAAE,CAAC,SAAS,SAAS,GAAG,MAAM,GAAG,GAAI,CAAE,MAAM,CAAE,CAAC;CACpE,CAAC;AAEF,oBAAY,wBAAwB,GAAG,KAAK,GAAG,OAAO,GAA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,EAAE,EAC1B,IAAI,CAAC,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE,MAAM,KACZ,gBAAgB,EAAE,CAAC;CACxB"}
@@ -34,9 +34,6 @@ class WP_Style_Engine_CSS_Declarations {
34
34
  * @param array $declarations An array of declarations (property => value pairs).
35
35
  */
36
36
  public function __construct( $declarations = array() ) {
37
- if ( empty( $declarations ) ) {
38
- return;
39
- }
40
37
  $this->add_declarations( $declarations );
41
38
  }
42
39
 
@@ -46,7 +43,7 @@ class WP_Style_Engine_CSS_Declarations {
46
43
  * @param string $property The CSS property.
47
44
  * @param string $value The CSS value.
48
45
  *
49
- * @return void
46
+ * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
50
47
  */
51
48
  public function add_declaration( $property, $value ) {
52
49
 
@@ -54,17 +51,31 @@ class WP_Style_Engine_CSS_Declarations {
54
51
  $property = $this->sanitize_property( $property );
55
52
  // Bail early if the property is empty.
56
53
  if ( empty( $property ) ) {
57
- return;
54
+ return $this;
58
55
  }
59
56
 
60
57
  // Trim the value. If empty, bail early.
61
58
  $value = trim( $value );
62
59
  if ( '' === $value ) {
63
- return;
60
+ return $this;
64
61
  }
65
62
 
66
63
  // Add the declaration property/value pair.
67
64
  $this->declarations[ $property ] = $value;
65
+
66
+ return $this;
67
+ }
68
+
69
+ /**
70
+ * Remove a single declaration.
71
+ *
72
+ * @param string $property The CSS property.
73
+ *
74
+ * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
75
+ */
76
+ public function remove_declaration( $property ) {
77
+ unset( $this->declarations[ $property ] );
78
+ return $this;
68
79
  }
69
80
 
70
81
  /**
@@ -72,12 +83,27 @@ class WP_Style_Engine_CSS_Declarations {
72
83
  *
73
84
  * @param array $declarations An array of declarations.
74
85
  *
75
- * @return void
86
+ * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
76
87
  */
77
88
  public function add_declarations( $declarations ) {
78
89
  foreach ( $declarations as $property => $value ) {
79
90
  $this->add_declaration( $property, $value );
80
91
  }
92
+ return $this;
93
+ }
94
+
95
+ /**
96
+ * Remove multiple declarations.
97
+ *
98
+ * @param array $properties An array of properties.
99
+ *
100
+ * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods.
101
+ */
102
+ public function remove_declarations( $properties = array() ) {
103
+ foreach ( $properties as $property ) {
104
+ $this->remove_declaration( $property );
105
+ }
106
+ return $this;
81
107
  }
82
108
 
83
109
  /**
@@ -89,18 +115,43 @@ class WP_Style_Engine_CSS_Declarations {
89
115
  return $this->declarations;
90
116
  }
91
117
 
118
+ /**
119
+ * Filters a CSS property + value pair.
120
+ *
121
+ * @param string $property The CSS property.
122
+ * @param string $value The value to be filtered.
123
+ * @param string $spacer The spacer between the colon and the value. Defaults to an empty string.
124
+ *
125
+ * @return string The filtered declaration as a single string.
126
+ */
127
+ protected static function filter_declaration( $property, $value, $spacer = '' ) {
128
+ $filtered_value = wp_strip_all_tags( $value, true );
129
+ if ( '' !== $filtered_value ) {
130
+ return safecss_filter_attr( "{$property}:{$spacer}{$filtered_value}" );
131
+ }
132
+ return '';
133
+ }
134
+
92
135
  /**
93
136
  * Filters and compiles the CSS declarations.
94
137
  *
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`.
140
+ *
95
141
  * @return string The CSS declarations.
96
142
  */
97
- public function get_declarations_string() {
143
+ public function get_declarations_string( $should_prettify = false, $indent_count = 0 ) {
98
144
  $declarations_array = $this->get_declarations();
99
145
  $declarations_output = '';
146
+ $indent = $should_prettify ? str_repeat( "\t", $indent_count ) : '';
147
+ $suffix = $should_prettify ? ' ' : '';
148
+ $suffix = $should_prettify && $indent_count > 0 ? "\n" : $suffix;
149
+ $spacer = $should_prettify ? ' ' : '';
150
+
100
151
  foreach ( $declarations_array as $property => $value ) {
101
- $filtered_declaration = esc_html( safecss_filter_attr( "{$property}: {$value}" ) );
152
+ $filtered_declaration = static::filter_declaration( $property, $value, $spacer );
102
153
  if ( $filtered_declaration ) {
103
- $declarations_output .= $filtered_declaration . '; ';
154
+ $declarations_output .= "{$indent}{$filtered_declaration};$suffix";
104
155
  }
105
156
  }
106
157
  return rtrim( $declarations_output );
@@ -0,0 +1,125 @@
1
+ <?php
2
+ /**
3
+ * WP_Style_Engine_CSS_Rule
4
+ *
5
+ * An object for CSS rules.
6
+ *
7
+ * @package Gutenberg
8
+ */
9
+
10
+ if ( class_exists( 'WP_Style_Engine_CSS_Rule' ) ) {
11
+ return;
12
+ }
13
+
14
+ /**
15
+ * Holds, sanitizes, processes and prints CSS declarations for the style engine.
16
+ *
17
+ * @access private
18
+ */
19
+ class WP_Style_Engine_CSS_Rule {
20
+
21
+ /**
22
+ * The selector.
23
+ *
24
+ * @var string
25
+ */
26
+ protected $selector;
27
+
28
+ /**
29
+ * The selector declarations.
30
+ *
31
+ * Contains a WP_Style_Engine_CSS_Declarations object.
32
+ *
33
+ * @var WP_Style_Engine_CSS_Declarations
34
+ */
35
+ protected $declarations;
36
+
37
+ /**
38
+ * Constructor
39
+ *
40
+ * @param string $selector The CSS selector.
41
+ * @param array|WP_Style_Engine_CSS_Declarations $declarations An array of declarations (property => value pairs),
42
+ * or a WP_Style_Engine_CSS_Declarations object.
43
+ */
44
+ public function __construct( $selector = '', $declarations = array() ) {
45
+ $this->set_selector( $selector );
46
+ $this->add_declarations( $declarations );
47
+ }
48
+
49
+ /**
50
+ * Set the selector.
51
+ *
52
+ * @param string $selector The CSS selector.
53
+ *
54
+ * @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods.
55
+ */
56
+ public function set_selector( $selector ) {
57
+ $this->selector = $selector;
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * Set the declarations.
63
+ *
64
+ * @param array|WP_Style_Engine_CSS_Declarations $declarations An array of declarations (property => value pairs),
65
+ * or a WP_Style_Engine_CSS_Declarations object.
66
+ *
67
+ * @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods.
68
+ */
69
+ public function add_declarations( $declarations ) {
70
+ $is_declarations_object = ! is_array( $declarations );
71
+ $declarations_array = $is_declarations_object ? $declarations->get_declarations() : $declarations;
72
+
73
+ if ( null === $this->declarations ) {
74
+ if ( $is_declarations_object ) {
75
+ $this->declarations = $declarations;
76
+ return $this;
77
+ }
78
+ $this->declarations = new WP_Style_Engine_CSS_Declarations( $declarations_array );
79
+ }
80
+ $this->declarations->add_declarations( $declarations_array );
81
+
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * Get the declarations object.
87
+ *
88
+ * @return WP_Style_Engine_CSS_Declarations
89
+ */
90
+ public function get_declarations() {
91
+ return $this->declarations;
92
+ }
93
+
94
+ /**
95
+ * Get the full selector.
96
+ *
97
+ * @return string
98
+ */
99
+ public function get_selector() {
100
+ return $this->selector;
101
+ }
102
+
103
+ /**
104
+ * Get the CSS.
105
+ *
106
+ * @param boolean $should_prettify Whether to add spacing, new lines and indents.
107
+ * @param number $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`.
108
+ *
109
+ * @return string
110
+ */
111
+ public function get_css( $should_prettify = false, $indent_count = 0 ) {
112
+ $rule_indent = $should_prettify ? str_repeat( "\t", $indent_count ) : '';
113
+ $declarations_indent = $should_prettify ? $indent_count + 1 : 0;
114
+ $new_line = $should_prettify ? "\n" : '';
115
+ $space = $should_prettify ? ' ' : '';
116
+ $selector = $should_prettify ? str_replace( ',', ",\n", $this->get_selector() ) : $this->get_selector();
117
+ $css_declarations = $this->declarations->get_declarations_string( $should_prettify, $declarations_indent );
118
+
119
+ if ( empty( $css_declarations ) ) {
120
+ return '';
121
+ }
122
+
123
+ return "{$rule_indent}{$selector}{$space}{{$new_line}{$css_declarations}{$new_line}{$rule_indent}}";
124
+ }
125
+ }
@@ -0,0 +1,144 @@
1
+ <?php
2
+ /**
3
+ * WP_Style_Engine_CSS_Rules_Store
4
+ *
5
+ * A store for WP_Style_Engine_CSS_Rule objects.
6
+ *
7
+ * @package Gutenberg
8
+ */
9
+
10
+ if ( class_exists( 'WP_Style_Engine_CSS_Rules_Store' ) ) {
11
+ return;
12
+ }
13
+
14
+ /**
15
+ * Holds, sanitizes, processes and prints CSS declarations for the style engine.
16
+ *
17
+ * @access private
18
+ */
19
+ class WP_Style_Engine_CSS_Rules_Store {
20
+
21
+ /**
22
+ * An array of named WP_Style_Engine_CSS_Rules_Store objects.
23
+ *
24
+ * @static
25
+ *
26
+ * @var WP_Style_Engine_CSS_Rules_Store[]
27
+ */
28
+ protected static $stores = array();
29
+
30
+ /**
31
+ * The store name.
32
+ *
33
+ * @var string
34
+ */
35
+ protected $name = '';
36
+
37
+ /**
38
+ * An array of CSS Rules objects assigned to the store.
39
+ *
40
+ * @var WP_Style_Engine_CSS_Rule[]
41
+ */
42
+ protected $rules = array();
43
+
44
+ /**
45
+ * Get an instance of the store.
46
+ *
47
+ * @param string $store_name The name of the store.
48
+ *
49
+ * @return WP_Style_Engine_CSS_Rules_Store|void
50
+ */
51
+ public static function get_store( $store_name = 'default' ) {
52
+ if ( ! is_string( $store_name ) || empty( $store_name ) ) {
53
+ return;
54
+ }
55
+ if ( ! isset( static::$stores[ $store_name ] ) ) {
56
+ static::$stores[ $store_name ] = new static();
57
+ // Set the store name.
58
+ static::$stores[ $store_name ]->set_name( $store_name );
59
+ }
60
+ return static::$stores[ $store_name ];
61
+ }
62
+
63
+ /**
64
+ * Get an array of all available stores.
65
+ *
66
+ * @return WP_Style_Engine_CSS_Rules_Store[]
67
+ */
68
+ public static function get_stores() {
69
+ return static::$stores;
70
+ }
71
+
72
+ /**
73
+ * Clears all stores from static::$stores.
74
+ *
75
+ * @return void
76
+ */
77
+ public static function remove_all_stores() {
78
+ static::$stores = array();
79
+ }
80
+
81
+ /**
82
+ * Set the store name.
83
+ *
84
+ * @param string $name The store name.
85
+ *
86
+ * @return void
87
+ */
88
+ public function set_name( $name ) {
89
+ $this->name = $name;
90
+ }
91
+
92
+ /**
93
+ * Get the store name.
94
+ *
95
+ * @return string
96
+ */
97
+ public function get_name() {
98
+ return $this->name;
99
+ }
100
+
101
+ /**
102
+ * Get an array of all rules.
103
+ *
104
+ * @return WP_Style_Engine_CSS_Rule[]
105
+ */
106
+ public function get_all_rules() {
107
+ return $this->rules;
108
+ }
109
+
110
+ /**
111
+ * Get a WP_Style_Engine_CSS_Rule object by its selector.
112
+ * If the rule does not exist, it will be created.
113
+ *
114
+ * @param string $selector The CSS selector.
115
+ *
116
+ * @return WP_Style_Engine_CSS_Rule|void Returns a WP_Style_Engine_CSS_Rule object, or null if the selector is empty.
117
+ */
118
+ public function add_rule( $selector ) {
119
+ $selector = trim( $selector );
120
+
121
+ // Bail early if there is no selector.
122
+ if ( empty( $selector ) ) {
123
+ return;
124
+ }
125
+
126
+ // Create the rule if it doesn't exist.
127
+ if ( empty( $this->rules[ $selector ] ) ) {
128
+ $this->rules[ $selector ] = new WP_Style_Engine_CSS_Rule( $selector );
129
+ }
130
+
131
+ return $this->rules[ $selector ];
132
+ }
133
+
134
+ /**
135
+ * Remove a selector from the store.
136
+ *
137
+ * @param string $selector The CSS selector.
138
+ *
139
+ * @return void
140
+ */
141
+ public function remove_rule( $selector ) {
142
+ unset( $this->rules[ $selector ] );
143
+ }
144
+ }