@html-graph/html-graph 3.17.0 → 3.19.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(y,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(y=typeof globalThis<"u"?globalThis:y||self,b(y.HtmlGraph={}))})(this,function(y){"use strict";var bt=Object.defineProperty;var Tt=(y,b,C)=>b in y?bt(y,b,{enumerable:!0,configurable:!0,writable:!0,value:C}):y[b]=C;var o=(y,b,C)=>Tt(y,typeof b!="symbol"?b+"":b,C);const b=()=>{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},C=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r.style.overflow="hidden",r},$e=r=>{r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.visibility="hidden"},D=(r,e)=>({x:r.scale*e.x+r.x,y:r.scale*e.y+r.y});var V=(r=>(r.Line="line",r.NodeCycle="node-cycle",r.PortCycle="port-cycle",r))(V||{});class he{constructor(e,t,s){o(this,"host",C());o(this,"container",b());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);$e(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,h=t.centerFn(s,i),a=t.x-n*h.x,d=t.y-n*h.y;t.element.style.transform=`translate(${a}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(),h=i.element.getBoundingClientRect(),a=this.host.getBoundingClientRect(),d=this.viewportStore.getViewportMatrix(),c=this.createEdgeRenderPort(t.from,s,n,a,d),l=this.createEdgeRenderPort(t.to,i,h,a,d);let g=V.Line;s.element===i.element?g=V.PortCycle:s.nodeId===i.nodeId&&(g=V.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 h={x:s.left-i.left,y:s.top-i.top},a=D(n,h);return{x:a.x,y:a.y,width:s.width*n.scale,height:s.height*n.scale,direction:t.direction,portId:e,nodeId:t.nodeId}}}class Fe{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),h=this.graphStore.getNode(i),a=Math.min(n.x,h.x),d=Math.max(n.x,h.x),c=Math.min(n.y,h.y),l=Math.max(n.y,h.y);return a<=this.xTo&&d>=this.xFrom&&c<=this.yTo&&l>=this.yFrom}}class Oe{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(h=>{const a=this.renderingBox.hasNode(h),d=this.attachedNodes.has(h);a&&!d?t.add(h):!a&&d&&s.add(h)}),this.graphStore.getAllEdgeIds().forEach(h=>{const a=this.renderingBox.hasEdge(h),d=this.attachedEdges.has(h),c=this.graphStore.getEdge(h),l=this.graphStore.getPort(c.from).nodeId,g=this.graphStore.getPort(c.to).nodeId;a&&(this.renderingBox.hasNode(l)||(t.add(l),s.delete(l)),this.renderingBox.hasNode(g)||(t.add(g),s.delete(g))),a&&!d?i.add(h):!a&&d&&n.add(h)}),n.forEach(h=>{this.handleDetachEdge(h)}),s.forEach(h=>{this.handleDetachNode(h)}),t.forEach(h=>{this.attachedNodes.has(h)||this.handleAttachNode(h)}),i.forEach(h=>{this.handleAttachEdge(h)})});this.htmlView=e,this.graphStore=t,this.trigger=s,this.params=i,this.renderingBox=new Fe(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.attachedNodes.add(e),this.params.onBeforeNodeAttached(e),this.htmlView.attachNode(e)}handleDetachNode(e){this.htmlView.detachNode(e),this.params.onAfterNodeDetached(e),this.attachedNodes.delete(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 E=()=>{const r=new H;return[r,r]};class ke{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 Y{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 S extends Error{constructor(){super(...arguments);o(this,"name","HtmlGraphError")}}class ae{constructor(e,t,s,i,n){o(this,"graph");o(this,"viewport");o(this,"nodeIdGenerator",new Y(e=>this.graph.getNode(e)!==null));o(this,"portIdGenerator",new Y(e=>this.graph.getPort(e)!==null));o(this,"edgeIdGenerator",new Y(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,"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 ke(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]=E()}addNode(e){const t=this.nodeIdGenerator.create(e.id);if(this.graph.getNode(t)!==null)throw new S("failed to add node with existing id");if(this.graphStore.getElementNodeId(e.element)!==void 0)throw new S("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 S("failed to update non existing node");return this.graphStore.updateNode(e,t??{}),this}removeNode(e){if(this.graph.getNode(e)===null)throw new S("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 S("failed to add port with existing id");if(this.graph.getNode(e.nodeId)===null)throw new S("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 S("failed to update nonexistent port");return this.graphStore.updatePort(e,t??{}),this}unmarkPort(e){if(this.graph.getPort(e)===null)throw new S("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 S("failed to add edge with existing id");if(this.graph.getPort(e.from)===null)throw new S("failed to add edge from nonexistent port");if(this.graph.getPort(e.to)===null)throw new S("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 S("failed to update nonexistent edge");return this.graphStore.updateEdge(e,t??{}),this}removeEdge(e){if(this.graph.getEdge(e)===null)throw new S("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.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()}}class Xe{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 de{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 Xe);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]=E(),[this.afterNodeUpdatedEmitter,this.onAfterNodeUpdated]=E(),[this.afterNodePriorityUpdatedEmitter,this.onAfterNodePriorityUpdated]=E(),[this.beforeNodeRemovedEmitter,this.onBeforeNodeRemoved]=E(),[this.afterPortAddedEmitter,this.onAfterPortAdded]=E(),[this.afterPortUpdatedEmitter,this.onAfterPortUpdated]=E(),[this.beforePortRemovedEmitter,this.onBeforePortRemoved]=E(),[this.afterEdgeAddedEmitter,this.onAfterEdgeAdded]=E(),[this.afterEdgeShapeUpdatedEmitter,this.onAfterEdgeShapeUpdated]=E(),[this.afterEdgeUpdatedEmitter,this.onAfterEdgeUpdated]=E(),[this.afterEdgePriorityUpdatedEmitter,this.onAfterEdgePriorityUpdated]=E(),[this.beforeEdgeRemovedEmitter,this.onBeforeEdgeRemoved]=E(),[this.beforeClearEmitter,this.onBeforeClear]=E()}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 ce=r=>({scale:1/r.scale,x:-r.x/r.scale,y:-r.y/r.scale}),ge={scale:1,x:0,y:0};class He{constructor(){o(this,"viewportMatrix",ge);o(this,"contentMatrix",ge);o(this,"afterUpdateEmitter");o(this,"onAfterUpdated");o(this,"beforeUpdateEmitter");o(this,"onBeforeUpdated");[this.afterUpdateEmitter,this.onAfterUpdated]=E(),[this.beforeUpdateEmitter,this.onBeforeUpdated]=E()}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=ce(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=ce(this.contentMatrix),this.afterUpdateEmitter.emit()}}class j{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()});o(this,"onBeforeDestroy",()=>{this.canvas.graph.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded),this.canvas.graph.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved),this.canvas.graph.onBeforeClear.unsubscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy)});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),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e){new j(e)}handleNodeResize(e){const t=this.elementToNodeId.get(e);this.canvas.updateNode(t)}}const Ye=(r,e,t)=>{const{x:s,y:i,width:n,height:h}=r.getBoundingClientRect();return e>=s&&e<=s+n&&t>=i&&t<=i+h},je=(r,e,t)=>e>=0&&e<=r.innerWidth&&t>=0&&t<=r.innerHeight,I=(r,e,t,s)=>Ye(e,t,s)&&je(r,t,s),$=(r,e)=>{e!==null?r.style.cursor=e:r.style.removeProperty("cursor")},F=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}]}},Ge=(r,e)=>{let t=e,s=null;for(;t!==null&&(s=r.getElementPortIds(t)[0]??null,s===null);)t=t.parentElement;return s},le=(r,e)=>{const t=document.elementsFromPoint(e.x,e.y);for(const s of t){const i=Ge(r,s);if(i!==null)return i}return null};var T=(r=>(r.Static="static",r.Dragging="dragging",r.Edge="edge",r))(T||{});const ue=(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)}),p={x:0,y:0};class Ke{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:p.y},this.params.sourceDirection,p),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},h={x:i.x-this.params.targetDirection.x*this.params.curvature,y:i.y-this.params.targetDirection.y*this.params.curvature},a=`M ${s.x} ${s.y} C ${n.x} ${n.y}, ${h.x} ${h.y}, ${i.x} ${i.y}`,d=this.params.hasSourceArrow?"":`M ${p.x} ${p.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}${a}${c}`}}const pe=(r,e,t,s)=>({x:e*r.x+(1-e)/2*s.x,y:t*r.y+(1-t)/2*s.y});class Ze{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,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,h=Math.sin(this.params.detourDirection)*this.params.detourDistance,a=n*this.params.flipX,d=h*this.params.flipY,c=m({x:i,y:p.y},this.params.sourceDirection,p),l={x:c.x+a,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+a,y:g.y+d},f={x:(l.x+w.x)/2,y:(l.y+w.y)/2},v={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+a,y:c.y+d},P={x:g.x+a,y:g.y+d};this.path=[`M ${t.x} ${t.y}`,`L ${c.x} ${c.y}`,`C ${v.x} ${v.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=pe(f,e.flipX,e.flipY,e.to)}}const U=(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,h=0;r.forEach((a,d)=>{let c=0,l=0,g=0;const w=d>0,f=d<s,v=w&&f;if(w&&(c=-i,l=-n,g=h),f){const W=r[d+1];i=W.x-a.x,n=W.y-a.y,h=Math.sqrt(i*i+n*n)}const x=h!==0?Math.min((v?e:0)/h,d<s-1?.5:1):0,P=v?{x:a.x+i*x,y:a.y+n*x}:a,M=g!==0?Math.min((v?e:0)/g,d>1?.5:1):0,L=v?{x:a.x+c*M,y:a.y+l*M}:a;d>0&&t.push(`L ${L.x} ${L.y}`),v&&t.push(`C ${a.x} ${a.y} ${a.x} ${a.y} ${P.x} ${P.y}`)})}return t.join(" ")};class Je{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:p.y},this.params.sourceDirection,p):p,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,h=n-this.params.roundness,a=m({x:h,y:p.y},this.params.sourceDirection,p),d=m({x:this.params.to.x-h,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((a.x+d.x)/2,n),l=this.params.to.y/2,g={x:this.params.flipX>0?c:-n,y:a.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},v={x:f.x,y:l};this.path=U([s,a,g,w,v,f,d,i],this.params.roundness)}}class G{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,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:p.y},this.params.sourceDirection,p),h=Math.cos(this.params.detourDirection)*this.params.detourDistance,a=Math.sin(this.params.detourDirection)*this.params.detourDistance,d=h*this.params.flipX,c=a*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=pe(f,e.flipX,e.flipY,e.to),this.path=U([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:p.y},this.params.sourceDirection,p):p,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,h=m({x:n,y:p.y},this.params.sourceDirection,p),a=m({x:this.params.to.x-n,y:this.params.to.y},this.params.targetDirection,this.params.to);this.path=U([s,h,a,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:p.y},this.params.sourceDirection,p):p,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,h=n-this.params.roundness,a=m({x:h,y:p.y},this.params.sourceDirection,p),d=m({x:this.params.to.x-h,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((a.y+d.y)/2,n),l=this.params.to.x/2,g={x:a.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},v={x:l,y:f.y};this.path=U([s,a,g,w,v,f,d,i],this.params.roundness)}}class K{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,a=[{x:this.params.arrowLength,y:p.y},{x:i,y:p.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:p.y},{x:this.params.arrowLength,y:p.y}].map(c=>m(c,this.params.sourceDirection,p)),d=`M ${p.x} ${p.y} L ${a[0].x} ${a[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":d}${U(a,this.params.roundness)}`,this.midpoint={x:(a[3].x+a[4].x)/2,y:(a[3].y+a[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,h=Math.sqrt(i*i-t*t),a=h*t/i,d=h+s+this.params.arrowLength,c=this.params.arrowLength+a,g=[{x:this.params.arrowLength,y:p.y},{x:c,y:n},{x:c,y:-n},{x:d,y:0}].map(v=>m(v,this.params.sourceDirection,p)),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:p}),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}}}const we=(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`},Z=Object.freeze({edgeColor:"--edge-color"}),fe=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(Z.edgeColor,r),e},O=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("fill",`var(${Z.edgeColor})`),r},ve=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.transformOrigin="50% 50%",r},me=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke",`var(${Z.edgeColor})`),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","none"),e},ye=(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),h=Math.abs(s.x-t.x),a=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:h,height:a,flipX:d,flipY:c}},J=(r,e,t,s)=>{const n=[p,{x:t,y:s},{x:t,y:-s}].map(c=>m(c,r,p)).map(c=>({x:c.x+e.x,y:c.y+e.y})),h=`M ${n[0].x} ${n[0].y}`,a=`L ${n[1].x} ${n[1].y}`,d=`L ${n[2].x} ${n[2].y}`;return`${h} ${a} ${d} Z`},u=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}),Ee=(r,e,t)=>({x:e*Math.cos(r),y:t*Math.sin(r)});class B{constructor(e){o(this,"svg");o(this,"group",ve());o(this,"line");o(this,"sourceArrow",null);o(this,"targetArrow",null);o(this,"onAfterRender");o(this,"afterRenderEmitter");this.params=e,[this.afterRenderEmitter,this.onAfterRender]=E(),this.svg=fe(e.color),this.svg.appendChild(this.group),this.line=me(e.width),this.group.appendChild(this.line),e.hasSourceArrow&&(this.sourceArrow=O(),this.group.appendChild(this.sourceArrow)),e.hasTargetArrow&&(this.targetArrow=O(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:i,height:n,flipX:h,flipY:a}=ye(e.from,e.to);we(this.svg,{x:t,y:s,width:i,height:n}),this.group.style.transform=`scale(${h}, ${a})`;const d=Ee(e.from.direction,h,a),c=Ee(e.to.direction,h,a),l={x:i,y:n};let g=c,w=-this.params.arrowLength,f;e.category===V.PortCycle?(f=this.params.createCyclePath,g=d,w=this.params.arrowLength):e.category===V.NodeCycle?f=this.params.createDetourPath:f=this.params.createLinePath;const v=f(d,c,l,h,a);this.line.setAttribute("d",v.path);let A=null;this.sourceArrow&&(A=J(d,p,this.params.arrowLength,this.params.arrowWidth),this.sourceArrow.setAttribute("d",A));let x=null;this.targetArrow&&(x=J(g,l,w,this.params.arrowWidth),this.targetArrow.setAttribute("d",x)),this.afterRenderEmitter.emit({edgePath:v,sourceArrowPath:A,targetArrowPath:x})}}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,"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 Ze({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 Ke({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)??u.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??u.arrowWidth,this.curvature=(e==null?void 0:e.curvature)??u.curvature,this.portCycleRadius=(e==null?void 0:e.cycleRadius)??u.cycleRadius,this.portCycleSmallRadius=(e==null?void 0:e.smallCycleRadius)??u.smallCycleRadius,this.detourDirection=(e==null?void 0:e.detourDirection)??u.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??u.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??u.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??u.hasTargetArrow,this.pathShape=new B({color:(e==null?void 0:e.color)??u.color,width:(e==null?void 0:e.width)??u.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 xe{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 K({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 G({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,i)=>new Je({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)??u.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??u.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??u.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??u.cycleSquareSide;const t=(e==null?void 0:e.roundness)??u.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??u.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??u.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??u.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??u.hasTargetArrow,this.pathShape=new B({color:(e==null?void 0:e.color)??u.color,width:(e==null?void 0:e.width)??u.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 Se{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 K({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 G({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)??u.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??u.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??u.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??u.cycleSquareSide;const t=(e==null?void 0:e.roundness)??u.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??u.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??u.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??u.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??u.hasTargetArrow,this.pathShape=new B({color:(e==null?void 0:e.color)??u.color,width:(e==null?void 0:e.width)??u.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 Pe{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 K({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 G({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,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)??u.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??u.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??u.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??u.cycleSquareSide;const t=(e==null?void 0:e.roundness)??u.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??u.detourDirectionVertical,this.detourDistance=(e==null?void 0:e.detourDistance)??u.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??u.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??u.hasTargetArrow,this.pathShape=new B({color:(e==null?void 0:e.color)??u.color,width:(e==null?void 0:e.width)??u.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 be=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 J(n,i,r.arrowLength,r.arrowWidth)};class Q{constructor(e){o(this,"svg");o(this,"group",ve());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]=E(),this.color=(e==null?void 0:e.color)??u.color,this.width=(e==null?void 0:e.width)??u.width,this.arrowLength=(e==null?void 0:e.arrowLength)??u.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??u.arrowWidth,this.sourceOffset=(e==null?void 0:e.sourceOffset)??u.preOffset,this.targetOffset=(e==null?void 0:e.targetOffset)??u.preOffset,this.svg=fe(this.color),this.svg.appendChild(this.group),this.line=me(this.width),this.group.appendChild(this.line),e!=null&&e.hasSourceArrow&&(this.sourceArrow=O(),this.group.appendChild(this.sourceArrow)),e!=null&&e.hasTargetArrow&&(this.targetArrow=O(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:i,height:n,flipX:h,flipY:a}=ye(e.from,e.to);we(this.svg,{x:t,y:s,width:i,height:n}),this.group.style.transform=`scale(${h}, ${a})`;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=be({diagonalDistance:c.diagonalDistance,to:d,offset:this.sourceOffset,flip:1,shift:p,arrowWidth:this.arrowWidth,arrowLength:this.arrowLength}),this.sourceArrow.setAttribute("d",l));let g=null;this.targetArrow&&(g=be({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 tt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.pointerEvents="auto",r.style.cursor="pointer",r},rt=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},Te=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 De extends Error{constructor(e){super(e),this.name="InteractiveEdgeError"}}class _{constructor(e,t){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"handle",tt());o(this,"onAfterRender");o(this,"interactiveLine");o(this,"interactiveSourceArrow",null);o(this,"interactiveTargetArrow",null);if(this.baseEdge=e,e instanceof _)throw new De("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)??u.interactiveWidth;this.interactiveLine=rt(s),this.handle.appendChild(this.interactiveLine),this.sourceArrow&&(this.interactiveSourceArrow=Te(s),this.handle.appendChild(this.interactiveSourceArrow)),this.targetArrow&&(this.interactiveTargetArrow=Te(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 Ne{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 Me=(r,e)=>{const t=new de,s=new he(t,e,r),i={nodes:{centerFn:ue,priorityFn:()=>0},edges:{shapeFactory:()=>new Q,priorityFn:()=>0},ports:{direction:0}};return new ae(r,t,e,s,i)};class q{constructor(e,t,s,i){o(this,"grabbedNodeId",null);o(this,"maxNodePriority",0);o(this,"previousTouchCoordinates",null);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.graph.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded),this.graph.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated),this.graph.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved),this.graph.onBeforeClear.unsubscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.unsubscribe(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.config.mouseDownEventVerifier(e))return;const t=e.currentTarget,s=this.graph.getElementNodeId(t),i=this.graph.getNode(s);this.config.onBeforeNodeDrag({nodeId:s,element:i.element,x:i.x,y:i.y})&&(e.stopImmediatePropagation(),this.grabbedNodeId=s,$(this.element,this.config.dragCursor),this.moveNodeOnTop(s),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}))});o(this,"onTouchStart",e=>{if(e.touches.length!==1)return;e.stopImmediatePropagation(),this.previousTouchCoordinates={x:e.touches[0].clientX,y:e.touches[0].clientY};const t=e.currentTarget,s=this.canvas.graph.getElementNodeId(t),i=this.graph.getNode(s);this.config.onBeforeNodeDrag({nodeId:s,element:i.element,x:i.x,y:i.y})&&(this.grabbedNodeId=s,this.moveNodeOnTop(s),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(!I(this.window,this.element,e.clientX,e.clientY)){this.cancelMouseDrag();return}this.grabbedNodeId!==null&&this.dragNode(this.grabbedNodeId,e.movementX,e.movementY)});o(this,"onWindowMouseUp",e=>{this.config.mouseUpEventVerifier(e)&&this.cancelMouseDrag()});o(this,"onWindowTouchMove",e=>{if(e.touches.length!==1)return;const t=e.touches[0];if(!I(this.window,this.element,t.clientX,t.clientY)){this.cancelTouchDrag();return}if(this.grabbedNodeId!==null&&this.previousTouchCoordinates!==null){const i=t.clientX-this.previousTouchCoordinates.x,n=t.clientY-this.previousTouchCoordinates.y;this.dragNode(this.grabbedNodeId,i,n),this.previousTouchCoordinates={x:e.touches[0].clientX,y:e.touches[0].clientY}}});o(this,"onWindowTouchFinish",()=>{this.previousTouchCoordinates=null,this.cancelTouchDrag()});this.canvas=e,this.element=t,this.window=s,this.config=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)}dragNode(e,t,s){const i=this.graph.getNode(e);if(i===null)return;const n=this.canvas.viewport.getContentMatrix(),h=D(n,{x:i.x,y:i.y}),a=D({scale:1,x:t,y:s},h),d=this.canvas.viewport.getViewportMatrix(),c=D(d,a);this.canvas.updateNode(e,{x:c.x,y:c.y}),this.config.onNodeDrag({nodeId:e,element:i.element,x:c.x,y:c.y})}moveNodeOnTop(e){if(this.config.moveOnTop){if(this.maxNodePriority++,this.config.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(){const e=this.graph.getNode(this.grabbedNodeId);e!==null&&this.config.onNodeDragFinished({nodeId:this.grabbedNodeId,element:e.element,x:e.x,y:e.y}),this.grabbedNodeId=null,$(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}cancelTouchDrag(){this.previousTouchCoordinates=null;const e=this.graph.getNode(this.grabbedNodeId);e!==null&&this.config.onNodeDragFinished({nodeId:this.grabbedNodeId,element:e.element,x:e.x,y:e.y}),this.grabbedNodeId=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)}}const ot=(r,e,t)=>({scale:r.scale,x:r.x+r.scale*e,y:r.y+r.scale*t}),st=(r,e,t,s)=>({scale:r.scale*e,x:r.scale*(1-e)*t+r.x,y:r.scale*(1-e)*s+r.y}),k=r=>{const e=[],t=r.touches.length;for(let a=0;a<t;a++)e.push([r.touches[a].clientX,r.touches[a].clientY]);const s=e.reduce((a,d)=>[a[0]+d[0],a[1]+d[1]],[0,0]),i=[s[0]/t,s[1]/t],h=e.map(a=>[a[0]-i[0],a[1]-i[1]]).reduce((a,d)=>a+Math.sqrt(d[0]*d[0]+d[1]*d[1]),0);return{x:i[0],y:i[1],scale:h/t,touchesCnt:t,touches:e}};class z{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(),this.observer.unobserve(this.element),this.element.removeEventListener("mousedown",this.onMouseDown),this.element.removeEventListener("wheel",this.onWheelScroll),this.element.removeEventListener("touchstart",this.onTouchStart),this.element.removeEventListener("wheel",this.preventWheelScaleListener),this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy)});o(this,"onMouseDown",e=>{this.element===null||!this.params.mouseDownEventVerifier(e)||($(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=I(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,a=1/(e.deltaY<0?this.params.wheelSensitivity:1/this.params.wheelSensitivity);this.wheelFinishTimer===null&&this.params.onTransformStarted(),this.scaleViewport(a,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=k(e);return}this.prevTouches=k(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=k(e);if(!t.touches.every(i=>I(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(),h=this.prevTouches.x-i,a=this.prevTouches.y-n,c=1/(t.scale/this.prevTouches.scale);this.scaleViewport(c,h,a)}this.prevTouches=t});o(this,"onWindowTouchFinish",e=>{e.touches.length>0?this.prevTouches=k(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 z(e,t,s,i)}moveViewport(e,t){const s=this.viewport.getViewportMatrix(),i=ot(s,e,t),{width:n,height:h}=this.element.getBoundingClientRect(),a=this.params.transformPreprocessor({prevTransform:s,nextTransform:i,canvasWidth:n,canvasHeight:h});this.performTransform(a)}scaleViewport(e,t,s){const i=this.canvas.viewport.getViewportMatrix(),n=st(i,e,t,s),{width:h,height:a}=this.element.getBoundingClientRect(),d=this.params.transformPreprocessor({prevTransform:i,nextTransform:n,canvasWidth:h,canvasHeight:a});this.performTransform(d)}stopMouseDrag(){$(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 ee{constructor(e,t,s,i,n,h){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,"onBeforeDestroy",()=>{this.trigger.unsubscribe(this.updateLoadedArea),this.canvasResizeObserver.unobserve(this.element),this.canvas.viewport.onAfterUpdated.unsubscribe(this.onAfterViewportUpdated),this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy)});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=h,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 a={...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(e,this.element,this.window,a),this.viewportMatrix=this.viewport.getViewportMatrix(),this.trigger.subscribe(this.updateLoadedArea),this.canvasResizeObserver.observe(this.element),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterViewportUpdated),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,i,n,h){new ee(e,t,s,i,n,h)}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,h=this.viewportMatrix.y+t+this.nodeVertical;this.loadedArea.xFrom<s&&this.loadedArea.xTo>n&&this.loadedArea.yFrom<i&&this.loadedArea.yTo>h||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,h=3*t+2*this.nodeVertical;this.trigger.emit({x:s,y:i,width:n,height:h})}}const it=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.style.position="absolute",r.style.inset="0",r},nt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","rect");return r.setAttribute("fill","url(#pattern)"),r},ht=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","pattern");return r.setAttribute("id","pattern"),r};class te{constructor(e,t,s){o(this,"svg",it());o(this,"patternRenderingRectangle",nt());o(this,"pattern",ht());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,h=this.tileHeight/i;this.pattern.setAttribute("width",`${n}`),this.pattern.setAttribute("height",`${h}`)}));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()});o(this,"onBeforeDestroy",()=>{this.resizeObserver.unobserve(this.host),this.host.removeChild(this.svg),this.canvas.viewport.onAfterUpdated.unsubscribe(this.onAfterTransformUpdated),this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy)});this.canvas=e,this.host=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.host),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterTransformUpdated),this.onAfterTransformUpdated(),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s){new te(e,t,s)}updateVisibility(){const t=this.canvas.viewport.getViewportMatrix().scale>this.maxViewportScale;t&&this.visible?(this.visible=!1,this.host.removeChild(this.svg)):!t&&!this.visible&&(this.visible=!0,this.host.appendChild(this.svg))}}class X{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(!I(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(!I(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.stopMouseDrag(),this.stopTouchDrag(),this.canvas.graph.onAfterPortMarked.unsubscribe(this.onAfterPortMarked),this.canvas.graph.onBeforePortUnmarked.unsubscribe(this.onBeforePortUnmarked),this.canvas.graph.onBeforeClear.unsubscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy)});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 X(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.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}stopTouchDrag(){this.params.onStopDrag(),this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}class re{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=Me(this.overlayLayer,this.viewportStore),X.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(h,a)=>{const d=this.params.connectionTypeResolver(h);return d===null?!1:(this.grabPort(h,a,d),!0)},onPointerMove:h=>{this.moveDraggingPort(h)},onPointerUp:h=>{this.tryCreateConnection(h)}})}static configure(e,t,s,i,n){new re(e,t,s,i,n)}grabPort(e,t,s){const i=this.canvas.graph.getPort(e);this.staticPortId=e;const n=i.element.getBoundingClientRect(),h=n.x+n.width/2,a=n.y+n.height/2,d=this.overlayLayer.getBoundingClientRect(),c=this.canvas.viewport.getViewportMatrix(),l=D(c,{x:h-d.x,y:a-d.y}),g=D(c,{x:t.x-d.x,y:t.y-d.y}),w={overlayId:T.Static,portCoords:l,portDirection:i.direction},f={overlayId:T.Dragging,portCoords:g,portDirection:this.params.dragPortDirection};this.isTargetDragging=s==="direct";const[v,A]=this.isTargetDragging?[w,f]:[f,w];this.overlayCanvas.addNode(F(v)),this.overlayCanvas.addNode(F(A)),this.overlayCanvas.addEdge({from:v.overlayId,to:A.overlayId,shape:this.params.edgeShapeFactory(T.Edge)})}resetDragState(){this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}tryCreateConnection(e){const t=le(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},h=this.params.connectionPreprocessor(n);h!==null?(this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated),this.canvas.addEdge(h),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=D(i,s);this.overlayCanvas.updateNode(T.Dragging,{x:n.x,y:n.y})}}class oe{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=Me(this.overlayLayer,this.viewportStore),X.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(h,a)=>this.tryStartEdgeDragging(h,a),onPointerMove:h=>{this.moveDraggingPort(h)},onPointerUp:h=>{this.tryCreateConnection(h)}})}static configure(e,t,s,i,n){new oe(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,h=e===i.to,a=n?i.to:i.from;this.staticPortId=a,this.isTargetDragging=h;const d=this.canvas.graph.getPort(e),c=this.canvas.graph.getPort(a),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(),v=D(w,{x:g.x-f.x,y:g.y-f.y}),A=D(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 x={overlayId:T.Static,portCoords:v,portDirection:c.direction},P={overlayId:T.Dragging,portCoords:A,portDirection:d.direction},[N,M]=this.isTargetDragging?[x,P]:[P,x];this.overlayCanvas.addNode(F(N)),this.overlayCanvas.addNode(F(M));const L=this.params.draggingEdgeShapeFactory!==null?this.params.draggingEdgeShapeFactory(T.Edge):i.shape;return this.overlayCanvas.addEdge({id:T.Edge,from:N.overlayId,to:M.overlayId,shape:L}),!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=D(i,s);this.overlayCanvas.updateNode(T.Dragging,{x:n.x,y:n.y})}tryCreateConnection(e){const t=le(this.canvas.graph,e);if(this.overlayCanvas.removeEdge(T.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,h={id:n.id,from:s,to:i,shape:n.shape,priority:n.priority},a=this.params.connectionPreprocessor(h);if(a!==null)this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeReattached),this.canvas.addEdge(a),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 at=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r},se=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.inset="0",r},Le=()=>{const r=se();return r.style.pointerEvents="none",r};class dt{constructor(e){o(this,"background",se());o(this,"main",se());o(this,"overlayConnectablePorts",Le());o(this,"overlayDraggableEdges",Le());o(this,"host",at());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 ie=r=>()=>r,Re=ie(0),ct=()=>{let r=0;return()=>r++},gt=(r,e)=>{let t=Re,s=Re;const i=ct();return r==="incremental"&&(t=i),e==="incremental"&&(s=i),typeof r=="number"&&(t=ie(r)),typeof e=="number"&&(s=ie(e)),typeof r=="function"&&(t=r),typeof e=="function"&&(s=e),{nodesPriorityFn:t,edgesPriorityFn:s}},ne=r=>{if(typeof r=="function")return r;switch(r==null?void 0:r.type){case"straight":return()=>new Se({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 xe({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 Pe({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 Q({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 Ae({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})}},lt=r=>{var t,s,i,n,h;const e=gt((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)??ue,priorityFn:e.nodesPriorityFn},ports:{direction:((n=r.ports)==null?void 0:n.direction)??0},edges:{shapeFactory:ne(((h=r.edges)==null?void 0:h.shape)??{}),priorityFn:e.edgesPriorityFn}}},ut=r=>{var w,f,v,A,x,P;const e=((w=r==null?void 0:r.events)==null?void 0:w.onNodeDrag)??(()=>{}),t=((f=r==null?void 0:r.events)==null?void 0:f.onBeforeNodeDrag)??(()=>!0),s=((v=r==null?void 0:r.events)==null?void 0:v.onNodeDragFinished)??(()=>{}),i=(r==null?void 0:r.moveOnTop)!==!1,n=(r==null?void 0:r.moveEdgesOnTop)!==!1&&i,h=(A=r==null?void 0:r.mouse)==null?void 0:A.dragCursor,a=h!==void 0?h:"grab",d=(x=r==null?void 0:r.mouse)==null?void 0:x.mouseDownEventVerifier,c=d!==void 0?d:N=>N.button===0,l=(P=r==null?void 0:r.mouse)==null?void 0:P.mouseUpEventVerifier;return{moveOnTop:i,moveEdgesOnTop:n,dragCursor:a,mouseDownEventVerifier:c,mouseUpEventVerifier:l!==void 0?l:N=>N.button===0,onNodeDrag:e,onBeforeNodeDrag:t,onNodeDragFinished:s}},pt=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 h=n.nextTransform.x,a=n.nextTransform.y;h<e&&h<n.prevTransform.x&&(h=Math.min(n.prevTransform.x,e));const d=n.canvasWidth*n.prevTransform.scale,c=t-d;h>c&&h>n.prevTransform.x&&(h=Math.max(n.prevTransform.x,c)),a<s&&a<n.prevTransform.y&&(a=Math.min(n.prevTransform.y,s));const l=n.canvasHeight*n.prevTransform.scale,g=i-l;return a>g&&a>n.prevTransform.y&&(a=Math.max(n.prevTransform.y,g)),{scale:n.nextTransform.scale,x:h,y:a}}},wt=r=>{const e=r.maxContentScale,t=r.minContentScale,s=e!==null?1/e:0,i=t!==null?1/t:1/0;return n=>{const h=n.prevTransform,a=n.nextTransform;let d=a.scale,c=a.x,l=a.y;if(a.scale>i&&a.scale>h.scale){d=Math.max(h.scale,i),c=h.x,l=h.y;const g=(d-h.scale)/(a.scale-h.scale);c=h.x+(a.x-h.x)*g,l=h.y+(a.y-h.y)*g}if(a.scale<s&&a.scale<h.scale){d=Math.min(h.scale,s),c=h.x,l=h.y;const g=(d-h.scale)/(a.scale-h.scale);c=h.x+(a.x-h.x)*g,l=h.y+(a.y-h.y)*g}return{scale:d,x:c,y:l}}},ft=r=>e=>r.reduce((t,s)=>s({prevTransform:e.prevTransform,nextTransform:t,canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight}),e.nextTransform),Ce=r=>{if(typeof r=="function")return r;switch(r.type){case"scale-limit":return wt({minContentScale:r.minContentScale??0,maxContentScale:r.maxContentScale??1/0});case"shift-limit":return pt({minX:r.minX??-1/0,maxX:r.maxX??1/0,minY:r.minY??-1/0,maxY:r.maxY??1/0})}},Ve=r=>{var v,A,x,P,N,M,L,W,Ie,Ue,Be,We;const e=(v=r==null?void 0:r.scale)==null?void 0:v.mouseWheelSensitivity,t=e!==void 0?e:1.2,s=r==null?void 0:r.transformPreprocessor;let i;s!==void 0?Array.isArray(s)?i=ft(s.map(R=>Ce(R))):i=Ce(s):i=R=>R.nextTransform;const n=((A=r==null?void 0:r.shift)==null?void 0:A.cursor)!==void 0?r.shift.cursor:"grab",h=((x=r==null?void 0:r.events)==null?void 0:x.onBeforeTransformChange)??(()=>{}),a=((P=r==null?void 0:r.events)==null?void 0:P.onTransformChange)??(()=>{}),d=(N=r==null?void 0:r.shift)==null?void 0:N.mouseDownEventVerifier,c=d!==void 0?d:R=>R.button===0,l=(M=r==null?void 0:r.shift)==null?void 0:M.mouseUpEventVerifier,g=l!==void 0?l:R=>R.button===0,w=(L=r==null?void 0:r.scale)==null?void 0:L.mouseWheelEventVerifier,f=w!==void 0?w:()=>!0;return{wheelSensitivity:t,onTransformStarted:((W=r==null?void 0:r.events)==null?void 0:W.onTransformStarted)??(()=>{}),onTransformFinished:((Ie=r==null?void 0:r.events)==null?void 0:Ie.onTransformFinished)??(()=>{}),onBeforeTransformChange:h,onTransformChange:a,transformPreprocessor:i,shiftCursor:n,mouseDownEventVerifier:c,mouseUpEventVerifier:g,mouseWheelEventVerifier:f,scaleWheelFinishTimeout:((Ue=r==null?void 0:r.scale)==null?void 0:Ue.wheelFinishTimeout)??500,onResizeTransformStarted:((Be=r==null?void 0:r.events)==null?void 0:Be.onResizeTransformStarted)??(()=>{}),onResizeTransformFinished:((We=r==null?void 0:r.events)==null?void 0:We.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},mt=r=>r instanceof SVGElement?r:vt((r==null?void 0:r.radius)??1.5,(r==null?void 0:r.color)??"#d8d8d8"),yt=r=>{const e=r.tileDimensions,t=(e==null?void 0:e.width)??25,s=(e==null?void 0:e.height)??25,i=mt(r.renderer??{});return{tileWidth:t,tileHeight:s,renderer:i,maxViewportScale:r.maxViewportScale??10}},Et=(r,e,t)=>{var c,l,g;const s=()=>"direct",i=w=>w,n=w=>w.button===0,h=()=>{},a=()=>{},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)??h,onEdgeCreationInterrupted:((l=r.events)==null?void 0:l.onEdgeCreationInterrupted)??d,onEdgeCreationPrevented:((g=r.events)==null?void 0:g.onEdgeCreationPrevented)??a,dragPortDirection:r.dragPortDirection??t,edgeShapeFactory:r.edgeShape!==void 0?ne(r.edgeShape):e}},At=(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},h=()=>{},a=()=>{},d=()=>{};return{connectionPreprocessor:r.connectionPreprocessor??t,mouseDownEventVerifier:r.mouseDownEventVerifier??s,mouseUpEventVerifier:r.mouseUpEventVerifier??i,draggingEdgeResolver:r.draggingEdgeResolver??n,draggingEdgeShapeFactory:r.draggingEdgeShape!==void 0?ne(r.draggingEdgeShape):null,onAfterEdgeReattached:((c=r.events)==null?void 0:c.onAfterEdgeReattached)??h,onEdgeReattachInterrupted:((l=r.events)==null?void 0:l.onEdgeReattachInterrupted)??d,onEdgeReattachPrevented:((g=r.events)==null?void 0:g.onEdgeReattachPrevented)??a}},xt=r=>({nodeVerticalRadius:r.nodeContainingRadius.vertical,nodeHorizontalRadius:r.nodeContainingRadius.horizontal}),St=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 Pt{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,"hasResizeReactiveNodes",!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.hasResizeReactiveNodes=!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 S("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 de,s=new He,i=new dt(this.element);let n=new he(t,s,i.main);e!==void 0&&(n=new Oe(n,t,e,St(this.virtualScrollConfig)));const h=lt(this.canvasDefaults),a=new ae(this.element,t,s,n,h);if(this.hasBackground&&te.configure(a,yt(this.backgroundConfig),i.background),this.hasResizeReactiveNodes&&j.configure(a),this.hasDraggableNode&&q.configure(a,i.main,this.window,ut(this.dragConfig)),this.hasUserConnectablePorts){const c=Et(this.connectablePortsConfig,h.edges.shapeFactory,h.ports.direction);re.configure(a,i.overlayConnectablePorts,s,this.window,c)}if(this.hasUserDraggableEdges){const c=At(this.draggableEdgesConfig,a.graph);oe.configure(a,i.overlayDraggableEdges,s,this.window,c)}this.virtualScrollConfig!==void 0?ee.configure(a,i.main,this.window,Ve(this.transformConfig),e,xt(this.virtualScrollConfig)):this.hasTransformableViewport&&z.configure(a,i.main,this.window,Ve(this.transformConfig)),this.reset();const d=()=>{i.destroy(),a.onBeforeDestroy.unsubscribe(d)};return a.onBeforeDestroy.subscribe(d),a}reset(){this.element=null,this.canvasDefaults={},this.dragConfig={},this.transformConfig={},this.backgroundConfig={},this.virtualScrollConfig=void 0,this.hasDraggableNode=!1,this.hasTransformableViewport=!1,this.hasResizeReactiveNodes=!1,this.hasBackground=!1,this.boxRenderingTrigger=void 0,this.hasUserConnectablePorts=!1}}y.BezierEdgeShape=Ae,y.CanvasBuilder=Pt,y.DirectEdgeShape=Q,y.EventSubject=H,y.HorizontalEdgeShape=xe,y.HtmlGraphError=S,y.InteractiveEdgeError=De,y.InteractiveEdgeShape=_,y.LineEdgeShape=B,y.MedianEdgeShape=Ne,y.MidpointEdgeShape=Ne,y.StraightEdgeShape=Se,y.VerticalEdgeShape=Pe,Object.defineProperty(y,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 bt=Object.defineProperty;var Tt=(v,E,T)=>E in v?bt(v,E,{enumerable:!0,configurable:!0,writable:!0,value:T}):v[E]=T;var o=(v,E,T)=>Tt(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 Be=()=>{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},$e=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",Be());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);$e(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,h=t.centerFn(s,i),a=t.x-n*h.x,d=t.y-n*h.y;t.element.style.transform=`translate(${a}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(),h=i.element.getBoundingClientRect(),a=this.host.getBoundingClientRect(),d=this.viewportStore.getViewportMatrix(),c=this.createEdgeRenderPort(t.from,s,n,a,d),l=this.createEdgeRenderPort(t.to,i,h,a,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 h={x:s.left-i.left,y:s.top-i.top},a=E(n,h);return{x:a.x,y:a.y,width:s.width*n.scale,height:s.height*n.scale,direction:t.direction,portId:e,nodeId:t.nodeId}}}class Fe{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),h=this.graphStore.getNode(i),a=Math.min(n.x,h.x),d=Math.max(n.x,h.x),c=Math.min(n.y,h.y),l=Math.max(n.y,h.y);return a<=this.xTo&&d>=this.xFrom&&c<=this.yTo&&l>=this.yFrom}}class Oe{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(h=>{const a=this.renderingBox.hasNode(h),d=this.attachedNodes.has(h);a&&!d?t.add(h):!a&&d&&s.add(h)}),this.graphStore.getAllEdgeIds().forEach(h=>{const a=this.renderingBox.hasEdge(h),d=this.attachedEdges.has(h),c=this.graphStore.getEdge(h),l=this.graphStore.getPort(c.from).nodeId,g=this.graphStore.getPort(c.to).nodeId;a&&(this.renderingBox.hasNode(l)||(t.add(l),s.delete(l)),this.renderingBox.hasNode(g)||(t.add(g),s.delete(g))),a&&!d?i.add(h):!a&&d&&n.add(h)}),n.forEach(h=>{this.handleDetachEdge(h)}),s.forEach(h=>{this.handleDetachNode(h)}),t.forEach(h=>{this.attachedNodes.has(h)||this.handleAttachNode(h)}),i.forEach(h=>{this.handleAttachEdge(h)})});this.htmlView=e,this.graphStore=t,this.trigger=s,this.params=i,this.renderingBox=new Fe(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.attachedNodes.add(e),this.params.onBeforeNodeAttached(e),this.htmlView.attachNode(e)}handleDetachNode(e){this.htmlView.detachNode(e),this.params.onAfterNodeDetached(e),this.attachedNodes.delete(e)}handleAttachEdge(e){this.attachedEdges.add(e),this.htmlView.attachEdge(e)}handleDetachEdge(e){this.htmlView.detachEdge(e),this.attachedEdges.delete(e)}}class z{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 z;return[r,r]};class ke{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 H{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 H(e=>this.graph.getNode(e)!==null));o(this,"portIdGenerator",new H(e=>this.graph.getPort(e)!==null));o(this,"edgeIdGenerator",new H(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 ke(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 He{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 he{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 He);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 ae=r=>({scale:1/r.scale,x:-r.x/r.scale,y:-r.y/r.scale}),de={scale:1,x:0,y:0};class Xe{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=ae(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=ae(this.contentMatrix),this.afterUpdateEmitter.emit()}}class X{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 X(e)}handleNodeResize(e){const t=this.elementToNodeId.get(e);this.canvas.updateNode(t)}}const Ye=(r,e,t)=>{const{x:s,y:i,width:n,height:h}=r.getBoundingClientRect();return e>=s&&e<=s+n&&t>=i&&t<=i+h},je=(r,e,t)=>e>=0&&e<=r.innerWidth&&t>=0&&t<=r.innerHeight,C=(r,e,t,s)=>Ye(e,t,s)&&je(r,t,s),B=(r,e)=>{e!==null?r.style.cursor=e:r.style.removeProperty("cursor")},W=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}]}},Ge=(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=Ge(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}),y=(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)}),p={x:0,y:0};class Ke{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=y({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p),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},h={x:i.x-this.params.targetDirection.x*this.params.curvature,y:i.y-this.params.targetDirection.y*this.params.curvature},a=`M ${s.x} ${s.y} C ${n.x} ${n.y}, ${h.x} ${h.y}, ${i.x} ${i.y}`,d=this.params.hasSourceArrow?"":`M ${p.x} ${p.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}${a}${c}`}}const le=(r,e,t,s)=>({x:e*r.x+(1-e)/2*s.x,y:t*r.y+(1-t)/2*s.y});class Ze{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,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,h=Math.sin(this.params.detourDirection)*this.params.detourDistance,a=n*this.params.flipX,d=h*this.params.flipY,c=y({x:i,y:p.y},this.params.sourceDirection,p),l={x:c.x+a,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+a,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},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+a,y:c.y+d},b={x:g.x+a,y:g.y+d};this.path=[`M ${t.x} ${t.y}`,`L ${c.x} ${c.y}`,`C ${m.x} ${m.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=le(f,e.flipX,e.flipY,e.to)}}const V=(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,h=0;r.forEach((a,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=h),f){const U=r[d+1];i=U.x-a.x,n=U.y-a.y,h=Math.sqrt(i*i+n*n)}const S=h!==0?Math.min((m?e:0)/h,d<s-1?.5:1):0,b=m?{x:a.x+i*S,y:a.y+n*S}:a,M=g!==0?Math.min((m?e:0)/g,d>1?.5:1):0,L=m?{x:a.x+c*M,y:a.y+l*M}:a;d>0&&t.push(`L ${L.x} ${L.y}`),m&&t.push(`C ${a.x} ${a.y} ${a.x} ${a.y} ${b.x} ${b.y}`)})}return t.join(" ")};class Je{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?y({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,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,h=n-this.params.roundness,a=y({x:h,y:p.y},this.params.sourceDirection,p),d=y({x:this.params.to.x-h,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((a.x+d.x)/2,n),l=this.params.to.y/2,g={x:this.params.flipX>0?c:-n,y:a.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=V([s,a,g,w,m,f,d,i],this.params.roundness)}}class Y{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,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:p.y},this.params.sourceDirection,p),h=Math.cos(this.params.detourDirection)*this.params.detourDistance,a=Math.sin(this.params.detourDirection)*this.params.detourDistance,d=h*this.params.flipX,c=a*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=le(f,e.flipX,e.flipY,e.to),this.path=V([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?y({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,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,h=y({x:n,y:p.y},this.params.sourceDirection,p),a=y({x:this.params.to.x-n,y:this.params.to.y},this.params.targetDirection,this.params.to);this.path=V([s,h,a,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?y({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,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,h=n-this.params.roundness,a=y({x:h,y:p.y},this.params.sourceDirection,p),d=y({x:this.params.to.x-h,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((a.y+d.y)/2,n),l=this.params.to.x/2,g={x:a.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=V([s,a,g,w,m,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,a=[{x:this.params.arrowLength,y:p.y},{x:i,y:p.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:p.y},{x:this.params.arrowLength,y:p.y}].map(c=>y(c,this.params.sourceDirection,p)),d=`M ${p.x} ${p.y} L ${a[0].x} ${a[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":d}${V(a,this.params.roundness)}`,this.midpoint={x:(a[3].x+a[4].x)/2,y:(a[3].y+a[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,h=Math.sqrt(i*i-t*t),a=h*t/i,d=h+s+this.params.arrowLength,c=this.params.arrowLength+a,g=[{x:this.params.arrowLength,y:p.y},{x:c,y:n},{x:c,y:-n},{x:d,y:0}].map(m=>y(m,this.params.sourceDirection,p)),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:p}),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}}}const ue=(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"}),pe=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},$=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("fill",`var(${G.edgeColor})`),r},we=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.transformOrigin="50% 50%",r},fe=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},me=(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),h=Math.abs(s.x-t.x),a=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:h,height:a,flipX:d,flipY:c}},K=(r,e,t,s)=>{const n=[p,{x:t,y:s},{x:t,y:-s}].map(c=>y(c,r,p)).map(c=>({x:c.x+e.x,y:c.y+e.y})),h=`M ${n[0].x} ${n[0].y}`,a=`L ${n[1].x} ${n[1].y}`,d=`L ${n[2].x} ${n[2].y}`;return`${h} ${a} ${d} Z`},u=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}),ye=(r,e,t)=>({x:e*Math.cos(r),y:t*Math.sin(r)});class I{constructor(e){o(this,"svg");o(this,"group",we());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=pe(e.color),this.svg.appendChild(this.group),this.line=fe(e.width),this.group.appendChild(this.line),e.hasSourceArrow&&(this.sourceArrow=$(),this.group.appendChild(this.sourceArrow)),e.hasTargetArrow&&(this.targetArrow=$(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:i,height:n,flipX:h,flipY:a}=me(e.from,e.to);ue(this.svg,{x:t,y:s,width:i,height:n}),this.group.style.transform=`scale(${h}, ${a})`;const d=ye(e.from.direction,h,a),c=ye(e.to.direction,h,a),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 m=f(d,c,l,h,a);this.line.setAttribute("d",m.path);let x=null;this.sourceArrow&&(x=K(d,p,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:m,sourceArrowPath:x,targetArrowPath:S})}}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,"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 Ze({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 Ke({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)??u.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??u.arrowWidth,this.curvature=(e==null?void 0:e.curvature)??u.curvature,this.portCycleRadius=(e==null?void 0:e.cycleRadius)??u.cycleRadius,this.portCycleSmallRadius=(e==null?void 0:e.smallCycleRadius)??u.smallCycleRadius,this.detourDirection=(e==null?void 0:e.detourDirection)??u.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??u.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??u.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??u.hasTargetArrow,this.pathShape=new I({color:(e==null?void 0:e.color)??u.color,width:(e==null?void 0:e.width)??u.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 Y({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,i)=>new Je({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)??u.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??u.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??u.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??u.cycleSquareSide;const t=(e==null?void 0:e.roundness)??u.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??u.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??u.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??u.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??u.hasTargetArrow,this.pathShape=new I({color:(e==null?void 0:e.color)??u.color,width:(e==null?void 0:e.width)??u.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,"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 Y({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)??u.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??u.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??u.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??u.cycleSquareSide;const t=(e==null?void 0:e.roundness)??u.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??u.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??u.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??u.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??u.hasTargetArrow,this.pathShape=new I({color:(e==null?void 0:e.color)??u.color,width:(e==null?void 0:e.width)??u.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 xe{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 Y({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,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)??u.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??u.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??u.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??u.cycleSquareSide;const t=(e==null?void 0:e.roundness)??u.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??u.detourDirectionVertical,this.detourDistance=(e==null?void 0:e.detourDistance)??u.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??u.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??u.hasTargetArrow,this.pathShape=new I({color:(e==null?void 0:e.color)??u.color,width:(e==null?void 0:e.width)??u.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 Se=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",we());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)??u.color,this.width=(e==null?void 0:e.width)??u.width,this.arrowLength=(e==null?void 0:e.arrowLength)??u.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??u.arrowWidth,this.sourceOffset=(e==null?void 0:e.sourceOffset)??u.preOffset,this.targetOffset=(e==null?void 0:e.targetOffset)??u.preOffset,this.svg=pe(this.color),this.svg.appendChild(this.group),this.line=fe(this.width),this.group.appendChild(this.line),e!=null&&e.hasSourceArrow&&(this.sourceArrow=$(),this.group.appendChild(this.sourceArrow)),e!=null&&e.hasTargetArrow&&(this.targetArrow=$(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:i,height:n,flipX:h,flipY:a}=me(e.from,e.to);ue(this.svg,{x:t,y:s,width:i,height:n}),this.group.style.transform=`scale(${h}, ${a})`;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=Se({diagonalDistance:c.diagonalDistance,to:d,offset:this.sourceOffset,flip:1,shift:p,arrowWidth:this.arrowWidth,arrowLength:this.arrowLength}),this.sourceArrow.setAttribute("d",l));let g=null;this.targetArrow&&(g=Se({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 tt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.pointerEvents="auto",r.style.cursor="pointer",r},rt=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},Pe=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 be 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",tt());o(this,"onAfterRender");o(this,"interactiveLine");o(this,"interactiveSourceArrow",null);o(this,"interactiveTargetArrow",null);if(this.baseEdge=e,e instanceof J)throw new be("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)??u.interactiveWidth;this.interactiveLine=rt(s),this.handle.appendChild(this.interactiveLine),this.sourceArrow&&(this.interactiveSourceArrow=Pe(s),this.handle.appendChild(this.interactiveSourceArrow)),this.targetArrow&&(this.interactiveTargetArrow=Pe(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 Te{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 De=(r,e)=>{const t=new he,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 F{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(!C(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(!C(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 F(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.onBeforeNodeDrag({nodeId:s,element:i.element,x:i.x,y:i.y}))return;e.stopPropagation();const h=this.calculateContentPoint({x:e.clientX,y:e.clientY});this.grabbedNode={nodeId:s,dx:h.x-i.x,dy:h.y-i.y},B(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.onBeforeNodeDrag({nodeId:i,element:n.element,x:n.x,y:n.y}))return;const a=this.calculateContentPoint({x:t.clientX,y:t.clientY});this.grabbedNode={nodeId:i,dx:a.x-n.x,dy:a.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(!C(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(!C(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},h=this.adjustNodeCoords(n);this.canvas.updateNode(e.nodeId,{x:h.x,y:h.y}),this.params.onNodeDrag({nodeId:e.nodeId,element:s.element,x:h.x,y:h.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,B(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 ot=(r,e,t)=>({scale:r.scale,x:r.x+r.scale*e,y:r.y+r.scale*t}),st=(r,e,t,s)=>({scale:r.scale*e,x:r.scale*(1-e)*t+r.x,y:r.scale*(1-e)*s+r.y}),O=r=>{const e=[],t=r.touches.length;for(let a=0;a<t;a++)e.push([r.touches[a].clientX,r.touches[a].clientY]);const s=e.reduce((a,d)=>[a[0]+d[0],a[1]+d[1]],[0,0]),i=[s[0]/t,s[1]/t],h=e.map(a=>[a[0]-i[0],a[1]-i[1]]).reduce((a,d)=>a+Math.sqrt(d[0]*d[0]+d[1]*d[1]),0);return{x:i[0],y:i[1],scale:h/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)||(B(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=C(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,a=1/(e.deltaY<0?this.params.wheelSensitivity:1/this.params.wheelSensitivity);this.wheelFinishTimer===null&&this.params.onTransformStarted(),this.scaleViewport(a,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=O(e);return}this.prevTouches=O(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=O(e);if(!t.touches.every(i=>C(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(),h=this.prevTouches.x-i,a=this.prevTouches.y-n,c=1/(t.scale/this.prevTouches.scale);this.scaleViewport(c,h,a)}this.prevTouches=t});o(this,"onWindowTouchFinish",e=>{e.touches.length>0?this.prevTouches=O(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=ot(s,e,t),{width:n,height:h}=this.element.getBoundingClientRect(),a=this.params.transformPreprocessor({prevTransform:s,nextTransform:i,canvasWidth:n,canvasHeight:h});this.performTransform(a)}scaleViewport(e,t,s){const i=this.canvas.viewport.getViewportMatrix(),n=st(i,e,t,s),{width:h,height:a}=this.element.getBoundingClientRect(),d=this.params.transformPreprocessor({prevTransform:i,nextTransform:n,canvasWidth:h,canvasHeight:a});this.performTransform(d)}stopMouseDrag(){B(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,h){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=h,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 a={...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,a),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,h){new _(e,t,s,i,n,h)}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,h=this.viewportMatrix.y+t+this.nodeVertical;this.loadedArea.xFrom<s&&this.loadedArea.xTo>n&&this.loadedArea.yFrom<i&&this.loadedArea.yTo>h||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,h=3*t+2*this.nodeVertical;this.trigger.emit({x:s,y:i,width:n,height:h})}}const it=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.style.position="absolute",r.style.inset="0",r},nt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","rect");return r.setAttribute("fill","url(#pattern)"),r},ht=()=>{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",it());o(this,"patternRenderingRectangle",nt());o(this,"pattern",ht());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,h=this.tileHeight/i;this.pattern.setAttribute("width",`${n}`),this.pattern.setAttribute("height",`${h}`)}));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=De(this.overlayLayer,this.viewportStore),F.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(h,a)=>{const d=this.params.connectionTypeResolver(h);return d===null?!1:(this.grabPort(h,a,d),!0)},onPointerMove:h=>{this.moveDraggingPort(h)},onPointerUp:h=>{this.tryCreateConnection(h)}})}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(),h=n.x+n.width/2,a=n.y+n.height/2,d=this.overlayLayer.getBoundingClientRect(),c=this.canvas.viewport.getViewportMatrix(),l=E(c,{x:h-d.x,y:a-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[m,x]=this.isTargetDragging?[w,f]:[f,w];this.overlayCanvas.addNode(W(m)),this.overlayCanvas.addNode(W(x)),this.overlayCanvas.addEdge({from:m.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},h=this.params.connectionPreprocessor(n);h!==null?(this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated),this.canvas.addEdge(h),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=De(this.overlayLayer,this.viewportStore),F.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(h,a)=>this.tryStartEdgeDragging(h,a),onPointerMove:h=>{this.moveDraggingPort(h)},onPointerUp:h=>{this.tryCreateConnection(h)}})}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,h=e===i.to,a=n?i.to:i.from;this.staticPortId=a,this.isTargetDragging=h;const d=this.canvas.graph.getPort(e),c=this.canvas.graph.getPort(a),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}),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:m,portDirection:c.direction},b={overlayId:D.Dragging,portCoords:x,portDirection:d.direction},[N,M]=this.isTargetDragging?[S,b]:[b,S];this.overlayCanvas.addNode(W(N)),this.overlayCanvas.addNode(W(M));const L=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:L}),!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,h={id:n.id,from:s,to:i,shape:n.shape,priority:n.priority},a=this.params.connectionPreprocessor(h);if(a!==null)this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeReattached),this.canvas.addEdge(a),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 at=()=>{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},Ne=()=>{const r=re();return r.style.pointerEvents="none",r};class dt{constructor(e){o(this,"background",re());o(this,"main",re());o(this,"overlayConnectablePorts",Ne());o(this,"overlayDraggableEdges",Ne());o(this,"host",at());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,Me=oe(0),ct=()=>{let r=0;return()=>r++},gt=(r,e)=>{let t=Me,s=Me;const i=ct();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 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"horizontal":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"vertical":return()=>new xe({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 ve({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})}},lt=r=>{var t,s,i,n,h;const e=gt((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(((h=r.edges)==null?void 0:h.shape)??{}),priorityFn:e.edgesPriorityFn}}},ut=r=>{var w,f,m,x,S,b;const e=((w=r.events)==null?void 0:w.onNodeDrag)??(()=>{}),t=((f=r.events)==null?void 0:f.onBeforeNodeDrag)??(()=>!0),s=((m=r.events)==null?void 0:m.onNodeDragFinished)??(()=>{}),i=r.moveOnTop!==!1,n=r.moveEdgesOnTop!==!1&&i,h=(x=r.mouse)==null?void 0:x.dragCursor,a=h!==void 0?h:"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:a,gridSize:r.gridSize??null,mouseDownEventVerifier:c,mouseUpEventVerifier:g,onNodeDrag:e,onBeforeNodeDrag:t,onNodeDragFinished:s}},pt=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 h=n.nextTransform.x,a=n.nextTransform.y;h<e&&h<n.prevTransform.x&&(h=Math.min(n.prevTransform.x,e));const d=n.canvasWidth*n.prevTransform.scale,c=t-d;h>c&&h>n.prevTransform.x&&(h=Math.max(n.prevTransform.x,c)),a<s&&a<n.prevTransform.y&&(a=Math.min(n.prevTransform.y,s));const l=n.canvasHeight*n.prevTransform.scale,g=i-l;return a>g&&a>n.prevTransform.y&&(a=Math.max(n.prevTransform.y,g)),{scale:n.nextTransform.scale,x:h,y:a}}},wt=r=>{const e=r.maxContentScale,t=r.minContentScale,s=e!==null?1/e:0,i=t!==null?1/t:1/0;return n=>{const h=n.prevTransform,a=n.nextTransform;let d=a.scale,c=a.x,l=a.y;if(a.scale>i&&a.scale>h.scale){d=Math.max(h.scale,i),c=h.x,l=h.y;const g=(d-h.scale)/(a.scale-h.scale);c=h.x+(a.x-h.x)*g,l=h.y+(a.y-h.y)*g}if(a.scale<s&&a.scale<h.scale){d=Math.min(h.scale,s),c=h.x,l=h.y;const g=(d-h.scale)/(a.scale-h.scale);c=h.x+(a.x-h.x)*g,l=h.y+(a.y-h.y)*g}return{scale:d,x:c,y:l}}},ft=r=>e=>r.reduce((t,s)=>s({prevTransform:e.prevTransform,nextTransform:t,canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight}),e.nextTransform),Le=r=>{if(typeof r=="function")return r;switch(r.type){case"scale-limit":return wt({minContentScale:r.minContentScale??0,maxContentScale:r.maxContentScale??1/0});case"shift-limit":return pt({minX:r.minX??-1/0,maxX:r.maxX??1/0,minY:r.minY??-1/0,maxY:r.maxY??1/0})}},Re=r=>{var m,x,S,b,N,M,L,U,Ce,Ve,Ie,Ue;const e=(m=r==null?void 0:r.scale)==null?void 0:m.mouseWheelSensitivity,t=e!==void 0?e:1.2,s=r==null?void 0:r.transformPreprocessor;let i;s!==void 0?Array.isArray(s)?i=ft(s.map(R=>Le(R))):i=Le(s):i=R=>R.nextTransform;const n=((x=r==null?void 0:r.shift)==null?void 0:x.cursor)!==void 0?r.shift.cursor:"grab",h=((S=r==null?void 0:r.events)==null?void 0:S.onBeforeTransformChange)??(()=>{}),a=((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:R=>R.button===0,l=(M=r==null?void 0:r.shift)==null?void 0:M.mouseUpEventVerifier,g=l!==void 0?l:R=>R.button===0,w=(L=r==null?void 0:r.scale)==null?void 0:L.mouseWheelEventVerifier,f=w!==void 0?w:()=>!0;return{wheelSensitivity:t,onTransformStarted:((U=r==null?void 0:r.events)==null?void 0:U.onTransformStarted)??(()=>{}),onTransformFinished:((Ce=r==null?void 0:r.events)==null?void 0:Ce.onTransformFinished)??(()=>{}),onBeforeTransformChange:h,onTransformChange:a,transformPreprocessor:i,shiftCursor:n,mouseDownEventVerifier:c,mouseUpEventVerifier:g,mouseWheelEventVerifier:f,scaleWheelFinishTimeout:((Ve=r==null?void 0:r.scale)==null?void 0:Ve.wheelFinishTimeout)??500,onResizeTransformStarted:((Ie=r==null?void 0:r.events)==null?void 0:Ie.onResizeTransformStarted)??(()=>{}),onResizeTransformFinished:((Ue=r==null?void 0:r.events)==null?void 0:Ue.onResizeTransformFinished)??(()=>{})}},mt=(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},yt=r=>r instanceof SVGElement?r:mt((r==null?void 0:r.radius)??1.5,(r==null?void 0:r.color)??"#d8d8d8"),vt=r=>{const e=r.tileDimensions,t=(e==null?void 0:e.width)??25,s=(e==null?void 0:e.height)??25,i=yt(r.renderer??{});return{tileWidth:t,tileHeight:s,renderer:i,maxViewportScale:r.maxViewportScale??10}},Et=(r,e,t)=>{var c,l,g;const s=()=>"direct",i=w=>w,n=w=>w.button===0,h=()=>{},a=()=>{},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)??h,onEdgeCreationInterrupted:((l=r.events)==null?void 0:l.onEdgeCreationInterrupted)??d,onEdgeCreationPrevented:((g=r.events)==null?void 0:g.onEdgeCreationPrevented)??a,dragPortDirection:r.dragPortDirection??t,edgeShapeFactory:r.edgeShape!==void 0?se(r.edgeShape):e}},At=(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},h=()=>{},a=()=>{},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)??h,onEdgeReattachInterrupted:((l=r.events)==null?void 0:l.onEdgeReattachInterrupted)??d,onEdgeReattachPrevented:((g=r.events)==null?void 0:g.onEdgeReattachPrevented)??a}},xt=r=>({nodeVerticalRadius:r.nodeContainingRadius.vertical,nodeHorizontalRadius:r.nodeContainingRadius.horizontal}),St=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 Pt{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 z);const t=new he,s=new Xe,i=new dt(this.element);let n=new ie(t,s,i.main);e!==void 0&&(n=new Oe(n,t,e,St(this.virtualScrollConfig)));const h=lt(this.canvasDefaults),a=new ne(this.element,t,s,n,h);if(this.hasBackground&&q.configure(a,vt(this.backgroundConfig),i.background),this.hasNodeResizeReactiveEdges&&X.configure(a),this.hasDraggableNode&&Q.configure(a,i.main,this.window,ut(this.dragConfig)),this.hasUserConnectablePorts){const c=Et(this.connectablePortsConfig,h.edges.shapeFactory,h.ports.direction);ee.configure(a,i.overlayConnectablePorts,s,this.window,c)}if(this.hasUserDraggableEdges){const c=At(this.draggableEdgesConfig,a.graph);te.configure(a,i.overlayDraggableEdges,s,this.window,c)}this.virtualScrollConfig!==void 0?_.configure(a,i.main,this.window,Re(this.transformConfig),e,xt(this.virtualScrollConfig)):this.hasTransformableViewport&&k.configure(a,i.main,this.window,Re(this.transformConfig)),this.reset();const d=()=>{i.destroy(),a.onBeforeDestroy.unsubscribe(d)};return a.onBeforeDestroy.subscribe(d),a}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=ve,v.CanvasBuilder=Pt,v.DirectEdgeShape=Z,v.EventSubject=z,v.HorizontalEdgeShape=Ee,v.HtmlGraphError=P,v.InteractiveEdgeError=be,v.InteractiveEdgeShape=J,v.LineEdgeShape=I,v.MedianEdgeShape=Te,v.MidpointEdgeShape=Te,v.StraightEdgeShape=Ae,v.VerticalEdgeShape=xe,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.17.0",
5
+ "version": "3.19.0",
6
6
  "type": "module",
7
7
  "main": "dist/html-graph.js",
8
8
  "types": "dist/html-graph.d.ts",