Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: css variable calc minification #526

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MoritzLoewenstein
Copy link

@MoritzLoewenstein MoritzLoewenstein commented Jun 26, 2023

Trying to implement the following cases:

  1. calc with one argument, just keep inner token.
:root {
  --foo: calc(1px);
}

to

:root {
  --foo: 1px;
}




2. calc inside another calc, inner calc can be converted to parenthesis tokens.

:root {
  -foo: calc(1px + calc(1px + 2px));
}

to

:root {
  -foo: calc(1px + (1px + 2px));
}




3. simplify calc with multiple tokens of the same unit(px, deg etc)

:root {
  --foo: calc(1px + 2px);
}

to

:root {
  --foo: 3px;
}




4. simplify parenthesis expression with multiple tokens of the same unit(px, deg etc)

:root {
  --foo: calc(1px + (1px + 2px));
}

to

:root {
  --foo: calc(1px + 3px);
}




5. remove parenthesis around a single token inside a calc expression

:root {
  -foo: calc(1px + (3px));
}

to

:root {
  -foo: calc(1px + 3px);
}

@KTibow
Copy link

KTibow commented Oct 11, 2023

Is it possible to just take the logic from crate::values::calc and apply it to all properties? That would fix those cases.

@MoritzLoewenstein
Copy link
Author

MoritzLoewenstein commented Oct 22, 2023

Possibly? If you want, you can try that approach, I was struggling to implement the more useful transforms because I dont have any rust experience anyways.

P.S.: Was also struggling with the general approach, how to make it "understand" the math expression without doing too much work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants