UNPKG

@projectstorm/react-diagrams-core

Version:
16 lines 24.8 kB
/*! For license information please see index.umd.js.LICENSE.txt */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["projectstorm/react-canvas-core"]=e():t["projectstorm/react-canvas-core"]=e()}(self,(()=>(()=>{"use strict";var t={n:e=>{var i=e&&e.__esModule?()=>e.default:()=>e;return t.d(i,{a:i}),i},d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{DefaultDiagramState:()=>K,DiagramEngine:()=>Q,DiagramModel:()=>F,DragDiagramItemsState:()=>J,DragNewLinkState:()=>G,LabelModel:()=>M,LinkLayerFactory:()=>I,LinkLayerModel:()=>b,LinkLayerWidget:()=>C,LinkModel:()=>k,LinkWidget:()=>T,NodeLayerFactory:()=>W,NodeLayerModel:()=>v,NodeLayerWidget:()=>j,NodeModel:()=>y,NodeWidget:()=>A,PointModel:()=>p,PortModel:()=>H,PortModelAlignment:()=>X,PortWidget:()=>Z});const i=require("lodash/filter");var s=t.n(i);const r=require("lodash/flatMap");var o=t.n(r);const n=require("lodash/forEach");var a=t.n(n);const h=require("lodash/some");var l=t.n(h);const g=require("lodash/values");var d=t.n(g);const c=require("@projectstorm/react-canvas-core");class p extends c.BasePositionModel{constructor(t){super(Object.assign(Object.assign({},t),{type:"point"})),this.parent=t.link}isConnectedToPort(){return null!==this.parent.getPortForPoint(this)}getLink(){return this.getParent()}remove(){this.parent&&this.parent.removePoint(this),super.remove()}isLocked(){return super.isLocked()||this.getParent().isLocked()}}const u=require("lodash/map");var P=t.n(u);const m=require("lodash/slice");var f=t.n(m);const L=require("@projectstorm/geometry");class k extends c.BaseModel{constructor(t){super(t),this.points=[new p({link:this}),new p({link:this})],this.sourcePort=null,this.targetPort=null,this.renderedPaths=[],this.labels=[]}getBoundingBox(){return new L.Rectangle((0,L.boundingBoxFromPoints)(P()(this.points,(t=>t.getPosition()))))}getSelectionEntities(){return this.getTargetPort()&&this.getSourcePort()?super.getSelectionEntities().concat(f()(this.points,1,this.points.length-1)):this.getSourcePort()?this.getTargetPort()?super.getSelectionEntities().concat(this.points):super.getSelectionEntities().concat(f()(this.points,1,this.points.length)):super.getSelectionEntities().concat(f()(this.points,0,this.points.length-1))}deserialize(t){super.deserialize(t),this.points=P()(t.data.points||[],(e=>{var i=new p({link:this,position:new L.Point(e.x,e.y)});return i.deserialize(Object.assign(Object.assign({},t),{data:e})),i})),a()(t.data.labels||[],(e=>{let i=t.engine.getFactoryForLabel(e.type).generateModel({});i.deserialize(Object.assign(Object.assign({},t),{data:e})),this.addLabel(i)})),t.data.target&&t.getModel(t.data.targetPort).then((t=>{this.setTargetPort(t)})),t.data.source&&t.getModel(t.data.sourcePort).then((t=>{this.setSourcePort(t)}))}getRenderedPath(){return this.renderedPaths}setRenderedPaths(t){this.renderedPaths=t}serialize(){return Object.assign(Object.assign({},super.serialize()),{source:this.sourcePort?this.sourcePort.getParent().getID():null,sourcePort:this.sourcePort?this.sourcePort.getID():null,target:this.targetPort?this.targetPort.getParent().getID():null,targetPort:this.targetPort?this.targetPort.getID():null,points:P()(this.points,(t=>t.serialize())),labels:P()(this.labels,(t=>t.serialize()))})}doClone(t={},e){e.setPoints(P()(this.getPoints(),(e=>e.clone(t)))),this.sourcePort&&e.setSourcePort(this.sourcePort.clone(t)),this.targetPort&&e.setTargetPort(this.targetPort.clone(t))}clearPort(t){this.sourcePort===t?this.setSourcePort(null):this.targetPort===t&&this.setTargetPort(null)}remove(){this.sourcePort&&(this.sourcePort.removeLink(this),delete this.sourcePort),this.targetPort&&(this.targetPort.removeLink(this),delete this.targetPort),super.remove()}isLastPoint(t){return this.getPointIndex(t)===this.points.length-1}getPointIndex(t){return this.points.indexOf(t)}getPointModel(t){for(var e=0;e<this.points.length;e++)if(this.points[e].getID()===t)return this.points[e];return null}getPortForPoint(t){return null!==this.sourcePort&&this.getFirstPoint().getID()===t.getID()?this.sourcePort:null!==this.targetPort&&this.getLastPoint().getID()===t.getID()?this.targetPort:null}getPointForPort(t){return null!==this.sourcePort&&this.sourcePort.getID()===t.getID()?this.getFirstPoint():null!==this.targetPort&&this.targetPort.getID()===t.getID()?this.getLastPoint():null}getFirstPoint(){return this.points[0]}getLastPoint(){return this.points[this.points.length-1]}setSourcePort(t){null!==t&&t.addLink(this),null!==this.sourcePort&&this.sourcePort.removeLink(this),this.sourcePort=t,this.fireEvent({port:t},"sourcePortChanged"),(null==t?void 0:t.reportedPosition)&&this.getPointForPort(t).setPosition(t.getCenter())}getSourcePort(){return this.sourcePort}getTargetPort(){return this.targetPort}setTargetPort(t){null!==t&&t.addLink(this),null!==this.targetPort&&this.targetPort.removeLink(this),this.targetPort=t,this.fireEvent({port:t},"targetPortChanged"),(null==t?void 0:t.reportedPosition)&&this.getPointForPort(t).setPosition(t.getCenter())}point(t,e,i=1){return this.addPoint(this.generatePoint(t,e),i)}addLabel(t){t.setParent(this),this.labels.push(t)}getPoints(){return this.points}getLabels(){return this.labels}setPoints(t){a()(t,(t=>{t.setParent(this)})),this.points=t}removePoint(t){this.isLastPoint(t)&&this.remove(),this.points.splice(this.getPointIndex(t),1)}removePointsBefore(t){this.points.splice(0,this.getPointIndex(t))}removePointsAfter(t){this.points.splice(this.getPointIndex(t)+1)}removeMiddlePoints(){this.points.length>2&&this.points.splice(1,this.points.length-2)}addPoint(t,e=1){return t.setParent(this),this.points.splice(e,0,t),t}generatePoint(t=0,e=0){return new p({link:this,position:new L.Point(t,e)})}}class y extends c.BasePositionModel{constructor(t){super(t),this.ports={},this.width=0,this.height=0}getBoundingBox(){return L.Rectangle.fromPointAndSize(this.getPosition(),this.width,this.height)}setPosition(t,e){const i=this.position;t instanceof L.Point?super.setPosition(t):super.setPosition(t,e),a()(this.ports,(t=>{t.setPosition(t.getX()+this.position.x-i.x,t.getY()+this.position.y-i.y)}))}deserialize(t){super.deserialize(t),a()(t.data.ports,(e=>{let i=t.engine.getFactoryForPort(e.type).generateModel({});i.deserialize(Object.assign(Object.assign({},t),{data:e})),t.registerModel(i),this.addPort(i)}))}serialize(){return Object.assign(Object.assign({},super.serialize()),{ports:P()(this.ports,(t=>t.serialize()))})}doClone(t={},e){e.ports={},a()(this.ports,(i=>{e.addPort(i.clone(t))}))}remove(){super.remove(),a()(this.ports,(t=>{a()(t.getLinks(),(t=>{t.remove()}))}))}getPortFromID(t){for(var e in this.ports)if(this.ports[e].getID()===t)return this.ports[e];return null}getLink(t){for(let e in this.ports){const i=this.ports[e].getLinks();if(i[t])return i[t]}}getPort(t){return this.ports[t]}getPorts(){return this.ports}removePort(t){for(let e of d()(t.getLinks()))e.clearPort(t);this.ports[t.getName()]&&(this.ports[t.getName()].setParent(null),delete this.ports[t.getName()])}addPort(t){return t.setParent(this),this.ports[t.getName()]=t,t}updateDimensions({width:t,height:e}){this.width=t,this.height=e}}class v extends c.LayerModel{constructor(){super({type:"diagram-nodes",isSvg:!1,transformed:!0})}addModel(t){if(!(t instanceof y))throw new Error("Can only add nodes to this layer");t.registerListener({entityRemoved:()=>{this.getParent().removeNode(t)}}),super.addModel(t)}getChildModelFactoryBank(t){return t.getNodeFactories()}getNodes(){return this.getModels()}}class b extends c.LayerModel{constructor(){super({type:"diagram-links",isSvg:!0,transformed:!0})}addModel(t){if(!(t instanceof k))throw new Error("Can only add links to this layer");t.registerListener({entityRemoved:()=>{this.getParent().removeLink(t)}}),super.addModel(t)}getLinks(){return this.getModels()}getChildModelFactoryBank(t){return t.getLinkFactories()}}class F extends c.CanvasModel{constructor(t={}){super(t),this.addLayer(new b),this.addLayer(new v)}deserialize(t){this.layers=[],super.deserialize(t)}addLayer(t){super.addLayer(t),t instanceof v&&(this.activeNodeLayer=t),t instanceof b&&(this.activeLinkLayer=t)}getLinkLayers(){return s()(this.layers,(t=>t instanceof b))}getNodeLayers(){return s()(this.layers,(t=>t instanceof v))}getActiveNodeLayer(){if(!this.activeNodeLayer){const t=this.getNodeLayers();0===t.length?this.addLayer(new v):this.activeNodeLayer=t[0]}return this.activeNodeLayer}getActiveLinkLayer(){if(!this.activeLinkLayer){const t=this.getLinkLayers();0===t.length?this.addLayer(new b):this.activeLinkLayer=t[0]}return this.activeLinkLayer}getNode(t){for(const e of this.getNodeLayers()){const i=e.getModel(t);if(i)return i}}getLink(t){for(const e of this.getLinkLayers()){const i=e.getModel(t);if(i)return i}}addAll(...t){return a()(t,(t=>{t instanceof k?this.addLink(t):t instanceof y&&this.addNode(t)})),t}addLink(t){return this.getActiveLinkLayer().addModel(t),this.fireEvent({link:t,isCreated:!0},"linksUpdated"),t}addNode(t){return this.getActiveNodeLayer().addModel(t),this.fireEvent({node:t,isCreated:!0},"nodesUpdated"),t}removeLink(t){l()(this.getLinkLayers(),(e=>e.removeModel(t)))&&this.fireEvent({link:t,isCreated:!1},"linksUpdated")}removeNode(t){l()(this.getNodeLayers(),(e=>e.removeModel(t)))&&this.fireEvent({node:t,isCreated:!1},"nodesUpdated")}getLinks(){return o()(this.getLinkLayers(),(t=>d()(t.getModels())))}getNodes(){return o()(this.getNodeLayers(),(t=>d()(t.getModels())))}}class M extends c.BaseModel{constructor(t){super(Object.assign(Object.assign({},t),{offsetX:t.offsetX||0,offsetY:t.offsetY||0}))}deserialize(t){super.deserialize(t),this.options.offsetX=t.data.offsetX,this.options.offsetY=t.data.offsetY}serialize(){return Object.assign(Object.assign({},super.serialize()),{offsetX:this.options.offsetX,offsetY:this.options.offsetY})}}const w=require("react"),N=require("@emotion/styled");var x,E,S=t.n(N);!function(t){t.Label=S().div` display: inline-block; position: absolute; `,t.Foreign=S().foreignObject` pointer-events: none; overflow: visible; `}(x||(x={}));class D extends w.Component{constructor(t){super(t),this.findPathAndRelativePositionToRenderLabel=t=>{const e=this.props.label.getParent(),i=e.getRenderedPath().map((t=>t.getTotalLength()));let s=i.reduce(((t,e)=>t+e),0)*(t/(e.getLabels().length+1)),r=0;for(;r<e.getRenderedPath().length;){if(s-i[r]<0)return{path:e.getRenderedPath()[r],position:s};s-=i[r],r++}},this.calculateLabelPosition=()=>{const t=this.findPathAndRelativePositionToRenderLabel(this.props.index+1);if(!t)return;const{path:e,position:i}=t,s=this.ref.current.offsetWidth,r=this.ref.current.offsetHeight,o=e.getPointAtLength(i),n=o.x-s/2+this.props.label.getOptions().offsetX,a=o.y-r/2+this.props.label.getOptions().offsetY;this.ref.current.style.transform=`translate(${n}px, ${a}px)`},this.ref=w.createRef()}componentDidUpdate(){window.requestAnimationFrame(this.calculateLabelPosition)}componentDidMount(){window.requestAnimationFrame(this.calculateLabelPosition)}render(){const t=this.props.engine.getCanvas();return w.createElement(x.Foreign,{key:this.props.label.getID(),width:null==t?void 0:t.offsetWidth,height:null==t?void 0:t.offsetHeight},w.createElement(x.Label,{ref:this.ref},this.props.engine.getFactoryForLabel(this.props.label).generateReactWidget({model:this.props.label})))}}class T extends w.Component{constructor(t){super(t),this.state={sourcePort:null,targetPort:null}}componentWillUnmount(){this.sourceListener&&this.sourceListener.deregister(),this.targetListener&&this.targetListener.deregister()}static getDerivedStateFromProps(t,e){return{sourcePort:t.link.getSourcePort(),targetPort:t.link.getTargetPort()}}installTarget(){this.targetListener&&this.targetListener.deregister(),this.props.link.getTargetPort()&&(this.targetListener=this.props.link.getTargetPort().registerListener({reportInitialPosition:t=>{this.forceUpdate()}}))}installSource(){this.sourceListener&&this.sourceListener.deregister(),this.props.link.getSourcePort()&&(this.sourceListener=this.props.link.getSourcePort().registerListener({reportInitialPosition:t=>{this.forceUpdate()}}))}componentDidUpdate(t,e,i){e.sourcePort!==this.state.sourcePort&&this.installSource(),e.targetPort!==this.state.targetPort&&this.installTarget()}static generateLinePath(t,e){return`M${t.getX()},${t.getY()} L ${e.getX()},${e.getY()}`}componentDidMount(){this.props.link.getSourcePort()&&this.installSource(),this.props.link.getTargetPort()&&this.installTarget()}render(){const{link:t}=this.props;return t.getSourcePort()&&!t.getSourcePort().reportedPosition||t.getTargetPort()&&!t.getTargetPort().reportedPosition?null:w.createElement(c.PeformanceWidget,{model:this.props.link,serialized:this.props.link.serialize()},(()=>w.createElement("g",{"data-linkid":this.props.link.getID()},this.props.diagramEngine.generateWidgetForLink(t),P()(this.props.link.getLabels(),((t,e)=>w.createElement(D,{key:t.getID(),engine:this.props.diagramEngine,label:t,index:e}))))))}}!function(t){t.Container=S().div``}(E||(E={}));class C extends w.Component{render(){return w.createElement(w.Fragment,null,P()(this.props.layer.getLinks(),(t=>w.createElement(T,{key:t.getID(),link:t,diagramEngine:this.props.engine}))))}}class I extends c.AbstractReactFactory{constructor(){super("diagram-links")}generateModel(t){return new b}generateReactWidget(t){return w.createElement(C,{layer:t.model,engine:this.engine})}}const O=require("resize-observer-polyfill");var z,R=t.n(O);!function(t){t.Node=S().div` position: absolute; -webkit-touch-callout: none; /* iOS Safari */ -webkit-user-select: none; /* Chrome/Safari/Opera */ user-select: none; cursor: move; pointer-events: all; `}(z||(z={}));class A extends w.Component{constructor(t){super(t),this.ref=w.createRef()}componentWillUnmount(){var t;this.ob.disconnect(),this.ob=null,null===(t=this.listener)||void 0===t||t.deregister(),this.listener=null}componentDidUpdate(t,e,i){this.listener&&this.props.node!==t.node&&(this.listener.deregister(),this.installSelectionListener())}installSelectionListener(){this.listener=this.props.node.registerListener({selectionChanged:t=>{this.forceUpdate()}})}updateSize(t,e){this.props.node.updateDimensions({width:t,height:e});try{a()(this.props.node.getPorts(),(t=>{t.updateCoords(this.props.diagramEngine.getPortCoords(t))}))}catch(t){}}componentDidMount(){this.ob=new(R())((t=>{const e=t[0].contentRect;this.updateSize(e.width,e.height)}));const t=this.ref.current.getBoundingClientRect();this.updateSize(t.width,t.height),this.ob.observe(this.ref.current),this.installSelectionListener()}render(){return w.createElement(c.PeformanceWidget,{model:this.props.node,serialized:this.props.node.serialize()},(()=>w.createElement(z.Node,{className:"node",ref:this.ref,"data-nodeid":this.props.node.getID(),style:{top:this.props.node.getY(),left:this.props.node.getX()}},this.props.diagramEngine.generateWidgetForNode(this.props.node))))}}class j extends w.Component{render(){return w.createElement(w.Fragment,null,P()(this.props.layer.getNodes(),(t=>w.createElement(A,{key:t.getID(),diagramEngine:this.props.engine,node:t}))))}}class W extends c.AbstractReactFactory{constructor(){super("diagram-nodes")}generateModel(t){return new v}generateReactWidget(t){return w.createElement(j,{layer:t.model,engine:this.engine})}}const B=require("lodash/isFinite");var U=t.n(B);const q=require("lodash/size");var X,Y=t.n(q);!function(t){t.TOP="top",t.LEFT="left",t.BOTTOM="bottom",t.RIGHT="right"}(X||(X={}));class H extends c.BasePositionModel{constructor(t){super(t),this.links={},this.reportedPosition=!1}deserialize(t){super.deserialize(t),this.reportedPosition=!1,this.options.name=t.data.name,this.options.alignment=t.data.alignment}serialize(){return Object.assign(Object.assign({},super.serialize()),{name:this.options.name,alignment:this.options.alignment,parentNode:this.parent.getID(),links:P()(this.links,(t=>t.getID()))})}setPosition(t,e){let i=this.position;super.setPosition(t,e),a()(this.getLinks(),(s=>{let r=s.getPointForPort(this);r.setPosition(r.getX()+t-i.x,r.getY()+e-i.y)}))}doClone(t={},e){e.links={},e.parent=this.getParent().clone(t)}getNode(){return this.getParent()}getName(){return this.options.name}getMaximumLinks(){return this.options.maximumLinks}setMaximumLinks(t){this.options.maximumLinks=t}removeLink(t){delete this.links[t.getID()]}addLink(t){this.links[t.getID()]=t}getLinks(){return this.links}createLinkModel(){if(U()(this.options.maximumLinks)){var t=Y()(this.links);if(1===this.options.maximumLinks&&t>=1)return d()(this.links)[0];if(t>=this.options.maximumLinks)return null}return null}reportPosition(){a()(this.getLinks(),(t=>{t.getPointForPort(this).setPosition(this.getCenter())})),this.fireEvent({entity:this},"reportInitialPosition")}getCenter(){return new L.Point(this.getX()+this.width/2,this.getY()+this.height/2)}getBoundingBox(){return L.Rectangle.fromPointAndSize(this.position,this.width,this.height)}updateCoords(t){this.width=t.getWidth(),this.height=t.getHeight(),this.setPosition(t.getTopLeft()),this.reportedPosition=!0,this.reportPosition()}canLinkToPort(t){return!0}isLocked(){return super.isLocked()||this.getParent().isLocked()}}const $=require("lodash/keys");var _=t.n($);class Z extends w.Component{constructor(t){super(t),this.ref=w.createRef()}report(){this.props.port.updateCoords(this.props.engine.getPortCoords(this.props.port,this.ref.current))}componentWillUnmount(){this.engineListenerHandle&&this.engineListenerHandle.deregister()}componentDidUpdate(t,e,i){this.props.port.reportedPosition||this.report()}componentDidMount(){this.engineListenerHandle=this.props.engine.registerListener({canvasReady:()=>{this.report()}}),this.props.engine.getCanvas()&&this.report()}getExtraProps(){if(c.Toolkit.TESTING){return{"data-links":_()(this.props.port.getNode().getPort(this.props.port.getName()).links).join(",")}}return{}}render(){return w.createElement("div",Object.assign({style:this.props.style,ref:this.ref,className:`port ${this.props.className||""}`,"data-name":this.props.port.getName(),"data-nodeid":this.props.port.getNode().getID()},this.getExtraProps()),this.props.children)}}class G extends c.AbstractDisplacementState{constructor(t={}){super({name:"drag-new-link"}),this.config=Object.assign({allowLooseLinks:!0,allowLinksFromLockedPorts:!1},t),this.registerAction(new c.Action({type:c.InputType.MOUSE_DOWN,fire:t=>{this.port=this.engine.getMouseElement(t.event),this.config.allowLinksFromLockedPorts||!this.port.isLocked()?(this.link=this.port.createLinkModel(),this.link?(this.link.setSelected(!0),this.link.setSourcePort(this.port),this.engine.getModel().addLink(this.link),this.port.reportPosition()):this.eject()):this.eject()}})),this.registerAction(new c.Action({type:c.InputType.MOUSE_UP,fire:t=>{const e=this.engine.getMouseElement(t.event);if(e instanceof H)return this.port.canLinkToPort(e)?(this.link.setTargetPort(e),e.reportPosition(),void this.engine.repaintCanvas()):(this.link.remove(),void this.engine.repaintCanvas());this.config.allowLooseLinks||(this.link.remove(),this.engine.repaintCanvas())}}))}fireMouseMoved(t){const e=this.port.getPosition(),i=this.engine.getModel().getZoomLevel()/100,s=this.engine.getModel().getOffsetX()/i,r=this.engine.getModel().getOffsetY()/i,o=this.initialXRelative/i,n=this.initialYRelative/i,a=e.x-s+(o-e.x)+t.virtualDisplacementX,h=e.y-r+(n-e.y)+t.virtualDisplacementY;this.link.getLastPoint().setPosition(a,h),this.engine.repaintCanvas()}}class J extends c.MoveItemsState{constructor(){super(),this.registerAction(new c.Action({type:c.InputType.MOUSE_UP,fire:t=>{const e=this.engine.getMouseElement(t.event);e instanceof H&&a()(this.initialPositions,(t=>{if(t.item instanceof p){const i=t.item.getParent();if(i.getLastPoint()!==t.item)return;i.getSourcePort().canLinkToPort(e)&&(i.setTargetPort(e),e.reportPosition(),this.engine.repaintCanvas())}}))}}))}}class K extends c.State{constructor(){super({name:"default-diagrams"}),this.childStates=[new c.SelectingState],this.dragCanvas=new c.DragCanvasState,this.dragNewLink=new G,this.dragItems=new J,this.registerAction(new c.Action({type:c.InputType.MOUSE_DOWN,fire:t=>{const e=this.engine.getActionEventBus().getModelForEvent(t);e?e instanceof H?this.transitionWithEvent(this.dragNewLink,t):this.transitionWithEvent(this.dragItems,t):this.transitionWithEvent(this.dragCanvas,t)}})),this.registerAction(new c.Action({type:c.InputType.TOUCH_START,fire:t=>{this.transitionWithEvent(this.dragCanvas,t)}}))}}class Q extends c.CanvasEngine{constructor(t={}){super(t),this.maxNumberPointsPerLink=1e3,this.nodeFactories=new c.FactoryBank,this.linkFactories=new c.FactoryBank,this.portFactories=new c.FactoryBank,this.labelFactories=new c.FactoryBank;const e=t=>{t.registerListener({factoryAdded:t=>{t.factory.setDiagramEngine(this)},factoryRemoved:t=>{t.factory.setDiagramEngine(null)}})};e(this.nodeFactories),e(this.linkFactories),e(this.portFactories),e(this.labelFactories)}getMouseElement(t){var e=t.target,i=this.model,s=c.Toolkit.closest(e,".port[data-name]");if(s){var r=c.Toolkit.closest(e,".node[data-nodeid]");return i.getNode(r.getAttribute("data-nodeid")).getPort(s.getAttribute("data-name"))}return(s=c.Toolkit.closest(e,".point[data-id]"))?i.getLink(s.getAttribute("data-linkid")).getPointModel(s.getAttribute("data-id")):(s=c.Toolkit.closest(e,"[data-linkid]"))?i.getLink(s.getAttribute("data-linkid")):(s=c.Toolkit.closest(e,".node[data-nodeid]"))?i.getNode(s.getAttribute("data-nodeid")):null}getNodeFactories(){return this.nodeFactories}getLinkFactories(){return this.linkFactories}getLabelFactories(){return this.labelFactories}getPortFactories(){return this.portFactories}getFactoryForNode(t){return"string"==typeof t?this.nodeFactories.getFactory(t):this.nodeFactories.getFactory(t.getType())}getFactoryForLink(t){return"string"==typeof t?this.linkFactories.getFactory(t):this.linkFactories.getFactory(t.getType())}getFactoryForLabel(t){return"string"==typeof t?this.labelFactories.getFactory(t):this.labelFactories.getFactory(t.getType())}getFactoryForPort(t){return"string"==typeof t?this.portFactories.getFactory(t):this.portFactories.getFactory(t.getType())}generateWidgetForLink(t){return this.getFactoryForLink(t).generateReactWidget({model:t})}generateWidgetForNode(t){return this.getFactoryForNode(t).generateReactWidget({model:t})}getNodeElement(t){const e=this.canvas.querySelector(`.node[data-nodeid="${t.getID()}"]`);if(null===e)throw new Error("Cannot find Node element with nodeID: ["+t.getID()+"]");return e}getNodePortElement(t){var e=this.canvas.querySelector(`.port[data-name="${t.getName()}"][data-nodeid="${t.getParent().getID()}"]`);if(null===e)throw new Error("Cannot find Node Port element with nodeID: ["+t.getParent().getID()+"] and name: ["+t.getName()+"]");return e}getPortCenter(t){return this.getPortCoords(t).getOrigin()}getPortCoords(t,e){if(!this.canvas)throw new Error("Canvas needs to be set first");e||(e=this.getNodePortElement(t));const i=e.getBoundingClientRect(),s=this.getRelativeMousePoint({clientX:i.left,clientY:i.top}),r=this.model.getZoomLevel()/100;return L.Rectangle.fromPointAndSize(s,i.width/r,i.height/r)}getNodeDimensions(t){if(!this.canvas)return{width:0,height:0};const e=this.getNodeElement(t).getBoundingClientRect();return{width:e.width,height:e.height}}getBoundingNodesRect(t){if(t)return 0===t.length?new L.Rectangle:new L.Rectangle((0,L.boundingBoxFromPolygons)(t.map((t=>t.getBoundingBox()))))}zoomToFitSelectedNodes(t){const e=this.model.getSelectedEntities().filter((t=>t instanceof y));this.zoomToFitNodes({margin:t.margin,maxZoom:t.maxZoom,nodes:e.length>0?e:null})}zoomToFitNodes(t){let e=t||0,i=[],s=null;t&&"object"==typeof t&&(e=t.margin||0,i=t.nodes||[],s=t.maxZoom||null),0===i.length&&(i=this.model.getNodes());const r=this.getBoundingNodesRect(i);if(r){let t=this.canvas.getBoundingClientRect();const i=(e=0)=>{const i=this.canvas.clientWidth/(r.getWidth()+2*e),o=this.canvas.clientHeight/(r.getHeight()+2*e);let n=i<o?i:o;return s&&n>s&&(n=s),{zoom:n,x:t.width/2-((r.getWidth()+2*e)/2+r.getTopLeft().x)*n+e,y:t.height/2-((r.getHeight()+2*e)/2+r.getTopLeft().y)*n+e}};let o=i(0);e&&(o.x<e||o.y<e)&&(o=i(e)),this.model.setZoomLevel(100*o.zoom),this.model.setOffset(o.x,o.y),this.repaintCanvas()}}getMaxNumberPointsPerLink(){return this.maxNumberPointsPerLink}setMaxNumberPointsPerLink(t){this.maxNumberPointsPerLink=t}}return e})())); //# sourceMappingURL=index.umd.js.map