@html-graph/html-graph 3.21.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- (function(v,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(v=typeof globalThis<"u"?globalThis:v||self,E(v.HtmlGraph={}))})(this,function(v){"use strict";var Dt=Object.defineProperty;var Nt=(v,E,T)=>E in v?Dt(v,E,{enumerable:!0,configurable:!0,writable:!0,value:T}):v[E]=T;var o=(v,E,T)=>Nt(v,typeof E!="symbol"?E+"":E,T);const E=(r,e)=>({x:r.scale*e.x+r.x,y:r.scale*e.y+r.y});var T=(r=>(r.Line="line",r.NodeCycle="node-cycle",r.PortCycle="port-cycle",r))(T||{});const Ue=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r.style.overflow="hidden",r},We=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.width="0",r.style.height="0",r},Be=r=>{r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.visibility="hidden"};class ie{constructor(e,t,s){o(this,"host",Ue());o(this,"container",We());o(this,"edgeIdToElementMap",new Map);o(this,"applyTransform",()=>{const e=this.viewportStore.getContentMatrix();this.container.style.transform=`matrix(${e.scale}, 0, 0, ${e.scale}, ${e.x}, ${e.y})`});this.graphStore=e,this.viewportStore=t,this.element=s,this.element.appendChild(this.host),this.host.appendChild(this.container),this.viewportStore.onAfterUpdated.subscribe(this.applyTransform)}attachNode(e){const t=this.graphStore.getNode(e);Be(t.element),this.container.appendChild(t.element),this.updateNodePosition(e),this.updateNodePriority(e),t.element.style.visibility="visible"}detachNode(e){const t=this.graphStore.getNode(e);this.container.removeChild(t.element)}attachEdge(e){const t=this.graphStore.getEdge(e).shape.svg;this.edgeIdToElementMap.set(e,t),this.container.appendChild(t),this.renderEdge(e),this.updateEdgePriority(e)}detachEdge(e){const t=this.edgeIdToElementMap.get(e);this.container.removeChild(t),this.edgeIdToElementMap.delete(e)}clear(){this.edgeIdToElementMap.forEach((e,t)=>{this.detachEdge(t)}),this.graphStore.getAllNodeIds().forEach(e=>{this.detachNode(e)})}destroy(){this.viewportStore.onAfterUpdated.unsubscribe(this.applyTransform),this.clear(),this.element.removeChild(this.host),this.host.removeChild(this.container)}updateNodePosition(e){const t=this.graphStore.getNode(e),{width:s,height:i}=t.element.getBoundingClientRect(),n=this.viewportStore.getViewportMatrix().scale,a=t.centerFn(s,i),h=t.x-n*a.x,d=t.y-n*a.y;t.element.style.transform=`translate(${h}px, ${d}px)`}updateNodePriority(e){const t=this.graphStore.getNode(e);t.element.style.zIndex=`${t.priority}`}updateEdgeShape(e){const t=this.edgeIdToElementMap.get(e);this.container.removeChild(t);const s=this.graphStore.getEdge(e);this.edgeIdToElementMap.set(e,s.shape.svg),this.container.appendChild(s.shape.svg)}renderEdge(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from),i=this.graphStore.getPort(t.to),n=s.element.getBoundingClientRect(),a=i.element.getBoundingClientRect(),h=this.host.getBoundingClientRect(),d=this.viewportStore.getViewportMatrix(),c=this.createEdgeRenderPort(t.from,s,n,h,d),l=this.createEdgeRenderPort(t.to,i,a,h,d);let g=T.Line;s.element===i.element?g=T.PortCycle:s.nodeId===i.nodeId&&(g=T.NodeCycle),t.shape.render({from:c,to:l,category:g})}updateEdgePriority(e){const t=this.graphStore.getEdge(e);t.shape.svg.style.zIndex=`${t.priority}`}createEdgeRenderPort(e,t,s,i,n){const a={x:s.left-i.left,y:s.top-i.top},h=E(n,a);return{x:h.x,y:h.y,width:s.width*n.scale,height:s.height*n.scale,direction:t.direction,portId:e,nodeId:t.nodeId}}}class $e{constructor(e){o(this,"xFrom",1/0);o(this,"yFrom",1/0);o(this,"xTo",1/0);o(this,"yTo",1/0);this.graphStore=e}setRenderingBox(e){this.xFrom=e.x,this.xTo=e.x+e.width,this.yFrom=e.y,this.yTo=e.y+e.height}hasNode(e){const t=this.graphStore.getNode(e);return t.x>=this.xFrom&&t.x<=this.xTo&&t.y>=this.yFrom&&t.y<=this.yTo}hasEdge(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from).nodeId,i=this.graphStore.getPort(t.to).nodeId,n=this.graphStore.getNode(s),a=this.graphStore.getNode(i),h=Math.min(n.x,a.x),d=Math.max(n.x,a.x),c=Math.min(n.y,a.y),l=Math.max(n.y,a.y);return h<=this.xTo&&d>=this.xFrom&&c<=this.yTo&&l>=this.yFrom}}class Fe{constructor(e,t,s,i){o(this,"attachedNodes",new Set);o(this,"attachedEdges",new Set);o(this,"renderingBox");o(this,"updateViewport",e=>{this.renderingBox.setRenderingBox(e);const t=new Set,s=new Set,i=new Set,n=new Set;this.graphStore.getAllNodeIds().forEach(a=>{const h=this.renderingBox.hasNode(a),d=this.attachedNodes.has(a);h&&!d?t.add(a):!h&&d&&s.add(a)}),this.graphStore.getAllEdgeIds().forEach(a=>{const h=this.renderingBox.hasEdge(a),d=this.attachedEdges.has(a),c=this.graphStore.getEdge(a),l=this.graphStore.getPort(c.from).nodeId,g=this.graphStore.getPort(c.to).nodeId;h&&(this.renderingBox.hasNode(l)||(t.add(l),s.delete(l)),this.renderingBox.hasNode(g)||(t.add(g),s.delete(g))),h&&!d?i.add(a):!h&&d&&n.add(a)}),n.forEach(a=>{this.handleDetachEdge(a)}),s.forEach(a=>{this.handleDetachNode(a)}),t.forEach(a=>{this.attachedNodes.has(a)||this.handleAttachNode(a)}),i.forEach(a=>{this.handleAttachEdge(a)})});this.htmlView=e,this.graphStore=t,this.trigger=s,this.params=i,this.renderingBox=new $e(this.graphStore),this.trigger.subscribe(this.updateViewport)}attachNode(e){this.renderingBox.hasNode(e)&&this.handleAttachNode(e)}detachNode(e){this.attachedNodes.has(e)&&this.handleDetachNode(e)}attachEdge(e){this.renderingBox.hasEdge(e)&&this.attachEdgeEntities(e)}detachEdge(e){this.attachedEdges.has(e)&&this.handleDetachEdge(e)}updateNodePosition(e){this.attachedNodes.has(e)?this.htmlView.updateNodePosition(e):this.renderingBox.hasNode(e)&&(this.handleAttachNode(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(t=>{this.attachEdgeEntities(t)}))}updateNodePriority(e){this.attachedNodes.has(e)&&this.htmlView.updateNodePriority(e)}updateEdgeShape(e){this.attachedEdges.has(e)&&this.htmlView.updateEdgeShape(e)}renderEdge(e){this.attachedEdges.has(e)&&this.htmlView.renderEdge(e)}updateEdgePriority(e){this.attachedEdges.has(e)&&this.htmlView.updateEdgePriority(e)}clear(){this.htmlView.clear(),this.attachedNodes.clear(),this.attachedEdges.clear()}destroy(){this.clear(),this.htmlView.destroy(),this.trigger.unsubscribe(this.updateViewport)}attachEdgeEntities(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from).nodeId,i=this.graphStore.getPort(t.to).nodeId;this.attachedNodes.has(s)||this.handleAttachNode(s),this.attachedNodes.has(i)||this.handleAttachNode(i),this.handleAttachEdge(e)}handleAttachNode(e){this.params.onBeforeNodeAttached(e),this.attachedNodes.add(e),this.htmlView.attachNode(e)}handleDetachNode(e){this.htmlView.detachNode(e),this.attachedNodes.delete(e),this.params.onAfterNodeDetached(e)}handleAttachEdge(e){this.attachedEdges.add(e),this.htmlView.attachEdge(e)}handleDetachEdge(e){this.htmlView.detachEdge(e),this.attachedEdges.delete(e)}}class H{constructor(){o(this,"callbacks",new Set)}subscribe(e){this.callbacks.add(e)}unsubscribe(e){this.callbacks.delete(e)}emit(e){this.callbacks.forEach(t=>{t(e)})}}const A=()=>{const r=new H;return[r,r]};class Oe{constructor(e){o(this,"onBeforeUpdated");o(this,"onAfterUpdated");this.viewportStore=e,this.onBeforeUpdated=this.viewportStore.onBeforeUpdated,this.onAfterUpdated=this.viewportStore.onAfterUpdated}getViewportMatrix(){return{...this.viewportStore.getViewportMatrix()}}getContentMatrix(){return{...this.viewportStore.getContentMatrix()}}}class ze{constructor(e){o(this,"onAfterNodeAdded");o(this,"onAfterNodeUpdated");o(this,"onAfterNodePriorityUpdated");o(this,"onBeforeNodeRemoved");o(this,"onAfterPortMarked");o(this,"onAfterPortUpdated");o(this,"onBeforePortUnmarked");o(this,"onAfterEdgeAdded");o(this,"onAfterEdgeShapeUpdated");o(this,"onAfterEdgeUpdated");o(this,"onAfterEdgePriorityUpdated");o(this,"onBeforeEdgeRemoved");o(this,"onBeforeClear");this.graphStore=e,this.onAfterNodeAdded=this.graphStore.onAfterNodeAdded,this.onAfterNodeUpdated=this.graphStore.onAfterNodeUpdated,this.onAfterNodePriorityUpdated=this.graphStore.onAfterNodePriorityUpdated,this.onBeforeNodeRemoved=this.graphStore.onBeforeNodeRemoved,this.onAfterPortMarked=this.graphStore.onAfterPortAdded,this.onAfterPortUpdated=this.graphStore.onAfterPortUpdated,this.onBeforePortUnmarked=this.graphStore.onBeforePortRemoved,this.onAfterEdgeAdded=this.graphStore.onAfterEdgeAdded,this.onAfterEdgeShapeUpdated=this.graphStore.onAfterEdgeShapeUpdated,this.onAfterEdgeUpdated=this.graphStore.onAfterEdgeUpdated,this.onAfterEdgePriorityUpdated=this.graphStore.onAfterEdgePriorityUpdated,this.onBeforeEdgeRemoved=this.graphStore.onBeforeEdgeRemoved,this.onBeforeClear=this.graphStore.onBeforeClear}getNode(e){const t=this.graphStore.getNode(e);return t===void 0?null:{element:t.element,x:t.x,y:t.y,centerFn:t.centerFn,priority:t.priority}}getElementNodeId(e){return this.graphStore.getElementNodeId(e)??null}getAllNodeIds(){return this.graphStore.getAllNodeIds()}getPort(e){const t=this.graphStore.getPort(e);return t===void 0?null:{element:t.element,direction:t.direction,nodeId:t.nodeId}}getAllPortIds(){return this.graphStore.getAllPortIds()}getNodePortIds(e){return this.graphStore.getNodePortIds(e)??null}getElementPortIds(e){return[...this.graphStore.getElementPortIds(e)]}getElementPortsIds(e){return this.getElementPortIds(e)}getAllEdgeIds(){return this.graphStore.getAllEdgeIds()}getEdge(e){const t=this.graphStore.getEdge(e);return t===void 0?null:{from:t.from,to:t.to,priority:t.priority,shape:t.shape}}getPortIncomingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortIncomingEdgeIds(e)}getPortOutgoingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortOutgoingEdgeIds(e)}getPortOutcomingEdgeIds(e){return this.getPortOutgoingEdgeIds(e)}getPortCycleEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortCycleEdgeIds(e)}getPortAdjacentEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortAdjacentEdgeIds(e)}getNodeIncomingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeIncomingEdgeIds(e)}getNodeOutgoingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeOutgoingEdgeIds(e)}getNodeOutcomingEdgeIds(e){return this.getNodeOutgoingEdgeIds(e)}getNodeCycleEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeCycleEdgeIds(e)}getNodeAdjacentEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeAdjacentEdgeIds(e)}}class X{constructor(e){o(this,"counter",0);this.checkExists=e}create(e){if(e!==void 0)return e;for(;this.checkExists(this.counter);)this.counter++;return this.counter}reset(){this.counter=0}}class P extends Error{constructor(){super(...arguments);o(this,"name","HtmlGraphError")}}class ne{constructor(e,t,s,i,n){o(this,"graph");o(this,"viewport");o(this,"nodeIdGenerator",new X(e=>this.graph.getNode(e)!==null));o(this,"portIdGenerator",new X(e=>this.graph.getPort(e)!==null));o(this,"edgeIdGenerator",new X(e=>this.graph.getEdge(e)!==null));o(this,"onAfterNodeAdded",e=>{this.htmlView.attachNode(e)});o(this,"onAfterNodeUpdated",e=>{this.htmlView.updateNodePosition(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(s=>{this.htmlView.renderEdge(s)})});o(this,"onAfterNodePriorityUpdated",e=>{this.htmlView.updateNodePriority(e)});o(this,"onBeforeNodeRemoved",e=>{this.graphStore.getNodePortIds(e).forEach(t=>{this.unmarkPort(t)}),this.htmlView.detachNode(e)});o(this,"onAfterPortUpdated",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(s=>{this.htmlView.renderEdge(s)})});o(this,"onBeforePortUnmarked",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(t=>{this.removeEdge(t)})});o(this,"onAfterEdgeAdded",e=>{this.htmlView.attachEdge(e)});o(this,"onAfterEdgeShapeUpdated",e=>{this.htmlView.updateEdgeShape(e)});o(this,"onAfterEdgeUpdated",e=>{this.htmlView.renderEdge(e)});o(this,"onAfterEdgePriorityUpdated",e=>{this.htmlView.updateEdgePriority(e)});o(this,"onBeforeEdgeRemoved",e=>{this.htmlView.detachEdge(e)});o(this,"onBeforeClear",()=>{this.nodeIdGenerator.reset(),this.portIdGenerator.reset(),this.edgeIdGenerator.reset(),this.htmlView.clear()});o(this,"onBeforeDestroyEmitter");o(this,"destroyed",!1);o(this,"onBeforeDestroy");this.element=e,this.graphStore=t,this.viewportStore=s,this.htmlView=i,this.params=n,this.graph=new ze(this.graphStore),this.viewport=new Oe(this.viewportStore),this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.subscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.subscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.subscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.subscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.subscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.subscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.subscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.subscribe(this.onBeforeClear),[this.onBeforeDestroyEmitter,this.onBeforeDestroy]=A()}addNode(e){const t=this.nodeIdGenerator.create(e.id);if(this.graph.getNode(t)!==null)throw new P("failed to add node with existing id");if(this.graphStore.getElementNodeId(e.element)!==void 0)throw new P("failed to add node with html element already in use by another node");if(this.graphStore.addNode({id:t,element:e.element,x:e.x,y:e.y,centerFn:e.centerFn??this.params.nodes.centerFn,priority:e.priority??this.params.nodes.priorityFn()}),e.ports!==void 0)for(const s of e.ports)this.markPort({id:s.id,element:s.element,nodeId:t,direction:s.direction});return this}updateNode(e,t){if(this.graph.getNode(e)===null)throw new P("failed to update non existing node");return this.graphStore.updateNode(e,t??{}),this}removeNode(e){if(this.graph.getNode(e)===null)throw new P("failed to remove non existing node");return this.graphStore.removeNode(e),this}markPort(e){const t=this.portIdGenerator.create(e.id);if(this.graph.getPort(t)!==null)throw new P("failed to add port with existing id");if(this.graph.getNode(e.nodeId)===null)throw new P("failed to mark port for nonexistent node");return this.graphStore.addPort({id:t,element:e.element,nodeId:e.nodeId,direction:e.direction??this.params.ports.direction}),this}updatePort(e,t){if(this.graph.getPort(e)===null)throw new P("failed to update nonexistent port");return this.graphStore.updatePort(e,t??{}),this}unmarkPort(e){if(this.graph.getPort(e)===null)throw new P("failed to unmark non existing port");return this.graphStore.removePort(e),this}addEdge(e){const t=this.edgeIdGenerator.create(e.id);if(this.graph.getEdge(t)!==null)throw new P("failed to add edge with existing id");if(this.graph.getPort(e.from)===null)throw new P("failed to add edge from nonexistent port");if(this.graph.getPort(e.to)===null)throw new P("failed to add edge to nonexistent port");return this.graphStore.addEdge({id:t,from:e.from,to:e.to,shape:e.shape??this.params.edges.shapeFactory(t),priority:e.priority??this.params.edges.priorityFn()}),this}updateEdge(e,t){if(this.graph.getEdge(e)===null)throw new P("failed to update nonexistent edge");return this.graphStore.updateEdge(e,t??{}),this}removeEdge(e){if(this.graph.getEdge(e)===null)throw new P("failed to remove nonexistent edge");return this.graphStore.removeEdge(e),this}patchViewportMatrix(e){return this.viewportStore.patchViewportMatrix(e),this}patchContentMatrix(e){return this.viewportStore.patchContentMatrix(e),this}clear(){return this.graphStore.clear(),this}destroy(){this.destroyed||(this.clear(),this.onBeforeDestroyEmitter.emit(),this.graphStore.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.unsubscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.unsubscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.unsubscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.unsubscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.unsubscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.unsubscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.unsubscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.unsubscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.unsubscribe(this.onBeforeClear),this.htmlView.destroy(),this.destroyed=!0)}}class ke{constructor(){o(this,"singleToMultiMap",new Map);o(this,"multiToSingleMap",new Map)}addRecord(e,t){const s=this.singleToMultiMap.get(e);s===void 0?this.singleToMultiMap.set(e,new Set([t])):s.add(t),this.multiToSingleMap.set(t,e)}getMultiBySingle(e){const t=this.singleToMultiMap.get(e)??new Set;return Array.from(t.values())}removeByMulti(e){const t=this.multiToSingleMap.get(e),s=this.singleToMultiMap.get(t);s.delete(e),s.size===0&&this.singleToMultiMap.delete(t),this.multiToSingleMap.delete(e)}getByMulti(e){return this.multiToSingleMap.get(e)}removeBySingle(e){this.singleToMultiMap.get(e).forEach(s=>{this.multiToSingleMap.delete(s)}),this.singleToMultiMap.delete(e)}clear(){this.singleToMultiMap.clear(),this.multiToSingleMap.clear()}forEachSingle(e){this.singleToMultiMap.forEach((t,s)=>{e(s)})}hasSingle(e){return this.singleToMultiMap.get(e)!==void 0}hasMulti(e){return this.multiToSingleMap.get(e)!==void 0}}class ae{constructor(){o(this,"nodes",new Map);o(this,"ports",new Map);o(this,"edges",new Map);o(this,"nodesElementsMap",new Map);o(this,"incomingEdges",new Map);o(this,"outcomingEdges",new Map);o(this,"cycleEdges",new Map);o(this,"elementPorts",new ke);o(this,"afterNodeAddedEmitter");o(this,"onAfterNodeAdded");o(this,"afterNodeUpdatedEmitter");o(this,"onAfterNodeUpdated");o(this,"afterNodePriorityUpdatedEmitter");o(this,"onAfterNodePriorityUpdated");o(this,"beforeNodeRemovedEmitter");o(this,"onBeforeNodeRemoved");o(this,"afterPortAddedEmitter");o(this,"onAfterPortAdded");o(this,"afterPortUpdatedEmitter");o(this,"onAfterPortUpdated");o(this,"beforePortRemovedEmitter");o(this,"onBeforePortRemoved");o(this,"afterEdgeAddedEmitter");o(this,"onAfterEdgeAdded");o(this,"afterEdgeShapeUpdatedEmitter");o(this,"onAfterEdgeShapeUpdated");o(this,"afterEdgeUpdatedEmitter");o(this,"onAfterEdgeUpdated");o(this,"afterEdgePriorityUpdatedEmitter");o(this,"onAfterEdgePriorityUpdated");o(this,"beforeEdgeRemovedEmitter");o(this,"onBeforeEdgeRemoved");o(this,"beforeClearEmitter");o(this,"onBeforeClear");[this.afterNodeAddedEmitter,this.onAfterNodeAdded]=A(),[this.afterNodeUpdatedEmitter,this.onAfterNodeUpdated]=A(),[this.afterNodePriorityUpdatedEmitter,this.onAfterNodePriorityUpdated]=A(),[this.beforeNodeRemovedEmitter,this.onBeforeNodeRemoved]=A(),[this.afterPortAddedEmitter,this.onAfterPortAdded]=A(),[this.afterPortUpdatedEmitter,this.onAfterPortUpdated]=A(),[this.beforePortRemovedEmitter,this.onBeforePortRemoved]=A(),[this.afterEdgeAddedEmitter,this.onAfterEdgeAdded]=A(),[this.afterEdgeShapeUpdatedEmitter,this.onAfterEdgeShapeUpdated]=A(),[this.afterEdgeUpdatedEmitter,this.onAfterEdgeUpdated]=A(),[this.afterEdgePriorityUpdatedEmitter,this.onAfterEdgePriorityUpdated]=A(),[this.beforeEdgeRemovedEmitter,this.onBeforeEdgeRemoved]=A(),[this.beforeClearEmitter,this.onBeforeClear]=A()}addNode(e){const t=new Map,s={element:e.element,x:e.x,y:e.y,centerFn:e.centerFn,priority:e.priority,ports:t};this.nodes.set(e.id,s),this.nodesElementsMap.set(e.element,e.id),this.afterNodeAddedEmitter.emit(e.id)}getAllNodeIds(){return Array.from(this.nodes.keys())}getNode(e){return this.nodes.get(e)}getElementNodeId(e){return this.nodesElementsMap.get(e)}updateNode(e,t){const s=this.nodes.get(e);s.x=t.x??s.x,s.y=t.y??s.y,s.centerFn=t.centerFn??s.centerFn,t.priority!==void 0&&(s.priority=t.priority,this.afterNodePriorityUpdatedEmitter.emit(e)),this.afterNodeUpdatedEmitter.emit(e)}removeNode(e){this.beforeNodeRemovedEmitter.emit(e);const t=this.nodes.get(e);this.nodesElementsMap.delete(t.element),this.nodes.delete(e)}addPort(e){this.ports.set(e.id,{element:e.element,direction:e.direction,nodeId:e.nodeId}),this.elementPorts.addRecord(e.element,e.id),this.cycleEdges.set(e.id,new Set),this.incomingEdges.set(e.id,new Set),this.outcomingEdges.set(e.id,new Set),this.nodes.get(e.nodeId).ports.set(e.id,e.element),this.afterPortAddedEmitter.emit(e.id)}getPort(e){return this.ports.get(e)}updatePort(e,t){const s=this.ports.get(e);s.direction=t.direction??s.direction,this.afterPortUpdatedEmitter.emit(e)}getAllPortIds(){return Array.from(this.ports.keys())}getElementPortIds(e){return this.elementPorts.getMultiBySingle(e)}getNodePortIds(e){const t=this.nodes.get(e);if(t!==void 0)return Array.from(t.ports.keys())}removePort(e){const t=this.ports.get(e).nodeId;this.beforePortRemovedEmitter.emit(e),this.nodes.get(t).ports.delete(e),this.ports.delete(e),this.elementPorts.removeByMulti(e)}addEdge(e){this.addEdgeInternal(e),this.afterEdgeAddedEmitter.emit(e.id)}updateEdge(e,t){if(t.from!==void 0||t.to!==void 0){const i=this.edges.get(e);this.removeEdgeInternal(e),this.addEdgeInternal({id:e,from:t.from??i.from,to:t.to??i.to,shape:i.shape,priority:i.priority})}const s=this.edges.get(e);t.shape!==void 0&&(s.shape=t.shape,this.afterEdgeShapeUpdatedEmitter.emit(e)),t.priority!==void 0&&(s.priority=t.priority,this.afterEdgePriorityUpdatedEmitter.emit(e)),this.afterEdgeUpdatedEmitter.emit(e)}getAllEdgeIds(){return Array.from(this.edges.keys())}getEdge(e){return this.edges.get(e)}removeEdge(e){this.beforeEdgeRemovedEmitter.emit(e),this.removeEdgeInternal(e)}clear(){this.beforeClearEmitter.emit(),this.incomingEdges.clear(),this.outcomingEdges.clear(),this.cycleEdges.clear(),this.elementPorts.clear(),this.nodesElementsMap.clear(),this.edges.clear(),this.ports.clear(),this.nodes.clear()}getPortIncomingEdgeIds(e){return Array.from(this.incomingEdges.get(e))}getPortOutgoingEdgeIds(e){return Array.from(this.outcomingEdges.get(e))}getPortCycleEdgeIds(e){return Array.from(this.cycleEdges.get(e))}getPortAdjacentEdgeIds(e){return[...this.getPortIncomingEdgeIds(e),...this.getPortOutgoingEdgeIds(e),...this.getPortCycleEdgeIds(e)]}getNodeIncomingEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys());let s=[];return t.forEach(i=>{s=[...s,...this.getPortIncomingEdgeIds(i)]}),s}getNodeOutgoingEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys());let s=[];return t.forEach(i=>{s=[...s,...this.getPortOutgoingEdgeIds(i)]}),s}getNodeCycleEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys());let s=[];return t.forEach(i=>{s=[...s,...this.getPortCycleEdgeIds(i)]}),s}getNodeAdjacentEdgeIds(e){return[...this.getNodeIncomingEdgeIds(e),...this.getNodeOutgoingEdgeIds(e),...this.getNodeCycleEdgeIds(e)]}addEdgeInternal(e){this.edges.set(e.id,{from:e.from,to:e.to,shape:e.shape,priority:e.priority}),e.from!==e.to?(this.outcomingEdges.get(e.from).add(e.id),this.incomingEdges.get(e.to).add(e.id)):this.cycleEdges.get(e.from).add(e.id)}removeEdgeInternal(e){const t=this.edges.get(e),s=t.from,i=t.to;this.cycleEdges.get(s).delete(e),this.cycleEdges.get(i).delete(e),this.incomingEdges.get(s).delete(e),this.incomingEdges.get(i).delete(e),this.outcomingEdges.get(s).delete(e),this.outcomingEdges.get(i).delete(e),this.edges.delete(e)}}const he=r=>({scale:1/r.scale,x:-r.x/r.scale,y:-r.y/r.scale}),de={scale:1,x:0,y:0};class He{constructor(){o(this,"viewportMatrix",de);o(this,"contentMatrix",de);o(this,"afterUpdateEmitter");o(this,"onAfterUpdated");o(this,"beforeUpdateEmitter");o(this,"onBeforeUpdated");[this.afterUpdateEmitter,this.onAfterUpdated]=A(),[this.beforeUpdateEmitter,this.onBeforeUpdated]=A()}getViewportMatrix(){return this.viewportMatrix}getContentMatrix(){return this.contentMatrix}patchViewportMatrix(e){this.beforeUpdateEmitter.emit(),this.viewportMatrix={scale:e.scale??this.viewportMatrix.scale,x:e.x??this.viewportMatrix.x,y:e.y??this.viewportMatrix.y},this.contentMatrix=he(this.viewportMatrix),this.afterUpdateEmitter.emit()}patchContentMatrix(e){this.beforeUpdateEmitter.emit(),this.contentMatrix={scale:e.scale??this.contentMatrix.scale,x:e.x??this.contentMatrix.x,y:e.y??this.contentMatrix.y},this.viewportMatrix=he(this.contentMatrix),this.afterUpdateEmitter.emit()}}class Y{constructor(e){o(this,"elementToNodeId",new Map);o(this,"nodesResizeObserver");o(this,"onAfterNodeAdded",e=>{const t=this.canvas.graph.getNode(e);this.elementToNodeId.set(t.element,e),this.nodesResizeObserver.observe(t.element)});o(this,"onBeforeNodeRemoved",e=>{const t=this.canvas.graph.getNode(e);this.elementToNodeId.delete(t.element),this.nodesResizeObserver.unobserve(t.element)});o(this,"onBeforeClear",()=>{this.nodesResizeObserver.disconnect(),this.elementToNodeId.clear()});this.canvas=e,this.nodesResizeObserver=new ResizeObserver(t=>{t.forEach(s=>{const i=s.target;this.handleNodeResize(i)})}),this.canvas.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.canvas.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear)}static configure(e){new Y(e)}handleNodeResize(e){const t=this.elementToNodeId.get(e);this.canvas.updateNode(t)}}const Xe=(r,e,t)=>{const{x:s,y:i,width:n,height:a}=r.getBoundingClientRect();return e>=s&&e<=s+n&&t>=i&&t<=i+a},Ye=(r,e,t)=>e>=0&&e<=r.innerWidth&&t>=0&&t<=r.innerHeight,V=(r,e,t,s)=>Xe(e,t,s)&&Ye(r,t,s),W=(r,e)=>{e!==null?r.style.cursor=e:r.style.removeProperty("cursor")},B=r=>{const e=document.createElement("div");return{id:r.overlayId,element:e,x:r.portCoords.x,y:r.portCoords.y,ports:[{id:r.overlayId,element:e,direction:r.portDirection}]}},je=(r,e)=>{let t=e,s=null;for(;t!==null&&(s=r.getElementPortIds(t)[0]??null,s===null);)t=t.parentElement;return s},ce=(r,e)=>{const t=document.elementsFromPoint(e.x,e.y);for(const s of t){const i=je(r,s);if(i!==null)return i}return null};var D=(r=>(r.Static="static",r.Dragging="dragging",r.Edge="edge",r))(D||{});const ge=(r,e)=>({x:r/2,y:e/2}),m=(r,e,t)=>({x:e.x*r.x-e.y*r.y+((1-e.x)*t.x+e.y*t.y),y:e.y*r.x+e.x*r.y+((1-e.x)*t.y-e.y*t.x)}),u={x:0,y:0};class Ge{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=m({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u),i=m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to),n={x:s.x+this.params.sourceDirection.x*this.params.curvature,y:s.y+this.params.sourceDirection.y*this.params.curvature},a={x:i.x-this.params.targetDirection.x*this.params.curvature,y:i.y-this.params.targetDirection.y*this.params.curvature},h=`M ${s.x} ${s.y} C ${n.x} ${n.y}, ${a.x} ${a.y}, ${i.x} ${i.y}`,d=this.params.hasSourceArrow?"":`M ${u.x} ${u.y} L ${s.x} ${s.y} `,c=this.params.hasTargetArrow?"":` M ${i.x} ${i.y} L ${this.params.to.x} ${this.params.to.y}`;this.path=`${d}${h}${c}`}}const $=(r,e,t,s)=>({x:e*r.x+(1-e)/2*s.x,y:t*r.y+(1-t)/2*s.y});class Ke{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength,n=Math.cos(this.params.detourDirection)*this.params.detourDistance,a=Math.sin(this.params.detourDirection)*this.params.detourDistance,h=n*this.params.flipX,d=a*this.params.flipY,c=m({x:i,y:u.y},this.params.sourceDirection,u),l={x:c.x+h,y:c.y+d},g=m({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),w={x:g.x+h,y:g.y+d},f={x:(l.x+w.x)/2,y:(l.y+w.y)/2},y={x:c.x+this.params.curvature*this.params.sourceDirection.x,y:c.y+this.params.curvature*this.params.sourceDirection.y},x={x:g.x-this.params.curvature*this.params.targetDirection.x,y:g.y-this.params.curvature*this.params.targetDirection.y},S={x:c.x+h,y:c.y+d},b={x:g.x+h,y:g.y+d};this.path=[`M ${t.x} ${t.y}`,`L ${c.x} ${c.y}`,`C ${y.x} ${y.y} ${S.x} ${S.y} ${f.x} ${f.y}`,`C ${b.x} ${b.y} ${x.x} ${x.y} ${g.x} ${g.y}`,`L ${s.x} ${s.y}`].join(" "),this.midpoint=$(f,e.flipX,e.flipY,e.to)}}const L=(r,e)=>{const t=[];if(r.length>0&&t.push(`M ${r[0].x} ${r[0].y}`),r.length===2&&t.push(`L ${r[1].x} ${r[1].y}`),r.length>2){const s=r.length-1;let i=0,n=0,a=0;r.forEach((h,d)=>{let c=0,l=0,g=0;const w=d>0,f=d<s,y=w&&f;if(w&&(c=-i,l=-n,g=a),f){const U=r[d+1];i=U.x-h.x,n=U.y-h.y,a=Math.sqrt(i*i+n*n)}const S=a!==0?Math.min((y?e:0)/a,d<s-1?.5:1):0,b=y?{x:h.x+i*S,y:h.y+n*S}:h,M=g!==0?Math.min((y?e:0)/g,d>1?.5:1):0,R=y?{x:h.x+c*M,y:h.y+l*M}:h;d>0&&t.push(`L ${R.x} ${R.y}`),y&&t.push(`C ${h.x} ${h.y} ${h.x} ${h.y} ${b.x} ${b.y}`)})}return t.join(" ")};class Ze{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=m({x:a,y:u.y},this.params.sourceDirection,u),d=m({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.x+d.x)/2,n),l=this.params.to.y/2,g={x:this.params.flipX>0?c:-n,y:h.y},w={x:g.x,y:l},f={x:this.params.flipX>0?this.params.to.x-c:this.params.to.x+n,y:d.y},y={x:f.x,y:l};this.path=L([s,h,g,w,y,f,d,i],this.params.roundness)}}class Je{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=m({x:i,y:u.y},this.params.sourceDirection,u),a=Math.cos(this.params.detourDirection)*this.params.detourDistance,h=Math.sin(this.params.detourDirection)*this.params.detourDistance,d=a*this.params.flipX,c=h*this.params.flipY,l={x:n.x+d,y:n.y+c},g=m({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),w={x:g.x+d,y:g.y+c},f={x:(l.x+w.x)/2,y:(l.y+w.y)/2};this.midpoint=$(f,e.flipX,e.flipY,e.to),this.path=L([t,n,l,w,g,s],this.params.roundness)}}class Qe{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=m({x:n,y:u.y},this.params.sourceDirection,u),h=m({x:this.params.to.x-n,y:this.params.to.y},this.params.targetDirection,this.params.to);this.path=L([s,a,h,i],this.params.roundness)}}class _e{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=m({x:a,y:u.y},this.params.sourceDirection,u),d=m({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.y+d.y)/2,n),l=this.params.to.x/2,g={x:h.x,y:this.params.flipY>0?c:-n},w={x:l,y:g.y},f={x:d.x,y:this.params.flipY>0?this.params.to.y-c:this.params.to.y+n},y={x:l,y:f.y};this.path=L([s,h,g,w,y,f,d,i],this.params.roundness)}}class j{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.arrowOffset,s=this.params.side,i=this.params.arrowLength+t,n=i+2*s,h=[{x:this.params.arrowLength,y:u.y},{x:i,y:u.y},{x:i,y:this.params.side},{x:n,y:this.params.side},{x:n,y:-this.params.side},{x:i,y:-this.params.side},{x:i,y:u.y},{x:this.params.arrowLength,y:u.y}].map(c=>m(c,this.params.sourceDirection,u)),d=`M ${u.x} ${u.y} L ${h[0].x} ${h[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":d}${L(h,this.params.roundness)}`,this.midpoint={x:(h[3].x+h[4].x)/2,y:(h[3].y+h[4].y)/2}}}class qe{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.smallRadius,s=this.params.radius,i=t+s,n=t*s/i,a=Math.sqrt(i*i-t*t),h=a*t/i,d=a+s+this.params.arrowLength,c=this.params.arrowLength+h,g=[{x:this.params.arrowLength,y:u.y},{x:c,y:n},{x:c,y:-n},{x:d,y:0}].map(y=>m(y,this.params.sourceDirection,u)),w=[`M ${g[0].x} ${g[0].y}`,`A ${t} ${t} 0 0 1 ${g[1].x} ${g[1].y}`,`A ${s} ${s} 0 1 0 ${g[2].x} ${g[2].y}`,`A ${t} ${t} 0 0 1 ${g[0].x} ${g[0].y}`].join(" "),f=`M 0 0 L ${g[0].x} ${g[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":f}${w}`,this.midpoint=g[3]}}class et{constructor(e){o(this,"path");o(this,"midpoint");o(this,"diagonalDistance");this.params=e;const t=this.params.to;if(this.midpoint={x:t.x/2,y:t.y/2},this.diagonalDistance=Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y),Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y)===0){this.path="";return}const i=this.createDirectLinePoint({offset:this.params.sourceOffset,hasArrow:this.params.hasSourceArrow,flip:1,shift:u}),n=this.createDirectLinePoint({offset:this.params.targetOffset,hasArrow:this.params.hasTargetArrow,flip:-1,shift:this.params.to});this.path=`M ${i.x} ${i.y} L ${n.x} ${n.y}`}createDirectLinePoint(e){const t=e.hasArrow?this.params.arrowLength:0,s=e.offset+t,i=e.flip*s/this.diagonalDistance;return{x:this.params.to.x*i+e.shift.x,y:this.params.to.y*i+e.shift.y}}}class tt{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=m({x:i,y:u.y},this.params.sourceDirection,u),a=m({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.y/2,c=d+Math.abs(this.params.detourDistance),l=d+c*this.params.flipY*h,g={x:(n.x+a.x)/2,y:l};this.midpoint=$(g,e.flipX,e.flipY,e.to),this.path=L([t,n,{x:n.x,y:l},{x:a.x,y:l},a,s],this.params.roundness)}}class rt{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=m({x:i,y:u.y},this.params.sourceDirection,u),a=m({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.x/2,c=d+Math.abs(this.params.detourDistance),l=d+c*this.params.flipX*h,g={x:l,y:(n.y+a.y)/2};this.midpoint=$(g,e.flipX,e.flipY,e.to),this.path=L([t,n,{x:l,y:n.y},{x:l,y:a.y},a,s],this.params.roundness)}}const le=(r,e)=>{r.style.transform=`translate(${e.x}px, ${e.y}px)`,r.style.width=`${Math.max(e.width,1)}px`,r.style.height=`${Math.max(e.height,1)}px`},G=Object.freeze({edgeColor:"--edge-color"}),ue=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.style.pointerEvents="none",e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.overflow="visible",e.style.setProperty(G.edgeColor,r),e},F=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("fill",`var(${G.edgeColor})`),r},pe=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.transformOrigin="50% 50%",r},we=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke",`var(${G.edgeColor})`),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","none"),e},fe=(r,e)=>{const t={x:r.x+r.width/2,y:r.y+r.height/2},s={x:e.x+e.width/2,y:e.y+e.height/2},i=Math.min(t.x,s.x),n=Math.min(t.y,s.y),a=Math.abs(s.x-t.x),h=Math.abs(s.y-t.y),d=t.x<=s.x?1:-1,c=t.y<=s.y?1:-1;return{x:i,y:n,width:a,height:h,flipX:d,flipY:c}},K=(r,e,t,s)=>{const n=[u,{x:t,y:s},{x:t,y:-s}].map(c=>m(c,r,u)).map(c=>({x:c.x+e.x,y:c.y+e.y})),a=`M ${n[0].x} ${n[0].y}`,h=`L ${n[1].x} ${n[1].y}`,d=`L ${n[2].x} ${n[2].y}`;return`${a} ${h} ${d} Z`},p=Object.freeze({color:"#777777",width:1,arrowLength:15,arrowWidth:4,arrowOffset:15,hasSourceArrow:!1,hasTargetArrow:!1,cycleRadius:30,cycleSquareSide:30,roundness:10,detourDistance:100,detourDirection:-Math.PI/2,detourDirectionVertical:0,smallCycleRadius:15,curvature:90,interactiveWidth:10,preOffset:0}),me=(r,e,t)=>({x:e*Math.cos(r),y:t*Math.sin(r)});class I{constructor(e){o(this,"svg");o(this,"group",pe());o(this,"line");o(this,"sourceArrow",null);o(this,"targetArrow",null);o(this,"onAfterRender");o(this,"afterRenderEmitter");this.params=e,[this.afterRenderEmitter,this.onAfterRender]=A(),this.svg=ue(e.color),this.svg.appendChild(this.group),this.line=we(e.width),this.group.appendChild(this.line),e.hasSourceArrow&&(this.sourceArrow=F(),this.group.appendChild(this.sourceArrow)),e.hasTargetArrow&&(this.targetArrow=F(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:i,height:n,flipX:a,flipY:h}=fe(e.from,e.to);le(this.svg,{x:t,y:s,width:i,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d=me(e.from.direction,a,h),c=me(e.to.direction,a,h),l={x:i,y:n};let g=c,w=-this.params.arrowLength,f;e.category===T.PortCycle?(f=this.params.createCyclePath,g=d,w=this.params.arrowLength):e.category===T.NodeCycle?f=this.params.createDetourPath:f=this.params.createLinePath;const y=f(d,c,l,a,h);this.line.setAttribute("d",y.path);let x=null;this.sourceArrow&&(x=K(d,u,this.params.arrowLength,this.params.arrowWidth),this.sourceArrow.setAttribute("d",x));let S=null;this.targetArrow&&(S=K(g,l,w,this.params.arrowWidth),this.targetArrow.setAttribute("d",S)),this.afterRenderEmitter.emit({edgePath:y,sourceArrowPath:x,targetArrowPath:S})}}class ye{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowWidth");o(this,"curvature");o(this,"portCycleRadius");o(this,"portCycleSmallRadius");o(this,"detourDirection");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new qe({sourceDirection:e,radius:this.portCycleRadius,smallRadius:this.portCycleSmallRadius,arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new Ke({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,detourDirection:this.detourDirection,detourDistance:this.detourDistance,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s)=>new Ge({to:s,sourceDirection:e,targetDirection:t,arrowLength:this.arrowLength,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??p.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??p.arrowWidth,this.curvature=(e==null?void 0:e.curvature)??p.curvature,this.portCycleRadius=(e==null?void 0:e.cycleRadius)??p.cycleRadius,this.portCycleSmallRadius=(e==null?void 0:e.smallCycleRadius)??p.smallCycleRadius,this.detourDirection=(e==null?void 0:e.detourDirection)??p.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??p.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??p.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??p.hasTargetArrow,this.pathShape=new I({color:(e==null?void 0:e.color)??p.color,width:(e==null?void 0:e.width)??p.width,arrowLength:this.arrowLength,arrowWidth:this.arrowWidth,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class ve{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowWidth");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new j({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new tt({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s,i)=>new Ze({to:s,sourceDirection:e,targetDirection:t,flipX:i,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??p.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??p.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??p.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??p.cycleSquareSide;const t=(e==null?void 0:e.roundness)??p.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(e==null?void 0:e.detourDistance)??p.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??p.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??p.hasTargetArrow,this.pathShape=new I({color:(e==null?void 0:e.color)??p.color,width:(e==null?void 0:e.width)??p.width,arrowLength:this.arrowLength,arrowWidth:this.arrowWidth,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Ee{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowWidth");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDirection");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new j({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new Je({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s)=>new Qe({to:s,sourceDirection:e,targetDirection:t,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??p.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??p.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??p.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??p.cycleSquareSide;const t=(e==null?void 0:e.roundness)??p.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??p.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??p.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??p.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??p.hasTargetArrow,this.pathShape=new I({color:(e==null?void 0:e.color)??p.color,width:(e==null?void 0:e.width)??p.width,arrowLength:this.arrowLength,arrowWidth:this.arrowWidth,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Ae{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowWidth");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new j({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new rt({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s,i,n)=>new _e({to:s,sourceDirection:e,targetDirection:t,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??p.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??p.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??p.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??p.cycleSquareSide;const t=(e==null?void 0:e.roundness)??p.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(e==null?void 0:e.detourDistance)??p.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??p.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??p.hasTargetArrow,this.pathShape=new I({color:(e==null?void 0:e.color)??p.color,width:(e==null?void 0:e.width)??p.width,arrowLength:this.arrowLength,arrowWidth:this.arrowWidth,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}const xe=r=>{if(r.diagonalDistance===0)return"";const e=r.offset/r.diagonalDistance,t=r.flip*r.to.x,s=r.flip*r.to.y,i={x:t*e+r.shift.x,y:s*e+r.shift.y},n={x:t/r.diagonalDistance,y:s/r.diagonalDistance};return K(n,i,r.arrowLength,r.arrowWidth)};class Z{constructor(e){o(this,"svg");o(this,"group",pe());o(this,"line");o(this,"sourceArrow",null);o(this,"targetArrow",null);o(this,"color");o(this,"width");o(this,"arrowLength");o(this,"arrowWidth");o(this,"sourceOffset");o(this,"targetOffset");o(this,"onAfterRender");o(this,"afterRenderEmitter");[this.afterRenderEmitter,this.onAfterRender]=A(),this.color=(e==null?void 0:e.color)??p.color,this.width=(e==null?void 0:e.width)??p.width,this.arrowLength=(e==null?void 0:e.arrowLength)??p.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??p.arrowWidth,this.sourceOffset=(e==null?void 0:e.sourceOffset)??p.preOffset,this.targetOffset=(e==null?void 0:e.targetOffset)??p.preOffset,this.svg=ue(this.color),this.svg.appendChild(this.group),this.line=we(this.width),this.group.appendChild(this.line),e!=null&&e.hasSourceArrow&&(this.sourceArrow=F(),this.group.appendChild(this.sourceArrow)),e!=null&&e.hasTargetArrow&&(this.targetArrow=F(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:i,height:n,flipX:a,flipY:h}=fe(e.from,e.to);le(this.svg,{x:t,y:s,width:i,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d={x:i,y:n},c=new et({to:d,sourceOffset:this.sourceOffset,targetOffset:this.targetOffset,hasSourceArrow:this.sourceArrow!==null,hasTargetArrow:this.targetArrow!==null,arrowLength:this.arrowLength});this.line.setAttribute("d",c.path);let l=null;this.sourceArrow&&(l=xe({diagonalDistance:c.diagonalDistance,to:d,offset:this.sourceOffset,flip:1,shift:u,arrowWidth:this.arrowWidth,arrowLength:this.arrowLength}),this.sourceArrow.setAttribute("d",l));let g=null;this.targetArrow&&(g=xe({diagonalDistance:c.diagonalDistance,to:d,offset:this.targetOffset,flip:-1,shift:d,arrowWidth:this.arrowWidth,arrowLength:this.arrowLength}),this.targetArrow.setAttribute("d",g)),this.afterRenderEmitter.emit({edgePath:c,sourceArrowPath:l,targetArrowPath:g})}}const ot=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.pointerEvents="auto",r.style.cursor="pointer",r},st=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke","transparent"),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","none"),e.setAttribute("stroke-linecap","round"),e},Se=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke-linejoin","round"),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","transparent"),e.setAttribute("stroke","transparent"),e};class Pe extends Error{constructor(e){super(e),this.name="InteractiveEdgeError"}}class J{constructor(e,t){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"handle",ot());o(this,"onAfterRender");o(this,"interactiveLine");o(this,"interactiveSourceArrow",null);o(this,"interactiveTargetArrow",null);if(this.baseEdge=e,e instanceof J)throw new Pe("interactive edge can be configured only once");this.svg=this.baseEdge.svg,this.group=this.baseEdge.group,this.line=this.baseEdge.line,this.sourceArrow=this.baseEdge.sourceArrow,this.targetArrow=this.baseEdge.targetArrow,this.onAfterRender=this.baseEdge.onAfterRender;const s=(t==null?void 0:t.width)??p.interactiveWidth;this.interactiveLine=st(s),this.handle.appendChild(this.interactiveLine),this.sourceArrow&&(this.interactiveSourceArrow=Se(s),this.handle.appendChild(this.interactiveSourceArrow)),this.targetArrow&&(this.interactiveTargetArrow=Se(s),this.handle.appendChild(this.interactiveTargetArrow)),this.group.appendChild(this.handle),this.baseEdge.onAfterRender.subscribe(i=>{this.interactiveLine.setAttribute("d",i.edgePath.path),this.interactiveSourceArrow&&this.interactiveSourceArrow.setAttribute("d",i.sourceArrowPath),this.interactiveTargetArrow&&this.interactiveTargetArrow.setAttribute("d",i.targetArrowPath)})}render(e){this.baseEdge.render(e)}}class be{constructor(e,t){o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"svg");o(this,"medianElement");this.baseShape=e,this.midpointElement=t,this.medianElement=this.midpointElement,this.svg=this.baseShape.svg,this.group=this.baseShape.group,this.line=this.baseShape.line,this.sourceArrow=this.baseShape.sourceArrow,this.targetArrow=this.baseShape.targetArrow,this.onAfterRender=this.baseShape.onAfterRender,this.svg.append(this.midpointElement),this.baseShape.onAfterRender.subscribe(s=>{const i=s.edgePath.midpoint,n=`translate(${i.x}px, ${i.y}px)`;this.midpointElement.style.setProperty("transform",n)})}render(e){this.baseShape.render(e)}}const Te=(r,e)=>{const t=new ae,s=new ie(t,e,r),i={nodes:{centerFn:ge,priorityFn:()=>0},edges:{shapeFactory:()=>new Z,priorityFn:()=>0},ports:{direction:0}};return new ne(r,t,e,s,i)};class O{constructor(e,t,s,i){o(this,"onAfterPortMarked",e=>{const t=this.canvas.graph.getPort(e);this.canvas.graph.getElementPortIds(t.element).length===1&&this.hookPortEvents(t.element)});o(this,"onBeforePortUnmarked",e=>{const t=this.canvas.graph.getPort(e);this.canvas.graph.getElementPortIds(t.element).length===1&&this.unhookPortEvents(t.element)});o(this,"onPortMouseDown",e=>{if(!this.params.mouseDownEventVerifier(e))return;const t=e.currentTarget,s=this.canvas.graph.getElementPortIds(t)[0];this.params.onPortPointerDown(s,{x:e.clientX,y:e.clientY})&&(e.stopPropagation(),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}))});o(this,"onWindowMouseMove",e=>{if(!V(this.window,this.element,e.clientX,e.clientY)){this.stopMouseDrag();return}this.params.onPointerMove({x:e.clientX,y:e.clientY})});o(this,"onWindowMouseUp",e=>{this.params.mouseUpEventVerifier(e)&&(this.params.onPointerUp({x:e.clientX,y:e.clientY}),this.stopMouseDrag())});o(this,"onPortTouchStart",e=>{if(e.touches.length!==1)return;const t=e.touches[0],s=e.currentTarget,i=this.canvas.graph.getElementPortIds(s)[0];this.params.onPortPointerDown(i,{x:t.clientX,y:t.clientY})&&(e.stopPropagation(),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}))});o(this,"onWindowTouchMove",e=>{const t=e.touches[0];if(!V(this.window,this.element,t.clientX,t.clientY)){this.stopTouchDrag();return}this.params.onPointerMove({x:t.clientX,y:t.clientY})});o(this,"onWindowTouchFinish",e=>{const t=e.changedTouches[0];this.params.onPointerUp({x:t.clientX,y:t.clientY}),this.stopTouchDrag()});o(this,"onBeforeClear",()=>{this.canvas.graph.getAllPortIds().forEach(e=>{const t=this.canvas.graph.getPort(e);this.unhookPortEvents(t.element)})});o(this,"onBeforeDestroy",()=>{this.params.onStopDrag(),this.removeWindowMouseListeners(),this.removeWindowTouchListeners()});this.canvas=e,this.element=t,this.window=s,this.params=i,this.canvas.graph.onAfterPortMarked.subscribe(this.onAfterPortMarked),this.canvas.graph.onBeforePortUnmarked.subscribe(this.onBeforePortUnmarked),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,i){new O(e,t,s,i)}hookPortEvents(e){e.addEventListener("mousedown",this.onPortMouseDown,{passive:!0}),e.addEventListener("touchstart",this.onPortTouchStart,{passive:!0})}unhookPortEvents(e){e.removeEventListener("mousedown",this.onPortMouseDown),e.removeEventListener("touchstart",this.onPortTouchStart)}stopMouseDrag(){this.params.onStopDrag(),this.removeWindowMouseListeners()}stopTouchDrag(){this.params.onStopDrag(),this.removeWindowTouchListeners()}removeWindowMouseListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}removeWindowTouchListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}class Q{constructor(e,t,s,i){o(this,"grabbedNode",null);o(this,"maxNodePriority",0);o(this,"graph");o(this,"onAfterNodeAdded",e=>{this.updateMaxNodePriority(e);const t=this.graph.getNode(e);t.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),t.element.addEventListener("touchstart",this.onTouchStart,{passive:!0})});o(this,"onAfterNodeUpdated",e=>{this.updateMaxNodePriority(e)});o(this,"onBeforeNodeRemoved",e=>{const t=this.graph.getNode(e);t.element.removeEventListener("mousedown",this.onMouseDown),t.element.removeEventListener("touchstart",this.onTouchStart)});o(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});o(this,"onBeforeClear",()=>{this.canvas.graph.getAllNodeIds().forEach(e=>{const t=this.canvas.graph.getNode(e);t.element.removeEventListener("mousedown",this.onMouseDown),t.element.removeEventListener("touchstart",this.onTouchStart)}),this.maxNodePriority=0});o(this,"onMouseDown",e=>{if(!this.params.mouseDownEventVerifier(e))return;const t=e.currentTarget,s=this.graph.getElementNodeId(t),i=this.graph.getNode(s);if(!this.params.nodeDragVerifier({nodeId:s,element:i.element,x:i.x,y:i.y}))return;e.stopPropagation();const a=this.calculateContentPoint({x:e.clientX,y:e.clientY});this.grabbedNode={nodeId:s,dx:a.x-i.x,dy:a.y-i.y},W(this.element,this.params.dragCursor),this.moveNodeOnTop(s),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0})});o(this,"onTouchStart",e=>{if(e.touches.length!==1)return;e.stopPropagation();const t=e.touches[0],s=e.currentTarget,i=this.canvas.graph.getElementNodeId(s),n=this.graph.getNode(i);if(!this.params.nodeDragVerifier({nodeId:i,element:n.element,x:n.x,y:n.y}))return;const h=this.calculateContentPoint({x:t.clientX,y:t.clientY});this.grabbedNode={nodeId:i,dx:h.x-n.x,dy:h.y-n.y},this.moveNodeOnTop(i),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0})});o(this,"onWindowMouseMove",e=>{if(!V(this.window,this.element,e.clientX,e.clientY)){this.cancelMouseDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:e.clientX,y:e.clientY})});o(this,"onWindowMouseUp",e=>{this.params.mouseUpEventVerifier(e)&&this.cancelMouseDrag()});o(this,"onWindowTouchMove",e=>{if(e.touches.length!==1)return;const t=e.touches[0];if(!V(this.window,this.element,t.clientX,t.clientY)){this.cancelTouchDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:t.clientX,y:t.clientY})});o(this,"onWindowTouchFinish",()=>{this.cancelTouchDrag()});this.canvas=e,this.element=t,this.window=s,this.params=i,this.graph=e.graph,this.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graph.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,i){new Q(e,t,s,i)}moveNode(e,t){const s=this.graph.getNode(e.nodeId);if(s===null)return;const i=this.calculateContentPoint(t),n={x:i.x-e.dx,y:i.y-e.dy},a=this.adjustNodeCoords(n);this.canvas.updateNode(e.nodeId,{x:a.x,y:a.y}),this.params.onNodeDrag({nodeId:e.nodeId,element:s.element,x:a.x,y:a.y})}moveNodeOnTop(e){if(this.params.moveOnTop){if(this.maxNodePriority++,this.params.moveEdgesOnTop){const t=this.maxNodePriority;this.maxNodePriority++,this.graph.getNodeAdjacentEdgeIds(e).forEach(i=>{this.canvas.updateEdge(i,{priority:t})})}this.canvas.updateNode(e,{priority:this.maxNodePriority})}}cancelMouseDrag(){if(this.grabbedNode!==null){const e=this.graph.getNode(this.grabbedNode.nodeId);e!==null&&this.params.onNodeDragFinished({nodeId:this.grabbedNode.nodeId,element:e.element,x:e.x,y:e.y})}this.grabbedNode=null,W(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}cancelTouchDrag(){if(this.grabbedNode!==null){const e=this.graph.getNode(this.grabbedNode.nodeId);e!==null&&this.params.onNodeDragFinished({nodeId:this.grabbedNode.nodeId,element:e.element,x:e.x,y:e.y})}this.grabbedNode=null,this.removeTouchDragListeners()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}updateMaxNodePriority(e){const t=this.graph.getNode(e).priority;this.maxNodePriority=Math.max(this.maxNodePriority,t)}calculateContentPoint(e){const t=this.element.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},i=this.canvas.viewport.getViewportMatrix();return E(i,s)}adjustNodeCoords(e){const t=this.params.gridSize;if(t!==null){const s=t/2;return{x:Math.floor((e.x+s)/t)*t,y:Math.floor((e.y+s)/t)*t}}return e}}const it=(r,e,t)=>({scale:r.scale,x:r.x+r.scale*e,y:r.y+r.scale*t}),nt=(r,e,t,s)=>({scale:r.scale*e,x:r.scale*(1-e)*t+r.x,y:r.scale*(1-e)*s+r.y}),z=r=>{const e=[],t=r.touches.length;for(let h=0;h<t;h++)e.push([r.touches[h].clientX,r.touches[h].clientY]);const s=e.reduce((h,d)=>[h[0]+d[0],h[1]+d[1]],[0,0]),i=[s[0]/t,s[1]/t],a=e.map(h=>[h[0]-i[0],h[1]-i[1]]).reduce((h,d)=>h+Math.sqrt(d[0]*d[0]+d[1]*d[1]),0);return{x:i[0],y:i[1],scale:a/t,touchesCnt:t,touches:e}};class k{constructor(e,t,s,i){o(this,"viewport");o(this,"prevTouches",null);o(this,"wheelFinishTimer",null);o(this,"transformInProgress",!1);o(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});o(this,"onMouseDown",e=>{this.element===null||!this.params.mouseDownEventVerifier(e)||(W(this.element,this.params.shiftCursor),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}),this.startRegisteredTransform())});o(this,"onWindowMouseMove",e=>{const t=V(this.window,this.element,e.clientX,e.clientY);if(this.element===null||!t){this.stopMouseDrag();return}const s=-e.movementX,i=-e.movementY;this.moveViewport(s,i)});o(this,"onWindowMouseUp",e=>{this.element===null||!this.params.mouseUpEventVerifier(e)||this.stopMouseDrag()});o(this,"onWheelScroll",e=>{if(!this.params.mouseWheelEventVerifier(e))return;const{left:t,top:s}=this.element.getBoundingClientRect(),i=e.clientX-t,n=e.clientY-s,h=1/(e.deltaY<0?this.params.wheelSensitivity:1/this.params.wheelSensitivity);this.wheelFinishTimer===null&&this.params.onTransformStarted(),this.scaleViewport(h,i,n),this.wheelFinishTimer!==null&&clearTimeout(this.wheelFinishTimer),this.wheelFinishTimer=setTimeout(()=>{this.transformInProgress||this.params.onTransformFinished(),this.wheelFinishTimer=null},this.params.scaleWheelFinishTimeout)});o(this,"onTouchStart",e=>{if(this.prevTouches!==null){this.prevTouches=z(e);return}this.prevTouches=z(e),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}),this.startRegisteredTransform()});o(this,"onWindowTouchMove",e=>{const t=z(e);if(!t.touches.every(i=>V(this.window,this.element,i[0],i[1]))){this.stopTouchDrag();return}if((t.touchesCnt===1||t.touchesCnt===2)&&this.moveViewport(-(t.x-this.prevTouches.x),-(t.y-this.prevTouches.y)),t.touchesCnt===2){const{left:i,top:n}=this.element.getBoundingClientRect(),a=this.prevTouches.x-i,h=this.prevTouches.y-n,c=1/(t.scale/this.prevTouches.scale);this.scaleViewport(c,a,h)}this.prevTouches=t});o(this,"onWindowTouchFinish",e=>{e.touches.length>0?this.prevTouches=z(e):this.stopTouchDrag()});o(this,"observer",new ResizeObserver(()=>{const e=this.viewport.getViewportMatrix(),{width:t,height:s}=this.element.getBoundingClientRect(),i=this.params.transformPreprocessor({prevTransform:e,nextTransform:e,canvasWidth:t,canvasHeight:s});this.params.onResizeTransformStarted(),this.canvas.patchViewportMatrix(i),this.params.onResizeTransformFinished()}));o(this,"preventWheelScaleListener",e=>{e.preventDefault()});this.canvas=e,this.element=t,this.window=s,this.params=i,this.element.addEventListener("wheel",this.preventWheelScaleListener,{passive:!1}),this.viewport=e.viewport,this.observer.observe(this.element),this.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),this.element.addEventListener("wheel",this.onWheelScroll,{passive:!0}),this.element.addEventListener("touchstart",this.onTouchStart,{passive:!0}),e.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,i){new k(e,t,s,i)}moveViewport(e,t){const s=this.viewport.getViewportMatrix(),i=it(s,e,t),{width:n,height:a}=this.element.getBoundingClientRect(),h=this.params.transformPreprocessor({prevTransform:s,nextTransform:i,canvasWidth:n,canvasHeight:a});this.performTransform(h)}scaleViewport(e,t,s){const i=this.canvas.viewport.getViewportMatrix(),n=nt(i,e,t,s),{width:a,height:h}=this.element.getBoundingClientRect(),d=this.params.transformPreprocessor({prevTransform:i,nextTransform:n,canvasWidth:a,canvasHeight:h});this.performTransform(d)}stopMouseDrag(){W(this.element,null),this.removeMouseDragListeners(),this.finishRegisteredTransform()}removeMouseDragListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}stopTouchDrag(){this.prevTouches=null,this.removeTouchDragListeners(),this.finishRegisteredTransform()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}performTransform(e){this.params.onBeforeTransformChange(),this.canvas.patchViewportMatrix(e),this.params.onTransformChange()}startRegisteredTransform(){this.transformInProgress=!0,this.params.onTransformStarted()}finishRegisteredTransform(){this.transformInProgress=!1,this.params.onTransformFinished()}}class _{constructor(e,t,s,i,n,a){o(this,"canvasResizeObserver");o(this,"nodeHorizontal");o(this,"nodeVertical");o(this,"viewport");o(this,"viewportWidth",0);o(this,"viewportHeight",0);o(this,"viewportMatrix");o(this,"loadedArea",{xFrom:1/0,xTo:1/0,yFrom:1/0,yTo:1/0});o(this,"updateLoadedArea",e=>{this.loadedArea={xFrom:e.x,xTo:e.x+e.width,yFrom:e.y,yTo:e.y+e.height}});o(this,"onAfterViewportUpdated",()=>{this.userTransformInProgress||(this.viewportMatrix=this.viewport.getViewportMatrix(),this.loadAreaAroundViewport())});o(this,"userTransformInProgress",!1);this.canvas=e,this.element=t,this.window=s,this.trigger=n,this.params=a,this.nodeHorizontal=this.params.nodeVerticalRadius,this.nodeVertical=this.params.nodeHorizontalRadius,this.canvasResizeObserver=new ResizeObserver(d=>{const c=d[0];this.viewportWidth=c.contentRect.width,this.viewportHeight=c.contentRect.height,this.scheduleLoadAreaAroundViewport()}),this.viewport=e.viewport;const h={...i,onResizeTransformStarted:()=>{this.userTransformInProgress=!0,i.onResizeTransformStarted()},onResizeTransformFinished:()=>{this.userTransformInProgress=!1,i.onResizeTransformFinished()},onBeforeTransformChange:()=>{this.userTransformInProgress=!0,i.onBeforeTransformChange()},onTransformChange:()=>{this.userTransformInProgress=!1;const d=this.viewportMatrix;this.viewportMatrix=this.viewport.getViewportMatrix(),d.scale!==this.viewportMatrix.scale&&this.scheduleEnsureViewportAreaLoaded(),i.onTransformChange()},onTransformFinished:()=>{this.scheduleLoadAreaAroundViewport(),i.onTransformFinished()}};k.configure(e,this.element,this.window,h),this.viewportMatrix=this.viewport.getViewportMatrix(),this.trigger.subscribe(this.updateLoadedArea),this.canvasResizeObserver.observe(this.element),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterViewportUpdated)}static configure(e,t,s,i,n,a){new _(e,t,s,i,n,a)}scheduleLoadAreaAroundViewport(){setTimeout(()=>{this.loadAreaAroundViewport()})}scheduleEnsureViewportAreaLoaded(){const e=this.viewportWidth*this.viewportMatrix.scale,t=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-this.nodeHorizontal,i=this.viewportMatrix.y-this.nodeVertical,n=this.viewportMatrix.x+e+this.nodeHorizontal,a=this.viewportMatrix.y+t+this.nodeVertical;this.loadedArea.xFrom<s&&this.loadedArea.xTo>n&&this.loadedArea.yFrom<i&&this.loadedArea.yTo>a||this.scheduleLoadAreaAroundViewport()}loadAreaAroundViewport(){const e=this.viewportWidth*this.viewportMatrix.scale,t=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-e-this.nodeHorizontal,i=this.viewportMatrix.y-t-this.nodeVertical,n=3*e+2*this.nodeHorizontal,a=3*t+2*this.nodeVertical;this.trigger.emit({x:s,y:i,width:n,height:a})}}const at=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.style.position="absolute",r.style.inset="0",r},ht=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","rect");return r.setAttribute("fill","url(#pattern)"),r},dt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","pattern");return r.setAttribute("id","pattern"),r};class q{constructor(e,t,s){o(this,"svg",at());o(this,"patternRenderingRectangle",ht());o(this,"pattern",dt());o(this,"patternContent");o(this,"tileWidth");o(this,"tileHeight");o(this,"halfTileWidth");o(this,"halfTileHeight");o(this,"maxViewportScale");o(this,"visible",!1);o(this,"resizeObserver",new ResizeObserver(e=>{const t=e[0],{width:s,height:i}=t.contentRect;this.svg.setAttribute("width",`${s}`),this.svg.setAttribute("height",`${i}`),this.patternRenderingRectangle.setAttribute("width",`${s}`),this.patternRenderingRectangle.setAttribute("height",`${i}`);const n=this.tileWidth/s,a=this.tileHeight/i;this.pattern.setAttribute("width",`${n}`),this.pattern.setAttribute("height",`${a}`)}));o(this,"onAfterTransformUpdated",()=>{const e=this.canvas.viewport.getContentMatrix(),t=e.x-this.halfTileWidth*e.scale,s=e.y-this.halfTileHeight*e.scale,i=`matrix(${e.scale}, 0, 0, ${e.scale}, ${t}, ${s})`;this.pattern.setAttribute("patternTransform",i),this.updateVisibility()});this.canvas=e,this.backgroundHost=s,this.tileWidth=t.tileWidth,this.tileHeight=t.tileHeight,this.halfTileWidth=this.tileWidth/2,this.halfTileHeight=this.tileHeight/2,this.patternContent=t.renderer,this.maxViewportScale=t.maxViewportScale;const i=`translate(${this.halfTileWidth}, ${this.halfTileHeight})`;this.patternContent.setAttribute("transform",i),this.pattern.appendChild(this.patternContent);const n=document.createElementNS("http://www.w3.org/2000/svg","defs");n.appendChild(this.pattern),this.svg.appendChild(n),this.svg.appendChild(this.patternRenderingRectangle),this.resizeObserver.observe(this.backgroundHost),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterTransformUpdated),this.onAfterTransformUpdated()}static configure(e,t,s){new q(e,t,s)}updateVisibility(){const t=this.canvas.viewport.getViewportMatrix().scale>this.maxViewportScale;t&&this.visible?(this.visible=!1,this.backgroundHost.removeChild(this.svg)):!t&&!this.visible&&(this.visible=!0,this.backgroundHost.appendChild(this.svg))}}class ee{constructor(e,t,s,i,n){o(this,"overlayCanvas");o(this,"staticPortId",null);o(this,"isTargetDragging",!0);o(this,"onEdgeCreated",e=>{this.params.onAfterEdgeCreated(e)});this.canvas=e,this.overlayLayer=t,this.viewportStore=s,this.window=i,this.params=n,this.overlayCanvas=Te(this.overlayLayer,this.viewportStore),O.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>{const d=this.params.connectionTypeResolver(a);return d===null?!1:(this.grabPort(a,h,d),!0)},onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(e,t,s,i,n){new ee(e,t,s,i,n)}grabPort(e,t,s){const i=this.canvas.graph.getPort(e);this.staticPortId=e;const n=i.element.getBoundingClientRect(),a=n.x+n.width/2,h=n.y+n.height/2,d=this.overlayLayer.getBoundingClientRect(),c=this.canvas.viewport.getViewportMatrix(),l=E(c,{x:a-d.x,y:h-d.y}),g=E(c,{x:t.x-d.x,y:t.y-d.y}),w={overlayId:D.Static,portCoords:l,portDirection:i.direction},f={overlayId:D.Dragging,portCoords:g,portDirection:this.params.dragPortDirection};this.isTargetDragging=s==="direct";const[y,x]=this.isTargetDragging?[w,f]:[f,w];this.overlayCanvas.addNode(B(y)),this.overlayCanvas.addNode(B(x)),this.overlayCanvas.addEdge({from:y.overlayId,to:x.overlayId,shape:this.params.edgeShapeFactory(D.Edge)})}resetDragState(){this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}tryCreateConnection(e){const t=ce(this.canvas.graph,e);if(t===null){this.params.onEdgeCreationInterrupted(this.staticPortId,this.isTargetDragging);return}const s=this.isTargetDragging?this.staticPortId:t,i=this.isTargetDragging?t:this.staticPortId,n={from:s,to:i},a=this.params.connectionPreprocessor(n);a!==null?(this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated),this.canvas.addEdge(a),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeCreated)):this.params.onEdgeCreationPrevented(n)}moveDraggingPort(e){const t=this.overlayLayer.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},i=this.canvas.viewport.getViewportMatrix(),n=E(i,s);this.overlayCanvas.updateNode(D.Dragging,{x:n.x,y:n.y})}}class te{constructor(e,t,s,i,n){o(this,"overlayCanvas");o(this,"staticPortId",null);o(this,"isTargetDragging",!0);o(this,"draggingEdgePayload",null);o(this,"onEdgeReattached",e=>{this.params.onAfterEdgeReattached(e)});this.canvas=e,this.overlayLayer=t,this.viewportStore=s,this.window=i,this.params=n,this.overlayCanvas=Te(this.overlayLayer,this.viewportStore),O.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>this.tryStartEdgeDragging(a,h),onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(e,t,s,i,n){new te(e,t,s,i,n)}tryStartEdgeDragging(e,t){const s=this.params.draggingEdgeResolver(e);if(s===null)return!1;const i=this.canvas.graph.getEdge(s);if(i===null)return!1;const n=e===i.from,a=e===i.to,h=n?i.to:i.from;this.staticPortId=h,this.isTargetDragging=a;const d=this.canvas.graph.getPort(e),c=this.canvas.graph.getPort(h),l=c.element.getBoundingClientRect(),g={x:l.x+l.width/2,y:l.y+l.height/2},w=this.canvas.viewport.getViewportMatrix(),f=this.overlayLayer.getBoundingClientRect(),y=E(w,{x:g.x-f.x,y:g.y-f.y}),x=E(w,{x:t.x-f.x,y:t.y-f.y});this.draggingEdgePayload={id:s,from:i.from,to:i.to,shape:i.shape,priority:i.priority},this.canvas.removeEdge(s);const S={overlayId:D.Static,portCoords:y,portDirection:c.direction},b={overlayId:D.Dragging,portCoords:x,portDirection:d.direction},[N,M]=this.isTargetDragging?[S,b]:[b,S];this.overlayCanvas.addNode(B(N)),this.overlayCanvas.addNode(B(M));const R=this.params.draggingEdgeShapeFactory!==null?this.params.draggingEdgeShapeFactory(D.Edge):i.shape;return this.overlayCanvas.addEdge({id:D.Edge,from:N.overlayId,to:M.overlayId,shape:R}),!0}resetDragState(){this.draggingEdgePayload=null,this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}moveDraggingPort(e){const t=this.overlayLayer.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},i=this.canvas.viewport.getViewportMatrix(),n=E(i,s);this.overlayCanvas.updateNode(D.Dragging,{x:n.x,y:n.y})}tryCreateConnection(e){const t=ce(this.canvas.graph,e);if(this.overlayCanvas.removeEdge(D.Edge),t===null){const d=this.draggingEdgePayload;this.params.onEdgeReattachInterrupted({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority});return}const[s,i]=this.isTargetDragging?[this.staticPortId,t]:[t,this.staticPortId],n=this.draggingEdgePayload,a={id:n.id,from:s,to:i,shape:n.shape,priority:n.priority},h=this.params.connectionPreprocessor(a);if(h!==null)this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeReattached),this.canvas.addEdge(h),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeReattached);else{const d=this.draggingEdgePayload;this.params.onEdgeReattachPrevented({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority})}}}const ct=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r},re=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.inset="0",r},De=()=>{const r=re();return r.style.pointerEvents="none",r};class gt{constructor(e){o(this,"background",re());o(this,"main",re());o(this,"overlayConnectablePorts",De());o(this,"overlayDraggableEdges",De());o(this,"host",ct());this.element=e,this.element.appendChild(this.host),this.host.appendChild(this.background),this.host.appendChild(this.main),this.host.appendChild(this.overlayConnectablePorts),this.host.appendChild(this.overlayDraggableEdges)}destroy(){this.host.removeChild(this.background),this.host.removeChild(this.main),this.host.removeChild(this.overlayConnectablePorts),this.host.removeChild(this.overlayDraggableEdges),this.element.removeChild(this.host)}}const oe=r=>()=>r,Ne=oe(0),lt=()=>{let r=0;return()=>r++},ut=(r,e)=>{let t=Ne,s=Ne;const i=lt();return r==="incremental"&&(t=i),e==="incremental"&&(s=i),typeof r=="number"&&(t=oe(r)),typeof e=="number"&&(s=oe(e)),typeof r=="function"&&(t=r),typeof e=="function"&&(s=e),{nodesPriorityFn:t,edgesPriorityFn:s}},se=r=>{if(typeof r=="function")return r;switch(r==null?void 0:r.type){case"straight":return()=>new Ee({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowWidth:r.arrowWidth,arrowOffset:r.arrowOffset,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance,detourDirection:r.detourDirection});case"horizontal":return()=>new ve({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowWidth:r.arrowWidth,arrowOffset:r.arrowOffset,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance,detourDirection:r.detourDirection});case"vertical":return()=>new Ae({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowWidth:r.arrowWidth,arrowOffset:r.arrowOffset,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance,detourDirection:r.detourDirection});case"direct":return()=>new Z({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowWidth:r.arrowWidth,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,sourceOffset:r.sourceOffset,targetOffset:r.targetOffset});default:return()=>new ye({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowWidth:r.arrowWidth,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleRadius:r.cycleRadius,smallCycleRadius:r.smallCycleRadius,curvature:r.curvature,detourDistance:r.detourDistance,detourDirection:r.detourDirection})}},pt=r=>{var t,s,i,n,a;const e=ut((t=r.nodes)==null?void 0:t.priority,(s=r.edges)==null?void 0:s.priority);return{nodes:{centerFn:((i=r.nodes)==null?void 0:i.centerFn)??ge,priorityFn:e.nodesPriorityFn},ports:{direction:((n=r.ports)==null?void 0:n.direction)??0},edges:{shapeFactory:se(((a=r.edges)==null?void 0:a.shape)??{}),priorityFn:e.edgesPriorityFn}}},wt=r=>{var w,f,y,x,S,b;const e=((w=r.events)==null?void 0:w.onNodeDrag)??(()=>{}),t=(((f=r.events)==null?void 0:f.onBeforeNodeDrag)||r.nodeDragVerifier)??(()=>!0),s=((y=r.events)==null?void 0:y.onNodeDragFinished)??(()=>{}),i=r.moveOnTop!==!1,n=r.moveEdgesOnTop!==!1&&i,a=(x=r.mouse)==null?void 0:x.dragCursor,h=a!==void 0?a:"grab",d=(S=r.mouse)==null?void 0:S.mouseDownEventVerifier,c=d!==void 0?d:N=>N.button===0,l=(b=r.mouse)==null?void 0:b.mouseUpEventVerifier,g=l!==void 0?l:N=>N.button===0;return{moveOnTop:i,moveEdgesOnTop:n,dragCursor:h,gridSize:r.gridSize??null,mouseDownEventVerifier:c,mouseUpEventVerifier:g,onNodeDrag:e,nodeDragVerifier:t,onNodeDragFinished:s}},ft=r=>{const e=r.minX!==null?r.minX:-1/0,t=r.maxX!==null?r.maxX:1/0,s=r.minY!==null?r.minY:-1/0,i=r.maxY!==null?r.maxY:1/0;return n=>{let a=n.nextTransform.x,h=n.nextTransform.y;a<e&&a<n.prevTransform.x&&(a=Math.min(n.prevTransform.x,e));const d=n.canvasWidth*n.prevTransform.scale,c=t-d;a>c&&a>n.prevTransform.x&&(a=Math.max(n.prevTransform.x,c)),h<s&&h<n.prevTransform.y&&(h=Math.min(n.prevTransform.y,s));const l=n.canvasHeight*n.prevTransform.scale,g=i-l;return h>g&&h>n.prevTransform.y&&(h=Math.max(n.prevTransform.y,g)),{scale:n.nextTransform.scale,x:a,y:h}}},mt=r=>{const e=r.maxContentScale,t=r.minContentScale,s=e!==null?1/e:0,i=t!==null?1/t:1/0;return n=>{const a=n.prevTransform,h=n.nextTransform;let d=h.scale,c=h.x,l=h.y;if(h.scale>i&&h.scale>a.scale){d=Math.max(a.scale,i),c=a.x,l=a.y;const g=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*g,l=a.y+(h.y-a.y)*g}if(h.scale<s&&h.scale<a.scale){d=Math.min(a.scale,s),c=a.x,l=a.y;const g=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*g,l=a.y+(h.y-a.y)*g}return{scale:d,x:c,y:l}}},yt=r=>e=>r.reduce((t,s)=>s({prevTransform:e.prevTransform,nextTransform:t,canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight}),e.nextTransform),Me=r=>{if(typeof r=="function")return r;switch(r.type){case"scale-limit":return mt({minContentScale:r.minContentScale??0,maxContentScale:r.maxContentScale??1/0});case"shift-limit":return ft({minX:r.minX??-1/0,maxX:r.maxX??1/0,minY:r.minY??-1/0,maxY:r.maxY??1/0})}},Le=r=>{var y,x,S,b,N,M,R,U,Re,Ce,Ve,Ie;const e=(y=r==null?void 0:r.scale)==null?void 0:y.mouseWheelSensitivity,t=e!==void 0?e:1.2,s=r==null?void 0:r.transformPreprocessor;let i;s!==void 0?Array.isArray(s)?i=yt(s.map(C=>Me(C))):i=Me(s):i=C=>C.nextTransform;const n=((x=r==null?void 0:r.shift)==null?void 0:x.cursor)!==void 0?r.shift.cursor:"grab",a=((S=r==null?void 0:r.events)==null?void 0:S.onBeforeTransformChange)??(()=>{}),h=((b=r==null?void 0:r.events)==null?void 0:b.onTransformChange)??(()=>{}),d=(N=r==null?void 0:r.shift)==null?void 0:N.mouseDownEventVerifier,c=d!==void 0?d:C=>C.button===0,l=(M=r==null?void 0:r.shift)==null?void 0:M.mouseUpEventVerifier,g=l!==void 0?l:C=>C.button===0,w=(R=r==null?void 0:r.scale)==null?void 0:R.mouseWheelEventVerifier,f=w!==void 0?w:()=>!0;return{wheelSensitivity:t,onTransformStarted:((U=r==null?void 0:r.events)==null?void 0:U.onTransformStarted)??(()=>{}),onTransformFinished:((Re=r==null?void 0:r.events)==null?void 0:Re.onTransformFinished)??(()=>{}),onBeforeTransformChange:a,onTransformChange:h,transformPreprocessor:i,shiftCursor:n,mouseDownEventVerifier:c,mouseUpEventVerifier:g,mouseWheelEventVerifier:f,scaleWheelFinishTimeout:((Ce=r==null?void 0:r.scale)==null?void 0:Ce.wheelFinishTimeout)??500,onResizeTransformStarted:((Ve=r==null?void 0:r.events)==null?void 0:Ve.onResizeTransformStarted)??(()=>{}),onResizeTransformFinished:((Ie=r==null?void 0:r.events)==null?void 0:Ie.onResizeTransformFinished)??(()=>{})}},vt=(r,e)=>{const t=document.createElementNS("http://www.w3.org/2000/svg","circle");return t.setAttribute("cx","0"),t.setAttribute("cy","0"),t.setAttribute("r",`${r}`),t.setAttribute("fill",`${e}`),t},Et=r=>r instanceof SVGElement?r:vt((r==null?void 0:r.radius)??1.5,(r==null?void 0:r.color)??"#d8d8d8"),At=r=>{const e=r.tileDimensions,t=(e==null?void 0:e.width)??25,s=(e==null?void 0:e.height)??25,i=Et(r.renderer??{});return{tileWidth:t,tileHeight:s,renderer:i,maxViewportScale:r.maxViewportScale??10}},xt=(r,e,t)=>{var c,l,g;const s=()=>"direct",i=w=>w,n=w=>w.button===0,a=()=>{},h=()=>{},d=()=>{};return{connectionTypeResolver:r.connectionTypeResolver??s,connectionPreprocessor:r.connectionPreprocessor??i,mouseDownEventVerifier:r.mouseDownEventVerifier??n,mouseUpEventVerifier:r.mouseUpEventVerifier??n,onAfterEdgeCreated:((c=r.events)==null?void 0:c.onAfterEdgeCreated)??a,onEdgeCreationInterrupted:((l=r.events)==null?void 0:l.onEdgeCreationInterrupted)??d,onEdgeCreationPrevented:((g=r.events)==null?void 0:g.onEdgeCreationPrevented)??h,dragPortDirection:r.dragPortDirection??t,edgeShapeFactory:r.edgeShape!==void 0?se(r.edgeShape):e}},St=(r,e)=>{var c,l,g;const t=w=>w,s=w=>w.button===0&&w.ctrlKey,i=w=>w.button===0,n=w=>{const f=e.getPortAdjacentEdgeIds(w);return f.length>0?f[f.length-1]:null},a=()=>{},h=()=>{},d=()=>{};return{connectionPreprocessor:r.connectionPreprocessor??t,mouseDownEventVerifier:r.mouseDownEventVerifier??s,mouseUpEventVerifier:r.mouseUpEventVerifier??i,draggingEdgeResolver:r.draggingEdgeResolver??n,draggingEdgeShapeFactory:r.draggingEdgeShape!==void 0?se(r.draggingEdgeShape):null,onAfterEdgeReattached:((c=r.events)==null?void 0:c.onAfterEdgeReattached)??a,onEdgeReattachInterrupted:((l=r.events)==null?void 0:l.onEdgeReattachInterrupted)??d,onEdgeReattachPrevented:((g=r.events)==null?void 0:g.onEdgeReattachPrevented)??h}},Pt=r=>({nodeVerticalRadius:r.nodeContainingRadius.vertical,nodeHorizontalRadius:r.nodeContainingRadius.horizontal}),bt=r=>{var e,t;return{onAfterNodeDetached:((e=r==null?void 0:r.events)==null?void 0:e.onAfterNodeDetached)??(()=>{}),onBeforeNodeAttached:((t=r==null?void 0:r.events)==null?void 0:t.onBeforeNodeAttached)??(()=>{})}};class Tt{constructor(e){o(this,"element",null);o(this,"canvasDefaults",{});o(this,"dragConfig",{});o(this,"transformConfig",{});o(this,"backgroundConfig",{});o(this,"connectablePortsConfig",{});o(this,"draggableEdgesConfig",{});o(this,"virtualScrollConfig");o(this,"hasDraggableNode",!1);o(this,"hasTransformableViewport",!1);o(this,"hasNodeResizeReactiveEdges",!1);o(this,"hasBackground",!1);o(this,"hasUserConnectablePorts",!1);o(this,"hasUserDraggableEdges",!1);o(this,"boxRenderingTrigger");o(this,"window",window);e!==void 0&&(this.element=e)}setElement(e){return this.element=e,this}setDefaults(e){return this.canvasDefaults=e,this}enableUserDraggableNodes(e){return this.hasDraggableNode=!0,this.dragConfig=e??{},this}enableUserTransformableViewport(e){return this.hasTransformableViewport=!0,this.transformConfig=e??{},this}enableResizeReactiveNodes(){return this.hasNodeResizeReactiveEdges=!0,this}enableNodeResizeReactiveEdges(){return this.hasNodeResizeReactiveEdges=!0,this}enableBoxAreaRendering(e){return this.boxRenderingTrigger=e,this}enableVirtualScroll(e){return this.virtualScrollConfig=e,this}enableBackground(e){return this.hasBackground=!0,this.backgroundConfig=e??{},this}enableUserConnectablePorts(e){return this.connectablePortsConfig=e??{},this.hasUserConnectablePorts=!0,this}enableUserDraggableEdges(e){return this.hasUserDraggableEdges=!0,this.draggableEdgesConfig=e??{},this}build(){if(this.element===null)throw new P("unable to build canvas when no attach element specified");let e=this.boxRenderingTrigger;this.virtualScrollConfig!==void 0&&e===void 0&&(e=new H);const t=new ae,s=new He,i=new gt(this.element);let n=new ie(t,s,i.main);e!==void 0&&(n=new Fe(n,t,e,bt(this.virtualScrollConfig)));const a=pt(this.canvasDefaults),h=new ne(this.element,t,s,n,a);if(this.hasBackground&&q.configure(h,At(this.backgroundConfig),i.background),this.hasNodeResizeReactiveEdges&&Y.configure(h),this.hasDraggableNode&&Q.configure(h,i.main,this.window,wt(this.dragConfig)),this.hasUserConnectablePorts){const c=xt(this.connectablePortsConfig,a.edges.shapeFactory,a.ports.direction);ee.configure(h,i.overlayConnectablePorts,s,this.window,c)}if(this.hasUserDraggableEdges){const c=St(this.draggableEdgesConfig,h.graph);te.configure(h,i.overlayDraggableEdges,s,this.window,c)}this.virtualScrollConfig!==void 0?_.configure(h,i.main,this.window,Le(this.transformConfig),e,Pt(this.virtualScrollConfig)):this.hasTransformableViewport&&k.configure(h,i.main,this.window,Le(this.transformConfig)),this.reset();const d=()=>{i.destroy(),h.onBeforeDestroy.unsubscribe(d)};return h.onBeforeDestroy.subscribe(d),h}reset(){this.element=null,this.canvasDefaults={},this.dragConfig={},this.transformConfig={},this.backgroundConfig={},this.virtualScrollConfig=void 0,this.hasDraggableNode=!1,this.hasTransformableViewport=!1,this.hasNodeResizeReactiveEdges=!1,this.hasBackground=!1,this.boxRenderingTrigger=void 0,this.hasUserConnectablePorts=!1}}v.BezierEdgeShape=ye,v.CanvasBuilder=Tt,v.DirectEdgeShape=Z,v.EventSubject=H,v.HorizontalEdgeShape=ve,v.HtmlGraphError=P,v.InteractiveEdgeError=Pe,v.InteractiveEdgeShape=J,v.LineEdgeShape=I,v.MedianEdgeShape=be,v.MidpointEdgeShape=be,v.StraightEdgeShape=Ee,v.VerticalEdgeShape=Ae,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
1
+ (function(v,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(v=typeof globalThis<"u"?globalThis:v||self,E(v.HtmlGraph={}))})(this,function(v){"use strict";var Ne=Object.defineProperty;var Me=(v,E,T)=>E in v?Ne(v,E,{enumerable:!0,configurable:!0,writable:!0,value:T}):v[E]=T;var o=(v,E,T)=>Me(v,typeof E!="symbol"?E+"":E,T);const E=(r,t)=>({x:r.scale*t.x+r.x,y:r.scale*t.y+r.y});var T=(r=>(r.Line="line",r.NodeCycle="node-cycle",r.PortCycle="port-cycle",r))(T||{});const Ut=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r.style.overflow="hidden",r},Wt=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.width="0",r.style.height="0",r},Bt=r=>{r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.visibility="hidden"};class st{constructor(t,e,s){o(this,"host",Ut());o(this,"container",Wt());o(this,"edgeIdToElementMap",new Map);o(this,"applyTransform",()=>{const t=this.viewportStore.getContentMatrix();this.container.style.transform=`matrix(${t.scale}, 0, 0, ${t.scale}, ${t.x}, ${t.y})`});this.graphStore=t,this.viewportStore=e,this.element=s,this.element.appendChild(this.host),this.host.appendChild(this.container),this.viewportStore.onAfterUpdated.subscribe(this.applyTransform)}attachNode(t){const e=this.graphStore.getNode(t);Bt(e.element),this.container.appendChild(e.element),this.updateNodePosition(t),this.updateNodePriority(t),e.element.style.visibility="visible"}detachNode(t){const e=this.graphStore.getNode(t);this.container.removeChild(e.element)}attachEdge(t){const e=this.graphStore.getEdge(t).payload.shape.svg;this.edgeIdToElementMap.set(t,e),this.container.appendChild(e),this.renderEdge(t),this.updateEdgePriority(t)}detachEdge(t){const e=this.edgeIdToElementMap.get(t);this.container.removeChild(e),this.edgeIdToElementMap.delete(t)}clear(){this.edgeIdToElementMap.forEach((t,e)=>{this.detachEdge(e)}),this.graphStore.getAllNodeIds().forEach(t=>{this.detachNode(t)})}destroy(){this.viewportStore.onAfterUpdated.unsubscribe(this.applyTransform),this.clear(),this.element.removeChild(this.host),this.host.removeChild(this.container)}updateNodePosition(t){const e=this.graphStore.getNode(t),{width:s,height:i}=e.element.getBoundingClientRect(),n=this.viewportStore.getViewportMatrix().scale,a=e.payload.centerFn(s,i),h=e.payload.x-n*a.x,d=e.payload.y-n*a.y;e.element.style.transform=`translate(${h}px, ${d}px)`}updateNodePriority(t){const e=this.graphStore.getNode(t);e.element.style.zIndex=`${e.payload.priority}`}updateEdgeShape(t){const e=this.edgeIdToElementMap.get(t);this.container.removeChild(e);const i=this.graphStore.getEdge(t).payload.shape.svg;this.edgeIdToElementMap.set(t,i),this.container.appendChild(i)}renderEdge(t){const e=this.graphStore.getEdge(t),s=this.graphStore.getPort(e.from),i=this.graphStore.getPort(e.to),n=s.element.getBoundingClientRect(),a=i.element.getBoundingClientRect(),h=this.host.getBoundingClientRect(),d=this.viewportStore.getViewportMatrix(),c=this.createEdgeRenderPort(s,n,h,d),l=this.createEdgeRenderPort(i,a,h,d);let g=T.Line;s.element===i.element?g=T.PortCycle:s.nodeId===i.nodeId&&(g=T.NodeCycle),e.payload.shape.render({from:c,to:l,category:g})}updateEdgePriority(t){const e=this.graphStore.getEdge(t);e.payload.shape.svg.style.zIndex=`${e.payload.priority}`}createEdgeRenderPort(t,e,s,i){const n={x:e.left-s.left,y:e.top-s.top},a=E(i,n);return{x:a.x,y:a.y,width:e.width*i.scale,height:e.height*i.scale,direction:t.payload.direction}}}class $t{constructor(t){o(this,"xFrom",1/0);o(this,"yFrom",1/0);o(this,"xTo",1/0);o(this,"yTo",1/0);this.graphStore=t}setRenderingBox(t){this.xFrom=t.x,this.xTo=t.x+t.width,this.yFrom=t.y,this.yTo=t.y+t.height}hasNode(t){const e=this.graphStore.getNode(t).payload;return e.x>=this.xFrom&&e.x<=this.xTo&&e.y>=this.yFrom&&e.y<=this.yTo}hasEdge(t){const e=this.graphStore.getEdge(t),s=this.graphStore.getPort(e.from).nodeId,i=this.graphStore.getPort(e.to).nodeId,n=this.graphStore.getNode(s).payload,a=this.graphStore.getNode(i).payload,h=Math.min(n.x,a.x),d=Math.max(n.x,a.x),c=Math.min(n.y,a.y),l=Math.max(n.y,a.y);return h<=this.xTo&&d>=this.xFrom&&c<=this.yTo&&l>=this.yFrom}}class Ft{constructor(t,e,s,i){o(this,"attachedNodes",new Set);o(this,"attachedEdges",new Set);o(this,"renderingBox");o(this,"updateViewport",t=>{this.renderingBox.setRenderingBox(t);const e=new Set,s=new Set,i=new Set,n=new Set;this.graphStore.getAllNodeIds().forEach(a=>{const h=this.renderingBox.hasNode(a),d=this.attachedNodes.has(a);h&&!d?e.add(a):!h&&d&&s.add(a)}),this.graphStore.getAllEdgeIds().forEach(a=>{const h=this.renderingBox.hasEdge(a),d=this.attachedEdges.has(a),c=this.graphStore.getEdge(a),l=this.graphStore.getPort(c.from).nodeId,g=this.graphStore.getPort(c.to).nodeId;h&&(this.renderingBox.hasNode(l)||(e.add(l),s.delete(l)),this.renderingBox.hasNode(g)||(e.add(g),s.delete(g))),h&&!d?i.add(a):!h&&d&&n.add(a)}),n.forEach(a=>{this.handleDetachEdge(a)}),s.forEach(a=>{this.handleDetachNode(a)}),e.forEach(a=>{this.attachedNodes.has(a)||this.handleAttachNode(a)}),i.forEach(a=>{this.handleAttachEdge(a)})});this.htmlView=t,this.graphStore=e,this.trigger=s,this.params=i,this.renderingBox=new $t(this.graphStore),this.trigger.subscribe(this.updateViewport)}attachNode(t){this.renderingBox.hasNode(t)&&this.handleAttachNode(t)}detachNode(t){this.attachedNodes.has(t)&&this.handleDetachNode(t)}attachEdge(t){this.renderingBox.hasEdge(t)&&this.attachEdgeEntities(t)}detachEdge(t){this.attachedEdges.has(t)&&this.handleDetachEdge(t)}updateNodePosition(t){this.attachedNodes.has(t)?this.htmlView.updateNodePosition(t):this.renderingBox.hasNode(t)&&(this.handleAttachNode(t),this.graphStore.getNodeAdjacentEdgeIds(t).forEach(e=>{this.attachEdgeEntities(e)}))}updateNodePriority(t){this.attachedNodes.has(t)&&this.htmlView.updateNodePriority(t)}updateEdgeShape(t){this.attachedEdges.has(t)&&this.htmlView.updateEdgeShape(t)}renderEdge(t){this.attachedEdges.has(t)&&this.htmlView.renderEdge(t)}updateEdgePriority(t){this.attachedEdges.has(t)&&this.htmlView.updateEdgePriority(t)}clear(){this.htmlView.clear(),this.attachedNodes.clear(),this.attachedEdges.clear()}destroy(){this.clear(),this.htmlView.destroy(),this.trigger.unsubscribe(this.updateViewport)}attachEdgeEntities(t){const e=this.graphStore.getEdge(t),s=this.graphStore.getPort(e.from).nodeId,i=this.graphStore.getPort(e.to).nodeId;this.attachedNodes.has(s)||this.handleAttachNode(s),this.attachedNodes.has(i)||this.handleAttachNode(i),this.handleAttachEdge(t)}handleAttachNode(t){this.params.onBeforeNodeAttached(t),this.attachedNodes.add(t),this.htmlView.attachNode(t)}handleDetachNode(t){this.htmlView.detachNode(t),this.attachedNodes.delete(t),this.params.onAfterNodeDetached(t)}handleAttachEdge(t){this.attachedEdges.add(t),this.htmlView.attachEdge(t)}handleDetachEdge(t){this.htmlView.detachEdge(t),this.attachedEdges.delete(t)}}class it{constructor(){o(this,"callbacks",new Set)}subscribe(t){this.callbacks.add(t)}unsubscribe(t){this.callbacks.delete(t)}emit(t){this.callbacks.forEach(e=>{e(t)})}}const S=()=>{const r=new it;return[r,r]};class Ot{constructor(t){o(this,"onAfterUpdated");this.viewportStore=t,this.onAfterUpdated=this.viewportStore.onAfterUpdated}getViewportMatrix(){return{...this.viewportStore.getViewportMatrix()}}getContentMatrix(){return{...this.viewportStore.getContentMatrix()}}}class kt{constructor(t){o(this,"onAfterNodeAdded");o(this,"onAfterNodeUpdated");o(this,"onAfterNodePriorityUpdated");o(this,"onBeforeNodeRemoved");o(this,"onAfterPortMarked");o(this,"onAfterPortUpdated");o(this,"onBeforePortUnmarked");o(this,"onAfterEdgeAdded");o(this,"onAfterEdgeShapeUpdated");o(this,"onAfterEdgeUpdated");o(this,"onAfterEdgePriorityUpdated");o(this,"onBeforeEdgeRemoved");o(this,"onBeforeClear");this.graphStore=t,this.onAfterNodeAdded=this.graphStore.onAfterNodeAdded,this.onAfterNodeUpdated=this.graphStore.onAfterNodeUpdated,this.onAfterNodePriorityUpdated=this.graphStore.onAfterNodePriorityUpdated,this.onBeforeNodeRemoved=this.graphStore.onBeforeNodeRemoved,this.onAfterPortMarked=this.graphStore.onAfterPortAdded,this.onAfterPortUpdated=this.graphStore.onAfterPortUpdated,this.onBeforePortUnmarked=this.graphStore.onBeforePortRemoved,this.onAfterEdgeAdded=this.graphStore.onAfterEdgeAdded,this.onAfterEdgeShapeUpdated=this.graphStore.onAfterEdgeShapeUpdated,this.onAfterEdgeUpdated=this.graphStore.onAfterEdgeUpdated,this.onAfterEdgePriorityUpdated=this.graphStore.onAfterEdgePriorityUpdated,this.onBeforeEdgeRemoved=this.graphStore.onBeforeEdgeRemoved,this.onBeforeClear=this.graphStore.onBeforeClear}getNode(t){const e=this.graphStore.getNode(t);if(e===void 0)return null;const s=e.payload;return{element:e.element,x:s.x,y:s.y,centerFn:s.centerFn,priority:s.priority}}getElementNodeId(t){return this.graphStore.getElementNodeId(t)??null}getAllNodeIds(){return this.graphStore.getAllNodeIds()}getPort(t){const e=this.graphStore.getPort(t);return e===void 0?null:{element:e.element,direction:e.payload.direction,nodeId:e.nodeId}}getAllPortIds(){return this.graphStore.getAllPortIds()}getNodePortIds(t){return this.graphStore.getNodePortIds(t)??null}getElementPortIds(t){return[...this.graphStore.getElementPortIds(t)]}getAllEdgeIds(){return this.graphStore.getAllEdgeIds()}getEdge(t){const e=this.graphStore.getEdge(t);if(e===void 0)return null;const s=e.payload;return{from:e.from,to:e.to,priority:s.priority,shape:s.shape}}getPortIncomingEdgeIds(t){return this.graphStore.getPort(t)===void 0?null:this.graphStore.getPortIncomingEdgeIds(t)}getPortOutgoingEdgeIds(t){return this.graphStore.getPort(t)===void 0?null:this.graphStore.getPortOutgoingEdgeIds(t)}getPortCycleEdgeIds(t){return this.graphStore.getPort(t)===void 0?null:this.graphStore.getPortCycleEdgeIds(t)}getPortAdjacentEdgeIds(t){return this.graphStore.getPort(t)===void 0?null:this.graphStore.getPortAdjacentEdgeIds(t)}getNodeIncomingEdgeIds(t){return this.graphStore.getNode(t)===void 0?null:this.graphStore.getNodeIncomingEdgeIds(t)}getNodeOutgoingEdgeIds(t){return this.graphStore.getNode(t)===void 0?null:this.graphStore.getNodeOutgoingEdgeIds(t)}getNodeCycleEdgeIds(t){return this.graphStore.getNode(t)===void 0?null:this.graphStore.getNodeCycleEdgeIds(t)}getNodeAdjacentEdgeIds(t){return this.graphStore.getNode(t)===void 0?null:this.graphStore.getNodeAdjacentEdgeIds(t)}}class X{constructor(t){o(this,"counter",0);this.checkExists=t}create(t){if(t!==void 0)return t;for(;this.checkExists(this.counter);)this.counter++;return this.counter}reset(){this.counter=0}}class b extends Error{constructor(){super(...arguments);o(this,"name","CanvasError")}}class nt{constructor(t,e,s,i){o(this,"graph");o(this,"viewport");o(this,"nodeIdGenerator",new X(t=>this.graph.getNode(t)!==null));o(this,"portIdGenerator",new X(t=>this.graph.getPort(t)!==null));o(this,"edgeIdGenerator",new X(t=>this.graph.getEdge(t)!==null));o(this,"onAfterNodeAdded",t=>{this.htmlView.attachNode(t)});o(this,"onAfterNodeUpdated",t=>{this.htmlView.updateNodePosition(t),this.graphStore.getNodeAdjacentEdgeIds(t).forEach(s=>{this.htmlView.renderEdge(s)})});o(this,"onAfterNodePriorityUpdated",t=>{this.htmlView.updateNodePriority(t)});o(this,"onBeforeNodeRemoved",t=>{this.graphStore.getNodePortIds(t).forEach(e=>{this.unmarkPort(e)}),this.htmlView.detachNode(t)});o(this,"onAfterPortUpdated",t=>{this.graphStore.getPortAdjacentEdgeIds(t).forEach(s=>{this.htmlView.renderEdge(s)})});o(this,"onBeforePortUnmarked",t=>{this.graphStore.getPortAdjacentEdgeIds(t).forEach(e=>{this.removeEdge(e)})});o(this,"onAfterEdgeAdded",t=>{this.htmlView.attachEdge(t)});o(this,"onAfterEdgeShapeUpdated",t=>{this.htmlView.updateEdgeShape(t)});o(this,"onAfterEdgeUpdated",t=>{this.htmlView.renderEdge(t)});o(this,"onAfterEdgePriorityUpdated",t=>{this.htmlView.updateEdgePriority(t)});o(this,"onBeforeEdgeRemoved",t=>{this.htmlView.detachEdge(t)});o(this,"onBeforeClear",()=>{this.nodeIdGenerator.reset(),this.portIdGenerator.reset(),this.edgeIdGenerator.reset(),this.htmlView.clear()});o(this,"onBeforeDestroyEmitter");o(this,"destroyed",!1);o(this,"onBeforeDestroy");this.graphStore=t,this.viewportStore=e,this.htmlView=s,this.params=i,this.graph=new kt(this.graphStore),this.viewport=new Ot(this.viewportStore),this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.subscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.subscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.subscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.subscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.subscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.subscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.subscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.subscribe(this.onBeforeClear),[this.onBeforeDestroyEmitter,this.onBeforeDestroy]=S()}addNode(t){const e=this.nodeIdGenerator.create(t.id);if(this.graphStore.getNode(e)!==void 0)throw new b("failed to add node with existing id");if(this.graphStore.getElementNodeId(t.element)!==void 0)throw new b("failed to add node with html element already in use by another node");if(this.graphStore.addNode({id:e,element:t.element,x:t.x,y:t.y,centerFn:t.centerFn??this.params.nodes.centerFn,priority:t.priority??this.params.nodes.priorityFn()}),t.ports!==void 0)for(const s of t.ports)this.markPort({id:s.id,element:s.element,nodeId:e,direction:s.direction});return this}updateNode(t,e){if(this.graphStore.getNode(t)===void 0)throw new b("failed to update non existing node");return this.graphStore.updateNode(t,e??{}),this}removeNode(t){if(this.graphStore.getNode(t)===void 0)throw new b("failed to remove non existing node");return this.graphStore.removeNode(t),this}markPort(t){const e=this.portIdGenerator.create(t.id);if(this.graphStore.getPort(e)!==void 0)throw new b("failed to add port with existing id");if(this.graphStore.getNode(t.nodeId)===void 0)throw new b("failed to mark port for nonexistent node");return this.graphStore.addPort({id:e,element:t.element,nodeId:t.nodeId,direction:t.direction??this.params.ports.direction}),this}updatePort(t,e){if(this.graphStore.getPort(t)===void 0)throw new b("failed to update nonexistent port");return this.graphStore.updatePort(t,e??{}),this}unmarkPort(t){if(this.graphStore.getPort(t)===void 0)throw new b("failed to unmark non existing port");return this.graphStore.removePort(t),this}addEdge(t){const e=this.edgeIdGenerator.create(t.id);if(this.graphStore.getEdge(e)!==void 0)throw new b("failed to add edge with existing id");if(this.graphStore.getPort(t.from)===void 0)throw new b("failed to add edge from nonexistent port");if(this.graphStore.getPort(t.to)===void 0)throw new b("failed to add edge to nonexistent port");return this.graphStore.addEdge({id:e,from:t.from,to:t.to,shape:t.shape??this.params.edges.shapeFactory(e),priority:t.priority??this.params.edges.priorityFn()}),this}updateEdge(t,e){if(this.graphStore.getEdge(t)===void 0)throw new b("failed to update nonexistent edge");return this.graphStore.updateEdge(t,e??{}),this}removeEdge(t){if(this.graphStore.getEdge(t)===void 0)throw new b("failed to remove nonexistent edge");return this.graphStore.removeEdge(t),this}patchViewportMatrix(t){return this.viewportStore.patchViewportMatrix(t),this}patchContentMatrix(t){return this.viewportStore.patchContentMatrix(t),this}clear(){return this.graphStore.clear(),this}destroy(){this.destroyed||(this.clear(),this.onBeforeDestroyEmitter.emit(),this.graphStore.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.unsubscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.unsubscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.unsubscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.unsubscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.unsubscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.unsubscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.unsubscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.unsubscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.unsubscribe(this.onBeforeClear),this.htmlView.destroy(),this.destroyed=!0)}}class zt{constructor(){o(this,"singleToMultiMap",new Map);o(this,"multiToSingleMap",new Map)}addRecord(t,e){const s=this.singleToMultiMap.get(t);s===void 0?this.singleToMultiMap.set(t,new Set([e])):s.add(e),this.multiToSingleMap.set(e,t)}getMultiBySingle(t){const e=this.singleToMultiMap.get(t)??new Set;return Array.from(e.values())}removeByMulti(t){const e=this.multiToSingleMap.get(t),s=this.singleToMultiMap.get(e);s.delete(t),s.size===0&&this.singleToMultiMap.delete(e),this.multiToSingleMap.delete(t)}getByMulti(t){return this.multiToSingleMap.get(t)}removeBySingle(t){this.singleToMultiMap.get(t).forEach(s=>{this.multiToSingleMap.delete(s)}),this.singleToMultiMap.delete(t)}clear(){this.singleToMultiMap.clear(),this.multiToSingleMap.clear()}forEachSingle(t){this.singleToMultiMap.forEach((e,s)=>{t(s)})}hasSingle(t){return this.singleToMultiMap.get(t)!==void 0}hasMulti(t){return this.multiToSingleMap.get(t)!==void 0}}class at{constructor(){o(this,"nodes",new Map);o(this,"ports",new Map);o(this,"edges",new Map);o(this,"nodesElementsMap",new Map);o(this,"incomingEdges",new Map);o(this,"outcomingEdges",new Map);o(this,"cycleEdges",new Map);o(this,"elementPorts",new zt);o(this,"afterNodeAddedEmitter");o(this,"onAfterNodeAdded");o(this,"afterNodeUpdatedEmitter");o(this,"onAfterNodeUpdated");o(this,"afterNodePriorityUpdatedEmitter");o(this,"onAfterNodePriorityUpdated");o(this,"beforeNodeRemovedEmitter");o(this,"onBeforeNodeRemoved");o(this,"afterPortAddedEmitter");o(this,"onAfterPortAdded");o(this,"afterPortUpdatedEmitter");o(this,"onAfterPortUpdated");o(this,"beforePortRemovedEmitter");o(this,"onBeforePortRemoved");o(this,"afterEdgeAddedEmitter");o(this,"onAfterEdgeAdded");o(this,"afterEdgeShapeUpdatedEmitter");o(this,"onAfterEdgeShapeUpdated");o(this,"afterEdgeUpdatedEmitter");o(this,"onAfterEdgeUpdated");o(this,"afterEdgePriorityUpdatedEmitter");o(this,"onAfterEdgePriorityUpdated");o(this,"beforeEdgeRemovedEmitter");o(this,"onBeforeEdgeRemoved");o(this,"beforeClearEmitter");o(this,"onBeforeClear");[this.afterNodeAddedEmitter,this.onAfterNodeAdded]=S(),[this.afterNodeUpdatedEmitter,this.onAfterNodeUpdated]=S(),[this.afterNodePriorityUpdatedEmitter,this.onAfterNodePriorityUpdated]=S(),[this.beforeNodeRemovedEmitter,this.onBeforeNodeRemoved]=S(),[this.afterPortAddedEmitter,this.onAfterPortAdded]=S(),[this.afterPortUpdatedEmitter,this.onAfterPortUpdated]=S(),[this.beforePortRemovedEmitter,this.onBeforePortRemoved]=S(),[this.afterEdgeAddedEmitter,this.onAfterEdgeAdded]=S(),[this.afterEdgeShapeUpdatedEmitter,this.onAfterEdgeShapeUpdated]=S(),[this.afterEdgeUpdatedEmitter,this.onAfterEdgeUpdated]=S(),[this.afterEdgePriorityUpdatedEmitter,this.onAfterEdgePriorityUpdated]=S(),[this.beforeEdgeRemovedEmitter,this.onBeforeEdgeRemoved]=S(),[this.beforeClearEmitter,this.onBeforeClear]=S()}addNode(t){const e=new Map,s={element:t.element,payload:{x:t.x,y:t.y,centerFn:t.centerFn,priority:t.priority},ports:e};this.nodes.set(t.id,s),this.nodesElementsMap.set(t.element,t.id),this.afterNodeAddedEmitter.emit(t.id)}getAllNodeIds(){return Array.from(this.nodes.keys())}getNode(t){return this.nodes.get(t)}getElementNodeId(t){return this.nodesElementsMap.get(t)}updateNode(t,e){const s=this.nodes.get(t).payload;s.x=e.x??s.x,s.y=e.y??s.y,s.centerFn=e.centerFn??s.centerFn,e.priority!==void 0&&(s.priority=e.priority,this.afterNodePriorityUpdatedEmitter.emit(t)),this.afterNodeUpdatedEmitter.emit(t)}removeNode(t){this.beforeNodeRemovedEmitter.emit(t);const e=this.nodes.get(t);this.nodesElementsMap.delete(e.element),this.nodes.delete(t)}addPort(t){this.ports.set(t.id,{element:t.element,payload:{direction:t.direction},nodeId:t.nodeId}),this.elementPorts.addRecord(t.element,t.id),this.cycleEdges.set(t.id,new Set),this.incomingEdges.set(t.id,new Set),this.outcomingEdges.set(t.id,new Set),this.nodes.get(t.nodeId).ports.set(t.id,t.element),this.afterPortAddedEmitter.emit(t.id)}getPort(t){return this.ports.get(t)}updatePort(t,e){const s=this.ports.get(t).payload;s.direction=e.direction??s.direction,this.afterPortUpdatedEmitter.emit(t)}getAllPortIds(){return Array.from(this.ports.keys())}getElementPortIds(t){return this.elementPorts.getMultiBySingle(t)}getNodePortIds(t){const e=this.nodes.get(t);if(e!==void 0)return Array.from(e.ports.keys())}removePort(t){const e=this.ports.get(t).nodeId;this.beforePortRemovedEmitter.emit(t),this.nodes.get(e).ports.delete(t),this.ports.delete(t),this.elementPorts.removeByMulti(t)}addEdge(t){this.addEdgeInternal(t),this.afterEdgeAddedEmitter.emit(t.id)}updateEdge(t,e){if(e.from!==void 0||e.to!==void 0){const i=this.edges.get(t),n=i.payload;this.removeEdgeInternal(t),this.addEdgeInternal({id:t,from:e.from??i.from,to:e.to??i.to,shape:n.shape,priority:n.priority})}const s=this.edges.get(t);e.shape!==void 0&&(s.payload.shape=e.shape,this.afterEdgeShapeUpdatedEmitter.emit(t)),e.priority!==void 0&&(s.payload.priority=e.priority,this.afterEdgePriorityUpdatedEmitter.emit(t)),this.afterEdgeUpdatedEmitter.emit(t)}getAllEdgeIds(){return Array.from(this.edges.keys())}getEdge(t){return this.edges.get(t)}removeEdge(t){this.beforeEdgeRemovedEmitter.emit(t),this.removeEdgeInternal(t)}clear(){this.beforeClearEmitter.emit(),this.incomingEdges.clear(),this.outcomingEdges.clear(),this.cycleEdges.clear(),this.elementPorts.clear(),this.nodesElementsMap.clear(),this.edges.clear(),this.ports.clear(),this.nodes.clear()}getPortIncomingEdgeIds(t){return Array.from(this.incomingEdges.get(t))}getPortOutgoingEdgeIds(t){return Array.from(this.outcomingEdges.get(t))}getPortCycleEdgeIds(t){return Array.from(this.cycleEdges.get(t))}getPortAdjacentEdgeIds(t){return[...this.getPortIncomingEdgeIds(t),...this.getPortOutgoingEdgeIds(t),...this.getPortCycleEdgeIds(t)]}getNodeIncomingEdgeIds(t){const e=Array.from(this.nodes.get(t).ports.keys());let s=[];return e.forEach(i=>{s=[...s,...this.getPortIncomingEdgeIds(i)]}),s}getNodeOutgoingEdgeIds(t){const e=Array.from(this.nodes.get(t).ports.keys());let s=[];return e.forEach(i=>{s=[...s,...this.getPortOutgoingEdgeIds(i)]}),s}getNodeCycleEdgeIds(t){const e=Array.from(this.nodes.get(t).ports.keys());let s=[];return e.forEach(i=>{s=[...s,...this.getPortCycleEdgeIds(i)]}),s}getNodeAdjacentEdgeIds(t){return[...this.getNodeIncomingEdgeIds(t),...this.getNodeOutgoingEdgeIds(t),...this.getNodeCycleEdgeIds(t)]}addEdgeInternal(t){this.edges.set(t.id,{from:t.from,to:t.to,payload:{shape:t.shape,priority:t.priority}}),t.from!==t.to?(this.outcomingEdges.get(t.from).add(t.id),this.incomingEdges.get(t.to).add(t.id)):this.cycleEdges.get(t.from).add(t.id)}removeEdgeInternal(t){const e=this.edges.get(t),s=e.from,i=e.to;this.cycleEdges.get(s).delete(t),this.cycleEdges.get(i).delete(t),this.incomingEdges.get(s).delete(t),this.incomingEdges.get(i).delete(t),this.outcomingEdges.get(s).delete(t),this.outcomingEdges.get(i).delete(t),this.edges.delete(t)}}const ht=r=>({scale:1/r.scale,x:-r.x/r.scale,y:-r.y/r.scale}),dt={scale:1,x:0,y:0};class Xt{constructor(){o(this,"viewportMatrix",dt);o(this,"contentMatrix",dt);o(this,"afterUpdateEmitter");o(this,"onAfterUpdated");[this.afterUpdateEmitter,this.onAfterUpdated]=S()}getViewportMatrix(){return this.viewportMatrix}getContentMatrix(){return this.contentMatrix}patchViewportMatrix(t){this.viewportMatrix={scale:t.scale??this.viewportMatrix.scale,x:t.x??this.viewportMatrix.x,y:t.y??this.viewportMatrix.y},this.contentMatrix=ht(this.viewportMatrix),this.afterUpdateEmitter.emit()}patchContentMatrix(t){this.contentMatrix={scale:t.scale??this.contentMatrix.scale,x:t.x??this.contentMatrix.x,y:t.y??this.contentMatrix.y},this.viewportMatrix=ht(this.contentMatrix),this.afterUpdateEmitter.emit()}}class Y{constructor(t){o(this,"elementToNodeId",new Map);o(this,"nodesResizeObserver");o(this,"onAfterNodeAdded",t=>{const e=this.canvas.graph.getNode(t);this.elementToNodeId.set(e.element,t),this.nodesResizeObserver.observe(e.element)});o(this,"onBeforeNodeRemoved",t=>{const e=this.canvas.graph.getNode(t);this.elementToNodeId.delete(e.element),this.nodesResizeObserver.unobserve(e.element)});o(this,"onBeforeClear",()=>{this.nodesResizeObserver.disconnect(),this.elementToNodeId.clear()});this.canvas=t,this.nodesResizeObserver=new ResizeObserver(e=>{e.forEach(s=>{const i=s.target;this.handleNodeResize(i)})}),this.canvas.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.canvas.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear)}static configure(t){new Y(t)}handleNodeResize(t){const e=this.elementToNodeId.get(t);this.canvas.updateNode(e)}}const Yt=(r,t,e)=>{const{x:s,y:i,width:n,height:a}=r.getBoundingClientRect();return t>=s&&t<=s+n&&e>=i&&e<=i+a},Ht=(r,t,e)=>t>=0&&t<=r.innerWidth&&e>=0&&e<=r.innerHeight,R=(r,t,e,s)=>Yt(t,e,s)&&Ht(r,e,s),U=(r,t)=>{t!==null?r.style.cursor=t:r.style.removeProperty("cursor")},W=r=>{const t=document.createElement("div");return{id:r.overlayId,element:t,x:r.portCoords.x,y:r.portCoords.y,ports:[{id:r.overlayId,element:t,direction:r.portDirection}]}},jt=(r,t)=>{let e=t,s=null;for(;e!==null&&(s=r.getElementPortIds(e)[0]??null,s===null);)e=e.parentElement;return s},ct=(r,t)=>{const e=document.elementsFromPoint(t.x,t.y);for(const s of e){const i=jt(r,s);if(i!==null)return i}return null};var D=(r=>(r.Static="static",r.Dragging="dragging",r.Edge="edge",r))(D||{});const gt=(r,t)=>({x:r/2,y:t/2}),y=(r,t,e)=>({x:t.x*r.x-t.y*r.y+((1-t.x)*e.x+t.y*e.y),y:t.y*r.x+t.x*r.y+((1-t.x)*e.y-t.y*e.x)}),u={x:0,y:0};class Gt{constructor(t){o(this,"path");o(this,"midpoint");this.params=t;const e=this.params.to;this.midpoint={x:e.x/2,y:e.y/2};const s=y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u),i=y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to),n={x:s.x+this.params.sourceDirection.x*this.params.curvature,y:s.y+this.params.sourceDirection.y*this.params.curvature},a={x:i.x-this.params.targetDirection.x*this.params.curvature,y:i.y-this.params.targetDirection.y*this.params.curvature},h=`M ${s.x} ${s.y} C ${n.x} ${n.y}, ${a.x} ${a.y}, ${i.x} ${i.y}`,d=this.params.hasSourceArrow?"":`M ${u.x} ${u.y} L ${s.x} ${s.y} `,c=this.params.hasTargetArrow?"":` M ${i.x} ${i.y} L ${this.params.to.x} ${this.params.to.y}`;this.path=`${d}${h}${c}`}}const B=(r,t,e,s)=>({x:t*r.x+(1-t)/2*s.x,y:e*r.y+(1-e)/2*s.y});class Kt{constructor(t){o(this,"path");o(this,"midpoint");this.params=t;const e=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength,n=Math.cos(this.params.detourDirection)*this.params.detourDistance,a=Math.sin(this.params.detourDirection)*this.params.detourDistance,h=n*this.params.flipX,d=a*this.params.flipY,c=y({x:i,y:u.y},this.params.sourceDirection,u),l={x:c.x+h,y:c.y+d},g=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),w={x:g.x+h,y:g.y+d},f={x:(l.x+w.x)/2,y:(l.y+w.y)/2},m={x:c.x+this.params.curvature*this.params.sourceDirection.x,y:c.y+this.params.curvature*this.params.sourceDirection.y},A={x:g.x-this.params.curvature*this.params.targetDirection.x,y:g.y-this.params.curvature*this.params.targetDirection.y},x={x:c.x+h,y:c.y+d},P={x:g.x+h,y:g.y+d};this.path=[`M ${e.x} ${e.y}`,`L ${c.x} ${c.y}`,`C ${m.x} ${m.y} ${x.x} ${x.y} ${f.x} ${f.y}`,`C ${P.x} ${P.y} ${A.x} ${A.y} ${g.x} ${g.y}`,`L ${s.x} ${s.y}`].join(" "),this.midpoint=B(f,t.flipX,t.flipY,t.to)}}const M=(r,t)=>{const e=[];if(r.length>0&&e.push(`M ${r[0].x} ${r[0].y}`),r.length===2&&e.push(`L ${r[1].x} ${r[1].y}`),r.length>2){const s=r.length-1;let i=0,n=0,a=0;r.forEach((h,d)=>{let c=0,l=0,g=0;const w=d>0,f=d<s,m=w&&f;if(w&&(c=-i,l=-n,g=a),f){const I=r[d+1];i=I.x-h.x,n=I.y-h.y,a=Math.sqrt(i*i+n*n)}const x=a!==0?Math.min((m?t:0)/a,d<s-1?.5:1):0,P=m?{x:h.x+i*x,y:h.y+n*x}:h,N=g!==0?Math.min((m?t:0)/g,d>1?.5:1):0,L=m?{x:h.x+c*N,y:h.y+l*N}:h;d>0&&e.push(`L ${L.x} ${L.y}`),m&&e.push(`C ${h.x} ${h.y} ${h.x} ${h.y} ${P.x} ${P.y}`)})}return e.join(" ")};class Zt{constructor(t){o(this,"path");o(this,"midpoint");this.params=t;const e=this.params.to;this.midpoint={x:e.x/2,y:e.y/2};const s=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=y({x:a,y:u.y},this.params.sourceDirection,u),d=y({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.x+d.x)/2,n),l=this.params.to.y/2,g={x:this.params.flipX>0?c:-n,y:h.y},w={x:g.x,y:l},f={x:this.params.flipX>0?this.params.to.x-c:this.params.to.x+n,y:d.y},m={x:f.x,y:l};this.path=M([s,h,g,w,m,f,d,i],this.params.roundness)}}class Jt{constructor(t){o(this,"path");o(this,"midpoint");this.params=t;const e=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=y({x:i,y:u.y},this.params.sourceDirection,u),a=Math.cos(this.params.detourDirection)*this.params.detourDistance,h=Math.sin(this.params.detourDirection)*this.params.detourDistance,d=a*this.params.flipX,c=h*this.params.flipY,l={x:n.x+d,y:n.y+c},g=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),w={x:g.x+d,y:g.y+c},f={x:(l.x+w.x)/2,y:(l.y+w.y)/2};this.midpoint=B(f,t.flipX,t.flipY,t.to),this.path=M([e,n,l,w,g,s],this.params.roundness)}}class Qt{constructor(t){o(this,"path");o(this,"midpoint");this.params=t;const e=this.params.to;this.midpoint={x:e.x/2,y:e.y/2};const s=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=y({x:n,y:u.y},this.params.sourceDirection,u),h=y({x:this.params.to.x-n,y:this.params.to.y},this.params.targetDirection,this.params.to);this.path=M([s,a,h,i],this.params.roundness)}}class _t{constructor(t){o(this,"path");o(this,"midpoint");this.params=t;const e=this.params.to;this.midpoint={x:e.x/2,y:e.y/2};const s=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=y({x:a,y:u.y},this.params.sourceDirection,u),d=y({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.y+d.y)/2,n),l=this.params.to.x/2,g={x:h.x,y:this.params.flipY>0?c:-n},w={x:l,y:g.y},f={x:d.x,y:this.params.flipY>0?this.params.to.y-c:this.params.to.y+n},m={x:l,y:f.y};this.path=M([s,h,g,w,m,f,d,i],this.params.roundness)}}class H{constructor(t){o(this,"path");o(this,"midpoint");this.params=t;const e=this.params.arrowOffset,s=this.params.side,i=this.params.arrowLength+e,n=i+2*s,h=[{x:this.params.arrowLength,y:u.y},{x:i,y:u.y},{x:i,y:this.params.side},{x:n,y:this.params.side},{x:n,y:-this.params.side},{x:i,y:-this.params.side},{x:i,y:u.y},{x:this.params.arrowLength,y:u.y}].map(c=>y(c,this.params.sourceDirection,u)),d=`M ${u.x} ${u.y} L ${h[0].x} ${h[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":d}${M(h,this.params.roundness)}`,this.midpoint={x:(h[3].x+h[4].x)/2,y:(h[3].y+h[4].y)/2}}}class qt{constructor(t){o(this,"path");o(this,"midpoint");this.params=t;const e=this.params.smallRadius,s=this.params.radius,i=e+s,n=e*s/i,a=Math.sqrt(i*i-e*e),h=a*e/i,d=a+s+this.params.arrowLength,c=this.params.arrowLength+h,g=[{x:this.params.arrowLength,y:u.y},{x:c,y:n},{x:c,y:-n},{x:d,y:0}].map(m=>y(m,this.params.sourceDirection,u)),w=[`M ${g[0].x} ${g[0].y}`,`A ${e} ${e} 0 0 1 ${g[1].x} ${g[1].y}`,`A ${s} ${s} 0 1 0 ${g[2].x} ${g[2].y}`,`A ${e} ${e} 0 0 1 ${g[0].x} ${g[0].y}`].join(" "),f=`M 0 0 L ${g[0].x} ${g[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":f}${w}`,this.midpoint=g[3]}}class te{constructor(t){o(this,"path");o(this,"midpoint");o(this,"diagonalDistance");this.params=t;const e=this.params.to;if(this.midpoint={x:e.x/2,y:e.y/2},this.diagonalDistance=Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y),Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y)===0){this.path="";return}const i=this.createDirectLinePoint({offset:this.params.sourceOffset,hasArrow:this.params.hasSourceArrow,flip:1,shift:u}),n=this.createDirectLinePoint({offset:this.params.targetOffset,hasArrow:this.params.hasTargetArrow,flip:-1,shift:this.params.to});this.path=`M ${i.x} ${i.y} L ${n.x} ${n.y}`}createDirectLinePoint(t){const e=t.hasArrow?this.params.arrowLength:0,s=t.offset+e,i=t.flip*s/this.diagonalDistance;return{x:this.params.to.x*i+t.shift.x,y:this.params.to.y*i+t.shift.y}}}class ee{constructor(t){o(this,"path");o(this,"midpoint");this.params=t;const e=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=y({x:i,y:u.y},this.params.sourceDirection,u),a=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.y/2,c=d+Math.abs(this.params.detourDistance),l=d+c*this.params.flipY*h,g={x:(n.x+a.x)/2,y:l};this.midpoint=B(g,t.flipX,t.flipY,t.to),this.path=M([e,n,{x:n.x,y:l},{x:a.x,y:l},a,s],this.params.roundness)}}class re{constructor(t){o(this,"path");o(this,"midpoint");this.params=t;const e=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=y({x:i,y:u.y},this.params.sourceDirection,u),a=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.x/2,c=d+Math.abs(this.params.detourDistance),l=d+c*this.params.flipX*h,g={x:l,y:(n.y+a.y)/2};this.midpoint=B(g,t.flipX,t.flipY,t.to),this.path=M([e,n,{x:l,y:n.y},{x:l,y:a.y},a,s],this.params.roundness)}}const lt=(r,t)=>{r.style.transform=`translate(${t.x}px, ${t.y}px)`,r.style.width=`${Math.max(t.width,1)}px`,r.style.height=`${Math.max(t.height,1)}px`},j=Object.freeze({edgeColor:"--edge-color"}),ut=r=>{const t=document.createElementNS("http://www.w3.org/2000/svg","svg");return t.style.pointerEvents="none",t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.overflow="visible",t.style.setProperty(j.edgeColor,r),t},$=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("fill",`var(${j.edgeColor})`),r},pt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.transformOrigin="50% 50%",r},wt=r=>{const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("stroke",`var(${j.edgeColor})`),t.setAttribute("stroke-width",`${r}`),t.setAttribute("fill","none"),t},ft=(r,t)=>{const e={x:r.x+r.width/2,y:r.y+r.height/2},s={x:t.x+t.width/2,y:t.y+t.height/2},i=Math.min(e.x,s.x),n=Math.min(e.y,s.y),a=Math.abs(s.x-e.x),h=Math.abs(s.y-e.y),d=e.x<=s.x?1:-1,c=e.y<=s.y?1:-1;return{x:i,y:n,width:a,height:h,flipX:d,flipY:c}},G=(r,t,e,s)=>{const n=[u,{x:e,y:s},{x:e,y:-s}].map(c=>y(c,r,u)).map(c=>({x:c.x+t.x,y:c.y+t.y})),a=`M ${n[0].x} ${n[0].y}`,h=`L ${n[1].x} ${n[1].y}`,d=`L ${n[2].x} ${n[2].y}`;return`${a} ${h} ${d} Z`},p=Object.freeze({color:"#777777",width:1,arrowLength:15,arrowWidth:4,arrowOffset:15,hasSourceArrow:!1,hasTargetArrow:!1,cycleRadius:30,cycleSquareSide:30,roundness:10,detourDistance:100,detourDirection:-Math.PI/2,detourDirectionVertical:0,smallCycleRadius:15,curvature:90,interactiveWidth:10,preOffset:0}),yt=(r,t,e)=>({x:t*Math.cos(r),y:e*Math.sin(r)});class F{constructor(t){o(this,"svg");o(this,"group",pt());o(this,"line");o(this,"sourceArrow",null);o(this,"targetArrow",null);o(this,"onAfterRender");o(this,"afterRenderEmitter");this.params=t,[this.afterRenderEmitter,this.onAfterRender]=S(),this.svg=ut(t.color),this.svg.appendChild(this.group),this.line=wt(t.width),this.group.appendChild(this.line),t.hasSourceArrow&&(this.sourceArrow=$(),this.group.appendChild(this.sourceArrow)),t.hasTargetArrow&&(this.targetArrow=$(),this.group.appendChild(this.targetArrow))}render(t){const{x:e,y:s,width:i,height:n,flipX:a,flipY:h}=ft(t.from,t.to);lt(this.svg,{x:e,y:s,width:i,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d=yt(t.from.direction,a,h),c=yt(t.to.direction,a,h),l={x:i,y:n};let g=c,w=-this.params.arrowLength,f;t.category===T.PortCycle?(f=this.params.createCyclePath,g=d,w=this.params.arrowLength):t.category===T.NodeCycle?f=this.params.createDetourPath:f=this.params.createLinePath;const m=f(d,c,l,a,h);this.line.setAttribute("d",m.path);let A=null;this.sourceArrow&&(A=G(d,u,this.params.arrowLength,this.params.arrowWidth),this.sourceArrow.setAttribute("d",A));let x=null;this.targetArrow&&(x=G(g,l,w,this.params.arrowWidth),this.targetArrow.setAttribute("d",x)),this.afterRenderEmitter.emit({edgePath:m,sourceArrowPath:A,targetArrowPath:x})}}class mt{constructor(t){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowWidth");o(this,"curvature");o(this,"portCycleRadius");o(this,"portCycleSmallRadius");o(this,"detourDirection");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",t=>new qt({sourceDirection:t,radius:this.portCycleRadius,smallRadius:this.portCycleSmallRadius,arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(t,e,s,i,n)=>new Kt({to:s,sourceDirection:t,targetDirection:e,flipX:i,flipY:n,arrowLength:this.arrowLength,detourDirection:this.detourDirection,detourDistance:this.detourDistance,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(t,e,s)=>new Gt({to:s,sourceDirection:t,targetDirection:e,arrowLength:this.arrowLength,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(t==null?void 0:t.arrowLength)??p.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??p.arrowWidth,this.curvature=(t==null?void 0:t.curvature)??p.curvature,this.portCycleRadius=(t==null?void 0:t.cycleRadius)??p.cycleRadius,this.portCycleSmallRadius=(t==null?void 0:t.smallCycleRadius)??p.smallCycleRadius,this.detourDirection=(t==null?void 0:t.detourDirection)??p.detourDirection,this.detourDistance=(t==null?void 0:t.detourDistance)??p.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??p.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??p.hasTargetArrow,this.pathShape=new F({color:(t==null?void 0:t.color)??p.color,width:(t==null?void 0:t.width)??p.width,arrowLength:this.arrowLength,arrowWidth:this.arrowWidth,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(t){this.pathShape.render(t)}}class vt{constructor(t){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowWidth");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",t=>new H({sourceDirection:t,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(t,e,s,i,n)=>new ee({to:s,sourceDirection:t,targetDirection:e,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(t,e,s,i)=>new Zt({to:s,sourceDirection:t,targetDirection:e,flipX:i,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(t==null?void 0:t.arrowLength)??p.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??p.arrowWidth,this.arrowOffset=(t==null?void 0:t.arrowOffset)??p.arrowOffset,this.cycleSquareSide=(t==null?void 0:t.cycleSquareSide)??p.cycleSquareSide;const e=(t==null?void 0:t.roundness)??p.roundness;this.roundness=Math.min(e,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(t==null?void 0:t.detourDistance)??p.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??p.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??p.hasTargetArrow,this.pathShape=new F({color:(t==null?void 0:t.color)??p.color,width:(t==null?void 0:t.width)??p.width,arrowLength:this.arrowLength,arrowWidth:this.arrowWidth,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(t){this.pathShape.render(t)}}class Et{constructor(t){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowWidth");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDirection");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",t=>new H({sourceDirection:t,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(t,e,s,i,n)=>new Jt({to:s,sourceDirection:t,targetDirection:e,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(t,e,s)=>new Qt({to:s,sourceDirection:t,targetDirection:e,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(t==null?void 0:t.arrowLength)??p.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??p.arrowWidth,this.arrowOffset=(t==null?void 0:t.arrowOffset)??p.arrowOffset,this.cycleSquareSide=(t==null?void 0:t.cycleSquareSide)??p.cycleSquareSide;const e=(t==null?void 0:t.roundness)??p.roundness;this.roundness=Math.min(e,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(t==null?void 0:t.detourDirection)??p.detourDirection,this.detourDistance=(t==null?void 0:t.detourDistance)??p.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??p.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??p.hasTargetArrow,this.pathShape=new F({color:(t==null?void 0:t.color)??p.color,width:(t==null?void 0:t.width)??p.width,arrowLength:this.arrowLength,arrowWidth:this.arrowWidth,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(t){this.pathShape.render(t)}}class At{constructor(t){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowWidth");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",t=>new H({sourceDirection:t,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(t,e,s,i,n)=>new re({to:s,sourceDirection:t,targetDirection:e,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(t,e,s,i,n)=>new _t({to:s,sourceDirection:t,targetDirection:e,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(t==null?void 0:t.arrowLength)??p.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??p.arrowWidth,this.arrowOffset=(t==null?void 0:t.arrowOffset)??p.arrowOffset,this.cycleSquareSide=(t==null?void 0:t.cycleSquareSide)??p.cycleSquareSide;const e=(t==null?void 0:t.roundness)??p.roundness;this.roundness=Math.min(e,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(t==null?void 0:t.detourDistance)??p.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??p.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??p.hasTargetArrow,this.pathShape=new F({color:(t==null?void 0:t.color)??p.color,width:(t==null?void 0:t.width)??p.width,arrowLength:this.arrowLength,arrowWidth:this.arrowWidth,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(t){this.pathShape.render(t)}}const xt=r=>{if(r.diagonalDistance===0)return"";const t=r.offset/r.diagonalDistance,e=r.flip*r.to.x,s=r.flip*r.to.y,i={x:e*t+r.shift.x,y:s*t+r.shift.y},n={x:e/r.diagonalDistance,y:s/r.diagonalDistance};return G(n,i,r.arrowLength,r.arrowWidth)};class K{constructor(t){o(this,"svg");o(this,"group",pt());o(this,"line");o(this,"sourceArrow",null);o(this,"targetArrow",null);o(this,"color");o(this,"width");o(this,"arrowLength");o(this,"arrowWidth");o(this,"sourceOffset");o(this,"targetOffset");o(this,"onAfterRender");o(this,"afterRenderEmitter");[this.afterRenderEmitter,this.onAfterRender]=S(),this.color=(t==null?void 0:t.color)??p.color,this.width=(t==null?void 0:t.width)??p.width,this.arrowLength=(t==null?void 0:t.arrowLength)??p.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??p.arrowWidth,this.sourceOffset=(t==null?void 0:t.sourceOffset)??p.preOffset,this.targetOffset=(t==null?void 0:t.targetOffset)??p.preOffset,this.svg=ut(this.color),this.svg.appendChild(this.group),this.line=wt(this.width),this.group.appendChild(this.line),t!=null&&t.hasSourceArrow&&(this.sourceArrow=$(),this.group.appendChild(this.sourceArrow)),t!=null&&t.hasTargetArrow&&(this.targetArrow=$(),this.group.appendChild(this.targetArrow))}render(t){const{x:e,y:s,width:i,height:n,flipX:a,flipY:h}=ft(t.from,t.to);lt(this.svg,{x:e,y:s,width:i,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d={x:i,y:n},c=new te({to:d,sourceOffset:this.sourceOffset,targetOffset:this.targetOffset,hasSourceArrow:this.sourceArrow!==null,hasTargetArrow:this.targetArrow!==null,arrowLength:this.arrowLength});this.line.setAttribute("d",c.path);let l=null;this.sourceArrow&&(l=xt({diagonalDistance:c.diagonalDistance,to:d,offset:this.sourceOffset,flip:1,shift:u,arrowWidth:this.arrowWidth,arrowLength:this.arrowLength}),this.sourceArrow.setAttribute("d",l));let g=null;this.targetArrow&&(g=xt({diagonalDistance:c.diagonalDistance,to:d,offset:this.targetOffset,flip:-1,shift:d,arrowWidth:this.arrowWidth,arrowLength:this.arrowLength}),this.targetArrow.setAttribute("d",g)),this.afterRenderEmitter.emit({edgePath:c,sourceArrowPath:l,targetArrowPath:g})}}const oe=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.pointerEvents="auto",r.style.cursor="pointer",r},se=r=>{const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("stroke","transparent"),t.setAttribute("stroke-width",`${r}`),t.setAttribute("fill","none"),t.setAttribute("stroke-linecap","round"),t},St=r=>{const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("stroke-linejoin","round"),t.setAttribute("stroke-width",`${r}`),t.setAttribute("fill","transparent"),t.setAttribute("stroke","transparent"),t};class Pt extends Error{constructor(t){super(t),this.name="InteractiveEdgeError"}}class Z{constructor(t,e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"handle",oe());o(this,"onAfterRender");o(this,"interactiveLine");o(this,"interactiveSourceArrow",null);o(this,"interactiveTargetArrow",null);if(this.baseEdge=t,t instanceof Z)throw new Pt("interactive edge can be configured only once");this.svg=this.baseEdge.svg,this.group=this.baseEdge.group,this.line=this.baseEdge.line,this.sourceArrow=this.baseEdge.sourceArrow,this.targetArrow=this.baseEdge.targetArrow,this.onAfterRender=this.baseEdge.onAfterRender;const s=(e==null?void 0:e.distance)??p.interactiveWidth;this.interactiveLine=se(s),this.handle.appendChild(this.interactiveLine),this.sourceArrow&&(this.interactiveSourceArrow=St(s),this.handle.appendChild(this.interactiveSourceArrow)),this.targetArrow&&(this.interactiveTargetArrow=St(s),this.handle.appendChild(this.interactiveTargetArrow)),this.group.appendChild(this.handle),this.baseEdge.onAfterRender.subscribe(i=>{this.interactiveLine.setAttribute("d",i.edgePath.path),this.interactiveSourceArrow&&this.interactiveSourceArrow.setAttribute("d",i.sourceArrowPath),this.interactiveTargetArrow&&this.interactiveTargetArrow.setAttribute("d",i.targetArrowPath)})}render(t){this.baseEdge.render(t)}}class ie{constructor(t,e){o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"svg");this.baseShape=t,this.midpointElement=e,this.svg=this.baseShape.svg,this.group=this.baseShape.group,this.line=this.baseShape.line,this.sourceArrow=this.baseShape.sourceArrow,this.targetArrow=this.baseShape.targetArrow,this.onAfterRender=this.baseShape.onAfterRender,this.svg.append(this.midpointElement),this.baseShape.onAfterRender.subscribe(s=>{const i=s.edgePath.midpoint,n=`translate(${i.x}px, ${i.y}px)`;this.midpointElement.style.setProperty("transform",n)})}render(t){this.baseShape.render(t)}}const bt=(r,t)=>{const e=new at,s=new st(e,t,r),i={nodes:{centerFn:gt,priorityFn:()=>0},edges:{shapeFactory:()=>new K,priorityFn:()=>0},ports:{direction:0}};return new nt(e,t,s,i)};class O{constructor(t,e,s,i){o(this,"onAfterPortMarked",t=>{const e=this.canvas.graph.getPort(t);this.canvas.graph.getElementPortIds(e.element).length===1&&this.hookPortEvents(e.element)});o(this,"onBeforePortUnmarked",t=>{const e=this.canvas.graph.getPort(t);this.canvas.graph.getElementPortIds(e.element).length===1&&this.unhookPortEvents(e.element)});o(this,"onPortMouseDown",t=>{if(!this.params.mouseDownEventVerifier(t))return;const e=t.currentTarget,s=this.canvas.graph.getElementPortIds(e)[0];this.params.onPortPointerDown(s,{x:t.clientX,y:t.clientY})&&(t.stopPropagation(),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}))});o(this,"onWindowMouseMove",t=>{if(!R(this.window,this.element,t.clientX,t.clientY)){this.stopMouseDrag();return}this.params.onPointerMove({x:t.clientX,y:t.clientY})});o(this,"onWindowMouseUp",t=>{this.params.mouseUpEventVerifier(t)&&(this.params.onPointerUp({x:t.clientX,y:t.clientY}),this.stopMouseDrag())});o(this,"onPortTouchStart",t=>{if(t.touches.length!==1)return;const e=t.touches[0],s=t.currentTarget,i=this.canvas.graph.getElementPortIds(s)[0];this.params.onPortPointerDown(i,{x:e.clientX,y:e.clientY})&&(t.stopPropagation(),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}))});o(this,"onWindowTouchMove",t=>{const e=t.touches[0];if(!R(this.window,this.element,e.clientX,e.clientY)){this.stopTouchDrag();return}this.params.onPointerMove({x:e.clientX,y:e.clientY})});o(this,"onWindowTouchFinish",t=>{const e=t.changedTouches[0];this.params.onPointerUp({x:e.clientX,y:e.clientY}),this.stopTouchDrag()});o(this,"onBeforeClear",()=>{this.canvas.graph.getAllPortIds().forEach(t=>{const e=this.canvas.graph.getPort(t);this.unhookPortEvents(e.element)})});o(this,"onBeforeDestroy",()=>{this.params.onStopDrag(),this.removeWindowMouseListeners(),this.removeWindowTouchListeners()});this.canvas=t,this.element=e,this.window=s,this.params=i,this.canvas.graph.onAfterPortMarked.subscribe(this.onAfterPortMarked),this.canvas.graph.onBeforePortUnmarked.subscribe(this.onBeforePortUnmarked),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(t,e,s,i){new O(t,e,s,i)}hookPortEvents(t){t.addEventListener("mousedown",this.onPortMouseDown,{passive:!0}),t.addEventListener("touchstart",this.onPortTouchStart,{passive:!0})}unhookPortEvents(t){t.removeEventListener("mousedown",this.onPortMouseDown),t.removeEventListener("touchstart",this.onPortTouchStart)}stopMouseDrag(){this.params.onStopDrag(),this.removeWindowMouseListeners()}stopTouchDrag(){this.params.onStopDrag(),this.removeWindowTouchListeners()}removeWindowMouseListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}removeWindowTouchListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}class J{constructor(t,e,s,i){o(this,"grabbedNode",null);o(this,"maxNodePriority",0);o(this,"graph");o(this,"onAfterNodeAdded",t=>{this.updateMaxNodePriority(t);const e=this.graph.getNode(t);e.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),e.element.addEventListener("touchstart",this.onTouchStart,{passive:!0})});o(this,"onAfterNodeUpdated",t=>{this.updateMaxNodePriority(t)});o(this,"onBeforeNodeRemoved",t=>{const e=this.graph.getNode(t);e.element.removeEventListener("mousedown",this.onMouseDown),e.element.removeEventListener("touchstart",this.onTouchStart)});o(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});o(this,"onBeforeClear",()=>{this.canvas.graph.getAllNodeIds().forEach(t=>{const e=this.canvas.graph.getNode(t);e.element.removeEventListener("mousedown",this.onMouseDown),e.element.removeEventListener("touchstart",this.onTouchStart)}),this.maxNodePriority=0});o(this,"onMouseDown",t=>{if(!this.params.mouseDownEventVerifier(t))return;const e=t.currentTarget,s=this.graph.getElementNodeId(e),i=this.graph.getNode(s);if(!this.params.nodeDragVerifier(s))return;t.stopPropagation();const a=this.calculateContentPoint({x:t.clientX,y:t.clientY});this.grabbedNode={nodeId:s,dx:a.x-i.x,dy:a.y-i.y},U(this.element,this.params.dragCursor),this.moveNodeOnTop(s),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0})});o(this,"onTouchStart",t=>{if(t.touches.length!==1)return;t.stopPropagation();const e=t.touches[0],s=t.currentTarget,i=this.canvas.graph.getElementNodeId(s),n=this.graph.getNode(i);if(!this.params.nodeDragVerifier({nodeId:i,element:n.element,x:n.x,y:n.y}))return;const h=this.calculateContentPoint({x:e.clientX,y:e.clientY});this.grabbedNode={nodeId:i,dx:h.x-n.x,dy:h.y-n.y},this.moveNodeOnTop(i),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0})});o(this,"onWindowMouseMove",t=>{if(!R(this.window,this.element,t.clientX,t.clientY)){this.cancelMouseDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:t.clientX,y:t.clientY})});o(this,"onWindowMouseUp",t=>{this.params.mouseUpEventVerifier(t)&&this.cancelMouseDrag()});o(this,"onWindowTouchMove",t=>{if(t.touches.length!==1)return;const e=t.touches[0];if(!R(this.window,this.element,e.clientX,e.clientY)){this.cancelTouchDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:e.clientX,y:e.clientY})});o(this,"onWindowTouchFinish",()=>{this.cancelTouchDrag()});this.canvas=t,this.element=e,this.window=s,this.params=i,this.graph=t.graph,this.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graph.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(t,e,s,i){new J(t,e,s,i)}moveNode(t,e){if(this.graph.getNode(t.nodeId)===null)return;const i=this.calculateContentPoint(e),n={x:i.x-t.dx,y:i.y-t.dy},a=this.adjustNodeCoords(n);this.canvas.updateNode(t.nodeId,{x:a.x,y:a.y}),this.params.onNodeDrag(t.nodeId)}moveNodeOnTop(t){if(this.params.moveOnTop){if(this.maxNodePriority++,this.params.moveEdgesOnTop){const e=this.maxNodePriority;this.maxNodePriority++,this.graph.getNodeAdjacentEdgeIds(t).forEach(i=>{this.canvas.updateEdge(i,{priority:e})})}this.canvas.updateNode(t,{priority:this.maxNodePriority})}}cancelMouseDrag(){this.grabbedNode!==null&&this.graph.getNode(this.grabbedNode.nodeId)!==null&&this.params.onNodeDragFinished(this.grabbedNode.nodeId),this.grabbedNode=null,U(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}cancelTouchDrag(){if(this.grabbedNode!==null){const t=this.graph.getNode(this.grabbedNode.nodeId);t!==null&&this.params.onNodeDragFinished({nodeId:this.grabbedNode.nodeId,element:t.element,x:t.x,y:t.y})}this.grabbedNode=null,this.removeTouchDragListeners()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}updateMaxNodePriority(t){const e=this.graph.getNode(t).priority;this.maxNodePriority=Math.max(this.maxNodePriority,e)}calculateContentPoint(t){const e=this.element.getBoundingClientRect(),s={x:t.x-e.x,y:t.y-e.y},i=this.canvas.viewport.getViewportMatrix();return E(i,s)}adjustNodeCoords(t){const e=this.params.gridSize;if(e!==null){const s=e/2;return{x:Math.floor((t.x+s)/e)*e,y:Math.floor((t.y+s)/e)*e}}return t}}const ne=(r,t,e)=>({scale:r.scale,x:r.x+r.scale*t,y:r.y+r.scale*e}),ae=(r,t,e,s)=>({scale:r.scale*t,x:r.scale*(1-t)*e+r.x,y:r.scale*(1-t)*s+r.y}),k=r=>{const t=[],e=r.touches.length;for(let h=0;h<e;h++)t.push([r.touches[h].clientX,r.touches[h].clientY]);const s=t.reduce((h,d)=>[h[0]+d[0],h[1]+d[1]],[0,0]),i=[s[0]/e,s[1]/e],a=t.map(h=>[h[0]-i[0],h[1]-i[1]]).reduce((h,d)=>h+Math.sqrt(d[0]*d[0]+d[1]*d[1]),0);return{x:i[0],y:i[1],scale:a/e,touchesCnt:e,touches:t}};class z{constructor(t,e,s,i){o(this,"viewport");o(this,"prevTouches",null);o(this,"wheelFinishTimer",null);o(this,"transformInProgress",!1);o(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});o(this,"onMouseDown",t=>{this.element===null||!this.params.mouseDownEventVerifier(t)||(U(this.element,this.params.shiftCursor),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}),this.startRegisteredTransform())});o(this,"onWindowMouseMove",t=>{const e=R(this.window,this.element,t.clientX,t.clientY);if(this.element===null||!e){this.stopMouseDrag();return}const s=-t.movementX,i=-t.movementY;this.moveViewport(s,i)});o(this,"onWindowMouseUp",t=>{this.element===null||!this.params.mouseUpEventVerifier(t)||this.stopMouseDrag()});o(this,"onWheelScroll",t=>{if(!this.params.mouseWheelEventVerifier(t))return;const{left:e,top:s}=this.element.getBoundingClientRect(),i=t.clientX-e,n=t.clientY-s,h=1/(t.deltaY<0?this.params.wheelSensitivity:1/this.params.wheelSensitivity);this.wheelFinishTimer===null&&this.params.onTransformStarted(),this.scaleViewport(h,i,n),this.wheelFinishTimer!==null&&clearTimeout(this.wheelFinishTimer),this.wheelFinishTimer=setTimeout(()=>{this.transformInProgress||this.params.onTransformFinished(),this.wheelFinishTimer=null},this.params.scaleWheelFinishTimeout)});o(this,"onTouchStart",t=>{if(this.prevTouches!==null){this.prevTouches=k(t);return}this.prevTouches=k(t),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}),this.startRegisteredTransform()});o(this,"onWindowTouchMove",t=>{const e=k(t);if(!e.touches.every(i=>R(this.window,this.element,i[0],i[1]))){this.stopTouchDrag();return}if((e.touchesCnt===1||e.touchesCnt===2)&&this.moveViewport(-(e.x-this.prevTouches.x),-(e.y-this.prevTouches.y)),e.touchesCnt===2){const{left:i,top:n}=this.element.getBoundingClientRect(),a=this.prevTouches.x-i,h=this.prevTouches.y-n,c=1/(e.scale/this.prevTouches.scale);this.scaleViewport(c,a,h)}this.prevTouches=e});o(this,"onWindowTouchFinish",t=>{t.touches.length>0?this.prevTouches=k(t):this.stopTouchDrag()});o(this,"observer",new ResizeObserver(()=>{const t=this.viewport.getViewportMatrix(),{width:e,height:s}=this.element.getBoundingClientRect(),i=this.params.transformPreprocessor({prevTransform:t,nextTransform:t,canvasWidth:e,canvasHeight:s});this.params.onResizeTransformStarted(),this.canvas.patchViewportMatrix(i),this.params.onResizeTransformFinished()}));o(this,"preventWheelScaleListener",t=>{t.preventDefault()});this.canvas=t,this.element=e,this.window=s,this.params=i,this.element.addEventListener("wheel",this.preventWheelScaleListener,{passive:!1}),this.viewport=t.viewport,this.observer.observe(this.element),this.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),this.element.addEventListener("wheel",this.onWheelScroll,{passive:!0}),this.element.addEventListener("touchstart",this.onTouchStart,{passive:!0}),t.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(t,e,s,i){new z(t,e,s,i)}moveViewport(t,e){const s=this.viewport.getViewportMatrix(),i=ne(s,t,e),{width:n,height:a}=this.element.getBoundingClientRect(),h=this.params.transformPreprocessor({prevTransform:s,nextTransform:i,canvasWidth:n,canvasHeight:a});this.performTransform(h)}scaleViewport(t,e,s){const i=this.canvas.viewport.getViewportMatrix(),n=ae(i,t,e,s),{width:a,height:h}=this.element.getBoundingClientRect(),d=this.params.transformPreprocessor({prevTransform:i,nextTransform:n,canvasWidth:a,canvasHeight:h});this.performTransform(d)}stopMouseDrag(){U(this.element,null),this.removeMouseDragListeners(),this.finishRegisteredTransform()}removeMouseDragListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}stopTouchDrag(){this.prevTouches=null,this.removeTouchDragListeners(),this.finishRegisteredTransform()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}performTransform(t){this.params.onBeforeTransformChange(),this.canvas.patchViewportMatrix(t),this.params.onTransformChange()}startRegisteredTransform(){this.transformInProgress=!0,this.params.onTransformStarted()}finishRegisteredTransform(){this.transformInProgress=!1,this.params.onTransformFinished()}}class Q{constructor(t,e,s,i,n,a){o(this,"canvasResizeObserver");o(this,"nodeHorizontal");o(this,"nodeVertical");o(this,"viewport");o(this,"viewportWidth",0);o(this,"viewportHeight",0);o(this,"viewportMatrix");o(this,"loadedArea",{xFrom:1/0,xTo:1/0,yFrom:1/0,yTo:1/0});o(this,"updateLoadedArea",t=>{this.loadedArea={xFrom:t.x,xTo:t.x+t.width,yFrom:t.y,yTo:t.y+t.height}});o(this,"onAfterViewportUpdated",()=>{this.userTransformInProgress||(this.viewportMatrix=this.viewport.getViewportMatrix(),this.loadAreaAroundViewport())});o(this,"userTransformInProgress",!1);this.canvas=t,this.element=e,this.window=s,this.trigger=n,this.params=a,this.nodeHorizontal=this.params.nodeVerticalRadius,this.nodeVertical=this.params.nodeHorizontalRadius,this.canvasResizeObserver=new ResizeObserver(d=>{const c=d[0];this.viewportWidth=c.contentRect.width,this.viewportHeight=c.contentRect.height,this.scheduleLoadAreaAroundViewport()}),this.viewport=t.viewport;const h={...i,onResizeTransformStarted:()=>{this.userTransformInProgress=!0,i.onResizeTransformStarted()},onResizeTransformFinished:()=>{this.userTransformInProgress=!1,i.onResizeTransformFinished()},onBeforeTransformChange:()=>{this.userTransformInProgress=!0,i.onBeforeTransformChange()},onTransformChange:()=>{this.userTransformInProgress=!1;const d=this.viewportMatrix;this.viewportMatrix=this.viewport.getViewportMatrix(),d.scale!==this.viewportMatrix.scale&&this.scheduleEnsureViewportAreaLoaded(),i.onTransformChange()},onTransformFinished:()=>{this.scheduleLoadAreaAroundViewport(),i.onTransformFinished()}};z.configure(t,this.element,this.window,h),this.viewportMatrix=this.viewport.getViewportMatrix(),this.trigger.subscribe(this.updateLoadedArea),this.canvasResizeObserver.observe(this.element),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterViewportUpdated)}static configure(t,e,s,i,n,a){new Q(t,e,s,i,n,a)}scheduleLoadAreaAroundViewport(){setTimeout(()=>{this.loadAreaAroundViewport()})}scheduleEnsureViewportAreaLoaded(){const t=this.viewportWidth*this.viewportMatrix.scale,e=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-this.nodeHorizontal,i=this.viewportMatrix.y-this.nodeVertical,n=this.viewportMatrix.x+t+this.nodeHorizontal,a=this.viewportMatrix.y+e+this.nodeVertical;this.loadedArea.xFrom<s&&this.loadedArea.xTo>n&&this.loadedArea.yFrom<i&&this.loadedArea.yTo>a||this.scheduleLoadAreaAroundViewport()}loadAreaAroundViewport(){const t=this.viewportWidth*this.viewportMatrix.scale,e=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-t-this.nodeHorizontal,i=this.viewportMatrix.y-e-this.nodeVertical,n=3*t+2*this.nodeHorizontal,a=3*e+2*this.nodeVertical;this.trigger.emit({x:s,y:i,width:n,height:a})}}const he=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.style.position="absolute",r.style.inset="0",r},de=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","rect");return r.setAttribute("fill","url(#pattern)"),r},ce=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","pattern");return r.setAttribute("id","pattern"),r};class _{constructor(t,e,s){o(this,"svg",he());o(this,"patternRenderingRectangle",de());o(this,"pattern",ce());o(this,"patternContent");o(this,"tileWidth");o(this,"tileHeight");o(this,"halfTileWidth");o(this,"halfTileHeight");o(this,"maxViewportScale");o(this,"visible",!1);o(this,"resizeObserver",new ResizeObserver(t=>{const e=t[0],{width:s,height:i}=e.contentRect;this.svg.setAttribute("width",`${s}`),this.svg.setAttribute("height",`${i}`),this.patternRenderingRectangle.setAttribute("width",`${s}`),this.patternRenderingRectangle.setAttribute("height",`${i}`);const n=this.tileWidth/s,a=this.tileHeight/i;this.pattern.setAttribute("width",`${n}`),this.pattern.setAttribute("height",`${a}`)}));o(this,"onAfterTransformUpdated",()=>{const t=this.canvas.viewport.getContentMatrix(),e=t.x-this.halfTileWidth*t.scale,s=t.y-this.halfTileHeight*t.scale,i=`matrix(${t.scale}, 0, 0, ${t.scale}, ${e}, ${s})`;this.pattern.setAttribute("patternTransform",i),this.updateVisibility()});this.canvas=t,this.backgroundHost=s,this.tileWidth=e.tileWidth,this.tileHeight=e.tileHeight,this.halfTileWidth=this.tileWidth/2,this.halfTileHeight=this.tileHeight/2,this.patternContent=e.renderer,this.maxViewportScale=e.maxViewportScale;const i=`translate(${this.halfTileWidth}, ${this.halfTileHeight})`;this.patternContent.setAttribute("transform",i),this.pattern.appendChild(this.patternContent);const n=document.createElementNS("http://www.w3.org/2000/svg","defs");n.appendChild(this.pattern),this.svg.appendChild(n),this.svg.appendChild(this.patternRenderingRectangle),this.resizeObserver.observe(this.backgroundHost),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterTransformUpdated),this.onAfterTransformUpdated()}static configure(t,e,s){new _(t,e,s)}updateVisibility(){const e=this.canvas.viewport.getViewportMatrix().scale>this.maxViewportScale;e&&this.visible?(this.visible=!1,this.backgroundHost.removeChild(this.svg)):!e&&!this.visible&&(this.visible=!0,this.backgroundHost.appendChild(this.svg))}}class q{constructor(t,e,s,i,n){o(this,"overlayCanvas");o(this,"staticPortId",null);o(this,"isTargetDragging",!0);o(this,"onEdgeCreated",t=>{this.params.onAfterEdgeCreated(t)});this.canvas=t,this.overlayLayer=e,this.viewportStore=s,this.window=i,this.params=n,this.overlayCanvas=bt(this.overlayLayer,this.viewportStore),O.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>{const d=this.params.connectionTypeResolver(a);return d===null?!1:(this.grabPort(a,h,d),!0)},onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(t,e,s,i,n){new q(t,e,s,i,n)}grabPort(t,e,s){const i=this.canvas.graph.getPort(t);this.staticPortId=t;const n=i.element.getBoundingClientRect(),a=n.x+n.width/2,h=n.y+n.height/2,d=this.overlayLayer.getBoundingClientRect(),c=this.canvas.viewport.getViewportMatrix(),l=E(c,{x:a-d.x,y:h-d.y}),g=E(c,{x:e.x-d.x,y:e.y-d.y}),w={overlayId:D.Static,portCoords:l,portDirection:i.direction},f={overlayId:D.Dragging,portCoords:g,portDirection:this.params.dragPortDirection};this.isTargetDragging=s==="direct";const[m,A]=this.isTargetDragging?[w,f]:[f,w];this.overlayCanvas.addNode(W(m)),this.overlayCanvas.addNode(W(A)),this.overlayCanvas.addEdge({from:m.overlayId,to:A.overlayId,shape:this.params.edgeShapeFactory(D.Edge)})}resetDragState(){this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}tryCreateConnection(t){const e=ct(this.canvas.graph,t),s=this.staticPortId;if(e===null){this.params.onEdgeCreationInterrupted({staticPortId:s,isDirect:this.isTargetDragging});return}const i=this.isTargetDragging?s:e,n=this.isTargetDragging?e:s,a={from:i,to:n},h=this.params.connectionPreprocessor(a);h!==null?(this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated),this.canvas.addEdge(h),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeCreated)):this.params.onEdgeCreationPrevented(a)}moveDraggingPort(t){const e=this.overlayLayer.getBoundingClientRect(),s={x:t.x-e.x,y:t.y-e.y},i=this.canvas.viewport.getViewportMatrix(),n=E(i,s);this.overlayCanvas.updateNode(D.Dragging,{x:n.x,y:n.y})}}class tt{constructor(t,e,s,i,n){o(this,"overlayCanvas");o(this,"staticPortId",null);o(this,"isTargetDragging",!0);o(this,"draggingEdgePayload",null);o(this,"onEdgeReattached",t=>{this.params.onAfterEdgeReattached(t)});this.canvas=t,this.overlayLayer=e,this.viewportStore=s,this.window=i,this.params=n,this.overlayCanvas=bt(this.overlayLayer,this.viewportStore),O.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>this.tryStartEdgeDragging(a,h),onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(t,e,s,i,n){new tt(t,e,s,i,n)}tryStartEdgeDragging(t,e){const s=this.params.draggingEdgeResolver(t);if(s===null)return!1;const i=this.canvas.graph.getEdge(s);if(i===null)return!1;const n=t===i.from,a=t===i.to,h=n?i.to:i.from;this.staticPortId=h,this.isTargetDragging=a;const d=this.canvas.graph.getPort(t),c=this.canvas.graph.getPort(h),l=c.element.getBoundingClientRect(),g={x:l.x+l.width/2,y:l.y+l.height/2},w=this.canvas.viewport.getViewportMatrix(),f=this.overlayLayer.getBoundingClientRect(),m=E(w,{x:g.x-f.x,y:g.y-f.y}),A=E(w,{x:e.x-f.x,y:e.y-f.y});this.draggingEdgePayload={id:s,from:i.from,to:i.to,shape:i.shape,priority:i.priority},this.canvas.removeEdge(s);const x={overlayId:D.Static,portCoords:m,portDirection:c.direction},P={overlayId:D.Dragging,portCoords:A,portDirection:d.direction},[V,N]=this.isTargetDragging?[x,P]:[P,x];this.overlayCanvas.addNode(W(V)),this.overlayCanvas.addNode(W(N));const L=this.params.draggingEdgeShapeFactory!==null?this.params.draggingEdgeShapeFactory(D.Edge):i.shape;return this.overlayCanvas.addEdge({id:D.Edge,from:V.overlayId,to:N.overlayId,shape:L}),!0}resetDragState(){this.draggingEdgePayload=null,this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}moveDraggingPort(t){const e=this.overlayLayer.getBoundingClientRect(),s={x:t.x-e.x,y:t.y-e.y},i=this.canvas.viewport.getViewportMatrix(),n=E(i,s);this.overlayCanvas.updateNode(D.Dragging,{x:n.x,y:n.y})}tryCreateConnection(t){const e=ct(this.canvas.graph,t);if(this.overlayCanvas.removeEdge(D.Edge),e===null){const d=this.draggingEdgePayload;this.params.onEdgeReattachInterrupted({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority});return}const[s,i]=this.isTargetDragging?[this.staticPortId,e]:[e,this.staticPortId],n=this.draggingEdgePayload,a={id:n.id,from:s,to:i,shape:n.shape,priority:n.priority},h=this.params.connectionPreprocessor(a);if(h!==null)this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeReattached),this.canvas.addEdge(h),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeReattached);else{const d=this.draggingEdgePayload;this.params.onEdgeReattachPrevented({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority})}}}const ge=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r},et=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.inset="0",r},Tt=()=>{const r=et();return r.style.pointerEvents="none",r};class le{constructor(t){o(this,"background",et());o(this,"main",et());o(this,"overlayConnectablePorts",Tt());o(this,"overlayDraggableEdges",Tt());o(this,"host",ge());this.element=t,this.element.appendChild(this.host),this.host.appendChild(this.background),this.host.appendChild(this.main),this.host.appendChild(this.overlayConnectablePorts),this.host.appendChild(this.overlayDraggableEdges)}destroy(){this.host.removeChild(this.background),this.host.removeChild(this.main),this.host.removeChild(this.overlayConnectablePorts),this.host.removeChild(this.overlayDraggableEdges),this.element.removeChild(this.host)}}const rt=r=>()=>r,Dt=rt(0),ue=()=>{let r=0;return()=>r++},pe=(r,t)=>{let e=Dt,s=Dt;const i=ue();return r==="incremental"&&(e=i),t==="incremental"&&(s=i),typeof r=="number"&&(e=rt(r)),typeof t=="number"&&(s=rt(t)),typeof r=="function"&&(e=r),typeof t=="function"&&(s=t),{nodesPriorityFn:e,edgesPriorityFn:s}},ot=r=>{if(typeof r=="function")return r;switch(r==null?void 0:r.type){case"straight":return()=>new Et({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowWidth:r.arrowWidth,arrowOffset:r.arrowOffset,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance,detourDirection:r.detourDirection});case"horizontal":return()=>new vt({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowWidth:r.arrowWidth,arrowOffset:r.arrowOffset,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance});case"vertical":return()=>new At({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowWidth:r.arrowWidth,arrowOffset:r.arrowOffset,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance});case"direct":return()=>new K({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowWidth:r.arrowWidth,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,sourceOffset:r.sourceOffset,targetOffset:r.targetOffset});default:return()=>new mt({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowWidth:r.arrowWidth,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleRadius:r.cycleRadius,smallCycleRadius:r.smallCycleRadius,curvature:r.curvature,detourDistance:r.detourDistance,detourDirection:r.detourDirection})}},we=r=>{var e,s,i,n,a;const t=pe((e=r.nodes)==null?void 0:e.priority,(s=r.edges)==null?void 0:s.priority);return{nodes:{centerFn:((i=r.nodes)==null?void 0:i.centerFn)??gt,priorityFn:t.nodesPriorityFn},ports:{direction:((n=r.ports)==null?void 0:n.direction)??0},edges:{shapeFactory:ot(((a=r.edges)==null?void 0:a.shape)??{}),priorityFn:t.edgesPriorityFn}}},fe=r=>{var w,f,m,A,x;const t=((w=r.events)==null?void 0:w.onNodeDrag)??(()=>{}),e=r.nodeDragVerifier??(()=>!0),s=((f=r.events)==null?void 0:f.onNodeDragFinished)??(()=>{}),i=r.moveOnTop!==!1,n=r.moveEdgesOnTop!==!1&&i,a=(m=r.mouse)==null?void 0:m.dragCursor,h=a!==void 0?a:"grab",d=(A=r.mouse)==null?void 0:A.mouseDownEventVerifier,c=d!==void 0?d:P=>P.button===0,l=(x=r.mouse)==null?void 0:x.mouseUpEventVerifier,g=l!==void 0?l:P=>P.button===0;return{moveOnTop:i,moveEdgesOnTop:n,dragCursor:h,gridSize:r.gridSize??null,mouseDownEventVerifier:c,mouseUpEventVerifier:g,onNodeDrag:t,nodeDragVerifier:e,onNodeDragFinished:s}},ye=r=>{const t=r.minX!==null?r.minX:-1/0,e=r.maxX!==null?r.maxX:1/0,s=r.minY!==null?r.minY:-1/0,i=r.maxY!==null?r.maxY:1/0;return n=>{let a=n.nextTransform.x,h=n.nextTransform.y;a<t&&a<n.prevTransform.x&&(a=Math.min(n.prevTransform.x,t));const d=n.canvasWidth*n.prevTransform.scale,c=e-d;a>c&&a>n.prevTransform.x&&(a=Math.max(n.prevTransform.x,c)),h<s&&h<n.prevTransform.y&&(h=Math.min(n.prevTransform.y,s));const l=n.canvasHeight*n.prevTransform.scale,g=i-l;return h>g&&h>n.prevTransform.y&&(h=Math.max(n.prevTransform.y,g)),{scale:n.nextTransform.scale,x:a,y:h}}},me=r=>{const t=r.maxContentScale,e=r.minContentScale,s=t!==null?1/t:0,i=e!==null?1/e:1/0;return n=>{const a=n.prevTransform,h=n.nextTransform;let d=h.scale,c=h.x,l=h.y;if(h.scale>i&&h.scale>a.scale){d=Math.max(a.scale,i),c=a.x,l=a.y;const g=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*g,l=a.y+(h.y-a.y)*g}if(h.scale<s&&h.scale<a.scale){d=Math.min(a.scale,s),c=a.x,l=a.y;const g=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*g,l=a.y+(h.y-a.y)*g}return{scale:d,x:c,y:l}}},ve=r=>t=>r.reduce((e,s)=>s({prevTransform:t.prevTransform,nextTransform:e,canvasWidth:t.canvasWidth,canvasHeight:t.canvasHeight}),t.nextTransform),Nt=r=>{if(typeof r=="function")return r;switch(r.type){case"scale-limit":return me({minContentScale:r.minContentScale??0,maxContentScale:r.maxContentScale??1/0});case"shift-limit":return ye({minX:r.minX??-1/0,maxX:r.maxX??1/0,minY:r.minY??-1/0,maxY:r.maxY??1/0})}},Mt=r=>{var m,A,x,P,V,N,L,I,Ct,Rt,Vt,It;const t=(m=r==null?void 0:r.scale)==null?void 0:m.mouseWheelSensitivity,e=t!==void 0?t:1.2,s=r==null?void 0:r.transformPreprocessor;let i;s!==void 0?Array.isArray(s)?i=ve(s.map(C=>Nt(C))):i=Nt(s):i=C=>C.nextTransform;const n=((A=r==null?void 0:r.shift)==null?void 0:A.cursor)!==void 0?r.shift.cursor:"grab",a=((x=r==null?void 0:r.events)==null?void 0:x.onBeforeTransformChange)??(()=>{}),h=((P=r==null?void 0:r.events)==null?void 0:P.onTransformChange)??(()=>{}),d=(V=r==null?void 0:r.shift)==null?void 0:V.mouseDownEventVerifier,c=d!==void 0?d:C=>C.button===0,l=(N=r==null?void 0:r.shift)==null?void 0:N.mouseUpEventVerifier,g=l!==void 0?l:C=>C.button===0,w=(L=r==null?void 0:r.scale)==null?void 0:L.mouseWheelEventVerifier,f=w!==void 0?w:()=>!0;return{wheelSensitivity:e,onTransformStarted:((I=r==null?void 0:r.events)==null?void 0:I.onTransformStarted)??(()=>{}),onTransformFinished:((Ct=r==null?void 0:r.events)==null?void 0:Ct.onTransformFinished)??(()=>{}),onBeforeTransformChange:a,onTransformChange:h,transformPreprocessor:i,shiftCursor:n,mouseDownEventVerifier:c,mouseUpEventVerifier:g,mouseWheelEventVerifier:f,scaleWheelFinishTimeout:((Rt=r==null?void 0:r.scale)==null?void 0:Rt.wheelFinishTimeout)??500,onResizeTransformStarted:((Vt=r==null?void 0:r.events)==null?void 0:Vt.onResizeTransformStarted)??(()=>{}),onResizeTransformFinished:((It=r==null?void 0:r.events)==null?void 0:It.onResizeTransformFinished)??(()=>{})}},Ee=(r,t)=>{const e=document.createElementNS("http://www.w3.org/2000/svg","circle");return e.setAttribute("cx","0"),e.setAttribute("cy","0"),e.setAttribute("r",`${r}`),e.setAttribute("fill",`${t}`),e},Ae=r=>r instanceof SVGElement?r:Ee((r==null?void 0:r.radius)??1.5,(r==null?void 0:r.color)??"#d8d8d8"),xe=r=>{const t=r.tileDimensions,e=(t==null?void 0:t.width)??25,s=(t==null?void 0:t.height)??25,i=Ae(r.renderer??{});return{tileWidth:e,tileHeight:s,renderer:i,maxViewportScale:r.maxViewportScale??10}},Se=(r,t,e)=>{var c,l,g;const s=()=>"direct",i=w=>w,n=w=>w.button===0,a=()=>{},h=()=>{},d=()=>{};return{connectionTypeResolver:r.connectionTypeResolver??s,connectionPreprocessor:r.connectionPreprocessor??i,mouseDownEventVerifier:r.mouseDownEventVerifier??n,mouseUpEventVerifier:r.mouseUpEventVerifier??n,onAfterEdgeCreated:((c=r.events)==null?void 0:c.onAfterEdgeCreated)??a,onEdgeCreationInterrupted:((l=r.events)==null?void 0:l.onEdgeCreationInterrupted)??d,onEdgeCreationPrevented:((g=r.events)==null?void 0:g.onEdgeCreationPrevented)??h,dragPortDirection:r.dragPortDirection??e,edgeShapeFactory:r.edgeShape!==void 0?ot(r.edgeShape):t}},Pe=(r,t)=>{var c,l,g;const e=w=>w,s=w=>w.button===0&&w.ctrlKey,i=w=>w.button===0,n=w=>{const f=t.getPortAdjacentEdgeIds(w);return f.length>0?f[f.length-1]:null},a=()=>{},h=()=>{},d=()=>{};return{connectionPreprocessor:r.connectionPreprocessor??e,mouseDownEventVerifier:r.mouseDownEventVerifier??s,mouseUpEventVerifier:r.mouseUpEventVerifier??i,draggingEdgeResolver:r.draggingEdgeResolver??n,draggingEdgeShapeFactory:r.draggingEdgeShape!==void 0?ot(r.draggingEdgeShape):null,onAfterEdgeReattached:((c=r.events)==null?void 0:c.onAfterEdgeReattached)??a,onEdgeReattachInterrupted:((l=r.events)==null?void 0:l.onEdgeReattachInterrupted)??d,onEdgeReattachPrevented:((g=r.events)==null?void 0:g.onEdgeReattachPrevented)??h}},be=r=>({nodeVerticalRadius:r.nodeContainingRadius.vertical,nodeHorizontalRadius:r.nodeContainingRadius.horizontal}),Te=r=>{var t,e;return{onAfterNodeDetached:((t=r==null?void 0:r.events)==null?void 0:t.onAfterNodeDetached)??(()=>{}),onBeforeNodeAttached:((e=r==null?void 0:r.events)==null?void 0:e.onBeforeNodeAttached)??(()=>{})}};class Lt extends Error{constructor(){super(...arguments);o(this,"name","CanvasBuilderError")}}class De{constructor(t){o(this,"used",!1);o(this,"canvasDefaults",{});o(this,"dragConfig",{});o(this,"transformConfig",{});o(this,"backgroundConfig",{});o(this,"connectablePortsConfig",{});o(this,"draggableEdgesConfig",{});o(this,"virtualScrollConfig");o(this,"hasDraggableNode",!1);o(this,"hasTransformableViewport",!1);o(this,"hasNodeResizeReactiveEdges",!1);o(this,"hasBackground",!1);o(this,"hasUserConnectablePorts",!1);o(this,"hasUserDraggableEdges",!1);o(this,"boxRenderingTrigger",new it);o(this,"graphStore",new at);o(this,"viewportStore",new Xt);o(this,"window",window);this.element=t}setDefaults(t){return this.canvasDefaults=t,this}enableUserDraggableNodes(t){return this.hasDraggableNode=!0,this.dragConfig=t??{},this}enableUserTransformableViewport(t){return this.hasTransformableViewport=!0,this.transformConfig=t??{},this}enableNodeResizeReactiveEdges(){return this.hasNodeResizeReactiveEdges=!0,this}enableVirtualScroll(t){return this.virtualScrollConfig=t,this}enableBackground(t){return this.hasBackground=!0,this.backgroundConfig=t??{},this}enableUserConnectablePorts(t){return this.hasUserConnectablePorts=!0,this.connectablePortsConfig=t??{},this}enableUserDraggableEdges(t){return this.hasUserDraggableEdges=!0,this.draggableEdgesConfig=t??{},this}build(){if(this.used)throw new Lt("CanvasBuilder is a single use object");this.used=!0;const t=new le(this.element);let e=new st(this.graphStore,this.viewportStore,t.main);this.virtualScrollConfig!==void 0&&(e=new Ft(e,this.graphStore,this.boxRenderingTrigger,Te(this.virtualScrollConfig)));const s=we(this.canvasDefaults),i=new nt(this.graphStore,this.viewportStore,e,s);if(this.hasBackground&&_.configure(i,xe(this.backgroundConfig),t.background),this.hasNodeResizeReactiveEdges&&Y.configure(i),this.hasDraggableNode&&J.configure(i,t.main,this.window,fe(this.dragConfig)),this.hasUserConnectablePorts){const a=Se(this.connectablePortsConfig,s.edges.shapeFactory,s.ports.direction);q.configure(i,t.overlayConnectablePorts,this.viewportStore,this.window,a)}if(this.hasUserDraggableEdges){const a=Pe(this.draggableEdgesConfig,i.graph);tt.configure(i,t.overlayDraggableEdges,this.viewportStore,this.window,a)}this.virtualScrollConfig!==void 0?Q.configure(i,t.main,this.window,Mt(this.transformConfig),this.boxRenderingTrigger,be(this.virtualScrollConfig)):this.hasTransformableViewport&&z.configure(i,t.main,this.window,Mt(this.transformConfig));const n=()=>{t.destroy(),i.onBeforeDestroy.unsubscribe(n)};return i.onBeforeDestroy.subscribe(n),i}}v.BezierEdgeShape=mt,v.CanvasBuilder=De,v.CanvasBuilderError=Lt,v.CanvasError=b,v.DirectEdgeShape=K,v.HorizontalEdgeShape=vt,v.InteractiveEdgeError=Pt,v.InteractiveEdgeShape=Z,v.MidpointEdgeShape=ie,v.StraightEdgeShape=Et,v.VerticalEdgeShape=At,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@html-graph/html-graph",
3
3
  "author": "Dmitry Marov <d.marov94@gmail.com>",
4
4
  "private": false,
5
- "version": "3.21.0",
5
+ "version": "4.1.0",
6
6
  "type": "module",
7
7
  "main": "dist/html-graph.js",
8
8
  "types": "dist/html-graph.d.ts",