postcss / postcss-calc

PostCSS plugin to reduce calc()
MIT License
212 stars 34 forks source link

[Feature Request]: Support for `min()` and `max()` #189

Open arayutw opened 1 year ago

arayutw commented 1 year ago

What should be improved?

I would like min() and max() to shrink similar to calc(). Within these functions, calculations can be performed without using calc(). So, it would be helpful if they can also perform shrinking similar to calc().

Describe the solution you would like

width: min(360px, 100% - 24px - 24px)

=>

width: min(360px, 100% - 48px)

Possible alternatives

I would be happy to consider your request, even though it is unsolicited.

Additional context

No response

Are you willing to work on this?

ludofischer commented 1 year ago

That would be a good feature, in all likelihood you would need to go into https://github.com/postcss/postcss-calc/blob/master/src/lib/reducer.js, and stect max() or min() when the node type is Function. The only problem is if there is not enough information in the AST to do that, unfortunately the parser is generated by an unmaintained port of the Bison parser generator and is unwieldy to work with.