@@ -0,0 +1,2081 @@
2+var Guid = function() {
4+ var guid = function() { counter += 1; return counter; };
7+var Foreign = function() {
8+ var JavaScript = function() {
9+ function castJSBoolToBool(b) { return b; }
10+ function castBoolToJSBool(b) { return b; }
12+ function castJSNumberToFloat(n) { return n; }
13+ function castFloatToJSNumber(n) { return n; }
15+ function castJSNumberToInt(n) { return ~~n; }
16+ function castIntToJSNumber(n) { return n; }
18+ var castJSElementToElement = Element.jsElement;
19+ function castElementToJSElement(elem) { return elem; }
21+ function castJSArrayToList(arr) {
23+ for (var i = arr.length; i--; ) {
24+ list = [ "Cons", arr[i], list ];
28+ function castListToJSArray(list) {
30+ while (list[0] === "Cons") {
37+ var castJSStringToString = castJSArrayToList;
38+ function castStringToJSString(str) {
39+ if (typeof str === "string") return str;
40+ return castListToJSArray(str).join('');
43+ function fromTuple(t) { return t.slice(1); }
44+ function toTuple(a) { return a.unshift("Tuple" + a.length); }
46+ return {castJSBoolToBool:castJSBoolToBool,
47+ castBoolToJSBool:castBoolToJSBool,
48+ castJSNumberToFloat:castJSNumberToFloat,
49+ castFloatToJSNumber:castFloatToJSNumber,
50+ castJSNumberToInt:castJSNumberToInt,
51+ castIntToJSNumber:castIntToJSNumber,
52+ castJSElementToElement:castJSElementToElement,
53+ castElementToJSElement:castElementToJSElement,
54+ castJSArrayToList:castJSArrayToList,
55+ castListToJSArray:castListToJSArray,
56+ castJSStringToString:castJSStringToString,
57+ castStringToJSString:castStringToJSString,
58+ castTupleToJSTuple2:fromTuple,
59+ castTupleToJSTuple3:fromTuple,
60+ castTupleToJSTuple4:fromTuple,
61+ castTupleToJSTuple5:fromTuple,
62+ castJSTupleToTuple2:toTuple,
63+ castJSTupleToTuple3:toTuple,
64+ castJSTupleToTuple4:toTuple,
65+ castJSTupleToTuple5:toTuple
68+ return {JavaScript:JavaScript};
70+var Value = function(){
72+ var eq = function(x,y) {
73+ if (typeof x === "object") {
74+ if (x === y) return true;
75+ if (x.length !== y.length) return false;
76+ for (var i = x.length; i--; ) {
77+ if (!eq(x[i],y[i])) return false;
84+ var Tuple = function() {
85+ var len = arguments.length;
86+ var arr = new Array(len+1);
87+ arr[0] = "Tuple" + arguments.length;
88+ for (var i = len; i--; ) {
89+ arr[i+1] = arguments[i];
94+ var listToArray = function(list) {
96+ while (list[0] === "Cons") {
103+ var properEscape = function(str) {
104+ str.replace('"', """);
105+ str.replace("&", "&");
106+ str.replace("'", "'");
107+ str.replace("<", "<");
108+ str.replace(">", ">");
112+ var toText = function(elmList) {
113+ if (typeof elmList === "string") return elmList;
115+ while (elmList[0] === "Cons") {
117+ elmList = elmList[2];
119+ return properEscape(a.join(''));
122+ var toString = function(v) {
123+ if (typeof v === "boolean") {
124+ return v ? "True" : "False";
125+ } else if (typeof v === "number") {
128+ if (v[0].substring(0,5) === "Tuple") {
130+ for (var i = v.length; --i; ) {
131+ output = "," + toString(v[i]) + output;
133+ if (output[0] === ",") output = output.substring(1);
134+ return "("+output+")";
135+ } else if (v[0] === "Cons") {
136+ var start = (typeof v[1] === "string") ? '"' : "[";
137+ var end = (typeof v[1] === "string") ? '"' : "]";
138+ var div = (typeof v[1] === "string") ? "" : ",";
139+ var output = start + toString(v[1]);
142+ if (v[0] === "Cons") {
143+ output += div + toString(v[1]);
146+ return output + end;
149+ } else if (v[0] === "Nil") {
153+ for (var i = v.length; --i; ) {
154+ output = " " + toString(v[i]) + output
156+ output = v[0] + output;
157+ return (v.length > 1) ? "(" + output + ")" : output;
162+ var show = function(v) {
163+ return Text.monospace(properEscape(toString(v)));
165+ var append = function(xs,ys) {
166+ if (typeof xs === "string" && typeof ys === "string") {
167+ return xs.concat(ys);
169+ if (xs[0] === "Nil") {
172+ var root = ["Cons", xs[1], ["Nil"]];
175+ while (xs[0]==="Cons") {
176+ curr[2] = ["Cons", xs[1], ["Nil"]];
184+ var str = function(s) {
186+ for (var i = s.length; i--; ) {
187+ out = ["Cons", s[i], out];
197+ listToArray:listToArray,
199+ properEscape : properEscape};
200+}();var List = function() {
202+ var throwError = function(f) {
203+ throw "Function '" + f + "' expecting a list!";
206+ function length(xs) {
208+ while (xs[0] === "Cons") {
214+ var reverse = foldl(function(x_72) {
215+ return function(y_73) {
216+ return["Cons", x_72, y_73]
219+ var concat = foldr(function(x_74) {
220+ return function(y_75) {
221+ return Value.append(x_74, y_75)
224+ var and = foldl(function(x_77) {
225+ return function(y_78) {
229+ var or = foldl(function(x_79) {
230+ return function(y_80) {
234+ var sum = foldl(function(x_89) {
235+ return function(y_90) {
239+ var product = foldl(function(x_91) {
240+ return function(y_92) {
244+ var maximum = foldl1(function(x) { return function(y) { return Math.max(x,y) } });
245+ var minimum = foldl1(function(x) { return function(y) { return Math.min(x,y) } });
247+ if (v[0] !== "Cons") {
248+ throw "Error: 'head' only accepts lists of length greater than one.";
253+ if (v[0] !== "Cons") {
254+ throw "Error: 'tail' only accepts lists of length greater than one.";
259+ return function(xs) {
260+ if (xs[0] === "Nil") { return xs; }
261+ if (xs[0] !== "Cons") { throwError('map'); }
262+ var root = ["Cons", f(xs[1]), ["Nil"]];
265+ while (xs[0]==="Cons") {
266+ curr[2] = ["Cons", f(xs[1]), ["Nil"]];
274+ return function(b) {
275+ return function(xs) {
277+ if (xs[0] === "Nil") { return acc; }
278+ if (xs[0] !== "Cons") { throwError('foldl'); }
279+ while (xs[0] === "Cons") {
280+ acc = f(xs[1])(acc);
288+ return function(b) {
289+ return function(xs) {
291+ if (xs[0] === "Nil") { return acc; }
292+ if (xs[0] !== "Cons") { throwError('foldr'); }
294+ while (xs[0] === "Cons") {
298+ for (var i = arr.length; i--; ) {
299+ acc = f(arr[i])(acc);
305+ function foldl1(f_49) {
306+ return function(_temp_50) {
307+ return function(v) {
308+ if("Cons" !== v[0]) {
313+ return foldl(f_49)(x_51)(xs_52)
318+ function foldr1(f_53) {
319+ return function(_temp_54) {
320+ return function(v) {
321+ if("Cons" !== v[0]) {
326+ return foldr(f_53)(x_55)(xs_56)
332+ return function(b) {
333+ return function(xs) {
334+ if (xs[0] === "Nil") { return ["Cons",b,["Nil"]]; }
335+ if (xs[0] !== "Cons") { throwError('scanl'); }
337+ while (xs[0] === "Cons") {
343+ for (var i = arr.length; i--; ) {
344+ out = ["Cons", arr[i], out];
350+ function scanl1(f) {
351+ return function(xs) {
352+ if (xs[0] !== "Cons") {
353+ throw "Error: 'scanl1' requires a list of at least length 1.";
355+ return scanl(f)(xs[1])(xs[2]);
358+ function filter(pred) {
359+ return function(xs) {
360+ if (xs[0] === "Nil") { return xs; }
361+ if (xs[0] !== "Cons") { throwError('filter'); }
363+ while (xs[0] === "Cons") {
364+ if (pred(xs[1])) { arr.push(xs[1]); }
368+ for (var i = arr.length; i--; ) {
369+ out = ["Cons", arr[i], out];
374+ function concatMap(f_76) {
375+ return function(x) {
376+ return concat(map(f_76)(x))
379+ function forall(pred) {
380+ return foldl(function(x) { return function(acc) {
381+ return acc && pred(x);
384+ function exists(pred) {
385+ return foldl(function(x) { return function(acc) {
386+ return acc || pred(x);
389+ function partition(pred_93) {
390+ return function(lst_94) {
393+ var c = [function(v) {
394+ if("Nil" !== v[0]) {
397+ return["Tuple2", ["Nil"], ["Nil"]]
400+ if("Cons" !== v[0]) {
405+ return function(v) {
406+ if("Tuple2" !== v[0]) {
411+ return pred_93(x_95) ? ["Tuple2", ["Cons", x_95, as_97], bs_98] : ["Tuple2", as_97, ["Cons", x_95, bs_98]]
413+ }(partition(pred_93)(xs_96))
416+ for(var i = c.length;i--;) {
418+ if(r !== undefined) {
425+ function zipWith(f) {
426+ return function(listA) {
427+ return function(listB) {
428+ if (listA[0] === "Nil" || listB[0] === "Nil") { return ["Nil"]; }
429+ if (listA[0] !== "Cons" || listB[0] !== "Cons") { throwError('zipWith'); }
431+ while (listA[0] === "Cons" && listB[0] === "Cons") {
432+ arr.push(f(listA[1])(listB[1]));
437+ for (var i = arr.length; i--; ) {
438+ out = ["Cons", arr[i], out];
444+ function zip(listA) {
445+ return function(listB) {
446+ if (listA[0] === "Nil" || listB[0] === "Nil") { return ["Nil"]; }
447+ if (listA[0] !== "Cons" || listB[0] !== "Cons") { throwError('zip'); }
449+ while (listA[0] === "Cons" && listB[0] === "Cons") {
450+ arr.push(["Tuple2", listA[1], listB[1]]);
455+ for (var i = arr.length; i--; ) {
456+ out = ["Cons", arr[i], out];
461+ function unzip(pairs_112) {
464+ var c = [function(v) {
465+ if("Nil" !== v[0]) {
468+ return["Tuple2", ["Nil"], ["Nil"]]
471+ if("Cons" !== v[0]) {
476+ return function(v) {
477+ if("Tuple2" !== v[0]) {
480+ if("Tuple2" !== v[1][0]) {
483+ var x_115 = v[1][1];
484+ var y_116 = v[1][2];
485+ if("Tuple2" !== v[2][0]) {
488+ var xs_117 = v[2][1];
489+ var ys_118 = v[2][2];
490+ return["Tuple2", ["Cons", x_115, xs_117], ["Cons", y_116, ys_118]]
494+ }(["Tuple2", p_113, unzip(ps_114)])
497+ for(var i = c.length;i--;) {
499+ if(r !== undefined) {
505+ function intersperse(sep_119) {
506+ return function(xs_120) {
509+ var c = [function(v) {
510+ if("Nil" !== v[0]) {
516+ if("Cons" !== v[0]) {
520+ if("Nil" !== v[2][0]) {
523+ return["Cons", a_124, ["Nil"]]
527+ if("Cons" !== v[0]) {
531+ if("Cons" !== v[2][0]) {
534+ var b_122 = v[2][1];
535+ var cs_123 = v[2][2];
536+ return["Cons", a_121, ["Cons", sep_119, intersperse(sep_119)(["Cons", b_122, cs_123])]]
540+ for(var i = c.length;i--;) {
542+ if(r !== undefined) {
549+ function intercalate(sep_125) {
550+ return function(xs_126) {
553+ var c = [function(v) {
554+ if("Nil" !== v[0]) {
560+ if("Cons" !== v[0]) {
564+ if("Nil" !== v[2][0]) {
571+ if("Cons" !== v[0]) {
575+ if("Cons" !== v[2][0]) {
578+ var b_128 = v[2][1];
579+ var cs_129 = v[2][2];
580+ return Value.append(a_127, Value.append(sep_125, intercalate(sep_125)(["Cons", b_128, cs_129])))
584+ for(var i = c.length;i--;) {
586+ if(r !== undefined) {
594+ if (xs[0] === "Nil") { return xs; }
595+ if (xs[0] !== "Cons") { throwError('sort'); }
597+ while (xs[0] === "Cons") {
601+ arr.sort(function(a,b) { return a - b});
603+ for (var i = arr.length; i--; ) {
604+ out = [ "Cons", arr[i], out ];
608+ function take(n) { return function(xs) {
609+ if (n <= 0) { return ["Nil"]; }
610+ if (xs[0] === "Nil") { return xs; }
611+ if (xs[0] !== "Cons") { throwError('take'); }
612+ var out = [ "Cons", xs[1], ["Nil"] ];
616+ while (xs[0] === "Cons" && n > 0) {
617+ temp[2] = [ "Cons", xs[1], ["Nil"] ];
625+ function drop(n) { return function(xs) {
626+ if (xs[0] === "Nil") { return xs; }
627+ if (xs[0] !== "Cons") { throwError('drop'); }
628+ while (xs[0] === "Cons" && n > 0) {
648+ concatMap:concatMap,
657+ partition:partition,
661+ intersperse:intersperse,
662+ intercalate:intercalate,
667+var Data = function() {
669+var Char = function() {
670+ return {fromCode : function(c) { return String.fromCharCode(c); },
671+ toCode : function(c) { return c.charCodeAt(0); },
672+ toUpper : function(c) { return c.toUpperCase(); },
673+ toLower : function(c) { return c.toLowerCase(); },
674+ toLocaleUpper : function(c) { return c.toLocaleUpperCase(); },
675+ toLocaleLower : function(c) { return c.toLocaleLowerCase(); }
679+var Maybe = function() {
680+ function consMaybe(x) { return function(xs) {
681+ if (x[0] === "Just") return ["Cons", x[1], xs];
685+ function fromMaybe(b) { return function(m) {
686+ if (m[0] === "Just") return m[1];
690+ function mapCons(f) { return function(y) { return function(xs) {
692+ if (x[0] === "Just") return ["Cons", x[1], xs];
697+ function maybe(b) { return function(f) { return function(m) {
698+ if (m[0] === "Just") return f(m[1]);
704+ return {Just : function(x) { return ["Just",x]; },
705+ Nothing : ["Nothing"],
706+ catMaybes : List.foldr(consMaybe)(["Nil"]),
707+ isJust : function(m) { return m[0] === "Just"; },
708+ isNothing : function(m) { return m[0] === "Nothing"; },
709+ fromMaybe : fromMaybe,
710+ consMaybe : consMaybe,
711+ mapMaybe : function(f) { return List.foldr(mapCons(f))(["Nil"]); },
716+var String = function() {
718+ function append(s1) { return function(s2) {
719+ return s1.concat(s2);
722+ function map(f) { return function(s) {
723+ for (var i = s.length; i--; ) { s[i] = f(s[i]); }
727+ function intercalate(sep) { return function(ss) {
728+ return Value.listToArray(ss).join(sep);
731+ function intersperse(sep) { return function(s) {
732+ return s.split("").join(sep);
736+ function foldl(f) { return function(b) { return function(s) {
738+ for (var i = 0, len = s.length; i < len; ++i) { acc = f(s[i])(acc); }
743+ function foldr(f) { return function(b) { return function(s) {
745+ for (var i = s.length; i--; ) { acc = f(s[i])(acc); }
751+ function concatMap(f) { return function(s) {
752+ var a = s.split("");
753+ for (var i = a.length; i--; ) { a[i] = f(a[i]); }
758+ function forall(pred) { return function(s) {
759+ for (var i = s.length; i--; ) { if (!pred(s[i])) {return false}; }
763+ function exists(pred) { return function(s) {
764+ for (var i = s.length; i--; ) { if (pred(s[i])) {return true}; }
769+ return {cons : append,
771+ head : function(s) { return s[0]; },
772+ last : function(s) { return s[s.length-1]; },
773+ tail : function(s) { return s.slice(1); },
774+ length : function(s) { return s.length; },
776+ intercalate : intercalate,
777+ intersperse : intersperse,
778+ reverse : function(s) { return s.split("").reverse().join(""); },
779+ toLower : function(s) { return s.toLowerCase(); },
780+ toUpper : function(s) { return s.toUpperCase(); },
783+ concat : function(ss) { return Value.listToArray(ss).join(""); },
784+ concatMap : concatMap,
792+ toText : Value.toText,
793+ properEscape : Value.properEscape
797+return {String: {toText:Value.toText, properEscape:Value.properEscape},
803+var Color = function() {
805+ var create = function(r,g,b,a) {
812+ var extract = function(c) {
814+ return 'rgb(' + c.r + ',' + c.g + ',' + c.b + ')';
816+ return 'rgba(' + c.r + ',' + c.g + ',' + c.b + ',' + c.a + ')';
819+ var rgba = function(r) { return function(g) { return function(b) {
820+ return function(a) { return create(r,g,b,a); }; }; };
823+ var rgb = function(r) { return function(g) { return function(b) {
824+ return create(r,g,b,1); }; };
826+ return {black: create( 0, 0, 0,1),
827+ white: create(255,255,255,1),
828+ red : create(255, 0, 0,1),
829+ green: create( 0,255, 0,1),
830+ blue : create( 0, 0,255,1),
832+ gray : create(128,128,128,1),
833+ grey : create(128,128,128,1),
835+ yellow : create(255,255, 0,1),
836+ cyan : create( 0,255,255,1),
837+ magenta : create(255, 0,255,1),
841+ Internal : { extract:extract }
844+var Element = function() {
845+ var newElement = function(elementType) {
846+ var e = document.createElement(elementType);
851+ var addTo = function(container, elem) {
852+ container.appendChild(clone(elem));
853+ //elem.timesAdded += 1;
855+ var clone = function(e) {
857+ /*if (e.timesAdded === 0) { return e; }
858+ if (e.tagName === "CANVAS") {
859+ var newCanvas = e.cloneNode(true);
860+ var ctx = newCanvas.getContext('2d');
861+ ctx.drawImage(e, 0, 0);
863+ } else if (e.tagName === "IMG") {
867+ if (e.style.width !== "") { d.style.width = d.width = e.style.width; }
868+ if (e.style.height !== ""){d.style.height = d.height = e.style.height;}
870+ } else if (e.hasOwnProperty('isElmLeaf')) {
871+ return e.cloneNode(true);
873+ d = e.cloneNode(false);
874+ var kids = e.childNodes;
875+ var len = kids.length;
876+ for (var i = 0; i < len; i++) {
877+ d.appendChild(clone(kids[i]));
882+ var divify = function(e) {
883+ var div = newElement('div');
888+ var rectangle = function(w) { return function(h) {
889+ var e = newElement('div');
891+ e.style.width = w + "px";
892+ e.style.height = h + "px";
897+ var makeText = function(w) { return function(pos) { return function(txt) {
898+ var e = newElement('div');
902+ e.style.textAlign = pos;
903+ if (w > 0) e.style.width = w + "px";
908+ var correctTextSize = function(e) {
909+ var w = e.style.width ? e.style.width.slice(0,-2) : 0;
911+ var t = newElement('div');
912+ t.innerHTML = e.innerHTML;
913+ t.style.textAlign = e.style.textAlign;
914+ if (w > 0) { t.style.width = w + "px"; }
916+ t.style.visibility = "hidden";
917+ t.style.styleFloat = "left";
918+ t.style.cssFloat = "left";
920+ document.body.appendChild(t);
921+ var cStyle = window.getComputedStyle(t);
922+ if (w <= 0) e.style.width = cStyle.getPropertyValue("width");
923+ e.style.height = cStyle.getPropertyValue("height");
924+ document.body.removeChild(t);
927+ var link = function (href) { return function (e) {
928+ var a = newElement('a');
929+ a.href = Text.fromString(href);
935+ var text = makeText(0)('left');
936+ var plainText = function(str) {
937+ return makeText(0)("left")(Data.String.toText(str)); };
938+ var justifiedText = makeText(0)('justify');
939+ var centeredText = makeText(0)('center');
940+ var rightedText = makeText(0)('right');
941+ var asText = function(v) { return makeText(0)("left")(Value.show(v)); };
943+ var image = function(src) {
944+ var img = newElement('img');
945+ img.isElmLeaf = true;
946+ img.onload = function() {
947+ if (img.style.width === "" && this.width > 0) {
948+ img.style.width = img.width = this.width + "px";
950+ if (img.style.height === "" && this.height > 0) {
951+ img.style.height = img.height = this.height + "px";
955+ img.src = Data.String.toText(src);
959+ var fittedImage = function(w) { return function(h) { return function(src) {
960+ var canvas = newElement('canvas');
961+ canvas.style.width = w + 'px';
962+ canvas.style.height = h + 'px';
965+ canvas.innerHTML = "Your browser does not support the canvas element.";
966+ canvas.isElmLeaf = true;
968+ var img = newElement('img');
969+ img.onload = function() {
970+ if (canvas.getContext) {
971+ var ctx = canvas.getContext('2d');
972+ var sx = 0, sy = 0, sWidth = this.width, sHeight = this.height;
973+ if (w / h > this.width / this.height) {
974+ sHeight = this.width * h / w;
975+ sy = (this.height - sHeight) / 2
977+ sWidth = this.height * w / h;
978+ sx = (this.width - sWidth) / 2
980+ ctx.drawImage(img, sx, sy, sWidth, sHeight,
981+ 0,0, canvas.width, canvas.height);
984+ img.src = Data.String.toText(src);
990+ var video = function(src) {
991+ src = Data.String.toText(src);
992+ var e = newElement('video');
993+ e.controls = "controls";
994+ var source = newElement('source');
996+ source.type = "video/" + src.substring(src.length - 3, src.length);
1001+ var audio = function(src) {
1002+ src = Data.String.toString(src);
1003+ var e = newElement('video');
1004+ e.controls = "controls";
1005+ var source = newElement('source');
1007+ source.type = "audio/" + src.substring(src.length - 3, src.length);
1009+ e.isElmLeaf = true;
1012+ var collage = function(w) { return function(h) { return function(cflist) {
1013+ var canvas = newElement('canvas');
1014+ canvas.style.width = w + 'px';
1015+ canvas.style.height = h + 'px';
1018+ if (canvas.getContext) {
1019+ var ctx = canvas.getContext('2d');
1020+ ctx.clearRect(0,0, canvas.width, canvas.height);
1021+ while (cflist[0] === "Cons") {
1022+ ctx = cflist[1](ctx);
1023+ cflist = cflist[2];
1027+ canvas.innerHTML = "Your browser does not support the canvas element.";
1028+ canvas.isElmLeaf = true;
1034+ var goDown = function(e) {
1035+ return e.tagName === "DIV" ? e : divify(e);
1037+ var goRight = function(e) {
1038+ e.style.styleFloat = "left";
1039+ e.style.cssFloat = "left";
1042+ var goIn = function(e) {
1043+ e.style.position = 'absolute';
1046+ var flowWith = function(dir, f, elist) {
1047+ var container = newElement('div');
1048+ for (var i = elist.length; i--; ) {
1049+ addTo(container, f(elist[i]));
1051+ container.elmFlowDirection = dir;
1055+ var flow = function(direction) { return function(elist) {
1057+ while (elist[0] === "Cons") {
1058+ arr.push(elist[1]);
1061+ if (direction >= 3) arr.reverse();
1062+ var f = function(x) { return x; };
1063+ var dir = direction % 3;
1064+ if (dir == 0) return flowWith("Y", goDown , arr);
1065+ if (dir == 1) return flowWith("X", goRight, arr);
1066+ if (dir == 2) return flowWith("Z", goIn , arr);
1070+ var beside = function(a) { return function(b) {
1071+ return flow(4)(["Cons",a,["Cons",b,["Nil"]]]); }; };
1072+ var above = function(a) { return function(b) {
1073+ return flow(3)(["Cons",a,["Cons",b,["Nil"]]]); }; };
1074+ var below = function(a) { return function(b) {
1075+ return flow(0)(["Cons",a,["Cons",b,["Nil"]]]); }; };
1077+ var box = function(pos) { return function(e) {
1078+ e.style.position = "absolute";
1079+ e.style.margin = "auto";
1080+ var x = (pos - 1) % 3;
1081+ var y = (pos - 1) / 3;
1082+ if (x < 2) e.style.left = 0;
1083+ if (x > 0) e.style.right = 0;
1084+ if (y < 2) e.style.top = 0;
1085+ if (y > 0) e.style.bottom = 0;
1086+ var div = newElement('div');
1087+ div.style.position = "relative";
1093+ var width = function(w) { return function(e) {
1094+ if (e.tagName === "A") {
1095+ width(w)(e.firstChild);
1098+ if (e.hasOwnProperty('isElmText')) {
1099+ var d = makeText(w)(e.style.textAlign)(e.innerHTML);
1100+ e.style.height = d.style.height;
1102+ e.style.width = w + "px";
1106+ var height = function(h) { return function(e) {
1107+ (e.tagName === "A" ? e.firstChild : e).style.height = h + "px";
1111+ var size = function(w) { return function(h) { return function(e) {
1112+ var d = e.tagName === "A" ? e.firstChild : e;
1113+ d.style.width = w + "px";
1114+ d.style.height = h + "px";
1120+ var color = function(c) { return function(e) {
1121+ e.style.backgroundColor = Color.Internal.extract(c);
1125+ var opacity = function(value) { return function(e) {
1126+ e.style.opacity = value;
1131+ var jsElement = function(w) { return function(h) { return function(elem) {
1132+ var e = newElement('div');
1133+ e.isElmLeaf = true;
1134+ e.style.width = w + "px";
1135+ e.style.height = h + "px";
1142+ return {text : text,
1144+ fittedImage : fittedImage,
1150+ rectangle : rectangle,
1165+ plainText : plainText,
1166+ justifiedText : justifiedText,
1167+ centeredText : centeredText,
1168+ rightedText : rightedText,
1178+ correctTextSize : correctTextSize,
1179+ jsElement : jsElement
1185+var Text = function() {
1186+ var fromString = function(elmList) {
1187+ if (typeof elmList === "string") return elmList;
1189+ while (elmList[0] === "Cons") {
1190+ a.push(elmList[1]);
1191+ elmList = elmList[2];
1193+ return Data.String.properEscape(a.join(''));
1196+ var addTag = function(tag) { return function(text) {
1197+ return '<' + tag + '>' + text + '</' + tag + '>';
1200+ var addStyle = function(style, value) { return function(text) {
1201+ return "<span style='" + style + ":" + value + "'>" + text + "</span>";
1205+ var typeface = function(name) { return addStyle('font-family', name); };
1206+ var size = function(px) {
1207+ return addStyle('font-size', px + 'px');
1209+ var header = addTag('h1');
1210+ var height = function(h) { return addStyle('font-size', h+'em'); }
1211+ var italic = addStyle('font-style', 'italic');
1212+ var bold = addTag('b');
1213+ var color = function(c) {
1214+ return addStyle('color', Color.Internal.extract(c));
1216+ var underline = addStyle('text-decoration', 'underline');
1217+ var overline = addStyle('text-decoration', 'overline');
1218+ var strikeThrough = addStyle('text-decoration', 'line-through');
1219+ var link = function(href) { return function(text) {
1220+ return "<a href='" + fromString(href) + "'>" + text + "</a>";
1224+ return {fromString : fromString,
1225+ toText: fromString,
1230+ underline : underline,
1231+ overline : overline,
1232+ strikeThrough : strikeThrough,
1233+ monospace : typeface('monospace'),
1237+var Shape = function() {
1239+ var create = function(center, ps, theta, s) {
1240+ return { center: center, points: ps, theta: theta, scale: s };
1243+ //// Construction ////
1245+ var polygon = function(ps) { return function(center) {
1247+ while (ps[0] === "Cons") {
1248+ parr.push([ps[1][1], ps[1][2]]);
1251+ center = [center[1], center[2]];
1252+ return create(center, parr, 0, 1);
1255+ var ngon = function(n) { return function(r) { return function(center) {
1257+ for (var i = n; i--;) {
1258+ ps.push([r * Math.cos(Math.PI * 2 * i/n),
1259+ r * Math.sin(Math.PI * 2 * i/n)]);
1261+ center = [center[1], center[2]];
1262+ return create(center, ps, 0, 1);
1266+ var rect = function(w) { return function(h) { return function(center) {
1267+ var ps = [[- w/2, - h/2],
1271+ center = [center[1], center[2]];
1272+ return create(center, ps, 0, 1);
1276+ var oval = function(w) { return function(h) { return function(center) {
1278+ for (var theta = 2 * Math.PI; theta > 0; theta -= Math.PI /50) {
1279+ ps.push([w/2 * Math.cos(theta), h/2 * Math.sin(theta)]);
1281+ center = [center[1], center[2]];
1282+ return create(center, ps, 0, 1);
1287+//// Transforms ////
1289+ var move = function(x) { return function(y) { return function(shape) {
1290+ var newCenter = [x + shape.center[0],y + shape.center[1]];
1291+ return create(newCenter, shape.points, shape.theta, shape.scale);
1295+ var rotate = function(theta) { return function(shape) {
1296+ var newTheta = shape.theta + 2 * Math.PI * theta;
1297+ return create(shape.center, shape.points, newTheta, shape.scale);
1300+ var scale = function(s) { return function(shape) {
1301+ return create(shape.center, shape.points, shape.theta, shape.scale * s);
1308+ var draw = function(fill) {
1309+ return function(color) { return function(shape) { return function(ctx) {
1311+ ctx.translate(shape.center[0], shape.center[1]);
1312+ ctx.rotate(shape.theta);
1313+ ctx.scale(shape.scale, shape.scale);
1315+ var points = shape.points;
1316+ ctx.moveTo(points[0][0], points[0][1]);
1317+ for (var i = points.length; i--; ) {
1318+ ctx.lineTo(points[i][0], points[i][1]);
1322+ ctx.fillStyle = Color.Internal.extract(color);
1325+ ctx.strokeStyle = Color.Internal.extract(color);
1335+ var customOutline = function(p) {
1336+ return function(c) { return function(shape) {
1337+ shape.points.push(shape.points[0]);
1338+ return Line.customLine(p)(c)(shape);
1342+ return {polygon:polygon, ngon:ngon, rect:rect, oval:oval,
1343+ move:move, rotate:rotate, scale:scale,
1344+ filled:draw(true), outlined:draw(false), customOutline:customOutline };
1346+var Line = function() {
1348+ var pair = function(a,b) { return [a,b]; };
1350+ var create = function(center, ps, theta, s) {
1351+ return { center: center, points: ps, theta: theta, scale: s };
1355+ //// Construction ////
1357+ var line = function(ps) {
1359+ while (ps[0] === "Cons") {
1360+ parr.push(pair(ps[1][1], ps[1][2]));
1363+ return create(pair(0,0), parr, 0, 1);
1368+ var solid = function(color) { return function(line) { return function(ctx) {
1371+ ctx.translate(line.center[0], line.center[1]);
1372+ ctx.rotate(line.theta);
1373+ ctx.scale(line.scale, line.scale);
1374+ var points = line.points;
1375+ var i = points.length;
1376+ ctx.moveTo(points[i-1][0], points[i-1][1]);
1378+ ctx.lineTo(points[i][0], points[i][1]);
1380+ ctx.strokeStyle = Color.Internal.extract(color);
1388+ var customLine = function(pattern) {
1389+ return function(color) { return function(line) {
1390+ if (typeof pattern[0] === "string") {
1392+ while (pattern[0] === "Cons") {
1393+ temp.push(pattern[1]);
1394+ pattern = pattern[2];
1398+ if (pattern.length === 0) { pattern = [8,4]; }
1399+ return function(ctx) {
1402+ ctx.translate(line.center[0], line.center[1]);
1403+ ctx.rotate(line.theta);
1404+ ctx.scale(line.scale, line.scale);
1405+ customLineHelp(ctx, pattern, line.points);
1406+ ctx.strokeStyle = Color.Internal.extract(color);
1414+ var customLineHelp = function(ctx, pattern, points) {
1415+ var i = points.length - 1;
1416+ var x0 = points[i][0], y0 = points[i][1];
1417+ var x1=0, y1=0, dx=0, dy=0, remaining=0, nx=0, ny=0;
1418+ var pindex = 0, plen = pattern.length;
1419+ var draw = true, segmentLength = pattern[0];
1422+ x1 = points[i][0]; y1 = points[i][1];
1423+ dx = x1 - x0; dy = y1 - y0;
1424+ remaining = Math.sqrt(dx * dx + dy * dy);
1425+ while (segmentLength <= remaining) {
1426+ x0 += dx * segmentLength / remaining;
1427+ y0 += dy * segmentLength / remaining;
1428+ ctx[draw ? 'lineTo' : 'moveTo'](x0, y0);
1429+ // update starting position
1430+ dx = x1 - x0; dy = y1 - y0;
1431+ remaining = Math.sqrt(dx * dx + dy * dy);
1434+ pindex = (pindex + 1) % plen;
1435+ segmentLength = pattern[pindex];
1437+ if (remaining > 0) {
1438+ ctx[draw ? 'lineTo' : 'moveTo'](x1, y1);
1439+ segmentLength -= remaining;
1445+ return {line:line, customLine:customLine, solid:solid,
1446+ dashed: customLine([8,4]), dotted: customLine([3,3]) };
1449+var Elm = function() {
1450+ var send = function(kids, timestep, changed) {
1451+ for (var i = kids.length; i--; ) {
1452+ kids[i].recv(timestep, changed);
1455+ var input = function(base) {
1456+ this.id = Guid.guid();
1459+ this.recv = function(timestep, eid, v) {
1460+ var changed = eid === this.id;
1461+ if (changed) { this.value = v; }
1462+ send(this.kids, timestep, changed);
1464+ Dispatcher.inputs.push(this);
1466+ var lift = function(func,args) {
1467+ this.id = Guid.guid();
1473+ this.recalc = function() {
1475+ for (var i = args.length; i--; ) {
1476+ f = f(args[i].value);
1482+ this.recv = function(timestep, changed) {
1483+ if (!this.inbox.hasOwnProperty(timestep)) {
1484+ this.inbox[timestep] = { changed: false, count: 0 };
1486+ var box = this.inbox[timestep];
1488+ if (changed) { box.changed = true; }
1489+ if (box.count == args.length) {
1490+ if (box.changed) { this.recalc() }
1491+ send(this.kids, timestep, box.changed);
1492+ delete this.inbox[timestep];
1495+ for (var i = args.length; i--; ) {
1496+ args[i].kids.push(this);
1499+ var fold = function(func,base,input) {
1500+ this.id = Guid.guid();
1503+ this.recv = function(timestep, changed) {
1504+ if (changed) { this.value = func(input.value)(this.value); }
1505+ send(this.kids, timestep, changed);
1507+ input.kids.push(this);
1510+ var dropIf = function(pred,base,input) {
1511+ this.id = Guid.guid();
1512+ this.value = pred(input.value) ? base : input.value;
1514+ this.recv = function(timestep, changed) {
1515+ var chng = changed && !pred(input.value);
1516+ if (chng) { this.value = input.value; }
1517+ send(this.kids, timestep, chng);
1519+ input.kids.push(this);
1521+ var dropRepeats = function(input) {
1522+ this.id = Guid.guid();
1523+ this.value = input.value;
1525+ this.recv = function(timestep, changed) {
1526+ var chng = changed && !eq(this.value,input.value);
1527+ if (chng) { this.value = input.value; }
1528+ send(this.kids, timestep, chng);
1530+ input.kids.push(this);
1533+ var dropWhen = function(s1) { return function(b) { return function(s2) {
1534+ var pairs = new lift(function(x){return function(y){return [x,y];};},[s1,s2]);
1535+ var dropped = new dropIf(function(p){return p[0];},[true,b],pairs);
1536+ return new lift(function(p){return p[1];},[dropped]); }; };
1539+ return {Input: function(x) {return new input(x);},
1540+ Lift: function(f,xs){return new lift(f,xs);},
1541+ Fold: function(f,b,x){return new fold(f,b,x);},
1542+ keepIf : function(pred) { return function(base) { return function(sig) {
1543+ return new dropIf(function(x) { return !pred(x)},base,sig); }; }; },
1544+ dropIf : function(pred) { return function(base) { return function(sig) {
1545+ return new dropIf(pred,base,sig); }; }; },
1546+ keepWhen : function(s) { return dropWhen(new lift(function(b){return !b;},[s])); },
1547+ dropWhen : dropWhen,
1548+ dropRepeats : function(s) { return new dropRepeats(s);}
1552+var Dispatcher = function() {
1553+ var program = null;
1557+ var correctSize = function(e) {
1558+ var kids = e.childNodes;
1559+ var len = kids.length;
1560+ if (e.hasOwnProperty('isElmLeaf')) {
1561+ if (e.hasOwnProperty('isElmText')) { Element.correctTextSize(e); }
1562+ var w = e.style.width === "" ?
1563+ 0 : e.style.width.slice(0,-2) - 0;
1564+ var h = e.style.height === "" ?
1565+ 0 : e.style.height.slice(0,-2) - 0;
1569+ var dim = correctSize(kids[0]);
1570+ if (e.style.width !== "") { dim[0] = e.style.width.slice(0,-2) - 0; }
1571+ if (e.style.height !== "") { dim[1] = e.style.height.slice(0,-2) - 0; }
1572+ if (dim[0] !== 0) { e.style.width = dim[0] + "px"; }
1573+ if (dim[1] !== 0) { e.style.height = dim[1] + "px"; }
1576+ var wmax = 0, hmax = 0, wsum = 0, hsum = 0;
1577+ var hasWidth = true, hasHeight = true, dim = null;
1579+ dim = correctSize(kids[len]);
1580+ wmax = Math.max(wmax, dim[0]);
1581+ hmax = Math.max(hmax, dim[1]);
1584+ hasWidth = hasWidth && dim[0] > 0;
1585+ hasHeight = hasHeight && dim[1] > 0;
1587+ var w = wmax, h = hmax, dir = e.elmFlowDirection;
1588+ if (dir === "X") { w = hasWidth ? wsum : 0; }
1589+ if (dir === "Y") { h = hasHeight ? hsum : 0; }
1590+ if (w > 0) e.style.width = w + "px";
1591+ if (h > 0) e.style.height = h + "px";
1595+ var initialize = function() {
1596+ program = ElmCode.main();
1597+ if (!program.hasOwnProperty('recv')) {
1598+ program = Elm.Input(program);
1600+ var content = document.getElementById('content');
1601+ content.appendChild(program.value);
1603+ var w = document.getElementById('widthChecker').offsetWidth;
1604+ if (w !== window.innerWidth) {
1605+ Dispatcher.notify(Window.dimensions.id, Value.Tuple(w, window.innerHeight));
1607+ program = Elm.Lift(function(value) {
1608+ var content = document.getElementById('content');
1609+ var kid = content.children[0]
1610+ content.replaceChild(value, kid);
1616+ var adjust = function() {
1617+ var content = document.getElementById('content');
1618+ correctSize(content.children[0]);
1620+ var notify = function(id, v) {
1622+ for (var i = inputs.length; i--; ) {
1623+ inputs[i].recv(timestep, id, v);
1626+ return {initialize:initialize, notify:notify, adjust:adjust, inputs:inputs};
1628+var Signal = function() {
1629+ function toElmString(str) {
1631+ for (var i = str.length; i--; ) {
1632+ out = ["Cons", str[i], out];
1636+ var addListener = function() {
1637+ if(document.addEventListener) {
1638+ return function(element, event, handler) {
1639+ element.addEventListener(event, handler, false);
1643+ return function(element, event, handler) {
1644+ element.attachEvent('on' + event, handler);
1649+ var Mouse = function() {
1650+ var position = Elm.Input(Value.Tuple(0,0));
1651+ var isDown = Elm.Input(false);
1652+ var isClicked = Elm.Input(false);
1654+ function getXY(e) {
1657+ if (!e) var e = window.event;
1658+ if (e.pageX || e.pageY) {
1661+ } else if (e.clientX || e.clientY) {
1662+ posx = e.clientX + document.body.scrollLeft +
1663+ document.documentElement.scrollLeft;
1664+ posy = e.clientY + document.body.scrollTop +
1665+ document.documentElement.scrollTop;
1667+ return Value.Tuple(posx, posy);
1670+ addListener(document, 'click', function(e) {
1671+ Dispatcher.notify(isClicked.id, true);
1672+ Dispatcher.notify(isClicked.id, false);
1674+ addListener(document, 'mousedown', function(e) {
1675+ Dispatcher.notify(isDown.id, true); });
1676+ addListener(document, 'mouseup', function(e) {
1677+ Dispatcher.notify(isDown.id, false); });
1678+ addListener(document, 'mousemove', function(e) {
1679+ Dispatcher.notify(position.id, getXY(e)); });
1680+ var clickedOn = function(elem) {
1681+ var click = Elm.Input(false);
1682+ addListener(elem, 'click', function(e) {
1683+ Dispatcher.notify(click.id, true);
1684+ Dispatcher.notify(click.id, false);
1686+ return Value.Tuple(elem, click);
1688+ return {position: position,
1689+ x: Elm.Lift(function(p){return p[1];},[position]),
1690+ y: Elm.Lift(function(p){return p[2];},[position]),
1691+ isClicked: isClicked,
1693+ clickedOn: clickedOn
1697+ var Time = function() {
1698+ var every = function(t) {
1700+ var clock = Elm.Input(0);
1702+ setInterval(function() {
1704+ Dispatcher.notify(clock.id, time/1000);
1708+ var after = function(t) {
1710+ var thread = Elm.Input(false);
1711+ setTimeout(function() { Dispatcher.notify(thread.id, true); }, t);
1714+ var before = function(t) {
1716+ var thread = Elm.Input(true);
1717+ setTimeout(function() { Dispatcher.notify(thread.id, false); }, t);
1720+ return {every:every,after:after,before:before};
1723+ var Window = function() {
1724+ var dimensions = Elm.Input(Value.Tuple(window.innerWidth,window.innerHeight));
1725+ addListener(window, 'resize', function(e) {
1726+ var w = document.getElementById('widthChecker').offsetWidth;
1727+ Dispatcher.notify(dimensions.id, Value.Tuple(w, window.innerHeight));
1729+ return {dimensions:dimensions,
1730+ width : Elm.Lift(function(p){return p[1];},[dimensions]),
1731+ height: Elm.Lift(function(p){return p[2];},[dimensions]) };
1734+ var Keyboard = { Raw : function() {
1735+ var keysDown = Elm.Input(["Nil"]);
1736+ var charPressed = Elm.Input(["Nothing"]);
1737+ function remove(x,xs) {
1738+ if (xs[0] === "Nil") return xs;
1739+ if (xs[1] === x) return xs[2];
1740+ return ["Cons", xs[1], remove(x,xs[2])];
1742+ function has(x,xs) {
1743+ while (xs[0] !== "Nil") {
1744+ if (xs[1] === x) return true;
1749+ addListener(document, 'keydown', function(e) {
1750+ if (has(e.keyCode, keysDown.value)) return;
1751+ Dispatcher.notify(keysDown.id, ["Cons", e.keyCode, keysDown.value]);
1753+ addListener(document, 'keyup', function(e) {
1754+ var codes = remove(e.keyCode, keysDown.value)
1755+ Dispatcher.notify(keysDown.id, codes);
1757+ addListener(window, 'blur', function(e) {
1758+ Dispatcher.notify(keysDown.id, ["Nil"]);
1760+ addListener(document, 'keypress', function(e) {
1761+ Dispatcher.notify(charPressed.id, ["Just",e.charCode || e.keyCode]);
1762+ Dispatcher.notify(charPressed.id, ["Nothing"]);
1764+ return {keysDown:keysDown,
1765+ charPressed:charPressed};
1769+ var HTTP = function() {
1770+ var fetch = function(how) { return function(url) {
1771+ var thread = Elm.Input(["Waiting"]);
1773+ if (window.XMLHttpRequest) { request = new XMLHttpRequest(); }
1774+ else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); }
1775+ request.onreadystatechange = function(e) {
1776+ if (request.readyState === 4) {
1777+ Dispatcher.notify(thread.id,
1778+ request.status === 200
1779+ ? ["Success", toElmString(request.responseText)]
1780+ : ["Failure", request.status, toElmString(request.statusText)]);
1783+ request.open(how, Data.String.toText(url), true);
1784+ request.send(null);
1788+ var fetches = function(how) { return function(input) {
1789+ var output = Elm.Input(["Nothing"]);
1790+ var fetcher = Elm.Lift(update, [input]);
1791+ var combine = Elm.Lift(function(x) { return function(y) { return x; } }, [output,fetcher]);
1792+ function update(strOpt) {
1793+ if (strOpt[0] !== "Just") {
1794+ try { Dispatcher.notify(output.id, ["Nothing"]); } catch(e) {}
1798+ Dispatcher.notify(output.id, ["Just", ["Waiting"]]);
1799+ } catch(e) { output.value = ["Just", ["Waiting"]]; }
1801+ if (window.XMLHttpRequest) { request = new XMLHttpRequest(); }
1802+ else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); }
1803+ request.onreadystatechange = function(e) {
1804+ if (request.readyState === 4) {
1805+ Dispatcher.notify(output.id,
1806+ ["Just", request.status === 200
1807+ ? ["Success", toElmString(request.responseText)]
1808+ : ["Failure", request.status, toElmString(request.statusText)]]);
1811+ request.open(how, Data.String.toText(strOpt[1]), true);
1812+ request.send(null);
1818+ return {get : fetch("GET"), post : fetch("POST"),
1819+ gets : fetches("GET"), posts : fetches("POST") };
1821+ var Random = function() {
1822+ var inRange = function(min) { return function(max) {
1823+ return Elm.Input(Math.floor(Math.random() * (max-min+1)) + min);
1826+ var randomize = function(min) { return function(max) { return function(signal) {
1827+ return Elm.Lift(function(x) { return Math.floor(Math.random() * (max-min+1)) + min;},[signal]);
1831+ return { inRange:inRange, randomize:randomize };
1833+ var Input = function() {
1834+ var newTextInput = function(elem, ghostText) {
1835+ elem.isElmLeaf = true;
1836+ var str = Elm.Input(["Nil"]);
1837+ addListener(elem, 'keyup', function(e) {
1838+ Dispatcher.notify(str.id, toElmString(elem.value));
1841+ return Value.Tuple(elem, str);
1843+ var newElement = function(name) {
1844+ var e = document.createElement(name);
1845+ e.id = Guid.guid();
1848+ var textArea = function(cols) { return function(rows) {
1849+ var textarea = newElement('textarea');
1850+ textarea.rows = rows;
1851+ textarea.cols = cols;
1852+ return newTextInput(textarea, "");
1855+ var textField = function(ghostText) {
1856+ var field = newElement('input');
1857+ field.type = 'text';
1858+ return newTextInput(field, ghostText);
1860+ var password = function(ghostText) {
1861+ var field = newElement('input');
1862+ field.type = 'password';
1863+ return newTextInput(field, ghostText);
1865+ var checkbox = function(checked) {
1866+ var box = newElement('input');
1867+ box.type = 'checkbox';
1868+ box.checked = checked;
1869+ var status = Elm.Input(checked);
1870+ addListener(box, 'change', function(e) {
1871+ Dispatcher.notify(status.id, box.checked);
1873+ return Value.Tuple(box, status);
1875+ var dropDown = function(options) {
1876+ var slct = newElement('select');
1878+ while (options[0] === "Cons") {
1879+ var opt = newElement('option');
1880+ var str = Text.toText(options[1][1]);
1882+ opt.innerHTML = str;
1883+ slct.appendChild(opt);
1884+ opts.push(options[1][2]);
1885+ options = options[2];
1887+ var status = Elm.Input(opts[0]);
1888+ addListener(slct, 'change', function(e) {
1889+ Dispatcher.notify(status.id, opts[slct.selectedIndex]);
1891+ return Value.Tuple(slct, status);
1893+ var stringDropDown = function(opts) {
1894+ return dropDown(List.map (function(x) {return Value.Tuple(x,x);}) (opts));
1896+ var button = function(name) {
1897+ var b = newElement('input');
1899+ b.value = Text.toText(name);
1900+ var press = Elm.Input(false);
1901+ addListener(b, 'click', function(e) {
1902+ Dispatcher.notify(press.id, true);
1903+ Dispatcher.notify(press.id, false);
1905+ return Value.Tuple(b,press);
1907+ return {textArea:textArea, textField:textField,
1908+ password:password, checkbox:checkbox,
1909+ dropDown:dropDown, stringDropDown:stringDropDown,
1913+ return {Mouse:Mouse,
1920+ constant : function(v) { return Elm.Input(v); },
1921+ lift : function(f){return function(e){return Elm.Lift(f,[e]);};},
1922+ lift2 : function(f) { return function(e1) { return function(e2) {
1923+ return Elm.Lift(f, [e1,e2]); }; }; },
1924+ lift3 : function(f) { return function(e1) { return function(e2) {
1925+ return function(e3){return Elm.Lift(f,[e1,e2,e3]);};};};},
1926+ lift4 : function(f) { return function(e1) { return function(e2) {
1927+ return function(e3) { return function(e4) {
1928+ return Elm.Lift(f, [e1,e2,e3,e4]); }; }; }; }; },
1929+ foldp : function(f) { return function(b) { return function(e) {
1930+ return Elm.Fold(f,b,e); }; }; },
1931+ count : function(sig){return Elm.fold(function(c){return c+1},0,sig)},
1932+ keepIf : Elm.keepIf,
1933+ dropIf : Elm.dropIf,
1934+ keepWhen : Elm.keepWhen,
1935+ dropWhen : Elm.dropWhen,
1936+ dropRepeats : Elm.dropRepeats
1939+var Prelude = function() {
1940+ var mod = function(x) { return function(y) {
1942+ var m = x==0 ? 0 : (y>0 ? (x>=0 ? r : r+y) : -mod(-x)(-y));
1943+ return m == y ? 0 : m;
1946+ var min = function(x) { return function(y) { return Math.min(x,y); }; };
1947+ var max = function(x) { return function(y) { return Math.max(x,y); }; };
1949+ var flip=function(f){return function(x){return function(y){return f(y)(x);};};};
1950+ var clamp = function(lo) { return function(hi) {
1951+ return function(x) { return Math.min(hi, Math.max(lo, x)); };
1954+ var curry = function(f) { return function(x) { return function(y) {
1955+ return f(["Tuple2",x,y]); }; };
1957+ var uncurry = function(f) { return function(p) {
1958+ if (p[0] !== "Tuple2") {
1959+ throw "Function was uncurry'd but was not given a pair.";
1961+ return f(p[1])(p[2]); };
1964+ var logBase=function(b){return function(x){return Math.log(x)/Math.log(b);};};
1966+ return {id : function(x) { return x; },
1967+ not : function(b) { return !b; },
1968+ fst : function(p) { return p[1]; },
1969+ snd : function(p) { return p[2]; },
1970+ rem : function(x) { return function(y) { return x % y; }; },
1988+ Just : Data.Maybe.Just,
1989+ Nothing : Data.Maybe.Nothing,
1990+ maybe : Data.Maybe.maybe,
1991+ map : Data.List.map,
1992+ filter : Data.List.filter,
1993+ head : Data.List.head,
1994+ tail : Data.List.tail,
1995+ length : Data.List.length,
1996+ reverse : Data.List.reverse,
1997+ foldr : Data.List.foldr,
1998+ foldr1 : Data.List.foldr1,
1999+ foldl : Data.List.foldl,
2000+ foldl1 : Data.List.foldl1,
2001+ and : Data.List.and,
2003+ forall : Data.List.forall,
2004+ exists : Data.List.exists,
2005+ sum : Data.List.sum,
2006+ product : Data.List.product,
2007+ concat : Data.List.concat,
2008+ concatMap : Data.List.concatMap,
2009+ maximum : Data.List.maximum,
2010+ minimum : Data.List.minimum,
2011+ scanl : Data.List.scanl,
2012+ scanl1 : Data.List.scanl1,
2013+ take : Data.List.take,
2014+ drop : Data.List.drop,
2015+ lift : Signal.lift,
2016+ lift2 : Signal.lift2,
2017+ lift3 : Signal.lift3,
2018+ lift4 : Signal.lift4,
2019+ foldp : Signal.foldp,
2020+ constant : Signal.constant,
2021+ count : Signal.count,
2022+ keepIf : Signal.keepIf,
2023+ dropIf : Signal.dropIf,
2024+ keepWhen : Signal.keepWhen,
2025+ dropWhen : Signal.dropWhen,
2026+ dropRepeats : Signal.dropRepeats
2031+var includeGlobal = this;
2033+ var include = function(library) {
2034+ for (var i in library) {
2035+ if (i === 'Internal') continue;
2037+ includeGlobal[i] = library[i];
2039+ if (i === 'length') {
2040+ includeGlobal.execScript('var length;');
2041+ length = library[i];
2047+ var includeAs = function(name) { return function(library) {
2048+ includeGlobal[name] = includeGlobal[name] || {};
2049+ for (var i in library) {
2050+ if (i === 'Internal') continue;
2051+ includeGlobal[name][i] = library[i];
2058+ color = Element.color;
2059+ height = Element.height;
2066+ includeAs ('Time') (Signal.Time);
2067+ includeAs ('Mouse') (Signal.Mouse);
2068+ includeAs ('Keyboard') (Signal.Keyboard);
2069+ includeAs ('Window') (Signal.Window);
2070+ includeAs ('HTTP') (Signal.HTTP);
2071+ includeAs ('Input') (Signal.Input);
2072+ includeAs ('Random') (Signal.Random);
2077+ElmCode.Data = Data;
2078+ElmCode.Signal = Signal;
2079+ElmCode.Data.List = List;
2080+ElmCode.Foreign = Foreign;
2081+ElmCode.Prelude = Prelude;