Re: [css-houdini-drafts] [css-typed-om] Do we need separate classes per color space? (#1034)

The unit types don't need separate classes because they're all the exact same thing - a single number paired with a single short string for the unit. There's nothing about their functionality that requires different behavior between them, either - all you want for them is math, and they all act identically there.

Colors are pretty strongly different, imo. Each color function has a different shape; they're generally all three/four-argument, but the arguments represent different things, and have different types. I don't think treating them identically as a list of args helps authors - in `color.r` vs `color.coords[0]`, the latter seems substantially worse in understandability.

This feels similar to trying to unify the transform functions into a single class with a list of args, which would similarly be bad for authors with dubious benefit, if any, to specs and impls.

> Though I'm not sure how to represent the difference between e.g. color(srgb...) and rgb(...). Perhaps an additional type attribute.

I think this is a code smell that suggests the merging wouldn't be a good thing. ^_^

> Note that this requires adding new classes and new methods on every CSSColorValue for every single color space supported

It does, but is this a bad thing?

(I'm also not quite sure what you mean by "on every CSSColorValue" - each new color class would add one method to the superclass; instances would see it by inheritance, as usual. Is there some multiplication of methods I'm missing?)

> (and it makes it harder to support custom color spaces)

I don't understand this bit - what about the design makes it harder? Custom color spaces is just through `color()`, right? That already has the generic design you're suggesting (by necessity; it's the clearest, most direct way to represent `color()` values). Or are you talking about a different sort of custom color feature, maybe something like I sketched in my earlier attempt at Color JS stuff a few years back?

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


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

Received on Wednesday, 12 May 2021 16:17:52 UTC