on master help sign in
Begin rewrite of rendering engine.
1501160evancz
core-js/Element.jsdeleted−317
@@ -1,317 +0,0 @@
1−
2−var Element = function() {
3− var newElement = function(elementType) {
4− var e = document.createElement(elementType);
5− e.id = Guid.guid();
6− e.style.padding = "0";
7− e.style.margin = "0";
8− return e;
9− };
10− var addTo = function(container, elem) {
11− container.appendChild(clone(elem));
12− };
13− var clone = function(e) {
14− return e;
15− };
16− var divify = function(e) {
17− var div = newElement('div');
18− addTo(div, e);
19− return div;
20− };
21−
22− var rectangle = function(w) { return function(h) {
23− var e = newElement('div');
24− e.isElmLeaf = true;
25− e.style.width = w + "px";
26− e.style.height = h + "px";
27− return e;
28− };
29− };
30−
31− var makeText = function(w) { return function(pos) { return function(txt) {
32− var e = newElement('div');
33− e.isElmLeaf = true;
34− e.isElmText = true;
35− e.innerHTML = txt;
36− e.style.textAlign = pos;
37− if (w > 0) e.style.width = w + "px";
38− return e;
39− };
40− };
41− };
42− var correctTextSize = function(e) {
43− var w = e.style.width ? e.style.width.slice(0,-2) : 0;
44−
45− var t = newElement('div');
46− t.innerHTML = e.innerHTML;
47− t.style.textAlign = e.style.textAlign;
48− if (w > 0) { t.style.width = w + "px"; }
49−
50− t.style.visibility = "hidden";
51− t.style.styleFloat = "left";
52− t.style.cssFloat = "left";
53−
54− document.body.appendChild(t);
55− var cStyle = window.getComputedStyle(t);
56− if (w <= 0) e.style.width = cStyle.getPropertyValue("width");
57− e.style.height = cStyle.getPropertyValue("height");
58− document.body.removeChild(t);
59− };
60−
61− var link = function (href) { return function (e) {
62− var a = newElement('a');
63− a.href = Text.fromString(href);
64− addTo(a,e);
65− return divify(a);
66− };
67− };
68−
69− var text = makeText(0)('left');
70− var plainText = function(str) {
71− return makeText(0)("left")(Value.toText(str)); };
72− var justifiedText = makeText(0)('justify');
73− var centeredText = makeText(0)('center');
74− var rightedText = makeText(0)('right');
75− var asText = function(v) { return makeText(0)("left")(Value.show(v)); };
76−
77− var image = function(src) {
78− var img = newElement('img');
79− img.isElmLeaf = true;
80− img.onload = function() {
81− if (img.style.width === "" && this.width > 0) {
82− img.style.width = img.width = this.width + "px";
83− }
84− if (img.style.height === "" && this.height > 0) {
85− img.style.height = img.height = this.height + "px";
86− }
87− Dispatcher.adjust()
88− };
89− img.src = Value.toText(src);
90− img.name = img.src;
91− return img;
92− };
93− var fittedImage = function(w) { return function(h) { return function(src) {
94− var canvas = newElement('canvas');
95− canvas.style.width = w + 'px';
96− canvas.style.height = h + 'px';
97− canvas.width = w;
98− canvas.height = h;
99− canvas.innerHTML = "Your browser does not support the canvas element.";
100− canvas.isElmLeaf = true;
101−
102− var img = newElement('img');
103− img.onload = function() {
104− if (canvas.getContext) {
105− var ctx = canvas.getContext('2d');
106− var sx = 0, sy = 0, sWidth = this.width, sHeight = this.height;
107− if (w / h > this.width / this.height) {
108− sHeight = this.width * h / w;
109− sy = (this.height - sHeight) / 2
110− } else {
111− sWidth = this.height * w / h;
112− sx = (this.width - sWidth) / 2
113− }
114− ctx.drawImage(img, sx, sy, sWidth, sHeight,
115− 0,0, canvas.width, canvas.height);
116− }
117− };
118− img.src = Value.toText(src);
119− return canvas;
120− };
121− };
122− };
123−
124− var video = function(src) {
125− src = Value.toText(src);
126− var e = newElement('video');
127− e.controls = "controls";
128− var source = newElement('source');
129− source.src = src;
130− source.type = "video/" + src.substring(src.length - 3, src.length);
131− addTo(e, source);
132− e.isElmLeaf = true;
133− return e;
134− };
135− var audio = function(src) {
136− src = Value.toText(src);
137− var e = newElement('video');
138− e.controls = "controls";
139− var source = newElement('source');
140− source.src = src;
141− source.type = "audio/" + src.substring(src.length - 3, src.length);
142− addTo(e, source);
143− e.isElmLeaf = true;
144− return e;
145− };
146− var collage = function(w) { return function(h) { return function(cflist) {
147− var canvas = newElement('canvas');
148− canvas.style.width = w + 'px';
149− canvas.style.height = h + 'px';
150− canvas.width = w;
151− canvas.height = h;
152− if (canvas.getContext) {
153− var ctx = canvas.getContext('2d');
154− ctx.clearRect(0,0, canvas.width, canvas.height);
155− while (cflist[0] === "Cons") {
156− ctx = cflist[1](ctx);
157− cflist = cflist[2];
158− }
159− return canvas;
160− }
161− canvas.innerHTML = "Your browser does not support the canvas element.";
162− canvas.isElmLeaf = true;
163− return canvas;
164− };
165− };
166− };
167−
168− var goDown = function(e) {
169− return e.tagName === "DIV" ? e : divify(e);
170− };
171− var goRight = function(e) {
172− e.style.styleFloat = "left";
173− e.style.cssFloat = "left";
174− return e;
175− };
176− var goIn = function(e) {
177− e.style.position = 'absolute';
178− return e;
179− };
180− var flowWith = function(dir, f, elist) {
181− var container = newElement('div');
182− for (var i = elist.length; i--; ) {
183− addTo(container, f(elist[i]));
184− }
185− container.elmFlowDirection = dir;
186− return container;
187− };
188−
189− var flow = function(direction) { return function(elist) {
190− var arr = [];
191− while (elist[0] === "Cons") {
192− arr.push(elist[1]);
193− elist = elist[2];
194− }
195− if (direction >= 3) arr.reverse();
196− var f = function(x) { return x; };
197− var dir = direction % 3;
198− if (dir == 0) return flowWith("Y", goDown , arr);
199− if (dir == 1) return flowWith("X", goRight, arr);
200− if (dir == 2) return flowWith("Z", goIn , arr);
201− };
202− };
203−
204− var beside = function(a) { return function(b) {
205− return flow(4)(["Cons",a,["Cons",b,["Nil"]]]); }; };
206− var above = function(a) { return function(b) {
207− return flow(3)(["Cons",a,["Cons",b,["Nil"]]]); }; };
208− var below = function(a) { return function(b) {
209− return flow(0)(["Cons",a,["Cons",b,["Nil"]]]); }; };
210−
211− var box = function(pos) { return function(e) {
212− e.style.position = "absolute";
213− e.style.margin = "auto";
214− var x = (pos - 1) % 3;
215− var y = (pos - 1) / 3;
216− if (x < 2) e.style.left = 0;
217− if (x > 0) e.style.right = 0;
218− if (y < 2) e.style.top = 0;
219− if (y > 0) e.style.bottom = 0;
220− var div = newElement('div');
221− div.style.position = "relative";
222− addTo(div,e);
223− return div;
224− };
225− };
226−
227− var width = function(w) { return function(e) {
228− if (e.tagName === "A") {
229− width(w)(e.firstChild);
230− return e;
231− }
232− if (e.hasOwnProperty('isElmText')) {
233− var d = makeText(w)(e.style.textAlign)(e.innerHTML);
234− e.style.height = d.style.height;
235− }
236− e.style.width = w + "px";
237− return e;
238− };
239− };
240− var height = function(h) { return function(e) {
241− (e.tagName === "A" ? e.firstChild : e).style.height = h + "px";
242− return e;
243− };
244− };
245− var size = function(w) { return function(h) { return function(e) {
246− var d = e.tagName === "A" ? e.firstChild : e;
247− d.style.width = w + "px";
248− d.style.height = h + "px";
249− return e;
250− };
251− };
252− };
253−
254− var color = function(c) { return function(e) {
255− e.style.backgroundColor = Color.Internal.extract(c);
256− return e;
257− };
258− };
259− var opacity = function(value) { return function(e) {
260− e.style.opacity = value;
261− return e;
262− };
263− };
264−
265− var jsElement = function(w) { return function(h) { return function(elem) {
266− var e = newElement('div');
267− e.isElmLeaf = true;
268− e.style.width = w + "px";
269− e.style.height = h + "px";
270− addTo(e,elem);
271− return e;
272− };
273− };
274− };
275−
276− return {text : text,
277− image : image,
278− fittedImage : fittedImage,
279− video : video,
280− audio : audio,
281− collage : collage,
282− flow : flow,
283− layers : flow(2),
284− rectangle : rectangle,
285−
286− beside : beside,
287− above : above,
288− below : below,
289− box : box,
290−
291− width : width,
292− height : height,
293− size : size,
294− color : color,
295− opacity : opacity,
296−
297− link : link,
298− asText : asText,
299− plainText : plainText,
300− justifiedText : justifiedText,
301− centeredText : centeredText,
302− rightedText : rightedText,
303−
304− // directions
305− up : 0,
306− left : 1,
307− inward : 2,
308− down : 3,
309− right : 4,
310− outward : 5,
311−
312− correctTextSize : correctTextSize,
313− jsElement : jsElement
314− };
315−}();
316−
317−
core-js/Everything.js+2−4
@@ -38,9 +38,7 @@ var includeGlobal = this;
38 height = Element.height;
38 height = Element.height;
39 show = Value.show;
39 show = Value.show;
40
40
41− include (Color);
41+ include (ElmCode.Graphics.Color);
42− include (Shape);
43− include (Line);
44
42
45 includeAs ('Time') (Signal.Time);
43 includeAs ('Time') (Signal.Time);
46 includeAs ('Mouse') (Signal.Mouse);
44 includeAs ('Mouse') (Signal.Mouse);
@@ -52,7 +50,7 @@ var includeGlobal = this;
52
50
53}());
51}());
54
52
55−var ElmCode = {};
53+var ElmCode = ElmCode || {};
56ElmCode.Data = Data;
54ElmCode.Data = Data;
57ElmCode.Signal = Signal;
55ElmCode.Signal = Signal;
58ElmCode.Data.List = List;
56ElmCode.Data.List = List;
core-js/Graphics/Collage.jsnew file+213
@@ -0,0 +1,213 @@
1+
2+var Collage = function() {
3+
4+function tracePoints(ctx,points) {
5+ var i = points.length - 1;
6+ if (i <= 0) return;
7+ ctx.moveTo(points[i][1], points[i][2]);
8+ while (i--) { ctx.lineTo(points[i][1], points[i][2]); }
9+}
10+
11+function solid(ctx,color,points) {
12+ tracePoints(ctx,points);
13+ ctx.strokeStyle = ElmCode.Graphics.Color.extract(color);
14+ ctx.stroke();
15+};
16+
17+function filled(ctx,color,points) {
18+ tracePoints(ctx,points);
19+ ctx.fillStyle = ElmCode.Graphics.Color.extract(color);
20+ ctx.fill();
21+}
22+
23+function textured(redo,ctx,src,points) {
24+ var img = new Image();
25+ img.src = Foreign.JavaScript.castStringToJSString(src);
26+ img.onload = redo;
27+
28+ tracePoints(ctx,points);
29+ ctx.fillStyle = ctx.createPattern(img,'repeat');
30+ ctx.fill();
31+}
32+
33+function customLine(pattern,ctx,color,points) {
34+ if (pattern.length === 0) { pattern = [8,4]; }
35+ customLineHelp(ctx, pattern, points);
36+ ctx.strokeStyle = ElmCode.Graphics.Color.extract(color);
37+ ctx.stroke();
38+};
39+
40+var customLineHelp = function(ctx, pattern, points) {
41+ var i = points.length - 1;
42+ if (i <= 0) return;
43+ var x0 = points[i][1], y0 = points[i][2];
44+ var x1=0, y1=0, dx=0, dy=0, remaining=0, nx=0, ny=0;
45+ var pindex = 0, plen = pattern.length;
46+ var draw = true, segmentLength = pattern[0];
47+ ctx.moveTo(x0,y0);
48+ while (i--) {
49+ x1 = points[i][1]; y1 = points[i][2];
50+ dx = x1 - x0; dy = y1 - y0;
51+ remaining = Math.sqrt(dx * dx + dy * dy);
52+ while (segmentLength <= remaining) {
53+ x0 += dx * segmentLength / remaining;
54+ y0 += dy * segmentLength / remaining;
55+ ctx[draw ? 'lineTo' : 'moveTo'](x0, y0);
56+ // update starting position
57+ dx = x1 - x0; dy = y1 - y0;
58+ remaining = Math.sqrt(dx * dx + dy * dy);
59+ // update pattern
60+ draw = !draw;
61+ pindex = (pindex + 1) % plen;
62+ segmentLength = pattern[pindex];
63+ }
64+ if (remaining > 0) {
65+ ctx[draw ? 'lineTo' : 'moveTo'](x1, y1);
66+ segmentLength -= remaining;
67+ }
68+ x0 = x1; y0 = y1;
69+ }
70+};
71+
72+function drawLine(ctx,form) {
73+ var points = Foreign.JavaScript.castListToJSArray(form[3][1]);
74+ switch(form[1][0]) {
75+ case "Solid" : return solid(ctx,form[2],points);
76+ case "Dotted": return customLine([3,3],ctx,form[2],points);
77+ case "Dashed": return customLine([8,4],ctx,form[2],points);
78+ case "Custom":
79+ var pattern = Foreign.JavaScript.castListToJSArray(form[1][1]);
80+ customLine(pattern,ctx,form[2],points);
81+ }
82+};
83+
84+function drawShape(redo,ctx,shapeStyle,color,points) {
85+ points = Foreign.JavaScript.castListToJSArray(points);
86+ if (points.length > 0) points.push(points[0]);
87+ switch(shapeStyle[0]) {
88+ case "Filled": return filled(ctx,color,points);
89+ case "Outlined": return solid(ctx,color,points);
90+ case "Textured": return textured(redo,ctx,shapeStyle[1],points);
91+ case "CustomOutline":
92+ var pattern = Foreign.JavaScript.castListToJSArray(shapeStyle[1]);
93+ customLine(pattern,ctx,color,points);
94+ }
95+};
96+
97+function drawImage(redo,ctx,w,h,src) {
98+ var img = new Image();
99+ img.onload = redo;
100+ img.src = Foreign.JavaScript.castStringToJSString(src);
101+ ctx.drawImage(img,-w/2,-h/2,w,h);
102+}
103+
104+function renderForm(redo,ctx,theta,scale,x,y,form) {
105+ ctx.save();
106+ if (x !== 0 || y !== 0) ctx.translate(x,y);
107+ if (theta !== ~~theta) ctx.rotate(2*Math.PI*theta);
108+ if (scale !== 1) ctx.scale(scale);
109+ ctx.beginPath();
110+ switch(form[0]) {
111+ case "FLine": drawLine(ctx,form); break;
112+ case "FShape": drawShape(redo,ctx,form[1],form[2],form[3][1]); break;
113+ case "FImage": drawImage(redo,ctx,form[1],form[2],form[3]); break;
114+ }
115+ ctx.restore();
116+};
117+
118+function renderForms(redo,ctx,w,h,forms) {
119+ ctx.clearRect(0,0,w,h);
120+ for (var i = forms.length; i--; ) {
121+ var f = forms[i];
122+ renderForm(redo,ctx,f[1],f[2],f[3][1],f[3][2],f[4]);
123+ }
124+}
125+
126+function collageForms(w,h,forms) {
127+ var canvas = Render.newElement('canvas');
128+ canvas.style.width = (~~w) + 'px';
129+ canvas.style.height = (~~h) + 'px';
130+ canvas.width = ~~w;
131+ canvas.height = ~~h;
132+ if (canvas.getContext) {
133+ var ctx = canvas.getContext('2d');
134+ var w = canvas.width, h = canvas.height;
135+ function redo() { renderForms(this,ctx,w,h,forms); }
136+ renderForms(redo,ctx,w,h,forms);
137+ return canvas;
138+ }
139+ canvas.innerHTML = "Your browser does not support the canvas element.";
140+ return canvas;
141+};
142+
143+function collageElement(w,h,theta,scale,x,y,elem) {
144+ var e = Render.render(elem);
145+ var t = "translate(" + (x - elem[3] / 2) + "px,"+ (y - elem[4] / 2) + "px)";
146+ var r = theta === (~~theta) ? "" : "rotate(" + theta*360 + "deg)";
147+ var s = scale === 1 ? "" : "scale(" + scale + "," + scale + ")";
148+ var transforms = t + " " + s + " " + r;
149+ e.style['-ms-transform'] = transforms;
150+ e.style['-webkit-transform'] = transforms;
151+ e.style['-o-transform'] = transforms;
152+ e.style['-moz-transform'] = transforms;
153+ e.style['transform'] = transforms;
154+ var div = Render.newElement('div');
155+ Render.addTo(div,e);
156+ div.style.width = (~~w) + "px";
157+ div.style.height = (~~h) + "px";
158+ return div;
159+}
160+
161+function collage(w,h,formss) {
162+ if (formss.length === 0) { return collageForms(w,h,[]); }
163+ var elems = new Array(formss.length);
164+ for (var i = formss.length; i--; ) {
165+ var f = formss[i];
166+ if (typeof f[0] === "string") {
167+ elems[i] = collageElement(w,h,f[1],f[2],f[3][1],f[3][2],f[4][1]);
168+ } else {
169+ elems[i] = collageForms(w,h,f);
170+ }
171+ }
172+ if (formss.length === 1) { return elems[0]; }
173+ return Render.flowWith(Render.goIn,function(x){return x},elems);
174+}
175+
176+function updateFormSet(node,currSet,nextSet) {
177+ if (Value.eq(nextSet,currSet)) return;
178+ var w = node.style.width.slice(0,-2) - 0;
179+ var h = node.style.height.slice(0,-2) - 0;
180+ if (typeof nextSet[0] === "object") {
181+ if (typeof currSet[0] === "object") {
182+ if (node.getContext) {
183+ var ctx = node.getContext('2d');
184+ function redo() { renderForms(this,ctx,w,h,nextSet); }
185+ return renderForms(redo,ctx,w,h,nextSet);
186+ }
187+ }
188+ var newNode = collageForms(w,h,nextSet);
189+ newNode.style.position = 'absolute';
190+ return node.parentNode.replaceChild(newNode,node);
191+ }
192+ var f = nextSet;
193+ var newNode = collageElement(w,h,f[1],f[2],f[3][1],f[3][2],f[4][1]);
194+ newNode.style.position = 'absolute';
195+ return node.parentNode.replaceChild(newNode,node);
196+}
197+
198+function updateCollage(node,currs,nexts) {
199+ if (currs.length !== nexts.length) {
200+ return node.parentNode.replaceChild(render(next),node); }
201+ if (nexts.length === 1) {
202+ return updateFormSet(node,currs[0],nexts[0]);
203+ }
204+ var kids = node.childNodes;
205+ var len = kids.length;
206+ for (var i = len; i--; ) {
207+ updateFormSet(kids[len-i-1], currs[i], nexts[i]);
208+ }
209+}
210+
211+return {collage:collage, updateCollage:updateCollage};
212+
213+}();
core-js/Graphics/Color.jsnew file+36
@@ -0,0 +1,36 @@
1+var ElmCode = ElmCode || {};
2+ElmCode.Graphics = ElmCode.Graphics || {};
3+ElmCode.Graphics.Color = function() {
4+ function Color_0(a1) {
5+ return function(a2) {
6+ return function(a3) {
7+ return function(a4) {
8+ return["Color", a1, a2, a3, a4]
9+ }
10+ }
11+ }
12+ }
13+ var rgba_1 = Color_0;
14+ var red_3 = ["Color",255,0,0,1];
15+ var green_4 = ["Color",0,255,0,1];
16+ var blue_5 = ["Color",0,0,255,1];
17+ var yellow_6 = ["Color",255,255,0,1];
18+ var cyan_7 = ["Color",0,255,255,1];
19+ var magenta_8 = ["Color",255,0,255,1];
20+ var black_9 = ["Color",0,0,0,1];
21+ var white_10 = ["Color",255,255,255,1];
22+ var gray_11 = ["Color",128,128,128,1];
23+ var grey_12 = ["Color",128,128,128,1];
24+ function rgb_2(r_13) {
25+ return function(g_14) {
26+ return function(b_15) {
27+ return ["Color",r_13,g_14,b_15,1]
28+ }
29+ }
30+ }
31+ function extract(c) {
32+ if (c[4] === 1) { return 'rgb(' + c[1] + ',' + c[2] + ',' + c[3] + ')'; }
33+ return 'rgba(' + c[1] + ',' + c[2] + ',' + c[3] + ',' + c[4] + ')';
34+ }
35+ return{rgba:rgba_1, rgb:rgb_2, red:red_3, green:green_4, blue:blue_5, yellow:yellow_6, cyan:cyan_7, magenta:magenta_8, black:black_9, white:white_10, gray:gray_11, grey:grey_12,extract:extract}
36+}();
core-js/Graphics/Element.jsnew file+545
@@ -0,0 +1,545 @@
1+var ElmCode = ElmCode || {};
2+ElmCode.Graphics = ElmCode.Graphics || {};
3+ElmCode.Graphics.Element = function() {
4+ var DLeft_0 = ["DLeft"];
5+ var DRight_1 = ["DRight"];
6+ var DUp_2 = ["DUp"];
7+ var DDown_3 = ["DDown"];
8+ var DIn_4 = ["DIn"];
9+ var DOut_5 = ["DOut"];
10+ function Absolute_12(a1) {
11+ return["Absolute", a1]
12+ }
13+ function Relative_13(a1) {
14+ return["Relative", a1]
15+ }
16+ var Near_14 = ["Near"];
17+ var Mid_15 = ["Mid"];
18+ var Far_16 = ["Far"];
19+ function Position_17(a1) {
20+ return function(a2) {
21+ return["Position", a1, a2]
22+ }
23+ }
24+ function PositionTL_18(a1) {
25+ return function(a2) {
26+ return["PositionTL", a1, a2]
27+ }
28+ }
29+ function PositionTR_19(a1) {
30+ return function(a2) {
31+ return["PositionTR", a1, a2]
32+ }
33+ }
34+ function PositionBL_20(a1) {
35+ return function(a2) {
36+ return["PositionBL", a1, a2]
37+ }
38+ }
39+ function PositionBR_21(a1) {
40+ return function(a2) {
41+ return["PositionBR", a1, a2]
42+ }
43+ }
44+ function Element_37(a1) {
45+ return function(a2) {
46+ return function(a3) {
47+ return function(a4) {
48+ return function(a5) {
49+ return function(a6) {
50+ return["Element", a1, a2, a3, a4, a5, a6]
51+ }
52+ }
53+ }
54+ }
55+ }
56+ }
57+ function EText_39(a1) {
58+ return function(a2) {
59+ return["EText", a1, a2]
60+ }
61+ }
62+ function EImage_40(a1) {
63+ return["EImage", a1]
64+ }
65+ function EVideo_41(a1) {
66+ return["EVideo", a1]
67+ }
68+ function EFittedImage_42(a1) {
69+ return["EFittedImage", a1]
70+ }
71+ function EFlow_43(a1) {
72+ return function(a2) {
73+ return["EFlow", a1, Foreign.JavaScript.castListToJSArray(a2)]
74+ }
75+ }
76+ function ECollage_44(a1) {
77+ return function(a2) {
78+ return function(a3) {
79+ return["ECollage", a1, a2, Value.groupForms(a3)]
80+ }
81+ }
82+ }
83+ var EEmpty_45 = ["EEmpty"];
84+ function EContainer_46(a1) {
85+ return function(a2) {
86+ return["EContainer", a1, a2]
87+ }
88+ }
89+ var Solid_68 = ["Solid"];
90+ var Dotted_69 = ["Dotted"];
91+ var Dashed_70 = ["Dashed"];
92+ function Custom_71(a1) {
93+ return["Custom", a1]
94+ }
95+ var Filled_72 = ["Filled"];
96+ var Outlined_73 = ["Outlined"];
97+ function CustomOutline_74(a1) {
98+ return["CustomOutline", a1]
99+ }
100+ function Line_75(a1) {
101+ return["Line", a1]
102+ }
103+ function Shape_78(a1) {
104+ return function(a2) {
105+ return["Shape", a1, a2]
106+ }
107+ }
108+ function Form_84(a1) {
109+ return function(a2) {
110+ return function(a3) {
111+ return function(a4) {
112+ return["Form", a1, a2, a3, a4]
113+ }
114+ }
115+ }
116+ }
117+ function FLine_85(a1) {
118+ return function(a2) {
119+ return function(a3) {
120+ return["FLine", a1, a2, a3]
121+ }
122+ }
123+ }
124+ function FShape_86(a1) {
125+ return function(a2) {
126+ return function(a3) {
127+ return["FShape", a1, a2, a3]
128+ }
129+ }
130+ }
131+ function FImage_87(a1) {
132+ return function(a2) {
133+ return function(a3) {
134+ return["FImage", a1, a2, a3]
135+ }
136+ }
137+ }
138+ function FElement_88(a1) {
139+ return["FElement", a1]
140+ }
141+ var left_6 = DLeft_0;
142+ var right_7 = DRight_1;
143+ var down_8 = DDown_3;
144+ var up_9 = DUp_2;
145+ var inward_10 = DIn_4;
146+ var outward_11 = DOut_5;
147+ var topLeft_22 = Position_17(Near_14)(Near_14);
148+ var topRight_23 = Position_17(Far_16)(Near_14);
149+ var bottomLeft_24 = Position_17(Near_14)(Far_16);
150+ var bottomRight_25 = Position_17(Far_16)(Far_16);
151+ var midLeft_26 = Position_17(Mid_15)(Near_14);
152+ var midRight_27 = Position_17(Mid_15)(Far_16);
153+ var midTop_28 = Position_17(Near_14)(Mid_15);
154+ var midBottom_29 = Position_17(Far_16)(Mid_15);
155+ var middle_30 = Position_17(Mid_15)(Mid_15);
156+ var topLeftAt_31 = PositionTL_18;
157+ var topRightAt_32 = PositionTR_19;
158+ var bottomLeftAt_33 = PositionBL_20;
159+ var bottomRightAt_34 = PositionBR_21;
160+ var absolute_35 = Absolute_12;
161+ var relative_36 = Relative_13;
162+ function newElement_38(a) { return Element_37(Guid.guid())(a); }
163+ var line_76 = Line_75;
164+ var polygon_79 = Shape_78;
165+ function sprite_96(src) {
166+ return function(w) {
167+ return function(h) {
168+ return function(pos) {
169+ return Form_84(0)(1)(pos)(FImage_87(w)(h)(src))
170+ }
171+ }
172+ }
173+ }
174+ function toForm_97(pos) {
175+ return function(e) {
176+ return Form_84(0)(1)(pos)(FElement_88(e))
177+ }
178+ }
179+ function width_47(w__101) {
180+ return function(Element$_ewhoc_102) {
181+ return function(case7) {
182+ var case0 = case7;
183+ switch(case0[0]) {
184+ case "Element":
185+ var case1 = case0[1], case2 = case0[2], case3 = case0[3], case4 = case0[4], case5 = case0[5], case6 = case0[6];
186+ return function(case12) {
187+ var case8 = case12;
188+ switch(case8[0]) {
189+ case "EImage":
190+ case "EVideo":
191+ return newElement_38(case2)(w__101)(case4 * w__101 / case3)(case5)(case6);
192+ case "EText":
193+ var p = Value.getTextSize(w__101,case4,case8[2]);
194+ return newElement_38(case2)(w__101)(p[1])(case5)(case6);
195+ }
196+ return newElement_38(case2)(w__101)(case4)(case5)(case6)
197+ }(case2)
198+ }
199+ throw"Non-exhaustive pattern match in case";
200+ }(Element$_ewhoc_102)
201+ }
202+ }
203+ function height_48(h__108) {
204+ return function(Element$_ewhoc_109) {
205+ return function(case7) {
206+ var case0 = case7;
207+ switch(case0[0]) {
208+ case "Element":
209+ var case1 = case0[1], case2 = case0[2], case3 = case0[3], case4 = case0[4], case5 = case0[5], case6 = case0[6];
210+ return function(case12) {
211+ var case8 = case12;
212+ switch(case8[0]) {
213+ case "EImage":
214+ case "EVideo":
215+ return newElement_38(case2)(case3 * h__108 / case4)(h__108)(case5)(case6);
216+ }
217+ return newElement_38(case2)(case3)(h__108)(case5)(case6)
218+ }(case2)
219+ }
220+ throw"Non-exhaustive pattern match in case";
221+ }(Element$_ewhoc_109)
222+ }
223+ }
224+ function size_49(w__115) {
225+ return function(h__116) {
226+ return function(Element$_ewhoc_117) {
227+ return function(case7) {
228+ var case0 = case7;
229+ switch(case0[0]) {
230+ case "Element":
231+ var case1 = case0[1], case2 = case0[2], case3 = case0[3], case4 = case0[4], case5 = case0[5], case6 = case0[6];
232+ return newElement_38(case2)(w__115)(h__116)(case5)(case6)
233+ }
234+ throw"Non-exhaustive pattern match in case";
235+ }(Element$_ewhoc_117)
236+ }
237+ }
238+ }
239+ function opacity_50(o__123) {
240+ return function(Element$_ewhoc_124) {
241+ return function(case7) {
242+ var case0 = case7;
243+ switch(case0[0]) {
244+ case "Element":
245+ var case1 = case0[1], case2 = case0[2], case3 = case0[3], case4 = case0[4], case5 = case0[5], case6 = case0[6];
246+ return newElement_38(case2)(case3)(case4)(o__123)(case6)
247+ }
248+ throw"Non-exhaustive pattern match in case";
249+ }(Element$_ewhoc_124)
250+ }
251+ }
252+ function color_51(c__130) {
253+ return function(Element$_ewhoc_131) {
254+ return function(case7) {
255+ var case0 = case7;
256+ switch(case0[0]) {
257+ case "Element":
258+ var case1 = case0[1], case2 = case0[2], case3 = case0[3], case4 = case0[4], case5 = case0[5], case6 = case0[6];
259+ return newElement_38(case2)(case3)(case4)(case5)(Just(c__130))
260+ }
261+ throw"Non-exhaustive pattern match in case";
262+ }(Element$_ewhoc_131)
263+ }
264+ }
265+ function widthOf_52(e) { return ~~e[3]; }
266+ function heightOf_53(e) { return ~~e[4]; }
267+ function sizeOf_54(e) { return["Tuple2", ~~e[3], ~~e[4]] }
268+ function text_56(txt) {
269+ var p = Value.getTextSize(-1,-1,txt);
270+ return newElement_38(EText_39("left")(txt))(p[0])(p[1])(1)(Nothing)
271+ }
272+ function plainText(str) {
273+ var txt = Value.toText(str);
274+ var p = Value.getTextSize(-1,-1,txt);
275+ return newElement_38(EText_39("left")(txt))(p[0])(p[1])(1)(Nothing)
276+ }
277+ function asText(v) {
278+ var txt = Value.show(v);
279+ var p = Value.getTextSize(-1,-1,txt);
280+ return newElement_38(EText_39("left")(txt))(p[0])(p[1])(1)(Nothing)
281+ }
282+ function centeredText(txt) {
283+ var p = Value.getTextSize(-1,-1,txt);
284+ return newElement_38(EText_39("center")(txt))(p[0])(p[1])(1)(Nothing)
285+ }
286+ function justifiedText(txt) {
287+ var p = Value.getTextSize(-1,-1,txt);
288+ return newElement_38(EText_39("justify")(txt))(p[0])(p[1])(1)(Nothing)
289+ }
290+ function rightedText(txt) {
291+ var p = Value.getTextSize(-1,-1,txt);
292+ return newElement_38(EText_39("right")(txt))(p[0])(p[1])(1)(Nothing)
293+ }
294+ function image_57(w) {
295+ return function(h) {
296+ return function(src) {
297+ return newElement_38(EImage_40(src))(w)(h)(1)(Nothing)
298+ }
299+ }
300+ }
301+ function video_58(w) {
302+ return function(h) {
303+ return function(src) {
304+ return newElement_38(EVideo_41(src))(w)(h)(1)(Nothing)
305+ }
306+ }
307+ }
308+ function fittedImage_59(w_147) {
309+ return function(h_148) {
310+ return function(s_149) {
311+ return newElement_38(EFittedImage_42(s_149))(w_147)(h_148)(1)(Nothing)
312+ }
313+ }
314+ }
315+ function flow_60(dir_150) {
316+ return function(es_151) {
317+ return function() {
318+ var w_152 = function() {
319+ var ws_154 = map(widthOf_52)(es_151);
320+ return function(case1) {
321+ var case0 = case1;
322+ switch(case0[0]) {
323+ case "DLeft":
324+ return sum(ws_154);
325+ case "DRight":
326+ return sum(ws_154)
327+ }
328+ return maximum(ws_154)
329+ }(dir_150)
330+ }();
331+ var h_153 = function() {
332+ var hs_155 = map(heightOf_53)(es_151);
333+ return function(case3) {
334+ var case2 = case3;
335+ switch(case2[0]) {
336+ case "DDown":
337+ return sum(hs_155);
338+ case "DUp":
339+ return sum(hs_155)
340+ }
341+ return maximum(hs_155)
342+ }(dir_150)
343+ }();
344+ return newElement_38(EFlow_43(dir_150)(es_151))(w_152)(h_153)(1)(Nothing)
345+ }()
346+ }
347+ }
348+ function above_61(e1_156) {
349+ return function(e2_157) {
350+ return newElement_38(EFlow_43(DDown_3)(["Cons", e1_156, ["Cons", e2_157, ["Nil"]]]))(max(widthOf_52(e1_156))(widthOf_52(e2_157)))(heightOf_53(e1_156) + heightOf_53(e2_157))(1)(Nothing)
351+ }
352+ }
353+ function below_62(e1_158) {
354+ return function(e2_159) {
355+ return newElement_38(EFlow_43(DDown_3)(["Cons", e2_159, ["Cons", e1_158, ["Nil"]]]))(max(widthOf_52(e1_158))(widthOf_52(e2_159)))(heightOf_53(e1_158) + heightOf_53(e2_159))(1)(Nothing)
356+ }
357+ }
358+ function beside_63(e1_160) {
359+ return function(e2_161) {
360+ return newElement_38(EFlow_43(DRight_1)(["Cons", e1_160, ["Cons", e2_161, ["Nil"]]]))(widthOf_52(e1_160) + widthOf_52(e2_161))(max(heightOf_53(e1_160))(heightOf_53(e2_161)))(1)(Nothing)
361+ }
362+ }
363+ function layers_64(es_162) {
364+ return newElement_38(EFlow_43(DOut_5)(es_162))(maximum(map(widthOf_52)(es_162)))(maximum(map(heightOf_53)(es_162)))(1)(Nothing)
365+ }
366+ function collage_65(w_163) {
367+ return function(h_164) {
368+ return function(forms_165) {
369+ return newElement_38(ECollage_44(w_163)(h_164)(forms_165))(w_163)(h_164)(1)(Nothing)
370+ }
371+ }
372+ }
373+ function spacer_66(w_166) {
374+ return function(h_167) {
375+ return newElement_38(EEmpty_45)(w_166)(h_167)(1)(Nothing)
376+ }
377+ }
378+ function container_67(pos_168) {
379+ return function(w_169) {
380+ return function(h_170) {
381+ return function(e_171) {
382+ return newElement_38(EContainer_46(pos_168)(e_171))(w_169)(h_170)(1)(Nothing)
383+ }
384+ }
385+ }
386+ }
387+ function segment_77(p1_172) {
388+ return function(p2_173) {
389+ return Line_75(["Cons", p1_172, ["Cons", p2_173, ["Nil"]]])
390+ }
391+ }
392+ function rect_80(w_174) {
393+ return function(h_175) {
394+ return function(pos_176) {
395+ return Shape_78(["Cons", ["Tuple2", 0 - w_174 / 2, 0 - h_175 / 2], ["Cons", ["Tuple2", 0 - w_174 / 2, h_175 / 2], ["Cons", ["Tuple2", w_174 / 2, h_175 / 2], ["Cons", ["Tuple2", w_174 / 2, 0 - h_175 / 2], ["Nil"]]]]])(pos_176)
396+ }
397+ }
398+ }
399+ function oval_81(w_177) {
400+ return function(h_178) {
401+ return function(pos_179) {
402+ return function() {
403+ var n_180 = 50;
404+ return function() {
405+ function f_181(i_182) {
406+ return["Tuple2", w_177 / 2 * cos(2 * (pi / n_180) * i_182), h_178 / 2 * sin(2 * (pi / n_180) * i_182)]
407+ }
408+ return Shape_78(map(f_181)(function() {
409+ var lo = 0;
410+ var hi = n_180 - 1;
411+ var lst = ["Nil"];
412+ if(lo <= hi) {
413+ do {
414+ var lst = ["Cons", hi, lst]
415+ }while(hi-- > lo)
416+ }
417+ return lst
418+ }()))(pos_179)
419+ }()
420+ }()
421+ }
422+ }
423+ }
424+ function circle_82(r_183) {
425+ return oval_81(2 * r_183)(2 * r_183)
426+ }
427+ function ngon_83(n_184) {
428+ return function(r_185) {
429+ return function(pos_186) {
430+ return function() {
431+ var m_187 = toFloat(n_184);
432+ return function() {
433+ function f_188(i_189) {
434+ return["Tuple2", r_185 * cos(2 * (pi / m_187) * i_189), r_185 * sin(2 * (pi / m_187) * i_189)]
435+ }
436+ return Shape_78(map(f_188)(function() {
437+ var lo = 0;
438+ var hi = n_184 - 1;
439+ var lst = ["Nil"];
440+ if(lo <= hi) {
441+ do {
442+ var lst = ["Cons", hi, lst]
443+ }while(hi-- > lo)
444+ }
445+ return lst
446+ }()))(pos_186)
447+ }()
448+ }()
449+ }
450+ }
451+ }
452+ function solid_89(clr_190) {
453+ return function(ln_191) {
454+ return Form_84(0)(1)(["Tuple2", 0, 0])(FLine_85(Solid_68)(clr_190)(ln_191))
455+ }
456+ }
457+ function dotted_90(clr_192) {
458+ return function(ln_193) {
459+ return Form_84(0)(1)(["Tuple2", 0, 0])(FLine_85(Dotted_69)(clr_192)(ln_193))
460+ }
461+ }
462+ function dashed_91(clr_194) {
463+ return function(ln_195) {
464+ return Form_84(0)(1)(["Tuple2", 0, 0])(FLine_85(Dashed_70)(clr_194)(ln_195))
465+ }
466+ }
467+ function customLine_92(pattern_196) {
468+ return function(clr_197) {
469+ return function(ln_198) {
470+ return Form_84(0)(1)(["Tuple2", 0, 0])(FLine_85(Custom_71(pattern_196))(clr_197)(ln_198))
471+ }
472+ }
473+ }
474+ function filled_93(clr) {
475+ return function(shape) {
476+ return Form_84(0)(1)(shape[2])(FShape_86(Filled_72)(clr)(shape));
477+ }
478+ }
479+ function outlined_94(clr) {
480+ return function(shape) {
481+ return Form_84(0)(1)(shape[2])(FShape_86(Outlined_73)(clr)(shape));
482+ }
483+ }
484+ function customOutline_95(pattern) {
485+ return function(clr) {
486+ return function(shape) {
487+ return Form_84(0)(1)(shape[2])(FShape_86(["CustomOutline",pattern])(clr)(shape));
488+ }
489+ }
490+ }
491+ function textured(src) {
492+ return function(shape) {
493+ return Form_84(0)(1)(shape[2])(FShape_86(["Textured",src])(null)(shape));
494+ }
495+ }
496+ function rotate_98(t_212) {
497+ return function(Form$thetascaleposform_213) {
498+ return function(case5) {
499+ var case0 = case5;
500+ switch(case0[0]) {
501+ case "Form":
502+ var case1 = case0[1], case2 = case0[2], case3 = case0[3], case4 = case0[4];
503+ return Form_84(t_212 + case1)(case2)(case3)(case4)
504+ }
505+ throw"Non-exhaustive pattern match in case";
506+ }(Form$thetascaleposform_213)
507+ }
508+ }
509+ function scale_99(s_218) {
510+ return function(Form$thetascaleposform_219) {
511+ return function(case5) {
512+ var case0 = case5;
513+ switch(case0[0]) {
514+ case "Form":
515+ var case1 = case0[1], case2 = case0[2], case3 = case0[3], case4 = case0[4];
516+ return Form_84(case1)(s_218 * case2)(case3)(case4)
517+ }
518+ throw"Non-exhaustive pattern match in case";
519+ }(Form$thetascaleposform_219)
520+ }
521+ }
522+ function move_100(x_224) {
523+ return function(y_225) {
524+ return function(Form$thetascaleTuple2$pxpyform_226) {
525+ return function(case7) {
526+ var case0 = case7;
527+ switch(case0[0]) {
528+ case "Form":
529+ var case1 = case0[1], case2 = case0[2], case3 = case0[3], case4 = case0[4];
530+ switch(case3[0]) {
531+ case "Tuple2":
532+ var case5 = case3[1], case6 = case3[2];
533+ return Form_84(case1)(case2)(["Tuple2", x_224 + case5, y_225 + case6])(case4)
534+ }
535+ break
536+ }
537+ throw"Non-exhaustive pattern match in case";
538+ }(Form$thetascaleTuple2$pxpyform_226)
539+ }
540+ }
541+ }
542+ return{left:left_6, right:right_7, down:down_8, up:up_9, inward:inward_10, outward:outward_11, topLeft:topLeft_22, topRight:topRight_23, bottomLeft:bottomLeft_24, bottomRight:bottomRight_25, midLeft:midLeft_26, midRight:midRight_27, midTop:midTop_28, midBottom:midBottom_29, middle:middle_30, topLeftAt:topLeftAt_31, topRightAt:topRightAt_32, bottomLeftAt:bottomLeftAt_33, bottomRightAt:bottomRightAt_34, absolute:absolute_35, relative:relative_36, width:width_47, height:height_48, size:size_49, opacity:opacity_50,
543+ color:color_51, widthOf:widthOf_52, heightOf:heightOf_53, sizeOf:sizeOf_54, text:text_56, plainText:plainText, centeredText:centeredText, justifiedText:justifiedText, rightedText:rightedText, image:image_57, video:video_58, fittedImage:fittedImage_59, flow:flow_60, above:above_61, below:below_62, beside:beside_63, layers:layers_64, collage:collage_65, spacer:spacer_66, container:container_67, line:line_76, segment:segment_77, polygon:polygon_79, rect:rect_80, oval:oval_81, circle:circle_82, ngon:ngon_83, solid:solid_89, dotted:dotted_90, dashed:dashed_91, customLine:customLine_92, filled:filled_93,
544+ outlined:outlined_94, customOutline:customOutline_95, textured:textured, sprite:sprite_96, toForm:toForm_97, rotate:rotate_98, scale:scale_99, move:move_100}
545+}();
core-js/Graphics/Render.jsnew file+177
@@ -0,0 +1,177 @@
1+
2+var Render = function(){
3+
4+function newElement(elementType) {
5+ var e = document.createElement(elementType);
6+ e.style.padding = "0";
7+ e.style.margin = "0";
8+ return e;
9+};
10+
11+function addTo(container, elem) {
12+ container.appendChild(elem);
13+};
14+
15+function makeText(pos,txt) {
16+ var e = newElement('div');
17+ e.innerHTML = txt;
18+ e.style.textAlign = pos;
19+ return e;
20+};
21+
22+function image(src) {
23+ var img = newElement('img');
24+ img.src = Value.toText(src);
25+ img.name = img.src;
26+ return img;
27+}
28+
29+function fittedImage(w,h,src) {
30+ var canvas = newElement('canvas');
31+ canvas.style.width = w + 'px';
32+ canvas.style.height = h + 'px';
33+ canvas.width = w;
34+ canvas.height = h;
35+ canvas.innerHTML = "Your browser does not support the canvas element.";
36+
37+ var img = newElement('img');
38+ img.onload = function() {
39+ if (canvas.getContext) {
40+ var ctx = canvas.getContext('2d');
41+ var sx = 0, sy = 0, sWidth = this.width, sHeight = this.height;
42+ if (w / h > this.width / this.height) {
43+ sHeight = this.width * h / w;
44+ sy = (this.height - sHeight) / 2;
45+ } else {
46+ sWidth = this.height * w / h;
47+ sx = (this.width - sWidth) / 2;
48+ }
49+ ctx.drawImage(img, sx, sy, sWidth, sHeight,
50+ 0,0, canvas.width, canvas.height);
51+ }
52+ };
53+ img.src = Value.toText(src);
54+ return canvas;
55+};
56+
57+var video = function(src) {
58+ src = Value.toText(src);
59+ var e = newElement('video');
60+ e.controls = "controls";
61+ var source = newElement('source');
62+ source.src = src;
63+ var segs = src.split('.');
64+ source.type = "video/" + segs[segs.length-1];
65+ addTo(e, source);
66+ return e;
67+};
68+
69+function divify(e) {
70+ var div = newElement('div');
71+ addTo(div, e);
72+ return div;
73+};
74+function goDown(e) {
75+ return e //.tagName === "DIV" ? e : divify(e);
76+};
77+function goRight(e) {
78+ e.style.styleFloat = "left";
79+ e.style.cssFloat = "left";
80+ return e;
81+};
82+function goIn(e) {
83+ e.style.position = 'absolute';
84+ return e;
85+};
86+function flowWith(f, prep, elist) {
87+ var container = newElement('div');
88+ for (var i = elist.length; i--; ) {
89+ addTo(container, f(prep(elist[i])));
90+ }
91+ return container;
92+};
93+
94+function flow(dir,elist) {
95+ switch(dir) {
96+ case "DDown": elist = elist.slice(0).reverse();
97+ case "DUp": return flowWith(goDown,render,elist);
98+ case "DRight": elist = elist.slice(0).reverse();
99+ case "DLeft": return flowWith(goRight,render,elist);
100+ case "DOut": elist = elist.slice(0).reverse();
101+ case "DIn": return flowWith(goIn,render,elist);
102+ };
103+};
104+
105+function render(elem) {
106+ var e = {};
107+ switch(elem[2][0]) {
108+ case "EText": e = makeText(elem[2][1],elem[2][2]); break;
109+ case "EImage": e = image(elem[2][1]); break;
110+ case "EVideo": e = video(elem[2][1]); break;
111+ case "EFittedImage": e = fittedImage(elem[3],elem[4],elem[2][1]); break;
112+ case "EFlow": e = flow(elem[2][1][0],elem[2][2]); break;
113+ case "ECollage": e = Collage.collage(elem[2][1],elem[2][2],elem[2][3]); break;
114+ case "EEmpty": e = newElement('div'); break;
115+ case "EContainer":
116+ e = newElement('div');
117+ }
118+ e.id = elem[1];
119+ e.style.width = (~~elem[3]) + 'px';
120+ e.style.height = (~~elem[4]) + 'px';
121+ if (elem[5] !== 1) { e.style.opacity = elem[5]; }
122+ if (elem[6][0] === "Just") {
123+ e.style.color = ElmCode.Graphics.Color.extract(elem[6][1]);
124+ }
125+ return e;
126+};
127+
128+function update(node,curr,next) {
129+ if (curr[1] === next[1]) return;
130+ if (curr[2][0] !== next[2][0]) {
131+ node.parentNode.replaceChild(render(next),node);
132+ }
133+ var nextE = next[2], currE = curr[2];
134+ switch(nextE[0]) {
135+ case "EText":
136+ if (nextE[1] !== currE[1]) node.innerHTML = Value.toText(nextE[1]);
137+ break;
138+ case "EImage":
139+ if (nextE[1] !== currE[1]) node.src = nextE[1];
140+ break;
141+ case "EVideo":
142+ case "EFittedImage":
143+ if (Value.eq(nextE,currE)) break;
144+ return node.parentNode.replaceChild(render(next),node);
145+ case "ECollage":
146+ if (nextE[1] !== currE[1] || nextE[2] !== currE[2]) {
147+ return node.parentNode.replaceChild(render(nextE),node);
148+ }
149+ Collage.updateCollage(node,currE[3],nextE[3]);
150+ break;
151+ case "EFlow":
152+ if (nextE[1] !== currE[1])
153+ return node.parentNode.replaceChild(render(next),node);
154+ var nexts = nextE[2];
155+ var kids = node.childNodes;
156+ if (nexts.length !== kids.length)
157+ return node.parentNode.replaceChild(render(next),node);
158+ var currs = currE[2];
159+ for (var i = kids.length ; i-- ; ) {
160+ update(kids[i],currs[i],nexts[i]);
161+ }
162+ case "EContainer":
163+ case "EEmpty":
164+ }
165+ if (next[3] !== curr[3]) node.style.width = (~~next[3]) + 'px';
166+ if (next[4] !== curr[4]) node.style.height = (~~next[4]) + 'px';
167+ if (next[5] !== curr[5]) node.style.opacity = next[5];
168+ if (next[6].length === 2) {
169+ var clr = ElmCode.Graphics.Color.extract(next[6][1]);
170+ if (clr !== node.style.color) node.style.color = clr;
171+ }
172+ next[1] = curr[1];
173+}
174+
175+return {render:render,update:update,addTo:addTo,newElement:newElement,flowWith:flowWith,goIn:goIn};
176+
177+}();
core-js/Value.js+43−1
@@ -78,6 +78,46 @@ var Value = function(){
78 return properEscape(a.join(''));
78 return properEscape(a.join(''));
79 };
79 };
80
80
81+ function getTextSize(w,h,txt) {
82+ var t = document.createElement('div');
83+ t.innerHTML = txt;
84+ t.style.width = w + "px";
85+ //t.style.height = h + 'px';
86+
87+ t.style.visibility = "hidden";
88+ t.style.styleFloat = "left";
89+ t.style.cssFloat = "left";
90+
91+ document.body.appendChild(t);
92+ var cStyle = window.getComputedStyle(t);
93+ var realW = cStyle.getPropertyValue("width").slice(0,-2) - 0;
94+ var realH = cStyle.getPropertyValue("height").slice(0,-2) - 0;
95+ document.body.removeChild(t);
96+ return [realW,Math.max(h,realH)];
97+ }
98+
99+ function groupForms(forms) {
100+ forms = Foreign.JavaScript.castListToJSArray(forms);
101+ var groups = [];
102+ var arr = [];
103+ for (var i = forms.length; i--; ) {
104+ var f = forms[i];
105+ switch(f[4][0]) {
106+ case "FElement":
107+ if (arr.length > 0) {
108+ groups.push(arr);
109+ arr = [];
110+ }
111+ groups.push(f);
112+ break;
113+ default:
114+ arr.push(f);
115+ }
116+ }
117+ if (arr.length > 0) groups.push(arr);
118+ return groups;
119+ }
120+
81 var toString = function(v) {
121 var toString = function(v) {
82 if (typeof v === "boolean") {
122 if (typeof v === "boolean") {
83 return v ? "True" : "False";
123 return v ? "True" : "False";
@@ -160,5 +200,7 @@ var Value = function(){
160 append:append,
200 append:append,
161 listToArray:listToArray,
201 listToArray:listToArray,
162 toText : toText,
202 toText : toText,
163− properEscape : properEscape};
203+ properEscape : properEscape,
204+ getTextSize : getTextSize,
205+ groupForms : groupForms };
164}();
206}();
core-js/cat.bat+1−3
@@ -1,7 +1,5 @@
1−copy /B Guid.js+foreign\JavaScript.js+foreign\JSON.js+Value.js+List.js+Data.js+collage\Color.js+Element.js+Text.js+collage\Shape.js+collage\Line.js+runtime\Dispatcher.js+runtime\Signal.js+Prelude.js+Everything.js ..\elm-mini.js
1+copy /B Guid.js+foreign\JavaScript.js+foreign\JSON.js+Value.js+List.js+Data.js+Graphics\Color.js+Graphics\Collage.js+Graphics\Element.js+Text.js+Graphics\Render.js+runtime\Dispatcher.js+runtime\Signal.js+Prelude.js+Everything.js ..\elm-mini.js
2
2
3cd ..\elm
3cd ..\elm
4
4
5copy /B ..\elm-mini.js elm-runtime-0.4.0.js
5copy /B ..\elm-mini.js elm-runtime-0.4.0.js
6−
7−cabal install
core-js/runtime/Dispatcher.js+35−50
@@ -10,10 +10,12 @@ var Elm = function() {
10 this.id = Guid.guid();
10 this.id = Guid.guid();
11 this.value = base;
11 this.value = base;
12 this.kids = [];
12 this.kids = [];
13+ this.defaultNumberOfKids = 0;
13 this.recv = function(timestep, eid, v) {
14 this.recv = function(timestep, eid, v) {
14 var changed = eid === this.id;
15 var changed = eid === this.id;
15 if (changed) { this.value = v; }
16 if (changed) { this.value = v; }
16 send(this, timestep, changed);
17 send(this, timestep, changed);
18+ return changed;
17 };
19 };
18 Dispatcher.inputs.push(this);
20 Dispatcher.inputs.push(this);
19 };
21 };
@@ -123,75 +125,58 @@ var Dispatcher = function() {
123 var program = null;
125 var program = null;
124 var timestep = 0;
126 var timestep = 0;
125 var inputs = [];
127 var inputs = [];
126−
128+ var currentElement = null;
127− var correctSize = function(e) {
128− var kids = e.childNodes;
129− var len = kids.length;
130− if (e.hasOwnProperty('isElmLeaf')) {
131− if (e.hasOwnProperty('isElmText')) { Element.correctTextSize(e); }
132− var w = e.style.width === "" ?
133− 0 : e.style.width.slice(0,-2) - 0;
134− var h = e.style.height === "" ?
135− 0 : e.style.height.slice(0,-2) - 0;
136− return [w, h];
137− }
138− if (len === 1) {
139− var dim = correctSize(kids[0]);
140− if (e.style.width !== "") { dim[0] = e.style.width.slice(0,-2) - 0; }
141− if (e.style.height !== "") { dim[1] = e.style.height.slice(0,-2) - 0; }
142− if (dim[0] !== 0) { e.style.width = dim[0] + "px"; }
143− if (dim[1] !== 0) { e.style.height = dim[1] + "px"; }
144− return dim;
145− }
146− var wmax = 0, hmax = 0, wsum = 0, hsum = 0;
147− var hasWidth = true, hasHeight = true, dim = null;
148− while (len--) {
149− dim = correctSize(kids[len]);
150− wmax = Math.max(wmax, dim[0]);
151− hmax = Math.max(hmax, dim[1]);
152− wsum += dim[0];
153− hsum += dim[1];
154− hasWidth = hasWidth && dim[0] > 0;
155− hasHeight = hasHeight && dim[1] > 0;
156− }
157− var w = wmax, h = hmax, dir = e.elmFlowDirection;
158− if (dir === "X") { w = hasWidth ? wsum : 0; }
159− if (dir === "Y") { h = hasHeight ? hsum : 0; }
160− if (w > 0) e.style.width = w + "px";
161− if (h > 0) e.style.height = h + "px";
162− return [w,h];
163− };
164
129
165 var initialize = function() {
130 var initialize = function() {
166 program = ElmCode.main();
131 program = ElmCode.main();
167 if (!program.hasOwnProperty('recv')) {
132 if (!program.hasOwnProperty('recv')) {
168 program = Elm.Input(program);
133 program = Elm.Input(program);
169 }
134 }
135+
136+ currentElement = program.value;
137+ filterDeadInputs();
138+
170 var content = document.getElementById('content');
139 var content = document.getElementById('content');
171− content.appendChild(program.value);
140+ content.appendChild(Render.render(currentElement));
172− adjust();
173 var w = document.getElementById('widthChecker').offsetWidth;
141 var w = document.getElementById('widthChecker').offsetWidth;
174 if (w !== window.innerWidth) {
142 if (w !== window.innerWidth) {
175 Dispatcher.notify(Window.dimensions.id, Value.Tuple(w, window.innerHeight));
143 Dispatcher.notify(Window.dimensions.id, Value.Tuple(w, window.innerHeight));
176 }
144 }
177 program = Elm.Lift(function(value) {
145 program = Elm.Lift(function(value) {
178 var content = document.getElementById('content');
146 var content = document.getElementById('content');
179− var kid = content.children[0]
147+ Render.update(content.firstChild,currentElement,value);
180− content.replaceChild(value, kid);
148+ currentElement = value;
181− delete kid;
182− adjust();
183 return value;
149 return value;
184 }, [program]);
150 }, [program]);
185 };
151 };
186− var adjust = function() {
187− var content = document.getElementById('content');
188− correctSize(content.children[0]);
189− }
190 var notify = function(id, v) {
152 var notify = function(id, v) {
191 timestep += 1;
153 timestep += 1;
154+ //console.log(timestep);
155+ var hasListener = false;
192 for (var i = inputs.length; i--; ) {
156 for (var i = inputs.length; i--; ) {
193− inputs[i].recv(timestep, id, v);
157+ hasListener = inputs[i].recv(timestep, id, v) || hasListener;
194 }
158 }
159+ return hasListener;
195 };
160 };
161+
162+ function isAlive(input) {
163+ if (!input.hasOwnProperty('defaultNumberOfKids')) return true;
164+ var len = input.kids.length;
165+ if (len == 0) return false;
166+ if (len > input.defaultNumberOfKids) return true;
167+ var alive = false;
168+ for (var i = len; i--; ) {
169+ alive = alive || isAlive(input.kids[i]);
170+ }
171+ return alive;
172+ }
173+ function filterDeadInputs() {
174+ var temp = [];
175+ for (var i = inputs.length; i--; ) {
176+ if (isAlive(inputs[i])) temp.push(inputs[i]);
177+ }
178+ inputs = temp;
179+ }
180+
196− return {initialize:initialize, notify:notify, adjust:adjust, inputs:inputs};
181+ return {initialize:initialize, notify:notify, inputs:inputs};
197}();
182}();
core-js/runtime/Signal.js+49−16
@@ -22,6 +22,13 @@ var Signal = function() {
22
22
23 var Mouse = function() {
23 var Mouse = function() {
24 var position = Elm.Input(Value.Tuple(0,0));
24 var position = Elm.Input(Value.Tuple(0,0));
25+ position.defaultNumberOfKids = 2;
26+
27+ var x = Elm.Lift(function(p){return p[1];},[position]);
28+ x.defaultNumberOfKids = 0;
29+ var y = Elm.Lift(function(p){return p[2];},[position]);
30+ y.defaultNumberOfKids = 0;
31+
25 var isDown = Elm.Input(false);
32 var isDown = Elm.Input(false);
26 var isClicked = Elm.Input(false);
33 var isClicked = Elm.Input(false);
27 var clicks = Elm.Input(Value.Tuple());
34 var clicks = Elm.Input(Value.Tuple());
@@ -43,16 +50,27 @@ var Signal = function() {
43 }
50 }
44
51
45 addListener(document, 'click', function(e) {
52 addListener(document, 'click', function(e) {
46− Dispatcher.notify(isClicked.id, true);
53+ var hasListener1 = Dispatcher.notify(isClicked.id, true);
47− Dispatcher.notify(clicks.id, Value.Tuple());
54+ var hasListener2 = Dispatcher.notify(clicks.id, Value.Tuple());
48 Dispatcher.notify(isClicked.id, false);
55 Dispatcher.notify(isClicked.id, false);
56+ if (!hasListener1 && !hasListener2)
57+ this.removeEventListener('click',arguments.callee,false);
49 });
58 });
50 addListener(document, 'mousedown', function(e) {
59 addListener(document, 'mousedown', function(e) {
51− Dispatcher.notify(isDown.id, true); });
60+ var hasListener = Dispatcher.notify(isDown.id, true);
61+ if (!hasListener)
62+ this.removeEventListener('mousedown',arguments.callee,false);
63+ });
52 addListener(document, 'mouseup', function(e) {
64 addListener(document, 'mouseup', function(e) {
53− Dispatcher.notify(isDown.id, false); });
65+ var hasListener = Dispatcher.notify(isDown.id, false);
66+ if (!hasListener)
67+ this.removeEventListener('mouseup',arguments.callee,false);
68+ });
54 addListener(document, 'mousemove', function(e) {
69 addListener(document, 'mousemove', function(e) {
55− Dispatcher.notify(position.id, getXY(e)); });
70+ var hasListener = Dispatcher.notify(position.id, getXY(e));
71+ if (!hasListener)
72+ this.removeEventListener('mousemove',arguments.callee,false);
73+ });
56 var clickedOn = function(elem) {
74 var clickedOn = function(elem) {
57 var click = Elm.Input(false);
75 var click = Elm.Input(false);
58 addListener(elem, 'click', function(e) {
76 addListener(elem, 'click', function(e) {
@@ -62,8 +80,8 @@ var Signal = function() {
62 return Value.Tuple(elem, click);
80 return Value.Tuple(elem, click);
63 };
81 };
64 return {position: position,
82 return {position: position,
65− x: Elm.Lift(function(p){return p[1];},[position]),
83+ x:x,
66− y: Elm.Lift(function(p){return p[2];},[position]),
84+ y:y,
67 isClicked: isClicked,
85 isClicked: isClicked,
68 isDown: isDown,
86 isDown: isDown,
69 clicks: clicks,
87 clicks: clicks,
@@ -99,13 +117,20 @@ var Signal = function() {
99
117
100 var Window = function() {
118 var Window = function() {
101 var dimensions = Elm.Input(Value.Tuple(window.innerWidth,window.innerHeight));
119 var dimensions = Elm.Input(Value.Tuple(window.innerWidth,window.innerHeight));
120+ dimensions.defaultNumberOfKids = 2;
121+
122+ var width = Elm.Lift(function(p){return p[1];},[dimensions]);
123+ width.defaultNumberOfKids = 0;
124+ var height = Elm.Lift(function(p){return p[2];},[dimensions]);
125+ height.defaultNumberOfKids = 0;
126+
102 addListener(window, 'resize', function(e) {
127 addListener(window, 'resize', function(e) {
103 var w = document.getElementById('widthChecker').offsetWidth;
128 var w = document.getElementById('widthChecker').offsetWidth;
104− Dispatcher.notify(dimensions.id, Value.Tuple(w, window.innerHeight));
129+ var hasListener = Dispatcher.notify(dimensions.id, Value.Tuple(w, window.innerHeight));
130+ if (!hasListener)
131+ this.removeEventListener('resize',arguments.callee,false);
105 });
132 });
106− return {dimensions:dimensions,
133+ return {dimensions:dimensions,width:width,height:height};
107− width : Elm.Lift(function(p){return p[1];},[dimensions]),
108− height: Elm.Lift(function(p){return p[2];},[dimensions]) };
109 }();
134 }();
110
135
111 var Keyboard = { Raw : function() {
136 var Keyboard = { Raw : function() {
@@ -125,18 +150,26 @@ var Signal = function() {
125 }
150 }
126 addListener(document, 'keydown', function(e) {
151 addListener(document, 'keydown', function(e) {
127 if (has(e.keyCode, keysDown.value)) return;
152 if (has(e.keyCode, keysDown.value)) return;
128− Dispatcher.notify(keysDown.id, ["Cons", e.keyCode, keysDown.value]);
153+ var hasListener = Dispatcher.notify(keysDown.id, ["Cons", e.keyCode, keysDown.value]);
154+ if (!hasListener)
155+ this.removeEventListener('keydown',arguments.callee,false);
129 });
156 });
130 addListener(document, 'keyup', function(e) {
157 addListener(document, 'keyup', function(e) {
131− var codes = remove(e.keyCode, keysDown.value)
158+ var codes = remove(e.keyCode, keysDown.value);
132− Dispatcher.notify(keysDown.id, codes);
159+ var hasListener = Dispatcher.notify(keysDown.id, codes);
160+ if (!hasListener)
161+ this.removeEventListener('keyup',arguments.callee,false);
133 });
162 });
134 addListener(window, 'blur', function(e) {
163 addListener(window, 'blur', function(e) {
135− Dispatcher.notify(keysDown.id, ["Nil"]);
164+ var hasListener = Dispatcher.notify(keysDown.id, ["Nil"]);
165+ if (!hasListener)
166+ this.removeEventListener('blur',arguments.callee,false);
136 });
167 });
137 addListener(document, 'keypress', function(e) {
168 addListener(document, 'keypress', function(e) {
138− Dispatcher.notify(charPressed.id, ["Just",e.charCode || e.keyCode]);
169+ var hasListener = Dispatcher.notify(charPressed.id, ["Just",e.charCode || e.keyCode]);
139 Dispatcher.notify(charPressed.id, ["Nothing"]);
170 Dispatcher.notify(charPressed.id, ["Nothing"]);
171+ if (!hasListener)
172+ this.removeEventListener('keypress',arguments.callee,false);
140 });
173 });
141 return {keysDown:keysDown,
174 return {keysDown:keysDown,
142 charPressed:charPressed};
175 charPressed:charPressed};