[csswg-drafts] [css-shapes] Allow optional rounding parameter for `polygon()` (#9843)

LeaVerou has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-shapes] Allow optional rounding parameter for `polygon()` ==
## Motivation

There is a wide variety of use cases where authors want to clip or mask an element based on a shape that is basically a simple polygon plus rounding. Right now this is exceedingly complicated to do by hand (since you'd need to use `path()`), and practically impossible to do with the same flexibility of units that `polygon()` supports.

Tons of SO questions about this:
- https://stackoverflow.com/questions/31765345/how-to-round-out-corners-when-using-css-clip-path
- https://stackoverflow.com/questions/46417361/clip-path-polygon-with-curve-edges
- https://stackoverflow.com/questions/62176115/clip-path-polygon-rounded-edge
- [Breadcrumb shapes](https://stackoverflow.com/questions/70987632/rounded-corners-and-border-for-clip-path-at-the-same-time)
![image](https://github.com/w3c/csswg-drafts/assets/175836/d150f0d1-326e-4771-89fa-e8f5f8456d76)
- [Speech bubbles where the pointer is not actually a separate element](https://stackoverflow.com/questions/46417361/clip-path-polygon-with-curve-edges):
![image](https://github.com/w3c/csswg-drafts/assets/175836/ec413313-814a-46e8-95d8-ea9cb2e1b93b)
 - Why? E.g. [to crop a picture in that shape](https://stackoverflow.com/questions/73051914/clip-path-curved-edges-background-image-and-triangle)
![image](https://github.com/w3c/csswg-drafts/assets/175836/5798ad52-1487-43a8-8739-e74c3c875904)
- https://stackoverflow.com/questions/62453115/how-to-make-a-rounded-triangle-using-clip-path
- [Rounded parallelogram picture cutout](https://stackoverflow.com/questions/72286820/how-to-create-a-rounded-corner-for-the-pictureimg-tag-in-clip-path-polygon-in) 
![image](https://github.com/w3c/csswg-drafts/assets/175836/84346ff0-0dc2-43ff-a231-8962e4d2d071)
- [Rounded tabs](https://stackoverflow.com/questions/76091116/rounded-clip-path-div)
![image](https://github.com/w3c/csswg-drafts/assets/175836/7e0cf765-9eca-409e-915d-b412a0e231fe)
- https://stackoverflow.com/questions/69634813/rounded-corner-on-clip-path-polygon
- https://stackoverflow.com/questions/74221270/any-idea-how-i-can-make-radial-corners-on-a-clip-path-polygon
- https://stackoverflow.com/questions/75429805/angled-edge-with-css-clip-path-and-rounded-corners
- https://stackoverflow.com/questions/77521892/how-to-curve-a-custom-polygon-element-with-a-clip-path-property 
![image](https://github.com/w3c/csswg-drafts/assets/175836/8ed38dd1-608d-4dae-b242-38e9a3095527)
- https://stackoverflow.com/questions/65045478/css-clip-path-polygon-rounded-borders
- https://stackoverflow.com/questions/51616941/how-to-make-radial-corners-in-clip-path-look-clean
- https://stackoverflow.com/questions/72539766/how-to-make-the-edge-of-a-button-round-with-clip-path
- https://stackoverflow.com/questions/70865868/how-do-i-make-the-edges-of-the-hexagon-image-round
- …and many others

It also reminded me of my [W3Conf 2013](https://www.w3.org/conf/2013sf/) site design:
<img width="463" alt="image" src="https://github.com/w3c/csswg-drafts/assets/175836/2ba8f6f4-8107-4f52-8a9c-d8a2d26ada03">


## The proposal

A good chunk of use cases only requires a single radius for all corners, and I have yet to see a use case that requires different horizontal and vertical radii. Therefore, even something as simple as the following would go a long way.

Change [`polygon()` grammar](https://drafts.csswg.org/css-shapes/#supported-basic-shapes) from:

```
<polygon()> = polygon(
  <'fill-rule'>? ,
  [<length-percentage> <length-percentage>]#
)
```
to
```
<polygon()> = polygon(
  <'fill-rule'>? [<length> radius]?,
  [<length-percentage> <length-percentage>]#
)
```

To cover even more use cases we could also explore allowing `[<length> radius]?` on a per-point basis, to customize rounding for a specific point. This can ship later.

## Rendering

There is always exactly one circle of a given radius that is tangential to each side adjacent to a corner < 180deg.

![image](https://github.com/w3c/csswg-drafts/assets/175836/e5d71a15-ba08-4790-8e46-f770e032bdf7)

For corners >= 180deg, the other side can would be used:

![image](https://github.com/w3c/csswg-drafts/assets/175836/1822c330-e218-4d42-8fa7-7d8a454dd262)


Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/9843 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 24 January 2024 02:44:56 UTC