@@ -4,11 +4,10 @@ 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);
7+ var toCss = Elm.Native.Color.make(elm).toCss;
9− var Color = Elm.Native.Color.make(elm);
10 var Element = Elm.Graphics.Element.make(elm);
8 var Element = Elm.Graphics.Element.make(elm);
11− var show = Elm.Native.Show.make(elm).show;
9+ var List = Elm.Native.List.make(elm);
10+ var Utils = Elm.Native.Utils.make(elm);
13 function makeSpaces(s) {
12 function makeSpaces(s) {
14 if (s.length == 0) { return s; }
13 if (s.length == 0) { return s; }
@@ -51,13 +50,51 @@ 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+ return ctor === 'Under' ? 'underline' :
69+ ctor === 'Over' ? 'overline' : 'line-through';
72+ // setting styles of Text
73+ function style(style, text) {
74+ var newText = '<span style="color:' + toCss(style.color) + ';'
75+ if (style.typeface.ctor !== '[]') {
76+ newText += 'font-family:' + toTypefaces(style.typeface) + ';'
78+ if (style.height.ctor !== "Nothing") {
79+ newText += 'font-size:' + style.height._0 + 'px;';
82+ newText += 'font-weight:bold;';
85+ newText += 'font-style:italic;';
87+ if (style.line.ctor !== 'Nothing') {
88+ newText += 'text-decoration:' + toLine(style.line._0) + ';';
90+ newText += '">' + Utils.makeText(text) + '</span>'
91+ return Utils.txt(newText);
56 function height(px, text) {
93 function height(px, text) {
57 return { style: 'font-size:' + px + 'px;', text:text }
94 return { style: 'font-size:' + px + 'px;', text:text }
59− function typeface(name, text) {
96+ function typeface(names, text) {
60− return { style: 'font-family:' + name + ';', text:text }
97+ return { style: 'font-family:' + toTypefaces(names) + ';', text:text }
62 function monospace(text) {
99 function monospace(text) {
63 return { style: 'font-family:monospace;', text:text }
100 return { style: 'font-family:monospace;', text:text }
@@ -71,25 +108,16 @@ Elm.Native.Text.make = function(elm) {
71 function link(href, text) {
108 function link(href, text) {
72 return { href: toText(href), text:text };
109 return { href: toText(href), text:text };
74− function underline(text) {
111+ function line(line, text) {
75− return { line: ' underline', text:text };
112+ return { style: 'text-decoration:' + toLine(line) + ';', text:text };
77− function overline(text) {
78− return { line: ' overline', text:text };
80− function strikeThrough(text) {
81− return { line: ' line-through', text:text };
84− function color(c, text) {
115+ function color(color, text) {
85− var color = (c._3 === 1)
86− ? ('rgb(' + c._0 + ', ' + c._1 + ', ' + c._2 + ')')
87− : ('rgba(' + c._0 + ', ' + c._1 + ', ' + c._2 + ', ' + c._3 + ')');
88− return { style: 'color:' + color + ';', text:text };
116+ return { style: 'color:' + toCss(color) + ';', text:text };
91− function position(align) {
119+ function block(align) {
92− function create(text) {
120+ return function(text) {
93 var raw = {
121 var raw = {
94 ctor :'RawHtml',
122 ctor :'RawHtml',
95 html : Utils.makeText(text),
123 html : Utils.makeText(text),
@@ -100,7 +128,6 @@ Elm.Native.Text.make = function(elm) {
100 var pos = A2(Utils.htmlHeight, 0, raw);
128 var pos = A2(Utils.htmlHeight, 0, raw);
101 return A3(Element.newElement, pos._0, pos._1, raw);
129 return A3(Element.newElement, pos._0, pos._1, raw);
106 function markdown(text, guid) {
133 function markdown(text, guid) {
@@ -115,36 +142,25 @@ Elm.Native.Text.make = function(elm) {
115 return A3(Element.newElement, pos._0, pos._1, raw);
142 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 = {
145 return elm.Native.Text.values = {
128 toText: toText,
146 toText: toText,
130 height : F2(height),
148 height : F2(height),
131 italic : italic,
149 italic : italic,
132 bold : bold,
150 bold : bold,
133− underline : underline,
151+ line : F2(line),
134− overline : overline,
135− strikeThrough : strikeThrough,
136 monospace : monospace,
152 monospace : monospace,
137 typeface : F2(typeface),
153 typeface : F2(typeface),
138 color : F2(color),
154 color : F2(color),
139 link : F2(link),
155 link : F2(link),
157+ leftAligned : block('left'),
158+ rightAligned : block('right'),
159+ centered : block('center'),
141− justified : position('justify'),
160+ justified : block('justify'),
142− centered : position('center'),
143− righted : position('right'),
145− plainText : plainText,
146− markdown : markdown,
161+ markdown : markdown,
148− asText : asText,
163+ toTypefaces:toTypefaces,