vuetify icon indicating copy to clipboard operation
vuetify copied to clipboard

[Feature Request] HDR support

Open multiflexi opened this issue 2 months ago • 6 comments

Problem to solve

Currently it is impossible to create Vuetify themes with HDR/WCG support, colours are limited to 8-bit sRGB.

Proposed solution

Implement https://www.w3.org/TR/css-color-hdr-1 . Currently works in Chrome.

multiflexi avatar Sep 06 '26 10:09 multiflexi

Anyone can provide a reliable function resolving APCA score against those new color values?

J-Sek avatar Nov 01 '26 11:11 J-Sek

On the APCA question: APCA-W3 (0.0.98G-4g) already has a Display P3 variant, displayP3toY, with the same 2.4 exponent and P3 coefficients (0.2289829594805780, 0.6917492625852380, 0.0792677779341829). So a function for the new values could work like this:

  1. Read color(display-p3 r g b) and color(srgb r g b) directly, and convert oklch() and oklab() to Display P3 (OKLab to linear sRGB with Björn Ottosson's matrices, then to linear P3, then P3-encoded).
  2. Clamp each channel to 0..1, since APCA only models SDR (HDR handling would stay outside this change), and compute Y with displayP3toY, or with the sRGB coefficients for sRGB values.
  3. Values that need the page to resolve them, such as light-dark(), color-mix() with variables or contrast-color(), get no score, so the theme keeps a user-set on-* color or falls back to the current default.

util/color/APCA.ts would then take two Y values, with a small converter in front of it. I can open a PR with this and tests against apca-w3's own results, if the direction works for you. One question: should an oklch value outside P3 be clamped per channel, or reduced in chroma the way CSS Color 4 gamut mapping does?

hskl18 avatar Nov 12 '26 16:11 hskl18

Thanks for sharing apca-w3 package. We cannot introduce 3rd-party dependency and it is a bit problematic to borrow its code. Also feels like a lot of work that belongs to some build-time helper in most cases. Not a problem, just observation.

I imagine we could have v5.0 built in a way that accepts a adapter for a foreground resolver.

  • built-in legacy adapter would resolve all RGB/HSL/HEX colors using existing apca.ts and simple parser we have
  • advanced adapter based on 3rd party libraries could be shared in docs.. with disclaimer that it would pull those libraries into bundle.. potentially a dead weight in most cases
  • (v) => 'contrast-color(${v})' could be a modern alternative
  • noop (no calculation) would be a default

J-Sek avatar Nov 16 '26 01:11 J-Sek

Understood on apca-w3, no dependency and no borrowed code.

The adapter idea works for me. If you'd like a PR against dev, I'd keep it to the seam and the built-in pieces:

  • a theme option that takes a resolver from a color value to its on-* color
  • the legacy adapter, the current parseColor + hasLightForeground path for hex, rgb and hsl values
  • noop as the default
  • a docs section with the contrast-color() resolver and a note that third-party adapters add their libraries to the bundle

One question before I start: with noop as the default, should an on-* color the theme doesn't set fall back to theme-on-light or theme-on-dark as now, or stay unset?

hskl18 avatar Nov 16 '26 04:11 hskl18

Let's not rush into implementation yet. I think we need to revive #22765, then replace ~120 places that depend on theme variables being pure numeric "r,g,b" values. The consequence of "noop" as default could be a need for color props to accept tuple [color, on-color] which needs some consideration to performance implications that could force us to add separate text-color prop instead.

It is a heavy task that requires coordination with v0. I'd say having another PR to audit and compare might slow us down. However, if you somehow figure it out and use your own workaround for HDR/oklch colors with v4.x in production, we could definitely learn something.

J-Sek avatar Nov 16 '26 13:11 J-Sek

Understood, I'll hold off on a PR. Thanks for laying out what a noop default would pull in: reviving #22765, the places that expect r,g,b theme values, and the color props.

hskl18 avatar Nov 16 '26 18:11 hskl18