Merged in feature/81-dev-dev01 (pull request #5)

auto-patch  81-dev-dev01-2023-12-05T22_45_26

* auto-patch  81-dev-dev01-2023-12-05T22_45_26
This commit is contained in:
Tony Volpe
2023-12-05 23:05:59 +00:00
parent ba16964e7a
commit 725d3043d5
1463 changed files with 142461 additions and 89421 deletions

View File

@@ -85,12 +85,13 @@ class WP_Style_Engine_Processor {
* Gets the CSS rules as a string.
*
* @since 6.1.0
* @since 6.4.0 The Optimization is no longer the default.
*
* @param array $options {
* Optional. An array of options. Default empty array.
*
* @type bool $optimize Whether to optimize the CSS output, e.g. combine rules.
* Default true.
* Default false.
* @type bool $prettify Whether to add new lines and indents to output.
* Defaults to whether the `SCRIPT_DEBUG` constant is defined.
* }
@@ -98,7 +99,7 @@ class WP_Style_Engine_Processor {
*/
public function get_css( $options = array() ) {
$defaults = array(
'optimize' => true,
'optimize' => false,
'prettify' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG,
);
$options = wp_parse_args( $options, $defaults );

View File

@@ -22,35 +22,46 @@
* @access private
* @since 6.1.0
* @since 6.3.0 Added support for text-columns.
* @since 6.4.0 Added support for background.backgroundImage.
*/
#[AllowDynamicProperties]
final class WP_Style_Engine {
/**
* Style definitions that contain the instructions to
* parse/output valid Gutenberg styles from a block's attributes.
* Style definitions that contain the instructions to parse/output valid Gutenberg styles from a block's attributes.
*
* For every style definition, the following properties are valid:
*
* - classnames => (array) An array of classnames to be returned for block styles.
* The key is a classname or pattern.
* A value of `true` means the classname should be applied always.
* Otherwise, a valid CSS property (string) to match the incoming value,
* e.g. "color" to match var:preset|color|somePresetSlug.
* - css_vars => (array) An array of key value pairs used to generate CSS var values.
* The key is a CSS var pattern, whose `$slug` fragment will be replaced with a preset slug.
* The value should be a valid CSS property (string) to match the incoming value,
* e.g. "color" to match var:preset|color|somePresetSlug.
* - property_keys => (array) An array of keys whose values represent a valid CSS property,
* e.g. "margin" or "border".
* - path => (array) A path that accesses the corresponding style value in the block style object.
* - 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", ... )`.
* - classnames => (array) an array of classnames to be returned for block styles. The key is a classname or pattern.
* A value of `true` means the classname should be applied always. Otherwise, a valid CSS property (string)
* to match the incoming value, e.g., "color" to match var:preset|color|somePresetSlug.
* - css_vars => (array) an array of key value pairs used to generate CSS var values.
* The key should be the CSS property name that matches the second element of the preset string value,
* i.e., "color" in var:preset|color|somePresetSlug. The value is a CSS var pattern (e.g. `--wp--preset--color--$slug`),
* whose `$slug` fragment will be replaced with the preset slug, which is the third element of the preset string value,
* i.e., `somePresetSlug` in var:preset|color|somePresetSlug.
* - property_keys => (array) array of keys whose values represent a valid CSS property, e.g., "margin" or "border".
* - path => (array) a path that accesses the corresponding style value in the block style object.
* - 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", ... )`.
*
* @since 6.1.0
* @var array
*/
const BLOCK_STYLE_DEFINITIONS_METADATA = array(
'background' => array(
'backgroundImage' => array(
'property_keys' => array(
'default' => 'background-image',
),
'value_func' => array( self::class, 'get_url_or_value_css_declaration' ),
'path' => array( 'background', 'backgroundImage' ),
),
'backgroundSize' => array(
'property_keys' => array(
'default' => 'background-size',
),
'path' => array( 'background', 'backgroundSize' ),
),
),
'color' => array(
'text' => array(
'property_keys' => array(
@@ -70,6 +81,9 @@ final class WP_Style_Engine {
'default' => 'background-color',
),
'path' => array( 'color', 'background' ),
'css_vars' => array(
'color' => '--wp--preset--color--$slug',
),
'classnames' => array(
'has-background' => true,
'has-$slug-background-color' => 'color',
@@ -80,6 +94,9 @@ final class WP_Style_Engine {
'default' => 'background',
),
'path' => array( 'color', 'gradient' ),
'css_vars' => array(
'gradient' => '--wp--preset--gradient--$slug',
),
'classnames' => array(
'has-background' => true,
'has-$slug-gradient-background' => 'gradient',
@@ -583,6 +600,42 @@ final class WP_Style_Engine {
return $css_declarations;
}
/**
* Style value parser that constructs a CSS definition array comprising a single CSS property and value.
* If the provided value is an array containing a `url` property, the function will return a CSS definition array
* with a single property and value, with `url` escaped and injected into a CSS `url()` function,
* e.g., array( 'background-image' => "url( '...' )" ).
*
* @since 6.4.0
*
* @param array $style_value A single raw style value from $block_styles array.
* @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
* @return string[] An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
*/
protected static function get_url_or_value_css_declaration( $style_value, $style_definition ) {
if ( empty( $style_value ) ) {
return array();
}
$css_declarations = array();
if ( isset( $style_definition['property_keys']['default'] ) ) {
$value = null;
if ( ! empty( $style_value['url'] ) ) {
$value = "url('" . $style_value['url'] . "')";
} elseif ( is_string( $style_value ) ) {
$value = $style_value;
}
if ( null !== $value ) {
$css_declarations[ $style_definition['property_keys']['default'] ] = $value;
}
}
return $css_declarations;
}
/**
* Returns compiled CSS from CSS declarations.
*
@@ -624,7 +677,7 @@ final class WP_Style_Engine {
* e.g. 'block-supports' or 'global-styles'. Default 'block-supports'.
* When set, the style engine will attempt to store the CSS rules.
* @type bool $optimize Whether to optimize the CSS output, e.g. combine rules.
* Default true.
* Default false.
* @type bool $prettify Whether to add new lines and indents to output.
* Defaults to whether the `SCRIPT_DEBUG` constant is defined.
* }