[Feature Request] HDR support
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.
Anyone can provide a reliable function resolving APCA score against those new color values?
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:
- Read
color(display-p3 r g b)andcolor(srgb r g b)directly, and convertoklch()andoklab()to Display P3 (OKLab to linear sRGB with Björn Ottosson's matrices, then to linear P3, then P3-encoded). - 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. - Values that need the page to resolve them, such as
light-dark(),color-mix()with variables orcontrast-color(), get no score, so the theme keeps a user-seton-*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?
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.tsand 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
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
themeoption that takes a resolver from a color value to itson-*color - the legacy adapter, the current
parseColor+hasLightForegroundpath 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?
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.
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.