23 * @since 6.1.0 |
23 * @since 6.1.0 |
24 * @since 6.3.0 Added support for text-columns. |
24 * @since 6.3.0 Added support for text-columns. |
25 * @since 6.4.0 Added support for background.backgroundImage. |
25 * @since 6.4.0 Added support for background.backgroundImage. |
26 * @since 6.5.0 Added support for background.backgroundPosition, |
26 * @since 6.5.0 Added support for background.backgroundPosition, |
27 * background.backgroundRepeat and dimensions.aspectRatio. |
27 * background.backgroundRepeat and dimensions.aspectRatio. |
|
28 * @since 6.7.0 Added support for typography.writingMode. |
28 */ |
29 */ |
29 #[AllowDynamicProperties] |
30 #[AllowDynamicProperties] |
30 final class WP_Style_Engine { |
31 final class WP_Style_Engine { |
31 /** |
32 /** |
32 * Style definitions that contain the instructions to parse/output valid Gutenberg styles from a block's attributes. |
33 * Style definitions that contain the instructions to parse/output valid Gutenberg styles from a block's attributes. |
48 * @since 6.1.0 |
49 * @since 6.1.0 |
49 * @var array |
50 * @var array |
50 */ |
51 */ |
51 const BLOCK_STYLE_DEFINITIONS_METADATA = array( |
52 const BLOCK_STYLE_DEFINITIONS_METADATA = array( |
52 'background' => array( |
53 'background' => array( |
53 'backgroundImage' => array( |
54 'backgroundImage' => array( |
54 'property_keys' => array( |
55 'property_keys' => array( |
55 'default' => 'background-image', |
56 'default' => 'background-image', |
56 ), |
57 ), |
57 'value_func' => array( self::class, 'get_url_or_value_css_declaration' ), |
58 'value_func' => array( self::class, 'get_url_or_value_css_declaration' ), |
58 'path' => array( 'background', 'backgroundImage' ), |
59 'path' => array( 'background', 'backgroundImage' ), |
59 ), |
60 ), |
60 'backgroundPosition' => array( |
61 'backgroundPosition' => array( |
61 'property_keys' => array( |
62 'property_keys' => array( |
62 'default' => 'background-position', |
63 'default' => 'background-position', |
63 ), |
64 ), |
64 'path' => array( 'background', 'backgroundPosition' ), |
65 'path' => array( 'background', 'backgroundPosition' ), |
65 ), |
66 ), |
66 'backgroundRepeat' => array( |
67 'backgroundRepeat' => array( |
67 'property_keys' => array( |
68 'property_keys' => array( |
68 'default' => 'background-repeat', |
69 'default' => 'background-repeat', |
69 ), |
70 ), |
70 'path' => array( 'background', 'backgroundRepeat' ), |
71 'path' => array( 'background', 'backgroundRepeat' ), |
71 ), |
72 ), |
72 'backgroundSize' => array( |
73 'backgroundSize' => array( |
73 'property_keys' => array( |
74 'property_keys' => array( |
74 'default' => 'background-size', |
75 'default' => 'background-size', |
75 ), |
76 ), |
76 'path' => array( 'background', 'backgroundSize' ), |
77 'path' => array( 'background', 'backgroundSize' ), |
|
78 ), |
|
79 'backgroundAttachment' => array( |
|
80 'property_keys' => array( |
|
81 'default' => 'background-attachment', |
|
82 ), |
|
83 'path' => array( 'background', 'backgroundAttachment' ), |
77 ), |
84 ), |
78 ), |
85 ), |
79 'color' => array( |
86 'color' => array( |
80 'text' => array( |
87 'text' => array( |
81 'property_keys' => array( |
88 'property_keys' => array( |
296 'letterSpacing' => array( |
303 'letterSpacing' => array( |
297 'property_keys' => array( |
304 'property_keys' => array( |
298 'default' => 'letter-spacing', |
305 'default' => 'letter-spacing', |
299 ), |
306 ), |
300 'path' => array( 'typography', 'letterSpacing' ), |
307 'path' => array( 'typography', 'letterSpacing' ), |
|
308 ), |
|
309 'writingMode' => array( |
|
310 'property_keys' => array( |
|
311 'default' => 'writing-mode', |
|
312 ), |
|
313 'path' => array( 'typography', 'writingMode' ), |
301 ), |
314 ), |
302 ), |
315 ), |
303 ); |
316 ); |
304 |
317 |
305 /** |
318 /** |
439 |
452 |
440 if ( ! static::is_valid_style_value( $style_value ) ) { |
453 if ( ! static::is_valid_style_value( $style_value ) ) { |
441 continue; |
454 continue; |
442 } |
455 } |
443 |
456 |
444 $parsed_styles['classnames'] = array_merge( $parsed_styles['classnames'], static::get_classnames( $style_value, $style_definition ) ); |
457 $classnames = static::get_classnames( $style_value, $style_definition ); |
445 $parsed_styles['declarations'] = array_merge( $parsed_styles['declarations'], static::get_css_declarations( $style_value, $style_definition, $options ) ); |
458 if ( ! empty( $classnames ) ) { |
|
459 $parsed_styles['classnames'] = array_merge( $parsed_styles['classnames'], $classnames ); |
|
460 } |
|
461 |
|
462 $css_declarations = static::get_css_declarations( $style_value, $style_definition, $options ); |
|
463 if ( ! empty( $css_declarations ) ) { |
|
464 $parsed_styles['declarations'] = array_merge( $parsed_styles['declarations'], $css_declarations ); |
|
465 } |
446 } |
466 } |
447 } |
467 } |
448 |
468 |
449 return $parsed_styles; |
469 return $parsed_styles; |
450 } |
470 } |