w3c / css-houdini-drafts

Mirror of https://hg.css-houdini.org/drafts
https://drafts.css-houdini.org/
Other
1.84k stars 141 forks source link

[css-typed-om] the `CSSColor` constructor is wrong #1032

Closed svgeesus closed 3 years ago

svgeesus commented 3 years ago

In 4.6 CSSColorValue objects, the CSSColor constructor is given as

[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)]
interface CSSColor : CSSColorValue {
    constructor
(sequence<(DOMString or CSSNumberish)> variant
);
    /* CSSColor(["foo", 0, 1, .5], ["bar", "yellow"], 1, fallbackColor) */
    /* or just make the alpha and fallback successive optional args? */
};

This has several problems.

Firstly, the colorspace slot is not named which makes it hard to refer to it; in CSS Color 4 the colorspace parameter to color() is mandatory.

Secondly, the alpha is also not named, but needs to be so that the various toFoo methods can require that it be filled in. And yes it should be an optional argument.

Thirdly, the non-normative comment uses the old syntax with multiple fallbacks. It also uses a colorspace "foo" which is not a dashed ident, nor is it a prefefined colorspace, so Typed OM would currently return a SyntaxError. I suggest replacing the comment with

/ CSSColor(["display-p3", 0, 1, .5] /

So the constructor should take:

  1. The colorspace
  2. The parameters (if the intent really is to restrict to predefined RGB spaces, these could be called r g and b; but that also cuts out xyz and lab from being represented. Otherwise, make them a sequence of parameters
  3. Optionally, the alpha
tabatkins commented 3 years ago

Ah yeah, sorry, looks like I had the commit fixing this sitting in my local copy for a few weeks. Pushed now, apologies for letting you review an old version.

That old version you're looking at is the older complicated syntax, back when we had fallbacks. Now it's much more straightforward, with a colorspace argument, and then just a numeric channels array.