text: var $ML=function(t){return t._StripElem=function(t,i,s,e){this.length=t,this.width=i,this.value_delta=s,this.base_point=e,this.value_index=0,this.value_rem=0,this.group=null,this.text=null},t._StripElem.prototype={set_index:function(t,i){void 0!==i&&(t-=i/this.length*this.value_delta);var s=t/this.value_delta;this.value_index=Math.floor(s),this.value_rem=t-this.value_index*this.value_delta,this.length_shift=-this.value_rem*this.length/this.value_delta},conv:function(t){for(var i=new Array(t.length),s=0;s<t.length;s+=2)i[s]=t[s],i[s+1]=-t[s+1];return i},draw:function(t){this.group=new Konva.Group;var i=this.conv([0,5]);this.text=new Konva.Text({x:i[0],y:i[1],text:"999",fontSize:14,fontFamily:"monospace",fill:"black",align:"left"}),this.group.add(this.text);var s=new Konva.Line({points:this.conv([0,0,this.width,0,this.width,this.length]),stroke:"red"});this.group.add(s),t.add(this.group)},update_text:function(){this.text&&this.text.setText(sprintf("%f",this.value_index*this.value_delta))},move_to_pos:function(t){void 0===t&&(t=0);var i=this.value_rem*this.length/this.value_delta,s=this.conv([0,i]);this.group.setX(this.base_point[0]+s[0]),this.group.setY(this.base_point[1]+s[1])}},t.TapeMeter=function(t){t=this._register(t,"TapeMeter",["value"],[])},t.TapeMeter.prototype=t._block_xtend({_init:function(i){this.group=new Konva.Group,this.max=t.getOpts(i,"max",100)},setval:function(t){},addToLayer:function(t){this.layer=t,t.add(this.group)}}),t}(($ML=function(t){return t.ImageSwitch=function(t){this._register(t,"ImageSwitch",[],["value"])},t.ImageSwitch.prototype=t._block_xtend({_init:function(i){this.img=[],this.img[0]=t.getOpts(i,"img_false",null),this.img[1]=t.getOpts(i,"img_true",null),this.value=t.getOpts(i,"value",!1),this.group=new Konva.Group,this.callback=t.getOpts(i,"callback",null),this.sw_groups=[];var s=this,e={visible_only:this.value?1:0,callback:function(t){for(var i=0;i<2;i++){var e=t.getKImage(i);e.on("click",(function(t){s._do_switch(t)})),e.setName(sprintf("%d",i))}},layer:this.group};this.loader=new t.ImageLoader(this.img,{x:0,y:0},e)},_setval:function(t){t?(this.loader.show_only(1),this.value=!0):(this.loader.show_only(0),this.value=!1),this.layer.draw()},setval:function(t,i){this._setval(t);for(var s=0;s<this.sw_groups.length;s++)void 0!==i&&i==this.sw_groups[s]||this.sw_groups[s].signal(this)},_do_switch:function(t){var i=t.target;this.setval("0"==i.name()),this.callback&&this.callback(this.value,this)},getval:function(){return this.value}}),t.SwitchGroup=function(i,s){this.exclusive=t.getOpts(i,"exclusive",!0),this.sw_list=[],void 0===s&&(s=[]);for(var e=0;e<s.length;e++)this.add(s[e])},t.SwitchGroup.prototype={add:function(t){t.sw_groups.push(this),this.sw_list.push(t)},signal:function(t){for(var i=t.getval(),s=0;s<this.sw_list.length;s++)this.sw_list[s]!=t&&(this.exclusive?this.sw_list[s].setval(!1,this):this.sw_list[s].setval(i,this))}},t}(($ML=function(t){return t.Slider=function(t){this._register(t,"Slider",[],["value"])},t.Slider.prototype=t._block_xtend({_init:function(i){this.group=new Konva.Group,this.min=t.getOpts(i,"min",0),this.max=t.getOpts(i,"max",100),this.n=t.getOpts(i,"n",11),this.log=t.getOpts(i,"log",!1),this.color=t.getOpts(i,"color","#808080"),this.width=t.getOpts(i,"width",100),this.height=t.getOpts(i,"height",15),this.slow_callback=t.getOpts(i,"slow_callback",null),this.fast_callback=t.getOpts(i,"fast_callback",null),this.bw=2*this.height,this.dx=(this.width-this.bw)/(1*(this.n-1));var s=this;if(this.log?(this._index2val=function(t){return s.min*Math.pow(s.max/s.min,t/(s.n-1))},this._val2index=function(t){return Math.round((s.n-1)*Math.log(t/s.min)/Math.log(s.max/s.min))}):(this._index2val=function(t){return s.min+t/(s.n-1)*(s.max-s.min)},this._val2index=function(t){return Math.round((s.n-1)*(t-s.min)/(s.max-s.min))}),this.base=new Konva.Rect({x:0,y:0,width:this.width,height:this.height,fill:"#F0F0F0",stroke:"black"}),this.cursor=new Konva.Rect({x:0,y:0,width:this.bw,height:this.height,cornerRadius:this.height/2,fill:this.color,stroke:"black",draggable:!0,dragBoundFunc:function(t){var i=s._get_relative_cursor_position(t),e=Math.round(i.x/(1*s.dx));e>=s.n&&(e=s.n-1),e<0&&(e=0),s.value=s._index2val(e);var o=s.dx*e;return s.text&&s.text.setText(sprintf(s.format,parseFloat(s.value))),s.fast_callback&&s.fast_callback(s.value,s),s._set_relative_cursor_position({x:o,y:0})}}),this.slow_callback&&this.cursor.on("dragend",(function(t){s.slow_callback(s.value,s)})),this.group.add(this.base),this.group.add(this.cursor),"value"in i)var e=this._setval(i.value);else e=this._setval(this.min);this.cursor.setPosition({x:e,y:0}),"format"in i&&(this.format=i.format,this.text=new Konva.Text({x:0,y:-this.height,text:sprintf(this.format,parseFloat(this.value)),fontSize:14,fontFamily:"Monospace",fill:this.color,align:"left"}),this.group.add(this.text),this.text.setY(-this.text.getTextHeight()))},_get_relative_cursor_position:function(t){void 0===t&&(t=this.cursor.getAbsolutePosition());var i=this.group.getAbsolutePosition();return{x:t.x-i.x,y:t.y-i.y}},_set_relative_cursor_position:function(t){var i=this.group.getAbsolutePosition();return{x:t.x+i.x,y:t.y+i.y}},_setval:function(t){return t<this.min&&(t=this.min),t>this.max&&(t=this.max),this.value=t,this._val2index(t)*this.dx},setval:function(t){var i=this._setval(t),s=this._set_relative_cursor_position({x:i,y:0});this.cursor.setAbsolutePosition(s)},getval:function(){return this.value}}),t.VSlider=function(t){this._register(t,"VSlider",[],["value"])},t.VSlider.prototype=t._xtend(t.Slider.prototype,{_init:function(i){t.Slider.prototype._init.call(this,i),this.group.rotate(-90)},_get_relative_cursor_position:function(t){void 0===t&&(t=this.cursor.getPosition());var i=this.group.getPosition();return{x:-(t.y-i.y),y:t.x-i.x}},_set_relative_cursor_position:function(t){var i=this.group.getPosition();return{x:t.y+i.x,y:-t.x+i.y}}}),t}(($ML=function(t){return t.Polyline=function(t){t=this._register(t,"Polyline",["value"],[])},t.Polyline.prototype=t._block_xtend({_init:function(i){this.stroke=t.getOpts(i,"stroke","black"),this.color=t.getOpts(i,"color","orange"),this.size=t.getOpts(i,"size",6),this.strokeWidth=t.getOpts(i,"strokeWidth",1),this.max_speed=t.getOpts(i,"max_speed",6),this.max=t.getOpts(i,"max",100),this.min=t.getOpts(i,"min",-100),this.reverse=t.getOpts(i,"reverse",!1),this.dot_space=t.getOpts(i,"dot_space",20),this.points=t.getOpts(i,"points",[]),this.group=new Konva.Group,this.offset=0,this.speed=0,this.segments=[],this.total_length=0,this.Kline=new Konva.Line({points:this.points,x:this.x,y:this.y,stroke:this.stroke}),this.group.add(this.Kline);for(var s=0;s<this.points.length-2;s+=2){var e=this.points[s],o=this.points[s+1],n=this.points[s+2],h=this.points[s+3],a=Math.sqrt((n-e)*(n-e)+(h-o)*(h-o)),r=(n-e)/a,l=(h-o)/a;this.total_length+=a,this.segments.push({length:a,point_indexes:[],vect:{x:r,y:l},coord:[e,o,n,h]})}this.dots=[],this._init_dots()},_get_line_index:function(t){var i,s=t;for(i=0;i<this.segments.length;i++){var e=s;if((s-=this.segments[i].length)<0){var o=this.segments[i];return{i:i,remaining:e,point:{x:o.coord[0]+o.vect.x*e,y:o.coord[1]+o.vect.y*e}}}}return{i:null,remaining:s,point:null}},_init_dots:function(){for(var t=Math.floor(this.total_length/this.dot_space)+1,i=0;i<t;i++){var s=i*this.dot_space,e=this._get_line_index(s),o=e.point,n=new Konva.Circle({x:o.x,y:o.y,radius:this.size/2,fill:this.color}),h=this.segments[e.i];this.dots.push({p:o,obj:n,base_dist:s,seg_index:e.i,to_seg_end:h.length-e.remaining}),h.point_indexes.push(this.dots.length-1),this.group.add(n)}},move_dots_old:function(t){Math.floor(this.total_length/this.dot_space);for(var i=0;i<this.dots.length;i++){var s=this.dots[i],e=this.getPointOnLine(s.base_dist+t);null!==e?(s.obj.setX(e.x),s.obj.setY(e.y),s.obj.show()):s.obj.hide()}},move_dots:function(t){Math.floor(this.total_length/this.dot_space);for(var i=0;i<this.dots.length;i++){var s=this.dots[i];if(t<=s.to_seg_end)var e=this.segments[s.seg_index],o=s.p.x,n=s.p.y;else if(s.seg_index+1<this.segments.length)o=(e=this.segments[s.seg_index+1]).coord[0]-e.vect.x*s.to_seg_end,n=e.coord[1]-e.vect.y*s.to_seg_end;else e=null,o=null,n=null;if(null!==o){var h=o+e.vect.x*t,a=n+e.vect.y*t;s.obj.setX(h),s.obj.setY(a),s.obj.show()}else s.obj.hide()}},getPointOnLine:function(t){var i=this._get_line_index(t);if(null===i.i)return null;this.segments[i.i].coord;return i.point},setval:function(t){t<this.min&&(t=this.min),t>this.max&&(t=this.max),this.reverse&&(t=-t),this.speed=t*this.max_speed/this.max,this._set_pos(0)},_set_pos:function(t){this.offset+=this.speed*this.dot_space*t/1e3,this.offset>this.dot_space&&(this.offset=0),this.offset<0&&(this.offset=this.dot_space),this.move_dots(this.offset)},addToLayer:function(t){this.layer=t;var i=this;this.anim=new Konva.Animation((function(t){i._set_pos(t.timeDiff)}),t),t.add(this.group),this.anim.start()}}),t}(($ML=function(t){return t.FlowMeter=function(t){t=this._register(t,"FlowMeter",["value"],[])},t.FlowMeter.prototype=t._block_xtend({_init:function(i){this.group=new Konva.Group,this.max=t.getOpts(i,"max",100),this.color=t.getOpts(i,"color","yellow"),this.reverse=t.getOpts(i,"reverse",!1);var s=t.getOpts(i,"height",15),e=t.getOpts(i,"height",100);this.wa=Math.round(e/3),this.ha=Math.round(s/2);var o={fill:"white",stroke:"black",strokeWidth:1,x:0,y:0,width:e,height:s},n=0,h=0;if("format"in i){this.format=i.format;n=2,h=2;this.bigbox=new Konva.Rect({x:0,y:0,width:e+4,height:2*s+6,fill:"white",stroke:"black",strokeWidth:1}),this.group.add(this.bigbox),this.text=new Konva.Text({x:2,y:s+4,text:"0123456",fontSize:12,fontFamily:"Monospace",fill:this.color,align:"left"}),this.group.add(this.text),this.bigbox.setHeight(this.text.getTextHeight()+s+6)}this.box=new Konva.Rect(o),this.group.add(this.box),this.box.setPosition({x:n,y:h}),this.arrows=[];var a=new Konva.Group;a.setClip({x:0,y:0,width:e,height:s});for(var r=0;r<3;r++){var l=new Konva.Line({fill:this.color,stroke:this.color,closed:!0});l.move(n,h),this.arrows.push(l),a.add(l)}this.group.add(a),a.setPosition({x:n,y:h}),this.offset=0,this.setval(0)},_set_arrows:function(t){this.offset=this.offset+this.speed*t,this.offset>1&&(this.offset=0),this.offset<0&&(this.offset=1);for(var i=this.arrows.length,s=0;s<i;s++){var e=this.wa*(s+this.offset);this.arrows[s].setPoints([e,0,e+this.ep,this.ha,e,2*this.ha])}},setval:function(t){this.text&&this.text.setText(sprintf(this.format,parseFloat(t))),t<-this.max&&(t=-this.max),t>this.max&&(t=this.max),this.reverse&&(t=-t),this.ep=Math.round(2*this.ha*t/this.max),this.speed=3*t/(1e3*this.max),this._set_arrows(0)},addToLayer:function(t){this.layer=t;var i=this;this.anim=new Konva.Animation((function(t){i._set_arrows(t.timeDiff)}),t),t.add(this.group),this.anim.start()}}),t.DigitalMeter=function(t){t=this._register(t,"DigitalMeter",["value"],[]),this.setval(this.value)},t.DigitalMeter.prototype=t._block_xtend({_init:function(i){if(i=i||{},this.value=t.getOpts(i,"value",0),this.width=t.getOpts(i,"width",80),this.adapt_width_for=t.getOpts(i,"adapt_width_for",null),this.height=t.getOpts(i,"height",15),this.format=t.getOpts(i,"format","%3.0f"),this.scale=t.getOpts(i,"scale",1),this.color=t.getOpts(i,"color","black"),this.fill=t.getOpts(i,"fill",null),this.stroke=t.getOpts(i,"stroke",null),this.base=null,this.group=new Konva.Group,this.text=new Konva.Text({x:2,y:2,text:"999",fontSize:14*this.scale,fontFamily:"monospace",fill:this.color,align:"left"}),null!==this.adapt_width_for){this.text.setText(sprintf(this.format,this.adapt_width_for));var s=this.text.getTextWidth(),e=this.text.getTextHeight()}else s=this.width*this.scale,e=this.height*this.scale;if(this.fill||this.stroke){var o={x:0,y:0,width:s,height:e};this.fill&&(o.fill=this.fill),this.stroke&&(o.stroke=this.stroke),this.base=new Konva.Rect(o),this.group.add(this.base)}this.group.add(this.text)},setval:function(t){this.text.setText(sprintf(this.format,t)),this.layer.draw()},setfill:function(t){this.base&&this.base.fill(t)},setcolor:function(t){this.text.fill(t)}}),t.AnalogMeter=function(t){t=this._register(t,"AnalogMeter",["value"],[]),this.setval(this.value)},t.AnalogMeter.prototype=t._block_xtend({_init:function(i){i=i||{},this.min=t.getOpts(i,"min",0),this.max=t.getOpts(i,"max",0),this.value=t.getOpts(i,"value",this.min),this.unit=t.getOpts(i,"unit",""),this.format=t.getOpts(i,"format","%3.0f"),this.scale=t.getOpts(i,"scale",1),this.color=t.getOpts(i,"color","lightblue"),this.text_color=t.getOpts(i,"text_color","#555"),this._redLine=new Konva.Line({points:[0,0,-20*this.scale,0],y:-2,stroke:"red",strokeWidth:2,lineCap:"round",lineJoin:"round"}),this._path=new Konva.Path({data:"M 14,-2484 C -1216,-2484 -2155,-1545 -2155,-315 -2155,-207 -2148,-101 -2133,2 L -1483,2 C -1435,-799 -803,-1399 14,-1399 831,-1399 1463,-799 1511,2 L 2162,2 C 2177,-101 2184,-207 2184,-315 2184,-1545 1244,-2484 14,-2484 Z M 14,-2800 C 1423,-2800 2500,-1724 2500,-315 2500,1094 1423,2171 14,2171 -1395,2171 -2471,1094 -2471,-315 -2471,-1724 -1395,-2800 14,-2800 Z",fill:this.color,scale:{x:.01*this.scale,y:.01*this.scale}}),this._back_path=new Konva.Path({data:"M 0,-2700 C 1361,-2700 2400,-1704 2400,-400 2400,904 1361,1900 0,1900 -1361,1900 -2400,904 -2400,-400 -2400,-1704 -1361,-2700 0,-2700 Z M -2400,-2700 L -2400,-2700 Z M 2401,1901 L 2401,1901 Z",fill:"white",scale:{x:.01*this.scale,y:.01*this.scale}}),this._unite=new Konva.Text({x:0,y:0,text:this.unit,fontSize:12*this.scale,fontFamily:"Monospace",fill:this.text_color,align:"center"}),this._unite.setX(-this._unite.getTextWidth()/2),this._unite.setY(-this._unite.getTextHeight()),this.group=new Konva.Group,this.group.add(this._back_path),this.group.add(this._redLine),this.group.add(this._path),this.group.add(this._unite),this.format&&(this._valeur=new Konva.Text({x:0,y:2*this.scale,text:"999",fontSize:12*this.scale,fontFamily:"Monospace",fill:this.text_color,align:"right"}),this._valeur.setX(-this._valeur.getTextWidth()/2),this.group.add(this._valeur))},setval:function(t){this.format&&(this._valeur.setText(sprintf(this.format,t)),this._valeur.setX(-this._valeur.getTextWidth()/2)),t<this.min&&(t=this.min),t>this.max&&(t=this.max);var i=0+180*(t-this.min)/(this.max-this.min);i=Math.PI*i/180;var s=20*-Math.cos(i)*this.scale,e=20*-Math.sin(i)*this.scale;this._redLine.setPoints([0,0,s,e]),this.layer.draw()}}),t}(($ML=function(t){return t.ImageLoader=function(t,i,s){this.URLs=t,this.img_opt=i||{},this._init(s)},t.ImageLoader.prototype={_init:function(i){this.img_opt.x=t.getOpts(this.img_opt,"x",0),this.img_opt.y=t.getOpts(this.img_opt,"y",0),this.config=i||{},"layer"in this.config?this.addToLayer(this.config.layer):t.default_layer?this.addToLayer(t.default_layer):this.layer=null,this.callback=t.getOpts(this.config,"callback",null),this.visible_only=t.getOpts(this.config,"visible_only",-1),this.partial=t.getOpts(this.config,"partial",!1),this.zindex=t.getOpts(this.config,"zindex",null),this.dx=t.getOpts(this.config,"dx",0),this.dy=t.getOpts(this.config,"dy",0),this.image_properties=[],this.length=this.URLs.length,this.loaded=0,this.load_complete=!1;for(var s=0;s<this.length;s++){var e=new Image;if(this.URLs[s].constructor==Array)var o=(n=this.URLs[s])[0];else{var n=[];o=this.URLs[s]}this.image_properties[s]={img:e,src:o,loaded:!1,KImage:null,prop:n},e.src=o,e.index=s,e.context=this,e.onload=this._image_loaded}},_image_loaded:function(){var t=this.index,i=this.context;i.image_properties[t].loaded=!0,i.loaded++,i.loaded==i.length&&(i.load_complete=!0,i.partial||i.createKImages(i.layer,i.zindex),i.callback&&i.callback(i))},createKImages:function(i,s){for(var e=0;e<this.length;e++){var o=this.image_properties[e],n=t.clone(this.img_opt);n.image=o.img,void 0!==o.prop[1]&&(n.x=o.prop[1]),void 0!==o.prop[2]&&(n.y=o.prop[2]),void 0!==o.prop[3]&&null!=o.prop[3]&&(s=o.prop[3]),this.dx&&(n.x+=e*this.dx),this.dy&&(n.y+=e*this.dy);var a=new Konva.Image(n);if(this.visible_only>=0&&(this.visible_only==e?a.show():a.hide()),void 0!==o.prop[4]){var r=o.prop[4];w=a.width(),h=a.height();var l=r.indexOf("r")>=0,g=r.indexOf("c")>=0;l&&(a.offsetX(w/2),a.offsetY(h/2)),l&&!g&&(a.x(a.x()+w/2),a.y(a.y()+h/2)),g&&!l&&(a.x(a.x()-w/2),a.y(a.y()-h/2)),r.indexOf("d")>=0&&a.draggable(!0),r.indexOf("h")>=0&&a.hide()}this.image_properties[e].KImage=a,i&&(i.add(a),"string"==typeof s&&"top"==s?a.moveToTop():"string"==typeof s&&"bottom"==s?a.moveToBottom():"number"==typeof s&&a.setZIndex(s))}i&&i.draw()},getImage:function(t){return t>=0&&t<this.length&&this.load_complete?this.image_properties[t].img:null},getKImage:function(t){return t>=0&&t<this.length&&this.load_complete?this.image_properties[t].KImage:null},show_only:function(t){this.visible_only=t;for(var i=0;i<this.length;i++)i==t?this.getKImage(i).show():this.getKImage(i).hide()},show_all:function(){this.visible_only=-1;for(var t=0;t<this.length;t++)this.getImage(i).show()},is_only_visible:function(t){return!(this.visible_only<0)&&this.getImage(t).isVisible()},addToLayer:function(t){this.layer=t},dump:function(){for(var t=0;t<this.length;t++){var i=this.getKImage(t),s=i.getImage().src,e=i.getX(),o=i.getY(),n=i.getZIndex(),h=this.image_properties[t].prop[4],a="['"+s+"', "+e+", "+o+", "+n;void 0!==h&&(a+=", '"+h+"'"),a+="], // index : "+t,console.log(a)}}},t.SpinningImage=function(t){this._register(t,"SpinningImage",["value"],[])},t.SpinningImage.prototype=t._block_xtend({_init:function(i){this.img=[],this.img[0]=t.getOpts(i,"img",null),this.objs=t.getOpts(i,"objs",null),this.max_speed=t.getOpts(i,"max_speed",1),this.max=t.getOpts(i,"max",100),this.min=t.getOpts(i,"min",0),this.reverse=t.getOpts(i,"reverse",!1);var s=t.getOpts(i,"layer",null);this.initial_value=t.getOpts(i,"value",0);var e=this;this.group=new Konva.Group({dragBoundFunc:function(t){return e.enable_man_rotate?this.getAbsolutePosition():t}}),this.angle=0,this.setval(this.initial_value);var o=function(){for(var t=0;e.objs&&t<e.objs.length;t++)e.group.add(e.objs[t]);var i=e.group.getClientRect(),o=i.width,n=i.height;e.group.offsetX(o/2),e.group.offsetY(n/2),s&&e.addToLayer(s)};if(this.img[0]){var n={callback:function(t){var i=t.getKImage(0);e.group.add(i),o()}};this.loader=new t.ImageLoader(this.img,{},n)}else o();this.enable_man_rotate=t.getOpts(i,"man_rotate",!1),this.group.on("dragstart",(function(t){e.enable_man_rotate&&(e.init_angle=e._pointer_angle(e.group,e.group)-e.angle)})),this.group.on("dragmove",(function(t){if(e.enable_man_rotate){var i=e._pointer_angle(e.group,e.group);e.set_angle(i-e.init_angle),e.layer.draw()}}))},_pointer_angle:function(t,i){var s=t.getStage().getPointerPosition(),e=i.getX()-s.x,o=i.getY()-s.y;return 180*Math.atan2(o,e)/Math.PI},setval:function(t){var i;t<this.min&&(t=this.min),t>this.max&&(t=this.max),i=this.reverse?-t:+t,this.speed=i*this.max_speed/(1*this.max),this._set_rotation(0)},set_angle:function(t){this.angle=t,this.angle>360&&(this.angle-=360),this.angle<0&&(this.angle+=360),this.group.setRotation(this.angle)},add_angle:function(t){this.set_angle(this.angle+t)},_set_rotation:function(t){this.set_angle(this.angle+360*this.speed*t/1e3)},dragBoundFunc:function(t){return this.enable_man_rotate?this.group.getAbsolutePosition():t},start:function(){this.anim.start()},stop:function(){this.anim.stop()},addToLayer:function(t){this.layer=t;var i=this;this.anim=new Konva.Animation((function(t){i.enable_man_rotate||i._set_rotation(t.timeDiff)}),t),t.add(this.group),this.anim.start()},man_rotate:function(t){this.enable_man_rotate=t,t&&this.group.draggable(!0)},draggable:function(t){this.group.draggable(t),t&&(this.enable_man_rotate=!1)},get_angle:function(){return this.angle}}),t}(($ML=function(t){function i(t){for(;t>180;)t-=360;for(;t<=-180;)t+=360;return t}return t.Arrow=function(t){this._register(t,"Arrow",[],[])},t.Arrow.prototype=t._block_xtend({_init:function(i){this.group=new Konva.Group,this.line=null,this.head=null,this.color=i.color||"black",this.size=i.size||5,this.scale=i.scale||1;var s=t.getOpts(i,"x0",0),e=t.getOpts(i,"y0",0),o=t.getOpts(i,"x1",s),n=t.getOpts(i,"y1",e);this.angle=0,this.is_not_visible=!1,this.line=new Konva.Line({points:[s,e,o,n],strokeWidth:i.strokeWidth||1,stroke:this.color});var h=this.size;this.head=new Konva.Line({points:[-2*h,0,-3*h,-h,0,0,-3*h,h],fill:this.color,stroke:this.color,closed:!0}),this.group.add(this.line),this.group.add(this.head),this.setPoints(s,e,o,n)},reverseY:!0,setPoints:function(t,i,s,e){if(this.x0=t,this.y0=i,this.x1=s,this.y1=e,t*=this.scale,i*=this.scale,s*=this.scale,e*=this.scale,this.reverseY&&(i=-i,e=-e),this.is_not_visible=this.get_length()*this.scale<1,this.is_not_visible||this.hidden)this.group.hide();else{this.group.show(),this.line.setPoints([t,i,s,e]),this.head.setX(s),this.head.setY(e);var o=this.get_angle();this.angle=o,this.reverseY&&(o=-o),this.head.setRotation(o)}},set_origin:function(t,i){this.setPoints(t,i,this.x1,this.y1)},set_destination:function(t,i){this.setPoints(this.x0,this.y0,t,i)},translate_to:function(t){if(void 0!==t.block_class&&"Arrow"==t.block_class)var i=t.x1,s=t.y1;else i=t.x,s=t.y;var e=this.x1-this.x0,o=this.y1-this.y0;this.setPoints(i,s,i+e,s+o)},get_angle:function(){var t=this.x1-this.x0,i=this.y1-this.y0;if(this.is_not_visible||isNaN(t)||isNaN(i))s=this.angle;else{var s=180/Math.PI*Math.atan2(i,t);this.angle=s}return s},get_length:function(){var t=this.x1-this.x0,i=this.y1-this.y0;return Math.sqrt(t*t+i*i)},set_angle:function(t){this.angle=i(t),t*=Math.PI/180;var s=this.get_length(),e=this.x0+s*Math.cos(t),o=this.y0+s*Math.sin(t);this.setPoints(this.x0,this.y0,e,o)},set_length:function(t){var i=this.get_angle()*(Math.PI/180),s=this.x0+t*Math.cos(i),e=this.y0+t*Math.sin(i);this.setPoints(this.x0,this.y0,s,e)}}),t.ArcArrow=function(t){this._register(t,"ArcArrow",[],[])},t.ArcArrow.prototype=t._block_xtend({_init:function(i){this.color=t.getOpts(i,"color","grey"),this.size=t.getOpts(i,"size",2),this.scale=t.getOpts(i,"scale",1),this.fontsize=t.getOpts(i,"fontsize",12),this.visible=i.visible||!0,this.show_angle=i.show_angle||!0,this.group=new Konva.Group,this.arc=new Konva.Arc({stroke:this.color,fill:this.color});var s=this.size;this.head=new Konva.Line({points:[-2*s,0,-3*s,-s,0,0,-3*s,s],fill:this.color,stroke:this.color,closed:!0}),this.label=new Konva.Label,this.text=new Konva.Text({fontFamily:"Monospace",fontSize:this.fontsize,fill:"black"}),this.group.add(this.arc),this.group.add(this.head),this.label.add(this.text),this.group.add(this.label),this.x0=t.getOpts(i,"x0",0),this.y0=t.getOpts(i,"y0",0),this.startAngle=t.getOpts(i,"startAngle",0),this.endAngle=t.getOpts(i,"endAngle",90),this.radius=t.getOpts(i,"radius",10),this.format=t.getOpts(i,"format","%+3.0f°"),this.calc(),"undefined"!=typeof layer&&layer.add(this.group)},reverseY:!0,setPoint:function(t,i){this.x0=t,this.y0=i,this.calc()},setAll:function(t,s,e,o,n){this.x0=t,this.y0=s,this.startAngle=i(e),this.endAngle=i(o),this.radius=n,this.calc()},setAngles:function(t,s){this.startAngle=i(t),this.endAngle=i(s),this.calc()},setRadius:function(t){this.radius=t,this.calc()},setAngleFromPoint:function(t,i,s){var e=180/Math.PI*Math.atan2(i-this.y0,t-this.x0);void 0===s||1==s?this.endAngle=e:this.startAngle=e,this.calc()},calc:function(){var t=this.radius*this.scale,i=this.x0*this.scale,s=this.y0*this.scale,e=this.startAngle,o=this.endAngle;this.reverseY&&(e=-e,o=-o,s=-s);var n=i+t*Math.cos(Math.PI/180*o),h=s+t*Math.sin(Math.PI/180*o),a=this.visible;if((Math.abs(o-e)<8||isNaN(e)||isNaN(o))&&(a=!1),Math.sin(Math.PI/180*(o-e))>0)var r=o-e,l=e,g=90;else r=e-o,l=o,g=-90;var c=(e+o)/2,u=i+(t+10)*Math.cos(Math.PI/180*c),d=s+(t+10)*Math.sin(Math.PI/180*c);this.arc.setAttrs({innerRadius:t,outerRadius:t,angle:r,rotation:l}),this.head.setX(n),this.head.setY(h),this.head.setRotation(o+g),this.arc.setX(i),this.arc.setY(s),this.arc.visible(a),this.head.visible(a),this.label.setX(u),this.label.setY(d),this.label.visible(this.show_angle&&a);var p=o-e;this.reverseY&&(p=-p),this.text.text(sprintf(this.format,p))}}),t}(($ML=function(t){return t.default_layer=0,t.set_default_layer=function(i){t.default_layer=i},t.getOpts=function(t,i,s){return void 0===t||void 0===t[i]?s:t[i]},t.clone=function(i){if(null==i||"object"!=typeof i)return i;var s=i.constructor();for(var e in i)i.hasOwnProperty(e)&&(s[e]=t.clone(i[e]));return s},t.xinspect=function(t,i,s){if(void 0===i&&(i=3),void 0===s&&(s=0),s>i)return"[MAX RECURSION LEVEL]";var e=Array(s).join("  "),o="";for(var n in t){var h=typeof t[n];o=o+(e+'"')+n+'" ('+h+") => "+("object"==h?"object:"+xinspect(t[n],i,s+1):t[n])+"\n"}return o},t._block=function(t){},t.block_list=[],t.block_dict={},t._block.prototype={_register:function(i,s,e,o){return void 0===i&&(i={}),this.config=i,void 0===e&&(e=[]),void 0===o&&(o=[]),this.inputs=e,this.outputs=o,this.block_class=s,this.hidden=!1,this._init(i),this._postinit(),self=this,t.block_list.push(self),t.block_dict[s+"."+self.name]=self,i},addToLayer:function(t){this.layer=t,t.add(this.group)},setPosition:function(t){this.group.setPosition(t)},rotateDeg:function(t){this.group.rotateDeg(t)},draggable:function(t){this.group.draggable(t)},visible:function(t){t?(this.hidden=!1,this.group.show()):(this.hidden=!0,this.group.hide())},_postinit:function(){"x"in this.config&&"y"in this.config&&this.setPosition({x:this.config.x,y:this.config.y}),"layer"in this.config?this.config.layer&&this.addToLayer(this.config.layer):t.default_layer&&this.addToLayer(t.default_layer),"name"in this.config&&(this.name=this.config.name),"draggable"in this.config&&this.draggable(this.config.draggable)}},t._xtend=function(t,i){for(var s in proto_base=Object.create(t),i)proto_base[s]=i[s];return proto_base},t._block_xtend=function(i){return t._xtend(t._block.prototype,i)},t.iterate_blocks=function(i,s,e,o){for(var n=new RegExp(i),h=new RegExp(s),a=t.block_list.length,r=0;r<a;r++){var l=t.block_list[r];void 0!==l.block_class&&n.test(l.block_class)&&(void 0!==l.name&&h.test(l.name)&&e(l,o))}},t.draggable_all=function(i){for(var s=t.block_list.length,e=0;e<s;e++){t.block_list[e].draggable(i)}},t.toggle_draggable=function(i){var s=i.childNodes[0];"Do NOT drag"!=s.data?(s.data="Do NOT drag",t.draggable_all(!0)):(s.data="Drag",t.draggable_all(!1))},t.dump_blocks=function(){for(var i=t.block_list.length,s=0;s<i;s++){var e=t.block_list[s],o=e.block_class,n=e.name,h=e.group.getPosition(),a=h.x,r=h.y;console.log('{ block_class:"'+o+'", name:"'+n+'", x:'+a+", y:"+r+", },")}},t}($ML||{}))||{}))||{}))||{}))||{}))||{}))||{}))||{});