Skip to content

Allow to enforce applying optimisations to custom property values #453

Description

@ygoe

When a CSS declaration contains multiple spaces/tabs or even a line break, all of those is preserved in a function context (like calc()). I believe these could be reduced to a single space (if not removed entirely, I'm not sure about that, sometimes CSS requires spaces between operators/parameters).

Usually the minified file contains only a single line, but with such source code (writted for readability), all the line breaks in the functions are kept and the minified file contains all the line breaks including the following indentation.

Activity

  1. lahmatiy commented on May 7, 2022

    @lahmatiy
    Member

    @ygoe Could you please provide an example? The single case I can imaging is a value of custom property.

  2. ygoe commented on May 7, 2022

    @ygoe
    Author

    Indeed, I observed this with a custom property:

    .something
    {
      --link-hover-color-l: calc(var(--link-color-l)
      	+ max(0%, (100% - var(--link-color-l)) * var(--link-hover-lf))
      	- max(0%, var(--link-color-l) * (0 - (var(--link-hover-lf)))));
    }
  3. lahmatiy commented on Jul 14, 2022

    @lahmatiy
    Member

    Custom properties can contain any content, that's not a regular value but a part of it when substituted. Removing anything from a custom property may break something. So CSSO do nothing with such values for now. Probably we need to add an option to enforce optimisation for such value in case you are sure it doesn't break anything in your case.

  4. changed the title [-]Collapse whitespace with line break[/-] [+]Allow to enforce applying optimisations to custom property values[/+] on Jul 14, 2022
  5. idoros commented on Oct 11, 2022

    @idoros

    Custom properties currently get trimmed, which creates a different output for development/production modes:

    .c {
      --x: aaa bbb ; 
      --y: zzz ; 
    }
    /* OUTPUT: removed whitespace before and after the custom properties values */
    .c{--x:aaa bbb;--y:zzz}

    Edit:
    Although this is the opposite of what the author is requesting, I think that the default behavior should preserve the value as is, untrimmed, and an option could be added to select between preserve/trim/min-whitespace

  6. ygoe commented on Oct 12, 2022

    @ygoe
    Author

    What's the difference of these additional spaces? I'm not aware of any situation where it's relevant.

  7. idoros commented on Oct 12, 2022

    @idoros

    getComputedStyle(node).getPropertyValue('--x') returns the untrimmed value

  8. ygoe commented on Oct 12, 2022

    @ygoe
    Author

    I still don't need those extra spaces and cannot imagine a scenario where I would ever need it. CSS usually doesn't preserve such spaces and any application that now does is highly unexpected and probably bad design.

  9. idoros commented on Oct 12, 2022

    @idoros

    I take it back, looking at the csswg it seems that custom properties should be trimmed. Browser implementation currently fail in my case.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions