Re: [css-color] Exposing browser color parsing to JS

I like the idea, and am all for exposing all the CSS parsing in appropriate primitive chunks. To that end maybe define a CSS.parser with a collection of parsing methods rather than a set of CSS.parseXXX methods?

A few nits about your proposal:
stringifiers operations can't take arguments[1], so you'd need to do it as:
interface RGBAColor {
  ...
  stringifier DOMString ();	 // rgba()
  stringifier DOMString hex3();
  stringifier DOMString hex6();
  ... etc ...

or you have to change the stringifier into a regular method, like:
  DOMString toString(optional DOMString type="rgba");

The HSLAColorInit should default to black like RGBAColorInit and HexColorInit instead of red.

I presume the parseColor method takes color names as well, how about a way to get the color name for an rgb value?

Peter

[1] http://heycam.github.io/webidl/#idl-stringifiers


On Jul 7, 2014, at 4:27 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:

> One of my coworkers brought my attention to
> <http://code.stephenmorley.org/javascript/colour-handling-and-processing/>,
> a library that does basic color manipulation and
> parsing/serialization.  I've seen this sort of thing multiple times,
> and even wrote my own (<http://www.xanthir.com/etc/color.js>).  I've
> also had to write a fairly complete color parser in PHP in the past.
> 
> Given that most/all of this machinery already exists in the browser,
> it's kinda sad that people have to keep reinventing it.  What would
> y'all think about introducing a bit of a helper for this kind of
> thing, that exposes all of the parsing and serialization the browser
> does, and is easily extensible so authors can use it as the basis for
> their own color-using code?
> 
> Here's my first draft of a proposal for it:
> <http://wiki.csswg.org/ideas/color-object>
> 
> Note that this intentionally does not try to interface deeply with the
> OM, as that's meant to be saved for the future OM upgrade based on
> value objects.  You can assign an RGBAColor directly to a CSS
> property, but it'll just stringify (which will have the intended
> effect).
> 
> ~TJ
> 

Received on Wednesday, 9 July 2014 00:08:05 UTC