Re: [csswg-drafts] [css-color-4] Resolving and serializing the opacity property (#8311)

With https://github.com/w3c/csswg-drafts/commit/711296f983ad8bb84ef762dca7155076858b6df5 and https://github.com/w3c/csswg-drafts/commit/d995b3485fb98ee7557449fd0ca7c3e79a11c8c3, `opacity` is now defined with `<opacity-value>` instead of `<alpha-value>`. Below are some suggestions and remaining problems.

---

In [3.3. Transparency: the `opacity` property](https://drafts.csswg.org/css-color-4/#transparency) (CSS Color 4), this sentence seems a bit confusing to me:

  > Opacity in CSS is typically represented using the `<opacity-value>` syntax, for example in the opacity property or as the alpha component in a color function, using the `<alpha-value>` syntax.

This seems clearer: *Opacity in CSS is typically represented using `<x>` syntax, [example for `<x>`], or using the `<y>` syntax, [example for `<y>`]*.

But other specs should only use `<opacity-value>` (which is missing a production rule, unlike `<alpha-value>`) and this section is about the `opacity` property, so it could be simplified to *Opacity in CSS is typically represented using the `<opacity-value>` syntax*.

However, other specs currently use `<'opacity'>` (except [`flood-opacity`](https://drafts.fxtf.org/filter-effects-1/#FloodOpacityProperty) and [`shape-image-threshold`](https://drafts.csswg.org/css-shapes-1/#shape-image-threshold-property), which incorrectly use `<alpha-value>`):

  - `fill-opacity` (SVG 2, Fill Stroke)
  - `stop-opacity` (SVG 2)
  - `stroke-opacity` (SVG 2, Fill Stroke, SVG Strokes)
  - `shape-image-threshold` (CSS Basic Shapes 1)

So it might be simpler to define `opacity` with `<number> | <percentage>` and a prose that requires clamping at computed value time, and `<alpha-value>` with `<'opacity'>` and a prose that requires clamping at parse time.

---

In [15.1 Serializing alpha values](https://drafts.csswg.org/css-color-4/#serializing-alpha-values) (CSS Color 4), the emphasized parts below seem redundant:

  > This applies to any `<color>` value which can take an optional alpha value. **It does not apply to the `opacity` property.**
  >
  > If, **after clamping to the range `[0.0, 1.0]`** the alpha is exactly `1`, it is omitted from the serialization; an implicit value of `1` (fully opaque) is the default.

Besides, one may wonder whether `1.0` as input (tokenized to `1`) can be omitted, because it is not *exactly* `1` and the specs do not clearly define when a component value can be omitted when serializing a specified value, at the moment (see https://github.com/w3c/csswg-drafts/issues/5642#issuecomment-1717185053)

-- 
GitHub Notification of comment by cdoublev
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8311#issuecomment-1892198235 using your GitHub account


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

Received on Monday, 15 January 2024 13:40:55 UTC