Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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