@html-graph/html-graph 0.1.3 → 0.1.5
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 +20 -22
- package/dist/main.d.ts +12 -10
- package/dist/main.js +297 -287
- package/dist/main.umd.cjs +1 -1
- package/package.json +5 -2
package/dist/main.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(x,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(x=typeof globalThis<"u"?globalThis:x||self,E(x.HTMLGraph={}))})(this,function(x){"use strict";var It=Object.defineProperty;var mt=(x,E,y)=>E in x?It(x,E,{enumerable:!0,configurable:!0,writable:!0,value:y}):x[E]=y;var n=(x,E,y)=>mt(x,typeof E!="symbol"?E+"":E,y);const E=(e,t)=>({x:e/2,y:t/2}),y=(e,t,o)=>({x:t.x*e.x-t.y*e.y+((1-t.x)*o.x+t.y*o.y),y:t.y*e.x+t.x*e.y+((1-t.x)*o.y-t.y*o.x)}),T=(e,t,o)=>({x:t*Math.cos(e),y:o*Math.sin(e)}),u={x:0,y:0},M=(e,t,o,r)=>{const s=[u,{x:o,y:r},{x:o,y:-r}].map(l=>y(l,e,u)).map(l=>({x:l.x+t.x,y:l.y+t.y})),h=`M ${s[0].x} ${s[0].y}`,d=`L ${s[1].x} ${s[1].y}`,c=`L ${s[2].x} ${s[2].y}`;return`${h} ${d} ${c}`},N=(e,t)=>{const o=[];if(e.length>0&&o.push(`M ${e[0].x} ${e[0].y}`),e.length===2&&o.push(`L ${e[1].x} ${e[1].y}`),e.length>2){const r=e.length-1;let i=0,s=0,h=0;e.forEach((d,c)=>{let l=0,a=0,g=0;const f=c>0,S=c<r,v=f&&S;if(f&&(l=-i,a=-s,g=h),S){const ot=e[c+1];i=ot.x-d.x,s=ot.y-d.y,h=Math.sqrt(i*i+s*s)}const L=h!==0?Math.min((v?t:0)/h,c<r-1?.5:1):0,q=v?{x:d.x+i*L,y:d.y+s*L}:d,tt=g!==0?Math.min((v?t:0)/g,c>1?.5:1):0,et=v?{x:d.x+l*tt,y:d.y+a*tt}:d;c>0&&o.push(`L ${et.x} ${et.y}`),v&&o.push(`C ${d.x} ${d.y} ${d.x} ${d.y} ${q.x} ${q.y}`)})}return o.join(" ")},D=()=>{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.style.pointerEvents="none",e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.overflow="visible",e},I=()=>{const e=document.createElementNS("http://www.w3.org/2000/svg","g");return e.style.transformOrigin="50% 50%",e},m=(e,t)=>{const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("stroke",e),o.setAttribute("stroke-width",`${t}`),o.setAttribute("fill","none"),o},C=e=>{const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("fill",e),t},$=(e,t)=>{const o={x:e.x+e.width/2,y:e.y+e.height/2},r={x:t.x+t.width/2,y:t.y+t.height/2},i=Math.min(o.x,r.x),s=Math.min(o.y,r.y),h=Math.abs(r.x-o.x),d=Math.abs(r.y-o.y),c=o.x<=r.x?1:-1,l=o.y<=r.y?1:-1;return{x:i,y:s,width:h,height:d,flipX:c,flipY:l}},rt=e=>{const t=y({x:e.arrowLength,y:u.y},e.fromVect,u),o=y({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to),r={x:t.x+e.fromVect.x*e.curvature,y:t.y+e.fromVect.y*e.curvature},i={x:o.x-e.toVect.x*e.curvature,y:o.y-e.toVect.y*e.curvature},s=`M ${t.x} ${t.y} C ${r.x} ${r.y}, ${i.x} ${i.y}, ${o.x} ${o.y}`,h=e.hasSourceArrow?"":`M ${u.x} ${u.y} L ${t.x} ${t.y} `,d=e.hasTargetArrow?"":` M ${o.x} ${o.y} L ${e.to.x} ${e.to.y}`;return`${h}${s}${d}`},it=e=>{const t=e.hasSourceArrow?y({x:e.arrowLength,y:u.y},e.fromVect,u):u,o=e.hasTargetArrow?y({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to):e.to,r=e.arrowLength,i=Math.cos(e.detourDirection)*e.detourDistance,s=Math.sin(e.detourDirection)*e.detourDistance,h=i*e.flipX,d=s*e.flipY,c=y({x:r,y:u.y},e.fromVect,u),l={x:c.x+h,y:c.y+d},a=y({x:e.to.x-r,y:e.to.y},e.toVect,e.to),g={x:a.x+h,y:a.y+d},f={x:(l.x+g.x)/2,y:(l.y+g.y)/2},S={x:c.x+e.curvature*e.fromVect.x,y:c.y+e.curvature*e.fromVect.y},v={x:a.x-e.curvature*e.toVect.x,y:a.y-e.curvature*e.toVect.y},k={x:c.x+h,y:c.y+d},L={x:a.x+h,y:a.y+d};return[`M ${t.x} ${t.y}`,`L ${c.x} ${c.y}`,`C ${S.x} ${S.y} ${k.x} ${k.y} ${f.x} ${f.y}`,`C ${L.x} ${L.y} ${v.x} ${v.y} ${a.x} ${a.y}`,`L ${o.x} ${o.y}`].join(" ")},nt=e=>{const t=e.hasSourceArrow?y({x:e.arrowLength,y:u.y},e.fromVect,u):u,o=e.hasTargetArrow?y({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to):e.to,r=e.arrowLength+e.arrowOffset,i=r-e.roundness,s=y({x:i,y:u.y},e.fromVect,u),h=y({x:e.to.x-i,y:e.to.y},e.toVect,e.to),d=Math.max((s.x+h.x)/2,r),c=e.to.y/2,l={x:e.flipX>0?d:-r,y:s.y},a={x:l.x,y:c},g={x:e.flipX>0?e.to.x-d:e.to.x+r,y:h.y},f={x:g.x,y:c};return N([t,s,l,a,f,g,h,o],e.roundness)},W=e=>{const t=e.hasSourceArrow?y({x:e.arrowLength,y:u.y},e.fromVect,u):u,o=e.hasTargetArrow?y({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to):e.to,r=e.arrowLength+e.arrowOffset,i=y({x:r,y:u.y},e.fromVect,u),s=Math.cos(e.detourDirection)*e.detourDistance,h=Math.sin(e.detourDirection)*e.detourDistance,d=s*e.flipX,c=h*e.flipY,l={x:i.x+d,y:i.y+c},a=y({x:e.to.x-r,y:e.to.y},e.toVect,e.to),g={x:a.x+d,y:a.y+c};return N([t,i,l,g,a,o],e.roundness)},st=e=>{const t=e.hasSourceArrow?y({x:e.arrowLength,y:u.y},e.fromVect,u):u,o=e.hasTargetArrow?y({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to):e.to,r=e.arrowLength+e.arrowOffset,i=y({x:r,y:u.y},e.fromVect,u),s=y({x:e.to.x-r,y:e.to.y},e.toVect,e.to);return N([t,i,s,o],e.roundness)},ht=e=>{const t=e.hasSourceArrow?y({x:e.arrowLength,y:u.y},e.fromVect,u):u,o=e.hasTargetArrow?y({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to):e.to,r=e.arrowLength+e.arrowOffset,i=r-e.roundness,s=y({x:i,y:u.y},e.fromVect,u),h=y({x:e.to.x-i,y:e.to.y},e.toVect,e.to),d=Math.max((s.y+h.y)/2,r),c=e.to.x/2,l={x:s.x,y:e.flipY>0?d:-r},a={x:c,y:l.y},g={x:h.x,y:e.flipY>0?e.to.y-d:e.to.y+r},f={x:c,y:g.y};return N([t,s,l,a,f,g,h,o],e.roundness)},F=e=>{const t=e.arrowOffset,o=e.side,r=e.arrowLength+t,i=r+2*o,h=[{x:e.arrowLength,y:u.y},{x:r,y:u.y},{x:r,y:e.side},{x:i,y:e.side},{x:i,y:-e.side},{x:r,y:-e.side},{x:r,y:u.y},{x:e.arrowLength,y:u.y}].map(c=>y(c,e.fromVect,u)),d=`M ${u.x} ${u.y} L ${h[0].x} ${h[0].y} `;return`${e.hasSourceArrow||e.hasTargetArrow?"":d}${N(h,e.roundness)}`},dt=e=>{const t=e.smallRadius,o=e.radius,r=Math.sqrt(t*t+o*o),i=t+o,s=e.arrowLength+r*(1-o/i),h=t*o/i,c=[{x:e.arrowLength,y:u.y},{x:s,y:h},{x:s,y:-h}].map(g=>y(g,e.fromVect,u)),l=[`M ${c[0].x} ${c[0].y}`,`A ${t} ${t} 0 0 1 ${c[1].x} ${c[1].y}`,`A ${o} ${o} 0 1 0 ${c[2].x} ${c[2].y}`,`A ${t} ${t} 0 0 1 ${c[0].x} ${c[0].y}`].join(" "),a=`M 0 0 L ${c[0].x} ${c[0].y} `;return`${e.hasSourceArrow||e.hasTargetArrow?"":a}${l}`},w=Object.freeze({color:"#5c5c5c",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});class B{constructor(t){n(this,"svg",D());n(this,"group",I());n(this,"line");n(this,"sourceArrow",null);n(this,"targetArrow",null);n(this,"arrowLength");n(this,"arrowWidth");n(this,"curvature");n(this,"portCycleRadius");n(this,"portCycleSmallRadius");n(this,"detourDirection");n(this,"detourDistance");n(this,"hasSourceArrow");n(this,"hasTargetArrow");this.arrowLength=(t==null?void 0:t.arrowLength)??w.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??w.arrowWidth,this.curvature=(t==null?void 0:t.curvature)??w.curvature,this.portCycleRadius=(t==null?void 0:t.cycleRadius)??w.cycleRadius,this.portCycleSmallRadius=(t==null?void 0:t.smallCycleRadius)??w.smallCycleRadius,this.detourDirection=(t==null?void 0:t.detourDirection)??w.detourDirection,this.detourDistance=(t==null?void 0:t.detourDistance)??w.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??w.hasTargetArrow;const o=(t==null?void 0:t.color)??w.color,r=(t==null?void 0:t.width)??w.width;this.svg.appendChild(this.group),this.line=m(o,r),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=C(o),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=C(o),this.group.appendChild(this.targetArrow))}render(t){const{x:o,y:r,width:i,height:s,flipX:h,flipY:d}=$(t.source,t.target);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${i}px`,this.svg.style.height=`${s}px`,this.group.style.transform=`scale(${h}, ${d})`;const c=T(t.source.direction,h,d),l=T(t.target.direction,h,d),a={x:i,y:s};let g,f=l,S=-this.arrowLength;if(t.source.portId===t.target.portId?(g=dt({fromVect:c,radius:this.portCycleRadius,smallRadius:this.portCycleSmallRadius,arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,S=this.arrowLength):t.source.nodeId===t.target.nodeId?g=it({to:a,fromVect:c,toVect:l,flipX:h,flipY:d,arrowLength:this.arrowLength,detourDirection:this.detourDirection,detourDistance:this.detourDistance,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=rt({to:a,fromVect:c,toVect:l,arrowLength:this.arrowLength,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=M(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=M(f,a,S,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}class z{constructor(t){n(this,"svg",D());n(this,"group",I());n(this,"line");n(this,"sourceArrow",null);n(this,"targetArrow",null);n(this,"arrowLength");n(this,"arrowWidth");n(this,"arrowOffset");n(this,"roundness");n(this,"cycleSquareSide");n(this,"detourDirection");n(this,"detourDistance");n(this,"hasSourceArrow");n(this,"hasTargetArrow");this.arrowLength=(t==null?void 0:t.arrowLength)??w.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??w.arrowWidth,this.arrowOffset=(t==null?void 0:t.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(t==null?void 0:t.cycleSquareSide)??w.cycleSquareSide;const o=(t==null?void 0:t.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(t==null?void 0:t.detourDirection)??w.detourDirection,this.detourDistance=(t==null?void 0:t.detourDistance)??w.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??w.hasTargetArrow;const r=(t==null?void 0:t.color)??w.color,i=(t==null?void 0:t.width)??w.width;this.svg.appendChild(this.group),this.line=m(r,i),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=C(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=C(r),this.group.appendChild(this.targetArrow))}render(t){const{x:o,y:r,width:i,height:s,flipX:h,flipY:d}=$(t.source,t.target);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${i}px`,this.svg.style.height=`${s}px`,this.group.style.transform=`scale(${h}, ${d})`;const c=T(t.source.direction,h,d),l=T(t.target.direction,h,d),a={x:i,y:s};let g,f=l,S=-this.arrowLength;if(t.source.portId===t.target.portId?(g=F({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,S=this.arrowLength):t.source.nodeId===t.target.nodeId?g=W({to:a,fromVect:c,toVect:l,flipX:h,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=nt({to:a,fromVect:c,toVect:l,flipX:h,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=M(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=M(f,a,S,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}class G{constructor(t){n(this,"svg",D());n(this,"group",I());n(this,"line");n(this,"sourceArrow",null);n(this,"targetArrow",null);n(this,"arrowLength");n(this,"arrowWidth");n(this,"arrowOffset");n(this,"roundness");n(this,"cycleSquareSide");n(this,"detourDirection");n(this,"detourDistance");n(this,"hasSourceArrow");n(this,"hasTargetArrow");this.arrowLength=(t==null?void 0:t.arrowLength)??w.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??w.arrowWidth,this.arrowOffset=(t==null?void 0:t.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(t==null?void 0:t.cycleSquareSide)??w.cycleSquareSide;const o=(t==null?void 0:t.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(t==null?void 0:t.detourDirection)??w.detourDirection,this.detourDistance=(t==null?void 0:t.detourDistance)??w.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??w.hasTargetArrow;const r=(t==null?void 0:t.color)??w.color,i=(t==null?void 0:t.width)??w.width;this.svg.appendChild(this.group),this.line=m(r,i),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=C(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=C(r),this.group.appendChild(this.targetArrow))}render(t){const{x:o,y:r,width:i,height:s,flipX:h,flipY:d}=$(t.source,t.target);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${i}px`,this.svg.style.height=`${s}px`,this.group.style.transform=`scale(${h}, ${d})`;const c=T(t.source.direction,h,d),l=T(t.target.direction,h,d),a={x:i,y:s};let g,f=l,S=-this.arrowLength;if(t.source.portId===t.target.portId?(g=F({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,S=this.arrowLength):t.source.nodeId===t.target.nodeId?g=W({to:a,fromVect:c,toVect:l,flipX:h,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=st({to:a,fromVect:c,toVect:l,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=M(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=M(f,a,S,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}class H{constructor(t){n(this,"svg",D());n(this,"group",I());n(this,"line");n(this,"sourceArrow",null);n(this,"targetArrow",null);n(this,"arrowLength");n(this,"arrowWidth");n(this,"arrowOffset");n(this,"roundness");n(this,"cycleSquareSide");n(this,"detourDirection");n(this,"detourDistance");n(this,"hasSourceArrow");n(this,"hasTargetArrow");this.arrowLength=(t==null?void 0:t.arrowLength)??w.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??w.arrowWidth,this.arrowOffset=(t==null?void 0:t.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(t==null?void 0:t.cycleSquareSide)??w.cycleSquareSide;const o=(t==null?void 0:t.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(t==null?void 0:t.detourDirection)??w.detourDirectionVertical,this.detourDistance=(t==null?void 0:t.detourDistance)??w.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??w.hasTargetArrow;const r=(t==null?void 0:t.color)??w.color,i=(t==null?void 0:t.width)??w.width;this.svg.appendChild(this.group),this.line=m(r,i),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=C(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=C(r),this.group.appendChild(this.targetArrow))}render(t){const{x:o,y:r,width:i,height:s,flipX:h,flipY:d}=$(t.source,t.target);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${i}px`,this.svg.style.height=`${s}px`,this.group.style.transform=`scale(${h}, ${d})`;const c=T(t.source.direction,h,d),l=T(t.target.direction,h,d),a={x:i,y:s};let g,f=l,S=-this.arrowLength;if(t.source.portId===t.target.portId?(g=F({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,S=this.arrowLength):t.source.nodeId===t.target.nodeId?g=W({to:a,fromVect:c,toVect:l,flipX:h,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=ht({to:a,fromVect:c,toVect:l,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=M(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=M(f,a,S,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}const ct=e=>{if(typeof e=="function")return e;switch(e==null?void 0:e.type){case"straight":return()=>new G({color:e.color,width:e.width,arrowLength:e.arrowLength,arrowWidth:e.arrowWidth,arrowOffset:e.arrowOffset,hasSourceArrow:e.hasSourceArrow,hasTargetArrow:e.hasTargetArrow,cycleSquareSide:e.cycleSquareSide,roundness:e.roundness,detourDistance:e.detourDistance,detourDirection:e.detourDirection});case"horizontal":return()=>new z({color:e.color,width:e.width,arrowLength:e.arrowLength,arrowWidth:e.arrowWidth,arrowOffset:e.arrowOffset,hasSourceArrow:e.hasSourceArrow,hasTargetArrow:e.hasTargetArrow,cycleSquareSide:e.cycleSquareSide,roundness:e.roundness,detourDistance:e.detourDistance,detourDirection:e.detourDirection});case"vertical":return()=>new H({color:e.color,width:e.width,arrowLength:e.arrowLength,arrowWidth:e.arrowWidth,arrowOffset:e.arrowOffset,hasSourceArrow:e.hasSourceArrow,hasTargetArrow:e.hasTargetArrow,cycleSquareSide:e.cycleSquareSide,roundness:e.roundness,detourDistance:e.detourDistance,detourDirection:e.detourDirection});default:return()=>new B({color:e.color,width:e.width,arrowLength:e.arrowLength,arrowWidth:e.arrowWidth,hasSourceArrow:e.hasSourceArrow,hasTargetArrow:e.hasTargetArrow,cycleRadius:e.cycleRadius,smallCycleRadius:e.smallCycleRadius,curvature:e.curvature,detourDistance:e.detourDistance,detourDirection:e.detourDirection})}},R=e=>()=>e,j=R(0),Y=()=>{let e=0;return()=>e++},lt=(e,t)=>{let o=j,r=j;e==="incremental"&&(o=Y()),t==="incremental"&&(r=Y());const i=Y();return e==="shared-incremental"&&(o=i),t==="shared-incremental"&&(r=i),typeof e=="number"&&(o=R(e)),typeof t=="number"&&(r=R(t)),typeof e=="function"&&(o=e),typeof t=="function"&&(r=t),{nodesPriorityFn:o,edgesPriorityFn:r}},at=e=>{var o,r,i,s,h;const t=lt((o=e==null?void 0:e.nodes)==null?void 0:o.priority,(r=e==null?void 0:e.edges)==null?void 0:r.priority);return{nodes:{centerFn:((i=e==null?void 0:e.nodes)==null?void 0:i.centerFn)??E,priorityFn:t.nodesPriorityFn},ports:{direction:((s=e==null?void 0:e.ports)==null?void 0:s.direction)??0},edges:{shapeFactory:ct(((h=e==null?void 0:e.edges)==null?void 0:h.shape)??{}),priorityFn:t.edgesPriorityFn}}};class gt{constructor(){n(this,"nodes",new Map);n(this,"ports",new Map);n(this,"nodePorts",new Map);n(this,"portNodeId",new Map);n(this,"edges",new Map);n(this,"incommingEdges",new Map);n(this,"outcommingEdges",new Map);n(this,"cycleEdges",new Map)}addNode(t){this.nodes.set(t.nodeId,{element:t.element,x:t.x,y:t.y,centerFn:t.centerFn,priority:t.priority}),this.nodePorts.set(t.nodeId,new Map)}getAllNodeIds(){return Array.from(this.nodes.keys())}getNode(t){return this.nodes.get(t)}removeNode(t){this.nodes.delete(t),this.nodePorts.delete(t)}addPort(t){this.ports.set(t.portId,{element:t.element,direction:t.direction}),this.cycleEdges.set(t.portId,new Set),this.incommingEdges.set(t.portId,new Set),this.outcommingEdges.set(t.portId,new Set),this.portNodeId.set(t.portId,t.nodeId),this.nodePorts.get(t.nodeId).set(t.portId,t.element)}getPort(t){return this.ports.get(t)}getAllPortIds(){return Array.from(this.ports.keys())}getNodePortIds(t){const o=this.nodePorts.get(t);if(o!==void 0)return Array.from(o.keys())}getPortNodeId(t){return this.portNodeId.get(t)}removePort(t){const o=this.portNodeId.get(t);this.portNodeId.delete(t),this.nodePorts.get(o).delete(t),this.ports.delete(t)}addEdge(t){this.edges.set(t.edgeId,{from:t.from,to:t.to,shape:t.shape,priority:t.priority}),t.from!==t.to?(this.outcommingEdges.get(t.from).add(t.edgeId),this.incommingEdges.get(t.to).add(t.edgeId)):this.cycleEdges.get(t.from).add(t.edgeId)}updateEdgeFrom(t,o){const r=this.edges.get(t);this.removeEdge(t),this.addEdge({edgeId:t,from:o,to:r.to,shape:r.shape,priority:r.priority})}updateEdgeTo(t,o){const r=this.edges.get(t);this.removeEdge(t),this.addEdge({edgeId:t,from:r.from,to:o,shape:r.shape,priority:r.priority})}getAllEdgeIds(){return Array.from(this.edges.keys())}getEdge(t){return this.edges.get(t)}removeEdge(t){const o=this.edges.get(t),r=o.from,i=o.to;this.cycleEdges.get(r).delete(t),this.cycleEdges.get(i).delete(t),this.incommingEdges.get(r).delete(t),this.incommingEdges.get(i).delete(t),this.outcommingEdges.get(r).delete(t),this.outcommingEdges.get(i).delete(t),this.edges.delete(t)}clear(){this.nodes.clear(),this.ports.clear(),this.nodePorts.clear(),this.portNodeId.clear(),this.edges.clear(),this.incommingEdges.clear(),this.outcommingEdges.clear(),this.cycleEdges.clear()}getPortIncomingEdgeIds(t){return Array.from(this.incommingEdges.get(t))}getPortOutcomingEdgeIds(t){return Array.from(this.outcommingEdges.get(t))}getPortCycleEdgeIds(t){return Array.from(this.cycleEdges.get(t))}getPortAdjacentEdgeIds(t){return[...this.getPortIncomingEdgeIds(t),...this.getPortOutcomingEdgeIds(t),...this.getPortCycleEdgeIds(t)]}getNodeIncomingEdgeIds(t){const o=Array.from(this.nodePorts.get(t).keys());let r=[];return o.forEach(i=>{r=[...r,...this.getPortIncomingEdgeIds(i)]}),r}getNodeOutcomingEdgeIds(t){const o=Array.from(this.nodePorts.get(t).keys());let r=[];return o.forEach(i=>{r=[...r,...this.getPortOutcomingEdgeIds(i)]}),r}getNodeCycleEdgeIds(t){const o=Array.from(this.nodePorts.get(t).keys());let r=[];return o.forEach(i=>{r=[...r,...this.getPortCycleEdgeIds(i)]}),r}getNodeAdjacentEdgeIds(t){return[...this.getNodeIncomingEdgeIds(t),...this.getNodeOutcomingEdgeIds(t),...this.getNodeCycleEdgeIds(t)]}}class ut{constructor(t){this.graphStore=t}getNode(t){const o=this.graphStore.getNode(t);return o===void 0?null:{element:o.element,x:o.x,y:o.y,centerFn:o.centerFn,priority:o.priority}}getAllNodeIds(){return this.graphStore.getAllNodeIds()}getPort(t){const o=this.graphStore.getPort(t);return o===void 0?null:{element:o.element,direction:o.direction}}getAllPortIds(){return this.graphStore.getAllPortIds()}getNodePortIds(t){return this.graphStore.getNodePortIds(t)}getPortNodeId(t){return this.graphStore.getPortNodeId(t)??null}getAllEdgeIds(){return this.graphStore.getAllEdgeIds()}getEdge(t){const o=this.graphStore.getEdge(t);return o===void 0?null:{from:o.from,to:o.to,priority:o.priority}}getPortIncomingEdgeIds(t){return this.graphStore.getPortIncomingEdgeIds(t)}getPortOutcomingEdgeIds(t){return this.graphStore.getPortOutcomingEdgeIds(t)}getPortCycleEdgeIds(t){return this.graphStore.getPortCycleEdgeIds(t)}getPortAdjacentEdgeIds(t){return this.graphStore.getPortAdjacentEdgeIds(t)}getNodeIncomingEdgeIds(t){return this.graphStore.getNodeIncomingEdgeIds(t)}getNodeOutcomingEdgeIds(t){return this.graphStore.getNodeOutcomingEdgeIds(t)}getNodeCycleEdgeIds(t){return this.graphStore.getNodeCycleEdgeIds(t)}getNodeAdjacentEdgeIds(t){return this.graphStore.getNodeAdjacentEdgeIds(t)}}const U=e=>({scale:1/e.scale,dx:-e.dx/e.scale,dy:-e.dy/e.scale}),O={scale:1,dx:0,dy:0};class wt{constructor(){n(this,"viewportMatrix",O);n(this,"contentMatrix",O)}getViewportMatrix(){return this.viewportMatrix}getContentMatrix(){return this.contentMatrix}patchViewportMatrix(t){this.viewportMatrix={scale:t.scale??this.viewportMatrix.scale,dx:t.dx??this.viewportMatrix.dx,dy:t.dy??this.viewportMatrix.dy},this.contentMatrix=U(this.viewportMatrix)}patchContentMatrix(t){this.contentMatrix={scale:t.scale??this.contentMatrix.scale,dx:t.dx??this.contentMatrix.dx,dy:t.dy??this.contentMatrix.dy},this.viewportMatrix=U(this.contentMatrix)}}class yt{constructor(t){this.transformer=t}getViewportMatrix(){return{...this.transformer.getViewportMatrix()}}getContentMatrix(){return{...this.transformer.getContentMatrix()}}}const ft=()=>{const e=document.createElement("div");return e.style.width="100%",e.style.height="100%",e.style.position="relative",e.style.overflow="hidden",e},vt=()=>{const e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="0",e.style.height="0",e},xt=()=>{const e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.visibility="hidden",e};class St{constructor(t,o){n(this,"canvasWrapper",null);n(this,"host",ft());n(this,"container",vt());n(this,"nodeIdToWrapperElementMap",new Map);n(this,"edgeIdToElementMap",new Map);this.graphStore=t,this.viewportTransformer=o,this.host.appendChild(this.container)}attach(t){this.detach(),this.canvasWrapper=t,this.canvasWrapper.appendChild(this.host)}detach(){this.canvasWrapper!==null&&(this.canvasWrapper.removeChild(this.host),this.canvasWrapper=null)}applyTransform(){const t=this.viewportTransformer.getContentMatrix();this.container.style.transform=`matrix(${t.scale}, 0, 0, ${t.scale}, ${t.dx}, ${t.dy})`}attachNode(t){const o=this.graphStore.getNode(t),r=xt();r.appendChild(o.element),this.container.appendChild(r),this.nodeIdToWrapperElementMap.set(t,r),this.updateNodeCoordinates(t),this.updateNodePriority(t),r.style.visibility="visible"}detachNode(t){const o=this.graphStore.getNode(t),r=this.nodeIdToWrapperElementMap.get(t);r.removeChild(o.element),this.container.removeChild(r),this.nodeIdToWrapperElementMap.delete(t)}attachEdge(t){const o=this.graphStore.getEdge(t);this.edgeIdToElementMap.set(t,o.shape.svg),this.container.appendChild(o.shape.svg),this.renderEdge(t),this.updateEdgePriority(t)}detachEdge(t){const o=this.graphStore.getEdge(t);this.container.removeChild(o.shape.svg),this.edgeIdToElementMap.delete(t)}clear(){this.edgeIdToElementMap.forEach((t,o)=>{this.detachEdge(o)}),this.nodeIdToWrapperElementMap.forEach((t,o)=>{this.detachNode(o)})}destroy(){this.clear(),this.detach(),this.host.removeChild(this.container)}updateNodeCoordinates(t){const o=this.nodeIdToWrapperElementMap.get(t),r=this.graphStore.getNode(t),{width:i,height:s}=r.element.getBoundingClientRect(),h=this.viewportTransformer.getViewportMatrix().scale,d=r.centerFn(i,s),c=r.x-h*d.x,l=r.y-h*d.y;o.style.transform=`translate(${c}px, ${l}px)`}updateNodePriority(t){const o=this.graphStore.getNode(t),r=this.nodeIdToWrapperElementMap.get(t);r.style.zIndex=`${o.priority}`}updateEdgeShape(t){const o=this.edgeIdToElementMap.get(t);this.container.removeChild(o);const r=this.graphStore.getEdge(t);this.edgeIdToElementMap.set(t,r.shape.svg),this.container.appendChild(r.shape.svg)}renderEdge(t){const o=this.graphStore.getEdge(t),r=this.graphStore.getPort(o.from),i=this.graphStore.getPort(o.to),s=r.element.getBoundingClientRect(),h=i.element.getBoundingClientRect(),d=this.host.getBoundingClientRect(),c=this.viewportTransformer.getViewportMatrix(),l={x:c.scale*(s.left-d.left)+c.dx,y:c.scale*(s.top-d.top)+c.dy},a={x:c.scale*(h.left-d.left)+c.dx,y:c.scale*(h.top-d.top)+c.dy},g={x:l.x,y:l.y,width:s.width*c.scale,height:s.height*c.scale,direction:r.direction,portId:o.from,nodeId:this.graphStore.getPortNodeId(o.from)},f={x:a.x,y:a.y,width:h.width*c.scale,height:h.height*c.scale,direction:i.direction,portId:o.to,nodeId:this.graphStore.getPortNodeId(o.to)};o.shape.render({source:g,target:f})}updateEdgePriority(t){const o=this.graphStore.getEdge(t);o.shape.svg.style.zIndex=`${o.priority}`}}class P{constructor(t){n(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 A extends Error{constructor(){super(...arguments);n(this,"name","HtmlGraphError")}}class Et{constructor(t,o,r,i,s,h,d){n(this,"nodeIdGenerator",new P(t=>this.graphStore.getNode(t)!==void 0));n(this,"portIdGenerator",new P(t=>this.graphStore.getPort(t)!==void 0));n(this,"edgeIdGenerator",new P(t=>this.graphStore.getEdge(t)!==void 0));this.graphStore=t,this.htmlController=o,this.viewportTransformer=r,this.defaultNodesCenterFn=i,this.defaultPortsDirection=s,this.defaultNodesPriorityFn=h,this.defaultEdgesPriorityFn=d}attach(t){this.htmlController.attach(t)}detach(){this.htmlController.detach()}addNode(t){const o=this.nodeIdGenerator.create(t.nodeId);if(this.graphStore.getNode(o)!==void 0)throw new A("failed to add node with existing id");this.graphStore.addNode({nodeId:o,element:t.element,x:t.x,y:t.y,centerFn:t.centerFn??this.defaultNodesCenterFn,priority:t.priority??this.defaultNodesPriorityFn()}),this.htmlController.attachNode(o),Array.from(t.ports??[]).forEach(r=>{this.markPort({portId:r.id,element:r.element,nodeId:o,direction:r.direction})})}markPort(t){const o=this.portIdGenerator.create(t.portId);if(this.graphStore.getPort(o)!==void 0)throw new A("failed to add port with existing id");if(this.graphStore.getNode(t.nodeId)===void 0)throw new A("failed to set port on nonexisting node");this.graphStore.addPort({portId:o,element:t.element,nodeId:t.nodeId,direction:t.direction??this.defaultPortsDirection})}addEdge(t){const o=this.edgeIdGenerator.create(t.edgeId);if(this.graphStore.getEdge(o)!==void 0)throw new A("failed to add edge with existing id");if(this.graphStore.getPort(t.from)===void 0)throw new A("failed to add edge from nonexisting port");if(this.graphStore.getPort(t.to)===void 0)throw new A("failed to add edge to nonexisting port");this.graphStore.addEdge({edgeId:o,from:t.from,to:t.to,shape:t.shape,priority:t.priority??this.defaultEdgesPriorityFn()}),this.htmlController.attachEdge(o)}updateEdge(t){const o=this.graphStore.getEdge(t.edgeId);if(o===void 0)throw new A("failed to update nonexisting edge");t.shape!==void 0&&(o.shape=t.shape,this.htmlController.updateEdgeShape(t.edgeId)),t.priority!==void 0&&(o.priority=t.priority,this.htmlController.updateEdgePriority(t.edgeId)),t.from!==void 0&&this.graphStore.updateEdgeFrom(t.edgeId,t.from),t.to!==void 0&&this.graphStore.updateEdgeTo(t.edgeId,t.to),this.htmlController.renderEdge(t.edgeId)}updatePort(t,o){const r=this.graphStore.getPort(t);if(r===void 0)throw new A("failed to unset nonexisting port");r.direction=o.direction??r.direction,this.graphStore.getPortAdjacentEdgeIds(t).forEach(s=>{this.htmlController.renderEdge(s)})}updateNode(t,o){const r=this.graphStore.getNode(t);if(r===void 0)throw new A("failed to update nonexisting node");r.x=(o==null?void 0:o.x)??r.x,r.y=(o==null?void 0:o.y)??r.y,r.centerFn=(o==null?void 0:o.centerFn)??r.centerFn,r.priority=(o==null?void 0:o.priority)??r.priority,this.htmlController.updateNodeCoordinates(t),this.htmlController.updateNodePriority(t),this.graphStore.getNodeAdjacentEdgeIds(t).forEach(s=>{this.htmlController.renderEdge(s)})}removeEdge(t){if(this.graphStore.getEdge(t)===void 0)throw new A("failed to remove nonexisting edge");this.htmlController.detachEdge(t),this.graphStore.removeEdge(t)}unmarkPort(t){if(this.graphStore.getPort(t)===void 0)throw new A("failed to unset nonexisting port");this.graphStore.getPortAdjacentEdgeIds(t).forEach(o=>{this.removeEdge(o)}),this.graphStore.removePort(t)}removeNode(t){if(this.graphStore.getNode(t)===void 0)throw new A("failed to remove nonexisting node");this.graphStore.getNodePortIds(t).forEach(o=>{this.unmarkPort(o)}),this.htmlController.detachNode(t),this.graphStore.removeNode(t)}patchViewportMatrix(t){this.viewportTransformer.patchViewportMatrix(t),this.htmlController.applyTransform()}patchContentMatrix(t){this.viewportTransformer.patchContentMatrix(t),this.htmlController.applyTransform()}clear(){this.htmlController.clear(),this.graphStore.clear(),this.nodeIdGenerator.reset(),this.portIdGenerator.reset(),this.edgeIdGenerator.reset()}destroy(){this.clear(),this.htmlController.destroy()}}class K{constructor(t){n(this,"transformation");n(this,"model");n(this,"canvasController");n(this,"edgeShapeFactory");this.apiOptions=t;const o=at(this.apiOptions),r=new wt,i=new gt;this.model=new ut(i),this.transformation=new yt(r);const s=new St(i,r);this.canvasController=new Et(i,s,r,o.nodes.centerFn,o.ports.direction,o.nodes.priorityFn,o.edges.priorityFn),this.edgeShapeFactory=o.edges.shapeFactory}attach(t){return this.canvasController.attach(t),this}detach(){return this.canvasController.detach(),this}addNode(t){return this.canvasController.addNode({nodeId:t.id,element:t.element,x:t.x,y:t.y,ports:t.ports,centerFn:t.centerFn,priority:t.priority}),this}updateNode(t,o){return this.canvasController.updateNode(t,{x:o==null?void 0:o.x,y:o==null?void 0:o.y,priority:o==null?void 0:o.priority,centerFn:o==null?void 0:o.centerFn}),this}removeNode(t){return this.canvasController.removeNode(t),this}addEdge(t){return this.canvasController.addEdge({edgeId:t.id,from:t.from,to:t.to,shape:t.shape??this.edgeShapeFactory(),priority:t.priority}),this}updateEdge(t,o){return this.canvasController.updateEdge({edgeId:t,shape:o==null?void 0:o.shape,priority:o==null?void 0:o.priority,from:o==null?void 0:o.from,to:o==null?void 0:o.to}),this}removeEdge(t){return this.canvasController.removeEdge(t),this}markPort(t){return this.canvasController.markPort({portId:t.id,element:t.element,nodeId:t.nodeId,direction:t.direction}),this}updatePort(t,o){return this.canvasController.updatePort(t,{direction:o==null?void 0:o.direction}),this}unmarkPort(t){return this.canvasController.unmarkPort(t),this}patchViewportMatrix(t){return this.canvasController.patchViewportMatrix(t),this}patchContentMatrix(t){return this.canvasController.patchContentMatrix(t),this}clear(){return this.canvasController.clear(),this}destroy(){this.clear(),this.canvasController.destroy()}}const b=(e,t,o)=>{const{x:r,y:i,width:s,height:h}=e.getBoundingClientRect();return t>=r&&t<=r+s&&o>=i&&o<=i+h},p=(e,t,o)=>t>=0&&t<=e.innerWidth&&o>=0&&o<=e.innerHeight,V=(e,t)=>{t!==null?e.style.cursor=t:e.style.removeProperty("cursor")};class _{constructor(t,o){n(this,"model");n(this,"transformation");n(this,"maxNodePriority",0);n(this,"nodes",new Map);n(this,"grabbedNodeId",null);n(this,"onNodeDrag");n(this,"onBeforeNodeDrag");n(this,"onNodeDragFinished");n(this,"nodeIdGenerator",new P(t=>this.nodes.has(t)));n(this,"element",null);n(this,"onWindowMouseMove",t=>{if(this.element!==null&&(!b(this.element,t.clientX,t.clientY)||!p(this.window,t.clientX,t.clientY))){this.cancelMouseDrag();return}this.grabbedNodeId!==null&&this.dragNode(this.grabbedNodeId,t.movementX,t.movementY)});n(this,"onWindowMouseUp",t=>{t.button===0&&this.cancelMouseDrag()});n(this,"onWindowTouchMove",t=>{if(t.touches.length!==1)return;const o=t.touches[0];if(this.element!==null&&(!b(this.element,o.clientX,o.clientY)||!p(this.window,o.clientX,o.clientY))){this.cancelTouchDrag();return}if(this.grabbedNodeId!==null&&this.previousTouchCoords!==null){const r=o.clientX-this.previousTouchCoords.x,i=o.clientY-this.previousTouchCoords.y;this.dragNode(this.grabbedNodeId,r,i),this.previousTouchCoords={x:t.touches[0].clientX,y:t.touches[0].clientY}}});n(this,"onWindowTouchFinish",t=>{t.touches.length>0?this.previousTouchCoords={x:t.touches[0].clientX,y:t.touches[0].clientY}:this.cancelTouchDrag()});n(this,"previousTouchCoords",null);n(this,"freezePriority");n(this,"window",window);n(this,"dragCursor");var r,i,s;this.canvas=t,this.transformation=this.canvas.transformation,this.model=this.canvas.model,this.onNodeDrag=((r=o==null?void 0:o.events)==null?void 0:r.onNodeDrag)??(()=>{}),this.onBeforeNodeDrag=((i=o==null?void 0:o.events)==null?void 0:i.onBeforeNodeDrag)??(()=>!0),this.onNodeDragFinished=((s=o==null?void 0:o.events)==null?void 0:s.onNodeDragFinished)??(()=>{}),this.freezePriority=(o==null?void 0:o.moveOnTop)===!1,this.dragCursor=(o==null?void 0:o.dragCursor)!==void 0?o.dragCursor:"grab"}attach(t){return this.detach(),this.element=t,this.canvas.attach(this.element),this}detach(){return this.canvas.detach(),this.element!==null&&(this.element=null),this}addNode(t){const o=this.nodeIdGenerator.create(t.id);this.canvas.addNode({...t,id:o}),this.updateMaxNodePriority(o);const r=s=>{if(this.element===null||s.button!==0)return;const h=this.model.getNode(o);this.onBeforeNodeDrag({nodeId:o,element:t.element,x:h.x,y:h.y})&&(s.stopImmediatePropagation(),this.grabbedNodeId=o,V(this.element,this.dragCursor),this.moveNodeOnTop(o),this.window.addEventListener("mouseup",this.onWindowMouseUp),this.window.addEventListener("mousemove",this.onWindowMouseMove))},i=s=>{s.stopImmediatePropagation(),this.previousTouchCoords={x:s.touches[0].clientX,y:s.touches[0].clientY};const h=this.model.getNode(o);this.onBeforeNodeDrag({nodeId:o,element:t.element,x:h.x,y:h.y})&&s.touches.length===1&&(this.grabbedNodeId=o,this.moveNodeOnTop(o),this.window.addEventListener("touchmove",this.onWindowTouchMove),this.window.addEventListener("touchend",this.onWindowTouchFinish),this.window.addEventListener("touchcancel",this.onWindowTouchFinish))};return this.nodes.set(o,{element:t.element,onMouseDown:r,onTouchStart:i}),t.element.addEventListener("mousedown",r),t.element.addEventListener("touchstart",i),this}updateNode(t,o){return this.canvas.updateNode(t,o),this.updateMaxNodePriority(t),this}removeNode(t){const o=this.nodes.get(t);return o!==void 0&&(o.element.removeEventListener("mousedown",o.onMouseDown),o.element.removeEventListener("touchstart",o.onTouchStart)),this.nodes.delete(t),this.canvas.removeNode(t),this}markPort(t){return this.canvas.markPort(t),this}updatePort(t,o){return this.canvas.updatePort(t,o),this}unmarkPort(t){return this.canvas.unmarkPort(t),this}addEdge(t){return this.canvas.addEdge(t),this}updateEdge(t,o){return this.canvas.updateEdge(t,o),this}removeEdge(t){return this.canvas.removeEdge(t),this}patchViewportMatrix(t){return this.canvas.patchViewportMatrix(t),this}patchContentMatrix(t){return this.canvas.patchContentMatrix(t),this}clear(){return this.canvas.clear(),this.nodes.forEach(t=>{t.element.removeEventListener("mousedown",t.onMouseDown),t.element.removeEventListener("touchstart",t.onTouchStart)}),this.nodes.clear(),this.maxNodePriority=0,this}destroy(){this.detach(),this.clear(),this.removeMouseDragListeners(),this.removeTouchDragListeners(),this.canvas.destroy()}dragNode(t,o,r){const i=this.model.getNode(t);if(i===null)return;const s=this.canvas.transformation.getContentMatrix(),h=s.scale*i.x+s.dx,d=s.scale*i.y+s.dy,c=h+o,l=d+r,a=this.canvas.transformation.getViewportMatrix(),g=a.scale*c+a.dx,f=a.scale*l+a.dy;this.canvas.updateNode(t,{x:g,y:f}),this.onNodeDrag({nodeId:t,element:i.element,x:i.x,y:i.y})}updateMaxNodePriority(t){const o=this.model.getNode(t).priority;this.maxNodePriority=Math.max(this.maxNodePriority,o)}moveNodeOnTop(t){if(this.freezePriority)return;this.maxNodePriority+=2,this.updateNode(t,{priority:this.maxNodePriority});const o=this.maxNodePriority-1;this.model.getNodeAdjacentEdgeIds(t).forEach(i=>{this.updateEdge(i,{priority:o})})}cancelMouseDrag(){const t=this.model.getNode(this.grabbedNodeId);t!==null&&this.onNodeDragFinished({nodeId:this.grabbedNodeId,element:t.element,x:t.x,y:t.y}),this.grabbedNodeId=null,this.element!==null&&V(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}cancelTouchDrag(){this.previousTouchCoords=null;const t=this.model.getNode(this.grabbedNodeId);t!==null&&this.onNodeDragFinished({nodeId:this.grabbedNodeId,element:t.element,x:t.x,y:t.y}),this.grabbedNodeId=null,this.removeTouchDragListeners()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}const At=e=>{const t=e.minX!==null?e.minX:-1/0,o=e.maxX!==null?e.maxX:1/0,r=e.minY!==null?e.minY:-1/0,i=e.maxY!==null?e.maxY:1/0;return s=>{let h=s.nextTransform.dx,d=s.nextTransform.dy;h<t&&h<s.prevTransform.dx&&(h=Math.min(s.prevTransform.dx,t));const c=s.canvasWidth*s.prevTransform.scale;h>o-c&&h>s.prevTransform.dx&&(h=Math.max(s.prevTransform.dx,o-c)),d<r&&d<s.prevTransform.dy&&(d=Math.min(s.prevTransform.dy,r));const l=s.canvasHeight*s.prevTransform.scale;return d>i-l&&d>s.prevTransform.dy&&(d=Math.max(s.prevTransform.dy,i-l)),{scale:s.nextTransform.scale,dx:h,dy:d}}},Tt=e=>{const t=e.maxContentScale,o=e.minContentScale,r=t!==null?1/t:0,i=o!==null?1/o:1/0;return s=>{const h=s.prevTransform,d=s.nextTransform;let c=d.scale,l=d.dx,a=d.dy;if(d.scale>i&&d.scale>h.scale){c=Math.max(h.scale,i),l=h.dx,a=h.dy;const g=(c-h.scale)/(d.scale-h.scale);l=h.dx+(d.dx-h.dx)*g,a=h.dy+(d.dy-h.dy)*g}if(d.scale<r&&d.scale<h.scale){c=Math.min(h.scale,r),l=h.dx,a=h.dy;const g=(c-h.scale)/(d.scale-h.scale);l=h.dx+(d.dx-h.dx)*g,a=h.dy+(d.dy-h.dy)*g}return{scale:c,dx:l,dy:a}}},Mt=e=>t=>e.reduce((o,r)=>r({prevTransform:t.prevTransform,nextTransform:o,canvasWidth:t.canvasWidth,canvasHeight:t.canvasHeight}),t.nextTransform),J=e=>{if(typeof e=="function")return e;switch(e.type){case"scale-limit":return Tt({minContentScale:e.minContentScale??0,maxContentScale:e.maxContentScale??1/0});case"shift-limit":return At({minX:e.minX??-1/0,maxX:e.maxX??1/0,minY:e.minY??-1/0,maxY:e.maxY??1/0})}},Ct=e=>{var c,l,a,g;const t=(c=e==null?void 0:e.scale)==null?void 0:c.mouseWheelSensitivity,o=t!==void 0?t:1.2,r=e==null?void 0:e.transformPreprocessor;let i;r!==void 0?Array.isArray(r)?i=Mt(r.map(f=>J(f))):i=J(r):i=f=>f.nextTransform;const s=((l=e==null?void 0:e.shift)==null?void 0:l.cursor)!==void 0?e.shift.cursor:"grab",h=((a=e==null?void 0:e.events)==null?void 0:a.onBeforeTransformStarted)??(()=>{}),d=((g=e==null?void 0:e.events)==null?void 0:g.onTransformFinished)??(()=>{});return{wheelSensitivity:o,onBeforeTransformStarted:h,onTransformFinished:d,transformPreprocessor:i,shiftCursor:s}},X=e=>{const t=[],o=e.touches.length;for(let d=0;d<o;d++)t.push([e.touches[d].clientX,e.touches[d].clientY]);const r=t.reduce((d,c)=>[d[0]+c[0],d[1]+c[1]],[0,0]),i=[r[0]/o,r[1]/o],h=t.map(d=>[d[0]-i[0],d[1]-i[1]]).reduce((d,c)=>d+Math.sqrt(c[0]*c[0]+c[1]*c[1]),0);return{x:i[0],y:i[1],scale:h/o,touchesCnt:o,touches:t}},Nt=(e,t,o)=>({scale:e.scale,dx:e.dx+e.scale*t,dy:e.dy+e.scale*o}),Pt=(e,t,o,r)=>({scale:e.scale*t,dx:e.scale*(1-t)*o+e.dx,dy:e.scale*(1-t)*r+e.dy});class Q{constructor(t,o){n(this,"model");n(this,"transformation");n(this,"element",null);n(this,"prevTouches",null);n(this,"window",window);n(this,"onMouseDown",t=>{this.element===null||t.button!==0||(V(this.element,this.options.shiftCursor),this.window.addEventListener("mousemove",this.onWindowMouseMove),this.window.addEventListener("mouseup",this.onWindowMouseUp))});n(this,"onWindowMouseMove",t=>{if(this.element===null||!b(this.element,t.clientX,t.clientY)||!p(this.window,t.clientX,t.clientY)){this.stopMouseDrag();return}const o=-t.movementX,r=-t.movementY;this.moveViewport(this.element,o,r)});n(this,"onWindowMouseUp",t=>{this.element===null||t.button!==0||this.stopMouseDrag()});n(this,"onWheelScroll",t=>{t.preventDefault();const{left:o,top:r}=this.element.getBoundingClientRect(),i=t.clientX-o,s=t.clientY-r,d=1/(t.deltaY<0?this.options.wheelSensitivity:1/this.options.wheelSensitivity);this.scaleViewport(this.element,d,i,s)});n(this,"onTouchStart",t=>{this.prevTouches=X(t),this.window.addEventListener("touchmove",this.onWindowTouchMove),this.window.addEventListener("touchend",this.onWindowTouchFinish),this.window.addEventListener("touchcancel",this.onWindowTouchFinish)});n(this,"onWindowTouchMove",t=>{const o=this.element;if(o===null)return;const r=X(t);if(!r.touches.every(s=>b(o,s[0],s[1])&&p(this.window,s[0],s[1]))){this.stopTouchDrag();return}if((r.touchesCnt===1||r.touchesCnt===2)&&this.moveViewport(o,-(r.x-this.prevTouches.x),-(r.y-this.prevTouches.y)),r.touchesCnt===2){const{left:s,top:h}=o.getBoundingClientRect(),d=this.prevTouches.x-s,c=this.prevTouches.y-h,a=1/(r.scale/this.prevTouches.scale);this.scaleViewport(o,a,d,c)}this.prevTouches=r});n(this,"onWindowTouchFinish",t=>{t.touches.length>0?this.prevTouches=X(t):this.stopTouchDrag()});n(this,"observer",new ResizeObserver(()=>{const t=this.canvas.transformation.getViewportMatrix(),{width:o,height:r}=this.element.getBoundingClientRect(),i=this.options.transformPreprocessor({prevTransform:t,nextTransform:t,canvasWidth:o,canvasHeight:r});this.canvas.patchViewportMatrix(i),this.options.onTransformFinished()}));n(this,"options");this.canvas=t,this.options=Ct(o),this.transformation=this.canvas.transformation,this.model=this.canvas.model}attach(t){return this.detach(),this.element=t,this.observer.observe(this.element),this.element.addEventListener("mousedown",this.onMouseDown),this.element.addEventListener("wheel",this.onWheelScroll),this.element.addEventListener("touchstart",this.onTouchStart),this.canvas.attach(this.element),this}detach(){return this.canvas.detach(),this.element!==null&&(this.observer.unobserve(this.element),this.element.removeEventListener("mousedown",this.onMouseDown),this.element.removeEventListener("wheel",this.onWheelScroll),this.element.removeEventListener("touchstart",this.onTouchStart),this.element=null),this}addNode(t){return this.canvas.addNode(t),this}updateNode(t,o){return this.canvas.updateNode(t,o),this}removeNode(t){return this.canvas.removeNode(t),this}markPort(t){return this.canvas.markPort(t),this}updatePort(t,o){return this.canvas.updatePort(t,o),this}unmarkPort(t){return this.canvas.unmarkPort(t),this}addEdge(t){return this.canvas.addEdge(t),this}updateEdge(t,o){return this.canvas.updateEdge(t,o),this}removeEdge(t){return this.canvas.removeEdge(t),this}patchViewportMatrix(t){return this.canvas.patchViewportMatrix(t),this}patchContentMatrix(t){return this.canvas.patchContentMatrix(t),this}clear(){return this.canvas.clear(),this}destroy(){this.detach(),this.removeMouseDragListeners(),this.removeTouchDragListeners(),this.canvas.destroy()}moveViewport(t,o,r){this.options.onBeforeTransformStarted();const i=this.transformation.getViewportMatrix(),s=Nt(i,o,r),{width:h,height:d}=t.getBoundingClientRect(),c=this.options.transformPreprocessor({prevTransform:i,nextTransform:s,canvasWidth:h,canvasHeight:d});this.canvas.patchViewportMatrix(c),this.options.onTransformFinished()}scaleViewport(t,o,r,i){this.options.onBeforeTransformStarted();const s=this.canvas.transformation.getViewportMatrix(),h=Pt(s,o,r,i),{width:d,height:c}=t.getBoundingClientRect(),l=this.options.transformPreprocessor({prevTransform:s,nextTransform:h,canvasWidth:d,canvasHeight:c});this.canvas.patchViewportMatrix(l),this.options.onTransformFinished()}stopMouseDrag(){this.element!==null&&V(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}stopTouchDrag(){this.prevTouches=null,this.removeTouchDragListeners()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}class Lt{constructor(){n(this,"keyMap",new Map);n(this,"valueMap",new Map)}set(t,o){this.keyMap.set(t,o),this.valueMap.set(o,t)}hasKey(t){return this.keyMap.has(t)}hasValue(t){return this.valueMap.has(t)}getByKey(t){return this.keyMap.get(t)}getByValue(t){return this.valueMap.get(t)}deleteByKey(t){const o=this.keyMap.get(t);o!==void 0&&this.valueMap.delete(o),this.keyMap.delete(t)}deleteByValue(t){const o=this.valueMap.get(t);o!==void 0&&this.keyMap.delete(o),this.valueMap.delete(t)}forEach(t){this.keyMap.forEach((o,r)=>{t(o,r)})}clear(){this.keyMap.clear(),this.valueMap.clear()}}class Z{constructor(t){n(this,"transformation");n(this,"model");n(this,"nodes",new Lt);n(this,"nodeIdGenerator",new P(t=>this.nodes.hasKey(t)));n(this,"nodesResizeObserver");this.canvas=t,this.nodesResizeObserver=new window.ResizeObserver(o=>{o.forEach(r=>{const i=r.target;this.reactNodeChange(i)})}),this.transformation=this.canvas.transformation,this.model=this.canvas.model}attach(t){return this.canvas.attach(t),this}detach(){return this.canvas.detach(),this}addNode(t){const o=this.nodeIdGenerator.create(t.id);return this.canvas.addNode({...t,id:o}),this.nodes.set(o,t.element),this.nodesResizeObserver.observe(t.element),this}updateNode(t,o){return this.canvas.updateNode(t,o),this}removeNode(t){this.canvas.removeNode(t);const o=this.nodes.getByKey(t);return this.nodes.deleteByKey(t),this.nodesResizeObserver.unobserve(o),this}markPort(t){return this.canvas.markPort(t),this}updatePort(t,o){return this.canvas.updatePort(t,o),this}unmarkPort(t){return this.canvas.unmarkPort(t),this}addEdge(t){return this.canvas.addEdge(t),this}updateEdge(t,o){return this.canvas.updateEdge(t,o),this}removeEdge(t){return this.canvas.removeEdge(t),this}patchViewportMatrix(t){return this.canvas.patchViewportMatrix(t),this}patchContentMatrix(t){return this.canvas.patchContentMatrix(t),this}clear(){return this.canvas.clear(),this.nodesResizeObserver.disconnect(),this.nodes.clear(),this}destroy(){this.clear(),this.canvas.destroy()}reactNodeChange(t){const o=this.nodes.getByValue(t);this.canvas.updateNode(o),this.model.getNodeAdjacentEdgeIds(o).forEach(i=>{this.canvas.updateEdge(i)})}}class Dt{constructor(){n(this,"coreOptions");n(this,"dragOptions");n(this,"transformOptions");n(this,"isDraggable",!1);n(this,"isTransformable",!1);n(this,"hasResizeReactiveNodes",!1)}setOptions(t){return this.coreOptions=t,this}setUserDraggableNodes(t){return this.isDraggable=!0,this.dragOptions=t,this}setUserTransformableCanvas(t){return this.isTransformable=!0,this.transformOptions=t,this}setResizeReactiveNodes(){return this.hasResizeReactiveNodes=!0,this}build(){let t=new K(this.coreOptions);return this.hasResizeReactiveNodes&&(t=new Z(t)),this.isDraggable&&(t=new _(t,this.dragOptions)),this.isTransformable&&(t=new Q(t,this.transformOptions)),t}}x.BezierEdgeShape=B,x.CanvasCore=K,x.HorizontalEdgeShape=z,x.HtmlGraphBuilder=Dt,x.HtmlGraphError=A,x.ResizeReactiveNodesCanvas=Z,x.StraightEdgeShape=G,x.UserDraggableNodesCanvas=_,x.UserTransformableCanvas=Q,x.VerticalEdgeShape=H,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(S,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(S=typeof globalThis<"u"?globalThis:S||self,E(S.HTMLGraph={}))})(this,function(S){"use strict";var mt=Object.defineProperty;var $t=(S,E,v)=>E in S?mt(S,E,{enumerable:!0,configurable:!0,writable:!0,value:v}):S[E]=v;var n=(S,E,v)=>$t(S,typeof E!="symbol"?E+"":E,v);const E=(e,t)=>({x:e/2,y:t/2}),v=(e,t,o)=>({x:t.x*e.x-t.y*e.y+((1-t.x)*o.x+t.y*o.y),y:t.y*e.x+t.x*e.y+((1-t.x)*o.y-t.y*o.x)}),T=(e,t,o)=>({x:t*Math.cos(e),y:o*Math.sin(e)}),u={x:0,y:0},M=(e,t,o,r)=>{const s=[u,{x:o,y:r},{x:o,y:-r}].map(l=>v(l,e,u)).map(l=>({x:l.x+t.x,y:l.y+t.y})),h=`M ${s[0].x} ${s[0].y}`,d=`L ${s[1].x} ${s[1].y}`,c=`L ${s[2].x} ${s[2].y}`;return`${h} ${d} ${c}`},D=(e,t)=>{const o=[];if(e.length>0&&o.push(`M ${e[0].x} ${e[0].y}`),e.length===2&&o.push(`L ${e[1].x} ${e[1].y}`),e.length>2){const r=e.length-1;let i=0,s=0,h=0;e.forEach((d,c)=>{let l=0,a=0,g=0;const y=c>0,x=c<r,f=y&&x;if(y&&(l=-i,a=-s,g=h),x){const ot=e[c+1];i=ot.x-d.x,s=ot.y-d.y,h=Math.sqrt(i*i+s*s)}const N=h!==0?Math.min((f?t:0)/h,c<r-1?.5:1):0,P=f?{x:d.x+i*N,y:d.y+s*N}:d,tt=g!==0?Math.min((f?t:0)/g,c>1?.5:1):0,et=f?{x:d.x+l*tt,y:d.y+a*tt}:d;c>0&&o.push(`L ${et.x} ${et.y}`),f&&o.push(`C ${d.x} ${d.y} ${d.x} ${d.y} ${P.x} ${P.y}`)})}return o.join(" ")},m=()=>{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.style.pointerEvents="none",e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.overflow="visible",e},$=()=>{const e=document.createElementNS("http://www.w3.org/2000/svg","g");return e.style.transformOrigin="50% 50%",e},p=(e,t)=>{const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("stroke",e),o.setAttribute("stroke-width",`${t}`),o.setAttribute("fill","none"),o},C=e=>{const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("fill",e),t},b=(e,t)=>{const o={x:e.x+e.width/2,y:e.y+e.height/2},r={x:t.x+t.width/2,y:t.y+t.height/2},i=Math.min(o.x,r.x),s=Math.min(o.y,r.y),h=Math.abs(r.x-o.x),d=Math.abs(r.y-o.y),c=o.x<=r.x?1:-1,l=o.y<=r.y?1:-1;return{x:i,y:s,width:h,height:d,flipX:c,flipY:l}},rt=e=>{const t=v({x:e.arrowLength,y:u.y},e.fromVect,u),o=v({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to),r={x:t.x+e.fromVect.x*e.curvature,y:t.y+e.fromVect.y*e.curvature},i={x:o.x-e.toVect.x*e.curvature,y:o.y-e.toVect.y*e.curvature},s=`M ${t.x} ${t.y} C ${r.x} ${r.y}, ${i.x} ${i.y}, ${o.x} ${o.y}`,h=e.hasSourceArrow?"":`M ${u.x} ${u.y} L ${t.x} ${t.y} `,d=e.hasTargetArrow?"":` M ${o.x} ${o.y} L ${e.to.x} ${e.to.y}`;return`${h}${s}${d}`},it=e=>{const t=e.hasSourceArrow?v({x:e.arrowLength,y:u.y},e.fromVect,u):u,o=e.hasTargetArrow?v({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to):e.to,r=e.arrowLength,i=Math.cos(e.detourDirection)*e.detourDistance,s=Math.sin(e.detourDirection)*e.detourDistance,h=i*e.flipX,d=s*e.flipY,c=v({x:r,y:u.y},e.fromVect,u),l={x:c.x+h,y:c.y+d},a=v({x:e.to.x-r,y:e.to.y},e.toVect,e.to),g={x:a.x+h,y:a.y+d},y={x:(l.x+g.x)/2,y:(l.y+g.y)/2},x={x:c.x+e.curvature*e.fromVect.x,y:c.y+e.curvature*e.fromVect.y},f={x:a.x-e.curvature*e.toVect.x,y:a.y-e.curvature*e.toVect.y},L={x:c.x+h,y:c.y+d},N={x:a.x+h,y:a.y+d};return[`M ${t.x} ${t.y}`,`L ${c.x} ${c.y}`,`C ${x.x} ${x.y} ${L.x} ${L.y} ${y.x} ${y.y}`,`C ${N.x} ${N.y} ${f.x} ${f.y} ${a.x} ${a.y}`,`L ${o.x} ${o.y}`].join(" ")},nt=e=>{const t=e.hasSourceArrow?v({x:e.arrowLength,y:u.y},e.fromVect,u):u,o=e.hasTargetArrow?v({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to):e.to,r=e.arrowLength+e.arrowOffset,i=r-e.roundness,s=v({x:i,y:u.y},e.fromVect,u),h=v({x:e.to.x-i,y:e.to.y},e.toVect,e.to),d=Math.max((s.x+h.x)/2,r),c=e.to.y/2,l={x:e.flipX>0?d:-r,y:s.y},a={x:l.x,y:c},g={x:e.flipX>0?e.to.x-d:e.to.x+r,y:h.y},y={x:g.x,y:c};return D([t,s,l,a,y,g,h,o],e.roundness)},R=e=>{const t=e.hasSourceArrow?v({x:e.arrowLength,y:u.y},e.fromVect,u):u,o=e.hasTargetArrow?v({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to):e.to,r=e.arrowLength+e.arrowOffset,i=v({x:r,y:u.y},e.fromVect,u),s=Math.cos(e.detourDirection)*e.detourDistance,h=Math.sin(e.detourDirection)*e.detourDistance,d=s*e.flipX,c=h*e.flipY,l={x:i.x+d,y:i.y+c},a=v({x:e.to.x-r,y:e.to.y},e.toVect,e.to),g={x:a.x+d,y:a.y+c};return D([t,i,l,g,a,o],e.roundness)},st=e=>{const t=e.hasSourceArrow?v({x:e.arrowLength,y:u.y},e.fromVect,u):u,o=e.hasTargetArrow?v({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to):e.to,r=e.arrowLength+e.arrowOffset,i=v({x:r,y:u.y},e.fromVect,u),s=v({x:e.to.x-r,y:e.to.y},e.toVect,e.to);return D([t,i,s,o],e.roundness)},ht=e=>{const t=e.hasSourceArrow?v({x:e.arrowLength,y:u.y},e.fromVect,u):u,o=e.hasTargetArrow?v({x:e.to.x-e.arrowLength,y:e.to.y},e.toVect,e.to):e.to,r=e.arrowLength+e.arrowOffset,i=r-e.roundness,s=v({x:i,y:u.y},e.fromVect,u),h=v({x:e.to.x-i,y:e.to.y},e.toVect,e.to),d=Math.max((s.y+h.y)/2,r),c=e.to.x/2,l={x:s.x,y:e.flipY>0?d:-r},a={x:c,y:l.y},g={x:h.x,y:e.flipY>0?e.to.y-d:e.to.y+r},y={x:c,y:g.y};return D([t,s,l,a,y,g,h,o],e.roundness)},Y=e=>{const t=e.arrowOffset,o=e.side,r=e.arrowLength+t,i=r+2*o,h=[{x:e.arrowLength,y:u.y},{x:r,y:u.y},{x:r,y:e.side},{x:i,y:e.side},{x:i,y:-e.side},{x:r,y:-e.side},{x:r,y:u.y},{x:e.arrowLength,y:u.y}].map(c=>v(c,e.fromVect,u)),d=`M ${u.x} ${u.y} L ${h[0].x} ${h[0].y} `;return`${e.hasSourceArrow||e.hasTargetArrow?"":d}${D(h,e.roundness)}`},dt=e=>{const t=e.smallRadius,o=e.radius,r=Math.sqrt(t*t+o*o),i=t+o,s=e.arrowLength+r*(1-o/i),h=t*o/i,c=[{x:e.arrowLength,y:u.y},{x:s,y:h},{x:s,y:-h}].map(g=>v(g,e.fromVect,u)),l=[`M ${c[0].x} ${c[0].y}`,`A ${t} ${t} 0 0 1 ${c[1].x} ${c[1].y}`,`A ${o} ${o} 0 1 0 ${c[2].x} ${c[2].y}`,`A ${t} ${t} 0 0 1 ${c[0].x} ${c[0].y}`].join(" "),a=`M 0 0 L ${c[0].x} ${c[0].y} `;return`${e.hasSourceArrow||e.hasTargetArrow?"":a}${l}`},w=Object.freeze({color:"#5c5c5c",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});class z{constructor(t){n(this,"svg",m());n(this,"group",$());n(this,"line");n(this,"sourceArrow",null);n(this,"targetArrow",null);n(this,"arrowLength");n(this,"arrowWidth");n(this,"curvature");n(this,"portCycleRadius");n(this,"portCycleSmallRadius");n(this,"detourDirection");n(this,"detourDistance");n(this,"hasSourceArrow");n(this,"hasTargetArrow");this.arrowLength=(t==null?void 0:t.arrowLength)??w.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??w.arrowWidth,this.curvature=(t==null?void 0:t.curvature)??w.curvature,this.portCycleRadius=(t==null?void 0:t.cycleRadius)??w.cycleRadius,this.portCycleSmallRadius=(t==null?void 0:t.smallCycleRadius)??w.smallCycleRadius,this.detourDirection=(t==null?void 0:t.detourDirection)??w.detourDirection,this.detourDistance=(t==null?void 0:t.detourDistance)??w.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??w.hasTargetArrow;const o=(t==null?void 0:t.color)??w.color,r=(t==null?void 0:t.width)??w.width;this.svg.appendChild(this.group),this.line=p(o,r),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=C(o),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=C(o),this.group.appendChild(this.targetArrow))}render(t){const{x:o,y:r,width:i,height:s,flipX:h,flipY:d}=b(t.source,t.target);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${i}px`,this.svg.style.height=`${s}px`,this.group.style.transform=`scale(${h}, ${d})`;const c=T(t.source.direction,h,d),l=T(t.target.direction,h,d),a={x:i,y:s};let g,y=l,x=-this.arrowLength;if(t.source.portId===t.target.portId?(g=dt({fromVect:c,radius:this.portCycleRadius,smallRadius:this.portCycleSmallRadius,arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),y=c,x=this.arrowLength):t.source.nodeId===t.target.nodeId?g=it({to:a,fromVect:c,toVect:l,flipX:h,flipY:d,arrowLength:this.arrowLength,detourDirection:this.detourDirection,detourDistance:this.detourDistance,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=rt({to:a,fromVect:c,toVect:l,arrowLength:this.arrowLength,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const f=M(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",f)}if(this.targetArrow){const f=M(y,a,x,this.arrowWidth);this.targetArrow.setAttribute("d",f)}}}class G{constructor(t){n(this,"svg",m());n(this,"group",$());n(this,"line");n(this,"sourceArrow",null);n(this,"targetArrow",null);n(this,"arrowLength");n(this,"arrowWidth");n(this,"arrowOffset");n(this,"roundness");n(this,"cycleSquareSide");n(this,"detourDirection");n(this,"detourDistance");n(this,"hasSourceArrow");n(this,"hasTargetArrow");this.arrowLength=(t==null?void 0:t.arrowLength)??w.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??w.arrowWidth,this.arrowOffset=(t==null?void 0:t.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(t==null?void 0:t.cycleSquareSide)??w.cycleSquareSide;const o=(t==null?void 0:t.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(t==null?void 0:t.detourDirection)??w.detourDirection,this.detourDistance=(t==null?void 0:t.detourDistance)??w.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??w.hasTargetArrow;const r=(t==null?void 0:t.color)??w.color,i=(t==null?void 0:t.width)??w.width;this.svg.appendChild(this.group),this.line=p(r,i),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=C(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=C(r),this.group.appendChild(this.targetArrow))}render(t){const{x:o,y:r,width:i,height:s,flipX:h,flipY:d}=b(t.source,t.target);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${i}px`,this.svg.style.height=`${s}px`,this.group.style.transform=`scale(${h}, ${d})`;const c=T(t.source.direction,h,d),l=T(t.target.direction,h,d),a={x:i,y:s};let g,y=l,x=-this.arrowLength;if(t.source.portId===t.target.portId?(g=Y({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),y=c,x=this.arrowLength):t.source.nodeId===t.target.nodeId?g=R({to:a,fromVect:c,toVect:l,flipX:h,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=nt({to:a,fromVect:c,toVect:l,flipX:h,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const f=M(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",f)}if(this.targetArrow){const f=M(y,a,x,this.arrowWidth);this.targetArrow.setAttribute("d",f)}}}class H{constructor(t){n(this,"svg",m());n(this,"group",$());n(this,"line");n(this,"sourceArrow",null);n(this,"targetArrow",null);n(this,"arrowLength");n(this,"arrowWidth");n(this,"arrowOffset");n(this,"roundness");n(this,"cycleSquareSide");n(this,"detourDirection");n(this,"detourDistance");n(this,"hasSourceArrow");n(this,"hasTargetArrow");this.arrowLength=(t==null?void 0:t.arrowLength)??w.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??w.arrowWidth,this.arrowOffset=(t==null?void 0:t.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(t==null?void 0:t.cycleSquareSide)??w.cycleSquareSide;const o=(t==null?void 0:t.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(t==null?void 0:t.detourDirection)??w.detourDirection,this.detourDistance=(t==null?void 0:t.detourDistance)??w.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??w.hasTargetArrow;const r=(t==null?void 0:t.color)??w.color,i=(t==null?void 0:t.width)??w.width;this.svg.appendChild(this.group),this.line=p(r,i),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=C(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=C(r),this.group.appendChild(this.targetArrow))}render(t){const{x:o,y:r,width:i,height:s,flipX:h,flipY:d}=b(t.source,t.target);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${i}px`,this.svg.style.height=`${s}px`,this.group.style.transform=`scale(${h}, ${d})`;const c=T(t.source.direction,h,d),l=T(t.target.direction,h,d),a={x:i,y:s};let g,y=l,x=-this.arrowLength;if(t.source.portId===t.target.portId?(g=Y({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),y=c,x=this.arrowLength):t.source.nodeId===t.target.nodeId?g=R({to:a,fromVect:c,toVect:l,flipX:h,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=st({to:a,fromVect:c,toVect:l,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const f=M(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",f)}if(this.targetArrow){const f=M(y,a,x,this.arrowWidth);this.targetArrow.setAttribute("d",f)}}}class j{constructor(t){n(this,"svg",m());n(this,"group",$());n(this,"line");n(this,"sourceArrow",null);n(this,"targetArrow",null);n(this,"arrowLength");n(this,"arrowWidth");n(this,"arrowOffset");n(this,"roundness");n(this,"cycleSquareSide");n(this,"detourDirection");n(this,"detourDistance");n(this,"hasSourceArrow");n(this,"hasTargetArrow");this.arrowLength=(t==null?void 0:t.arrowLength)??w.arrowLength,this.arrowWidth=(t==null?void 0:t.arrowWidth)??w.arrowWidth,this.arrowOffset=(t==null?void 0:t.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(t==null?void 0:t.cycleSquareSide)??w.cycleSquareSide;const o=(t==null?void 0:t.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(t==null?void 0:t.detourDirection)??w.detourDirectionVertical,this.detourDistance=(t==null?void 0:t.detourDistance)??w.detourDistance,this.hasSourceArrow=(t==null?void 0:t.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(t==null?void 0:t.hasTargetArrow)??w.hasTargetArrow;const r=(t==null?void 0:t.color)??w.color,i=(t==null?void 0:t.width)??w.width;this.svg.appendChild(this.group),this.line=p(r,i),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=C(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=C(r),this.group.appendChild(this.targetArrow))}render(t){const{x:o,y:r,width:i,height:s,flipX:h,flipY:d}=b(t.source,t.target);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${i}px`,this.svg.style.height=`${s}px`,this.group.style.transform=`scale(${h}, ${d})`;const c=T(t.source.direction,h,d),l=T(t.target.direction,h,d),a={x:i,y:s};let g,y=l,x=-this.arrowLength;if(t.source.portId===t.target.portId?(g=Y({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),y=c,x=this.arrowLength):t.source.nodeId===t.target.nodeId?g=R({to:a,fromVect:c,toVect:l,flipX:h,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=ht({to:a,fromVect:c,toVect:l,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const f=M(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",f)}if(this.targetArrow){const f=M(y,a,x,this.arrowWidth);this.targetArrow.setAttribute("d",f)}}}const ct=e=>{if(typeof e=="function")return e;switch(e==null?void 0:e.type){case"straight":return()=>new H({color:e.color,width:e.width,arrowLength:e.arrowLength,arrowWidth:e.arrowWidth,arrowOffset:e.arrowOffset,hasSourceArrow:e.hasSourceArrow,hasTargetArrow:e.hasTargetArrow,cycleSquareSide:e.cycleSquareSide,roundness:e.roundness,detourDistance:e.detourDistance,detourDirection:e.detourDirection});case"horizontal":return()=>new G({color:e.color,width:e.width,arrowLength:e.arrowLength,arrowWidth:e.arrowWidth,arrowOffset:e.arrowOffset,hasSourceArrow:e.hasSourceArrow,hasTargetArrow:e.hasTargetArrow,cycleSquareSide:e.cycleSquareSide,roundness:e.roundness,detourDistance:e.detourDistance,detourDirection:e.detourDirection});case"vertical":return()=>new j({color:e.color,width:e.width,arrowLength:e.arrowLength,arrowWidth:e.arrowWidth,arrowOffset:e.arrowOffset,hasSourceArrow:e.hasSourceArrow,hasTargetArrow:e.hasTargetArrow,cycleSquareSide:e.cycleSquareSide,roundness:e.roundness,detourDistance:e.detourDistance,detourDirection:e.detourDirection});default:return()=>new z({color:e.color,width:e.width,arrowLength:e.arrowLength,arrowWidth:e.arrowWidth,hasSourceArrow:e.hasSourceArrow,hasTargetArrow:e.hasTargetArrow,cycleRadius:e.cycleRadius,smallCycleRadius:e.smallCycleRadius,curvature:e.curvature,detourDistance:e.detourDistance,detourDirection:e.detourDirection})}},X=e=>()=>e,U=X(0),k=()=>{let e=0;return()=>e++},lt=(e,t)=>{let o=U,r=U;e==="incremental"&&(o=k()),t==="incremental"&&(r=k());const i=k();return e==="shared-incremental"&&(o=i),t==="shared-incremental"&&(r=i),typeof e=="number"&&(o=X(e)),typeof t=="number"&&(r=X(t)),typeof e=="function"&&(o=e),typeof t=="function"&&(r=t),{nodesPriorityFn:o,edgesPriorityFn:r}},at=e=>{var o,r,i,s,h;const t=lt((o=e==null?void 0:e.nodes)==null?void 0:o.priority,(r=e==null?void 0:e.edges)==null?void 0:r.priority);return{nodes:{centerFn:((i=e==null?void 0:e.nodes)==null?void 0:i.centerFn)??E,priorityFn:t.nodesPriorityFn},ports:{direction:((s=e==null?void 0:e.ports)==null?void 0:s.direction)??0},edges:{shapeFactory:ct(((h=e==null?void 0:e.edges)==null?void 0:h.shape)??{}),priorityFn:t.edgesPriorityFn}}};class gt{constructor(){n(this,"nodes",new Map);n(this,"ports",new Map);n(this,"nodePorts",new Map);n(this,"portNodeId",new Map);n(this,"edges",new Map);n(this,"incommingEdges",new Map);n(this,"outcommingEdges",new Map);n(this,"cycleEdges",new Map)}addNode(t){this.nodes.set(t.nodeId,{element:t.element,x:t.x,y:t.y,centerFn:t.centerFn,priority:t.priority}),this.nodePorts.set(t.nodeId,new Map)}getAllNodeIds(){return Array.from(this.nodes.keys())}getNode(t){return this.nodes.get(t)}removeNode(t){this.nodes.delete(t),this.nodePorts.delete(t)}addPort(t){this.ports.set(t.portId,{element:t.element,direction:t.direction}),this.cycleEdges.set(t.portId,new Set),this.incommingEdges.set(t.portId,new Set),this.outcommingEdges.set(t.portId,new Set),this.portNodeId.set(t.portId,t.nodeId),this.nodePorts.get(t.nodeId).set(t.portId,t.element)}getPort(t){return this.ports.get(t)}getAllPortIds(){return Array.from(this.ports.keys())}getNodePortIds(t){const o=this.nodePorts.get(t);if(o!==void 0)return Array.from(o.keys())}getPortNodeId(t){return this.portNodeId.get(t)}removePort(t){const o=this.portNodeId.get(t);this.portNodeId.delete(t),this.nodePorts.get(o).delete(t),this.ports.delete(t)}addEdge(t){this.edges.set(t.edgeId,{from:t.from,to:t.to,shape:t.shape,priority:t.priority}),t.from!==t.to?(this.outcommingEdges.get(t.from).add(t.edgeId),this.incommingEdges.get(t.to).add(t.edgeId)):this.cycleEdges.get(t.from).add(t.edgeId)}updateEdgeFrom(t,o){const r=this.edges.get(t);this.removeEdge(t),this.addEdge({edgeId:t,from:o,to:r.to,shape:r.shape,priority:r.priority})}updateEdgeTo(t,o){const r=this.edges.get(t);this.removeEdge(t),this.addEdge({edgeId:t,from:r.from,to:o,shape:r.shape,priority:r.priority})}getAllEdgeIds(){return Array.from(this.edges.keys())}getEdge(t){return this.edges.get(t)}removeEdge(t){const o=this.edges.get(t),r=o.from,i=o.to;this.cycleEdges.get(r).delete(t),this.cycleEdges.get(i).delete(t),this.incommingEdges.get(r).delete(t),this.incommingEdges.get(i).delete(t),this.outcommingEdges.get(r).delete(t),this.outcommingEdges.get(i).delete(t),this.edges.delete(t)}clear(){this.nodes.clear(),this.ports.clear(),this.nodePorts.clear(),this.portNodeId.clear(),this.edges.clear(),this.incommingEdges.clear(),this.outcommingEdges.clear(),this.cycleEdges.clear()}getPortIncomingEdgeIds(t){return Array.from(this.incommingEdges.get(t))}getPortOutcomingEdgeIds(t){return Array.from(this.outcommingEdges.get(t))}getPortCycleEdgeIds(t){return Array.from(this.cycleEdges.get(t))}getPortAdjacentEdgeIds(t){return[...this.getPortIncomingEdgeIds(t),...this.getPortOutcomingEdgeIds(t),...this.getPortCycleEdgeIds(t)]}getNodeIncomingEdgeIds(t){const o=Array.from(this.nodePorts.get(t).keys());let r=[];return o.forEach(i=>{r=[...r,...this.getPortIncomingEdgeIds(i)]}),r}getNodeOutcomingEdgeIds(t){const o=Array.from(this.nodePorts.get(t).keys());let r=[];return o.forEach(i=>{r=[...r,...this.getPortOutcomingEdgeIds(i)]}),r}getNodeCycleEdgeIds(t){const o=Array.from(this.nodePorts.get(t).keys());let r=[];return o.forEach(i=>{r=[...r,...this.getPortCycleEdgeIds(i)]}),r}getNodeAdjacentEdgeIds(t){return[...this.getNodeIncomingEdgeIds(t),...this.getNodeOutcomingEdgeIds(t),...this.getNodeCycleEdgeIds(t)]}}class ut{constructor(t){this.graphStore=t}getNode(t){const o=this.graphStore.getNode(t);return o===void 0?null:{element:o.element,x:o.x,y:o.y,centerFn:o.centerFn,priority:o.priority}}getAllNodeIds(){return this.graphStore.getAllNodeIds()}getPort(t){const o=this.graphStore.getPort(t);return o===void 0?null:{element:o.element,direction:o.direction}}getAllPortIds(){return this.graphStore.getAllPortIds()}getNodePortIds(t){return this.graphStore.getNodePortIds(t)}getPortNodeId(t){return this.graphStore.getPortNodeId(t)??null}getAllEdgeIds(){return this.graphStore.getAllEdgeIds()}getEdge(t){const o=this.graphStore.getEdge(t);return o===void 0?null:{from:o.from,to:o.to,priority:o.priority}}getPortIncomingEdgeIds(t){return this.graphStore.getPortIncomingEdgeIds(t)}getPortOutcomingEdgeIds(t){return this.graphStore.getPortOutcomingEdgeIds(t)}getPortCycleEdgeIds(t){return this.graphStore.getPortCycleEdgeIds(t)}getPortAdjacentEdgeIds(t){return this.graphStore.getPortAdjacentEdgeIds(t)}getNodeIncomingEdgeIds(t){return this.graphStore.getNodeIncomingEdgeIds(t)}getNodeOutcomingEdgeIds(t){return this.graphStore.getNodeOutcomingEdgeIds(t)}getNodeCycleEdgeIds(t){return this.graphStore.getNodeCycleEdgeIds(t)}getNodeAdjacentEdgeIds(t){return this.graphStore.getNodeAdjacentEdgeIds(t)}}const K=e=>({scale:1/e.scale,dx:-e.dx/e.scale,dy:-e.dy/e.scale}),_={scale:1,dx:0,dy:0};class wt{constructor(){n(this,"viewportMatrix",_);n(this,"contentMatrix",_)}getViewportMatrix(){return this.viewportMatrix}getContentMatrix(){return this.contentMatrix}patchViewportMatrix(t){this.viewportMatrix={scale:t.scale??this.viewportMatrix.scale,dx:t.dx??this.viewportMatrix.dx,dy:t.dy??this.viewportMatrix.dy},this.contentMatrix=K(this.viewportMatrix)}patchContentMatrix(t){this.contentMatrix={scale:t.scale??this.contentMatrix.scale,dx:t.dx??this.contentMatrix.dx,dy:t.dy??this.contentMatrix.dy},this.viewportMatrix=K(this.contentMatrix)}}class yt{constructor(t){this.transformer=t}getViewportMatrix(){return{...this.transformer.getViewportMatrix()}}getContentMatrix(){return{...this.transformer.getContentMatrix()}}}const ft=()=>{const e=document.createElement("div");return e.style.width="100%",e.style.height="100%",e.style.position="relative",e.style.overflow="hidden",e},vt=()=>{const e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="0",e.style.height="0",e},xt=()=>{const e=document.createElement("div");return e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.visibility="hidden",e};class St{constructor(t,o){n(this,"canvasWrapper",null);n(this,"host",ft());n(this,"container",vt());n(this,"nodeIdToWrapperElementMap",new Map);n(this,"edgeIdToElementMap",new Map);this.graphStore=t,this.viewportTransformer=o,this.host.appendChild(this.container)}attach(t){this.detach(),this.canvasWrapper=t,this.canvasWrapper.appendChild(this.host)}detach(){this.canvasWrapper!==null&&(this.canvasWrapper.removeChild(this.host),this.canvasWrapper=null)}applyTransform(){const t=this.viewportTransformer.getContentMatrix();this.container.style.transform=`matrix(${t.scale}, 0, 0, ${t.scale}, ${t.dx}, ${t.dy})`}attachNode(t){const o=this.graphStore.getNode(t),r=xt();r.appendChild(o.element),this.container.appendChild(r),this.nodeIdToWrapperElementMap.set(t,r),this.updateNodeCoordinates(t),this.updateNodePriority(t),r.style.visibility="visible"}detachNode(t){const o=this.graphStore.getNode(t),r=this.nodeIdToWrapperElementMap.get(t);r.removeChild(o.element),this.container.removeChild(r),this.nodeIdToWrapperElementMap.delete(t)}attachEdge(t){const o=this.graphStore.getEdge(t);this.edgeIdToElementMap.set(t,o.shape.svg),this.container.appendChild(o.shape.svg),this.renderEdge(t),this.updateEdgePriority(t)}detachEdge(t){const o=this.graphStore.getEdge(t);this.container.removeChild(o.shape.svg),this.edgeIdToElementMap.delete(t)}clear(){this.edgeIdToElementMap.forEach((t,o)=>{this.detachEdge(o)}),this.nodeIdToWrapperElementMap.forEach((t,o)=>{this.detachNode(o)})}destroy(){this.clear(),this.detach(),this.host.removeChild(this.container)}updateNodeCoordinates(t){const o=this.nodeIdToWrapperElementMap.get(t),r=this.graphStore.getNode(t),{width:i,height:s}=r.element.getBoundingClientRect(),h=this.viewportTransformer.getViewportMatrix().scale,d=r.centerFn(i,s),c=r.x-h*d.x,l=r.y-h*d.y;o.style.transform=`translate(${c}px, ${l}px)`}updateNodePriority(t){const o=this.graphStore.getNode(t),r=this.nodeIdToWrapperElementMap.get(t);r.style.zIndex=`${o.priority}`}updateEdgeShape(t){const o=this.edgeIdToElementMap.get(t);this.container.removeChild(o);const r=this.graphStore.getEdge(t);this.edgeIdToElementMap.set(t,r.shape.svg),this.container.appendChild(r.shape.svg)}renderEdge(t){const o=this.graphStore.getEdge(t),r=this.graphStore.getPort(o.from),i=this.graphStore.getPort(o.to),s=r.element.getBoundingClientRect(),h=i.element.getBoundingClientRect(),d=this.host.getBoundingClientRect(),c=this.viewportTransformer.getViewportMatrix(),l={x:c.scale*(s.left-d.left)+c.dx,y:c.scale*(s.top-d.top)+c.dy},a={x:c.scale*(h.left-d.left)+c.dx,y:c.scale*(h.top-d.top)+c.dy},g={x:l.x,y:l.y,width:s.width*c.scale,height:s.height*c.scale,direction:r.direction,portId:o.from,nodeId:this.graphStore.getPortNodeId(o.from)},y={x:a.x,y:a.y,width:h.width*c.scale,height:h.height*c.scale,direction:i.direction,portId:o.to,nodeId:this.graphStore.getPortNodeId(o.to)};o.shape.render({source:g,target:y})}updateEdgePriority(t){const o=this.graphStore.getEdge(t);o.shape.svg.style.zIndex=`${o.priority}`}}class I{constructor(t){n(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 A extends Error{constructor(){super(...arguments);n(this,"name","HtmlGraphError")}}class Et{constructor(t,o,r,i,s,h,d){n(this,"nodeIdGenerator",new I(t=>this.graphStore.getNode(t)!==void 0));n(this,"portIdGenerator",new I(t=>this.graphStore.getPort(t)!==void 0));n(this,"edgeIdGenerator",new I(t=>this.graphStore.getEdge(t)!==void 0));this.graphStore=t,this.htmlController=o,this.viewportTransformer=r,this.defaultNodesCenterFn=i,this.defaultPortsDirection=s,this.defaultNodesPriorityFn=h,this.defaultEdgesPriorityFn=d}attach(t){this.htmlController.attach(t)}detach(){this.htmlController.detach()}addNode(t){const o=this.nodeIdGenerator.create(t.nodeId);if(this.graphStore.getNode(o)!==void 0)throw new A("failed to add node with existing id");this.graphStore.addNode({nodeId:o,element:t.element,x:t.x,y:t.y,centerFn:t.centerFn??this.defaultNodesCenterFn,priority:t.priority??this.defaultNodesPriorityFn()}),this.htmlController.attachNode(o),Array.from(t.ports??[]).forEach(r=>{this.markPort({portId:r.id,element:r.element,nodeId:o,direction:r.direction})})}markPort(t){const o=this.portIdGenerator.create(t.portId);if(this.graphStore.getPort(o)!==void 0)throw new A("failed to add port with existing id");if(this.graphStore.getNode(t.nodeId)===void 0)throw new A("failed to set port on nonexisting node");this.graphStore.addPort({portId:o,element:t.element,nodeId:t.nodeId,direction:t.direction??this.defaultPortsDirection})}addEdge(t){const o=this.edgeIdGenerator.create(t.edgeId);if(this.graphStore.getEdge(o)!==void 0)throw new A("failed to add edge with existing id");if(this.graphStore.getPort(t.from)===void 0)throw new A("failed to add edge from nonexisting port");if(this.graphStore.getPort(t.to)===void 0)throw new A("failed to add edge to nonexisting port");this.graphStore.addEdge({edgeId:o,from:t.from,to:t.to,shape:t.shape,priority:t.priority??this.defaultEdgesPriorityFn()}),this.htmlController.attachEdge(o)}updateEdge(t){const o=this.graphStore.getEdge(t.edgeId);if(o===void 0)throw new A("failed to update nonexisting edge");t.shape!==void 0&&(o.shape=t.shape,this.htmlController.updateEdgeShape(t.edgeId)),t.priority!==void 0&&(o.priority=t.priority,this.htmlController.updateEdgePriority(t.edgeId)),t.from!==void 0&&this.graphStore.updateEdgeFrom(t.edgeId,t.from),t.to!==void 0&&this.graphStore.updateEdgeTo(t.edgeId,t.to),this.htmlController.renderEdge(t.edgeId)}updatePort(t,o){const r=this.graphStore.getPort(t);if(r===void 0)throw new A("failed to unset nonexisting port");r.direction=o.direction??r.direction,this.graphStore.getPortAdjacentEdgeIds(t).forEach(s=>{this.htmlController.renderEdge(s)})}updateNode(t,o){const r=this.graphStore.getNode(t);if(r===void 0)throw new A("failed to update nonexisting node");r.x=(o==null?void 0:o.x)??r.x,r.y=(o==null?void 0:o.y)??r.y,r.centerFn=(o==null?void 0:o.centerFn)??r.centerFn,r.priority=(o==null?void 0:o.priority)??r.priority,this.htmlController.updateNodeCoordinates(t),this.htmlController.updateNodePriority(t),this.graphStore.getNodeAdjacentEdgeIds(t).forEach(s=>{this.htmlController.renderEdge(s)})}removeEdge(t){if(this.graphStore.getEdge(t)===void 0)throw new A("failed to remove nonexisting edge");this.htmlController.detachEdge(t),this.graphStore.removeEdge(t)}unmarkPort(t){if(this.graphStore.getPort(t)===void 0)throw new A("failed to unset nonexisting port");this.graphStore.getPortAdjacentEdgeIds(t).forEach(o=>{this.removeEdge(o)}),this.graphStore.removePort(t)}removeNode(t){if(this.graphStore.getNode(t)===void 0)throw new A("failed to remove nonexisting node");this.graphStore.getNodePortIds(t).forEach(o=>{this.unmarkPort(o)}),this.htmlController.detachNode(t),this.graphStore.removeNode(t)}patchViewportMatrix(t){this.viewportTransformer.patchViewportMatrix(t),this.htmlController.applyTransform()}patchContentMatrix(t){this.viewportTransformer.patchContentMatrix(t),this.htmlController.applyTransform()}clear(){this.htmlController.clear(),this.graphStore.clear(),this.nodeIdGenerator.reset(),this.portIdGenerator.reset(),this.edgeIdGenerator.reset()}destroy(){this.clear(),this.htmlController.destroy()}}class J{constructor(t){n(this,"transformation");n(this,"model");n(this,"canvasController");n(this,"edgeShapeFactory");this.apiOptions=t;const o=at(this.apiOptions),r=new wt,i=new gt;this.model=new ut(i),this.transformation=new yt(r);const s=new St(i,r);this.canvasController=new Et(i,s,r,o.nodes.centerFn,o.ports.direction,o.nodes.priorityFn,o.edges.priorityFn),this.edgeShapeFactory=o.edges.shapeFactory}attach(t){return this.canvasController.attach(t),this}detach(){return this.canvasController.detach(),this}addNode(t){return this.canvasController.addNode({nodeId:t.id,element:t.element,x:t.x,y:t.y,ports:t.ports,centerFn:t.centerFn,priority:t.priority}),this}updateNode(t,o){return this.canvasController.updateNode(t,{x:o==null?void 0:o.x,y:o==null?void 0:o.y,priority:o==null?void 0:o.priority,centerFn:o==null?void 0:o.centerFn}),this}removeNode(t){return this.canvasController.removeNode(t),this}addEdge(t){return this.canvasController.addEdge({edgeId:t.id,from:t.from,to:t.to,shape:t.shape??this.edgeShapeFactory(),priority:t.priority}),this}updateEdge(t,o){return this.canvasController.updateEdge({edgeId:t,shape:o==null?void 0:o.shape,priority:o==null?void 0:o.priority,from:o==null?void 0:o.from,to:o==null?void 0:o.to}),this}removeEdge(t){return this.canvasController.removeEdge(t),this}markPort(t){return this.canvasController.markPort({portId:t.id,element:t.element,nodeId:t.nodeId,direction:t.direction}),this}updatePort(t,o){return this.canvasController.updatePort(t,{direction:o==null?void 0:o.direction}),this}unmarkPort(t){return this.canvasController.unmarkPort(t),this}patchViewportMatrix(t){return this.canvasController.patchViewportMatrix(t),this}patchContentMatrix(t){return this.canvasController.patchContentMatrix(t),this}clear(){return this.canvasController.clear(),this}destroy(){this.clear(),this.canvasController.destroy()}}const V=(e,t,o)=>{const{x:r,y:i,width:s,height:h}=e.getBoundingClientRect();return t>=r&&t<=r+s&&o>=i&&o<=i+h},W=(e,t,o)=>t>=0&&t<=e.innerWidth&&o>=0&&o<=e.innerHeight,F=(e,t)=>{t!==null?e.style.cursor=t:e.style.removeProperty("cursor")},At=e=>{var g,y,x,f,L,N;const t=((g=e==null?void 0:e.events)==null?void 0:g.onNodeDrag)??(()=>{}),o=((y=e==null?void 0:e.events)==null?void 0:y.onBeforeNodeDrag)??(()=>!0),r=((x=e==null?void 0:e.events)==null?void 0:x.onNodeDragFinished)??(()=>{}),i=(e==null?void 0:e.moveOnTop)===!1,s=(f=e==null?void 0:e.mouse)==null?void 0:f.dragCursor,h=s!==void 0?s:"grab",d=(L=e==null?void 0:e.mouse)==null?void 0:L.mouseDownEventValidator,c=d!==void 0?d:P=>P.button===0,l=(N=e==null?void 0:e.mouse)==null?void 0:N.mouseUpEventValidator;return{freezePriority:i,dragCursor:h,mouseDownEventValidator:c,mouseUpEventValidator:l!==void 0?l:P=>P.button===0,onNodeDrag:t,onBeforeNodeDrag:o,onNodeDragFinished:r}};class Q{constructor(t,o){n(this,"model");n(this,"transformation");n(this,"maxNodePriority",0);n(this,"nodes",new Map);n(this,"grabbedNodeId",null);n(this,"nodeIdGenerator",new I(t=>this.nodes.has(t)));n(this,"element",null);n(this,"onWindowMouseMove",t=>{if(this.element!==null&&(!V(this.element,t.clientX,t.clientY)||!W(this.window,t.clientX,t.clientY))){this.cancelMouseDrag();return}this.grabbedNodeId!==null&&this.dragNode(this.grabbedNodeId,t.movementX,t.movementY)});n(this,"onWindowMouseUp",t=>{this.options.mouseUpEventValidator(t)&&this.cancelMouseDrag()});n(this,"onWindowTouchMove",t=>{if(t.touches.length!==1)return;const o=t.touches[0];if(this.element!==null&&(!V(this.element,o.clientX,o.clientY)||!W(this.window,o.clientX,o.clientY))){this.cancelTouchDrag();return}if(this.grabbedNodeId!==null&&this.previousTouchCoords!==null){const r=o.clientX-this.previousTouchCoords.x,i=o.clientY-this.previousTouchCoords.y;this.dragNode(this.grabbedNodeId,r,i),this.previousTouchCoords={x:t.touches[0].clientX,y:t.touches[0].clientY}}});n(this,"onWindowTouchFinish",()=>{this.previousTouchCoords=null,this.cancelTouchDrag()});n(this,"previousTouchCoords",null);n(this,"window",window);n(this,"options");this.canvas=t,this.transformation=this.canvas.transformation,this.model=this.canvas.model,this.options=At(o??{})}attach(t){return this.detach(),this.element=t,this.canvas.attach(this.element),this}detach(){return this.canvas.detach(),this.element!==null&&(this.element=null),this}addNode(t){const o=this.nodeIdGenerator.create(t.id);this.canvas.addNode({...t,id:o}),this.updateMaxNodePriority(o);const r=s=>{if(this.element===null||!this.options.mouseDownEventValidator(s))return;const h=this.model.getNode(o);this.options.onBeforeNodeDrag({nodeId:o,element:t.element,x:h.x,y:h.y})&&(s.stopImmediatePropagation(),this.grabbedNodeId=o,F(this.element,this.options.dragCursor),this.moveNodeOnTop(o),this.window.addEventListener("mouseup",this.onWindowMouseUp),this.window.addEventListener("mousemove",this.onWindowMouseMove))},i=s=>{if(s.touches.length!==1)return;s.stopImmediatePropagation(),this.previousTouchCoords={x:s.touches[0].clientX,y:s.touches[0].clientY};const h=this.model.getNode(o);this.options.onBeforeNodeDrag({nodeId:o,element:t.element,x:h.x,y:h.y})&&(this.grabbedNodeId=o,this.moveNodeOnTop(o),this.window.addEventListener("touchmove",this.onWindowTouchMove),this.window.addEventListener("touchend",this.onWindowTouchFinish),this.window.addEventListener("touchcancel",this.onWindowTouchFinish))};return this.nodes.set(o,{element:t.element,onMouseDown:r,onTouchStart:i}),t.element.addEventListener("mousedown",r),t.element.addEventListener("touchstart",i),this}updateNode(t,o){return this.canvas.updateNode(t,o),this.updateMaxNodePriority(t),this}removeNode(t){const o=this.nodes.get(t);return o!==void 0&&(o.element.removeEventListener("mousedown",o.onMouseDown),o.element.removeEventListener("touchstart",o.onTouchStart)),this.nodes.delete(t),this.canvas.removeNode(t),this}markPort(t){return this.canvas.markPort(t),this}updatePort(t,o){return this.canvas.updatePort(t,o),this}unmarkPort(t){return this.canvas.unmarkPort(t),this}addEdge(t){return this.canvas.addEdge(t),this}updateEdge(t,o){return this.canvas.updateEdge(t,o),this}removeEdge(t){return this.canvas.removeEdge(t),this}patchViewportMatrix(t){return this.canvas.patchViewportMatrix(t),this}patchContentMatrix(t){return this.canvas.patchContentMatrix(t),this}clear(){return this.canvas.clear(),this.nodes.forEach(t=>{t.element.removeEventListener("mousedown",t.onMouseDown),t.element.removeEventListener("touchstart",t.onTouchStart)}),this.nodes.clear(),this.maxNodePriority=0,this}destroy(){this.detach(),this.clear(),this.removeMouseDragListeners(),this.removeTouchDragListeners(),this.canvas.destroy()}dragNode(t,o,r){const i=this.model.getNode(t);if(i===null)return;const s=this.canvas.transformation.getContentMatrix(),h=s.scale*i.x+s.dx,d=s.scale*i.y+s.dy,c=h+o,l=d+r,a=this.canvas.transformation.getViewportMatrix(),g=a.scale*c+a.dx,y=a.scale*l+a.dy;this.canvas.updateNode(t,{x:g,y}),this.options.onNodeDrag({nodeId:t,element:i.element,x:i.x,y:i.y})}updateMaxNodePriority(t){const o=this.model.getNode(t).priority;this.maxNodePriority=Math.max(this.maxNodePriority,o)}moveNodeOnTop(t){if(this.options.freezePriority)return;this.maxNodePriority+=2,this.updateNode(t,{priority:this.maxNodePriority});const o=this.maxNodePriority-1;this.model.getNodeAdjacentEdgeIds(t).forEach(i=>{this.updateEdge(i,{priority:o})})}cancelMouseDrag(){const t=this.model.getNode(this.grabbedNodeId);t!==null&&this.options.onNodeDragFinished({nodeId:this.grabbedNodeId,element:t.element,x:t.x,y:t.y}),this.grabbedNodeId=null,this.element!==null&&F(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}cancelTouchDrag(){this.previousTouchCoords=null;const t=this.model.getNode(this.grabbedNodeId);t!==null&&this.options.onNodeDragFinished({nodeId:this.grabbedNodeId,element:t.element,x:t.x,y:t.y}),this.grabbedNodeId=null,this.removeTouchDragListeners()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}const Tt=e=>{const t=e.minX!==null?e.minX:-1/0,o=e.maxX!==null?e.maxX:1/0,r=e.minY!==null?e.minY:-1/0,i=e.maxY!==null?e.maxY:1/0;return s=>{let h=s.nextTransform.dx,d=s.nextTransform.dy;h<t&&h<s.prevTransform.dx&&(h=Math.min(s.prevTransform.dx,t));const c=s.canvasWidth*s.prevTransform.scale;h>o-c&&h>s.prevTransform.dx&&(h=Math.max(s.prevTransform.dx,o-c)),d<r&&d<s.prevTransform.dy&&(d=Math.min(s.prevTransform.dy,r));const l=s.canvasHeight*s.prevTransform.scale;return d>i-l&&d>s.prevTransform.dy&&(d=Math.max(s.prevTransform.dy,i-l)),{scale:s.nextTransform.scale,dx:h,dy:d}}},Mt=e=>{const t=e.maxContentScale,o=e.minContentScale,r=t!==null?1/t:0,i=o!==null?1/o:1/0;return s=>{const h=s.prevTransform,d=s.nextTransform;let c=d.scale,l=d.dx,a=d.dy;if(d.scale>i&&d.scale>h.scale){c=Math.max(h.scale,i),l=h.dx,a=h.dy;const g=(c-h.scale)/(d.scale-h.scale);l=h.dx+(d.dx-h.dx)*g,a=h.dy+(d.dy-h.dy)*g}if(d.scale<r&&d.scale<h.scale){c=Math.min(h.scale,r),l=h.dx,a=h.dy;const g=(c-h.scale)/(d.scale-h.scale);l=h.dx+(d.dx-h.dx)*g,a=h.dy+(d.dy-h.dy)*g}return{scale:c,dx:l,dy:a}}},Ct=e=>t=>e.reduce((o,r)=>r({prevTransform:t.prevTransform,nextTransform:o,canvasWidth:t.canvasWidth,canvasHeight:t.canvasHeight}),t.nextTransform),Z=e=>{if(typeof e=="function")return e;switch(e.type){case"scale-limit":return Mt({minContentScale:e.minContentScale??0,maxContentScale:e.maxContentScale??1/0});case"shift-limit":return Tt({minX:e.minX??-1/0,maxX:e.maxX??1/0,minY:e.minY??-1/0,maxY:e.maxY??1/0})}},Nt=e=>{var c,l,a,g,y,x;const t=(c=e==null?void 0:e.scale)==null?void 0:c.mouseWheelSensitivity,o=t!==void 0?t:1.2,r=e==null?void 0:e.transformPreprocessor;let i;r!==void 0?Array.isArray(r)?i=Ct(r.map(f=>Z(f))):i=Z(r):i=f=>f.nextTransform;const s=((l=e==null?void 0:e.shift)==null?void 0:l.cursor)!==void 0?e.shift.cursor:"grab",h=((a=e==null?void 0:e.events)==null?void 0:a.onBeforeTransformChange)??(()=>{}),d=((g=e==null?void 0:e.events)==null?void 0:g.onTransformChange)??(()=>{});return{wheelSensitivity:o,onTransformStarted:((y=e==null?void 0:e.events)==null?void 0:y.onTransformStarted)??(()=>{}),onTransformFinished:((x=e==null?void 0:e.events)==null?void 0:x.onTransformFinished)??(()=>{}),onBeforeTransformChange:h,onTransformChange:d,transformPreprocessor:i,shiftCursor:s}},B=e=>{const t=[],o=e.touches.length;for(let d=0;d<o;d++)t.push([e.touches[d].clientX,e.touches[d].clientY]);const r=t.reduce((d,c)=>[d[0]+c[0],d[1]+c[1]],[0,0]),i=[r[0]/o,r[1]/o],h=t.map(d=>[d[0]-i[0],d[1]-i[1]]).reduce((d,c)=>d+Math.sqrt(c[0]*c[0]+c[1]*c[1]),0);return{x:i[0],y:i[1],scale:h/o,touchesCnt:o,touches:t}},Lt=(e,t,o)=>({scale:e.scale,dx:e.dx+e.scale*t,dy:e.dy+e.scale*o}),Pt=(e,t,o,r)=>({scale:e.scale*t,dx:e.scale*(1-t)*o+e.dx,dy:e.scale*(1-t)*r+e.dy});class O{constructor(t,o){n(this,"model");n(this,"transformation");n(this,"element",null);n(this,"prevTouches",null);n(this,"window",window);n(this,"onMouseDown",t=>{this.element===null||t.button!==0||(F(this.element,this.options.shiftCursor),this.window.addEventListener("mousemove",this.onWindowMouseMove),this.window.addEventListener("mouseup",this.onWindowMouseUp),this.options.onTransformStarted())});n(this,"onWindowMouseMove",t=>{if(this.element===null||!V(this.element,t.clientX,t.clientY)||!W(this.window,t.clientX,t.clientY)){this.stopMouseDrag();return}const o=-t.movementX,r=-t.movementY;this.moveViewport(this.element,o,r)});n(this,"onWindowMouseUp",t=>{this.element===null||t.button!==0||this.stopMouseDrag()});n(this,"onWheelScroll",t=>{t.preventDefault();const{left:o,top:r}=this.element.getBoundingClientRect(),i=t.clientX-o,s=t.clientY-r,d=1/(t.deltaY<0?this.options.wheelSensitivity:1/this.options.wheelSensitivity);this.scaleViewport(this.element,d,i,s)});n(this,"onTouchStart",t=>{this.prevTouches=B(t),this.window.addEventListener("touchmove",this.onWindowTouchMove),this.window.addEventListener("touchend",this.onWindowTouchFinish),this.window.addEventListener("touchcancel",this.onWindowTouchFinish),this.options.onTransformStarted()});n(this,"onWindowTouchMove",t=>{const o=this.element;if(o===null)return;const r=B(t);if(!r.touches.every(s=>V(o,s[0],s[1])&&W(this.window,s[0],s[1]))){this.stopTouchDrag();return}if((r.touchesCnt===1||r.touchesCnt===2)&&this.moveViewport(o,-(r.x-this.prevTouches.x),-(r.y-this.prevTouches.y)),r.touchesCnt===2){const{left:s,top:h}=o.getBoundingClientRect(),d=this.prevTouches.x-s,c=this.prevTouches.y-h,a=1/(r.scale/this.prevTouches.scale);this.scaleViewport(o,a,d,c)}this.prevTouches=r});n(this,"onWindowTouchFinish",t=>{t.touches.length>0?this.prevTouches=B(t):this.stopTouchDrag()});n(this,"observer",new ResizeObserver(()=>{const t=this.canvas.transformation.getViewportMatrix(),{width:o,height:r}=this.element.getBoundingClientRect(),i=this.options.transformPreprocessor({prevTransform:t,nextTransform:t,canvasWidth:o,canvasHeight:r});this.canvas.patchViewportMatrix(i),this.options.onTransformChange()}));n(this,"options");this.canvas=t,this.options=Nt(o),this.transformation=this.canvas.transformation,this.model=this.canvas.model}attach(t){return this.detach(),this.element=t,this.observer.observe(this.element),this.element.addEventListener("mousedown",this.onMouseDown),this.element.addEventListener("wheel",this.onWheelScroll),this.element.addEventListener("touchstart",this.onTouchStart),this.canvas.attach(this.element),this}detach(){return this.canvas.detach(),this.element!==null&&(this.observer.unobserve(this.element),this.element.removeEventListener("mousedown",this.onMouseDown),this.element.removeEventListener("wheel",this.onWheelScroll),this.element.removeEventListener("touchstart",this.onTouchStart),this.element=null),this}addNode(t){return this.canvas.addNode(t),this}updateNode(t,o){return this.canvas.updateNode(t,o),this}removeNode(t){return this.canvas.removeNode(t),this}markPort(t){return this.canvas.markPort(t),this}updatePort(t,o){return this.canvas.updatePort(t,o),this}unmarkPort(t){return this.canvas.unmarkPort(t),this}addEdge(t){return this.canvas.addEdge(t),this}updateEdge(t,o){return this.canvas.updateEdge(t,o),this}removeEdge(t){return this.canvas.removeEdge(t),this}patchViewportMatrix(t){return this.canvas.patchViewportMatrix(t),this}patchContentMatrix(t){return this.canvas.patchContentMatrix(t),this}clear(){return this.canvas.clear(),this}destroy(){this.detach(),this.removeMouseDragListeners(),this.removeTouchDragListeners(),this.canvas.destroy()}moveViewport(t,o,r){this.options.onBeforeTransformChange();const i=this.transformation.getViewportMatrix(),s=Lt(i,o,r),{width:h,height:d}=t.getBoundingClientRect(),c=this.options.transformPreprocessor({prevTransform:i,nextTransform:s,canvasWidth:h,canvasHeight:d});this.canvas.patchViewportMatrix(c),this.options.onTransformChange()}scaleViewport(t,o,r,i){this.options.onBeforeTransformChange();const s=this.canvas.transformation.getViewportMatrix(),h=Pt(s,o,r,i),{width:d,height:c}=t.getBoundingClientRect(),l=this.options.transformPreprocessor({prevTransform:s,nextTransform:h,canvasWidth:d,canvasHeight:c});this.canvas.patchViewportMatrix(l),this.options.onTransformChange()}stopMouseDrag(){this.element!==null&&F(this.element,null),this.removeMouseDragListeners(),this.options.onTransformFinished()}removeMouseDragListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}stopTouchDrag(){this.prevTouches=null,this.removeTouchDragListeners(),this.options.onTransformFinished()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}class Dt{constructor(){n(this,"keyMap",new Map);n(this,"valueMap",new Map)}set(t,o){this.keyMap.set(t,o),this.valueMap.set(o,t)}hasKey(t){return this.keyMap.has(t)}hasValue(t){return this.valueMap.has(t)}getByKey(t){return this.keyMap.get(t)}getByValue(t){return this.valueMap.get(t)}deleteByKey(t){const o=this.keyMap.get(t);o!==void 0&&this.valueMap.delete(o),this.keyMap.delete(t)}deleteByValue(t){const o=this.valueMap.get(t);o!==void 0&&this.keyMap.delete(o),this.valueMap.delete(t)}forEach(t){this.keyMap.forEach((o,r)=>{t(o,r)})}clear(){this.keyMap.clear(),this.valueMap.clear()}}class q{constructor(t){n(this,"transformation");n(this,"model");n(this,"nodes",new Dt);n(this,"nodeIdGenerator",new I(t=>this.nodes.hasKey(t)));n(this,"nodesResizeObserver");this.canvas=t,this.nodesResizeObserver=new window.ResizeObserver(o=>{o.forEach(r=>{const i=r.target;this.reactNodeChange(i)})}),this.transformation=this.canvas.transformation,this.model=this.canvas.model}attach(t){return this.canvas.attach(t),this}detach(){return this.canvas.detach(),this}addNode(t){const o=this.nodeIdGenerator.create(t.id);return this.canvas.addNode({...t,id:o}),this.nodes.set(o,t.element),this.nodesResizeObserver.observe(t.element),this}updateNode(t,o){return this.canvas.updateNode(t,o),this}removeNode(t){this.canvas.removeNode(t);const o=this.nodes.getByKey(t);return this.nodes.deleteByKey(t),this.nodesResizeObserver.unobserve(o),this}markPort(t){return this.canvas.markPort(t),this}updatePort(t,o){return this.canvas.updatePort(t,o),this}unmarkPort(t){return this.canvas.unmarkPort(t),this}addEdge(t){return this.canvas.addEdge(t),this}updateEdge(t,o){return this.canvas.updateEdge(t,o),this}removeEdge(t){return this.canvas.removeEdge(t),this}patchViewportMatrix(t){return this.canvas.patchViewportMatrix(t),this}patchContentMatrix(t){return this.canvas.patchContentMatrix(t),this}clear(){return this.canvas.clear(),this.nodesResizeObserver.disconnect(),this.nodes.clear(),this}destroy(){this.clear(),this.canvas.destroy()}reactNodeChange(t){const o=this.nodes.getByValue(t);this.canvas.updateNode(o),this.model.getNodeAdjacentEdgeIds(o).forEach(i=>{this.canvas.updateEdge(i)})}}class It{constructor(){n(this,"coreOptions");n(this,"dragOptions");n(this,"transformOptions");n(this,"isDraggable",!1);n(this,"isTransformable",!1);n(this,"hasResizeReactiveNodes",!1)}setOptions(t){return this.coreOptions=t,this}setUserDraggableNodes(t){return this.isDraggable=!0,this.dragOptions=t,this}setUserTransformableCanvas(t){return this.isTransformable=!0,this.transformOptions=t,this}setResizeReactiveNodes(){return this.hasResizeReactiveNodes=!0,this}build(){let t=new J(this.coreOptions);return this.hasResizeReactiveNodes&&(t=new q(t)),this.isDraggable&&(t=new Q(t,this.dragOptions)),this.isTransformable&&(t=new O(t,this.transformOptions)),t}}S.BezierEdgeShape=z,S.CanvasCore=J,S.HorizontalEdgeShape=G,S.HtmlGraphBuilder=It,S.HtmlGraphError=A,S.ResizeReactiveNodesCanvas=q,S.StraightEdgeShape=H,S.UserDraggableNodesCanvas=Q,S.UserTransformableCanvas=O,S.VerticalEdgeShape=j,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@html-graph/html-graph",
|
|
3
3
|
"author": "Dmitry Marov <d.marov94@gmail.com>",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.5",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/main.js",
|
|
8
8
|
"types": "dist/main.d.ts",
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
"preview": "vite preview",
|
|
39
39
|
"before-build": "npm run check-formatting && npm run lint && npm run test:ci",
|
|
40
40
|
"release-next-version": "tsx ./scripts/release-next-version.ts",
|
|
41
|
+
"release-next-version:minor": "tsx ./scripts/release-next-version.ts -- --minor",
|
|
42
|
+
"release-next-version:major": "tsx ./scripts/release-next-version.ts -- --major",
|
|
41
43
|
"deploy-docs": "tsx ./scripts/deploy-docs.ts",
|
|
42
44
|
"make-deps-graph": "npx depcruise lib --include-only \"^lib\" --output-type dot > ./deps-graph/deps-graph.dot",
|
|
43
45
|
"test": "jest",
|
|
@@ -50,6 +52,7 @@
|
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
54
|
"@eslint/js": "^9.9.1",
|
|
55
|
+
"@playwright/test": "^1.50.1",
|
|
53
56
|
"@types/jest": "^29.5.14",
|
|
54
57
|
"@types/node": "^22.5.0",
|
|
55
58
|
"dependency-cruiser": "^16.7.0",
|
|
@@ -61,7 +64,7 @@
|
|
|
61
64
|
"prettier": "3.3.3",
|
|
62
65
|
"ts-jest": "^29.2.5",
|
|
63
66
|
"ts-node": "^10.9.2",
|
|
64
|
-
"tsx": "^
|
|
67
|
+
"tsx": "^3.12.10",
|
|
65
68
|
"typescript": "^5.5.3",
|
|
66
69
|
"typescript-eslint": "^8.3.0",
|
|
67
70
|
"vite": "^5.4.1",
|