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