home/barrin16/ilaaup.org/wp-includes/style-engine/class-wp-style-engine.php 0000644 00000065673 14740064004 0022701 0 ustar 00 (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' ),
),
'backgroundPosition' => array(
'property_keys' => array(
'default' => 'background-position',
),
'path' => array( 'background', 'backgroundPosition' ),
),
'backgroundRepeat' => array(
'property_keys' => array(
'default' => 'background-repeat',
),
'path' => array( 'background', 'backgroundRepeat' ),
),
'backgroundSize' => array(
'property_keys' => array(
'default' => 'background-size',
),
'path' => array( 'background', 'backgroundSize' ),
),
'backgroundAttachment' => array(
'property_keys' => array(
'default' => 'background-attachment',
),
'path' => array( 'background', 'backgroundAttachment' ),
),
),
'color' => array(
'text' => array(
'property_keys' => array(
'default' => 'color',
),
'path' => array( 'color', 'text' ),
'css_vars' => array(
'color' => '--wp--preset--color--$slug',
),
'classnames' => array(
'has-text-color' => true,
'has-$slug-color' => 'color',
),
),
'background' => array(
'property_keys' => array(
'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',
),
),
'gradient' => array(
'property_keys' => array(
'default' => 'background',
),
'path' => array( 'color', 'gradient' ),
'css_vars' => array(
'gradient' => '--wp--preset--gradient--$slug',
),
'classnames' => array(
'has-background' => true,
'has-$slug-gradient-background' => 'gradient',
),
),
),
'border' => array(
'color' => array(
'property_keys' => array(
'default' => 'border-color',
'individual' => 'border-%s-color',
),
'path' => array( 'border', 'color' ),
'classnames' => array(
'has-border-color' => true,
'has-$slug-border-color' => 'color',
),
),
'radius' => array(
'property_keys' => array(
'default' => 'border-radius',
'individual' => 'border-%s-radius',
),
'path' => array( 'border', 'radius' ),
),
'style' => array(
'property_keys' => array(
'default' => 'border-style',
'individual' => 'border-%s-style',
),
'path' => array( 'border', 'style' ),
),
'width' => array(
'property_keys' => array(
'default' => 'border-width',
'individual' => 'border-%s-width',
),
'path' => array( 'border', 'width' ),
),
'top' => array(
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
'path' => array( 'border', 'top' ),
'css_vars' => array(
'color' => '--wp--preset--color--$slug',
),
),
'right' => array(
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
'path' => array( 'border', 'right' ),
'css_vars' => array(
'color' => '--wp--preset--color--$slug',
),
),
'bottom' => array(
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
'path' => array( 'border', 'bottom' ),
'css_vars' => array(
'color' => '--wp--preset--color--$slug',
),
),
'left' => array(
'value_func' => array( self::class, 'get_individual_property_css_declarations' ),
'path' => array( 'border', 'left' ),
'css_vars' => array(
'color' => '--wp--preset--color--$slug',
),
),
),
'shadow' => array(
'shadow' => array(
'property_keys' => array(
'default' => 'box-shadow',
),
'path' => array( 'shadow' ),
'css_vars' => array(
'shadow' => '--wp--preset--shadow--$slug',
),
),
),
'dimensions' => array(
'aspectRatio' => array(
'property_keys' => array(
'default' => 'aspect-ratio',
),
'path' => array( 'dimensions', 'aspectRatio' ),
'classnames' => array(
'has-aspect-ratio' => true,
),
),
'minHeight' => array(
'property_keys' => array(
'default' => 'min-height',
),
'path' => array( 'dimensions', 'minHeight' ),
'css_vars' => array(
'spacing' => '--wp--preset--spacing--$slug',
),
),
),
'spacing' => array(
'padding' => array(
'property_keys' => array(
'default' => 'padding',
'individual' => 'padding-%s',
),
'path' => array( 'spacing', 'padding' ),
'css_vars' => array(
'spacing' => '--wp--preset--spacing--$slug',
),
),
'margin' => array(
'property_keys' => array(
'default' => 'margin',
'individual' => 'margin-%s',
),
'path' => array( 'spacing', 'margin' ),
'css_vars' => array(
'spacing' => '--wp--preset--spacing--$slug',
),
),
),
'typography' => array(
'fontSize' => array(
'property_keys' => array(
'default' => 'font-size',
),
'path' => array( 'typography', 'fontSize' ),
'css_vars' => array(
'font-size' => '--wp--preset--font-size--$slug',
),
'classnames' => array(
'has-$slug-font-size' => 'font-size',
),
),
'fontFamily' => array(
'property_keys' => array(
'default' => 'font-family',
),
'css_vars' => array(
'font-family' => '--wp--preset--font-family--$slug',
),
'path' => array( 'typography', 'fontFamily' ),
'classnames' => array(
'has-$slug-font-family' => 'font-family',
),
),
'fontStyle' => array(
'property_keys' => array(
'default' => 'font-style',
),
'path' => array( 'typography', 'fontStyle' ),
),
'fontWeight' => array(
'property_keys' => array(
'default' => 'font-weight',
),
'path' => array( 'typography', 'fontWeight' ),
),
'lineHeight' => array(
'property_keys' => array(
'default' => 'line-height',
),
'path' => array( 'typography', 'lineHeight' ),
),
'textColumns' => array(
'property_keys' => array(
'default' => 'column-count',
),
'path' => array( 'typography', 'textColumns' ),
),
'textDecoration' => array(
'property_keys' => array(
'default' => 'text-decoration',
),
'path' => array( 'typography', 'textDecoration' ),
),
'textTransform' => array(
'property_keys' => array(
'default' => 'text-transform',
),
'path' => array( 'typography', 'textTransform' ),
),
'letterSpacing' => array(
'property_keys' => array(
'default' => 'letter-spacing',
),
'path' => array( 'typography', 'letterSpacing' ),
),
'writingMode' => array(
'property_keys' => array(
'default' => 'writing-mode',
),
'path' => array( 'typography', 'writingMode' ),
),
),
);
/**
* Util: Extracts the slug in kebab case from a preset string,
* e.g. `heavenly-blue` from `var:preset|color|heavenlyBlue`.
*
* @since 6.1.0
*
* @param string $style_value A single CSS preset value.
* @param string $property_key The CSS property that is the second element of the preset string.
* Used for matching.
* @return string The slug, or empty string if not found.
*/
protected static function get_slug_from_preset_value( $style_value, $property_key ) {
if ( is_string( $style_value ) && is_string( $property_key )
&& str_contains( $style_value, "var:preset|{$property_key}|" )
) {
$index_to_splice = strrpos( $style_value, '|' ) + 1;
return _wp_to_kebab_case( substr( $style_value, $index_to_splice ) );
}
return '';
}
/**
* Util: Generates a CSS var string, e.g. `var(--wp--preset--color--background)`
* from a preset string such as `var:preset|space|50`.
*
* @since 6.1.0
*
* @param string $style_value A single CSS preset value.
* @param string[] $css_vars An associate array of CSS var patterns
* used to generate the var string.
* @return string The CSS var, or an empty string if no match for slug found.
*/
protected static function get_css_var_value( $style_value, $css_vars ) {
foreach ( $css_vars as $property_key => $css_var_pattern ) {
$slug = static::get_slug_from_preset_value( $style_value, $property_key );
if ( static::is_valid_style_value( $slug ) ) {
$var = strtr(
$css_var_pattern,
array( '$slug' => $slug )
);
return "var($var)";
}
}
return '';
}
/**
* Util: Checks whether an incoming block style value is valid.
*
* @since 6.1.0
*
* @param string $style_value A single CSS preset value.
* @return bool
*/
protected static function is_valid_style_value( $style_value ) {
return '0' === $style_value || ! empty( $style_value );
}
/**
* Stores a CSS rule using the provided CSS selector and CSS declarations.
*
* @since 6.1.0
* @since 6.6.0 Added the `$rules_group` parameter.
*
* @param string $store_name A valid store key.
* @param string $css_selector When a selector is passed, the function will return
* a full CSS rule `$selector { ...rules }`
* otherwise a concatenated string of properties and values.
* @param string[] $css_declarations An associative array of CSS definitions,
* e.g. `array( "$property" => "$value", "$property" => "$value" )`.
* @param string $rules_group Optional. A parent CSS selector in the case of nested CSS, or a CSS nested @rule,
* such as `@media (min-width: 80rem)` or `@layer module`.
*/
public static function store_css_rule( $store_name, $css_selector, $css_declarations, $rules_group = '' ) {
if ( empty( $store_name ) || empty( $css_selector ) || empty( $css_declarations ) ) {
return;
}
static::get_store( $store_name )->add_rule( $css_selector, $rules_group )->add_declarations( $css_declarations );
}
/**
* Returns a store by store key.
*
* @since 6.1.0
*
* @param string $store_name A store key.
* @return WP_Style_Engine_CSS_Rules_Store|null
*/
public static function get_store( $store_name ) {
return WP_Style_Engine_CSS_Rules_Store::get_store( $store_name );
}
/**
* Returns classnames and CSS based on the values in a styles object.
*
* Return values are parsed based on the instructions in BLOCK_STYLE_DEFINITIONS_METADATA.
*
* @since 6.1.0
*
* @param array $block_styles The style object.
* @param array $options {
* Optional. An array of options. Default empty array.
*
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns,
* e.g. `var:preset|