ngx-diagrams
Version:
> Light Weight, Modular, Typed Diagram Engine for Angular
16 lines • 70.8 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/common"),require("@angular/core"),require("rxjs"),require("rxjs/operators"),require("paths-js/path"),require("pathfinding"),require("dagre")):"function"==typeof define&&define.amd?define("ngx-diagrams",["exports","@angular/common","@angular/core","rxjs","rxjs/operators","paths-js/path","pathfinding","dagre"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["ngx-diagrams"]={},t.ng.common,t.ng.core,t.rxjs,t.rxjs.operators,t.Path,t.pathfinding,t.dagre)}(this,(function(t,e,n,o,r,i,s,a){"use strict";function u(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var c=u(i),l=function(t,e){return(l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function d(t,e){function n(){this.constructor=t}l(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function p(t,e,n,o){var r,i=arguments.length,s=i<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,o);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(s=(i<3?r(s):i>3?r(e,n,s):r(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s}function h(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}Object.create;function g(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],o=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function f(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,r,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)s.push(o.value)}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s}function y(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(f(arguments[e]));return t}Object.create;var m,v=function(t,e){this.mouseX=t,this.mouseY=e,this.ms=(new Date).getTime()},P=function(t){function e(e,n,o){var r=t.call(this,e,n)||this;return r.initialOffsetX=o.getOffsetX(),r.initialOffsetY=o.getOffsetY(),r}return d(e,t),e}(v),x=function(t){function e(e,n){var o=t.call(this,e,n)||this;return o.mouseX2=e,o.mouseY2=n,o}return d(e,t),e.prototype.getBoxDimensions=function(){return this.dimensions={left:this.mouseX2>this.mouseX?this.mouseX:this.mouseX2,top:this.mouseY2>this.mouseY?this.mouseY:this.mouseY2,width:Math.abs(this.mouseX2-this.mouseX),height:Math.abs(this.mouseY2-this.mouseY),right:this.mouseX2<this.mouseX?this.mouseX:this.mouseX2,bottom:this.mouseY2<this.mouseY?this.mouseY:this.mouseY2},this.dimensions},e.prototype.containsElement=function(t,e){var n=t.x,o=t.y,r=e.getZoomLevel()/100,i=this.getBoxDimensions();return n*r+e.getOffsetX()>i.left&&n*r+e.getOffsetX()<i.right&&o*r+e.getOffsetY()>i.top&&o*r+e.getOffsetY()<i.bottom},e}(v),L=10,M=function(){function t(t,e){void 0===e&&(e=s.Heuristic.manhattan),this.diagramEngine=t,this.pathFinderInstance=new s.AStarFinder({heuristic:e,diagonalMovement:s.DiagonalMovement.Always,weight:0})}return t.prototype.calculateDirectPath=function(t,e){var n=this.diagramEngine.getCanvasMatrix(),o=new s.Grid(n),r=this.diagramEngine.translateRoutingX(Math.floor(t.x/L)),i=this.diagramEngine.translateRoutingX(Math.floor(e.x/L)),a=this.diagramEngine.translateRoutingX(Math.floor(t.y/L)),u=this.diagramEngine.translateRoutingX(Math.floor(e.y/L));return this.pathFinderInstance.findPath(r,a,i,u,o)},t.prototype.calculateLinkStartEndCoords=function(t,e){var n=e.findIndex((function(e){return 0===t[e[1]][e[0]]})),o=e.length-1-e.slice().reverse().findIndex((function(e){return 0===t[e[1]][e[0]]}));if(-1!==n&&-1!==o){var r=e.slice(0,n),i=e.slice(o);return{start:{x:e[n][0],y:e[n][1]},end:{x:e[o][0],y:e[o][1]},pathToStart:r,pathToEnd:i}}},t.prototype.calculateDynamicPath=function(t,e,n,o,r){var i=this,a=new s.Grid(t),u=this.pathFinderInstance.findPath(e.x,e.y,n.x,n.y,a),c=o.concat(u,r).map((function(t){return[i.diagramEngine.translateRoutingX(t[0],!0),i.diagramEngine.translateRoutingY(t[1],!0)]}));return s.Util.compressPath(c)},t}();function b(){return t.__DEV__}function k(e,n){void 0===n&&(n=t.LOG_LEVEL.LOG);for(var o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];b()&&t.__LOG__===n&&(t.__LOG__===t.LOG_LEVEL.ERROR&&console.error.apply(console,y([e],o)),console.log.apply(console,y([e],o)))}function $(e,n){void 0===n&&(n=t.LOG_LEVEL.LOG);for(var o=[],i=2;i<arguments.length;i++)o[i-2]=arguments[i];return function(t){return b()?t.pipe(r.tap((function(t){return k.apply(void 0,y([e,n,t],o))}))):t}}function w(t,e,n){return void 0===e&&(e=1),void 0===n&&(n=""),function(o){return o.pipe(r.distinctUntilChanged((function(t,e){return!(t instanceof Map||e instanceof Map)&&t===e})),r.shareReplay(e),$(n),r.takeUntil(t))}}function C(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}))}function E(t){return Array.isArray(t)}function F(t){return"string"==typeof t}function O(t){return null==t}function S(t){return O(t)?[]:Array.isArray(t)?t:[t]}function D(t){return!t||!E(t)||0===t.length}function R(t){var e=[];for(var n in t)e.push([n,t[n]]);return e}function A(t){return y(new Set(t))}function N(t,e,n){void 0===n&&(n=0);var o=Math.abs(t.x-e.x)>Math.abs(t.y-e.y),r=o?n:0,i=o?0:n;return"M"+t.x+","+t.y+" C "+(t.x+r)+","+(t.y+i)+"\n "+(e.x-r)+","+(e.y-i)+" "+e.x+","+e.y}function T(t){var e=c.default();return e=e.moveto(t[0][0]*L,t[0][1]*L),t.slice(1).forEach((function(t){e=e.lineto(t[0]*L,t[1]*L)})),e.print()}function j(t,e,n){var o=n.value;return n.value=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(!this.ngZone)throw new Error("Class with 'OutsideZone' decorator should have 'ngZone' class property with 'NgZone' class.");return this.ngZone.runOutsideAngular((function(){return o.call.apply(o,y([t],e))}))},n}(m=t.LOG_LEVEL||(t.LOG_LEVEL={}))[m.LOG=0]="LOG",m[m.ERROR=1]="ERROR",t.__DEV__=!0,t.__LOG__=t.LOG_LEVEL.ERROR;var X=function(){function t(t,e){this.stream$=new o.BehaviorSubject(t),this.value$=e?this.stream$.pipe(e):this.stream$.asObservable()}return Object.defineProperty(t.prototype,"value",{get:function(){return this.stream$.getValue()},enumerable:!1,configurable:!0}),t.prototype.set=function(t){return this.stream$.next(t),this},t.prototype.emit=function(){this.stream$.next(this.value)},t.prototype.select=function(t){var e=t||function(t){return t};return this.value$.pipe(r.map((function(t){return e(t)})),r.distinctUntilChanged())},t}();function Y(t,e){return new X(t,e)}var _=function(t){function e(e,n){return t.call(this,e,n)||this}return d(e,t),e.prototype.destroy=function(){this.clear(),this.stream$=null,this.value$=null},e.prototype.clear=function(t){return void 0===t&&(t=!0),t&&this.forEach((function(t){return t.destroy()})),this.value.clear(),this},e.prototype.get=function(t){return this.value.get(t)},e.prototype.has=function(t){return this.value.has(t)},e.prototype.add=function(t){return this.value.set(t.id,t),this},e.prototype.addMany=function(t){var e,n;try{for(var o=g(t),r=o.next();!r.done;r=o.next()){var i=r.value;this.add(i)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return this},e.prototype.remove=function(t,e){var n;return void 0===e&&(e=!0),e&&(null===(n=this.value.get(t))||void 0===n||n.destroy()),this.value.delete(t),this},e.prototype.array=function(){return Array.from(this.value.values())},e.prototype.array$=function(){return this.select((function(t){return Array.from(t.values())}))},e.prototype.forEach=function(t){this.value.forEach(t)},e.prototype.map=function(t){return this.array().map(t)},e}(X);function I(t,e){return void 0===t&&(t=[]),E(t)?new _(new Map(t),e):new _(new Map(R(t)),e)}var Z=function(t,e){var n=this;this.id=C(),this.entity=t,this.entityId=t.id,this.firing=!0,this.stopPropagation=function(){return n.firing=!1},this.propogate=e?e.propagate:null},W=function(t){function e(e,n){void 0===n&&(n=!1);var o=t.call(this,e)||this;return o.locked=n,o}return d(e,t),e}(Z),V=function(t){function e(e,n){var o=t.call(this,e)||this;return o.parent=n,o}return d(e,t),e}(Z),H=function(t){function e(e,n){var o=t.call(this,e)||this;return o.isSelected=n,o}return d(e,t),e}(Z),z=function(t){function e(e,n){void 0===n&&(n=!1);var o=t.call(this,e)||this;return o.isPainted=n,o}return d(e,t),e}(Z),B=function(){function e(t,e){void 0===e&&(e=""),this.destroyed$=new o.Subject,this.locked$=Y(!1,this.entityPipe("locked")),this._id=t||C(),this._logPrefix=""+e}return Object.defineProperty(e.prototype,"id",{get:function(){return this._id},set:function(t){this._id=t},enumerable:!1,configurable:!0}),e.prototype.log=function(e){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];k.apply(void 0,y([this._logPrefix+" "+e+": ",t.LOG_LEVEL.LOG],n))},e.prototype.withLog=function(e){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];return $.apply(void 0,y([this._logPrefix+" "+e+": ",t.LOG_LEVEL.LOG],n))},e.prototype.entityPipe=function(t){return void 0===t&&(t=""),w(this.onEntityDestroy(),0,this._logPrefix+": "+t)},e.prototype.getLocked=function(){return this.locked$.value},e.prototype.setLocked=function(t){void 0===t&&(t=!0),this.locked$.set(t).emit()},e.prototype.doClone=function(t,e){void 0===t&&(t={})},e.prototype.clone=function(t){if(void 0===t&&(t={}),t[this.id])return t[this.id];var e=Object.assign({},this);return e.id=C(),t[this.id]=e,this.doClone(t,e),e},e.prototype.serialize=function(){return{id:this.id,locked:this.getLocked()}},e.prototype.lockChanges=function(){var t=this;return this.locked$.select((function(e){return new W(t,e)}))},e.prototype.destroy=function(){this.log("entity destroyed"),this.destroyed$.next(),this.destroyed$.complete()},e.prototype.onEntityDestroy=function(){var t=this;return this.destroyed$.pipe(r.map((function(e){return new Z(t,e)})))},e}(),G=function(t){function e(e,n,o){void 0===o&&(o="[Base]");var r=t.call(this,n,o)||this;return r.parent$=Y(null,r.entityPipe("ParentsChange")),r.selected$=Y(!1,r.entityPipe("SelectedChange")),r.hovered$=Y(!1,r.entityPipe("HoveredChange")),r.painted$=Y(!1,r.entityPipe("PaintedChange")),r._type=e,r}return d(e,t),e.prototype.serialize=function(){return Object.assign(Object.assign({},t.prototype.serialize.call(this)),{type:this.getType()})},e.prototype.getParent=function(){return this.parent$.value},e.prototype.setParent=function(t){this.parent$.set(t).emit()},e.prototype.parentChanges=function(){var t=this;return this.parent$.select((function(e){return new V(t,e)}))},e.prototype.getPainted=function(){return this.painted$.value},e.prototype.setPainted=function(t){void 0===t&&(t=!0),this.painted$.set(t).emit()},e.prototype.getHovered=function(){return this.hovered$.value},e.prototype.setHovered=function(t){void 0===t&&(t=!0),this.hovered$.set(t).emit()},e.prototype.selectHovered=function(){return this.hovered$.value$},e.prototype.paintChanges=function(){var t=this;return this.painted$.select((function(e){return new z(t,e)}))},e.prototype.getType=function(){return this._type},e.prototype.getSelected=function(){return this.selected$.value},e.prototype.selectSelected=function(){return this.selected$.select()},e.prototype.setSelected=function(t){void 0===t&&(t=!0),this.selected$.set(t).emit()},e.prototype.selectionChanges=function(){var t=this;return this.selected$.select((function(e){return new H(t,e)}))},e.prototype.getSelectedEntities=function(){return this.getSelected()?[this]:[]},e}(B),U=function(t){function e(e,n,o,r){void 0===r&&(r="[Point]");var i=t.call(this,e.getType(),o,r)||this;return i.coords$=Y(n,i.entityPipe("coords")),i.setParent(e),i}return d(e,t),e.prototype.serialize=function(){return Object.assign(Object.assign({},t.prototype.serialize.call(this)),{coords:this.getCoords()})},e.prototype.isConnectedToPort=function(){return null!==this.getParent().getPortForPoint(this)},e.prototype.getLink=function(){return this.getParent()},e.prototype.destroy=function(){this.getParent&&this.getParent().removePoint(this),t.prototype.destroy.call(this)},e.prototype.setCoords=function(t){this.coords$.set(Object.assign(Object.assign({},this.getCoords()),t)).emit()},e.prototype.selectCoords=function(){return this.coords$.value$},e.prototype.getCoords=function(){return this.coords$.value},e.prototype.selectX=function(){return this.coords$.select((function(t){return t.x}))},e.prototype.selectY=function(){return this.coords$.select((function(t){return t.y}))},e}(G),q=function(t){function e(e,n,o){void 0===e&&(e="default"),void 0===o&&(o="[Link]");var r=t.call(this,e,n,o)||this;return r.label$=Y(null,r.entityPipe("label")),r.points=[new U(r,{x:0,y:0}),new U(r,{x:0,y:0})],r.extras={},r.sourcePort=null,r.targetPort=null,r}return d(e,t),e.prototype.serialize=function(){var e,n=this.points.map((function(t){return t.serialize()})),o=null===(e=this.getLabel())||void 0===e?void 0:e.serialize();return Object.assign(Object.assign({},t.prototype.serialize.call(this)),{name:this.getName(),sourcePort:this.getSourcePort().id,targetPort:this.getTargetPort().id,extras:this.getExtras(),points:n,label:o})},e.prototype.setName=function(t){this.name=t},e.prototype.getName=function(){return this.name},e.prototype.getExtras=function(){return this.extras},e.prototype.setExtras=function(t){this.extras=t},e.prototype.destroy=function(){this.sourcePort&&this.sourcePort.removeLink(this),this.targetPort&&this.targetPort.removeLink(this),t.prototype.destroy.call(this)},e.prototype.doClone=function(t,e){void 0===t&&(t={}),e.setPoints(this.getPoints().map((function(e){return e.clone(t)}))),this.sourcePort&&e.setSourcePort(this.sourcePort.clone(t)),this.targetPort&&e.setTargetPort(this.targetPort.clone(t))},e.prototype.isLastPoint=function(t){return this.getPointIndex(t)===this.points.length-1},e.prototype.getPointIndex=function(t){return this.points.indexOf(t)},e.prototype.getPointModel=function(t){var e,n;try{for(var o=g(this.points),r=o.next();!r.done;r=o.next()){var i=r.value;if(i.id===t)return i}}catch(t){e={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return null},e.prototype.getPortForPoint=function(t){return null!==this.sourcePort&&this.getFirstPoint().id===t.id?this.sourcePort:null!==this.targetPort&&this.getLastPoint().id===t.id?this.targetPort:null},e.prototype.getPointForPort=function(t){return null!==this.sourcePort&&this.sourcePort.id===t.id?this.getFirstPoint():null!==this.targetPort&&this.targetPort.id===t.id?this.getLastPoint():null},e.prototype.getFirstPoint=function(){return this.points[0]},e.prototype.getLastPoint=function(){return this.points[this.points.length-1]},e.prototype.setSourcePort=function(t){null!==t&&t.addLink(this),null!==this.sourcePort&&this.sourcePort.removeLink(this),this.sourcePort=t},e.prototype.getSourcePort=function(){return this.sourcePort},e.prototype.getTargetPort=function(){return this.targetPort},e.prototype.setTargetPort=function(t){null!==t&&t.addLink(this),null!==this.targetPort&&this.targetPort.removeLink(this),this.targetPort=t},e.prototype.point=function(t){var e=t.x,n=t.y;return this.addPoint(this.generatePoint({x:e,y:n}))},e.prototype.getPoints=function(){return this.points},e.prototype.setPoints=function(t){var e=this;t.forEach((function(t){t.setParent(e)})),this.points=t},e.prototype.setLabel=function(t){t.setParent(this),this.label$.set(t).emit()},e.prototype.selectLabel=function(){return this.label$.value$},e.prototype.getLabel=function(){return this.label$.value},e.prototype.resetLabel=function(){var t=this.getLabel();t&&(t.setParent(null),t.setPainted(!1)),this.setLabel(null)},e.prototype.removePoint=function(t){this.points.splice(this.getPointIndex(t),1)},e.prototype.removePointsBefore=function(t){this.points.splice(0,this.getPointIndex(t))},e.prototype.removePointsAfter=function(t){this.points.splice(this.getPointIndex(t)+1)},e.prototype.removeMiddlePoints=function(){this.points.length>2&&this.points.splice(0,this.points.length-2)},e.prototype.addPoint=function(t,e){return void 0===e&&(e=1),t.setParent(this),t.setLocked(this.getLocked()),this.points.splice(e,0,t),t},e.prototype.generatePoint=function(t){var e=t.x,n=void 0===e?0:e,o=t.y;return new U(this,{x:n,y:void 0===o?0:o})},e.prototype.setLocked=function(e){void 0===e&&(e=!0),t.prototype.setLocked.call(this,e),this.points.forEach((function(t){return t.setLocked(e)}))},e}(G),K=function(t){function e(e,n,o){var r=t.call(this,e,n)||this;r.moved=!1;var i=o.getDiagramModel().getSelectedItems();return i=i.filter((function(t){return!(o.isModelLocked(t)||t instanceof q)})),r.selectionModels=i.map((function(t){var e=t.getCoords();return{model:t,initialX:e.x,initialY:e.y}})),r}return d(e,t),e}(v),J=function(t){function e(e,n,o){var r=t.call(this,e,n)||this;return r.sourcePort=o.getSourcePort(),r.targetPort=o.getTargetPort(),r.link=o,r}return d(e,t),e.prototype.getOutPortNode=function(){return this.sourcePort.getParent()},e.prototype.getInPortNode=function(){return this.targetPort.getParent()},e}(v),Q=function(t){function e(e,n,o){var r=t.call(this,e,n)||this;return r.sourcePort=o.getSourcePort(),r.link=o,r}return d(e,t),e.prototype.getOutPortNode=function(){return this.sourcePort.getParent()},e}(v),tt=function(t){function e(e,n,o){var r=t.call(this,e,n)||this;return r.sourcePort=o.getSourcePort(),r.link=o,r}return d(e,t),e.prototype.getOutPortNode=function(){return this.sourcePort.getParent()},e}(v),et=function(t){function e(e,n,o,r,i,s,a,u){void 0===e&&(e="default"),void 0===o&&(o={}),void 0===r&&(r=0),void 0===i&&(i=0),void 0===s&&(s=0),void 0===a&&(a=0),void 0===u&&(u="[Node]");var c=t.call(this,e,n,u)||this;return c.diagramEngine$=Y(null,c.entityPipe("diagramEngine")),c.extras$=Y({},c.entityPipe("extras")),c.ports$=I([],c.entityPipe("ports")),c.coords$=Y({x:0,y:0},c.entityPipe("coords")),c.dimensions$=Y({width:0,height:0},c.entityPipe("dimensions")),c.setExtras(o),c.setDimensions({width:s,height:a}),c.setCoords({x:r,y:i}),c}return d(e,t),e.prototype.getDiagramEngine=function(){return this.diagramEngine$.value},e.prototype.selectDiagramEngine=function(){return this.diagramEngine$.value$},e.prototype.setDiagramEngine=function(t){this.diagramEngine$.set(t).emit()},e.prototype.getCoords=function(){return this.coords$.value},e.prototype.setCoords=function(t){var e=t.x,n=t.y,o=this.getCoords(),r=o.x,i=o.y;this.getPorts().forEach((function(t){t.getLinks().forEach((function(o){var s=o.getPointForPort(t),a=s.getCoords(),u=a.x,c=a.y;s.setCoords({x:u+e-r,y:c+n-i})}))})),this.coords$.set({x:e,y:n}).emit()},e.prototype.serialize=function(){var e=this.getPortsArray().map((function(t){return t.serialize()}));return Object.assign(Object.assign(Object.assign(Object.assign({},t.prototype.serialize.call(this)),{nodeType:this.getType(),extras:this.getExtras(),width:this.getWidth(),height:this.getHeight()}),this.getCoords()),{ports:e})},e.prototype.getSelectedEntities=function(){var e=t.prototype.getSelectedEntities.call(this);return this.getSelected()&&this.getPorts().forEach((function(t){var n=t.getLinksArray().map((function(e){return e.getPointForPort(t)}));e=e.concat(n)})),this.log("selectedEntities",e),e},e.prototype.coordsChanges=function(){return this.coords$.value$},e.prototype.selectCoords=function(){return this.coords$.value$},e.prototype.selectX=function(){return this.coords$.select((function(t){return t.x}))},e.prototype.selectY=function(){return this.coords$.select((function(t){return t.y}))},e.prototype.addPort=function(t){return t.setParent(this),this.ports$.add(t).emit(),t},e.prototype.removePort=function(t){var e="string"==typeof t?t:t.id;return this.ports$.remove(e).emit(),e},e.prototype.getPort=function(t){return this.ports$.get(t)},e.prototype.selectPorts=function(t){return this.ports$.array$().pipe(this.withLog("selectPorts"))},e.prototype.getPorts=function(){return this.ports$.value},e.prototype.getPortsArray=function(){return this.ports$.array()},e.prototype.setDimensions=function(t){this.dimensions$.set(Object.assign(Object.assign({},this.getDimensions()),t)).emit()},e.prototype.getDimensions=function(){return this.dimensions$.value},e.prototype.dimensionChanges=function(){return this.dimensions$.select()},e.prototype.getHeight=function(){return this.getDimensions().height},e.prototype.setHeight=function(t){return this.setDimensions({height:t})},e.prototype.getWidth=function(){return this.getDimensions().width},e.prototype.setWidth=function(t){return this.setDimensions({width:t})},e.prototype.selectWidth=function(){return this.dimensions$.select((function(t){return t.width})).pipe(this.withLog("selectWidth"))},e.prototype.selectHeight=function(){return this.dimensions$.select((function(t){return t.height})).pipe(this.withLog("selectHeight"))},e.prototype.setExtras=function(t){this.extras$.set(t).emit()},e.prototype.getExtras=function(){return this.extras$.value},e.prototype.selectExtras=function(t){return this.extras$.select(t)},e.prototype.destroy=function(){t.prototype.destroy.call(this),this.removeAllPorts()},e.prototype.removeAllPorts=function(){this.ports$.clear().emit()},e}(G),nt=function(t){function e(e,n,o,r,i,s,a){void 0===s&&(s=!0),void 0===a&&(a="[Port]");var u=t.call(this,n,o,a)||this;return u.links$=I([],u.entityPipe("links")),u.x$=Y(0,u.entityPipe("x")),u.y$=Y(0,u.entityPipe("y")),u.width$=Y(0,u.entityPipe("y")),u.height$=Y(0,u.entityPipe("y")),u.magnetic$=Y(!0,u.entityPipe("magnetic")),u.canCreateLinks$=Y(!0,u.entityPipe("magnetic")),u.name=e,u.maximumLinks=r,u.linkType=i,u.setMagnetic(s),u}return d(e,t),e.prototype.serialize=function(){return Object.assign(Object.assign(Object.assign({},t.prototype.serialize.call(this)),{name:this.getName(),linkType:this.getLinkType(),maximumLinks:this.getMaximumLinks(),type:this.getType(),magnetic:this.getMagnetic(),height:this.getHeight(),width:this.getWidth(),canCreateLinks:this.getCanCreateLinks()}),this.getCoords())},e.prototype.getNode=function(){return this.getParent()},e.prototype.getName=function(){return this.name},e.prototype.getCanCreateLinks=function(){var t=this.getLinks().size;return!(this.maximumLinks&&t>=this.maximumLinks)&&this.canCreateLinks$.value},e.prototype.getCoords=function(){return{x:this.getX(),y:this.getY()}},e.prototype.selectCanCreateLinks=function(){return this.canCreateLinks$.value$},e.prototype.setCanCreateLinks=function(t){this.canCreateLinks$.set(t).emit()},e.prototype.getMagnetic=function(){return this.magnetic$.value},e.prototype.selectMagnetic=function(){return this.magnetic$.value$},e.prototype.setMagnetic=function(t){this.magnetic$.set(t).emit()},e.prototype.selectX=function(){return this.x$.value$},e.prototype.selectY=function(){return this.y$.value$},e.prototype.getY=function(){return this.y$.value},e.prototype.getX=function(){return this.x$.value},e.prototype.getHeight=function(){return this.height$.value},e.prototype.getWidth=function(){return this.width$.value},e.prototype.getMaximumLinks=function(){return this.maximumLinks},e.prototype.setMaximumLinks=function(t){this.maximumLinks=t},e.prototype.getLinkType=function(){return this.linkType},e.prototype.setLinkType=function(t){this.linkType=t},e.prototype.removeLink=function(t){var e=F(t)?t:t.id;this.links$.remove(e,!1).emit()},e.prototype.addLink=function(t){this.links$.add(t).emit()},e.prototype.getLinks=function(){return this.links$.value},e.prototype.getLinksArray=function(){return this.links$.array()},e.prototype.selectLinks=function(){return this.links$.value$},e.prototype.updateCoords=function(t){var e=t.x,n=t.y,o=t.width,r=t.height;this.x$.set(e).emit(),this.y$.set(n).emit(),this.width$.set(o).emit(),this.height$.set(r).emit()},e.prototype.canLinkToPort=function(t){return!0},e.prototype.isLocked=function(){return t.prototype.getLocked.call(this)},e.prototype.createLinkModel=function(){if(this.getCanCreateLinks())return new q},e.prototype.destroy=function(){t.prototype.destroy.call(this),this.links$.clear().emit()},e}(G),ot=function(){function t(t,e,r,i,s){this.document=t,this.ngZone=e,this.renderer=r,this.cdRef=i,this.elRef=s,this.allowCanvasZoom=!0,this.allowCanvasTranslation=!0,this.inverseZoom=!0,this.allowLooseLinks=!0,this.maxZoomOut=null,this.maxZoomIn=null,this.portMagneticRadius=30,this.smartRouting=!1,this.actionStartedFiring=new n.EventEmitter,this.actionStillFiring=new n.EventEmitter,this.actionStoppedFiring=new n.EventEmitter,this.action$=new o.BehaviorSubject(null),this.nodesRendered$=new o.BehaviorSubject(!1),this.destroyed$=new o.ReplaySubject(1)}return Object.defineProperty(t.prototype,"host",{get:function(){return this.elRef.nativeElement},enumerable:!1,configurable:!0}),t.prototype.ngAfterViewInit=function(){this.diagramModel&&(this.initNodes(),this.initLinks(),this.initSubs())},t.prototype.ngOnDestroy=function(){this.destroyed$.next(!0),this.destroyed$.complete()},t.prototype.fireAction=function(){this.action$.value&&this.actionStillFiring.emit(this.action$.value)},t.prototype.stopFiringAction=function(t){t||this.actionStoppedFiring.emit(this.action$.value),this.action$.next(null)},t.prototype.startFiringAction=function(t){this.action$.next(t),this.actionStartedFiring.emit(t)},t.prototype.selectAction=function(){return this.action$},t.prototype.shouldDrawSelectionBox=function(){var t=this.action$.getValue();return t instanceof x&&(t.getBoxDimensions(),!0)},t.prototype.getMouseElement=function(t){var e=t.target,n=e.closest("[data-portid]");if(n){var o=e.closest("[data-nodeid]");return{model:this.diagramModel.getNode(o.getAttribute("data-nodeid")).getPort(n.getAttribute("data-portid")),element:n}}return(n=e.closest("[data-pointid]"))?{model:this.diagramModel.getLink(n.getAttribute("data-linkid")).getPointModel(n.getAttribute("data-pointid")),element:n}:(n=e.closest("[data-linkid]"))?{model:this.diagramModel.getLink(n.getAttribute("data-linkid")),element:n}:(n=e.closest("[data-nodeid]"))?{model:this.diagramModel.getNode(n.getAttribute("data-nodeid")),element:n}:null},t.prototype.onMouseUp=function(t){var e=this,n=this.diagramModel.getDiagramEngine(),o=this.action$.getValue();if(o instanceof K){var r=this.getMouseElement(t);o.selectionModels.forEach((function(o){if(o&&o.model instanceof U){var i;if(o.magnet?i=o.magnet:r&&r.model&&(i=r.model),i instanceof nt&&!n.isModelLocked(i)){var s=o.model.getLink();if(null!==s.getTargetPort())if(s.getTargetPort()!==i&&s.getSourcePort()!==i){var a=s.getTargetPort(),u=s.clone({});u.setSourcePort(i),u.setTargetPort(a),s.setTargetPort(i),a.removeLink(s),u.removePointsBefore(u.getPoints()[s.getPointIndex(o.model)]),s.removePointsAfter(o.model),n.getDiagramModel().addLink(u)}else s.getTargetPort()===i?s.removePointsAfter(o.model):s.getSourcePort()===i&&s.removePointsBefore(o.model);else{s.setTargetPort(i);a=s.getTargetPort();var c=s.getSourcePort();a.id!==c.id&&c.canLinkToPort(a)&&e.startFiringAction(new J(t.clientX,t.clientY,s))}}o.magnet=void 0}})),this.allowLooseLinks||o.selectionModels.forEach((function(n){if(n&&n.model instanceof U){var o=n.model.getLink();null!==o.getSourcePort()&&null!==o.getTargetPort()||(o.destroy(),e.startFiringAction(new Q(t.clientX,t.clientY,o)))}})),o.selectionModels.forEach((function(n){if(n&&n.model instanceof U){var o=n.model.getLink(),r=o.getSourcePort(),i=o.getTargetPort();null!==r&&null!==i&&(r.canLinkToPort(i)?i.getLinksArray().some((function(t){return t!=t&&(t.getSourcePort()===r||t.getTargetPort()===r)}))&&o.destroy():(o.destroy(),e.startFiringAction(new tt(t.clientX,t.clientY,o))))}})),this.stopFiringAction()}else this.stopFiringAction();this.action$.next(null)},t.prototype.onMouseMove=function(t){var e=this,n=this.action$.getValue();if(null!=n){if(n instanceof x){var o=this.diagramModel.getDiagramEngine().getRelativePoint(t.clientX,t.clientY);return this.diagramModel.getNodes().forEach((function(t){n.containsElement(t.getCoords(),e.diagramModel)?t.setSelected():t.setSelected(!1)})),this.diagramModel.getLinks().forEach((function(t){var o=!0;t.getPoints().forEach((function(t){n.containsElement(t.getCoords(),e.diagramModel)?t.setSelected():(t.setSelected(!1),o=!1)})),o&&t.setSelected()})),n.mouseX2=o.x,n.mouseY2=o.y,this.fireAction(),void this.action$.next(n)}if(n instanceof K){var r={x:t.clientX-n.mouseX,y:t.clientY-n.mouseY},i=this.diagramModel.getZoomLevel()/100;n.selectionModels.forEach((function(t){var n,o;if(t.magnet=void 0,t.model instanceof et||t.model instanceof U&&!t.model.isConnectedToPort()){var s={x:t.initialX+r.x/i,y:t.initialY+r.y/i},a=e.diagramModel.getGridPosition(s);if(t.model instanceof U&&e.portMagneticRadius){var u=e.diagramModel.getAllPorts({filter:function(t){return t.getMagnetic()}});try{for(var c=g(u.values()),l=c.next();!l.done;l=c.next()){var d=l.value,p=d.getCoords();if(Math.hypot(p.x-s.x,p.y-s.y)<=e.portMagneticRadius){var h=e.diagramModel.getDiagramEngine().getPortCenter(d);return t.model.setCoords(h),void(t.magnet=d)}}}catch(t){n={error:t}}finally{try{l&&!l.done&&(o=c.return)&&o.call(c)}finally{if(n)throw n.error}}}t.model.setCoords(a),t.model instanceof et&&t.model.getPorts().forEach((function(t){var n=e.diagramModel.getDiagramEngine().getPortCoords(t);t.updateCoords(n)})),e.diagramModel.getDiagramEngine().getSmartRouting()&&setTimeout((function(){e.diagramModel.getDiagramEngine().calculateRoutingMatrix()}),1)}else if(t.model instanceof U){s=e.diagramModel.getGridPosition({x:r.x/i,y:r.y/i});t.model.setCoords({x:t.initialX+s.x,y:t.initialY+s.y})}})),this.fireAction()}else n instanceof P&&this.allowCanvasTranslation&&(this.diagramModel.setOffset(n.initialOffsetX+(t.clientX-n.mouseX),n.initialOffsetY+(t.clientY-n.mouseY)),this.fireAction())}},t.prototype.onMouseDown=function(t){if(3!==t.button){var e=this.getMouseElement(t);if(null===e)if(t.shiftKey){var n=this.diagramModel.getDiagramEngine().getRelativePoint(t.clientX,t.clientY);this.startFiringAction(new x(n.x,n.y))}else this.diagramModel.clearSelection(),this.startFiringAction(new P(t.clientX,t.clientY,this.diagramModel));else if(e.model instanceof nt)if(!e.model.isLocked()&&e.model.getCanCreateLinks()){n=this.diagramModel.getDiagramEngine().getRelativeMousePoint(t);var o=e.model,r=o.createLinkModel();r&&(r.setSourcePort(o),r.removeMiddlePoints(),r.getSourcePort()!==o&&r.setSourcePort(o),r.setTargetPort(null),r.getFirstPoint().setCoords(n),r.getLastPoint().setCoords(n),this.diagramModel.clearSelection(),r.getLastPoint().setSelected(),this.diagramModel.addLink(r),this.startFiringAction(new K(t.clientX,t.clientY,this.diagramModel.getDiagramEngine())))}else this.diagramModel.clearSelection();else e.model instanceof U&&e.model.isConnectedToPort()?this.diagramModel.clearSelection():(t.shiftKey||e.model.getSelected()||this.diagramModel.clearSelection(),e.model.setSelected(),this.startFiringAction(new K(t.clientX,t.clientY,this.diagramModel.getDiagramEngine())));this.createMouseListeners()}},t.prototype.onMouseWheel=function(t){if(this.allowCanvasZoom){t.preventDefault(),t.stopPropagation();var e=this.diagramModel.getZoomLevel(),n=e/100,o=this.inverseZoom?-t.deltaY:t.deltaY;if(t.ctrlKey&&o%1!=0?o/=3:o/=60,e+o>10){var r=e+o;this.diagramModel.setZoomLevel(r)}var i=this.diagramModel.getZoomLevel()/100,s=t.currentTarget.getBoundingClientRect(),a=s.width,u=s.height,c=a*i-a*n,l=u*i-u*n,d=t.clientX-s.left,p=t.clientY-s.top,h=(d-this.diagramModel.getOffsetX())/n/a,g=(p-this.diagramModel.getOffsetY())/n/u,f=this.diagramModel.getOffsetX()-c*h,y=this.diagramModel.getOffsetY()-l*g;this.diagramModel.setOffset(f,y)}},t.prototype.setLayerStyles=function(t,e,n){var o=this.getNodesLayer(),r=this.getLinksLayer(),i="transform",s="translate("+t+"px, "+e+"px) scale("+n/100+")";this.renderer.setStyle(o,i,s),this.renderer.setStyle(r,i,s)},t.prototype.initNodes=function(){var t=this;this.nodes$=this.diagramModel.selectNodes(),this.diagramModel.getDiagramEngine().setCanvas(this.canvas.nativeElement),this.diagramModel.getDiagramEngine().setSmartRoutingStatus(this.smartRouting),this.diagramModel.setMaxZoomIn(this.maxZoomIn),this.diagramModel.setMaxZoomOut(this.maxZoomOut),this.nodes$.pipe(r.takeUntil(this.destroyed$)).subscribe((function(e){var n,o;t.nodesRendered$.next(!1);try{for(var r=g(e.values()),i=r.next();!i.done;i=r.next()){var s=i.value;s.getPainted()||(t.diagramModel.getDiagramEngine().generateWidgetForNode(s,t.nodesLayer),t.cdRef.detectChanges())}}catch(t){n={error:t}}finally{try{i&&!i.done&&(o=r.return)&&o.call(r)}finally{if(n)throw n.error}}t.nodesRendered$.next(!0)}))},t.prototype.initLinks=function(){var t=this;this.links$=this.diagramModel.selectLinks(),o.combineLatest([this.nodesRendered$,this.links$]).pipe(r.filter((function(t){return!!f(t,1)[0]})),r.takeUntil(this.destroyed$)).subscribe((function(e){var n,o,r=f(e,2)[1];try{for(var i=g(r.values()),s=i.next();!s.done;s=i.next()){var a=s.value;if(!a.getPainted()&&a.getSourcePort().getPainted()){if(null!==a.getSourcePort()){var u=t.diagramModel.getDiagramEngine().getPortCenter(a.getSourcePort());a.getPoints()[0].setCoords(u);var c=t.diagramModel.getDiagramEngine().getPortCoords(a.getSourcePort());a.getSourcePort().updateCoords(c)}if(null!==a.getTargetPort()){u=t.diagramModel.getDiagramEngine().getPortCenter(a.getTargetPort());a.getPoints()[a.getPoints().length-1].setCoords(u);c=t.diagramModel.getDiagramEngine().getPortCoords(a.getTargetPort());a.getTargetPort().updateCoords(c)}t.diagramModel.getDiagramEngine().generateWidgetForLink(a,t.linksLayer),t.cdRef.detectChanges()}}}catch(t){n={error:t}}finally{try{s&&!s.done&&(o=i.return)&&o.call(i)}finally{if(n)throw n.error}}}))},t.prototype.initSubs=function(){var t=this;o.combineLatest([this.diagramModel.selectOffsetX(),this.diagramModel.selectOffsetY(),this.diagramModel.selectZoomLevel()]).pipe(r.tap((function(e){var n=f(e,3),o=n[0],r=n[1],i=n[2];return t.setLayerStyles(o,r,i)})),r.takeUntil(this.destroyed$)).subscribe()},t.prototype.getNodesLayer=function(){return this.host.querySelector(".ngdx-nodes-layer")},t.prototype.getLinksLayer=function(){return this.host.querySelector(".ngdx-links-layer")},t.prototype.createMouseListeners=function(){var t=this,e=o.fromEvent(this.document,"mouseup").pipe(r.tap((function(e){return t.onMouseUp(e)})),r.take(1)),n=o.fromEvent(this.document,"mousemove").pipe(r.tap((function(e){return t.onMouseMove(e)})),r.takeUntil(e));o.merge(n,e).subscribe()},t}();ot.decorators=[{type:n.Component,args:[{selector:"ngdx-diagram",template:'<div class="ngdx-diagram" #canvas (mousedown)="onMouseDown($event)" (wheel)="onMouseWheel($event)">\n\t\x3c!-- Nodes Layer --\x3e\n\t<div class="ngdx-nodes-layer">\n\t\t<ng-template #nodesLayer></ng-template>\n\t</div>\n\n\t\x3c!-- Links Layer --\x3e\n\t<div class="ngdx-links-layer">\n\t\t<ng-template #linksLayer></ng-template>\n\t</div>\n\n\t\x3c!-- Selection Box --\x3e\n\t<div\n\t\t*ngIf="shouldDrawSelectionBox() && selectAction() | async as action"\n\t\tclass="selector"\n\t\t[ngStyle]="{\n\t\t\ttop: action.dimensions.top + \'px\',\n\t\t\tleft: action.dimensions.left + \'px\',\n\t\t\twidth: action.dimensions.width + \'px\',\n\t\t\theight: action.dimensions.height + \'px\'\n\t\t}"></div>\n</div>\n',changeDetection:n.ChangeDetectionStrategy.OnPush,styles:[".ngdx-diagram{cursor:move;display:flex;flex-grow:1;overflow:hidden;position:relative}.ngdx-diagram .selector{background-color:rgba(0,192,255,.2);border:2px solid #00c0ff;position:absolute}.ngdx-diagram .ngdx-nodes-layer{z-index:150}.ngdx-diagram .ngdx-links-layer,.ngdx-diagram .ngdx-nodes-layer{bottom:0;height:100%;left:0;overflow:visible!important;pointer-events:none;position:absolute;right:0;top:0;transform-origin:0 0;width:100%}.ngdx-diagram .ngdx-links-layer{z-index:100}"]}]}],ot.ctorParameters=function(){return[{type:void 0,decorators:[{type:n.Inject,args:[e.DOCUMENT]}]},{type:n.NgZone},{type:n.Renderer2},{type:n.ChangeDetectorRef},{type:n.ElementRef}]},ot.propDecorators={diagramModel:[{type:n.Input,args:["model"]}],allowCanvasZoom:[{type:n.Input}],allowCanvasTranslation:[{type:n.Input}],inverseZoom:[{type:n.Input}],allowLooseLinks:[{type:n.Input}],maxZoomOut:[{type:n.Input}],maxZoomIn:[{type:n.Input}],portMagneticRadius:[{type:n.Input}],smartRouting:[{type:n.Input}],actionStartedFiring:[{type:n.Output}],actionStillFiring:[{type:n.Output}],actionStoppedFiring:[{type:n.Output}],nodesLayer:[{type:n.ViewChild,args:["nodesLayer",{read:n.ViewContainerRef}]}],linksLayer:[{type:n.ViewChild,args:["linksLayer",{read:n.ViewContainerRef}]}],canvas:[{type:n.ViewChild,args:["canvas",{read:n.ElementRef}]}]},p([j,h("design:type",Function),h("design:paramtypes",[MouseEvent]),h("design:returntype",void 0)],ot.prototype,"onMouseUp",null),p([j,h("design:type",Function),h("design:paramtypes",[MouseEvent]),h("design:returntype",void 0)],ot.prototype,"onMouseMove",null),p([j,h("design:type",Function),h("design:paramtypes",[MouseEvent]),h("design:returntype",void 0)],ot.prototype,"onMouseDown",null),p([j,h("design:type",Function),h("design:paramtypes",[WheelEvent]),h("design:returntype",void 0)],ot.prototype,"onMouseWheel",null),p([j,h("design:type",Function),h("design:paramtypes",[Number,Number,Number]),h("design:returntype",void 0)],ot.prototype,"setLayerStyles",null);var rt=function(){function t(t){this._type=t}return Object.defineProperty(t.prototype,"type",{get:function(){return this._type},enumerable:!1,configurable:!0}),t}(),it=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return d(e,t),e}(rt),st=function(t){function e(e,n,o){void 0===o&&(o="[Label]");var r=t.call(this,e,n,o)||this;return r.coords$=Y({x:0,y:0},r.entityPipe("coords")),r.rotation$=Y(0,r.entityPipe("rotation")),r}return d(e,t),e.prototype.serialize=function(){return Object.assign(Object.assign({},t.prototype.serialize.call(this)),{type:this.getType(),rotation:this.getRotation(),coords:this.getCoords()})},e.prototype.getRotation=function(){return this.rotation$.value},e.prototype.getCoords=function(){return this.coords$.value},e.prototype.destroy=function(){t.prototype.destroy.call(this)},e.prototype.setRotation=function(t){this.rotation$.set(t).emit()},e.prototype.selectRotation=function(){return this.rotation$.value$},e.prototype.setCoords=function(t){this.coords$.set(Object.assign(Object.assign({},this.coords$.value),t)).emit()},e.prototype.selectCoords=function(){return this.coords$.value$},e}(G),at=function(t){function e(e,n,o,r){void 0===e&&(e="NO LABEL"),void 0===n&&(n="default"),void 0===r&&(r="[DefaultLabel]");var i=t.call(this,n,o,r)||this;return i.label$=Y("",i.entityPipe("label")),i.setLabel(e),i}return d(e,t),e.prototype.setLabel=function(t){this.label$.set(t).emit()},e.prototype.getLabel=function(){return this.label$.value},e.prototype.selectLabel=function(){return this.label$.value$},e}(st),ut=function(t){function e(){return t.call(this,"ngdx-default-label")||this}return d(e,t),e}(at);ut.decorators=[{type:n.Component,args:[{selector:"ngdx-default-label",template:"<div\n class=\"default-label\"\n [ngStyle]=\"{\n\t\ttransform:\n\t\t\t'translate(' +\n\t\t\t(selectCoords() | async).x +\n\t\t\t'px, ' +\n\t\t\t(selectCoords() | async).y +\n\t\t\t'px)' +\n\t\t\t'rotate(' +\n\t\t\t(selectRotation() | async) +\n\t\t\t'deg)'\n\t}\">\n {{ selectLabel() | async }}\n</div>\n",changeDetection:n.ChangeDetectionStrategy.OnPush,styles:[".default-label{-moz-user-select:none;-ms-user-select:none;-webkit-user-select:none;color:#fff;user-select:none}"]}]}],ut.ctorParameters=function(){return[]};var ct=function(t){function e(e,n){var o=t.call(this,"default")||this;return o.resolver=e,o.renderer=n,o}return d(e,t),e.prototype.generateWidget=function(t,e){var n=e.createComponent(this.getRecipe()),o=n.location.nativeElement;return this.renderer.setStyle(o,"position","absolute"),this.renderer.setAttribute(o,"data-labelid",t.id),t.onEntityDestroy().subscribe((function(){n.destroy()})),Object.entries(t).forEach((function(t){var e=f(t,2),o=e[0],r=e[1];n.instance[o]=r})),n.instance.setPainted(!0),n},e.prototype.getRecipe=function(){return this.resolver.resolveComponentFactory(ut)},e.prototype.getNewInstance=function(){return new at},e}(it),lt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return d(e,t),e}(rt),dt=function(t){function e(e){var n=void 0===e?{}:e,o=n.type,r=void 0===o?"default":o,i=n.id,s=n.logPrefix,a=void 0===s?"[DefaultLink]":s,u=t.call(this,r,i,a)||this;return u.width$=Y(3,u.entityPipe("width")),u.color$=Y("rgba(255, 255, 255, 0.5)",u.entityPipe("color")),u.curvyness$=Y(50,u.entityPipe("curvyness")),u}return d(e,t),e.prototype.setWidth=function(t){this.width$.set(t).emit()},e.prototype.setColor=function(t){this.color$.set(t).emit()},e.prototype.selectWidth=function(){return this.width$.value$},e.prototype.selectColor=function(){return this.color$.value$},e.prototype.setCurvyness=function(t){this.curvyness$.set(t).emit()},Object.defineProperty(e.prototype,"color",{get:function(){return this.color$.value},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this.width$.value},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"curvyness",{get:function(){return this.curvyness$.value},enumerable:!1,configurable:!0}),e}(q),pt=function(t){function e(e){var n=t.call(this,{type:"ngdx-default-link"})||this;return n.cdRef=e,n.path$=Y(null,n.entityPipe("path")),n.points$=Y([],n.entityPipe("points")),n}return d(e,t),e.prototype.trackByPoints=function(t,e){return e.id},e.prototype.ngOnInit=function(){this.diagramEngine.getSmartRouting()&&(this.pathFinding=this.diagramEngine.getPathfinding())},e.prototype.ngAfterViewInit=function(){var t=this,e=this.getFirstPoint().selectCoords(),n=this.getLastPoint().selectCoords();o.combineLatest([e,n]).pipe(r.takeUntil(this.onEntityDestroy())).subscribe((function(e){var n=f(e,2),o=n[0],r=n[1],i=[o,r];if(t.diagramEngine.getSmartRouting()){var s=t.pathFinding.calculateDirectPath(o,r),a=t.diagramEngine.getRoutingMatrix(),u=t.pathFinding.calculateLinkStartEndCoords(a,s);if(u){var c=u.start,l=u.end,d=u.pathToStart,p=u.pathToEnd,h=T(t.pathFinding.calculateDynamicPath(a,c,l,d,p));t.path$.set(h).emit()}}else{var g=Math.abs(o.x-r.x)>Math.abs(o.y-r.y)?"x":"y",y=!1;Math.abs(i[0][g]-i[1][g])<50&&(y=!0);var m=N(o,r,y?0:t.curvyness);t.path$.set(m).emit()}var v=t.getLabel();v&&v.setCoords(t.calcCenterOfPath(o,r)),t.cdRef.detectChanges()})),this.selectLabel().pipe(r.filter(Boolean)).subscribe((function(e){t.diagramEngine.generateWidgetForLabel(e,t.labelLayer),t.cdRef.detectChanges()}))},e.prototype.calcLabelIncline=function(t,e){var n=e.y-t.y,o=e.x-t.x;if(0===o)return 0;var r=180*Math.atan(n/o)/Math.PI;return r<0&&(r+=180),r},e.prototype.calcCenterOfPath=function(t,e){return{x:(t.x+e.x)/2+20,y:(t.y+e.y)/2+20}},e.prototype.selectPath=function(){return this.path$.value$},e}(dt);pt.decorators=[{type:n.Component,args:[{selector:"ngdx-default-link",template:'\x3c!-- Label Host --\x3e\n<ng-template #labelLayer></ng-template>\n\n<svg class="link-container">\n \x3c!-- Link --\x3e\n <g [id]="id">\n <path\n [attr.stroke-width]="width"\n [attr.stroke]="selectColor() | async"\n [attr.d]="selectPath() | async"\n class="default-link"\n (mouseleave)="setHovered(false)"\n (mouseenter)="setHovered()"\n [ngClass]="{ hovered: selectHovered() | async }"\n ></path>\n <path\n class="default-link"\n (mouseleave)="setHovered(false)"\n (mouseenter)="setHovered()"\n [attr.stroke-width]="20"\n [attr.stroke]="selectColor() | async"\n [attr.stroke-linecap]="\'round\'"\n [attr.data-linkid]="id"\n [attr.stroke-opacity]="(selectHovered() | async) ? \'0.1\' : \'0\'"\n [attr.d]="selectPath() | async"\n ></path>\n </g>\n\n \x3c!-- Points --\x3e\n <g *ngFor="let point of getPoints(); trackBy: trackByPoints" [id]="point.id">\n <circle\n fill="currentColor"\n [attr.cx]="point.selectX() | async"\n [attr.cy]="point.selectY() | async"\n r="5"\n class="default-point"\n [ngClass]="{ hovered: point.selectHovered() | async }"\n />\n <circle\n [attr.data-pointid]="point.id"\n [attr.data-linkid]="id"\n (mouseleave)="point.setHovered(false); setHovered(false)"\n (mouseenter)="point.setHovered(); setHovered()"\n [attr.cx]="point.selectX() | async"\n [attr.cy]="point.selectY() | async"\n r="15"\n [attr.opacity]="0"\n [ngClass]="{ selected: point.selectSelected() | async }"\n />\n </g>\n</svg>\n',changeDetection:n.ChangeDetectionStrategy.OnPush,styles:[".link-container{pointer-events:all;position:relative}.default-link,.link-container{fill:none;overflow:visible}@-webkit-keyframes dash{0%{stroke-dashoffset:24}to{stroke-dashoffset:0}}@keyframes dash{0%{stroke-dashoffset:24}to{stroke-dashoffset:0}}.default-link.hovered{-webkit-animation:dash 1s linear infinite;animation:dash 1s linear infinite;stroke:#00c0ff;stroke-dasharray:10,2}.default-point{color:#d3d3d3;overflow:visible;pointer-events:all}.default-point.hovered{color:#00c0ff}"]}]}],pt.ctorParameters=function(){return[{type:n.ChangeDetectorRef}]},pt.propDecorators={labelLayer:[{type:n.ViewChild,args:["labelLayer",{read:n.ViewContainerRef,static:!0}]}]};var ht=function(t){function e(e,n){var o=t.call(this,"default")||this;return o.resolver=e,o.renderer=n,o}return d(e,t),e.prototype.generateWidget=function(t,e,n){var o=n.createComponent(this.getRecipe()),r=o.location.nativeElement;return this.renderer.setStyle(r,"position","absolute"),this.renderer.addClass(r,"label"),this.renderer.setAttribute(r,"data-linkid",e.id),e.onEntityDestroy().subscribe((function(){o.destroy()})),Object.entries(e).forEach((function(t){var e=f(t,2),n=e[0],r=e[1];o.instance[n]=r})),o.instance.diagramEngine=t,o.instance.setPainted(!0),o},e.prototype.getRecipe=function(){return this.resolver.resolveComponentFactory(pt)},e.prototype.getNewInstance=function(){return new dt},e}(lt),gt=function(t){function e(e){var n=void 0===e?{}:e,o=n.isInput,r=void 0===o||o,i=n.name,s=void 0===i?"port":i,a=n.type,u=void 0===a?"default":a,c=n.id,l=void 0===c?null:c,d=n.label,p=void 0===d?null:d,h=n.linkType,g=void 0===h?"default":h,f=n.maximumLinks,y=void 0===f?null:f,m=t.call(this,s,u,l,null,g)||this;return m.in=r,m.label=p||s,m.in?m.setCanCreateLinks(!1):(m.setMaximumLinks(y),m.setMagnetic(!1)),m}return d(e,t),e.prototype.link=function(e){if(t.prototype.getCanCreateLinks.call(this)){var n=new dt({type:this.getLinkType()});return n.setSourcePort(this),n.setTargetPort(e),n}return null},e.prototype.createLinkModel=function(){if(t.prototype.getCanCreateLinks.call(this))return new dt({type:this.getLinkType()})},e.prototype.canLinkToPort=function(t){return!(t instanceof e)||this.in!==t.in},e}(nt),ft=function(t){function e(e){var n=void 0===e?{}:e,o=n.name,r=void 0===o?"Untitled":o,i=n.type,s=void 0===i?"default":i,a=n.color,u=void 0===a?"rgb(0, 192, 255)":a,c=n.id,l=t.call(this,s,c)||this;return l.name=r,l.color=u,l.height$=l.selectHeight(),l.width$=l.selectWidth(),l}return d(e,t),e.prototype.addInPort=function(t){var e=t.name,n=t.type,o=void 0===n?"default":n,r=t.id,i=t.linkType,s=new gt({isInput:!0,name:e,type:o,id:r,label:null,linkType:void 0===i?"default":i});return this.addPort(s),s},e.prototype.addOutPort=function(t){var e=t.name,n=t.type,o=void 0===n?"default":n,r=t.id,i=t.linkType,s=void 0===i?"default":i,a=t.maximumLinks,u=new gt({isInput:!1,name:e,type:o,id:r,label:null,linkType:s,maximumLinks:void 0===a?null:a});return this.addPort(u),u},e}(et),yt=function(t){function e(){return t.call(this,{type:"ngdx-default-node"})||this}return d(e,t),e.prototype.ngOnInit=function(){var t=this;this.paintChanges().pipe(r.filter((function(t){return t.isPainted})),r.switchMap((function(){return t.selectPorts()}))).subscribe((function(e){e.forEach((function(e){e.getPainted()||t.generatePort(e)}))}))},e.prototype.generatePort=function(t){var e=this.getDiagramEngine();e.generateWidgetForPort(t,this.portsLayer),t.paintChanges().subscribe((function(n){n.isPainted&&t.updateCoords(e.getPortCoords(t))}))},e}(ft);yt.decorators=[{type:n.Component,args:[{selector:"ngdx-default-node",template:"<div\n class=\"default-node\"\n [ngStyle]=\"{\n 'height.px': height$ | async,\n 'width.px': width$ | async,\n 'background-color': color\n }\"\n>\n <div class=\"ports\">\n <ng-template #portsLayer></ng-template>\n </div>\n</div>\n",changeDetection:n.ChangeDetectionStrategy.OnPush,styles:[":host.selected .default-node{background-color:#fff!important;border-color:#00f}:host .default-node{border-radius:10px;cursor:auto;pointer-events:all;transition:all .3s ease-in-out;width:100%}:host .default-node .title{border-bottom:1px solid #00f;padding:10px;text-align:center}:host .ports{display:flex;flex-direction:column;flex-grow:1}"]}]}],yt.ctorParameters=function(){return[]},yt.propDecorators={portsLayer:[{type:n.ViewChild,args:["portsLayer",{read:n.ViewContainerRef,static:!0}]}]};var mt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return d(e,t),e}(rt),vt=function(t){function e(e,n){var o=t.call(this,"default")||this;return o.resolver=e,o.renderer=n,o}return d(e,t),e.prototype.generateWidget=function(t,e,n){var o=this,r=n.createComponent(this.getRecipe()),i=r.location.nativeElement;return this.renderer.setStyle(i,"position","absolute"),this.renderer.setStyle(i,"display","block"),this.renderer.setAttribute(i,"data-nodeid",e.id),e.selectCoords().subscribe((function(t){var e=t.x,n=t.y;o.renderer.setStyle(i,"left",e+"px"),o.renderer.setStyle(i,"top",n+"px")})),e.selectionChanges().subscribe((function(t){t.isSelected?o.renderer.addClass(i,"selected"):o.renderer.removeClass(i,"selected")})),e.onEntityDestroy().subscribe((function(){r.destroy()})),Object.entries(e).forEach((function(t){var e=f(t,2),n=e[0],o=e[1];r.instance[n]=o})),r.instance.setDiagramEngine(t),r.instance.setPainted(!0),r},e.prototype.getRecipe=function(){return this.resolver.resolveComponentFactory(yt)},e.prototype.getNewInstance=function(t){return new ft(t)},e}(mt),Pt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return d(e,t),e}(rt),xt=function(t){function e(){return t.call(this)||this}return d(e,t),e}(gt);xt.decorators=[{type:n.Component,args:[{selector:"ngdx-default-port",template:"<div [ngClass]=\"in ? 'in' : 'out'\" draggable=\"false\"></div>\n",changeDetection:n.ChangeDetectionStrategy.OnPush,styles:[":host{background-color:#d3d3d3;border:1px solid grey;border-radius:60px;height:10px;margin:10px 0;position:relative;width:10px}:host:hover{background-color:green}:host.out{right:-195px}:host.in{left:-5px}"]}]}],xt.ctorParameters=function(){return[]};var Lt=function(t){function e(e,n){var o=t.call(this,"default")||this;return o.resolver=e,o.renderer=n,o}return d(e,t),e.prototype.generateWidget=function(t,e){var n=e.createComponent(this.getRecipe()),o=n.location.nativeElement;return this.renderer.setAttribute(o,"data-portid",t.id),this.renderer.setAttribute(o,"data-name",t.getName()),t.in?this.renderer.addClass(o,"in"):this.renderer.addClass(o,"out"),Object.entries(t).forEach((function(t){var e=f(t,2),o=e[0],r=e[1];n.instance[o]=r})),t.onEntityDestroy().subscribe((function(){n.destroy()})),n.instance.setPainted(!0),n},e.prototype.getRecipe=function(){return this.resolver.resolveComponentFactory(xt)},e.prototype.getNewInstance=function(t){return new gt(Object.assign({isInput:!0,name:"unknown"},t))},e}(Pt),Mt=function(t){function e(e,n,o){void 0===o&&(o="[Diagram]");var r=t.call(this,n,o)||this;return r.diagramEngine=e,r.nodes$=I([],r.entityPipe("nodes")),r.links$=I([],r.entityPipe("links")),r.offsetX$=Y(0,r.entityPipe("offsetX")),r.offsetY$=Y(0,r.entityPipe("offsetY")),r.zoom$=Y(100,r.entityPipe("zoom")),r.maxZoomOut$=Y(null),r.maxZoomIn$=Y(null),r.gridSize$=Y(0),r}return d(e,t),e.prototype.getNodes=function(){return this.nodes$.value},e.prototype.getNodesArray=function(){return this.nodes$.array()},e.prototype.getNode=function(t){return this.nodes$.get(t)},e.prototype.getLink=function(t){return this.links$.get(t)},e.prototype.getLinks=function(){return this.links$.value},e.prototype.getLinksArray=function(){return this.links$.array()},e.prototype.getAllPorts=function(t){void 0===t&&(t={});var e=new Map;return this.getNodes().forEach((function(n){(t.filter?n.getPortsArray().filter(t.filter):n.getPortsArray()).forEach((function(t){return e.set(t.id,t)}))})),e},e.prototype.addNode=function(t){return this.nodes$.add(t).emit(),t},e.prototype.deleteNode=function(t){var e,n,o,r,i="string"==typeof t?t:t.id,s=this.getNode(i);try{for(var a=g(s.getPorts().values()),u=a.next();!u.done;u=a.next()){var c=u.value;try{for(var l=(o=void 0,g(c.getLinks().values())),d=l.next();!d.done;d=l.next()){var p=d.value;this.deleteLink(p)}}catch(t){o={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(o)throw o.error}}}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}this.nodes$.remove(i).emit()},e.prototype.selectNodes=function(){return this.nodes$.value$},e.prototype.addLink=function(t){return this.links$.add(t).emit(),t},e.prototype.deleteLink=function(t){var e="string"==typeof t?t:t.id;this.links$.remove(e).emit()},e.prototype.reset=function(){this.nodes$.clear().emit(),this.links$.clear().emit()},e.prototype.selectLinks=function(){return this.links$.value$},e.prototype.serialize=function(){var e=this.nodes$.map((function(t){return t.serialize()})),n=this.links$.map((function(t){return t.serialize()}));return Object.assign(Object.assign({},t.prototype.serialize.call(this)),{nodes:e,links:n})},e.prototype.setMaxZoomOut=function(t){this.maxZoomOut$.set(t).emit()},e.prototype.setMaxZoomIn=function(t){this.maxZoomIn$.set(t).emit()},e.prototype.getMaxZoomOut=function(){return this.maxZoomOut$.value},e.prototype.getMaxZoomIn=function(){return this.maxZoomIn$.value},e.prototype.setOffset=function(t,e){this.offsetX$.set(t).emit(),this.offsetY$.set(e).emit()},e.prototype.setOffsetX=function(t){this.offsetX$.set(t).emit()},e.prototype.getOffsetX=function(){return this.offsetX$.value},e.prototype.selectOffsetX=function(){return this.offsetX$.value$},e.prototype.setOffsetY=function(t){this.offsetY$.set(t).emit()},e.prototype.getOffsetY=function(){return this.offsetY$.value},e.prototype.selectOffsetY=function(){return this.offsetY$.value$},e.prototype.setZoomLevel=function(t){var e=this.getMaxZoomIn(),n=this.getMaxZoomOut();e&&t>e||n&&t<n||this.zoom$.set(t).emit()},e.prototype.getZoomLevel=function(){return this.zoom$.value},e.prototype.selectZoomLevel=function(){return this.zoom$.value$},e.prototype.getDiagramEngine=function(){return this.diagramEngine},e.prototype.clearSelection=function(t){void 0===t&&(t=null),this.getSelectedItems().forEach((function(e){(null==t?void 0:t.id)!==e.id&&e.setSelected(!1)}))},e.prototype.getGridPosition=function(t){var e=t.x,n=t.y,o=this.gridSize$.value;return 0===o?{x:e,y:n}:{x:o*Math.floor((e+o/2)/o),y:o*Math.floor((n+o/2)/o)}},e.prototype.getSelectedItems=function(){for(var t,e,n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];n=S(n);var r=[],i=this.nodes$.array(),s=this.links$.array(),a=function(){return i.flatMap((function(t){return t.getSelectedEntities()}))},u=function(){return i.flatMap((function(t){return t.getPortsArray().flatMap((function(t){return t.getSelectedEntities()}))}))},c=function(){return s.flatMap((function(t){return t.getSelectedEntities()}))},l=function(){return s.flatMap((function(t){return t.getPoints().flatMap((function(t){return t.getSelectedEntities()}))}))};if(D(n))r.push.apply(r,y(a(),u(),c(),l()));else{var d={node:a,port:u,link:c,point:l};try{for(var p=g(n),h=p.next();!h.done;h=p.next()){var f=h.value;r.push.apply(r,y(d[f]()))}}catch(e){t={error:e}}finally{try{h&&!h.done&&(e=p.return)&&e.call(p)}finally{if(t)throw t.error}}}return A(r)},e.prototype.addAll=function(){for(var t,e,n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];var r=[],i=[];try{for(var s=g(n),a=s.next();!a.done;a=s.next()){var u=a.value;u instanceof q?r.push(u):u instanceof et&&i.push(u)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}return this.addLinks(r),this.addNodes(i),n},e.prototype.addLinks=function(t){this.links$.addMany(t).emit()},e.prototype.addNodes=function(t){this.nodes$.addMany(t).emit()},e.prototype.destroy=function(){t.prototype.destroy.call(this),this.nodes$.destroy(),this.links$.destroy()},e}(B),bt=function(){},kt=function(){function t(t,e){this.vcRef=t,this.templateRef=e,this.context=new bt}return Object.defineProperty(t.prototype,"templateVar",{set:function(t){this.context.$implicit=this.context.templateVar=t,this.updateView()},enumerable:!1,configurable:!0}),t.prototype.updateView=function(){this.view?this.view.markForCheck():(this.vcRef.clear(),this.view=this.vcRef.createEmbeddedView(this.templateRef,this.context))},t}();kt.decorators=[{type:n.Directive,args:[{selector:"[templateVar]"}]}],kt.ctorParameters=function(){return[{type:n.ViewContainerRef},{type:n.TemplateRef}]},kt.propDecorators={templateVar:[{type:n.Input}]};var $t=function(){};$t.decorators=[{type:n.NgModule,args:[{declarations:[ot,kt],imports:[e.CommonModule],exports:[ot]}]}];var wt=function(){function t(t,e){this.resolver=t,this.rendererFactory=e,this.nodeFactories=new Map,this.labelFactories=new Map,this.linkFactories=new Map,this.portFactories=new Map,this.canvas$=Y(null),this.canvasMatrix=[],this.routingMatrix=[],this.hAdjustmentFactor=0,this.vAdjustmentFactor=0,this.markMatrixPoint=function(t,e,n){void 0!==t[n]&&void 0!==t[n][e]&&(t[n][e]=1)},this._renderer=this.rendererFactory.createRenderer(null,null)}return t.prototype.createDiagram=function(){return this.diagramModel=new Mt(this),this.diagramModel},t.prototype.registerDefaultFactories=function(){this.registerNodeFactory(new vt(this.resolver,this._renderer)),this.registerPortFactory(new Lt(this.resolver,this._renderer)),this.registerLinkFactory(new ht(this.resolver,this._renderer)),this.registerLabelFactory(new ct(this.resolver,this._renderer))},t.prototype.registerLabelFactory=function(t){this.labelFactories.set(t.type,t)},t.prototype.getLabelFactories=function(){return this.labelFactories},t.prototype.getLabelFactory=function(t){if(this.labelFactories.has(t))return this.labelFactories.get(t);throw new Error("cannot find factory for node of type: ["+t+"]")},t.prototype.getFactoryForLabel=function(t){return this.getLabelFactory(t.getType())},t.prototype.generateWidgetForLabel=function(t,e){var n=this.getFactoryForLabel(t);if(!n)throw new Error("Cannot find widget factory for node: "+t.getType());return n.generateWidget(t,e)},t.prototype.registerNodeFactory=function(t){this.nodeFactories.set(t.type,t)},t.prototype.getNodeFactories=function(){return this.nodeFactories},t.prototype.getNodeFactory=function(t){if(this.nodeFactories.has(t))return this.nodeFactories.get(t);throw new Error("cannot find factory for node of type: ["+t+"]")},t.prototype.getFactoryForNode=function(t){return this.getNodeFactory(t.getType())},t.prototype.generateWidgetForNode=function(t,e){var n=this.getFactoryForNode(t);if(!n)throw new Error("Cannot find widget factory for node: "+t.getType());return n.generateWidget(this,t,e)},t.prototype.registerPortFactory=function(t){this.portFactories.set(t.type,t)},t.prototype.getPortFactories=function(){return this.portFactories},t.prototype.getPortFactory=function(t){if(this.portFactories.has(t))return this.portFactories.get(t);throw new Error("cannot find factory for port of type: ["+t+"]")},t.prototype.getFactoryForPort=function(t){return this.getPortFactory(t.getType())},t.prototype.generateWidgetForPort=function(t,e){var n=this.getFactoryForPort(t);if(!n)throw new Error("Cannot find widget factory for port: "+t.getType());return n.generateWidget(t,e)},t.prototype.getLinkFactories=function(){return this.linkFactories},t.prototype.registerLinkFactory=function(t){this.linkFactories.set(t.type,t)},t.prototype.getLinkFactory=function(t){if(this.linkFactories.has(t))return this.linkFactories.get(t);throw new Error("cannot find factory for link of type: ["+t+"]")},t.prototype.getFactoryForLink=function(t){return this.getLinkFactory(t.getType())},t.prototype.generateWidgetForLink=function(t,e){var n=this.getFactoryForLink(t);if(!n)throw new Error("Cannot find link factory for link: "+t.getType());return n.generateWidget(this,t,e)},t.prototype.getNodeElement=function(t){var e=this.canvas$.value.querySelector('[data-nodeid="'+t.id+'"]');if(null===e)throw new Error("Cannot find Node element with node id: ["+t.id+"]");return e},t.prototype.getNodePortElement=function(t){var e=this.canvas$.value.querySelector('[data-nodeid="'+t.getParent().id+'"] [data-portid="'+t.id+'"]');if(null===e)throw new Error("Cannot find Node Port element with node id: ["+t.getParent().id+"] and port id: ["+t.id+"]");return e},t.prototype.getPortCenter=function(t){var e=this.getNodePortElement(t),n=e.getBoundingClientRect(),o=this.getRelativePoint(n.left,n.top);return{x:e.offsetWidth/2+(o.x-this.diagramModel.getOffsetX())/(this.diagramModel.getZoomLevel()/100),y:e.offsetHeight/2+(o.y-this.diagramModel.getOffsetY())/(this.diagramModel.getZoomLevel()/100)}},t.prototype.getPortCoords=function(t){var e=this.getNodePortElement(t).getBoundingClientRect(),n=this.canvas$.value.getBoundingClientRect();return{x:(e.x-this.diagramModel.getOffsetX())/(this.diagramModel.getZoomLevel()/100)-n.left,y:(e.y-this.diagramModel.getOffsetY())/(this.diagramModel.getZoomLevel()/100)-n.top,width:e.width,height:e.height}},t.prototype.getNodeDimensions=function(t){if(!this.canvas$.value)return{width:0,height:0};var e=this.getNodeElement(t).getBoundingClientRect();return{width:e.width,height:e.height}},t.prototype.setCanvas=function(t){this.canvas$.set(t).emit()},t.prototype.getRelativeMousePoint=function(t){var e=this.getRelativePoint(t.clientX,t.clientY);return{x:(e.x-this.diagramModel.getOffsetX())/(this.diagramModel.getZoomLevel()/100),y:(e.y-this.diagramModel.getOffsetY())/(this.diagramModel.getZoomLevel()/100)}},t.prototype.getRelativePoint=function(t,e){var n=this.canvas$.value.getBoundingClientRect();return{x:t-n.left,y:e-n.top}},t.prototype.getDiagramModel=function(){return this.diagramModel},t.prototype.isModelLocked=function(t){return!!this.diagramModel.getLocked()||t.getLocked()},t.prototype.zoomToFit=function(t){var e=this;void 0===t&&(t=.005),this.canvas$.value$.pipe(r.filter(Boolean),r.take(1),r.delay(0)).subscribe((function(n){var o=n.clientWidth/n.scrollWidth,r=n.clientHeight/n.scrollHeight,i=o<r?o:r,s=e.diagramModel.getZoomLevel()*(i-t),a=e.diagramModel.getMaxZoomOut();a&&s<a&&(s=a),e.diagramModel.setZoomLevel(s),e.diagramModel.setOffset(0,0)}))},t.prototype.setSmartRoutingStatus=function(t){t&&!this.pathFinding?this.pathFinding=new M(this):this.pathFinding=null,this.smartRouting=t},t.prototype.getPathfinding=function(){return this.pathFinding},t.prototype.calculateCanvasMatrix=function(){var t=this.calculateMatrixDimensions(),e=t.width,n=t.hAdjustmentFactor,o=t.height,r=t.vAdjustmentFactor;this.hAdjustmentFactor=n,this.vAdjustmentFactor=r;var i=Math.ceil(e/L),s=Math.ceil(o/L);this.canvasMatrix=Array.from({length:s},(function(t,e){return e+1})).map((function(){return new Array(i).fill(0)}))},t.prototype.calculateMatrixDimensions=function(){var t=this.diagramModel.getNodesArray().map((function(t){return{x:t.getCoords().x,width:t.getWidth(),y:t.getCoords().y,height:t.getHeight()}})),e=this.diagramModel.getLinksArray(),n=e.flatMap((function(t){return[t.getSourcePort(),t.getTargetPort()]})).filter((function(t){return null!==t})).map((function(t){return{x:t.getX(),width:t.getWidth(),y:t.getY(),height:t.getHeight()}})),o=e.flatMap((function(t){return t.getPoints()})).map((function(t){return{x:t.getCoords().x,width:0,y:t.getCoords().y,height:0}})),r=this.canvas$.value,i=t.concat(n,o),s=Math.floor(Math.min(i.reduce((function(t,e){return t.x<=e.x?t:e})).x,0)/L)*L,a=i.reduce((function(t,e){return t.x+t.width>=e.x+e.width?t:e})),u=Math.max(a.x+a.width,r.offsetWidth),c=Math.floor(Math.min(i.reduce((function(t,e){return t.y<=e.y?t:e})).y,0)/L)*L,l=i.reduce((function(t,e){return t.y+t.height>=e.y+e.height?t:e})),d=Math.max(l.y+l.height,r.offsetWidth),p=Math.ceil(Math.abs(s)+u),h=Math.ceil(Math.abs(c)+d);return{width:p,hAdjustmentFactor:Math.abs(s)/L+1,height:h,vAdjustmentFactor:Math.abs(c)/L+1}},t.prototype.getCanvasMatrix=function(){return 0===this.canvasMatrix.length&&this.calculateCanvasMatrix(),this.canvasMatrix},t.prototype.translateRoutingX=function(t,e){return void 0===e&&(e=!1),t+this.hAdjustmentFactor*(e?-1:1)},t.prototype.translateRoutingY=function(t,e){return void 0===e&&(e=!1),t+this.vAdjustmentFactor*(e?-1:1)},t.prototype.getRoutingMatrix=function(){return 0===this.routingMatrix.length&&this.calculateRoutingMatrix(),this.routingMatrix},t.prototype.calculateRoutingMatrix=function(){var t=this.getCanvasMatrix().map((function(t){return t.slice(0)}));this.markNodes(t),this.markPorts(t),this.routingMatrix=t},t.prototype.getSmartRouting=function(){return!!this.smartRouting},t.prototype.markNodes=function(t){var e=this;this.diagramModel.getNodes().forEach((function(n){for(var o=Math.floor(n.getCoords().x/L),r=Math.ceil((n.getCoords().x+n.getWidth())/L),i=Math.floor(n.getCoords().y/L),s=Math.ceil((n.getCoords().y+n.getHeight())/L),a=o-1;a<=r+1;a++)for(var u=i-1;u<s+1;u++)e.markMatrixPoint(t,e.translateRoutingX(a),e.translateRoutingY(u))}))},t.prototype.markPorts=function(t){var e=this;this.diagramModel.getLinksArray().flatMap((function(t){return[t.getSourcePort(),t.getTargetPort()]})).filter((function(t){return null!==t})).forEach((function(n){for(var o=Math.floor(n.getX()/L),r=Math.ceil((n.getX()+n.getWidth())/L),i=Math.floor(n.getY()/L),s=Math.ceil((n.getY()+n.getHeight())/L),a=o-1;a<=r+1;a++)for(var u=i-1;u<s+1;u++)e.markMatrixPoint(t,e.translateRoutingX(a),e.translateRoutingY(u))}))},t}();wt.ɵprov=n.ɵɵdefineInjectable({factory:function(){return new wt(n.ɵɵinject(n.ComponentFactoryResolver),n.ɵɵinject(n.RendererFactory2))},token:wt,providedIn:$t}),wt.decorators=[{type:n.Injectable,args:[{providedIn:$t}]}],wt.ctorParameters=function(){return[{type:n.ComponentFactoryResolver},{type:n.RendererFactory2}]};var Ct=function(){};Ct.decorators=[{type:n.NgModule,args:[{declarations:[pt],imports:[e.CommonModule],exports:[pt],entryComponents:[pt]}]}];var Et=function(){};Et.decorators=[{type:n.NgModule,args:[{declarations:[yt],imports:[e.CommonModule],exports:[yt],entryComponents:[yt]}]}];var Ft=function(){};Ft.decorators=[{type:n.NgModule,args:[{declarations:[xt],imports:[e.CommonModule],exports:[xt],entryComponents:[xt]}]}];var Ot=function(){};Ot.decorators=[{type:n.NgModule,args:[{declarations:[ut],imports:[e.CommonModule],exports:[ut],entryComponents:[ut]}]}];var St=function(){function t(){}return t.prototype.instantiate=function(){try{this.g=new a.graphlib.Graph({multigraph:!0})}catch(t){console.warn("`dagre` packages isn't installed, please install it before using the DagreEngine plugin")}},t.prototype.redistribute=function(t,e){var n=this;void 0===e&&(e={}),this.instantiate(),this.g.setGraph(e.graph||{}),this.g.setDefaultEdgeLabel((function(){return{}}));var o={};t.getNodes().forEach((function(t){n.g.setNode(t.id,{width:t.getWidth(),height:t.getHeight()})})),t.getLinks().forEach((function(t){t.getSourcePort()&&t.getTargetPort()&&(o[t.id]=!0,n.g.setEdge({v:t.getSourcePort().getNode().id,w:t.getTargetPort().getNode().id,name:t.id}))})),a.layout(this.g,e.layout),this.g.nodes().forEach((function(e){var o=n.g.node(e),r=o.x,i=o.y;t.getNode(e).setCoords({x:r,y:i})})),e.includeLinks&&this.g.edges().forEach((function(e){for(var o=n.g.edge(e),r=t.getLink(e.name),i=[r.getFirstPoint()],s=1;s<o.points.length-2;s++)i.push(new U(r,{x:o.points[s].x,y:o.points[s].y}));r.setPoints(i.concat(r.getLastPoint()))}))},t}();St.decorators=[{type:n.Injectable}],t.AbstractFactory=rt,t.AbstractLabelFactory=it,t.AbstractLinkFactory=lt,t.AbstractNodeFactory=mt,t.AbstractPortFactory=Pt,t.BaseAction=v,t.BaseEvent=Z,t.BaseModel=G,t.DagreEngine=St,t.DefaultLabelComponent=ut,t.DefaultLabelFactory=ct,t.DefaultLabelModel=at,t.DefaultLabelModule=Ot,t.DefaultLinkComponent=pt,t.DefaultLinkFactory=ht,t.DefaultLinkModel=dt,t.DefaultLinkModule=Ct,t.DefaultNodeComponent=yt,t.DefaultNodeFactory=vt,t.DefaultNodeModel=ft,t.DefaultNodeModule=Et,t.DefaultPortComponent=xt,t.DefaultPortFactory=Lt,t.DefaultPortModel=gt,t.DefaultPortModule=Ft,t.DiagramEngine=wt,t.DiagramModel=Mt,t.InvalidLinkDestroyed=tt,t.LabelModel=st,t.LinkCreatedAction=J,t.LinkModel=q,t.LockEvent=W,t.LooseLinkDestroyed=Q,t.MoveCanvasAction=P,t.MoveItemsAction=K,t.NgxDiagramComponent=ot,t.NgxDiagramsModule=$t,t.NodeModel=et,t.OutsideZone=j,t.PaintedEvent=z,t.ParentChangeEvent=V,t.PointModel=U,t.PortModel=nt,t.SelectingAction=x,t.SelectionEvent=H,t.UID=C,t.arrayToMap=function(t){var e,n,o={};try{for(var r=g(t),i=r.next();!i.done;i=r.next()){var s=i.value;O(s)||(o[s.id]=s)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return o},t.coerceArray=S,t.enableDiagramProdMode=function(){t.__DEV__=!1},t.entityProperty=w,t.generateCurvePath=N,t.generateDynamicPath=T,t.generateLinePath=function(t,e){return"M"+t.x$+","+t.y+" L "+e.x$+","+e.y},t.isArray=E,t.isDev=b,t.isEmptyArray=D,t.isFunction=function(t){return"function"==typeof t},t.isNil=O,t.isString=F,t.log=k,t.mapToArray=function(t){var e=[];for(var n in t)O(t[n])||e.push(t[n]);return e},t.mapToEntries=R,t.setLogLevel=function(e){t.__LOG__=e},t.unique=A,t.withLog=$,t.ɵa=j,t.ɵb=kt,t.ɵc=dt,t.ɵd=q,t.ɵe=G,t.ɵf=B,t.ɵh=ft,t.ɵi=et,t.ɵk=gt,t.ɵl=nt,t.ɵm=at,t.ɵn=st,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-diagrams.umd.min.js.map