Skip to content

Parse padding presets for use in sizes values #1240

Open

Description

@joemcgill

As described in this comment. In order to make an image's sizes value more accurately reflect the constraints of its alignment container, we need to incorporate the way padding settings affect the width of the container. For example, in the Twenty Twenty-four theme, the default settings.layout.contentSize setting is 620px, which is the max size that the container will be on larger viewport widths, but that width gets constrained by the padding styles for the site.

image

However, in many cases, theme.json padding styles reference the global padding settings, using CSS variables like var(--wp--preset--spacing--50), which cannot be calculated by the browser when the sizes attribute is parsed, so we will need a way to parse these settings into valid media query values.

Activity

  1. changed the title [-]Parse padding presets for use in sizes values[/-] [+]Parse padding presets for use in `sizes` values[/+] on May 23, 2024
  2. swissspidy commented on May 23, 2024

    @swissspidy
    Member

    An alternative to parsing those values could be to use Optimization Detective, WDYT?

  3. joemcgill commented on May 24, 2024

    @joemcgill
    MemberAuthor

    For sure! But I intentionally don't want to make OD a dependency of this effort for now. I think OD could be used to enhance things but it would be good to have some improvements that could be merged to WP without also merging the whole OD API.

  4. moved this to Not Started/Backlog 📆 in WP Performance Ongoingon May 26, 2024
  5. added
    [Plugin] Enhanced Responsive Images
    and removed
    [Plugin] Enhanced Responsive Images
    on May 26, 2024
  6. joemcgill commented on Dec 18, 2024

    @joemcgill
    MemberAuthor

    Instead of trying to parse the value of CSS variables in theme.json on the server, an alternate idea to explore here is to see if these values can be used by CSS functions if they are included in the initial page render from WordPress.

    So for example, if core is including inline styles using the global-styles-inline-css handle that defines values like --wp--preset--spacing--30, etc. Could they be used directly in sizes values?

  7. mukeshpanchal27 commented on Dec 19, 2024

    @mukeshpanchal27
    Member

    The wp_get_global_stylesheet function is responsible for retrieving the CSS, which we can parse to extract the necessary CSS values for use in the sizes attribute. This approach looks promising based on an initial review and is worth exploring further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Plugin] Enhanced Responsive Images

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions