Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ideas:color-object [2014/07/09 19:25] – Add asKeyword(). tabatkinsideas:color-object [2021/10/01 15:36] (current) fantasai
Line 1: Line 1:
 +<note>
 +This has been superseded by work on a common color API for the Web Platform and by work on Typed OM for manipulating CSS syntax specifically.
 +</note>
 +
 +<code idl>
   [Constructor(double r, double g, double b, optional double a=1),   [Constructor(double r, double g, double b, optional double a=1),
    Constructor(RGBAColorInit color)]    Constructor(RGBAColorInit color)]
Line 15: Line 20:
     static RGBAColor fromHex(optional HexColorInit color);     static RGBAColor fromHex(optional HexColorInit color);
          
-    DOMString? asKeyword(); +    DOMString? asName();
-    /* Add fromKeyword()? Add "keyword" serialization type? Needs rounding. */+
          
     DOMString toString(optional DOMString type="rgba");     DOMString toString(optional DOMString type="rgba");
     static readonly attribute Map serializationTypes;     static readonly attribute Map serializationTypes;
   };   };
 +</code>
  
-The toString() method looks up the type in the RGBAColor.serializationTypes Map; if it finds a function, it calls that with the RGBAColor as the sole argument and returns whatever the function returns.  It's preloaded with UA-defined functions for "hex3", "hex6", "rgb", "rgba", "hsl", and "hsla"+The ''toString()'' method looks up the type in the ''RGBAColor.serializationTypes Map''; if it finds a function, it calls that with the ''RGBAColor'' as the sole argument and returns whatever the function returns.  It's preloaded with UA-defined functions for "hex3", "hex6", "rgb", "rgba", "hsl", and "hsla"
  
-Authors can define their own color formats by adding a fromFoo() to RGBAColor, a toFoo() to RGBAColor.prototype, and adding an appropriate serialization tag to RGBAColor.serializationTypes.+Authors can define their own color formats by adding a ''fromFoo()'' to ''RGBAColor'', a ''toFoo()'' to ''RGBAColor.prototype'', and adding an appropriate serialization tag to ''RGBAColor.serializationTypes''.
  
 +<code idl>
   dictionary RGBAColorInit {   dictionary RGBAColorInit {
     double r = 0;     double r = 0;
Line 50: Line 56:
     RGBAColor parseColor(DOMString color, optional Element el);     RGBAColor parseColor(DOMString color, optional Element el);
   };   };
 +</code>
  
-parseColor() takes a string containing any CSS color, and returns an RGBAColor for it.  If the string isn't parseable as a color, throw a SyntaxError exception.+''parseColor()'' takes a string containing any CSS color, and returns an RGBAColor for it.  If the string isn't parseable as a color, throw a ''SyntaxError'' exception.
  
 The optional second argument is used to resolve colors that vary based on the element, such as ''currentcolor'' If such a color is parsed but the second argument is not provided, throw a XXX exception. The optional second argument is used to resolve colors that vary based on the element, such as ''currentcolor'' If such a color is parsed but the second argument is not provided, throw a XXX exception.
 
ideas/color-object.1404959151.txt.gz · Last modified: 2014/12/09 15:48 (external edit)
Recent changes RSS feed Valid XHTML 1.0 Valid CSS Driven by DokuWiki