UNPKG

ayajs

Version:

A flexible JavaScript library for building any kind of diagrams quickly and in a programmatic way

15 lines 51.5 kB
var t,s;t=this,s=function(exports){class o{static store={};static add(t){o.store[t.uuid]=t}static find(t){return o.store[t]}static clear(t){delete o.store[t]}static findAllLink(s){var i=[];return Object.keys(o.store).map(t=>{t=o.find(t);"link"!=t.type||s.uuid!=t.source.ref&&s.uuid!=t.destination.ref||i.push(t)}),i}static findAllComponents(){var s=[];return Object.keys(o.store).map(t=>{t=o.find(t);"point"!=t.type&&"link"!=t.type&&s.push(t)}),s}}class v{static generate(){return Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}}class c{constructor(t,s=0,i=0,e=5,h){this.ref=t||null,this.uuid=v.generate(),this.x=s,this.y=i,this.r=e,this.scale=1,this.events={},this.config=h,this.type="point",this.c_svg="",this.svg=this.config.svg,o.add(this)}addEvent(t,s){this.c_svg.addEventListener(t,s),this.events[t]=s}deleteEvent(t){var s=this.events[t];this.c_svg.removeEventListener(t,s),delete this.events[t]}deleteAllEvents(){Object.keys(this.events).map(t=>{this.deleteEvent(t)})}setScale(t){this.scale=t}getScale(){return this.scale}setStyles(t){t.fill&&this.c_svg.setAttribute("fill",t.fill),t.stroke&&this.c_svg.setAttribute("stroke",t.stroke),t.strokewidth&&this.c_svg.setAttribute("stroke-width",t.strokewidth),t.fillopacity&&this.c_svg.setAttribute("fill-opacity",t.fillopacity),t.strokeopacity&&this.c_svg.setAttribute("stroke-opacity",t.strokeopacity),t.strokedasharray&&this.c_svg.setAttribute("stroke-dasharray",t.strokedasharray),t.strokedashoffset&&this.c_svg.setAttribute("stroke-dashoffset",t.strokedashoffset)}draw(){this.c_svg=document.createElementNS("http://www.w3.org/2000/svg","circle"),this.c_svg.setAttribute("id",this.uuid),this.c_svg.setAttribute("cx",this.x),this.c_svg.setAttribute("cy",this.y),this.c_svg.setAttribute("r",this.config.point.radius*this.scale),this.c_svg.setAttribute("class","hidden_point"),this.addEvent("mousedown",t=>{x.mousedowncb(t,this.config)}),this.addEvent("mouseover",t=>{this.r+=4,this.c_svg.setAttribute("r",this.r)}),this.addEvent("mouseleave",t=>{this.r=this.config.point.radius,this.c_svg.setAttribute("r",this.r)}),this.svg.appendChild(this.c_svg)}removeFromDOM(){this.svg.removeChild(this.c_svg)}shift(t,s){this.x+=t,this.y+=s}redraw(){this.c_svg.setAttribute("cx",this.x),this.c_svg.setAttribute("cy",this.y),this.c_svg.setAttribute("r",this.config.point.radius*this.scale)}}class t{constructor(t){this.uuid=t.uuid||v.generate(),this.c_svg="",this.config=t.config,this.svg=this.config.svg,this.events={},this.children=[],this.offsetX=0,this.offsetY=0,this.scaleX=1,this.scaleY=1,this.angle=0,this.centerX=0,this.centerY=0,this.c_points=[new c(this.uuid,0,0,5,this.config),new c(this.uuid,0,0,5,this.config),new c(this.uuid,0,0,5,this.config),new c(this.uuid,0,0,5,this.config)],this.vertex=[new c(this.uuid,0,0,5,this.config),new c(this.uuid,0,0,5,this.config),new c(this.uuid,0,0,5,this.config),new c(this.uuid,0,0,5,this.config)],t.isSave&&o.add(this)}addEvent(t,s){this.c_svg.addEventListener(t,s),this.events[t]=s}deleteEvent(t){var s=this.events[t];this.c_svg.removeEventListener(t,s),delete this.events[t]}deleteAllEvents(){Object.keys(this.events).map(t=>{this.deleteEvent(t)})}setStyles(t){t.fill&&this.c_svg.setAttribute("fill",t.fill),t.stroke&&this.c_svg.setAttribute("stroke",t.stroke),t.strokewidth&&this.c_svg.setAttribute("stroke-width",t.strokewidth),t.fillopacity&&this.c_svg.setAttribute("fill-opacity",t.fillopacity),t.strokeopacity&&this.c_svg.setAttribute("stroke-opacity",t.strokeopacity),t.strokedasharray&&this.c_svg.setAttribute("stroke-dasharray",t.strokedasharray),t.strokedashoffset&&this.c_svg.setAttribute("stroke-dashoffset",t.strokedashoffset)}makeHiddenCpoints(){this.c_points.map(t=>{t.c_svg.setAttribute("fill","none")})}makeVisibleCpoints(){this.c_points.map(t=>{t.c_svg.setAttribute("fill","black")})}makeHiddenVertex(){this.vertex.map(t=>{t.c_svg.setAttribute("fill","none")})}makeVisibleVertex(){this.vertex.map(t=>{t.c_svg.setAttribute("fill","black")})}removeChildren(){this.children.map(({child:t})=>{t.removeFromDOM()})}removeFromDOM(){this.c_points.map(t=>{t.removeFromDOM()}),this.vertex.map(t=>{t.removeFromDOM()}),this.children.map(({child:t})=>{t.removeFromDOM()}),this.svg.removeChild(this.c_svg)}move(t,s){this.shape.x+=t,this.shape.y+=s,this.redraw(),o.findAllLink(this).map(t=>{t.redraw()})}addChild(t,s=null,i=null,e=!0){t.vertex=[],t.c_points=[],null!=s&&(t.offsetX=s.x,t.offsetY=s.y),null!=i&&(t.centerX=i.x,t.centerY=i.y,t.angle=i.angle),1==e&&t.draw(),this.children.push({child:t})}remove(){this.removeFromDOM(),o.clear(this.uuid)}}class a extends t{constructor(t=0,s=0,i=t,e=s,h=!0,r=!0,n=void 0,o){super({uuid:n,isSave:r,config:o}),this.x=t,this.y=s,this.c1={x:this.x,y:this.y},this.c2={x:this.x,y:this.y},this.dest_x=i,this.dest_y=e,this.type="line",this.p=null,this.path_is_set=!1,this.vertex=[new c(this.uuid,0,0,3,o),new c(this.uuid,0,0,3,o)],this.c_points=[],h&&this.draw()}drawVertex(){0!=this.vertex.length&&(this.vertex[0].x=this.x+this.offsetX,this.vertex[0].y=this.y+this.offsetY,this.vertex[1].x=(this.dest_x+this.offsetX)*this.scaleX,this.vertex[1].y=(this.dest_y+this.offsetY)*this.scaleY)}drawConnector(){this.c_points.length}setPath(t=[{}]){this.path_is_set=!0,this.p="M "+this.x+","+this.y+" ",t.map(t=>{this.p+="L "+t.x+","+t.y+" "}),this.p+="L "+this.dest_x+","+this.dest_y}setPathCur(t=[{}]){var s=!(this.path_is_set=!0),i=1,e=1,h=1,r=1;this.p="M "+this.x+","+this.y+" ",(this.y<t[0].y&&this.dest_y<t[1].y||this.y>t[0].y&&this.dest_y>t[1].y)&&(h=-1),(this.x<t[0].x&&this.dest_x<t[1].x||this.x>t[0].x&&this.dest_x>t[1].x)&&(r=-1),this.x>this.dest_x&&(e=-1),this.dest_y>this.y&&(i=-1),t[0].x==t[1].x&&(s=!0);for(var n=0;n<t.length;n++)s?(this.p+="L "+(t[n].x-5*(0==n)*e*r)+","+(t[n].y+5*n*i)+" ",this.p+="C "+(t[n].x-2.5*(0==n)*e*r)+","+(t[n].y+2.5*n*i)+" , "+(t[n].x+2.5*n*e)+","+(t[n].y-2.5*(0==n)*i)+" , "+(t[n].x+5*n*e)+","+(t[n].y-5*(0==n)*i)):(this.p+="L "+(t[n].x-5*n*e)+","+(t[n].y+5*i*!n)+" ",this.p+="C "+(t[n].x-2.5*n*e)+","+(t[n].y+2.5*i*!n)+" , "+(t[n].x+2.5*e*!n)+","+(t[n].y-2.5*i*n*h)+" , "+(t[n].x+5*e*!n)+","+(t[n].y-5*i*n*h));this.p+="L "+this.dest_x+","+this.dest_y+" "}draw(){this.c_svg=document.createElementNS("http://www.w3.org/2000/svg","path"),null==this.p&&(this.p="M "+(this.x+this.offsetX)+","+(this.y+this.offsetY)+" "+(this.dest_x+this.offsetX)*this.scaleX+","+(this.dest_y+this.offsetY)*this.scaleY),this.c_svg.setAttribute("id",this.uuid),this.c_svg.setAttribute("d",this.p),this.c_svg.setAttribute("fill",this.config.line.fill),this.c_svg.setAttribute("stroke",this.config.shape.stroke),this.c_svg.setAttributeNS(null,"stroke-width",this.config.line.strokeWidth),this.svg.appendChild(this.c_svg),this.drawVertex(),this.vertex.map(t=>{t.draw()}),this.children.map(({child:t})=>{t.draw()}),this.addEvent("mousedown",t=>{x.mousedowncb(t,this.config)}),this.addEvent("mouseleave",t=>{x.mouseleavecb(t,this.config)}),this.addEvent("mouseover",t=>{x.mouseovercb(t,this.config),this.c_svg.setAttribute("class","move")})}shift(i,e){this.x+=i,this.y+=e,this.dest_x+=i,this.dest_y+=e,this.children.map(({child:t},s)=>{t.shift(i,e)})}redraw(){this.drawVertex(),this.vertex.map(t=>{t.redraw()}),this.path_is_set?this.path_is_set=!1:this.p="M "+(this.x+this.offsetX)+","+(this.y+this.offsetY)+" "+(this.dest_x+this.offsetX)*this.scaleX+","+(this.dest_y+this.offsetY)*this.scaleY,this.c_svg.setAttribute("d",this.p),this.children.map(({child:t})=>{t.redraw()})}calculateAngle(){var t=0,s=(this.dest_y-this.y)/(this.dest_x-this.x);return this.dest_x==this.x&&(t=Math.PI/2),0==s&&(t=0),0<=s&&this.x<this.dest_x&&this.y<this.dest_y?t=Math.asin(Math.sqrt(Math.pow(this.x-this.x,2)+Math.pow(this.y-this.dest_y,2))/Math.sqrt(Math.pow(this.x-this.dest_x,2)+Math.pow(this.y-this.dest_y,2))):0<=s&&this.x>this.dest_x&&this.y>this.dest_y?t=Math.PI+Math.asin(Math.sqrt(Math.pow(this.x-this.x,2)+Math.pow(this.dest_y-this.y,2))/Math.sqrt(Math.pow(this.x-this.dest_x,2)+Math.pow(this.y-this.dest_y,2))):s<=0&&this.x<this.dest_x&&this.y>this.dest_y?t=2*Math.PI-Math.asin(Math.sqrt(Math.pow(this.x-this.x,2)+Math.pow(this.dest_y-this.y,2))/Math.sqrt(Math.pow(this.x-this.dest_x,2)+Math.pow(this.y-this.dest_y,2))):s<=0&&this.x>this.dest_x&&this.y<this.dest_y&&(t=Math.PI-Math.asin(Math.sqrt(Math.pow(this.x-this.x,2)+Math.pow(this.dest_y-this.y,2))/Math.sqrt(Math.pow(this.x-this.dest_x,2)+Math.pow(this.y-this.dest_y,2)))),t}inclination(){var t=0,s=(this.dest_y-this.y)/(this.dest_x-this.x),t=this.dest_x==this.x?Math.PI/2:0==s?0:Math.asin(Math.sqrt(Math.pow(this.x-this.x,2)+Math.pow(this.y-this.dest_y,2))/Math.sqrt(Math.pow(this.x-this.dest_x,2)+Math.pow(this.y-this.dest_y,2)));return 0<s&&(t*=-1),t}resize(t,s,i){0==t?(this.x+=s,this.y+=i,this.children[0]&&this.children[0].child.shift(s,i)):(this.dest_x+=s,this.dest_y+=i,this.children[1]&&this.children[1].child.shift(s,i)),this.children.map(({child:t},s)=>{t.redraw()})}}class l{constructor(t=0,s=0,i="text",e=0,h,r,n=!0,o){this.uuid=v.generate(),this.x=t,this.y=s,this.config=o,h&&r?(this.dest_x=h,this.dest_y=r):this.size=e||this.config.text.size,this.text=i,this.type="text",this.svg=this.config.svg,this.events={},this.offsetX=0,this.offsetY=0,this.centerX=0,this.centerY=0,this.angle=0,this.title="",this.c_svg=null,this.textPath=null,this.path_text=null,n&&this.draw()}addEvent(t,s){this.c_svg.addEventListener(t,s),this.events[t]=s}deleteEvent(t){var s=this.events[t];this.c_svg.removeEventListener(t,s),delete this.events[t]}deleteAllEvents(){Object.keys(this.events).map(t=>{this.deleteEvent(t)})}setStyles(t){t.fill&&this.c_svg.setAttribute("fill",t.fill),t.stroke&&this.c_svg.setAttribute("stroke",t.stroke),t.strokewidth&&this.c_svg.setAttribute("stroke-width",t.strokewidth),t.fillopacity&&this.c_svg.setAttribute("fill-opacity",t.fillopacity),t.strokeopacity&&this.c_svg.setAttribute("stroke-opacity",t.strokeopacity),t.strokedasharray&&this.c_svg.setAttribute("stroke-dasharray",t.strokedasharray),t.strokedashoffset&&this.c_svg.setAttribute("stroke-dashoffset",t.strokedashoffset),t.fontsize&&this.c_svg.setAttribute("font-size",t.fontsize),t.fontfamily&&this.c_svg.setAttribute("font-family",t.fontfamily),t.fontstyle&&this.c_svg.setAttribute("font-style",t.fontstyle),t.wordspacing&&this.c_svg.setAttribute("word-spacing",t.wordspacing),t.letterspacing&&this.c_svg.setAttribute("letter-spacing",t.letterspacing),t.textlength&&this.c_svg.setAttributeNS(null,"textLength",t.textlength)}draw(){var t="http://www.w3.org/2000/svg",s="M "+this.x+","+this.y+" ";this.dest_x?s+=this.dest_x+","+this.dest_y:s+=this.x+this.size+","+this.y,this.path_text=document.createElementNS(t,"path"),this.path_text.setAttribute("id",v.generate()),this.path_text.setAttribute("d",s),this.svg.appendChild(this.path_text),this.c_svg=document.createElementNS(t,"text"),this.c_svg.setAttribute("id",v.generate()),this.c_svg.setAttributeNS(null,"letter-spacing",this.config.text.letterspacing),this.c_svg.setAttributeNS(null,"font-family",this.config.text.fontfamily),this.c_svg.setAttributeNS(null,"font-size",this.config.text.fontsize),this.c_svg.setAttributeNS(null,"font-style",this.config.text.fontstyle),this.textPath=document.createElementNS(t,"textPath"),this.textPath.setAttribute("id",v.generate()),this.textPath.setAttribute("href","#"+this.path_text.getAttribute("id")),this.textPath.setAttribute("startOffset",this.config.text.startoffset),this.textPath.setAttribute("text-anchor",this.config.text.textanchor),this.textPath.textContent=this.text,this.c_svg.appendChild(this.textPath),this.svg.appendChild(this.c_svg),this.title=document.createElementNS(t,"title"),this.title.textContent=this.text,this.c_svg.appendChild(this.title),this.svg.appendChild(this.c_svg)}redraw(){this.path_text.remove(),this.c_svg.remove(),this.textPath.remove(),this.draw()}shift(t,s){this.x+=t,this.y+=s,this.dest_x&&(this.dest_x+=t,this.dest_y+=s)}removeFromDOM(){this.path_text.remove(),this.c_svg.remove(),this.textPath.remove()}setText(t){this.text=t}}class h{constructor(t,s,i={},e){this.config=e;var h={},t=(this.uuid=v.generate(),o.find(t)),s=o.find(s);if(!t||!s)throw new Error("component is missing");this.type="link",this.src_end_csvg=null,this.dest_end_csvg=null,i.subtype?this.subtype=i.subtype:this.subtype=e.link.type,this.end_start=i.end_start||e.link.end_start,this.end_dest=i.end_dest||e.link.end_dest,this.altpath=!!i.altpath,h="broke"!=this.subtype?this.optimal(t,s):this.breakline(t,s),this.source=t.c_points[h.src],this.destination=s.c_points[h.dest],this.line=new a(this.source.x,this.source.y,this.destination.x,this.destination.y,!1,!1,null,e),"broke"==this.subtype&&(this.line.c1.x=h.c1.x,this.line.c1.y=h.c1.y,this.line.c2.x=h.c2.x,this.line.c2.y=h.c2.y,this.line.setPath([this.line.c1,this.line.c2])),this.line.draw(),this.line.setStyles({fill:"none"}),this.end_start&&this.addEnd(this.end_start,"source"),this.end_dest&&this.addEnd(this.end_dest,"destination"),this.text=null,this.text_c_svg=null,o.add(this)}addEnd(t,s){var i,e,h,r,n,o={},c=null,a=this.config.ends.circle.r,d=this.config.ends.tri.h,l="http://www.w3.org/2000/svg",x=this.line.x,f=this.line.y,u=this.line.dest_x,g=this.line.dest_y,p=this.line.inclination();"triangle"!=t&&"circle"!=t||("source"==s?(i=this.line.x,e=this.line.y,this.src_end_csvg&&this.src_end_csvg.remove(),this.line.x!=this.line.c1.x&&this.line.y!=this.line.c1.y&&(u=this.line.c1.x,g=this.line.c1.y)):"destination"==s&&(i=this.line.dest_x,e=this.line.dest_y,d=-d,a=-a,this.dest_end_csvg&&this.dest_end_csvg.remove(),this.line.x!=this.line.c2.x)&&this.line.y!=this.line.c2.y&&(x=this.line.c2.x,f=this.line.c2.y),"triangle"==t?(r=this.config.ends.tri.base,f==g?x<u?(o.x1=i,o.y1=e,o.x2=i+d,o.y2=e-r/2,o.x3=i+d,o.y3=e+r/2):(o.x1=i,o.y1=e,o.x2=i-d,o.y2=e+r/2,o.x3=i-d,o.y3=e-r/2):x==u?f<g?(o.x1=i,o.y1=e,o.x2=i+r/2,o.y2=e+d,o.x3=i-r/2,o.y3=e+d):(o.x1=i,o.y1=e,o.x2=i-r/2,o.y2=e-d,o.x3=i+r/2,o.y3=e-d):(n=d*Math.cos(p),d=d*Math.sin(p<0?-p:p),h=r/2*Math.cos(p),r=r/2*Math.sin(p<0?-p:p),p<0?x<u?(o.x1=i,o.y1=e,o.x2=i+n+r,o.y2=e+d-h,o.x3=i+n-r,o.y3=e+d+h):u<x&&(o.x1=i,o.y1=e,o.x2=i-n+r,o.y2=e-d-h,o.x3=i-n-r,o.y3=e-d+h):x<u?(o.x1=i,o.y1=e,o.x2=i+n-r,o.y2=e-d-h,o.x3=i+n+r,o.y3=e-d+h):u<x&&(o.x1=i,o.y1=e,o.x2=i-n+r,o.y2=e+d+h,o.x3=i-n-r,o.y3=e+d-h)),(c=document.createElementNS(l,"path")).setAttribute("d","M "+o.x1+","+o.y1+" L "+o.x2+","+o.y2+" L "+o.x3+","+o.y3+" Z"),c.setAttribute("id",v.generate()),c.setAttribute("fill",this.config.ends.tri.fill),c.setAttribute("stroke",this.config.ends.tri.stroke),c.setAttribute("stroke-width",this.config.ends.tri.strokeWidth)):"circle"==t&&(f==g?(o.x=x<u?i+a:i-a,o.y=e):x==u?f<g?(o.x=i,o.y=e+a):(o.x=i,o.y=e-a):(n=(g-f)/(u-x),x<u?(o.x=i+a*Math.cos(p),o.y=n*o.x+(f-n*x)):u<x&&(o.x=i-a*Math.cos(p),o.y=n*o.x+(f-n*x))),(c=document.createElementNS(l,"circle")).setAttribute("cx",o.x),c.setAttribute("cy",o.y),c.setAttribute("r",this.config.ends.circle.r),c.setAttribute("fill",this.config.ends.circle.fill),c.setAttribute("stroke",this.config.ends.circle.stroke),c.setAttribute("stroke-width",this.config.ends.circle.strokeWidth),c.setAttribute("id",v.generate())),this.config.svg.appendChild(c),"source"==s&&(this.src_end_csvg=c),"destination"==s&&(this.dest_end_csvg=c))}addText(t,s){var i;t&&(this.text=t,this.position=s="top"!=s&&"bottom"!=s&&"middle"!=s?"top":s,this.text_c_svg?(i=this.textCoordonate(),this.text_c_svg.x=i.x,this.text_c_svg.y=i.y,this.text_c_svg.dest_x=i.dest_x,this.text_c_svg.dest_y=i.dest_y,this.text_c_svg.text=this.text,this.text_c_svg.redraw()):(i=this.textCoordonate(),this.text_c_svg=new l(v.generate(),i.x,i.y,this.text,0,i.dest_x,i.dest_y),this.text_c_svg.draw()))}textCoordonate(){var t={x:0,y:0,dest_x:0,dest_y:0};return"broke"==this.subtype&&(this.line.c2.y==this.line.dest_y&&this.line.dest_x>this.line.c2.x?(t.x=this.line.c2.x,t.y=this.line.c2.y,t.dest_x=this.line.dest_x,t.dest_y=this.line.dest_y):this.line.c2.y==this.line.dest_y&&this.line.dest_x<this.line.c2.x?(t.x=this.line.dest_x,t.y=this.line.dest_y,t.dest_x=this.line.c2.x,t.dest_y=this.line.c2.y):this.line.c1.x<this.line.c2.x?(t.x=this.line.c1.x,t.y=this.line.c1.y,t.dest_x=this.line.c2.x,t.dest_y=this.line.c2.y):(t.x=this.line.c2.x,t.y=this.line.c2.y,t.dest_x=this.line.c1.x,t.dest_y=this.line.c1.y),"top"==this.position?(t.y-=10,t.dest_y-=10):"bottom"==this.position?(t.y+=22,t.dest_y+=22):(t.y+=4.5,t.dest_y+=4.5)),t}removeFromDOM(){this.line.removeFromDOM(),this.src_end_csvg&&this.config.svg.removeChild(this.src_end_csvg),this.dest_end_csvg&&this.config.svg.removeChild(this.dest_end_csvg),this.text&&this.text_c_svg.removeFromDOM();var t=o.find(this.uuid);o.clear(t.uuid)}breakline(t,s){var i={src:1,dest:3,c1:{},c2:{}},e="horizontal";return(t.c_points[1].y==s.c_points[3].y?(i.src=1,i.dest=3):t.c_points[3].y==s.c_points[1].y&&(i.src=3,i.dest=1))||(t.c_points[0].x==s.c_points[2].x&&(i.src=0),t.c_points[2].x==s.c_points[0].x&&(i.src=2,i.dest=0))?e=!1:(t.c_points[i.src].x>s.c_points[i.dest].x&&(i.src=3,i.dest=1),t.c_points[i.src].y>s.c_points[i.dest].y?Math.abs(s.c_points[i.dest].x-t.c_points[i.src].x)<=2*this.config.ends.minspace&&(i.src=0,i.dest=2,e="vertical"):Math.abs(s.c_points[i.dest].x-t.c_points[i.src].x)<=2*this.config.ends.minspace&&(i.src=2,i.dest=0,e="vertical")),this.altpath&&(1==i.src&&3==i.dest||3==i.src&&1==i.dest?t.c_points[i.src].y<s.c_points[i.dest].y?(i.src=2,i.dest=2):(i.src=0,i.dest=0):(0==i.src&&2==i.dest||2==i.src&&0==i.dest)&&(i.src=3,i.dest=3),e="altpath"),"vertical"==e?(i.c1.x=t.c_points[i.src].x,i.c1.y=(t.c_points[i.src].y+s.c_points[i.dest].y)/2,i.c2.x=s.c_points[i.dest].x,i.c2.y=(t.c_points[i.src].y+s.c_points[i.dest].y)/2):"horizontal"==e?(i.c1.x=(t.c_points[i.src].x+s.c_points[i.dest].x)/2,i.c1.y=t.c_points[i.src].y,i.c2.x=(t.c_points[i.src].x+s.c_points[i.dest].x)/2,i.c2.y=s.c_points[i.dest].y):"altpath"==e?0==i.src?(i.c1.x=t.c_points[i.src].x,i.c1.y=s.c_points[i.dest].y-2*this.config.ends.minspace,i.c2.x=s.c_points[i.dest].x,i.c2.y=s.c_points[i.dest].y-2*this.config.ends.minspace):2==i.src?(i.c1.x=t.c_points[i.src].x,i.c1.y=s.c_points[i.dest].y+2*this.config.ends.minspace,i.c2.x=s.c_points[i.dest].x,i.c2.y=s.c_points[i.dest].y+2*this.config.ends.minspace):(i.c1.x=t.c_points[i.src].x-3*this.config.ends.minspace,i.c1.y=t.c_points[i.src].y,i.c2.x=t.c_points[i.src].x-3*this.config.ends.minspace,i.c2.y=s.c_points[i.dest].y):(i.c1.x=t.c_points[i.src].x,i.c1.y=t.c_points[i.src].y,i.c2.x=t.c_points[i.src].x,i.c2.y=t.c_points[i.src].y),i}redraw(){var t=o.find(this.source.ref),s=o.find(this.destination.ref),i={},i="broke"!=this.subtype?this.optimal(t,s):this.breakline(t,s);this.source=t.c_points[i.src],this.destination=s.c_points[i.dest],this.line.x=this.source.x,this.line.y=this.source.y,this.line.dest_x=this.destination.x,this.line.dest_y=this.destination.y,"broke"==this.subtype&&(this.line.c1.x=i.c1.x,this.line.c1.y=i.c1.y,this.line.c2.x=i.c2.x,this.line.c2.y=i.c2.y,9<Math.abs(this.line.y-this.line.dest_y)&&(i.c1.x!=i.c2.x||i.c1.y!=i.c2.y)?this.line.setPathCur([this.line.c1,this.line.c2]):this.line.setPath([this.line.c1,this.line.c2])),this.line.redraw(),this.end_start&&this.addEnd(this.end_start,"source"),this.end_dest&&this.addEnd(this.end_dest,"destination"),null!=this.text&&(t=this.textCoordonate(),this.text_c_svg.x=t.x,this.text_c_svg.y=t.y,this.text_c_svg.dest_x=t.dest_x,this.text_c_svg.dest_y=t.dest_y,this.text_c_svg.redraw())}optimal(t,s){for(var i,e,h,r={},n=0;n<4;n++)for(e=0;e<4;e++)h=(t.c_points[n].x-s.c_points[e].x)*(t.c_points[n].x-s.c_points[e].x)+(t.c_points[n].y-s.c_points[e].y)*(t.c_points[n].y-s.c_points[e].y),(!i||h<i)&&(r.src=n,r.dest=e,i=h);return r}}class x{static source=null;static line=null;static current_vertex;static current_cpoint;static state=null;static dx=null;static dy=null;static mousedowncb(t,s){var i=t.srcElement.id;if(x.dx=t.offsetX,x.dy=t.offsetY,(t=o.find(i))&&(x.source=null!=t&&null!=t.ref?o.find(t.ref):t),null!=t)return null!=t&&null==t.ref?x.state="moving":null!=x.source.vertex&&0<=(x.current_vertex=x.source.vertex.indexOf(t))?x.state="resizing":(x.state="drawing_link",x.current_cpoint={x:t.x,y:t.y},x.line=document.createElementNS("http://www.w3.org/2000/svg","line"),x.line.setAttribute("x1",x.current_cpoint.x),x.line.setAttribute("y1",x.current_cpoint.y),x.line.setAttribute("x2",x.current_cpoint.x),x.line.setAttribute("y2",x.current_cpoint.y),x.line.setAttribute("stroke","black"),x.line.setAttribute("id",v.generate()),s.svg.appendChild(x.line)),x.state}static mousemovecb(t,s){var i,e,h,r=t.offsetX-x.dx,n=t.offsetY-x.dy;x.dx=t.offsetX,x.dy=t.offsetY,"moving"==x.state?(h=o.findAllLink(x.source),null!=x.source&&(h.map(s=>{x.source.c_points.map(t=>{t==s.source?i=t:t==s.destination&&(e=t)}),e?(s.line.dest_x=e.x,s.line.dest_y=e.y):(s.line.x=i.x,s.line.y=i.y),s.redraw()}),x.source.shift(r,n),x.source.redraw(),h.map(t=>{t.redraw()}))):"drawing_link"==x.state?(x.line.setAttribute("x2",t.clientX),x.line.setAttribute("y2",t.clientY)):"resizing"==x.state&&(h=o.findAllLink(x.source),x.source.resize(x.current_vertex,r,n),x.source.redraw(),h.map(t=>{t.redraw()}))}static mouseupcb(t,s){t=t.srcElement.id;if("drawing_link"==x.state){var t=o.find(t);if(t&&t.ref==x.source.uuid)return void x.line.remove();t&&t.ref&&(x.line.setAttribute("x2",t.x),x.line.setAttribute("y2",t.y),t=o.find(t.ref),new h(x.source.uuid,t.uuid,{},s)),x.line.remove(),x.line=null,x.source=null}x.state=""}static mouseovercb(t){t=t.srcElement.id,t=o.find(t);null!=t&&("line"==t.type?(t.c_svg.setAttribute("class","move"),t.vertex.map(t=>{t.c_svg.setAttribute("class","default")})):null!=t&&(t.c_svg.setAttribute("class","move"),t.c_points.map(t=>{t.c_svg.setAttribute("class","show_point")}),t.vertex.map((t,s)=>{t.c_svg.setAttribute("class","show_point"),0==s?t.c_svg.setAttribute("class","resize_left_top"):1==s?t.c_svg.setAttribute("class","resize_right_top"):2==s?t.c_svg.setAttribute("class","resize_right_bottom"):3==s&&t.c_svg.setAttribute("class","resize_left_bottom")})))}static mouseleavecb(t,s){o.findAllComponents()}}class n extends t{constructor(t=0,s=0,i=3,e=!0,h=!0,r=void 0,n){super({uuid:r,isSave:h,config:n}),this.x=t,this.y=s,this.r=i,this.box="",this.c_svg="",this.type="circle",this.scale=1,this.angle=0,e&&this.draw()}drawVertex(){0!=this.vertex.length&&(this.vertex[0].x=this.x+this.offsetX-this.r*this.scale,this.vertex[0].y=this.y+this.offsetY-this.r*this.scale,this.vertex[1].x=this.x+this.offsetX+this.r*this.scale,this.vertex[1].y=this.y+this.offsetY-this.r*this.scale,this.vertex[2].x=this.x+this.offsetX+this.r*this.scale,this.vertex[2].y=this.y+this.offsetY+this.r*this.scale,this.vertex[3].x=this.x+this.offsetX-this.r*this.scale,this.vertex[3].y=this.y+this.offsetY+this.r*this.scale)}drawConnector(){0!=this.c_points.length&&(this.c_points[0].x=this.x+this.offsetX,this.c_points[0].y=this.y+this.offsetY-this.r*this.scale,this.c_points[1].x=this.x+this.offsetX+this.r*this.scale,this.c_points[1].y=this.y+this.offsetY,this.c_points[2].x=this.x+this.offsetX,this.c_points[2].y=this.y+this.offsetY+this.r*this.scale,this.c_points[3].x=this.x+this.offsetX-this.r*this.scale,this.c_points[3].y=this.y+this.offsetY)}drawBox(){var t;0!=this.c_points.length&&0!=this.vertex.length&&(t=`M ${this.vertex[0].x} ${this.vertex[0].y} L ${this.c_points[0].x} ${this.c_points[0].y} L ${this.vertex[1].x} ${this.vertex[1].y} L ${this.c_points[1].x} ${this.c_points[1].y} L ${this.vertex[2].x} ${this.vertex[2].y} L ${this.c_points[2].x} ${this.c_points[2].y} L ${this.vertex[3].x} ${this.vertex[3].y} L ${this.c_points[3].x} ${this.c_points[3].y} Z`,this.box.setAttribute("d",t))}draw(){var t="http://www.w3.org/2000/svg";this.box=document.createElementNS(t,"path"),this.c_svg=document.createElementNS(t,"circle"),this.c_svg.setAttribute("id",this.uuid),this.c_svg.setAttribute("cx",this.x+this.offsetX),this.c_svg.setAttribute("cy",this.y+this.offsetY),this.c_svg.setAttribute("r",this.r*this.scale),this.c_svg.setAttribute("fill",this.config.shape.fill),this.c_svg.setAttribute("stroke",this.config.shape.stroke),this.c_svg.setAttribute("stroke-width",this.config.shape.strokeWidth),this.drawVertex(),this.drawConnector(),this.drawBox(),this.box.setAttribute("id",this.uuid),this.box.setAttributeNS(null,"fill",this.config.box.fill),this.box.setAttributeNS(null,"stroke",this.config.box.stroke),this.box.setAttributeNS(null,"stroke-width",this.config.box.strokeWidth),this.box.setAttribute("stroke-dasharray",this.config.box.strokeDasharray),this.svg.appendChild(this.c_svg),this.svg.appendChild(this.box),this.c_points.map(t=>{t.draw()}),this.vertex.map(t=>{t.draw()}),this.children.map(({child:t})=>{t.draw()}),this.addEvent("mousedown",t=>{x.mousedowncb(t,this.config)}),this.addEvent("mouseleave",t=>{x.mouseleavecb(t,this.config)}),this.addEvent("mouseover",t=>{x.mouseovercb(t,this.config)})}removeBoxFromDOM(){this.svg.removeChild(this.box)}shift(s,i){this.x+=s,this.y+=i,this.children.map(({child:t})=>{t.shift(s,i)})}redraw(){this.c_svg.setAttribute("cx",this.x+this.offsetX),this.c_svg.setAttribute("cy",this.y+this.offsetY),this.c_svg.setAttribute("r",this.r*this.scale),this.drawConnector(),this.drawVertex(),this.drawBox(),this.vertex.map(t=>{t.redraw()}),this.c_points.map(t=>{t.redraw()}),this.children.map(({child:t})=>{t.redraw()})}resize(t,s,i){0==t?this.r+=-s:1==t||2==t?this.r+=s:this.r-=s,this.children.map(({child:t})=>{t.redraw()})}}class f extends t{constructor(t=0,s=0,i=10,e=30,h=!0,r=!0,n=void 0,o){super({uuid:n,isSave:r,config:o}),this.x=t,this.y=s,this.width=i,this.height=e,this.box="",this.type="lozenge",this.p="",h&&this.draw()}drawVertex(){0!=this.vertex.length&&(this.vertex[0].x=this.x+this.offsetX-this.width/2*this.scaleX,this.vertex[0].y=this.y+this.offsetY,this.vertex[1].x=this.x+this.offsetX+this.width/2*this.scaleX,this.vertex[1].y=this.y+this.offsetY,this.vertex[2].x=this.x+this.offsetX+this.width/2*this.scaleX,this.vertex[2].y=this.y+this.offsetY+this.height*this.scaleY,this.vertex[3].x=this.x+this.offsetX-this.width/2*this.scaleX,this.vertex[3].y=this.y+this.offsetY+this.height*this.scaleY)}drawConnector(){0!=this.c_points.length&&(this.c_points[0].x=this.x+this.offsetX,this.c_points[0].y=this.y+this.offsetY,this.c_points[1].x=this.x+this.offsetX+this.width/2*this.scaleX,this.c_points[1].y=this.y+this.offsetY+this.height/2*this.scaleY,this.c_points[2].x=this.x+this.offsetX,this.c_points[2].y=this.y+this.offsetY+this.height*this.scaleY,this.c_points[3].x=this.x+this.offsetX-this.width/2*this.scaleX,this.c_points[3].y=this.y+this.offsetY+this.height/2*this.scaleY)}draw(){var t,s,i,e="http://www.w3.org/2000/svg";this.c_svg=document.createElementNS(e,"path"),this.box=document.createElementNS(e,"path"),0!=this.angle?(e=this.x*Math.cos(this.angle)-this.y*Math.sin(this.angle),t=this.x*Math.sin(this.angle)+this.y*Math.cos(this.angle),s=this.centerX*Math.cos(this.angle)-this.centerY*Math.sin(this.angle),i=this.centerX*Math.sin(this.angle)+this.centerY*Math.cos(this.angle),s=s-this.centerX,i=i-this.centerY,this.p=`M ${e-s+this.offsetX} ${t-i+this.offsetY} L ${e-s+this.offsetX+this.width/2*this.scaleX} ${t-i+this.offsetY+this.height/2*this.scaleY} L ${e-s+this.offsetX} ${t-i+this.offsetY+this.height*this.scaleY} L ${e-s+this.offsetX-this.width/2*this.scaleX} ${t-i+this.offsetY+this.height/2*this.scaleY}Z`):this.p=`M ${this.x+this.offsetX} ${this.y+this.offsetY} L ${this.x+this.offsetX+this.width/2*this.scaleX} ${this.y+this.offsetY+this.height/2*this.scaleY} L ${this.x+this.offsetX} ${this.y+this.offsetY+this.height*this.scaleY} L ${this.x+this.offsetX-this.width/2*this.scaleX} ${this.y+this.offsetY+this.height/2*this.scaleY}Z`,this.drawVertex(),this.drawConnector(),this.drawBox(),this.vertex.map(t=>{t.draw()}),this.c_points.map(t=>{t.draw()}),this.box.setAttribute("id",this.uuid),this.box.setAttributeNS(null,"fill",this.config.box.fill),this.box.setAttributeNS(null,"stroke",this.config.box.stroke),this.box.setAttributeNS(null,"stroke-width",this.config.box.strokeWidth),this.box.setAttribute("stroke-dasharray",this.config.box.strokeDasharray),this.c_svg.setAttribute("id",this.uuid),this.c_svg.setAttribute("d",this.p),this.c_svg.setAttribute("fill",this.config.shape.fill),this.c_svg.setAttributeNS(null,"stroke",this.config.shape.stroke),this.c_svg.setAttributeNS(null,"stroke-width",this.config.shape.strokeWidth),this.addEvent("mousedown",t=>{x.mousedowncb(t,this.config)}),this.addEvent("mouseleave",t=>{x.mouseleavecb(t,this.config)}),this.addEvent("mouseover",t=>{x.mouseovercb(t,this.config)}),this.svg.appendChild(this.c_svg),this.svg.appendChild(this.box)}removeBoxFromDOM(){this.svg.removeChild(this.box)}redraw(){var t,s,i,e;0!=this.angle?(t=this.x*Math.cos(this.angle)-this.y*Math.sin(this.angle),s=this.x*Math.sin(this.angle)+this.y*Math.cos(this.angle),i=this.centerX*Math.cos(this.angle)-this.centerY*Math.sin(this.angle),e=this.centerX*Math.sin(this.angle)+this.centerY*Math.cos(this.angle),i=i-this.centerX,e=e-this.centerY,this.p=`M ${t-i+this.offsetX} ${s-e+this.offsetY} L ${t-i+this.offsetX+this.width/2*this.scaleX} ${s-e+this.offsetY+this.height/2*this.scaleY} L ${t-i+this.offsetX} ${s-e+this.offsetY+this.height*this.scaleY} L ${t-i+this.offsetX-this.width/2*this.scaleX} ${s-e+this.offsetY+this.height/2*this.scaleY}Z`):this.p=`M ${this.x+this.offsetX} ${this.y+this.offsetY} L ${this.x+this.offsetX+this.width/2*this.scaleX} ${this.y+this.offsetY+this.height/2*this.scaleY} L ${this.x+this.offsetX} ${this.y+this.offsetY+this.height*this.scaleY} L ${this.x+this.offsetX-this.width/2*this.scaleX} ${this.y+this.offsetY+this.height/2*this.scaleY}Z`,this.drawVertex(),this.drawConnector(),this.drawBox(),this.c_svg.setAttribute("d",this.p),this.vertex.map(t=>{t.redraw()}),this.c_points.map(t=>{t.redraw()}),this.children.map(({child:t})=>{t.redraw()}),this.addEvent("mousedown",t=>{x.mousedowncb(t)}),this.addEvent("mouseleave",t=>{x.mouseleavecb(t)}),this.addEvent("mouseover",t=>{x.mouseovercb(t)})}resize(t,s,i){0==t?(this.shift(s,i),this.width+=-s,this.height+=-i):1==t?(this.y+=i,this.width+=s,this.height+=-i):2==t?(this.width+=s,this.height+=i):3==t&&(this.x+=s,this.width+=-s,this.height+=i),this.width<this.config.shape.limitWidth&&(this.width=this.config.shape.limitWidth),this.height<this.config.shape.limitHeight&&(this.height=this.config.shape.limitHeight),this.children.map(({child:t})=>{t.redraw()})}drawBox(){var t;0!=this.c_points.length&&0!=this.vertex.length&&(t=`M ${this.vertex[0].x} ${this.vertex[0].y} L ${this.c_points[0].x} ${this.c_points[0].y} L ${this.vertex[1].x} ${this.vertex[1].y} L ${this.c_points[1].x} ${this.c_points[1].y} L ${this.vertex[2].x} ${this.vertex[2].y} L ${this.c_points[2].x} ${this.c_points[2].y} L ${this.vertex[3].x} ${this.vertex[3].y} L ${this.c_points[3].x} ${this.c_points[3].y} Z`,this.box.setAttribute("d",t))}shift(s,i){this.x+=s,this.y+=i,this.c_points.map(t=>{t.shift(s,i)}),this.vertex.map(t=>{t.shift(s,i)}),this.children.map(({child:t})=>{t.shift(s,i)})}}class u extends t{constructor(t=100,s=100,i=200,e=300,h=!0,r=!0,n,o){super({uuid:n,isSave:r,config:o}),this.x=t,this.y=s,this.width=i,this.height=e,this.type="rectangle",h&&this.draw()}arroundCorners(t=3,s=3){this.c_svg.setAttributeNS(null,"rx",t),this.c_svg.setAttributeNS(null,"ry",s)}draw(){this.c_svg=document.createElementNS("http://www.w3.org/2000/svg","rect"),this.c_svg.setAttributeNS(null,"id",this.uuid),this.c_svg.setAttributeNS(null,"x",this.x+this.offsetX),this.c_svg.setAttributeNS(null,"y",this.y+this.offsetY),this.c_svg.setAttributeNS(null,"width",this.width*this.scaleX),this.c_svg.setAttributeNS(null,"height",this.height*this.scaleY),this.c_svg.setAttributeNS(null,"fill",this.config.shape.fill),this.c_svg.setAttributeNS(null,"stroke",this.config.shape.stroke),this.c_svg.setAttributeNS(null,"stroke-width",this.config.shape.strokeWidth),this.svg.appendChild(this.c_svg),this.drawConnector(),this.drawVertex(),this.c_points.map(t=>{t.draw()}),this.vertex.map(t=>{t.draw()}),this.children.map(({child:t})=>{t.draw()}),this.addEvent("mousedown",t=>{x.mousedowncb(t,this.config)}),this.addEvent("mouseleave",t=>{x.mouseleavecb(t,this.config)}),this.addEvent("mouseover",t=>{x.mouseovercb(t,this.config)})}drawVertex(){0!=this.vertex.length&&(this.vertex[0].x=this.x+this.offsetX,this.vertex[0].y=this.y+this.offsetY,this.vertex[1].x=this.x+this.offsetX+this.width*this.scaleX,this.vertex[1].y=this.y+this.offsetY,this.vertex[2].x=this.x+this.offsetX+this.width*this.scaleX,this.vertex[2].y=this.y+this.offsetY+this.height*this.scaleY,this.vertex[3].x=this.x+this.offsetX,this.vertex[3].y=this.y+this.offsetY+this.height*this.scaleY)}drawConnector(){0!=this.c_points.length&&(this.c_points[0].x=this.x+this.offsetX+this.width/2*this.scaleX,this.c_points[0].y=this.y+this.offsetY,this.c_points[1].x=this.x+this.offsetX+this.width*this.scaleX,this.c_points[1].y=this.y+this.offsetY+this.height/2*this.scaleY,this.c_points[2].x=this.x+this.offsetX+this.width/2*this.scaleX,this.c_points[2].y=this.y+this.offsetY+this.height*this.scaleY,this.c_points[3].x=this.x+this.offsetX,this.c_points[3].y=this.y+this.offsetY+this.height/2*this.scaleY)}shift(s,i){this.x+=s,this.y+=i,this.c_points.map(t=>{t.shift(s,i)}),this.vertex.map(t=>{t.shift(s,i)}),this.children.map(({child:t})=>{t.shift(s,i)})}redraw(){this.c_svg.setAttributeNS(null,"x",this.x+this.offsetX),this.c_svg.setAttributeNS(null,"y",this.y+this.offsetY),this.c_svg.setAttributeNS(null,"height",this.height*this.scaleY),this.c_svg.setAttributeNS(null,"width",this.width*this.scaleX),this.drawVertex(),this.drawConnector(),this.c_points.map(t=>{t.redraw()}),this.vertex.map(t=>{t.redraw()}),this.children.map(({child:t})=>{t.redraw()})}resize(t,s,i){0==t?(this.shift(s,i),this.width+=-s,this.height+=-i):1==t?(this.shift(0,i),this.width+=s,this.height+=-i):2==t?(this.width+=s,this.height+=i):3==t&&(this.shift(s,0),this.width+=-s,this.height+=i),this.width<this.config.shape.limitWidth&&(this.width=this.config.shape.limitWidth),this.height<this.config.shape.limitHeight&&(this.height=this.config.shape.limitHeight),this.children.map(({child:t})=>{t.redraw()})}}class g extends t{constructor(t=0,s=0,i=5,e=5,h=10,r=10,n=!0,o=!0,c,a){super({uuid:c,isSave:o,config:a}),this.x1=t,this.y1=s,this.x2=i,this.y2=e,this.x3=h,this.y3=r,this.type="triangle",this.c_points=[],this.vertex=[],n&&this.draw()}drawVertex(){this.vertex.length}drawConnector(){this.c_points.length}drawBox(){}draw(){var t,s,i,e,h,r,n,o;this.c_svg=document.createElementNS("http://www.w3.org/2000/svg","path"),0!=this.angle?(t=this.x1*Math.cos(this.angle)-this.y1*Math.sin(this.angle),s=this.x1*Math.sin(this.angle)+this.y1*Math.cos(this.angle),i=this.x2*Math.cos(this.angle)-this.y2*Math.sin(this.angle),e=this.x2*Math.sin(this.angle)+this.y2*Math.cos(this.angle),h=this.x3*Math.cos(this.angle)-this.y3*Math.sin(this.angle),r=this.x3*Math.sin(this.angle)+this.y3*Math.cos(this.angle),n=this.centerX*Math.cos(this.angle)-this.centerY*Math.sin(this.angle),o=this.centerX*Math.sin(this.angle)+this.centerY*Math.cos(this.angle),n=n-this.centerX,o=o-this.centerY,this.p="M "+(t-n+this.offsetX)+","+(s-o+this.offsetY)+" L "+(i-n+this.offsetX)+","+(e-o+this.offsetY)+" L "+(h-n+this.offsetX)+","+(r-o+this.offsetY)+" Z"):this.p="M "+(this.x1+this.offsetX)+","+(this.y1+this.offsetY)+" L "+(this.x2+this.offsetX)+","+(this.y2+this.offsetY)+" L "+(this.x3+this.offsetX)+","+(this.y3+this.offsetY)+" Z",this.c_svg.setAttribute("id",this.uuid),this.c_svg.setAttribute("d",this.p),this.c_svg.setAttribute("fill",this.config.shape.fill),this.c_svg.setAttributeNS(null,"stroke",this.config.shape.stroke),this.c_svg.setAttributeNS(null,"stroke-width",this.config.shape.strokeWidth),this.svg.appendChild(this.c_svg),this.addEvent("mousedown",t=>{x.mousedowncb(t,this.config)}),this.addEvent("mouseleave",t=>{x.mouseleavecb(t,this.config)}),this.addEvent("mouseover",t=>{x.mouseovercb(t,this.config)})}shift(s,i){this.x1+=s,this.y1+=i,this.x2+=s,this.y2+=i,this.x3+=s,this.y3+=i,this.c_points.map(t=>{t.shift(s,i)}),this.vertex.map(t=>{t.shift(s,i)}),this.children.map(({child:t})=>{t.shift(s,i)})}redraw(){var t,s,i,e,h,r,n,o;0!=this.angle?(t=this.x1*Math.cos(this.angle)-this.y1*Math.sin(this.angle),s=this.x1*Math.sin(this.angle)+this.y1*Math.cos(this.angle),i=this.x2*Math.cos(this.angle)-this.y2*Math.sin(this.angle),e=this.x2*Math.sin(this.angle)+this.y2*Math.cos(this.angle),h=this.x3*Math.cos(this.angle)-this.y3*Math.sin(this.angle),r=this.x3*Math.sin(this.angle)+this.y3*Math.cos(this.angle),n=this.centerX*Math.cos(this.angle)-this.centerY*Math.sin(this.angle),o=this.centerX*Math.sin(this.angle)+this.centerY*Math.cos(this.angle),n=n-this.centerX,o=o-this.centerY,this.p="M "+(t-n+this.offsetX)+","+(s-o+this.offsetY)+" L "+(i-n+this.offsetX)+","+(e-o+this.offsetY)+" L "+(h-n+this.offsetX)+","+(r-o+this.offsetY)+" Z"):this.p="M "+(this.x1+this.offsetX)+","+(this.y1+this.offsetY)+" L "+(this.x2+this.offsetX)+","+(this.y2+this.offsetY)+" L "+(this.x3+this.offsetX)+","+(this.y3+this.offsetY)+" Z",this.c_svg.setAttribute("d",this.p)}resize(t,s,i){0==t?(this.x1=s,this.y1=i,this.vertex[0].x=s,this.vertex[0].y=i):1==t?(this.x2=s,this.y2=i,this.vertex[1].x=s,this.vertex[1].y=i):2==t&&(this.x3=s,this.y3=i,this.vertex[2].x=s,this.vertex[2].y=i)}}class r extends t{constructor(t=[],s=!0,i=!0,e=void 0,h){super({uuid:e,isSave:i,config:h}),this.x=t[0],this.y=t[1],this.dest_x=t[t.length-2],this.dest_y=t[t.length-1],this.points=t,this.type="polyline",this.vertex=[],this.c_points=[],s&&this.draw()}drawVertex(){this.vertex.length}drawConnector(){this.c_points.length}draw(){this.c_svg=document.createElementNS("http://www.w3.org/2000/svg","polyline");for(var t="",s=0;s<this.points.length;s++)t+=s%2==0?this.points[s]+this.offsetX+",":this.points[s]+this.offsetY+" ";this.c_svg.setAttribute("id",this.uuid),this.c_svg.setAttribute("fill",this.config.shape.fill),this.c_svg.setAttribute("stroke",this.config.shape.stroke),this.c_svg.setAttributeNS(null,"stroke-width",this.config.shape.strokeWidth),this.c_svg.setAttribute("points",t),this.svg.appendChild(this.c_svg),this.drawVertex(),this.c_points.map(t=>{t.draw()}),this.vertex.map(t=>{t.draw()}),this.children.map(({child:t})=>{t.draw()})}shift(s,i){for(var t=0;t<this.points.length;t++)this.points[t]+=t%2==0?s:i;this.children.map(({child:t})=>{t.shift(s,i)})}redraw(){this.drawVertex(),this.vertex.map(t=>{t.redraw()});for(var t="",s=0;s<this.points.length;s++)t+=s%2==0?this.points[s]+this.offsetX+",":this.points[s]+this.offsetY+" ";this.c_svg.setAttribute("points",t),this.children.map(({child:t})=>{t.redraw()})}calculateAngle(){var t,s=(this.dest_y-this.y)/(this.dest_x-this.x);return 0==s&&(t=0),0<=s&&this.x<this.dest_x&&this.y<this.dest_y?t=Math.asin(Math.sqrt(Math.pow(this.x-this.x,2)+Math.pow(this.y-this.dest_y,2))/Math.sqrt(Math.pow(this.x-this.dest_x,2)+Math.pow(this.y-this.dest_y,2))):0<=s&&this.x>this.dest_x&&this.y>this.dest_y?t=Math.PI+Math.asin(Math.sqrt(Math.pow(this.x-this.x,2)+Math.pow(this.dest_y-this.y,2))/Math.sqrt(Math.pow(this.x-this.dest_x,2)+Math.pow(this.y-this.dest_y,2))):s<=0&&this.x<this.dest_x&&this.y>this.dest_y?t=2*Math.PI-Math.asin(Math.sqrt(Math.pow(this.x-this.x,2)+Math.pow(this.dest_y-this.y,2))/Math.sqrt(Math.pow(this.x-this.dest_x,2)+Math.pow(this.y-this.dest_y,2))):s<=0&&this.x>this.dest_x&&this.y<this.dest_y&&(t=Math.PI-Math.asin(Math.sqrt(Math.pow(this.x-this.x,2)+Math.pow(this.dest_y-this.y,2))/Math.sqrt(Math.pow(this.x-this.dest_x,2)+Math.pow(this.y-this.dest_y,2)))),t}resize(t,s,i){0==t?(this.x+=s,this.y+=i):(this.dest_x+=s,this.dest_y+=i),this.children.map(({})=>{(this.calculateAngle()+90*Math.PI/180).redraw()})}}class p extends t{constructor(t=0,s=0,i=100,e=100,h=90,r=.5,n=!0,o=!0,c=void 0,a){super({uuid:c,isSave:o,config:a}),this.x0=t,this.y0=s,this.x=i,this.y=e,this.angle=h,this.offsetX0=0,this.offsetY0=0,this.dest_x=Math.round(this.x0+this.offsetX0+(this.x+this.offsetX-(this.x0+this.offsetX0))*Math.cos(this.angle*Math.PI/180)+(this.y+this.offsetY-(this.y0+this.offsetY0))*Math.sin(this.angle*Math.PI/180)),this.dest_y=Math.round(this.y0+this.offsetY0-(this.x+this.offsetX-(this.x0+this.offsetX0))*Math.sin(this.angle*Math.PI/180)+(this.y+this.offsetY-(this.y0+this.offsetY0))*Math.cos(this.angle*Math.PI/180)),this.type="arc",this.radius=Math.sqrt((this.x+this.offsetX-(this.x0+this.offsetX0))*(this.x+this.offsetX-(this.x0+this.offsetX0))+(this.y+this.offsetY-(this.y0+this.offsetY0))*(this.y+this.offsetY-(this.y0+this.offsetY0))),this.ratio=r,this.vertex=[],this.c_points=[],n&&this.draw()}drawVertex(){this.vertex.length}drawConnector(){this.c_points.length}draw(){this.c_svg=document.createElementNS("http://www.w3.org/2000/svg","path"),this.dest_x=Math.round(this.x0+this.offsetX0+(this.x+this.offsetX-(this.x0+this.offsetX0))*Math.cos(this.angle*Math.PI/180)+(this.y+this.offsetY-(this.y0+this.offsetY0))*Math.sin(this.angle*Math.PI/180)),this.dest_y=Math.round(this.y0+this.offsetY0-(this.x+this.offsetX-(this.x0+this.offsetX0))*Math.sin(this.angle*Math.PI/180)+(this.y+this.offsetY-(this.y0+this.offsetY0))*Math.cos(this.angle*Math.PI/180)),this.p="M"+(this.x0==this.x?this.x0:this.x0+this.ratio*(this.x-this.x0))+" "+(this.x0==this.x?this.y0+this.ratio*(this.y-this.y0):(this.y-this.y0)/(this.x-this.x0)*(this.x0+this.ratio*(this.x-this.x0))+(this.y0-(this.y-this.y0)/(this.x-this.x0)*this.x0))+" L"+this.x+" "+this.y+" A "+this.radius+" "+this.radius+" 0 "+(180<this.angle?1:0)+" 0 "+this.dest_x+" "+this.dest_y+" L "+(this.dest_x-(1-this.ratio)*(this.dest_x-this.x0))+" "+((this.dest_y-this.y0)/(this.dest_x-this.x0)*(this.dest_x-(1-this.ratio)*(this.dest_x-this.x0))+(this.y0-(this.dest_y-this.y0)/(this.dest_x-this.x0)*this.x0)),this.c_svg.setAttribute("id",this.uuid),this.c_svg.setAttribute("fill",this.config.arc.fill),this.c_svg.setAttribute("stroke",this.config.arc.stroke),this.c_svg.setAttributeNS(null,"stroke-width",this.config.arc.strokeWidth),this.c_svg.setAttribute("d",this.p),this.svg.appendChild(this.c_svg),this.addEvent("mouseover",t=>{this.c_svg.setAttribute("class","move"),x.mouseovercb(t,this.config)}),this.addEvent("mousedown",t=>{x.mousedowncb(t,this.config)}),this.addEvent("mouseleave",t=>{x.mouseleavecb(t,this.config)})}shift(s,i){this.x0+=s,this.y0+=i,this.x+=s,this.y+=i,this.children.map(({child:t})=>{t.shift(s,i)})}redraw(){this.dest_x=Math.round(this.x0+this.offsetX0+(this.x+this.offsetX-(this.x0+this.offsetX0))*Math.cos(this.angle*Math.PI/180)+(this.y+this.offsetY-(this.y0+this.offsetY0))*Math.sin(this.angle*Math.PI/180)),this.dest_y=Math.round(this.y0+this.offsetY0-(this.x+this.offsetX-(this.x0+this.offsetX0))*Math.sin(this.angle*Math.PI/180)+(this.y+this.offsetY-(this.y0+this.offsetY0))*Math.cos(this.angle*Math.PI/180)),this.p="M"+(this.x0==this.x?this.x0:this.x0+this.ratio*(this.x-this.x0))+" "+(this.x0==this.x?this.y0+this.ratio*(this.y-this.y0):(this.y-this.y0)/(this.x-this.x0)*(this.x0+this.ratio*(this.x-this.x0))+(this.y0-(this.y-this.y0)/(this.x-this.x0)*this.x0))+" L"+this.x+" "+this.y+" A "+this.radius+" "+this.radius+" 0 "+(180<this.angle?1:0)+" 0 "+this.dest_x+" "+this.dest_y+" L "+(this.dest_x-(1-this.ratio)*(this.dest_x-this.x0))+" "+((this.dest_y-this.y0)/(this.dest_x-this.x0)*(this.dest_x-(1-this.ratio)*(this.dest_x-this.x0))+(this.y0-(this.dest_y-this.y0)/(this.dest_x-this.x0)*this.x0)),this.c_svg.setAttribute("d",this.p),this.children.map(({child:t})=>{t.redraw()})}calculateAngle(t,s,i,e){var h,r=(e-s)/(i-t);return i==t&&(h=-Math.PI/2),0==r&&(h=0),0<=r&&t<i&&s<e?h=Math.asin(Math.sqrt(Math.pow(t-t,2)+Math.pow(s-e,2))/Math.sqrt(Math.pow(t-i,2)+Math.pow(s-e,2))):0<=r&&i<t&&e<s?h=Math.PI+Math.asin(Math.sqrt(Math.pow(t-t,2)+Math.pow(e-s,2))/Math.sqrt(Math.pow(t-i,2)+Math.pow(s-e,2))):r<=0&&t<i&&e<s?h=2*Math.PI-Math.asin(Math.sqrt(Math.pow(t-t,2)+Math.pow(e-s,2))/Math.sqrt(Math.pow(t-i,2)+Math.pow(s-e,2))):r<=0&&i<t&&s<e&&(h=Math.PI-Math.asin(Math.sqrt(Math.pow(t-t,2)+Math.pow(e-s,2))/Math.sqrt(Math.pow(t-i,2)+Math.pow(s-e,2)))),h}resize(t,s,i){0==t?(this.x+=s,this.y+=i):(this.dest_x+=s,this.dest_y+=i),this.children.map(({child:t})=>{t.angle=this.calculateAngle()+90*Math.PI/180,t.redraw()})}}class y extends t{constructor(t=0,s=0,i=50,e=50,h,r,n=!0,o=!0,c=void 0,a,d=void 0){super({uuid:c,isSave:o,config:a}),null!=d&&(this.c_svg=this.stringToSvg(d)),this.width=i,this.height=e,this.x=t,this.y=s,this.path=h,this.name=r,this.type="image",n&&this.draw()}stringToSvg(t){return(new DOMParser).parseFromString(t,"image/svg+xml").documentElement}draw(){""!=this.c_svg&&null!=this.c_svg||(this.c_svg=document.createElementNS("http://www.w3.org/2000/svg","image"),this.c_svg.setAttributeNS("http://www.w3.org/1999/xlink","href",this.path)),this.c_svg.setAttributeNS(null,"id",this.uuid),this.c_svg.setAttributeNS(null,"height",this.height),this.c_svg.setAttributeNS(null,"width",this.width),this.c_svg.setAttributeNS(null,"x",this.x+this.offsetX),this.c_svg.setAttributeNS(null,"y",this.y+this.offsetY),this.svg.append(this.c_svg)}shift(t,s){this.x+=t,this.y+=s}redraw(){this.c_svg.setAttributeNS(null,"x",this.x+this.offsetX),this.c_svg.setAttributeNS(null,"y",this.y+this.offsetY)}removeFromDOM(){this.svg.removeChild(this.c_svg)}}class _{constructor(t,s=40,i=40,e=2,h=2,r="white",n="gray",o=.2){if(null==t)throw"missing parameter";this.cellW=s,this.cellH=i,this.subdivisionX=e,this.subdivisionY=h,this.bgColor=r,this.lineColor=n,this.lineThicness=o,this.svg=t,this.subpattern=document.createElementNS("http://www.w3.org/2000/svg","pattern"),this.subpattern.setAttribute("id","subpatternId"),this.subpattern.setAttribute("width",this.cellW/this.subdivisionX),this.subpattern.setAttribute("height",this.cellH/this.subdivisionY),this.subpattern.setAttribute("patternUnits","userSpaceOnUse"),this.subpatternRect=document.createElementNS("http://www.w3.org/2000/svg","rect"),this.subpatternRect.setAttribute("width","100%"),this.subpatternRect.setAttribute("height","100%"),this.subpatternRect.setAttribute("height","100%"),this.subpatternRect.setAttribute("fill",this.bgColor),this.subpatternRect.setAttribute("stroke",this.lineColor),this.subpatternRect.setAttribute("stroke-width",this.lineThicness/2),this.subpattern.append(this.subpatternRect),this.svg.append(this.subpattern),this.pattern=document.createElementNS("http://www.w3.org/2000/svg","pattern"),this.pattern.setAttribute("id","patternId"),this.pattern.setAttribute("width",this.cellW),this.pattern.setAttribute("height",this.cellH),this.pattern.setAttribute("patternUnits","userSpaceOnUse"),this.patternrect=document.createElementNS("http://www.w3.org/2000/svg","rect"),this.patternrect.setAttribute("width","100%"),this.patternrect.setAttribute("height","100%"),this.patternrect.setAttribute("fill","url(#subpatternId)"),this.patternrect.setAttribute("stroke",this.lineColor),this.patternrect.setAttribute("stroke-width",this.lineThicness),this.pattern.append(this.patternrect),this.svg.append(this.pattern),this.rect=document.createElementNS("http://www.w3.org/2000/svg","rect"),this.rect.setAttribute("id","gridRect"),this.rect.setAttribute("fill","url(#patternId)"),this.rect.setAttribute("width","100%"),this.rect.setAttribute("height","100%"),this.svg.append(this.rect),this.subpattern.addEventListener("mousemove",()=>{}),this.subpattern.addEventListener("mouseup",()=>{}),this.subpatternRect.addEventListener("mousemove",()=>{}),this.subpatternRect.addEventListener("mouseup",()=>{}),this.pattern.addEventListener("mousemove",()=>{}),this.pattern.addEventListener("mouseup",()=>{}),this.patternrect.addEventListener("mousemove",()=>{}),this.patternrect.addEventListener("mouseup",()=>{}),this.rect.addEventListener("mousemove",()=>{}),this.rect.addEventListener("mouseup",()=>{})}redraw(){this.subpattern.setAttribute("width",this.cellW/this.subdivisionX),this.subpattern.setAttribute("height",this.cellH/this.subdivisionY),this.subpatternRect.setAttribute("width","100%"),this.subpatternRect.setAttribute("height","100%"),this.subpatternRect.setAttribute("fill",this.bgColor),this.subpatternRect.setAttribute("stroke",this.lineColor),this.subpatternRect.setAttribute("stroke-width",this.lineThicness/2),this.pattern.setAttribute("id","patternId"),this.pattern.setAttribute("width",this.cellW),this.pattern.setAttribute("height",this.cellH),this.patternrect.setAttribute("width","100%"),this.patternrect.setAttribute("height","100%"),this.patternrect.setAttribute("fill","url(#subpatternId)"),this.patternrect.setAttribute("stroke",this.lineColor),this.patternrect.setAttribute("stroke-width",this.lineThicness),this.rect.setAttribute("id","gridRect"),this.rect.setAttribute("fill","url(#patternId)"),this.rect.setAttribute("width","100%"),this.rect.setAttribute("height","100%")}remove(){this.svg.removeChild(this.subpattern),this.svg.removeChild(this.pattern),this.svg.removeChild(this.rect)}setGridSize(t){t.cellw&&(this.cellW=t.cellw),t.cellh&&(this.cellH=t.cellh),t.subdx&&(this.subdivisionX=t.subdx),t.subdy&&(this.subdivisionY=t.subdy),t.bgc&&(this.bgColor=t.bgc),t.lc&&(this.lineColor=t.lc),t.border&&(this.lineThicness=t.border),t.width&&this.svg.setAttribute("width",t.width),t.height&&this.svg.setAttribute("height",t.height),this.redraw()}}var w={svg:null,shape:{stroke:"black",fill:"white",strokeOpacity:"1",strokeWidth:"1px",fillOpacity:"1",limitWidth:20,limitHeight:20},arc:{stroke:"black",fill:"white",strokeOpacity:"1",strokeWidth:"1px",fillOpacity:"1",limitWidth:20,limitHeight:20},box:{stroke:"indigo",strokeWidth:"2px",fill:"none",strokeDasharray:"4"},point:{fill:"black",strokeWidth:"1pt",radius:3},line:{stroke:"black",fill:"white",strokeWidth:"1px",strokeDasharray:"4",strokelinejoin:"round"},link:{type:"broke",end_start:"cirle",end_dest:"triangle"},text:{fill:"black",fontfamily:"sans-serif",fontstyle:"normal",fontsize:"medium",fontweight:"normal",size:100,textanchor:"middle",letterspacing:0,startoffset:"50%"},ends:{tri:{h:8,base:8,fill:"black",stroke:"black",strokeW