on master help sign in
Move conversion from colors to CSS to the Color library
commit7e901a668f53655af918a05aa9ad0b70826bb9a6 authorEvan Czaplicki <info@elm-lang.org> dateSat 1 Mar 2014, 20:08 (13 years ago) parent41aa199
2 files changed+13−14
libraries/Native/Color.js+9−2 libraries/Native/Text.js+4−12
libraries/Native/Color.js+9−2
@@ -6,6 +6,12 @@ Elm.Native.Color.make = function(elm) {
66
77 var Utils = Elm.Native.Utils.make(elm);
88
9+ function toCss(c) {
10+ return (c._3 === 1)
11+ ? ('rgb(' + c._0 + ', ' + c._1 + ', ' + c._2 + ')')
12+ : ('rgba(' + c._0 + ', ' + c._1 + ', ' + c._2 + ', ' + c._3 + ')');
13+ }
14+
915 function complement(rgb) {
1016 var hsv = toHSV(rgb);
1117 hsv.hue = (hsv.hue + 180) % 360;
@@ -63,7 +69,8 @@ Elm.Native.Color.make = function(elm) {
6369 return elm.Native.Color.values = {
6470 hsva:F4(hsva),
6571 hsv:F3(hsv),
66− complement:complement
72+ complement:complement,
73+ toCss:toCss
6774 };
6875
69−};
76+};
libraries/Native/Text.js+4−12
@@ -4,6 +4,7 @@ Elm.Native.Text.make = function(elm) {
44 elm.Native.Text = elm.Native.Text || {};
55 if (elm.Native.Text.values) return elm.Native.Text.values;
66
7+ var Color = Elm.Native.Color.make(elm);
78 var Element = Elm.Graphics.Element.make(elm);
89 var List = Elm.Native.List.make(elm);
910 var Utils = Elm.Native.Utils.make(elm);
@@ -69,16 +70,10 @@ Elm.Native.Text.make = function(elm) {
6970 ctor === 'Over' ? 'overline' : 'line-through';
7071 return 'text-decoration:' + decoration + ';';
7172 }
72− function toColor(c) {
73− var color = (c._3 === 1)
74− ? ('rgb(' + c._0 + ', ' + c._1 + ', ' + c._2 + ')')
75− : ('rgba(' + c._0 + ', ' + c._1 + ', ' + c._2 + ', ' + c._3 + ')');
76− return 'color:' + color + ';';
77− }
7873
7974 // setting styles of Text
8075 function style(style, text) {
81− var newText = '<span style="' + toColor(style.color);
76+ var newText = '<span style="color:' + toCss(style.color) + ';'
8277 if (style.typeface.ctor !== '[]') {
8378 newText += 'font-family:' + toTypefaces(style.typeface) + ';'
8479 }
@@ -119,11 +114,8 @@ Elm.Native.Text.make = function(elm) {
119114 return { style: toLine(line), text:text };
120115 }
121116
122− function color(c, text) {
123− var color = (c._3 === 1)
124− ? ('rgb(' + c._0 + ', ' + c._1 + ', ' + c._2 + ')')
125− : ('rgba(' + c._0 + ', ' + c._1 + ', ' + c._2 + ', ' + c._3 + ')');
126− return { style: 'color:' + color + ';', text:text };
117+ function color(color, text) {
118+ return { style: 'color:' + toCss(color) + ';', text:text };
127119 }
128120
129121 function block(align) {