Skip to content

WIP: css variable calc minification#526

Draft
MoritzLoewenstein wants to merge 3 commits intoparcel-bundler:masterfrom
MoritzLoewenstein:var-calc-minify
Draft

WIP: css variable calc minification#526
MoritzLoewenstein wants to merge 3 commits intoparcel-bundler:masterfrom
MoritzLoewenstein:var-calc-minify

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);
}

@devongovett devongovett force-pushed the master branch 3 times, most recently from 68a1bff to 3930139 Compare August 20, 2023 17:41
@KTibow
Copy link
Contributor

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.

2 participants