@wordpress/style-engine 1.0.1 → 1.1.1-next.4d3b314fd5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +51 -38
- package/build/styles/border/index.js +37 -50
- package/build/styles/border/index.js.map +1 -1
- package/build/styles/utils.js +19 -5
- package/build/styles/utils.js.map +1 -1
- package/build-module/styles/border/index.js +38 -51
- package/build-module/styles/border/index.js.map +1 -1
- package/build-module/styles/utils.js +18 -6
- package/build-module/styles/utils.js.map +1 -1
- package/build-types/styles/border/index.d.ts +2 -5
- package/build-types/styles/border/index.d.ts.map +1 -1
- package/build-types/styles/color/background.d.ts +1 -5
- package/build-types/styles/color/background.d.ts.map +1 -1
- package/build-types/styles/color/gradient.d.ts +1 -5
- package/build-types/styles/color/gradient.d.ts.map +1 -1
- package/build-types/styles/color/index.d.ts +1 -5
- package/build-types/styles/color/index.d.ts.map +1 -1
- package/build-types/styles/color/text.d.ts +1 -5
- package/build-types/styles/color/text.d.ts.map +1 -1
- package/build-types/styles/shadow/index.d.ts +1 -5
- package/build-types/styles/shadow/index.d.ts.map +1 -1
- package/build-types/styles/typography/index.d.ts +1 -5
- package/build-types/styles/typography/index.d.ts.map +1 -1
- package/build-types/styles/utils.d.ts +12 -8
- package/build-types/styles/utils.d.ts.map +1 -1
- package/build-types/types.d.ts +19 -16
- package/build-types/types.d.ts.map +1 -1
- package/class-wp-style-engine-css-declarations.php +1 -1
- package/class-wp-style-engine-css-rule.php +1 -1
- package/class-wp-style-engine-css-rules-store.php +1 -1
- package/class-wp-style-engine-processor.php +1 -1
- package/docs/toc.json +8 -0
- package/docs/using-the-style-engine-with-block-supports.md +92 -32
- package/package.json +2 -2
- package/phpunit/style-engine-test.php +6 -6
- package/src/styles/border/index.ts +49 -99
- package/src/styles/utils.ts +19 -5
- package/src/test/index.js +13 -0
- package/src/test/utils.js +31 -1
- package/src/types.ts +23 -20
- package/style-engine.php +4 -4
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/style-engine/src/styles/border/index.ts"],"names":["generateRule","generateBoxRules","
|
|
1
|
+
{"version":3,"sources":["@wordpress/style-engine/src/styles/border/index.ts"],"names":["generateRule","generateBoxRules","camelCaseJoin","createBorderGenerateFunction","path","style","options","createBorderEdgeGenerateFunction","edge","flatMap","key","color","name","generate","radius","default","individual","borderStyle","width","borderTop","borderRight","borderBottom","borderLeft"],"mappings":"AAAA;AACA;AACA;AAEA,SAASA,YAAT,EAAuBC,gBAAvB,EAAyCC,aAAzC,QAA8D,UAA9D;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,4BAAT,CAAuCC,IAAvC,EAA0E;AACzE,SAAO,CAAEC,KAAF,EAASC,OAAT,KACNN,YAAY,CAAEK,KAAF,EAASC,OAAT,EAAkBF,IAAlB,EAAwBF,aAAa,CAAEE,IAAF,CAArC,CADb;AAEA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASG,gCAAT,CAA2CC,IAA3C,EAA6E;AAC5E,SAAO,CAAEH,KAAF,EAASC,OAAT,KAAsB;AAC5B,WAAO,CAAE,OAAF,EAAW,OAAX,EAAoB,OAApB,EAA8BG,OAA9B,CAAyCC,GAAF,IAAW;AACxD,YAAMN,IAAI,GAAG,CAAE,QAAF,EAAYI,IAAZ,EAAkBE,GAAlB,CAAb;AACA,aAAOP,4BAA4B,CAAEC,IAAF,CAA5B,CAAsCC,KAAtC,EAA6CC,OAA7C,CAAP;AACA,KAHM,CAAP;AAIA,GALD;AAMA;;AAED,MAAMK,KAAsB,GAAG;AAC9BC,EAAAA,IAAI,EAAE,OADwB;AAE9BC,EAAAA,QAAQ,EAAEV,4BAA4B,CAAE,CAAE,QAAF,EAAY,OAAZ,CAAF;AAFR,CAA/B;AAKA,MAAMW,MAAuB,GAAG;AAC/BF,EAAAA,IAAI,EAAE,QADyB;AAE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ent":["/**\n * Internal dependencies\n */\nimport type { BoxEdge, GenerateFunction, StyleDefinition } from '../../types';\nimport { generateRule, generateBoxRules, camelCaseJoin } from '../utils';\n\n/**\n * Creates a function for generating CSS rules when the style path is the same as the camelCase CSS property used in React.\n *\n * @param path An array of strings representing the path to the style value in the style object.\n *\n * @return A function that generates CSS rules.\n */\nfunction createBorderGenerateFunction( path: string[] ): GenerateFunction {\n\treturn ( style, options ) =>\n\t\tgenerateRule( style, options, path, camelCaseJoin( path ) );\n}\n\n/**\n * Creates a function for generating border-{top,bottom,left,right}-{color,style,width} CSS rules.\n *\n * @param edge The edge to create CSS rules for.\n *\n * @return A function that generates CSS rules.\n */\nfunction createBorderEdgeGenerateFunction( edge: BoxEdge ): GenerateFunction {\n\treturn ( style, options ) => {\n\t\treturn [ 'color', 'style', 'width' ].flatMap( ( key ) => {\n\t\t\tconst path = [ 'border', edge, key ];\n\t\t\treturn createBorderGenerateFunction( path )( style, options );\n\t\t} );\n\t};\n}\n\nconst color: StyleDefinition = {\n\tname: 'color',\n\tgenerate: createBorderGenerateFunction( [ 'border', 'color' ] ),\n};\n\nconst radius: StyleDefinition = {\n\tname: 'radius',\n\tgenerate: ( style, options ) => {\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: StyleDefinition = {\n\tname: 'style',\n\tgenerate: createBorderGenerateFunction( [ 'border', 'style' ] ),\n};\n\nconst width: StyleDefinition = {\n\tname: 'width',\n\tgenerate: createBorderGenerateFunction( [ 'border', 'width' ] ),\n};\n\nconst borderTop: StyleDefinition = {\n\tname: 'borderTop',\n\tgenerate: createBorderEdgeGenerateFunction( 'top' ),\n};\n\nconst borderRight: StyleDefinition = {\n\tname: 'borderRight',\n\tgenerate: createBorderEdgeGenerateFunction( 'right' ),\n};\n\nconst borderBottom: StyleDefinition = {\n\tname: 'borderBottom',\n\tgenerate: createBorderEdgeGenerateFunction( 'bottom' ),\n};\n\nconst borderLeft: StyleDefinition = {\n\tname: 'borderLeft',\n\tgenerate: createBorderEdgeGenerateFunction( 'left' ),\n};\n\nexport default [\n\tcolor,\n\tborderStyle,\n\twidth,\n\tradius,\n\tborderTop,\n\tborderRight,\n\tborderBottom,\n\tborderLeft,\n];\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { get } from 'lodash';
|
|
4
|
+
import { get, kebabCase } from 'lodash';
|
|
5
5
|
/**
|
|
6
6
|
* Internal dependencies
|
|
7
7
|
*/
|
|
@@ -83,7 +83,7 @@ export function generateBoxRules(style, options, path, ruleKeys) {
|
|
|
83
83
|
|
|
84
84
|
export function getCSSVarFromStyleValue(styleValue) {
|
|
85
85
|
if (typeof styleValue === 'string' && styleValue.startsWith(VARIABLE_REFERENCE_PREFIX)) {
|
|
86
|
-
const variable = styleValue.slice(VARIABLE_REFERENCE_PREFIX.length).split(VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE).join(VARIABLE_PATH_SEPARATOR_TOKEN_STYLE);
|
|
86
|
+
const variable = styleValue.slice(VARIABLE_REFERENCE_PREFIX.length).split(VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE).map(presetVariable => kebabCase(presetVariable)).join(VARIABLE_PATH_SEPARATOR_TOKEN_STYLE);
|
|
87
87
|
return `var(--wp--${variable})`;
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -92,13 +92,25 @@ export function getCSSVarFromStyleValue(styleValue) {
|
|
|
92
92
|
/**
|
|
93
93
|
* Capitalizes the first letter in a string.
|
|
94
94
|
*
|
|
95
|
-
* @param
|
|
95
|
+
* @param string The string whose first letter the function will capitalize.
|
|
96
96
|
*
|
|
97
|
-
* @return
|
|
97
|
+
* @return String with the first letter capitalized.
|
|
98
98
|
*/
|
|
99
99
|
|
|
100
|
-
export function upperFirst(
|
|
101
|
-
|
|
100
|
+
export function upperFirst(string) {
|
|
101
|
+
const [firstLetter, ...rest] = string;
|
|
102
102
|
return firstLetter.toUpperCase() + rest.join('');
|
|
103
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Converts an array of strings into a camelCase string.
|
|
106
|
+
*
|
|
107
|
+
* @param strings The strings to join into a camelCase string.
|
|
108
|
+
*
|
|
109
|
+
* @return camelCase string.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
export function camelCaseJoin(strings) {
|
|
113
|
+
const [firstItem, ...rest] = strings;
|
|
114
|
+
return firstItem.toLowerCase() + rest.map(upperFirst).join('');
|
|
115
|
+
}
|
|
104
116
|
//# sourceMappingURL=utils.js.map
|
|
@@ -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,
|
|
1
|
+
{"version":3,"sources":["@wordpress/style-engine/src/styles/utils.ts"],"names":["get","kebabCase","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","map","presetVariable","join","string","firstLetter","rest","toUpperCase","camelCaseJoin","strings","firstItem","toLowerCase"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,EAAcC,SAAd,QAA+B,QAA/B;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,EAKe;AACrB,QAAMC,UAA8B,GAAGV,GAAG,CAAEM,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,GAAGlB,GAAG,CAAEM,KAAF,EAASE,IAAT,CAA9C;;AACA,MAAK,CAAEU,QAAP,EAAkB;AACjB,WAAO,EAAP;AACA;;AAED,QAAMC,KAAyB,GAAG,EAAlC;;AACA,MAAK,OAAOD,QAAP,KAAoB,QAAzB,EAAoC;AACnCC,IAAAA,KAAK,CAACC,IAAN,CAAY;AACXT,MAAAA,QAAQ,EAAEJ,OAAF,aAAEA,OAAF,uBAAEA,OAAO,CAAEI,QADR;AAEXC,MAAAA,GAAG,EAAEI,QAAQ,CAACK,OAFH;AAGXR,MAAA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CAAEC,WAAF,EAAe,GAAGC,IAAlB,IAA2BF,MAAjC;AACA,SAAOC,WAAW,CAACE,WAAZ,KAA4BD,IAAI,CAACH,IAAL,CAAW,EAAX,CAAnC;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASK,aAAT,CAAwBC,OAAxB,EAAoD;AAC1D,QAAM,CAAEC,SAAF,EAAa,GAAGJ,IAAhB,IAAyBG,OAA/B;AACA,SAAOC,SAAS,CAACC,WAAV,KAA0BL,IAAI,CAACL,GAAL,CAAUN,UAAV,EAAuBQ,IAAvB,CAA6B,EAA7B,CAAjC;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get, kebabCase } 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): GeneratedCSSRule[] {\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.map( ( presetVariable ) => kebabCase( presetVariable ) )\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 The string whose first letter the function will capitalize.\n *\n * @return String with the first letter capitalized.\n */\nexport function upperFirst( string: string ): string {\n\tconst [ firstLetter, ...rest ] = string;\n\treturn firstLetter.toUpperCase() + rest.join( '' );\n}\n\n/**\n * Converts an array of strings into a camelCase string.\n *\n * @param strings The strings to join into a camelCase string.\n *\n * @return camelCase string.\n */\nexport function camelCaseJoin( strings: string[] ): string {\n\tconst [ firstItem, ...rest ] = strings;\n\treturn firstItem.toLowerCase() + rest.map( upperFirst ).join( '' );\n}\n"]}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
5
|
-
declare const _default:
|
|
6
|
-
name: string;
|
|
7
|
-
generate: (style: Style, options: StyleOptions) => GeneratedCSSRule[];
|
|
8
|
-
})[];
|
|
4
|
+
import type { StyleDefinition } from '../../types';
|
|
5
|
+
declare const _default: StyleDefinition[];
|
|
9
6
|
export default _default;
|
|
10
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/border/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/border/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAA6B,eAAe,EAAE,MAAM,aAAa,CAAC;;AAkF9E,wBASE"}
|
|
@@ -4,11 +4,7 @@
|
|
|
4
4
|
import type { Style, StyleOptions } from '../../types';
|
|
5
5
|
declare const background: {
|
|
6
6
|
name: string;
|
|
7
|
-
generate: (style: Style, options: StyleOptions) =>
|
|
8
|
-
selector: string | undefined;
|
|
9
|
-
key: string;
|
|
10
|
-
value: string;
|
|
11
|
-
}[];
|
|
7
|
+
generate: (style: Style, options: StyleOptions) => import("../../types").GeneratedCSSRule[];
|
|
12
8
|
};
|
|
13
9
|
export default background;
|
|
14
10
|
//# sourceMappingURL=background.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../../src/styles/color/background.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,UAAU;;sBAEI,KAAK,WAAW,YAAY
|
|
1
|
+
{"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../../src/styles/color/background.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,UAAU;;sBAEI,KAAK,WAAW,YAAY;CAQ/C,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -4,11 +4,7 @@
|
|
|
4
4
|
import type { Style, StyleOptions } from '../../types';
|
|
5
5
|
declare const gradient: {
|
|
6
6
|
name: string;
|
|
7
|
-
generate: (style: Style, options: StyleOptions) =>
|
|
8
|
-
selector: string | undefined;
|
|
9
|
-
key: string;
|
|
10
|
-
value: string;
|
|
11
|
-
}[];
|
|
7
|
+
generate: (style: Style, options: StyleOptions) => import("../../types").GeneratedCSSRule[];
|
|
12
8
|
};
|
|
13
9
|
export default gradient;
|
|
14
10
|
//# sourceMappingURL=gradient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradient.d.ts","sourceRoot":"","sources":["../../../src/styles/color/gradient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,QAAQ;;sBAEM,KAAK,WAAW,YAAY
|
|
1
|
+
{"version":3,"file":"gradient.d.ts","sourceRoot":"","sources":["../../../src/styles/color/gradient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,QAAQ;;sBAEM,KAAK,WAAW,YAAY;CAQ/C,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
name: string;
|
|
3
|
-
generate: (style: import("../../types").Style, options: import("../../types").StyleOptions) =>
|
|
4
|
-
selector: string | undefined;
|
|
5
|
-
key: string;
|
|
6
|
-
value: string;
|
|
7
|
-
}[];
|
|
3
|
+
generate: (style: import("../../types").Style, options: import("../../types").StyleOptions) => import("../../types").GeneratedCSSRule[];
|
|
8
4
|
}[];
|
|
9
5
|
export default _default;
|
|
10
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/color/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/color/index.ts"],"names":[],"mappings":";;;;AAOA,wBAA8C"}
|
|
@@ -4,11 +4,7 @@
|
|
|
4
4
|
import type { Style, StyleOptions } from '../../types';
|
|
5
5
|
declare const text: {
|
|
6
6
|
name: string;
|
|
7
|
-
generate: (style: Style, options: StyleOptions) =>
|
|
8
|
-
selector: string | undefined;
|
|
9
|
-
key: string;
|
|
10
|
-
value: string;
|
|
11
|
-
}[];
|
|
7
|
+
generate: (style: Style, options: StyleOptions) => import("../../types").GeneratedCSSRule[];
|
|
12
8
|
};
|
|
13
9
|
export default text;
|
|
14
10
|
//# sourceMappingURL=text.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/styles/color/text.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,IAAI;;sBAEU,KAAK,WAAW,YAAY
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/styles/color/text.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,IAAI;;sBAEU,KAAK,WAAW,YAAY;CAG/C,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -4,11 +4,7 @@
|
|
|
4
4
|
import type { Style, StyleOptions } from '../../types';
|
|
5
5
|
declare const _default: {
|
|
6
6
|
name: string;
|
|
7
|
-
generate: (style: Style, options: StyleOptions) =>
|
|
8
|
-
selector: string | undefined;
|
|
9
|
-
key: string;
|
|
10
|
-
value: string;
|
|
11
|
-
}[];
|
|
7
|
+
generate: (style: Style, options: StyleOptions) => import("../../types").GeneratedCSSRule[];
|
|
12
8
|
}[];
|
|
13
9
|
export default _default;
|
|
14
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/shadow/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/shadow/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;;;;;AAUvD,wBAA0B"}
|
|
@@ -4,11 +4,7 @@
|
|
|
4
4
|
import type { Style, StyleOptions } from '../../types';
|
|
5
5
|
declare const _default: {
|
|
6
6
|
name: string;
|
|
7
|
-
generate: (style: Style, options: StyleOptions) =>
|
|
8
|
-
selector: string | undefined;
|
|
9
|
-
key: string;
|
|
10
|
-
value: string;
|
|
11
|
-
}[];
|
|
7
|
+
generate: (style: Style, options: StyleOptions) => import("../../types").GeneratedCSSRule[];
|
|
12
8
|
}[];
|
|
13
9
|
export default _default;
|
|
14
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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
|
|
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"}
|
|
@@ -12,11 +12,7 @@ import type { CssRulesKeys, GeneratedCSSRule, Style, StyleOptions } from '../typ
|
|
|
12
12
|
*
|
|
13
13
|
* @return GeneratedCSSRule[] CSS rules.
|
|
14
14
|
*/
|
|
15
|
-
export declare function generateRule(style: Style, options: StyleOptions, path: string[], ruleKey: string):
|
|
16
|
-
selector: string | undefined;
|
|
17
|
-
key: string;
|
|
18
|
-
value: string;
|
|
19
|
-
}[];
|
|
15
|
+
export declare function generateRule(style: Style, options: StyleOptions, path: string[], ruleKey: string): GeneratedCSSRule[];
|
|
20
16
|
/**
|
|
21
17
|
* Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.
|
|
22
18
|
*
|
|
@@ -40,9 +36,17 @@ export declare function getCSSVarFromStyleValue(styleValue: string): string;
|
|
|
40
36
|
/**
|
|
41
37
|
* Capitalizes the first letter in a string.
|
|
42
38
|
*
|
|
43
|
-
* @param
|
|
39
|
+
* @param string The string whose first letter the function will capitalize.
|
|
44
40
|
*
|
|
45
|
-
* @return
|
|
41
|
+
* @return String with the first letter capitalized.
|
|
42
|
+
*/
|
|
43
|
+
export declare function upperFirst(string: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Converts an array of strings into a camelCase string.
|
|
46
|
+
*
|
|
47
|
+
* @param strings The strings to join into a camelCase string.
|
|
48
|
+
*
|
|
49
|
+
* @return camelCase string.
|
|
46
50
|
*/
|
|
47
|
-
export declare function
|
|
51
|
+
export declare function camelCaseJoin(strings: string[]): string;
|
|
48
52
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/styles/utils.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EACX,YAAY,EACZ,gBAAgB,EAChB,KAAK,EAEL,YAAY,EACZ,MAAM,UAAU,CAAC;AAOlB;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/styles/utils.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EACX,YAAY,EACZ,gBAAgB,EAChB,KAAK,EAEL,YAAY,EACZ,MAAM,UAAU,CAAC;AAOlB;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,MAAM,GACb,gBAAgB,EAAE,CAYpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EAAE,EACd,QAAQ,EAAE,YAAY,EACtB,oBAAoB,GAAE,MAAM,EAAyC,GACnE,gBAAgB,EAAE,CAqCpB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAE,UAAU,EAAE,MAAM,GAAI,MAAM,CAapE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAE,MAAM,EAAE,MAAM,GAAI,MAAM,CAGnD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAE,OAAO,EAAE,MAAM,EAAE,GAAI,MAAM,CAGzD"}
|
package/build-types/types.d.ts
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import type { CSSProperties } from 'react';
|
|
5
|
-
declare type
|
|
6
|
-
export
|
|
5
|
+
declare type BoxVariant = 'margin' | 'padding';
|
|
6
|
+
export interface Box<T extends BoxVariant | undefined = undefined> {
|
|
7
7
|
top?: CSSProperties[T extends undefined ? 'top' : `${T}Top`];
|
|
8
8
|
right?: CSSProperties[T extends undefined ? 'right' : `${T}Right`];
|
|
9
9
|
bottom?: CSSProperties[T extends undefined ? 'bottom' : `${T}Bottom`];
|
|
10
10
|
left?: CSSProperties[T extends undefined ? 'left' : `${T}Left`];
|
|
11
|
-
}
|
|
12
|
-
export declare type
|
|
13
|
-
export
|
|
14
|
-
color?: CSSProperties[`border${Capitalize<
|
|
15
|
-
style?: CSSProperties[`border${Capitalize<
|
|
16
|
-
width?: CSSProperties[`border${Capitalize<
|
|
17
|
-
}
|
|
11
|
+
}
|
|
12
|
+
export declare type BoxEdge = 'top' | 'right' | 'bottom' | 'left';
|
|
13
|
+
export interface BorderIndividualStyles<T extends BoxEdge> {
|
|
14
|
+
color?: CSSProperties[`border${Capitalize<T>}Color`];
|
|
15
|
+
style?: CSSProperties[`border${Capitalize<T>}Style`];
|
|
16
|
+
width?: CSSProperties[`border${Capitalize<T>}Width`];
|
|
17
|
+
}
|
|
18
18
|
export interface Style {
|
|
19
19
|
border?: {
|
|
20
20
|
color?: CSSProperties['borderColor'];
|
|
@@ -58,17 +58,17 @@ export interface Style {
|
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
export
|
|
61
|
+
export interface CssRulesKeys {
|
|
62
62
|
default: string;
|
|
63
63
|
individual: string;
|
|
64
|
-
}
|
|
65
|
-
export
|
|
64
|
+
}
|
|
65
|
+
export interface StyleOptions {
|
|
66
66
|
/**
|
|
67
67
|
* CSS selector for the generated style.
|
|
68
68
|
*/
|
|
69
69
|
selector?: string;
|
|
70
|
-
}
|
|
71
|
-
export
|
|
70
|
+
}
|
|
71
|
+
export interface GeneratedCSSRule {
|
|
72
72
|
selector?: string;
|
|
73
73
|
value: string;
|
|
74
74
|
/**
|
|
@@ -76,10 +76,13 @@ export declare type GeneratedCSSRule = {
|
|
|
76
76
|
* E.g. `paddingTop` instead of `padding-top`.
|
|
77
77
|
*/
|
|
78
78
|
key: string;
|
|
79
|
-
}
|
|
79
|
+
}
|
|
80
|
+
export interface GenerateFunction {
|
|
81
|
+
(style: Style, options: StyleOptions): GeneratedCSSRule[];
|
|
82
|
+
}
|
|
80
83
|
export interface StyleDefinition {
|
|
81
84
|
name: string;
|
|
82
|
-
generate?:
|
|
85
|
+
generate?: GenerateFunction;
|
|
83
86
|
}
|
|
84
87
|
export {};
|
|
85
88
|
//# 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,
|
|
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,UAA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C;QAChD,QAAQ,CAAC,EAAE,aAAa,CAAE,YAAY,CAAE,CAAC;KACzC,CAAC;IACF,QAAQ,CAAC,EAAE;QACV,IAAI,CAAC,EAAE;YACN,KAAK,CAAC,EAAE;gBACP,IAAI,CAAC,EAAE,aAAa,CAAE,OAAO,CAAE,CAAC;aAChC,CAAC;SACF,CAAC;KACF,CAAC;CACF;AAED,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC5B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,gBAAgB;IAChC,CAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,GAAI,gBAAgB,EAAE,CAAC;CAC5D;AAED,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC5B"}
|
|
@@ -12,7 +12,7 @@ if ( class_exists( 'WP_Style_Engine_CSS_Declarations' ) ) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Holds, sanitizes, processes and prints CSS declarations for the
|
|
15
|
+
* Holds, sanitizes, processes and prints CSS declarations for the Style Engine.
|
|
16
16
|
*
|
|
17
17
|
* @access private
|
|
18
18
|
*/
|
|
@@ -12,7 +12,7 @@ if ( class_exists( 'WP_Style_Engine_CSS_Rule' ) ) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Holds, sanitizes, processes and prints CSS declarations for the
|
|
15
|
+
* Holds, sanitizes, processes and prints CSS declarations for the Style Engine.
|
|
16
16
|
*
|
|
17
17
|
* @access private
|
|
18
18
|
*/
|
|
@@ -12,7 +12,7 @@ if ( class_exists( 'WP_Style_Engine_CSS_Rules_Store' ) ) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Holds, sanitizes, processes and prints CSS declarations for the
|
|
15
|
+
* Holds, sanitizes, processes and prints CSS declarations for the Style Engine.
|
|
16
16
|
*
|
|
17
17
|
* @access private
|
|
18
18
|
*/
|
|
@@ -85,7 +85,7 @@ class WP_Style_Engine_Processor {
|
|
|
85
85
|
* Optional. An array of options. Default empty array.
|
|
86
86
|
*
|
|
87
87
|
* @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
|
|
88
|
-
* @type bool $prettify Whether to add new lines and indents to output. Default is the
|
|
88
|
+
* @type bool $prettify Whether to add new lines and indents to output. Default is to inherit the value of the global constant `SCRIPT_DEBUG`, if it is defined.
|
|
89
89
|
* }
|
|
90
90
|
*
|
|
91
91
|
* @return string The computed CSS.
|
package/docs/toc.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"title": "@wordpress/style-engine Using the Style Engine to generate block supports styles",
|
|
4
|
+
"slug": "using-the-style-engine-with-block-supports",
|
|
5
|
+
"markdown_source": "../packages/style-engine/docs/using-the-style-engine-with-block-supports.md",
|
|
6
|
+
"parent": "packages-style-engine"
|
|
7
|
+
}
|
|
8
|
+
]
|
|
@@ -46,45 +46,105 @@ array(
|
|
|
46
46
|
*/
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
## Use case
|
|
50
|
+
When [registering a block support](https://developer.wordpress.org/reference/classes/wp_block_supports/register/), it is possible to pass an 'apply' callback in the block support config array to add or extend block support attributes with "class" or "style" properties.
|
|
51
|
+
|
|
52
|
+
If a block has opted into the block support, the values of "class" and "style" will be applied to the block element's "class" and "style" attributes accordingly when rendered in the frontend HTML. Note, this applies only to server-side rendered blocks, for example, the [Site Title block](https://developer.wordpress.org/block-editor/reference-guides/core-blocks/#site-title).
|
|
53
|
+
|
|
54
|
+
The callback receives `$block_type` and `$block_attributes` as arguments. The `style` attribute within `$block_attributes` only contains the raw style object, if any styles have been set for the block, and not any CSS or classnames to be applied to the block's HTML elements.
|
|
55
|
+
|
|
56
|
+
Here is where `wp_style_engine_get_styles` comes in handy: it will generate CSS and, if appropriate, classnames to be added to the "style" and "class" HTML attributes in the final rendered block markup.
|
|
57
|
+
|
|
58
|
+
Here is a _very_ simplified version of how the [color block support](https://github.com/WordPress/gutenberg/tree/HEAD/lib/block-supports/color.php) works:
|
|
59
|
+
|
|
60
|
+
```php
|
|
61
|
+
function gutenberg_apply_colors_support( $block_type, $block_attributes ) {
|
|
62
|
+
// Get the color styles from the style object.
|
|
63
|
+
$block_color_styles = isset( $block_attributes['style']['color'] ) ? $block_attributes['style']['color'] : null;
|
|
64
|
+
|
|
65
|
+
// Since we only want the color styles, pass the color styles only to the Style Engine.
|
|
66
|
+
$styles = wp_style_engine_get_styles( array( 'color' => $block_color_styles ) );
|
|
67
|
+
|
|
68
|
+
// Return the generated styles to be applied to the block's HTML element.
|
|
69
|
+
return array(
|
|
70
|
+
'style' => $styles['css'],
|
|
71
|
+
'class' => $styles['classnames']
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Register the block support.
|
|
76
|
+
WP_Block_Supports::get_instance()->register(
|
|
77
|
+
'colors',
|
|
78
|
+
array(
|
|
79
|
+
'register_attribute' => 'gutenberg_register_colors_support',
|
|
80
|
+
'apply' => 'gutenberg_apply_colors_support',
|
|
81
|
+
)
|
|
82
|
+
);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
It's important to note that, for now, the Style Engine will only generate styles for the following, core block supports:
|
|
86
|
+
|
|
87
|
+
- border
|
|
88
|
+
- color
|
|
89
|
+
- spacing
|
|
90
|
+
- typography
|
|
91
|
+
|
|
92
|
+
In future releases, it will be possible to extend this list.
|
|
93
|
+
|
|
49
94
|
## Checking for block support and skip serialization
|
|
50
95
|
|
|
51
|
-
Before passing the block style object to the Style Engine,
|
|
96
|
+
Before passing the block style object to the Style Engine, you'll need to take into account:
|
|
52
97
|
|
|
53
98
|
1. whether the theme has elected to support a particular block style, and
|
|
54
99
|
2. whether a block has elected to "skip serialization" of that particular block style, that is, opt-out of automatic application of styles to the block's element (usually in order to do it via the block's internals). See the [block API documentation](https://developer.wordpress.org/block-editor/explanations/architecture/styles/#block-supports-api) for further information.
|
|
55
100
|
|
|
56
101
|
If a block either:
|
|
57
102
|
|
|
58
|
-
- has no support for a
|
|
103
|
+
- has no support for a style, or
|
|
59
104
|
- skips serialization of that style
|
|
60
105
|
|
|
61
|
-
it's likely that you'll want to remove those style values from the style object
|
|
62
|
-
|
|
63
|
-
For example:
|
|
64
|
-
|
|
65
|
-
```php
|
|
66
|
-
// Check if a block has support using block_has_support (https://developer.wordpress.org/reference/functions/block_has_support/)
|
|
67
|
-
$has_padding_support = block_has_support( $block_type, array( 'spacing', 'padding' ), false ); // Returns true.
|
|
68
|
-
$has_margin_support = block_has_support( $block_type, array( 'spacing', 'margin' ), false ); // Returns false.
|
|
69
|
-
|
|
70
|
-
// Check skipping of serialization.
|
|
71
|
-
$should_skip_padding = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' ); // Returns true.
|
|
72
|
-
$should_skip_margin = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' ); // Returns false.
|
|
106
|
+
it's likely that you'll want to remove those style values from the style object before passing it to the Style Engine with help of two functions:
|
|
73
107
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
$spacing_block_styles['padding'] = $has_padding_support && ! $skip_padding ? _wp_array_get( $block_attributes['style'], array( 'spacing', 'padding' ), null ) : null;
|
|
77
|
-
$spacing_block_styles['margin'] = $has_margin_support && ! $skip_margin ? _wp_array_get( $block_attributes['style'], array( 'spacing', 'margin' ), null ) : null;
|
|
108
|
+
- wp_should_skip_block_supports_serialization()
|
|
109
|
+
- block_has_support()
|
|
78
110
|
|
|
79
|
-
|
|
80
|
-
$styles = wp_style_engine_get_styles( array( 'spacing' => $spacing_block_styles ) );
|
|
111
|
+
We can now update the apply callback code above so that we'll only return "style" and "class", where a block has support and it doesn't skip serialization:
|
|
81
112
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
113
|
+
```php
|
|
114
|
+
function gutenberg_apply_colors_support( $block_type, $block_attributes ) {
|
|
115
|
+
// The return value.
|
|
116
|
+
$attributes = array();
|
|
117
|
+
|
|
118
|
+
// Return early if the block skips all serialization for block supports.
|
|
119
|
+
if ( gutenberg_should_skip_block_supports_serialization( $block_type, 'color' ) ) {
|
|
120
|
+
return $attributes;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Checks for support and skip serialization.
|
|
124
|
+
$has_text_support = block_has_support( $block_type, array( 'color', 'text' ), false );
|
|
125
|
+
$has_background_support = block_has_support( $block_type, array( 'color', 'background' ), false );
|
|
126
|
+
$skips_serialization_of_color_text = wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' );
|
|
127
|
+
$skips_serialization_of_color_background = wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' );
|
|
128
|
+
|
|
129
|
+
// Get the color styles from the style object.
|
|
130
|
+
$block_color_styles = isset( $block_attributes['style']['color'] ) ? $block_attributes['style']['color'] : null;
|
|
131
|
+
|
|
132
|
+
// The mutated styles object we're going to pass to wp_style_engine_get_styles().
|
|
133
|
+
$color_block_styles = array();
|
|
134
|
+
|
|
135
|
+
// Set the color style values according to whether the block has support and does not skip serialization.
|
|
136
|
+
$spacing_block_styles['text'] = $has_text_support && ! $skips_serialization_of_color_text ? _wp_array_get( $block_color_styles, array( 'text' ), null ) : null;
|
|
137
|
+
$spacing_block_styles['background'] = $has_background_support && ! $skips_serialization_of_color_background ? _wp_array_get( $block_color_styles, array( 'background' ), null ) : null;
|
|
138
|
+
|
|
139
|
+
// Pass the color styles, excluding those that have no support or skip serialization, to the Style Engine.
|
|
140
|
+
$styles = wp_style_engine_get_styles( array( 'color' => $block_color_styles ) );
|
|
141
|
+
|
|
142
|
+
// Return the generated styles to be applied to the block's HTML element.
|
|
143
|
+
return array(
|
|
144
|
+
'style' => $styles['css'],
|
|
145
|
+
'class' => $styles['classnames']
|
|
146
|
+
);
|
|
147
|
+
}
|
|
88
148
|
```
|
|
89
149
|
|
|
90
150
|
## Generating classnames and CSS custom selectors from presets
|
|
@@ -110,8 +170,8 @@ $preset_font_size = "var:preset|font-size|{$block_attributes['fontSize']}
|
|
|
110
170
|
$preset_background_color = "var:preset|color|{$block_attributes['backgroundColor']}";
|
|
111
171
|
|
|
112
172
|
$block_styles = array(
|
|
113
|
-
|
|
114
|
-
|
|
173
|
+
'typography' => array( 'fontSize' => $preset_font_size ),
|
|
174
|
+
'color' => array( 'background' => $preset_background_color )
|
|
115
175
|
);
|
|
116
176
|
|
|
117
177
|
$styles = wp_style_engine_get_styles(
|
|
@@ -131,12 +191,12 @@ If you don't want the Style Engine to output the CSS custom vars as well, which
|
|
|
131
191
|
|
|
132
192
|
```php
|
|
133
193
|
$options = array(
|
|
134
|
-
|
|
135
|
-
|
|
194
|
+
// Whether to skip converting CSS var:? values to var( --wp--preset--* ) values. Default is `false`.
|
|
195
|
+
'convert_vars_to_classnames' => 'true',
|
|
136
196
|
);
|
|
137
197
|
$styles = wp_style_engine_get_styles(
|
|
138
|
-
|
|
139
|
-
|
|
198
|
+
$block_styles,
|
|
199
|
+
$options
|
|
140
200
|
);
|
|
141
201
|
print_r( $styles );
|
|
142
202
|
|