Re: [css-houdini-drafts] [css-typed-om] Inputs for the CSSColorValue constructors (#1014)

Hi all. Author of Popmotion and Framer Motion here, I've spent a fair amount of time working with value ranges and I'd love to ditch a bunch of code in favour of a native color API. Here's some thoughts after reading this discussion.

First of all I recognise there's a huge value in maintaining familiar APIs like the RGB 0-255 range. But for me, that doesn't override the potential wins from option 1.

All finite ranges are IMO best described as ranges 0-1. It's a range that has intrinsically semantic meaning and is easy to visualise mentally. Standardising it between percentage/bounded time/8 bit color makes interpolating between these ranges straightforward.

On the keyed object idea, it'd of course be possible to make `new RGB({ r: 0 ... })` to differentiate between 0-1 and 0-255. But compared to `new RGB(0, 0.5, 1)` this would be unwieldy and only promote wrapper libraries that simplify the syntax. I'd prefer to reduce the keystrokes and the payload. `new RGB(0.5)` should forward-fill with `0, 0, 1`, the common-sense defaults. The short-hand for blue: 1 is `new RGB(0,0,1)`, shorter than `new RGB({ b: 1 })`.

> I don't think an initialization dict, in general, is the best pattern here - most of the arguments are required, and there's already a well-known and established order for them

I totally agree with this, it's even in the name!

> Right, and that should be a Color class 

I agree with this too. But Houdini has been developing for a while and I can easily imagine another 5(ish?) years waiting for a proper Color API. This should and can be it. It can be renamed, or not, I don't overly care. I just want a sane, native color API. The semantics in this sense really don't have me concerned.

Ultimately I think if the existing standard was `rgb(0, 0.5, 1)` and we were debating `0-255` this issue wouldn't get past the opening post. As @LeaVerou mentions, it's rooted in legacy and even accepts decimals now. If I want a half-value it's far more intuitive to think "0.5" than "127.5". This is a choice that can be chose for everyone consuming this new API in the coming decades.

-- 
GitHub Notification of comment by mattgperry
Please view or discuss this issue at https://github.com/w3c/css-houdini-drafts/issues/1014#issuecomment-745485759 using your GitHub account


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

Received on Tuesday, 15 December 2020 18:40:54 UTC