@@ -4,10 +4,9 @@ Elm.Native.Text.make = function(elm) {
4 elm.Native.Text = elm.Native.Text || {};
4 elm.Native.Text = elm.Native.Text || {};
5 if (elm.Native.Text.values) return elm.Native.Text.values;
5 if (elm.Native.Text.values) return elm.Native.Text.values;
7− var JS = Elm.JavaScript.make(elm);
8− var Utils = Elm.Native.Utils.make(elm);
9− var Color = Elm.Native.Color.make(elm);
10 var Element = Elm.Graphics.Element.make(elm);
7 var Element = Elm.Graphics.Element.make(elm);
8+ var List = Elm.Native.List.make(elm);
9+ var Utils = Elm.Native.Utils.make(elm);
11 var show = Elm.Native.Show.make(elm).show;
10 var show = Elm.Native.Show.make(elm).show;
13 function makeSpaces(s) {
12 function makeSpaces(s) {
@@ -51,13 +50,58 @@ Elm.Native.Text.make = function(elm) {
51 return arr.join('<br/>');
50 return arr.join('<br/>');
54− function toText(str) { return Utils.txt(properEscape(JS.fromString(str))); }
53+ function toText(str) { return Utils.txt(properEscape(str)); }
55+ // conversions from Elm values to CSS
56+ function toTypefaces(list) {
57+ var typefaces = List.toArray(list);
58+ for (var i = typefaces.length; i--; ) {
59+ var typeface = typefaces[i];
60+ if (typeface.contains(' ')) {
61+ typefaces[i] = "'" + typeface + "'";
64+ return typefaces.join(',');
66+ function toLine(line) {
67+ var ctor = line.ctor;
68+ var decoration = ctor === 'Under' ? 'underline' :
69+ ctor === 'Over' ? 'overline' : 'line-through';
70+ return 'text-decoration:' + decoration + ';';
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 + ';';
79+ // setting styles of Text
80+ function style(style, text) {
81+ var newText = '<span style="' + toColor(style.color);
82+ if (style.typeface.ctor !== '[]') {
83+ newText += 'font-family:' + toTypefaces(style.typeface) + ';'
85+ if (style.height.ctor !== "Nothing") {
86+ newText += 'font-size:' + style.height._0 + 'px;';
89+ newText += 'font-weight:bold;';
92+ newText += 'font-style:italic;';
94+ if (style.line.ctor !== 'Nothing') {
95+ newText += toLine(style.line._0);
97+ newText += '">' + Utils.makeText(text) + '</span>'
98+ return Utils.txt(newText);
56 function height(px, text) {
100 function height(px, text) {
57 return { style: 'font-size:' + px + 'px;', text:text }
101 return { style: 'font-size:' + px + 'px;', text:text }
59− function typeface(name, text) {
103+ function typeface(names, text) {
60− return { style: 'font-family:' + name + ';', text:text }
104+ return { style: 'font-family:' + toTypefaces(names) + ';', text:text }
62 function monospace(text) {
106 function monospace(text) {
63 return { style: 'font-family:monospace;', text:text }
107 return { style: 'font-family:monospace;', text:text }
@@ -71,14 +115,8 @@ Elm.Native.Text.make = function(elm) {
71 function link(href, text) {
115 function link(href, text) {
72 return { href: toText(href), text:text };
116 return { href: toText(href), text:text };
74− function underline(text) {
118+ function line(line, text) {
75− return { line: ' underline', text:text };
77− function overline(text) {
78− return { line: ' overline', text:text };
80− function strikeThrough(text) {
81− return { line: ' line-through', text:text };
119+ return { style: toLine(line), text:text };
84 function color(c, text) {
122 function color(c, text) {
@@ -88,8 +126,8 @@ Elm.Native.Text.make = function(elm) {
88 return { style: 'color:' + color + ';', text:text };
126 return { style: 'color:' + color + ';', text:text };
91− function position(align) {
129+ function block(align) {
92− function create(text) {
130+ return function(text) {
93 var raw = {
131 var raw = {
94 ctor :'RawHtml',
132 ctor :'RawHtml',
95 html : Utils.makeText(text),
133 html : Utils.makeText(text),
@@ -100,7 +138,6 @@ Elm.Native.Text.make = function(elm) {
100 var pos = A2(Utils.htmlHeight, 0, raw);
138 var pos = A2(Utils.htmlHeight, 0, raw);
101 return A3(Element.newElement, pos._0, pos._1, raw);
139 return A3(Element.newElement, pos._0, pos._1, raw);
106 function markdown(text, guid) {
143 function markdown(text, guid) {
@@ -115,36 +152,22 @@ Elm.Native.Text.make = function(elm) {
115 return A3(Element.newElement, pos._0, pos._1, raw);
152 return A3(Element.newElement, pos._0, pos._1, raw);
118− var text = position('left');
119− function asText(v) {
120− return text(monospace(toText(show(v))));
123− function plainText(v) {
124− return text(toText(v));
127 return elm.Native.Text.values = {
155 return elm.Native.Text.values = {
128 toText: toText,
156 toText: toText,
130 height : F2(height),
158 height : F2(height),
131 italic : italic,
159 italic : italic,
132 bold : bold,
160 bold : bold,
133− underline : underline,
161+ line : F2(line),
134− overline : overline,
135− strikeThrough : strikeThrough,
136 monospace : monospace,
162 monospace : monospace,
137 typeface : F2(typeface),
163 typeface : F2(typeface),
138 color : F2(color),
164 color : F2(color),
139 link : F2(link),
165 link : F2(link),
167+ leftAligned : block('left'),
168+ rightAligned : block('right'),
169+ centered : block('center'),
141− justified : position('justify'),
170+ justified : block('justify'),
142− centered : position('center'),
143− righted : position('right'),
145− plainText : plainText,
146− markdown : markdown,
171+ markdown : markdown,