]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/colors.js
2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo
._hasResource
["dojo.colors"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo
._hasResource
["dojo.colors"] = true;
10 dojo
.provide("dojo.colors");
12 dojo
.getObject("colors", true, dojo
);
14 //TODO: this module appears to break naming conventions
18 // summary: Color utilities
23 // this is a standard conversion prescribed by the CSS3 Color Module
24 var hue2rgb = function(m1
, m2
, h
){
28 if(h6
< 1){ return m1
+ (m2
- m1
) * h6
; }
29 if(2 * h
< 1){ return m2
; }
30 if(3 * h
< 2){ return m1
+ (m2
- m1
) * (2 / 3 - h
) * 6; }
34 dojo
.colorFromRgb = function(/*String*/ color
, /*dojo.Color?*/ obj
){
36 // get rgb(a) array from css-style color declarations
38 // this function can handle all 4 CSS3 Color Module formats: rgb,
39 // rgba, hsl, hsla, including rgb(a) with percentage values.
40 var m
= color
.toLowerCase().match(/^(rgba?|hsla?)\(([\s\.\-,%0-9]+)\)/);
42 var c
= m
[2].split(/\s*,\s*/), l
= c
.length
, t
= m
[1], a
;
43 if((t
== "rgb" && l
== 3) || (t
== "rgba" && l
== 4)){
45 if(r
.charAt(r
.length
- 1) == "%"){
46 // 3 rgb percentage values
47 a
= dojo
.map(c
, function(x
){
48 return parseFloat(x
) * 2.56;
50 if(l
== 4){ a
[3] = c
[3]; }
51 return dojo
.colorFromArray(a
, obj
); // dojo.Color
53 return dojo
.colorFromArray(c
, obj
); // dojo.Color
55 if((t
== "hsl" && l
== 3) || (t
== "hsla" && l
== 4)){
56 // normalize hsl values
57 var H
= ((parseFloat(c
[0]) % 360) + 360) % 360 / 360,
58 S
= parseFloat(c
[1]) / 100,
59 L
= parseFloat(c
[2]) / 100,
60 // calculate rgb according to the algorithm
61 // recommended by the CSS3 Color Module
62 m2
= L
<= 0.5 ? L
* (S
+ 1) : L
+ S
- L
* S
,
65 hue2rgb(m1
, m2
, H
+ 1 / 3) * 256,
66 hue2rgb(m1
, m2
, H
) * 256,
67 hue2rgb(m1
, m2
, H
- 1 / 3) * 256,
70 if(l
== 4){ a
[3] = c
[3]; }
71 return dojo
.colorFromArray(a
, obj
); // dojo.Color
74 return null; // dojo.Color
77 var confine = function(c
, low
, high
){
79 // sanitize a color component by making sure it is a number,
80 // and clamping it to valid values
82 return isNaN(c
) ? high
: c
< low
? low
: c
> high
? high
: c
; // Number
85 dojo
.Color
.prototype.sanitize = function(){
86 // summary: makes sure that the object has correct attributes
88 t
.r
= Math
.round(confine(t
.r
, 0, 255));
89 t
.g
= Math
.round(confine(t
.g
, 0, 255));
90 t
.b
= Math
.round(confine(t
.b
, 0, 255));
91 t
.a
= confine(t
.a
, 0, 1);
92 return this; // dojo.Color
97 dojo
.colors
.makeGrey = function(/*Number*/ g
, /*Number?*/ a
){
98 // summary: creates a greyscale color with an optional alpha
99 return dojo
.colorFromArray([g
, g
, g
, a
]);
102 // mixin all CSS3 named colors not already in _base, along with SVG 1.0 variant spellings
103 dojo
.mixin(dojo
.Color
.named
, {
104 aliceblue
: [240,248,255],
105 antiquewhite
: [250,235,215],
106 aquamarine
: [127,255,212],
107 azure
: [240,255,255],
108 beige
: [245,245,220],
109 bisque
: [255,228,196],
110 blanchedalmond
: [255,235,205],
111 blueviolet
: [138,43,226],
113 burlywood
: [222,184,135],
114 cadetblue
: [95,158,160],
115 chartreuse
: [127,255,0],
116 chocolate
: [210,105,30],
118 cornflowerblue
: [100,149,237],
119 cornsilk
: [255,248,220],
120 crimson
: [220,20,60],
123 darkcyan
: [0,139,139],
124 darkgoldenrod
: [184,134,11],
125 darkgray
: [169,169,169],
126 darkgreen
: [0,100,0],
127 darkgrey
: [169,169,169],
128 darkkhaki
: [189,183,107],
129 darkmagenta
: [139,0,139],
130 darkolivegreen
: [85,107,47],
131 darkorange
: [255,140,0],
132 darkorchid
: [153,50,204],
134 darksalmon
: [233,150,122],
135 darkseagreen
: [143,188,143],
136 darkslateblue
: [72,61,139],
137 darkslategray
: [47,79,79],
138 darkslategrey
: [47,79,79],
139 darkturquoise
: [0,206,209],
140 darkviolet
: [148,0,211],
141 deeppink
: [255,20,147],
142 deepskyblue
: [0,191,255],
143 dimgray
: [105,105,105],
144 dimgrey
: [105,105,105],
145 dodgerblue
: [30,144,255],
146 firebrick
: [178,34,34],
147 floralwhite
: [255,250,240],
148 forestgreen
: [34,139,34],
149 gainsboro
: [220,220,220],
150 ghostwhite
: [248,248,255],
152 goldenrod
: [218,165,32],
153 greenyellow
: [173,255,47],
155 honeydew
: [240,255,240],
156 hotpink
: [255,105,180],
157 indianred
: [205,92,92],
159 ivory
: [255,255,240],
160 khaki
: [240,230,140],
161 lavender
: [230,230,250],
162 lavenderblush
: [255,240,245],
163 lawngreen
: [124,252,0],
164 lemonchiffon
: [255,250,205],
165 lightblue
: [173,216,230],
166 lightcoral
: [240,128,128],
167 lightcyan
: [224,255,255],
168 lightgoldenrodyellow
: [250,250,210],
169 lightgray
: [211,211,211],
170 lightgreen
: [144,238,144],
171 lightgrey
: [211,211,211],
172 lightpink
: [255,182,193],
173 lightsalmon
: [255,160,122],
174 lightseagreen
: [32,178,170],
175 lightskyblue
: [135,206,250],
176 lightslategray
: [119,136,153],
177 lightslategrey
: [119,136,153],
178 lightsteelblue
: [176,196,222],
179 lightyellow
: [255,255,224],
180 limegreen
: [50,205,50],
181 linen
: [250,240,230],
182 magenta
: [255,0,255],
183 mediumaquamarine
: [102,205,170],
184 mediumblue
: [0,0,205],
185 mediumorchid
: [186,85,211],
186 mediumpurple
: [147,112,219],
187 mediumseagreen
: [60,179,113],
188 mediumslateblue
: [123,104,238],
189 mediumspringgreen
: [0,250,154],
190 mediumturquoise
: [72,209,204],
191 mediumvioletred
: [199,21,133],
192 midnightblue
: [25,25,112],
193 mintcream
: [245,255,250],
194 mistyrose
: [255,228,225],
195 moccasin
: [255,228,181],
196 navajowhite
: [255,222,173],
197 oldlace
: [253,245,230],
198 olivedrab
: [107,142,35],
200 orangered
: [255,69,0],
201 orchid
: [218,112,214],
202 palegoldenrod
: [238,232,170],
203 palegreen
: [152,251,152],
204 paleturquoise
: [175,238,238],
205 palevioletred
: [219,112,147],
206 papayawhip
: [255,239,213],
207 peachpuff
: [255,218,185],
211 powderblue
: [176,224,230],
212 rosybrown
: [188,143,143],
213 royalblue
: [65,105,225],
214 saddlebrown
: [139,69,19],
215 salmon
: [250,128,114],
216 sandybrown
: [244,164,96],
217 seagreen
: [46,139,87],
218 seashell
: [255,245,238],
220 skyblue
: [135,206,235],
221 slateblue
: [106,90,205],
222 slategray
: [112,128,144],
223 slategrey
: [112,128,144],
225 springgreen
: [0,255,127],
226 steelblue
: [70,130,180],
228 thistle
: [216,191,216],
230 transparent
: [0, 0, 0, 0],
231 turquoise
: [64,224,208],
232 violet
: [238,130,238],
233 wheat
: [245,222,179],
234 whitesmoke
: [245,245,245],
235 yellowgreen
: [154,205,50]