W3C home > Mailing lists > Public > www-style@w3.org > July 2014

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

From: Simon Sapin <simon.sapin@exyr.org>
Date: Tue, 08 Jul 2014 01:48:44 +0100
Message-ID: <53BB3FEC.6080607@exyr.org>
To: www-style@w3.org
On 08/07/14 00:27, Tab Atkins Jr. 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?

A trick I’ve seen in stuff made by Lea Verou to use the browser’s color 
parsing code is to set e.g. someElement.style.color to the string to 
parse, then get getComputedStyle(someElement).color, which is in rgb() 
or rgba() format and much easier to hand-parse.


> 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).

-- 
Simon Sapin
Received on Tuesday, 8 July 2014 00:49:09 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 8 July 2014 00:49:10 UTC