on master help sign in
Get rid of render code, moved it to core libraries repo
commitd90e606f5902c0affede01469b1fdecab546bb0c authorEvan Czaplicki <info@elm-lang.org> dateThu 16 Oct 2014, 18:59 (12 years ago) parentdedbd23
3 files changed−864
runtime/Render/Collage.js−355 runtime/Render/Element.js−469 runtime/Render/Utils.js−40
runtime/Render/Collage.jsdeleted−355
@@ -1,355 +0,0 @@
1−
2−ElmRuntime.Render.Collage = function() {
3−
4−var Render = ElmRuntime.use(ElmRuntime.Render.Element);
5−var Transform = Elm.Transform2D.make({});
6−var Utils = ElmRuntime.use(ElmRuntime.Render.Utils);
7−var newElement = Utils.newElement,
8− colorToCss = Utils.colorToCss, fromList = Utils.fromList,
9− fromString = Utils.fromString, addTransform = Utils.addTransform;
10−
11−function trace(ctx, path) {
12− var points = fromList(path);
13− var i = points.length - 1;
14− if (i <= 0) return;
15− ctx.moveTo(points[i]._0, points[i]._1);
16− while (i--) { ctx.lineTo(points[i]._0, points[i]._1); }
17− if (path.closed) {
18− i = points.length - 1;
19− ctx.lineTo(points[i]._0, points[i]._1);
20− }
21−}
22−
23−function line(ctx,style,path) {
24− style.dashing.ctor === '[]' ? trace(ctx, path) : customLineHelp(ctx, style, path);
25− ctx.scale(1,-1);
26− ctx.stroke();
27−}
28−
29−function customLineHelp(ctx, style, path) {
30− var points = fromList(path);
31− if (path.closed) points.push(points[0]);
32− var pattern = fromList(style.dashing);
33− var i = points.length - 1;
34− if (i <= 0) return;
35− var x0 = points[i]._0, y0 = points[i]._1;
36− var x1=0, y1=0, dx=0, dy=0, remaining=0, nx=0, ny=0;
37− var pindex = 0, plen = pattern.length;
38− var draw = true, segmentLength = pattern[0];
39− ctx.moveTo(x0,y0);
40− while (i--) {
41− x1 = points[i]._0; y1 = points[i]._1;
42− dx = x1 - x0; dy = y1 - y0;
43− remaining = Math.sqrt(dx * dx + dy * dy);
44− while (segmentLength <= remaining) {
45− x0 += dx * segmentLength / remaining;
46− y0 += dy * segmentLength / remaining;
47− ctx[draw ? 'lineTo' : 'moveTo'](x0, y0);
48− // update starting position
49− dx = x1 - x0; dy = y1 - y0;
50− remaining = Math.sqrt(dx * dx + dy * dy);
51− // update pattern
52− draw = !draw;
53− pindex = (pindex + 1) % plen;
54− segmentLength = pattern[pindex];
55− }
56− if (remaining > 0) {
57− ctx[draw ? 'lineTo' : 'moveTo'](x1, y1);
58− segmentLength -= remaining;
59− }
60− x0 = x1; y0 = y1;
61− }
62−}
63−
64−function drawLine(ctx, style, path) {
65− ctx.lineWidth = style.width;
66− var cap = style.cap.ctor;
67− ctx.lineCap = cap === 'Flat' ? 'butt' :
68− cap === 'Round' ? 'round' : 'square';
69− var join = style.join.ctor;
70− ctx.lineJoin = join === 'Smooth' ? 'round' :
71− join === 'Sharp' ? 'miter' : 'bevel';
72− ctx.miterLimit = style.join._0 || 10;
73− ctx.strokeStyle = colorToCss(style.color);
74− return line(ctx, style, path);
75−}
76−
77−function texture(redo, ctx, src) {
78− var img = new Image();
79− img.src = fromString(src);
80− img.onload = redo;
81− return ctx.createPattern(img, 'repeat');
82−}
83−
84−function gradient(ctx, grad) {
85− var g;
86− var stops = [];
87− if (grad.ctor === 'Linear') {
88− var p0 = grad._0, p1 = grad._1;
89− g = ctx.createLinearGradient(p0._0, -p0._1, p1._0, -p1._1);
90− stops = fromList(grad._2);
91− } else {
92− var p0 = grad._0, p2 = grad._2;
93− g = ctx.createRadialGradient(p0._0, -p0._1, grad._1, p2._0, -p2._1, grad._3);
94− stops = fromList(grad._4);
95− }
96− var len = stops.length;
97− for (var i = 0; i < len; ++i) {
98− var stop = stops[i];
99− g.addColorStop(stop._0, colorToCss(stop._1));
100− }
101− return g;
102−}
103−
104−function drawShape(redo, ctx, style, path) {
105− trace(ctx, path);
106− var sty = style.ctor;
107− ctx.fillStyle =
108− sty === 'Solid' ? colorToCss(style._0) :
109− sty === 'Texture' ? texture(redo, ctx, style._0) : gradient(ctx, style._0);
110− ctx.scale(1,-1);
111− ctx.fill();
112−}
113−
114−function drawImage(redo, ctx, form) {
115− var img = new Image();
116− img.onload = redo;
117− img.src = fromString(form._3);
118− var w = form._0,
119− h = form._1,
120− pos = form._2,
121− srcX = pos._0,
122− srcY = pos._1,
123− srcW = w,
124− srcH = h,
125− destX = -w/2,
126− destY = -h/2,
127− destW = w,
128− destH = h;
129−
130− ctx.scale(1,-1);
131− ctx.drawImage(img, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
132−}
133−
134−function renderForm(redo, ctx, form) {
135− ctx.save();
136− var x = form.x, y = form.y, theta = form.theta, scale = form.scale;
137− if (x !== 0 || y !== 0) ctx.translate(x, y);
138− if (theta !== 0) ctx.rotate(theta);
139− if (scale !== 1) ctx.scale(scale,scale);
140− if (form.alpha !== 1) ctx.globalAlpha = ctx.globalAlpha * form.alpha;
141− ctx.beginPath();
142− var f = form.form;
143− switch(f.ctor) {
144− case 'FPath' : drawLine(ctx, f._0, f._1); break;
145− case 'FImage': drawImage(redo, ctx, f); break;
146− case 'FShape':
147− if (f._0.ctor === 'Left') {
148− f._1.closed = true;
149− drawLine(ctx, f._0._0, f._1);
150− } else {
151− drawShape(redo, ctx, f._0._0, f._1);
152− }
153− break;
154− }
155− ctx.restore();
156−}
157−
158−function formToMatrix(form) {
159− var scale = form.scale;
160− var matrix = A6( Transform.matrix, scale, 0, 0, scale, form.x, form.y );
161−
162− var theta = form.theta
163− if (theta !== 0)
164− matrix = A2( Transform.multiply, matrix, Transform.rotation(theta) );
165−
166− return matrix;
167−}
168−
169−function str(n) {
170− if (n < 0.00001 && n > -0.00001) return 0;
171− return n;
172−}
173−
174−function makeTransform(w, h, form, matrices) {
175− var props = form.form._0.props;
176− var m = A6( Transform.matrix, 1, 0, 0, -1,
177− (w - props.width ) / 2,
178− (h - props.height) / 2 );
179− var len = matrices.length;
180− for (var i = 0; i < len; ++i) { m = A2( Transform.multiply, m, matrices[i] ); }
181− m = A2( Transform.multiply, m, formToMatrix(form) );
182−
183− return 'matrix(' + str( m[0]) + ', ' + str( m[3]) + ', ' +
184− str(-m[1]) + ', ' + str(-m[4]) + ', ' +
185− str( m[2]) + ', ' + str( m[5]) + ')';
186−}
187−
188−function stepperHelp(list) {
189− var arr = fromList(list);
190− var i = 0;
191− function peekNext() {
192− return i < arr.length ? arr[i].form.ctor : '';
193− }
194− // assumes that there is a next element
195− function next() {
196− var out = arr[i];
197− ++i;
198− return out;
199− }
200− return { peekNext:peekNext, next:next };
201−}
202−
203−function formStepper(forms) {
204− var ps = [stepperHelp(forms)];
205− var matrices = [];
206− var alphas = [];
207− function peekNext() {
208− var len = ps.length;
209− var formType = '';
210− for (var i = 0; i < len; ++i ) {
211− if (formType = ps[i].peekNext()) return formType;
212− }
213− return '';
214− }
215− // assumes that there is a next element
216− function next(ctx) {
217− while (!ps[0].peekNext()) {
218− ps.shift();
219− matrices.pop();
220− alphas.shift();
221− if (ctx) { ctx.restore(); }
222− }
223− var out = ps[0].next();
224− var f = out.form;
225− if (f.ctor === 'FGroup') {
226− ps.unshift(stepperHelp(f._1));
227− var m = A2(Transform.multiply, f._0, formToMatrix(out));
228− ctx.save();
229− ctx.transform(m[0], m[3], m[1], m[4], m[2], m[5]);
230− matrices.push(m);
231−
232− var alpha = (alphas[0] || 1) * out.alpha;
233− alphas.unshift(alpha);
234− ctx.globalAlpha = alpha;
235− }
236− return out;
237− }
238− function transforms() { return matrices; }
239− function alpha() { return alphas[0] || 1; }
240− return { peekNext:peekNext, next:next, transforms:transforms, alpha:alpha };
241−}
242−
243−function makeCanvas(w,h) {
244− var canvas = newElement('canvas');
245− canvas.style.width = w + 'px';
246− canvas.style.height = h + 'px';
247− canvas.style.display = "block";
248− canvas.style.position = "absolute";
249− canvas.width = w;
250− canvas.height = h;
251− return canvas;
252−}
253−
254−function render(model) {
255− var div = newElement('div');
256− div.style.overflow = 'hidden';
257− div.style.position = 'relative';
258− update(div, model, model);
259− return div;
260−}
261−
262−function nodeStepper(w,h,div) {
263− var kids = div.childNodes;
264− var i = 0;
265− function transform(transforms, ctx) {
266− ctx.translate(w/2, h/2);
267− ctx.scale(1,-1);
268− var len = transforms.length;
269− for (var i = 0; i < len; ++i) {
270− var m = transforms[i];
271− ctx.save();
272− ctx.transform(m[0], m[3], m[1], m[4], m[2], m[5]);
273− }
274− return ctx;
275− }
276− function nextContext(transforms) {
277− while (i < kids.length) {
278− var node = kids[i];
279− if (node.getContext) {
280− node.width = w;
281− node.height = h;
282− node.style.width = w + 'px';
283− node.style.height = h + 'px';
284− ++i;
285− return transform(transforms, node.getContext('2d'));
286− }
287− div.removeChild(node);
288− }
289− var canvas = makeCanvas(w,h);
290− div.appendChild(canvas);
291− // we have added a new node, so we must step our position
292− ++i;
293− return transform(transforms, canvas.getContext('2d'));
294− }
295− function addElement(matrices, alpha, form) {
296− var kid = kids[i];
297− var elem = form.form._0;
298−
299− var node = (!kid || kid.getContext)
300− ? Render.render(elem)
301− : (Render.update(kid, kid.oldElement, elem), kids[i]);
302−
303− node.style.position = 'absolute';
304− node.style.opacity = alpha * form.alpha * elem.props.opacity;
305− addTransform(node.style, makeTransform(w, h, form, matrices));
306− node.oldElement = elem;
307− ++i;
308− if (!kid) {
309− div.appendChild(node);
310− } else if (kid.getContext) {
311− div.insertBefore(node, kid);
312− }
313− }
314− function clearRest() {
315− while (i < kids.length) {
316− div.removeChild(kids[i]);
317− }
318− }
319− return { nextContext:nextContext, addElement:addElement, clearRest:clearRest };
320−}
321−
322−
323−function update(div, _, model) {
324− var w = model.w;
325− var h = model.h;
326−
327− var forms = formStepper(model.forms);
328− var nodes = nodeStepper(w,h,div);
329− var ctx = null;
330− var formType = '';
331−
332− while (formType = forms.peekNext()) {
333− // make sure we have context if we need it
334− if (ctx === null && formType !== 'FElement') {
335− ctx = nodes.nextContext(forms.transforms());
336− ctx.globalAlpha = forms.alpha();
337− }
338−
339− var form = forms.next(ctx);
340− // if it is FGroup, all updates are made within formStepper when next is called.
341− if (formType === 'FElement') {
342− // update or insert an element, get a new context
343− nodes.addElement(forms.transforms(), forms.alpha(), form);
344− ctx = null;
345− } else if (formType !== 'FGroup') {
346− renderForm(function() { update(div, model, model); }, ctx, form);
347− }
348− }
349− nodes.clearRest();
350− return false;
351−}
352−
353−return { render:render, update:update };
354−
355−};
runtime/Render/Element.jsdeleted−469
@@ -1,469 +0,0 @@
1−
2−ElmRuntime.Render.Element = function() {
3−'use strict';
4−
5−var Utils = ElmRuntime.use(ElmRuntime.Render.Utils);
6−var newElement = Utils.newElement;
7−var colorToCss = Utils.colorToCss;
8−var addTransform = Utils.addTransform;
9−var removeTransform = Utils.removeTransform;
10−var fromList = Utils.fromList;
11−var eq = Utils.eq;
12−
13−function setProps(elem, node) {
14− var props = elem.props;
15−
16− var element = elem.element;
17− var width = props.width - (element.adjustWidth || 0);
18− var height = props.height - (element.adjustHeight || 0);
19− node.style.width = (width |0) + 'px';
20− node.style.height = (height|0) + 'px';
21−
22− if (props.opacity !== 1) {
23− node.style.opacity = props.opacity;
24− }
25−
26− if (props.color.ctor === 'Just') {
27− node.style.backgroundColor = colorToCss(props.color._0);
28− }
29−
30− if (props.tag !== '') {
31− node.id = props.tag;
32− }
33−
34− if (props.hover.ctor !== '_Tuple0') {
35− addHover(node, props.hover);
36− }
37−
38− if (props.click.ctor !== '_Tuple0') {
39− addClick(node, props.click);
40− }
41−
42− if (props.href !== '') {
43− var anchor = newElement('a');
44− anchor.href = props.href;
45− anchor.style.display = 'block';
46− anchor.style.pointerEvents = 'auto';
47− anchor.appendChild(node);
48− node = anchor;
49− }
50−
51− return node;
52−}
53−
54−function addClick(e, handler) {
55− e.style.pointerEvents = 'auto';
56− e.elm_click_handler = handler;
57− function trigger(ev) {
58− e.elm_click_handler(Utils.Tuple0);
59− ev.stopPropagation();
60− }
61− e.elm_click_trigger = trigger;
62− e.addEventListener('click', trigger);
63−}
64−
65−function removeClick(e, handler) {
66− if (e.elm_click_trigger) {
67− e.removeEventListener('click', e.elm_click_trigger);
68− e.elm_click_trigger = null;
69− e.elm_click_handler = null;
70− }
71−}
72−
73−function addHover(e, handler) {
74− e.style.pointerEvents = 'auto';
75− e.elm_hover_handler = handler;
76− e.elm_hover_count = 0;
77−
78− function over(evt) {
79− if (e.elm_hover_count++ > 0) return;
80− e.elm_hover_handler(true);
81− evt.stopPropagation();
82− }
83− function out(evt) {
84− if (e.contains(evt.toElement || evt.relatedTarget)) return;
85− e.elm_hover_count = 0;
86− e.elm_hover_handler(false);
87− evt.stopPropagation();
88− }
89− e.elm_hover_over = over;
90− e.elm_hover_out = out;
91− e.addEventListener('mouseover', over);
92− e.addEventListener('mouseout', out);
93−}
94−
95−function removeHover(e) {
96− e.elm_hover_handler = null;
97− if (e.elm_hover_over) {
98− e.removeEventListener('mouseover', e.elm_hover_over);
99− e.elm_hover_over = null;
100− }
101− if (e.elm_hover_out) {
102− e.removeEventListener('mouseout', e.elm_hover_out);
103− e.elm_hover_out = null;
104− }
105−}
106−
107−function image(props, img) {
108− switch (img._0.ctor) {
109− case 'Plain': return plainImage(img._3);
110− case 'Fitted': return fittedImage(props.width, props.height, img._3);
111− case 'Cropped': return croppedImage(img,props.width,props.height,img._3);
112− case 'Tiled': return tiledImage(img._3);
113− }
114−}
115−
116−function plainImage(src) {
117− var img = newElement('img');
118− img.src = src;
119− img.name = src;
120− img.style.display = "block";
121− return img;
122−}
123−
124−function tiledImage(src) {
125− var div = newElement('div');
126− div.style.backgroundImage = 'url(' + src + ')';
127− return div;
128−}
129−
130−function fittedImage(w, h, src) {
131− var div = newElement('div');
132− div.style.background = 'url(' + src + ') no-repeat center';
133− div.style.webkitBackgroundSize = 'cover';
134− div.style.MozBackgroundSize = 'cover';
135− div.style.OBackgroundSize = 'cover';
136− div.style.backgroundSize = 'cover';
137− return div;
138−}
139−
140−function croppedImage(elem, w, h, src) {
141− var pos = elem._0._0;
142− var e = newElement('div');
143− e.style.overflow = "hidden";
144−
145− var img = newElement('img');
146− img.onload = function() {
147− var sw = w / elem._1, sh = h / elem._2;
148− img.style.width = ((this.width * sw)|0) + 'px';
149− img.style.height = ((this.height * sh)|0) + 'px';
150− img.style.marginLeft = ((- pos._0 * sw)|0) + 'px';
151− img.style.marginTop = ((- pos._1 * sh)|0) + 'px';
152− };
153− img.src = src;
154− img.name = src;
155− e.appendChild(img);
156− return e;
157−}
158−
159−function goOut(e) { e.style.position = 'absolute'; return e; }
160−function goDown(e) { return e }
161−function goRight(e) { e.style.styleFloat = e.style.cssFloat = "left"; return e; }
162−
163−var directionTable = {
164− DUp : goDown,
165− DDown : goDown,
166− DLeft : goRight,
167− DRight : goRight,
168− DIn : goOut,
169− DOut : goOut
170−};
171−function needsReversal(dir) {
172− return dir == 'DUp' || dir == 'DLeft' || dir == 'DIn';
173−}
174−
175−function flow(dir,elist) {
176− var array = fromList(elist);
177− var container = newElement('div');
178− var goDir = directionTable[dir];
179− if (goDir == goOut) {
180− container.style.pointerEvents = 'none';
181− }
182− if (needsReversal(dir)) {
183− array.reverse();
184− }
185− var len = array.length;
186− for (var i = 0; i < len; ++i) {
187− container.appendChild(goDir(render(array[i])));
188− }
189− return container;
190−}
191−
192−function toPos(pos) {
193− switch(pos.ctor) {
194− case "Absolute": return pos._0 + "px";
195− case "Relative": return (pos._0 * 100) + "%";
196− }
197−}
198−
199−// must clear right, left, top, bottom, and transform
200−// before calling this function
201−function setPos(pos,elem,e) {
202− var element = elem.element;
203− var props = elem.props;
204− var w = props.width + (element.adjustWidth ? element.adjustWidth : 0);
205− var h = props.height + (element.adjustHeight ? element.adjustHeight : 0);
206−
207− e.style.position = 'absolute';
208− e.style.margin = 'auto';
209− var transform = '';
210− switch(pos.horizontal.ctor) {
211− case 'P': e.style.right = toPos(pos.x); e.style.removeProperty('left'); break;
212− case 'Z': transform = 'translateX(' + ((-w/2)|0) + 'px) ';
213− case 'N': e.style.left = toPos(pos.x); e.style.removeProperty('right'); break;
214− }
215− switch(pos.vertical.ctor) {
216− case 'N': e.style.bottom = toPos(pos.y); e.style.removeProperty('top'); break;
217− case 'Z': transform += 'translateY(' + ((-h/2)|0) + 'px)';
218− case 'P': e.style.top = toPos(pos.y); e.style.removeProperty('bottom'); break;
219− }
220− if (transform !== '') addTransform(e.style, transform);
221− return e;
222−}
223−
224−function container(pos,elem) {
225− var e = render(elem);
226− setPos(pos, elem, e);
227− var div = newElement('div');
228− div.style.position = 'relative';
229− div.style.overflow = 'hidden';
230− div.appendChild(e);
231− return div;
232−}
233−
234−function rawHtml(elem) {
235− var html = elem.html;
236− var args = elem.args;
237− var guid = elem.guid;
238− var align = elem.align;
239−
240− var div = newElement('div');
241− div.innerHTML = html;
242− div.style.visibility = "hidden";
243− if (align) div.style.textAlign = align;
244− document.body.appendChild(div);
245−
246− for (var i = args.length; i--; ) {
247− var arg = args[i];
248− var span = document.getElementById('md-' + guid + '-' + i);
249− if (arg.isText) {
250− span.innerHTML = arg;
251− } else {
252− span.style.display = 'block';
253− span.style.width = arg.props.width + 'px';
254− span.style.height = arg.props.height + 'px';
255− span.appendChild(render(arg));
256− }
257− }
258− document.body.removeChild(div);
259− div.style.visibility = 'visible';
260− div.style.pointerEvents = 'auto';
261− return div;
262−}
263−
264−function render(elem) {
265− return setProps(elem, makeElement(elem));
266−}
267−function makeElement(e) {
268− var elem = e.element;
269− switch(elem.ctor) {
270− case 'Image': return image(e.props, elem);
271− case 'Flow': return flow(elem._0.ctor, elem._1);
272− case 'Container': return container(elem._0, elem._1);
273− case 'Spacer': return newElement('div');
274− case 'RawHtml': return rawHtml(elem);
275− case 'Custom': return elem.render(elem.model);
276− }
277−}
278−
279−function update(node, curr, next) {
280− if (node.tagName === 'A') {
281− node = node.firstChild;
282− }
283− if (curr.props.id === next.props.id) {
284− return updateProps(node, curr, next);
285− }
286− if (curr.element.ctor !== next.element.ctor) {
287− node.parentNode.replaceChild(render(next),node);
288− return true;
289− }
290− var nextE = next.element, currE = curr.element;
291− switch(nextE.ctor) {
292− case "Spacer": break;
293− case "RawHtml":
294− // only markdown blocks have guids, so this must be a text block
295− if (nextE.guid === null) {
296− if(currE.html.valueOf() !== nextE.html.valueOf()) {
297− node.innerHTML = nextE.html;
298− }
299− break;
300− }
301− if (nextE.guid !== currE.guid) {
302− node.parentNode.replaceChild(render(next),node);
303− return true;
304− }
305− var nargs = nextE.args;
306− var cargs = currE.args;
307− for (var i = nargs.length; i--; ) {
308− var narg = nargs[i];
309− var carg = cargs[i]
310− if (narg == carg) continue;
311− var span = document.getElementById('md-' + currE.guid + '-' + i);
312− if (narg.isElement) {
313− if (carg.isElement) {
314− update(span, carg, narg);
315− } else {
316− span.style.display = 'block';
317− var e = render(narg);
318− span.innerHTML = '';
319− span.appendChild(e);
320− }
321− } else {
322− span.style.display = 'inline';
323− span.innerHTML = narg;
324− }
325− }
326− break;
327− case "Image":
328− if (nextE._0.ctor === 'Plain') {
329− if (nextE._3 !== currE._3) node.src = nextE._3;
330− } else if (!eq(nextE,currE) ||
331− next.props.width !== curr.props.width ||
332− next.props.height !== curr.props.height) {
333− node.parentNode.replaceChild(render(next),node);
334− return true;
335− }
336− break;
337− case "Flow":
338− var arr = fromList(nextE._1);
339− for (var i = arr.length; i--; ) { arr[i] = arr[i].element.ctor; }
340− if (nextE._0.ctor !== currE._0.ctor) {
341− node.parentNode.replaceChild(render(next),node);
342− return true;
343− }
344− var nexts = fromList(nextE._1);
345− var kids = node.childNodes;
346− if (nexts.length !== kids.length) {
347− node.parentNode.replaceChild(render(next),node);
348− return true;
349− }
350− var currs = fromList(currE._1);
351− var dir = nextE._0.ctor;
352− var goDir = directionTable[dir];
353− var toReverse = needsReversal(dir);
354− var len = kids.length;
355− for (var i = len; i-- ;) {
356− update(kids[toReverse ? len - i - 1 : i],currs[i],nexts[i]);
357− goDir(kids[i]);
358− }
359− break;
360− case "Container":
361− update(node.firstChild, currE._1, nextE._1);
362− setPos(nextE._0, nextE._1, node.firstChild);
363− break;
364− case "Custom":
365− if (currE.type === nextE.type) {
366− var done = nextE.update(node, currE.model, nextE.model);
367− if (done) return;
368− } else {
369− return node.parentNode.replaceChild(render(next), node);
370− }
371− }
372− updateProps(node, curr, next);
373−}
374−
375−function updateProps(node, curr, next) {
376− var nextProps = next.props;
377− var currProps = curr.props;
378−
379− var element = next.element;
380− var width = nextProps.width - (element.adjustWidth || 0);
381− var height = nextProps.height - (element.adjustHeight || 0);
382− if (width !== currProps.width) {
383− node.style.width = (width|0) + 'px';
384− }
385− if (height !== currProps.height) {
386− node.style.height = (height|0) + 'px';
387− }
388−
389− if (nextProps.opacity !== currProps.opacity) {
390− node.style.opacity = nextProps.opacity;
391− }
392−
393− var nextColor = nextProps.color.ctor === 'Just'
394− ? colorToCss(nextProps.color._0)
395− : '';
396− if (node.style.backgroundColor !== nextColor) {
397− node.style.backgroundColor = nextColor;
398− }
399−
400− if (nextProps.tag !== currProps.tag) {
401− node.id = nextProps.tag;
402− }
403−
404− if (nextProps.href !== currProps.href) {
405− if (currProps.href === '') {
406− // add a surrounding href
407− var anchor = newElement('a');
408− anchor.href = nextProps.href;
409− anchor.style.display = 'block';
410− anchor.style.pointerEvents = 'auto';
411−
412− node.parentNode.replaceChild(anchor, node);
413− anchor.appendChild(node);
414− } else if (nextProps.href === '') {
415− // remove the surrounding href
416− var anchor = node.parentNode;
417− anchor.parentNode.replaceChild(node, anchor);
418− } else {
419− // just update the link
420− node.parentNode.href = nextProps.href;
421− }
422− }
423−
424− // update click and hover handlers
425− var removed = false;
426−
427− // update hover handlers
428− if (currProps.hover.ctor === '_Tuple0') {
429− if (nextProps.hover.ctor !== '_Tuple0') {
430− addHover(node, nextProps.hover);
431− }
432− }
433− else {
434− if (nextProps.hover.ctor === '_Tuple0') {
435− removed = true;
436− removeHover(node);
437− }
438− else {
439− node.elm_hover_handler = nextProps.hover;
440− }
441− }
442−
443− // update click handlers
444− if (currProps.click.ctor === '_Tuple0') {
445− if (nextProps.click.ctor !== '_Tuple0') {
446− addClick(node, nextProps.click);
447− }
448− }
449− else {
450− if (nextProps.click.ctor === '_Tuple0') {
451− removed = true;
452− removeClick(node);
453− } else {
454− node.elm_click_handler = nextProps.click;
455− }
456− }
457−
458− // stop capturing clicks if
459− if (removed
460− && nextProps.hover.ctor === '_Tuple0'
461− && nextProps.click.ctor === '_Tuple0')
462− {
463− node.style.pointerEvents = 'none';
464− }
465−}
466−
467−return { render:render, update:update };
468−
469−};
runtime/Render/Utils.jsdeleted−40
@@ -1,40 +0,0 @@
1−ElmRuntime.Render.Utils = function() {
2− function newElement(elementType) {
3− var e = document.createElement(elementType);
4− e.style.padding = "0";
5− e.style.margin = "0";
6− return e;
7− }
8−
9− function addTo(container, elem) {
10− container.appendChild(elem);
11− }
12−
13− function addTransform(style, trans) {
14− style.transform = trans;
15− style.msTransform = trans;
16− style.MozTransform = trans;
17− style.webkitTransform = trans;
18− style.OTransform = trans;
19− }
20−
21− function removeTransform(style) {
22− style.transform = 'none';
23− style.msTransform = 'none';
24− style.MozTransform = 'none';
25− style.webkitTransform = 'none';
26− style.OTransform = 'none';
27− }
28−
29− var List = Elm.Native.List.make({});
30−
31− return {addTo:addTo,
32− newElement: newElement,
33− colorToCss: Elm.Native.Color.make({}).toCss,
34− fromList: List.toArray,
35− fromString: function(s) { return s; },
36− toString: function(s) { return s; },
37− eq: Elm.Native.Utils.make({}).eq,
38− addTransform: addTransform,
39− removeTransform: removeTransform};
40−};