Make WordPress Core


Ignore:
Timestamp:
09/20/2022 03:41:44 PM (2 years ago)
Author:
hellofromTonya
Message:

Editor: Introduces fluid typography and uses Style Engine.

This commit introduces fluid typography block supports and switches to use the Style Engine for typography and colors.

The motivation for fluid typography block supports:

"Fluid typography" describes how a site's font sizes adapt to every change in screen size, for example, growing larger as the viewport width increases, or smaller as it decreases.

Font sizes can smoothly scale between minimum and maximum viewport widths.

Typography changes introduced from Gutenberg:

  • Uses the Style Engine to generate the CSS and classnames in wp_apply_typography_support().
  • Introduces wp_typography_get_preset_inline_style_value() for backwards-compatibility.
  • Introduces a private internal function called wp_get_typography_value_and_unit(), for checking and getting typography unit and value.
  • Introduces a private internal function called wp_get_computed_fluid_typography_value(), for an internal implementation of CSS clamp().
  • Deprecates wp_typography_get_css_variable_inline_style().

References:

Follow-up to [53076], [52302], [52069], [51089], [50761], [49226].

Props ramonopoly, youknowriad, aristath, oandregal, aaronrobertshaw, cbirdsong, jorgefilipecosta, ironprogrammer, hellofromTonya.
See #56467.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/deprecated.php

    r54157 r54260  
    44574457    return $metadata;
    44584458}
     4459
     4460/**
     4461 * Generates an inline style for a typography feature e.g. text decoration,
     4462 * text transform, and font style.
     4463 *
     4464 * @since 5.8.0
     4465 * @access private
     4466 * @deprecated 6.1.0 Use wp_style_engine_get_styles() introduced in 6.1.0.
     4467 *
     4468 * @see wp_style_engine_get_styles()
     4469 *
     4470 * @param array  $attributes   Block's attributes.
     4471 * @param string $feature      Key for the feature within the typography styles.
     4472 * @param string $css_property Slug for the CSS property the inline style sets.
     4473 * @return string CSS inline style.
     4474 */
     4475function wp_typography_get_css_variable_inline_style( $attributes, $feature, $css_property ) {
     4476    _deprecated_function( __FUNCTION__, '6.1.0', 'wp_style_engine_get_styles()' );
     4477
     4478    // Retrieve current attribute value or skip if not found.
     4479    $style_value = _wp_array_get( $attributes, array( 'style', 'typography', $feature ), false );
     4480    if ( ! $style_value ) {
     4481        return;
     4482    }
     4483
     4484    // If we don't have a preset CSS variable, we'll assume it's a regular CSS value.
     4485    if ( strpos( $style_value, "var:preset|{$css_property}|" ) === false ) {
     4486        return sprintf( '%s:%s;', $css_property, $style_value );
     4487    }
     4488
     4489    /*
     4490     * We have a preset CSS variable as the style.
     4491     * Get the style value from the string and return CSS style.
     4492     */
     4493    $index_to_splice = strrpos( $style_value, '|' ) + 1;
     4494    $slug            = substr( $style_value, $index_to_splice );
     4495
     4496    // Return the actual CSS inline style e.g. `text-decoration:var(--wp--preset--text-decoration--underline);`.
     4497    return sprintf( '%s:var(--wp--preset--%s--%s);', $css_property, $css_property, $slug );
     4498}
Note: See TracChangeset for help on using the changeset viewer.