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