@wordpress/style-engine 0.10.0 → 0.11.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 +34 -2
- package/build/styles/border/index.js +94 -0
- package/build/styles/border/index.js.map +1 -0
- package/build/styles/index.js +3 -1
- package/build/styles/index.js.map +1 -1
- package/build/styles/spacing/margin.js +4 -1
- package/build/styles/spacing/margin.js.map +1 -1
- package/build/styles/spacing/padding.js +4 -1
- package/build/styles/spacing/padding.js.map +1 -1
- package/build/styles/utils.js +25 -9
- package/build/styles/utils.js.map +1 -1
- package/build-module/styles/border/index.js +85 -0
- package/build-module/styles/border/index.js.map +1 -0
- package/build-module/styles/index.js +2 -1
- package/build-module/styles/index.js.map +1 -1
- package/build-module/styles/spacing/margin.js +4 -1
- package/build-module/styles/spacing/margin.js.map +1 -1
- package/build-module/styles/spacing/padding.js +4 -1
- package/build-module/styles/spacing/padding.js.map +1 -1
- package/build-module/styles/utils.js +24 -10
- package/build-module/styles/utils.js.map +1 -1
- package/build-types/styles/border/index.d.ts +10 -0
- package/build-types/styles/border/index.d.ts.map +1 -0
- package/build-types/styles/index.d.ts +3 -7
- package/build-types/styles/index.d.ts.map +1 -1
- package/build-types/styles/spacing/margin.d.ts.map +1 -1
- package/build-types/styles/spacing/padding.d.ts.map +1 -1
- package/build-types/styles/utils.d.ts +16 -7
- package/build-types/styles/utils.d.ts.map +1 -1
- package/build-types/types.d.ts +26 -1
- package/build-types/types.d.ts.map +1 -1
- package/class-wp-style-engine.php +50 -49
- package/package.json +2 -2
- package/src/styles/border/index.ts +145 -0
- package/src/styles/index.ts +7 -1
- package/src/styles/spacing/margin.ts +4 -6
- package/src/styles/spacing/padding.ts +4 -6
- package/src/styles/utils.ts +33 -11
- package/src/test/index.js +51 -0
- package/src/test/utils.js +12 -0
- package/src/types.ts +33 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { GeneratedCSSRule, Style, StyleDefinition, StyleOptions } from '../../types';
|
|
5
|
+
declare const _default: (StyleDefinition | {
|
|
6
|
+
name: string;
|
|
7
|
+
generate: (style: Style, options: StyleOptions) => GeneratedCSSRule[];
|
|
8
|
+
})[];
|
|
9
|
+
export default _default;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/styles/border/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAGX,gBAAgB,EAChB,KAAK,EACL,eAAe,EACf,YAAY,EACZ,MAAM,aAAa,CAAC;;;;;AA+HrB,wBAOE"}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export declare const styleDefinitions: {
|
|
1
|
+
export declare const styleDefinitions: (import("../types").StyleDefinition | {
|
|
2
2
|
name: string;
|
|
3
|
-
generate: (style: import("../types").Style, options: import("../types").StyleOptions) =>
|
|
4
|
-
|
|
5
|
-
key: string;
|
|
6
|
-
value: string;
|
|
7
|
-
}[];
|
|
8
|
-
}[];
|
|
3
|
+
generate: (style: import("../types").Style, options: import("../types").StyleOptions) => import("../types").GeneratedCSSRule[];
|
|
4
|
+
})[];
|
|
9
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,gBAAgB;;;IAK5B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"margin.d.ts","sourceRoot":"","sources":["../../../src/styles/spacing/margin.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,MAAM;;sBAEQ,KAAK,WAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"margin.d.ts","sourceRoot":"","sources":["../../../src/styles/spacing/margin.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,MAAM;;sBAEQ,KAAK,WAAW,YAAY;CAM/C,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"padding.d.ts","sourceRoot":"","sources":["../../../src/styles/spacing/padding.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,OAAO;;sBAEO,KAAK,WAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"padding.d.ts","sourceRoot":"","sources":["../../../src/styles/spacing/padding.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGvD,QAAA,MAAM,OAAO;;sBAEO,KAAK,WAAW,YAAY;CAM/C,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import type { GeneratedCSSRule, Style, StyleOptions } from '../types';
|
|
4
|
+
import type { CssRulesKeys, GeneratedCSSRule, Style, StyleOptions } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Returns a JSON representation of the generated CSS rules.
|
|
7
7
|
*
|
|
@@ -20,14 +20,15 @@ export declare function generateRule(style: Style, options: StyleOptions, path:
|
|
|
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
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
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.
|
|
27
28
|
*
|
|
28
|
-
* @return GeneratedCSSRule[]
|
|
29
|
+
* @return GeneratedCSSRule[] CSS rules.
|
|
29
30
|
*/
|
|
30
|
-
export declare function generateBoxRules(style: Style, options: StyleOptions, path: string[],
|
|
31
|
+
export declare function generateBoxRules(style: Style, options: StyleOptions, path: string[], ruleKeys: CssRulesKeys, individualProperties?: string[]): GeneratedCSSRule[];
|
|
31
32
|
/**
|
|
32
33
|
* Returns a CSS var value from incoming style value following the pattern `var:description|context|slug`.
|
|
33
34
|
*
|
|
@@ -36,4 +37,12 @@ export declare function generateBoxRules(style: Style, options: StyleOptions, pa
|
|
|
36
37
|
* @return string A CSS var value.
|
|
37
38
|
*/
|
|
38
39
|
export declare function getCSSVarFromStyleValue(styleValue: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Capitalizes the first letter in a string.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} str The string whose first letter the function will capitalize.
|
|
44
|
+
*
|
|
45
|
+
* @return string A CSS var value.
|
|
46
|
+
*/
|
|
47
|
+
export declare function upperFirst([firstLetter, ...rest]: string): string;
|
|
39
48
|
//# 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,
|
|
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;;;;IAaf;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,CAmCpB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAE,UAAU,EAAE,MAAM,GAAI,MAAM,CAYpE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAE,CAAE,WAAW,EAAE,GAAG,IAAI,CAAE,EAAE,MAAM,UAE3D"}
|
package/build-types/types.d.ts
CHANGED
|
@@ -9,7 +9,28 @@ export declare type Box<T extends BoxVariants = undefined> = {
|
|
|
9
9
|
bottom?: CSSProperties[T extends undefined ? 'bottom' : `${T}Bottom`];
|
|
10
10
|
left?: CSSProperties[T extends undefined ? 'left' : `${T}Left`];
|
|
11
11
|
};
|
|
12
|
+
export declare type BorderIndividualProperty = 'top' | 'right' | 'bottom' | 'left';
|
|
13
|
+
export declare type BorderIndividualStyles<T extends BorderIndividualProperty> = {
|
|
14
|
+
color?: CSSProperties[`border${Capitalize<string & T>}Color`];
|
|
15
|
+
style?: CSSProperties[`border${Capitalize<string & T>}Style`];
|
|
16
|
+
width?: CSSProperties[`border${Capitalize<string & T>}Width`];
|
|
17
|
+
};
|
|
12
18
|
export interface Style {
|
|
19
|
+
border?: {
|
|
20
|
+
color?: CSSProperties['borderColor'];
|
|
21
|
+
radius?: CSSProperties['borderRadius'] | {
|
|
22
|
+
topLeft?: CSSProperties['borderTopLeftRadius'];
|
|
23
|
+
topRight?: CSSProperties['borderTopRightRadius'];
|
|
24
|
+
bottomLeft?: CSSProperties['borderBottomLeftRadius'];
|
|
25
|
+
bottomRight?: CSSProperties['borderBottomLeftRadius'];
|
|
26
|
+
};
|
|
27
|
+
style?: CSSProperties['borderStyle'];
|
|
28
|
+
width?: CSSProperties['borderWidth'];
|
|
29
|
+
top?: BorderIndividualStyles<'top'>;
|
|
30
|
+
right?: BorderIndividualStyles<'right'>;
|
|
31
|
+
bottom?: BorderIndividualStyles<'bottom'>;
|
|
32
|
+
left?: BorderIndividualStyles<'left'>;
|
|
33
|
+
};
|
|
13
34
|
spacing?: {
|
|
14
35
|
margin?: CSSProperties['margin'] | Box<'margin'>;
|
|
15
36
|
padding?: CSSProperties['padding'] | Box<'padding'>;
|
|
@@ -37,6 +58,10 @@ export interface Style {
|
|
|
37
58
|
};
|
|
38
59
|
};
|
|
39
60
|
}
|
|
61
|
+
export declare type CssRulesKeys = {
|
|
62
|
+
default: string;
|
|
63
|
+
individual: string;
|
|
64
|
+
};
|
|
40
65
|
export declare type StyleOptions = {
|
|
41
66
|
/**
|
|
42
67
|
* CSS selector for the generated style.
|
|
@@ -54,7 +79,7 @@ export declare type GeneratedCSSRule = {
|
|
|
54
79
|
};
|
|
55
80
|
export interface StyleDefinition {
|
|
56
81
|
name: string;
|
|
57
|
-
generate?: (style: Style, options: StyleOptions) => GeneratedCSSRule[];
|
|
82
|
+
generate?: (style: Style, options: StyleOptions, path?: string[], ruleKey?: string) => GeneratedCSSRule[];
|
|
58
83
|
getClassNames?: (style: Style) => string[];
|
|
59
84
|
}
|
|
60
85
|
export {};
|
|
@@ -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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AAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,CACV,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,EACrB,IAAI,CAAC,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE,MAAM,KACZ,gBAAgB,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,CAAE,KAAK,EAAE,KAAK,KAAM,MAAM,EAAE,CAAC;CAC7C"}
|
|
@@ -41,7 +41,7 @@ class WP_Style_Engine {
|
|
|
41
41
|
* The value should be a valid CSS property (string) to match the incoming value, e.g., "color" to match var:preset|color|somePresetSlug.
|
|
42
42
|
* - property_keys => (array) array of keys whose values represent a valid CSS property, e.g., "margin" or "border".
|
|
43
43
|
* - path => (array) a path that accesses the corresponding style value in the block style object.
|
|
44
|
-
* - value_func => (string) the name of a function to generate
|
|
44
|
+
* - value_func => (string) the name of a function to generate a CSS definition array for a particular style object. The output of this function should be `array( "$property" => "$value", ... )`.
|
|
45
45
|
*/
|
|
46
46
|
const BLOCK_STYLE_DEFINITIONS_METADATA = array(
|
|
47
47
|
'color' => array(
|
|
@@ -113,28 +113,28 @@ class WP_Style_Engine {
|
|
|
113
113
|
'path' => array( 'border', 'width' ),
|
|
114
114
|
),
|
|
115
115
|
'top' => array(
|
|
116
|
-
'value_func' => 'static::
|
|
116
|
+
'value_func' => 'static::get_individual_property_css_declarations',
|
|
117
117
|
'path' => array( 'border', 'top' ),
|
|
118
118
|
'css_vars' => array(
|
|
119
119
|
'color' => '--wp--preset--color--$slug',
|
|
120
120
|
),
|
|
121
121
|
),
|
|
122
122
|
'right' => array(
|
|
123
|
-
'value_func' => 'static::
|
|
123
|
+
'value_func' => 'static::get_individual_property_css_declarations',
|
|
124
124
|
'path' => array( 'border', 'right' ),
|
|
125
125
|
'css_vars' => array(
|
|
126
126
|
'color' => '--wp--preset--color--$slug',
|
|
127
127
|
),
|
|
128
128
|
),
|
|
129
129
|
'bottom' => array(
|
|
130
|
-
'value_func' => 'static::
|
|
130
|
+
'value_func' => 'static::get_individual_property_css_declarations',
|
|
131
131
|
'path' => array( 'border', 'bottom' ),
|
|
132
132
|
'css_vars' => array(
|
|
133
133
|
'color' => '--wp--preset--color--$slug',
|
|
134
134
|
),
|
|
135
135
|
),
|
|
136
136
|
'left' => array(
|
|
137
|
-
'value_func' => 'static::
|
|
137
|
+
'value_func' => 'static::get_individual_property_css_declarations',
|
|
138
138
|
'path' => array( 'border', 'left' ),
|
|
139
139
|
'css_vars' => array(
|
|
140
140
|
'color' => '--wp--preset--color--$slug',
|
|
@@ -247,7 +247,7 @@ class WP_Style_Engine {
|
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
/**
|
|
250
|
-
* Checks whether an incoming style value is valid.
|
|
250
|
+
* Checks whether an incoming block style value is valid.
|
|
251
251
|
*
|
|
252
252
|
* @param string? $style_value A single css preset value.
|
|
253
253
|
*
|
|
@@ -302,17 +302,15 @@ class WP_Style_Engine {
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
/**
|
|
305
|
-
* Returns CSS
|
|
305
|
+
* Returns an array of CSS declarations based on valid block style values.
|
|
306
306
|
*
|
|
307
307
|
* @param array $style_value A single raw style value from the generate() $block_styles array.
|
|
308
308
|
* @param array<string> $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
|
|
309
309
|
* @param boolean $should_return_css_vars Whether to try to build and return CSS var values.
|
|
310
310
|
*
|
|
311
|
-
* @return array An array of CSS
|
|
311
|
+
* @return array An array of CSS definitions, e.g., array( "$property" => "$value" ).
|
|
312
312
|
*/
|
|
313
|
-
protected static function
|
|
314
|
-
$rules = array();
|
|
315
|
-
|
|
313
|
+
protected static function get_css_declarations( $style_value, $style_definition, $should_return_css_vars ) {
|
|
316
314
|
if (
|
|
317
315
|
isset( $style_definition['value_func'] ) &&
|
|
318
316
|
is_callable( $style_definition['value_func'] )
|
|
@@ -320,7 +318,8 @@ class WP_Style_Engine {
|
|
|
320
318
|
return call_user_func( $style_definition['value_func'], $style_value, $style_definition );
|
|
321
319
|
}
|
|
322
320
|
|
|
323
|
-
$
|
|
321
|
+
$css_declarations = array();
|
|
322
|
+
$style_property_keys = $style_definition['property_keys'];
|
|
324
323
|
|
|
325
324
|
// Build CSS var values from var:? values, e.g, `var(--wp--css--rule-slug )`
|
|
326
325
|
// Check if the value is a CSS preset and there's a corresponding css_var pattern in the style definition.
|
|
@@ -329,15 +328,15 @@ class WP_Style_Engine {
|
|
|
329
328
|
foreach ( $style_definition['css_vars'] as $css_var_pattern => $property_key ) {
|
|
330
329
|
$slug = static::get_slug_from_preset_value( $style_value, $property_key );
|
|
331
330
|
if ( $slug ) {
|
|
332
|
-
$css_var
|
|
331
|
+
$css_var = strtr(
|
|
333
332
|
$css_var_pattern,
|
|
334
333
|
array( '$slug' => $slug )
|
|
335
334
|
);
|
|
336
|
-
$
|
|
335
|
+
$css_declarations[ $style_property_keys['default'] ] = "var($css_var)";
|
|
337
336
|
}
|
|
338
337
|
}
|
|
339
338
|
}
|
|
340
|
-
return $
|
|
339
|
+
return $css_declarations;
|
|
341
340
|
}
|
|
342
341
|
|
|
343
342
|
// Default rule builder.
|
|
@@ -345,19 +344,19 @@ class WP_Style_Engine {
|
|
|
345
344
|
// for styles such as margins and padding.
|
|
346
345
|
if ( is_array( $style_value ) ) {
|
|
347
346
|
foreach ( $style_value as $key => $value ) {
|
|
348
|
-
$individual_property
|
|
349
|
-
$
|
|
347
|
+
$individual_property = sprintf( $style_property_keys['individual'], _wp_to_kebab_case( $key ) );
|
|
348
|
+
$css_declarations[ $individual_property ] = $value;
|
|
350
349
|
}
|
|
351
350
|
} else {
|
|
352
|
-
$
|
|
351
|
+
$css_declarations[ $style_property_keys['default'] ] = $style_value;
|
|
353
352
|
}
|
|
354
353
|
|
|
355
|
-
return $
|
|
354
|
+
return $css_declarations;
|
|
356
355
|
}
|
|
357
356
|
|
|
358
357
|
/**
|
|
359
|
-
* Returns
|
|
360
|
-
*
|
|
358
|
+
* Returns classname and CSS from a block styles object.
|
|
359
|
+
* Return values are parsed based on the instructions in BLOCK_STYLE_DEFINITIONS_METADATA.
|
|
361
360
|
*
|
|
362
361
|
* @param array $block_styles An array of styles from a block's attributes.
|
|
363
362
|
* @param array $options array(
|
|
@@ -375,7 +374,7 @@ class WP_Style_Engine {
|
|
|
375
374
|
return null;
|
|
376
375
|
}
|
|
377
376
|
|
|
378
|
-
$
|
|
377
|
+
$css_declarations = array();
|
|
379
378
|
$classnames = array();
|
|
380
379
|
$should_return_css_vars = isset( $options['css_vars'] ) && true === $options['css_vars'];
|
|
381
380
|
|
|
@@ -391,36 +390,38 @@ class WP_Style_Engine {
|
|
|
391
390
|
continue;
|
|
392
391
|
}
|
|
393
392
|
|
|
394
|
-
$classnames
|
|
395
|
-
$
|
|
393
|
+
$classnames = array_merge( $classnames, static::get_classnames( $style_value, $style_definition ) );
|
|
394
|
+
$css_declarations = array_merge( $css_declarations, static::get_css_declarations( $style_value, $style_definition, $should_return_css_vars ) );
|
|
396
395
|
}
|
|
397
396
|
}
|
|
398
397
|
|
|
399
398
|
// Build CSS rules output.
|
|
400
|
-
$
|
|
401
|
-
$
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
$css[] = $filtered_css . ';';
|
|
399
|
+
$css_selector = isset( $options['selector'] ) ? $options['selector'] : null;
|
|
400
|
+
$filtered_css_declarations = array();
|
|
401
|
+
|
|
402
|
+
if ( ! empty( $css_declarations ) ) {
|
|
403
|
+
// Generate inline style declarations.
|
|
404
|
+
foreach ( $css_declarations as $css_property => $css_value ) {
|
|
405
|
+
$filtered_css_declaration = esc_html( safecss_filter_attr( "{$css_property}: {$css_value}" ) );
|
|
406
|
+
if ( ! empty( $filtered_css_declaration ) ) {
|
|
407
|
+
$filtered_css_declarations[] = $filtered_css_declaration . ';';
|
|
410
408
|
}
|
|
411
409
|
}
|
|
412
410
|
}
|
|
413
411
|
|
|
412
|
+
// The return object.
|
|
413
|
+
$styles_output = array();
|
|
414
|
+
|
|
414
415
|
// Return css, if any.
|
|
415
|
-
if ( ! empty( $
|
|
416
|
+
if ( ! empty( $filtered_css_declarations ) ) {
|
|
416
417
|
// Return an entire rule if there is a selector.
|
|
417
|
-
if ( $
|
|
418
|
-
$
|
|
419
|
-
$
|
|
420
|
-
$
|
|
421
|
-
$styles_output['css'] = $
|
|
418
|
+
if ( $css_selector ) {
|
|
419
|
+
$css_rule = "$css_selector { ";
|
|
420
|
+
$css_rule .= implode( ' ', $filtered_css_declarations );
|
|
421
|
+
$css_rule .= ' }';
|
|
422
|
+
$styles_output['css'] = $css_rule;
|
|
422
423
|
} else {
|
|
423
|
-
$styles_output['css'] = implode( ' ', $
|
|
424
|
+
$styles_output['css'] = implode( ' ', $filtered_css_declarations );
|
|
424
425
|
}
|
|
425
426
|
}
|
|
426
427
|
|
|
@@ -434,7 +435,7 @@ class WP_Style_Engine {
|
|
|
434
435
|
|
|
435
436
|
|
|
436
437
|
/**
|
|
437
|
-
* Style value parser that returns a CSS
|
|
438
|
+
* Style value parser that returns a CSS definition array comprising style properties
|
|
438
439
|
* that have keys representing individual style properties, otherwise known as longhand CSS properties.
|
|
439
440
|
* e.g., "$style_property-$individual_feature: $value;", which could represent the following:
|
|
440
441
|
* "border-{top|right|bottom|left}-{color|width|style}: {value};" or,
|
|
@@ -443,13 +444,13 @@ class WP_Style_Engine {
|
|
|
443
444
|
* @param array $style_value A single raw Gutenberg style attributes value for a CSS property.
|
|
444
445
|
* @param array $individual_property_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
|
|
445
446
|
*
|
|
446
|
-
* @return array
|
|
447
|
+
* @return array An array of CSS definitions, e.g., array( "$property" => "$value" ).
|
|
447
448
|
*/
|
|
448
|
-
protected static function
|
|
449
|
-
$
|
|
449
|
+
protected static function get_individual_property_css_declarations( $style_value, $individual_property_definition ) {
|
|
450
|
+
$css_declarations = array();
|
|
450
451
|
|
|
451
452
|
if ( ! is_array( $style_value ) || empty( $style_value ) || empty( $individual_property_definition['path'] ) ) {
|
|
452
|
-
return $
|
|
453
|
+
return $css_declarations;
|
|
453
454
|
}
|
|
454
455
|
|
|
455
456
|
// The first item in $individual_property_definition['path'] array tells us the style property, e.g., "border".
|
|
@@ -477,11 +478,11 @@ class WP_Style_Engine {
|
|
|
477
478
|
);
|
|
478
479
|
$value = "var($css_var)";
|
|
479
480
|
}
|
|
480
|
-
$individual_css_property
|
|
481
|
-
$
|
|
481
|
+
$individual_css_property = sprintf( $style_definition['property_keys']['individual'], $individual_property_key );
|
|
482
|
+
$css_declarations[ $individual_css_property ] = $value;
|
|
482
483
|
}
|
|
483
484
|
}
|
|
484
|
-
return $
|
|
485
|
+
return $css_declarations;
|
|
485
486
|
}
|
|
486
487
|
}
|
|
487
488
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/style-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "WordPress Style engine.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "a80eeb62ec7cb1418b9915c277e084a29d6665e3"
|
|
38
38
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type {
|
|
5
|
+
BorderIndividualStyles,
|
|
6
|
+
BorderIndividualProperty,
|
|
7
|
+
GeneratedCSSRule,
|
|
8
|
+
Style,
|
|
9
|
+
StyleDefinition,
|
|
10
|
+
StyleOptions,
|
|
11
|
+
} from '../../types';
|
|
12
|
+
import { generateRule, generateBoxRules, upperFirst } from '../utils';
|
|
13
|
+
|
|
14
|
+
const color = {
|
|
15
|
+
name: 'color',
|
|
16
|
+
generate: (
|
|
17
|
+
style: Style,
|
|
18
|
+
options: StyleOptions,
|
|
19
|
+
path: string[] = [ 'border', 'color' ],
|
|
20
|
+
ruleKey: string = 'borderColor'
|
|
21
|
+
): GeneratedCSSRule[] => {
|
|
22
|
+
return generateRule( style, options, path, ruleKey );
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const radius = {
|
|
27
|
+
name: 'radius',
|
|
28
|
+
generate: ( style: Style, options: StyleOptions ): GeneratedCSSRule[] => {
|
|
29
|
+
return generateBoxRules(
|
|
30
|
+
style,
|
|
31
|
+
options,
|
|
32
|
+
[ 'border', 'radius' ],
|
|
33
|
+
{
|
|
34
|
+
default: 'borderRadius',
|
|
35
|
+
individual: 'border%sRadius',
|
|
36
|
+
},
|
|
37
|
+
[ 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' ]
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const borderStyle = {
|
|
43
|
+
name: 'style',
|
|
44
|
+
generate: (
|
|
45
|
+
style: Style,
|
|
46
|
+
options: StyleOptions,
|
|
47
|
+
path: string[] = [ 'border', 'style' ],
|
|
48
|
+
ruleKey: string = 'borderStyle'
|
|
49
|
+
): GeneratedCSSRule[] => {
|
|
50
|
+
return generateRule( style, options, path, ruleKey );
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const width = {
|
|
55
|
+
name: 'width',
|
|
56
|
+
generate: (
|
|
57
|
+
style: Style,
|
|
58
|
+
options: StyleOptions,
|
|
59
|
+
path: string[] = [ 'border', 'width' ],
|
|
60
|
+
ruleKey: string = 'borderWidth'
|
|
61
|
+
): GeneratedCSSRule[] => {
|
|
62
|
+
return generateRule( style, options, path, ruleKey );
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const borderDefinitionsWithIndividualStyles: StyleDefinition[] = [
|
|
67
|
+
color,
|
|
68
|
+
borderStyle,
|
|
69
|
+
width,
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Returns a curried generator function with the individual border property ('top' | 'right' | 'bottom' | 'left') baked in.
|
|
74
|
+
*
|
|
75
|
+
* @param individualProperty Individual border property ('top' | 'right' | 'bottom' | 'left').
|
|
76
|
+
*
|
|
77
|
+
* @return StyleDefinition[ 'generate' ]
|
|
78
|
+
*/
|
|
79
|
+
const createBorderGenerateFunction =
|
|
80
|
+
( individualProperty: BorderIndividualProperty ) =>
|
|
81
|
+
( style: Style, options: StyleOptions ) => {
|
|
82
|
+
const styleValue:
|
|
83
|
+
| BorderIndividualStyles< typeof individualProperty >
|
|
84
|
+
| undefined = style?.border?.[ individualProperty ];
|
|
85
|
+
|
|
86
|
+
if ( ! styleValue ) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return borderDefinitionsWithIndividualStyles.reduce(
|
|
91
|
+
(
|
|
92
|
+
acc: GeneratedCSSRule[],
|
|
93
|
+
borderDefinition: StyleDefinition
|
|
94
|
+
): GeneratedCSSRule[] => {
|
|
95
|
+
const key = borderDefinition.name;
|
|
96
|
+
if (
|
|
97
|
+
styleValue.hasOwnProperty( key ) &&
|
|
98
|
+
typeof borderDefinition.generate === 'function'
|
|
99
|
+
) {
|
|
100
|
+
const ruleKey = `border${ upperFirst(
|
|
101
|
+
individualProperty
|
|
102
|
+
) }${ upperFirst( key ) }`;
|
|
103
|
+
acc.push(
|
|
104
|
+
...borderDefinition.generate(
|
|
105
|
+
style,
|
|
106
|
+
options,
|
|
107
|
+
[ 'border', individualProperty, key ],
|
|
108
|
+
ruleKey
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
return acc;
|
|
113
|
+
},
|
|
114
|
+
[]
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const borderTop = {
|
|
119
|
+
name: 'borderTop',
|
|
120
|
+
generate: createBorderGenerateFunction( 'top' ),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const borderRight = {
|
|
124
|
+
name: 'borderRight',
|
|
125
|
+
generate: createBorderGenerateFunction( 'right' ),
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const borderBottom = {
|
|
129
|
+
name: 'borderBottom',
|
|
130
|
+
generate: createBorderGenerateFunction( 'bottom' ),
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const borderLeft = {
|
|
134
|
+
name: 'borderLeft',
|
|
135
|
+
generate: createBorderGenerateFunction( 'left' ),
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export default [
|
|
139
|
+
...borderDefinitionsWithIndividualStyles,
|
|
140
|
+
radius,
|
|
141
|
+
borderTop,
|
|
142
|
+
borderRight,
|
|
143
|
+
borderBottom,
|
|
144
|
+
borderLeft,
|
|
145
|
+
];
|
package/src/styles/index.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
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
8
|
|
|
8
|
-
export const styleDefinitions = [
|
|
9
|
+
export const styleDefinitions = [
|
|
10
|
+
...border,
|
|
11
|
+
...color,
|
|
12
|
+
...spacing,
|
|
13
|
+
...typography,
|
|
14
|
+
];
|
|
@@ -7,12 +7,10 @@ import { generateBoxRules } from '../utils';
|
|
|
7
7
|
const margin = {
|
|
8
8
|
name: 'margin',
|
|
9
9
|
generate: ( style: Style, options: StyleOptions ) => {
|
|
10
|
-
return generateBoxRules(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
'margin'
|
|
15
|
-
);
|
|
10
|
+
return generateBoxRules( style, options, [ 'spacing', 'margin' ], {
|
|
11
|
+
default: 'margin',
|
|
12
|
+
individual: 'margin%s',
|
|
13
|
+
} );
|
|
16
14
|
},
|
|
17
15
|
};
|
|
18
16
|
|
|
@@ -7,12 +7,10 @@ import { generateBoxRules } from '../utils';
|
|
|
7
7
|
const padding = {
|
|
8
8
|
name: 'padding',
|
|
9
9
|
generate: ( style: Style, options: StyleOptions ) => {
|
|
10
|
-
return generateBoxRules(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
'padding'
|
|
15
|
-
);
|
|
10
|
+
return generateBoxRules( style, options, [ 'spacing', 'padding' ], {
|
|
11
|
+
default: 'padding',
|
|
12
|
+
individual: 'padding%s',
|
|
13
|
+
} );
|
|
16
14
|
},
|
|
17
15
|
};
|
|
18
16
|
|