forked from elm/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color.js
30 lines (27 loc) · 835 Bytes
/
Color.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Elm.Native.Color = {};
Elm.Native.Color.make = function(elm) {
elm.Native = elm.Native || {};
elm.Native.Color = elm.Native.Color || {};
if (elm.Native.Color.values) return elm.Native.Color.values;
function toCss(c) {
var format = '';
var colors = '';
if (c.ctor === 'RGBA') {
format = 'rgb';
colors = c._0 + ', ' + c._1 + ', ' + c._2;
} else {
format = 'hsl';
colors = (c._0 * 180 / Math.PI) + ', ' +
(c._1 * 100) + '%, ' +
(c._2 * 100) + '%';
}
if (c._3 === 1) {
return format + '(' + colors + ')';
} else {
return format + 'a(' + colors + ', ' + c._3 + ')';
}
}
return elm.Native.Color.values = {
toCss:toCss
};
};