-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathflowSharpWeb.all.js.min
More file actions
3 lines (3 loc) · 36.4 KB
/
flowSharpWeb.all.js.min
File metadata and controls
3 lines (3 loc) · 36.4 KB
1
2
3
Array.prototype.any=function(n){for(var i,t=0;t<this.length;t++)if(n&&(i=n(this[t]),i))return!0;return!1};class Helpers{static uuidv4(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,n=>(n^crypto.getRandomValues(new Uint8Array(1))[0]&15>>n/4).toString(16))}static parseTransform(n){var i={},r,t;for(r in a=n.match(/(\w+\((\-?\d+\.?\d*e?\-?\d*,?)+\))+/g))t=a[r].match(/[\w\.\-]+/g),i[t.shift()]=t;return i}static getElement(n){var t=document.getElementById(Constants.SVG_ELEMENT_ID);return t.getElementById(n)}static getElements(n){var t=document.getElementById(Constants.SVG_ELEMENT_ID);return t.getElementsByClassName(n)}static createElement(n,t){var i=document.createElementNS(Constants.SVG_NS,n);return i.setAttributeNS(null,"id",Helpers.uuidv4()),i.setAttributeNS(null,"class",Constants.SHAPE_CLASS_NAME),Object.entries(t).map([n,t]=>i.setAttributeNS(null,n,t)),i}static translateToSvgCoordinate(n){var t=document.getElementById(Constants.SVG_ELEMENT_ID),r=t.createSVGPoint(),i=r.matrixTransform(t.getScreenCTM().inverse());return n.translate(i.x,i.y)}static translateToScreenCoordinate(n){var t=document.getElementById(Constants.SVG_ELEMENT_ID),r=t.createSVGPoint(),i=r.matrixTransform(t.getScreenCTM());return n.translate(-i.x,-i.y)}static getNearbyShapes(n){var f=document.getElementById("svg"),t=f.createSVGRect(),r,u,i;for(t.x=n.x-Constants.NEARBY_DELTA/2,t.y=n.y-Constants.NEARBY_DELTA/2,t.height=Constants.NEARBY_DELTA,t.width=Constants.NEARBY_DELTA,r=f.getIntersectionList(t,null),u=[],i=0;i<r.length;i++)r[i].getAttribute("class")==Constants.SHAPE_CLASS_NAME&&u.push(r[i]);return u}static removeChildren(n){while(n.firstChild)n.removeChild(n.firstChild)}static isNear(n,t,i){return Math.abs(n.x-t.x)<=i&&Math.abs(n.y-t.y)<=i}}class Point{constructor(n,t){this.x=n;this.y=t}translate(n,t){return new Point(this.x+n,this.y+t)}}
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/src/FileSaver.js */
var saveAs=saveAs||function(n){"use strict";if(typeof n!="undefined"&&(typeof navigator=="undefined"||!/MSIE [1-9]\./.test(navigator.userAgent))){var s=n.document,r=function(){return n.URL||n.webkitURL||n},i=s.createElementNS("http://www.w3.org/1999/xhtml","a"),h="download"in i,c=function(n){var t=new MouseEvent("click");n.dispatchEvent(t)},l=/constructor/i.test(n.HTMLElement)||n.safari,u=/CriOS\/[\d]+/.test(navigator.userAgent),a=function(t){(n.setImmediate||n.setTimeout)(function(){throw t;},0)},v="application/octet-stream",y=4e4,f=function(n){var t=function(){typeof n=="string"?r().revokeObjectURL(n):n.remove()};setTimeout(t,y)},p=function(n,t,i){var r,u;for(t=[].concat(t),r=t.length;r--;)if(u=n["on"+t[r]],typeof u=="function")try{u.call(n,i||n)}catch(f){a(f)}},e=function(n){return/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(n.type)?new Blob([String.fromCharCode(65279),n],{type:n.type}):n},o=function(t,o,s){s||(t=e(t));var a=this,k=t.type,b=k===v,y,w=function(){p(a,"writestart progress write writeend".split(" "))},d=function(){var i,e;if((u||b&&l)&&n.FileReader){i=new FileReader;i.onloadend=function(){var t=u?i.result:i.result.replace(/^data:[^;]*;/,"data:attachment/file;"),r=n.open(t,"_blank");r||(n.location.href=t);t=undefined;a.readyState=a.DONE;w()};i.readAsDataURL(t);a.readyState=a.INIT;return}y||(y=r().createObjectURL(t));b?n.location.href=y:(e=n.open(y,"_blank"),e||(n.location.href=y));a.readyState=a.DONE;w();f(y)};if(a.readyState=a.INIT,h){y=r().createObjectURL(t);setTimeout(function(){i.href=y;i.download=o;c(i);w();f(y);a.readyState=a.DONE});return}d()},t=o.prototype,w=function(n,t,i){return new o(n,t||n.name||"download",i)};return typeof navigator!="undefined"&&navigator.msSaveOrOpenBlob?function(n,t,i){return t=t||n.name||"download",i||(n=e(n)),navigator.msSaveOrOpenBlob(n,t)}:(t.abort=function(){},t.readyState=t.INIT=0,t.WRITING=1,t.DONE=2,t.error=t.onwritestart=t.onprogress=t.onwrite=t.onabort=t.onerror=t.onwriteend=null,w)}}(typeof self!="undefined"&&self||typeof window!="undefined"&&window||this);class Model{constructor(){this.eventPropertyChanged=null;this._tx=0;this._ty=0}get tx(){return this._tx}get ty(){return this._ty}propertyChanged(n,t){this.eventPropertyChanged!=null&&this.eventPropertyChanged(n,t)}serialize(){return{tx:this._tx,ty:this._ty}}deserialize(n){this._tx=n.tx;this._ty=n.ty;this.setTranslate(this._tx,this._ty)}translate(n,t){this._tx+=n;this._ty+=t;this.setTranslate(this._tx,this._ty)}setTranslation(n,t){this._tx=n;this._ty=t;this.setTranslate(n,t)}updateTranslation(n,t){this._tx+=n;this._ty+=t}setTranslate(n,t){this.translation="translate("+n+","+t+")";this.transform=this.translation}set transform(n){this._transform=n;this.propertyChanged("transform",n)}set tx(n){this._tx=n;this.translation="translate("+this._tx+","+this._ty+")";this.transform=this.translation}set ty(n){this._ty=n;this.translation="translate("+this._tx+","+this._ty+")";this.transform=this.translation}}class DiagramModel{constructor(n){this.mouseController=n;this.models=[];this.mvc={Rectangle:{model:RectangleModel,view:ShapeView,controller:RectangleController,creator:()=>this.createElement("rect")},Circle:{model:CircleModel,view:ShapeView,controller:CircleController,creator:()=>this.createElement("circle")},Diamond:{model:DiamondModel,view:ShapeView,controller:DiamondController,creator:()=>this.createElement("path")},Line:{model:LineModel,view:LineView,controller:LineController,creator:()=>this.createLineElement()},Text:{model:TextModel,view:TextView,controller:TextController,creator:()=>this.createTextElement()}};this.connections=[]}clear(){this.models=[];this.connections=[]}addModel(n,t){this.models.push({model:n,id:t})}connect(n,t,i,r){this.connections.push({shapeId:n,lineId:t,shapeCPIdx:i,lineAnchorIdx:r})}disconnect(n,t){this.connections=this.connections.filter(i=>!(i.lineId==n&&i.lineAnchorIdx==t))}removeShape(n){this.connections=this.connections.filter(t=>!(t.shapeId==n||t.lineId==n));this.models=this.models.filter(t=>t.id!=n)}createElement(n){return Helpers.createElement(n,{fill:"#FFFFFF",stroke:"black","stroke-width":1})}createTextElement(){return Helpers.createElement("text",{"font-size":12,"font-family":"Verdana"})}createLineElement(){var n=Helpers.createElement("g",{});return n.appendChild(Helpers.createElement("line",{"stroke-width":20,stroke:"black","stroke-opacity":"0","fill-opacity":"0"})),n.appendChild(Helpers.createElement("line",{fill:"#FFFFFF",stroke:"black","stroke-width":1})),n}serialize(){var n=[],t=surfaceModel.serialize();return t[Object.keys(t)[0]].id=Constants.SVG_SURFACE_ID,n.push(t),this.models.map(t=>{var i=t.model.serialize();i[Object.keys(i)[0]].id=t.id;n.push(i)}),JSON.stringify({model:n,connections:this.connections})}deserialize(n){var t=JSON.parse(n),r=t.model,i;this.connections=t.connections;i=[];surfaceModel.setTranslation(0,0);objectsModel.setTranslation(0,0);r.map(n=>{var t=Object.keys(n)[0],u=n[t],n,f,r,e;t=="Surface"?(surfaceModel.deserialize(u),objectsModel.setTranslation(surfaceModel.tx,surfaceModel.ty)):(n=new this.mvc[t].model,i.push(n),f=this.mvc[t].creator(),r=new this.mvc[t].view(f,n),n.deserialize(u,f),r.id=u.id,e=new this.mvc[t].controller(mouseController,r,n),this.models.push({model:n,id:u.id}),Helpers.getElement(Constants.SVG_OBJECTS_ID).appendChild(f),this.mouseController.attach(r,e),e.shouldShowAnchors&&this.mouseController.attach(r,anchorGroupController))})}}class ObjectsModel extends Model{constructor(){super()}}class ShapeModel extends Model{constructor(){super()}}class SurfaceModel extends Model{constructor(){super();this.gridCellW=80;this.gridCellH=80;this.cellW=8;this.cellH=8}serialize(){var n=super.serialize();return n.gridCellW=this.gridCellW,n.gridCellH=this.gridCellH,n.cellW=this.cellW,n.cellH=this.cellH,{Surface:n}}deserialize(n){this.gridCellW=n.gridCellW;this.gridCellH=n.gridCellH;this.cellW=n.cellW;this.cellH=n.cellH;this.resizeGrid(this.gridCellW,this.gridCellH,this.cellW,this.cellH);this._tx=n.tx;this._ty=n.ty;var t=this.tx%this.gridCellW,i=this.ty%this.gridCellH;this.setTranslate(t,i)}resizeGrid(n,t,i,r){var f,e;this.gridCellW=n;this.gridCellH=t;this.cellW=i;this.cellH=r;var o=document.getElementById("largeGridRect"),a=document.getElementById("largeGridPath"),s=document.getElementById("largeGrid"),v=document.getElementById("smallGridPath"),h=document.getElementById("smallGrid"),c=document.getElementById("svg"),u=document.getElementById("surface"),l=document.getElementById("grid");o.setAttribute("width",n);o.setAttribute("height",t);a.setAttribute("d","M "+n+" 0 H 0 V "+t);s.setAttribute("width",n);s.setAttribute("height",t);v.setAttribute("d","M "+i+" 0 H 0 V "+r);h.setAttribute("width",i);h.setAttribute("height",r);l.setAttribute("x",-n);l.setAttribute("y",-t);f=+c.getAttribute("width");e=+c.getAttribute("height");u.setAttribute("width",f+n*2);u.setAttribute("height",e+t*2);u.setAttribute("x",-n);u.setAttribute("y",-t);u.setAttribute("width",f+n*2);u.setAttribute("height",e+t*2)}}class RectangleModel extends ShapeModel{constructor(){super();this._x=0;this._y=0;this._width=0;this._height=0}serialize(){var n=super.serialize();return n.x=this._x,n.y=this._y,n.width=this._width,n.height=this._height,{Rectangle:n}}deserialize(n,t){super.deserialize(n,t);this.x=n.x;this.y=n.y;this.width=n.width;this.height=n.height}get x(){return this._x}get y(){return this._y}get width(){return this._width}get height(){return this._height}set x(n){this._x=n;this.propertyChanged("x",n)}set y(n){this._y=n;this.propertyChanged("y",n)}set width(n){this._width=n;this.propertyChanged("width",n)}set height(n){this._height=n;this.propertyChanged("height",n)}}class CircleModel extends ShapeModel{constructor(){super();this._cx=0;this._cy=0;this._r=0}serialize(){var n=super.serialize();return n.cx=this._cx,n.cy=this._cy,n.r=this._r,{Circle:n}}deserialize(n,t){super.deserialize(n,t);this.cx=n.cx;this.cy=n.cy;this.r=n.r}get cx(){return this._cx}get cy(){return this._cy}get r(){return this._r}set cx(n){this._cx=n;this.propertyChanged("cx",n)}set cy(n){this._cy=n;this.propertyChanged("cy",n)}set r(n){this._r=n;this.propertyChanged("r",n)}}class PathModel extends ShapeModel{constructor(){super();this._d=null}serialize(){var n=super.serialize();return n.d=this._d,n}deserialize(n,t){super.deserialize(n,t);this.d=n.d}get d(){return this._d}set d(n){this._d=n;this.propertyChanged("d",n)}}class DiamondModel extends PathModel{constructor(){super()}serialize(){var n=super.serialize();return{Diamond:n}}}class LineModel extends ShapeModel{constructor(){super();this._x1=0;this._y1=0;this._x2=0;this._y2=0}serialize(){var n=super.serialize();return n.x1=this._x1,n.y1=this._y1,n.x2=this._x2,n.y2=this._y2,{Line:n}}deserialize(n,t){super.deserialize(n,t);this.x1=n.x1;this.y1=n.y1;this.x2=n.x2;this.y2=n.y2}get x1(){return this._x1}get y1(){return this._y1}get x2(){return this._x2}get y2(){return this._y2}set x1(n){this._x1=n;this.propertyChanged("x1",n)}set y1(n){this._y1=n;this.propertyChanged("y1",n)}set x2(n){this._x2=n;this.propertyChanged("x2",n)}set y2(n){this._y2=n;this.propertyChanged("y2",n)}}class TextModel extends ShapeModel{constructor(){super();this._x=0;this._y=0;this._text=""}serialize(){var n=super.serialize();return n.x=this._x,n.y=this._y,n.text=this._text,{Text:n}}deserialize(n,t){super.deserialize(n,t);this.x=n.x;this.y=n.y;this.text=n.text}get x(){return this._x}get y(){return this._y}get text(){return this._text}set x(n){this._x=n;this.propertyChanged("x",n)}set y(n){this._y=n;this.propertyChanged("y",n)}set text(n){this._text=n;this.propertyChanged("text",n)}}class View{constructor(n,t){this.svgElement=n;t.eventPropertyChanged=this.onPropertyChange.bind(this)}get id(){return this.svgElement.getAttribute("id")}set id(n){this.svgElement.setAttribute("id",n)}onPropertyChange(n,t){this.svgElement.firstElementChild==null?this.svgElement.setAttribute(n,t):this.svgElement.firstElementChild.setAttribute(n,t)}}class AnchorView extends View{constructor(n,t){super(n,t)}onPropertyChange(n,t){this.svgElement.setAttribute(n,t)}}class ObjectsView extends View{constructor(n,t){super(n,t)}}class ShapeView extends View{constructor(n,t){super(n,t)}}class LineView extends ShapeView{constructor(n,t){super(n,t)}onPropertyChange(n,t){this.svgElement.children[0].setAttribute(n,t);this.svgElement.children[1].setAttribute(n,t)}}class TextView extends View{constructor(n,t){super(n,t)}onPropertyChange(n,t){if(n=="text")this.svgElement.innerHTML=t;else super.onPropertyChange(n,t)}}class SurfaceView extends View{constructor(n,t){super(n,t)}onPropertyChange(n,t){this.svgElement.setAttribute(n,t)}}class Controller{constructor(n,t,i){this.mouseController=n;this.view=t;this.model=i;this.events=[];this.wireUpEvents()}get isSurfaceController(){return!1}get isAnchorController(){return!1}get isToolboxShapeController(){return!1}get shouldShowAnchors(){return!0}get hasConnectionPoints(){return!0}registerEvent(n,t,i){this.events.push({element:n,eventName:t,callbackRef:i})}destroy(){this.unhookEvents()}registerEventListener(n,t,i,r){var u;(r==null||r===undefined)&&(r=this);n.addEventListener(t,u=i.bind(r));this.registerEvent(n,t,u)}unhookEvents(){for(var t,n=0;n<this.events.length;n++)t=this.events[n],t.element.removeEventListener(t.eventName,t.callbackRef);this.events=[]}wireUpEvents(){this.registerEventListener(this.view.svgElement,"mousedown",this.mouseController.onMouseDown,this.mouseController);this.registerEventListener(this.view.svgElement,"mouseup",this.mouseController.onMouseUp,this.mouseController);this.registerEventListener(this.view.svgElement,"mousemove",this.mouseController.onMouseMove,this.mouseController);this.registerEventListener(this.view.svgElement,"mouseenter",this.mouseController.onMouseEnter,this.mouseController);this.registerEventListener(this.view.svgElement,"mouseleave",this.mouseController.onMouseLeave,this.mouseController)}getAbsoluteLocation(n){return n=n.translate(this.model.tx,this.model.ty),n.translate(surfaceModel.tx,surfaceModel.ty)}getRelativeLocation(n){return n=n.translate(-this.model.tx,-this.model.ty),n.translate(-surfaceModel.tx,-surfaceModel.ty)}onMouseEnter(){}onMouseLeave(){}onMouseDown(){}onMouseUp(){}onDrag(n,t){this.model.translate(n,t);this.adjustConnections(n,t)}adjustConnections(n,t){var i=diagramModel.connections.filter(n=>n.shapeId==this.view.id);i.map(i=>{var r=this.mouseController.getControllersById(i.lineId)[0];r.translateEndpoint(i.lineAnchorIdx,n,t)})}adjustConnectorsAttachedToConnectionPoint(n,t,i){var r=diagramModel.connections.filter(n=>n.shapeId==this.view.id&&n.shapeCPIdx==i);r.map(i=>{var r=this.mouseController.getControllersById(i.lineId)[0];r.translateEndpoint(i.lineAnchorIdx,n,t)})}}class AnchorController extends Controller{constructor(n,t,i,r,u,f){super(n,t,i);this.fncDragAnchor=u;this.anchorIdx=f;this.shapeConnectionPoints=[];this.shapeController=r}get isAnchorController(){return!0}get hasConnectionPoints(){return!1}get shouldShowAnchors(){return!1}onDrag(n,t){this.fncDragAnchor(n,t);this.showAnyConnectionPoints()}onMouseUp(n){super.onMouseUp(n);this.connectIfCloseToShapeConnectionPoint();this.removeConnectionPoints();this.shapeConnectionPoints=[]}showAnyConnectionPoints(){var n,i,r,t;this.shapeController.canConnectToShapes&&(n=this.getNewNearbyShapes(this.mouseController.x,this.mouseController.y),this.createConnectionPoints(n.newShapes),i=n.newShapes.concat(n.existingShapes).map(n=>n.id),r=this.shapeConnectionPoints.filter(n=>i.indexOf(n.id)<0),this.removeExpiredShapeConnectionPoints(r),t=n.existingShapes.map(n=>n.id),this.shapeConnectionPoints=this.shapeConnectionPoints.filter(n=>t.indexOf(n.id)>=0),this.shapeConnectionPoints=this.shapeConnectionPoints.concat(n.newShapes),console.log("scp: "+this.shapeConnectionPoints.length+", new: "+n.newShapes.length+", existing: "+t.length))}getNewNearbyShapes(n,t){var r=[],u=[],i=new Point(n,t),f;return i=Helpers.translateToScreenCoordinate(i),f=Helpers.getNearbyShapes(i),f.map(n=>{var t=this.mouseController.getControllersByElement(n);t&&t.map(n=>{var t,i;n.hasConnectionPoints&&(t=n.view.id,this.shapeConnectionPoints.any(n=>n.id==t)?u.push({id:t}):(i=n.getConnectionPoints(),r.push({id:t,controller:n,connectionPoints:i})))})}),{newShapes:r,existingShapes:u}}createConnectionPoints(n){var t=Helpers.getElement(Constants.SVG_CONNECTION_POINTS_ID);n.map(n=>{n.connectionPoints.map(i=>{var r=i.connectionPoint,u=Helpers.createElement("g",{connectingToShapeId:n.id});u.appendChild(Helpers.createElement("line",{x1:r.x-5,y1:r.y-5,x2:r.x+5,y2:r.y+5,fill:"#FFFFFF",stroke:"#000080","stroke-width":1}));u.appendChild(Helpers.createElement("line",{x1:r.x+5,y1:r.y-5,x2:r.x-5,y2:r.y+5,fill:"#FFFFFF",stroke:"#000080","stroke-width":1}));t.appendChild(u)})})}removeConnectionPoints(){var n=Helpers.getElement(Constants.SVG_CONNECTION_POINTS_ID);Helpers.removeChildren(n)}removeExpiredShapeConnectionPoints(n){n.map(n=>{var t=document.querySelectorAll('[connectingtoshapeid="'+n.id+'"]');[...t].map(n=>{n.parentNode.removeChild(n)})})}connectIfCloseToShapeConnectionPoint(){var n=new Point(this.mouseController.x,this.mouseController.y),t,i;n=Helpers.translateToScreenCoordinate(n);t=[];this.shapeConnectionPoints.filter(i=>{for(var u,r=0;r<i.connectionPoints.length;r++)u=i.connectionPoints[r],Helpers.isNear(u.connectionPoint,n,Constants.MAX_CP_NEAR)&&t.push({shapeController:i.controller,shapeCPIdx:r,connectionPoint:u.connectionPoint})});t.length==1&&(i=t[0],n=i.connectionPoint,n=n.translate(-this.shapeController.model.tx,-this.shapeController.model.ty),n=n.translate(-surfaceModel.tx,-surfaceModel.ty),this.shapeController.connect(this.anchorIdx,n),diagramModel.connect(i.shapeController.view.id,this.shapeController.view.id,i.shapeCPIdx,this.anchorIdx))}}class AnchorGroupController extends Controller{constructor(n,t,i){super(n,t,i);this.anchors=[];this.showingAnchors=!1}get hasConnectionPoints(){return!1}wireUpEvents(){}partialOnDrag(n,t,i){return function(n,t,i){return function(r,u){i(n,t,r,u)}}(n,t,i)}showAnchors(n){var e,r,i,t,o,u;for(this.anchors=n.getAnchors(),this.anchors.views=[],this.showingAnchors=!0,e=Helpers.getElement(Constants.SVG_ANCHORS_ID),this.model._tx=0,this.model._ty=0,this.model.setTranslate(0,0),r=[],i=[],this.anchors.map(n=>{var f=n.anchor,t=new RectangleModel,u;t._x=f.x-5;t._y=f.y-5;t._width=10;t._height=10;u=this.createElement("rect",{x:t.x,y:t.y,width:t.width,height:t.height,fill:"#FFFFFF",stroke:"#808080","stroke-width":.5});r.push(u);i.push(t);e.appendChild(u)}),t=0;t<this.anchors.length;t++){o=this.anchors[t];u=r[t];u.setAttribute("id","anchor"+t);var f=new View(u,i[t]),s=this.partialOnDrag(i,i[t],o.onDrag),h=new AnchorController(this.mouseController,f,i[t],n,s,t);this.mouseController.attach(f,h);this.anchors.views.push(f)}}createElement(n,t){var i=document.createElementNS("http://www.w3.org/2000/svg",n);return i.setAttribute("id",Helpers.uuidv4()),Object.entries(t).map([n,t]=>i.setAttribute(n,t)),i}removeAnchors(){var n=Helpers.getElement(Constants.SVG_ANCHORS_ID);n.innerHTML="";this.anchors.views.map(n=>this.mouseController.destroy(n));this.anchors=[];this.showingAnchors=!1}}const LEFT_MOUSE_BUTTON=0,TOOLBOX_DRAG_MIN_MOVE=3;class MouseController{constructor(){this.mouseDown=!1;this.controllers={};this.activeControllers=null;this.currentHoverControllers=[];this.leavingId=-1;this.draggingToolboxShape=!1;this.selectedControllers=null;this.selectedShapeId=null;this.hoverShapeId=null;this.x=0;this.y=0;this.dx=0;this.dy=0}attach(n,t){var i=n.id;this.controllers[i]==undefined&&(this.controllers[i]=[]);this.controllers[i].push(t)}detach(n){var t=n.id;delete this.controllers[t]}detachAll(){this.controllers={}}destroy(n){var t=n.id;this.controllers[t].map(n=>n.destroy());delete this.controllers[t]}destroyShapeById(n){this.controllers[n].map(n=>n.destroy());delete this.controllers[n]}destroyAll(){Object.entries(this.controllers).map([,n]=>n.map(n=>n.destroy()));this.controllers={}}destroyAllButSurface(){Object.entries(this.controllers).map([n,t]=>{t.map(t=>{t.isSurfaceController||t.isToolboxShapeController||(t.destroy(),delete this.controllers[n])})})}get isClick(){var n=this.x,t=this.y;return Math.abs(this.startDownX-n)<TOOLBOX_DRAG_MIN_MOVE&&Math.abs(this.startDownY-t)<TOOLBOX_DRAG_MIN_MOVE}onKeyDown(n){var r=this.hoverShapeId!=null,t=!1,i;if(r)switch(n.keyCode){case Constants.KEY_RIGHT:this.currentHoverControllers.map(n=>n.onDrag(1,0));t=!0;break;case Constants.KEY_UP:this.currentHoverControllers.map(n=>n.onDrag(0,-1));t=!0;break;case Constants.KEY_LEFT:this.currentHoverControllers.map(n=>n.onDrag(-1,0));t=!0;break;case Constants.KEY_DOWN:this.currentHoverControllers.map(n=>n.onDrag(0,1));t=!0;break;case Constants.KEY_DELETE:this.currentHoverControllers.map(n=>n.onMouseLeave());diagramModel.removeShape(this.hoverShapeId);this.destroyShapeById(this.hoverShapeId);i=Helpers.getElement(this.hoverShapeId);i.parentNode.removeChild(i);this.currentHoverControllers=[];this.hoverShapeId=null;t=!0}return r&&t}onMouseDown(n){if(n.button==LEFT_MOUSE_BUTTON){n.preventDefault();var t=n.currentTarget.getAttribute("id");this.selectedShapeId=t;this.activeControllers=this.controllers[t];this.selectedControllers=this.controllers[t];this.mouseDown=!0;this.startDownX=n.clientX;this.startDownY=n.clientY;this.x=n.clientX;this.y=n.clientY;this.activeControllers.map(n=>n.onMouseDown())}}onMouseMove(n){n.preventDefault();this.mouseDown&&this.activeControllers!=null&&(this.dx=n.clientX-this.x,this.dy=n.clientY-this.y,this.x=n.clientX,this.y=n.clientY,this.activeControllers.map(n=>n.onDrag(this.dx,this.dy)))}onMouseUp(n){if(n.preventDefault(),n.button==LEFT_MOUSE_BUTTON&&this.activeControllers!=null){this.selectedShapeId=null;this.x=n.clientX;this.y=n.clientY;var t=this.isClick;this.activeControllers.map(n=>n.onMouseUp(t));this.clearSelectedObject();this.draggingToolboxShape&&this.finishDragAndDrop(this.shapeBeingDraggedAndDropped,n.currentTarget)}}onMouseEnter(n){n.preventDefault();var t=n.currentTarget.getAttribute("id");this.hoverShapeId=t;this.mouseDown||this.leavingId!=-1&&(console.log("Leaving "+this.leavingId),this.controllers[t][0].isAnchorController?console.log("Leaving shape to enter anchor."):(this.currentHoverControllers.map(n=>n.onMouseLeave()),console.log("Entering "+t+" => "+this.controllers[t].map(n=>n.constructor.name).join(", ")),this.currentHoverControllers=this.controllers[t],this.currentHoverControllers.map(n=>n.onMouseEnter())))}onMouseLeave(n){n.preventDefault();this.leavingId=n.currentTarget.getAttribute("id");this.hoverShapeId=null}getControllers(n){var t=n.currentTarget.getAttribute("id");return this.controllers[t]}getControllersById(n){return this.controllers[n]}getControllersByElement(n){var t=n.getAttribute("id");return this.getControllersById(t)}clearSelectedObject(){this.mouseDown=!1;this.activeControllers=null}finishDragAndDrop(n,t){Helpers.getElement(Constants.SVG_TOOLBOX_ID).removeChild(n);var i=n.getAttribute("id");this.controllers[i].map(n=>n.model.translate(-surfaceModel.tx+toolboxGroupController.model.tx,-surfaceModel.ty+toolboxGroupController.model.ty));Helpers.getElement(Constants.SVG_OBJECTS_ID).appendChild(n);i==t.getAttribute("id")&&(this.currentHoverControllers=this.controllers[i],this.currentHoverControllers.map(n=>n.onMouseEnter()));this.draggingToolboxShape=!1}}class ShapeController extends Controller{constructor(n,t,i){super(n,t,i)}getAnchors(){return[]}getConnectionPoints(){return[]}getCorners(){return[this.getULCorner(),this.getLRCorner()]}onDrag(n,t){super.onDrag(n,t)}get canConnectToShapes(){return!1}connect(){throw"Shape appears to be capable of connecting to other shapes but doesn't implement connect(idx, p).";}onMouseEnter(){!this.mouseController.mouseDown&&this.shouldShowAnchors&&anchorGroupController.showAnchors(this)}onMouseLeave(){this.shouldShowAnchors&&anchorGroupController.removeAnchors()}moveAnchor(n,t,i){n.translate(t,i)}adjustAnchorX(n,t){n.translate(t,0)}adjustAnchorY(n,t){n.translate(0,t)}}class ToolboxShapeController extends Controller{constructor(n,t,i){super(n,t,i)}get isToolboxShapeController(){return!0}onMouseUp(n){if(n){console.log("toolbox shape click");var t=this.createElementAt(270,130);diagramModel.addModel(t.model,t.view.id);t.model.translate(-surfaceModel.tx,-surfaceModel.ty);this.addToObjectsGroup(t);this.attachToMouseController(t)}}onDrag(){var n,t;this.mouseController.isClick||(console.log("toolbox shape onDrag"),n=this.createElementAt(this.mouseController.x-toolboxGroupController.model.tx,this.mouseController.y-toolboxGroupController.model.ty),diagramModel.addModel(n.model,n.view.id),this.addToToolboxGroup(n),t=this.attachToMouseController(n),this.mouseController.activeControllers=t,this.mouseController.draggingToolboxShape=!0,this.mouseController.shapeBeingDraggedAndDropped=n.el)}addToObjectsGroup(n){Helpers.getElement(Constants.SVG_OBJECTS_ID).appendChild(n.el)}addToToolboxGroup(n){Helpers.getElement(Constants.SVG_TOOLBOX_ID).appendChild(n.el)}attachToMouseController(n){return this.mouseController.attach(n.view,n.controller),this.mouseController.attach(n.view,anchorGroupController),[n.controller,anchorGroupController]}}class SurfaceController extends Controller{constructor(n,t,i){super(n,t,i)}get isSurfaceController(){return!0}get hasConnectionPoints(){return!1}onDrag(n,t){this.model.updateTranslation(n,t);var n=this.model.tx%this.model.gridCellW,t=this.model.ty%this.model.gridCellH;this.model.setTranslate(n,t)}onMouseLeave(){this.mouseController.clearSelectedObject()}}class ObjectsController extends Controller{constructor(n,t,i){super(n,t,i)}get isSurfaceController(){return!0}get hasConnectionPoints(){return!1}wireUpEvents(){}}class ToolboxGroupController extends Controller{constructor(n,t,i){super(n,t,i)}wireUpEvents(){}}class ToolboxSurfaceController extends Controller{constructor(n,t,i){super(n,t,i)}get isSurfaceController(){return!0}get hasConnectionPoints(){return!1}onDrag(n,t){toolboxGroupController.onDrag(n,t)}}class RectangleController extends ShapeController{constructor(n,t,i){super(n,t,i)}getAnchors(){var n=this.getCorners(),t=new Point((n[0].x+n[1].x)/2,n[0].y),i=new Point((n[0].x+n[1].x)/2,n[1].y),r=new Point(n[0].x,(n[0].y+n[1].y)/2),u=new Point(n[1].x,(n[0].y+n[1].y)/2);return[{anchor:t,onDrag:this.topMove.bind(this)},{anchor:i,onDrag:this.bottomMove.bind(this)},{anchor:r,onDrag:this.leftMove.bind(this)},{anchor:u,onDrag:this.rightMove.bind(this)}]}getConnectionPoints(){var n=this.getCorners(),t=new Point((n[0].x+n[1].x)/2,n[0].y),i=new Point((n[0].x+n[1].x)/2,n[1].y),r=new Point(n[0].x,(n[0].y+n[1].y)/2),u=new Point(n[1].x,(n[0].y+n[1].y)/2);return[{connectionPoint:t},{connectionPoint:i},{connectionPoint:r},{connectionPoint:u}]}getULCorner(){var n=new Point(this.model.x,this.model.y);return this.getAbsoluteLocation(n)}getLRCorner(){var n=new Point(this.model.x+this.model.width,this.model.y+this.model.height);return this.getAbsoluteLocation(n)}topMove(n,t,i,r){var u=this.model.y+r,f=this.model.height-r;this.model.y=u;this.model.height=f;this.moveAnchor(n[0],0,r);this.adjustAnchorY(n[2],r/2);this.adjustAnchorY(n[3],r/2);this.adjustConnectorsAttachedToConnectionPoint(0,r,0);this.adjustConnectorsAttachedToConnectionPoint(0,r/2,2);this.adjustConnectorsAttachedToConnectionPoint(0,r/2,3)}bottomMove(n,t,i,r){var u=this.model.height+r;this.model.height=u;this.moveAnchor(n[1],0,r);this.adjustAnchorY(n[2],r/2);this.adjustAnchorY(n[3],r/2);this.adjustConnectorsAttachedToConnectionPoint(0,r,1);this.adjustConnectorsAttachedToConnectionPoint(0,r/2,2);this.adjustConnectorsAttachedToConnectionPoint(0,r/2,3)}leftMove(n,t,i){var r=this.model.x+i,u=this.model.width-i;this.model.x=r;this.model.width=u;this.moveAnchor(n[2],i,0);this.adjustAnchorX(n[0],i/2);this.adjustAnchorX(n[1],i/2);this.adjustConnectorsAttachedToConnectionPoint(i,0,2);this.adjustConnectorsAttachedToConnectionPoint(i/2,0,0);this.adjustConnectorsAttachedToConnectionPoint(i/2,0,1)}rightMove(n,t,i){var r=this.model.width+i;this.model.width=r;this.moveAnchor(n[3],i,0);this.adjustAnchorX(n[0],i/2);this.adjustAnchorX(n[1],i/2);this.adjustConnectorsAttachedToConnectionPoint(i,0,3);this.adjustConnectorsAttachedToConnectionPoint(i/2,0,0);this.adjustConnectorsAttachedToConnectionPoint(i/2,0,1)}}class CircleController extends ShapeController{constructor(n,t,i){super(n,t,i)}getAnchors(){var n=this.getCorners(),t=new Point((n[0].x+n[1].x)/2,n[0].y),i=new Point((n[0].x+n[1].x)/2,n[1].y),r=new Point(n[0].x,(n[0].y+n[1].y)/2),u=new Point(n[1].x,(n[0].y+n[1].y)/2);return[{anchor:t,onDrag:this.topMove.bind(this)},{anchor:i,onDrag:this.bottomMove.bind(this)},{anchor:r,onDrag:this.leftMove.bind(this)},{anchor:u,onDrag:this.rightMove.bind(this)}]}getConnectionPoints(){var n=this.getCorners(),t=new Point((n[0].x+n[1].x)/2,n[0].y),i=new Point((n[0].x+n[1].x)/2,n[1].y),r=new Point(n[0].x,(n[0].y+n[1].y)/2),u=new Point(n[1].x,(n[0].y+n[1].y)/2);return[{connectionPoint:t},{connectionPoint:i},{connectionPoint:r},{connectionPoint:u}]}getULCorner(){var n=new Point(this.model.cx-this.model.r,this.model.cy-this.model.r);return this.getAbsoluteLocation(n)}getLRCorner(){var n=new Point(this.model.cx+this.model.r,this.model.cy+this.model.r);return this.getAbsoluteLocation(n)}topMove(n,t,i,r){this.changeRadius(-r);this.moveAnchor(n[0],0,r);this.moveAnchor(n[1],0,-r);this.moveAnchor(n[2],r,0);this.moveAnchor(n[3],-r,0);this.adjustConnectorsAttachedToConnectionPoint(0,r,0);this.adjustConnectorsAttachedToConnectionPoint(0,-r,1);this.adjustConnectorsAttachedToConnectionPoint(r,0,2);this.adjustConnectorsAttachedToConnectionPoint(-r,0,3)}bottomMove(n,t,i,r){this.changeRadius(r);this.moveAnchor(n[0],0,-r);this.moveAnchor(n[1],0,r);this.moveAnchor(n[2],-r,0);this.moveAnchor(n[3],r,0);this.adjustConnectorsAttachedToConnectionPoint(0,-r,0);this.adjustConnectorsAttachedToConnectionPoint(0,r,1);this.adjustConnectorsAttachedToConnectionPoint(-r,0,2);this.adjustConnectorsAttachedToConnectionPoint(r,0,3)}leftMove(n,t,i){this.changeRadius(-i);this.moveAnchor(n[0],0,i);this.moveAnchor(n[1],0,-i);this.moveAnchor(n[2],i,0);this.moveAnchor(n[3],-i,0);this.adjustConnectorsAttachedToConnectionPoint(0,i,0);this.adjustConnectorsAttachedToConnectionPoint(0,-i,1);this.adjustConnectorsAttachedToConnectionPoint(i,0,2);this.adjustConnectorsAttachedToConnectionPoint(-i,0,3)}rightMove(n,t,i){this.changeRadius(i);this.moveAnchor(n[0],0,-i);this.moveAnchor(n[1],0,i);this.moveAnchor(n[2],-i,0);this.moveAnchor(n[3],i,0);this.adjustConnectorsAttachedToConnectionPoint(0,-i,0);this.adjustConnectorsAttachedToConnectionPoint(0,i,1);this.adjustConnectorsAttachedToConnectionPoint(-i,0,2);this.adjustConnectorsAttachedToConnectionPoint(i,0,3)}changeRadius(n){this.model.r=this.model.r+n}}class DiamondController extends ShapeController{constructor(n,t,i){super(n,t,i)}getAnchors(){var n=this.getCorners(),t=new Point((n[0].x+n[1].x)/2,n[0].y),i=new Point((n[0].x+n[1].x)/2,n[1].y),r=new Point(n[0].x,(n[0].y+n[1].y)/2),u=new Point(n[1].x,(n[0].y+n[1].y)/2);return[{anchor:t,onDrag:this.topMove.bind(this)},{anchor:i,onDrag:this.bottomMove.bind(this)},{anchor:r,onDrag:this.leftMove.bind(this)},{anchor:u,onDrag:this.rightMove.bind(this)}]}getConnectionPoints(){var n=this.getCorners(),t=new Point((n[0].x+n[1].x)/2,n[0].y),i=new Point((n[0].x+n[1].x)/2,n[1].y),r=new Point(n[0].x,(n[0].y+n[1].y)/2),u=new Point(n[1].x,(n[0].y+n[1].y)/2);return[{connectionPoint:t},{connectionPoint:i},{connectionPoint:r},{connectionPoint:u}]}getULCorner(){var n=this.view.svgElement.getBoundingClientRect(),t=new Point(n.left,n.top);return Helpers.translateToSvgCoordinate(t)}getLRCorner(){var n=this.view.svgElement.getBoundingClientRect(),t=new Point(n.right,n.bottom);return Helpers.translateToSvgCoordinate(t)}topMove(n,t,i,r){var u=this.getULCorner(),f=this.getLRCorner();this.changeHeight(u,f,-r);this.moveAnchor(n[0],0,r);this.moveAnchor(n[1],0,-r);this.adjustConnectorsAttachedToConnectionPoint(0,r,0);this.adjustConnectorsAttachedToConnectionPoint(0,-r,1)}bottomMove(n,t,i,r){var u=this.getULCorner(),f=this.getLRCorner();this.changeHeight(u,f,r);this.moveAnchor(n[0],0,-r);this.moveAnchor(n[1],0,r);this.adjustConnectorsAttachedToConnectionPoint(0,-r,0);this.adjustConnectorsAttachedToConnectionPoint(0,r,1)}leftMove(n,t,i){var r=this.getULCorner(),u=this.getLRCorner();this.changeWidth(r,u,-i);this.moveAnchor(n[2],i,0);this.moveAnchor(n[3],-i,0);this.adjustConnectorsAttachedToConnectionPoint(i,0,2);this.adjustConnectorsAttachedToConnectionPoint(-i,0,3)}rightMove(n,t,i){var r=this.getULCorner(),u=this.getLRCorner();this.changeWidth(r,u,i);this.moveAnchor(n[2],-i,0);this.moveAnchor(n[3],i,0);this.adjustConnectorsAttachedToConnectionPoint(-i,0,2);this.adjustConnectorsAttachedToConnectionPoint(i,0,3)}changeWidth(n,t,i){n.x-=i;t.x+=i;this.updatePath(n,t)}changeHeight(n,t,i){n.y-=i;t.y+=i;this.updatePath(n,t)}updatePath(n,t){var n=this.getRelativeLocation(n),t=this.getRelativeLocation(t),r=(n.x+t.x)/2,u=(n.y+t.y)/2,i="M "+r+" "+n.y;i=i+" L "+n.x+" "+u;i=i+" L "+r+" "+t.y;i=i+" L "+t.x+" "+u;i=i+" Z";this.model.d=i}}class LineController extends ShapeController{constructor(n,t,i){super(n,t,i)}get canConnectToShapes(){return!0}onDrag(n,t){super.onDrag(n,t);diagramModel.disconnect(this.view.id,0);diagramModel.disconnect(this.view.id,1)}connect(n,t){switch(n){case 0:this.model.x1=t.x;this.model.y1=t.y;break;case 1:this.model.x2=t.x;this.model.y2=t.y}}translateEndpoint(n,t,i){var r;switch(n){case 0:r=new Point(this.model.x1,this.model.y1);r=r.translate(t,i);this.model.x1=r.x;this.model.y1=r.y;break;case 1:r=new Point(this.model.x2,this.model.y2);r=r.translate(t,i);this.model.x2=r.x;this.model.y2=r.y}}getAnchors(){var n=this.getCorners();return[{anchor:n[0],onDrag:this.moveULCorner.bind(this)},{anchor:n[1],onDrag:this.moveLRCorner.bind(this)}]}getULCorner(){var n=new Point(this.model.x1,this.model.y1);return this.getAbsoluteLocation(n)}getLRCorner(){var n=new Point(this.model.x2,this.model.y2);return this.getAbsoluteLocation(n)}moveULCorner(n,t,i,r){this.model.x1=this.model.x1+i;this.model.y1=this.model.y1+r;this.moveAnchor(t,i,r);diagramModel.disconnect(this.view.id,0)}moveLRCorner(n,t,i,r){this.model.x2=this.model.x2+i;this.model.y2=this.model.y2+r;this.moveAnchor(t,i,r);diagramModel.disconnect(this.view.id,1)}}class TextController extends ShapeController{constructor(n,t,i){super(n,t,i)}get shouldShowAnchors(){return!1}getConnectionPoints(){var n=this.getCorners(),t=new Point((n[0].x+n[1].x)/2,n[0].y),i=new Point((n[0].x+n[1].x)/2,n[1].y),r=new Point(n[0].x,(n[0].y+n[1].y)/2),u=new Point(n[1].x,(n[0].y+n[1].y)/2);return[{connectionPoint:t},{connectionPoint:i},{connectionPoint:r},{connectionPoint:u}]}onMouseDown(n){super.onMouseDown(n);var t=this.model.text;document.getElementById("text").value=t}getULCorner(){var n=this.view.svgElement.getBoundingClientRect(),t=new Point(n.left,n.top);return Helpers.translateToSvgCoordinate(t)}getLRCorner(){var n=this.view.svgElement.getBoundingClientRect(),t=new Point(n.right,n.bottom);return Helpers.translateToSvgCoordinate(t)}}class ToolboxRectangleController extends ToolboxShapeController{constructor(n,t,i){super(n,t,i)}createElementAt(n,t){var r=Helpers.createElement("g",{}),e=Helpers.createElement("rect",{x:n-30,y:t-30,width:60,height:60,fill:"#FFFFFF",stroke:"black","stroke-width":1}),i,u,f;return r.appendChild(e),i=new RectangleModel,i._x=n-30,i._y=t-30,i._width=60,i._height=60,u=new ShapeView(r,i),f=new RectangleController(this.mouseController,u,i),{el:r,model:i,view:u,controller:f}}}class ToolboxCircleController extends ToolboxShapeController{constructor(n,t,i){super(n,t,i)}createElementAt(n,t){var u=Helpers.createElement("circle",{cx:n,cy:t,r:30,fill:"#FFFFFF",stroke:"black","stroke-width":1}),i=new CircleModel,r,f;return i._cx=n,i._cy=t,i._r=30,r=new ShapeView(u,i),f=new CircleController(this.mouseController,r,i),{el:u,model:i,view:r,controller:f}}}class ToolboxDiamondController extends ToolboxShapeController{constructor(n,t,i){super(n,t,i)}createElementAt(n,t){var o=[{cmd:"M",x:n-15,y:t-30},{cmd:"L",x:n-45,y:t},{cmd:"L",x:n-15,y:t+30},{cmd:"L",x:n+15,y:t}],r=o.reduce((n,t)=>n=n+t.cmd+" "+t.x+" "+t.y,""),u,i,f,e;return r=r+" Z",u=Helpers.createElement("path",{d:r,stroke:"black","stroke-width":1,fill:"#FFFFFF"}),i=new DiamondModel,i._d=r,f=new ShapeView(u,i),e=new DiamondController(this.mouseController,f,i),{el:u,model:i,view:f,controller:e}}}class ToolboxLineController extends ToolboxShapeController{constructor(n,t,i){super(n,t,i)}createElementAt(n,t){var u=n-30,f=t-30,e=n+30,o=t+30,r=Helpers.createElement("g",{}),i,s,h;return r.appendChild(Helpers.createElement("line",{x1:u,y1:f,x2:e,y2:o,"stroke-width":20,stroke:"black","stroke-opacity":"0","fill-opacity":"0"})),r.appendChild(Helpers.createElement("line",{x1:u,y1:f,x2:e,y2:o,fill:"#FFFFFF",stroke:"black","stroke-width":1})),i=new LineModel,i._x1=u,i._y1=f,i._x2=e,i._y2=o,s=new LineView(r,i),h=new LineController(this.mouseController,s,i),{el:r,model:i,view:s,controller:h}}}class ToolboxTextController extends ToolboxShapeController{constructor(n,t,i){super(n,t,i)}createElementAt(n,t){var r=Helpers.createElement("text",{x:n,y:t,"font-size":12,"font-family":"Verdana"}),i,u,f;return r.innerHTML=Constants.DEFAULT_TEXT,i=new TextModel,i._x=n,i._y=t,i._text=Constants.DEFAULT_TEXT,u=new TextView(r,i),f=new TextController(this.mouseController,u,i),{el:r,model:i,view:u,controller:f}}}